My Kernel v0.1.0
Mathematical operations

Collection of macros to perform simple and common math operations. More...

Collaboration diagram for Mathematical operations:

Macros

#define MAX(_x, _y)
 Compute the maximum value between 2 numbers.
 
#define MIN(_x, _y)
 Compute the minimum value between 2 numbers.
 
#define ABS(_x)
 Compute the absolute value of a number.
 
#define align_up(_value, _power)    ((((_value)-1) | __align_mask(_value, _power)) + 1)
 Align _value to the next multiple of _power. More...
 
#define align_down(_value, _power)   ((_value) & ~__align_mask(_value, _power))
 Align _value to the previous multiple of _power. More...
 
#define is_aligned(_value, _alignment)   (!((_value) % (_alignment)))
 

Functions

static u32 round_up (u32 value, u32 alignment)
 Round value to the next multiple of alignment. More...
 
static u32 round_down (u32 value, u32 alignment)
 Round value to the previous multiple of alignment. More...
 

Detailed Description

Macro Definition Documentation

◆ align_down

#define align_down (   _value,
  _power 
)    ((_value) & ~__align_mask(_value, _power))
Warning
This macro assumes _power is a power of 2. When using an arbitrary value, you must use round_down instead.

◆ align_up

#define align_up (   _value,
  _power 
)     ((((_value)-1) | __align_mask(_value, _power)) + 1)
Warning
This macro assumes _power is a power of 2. When using an arbitrary value, you must use round_up instead.

◆ is_aligned

#define is_aligned (   _value,
  _alignment 
)    (!((_value) % (_alignment)))
Returns
Whether a value is aligned onto a given boundary

Function Documentation

◆ round_down()

static u32 round_down ( u32  value,
u32  alignment 
)
inlinestatic

When rounding to a power of two, prefere using align_down instead.

◆ round_up()

static u32 round_up ( u32  value,
u32  alignment 
)
inlinestatic

When rounding to a power of two, prefere using align_up instead.

Warning
This function does not check against overflow