Skip to content
/ mlr Public

MLR - single-header-only C++ linear algebra math library

License

Notifications You must be signed in to change notification settings

jopadan/mlr

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

12 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

mlr

MLR - single-header-only C++ linear algebra math library

About

MLR implements vector/matrix types in a comfortable readable syntax style including missing AVX instructions like _mm256_dp_pd

Sources

get clone --recurse-submodules --recursive http://codeberg.org/forcemaster/mlr
cd mlr

Building

cmake . --install-prefix=/usr
make install

Optimization

Change CMakeLists.txt compile flags to fit your needs:

add_compile_options(-march=native -mfpmath=[your SIMD instruction set] -O3)

Usage

#include <MLR/mlr.hpp>

using namespace math::la;

/* unsigned short integer bitfield with 3 color components */
col::u16<col::rgb565>   c = { 24, 12, 12 };

/* unsigned char integer vector with 4 color components */
col::u8<col::rgba8888>  e = { 24, 12, 12, 8 };

/* floating point vector with 4 color components */
col::f32<col::rgbaf32>  f = { 24.0f, 12.0f, 12.0f, 8.0f };

/* floating point 4x4 square matrix identity */
mat::f32<4,4> m4 = {{1,0,0,0},{0,1,0,0},{0,0,1,0},{0,0,0,1}};

/* vector/cross product calculation with added simd instructions based on laplace */
(*(__v2sf*)&m4[1]) = _mm_cross2_ps(*(__v2sf*)&m4[0], GL_CCW);
m4[2]              = _mm_cross3_ps(m4[0],m4[1]);
m4[3]              = _mm_cross4_ps(m4[0],m4[1],m4[2]);

/* determinant calculation with added simd instructions based on laplace */
typ::f32 det2 = _mm_det2_ps(*(__v2sf*)&m4[0], *(__v2sf*)&m4[1]);
typ::f32 det3 = _mm_det3_ps(m4[0],m4[1],m4[2]);
typ::f32 det4 = _mm_det4_ps(m4[0],m4[1],m4[2],m4[3]);

}

Links

About

MLR - single-header-only C++ linear algebra math library

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published