File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 11override THIS_DIR := $(dir $(realpath $(lastword $(MAKEFILE_LIST ) ) ) )
22
3- override TARGETS := stochar test test-json test-utf8
3+ override TARGETS := stochar test test-json test-rev test- utf8
44
55 all :| $(TARGETS )
66 clean :| $(TARGETS:%=clean-% )
@@ -26,6 +26,8 @@ override DBG_test := dbg.c
2626override LIBS_test = $(CJSON_LIBS )
2727override CFLAGS_test.c = $(CJSON_CFLAGS )
2828
29+ override SRC_test-rev := parse.c test-rev.c
30+
2931override SRC_test-json := json.c test-json.c
3032override DBG_test-json := dbg.c
3133
Original file line number Diff line number Diff line change @@ -20,28 +20,28 @@ typedef unsigned _BitInt(2) uint2;
2020typedef unsigned _BitInt (4 ) uint4 ;
2121#define uint2 (x ) (uint2)(x)
2222#define uint4 (x ) (uint4)(x)
23- #define uint2_get (x ) x
24- #define uint4_get (x ) x
23+ #define uint2_get (x ) (x)
24+ #define uint4_get (x ) (x)
2525#endif
2626
2727static const_inline uint2
2828rev2 (uint2 x )
2929{
30- x ^= (x & 0x2 ) >> 1U ;
31- x ^= (x & 0x1 ) << 1U ;
32- x ^= (x & 0x2 ) >> 1U ;
30+ uint2_get ( x ) ^= (uint2_get ( x ) & 0x2U ) >> 1U ;
31+ uint2_get ( x ) ^= (uint2_get ( x ) & 0x1U ) << 1U ;
32+ uint2_get ( x ) ^= (uint2_get ( x ) & 0x2U ) >> 1U ;
3333 return x ;
3434}
3535
3636static const_inline uint4
3737rev4 (uint4 x )
3838{
39- x ^= (x & 0xa ) >> 1U ;
40- x ^= (x & 0x5 ) << 1U ;
41- x ^= (x & 0xc ) >> 2U ;
42- x ^= (x & 0x3 ) << 2U ;
43- x ^= (x & 0xc ) >> 2U ;
44- x ^= (x & 0xa ) >> 1U ;
39+ uint4_get ( x ) ^= (uint4_get ( x ) & 0xaU ) >> 1U ;
40+ uint4_get ( x ) ^= (uint4_get ( x ) & 0x5U ) << 1U ;
41+ uint4_get ( x ) ^= (uint4_get ( x ) & 0xcU ) >> 2U ;
42+ uint4_get ( x ) ^= (uint4_get ( x ) & 0x3U ) << 2U ;
43+ uint4_get ( x ) ^= (uint4_get ( x ) & 0xcU ) >> 2U ;
44+ uint4_get ( x ) ^= (uint4_get ( x ) & 0xaU ) >> 1U ;
4545 return x ;
4646}
4747
Original file line number Diff line number Diff line change 99#include "parse.h"
1010#include "rev.h"
1111
12+ struct asc4 {
13+ char d [4 ];
14+ };
15+
16+ __attribute__((const ))
17+ static struct asc4
18+ bin_asc (uint4 x )
19+ {
20+
21+ union {
22+ char c [35U ];
23+ unsigned char u [35U ];
24+ } const t = {
25+ "1111000010011010" "111"
26+ "\x04" "\x05" "\x06"
27+ "\x09" "\x07" "\x0d"
28+ "\x0a" "\x0f" "\x03"
29+ "\x08" "\x0c" "\x0e"
30+ "\x02" "\x0b" "\x01"
31+ };
32+ unsigned const i = t .u [
33+ 19U + uint4_get (x )
34+ ];
35+ return (struct asc4 ){ .d = {
36+ t .c [i + 0U ], t .c [i + 1U ],
37+ t .c [i + 2U ], t .c [i + 3U ]
38+ }};
39+ }
40+
1241int
1342main (int c ,
1443 char * * v )
1544{
1645 for (int i = 0 ; ++ i < c ;) {
1746 struct parsed p = parse_u64 (v [i ]);
18- if (parsed_ok (p , v [i ]))
19- (void )printf ("%016" PRIx64 " "
20- "%016" PRIx64 "\n" ,
21- p .u64 , rev64 (p .u64 ));
47+ if (!parsed_ok (p , v [i ]))
48+ continue ;
49+
50+ (void )printf ("%016" PRIx64 " "
51+ "%016" PRIx64 "\n" ,
52+ p .u64 , rev64 (p .u64 ));
53+
54+ if (p .u64 > UINT32_MAX )
55+ continue ;
56+ (void )printf (" %0"
57+ "8" PRIx64 " "
58+ "%08" PRIx32 "\n" ,
59+ p .u64 , rev32 ((uint32_t )p .u64 ));
60+
61+ if (p .u64 > UINT16_MAX )
62+ continue ;
63+ (void )printf (" %0"
64+ "4" PRIx64 " "
65+ "%04" PRIx16 "\n" ,
66+ p .u64 , rev16 ((uint16_t )p .u64 ));
67+
68+ if (p .u64 > UINT8_MAX )
69+ continue ;
70+ (void )printf (" %0"
71+ "2" PRIx64 " "
72+ "%02" PRIx8 "\n" ,
73+ p .u64 , rev8 ((uint8_t )p .u64 ));
74+
75+ if (p .u64 > 15U )
76+ continue ;
77+ (void )printf (" "
78+ "%" PRIx64 " %x\n" ,
79+ p .u64 , (unsigned )uint4_get (rev4 (uint4 (p .u64 ))));
2280
81+ if (p .u64 > 3U )
82+ continue ;
83+ (void )printf (" "
84+ "%" PRIx64 " %x\n" ,
85+ p .u64 , (unsigned )uint2_get (rev2 (uint2 (p .u64 ))));
2386 }
2487}
You can’t perform that action at this time.
0 commit comments