A C/C++ SIMD math library for video game programming and connected fields, targeting x86, x86-64 and ARM architectures. bad
aims at providing a math library, but might be extended to offer systems, modules and algorithms commonly used in the video game industry (collision, physics, etc.).
Because I am working on this library primarily to learn, it is a work in progress in its early days. It is missing a lot of features and may contain dirty and incorrect code.
- Provide a cross-platform optimized API
- Compile with Clang, GCC and MSVC
- Compile and run under Windows and Linux
- Both C and C++ compatible
- Take advantage of the available SIMD instruction sets
- Offer the best performance for mathematics (and other modules and algorithms commonly found in the video game industry) for low energy consumption
- Provide a library with no dependencies that relies as little as possible on the standard C/C++ library
- Tested on a laptop with an AMD x86-64 CPU (Ryzen 7 5800H)
- Compiled with Clang for both C and C++
- Compiled under Windows 10
- C++ compatible
- Takes advantage of MMX, SSE, SSE2, SSE3, SSSE3, SSE4.1, SSE4.2, AVX, AVX2 and FMA intrinsics
- Contains only common single-precision floating-point vector operations
- Has no dependency, but relies on
stdint.h
src/bad/
: the library. If you want to usebad
in your project, this is probably the only directory you needcommon/
: common operations likely to be used throughout the rest of the librarydetect/
: context detection around the librarymath/
: math functionstypes/
: where scalar, simd and math types are defined. No functions are contained here, only declarationsbad.h
: included accross all headers, currently used solely for wrapping sources in an optional namespacedebug.h
: debug-mode runtime checks through macrosqualifiers.h
: a variety of qualifiers used to affect how the compiler generates code
test/
: unit tests on important and/or non-trivial functionsbuild.bat
: custom compilation script for Windows 10 with Clang. Can be called withbuild
to build the library,build test
,build asm
,build run
,build clean
RESOURCES.md
: a collection of knowledge that helped me learn
General:
- Work on C/C++ interoperability
- Work on Linux support
- Support compilation with GCC and MSVC
- Support compilation under ARM
- Add support for more SIMD instruction sets? (RISC-V "V", PowerPC's AltiVec, MIPS' MSA, ARM's Helium?)
- Take endianness in consideration
Common:
- Implement
f32xn
andmaskn
, a general vector type built on top of the most suited SIMD ISA available for the needs of the user - Explore non-temporal loads and stores
- Explore possible implementation of types whose size is not a multiple of the available vector width (vec2 and vec3 for instance)
- Remove the dependency on
stdint.h
if possible intypes.h
- Learn about interoperability and penalties between ISA (SSE <--> AVX for instance), and manage them
Tests:
- Extend tests to all functions, trivial or not
- Improve testing framework?
Math:
- Migrate calculus/mathematical functions in
common/f32x4.h
tomath
- Implement common calculus functions such as power, exponential, log, tan...
- Implement 4-dimensional vector
- Implement 3-dimensional vector
- Implement quaternion
- Implement 4x4, 3x4 and 3x3 matrices
- Implement math types conversion functions
- Implement common splines
Collisions & intersections:
- Implement shapes
- Implement collision algorithms
Physics:
- Implement kinematic
bad
is licensed under the MIT license