Blender  V2.93
util_math_int3.h
Go to the documentation of this file.
1 /*
2  * Copyright 2011-2017 Blender Foundation
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16 
17 #ifndef __UTIL_MATH_INT3_H__
18 #define __UTIL_MATH_INT3_H__
19 
20 #ifndef __UTIL_MATH_H__
21 # error "Do not include this file directly, include util_types.h instead."
22 #endif
23 
25 
26 /*******************************************************************************
27  * Declaration.
28  */
29 
30 #ifndef __KERNEL_OPENCL__
33 ccl_device_inline int3 clamp(const int3 &a, int mn, int mx);
34 ccl_device_inline int3 clamp(const int3 &a, int3 &mn, int mx);
35 #endif /* !__KERNEL_OPENCL__ */
36 
37 /*******************************************************************************
38  * Definition.
39  */
40 
41 #ifndef __KERNEL_OPENCL__
43 {
44 # if defined(__KERNEL_SSE__) && defined(__KERNEL_SSE41__)
45  return int3(_mm_min_epi32(a.m128, b.m128));
46 # else
47  return make_int3(min(a.x, b.x), min(a.y, b.y), min(a.z, b.z));
48 # endif
49 }
50 
52 {
53 # if defined(__KERNEL_SSE__) && defined(__KERNEL_SSE41__)
54  return int3(_mm_max_epi32(a.m128, b.m128));
55 # else
56  return make_int3(max(a.x, b.x), max(a.y, b.y), max(a.z, b.z));
57 # endif
58 }
59 
60 ccl_device_inline int3 clamp(const int3 &a, int mn, int mx)
61 {
62 # ifdef __KERNEL_SSE__
63  return min(max(a, make_int3(mn)), make_int3(mx));
64 # else
65  return make_int3(clamp(a.x, mn, mx), clamp(a.y, mn, mx), clamp(a.z, mn, mx));
66 # endif
67 }
68 
69 ccl_device_inline int3 clamp(const int3 &a, int3 &mn, int mx)
70 {
71 # ifdef __KERNEL_SSE__
72  return min(max(a, mn), make_int3(mx));
73 # else
74  return make_int3(clamp(a.x, mn.x, mx), clamp(a.y, mn.y, mx), clamp(a.z, mn.z, mx));
75 # endif
76 }
77 
78 ccl_device_inline bool operator==(const int3 &a, const int3 &b)
79 {
80  return a.x == b.x && a.y == b.y && a.z == b.z;
81 }
82 
83 ccl_device_inline bool operator!=(const int3 &a, const int3 &b)
84 {
85  return !(a == b);
86 }
87 
88 ccl_device_inline bool operator<(const int3 &a, const int3 &b)
89 {
90  return a.x < b.x && a.y < b.y && a.z < b.z;
91 }
92 
94 {
95 # ifdef __KERNEL_SSE__
96  return int3(_mm_add_epi32(a.m128, b.m128));
97 # else
98  return make_int3(a.x + b.x, a.y + b.y, a.z + b.z);
99 # endif
100 }
101 
103 {
104 # ifdef __KERNEL_SSE__
105  return int3(_mm_sub_epi32(a.m128, b.m128));
106 # else
107  return make_int3(a.x - b.x, a.y - b.y, a.z - b.z);
108 # endif
109 }
110 #endif /* !__KERNEL_OPENCL__ */
111 
113 
114 #endif /* __UTIL_MATH_INT3_H__ */
#define ccl_device_inline
#define CCL_NAMESPACE_END
#define make_int3(x, y, z)
static unsigned a[3]
Definition: RandGen.cpp:92
CCL_NAMESPACE_BEGIN ccl_device_inline int3 min(int3 a, int3 b)
ccl_device_inline int3 max(int3 a, int3 b)
ccl_device_inline bool operator<(const int3 &a, const int3 &b)
ccl_device_inline bool operator!=(const int3 &a, const int3 &b)
ccl_device_inline int3 clamp(const int3 &a, int mn, int mx)
ccl_device_inline bool operator==(const int3 &a, const int3 &b)
ccl_device_inline int3 operator-(const int3 &a, const int3 &b)
ccl_device_inline int3 operator+(const int3 &a, const int3 &b)