titzer / virgil

A fast and lightweight native programming language
1.23k stars 44 forks source link

[X86-64]: Add assembler methods for v128 extract_lane and insert_lane #170

Closed haoyu-zc closed 1 year ago

haoyu-zc commented 1 year ago

I tried to add two test patterns: do_s_r_b and do_r_s_b" in X86_64AssemblerTestGen.v3. However, when I invoked them with newly implemented instructionspinsrb_s_r_iandpextrb_r_s_i`, the tests failed:

For both of the two instructions I'm sure I wrote the bytes correctly. But I have no clues what would lead to the failures. Could you give me some help here?

titzer commented 1 year ago

If those are lane immediates, then nasm is probably checking that they are in range of the lane indices. So you should change the assembler test generator to have a set of valid indices.

haoyu-zc commented 1 year ago

Thank you! It turns out I need to set regSize to specify r32 registers

haoyu-zc commented 1 year ago

I'm stuck with another issue now. I created a new test pattern do_r_s_b for lane extractions but the tests failed. One of the assembler methods as an example is:

def pextrq_r_s_i(a: X86_64Gpr, b: X86_64Xmmr, imm: u8) -> this {
    emitb(0x66);
    emit_rex_bbb_r_r(a, b, REX_W, 0x0F, 0x3A, 0x16);
    emitb(imm);
}

However, the generated asm code is off at the bytes specifying registers in some lines: image

I doubt the method emit_rex_bbb_r_r is not compatible with patterns like `r_s_b". Or could you give me some suggestions to fix this? Thank you!

(The diff file is attached)

test.list.diff.txt

titzer commented 1 year ago

Hmm, I don't have any more insights other than that instruction is apparently not encoded the way the utility method works. You'll have to double-check how it is encoded in the manual.

haoyu-zc commented 1 year ago