Skip to content

Commit 16cf14d

Browse files
committed
Fixes failing PowerPC unit tests
Also includes a fix for `ldu`. The manual says that the immediate is sign-extended.
1 parent 13106cb commit 16cf14d

File tree

5 files changed

+27
-19
lines changed

5 files changed

+27
-19
lines changed

plugins/powerpc/powerpc.mli

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -399,6 +399,8 @@ module Std : sig
399399
(** imm constructor - constructs an immediate from operand *)
400400
val imm : (op -> exp) ec
401401

402+
val imm16 : (op -> exp) ec
403+
402404
(** var constructor - constructs a variable of bitwidth *)
403405
val var : (bitwidth -> exp) ec
404406

plugins/powerpc/powerpc_dsl.ml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,11 @@ let imm signed op =
3232
if signed then Exp.(signed @@ of_word w)
3333
else Exp.(unsigned @@ of_word w)
3434

35+
let imm16 signed op =
36+
let w = Word.of_int ~width:16 (int_of_imm op) in
37+
if signed then Exp.(signed @@ of_word w)
38+
else Exp.(unsigned @@ of_word w)
39+
3540
let signed f = f true
3641
let unsigned f = f false
3742

plugins/powerpc/powerpc_dsl.mli

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ val bitwidth : int -> bitwidth
1616
val int_of_bitwidth : bitwidth -> int
1717

1818
val imm : (op -> exp) ec
19+
val imm16 : (op -> exp) ec
1920
val var : (bitwidth -> exp) ec
2021
val reg : (reg -> exp) -> (op -> exp) ec
2122
val const : (bitwidth -> int -> exp) ec

plugins/powerpc/powerpc_load.ml

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -9,19 +9,19 @@ open Powerpc.Std
99
83 eb ff fc - lwz r31, -4(r11) *)
1010
let lbz cpu ops =
1111
let rt = unsigned cpu.reg ops.(0) in
12-
let im = signed imm ops.(1) in
12+
let im = signed imm16 ops.(1) in
1313
let ra = signed cpu.reg ops.(2) in
1414
RTL.[ rt := cpu.load (ra + im) byte; ]
1515

1616
let lhz cpu ops =
1717
let rt = unsigned cpu.reg ops.(0) in
18-
let im = signed imm ops.(1) in
18+
let im = signed imm16 ops.(1) in
1919
let ra = signed cpu.reg ops.(2) in
2020
RTL.[ rt := cpu.load (ra + im) halfword; ]
2121

2222
let lwz cpu ops =
2323
let rt = unsigned cpu.reg ops.(0) in
24-
let im = signed imm ops.(1) in
24+
let im = signed imm16 ops.(1) in
2525
let ra = signed cpu.reg ops.(2) in
2626
RTL.[ rt := cpu.load (ra + im) word; ]
2727

