dotnet / dotnet/Silk.NET

SIMD Math tracking issue

Open
#666 6 comments 0 reactions 2 assignees Claimed by @WhiteBlackGoose View on GitHub
area-Maths feature help wanted tracking issue / epic
Dominant language
C#
Stars
5.2k
Forks
477
Avg merge
3d 16h
Merged PRs (30d)
2

Description

**COMMUNITY-DRIVEN WORK TRACKING ISSUE**

Tracks implementation of the [**SIMD Math Proposal**](https://github.com/dotnet/Silk.NET/blob/main/documentation/proposals/Proposal%20-%20Vectorization%20-%20SIMD.md).

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

# Tasks

## API implementation

#665 ([generator](https://gist.github.com/WhiteBlackGoose/4bf2f633dcc3bd7a10ae44de61598be9))
- [x] `Create`
- [x] `Load`
- [x] `Add`
- [x] `Subtract`
- [x] `Multiply`
- [x] `Divide`
- [x] `Abs`
- [x] Constants
- [x] `And`
- [x] `Or`
- [x] `Xor`
- [x] `Not`
- [x] `AllBitsSet`
- [x] `IsHardwareAccelerated`

#670
- [x] `Equal`
- [x] `NotEqual`
- [x] `GreaterThan`
- [x] `GreaterOrEqual`
- [x] `LessThan`
- [x] `LessThanOrEqual`
- [x] `Min`
- [x] `Max`

#684
- [x] `IsFinite`
- [x] `IsInfinity`
- [x] `IsNaN`
- [x] `IsNegative`
- [x] `IsNegativeInfinity`
- [x] `IsNormal`
- [x] `IsPositiveInfinity`
- [x] `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
- [x] 4 arithmetic operators
- [x] `Less`/`Greater` `Than` (`OrEqual`)
- [x] `Min`, `Max`
- [x] (`Not`)`Equal`
- [x] Bitwise operations

#684
- [x] 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
- [x] 4 arithmetic operators
- [x] `Less`/`Greater` `Than` (`OrEqual`)
- [x] `Min`, `Max`
- [x] (`Not`)`Equal`

#684
- [x] State of number
- [x] Bitwise operations
- [x] `Abs`

#### Other
- [ ] `Create`, `Load`, `Store`
- [ ] Regular trigonometry
- [ ] Hyperbolic trigonometry
- [ ] Inverse trigonometry
- [ ] Inverse hyperbolic trigonometry
- [ ] Power
- [ ] Rounding
- [ ] Bit operations

## TODOs

#670
- [x] Make fallback to 128-bit if 256-bit is not supported
- [x] Use naive operations for 8-byte values on simd64

#684
- [x] 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](https://stackoverflow.com/questions/16822757/sse-integer-division)
- [ ] `Multiply` for bytes to be done in a more efficient way [link](https://stackoverflow.com/questions/8193601/sse-multiplication-16-x-uint8-t)
- [ ] Use intrinsic ShiftRight/ShiftLeft once [proposal](https://github.com/dotnet/runtime/issues/20510) 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
- [x] `AllBitsSet` API for Scalar

#690

#### Other
- [ ] `MaxValueOver2` API for Simd and Scalar
- [ ] `IsHardwareAccelerated` should be `&& IsSupported`? Otherwise `Simd128.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

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.