UDocumentation UE5.7 10.02.2026 (Source)
API documentation for Unreal Engine 5.7
SimdTypes.h
Go to the documentation of this file.
1// Copyright Epic Games, Inc. All Rights Reserved.
2#pragma once
3
4#include "Chaos/Core.h"
7
8namespace Chaos
9{
10 namespace Private
11 {
12 //
13 // WIP: Not ready for public use. Keep in the Private namespace for now...
14 //
15 // NOTE: Only TNumLanes == 4 is supported for now
16 //
17
18 static const int SimdAlignment = 16;
19
73 template<int TNumLanes>
75 {
76 alignas(SimdAlignment) float V[TNumLanes];
77
78 FORCEINLINE void SetValue(const int LaneIndex, bool B)
79 {
80 reinterpret_cast<uint32*>(V)[LaneIndex] = B ? 0xFFFFFFFF : 0;
81 }
82
83 FORCEINLINE bool GetValue(const int LaneIndex) const
84 {
85 // Can't do float comparison because its a NaN for true
86 return (reinterpret_cast<const uint32*>(V)[LaneIndex] != 0);
87 }
88
91 };
92
97 template<typename T, int TNumLanes>
99 {
100 using ValueType = T;
101 alignas(SimdAlignment) ValueType V[TNumLanes];
102
103 FORCEINLINE void SetValue(const int32 LaneIndex, const ValueType F)
104 {
105 V[LaneIndex] = F;
106 }
107
108 FORCEINLINE ValueType GetValue(const int32 LaneIndex) const
109 {
110 return V[LaneIndex];
111 }
112
114 {
115 for (int32 LaneIndex = 0; LaneIndex < TNumLanes; ++LaneIndex)
116 {
117 SetValue(LaneIndex, F);
118 }
119 }
120 };
121
125 template<int TNumLanes>
127 {
128 alignas(SimdAlignment) int32 V[TNumLanes];
129
131 {
132 }
133
134 FORCEINLINE void SetValue(const int32 LaneIndex, const int32 I)
135 {
136 V[LaneIndex] = I;
137 }
138
139 FORCEINLINE int32 GetValue(const int32 LaneIndex) const
140 {
141 return V[LaneIndex];
142 }
143
145 {
146 *this = Make(I);
147 }
148
150 {
151 int32 MaxValue = V[0];
152 for (int32 LaneIndex = 1; LaneIndex < TNumLanes; ++LaneIndex)
153 {
154 MaxValue = FMath::Max(MaxValue, V[LaneIndex]);
155 }
156 return MaxValue;
157 }
158
161 };
162
166 template<int TNumLanes>
168 {
169 alignas(SimdAlignment) float V[TNumLanes];
170
172 {
173 }
174
175 FORCEINLINE void SetValue(const int32 LaneIndex, const float F)
176 {
177 V[LaneIndex] = F;
178 }
179
180 FORCEINLINE float GetValue(const int32 LaneIndex) const
181 {
182 return V[LaneIndex];
183 }
184
185 FORCEINLINE void SetValues(const float F)
186 {
187 *this = Make(F);
188 }
189
190 static TSimdRealf Make(const float F);
191 static TSimdRealf Zero();
192 static TSimdRealf One();
193 };
194
202 template<int TNumLanes>
204 {
205 static_assert(TNumLanes == 4, "Other sizes not yet supported");
206
207 alignas(SimdAlignment) float VX[TNumLanes];
208 alignas(SimdAlignment) float VY[TNumLanes];
209 alignas(SimdAlignment) float VZ[TNumLanes];
210
212 {
213 }
214
216 {
217 SetValues(V);
218 }
219
220 FORCEINLINE void SetValue(const int32 LaneIndex, const FVec3f& V)
221 {
222 VX[LaneIndex] = V.X;
223 VY[LaneIndex] = V.Y;
224 VZ[LaneIndex] = V.Z;
225 };
226
227 FORCEINLINE FVec3f GetValue(const int32 LaneIndex) const
228 {
229 return FVec3f(VX[LaneIndex], VY[LaneIndex], VZ[LaneIndex]);
230 }
231
233 {
234 *this = Make(V);
235 }
236
238 {
239 TSimdVec3f Out;
240 for (int32 LaneIndex = 0; LaneIndex < TNumLanes; ++LaneIndex)
241 {
242 Out.SetValue(LaneIndex, V);
243 }
244 return Out;
245 }
246
247 FORCEINLINE static TSimdVec3f Make(const FVec3f& V0, const FVec3f& V1, const FVec3f& V2, const FVec3f& V3)
248 {
249 TSimdVec3f Out;
250 if (TNumLanes == 4)
251 {
252 Out.SetValue(0, V0);
253 Out.SetValue(1, V1);
254 Out.SetValue(2, V2);
255 Out.SetValue(3, V3);
256
257 }
258 return Out;
259 }
260 };
261 }
262}
#define FORCEINLINE
Definition AndroidPlatform.h:140
FPlatformTypes::int32 int32
A 32-bit signed integer.
Definition Platform.h:1125
uint32_t uint32
Definition binka_ue_file_header.h:6
Definition Vector.h:407
Definition SkeletalMeshComponent.h:307
TVector< FRealSingle, 3 > FVec3f
Definition Core.h:27
Definition OverriddenPropertySet.cpp:45
Definition SimdTypes.h:127
FORCEINLINE void SetValues(const int32 I)
Definition SimdTypes.h:144
int32 V[TNumLanes]
Definition SimdTypes.h:128
FORCEINLINE int32 GetValue(const int32 LaneIndex) const
Definition SimdTypes.h:139
static TSimdInt32< TNumLanes > Make(const int32 I)
FORCEINLINE TSimdInt32()
Definition SimdTypes.h:130
static TSimdInt32< TNumLanes > Zero()
FORCEINLINE int32 GetMaxValue() const
Definition SimdTypes.h:149
FORCEINLINE void SetValue(const int32 LaneIndex, const int32 I)
Definition SimdTypes.h:134
Definition SimdTypes.h:168
FORCEINLINE float GetValue(const int32 LaneIndex) const
Definition SimdTypes.h:180
static TSimdRealf Make(const float F)
FORCEINLINE void SetValue(const int32 LaneIndex, const float F)
Definition SimdTypes.h:175
static TSimdRealf Zero()
float V[TNumLanes]
Definition SimdTypes.h:169
FORCEINLINE void SetValues(const float F)
Definition SimdTypes.h:185
static TSimdRealf One()
FORCEINLINE TSimdRealf()
Definition SimdTypes.h:171
Definition SimdTypes.h:75
static TSimdSelector< TNumLanes > True()
static TSimdSelector< TNumLanes > False()
FORCEINLINE void SetValue(const int LaneIndex, bool B)
Definition SimdTypes.h:78
float V[TNumLanes]
Definition SimdTypes.h:76
FORCEINLINE bool GetValue(const int LaneIndex) const
Definition SimdTypes.h:83
Definition SimdTypes.h:99
FORCEINLINE void SetValue(const int32 LaneIndex, const ValueType F)
Definition SimdTypes.h:103
T ValueType
Definition SimdTypes.h:100
FORCEINLINE ValueType GetValue(const int32 LaneIndex) const
Definition SimdTypes.h:108
FORCEINLINE void SetValues(const ValueType F)
Definition SimdTypes.h:113
ValueType V[TNumLanes]
Definition SimdTypes.h:101
Definition SimdTypes.h:204
float VZ[TNumLanes]
Definition SimdTypes.h:209
FORCEINLINE TSimdVec3f(const FVec3f &V)
Definition SimdTypes.h:215
FORCEINLINE void SetValues(const FVec3f &V)
Definition SimdTypes.h:232
float VX[TNumLanes]
Definition SimdTypes.h:207
float VY[TNumLanes]
Definition SimdTypes.h:208
FORCEINLINE void SetValue(const int32 LaneIndex, const FVec3f &V)
Definition SimdTypes.h:220
static FORCEINLINE TSimdVec3f Make(const FVec3f &V0, const FVec3f &V1, const FVec3f &V2, const FVec3f &V3)
Definition SimdTypes.h:247
FORCEINLINE TSimdVec3f()
Definition SimdTypes.h:211
FORCEINLINE FVec3f GetValue(const int32 LaneIndex) const
Definition SimdTypes.h:227
static FORCEINLINE TSimdVec3f Make(const FVec3f &V)
Definition SimdTypes.h:237
T Z
Definition Vector.h:68
T Y
Definition Vector.h:65
T X
Definition Vector.h:62