Skip to content

Commit

Permalink
Merge pull request #18 from MrUnbelievable92/2.9.0
Browse files Browse the repository at this point in the history
Version 2.9.0
  • Loading branch information
MrUnbelievable92 authored Oct 26, 2024
2 parents f59e9c2 + a991a2c commit 7f4752f
Show file tree
Hide file tree
Showing 1,139 changed files with 324,297 additions and 139,336 deletions.
2 changes: 1 addition & 1 deletion LICENSE
Original file line number Diff line number Diff line change
Expand Up @@ -186,7 +186,7 @@
same "printed page" as the copyright notice for easier
identification within third-party archives.

Copyright 2020 - 2021 Maximilian Kalimon
Copyright 2020 - 2024 Maximilian Kalimon

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
Expand Down
21 changes: 11 additions & 10 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
# MaxMath
A C# SIMD math library for use with Unity only, supplementary to Unity.Mathematics using Unity.Burst.

It adds (s)byte, (u)short and (u)long SIMD vectors and matrices to the ones already provided by Unity.Mathematics.
Almost all functions present in Unity.Mathematics have been transcribed to work with the new vector and matrix types in addition to many useful functions having been added.

Note:
- [C Sharp Dev Tools](https://github.com/MrUnbelievable92/C-Sharp-Dev-Tools) (conditionally compiled runtime checks) is required. Unit tests for this library are included in this repository.
- This library utilizes Avx2 as often as possible. Optimized fallback procedures for Sse4 and Sse2 are included, aswell as a managed C# implementation. There are currently no plans for supporting ARM or other instruction sets in the future, although Burst/LLVM is generally good at vectorizing some of the code for them.
- The "float8" type does not support deterministic compilation across all platforms with Unity.Burst. Split up the vector into two "float4" vectors via the properties "myfloat8.v4_0" and "myfloat8.v4_4" to take advantage of deterministic compilation instead.
#MaxMath
MaxMath is the most powerful and extensive SIMD math library available to Unity developers. Built on top of Unity.Mathematics and utilizing Unity.Burst, it introduces the following key features:

- **Support For All Primitive Data Types:** MaxMath adds support for `(s)byte`, `(u)short`, and `(u)long` vectors and matrices. These data types come with specialized overloads for all functions in Unity.Mathematics. Additionally, specialized `Random8/16/32/64/128` types are available for efficient pseudo-random number generation.
- **Wider Vectors With Full Hardware Support:** Vector types are expanded to 256 bits, enabling types like `byte32`, `short16`, `int8`, and `float8`. This allows you to leverage the full potential of SIMD computation.
- **Many Additional Functions:** MaxMath includes a massive library of mathematical functions not found in Unity.Mathematics, with about five times as many highly optimized functions at your disposal. Each function is fully documented with XML annotations. A full list is provided further below.
- **Exotic Data Types:** MaxMath introduces data types such as `(U)Int128` (scalar only), 128-bit `quadruple` precision floats (scalar only), and 8-bit `quarter` precision floats (in both scalar and vector forms). Additionally, `Divider<T>` offers highly optimized integer division operations, extending and outperforming specialized libraries like libdivide.
- **Written Entirely With Hardware Intrinsics:** MaxMath guarantees optimal performance by utilizing specialized CPU instructions for both ARM and x86 ISAs, while abstracting these complexities away from the user entirely.
- **Extends The Burst Compiler:** MaxMath integrates deeply with Unity.Burst and LLVM, leveraging `Unity.Burst.CompilerServices.Constant.IsConstantExpression<T>()` to include code typically only found in optimizing compilers. This functionality allows MaxMath to choose more optimized code paths at compile time, and users can influence this behavior via the optional `Promise` enum parameter available in many functions.
- **Easy To Use:** MaxMath is just as easy to use as Unity.Mathematics. It supports features like `implicit` and `explicit` type conversions, making it seamless for you to use if you expect typical C# behavior of primitive types.
- **Extensive Test Coverage:** MaxMath is backed by 250,000 lines of unit tests for its 400,000 lines of code, as well as `DEBUG` only runtime checks where appropriate, together ensuring it is _production ready_.


# How To Use This Library
Expand Down
33 changes: 12 additions & 21 deletions Runtime/AssemblyInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,38 +3,29 @@
using System.Runtime.CompilerServices;
using System.Diagnostics.CodeAnalysis;

// General Information about an assembly is controlled through the following
// set of attributes. Change these attribute values to modify the information
// associated with an assembly.
[assembly: AssemblyTitle("MaxMath")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("MaxMath")]
[assembly: AssemblyCopyright("Copyright © 2020 - 2022 Maximilian Kalimon")]
[assembly: AssemblyCopyright("Copyright © 2020 - 2024 Maximilian Kalimon")]
[assembly: AssemblyTrademark("")]
[assembly: AssemblyCulture("")]
[assembly: InternalsVisibleTo("MaxMath.Tests")]
[assembly: InternalsVisibleTo("SIMD Algorithms")]

// Setting ComVisible to false makes the types in this assembly not visible
// to COM components. If you need to access a type in this assembly from
// COM, set the ComVisible attribute to true on that type.
[assembly: ComVisible(false)]

// The following GUID is for the ID of the typelib if this project is exposed to COM
[assembly: Guid("d3cc711d-084c-435c-8c84-7d624992dc10")]

// Version information for an assembly consists of the following four values:
//
// Major Version
// Minor Version
// Build Number
// Revision
//
[assembly: AssemblyVersion("2.3.5")]
[assembly: AssemblyFileVersion("2.3.5")]
[assembly: AssemblyInformationalVersion("2.3.5 Release")]
[assembly: AssemblyVersion("2.9.0")]
[assembly: AssemblyFileVersion("2.9.0")]
[assembly: AssemblyInformationalVersion("2.9.0 Release")]

// Style
[assembly: SuppressMessage("Style", "IDE1006: Naming Styles", Justification = "Unity.Mathematics API consistency")]
[assembly: SuppressMessage("Style", "IDE0034: Simplify 'default' expression", Justification = "Coding Guidelines")]
[assembly: SuppressMessage("Style", "IDE0066: Use 'switch' expression", Justification = "Coding Guidelines")]
[assembly: SuppressMessage("Style", "IDE0090: Simplify 'new' expression", Justification = "Compatibility with C#8 or less")]

[assembly: SuppressMessage("Style", "IDE1006:Naming Styles", Justification = "Unity.Mathematics API consistency")]
// Compilation
[assembly: InternalsVisibleTo("MaxMath.Tests")]
[assembly: CompilationRelaxationsAttribute(CompilationRelaxations.NoStringInterning)]

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

39 changes: 39 additions & 0 deletions Runtime/Compiler Extensions/Compilation Options.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
//#define TESTING

using Unity.Burst;

namespace MaxMath
{
internal static class COMPILATION_OPTIONS
{
internal static OptimizeFor OPTIMIZE_FOR
{
get;
#if TESTING
set;
#endif
} = OptimizeFor.Performance;

internal static FloatMode FLOAT_MODE
{
get;
#if TESTING
set;
#endif
} = FloatMode.Default;

internal static FloatPrecision FLOAT_PRECISION
{
get;
#if TESTING
set;
#endif
} = FloatPrecision.Standard;


internal static bool FLOAT_SIGNED_ZERO => FLOAT_MODE != FloatMode.Fast;
internal static bool FLOAT_NO_NAN => FLOAT_MODE == FloatMode.Fast;
internal static bool FLOAT_NO_INF => FLOAT_MODE == FloatMode.Fast;
internal static bool FLOAT_DENORMALS_ARE_ZERO => FLOAT_PRECISION == FloatPrecision.Low;
}
}

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

27 changes: 27 additions & 0 deletions Runtime/Compiler Extensions/constexpr/Condition Validation.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
using System.Runtime.CompilerServices;
using Unity.Burst.CompilerServices;

namespace MaxMath.Intrinsics
{
public static partial class constexpr
{
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static bool IS_CONST<T>(T value)
where T : unmanaged
{
return Constant.IsConstantExpression(value);
}

[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static bool IS_TRUE(bool condition)
{
return IS_CONST(condition) && condition;
}

[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static bool IS_FALSE(bool condition)
{
return IS_CONST(condition) && !condition;
}
}
}

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

20 changes: 20 additions & 0 deletions Runtime/Compiler Extensions/constexpr/Validated Assume.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
//#define TESTING

using System.Runtime.CompilerServices;
using Unity.Burst.CompilerServices;
using DevTools;

namespace MaxMath.Intrinsics
{
public static partial class constexpr
{
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static void ASSUME(bool value)
{
#if TESTING
Assert.IsTrue(value);
#endif
Hint.Assume(value);
}
}
}

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit 7f4752f

Please sign in to comment.