mirror of
https://github.com/thepigeongenerator/mcaselector-lite
synced 2026-02-08 07:33:35 +01:00
Move more of the utility headers into /include/mcaselector-lite.
These headers have no associated C files, and are mainly used for utility logic. Having them in `/include` makes them more easily located, and more globally used. We are using "classic" header guards here over `#pragma once` for better support. Since `#pragma once` is defined by the compiler, rather than standard C. Why isn't it used across the project? I have no idea.
This commit is contained in:
69
include/mcaselector-lite/atrb.h
Normal file
69
include/mcaselector-lite/atrb.h
Normal file
@@ -0,0 +1,69 @@
|
||||
/* This file is part of MCA-Selector-lite,
|
||||
* and is licensed under GPL-2.0-only.
|
||||
* Copyright (C)2025 quinnthepigeon@proton.me Quinn
|
||||
* For further information, view COPYING and CONTRIBUTORS
|
||||
* at: www.github.com/thepigeongenerator/mcaselector-lite */
|
||||
#ifndef MCASELECTOR_LITE_ATRB_H
|
||||
#define MCASELECTOR_LITE_ATRB_H
|
||||
|
||||
#if defined(__GNUC__)
|
||||
#if __has_attribute(__pure__)
|
||||
#define PURE __attribute__((__pure__))
|
||||
#else
|
||||
#define PURE
|
||||
#endif
|
||||
|
||||
#if __has_attribute(__const__)
|
||||
#define CONST __attribute__((__const__))
|
||||
#else
|
||||
#define CONST
|
||||
#endif
|
||||
|
||||
#if __has_attribute(__noreturn__)
|
||||
#define NORET __attribute__((__noreturn__))
|
||||
#else
|
||||
#define NORET
|
||||
#endif
|
||||
|
||||
#if __has_attribute(__malloc__)
|
||||
#define MALLOC __attribute__((__malloc__))
|
||||
#else
|
||||
#define MALLOC
|
||||
#endif
|
||||
|
||||
#if __has_attribute(__used__)
|
||||
#define USED __attribute__((__used__))
|
||||
#else
|
||||
#define USED
|
||||
#endif
|
||||
|
||||
#if __has_attribute(__unused__)
|
||||
#define UNUSED __attribute__((__unused__))
|
||||
#else
|
||||
#define UNUSED
|
||||
#endif
|
||||
|
||||
#if __has_attribute(__deprecated__)
|
||||
#define DEPRECATED __attribute__((__deprecated__))
|
||||
#else
|
||||
#define DEPRECATED
|
||||
#endif
|
||||
|
||||
#if __has_attribute(__format__)
|
||||
#define FORMAT(args) __attribute__((format args))
|
||||
#else
|
||||
#define FORMAT(args)
|
||||
#endif
|
||||
|
||||
#if __has_attribute(__nonnull__)
|
||||
#define NONNULL(args) __attribute__((__nonnull__ args))
|
||||
#else
|
||||
#define NONNULL(args)
|
||||
#endif
|
||||
|
||||
#if __has_attribute(__assume__)
|
||||
#define ASSUME(args) __attribute__((__assume__ args))
|
||||
#endif
|
||||
#endif
|
||||
|
||||
#endif /* MCASELECTOR_LITE_ATRB_H */
|
||||
43
include/mcaselector-lite/endian.h
Normal file
43
include/mcaselector-lite/endian.h
Normal file
@@ -0,0 +1,43 @@
|
||||
/* This file is part of MCA-Selector-lite,
|
||||
* and is licensed under GPL-2.0-only.
|
||||
* Copyright (C)2025 quinnthepigeon@proton.me Quinn
|
||||
* For further information, view COPYING and CONTRIBUTORS
|
||||
* at: www.github.com/thepigeongenerator/mcaselector-lite */
|
||||
#ifndef MCASELECTOR_LITE_ENDIAN_H
|
||||
#define MCASELECTOR_LITE_ENDIAN_H
|
||||
|
||||
#if defined(__GNUC__)
|
||||
#if __BYTE_ORDER__ == __ORDER_LITTLE_ENDIAN__
|
||||
#define le16toh(x) __uint16_identity(x)
|
||||
#define le32toh(x) __uint32_identity(x)
|
||||
#define le64toh(x) __uint64_identity(x)
|
||||
#define htole16(x) __uint16_identity(x)
|
||||
#define htole32(x) __uint32_identity(x)
|
||||
#define htole64(x) __uint64_identity(x)
|
||||
#define be16toh(x) __builtin_bswap16(x)
|
||||
#define be32toh(x) __builtin_bswap32(x)
|
||||
#define be64toh(x) __builtin_bswap64(x)
|
||||
#define htobe16(x) __builtin_bswap16(x)
|
||||
#define htobe32(x) __builtin_bswap32(x)
|
||||
#define htobe64(x) __builtin_bswap64(x)
|
||||
#elif __BYTE_ORDER__ == __ORDER_BIG_ENDIAN__
|
||||
#define le16toh(x) __builtin_bswap16(x)
|
||||
#define le32toh(x) __builtin_bswap32(x)
|
||||
#define le64toh(x) __builtin_bswap64(x)
|
||||
#define htole16(x) __builtin_bswap16(x)
|
||||
#define htole32(x) __builtin_bswap32(x)
|
||||
#define htole64(x) __builtin_bswap64(x)
|
||||
#define be16toh(x) __uint16_identity(x)
|
||||
#define be32toh(x) __uint32_identity(x)
|
||||
#define be64toh(x) __uint64_identity(x)
|
||||
#define htobe16(x) __uint16_identity(x)
|
||||
#define htobe32(x) __uint32_identity(x)
|
||||
#define htobe64(x) __uint64_identity(x)
|
||||
#else
|
||||
#error machine architecture unsupported! Expected either big-endian or little-endian, make sure to use a compiler which defines __BYTE_ORDER__ (like clang or gcc)
|
||||
#endif /* byte order */
|
||||
|
||||
#else
|
||||
#error GNU C is unavailable
|
||||
#endif /* __GNUC__ */
|
||||
#endif /* MCASELECTOR_LITE_ENDIAN_H */
|
||||
15
include/mcaselector-lite/macro.h
Normal file
15
include/mcaselector-lite/macro.h
Normal file
@@ -0,0 +1,15 @@
|
||||
/* This file is part of MCA-Selector-lite,
|
||||
* and is licensed under GPL-2.0-only.
|
||||
* Copyright (C)2025 quinnthepigeon@proton.me Quinn
|
||||
* For further information, view COPYING and CONTRIBUTORS
|
||||
* at: www.github.com/thepigeongenerator/mcaselector-lite */
|
||||
#ifndef MCASELECTOR_LITE_MACRO_H
|
||||
#define MCASELECTOR_LITE_MACRO_H
|
||||
|
||||
#define WIDTHOF(t) (sizeof(t) * 8) // gets the bit width of a type
|
||||
#define MACRO_CAT(x, y) x##y // concatenate two macro variables together
|
||||
#define MACRO_CAT2(x, y) MACRO_CAT(x, y) // concatenate two macro variables together
|
||||
#define MACRO_STR(v) #v // for converting macro variable into a string
|
||||
#define MACRO_STR2(v) MACRO_STR(v) // for a recursive string generation
|
||||
|
||||
#endif /* MCASELECTOR_LITE_MACRO_H */
|
||||
40
include/mcaselector-lite/types.h
Normal file
40
include/mcaselector-lite/types.h
Normal file
@@ -0,0 +1,40 @@
|
||||
/* This file is part of MCA-Selector-lite,
|
||||
* and is licensed under GPL-2.0-only.
|
||||
* Copyright (C)2025 quinnthepigeon@proton.me Quinn
|
||||
* For further information, view COPYING and CONTRIBUTORS
|
||||
* at: www.github.com/thepigeongenerator/mcaselector-lite */
|
||||
#ifndef MCASELECTOR_LITE_TYPES_H
|
||||
#define MCASELECTOR_LITE_TYPES_H
|
||||
|
||||
typedef signed long long int llong;
|
||||
typedef unsigned short int ushort;
|
||||
typedef unsigned int uint;
|
||||
typedef unsigned long ulong;
|
||||
typedef unsigned long long ullong;
|
||||
typedef __INT8_TYPE__ s8;
|
||||
typedef __INT16_TYPE__ s16;
|
||||
typedef __INT32_TYPE__ s32;
|
||||
typedef __INT64_TYPE__ s64;
|
||||
typedef __UINT8_TYPE__ u8;
|
||||
typedef __UINT16_TYPE__ u16;
|
||||
typedef __UINT32_TYPE__ u32;
|
||||
typedef __UINT64_TYPE__ u64;
|
||||
typedef __SIZE_TYPE__ usize;
|
||||
typedef __INTPTR_TYPE__ intptr;
|
||||
typedef __UINTPTR_TYPE__ uintptr;
|
||||
|
||||
#if __SIZEOF_SIZE_T__ == __SIZEOF_LONG_LONG__
|
||||
typedef llong ssize;
|
||||
#elif __SIZEOF_SIZE_T__ == __SIZEOF_LONG__
|
||||
typedef long ssize;
|
||||
#elif __SIZEOF_SIZE_T__ == __SIZEOF_INT__
|
||||
typedef int ssize;
|
||||
#endif
|
||||
|
||||
#if __SIZEOF_FLOAT__ == 4
|
||||
typedef float f32;
|
||||
#endif
|
||||
#if __SIZEOF_DOUBLE__ == 8
|
||||
typedef double f64;
|
||||
#endif
|
||||
#endif /* MCASELECTOR_LITE_TYPES_H */
|
||||
14
include/mcaselector-lite/util.h
Normal file
14
include/mcaselector-lite/util.h
Normal file
@@ -0,0 +1,14 @@
|
||||
/* This file is part of MCA-Selector-lite,
|
||||
* and is licensed under GPL-2.0-only.
|
||||
* Copyright (C)2025 quinnthepigeon@proton.me Quinn
|
||||
* For further information, view COPYING and CONTRIBUTORS
|
||||
* at: www.github.com/thepigeongenerator/mcaselector-lite */
|
||||
#ifndef MCASELECTOR_LITE_UTIL_H
|
||||
#define MCASELECTOR_LITE_UTIL_H
|
||||
|
||||
/* Acquires the next power of two of value `x`.
|
||||
* Automatically determines the type (and therefore the width) of `x`.
|
||||
* Explicitly cast `x` to a desired width, if necessary. */
|
||||
#define bit_ceil(x) (1 << (sizeof(__typeof__(x)) * 8 - __builtin_clzg(((x) - !!(x)) | 1)))
|
||||
|
||||
#endif /* MCASELECTOR_LITE_UTIL_H */
|
||||
26
include/mcaselector-lite/vec.h
Normal file
26
include/mcaselector-lite/vec.h
Normal file
@@ -0,0 +1,26 @@
|
||||
/* This file is part of MCA-Selector-lite,
|
||||
* and is licensed under GPL-2.0-only.
|
||||
* Copyright (C)2025 quinnthepigeon@proton.me Quinn
|
||||
* For further information, view COPYING and CONTRIBUTORS
|
||||
* at: www.github.com/thepigeongenerator/mcaselector-lite */
|
||||
#ifndef MCASELECTOR_LITE_VEC_H
|
||||
#define MCASELECTOR_LITE_VEC_H
|
||||
|
||||
#include <mcaselector-lite/types.h>
|
||||
|
||||
#if defined(__has_attribute) && __has_attribute(vector_size)
|
||||
typedef float fvec2 __attribute__((vector_size(sizeof(float) * 2))); // SMID vector for 2 `float`
|
||||
typedef float fvec4 __attribute__((vector_size(sizeof(float) * 4))); // SMID vector for 4 `float`
|
||||
|
||||
typedef u8 u8vec2 __attribute__((vector_size(sizeof(u8) * 2))); // SMID vector for 2 `u8`
|
||||
typedef u8 u8vec4 __attribute__((vector_size(sizeof(u8) * 4))); // SMID vector for 4 `u8`
|
||||
#else
|
||||
#error the platform is unsupported, attribute vector_size must be available (and so does __has_attribute)
|
||||
#endif
|
||||
|
||||
#define VX 0
|
||||
#define VY 1
|
||||
#define VZ 2
|
||||
#define VW 3
|
||||
|
||||
#endif /* MCASELECTOR_LITE_VEC_H */
|
||||
Reference in New Issue
Block a user