1 // SPDX-License-Identifier: BSD-2-Clause
2 
3 // This code is part of the sfizz library and is licensed under a BSD 2-clause
4 // license. You should have receive a LICENSE.md file along with the code.
5 // If not, contact the sfizz maintainers at https://github.com/sfztools/sfizz
6 
7 #pragma once
8 
9 /**
10    Define the following macros, 1 if available, otherwise 0.
11    These are allowed to be defined externally, in case automatic detection would
12    fail based on the compiler predefinitions.
13 
14    - SFIZZ_HAVE_SSE
15    - SFIZZ_HAVE_SSE2
16    - SFIZZ_HAVE_NEON
17  */
18 
19 #if defined(__GNUC__)
20 #   if defined(__SSE2__)
21 #       define SFIZZ_DETECT_SSE 1
22 #       define SFIZZ_DETECT_SSE2 1
23 #   elif defined(__SSE__)
24 #       define SFIZZ_DETECT_SSE 1
25 #       define SFIZZ_DETECT_SSE2 0
26 #   else
27 #       define SFIZZ_DETECT_SSE 0
28 #       define SFIZZ_DETECT_SSE2 0
29 #   endif
30 #   if defined(__ARM_NEON__)
31 #       define SFIZZ_DETECT_NEON 1
32 #   else
33 #       define SFIZZ_DETECT_NEON 0
34 #   endif
35 #elif defined(_MSC_VER)
36 #   if defined(_M_AMD64) || defined(_M_X64)
37 #       define SFIZZ_DETECT_SSE 1
38 #       define SFIZZ_DETECT_SSE2 1
39 #   elif _M_IX86_FP == 2
40 #       define SFIZZ_DETECT_SSE 1
41 #       define SFIZZ_DETECT_SSE2 1
42 #   elif _M_IX86_FP == 1
43 #       define SFIZZ_DETECT_SSE 1
44 #       define SFIZZ_DETECT_SSE2 0
45 #   endif
46 // TODO: how to check for NEON on MSVC ARM?
47 #endif
48 
49 #ifndef SFIZZ_HAVE_SSE
50 #   ifdef SFIZZ_DETECT_SSE
51 #       define SFIZZ_HAVE_SSE SFIZZ_DETECT_SSE
52 #   else
53 #       define SFIZZ_HAVE_SSE 0
54 #   endif
55 #endif
56 #ifndef SFIZZ_HAVE_SSE2
57 #   ifdef SFIZZ_DETECT_SSE2
58 #       define SFIZZ_HAVE_SSE2 SFIZZ_DETECT_SSE2
59 #   else
60 #       define SFIZZ_HAVE_SSE2 0
61 #   endif
62 #endif
63 #ifndef SFIZZ_HAVE_NEON
64 #   ifdef SFIZZ_DETECT_NEON
65 #       define SFIZZ_HAVE_NEON SFIZZ_DETECT_NEON
66 #   else
67 #       define SFIZZ_HAVE_NEON 0
68 #   endif
69 #endif
70 
71 /**
72    Detect one of the following the processor families.
73 
74    - SFIZZ_CPU_FAMILY_X86_64
75    - SFIZZ_CPU_FAMILY_I386
76    - SFIZZ_CPU_FAMILY_AARCH64
77    - SFIZZ_CPU_FAMILY_ARM
78  */
79 
80 #if defined(_MSC_VER) && defined(_M_AMD64)
81 #   define SFIZZ_CPU_FAMILY_X86_64 1
82 #elif defined(_MSC_VER) && defined(_M_IX86)
83 #   define SFIZZ_CPU_FAMILY_I386 1
84 #elif defined(_MSC_VER) && defined(_M_ARM64)
85 #   define SFIZZ_CPU_FAMILY_AARCH64 1
86 #elif defined(_MSC_VER) && defined(_M_ARM)
87 #   define SFIZZ_CPU_FAMILY_ARM 1
88 #elif defined(__x86_64__) || defined(__x86_64) || defined(__amd64__) || defined(__amd64)
89 #   define SFIZZ_CPU_FAMILY_X86_64 1
90 #elif defined(__i386__) || defined(__i386)
91 #   define SFIZZ_CPU_FAMILY_I386 1
92 #elif defined(__aarch64__)
93 #   define SFIZZ_CPU_FAMILY_AARCH64 1
94 #elif defined(__arm__) || defined(__arm)
95 #   define SFIZZ_CPU_FAMILY_ARM 1
96 #endif
97