mirror of
https://github.com/MariaDB/server.git
synced 2025-08-07 00:04:31 +03:00
MDEV-21133 Optimize access to InnoDB page header fields
Introduce memcpy_aligned<N>(), memcmp_aligned<N>(), memset_aligned<N>() and use them for accessing InnoDB page header fields that are known to be aligned. MY_ASSUME_ALIGNED(): Wrapper for the GCC/clang __builtin_assume_aligned(). Nothing similar seems to exist in Microsoft Visual Studio, and the C++20 std::assume_aligned is not available to us yet. Explicitly specified alignment guarantees allow compilers to generate faster code on platforms with strict alignment rules, instead of emitting calls to potentially unaligned memcpy(), memcmp(), or memset().
This commit is contained in:
@@ -1,5 +1,6 @@
|
||||
/*
|
||||
Copyright (c) 2000, 2012, Oracle and/or its affiliates.
|
||||
Copyright (c) 2019, MariaDB Corporation.
|
||||
|
||||
This program is free software; you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
@@ -194,6 +195,33 @@ extern ulonglong strtoull(const char *str, char **ptr, int base);
|
||||
|
||||
#if defined(__cplusplus)
|
||||
}
|
||||
|
||||
# ifdef _MSC_VER
|
||||
# define MY_ASSUME_ALIGNED(x,n) x
|
||||
# else
|
||||
# define MY_ASSUME_ALIGNED(x,n) __builtin_assume_aligned(x,n)
|
||||
# endif
|
||||
|
||||
template <size_t Alignment>
|
||||
inline void *memcpy_aligned(void *dest, const void *src, size_t n)
|
||||
{
|
||||
static_assert(Alignment && !(Alignment & (Alignment - 1)), "power of 2");
|
||||
return memcpy(MY_ASSUME_ALIGNED(dest, Alignment),
|
||||
MY_ASSUME_ALIGNED(src, Alignment), n);
|
||||
}
|
||||
template <size_t Alignment>
|
||||
inline int memcmp_aligned(const void *s1, const void *s2, size_t n)
|
||||
{
|
||||
static_assert(Alignment && !(Alignment & (Alignment - 1)), "power of 2");
|
||||
return memcmp(MY_ASSUME_ALIGNED(s1, Alignment),
|
||||
MY_ASSUME_ALIGNED(s2, Alignment), n);
|
||||
}
|
||||
template <size_t Alignment>
|
||||
inline void *memset_aligned(void *s, int c, size_t n)
|
||||
{
|
||||
static_assert(Alignment && !(Alignment & (Alignment - 1)), "power of 2");
|
||||
return memset(MY_ASSUME_ALIGNED(s, Alignment), c, n);
|
||||
}
|
||||
#endif
|
||||
|
||||
#include <mysql/plugin.h>
|
||||
|
Reference in New Issue
Block a user