All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] x86 emulation: fix bswap
@ 2007-02-15 10:22 Jan Beulich
  2007-02-15 10:33 ` Keir Fraser
  0 siblings, 1 reply; 7+ messages in thread
From: Jan Beulich @ 2007-02-15 10:22 UTC (permalink / raw)
  To: xen-devel

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@novell.com>

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;
     }

^ permalink raw reply	[flat|nested] 7+ messages in thread

end of thread, other threads:[~2007-02-16  7:32 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2007-02-15 10:22 [PATCH] x86 emulation: fix bswap Jan Beulich
2007-02-15 10:33 ` Keir Fraser
2007-02-15 11:37   ` Jan Beulich
2007-02-15 11:46   ` Petersson, Mats
2007-02-15 11:54     ` Keir Fraser
2007-02-15 12:12       ` Petersson, Mats
2007-02-16  7:32     ` Error with vfb Xen 3.0.4 Kaushik Barde

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.