Skip to content

unrolling #3

@MyTDT-Mysoft

Description

@MyTDT-Mysoft

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...

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions