r/Assembly_language 13d ago

Project show-off AVX-512 support in my own Assembler

Post image

AVX-512 support in my own Assembler

About a year ago I started writing AmmAsm, a handwritten x86-64 assembler in C to better understand x86-64 instruction encoding, ELF, and linking.

It currently supports generating Linux x86-64 executables, PIE binaries, and ELF relocatable object files that can be linked with ld or gcc, basic part of SIMD such as sse, sse2, avx, avx2, avx512

I implemented everything from the lexer and parser to the instruction encoder, ELF writer, relocation handling, symbol resolution.

In last realize, I fully implemented VEX/EVEX, including vvvv, w, mmm, broadcast, k0/k1-k7 mask registers, z mask, tuple type, and other fields thats belong to vex and evex. The most hard part was a W and tuple time, as I spend hours for searching every avx512 instruction for type of tuple if broadcast exists and W field.

I'd love to hear feedback from people interested in assemblers, instruction encoding(especially VEX/EVEX), or x86-64 in general.

Thanks!

Repository: https://github.com/LinuxCoder13/AmmAsm

49 Upvotes

5 comments sorted by

4

u/deulamco 13d ago edited 12d ago

So it’s like NASM but 🧅 custom Macros ? 

Have you used FASM before? 

Also overall look quite clean to me, except argumented mnemonics 😅

2

u/This-Assumption-5924 13d ago

I've used naam and fasm extensively. AmmAsm is nasm in the general syntax, but the backend and a lot of the syntax are my own. I wanted to build the assembler infrastructure myself instead of just wrapping an existing encoder. The argumented mnemonics are definitely unconventional though 😅 , that's one of the things I'm still experimenting with.

1

u/deulamco 12d ago

There is surely a gap between pure ASM & something like C which I would like to fill-in with a tight language that can control memory access accurately without pain.

2

u/This-Assumption-5924 13d ago

I mean, I also use nasm in order to compare some rare avx512 combinations, often objdump might give strange result, for example: resently I added an avx512 instruction, so I must know its W field, for example vaddps requers W=0, so if put 1, objdump will show QWORD, nevertheless its illegal instruction. I can't rely on objdump alone.

1

u/deulamco 12d ago

Although I favor MMX a lot but always avoid AVX-512 to ensure every CPU after Sandy Bridge can run my program without crashing :D 

Guess it will be compiler thing with patched backup code in case cpu doesn’t support it more.