commit 6c6418d19a73fab6ad5ea7215b73f22b0d7f946c Author: Recep Aslantas Date: Sun Sep 11 12:29:22 2016 +0300 Initial Commit diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..e7a597c --- /dev/null +++ b/.gitignore @@ -0,0 +1,49 @@ +*.xcodeproj +*.xcworkspace +*.sln +*.vcxproj +*.vcxproj.* +*.suo +*.sdf +*.opensdf +ipch/ +Debug/ +Release/ +.DS_Store +.vs +*.nupkg +*.opendb +packages.config +/aclocal.m4 +/ar-lib +/autom4te.cache/ +/compile +/config.guess +/config.log +/config.status +/config.sub +/configure +/depcomp +/install-sh +/ltmain.sh +/missing +/libtool +/.libs/ +.deps/ +*.[oa] +*.l[oa] +Makefile +Makefile.in +m4/*.m4 +.buildstamp +.dirstamp +packages/ +.anjuta/* +*.anjuta* +config.h.* +config.h +stamp* +COPYING +.idea/* +*.VC.db +cscope.* diff --git a/LICENSE b/LICENSE new file mode 100644 index 0000000..c92e559 --- /dev/null +++ b/LICENSE @@ -0,0 +1,21 @@ +The MIT License (MIT) + +Copyright (c) 2015 Recep Aslantas + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE. diff --git a/include/cglm-common.h b/include/cglm-common.h new file mode 100644 index 0000000..3ce2390 --- /dev/null +++ b/include/cglm-common.h @@ -0,0 +1,17 @@ +/* + * Copyright (c), Recep Aslantas. + * + * MIT License (MIT), http://opensource.org/licenses/MIT + * Full license can be found in the LICENSE file + */ + +#ifndef glm_common_h +#define glm_common_h + +#if defined(_WIN32) +# define CGLM_INLINE __forceinline +#else +# define CGLM_INLINE static inline __attribute((always_inline)) +#endif + +#endif /* glm_common_h */ diff --git a/include/cglm-intrin.h b/include/cglm-intrin.h new file mode 100644 index 0000000..79ebd3c --- /dev/null +++ b/include/cglm-intrin.h @@ -0,0 +1,23 @@ +/* + * Copyright (c), Recep Aslantas. + * + * MIT License (MIT), http://opensource.org/licenses/MIT + * Full license can be found in the LICENSE file + */ + +#ifndef cglm_intrin_h +#define cglm_intrin_h + +#include +#include + +/* float */ +#define _mm_madd_ps(L, R0, R1) \ + _mm_add_ps(_mm_mul_ps(_mm_set1_ps(*(L)), R0), \ + _mm_mul_ps(_mm_set1_ps(*(L + 1)), R1)) + +#define _mm_madd4_ps(L, R0, R1, R2, R3) \ + _mm_add_ps(_mm_madd_ps(L, R0, R1), \ + _mm_madd_ps(L + 2, R2, R3)) + +#endif /* cglm_intrin_h */ diff --git a/include/cglm-mat-simd.h b/include/cglm-mat-simd.h new file mode 100644 index 0000000..65e9f4d --- /dev/null +++ b/include/cglm-mat-simd.h @@ -0,0 +1,31 @@ +/* + * Copyright (c), Recep Aslantas. + * + * MIT License (MIT), http://opensource.org/licenses/MIT + * Full license can be found in the LICENSE file + */ + +#ifndef cglm_mat_sse_h +#define cglm_mat_sse_h + +#include "cglm-intrin.h" + +#define CGLM_MAT_MUL_SSE_4x4f(L, R, D) \ + do { \ + __m128 r0; \ + __m128 r1; \ + __m128 r2; \ + __m128 r3; \ + \ + r0 = _mm_load_ps(R); \ + r1 = _mm_load_ps(R + 4); \ + r2 = _mm_load_ps(R + 8); \ + r3 = _mm_load_ps(R + 12); \ + \ + _mm_store_ps(D, _mm_madd4_ps(L, r0, r1, r2, r3)); \ + _mm_store_ps(D + 4, _mm_madd4_ps(L + 4, r0, r1, r2, r3)); \ + _mm_store_ps(D + 8, _mm_madd4_ps(L + 8, r0, r1, r2, r3)); \ + _mm_store_ps(D + 12, _mm_madd4_ps(L + 12, r0, r1, r2, r3)); \ + } while (0) + +#endif /* cglm_mat_sse_h */ diff --git a/include/cglm-mat.h b/include/cglm-mat.h new file mode 100644 index 0000000..330cd83 --- /dev/null +++ b/include/cglm-mat.h @@ -0,0 +1,46 @@ +/* + * Copyright (c), Recep Aslantas. + * + * MIT License (MIT), http://opensource.org/licenses/MIT + * Full license can be found in the LICENSE file + */ + +#ifndef cglm_mat_h +#define cglm_mat_h + +#include "cglm.h" +#include "cglm-mat-simd.h" + +#define glm_mat_mul4_impl(l, r, d) \ + do { \ + d[0] = l[0] * r[0] + l[1] * r[4] + l[2] * r[8] + l[3] * r[12]; \ + d[1] = l[0] * r[1] + l[1] * r[5] + l[2] * r[9] + l[3] * r[13]; \ + d[2] = l[0] * r[2] + l[1] * r[6] + l[2] * r[10] + l[3] * r[14]; \ + d[3] = l[0] * r[3] + l[1] * r[7] + l[2] * r[11] + l[3] * r[15]; \ + d[4] = l[4] * r[0] + l[5] * r[4] + l[6] * r[8] + l[7] * r[12]; \ + d[5] = l[4] * r[1] + l[5] * r[5] + l[6] * r[9] + l[7] * r[13]; \ + d[6] = l[4] * r[2] + l[5] * r[6] + l[6] * r[10] + l[7] * r[14]; \ + d[7] = l[4] * r[3] + l[5] * r[7] + l[6] * r[11] + l[7] * r[15]; \ + d[8] = l[8] * r[0] + l[9] * r[4] + l[10] * r[8] + l[11] * r[12]; \ + d[9] = l[8] * r[1] + l[9] * r[5] + l[10] * r[9] + l[11] * r[13]; \ + d[10] = l[8] * r[2] + l[9] * r[6] + l[10] * r[10] + l[11] * r[14]; \ + d[11] = l[8] * r[3] + l[9] * r[7] + l[10] * r[11] + l[11] * r[15]; \ + d[12] = l[12] * r[0] + l[13] * r[4] + l[14] * r[8] + l[15] * r[12]; \ + d[13] = l[12] * r[1] + l[13] * r[5] + l[14] * r[9] + l[15] * r[13]; \ + d[14] = l[12] * r[2] + l[13] * r[6] + l[14] * r[10] + l[15] * r[14]; \ + d[15] = l[12] * r[3] + l[13] * r[7] + l[14] * r[11] + l[15] * r[15]; \ + } while (0) + +CGLM_INLINE +void +glm_mat_mul4(float * __restrict m1, + float * __restrict m2, + float * __restrict dest) { +#if defined( __SSE__ ) || defined( __SSE2__ ) + CGLM_MAT_MUL_SSE_4x4f(m1, m2, dest); +#else + glm_mat_mul4_impl(m1, m2, dest); +#endif +} + +#endif /* cglm_mat_h */ diff --git a/include/cglm-vec.h b/include/cglm-vec.h new file mode 100644 index 0000000..57fd7ae --- /dev/null +++ b/include/cglm-vec.h @@ -0,0 +1,13 @@ +/* + * Copyright (c), Recep Aslantas. + * + * MIT License (MIT), http://opensource.org/licenses/MIT + * Full license can be found in the LICENSE file + */ + +#ifndef cglm_vec_h +#define cglm_vec_h + + + +#endif /* cglm_vec_h */ diff --git a/include/cglm.h b/include/cglm.h new file mode 100644 index 0000000..27f8ea3 --- /dev/null +++ b/include/cglm.h @@ -0,0 +1,28 @@ +/* + * Copyright (c), Recep Aslantas. + * + * MIT License (MIT), http://opensource.org/licenses/MIT + * Full license can be found in the LICENSE file + */ + +#ifndef glm_h +#define glm_h + +#include "cglm-common.h" + +typedef float vec3[3]; +typedef float vec4[4]; + +typedef float mat3[3]; +typedef float mat4[16]; + +CGLM_INLINE +void +glm_mat_mul4(float * __restrict m1, + float * __restrict m2, + float * __restrict dest); + +#include "cglm-vec.h" +#include "cglm-mat.h" + +#endif /* glm_h */