Blender V5.0
types_float4.h
Go to the documentation of this file.
1/* SPDX-FileCopyrightText: 2011-2022 Blender Foundation
2 *
3 * SPDX-License-Identifier: Apache-2.0 */
4
5#pragma once
6
7#include "util/types_base.h"
8#include "util/types_float3.h"
9#include "util/types_int4.h"
10
12
13#ifndef __KERNEL_NATIVE_VECTOR_TYPES__
14struct int4;
15
16struct ccl_try_align(16) float4 {
17# ifdef __KERNEL_SSE__
18 union {
19 __m128 m128;
20 struct {
21 float x, y, z, w;
22 };
23 };
24
25 __forceinline float4() = default;
26 __forceinline float4(const float4 &a) = default;
27 __forceinline explicit float4(const __m128 &a) : m128(a) {}
28
29 __forceinline operator const __m128 &() const
30 {
31 return m128;
32 }
33 __forceinline operator __m128 &()
34 {
35 return m128;
36 }
37
39 {
40 m128 = a.m128;
41 return *this;
42 }
43
44# else /* __KERNEL_SSE__ */
45 float x, y, z, w;
46# endif /* __KERNEL_SSE__ */
47
48# ifndef __KERNEL_GPU__
49 __forceinline float operator[](int i) const
50 {
51 util_assert(i >= 0);
52 util_assert(i < 4);
53 return *(&x + i);
54 }
55 __forceinline float &operator[](int i)
56 {
57 util_assert(i >= 0);
58 util_assert(i < 4);
59 return *(&x + i);
60 }
61# endif
62};
63
64ccl_device_inline float4 make_float4(const float x, const float y, float z, const float w)
65{
66# ifdef __KERNEL_SSE__
67 return float4(_mm_set_ps(w, z, y, x));
68# else
69 return {x, y, z, w};
70# endif
71}
72
73#endif /* __KERNEL_NATIVE_VECTOR_TYPES__ */
74
76{
77#ifdef __KERNEL_SSE__
78 return float4(_mm_set1_ps(f));
79#else
80 return make_float4(f, f, f, f);
81#endif
82}
83
85{
86 return make_float4(a.x, a.y, a.z, b);
87}
88
90{
91 return make_float4(a.x, a.y, a.z, 1.0f);
92}
93
95{
96 return make_float4(a.x, a.y, a.z, 1.0f);
97}
98
100{
101#ifdef __KERNEL_SSE__
102 return float4(_mm_cvtepi32_ps(i.m128));
103#else
104 return make_float4((float)i.x, (float)i.y, (float)i.z, (float)i.w);
105#endif
106}
107
109{
110 return make_float3(a.x, a.y, a.z);
111}
112
114{
115#ifdef __KERNEL_SSE__
116 return int4(_mm_cvtps_epi32(f.m128));
117#else
118 return make_int4((int)f.x, (int)f.y, (int)f.z, (int)f.w);
119#endif
120}
121
122#if defined __METAL_PRINTF__
123# define print_float4(label, a) \
124 metal::os_log_default.log_debug(label ": %.8f %.8f %.8f %.8f", a.x, a.y, a.z, a.w)
125#else
126ccl_device_inline void print_float4(const ccl_private char *label, const float4 a)
127{
128# ifdef __KERNEL_PRINTF__
129 printf("%s: %.8f %.8f %.8f %.8f\n", label, (double)a.x, (double)a.y, (double)a.z, (double)a.w);
130# endif
131}
132#endif
133
btGeneric6DofConstraint & operator=(btGeneric6DofConstraint &other)
SIMD_FORCE_INLINE btVector3 & operator[](int i)
Get a mutable reference to a row of the matrix as a vector.
SIMD_FORCE_INLINE const btScalar & z() const
Return the z value.
Definition btQuadWord.h:117
SIMD_FORCE_INLINE const btScalar & w() const
Return the w value.
Definition btQuadWord.h:119
#define util_assert(statement)
#define ccl_private
#define ccl_device_inline
#define ccl_try_align(...)
#define __forceinline
#define CCL_NAMESPACE_END
#define printf(...)
VecBase< float, 4 > float4
VecBase< int, 4 > int4
#define make_float4
float z
Definition sky_math.h:136
float y
Definition sky_math.h:136
float x
Definition sky_math.h:136
float y
Definition sky_math.h:225
float z
Definition sky_math.h:225
float x
Definition sky_math.h:225
float w
Definition sky_math.h:225
i
Definition text_draw.cc:230
ccl_device_inline float3 make_float3(const float4 a)
ccl_device_inline void print_float4(const ccl_private char *label, const float4 a)
ccl_device_inline float4 make_homogeneous(const float3 a)
ccl_device_inline int4 make_int4(const float4 f)