GDAL

cpl_cpu_features.h
1/******************************************************************************
2 *
3 * Project: CPL - Common Portability Library
4 * Purpose: Prototypes, and definitions for of CPU features detection
5 * Author: Even Rouault, <even dot rouault at spatialys dot com>
6 *
7 ******************************************************************************
8 * Copyright (c) 2016, Even Rouault <even dot rouault at spatialys dot com>
9 *
10 * Permission is hereby granted, free of charge, to any person obtaining a
11 * copy of this software and associated documentation files (the "Software"),
12 * to deal in the Software without restriction, including without limitation
13 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
14 * and/or sell copies of the Software, and to permit persons to whom the
15 * Software is furnished to do so, subject to the following conditions:
16 *
17 * The above copyright notice and this permission notice shall be included
18 * in all copies or substantial portions of the Software.
19 *
20 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
21 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
22 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
23 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
24 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
25 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
26 * DEALINGS IN THE SOFTWARE.
27 ****************************************************************************/
28
29#ifndef CPL_CPU_FEATURES_H
30#define CPL_CPU_FEATURES_H
31
32#include "cpl_port.h"
33#include "cpl_string.h"
34
36
37#ifdef HAVE_SSE_AT_COMPILE_TIME
38#if (defined(_M_X64) || defined(__x86_64))
39#define HAVE_INLINE_SSE
40
41static bool inline CPLHaveRuntimeSSE()
42{
43 return true;
44}
45#else
46bool CPLHaveRuntimeSSE();
47#endif
48#endif
49
50#ifdef HAVE_SSSE3_AT_COMPILE_TIME
51#if __SSSE3__
52#define HAVE_INLINE_SSSE3
53
54static bool inline CPLHaveRuntimeSSSE3()
55{
56#ifdef DEBUG
57 if (!CPLTestBool(CPLGetConfigOption("GDAL_USE_SSSE3", "YES")))
58 return false;
59#endif
60 return true;
61}
62#else
63#if defined(__GNUC__) && !defined(DEBUG)
64extern bool bCPLHasSSSE3;
65
66static bool inline CPLHaveRuntimeSSSE3()
67{
68 return bCPLHasSSSE3;
69}
70#else
71bool CPLHaveRuntimeSSSE3();
72#endif
73#endif
74#endif
75
76#ifdef HAVE_AVX_AT_COMPILE_TIME
77#if __AVX__
78#define HAVE_INLINE_AVX
79
80static bool inline CPLHaveRuntimeAVX()
81{
82 return true;
83}
84#elif defined(__GNUC__)
85extern bool bCPLHasAVX;
86
87static bool inline CPLHaveRuntimeAVX()
88{
89 return bCPLHasAVX;
90}
91#else
92bool CPLHaveRuntimeAVX();
93#endif
94#endif
95
97
98#endif // CPL_CPU_FEATURES_H
CPLGetConfigOption
const char * CPLGetConfigOption(const char *, const char *)
Get the value of a configuration option.
Definition: cpl_conv.cpp:1696
cpl_port.h
Core portability definitions for CPL.
cpl_string.h
Various convenience functions for working with strings and string lists.
CPLTestBool
bool CPLTestBool(const char *pszValue)
Test what boolean value contained in the string.
Definition: cpl_string.cpp:1557