Commit 630a1fc0 authored by marko's avatar marko

branches/zip: Implement ut_calc_align() and ut_calc_align_down() as

type-independent macros.
parent 9be9363c
......@@ -192,28 +192,6 @@ ut_dulint_sort(dulint* arr, dulint* aux_arr, ulint low, ulint high);
/*===============================================================*/
#endif /* notdefined */
/************************************************************
The following function calculates the value of an integer n rounded
to the least product of align_no which is >= n. align_no has to be a
power of 2. */
UNIV_INLINE
ulint
ut_calc_align(
/*==========*/
/* out: rounded value */
ulint n, /* in: number to be rounded */
ulint align_no); /* in: align by this number */
/************************************************************
The following function calculates the value of an integer n rounded
to the biggest product of align_no which is <= n. align_no has to be a
power of 2. */
UNIV_INLINE
ulint
ut_calc_align_down(
/*===============*/
/* out: rounded value */
ulint n, /* in: number to be rounded */
ulint align_no); /* in: align by this number */
/*************************************************************
The following function rounds up a pointer to the nearest aligned address. */
UNIV_INLINE
......
......@@ -296,24 +296,6 @@ ut_uint64_align_up(
return((n + align_1) & ~align_1);
}
/************************************************************
The following function calculates the value of an integer n rounded
to the least product of align_no which is >= n. align_no
has to be a power of 2. */
UNIV_INLINE
ulint
ut_calc_align(
/*==========*/
/* out: rounded value */
ulint n, /* in: number to be rounded */
ulint align_no) /* in: align by this number */
{
ut_ad(align_no > 0);
ut_ad(ut_is_2pow(align_no));
return((n + align_no - 1) & ~(align_no - 1));
}
/*************************************************************
The following function rounds up a pointer to the nearest aligned address. */
UNIV_INLINE
......@@ -333,24 +315,6 @@ ut_align(
return((void*)((((ulint)ptr) + align_no - 1) & ~(align_no - 1)));
}
/************************************************************
The following function calculates the value of an integer n rounded
to the biggest product of align_no which is <= n. align_no has to be a
power of 2. */
UNIV_INLINE
ulint
ut_calc_align_down(
/*===============*/
/* out: rounded value */
ulint n, /* in: number to be rounded */
ulint align_no) /* in: align by this number */
{
ut_ad(align_no > 0);
ut_ad(ut_is_2pow(align_no));
return(n & ~(align_no - 1));
}
/*************************************************************
The following function rounds down a pointer to the nearest
aligned address. */
......
......@@ -103,9 +103,14 @@ Determines if a number is zero or a power of two. */
Calculates fast the remainder of n/m when m is a power of two. */
#define ut_2pow_remainder(n, m) ((n) & ((m) - 1))
/*****************************************************************
Calculates n rounded down to the nearest multiple of m
when m is a power of two. */
Calculates the biggest multiple of m that is not bigger than n
when m is a power of two. In other words, rounds n down to m * k. */
#define ut_2pow_round(n, m) ((n) & ~((m) - 1))
#define ut_calc_align_down(n, m) ut_2pow_round(n, m)
/************************************************************
Calculates the smallest multiple of m that is not smaller than n
when m is a power of two. In other words, rounds n up to m * k. */
#define ut_calc_align(n, m) (((n) + ((m) - 1)) & ~((m) - 1))
/*****************************************************************
Calculates fast the 2-logarithm of a number, rounded upward to an
integer. */
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment