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