1 /*******************************************************************************
2 * Copyright 2018 Intel Corporation
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 *******************************************************************************/
17 #ifndef CPU_ISA_TRAITS_HPP
18 #define CPU_ISA_TRAITS_HPP
20 #include <type_traits>
23 #define XBYAK_NO_OP_NAMES
24 /* in order to make selinux happy memory that would be marked with X-bit should
25 * be obtained with mmap */
26 #define XBYAK_USE_MMAP_ALLOCATOR
27 #if defined(_MSC_VER) && !defined(__INTEL_COMPILER)
28 /* turn off `size_t to other-type implicit casting` warning
29 * currently we have a lot of jit-generated instructions that
30 * take uint32_t, but we pass size_t (e.g. due to using sizeof).
31 * FIXME: replace size_t parameters with the appropriate ones */
32 #pragma warning (disable: 4267)
34 #include "xbyak/xbyak.h"
35 #include "xbyak/xbyak_util.h"
55 template <cpu_isa_t> struct cpu_isa_traits {}; /* ::vlen -> 32 (for avx2) */
57 template <> struct cpu_isa_traits<sse42> {
58 typedef Xbyak::Xmm Vmm;
59 static constexpr int vlen_shift = 4;
60 static constexpr int vlen = 16;
61 static constexpr int n_vregs = 16;
63 template <> struct cpu_isa_traits<avx> {
64 typedef Xbyak::Ymm Vmm;
65 static constexpr int vlen_shift = 5;
66 static constexpr int vlen = 32;
67 static constexpr int n_vregs = 16;
69 template <> struct cpu_isa_traits<avx2>:
70 public cpu_isa_traits<avx> {};
72 template <> struct cpu_isa_traits<avx512_common> {
73 typedef Xbyak::Zmm Vmm;
74 static constexpr int vlen_shift = 6;
75 static constexpr int vlen = 64;
76 static constexpr int n_vregs = 32;
78 template <> struct cpu_isa_traits<avx512_core>:
79 public cpu_isa_traits<avx512_common> {};
81 template <> struct cpu_isa_traits<avx512_mic>:
82 public cpu_isa_traits<avx512_common> {};
84 template <> struct cpu_isa_traits<avx512_mic_4ops>:
85 public cpu_isa_traits<avx512_common> {};
87 template <> struct cpu_isa_traits<avx512_core_bf16>:
88 public cpu_isa_traits<avx512_common> {};
92 static Xbyak::util::Cpu cpu;
93 static inline bool mayiuse(const cpu_isa_t cpu_isa) {
94 using namespace Xbyak::util;
98 return cpu.has(Cpu::tSSE42);
100 return cpu.has(Cpu::tAVX);
102 return cpu.has(Cpu::tAVX2);
104 return cpu.has(Cpu::tAVX512F);
107 && cpu.has(Cpu::tAVX512F)
108 && cpu.has(Cpu::tAVX512BW)
109 && cpu.has(Cpu::tAVX512VL)
110 && cpu.has(Cpu::tAVX512DQ);
111 case avx512_core_vnni:
113 && cpu.has(Cpu::tAVX512F)
114 && cpu.has(Cpu::tAVX512BW)
115 && cpu.has(Cpu::tAVX512VL)
116 && cpu.has(Cpu::tAVX512DQ)
117 && cpu.has(Cpu::tAVX512_VNNI);
120 && cpu.has(Cpu::tAVX512F)
121 && cpu.has(Cpu::tAVX512CD)
122 && cpu.has(Cpu::tAVX512ER)
123 && cpu.has(Cpu::tAVX512PF);
124 case avx512_mic_4ops:
126 && mayiuse(avx512_mic)
127 && cpu.has(Cpu::tAVX512_4FMAPS)
128 && cpu.has(Cpu::tAVX512_4VNNIW);
129 case avx512_core_bf16:
131 && mayiuse(avx512_core_vnni)
132 && cpu.has(Cpu::tAVX512_BF);
135 && cpu.has(Cpu::tAVX512_VPOPCNTDQ);
143 /* whatever is required to generate string literals... */
144 #include "z_magic.hpp"
145 #define JIT_IMPL_NAME_HELPER(prefix, isa, suffix_if_any) \
146 (isa == sse42 ? prefix STRINGIFY(sse42) : \
147 (isa == avx ? prefix STRINGIFY(avx) : \
148 (isa == avx2 ? prefix STRINGIFY(avx2) : \
149 (isa == avx512_common ? prefix STRINGIFY(avx512_common) : \
150 (isa == avx512_core ? prefix STRINGIFY(avx512_core) : \
151 (isa == avx512_mic ? prefix STRINGIFY(avx512_mic) : \
152 (isa == avx512_mic_4ops ? prefix STRINGIFY(avx512_mic_4ops) : \
153 (isa == avx512_core_bf16 ? prefix STRINGIFY(avx512_core_bf16) : \
154 prefix suffix_if_any))))))))