1/* Copyright (C) 2013 Povilas Kanapickas <povilas@radix.lt>
2
3 Distributed under the Boost Software License, Version 1.0.
4 (See accompanying file LICENSE_1_0.txt or copy at
5 http://www.boost.org/LICENSE_1_0.txt)
6*/
7
8#ifndef LIBSIMDPP_SIMDPP_DETAIL_ALIGN_H
9#define LIBSIMDPP_SIMDPP_DETAIL_ALIGN_H
10
11#ifndef LIBSIMDPP_SIMD_H
12 #error "This file must be included through simd.h"
13#endif
14
15#include <simdpp/types.h>
16
17namespace simdpp {
18namespace SIMDPP_ARCH_NAMESPACE {
19namespace detail {
20
21template<class T> SIMDPP_INL
22T* assume_aligned(T* x, unsigned bytes)
23{
24#if (__GNUC__ == 4) && (__GNUC_MINOR__ > 7) && !defined(__clang__)
25 // since GCC(>4.7.0)
26 return reinterpret_cast<T*>(__builtin_assume_aligned(x, bytes));
27#else
28 (void) bytes;
29 return x;
30#endif
31}
32
33template<class T> SIMDPP_INL
34const T* assume_aligned(const T* x, unsigned bytes)
35{
36#if (__GNUC__ == 4) && (__GNUC_MINOR__ > 7) && !defined(__clang__)
37 // since GCC(>4.7.0)
38 return reinterpret_cast<const T*>(__builtin_assume_aligned(x, bytes));
39#else
40 (void) bytes;
41 return x;
42#endif
43}
44
45} // namespace detail
46} // namespace SIMDPP_ARCH_NAMESPACE
47} // namespace simdpp
48
49#endif
50
51