aboutsummaryrefslogtreecommitdiff
path: root/vendor/sdl3/include/SDL_begin_code.h
diff options
context:
space:
mode:
Diffstat (limited to 'vendor/sdl3/include/SDL_begin_code.h')
-rw-r--r--vendor/sdl3/include/SDL_begin_code.h75
1 files changed, 71 insertions, 4 deletions
diff --git a/vendor/sdl3/include/SDL_begin_code.h b/vendor/sdl3/include/SDL_begin_code.h
index a6b47cf4b..675cd7f09 100644
--- a/vendor/sdl3/include/SDL_begin_code.h
+++ b/vendor/sdl3/include/SDL_begin_code.h
@@ -261,9 +261,9 @@
*
* On compilers without restrict support, this is defined to nothing.
*
- * \since This macro is available since SDL 3.2.0.
+ * \since This macro is available since SDL 3.4.0.
*/
-#define SDL_RESTRICT __restrict__
+#define SDL_RESTRICT __restrict
/**
* Check if the compiler supports a given builtin functionality.
@@ -281,9 +281,61 @@
*/
#define SDL_HAS_BUILTIN(x) __has_builtin(x)
+/**
+ * A macro to specify data alignment.
+ *
+ * This informs the compiler that a given datatype or variable must be aligned
+ * to a specific byte count.
+ *
+ * For example:
+ *
+ * ```c
+ * // make sure this is struct is aligned to 16 bytes for SIMD access.
+ * typedef struct {
+ * float x, y, z, w;
+ * } SDL_ALIGNED(16) MySIMDAlignedData;
+ *
+ * // make sure this one field in a struct is aligned to 16 bytes for SIMD access.
+ * typedef struct {
+ * SomeStuff stuff;
+ * float SDL_ALIGNED(16) position[4];
+ * SomeOtherStuff other_stuff;
+ * } MyStruct;
+ *
+ * // make sure this variable is aligned to 32 bytes.
+ * int SDL_ALIGNED(32) myval = 0;
+ * ```
+ *
+ * Alignment is only guaranteed for things the compiler places: local
+ * variables on the stack and global/static variables. To dynamically allocate
+ * something that respects this alignment, use SDL_aligned_alloc() or some
+ * other mechanism.
+ *
+ * On compilers without alignment support, this macro is defined to an invalid
+ * symbol, to make it clear that the current compiler is likely to generate
+ * incorrect code when it sees this macro.
+ *
+ * \param x the byte count to align to, so the data's address will be a
+ * multiple of this value.
+ *
+ * \since This macro is available since SDL 3.4.0.
+ */
+#define SDL_ALIGNED(x) __attribute__((aligned(x)))
+
/* end of wiki documentation section. */
#endif
+/* `restrict` is from C99, but __restrict works with both Visual Studio and GCC. */
+#ifndef SDL_RESTRICT
+# if defined(restrict) || ((defined(__STDC_VERSION__) && (__STDC_VERSION__ >= 199901L)))
+# define SDL_RESTRICT restrict
+# elif defined(_MSC_VER) || defined(__GNUC__) || defined(__clang__)
+# define SDL_RESTRICT __restrict
+# else
+# define SDL_RESTRICT
+# endif
+#endif
+
#ifndef SDL_HAS_BUILTIN
#ifdef __has_builtin
#define SDL_HAS_BUILTIN(x) __has_builtin(x)
@@ -379,7 +431,7 @@
#endif /* SDL_INLINE not defined */
#ifndef SDL_FORCE_INLINE
-#ifdef _MSC_VER
+#if defined(_MSC_VER) && (_MSC_VER >= 1200)
#define SDL_FORCE_INLINE __forceinline
#elif ( (defined(__GNUC__) && (__GNUC__ >= 4)) || defined(__clang__) )
#define SDL_FORCE_INLINE __attribute__((always_inline)) static __inline__
@@ -389,7 +441,7 @@
#endif /* SDL_FORCE_INLINE not defined */
#ifndef SDL_NORETURN
-#ifdef __GNUC__
+#if defined(__GNUC__)
#define SDL_NORETURN __attribute__((noreturn))
#elif defined(_MSC_VER)
#define SDL_NORETURN __declspec(noreturn)
@@ -484,3 +536,18 @@
#define SDL_ALLOC_SIZE2(p1, p2)
#endif
#endif /* SDL_ALLOC_SIZE2 not defined */
+
+#ifndef SDL_ALIGNED
+#if defined(__clang__) || defined(__GNUC__)
+#define SDL_ALIGNED(x) __attribute__((aligned(x)))
+#elif defined(_MSC_VER)
+#define SDL_ALIGNED(x) __declspec(align(x))
+#elif defined(__cplusplus) && (__cplusplus >= 201103L)
+#define SDL_ALIGNED(x) alignas(x)
+#elif defined(__STDC_VERSION__) && (__STDC_VERSION__ >= 201112L)
+#define SDL_ALIGNED(x) _Alignas(x)
+#else
+#define SDL_ALIGNED(x) PLEASE_DEFINE_SDL_ALIGNED
+#endif
+#endif /* SDL_ALIGNED not defined */
+