From c4e13c1ef97a757136bd52ce23c52c5598ebf3c1 Mon Sep 17 00:00:00 2001 From: Danny Milosavljevic Date: Sat, 26 Dec 2020 16:51:26 +0100 Subject: [PATCH] arm-asm: Add clz, sxtb, sxth, uxtb, uxth --- arm-asm.c | 47 +++++++++++++++++++++++++++++++++++++++++++++++ arm-tok.h | 10 ++++++++++ 2 files changed, 57 insertions(+) diff --git a/arm-asm.c b/arm-asm.c index b6dfafea..c2598a83 100644 --- a/arm-asm.c +++ b/arm-asm.c @@ -190,6 +190,47 @@ static void asm_unary_opcode(TCCState *s1, int token) } } +static void asm_binary_opcode(TCCState *s1, int token) +{ + Operand ops[2]; + parse_operand(s1, &ops[0]); + if (tok == ',') + next(); + else + expect("','"); + parse_operand(s1, &ops[1]); + if (ops[0].type != OP_REG32) { + expect("(destination operand) register"); + return; + } + + if (ops[1].type != OP_REG32) + expect("(source operand) register"); + else switch (ARM_INSTRUCTION_GROUP(token)) { + case TOK_ASM_clzeq: + asm_emit_opcode(token, 0x16f0f10 | (ops[0].reg << 12) | ops[1].reg); + break; + case TOK_ASM_sxtbeq: + /* TODO: optional ROR (8|16|24) */ + asm_emit_opcode(token, 0x6af0070 | (ops[0].reg << 12) | ops[1].reg); + break; + case TOK_ASM_sxtheq: + /* TODO: optional ROR (8|16|24) */ + asm_emit_opcode(token, 0x6bf0070 | (ops[0].reg << 12) | ops[1].reg); + break; + case TOK_ASM_uxtbeq: + /* TODO: optional ROR (8|16|24) */ + asm_emit_opcode(token, 0x6ef0070 | (ops[0].reg << 12) | ops[1].reg); + break; + case TOK_ASM_uxtheq: + /* TODO: optional ROR (8|16|24) */ + asm_emit_opcode(token, 0x6ff0070 | (ops[0].reg << 12) | ops[1].reg); + break; + default: + expect("binary instruction"); + } +} + static void asm_block_data_transfer_opcode(TCCState *s1, int token) { uint32_t opcode; @@ -268,6 +309,12 @@ ST_FUNC void asm_opcode(TCCState *s1, int token) return asm_nullary_opcode(token); case TOK_ASM_swieq: return asm_unary_opcode(s1, token); + case TOK_ASM_clzeq: + case TOK_ASM_sxtbeq: + case TOK_ASM_sxtheq: + case TOK_ASM_uxtbeq: + case TOK_ASM_uxtheq: + return asm_binary_opcode(s1, token); default: expect("known instruction"); } diff --git a/arm-tok.h b/arm-tok.h index db1935fb..06cee7a2 100644 --- a/arm-tok.h +++ b/arm-tok.h @@ -56,6 +56,16 @@ DEF_ASM_CONDED(wfi) DEF_ASM_CONDED(swi) + /* misc */ + DEF_ASM_CONDED(clz) + + /* size conversion */ + + DEF_ASM_CONDED(sxtb) + DEF_ASM_CONDED(sxth) + DEF_ASM_CONDED(uxtb) + DEF_ASM_CONDED(uxth) + /* instruction macros */ DEF_ASM_CONDED(push)