ML is a cross-platform header-only SSE/AVX/NEON-accelerated math library, designed for computer graphics. It serves two goals:
- accelerate performance using SSE/AVX/NEON intrinsics
- be HLSL compatible and deliver functionality to both CPU and shader code without code duplication
Features:
- compile-time optimization level specialization: SSE3 (and below), +SSE4, +AVX1, +AVX2 (or NEON on ARM via sse2neon)
int2
,int3
andint4
typesuint2
,uint3
anduint4
typesfloat2
,float3
,float4
andfloat4x4
typesdouble2
,double3
,double4
anddouble4x4
typesbool2
,bool3
andbool4
types- overloaded operators
- vector swizzling
- common functions:
all
,any
,sign
,abs
,floor
,round
,ceil
,fmod
,frac
,min
,max
,clamp
,saturate
,lerp
,step
,smoothstep
andlinearstep
- transcendental functions:
sin
,cos
,tan
,asin
,acos
,atan
,atan2
,sqrt
,rsqrt
,rcp
,pow
,log
,log2
,exp
andexp2
- data conversion and packing functionality - FP32, FP16, SNORM and UNORM (with any number of bits per component)
- vectors and matrices
- linear algebra miscellaneous functionality
- projective math miscellaneous functionality
- frustum & AABB primitives
- random numbers generation
- sorting
Important:
sizeof(int3/uint3/float3) == sizeof(float4)
on CPUsizeof(double3) == sizeof(double4)
on CPUusing namespace std
can lead to name collisions- inclusion of
cmath
and/orcstdlib
(even implicitly) afterml.h
leads to name collisions
Also includes ml.hlsli
file which is a standalone HLSL math library usable in C++ code.
ML is licensed under the MIT License.