flat assembler
Message board for the users of flat assembler.

Index > Compiler Internals > [fasmg] x86 'pause' instruction | format/AVX .inc conflict

Author
Thread Post new topic Reply to topic
Jessé



Joined: 03 May 2025
Posts: 44
Jessé 14 May 2025, 20:24
I can't find the 'pause' instruction (db 0F3h, 90h) anywhere else in the cpu include files bundled with fasmg. Is it missing? Where would be the correct (recommended) place to append it in the current bundled files?

Code:
macro pause?
  db 0F3h, 90h
end macro
    


I also have found a problem when trying to include 'avxX.inc' files together with 'format/format.inc' file.
It gaves me the following error:

Quote:
─ ❯ fasmg error.fasmg
flat assembler version g.kp60
error.fasmg [4] ../include/cpu/ext/avx2.inc [7] ../include/cpu/ext/avx.inc [7] ../include/cpu/ext/sse4.2.inc [2] ../include/cpu/ext/sse4.1.inc [2] ../include/cpu/ext/ssse3.inc [2] ../include/cpu/ext/sse3.inc [2] ../include/cpu/ext/sse2.inc [7] ../include/cpu/ext/sse.inc [7] ../include/cpu/ext/mmx.inc [48]:
xcall x86.store_instruction@src, <0Fh,ext>,@dest.rm
Processed: xcall x86.store_instruction@src, <0Fh,ext>,@dest.rm
Error: unexpected instruction.
[exit=2]


Example code (which triggers error condition):

Code:
include '../include/format/format.inc'
; include '../include/format/elfexe.inc'
; include '../include/cpu/x64.inc'
include '../include/cpu/ext/avx2.inc'
include '../include/cpu/ext/cet_ibt.inc'
include '../include/cpu/ext/cet_ss.inc'

format ELF64 executable 3

entry Start

segment readable executable

Start:                          jmp     $
                                vpxor   ymm0, ymm7, ymm15
                                vpcmpeqw ymm8, ymm9, ymm10
                                vmovdqu ymm12, yword [Start]
                                vzeroupper

    


Disabling 'format.inc' include and its parts in the code, end enabling others doesn't do any conflict.
I searched for it, but didn't find what might be wrong and causing the conflict with format.

In time: I suspect there's something wrong with 'format?.include' lines. I've commented (disabled) them, manually include in the source file what's needed using traditional 'include' directive, and problem's gone.

_________________
jesse6
Post 14 May 2025, 20:24
View user's profile Send private message Reply with quote
macomics



Joined: 26 Jan 2021
Posts: 1158
Location: Russia
macomics 14 May 2025, 20:29
[strikeout]pause = 486 or p5[/strikeout]
No.


Description:
Filesize: 196.91 KB
Viewed: 783 Time(s)

Снимок экрана_20250515_003201.png


Post 14 May 2025, 20:29
View user's profile Send private message Reply with quote
Jessé



Joined: 03 May 2025
Posts: 44
Jessé 14 May 2025, 21:50
I added to p6.inc and x64.inc in the following format:

Code:
iterate <instr,opcode>, pause,<0F3h,90h>        ; added by Jessé Gonçalves

        calminstruction instr?
                asm db opcode
        end calminstruction

end iterate
    


Now remaining only the complicated question: wht it appears that 'format?.include' excludes xcall? definition... 😅
Post 14 May 2025, 21:50
View user's profile Send private message Reply with quote
bitRAKE



Joined: 21 Jul 2003
Posts: 4226
Location: vpcmpistri
bitRAKE 15 May 2025, 01:59
Switching to the x86-2.inc processor model would be another option - seems the instruction development has progressed further.

_________________
¯\(°_o)/¯ “languages are not safe - uses can be” Bjarne Stroustrup
Post 15 May 2025, 01:59
View user's profile Send private message Visit poster's website Reply with quote
Tomasz Grysztar



Joined: 16 Jun 2003
Posts: 8417
Location: Kraków, Poland
Tomasz Grysztar 15 May 2025, 06:38
Jessé wrote:
Now remaining only the complicated question: wht it appears that 'format?.include' excludes xcall? definition... 😅
Because it's the FORMAT statement that actually includes the base instruction set, and the base instruction sets needs to be included before extensions, you need to move them after the FORMAT statement:
Code:
include 'format/format.inc'

