Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

unrolling #3

Open
MyTDT-Mysoft opened this issue Aug 15, 2021 · 0 comments
Open

unrolling #3

MyTDT-Mysoft opened this issue Aug 15, 2021 · 0 comments

Comments

@MyTDT-Mysoft
Copy link

MyTDT-Mysoft commented Aug 15, 2021

seems unrolling is not being considered for your tests... in my tests here
unrolling 8x seems to be faster than cmov in a lot more situations...
i actually came here because i was checking the " x = (x&1) ? x*2+x+1 : x/2; "
where GCC was optimizing poorly for my machine like...

if...: 311ns 233332 116666 58333 175000 87500 43750 21875 65626 32813...
iif..: 261ns 233332 116666 58333 175000 87500 43750 21875 65626 32813...
asmi.: 104ns 233332 116666 58333 175000 87500 43750 21875 65626 32813...
asmi2: 153ns 233332 116666 58333 175000 87500 43750 21875 65626 32813...

where if is the regular if version... iif is using the ?: operator ... asmi is
0:
lea edx,[eax*2+eax+1]
shr eax, 1
jz 9f
jnc 1f
mov eax, edx
1:
// unrolled N times
jmp 0b

(with the differential that i do late exit when the "shr eax, 1" gives it 0)
and asmi2 is the same but using "cmovc" instead of jnc+mov
unrolled 8x it does faster than cmovc without unrolling it does like half of the speed of even the "slowest if" version
and unrolled 4x it like ties with cmovc...

which yeah it corroborates to your tests that "cmov" is stable... despite that block speculative execution or something...

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant