vector and matrix optimization
This commit is contained in:
@@ -1,7 +1,3 @@
|
||||
#ifdef _MSC_VER
|
||||
#pragma once
|
||||
#endif
|
||||
|
||||
#ifndef SSC_INTRIN
|
||||
#define SSC_INTRIN
|
||||
|
||||
@@ -128,7 +124,7 @@ typedef struct sn_intrinsic {
|
||||
SCALARMATARITHMETIC f32_scalar_mul;
|
||||
MATARITHMETIC f32_sub;
|
||||
MATTRANSPOSEPROC f32_transpose;
|
||||
VECTORNORMALIZEPROC normalize_3;
|
||||
VECTORNORMALIZEPROC f32_normalize_3;
|
||||
} sn_intrinsic;
|
||||
|
||||
typedef enum most_advanced_instruction {
|
||||
@@ -145,4 +141,4 @@ typedef enum most_advanced_instruction {
|
||||
#endif
|
||||
} most_advanced_instruction;
|
||||
|
||||
#endif // !SSC_INTRIN
|
||||
#endif
|
||||
|
||||
@@ -1,15 +1,15 @@
|
||||
#ifndef SN_MATKERNEL
|
||||
#define SN_MATKERNEL
|
||||
|
||||
#include <immintrin.h>
|
||||
|
||||
#define ELEMENTSIZE(T) sizeof(T)
|
||||
#define XMMCOUNT(T) sizeof(T)
|
||||
#define YMMCOUNT(T) sizeof(T) / 2
|
||||
#define ZMMCOUNT(T) sizeof(T) / 4
|
||||
|
||||
#include <immintrin.h>
|
||||
|
||||
#define MAT_KERNEL(T) \
|
||||
union mat_kernel_##T##{ \
|
||||
union { \
|
||||
__m128 xmm[XMMCOUNT(T)]; \
|
||||
__m256 ymm[YMMCOUNT(T)]; \
|
||||
__m512 zmm[ZMMCOUNT(T)]; \
|
||||
@@ -17,18 +17,11 @@
|
||||
}
|
||||
|
||||
#define VEC(T) \
|
||||
union vec_##T##{ \
|
||||
union { \
|
||||
__m128 xmm[XMMCOUNT(T) / 4]; \
|
||||
__m256 ymm[YMMCOUNT(T) / 4]; \
|
||||
__m512 zmm[ZMMCOUNT(T) / 4]; \
|
||||
T v[4]; \
|
||||
}
|
||||
|
||||
/*
|
||||
#undef ELEMENTSIZE
|
||||
#undef XMMCOUNT
|
||||
#undef YMMCOUNT
|
||||
#undef ZMMCOUNT
|
||||
/**/
|
||||
|
||||
#endif
|
||||
|
||||
@@ -1,7 +1,6 @@
|
||||
#include "StgSharpNative.h"
|
||||
#include "sn_intrinsic.h"
|
||||
|
||||
|
||||
#if defined(_MSC_VER) && !defined(__clang__)
|
||||
#include <intrin.h>
|
||||
#include <isa_availability.h>
|
||||
@@ -71,7 +70,7 @@ void load_intrinsic_sse(sn_intrinsic *context)
|
||||
context->f32_scalar_mul = f32_scalar_mul_sse;
|
||||
context->f32_sub = (MATARITHMETIC)f32_sub_sse;
|
||||
context->f32_transpose = (MATTRANSPOSEPROC)f32_transpose_sse;
|
||||
context->normalize_3 = normalize;
|
||||
context->f32_normalize_3 = f32_normalize;
|
||||
}
|
||||
|
||||
void load_intrinsic_avx(sn_intrinsic *context)
|
||||
@@ -80,11 +79,11 @@ void load_intrinsic_avx(sn_intrinsic *context)
|
||||
context->factorial_simd = factorial_simd_sse;
|
||||
context->index_pair = index_pair_sse;
|
||||
context->f32_add = (MATARITHMETIC)f32_add_avx;
|
||||
context->f32_fma = (void(*)(void*, void*, void*))f32_fma_sse;
|
||||
context->f32_fma = (void (*)(void *, void *, void *))f32_fma_sse;
|
||||
context->f32_scalar_mul = f32_scalar_mul_avx;
|
||||
context->f32_sub = (MATARITHMETIC)f32_sub_avx;
|
||||
context->f32_transpose = (MATTRANSPOSEPROC)f32_transpose_avx;
|
||||
context->normalize_3 = normalize;
|
||||
context->f32_normalize_3 = f32_normalize;
|
||||
}
|
||||
|
||||
void load_intrinsic_512(sn_intrinsic *context)
|
||||
@@ -93,9 +92,9 @@ void load_intrinsic_512(sn_intrinsic *context)
|
||||
context->factorial_simd = factorial_simd_sse;
|
||||
context->index_pair = index_pair_sse;
|
||||
context->f32_add = (MATARITHMETIC)f32_add_512;
|
||||
context->f32_fma = (void(*)(void*, void*, void*))f32_fma_sse;
|
||||
context->f32_fma = (void (*)(void *, void *, void *))f32_fma_sse;
|
||||
context->f32_scalar_mul = f32_scalar_mul_512;
|
||||
context->f32_sub = (MATARITHMETIC)f32_sub_512;
|
||||
context->f32_transpose = (MATTRANSPOSEPROC)f32_transpose_512;
|
||||
context->normalize_3 = normalize;
|
||||
context->f32_normalize_3 = f32_normalize;
|
||||
}
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
#include "sn_intrinsic.h"
|
||||
#include "sn_internal.h"
|
||||
|
||||
SN_API void SN_DECL normalize(VEC(float) *restrict source, VEC(float) *restrict target)
|
||||
INTERNAL void SN_DECL f32_normalize(VEC(float) *restrict source, VEC(float) *restrict target)
|
||||
{
|
||||
register __m128 s = _mm_load_ps(&source->xmm);
|
||||
register __m128 a_length_sq = _mm_mul_ps(s, s);
|
||||
|
||||
Reference in New Issue
Block a user