Skip to content

Commit f26d36e

Browse files
committed
Change sign conversion macro to only do u2s since that's all we're using it for
1 parent 56efb0c commit f26d36e

File tree

1 file changed

+16
-24
lines changed

1 file changed

+16
-24
lines changed

src/main.mlog

Lines changed: 16 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -411,27 +411,19 @@ extend_sign:
411411

412412
set @counter ret
413413

414-
# converts a pair of two's complement unsigned values to signed in-place, or vice versa
414+
# converts a pair of two's complement unsigned values to signed in-place
415415
# this converts two values at once because most usages of it need to convert two values
416416
# also, the values are assumed to be in rs1 and rs2
417417
# rs1, rs2 -> rs1, rs2
418-
swap_signedness_rs1_rs2:
419-
# value < 2^31 ? (value + 2^32) % 2^32 : value - 2^32
420-
jump swap_signedness__s2u_2 lessThan rs2 0x80000000
421-
op sub rs2 rs2 0x100000000
422-
jump swap_signedness__done_2 always
423-
swap_signedness__s2u_2:
424-
op add rs2 rs2 0x100000000
425-
op mod rs2 rs2 0x100000000
426-
swap_signedness__done_2:
427-
428-
jump swap_signedness__s2u_1 lessThan rs1 0x80000000 # 2^31
418+
unsigned_to_signed_rs1_rs2:
419+
# value < 2^31 ? value : value - 2^32
420+
jump unsigned_to_signed__done_1 lessThan rs1 0x80000000 # 2^31
429421
op sub rs1 rs1 0x100000000 # 2^32
430-
jump swap_signedness__done_1 always
431-
swap_signedness__s2u_1:
432-
op add rs1 rs1 0x100000000
433-
op mod rs1 rs1 0x100000000
434-
swap_signedness__done_1:
422+
unsigned_to_signed__done_1:
423+
424+
jump unsigned_to_signed__done_2 lessThan rs2 0x80000000
425+
op sub rs2 rs2 0x100000000
426+
unsigned_to_signed__done_2:
435427

436428
set @counter ret
437429

@@ -1000,7 +992,7 @@ BNE:
1000992
BLT:
1001993
# B-type: arg1=rs1, arg2=rs2, arg3=imm
1002994
op add ret @counter 1
1003-
jump swap_signedness_rs1_rs2 always
995+
jump unsigned_to_signed_rs1_rs2 always
1004996
# continue into BLTU
1005997

1006998
BLTU:
@@ -1011,7 +1003,7 @@ BLTU:
10111003
BGE:
10121004
# B-type: arg1=rs1, arg2=rs2, arg3=imm
10131005
op add ret @counter 1
1014-
jump swap_signedness_rs1_rs2 always
1006+
jump unsigned_to_signed_rs1_rs2 always
10151007
# continue into BGEU
10161008

10171009
BGEU:
@@ -1265,14 +1257,14 @@ amo__no_write_rd:
12651257
jump amo__done_modify always
12661258
# min
12671259
op add ret @counter 1
1268-
jump swap_signedness_rs1_rs2 always
1260+
jump unsigned_to_signed_rs1_rs2 always
12691261
# continue into minu
12701262
# minu
12711263
op min result rs1 rs2
12721264
jump amo__done_modify always
12731265
# max
12741266
op add ret @counter 1
1275-
jump swap_signedness_rs1_rs2 always
1267+
jump unsigned_to_signed_rs1_rs2 always
12761268
# continue into maxu
12771269
# maxu
12781270
op max result rs1 rs2
@@ -1345,7 +1337,7 @@ SLTI:
13451337
# I-type: arg1=rs1, arg2=imm, arg3=rd
13461338
set rs2 arg2
13471339
op add ret @counter 1
1348-
jump swap_signedness_rs1_rs2 always
1340+
jump unsigned_to_signed_rs1_rs2 always
13491341

13501342
op lessThan result rs1 rs2
13511343

@@ -1511,7 +1503,7 @@ MULHU:
15111503
DIV:
15121504
# R-type: arg1=rs1, arg2=rs2, arg3=rd
15131505
op add ret @counter 1
1514-
jump swap_signedness_rs1_rs2 always
1506+
jump unsigned_to_signed_rs1_rs2 always
15151507
# continue into DIVU
15161508

15171509
DIVU:
@@ -1533,7 +1525,7 @@ div_by_zero:
15331525
REM:
15341526
# R-type: arg1=rs1, arg2=rs2, arg3=rd
15351527
op add ret @counter 1
1536-
jump swap_signedness_rs1_rs2 always
1528+
jump unsigned_to_signed_rs1_rs2 always
15371529
# continue into REMU
15381530

15391531
# reimu?

0 commit comments

Comments
 (0)