Blender V5.0
math_int3.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_int3.h"
8
10
11#if !defined(__KERNEL_METAL__)
13{
14# if defined(__KERNEL_SSE__) && defined(__KERNEL_SSE42__)
15 return int3(_mm_min_epi32(a.m128, b.m128));
16# else
17 return make_int3(min(a.x, b.x), min(a.y, b.y), min(a.z, b.z));
18# endif
19}
20
22{
23# if defined(__KERNEL_SSE__) && defined(__KERNEL_SSE42__)
24 return int3(_mm_max_epi32(a.m128, b.m128));
25# else
26 return make_int3(max(a.x, b.x), max(a.y, b.y), max(a.z, b.z));
27# endif
28}
29
30ccl_device_inline int3 clamp(const int3 a, const int mn, const int mx)
31{
32# ifdef __KERNEL_SSE__
33 return min(max(a, make_int3(mn)), make_int3(mx));
34# else
35 return make_int3(clamp(a.x, mn, mx), clamp(a.y, mn, mx), clamp(a.z, mn, mx));
36# endif
37}
38
39ccl_device_inline int3 clamp(const int3 a, int3 &mn, const int mx)
40{
41# ifdef __KERNEL_SSE__
42 return min(max(a, mn), make_int3(mx));
43# else
44 return make_int3(clamp(a.x, mn.x, mx), clamp(a.y, mn.y, mx), clamp(a.z, mn.z, mx));
45# endif
46}
47
49{
50 return a.x == b.x && a.y == b.y && a.z == b.z;
51}
52
54{
55 return !(a == b);
56}
57
59{
60 return a.x < b.x && a.y < b.y && a.z < b.z;
61}
62
64{
65# ifdef __KERNEL_SSE__
66 return int3(_mm_add_epi32(a.m128, b.m128));
67# else
68 return make_int3(a.x + b.x, a.y + b.y, a.z + b.z);
69# endif
70}
71
73{
74# ifdef __KERNEL_SSE__
75 return int3(_mm_sub_epi32(a.m128, b.m128));
76# else
77 return make_int3(a.x - b.x, a.y - b.y, a.z - b.z);
78# endif
79}
80
82{
83 return make_int3(a.x >> i, a.y >> i, a.z >> i);
84}
85
87{
88 return make_int3(a.x * b.x, a.y * b.y, a.z * b.z);
89}
90
92{
93 return make_int3(a.x ^ b.x, a.y ^ b.y, a.z ^ b.z);
94}
95
97{
98 return make_int3(a.x & b.x, a.y & b.y, a.z & b.z);
99}
100
102{
103# ifdef __KERNEL_SSE__
104 return int3(_mm_and_si128(a.m128, _mm_set1_epi32(b)));
105# else
106 return make_int3(a.x & b, a.y & b, a.z & b);
107# endif
108}
109
111{
112 return a.x && a.y && a.z;
113}
114
115#endif /* !__KERNEL_METAL__ */
116
#define ccl_device_inline
#define CCL_NAMESPACE_END
ccl_device_forceinline int3 make_int3(const int x, const int y, const int z)
constexpr T clamp(T, U, U) RET
VecBase< int, 3 > int3
ccl_device_inline int3 operator*(const int3 a, const int3 b)
Definition math_int3.h:86
ccl_device_inline int3 operator+(const int3 a, const int3 b)
Definition math_int3.h:63
ccl_device_inline bool operator<(const int3 a, const int3 b)
Definition math_int3.h:58
ccl_device_inline int3 operator>>(const int3 a, const int i)
Definition math_int3.h:81
ccl_device_inline int3 operator-(const int3 a, const int3 b)
Definition math_int3.h:72
ccl_device_inline bool all(const int3 a)
Definition math_int3.h:110
ccl_device_inline int3 operator&(const int3 a, const int3 b)
Definition math_int3.h:96
ccl_device_inline bool operator==(const int3 a, const int3 b)
Definition math_int3.h:48
ccl_device_inline bool operator!=(const int3 a, const int3 b)
Definition math_int3.h:53
ccl_device_inline int3 operator^(const int3 a, const int3 b)
Definition math_int3.h:91
ccl_device_inline int3 clamp(const int3 a, const int mn, const int mx)
Definition math_int3.h:30
#define min(a, b)
Definition sort.cc:36
i
Definition text_draw.cc:230
max
Definition text_draw.cc:251