#pragma once #include "GLenv/include/glad/glad.h" #include "StgSharpGraphic.h" #include #include #include #include #include /* Basic functions as a copy of SIMD intrisic function */ SSGC_API __m128* __cdecl load(float x, float y, float z, float w) { float array[4] = {x,y,z,w}; __m128* ptr = _aligned_malloc(sizeof(__m128),16); if (NULL != ptr) { *ptr = _mm_loadu_ps(&array); return ptr; } else { return -1; } } SSGC_API __m128* __cdecl load_cpy(__m128* ptr) { __m128* ret = _aligned_malloc(sizeof(__m128*),16); if (NULL != ret) { *ret = *ptr; } return ret; } SSGC_API __m128* __cdecl addps(__m128* ptr1, __m128* ptr2) { __m128* ret = _aligned_malloc(sizeof(__m128*),16); if (NULL != ret) { *ret = _mm_add_ps(*ptr1, *ptr2); return ret; } else { return (__m128*) - 1; } } SSGC_API __m128* __cdecl subps(__m128* ptr1, __m128* ptr2) { __m128* ret = _aligned_malloc(sizeof(__m128*), 16); if (NULL != ret) { *ret = _mm_sub_ps(*ptr1, *ptr2); return ret; } else { return -1; } } SSGC_API __m128* __cdecl mulps_const(__m128* ptr, float value) { float c[4] = { value, value, value, value }; __m128* ret = _aligned_malloc(sizeof(__m128),16); __m128 valueVec = _mm_loadu_ps(&c); if (NULL != ret) { *ret = _mm_mul_ps(*ptr,valueVec); return ret; } else { return -1; } } SSGC_API __m128* __cdecl mulps(__m128* ptr1, __m128* ptr2) { __m128* ret = _aligned_malloc(sizeof(__m128), 16); if (NULL != ret) { *ret = _mm_mul_ps(*ptr1, *ptr2); return ret; } else { return -1; } } SSGC_API _inline float __cdecl mulps_sum(__m128* ptr1, __m128* ptr2) { __m128 ret = _mm_mul_ps(*ptr1,*ptr2); ret = _mm_hadd_ps(ret,ret); ret = _mm_hadd_ps(ret,ret); return *(float*)&ret; } _inline float __cdecl mulps_sum_internal(__m128 left, __m128 right) { __m128 ret = _mm_mul_ps(left, right); ret = _mm_hadd_ps(ret, ret); ret = _mm_hadd_ps(ret, ret); return *(float*)&ret; } _inline float __cdecl mulps_total_internal(__m128 vec) { } SSGC_API __m128* __cdecl divps_const(__m128* ptr, float value) { float c[4] = { value, value, value, value }; __m128* ret = _aligned_malloc(sizeof(__m128), 16); __m128 valueVec = _mm_loadu_ps(&c); if (NULL != ret) { *ret = _mm_div_ps(*ptr, valueVec); return ret; } else { return -1; } } SSGC_API __m128* __cdecl divps(__m128* ptr1, __m128* ptr2) { __m128* ret = _aligned_malloc(sizeof(__m128), 16); if (NULL != ret) { *ret = _mm_div_ps(*ptr1, *ptr2); return ret; } else { return -1; } } SSGC_API float __cdecl sqrtss_const(float a) { __m128 ret = _mm_sqrt_ss(*(__m128*) & a); return ret.m128_f32[0]; } /* Some complex functions for matrix calculations. */ SSGC_API __m256i* __cdecl load_matmap(uint64_t c0, uint64_t c1, uint64_t c2, uint64_t c3) { __m256i* retPtr = _aligned_malloc(sizeof(__m256i), sizeof(__m256i)); uint64_t ptr[4] = {c0,c1,c2,c3 }; if (NULL != retPtr) { *retPtr = _mm256_loadu_epi64(&ptr); } return retPtr; } SSGC_API __m128* __cdecl set_m128ptr_default() { return defaultVecPtr; } /* Functions to clean up colum and matrix resources */ SSGC_API void __cdecl deinitM128(__m128* ptr) { _aligned_free(ptr); }