move my_assume_aligned() to a separate header
This commit is contained in:
parent
95da2113a0
commit
bb24fa31fa
70
include/assume_aligned.h
Normal file
70
include/assume_aligned.h
Normal file
@ -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);
|
||||||
|
}
|
@ -195,53 +195,6 @@ extern ulonglong strtoull(const char *str, char **ptr, int base);
|
|||||||
|
|
||||||
#if defined(__cplusplus)
|
#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
|
#endif
|
||||||
|
|
||||||
#include <mysql/plugin.h>
|
#include <mysql/plugin.h>
|
||||||
|
@ -31,6 +31,7 @@ The database buffer buf_pool
|
|||||||
Created 11/5/1995 Heikki Tuuri
|
Created 11/5/1995 Heikki Tuuri
|
||||||
*******************************************************/
|
*******************************************************/
|
||||||
|
|
||||||
|
#include "assume_aligned.h"
|
||||||
#include "mtr0types.h"
|
#include "mtr0types.h"
|
||||||
#include "mach0data.h"
|
#include "mach0data.h"
|
||||||
#include "buf0buf.h"
|
#include "buf0buf.h"
|
||||||
|
@ -24,6 +24,7 @@ The database buffer pool flush algorithm
|
|||||||
Created 11/5/1995 Heikki Tuuri
|
Created 11/5/1995 Heikki Tuuri
|
||||||
*******************************************************/
|
*******************************************************/
|
||||||
|
|
||||||
|
#include "assume_aligned.h"
|
||||||
#include "buf0buf.h"
|
#include "buf0buf.h"
|
||||||
#include "mtr0mtr.h"
|
#include "mtr0mtr.h"
|
||||||
#include "srv0srv.h"
|
#include "srv0srv.h"
|
||||||
|
@ -27,6 +27,7 @@ Created 12/18/1995 Heikki Tuuri
|
|||||||
#ifndef fsp0fsp_h
|
#ifndef fsp0fsp_h
|
||||||
#define fsp0fsp_h
|
#define fsp0fsp_h
|
||||||
|
|
||||||
|
#include "assume_aligned.h"
|
||||||
#include "fsp0types.h"
|
#include "fsp0types.h"
|
||||||
#include "fut0lst.h"
|
#include "fut0lst.h"
|
||||||
#include "ut0byte.h"
|
#include "ut0byte.h"
|
||||||
|
@ -27,6 +27,7 @@ MDEV-11782: Rewritten for MariaDB 10.2 by Marko Mäkelä, MariaDB Corporation.
|
|||||||
#include <my_global.h>
|
#include <my_global.h>
|
||||||
#include "log0crypt.h"
|
#include "log0crypt.h"
|
||||||
#include <mysql/service_my_crypt.h>
|
#include <mysql/service_my_crypt.h>
|
||||||
|
#include "assume_aligned.h"
|
||||||
|
|
||||||
#include "log0crypt.h"
|
#include "log0crypt.h"
|
||||||
#include "log0recv.h" // for recv_sys
|
#include "log0recv.h" // for recv_sys
|
||||||
|
Loading…
x
Reference in New Issue
Block a user