flat assembler
Message board for the users of flat assembler.

Index > Main > when to use FWAIT?

Author
Thread Post new topic Reply to topic
ProphetOfDoom



Joined: 08 Aug 2008
Posts: 120
Location: UK
ProphetOfDoom 07 Dec 2010, 23:52
Hi,

I've been googling but can't find an answer to my question. The Simply FPU tutorial seems a bit vague on the subject. Do I need an FWAIT instruction in this code?

Code:
push 1.5 ; push any old float
fadd dword [esp] ; add [esp] to st
add esp, 4 ; restore the old value of esp
    


In other words, is there a danger that the third instruction might finish executing before the second one?

Thanks in advance.
Post 07 Dec 2010, 23:52
View user's profile Send private message Reply with quote
nop



Joined: 01 Sep 2008
Posts: 165
Location: right here left there
nop 08 Dec 2010, 04:54
afaik the answer to both questions is no

afaik all potential synchronisation conflicts between cpu and fpu are handled automatically in modern processors except where exceptions are raised and flag testing instructions are involved. thats where wait or fwait is needed

here for a conflict to arise the cpu would have to finish the 3rd instruction before the fpu had read the operand data of the 2nd instruction. when the fpu actually finishes the fadd instruction is not critical (except maybe for any subseqent compare instructions handled by the cpu)

but at the end of the day only thorough testing of your code will prove it one way or the other
Post 08 Dec 2010, 04:54
View user's profile Send private message Reply with quote
MazeGen



Joined: 06 Oct 2003
Posts: 977
Location: Czechoslovakia
MazeGen 08 Dec 2010, 08:24
As nop said, WAIT checks for pending FP exceptions so you don't need it.

WAIT is documented well in offical processor manuals:

http://x86asm.net/links/index.html#Processor-Manuals
Post 08 Dec 2010, 08:24
View user's profile Send private message Visit poster's website Reply with quote
mindcooler



Joined: 01 Dec 2009
Posts: 423
Location: Västerås, Sweden
mindcooler 08 Dec 2010, 08:48
But you still need it at compares?
Code:
                ficomp  [ecx]
                (implicit wait)
                fstsw   ax
                fwait
                sahf    

_________________
This is a block of text that can be added to posts you make.
Post 08 Dec 2010, 08:48
View user's profile Send private message Visit poster's website MSN Messenger ICQ Number Reply with quote
ProphetOfDoom



Joined: 08 Aug 2008
Posts: 120
Location: UK
ProphetOfDoom 08 Dec 2010, 12:33
Thanks for clarifying guys.
Post 08 Dec 2010, 12:33
View user's profile Send private message Reply with quote
Display posts from previous:
Post new topic Reply to topic

Jump to:  


< Last Thread | Next Thread >
Forum Rules:
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You cannot attach files in this forum
You can download files in this forum


Copyright © 1999-2025, Tomasz Grysztar. Also on GitHub, YouTube.

Website powered by rwasa.