• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 // Copyright 2019 The Fuchsia Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4 
5 #ifndef SRC_GRAPHICS_LIB_COMPUTE_COMMON_UTIL_H_
6 #define SRC_GRAPHICS_LIB_COMPUTE_COMMON_UTIL_H_
7 
8 //
9 //
10 //
11 
12 #include <stdbool.h>
13 #include <stdint.h>
14 
15 //
16 //
17 //
18 
19 #ifdef __cplusplus
20 extern "C" {
21 #endif
22 
23 //
24 //
25 //
26 
27 // Return true iff |n| is a power of 2.
28 bool
29 is_pow2_u32(uint32_t n);
30 
31 // Return |n| rounded-up to the nearest power of 2.
32 // If |n| is zero then return 0.
33 // REQUIRES: |n <= 0x80000000|.
34 uint32_t
35 pow2_ru_u32(uint32_t n);
36 
37 // Return |n| rounded-down to the nearest power of 2.
38 // REQUIRES: |n > 0|.
39 uint32_t
40 pow2_rd_u32(uint32_t n);
41 
42 // Return the most-significant bit position for |n|.
43 // REQUIRES: |n > 0|.
44 uint32_t
45 msb_idx_u32(uint32_t n);  // 0-based bit position
46 
47 //
48 //
49 //
50 
51 #ifdef __cplusplus
52 }
53 #endif
54 
55 //
56 //
57 //
58 
59 #endif  // SRC_GRAPHICS_LIB_COMPUTE_COMMON_UTIL_H_
60