diff --git a/llvm/lib/Target/SBF/Disassembler/SBFDisassembler.cpp b/llvm/lib/Target/SBF/Disassembler/SBFDisassembler.cpp index d3cad4bc32321d4..55c24d9c3288e80 100644 --- a/llvm/lib/Target/SBF/Disassembler/SBFDisassembler.cpp +++ b/llvm/lib/Target/SBF/Disassembler/SBFDisassembler.cpp @@ -68,6 +68,7 @@ class SBFDisassembler : public MCDisassembler { uint8_t getInstSize(uint64_t Inst) const { return (Inst >> 59) & 0x3; }; uint8_t getInstMode(uint64_t Inst) const { return (Inst >> 61) & 0x7; }; bool isMov32(uint64_t Inst) const { return (Inst >> 56) == 0xb4; } + bool isNewMem(uint64_t Inst) const; }; } // end anonymous namespace @@ -156,6 +157,18 @@ static DecodeStatus readInstruction64(ArrayRef Bytes, uint64_t Address, return MCDisassembler::Success; } +bool SBFDisassembler::isNewMem(uint64_t Inst) const { + uint8_t OpCode = Inst >> 56; + + uint8_t LSB = OpCode & 0xf; + if (LSB != 0x7 && LSB != 0xc && LSB != 0xf) + return false; + + uint8_t MSB = OpCode >> 4; + + return MSB == 0x2 || MSB == 0x3 || MSB == 0x8 || MSB == 0x9; +} + DecodeStatus SBFDisassembler::getInstruction(MCInst &Instr, uint64_t &Size, ArrayRef Bytes, uint64_t Address, @@ -171,6 +184,7 @@ DecodeStatus SBFDisassembler::getInstruction(MCInst &Instr, uint64_t &Size, uint8_t InstClass = getInstClass(Insn); uint8_t InstMode = getInstMode(Insn); + if ((InstClass == SBF_LDX || InstClass == SBF_STX) && getInstSize(Insn) != SBF_DW && (InstMode == SBF_MEM || InstMode == SBF_ATOMIC) && @@ -181,6 +195,16 @@ DecodeStatus SBFDisassembler::getInstruction(MCInst &Instr, uint64_t &Size, STI.hasFeature(SBF::FeatureDisableLddw)) Result = decodeInstruction(DecoderTableSBFv264, Instr, Insn, Address, this, STI); + else if (isNewMem(Insn) && (Insn >> 60) != 0x9 && + STI.hasFeature(SBF::FeatureNewMemEncoding) && + STI.hasFeature(SBF::ALU32)) + Result = + decodeInstruction(DecoderTableSBFALU32MEM64, + Instr, Insn, Address, this, STI); + else if (isNewMem(Insn) && STI.hasFeature(SBF::FeatureNewMemEncoding)) + Result = + decodeInstruction(DecoderTableSBFv264, + Instr, Insn, Address, this, STI); else Result = decodeInstruction(DecoderTableSBF64, Instr, Insn, Address, this, STI); diff --git a/llvm/lib/Target/SBF/SBFInstrInfo.td b/llvm/lib/Target/SBF/SBFInstrInfo.td index ae01cb09919dd3b..b48b74df179489c 100644 --- a/llvm/lib/Target/SBF/SBFInstrInfo.td +++ b/llvm/lib/Target/SBF/SBFInstrInfo.td @@ -1305,7 +1305,7 @@ multiclass STOREi32; defm STH32 : STOREi32; defm STB32 : STOREi32; @@ -1368,7 +1368,7 @@ multiclass LOADi32; defm LDH32 : LOADi32; defm LDB32 : LOADi32; diff --git a/llvm/test/MC/Disassembler/SBF/sbf-ldst-new.txt b/llvm/test/MC/Disassembler/SBF/sbf-ldst-new.txt new file mode 100644 index 000000000000000..54f903f72cc11b7 --- /dev/null +++ b/llvm/test/MC/Disassembler/SBF/sbf-ldst-new.txt @@ -0,0 +1,62 @@ +# RUN: llvm-mc --disassemble %s -triple=sbf-solana-solana -mattr=+mem-encoding,+pqr-instr \ +# RUN: | FileCheck %s --check-prefix=CHECK-NEW +# RUN: llvm-mc --disassemble %s -triple=sbf-solana-solana -mattr=+alu32,+mem-encoding,+pqr-instr \ +# RUN: | FileCheck %s --check-prefix=CHECK32-NEW + + +# CHECK-NEW: ldxb r6, [r1 + 17] +# CHECK-NEW: ldxb r1, [r10 - 3] +# CHECK-NEW: ldxh r8, [r2 + 32] +# CHECK-NEW: ldxw r4, [r3 + 64] +# CHECK-NEW: ldxdw r0, [r4 + 128] +0x2c,0x16,0x11,0x00,0x00,0x00,0x00,0x00 +0x2c,0xa1,0xfd,0xff,0x00,0x00,0x00,0x00 +0x3c,0x28,0x20,0x00,0x00,0x00,0x00,0x00 +0x8c,0x34,0x40,0x00,0x00,0x00,0x00,0x00 +0x9c,0x40,0x80,0x00,0x00,0x00,0x00,0x00 + + + +# CHECK32-NEW: ldxb w6, [r1 + 17] +# CHECK32-NEW: ldxb w1, [r10 - 3] +# CHECK32-NEW: ldxh w8, [r2 + 32] +# CHECK32-NEW: ldxw w4, [r3 + 64] +0x2c,0x16,0x11,0x00,0x00,0x00,0x00,0x00 +0x2c,0xa1,0xfd,0xff,0x00,0x00,0x00,0x00 +0x3c,0x28,0x20,0x00,0x00,0x00,0x00,0x00 +0x8c,0x34,0x40,0x00,0x00,0x00,0x00,0x00 + + + +# CHECK-NEW: stxb [r1 + 17], r6 +# CHECK-NEW: stxb [r10 - 3], r1 +# CHECK-NEW: stxh [r2 + 32], r8 +# CHECK-NEW: stxw [r3 + 64], r4 +# CHECK-NEW: stxdw [r4 + 128], r0 +0x2f,0x61,0x11,0x00,0x00,0x00,0x00,0x00 +0x2f,0x1a,0xfd,0xff,0x00,0x00,0x00,0x00 +0x3f,0x82,0x20,0x00,0x00,0x00,0x00,0x00 +0x8f,0x43,0x40,0x00,0x00,0x00,0x00,0x00 +0x9f,0x04,0x80,0x00,0x00,0x00,0x00,0x00 + + + +# CHECK32-NEW: stxb [r1 + 17], w6 +# CHECK32-NEW: stxb [r10 - 3], w1 +# CHECK32-NEW: stxh [r2 + 32], w8 +# CHECK32-NEW: stxw [r3 + 64], w4 +0x2f,0x61,0x11,0x00,0x00,0x00,0x00,0x00 +0x2f,0x1a,0xfd,0xff,0x00,0x00,0x00,0x00 +0x3f,0x82,0x20,0x00,0x00,0x00,0x00,0x00 +0x8f,0x43,0x40,0x00,0x00,0x00,0x00,0x00 + + + +# CHECK-NEW: stb [r10 - 8], 2 +# CHECK-NEW: sth [r9 + 4], -20 +# CHECK-NEW: stw [r4 - 16], 34 +# CHECK-NEW: stdw [r1 + 24], 65534 +0x27,0x0a,0xf8,0xff,0x02,0x00,0x00,0x00 +0x37,0x09,0x04,0x00,0xec,0xff,0xff,0xff +0x87,0x04,0xf0,0xff,0x22,0x00,0x00,0x00 +0x97,0x01,0x18,0x00,0xfe,0xff,0x00,0x00 \ No newline at end of file diff --git a/llvm/test/MC/SBF/sbf-ldst-new.s b/llvm/test/MC/SBF/sbf-ldst-new.s new file mode 100644 index 000000000000000..5c2ac216f709f01 --- /dev/null +++ b/llvm/test/MC/SBF/sbf-ldst-new.s @@ -0,0 +1,91 @@ +# RUN: llvm-mc %s -triple=sbf-solana-solana -mattr=+mem-encoding,+pqr-instr --show-encoding \ +# RUN: | FileCheck %s --check-prefix=CHECK-ASM-NEW +# RUN: llvm-mc %s -triple=sbf-solana-solana -mcpu=sbfv2 -mattr=+mem-encoding,+pqr-instr -filetype=obj \ +# RUN: | llvm-objdump --mattr=+mem-encoding,+pqr-instr -d -r - \ +# RUN: | FileCheck --check-prefix=CHECK-OBJ-NEW %s +# RUN: llvm-mc %s -triple=sbf-solana-solana -mattr=+alu32,+mem-encoding,+pqr-instr --show-encoding \ +# RUN: | FileCheck %s --check-prefix=CHECK32-ASM-NEW +# RUN: llvm-mc %s -triple=sbf-solana-solana -mcpu=sbfv2 -mattr=+alu32,+mem-encoding,+pqr-instr -filetype=obj \ +# RUN: | llvm-objdump --mattr=+mem-encoding,+pqr-instr,+alu32 -d -r - \ +# RUN: | FileCheck --check-prefix=CHECK32-OBJ-NEW %s + + + +# CHECK-OBJ-NEW: ldxb r6, [r1 + 0x11] +# CHECK-OBJ-NEW: ldxb r1, [r10 - 0x3] +# CHECK-OBJ-NEW: ldxh r8, [r2 + 0x20] +# CHECK-OBJ-NEW: ldxw r4, [r3 + 0x40] +# CHECK-OBJ-NEW: ldxdw r0, [r4 + 0x80] +# CHECK-ASM-NEW: encoding: [0x2c,0x16,0x11,0x00,0x00,0x00,0x00,0x00] +# CHECK-ASM-NEW: encoding: [0x2c,0xa1,0xfd,0xff,0x00,0x00,0x00,0x00] +# CHECK-ASM-NEW: encoding: [0x3c,0x28,0x20,0x00,0x00,0x00,0x00,0x00] +# CHECK-ASM-NEW: encoding: [0x8c,0x34,0x40,0x00,0x00,0x00,0x00,0x00] +# CHECK-ASM-NEW: encoding: [0x9c,0x40,0x80,0x00,0x00,0x00,0x00,0x00] +ldxb r6, [r1 + 17] +ldxb r1, [r10 - 3] +ldxh r8, [r2 + 32] +ldxw r4, [r3 + 64] +ldxdw r0, [r4 + 128] + + + +# CHECK32-OBJ-NEW: ldxb w6, [r1 + 0x11] +# CHECK32-OBJ-NEW: ldxb w1, [r10 - 0x3] +# CHECK32-OBJ-NEW: ldxh w8, [r2 + 0x20] +# CHECK32-OBJ-NEW: ldxw w4, [r3 + 0x40] +# CHECK32-ASM-NEW: encoding: [0x2c,0x16,0x11,0x00,0x00,0x00,0x00,0x00] +# CHECK32-ASM-NEW: encoding: [0x2c,0xa1,0xfd,0xff,0x00,0x00,0x00,0x00] +# CHECK32-ASM-NEW: encoding: [0x3c,0x28,0x20,0x00,0x00,0x00,0x00,0x00] +# CHECK32-ASM-NEW: encoding: [0x8c,0x34,0x40,0x00,0x00,0x00,0x00,0x00] +ldxb w6, [r1 + 17] +ldxb w1, [r10 - 3] +ldxh w8, [r2 + 32] +ldxw w4, [r3 + 64] + + + +# CHECK-OBJ-NEW: stxb [r1 + 0x11], r6 +# CHECK-OBJ-NEW: stxb [r10 - 0x3], r1 +# CHECK-OBJ-NEW: stxh [r2 + 0x20], r8 +# CHECK-OBJ-NEW: stxw [r3 + 0x40], r4 +# CHECK-OBJ-NEW: stxdw [r4 + 0x80], r0 +# CHECK-ASM-NEW: encoding: [0x2f,0x61,0x11,0x00,0x00,0x00,0x00,0x00] +# CHECK-ASM-NEW: encoding: [0x2f,0x1a,0xfd,0xff,0x00,0x00,0x00,0x00] +# CHECK-ASM-NEW: encoding: [0x3f,0x82,0x20,0x00,0x00,0x00,0x00,0x00] +# CHECK-ASM-NEW: encoding: [0x8f,0x43,0x40,0x00,0x00,0x00,0x00,0x00] +# CHECK-ASM-NEW: encoding: [0x9f,0x04,0x80,0x00,0x00,0x00,0x00,0x00] +stxb [r1 + 17], r6 +stxb [r10 - 3], r1 +stxh [r2 + 32], r8 +stxw [r3 + 64], r4 +stxdw [r4 + 128], r0 + + + +# CHECK32-OBJ-NEW: stxb [r1 + 0x11], w6 +# CHECK32-OBJ-NEW: stxb [r10 - 0x3], w1 +# CHECK32-OBJ-NEW: stxh [r2 + 0x20], w8 +# CHECK32-OBJ-NEW: stxw [r3 + 0x40], w4 +# CHECK32-ASM-NEW: encoding: [0x2f,0x61,0x11,0x00,0x00,0x00,0x00,0x00] +# CHECK32-ASM-NEW: encoding: [0x2f,0x1a,0xfd,0xff,0x00,0x00,0x00,0x00] +# CHECK32-ASM-NEW: encoding: [0x3f,0x82,0x20,0x00,0x00,0x00,0x00,0x00] +# CHECK32-ASM-NEW: encoding: [0x8f,0x43,0x40,0x00,0x00,0x00,0x00,0x00] +stxb [r1 + 17], w6 +stxb [r10 - 3], w1 +stxh [r2 + 32], w8 +stxw [r3 + 64], w4 + + + +# CHECK-OBJ-NEW: stb [r10 - 0x8], 0x2 +# CHECK-OBJ-NEW: sth [r9 + 0x4], -0x14 +# CHECK-OBJ-NEW: stw [r4 - 0x10], 0x22 +# CHECK-OBJ-NEW: stdw [r1 + 0x18], 0xfffe +# CHECK-ASM-NEW: encoding: [0x27,0x0a,0xf8,0xff,0x02,0x00,0x00,0x00] +# CHECK-ASM-NEW: encoding: [0x37,0x09,0x04,0x00,0xec,0xff,0xff,0xff] +# CHECK-ASM-NEW: encoding: [0x87,0x04,0xf0,0xff,0x22,0x00,0x00,0x00] +# CHECK-ASM-NEW: encoding: [0x97,0x01,0x18,0x00,0xfe,0xff,0x00,0x00] +stb [r10 - 8], 2 +sth [r9 + 4], -20 +stw [r4 - 16], 34 +stdw [r1 + 24], 65534 \ No newline at end of file