summaryrefslogtreecommitdiff
path: root/include
diff options
context:
space:
mode:
authorEugene Kosov <claprix@yandex.ru>2020-03-20 18:47:35 +0300
committerEugene Kosov <claprix@yandex.ru>2020-03-20 18:47:35 +0300
commitbb24fa31fa28d68ed4e38ecbd8d49773d22c96df (patch)
tree040157e53bf62fe1e8cec9d7219fe8bcfe9f491d /include
parent95da2113a050ad739fdaf60ee871329468a01554 (diff)
downloadmariadb-git-bb24fa31fa28d68ed4e38ecbd8d49773d22c96df.tar.gz
move my_assume_aligned() to a separate header
Diffstat (limited to 'include')
-rw-r--r--include/assume_aligned.h70
-rw-r--r--include/m_string.h47
2 files changed, 70 insertions, 47 deletions
diff --git a/include/assume_aligned.h b/include/assume_aligned.h
new file mode 100644
index 00000000000..89f88c1b728
--- /dev/null
+++ b/include/assume_aligned.h
@@ -0,0 +1,70 @@
+/*
+ Copyright (c) 2000, 2012, Oracle and/or its affiliates.
+ Copyright (c) 2020, 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
+ the Free Software Foundation; version 2 of the License.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program; if not, write to the Free Software
+ Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1335 USA */
+
+#pragma once
+
+#include <cassert>
+#include <cstring>
+
+#ifdef _MSC_VER
+template <std::size_t Alignment, class T>
+static inline T my_assume_aligned(T ptr)
+{
+ assert(reinterpret_cast<size_t>(ptr) % Alignment == 0);
+ __assume(reinterpret_cast<size_t>(ptr) % Alignment == 0);
+ return ptr;
+}
+#else
+template <std::size_t Alignment, class T>
+static inline T my_assume_aligned(T ptr)
+{
+ assert(reinterpret_cast<size_t>(ptr) % Alignment == 0);
+ return static_cast<T>(__builtin_assume_aligned(ptr, Alignment));
+}
+#endif
+
+template <std::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 std::memcpy(my_assume_aligned<Alignment>(dest),
+ my_assume_aligned<Alignment>(src), n);
+}
+template <std::size_t Alignment>
+inline void *memmove_aligned(void *dest, const void *src, size_t n)
+{
+ static_assert(Alignment && !(Alignment & (Alignment - 1)), "power of 2");
+
+ return std::memmove(my_assume_aligned<Alignment>(dest),
+ my_assume_aligned<Alignment>(src), n);
+}
+template <std::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 std::memcmp(my_assume_aligned<Alignment>(s1),
+ my_assume_aligned<Alignment>(s2), n);
+}
+template <std::size_t Alignment>
+inline void *memset_aligned(void *s, int c, size_t n)
+{
+ static_assert(Alignment && !(Alignment & (Alignment - 1)), "power of 2");
+
+ return std::memset(my_assume_aligned<Alignment>(s), c, n);
+}
diff --git a/include/m_string.h b/include/m_string.h
index 9e786908dc6..e4c11d24c0b 100644
--- a/include/m_string.h
+++ b/include/m_string.h
@@ -195,53 +195,6 @@ extern ulonglong strtoull(const char *str, char **ptr, int base);
#if defined(__cplusplus)
}
-
-# ifdef _MSC_VER
-template <size_t Alignment, class T> static inline T my_assume_aligned(T ptr)
-{
- DBUG_ASSERT(reinterpret_cast<size_t>(ptr) % Alignment == 0);
- __assume(reinterpret_cast<size_t>(ptr) % Alignment == 0);
- return ptr;
-}
-# else
-template <size_t Alignment, class T> static inline T my_assume_aligned(T ptr)
-{
- DBUG_ASSERT(reinterpret_cast<size_t>(ptr) % Alignment == 0);
- return static_cast<T>(__builtin_assume_aligned(ptr, Alignment));
-}
-# 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<Alignment>(dest),
- my_assume_aligned<Alignment>(src), n);
-}
-template <size_t Alignment>
-inline void *memmove_aligned(void *dest, const void *src, size_t n)
-{
- static_assert(Alignment && !(Alignment & (Alignment - 1)), "power of 2");
-
- return memmove(my_assume_aligned<Alignment>(dest),
- my_assume_aligned<Alignment>(src), 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<Alignment>(s1),
- my_assume_aligned<Alignment>(s2), 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<Alignment>(s), c, n);
-}
#endif
#include <mysql/plugin.h>