Blender V4.5
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{
18# ifdef __KERNEL_SSE__
19 union {
20 __m128 m128;
21 struct {
22 float x, y, z, w;
23 };
24 };
25
26 __forceinline float4() = default;
27 __forceinline float4(const float4 &a) = default;
28 __forceinline explicit float4(const __m128 &a) : m128(a) {}
29
30 __forceinline operator const __m128 &() const
31 {
32 return m128;
33 }
34 __forceinline operator __m128 &()
35 {
36 return m128;
37 }
38
40 {
41 m128 = a.m128;
42 return *this;
43 }
44
45# else /* __KERNEL_SSE__ */
46 float x, y, z, w;
47# endif /* __KERNEL_SSE__ */
48
49# ifndef __KERNEL_GPU__
50 __forceinline float operator[](int i) const
51 {
52 util_assert(i >= 0);
53 util_assert(i < 4);
54 return *(&x + i);
55 }
56 __forceinline float &operator[](int i)
57 {
58 util_assert(i >= 0);
59 util_assert(i < 4);
60 return *(&x + i);
61 }
62# endif
63};
64
65ccl_device_inline float4 make_float4(const float x, const float y, float z, const float w)
66{
67# ifdef __KERNEL_SSE__
68 return float4(_mm_set_ps(w, z, y, x));
69# else
70 return {x, y, z, w};
71# endif
72}
73
74#endif /* __KERNEL_NATIVE_VECTOR_TYPES__ */
75
77{
78#ifdef __KERNEL_SSE__
79 return float4(_mm_set1_ps(f));
80#else
81 return make_float4(f, f, f, f);
82#endif
83}
84
86{
87 return make_float4(a.x, a.y, a.z, b);
88}
89
91{
92 return make_float4(a.x, a.y, a.z, 1.0f);
93}
94
96{
97#ifdef __KERNEL_SSE__
98 return float4(_mm_cvtepi32_ps(i.m128));
99#else
100 return make_float4((float)i.x, (float)i.y, (float)i.z, (float)i.w);
101#endif
102}
103
105{
106 return make_float3(a.x, a.y, a.z);
107}
108
110{
111#ifdef __KERNEL_SSE__
112 return int4(_mm_cvtps_epi32(f.m128));
113#else
114 return make_int4((int)f.x, (int)f.y, (int)f.z, (int)f.w);
115#endif
116}
117
118ccl_device_inline void print_float4(const ccl_private char *label, const float4 a)
119{
120#ifdef __KERNEL_PRINTF__
121 printf("%s: %.8f %.8f %.8f %.8f\n", label, (double)a.x, (double)a.y, (double)a.z, (double)a.w);
122#endif
123}
124
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
VecBase< float, 4 > float4
VecBase< int, 4 > int4
#define printf(...)
float z
Definition sky_float3.h:27
float y
Definition sky_float3.h:27
float x
Definition sky_float3.h:27
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_float4(const float x, const float y, float z, const float w)
ccl_device_inline int4 make_int4(const float4 f)