diff options
Diffstat (limited to 'src/zstd/contrib/linux-kernel/test/include')
8 files changed, 235 insertions, 0 deletions
diff --git a/src/zstd/contrib/linux-kernel/test/include/asm/unaligned.h b/src/zstd/contrib/linux-kernel/test/include/asm/unaligned.h new file mode 100644 index 00000000..4f482812 --- /dev/null +++ b/src/zstd/contrib/linux-kernel/test/include/asm/unaligned.h @@ -0,0 +1,177 @@ +#ifndef ASM_UNALIGNED_H +#define ASM_UNALIGNED_H + +#include <assert.h> +#include <linux/string.h> +#include <linux/types.h> + +#define _LITTLE_ENDIAN 1 + +static unsigned _isLittleEndian(void) +{ + const union { uint32_t u; uint8_t c[4]; } one = { 1 }; + assert(_LITTLE_ENDIAN == one.c[0]); + return _LITTLE_ENDIAN; +} + +static uint16_t _swap16(uint16_t in) +{ + return ((in & 0xF) << 8) + ((in & 0xF0) >> 8); +} + +static uint32_t _swap32(uint32_t in) +{ + return __builtin_bswap32(in); +} + +static uint64_t _swap64(uint64_t in) +{ + return __builtin_bswap64(in); +} + +/* Little endian */ +static uint16_t get_unaligned_le16(const void* memPtr) +{ + uint16_t val; + memcpy(&val, memPtr, sizeof(val)); + if (!_isLittleEndian()) _swap16(val); + return val; +} + +static uint32_t get_unaligned_le32(const void* memPtr) +{ + uint32_t val; + memcpy(&val, memPtr, sizeof(val)); + if (!_isLittleEndian()) _swap32(val); + return val; +} + +static uint64_t get_unaligned_le64(const void* memPtr) +{ + uint64_t val; + memcpy(&val, memPtr, sizeof(val)); + if (!_isLittleEndian()) _swap64(val); + return val; +} + +static void put_unaligned_le16(uint16_t value, void* memPtr) +{ + if (!_isLittleEndian()) value = _swap16(value); + memcpy(memPtr, &value, sizeof(value)); +} + +static void put_unaligned_le32(uint32_t value, void* memPtr) +{ + if (!_isLittleEndian()) value = _swap32(value); + memcpy(memPtr, &value, sizeof(value)); +} + +static void put_unaligned_le64(uint64_t value, void* memPtr) +{ + if (!_isLittleEndian()) value = _swap64(value); + memcpy(memPtr, &value, sizeof(value)); +} + +/* big endian */ +static uint32_t get_unaligned_be32(const void* memPtr) +{ + uint32_t val; + memcpy(&val, memPtr, sizeof(val)); + if (_isLittleEndian()) _swap32(val); + return val; +} + +static uint64_t get_unaligned_be64(const void* memPtr) +{ + uint64_t val; + memcpy(&val, memPtr, sizeof(val)); + if (_isLittleEndian()) _swap64(val); + return val; +} + +static void put_unaligned_be32(uint32_t value, void* memPtr) +{ + if (_isLittleEndian()) value = _swap32(value); + memcpy(memPtr, &value, sizeof(value)); +} + +static void put_unaligned_be64(uint64_t value, void* memPtr) +{ + if (_isLittleEndian()) value = _swap64(value); + memcpy(memPtr, &value, sizeof(value)); +} + +/* generic */ +extern void __bad_unaligned_access_size(void); + +#define __get_unaligned_le(ptr) ((typeof(*(ptr)))({ \ + __builtin_choose_expr(sizeof(*(ptr)) == 1, *(ptr), \ + __builtin_choose_expr(sizeof(*(ptr)) == 2, get_unaligned_le16((ptr)), \ + __builtin_choose_expr(sizeof(*(ptr)) == 4, get_unaligned_le32((ptr)), \ + __builtin_choose_expr(sizeof(*(ptr)) == 8, get_unaligned_le64((ptr)), \ + __bad_unaligned_access_size())))); \ + })) + +#define __get_unaligned_be(ptr) ((typeof(*(ptr)))({ \ + __builtin_choose_expr(sizeof(*(ptr)) == 1, *(ptr), \ + __builtin_choose_expr(sizeof(*(ptr)) == 2, get_unaligned_be16((ptr)), \ + __builtin_choose_expr(sizeof(*(ptr)) == 4, get_unaligned_be32((ptr)), \ + __builtin_choose_expr(sizeof(*(ptr)) == 8, get_unaligned_be64((ptr)), \ + __bad_unaligned_access_size())))); \ + })) + +#define __put_unaligned_le(val, ptr) \ + ({ \ + void *__gu_p = (ptr); \ + switch (sizeof(*(ptr))) { \ + case 1: \ + *(uint8_t *)__gu_p = (uint8_t)(val); \ + break; \ + case 2: \ + put_unaligned_le16((uint16_t)(val), __gu_p); \ + break; \ + case 4: \ + put_unaligned_le32((uint32_t)(val), __gu_p); \ + break; \ + case 8: \ + put_unaligned_le64((uint64_t)(val), __gu_p); \ + break; \ + default: \ + __bad_unaligned_access_size(); \ + break; \ + } \ + (void)0; \ + }) + +#define __put_unaligned_be(val, ptr) \ + ({ \ + void *__gu_p = (ptr); \ + switch (sizeof(*(ptr))) { \ + case 1: \ + *(uint8_t *)__gu_p = (uint8_t)(val); \ + break; \ + case 2: \ + put_unaligned_be16((uint16_t)(val), __gu_p); \ + break; \ + case 4: \ + put_unaligned_be32((uint32_t)(val), __gu_p); \ + break; \ + case 8: \ + put_unaligned_be64((uint64_t)(val), __gu_p); \ + break; \ + default: \ + __bad_unaligned_access_size(); \ + break; \ + } \ + (void)0; \ + }) + +#if _LITTLE_ENDIAN +# define get_unaligned __get_unaligned_le +# define put_unaligned __put_unaligned_le +#else +# define get_unaligned __get_unaligned_be +# define put_unaligned __put_unaligned_be +#endif + +#endif // ASM_UNALIGNED_H diff --git a/src/zstd/contrib/linux-kernel/test/include/linux/compiler.h b/src/zstd/contrib/linux-kernel/test/include/linux/compiler.h new file mode 100644 index 00000000..7991b8b2 --- /dev/null +++ b/src/zstd/contrib/linux-kernel/test/include/linux/compiler.h @@ -0,0 +1,12 @@ +#ifndef LINUX_COMIPLER_H_ +#define LINUX_COMIPLER_H_ + +#ifndef __always_inline +# define __always_inline inline +#endif + +#ifndef noinline +# define noinline __attribute__((__noinline__)) +#endif + +#endif // LINUX_COMIPLER_H_ diff --git a/src/zstd/contrib/linux-kernel/test/include/linux/errno.h b/src/zstd/contrib/linux-kernel/test/include/linux/errno.h new file mode 100644 index 00000000..b9db0852 --- /dev/null +++ b/src/zstd/contrib/linux-kernel/test/include/linux/errno.h @@ -0,0 +1,6 @@ +#ifndef LINUX_ERRNO_H_ +#define LINUX_ERRNO_H_ + +#define EINVAL 22 + +#endif // LINUX_ERRNO_H_ diff --git a/src/zstd/contrib/linux-kernel/test/include/linux/kernel.h b/src/zstd/contrib/linux-kernel/test/include/linux/kernel.h new file mode 100644 index 00000000..3ef2f7fe --- /dev/null +++ b/src/zstd/contrib/linux-kernel/test/include/linux/kernel.h @@ -0,0 +1,16 @@ +#ifndef LINUX_KERNEL_H_ +#define LINUX_KERNEL_H_ + +#define ALIGN(x, a) ({ \ + typeof(x) const __xe = (x); \ + typeof(a) const __ae = (a); \ + typeof(a) const __m = __ae - 1; \ + typeof(x) const __r = __xe & __m; \ + __xe + (__r ? (__ae - __r) : 0); \ + }) + +#define PTR_ALIGN(p, a) (typeof(p))ALIGN((unsigned long long)(p), (a)) + +#define current Something that doesn't compile :) + +#endif // LINUX_KERNEL_H_ diff --git a/src/zstd/contrib/linux-kernel/test/include/linux/math64.h b/src/zstd/contrib/linux-kernel/test/include/linux/math64.h new file mode 100644 index 00000000..3d0ae72d --- /dev/null +++ b/src/zstd/contrib/linux-kernel/test/include/linux/math64.h @@ -0,0 +1,11 @@ +#ifndef LINUX_MATH64_H +#define LINUX_MATH64_H + +#include <stdint.h> + +static uint64_t div_u64(uint64_t n, uint32_t d) +{ + return n / d; +} + +#endif diff --git a/src/zstd/contrib/linux-kernel/test/include/linux/module.h b/src/zstd/contrib/linux-kernel/test/include/linux/module.h new file mode 100644 index 00000000..ef514c34 --- /dev/null +++ b/src/zstd/contrib/linux-kernel/test/include/linux/module.h @@ -0,0 +1,10 @@ +#ifndef LINUX_MODULE_H_ +#define LINUX_MODULE_H_ + +#define EXPORT_SYMBOL(symbol) \ + void* __##symbol = symbol +#define MODULE_LICENSE(license) static char const *const LICENSE = license +#define MODULE_DESCRIPTION(description) \ + static char const *const DESCRIPTION = description + +#endif // LINUX_MODULE_H_ diff --git a/src/zstd/contrib/linux-kernel/test/include/linux/string.h b/src/zstd/contrib/linux-kernel/test/include/linux/string.h new file mode 100644 index 00000000..3b2f5900 --- /dev/null +++ b/src/zstd/contrib/linux-kernel/test/include/linux/string.h @@ -0,0 +1 @@ +#include <string.h> diff --git a/src/zstd/contrib/linux-kernel/test/include/linux/types.h b/src/zstd/contrib/linux-kernel/test/include/linux/types.h new file mode 100644 index 00000000..c2d4f4b7 --- /dev/null +++ b/src/zstd/contrib/linux-kernel/test/include/linux/types.h @@ -0,0 +1,2 @@ +#include <stddef.h> +#include <stdint.h> |