From e85a43be98418a92c4fbe008f51c5bfbf049e707 Mon Sep 17 00:00:00 2001 From: ChinYikMing Date: Sun, 15 Dec 2024 04:15:55 +0800 Subject: [PATCH] Introduce ablation study feature Block chaining and macro-operation (MOP) fusion are accelerator techniques designed to enhance performance. To conduct further ablation studies, two feature options, MOP_FUSION and BLOCK_CHAINING, are introduced. These features can be freely combined with the other emulator features. Ablation study of these two techniques in system emulation: | Metric | Block Chaining & | Block Chaining | MOP fusion | | | MOP fusion | | | |--------------------|------------------|----------------|------------| | Dhrystone (DMIPS) | 175 | 123 | 175 | | (1000000 runs) | | | | | | | | | | Coremark (Iter/s) | 222 | 204 | 222 | --- Makefile | 8 ++++++++ src/emulate.c | 4 ++++ src/feature.h | 10 ++++++++++ 3 files changed, 22 insertions(+) diff --git a/Makefile b/Makefile index 79253124..f0928fde 100644 --- a/Makefile +++ b/Makefile @@ -18,6 +18,14 @@ CFLAGS += -include src/common.h -Isrc/ ENABLE_ELF_LOADER ?= 0 $(call set-feature, ELF_LOADER) +# Enable MOP fusion, easier for ablation study +ENABLE_MOP_FUSION ?= 1 +$(call set-feature, MOP_FUSION) + +# Enable block chaining, easier for ablation study +ENABLE_BLOCK_CHAINING ?= 1 +$(call set-feature, BLOCK_CHAINING) + # Enable system emulation ENABLE_SYSTEM ?= 0 $(call set-feature, SYSTEM) diff --git a/src/emulate.c b/src/emulate.c index 6d2669d1..293ce031 100644 --- a/src/emulate.c +++ b/src/emulate.c @@ -865,8 +865,10 @@ static block_t *block_find_or_translate(riscv_t *rv) #if RV32_HAS(GDBSTUB) if (likely(!rv->debug_mode)) #endif +#if RV32_HAS(MOP_FUSION) /* macro operation fusion */ match_pattern(rv, next_blk); +#endif #if !RV32_HAS(JIT) /* insert the block into block map */ @@ -1027,6 +1029,7 @@ void rv_step(void *arg) * the previous block. */ +#if RV32_HAS(BLOCK_CHAINING) if (prev) { rv_insn_t *last_ir = prev->ir_tail; /* chain block */ @@ -1042,6 +1045,7 @@ void rv_step(void *arg) } } } +#endif last_pc = rv->PC; #if RV32_HAS(JIT) #if RV32_HAS(T2C) diff --git a/src/feature.h b/src/feature.h index 6c33110a..a8956b47 100644 --- a/src/feature.h +++ b/src/feature.h @@ -73,5 +73,15 @@ #define RV32_FEATURE_ELF_LOADER 0 #endif +/* MOP fusion */ +#ifndef RV32_FEATURE_MOP_FUSION +#define RV32_FEATURE_MOP_FUSION 1 +#endif + +/* Block chaining */ +#ifndef RV32_FEATURE_BLOCK_CHAINING +#define RV32_FEATURE_BLOCK_CHAINING 1 +#endif + /* Feature test macro */ #define RV32_HAS(x) RV32_FEATURE_##x