Skip to content

Latest commit

 

History

History
84 lines (64 loc) · 2.51 KB

README.md

File metadata and controls

84 lines (64 loc) · 2.51 KB

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