1 /*
2 * Copyright 2011-2013 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_TYPES_H__
18 #define __UTIL_TYPES_H__
19
20 #ifndef __KERNEL_OPENCL__
21 # include <stdlib.h>
22 #endif
23
24 /* Standard Integer Types */
25
26 #if !defined(__KERNEL_GPU__) && !defined(_WIN32)
27 # include <stdint.h>
28 #endif
29
30 #include "util/util_defines.h"
31
32 #ifndef __KERNEL_GPU__
33 # include "util/util_optimization.h"
34 # include "util/util_simd.h"
35 #endif
36
37 CCL_NAMESPACE_BEGIN
38
39 /* Types
40 *
41 * Define simpler unsigned type names, and integer with defined number of bits.
42 * Also vector types, named to be compatible with OpenCL builtin types, while
43 * working for CUDA and C++ too. */
44
45 /* Shorter Unsigned Names */
46
47 #ifndef __KERNEL_OPENCL__
48 typedef unsigned char uchar;
49 typedef unsigned int uint;
50 typedef unsigned short ushort;
51 #endif
52
53 /* Fixed Bits Types */
54
55 #ifdef __KERNEL_OPENCL__
56 typedef ulong uint64_t;
57 #endif
58
59 #ifndef __KERNEL_GPU__
60 # ifdef _WIN32
61 typedef signed char int8_t;
62 typedef unsigned char uint8_t;
63
64 typedef signed short int16_t;
65 typedef unsigned short uint16_t;
66
67 typedef signed int int32_t;
68 typedef unsigned int uint32_t;
69
70 typedef long long int64_t;
71 typedef unsigned long long uint64_t;
72 # ifdef __KERNEL_64_BIT__
73 typedef int64_t ssize_t;
74 # else
75 typedef int32_t ssize_t;
76 # endif
77 # endif /* _WIN32 */
78
79 /* Generic Memory Pointer */
80
81 typedef uint64_t device_ptr;
82 #endif /* __KERNEL_GPU__ */
83
align_up(size_t offset,size_t alignment)84 ccl_device_inline size_t align_up(size_t offset, size_t alignment)
85 {
86 return (offset + alignment - 1) & ~(alignment - 1);
87 }
88
divide_up(size_t x,size_t y)89 ccl_device_inline size_t divide_up(size_t x, size_t y)
90 {
91 return (x + y - 1) / y;
92 }
93
round_up(size_t x,size_t multiple)94 ccl_device_inline size_t round_up(size_t x, size_t multiple)
95 {
96 return ((x + multiple - 1) / multiple) * multiple;
97 }
98
round_down(size_t x,size_t multiple)99 ccl_device_inline size_t round_down(size_t x, size_t multiple)
100 {
101 return (x / multiple) * multiple;
102 }
103
is_power_of_two(size_t x)104 ccl_device_inline bool is_power_of_two(size_t x)
105 {
106 return (x & (x - 1)) == 0;
107 }
108
109 CCL_NAMESPACE_END
110
111 /* Vectorized types declaration. */
112 #include "util/util_types_uchar2.h"
113 #include "util/util_types_uchar3.h"
114 #include "util/util_types_uchar4.h"
115
116 #include "util/util_types_int2.h"
117 #include "util/util_types_int3.h"
118 #include "util/util_types_int4.h"
119
120 #include "util/util_types_uint2.h"
121 #include "util/util_types_uint3.h"
122 #include "util/util_types_uint4.h"
123
124 #include "util/util_types_ushort4.h"
125
126 #include "util/util_types_float2.h"
127 #include "util/util_types_float3.h"
128 #include "util/util_types_float4.h"
129 #include "util/util_types_float8.h"
130
131 #include "util/util_types_vector3.h"
132
133 /* Vectorized types implementation. */
134 #include "util/util_types_uchar2_impl.h"
135 #include "util/util_types_uchar3_impl.h"
136 #include "util/util_types_uchar4_impl.h"
137
138 #include "util/util_types_int2_impl.h"
139 #include "util/util_types_int3_impl.h"
140 #include "util/util_types_int4_impl.h"
141
142 #include "util/util_types_uint2_impl.h"
143 #include "util/util_types_uint3_impl.h"
144 #include "util/util_types_uint4_impl.h"
145
146 #include "util/util_types_float2_impl.h"
147 #include "util/util_types_float3_impl.h"
148 #include "util/util_types_float4_impl.h"
149 #include "util/util_types_float8_impl.h"
150
151 #include "util/util_types_vector3_impl.h"
152
153 /* SSE types. */
154 #ifndef __KERNEL_GPU__
155 # include "util/util_sseb.h"
156 # include "util/util_ssef.h"
157 # include "util/util_ssei.h"
158 # if defined(__KERNEL_AVX__) || defined(__KERNEL_AVX2__)
159 # include "util/util_avxb.h"
160 # include "util/util_avxf.h"
161 # include "util/util_avxi.h"
162 # endif
163 #endif
164
165 #endif /* __UTIL_TYPES_H__ */
166