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
30 #include "dev/gen_device_info.h"
31 #include "util/macros.h"
35 #define isl_finishme(format, ...) \
37 static bool reported = false; \
39 __isl_finishme(__FILE__, __LINE__, format, ##__VA_ARGS__); \
44 void PRINTFLIKE(3, 4) UNUSED
45 __isl_finishme(const char *file
, int line
, const char *fmt
, ...);
47 #define MIN(a, b) ((a) < (b) ? (a) : (b))
48 #define MAX(a, b) ((a) > (b) ? (a) : (b))
51 isl_is_pow2(uintmax_t n
)
53 return !(n
& (n
- 1));
57 * Alignment must be a power of 2.
60 isl_is_aligned(uintmax_t n
, uintmax_t a
)
62 assert(isl_is_pow2(a
));
63 return (n
& (a
- 1)) == 0;
67 * Alignment must be a power of 2.
69 static inline uintmax_t
70 isl_align(uintmax_t n
, uintmax_t a
)
72 assert(a
!= 0 && isl_is_pow2(a
));
73 return (n
+ a
- 1) & ~(a
- 1);
76 static inline uintmax_t
77 isl_align_npot(uintmax_t n
, uintmax_t a
)
80 return ((n
+ a
- 1) / a
) * a
;
83 static inline uintmax_t
84 isl_assert_div(uintmax_t n
, uintmax_t a
)
91 * Alignment must be a power of 2.
93 static inline uintmax_t
94 isl_align_div(uintmax_t n
, uintmax_t a
)
96 return isl_align(n
, a
) / a
;
99 static inline uintmax_t
100 isl_align_div_npot(uintmax_t n
, uintmax_t a
)
102 return isl_align_npot(n
, a
) / a
;
106 * Log base 2, rounding towards zero.
108 static inline uint32_t
109 isl_log2u(uint32_t n
)
112 return 31 - __builtin_clz(n
);
115 static inline uint32_t
116 isl_round_up_to_power_of_two(uint32_t value
)
121 return 1 << (32 - __builtin_clz(value
- 1));
124 static inline uint32_t
125 isl_minify(uint32_t n
, uint32_t levels
)
127 if (unlikely(n
== 0))
130 return MAX(n
>> levels
, 1);
133 static inline struct isl_extent3d
134 isl_extent3d_sa_to_el(enum isl_format fmt
, struct isl_extent3d extent_sa
)
136 const struct isl_format_layout
*fmtl
= isl_format_get_layout(fmt
);
138 assert(extent_sa
.w
% fmtl
->bw
== 0);
139 assert(extent_sa
.h
% fmtl
->bh
== 0);
140 assert(extent_sa
.d
% fmtl
->bd
== 0);
142 return (struct isl_extent3d
) {
143 .w
= extent_sa
.w
/ fmtl
->bw
,
144 .h
= extent_sa
.h
/ fmtl
->bh
,
145 .d
= extent_sa
.d
/ fmtl
->bd
,
149 static inline struct isl_extent3d
150 isl_extent3d_el_to_sa(enum isl_format fmt
, struct isl_extent3d extent_el
)
152 const struct isl_format_layout
*fmtl
= isl_format_get_layout(fmt
);
154 return (struct isl_extent3d
) {
155 .w
= extent_el
.w
* fmtl
->bw
,
156 .h
= extent_el
.h
* fmtl
->bh
,
157 .d
= extent_el
.d
* fmtl
->bd
,
161 /* This is useful for adding the isl_prefix to genX functions */
162 #define __PASTE2(x, y) x ## y
163 #define __PASTE(x, y) __PASTE2(x, y)
164 #define isl_genX(x) __PASTE(isl_, genX(x))
167 # include "isl_genX_priv.h"
169 # define genX(x) gen4_##x
170 # include "isl_genX_priv.h"
172 # define genX(x) gen5_##x
173 # include "isl_genX_priv.h"
175 # define genX(x) gen6_##x
176 # include "isl_genX_priv.h"
178 # define genX(x) gen7_##x
179 # include "isl_genX_priv.h"
181 # define genX(x) gen75_##x
182 # include "isl_genX_priv.h"
184 # define genX(x) gen8_##x
185 # include "isl_genX_priv.h"
187 # define genX(x) gen9_##x
188 # include "isl_genX_priv.h"
190 # define genX(x) gen10_##x
191 # include "isl_genX_priv.h"
193 # define genX(x) gen11_##x
194 # include "isl_genX_priv.h"
198 #endif /* ISL_PRIV_H */