From a9e001bd307e75cba39a28bc4ce05518929825c2 Mon Sep 17 00:00:00 2001 From: Stanislav Shwartsman Date: Sat, 5 Jan 2008 10:21:25 +0000 Subject: [PATCH] Optimize short traces --- bochs/cpu/cpu.cc | 27 ++++++++++++++------------- bochs/cpu/cpu.h | 4 ++-- 2 files changed, 16 insertions(+), 15 deletions(-) diff --git a/bochs/cpu/cpu.cc b/bochs/cpu/cpu.cc index c5fd2663d..6d9334c23 100644 --- a/bochs/cpu/cpu.cc +++ b/bochs/cpu/cpu.cc @@ -1,5 +1,5 @@ ///////////////////////////////////////////////////////////////////////// -// $Id: cpu.cc,v 1.196 2007-12-30 17:53:12 sshwarts Exp $ +// $Id: cpu.cc,v 1.197 2008-01-05 10:21:25 sshwarts Exp $ ///////////////////////////////////////////////////////////////////////// // // Copyright (C) 2001 MandrakeSoft S.A. @@ -100,7 +100,7 @@ static Bit32u iCacheTraceLengh[BX_MAX_TRACE_LENGTH]; #if BX_SUPPORT_TRACE_CACHE -bxICacheEntry_c* BX_CPU_C::fetchInstructionTrace(bxInstruction_c *iStorage, bx_address eipBiased) +bxInstruction_c* BX_CPU_C::fetchInstructionTrace(bxInstruction_c *iStorage, unsigned *len, bx_address eipBiased) { bx_phy_address pAddr = (bx_phy_address)(BX_CPU_THIS_PTR pAddrA20Page + eipBiased); unsigned iCacheHash = BX_CPU_THIS_PTR iCache.hash(pAddr); @@ -113,8 +113,10 @@ bxICacheEntry_c* BX_CPU_C::fetchInstructionTrace(bxInstruction_c *iStorage, bx_a if ((trace->pAddr == pAddr) && (trace->writeStamp == pageWriteStamp)) { + // We are lucky - trace cache hit ! InstrICache_Increment(iCacheTraceLengh[trace->ilen-1]); - return trace; // We are lucky - trace cache hit ! + *len = trace->ilen; + return trace->i; } // We are not so lucky, but let's be optimistic - try to build trace from @@ -136,7 +138,7 @@ bxICacheEntry_c* BX_CPU_C::fetchInstructionTrace(bxInstruction_c *iStorage, bx_a bxInstruction_c *i = trace->i; - for (unsigned len=0;len 0) { + if (n > 0) { // The trace is already valid, it has several instructions inside, // in this case just drop the boundary instruction and stop // tracing. @@ -157,7 +159,9 @@ bxICacheEntry_c* BX_CPU_C::fetchInstructionTrace(bxInstruction_c *iStorage, bx_a // the trace cache entry invalid (do not cache the instruction) trace->writeStamp = ICacheWriteStampInvalid; boundaryFetch(fetchPtr, remainingInPage, iStorage); - return 0; + + *len = 1; + return iStorage; } // add instruction to the trace ... @@ -183,7 +187,8 @@ bxICacheEntry_c* BX_CPU_C::fetchInstructionTrace(bxInstruction_c *iStorage, bx_a if (mergeTraces(trace, i+1, pAddr)) break; } - return trace; + *len = trace->ilen; + return trace->i; } bx_bool BX_CPU_C::mergeTraces(bxICacheEntry_c *trace, bxInstruction_c *i, bx_phy_address pAddr) @@ -394,17 +399,13 @@ void BX_CPU_C::cpu_loop(Bit32u max_instr_count) eipBiased = RIP + BX_CPU_THIS_PTR eipPageBias; } + #if BX_SUPPORT_TRACE_CACHE == 0 // fetch and decode single instruction bxInstruction_c *i = fetchInstruction(&iStorage, eipBiased); #else unsigned n, length = 1; - bxInstruction_c *i = &iStorage; - bxICacheEntry_c *trace = fetchInstructionTrace(&iStorage, eipBiased); - if (trace) { - i = trace->i; // execute from first instruction in trace - length = trace->ilen; - } + bxInstruction_c *i = fetchInstructionTrace(&iStorage, &length, eipBiased); Bit32u currPageWriteStamp = *(BX_CPU_THIS_PTR currPageWriteStampPtr); for (n=0; n < length; n++, i++) { diff --git a/bochs/cpu/cpu.h b/bochs/cpu/cpu.h index a58653f27..97317662a 100644 --- a/bochs/cpu/cpu.h +++ b/bochs/cpu/cpu.h @@ -1,5 +1,5 @@ ///////////////////////////////////////////////////////////////////////// -// $Id: cpu.h,v 1.406 2007-12-30 20:16:34 sshwarts Exp $ +// $Id: cpu.h,v 1.407 2008-01-05 10:21:25 sshwarts Exp $ ///////////////////////////////////////////////////////////////////////// // // Copyright (C) 2001 MandrakeSoft S.A. @@ -3112,7 +3112,7 @@ public: // for now... BX_SMF unsigned fetchDecode64(Bit8u *fetchPtr, bxInstruction_c *i, unsigned remainingInPage); #endif #if BX_SUPPORT_TRACE_CACHE - BX_SMF bxICacheEntry_c* fetchInstructionTrace(bxInstruction_c *, bx_address); + BX_SMF bxInstruction_c* fetchInstructionTrace(bxInstruction_c *iStorage, unsigned *len, bx_address eipBiased); BX_SMF bx_bool mergeTraces(bxICacheEntry_c *trace, bxInstruction_c *, bx_phy_address pAddr); BX_SMF void instrumentTraces(void); #else