Skip to content

Commit

Permalink
Adds alignemnt and utilities types
Browse files Browse the repository at this point in the history
  • Loading branch information
simondevenish committed Nov 19, 2024
1 parent e156f89 commit bb62d45
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 0 deletions.
17 changes: 17 additions & 0 deletions include/allocx/allocx_alignment.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
#ifndef ALLOCX_ALIGNMENT_H
#define ALLOCX_ALIGNMENT_H

#include "allocx_core_types.h"

// Alignment macros
#define ALIGN_UP(value, alignment) (((value) + ((alignment)-1)) & ~((alignment)-1))
#define ALIGN_DOWN(value, alignment) ((value) & ~((alignment)-1))
#define IS_ALIGNED(value, alignment) (((value) & ((alignment)-1)) == 0)

// Alignment types
typedef u8 align8_t __attribute__((aligned(8)));
typedef u16 align16_t __attribute__((aligned(16)));
typedef u32 align32_t __attribute__((aligned(32)));
typedef u64 align64_t __attribute__((aligned(64)));

#endif // ALLOCX_ALIGNMENT_H
13 changes: 13 additions & 0 deletions include/allocx/allocx_utilities.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
#ifndef ALLOCX_UTILITIES_H
#define ALLOCX_UTILITIES_H

#include "allocx_alignment.h"

// Array size
#define ARRAY_SIZE(arr) (sizeof(arr) / sizeof((arr)[0]))

// Range
#define IN_RANGE(value, min, max) ((value) >= (min) && (value) <= (max))
#define CLAMP(value, min, max) (allocx_min(allocx_max((value), (min)), (max)))

#endif // ALLOCX_UTILITIES_H

0 comments on commit bb62d45

Please sign in to comment.