naked popcnt function

safety0ff via Digitalmars-d-learn digitalmars-d-learn at puremagic.com
Sat Nov 22 13:12:51 PST 2014


On Saturday, 22 November 2014 at 18:30:06 UTC, Ad wrote:
> Hello, I would like to write a "popcnt" function. This works 
> fine
>
> ulong popcnt(ulong x)
> {
> asm { mov RAX, x ; popcnt RAX, RAX ; }
> }
>
> However, if I add the "naked" keyword ( which should improve 
> performance? ) it doesn't work anymore and I can't figure out 
> what change I am supposed to make ( aside from x[RBP] instead 
> of x )
> This function is going to be *heavily* used.
>
> Thanks for any help.

Last time I used naked asm simply used the calling convention to 
figure out the location of the parameter (e.g. RCX win64, RDI 
linux 64, iirc.)
N.B. on LDC & GDC there is an intrinsic for popcnt.


More information about the Digitalmars-d-learn mailing list