Blender  V3.3
math_int3.h
Go to the documentation of this file.
1 /* SPDX-License-Identifier: Apache-2.0
2  * Copyright 2011-2022 Blender Foundation */
3 
4 #ifndef __UTIL_MATH_INT3_H__
5 #define __UTIL_MATH_INT3_H__
6 
7 #ifndef __UTIL_MATH_H__
8 # error "Do not include this file directly, include util/types.h instead."
9 #endif
10 
12 
13 /*******************************************************************************
14  * Declaration.
15  */
16 
17 #if !defined(__KERNEL_METAL__)
20 ccl_device_inline int3 clamp(const int3 &a, int mn, int mx);
21 ccl_device_inline int3 clamp(const int3 &a, int3 &mn, int mx);
22 #endif /* !defined(__KERNEL_METAL__) */
23 
24 /*******************************************************************************
25  * Definition.
26  */
27 
28 #if !defined(__KERNEL_METAL__)
30 {
31 # if defined(__KERNEL_SSE__) && defined(__KERNEL_SSE41__)
32  return int3(_mm_min_epi32(a.m128, b.m128));
33 # else
34  return make_int3(min(a.x, b.x), min(a.y, b.y), min(a.z, b.z));
35 # endif
36 }
37 
39 {
40 # if defined(__KERNEL_SSE__) && defined(__KERNEL_SSE41__)
41  return int3(_mm_max_epi32(a.m128, b.m128));
42 # else
43  return make_int3(max(a.x, b.x), max(a.y, b.y), max(a.z, b.z));
44 # endif
45 }
46 
47 ccl_device_inline int3 clamp(const int3 &a, int mn, int mx)
48 {
49 # ifdef __KERNEL_SSE__
50  return min(max(a, make_int3(mn)), make_int3(mx));
51 # else
52  return make_int3(clamp(a.x, mn, mx), clamp(a.y, mn, mx), clamp(a.z, mn, mx));
53 # endif
54 }
55 
56 ccl_device_inline int3 clamp(const int3 &a, int3 &mn, int mx)
57 {
58 # ifdef __KERNEL_SSE__
59  return min(max(a, mn), make_int3(mx));
60 # else
61  return make_int3(clamp(a.x, mn.x, mx), clamp(a.y, mn.y, mx), clamp(a.z, mn.z, mx));
62 # endif
63 }
64 
65 ccl_device_inline bool operator==(const int3 &a, const int3 &b)
66 {
67  return a.x == b.x && a.y == b.y && a.z == b.z;
68 }
69 
70 ccl_device_inline bool operator!=(const int3 &a, const int3 &b)
71 {
72  return !(a == b);
73 }
74 
75 ccl_device_inline bool operator<(const int3 &a, const int3 &b)
76 {
77  return a.x < b.x && a.y < b.y && a.z < b.z;
78 }
79 
81 {
82 # ifdef __KERNEL_SSE__
83  return int3(_mm_add_epi32(a.m128, b.m128));
84 # else
85  return make_int3(a.x + b.x, a.y + b.y, a.z + b.z);
86 # endif
87 }
88 
90 {
91 # ifdef __KERNEL_SSE__
92  return int3(_mm_sub_epi32(a.m128, b.m128));
93 # else
94  return make_int3(a.x - b.x, a.y - b.y, a.z - b.z);
95 # endif
96 }
97 #endif /* !__KERNEL_METAL__ */
98 
100 
101 #endif /* __UTIL_MATH_INT3_H__ */
int int3[2]
#define ccl_device_inline
Definition: cuda/compat.h:34
#define CCL_NAMESPACE_END
Definition: cuda/compat.h:9
CCL_NAMESPACE_BEGIN ccl_device_inline int3 min(int3 a, int3 b)
Definition: math_int3.h:29
ccl_device_inline int3 max(int3 a, int3 b)
Definition: math_int3.h:38
ccl_device_inline bool operator<(const int3 &a, const int3 &b)
Definition: math_int3.h:75
ccl_device_inline bool operator!=(const int3 &a, const int3 &b)
Definition: math_int3.h:70
ccl_device_inline int3 clamp(const int3 &a, int mn, int mx)
Definition: math_int3.h:47
ccl_device_inline bool operator==(const int3 &a, const int3 &b)
Definition: math_int3.h:65
ccl_device_inline int3 operator-(const int3 &a, const int3 &b)
Definition: math_int3.h:89
ccl_device_inline int3 operator+(const int3 &a, const int3 &b)
Definition: math_int3.h:80
#define make_int3(x, y, z)
Definition: metal/compat.h:207
static unsigned a[3]
Definition: RandGen.cpp:78
static const pxr::TfToken b("b", pxr::TfToken::Immortal)