daily update on 20241002 by nitload youmu, intrinsic function rebuild, syntax style arrange

This commit is contained in:
Nitload
2024-10-03 04:03:06 +08:00
parent 0979123ac0
commit 6e2f93b053
265 changed files with 26732 additions and 19058 deletions
+51 -53
View File
@@ -1,81 +1,79 @@
#include "ssgc_framework.h"
#include "StgSharpC.h"
#include "gl.h"
#include "glfw3.h"
#include "StgSharpC.h"
#include "ssc_framework.h"
#include <stdio.h>
GladGLContext* currentContext;
GladGLContext *currentContext;
extern char infolog[512] = { 0 };
SSCAPI int SSCDECL glCheckShaderStat(GladGLContext* context,uint64_t shaderHandle , int key, char** logRef)
SSCAPI int SSCDECL glCheckShaderStat(GladGLContext *context,
uint64_t shaderHandle, int key,
char **logRef)
{
int stat = 0;
context->GetShaderiv(shaderHandle, key, &stat);
if (!stat)
{
context->GetShaderInfoLog(shaderHandle, 512, NULL, infolog);
}
*logRef = infolog;
return stat;
int stat = 0;
context->GetShaderiv(shaderHandle, key, &stat);
if (!stat) {
context->GetShaderInfoLog(shaderHandle, 512, NULL, infolog);
}
*logRef = infolog;
return stat;
}
SSCAPI void SSCDECL initGL(int majorVersion, int minorVersion)
{
glfwWindowHint(GLFW_CONTEXT_VERSION_MAJOR, majorVersion);
glfwWindowHint(GLFW_CONTEXT_VERSION_MINOR, minorVersion);
glfwWindowHint(GLFW_OPENGL_PROFILE, GLFW_OPENGL_CORE_PROFILE);
glfwWindowHint(GLFW_RESIZABLE, GLFW_TRUE);
glfwWindowHint(GLFW_CONTEXT_VERSION_MAJOR, majorVersion);
glfwWindowHint(GLFW_CONTEXT_VERSION_MINOR, minorVersion);
glfwWindowHint(GLFW_OPENGL_PROFILE, GLFW_OPENGL_CORE_PROFILE);
glfwWindowHint(GLFW_RESIZABLE, GLFW_TRUE);
}
SSCAPI GLFWglproc SSCDECL loadGlfuncDefault(char* procName)
SSCAPI GLFWglproc SSCDECL loadGlfuncDefault(char *procName)
{
void* ret = glfwGetProcAddress(procName);
//printf("%llu\n", (uint64_t)ret);
if (ret = NULL)
{
*infolog = "Failed to load OpenGL api:";
for (size_t i = 0; i < sizeof(procName); i++)
{
infolog[30 + i] = procName[i];
void *ret = glfwGetProcAddress(procName);
// printf("%llu\n", (uint64_t)ret);
if (ret = NULL) {
*infolog = "Failed to load OpenGL api:";
for (size_t i = 0; i < sizeof(procName); i++) {
infolog[30 + i] = procName[i];
}
printf("%s\n", infolog);
}
printf("%s\n", infolog);
}
return (GLFWglproc)ret;
return (GLFWglproc)ret;
}
SSCAPI unsigned int linkShaderProgram(GladGLContext* context, GLuint shaderProgram)
SSCAPI unsigned int linkShaderProgram(GladGLContext *context,
GLuint shaderProgram)
{
context->LinkProgram(shaderProgram);
context->LinkProgram(shaderProgram);
int success;
context->GetProgramiv(shaderProgram, GL_LINK_STATUS, &success);
if (!success)
{
context->GetProgramInfoLog(shaderProgram, 512, NULL, infolog);
return 0;
}
else
{
return shaderProgram;
}
int success;
context->GetProgramiv(shaderProgram, GL_LINK_STATUS, &success);
if (!success) {
context->GetProgramInfoLog(shaderProgram, 512, NULL, infolog);
return 0;
} else {
return shaderProgram;
}
}
SSCAPI void SSCDECL loadImageData(char* location, Image* out, imageLoader loader)
SSCAPI void SSCDECL loadImageData(char *location, Image *out,
imageLoader loader)
{
if (loader == NULL)
{
loader = stbi_load;
}
out->pixelPtr = loader(location, &(out->width), &(out->height), &(out->channel), 0);
if (loader == NULL) {
loader = stbi_load;
}
out->pixelPtr = loader(location, &(out->width), &(out->height),
&(out->channel), 0);
}
SSCAPI void SSCDECL unloadImageData(Image* out)
SSCAPI void SSCDECL unloadImageData(Image *out)
{
free(out->pixelPtr);
free(out->pixelPtr);
}
char* _cdecl readLog()
char *_cdecl readLog()
{
infolog[511] = '\0';
return &infolog;
}
infolog[511] = '\0';
return &infolog;
}
+53 -92
View File
@@ -1,114 +1,75 @@
#ifndef SSC
#ifdef _MSC_VER
#pragma once
#endif
#ifndef SSC
#define SSC
#define SSC_Api
#include "ssgc_framework.h"
#include "ssgc_internal.h"
#include "gl.h"
#include "wgl.h"
#include "glfw3.h"
#include <immintrin.h>
#include "ssc_framework.h"
#include "ssc_internal.h"
#define STBIDEF SSCAPI
#include "stb_image.h"
#pragma comment(lib,"glfw3.lib")
#include "gl.h"
#include "wgl.h"
#include "glfw3.h"
#include <immintrin.h>
#include <assert.h>
#ifndef SSCAPI_DEFINE
#ifdef _WIN32
#define SSCAPI __declspec(dllexport)
#elif defined _LINUX_
#define SSCAPI __attribute__((dllexport))
#elif defined _APPLE_
#define SSCAPI __attribute__((visibility("default")))
#else
#define SSCAPI
#endif
#endif // ! SSCAPI_DEFINE
#if __cplusplus
extern "C"
{
#endif // _cplusplus
extern "C" {
#endif
#define byte char
#pragma region Internal
#define ssc_null_assert(ptr) assert(ptr != NULL)
#define ALIGN(simdVec) _mm_loadu_ps(&simdVec)
typedef struct Image {
typedef struct Image {
int width;
int height;
int channel;
char* pixelPtr;
}Image;
char *pixelPtr;
} Image;
typedef char *(*imageLoader)(char const *filename, int *x, int *y,
int *channels_in_file, int desired_channels);
SSCAPI char infolog[512];
SSCAPI int SSCDECL glCheckShaderStat(GladGLContext *context,
uint64_t shaderHandle, int key,
char **logRef);
SSCAPI void SSCDECL initGL(int majorVersion, int minorVersion);
SSCAPI unsigned int SSCDECL linkShaderProgram(GladGLContext *context,
GLuint shadertype);
SSCAPI void SSCDECL loadImageData(char *location, Image *out,
imageLoader loader);
SSCAPI GLFWglproc SSCDECL loadGlfuncDefault(char *procName);
SSCAPI void SSCDECL unloadImageData(Image *out);
SSCAPI char *SSCDECL readLog(void);
#pragma endregion
typedef char* (*imageLoader)(char const* filename, int* x, int* y, int* channels_in_file, int desired_channels);
SSCAPI void SSCDECL load_intrinsic_function(void *intrinsic_context);
SSCAPI char infolog[512];
SSCAPI int SSCDECL glCheckShaderStat(GladGLContext* context, int key, char** logRef);
SSCAPI void SSCDECL initGL(int majorVersion, int minorVersion);
SSCAPI unsigned int SSCDECL linkShaderProgram(GladGLContext* context, GLuint shadertype);
SSCAPI void SSCDECL loadImageData(char* location, Image* out, imageLoader loader);
SSCAPI GLFWglproc SSCDECL loadGlfuncDefault(char* procName);
SSCAPI void SSCDECL unloadImageData(Image* out);
SSCAPI char* SSCDECL readLog(void);
//linear related function
#pragma region mat define
typedef union matrix2map
{
__m128 colum[2];
float m[4][2];
}matrix2map;
typedef struct matrix3map
{
__m128 colum[3];
float m[4][3];
}matrix3map;
typedef union matrix4map {
__m128 colum[4];
float m[4][4];
}matrix4map;
#pragma endregion
#pragma region Vector
SSCAPI void SSCDECL normalize(__m128* source, __m128* target);
#pragma endregion
#pragma region mat2
SSCAPI _inline void __cdecl transpose2to3(matrix2map* source, matrix3map* target);
SSCAPI _inline void __cdecl transpose2to4(matrix2map* source, matrix4map* target);
SSCAPI _inline void __cdecl deinit_mat2(matrix2map* mat);
#pragma endregion
#pragma region mat3
SSCAPI __inline void _cdecl transpose3to2(matrix3map* source, matrix2map* target);
SSCAPI __inline void _cdecl transpose3to3(matrix3map* source, matrix3map* target);
SSCAPI __inline void _cdecl transpose3to4(matrix3map* source, matrix4map* target);
SSCAPI _inline float _cdecl det_mat3(matrix3map* mat);
SSCAPI __inline float det_mat3_internal(__m128 const c1, __m128 const c2, __m128 const c3);
#pragma endregion
#pragma region mat4
//type and function for 4 colum matrix
SSCAPI __inline void __cdecl transpose4to2(matrix4map* source, matrix4map* target);
SSCAPI __inline void __cdecl transpose4to4(matrix4map* matrix, matrix4map* target);
SSCAPI __inline float __cdecl det_mat4(matrix4map* matPtr, matrix4map* transpose);
SSCAPI __inline void __cdecl deinit_mat4(matrix4map* matPtr);
#pragma endregion
#ifdef __cplusplus
#ifdef __cplusplus
}
#endif // __cplusplus
#endif
#endif // !SSG
#endif
+5 -5
View File
@@ -159,27 +159,27 @@
</ItemGroup>
<ItemGroup>
<ClCompile Include="dllmain.c" />
<ClCompile Include="intrinsic.c" />
<ClCompile Include="mat2.c" />
<ClCompile Include="mat3.c" />
<ClCompile Include="mat4.c" />
<ClCompile Include="stb_image.c" />
<ClCompile Include="StgSharpC.c" />
<ClCompile Include="quick_hash.c" />
<ClCompile Include="vector.c" />
</ItemGroup>
<ItemGroup>
<ClInclude Include="gl.h" />
<ClInclude Include="glfw3.h" />
<ClInclude Include="glfw3native.h" />
<ClInclude Include="ssc_intrinsic.h" />
<ClInclude Include="khrplatform.h" />
<ClInclude Include="ssgc_framework.h" />
<ClInclude Include="ssgc_internal.h" />
<ClInclude Include="ssc_framework.h" />
<ClInclude Include="ssc_internal.h" />
<ClInclude Include="stb_image.h" />
<ClInclude Include="StgSharpC.h" />
<ClInclude Include="wgl.h" />
</ItemGroup>
<ItemGroup>
<None Include="ClassDiagram.cd" />
</ItemGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
<ImportGroup Label="ExtensionTargets">
</ImportGroup>
+22 -21
View File
@@ -1,34 +1,33 @@
// dllmain.cpp : 定义 DLL 应用程序的入口点。
#ifdef _WIN32
#include "ssgc_framework.h"
#include "ssc_framework.h"
#endif // __
#include "StgSharpC.h"
#ifdef _WIN32
BOOL APIENTRY DllMain(HMODULE hModule,
DWORD ul_reason_for_call,
LPVOID lpReserved
// clang-format off
BOOL APIENTRY DllMain(
HMODULE hModule,
DWORD ul_reason_for_call,
LPVOID lpReserved
)
{
switch (ul_reason_for_call)
{
case DLL_PROCESS_ATTACH:
return 1;
case DLL_THREAD_ATTACH:
return 1;
case DLL_THREAD_DETACH:
return 1;
case DLL_PROCESS_DETACH:
return 1;
switch (ul_reason_for_call)
{
case DLL_PROCESS_ATTACH:
return 1;
case DLL_THREAD_ATTACH:
return 1;
case DLL_THREAD_DETACH:
return 1;
case DLL_PROCESS_DETACH:
return 1;
break;
}
}
return TRUE;
}
#else
@@ -36,4 +35,6 @@ attribute((constructor)) void DllMain()
{
}
#endif // _WIN32
// clang-format on
#endif // _WIN32
+24
View File
@@ -0,0 +1,24 @@
#include "StgSharpC.h"
#include "ssc_intrinsic.h"
#include <stdio.h>
SSCAPI void load_intrinsic_function(void *intrinsic_context)
{
ssc_null_assert(intrinsic_context);
ssc_intrinsic *context = (ssc_intrinsic *)intrinsic_context;
context->transpose_23 = transpose23;
context->transpose_24 = transpose24;
context->transpose_32 = transpose32;
context->transpose_33 = transpose33;
context->transpose_34 = transpose34;
context->transpose_42 = transpose42;
context->transpose_43 = transpose43;
context->transpose_44 = transpose44;
context->normalize_3 = normalize;
context->det_matrix33 = det_mat3;
context->det_matrix44 = det_mat4;
context->string_quick_hash = quick_string_hash;
}
+31 -19
View File
@@ -1,28 +1,40 @@
#include "StgSharpC.h"
#include "ssgc_internal.h"
#include "ssc_intrinsic.h"
SSCAPI _inline void __cdecl transpose2to3(matrix2map* source, matrix3map* target)
INTERNAL void __cdecl transpose23(__2_columnset *source,
__3_columnset *target)
{
__m128 t0 = _mm_shuffle_ps(ALIGN(source->colum[0]), ALIGN(source->colum[1]), _MM_SHUFFLE(1, 0, 1, 0));
__m128 t1 = _mm_shuffle_ps(ALIGN(source->colum[0]), ALIGN(source->colum[1]), _MM_SHUFFLE(3, 2, 3, 2));
__m128 t0 = _mm_shuffle_ps(ALIGN(source->column[0]),
ALIGN(source->column[1]),
_MM_SHUFFLE(1, 0, 1, 0));
__m128 t1 = _mm_shuffle_ps(ALIGN(source->column[0]),
ALIGN(source->column[1]),
_MM_SHUFFLE(3, 2, 3, 2));
target->colum[0] = _mm_shuffle_ps(t0, zeroVec, _MM_SHUFFLE(2, 0, 2, 0));
target->colum[1] = _mm_shuffle_ps(t0, zeroVec, _MM_SHUFFLE(3, 1, 3, 1));
target->colum[2] = _mm_shuffle_ps(t1, zeroVec, _MM_SHUFFLE(2, 0, 2, 0));
target->column[0] =
_mm_shuffle_ps(t0, zeroVec, _MM_SHUFFLE(2, 0, 2, 0));
target->column[1] =
_mm_shuffle_ps(t0, zeroVec, _MM_SHUFFLE(3, 1, 3, 1));
target->column[2] =
_mm_shuffle_ps(t1, zeroVec, _MM_SHUFFLE(2, 0, 2, 0));
}
SSCAPI _inline void __cdecl transpose2to4(matrix2map* source, matrix4map* target)
INTERNAL void __cdecl transpose24(__2_columnset *source,
__4_columnset *target)
{
__m128 t0 = _mm_shuffle_ps(ALIGN(source->colum[0]), ALIGN(source->colum[1]), _MM_SHUFFLE(1, 0, 1, 0));
__m128 t1 = _mm_shuffle_ps(ALIGN(source->colum[0]), ALIGN(source->colum[1]), _MM_SHUFFLE(3, 2, 3, 2));
__m128 t0 = _mm_shuffle_ps(ALIGN(source->column[0]),
ALIGN(source->column[1]),
_MM_SHUFFLE(1, 0, 1, 0));
__m128 t1 = _mm_shuffle_ps(ALIGN(source->column[0]),
ALIGN(source->column[1]),
_MM_SHUFFLE(3, 2, 3, 2));
target->colum[0] = _mm_shuffle_ps(t0, zeroVec, _MM_SHUFFLE(2, 0, 2, 0));
target->colum[1] = _mm_shuffle_ps(t0, zeroVec, _MM_SHUFFLE(3, 1, 3, 1));
target->colum[2] = _mm_shuffle_ps(t1, zeroVec, _MM_SHUFFLE(2, 0, 2, 0));
target->colum[3] = _mm_shuffle_ps(t1, zeroVec, _MM_SHUFFLE(3, 1, 3, 1));
target->column[0] =
_mm_shuffle_ps(t0, zeroVec, _MM_SHUFFLE(2, 0, 2, 0));
target->column[1] =
_mm_shuffle_ps(t0, zeroVec, _MM_SHUFFLE(3, 1, 3, 1));
target->column[2] =
_mm_shuffle_ps(t1, zeroVec, _MM_SHUFFLE(2, 0, 2, 0));
target->column[3] =
_mm_shuffle_ps(t1, zeroVec, _MM_SHUFFLE(3, 1, 3, 1));
}
SSCAPI _inline void __cdecl deinit_mat2(matrix2map* mat)
{
_aligned_free(mat);
}
+66 -48
View File
@@ -1,73 +1,91 @@
#include "StgSharpC.h"
#include "ssgc_internal.h"
#include "ssc_intrinsic.h"
#include <stdio.h>
SSCAPI __inline void _cdecl transpose3to2(matrix3map* source, matrix2map* target)
INTERNAL void _cdecl transpose32(__3_columnset *source,
__2_columnset *target)
{
__m128 t0 = _mm_shuffle_ps(ALIGN(source->colum[0]), ALIGN(source->colum[1]), _MM_SHUFFLE(1, 0, 1, 0));
__m128 t2 = _mm_shuffle_ps(ALIGN(source->colum[2]), zeroVec, _MM_SHUFFLE(1, 0, 1, 0));
__m128 t0 = _mm_shuffle_ps(ALIGN(source->column[0]),
ALIGN(source->column[1]),
_MM_SHUFFLE(1, 0, 1, 0));
__m128 t2 = _mm_shuffle_ps(ALIGN(source->column[2]), zeroVec,
_MM_SHUFFLE(1, 0, 1, 0));
target->colum[0] = _mm_shuffle_ps(t0, t2, _MM_SHUFFLE(2, 0, 2, 0));
target->colum[1] = _mm_shuffle_ps(t0, t2, _MM_SHUFFLE(3, 1, 3, 1));
target->column[0] = _mm_shuffle_ps(t0, t2, _MM_SHUFFLE(2, 0, 2, 0));
target->column[1] = _mm_shuffle_ps(t0, t2, _MM_SHUFFLE(3, 1, 3, 1));
}
SSCAPI __inline void _cdecl transpose3to3(matrix3map* source, matrix3map* target)
INTERNAL void _cdecl transpose33(__3_columnset *source,
__3_columnset *target)
{
__m128 t0 = _mm_shuffle_ps(ALIGN(source->colum[0]), ALIGN(source->colum[1]), _MM_SHUFFLE(1, 0, 1, 0));
__m128 t1 = _mm_shuffle_ps(ALIGN(source->colum[0]), ALIGN(source->colum[1]), _MM_SHUFFLE(3, 2, 3, 2));
__m128 t2 = _mm_shuffle_ps(ALIGN(source->colum[2]), zeroVec, _MM_SHUFFLE(1, 0, 1, 0));
__m128 t3 = _mm_shuffle_ps(ALIGN(source->colum[2]), zeroVec, _MM_SHUFFLE(3, 2, 3, 2));
__m128 t0 = _mm_shuffle_ps(ALIGN(source->column[0]),
ALIGN(source->column[1]),
_MM_SHUFFLE(1, 0, 1, 0));
__m128 t1 = _mm_shuffle_ps(ALIGN(source->column[0]),
ALIGN(source->column[1]),
_MM_SHUFFLE(3, 2, 3, 2));
__m128 t2 = _mm_shuffle_ps(ALIGN(source->column[2]), zeroVec,
_MM_SHUFFLE(1, 0, 1, 0));
__m128 t3 = _mm_shuffle_ps(ALIGN(source->column[2]), zeroVec,
_MM_SHUFFLE(3, 2, 3, 2));
target->colum[0] = _mm_shuffle_ps(t0, t2, _MM_SHUFFLE(2, 0, 2, 0));
target->colum[1] = _mm_shuffle_ps(t0, t2, _MM_SHUFFLE(3, 1, 3, 1));
target->colum[2] = _mm_shuffle_ps(t1, t3, _MM_SHUFFLE(2, 0, 2, 0));
target->column[0] = _mm_shuffle_ps(t0, t2, _MM_SHUFFLE(2, 0, 2, 0));
target->column[1] = _mm_shuffle_ps(t0, t2, _MM_SHUFFLE(3, 1, 3, 1));
target->column[2] = _mm_shuffle_ps(t1, t3, _MM_SHUFFLE(2, 0, 2, 0));
}
SSCAPI __inline void _cdecl transpose3to4(matrix3map* source, matrix4map* target)
INTERNAL void _cdecl transpose34(__3_columnset *source,
__4_columnset *target)
{
__m128 t0 = _mm_shuffle_ps(ALIGN(source->colum[0]), ALIGN(source->colum[1]), _MM_SHUFFLE(1, 0, 1, 0));
__m128 t1 = _mm_shuffle_ps(ALIGN(source->colum[0]), ALIGN(source->colum[1]), _MM_SHUFFLE(3, 2, 3, 2));
__m128 t2 = _mm_shuffle_ps(ALIGN(source->colum[2]), zeroVec, _MM_SHUFFLE(1, 0, 1, 0));
__m128 t3 = _mm_shuffle_ps(ALIGN(source->colum[2]), zeroVec, _MM_SHUFFLE(3, 2, 3, 2));
__m128 t0 = _mm_shuffle_ps(ALIGN(source->column[0]),
ALIGN(source->column[1]),
_MM_SHUFFLE(1, 0, 1, 0));
__m128 t1 = _mm_shuffle_ps(ALIGN(source->column[0]),
ALIGN(source->column[1]),
_MM_SHUFFLE(3, 2, 3, 2));
__m128 t2 = _mm_shuffle_ps(ALIGN(source->column[2]), zeroVec,
_MM_SHUFFLE(1, 0, 1, 0));
__m128 t3 = _mm_shuffle_ps(ALIGN(source->column[2]), zeroVec,
_MM_SHUFFLE(3, 2, 3, 2));
target->colum[0] = _mm_shuffle_ps(t0, t2, _MM_SHUFFLE(2, 0, 2, 0));
target->colum[1] = _mm_shuffle_ps(t0, t2, _MM_SHUFFLE(3, 1, 3, 1));
target->colum[2] = _mm_shuffle_ps(t1, t3, _MM_SHUFFLE(2, 0, 2, 0));
target->colum[3] = _mm_shuffle_ps(t1, t3, _MM_SHUFFLE(3, 1, 3, 1));
target->column[0] = _mm_shuffle_ps(t0, t2, _MM_SHUFFLE(2, 0, 2, 0));
target->column[1] = _mm_shuffle_ps(t0, t2, _MM_SHUFFLE(3, 1, 3, 1));
target->column[2] = _mm_shuffle_ps(t1, t3, _MM_SHUFFLE(2, 0, 2, 0));
target->column[3] = _mm_shuffle_ps(t1, t3, _MM_SHUFFLE(3, 1, 3, 1));
}
SSCAPI _inline float _cdecl det_mat3_internal(__m128 const c0, __m128 const c1, __m128 const c2)
INTERNAL float _cdecl det_mat3_internal(__m128 const c0,
__m128 const c1,
__m128 const c2)
{
//let adding row aligned
__m128 addc1 = _mm_shuffle_ps(c1, c1, _MM_SHUFFLE(3, 0, 2, 1));
__m128 addc2 = _mm_shuffle_ps(c2, c2, _MM_SHUFFLE(3, 1, 0, 2));
//let adding row aligned
__m128 addc1 = _mm_shuffle_ps(c1, c1, _MM_SHUFFLE(3, 0, 2, 1));
__m128 addc2 = _mm_shuffle_ps(c2, c2, _MM_SHUFFLE(3, 1, 0, 2));
//let sub row aligned
__m128 subc1 = _mm_shuffle_ps(c1, c1, _MM_SHUFFLE(3, 1, 0, 2));
__m128 subc2 = _mm_shuffle_ps(c2, c2, _MM_SHUFFLE(3, 0, 2, 1));
//let sub row aligned
__m128 subc1 = _mm_shuffle_ps(c1, c1, _MM_SHUFFLE(3, 1, 0, 2));
__m128 subc2 = _mm_shuffle_ps(c2, c2, _MM_SHUFFLE(3, 0, 2, 1));
//multple all add row
__m128 cache = _mm_mul_ps(c0, addc1);
cache = _mm_mul_ps(cache, addc2);
//multple all add row
__m128 cache = _mm_mul_ps(c0, addc1);
cache = _mm_mul_ps(cache, addc2);
//multiple all sub row
__m128 sub = _mm_mul_ps(c0, subc1);
sub = _mm_mul_ps(sub, subc2);
//multiple all sub row
__m128 sub = _mm_mul_ps(c0, subc1);
sub = _mm_mul_ps(sub, subc2);
//main-corner sub sub-corner
cache = _mm_sub_ps(cache, sub);
//main-corner sub sub-corner
cache = _mm_sub_ps(cache, sub);
__m128 ret = _mm_hadd_ps(cache, cache); //element 1 add element 2
ret = _mm_add_ps(ret, cache); //(e1 add e2) add element 3
__m128 ret = _mm_hadd_ps(cache, cache); //element 1 add element 2
ret = _mm_add_ps(ret, cache); //(e1 add e2) add element 3
return ret.m128_f32[2];
return ret.m128_f32[2];
}
SSCAPI _inline float _cdecl det_mat3(matrix3map* mat)
INTERNAL float _cdecl det_mat3(__3_columnset *source,
__3_columnset *transpose)
{
return det_mat3_internal(
mat->colum[0],
mat->colum[1],
mat->colum[2]
);
}
return det_mat3_internal(source->column[0], source->column[1],
source->column[2]);
}
+57 -43
View File
@@ -1,62 +1,76 @@
#include "StgSharpC.h"
#include "ssgc_internal.h"
#include "ssc_intrinsic.h"
#include <stdio.h>
#include <pmmintrin.h>
SSCAPI __inline void __cdecl transpose4to2(matrix4map* source, matrix4map* target)
INTERNAL void __cdecl transpose42(__4_columnset *source, __2_columnset *target)
{
__m128 t0 = _mm_shuffle_ps(ALIGN(source->colum[0]), ALIGN(source->colum[1]), _MM_SHUFFLE(1, 0, 1, 0));
__m128 t2 = _mm_shuffle_ps(ALIGN(source->colum[2]), ALIGN(source->colum[3]), _MM_SHUFFLE(1, 0, 1, 0));
__m128 t0 = _mm_shuffle_ps(ALIGN(source->column[0]),
ALIGN(source->column[1]),
_MM_SHUFFLE(1, 0, 1, 0));
__m128 t2 = _mm_shuffle_ps(ALIGN(source->column[2]),
ALIGN(source->column[3]),
_MM_SHUFFLE(1, 0, 1, 0));
target->colum[0] = _mm_shuffle_ps(t0, t2, _MM_SHUFFLE(2, 0, 2, 0));
target->colum[1] = _mm_shuffle_ps(t0, t2, _MM_SHUFFLE(3, 1, 3, 1));
target->column[0] = _mm_shuffle_ps(t0, t2, _MM_SHUFFLE(2, 0, 2, 0));
target->column[1] = _mm_shuffle_ps(t0, t2, _MM_SHUFFLE(3, 1, 3, 1));
}
SSCAPI __inline void __cdecl transpose4to4(matrix4map* source, matrix4map* target)
INTERNAL void __cdecl transpose43(__4_columnset *source, __3_columnset *target)
{
__m128 t0 = _mm_shuffle_ps(ALIGN(source->colum[0]), ALIGN(source->colum[1]), _MM_SHUFFLE(1, 0, 1, 0));
__m128 t1 = _mm_shuffle_ps(ALIGN(source->colum[0]), ALIGN(source->colum[1]), _MM_SHUFFLE(3, 2, 3, 2));
__m128 t2 = _mm_shuffle_ps(ALIGN(source->colum[2]), ALIGN(source->colum[3]), _MM_SHUFFLE(1, 0, 1, 0));
__m128 t3 = _mm_shuffle_ps(ALIGN(source->colum[2]), ALIGN(source->colum[3]), _MM_SHUFFLE(3, 2, 3, 2));
__m128 t0 = _mm_shuffle_ps(ALIGN(source->column[0]),
ALIGN(source->column[1]),
_MM_SHUFFLE(1, 0, 1, 0));
__m128 t1 = _mm_shuffle_ps(ALIGN(source->column[0]),
ALIGN(source->column[1]),
_MM_SHUFFLE(3, 2, 3, 2));
__m128 t2 = _mm_shuffle_ps(ALIGN(source->column[2]),
ALIGN(source->column[3]),
_MM_SHUFFLE(1, 0, 1, 0));
__m128 t3 = _mm_shuffle_ps(ALIGN(source->column[2]),
ALIGN(source->column[3]),
_MM_SHUFFLE(3, 2, 3, 2));
target->colum[0] = _mm_shuffle_ps(t0, t2, _MM_SHUFFLE(2, 0, 2, 0));
target->colum[1] = _mm_shuffle_ps(t0, t2, _MM_SHUFFLE(3, 1, 3, 1));
target->colum[2] = _mm_shuffle_ps(t1, t3, _MM_SHUFFLE(2, 0, 2, 0));
target->colum[3] = _mm_shuffle_ps(t1, t3, _MM_SHUFFLE(3, 1, 3, 1));
target->column[0] = _mm_shuffle_ps(t0, t2, _MM_SHUFFLE(2, 0, 2, 0));
target->column[1] = _mm_shuffle_ps(t0, t2, _MM_SHUFFLE(3, 1, 3, 1));
target->column[2] = _mm_shuffle_ps(t1, t3, _MM_SHUFFLE(2, 0, 2, 0));
}
SSCAPI __inline void __cdecl transpose4to3(matrix4map* source, matrix3map* target)
INTERNAL void __cdecl transpose44(__4_columnset *source, __4_columnset *target)
{
__m128 t0 = _mm_shuffle_ps(ALIGN(source->colum[0]), ALIGN(source->colum[1]), _MM_SHUFFLE(1, 0, 1, 0));
__m128 t1 = _mm_shuffle_ps(ALIGN(source->colum[0]), ALIGN(source->colum[1]), _MM_SHUFFLE(3, 2, 3, 2));
__m128 t2 = _mm_shuffle_ps(ALIGN(source->colum[2]), ALIGN(source->colum[3]), _MM_SHUFFLE(1, 0, 1, 0));
__m128 t3 = _mm_shuffle_ps(ALIGN(source->colum[2]), ALIGN(source->colum[3]), _MM_SHUFFLE(3, 2, 3, 2));
__m128 t0 = _mm_shuffle_ps(ALIGN(source->column[0]),
ALIGN(source->column[1]),
_MM_SHUFFLE(1, 0, 1, 0));
__m128 t1 = _mm_shuffle_ps(ALIGN(source->column[0]),
ALIGN(source->column[1]),
_MM_SHUFFLE(3, 2, 3, 2));
__m128 t2 = _mm_shuffle_ps(ALIGN(source->column[2]),
ALIGN(source->column[3]),
_MM_SHUFFLE(1, 0, 1, 0));
__m128 t3 = _mm_shuffle_ps(ALIGN(source->column[2]),
ALIGN(source->column[3]),
_MM_SHUFFLE(3, 2, 3, 2));
target->colum[0] = _mm_shuffle_ps(t0, t2, _MM_SHUFFLE(2, 0, 2, 0));
target->colum[1] = _mm_shuffle_ps(t0, t2, _MM_SHUFFLE(3, 1, 3, 1));
target->colum[2] = _mm_shuffle_ps(t1, t3, _MM_SHUFFLE(2, 0, 2, 0));
target->column[0] = _mm_shuffle_ps(t0, t2, _MM_SHUFFLE(2, 0, 2, 0));
target->column[1] = _mm_shuffle_ps(t0, t2, _MM_SHUFFLE(3, 1, 3, 1));
target->column[2] = _mm_shuffle_ps(t1, t3, _MM_SHUFFLE(2, 0, 2, 0));
target->column[3] = _mm_shuffle_ps(t1, t3, _MM_SHUFFLE(3, 1, 3, 1));
}
SSCAPI __inline float __cdecl det_mat4(matrix4map* matPtr, matrix4map* transpose)
INTERNAL float __cdecl det_mat4(__4_columnset *matPtr, __4_columnset *transpose)
{
__m128 mc0 = ALIGN(matPtr->colum[0]);
__m128 mc1 = ALIGN(matPtr->colum[1]);
__m128 mc2 = ALIGN(matPtr->colum[2]);
__m128 mc3 = ALIGN(matPtr->colum[3]);
__m128 mc0 = ALIGN(matPtr->column[0]);
__m128 mc1 = ALIGN(matPtr->column[1]);
__m128 mc2 = ALIGN(matPtr->column[2]);
__m128 mc3 = ALIGN(matPtr->column[3]);
__m128 cogeneration = _mm_set_ps(
det_mat3_internal(mc0, mc1, mc2),
det_mat3_internal(mc0, mc1, mc3),
det_mat3_internal(mc0, mc2, mc3),
det_mat3_internal(mc1, mc2, mc3)
);
__m128 retvec = _mm_mul_ps(ALIGN(transpose->colum[3]), cogeneration);
retvec = _mm_hsub_ps(retvec, retvec);
retvec = _mm_hadd_ps(retvec, retvec);
return -retvec.m128_f32[0];
__m128 cogeneration = _mm_set_ps(det_mat3_internal(mc0, mc1, mc2),
det_mat3_internal(mc0, mc1, mc3),
det_mat3_internal(mc0, mc2, mc3),
det_mat3_internal(mc1, mc2, mc3));
__m128 retvec = _mm_mul_ps(ALIGN(transpose->column[3]), cogeneration);
retvec = _mm_hsub_ps(retvec, retvec);
retvec = _mm_hadd_ps(retvec, retvec);
return -retvec.m128_f32[0];
}
SSCAPI __inline void __cdecl deinit_mat4(matrix4map* matPtr)
{
_aligned_free(matPtr);
}
+24
View File
@@ -0,0 +1,24 @@
#include "ssc_intrinsic.h"
#include "StgSharpC.h"
static __m128i hash_mask = { .m128i_i32 = { 31 * 31 * 31, 31 * 31, 31, 1 } };
INTERNAL int quick_string_hash(byte const *str, int const length)
{
__m128i source;
int source_length = length * 2;
if (source_length > 15) {
source = _mm_lddqu_si128((__m128i *)str);
} else {
byte buffer[16];
memcpy(buffer, str, source_length);
memset(buffer + source_length - 1, 0, 16 - source_length);
source = _mm_lddqu_si128((__m128i *)buffer);
}
__m128i ret = _mm_mullo_epi32(source, hash_mask);
ret = _mm_hadd_epi32(ret, ret);
ret = _mm_hadd_epi32(ret, ret);
return _mm_cvtsi128_si32(ret);
}
+12
View File
@@ -0,0 +1,12 @@
#ifdef _MSC_VER
#pragma once
#endif
#if _WIN32
#endif // __WIN32
+39
View File
@@ -0,0 +1,39 @@
#ifdef _MSC_VER
#pragma once
#endif
#include "xmmintrin.h"
/*
#include "GLAD/gl.h"
#include "glfw3.h"
#include "StgSharpC.h"
*/
#ifndef SSC_INTERNAL
#define SSC_INTERNAL
#ifdef _WIN32
#define WIN32_LEAN_AND_MEAN
#define SSCAPI __declspec(dllexport)
#include <windows.h>
#elif defined _LINUX_
#define SSCAPI __attribute__((dllexport))
#elif defined _APPLE_
#define SSCAPI __attribute__((visibility("default")))
#else
#define SSCAPI
#endif
#ifdef _WIN32
#define _CRT_SECURE_NO_WARNINGS 1
#endif
#define SSCDECL __cdecl
#define zeroVec _mm_setzero_ps()
#define SSCAPI_DEFINE
#define INTERNAL extern
#endif //
+70
View File
@@ -0,0 +1,70 @@
#ifdef _MSC_VER
#pragma once
#endif
#ifndef SSC_INTRIN
#define SSC_INTRIN
#include "StgSharpC.h"
#include <immintrin.h>
typedef union column_2 {
__m128 column[2];
float m[4][2];
} __2_columnset;
typedef struct column_3 {
__m128 column[3];
float m[4][3];
} __3_columnset;
typedef union column_4 {
__m128 column[4];
float m[4][4];
} __4_columnset;
typedef void (*VECTORNORMALIZEPROC)(__m128 *source, __m128 *target);
typedef void (*MATRIXTRANSPOSEPROC)(void *source, void *target);
typedef void (*MATRIXDETPROC)(void *mat, void *transpose);
#pragma region matix function
INTERNAL void normalize(__m128 *source, __m128 *target);
INTERNAL void transpose23(__2_columnset *source, __3_columnset *target);
INTERNAL void transpose24(__2_columnset *source, __4_columnset *target);
INTERNAL void transpose32(__3_columnset *source, __2_columnset *target);
INTERNAL void transpose33(__3_columnset *source, __3_columnset *target);
INTERNAL void transpose34(__3_columnset *source, __4_columnset *target);
INTERNAL float det_mat3(__3_columnset *matrix, __3_columnset *tranpose);
INTERNAL void transpose42(__4_columnset *source, __2_columnset *target);
INTERNAL void transpose43(__4_columnset *source, __3_columnset *target);
INTERNAL void transpose44(__4_columnset *matrix, __4_columnset *target);
INTERNAL float det_mat4(__4_columnset *matrix, __4_columnset *transpose);
#pragma endregion
#pragma region quick_hash
INTERNAL int quick_string_hash(byte *str, int length);
#pragma endregion
typedef struct ssc_intrinsic {
MATRIXTRANSPOSEPROC transpose_23;
MATRIXTRANSPOSEPROC transpose_24;
MATRIXTRANSPOSEPROC transpose_32;
MATRIXTRANSPOSEPROC transpose_33;
MATRIXTRANSPOSEPROC transpose_34;
MATRIXTRANSPOSEPROC transpose_42;
MATRIXTRANSPOSEPROC transpose_43;
MATRIXTRANSPOSEPROC transpose_44;
VECTORNORMALIZEPROC normalize_3;
MATRIXDETPROC det_matrix33;
MATRIXDETPROC det_matrix44;
int (*string_quick_hash)(char *str, int length);
} ssc_intrinsic;
#endif // !SSC_INTRIN
File diff suppressed because it is too large Load Diff
+29 -22
View File
@@ -1,31 +1,38 @@
#include "StgSharpC.h"
#include "ssgc_internal.h"
#include "ssc_internal.h"
SSCAPI void SSCDECL normalize(__m128* source, __m128* target)
SSCAPI void SSCDECL normalize(__m128 *source, __m128 *target)
{
// 计算source的长度的平方
__m128 a_length_sq = _mm_mul_ps(*source, *source); // 向量点乘自身
a_length_sq = _mm_add_ps(a_length_sq, _mm_shuffle_ps(a_length_sq, a_length_sq, _MM_SHUFFLE(2, 3, 0, 1)));
a_length_sq = _mm_add_ss(a_length_sq, _mm_shuffle_ps(a_length_sq, a_length_sq, _MM_SHUFFLE(0, 0, 3, 2)));
__m128 a_length_sq = _mm_mul_ps(*source, *source);
a_length_sq = _mm_add_ps(a_length_sq,
_mm_shuffle_ps(a_length_sq, a_length_sq,
_MM_SHUFFLE(2, 3, 0, 1)));
a_length_sq = _mm_add_ss(a_length_sq,
_mm_shuffle_ps(a_length_sq, a_length_sq,
_MM_SHUFFLE(0, 0, 3, 2)));
// 归一化向量source
__m128 a_inv_length = _mm_rsqrt_ps(a_length_sq); // 计算source长度的倒数平方根
*source = _mm_mul_ps(*source, a_inv_length); // 用source乘以其长度的倒数平方根得到单位向量
__m128 a_inv_length = _mm_rsqrt_ps(a_length_sq);
*source = _mm_mul_ps(*source, a_inv_length);
// 计算target与source的点积
__m128 dot_product = _mm_mul_ps(*target, *source);
dot_product = _mm_add_ps(dot_product, _mm_shuffle_ps(dot_product, dot_product, _MM_SHUFFLE(2, 3, 0, 1)));
dot_product = _mm_add_ss(dot_product, _mm_shuffle_ps(dot_product, dot_product, _MM_SHUFFLE(0, 0, 3, 2)));
__m128 dot_product = _mm_mul_ps(*target, *source);
dot_product = _mm_add_ps(dot_product,
_mm_shuffle_ps(dot_product, dot_product,
_MM_SHUFFLE(2, 3, 0, 1)));
dot_product = _mm_add_ss(dot_product,
_mm_shuffle_ps(dot_product, dot_product,
_MM_SHUFFLE(0, 0, 3, 2)));
// 从target中减去source的方向分量,使其垂直于source
__m128 b_orthogonal = _mm_sub_ps(*target, _mm_mul_ps(*source, dot_product));
__m128 b_orthogonal =
_mm_sub_ps(*target, _mm_mul_ps(*source, dot_product));
// 归一化向量b_orthogonal
__m128 b_length_sq = _mm_mul_ps(b_orthogonal, b_orthogonal);
b_length_sq = _mm_add_ps(b_length_sq, _mm_shuffle_ps(b_length_sq, b_length_sq, _MM_SHUFFLE(2, 3, 0, 1)));
b_length_sq = _mm_add_ss(b_length_sq, _mm_shuffle_ps(b_length_sq, b_length_sq, _MM_SHUFFLE(0, 0, 3, 2)));
__m128 b_inv_length = _mm_rsqrt_ps(b_length_sq);
*target = _mm_mul_ps(b_orthogonal, b_inv_length);
__m128 b_length_sq = _mm_mul_ps(b_orthogonal, b_orthogonal);
b_length_sq = _mm_add_ps(b_length_sq,
_mm_shuffle_ps(b_length_sq, b_length_sq,
_MM_SHUFFLE(2, 3, 0, 1)));
b_length_sq = _mm_add_ss(b_length_sq,
_mm_shuffle_ps(b_length_sq, b_length_sq,
_MM_SHUFFLE(0, 0, 3, 2)));
__m128 b_inv_length = _mm_rsqrt_ps(b_length_sq);
*target = _mm_mul_ps(b_orthogonal, b_inv_length);
}