mirror of
https://github.com/MariaDB/server.git
synced 2025-01-31 02:51:44 +01:00
branches/zip: ut_is_2pow(), ut_2pow_round(), ut_2pow_remainder(): Define
as type-independent macros instead of functions. Because ut_2pow_round() and ut_2pow_remainder() no longer assert ut_is_2pow(m), add the assertions to callers when needed. Also add parentheses to assist the compiler in common subexpression elimination.
This commit is contained in:
parent
0f599ce0d3
commit
d4f5d8a892
7 changed files with 23 additions and 68 deletions
|
@ -637,6 +637,8 @@ xdes_calc_descriptor_page(
|
|||
+ (PAGE_ZIP_MIN_SIZE / FSP_EXTENT_SIZE) * XDES_SIZE
|
||||
# error
|
||||
#endif
|
||||
ut_ad(ut_is_2pow(zip_size));
|
||||
|
||||
if (!zip_size) {
|
||||
return(ut_2pow_round(offset, UNIV_PAGE_SIZE));
|
||||
} else {
|
||||
|
@ -657,6 +659,8 @@ xdes_calc_descriptor_index(
|
|||
0 for uncompressed pages */
|
||||
ulint offset) /* in: page offset */
|
||||
{
|
||||
ut_ad(ut_is_2pow(zip_size));
|
||||
|
||||
if (!zip_size) {
|
||||
return(ut_2pow_remainder(offset, UNIV_PAGE_SIZE)
|
||||
/ FSP_EXTENT_SIZE);
|
||||
|
|
|
@ -136,7 +136,8 @@ hash_create_mutexes_func(
|
|||
{
|
||||
ulint i;
|
||||
|
||||
ut_a(n_mutexes > 0 && ut_is_2pow(n_mutexes));
|
||||
ut_a(n_mutexes > 0);
|
||||
ut_a(ut_is_2pow(n_mutexes));
|
||||
|
||||
table->mutexes = mem_alloc(n_mutexes * sizeof(mutex_t));
|
||||
|
||||
|
|
|
@ -70,6 +70,7 @@ hash_get_mutex_no(
|
|||
hash_table_t* table, /* in: hash table */
|
||||
ulint fold) /* in: fold */
|
||||
{
|
||||
ut_ad(ut_is_2pow(table->n_mutexes));
|
||||
return(ut_2pow_remainder(fold, table->n_mutexes));
|
||||
}
|
||||
|
||||
|
|
|
@ -97,30 +97,15 @@ ut_pair_cmp(
|
|||
ulint b1, /* in: more significant part of second pair */
|
||||
ulint b2); /* in: less significant part of second pair */
|
||||
/*****************************************************************
|
||||
Determines if a number is zero or a power of two.
|
||||
This function is used in assertions or assertion-like tests. */
|
||||
UNIV_INLINE
|
||||
ibool
|
||||
ut_is_2pow(
|
||||
/*=======*/ /* out: TRUE if zero or a power of 2 */
|
||||
ulint n); /* in: number to be tested */
|
||||
Determines if a number is zero or a power of two. */
|
||||
#define ut_is_2pow(n) UNIV_LIKELY(!((n) & ((n) - 1)))
|
||||
/*****************************************************************
|
||||
Calculates fast the remainder when divided by a power of two. */
|
||||
UNIV_INLINE
|
||||
ulint
|
||||
ut_2pow_remainder(
|
||||
/*==============*/ /* out: remainder */
|
||||
ulint n, /* in: number to be divided */
|
||||
ulint m); /* in: divisor; power of 2 */
|
||||
Calculates fast the remainder of n/m when m is a power of two. */
|
||||
#define ut_2pow_remainder(n, m) ((n) & ((m) - 1))
|
||||
/*****************************************************************
|
||||
Calculates fast value rounded to a multiple of a power of 2. */
|
||||
UNIV_INLINE
|
||||
ulint
|
||||
ut_2pow_round(
|
||||
/*==========*/ /* out: value of n rounded down to nearest
|
||||
multiple of m */
|
||||
ulint n, /* in: number to be rounded */
|
||||
ulint m); /* in: divisor; power of 2 */
|
||||
Calculates n rounded down to the nearest multiple of m
|
||||
when m is a power of two. */
|
||||
#define ut_2pow_round(n, m) ((n) & ~((m) - 1))
|
||||
/*****************************************************************
|
||||
Calculates fast the 2-logarithm of a number, rounded upward to an
|
||||
integer. */
|
||||
|
|
|
@ -101,47 +101,6 @@ ut_pair_cmp(
|
|||
}
|
||||
}
|
||||
|
||||
/*****************************************************************
|
||||
Determines if a number is zero or a power of two.
|
||||
This function is used in assertions or assertion-like tests. */
|
||||
UNIV_INLINE
|
||||
ibool
|
||||
ut_is_2pow(
|
||||
/*=======*/ /* out: TRUE if zero or a power of 2 */
|
||||
ulint n) /* in: number to be tested */
|
||||
{
|
||||
return(UNIV_LIKELY(!(n & (n - 1))));
|
||||
}
|
||||
|
||||
/*****************************************************************
|
||||
Calculates fast the remainder when divided by a power of two. */
|
||||
UNIV_INLINE
|
||||
ulint
|
||||
ut_2pow_remainder(
|
||||
/*==============*/ /* out: remainder */
|
||||
ulint n, /* in: number to be divided */
|
||||
ulint m) /* in: divisor; power of 2 */
|
||||
{
|
||||
ut_ad(ut_is_2pow(m));
|
||||
|
||||
return(n & (m - 1));
|
||||
}
|
||||
|
||||
/*****************************************************************
|
||||
Calculates fast a value rounded to a multiple of a power of 2. */
|
||||
UNIV_INLINE
|
||||
ulint
|
||||
ut_2pow_round(
|
||||
/*==========*/ /* out: value of n rounded down to nearest
|
||||
multiple of m */
|
||||
ulint n, /* in: number to be rounded */
|
||||
ulint m) /* in: divisor; power of 2 */
|
||||
{
|
||||
ut_ad(ut_is_2pow(m));
|
||||
|
||||
return(n & ~(m - 1));
|
||||
}
|
||||
|
||||
/*****************************************************************
|
||||
Calculates fast the 2-logarithm of a number, rounded upward to an
|
||||
integer. */
|
||||
|
|
10
os/os0proc.c
10
os/os0proc.c
|
@ -86,7 +86,9 @@ os_mem_alloc_large(
|
|||
}
|
||||
|
||||
/* Align block size to os_large_page_size */
|
||||
size = ut_2pow_round(*n + os_large_page_size - 1, os_large_page_size);
|
||||
ut_ad(ut_is_2pow(os_large_page_size));
|
||||
size = ut_2pow_round(*n + (os_large_page_size - 1),
|
||||
os_large_page_size);
|
||||
|
||||
shmid = shmget(IPC_PRIVATE, (size_t)size, SHM_HUGETLB | SHM_R | SHM_W);
|
||||
if (shmid < 0) {
|
||||
|
@ -126,7 +128,8 @@ skip:
|
|||
GetSystemInfo(&system_info);
|
||||
|
||||
/* Align block size to system page size */
|
||||
size = *n = ut_2pow_round(*n + system_info.dwPageSize - 1,
|
||||
ut_ad(ut_is_2pow(system_info.dwPageSize));
|
||||
size = *n = ut_2pow_round(*n + (system_info.dwPageSize - 1),
|
||||
system_info.dwPageSize);
|
||||
ptr = VirtualAlloc(NULL, size, MEM_COMMIT | MEM_RESERVE,
|
||||
PAGE_READWRITE);
|
||||
|
@ -147,7 +150,8 @@ skip:
|
|||
size = UNIV_PAGE_SIZE;
|
||||
# endif
|
||||
/* Align block size to system page size */
|
||||
size = *n = ut_2pow_round(*n + size - 1, size);
|
||||
ut_ad(ut_is_2pow(size));
|
||||
size = *n = ut_2pow_round(*n + (size - 1), size);
|
||||
ptr = mmap(NULL, size, PROT_READ | PROT_WRITE,
|
||||
MAP_PRIVATE | OS_MAP_ANON, -1, 0);
|
||||
if (UNIV_UNLIKELY(ptr == (void*) -1)) {
|
||||
|
|
|
@ -1474,7 +1474,8 @@ row_merge_sort(
|
|||
ulint half;
|
||||
ulint error;
|
||||
|
||||
half = ut_2pow_round((file->offset + blksz - 1) / 2, blksz);
|
||||
ut_ad(ut_is_2pow(blksz));
|
||||
half = ut_2pow_round((file->offset + (blksz - 1)) / 2, blksz);
|
||||
error = row_merge(index, file, half, block, tmpfd, table);
|
||||
|
||||
if (error != DB_SUCCESS) {
|
||||
|
|
Loading…
Add table
Reference in a new issue