Using new file structure. Use new regexir display method. Fix line dependency error in prefix analysing.
Signed-off-by: Nitload <YoumuLiu_NSI@whv0t.onmicrosoft.com>
This commit is contained in:
@@ -0,0 +1,60 @@
|
||||
#ifndef SNative
|
||||
#define SNative
|
||||
|
||||
#ifdef __cplusplus
|
||||
#error "This header is not meant to be included in C++ code. StgSharp.Native is a C library and should be used with C linkage."
|
||||
#endif
|
||||
|
||||
#include "sn_internal.h"
|
||||
#include "sn_target.h"
|
||||
|
||||
#define STBIDEF SN_API
|
||||
#include "../lib/stbi/stb_image.h"
|
||||
|
||||
#include "gl.h"
|
||||
// #include "wgl.h"
|
||||
// #define GLFWAPI INTERNAL
|
||||
#include "glfw\glfw3.h"
|
||||
#include <immintrin.h>
|
||||
#include <assert.h>
|
||||
#include <glfw_function.h>
|
||||
|
||||
#define byte char
|
||||
#define cs_char uint16_t
|
||||
#define sn_null_assert(ptr) assert(ptr != NULL)
|
||||
|
||||
#ifndef SN_
|
||||
#endif
|
||||
|
||||
typedef struct Image {
|
||||
int width;
|
||||
int height;
|
||||
int channel;
|
||||
char *pixelPtr;
|
||||
} Image;
|
||||
|
||||
typedef char *(*imageLoader)(char const *filename, int *x, int *y, int *channels_in_file,
|
||||
int desired_channels);
|
||||
|
||||
extern SN_API char infolog[512];
|
||||
SN_API int SN_DECL glCheckShaderStat(GladGLContext *context, uint64_t shaderHandle, int key,
|
||||
char **logRef);
|
||||
SN_API void SN_DECL initGL(int majorVersion, int minorVersion);
|
||||
SN_API void SN_DECL loadImageData(char *location, Image *out, imageLoader loader);
|
||||
SN_API GLFWglproc SN_DECL loadGlfuncDefault(char *procName);
|
||||
SN_API void SN_DECL unloadImageData(Image *out);
|
||||
SN_API char *SN_DECL readLog(void);
|
||||
SN_API void SN_DECL load_glfw_functions(GLFWFunctionTable *table);
|
||||
SN_API void SN_DECL load_intrinsic_function(void *intrinsic_context, uint64_t id);
|
||||
SN_API SIMDID SN_DECL sn_get_simd_level_global();
|
||||
/* Per-core variant: always re-executes CPUID, never caches.
|
||||
* Must be called on the target core (after affinity is set). */
|
||||
SN_API SIMDID SN_DECL sn_get_simd_level_local();
|
||||
SN_API SIMDID SN_DECL sn_get_unite_simd(SIMDID left, SIMDID right);
|
||||
SN_API int SN_DECL sn_compare_simd(SIMDID left, SIMDID right);
|
||||
SN_API void SN_DECL sn_set_thread_affinity(int core_id, int numa_id);
|
||||
SN_API void* SN_DECL sn_numa_alloc(size_t size, int numa_id);
|
||||
SN_API void SN_DECL sn_numa_free(void *ptr, size_t size, int numa_id);
|
||||
SN_API int SN_DECL sn_get_numa_each(int numa_id, uint64_t *internal, uint32_t *global);
|
||||
SN_API int SN_DECL sn_get_numa_overall(int *out_numa_count, int *count_of_each_numa);
|
||||
#endif
|
||||
File diff suppressed because one or more lines are too long
@@ -0,0 +1,146 @@
|
||||
#ifndef GLFW_FUNCTION_TABLE_H
|
||||
#define GLFW_FUNCTION_TABLE_H
|
||||
|
||||
#include "../lib/glfw/glfw3.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
typedef struct GLFWFunctionTable {
|
||||
GLFWcursor *(*glfwCreateCursor)(const GLFWimage *image, int xhot, int yhot);
|
||||
GLFWcursor *(*glfwCreateStandardCursor)(int shape);
|
||||
GLFWwindow *(*glfwCreateWindow)(int width, int height, const char *title,
|
||||
GLFWmonitor *monitor, GLFWwindow *share);
|
||||
void (*glfwDefaultWindowHints)(void);
|
||||
void (*glfwDestroyCursor)(GLFWcursor *cursor);
|
||||
void (*glfwDestroyWindow)(GLFWwindow *window);
|
||||
int (*glfwExtensionSupported)(const char *extension);
|
||||
void (*glfwFocusWindow)(GLFWwindow *window);
|
||||
const char *(*glfwGetClipboardString)(GLFWwindow *window);
|
||||
GLFWwindow *(*glfwGetCurrentContext)(void);
|
||||
void (*glfwGetCursorPos)(GLFWwindow *window, double *xpos, double *ypos);
|
||||
int (*glfwGetError)(const char **description);
|
||||
void (*glfwGetFrameBufferSize)(GLFWwindow *window, int *width, int *height);
|
||||
const char *(*glfwGetGamepadName)(int jid);
|
||||
int (*glfwGetGamepadState)(int jid, GLFWgamepadstate *state);
|
||||
const GLFWgammaramp *(*glfwGetGammaRamp)(GLFWmonitor *monitor);
|
||||
int (*glfwGetInputMode)(GLFWwindow *window, int mode);
|
||||
const float *(*glfwGetJoystickAxes)(int jid, int *count);
|
||||
const unsigned char *(*glfwGetJoystickButtons)(int jid, int *count);
|
||||
const char *(*glfwGetJoystickGUID)(int jid);
|
||||
const unsigned char *(*glfwGetJoystickHats)(int jid, int *count);
|
||||
const char *(*glfwGetJoystickName)(int jid);
|
||||
void *(*glfwGetJoystickUserPointer)(int jid);
|
||||
int (*glfwGetKey)(GLFWwindow *window, int key);
|
||||
const char *(*glfwGetKeyName)(int key, int scancode);
|
||||
int (*glfwGetKeyScancode)(int key);
|
||||
void (*glfwGetMonitorContentScale)(GLFWmonitor *monitor, float *xscale, float *yscale);
|
||||
const char *(*glfwGetMonitorName)(GLFWmonitor *monitor);
|
||||
void (*glfwGetMonitorPhysicalSize)(GLFWmonitor *monitor, int *widthMM, int *heightMM);
|
||||
void (*glfwGetMonitorPos)(GLFWmonitor *monitor, int *xpos, int *ypos);
|
||||
GLFWmonitor **(*glfwGetMonitors)(int *count);
|
||||
void *(*glfwGetMonitorUserPointer)(GLFWmonitor *monitor);
|
||||
void (*glfwGetMonitorWorkarea)(GLFWmonitor *monitor, int *xpos, int *ypos, int *width,
|
||||
int *height);
|
||||
int (*glfwGetMouseButton)(GLFWwindow *window, int button);
|
||||
GLFWmonitor *(*glfwGetPrimaryMonitor)(void);
|
||||
GLFWglproc (*glfwGetProcAddress)(const char *procname);
|
||||
const char **(*glfwGetRequiredInstanceExtensions)(unsigned int *count);
|
||||
double (*glfwGetTime)(void);
|
||||
unsigned long long (*glfwGetTimerFrequency)(void);
|
||||
unsigned long long (*glfwGetTimerValue)(void);
|
||||
void (*glfwGetVersion)(int *major, int *minor, int *rev);
|
||||
const char *(*glfwGetVersionString)(void);
|
||||
const GLFWvidmode *(*glfwGetVideoMode)(GLFWmonitor *monitor);
|
||||
const GLFWvidmode *(*glfwGetVideoModes)(GLFWmonitor *monitor, int *count);
|
||||
int (*glfwGetWindowAttrib)(GLFWwindow *window, int attrib);
|
||||
void (*glfwGetWindowContentScale)(GLFWwindow *window, float *xscale, float *yscale);
|
||||
void (*glfwGetWindowFrameSize)(GLFWwindow *window, int *left, int *top, int *right,
|
||||
int *bottom);
|
||||
GLFWmonitor *(*glfwGetWindowMonitor)(GLFWwindow *window);
|
||||
float (*glfwGetWindowOpacity)(GLFWwindow *window);
|
||||
void (*glfwGetWindowPos)(GLFWwindow *window, int *xpos, int *ypos);
|
||||
void (*glfwGetWindowSize)(GLFWwindow *window, int *width, int *height);
|
||||
void *(*glfwGetWindowUserPointer)(GLFWwindow *window);
|
||||
void (*glfwHideWindow)(GLFWwindow *window);
|
||||
void (*glfwIconifyWindow)(GLFWwindow *window);
|
||||
int (*glfwInit)(void);
|
||||
void (*glfwInitHint)(int hint, int value);
|
||||
int (*glfwJoystickIsGamePad)(int jid);
|
||||
int (*glfwJoystickPresent)(int jid);
|
||||
void (*glfwMakeContextCurrent)(GLFWwindow *window);
|
||||
void (*glfwMaximizeWindow)(GLFWwindow *window);
|
||||
void (*glfwPollEvents)(void);
|
||||
void (*glfwPostEmptyEvent)(void);
|
||||
int (*glfwRawMouseMotionSupported)(void);
|
||||
void (*glfwRequestWindowAttention)(GLFWwindow *window);
|
||||
void (*glfwRestoreWindow)(GLFWwindow *window);
|
||||
GLFWcharfun (*glfwSetCharCallback)(GLFWwindow *window, GLFWcharfun callback);
|
||||
GLFWcharmodsfun (*glfwSetCharModsCallback)(GLFWwindow *window, GLFWcharmodsfun callback);
|
||||
void (*glfwSetClipboardString)(GLFWwindow *window, const char *str);
|
||||
void (*glfwSetCursor)(GLFWwindow *window, GLFWcursor *cursor);
|
||||
GLFWcursorenterfun (*glfwSetCursorEnterCallback)(GLFWwindow *window,
|
||||
GLFWcursorenterfun callback);
|
||||
void (*glfwSetCursorPos)(GLFWwindow *window, double xpos, double ypos);
|
||||
GLFWcursorposfun (*glfwSetCursorPosCallback)(GLFWwindow *window, GLFWcursorposfun callback);
|
||||
GLFWdropfun (*glfwSetDropCallback)(GLFWwindow *window, GLFWdropfun callback);
|
||||
GLFWerrorfun (*glfwSetErrorCallback)(GLFWerrorfun callback);
|
||||
GLFWframebuffersizefun (*glfwSetFramebufferSizeCallback)(GLFWwindow *window,
|
||||
GLFWframebuffersizefun callback);
|
||||
void (*glfwSetGamma)(GLFWmonitor *monitor, float gamma);
|
||||
void (*glfwSetGammaRamp)(GLFWmonitor *monitor, const GLFWgammaramp *ramp);
|
||||
void (*glfwSetInputMode)(GLFWwindow *window, int mode, int value);
|
||||
GLFWjoystickfun (*glfwSetJoystickCallback)(GLFWjoystickfun callback);
|
||||
void (*glfwSetJoystickUserPointer)(int jid, void *pointer);
|
||||
GLFWkeyfun (*glfwSetKeyCallback)(GLFWwindow *window, GLFWkeyfun callback);
|
||||
GLFWmonitorfun (*glfwSetMonitorCallback)(GLFWmonitorfun callback);
|
||||
void (*glfwSetMonitorUserPointer)(GLFWmonitor *monitor, void *pointer);
|
||||
GLFWmousebuttonfun (*glfwSetMouseButtonCallback)(GLFWwindow *window,
|
||||
GLFWmousebuttonfun callback);
|
||||
GLFWscrollfun (*glfwSetScrollCallback)(GLFWwindow *window, GLFWscrollfun callback);
|
||||
void (*glfwSetTime)(double time);
|
||||
void (*glfwSetWindowAspectRatio)(GLFWwindow *window, int numer, int denom);
|
||||
void (*glfwSetWindowAttrib)(GLFWwindow *window, int attrib, int value);
|
||||
GLFWwindowclosefun (*glfwSetWindowCloseCallback)(GLFWwindow *window,
|
||||
GLFWwindowclosefun callback);
|
||||
GLFWwindowcontentscalefun (*glfwSetWindowContentScaleCallback)(
|
||||
GLFWwindow *window, GLFWwindowcontentscalefun callback);
|
||||
GLFWwindowfocusfun (*glfwSetWindowFocusCallback)(GLFWwindow *window,
|
||||
GLFWwindowfocusfun callback);
|
||||
void (*glfwSetWindowIcon)(GLFWwindow *window, int count, const GLFWimage *images);
|
||||
GLFWwindowiconifyfun (*glfwSetWindowIconifyCallback)(GLFWwindow *window,
|
||||
GLFWwindowiconifyfun callback);
|
||||
GLFWwindowmaximizefun (*glfwSetWindowMaximizeCallback)(GLFWwindow *window,
|
||||
GLFWwindowmaximizefun callback);
|
||||
void (*glfwSetWindowMonitor)(GLFWwindow *window, GLFWmonitor *monitor, int xpos, int ypos,
|
||||
int width, int height, int refreshRate);
|
||||
void (*glfwSetWindowOpacity)(GLFWwindow *window, float opacity);
|
||||
void (*glfwSetWindowPos)(GLFWwindow *window, int xpos, int ypos);
|
||||
GLFWwindowposfun (*glfwSetWindowPosCallback)(GLFWwindow *window, GLFWwindowposfun callback);
|
||||
GLFWwindowrefreshfun (*glfwSetWindowRefreshCallback)(GLFWwindow *window,
|
||||
GLFWwindowrefreshfun callback);
|
||||
void (*glfwSetWindowShouldClose)(GLFWwindow *window, int value);
|
||||
void (*glfwSetWindowSize)(GLFWwindow *window, int width, int height);
|
||||
GLFWwindowsizefun (*glfwSetWindowSizeCallback)(GLFWwindow *window,
|
||||
GLFWwindowsizefun callback);
|
||||
void (*glfwSetWindowSizeLimits)(GLFWwindow *window, int minwidth, int minheight,
|
||||
int maxwidth, int maxheight);
|
||||
void (*glfwSetWindowTitle)(GLFWwindow *window, const char *title);
|
||||
void (*glfwSetWindowUserPointer)(GLFWwindow *window, void *pointer);
|
||||
void (*glfwShowWindow)(GLFWwindow *window);
|
||||
void (*glfwSwapBuffers)(GLFWwindow *window);
|
||||
void (*glfwSwapInterval)(int interval);
|
||||
void (*glfwTerminate)(void);
|
||||
int (*glfwUpdateGamePadMappings)(const char *str);
|
||||
int (*glfwVulkanSupported)(void);
|
||||
void (*glfwWaitEvents)(void);
|
||||
void (*glfwWaitEventsTimeout)(double timeout);
|
||||
void (*glfwWindowHint)(int hint, int value);
|
||||
void (*glfwWindowHintString)(int hint, const char *value);
|
||||
int (*glfwWindowShouldClose)(GLFWwindow *window);
|
||||
} GLFWFunctionTable;
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif
|
||||
@@ -0,0 +1,310 @@
|
||||
#ifndef __khrplatform_h_
|
||||
#define __khrplatform_h_
|
||||
|
||||
/*
|
||||
** Copyright (c) 2008-2018 The Khronos Group Inc.
|
||||
**
|
||||
** Permission is hereby granted, free of charge, to any person obtaining a
|
||||
** copy of this software and/or associated documentation files (the
|
||||
** "Materials"), to deal in the Materials without restriction, including
|
||||
** without limitation the rights to use, copy, modify, merge, publish,
|
||||
** distribute, sublicense, and/or sell copies of the Materials, and to
|
||||
** permit persons to whom the Materials are furnished to do so, subject to
|
||||
** the following conditions:
|
||||
**
|
||||
** The above copyright notice and this permission notice shall be included
|
||||
** in all copies or substantial portions of the Materials.
|
||||
**
|
||||
** THE MATERIALS ARE PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
||||
** EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
||||
** MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
|
||||
** IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
|
||||
** CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
|
||||
** TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
|
||||
** MATERIALS OR THE USE OR OTHER DEALINGS IN THE MATERIALS.
|
||||
*/
|
||||
|
||||
/* Khronos platform-specific types and definitions.
|
||||
*
|
||||
* The master copy of khrplatform.h is maintained in the Khronos EGL
|
||||
* Registry repository at https://github.com/KhronosGroup/EGL-Registry
|
||||
* The last semantic modification to khrplatform.h was at commit ID:
|
||||
* 67a3e0864c2d75ea5287b9f3d2eb74a745936692
|
||||
*
|
||||
* Adopters may modify this file to suit their platform. Adopters are
|
||||
* encouraged to submit platform specific modifications to the Khronos
|
||||
* group so that they can be included in future versions of this file.
|
||||
* Please submit changes by filing pull requests or issues on
|
||||
* the EGL Registry repository linked above.
|
||||
*
|
||||
*
|
||||
* See the Implementer's Guidelines for information about where this file
|
||||
* should be located on your system and for more details of its use:
|
||||
* http://www.khronos.org/registry/implementers_guide.pdf
|
||||
*
|
||||
* This file should be included as
|
||||
* #include <KHR/khrplatform.h>
|
||||
* by Khronos client API header files that use its types and defines.
|
||||
*
|
||||
* The types in khrplatform.h should only be used to define API-specific types.
|
||||
*
|
||||
* Types defined in khrplatform.h:
|
||||
* khronos_int8_t signed 8 bit
|
||||
* khronos_uint8_t unsigned 8 bit
|
||||
* khronos_int16_t signed 16 bit
|
||||
* khronos_uint16_t unsigned 16 bit
|
||||
* khronos_int32_t signed 32 bit
|
||||
* khronos_uint32_t unsigned 32 bit
|
||||
* khronos_int64_t signed 64 bit
|
||||
* khronos_uint64_t unsigned 64 bit
|
||||
* khronos_intptr_t signed same number of bits as a pointer
|
||||
* khronos_uintptr_t unsigned same number of bits as a pointer
|
||||
* khronos_ssize_t signed size
|
||||
* khronos_usize_t unsigned size
|
||||
* khronos_float_t signed 32 bit floating point
|
||||
* khronos_time_ns_t unsigned 64 bit time in nanoseconds
|
||||
* khronos_utime_nanoseconds_t unsigned time interval or absolute time in
|
||||
* nanoseconds
|
||||
* khronos_stime_nanoseconds_t signed time interval in nanoseconds
|
||||
* khronos_boolean_enum_t enumerated boolean type. This should
|
||||
* only be used as a base type when a client API's boolean type is
|
||||
* an enum. Client APIs which use an integer or other type for
|
||||
* booleans cannot use this as the base type for their boolean.
|
||||
*
|
||||
* Tokens defined in khrplatform.h:
|
||||
*
|
||||
* KHRONOS_FALSE, KHRONOS_TRUE Enumerated boolean false/true values.
|
||||
*
|
||||
* KHRONOS_SUPPORT_INT64 is 1 if 64 bit integers are supported; otherwise 0.
|
||||
* KHRONOS_SUPPORT_FLOAT is 1 if floats are supported; otherwise 0.
|
||||
*
|
||||
* Calling convention macros defined in this file:
|
||||
* KHRONOS_APICALL
|
||||
* KHRONOS_APIENTRY
|
||||
* KHRONOS_APIATTRIBUTES
|
||||
*
|
||||
* These may be used in function prototypes as:
|
||||
*
|
||||
* KHRONOS_APICALL void KHRONOS_APIENTRY funcname(
|
||||
* int arg1,
|
||||
* int arg2) KHRONOS_APIATTRIBUTES;
|
||||
*/
|
||||
|
||||
#if defined(__SCITECH_SNAP__) && !defined(KHRONOS_STATIC)
|
||||
#define KHRONOS_STATIC 1
|
||||
#endif
|
||||
|
||||
/*-------------------------------------------------------------------------
|
||||
* Definition of KHRONOS_APICALL
|
||||
*-------------------------------------------------------------------------
|
||||
* This precedes the return type of the function in the function prototype.
|
||||
*/
|
||||
#if defined(KHRONOS_STATIC)
|
||||
/* If the preprocessor constant KHRONOS_STATIC is defined, make the
|
||||
* header compatible with static linking. */
|
||||
#define KHRONOS_APICALL
|
||||
#elif defined(_WIN32)
|
||||
#define KHRONOS_APICALL __declspec(dllimport)
|
||||
#elif defined(__SYMBIAN32__)
|
||||
#define KHRONOS_APICALL IMPORT_C
|
||||
#elif defined(__ANDROID__)
|
||||
#define KHRONOS_APICALL __attribute__((visibility("default")))
|
||||
#else
|
||||
#define KHRONOS_APICALL
|
||||
#endif
|
||||
|
||||
/*-------------------------------------------------------------------------
|
||||
* Definition of KHRONOS_APIENTRY
|
||||
*-------------------------------------------------------------------------
|
||||
* This follows the return type of the function and precedes the function
|
||||
* name in the function prototype.
|
||||
*/
|
||||
#if defined(_WIN32) && !defined(_WIN32_WCE) && !defined(__SCITECH_SNAP__)
|
||||
/* Win32 but not WinCE */
|
||||
#define KHRONOS_APIENTRY __stdcall
|
||||
#else
|
||||
#define KHRONOS_APIENTRY
|
||||
#endif
|
||||
|
||||
/*-------------------------------------------------------------------------
|
||||
* Definition of KHRONOS_APIATTRIBUTES
|
||||
*-------------------------------------------------------------------------
|
||||
* This follows the closing parenthesis of the function prototype arguments.
|
||||
*/
|
||||
#if defined(__ARMCC_2__)
|
||||
#define KHRONOS_APIATTRIBUTES __softfp
|
||||
#else
|
||||
#define KHRONOS_APIATTRIBUTES
|
||||
#endif
|
||||
|
||||
/*-------------------------------------------------------------------------
|
||||
* basic type definitions
|
||||
*-----------------------------------------------------------------------*/
|
||||
#if (defined(__STDC_VERSION__) && __STDC_VERSION__ >= 199901L) || defined(__GNUC__) || \
|
||||
defined(__SCO__) || defined(__USLC__)
|
||||
|
||||
/*
|
||||
* Using <stdint.h>
|
||||
*/
|
||||
#include <stdint.h>
|
||||
typedef int32_t khronos_int32_t;
|
||||
typedef uint32_t khronos_uint32_t;
|
||||
typedef int64_t khronos_int64_t;
|
||||
typedef uint64_t khronos_uint64_t;
|
||||
#define KHRONOS_SUPPORT_INT64 1
|
||||
#define KHRONOS_SUPPORT_FLOAT 1
|
||||
/*
|
||||
* To support platform where unsigned long cannot be used interchangeably with
|
||||
* inptr_t (e.g. CHERI-extended ISAs), we can use the stdint.h intptr_t.
|
||||
* Ideally, we could just use (u)intptr_t everywhere, but this could result in
|
||||
* ABI breakage if khronos_uintptr_t is changed from unsigned long to
|
||||
* unsigned long long or similar (this results in different C++ name mangling).
|
||||
* To avoid changes for existing platforms, we restrict usage of intptr_t to
|
||||
* platforms where the size of a pointer is larger than the size of long.
|
||||
*/
|
||||
#if defined(__SIZEOF_LONG__) && defined(__SIZEOF_POINTER__)
|
||||
#if __SIZEOF_POINTER__ > __SIZEOF_LONG__
|
||||
#define KHRONOS_USE_INTPTR_T
|
||||
#endif
|
||||
#endif
|
||||
|
||||
#elif defined(__VMS) || defined(__sgi)
|
||||
|
||||
/*
|
||||
* Using <inttypes.h>
|
||||
*/
|
||||
#include <inttypes.h>
|
||||
typedef int32_t khronos_int32_t;
|
||||
typedef uint32_t khronos_uint32_t;
|
||||
typedef int64_t khronos_int64_t;
|
||||
typedef uint64_t khronos_uint64_t;
|
||||
#define KHRONOS_SUPPORT_INT64 1
|
||||
#define KHRONOS_SUPPORT_FLOAT 1
|
||||
|
||||
#elif defined(_WIN32) && !defined(__SCITECH_SNAP__)
|
||||
|
||||
/*
|
||||
* Win32
|
||||
*/
|
||||
typedef __int32 khronos_int32_t;
|
||||
typedef unsigned __int32 khronos_uint32_t;
|
||||
typedef __int64 khronos_int64_t;
|
||||
typedef unsigned __int64 khronos_uint64_t;
|
||||
#define KHRONOS_SUPPORT_INT64 1
|
||||
#define KHRONOS_SUPPORT_FLOAT 1
|
||||
|
||||
#elif defined(__sun__) || defined(__digital__)
|
||||
|
||||
/*
|
||||
* Sun or Digital
|
||||
*/
|
||||
typedef int khronos_int32_t;
|
||||
typedef unsigned int khronos_uint32_t;
|
||||
#if defined(__arch64__) || defined(_LP64)
|
||||
typedef long int khronos_int64_t;
|
||||
typedef unsigned long int khronos_uint64_t;
|
||||
#else
|
||||
typedef long long int khronos_int64_t;
|
||||
typedef unsigned long long int khronos_uint64_t;
|
||||
#endif /* __arch64__ */
|
||||
#define KHRONOS_SUPPORT_INT64 1
|
||||
#define KHRONOS_SUPPORT_FLOAT 1
|
||||
|
||||
#elif 0
|
||||
|
||||
/*
|
||||
* Hypothetical platform with no float or int64 support
|
||||
*/
|
||||
typedef int khronos_int32_t;
|
||||
typedef unsigned int khronos_uint32_t;
|
||||
#define KHRONOS_SUPPORT_INT64 0
|
||||
#define KHRONOS_SUPPORT_FLOAT 0
|
||||
|
||||
#else
|
||||
|
||||
/*
|
||||
* Generic fallback
|
||||
*/
|
||||
#include <stdint.h>
|
||||
typedef int32_t khronos_int32_t;
|
||||
typedef uint32_t khronos_uint32_t;
|
||||
typedef int64_t khronos_int64_t;
|
||||
typedef uint64_t khronos_uint64_t;
|
||||
#define KHRONOS_SUPPORT_INT64 1
|
||||
#define KHRONOS_SUPPORT_FLOAT 1
|
||||
|
||||
#endif
|
||||
|
||||
/*
|
||||
* Types that are (so far) the same on all platforms
|
||||
*/
|
||||
typedef signed char khronos_int8_t;
|
||||
typedef unsigned char khronos_uint8_t;
|
||||
typedef signed short int khronos_int16_t;
|
||||
typedef unsigned short int khronos_uint16_t;
|
||||
|
||||
/*
|
||||
* Types that differ between LLP64 and LP64 architectures - in LLP64,
|
||||
* pointers are 64 bits, but 'long' is still 32 bits. Win64 appears
|
||||
* to be the only LLP64 architecture in current use.
|
||||
*/
|
||||
#ifdef KHRONOS_USE_INTPTR_T
|
||||
typedef intptr_t khronos_intptr_t;
|
||||
typedef uintptr_t khronos_uintptr_t;
|
||||
#elif defined(_WIN64)
|
||||
typedef signed long long int khronos_intptr_t;
|
||||
typedef unsigned long long int khronos_uintptr_t;
|
||||
#else
|
||||
typedef signed long int khronos_intptr_t;
|
||||
typedef unsigned long int khronos_uintptr_t;
|
||||
#endif
|
||||
|
||||
#if defined(_WIN64)
|
||||
typedef signed long long int khronos_ssize_t;
|
||||
typedef unsigned long long int khronos_usize_t;
|
||||
#else
|
||||
typedef signed long int khronos_ssize_t;
|
||||
typedef unsigned long int khronos_usize_t;
|
||||
#endif
|
||||
|
||||
#if KHRONOS_SUPPORT_FLOAT
|
||||
/*
|
||||
* Float type
|
||||
*/
|
||||
typedef float khronos_float_t;
|
||||
#endif
|
||||
|
||||
#if KHRONOS_SUPPORT_INT64
|
||||
/* Time types
|
||||
*
|
||||
* These types can be used to represent a time interval in nanoseconds or
|
||||
* an absolute Unadjusted System Time. Unadjusted System Time is the number
|
||||
* of nanoseconds since some arbitrary system event (e.g. since the last
|
||||
* time the system booted). The Unadjusted System Time is an unsigned
|
||||
* 64 bit value that wraps back to 0 every 584 years. Time intervals
|
||||
* may be either signed or unsigned.
|
||||
*/
|
||||
typedef khronos_uint64_t khronos_utime_nanoseconds_t;
|
||||
typedef khronos_int64_t khronos_stime_nanoseconds_t;
|
||||
#endif
|
||||
|
||||
/*
|
||||
* Dummy value used to pad enum types to 32 bits.
|
||||
*/
|
||||
#ifndef KHRONOS_MAX_ENUM
|
||||
#define KHRONOS_MAX_ENUM 0x7FFFFFFF
|
||||
#endif
|
||||
|
||||
/*
|
||||
* Enumerated boolean type
|
||||
*
|
||||
* Values other than zero should be considered to be true. Therefore
|
||||
* comparisons should not be made against KHRONOS_TRUE.
|
||||
*/
|
||||
typedef enum {
|
||||
KHRONOS_FALSE = 0,
|
||||
KHRONOS_TRUE = 1,
|
||||
KHRONOS_BOOLEAN_ENUM_FORCE_SIZE = KHRONOS_MAX_ENUM
|
||||
} khronos_boolean_enum_t;
|
||||
|
||||
#endif /* __khrplatform_h_ */
|
||||
@@ -0,0 +1,45 @@
|
||||
|
||||
#ifndef SN_INTERNAL
|
||||
#define SN_INTERNAL
|
||||
|
||||
#include <xmmintrin.h>
|
||||
|
||||
#define UNSAFE_AS(type, expr) *(type *)&(expr)
|
||||
|
||||
#ifdef _MSC_VER
|
||||
#define _CRT_SECURE_NO_WARNINGS 1
|
||||
#define WIN32_LEAN_AND_MEAN
|
||||
#define SN_DECL __cdecl
|
||||
#define SN_MAT_DECL __cdecl __forceinline
|
||||
#define SN_API __declspec(dllexport)
|
||||
#define FORCEINLINE __forceinline
|
||||
#define NOINLINE __declspec(noinline)
|
||||
#include <windows.h>
|
||||
#elif defined(__clang__) || defined(__GNUC__)
|
||||
#define SN_DECL __attribute__((cdecl))
|
||||
#define SN_MAT_DECL __attribute__((cdecl)) __attribute__((always_inline))
|
||||
#define SN_API __attribute__((dllexport))
|
||||
#define FORCEINLINE __attribute__((always_inline))
|
||||
#define NOINLINE __attribute__((noinline))
|
||||
#else
|
||||
#define SN_API
|
||||
#define SN_DECL
|
||||
#define SN_MAT_DECL
|
||||
#define FORCEINLINE
|
||||
#define NOINLINE
|
||||
#endif
|
||||
|
||||
#if defined(_MSC_VER)
|
||||
#define SN_ALIGNAS(n) __declspec(align(n))
|
||||
#else
|
||||
#define SN_ALIGNAS(n) __attribute__((aligned(n)))
|
||||
#endif
|
||||
|
||||
#define SN_APIDEF
|
||||
|
||||
#define PRIVATE static
|
||||
#define INTERNAL extern
|
||||
|
||||
#define u64 uint64_t
|
||||
|
||||
#endif //
|
||||
@@ -0,0 +1,34 @@
|
||||
#ifndef SN_INTRINSIC_CONTEXT_BASE
|
||||
#define SN_INTRINSIC_CONTEXT_BASE
|
||||
|
||||
|
||||
// -----------------------------------------------------------------------------
|
||||
// SIMDID layout helpers (see SIMDID.x86.md)
|
||||
// bits [3..0] : Root ISA
|
||||
// bits [7..4] : Manufacture (ISA-specific)
|
||||
// bits [15..8] : MainLevel (monotonic capability)
|
||||
// -----------------------------------------------------------------------------
|
||||
#define SIMDID_SHIFT_ROOT 0
|
||||
#define SIMDID_SHIFT_MANU 4
|
||||
#define SIMDID_SHIFT_MAIN 8
|
||||
|
||||
|
||||
#ifndef SIMDID_PACK_ROOT
|
||||
#define SIMDID_PACK_ROOT(root) (((uint64_t)(root) & 0xFULL) << SIMDID_SHIFT_ROOT)
|
||||
#define SIMDID_PACK_MANU(manu) (((uint64_t)(manu) & 0xFULL) << SIMDID_SHIFT_MANU)
|
||||
#define SIMDID_PACK_MAIN(main) (((uint64_t)(main) & 0xFFULL) << SIMDID_SHIFT_MAIN)
|
||||
#endif
|
||||
|
||||
// Root ISA (low nibble)
|
||||
#define SIMDID_ROOT_UNKNOWN 0x0 // cannot find root isa, error branch
|
||||
#define SIMDID_ROOT_X86_64 0x1 // support
|
||||
#define SIMDID_ROOT_AARCH64 0x2 // schedualed
|
||||
#define SIMDID_ROOT_PPC64LE 0x3 // willing, but no plan yet
|
||||
#define SIMDID_ROOT_RISCV64 0x4 // willing, but no plan yet
|
||||
#define SIMDID_ROOT_LOONGARCH 0x5 // willing, but no plan yet
|
||||
|
||||
#define SIMDID_MASK_ROOT 0xFULL
|
||||
#define SIMDID_MASK_MANU (0xFULL << SIMDID_SHIFT_MANU)
|
||||
#define SIMDID_MASK_MAIN (0xFFULL << SIMDID_SHIFT_MAIN)
|
||||
|
||||
#endif
|
||||
@@ -0,0 +1,313 @@
|
||||
#ifndef SN_INTRINSIC_CONTEXT_X86_H
|
||||
#define SN_INTRINSIC_CONTEXT_X86_H
|
||||
|
||||
#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.base.h"
|
||||
|
||||
#ifndef SN_X86_TARGET_ATTR_sse
|
||||
#define SN_STD_TARGET_ATTR_IMPL(T_arch, T_feature) SN_X86_TARGET_ATTR_##T_arch##T_feature
|
||||
#define SN_X86_TARGET_ATTR_sse SN_CLANG_TARGET_ATTR("sse4.2")
|
||||
#define SN_X86_TARGET_ATTR_avx SN_CLANG_TARGET_ATTR("avx")
|
||||
#define SN_X86_TARGET_ATTR_avx_fma SN_CLANG_TARGET_ATTR("avx,avx2,fma")
|
||||
#define SN_X86_TARGET_ATTR_512 SN_CLANG_TARGET_ATTR("avx512f,avx512vl")
|
||||
#endif
|
||||
|
||||
// -----------------------------------------------------------------------------
|
||||
// SIMDID layout helpers (see SIMDID.x86.md)
|
||||
// bits [3..0] : Root ISA
|
||||
// bits [7..4] : Manufacture (ISA-specific)
|
||||
// bits [15..8] : MainLevel (monotonic capability)
|
||||
// bits [31..16]: AVX512 Feature
|
||||
// bits [39..32]: AMX Feature
|
||||
// bits [47..40]: AVX Feature
|
||||
// bits [55..48]: AVX10 Feature
|
||||
// bits [63..56]: uArchHi / Policy (optional)
|
||||
// -----------------------------------------------------------------------------
|
||||
#define SIMDID_SHIFT_AVX512 16
|
||||
#define SIMDID_SHIFT_AMX 32
|
||||
#define SIMDID_SHIFT_AVX 40
|
||||
#define SIMDID_SHIFT_AVX10 48
|
||||
#define SIMDID_SHIFT_UARCH 56
|
||||
|
||||
#define SIMDID_MASK_AVX512 (0xFFFFULL << SIMDID_SHIFT_AVX512)
|
||||
#define SIMDID_MASK_AMX (0xFFULL << SIMDID_SHIFT_AMX)
|
||||
#define SIMDID_MASK_AVX (0xFFULL << SIMDID_SHIFT_AVX)
|
||||
#define SIMDID_MASK_AVX10 (0xFFULL << SIMDID_SHIFT_AVX10)
|
||||
#define SIMDID_MASK_UARCH (0xFFULL << SIMDID_SHIFT_UARCH)
|
||||
|
||||
// Manufacture (x86-64 mapping; other ISAs may reinterpret)
|
||||
#define SIMDID_MANU_UNKNOWN 0x0
|
||||
#define SIMDID_MANU_INTEL 0x1
|
||||
#define SIMDID_MANU_AMD 0x2
|
||||
#define SIMDID_MANU_VIA 0x3
|
||||
#define SIMDID_MANU_HYGON 0x4 /* 海光: Zen1-derived, separate from AMD */
|
||||
|
||||
// MainLevel (ordinal, shared bits 8..15; not bit-flags)
|
||||
#define SIMDID_MAIN_LVL_NONE 0x00u
|
||||
#define SIMDID_MAIN_LVL_SSE 0x01u /* SSE1..SSE4.2 */
|
||||
#define SIMDID_MAIN_LVL_AVX2 0x02u
|
||||
#define SIMDID_MAIN_LVL_AVX512 0x03u
|
||||
#define SIMDID_MAIN_LVL_AMX 0x04u
|
||||
#define SIMDID_MAIN_LVL_AVX10 0x05u
|
||||
|
||||
#ifndef SIMDID_AVX512_BASE
|
||||
#define SIMDID_AVX512_FP16 (1U << 13) /* relative bit 13 within [31..16] */
|
||||
#define SIMDID_AVX512_BF16 (1U << 12)
|
||||
#define SIMDID_AVX512_VNNI (1U << 11)
|
||||
#define SIMDID_AVX512_VBMI2 (1U << 10)
|
||||
#define SIMDID_AVX512_VBMI (1U << 9)
|
||||
#define SIMDID_AVX512_AI_RESERVED (1U << 8)
|
||||
#define SIMDID_AVX512_BASE (1U << 4)
|
||||
#define SIMDID_AVX512_IMPL_SHIFT 6
|
||||
#define SIMDID_AVX512_IMPL_MASK (0x3U << SIMDID_AVX512_IMPL_SHIFT)
|
||||
#define SIMDID_AVX512_IMPL_UNKNOWN (0x0U << SIMDID_AVX512_IMPL_SHIFT)
|
||||
#define SIMDID_AVX512_IMPL_DUAL (0x1U << SIMDID_AVX512_IMPL_SHIFT)
|
||||
#define SIMDID_AVX512_IMPL_NATIVE (0x2U << SIMDID_AVX512_IMPL_SHIFT)
|
||||
#endif
|
||||
|
||||
#ifndef SIMDID_AVX_BASE
|
||||
#define SIMDID_AVX (1U << 0) /* relative bit 0 within [47..40] */
|
||||
#define SIMDID_AVX2 (1U << 1)
|
||||
#define SIMDID_AVX_FMA (1U << 2)
|
||||
#define SIMDID_AVX_F16C (1U << 3)
|
||||
#define SIMDID_AVX_DUAL \
|
||||
(1U << 4) /* glued/split-lane YMM (two 128-bit units; Zen1, Hygon, VIA/Zhaoxin) */
|
||||
#endif
|
||||
|
||||
#ifndef SIMDID_AMX_TILE
|
||||
#define SIMDID_AMX_TILE (1U << 0) /* relative bit 0 within [39..32] */
|
||||
#define SIMDID_AMX_INT8 (1U << 1)
|
||||
#define SIMDID_AMX_BF16 (1U << 2)
|
||||
#endif
|
||||
|
||||
#ifndef SIMDID_AVX10_BASE
|
||||
#define SIMDID_AVX10 (1U << 0) /* relative bit 0 within [55..48] */
|
||||
#define SIMDID_AVX10_V1 (1U << 1)
|
||||
#define SIMDID_AVX10_V2 (1U << 2)
|
||||
#define SIMDID_AVX10_256W (1U << 3)
|
||||
#define SIMDID_AVX10_512W (1U << 4)
|
||||
#endif
|
||||
|
||||
/* uArchHi ([63..56]) bitmask — core topology and SIMD-width execution policy */
|
||||
#ifndef SIMDID_UARCH_HYBRID_P
|
||||
/* Topology 2-bit field (bits [1..0] of uArchHi byte):
|
||||
* 00 = unknown (undetected hybrid type or pre-CPUID.1A hardware)
|
||||
* 01 = E-core (efficiency/small core in a hybrid CPU)
|
||||
* 10 = P-core (performance/big core in a hybrid CPU)
|
||||
* 11 = unified (confirmed non-hybrid; numerically strongest)
|
||||
* Higher numeric value == stronger / higher-capability topology. */
|
||||
#define SIMDID_UARCH_HYBRID_E (1U << 0) /* E-core (efficiency/small) in a hybrid topology */
|
||||
#define SIMDID_UARCH_HYBRID_P (1U << 1) /* P-core (performance/big) in a hybrid topology */
|
||||
#define SIMDID_UARCH_SIMD_DUAL (1U << 2) /* SIMD is glued/dual (summary: AVX_DUAL or AVX512_IMPL=DUAL) */
|
||||
#endif
|
||||
|
||||
// Pack helpers (define locally to avoid missing macros when included standalone)
|
||||
#ifndef SIMDID_PACK_X86
|
||||
#define SIMDID_PACK_X86(root, manu, main) \
|
||||
(SIMDID_PACK_ROOT(root) | SIMDID_PACK_MANU(manu) | SIMDID_PACK_MAIN(main))
|
||||
#define SIMDID_PACK_AVX512(avx512_bits) \
|
||||
(((uint64_t)(avx512_bits) & 0xFFFFULL) << SIMDID_SHIFT_AVX512)
|
||||
#define SIMDID_PACK_AMX(amx_bits) (((uint64_t)(amx_bits) & 0xFFULL) << SIMDID_SHIFT_AMX)
|
||||
#define SIMDID_PACK_AVX(avx_bits) (((uint64_t)(avx_bits) & 0xFFULL) << SIMDID_SHIFT_AVX)
|
||||
#define SIMDID_PACK_AVX10(avx10_bits) (((uint64_t)(avx10_bits) & 0xFFULL) << SIMDID_SHIFT_AVX10)
|
||||
#define SIMDID_PACK_UARCH(uarch_hi) (((uint64_t)(uarch_hi) & 0xFFULL) << SIMDID_SHIFT_UARCH)
|
||||
#endif
|
||||
|
||||
/* Pre-shifted helpers for convenience when constructing SIMDID */
|
||||
#define SIMDID_MAIN_ENC_NONE SIMDID_PACK_MAIN(SIMDID_MAIN_LVL_NONE)
|
||||
#define SIMDID_MAIN_ENC_SSE SIMDID_PACK_MAIN(SIMDID_MAIN_LVL_SSE)
|
||||
#define SIMDID_MAIN_ENC_AVX2 SIMDID_PACK_MAIN(SIMDID_MAIN_LVL_AVX2)
|
||||
#define SIMDID_MAIN_ENC_AVX512 SIMDID_PACK_MAIN(SIMDID_MAIN_LVL_AVX512)
|
||||
#define SIMDID_MAIN_ENC_AMX SIMDID_PACK_MAIN(SIMDID_MAIN_LVL_AMX)
|
||||
#define SIMDID_MAIN_ENC_AVX10 SIMDID_PACK_MAIN(SIMDID_MAIN_LVL_AVX10)
|
||||
|
||||
#pragma region matix function
|
||||
|
||||
INTERNAL void f32_normalize(VEC_SEGMENT(float) * source, VEC_SEGMENT(float) * target);
|
||||
|
||||
SN_MK_PROC_DECL_STD(float, sse, , k_quality);
|
||||
|
||||
SN_MK_PROC_DECL_STD(float, sse, , add);
|
||||
SN_MK_PROC_DECL_STD(float, avx, , add);
|
||||
SN_MK_PROC_DECL_STD(float, 512, , add);
|
||||
|
||||
SN_MK_PROC_DECL_STD(double, sse, , add);
|
||||
SN_MK_PROC_DECL_STD(double, avx, , add);
|
||||
SN_MK_PROC_DECL_STD(double, 512, , add);
|
||||
|
||||
SN_MK_PROC_DECL_STD(float, sse, , sub);
|
||||
SN_MK_PROC_DECL_STD(float, avx, , sub);
|
||||
SN_MK_PROC_DECL_STD(float, 512, , sub);
|
||||
|
||||
SN_MK_PROC_DECL_STD(double, sse, , sub);
|
||||
SN_MK_PROC_DECL_STD(double, avx, , sub);
|
||||
SN_MK_PROC_DECL_STD(double, 512, , sub);
|
||||
|
||||
SN_MK_PROC_DECL_STD(float, sse, , transpose);
|
||||
SN_MK_PROC_DECL_STD(float, avx, , transpose);
|
||||
SN_MK_PROC_DECL_STD(float, 512, , transpose);
|
||||
|
||||
SN_MK_PROC_DECL_STD(float, sse, , scalar_mul);
|
||||
SN_MK_PROC_DECL_STD(float, avx, , scalar_mul);
|
||||
SN_MK_PROC_DECL_STD(float, 512, , scalar_mul);
|
||||
|
||||
SN_MK_PROC_DECL_STD(double, sse, , scalar_mul);
|
||||
SN_MK_PROC_DECL_STD(double, avx, , scalar_mul);
|
||||
SN_MK_PROC_DECL_STD(double, 512, , scalar_mul);
|
||||
|
||||
SN_MK_PROC_DECL_STD(float, sse, , fill);
|
||||
SN_MK_PROC_DECL_STD(float, avx, , fill);
|
||||
SN_MK_PROC_DECL_STD(float, 512, , fill);
|
||||
|
||||
SN_MK_PROC_DECL_STD(double, sse, , fill);
|
||||
SN_MK_PROC_DECL_STD(double, avx, , fill);
|
||||
SN_MK_PROC_DECL_STD(double, 512, , fill);
|
||||
|
||||
SN_MK_PROC_DECL_STD(float, sse, , quality);
|
||||
|
||||
/*
|
||||
* pack left matrix data to L4 buffer
|
||||
*
|
||||
* CONVENSIONS:
|
||||
*
|
||||
* buffer_1 is pointer to original colum,
|
||||
* offset_1 is the offset to the original column,
|
||||
* count_1 is the count can be packed
|
||||
*
|
||||
* C# shceduler is responsible for calculating the offset and count based on the actual buffer size and matrix dimension,
|
||||
* and make sure that count_1 will not exceeds lenght of the column
|
||||
*
|
||||
* scalar pack carries column length and offset data:
|
||||
* [column length, empty, empty, empty]
|
||||
*/
|
||||
SN_MK_PROC_DECL_STD(float, sse, , fma_pack_left);
|
||||
SN_MK_PROC_DECL_STD(float, avx, , fma_pack_left);
|
||||
SN_MK_PROC_DECL_STD(float, 512, , fma_pack_left);
|
||||
|
||||
/*
|
||||
* pack right matrix data to L4 buffer
|
||||
*
|
||||
* CONVENSIONS:
|
||||
*
|
||||
* buffer_1 is pointer to original row,
|
||||
* offset_1 is the offset to the original row,
|
||||
* count_1 is the count can be packed
|
||||
*
|
||||
* C# shceduler is responsible for calculating the offset and count based on the actual buffer size and matrix dimension,
|
||||
* and make sure that count_1 will not exceeds lenght of the row
|
||||
*
|
||||
* scalar pack carries column length and offset data:
|
||||
* [column length, empty, empty, empty]
|
||||
*/
|
||||
SN_MK_PROC_DECL_STD(float, sse, , fma_pack_right);
|
||||
SN_MK_PROC_DECL_STD(float, avx, , fma_pack_right);
|
||||
SN_MK_PROC_DECL_STD(float, 512, , fma_pack_right);
|
||||
|
||||
SN_MK_PROC_DECL_STD(float, sse, , fma);
|
||||
SN_MK_PROC_DECL_STD(float, avx, , fma);
|
||||
SN_MK_PROC_DECL_STD(float, avx, _fma, fma);
|
||||
SN_MK_PROC_DECL_STD(float, 512, , fma);
|
||||
|
||||
SN_MK_PROC_DECL_STD(float, sse, , fma_unpack);
|
||||
SN_MK_PROC_DECL_STD(float, avx, , fma_unpack);
|
||||
SN_MK_PROC_DECL_STD(float, 512, , fma_unpack);
|
||||
|
||||
SN_MK_PROC_DECL_STD(double, sse, , fma_pack_left);
|
||||
SN_MK_PROC_DECL_STD(double, avx, , fma_pack_left);
|
||||
SN_MK_PROC_DECL_STD(double, 512, , fma_pack_left);
|
||||
|
||||
SN_MK_PROC_DECL_STD(double, sse, , fma);
|
||||
SN_MK_PROC_DECL_STD(double, avx, , fma);
|
||||
SN_MK_PROC_DECL_STD(double, avx, _fma, fma);
|
||||
SN_MK_PROC_DECL_STD(double, 512, , fma);
|
||||
|
||||
SN_MK_PROC_DECL_STD(double, sse, , fma_unpack);
|
||||
SN_MK_PROC_DECL_STD(double, avx, , fma_unpack);
|
||||
SN_MK_PROC_DECL_STD(double, 512, , fma_unpack);
|
||||
|
||||
SN_SK_PROC_DECL_STD(float, avx, , add);
|
||||
SN_SK_PROC_DECL_STD(float, 512, , add);
|
||||
|
||||
SN_SK_PROC_DECL_STD(double, sse, , add);
|
||||
SN_SK_PROC_DECL_STD(double, avx, , add);
|
||||
SN_SK_PROC_DECL_STD(double, 512, , add);
|
||||
|
||||
SN_SK_PROC_DECL_STD(float, sse, , sub);
|
||||
SN_SK_PROC_DECL_STD(float, avx, , sub);
|
||||
SN_SK_PROC_DECL_STD(float, 512, , sub);
|
||||
|
||||
SN_SK_PROC_DECL_STD(double, sse, , sub);
|
||||
SN_SK_PROC_DECL_STD(double, avx, , sub);
|
||||
SN_SK_PROC_DECL_STD(double, 512, , sub);
|
||||
|
||||
SN_SK_PROC_DECL_STD(float, sse, , transpose);
|
||||
SN_SK_PROC_DECL_STD(float, avx, , transpose);
|
||||
SN_SK_PROC_DECL_STD(float, 512, , transpose);
|
||||
|
||||
SN_SK_PROC_DECL_STD(float, sse, , scalar_mul);
|
||||
SN_SK_PROC_DECL_STD(float, avx, , scalar_mul);
|
||||
SN_SK_PROC_DECL_STD(float, 512, , scalar_mul);
|
||||
|
||||
SN_SK_PROC_DECL_STD(double, sse, , scalar_mul);
|
||||
SN_SK_PROC_DECL_STD(double, avx, , scalar_mul);
|
||||
SN_SK_PROC_DECL_STD(double, 512, , scalar_mul);
|
||||
|
||||
SN_SK_PROC_DECL_STD(float, sse, , fill);
|
||||
SN_SK_PROC_DECL_STD(float, avx, , fill);
|
||||
SN_SK_PROC_DECL_STD(float, 512, , fill);
|
||||
|
||||
SN_SK_PROC_DECL_STD(double, sse, , fill);
|
||||
SN_SK_PROC_DECL_STD(double, avx, , fill);
|
||||
SN_SK_PROC_DECL_STD(double, 512, , fill);
|
||||
|
||||
SN_SK_PROC_DECL_STD(float, sse, , quality);
|
||||
|
||||
SN_SK_PROC_DECL_STD(float, sse, , fma);
|
||||
SN_SK_PROC_DECL_STD(float, avx, , fma);
|
||||
SN_SK_PROC_DECL_STD(float, avx, _fma, fma);
|
||||
SN_SK_PROC_DECL_STD(float, 512, , fma);
|
||||
|
||||
SN_SK_PROC_DECL_STD(double, sse, , fma);
|
||||
SN_SK_PROC_DECL_STD(double, avx, , fma);
|
||||
SN_SK_PROC_DECL_STD(double, avx, _fma, fma);
|
||||
SN_SK_PROC_DECL_STD(double, 512, , fma);
|
||||
|
||||
#pragma endregion
|
||||
|
||||
#pragma region scaler_simd
|
||||
|
||||
INTERNAL uint64_t SN_DECL factorial_simd_sse(int n);
|
||||
|
||||
#pragma endregion
|
||||
|
||||
#pragma region dot_product
|
||||
|
||||
INTERNAL void FORCEINLINE SN_DECL dot_41_sse(MAT_KERNEL(float) const *transpose,
|
||||
__m128 const *vector, __m128 *ans);
|
||||
INTERNAL void SN_DECL dot_41_avx(MAT_KERNEL(float) const *transpose, __m128 const *vector,
|
||||
__m128 *ans);
|
||||
INTERNAL void SN_DECL dot_42_sse(MAT_KERNEL(float) const *transpose, __m128 const *vector,
|
||||
__m128 *ans);
|
||||
INTERNAL void SN_DECL dot_42_avx(MAT_KERNEL(float) const *transpose, __m128 const *vector,
|
||||
__m128 *ans);
|
||||
|
||||
#pragma endregion
|
||||
|
||||
#pragma region string
|
||||
|
||||
INTERNAL int SN_DECL city_hash_simplify_sse(byte const *str, int length);
|
||||
INTERNAL int SN_DECL index_pair_sse(short const *stram, uint32_t target, int length);
|
||||
|
||||
#pragma endregion
|
||||
|
||||
#else
|
||||
|
||||
typedef enum intrinsic_level { SIMD0 = 0 } intrinsic_level;
|
||||
|
||||
#endif
|
||||
#endif
|
||||
@@ -0,0 +1,194 @@
|
||||
#ifndef SSC_INTRIN
|
||||
#define SSC_INTRIN
|
||||
|
||||
#define SSC_INTRIN_HEAD
|
||||
|
||||
#include "StgSharpNative.h"
|
||||
#include "sn_target.h"
|
||||
#include <xmmintrin.h>
|
||||
#include <immintrin.h>
|
||||
#include <smmintrin.h>
|
||||
#include "sn_intrinsic.matkernel.h"
|
||||
#include <stdint.h>
|
||||
|
||||
#ifdef _MSC_VER
|
||||
#include <intrin.h>
|
||||
#include <isa_availability.h>
|
||||
#endif
|
||||
|
||||
#define LASTTWO(x) (x & 3)
|
||||
#define LAST(x) (x & 3)
|
||||
#define get_align_begin(x) ((x + 15) & (~15))
|
||||
|
||||
#define SSE_INSERT(source, target, reset3, reset2, reset1, reset0) \
|
||||
(LASTTWO(source - 1) << 6) | (LASTTWO(target - 1) << 4) | (LAST(reset3) << 3) | \
|
||||
(LAST(reset2) << 2) | (LAST(reset1) << 1) | LAST(reset0)
|
||||
#define SSE_INSERT_SIMPLE(source, target) SSE_INSERT(source, target, 0, 0, 0, 0)
|
||||
#define M256_PERMUTE(s3, s2, s1, s0) \
|
||||
((LASTTWO(s3) << 6) | (LASTTWO(s2) << 4) | (LASTTWO(s1) << 2) | (LASTTWO(s0)))
|
||||
#define BIT_CVRT(pack, index, T) *(T *)(pack->data + index)
|
||||
|
||||
#if SN_IS_ARCH(x86_64)
|
||||
|
||||
#define vec_128 __m128
|
||||
#define vec_256 __m256
|
||||
#define vec_512 __m512
|
||||
|
||||
#define zero_vec _mm_setzero_ps()
|
||||
#define zero_vec_256 _mm256_setzero_ps()
|
||||
|
||||
#define ALIGN(simdVec) _mm_loadu_ps(&simdVec)
|
||||
#define ALIGN256(simdVec) _mm256_loadu_ps(&simdVec)
|
||||
#define ALIGN512(simdVec) _mm512_loadu_ps(&simdVec)
|
||||
|
||||
#else
|
||||
|
||||
#define zero_vec
|
||||
#define zero_vec_256
|
||||
|
||||
#define ALIGN(simdVec)
|
||||
#define ALIGN256(simdVec)
|
||||
#define ALIGN512(simdVec)
|
||||
|
||||
#endif
|
||||
|
||||
#define SPAN(T) \
|
||||
struct SPAN_T { \
|
||||
T *pointer; \
|
||||
size_t length; \
|
||||
};
|
||||
|
||||
typedef union uint64_u {
|
||||
uint64_t u64;
|
||||
uint32_t u32[2];
|
||||
} uint64_u;
|
||||
|
||||
typedef struct mat_kernel mat_kernel;
|
||||
|
||||
typedef union M128{
|
||||
#if SN_IS_ARCH(x86_64)
|
||||
__m128 m128;
|
||||
#endif
|
||||
float f32[4];
|
||||
double f64[2];
|
||||
int32_t i32[4];
|
||||
int64_t i64[2];
|
||||
}M128;
|
||||
|
||||
typedef union M256{
|
||||
#if SN_IS_ARCH(x86_64)
|
||||
__m256 m256;
|
||||
#endif
|
||||
float f32[8];
|
||||
double f64[4];
|
||||
int32_t i32[8];
|
||||
int64_t i64[4];
|
||||
}M256;
|
||||
|
||||
typedef union M512{
|
||||
#if SN_IS_ARCH(x86_64)
|
||||
__m512 m512;
|
||||
#endif
|
||||
uint64_t u64[8];
|
||||
uint32_t u32[16];
|
||||
float f32[16];
|
||||
double f64[8];
|
||||
int32_t i32[16];
|
||||
int64_t i64[8];
|
||||
}M512;
|
||||
|
||||
typedef struct sn_L4_cache_head {
|
||||
uint64_t reverse_mask_0;
|
||||
uint32_t position_mask;
|
||||
uint32_t size;
|
||||
uint64_t reverse_mask_1;
|
||||
uint64_t reverse_mask_2;
|
||||
} sn_L4_cache_head;
|
||||
|
||||
typedef struct sn_L4_handle {
|
||||
void *ptr;
|
||||
sn_L4_cache_head* head;
|
||||
} sn_L4_handle;
|
||||
|
||||
typedef struct matrix_task {
|
||||
sn_L4_handle buffer_0;
|
||||
sn_L4_handle buffer_1;
|
||||
sn_L4_handle buffer_2;
|
||||
sn_L4_handle buffer_3;
|
||||
union {
|
||||
struct {
|
||||
int32_t reverse_0;
|
||||
int32_t reverse_1;
|
||||
int32_t offset_0;
|
||||
int32_t count_0;
|
||||
int32_t offset_1;
|
||||
int32_t count_1;
|
||||
int32_t offset_2;
|
||||
int32_t count_2;
|
||||
int32_t offset_3;
|
||||
int32_t count_3;
|
||||
int32_t reverse_2;
|
||||
int32_t reverse_3;
|
||||
M128 scalar_pack;
|
||||
};
|
||||
M512 profile;
|
||||
};
|
||||
|
||||
} matrix_task;
|
||||
|
||||
#define MAT_TASK(T) matrix_task
|
||||
|
||||
#if defined(__cplusplus)
|
||||
static_assert(sizeof(matrix_task) == 128, "matrix_parallel_task_package size mismatch");
|
||||
#elif defined(__STDC_VERSION__)
|
||||
static_assert(sizeof(matrix_task) == 128, "matrix_parallel_task_package size mismatch");
|
||||
#endif
|
||||
|
||||
typedef void(SN_DECL *UNI_MK_PROC)(matrix_task *task);
|
||||
typedef void(SN_DECL *UNI_SK_PROC)(mat_kernel const *left, mat_kernel const *right,
|
||||
mat_kernel *restrict ans, uint64_t scalar);
|
||||
|
||||
typedef void(SN_DECL *VECTORNORMALIZEPROC)(VEC_SEGMENT(float) *source, VEC_SEGMENT(float) *target);
|
||||
typedef void(SN_DECL *DOTPROC)(void *transpose, __m128 *vector, __m128 *ans);
|
||||
typedef uint64_t(SN_DECL *FACTORIALROC)(int n);
|
||||
|
||||
#pragma region string
|
||||
|
||||
typedef int(SN_DECL *HASH)(byte const *str, int length);
|
||||
typedef int(SN_DECL *INDEX_PAIR)(short const *stram, uint32_t target, int length);
|
||||
|
||||
#pragma endregion
|
||||
|
||||
typedef struct mat_mk_intrinsic {
|
||||
UNI_MK_PROC proc_array[10];
|
||||
} mat_mk_intrinsic;
|
||||
|
||||
typedef struct mat_sk_intrinsic {
|
||||
UNI_SK_PROC proc_array[10];
|
||||
} mat_sk_intrinsic;
|
||||
|
||||
// Mirrors C# IntrinsicContext field order so managed/unmanaged layouts stay in sync.
|
||||
typedef struct sn_intrinsic {
|
||||
HASH city_hash_simplify;
|
||||
FACTORIALROC factorial_simd;
|
||||
VECTORNORMALIZEPROC vec_f32_normalize_3;
|
||||
mat_mk_intrinsic mat_mk[0x0a];
|
||||
mat_sk_intrinsic mat_sk[0x0a];
|
||||
} sn_intrinsic;
|
||||
|
||||
|
||||
typedef enum mat_proc_index {
|
||||
Add = 0,
|
||||
Fill = 1,
|
||||
ScalarMul = 2,
|
||||
Sub = 3,
|
||||
Transpose = 4,
|
||||
ClearPanel = 5,
|
||||
Fma = 6,
|
||||
PackFmaLeft = 7,
|
||||
PackFmaRight = 8,
|
||||
Pivot = 9,
|
||||
} mat_proc_index;
|
||||
typedef enum elment_mask { F32 = 0, F64 = 1, I32 = 2, I64 = 3 } element_mask;
|
||||
|
||||
#endif
|
||||
@@ -0,0 +1,54 @@
|
||||
#ifndef SN_MATKERNEL
|
||||
#define SN_MATKERNEL
|
||||
|
||||
#include <immintrin.h>
|
||||
#include <stdint.h>
|
||||
|
||||
#include "sn_internal.h"
|
||||
|
||||
/* Kernel storage unions for a fixed 4x4 block. */
|
||||
#define ELEMENTSIZE(T) sizeof(T)
|
||||
#define XMMCOUNT(T) (sizeof(T))
|
||||
#define YMMCOUNT(T) (sizeof(T) / 2)
|
||||
#define ZMMCOUNT(T) (sizeof(T) / 4)
|
||||
|
||||
#define SN_MAT_KERNEL_MEMBER(T) \
|
||||
{ \
|
||||
__m128 x[XMMCOUNT(T)]; \
|
||||
__m256 y[YMMCOUNT(T)]; \
|
||||
__m512 z[ZMMCOUNT(T)]; \
|
||||
T m[4][4]; \
|
||||
}
|
||||
|
||||
#define SN_MAT_KERNEL_DEFINE(T) \
|
||||
typedef union SN_MAT_KERNEL_TYPE_##T SN_MAT_KERNEL_MEMBER(T) SN_MAT_KERNEL_TYPE_##T
|
||||
|
||||
#define MAT_KERNEL(T) SN_MAT_KERNEL_TYPE(T)
|
||||
#define SN_MAT_KERNEL_TYPE(T) SN_MAT_KERNEL_TYPE_##T
|
||||
|
||||
SN_MAT_KERNEL_DEFINE(float);
|
||||
SN_MAT_KERNEL_DEFINE(double);
|
||||
SN_MAT_KERNEL_DEFINE(uint64_t);
|
||||
|
||||
|
||||
#define SN_VEC_SEGMENT_MEMBER(T) \
|
||||
{ \
|
||||
__m128 f32_x[XMMCOUNT(T) / 4]; \
|
||||
__m256 f32_y[YMMCOUNT(T) / 4]; \
|
||||
__m512 f32_z[ZMMCOUNT(T) / 4]; \
|
||||
T v[4]; \
|
||||
}
|
||||
|
||||
#define SN_VEC_SEGMENT_DEFINE(T) \
|
||||
typedef union SN_VEC_SEGMENT_TYPE_##T SN_VEC_SEGMENT_MEMBER(T) SN_VEC_SEGMENT_TYPE_##T
|
||||
|
||||
#define VEC_SEGMENT(T) SN_VEC_SEGMENT_TYPE(T)
|
||||
#define SN_VEC_SEGMENT_TYPE(T) SN_VEC_SEGMENT_TYPE_##T
|
||||
|
||||
SN_VEC_SEGMENT_DEFINE(float);
|
||||
SN_VEC_SEGMENT_DEFINE(double);
|
||||
|
||||
/* Global zero kernel declaration (defined in dllmain.c), aligned to 64 bytes */
|
||||
extern __declspec(align(64)) MAT_KERNEL(u64) SN_ZERO_KERNEL;
|
||||
|
||||
#endif /* SN_MATKERNEL */
|
||||
@@ -0,0 +1,101 @@
|
||||
#ifndef SN_INTRINSIC_CALLCONV_STD
|
||||
#define SN_INTRINSIC_CALLCONV_STD
|
||||
|
||||
#include "sn_internal.h"
|
||||
#include "sn_intrinsic.h"
|
||||
|
||||
#ifndef static_assert
|
||||
#define static_assert _Static_assert
|
||||
#endif
|
||||
|
||||
#define SN_STD_TARGET_ATTR(T_arch, T_feature) SN_STD_TARGET_ATTR_IMPL(T_arch, T_feature)
|
||||
|
||||
#pragma region mk_proc attributes
|
||||
#define MK_PROC_NAME_STD(T_type, T_arch, T_feature, T_op) \
|
||||
T_type##_multi_kernel_proc_##T_op##_##T_arch##_##T_feature
|
||||
#define GET_MK_PROC_STD(T_type, T_arch, T_feature, T_op) \
|
||||
((UNI_MK_PROC)MK_PROC_NAME_STD(T_type, T_arch, T_feature, T_op))
|
||||
#define SN_MK_PROC_DECL(T_type, P_name) INTERNAL void SN_DECL P_name(MAT_TASK(T_type) const *task)
|
||||
#define SN_MK_PROC_DECL_STD(T_type, T_arch, T_feature, T_op) \
|
||||
INTERNAL NOINLINE SN_STD_TARGET_ATTR(T_arch, T_feature) void SN_DECL MK_PROC_NAME_STD( \
|
||||
T_type, T_arch, T_feature, T_op)(MAT_TASK(T_type) const *task)
|
||||
#pragma endregion
|
||||
|
||||
#pragma region sk_proc attributes
|
||||
#define SK_PROC_NAME_STD(T_type, T_arch, T_feature, T_op) \
|
||||
T_type##_single_kernel_proc_##T_op##_##T_arch##_##T_feature
|
||||
#define GET_SK_PROC_STD(T_type, T_arch, T_feature, T_op) \
|
||||
((UNI_SK_PROC)SK_PROC_NAME_STD(T_type, T_arch, T_feature, T_op))
|
||||
#define SN_SK_PROC_DECL_STD(T_type, T_arch, T_feature, T_op) \
|
||||
INTERNAL NOINLINE SN_STD_TARGET_ATTR(T_arch, T_feature) void SN_DECL SK_PROC_NAME_STD( \
|
||||
T_type, T_arch, T_feature, \
|
||||
T_op)(MAT_KERNEL(T_type) const *left, MAT_KERNEL(T_type) const *right, \
|
||||
MAT_KERNEL(T_type) *restrict ans, uint64_t scalar)
|
||||
#pragma endregion
|
||||
|
||||
#define _SN_STD__PROBE_0 0
|
||||
#define _SN_STD__PROBE_1 1
|
||||
#define SN_STD__PROBE_PRINT(x) _SN_STD__PROBE_##x
|
||||
#define SN_STD__PROBE(x) SN_STD__PROBE_PRINT(x)
|
||||
|
||||
#pragma region param styles
|
||||
|
||||
#define _SN_MATPROC_LEFT_RIGHT_ANS 1
|
||||
#define _SN_MATPROC_RIGHT_ANS 1
|
||||
#define _SN_MATPROC_LEFT_RIGHT_ANS_SCALAR 1
|
||||
#define _SN_MATPROC_RIGHT_ANS_SCALAR 1
|
||||
#define _SN_MATPROC_ANS_SCALAR 1
|
||||
|
||||
#define _SN_MK_EXPAND_BUFFER_SIZE(i)\
|
||||
int offset_##i = task->offset_##i;\
|
||||
int count_##i = task->count_##i;\
|
||||
|
||||
#define _SN_MK_EXPAND_RIGHT_ANS \
|
||||
SN_MAT_KERNEL_LOCAL const *right = (SN_MAT_KERNEL_LOCAL const *)task->buffer_1.ptr; \
|
||||
SN_MAT_KERNEL_LOCAL *restrict ans = (SN_MAT_KERNEL_LOCAL *)task->buffer_2.ptr;\
|
||||
_SN_MK_EXPAND_BUFFER_SIZE(1); \
|
||||
_SN_MK_EXPAND_BUFFER_SIZE(2);
|
||||
|
||||
#define _SN_MK_EXPAND_LEFT_RIGHT_ANS \
|
||||
SN_MAT_KERNEL_LOCAL const *left = (SN_MAT_KERNEL_LOCAL const *)task->buffer_0.ptr; \
|
||||
SN_MAT_KERNEL_LOCAL const *right = (SN_MAT_KERNEL_LOCAL const *)task->buffer_1.ptr; \
|
||||
SN_MAT_KERNEL_LOCAL *restrict ans = (SN_MAT_KERNEL_LOCAL *)task->buffer_2.ptr;\
|
||||
_SN_MK_EXPAND_BUFFER_SIZE(0); \
|
||||
_SN_MK_EXPAND_BUFFER_SIZE(1);\
|
||||
_SN_MK_EXPAND_BUFFER_SIZE(2);
|
||||
|
||||
#define _SN_MK_EXPAND_RIGHT_ANS_SCALAR \
|
||||
SN_MAT_KERNEL_LOCAL const *right = (SN_MAT_KERNEL_LOCAL const *)task->buffer_1.ptr; \
|
||||
SN_MAT_KERNEL_LOCAL *restrict ans = (SN_MAT_KERNEL_LOCAL *)task->buffer_2.ptr; \
|
||||
M128 scalar = task->scalar_pack;\
|
||||
_SN_MK_EXPAND_BUFFER_SIZE(1);\
|
||||
_SN_MK_EXPAND_BUFFER_SIZE(2);
|
||||
|
||||
#define _SN_MK_EXPAND_LEFT_RIGHT_ANS_SCALAR \
|
||||
SN_MAT_KERNEL_LOCAL const *left = (SN_MAT_KERNEL_LOCAL const *)task->buffer_0.ptr; \
|
||||
SN_MAT_KERNEL_LOCAL const *right = (SN_MAT_KERNEL_LOCAL const *)task->buffer_1.ptr; \
|
||||
SN_MAT_KERNEL_LOCAL *restrict ans = (SN_MAT_KERNEL_LOCAL *)task->buffer_2.ptr; \
|
||||
M128 scalar = task->scalar_pack;\
|
||||
_SN_MK_EXPAND_BUFFER_SIZE(0);\
|
||||
_SN_MK_EXPAND_BUFFER_SIZE(1);\
|
||||
_SN_MK_EXPAND_BUFFER_SIZE(2);
|
||||
|
||||
#define _SN_MK_EXPAND_ANS_SCALAR \
|
||||
SN_MAT_KERNEL_LOCAL *restrict ans = (SN_MAT_KERNEL_LOCAL *)task->buffer_2.ptr; \
|
||||
M128 scalar = task->scalar_pack;\
|
||||
_SN_MK_EXPAND_BUFFER_SIZE(2);
|
||||
|
||||
#define _SN_PARAM_STYLE(T) _SN_MATPROC_##T
|
||||
#define _SN_MK_EXPAND_PARAM(style) _SN_MK_EXPAND_##style
|
||||
|
||||
#pragma endregion
|
||||
|
||||
#define __mk_param_std(param, T) \
|
||||
typedef MAT_KERNEL(T) SN_MAT_KERNEL_LOCAL; \
|
||||
matrix_task const *_ = (_SN_PARAM_STYLE(param), task); \
|
||||
_SN_MK_EXPAND_PARAM(param)
|
||||
|
||||
#define __sk_param_std(T) \
|
||||
typedef MAT_KERNEL(T) SN_MAT_KERNEL_LOCAL; \
|
||||
(void)scalar
|
||||
#endif // !SN_INTRINSIC_PARAM_EXPAND
|
||||
@@ -0,0 +1,94 @@
|
||||
#ifndef SN_TARGET
|
||||
#define SN_TARGET
|
||||
|
||||
#include "sn_internal.h"
|
||||
#include <stdint.h>
|
||||
|
||||
#define SN_OS_WINDOWS 0
|
||||
#define SN_OS_LINUX 1
|
||||
#define SN_OS_MACOS 2
|
||||
#define SN_OS_IOS 3
|
||||
#define SN_OS_ANDROID 4
|
||||
#define SN_OS_UNKNOWN 5
|
||||
|
||||
#define SN_ARCH_X86_64 0
|
||||
#define SN_ARCH_ARM64 1
|
||||
#define SN_ARCH_RISCV64 2
|
||||
#define SN_ARCH_PPC64le 3
|
||||
|
||||
#if defined(_M_X64) || defined(_M_AMD64) || defined(__x86_64__) || defined(__amd64__)
|
||||
#define SN_CURRENT_ARCH SN_ARCH_X86_64
|
||||
|
||||
#elif defined(_M_ARM64) || defined(__aarch64__)
|
||||
#define SN_CURRENT_ARCH SN_ARCH_ARM64
|
||||
|
||||
#elif defined(_M_ARM) || defined(__arm__)
|
||||
#define SN_CURRENT_ARCH SN_ARCH_ARM32
|
||||
|
||||
#elif defined(_M_IX86) || defined(__i386__)
|
||||
#define SN_CURRENT_ARCH SN_ARCH_X86_32
|
||||
|
||||
#elif defined(__powerpc64__) && defined(__LITTLE_ENDIAN__)
|
||||
#define SN_CURRENT_ARCH SN_ARCH_PPC64LE
|
||||
|
||||
#elif defined(__riscv) && (__riscv_xlen == 64)
|
||||
#define SN_CURRENT_ARCH SN_ARCH_RISCV64
|
||||
|
||||
#else
|
||||
#error "SN: Unsupported target architecture"
|
||||
#endif
|
||||
|
||||
/*
|
||||
* Target selection policy:
|
||||
* - Default (no SN_EXTERN_TARGET): fixed Windows + x86_64.
|
||||
* - External (SN_EXTERN_TARGET): build system must provide SN_OS and SN_ARCH.
|
||||
*/
|
||||
#ifndef SN_EXTERN_TARGET
|
||||
|
||||
#define SN_OS_TARGET SN_OS_WINDOWS
|
||||
#define SN_ARCH_TARGET SN_ARCH_X86_64
|
||||
|
||||
#else
|
||||
|
||||
#ifndef SN_OS_TARGET
|
||||
#error "SN_EXTERN_TARGET is defined but SN_OS is not provided."
|
||||
#endif
|
||||
|
||||
#ifndef SN_ARCH_TARGET
|
||||
#error "SN_EXTERN_TARGET is defined but SN_ARCH is not provided."
|
||||
#endif
|
||||
|
||||
/* Validate externally supplied values are within known enum constants. */
|
||||
#if (SN_OS_TARGET != SN_OS_WINDOWS) && (SN_OS_TARGET != SN_OS_LINUX) && \
|
||||
(SN_OS_TARGET != SN_OS_MACOS) && (SN_OS_TARGET != SN_OS_IOS) && \
|
||||
(SN_OS_TARGET != SN_OS_ANDROID) && (SN_OS_TARGET != SN_OS_UNKNOWN)
|
||||
#error "SN_OS has an invalid value. Use SN_OS_<...> enum constants."
|
||||
#endif
|
||||
|
||||
#if (SN_ARCH_TARGET != SN_ARCH_X86_64) && (SN_ARCH_TARGET != SN_ARCH_ARM64) && \
|
||||
(SN_ARCH_TARGET != SN_ARCH_RISCV64) && (SN_ARCH_TARGET != SN_ARCH_PPC64le)
|
||||
#error "SN_ARCH has an invalid value. Use SN_ARCH_<...> enum constants."
|
||||
#endif
|
||||
|
||||
#endif
|
||||
|
||||
#define SN_IS_OS(os) ((SN_OS_TARGET) == (os))
|
||||
|
||||
#define SN_IS_ARCH(arch) ((SN_ARCH_TARGET) == (arch))
|
||||
|
||||
/*
|
||||
* Per-function ISA selection is required for runtime-dispatched kernels that
|
||||
* mix multiple x86 feature levels in one build target.
|
||||
*/
|
||||
#if defined(__clang__) && ((SN_ARCH_TARGET) == SN_ARCH_X86_64)
|
||||
#define SN_CLANG_TARGET_ATTR(options) __attribute__((target(options)))
|
||||
#else
|
||||
#define SN_CLANG_TARGET_ATTR(options)
|
||||
#endif
|
||||
|
||||
typedef union SIMDID {
|
||||
uint64_t mask;
|
||||
char make_byte[8];
|
||||
} SIMDID;
|
||||
|
||||
#endif // SN_TARGET
|
||||
File diff suppressed because it is too large
Load Diff
Reference in New Issue
Block a user