2016-09-25 20:17:14 +00:00
|
|
|
REGISTERS
|
|
|
|
|
2016-10-01 10:17:14 +00:00
|
|
|
r0 any int ret;
|
|
|
|
r1 any int;
|
|
|
|
r2 any int;
|
|
|
|
r3 any int;
|
|
|
|
r4 any int;
|
|
|
|
r5 any int;
|
|
|
|
r6 any int;
|
|
|
|
r7 any int;
|
|
|
|
r8 any int;
|
|
|
|
r9 any int;
|
|
|
|
r10 any int;
|
|
|
|
r11 any int;
|
|
|
|
|
|
|
|
s0 any float;
|
|
|
|
s1 any float;
|
|
|
|
s2 any float;
|
|
|
|
s3 any float;
|
|
|
|
s4 any float;
|
|
|
|
s5 any float;
|
|
|
|
s6 any float;
|
|
|
|
s7 any float;
|
|
|
|
s8 any float;
|
|
|
|
s9 any float;
|
|
|
|
|
|
|
|
cc cc;
|
|
|
|
|
2016-09-25 20:17:14 +00:00
|
|
|
|
|
|
|
DECLARATIONS
|
|
|
|
|
|
|
|
address fragment;
|
|
|
|
aluparam fragment;
|
2016-10-01 10:17:14 +00:00
|
|
|
|
2016-09-25 20:17:14 +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-01 10:17:14 +00:00
|
|
|
int;
|
|
|
|
float;
|
2016-09-25 20:17:14 +00:00
|
|
|
|
2016-09-24 20:46:08 +00:00
|
|
|
PAIR(BLOCK4, BLOCK4);
|
|
|
|
|
|
|
|
|
|
|
|
/* Miscellaneous special things */
|
|
|
|
|
2016-10-01 10:17:14 +00:00
|
|
|
PUSH4(in:int)
|
2016-09-24 20:46:08 +00:00
|
|
|
emit "push %in"
|
|
|
|
cost 4;
|
|
|
|
|
2016-10-01 10:17:14 +00:00
|
|
|
int = POP4
|
|
|
|
emit "pop %int"
|
2016-09-24 20:46:08 +00:00
|
|
|
cost 4;
|
|
|
|
|
|
|
|
RET
|
|
|
|
emit "ret"
|
|
|
|
cost 4;
|
|
|
|
|
2016-10-01 10:17:14 +00:00
|
|
|
SETRET4(in:ret)
|
2016-09-24 20:46:08 +00:00
|
|
|
emit "mov r0, %in"
|
|
|
|
cost 4;
|
|
|
|
|
2016-10-01 11:56:52 +00:00
|
|
|
int = in:REG4
|
|
|
|
prefers int(in)
|
|
|
|
cost 1;
|
2016-10-01 10:17:14 +00:00
|
|
|
|
2016-10-01 11:56:52 +00:00
|
|
|
float = in:REG4
|
|
|
|
prefers float(in)
|
|
|
|
cost 1;
|
|
|
|
|
|
|
|
ret = in:any emit "mov %ret, %in" cost 1;
|
|
|
|
any = in:int emit "mov %any, %in" cost 1;
|
|
|
|
int = in:any emit "mov %int, %in" cost 1;
|
|
|
|
any = in:float emit "mov %any, %in" cost 1;
|
|
|
|
float = in:any emit "mov %float, %in" cost 1;
|
2016-10-01 10:17:14 +00:00
|
|
|
|
2016-09-25 20:17:14 +00:00
|
|
|
|
2016-09-24 20:46:08 +00:00
|
|
|
/* Memory operations */
|
|
|
|
|
2016-10-01 10:17:14 +00:00
|
|
|
STORE4(addr:address, value:int)
|
2016-09-24 15:20:40 +00:00
|
|
|
emit "str %value, %addr"
|
|
|
|
cost 4;
|
|
|
|
|
2016-10-01 10:17:14 +00:00
|
|
|
int = LOAD4(addr:address)
|
|
|
|
emit "ldr %int, %addr"
|
2016-09-24 20:46:08 +00:00
|
|
|
cost 4;
|
|
|
|
|
2016-10-01 10:17:14 +00:00
|
|
|
int = LOAD1(addr:address)
|
|
|
|
emit "ldrb %int, %addr"
|
2016-09-24 20:46:08 +00:00
|
|
|
cost 4;
|
|
|
|
|
2016-10-01 10:17:14 +00:00
|
|
|
int = CIU14(LOAD1(addr:address))
|
|
|
|
emit "ldrb %int, %addr"
|
2016-09-24 20:46:08 +00:00
|
|
|
cost 4;
|
2016-09-25 15:14:54 +00:00
|
|
|
|
2016-10-01 10:17:14 +00:00
|
|
|
int = CII14(CIU41(CIU14(LOAD1(addr:address))))
|
|
|
|
emit "ldrsb %int, %addr"
|
2016-09-25 15:14:54 +00:00
|
|
|
cost 4;
|
2016-09-24 20:46:08 +00:00
|
|
|
|
|
|
|
|
|
|
|
/* Locals */
|
|
|
|
|
2016-10-01 10:17:14 +00:00
|
|
|
int = in:LOCAL4
|
|
|
|
emit "add %int, fp, #$in"
|
2016-09-24 15:20:40 +00:00
|
|
|
cost 4;
|
|
|
|
|
2016-09-24 20:46:08 +00:00
|
|
|
address = in:LOCAL4
|
2016-09-25 20:17:14 +00:00
|
|
|
emit "[fp, #$in]";
|
2016-09-24 20:46:08 +00:00
|
|
|
|
|
|
|
|
|
|
|
/* Memory addressing modes */
|
|
|
|
|
2016-10-01 10:17:14 +00:00
|
|
|
address = ADD4(addr:int, offset:CONST4)
|
2016-09-25 20:17:14 +00:00
|
|
|
emit "[%addr, #$offset]";
|
2016-09-24 15:20:40 +00:00
|
|
|
|
2016-10-01 10:17:14 +00:00
|
|
|
address = addr:int
|
2016-09-25 20:17:14 +00:00
|
|
|
emit "[%addr]";
|
2016-09-24 15:20:40 +00:00
|
|
|
|
2016-09-24 20:46:08 +00:00
|
|
|
|
|
|
|
/* Branches */
|
|
|
|
|
|
|
|
JUMP(addr:BLOCK4)
|
2016-09-25 15:14:54 +00:00
|
|
|
emit "b $addr"
|
2016-09-24 20:46:08 +00:00
|
|
|
cost 4;
|
|
|
|
|
2016-10-01 10:17:14 +00:00
|
|
|
CJUMPEQ(value:cc, PAIR(true:BLOCK4, false:BLOCK4))
|
2016-09-27 21:38:47 +00:00
|
|
|
emit "beq $true"
|
|
|
|
emit "b $false"
|
|
|
|
cost 8;
|
|
|
|
|
2016-09-24 20:46:08 +00:00
|
|
|
|
|
|
|
/* Comparisons */
|
|
|
|
|
2016-10-01 10:17:14 +00:00
|
|
|
cc = COMPARES4(left:int, right:aluparam)
|
2016-09-25 09:49:51 +00:00
|
|
|
emit "cmp %left, %right"
|
2016-09-24 20:46:08 +00:00
|
|
|
cost 4;
|
|
|
|
|
2016-10-01 10:17:14 +00:00
|
|
|
cc = COMPARES4(COMPARES4(left:int, right:aluparam), CONST4)
|
2016-09-27 21:38:47 +00:00
|
|
|
emit "cmp %left, %right"
|
|
|
|
cost 4;
|
|
|
|
|
2016-10-01 10:17:14 +00:00
|
|
|
int = cc
|
|
|
|
emit "mov %int, #0"
|
|
|
|
emit "movlt %int, #-1"
|
|
|
|
emit "movgt %int, #1"
|
2016-09-24 20:46:08 +00:00
|
|
|
cost 12;
|
|
|
|
|
|
|
|
|
|
|
|
/* Conversions */
|
|
|
|
|
2016-10-01 10:17:14 +00:00
|
|
|
int = CII14(CIU41(value:int))
|
|
|
|
emit "sxtb %int, %value"
|
2016-09-24 20:46:08 +00:00
|
|
|
cost 4;
|
|
|
|
|
2016-10-01 10:17:14 +00:00
|
|
|
int = CIU41(in:int)
|
|
|
|
emit "and %int, %in, #0xff"
|
2016-09-24 20:46:08 +00:00
|
|
|
cost 4;
|
|
|
|
|
|
|
|
|
|
|
|
/* ALU operations */
|
2016-09-24 15:20:40 +00:00
|
|
|
|
2016-10-01 10:17:14 +00:00
|
|
|
int = ADD4(left:int, right:aluparam)
|
|
|
|
emit "add %int, %left, %right"
|
2016-09-24 15:20:40 +00:00
|
|
|
cost 4;
|
|
|
|
|
2016-10-01 10:17:14 +00:00
|
|
|
int = ADD4(left:aluparam, right:int)
|
|
|
|
emit "add %int, %right, %left"
|
2016-09-24 15:20:40 +00:00
|
|
|
cost 4;
|
|
|
|
|
2016-09-24 16:31:35 +00:00
|
|
|
aluparam = value:CONST4
|
2016-09-25 20:17:14 +00:00
|
|
|
emit "#$value";
|
2016-09-24 15:20:40 +00:00
|
|
|
|
2016-10-01 10:17:14 +00:00
|
|
|
aluparam = value:int
|
2016-09-29 20:06:04 +00:00
|
|
|
emit "%value";
|
2016-09-24 15:20:40 +00:00
|
|
|
|
2016-10-01 10:17:14 +00:00
|
|
|
int = value:aluparam
|
|
|
|
emit "mov %int, %value"
|
2016-09-24 15:20:40 +00:00
|
|
|
cost 4;
|
|
|
|
|
2016-10-01 10:17:14 +00:00
|
|
|
int = value:LABEL4
|
|
|
|
emit "adr %int, $value"
|
2016-09-24 20:46:08 +00:00
|
|
|
cost 4;
|
|
|
|
|
2016-10-01 10:17:14 +00:00
|
|
|
int = value:BLOCK4
|
|
|
|
emit "adr %int, $value"
|
2016-09-24 15:20:40 +00:00
|
|
|
cost 4;
|
|
|
|
|
2016-10-01 11:56:52 +00:00
|
|
|
int = value:CONST4
|
|
|
|
emit "ldr %int, address-containing-$value"
|
|
|
|
cost 8;
|
|
|
|
|
2016-10-01 17:10:22 +00:00
|
|
|
float = value:CONSTF4
|
2016-10-01 11:56:52 +00:00
|
|
|
emit "vldr %float, address-containing-$value"
|
2016-09-29 17:58:02 +00:00
|
|
|
cost 8;
|
2016-09-29 20:06:04 +00:00
|
|
|
|
|
|
|
/* FPU operations */
|
|
|
|
|
2016-10-01 10:17:14 +00:00
|
|
|
float = ADDF4(left:float, right:float)
|
|
|
|
emit "fadds %float, %left, %right"
|
2016-09-29 20:06:04 +00:00
|
|
|
cost 4;
|
|
|
|
|