Skip to content

ALIGN_UP

ALIGN_UP

Description

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

Parameters

Name Direction Description
value in The value to be aligned up.
alignment in The 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)

Usage examples (Cross-references)
    
        // 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
    #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.
    /// 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))
Last updated on