Skip to content

Commit 6595cb1

Browse files
committed
[m68k] Implement BSR Instruction
Reviewed By: myhsu Differential Revision: https://reviews.llvm.org/D143315
1 parent 2f62803 commit 6595cb1

File tree

5 files changed

+129
-1
lines changed

5 files changed

+129
-1
lines changed

llvm/lib/Target/M68k/M68kInstrControl.td

Lines changed: 29 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
///
1313
/// Machine:
1414
///
15-
/// BRA [x] BSR [ ] Bcc [~] DBcc [ ] FBcc [ ]
15+
/// BRA [x] BSR [~] Bcc [~] DBcc [ ] FBcc [ ]
1616
/// FDBcc [ ] FNOP [ ] FPn [ ] FScc [ ] FTST [ ]
1717
/// JMP [~] JSR [x] NOP [x] RTD [!] RTR [ ]
1818
/// RTS [x] Scc [~] TST [ ]
@@ -225,6 +225,34 @@ def BRA16 : MxBra<MxBrTarget16, (descend 0b0000, 0b0000),
225225

226226
def : Pat<(br bb:$target), (BRA8 MxBrTarget8:$target)>;
227227

228+
/// -------------------------------------------------
229+
/// F E D C B A 9 8 | 7 6 5 4 3 2 1 0
230+
/// -------------------------------------------------
231+
/// 0 1 1 0 0 0 0 1 | 8-BIT DISPLACEMENT
232+
/// -------------------------------------------------
233+
/// 16-BIT DISPLACEMENT IF 8-BIT DISPLACEMENT = $00
234+
/// -------------------------------------------------
235+
/// 32-BIT DISPLACEMENT IF 8-BIT DISPLACEMENT = $FF
236+
/// -------------------------------------------------
237+
238+
let isBranch = 1, isTerminator = 1 in
239+
class MxBsr<Operand TARGET, MxType TYPE, dag disp_8, dag disp_16_32>
240+
: MxInst<(outs), (ins TARGET:$dst), "bsr."#TYPE.Prefix#"\t$dst"> {
241+
let Inst = (ascend
242+
(descend 0b0110, 0b0001, disp_8),
243+
disp_16_32
244+
);
245+
}
246+
247+
def BSR8 : MxBsr<MxBrTarget8, MxType8,
248+
(operand "$dst", 8, (encoder "encodePCRelImm<8>")), (ascend)>;
249+
250+
def BSR16 : MxBsr<MxBrTarget16, MxType16, (descend 0b0000, 0b0000),
251+
(operand "$dst", 16, (encoder "encodePCRelImm<16>"))>;
252+
253+
def BSR32 : MxBsr<MxBrTarget32, MxType32, (descend 0b1111, 0b1111),
254+
(operand "$dst", 32, (encoder "encodePCRelImm<32>"),
255+
(decoder "DecodeImm32"))>;
228256

229257
//===----------------------------------------------------------------------===//
230258
// Call

llvm/test/MC/Disassembler/M68k/control.txt

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,3 +12,12 @@
1212
0x5e 0xc0
1313
# CHECK: nop
1414
0x4e 0x71
15+
16+
# CHECK: bsr.b $1
17+
0x61 0x01
18+
19+
# CHECK: bsr.w $f01
20+
0x61 0x00 0x0f 0x01
21+
22+
# CHECK: bsr.l $f0001
23+
0x61 0xff 0x00 0x0f 0x00 0x01

