make compat/endian.h use different methods for swapping bytes depending on what is available

This commit is contained in:
2025-06-14 22:31:52 +02:00
parent d277a1735b
commit bb1b36127e

View File

@@ -2,11 +2,22 @@
// Licensed under the MIT Licence. See LICENSE for details // Licensed under the MIT Licence. See LICENSE for details
#pragma once #pragma once
#include <byteswap.h>
#include <stdint.h> #include <stdint.h>
#include "../atrb.h" #include "../atrb.h"
#if __has_include(<byteswap.h>)
#include <byteswap.h>
#elif defined(__GNUC__) || defined(__clang__)
#define bswap_16 __builtin_bswap16
#define bswap_32 __builtin_bswap32
#define bswap_64 __builtin_bswap64
#else
// TODO: use custom bswap bacros
#error WIP, no support
#endif
/* little endian */ /* little endian */
atrb_const static inline uint16_t le16ton(uint16_t); // converts little-endian (LE) encoding to native for a 16 bit integer. (NOOP if native is LE) atrb_const static inline uint16_t le16ton(uint16_t); // converts little-endian (LE) encoding to native for a 16 bit integer. (NOOP if native is LE)
atrb_const static inline uint32_t le32ton(uint32_t); // converts little-endian (LE) encoding to native for a 32 bit integer. (NOOP if native is LE) atrb_const static inline uint32_t le32ton(uint32_t); // converts little-endian (LE) encoding to native for a 32 bit integer. (NOOP if native is LE)