Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
PojavLauncherTeam
GitHub Repository: PojavLauncherTeam/mesa
Path: blob/21.2-virgl/src/util/compiler.h
4545 views
1
/*
2
* Mesa 3-D graphics library
3
*
4
* Copyright (C) 1999-2008 Brian Paul All Rights Reserved.
5
* Copyright (C) 2009 VMware, Inc. All Rights Reserved.
6
*
7
* Permission is hereby granted, free of charge, to any person obtaining a
8
* copy of this software and associated documentation files (the "Software"),
9
* to deal in the Software without restriction, including without limitation
10
* the rights to use, copy, modify, merge, publish, distribute, sublicense,
11
* and/or sell copies of the Software, and to permit persons to whom the
12
* Software is furnished to do so, subject to the following conditions:
13
*
14
* The above copyright notice and this permission notice shall be included
15
* in all copies or substantial portions of the Software.
16
*
17
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
18
* OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
19
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
20
* THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR
21
* OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
22
* ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
23
* OTHER DEALINGS IN THE SOFTWARE.
24
*/
25
26
27
/**
28
* \file compiler.h
29
* Compiler-related stuff.
30
*/
31
32
33
#ifndef COMPILER_H
34
#define COMPILER_H
35
36
37
#include <assert.h>
38
39
#include "util/macros.h"
40
41
#include "c99_compat.h" /* inline, __func__, etc. */
42
43
44
/**
45
* Either define MESA_BIG_ENDIAN or MESA_LITTLE_ENDIAN, and CPU_TO_LE32.
46
* Do not use these unless absolutely necessary!
47
* Try to use a runtime test instead.
48
* For now, only used by some DRI hardware drivers for color/texel packing.
49
*/
50
#if defined(BYTE_ORDER) && defined(BIG_ENDIAN) && BYTE_ORDER == BIG_ENDIAN
51
#if defined(__linux__)
52
#include <byteswap.h>
53
#define CPU_TO_LE32( x ) bswap_32( x )
54
#elif defined(__APPLE__)
55
#include <CoreFoundation/CFByteOrder.h>
56
#define CPU_TO_LE32( x ) CFSwapInt32HostToLittle( x )
57
#elif defined(__OpenBSD__)
58
#include <sys/types.h>
59
#define CPU_TO_LE32( x ) htole32( x )
60
#else /*__linux__ */
61
#include <sys/endian.h>
62
#define CPU_TO_LE32( x ) bswap32( x )
63
#endif /*__linux__*/
64
#define MESA_BIG_ENDIAN 1
65
#else
66
#define CPU_TO_LE32( x ) ( x )
67
#define MESA_LITTLE_ENDIAN 1
68
#endif
69
#define LE32_TO_CPU( x ) CPU_TO_LE32( x )
70
71
72
73
#define IEEE_ONE 0x3f800000
74
75
#ifndef __has_attribute
76
# define __has_attribute(x) 0
77
#endif
78
79
#if __cplusplus >= 201703L || __STDC_VERSION__ > 201710L
80
/* Standard C++17/C23 attribute */
81
#define FALLTHROUGH [[fallthrough]]
82
#elif __has_attribute(fallthrough)
83
/* Non-standard but supported by at least gcc and clang */
84
#define FALLTHROUGH __attribute__((fallthrough))
85
#else
86
#define FALLTHROUGH do { } while(0)
87
#endif
88
89
#endif /* COMPILER_H */
90
91