llvm/test/MC/M68k/Control/bsr.s

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
; RUN: llvm-mc -triple=m68k -show-encoding %s | FileCheck %s
2+
3+
; CHECK: bsr.b .LBB0_1
4+
; CHECK-SAME: encoding: [0x61,A]
5+
; CHECK: fixup A - offset: 1, value: .LBB0_1-1, kind: FK_PCRel_1
6+
bsr.b .LBB0_1
7+
; CHECK: bsr.w .LBB0_2
8+
; CHECK-SAME: encoding: [0x61,0x00,A,A]
9+
; CHECK: fixup A - offset: 2, value: .LBB0_2, kind: FK_PCRel_2
10+
bsr.w .LBB0_2
11+
; CHECK: bsr.l .LBB0_3
12+
; CHECK-SAME: encoding: [0x61,0xff,A,A,A,A]
13+
; CHECK: fixup A - offset: 2, value: .LBB0_3, kind: FK_PCRel_4
14+
bsr.l .LBB0_3
15+
.LBB0_1:
16+
; CHECK: add.l #0, %d0
17+
; CHECK-SAME: encoding: [0xd0,0xbc,0x00,0x00,0x00,0x00]
18+
add.l #0, %d0
19+
; CHECK: rts
20+
; CHECK-SAME: encoding: [0x4e,0x75]
21+
rts
22+
.LBB0_2:
23+
; CHECK: add.l #1, %d0
24+
; CHECK-SAME: encoding: [0xd0,0xbc,0x00,0x00,0x00,0x01]
25+
add.l #1, %d0
26+
; CHECK: rts
27+
; CHECK-SAME: encoding: [0x4e,0x75]
28+
rts
29+
.LBB0_3:
30+
; CHECK: add.l #1, %d0
31+
; CHECK-SAME: encoding: [0xd0,0xbc,0x00,0x00,0x00,0x01]
32+
add.l #1, %d0
33+
; CHECK: rts
34+
; CHECK-SAME: encoding: [0x4e,0x75]
35+
rts

llvm/test/MC/M68k/Relaxations/bsr.s

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
; RUN: llvm-mc -triple=m68k -motorola-integers -filetype=obj < %s \
2+
; RUN: | llvm-objdump -d - | FileCheck %s
3+
4+
; CHECK-LABEL: <TIGHT>:
5+
TIGHT:
6+
; CHECK: bsr.w $7a
7+
bsr.w .LBB0_2
8+
move.l $0, $0
9+
move.l $0, $0
10+
move.l $0, $0
11+
move.l $0, $0
12+
move.l $0, $0
13+
move.l $0, $0
14+
move.l $0, $0
15+
move.l $0, $0
16+
move.l $0, $0
17+
move.l $0, $0
18+
move.l $0, $0
19+
move.l $0, $0
20+
.LBB0_2:
21+
add.l #0, %d0
22+
rts
23+
24+
; CHECK-LABEL: <RELAXED>:
25+
RELAXED:
26+
; CHECK: bsr.b $82
27+
bsr.b .LBB1_2
28+
move.l $0, $0
29+
move.l $0, $0
30+
move.l $0, $0
31+
move.l $0, $0
32+
move.l $0, $0
33+
move.l $0, $0
34+
move.l $0, $0
35+
move.l $0, $0
36+
move.l $0, $0
37+
move.l $0, $0
38+
move.l $0, $0
39+
move.l $0, $0
40+
move.l $0, $0
41+
.LBB1_2:
42+
add.l #0, %d0
43+
rts
44+
45+
; CHECK-LABEL: <ZERO>:
46+
ZERO:
47+
; CHECK: bsr.w $2
48+
bsr.w .LBB2_1
49+
.LBB2_1:
50+
add.l #0, %d0
51+
rts

llvm/test/MC/M68k/Relocations/text-plt.s

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,3 +7,8 @@
77
; INSTR: jsr (target@PLT,%pc)
88
; FIXUP: fixup A - offset: 2, value: target@PLT, kind: FK_PCRel_2
99
jsr (target@PLT,%pc)
10+
11+
; RELOC: R_68K_PLT32 __tls_get_addr 0x0
12+
; INSTR: bsr.l __tls_get_addr@PLT
13+
; FIXUP: fixup A - offset: 2, value: __tls_get_addr@PLT, kind: FK_PCRel_4
14+
bsr.l __tls_get_addr@PLT

0 commit comments

Comments
 (0)