[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Xen-devel] [PATCH] x86 emulation: fix bswap



REX.R needs to be decoded and since bswap on a 16-bit operand is undefined,
it is best to have hardware execute this so the emulation result matches
hardware behavior. Since it is simple to do, faster, and smaller, also let 
hardware
do 32- and 64-bit ones.

Signed-off-by: Jan Beulich <jbeulich@xxxxxxxxxx>

Index: 2007-02-07/xen/arch/x86/x86_emulate.c
===================================================================
--- 2007-02-07.orig/xen/arch/x86/x86_emulate.c  2007-02-08 08:46:39.000000000 
+0100
+++ 2007-02-07/xen/arch/x86/x86_emulate.c       2007-02-08 09:32:00.000000000 
+0100
@@ -2326,32 +2326,22 @@ x86_emulate(
 
     case 0xc8 ... 0xcf: /* bswap */
         dst.type  = OP_REG;
-        dst.reg   = decode_register(b & 7, &_regs, 0);
+        dst.reg   = decode_register(
+            (b & 7) | ((rex_prefix & 1) << 3), &_regs, 0);
         dst.val = *dst.reg;
         switch ( dst.bytes = op_bytes )
         {
         case 2:
-            dst.val = (((dst.val & 0x00FFUL) << 8) |
-                       ((dst.val & 0xFF00UL) >> 8));
+            __asm__("data16 bswap %k0" : "+r" (dst.val));
             break;
         case 4:
-            dst.val = (((dst.val & 0x000000FFUL) << 24) |
-                       ((dst.val & 0x0000FF00UL) <<  8) |
-                       ((dst.val & 0x00FF0000UL) >>  8) |
-                       ((dst.val & 0xFF000000UL) >> 24));
-            break;
 #ifdef __x86_64__
-        case 8:
-            dst.val = (((dst.val & 0x00000000000000FFUL) << 56) |
-                       ((dst.val & 0x000000000000FF00UL) << 40) |
-                       ((dst.val & 0x0000000000FF0000UL) << 24) |
-                       ((dst.val & 0x00000000FF000000UL) <<  8) |
-                       ((dst.val & 0x000000FF00000000UL) >>  8) |
-                       ((dst.val & 0x0000FF0000000000UL) >> 24) |
-                       ((dst.val & 0x00FF000000000000UL) >> 40) |
-                       ((dst.val & 0xFF00000000000000UL) >> 56));
+            __asm__("bswap %k0" : "+r" (dst.val));
             break;
+        case 8:
 #endif
+            __asm__("bswap %0" : "+r" (dst.val));
+            break;
         }
         break;
     }


_______________________________________________
Xen-devel mailing list
Xen-devel@xxxxxxxxxxxxxxxxxxx
http://lists.xensource.com/xen-devel


 


Rackspace

Lists.xenproject.org is hosted with RackSpace, monitoring our
servers 24x7x365 and backed by RackSpace's Fanatical Support®.