@@ -57,7 +57,7 @@ let lwzx cpu ops =
5757
85 3f ff fc lwzu r9, -4(r31) *)
5858
let lbzu cpu ops =
5959
let rt = unsigned cpu.reg ops.(0) in
60-
let im = signed imm ops.(2) in
60+
let im = signed imm16 ops.(2) in
6161
let ra = signed cpu.reg ops.(3) in
6262
RTL.[
6363
rt := cpu.load (ra + im) byte;
@@ -66,7 +66,7 @@ let lbzu cpu ops =
6666

6767
let lhzu cpu ops =
6868
let rt = unsigned cpu.reg ops.(0) in
69-
let im = signed imm ops.(2) in
69+
let im = signed imm16 ops.(2) in
7070
let ra = signed cpu.reg ops.(3) in
7171
RTL.[
7272
rt := cpu.load (ra + im) halfword;
@@ -75,7 +75,7 @@ let lhzu cpu ops =
7575

7676
let lwzu cpu ops =
7777
let rt = unsigned cpu.reg ops.(0) in
78-
let im = signed imm ops.(2) in
78+
let im = signed imm16 ops.(2) in
7979
let ra = signed cpu.reg ops.(3) in
8080
RTL.[
8181
rt := cpu.load (ra + im) word;
@@ -122,7 +122,7 @@ let lwzux cpu ops =
122122
a8 29 00 05 lha r1, 5(r9) *)
123123
let lha cpu ops =
124124
let rt = signed cpu.reg ops.(0) in
125-
let im = signed imm ops.(1) in
125+
let im = signed imm16 ops.(1) in
126126
let ra = signed cpu.reg ops.(2) in
127127
RTL.[
128128
rt := cpu.load (ra + im) halfword;
@@ -134,7 +134,7 @@ let lha cpu ops =
134134
eb eb 01 16 lwa r31, 276(r11) *)
135135
let lwa cpu ops =
136136
let rt = signed cpu.reg ops.(0) in
137-
let im = signed imm ops.(1) in
137+
let im = signed imm16 ops.(1) in
138138
let ra = signed cpu.reg ops.(2) in
139139
RTL.[
140140
rt := cpu.load (ra + im) word;
@@ -168,7 +168,7 @@ let lwax cpu ops =
168168
let lhau cpu ops =
169169
let rt = signed cpu.reg ops.(0) in
170170
let ra = signed cpu.reg ops.(1) in
171-
let im = signed imm ops.(2) in
171+
let im = signed imm16 ops.(2) in
172172
RTL.[
173173
rt := cpu.load (ra + im) halfword;
174174
ra := ra + im
@@ -203,7 +203,7 @@ let lwaux cpu ops =
203203
e8 29 00 08 ld r1, 8(r9) *)
204204
let ld cpu ops =
205205
let rt = unsigned cpu.reg ops.(0) in
206-
let im = signed imm ops.(1) in
206+
let im = signed imm16 ops.(1) in
207207
let ra = signed cpu.reg ops.(2) in
208208
RTL.[
209209
rt := cpu.load (ra + im) doubleword;
@@ -228,7 +228,7 @@ let ldx cpu ops =
228228
let ldu cpu ops =
229229
let rt = unsigned cpu.reg ops.(0) in
230230
let ra = signed cpu.reg ops.(1) in
231-
let im = unsigned imm ops.(2) in
231+
let im = signed imm16 ops.(2) in
232232
RTL.[
233233
rt := cpu.load (ra + im) doubleword;
234234
ra := ra + im;

plugins/powerpc/powerpc_store.ml

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -9,19 +9,19 @@ open Powerpc.Std
99
91 28 ff d4 stw r9,-44(r8) *)
1010
let stb cpu ops =
1111
let rs = unsigned cpu.reg ops.(0) in
12-
let im = signed imm ops.(1) in
12+
let im = signed imm16 ops.(1) in
1313
let ra = signed cpu.reg ops.(2) in
1414
RTL.[ cpu.store (ra + im) rs byte; ]
1515

1616
let sth cpu ops =
1717
let rs = unsigned cpu.reg ops.(0) in
18-
let im = signed imm ops.(1) in
18+
let im = signed imm16 ops.(1) in
1919
let ra = signed cpu.reg ops.(2) in
2020
RTL.[ cpu.store (ra + im) rs halfword; ]
2121

2222
let stw cpu ops =
2323
let rs = unsigned cpu.reg ops.(0) in
24-
let im = signed imm ops.(1) in
24+
let im = signed imm16 ops.(1) in
2525
let ra = signed cpu.reg ops.(2) in
2626
RTL.[ cpu.store (ra + im) rs word; ]
2727

@@ -64,7 +64,7 @@ let stdx cpu ops =
6464
94 21 ff f0 stwu r1,-16(r1) *)
6565
let stbu cpu ops =
6666
let rs = unsigned cpu.reg ops.(1) in
67-
let im = signed imm ops.(2) in
67+
let im = signed imm16 ops.(2) in
6868
let ra = signed cpu.reg ops.(3) in
6969
RTL.[
7070
cpu.store (ra + im) rs byte;
@@ -73,7 +73,7 @@ let stbu cpu ops =
7373

7474
let sthu cpu ops =
7575
let rs = unsigned cpu.reg ops.(1) in
76-
let im = signed imm ops.(2) in
76+
let im = signed imm16 ops.(2) in
7777
let ra = signed cpu.reg ops.(3) in
7878
RTL.[
7979
cpu.store (ra + im) rs halfword;
@@ -82,7 +82,7 @@ let sthu cpu ops =
8282

8383
let stwu cpu ops =
8484
let rs = unsigned cpu.reg ops.(1) in
85-
let im = signed imm ops.(2) in
85+
let im = signed imm16 ops.(2) in
8686
let ra = signed cpu.reg ops.(3) in
8787
RTL.[
8888
cpu.store (ra + im) rs word;
@@ -138,7 +138,7 @@ let stdux cpu ops =
138138
f8 29 00 08 std r1, 8(r9) *)
139139
let std cpu ops =
140140
let rs = unsigned cpu.reg ops.(0) in
141-
let im = signed imm ops.(1) in
141+
let im = signed imm16 ops.(1) in
142142
let ra = signed cpu.reg ops.(2) in
143143
RTL.[
144144
cpu.store (ra + im) rs doubleword;
@@ -150,7 +150,7 @@ let std cpu ops =
150150
f8 29 00 09 stdu r1, 8(r9) *)
151151
let stdu cpu ops =
152152
let rs = unsigned cpu.reg ops.(1) in
153-
let im = signed imm ops.(2) in
153+
let im = signed imm16 ops.(2) in
154154
let ra = signed cpu.reg ops.(3) in
155155
let ea = unsigned var doubleword in
156156
RTL.[

0 commit comments

Comments
 (0)