From 794e602a99d0e082fe1df9e3b6df006832e52ba2 Mon Sep 17 00:00:00 2001 From: mrb0nk500 Date: Fri, 14 Jan 2022 13:03:50 -0400 Subject: Start work on new instruction handler macro. This macro will create a function for each opcode, but with only a single block of code for each one. It uses a bitmask (one bit for each opcode) that will evaluate which blocks of code are used by each opcode. The bitmask checks are (usually) evaluated at compile time, which means that each function will only have the blocks that had the bit for that opcode set in the bitmask. --- sux.h | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/sux.h b/sux.h index f2c4227..fe70827 100644 --- a/sux.h +++ b/sux.h @@ -1778,6 +1778,29 @@ static /*inline*/ void exec_base_inst(struct sux *cpu, uint8_t opcode, uint8_t p } } +#if 0 +#define t(w8, w7, w6, w5, w4, w3, w2, w1, w0, code) \ + do { \ + const uint32_t mask[9] = {w0, w1, w2, w3, w4, w5, w6, w7, w8}; \ + if (mask[o8] & o8m) { code } \ + } while (0); +#else +#define t(w8, w7, w6, w5, w4, w3, w2, w1, w0) \ + if ((const uint32_t [9]){w0, w1, w2, w3, w4, w5, w6, w7, w8}[o8] & o8m) +#endif + +#define inst(op, ext) \ +static /*inline*/ void inst_##op(struct sux *cpu, uint8_t prefix, int inc_pc, int inc_clk, uint8_t thread) { \ + const unsigned int o8 = 0x##op / 32, o8m = 1 << (0x##op % 32); \ + uint64_t addr = 0, idx = 0, tmp = -1 \ + uint8_t pbits = 0x##op < 0x100 ? 0x30 : 0x20; \ + t(1, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000) { addr = 0xFFA0; } /* NMI Vector. */ \ + t(2, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000) { addr = 0xFFC0; } /* Reset Vector. */ \ + t(4, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000) { addr = 0xFFE0; } /* IRQ Vector. */ \ + t(0, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000200, 0x00000000, 0x00000000, 0x00000000) { addr = 0xFFF0; } /* BRK Vector. */ \ + t(0, 0x00400160, 0x00400160, 0x00000160, 0x00000160, 0x00001160, 0x10005161, 0x10005161, 0x00001160) { addr = read_addr(cpu, prefix, inc_clk, ZM, inc_pc) + idx; } /* Read Zero Matrix address. */ \ +} + #undef ORTHO_1CC #undef ORTHO_1OP #undef ORTHO_2OP -- cgit v1.2.3-13-gbd6f