由买买提看人间百态

topics

全部话题 - 话题: fldcw
(共0页)
z******i
发帖数: 59
1
来自主题: Programming版 - double转换int的问题
It is a truncation. You can write a simple C code, and check its
assemly to figure out what it is doing. X86 has the fistpl (convert float to
integer) instruction to do that.
But be careful if performance is important in your code. Since the
conversion
is very slow (stall FPU due to fldcw - load FPU control word).
146 80483ee: d9 6d e4 fldcw -0x1c(%ebp)
147 80483f1: db 5d f4 fistpl -0xc(%ebp)
148 80483f4: d9 6d e6 fldcw -0x1a(%ebp)
int to
z******i
发帖数: 59
2
来自主题: Programming版 - round function in math
This code might be very slow.
It will be translated to something like the following assemly code.
fldcw [ebp-4] ;Write new value to FCW
fistp DWORD PTR [ebp-16] ;Convert fvalue to integer
;and pop stack
fldcw [ebp-12] ;Restore FCW to its
;original state
It is a serial code in CPU because it changes FPU's control word.
A better solution is using SSE, 4 float one time
(共0页)