Normalize all existing files to LF
This commit is contained in:
@@ -1,75 +1,75 @@
|
||||
#include "StgSharpC.h"
|
||||
#include "gl.h"
|
||||
#include "glfw3.h"
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
|
||||
extern GladGLContext *currentContext;
|
||||
extern char infolog[512];
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
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);
|
||||
}
|
||||
|
||||
SSCAPI GLFWglproc SSCDECL loadGlfuncDefault(char const *procName)
|
||||
{
|
||||
void *ret = glfwGetProcAddress(procName);
|
||||
// printf("%llu\n", (uint64_t)ret);
|
||||
if (ret == NULL) {
|
||||
strcpy_s(infolog,30, "Failed to load OpenGL api:");
|
||||
for (size_t i = 0; i < sizeof(procName); i++) {
|
||||
infolog[30 + i] = procName[i];
|
||||
}
|
||||
//printf("%s\n", infolog);
|
||||
}
|
||||
return (GLFWglproc)ret;
|
||||
}
|
||||
|
||||
SSCAPI unsigned int linkShaderProgram(GladGLContext *context, GLuint 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;
|
||||
}
|
||||
}
|
||||
|
||||
SSCAPI void SSCDECL loadImageData(char const *location, Image *out, imageLoader loader)
|
||||
{
|
||||
if (loader == NULL) {
|
||||
loader = stbi_load;
|
||||
}
|
||||
out->pixelPtr = loader(location, &(out->width), &(out->height), &(out->channel), 0);
|
||||
}
|
||||
|
||||
SSCAPI void SSCDECL unloadImageData(Image *restrict out)
|
||||
{
|
||||
free(out->pixelPtr);
|
||||
}
|
||||
|
||||
SSCAPI char *SSCDECL readLog()
|
||||
{
|
||||
infolog[511] = '\0';
|
||||
return infolog;
|
||||
}
|
||||
#include "StgSharpC.h"
|
||||
#include "gl.h"
|
||||
#include "glfw3.h"
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
|
||||
extern GladGLContext *currentContext;
|
||||
extern char infolog[512];
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
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);
|
||||
}
|
||||
|
||||
SSCAPI GLFWglproc SSCDECL loadGlfuncDefault(char const *procName)
|
||||
{
|
||||
void *ret = glfwGetProcAddress(procName);
|
||||
// printf("%llu\n", (uint64_t)ret);
|
||||
if (ret == NULL) {
|
||||
strcpy_s(infolog,30, "Failed to load OpenGL api:");
|
||||
for (size_t i = 0; i < sizeof(procName); i++) {
|
||||
infolog[30 + i] = procName[i];
|
||||
}
|
||||
//printf("%s\n", infolog);
|
||||
}
|
||||
return (GLFWglproc)ret;
|
||||
}
|
||||
|
||||
SSCAPI unsigned int linkShaderProgram(GladGLContext *context, GLuint 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;
|
||||
}
|
||||
}
|
||||
|
||||
SSCAPI void SSCDECL loadImageData(char const *location, Image *out, imageLoader loader)
|
||||
{
|
||||
if (loader == NULL) {
|
||||
loader = stbi_load;
|
||||
}
|
||||
out->pixelPtr = loader(location, &(out->width), &(out->height), &(out->channel), 0);
|
||||
}
|
||||
|
||||
SSCAPI void SSCDECL unloadImageData(Image *restrict out)
|
||||
{
|
||||
free(out->pixelPtr);
|
||||
}
|
||||
|
||||
SSCAPI char *SSCDECL readLog()
|
||||
{
|
||||
infolog[511] = '\0';
|
||||
return infolog;
|
||||
}
|
||||
|
||||
@@ -1,47 +1,47 @@
|
||||
#include "StgSharpNative.h"
|
||||
#include "sn_intrinsic.matkernel.h"
|
||||
#include <stdint.h>
|
||||
|
||||
#ifdef _WIN32
|
||||
|
||||
/* Define and initialize a global zero kernel aligned to 64 bytes for universal ISA usage */
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
__declspec(align(64)) sn_zero_kernel_u64 SN_ZERO_KERNEL;
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
static void init_zero_kernel(void)
|
||||
{
|
||||
for (int c = 0; c < 4; ++c) {
|
||||
for (int r = 0; r < 4; ++r) {
|
||||
SN_ZERO_KERNEL.m[r][c] = 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
BOOL APIENTRY DllMain(HMODULE hModule, DWORD ul_reason_for_call, LPVOID lpReserved)
|
||||
{
|
||||
switch (ul_reason_for_call) {
|
||||
case DLL_PROCESS_ATTACH:
|
||||
init_zero_kernel();
|
||||
return 1;
|
||||
case DLL_THREAD_ATTACH:
|
||||
return 1;
|
||||
case DLL_THREAD_DETACH:
|
||||
return 1;
|
||||
case DLL_PROCESS_DETACH:
|
||||
return 1;
|
||||
break;
|
||||
}
|
||||
return TRUE;
|
||||
}
|
||||
#else
|
||||
attribute((constructor)) void DllMain()
|
||||
{
|
||||
init_zero_kernel();
|
||||
}
|
||||
|
||||
#endif // _WIN32
|
||||
#include "StgSharpNative.h"
|
||||
#include "sn_intrinsic.matkernel.h"
|
||||
#include <stdint.h>
|
||||
|
||||
#ifdef _WIN32
|
||||
|
||||
/* Define and initialize a global zero kernel aligned to 64 bytes for universal ISA usage */
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
__declspec(align(64)) sn_zero_kernel_u64 SN_ZERO_KERNEL;
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
static void init_zero_kernel(void)
|
||||
{
|
||||
for (int c = 0; c < 4; ++c) {
|
||||
for (int r = 0; r < 4; ++r) {
|
||||
SN_ZERO_KERNEL.m[r][c] = 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
BOOL APIENTRY DllMain(HMODULE hModule, DWORD ul_reason_for_call, LPVOID lpReserved)
|
||||
{
|
||||
switch (ul_reason_for_call) {
|
||||
case DLL_PROCESS_ATTACH:
|
||||
init_zero_kernel();
|
||||
return 1;
|
||||
case DLL_THREAD_ATTACH:
|
||||
return 1;
|
||||
case DLL_THREAD_DETACH:
|
||||
return 1;
|
||||
case DLL_PROCESS_DETACH:
|
||||
return 1;
|
||||
break;
|
||||
}
|
||||
return TRUE;
|
||||
}
|
||||
#else
|
||||
attribute((constructor)) void DllMain()
|
||||
{
|
||||
init_zero_kernel();
|
||||
}
|
||||
|
||||
#endif // _WIN32
|
||||
|
||||
+123
-123
@@ -1,123 +1,123 @@
|
||||
#include "StgSharpNative.h"
|
||||
#include "glfw_function.h"
|
||||
#include <string.h>
|
||||
|
||||
SN_API void SN_DECL load_glfw_functions(GLFWFunctionTable *table)
|
||||
{
|
||||
table->glfwCreateCursor = glfwCreateCursor;
|
||||
table->glfwCreateStandardCursor = glfwCreateStandardCursor;
|
||||
table->glfwCreateWindow = glfwCreateWindow;
|
||||
table->glfwDefaultWindowHints = glfwDefaultWindowHints;
|
||||
table->glfwDestroyCursor = glfwDestroyCursor;
|
||||
table->glfwDestroyWindow = glfwDestroyWindow;
|
||||
table->glfwExtensionSupported = glfwExtensionSupported;
|
||||
table->glfwFocusWindow = glfwFocusWindow;
|
||||
table->glfwGetClipboardString = glfwGetClipboardString;
|
||||
table->glfwGetCurrentContext = glfwGetCurrentContext;
|
||||
table->glfwGetCursorPos = glfwGetCursorPos;
|
||||
table->glfwGetError = glfwGetError;
|
||||
table->glfwGetFrameBufferSize = glfwGetFramebufferSize;
|
||||
table->glfwGetGamepadName = glfwGetGamepadName;
|
||||
table->glfwGetGamepadState = glfwGetGamepadState;
|
||||
table->glfwGetGammaRamp = glfwGetGammaRamp;
|
||||
table->glfwGetInputMode = glfwGetInputMode;
|
||||
table->glfwGetJoystickAxes = glfwGetJoystickAxes;
|
||||
table->glfwGetJoystickButtons = glfwGetJoystickButtons;
|
||||
table->glfwGetJoystickGUID = glfwGetJoystickGUID;
|
||||
table->glfwGetJoystickHats = glfwGetJoystickHats;
|
||||
table->glfwGetJoystickName = glfwGetJoystickName;
|
||||
table->glfwGetJoystickUserPointer = glfwGetJoystickUserPointer;
|
||||
table->glfwGetKey = glfwGetKey;
|
||||
table->glfwGetKeyName = glfwGetKeyName;
|
||||
table->glfwGetKeyScancode = glfwGetKeyScancode;
|
||||
table->glfwGetMonitorContentScale = glfwGetMonitorContentScale;
|
||||
table->glfwGetMonitorName = glfwGetMonitorName;
|
||||
table->glfwGetMonitorPhysicalSize = glfwGetMonitorPhysicalSize;
|
||||
table->glfwGetMonitorPos = glfwGetMonitorPos;
|
||||
table->glfwGetMonitors = glfwGetMonitors;
|
||||
table->glfwGetMonitorUserPointer = glfwGetMonitorUserPointer;
|
||||
table->glfwGetMonitorWorkarea = glfwGetMonitorWorkarea;
|
||||
table->glfwGetMouseButton = glfwGetMouseButton;
|
||||
table->glfwGetPrimaryMonitor = glfwGetPrimaryMonitor;
|
||||
table->glfwGetProcAddress = glfwGetProcAddress;
|
||||
table->glfwGetRequiredInstanceExtensions = glfwGetRequiredInstanceExtensions;
|
||||
table->glfwGetTime = glfwGetTime;
|
||||
table->glfwGetTimerFrequency = glfwGetTimerFrequency;
|
||||
table->glfwGetTimerValue = glfwGetTimerValue;
|
||||
table->glfwGetVersion = glfwGetVersion;
|
||||
table->glfwGetVersionString = glfwGetVersionString;
|
||||
table->glfwGetVideoMode = glfwGetVideoMode;
|
||||
table->glfwGetVideoModes = glfwGetVideoModes;
|
||||
table->glfwGetWindowAttrib = glfwGetWindowAttrib;
|
||||
table->glfwGetWindowContentScale = glfwGetWindowContentScale;
|
||||
table->glfwGetWindowFrameSize = glfwGetWindowFrameSize;
|
||||
table->glfwGetWindowMonitor = glfwGetWindowMonitor;
|
||||
table->glfwGetWindowOpacity = glfwGetWindowOpacity;
|
||||
table->glfwGetWindowPos = glfwGetWindowPos;
|
||||
table->glfwGetWindowSize = glfwGetWindowSize;
|
||||
table->glfwGetWindowUserPointer = glfwGetWindowUserPointer;
|
||||
table->glfwHideWindow = glfwHideWindow;
|
||||
table->glfwIconifyWindow = glfwIconifyWindow;
|
||||
table->glfwInit = glfwInit;
|
||||
table->glfwInitHint = glfwInitHint;
|
||||
table->glfwJoystickIsGamePad = glfwJoystickIsGamepad;
|
||||
table->glfwJoystickPresent = glfwJoystickPresent;
|
||||
table->glfwMakeContextCurrent = glfwMakeContextCurrent;
|
||||
table->glfwMaximizeWindow = glfwMaximizeWindow;
|
||||
table->glfwPollEvents = glfwPollEvents;
|
||||
table->glfwPostEmptyEvent = glfwPostEmptyEvent;
|
||||
table->glfwRawMouseMotionSupported = glfwRawMouseMotionSupported;
|
||||
table->glfwRequestWindowAttention = glfwRequestWindowAttention;
|
||||
table->glfwRestoreWindow = glfwRestoreWindow;
|
||||
table->glfwSetCharCallback = glfwSetCharCallback;
|
||||
table->glfwSetCharModsCallback = glfwSetCharModsCallback;
|
||||
table->glfwSetClipboardString = glfwSetClipboardString;
|
||||
table->glfwSetCursor = glfwSetCursor;
|
||||
table->glfwSetCursorEnterCallback = glfwSetCursorEnterCallback;
|
||||
table->glfwSetCursorPos = glfwSetCursorPos;
|
||||
table->glfwSetCursorPosCallback = glfwSetCursorPosCallback;
|
||||
table->glfwSetDropCallback = glfwSetDropCallback;
|
||||
table->glfwSetErrorCallback = glfwSetErrorCallback;
|
||||
table->glfwSetFramebufferSizeCallback = glfwSetFramebufferSizeCallback;
|
||||
table->glfwSetGamma = glfwSetGamma;
|
||||
table->glfwSetGammaRamp = glfwSetGammaRamp;
|
||||
table->glfwSetInputMode = glfwSetInputMode;
|
||||
table->glfwSetJoystickCallback = glfwSetJoystickCallback;
|
||||
table->glfwSetJoystickUserPointer = glfwSetJoystickUserPointer;
|
||||
table->glfwSetKeyCallback = glfwSetKeyCallback;
|
||||
table->glfwSetMonitorCallback = glfwSetMonitorCallback;
|
||||
table->glfwSetMonitorUserPointer = glfwSetMonitorUserPointer;
|
||||
table->glfwSetMouseButtonCallback = glfwSetMouseButtonCallback;
|
||||
table->glfwSetScrollCallback = glfwSetScrollCallback;
|
||||
table->glfwSetTime = glfwSetTime;
|
||||
table->glfwSetWindowAspectRatio = glfwSetWindowAspectRatio;
|
||||
table->glfwSetWindowAttrib = glfwSetWindowAttrib;
|
||||
table->glfwSetWindowCloseCallback = glfwSetWindowCloseCallback;
|
||||
table->glfwSetWindowContentScaleCallback = glfwSetWindowContentScaleCallback;
|
||||
table->glfwSetWindowFocusCallback = glfwSetWindowFocusCallback;
|
||||
table->glfwSetWindowIcon = glfwSetWindowIcon;
|
||||
table->glfwSetWindowIconifyCallback = glfwSetWindowIconifyCallback;
|
||||
table->glfwSetWindowMaximizeCallback = glfwSetWindowMaximizeCallback;
|
||||
table->glfwSetWindowMonitor = glfwSetWindowMonitor;
|
||||
table->glfwSetWindowOpacity = glfwSetWindowOpacity;
|
||||
table->glfwSetWindowPos = glfwSetWindowPos;
|
||||
table->glfwSetWindowPosCallback = glfwSetWindowPosCallback;
|
||||
table->glfwSetWindowRefreshCallback = glfwSetWindowRefreshCallback;
|
||||
table->glfwSetWindowShouldClose = glfwSetWindowShouldClose;
|
||||
table->glfwSetWindowSize = glfwSetWindowSize;
|
||||
table->glfwSetWindowSizeCallback = glfwSetWindowSizeCallback;
|
||||
table->glfwSetWindowSizeLimits = glfwSetWindowSizeLimits;
|
||||
table->glfwSetWindowTitle = glfwSetWindowTitle;
|
||||
table->glfwSetWindowUserPointer = glfwSetWindowUserPointer;
|
||||
table->glfwShowWindow = glfwShowWindow;
|
||||
table->glfwSwapBuffers = glfwSwapBuffers;
|
||||
table->glfwSwapInterval = glfwSwapInterval;
|
||||
table->glfwTerminate = glfwTerminate;
|
||||
table->glfwUpdateGamePadMappings = glfwUpdateGamepadMappings;
|
||||
table->glfwVulkanSupported = glfwVulkanSupported;
|
||||
table->glfwWaitEvents = glfwWaitEvents;
|
||||
table->glfwWaitEventsTimeout = glfwWaitEventsTimeout;
|
||||
table->glfwWindowHint = glfwWindowHint;
|
||||
table->glfwWindowHintString = glfwWindowHintString;
|
||||
table->glfwWindowShouldClose = glfwWindowShouldClose;
|
||||
}
|
||||
#include "StgSharpNative.h"
|
||||
#include "glfw_function.h"
|
||||
#include <string.h>
|
||||
|
||||
SN_API void SN_DECL load_glfw_functions(GLFWFunctionTable *table)
|
||||
{
|
||||
table->glfwCreateCursor = glfwCreateCursor;
|
||||
table->glfwCreateStandardCursor = glfwCreateStandardCursor;
|
||||
table->glfwCreateWindow = glfwCreateWindow;
|
||||
table->glfwDefaultWindowHints = glfwDefaultWindowHints;
|
||||
table->glfwDestroyCursor = glfwDestroyCursor;
|
||||
table->glfwDestroyWindow = glfwDestroyWindow;
|
||||
table->glfwExtensionSupported = glfwExtensionSupported;
|
||||
table->glfwFocusWindow = glfwFocusWindow;
|
||||
table->glfwGetClipboardString = glfwGetClipboardString;
|
||||
table->glfwGetCurrentContext = glfwGetCurrentContext;
|
||||
table->glfwGetCursorPos = glfwGetCursorPos;
|
||||
table->glfwGetError = glfwGetError;
|
||||
table->glfwGetFrameBufferSize = glfwGetFramebufferSize;
|
||||
table->glfwGetGamepadName = glfwGetGamepadName;
|
||||
table->glfwGetGamepadState = glfwGetGamepadState;
|
||||
table->glfwGetGammaRamp = glfwGetGammaRamp;
|
||||
table->glfwGetInputMode = glfwGetInputMode;
|
||||
table->glfwGetJoystickAxes = glfwGetJoystickAxes;
|
||||
table->glfwGetJoystickButtons = glfwGetJoystickButtons;
|
||||
table->glfwGetJoystickGUID = glfwGetJoystickGUID;
|
||||
table->glfwGetJoystickHats = glfwGetJoystickHats;
|
||||
table->glfwGetJoystickName = glfwGetJoystickName;
|
||||
table->glfwGetJoystickUserPointer = glfwGetJoystickUserPointer;
|
||||
table->glfwGetKey = glfwGetKey;
|
||||
table->glfwGetKeyName = glfwGetKeyName;
|
||||
table->glfwGetKeyScancode = glfwGetKeyScancode;
|
||||
table->glfwGetMonitorContentScale = glfwGetMonitorContentScale;
|
||||
table->glfwGetMonitorName = glfwGetMonitorName;
|
||||
table->glfwGetMonitorPhysicalSize = glfwGetMonitorPhysicalSize;
|
||||
table->glfwGetMonitorPos = glfwGetMonitorPos;
|
||||
table->glfwGetMonitors = glfwGetMonitors;
|
||||
table->glfwGetMonitorUserPointer = glfwGetMonitorUserPointer;
|
||||
table->glfwGetMonitorWorkarea = glfwGetMonitorWorkarea;
|
||||
table->glfwGetMouseButton = glfwGetMouseButton;
|
||||
table->glfwGetPrimaryMonitor = glfwGetPrimaryMonitor;
|
||||
table->glfwGetProcAddress = glfwGetProcAddress;
|
||||
table->glfwGetRequiredInstanceExtensions = glfwGetRequiredInstanceExtensions;
|
||||
table->glfwGetTime = glfwGetTime;
|
||||
table->glfwGetTimerFrequency = glfwGetTimerFrequency;
|
||||
table->glfwGetTimerValue = glfwGetTimerValue;
|
||||
table->glfwGetVersion = glfwGetVersion;
|
||||
table->glfwGetVersionString = glfwGetVersionString;
|
||||
table->glfwGetVideoMode = glfwGetVideoMode;
|
||||
table->glfwGetVideoModes = glfwGetVideoModes;
|
||||
table->glfwGetWindowAttrib = glfwGetWindowAttrib;
|
||||
table->glfwGetWindowContentScale = glfwGetWindowContentScale;
|
||||
table->glfwGetWindowFrameSize = glfwGetWindowFrameSize;
|
||||
table->glfwGetWindowMonitor = glfwGetWindowMonitor;
|
||||
table->glfwGetWindowOpacity = glfwGetWindowOpacity;
|
||||
table->glfwGetWindowPos = glfwGetWindowPos;
|
||||
table->glfwGetWindowSize = glfwGetWindowSize;
|
||||
table->glfwGetWindowUserPointer = glfwGetWindowUserPointer;
|
||||
table->glfwHideWindow = glfwHideWindow;
|
||||
table->glfwIconifyWindow = glfwIconifyWindow;
|
||||
table->glfwInit = glfwInit;
|
||||
table->glfwInitHint = glfwInitHint;
|
||||
table->glfwJoystickIsGamePad = glfwJoystickIsGamepad;
|
||||
table->glfwJoystickPresent = glfwJoystickPresent;
|
||||
table->glfwMakeContextCurrent = glfwMakeContextCurrent;
|
||||
table->glfwMaximizeWindow = glfwMaximizeWindow;
|
||||
table->glfwPollEvents = glfwPollEvents;
|
||||
table->glfwPostEmptyEvent = glfwPostEmptyEvent;
|
||||
table->glfwRawMouseMotionSupported = glfwRawMouseMotionSupported;
|
||||
table->glfwRequestWindowAttention = glfwRequestWindowAttention;
|
||||
table->glfwRestoreWindow = glfwRestoreWindow;
|
||||
table->glfwSetCharCallback = glfwSetCharCallback;
|
||||
table->glfwSetCharModsCallback = glfwSetCharModsCallback;
|
||||
table->glfwSetClipboardString = glfwSetClipboardString;
|
||||
table->glfwSetCursor = glfwSetCursor;
|
||||
table->glfwSetCursorEnterCallback = glfwSetCursorEnterCallback;
|
||||
table->glfwSetCursorPos = glfwSetCursorPos;
|
||||
table->glfwSetCursorPosCallback = glfwSetCursorPosCallback;
|
||||
table->glfwSetDropCallback = glfwSetDropCallback;
|
||||
table->glfwSetErrorCallback = glfwSetErrorCallback;
|
||||
table->glfwSetFramebufferSizeCallback = glfwSetFramebufferSizeCallback;
|
||||
table->glfwSetGamma = glfwSetGamma;
|
||||
table->glfwSetGammaRamp = glfwSetGammaRamp;
|
||||
table->glfwSetInputMode = glfwSetInputMode;
|
||||
table->glfwSetJoystickCallback = glfwSetJoystickCallback;
|
||||
table->glfwSetJoystickUserPointer = glfwSetJoystickUserPointer;
|
||||
table->glfwSetKeyCallback = glfwSetKeyCallback;
|
||||
table->glfwSetMonitorCallback = glfwSetMonitorCallback;
|
||||
table->glfwSetMonitorUserPointer = glfwSetMonitorUserPointer;
|
||||
table->glfwSetMouseButtonCallback = glfwSetMouseButtonCallback;
|
||||
table->glfwSetScrollCallback = glfwSetScrollCallback;
|
||||
table->glfwSetTime = glfwSetTime;
|
||||
table->glfwSetWindowAspectRatio = glfwSetWindowAspectRatio;
|
||||
table->glfwSetWindowAttrib = glfwSetWindowAttrib;
|
||||
table->glfwSetWindowCloseCallback = glfwSetWindowCloseCallback;
|
||||
table->glfwSetWindowContentScaleCallback = glfwSetWindowContentScaleCallback;
|
||||
table->glfwSetWindowFocusCallback = glfwSetWindowFocusCallback;
|
||||
table->glfwSetWindowIcon = glfwSetWindowIcon;
|
||||
table->glfwSetWindowIconifyCallback = glfwSetWindowIconifyCallback;
|
||||
table->glfwSetWindowMaximizeCallback = glfwSetWindowMaximizeCallback;
|
||||
table->glfwSetWindowMonitor = glfwSetWindowMonitor;
|
||||
table->glfwSetWindowOpacity = glfwSetWindowOpacity;
|
||||
table->glfwSetWindowPos = glfwSetWindowPos;
|
||||
table->glfwSetWindowPosCallback = glfwSetWindowPosCallback;
|
||||
table->glfwSetWindowRefreshCallback = glfwSetWindowRefreshCallback;
|
||||
table->glfwSetWindowShouldClose = glfwSetWindowShouldClose;
|
||||
table->glfwSetWindowSize = glfwSetWindowSize;
|
||||
table->glfwSetWindowSizeCallback = glfwSetWindowSizeCallback;
|
||||
table->glfwSetWindowSizeLimits = glfwSetWindowSizeLimits;
|
||||
table->glfwSetWindowTitle = glfwSetWindowTitle;
|
||||
table->glfwSetWindowUserPointer = glfwSetWindowUserPointer;
|
||||
table->glfwShowWindow = glfwShowWindow;
|
||||
table->glfwSwapBuffers = glfwSwapBuffers;
|
||||
table->glfwSwapInterval = glfwSwapInterval;
|
||||
table->glfwTerminate = glfwTerminate;
|
||||
table->glfwUpdateGamePadMappings = glfwUpdateGamepadMappings;
|
||||
table->glfwVulkanSupported = glfwVulkanSupported;
|
||||
table->glfwWaitEvents = glfwWaitEvents;
|
||||
table->glfwWaitEventsTimeout = glfwWaitEventsTimeout;
|
||||
table->glfwWindowHint = glfwWindowHint;
|
||||
table->glfwWindowHintString = glfwWindowHintString;
|
||||
table->glfwWindowShouldClose = glfwWindowShouldClose;
|
||||
}
|
||||
|
||||
@@ -1,127 +1,127 @@
|
||||
#include "sn_target.h"
|
||||
|
||||
#if SN_IS_ARCH(SN_ARCH_X86_64)
|
||||
|
||||
#include "StgSharpNative.h"
|
||||
#include "sn_intrinsic.h"
|
||||
#include "sn_intrinsic.std.h"
|
||||
#include "sn_intrinsic.context.x86.h"
|
||||
|
||||
#if defined(_MSC_VER) && !defined(__clang__)
|
||||
#include <intrin.h>
|
||||
#include <isa_availability.h>
|
||||
#else
|
||||
#include <cpuid.h>
|
||||
#endif // _MSC_VER
|
||||
|
||||
PRIVATE void load_intrinsic_sse(sn_intrinsic *context, SIMDID id);
|
||||
PRIVATE void load_intrinsic_avx(sn_intrinsic *context, SIMDID id);
|
||||
PRIVATE void load_intrinsic_512(sn_intrinsic *context, SIMDID id);
|
||||
|
||||
SN_API void load_intrinsic_function(void *intrinsic_context, uint64_t id)
|
||||
{
|
||||
sn_null_assert(intrinsic_context);
|
||||
|
||||
SIMDID simdid;
|
||||
if (id) {
|
||||
simdid.mask = id;
|
||||
} else {
|
||||
simdid = sn_get_simd_level_global();
|
||||
}
|
||||
|
||||
sn_intrinsic *context = (sn_intrinsic *)intrinsic_context;
|
||||
|
||||
switch (simdid.make_byte[1]) {
|
||||
case SIMDID_MAIN_LVL_SSE:
|
||||
load_intrinsic_sse(context, simdid);
|
||||
break;
|
||||
case SIMDID_MAIN_LVL_AVX2:
|
||||
load_intrinsic_avx(context, simdid);
|
||||
break;
|
||||
case SIMDID_MAIN_LVL_AVX512:
|
||||
case SIMDID_MAIN_LVL_AMX:
|
||||
case SIMDID_MAIN_LVL_AVX10:
|
||||
load_intrinsic_512(context, simdid);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
void load_intrinsic_sse(sn_intrinsic *context, SIMDID id)
|
||||
{
|
||||
context->city_hash_simplify = city_hash_simplify_sse;
|
||||
context->factorial_simd = factorial_simd_sse;
|
||||
|
||||
context->mat_mk[F32].add = MK_PROC_NAME_STD(float, sse, , add);
|
||||
context->mat_mk[F32].fill = MK_PROC_NAME_STD(float, sse, , fill);
|
||||
context->mat_mk[F32].scalar_mul = MK_PROC_NAME_STD(float, sse, , scalar_mul);
|
||||
context->mat_mk[F32].sub = MK_PROC_NAME_STD(float, sse, , sub);
|
||||
context->mat_mk[F32].transpose = MK_PROC_NAME_STD(float, sse, , transpose);
|
||||
context->mat_mk[F32].fma = MK_PROC_NAME_STD(float, sse, , fma);
|
||||
context->mat_mk[F32].pivot = NULL;
|
||||
|
||||
context->mat_mk[F64].add = MK_PROC_NAME_STD(double, sse, , add);
|
||||
context->mat_mk[F64].fill = MK_PROC_NAME_STD(double, sse, , fill);
|
||||
context->mat_mk[F64].scalar_mul = MK_PROC_NAME_STD(double, sse, , scalar_mul);
|
||||
context->mat_mk[F64].sub = MK_PROC_NAME_STD(double, sse, , sub);
|
||||
context->mat_mk[F64].transpose = NULL;
|
||||
context->mat_mk[F64].fma = MK_PROC_NAME_STD(double, sse, , fma);
|
||||
context->mat_mk[F64].pivot = NULL;
|
||||
|
||||
context->vec_f32_normalize_3 = f32_normalize;
|
||||
}
|
||||
|
||||
void load_intrinsic_avx(sn_intrinsic *context, SIMDID id)
|
||||
{
|
||||
char avx_seg = id.make_byte[5];
|
||||
char is_fma = (avx_seg & SIMDID_AVX_FMA) != 0;
|
||||
char is_f16c = (avx_seg & SIMDID_AVX_F16C) != 0;
|
||||
|
||||
context->city_hash_simplify = city_hash_simplify_sse;
|
||||
context->factorial_simd = factorial_simd_sse;
|
||||
|
||||
context->mat_mk[F32].add = MK_PROC_NAME_STD(float, avx, , add);
|
||||
context->mat_mk[F32].fill = MK_PROC_NAME_STD(float, avx, , fill);
|
||||
context->mat_mk[F32].scalar_mul = MK_PROC_NAME_STD(float, avx, , scalar_mul);
|
||||
context->mat_mk[F32].sub = MK_PROC_NAME_STD(float, avx, , sub);
|
||||
context->mat_mk[F32].transpose = MK_PROC_NAME_STD(float, avx, , transpose);
|
||||
context->mat_mk[F32].fma = is_fma ? MK_PROC_NAME_STD(float, avx, , fma) :
|
||||
MK_PROC_NAME_STD(float, avx, _fma, fma);
|
||||
context->mat_mk[F32].pivot = NULL;
|
||||
|
||||
context->mat_mk[F64].add = MK_PROC_NAME_STD(double, avx, , add);
|
||||
context->mat_mk[F64].fill = MK_PROC_NAME_STD(double, avx, , fill);
|
||||
context->mat_mk[F64].scalar_mul = MK_PROC_NAME_STD(double, avx, , scalar_mul);
|
||||
context->mat_mk[F64].sub = MK_PROC_NAME_STD(double, avx, , sub);
|
||||
context->mat_mk[F64].transpose = NULL;
|
||||
context->mat_mk[F64].fma = is_fma ? MK_PROC_NAME_STD(double, avx, , fma) :
|
||||
MK_PROC_NAME_STD(double, avx, _fma, fma);
|
||||
context->mat_mk[F64].pivot = NULL;
|
||||
|
||||
context->vec_f32_normalize_3 = f32_normalize;
|
||||
}
|
||||
|
||||
void load_intrinsic_512(sn_intrinsic *context, SIMDID id)
|
||||
{
|
||||
context->city_hash_simplify = city_hash_simplify_sse;
|
||||
context->factorial_simd = factorial_simd_sse;
|
||||
|
||||
context->mat_mk[F32].add = MK_PROC_NAME_STD(float, 512, , add);
|
||||
context->mat_mk[F32].fill = MK_PROC_NAME_STD(float, 512, , fill);
|
||||
context->mat_mk[F32].scalar_mul = MK_PROC_NAME_STD(float, 512, , scalar_mul);
|
||||
context->mat_mk[F32].sub = MK_PROC_NAME_STD(float, 512, , sub);
|
||||
context->mat_mk[F32].transpose = MK_PROC_NAME_STD(float, 512, , transpose);
|
||||
context->mat_mk[F32].fma = MK_PROC_NAME_STD(float, 512, , fma);
|
||||
context->mat_mk[F32].pivot = NULL;
|
||||
|
||||
context->mat_mk[F64].add = MK_PROC_NAME_STD(double, 512, , add);
|
||||
context->mat_mk[F64].fill = MK_PROC_NAME_STD(double, 512, , fill);
|
||||
context->mat_mk[F64].scalar_mul = MK_PROC_NAME_STD(double, 512, , scalar_mul);
|
||||
context->mat_mk[F64].sub = MK_PROC_NAME_STD(double, 512, , sub);
|
||||
context->mat_mk[F64].transpose = NULL;
|
||||
context->mat_mk[F64].fma = MK_PROC_NAME_STD(double, 512, , fma);
|
||||
context->mat_mk[F64].pivot = NULL;
|
||||
|
||||
context->vec_f32_normalize_3 = f32_normalize;
|
||||
}
|
||||
|
||||
#endif
|
||||
#include "sn_target.h"
|
||||
|
||||
#if SN_IS_ARCH(SN_ARCH_X86_64)
|
||||
|
||||
#include "StgSharpNative.h"
|
||||
#include "sn_intrinsic.h"
|
||||
#include "sn_intrinsic.std.h"
|
||||
#include "sn_intrinsic.context.x86.h"
|
||||
|
||||
#if defined(_MSC_VER) && !defined(__clang__)
|
||||
#include <intrin.h>
|
||||
#include <isa_availability.h>
|
||||
#else
|
||||
#include <cpuid.h>
|
||||
#endif // _MSC_VER
|
||||
|
||||
PRIVATE void load_intrinsic_sse(sn_intrinsic *context, SIMDID id);
|
||||
PRIVATE void load_intrinsic_avx(sn_intrinsic *context, SIMDID id);
|
||||
PRIVATE void load_intrinsic_512(sn_intrinsic *context, SIMDID id);
|
||||
|
||||
SN_API void load_intrinsic_function(void *intrinsic_context, uint64_t id)
|
||||
{
|
||||
sn_null_assert(intrinsic_context);
|
||||
|
||||
SIMDID simdid;
|
||||
if (id) {
|
||||
simdid.mask = id;
|
||||
} else {
|
||||
simdid = sn_get_simd_level_global();
|
||||
}
|
||||
|
||||
sn_intrinsic *context = (sn_intrinsic *)intrinsic_context;
|
||||
|
||||
switch (simdid.make_byte[1]) {
|
||||
case SIMDID_MAIN_LVL_SSE:
|
||||
load_intrinsic_sse(context, simdid);
|
||||
break;
|
||||
case SIMDID_MAIN_LVL_AVX2:
|
||||
load_intrinsic_avx(context, simdid);
|
||||
break;
|
||||
case SIMDID_MAIN_LVL_AVX512:
|
||||
case SIMDID_MAIN_LVL_AMX:
|
||||
case SIMDID_MAIN_LVL_AVX10:
|
||||
load_intrinsic_512(context, simdid);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
void load_intrinsic_sse(sn_intrinsic *context, SIMDID id)
|
||||
{
|
||||
context->city_hash_simplify = city_hash_simplify_sse;
|
||||
context->factorial_simd = factorial_simd_sse;
|
||||
|
||||
context->mat_mk[F32].add = MK_PROC_NAME_STD(float, sse, , add);
|
||||
context->mat_mk[F32].fill = MK_PROC_NAME_STD(float, sse, , fill);
|
||||
context->mat_mk[F32].scalar_mul = MK_PROC_NAME_STD(float, sse, , scalar_mul);
|
||||
context->mat_mk[F32].sub = MK_PROC_NAME_STD(float, sse, , sub);
|
||||
context->mat_mk[F32].transpose = MK_PROC_NAME_STD(float, sse, , transpose);
|
||||
context->mat_mk[F32].fma = MK_PROC_NAME_STD(float, sse, , fma);
|
||||
context->mat_mk[F32].pivot = NULL;
|
||||
|
||||
context->mat_mk[F64].add = MK_PROC_NAME_STD(double, sse, , add);
|
||||
context->mat_mk[F64].fill = MK_PROC_NAME_STD(double, sse, , fill);
|
||||
context->mat_mk[F64].scalar_mul = MK_PROC_NAME_STD(double, sse, , scalar_mul);
|
||||
context->mat_mk[F64].sub = MK_PROC_NAME_STD(double, sse, , sub);
|
||||
context->mat_mk[F64].transpose = NULL;
|
||||
context->mat_mk[F64].fma = MK_PROC_NAME_STD(double, sse, , fma);
|
||||
context->mat_mk[F64].pivot = NULL;
|
||||
|
||||
context->vec_f32_normalize_3 = f32_normalize;
|
||||
}
|
||||
|
||||
void load_intrinsic_avx(sn_intrinsic *context, SIMDID id)
|
||||
{
|
||||
char avx_seg = id.make_byte[5];
|
||||
char is_fma = (avx_seg & SIMDID_AVX_FMA) != 0;
|
||||
char is_f16c = (avx_seg & SIMDID_AVX_F16C) != 0;
|
||||
|
||||
context->city_hash_simplify = city_hash_simplify_sse;
|
||||
context->factorial_simd = factorial_simd_sse;
|
||||
|
||||
context->mat_mk[F32].add = MK_PROC_NAME_STD(float, avx, , add);
|
||||
context->mat_mk[F32].fill = MK_PROC_NAME_STD(float, avx, , fill);
|
||||
context->mat_mk[F32].scalar_mul = MK_PROC_NAME_STD(float, avx, , scalar_mul);
|
||||
context->mat_mk[F32].sub = MK_PROC_NAME_STD(float, avx, , sub);
|
||||
context->mat_mk[F32].transpose = MK_PROC_NAME_STD(float, avx, , transpose);
|
||||
context->mat_mk[F32].fma = is_fma ? MK_PROC_NAME_STD(float, avx, , fma) :
|
||||
MK_PROC_NAME_STD(float, avx, _fma, fma);
|
||||
context->mat_mk[F32].pivot = NULL;
|
||||
|
||||
context->mat_mk[F64].add = MK_PROC_NAME_STD(double, avx, , add);
|
||||
context->mat_mk[F64].fill = MK_PROC_NAME_STD(double, avx, , fill);
|
||||
context->mat_mk[F64].scalar_mul = MK_PROC_NAME_STD(double, avx, , scalar_mul);
|
||||
context->mat_mk[F64].sub = MK_PROC_NAME_STD(double, avx, , sub);
|
||||
context->mat_mk[F64].transpose = NULL;
|
||||
context->mat_mk[F64].fma = is_fma ? MK_PROC_NAME_STD(double, avx, , fma) :
|
||||
MK_PROC_NAME_STD(double, avx, _fma, fma);
|
||||
context->mat_mk[F64].pivot = NULL;
|
||||
|
||||
context->vec_f32_normalize_3 = f32_normalize;
|
||||
}
|
||||
|
||||
void load_intrinsic_512(sn_intrinsic *context, SIMDID id)
|
||||
{
|
||||
context->city_hash_simplify = city_hash_simplify_sse;
|
||||
context->factorial_simd = factorial_simd_sse;
|
||||
|
||||
context->mat_mk[F32].add = MK_PROC_NAME_STD(float, 512, , add);
|
||||
context->mat_mk[F32].fill = MK_PROC_NAME_STD(float, 512, , fill);
|
||||
context->mat_mk[F32].scalar_mul = MK_PROC_NAME_STD(float, 512, , scalar_mul);
|
||||
context->mat_mk[F32].sub = MK_PROC_NAME_STD(float, 512, , sub);
|
||||
context->mat_mk[F32].transpose = MK_PROC_NAME_STD(float, 512, , transpose);
|
||||
context->mat_mk[F32].fma = MK_PROC_NAME_STD(float, 512, , fma);
|
||||
context->mat_mk[F32].pivot = NULL;
|
||||
|
||||
context->mat_mk[F64].add = MK_PROC_NAME_STD(double, 512, , add);
|
||||
context->mat_mk[F64].fill = MK_PROC_NAME_STD(double, 512, , fill);
|
||||
context->mat_mk[F64].scalar_mul = MK_PROC_NAME_STD(double, 512, , scalar_mul);
|
||||
context->mat_mk[F64].sub = MK_PROC_NAME_STD(double, 512, , sub);
|
||||
context->mat_mk[F64].transpose = NULL;
|
||||
context->mat_mk[F64].fma = MK_PROC_NAME_STD(double, 512, , fma);
|
||||
context->mat_mk[F64].pivot = NULL;
|
||||
|
||||
context->vec_f32_normalize_3 = f32_normalize;
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
@@ -1,58 +1,58 @@
|
||||
#include "sn_target.h"
|
||||
|
||||
#if SN_IS_ARCH(SN_ARCH_X86_64)
|
||||
|
||||
#include "sn_intrinsic.h"
|
||||
#include "sn_intrinsic.context.x86.h"
|
||||
#include "sn_intrinsic.std.h"
|
||||
|
||||
// Matrix transpose implementations
|
||||
SN_MK_PROC_DECL_STD(float, sse, , transpose)
|
||||
{
|
||||
__mk_param_std(KERNEL, RIGHT_ANS, float);
|
||||
|
||||
register __m128 col0 = right->f32_x[0];
|
||||
register __m128 col1 = right->f32_x[1];
|
||||
register __m128 col2 = right->f32_x[2];
|
||||
register __m128 col3 = right->f32_x[3];
|
||||
register __m128 tmp0 = _mm_unpacklo_ps(col0, col1);
|
||||
register __m128 tmp1 = _mm_unpackhi_ps(col0, col1);
|
||||
register __m128 tmp2 = _mm_unpacklo_ps(col2, col3);
|
||||
register __m128 tmp3 = _mm_unpackhi_ps(col2, col3);
|
||||
|
||||
_mm_store_ps(&(ans->f32_x[0]), _mm_movelh_ps(tmp0, tmp2));
|
||||
_mm_store_ps(&(ans->f32_x[1]), _mm_movehl_ps(tmp2, tmp0));
|
||||
_mm_store_ps(&(ans->f32_x[2]), _mm_movelh_ps(tmp1, tmp3));
|
||||
_mm_store_ps(&(ans->f32_x[3]), _mm_movehl_ps(tmp3, tmp1));
|
||||
}
|
||||
|
||||
SN_MK_PROC_DECL_STD(float, avx, , transpose)
|
||||
{
|
||||
__mk_param_std(KERNEL, RIGHT_ANS, float);
|
||||
register __m256 col_low = right->f32_y[0];
|
||||
register __m256 col_high = right->f32_y[1];
|
||||
|
||||
register __m256 unpack_low = _mm256_unpacklo_ps(col_low, col_high);
|
||||
register __m256 unpack_high = _mm256_unpackhi_ps(col_low, col_high);
|
||||
|
||||
col_low = _mm256_permute2f128_ps(unpack_low, unpack_high, 0x20);
|
||||
col_high = _mm256_permute2f128_ps(unpack_low, unpack_high, 0x31);
|
||||
|
||||
_mm256_store_ps(&(ans->f32_y[0]),
|
||||
_mm256_shuffle_ps(col_high, col_low, _MM_SHUFFLE(2, 0, 2, 0)));
|
||||
_mm256_store_ps(&(ans->f32_y[1]),
|
||||
_mm256_shuffle_ps(col_high, col_low, _MM_SHUFFLE(3, 1, 3, 1)));
|
||||
}
|
||||
|
||||
SN_MK_PROC_DECL_STD(float, 512, , transpose)
|
||||
{
|
||||
__mk_param_std(KERNEL, RIGHT_ANS, float);
|
||||
register __m512 matrix = right->f32_z[0];
|
||||
|
||||
const __m512i transpose_indices =
|
||||
_mm512_setr_epi32(0, 4, 8, 12, 1, 5, 9, 13, 2, 6, 10, 14, 3, 7, 11, 15);
|
||||
|
||||
_mm512_store_ps(&(ans->f32_z[0]), _mm512_permutexvar_ps(transpose_indices, matrix));
|
||||
}
|
||||
|
||||
#endif
|
||||
#include "sn_target.h"
|
||||
|
||||
#if SN_IS_ARCH(SN_ARCH_X86_64)
|
||||
|
||||
#include "sn_intrinsic.h"
|
||||
#include "sn_intrinsic.context.x86.h"
|
||||
#include "sn_intrinsic.std.h"
|
||||
|
||||
// Matrix transpose implementations
|
||||
SN_MK_PROC_DECL_STD(float, sse, , transpose)
|
||||
{
|
||||
__mk_param_std(KERNEL, RIGHT_ANS, float);
|
||||
|
||||
register __m128 col0 = right->f32_x[0];
|
||||
register __m128 col1 = right->f32_x[1];
|
||||
register __m128 col2 = right->f32_x[2];
|
||||
register __m128 col3 = right->f32_x[3];
|
||||
register __m128 tmp0 = _mm_unpacklo_ps(col0, col1);
|
||||
register __m128 tmp1 = _mm_unpackhi_ps(col0, col1);
|
||||
register __m128 tmp2 = _mm_unpacklo_ps(col2, col3);
|
||||
register __m128 tmp3 = _mm_unpackhi_ps(col2, col3);
|
||||
|
||||
_mm_store_ps(&(ans->f32_x[0]), _mm_movelh_ps(tmp0, tmp2));
|
||||
_mm_store_ps(&(ans->f32_x[1]), _mm_movehl_ps(tmp2, tmp0));
|
||||
_mm_store_ps(&(ans->f32_x[2]), _mm_movelh_ps(tmp1, tmp3));
|
||||
_mm_store_ps(&(ans->f32_x[3]), _mm_movehl_ps(tmp3, tmp1));
|
||||
}
|
||||
|
||||
SN_MK_PROC_DECL_STD(float, avx, , transpose)
|
||||
{
|
||||
__mk_param_std(KERNEL, RIGHT_ANS, float);
|
||||
register __m256 col_low = right->f32_y[0];
|
||||
register __m256 col_high = right->f32_y[1];
|
||||
|
||||
register __m256 unpack_low = _mm256_unpacklo_ps(col_low, col_high);
|
||||
register __m256 unpack_high = _mm256_unpackhi_ps(col_low, col_high);
|
||||
|
||||
col_low = _mm256_permute2f128_ps(unpack_low, unpack_high, 0x20);
|
||||
col_high = _mm256_permute2f128_ps(unpack_low, unpack_high, 0x31);
|
||||
|
||||
_mm256_store_ps(&(ans->f32_y[0]),
|
||||
_mm256_shuffle_ps(col_high, col_low, _MM_SHUFFLE(2, 0, 2, 0)));
|
||||
_mm256_store_ps(&(ans->f32_y[1]),
|
||||
_mm256_shuffle_ps(col_high, col_low, _MM_SHUFFLE(3, 1, 3, 1)));
|
||||
}
|
||||
|
||||
SN_MK_PROC_DECL_STD(float, 512, , transpose)
|
||||
{
|
||||
__mk_param_std(KERNEL, RIGHT_ANS, float);
|
||||
register __m512 matrix = right->f32_z[0];
|
||||
|
||||
const __m512i transpose_indices =
|
||||
_mm512_setr_epi32(0, 4, 8, 12, 1, 5, 9, 13, 2, 6, 10, 14, 3, 7, 11, 15);
|
||||
|
||||
_mm512_store_ps(&(ans->f32_z[0]), _mm512_permutexvar_ps(transpose_indices, matrix));
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
@@ -1,367 +1,367 @@
|
||||
#include "sn_target.h"
|
||||
|
||||
#if SN_IS_ARCH(SN_ARCH_X86_64)
|
||||
|
||||
#include "sn_intrinsic.h"
|
||||
#include "sn_intrinsic.std.h"
|
||||
#include "sn_intrinsic.context.x86.h"
|
||||
|
||||
SN_MK_PROC_DECL_STD(float, sse, , fill)
|
||||
{
|
||||
__mk_param_std(BUFFER, ANS_SCALAR, float);
|
||||
register __m128 vec = _mm_set_ps1(((float *)(scalar->data))[0]);
|
||||
for (size_t i = 0; i < count; i++) {
|
||||
ans[i].f32_x[0] = vec;
|
||||
ans[i].f32_x[1] = vec;
|
||||
ans[i].f32_x[2] = vec;
|
||||
ans[i].f32_x[3] = vec;
|
||||
}
|
||||
}
|
||||
|
||||
SN_MK_PROC_DECL_STD(float, avx, , fill)
|
||||
{
|
||||
__mk_param_std(BUFFER, ANS_SCALAR, float);
|
||||
register __m256 vec = _mm256_broadcast_ss(((float *)(scalar->data)));
|
||||
for (size_t i = 0; i < count; i++) {
|
||||
ans[i].f32_y[0] = vec;
|
||||
ans[i].f32_y[1] = vec;
|
||||
}
|
||||
}
|
||||
|
||||
SN_MK_PROC_DECL_STD(float, 512, , fill)
|
||||
{
|
||||
__mk_param_std(BUFFER, ANS_SCALAR, float);
|
||||
register __m512 vec = _mm512_broadcastss_ps(((__m128 *)(scalar->data))[0]);
|
||||
for (size_t i = 0; i < count; i++) {
|
||||
ans[i].f32_z[0] = vec;
|
||||
}
|
||||
}
|
||||
|
||||
SN_MK_PROC_DECL_STD(double, sse, , fill)
|
||||
{
|
||||
__mk_param_std(BUFFER, ANS_SCALAR, double);
|
||||
register __m128d vec = _mm_set1_pd(((double *)(scalar->data))[0]);
|
||||
for (size_t i = 0; i < count; i++) {
|
||||
ans[i].f64_x[0] = vec;
|
||||
ans[i].f64_x[1] = vec;
|
||||
ans[i].f64_x[2] = vec;
|
||||
ans[i].f64_x[3] = vec;
|
||||
ans[i].f64_x[4] = vec;
|
||||
ans[i].f64_x[5] = vec;
|
||||
ans[i].f64_x[6] = vec;
|
||||
ans[i].f64_x[7] = vec;
|
||||
}
|
||||
}
|
||||
|
||||
SN_MK_PROC_DECL_STD(double, avx, , fill)
|
||||
{
|
||||
__mk_param_std(BUFFER, ANS_SCALAR, double);
|
||||
register __m256d vec = _mm256_broadcast_sd(((double *)(scalar->data)));
|
||||
for (size_t i = 0; i < count; i++) {
|
||||
ans[i].f64_y[0] = vec;
|
||||
ans[i].f64_y[1] = vec;
|
||||
ans[i].f64_y[2] = vec;
|
||||
ans[i].f64_y[3] = vec;
|
||||
}
|
||||
}
|
||||
|
||||
SN_MK_PROC_DECL_STD(double, 512, , fill)
|
||||
{
|
||||
__mk_param_std(BUFFER, ANS_SCALAR, double);
|
||||
register __m512d vec = _mm512_broadcastsd_pd(_mm_loadu_pd(scalar));
|
||||
for (size_t i = 0; i < count; i++) {
|
||||
ans[i].f64_z[0] = vec;
|
||||
ans[i].f64_z[1] = vec;
|
||||
}
|
||||
}
|
||||
|
||||
SN_MK_PROC_DECL_STD(float, sse, , add)
|
||||
{
|
||||
__mk_param_std(BUFFER, LEFT_RIGHT_ANS, float);
|
||||
|
||||
for (size_t i = 0; i < count; i++) {
|
||||
register __m128 c0 = _mm_add_ps(left[i].f32_x[0], right[i].f32_x[0]);
|
||||
register __m128 c1 = _mm_add_ps(left[i].f32_x[1], right[i].f32_x[1]);
|
||||
register __m128 c2 = _mm_add_ps(left[i].f32_x[2], right[i].f32_x[2]);
|
||||
register __m128 c3 = _mm_add_ps(left[i].f32_x[3], right[i].f32_x[3]);
|
||||
|
||||
ans[i].f32_x[0] = c0;
|
||||
ans[i].f32_x[1] = c1;
|
||||
ans[i].f32_x[2] = c2;
|
||||
ans[i].f32_x[3] = c3;
|
||||
}
|
||||
}
|
||||
|
||||
SN_MK_PROC_DECL_STD(float, avx, , add)
|
||||
{
|
||||
__mk_param_std(BUFFER, LEFT_RIGHT_ANS, float);
|
||||
|
||||
for (size_t i = 0; i < count; i++) {
|
||||
size_t s = sizeof(MAT_KERNEL(float));
|
||||
register __m256 c0 = _mm256_add_ps(left[i].f32_y[0], right[i].f32_y[0]);
|
||||
register __m256 c1 = _mm256_add_ps(left[i].f32_y[1], right[i].f32_y[1]);
|
||||
ans[i].f32_y[0] = c0;
|
||||
ans[i].f32_y[1] = c1;
|
||||
}
|
||||
}
|
||||
|
||||
SN_MK_PROC_DECL_STD(float, 512, , add)
|
||||
{
|
||||
__mk_param_std(BUFFER, LEFT_RIGHT_ANS, float);
|
||||
|
||||
for (size_t i = 0; i < count; i++) {
|
||||
register __m512 c0 = _mm512_add_ps(left[i].f32_z[0], right[i].f32_z[0]);
|
||||
ans[i].f32_z[0] = c0;
|
||||
}
|
||||
}
|
||||
SN_MK_PROC_DECL_STD(double, sse, , add)
|
||||
{
|
||||
__mk_param_std(BUFFER, LEFT_RIGHT_ANS, double);
|
||||
|
||||
for (size_t i = 0; i < count; i++) {
|
||||
register __m128d c0 = _mm_add_pd(_mm_castps_pd(left[i].f32_x[0]),
|
||||
_mm_castps_pd(right[i].f32_x[0]));
|
||||
register __m128d c1 = _mm_add_pd(_mm_castps_pd(left[i].f32_x[1]),
|
||||
_mm_castps_pd(right[i].f32_x[1]));
|
||||
register __m128d c2 = _mm_add_pd(_mm_castps_pd(left[i].f32_x[2]),
|
||||
_mm_castps_pd(right[i].f32_x[2]));
|
||||
register __m128d c3 = _mm_add_pd(_mm_castps_pd(left[i].f32_x[3]),
|
||||
_mm_castps_pd(right[i].f32_x[3]));
|
||||
register __m128d c4 = _mm_add_pd(_mm_castps_pd(left[i].f32_x[4]),
|
||||
_mm_castps_pd(right[i].f32_x[4]));
|
||||
register __m128d c5 = _mm_add_pd(_mm_castps_pd(left[i].f32_x[5]),
|
||||
_mm_castps_pd(right[i].f32_x[5]));
|
||||
register __m128d c6 = _mm_add_pd(_mm_castps_pd(left[i].f32_x[6]),
|
||||
_mm_castps_pd(right[i].f32_x[6]));
|
||||
register __m128d c7 = _mm_add_pd(_mm_castps_pd(left[i].f32_x[7]),
|
||||
_mm_castps_pd(right[i].f32_x[7]));
|
||||
|
||||
ans[i].f32_x[0] = _mm_castpd_ps(c0);
|
||||
ans[i].f32_x[1] = _mm_castpd_ps(c1);
|
||||
ans[i].f32_x[2] = _mm_castpd_ps(c2);
|
||||
ans[i].f32_x[3] = _mm_castpd_ps(c3);
|
||||
ans[i].f32_x[4] = _mm_castpd_ps(c4);
|
||||
ans[i].f32_x[5] = _mm_castpd_ps(c5);
|
||||
ans[i].f32_x[6] = _mm_castpd_ps(c6);
|
||||
ans[i].f32_x[7] = _mm_castpd_ps(c7);
|
||||
}
|
||||
}
|
||||
|
||||
SN_MK_PROC_DECL_STD(double, avx, , add)
|
||||
{
|
||||
__mk_param_std(BUFFER, LEFT_RIGHT_ANS, double);
|
||||
|
||||
for (size_t i = 0; i < count; i++) {
|
||||
size_t s = sizeof(MAT_KERNEL(float));
|
||||
register __m256d c0 = _mm256_add_pd(left[i].f64_y[0], right[i].f64_y[0]);
|
||||
register __m256d c1 = _mm256_add_pd(left[i].f64_y[1], right[i].f64_y[1]);
|
||||
register __m256d c2 = _mm256_add_pd(left[i].f64_y[0], right[i].f64_y[0]);
|
||||
register __m256d c3 = _mm256_add_pd(left[i].f64_y[1], right[i].f64_y[1]);
|
||||
ans[i].f64_y[0] = c0;
|
||||
ans[i].f64_y[1] = c1;
|
||||
ans[i].f64_y[2] = c2;
|
||||
ans[i].f64_y[3] = c3;
|
||||
}
|
||||
}
|
||||
|
||||
SN_MK_PROC_DECL_STD(double, 512, , add)
|
||||
{
|
||||
__mk_param_std(BUFFER, LEFT_RIGHT_ANS, double);
|
||||
|
||||
for (size_t i = 0; i < count; i++) {
|
||||
register __m512d c0 = _mm512_add_pd(left[i].f64_z[0], right[i].f64_z[0]);
|
||||
register __m512d c1 = _mm512_add_pd(left[i].f64_z[1], right[i].f64_z[1]);
|
||||
ans[i].f64_z[0] = c0;
|
||||
ans[i].f64_z[1] = c1;
|
||||
}
|
||||
}
|
||||
|
||||
SN_MK_PROC_DECL_STD(float, sse, , sub)
|
||||
{
|
||||
__mk_param_std(BUFFER, LEFT_RIGHT_ANS, float);
|
||||
|
||||
for (size_t i = 0; i < count; i++) {
|
||||
register __m128 c0 = _mm_sub_ps(left[i].f32_x[0], right[i].f32_x[0]);
|
||||
register __m128 c1 = _mm_sub_ps(left[i].f32_x[1], right[i].f32_x[1]);
|
||||
register __m128 c2 = _mm_sub_ps(left[i].f32_x[2], right[i].f32_x[2]);
|
||||
register __m128 c3 = _mm_sub_ps(left[i].f32_x[3], right[i].f32_x[3]);
|
||||
|
||||
ans[i].f32_x[0] = c0;
|
||||
ans[i].f32_x[1] = c1;
|
||||
ans[i].f32_x[2] = c2;
|
||||
ans[i].f32_x[3] = c3;
|
||||
}
|
||||
}
|
||||
|
||||
SN_MK_PROC_DECL_STD(float, avx, , sub)
|
||||
{
|
||||
__mk_param_std(BUFFER, LEFT_RIGHT_ANS, float);
|
||||
|
||||
for (size_t i = 0; i < count; i++) {
|
||||
register __m256 c0 = _mm256_sub_ps(left[i].f32_y[0], right[i].f32_y[0]);
|
||||
register __m256 c1 = _mm256_sub_ps(left[i].f32_y[1], right[i].f32_y[1]);
|
||||
ans[i].f32_y[0] = c0;
|
||||
ans[i].f32_y[1] = c1;
|
||||
}
|
||||
}
|
||||
|
||||
SN_MK_PROC_DECL_STD(float, 512, , sub)
|
||||
{
|
||||
__mk_param_std(BUFFER, LEFT_RIGHT_ANS, float);
|
||||
|
||||
for (size_t i = 0; i < count; i++) {
|
||||
register __m512 c0 = _mm512_sub_ps(left[i].f32_z[0], right[i].f32_z[0]);
|
||||
ans[i].f32_z[0] = c0;
|
||||
}
|
||||
}
|
||||
|
||||
SN_MK_PROC_DECL_STD(double, sse, , sub)
|
||||
{
|
||||
__mk_param_std(BUFFER, LEFT_RIGHT_ANS, double);
|
||||
|
||||
for (size_t i = 0; i < count; i++) {
|
||||
register __m128d c0 = _mm_sub_pd(left[i].f64_x[0], right[i].f64_x[0]);
|
||||
register __m128d c1 = _mm_sub_pd(left[i].f64_x[1], right[i].f64_x[1]);
|
||||
register __m128d c2 = _mm_sub_pd(left[i].f64_x[2], right[i].f64_x[2]);
|
||||
register __m128d c3 = _mm_sub_pd(left[i].f64_x[3], right[i].f64_x[3]);
|
||||
register __m128d c4 = _mm_sub_pd(left[i].f64_x[4], right[i].f64_x[4]);
|
||||
register __m128d c5 = _mm_sub_pd(left[i].f64_x[5], right[i].f64_x[5]);
|
||||
register __m128d c6 = _mm_sub_pd(left[i].f64_x[6], right[i].f64_x[6]);
|
||||
register __m128d c7 = _mm_sub_pd(left[i].f64_x[7], right[i].f64_x[7]);
|
||||
|
||||
ans[i].f64_x[0] = c0;
|
||||
ans[i].f64_x[1] = c1;
|
||||
ans[i].f64_x[2] = c2;
|
||||
ans[i].f64_x[3] = c3;
|
||||
ans[i].f64_x[4] = c4;
|
||||
ans[i].f64_x[5] = c5;
|
||||
ans[i].f64_x[6] = c6;
|
||||
ans[i].f64_x[7] = c7;
|
||||
}
|
||||
}
|
||||
|
||||
SN_MK_PROC_DECL_STD(double, avx, , sub)
|
||||
{
|
||||
__mk_param_std(BUFFER, LEFT_RIGHT_ANS, double);
|
||||
|
||||
for (size_t i = 0; i < count; i++) {
|
||||
register __m256 c0 = _mm256_sub_ps(left[i].f32_y[0], right[i].f32_y[0]);
|
||||
register __m256 c1 = _mm256_sub_ps(left[i].f32_y[1], right[i].f32_y[1]);
|
||||
ans[i].f32_y[0] = c0;
|
||||
ans[i].f32_y[1] = c1;
|
||||
}
|
||||
}
|
||||
|
||||
SN_MK_PROC_DECL_STD(double, 512, , sub)
|
||||
{
|
||||
__mk_param_std(BUFFER, LEFT_RIGHT_ANS, double);
|
||||
|
||||
for (size_t i = 0; i < count; i++) {
|
||||
register __m512 c0 = _mm512_sub_ps(left[i].f32_z[0], right[i].f32_z[0]);
|
||||
ans[i].f32_z[0] = c0;
|
||||
}
|
||||
}
|
||||
|
||||
SN_MK_PROC_DECL_STD(float, sse, , scalar_mul)
|
||||
{
|
||||
__mk_param_std(BUFFER, RIGHT_ANS_SCALAR, float);
|
||||
|
||||
register __m128 vec = _mm_set_ps1(((float *)(scalar->data))[0]);
|
||||
for (size_t i = 0; i < count; i++) {
|
||||
register __m128 c0 = _mm_mul_ps(right[i].f32_x[0], vec);
|
||||
register __m128 c1 = _mm_mul_ps(right[i].f32_x[1], vec);
|
||||
register __m128 c2 = _mm_mul_ps(right[i].f32_x[2], vec);
|
||||
register __m128 c3 = _mm_mul_ps(right[i].f32_x[3], vec);
|
||||
|
||||
ans[i].f32_x[0] = c0;
|
||||
ans[i].f32_x[1] = c1;
|
||||
ans[i].f32_x[2] = c2;
|
||||
ans[i].f32_x[3] = c3;
|
||||
}
|
||||
}
|
||||
|
||||
SN_MK_PROC_DECL_STD(float, avx, , scalar_mul)
|
||||
{
|
||||
__mk_param_std(BUFFER, RIGHT_ANS_SCALAR, float);
|
||||
|
||||
register __m256 vec = _mm256_broadcast_ss(((float *)(scalar->data)));
|
||||
for (size_t i = 0; i < count; i++) {
|
||||
register __m256 c0 = _mm256_mul_ps(right[i].f32_y[0], vec);
|
||||
register __m256 c1 = _mm256_mul_ps(right[i].f32_y[1], vec);
|
||||
|
||||
ans[i].f32_y[0] = c0;
|
||||
ans[i].f32_y[1] = c1;
|
||||
}
|
||||
}
|
||||
|
||||
SN_MK_PROC_DECL_STD(float, 512, , scalar_mul)
|
||||
{
|
||||
__mk_param_std(BUFFER, RIGHT_ANS_SCALAR, float);
|
||||
|
||||
register __m512 vec = _mm512_broadcastss_ps(((__m128 *)(scalar->data))[0]);
|
||||
for (size_t i = 0; i < count; i++) {
|
||||
register __m512 c0 = _mm512_mul_ps(right[i].f32_z[0], vec);
|
||||
|
||||
ans[i].f32_z[0] = c0;
|
||||
}
|
||||
}
|
||||
|
||||
SN_MK_PROC_DECL_STD(double, sse, , scalar_mul)
|
||||
{
|
||||
__mk_param_std(BUFFER, RIGHT_ANS_SCALAR, double);
|
||||
|
||||
register __m128d vec = _mm_set1_pd(((double *)(scalar->data))[0]);
|
||||
for (size_t i = 0; i < count; i++) {
|
||||
register __m128d c0 = _mm_mul_pd(right[i].f64_x[0], vec);
|
||||
register __m128d c1 = _mm_mul_pd(right[i].f64_x[1], vec);
|
||||
register __m128d c2 = _mm_mul_pd(right[i].f64_x[2], vec);
|
||||
register __m128d c3 = _mm_mul_pd(right[i].f64_x[3], vec);
|
||||
register __m128d c4 = _mm_mul_pd(right[i].f64_x[4], vec);
|
||||
register __m128d c5 = _mm_mul_pd(right[i].f64_x[5], vec);
|
||||
register __m128d c6 = _mm_mul_pd(right[i].f64_x[6], vec);
|
||||
register __m128d c7 = _mm_mul_pd(right[i].f64_x[7], vec);
|
||||
|
||||
ans[i].f64_x[0] = c0;
|
||||
ans[i].f64_x[1] = c1;
|
||||
ans[i].f64_x[2] = c2;
|
||||
ans[i].f64_x[3] = c3;
|
||||
ans[i].f64_x[4] = c4;
|
||||
ans[i].f64_x[5] = c5;
|
||||
ans[i].f64_x[6] = c6;
|
||||
ans[i].f64_x[7] = c7;
|
||||
}
|
||||
}
|
||||
|
||||
SN_MK_PROC_DECL_STD(double, avx, , scalar_mul)
|
||||
{
|
||||
__mk_param_std(BUFFER, RIGHT_ANS_SCALAR, double);
|
||||
|
||||
register __m256d vec = _mm256_broadcast_sd(((double *)(scalar->data)));
|
||||
for (size_t i = 0; i < count; i++) {
|
||||
register __m256d c0 = _mm256_mul_pd(right[i].f64_y[0], vec);
|
||||
register __m256d c1 = _mm256_mul_pd(right[i].f64_y[1], vec);
|
||||
register __m256d c2 = _mm256_mul_pd(right[i].f64_y[2], vec);
|
||||
register __m256d c3 = _mm256_mul_pd(right[i].f64_y[3], vec);
|
||||
|
||||
ans[i].f64_y[0] = c0;
|
||||
ans[i].f64_y[1] = c1;
|
||||
ans[i].f64_y[2] = c2;
|
||||
ans[i].f64_y[3] = c3;
|
||||
}
|
||||
}
|
||||
|
||||
SN_MK_PROC_DECL_STD(double, 512, , scalar_mul)
|
||||
{
|
||||
__mk_param_std(BUFFER, RIGHT_ANS_SCALAR, double);
|
||||
|
||||
register __m512d vec = _mm512_broadcastsd_pd(_mm_load_pd(scalar));
|
||||
for (size_t i = 0; i < count; i++) {
|
||||
register __m512d c0 = _mm512_mul_pd(right[i].f64_z[0], vec);
|
||||
register __m512d c1 = _mm512_mul_pd(right[i].f64_z[1], vec);
|
||||
|
||||
ans[i].f64_z[0] = c0;
|
||||
ans[i].f64_z[1] = c1;
|
||||
}
|
||||
}
|
||||
|
||||
#endif
|
||||
#include "sn_target.h"
|
||||
|
||||
#if SN_IS_ARCH(SN_ARCH_X86_64)
|
||||
|
||||
#include "sn_intrinsic.h"
|
||||
#include "sn_intrinsic.std.h"
|
||||
#include "sn_intrinsic.context.x86.h"
|
||||
|
||||
SN_MK_PROC_DECL_STD(float, sse, , fill)
|
||||
{
|
||||
__mk_param_std(BUFFER, ANS_SCALAR, float);
|
||||
register __m128 vec = _mm_set_ps1(((float *)(scalar->data))[0]);
|
||||
for (size_t i = 0; i < count; i++) {
|
||||
ans[i].f32_x[0] = vec;
|
||||
ans[i].f32_x[1] = vec;
|
||||
ans[i].f32_x[2] = vec;
|
||||
ans[i].f32_x[3] = vec;
|
||||
}
|
||||
}
|
||||
|
||||
SN_MK_PROC_DECL_STD(float, avx, , fill)
|
||||
{
|
||||
__mk_param_std(BUFFER, ANS_SCALAR, float);
|
||||
register __m256 vec = _mm256_broadcast_ss(((float *)(scalar->data)));
|
||||
for (size_t i = 0; i < count; i++) {
|
||||
ans[i].f32_y[0] = vec;
|
||||
ans[i].f32_y[1] = vec;
|
||||
}
|
||||
}
|
||||
|
||||
SN_MK_PROC_DECL_STD(float, 512, , fill)
|
||||
{
|
||||
__mk_param_std(BUFFER, ANS_SCALAR, float);
|
||||
register __m512 vec = _mm512_broadcastss_ps(((__m128 *)(scalar->data))[0]);
|
||||
for (size_t i = 0; i < count; i++) {
|
||||
ans[i].f32_z[0] = vec;
|
||||
}
|
||||
}
|
||||
|
||||
SN_MK_PROC_DECL_STD(double, sse, , fill)
|
||||
{
|
||||
__mk_param_std(BUFFER, ANS_SCALAR, double);
|
||||
register __m128d vec = _mm_set1_pd(((double *)(scalar->data))[0]);
|
||||
for (size_t i = 0; i < count; i++) {
|
||||
ans[i].f64_x[0] = vec;
|
||||
ans[i].f64_x[1] = vec;
|
||||
ans[i].f64_x[2] = vec;
|
||||
ans[i].f64_x[3] = vec;
|
||||
ans[i].f64_x[4] = vec;
|
||||
ans[i].f64_x[5] = vec;
|
||||
ans[i].f64_x[6] = vec;
|
||||
ans[i].f64_x[7] = vec;
|
||||
}
|
||||
}
|
||||
|
||||
SN_MK_PROC_DECL_STD(double, avx, , fill)
|
||||
{
|
||||
__mk_param_std(BUFFER, ANS_SCALAR, double);
|
||||
register __m256d vec = _mm256_broadcast_sd(((double *)(scalar->data)));
|
||||
for (size_t i = 0; i < count; i++) {
|
||||
ans[i].f64_y[0] = vec;
|
||||
ans[i].f64_y[1] = vec;
|
||||
ans[i].f64_y[2] = vec;
|
||||
ans[i].f64_y[3] = vec;
|
||||
}
|
||||
}
|
||||
|
||||
SN_MK_PROC_DECL_STD(double, 512, , fill)
|
||||
{
|
||||
__mk_param_std(BUFFER, ANS_SCALAR, double);
|
||||
register __m512d vec = _mm512_broadcastsd_pd(_mm_loadu_pd(scalar));
|
||||
for (size_t i = 0; i < count; i++) {
|
||||
ans[i].f64_z[0] = vec;
|
||||
ans[i].f64_z[1] = vec;
|
||||
}
|
||||
}
|
||||
|
||||
SN_MK_PROC_DECL_STD(float, sse, , add)
|
||||
{
|
||||
__mk_param_std(BUFFER, LEFT_RIGHT_ANS, float);
|
||||
|
||||
for (size_t i = 0; i < count; i++) {
|
||||
register __m128 c0 = _mm_add_ps(left[i].f32_x[0], right[i].f32_x[0]);
|
||||
register __m128 c1 = _mm_add_ps(left[i].f32_x[1], right[i].f32_x[1]);
|
||||
register __m128 c2 = _mm_add_ps(left[i].f32_x[2], right[i].f32_x[2]);
|
||||
register __m128 c3 = _mm_add_ps(left[i].f32_x[3], right[i].f32_x[3]);
|
||||
|
||||
ans[i].f32_x[0] = c0;
|
||||
ans[i].f32_x[1] = c1;
|
||||
ans[i].f32_x[2] = c2;
|
||||
ans[i].f32_x[3] = c3;
|
||||
}
|
||||
}
|
||||
|
||||
SN_MK_PROC_DECL_STD(float, avx, , add)
|
||||
{
|
||||
__mk_param_std(BUFFER, LEFT_RIGHT_ANS, float);
|
||||
|
||||
for (size_t i = 0; i < count; i++) {
|
||||
size_t s = sizeof(MAT_KERNEL(float));
|
||||
register __m256 c0 = _mm256_add_ps(left[i].f32_y[0], right[i].f32_y[0]);
|
||||
register __m256 c1 = _mm256_add_ps(left[i].f32_y[1], right[i].f32_y[1]);
|
||||
ans[i].f32_y[0] = c0;
|
||||
ans[i].f32_y[1] = c1;
|
||||
}
|
||||
}
|
||||
|
||||
SN_MK_PROC_DECL_STD(float, 512, , add)
|
||||
{
|
||||
__mk_param_std(BUFFER, LEFT_RIGHT_ANS, float);
|
||||
|
||||
for (size_t i = 0; i < count; i++) {
|
||||
register __m512 c0 = _mm512_add_ps(left[i].f32_z[0], right[i].f32_z[0]);
|
||||
ans[i].f32_z[0] = c0;
|
||||
}
|
||||
}
|
||||
SN_MK_PROC_DECL_STD(double, sse, , add)
|
||||
{
|
||||
__mk_param_std(BUFFER, LEFT_RIGHT_ANS, double);
|
||||
|
||||
for (size_t i = 0; i < count; i++) {
|
||||
register __m128d c0 = _mm_add_pd(_mm_castps_pd(left[i].f32_x[0]),
|
||||
_mm_castps_pd(right[i].f32_x[0]));
|
||||
register __m128d c1 = _mm_add_pd(_mm_castps_pd(left[i].f32_x[1]),
|
||||
_mm_castps_pd(right[i].f32_x[1]));
|
||||
register __m128d c2 = _mm_add_pd(_mm_castps_pd(left[i].f32_x[2]),
|
||||
_mm_castps_pd(right[i].f32_x[2]));
|
||||
register __m128d c3 = _mm_add_pd(_mm_castps_pd(left[i].f32_x[3]),
|
||||
_mm_castps_pd(right[i].f32_x[3]));
|
||||
register __m128d c4 = _mm_add_pd(_mm_castps_pd(left[i].f32_x[4]),
|
||||
_mm_castps_pd(right[i].f32_x[4]));
|
||||
register __m128d c5 = _mm_add_pd(_mm_castps_pd(left[i].f32_x[5]),
|
||||
_mm_castps_pd(right[i].f32_x[5]));
|
||||
register __m128d c6 = _mm_add_pd(_mm_castps_pd(left[i].f32_x[6]),
|
||||
_mm_castps_pd(right[i].f32_x[6]));
|
||||
register __m128d c7 = _mm_add_pd(_mm_castps_pd(left[i].f32_x[7]),
|
||||
_mm_castps_pd(right[i].f32_x[7]));
|
||||
|
||||
ans[i].f32_x[0] = _mm_castpd_ps(c0);
|
||||
ans[i].f32_x[1] = _mm_castpd_ps(c1);
|
||||
ans[i].f32_x[2] = _mm_castpd_ps(c2);
|
||||
ans[i].f32_x[3] = _mm_castpd_ps(c3);
|
||||
ans[i].f32_x[4] = _mm_castpd_ps(c4);
|
||||
ans[i].f32_x[5] = _mm_castpd_ps(c5);
|
||||
ans[i].f32_x[6] = _mm_castpd_ps(c6);
|
||||
ans[i].f32_x[7] = _mm_castpd_ps(c7);
|
||||
}
|
||||
}
|
||||
|
||||
SN_MK_PROC_DECL_STD(double, avx, , add)
|
||||
{
|
||||
__mk_param_std(BUFFER, LEFT_RIGHT_ANS, double);
|
||||
|
||||
for (size_t i = 0; i < count; i++) {
|
||||
size_t s = sizeof(MAT_KERNEL(float));
|
||||
register __m256d c0 = _mm256_add_pd(left[i].f64_y[0], right[i].f64_y[0]);
|
||||
register __m256d c1 = _mm256_add_pd(left[i].f64_y[1], right[i].f64_y[1]);
|
||||
register __m256d c2 = _mm256_add_pd(left[i].f64_y[0], right[i].f64_y[0]);
|
||||
register __m256d c3 = _mm256_add_pd(left[i].f64_y[1], right[i].f64_y[1]);
|
||||
ans[i].f64_y[0] = c0;
|
||||
ans[i].f64_y[1] = c1;
|
||||
ans[i].f64_y[2] = c2;
|
||||
ans[i].f64_y[3] = c3;
|
||||
}
|
||||
}
|
||||
|
||||
SN_MK_PROC_DECL_STD(double, 512, , add)
|
||||
{
|
||||
__mk_param_std(BUFFER, LEFT_RIGHT_ANS, double);
|
||||
|
||||
for (size_t i = 0; i < count; i++) {
|
||||
register __m512d c0 = _mm512_add_pd(left[i].f64_z[0], right[i].f64_z[0]);
|
||||
register __m512d c1 = _mm512_add_pd(left[i].f64_z[1], right[i].f64_z[1]);
|
||||
ans[i].f64_z[0] = c0;
|
||||
ans[i].f64_z[1] = c1;
|
||||
}
|
||||
}
|
||||
|
||||
SN_MK_PROC_DECL_STD(float, sse, , sub)
|
||||
{
|
||||
__mk_param_std(BUFFER, LEFT_RIGHT_ANS, float);
|
||||
|
||||
for (size_t i = 0; i < count; i++) {
|
||||
register __m128 c0 = _mm_sub_ps(left[i].f32_x[0], right[i].f32_x[0]);
|
||||
register __m128 c1 = _mm_sub_ps(left[i].f32_x[1], right[i].f32_x[1]);
|
||||
register __m128 c2 = _mm_sub_ps(left[i].f32_x[2], right[i].f32_x[2]);
|
||||
register __m128 c3 = _mm_sub_ps(left[i].f32_x[3], right[i].f32_x[3]);
|
||||
|
||||
ans[i].f32_x[0] = c0;
|
||||
ans[i].f32_x[1] = c1;
|
||||
ans[i].f32_x[2] = c2;
|
||||
ans[i].f32_x[3] = c3;
|
||||
}
|
||||
}
|
||||
|
||||
SN_MK_PROC_DECL_STD(float, avx, , sub)
|
||||
{
|
||||
__mk_param_std(BUFFER, LEFT_RIGHT_ANS, float);
|
||||
|
||||
for (size_t i = 0; i < count; i++) {
|
||||
register __m256 c0 = _mm256_sub_ps(left[i].f32_y[0], right[i].f32_y[0]);
|
||||
register __m256 c1 = _mm256_sub_ps(left[i].f32_y[1], right[i].f32_y[1]);
|
||||
ans[i].f32_y[0] = c0;
|
||||
ans[i].f32_y[1] = c1;
|
||||
}
|
||||
}
|
||||
|
||||
SN_MK_PROC_DECL_STD(float, 512, , sub)
|
||||
{
|
||||
__mk_param_std(BUFFER, LEFT_RIGHT_ANS, float);
|
||||
|
||||
for (size_t i = 0; i < count; i++) {
|
||||
register __m512 c0 = _mm512_sub_ps(left[i].f32_z[0], right[i].f32_z[0]);
|
||||
ans[i].f32_z[0] = c0;
|
||||
}
|
||||
}
|
||||
|
||||
SN_MK_PROC_DECL_STD(double, sse, , sub)
|
||||
{
|
||||
__mk_param_std(BUFFER, LEFT_RIGHT_ANS, double);
|
||||
|
||||
for (size_t i = 0; i < count; i++) {
|
||||
register __m128d c0 = _mm_sub_pd(left[i].f64_x[0], right[i].f64_x[0]);
|
||||
register __m128d c1 = _mm_sub_pd(left[i].f64_x[1], right[i].f64_x[1]);
|
||||
register __m128d c2 = _mm_sub_pd(left[i].f64_x[2], right[i].f64_x[2]);
|
||||
register __m128d c3 = _mm_sub_pd(left[i].f64_x[3], right[i].f64_x[3]);
|
||||
register __m128d c4 = _mm_sub_pd(left[i].f64_x[4], right[i].f64_x[4]);
|
||||
register __m128d c5 = _mm_sub_pd(left[i].f64_x[5], right[i].f64_x[5]);
|
||||
register __m128d c6 = _mm_sub_pd(left[i].f64_x[6], right[i].f64_x[6]);
|
||||
register __m128d c7 = _mm_sub_pd(left[i].f64_x[7], right[i].f64_x[7]);
|
||||
|
||||
ans[i].f64_x[0] = c0;
|
||||
ans[i].f64_x[1] = c1;
|
||||
ans[i].f64_x[2] = c2;
|
||||
ans[i].f64_x[3] = c3;
|
||||
ans[i].f64_x[4] = c4;
|
||||
ans[i].f64_x[5] = c5;
|
||||
ans[i].f64_x[6] = c6;
|
||||
ans[i].f64_x[7] = c7;
|
||||
}
|
||||
}
|
||||
|
||||
SN_MK_PROC_DECL_STD(double, avx, , sub)
|
||||
{
|
||||
__mk_param_std(BUFFER, LEFT_RIGHT_ANS, double);
|
||||
|
||||
for (size_t i = 0; i < count; i++) {
|
||||
register __m256 c0 = _mm256_sub_ps(left[i].f32_y[0], right[i].f32_y[0]);
|
||||
register __m256 c1 = _mm256_sub_ps(left[i].f32_y[1], right[i].f32_y[1]);
|
||||
ans[i].f32_y[0] = c0;
|
||||
ans[i].f32_y[1] = c1;
|
||||
}
|
||||
}
|
||||
|
||||
SN_MK_PROC_DECL_STD(double, 512, , sub)
|
||||
{
|
||||
__mk_param_std(BUFFER, LEFT_RIGHT_ANS, double);
|
||||
|
||||
for (size_t i = 0; i < count; i++) {
|
||||
register __m512 c0 = _mm512_sub_ps(left[i].f32_z[0], right[i].f32_z[0]);
|
||||
ans[i].f32_z[0] = c0;
|
||||
}
|
||||
}
|
||||
|
||||
SN_MK_PROC_DECL_STD(float, sse, , scalar_mul)
|
||||
{
|
||||
__mk_param_std(BUFFER, RIGHT_ANS_SCALAR, float);
|
||||
|
||||
register __m128 vec = _mm_set_ps1(((float *)(scalar->data))[0]);
|
||||
for (size_t i = 0; i < count; i++) {
|
||||
register __m128 c0 = _mm_mul_ps(right[i].f32_x[0], vec);
|
||||
register __m128 c1 = _mm_mul_ps(right[i].f32_x[1], vec);
|
||||
register __m128 c2 = _mm_mul_ps(right[i].f32_x[2], vec);
|
||||
register __m128 c3 = _mm_mul_ps(right[i].f32_x[3], vec);
|
||||
|
||||
ans[i].f32_x[0] = c0;
|
||||
ans[i].f32_x[1] = c1;
|
||||
ans[i].f32_x[2] = c2;
|
||||
ans[i].f32_x[3] = c3;
|
||||
}
|
||||
}
|
||||
|
||||
SN_MK_PROC_DECL_STD(float, avx, , scalar_mul)
|
||||
{
|
||||
__mk_param_std(BUFFER, RIGHT_ANS_SCALAR, float);
|
||||
|
||||
register __m256 vec = _mm256_broadcast_ss(((float *)(scalar->data)));
|
||||
for (size_t i = 0; i < count; i++) {
|
||||
register __m256 c0 = _mm256_mul_ps(right[i].f32_y[0], vec);
|
||||
register __m256 c1 = _mm256_mul_ps(right[i].f32_y[1], vec);
|
||||
|
||||
ans[i].f32_y[0] = c0;
|
||||
ans[i].f32_y[1] = c1;
|
||||
}
|
||||
}
|
||||
|
||||
SN_MK_PROC_DECL_STD(float, 512, , scalar_mul)
|
||||
{
|
||||
__mk_param_std(BUFFER, RIGHT_ANS_SCALAR, float);
|
||||
|
||||
register __m512 vec = _mm512_broadcastss_ps(((__m128 *)(scalar->data))[0]);
|
||||
for (size_t i = 0; i < count; i++) {
|
||||
register __m512 c0 = _mm512_mul_ps(right[i].f32_z[0], vec);
|
||||
|
||||
ans[i].f32_z[0] = c0;
|
||||
}
|
||||
}
|
||||
|
||||
SN_MK_PROC_DECL_STD(double, sse, , scalar_mul)
|
||||
{
|
||||
__mk_param_std(BUFFER, RIGHT_ANS_SCALAR, double);
|
||||
|
||||
register __m128d vec = _mm_set1_pd(((double *)(scalar->data))[0]);
|
||||
for (size_t i = 0; i < count; i++) {
|
||||
register __m128d c0 = _mm_mul_pd(right[i].f64_x[0], vec);
|
||||
register __m128d c1 = _mm_mul_pd(right[i].f64_x[1], vec);
|
||||
register __m128d c2 = _mm_mul_pd(right[i].f64_x[2], vec);
|
||||
register __m128d c3 = _mm_mul_pd(right[i].f64_x[3], vec);
|
||||
register __m128d c4 = _mm_mul_pd(right[i].f64_x[4], vec);
|
||||
register __m128d c5 = _mm_mul_pd(right[i].f64_x[5], vec);
|
||||
register __m128d c6 = _mm_mul_pd(right[i].f64_x[6], vec);
|
||||
register __m128d c7 = _mm_mul_pd(right[i].f64_x[7], vec);
|
||||
|
||||
ans[i].f64_x[0] = c0;
|
||||
ans[i].f64_x[1] = c1;
|
||||
ans[i].f64_x[2] = c2;
|
||||
ans[i].f64_x[3] = c3;
|
||||
ans[i].f64_x[4] = c4;
|
||||
ans[i].f64_x[5] = c5;
|
||||
ans[i].f64_x[6] = c6;
|
||||
ans[i].f64_x[7] = c7;
|
||||
}
|
||||
}
|
||||
|
||||
SN_MK_PROC_DECL_STD(double, avx, , scalar_mul)
|
||||
{
|
||||
__mk_param_std(BUFFER, RIGHT_ANS_SCALAR, double);
|
||||
|
||||
register __m256d vec = _mm256_broadcast_sd(((double *)(scalar->data)));
|
||||
for (size_t i = 0; i < count; i++) {
|
||||
register __m256d c0 = _mm256_mul_pd(right[i].f64_y[0], vec);
|
||||
register __m256d c1 = _mm256_mul_pd(right[i].f64_y[1], vec);
|
||||
register __m256d c2 = _mm256_mul_pd(right[i].f64_y[2], vec);
|
||||
register __m256d c3 = _mm256_mul_pd(right[i].f64_y[3], vec);
|
||||
|
||||
ans[i].f64_y[0] = c0;
|
||||
ans[i].f64_y[1] = c1;
|
||||
ans[i].f64_y[2] = c2;
|
||||
ans[i].f64_y[3] = c3;
|
||||
}
|
||||
}
|
||||
|
||||
SN_MK_PROC_DECL_STD(double, 512, , scalar_mul)
|
||||
{
|
||||
__mk_param_std(BUFFER, RIGHT_ANS_SCALAR, double);
|
||||
|
||||
register __m512d vec = _mm512_broadcastsd_pd(_mm_load_pd(scalar));
|
||||
for (size_t i = 0; i < count; i++) {
|
||||
register __m512d c0 = _mm512_mul_pd(right[i].f64_z[0], vec);
|
||||
register __m512d c1 = _mm512_mul_pd(right[i].f64_z[1], vec);
|
||||
|
||||
ans[i].f64_z[0] = c0;
|
||||
ans[i].f64_z[1] = c1;
|
||||
}
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
@@ -1,185 +1,185 @@
|
||||
#include "sn_target.h"
|
||||
|
||||
#if SN_IS_ARCH(SN_ARCH_X86_64)
|
||||
|
||||
#include "sn_intrinsic.h"
|
||||
#include "sn_intrinsic.std.h"
|
||||
#include <math.h>
|
||||
|
||||
static const float quality_threshold = 1e-6f;
|
||||
|
||||
SN_MK_PROC_DECL_STD(float, sse, , try_plu)
|
||||
{
|
||||
__mk_param_std(TILE, LEFT_RIGHT_ANS_SCALAR, float);
|
||||
|
||||
/* Aliases */
|
||||
MAT_KERNEL(float) *upper = left; /* U */
|
||||
MAT_KERNEL(float) *lower = right; /* L (unit diag) */
|
||||
MAT_KERNEL(float) *source = ans; /* A */
|
||||
unsigned char *pivot = (unsigned char *)&scalar->data[0]; /* length = 4 */
|
||||
int *success = (int *)&scalar->data[1];
|
||||
|
||||
/* Init permutation and outputs */
|
||||
pivot[0] = 0;
|
||||
pivot[1] = 1;
|
||||
pivot[2] = 2;
|
||||
pivot[3] = 3;
|
||||
*success = 1;
|
||||
|
||||
/* Working copy of A in column-major a[col][row], load via SIMD view */
|
||||
MAT_KERNEL(float) a;
|
||||
const __m128 z = _mm_setzero_ps();
|
||||
for (int c = 0; c < 4; ++c) {
|
||||
__m128 col = _mm_load_ps((float *)&source->f32_x[c]);
|
||||
_mm_storeu_ps((float *)&a.f32_x[c], col);
|
||||
_mm_store_ps((float *)&upper->f32_x[c], z);
|
||||
_mm_store_ps((float *)&lower->f32_x[c], z);
|
||||
}
|
||||
|
||||
const float eps = 1e-12f;
|
||||
|
||||
for (int k = 0; k < 4; ++k) {
|
||||
/* Pivot search on column k, rows k..3 */
|
||||
int p = k;
|
||||
float maxabs = fabsf(a.m[k][p]);
|
||||
for (int r = k + 1; r < 4; ++r) {
|
||||
float v = fabsf(a.m[k][r]);
|
||||
if (v > maxabs) {
|
||||
maxabs = v;
|
||||
p = r;
|
||||
}
|
||||
}
|
||||
|
||||
if (maxabs < eps) {
|
||||
*success = 0;
|
||||
/* leave outputs zeroed */
|
||||
return;
|
||||
}
|
||||
|
||||
/* Swap rows if needed */
|
||||
if (p != k) {
|
||||
for (int c = 0; c < 4; ++c) {
|
||||
float tmp = a.m[c][k];
|
||||
a.m[c][k] = a.m[c][p];
|
||||
a.m[c][p] = tmp;
|
||||
}
|
||||
unsigned char tmpi = pivot[k];
|
||||
pivot[k] = pivot[p];
|
||||
pivot[p] = tmpi;
|
||||
}
|
||||
|
||||
float pivot_val = a.m[k][k];
|
||||
|
||||
/* Eliminate below pivot: store multipliers in L column k */
|
||||
for (int r = k + 1; r < 4; ++r) {
|
||||
float factor = a.m[k][r] / pivot_val;
|
||||
lower->m[k][r] = factor;
|
||||
for (int c = k; c < 4; ++c) {
|
||||
a.m[c][r] -= factor * a.m[c][k];
|
||||
}
|
||||
}
|
||||
|
||||
/* Set U row k (columns k..3) and L diagonal */
|
||||
lower->m[k][k] = 1.0f;
|
||||
for (int c = k; c < 4; ++c) {
|
||||
upper->m[c][k] = a.m[c][k];
|
||||
}
|
||||
}
|
||||
|
||||
/* Ensure remaining diagonal ones for L */
|
||||
for (int d = 0; d < 4; ++d) {
|
||||
if (lower->m[d][d] == 0.0f)
|
||||
lower->m[d][d] = 1.0f;
|
||||
}
|
||||
}
|
||||
|
||||
#define DOT_F32_SSE(a, b, ans) \
|
||||
do { \
|
||||
__m128 _p = _mm_mul_ps((a), (b)); /* p0 p1 p2 p3 */ \
|
||||
__m128 _t = _mm_shuffle_ps(_p, _p, _MM_SHUFFLE(2, 3, 0, 1)); \
|
||||
_p = _mm_add_ps(_p, _t); \
|
||||
_t = _mm_movehl_ps(_t, _p); \
|
||||
ans = _mm_cvtss_f32(_mm_add_ss(_p, _t)); \
|
||||
} while (0)
|
||||
|
||||
#define FIND_MAX_F32_SSE(a, b) \
|
||||
do { \
|
||||
__m128 _t = _mm_movehl_ps(a, a); \
|
||||
a = _mm_max_ps(a, _t); \
|
||||
_t = _mm_shuffle_ps(a, a, _MM_SHUFFLE(2, 3, 0, 1)); \
|
||||
b = _mm_max_ps(a, _t); \
|
||||
} while (0)
|
||||
|
||||
/*
|
||||
* layout of scalarpack:
|
||||
*
|
||||
*/
|
||||
SN_MK_PROC_DECL_STD(float, sse, , quality)
|
||||
{
|
||||
__mk_param_std(KERNEL, RIGHT_ANS, float);
|
||||
|
||||
static const __m128 tiny_source = { .m128_f32 = { 1e-6f, 1e-6f, 1e-6f, 1e-6f } };
|
||||
|
||||
register __m128 tiny = _mm_load_ps(tiny_source.m128_f32);
|
||||
|
||||
register __m128 col0 = _mm_load_ps((float *)&right->f32_x[0]);
|
||||
register __m128 col1 = _mm_load_ps((float *)&right->f32_x[1]);
|
||||
register __m128 col2 = _mm_load_ps((float *)&right->f32_x[2]);
|
||||
register __m128 col3 = _mm_load_ps((float *)&right->f32_x[3]);
|
||||
|
||||
__m128 self_dot_src = { 0 };
|
||||
// try in reigister mix later
|
||||
DOT_F32_SSE(col0, col0, self_dot_src.m128_f32[0]);
|
||||
DOT_F32_SSE(col1, col1, self_dot_src.m128_f32[1]);
|
||||
DOT_F32_SSE(col2, col2, self_dot_src.m128_f32[2]);
|
||||
DOT_F32_SSE(col3, col3, self_dot_src.m128_f32[3]);
|
||||
|
||||
register __m128 self_dot = _mm_load_ps(self_dot_src.m128_f32);
|
||||
|
||||
register __m128 max;
|
||||
FIND_MAX_F32_SSE(self_dot, max);
|
||||
//float norm = _mm_cvtss_f32(max);
|
||||
|
||||
// min on cross
|
||||
register __m128 col_shuff_1 = _mm_shuffle_ps(col1, col1, _MM_SHUFFLE(0, 3, 2, 1));
|
||||
register __m128 col_shuff_2 = _mm_shuffle_ps(col2, col2, _MM_SHUFFLE(1, 0, 3, 2));
|
||||
register __m128 col_shuff_3 = _mm_shuffle_ps(col3, col3, _MM_SHUFFLE(2, 1, 0, 3));
|
||||
register __m128 min = _mm_min_ps(col0, col_shuff_1);
|
||||
register __m128 min0 = _mm_min_ps(col_shuff_2, col_shuff_3);
|
||||
min = _mm_min_ps(min, min0);
|
||||
|
||||
float quality = _mm_cvtss_f32(_mm_div_ps(min, _mm_add_ps(max, tiny)));
|
||||
ans->f32_x[0].m128_f32[0] = quality;
|
||||
if (quality < quality_threshold) {
|
||||
return;
|
||||
}
|
||||
|
||||
__m128 cross_dot_src[2];
|
||||
DOT_F32_SSE(col0, col1, cross_dot_src[0].m128_f32[0]);
|
||||
DOT_F32_SSE(col0, col2, cross_dot_src[0].m128_f32[1]);
|
||||
DOT_F32_SSE(col0, col3, cross_dot_src[0].m128_f32[2]);
|
||||
DOT_F32_SSE(col1, col2, cross_dot_src[0].m128_f32[3]);
|
||||
DOT_F32_SSE(col1, col3, cross_dot_src[1].m128_f32[0]);
|
||||
DOT_F32_SSE(col2, col3, cross_dot_src[1].m128_f32[1]);
|
||||
|
||||
register __m128 cross_dot_0 = _mm_load_ps(cross_dot_src[0].m128_f32);
|
||||
register __m128 cross_dot_1 = _mm_load_ps(cross_dot_src[1].m128_f32);
|
||||
|
||||
register __m128 base_0 = _mm_shuffle_ps(self_dot, self_dot, _MM_SHUFFLE(1, 0, 0, 0));
|
||||
register __m128 base_1 = _mm_shuffle_ps(self_dot, self_dot, _MM_SHUFFLE(3, 3, 2, 1));
|
||||
|
||||
register __m128 relation_0 =
|
||||
_mm_div_ps(cross_dot_0, _mm_add_ps(_mm_mul_ps(base_0, base_1), tiny));
|
||||
|
||||
base_0 = _mm_shuffle_ps(self_dot, self_dot, _MM_SHUFFLE(2, 3, 2, 1));
|
||||
base_1 = _mm_shuffle_ps(self_dot, self_dot, _MM_SHUFFLE(3, 3, 3, 3));
|
||||
|
||||
register __m128 relation_1 =
|
||||
_mm_div_ps(cross_dot_0, _mm_add_ps(_mm_mul_ps(base_0, base_1), tiny));
|
||||
|
||||
relation_0 = _mm_max_ps(relation_0, relation_1);
|
||||
FIND_MAX_F32_SSE(relation_0, relation_0);
|
||||
ans->f32_x[0].m128_f32[1] = _mm_cvtss_f32(relation_0);
|
||||
}
|
||||
|
||||
#endif
|
||||
#include "sn_target.h"
|
||||
|
||||
#if SN_IS_ARCH(SN_ARCH_X86_64)
|
||||
|
||||
#include "sn_intrinsic.h"
|
||||
#include "sn_intrinsic.std.h"
|
||||
#include <math.h>
|
||||
|
||||
static const float quality_threshold = 1e-6f;
|
||||
|
||||
SN_MK_PROC_DECL_STD(float, sse, , try_plu)
|
||||
{
|
||||
__mk_param_std(TILE, LEFT_RIGHT_ANS_SCALAR, float);
|
||||
|
||||
/* Aliases */
|
||||
MAT_KERNEL(float) *upper = left; /* U */
|
||||
MAT_KERNEL(float) *lower = right; /* L (unit diag) */
|
||||
MAT_KERNEL(float) *source = ans; /* A */
|
||||
unsigned char *pivot = (unsigned char *)&scalar->data[0]; /* length = 4 */
|
||||
int *success = (int *)&scalar->data[1];
|
||||
|
||||
/* Init permutation and outputs */
|
||||
pivot[0] = 0;
|
||||
pivot[1] = 1;
|
||||
pivot[2] = 2;
|
||||
pivot[3] = 3;
|
||||
*success = 1;
|
||||
|
||||
/* Working copy of A in column-major a[col][row], load via SIMD view */
|
||||
MAT_KERNEL(float) a;
|
||||
const __m128 z = _mm_setzero_ps();
|
||||
for (int c = 0; c < 4; ++c) {
|
||||
__m128 col = _mm_load_ps((float *)&source->f32_x[c]);
|
||||
_mm_storeu_ps((float *)&a.f32_x[c], col);
|
||||
_mm_store_ps((float *)&upper->f32_x[c], z);
|
||||
_mm_store_ps((float *)&lower->f32_x[c], z);
|
||||
}
|
||||
|
||||
const float eps = 1e-12f;
|
||||
|
||||
for (int k = 0; k < 4; ++k) {
|
||||
/* Pivot search on column k, rows k..3 */
|
||||
int p = k;
|
||||
float maxabs = fabsf(a.m[k][p]);
|
||||
for (int r = k + 1; r < 4; ++r) {
|
||||
float v = fabsf(a.m[k][r]);
|
||||
if (v > maxabs) {
|
||||
maxabs = v;
|
||||
p = r;
|
||||
}
|
||||
}
|
||||
|
||||
if (maxabs < eps) {
|
||||
*success = 0;
|
||||
/* leave outputs zeroed */
|
||||
return;
|
||||
}
|
||||
|
||||
/* Swap rows if needed */
|
||||
if (p != k) {
|
||||
for (int c = 0; c < 4; ++c) {
|
||||
float tmp = a.m[c][k];
|
||||
a.m[c][k] = a.m[c][p];
|
||||
a.m[c][p] = tmp;
|
||||
}
|
||||
unsigned char tmpi = pivot[k];
|
||||
pivot[k] = pivot[p];
|
||||
pivot[p] = tmpi;
|
||||
}
|
||||
|
||||
float pivot_val = a.m[k][k];
|
||||
|
||||
/* Eliminate below pivot: store multipliers in L column k */
|
||||
for (int r = k + 1; r < 4; ++r) {
|
||||
float factor = a.m[k][r] / pivot_val;
|
||||
lower->m[k][r] = factor;
|
||||
for (int c = k; c < 4; ++c) {
|
||||
a.m[c][r] -= factor * a.m[c][k];
|
||||
}
|
||||
}
|
||||
|
||||
/* Set U row k (columns k..3) and L diagonal */
|
||||
lower->m[k][k] = 1.0f;
|
||||
for (int c = k; c < 4; ++c) {
|
||||
upper->m[c][k] = a.m[c][k];
|
||||
}
|
||||
}
|
||||
|
||||
/* Ensure remaining diagonal ones for L */
|
||||
for (int d = 0; d < 4; ++d) {
|
||||
if (lower->m[d][d] == 0.0f)
|
||||
lower->m[d][d] = 1.0f;
|
||||
}
|
||||
}
|
||||
|
||||
#define DOT_F32_SSE(a, b, ans) \
|
||||
do { \
|
||||
__m128 _p = _mm_mul_ps((a), (b)); /* p0 p1 p2 p3 */ \
|
||||
__m128 _t = _mm_shuffle_ps(_p, _p, _MM_SHUFFLE(2, 3, 0, 1)); \
|
||||
_p = _mm_add_ps(_p, _t); \
|
||||
_t = _mm_movehl_ps(_t, _p); \
|
||||
ans = _mm_cvtss_f32(_mm_add_ss(_p, _t)); \
|
||||
} while (0)
|
||||
|
||||
#define FIND_MAX_F32_SSE(a, b) \
|
||||
do { \
|
||||
__m128 _t = _mm_movehl_ps(a, a); \
|
||||
a = _mm_max_ps(a, _t); \
|
||||
_t = _mm_shuffle_ps(a, a, _MM_SHUFFLE(2, 3, 0, 1)); \
|
||||
b = _mm_max_ps(a, _t); \
|
||||
} while (0)
|
||||
|
||||
/*
|
||||
* layout of scalarpack:
|
||||
*
|
||||
*/
|
||||
SN_MK_PROC_DECL_STD(float, sse, , quality)
|
||||
{
|
||||
__mk_param_std(KERNEL, RIGHT_ANS, float);
|
||||
|
||||
static const __m128 tiny_source = { .m128_f32 = { 1e-6f, 1e-6f, 1e-6f, 1e-6f } };
|
||||
|
||||
register __m128 tiny = _mm_load_ps(tiny_source.m128_f32);
|
||||
|
||||
register __m128 col0 = _mm_load_ps((float *)&right->f32_x[0]);
|
||||
register __m128 col1 = _mm_load_ps((float *)&right->f32_x[1]);
|
||||
register __m128 col2 = _mm_load_ps((float *)&right->f32_x[2]);
|
||||
register __m128 col3 = _mm_load_ps((float *)&right->f32_x[3]);
|
||||
|
||||
__m128 self_dot_src = { 0 };
|
||||
// try in reigister mix later
|
||||
DOT_F32_SSE(col0, col0, self_dot_src.m128_f32[0]);
|
||||
DOT_F32_SSE(col1, col1, self_dot_src.m128_f32[1]);
|
||||
DOT_F32_SSE(col2, col2, self_dot_src.m128_f32[2]);
|
||||
DOT_F32_SSE(col3, col3, self_dot_src.m128_f32[3]);
|
||||
|
||||
register __m128 self_dot = _mm_load_ps(self_dot_src.m128_f32);
|
||||
|
||||
register __m128 max;
|
||||
FIND_MAX_F32_SSE(self_dot, max);
|
||||
//float norm = _mm_cvtss_f32(max);
|
||||
|
||||
// min on cross
|
||||
register __m128 col_shuff_1 = _mm_shuffle_ps(col1, col1, _MM_SHUFFLE(0, 3, 2, 1));
|
||||
register __m128 col_shuff_2 = _mm_shuffle_ps(col2, col2, _MM_SHUFFLE(1, 0, 3, 2));
|
||||
register __m128 col_shuff_3 = _mm_shuffle_ps(col3, col3, _MM_SHUFFLE(2, 1, 0, 3));
|
||||
register __m128 min = _mm_min_ps(col0, col_shuff_1);
|
||||
register __m128 min0 = _mm_min_ps(col_shuff_2, col_shuff_3);
|
||||
min = _mm_min_ps(min, min0);
|
||||
|
||||
float quality = _mm_cvtss_f32(_mm_div_ps(min, _mm_add_ps(max, tiny)));
|
||||
ans->f32_x[0].m128_f32[0] = quality;
|
||||
if (quality < quality_threshold) {
|
||||
return;
|
||||
}
|
||||
|
||||
__m128 cross_dot_src[2];
|
||||
DOT_F32_SSE(col0, col1, cross_dot_src[0].m128_f32[0]);
|
||||
DOT_F32_SSE(col0, col2, cross_dot_src[0].m128_f32[1]);
|
||||
DOT_F32_SSE(col0, col3, cross_dot_src[0].m128_f32[2]);
|
||||
DOT_F32_SSE(col1, col2, cross_dot_src[0].m128_f32[3]);
|
||||
DOT_F32_SSE(col1, col3, cross_dot_src[1].m128_f32[0]);
|
||||
DOT_F32_SSE(col2, col3, cross_dot_src[1].m128_f32[1]);
|
||||
|
||||
register __m128 cross_dot_0 = _mm_load_ps(cross_dot_src[0].m128_f32);
|
||||
register __m128 cross_dot_1 = _mm_load_ps(cross_dot_src[1].m128_f32);
|
||||
|
||||
register __m128 base_0 = _mm_shuffle_ps(self_dot, self_dot, _MM_SHUFFLE(1, 0, 0, 0));
|
||||
register __m128 base_1 = _mm_shuffle_ps(self_dot, self_dot, _MM_SHUFFLE(3, 3, 2, 1));
|
||||
|
||||
register __m128 relation_0 =
|
||||
_mm_div_ps(cross_dot_0, _mm_add_ps(_mm_mul_ps(base_0, base_1), tiny));
|
||||
|
||||
base_0 = _mm_shuffle_ps(self_dot, self_dot, _MM_SHUFFLE(2, 3, 2, 1));
|
||||
base_1 = _mm_shuffle_ps(self_dot, self_dot, _MM_SHUFFLE(3, 3, 3, 3));
|
||||
|
||||
register __m128 relation_1 =
|
||||
_mm_div_ps(cross_dot_0, _mm_add_ps(_mm_mul_ps(base_0, base_1), tiny));
|
||||
|
||||
relation_0 = _mm_max_ps(relation_0, relation_1);
|
||||
FIND_MAX_F32_SSE(relation_0, relation_0);
|
||||
ans->f32_x[0].m128_f32[1] = _mm_cvtss_f32(relation_0);
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
@@ -1,29 +1,29 @@
|
||||
#include "sn_target.h"
|
||||
|
||||
#if SN_IS_ARCH(SN_ARCH_X86_64)
|
||||
|
||||
#include "sn_internal.h"
|
||||
#include "sn_intrinsic.h"
|
||||
|
||||
INTERNAL __m128i facIncrement = { 4, 4, 4, 4 };
|
||||
INTERNAL __m128i facBase = { 1, 2, 3, 4 };
|
||||
|
||||
INTERNAL uint64_t SN_DECL factorial_simd_sse(int n)
|
||||
{
|
||||
__m128i baseResult = facBase;
|
||||
__m128i facBaseLocal = facBase;
|
||||
const int cycle = (n - 3) >> 2;
|
||||
const uint32_t rest = (cycle << 2) + 1;
|
||||
for (size_t i = 0; i < cycle; i++) {
|
||||
facBaseLocal = _mm_add_epi32(facBaseLocal, facIncrement);
|
||||
baseResult = _mm_mullo_epi32(baseResult, facBaseLocal);
|
||||
}
|
||||
uint64_t result = (uint64_t)baseResult.m128i_i32[0] * (uint64_t)baseResult.m128i_i32[1] *
|
||||
(uint64_t)baseResult.m128i_i32[2] * (uint64_t)baseResult.m128i_i32[3];
|
||||
for (uint64_t i = rest; i < n; i++) {
|
||||
result *= i;
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
#endif
|
||||
#include "sn_target.h"
|
||||
|
||||
#if SN_IS_ARCH(SN_ARCH_X86_64)
|
||||
|
||||
#include "sn_internal.h"
|
||||
#include "sn_intrinsic.h"
|
||||
|
||||
INTERNAL __m128i facIncrement = { 4, 4, 4, 4 };
|
||||
INTERNAL __m128i facBase = { 1, 2, 3, 4 };
|
||||
|
||||
INTERNAL uint64_t SN_DECL factorial_simd_sse(int n)
|
||||
{
|
||||
__m128i baseResult = facBase;
|
||||
__m128i facBaseLocal = facBase;
|
||||
const int cycle = (n - 3) >> 2;
|
||||
const uint32_t rest = (cycle << 2) + 1;
|
||||
for (size_t i = 0; i < cycle; i++) {
|
||||
facBaseLocal = _mm_add_epi32(facBaseLocal, facIncrement);
|
||||
baseResult = _mm_mullo_epi32(baseResult, facBaseLocal);
|
||||
}
|
||||
uint64_t result = (uint64_t)baseResult.m128i_i32[0] * (uint64_t)baseResult.m128i_i32[1] *
|
||||
(uint64_t)baseResult.m128i_i32[2] * (uint64_t)baseResult.m128i_i32[3];
|
||||
for (uint64_t i = rest; i < n; i++) {
|
||||
result *= i;
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
@@ -1,51 +1,51 @@
|
||||
#include "sn_target.h"
|
||||
|
||||
#if SN_IS_ARCH(SN_ARCH_X86_64)
|
||||
|
||||
#include "sn_intrinsic.h"
|
||||
#include "StgSharpNative.h"
|
||||
|
||||
INTERNAL int SN_DECL city_hash_simplify_sse(byte const *str, int const length)
|
||||
{
|
||||
uint32_t hash = length, size = length << 1;
|
||||
byte *end = str + size, *ptr = str;
|
||||
|
||||
if (size < 4) {
|
||||
for (; ptr < end; ptr += 2) {
|
||||
hash = _mm_crc32_u16(hash, *ptr);
|
||||
}
|
||||
} else if (size < 16) {
|
||||
byte *last = end - 4;
|
||||
for (; ptr < end; ptr += 4) {
|
||||
hash = _mm_crc32_u32(hash, *(uint32_t *)ptr);
|
||||
}
|
||||
for (; ptr < end; ptr++) {
|
||||
hash = _mm_crc32_u16(hash, *ptr);
|
||||
}
|
||||
} else {
|
||||
byte *last_128 = end - 16;
|
||||
byte *last_32 = end - 4;
|
||||
uint64_t hash64 = size;
|
||||
for (; ptr < last_128; ptr += 16) {
|
||||
__m128i vec = _mm_loadu_si32((int *)ptr);
|
||||
hash64 = _mm_crc32_u64(hash64, _mm_extract_epi64(vec, 0));
|
||||
hash64 = _mm_crc32_u64(hash64, _mm_extract_epi64(vec, 1));
|
||||
}
|
||||
hash = _mm_crc32_u8(hash, hash64);
|
||||
hash = _mm_crc32_u8(hash, hash64 >> 32);
|
||||
for (; ptr < last_32; ptr += 4) {
|
||||
hash = _mm_crc32_u32(hash, *(uint32_t *)ptr);
|
||||
}
|
||||
for (; ptr < end; ptr += 2) {
|
||||
hash = _mm_crc32_u8(hash, *ptr);
|
||||
}
|
||||
}
|
||||
hash ^= hash >> 16;
|
||||
hash *= 0x85ebca6b;
|
||||
hash ^= hash >> 13;
|
||||
hash *= 0xc2b2ae35;
|
||||
hash ^= hash >> 16;
|
||||
return hash;
|
||||
}
|
||||
|
||||
#endif
|
||||
#include "sn_target.h"
|
||||
|
||||
#if SN_IS_ARCH(SN_ARCH_X86_64)
|
||||
|
||||
#include "sn_intrinsic.h"
|
||||
#include "StgSharpNative.h"
|
||||
|
||||
INTERNAL int SN_DECL city_hash_simplify_sse(byte const *str, int const length)
|
||||
{
|
||||
uint32_t hash = length, size = length << 1;
|
||||
byte *end = str + size, *ptr = str;
|
||||
|
||||
if (size < 4) {
|
||||
for (; ptr < end; ptr += 2) {
|
||||
hash = _mm_crc32_u16(hash, *ptr);
|
||||
}
|
||||
} else if (size < 16) {
|
||||
byte *last = end - 4;
|
||||
for (; ptr < end; ptr += 4) {
|
||||
hash = _mm_crc32_u32(hash, *(uint32_t *)ptr);
|
||||
}
|
||||
for (; ptr < end; ptr++) {
|
||||
hash = _mm_crc32_u16(hash, *ptr);
|
||||
}
|
||||
} else {
|
||||
byte *last_128 = end - 16;
|
||||
byte *last_32 = end - 4;
|
||||
uint64_t hash64 = size;
|
||||
for (; ptr < last_128; ptr += 16) {
|
||||
__m128i vec = _mm_loadu_si32((int *)ptr);
|
||||
hash64 = _mm_crc32_u64(hash64, _mm_extract_epi64(vec, 0));
|
||||
hash64 = _mm_crc32_u64(hash64, _mm_extract_epi64(vec, 1));
|
||||
}
|
||||
hash = _mm_crc32_u8(hash, hash64);
|
||||
hash = _mm_crc32_u8(hash, hash64 >> 32);
|
||||
for (; ptr < last_32; ptr += 4) {
|
||||
hash = _mm_crc32_u32(hash, *(uint32_t *)ptr);
|
||||
}
|
||||
for (; ptr < end; ptr += 2) {
|
||||
hash = _mm_crc32_u8(hash, *ptr);
|
||||
}
|
||||
}
|
||||
hash ^= hash >> 16;
|
||||
hash *= 0x85ebca6b;
|
||||
hash ^= hash >> 13;
|
||||
hash *= 0xc2b2ae35;
|
||||
hash ^= hash >> 16;
|
||||
return hash;
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
@@ -1,77 +1,77 @@
|
||||
#ifndef STB_IMAGE_IMPLEMENTATION
|
||||
#define STB_IMAGE_IMPLEMENTATION
|
||||
#endif
|
||||
#include "StgSharpNative.h"
|
||||
#include "gl.h"
|
||||
#include "../lib/glfw/glfw3.h"
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
|
||||
extern GladGLContext *currentContext;
|
||||
extern char infolog[512];
|
||||
|
||||
SN_API int SN_DECL 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;
|
||||
}
|
||||
|
||||
SN_API void SN_DECL 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);
|
||||
}
|
||||
|
||||
SN_API GLFWglproc SN_DECL loadGlfuncDefault(char const *procName)
|
||||
{
|
||||
void *ret = glfwGetProcAddress(procName);
|
||||
// printf("%llu\n", (uint64_t)ret);
|
||||
if (ret == NULL) {
|
||||
strcpy_s(infolog, 30, "Failed to load OpenGL api:");
|
||||
for (size_t i = 0; i < sizeof(procName); i++) {
|
||||
infolog[30 + i] = procName[i];
|
||||
}
|
||||
//printf("%s\n", infolog);
|
||||
}
|
||||
return (GLFWglproc)ret;
|
||||
}
|
||||
|
||||
SN_API unsigned int linkShaderProgram(GladGLContext *context, GLuint 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;
|
||||
}
|
||||
}
|
||||
|
||||
SN_API void SN_DECL loadImageData(char const *location, Image *out, imageLoader loader)
|
||||
{
|
||||
if (loader == NULL) {
|
||||
loader = stbi_load;
|
||||
}
|
||||
out->pixelPtr = loader(location, &(out->width), &(out->height), &(out->channel), 0);
|
||||
}
|
||||
SN_API void SN_DECL unloadImageData(Image *out)
|
||||
{
|
||||
free(out->pixelPtr);
|
||||
}
|
||||
|
||||
SN_API char *SN_DECL readLog()
|
||||
{
|
||||
infolog[511] = '\0';
|
||||
return infolog;
|
||||
}
|
||||
#ifndef STB_IMAGE_IMPLEMENTATION
|
||||
#define STB_IMAGE_IMPLEMENTATION
|
||||
#endif
|
||||
#include "StgSharpNative.h"
|
||||
#include "gl.h"
|
||||
#include "../lib/glfw/glfw3.h"
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
|
||||
extern GladGLContext *currentContext;
|
||||
extern char infolog[512];
|
||||
|
||||
SN_API int SN_DECL 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;
|
||||
}
|
||||
|
||||
SN_API void SN_DECL 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);
|
||||
}
|
||||
|
||||
SN_API GLFWglproc SN_DECL loadGlfuncDefault(char const *procName)
|
||||
{
|
||||
void *ret = glfwGetProcAddress(procName);
|
||||
// printf("%llu\n", (uint64_t)ret);
|
||||
if (ret == NULL) {
|
||||
strcpy_s(infolog, 30, "Failed to load OpenGL api:");
|
||||
for (size_t i = 0; i < sizeof(procName); i++) {
|
||||
infolog[30 + i] = procName[i];
|
||||
}
|
||||
//printf("%s\n", infolog);
|
||||
}
|
||||
return (GLFWglproc)ret;
|
||||
}
|
||||
|
||||
SN_API unsigned int linkShaderProgram(GladGLContext *context, GLuint 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;
|
||||
}
|
||||
}
|
||||
|
||||
SN_API void SN_DECL loadImageData(char const *location, Image *out, imageLoader loader)
|
||||
{
|
||||
if (loader == NULL) {
|
||||
loader = stbi_load;
|
||||
}
|
||||
out->pixelPtr = loader(location, &(out->width), &(out->height), &(out->channel), 0);
|
||||
}
|
||||
SN_API void SN_DECL unloadImageData(Image *out)
|
||||
{
|
||||
free(out->pixelPtr);
|
||||
}
|
||||
|
||||
SN_API char *SN_DECL readLog()
|
||||
{
|
||||
infolog[511] = '\0';
|
||||
return infolog;
|
||||
}
|
||||
|
||||
@@ -1,32 +1,32 @@
|
||||
#include "sn_intrinsic.h"
|
||||
#include "sn_internal.h"
|
||||
|
||||
INTERNAL void SN_DECL f32_normalize(VEC(float) *restrict source, VEC(float) *restrict target)
|
||||
{
|
||||
register __m128 s = _mm_load_ps(&source->f32_x);
|
||||
register __m128 a_length_sq = _mm_mul_ps(s, s);
|
||||
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_inv_length = _mm_rsqrt_ps(a_length_sq);
|
||||
s = _mm_mul_ps(s, a_inv_length);
|
||||
|
||||
__m128 dot_product = _mm_mul_ps(target->f32_x[0], s);
|
||||
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 b_orthogonal = _mm_sub_ps(target->f32_x[0], _mm_mul_ps(s, dot_product));
|
||||
|
||||
__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->f32_x[0] = _mm_mul_ps(b_orthogonal, b_inv_length);
|
||||
}
|
||||
#include "sn_intrinsic.h"
|
||||
#include "sn_internal.h"
|
||||
|
||||
INTERNAL void SN_DECL f32_normalize(VEC(float) *restrict source, VEC(float) *restrict target)
|
||||
{
|
||||
register __m128 s = _mm_load_ps(&source->f32_x);
|
||||
register __m128 a_length_sq = _mm_mul_ps(s, s);
|
||||
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_inv_length = _mm_rsqrt_ps(a_length_sq);
|
||||
s = _mm_mul_ps(s, a_inv_length);
|
||||
|
||||
__m128 dot_product = _mm_mul_ps(target->f32_x[0], s);
|
||||
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 b_orthogonal = _mm_sub_ps(target->f32_x[0], _mm_mul_ps(s, dot_product));
|
||||
|
||||
__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->f32_x[0] = _mm_mul_ps(b_orthogonal, b_inv_length);
|
||||
}
|
||||
|
||||
@@ -1,67 +1,67 @@
|
||||
#include "sn_intrinsic.h"
|
||||
#include "sn_internal.h"
|
||||
|
||||
static const int avxdot_indices[] = { 0, 4, 1, 5, 2, 3, 6, 7 };
|
||||
|
||||
INTERNAL void FORCEINLINE SN_DECL dot_41_sse(MAT_KERNEL(float) const *transpose,
|
||||
__m128 const *vector, __m128 *ans)
|
||||
{
|
||||
*ans = _mm_dp_ps(transpose->f32_x[0], *vector, 0B11110001);
|
||||
*ans = _mm_insert_ps(*ans, _mm_dp_ps(transpose->f32_x[1], *vector, 0B11110001),
|
||||
SSE_INSERT_SIMPLE(1, 1));
|
||||
*ans = _mm_insert_ps(*ans, _mm_dp_ps(transpose->f32_x[2], *vector, 0B11110001),
|
||||
SSE_INSERT_SIMPLE(1, 3));
|
||||
*ans = _mm_insert_ps(*ans, _mm_dp_ps(transpose->f32_x[3], *vector, 0B11110001),
|
||||
SSE_INSERT_SIMPLE(1, 4));
|
||||
}
|
||||
|
||||
INTERNAL void SN_DECL dot_41_avx(MAT_KERNEL(float) const *transpose, __m128 const *vector,
|
||||
__m128 *ans)
|
||||
{
|
||||
__m256 _double = _mm256_set_m128(vector[0], vector[0]);
|
||||
__m256 tmp = _mm256_dp_ps(transpose->f32_y[0], _double, 0B11110001);
|
||||
tmp = _mm256_blend_ps(tmp, _mm256_dp_ps(transpose->f32_y[0], _double, 0B11110010),
|
||||
0B00100010);
|
||||
*ans = _mm256_castps256_ps128(
|
||||
_mm256_permutevar8x32_ps(tmp, _mm256_loadu_epi32(avxdot_indices)));
|
||||
}
|
||||
|
||||
INTERNAL void SN_DECL dot_42_sse(MAT_KERNEL(float) const *transpose, __m128 const *vector,
|
||||
__m128 *ans)
|
||||
{
|
||||
ans[0] = _mm_dp_ps(transpose->f32_x[0], vector[0], 0B11110001);
|
||||
ans[0] = _mm_insert_ps(*ans, _mm_dp_ps(transpose->f32_x[1], vector[0], 0B11110001),
|
||||
SSE_INSERT_SIMPLE(1, 2));
|
||||
ans[0] = _mm_insert_ps(*ans, _mm_dp_ps(transpose->f32_x[2], vector[0], 0B11110001),
|
||||
SSE_INSERT_SIMPLE(1, 3));
|
||||
ans[0] = _mm_insert_ps(*ans, _mm_dp_ps(transpose->f32_x[3], vector[0], 0B11110001),
|
||||
SSE_INSERT_SIMPLE(1, 4));
|
||||
|
||||
ans[1] = _mm_dp_ps(transpose->f32_x[0], vector[1], 0B11110001);
|
||||
ans[1] = _mm_insert_ps(*ans, _mm_dp_ps(transpose->f32_x[1], vector[1], 0B11110001),
|
||||
SSE_INSERT_SIMPLE(1, 2));
|
||||
ans[1] = _mm_insert_ps(*ans, _mm_dp_ps(transpose->f32_x[2], vector[1], 0B11110001),
|
||||
SSE_INSERT_SIMPLE(1, 3));
|
||||
ans[1] = _mm_insert_ps(*ans, _mm_dp_ps(transpose->f32_x[3], vector[1], 0B11110001),
|
||||
SSE_INSERT_SIMPLE(1, 4));
|
||||
}
|
||||
|
||||
INTERNAL void SN_DECL dot_42_avx(MAT_KERNEL(float) const *transpose, __m128 const *vector,
|
||||
__m128 *ans)
|
||||
{
|
||||
__m256 temp = transpose->f32_y[0];
|
||||
__m256 vector_stream = _mm256_set_m128(vector[1], vector[0]);
|
||||
|
||||
__m256 result = _mm256_dp_ps(temp, vector_stream, 0B11110001);
|
||||
temp = _mm256_permute2f128_ps(temp, temp, 0B00000001);
|
||||
result = _mm256_blend_ps(result, _mm256_dp_ps(temp, vector_stream, 0B11110010), 0B00100010);
|
||||
|
||||
temp = transpose->f32_y[1];
|
||||
result = _mm256_blend_ps(result, _mm256_dp_ps(temp, vector_stream, 0B11110100), 0B01000100);
|
||||
temp = _mm256_permute2f128_ps(temp, temp, 0B00000001);
|
||||
result = _mm256_blend_ps(result, _mm256_dp_ps(temp, vector_stream, 0B11111000), 0B10001000);
|
||||
|
||||
ans[0] = _mm256_castps256_ps128(result);
|
||||
ans[1] = _mm256_extractf128_ps(result, 1);
|
||||
ans[1] = _mm_shuffle_ps(ans[1], ans[1], _MM_SHUFFLE(2, 3, 0, 1));
|
||||
}
|
||||
#include "sn_intrinsic.h"
|
||||
#include "sn_internal.h"
|
||||
|
||||
static const int avxdot_indices[] = { 0, 4, 1, 5, 2, 3, 6, 7 };
|
||||
|
||||
INTERNAL void FORCEINLINE SN_DECL dot_41_sse(MAT_KERNEL(float) const *transpose,
|
||||
__m128 const *vector, __m128 *ans)
|
||||
{
|
||||
*ans = _mm_dp_ps(transpose->f32_x[0], *vector, 0B11110001);
|
||||
*ans = _mm_insert_ps(*ans, _mm_dp_ps(transpose->f32_x[1], *vector, 0B11110001),
|
||||
SSE_INSERT_SIMPLE(1, 1));
|
||||
*ans = _mm_insert_ps(*ans, _mm_dp_ps(transpose->f32_x[2], *vector, 0B11110001),
|
||||
SSE_INSERT_SIMPLE(1, 3));
|
||||
*ans = _mm_insert_ps(*ans, _mm_dp_ps(transpose->f32_x[3], *vector, 0B11110001),
|
||||
SSE_INSERT_SIMPLE(1, 4));
|
||||
}
|
||||
|
||||
INTERNAL void SN_DECL dot_41_avx(MAT_KERNEL(float) const *transpose, __m128 const *vector,
|
||||
__m128 *ans)
|
||||
{
|
||||
__m256 _double = _mm256_set_m128(vector[0], vector[0]);
|
||||
__m256 tmp = _mm256_dp_ps(transpose->f32_y[0], _double, 0B11110001);
|
||||
tmp = _mm256_blend_ps(tmp, _mm256_dp_ps(transpose->f32_y[0], _double, 0B11110010),
|
||||
0B00100010);
|
||||
*ans = _mm256_castps256_ps128(
|
||||
_mm256_permutevar8x32_ps(tmp, _mm256_loadu_epi32(avxdot_indices)));
|
||||
}
|
||||
|
||||
INTERNAL void SN_DECL dot_42_sse(MAT_KERNEL(float) const *transpose, __m128 const *vector,
|
||||
__m128 *ans)
|
||||
{
|
||||
ans[0] = _mm_dp_ps(transpose->f32_x[0], vector[0], 0B11110001);
|
||||
ans[0] = _mm_insert_ps(*ans, _mm_dp_ps(transpose->f32_x[1], vector[0], 0B11110001),
|
||||
SSE_INSERT_SIMPLE(1, 2));
|
||||
ans[0] = _mm_insert_ps(*ans, _mm_dp_ps(transpose->f32_x[2], vector[0], 0B11110001),
|
||||
SSE_INSERT_SIMPLE(1, 3));
|
||||
ans[0] = _mm_insert_ps(*ans, _mm_dp_ps(transpose->f32_x[3], vector[0], 0B11110001),
|
||||
SSE_INSERT_SIMPLE(1, 4));
|
||||
|
||||
ans[1] = _mm_dp_ps(transpose->f32_x[0], vector[1], 0B11110001);
|
||||
ans[1] = _mm_insert_ps(*ans, _mm_dp_ps(transpose->f32_x[1], vector[1], 0B11110001),
|
||||
SSE_INSERT_SIMPLE(1, 2));
|
||||
ans[1] = _mm_insert_ps(*ans, _mm_dp_ps(transpose->f32_x[2], vector[1], 0B11110001),
|
||||
SSE_INSERT_SIMPLE(1, 3));
|
||||
ans[1] = _mm_insert_ps(*ans, _mm_dp_ps(transpose->f32_x[3], vector[1], 0B11110001),
|
||||
SSE_INSERT_SIMPLE(1, 4));
|
||||
}
|
||||
|
||||
INTERNAL void SN_DECL dot_42_avx(MAT_KERNEL(float) const *transpose, __m128 const *vector,
|
||||
__m128 *ans)
|
||||
{
|
||||
__m256 temp = transpose->f32_y[0];
|
||||
__m256 vector_stream = _mm256_set_m128(vector[1], vector[0]);
|
||||
|
||||
__m256 result = _mm256_dp_ps(temp, vector_stream, 0B11110001);
|
||||
temp = _mm256_permute2f128_ps(temp, temp, 0B00000001);
|
||||
result = _mm256_blend_ps(result, _mm256_dp_ps(temp, vector_stream, 0B11110010), 0B00100010);
|
||||
|
||||
temp = transpose->f32_y[1];
|
||||
result = _mm256_blend_ps(result, _mm256_dp_ps(temp, vector_stream, 0B11110100), 0B01000100);
|
||||
temp = _mm256_permute2f128_ps(temp, temp, 0B00000001);
|
||||
result = _mm256_blend_ps(result, _mm256_dp_ps(temp, vector_stream, 0B11111000), 0B10001000);
|
||||
|
||||
ans[0] = _mm256_castps256_ps128(result);
|
||||
ans[1] = _mm256_extractf128_ps(result, 1);
|
||||
ans[1] = _mm_shuffle_ps(ans[1], ans[1], _MM_SHUFFLE(2, 3, 0, 1));
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user