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

Comparing libecb/ecb.h (file contents):
Revision 1.201 by root, Fri Aug 20 20:13:20 2021 UTC vs.
Revision 1.202 by root, Wed Mar 23 09:58:06 2022 UTC

40 40
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 0x0001000a 45#define ECB_VERSION 0x0001000b
46 46
47#include <string.h> /* for memcpy */ 47#include <string.h> /* for memcpy */
48 48
49#if defined (_WIN32) && !defined (__MINGW32__) 49#if defined (_WIN32) && !defined (__MINGW32__)
50 typedef signed char int8_t; 50 typedef signed char int8_t;
884} 884}
885 885
886#endif 886#endif
887 887
888/*****************************************************************************/ 888/*****************************************************************************/
889/* gray code */
890
891ecb_function_ uint_fast8_t ecb_gray8_encode (uint_fast8_t b) { return b ^ (b >> 1); }
892ecb_function_ uint_fast16_t ecb_gray16_encode (uint_fast16_t b) { return b ^ (b >> 1); }
893ecb_function_ uint_fast32_t ecb_gray32_encode (uint_fast32_t b) { return b ^ (b >> 1); }
894ecb_function_ uint_fast64_t ecb_gray64_encode (uint_fast64_t b) { return b ^ (b >> 1); }
895
896ecb_function_ uint8_t ecb_gray8_decode (uint8_t g)
897{
898 g = g ^ (g >> 1);
899 g = g ^ (g >> 2);
900 g = g ^ (g >> 4);
901 return g;
902}
903
904ecb_function_ uint16_t ecb_gray16_decode (uint16_t g)
905{
906 g = g ^ (g >> 1);
907 g = g ^ (g >> 2);
908 g = g ^ (g >> 4);
909 g = g ^ (g >> 8);
910 return g;
911}
912
913ecb_function_ uint32_t ecb_gray32_decode (uint32_t g)
914{
915 g = g ^ (g >> 1);
916 g = g ^ (g >> 2);
917 g = g ^ (g >> 4);
918 g = g ^ (g >> 8);
919 g = g ^ (g >> 16);
920 return g;
921}
922
923ecb_function_ uint64_t ecb_gray64_decode (uint64_t g)
924{
925 g = g ^ (g >> 1);
926 g = g ^ (g >> 2);
927 g = g ^ (g >> 4);
928 g = g ^ (g >> 8);
929 g = g ^ (g >> 16);
930 g = g ^ (g >> 32);
931 return g;
932}
933
934#if ECB_CPP
935
936ecb_function_ uint8_t ecb_gray_encode (uint8_t b) { return ecb_gray8_encode (b); }
937ecb_function_ uint16_t ecb_gray_encode (uint16_t b) { return ecb_gray16_encode (b); }
938ecb_function_ uint32_t ecb_gray_encode (uint32_t b) { return ecb_gray32_encode (b); }
939ecb_function_ uint64_t ecb_gray_encode (uint64_t b) { return ecb_gray64_encode (b); }
940
941ecb_function_ uint8_t ecb_gray_decode (uint8_t g) { return ecb_gray8_decode (g); }
942ecb_function_ uint16_t ecb_gray_decode (uint16_t g) { return ecb_gray16_decode (g); }
943ecb_function_ uint32_t ecb_gray_decode (uint32_t g) { return ecb_gray32_decode (g); }
944ecb_function_ uint64_t ecb_gray_decode (uint64_t g) { return ecb_gray64_decode (g); }
945
946#endif
947
948/*****************************************************************************/
889/* division */ 949/* division */
890 950
891#if ECB_GCC_VERSION(3,0) || ECB_C99 951#if ECB_GCC_VERSION(3,0) || ECB_C99
892 /* C99 tightened the definition of %, so we can use a more efficient version */ 952 /* C99 tightened the definition of %, so we can use a more efficient version */
893 #define ecb_mod(m,n) ((m) % (n) + ((m) % (n) < 0 ? (n) : 0)) 953 #define ecb_mod(m,n) ((m) % (n) + ((m) % (n) < 0 ? (n) : 0))

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines