]> git.uio.no Git - u/mrichter/AliRoot.git/blame - Vc/include/Vc/sse/helperimpl.tcc
Vc package added (version 0.6.79-dev)
[u/mrichter/AliRoot.git] / Vc / include / Vc / sse / helperimpl.tcc
CommitLineData
f22341db 1/* This file is part of the Vc library.
2
3 Copyright (C) 2010-2012 Matthias Kretz <kretz@kde.org>
4
5 Vc is free software: you can redistribute it and/or modify
6 it under the terms of the GNU Lesser General Public License as
7 published by the Free Software Foundation, either version 3 of
8 the License, or (at your option) any later version.
9
10 Vc is distributed in the hope that it will be useful, but
11 WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 GNU Lesser General Public License for more details.
14
15 You should have received a copy of the GNU Lesser General Public
16 License along with Vc. If not, see <http://www.gnu.org/licenses/>.
17
18*/
19
20#ifndef VC_SSE_HELPERIMPL_TCC
21#define VC_SSE_HELPERIMPL_TCC
22
23#include "intrinsics.h"
24#include <cstdio>
25
26namespace Vc
27{
28namespace Internal
29{
30
31template<size_t X>
32static inline size_t nextMultipleOf(size_t value)
33{
34 const size_t offset = value % X;
35 if ( offset > 0 ) {
36 return value + X - offset;
37 }
38 return value;
39}
40
41template<Vc::MallocAlignment A>
42inline void *HelperImpl<SSE2Impl>::malloc(size_t n)
43{
44 switch (A) {
45 case Vc::AlignOnVector:
46 return _mm_malloc(nextMultipleOf<Vc::SSE::VectorAlignment>(n), Vc::SSE::VectorAlignment);
47 case Vc::AlignOnCacheline:
48 // TODO: hardcoding 64 is not such a great idea
49 return _mm_malloc(nextMultipleOf<64>(n), 64);
50 case Vc::AlignOnPage:
51 // TODO: hardcoding 4096 is not such a great idea
52 return _mm_malloc(nextMultipleOf<4096>(n), 4096);
53 default:
54#ifndef NDEBUG
55 abort();
56#endif
57 return _mm_malloc(n, 8);
58 }
59}
60
61inline void HelperImpl<SSE2Impl>::free(void *p)
62{
63 _mm_free(p);
64}
65
66} // namespace Internal
67} // namespace Vc
68
69#endif // VC_SSE_HELPERIMPL_TCC