agenium-scale / nsimd

Agenium Scale vectorization library for CPUs and GPUs
MIT License
325 stars 28 forks source link

Provide more "inline" operators such as copysign, isfinite, etc... #92

Open eschnett opened 3 years ago

eschnett commented 3 years ago

Certain math functions such as copysign can be implemented efficiently with bitwise operations. It would be convenient to have these available:

I find the non-standard flipsign function https://docs.julialang.org/en/v1/base/math/#Base.flipsign convenient, e.g. to implement upwind finite differencing stencils. It can be defined as

flipsign(x, y) = copysign(1, y) * x

but can be implemented more efficiently as

flipsign(x, y) = x ^ (y & SIGNMASK)
gquintin commented 3 years ago

This issue is more general than #32, so I am closing #32.

gquintin commented 3 years ago

I put the text of issue #93 into your orginal request to have it all here.