1 | /* |
1 | /* |
2 | * libecb - http://software.schmorp.de/pkg/libecb |
2 | * libecb - http://software.schmorp.de/pkg/libecb |
3 | * |
3 | * |
4 | * Copyright (©) 2009-2015 Marc Alexander Lehmann <libecb@schmorp.de> |
4 | * Copyright (©) 2009-2015,2018-2020 Marc Alexander Lehmann <libecb@schmorp.de> |
5 | * Copyright (©) 2011 Emanuele Giaquinta |
5 | * Copyright (©) 2011 Emanuele Giaquinta |
6 | * All rights reserved. |
6 | * All rights reserved. |
7 | * |
7 | * |
8 | * Redistribution and use in source and binary forms, with or without modifica- |
8 | * Redistribution and use in source and binary forms, with or without modifica- |
9 | * tion, are permitted provided that the following conditions are met: |
9 | * tion, are permitted provided that the following conditions are met: |
… | |
… | |
41 | #ifndef ECB_H |
41 | #ifndef ECB_H |
42 | #define ECB_H |
42 | #define ECB_H |
43 | |
43 | |
44 | /* 16 bits major, 16 bits minor */ |
44 | /* 16 bits major, 16 bits minor */ |
45 | #define ECB_VERSION 0x00010008 |
45 | #define ECB_VERSION 0x00010008 |
|
|
46 | |
|
|
47 | #include <string.h> /* for memcpy */ |
46 | |
48 | |
47 | #ifdef _WIN32 |
49 | #ifdef _WIN32 |
48 | typedef signed char int8_t; |
50 | typedef signed char int8_t; |
49 | typedef unsigned char uint8_t; |
51 | typedef unsigned char uint8_t; |
50 | typedef signed char int_fast8_t; |
52 | typedef signed char int_fast8_t; |
… | |
… | |
769 | |
771 | |
770 | ecb_inline void ecb_poke_le_u16_u (void *ptr, uint_fast16_t v) { ecb_poke_u16_u (ptr, ecb_host_to_le_u16 (v)); } |
772 | ecb_inline void ecb_poke_le_u16_u (void *ptr, uint_fast16_t v) { ecb_poke_u16_u (ptr, ecb_host_to_le_u16 (v)); } |
771 | ecb_inline void ecb_poke_le_u32_u (void *ptr, uint_fast32_t v) { ecb_poke_u32_u (ptr, ecb_host_to_le_u32 (v)); } |
773 | ecb_inline void ecb_poke_le_u32_u (void *ptr, uint_fast32_t v) { ecb_poke_u32_u (ptr, ecb_host_to_le_u32 (v)); } |
772 | ecb_inline void ecb_poke_le_u64_u (void *ptr, uint_fast64_t v) { ecb_poke_u64_u (ptr, ecb_host_to_le_u64 (v)); } |
774 | ecb_inline void ecb_poke_le_u64_u (void *ptr, uint_fast64_t v) { ecb_poke_u64_u (ptr, ecb_host_to_le_u64 (v)); } |
773 | |
775 | |
774 | #ifdef ECB_CPP |
776 | #if ECB_CPP |
775 | |
777 | |
776 | inline uint8_t ecb_bswap (uint8_t v) { return v; } |
778 | inline uint8_t ecb_bswap (uint8_t v) { return v; } |
777 | inline uint16_t ecb_bswap (uint16_t v) { return ecb_bswap16 (v); } |
779 | inline uint16_t ecb_bswap (uint16_t v) { return ecb_bswap16 (v); } |
778 | inline uint32_t ecb_bswap (uint32_t v) { return ecb_bswap32 (v); } |
780 | inline uint32_t ecb_bswap (uint32_t v) { return ecb_bswap32 (v); } |
779 | inline uint64_t ecb_bswap (uint64_t v) { return ecb_bswap64 (v); } |
781 | inline uint64_t ecb_bswap (uint64_t v) { return ecb_bswap64 (v); } |
… | |
… | |
781 | template<typename T> inline T ecb_be_to_host (T v) { return ecb_little_endian () ? ecb_bswap (v) : v; } |
783 | template<typename T> inline T ecb_be_to_host (T v) { return ecb_little_endian () ? ecb_bswap (v) : v; } |
782 | template<typename T> inline T ecb_le_to_host (T v) { return ecb_big_endian () ? ecb_bswap (v) : v; } |
784 | template<typename T> inline T ecb_le_to_host (T v) { return ecb_big_endian () ? ecb_bswap (v) : v; } |
783 | template<typename T> inline T ecb_peek (const void *ptr) { return *(const T *)ptr; } |
785 | template<typename T> inline T ecb_peek (const void *ptr) { return *(const T *)ptr; } |
784 | template<typename T> inline T ecb_peek_be (const void *ptr) { return ecb_be_to_host (ecb_peek <T> (ptr)); } |
786 | template<typename T> inline T ecb_peek_be (const void *ptr) { return ecb_be_to_host (ecb_peek <T> (ptr)); } |
785 | template<typename T> inline T ecb_peek_le (const void *ptr) { return ecb_le_to_host (ecb_peek <T> (ptr)); } |
787 | template<typename T> inline T ecb_peek_le (const void *ptr) { return ecb_le_to_host (ecb_peek <T> (ptr)); } |
786 | template<typename T> inline T ecb_peek_u (const void *ptr) { T v; std::memcpy (&v, ptr, sizeof (v)); return v; } |
788 | template<typename T> inline T ecb_peek_u (const void *ptr) { T v; memcpy (&v, ptr, sizeof (v)); return v; } |
787 | template<typename T> inline T ecb_peek_be_u (const void *ptr) { return ecb_be_to_host (ecb_peek_u<T> (ptr)); } |
789 | template<typename T> inline T ecb_peek_be_u (const void *ptr) { return ecb_be_to_host (ecb_peek_u<T> (ptr)); } |
788 | template<typename T> inline T ecb_peek_le_u (const void *ptr) { return ecb_le_to_host (ecb_peek_u<T> (ptr)); } |
790 | template<typename T> inline T ecb_peek_le_u (const void *ptr) { return ecb_le_to_host (ecb_peek_u<T> (ptr)); } |
789 | |
791 | |
790 | template<typename T> inline T ecb_host_to_be (T v) { return ecb_little_endian () ? ecb_bswap (v) : v; } |
792 | template<typename T> inline T ecb_host_to_be (T v) { return ecb_little_endian () ? ecb_bswap (v) : v; } |
791 | template<typename T> inline T ecb_host_to_le (T v) { return ecb_big_endian () ? ecb_bswap (v) : v; } |
793 | template<typename T> inline T ecb_host_to_le (T v) { return ecb_big_endian () ? ecb_bswap (v) : v; } |
792 | template<typename T> inline void ecb_poke (void *ptr, T v) { *(T *)ptr = v; } |
794 | template<typename T> inline void ecb_poke (void *ptr, T v) { *(T *)ptr = v; } |
793 | template<typename T> inline void ecb_poke_be (void *ptr, T v) { return ecb_poke <T> (ptr, ecb_host_to_be (v)); } |
795 | template<typename T> inline void ecb_poke_be (void *ptr, T v) { return ecb_poke <T> (ptr, ecb_host_to_be (v)); } |
794 | template<typename T> inline void ecb_poke_le (void *ptr, T v) { return ecb_poke <T> (ptr, ecb_host_to_le (v)); } |
796 | template<typename T> inline void ecb_poke_le (void *ptr, T v) { return ecb_poke <T> (ptr, ecb_host_to_le (v)); } |
795 | template<typename T> inline void ecb_poke_u (void *ptr, T v) { std::memcpy (ptr, &v, sizeof (v)); } |
797 | template<typename T> inline void ecb_poke_u (void *ptr, T v) { memcpy (ptr, &v, sizeof (v)); } |
796 | template<typename T> inline void ecb_poke_be_u (void *ptr, T v) { return ecb_poke_u<T> (ptr, ecb_host_to_be (v)); } |
798 | template<typename T> inline void ecb_poke_be_u (void *ptr, T v) { return ecb_poke_u<T> (ptr, ecb_host_to_be (v)); } |
797 | template<typename T> inline void ecb_poke_le_u (void *ptr, T v) { return ecb_poke_u<T> (ptr, ecb_host_to_le (v)); } |
799 | template<typename T> inline void ecb_poke_le_u (void *ptr, T v) { return ecb_poke_u<T> (ptr, ecb_host_to_le (v)); } |
798 | |
800 | |
799 | #endif |
801 | #endif |
800 | |
802 | |
… | |
… | |
950 | || defined __sh__ \ |
952 | || defined __sh__ \ |
951 | || defined _M_IX86 || defined ECB_MSVC_AMD64 || defined _M_IA64 \ |
953 | || defined _M_IX86 || defined ECB_MSVC_AMD64 || defined _M_IA64 \ |
952 | || (defined __arm__ && (defined __ARM_EABI__ || defined __EABI__ || defined __VFP_FP__ || defined _WIN32_WCE || defined __ANDROID__)) \ |
954 | || (defined __arm__ && (defined __ARM_EABI__ || defined __EABI__ || defined __VFP_FP__ || defined _WIN32_WCE || defined __ANDROID__)) \ |
953 | || defined __aarch64__ |
955 | || defined __aarch64__ |
954 | #define ECB_STDFP 1 |
956 | #define ECB_STDFP 1 |
955 | #include <string.h> /* for memcpy */ |
|
|
956 | #else |
957 | #else |
957 | #define ECB_STDFP 0 |
958 | #define ECB_STDFP 0 |
958 | #endif |
959 | #endif |
959 | |
960 | |
960 | #ifndef ECB_NO_LIBM |
961 | #ifndef ECB_NO_LIBM |