flat assembler
Message board for the users of flat assembler.

Index > Main > Intel AMX extension

Author
Thread Post new topic Reply to topic
Ali.Z



Joined: 08 Jan 2018
Posts: 822
Ali.Z 18 Jan 2022, 05:48
https://en.wikichip.org/wiki/x86/amx

not sure how old are these instructions, but AFAIK this is the latest extension.
it looks like it could be useful for this type of software that does math, graphics and/or games.

edit:
also does fasm support these things Rolling Eyes just curious Smile

_________________
Asm For Wise Humans
Post 18 Jan 2022, 05:48
View user's profile Send private message Reply with quote
Tomasz Grysztar



Joined: 16 Jun 2003
Posts: 8454
Location: Kraków, Poland
Tomasz Grysztar 18 Jan 2022, 12:01
The previous thread about it went completely off the rails.

I keep this extension in mind, I want to implement it, but with no hurry. I'm likely to start with a fasmg cpu/ext package, as this is generally the route I take these days.
Post 18 Jan 2022, 12:01
View user's profile Send private message Visit poster's website Reply with quote
sylware



Joined: 23 Oct 2020
Posts: 503
Location: Marseille/France
sylware 18 Jan 2022, 22:16
isn't that risc-v gpu?
Post 18 Jan 2022, 22:16
View user's profile Send private message Reply with quote
Ali.Z



Joined: 08 Jan 2018
Posts: 822
Ali.Z 23 Jan 2022, 09:56
Tomasz Grysztar wrote:
previous thread


i think i missed that thread, sorry Very Happy

_________________
Asm For Wise Humans
Post 23 Jan 2022, 09:56
View user's profile Send private message Reply with quote
ohara



Joined: 13 Oct 2006
Posts: 21
ohara 02 Oct 2025, 16:42
Are AMX instructions in FASM yet?
Post 02 Oct 2025, 16:42
View user's profile Send private message Reply with quote
Tomasz Grysztar



Joined: 16 Jun 2003
Posts: 8454
Location: Kraków, Poland
Tomasz Grysztar 02 Oct 2025, 16:53
ohara wrote:
Are AMX instructions in FASM yet?
Not yet, and it's likely that only fasm2 may have them.
Post 02 Oct 2025, 16:53
View user's profile Send private message Visit poster's website Reply with quote
Tomasz Grysztar



Joined: 16 Jun 2003
Posts: 8454
Location: Kraków, Poland
Tomasz Grysztar 03 Oct 2025, 14:18
Intel AMX instructions support for fasm2 is ready: https://github.com/tgrysztar/fasm2/commit/eee0e48d67ce97d0c3241a7f80937b0f2e11b9f9
Quick and dirty, but that's the advantage of fasmg-based implementation: rapid prototyping is easy.
Post 03 Oct 2025, 14:18
View user's profile Send private message Visit poster's website Reply with quote
Feryno



Joined: 23 Mar 2005
Posts: 517
Location: Czech republic, Slovak republic
Feryno 03 Oct 2025, 19:27
Tomasz - great job !!!!!

I have Xeon 6300 series CPUs (entry level server) 6315P, 6369P and they both lack AMX. You need datacenter or AI level Xeon 6 family to run AMX (that is 6700 or 6500 family)
this is the detection code:
Code:
        mov     eax,1
        cpuid
        bt      ecx,26  ; bit 26 XSAVE: XSAVE (and related) instructions are supported by hardware
        jnc     exit

; Software can use CPUID leaf function 0DH to enumerate the bits in XCR0 that the processor supports
        xor     eax,eax
        cpuid
        cmp     eax,0Dh
        jc      exit            ; CPUID with eax=0Dh not available

        xor     ecx,ecx
        lea     eax,[rcx+0Dh]
        cpuid

        mov     ecx,(1 shl 18) or (1 shl 17)    ; Bit 17: TILECFG state.
                                                ; Bit 18: TILEDATA state.
        and     eax,ecx
        cmp     eax,ecx
        jnz     exit
; highest present bit at Xeon 6300 series is bit 9. PKRU state
; bits 17, 18 are zeros
; if your CPU has these bits present, you can enable the AMX in the XCR0

        mov     rax,cr4
        bts     rax,18
; XSAVE and Extended States (OSXSAVE) Bit. Bit 18. If this bit is set to 1 then the operating system
; supports the XGETBV, XSETBV, XSAVE and XRSTOR instructions. The processor will also be able
; to execute XGETBV and XSETBV instructions in order to read and write XCR0. Also, if set, the
; XSAVE and XRSTOR instructions can save and restore the x87 FPU state (including MMX registers),
; the SSE state (YMM/XMM registers and MXCSR), along with other processor extended states
; enabled in XCR0.
        mov     cr4,rax

; CPUID.01H:ECX.OSXSAVE[bit 27]) now should be 1
        mov     eax,1
        cpuid
        bt      ecx,27
        jnc     exit

        xor     ecx,ecx
        xgetbv                          ; get XCR0

        or      eax,(1 shl 18) or (1 shl 17)
; XCR0.TILECFG (bit 17.) : If 1, and if XCR0.TILEDATA is also 1, Intel AMX instructions can be executed and the XSAVE feature set can be used to manage TILECFG.
; XCR0.TILEDATA (bit 18.) : If 1, and if XCR0.TILECFG is also 1, Intel AMX instructions can be executed and the XSAVE feature set can be used to manage TILEDATA.
; !!!!! of course you need to enable more bits than only bits 17, 18 - enable also some lower bits like MMX, SSE, AVX, very likely also ZMM_Hi256, Hi16_ZMM - chapter 2.6. in Intel 64 and IA-32 Architectures Software Developer’s Manual Volume 3 System Programming Guide

        xsetbv                          ; set XCR0    


note the code needs ring0 privilege but the detection (CPUID part) can be executed also from ring3
you can play with it under UEFI shell if you have AMX capable CPU but your OS is not the most recent one (when the OS does not enable AMX even it is present)
Post 03 Oct 2025, 19:27
View user's profile Send private message Visit poster's website ICQ Number 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.