diff --git a/bochs/CHANGES b/bochs/CHANGES index 5d76fc75e..0a25c3bca 100644 --- a/bochs/CHANGES +++ b/bochs/CHANGES @@ -45,6 +45,7 @@ Bochs repository moved to the SVN version control ! - VBE: added HDTV resolutions (patch by Tristan Schmelcher) - SF patches applied + [3289448] optimized powerpc byte swapping by Heikki Lindholm [3292581] Core Audio first aid by Heikki Lindholm [3205979] Compilation fixes for OpenBSD by Brad Smith [3290979] acpi/muldiv64 endian bug by Heikki Lindholm diff --git a/bochs/bochs.h b/bochs/bochs.h index 589326ffd..87361d38b 100644 --- a/bochs/bochs.h +++ b/bochs/bochs.h @@ -511,19 +511,27 @@ BX_CPP_INLINE Bit16u bx_bswap16(Bit16u val16) { return (val16<<8) | (val16>>8); } - + +#if BX_HAVE___BUILTIN_BSWAP32 +#define bx_bswap32 __builtin_bswap32 +#else BX_CPP_INLINE Bit32u bx_bswap32(Bit32u val32) { val32 = ((val32<<8) & 0xFF00FF00) | ((val32>>8) & 0x00FF00FF); return (val32<<16) | (val32>>16); } +#endif +#if BX_HAVE___BUILTIN_BSWAP64 +#define bx_bswap64 __builtin_bswap64 +#else BX_CPP_INLINE Bit64u bx_bswap64(Bit64u val64) { Bit32u lo = bx_bswap32((Bit32u)(val64 >> 32)); Bit32u hi = bx_bswap32((Bit32u)(val64 & 0xFFFFFFFF)); return ((Bit64u)hi << 32) | (Bit64u)lo; } +#endif // These are some convenience macros which abstract out accesses between // a variable in native byte ordering to/from guest (x86) memory, which is diff --git a/bochs/config.h.in b/bochs/config.h.in index 0ed8d6962..0a273448b 100644 --- a/bochs/config.h.in +++ b/bochs/config.h.in @@ -132,6 +132,9 @@ #define BX_HAVE_GMTIME 0 #define BX_HAVE_MKTIME 0 #define BX_HAVE_NET_IF_H 0 +#define BX_HAVE___BUILTIN_BSWAP16 0 +#define BX_HAVE___BUILTIN_BSWAP32 0 +#define BX_HAVE___BUILTIN_BSWAP64 0 // This turns on Roland Mainz's idle hack. Presently it is specific to the X11 // and term gui. If people try to enable it elsewhere, give a compile error diff --git a/bochs/configure b/bochs/configure index 480b13e32..6a05d47cc 100755 --- a/bochs/configure +++ b/bochs/configure @@ -1,5 +1,5 @@ #! /bin/sh -# From configure.in Id: configure.in 10315 2011-04-20 17:44:00Z sshwarts . +# From configure.in Id: configure.in 10316 2011-04-21 13:27:42Z sshwarts . # Guess values for system-dependent variables and create Makefiles. # Generated by GNU Autoconf 2.67. # @@ -20783,6 +20783,69 @@ fi done +{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for __builtin_bswap32" >&5 +$as_echo_n "checking for __builtin_bswap32... " >&6; } +cat confdefs.h - <<_ACEOF >conftest.$ac_ext +/* end confdefs.h. */ + +int +main () +{ + + __builtin_bswap32(0x12345678); + + ; + return 0; +} +_ACEOF +if ac_fn_c_try_link "$LINENO"; then : + + +$as_echo "#define BX_HAVE___BUILTIN_BSWAP32 1" >>confdefs.h + + { $as_echo "$as_me:${as_lineno-$LINENO}: result: yes" >&5 +$as_echo "yes" >&6; } + +else + + { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5 +$as_echo "no" >&6; } + +fi +rm -f core conftest.err conftest.$ac_objext \ + conftest$ac_exeext conftest.$ac_ext +{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for __builtin_bswap64" >&5 +$as_echo_n "checking for __builtin_bswap64... " >&6; } +cat confdefs.h - <<_ACEOF >conftest.$ac_ext +/* end confdefs.h. */ + +int +main () +{ + + __builtin_bswap64(0x12345678); + + ; + return 0; +} +_ACEOF +if ac_fn_c_try_link "$LINENO"; then : + + +$as_echo "#define BX_HAVE___BUILTIN_BSWAP64 1" >>confdefs.h + + { $as_echo "$as_me:${as_lineno-$LINENO}: result: yes" >&5 +$as_echo "yes" >&6; } + +else + + { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5 +$as_echo "no" >&6; } + +fi +rm -f core conftest.err conftest.$ac_objext \ + conftest$ac_exeext conftest.$ac_ext + # Check whether --enable-largefile was given. if test "${enable_largefile+set}" = set; then : enableval=$enable_largefile; diff --git a/bochs/configure.in b/bochs/configure.in index f66b2bb15..f9ed662b6 100644 --- a/bochs/configure.in +++ b/bochs/configure.in @@ -159,6 +159,25 @@ AC_CHECK_FUNCS(timelocal, AC_DEFINE(BX_HAVE_TIMELOCAL)) AC_CHECK_FUNCS(gmtime, AC_DEFINE(BX_HAVE_GMTIME)) AC_CHECK_FUNCS(mktime, AC_DEFINE(BX_HAVE_MKTIME)) +AC_MSG_CHECKING(for __builtin_bswap32) +AC_TRY_LINK([],[ + __builtin_bswap32(0x12345678); +],[ + AC_DEFINE(BX_HAVE___BUILTIN_BSWAP32, 1, [Define to 1 if you have the '__builtin_bswap32' function.]) + AC_MSG_RESULT(yes) +],[ + AC_MSG_RESULT(no) +]) +AC_MSG_CHECKING(for __builtin_bswap64) +AC_TRY_LINK([],[ + __builtin_bswap64(0x12345678); +],[ + AC_DEFINE(BX_HAVE___BUILTIN_BSWAP64, 1, [Define to 1 if you have the '__builtin_bswap64' function.]) + AC_MSG_RESULT(yes) +],[ + AC_MSG_RESULT(no) +]) + dnl As of autoconf 2.53, the standard largefile test fails for Linux/gcc. dnl It does not put the largefiles arguments into CFLAGS, even though Linux/gcc dnl does need them. So we do it ourselves. diff --git a/bochs/cpu/mult64.cc b/bochs/cpu/mult64.cc index c3c4cd8a5..3285b105f 100644 --- a/bochs/cpu/mult64.cc +++ b/bochs/cpu/mult64.cc @@ -312,7 +312,7 @@ void BX_CPP_AttrRegparmN(1) BX_CPU_C::IDIV_RAXEqR(bxInstruction_c *i) quotient_64l = quotient_128.lo; if ((!(quotient_128.lo & BX_CONST64(0x8000000000000000)) && quotient_128.hi != (Bit64s) 0) || - (quotient_128.lo & BX_CONST64(0x8000000000000000)) && quotient_128.hi != (Bit64s) BX_CONST64(0xffffffffffffffff)) + ((quotient_128.lo & BX_CONST64(0x8000000000000000)) && quotient_128.hi != (Bit64s) BX_CONST64(0xffffffffffffffff))) { exception(BX_DE_EXCEPTION, 0); } @@ -330,10 +330,10 @@ void BX_CPP_AttrRegparmN(1) BX_CPU_C::IMUL_GqEqIdR(bxInstruction_c *i) { Bit128s product_128; - Bit64s op2_64 = BX_READ_64BIT_REG(i->rm()); - Bit64s op3_64 = (Bit32s) i->Id(); + Bit64s op1_64 = BX_READ_64BIT_REG(i->rm()); + Bit64s op2_64 = (Bit32s) i->Id(); - long_imul(&product_128,op2_64,op3_64); + long_imul(&product_128,op1_64,op2_64); /* now write product back to destination */ BX_WRITE_64BIT_REG(i->nnn(), product_128.lo);