flat assembler
Message board for the users of flat assembler.

Index > Main > [fasmg] sad spinlock

Author
Thread Post new topic Reply to topic
sylware



Joined: 23 Oct 2020
Posts: 228
Location: Marseille/France
sylware 24 Jan 2023, 14:16
no "pause" machine instruction in the standard distribution or I did grep like an animal?
Post 24 Jan 2023, 14:16
View user's profile Send private message Reply with quote
Tomasz Grysztar



Joined: 16 Jun 2003
Posts: 8103
Location: Kraków, Poland
Tomasz Grysztar 24 Jan 2023, 14:34
This one is really easy to implement, likely for everyone:
Code:
macro pause?
        db 0F3h, 90h
end macro    
Also, it's actually the same as:
Code:
        rep nop    
Post 24 Jan 2023, 14:34
View user's profile Send private message Visit poster's website Reply with quote
sylware



Joined: 23 Oct 2020
Posts: 228
Location: Marseille/France
sylware 24 Jan 2023, 14:39
Are you going to add "pause" to fasmg distribution?
Post 24 Jan 2023, 14:39
View user's profile Send private message Reply with quote
Tomasz Grysztar



Joined: 16 Jun 2003
Posts: 8103
Location: Kraków, Poland
Tomasz Grysztar 24 Jan 2023, 14:46
I don't know, there's lot of things I could add, I focus on ones I personally find the most valuable. The idea was, once everything is easily customizable, then it should be relatively easy for others to implement instruction sets they require when I'm not up to the task.
Post 24 Jan 2023, 14:46
View user's profile Send private message Visit poster's website Reply with quote
revolution
When all else fails, read the source


Joined: 24 Aug 2004
Posts: 19087
Location: In your JS exploiting you and your system
revolution 24 Jan 2023, 14:51
Code:
pause equ db 0xf3, 0x90    
Solved. Smile
Post 24 Jan 2023, 14:51
View user's profile Send private message Visit poster's website Reply with quote
sylware



Joined: 23 Oct 2020
Posts: 228
Location: Marseille/France
sylware 24 Jan 2023, 14:53
Well, if you don't use spin locks... that's not going to be very valuable Confused
Post 24 Jan 2023, 14:53
View user's profile Send private message Reply with quote
sylware



Joined: 23 Oct 2020
Posts: 228
Location: Marseille/France
sylware 24 Jan 2023, 14:59
@revolution I was thinking it was mistakenly missing from the official distribution. Because using spinlocks is quite common in parallel programming and the "right" implementation on x86_64 uses the pause machine instruction.
Post 24 Jan 2023, 14:59
View user's profile Send private message Reply with quote
revolution
When all else fails, read the source


Joined: 24 Aug 2004
Posts: 19087
Location: In your JS exploiting you and your system
revolution 24 Jan 2023, 15:07
PAUSE was first defined on the P4. So even 32-bit code can benefit from it.

Older CPUs just see rep nop, no benefit for them, but also no harm.
Post 24 Jan 2023, 15:07
View user's profile Send private message Visit poster's website Reply with quote
FlierMate11



Joined: 13 Oct 2022
Posts: 48
FlierMate11 24 Jan 2023, 15:45
I insert "rep nop" in FASM source file, but compiled program is disassembled as "pause".

So revolution is right.


Description:
Filesize: 12.61 KB
Viewed: 302 Time(s)

Screenshot 2023-01-24 234415.png


Post 24 Jan 2023, 15:45
View user's profile Send private message Visit poster's website Reply with quote
macomics



Joined: 26 Jan 2021
Posts: 701
Location: Russia
macomics 24 Jan 2023, 15:54
Your debugger does not allow you to choose the disassembly mode. Open the program in IDA Pro and select different processors. Before Pentium 4, you will be issued a rep nop

ADD: You also assemble the sequence
Code:
rep xchg eax, eax    
and it will also turn into pause
Post 24 Jan 2023, 15:54
View user's profile Send private message Reply with quote
FlierMate11



Joined: 13 Oct 2022
Posts: 48
FlierMate11 24 Jan 2023, 16:12
macomics wrote:

ADD: You also assemble the sequence
Code:
rep xchg eax, eax    
and it will also turn into pause


Yeah, I see it now, is it designed this way?


Description:
Filesize: 7.88 KB
Viewed: 290 Time(s)

Screenshot 2023-01-25 001121.png


Post 24 Jan 2023, 16:12
View user's profile Send private message Visit poster's website Reply with quote
revolution
When all else fails, read the source


