|
Modules | |
| Assembler Support | |
| Assertions | |
| Atomic Operations | |
| Bit Operations | |
| Byte Order Conversion | |
| Compiler Support | |
| Data in Huge Data Memory Space | |
| Data in Program Space | |
| Standard integer types | |
| String Operations | |
| Unaligned Access Helpers | |
Defines | |
| #define | xstr(s) str(s) |
| Stringify the result after expansion of a macro argument. | |
| #define | str(s) #s |
| Stringify a macro argument without expansion. | |
| #define | ARRAY_LEN(a) (sizeof(a) / sizeof((a)[0])) |
| Get the number of elements in array a. | |
| #define | container_of(ptr, type, member) ((type *)((uintptr_t)(ptr) - offsetof(type, member))) |
| Get the containing object. | |
| #define | round_down(x, order) |
| Round down to the nearest power of two boundary. | |
| #define | round_up(x, order) |
| Round up to the nearest power of two boundary. | |
| #define | div_ceil(a, b) (((a) + (b) - 1) / (b)) |
Calculate using integer arithmetic. | |
Functions | |
| static int | isdigit (int c) |
| Determine whether or not the character c is a digit. | |
| static int | iscntrl (int c) |
| Determine whether or not the character c is a control character. | |
| static int | isspace (int c) |
| Determine whether or not the character c is a space. | |
| int_fast8_t | ilog2_undefined (void) |
| static __always_inline int_fast8_t | ilog2 (uint32_t x) |
| Calculate the base-2 logarithm of a number rounded down to the nearest integer. | |
| static __always_inline bool | is_power_of_two (unsigned long x) |
| Test if a given value is a power of two. | |
| static unsigned long | word_align (unsigned long x) |
| Round up to the nearest word-aligned boundary. | |
Minimum and Maximum | |
|
| |
| #define | min_s(a, b) |
| Get the lowest of two signed values. | |
| #define | min_u(a, b) |
| Get the lowest of two unsigned values. | |
| #define | max_s(a, b) |
| Get the highest of two signed values. | |
| #define | max_u(a, b) |
| Get the highest of two unsigned values. | |
This is a collection of utility functions and macros which may be useful when dealing with certain common problems, e.g. accessing data from a byte stream, simple mathematical operations, etc.
| #define ARRAY_LEN | ( | a | ) | (sizeof(a) / sizeof((a)[0])) |
Get the number of elements in array a.
Definition at line 68 of file util.h.
Referenced by load_desktop(), membag_alloc(), membag_free(), membag_get_largest_free_block_size(), membag_get_smallest_free_block_size(), membag_get_total(), and membag_init().
| #define container_of | ( | ptr, | |||
| type, | |||||
| member | ) | ((type *)((uintptr_t)(ptr) - offsetof(type, member))) |
Get the containing object.
| ptr | Pointer to the contained object. | |
| type | Type of the containing object. | |
| member | Member name of the contained object inside the containing object. |
Definition at line 120 of file util.h.
Referenced by spi_master_polled_of(), spi_poll(), string_stream_of(), and touch_calibrate_task_handler().
| #define div_ceil | ( | a, | |||
| b | ) | (((a) + (b) - 1) / (b)) |
Calculate
using integer arithmetic.
| a | An integer | |
| b | Another integer |
Definition at line 335 of file util.h.
Referenced by bit_array_find_first_one_bit().
| #define max_s | ( | a, | |||
| b | ) |
((sizeof(a) == 1) && (sizeof(b) == 1) ? compiler_max_s8(a, b) \ : (sizeof(a) <= 2) && (sizeof(b) <= 2) ? compiler_max_s16(a, b) \ : (sizeof(a) <= 4) && (sizeof(b) <= 4) ? compiler_max_s32(a, b) \ : compiler_max_s64(a, b))
Get the highest of two signed values.
| a | A signed integer | |
| b | Another signed integer |
Definition at line 156 of file util.h.
Referenced by calc_frame_command_handler(), tank_logistic_map(), wtk_check_box_size_hint(), and wtk_radio_button_size_hint().
| #define max_u | ( | a, | |||
| b | ) |
((sizeof(a) == 1) && (sizeof(b) == 1) ? compiler_max_u8(a, b) \ : (sizeof(a) <= 2) && (sizeof(b) <= 2) ? compiler_max_u16(a, b) \ : (sizeof(a) <= 4) && (sizeof(b) <= 4) ? compiler_max_u32(a, b) \ : compiler_max_u64(a, b))
Get the highest of two unsigned values.
| a | An unsigned integer | |
| b | Another unsigned integer |
| #define min_s | ( | a, | |||
| b | ) |
((sizeof(a) == 1) && (sizeof(b) == 1) ? compiler_min_s8(a, b) \ : (sizeof(a) <= 2) && (sizeof(b) <= 2) ? compiler_min_s16(a, b) \ : (sizeof(a) <= 4) && (sizeof(b) <= 4) ? compiler_min_s32(a, b) \ : compiler_min_s64(a, b))
Get the lowest of two signed values.
| a | A signed integer | |
| b | Another signed integer |
Definition at line 132 of file util.h.
Referenced by calc_frame_command_handler(), and tank_logistic_map().
| #define min_u | ( | a, | |||
| b | ) |
((sizeof(a) == 1) && (sizeof(b) == 1) ? compiler_min_u8(a, b) \ : (sizeof(a) <= 2) && (sizeof(b) <= 2) ? compiler_min_u16(a, b) \ : (sizeof(a) <= 4) && (sizeof(b) <= 4) ? compiler_min_u32(a, b) \ : compiler_min_u64(a, b))
Get the lowest of two unsigned values.
| a | An unsigned integer | |
| b | Another unsigned integer |
Definition at line 144 of file util.h.
Referenced by load_to_hugemem_worker(), load_to_screen_worker(), screen_draw_file_list_from_index(), stream_priv_write(), and tank_worker().
| #define round_down | ( | x, | |||
| order | ) |
(sizeof(x) == 4 ? round_down32((uint32_t)(x), (order)) : \ sizeof(x) == 2 ? round_down16((uint16_t)(x), (order)) : \ sizeof(x) == 1 ? round_down8 (( uint8_t)(x), (order)) : \ (priv_round_down_bad_type(),1))
Round down to the nearest power of two boundary.
| x | A positive integer | |
| order | log2 of the required boundary. |
Definition at line 250 of file util.h.
Referenced by physmem_alloc().
| #define round_up | ( | x, | |||
| order | ) |
(sizeof(x) == 4 ? round_up32((uint32_t)(x), (order)) : \ sizeof(x) == 2 ? round_up16((uint16_t)(x), (order)) : \ sizeof(x) == 1 ? round_up8 (( uint8_t)(x), (order)) : \ (priv_round_up_bad_type(),1))
Round up to the nearest power of two boundary.
| x | A positive integer | |
| order | log2 of the required boundary. |
Definition at line 280 of file util.h.
Referenced by membag_pool_init_physmem(), physmem_alloc_low(), and word_align().
| #define str | ( | s | ) | #s |
Stringify a macro argument without expansion.
Definition at line 63 of file util.h.
Referenced by memgame_print_tries().
| #define xstr | ( | s | ) | str(s) |
| static __always_inline int_fast8_t ilog2 | ( | uint32_t | x | ) | [static] |
Calculate the base-2 logarithm of a number rounded down to the nearest integer.
| x | A 32-bit value |
Definition at line 190 of file util.h.
References compiler_clz, ilog2_undefined(), and is_constant.
Referenced by board_enable_sdram(), and tsfs_read().
| int_fast8_t ilog2_undefined | ( | void | ) |
| static __always_inline bool is_power_of_two | ( | unsigned long | x | ) | [static] |
| static int iscntrl | ( | int | c | ) | [inline, static] |
| static int isdigit | ( | int | c | ) | [inline, static] |
| static int isspace | ( | int | c | ) | [inline, static] |
Determine whether or not the character c is a space.
| c | The character to consider. |
| 0 | The character c is not a space. | |
| 1 | The character c is a space. |
1.6.3