RavEngine
Loading...
Searching...
No Matches
simd_math_config.h
1//----------------------------------------------------------------------------//
2// //
3// ozz-animation is hosted at http://github.com/guillaumeblanc/ozz-animation //
4// and distributed under the MIT License (MIT). //
5// //
6// Copyright (c) Guillaume Blanc //
7// //
8// Permission is hereby granted, free of charge, to any person obtaining a //
9// copy of this software and associated documentation files (the "Software"), //
10// to deal in the Software without restriction, including without limitation //
11// the rights to use, copy, modify, merge, publish, distribute, sublicense, //
12// and/or sell copies of the Software, and to permit persons to whom the //
13// Software is furnished to do so, subject to the following conditions: //
14// //
15// The above copyright notice and this permission notice shall be included in //
16// all copies or substantial portions of the Software. //
17// //
18// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR //
19// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, //
20// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL //
21// THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER //
22// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING //
23// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER //
24// DEALINGS IN THE SOFTWARE. //
25// //
26//----------------------------------------------------------------------------//
27
28#ifndef OZZ_OZZ_BASE_MATHS_INTERNAL_SIMD_MATH_CONFIG_H_
29#define OZZ_OZZ_BASE_MATHS_INTERNAL_SIMD_MATH_CONFIG_H_
30
31#include "ozz/base/platform.h"
32
33// Avoid SIMD instruction detection if reference (aka scalar) implementation is
34// forced.
35#if !defined(OZZ_BUILD_SIMD_REF)
36
37// Try to match a SSE2+ version.
38#if defined(__AVX2__) || defined(OZZ_SIMD_AVX2)
39#include <immintrin.h>
40#define OZZ_SIMD_AVX2
41#define OZZ_SIMD_AVX // avx is available if avx2 is.
42#endif
43
44#if defined(__FMA__) || defined(OZZ_SIMD_FMA)
45#include <immintrin.h>
46#define OZZ_SIMD_FMA
47#endif
48
49#if defined(__AVX__) || defined(OZZ_SIMD_AVX)
50#include <immintrin.h>
51#define OZZ_SIMD_AVX
52#define OZZ_SIMD_SSE4_2 // SSE4.2 is available if avx is.
53#endif
54
55#if defined(__SSE4_2__) || defined(OZZ_SIMD_SSE4_2)
56#include <nmmintrin.h>
57#define OZZ_SIMD_SSE4_2
58#define OZZ_SIMD_SSE4_1 // SSE4.1 is available if SSE4.2 is.
59#endif
60
61#if defined(__SSE4_1__) || defined(OZZ_SIMD_SSE4_1)
62#include <smmintrin.h>
63#define OZZ_SIMD_SSE4_1
64#define OZZ_SIMD_SSSE3 // SSSE3 is available if SSE4.1 is.
65#endif
66
67#if defined(__SSSE3__) || defined(OZZ_SIMD_SSSE3)
68#include <tmmintrin.h>
69#define OZZ_SIMD_SSSE3
70#define OZZ_SIMD_SSE3 // SSE3 is available if SSSE3 is.
71#endif
72
73#if defined(__SSE3__) || defined(OZZ_SIMD_SSE3)
74#include <pmmintrin.h>
75#define OZZ_SIMD_SSE3
76#define OZZ_SIMD_SSE2 // SSE2 is available if SSE3 is.
77#endif
78
79// x64/amd64 have SSE2 instructions
80// _M_IX86_FP is 2 if /arch:SSE2, /arch:AVX or /arch:AVX2 was used.
81#if defined(__SSE2__) || defined(_M_AMD64) || defined(_M_X64) || \
82 (_M_IX86_FP >= 2) || defined(OZZ_SIMD_SSE2)
83#include <emmintrin.h>
84#define OZZ_SIMD_SSE2
85#define OZZ_SIMD_SSEx // OZZ_SIMD_SSEx is the generic flag for SSE support
86#endif
87
88// End of SIMD instruction detection
89#endif // !OZZ_BUILD_SIMD_REF
90
91// SEE* intrinsics available
92#if defined(OZZ_SIMD_SSEx)
93
94namespace ozz {
95namespace math {
96
97// Vector of four floating point values.
98typedef __m128 SimdFloat4;
99
100// Argument type for Float4.
101typedef const __m128 _SimdFloat4;
102
103// Vector of four integer values.
104typedef __m128i SimdInt4;
105
106// Argument type for Int4.
107typedef const __m128i _SimdInt4;
108} // namespace math
109} // namespace ozz
110
111#else // No builtin simd available
112
113// No simd instruction set detected, switch back to reference implementation.
114// OZZ_SIMD_REF is the generic flag for SIMD reference implementation.
115#define OZZ_SIMD_REF
116
117// Declares reference simd float and integer vectors outside of ozz::math, in
118// order to match non-reference implementation details.
119
120// Vector of four floating point values.
122 alignas(16) float x;
123 float y;
124 float z;
125 float w;
126};
127
128// Vector of four integer values.
130 alignas(16) int x;
131 int y;
132 int z;
133 int w;
134};
135
136namespace ozz {
137namespace math {
138
139// Vector of four floating point values.
140typedef SimdFloat4Def SimdFloat4;
141
142// Argument type for SimdFloat4
143typedef const SimdFloat4& _SimdFloat4;
144
145// Vector of four integer values.
146typedef SimdInt4Def SimdInt4;
147
148// Argument type for SimdInt4.
149typedef const SimdInt4& _SimdInt4;
150
151} // namespace math
152} // namespace ozz
153#endif // OZZ_SIMD_x
154
155// Native SIMD operator already exist on some compilers, so they have to be
156// disable from ozz implementation
157#if !defined(OZZ_SIMD_REF) && (defined(__GNUC__) || defined(__llvm__))
158#define OZZ_DISABLE_SSE_NATIVE_OPERATORS
159#endif
160#endif // OZZ_OZZ_BASE_MATHS_INTERNAL_SIMD_MATH_CONFIG_H_
Definition simd_math_config.h:121
Definition simd_math_config.h:129