[llvmlinux] [PATCH] x86/hweight: LLVMLinux: Fix __arch_hweight{32, 64}() for compilation with clang

PaX Team pageexec at gmail.com
Sun Sep 13 21:14:22 UTC 2015


On 13 Sep 2015 at 13:25, Sanjoy Das wrote:

> I'm an outsider to the llvmlinux project, so I cannot comment on the 
> patch as is; as I do not know how what is a good candidate for merging 
> into what tree and what isn't.  Sedat CC'ed me only because we had a 
> discussion about this issue on IRC.
> 
> However, I will comment that clang not supporting ALTERNATIVE is only 
> one issue here.  I think there is a bug that needs to be fixed in 
> __arch_hweight64 --
> 
> 	asm (ALTERNATIVE("call __sw_hweight64", POPCNT64, X86_FEATURE_POPCNT)
> 		     : "="REG_OUT (res)
> 		     : REG_IN (w));
> 
> 
> does not specify that the "call __sw_hweight64" instruction may clobber 
> caller saved registers (like %rcx and %rdx).

actually, the __sw_hweight* functions may *not* clobber anything. the
trick is in how lib/hweight.o is compiled: CFLAGS contains a set of
-fcall-saved-REG switches (cf. ARCH_HWEIGHT_CFLAGS) that effectively
override the function call ABI for the functions defined in this file
so there's no need for the callers to specify any extra clobbers. this
way the fast path execution (inlined popcnt insn) doesn't unnecessarily
perturb the register allocator in the callers.



More information about the LLVMLinux mailing list