Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Abstraction Level for Math Optimization Mode #981

Closed
RoyiAvital opened this issue Oct 3, 2020 · 7 comments
Closed

Add Abstraction Level for Math Optimization Mode #981

RoyiAvital opened this issue Oct 3, 2020 · 7 comments

Comments

@RoyiAvital
Copy link

All compilers have flags to control the precision mode of Math.
Most of them have something like default, strict and fast (Intel Compiler has few fast modes).

It will be great to have abstraction for those in the same manner the optimization level was abstracted.

It has some overlap with the optimization level, yet I think when a user set this it should override optimization level.

@waruqi
Copy link
Member

waruqi commented Oct 4, 2020

Is like this? https://gcc.gnu.org/wiki/FloatingPointMath

@RoyiAvital
Copy link
Author

Yes. GCC is more tricky as it has many flags which are math related.

MSVC, ICC and I think CLang (See -ffp-model) have this with simple high level flag.
I think a good policy will be to imitate CLang with GCC.
Though even first iteration for GCC could be default (No flag) or -ffast-math

@waruqi waruqi added this to the v2.3.8 milestone Oct 4, 2020
@waruqi
Copy link
Member

waruqi commented Oct 6, 2020

I have added a new set_fpmodels() interface, and initially supported some abstract levels. e.g. precise(default), fast, strict, except, noexcept

set_fpmodels("fast")
set_fpmodels("strict")
set_fpmodels("fast", "except")
set_fpmodels("precise") -- default

0e6d98d

@RoyiAvital
Copy link
Author

RoyiAvital commented Oct 6, 2020

This is great. It seems xmake is truly an abstraction level over most compilers.
When I use CMake or Meson I have to have conditionals on the actual compiler used (Not to mention I can chose the compiler in the code using xmake).

With xmake abstractions there is no need for that because of the flexible mapping you created.
A single code can be fairly optimized for all compilers.
Really great!

@waruqi
Copy link
Member

waruqi commented Oct 6, 2020

Ok, you can review the gcc/clang flags corresponding to fp-model level. If there are still incorrect mapping flags, I will modify it

gcc:

function nf_fpmodel(self, level)
    local maps =
    {
        precise    = "" --default
    ,   fast       = "-ffast-math"
    ,   strict     = {"-frounding-math", "-ftrapping-math"}
    ,   except     = "-ftrapping-math"
    ,   noexcept   = "-fno-trapping-math"
    }
    return maps[level]
end

Clang

function nf_fpmodel(self, level)
    local maps
    if self:has_flags("-ffp-model=fast") then
        maps =
        {
            precise    = "-ffp-model=precise"
        ,   fast       = "-ffp-model=fast"
        ,   strict     = "-ffp-model=strict"
        ,   except     = "-ftrapping-math"
        ,   noexcept   = "-fno-trapping-math"
        }
    else
        maps =
        {
            precise    = "" -- default
        ,   fast       = "-ffast-math"
        ,   strict     = {"-frounding-math", "-ftrapping-math"}
        ,   except     = "-ftrapping-math"
        ,   noexcept   = "-fno-trapping-math"
        }
    end
    return maps[level]
end

@waruqi
Copy link
Member

waruqi commented Oct 7, 2020

I have added fp-models for intel compiler

@waruqi waruqi closed this as completed Oct 7, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants