![]() |
|
|
#12 | |
|
Tribal Bullet
Oct 2004
3,541 Posts |
Quote:
I don't know about more modern processors; the big drawback to this method is that you do a store of one size to memory and a load of a different size to the same memory. That may cause big stalls, or it may not, because hardware designers know lots of people used to use this trick. jasonp |
|
|
|
|
|
|
#13 | |
|
Nov 2003
22×5×373 Posts |
Quote:
on the Pentium please tell me if the finit is NEEDED?? Thanks. |
|
|
|
|
|
|
#14 | |
|
Banned
"Luigi"
Aug 2002
Team Italia
32×5×107 Posts |
Quote:
My wild guess is that the FPU and the CPU in the chip of a Pentium-like processor are reset together at the same time. Michael L. Schmit (Pentium processor optimization tools, AP-Professional, founder of Quantasm Corp.) seems to think the same: he never delved into FINIT instruction in his book. Well, he didn't find out the Pentium bug either... Just my 0.02 euro... Luigi |
|
|
|
|
|
|
#15 | |
|
Nov 2003
11101001001002 Posts |
Quote:
will cause problems elsewhere. |
|
|
|
|
|
|
#16 |
|
Aug 2002
Buenos Aires, Argentina
2·683 Posts |
In a program I wrote in assembler using inline assembly in Visual C++, I had to use the instruction FINIT in order to restore the full precision of the coprocessor.
It appears that Visual C++ sets the precision to 53 bits. After I executed the instruction FINIT the precision was incremented to 64 bits that's what I needed in that program. |
|
|
|
|
|
#17 |
|
"Nancy"
Aug 2002
Alexandria
246710 Posts |
According to the Intel Instruction Set Reference, FINIT initialises the FPU state to default values: round to nearest, 64 bit precision, all exceptions masked. Afaik it needs to be issued once per process before that process uses the FPU to get a well-defined state (not sure about that, though). In any case it should not be issued before every double->int conversion, the FINIT is almost certainly a serialising instruction and will flush the pipeline again.
Alex |
|
|
|
|
|
#18 |
|
Banned
"Luigi"
Aug 2002
Team Italia
113178 Posts |
I found this piece of (assembly) code that may look interesting to you in Agner Fog sources:
Code:
; TRUNCATE.ASM Agner Fog 2004
; © 2003 GNU General Public License www.gnu.org/copyleft/gpl.html
.686
.xmm
.model flat
extrn instrset:dword, InstructionSet:near
PublicAlias MACRO MangledName ; macro for giving a function alias public names
MangledName label near
public MangledName
ENDM
.code
; ********** Truncate function **********
; C++ prototype:
; extern "C" int Truncate (double x);
; This function converts a double precision floating point number to
; an integer, rounding towards zero.
; This function is faster than the default conversion method in C++.
; Uses SSE2 instruction set if possible.
; For the sake of speed, there is no special overflow check. In case of
; overflow, you may get an exception or an invalid result.
Truncate PROC NEAR
PUBLIC Truncate
PublicAlias _Truncate ; Underscore needed when called from Windows
cmp [instrset], 4 ; can we use XMM instructions?
jl NO_SSE2
; SSE2 (XMM) instruction set:
cvttsd2si eax, [esp+4] ; use truncation instruction
ret
NO_SSE2:cmp [instrset], 0
jl DETECT_INSTRUCTIONSET
; default instruction set:
fld qword ptr [esp+4] ; x
sub esp, 12 ; space for local variables
fist dword ptr [esp] ; rounded value
fst dword ptr [esp+4] ; float value
fisub dword ptr [esp] ; subtract rounded value
fstp dword ptr [esp+8] ; difference
pop eax ; rounded value
pop ecx ; float value
pop edx ; difference (float)
test ecx, ecx ; test sign of x
js SHORT NEGATIVE
add edx, 7FFFFFFFH ; produce carry if difference < -0
sbb eax, 0 ; subtract 1 if x-round(x) < -0
ret
NEGATIVE:
xor ecx, ecx
test edx, edx
setg cl ; 1 if difference > 0
add eax, ecx ; add 1 if x-round(x) > 0
ret
DETECT_INSTRUCTIONSET: ; first time call. detect instruction set
call InstructionSet
jmp Truncate
Truncate ENDP
END
cvttsd2si eax, [esp+4] ; use truncation instruction HTH Luigi Last fiddled with by ET_ on 2005-07-26 at 19:14 |
|
|
|
|
|
#19 | |
|
Nov 2003
22×5×373 Posts |
Quote:
What is the exact name of this book?
|
|
|
|
|
|
|
#20 | |
|
P90 years forever!
Aug 2002
Yeehaw, FL
2×53×71 Posts |
Quote:
If you change the rounding mode, then you must set it back - either with FINIT or by manipulating the rounding control bits. |
|
|
|
|
|
|
#21 | |
|
Nov 2002
11 Posts |
Quote:
Here's a link for further info about this book: http://portal.acm.org/citation.cfm?id=188852 |
|
|
|
|
|
|
#22 | |
|
Banned
"Luigi"
Aug 2002
Team Italia
481510 Posts |
Quote:
"Pentium processor optimization tools" AP Professional ISBN 0-12-627230-1 Luigi (whoops... already answered )
Last fiddled with by ET_ on 2005-07-27 at 19:16 |
|
|
|
|
![]() |
Similar Threads
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| A Challenge on the net | devarajkandadai | Miscellaneous Math | 0 | 2012-05-31 05:17 |
| When I was your age.....CHALLENGE | petrw1 | Lounge | 14 | 2009-11-23 02:18 |
| Challenge | science_man_88 | Miscellaneous Math | 229 | 2009-09-07 08:08 |
| rsa-640 challenge | ValerieVonck | Factoring | 58 | 2005-10-24 15:54 |
| Who is Challenge? | JuanTutors | PrimeNet | 2 | 2004-07-22 12:56 |