2016-09-25 20:17:14 +00:00
|
|
|
REGISTERS
|
|
|
|
|
2016-10-09 12:45:13 +00:00
|
|
|
/* Registers are allocated top down; the order here is odd in order to make
|
2016-10-12 20:58:46 +00:00
|
|
|
* sure that non-volatile registers get allocated from r31 (or f31) down.
|
|
|
|
*
|
2016-10-25 21:04:20 +00:00
|
|
|
* Attributes may have at most one of: int, float, long, double. These
|
|
|
|
* indicate that the register is used to store a value of that type. If
|
|
|
|
* your register can store more than one type, create an alias. Registers
|
|
|
|
* with none of these cannot be copied by the code generator (and so cannot
|
|
|
|
* be moved from register to register or spilt).
|
2016-10-12 20:58:46 +00:00
|
|
|
*/
|
|
|
|
|
2016-10-25 21:04:20 +00:00
|
|
|
r12 int volatile;
|
|
|
|
r11 int volatile;
|
|
|
|
r10 int volatile;
|
|
|
|
r9 int volatile;
|
|
|
|
r8 int volatile;
|
|
|
|
r7 int volatile;
|
|
|
|
r6 int volatile;
|
|
|
|
r5 int volatile;
|
|
|
|
r4 int volatile;
|
|
|
|
r3 int volatile ret;
|
|
|
|
|
|
|
|
r31 int;
|
|
|
|
r30 int;
|
|
|
|
r29 int;
|
|
|
|
r28 int;
|
|
|
|
r27 int;
|
|
|
|
r26 int;
|
|
|
|
r25 int;
|
|
|
|
r24 int;
|
|
|
|
r23 int;
|
|
|
|
r22 int;
|
|
|
|
r21 int;
|
|
|
|
r20 int;
|
|
|
|
r19 int;
|
|
|
|
r18 int;
|
|
|
|
r17 int;
|
|
|
|
r16 int;
|
|
|
|
r15 int;
|
|
|
|
r14 int;
|
|
|
|
r13 int;
|
|
|
|
|
|
|
|
r11r12 named("r11", "r12") aliases(r11, r12) long volatile;
|
|
|
|
r9r10 named("r9", "r10") aliases(r9, r10) long volatile;
|
|
|
|
r7r8 named("r7", "r8") aliases(r7, r8) long volatile;
|
|
|
|
r5r6 named("r5", "r6") aliases(r6, r6) long volatile;
|
|
|
|
r3r4 named("r3", "r4") aliases(r3, r4) long volatile lret;
|
|
|
|
|
|
|
|
r29r30 named("r29", "r30") aliases(r29, r30) long;
|
|
|
|
r27r28 named("r27", "r28") aliases(r27, r28) long;
|
|
|
|
r25r26 named("r25", "r26") aliases(r25, r26) long;
|
|
|
|
r23r24 named("r23", "r24") aliases(r23, r24) long;
|
|
|
|
r21r22 named("r21", "r22") aliases(r21, r22) long;
|
|
|
|
r19r20 named("r19", "r20") aliases(r19, r20) long;
|
|
|
|
r17r18 named("r17", "r18") aliases(r17, r18) long;
|
|
|
|
r15r16 named("r15", "r16") aliases(r15, r16) long;
|
|
|
|
r13r14 named("r13", "r14") aliases(r13, r14) long;
|
|
|
|
|
|
|
|
f14 float volatile;
|
|
|
|
f13 float volatile;
|
|
|
|
f12 float volatile;
|
|
|
|
f11 float volatile;
|
|
|
|
f10 float volatile;
|
|
|
|
f9 float volatile;
|
|
|
|
f8 float volatile;
|
|
|
|
f7 float volatile;
|
|
|
|
f6 float volatile;
|
|
|
|
f5 float volatile;
|
|
|
|
f4 float volatile;
|
|
|
|
f3 float volatile fret;
|
|
|
|
f2 float volatile;
|
|
|
|
f1 float volatile;
|
|
|
|
f0 float volatile;
|
|
|
|
|
|
|
|
f31 float;
|
|
|
|
f30 float;
|
|
|
|
f29 float;
|
|
|
|
f28 float;
|
|
|
|
f27 float;
|
|
|
|
f26 float;
|
|
|
|
f25 float;
|
|
|
|
f24 float;
|
|
|
|
f23 float;
|
|
|
|
f22 float;
|
|
|
|
f21 float;
|
|
|
|
f20 float;
|
|
|
|
f19 float;
|
|
|
|
f18 float;
|
|
|
|
f17 float;
|
|
|
|
f16 float;
|
|
|
|
f15 float;
|
|
|
|
|
|
|
|
d14 named("f14") aliases(f14) double volatile;
|
|
|
|
d13 named("f13") aliases(f13) double volatile;
|
|
|
|
d12 named("f12") aliases(f12) double volatile;
|
|
|
|
d11 named("f11") aliases(f11) double volatile;
|
|
|
|
d10 named("f10") aliases(f10) double volatile;
|
|
|
|
d9 named("f9") aliases(f9) double volatile;
|
|
|
|
d8 named("f8") aliases(f8) double volatile;
|
|
|
|
d7 named("f7") aliases(f7) double volatile;
|
|
|
|
d6 named("f6") aliases(f6) double volatile;
|
|
|
|
d5 named("f5") aliases(f5) double volatile;
|
|
|
|
d4 named("f4") aliases(f4) double volatile;
|
|
|
|
d3 named("f3") aliases(f3) double volatile dret;
|
|
|
|
d2 named("f2") aliases(f2) double volatile;
|
|
|
|
d1 named("f1") aliases(f1) double volatile;
|
|
|
|
d0 named("f0") aliases(f0) double volatile;
|
|
|
|
|
|
|
|
d31 named("f31") aliases(f31) double;
|
|
|
|
d30 named("f30") aliases(f30) double;
|
|
|
|
d29 named("f29") aliases(f29) double;
|
|
|
|
d28 named("f28") aliases(f28) double;
|
|
|
|
d27 named("f27") aliases(f27) double;
|
|
|
|
d26 named("f26") aliases(f26) double;
|
|
|
|
d25 named("f25") aliases(f25) double;
|
|
|
|
d24 named("f24") aliases(f24) double;
|
|
|
|
d23 named("f23") aliases(f23) double;
|
|
|
|
d22 named("f22") aliases(f22) double;
|
|
|
|
d21 named("f21") aliases(f21) double;
|
|
|
|
d20 named("f20") aliases(f20) double;
|
|
|
|
d19 named("f19") aliases(f19) double;
|
|
|
|
d18 named("f18") aliases(f18) double;
|
|
|
|
d17 named("f17") aliases(f17) double;
|
|
|
|
d16 named("f16") aliases(f16) double;
|
|
|
|
d15 named("f15") aliases(f15) double;
|
|
|
|
|
|
|
|
cr0 cr;
|
2016-10-01 10:17:14 +00:00
|
|
|
|
2016-09-25 20:17:14 +00:00
|
|
|
|
2016-10-15 21:19:44 +00:00
|
|
|
|
2016-09-25 20:17:14 +00:00
|
|
|
DECLARATIONS
|
|
|
|
|
2016-10-08 09:35:33 +00:00
|
|
|
cr;
|
2016-10-14 21:19:02 +00:00
|
|
|
ubyteX; /* bottom 8 bits valid, the rest undefined */
|
2016-10-22 10:13:57 +00:00
|
|
|
ubyte0; /* bottom 8 bits valid, the rest 0 */
|
2016-10-14 21:19:02 +00:00
|
|
|
ushortX; /* bottom 16 bits valid, the rest undefined */
|
2016-10-22 10:13:57 +00:00
|
|
|
ushort0; /* bottom 16 bits valid, the rest 0 */
|
2016-10-02 19:51:25 +00:00
|
|
|
|
2016-10-12 20:58:46 +00:00
|
|
|
address fragment;
|
2016-10-01 10:17:14 +00:00
|
|
|
|
2016-09-25 20:17:14 +00:00
|
|
|
|
2016-10-15 21:19:44 +00:00
|
|
|
|
2016-09-24 17:03:55 +00:00
|
|
|
PATTERNS
|
2016-09-24 15:20:40 +00:00
|
|
|
|
2016-09-24 20:46:08 +00:00
|
|
|
/* Special */
|
|
|
|
|
2016-10-23 19:54:14 +00:00
|
|
|
PAIR(BLOCK.I, BLOCK.I);
|
2016-09-24 20:46:08 +00:00
|
|
|
|
|
|
|
|
2016-10-08 09:35:33 +00:00
|
|
|
|
2016-09-24 20:46:08 +00:00
|
|
|
/* Miscellaneous special things */
|
|
|
|
|
2016-10-23 19:54:14 +00:00
|
|
|
PUSH.I(in:(int)reg)
|
2016-10-08 09:35:33 +00:00
|
|
|
emit "stwu %in, -4(sp)"
|
2016-09-24 20:46:08 +00:00
|
|
|
cost 4;
|
|
|
|
|
2016-10-23 19:54:14 +00:00
|
|
|
PUSH.L(in:(long)reg)
|
2016-10-21 21:31:00 +00:00
|
|
|
emit "stwu %in.0, -4(sp)"
|
|
|
|
emit "stwu %in.1, -4(sp)"
|
|
|
|
cost 8;
|
|
|
|
|
2016-10-23 19:54:14 +00:00
|
|
|
PUSH.D(in:(double)reg)
|
|
|
|
emit "stfdu %in, -8(sp)"
|
|
|
|
cost 4;
|
|
|
|
|
|
|
|
out:(int)reg = POP.I
|
2016-10-08 09:35:33 +00:00
|
|
|
emit "lwz %out, 0(sp)"
|
|
|
|
emit "addi sp, sp, 4"
|
|
|
|
cost 8;
|
2016-09-24 20:46:08 +00:00
|
|
|
|
2016-10-23 19:54:14 +00:00
|
|
|
out:(long)reg = POP.L
|
2016-10-21 22:02:15 +00:00
|
|
|
emit "lwz %out.0, 4(sp)"
|
|
|
|
emit "lwz %out.1, 0(sp)"
|
|
|
|
emit "addi sp, sp, 8"
|
|
|
|
cost 12;
|
|
|
|
|
2016-10-23 19:54:14 +00:00
|
|
|
out:(float)reg = POP.F
|
2016-10-08 09:35:33 +00:00
|
|
|
emit "lfs %out, 0(sp)"
|
|
|
|
emit "addi sp, sp, 4"
|
|
|
|
cost 8;
|
|
|
|
|
2016-10-25 21:04:20 +00:00
|
|
|
out:(double)reg = POP.D
|
2016-10-24 18:15:22 +00:00
|
|
|
emit "lfd %out, 0(sp)"
|
|
|
|
emit "addi sp, sp, 8"
|
|
|
|
cost 8;
|
|
|
|
|
2016-10-23 19:54:14 +00:00
|
|
|
SETRET.I(in:(ret)reg)
|
2016-10-12 20:58:46 +00:00
|
|
|
emit "! setret4"
|
2016-10-21 21:31:00 +00:00
|
|
|
cost 1;
|
|
|
|
|
2016-10-25 21:04:20 +00:00
|
|
|
SETRET.L(in:(lret)reg)
|
2016-10-21 21:31:00 +00:00
|
|
|
emit "! setret8"
|
|
|
|
cost 1;
|
2016-09-24 20:46:08 +00:00
|
|
|
|
2016-10-23 19:54:14 +00:00
|
|
|
STACKADJUST.I(delta:CONST.I)
|
2016-10-09 10:32:36 +00:00
|
|
|
when signed_constant(%delta, 16)
|
2016-10-08 09:35:33 +00:00
|
|
|
emit "addi sp, sp, $delta"
|
2016-10-01 21:41:45 +00:00
|
|
|
cost 4;
|
|
|
|
|
2016-10-23 19:54:14 +00:00
|
|
|
STACKADJUST.I(in:(int)reg)
|
2016-10-22 09:26:28 +00:00
|
|
|
emit "add sp, sp, %in"
|
|
|
|
cost 4;
|
|
|
|
|
2016-10-23 20:24:08 +00:00
|
|
|
STACKADJUST.I(NEG.I(in:(int)reg))
|
|
|
|
emit "subf sp, %in, sp"
|
|
|
|
cost 4;
|
|
|
|
|
2016-10-23 19:54:14 +00:00
|
|
|
out:(int)reg = GETFP.I
|
2016-10-15 11:07:59 +00:00
|
|
|
emit "mr %out, fp"
|
|
|
|
cost 4;
|
|
|
|
|
2016-10-29 09:57:56 +00:00
|
|
|
SETFP.I(in:(int)reg)
|
|
|
|
emit "mr fp, %in"
|
|
|
|
cost 4;
|
|
|
|
|
2016-10-27 19:50:58 +00:00
|
|
|
out:(int)reg = CHAINFP.I(in:(int)reg)
|
|
|
|
emit "lwz %out, 0(%in)"
|
|
|
|
cost 4;
|
|
|
|
|
2016-10-29 09:57:56 +00:00
|
|
|
out:(int)reg = FPTOAB.I(GETFP.I)
|
2016-10-15 11:07:59 +00:00
|
|
|
emit "addi %out, fp, 8"
|
|
|
|
cost 4;
|
|
|
|
|
2016-10-29 09:57:56 +00:00
|
|
|
out:(int)reg = FPTOAB.I(in:(int)reg)
|
2016-10-15 11:07:59 +00:00
|
|
|
emit "addi %out, %in, 8"
|
|
|
|
cost 4;
|
|
|
|
|
2016-10-29 09:57:56 +00:00
|
|
|
out:(int)reg = FPTOLB.I(in:(int)reg)
|
|
|
|
with %out == %in
|
|
|
|
cost 1;
|
2016-10-29 10:48:05 +00:00
|
|
|
|
2016-10-23 19:54:14 +00:00
|
|
|
out:(int)reg = GETSP.I
|
2016-10-22 09:26:28 +00:00
|
|
|
emit "mr %out, sp"
|
|
|
|
cost 4;
|
|
|
|
|
2016-10-23 19:54:14 +00:00
|
|
|
SETSP.I(in:(int)reg)
|
2016-10-22 09:26:28 +00:00
|
|
|
emit "mr sp, %in"
|
|
|
|
cost 4;
|
2016-10-23 19:54:14 +00:00
|
|
|
|
2016-10-29 09:57:56 +00:00
|
|
|
out:(int)reg = ANY.I
|
|
|
|
cost 1;
|
|
|
|
|
2016-10-23 19:54:14 +00:00
|
|
|
out:(int)reg = COPYF.I(in:(float)reg)
|
|
|
|
emit "stfsu %in, -4(sp)"
|
|
|
|
emit "lwz %out, 0(sp)"
|
|
|
|
emit "addi sp, sp, 4"
|
|
|
|
cost 12;
|
|
|
|
|
|
|
|
out:(double)reg = COPYL.D(in:(long)reg)
|
|
|
|
emit "stwu %in.0, -4(sp)"
|
|
|
|
emit "stwu %in.1, -4(sp)"
|
|
|
|
emit "lfd %out, 0(sp)"
|
|
|
|
emit "addi sp, sp, 8"
|
|
|
|
cost 16;
|
2016-10-22 09:26:28 +00:00
|
|
|
|
2016-10-24 18:15:22 +00:00
|
|
|
out:(long)reg = COPYD.L(in:(double)reg)
|
2016-10-24 20:14:08 +00:00
|
|
|
emit "stfdu %in, -8(sp)"
|
2016-10-24 18:15:22 +00:00
|
|
|
emit "lwz %out.0, 4(sp)"
|
|
|
|
emit "lwz %out.1, 0(sp)"
|
|
|
|
emit "addi sp, sp, 8"
|
|
|
|
cost 16;
|
|
|
|
|
2016-09-25 20:17:14 +00:00
|
|
|
|
2016-10-08 09:35:33 +00:00
|
|
|
|
2016-09-24 20:46:08 +00:00
|
|
|
/* Memory operations */
|
|
|
|
|
2016-10-12 21:12:53 +00:00
|
|
|
/* Stores */
|
|
|
|
|
2016-10-24 20:14:08 +00:00
|
|
|
STORE.D(addr:address, value:(double)reg)
|
2016-10-25 21:04:20 +00:00
|
|
|
emit "stfd %value, %addr"
|
2016-10-24 20:14:08 +00:00
|
|
|
cost 4;
|
|
|
|
|
2016-10-23 19:54:14 +00:00
|
|
|
STORE.L(addr:address, value:(long)reg)
|
2016-10-21 21:31:00 +00:00
|
|
|
emit "stw %value.0, 4+%addr"
|
|
|
|
emit "stw %value.1, 0+%addr"
|
2016-10-24 20:14:08 +00:00
|
|
|
cost 8;
|
2016-10-21 21:31:00 +00:00
|
|
|
|
2016-10-23 19:54:14 +00:00
|
|
|
STORE.I(addr:address, value:(int)reg)
|
2016-10-08 09:35:33 +00:00
|
|
|
emit "stw %value, %addr"
|
|
|
|
cost 4;
|
|
|
|
|
2016-10-23 19:54:14 +00:00
|
|
|
STOREH.I(addr:address, value:(int)ushortX)
|
2016-10-08 09:35:33 +00:00
|
|
|
emit "sth %value, %addr"
|
2016-09-24 15:20:40 +00:00
|
|
|
cost 4;
|
|
|
|
|
2016-10-23 19:54:14 +00:00
|
|
|
STOREH.I(ADD.I(left:(int)reg, right:(int)reg), value:(int)ushortX)
|
2016-10-12 21:12:53 +00:00
|
|
|
emit "sthx %value, %left, %right"
|
|
|
|
cost 4;
|
|
|
|
|
2016-10-23 19:54:14 +00:00
|
|
|
STOREB.I(addr:address, value:(int)ushortX)
|
|
|
|
emit "sth %value, %addr"
|
|
|
|
cost 4;
|
|
|
|
|
|
|
|
STOREB.I(addr:address, value:(int)ubyteX)
|
2016-10-08 09:35:33 +00:00
|
|
|
emit "stb %value, %addr"
|
2016-10-01 21:41:45 +00:00
|
|
|
cost 4;
|
|
|
|
|
2016-10-23 19:54:14 +00:00
|
|
|
STOREB.I(ADD.I(left:(int)reg, right:(int)reg), value:(int)ubyteX)
|
2016-10-10 22:23:35 +00:00
|
|
|
emit "stbx %value, %left, %right"
|
|
|
|
cost 4;
|
|
|
|
|
2016-10-12 21:12:53 +00:00
|
|
|
/* Loads */
|
2016-10-10 22:23:35 +00:00
|
|
|
|
2016-10-23 19:54:14 +00:00
|
|
|
out:(int)reg = LOAD.I(addr:address)
|
2016-10-08 09:35:33 +00:00
|
|
|
emit "lwz %out, %addr"
|
|
|
|
cost 4;
|
|
|
|
|
2016-10-23 19:54:14 +00:00
|
|
|
out:(long)reg = LOAD.L(addr:address)
|
2016-10-21 21:31:00 +00:00
|
|
|
emit "lwz %out.0, 4+%addr"
|
|
|
|
emit "lwz %out.1, 0+%addr"
|
|
|
|
cost 8;
|
|
|
|
|
2016-10-23 19:54:14 +00:00
|
|
|
out:(int)ushort0 = LOADH.I(addr:address)
|
2016-10-08 09:35:33 +00:00
|
|
|
emit "lhz %out, %addr"
|
2016-09-24 20:46:08 +00:00
|
|
|
cost 4;
|
|
|
|
|
2016-10-23 19:54:14 +00:00
|
|
|
out:(int)ubyte0 = LOADB.I(addr:address)
|
2016-10-08 09:35:33 +00:00
|
|
|
emit "lbz %out, %addr"
|
2016-09-24 20:46:08 +00:00
|
|
|
cost 4;
|
|
|
|
|
2016-10-14 21:19:02 +00:00
|
|
|
/* ubyte intrinsics */
|
2016-10-12 21:12:53 +00:00
|
|
|
|
2016-10-14 21:19:02 +00:00
|
|
|
out:(int)ubyteX = in:(int)ubyte0
|
2016-10-14 20:17:02 +00:00
|
|
|
with %out == %in
|
2016-10-14 21:19:02 +00:00
|
|
|
emit "! ubyte0 -> ubyteX"
|
2016-10-12 21:12:53 +00:00
|
|
|
cost 1;
|
|
|
|
|
2016-10-14 21:19:02 +00:00
|
|
|
out:(int)ubyte0 = in:(int)ubyteX
|
|
|
|
emit "andi %out, %in, 0xff ! ubyteX -> ubyte0"
|
|
|
|
cost 4;
|
2016-10-12 21:12:53 +00:00
|
|
|
|
2016-10-14 21:19:02 +00:00
|
|
|
out:(int)reg = in:(int)ubyte0
|
|
|
|
with %out == %in
|
|
|
|
emit "! ubyte0 -> reg"
|
|
|
|
cost 4;
|
2016-10-12 21:12:53 +00:00
|
|
|
|
2016-10-14 21:19:02 +00:00
|
|
|
out:(int)ubyteX = in:(int)reg
|
2016-10-14 20:17:02 +00:00
|
|
|
with %out == %in
|
2016-10-14 21:19:02 +00:00
|
|
|
emit "! reg -> ubyteX"
|
2016-10-12 21:12:53 +00:00
|
|
|
cost 1;
|
|
|
|
|
2016-10-14 21:19:02 +00:00
|
|
|
/* ushort intrinsics */
|
|
|
|
|
|
|
|
out:(int)ushortX = in:(int)ushort0
|
|
|
|
with %out == %in
|
|
|
|
emit "! ushort0 -> ushortX"
|
2016-10-12 21:12:53 +00:00
|
|
|
cost 1;
|
|
|
|
|
2016-10-14 21:19:02 +00:00
|
|
|
out:(int)ushort0 = in:(int)ushortX
|
|
|
|
emit "andi %out, %in, 0xff ! ushortX -> ushort0"
|
|
|
|
cost 4;
|
|
|
|
|
|
|
|
out:(int)reg = in:(int)ushort0
|
|
|
|
with %out == %in
|
|
|
|
emit "! ushort0 -> reg"
|
|
|
|
cost 4;
|
|
|
|
|
|
|
|
out:(int)ushortX = in:(int)reg
|
|
|
|
with %out == %in
|
|
|
|
emit "! reg -> ushortX"
|
2016-10-12 21:12:53 +00:00
|
|
|
cost 1;
|
|
|
|
|
2016-10-23 19:54:14 +00:00
|
|
|
|
|
|
|
/* Extensions and conversions */
|
|
|
|
|
|
|
|
out:(int)reg = EXTENDB.I(in:(int)reg)
|
|
|
|
emit "extsb %out, %in"
|
|
|
|
cost 4;
|
|
|
|
|
|
|
|
out:(int)reg = EXTENDH.I(in:(int)reg)
|
|
|
|
emit "extsh %out, %in"
|
|
|
|
cost 4;
|
|
|
|
|
|
|
|
out:(int)reg = FROMSI.I(in:(int)reg)
|
|
|
|
with %out == %in
|
|
|
|
emit "! FROMSI.I(int) -> int"
|
|
|
|
cost 1;
|
|
|
|
|
|
|
|
out:(int)reg = FROMUI.I(in:(int)reg)
|
|
|
|
with %out == %in
|
|
|
|
emit "! FROMUI.I(int) -> int"
|
|
|
|
cost 1;
|
|
|
|
|
|
|
|
out:(long)reg = FROMSI.L(in:(int)reg)
|
|
|
|
emit "mr %out.0, %in"
|
|
|
|
emit "srawi %out.1, %out.0, 31"
|
|
|
|
cost 8;
|
|
|
|
|
2016-10-29 09:57:56 +00:00
|
|
|
out:(ret)reg = FROMF.I(in:(dret)reg)
|
|
|
|
with corrupted(volatile)
|
|
|
|
emit "bl .fromf2i"
|
|
|
|
cost 4;
|
|
|
|
|
2016-10-25 21:04:20 +00:00
|
|
|
out:(ret)reg = FROMD.I(in:(dret)reg)
|
2016-10-23 19:54:14 +00:00
|
|
|
with corrupted(volatile)
|
|
|
|
emit "bl .fromd2i"
|
|
|
|
cost 4;
|
|
|
|
|
2016-10-25 21:04:20 +00:00
|
|
|
out:(lret)reg = FROMF.L(in:(fret)reg)
|
2016-10-24 18:15:22 +00:00
|
|
|
with corrupted(volatile)
|
|
|
|
emit "bl .fromf2l"
|
|
|
|
cost 4;
|
|
|
|
|
2016-10-25 21:04:20 +00:00
|
|
|
out:(dret)reg = FROMSI.D(in:(ret)reg)
|
2016-10-24 20:14:08 +00:00
|
|
|
with corrupted(volatile)
|
|
|
|
emit "bl .fromsi2d"
|
|
|
|
cost 4;
|
|
|
|
|
2016-10-29 09:57:56 +00:00
|
|
|
out:(fret)reg = FROMUI.F(in:(ret)reg)
|
|
|
|
with corrupted(volatile)
|
|
|
|
emit "bl .fromui2f"
|
2016-10-12 21:12:53 +00:00
|
|
|
cost 4;
|
2016-10-08 09:35:33 +00:00
|
|
|
|
2016-10-29 09:57:56 +00:00
|
|
|
out:(dret)reg = FROMUI.D(in:(ret)reg)
|
|
|
|
with corrupted(volatile)
|
|
|
|
emit "bl .fromui2d"
|
2016-10-14 21:19:02 +00:00
|
|
|
cost 4;
|
2016-10-29 09:57:56 +00:00
|
|
|
|
2016-10-29 10:48:05 +00:00
|
|
|
out:(lret)reg = FROMIPAIR.L(in1:(int)reg, in2:(int)reg)
|
|
|
|
emit "mr %out.0, %in1"
|
|
|
|
emit "mr %out.1, %in2"
|
|
|
|
cost 8;
|
|
|
|
|
|
|
|
out:(int)reg = FROML0.I(in:(long)reg)
|
|
|
|
emit "mr %out, %in.0"
|
|
|
|
cost 4;
|
|
|
|
|
|
|
|
out:(int)reg = FROML1.I(in:(long)reg)
|
|
|
|
emit "mr %out, %in.1"
|
|
|
|
cost 4;
|
|
|
|
|
2016-09-24 20:46:08 +00:00
|
|
|
|
|
|
|
|
|
|
|
/* Locals */
|
|
|
|
|
2016-10-23 19:54:14 +00:00
|
|
|
out:(int)reg = in:LOCAL.I
|
2016-10-17 22:31:26 +00:00
|
|
|
emit "addi %out, fp, $in"
|
2016-09-24 15:20:40 +00:00
|
|
|
cost 4;
|
|
|
|
|
2016-10-23 19:54:14 +00:00
|
|
|
address = in:LOCAL.I
|
2016-10-08 09:35:33 +00:00
|
|
|
emit "$in(fp)";
|
|
|
|
|
2016-09-24 20:46:08 +00:00
|
|
|
|
|
|
|
|
2016-10-29 09:57:56 +00:00
|
|
|
|
2016-09-24 20:46:08 +00:00
|
|
|
/* Memory addressing modes */
|
|
|
|
|
2016-10-23 19:54:14 +00:00
|
|
|
address = ADD.I(addr:(int)reg, offset:CONST.I)
|
2016-10-09 10:32:36 +00:00
|
|
|
when signed_constant(%offset, 16)
|
2016-10-08 09:35:33 +00:00
|
|
|
emit "$offset(%addr)";
|
2016-10-01 21:41:45 +00:00
|
|
|
|
2016-10-05 20:56:25 +00:00
|
|
|
address = addr:(int)reg
|
2016-10-08 09:35:33 +00:00
|
|
|
emit "0(%addr)";
|
2016-09-24 15:20:40 +00:00
|
|
|
|
2016-09-24 20:46:08 +00:00
|
|
|
|
2016-10-01 21:41:45 +00:00
|
|
|
|
2016-09-24 20:46:08 +00:00
|
|
|
/* Branches */
|
|
|
|
|
2016-10-23 19:54:14 +00:00
|
|
|
JUMP(addr:BLOCK.I)
|
2016-09-25 15:14:54 +00:00
|
|
|
emit "b $addr"
|
2016-09-24 20:46:08 +00:00
|
|
|
cost 4;
|
|
|
|
|
2016-10-29 10:48:05 +00:00
|
|
|
JUMP(dest:(int)reg)
|
|
|
|
emit "mtspr ctr, %dest"
|
|
|
|
emit "bcctrl 20, 0, 0"
|
|
|
|
cost 8;
|
|
|
|
|
2016-10-23 19:54:14 +00:00
|
|
|
CJUMPEQ(value:(cr)cr, PAIR(true:BLOCK.I, false:BLOCK.I))
|
2016-10-17 22:31:26 +00:00
|
|
|
emit "bc 12, 2, $true" /* IFTRUE EQ */
|
2016-09-27 21:38:47 +00:00
|
|
|
emit "b $false"
|
|
|
|
cost 8;
|
|
|
|
|
2016-10-23 19:54:14 +00:00
|
|
|
CJUMPLE(value:(cr)cr, PAIR(true:BLOCK.I, false:BLOCK.I))
|
2016-10-17 22:31:26 +00:00
|
|
|
emit "bc 4, 1, $true" /* IFFALSE GT */
|
2016-10-08 09:35:33 +00:00
|
|
|
emit "b $false"
|
2016-10-01 21:41:45 +00:00
|
|
|
cost 8;
|
|
|
|
|
2016-10-23 19:54:14 +00:00
|
|
|
CJUMPLT(value:(cr)cr, PAIR(true:BLOCK.I, false:BLOCK.I))
|
2016-10-17 22:31:26 +00:00
|
|
|
emit "bc 12, 0, $true" /* IFTRUE LT */
|
2016-10-08 09:35:33 +00:00
|
|
|
emit "b $false"
|
2016-10-02 15:50:34 +00:00
|
|
|
cost 8;
|
|
|
|
|
2016-10-29 09:57:56 +00:00
|
|
|
#define CALLLABEL(insn) \
|
|
|
|
insn (dest:LABEL.I) \
|
|
|
|
with corrupted(volatile) \
|
|
|
|
emit "bl $dest" \
|
|
|
|
cost 4;
|
2016-10-01 21:41:45 +00:00
|
|
|
|
2016-10-29 09:57:56 +00:00
|
|
|
CALLLABEL(CALL)
|
|
|
|
out:(int)reg = CALLLABEL(CALL.I)
|
|
|
|
out:(long)reg = CALLLABEL(CALL.L)
|
2016-10-22 10:13:57 +00:00
|
|
|
|
2016-10-29 09:57:56 +00:00
|
|
|
#define CALLINDIRECT(insn) \
|
|
|
|
insn (dest:(int)reg) \
|
|
|
|
with corrupted(volatile) \
|
|
|
|
emit "mtspr ctr, %dest" \
|
|
|
|
emit "bcctrl 20, 0, 0" \
|
|
|
|
cost 8;
|
2016-10-22 10:13:57 +00:00
|
|
|
|
2016-10-29 09:57:56 +00:00
|
|
|
CALLINDIRECT(CALL)
|
|
|
|
out:(int)reg = CALLINDIRECT(CALL.I)
|
|
|
|
out:(long)reg = CALLINDIRECT(CALL.L)
|
2016-10-08 09:35:33 +00:00
|
|
|
|
2016-10-23 19:54:14 +00:00
|
|
|
JUMP(dest:LABEL.I)
|
2016-10-08 09:35:33 +00:00
|
|
|
emit "b $dest"
|
|
|
|
cost 4;
|
|
|
|
|
|
|
|
|
2016-09-24 20:46:08 +00:00
|
|
|
|
|
|
|
/* Comparisons */
|
|
|
|
|
2016-10-23 19:54:14 +00:00
|
|
|
cr:(cr)cr = COMPARESI.I(left:(int)reg, right:(int)reg)
|
2016-10-08 09:35:33 +00:00
|
|
|
emit "cmp %cr, 0, %left, %right"
|
2016-09-24 20:46:08 +00:00
|
|
|
cost 4;
|
|
|
|
|
2016-10-23 19:54:14 +00:00
|
|
|
cr:(cr)cr = COMPARESI.I(left:(int)reg, right:CONST.I)
|
2016-10-09 10:32:36 +00:00
|
|
|
when signed_constant(%right, 16)
|
2016-10-08 09:35:33 +00:00
|
|
|
emit "cmpi %cr, 0, %left, $right"
|
2016-09-27 21:38:47 +00:00
|
|
|
cost 4;
|
|
|
|
|
2016-10-23 19:54:14 +00:00
|
|
|
cr:(cr)cr = COMPAREUI.I(left:(int)reg, right:(int)reg)
|
2016-10-08 09:35:33 +00:00
|
|
|
emit "cmpl %cr, 0, %left, %right"
|
|
|
|
cost 4;
|
|
|
|
|
2016-10-23 19:54:14 +00:00
|
|
|
cr:(cr)cr = COMPAREUI.I(left:(int)reg, right:CONST.I)
|
2016-10-09 10:32:36 +00:00
|
|
|
when signed_constant(%right, 16)
|
2016-10-08 09:35:33 +00:00
|
|
|
emit "cmpli %cr, 0, %left, $right"
|
|
|
|
cost 4;
|
|
|
|
|
2016-10-23 19:54:14 +00:00
|
|
|
out:(cr)cr = COMPARESI.I(in:(cr)cr, result:CONST.I)
|
2016-10-09 10:32:36 +00:00
|
|
|
when specific_constant(%result, 0)
|
2016-10-21 22:48:26 +00:00
|
|
|
with %out == %in
|
2016-10-23 19:54:14 +00:00
|
|
|
emit "! COMPARESI.I(cr, 0)"
|
2016-10-08 09:35:33 +00:00
|
|
|
cost 4;
|
|
|
|
|
2016-09-24 20:46:08 +00:00
|
|
|
|
|
|
|
|
2016-10-15 11:07:59 +00:00
|
|
|
/* Booleans */
|
|
|
|
|
2016-10-23 19:54:14 +00:00
|
|
|
out:(int)reg = IFEQ.I(in:(cr)cr)
|
2016-10-15 11:07:59 +00:00
|
|
|
emit "mfcr %out" /* get cr0 */
|
2016-10-22 18:32:51 +00:00
|
|
|
emit "rlwinm %out, %out, [32-2], 2, 31" /* extract just EQ */
|
2016-10-15 11:07:59 +00:00
|
|
|
cost 8;
|
|
|
|
|
2016-10-23 19:54:14 +00:00
|
|
|
out:(int)reg = IFEQ.I(in:(int)reg)
|
2016-10-15 11:07:59 +00:00
|
|
|
emit "cntlzw %out, %in" /* returns 0..32 */
|
2016-10-22 18:32:51 +00:00
|
|
|
emit "rlwinm %out, %out, [32-5], 5, 31" /* if 32, return 1, otherwise 0 */
|
2016-10-15 11:07:59 +00:00
|
|
|
cost 8;
|
|
|
|
|
2016-10-24 18:15:22 +00:00
|
|
|
out:(int)reg = IFLT.I(in:(cr)cr)
|
|
|
|
emit "mfcr %out" /* get cr0 */
|
|
|
|
emit "andi. %out, %out, 1" /* leave just LT */
|
|
|
|
cost 8;
|
|
|
|
|
|
|
|
out:(int)reg = IFLE.I(in:(cr)cr)
|
|
|
|
emit "mfcr %out" /* get cr0 */
|
|
|
|
emit "andi. %out, %out, 5" /* leave just LT and EQ */
|
|
|
|
emit "cntlzw %out, %out" /* returns 0..32 */
|
|
|
|
emit "rlwinm %out, %out, [32-5], 5, 31" /* if 32, return 1, otherwise 0 */
|
|
|
|
emit "xori %out, %out, 1" /* negate */
|
|
|
|
cost 8;
|
|
|
|
|
2016-10-15 11:07:59 +00:00
|
|
|
|
|
|
|
|
2016-09-24 20:46:08 +00:00
|
|
|
/* Conversions */
|
|
|
|
|
2016-10-23 19:54:14 +00:00
|
|
|
#if 0
|
2016-10-08 09:35:33 +00:00
|
|
|
out:(int)reg = CIU44(in:(int)reg)
|
2016-10-17 22:31:26 +00:00
|
|
|
with %out == %in
|
|
|
|
emit "! ciu44"
|
2016-10-08 09:35:33 +00:00
|
|
|
cost 4;
|
|
|
|
|
2016-10-12 20:58:46 +00:00
|
|
|
out:(int)reg = CUI44(in:(int)reg)
|
2016-10-17 22:31:26 +00:00
|
|
|
with %out == %in
|
|
|
|
emit "! cui44"
|
2016-10-12 20:58:46 +00:00
|
|
|
cost 4;
|
2016-10-23 19:54:14 +00:00
|
|
|
#endif
|
2016-09-24 20:46:08 +00:00
|
|
|
|
|
|
|
/* ALU operations */
|
2016-09-24 15:20:40 +00:00
|
|
|
|
2016-10-22 08:48:22 +00:00
|
|
|
#define ALUR(name, instr) \
|
|
|
|
out:(int)reg = name(left:(int)reg, right:(int)reg) \
|
|
|
|
emit instr " %out, %left, %right" \
|
|
|
|
cost 4; \
|
|
|
|
|
|
|
|
#define ALUC(name, instr) \
|
2016-10-23 19:54:14 +00:00
|
|
|
out:(int)reg = name(left:(int)reg, right:CONST.I) \
|
2016-10-22 08:48:22 +00:00
|
|
|
when signed_constant(%right, 16) \
|
|
|
|
emit instr " %out, %left, $right" \
|
|
|
|
cost 4; \
|
|
|
|
|
|
|
|
#define ALUC_reversed(name, instr) \
|
2016-10-23 19:54:14 +00:00
|
|
|
out:(int)reg = name(left:CONST.I, right:(int)reg) \
|
2016-10-22 08:48:22 +00:00
|
|
|
when signed_constant(%left, 16) \
|
|
|
|
emit instr " %out, %right, $left" \
|
|
|
|
cost 4; \
|
|
|
|
|
|
|
|
#define ALUCC(name, instr) \
|
|
|
|
ALUC(name, instr) \
|
|
|
|
ALUC_reversed(name, instr)
|
|
|
|
|
2016-10-23 19:54:14 +00:00
|
|
|
ALUR(ADD.I, "add")
|
|
|
|
ALUCC(ADD.I, "addi")
|
2016-10-15 16:38:46 +00:00
|
|
|
|
2016-10-23 19:54:14 +00:00
|
|
|
out:(int)reg = SUB.I(left:(int)reg, right:(int)reg)
|
2016-10-10 22:29:18 +00:00
|
|
|
emit "subf %out, %left, %right"
|
|
|
|
cost 4;
|
|
|
|
|
2016-10-23 19:54:14 +00:00
|
|
|
out:(int)reg = SUB.I(left:(int)reg, right:CONST.I)
|
2016-10-17 22:31:26 +00:00
|
|
|
emit "addi %out, %left, -[$right]"
|
2016-10-08 09:35:33 +00:00
|
|
|
cost 4;
|
2016-10-01 21:41:45 +00:00
|
|
|
|
2016-10-23 19:54:14 +00:00
|
|
|
out:(int)reg = MOD.I(left:(int)reg, right:(int)reg)
|
2016-10-08 09:35:33 +00:00
|
|
|
emit "divw %out, %left, %right"
|
|
|
|
emit "mullw %out, %out, %right"
|
|
|
|
emit "subf %out, %out, %left"
|
|
|
|
cost 12;
|
|
|
|
|
2016-10-23 19:54:14 +00:00
|
|
|
out:(int)reg = MODU.I(left:(int)reg, right:(int)reg)
|
2016-10-22 18:32:51 +00:00
|
|
|
emit "divwu %out, %left, %right"
|
|
|
|
emit "mullw %out, %out, %right"
|
|
|
|
emit "subf %out, %out, %left"
|
|
|
|
cost 12;
|
|
|
|
|
2016-10-23 19:54:14 +00:00
|
|
|
ALUR(MUL.I, "mullw")
|
|
|
|
ALUCC(MUL.I, "mulli")
|
2016-10-16 22:06:06 +00:00
|
|
|
|
2016-10-23 19:54:14 +00:00
|
|
|
ALUR(DIV.I, "divw")
|
|
|
|
ALUR(DIVU.I, "divwu")
|
2016-09-24 15:20:40 +00:00
|
|
|
|
2016-10-23 19:54:14 +00:00
|
|
|
ALUR(ASL.I, "slw")
|
2016-10-27 19:50:58 +00:00
|
|
|
ALUR(ASR.I, "sraw")
|
2016-10-09 12:45:13 +00:00
|
|
|
|
2016-10-23 19:54:14 +00:00
|
|
|
ALUR(LSL.I, "slw")
|
2016-10-27 19:50:58 +00:00
|
|
|
ALUR(LSR.I, "srw")
|
2016-10-22 18:32:51 +00:00
|
|
|
|
2016-10-23 19:54:14 +00:00
|
|
|
out:(int)reg = NEG.I(left:(int)reg)
|
2016-10-08 09:35:33 +00:00
|
|
|
emit "neg %out, %left"
|
|
|
|
cost 4;
|
2016-09-24 15:20:40 +00:00
|
|
|
|
2016-10-23 19:54:14 +00:00
|
|
|
out:(int)reg = NOT.I(left:(int)reg)
|
2016-10-22 18:32:51 +00:00
|
|
|
emit "cntlzw %out, %left"
|
|
|
|
emit "rlwinm %out, %out, 32-5, 5, 31"
|
|
|
|
cost 8;
|
|
|
|
|
2016-10-23 19:54:14 +00:00
|
|
|
ALUR(AND.I, "and")
|
|
|
|
ALUCC(AND.I, "andi.")
|
2016-10-17 22:31:26 +00:00
|
|
|
|
2016-10-23 19:54:14 +00:00
|
|
|
ALUR(OR.I, "or")
|
|
|
|
ALUCC(OR.I, "ori")
|
2016-10-17 22:31:26 +00:00
|
|
|
|
2016-10-23 19:54:14 +00:00
|
|
|
ALUR(EOR.I, "xor")
|
|
|
|
ALUCC(EOR.I, "xori")
|
2016-09-24 15:20:40 +00:00
|
|
|
|
2016-10-23 19:54:14 +00:00
|
|
|
out:(int)reg = value:LABEL.I
|
2016-10-08 09:35:33 +00:00
|
|
|
emit "la %out, $value"
|
2016-09-24 20:46:08 +00:00
|
|
|
cost 4;
|
|
|
|
|
2016-10-23 19:54:14 +00:00
|
|
|
out:(int)reg = value:BLOCK.I
|
2016-10-08 09:35:33 +00:00
|
|
|
emit "la %out, $value"
|
2016-09-24 15:20:40 +00:00
|
|
|
cost 4;
|
|
|
|
|
2016-10-23 19:54:14 +00:00
|
|
|
out:(int)reg = value:CONST.I
|
2016-10-10 22:23:35 +00:00
|
|
|
emit "li %out, $value"
|
2016-10-01 11:56:52 +00:00
|
|
|
cost 8;
|
|
|
|
|
2016-10-08 09:35:33 +00:00
|
|
|
|
2016-09-29 20:06:04 +00:00
|
|
|
/* FPU operations */
|
|
|
|
|
2016-10-22 08:48:22 +00:00
|
|
|
#define FPU4R(name, instr) \
|
|
|
|
out:(float)reg = name(left:(float)reg, right:(float)reg) \
|
|
|
|
emit instr " %out, %left, %right" \
|
|
|
|
cost 4; \
|
|
|
|
|
|
|
|
#define FPU8R(name, instr) \
|
|
|
|
out:(double)reg = name(left:(double)reg, right:(double)reg) \
|
|
|
|
emit instr " %out, %left, %right" \
|
|
|
|
cost 4; \
|
|
|
|
|
2016-10-23 19:54:14 +00:00
|
|
|
out:(float)reg = LOAD.F(addr:address)
|
2016-10-19 21:29:05 +00:00
|
|
|
emit "lfs %out, %addr"
|
|
|
|
cost 4;
|
|
|
|
|
2016-10-23 19:54:14 +00:00
|
|
|
out:(double)reg = LOAD.D(addr:address)
|
2016-10-21 21:31:00 +00:00
|
|
|
emit "lfd %out, %addr"
|
|
|
|
cost 4;
|
2016-10-09 13:08:03 +00:00
|
|
|
|
2016-10-29 09:57:56 +00:00
|
|
|
out:(float)reg = in:CONST.F
|
|
|
|
when specific_constant(%in, 0)
|
|
|
|
emit "la r0, .fd_00000000"
|
|
|
|
emit "lfs %out, 0(r0)"
|
|
|
|
cost 12;
|
|
|
|
|
2016-10-23 19:54:14 +00:00
|
|
|
FPU4R(ADDF.F, "fadds")
|
|
|
|
FPU8R(ADDF.D, "fadd")
|
2016-10-21 21:31:00 +00:00
|
|
|
|
2016-10-23 19:54:14 +00:00
|
|
|
FPU4R(SUBF.F, "fsubs")
|
|
|
|
FPU8R(SUBF.D, "fsub")
|
2016-10-09 13:08:03 +00:00
|
|
|
|
2016-10-23 19:54:14 +00:00
|
|
|
FPU4R(MULF.F, "fmuls")
|
|
|
|
FPU8R(MULF.D, "fmul")
|
2016-10-21 22:48:26 +00:00
|
|
|
|
2016-10-23 19:54:14 +00:00
|
|
|
FPU4R(DIVF.F, "fdivs")
|
|
|
|
FPU8R(DIVF.D, "fdiv")
|
2016-10-21 22:48:26 +00:00
|
|
|
|
2016-10-23 19:54:14 +00:00
|
|
|
out:(float)reg = NEGF.F(left:(float)reg)
|
2016-10-19 21:29:05 +00:00
|
|
|
emit "fneg %out, %left"
|
|
|
|
cost 4;
|
|
|
|
|
2016-10-23 19:54:14 +00:00
|
|
|
out:(double)reg = NEGF.D(left:(double)reg)
|
2016-10-21 22:48:26 +00:00
|
|
|
emit "fneg %out, %left"
|
|
|
|
cost 4;
|
|
|
|
|
2016-10-23 19:54:14 +00:00
|
|
|
cr:(cr)cr = COMPAREF.I(left:(float)reg, right:(float)reg)
|
2016-10-19 21:29:05 +00:00
|
|
|
emit "fcmpu %cr, %left, %right"
|
|
|
|
cost 4;
|
|
|
|
|
2016-10-23 19:54:14 +00:00
|
|
|
cr:(cr)cr = COMPARED.I(left:(double)reg, right:(double)reg)
|
2016-10-19 21:29:05 +00:00
|
|
|
emit "fcmpu %cr, %left, %right"
|
2016-10-21 22:48:26 +00:00
|
|
|
cost 4;
|
2016-10-19 21:29:05 +00:00
|
|
|
|
2016-10-05 19:07:29 +00:00
|
|
|
/* vim: set sw=4 ts=4 expandtab : */
|
|
|
|
|