libspades
Ace of Spades library
datatypes.h
1
4
5#ifndef LIBSPADES_DATATYPES_H
6#define LIBSPADES_DATATYPES_H
7#ifdef __cplusplus
8extern "C" {
9#endif
10
11#include "../config.h"
12
13#include <float.h>
14#include <math.h>
15#include <stddef.h>
16
17#ifndef true
18#define true 1
19#endif
20#ifndef false
21#define false 0
22#endif
23
24#ifndef isnan
25#define isnan(x) (x != x)
26#endif
27#define isnotnan(x) (x == x)
28#ifndef isinf
29#define isinf(x) ((x > FLT_MAX) || (x < -FLT_MAX))
30#endif
31#define isnotinf(x) ((x < FLT_MAX) && (x > -FLT_MAX))
32#ifndef isfinite
33#define isfinite(x) (isnotnan(x) && isnotinf(x))
34#endif
35#define isnotfinite(x) (isnan(x) || isinf(x))
36
37#if defined(__STRICT_ANSI__) || !defined(__STDC_VERSION__) /* Stupid little workaround for fabsf and sqrtf and \
38 floorf not existing in ANSI C89 */
39#define fabsf(x) ((float)fabs((double)(x)))
40#define fmodf(x, y) ((float)fmod((double)(x), (double)(y)))
41#define sqrtf(x) ((float)sqrt((double)(x)))
42#define floorf(x) ((float)floor((double)(x)))
43#define ceilf(x) ((float)ceil((double)(x)))
44#define truncf(x) ((x) > 0 ? floorf(x) : ceilf(x))
45#endif
46
47/* Define the fixed-width integer types. */
48#if (defined(__has_include) && !defined(STDINT_INCLUDED))
49#if (__has_include(<stdint.h>))
50#include <stdint.h>
51#define STDINT_INCLUDED
52#endif
53#endif
54#ifndef STDINT_INCLUDED
55#include <limits.h>
56/* prepare for a big mess */
57#if (CHAR_BIT != 8)
58/* May as well make an attempt to get uint8_t */
59#include <stdint.h>
60#define STDINT_INCLUDED
61#else
62/* uint8_t */
63typedef unsigned char uint8_t;
64
65/* int8_t */
66typedef signed char int8_t;
67
68/* uint16_t */
69#if (USHRT_MAX == 65535)
70typedef unsigned short uint16_t;
71#elif (UINT_MAX == 65535)
72typedef unsigned int uint16_t;
73#endif
74
75/* int16_t */
76#if (SHRT_MAX == 32767)
77typedef signed short int16_t;
78#elif (INT_MAX == 32767)
79typedef signed int int16_t;
80#endif
81
82/* uint32_t */
83#if (USHRT_MAX == 4294967295)
84typedef unsigned short uint32_t;
85#elif (UINT_MAX == 4294967295)
86typedef unsigned int uint32_t;
87#elif (ULONG_MAX == 4294967295)
88typedef unsigned long uint32_t;
89#endif
90
91/* int32_t */
92#if (SHRT_MAX == 2147483647)
93typedef signed short int32_t;
94#elif (INT_MAX == 2147483647)
95typedef signed int int32_t;
96#elif (LONG_MAX == 2147483647)
97typedef signed long int32_t;
98#endif
99
100/* Make a replacement for uint_fastXX_t */
101typedef uint8_t uint_fast8_t;
102typedef uint32_t uint_fast16_t;
103typedef uint32_t uint_fast32_t;
104typedef int8_t int_fast8_t;
105typedef int32_t int_fast16_t;
106typedef int32_t int_fast32_t;
107
108#endif
109#endif
110
111#if (MAX_PLAYERS == 256)
112#include <immintrin.h>
113typedef __m256 bitmask_t;
114#elif (MAX_PLAYERS == 128)
115typedef __uint128_t bitmask_t; /* could also use unsigned __int128_t */
116#elif (MAX_PLAYERS == 64)
117typedef uint_fast64_t bitmask_t;
118#elif (MAX_PLAYERS == 32)
119typedef uint_fast32_t bitmask_t;
120#elif (MAX_PLAYERS == 16)
121typedef uint_fast16_t bitmask_t;
122#elif (MAX_PLAYERS == 8)
123typedef uint_fast8_t bitmask_t;
124#elif !defined(MAX_PLAYERS)
125#define MAX_PLAYERS 32
126typedef uint_fast32_t bitmask_t;
127#else
128#error MAX_PLAYERS must be a power of 2 from 8 to 256!
129#endif
130
131/* NOTE: only 32, 128 and 256 should really be used here to avoid segfaults.
132 * 256 is preferred over 128 when possible.
133 */
134
136typedef float Vector3Float[3];
137
139typedef int8_t Vector3Sint8[3];
141typedef uint8_t Vector3Uint8[3];
143typedef uint8_t Vector4Uint8[4];
144
146typedef int32_t Vector3Sint32[3];
148typedef uint32_t Vector3Uint32[3];
149
151typedef int64_t Vector3Sint64[3];
153typedef uint64_t Vector3Uint64[3];
154
156typedef float Vector2Float[2];
157
158#ifndef __cplusplus
159typedef uint_fast8_t bool;
160#endif
161
162#ifdef __cplusplus
163}
164#endif
165#endif