Turnstone Operating System
|
util functions and macros More...
#include <types.h>
Macros | |
#define | ___UTILS_H 0 |
#define | ARRAY_SIZE(x) (sizeof(x) / sizeof((x)[0])) |
#define | MIN(x, y) (x < y ? x : y) |
#define | MAX(x, y) (x > y ? x : y) |
#define | ABS(x) (x >= 0?x:-1 * x) |
#define | sizeof_field(s, m) (sizeof((((s*)0)->m))) |
#define | typeof_field(s, m) (typeof(((s*)0)->m)) |
#define | offsetof_field(s, m) ( ((uint64_t)&((s*)0)->m) ) |
#define | itoa_with_buffer(buf, number) ito_base_with_buffer(buf, number, 10) |
#define | utoa_with_buffer(buf, number) uto_base_with_buffer(buf, number, 10) |
#define | utoh_with_buffer(buf, number) uto_base_with_buffer(buf, number, 16) |
#define | ftoa_with_buffer(buf, number) fto_base_with_buffer(buf, number, 6, 10) |
#define | ftoh_with_buffer(buf, number) fto_base_with_buffer(buf, number, 6, 16) |
#define | ftoa_with_buffer_and_prec(buf, number, prec) fto_base_with_buffer(buf, number, prec, 10) |
#define | ftoh_with_buffer_and_prec(buf, number, prec) fto_base_with_buffer(buf, number, prec, 16) |
#define | BYTE_SWAP16(n) byte_swap(n, 2) |
#define | BYTE_SWAP32(n) byte_swap(n, 4) |
#define | BYTE_SWAP64(n) byte_swap(n, 8) |
#define | DIGIT_TO_HEX(r) (((r) < 10)?(r) + 48:(r) + 55) |
#define | ROTLEFT(a, b, c) (((a) << (b)) | ((a) >> (c - (b)))) |
#define | ROTRIGHT(a, b, c) (((a) >> (b)) | ((a) << (c - (b)))) |
#define | ROTLEFT8(a, b) ROTLEFT(a, b, 8) |
#define | ROTRIGHT8(a, b) ROTRIGHT(a, b, 8) |
#define | ROTLEFT16(a, b) ROTLEFT(a, b, 16) |
#define | ROTRIGHT16(a, b) ROTRIGHT(a, b, 16) |
#define | ROTLEFT32(a, b) ROTLEFT(a, b, 32) |
#define | ROTRIGHT32(a, b) ROTRIGHT(a, b, 32) |
#define | ROTLEFT64(a, b) ROTLEFT((uint64_t)a, (uint64_t)b, 64ULL) |
#define | ROTRIGHT64(a, b) ROTRIGHT((uint64_t)a, (uint64_t)b, 64ULL) |
Functions | |
number_t | power (number_t base, number_t p) |
power base with p More... | |
int8_t | ito_base_with_buffer (char_t *buffer, number_t number, number_t base) |
converts integer to string More... | |
int8_t | uto_base_with_buffer (char_t *buffer, unumber_t number, number_t base) |
converts unsigned integer to string More... | |
int8_t | fto_base_with_buffer (char_t *buffer, float64_t number, number_t prec, number_t base) |
converts float to string More... | |
static uint64_t | byte_swap (uint64_t num, uint8_t bc) |
uint8_t | byte_count (const uint64_t num) |
static boolean_t | bit_test32 (uint32_t *data, uint8_t bitloc) |
test bit value of given data at bitloc More... | |
static boolean_t | bit_clear32 (volatile uint32_t *data, uint8_t bitloc) |
clears bit value of given data at bitloc More... | |
static boolean_t | bit_set32 (volatile uint32_t *data, uint8_t bitloc) |
sets bit value of given data at bitloc More... | |
static boolean_t | bit_test (uint64_t *data, uint8_t bitloc) |
test bit value of given data at bitloc More... | |
static boolean_t | bit_clear (uint64_t *data, uint8_t bitloc) |
clears bit value of given data at bitloc More... | |
static boolean_t | bit_set (uint64_t *data, uint8_t bitloc) |
sets bit value of given data at bitloc More... | |
static boolean_t | bit_change (uint64_t *data, uint8_t bitloc) |
changes bit value of given data at bitloc More... | |
static uint64_t | bit_most_significant (uint64_t num) |
gets most significant bit location More... | |
uint64_t | read_memio (uint64_t va, uint8_t size) |
void | write_memio (uint64_t va, uint64_t val, uint8_t size) |
static uint64_t | reverse_bits (uint64_t bits, uint8_t bit_count) |
boolean_t | isalpha (char_t c) |
boolean_t | isdigit (char_t c) |
boolean_t | isalnum (char_t c) |
boolean_t | isxdigit (char_t c) |
boolean_t | islower (char_t c) |
boolean_t | isupper (char_t c) |
boolean_t | isspace (char_t c) |
boolean_t | ispunct (char_t c) |
boolean_t | isprint (char_t c) |
boolean_t | isgraph (char_t c) |
boolean_t | iscntrl (char_t c) |
boolean_t | isblank (char_t c) |
boolean_t | isascii (char_t c) |
boolean_t | isalnumw (char_t c) |
const char_t * | randstr (uint32_t len) |
util functions and macros
This work is licensed under TURNSTONE OS Public License. Please read and understand latest version of Licence.
#define ___UTILS_H 0 |
prevent duplicate header error macro
#define MAX | ( | x, | |
y | |||
) | (x > y ? x : y) |
find max of two numbers
[in] | x | first number |
[in] | y | first number |
#define MIN | ( | x, | |
y | |||
) | (x < y ? x : y) |
find min of two numbers
[in] | x | first number |
[in] | y | first number |
changes bit value of given data at bitloc
[in] | data | bit array |
[in] | bitloc | bit location at data |
clears bit value of given data at bitloc
[in] | data | bit array |
[in] | bitloc | bit location at data |
clears bit value of given data at bitloc
[in] | data | bit array |
[in] | bitloc | bit location at data |
gets most significant bit location
[in] | num | number to get |
sets bit value of given data at bitloc
[in] | data | bit array |
[in] | bitloc | bit location at data |
sets bit value of given data at bitloc
[in] | data | bit array |
[in] | bitloc | bit location at data |
test bit value of given data at bitloc
[in] | data | bit array |
[in] | bitloc | bit location at data |
test bit value of given data at bitloc
[in] | data | bit array |
[in] | bitloc | bit location at data |
converts float to string
[in] | buffer | destination buffer |
[in] | number | to convert |
[in] | base | to convert |
buffer should be enough to take data. it's malloc free
converts integer to string
[in] | buffer | destination buffer |
[in] | number | to convert |
[in] | base | to convert |
buffer should be enough to take data. it's malloc free
power base with p
[in] | base | the base |
[in] | p | the power |