|
|
|
|
|
by piadodjanho
2238 days ago
|
|
In practice, subnormal are very rarely used. Most compiler disable subnormals when compiling with anything other than -O0. It takes over a hundred cycle to complete an operation. Demo:
#include <stdio.h> int
main ()
{
volatile float v;
float acc = 0;
float den = 1.40129846432e-45;
for (size_t i; i < (1ul<<33); i++) {
acc += den;
}
v = acc;
return 0;
}
With -01:
$ gcc float.c -o float -O1 && time ./float
./float 8.93s user 0.00s system 99% cpu 8.933 totalWith -O0:
$ gcc float.c -o float -O1 && time ./float
./float 20.60s user 0.00s system 99% cpu 20.610 total |
|
EDIT That one is interesting too
clang (9.0.1) performs about the same without -ffast-math; but with it, it managed to optimize the loop away.