format ELF64 executable 3

include 'cpu/ext/avx2.inc'
include 'cpu/ext/cet_ibt.inc'
include 'cpu/ext/cet_ss.inc'    
Keep in mind that this x86 implementation has been generally superseded by fasm2 project (which is based on x86-2.inc mentioned by bitRAKE above), and I maintain it mostly as an example instruction set to analyse/follow, because it's simpler. That's why its copy still comes with fasmg under "examples".
Post 15 May 2025, 06:38
View user's profile Send private message Visit poster's website Reply with quote
Jessé



Joined: 03 May 2025
Posts: 44
Jessé 15 May 2025, 16:16
Nice, problem solved. My bad about it. I've tried many things, but not the one above...

I'm trying to adapt to x86-2 as suggested. For now, I have minor issues (related with AVX2) with it at first, but I'm trying to figure out myself before opening topic here.

Either way, both of them are usually easy fixes, like both ways of reaching pause instruction, for example.
Post 15 May 2025, 16:16
View user's profile Send private message Reply with quote
Tomasz Grysztar



Joined: 16 Jun 2003
Posts: 8417
Location: Kraków, Poland
Tomasz Grysztar 15 May 2025, 16:53
Jessé wrote:
Either way, both of them are usually easy fixes, like both ways of reaching pause instruction, for example.
See also: https://board.flatassembler.net/topic.php?p=226617#226617
Post 15 May 2025, 16:53
View user's profile Send private message Visit poster's website Reply with quote
Jessé



Joined: 03 May 2025
Posts: 44
Jessé 16 May 2025, 12:37
I read it, and let +1 way of doing it there... Very Happy

The question on AVX2 instruction vmovdqa/vmovdqu remains an issue.
From now, I still not able to figure out what's wrong:

Test Code
Code:
format ELF64 executable 3
entry Start

; use everything

segment readable executable

Start:          endbr64
                xor             rbp, rbp
                vpxor           ymm14, ymm14, ymm14 ; this is fine
                vmovdqa         ymm0, [rsp]     ; this gives an error
                vmovdqu         ymm1, [rsp]     ; this too
                jmp             $
    


Using entire fasm2 environment to compile it (including the fasm2 shell script instead of fasmg.x64 executable directly knowing that it is already including fasm2.inc file), it gives this error:

Quote:
❯ fasm2 testavx2.fasm2
flat assembler version g.kp60
testavx2.fasm2 [11]:
vmovdqa ymm0, [rsp] ; this gives an error
? [4]
Processed: vmovdqa ymm0, [rsp]
Error: illegal instruction.
[exit=2]


Using fasm2 because I know it is essentially fasmg using x86-2 include.

Thanks in advance.
Post 16 May 2025, 12:37
View user's profile Send private message Reply with quote
Tomasz Grysztar



Joined: 16 Jun 2003
Posts: 8417
Location: Kraków, Poland
Tomasz Grysztar 16 May 2025, 13:08
It seems I lost these two instructions during editing. Should be fixed now.
Post 16 May 2025, 13:08
View user's profile Send private message Visit poster's website Reply with quote
Tomasz Grysztar



Joined: 16 Jun 2003
Posts: 8417
Location: Kraków, Poland
Tomasz Grysztar 16 May 2025, 15:05
There's one more thing that you should be careful with when assembling AVX instructions with fasm2, by default it has all AVX-512 instructions enabled and some of the AVX/AVX2 instructions may be optimized when EVEX displacement compression allows to make them shorter (see my earlier post about it). Perhaps the AVX-512 should not be enabled unless explicitly stated? For now you can disable it with USEAVX256 or USE AVX2, or by manually selecting instruction sets like win64avx512.asm does.
Post 16 May 2025, 15:05
View user's profile Send private message Visit poster's website Reply with quote
Jessé



Joined: 03 May 2025
Posts: 44
Jessé 16 May 2025, 19:34
Working fine now.
Thanks for the advice on AVX512.
Post 16 May 2025, 19:34
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.