ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/libecb/ecb.h
(Generate patch)

Comparing libecb/ecb.h (file contents):
Revision 1.181 by root, Mon Jan 20 13:16:01 2020 UTC vs.
Revision 1.186 by root, Tue Jan 21 23:51:21 2020 UTC

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;
608ecb_inline ecb_const uint32_t ecb_rotl32 (uint32_t x, unsigned int count) { return (x >> (32 - count)) | (x << count); } 610ecb_inline ecb_const uint32_t ecb_rotl32 (uint32_t x, unsigned int count) { return (x >> (32 - count)) | (x << count); }
609ecb_inline ecb_const uint32_t ecb_rotr32 (uint32_t x, unsigned int count) { return (x << (32 - count)) | (x >> count); } 611ecb_inline ecb_const uint32_t ecb_rotr32 (uint32_t x, unsigned int count) { return (x << (32 - count)) | (x >> count); }
610ecb_inline ecb_const uint64_t ecb_rotl64 (uint64_t x, unsigned int count) { return (x >> (64 - count)) | (x << count); } 612ecb_inline ecb_const uint64_t ecb_rotl64 (uint64_t x, unsigned int count) { return (x >> (64 - count)) | (x << count); }
611ecb_inline ecb_const uint64_t ecb_rotr64 (uint64_t x, unsigned int count) { return (x << (64 - count)) | (x >> count); } 613ecb_inline ecb_const uint64_t ecb_rotr64 (uint64_t x, unsigned int count) { return (x << (64 - count)) | (x >> count); }
612 614
615#if ECB_CPP
616
617inline uint8_t ecb_ctz (uint8_t v) { return ecb_ctz32 (v); }
618inline uint16_t ecb_ctz (uint16_t v) { return ecb_ctz32 (v); }
619inline uint32_t ecb_ctz (uint32_t v) { return ecb_ctz32 (v); }
620inline uint64_t ecb_ctz (uint64_t v) { return ecb_ctz64 (v); }
621
622inline bool ecb_is_pot (uint8_t v) { return ecb_is_pot32 (v); }
623inline bool ecb_is_pot (uint16_t v) { return ecb_is_pot32 (v); }
624inline bool ecb_is_pot (uint32_t v) { return ecb_is_pot32 (v); }
625inline bool ecb_is_pot (uint64_t v) { return ecb_is_pot64 (v); }
626
627inline int ecb_ld (uint8_t v) { return ecb_ld32 (v); }
628inline int ecb_ld (uint16_t v) { return ecb_ld32 (v); }
629inline int ecb_ld (uint32_t v) { return ecb_ld32 (v); }
630inline int ecb_ld (uint64_t v) { return ecb_ld64 (v); }
631
632inline int ecb_popcount (uint8_t v) { return ecb_popcount32 (v); }
633inline int ecb_popcount (uint16_t v) { return ecb_popcount32 (v); }
634inline int ecb_popcount (uint32_t v) { return ecb_popcount32 (v); }
635inline int ecb_popcount (uint64_t v) { return ecb_popcount64 (v); }
636
637inline uint8_t ecb_bitrev (uint8_t v) { return ecb_bitrev8 (v); }
638inline uint16_t ecb_bitrev (uint16_t v) { return ecb_bitrev16 (v); }
639inline uint32_t ecb_bitrev (uint32_t v) { return ecb_bitrev32 (v); }
640
641inline uint8_t ecb_rotl (uint8_t v, unsigned int count) { return ecb_rotl8 (v, count); }
642inline uint16_t ecb_rotl (uint16_t v, unsigned int count) { return ecb_rotl16 (v, count); }
643inline uint32_t ecb_rotl (uint32_t v, unsigned int count) { return ecb_rotl32 (v, count); }
644inline uint64_t ecb_rotl (uint64_t v, unsigned int count) { return ecb_rotl64 (v, count); }
645
646inline uint8_t ecb_rotr (uint8_t v, unsigned int count) { return ecb_rotr8 (v, count); }
647inline uint16_t ecb_rotr (uint16_t v, unsigned int count) { return ecb_rotr16 (v, count); }
648inline uint32_t ecb_rotr (uint32_t v, unsigned int count) { return ecb_rotr32 (v, count); }
649inline uint64_t ecb_rotr (uint64_t v, unsigned int count) { return ecb_rotr64 (v, count); }
650
651#endif
652
613#if ECB_GCC_VERSION(4,3) || (ECB_CLANG_BUILTIN(__builtin_bswap32) && ECB_CLANG_BUILTIN(__builtin_bswap64)) 653#if ECB_GCC_VERSION(4,3) || (ECB_CLANG_BUILTIN(__builtin_bswap32) && ECB_CLANG_BUILTIN(__builtin_bswap64))
614 #if ECB_GCC_VERSION(4,8) || ECB_CLANG_BUILTIN(__builtin_bswap16) 654 #if ECB_GCC_VERSION(4,8) || ECB_CLANG_BUILTIN(__builtin_bswap16)
615 #define ecb_bswap16(x) __builtin_bswap16 (x) 655 #define ecb_bswap16(x) __builtin_bswap16 (x)
616 #else 656 #else
617 #define ecb_bswap16(x) (__builtin_bswap32 (x) >> 16) 657 #define ecb_bswap16(x) (__builtin_bswap32 (x) >> 16)
731 771
732ecb_inline void ecb_poke_le_u16_u (void *ptr, uint_fast16_t v) { ecb_poke_u16_u (ptr, ecb_host_to_le_u16 (v)); } 772ecb_inline void ecb_poke_le_u16_u (void *ptr, uint_fast16_t v) { ecb_poke_u16_u (ptr, ecb_host_to_le_u16 (v)); }
733ecb_inline void ecb_poke_le_u32_u (void *ptr, uint_fast32_t v) { ecb_poke_u32_u (ptr, ecb_host_to_le_u32 (v)); } 773ecb_inline void ecb_poke_le_u32_u (void *ptr, uint_fast32_t v) { ecb_poke_u32_u (ptr, ecb_host_to_le_u32 (v)); }
734ecb_inline void ecb_poke_le_u64_u (void *ptr, uint_fast64_t v) { ecb_poke_u64_u (ptr, ecb_host_to_le_u64 (v)); } 774ecb_inline void ecb_poke_le_u64_u (void *ptr, uint_fast64_t v) { ecb_poke_u64_u (ptr, ecb_host_to_le_u64 (v)); }
735 775
736#ifdef ECB_CPP 776#if ECB_CPP
737 777
738inline uint8_t ecb_bswap (uint8_t v) { return v; } 778inline uint8_t ecb_bswap (uint8_t v) { return v; }
739inline uint16_t ecb_bswap (uint16_t v) { return ecb_bswap16 (v); } 779inline uint16_t ecb_bswap (uint16_t v) { return ecb_bswap16 (v); }
740inline uint32_t ecb_bswap (uint32_t v) { return ecb_bswap32 (v); } 780inline uint32_t ecb_bswap (uint32_t v) { return ecb_bswap32 (v); }
741inline uint64_t ecb_bswap (uint64_t v) { return ecb_bswap64 (v); } 781inline uint64_t ecb_bswap (uint64_t v) { return ecb_bswap64 (v); }
743template<typename T> inline T ecb_be_to_host (T v) { return ecb_little_endian () ? ecb_bswap (v) : v; } 783template<typename T> inline T ecb_be_to_host (T v) { return ecb_little_endian () ? ecb_bswap (v) : v; }
744template<typename T> inline T ecb_le_to_host (T v) { return ecb_big_endian () ? ecb_bswap (v) : v; } 784template<typename T> inline T ecb_le_to_host (T v) { return ecb_big_endian () ? ecb_bswap (v) : v; }
745template<typename T> inline T ecb_peek (const void *ptr) { return *(const T *)ptr; } 785template<typename T> inline T ecb_peek (const void *ptr) { return *(const T *)ptr; }
746template<typename T> inline T ecb_peek_be (const void *ptr) { return ecb_be_to_host (ecb_peek <T> (ptr)); } 786template<typename T> inline T ecb_peek_be (const void *ptr) { return ecb_be_to_host (ecb_peek <T> (ptr)); }
747template<typename T> inline T ecb_peek_le (const void *ptr) { return ecb_le_to_host (ecb_peek <T> (ptr)); } 787template<typename T> inline T ecb_peek_le (const void *ptr) { return ecb_le_to_host (ecb_peek <T> (ptr)); }
748template<typename T> inline T ecb_peek_u (const void *ptr) { T v; std::memcpy (&v, ptr, sizeof (v)); return v; } 788template<typename T> inline T ecb_peek_u (const void *ptr) { T v; memcpy (&v, ptr, sizeof (v)); return v; }
749template<typename T> inline T ecb_peek_be_u (const void *ptr) { return ecb_be_to_host (ecb_peek_u<T> (ptr)); } 789template<typename T> inline T ecb_peek_be_u (const void *ptr) { return ecb_be_to_host (ecb_peek_u<T> (ptr)); }
750template<typename T> inline T ecb_peek_le_u (const void *ptr) { return ecb_le_to_host (ecb_peek_u<T> (ptr)); } 790template<typename T> inline T ecb_peek_le_u (const void *ptr) { return ecb_le_to_host (ecb_peek_u<T> (ptr)); }
751 791
752template<typename T> inline T ecb_host_to_be (T v) { return ecb_little_endian () ? ecb_bswap (v) : v; } 792template<typename T> inline T ecb_host_to_be (T v) { return ecb_little_endian () ? ecb_bswap (v) : v; }
753template<typename T> inline T ecb_host_to_le (T v) { return ecb_big_endian () ? ecb_bswap (v) : v; } 793template<typename T> inline T ecb_host_to_le (T v) { return ecb_big_endian () ? ecb_bswap (v) : v; }
754template<typename T> inline void ecb_poke (void *ptr, T v) { *(T *)ptr = v; } 794template<typename T> inline void ecb_poke (void *ptr, T v) { *(T *)ptr = v; }
755template<typename T> inline void ecb_poke_be (void *ptr, T v) { return ecb_poke <T> (ptr, ecb_host_to_be (v)); } 795template<typename T> inline void ecb_poke_be (void *ptr, T v) { return ecb_poke <T> (ptr, ecb_host_to_be (v)); }
756template<typename T> inline void ecb_poke_le (void *ptr, T v) { return ecb_poke <T> (ptr, ecb_host_to_le (v)); } 796template<typename T> inline void ecb_poke_le (void *ptr, T v) { return ecb_poke <T> (ptr, ecb_host_to_le (v)); }
757template<typename T> inline void ecb_poke_u (void *ptr, T v) { std::memcpy (ptr, &v, sizeof (v)); } 797template<typename T> inline void ecb_poke_u (void *ptr, T v) { memcpy (ptr, &v, sizeof (v)); }
758template<typename T> inline void ecb_poke_be_u (void *ptr, T v) { return ecb_poke_u<T> (ptr, ecb_host_to_be (v)); } 798template<typename T> inline void ecb_poke_be_u (void *ptr, T v) { return ecb_poke_u<T> (ptr, ecb_host_to_be (v)); }
759template<typename T> inline void ecb_poke_le_u (void *ptr, T v) { return ecb_poke_u<T> (ptr, ecb_host_to_le (v)); } 799template<typename T> inline void ecb_poke_le_u (void *ptr, T v) { return ecb_poke_u<T> (ptr, ecb_host_to_le (v)); }
760 800
761#endif 801#endif
762 802
912 || defined __sh__ \ 952 || defined __sh__ \
913 || defined _M_IX86 || defined ECB_MSVC_AMD64 || defined _M_IA64 \ 953 || defined _M_IX86 || defined ECB_MSVC_AMD64 || defined _M_IA64 \
914 || (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__)) \
915 || defined __aarch64__ 955 || defined __aarch64__
916 #define ECB_STDFP 1 956 #define ECB_STDFP 1
917 #include <string.h> /* for memcpy */
918#else 957#else
919 #define ECB_STDFP 0 958 #define ECB_STDFP 0
920#endif 959#endif
921 960
922#ifndef ECB_NO_LIBM 961#ifndef ECB_NO_LIBM

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines