Support for {$EXCESSPRECISION ON/OFF} switch
Original Reporter info from Mantis: jay3d
-
Reporter name: Jameel Halabi
Original Reporter info from Mantis: jay3d
- Reporter name: Jameel Halabi
Description:
Hi,
Porting several libraries and components to FreePascal from Delphi,
related to a GUI library I'm developing, I've found that
calculations involving single precision floating point numbers always default to double precision.
This is under Win64.
Found here about the $MINFPCONSTPREC directive:
http://www.freepascal.org/docs-html/prog/progsu49.html
I guess it was like the {$EXCESSPRECISION OFF} in Delphi XE2.
But doesn't work either.
And doesn't look like there is a $MAXFPCONSTPREC in FPC.
I made my own Sin and Cos fucntions which supports Single,
because in FPC all math functions is forcibly double???
That is a problem for many tasks because it imposes unnecesary
slow calculations slowing it down in 64 bits,
where the original code intention is to use single precision floats
Here are two snippets of code with their corresponding assembler:
d := d * (0.96 + Cos(d * PI) * 0.05);
cvtss2sd xmm1,DWORD PTR [rdx]
cvtss2sd xmm0,DWORD PTR [rdx]
mulsd xmm0,QWORD PTR [rip+0x171358]
movsd QWORD PTR [rbp-0x10],xmm0
fld QWORD PTR [rbp-0x10]
fcos
fstp QWORD PTR [rbp-0x10]
movsd xmm0,QWORD PTR [rbp-0x10]
mulsd xmm0,QWORD PTR [rip+0x171346]
addsd xmm0,QWORD PTR [rip+0x17132e]
mulsd xmm0,xmm1
cvtsd2ss xmm0,xmm0
movss DWORD PTR [rdx],xmm0
r := r + (ARandomNumber - 0.5) * 0.05;
cvtss2sd xmm1,DWORD PTR [rax]
movss xmm0,DWORD PTR [rip+0x1e0cb6]
subss xmm0,DWORD PTR [rip+0x171326]
cvtss2sd xmm0,xmm0
mulsd xmm0,QWORD PTR [rip+0x171312]
addsd xmm0,xmm1
cvtsd2ss xmm0,xmm0
movss DWORD PTR [rax],xmm0
Now with the custom Sin and Cos and putting Single around each constant (which is ugly BTW):
function Cos(const X: Single): Single; nostackframe;
const temp: DWord = 0;
asm
movd temp, xmm0
fld temp
fcos
fstp temp
movss xmm0, temp
end;
d := d * (Single(0.96) + Cos(d * Single(PI)) * Single(0.05));
movss xmm0,DWORD PTR [rsi]
mulss xmm0,DWORD PTR [rip+0x171314]
call 0x4296b0 <COS>
mulss xmm0,DWORD PTR [rip+0x17130f]
addss xmm0,DWORD PTR [rip+0x1712f7]
mulss xmm0,DWORD PTR [rsi]
movss DWORD PTR [rsi],xmm0
r := r + (ARandomNumber - 0.5) * Single(0.05);
movss xmm0,DWORD PTR [rip+0x1e0c67]
subss xmm0,DWORD PTR [rip+0x1712f7]
mulss xmm0,DWORD PTR [rip+0x1712e7]
addss xmm0,DWORD PTR [rbx]
movss DWORD PTR [rbx],xmm0
Mantis conversion info:
- Mantis ID: 21151
- OS: Windows
- OS Build: 7 x64
- Platform: x86_64
- Version: 2.6.0
- Fixed in version: 3.0.0
- Fixed in revision: 20190 (#74e72151)
- Monitored by: » jay3d (Jameel Halabi)