mirror of
https://gitea.nishi.boats/pyrite-dev/milsko
synced 2026-01-21 00:24:07 +00:00
closes #10
git-svn-id: http://svn2.nishi.boats/svn/milsko/trunk@570 b9cfdab3-6d41-4d17-bbe4-086880011989
This commit is contained in:
@@ -1,7 +1,7 @@
|
||||
/* $Id$ */
|
||||
/*!
|
||||
* @file Mw/LowLevelMath.h
|
||||
* @brief A few portable functions for supporting simultaneously supporting SIMD and not supporting it
|
||||
* @brief A few portable functions for simultaneously supporting SIMD and not supporting it
|
||||
* @warning This is mostly used internally. Anything undocumented, and/or anything with an _ prefix (that doesn't have a corresponding typedef) should be avoided.
|
||||
*/
|
||||
|
||||
@@ -12,70 +12,123 @@
|
||||
#include <Mw/MachDep.h>
|
||||
|
||||
#if defined(__i386__) || defined(__x86_64__) || defined(__WATCOMC__)
|
||||
#define MwLLMathMMX
|
||||
#endif
|
||||
|
||||
#if !defined(MwLLMathMMX)
|
||||
// #warning LowLevelMath.h does not yet support this platform
|
||||
#define MwLLMath_x86
|
||||
#endif
|
||||
|
||||
/*!
|
||||
* @brief Generic vector type
|
||||
* @warning Do not try to instantiate this yourself, use the appropriate functions instead.
|
||||
* @brief SIMD vector
|
||||
*/
|
||||
|
||||
typedef struct _MwLLVec MwLLVec;
|
||||
|
||||
typedef union _MwLLVecUnion MwLLVecUnion;
|
||||
/*!
|
||||
* @brief SIMD vector type
|
||||
* @warning Not exhaustive, enums subject to be added later.
|
||||
*/
|
||||
enum MwLLVecType {
|
||||
MwLLVecTypeU8 = 0,
|
||||
MwLLVecTypeU16,
|
||||
MwLLVecTypeU32,
|
||||
MwLLVecTypeU64,
|
||||
MwLLVecTypeI8,
|
||||
MwLLVecTypeI16,
|
||||
MwLLVecTypeI32,
|
||||
MwLLVecTypeI64,
|
||||
|
||||
// clang-format off
|
||||
struct _MwLLVecDataU8x8 { MwU8 a; MwU8 b; MwU8 c; MwU8 d; MwU8 e; MwU8 f; MwU8 g; MwU8 h;};
|
||||
struct _MwLLVecDataU16x4 { MwU16 a; MwU16 b; MwU16 c; MwU16 d;};
|
||||
struct _MwLLVecDataU32x2 { MwU32 a; MwU32 b;};
|
||||
struct _MwLLVecDataI8x8 { MwI8 a; MwI8 b; MwI8 c; MwI8 d; MwI8 e; MwI8 f; MwI8 g; MwI8 h;};
|
||||
struct _MwLLVecDataI16x4 { MwI16 a; MwI16 b; MwI16 c; MwI16 d;};
|
||||
struct _MwLLVecDataI32x2 { MwI32 a; MwI32 b;};
|
||||
union _MwLLVecUnion {
|
||||
struct _MwLLVecDataU8x8 u8; struct _MwLLVecDataU16x4 u16; struct _MwLLVecDataU32x2 u32;
|
||||
struct _MwLLVecDataI8x8 i8; struct _MwLLVecDataI16x4 i16; struct _MwLLVecDataI32x2 i32;
|
||||
MwU64 all;
|
||||
};
|
||||
// clang-format on
|
||||
enum _MwLLVecType {
|
||||
_MwLLVecTypeU8x8 = 0,
|
||||
_MwLLVecTypeU16x4 = 1,
|
||||
_MwLLVecTypeU32x2 = 2,
|
||||
_MwLLVecTypeI8x8 = 3,
|
||||
_MwLLVecTypeI16x4 = 4,
|
||||
_MwLLVecTypeI32x2 = 5,
|
||||
|
||||
_MwLLVecType_Max,
|
||||
};
|
||||
struct _MwLLVec {
|
||||
int ty;
|
||||
MwLLVecUnion un;
|
||||
MwLLVecType_Max,
|
||||
};
|
||||
|
||||
MWDECL MwLLVec _MwLLVecCreateGeneric(int ty, ...);
|
||||
/*!
|
||||
* @brief Create a SIMD Vector (variadic)
|
||||
* @warning Prefer using the macro version.
|
||||
*/
|
||||
MWDECL MwLLVec* MwLLVaVecCreate(int ty, MwU64 size, ...);
|
||||
|
||||
#define MwLLVecU8x8(a, b, c, d, e, f, g, h) _MwLLVecCreateGeneric(_MwLLVecTypeU8x8, a, b, c, d, e, f, g, h)
|
||||
#define MwLLVecU16x4(a, b, c, d) _MwLLVecCreateGeneric(_MwLLVecTypeU16x4, a, b, c, d)
|
||||
#define MwLLVecU32x2(a, b) _MwLLVecCreateGeneric(_MwLLVecTypeU32x2, a, b)
|
||||
#define MwLLVecI8x8(a, b, c, d, e, f, g, h) _MwLLVecCreateGeneric(_MwLLVecTypeI8x8, a, b, c, d, e, f, g, h)
|
||||
#define MwLLVecI16x4(a, b, c, d) _MwLLVecCreateGeneric(_MwLLVecTypeI16x4, a, b, c, d)
|
||||
#define MwLLVecI32x2(a, b) _MwLLVecCreateGeneric(_MwLLVecTypeI32x2, a, b)
|
||||
/*!
|
||||
* @brief Destroy the given SIMD Vector
|
||||
*/
|
||||
MWDECL void MwLLVecDestroy(MwLLVec* vec);
|
||||
|
||||
/*!
|
||||
* @brief index the given SIMD Vector (u8)
|
||||
*/
|
||||
MWDECL MwU8 MwLLVecIndexU8(MwLLVec* vec, MwU64 index);
|
||||
/*!
|
||||
* @brief index the given SIMD Vector (u16)
|
||||
*/
|
||||
MWDECL MwU16 MwLLVecIndexU16(MwLLVec* vec, MwU64 index);
|
||||
/*!
|
||||
* @brief index the given SIMD Vector (u32)
|
||||
*/
|
||||
MWDECL MwU32 MwLLVecIndexU32(MwLLVec* vec, MwU64 index);
|
||||
/*!
|
||||
* @brief index the given SIMD Vector (u64)
|
||||
*/
|
||||
MWDECL MwU64 MwLLVecIndexU64(MwLLVec* vec, MwU64 index);
|
||||
|
||||
/*!
|
||||
* @brief index the given SIMD Vector (i8)
|
||||
*/
|
||||
MWDECL MwI8 MwLLVecIndexI8(MwLLVec* vec, MwU64 index);
|
||||
/*!
|
||||
* @brief index the given SIMD Vector (i16)
|
||||
*/
|
||||
MWDECL MwI16 MwLLVecIndexI16(MwLLVec* vec, MwU64 index);
|
||||
/*!
|
||||
* @brief index the given SIMD Vector (i32)
|
||||
*/
|
||||
MWDECL MwI32 MwLLVecIndexI32(MwLLVec* vec, MwU64 index);
|
||||
/*!
|
||||
* @brief index the given SIMD Vector (i64)
|
||||
*/
|
||||
MWDECL MwI64 MwLLVecIndexI64(MwLLVec* vec, MwU64 index);
|
||||
|
||||
/*!
|
||||
* @brief SIMD Vector add
|
||||
*/
|
||||
MWDECL void MwLLMathAdd(MwLLVec* a, MwLLVec* b, MwLLVec* out);
|
||||
/*!
|
||||
* @brief SIMD Vector multiply
|
||||
*/
|
||||
MWDECL void MwLLMathMultiply(MwLLVec* a, MwLLVec* b, MwLLVec* out);
|
||||
/*!
|
||||
* @brief SIMD Vector subtract
|
||||
*/
|
||||
MWDECL void MwLLMathSub(MwLLVec* a, MwLLVec* b, MwLLVec* out);
|
||||
/*!
|
||||
* @brief SIMD Vector reciprocal
|
||||
*/
|
||||
MWDECL void MwLLMathReciprocal(MwLLVec* a, MwLLVec* out);
|
||||
/*!
|
||||
* @brief SIMD Vector square root
|
||||
*/
|
||||
MWDECL void MwLLMathSquareRoot(MwLLVec* a, MwLLVec* out);
|
||||
/*!
|
||||
* @brief SIMD Vector bitwise and
|
||||
*/
|
||||
MWDECL void MwLLMathAnd(MwLLVec* a, MwLLVec* b, MwLLVec* out);
|
||||
/*!
|
||||
* @brief SIMD Vector bitwise or
|
||||
*/
|
||||
MWDECL void MwLLMathOr(MwLLVec* a, MwLLVec* b, MwLLVec* out);
|
||||
/*!
|
||||
* @brief SIMD Vector bitwise shift right
|
||||
*/
|
||||
MWDECL void MwLLMathShiftRight(MwLLVec* a, MwLLVec* b, MwLLVec* out);
|
||||
/*!
|
||||
* @brief SIMD Vector bitwise shift left
|
||||
*/
|
||||
MWDECL void MwLLMathShiftLeft(MwLLVec* a, MwLLVec* b, MwLLVec* out);
|
||||
/*!
|
||||
* @brief SIMD Vector bitwise equal
|
||||
*/
|
||||
MWDECL void MwLLMathEqual(MwLLVec* a, MwLLVec* b, MwLLVec* out);
|
||||
/*!
|
||||
* @brief SIMD Vector greater then
|
||||
*/
|
||||
MWDECL void MwLLMathGreaterThen(MwLLVec* a, MwLLVec* b, MwLLVec* out);
|
||||
/*!
|
||||
* @brief SIMD Vector lesser then
|
||||
*/
|
||||
MWDECL void MwLLMathLesserThen(MwLLVec* a, MwLLVec* b, MwLLVec* out);
|
||||
|
||||
#endif
|
||||
|
||||
Reference in New Issue
Block a user