[PATCH] Fix some dodgy inline assembler
Andi Kleen
andi at firstfloor.org
Sun Mar 2 16:28:49 PST 2008
Potential miscompilation, there is no guarantee the clobbers
won't conflict with the input registers. Also the ifdef is not really needed.
Write it properly.
Just spotted while looking at the linux lowlevel code.
-Andi
diff -u openjdk/hotspot/src/os/linux/launcher/java_md.c-o openjdk/hotspot/src/os/linux/launcher/java_md.c
--- openjdk/hotspot/src/os/linux/launcher/java_md.c-o 2007-05-24 09:30:53.000000000 +0200
+++ openjdk/hotspot/src/os/linux/launcher/java_md.c 2007-05-28 15:42:23.000000000 +0200
@@ -1233,57 +1233,16 @@
uint32_t* ebxp,
uint32_t* ecxp,
uint32_t* edxp) {
-#ifdef _LP64
- __asm__ volatile (/* Instructions */
- " movl %4, %%eax \n"
- " cpuid \n"
- " movl %%eax, (%0)\n"
- " movl %%ebx, (%1)\n"
- " movl %%ecx, (%2)\n"
- " movl %%edx, (%3)\n"
- : /* Outputs */
- : /* Inputs */
- "r" (eaxp),
- "r" (ebxp),
- "r" (ecxp),
- "r" (edxp),
- "r" (arg)
- : /* Clobbers */
- "%rax", "%rbx", "%rcx", "%rdx", "memory"
- );
-#else
- uint32_t value_of_eax = 0;
- uint32_t value_of_ebx = 0;
- uint32_t value_of_ecx = 0;
- uint32_t value_of_edx = 0;
- __asm__ volatile (/* Instructions */
- /* ebx is callee-save, so push it */
- /* even though it's in the clobbers section */
- " pushl %%ebx \n"
- " movl %4, %%eax \n"
- " cpuid \n"
- " movl %%eax, %0 \n"
- " movl %%ebx, %1 \n"
- " movl %%ecx, %2 \n"
- " movl %%edx, %3 \n"
- /* restore ebx */
- " popl %%ebx \n"
-
- : /* Outputs */
- "=m" (value_of_eax),
- "=m" (value_of_ebx),
- "=m" (value_of_ecx),
- "=m" (value_of_edx)
- : /* Inputs */
- "m" (arg)
- : /* Clobbers */
- "%eax", "%ebx", "%ecx", "%edx"
- );
- *eaxp = value_of_eax;
- *ebxp = value_of_ebx;
- *ecxp = value_of_ecx;
- *edxp = value_of_edx;
-#endif
+ asm(/* Instructions */
+ "cpuid"
+ : /* Outputs */
+ "=a" (*eaxp),
+ "=b" (*ebxp),
+ "=c" (*ecxp),
+ "=d" (*edxp)
+ : /* Inputs */
+ "0" (arg)
+ );
}
#endif /* __linux__ && i586 */
More information about the hotspot-dev
mailing list