From efc7c3000a5064e7b13f465c5aa61d9fea41d882 Mon Sep 17 00:00:00 2001 From: ekeeke31 Date: Sat, 7 Aug 2010 14:22:36 +0000 Subject: [PATCH] [68k] improved MULU/MULS instructions timing accuracy --- source/m68k/m68kCycleAccurate.h | 14 +++++--------- 1 file changed, 5 insertions(+), 9 deletions(-) diff --git a/source/m68k/m68kCycleAccurate.h b/source/m68k/m68kCycleAccurate.h index 97ef667..7a6ffd3 100644 --- a/source/m68k/m68kCycleAccurate.h +++ b/source/m68k/m68kCycleAccurate.h @@ -169,12 +169,10 @@ INLINE unsigned getDivs68kCycles( LONG dividend, SHORT divisor) INLINE unsigned getMulu68kCycles( WORD source) { - int i; - unsigned mcycles = 266; /* count number of bits set to 1 */ - for( i = 0; i < 15; i++) + while (source) { if (source & 1) { @@ -194,22 +192,20 @@ INLINE unsigned getMulu68kCycles( WORD source) INLINE unsigned getMuls68kCycles( SHORT source) { - int i; - unsigned mcycles = 266; /* detect 01 or 10 patterns */ LONG temp = source << 1; - temp ^= source; + temp = (temp ^ source) & 0xFFFF; /* count number of bits set to 1 */ - for( i = 0; i < 15; i++) + while (temp) { - if (source & 1) + if (temp & 1) { mcycles += 14; } - source >>= 1; + temp >>= 1; } /* 38 + 2*N */