Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

Using Julia I get this:

    julia> clamp(x, lo, hi) = x < lo ? lo : x > hi ? hi : x
    clamp (generic function with 1 method)
    
    julia> @code_native clamp(2.0f0, -1.0f0, 1.0f0)
     .text
     vminss %xmm0, %xmm2, %xmm2
     vcmpnltss %xmm1, %xmm0, %xmm0
     vblendvps %xmm0, %xmm2, %xmm1, %xmm0
     retq


Looks like it might even be better? I'm not quite sure but the mnemonics are longer so they must be better ;)

Does Julia have a JIT? If so, maybe LLVM's x86 backend could do better if given the codegen flags corresponding to what Julia detects is available natively.


I think minss+maxss might be best on Zen, but it is worse on Intel, at least if I'm reading the latency tables correctly.




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: