From 356aee5e9f498aae91858d4ec1e7c0008455a5d0 Mon Sep 17 00:00:00 2001 From: Connor Olding Date: Thu, 7 Apr 2016 07:56:46 -0700 Subject: [PATCH] add branch-likely pseudo-instructions --- lips/data.lua | 41 ++++++++++++++++++++++++----------------- lips/overrides.lua | 12 ++++++++++++ 2 files changed, 36 insertions(+), 17 deletions(-) diff --git a/lips/data.lua b/lips/data.lua index 3fee16f..7d880e7 100644 --- a/lips/data.lua +++ b/lips/data.lua @@ -371,17 +371,19 @@ data.instructions = { -- pseudo-instructions - B = {4, 'r', '00o'}, -- BEQ R0, R0, offset - BAL = {1, 'r', '0Co', 17}, -- BGEZAL R0, offset - BEQZ = {4, 'sr', 's0o'}, -- BEQ RS, R0, offset - BNEZ = {5, 'sr', 's0o'}, -- BNE RS, R0, offset - CL = {0, 'd', '00d0C', 37}, -- OR RD, R0, R0 - MOV = {0, 'ds', 's0d0C', 37}, -- OR RD, RS, R0 - NEG = {0, 'dt', '0td0C', 34}, -- SUB RD, R0, RT - NOP = {0, '', '0'}, -- SLL R0, R0, 0 - NOT = {0, 'ds', 's0d0C', 39}, -- NOR RD, RS, R0 - SUBI = {8, 'tsk', 'sti'}, -- ADDI RT, RS, -immediate - SUBIU = {9, 'tsk', 'sti'}, -- ADDIU RT, RS, -immediate + B = { 4, 'r', '00o'}, -- BEQ R0, R0, offset + BAL = { 1, 'r', '0Co', 17}, -- BGEZAL R0, offset + BEQZ = { 4, 'sr', 's0o'}, -- BEQ RS, R0, offset + BEQZL = {20, 'sr', 's0o'}, -- BEQL RS, R0, offset + BNEZ = { 5, 'sr', 's0o'}, -- BNE RS, R0, offset + BNEZL = {21, 'sr', 's0o'}, -- BNEL RS, R0, offset + CL = { 0, 'd', '00d0C', 37}, -- OR RD, R0, R0 + MOV = { 0, 'ds', 's0d0C', 37}, -- OR RD, RS, R0 + NEG = { 0, 'dt', '0td0C', 34}, -- SUB RD, R0, RT + NOP = { 0, '', '0'}, -- SLL R0, R0, 0 + NOT = { 0, 'ds', 's0d0C', 39}, -- NOR RD, RS, R0 + SUBI = { 8, 'tsk', 'sti'}, -- ADDI RT, RS, -immediate + SUBIU = { 9, 'tsk', 'sti'}, -- ADDIU RT, RS, -immediate -- ...that expand to multiple instructions LI = __, -- only one instruction for values < 0x10000 @@ -409,12 +411,17 @@ data.instructions = { SLE = __, SLEI = __, SLEIU = __, SLEU = __, SNE = __, SNEI = __, SNEIU = __, SNEU = __, - BEQI = __, - BNEI = __, - BGE = __, BGEI = __, - BLE = __, BLEI = __, - BLT = __, BLTI = __, - BGT = __, BGTI = __, + BGE = __, + BLE = __, + BLT = __, + BGT = __, + + BEQI = __, BEQIL = __, + BNEI = __, BNEIL = __, + BGEI = __, BGEIL = __, + BLEI = __, BLEIL = __, + BLTI = __, BLTIL = __, + BGTI = __, BGTIL = __, } data.all_instructions = {} diff --git a/lips/overrides.lua b/lips/overrides.lua index 6893414..28ec0c0 100644 --- a/lips/overrides.lua +++ b/lips/overrides.lua @@ -237,6 +237,12 @@ local branch_basics = { BLEI = "BNE", BLTI = "BNE", BNEI = "BNE", + BEQIL = "BEQL", + BGEIL = "BEQL", + BGTIL = "BEQL", + BLEIL = "BNEL", + BLTIL = "BNEL", + BNEIL = "BNEL", } function overrides.BEQI(self, name) @@ -261,6 +267,8 @@ function overrides.BEQI(self, name) self:format_out(branch, args) end overrides.BNEI = overrides.BEQI +overrides.BEQIL = overrides.BEQI +overrides.BNEIL = overrides.BEQI function overrides.BLTI(self, name) local slti = instructions['SLTI'] @@ -284,6 +292,8 @@ function overrides.BLTI(self, name) self:format_out(branch, args) end overrides.BGEI = overrides.BLTI +overrides.BLTIL = overrides.BLTI +overrides.BGEIL = overrides.BLTI function overrides.BLEI(self, name) -- TODO: this can probably be optimized @@ -323,5 +333,7 @@ function overrides.BLEI(self, name) self:format_out(branch, args) end overrides.BGTI = overrides.BLEI +overrides.BLEIL = overrides.BLEI +overrides.BGTIL = overrides.BLEI return overrides