flat assembler
Message board for the users of flat assembler.
![]() Goto page 1, 2 Next |
Author |
|
ouadji 30 Apr 2011, 21:07
Does FISTP write atomically if the memory target is not aligned on 64 bits boundary ? |
|||
![]() |
|
revolution 01 May 2011, 01:33
No.
Unaligned memory writes are never guaranteed to be atomic, no matter what instruction you use for writing. It is in the docs. |
|||
![]() |
|
ouadji 01 May 2011, 07:21
Quote:
but, clic in this page: this is what gave me a doubt! Quote:
|
|||
![]() |
|
ouadji 01 May 2011, 15:49
Quote:
inside the Fpu, with 64 bits for the mantissa, yes, an integer will never be rounded. (not true with 64bits or 32 bits float, but with 80 bits, yes) Code: __asm { mov edi, p fild qword ptr [value] fistp qword ptr [edi] } where have you seen C ? |
|||
![]() |
|
Madis731 01 May 2011, 16:21
Intel System Programming Guide 3A wrote:
...so you are asking for trouble if you trust this construct. What you are meant to do is put your FPU instructions in a lock (where lock is gained through guaranteed atomic instructions) so you can use them without worries. Guaranteed atomic operations are described in 8.1.1 I cannot find in the documentation a proof to the comment that CMPXCHG8 uses an implicit lock: wrote:
|
|||
![]() |
|
ouadji 01 May 2011, 16:39
1) fild (end fist) does not accesses data larger than a qword 2) "Guaranteed atomic operations are described in 8.1.1" thank you, but I know and I use that long ago. cmpxchg8b, lock ... Here, with the fpu, it's just for the fun. ![]() "cmpxchg8b" does not use a implicit lock only true with "xchg" i use this ... 300% ok. Code: push ss pop ss lock cmpxchg8b [esi] |
|||
![]() |
|
Madis731 01 May 2011, 16:52
If fild/fist combo does not access data larger than a qword then your data might be rounded according to floating point rules.
When you want your lock to work, you need to have 80-bit fild/fist and that is definitely NOT guaranteed to be atomic (1 QWORD+1 WORD). |
|||
![]() |
|
ouadji 01 May 2011, 17:38
Quote:
fild and fist, read an write max a 1 qword ...not 1 qword + 1 word |
|||
![]() |
|
Madis731 01 May 2011, 18:07
Oops, my bad! I was not thinking it through - of course fild/fist qword[mem] will work.
|
|||
![]() |
|
revolution 02 May 2011, 01:13
Madis731 wrote: Oops, my bad! I was not thinking it through - of course fild/fist qword[mem] will work. Only FILD is guaranteed not to round. FISTP does not offer that guarantee. AFAIK all current implementations of FISTP do work but the docs provide no guarantee of that. Use at your own risk. Why not just use MMX? That is the sort of thing it is meant for. |
|||
![]() |
|
ouadji 02 May 2011, 07:12
with FIST, it's mathematical ! with 64 bits of mantissa, it is simply impossible that an integer be rounded! or so, 1+1 is no longer equal to 10 Quote: FILD (intel 2A) FIST will always store an integral value. Quote: Why not just use MMX? That is the sort of thing it is meant for. ![]() |
|||
![]() |
|
revolution 02 May 2011, 08:52
ouadji: Don't for get about the precision setting within the FPU. Sometimes even integers get rounded to other integers. Also the rounding setting has four modes.
|
|||
![]() |
|
ouadji 02 May 2011, 09:42
it's just a left shift of the mantissa by the exponent. the rounding is not possible with an integer and a 64 bits mantissa. Whatever the rounding ... since there will be no rounding. revolution, give me an example of rounding with an integer/fild/fist ... and I'm moving to offer you a drink! ![]() A integer FILD A FIADD 0 FIST A my god, the result would not be always equal to A |
|||
![]() |
|
revolution 02 May 2011, 10:34
ouadji: I'm not arguing about the technical ability of an 80 bit FPU register to store a 64 bit value without error. I already stated above that all current implementations that I know of can, and do, recover the integer without error. But you must understand that the documents do not guarantee this behaviour.
If someone were to change the precision mode to 24 bits can you guarantee that all future incarnations of the FPU in all CPUs will not truncate the internal value to 24 bits before conversion to integer? |
|||
![]() |
|
bitshifter 02 May 2011, 10:47
Code: fild [int] fiadd [zero] fistp [int] Not sure what youre getting at but input == output here... Although float -> integer rounds down below 0.5, and up if above... Ex: Code: fld [f14] ;1.4 fistp [int] ;rounds down to 1 fld [f15] ;1.5 fistp [int] ;rounds up to 2 Or are we talking the other way around (int -> float) ??? _________________ Coding a 3D game engine with fasm is like trying to eat an elephant, you just have to keep focused and take it one 'byte' at a time. |
|||
![]() |
|
revolution 02 May 2011, 11:15
ouadji wrote: FILD A Now, let's be sure to add that if you were to try this on your x86 FPU then currently you would not find any problem. But once again, this is not guaranteed. The result is only guaranteed to have enough bits as required by the precision setting. The fact that you currently get more bits of precision is just a bonus and should not be relied upon to always be true. |
|||
![]() |
|
ouadji 02 May 2011, 18:51
Quote: The 24 bit result of adding... Code: FILD qword[A] ;80bits float(16+64) <--- 64 bits integer FIADD dword[B] ;32 bits FISTP qword[A] ;80bits float(16+64) ---> 64 bits integer where do you see 24-bit here ? |
|||
![]() |
|
revolution 02 May 2011, 23:55
ouadji wrote: where do you see 24-bit here ? Let me ask you this: Would you agree that the following should not change the value of [value]? Code: fild qword[value] fld1 fdivp ;st0 = value / 1 fistp qword[value] |
|||
![]() |
|
ouadji 03 May 2011, 00:37
you won! checkmate! ![]() |
|||
![]() |
|
Goto page 1, 2 Next < Last Thread | Next Thread > |
Forum Rules:
|
Copyright © 1999-2023, Tomasz Grysztar. Also on GitHub, YouTube.
Website powered by rwasa.