Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

SIMD Math tracking issue #666

Open
WhiteBlackGoose opened this issue Nov 3, 2021 · 6 comments
Open

SIMD Math tracking issue #666

WhiteBlackGoose opened this issue Nov 3, 2021 · 6 comments
Assignees
Labels

Comments

@WhiteBlackGoose
Copy link
Contributor

WhiteBlackGoose commented Nov 3, 2021

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)

  • Create
  • Load
  • Add
  • Subtract
  • Multiply
  • Divide
  • Abs
  • Constants
  • And
  • Or
  • Xor
  • Not
  • AllBitsSet
  • IsHardwareAccelerated

#670

  • Equal
  • NotEqual
  • GreaterThan
  • GreaterOrEqual
  • LessThan
  • LessThanOrEqual
  • Min
  • Max

#684

  • IsFinite
  • IsInfinity
  • IsNaN
  • IsNegative
  • IsNegativeInfinity
  • IsNormal
  • IsPositiveInfinity
  • Sign

Arithmetics

  • Negate

Special

  • As
  • IEEERemainder

Trigonometry

  • Acos
  • Acosh
  • Asin
  • Asinh
  • Atan2
  • Atan
  • Atanh
  • Cos
  • Cosh
  • Sin
  • Sinh
  • Tan
  • Tanh

Powers

  • Exp
  • Cbrt
  • Sqrt
  • Pow
  • Log10
  • Log
  • Log of two args
  • Reciprocal

Rounding

  • Floor
  • Ceiling
  • Round
  • Round of two args
  • Truncate

Bit operations

  • ShiftLeft
  • ShiftRight
  • RotateLeft
  • RotateRight

Tests

For all bitnesses x for all types

#670

  • 4 arithmetic operators
  • Less/Greater Than (OrEqual)
  • Min, Max
  • (Not)Equal
  • Bitwise operations

#684

  • State of number

Other

  • Create, Load, Store
  • Regular trigonometry
  • Hyperbolic trigonometry
  • Inverse trigonometry
  • Inverse hyperbolic trigonometry
  • Power
  • Rounding
  • Bit operations

Benchmarks

For all bitnesses x for all types

#670

  • 4 arithmetic operators
  • Less/Greater Than (OrEqual)
  • Min, Max
  • (Not)Equal

#684

  • State of number
  • Bitwise operations
  • Abs

Other

  • Create, Load, Store
  • Regular trigonometry
  • Hyperbolic trigonometry
  • Inverse trigonometry
  • Inverse hyperbolic trigonometry
  • Power
  • Rounding
  • Bit operations

TODOs

#670

  • Make fallback to 128-bit if 256-bit is not supported
  • Use naive operations for 8-byte values on simd64

#684

  • The random feeder should be either static or without seed or anything, otherwise it fills both vectors with the same data

Other

  • Divide for integers to be done in a more efficient way link
  • Multiply for bytes to be done in a more efficient way link
  • Use intrinsic ShiftRight/ShiftLeft once proposal is impl
  • Remove unmanaged constraints where possible
  • Relax constraints to struct where possible
  • Hardware accelerated comparison operations for long and ulong

Far TODOs

  • Propose & add support for Simd512 (that requires runtime support)

To discuss

#678

  • AllBitsSet API for Scalar

#690

Other

  • MaxValueOver2 API for Simd and Scalar
  • IsHardwareAccelerated should be && IsSupported? Otherwise Simd128<MyAwesomeType>.IsHardwareAccelerated returns true on net5 on avx machine
  • Math.Abs throws on Math.Abs(int.MinValue). We can keep it, or we can have a faster version without this check
  • CopySign API
@Perksey Perksey added area-Maths feature New feature. help wanted Extra attention is needed tracking issue / epic labels Nov 3, 2021
@Perksey Perksey added this to the Future milestone Nov 3, 2021
@WhiteBlackGoose
Copy link
Contributor Author

WhiteBlackGoose commented Nov 4, 2021

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
Copy link
Member

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

@WhiteBlackGoose
Copy link
Contributor Author

WhiteBlackGoose commented Nov 4, 2021

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 HurricanKai modified the milestones: Future, 2.X Nov 5, 2021
@HurricanKai
Copy link
Member

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
Copy link
Member

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

@WhiteBlackGoose
Copy link
Contributor Author

Important: Notes from working group meeting

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
Status: In Progress
Development

No branches or pull requests

3 participants