Joined: 24 Aug 2004
Posts: 19087
Location: In your JS exploiting you and your system
revolution 24 Jan 2023, 16:23
Note that xchg eax,eax encoded as 0x90 is not valid for x64 code. It is a true nop and won't zero the upper 32-bits of rax.

In 64-bit code use db 0x87, 0xc0.
Post 24 Jan 2023, 16:23
View user's profile Send private message Visit poster's website Reply with quote
DimonSoft



Joined: 03 Mar 2010
Posts: 1152
Location: Belarus
DimonSoft 26 Jan 2023, 08:11
revolution wrote:
Code:
pause equ db 0xf3, 0x90    
Solved. Smile

Wouldn’t a macro be a better solution? pause probably shouldn’t be used everywhere, just in places where an instruction name is allowed. (I completely ignore the fasmg branch, so may miss something here.)
Post 26 Jan 2023, 08:11
View user's profile Send private message Visit poster's website Reply with quote
revolution
When all else fails, read the source


Joined: 24 Aug 2004
Posts: 19087
Location: In your JS exploiting you and your system
revolution 26 Jan 2023, 08:17
I suppose a macro would be better. But I don't know the fasmg syntax for macros so I just took the easy path and posted what I do know.
Post 26 Jan 2023, 08:17
View user's profile Send private message Visit poster's website Reply with quote
Tomasz Grysztar



Joined: 16 Jun 2003
Posts: 8103
Location: Kraków, Poland
Tomasz Grysztar 26 Jan 2023, 09:04
revolution wrote:
I suppose a macro would be better. But I don't know the fasmg syntax for macros so I just took the easy path and posted what I do know.
This actually wouldn't work with fasmg, for a reason very similar to why you cannot do "mc equ macro" in fasm 1. In fasmg this extends to all instructions and therefore EQU becomes limited to replacements in the expressions arguments. In fasmg's terminology it's the separation of symbols into three classes: instruction class, expression class, and also "labeled instruction" class for things like structure macros (but also EQU itself is a "labeled instruction").
Post 26 Jan 2023, 09:04
View user's profile Send private message Visit poster's website Reply with quote
revolution
When all else fails, read the source


Joined: 24 Aug 2004
Posts: 19087
Location: In your JS exploiting you and your system
revolution 26 Jan 2023, 09:11
Okay. I cheated to took the 8087.inc as a template and made this:
Code:
macro pause?
        db 0xf3, 0x90
end macro    
I have no idea if it works or not. Embarassed

What is the ? for?
Post 26 Jan 2023, 09:11
View user's profile Send private message Visit poster's website Reply with quote
Tomasz Grysztar



Joined: 16 Jun 2003
Posts: 8103
Location: Kraków, Poland
Tomasz Grysztar 26 Jan 2023, 09:19
revolution wrote:
I have no idea if it works or not. Embarassed
You actually reproduced the macro I posted in the beginning of this thread.

revolution wrote:
What is the ? for?
It defines the symbol as case-insensitive.

PS. Also, usually you can adapt fasmg to work the way you need:
Code:
pause? equ db 0xf3, 0x90

calminstruction ? line&
        transform line
        assemble line
end calminstruction

pause    
But this like opening a can of... bugs. Good luck if you need to re-define an equate etc.

PPS. Actually, I forgot I have a better option now:
Code:
calminstruction ?? line&
        transform line
        assemble line
end calminstruction

pause? equ db 0xf3, 0x90

pause   

pause? equ db 0F3h, 90h

pause    


Last edited by Tomasz Grysztar on 26 Jan 2023, 09:48; edited 2 times in total
Post 26 Jan 2023, 09:19
View user's profile Send private message Visit poster's website Reply with quote
revolution
When all else fails, read the source


Joined: 24 Aug 2004
Posts: 19087
Location: In your JS exploiting you and your system
revolution 26 Jan 2023, 09:25
Tomasz Grysztar wrote:
You actually reproduced the macro I posted in the beginning of this thread.
Oh, yeah I did (but with better hexification Razz). That'll teach me for not properly reveiwing the thread. Embarassed
Tomasz Grysztar wrote:
revolution wrote:
What is the ? for?
It defines the symbol as case-insensitive.
I like that feature. Smile fasm also needs that. Very Happy
Post 26 Jan 2023, 09:25
View user's profile Send private message Visit poster's website 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-2023, Tomasz Grysztar. Also on GitHub, YouTube, Twitter.

Website powered by rwasa.