Displaying 3 results from an estimated 3 matches for "fe_downward".
2016 Aug 18
5
fenv.h vs the optimizer
...ly, the LLVM compiler does not regard to the
exception-flag side-effects of floating point operations?
When run on my macbook, the example code on
http://en.cppreference.com/w/c/numeric/fenv/FE_exceptions does not print
all the expected exceptions.
Other examples:
void foo() {
fesetround(FE_DOWNWARD);
printf("foo downward: %f\n", rint(0.5));
fesetround(FE_UPWARD);
printf("foo upward: %f\n", rint(0.5));
}
If compiled with optimization, only one call to rint() is made and the
result is reused.
void bar(double a, double b) {
feclearexcept(FE_INEXACT);...
2015 Aug 21
2
The semantics of the fptrunc instruction with an example of incorrect optimisation
...le in C
```
#include <stdio.h>
#include <fenv.h>
int main() {
double x = 0.3;
fesetround(FE_TONEAREST);
float y = (float) x;
printf("y (nearest):%a\n", y);
fesetround(FE_UPWARD);
y = (float) x;
printf("y (upward):%a\n", y);
fesetround(FE_DOWNWARD);
y = (float) x;
printf("y (downward):%a\n", y);
return (int) y;
}
```
If I get the unoptimised LLVM IR for this by running ``clang -O0
float.c -emit-llvm -c -o float.clang.o0.bc`` I can see that the cast
of variable x is being handled using LLVM IR's ``fptrunc``
```
......
2020 Jan 18
2
Combining fast math flags with constrained intrinsics
...e(double X, double Y, double Z) {
// Some operation that doesn't need to be precise.
if (X/Y > SomeThreshold)
return doSomethingPrecise(X, Y);
else
return Z;
}
#pragma STDC FENV_ACCESS ON
double doSomethingPrecise(double X, double Y) {
int SaveRM = fegetround();
fesetround(FE_DOWNWARD);
feclearexcept(FE_ALL_EXCEPT);
double Temp = X * Y + Z;
if (fetestexcept(FE_ALL_EXCEPT))
std::cerr << "Something happened.\n";
fesetround(SaveRM);
return Temp;
}
-=-=-=-=-=-=-=-=
Now suppose I compile that with "-O2 -ffp-contract=fast". We will need to gen...