Turnstone Operating System
Loading...
Searching...
No Matches
utils.h File Reference

util functions and macros More...

#include <types.h>

Macros

#define ___UTILS_H   0
 
#define ARRAY_SIZE(x)
 
#define MIN(x, y)
 
#define MAX(x, y)
 
#define ABS(x)
 
#define sizeof_field(s, m)
 
#define typeof_field(s, m)
 
#define offsetof_field(s, m)
 
#define itoa_with_buffer(buf, number)
 
#define utoa_with_buffer(buf, number)
 
#define utoh_with_buffer(buf, number)
 
#define ftoa_with_buffer(buf, number)
 
#define ftoh_with_buffer(buf, number)
 
#define ftoa_with_buffer_and_prec(buf, number, prec)
 
#define ftoh_with_buffer_and_prec(buf, number, prec)
 
#define BYTE_SWAP16(n)
 
#define BYTE_SWAP32(n)
 
#define BYTE_SWAP64(n)
 
#define DIGIT_TO_HEX(r)
 
#define ROTLEFT(a, b, c)
 
#define ROTRIGHT(a, b, c)
 
#define ROTLEFT8(a, b)
 
#define ROTRIGHT8(a, b)
 
#define ROTLEFT16(a, b)
 
#define ROTRIGHT16(a, b)
 
#define ROTLEFT32(a, b)
 
#define ROTRIGHT32(a, b)
 
#define ROTLEFT64(a, b)
 
#define ROTRIGHT64(a, b)
 

Functions

number_t power (number_t base, number_t p)
 power base with p
 
int8_t ito_base_with_buffer (char_t *buffer, number_t number, number_t base)
 converts integer to string
 
int8_t uto_base_with_buffer (char_t *buffer, unumber_t number, number_t base)
 converts unsigned integer to string
 
int8_t fto_base_with_buffer (char_t *buffer, float64_t number, number_t prec, number_t base)
 converts float to string
 
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
 
static boolean_t bit_clear32 (volatile uint32_t *data, uint8_t bitloc)
 clears bit value of given data at bitloc
 
static boolean_t bit_set32 (volatile uint32_t *data, uint8_t bitloc)
 sets bit value of given data at bitloc
 
static boolean_t bit_test (uint64_t *data, uint8_t bitloc)
 test bit value of given data at bitloc
 
static boolean_t bit_clear (uint64_t *data, uint8_t bitloc)
 clears bit value of given data at bitloc
 
static boolean_t bit_set (uint64_t *data, uint8_t bitloc)
 sets bit value of given data at bitloc
 
static boolean_t bit_locked_set (volatile uint64_t *data, uint64_t bitloc)
 sets bit value of given data at bitloc with lock prefix
 
static boolean_t bit_change (uint64_t *data, uint8_t bitloc)
 changes bit value of given data at bitloc
 
static uint64_t bit_most_significant (uint64_t num)
 gets most significant bit location
 
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_trandstr (uint32_t len)
 
static boolean_t find_lsb (uint64_t search, uint64_t *location)
 

Detailed Description

util functions and macros

This work is licensed under TURNSTONE OS Public License. Please read and understand latest version of Licence.

Macro Definition Documentation

◆ ___UTILS_H

#define ___UTILS_H   0

prevent duplicate header error macro

◆ ABS

#define ABS ( x)
Value:
((x) >= 0?(x):-1 * (x))

◆ ARRAY_SIZE

#define ARRAY_SIZE ( x)
Value:
(sizeof(x) / sizeof((x)[0]))

◆ BYTE_SWAP16

#define BYTE_SWAP16 ( n)
Value:
byte_swap(n, 2)

◆ BYTE_SWAP32

#define BYTE_SWAP32 ( n)
Value:
byte_swap(n, 4)

◆ BYTE_SWAP64

#define BYTE_SWAP64 ( n)
Value:
byte_swap(n, 8)

◆ DIGIT_TO_HEX

#define DIGIT_TO_HEX ( r)
Value:
(((r) < 10)?(r) + 48:(r) + 55)

◆ ftoa_with_buffer

#define ftoa_with_buffer ( buf,
number )
Value:
fto_base_with_buffer(buf, number, 6, 10)
int8_t fto_base_with_buffer(char_t *buffer, float64_t number, number_t prec, number_t base)
converts float to string
Definition utils.xx.c:124

◆ ftoa_with_buffer_and_prec

#define ftoa_with_buffer_and_prec ( buf,
number,
prec )
Value:
fto_base_with_buffer(buf, number, prec, 10)

◆ ftoh_with_buffer

#define ftoh_with_buffer ( buf,
number )
Value:
fto_base_with_buffer(buf, number, 6, 16)

◆ ftoh_with_buffer_and_prec

#define ftoh_with_buffer_and_prec ( buf,
number,
prec )
Value:
fto_base_with_buffer(buf, number, prec, 16)

◆ itoa_with_buffer

#define itoa_with_buffer ( buf,
number )
Value:
ito_base_with_buffer(buf, number, 10)
int8_t ito_base_with_buffer(char_t *buffer, number_t number, number_t base)
converts integer to string
Definition utils.xx.c:32

◆ MAX

#define MAX ( x,
y )
Value:
((x) > (y) ? (x) : (y))

find max of two numbers

Parameters
[in]xfirst number
[in]yfirst number
Returns
maximum of x or y

◆ MIN

#define MIN ( x,
y )
Value:
((x) < (y) ? (x) : (y))

find min of two numbers

Parameters
[in]xfirst number
[in]yfirst number
Returns
minimum of x or y

