From 7e31fbd5824d612e26a176aa2946497cfb2aa02e Mon Sep 17 00:00:00 2001 From: Guy Perfect Date: Mon, 11 Nov 2024 20:05:14 -0600 Subject: [PATCH] VSU performance tweak, add immediate notation setting --- core/vsu.c | 14 +++++++------- util/disassembler.c | 20 ++++++++++++++------ util/vbu.c | 1 + util/vbu.h | 3 +++ web/Constants.js | 2 ++ web/Core.js | 1 + web/VB.js | 15 +++++++++++++++ web/wasm.c | 7 ++++--- 8 files changed, 47 insertions(+), 16 deletions(-) diff --git a/core/vsu.c b/core/vsu.c index 0621f5c..9c16c25 100644 --- a/core/vsu.c +++ b/core/vsu.c @@ -87,16 +87,16 @@ static void vsuEmulateChannel(VB *sim, int index, uint32_t clocks) { if (!chan->int_.enb) return; + /* Frequency modifications are active */ + freqmod = + index == 4 && /* Channel 5 */ + sim->vsu.freqmod.enb && /* Modifications enabled */ + sim->vsu.freqmod.interval != 0 /* Modifications valid */ + ; + /* Process all clocks */ do { - /* Frequency modifications are active */ - freqmod = - index == 4 && /* Channel 5 */ - sim->vsu.freqmod.enb && /* Modifications enabled */ - sim->vsu.freqmod.interval != 0 /* Modifications valid */ - ; - /* Clocks until next state change */ until = clocks; if (chan->clocks < until) diff --git a/util/disassembler.c b/util/disassembler.c index 3165e85..5b06997 100644 --- a/util/disassembler.c +++ b/util/disassembler.c @@ -253,18 +253,24 @@ static void dasmOpDisp26(char*dest, VBU_DasmConfig*config, VBU_DasmLine*line) { } /* Format a 5-bit sign-extended immediate operand */ -static void dasmOpImm5S(char *dest, VBU_DasmLine *line) { +static void dasmOpImm5S(char *dest, VBU_DasmConfig*config, VBU_DasmLine *line){ + if (config->immediateNotation == VBU_NUMBER) + *dest++ = '#'; sprintf(dest, "%d", SignExtend(line->code[0], 5)); } /* Format a 5-bit zero-filled immediate operand */ -static void dasmOpImm5U(char *dest, VBU_DasmLine *line) { +static void dasmOpImm5U(char *dest, VBU_DasmConfig*config, VBU_DasmLine *line){ + if (config->immediateNotation == VBU_NUMBER) + *dest++ = '#'; sprintf(dest, "%d", line->code[0] & 31); } /* Format a 16-bit sign-extended immediate operand */ static void dasmOpImm16S(char*dest, VBU_DasmConfig*config, VBU_DasmLine*line) { - int32_t imm = (int16_t) ((int16_t) line->code[3] << 8 | line->code[2]); + int32_t imm = (int16_t) ((int16_t) line->code[3] << 8 | line->code[2]); + if (config->immediateNotation == VBU_NUMBER) + *dest++ = '#'; if (imm >= -256 && imm <= 256) { sprintf(dest, "%d", imm); return; @@ -279,6 +285,8 @@ static void dasmOpImm16S(char*dest, VBU_DasmConfig*config, VBU_DasmLine*line) { /* Format a 16-bit zero-filled immediate operand */ static void dasmOpImm16U(char*dest, VBU_DasmConfig*config, VBU_DasmLine*line) { uint16_t imm = (uint16_t) line->code[3] << 8 | line->code[2]; + if (config->immediateNotation == VBU_NUMBER) + *dest++ = '#'; dasmToHex(dest, config, 4, imm); } @@ -454,8 +462,8 @@ static void dasmOperand(char *dest, VBU_DasmConfig *config, case DASM_BCOND : dasmOpBCOND (dest, config, line); break; case DASM_DISP9 : dasmOpDisp9 (dest, config, line); break; case DASM_DISP26: dasmOpDisp26(dest, config, line); break; - case DASM_IMM5S : dasmOpImm5S (dest, line); break; - case DASM_IMM5U : dasmOpImm5U (dest, line); break; + case DASM_IMM5S : dasmOpImm5S (dest, config, line); break; + case DASM_IMM5U : dasmOpImm5U (dest, config, line); break; case DASM_IMM16S: dasmOpImm16S(dest, config, line); break; case DASM_IMM16U: dasmOpImm16U(dest, config, line); break; case DASM_JMP : dasmOpJMP (dest, config, line); break; @@ -680,7 +688,7 @@ static VBU_DasmLine* dasmDisassemble(VB *sim, uint32_t address, if (dasmLine(sim, &addr, pc, config, &lines, &size, &offset, x)) goto catch; } - return lines; + return VBU_REALLOC(lines, offset); /* Exception handler */ catch: diff --git a/util/vbu.c b/util/vbu.c index 8abbd1d..38b854b 100644 --- a/util/vbu.c +++ b/util/vbu.c @@ -47,6 +47,7 @@ VBUAPI VBU_DasmConfig* vbuDasmInit(VBU_DasmConfig *config) { config->conditionNotation = VBU_NAMES; config->hexCase = VBU_UPPER; config->hexNotation = VBU_0X; + config->immediateNotation = VBU_NONE; config->memoryNotation = VBU_OUTSIDE; config->mnemonicCase = VBU_UPPER; config->operandOrder = VBU_DEST_LAST; diff --git a/util/vbu.h b/util/vbu.h index dc02f01..6fd4287 100644 --- a/util/vbu.h +++ b/util/vbu.h @@ -29,6 +29,8 @@ extern "C" { #define VBU_L 0 #define VBU_LOWER 1 #define VBU_NAMES 1 +#define VBU_NONE 0 +#define VBU_NUMBER 1 #define VBU_NUMBERS 0 #define VBU_OUTSIDE 0 #define VBU_SPLIT 1 @@ -48,6 +50,7 @@ typedef struct { /* Defaults listed first */ uint8_t conditionNotation; /* NAMES, NUMBERS */ uint8_t hexCase; /* UPPER, LOWER */ uint8_t hexNotation; /* 0X, H, DOLLAR */ + uint8_t immediateNotation; /* NONE, NUMBER */ uint8_t memoryNotation; /* OUTSIDE, INSIDE */ uint8_t mnemonicCase; /* UPPER, LOWER */ uint8_t operandOrder; /* DEST_LAST, DEST_FIRST */ diff --git a/web/Constants.js b/web/Constants.js index 59244cb..a8f318f 100644 --- a/web/Constants.js +++ b/web/Constants.js @@ -61,6 +61,8 @@ let Constants = { L : 0, LOWER : 1, NAMES : 1, + NONE : 0, + NUMBER : 1, NUMBERS : 0, OUTSIDE : 0, SPLIT : 1, diff --git a/web/Core.js b/web/Core.js index 5829e54..bd1b13b 100644 --- a/web/Core.js +++ b/web/Core.js @@ -128,6 +128,7 @@ new class Core { message.config.conditionNotation, message.config.hexCase, message.config.hexNotation, + message.config.immediateNotation, message.config.memoryNotation, message.config.mnemonicCase, message.config.operandOrder, diff --git a/web/VB.js b/web/VB.js index 7b4fb84..1b2150f 100644 --- a/web/VB.js +++ b/web/VB.js @@ -19,6 +19,7 @@ class DasmConfig { #conditionNotation; #hexCase; #hexNotation; + #immediateNotation; #memoryNotation; #mnemonicCase; #operandOrder; @@ -40,6 +41,7 @@ class DasmConfig { this.#conditionNotation = Constants.VBU.NAMES; this.#hexCase = Constants.VBU.UPPER; this.#hexNotation = Constants.VBU["0X"]; + this.#immediateNotation = Constants.VBU.NONE; this.#memoryNotation = Constants.VBU.OUTSIDE; this.#mnemonicCase = Constants.VBU.UPPER; this.#operandOrder = Constants.VBU.DEST_LAST; @@ -125,6 +127,16 @@ class DasmConfig { this.#hexNotation = value; } + get immediateNotation() { return this.#immediateNotation; } + set immediateNotation(value) { + switch (value) { + case Constants.VBU.NONE : + case Constants.VBU.NUMBER: break; + default: return; + } + this.#immediateNotation = value; + } + get memoryNotation() { return this.#memoryNotation; } set memoryNotation(value) { switch (value) { @@ -407,6 +419,7 @@ class Sim extends HTMLElement { conditionNotation: config.conditionNotation, hexCase : config.hexCase, hexNotation : config.hexNotation, + immediateNotation: config.immediateNotation, memoryNotation : config.memoryNotation, mnemonicCase : config.mnemonicCase, operandOrder : config.operandOrder, @@ -650,6 +663,8 @@ class VB { static get L () { return Constants.VBU.L ; } static get LOWER () { return Constants.VBU.LOWER ; } static get NAMES () { return Constants.VBU.NAMES ; } + static get NONE () { return Constants.VBU.NONE ; } + static get NUMBER () { return Constants.VBU.NUMBER ; } static get NUMBERS () { return Constants.VBU.NUMBERS ; } static get OUTSIDE () { return Constants.VBU.OUTSIDE ; } static get RELATIVE () { return Constants.VBU.RELATIVE ; } diff --git a/web/wasm.c b/web/wasm.c index 15cd95a..428f0d6 100644 --- a/web/wasm.c +++ b/web/wasm.c @@ -108,9 +108,9 @@ EMSCRIPTEN_KEEPALIVE void* CreateSim() { // Disassemble from a simulation EMSCRIPTEN_KEEPALIVE void* Disassemble( int bcondNotation, int conditionCase, int conditionCL, int conditionEZ, - int conditionNotation, int hexCase, int hexNotation, int memoryNotation, - int mnemonicCase, int operandOrder, int programCase, int programNotation, - int setfNotation, int systemCase, int systemNotation, + int conditionNotation, int hexCase, int hexNotation, int immediateNotation, + int memoryNotation, int mnemonicCase, int operandOrder, int programCase, + int programNotation, int setfNotation, int systemCase, int systemNotation, VB *sim, uint32_t address, unsigned length, int line ) { VBU_DasmConfig config; @@ -121,6 +121,7 @@ EMSCRIPTEN_KEEPALIVE void* Disassemble( config.conditionNotation = conditionNotation; config.hexCase = hexCase; config.hexNotation = hexNotation; + config.immediateNotation = immediateNotation; config.memoryNotation = memoryNotation; config.mnemonicCase = mnemonicCase; config.operandOrder = operandOrder;