Blender V5.0
types_float8.h
Go to the documentation of this file.
1/* SPDX-FileCopyrightText: 2017 Intel Corporation
2 * SPDX-FileCopyrightText: 2018-2022 Blender Foundation
3 *
4 * SPDX-License-Identifier: BSD-3-Clause
5 *
6 * Originally by Intel Corporation, modified by the Blender Foundation. */
7
8#pragma once
9
10#include "util/types_base.h"
11#include "util/types_float4.h"
12#include "util/types_int8.h"
13
15
16/* float8 is a reserved type in Metal that has not been implemented. For
17 * that reason this is named vfloat8 and not using native vector types. */
18
19#ifdef __KERNEL_GPU__
20struct vfloat8
21#else
22struct ccl_try_align(32) vfloat8
23#endif
24{
25#ifdef __KERNEL_AVX__
26 union {
27 __m256 m256;
28 struct {
29 float a, b, c, d, e, f, g, h;
30 };
31 };
32
33 __forceinline vfloat8() = default;
34 __forceinline vfloat8(const vfloat8 &a) = default;
35 __forceinline explicit vfloat8(const __m256 &a) : m256(a) {}
36
37 __forceinline operator const __m256 &() const
38 {
39 return m256;
40 }
41 __forceinline operator __m256 &()
42 {
43 return m256;
44 }
45
46 __forceinline vfloat8 &operator=(const vfloat8 &a)
47 {
48 m256 = a.m256;
49 return *this;
50 }
51
52#else /* __KERNEL_AVX__ */
53 float a, b, c, d, e, f, g, h;
54#endif /* __KERNEL_AVX__ */
55
56#ifndef __KERNEL_GPU__
57 __forceinline float operator[](int i) const
58 {
59 util_assert(i >= 0);
60 util_assert(i < 8);
61 return *(&a + i);
62 }
63 __forceinline float &operator[](int i)
64 {
65 util_assert(i >= 0);
66 util_assert(i < 8);
67 return *(&a + i);
68 }
69#endif
70};
71
72ccl_device_inline vfloat8 make_vfloat8(const float f)
73{
74#ifdef __KERNEL_AVX__
75 vfloat8 r(_mm256_set1_ps(f));
76#else
77 vfloat8 r = {f, f, f, f, f, f, f, f};
78#endif
79 return r;
80}
81
82ccl_device_inline vfloat8 make_vfloat8(const float a,
83 const float b,
84 float c,
85 const float d,
86 float e,
87 const float f,
88 float g,
89 const float h)
90{
91#ifdef __KERNEL_AVX__
92 vfloat8 r(_mm256_setr_ps(a, b, c, d, e, f, g, h));
93#else
94 vfloat8 r = {a, b, c, d, e, f, g, h};
95#endif
96 return r;
97}
98
100{
101#ifdef __KERNEL_AVX__
102 return vfloat8(_mm256_insertf128_ps(_mm256_castps128_ps256(a), b, 1));
103#else
104 return make_vfloat8(a.x, a.y, a.z, a.w, b.x, b.y, b.z, b.w);
105#endif
106}
107
108ccl_device_inline void print_vfloat8(const ccl_private char *label, const vfloat8 a)
109{
110#ifdef __KERNEL_PRINTF__
111 printf("%s: %.8f %.8f %.8f %.8f %.8f %.8f %.8f %.8f\n",
112 label,
113 (double)a.a,
114 (double)a.b,
115 (double)a.c,
116 (double)a.d,
117 (double)a.e,
118 (double)a.f,
119 (double)a.g,
120 (double)a.h);
121#endif
122}
123
124ccl_device_inline vint8 make_vint8(const vfloat8 f)
125{
126#ifdef __KERNEL_AVX__
127 return vint8(_mm256_cvtps_epi32(f.m256));
128#else
129 return make_vint8(
130 (int)f.a, (int)f.b, (int)f.c, (int)f.d, (int)f.e, (int)f.f, (int)f.g, (int)f.h);
131#endif
132}
133
ATTR_WARN_UNUSED_RESULT const BMVert const BMEdge * e
btGeneric6DofConstraint & operator=(btGeneric6DofConstraint &other)
SIMD_FORCE_INLINE btVector3 & operator[](int i)
Get a mutable reference to a row of the matrix as a vector.
#define util_assert(statement)
#define ccl_private
#define ccl_device_inline
#define ccl_try_align(...)
#define __forceinline
#define CCL_NAMESPACE_END
#define printf(...)
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 vfloat8 make_vfloat8(const float f)
ccl_device_inline void print_vfloat8(const ccl_private char *label, const vfloat8 a)
ccl_device_inline vint8 make_vint8(const vfloat8 f)