◆ offsetof_field

#define offsetof_field ( s,
m )
Value:
( ((uint64_t)&((s*)0)->m) )
unsigned long long uint64_t
Definition types.h:54

◆ ROTLEFT

#define ROTLEFT ( a,
b,
c )
Value:
(((a) << (b)) | ((a) >> (c - (b))))

◆ ROTLEFT16

#define ROTLEFT16 ( a,
b )
Value:
ROTLEFT(a, b, 16)

◆ ROTLEFT32

#define ROTLEFT32 ( a,
b )
Value:
ROTLEFT(a, b, 32)

◆ ROTLEFT64

#define ROTLEFT64 ( a,
b )
Value:
ROTLEFT((uint64_t)a, (uint64_t)b, 64ULL)

◆ ROTLEFT8

#define ROTLEFT8 ( a,
b )
Value:
ROTLEFT(a, b, 8)

◆ ROTRIGHT

#define ROTRIGHT ( a,
b,
c )
Value:
(((a) >> (b)) | ((a) << (c - (b))))

◆ ROTRIGHT16

#define ROTRIGHT16 ( a,
b )
Value:
ROTRIGHT(a, b, 16)

◆ ROTRIGHT32

#define ROTRIGHT32 ( a,
b )
Value:
ROTRIGHT(a, b, 32)

◆ ROTRIGHT64

#define ROTRIGHT64 ( a,
b )
Value:
ROTRIGHT((uint64_t)a, (uint64_t)b, 64ULL)

◆ ROTRIGHT8

#define ROTRIGHT8 ( a,
b )
Value:
ROTRIGHT(a, b, 8)

◆ sizeof_field

#define sizeof_field ( s,
m )
Value:
(sizeof((((s*)0)->m)))

◆ typeof_field

#define typeof_field ( s,
m )
Value:
(typeof(((s*)0)->m))

◆ utoa_with_buffer

#define utoa_with_buffer ( buf,
number )
Value:
uto_base_with_buffer(buf, number, 10)
int8_t uto_base_with_buffer(char_t *buffer, unumber_t number, number_t base)
converts unsigned integer to string
Definition utils.xx.c:84

◆ utoh_with_buffer

#define utoh_with_buffer ( buf,
number )
Value:
uto_base_with_buffer(buf, number, 16)

Function Documentation

◆ bit_change()

static boolean_t bit_change ( uint64_t * data,
uint8_t bitloc )
inlinestatic

changes bit value of given data at bitloc

Parameters
[in]databit array
[in]bitlocbit location at data
Returns
old value

◆ bit_clear()

static boolean_t bit_clear ( uint64_t * data,
uint8_t bitloc )
inlinestatic

clears bit value of given data at bitloc

Parameters
[in]databit array
[in]bitlocbit location at data
Returns
old value

◆ bit_clear32()

static boolean_t bit_clear32 ( volatile uint32_t * data,
uint8_t bitloc )
inlinestatic

clears bit value of given data at bitloc

Parameters
[in]databit array
[in]bitlocbit location at data
Returns
old value

◆ bit_locked_set()

static boolean_t bit_locked_set ( volatile uint64_t * data,
uint64_t bitloc )
inlinestatic

sets bit value of given data at bitloc with lock prefix

Parameters
[in]databit array
[in]bitlocbit location at data
Returns
old value

◆ bit_most_significant()

static uint64_t bit_most_significant ( uint64_t num)
inlinestatic

gets most significant bit location

Parameters
[in]numnumber to get
Returns
bit location

◆ bit_set()

static boolean_t bit_set ( uint64_t * data,
uint8_t bitloc )
inlinestatic

sets bit value of given data at bitloc

Parameters
[in]databit array
[in]bitlocbit location at data
Returns
old value

◆ bit_set32()

static boolean_t bit_set32 ( volatile uint32_t * data,
uint8_t bitloc )
inlinestatic

sets bit value of given data at bitloc

Parameters
[in]databit array
[in]bitlocbit location at data
Returns
old value

◆ bit_test()

static boolean_t bit_test ( uint64_t * data,
uint8_t bitloc )
inlinestatic

test bit value of given data at bitloc

Parameters
[in]databit array
[in]bitlocbit location at data
Returns
bit value

◆ bit_test32()

static boolean_t bit_test32 ( uint32_t * data,
uint8_t bitloc )
inlinestatic

test bit value of given data at bitloc

Parameters
[in]databit array
[in]bitlocbit location at data
Returns
bit value

◆ fto_base_with_buffer()

int8_t fto_base_with_buffer ( char_t * buffer,
float64_t number,
number_t prec,
number_t base )

converts float to string

Parameters
[in]bufferdestination buffer
[in]numberto convert
[in]baseto convert
Returns
0 if successed

buffer should be enough to take data. it's malloc free

◆ ito_base_with_buffer()

int8_t ito_base_with_buffer ( char_t * buffer,
number_t number,
number_t base )

converts integer to string

Parameters
[in]bufferdestination buffer
[in]numberto convert
[in]baseto convert
Returns
0 if successed

buffer should be enough to take data. it's malloc free

◆ power()

number_t power ( number_t base,
number_t p )

power base with p

Parameters
[in]basethe base
[in]pthe power
Returns
base^p with fast power algorithm

◆ uto_base_with_buffer()

int8_t uto_base_with_buffer ( char_t * buffer,
unumber_t number,
number_t base )

converts unsigned integer to string

Parameters
[in]bufferdestination buffer
[in]numberunsigned number to convert
[in]baseto convert
Returns
0 if successed

buffer should be enough to take data. it's malloc free