Skip to content

Commit

Permalink
Fix disassembler bug
Browse files Browse the repository at this point in the history
  • Loading branch information
LucasSte committed Jan 22, 2025
1 parent 97c03b9 commit bf61f5c
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 4 deletions.
17 changes: 13 additions & 4 deletions llvm/lib/Target/SBF/Disassembler/SBFDisassembler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@ class SBFDisassembler : public MCDisassembler {
bool isMov32(uint64_t Inst) const { return (Inst >> 56) == 0xb4; }
bool isNewMem(uint64_t Inst) const;
bool isSyscallOrExit(uint64_t Inst) const { return (Inst >> 56) == 0x95; }
bool isAlu32NewLoadStoreReg(uint64_t Inst) const;
};

} // end anonymous namespace
Expand Down Expand Up @@ -172,6 +173,14 @@ bool SBFDisassembler::isNewMem(uint64_t Inst) const {
return MSB == 0x2 || MSB == 0x3 || MSB == 0x8 || MSB == 0x9;
}

bool SBFDisassembler::isAlu32NewLoadStoreReg(uint64_t Inst) const {
bool IsNotDw = (Inst >> 60) != 0x9;
bool IsNotStoreImm = (Inst >> 56 & 0xf) != 0x7;
return isNewMem(Inst) && IsNotDw && IsNotStoreImm &&
STI.hasFeature(SBF::FeatureNewMemEncoding) &&
STI.hasFeature(SBF::ALU32);
}

DecodeStatus SBFDisassembler::getInstruction(MCInst &Instr, uint64_t &Size,
ArrayRef<uint8_t> Bytes,
uint64_t Address,
Expand All @@ -197,17 +206,17 @@ 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))
else if (isAlu32NewLoadStoreReg(Insn)) {
Result =
decodeInstruction(DecoderTableSBFALU32MEMv264,
Instr, Insn, Address, this, STI);
}
else if ((isNewMem(Insn) && STI.hasFeature(SBF::FeatureNewMemEncoding)) ||
(isSyscallOrExit(Insn) && STI.hasFeature(SBF::FeatureStaticSyscalls)))
(isSyscallOrExit(Insn) && STI.hasFeature(SBF::FeatureStaticSyscalls))) {
Result =
decodeInstruction(DecoderTableSBFv264,
Instr, Insn, Address, this, STI);
}
else
Result =
decodeInstruction(DecoderTableSBF64, Instr, Insn, Address, this, STI);
Expand Down
22 changes: 22 additions & 0 deletions llvm/test/CodeGen/SBF/store-imm.ll
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
; RUN: llc < %s -march=sbf -mattr=+store-imm -show-mc-encoding | FileCheck %s
; RUN: llc < %s -march=sbf -mattr=+store-imm,+alu32 -show-mc-encoding | FileCheck %s
; RUN: llc < %s -march=sbf -mattr=+store-imm,+mem-encoding -show-mc-encoding | FileCheck --check-prefix=CHECK-V2 %s
; RUN: llc -march=sbf -mcpu=v3 -filetype=obj -o - %s | llvm-objdump -d --no-print-imm-hex - | FileCheck --check-prefix=CHECK-DUMP %s

define void @byte(ptr %p0) {
; CHECK-LABEL: byte:
Expand All @@ -10,6 +11,10 @@ define void @byte(ptr %p0) {

; CHECK-V2: stb [r1 + 0], 1 # encoding: [0x27,0x01,0x00,0x00,0x01,0x00,0x00,0x00]
; CHECK-V2: stb [r1 + 1], 255 # encoding: [0x27,0x01,0x01,0x00,0xff,0x00,0x00,0x00]

; CHECK-DUMP: stb [r1 + 0], 1
; CHECK-DUMP: stb [r1 + 1], 255

%p1 = getelementptr i8, ptr %p0, i32 1
store volatile i8 1, ptr %p0, align 1
store volatile i8 -1, ptr %p1, align 1
Expand All @@ -23,6 +28,10 @@ define void @half(ptr, ptr %p0) {

; CHECK-V2: sth [r2 + 0], 1 # encoding: [0x37,0x02,0x00,0x00,0x01,0x00,0x00,0x00]
; CHECK-V2: sth [r2 + 2], 65535 # encoding: [0x37,0x02,0x02,0x00,0xff,0xff,0x00,0x00]

; CHECK-DUMP: sth [r2 + 0], 1
; CHECK-DUMP: sth [r2 + 2], 65535

%p1 = getelementptr i8, ptr %p0, i32 2
store volatile i16 1, ptr %p0, align 2
store volatile i16 -1, ptr %p1, align 2
Expand All @@ -42,6 +51,13 @@ define void @word(ptr, ptr, ptr %p0) {
; CHECK-V2: stw [r3 + 8], -2000000000 # encoding: [0x87,0x03,0x08,0x00,0x00,0x6c,0xca,0x88]
; CHECK-V2: stw [r3 + 12], -1 # encoding: [0x87,0x03,0x0c,0x00,0xff,0xff,0xff,0xff]
; CHECK-V2: stw [r3 + 12], 0 # encoding: [0x87,0x03,0x0c,0x00,0x00,0x00,0x00,0x00]

; CHECK-DUMP: stw [r3 + 0], 1
; CHECK-DUMP: stw [r3 + 4], -1
; CHECK-DUMP: stw [r3 + 8], -2000000000
; CHECK-DUMP: stw [r3 + 12], -1
; CHECK-DUMP: stw [r3 + 12], 0

%p1 = getelementptr i8, ptr %p0, i32 4
%p2 = getelementptr i8, ptr %p0, i32 8
%p3 = getelementptr i8, ptr %p0, i32 12
Expand All @@ -68,6 +84,12 @@ define void @dword(ptr, ptr, ptr, ptr %p0) {
; CHECK-V2: stdw [r4 + 16], -2000000000 # encoding: [0x97,0x04,0x10,0x00,0x00,0x6c,0xca,0x88]
; CHECK-V2: lddw r1, 4294967295 # encoding: [0x18,0x01,0x00,0x00,0xff,0xff,0xff,0xff,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00]
; CHECK-V2: stxdw [r4 + 24], r1 # encoding: [0x9f,0x14,0x18,0x00,0x00,0x00,0x00,0x00]

; CHECK-DUMP: stdw [r4 + 0], 1
; CHECK-DUMP: stdw [r4 + 8], -1
; CHECK-DUMP: stdw [r4 + 16], 2000000000
; CHECK-DUMP: stdw [r4 + 16], -2000000000

%p1 = getelementptr i8, ptr %p0, i32 8
%p2 = getelementptr i8, ptr %p0, i32 16
%p3 = getelementptr i8, ptr %p0, i32 24
Expand Down

0 comments on commit bf61f5c

Please sign in to comment.