odin-lang / Odin

Odin Programming Language
https://odin-lang.org
BSD 3-Clause "New" or "Revised" License
6.41k stars 562 forks source link

abs() (and others) @builtin supporting [N]T for N=1..4 via SIMD acceleration #2418

Open JesseRMeyer opened 1 year ago

JesseRMeyer commented 1 year ago

The proposed builtin would leverage SIMD to compute the abs(). This would allow translating more shaders to Odin to 'just work', and operate more optimally.

If this feature request is accepted and implemented, I envision a wider set of built-ins that act similarly, designed specifically to aid shader-like (for a lack of a better description) Odin.

    [cross](https://docs.gl/sl4/cross)
    [distance](https://docs.gl/sl4/distance)
    [dot](https://docs.gl/sl4/dot)
    [equal](https://docs.gl/sl4/equal)
    [faceforward](https://docs.gl/sl4/faceforward)
    [length](https://docs.gl/sl4/length)
    [normalize](https://docs.gl/sl4/normalize)
    [notEqual](https://docs.gl/sl4/notEqual)
    [reflect](https://docs.gl/sl4/reflect)
    [refract](https://docs.gl/sl4/refract)

(credit: @Kelimion for the idea)

Kelimion commented 1 year ago

AMD/Intel can compute abs in several ways. https://stackoverflow.com/questions/32408665/fastest-way-to-compute-absolute-value-using-sse

ARM has a SIMD operation for it for floats, apparently. https://developer.arm.com/documentation/ddi0596/2021-12/SIMD-FP-Instructions/ABS--Absolute-value--vector--