diff --git a/nemu/Makefile b/nemu/Makefile index e058045535d99d11ce3bf744ce435c0ce42fc517..57860b6a50f54ca68556e6a401b887100970ba5f 100644 --- a/nemu/Makefile +++ b/nemu/Makefile @@ -19,8 +19,8 @@ include Makefile.git CXX ?= g++ LD = $(CXX) INCLUDES = $(addprefix -I, $(INC_DIR)) -CFLAGS += -O2 -MMD -Wall -ggdb3 $(INCLUDES) -fomit-frame-pointer -std=c++17 -CFLAGS += -DDIFF_TEST_QEMU +CFLAGS += -O3 -MMD -Wall -ggdb $(INCLUDES) -fomit-frame-pointer -std=c++17 +# CFLAGS += -DDIFF_TEST_QEMU # Source code generation before any targets. SUBDIRS = src/monitor/debug/expr_impl diff --git a/nemu/include/common.h b/nemu/include/common.h index b734ebc0e3100c1c84e49fb8e93a1cb011d8eee5..83d7ae959575662c70fa4d9f20b3afeffd98cc32 100644 --- a/nemu/include/common.h +++ b/nemu/include/common.h @@ -1,7 +1,7 @@ #ifndef __COMMON_H__ #define __COMMON_H__ -#define DEBUG +//#define DEBUG //#define DIFF_TEST #if _SHARE diff --git a/nemu/src/cpu/exec/exec.cc b/nemu/src/cpu/exec/exec.cc index 3c67656de60b0c26d801a851b00a8a3dd5de09d2..f6e847abcce4ca5bc94d63abc7c389f9e799c9d6 100644 --- a/nemu/src/cpu/exec/exec.cc +++ b/nemu/src/cpu/exec/exec.cc @@ -14,10 +14,8 @@ typedef struct { #define EMPTY EX(inv) static inline void set_width(int width) { - if (width == 0) { - width = decoding.is_operand_size_16 ? 2 : 4; - } - decoding.src.width = decoding.dest.width = decoding.src2.width = width; + const auto tmp = width == 0 ? (decoding.is_operand_size_16 ? 2 : 4) : width; + decoding.src.width = decoding.dest.width = decoding.src2.width = tmp; } /* Instruction Decode and EXecute */ @@ -211,7 +209,7 @@ namespace EHelperImpl { idex(eip, &opcode_table[opcode]); } - make_EHelper(real) { + __attribute__((hot)) make_EHelper(real) { uint32_t opcode = instr_fetch(eip, 1); decoding.opcode = opcode; set_width(opcode_table[opcode].width); diff --git a/nemu/src/memory/memory.cc b/nemu/src/memory/memory.cc index 0206211aa00cb15402a95ff951e9d64d1652a2d1..f4ce3bf89836de568c700095f03384f0db196bf4 100644 --- a/nemu/src/memory/memory.cc +++ b/nemu/src/memory/memory.cc @@ -11,7 +11,14 @@ uint8_t pmem[PMEM_SIZE]; /* Memory accessing interfaces */ -uint32_t paddr_read(paddr_t addr, int len) { +__attribute__((hot)) uint32_t paddr_read(paddr_t addr, int len) { + switch(len) { + case 4: return pmem_rw(addr, uint32_t); + case 2: return pmem_rw(addr, uint32_t) & 0x0000ffff; + case 1: return pmem_rw(addr, uint32_t) & 0x000000ff; + case 3: return pmem_rw(addr, uint32_t) & 0x00ffffff; + case 0: return 0; + } return pmem_rw(addr, uint32_t) & (~0u >> ((4 - len) << 3)); }