dotnet / Silk.NET

The high-speed OpenGL, OpenCL, OpenAL, OpenXR, GLFW, SDL, Vulkan, Assimp, WebGPU, and DirectX bindings library your mother warned you about.
https://dotnet.github.io/Silk.NET
MIT License
4.12k stars 397 forks source link

SIMD Math tracking issue #666

Open WhiteBlackGoose opened 2 years ago

WhiteBlackGoose commented 2 years ago

COMMUNITY-DRIVEN WORK TRACKING ISSUE

Tracks implementation of the SIMD Math Proposal.

It is being implemented in the feature/math-simd.

Tasks

API implementation

665 (generator)

670

684

Arithmetics

Special

Trigonometry

Powers

Rounding

Bit operations

Tests

For all bitnesses x for all types

670

684

Other

Benchmarks

For all bitnesses x for all types

670

684

Other

TODOs

670

684

Other

Far TODOs

To discuss

678

690

Other

WhiteBlackGoose commented 2 years ago

Ideas

Sinh / Cosh

Those two have similar formulas:

(e^x + e^-x) / 2
(e^x - e^-x) / 2

So we can have Sinh/Cosh method

Speaking of implementation, we have

var ex = Simd.Exp(x);
var exm = Simd.Reciprocal(ex);
var multiplier = Simd.Create(0.5);
var sinh = Simd.Multiply(Simd.Subtract(ex, exm), multiplier);
var cosh = Simd.Multiply(Simd.Add(ex, exm), multiplier);
return (sinh, cosh);

Exp

Min/Max for longs

var compared = LessThan(left, right);
var antiCompared = GreaterThanOrEqual(left, right);
var withOnes = And(compared, Vector.Create(1));
var antiWithOnes = And(compared, Vector.Create(1));
var res = Or(Multiply(withOnes, left), Multiply(antiWithOnes, right));

State of number

  1. IsPositiveInfinity and IsNegativeInfinity can be verified on exact equality (for ints it returns zero) (though Tanner mentions some exception)
  2. IsFinite is & and equality: source (for ints it returns all bits set)
  3. IsInfinity is trivial too (for ints it returns zero)
  4. NaN can be checked with inequality to itself
  5. IsNegative/IsPositive should probably be Compare Less/Greater against 0? Or source
  6. IsNormal just follows source
HurricanKai commented 2 years ago

Should verify that for Store (and other void returning methods) the nested method trick actually works.

WhiteBlackGoose commented 2 years ago

128 bit sharplab

256 bit sharplab

64 bit sharplab (well I don't have a mobile sharplab)

@HurricanKai

And also it's probably #665 -related, not this issue

HurricanKai commented 2 years ago

Future: Look at checking for IsHardwareAccelerated before calling down into other methods, don't want to ie call Not(LessThen(...)) if it's not hardware accelerated, because it means two loops with non-hardware accelerated Loads/Stores

HurricanKai commented 2 years ago

Future: Improve IsNegative check by checking for bit instead of doing a full blown compare

WhiteBlackGoose commented 2 years ago

Important: Notes from working group meeting