Join GitHub today
GitHub is home to over 31 million developers working together to host and review code, manage projects, and build software together.
Sign upImprecise floating point operations (fast-math) #21690
Comments
kmcallister
added
the
A-LLVM
label
Jan 28, 2015
This comment has been minimized.
This comment has been minimized.
|
Inline IR was discussed on #15180. Another option is |
huonw
added
the
I-slow
label
Jan 28, 2015
This comment has been minimized.
This comment has been minimized.
|
Yeah, adding it as a function in There are a few different fast math flags, but the |
cmr
self-assigned this
Mar 25, 2015
This comment has been minimized.
This comment has been minimized.
|
This forum thread has examples of loops that llvm can vectorize well for integers, but doesn't for floats (a dot product). |
bluss
changed the title
Imprecise floating point operations
Imprecise floating point operations (fast-math)
Dec 20, 2015
This was referenced Dec 20, 2015
cmr
removed their assignment
Jan 5, 2016
bluss
referenced this issue
Mar 15, 2016
Merged
Add intrinsics for float arithmetic with `fast` flag enabled #32256
This comment has been minimized.
This comment has been minimized.
|
That would be super useful for me. I've prototyped it using a newtype: https://play.rust-lang.org/?gist=d516771d1d002f740cc9bf6eb5cacdf0&version=nightly&backtrace=0 It works in simple cases, but the newtype solution is insufficient:
So I'm very keen on seeing it supported natively in Rust. |
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
pedrocr
commented
Jun 8, 2017
•
|
I've tried -ffast-math in my C vs Rust benchmark of some graphics code: https://github.com/pedrocr/rustc-math-bench In the C code it's a ~20% improvement in clang but no benefit with GCC. In both cases it returns a wrong result and the math is extremely simple (multiplying a vector by a matrix). According to this:
|
This comment has been minimized.
This comment has been minimized.
|
@pedrocr Your benchmark has a loss of precision in With You get significantly different sum with All values from matrix multiplication are the same to at least 6 digits (I've diffed |
This comment has been minimized.
This comment has been minimized.
pedrocr
commented
Jun 8, 2017
•
|
@pornel thanks, fixed here: pedrocr/rustc-math-bench@8169fa3 The benchmark results are fine though, the sum is only used as a checksum. Here are the averages of three runs in ms/megapixel:
So as I mentioned before clang/llvm gets a good benefit from ffast-math but not gcc. I'd say making sure things like |
This comment has been minimized.
This comment has been minimized.
pedrocr
commented
Jun 8, 2017
•
|
I've suggested it would make sense to expose https://internals.rust-lang.org/t/pre-rfc-stabilization-of-target-feature/5176/23 |
This comment has been minimized.
This comment has been minimized.
|
Rust has fast math intrinsics, so the fast math behavior could be limited to a specific type or selected functions, without forcing the whole program into it. |
This comment has been minimized.
This comment has been minimized.
pedrocr
commented
Jun 9, 2017
|
A usable solution for my use cases would probably be to have the vector types in the simd crate be the types that allow the opt-in to ffast-math. That way there's only one type I need to conciously convert the code to for speedups. But for the general solution of in normal code having to swap types seems cumbersome. But maybe just doing |
Mark-Simulacrum
added
the
C-feature-request
label
Jul 22, 2017
pedrocr
referenced this issue
Jul 25, 2017
Open
Would it make sense to enable ffast-math for simd types? #19
Mark-Simulacrum
added
C-enhancement
and removed
C-enhancement
labels
Jul 26, 2017
This comment has been minimized.
This comment has been minimized.
pedrocr
commented
Aug 10, 2017
|
Created a pre-RFC discussion on internals to try and get a discussion on the best way to do this: https://internals.rust-lang.org/t/pre-rfc-whats-the-best-way-to-implement-ffast-math/5740 |
This comment has been minimized.
This comment has been minimized.
robsmith11
commented
Jan 20, 2019
|
Is there a current recommended approach to using fast-math optimizations in rust nightly? |
noctune commentedJan 27, 2015
There should be a way to use imprecise floating point operations like GCC's and Clang's
-ffast-math. The simplest way to do this would be to do like GCC and Clang and implement a command line flag, but I think a better way to do this would be to create af32fastandf64fasttype that would then call the fast LLVM math functions. This way you can easily mix fast and "slow" floating point operations.I think this could be implemented as a library if LLVM assembly could be used in the
asmmacro.