Skip to content

Commit eb5f5f3

Browse files
committed
[RP009] crc32_update_uint64() can be inlined
crc32_update_uint64() is defined with '__attribute__((target("...")))'. But, if the caller and the inline function have different target attributes, the inline function is never inlined. Better to avoid not to block the inlining, as possible as we can. This change uses InnoDB compile option "-mcrc32" or "-mcrc" and not use the '__attribute__((target("...")))' for the crc32_update_uint64(), if compiler and its version allow.
1 parent 9d88f21 commit eb5f5f3

File tree

4 files changed

+35
-4
lines changed

4 files changed

+35
-4
lines changed

MYSQL_VERSION

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,4 +3,4 @@ MYSQL_VERSION_MINOR=0
33
MYSQL_VERSION_PATCH=42
44
MYSQL_VERSION_EXTRA=
55
MYSQL_VERSION_STABILITY="LTS"
6-
MYSQL_RP_REVISION="-RP008"
6+
MYSQL_RP_REVISION="-RP009"

storage/innobase/include/ut0crc32.h

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
/*****************************************************************************
22
33
Copyright (c) 2011, 2025, Oracle and/or its affiliates.
4+
Copyright (c) 2025, buildup-db.
45
56
This program is free software; you can redistribute it and/or modify it under
67
the terms of the GNU General Public License, version 2.0, as published by the
@@ -184,14 +185,20 @@ extern bool ut_poly_mul_cpu_enabled;
184185
@param[in] crc base CRC32 value
185186
@param[in] data 8 bytes data to be processed
186187
@return updated CRC32 value */
187-
#ifdef CRC32_x86_64
188+
#ifdef CRC32_NOT_NEED_TARGET_ATTR
189+
MY_ATTRIBUTE((always_inline))
190+
#elif defined(CRC32_x86_64)
188191
MY_ATTRIBUTE((target("sse4.2")))
189192
#elif defined(CRC32_ARM64_DEFAULT)
190193
MY_ATTRIBUTE((target("+crc")))
191-
#endif /* CRC32_x86_64 */
194+
#endif /* CRC32_NOT_NEED_TARGET_ATTR */
192195
static inline uint64_t crc32_update_uint64(uint64_t crc, uint64_t data) {
193196
#ifdef CRC32_x86_64
197+
#ifdef CRC32_NOT_NEED_TARGET_ATTR
198+
return __builtin_ia32_crc32di(crc, data);
199+
#else
194200
return _mm_crc32_u64(crc, data);
201+
#endif /* CRC32_NOT_NEED_TARGET_ATTR */
195202
#elif defined(CRC32_ARM64)
196203
return (uint64_t)__crc32cd((uint32_t)crc, data);
197204
#endif /* CRC32_x86_64 */
@@ -200,6 +207,9 @@ static inline uint64_t crc32_update_uint64(uint64_t crc, uint64_t data) {
200207
/** Hashes a 64-bit integer with CRC32 instructions of the architecture.
201208
@param[in] value 64-bit integer
202209
@return hashed value */
210+
#ifdef CRC32_NOT_NEED_TARGET_ATTR
211+
MY_ATTRIBUTE((always_inline))
212+
#endif
203213
static inline uint64_t crc32_hash_uint64(uint64_t value) {
204214
ut_ad(ut_crc32_cpu_enabled);
205215
value *= 0xb5eb6fbadd39bf9b;

storage/innobase/include/ut0rnd.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -198,7 +198,7 @@ static inline uint64_t random_from_interval_fast(uint64_t low, uint64_t high) {
198198

199199
static inline uint64_t hash_uint64(uint64_t value) {
200200
#ifndef CRC32_DEFAULT
201-
if (ut_crc32_cpu_enabled) {
201+
if (UNIV_LIKELY(ut_crc32_cpu_enabled)) {
202202
return crc32_hash_uint64(value);
203203
}
204204
#endif /* !CRC32_DEFAULT */

storage/innobase/innodb.cmake

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
# Copyright (c) 2006, 2025, Oracle and/or its affiliates.
2+
# Copyright (c) 2025, buildup-db.
23
#
34
# This program is free software; you can redistribute it and/or modify
45
# it under the terms of the GNU General Public License, version 2.0,
@@ -258,6 +259,26 @@ ELSE()
258259
ADD_DEFINITIONS(-DMUTEX_SYS)
259260
ENDIF()
260261

262+
# __attribute__((target("..."))) blocks inlining. better to avoid.
263+
IF(MY_COMPILER_IS_GNU_OR_CLANG)
264+
IF(CMAKE_SYSTEM_PROCESSOR MATCHES "^(AMD64|x86_64)$")
265+
IF(CMAKE_CXX_COMPILER_ID MATCHES "GNU"
266+
OR (CMAKE_CXX_COMPILER_ID MATCHES "Clang"
267+
AND CMAKE_CXX_COMPILER_VERSION VERSION_GREATER_EQUAL 14))
268+
# Can treat __builtin_ia32_crc32di() contanins function inlined
269+
ADD_COMPILE_OPTIONS("-mcrc32")
270+
ADD_DEFINITIONS(-DCRC32_NOT_NEED_TARGET_ATTR)
271+
ENDIF()
272+
ELSEIF(NOT APPLE AND CMAKE_SYSTEM_PROCESSOR MATCHES "^(arm64|aarch64)$")
273+
IF(CMAKE_CXX_COMPILER_ID MATCHES "Clang"
274+
AND CMAKE_CXX_COMPILER_VERSION VERSION_GREATER_EQUAL 16)
275+
# Can treat __crc32cd() contanins function inlined
276+
ADD_COMPILE_OPTIONS("-mcrc")
277+
ADD_DEFINITIONS(-DCRC32_NOT_NEED_TARGET_ATTR)
278+
ENDIF()
279+
ENDIF()
280+
ENDIF()
281+
261282
# Include directories under innobase
262283
INCLUDE_DIRECTORIES(${CMAKE_SOURCE_DIR}/storage/innobase/
263284
${CMAKE_SOURCE_DIR}/storage/innobase/include

0 commit comments

Comments
 (0)