problem with fmath::expd on -711 and lesser values...
gwenael opened this issue · comments
Hello,
I started to try fmath::expd this morning and the perf was amazing...
I used it in a bigger piece of code and this problem came up : for values less than -711, the fmath::expd return value becomes wrong...
Maybe my plateform is to blame :
Freebsd 8.2
gcc 4.2.1
cpuflags
OS : 'FreeBSD'
hw.model : 'Intel Core i5-2300 CPU @ 2.80GHz'
hw.machine : 'amd64'
hw.machine_arch : 'amd64'
cpu details :
CPU: Intel(R) Core(TM) i5-2300 CPU @ 2.80GHz (2793.68-MHz K8-class CPU)
Origin = "GenuineIntel" Id = 0x206a7 Family = 6 Model = 2a Stepping = 7
Features=0xbfebfbff<FPU,VME,DE,PSE,TSC,MSR,PAE,MCE,CX8,APIC,SEP,MTRR,PGE,MCA,CMOV,PAT,PSE36,CLFLUSH,DTS,ACPI,MMX,FXSR,SSE,SSE2,SS,HTT,TM,PBE>
Features2=0x179ae3bf<SSE3,PCLMULQDQ,DTES64,MON,DS_CPL,VMX,EST,TM2,SSSE3,CX16,xTPR,PDCM,PCID,SSE4.1,SSE4.2,POPCNT,,AESNI,XSAVE,>
AMD Features=0x28100800<SYSCALL,NX,RDTSCP,LM>
AMD Features2=0x1
TSC: P-state invariant
-msse3 -mfpmath=sse
You will find below the code I used to compare std::exp and fmath::exp...
./myTest -s 711 is OK
./myTest -f 711 is not
include <math.h>
include <memory.h>
include <stdio.h>
include <stdlib.h>
include <time.h>
include <emmintrin.h>
include "fmath.hpp"
include "xbyak/xbyak_util.h"
int main(int argc, char** argv)
{
if (argc!=3)
{
printf("usage : ./test -s(=std) -f(=fast) integer (=loop count)\n" );
exit(1);
}
int loopCount = atoi(argv[2]);
double* vals = (double*)malloc(loopCount*sizeof(double));
int sign = -1;
for (int i=0; i < loopCount;i++)
{
vals[i] = sign*i;
}
double sum = 0;
if (argv[1][1] == 'f')
{
printf("fast\n");
for (int i=0; i < loopCount;i++)
{
sum += fmath::expd(vals[i]);
}
}
else
{
printf("standard\n");
for (int i=0; i < loopCount;i++)
{
sum += exp(vals[i]);
}
}
printf("sum is : %5.30f\n",sum);
}
Thanks a lot for your great work !
Gwen
Thank you for your review.
fmath::expd does not check small x such that exp(x) = 0, so I fixed it.
fmath::exp(float) already does it.