1111
1212#include "backend/generic-internal.h"
1313
14- uint8_t __pgfe_build_mask ( uint8_t digit_c );
14+ #define __bitsz 8
1515
16- inline uint8_t __pgfe_build_mask (uint8_t digit_c ) {
17- return UINT8_MAX >> (to_bit (sizeof (uint8_t )) - digit_c );
18- }
16+ #define __mkmask (digit ) (UINT8_MAX >> (__bitsz - (digit)))
1917
2018size_t __pgfe_transform_codes (const pgfe_encode_t input [], size_t length , uint8_t chunk_size , pgfe_encode_t out []) {
21- const uint16_t bitsz = to_bit ( sizeof ( pgfe_encode_t )) ;
22- pgfe_encode_t * inp = ( pgfe_encode_t * ) input , * op = out ;
19+ const pgfe_encode_t * inp = input ;
20+ pgfe_encode_t * op = out ;
2321 size_t low , high , mv_sz , sz_diff ;
2422
25- const uint8_t chunk_mask = __pgfe_build_mask (chunk_size );
23+ const uint8_t chunk_mask = __mkmask (chunk_size );
2624
27- for (low = 0 , high = chunk_size % bitsz ; inp - input <= length ; inp ++ , op ++ ) {
25+ for (low = 0 , high = chunk_size % __bitsz ; inp - input <= length ; inp ++ , op ++ ) {
2826 if (low < high ) {
29- * op = ((* inp ) >> (bitsz - high )) & chunk_mask ;
27+ * op = ((* inp ) >> (__bitsz - high )) & chunk_mask ;
3028 inp -- ;
3129 }
3230 else if (!high ) {
3331 * op = (* inp ) & chunk_mask ;
3432 }
3533 else {
36- sz_diff = bitsz - low ;
34+ sz_diff = __bitsz - low ;
3735 mv_sz = chunk_size - sz_diff ;
38- * op = ((* inp ) & __pgfe_build_mask (sz_diff )) << mv_sz ;
36+ * op = ((* inp ) & __mkmask (sz_diff )) << mv_sz ;
3937 if (inp - input + 1 < length ) {
40- * op |= ((* (inp + 1 )) >> (bitsz - high )) & __pgfe_build_mask (high );
38+ * op |= ((* (inp + 1 )) >> (__bitsz - high )) & __mkmask (high );
4139 }
4240 }
4341
44- low = (low + chunk_size ) % bitsz ;
45- high = (high + chunk_size ) % bitsz ;
42+ low = (low + chunk_size ) % __bitsz ;
43+ high = (high + chunk_size ) % __bitsz ;
4644 }
4745
4846 return op - out ;
@@ -75,10 +73,11 @@ size_t __pgfe_unittostr(
7573 return chunk_count ;
7674}
7775
78- size_t __pgfe_encode_generic (
76+ size_t __pgfe_encode_base_generic (
7977 PGFE_BASE_PARAMS_DEF , const char alphabet [], const pgfe_encode_t input [], size_t input_length , char cs_out []
8078) {
81- pgfe_encode_t input_unit [unit_size ], * inp = (pgfe_encode_t * )input ;
79+ pgfe_encode_t input_unit [unit_size ];
80+ const pgfe_encode_t * inp = input ;
8281 size_t i , remain ;
8382 char * sp = cs_out ;
8483
@@ -103,15 +102,14 @@ size_t __pgfe_encode_generic(
103102 return sp - cs_out ;
104103}
105104
106- size_t __pgfe_decode_generic (
105+ size_t __pgfe_decode_base_generic (
107106 PGFE_BASE_PARAMS_DEF , pgfe_encode_t (* func )(char ), const char basexx_cs [], pgfe_encode_t output []
108107) {
109108 pgfe_encode_t * op , ch , sig , o_unit [unit_size ];
110- const size_t sz_ou = to_bit (sizeof (pgfe_encode_t ));
111- char * sp = (char * )basexx_cs ;
112- size_t i = 0 , j ;
109+ const char * sp = basexx_cs ;
110+ size_t i , j ;
113111 uint64_t u ;
114- const uint8_t mask = __pgfe_build_mask (bit_size );
112+ const uint8_t mask = __mkmask (bit_size );
115113
116114 u = 0 ;
117115 op = output ;
@@ -134,7 +132,7 @@ size_t __pgfe_decode_generic(
134132 }
135133
136134 for (j = 0 ; j < unit_size ; j ++ ) {
137- o_unit [j ] = (pgfe_encode_t )((u >> (sz_ou * (unit_size - j - 1 ))) & 0xFF );
135+ o_unit [j ] = (pgfe_encode_t )((u >> (__bitsz * (unit_size - j - 1 ))) & 0xFF );
138136 }
139137
140138 memcpy (op , o_unit , unit_size );
0 commit comments