libaaruformat 1.0
Aaru Data Preservation Suite - Format Library
Loading...
Searching...
No Matches
simd.h
Go to the documentation of this file.
1/*
2 * This file is part of the Aaru Data Preservation Suite.
3 * Copyright (c) 2019-2025 Natalia Portillo.
4 *
5 * This library 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 2.1 of the
8 * License, or (at your option) any later version.
9 *
10 * This library 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 GNU
13 * 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 this library; if not, see <http://www.gnu.org/licenses/>.
17 */
18
19#ifndef LIBAARUFORMAT_SIMD_H
20#define LIBAARUFORMAT_SIMD_H
21
22#ifdef _MSC_VER
23#define ALIGNED_(n) __declspec(align(n))
24#else
25#define ALIGNED_(n) __attribute__((aligned(n)))
26#endif
27
28#if defined(__x86_64__) || defined(__amd64) || defined(_M_AMD64) || defined(_M_X64) || defined(__I386__) || \
29 defined(__i386__) || defined(__THW_INTEL) || defined(_M_IX86)
30
31#ifdef _MSC_VER
32#define AVX2
33#define SSSE3
34#define CLMUL
35#else
36#define AVX2 __attribute__((target("avx2")))
37#define SSSE3 __attribute__((target("ssse3")))
38#define CLMUL __attribute__((target("pclmul,sse4.1")))
39#endif
40#endif
41
42#if(defined(__arm__) || defined(_M_ARM)) && !defined(_WIN32)
43#define HWCAP_NEON (1 << 12)
44#define HWCAP2_AES (1 << 0)
45#define HWCAP2_CRC32 (1 << 4)
46#endif
47
48#if(defined(__aarch64__) || defined(_M_ARM64)) && !defined(_WIN32)
49#define HWCAP_NEON (1 << 1)
50#define HWCAP_AES (1 << 3)
51#define HWCAP_CRC32 (1 << 7)
52#endif
53
54#if defined(__aarch64__) || defined(_M_ARM64) || defined(__arm__) || defined(_M_ARM)
55
56#ifndef __ARM_FEATURE_CRC32
57#define __ARM_FEATURE_CRC32 1
58#endif
59
60#ifdef _MSC_VER
61
62#define TARGET_ARMV8_WITH_CRC
63#define TARGET_WITH_CRYPTO
64#define TARGET_WITH_SIMD
65
66#else // _MSC_VER
67
68#if defined(__aarch64__) || defined(_M_ARM64)
69
70#ifdef __clang__
71#define TARGET_ARMV8_WITH_CRC __attribute__((target("crc")))
72#else
73#define TARGET_ARMV8_WITH_CRC __attribute__((target("+crc")))
74#endif
75
76#ifdef __clang__
77#define TARGET_WITH_CRYPTO __attribute__((target("crypto")))
78#else
79#define TARGET_WITH_CRYPTO __attribute__((target("+crypto")))
80#endif
81
82#define TARGET_WITH_SIMD
83#else
84
85#if __ARM_ARCH >= 8
86
87#ifdef __clang__
88#define TARGET_ARMV8_WITH_CRC __attribute__((target("armv8-a,crc")))
89#else
90#define TARGET_ARMV8_WITH_CRC __attribute__((target("arch=armv8-a+crc")))
91#endif
92
93#endif // __ARM_ARCH >= 8
94
95#ifdef __clang__
96#define TARGET_WITH_CRYPTO __attribute__((target("armv8-a,crypto")))
97#else
98#define TARGET_WITH_CRYPTO __attribute__((target("fpu=crypto-neon-fp-armv8")))
99#endif
100
101#ifdef __clang__
102#define TARGET_WITH_SIMD __attribute__((target("neon")))
103#else
104#define TARGET_WITH_SIMD __attribute__((target("fpu=neon")))
105#endif
106
107#endif // __aarch64__ || _M_ARM64
108
109#endif // _MSC_VER
110
111#endif // __aarch64__ || _M_ARM64 || __arm__ || _M_ARM
112
113#endif // LIBAARUFORMAT_SIMD_H