Hi guys,
I'm writing a little toy brainf*ck compiler but I'm having some trouble with x86 codegen
Since brainf*ck primarily uses a big u8 array for storage, I'm emitting lots of
let old_val = b.ins().load(types::I8, mem_flags, real_ptr, static_offset_accum);
let new_val = b.ins().iadd_imm(old_val, insn_val as i64);
b.ins().store(mem_flags, new_val, real_ptr, static_offset_accum);
unfortunately these seem to get turned into manual loads and stores:
movzx rax,BYTE PTR [rcx+0x8000]
add eax,0x1
mov BYTE PTR [rcx+0x8000],al
I would have expected these to get turned into ADD r/m8, r8
, i.e. something like
add BYTE PTR [rcx+0x8000], 0x1
Does somebody have some insight into this? Seems odd to me that the x86 backend wouldn't clean that up
we have lowering rules for the 32 and 64 bit cases: https://github.com/bytecodealliance/wasmtime/blob/c7756bd2654fe1ac795f9dd9d13de41a31cafbac/cranelift/codegen/src/isa/x64/lower.isle#L3154-L3278
it seems someone just needs to add this for the narrower cases; no reason why not other than "someone needs to do it" :-)
Ah, thanks for the pointer :D
Seems like a good opportunity to learn how ISLE works
This seems to be a bit of a bigger challenge than I hoped, since mem/imm instructions are not supported AT ALL by the x86 backend AFAICT
Ah, yes, we've added encodings as we've needed them, so that's a bit of work to fill that out
No worries, makes me do something and actually learn how it works :D
Quick question, what would be the best type for immediates in ISLE? I've seen i32 be used as a "general type" but I can't figure out how to get one from an iconst or whatever the second operand should be
we've tended to use u64
s and should have an extractor that converts from iconst
's parameter (u64_from_imm64
or somesuch? can't look at the moment)
Last updated: Nov 22 2024 at 16:03 UTC