crashtesting: crash seen on exporting forum-it-5909.ods to xlsx
[LibreOffice.git] / include / tools / simdsupport.hxx
blobfa8923bb095f8d5559ba6d640f8db681ca497258
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3 * This file is part of the LibreOffice project.
5 * This Source Code Form is subject to the terms of the Mozilla Public
6 * License, v. 2.0. If a copy of the MPL was not distributed with this
7 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
9 */
11 // IMPORTANT: Having CPU-specific routines turned out to be a maintenance
12 // problem, because of various problems such as compilers moving CPU-specific
13 // code out of #ifdef code into static initialization or our code using C++
14 // features that caused the compiler to emit code that used CPU-specific
15 // instructions (even cpuid.hxx isn't safe, see the comment there).
16 // The only safe usage is using CPU-specific code that's always available,
17 // such as SSE2-specific code for x86_64. Do not use for anything else
18 // unless you really know what you are doing (and you check git history
19 // to learn from past problems).
21 // Determine the compiler support for SIMD compiler intrinsics.
22 // This changes from one compiled unit to the other, depending if
23 // the support has been detected and if the compiled unit contains
24 // code using intrinsics or not. So we have to (re)set them again
25 // every time this file has been included.
27 // In other words... DO NOT ADD "#pragma once" here
29 #undef LO_SSE2_AVAILABLE
30 #undef LO_SSSE3_AVAILABLE
31 #undef LO_AVX_AVAILABLE
32 #undef LO_AVX2_AVAILABLE
33 #undef LO_AVX512F_AVAILABLE
35 #if defined(_MSC_VER) // VISUAL STUDIO COMPILER
37 // With MSVC using -arch is in fact not necessary for being able
38 // to use CPU intrinsics, code using AVX512F intrinsics will compile
39 // even if compiled with -arch:AVX, the -arch option really only affects
40 // instructions generated for C/C++ code.
41 #if defined(_M_X64) || defined(_M_X86)
42 // As such, if we're building for X86 or X64, support for these is always available
43 // with MSVC2019+.
44 #define LO_SSE2_AVAILABLE
45 #define LO_SSSE3_AVAILABLE
46 #define LO_AVX_AVAILABLE
47 #define LO_AVX2_AVAILABLE
48 #define LO_AVX512F_AVAILABLE
49 #include <intrin.h>
50 #include <immintrin.h>
51 #endif
53 #else // compiler Clang and GCC
55 #if defined(__SSE2__) || defined(__x86_64__) // SSE2 is required for X64
56 #define LO_SSE2_AVAILABLE
57 #include <emmintrin.h>
58 #endif // defined(__SSE2__)
60 #if defined(__SSSE3__)
61 #define LO_SSSE3_AVAILABLE
62 #include <tmmintrin.h>
63 #endif // defined(__SSSE3__)
65 #if defined(__AVX__)
66 #define LO_AVX_AVAILABLE
67 #include <immintrin.h>
68 #endif // defined(__AVX__)
70 #if defined(__AVX2__)
71 #define LO_AVX2_AVAILABLE
72 #include <immintrin.h>
73 #endif // defined(__AVX2__)
75 #if defined(__AVX512F__)
76 #define LO_AVX512F_AVAILABLE
77 #include <immintrin.h>
78 #else
79 #endif // defined(__AVX512F__)
81 #endif // end compiler Clang and GCC
83 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */