2 * Copyright 2015 Intel Corporation
4 * Permission is hereby granted, free of charge, to any person obtaining a
5 * copy of this software and associated documentation files (the "Software"),
6 * to deal in the Software without restriction, including without limitation
7 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
8 * and/or sell copies of the Software, and to permit persons to whom the
9 * Software is furnished to do so, subject to the following conditions:
11 * The above copyright notice and this permission notice (including the next
12 * paragraph) shall be included in all copies or substantial portions of the
15 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
18 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
20 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
31 #include "dev/gen_device_info.h"
32 #include "util/macros.h"
36 #define isl_finishme(format, ...) \
38 static bool reported = false; \
40 __isl_finishme(__FILE__, __LINE__, format, ##__VA_ARGS__); \
45 void PRINTFLIKE(3, 4) UNUSED
46 __isl_finishme(const char *file
, int line
, const char *fmt
, ...);
48 #define MIN(a, b) ((a) < (b) ? (a) : (b))
49 #define MAX(a, b) ((a) > (b) ? (a) : (b))
51 typedef void *(*isl_mem_copy_fn
)(void *dest
, const void *src
, size_t n
);
54 isl_is_pow2(uintmax_t n
)
56 return !(n
& (n
- 1));
60 * Alignment must be a power of 2.
63 isl_is_aligned(uintmax_t n
, uintmax_t a
)
65 assert(isl_is_pow2(a
));
66 return (n
& (a
- 1)) == 0;
70 * Alignment must be a power of 2.
72 static inline uintmax_t
73 isl_align(uintmax_t n
, uintmax_t a
)
75 assert(a
!= 0 && isl_is_pow2(a
));
76 return (n
+ a
- 1) & ~(a
- 1);
79 static inline uintmax_t
80 isl_align_npot(uintmax_t n
, uintmax_t a
)
83 return ((n
+ a
- 1) / a
) * a
;
86 static inline uintmax_t
87 isl_assert_div(uintmax_t n
, uintmax_t a
)
94 * Alignment must be a power of 2.
96 static inline uintmax_t
97 isl_align_div(uintmax_t n
, uintmax_t a
)
99 return isl_align(n
, a
) / a
;
102 static inline uintmax_t
103 isl_align_div_npot(uintmax_t n
, uintmax_t a
)
105 return isl_align_npot(n
, a
) / a
;
109 * Log base 2, rounding towards zero.
111 static inline uint32_t
112 isl_log2u(uint32_t n
)
115 return 31 - __builtin_clz(n
);
118 static inline uint32_t
119 isl_round_up_to_power_of_two(uint32_t value
)
124 return 1 << (32 - __builtin_clz(value
- 1));
127 static inline uint32_t
128 isl_minify(uint32_t n
, uint32_t levels
)
130 if (unlikely(n
== 0))
133 return MAX(n
>> levels
, 1);
136 static inline struct isl_extent3d
137 isl_extent3d_sa_to_el(enum isl_format fmt
, struct isl_extent3d extent_sa
)
139 const struct isl_format_layout
*fmtl
= isl_format_get_layout(fmt
);
141 assert(extent_sa
.w
% fmtl
->bw
== 0);
142 assert(extent_sa
.h
% fmtl
->bh
== 0);
143 assert(extent_sa
.d
% fmtl
->bd
== 0);
145 return (struct isl_extent3d
) {
146 .w
= extent_sa
.w
/ fmtl
->bw
,
147 .h
= extent_sa
.h
/ fmtl
->bh
,
148 .d
= extent_sa
.d
/ fmtl
->bd
,
152 static inline struct isl_extent3d
153 isl_extent3d_el_to_sa(enum isl_format fmt
, struct isl_extent3d extent_el
)
155 const struct isl_format_layout
*fmtl
= isl_format_get_layout(fmt
);
157 return (struct isl_extent3d
) {
158 .w
= extent_el
.w
* fmtl
->bw
,
159 .h
= extent_el
.h
* fmtl
->bh
,
160 .d
= extent_el
.d
* fmtl
->bd
,
165 _isl_memcpy_linear_to_tiled(uint32_t xt1
, uint32_t xt2
,
166 uint32_t yt1
, uint32_t yt2
,
167 char *dst
, const char *src
,
168 uint32_t dst_pitch
, int32_t src_pitch
,
170 enum isl_tiling tiling
,
171 isl_memcpy_type copy_type
);
174 _isl_memcpy_tiled_to_linear(uint32_t xt1
, uint32_t xt2
,
175 uint32_t yt1
, uint32_t yt2
,
176 char *dst
, const char *src
,
177 int32_t dst_pitch
, uint32_t src_pitch
,
179 enum isl_tiling tiling
,
180 isl_memcpy_type copy_type
);
183 _isl_memcpy_linear_to_tiled_sse41(uint32_t xt1
, uint32_t xt2
,
184 uint32_t yt1
, uint32_t yt2
,
185 char *dst
, const char *src
,
186 uint32_t dst_pitch
, int32_t src_pitch
,
188 enum isl_tiling tiling
,
189 isl_memcpy_type copy_type
);
192 _isl_memcpy_tiled_to_linear_sse41(uint32_t xt1
, uint32_t xt2
,
193 uint32_t yt1
, uint32_t yt2
,
194 char *dst
, const char *src
,
195 int32_t dst_pitch
, uint32_t src_pitch
,
197 enum isl_tiling tiling
,
198 isl_memcpy_type copy_type
);
200 /* This is useful for adding the isl_prefix to genX functions */
201 #define __PASTE2(x, y) x ## y
202 #define __PASTE(x, y) __PASTE2(x, y)
203 #define isl_genX(x) __PASTE(isl_, genX(x))
206 # include "isl_genX_priv.h"
208 # define genX(x) gen4_##x
209 # include "isl_genX_priv.h"
211 # define genX(x) gen5_##x
212 # include "isl_genX_priv.h"
214 # define genX(x) gen6_##x
215 # include "isl_genX_priv.h"
217 # define genX(x) gen7_##x
218 # include "isl_genX_priv.h"
220 # define genX(x) gen75_##x
221 # include "isl_genX_priv.h"
223 # define genX(x) gen8_##x
224 # include "isl_genX_priv.h"
226 # define genX(x) gen9_##x
227 # include "isl_genX_priv.h"
229 # define genX(x) gen10_##x
230 # include "isl_genX_priv.h"
232 # define genX(x) gen11_##x
233 # include "isl_genX_priv.h"
237 #endif /* ISL_PRIV_H */