Re: [patch V3] lib: GCD: add binary GCD algorithm

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

 



Dave Miller spake truth from on high:
> Read it again, it is patched if the cpu supports the necessary instructions
> in which case it's a very short sequence.
> 
> The actual code used when the cpu support said instruction is simply:
> 
>	neg	%o0, %g1
>	xnor	%o0, %g1, %o1
>	popc	%o1, %o0
>	retl
>	 sub	%o0, 1, %o0

D'oh!  Missed that run-time patching.  (Done by popc_patch() in
arch/sparc/kernel/setup_64.c, which is executed based on boot-time
capabilities detection.)

I'm surprised you don't use the shorter:
	sub	%o0, 1, %g1
	andn	%g1, %o0, %g1
	retl
	 popc	%g1, %o0

This kind of blows a hole in having a compile-time flag.  Which code
path to use?  It's absolutely not worth choosing gcd() implementations
at boot time.

The race is between that, plus the call and right shift, and the loop

1:	andcc	<src>, 1, %g0
	bne,a	1b
	 srl	<src>, 1, <src>
... where the branch is taken 50% of the time, so on average it
will be taken once before being not taken.
--
To unsubscribe from this list: send the line "unsubscribe sparclinux" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at  http://vger.kernel.org/majordomo-info.html



[Index of Archives]     [Kernel Development]     [DCCP]     [Linux ARM Development]     [Linux]     [Photo]     [Yosemite Help]     [Linux ARM Kernel]     [Linux SCSI]     [Linux x86_64]     [Linux Hams]

  Powered by Linux