Skip to contentSkip to conversation

Fix register corruption in pvclock_scale_delta

PATCH Applied Duncan Sands 2 participants 2 messages Aug 30, 2011

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

Hi Zachary, this patch can cause a compile failure if the compiler chooses to use a memory location for mul_frac rather than a register (as allowed by the "m" in the constraints):

pvclock.s:229: Error: no instruction mnemonic suffix given and no register
operands; can't size instruction

In this example the assembler is:

        #APP
        mul -48(%rbp) ; shrd $32, %rdx, %rax
        #NO_APP

A simple solution is to use mulq, as in the following patch:

arch/x86/include/asm/pvclock.h +1 -1
@@ -44,7 +44,7 @@ static inline u64 pvclock_scale_delta(u64 delta, u32 mul_frac, int shift)
                : "a" ((u32)delta), "1" ((u32)(delta >> 32)), "2" (mul_frac) );
 #elif defined(__x86_64__)
        __asm__ (
-               "mul %[mul_frac] ; shrd $32, %[hi], %[lo]"
+               "mulq %[mul_frac] ; shrd $32, %[hi], %[lo]"
                : [lo]"=a"(product),
                  [hi]"=d"(tmp)
                : "0"(delta),
Applied
#1 lore raw
Quoted 28 lines · Duncan Sands

Hi Zachary, this patch can cause a compile failure if the compiler chooses to use a memory location for mul_frac rather than a register (as allowed by the "m" in the constraints):

pvclock.s:229: Error: no instruction mnemonic suffix given and no
register operands; can't size instruction

In this example the assembler is:

        #APP
        mul -48(%rbp) ; shrd $32, %rdx, %rax
        #NO_APP

A simple solution is to use mulq, as in the following patch:

arch/x86/include/asm/pvclock.h +1 -1
@@ -44,7 +44,7 @@ static inline u64 pvclock_scale_delta(u64 delta, u32 
 mul_frac, int shift)
                : "a" ((u32)delta), "1" ((u32)(delta >> 32)), "2" 
 (mul_frac) );
 #elif defined(__x86_64__)
        __asm__ (
-               "mul %[mul_frac] ; shrd $32, %[hi], %[lo]"
+               "mulq %[mul_frac] ; shrd $32, %[hi], %[lo]"
                : [lo]"=a"(product),
Quoted 2 lines
                  [hi]"=d"(tmp)
                : "0"(delta),

Thanks, applied.

Signature · 1 line
error compiling committee.c: too many arguments to function