Skip to content

Commit

Permalink
Finish tests
Browse files Browse the repository at this point in the history
  • Loading branch information
LucasSte committed Dec 12, 2024
1 parent 8379b4c commit 7805d85
Show file tree
Hide file tree
Showing 4 changed files with 179 additions and 2 deletions.
24 changes: 24 additions & 0 deletions llvm/lib/Target/SBF/Disassembler/SBFDisassembler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -156,6 +157,18 @@ static DecodeStatus readInstruction64(ArrayRef<uint8_t> 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<uint8_t> Bytes,
uint64_t Address,
Expand All @@ -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) &&
Expand All @@ -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);
Expand Down
4 changes: 2 additions & 2 deletions llvm/lib/Target/SBF/SBFInstrInfo.td
Original file line number Diff line number Diff line change
Expand Up @@ -1305,7 +1305,7 @@ multiclass STOREi32<SBFWidthModifer SizeV1, SBFSizeModifier SizeV2,
}
}

let DecoderNamespace = "SBFALU32" in {
let DecoderNamespace = "SBFALU32MEM" in {
defm STW32 : STOREi32<SBF_W, SBF_W_V2, "stxw">;
defm STH32 : STOREi32<SBF_H, SBF_H_V2, "stxh">;
defm STB32 : STOREi32<SBF_B, SBF_B_V2, "stxb">;
Expand Down Expand Up @@ -1368,7 +1368,7 @@ multiclass LOADi32<SBFWidthModifer SizeV1, SBFSizeModifier SizeV2,
}
}

let DecoderNamespace = "SBFALU32" in {
let DecoderNamespace = "SBFALU32MEM" in {
defm LDW32 : LOADi32<SBF_W, SBF_W_V2, "ldxw">;
defm LDH32 : LOADi32<SBF_H, SBF_H_V2, "ldxh">;
defm LDB32 : LOADi32<SBF_B, SBF_B_V2, "ldxb">;
Expand Down
62 changes: 62 additions & 0 deletions llvm/test/MC/Disassembler/SBF/sbf-ldst-new.txt
Original file line number Diff line number Diff line change
@@ -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
91 changes: 91 additions & 0 deletions llvm/test/MC/SBF/sbf-ldst-new.s
Original file line number Diff line number Diff line change
@@ -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

0 comments on commit 7805d85

Please sign in to comment.