forked from TimesGraph/TimesGraph
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdispatcher.h
64 lines (52 loc) · 1.88 KB
/
dispatcher.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
/*******************************************************************************
*
* Copyright (c) 2019-2022 TimesGraph
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
******************************************************************************/
#ifndef TimesGraph_DISPATCHER_H
#define TimesGraph_DISPATCHER_H
#include "vec_dispatch.h"
#ifdef __aarch64__
#define DECLARE_DISPATCHER(FUNCNAME)
#define DECLARE_DISPATCHER_TYPE(FUNCNAME, ...) void FUNCNAME(__VA_ARGS__);
#else // __aarch64__
#include "vcl/vectorclass.h"
#define DECLARE_DISPATCHER(FUNCNAME) TF_##FUNCNAME *FUNCNAME = dispatch_to_ptr(&F_AVX512(FUNCNAME), &F_AVX2(FUNCNAME), &F_SSE41(FUNCNAME), &F_VANILLA(FUNCNAME))
#define DECLARE_DISPATCHER_TYPE(FUNCNAME, ...) \
typedef void TF_##FUNCNAME(__VA_ARGS__); \
TF_##FUNCNAME F_AVX512(FUNCNAME), F_AVX2(FUNCNAME), F_SSE41(FUNCNAME), F_VANILLA(FUNCNAME)
template <typename T>
T *dispatch_to_ptr(T *avx512, T *avx2, T *sse4, T *vanilla)
{
const int iset = instrset_detect();
if (iset == 10)
return avx512;
if (iset >= 8)
return avx2;
if (iset >= 5)
return sse4;
return vanilla;
}
#if INSTRSET == 10
#define MULTI_VERSION_NAME F_AVX512
#elif INSTRSET >= 8
#define MULTI_VERSION_NAME F_AVX2
#elif INSTRSET >= 5
#define MULTI_VERSION_NAME F_SSE41
#else
#define MULTI_VERSION_NAME F_VANILLA
#endif
#endif
#endif //TimesGraph_DISPATCHER_H