ALIGN_UP

Table of Contents

ALIGN_UP

Description

Aligns the given value up to the nearest multiple of alignment.

Parameters

NameDirectionDescription
valueinThe value to be aligned up.
alignmentinThe alignment boundary.

Success

Returns aligned-up value when alignment > 1, original value otherwise.

Failure

Function cannot fail - always returns a valid value.

Usage example (Cross-references)

    /// TAGS: Memory, Size, Iter
    ///
    #define IterSize(mi) IterLength(mi) * ALIGN_UP(sizeof(ITER_DATA_TYPE(mi)), (mi)->alignment)
    
    ///
    /// TAGS: Memory, Iter, Size
    ///
    #define IterRemainingSize(mi) IterRemainingLength(mi) * ALIGN_UP(sizeof(ITER_DATA_TYPE(mi)), (mi)->alignment)
    
    ///
    (IterRemainingLength(mi) ?                                                                                         \
    (ITER_DATA_TYPE(mi) *)(((u64)(mi)->data) +                                                                    \
    (mi)->pos * ALIGN_UP(sizeof(ITER_DATA_TYPE(mi)), (mi)->alignment)) :                   \
    NULL_ITER_DATA(mi))
    #define VecInitAlignedWithDeepCopyStack(v, ne, ci, cd, aln, scoped_body)                                               \
    do {                                                                                                               \
    char ___data___[ALIGN_UP(sizeof(VEC_DATATYPE(&(v))), (aln)) * ((ne) + 1)] = {0};                               \
    \
    (v)          = VecInitAlignedWithDeepCopyT((v), (ci), (cd), (aln));                                            \
    /// FAILURE : Does not return on failure
    ///
    #define VecAlignedOffsetAt(v, idx) ((idx) * ALIGN_UP(sizeof(VEC_DATATYPE(v)), (v)->alignment))
    ///
    /// Value at given index in a vector.
    
    // For 8-byte alignment, each int (4 bytes) should be padded to 8 bytes
    size aligned_size = ALIGN_UP(sizeof(int), 8);
    
    // Check offsets with alignment

Share :

Related Posts

MIN2

MIN2 Description Returns the smaller of two values x and y.

Read More

CLAMP

CLAMP Description Clamps the value of x to be within the inclusive range [lo, hi].

Read More

MAX2

MAX2 Description Returns the larger of two values x and y.

Read More