diff --git a/fsp/fsp0fsp.c b/fsp/fsp0fsp.c index 742673dc9d1..189965fa24b 100644 --- a/fsp/fsp0fsp.c +++ b/fsp/fsp0fsp.c @@ -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); diff --git a/ha/hash0hash.c b/ha/hash0hash.c index a8afa999f7a..0587bb37495 100644 --- a/ha/hash0hash.c +++ b/ha/hash0hash.c @@ -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)); diff --git a/include/hash0hash.ic b/include/hash0hash.ic index 7fa71f29967..37eb5ec2813 100644 --- a/include/hash0hash.ic +++ b/include/hash0hash.ic @@ -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)); } diff --git a/include/ut0ut.h b/include/ut0ut.h index 06c0662b560..0bf2feca853 100644 --- a/include/ut0ut.h +++ b/include/ut0ut.h @@ -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. */ diff --git a/include/ut0ut.ic b/include/ut0ut.ic index 4fb0be0e806..12cd48bb7eb 100644 --- a/include/ut0ut.ic +++ b/include/ut0ut.ic @@ -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. */ diff --git a/os/os0proc.c b/os/os0proc.c index 33f3064e4d9..23d8907ff3d 100644 --- a/os/os0proc.c +++ b/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)) { diff --git a/row/row0merge.c b/row/row0merge.c index 47bb72a124e..0429e25df6e 100644 --- a/row/row0merge.c +++ b/row/row0merge.c @@ -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) {