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
28 #include "brw_device_info.h"
29 #include "util/macros.h"
33 #define isl_finishme(format, ...) \
34 __isl_finishme(__FILE__, __LINE__, format, ##__VA_ARGS__)
36 void PRINTFLIKE(3, 4) UNUSED
37 __isl_finishme(const char *file
, int line
, const char *fmt
, ...);
39 #define MIN(a, b) ((a) < (b) ? (a) : (b))
40 #define MAX(a, b) ((a) > (b) ? (a) : (b))
42 static inline uint32_t
44 return __builtin_ffs(n
);
48 isl_is_pow2(uintmax_t n
)
50 return !(n
& (n
- 1));
54 * Alignment must be a power of 2.
57 isl_is_aligned(uintmax_t n
, uintmax_t a
)
59 assert(isl_is_pow2(a
));
60 return (n
& (a
- 1)) == 0;
64 * Alignment must be a power of 2.
66 static inline uintmax_t
67 isl_align(uintmax_t n
, uintmax_t a
)
69 assert(a
!= 0 && isl_is_pow2(a
));
70 return (n
+ a
- 1) & ~(a
- 1);
73 static inline uintmax_t
74 isl_align_npot(uintmax_t n
, uintmax_t a
)
77 return ((n
+ a
- 1) / a
) * a
;
81 * Alignment must be a power of 2.
83 static inline uintmax_t
84 isl_align_div(uintmax_t n
, uintmax_t a
)
86 return isl_align(n
, a
) / a
;
89 static inline uintmax_t
90 isl_align_div_npot(uintmax_t n
, uintmax_t a
)
92 return isl_align_npot(n
, a
) / a
;
96 * Log base 2, rounding towards zero.
98 static inline uint32_t
102 return 31 - __builtin_clz(n
);
105 static inline uint32_t
106 isl_minify(uint32_t n
, uint32_t levels
)
108 if (unlikely(n
== 0))
111 return MAX(n
>> levels
, 1);
114 static inline struct isl_extent3d
115 isl_extent3d_sa_to_el(enum isl_format fmt
, struct isl_extent3d extent_sa
)
117 const struct isl_format_layout
*fmtl
= isl_format_get_layout(fmt
);
119 assert(extent_sa
.w
% fmtl
->bw
== 0);
120 assert(extent_sa
.h
% fmtl
->bh
== 0);
121 assert(extent_sa
.d
% fmtl
->bd
== 0);
123 return (struct isl_extent3d
) {
124 .w
= extent_sa
.w
/ fmtl
->bw
,
125 .h
= extent_sa
.h
/ fmtl
->bh
,
126 .d
= extent_sa
.d
/ fmtl
->bd
,
130 static inline struct isl_extent3d
131 isl_extent3d_el_to_sa(enum isl_format fmt
, struct isl_extent3d extent_el
)
133 const struct isl_format_layout
*fmtl
= isl_format_get_layout(fmt
);
135 return (struct isl_extent3d
) {
136 .w
= extent_el
.w
* fmtl
->bw
,
137 .h
= extent_el
.h
* fmtl
->bh
,
138 .d
= extent_el
.d
* fmtl
->bd
,