7
7
#define idx_2 (LUT , i1 , i0 ) (idx_1(LUT, i0) + (LUT)[1][i1])
8
8
#define min (x , y ) (((x) > (y)) ? (y) : (x))
9
9
#define unlikely (x ) __builtin_expect(!!(x), 0)
10
- #define PUSH_SOLUTION (current_solution ) \
11
- { \
12
- packVectors_of_solution[current_solution_index ] = current_solution; \
13
- current_solution_index ++; \
14
- if (current_solution_index == 1) { \
15
- if (testSolution(States, current_solution_index, packVectors_of_solution )) { \
16
- return; \
17
- } \
18
- current_solution_index = 0; \
19
- } \
10
+ #define PUSH_SOLUTION (current_solution ) \
11
+ { \
12
+ solution[currentCandidateIndex ] = current_solution; \
13
+ currentCandidateIndex ++; \
14
+ if (currentCandidateIndex == 1) { \
15
+ if (testSolution(States, currentCandidateIndex, solution )) { \
16
+ return; \
17
+ } \
18
+ currentCandidateIndex = 0; \
19
+ } \
20
20
}
21
- #define CHECK_SOLUTIONS () \
22
- { \
23
- for (uint64_t i = 0; i < n_solutions_found ; i++) { \
24
- if (solution_buffer [i].mask & 0xffff) { \
25
- PUSH_SOLUTION(encodeToGray(solution_buffer [i].intIndex)); \
26
- } \
27
- } \
28
- n_solutions_found = 0; \
21
+ #define CHECK_SOLUTIONS () \
22
+ { \
23
+ for (uint64_t i = 0; i < numCandidates ; i++) { \
24
+ if (candidates [i].mask & 0xffff) { \
25
+ PUSH_SOLUTION(encodeToGray(candidates [i].intIndex)); \
26
+ } \
27
+ } \
28
+ numCandidates = 0; \
29
29
}
30
- #define STEP_0 (i ) \
31
- { \
32
- if (unlikely(F[0] == 0)) { \
33
- solution_buffer[n_solutions_found ].intIndex = i; \
34
- solution_buffer[n_solutions_found ].mask = 0x000f; \
35
- n_solutions_found ++; \
36
- } \
30
+ #define STEP_0 (i ) \
31
+ { \
32
+ if (unlikely(F[0] == 0)) { \
33
+ candidates[numCandidates ].intIndex = i; \
34
+ candidates[numCandidates ].mask = 0x000f; \
35
+ numCandidates ++; \
36
+ } \
37
37
}
38
- #define STEP_1 (a , i ) \
39
- { \
40
- F[0] ^= F[a]; \
41
- if (unlikely(F[0] == 0)) { \
42
- solution_buffer[n_solutions_found ].intIndex = i; \
43
- solution_buffer[n_solutions_found ].mask = 0x000f; \
44
- n_solutions_found ++; \
45
- } \
38
+ #define STEP_1 (a , i ) \
39
+ { \
40
+ F[0] ^= F[a]; \
41
+ if (unlikely(F[0] == 0)) { \
42
+ candidates[numCandidates ].intIndex = i; \
43
+ candidates[numCandidates ].mask = 0x000f; \
44
+ numCandidates ++; \
45
+ } \
46
46
}
47
- #define STEP_2 (a , b , i ) \
48
- { \
49
- F[a] ^= F[b]; \
50
- F[0] ^= F[a]; \
51
- if (unlikely(F[0] == 0)) { \
52
- solution_buffer[n_solutions_found ].intIndex = i; \
53
- solution_buffer[n_solutions_found ].mask = 0x000f; \
54
- n_solutions_found ++; \
55
- } \
47
+ #define STEP_2 (a , b , i ) \
48
+ { \
49
+ F[a] ^= F[b]; \
50
+ F[0] ^= F[a]; \
51
+ if (unlikely(F[0] == 0)) { \
52
+ candidates[numCandidates ].intIndex = i; \
53
+ candidates[numCandidates ].mask = 0x000f; \
54
+ numCandidates ++; \
55
+ } \
56
56
}
57
57
58
58
typedef uint32_t TableInteger ;
@@ -141,16 +141,16 @@ int exfes(uint32_t numFixedVariables, uint32_t numVariables, uint32_t numEquatio
141
141
if (!(solutionHigh && solutionLow )) {
142
142
return -3 ;
143
143
}
144
- Settings exfes_ctx ;
145
- exfes_ctx .numFixedVariables = m ;
146
- exfes_ctx .numVariables = n ;
147
- exfes_ctx .partialSolution = 0 ;
148
- exfes_ctx .solutionCount = 0 ;
149
- exfes_ctx .startPointHigh = startPointHigh ;
150
- exfes_ctx .startPointLow = startPointLow ;
151
- exfes_ctx .solutionHigh = solutionHigh ;
152
- exfes_ctx .solutionLow = solutionLow ;
153
- exfes_ctx .shouldAbortNow = shouldAbortNow ;
144
+ Settings settings ;
145
+ settings .numFixedVariables = m ;
146
+ settings .numVariables = n ;
147
+ settings .partialSolution = 0 ;
148
+ settings .solutionCount = 0 ;
149
+ settings .startPointHigh = startPointHigh ;
150
+ settings .startPointLow = startPointLow ;
151
+ settings .solutionHigh = solutionHigh ;
152
+ settings .solutionLow = solutionLow ;
153
+ settings .shouldAbortNow = shouldAbortNow ;
154
154
int * * * Eqs ;
155
155
if (initEqs (n , e , & Eqs ) != 0 ) {
156
156
return -4 ;
@@ -178,7 +178,7 @@ int exfes(uint32_t numFixedVariables, uint32_t numVariables, uint32_t numEquatio
178
178
int p = n - m ;
179
179
int npartial ;
180
180
int fixvalue ;
181
- for (exfes_ctx .partialSolution = 0 ; exfes_ctx .partialSolution < (uint64_t )1 << m ; exfes_ctx .partialSolution ++ ) {
181
+ for (settings .partialSolution = 0 ; settings .partialSolution < (uint64_t )1 << m ; settings .partialSolution ++ ) {
182
182
npartial = n ;
183
183
for (int i = 0 ; i < e ; i ++ ) {
184
184
for (int j = 0 ; j < 3 ; j ++ ) {
@@ -188,7 +188,7 @@ int exfes(uint32_t numFixedVariables, uint32_t numVariables, uint32_t numEquatio
188
188
}
189
189
}
190
190
while (npartial != p ) {
191
- fixvalue = (exfes_ctx .partialSolution >> (n - npartial )) & 1 ;
191
+ fixvalue = (settings .partialSolution >> (n - npartial )) & 1 ;
192
192
for (int i = 0 ; i < e ; i ++ ) {
193
193
for (int j = 0 ; j < npartial - 1 ; j ++ ) {
194
194
EqsCopy [i ][1 ][j + 1 ] ^= EqsCopy [i ][2 ][j ] & fixvalue ;
@@ -203,23 +203,23 @@ int exfes(uint32_t numFixedVariables, uint32_t numVariables, uint32_t numEquatio
203
203
}
204
204
npartial -= 1 ;
205
205
}
206
- if (fes (npartial , e , EqsCopy , & exfes_ctx ) != 0 ) {
206
+ if (fes (npartial , e , EqsCopy , & settings ) != 0 ) {
207
207
freeEqs (EqsCopy , e , -1 );
208
208
freeEqs (Eqs , e , -1 );
209
209
return -4 ;
210
210
}
211
- if (exfes_ctx .solutionCount == 1 ) {
211
+ if (settings .solutionCount == 1 ) {
212
212
break ;
213
213
}
214
- if (exfes_ctx .solutionCount == 2 ) {
214
+ if (settings .solutionCount == 2 ) {
215
215
break ;
216
216
}
217
217
}
218
218
freeEqs (EqsCopy , e , -1 );
219
219
freeEqs (Eqs , e , -1 );
220
- if (exfes_ctx .solutionCount == 1 ) {
220
+ if (settings .solutionCount == 1 ) {
221
221
return 0 ;
222
- } else if (exfes_ctx .solutionCount == 0 ) {
222
+ } else if (settings .solutionCount == 0 ) {
223
223
return -1 ;
224
224
} else {
225
225
return -2 ;
@@ -595,23 +595,23 @@ static int fes(const int n, int n_eqs, int ***coeffs, Settings *settings)
595
595
return 0 ;
596
596
}
597
597
598
- static void primarySearch (Table LUT , int n , PackedVectors * F , States * States )
598
+ static void primarySearch (Table table , int n , PackedVectors * F , States * States )
599
599
{
600
- Settings * ctx = States -> settings ;
600
+ Settings * settings = States -> settings ;
601
601
for (int i0 = 1 ; i0 < n ; i0 ++ ) {
602
602
if (i0 != 0 ) {
603
- F [idx_1 (LUT , i0 )] ^= F [idx_2 (LUT , i0 - 1 , i0 )];
603
+ F [idx_1 (table , i0 )] ^= F [idx_2 (table , i0 - 1 , i0 )];
604
604
}
605
605
}
606
- uint64_t n_solutions_found = 0 ;
607
- uint64_t current_solution_index = 0 ;
608
- uint64_t packVectors_of_solution [1 ];
609
- Candidate solution_buffer [516 ];
606
+ uint64_t numCandidates = 0 ;
607
+ uint64_t currentCandidateIndex = 0 ;
608
+ uint64_t solution [1 ];
609
+ Candidate candidates [516 ];
610
610
const uint64_t weight_0_start = 0 ;
611
611
STEP_0 (0 );
612
612
for (int idx_0 = 0 ; idx_0 < n ; idx_0 ++ ) {
613
613
const uint64_t weight_1_start = weight_0_start + (1ULL << idx_0 );
614
- STEP_1 (idx_1 (LUT , idx_0 ), weight_1_start );
614
+ STEP_1 (idx_1 (table , idx_0 ), weight_1_start );
615
615
const uint64_t rolled_end = weight_1_start + (1ULL << min (9 , idx_0 ));
616
616
for (uint64_t i = 1 + weight_1_start ; i < rolled_end ; i ++ ) {
617
617
int pos = 0 ;
@@ -628,12 +628,12 @@ static void primarySearch(Table LUT, int n, PackedVectors *F, States *States)
628
628
pos ++ ;
629
629
}
630
630
const int k_2 = pos ;
631
- STEP_2 (idx_1 (LUT , k_1 ), idx_2 (LUT , k_1 , k_2 ), i );
631
+ STEP_2 (idx_1 (table , k_1 ), idx_2 (table , k_1 , k_2 ), i );
632
632
}
633
633
CHECK_SOLUTIONS ();
634
634
for (uint64_t j = 512 ; j < (1ull << idx_0 ); j += 512 ) {
635
- if (ctx -> shouldAbortNow ()) {
636
- ctx -> solutionCount = 2 ;
635
+ if (settings -> shouldAbortNow ()) {
636
+ settings -> solutionCount = 2 ;
637
637
return ;
638
638
}
639
639
const uint64_t i = j + weight_1_start ;
@@ -651,8 +651,8 @@ static void primarySearch(Table LUT, int n, PackedVectors *F, States *States)
651
651
pos ++ ;
652
652
}
653
653
const int k_2 = pos ;
654
- const int alpha = LUT [0 ][k_1 ];
655
- const int beta = LUT [1 ][k_1 ] + LUT [0 ][k_2 ];
654
+ const int alpha = table [0 ][k_1 ];
655
+ const int beta = table [1 ][k_1 ] + table [0 ][k_2 ];
656
656
STEP_2 (0 + alpha , 0 + beta , i + 0 );
657
657
STEP_2 (1 , 1 + alpha , i + 1 );
658
658
STEP_2 (2 , 2 + alpha , i + 2 );
@@ -1168,5 +1168,5 @@ static void primarySearch(Table LUT, int n, PackedVectors *F, States *States)
1168
1168
CHECK_SOLUTIONS ();
1169
1169
}
1170
1170
}
1171
- testSolution (States , current_solution_index , packVectors_of_solution );
1171
+ testSolution (States , currentCandidateIndex , solution );
1172
1172
}
0 commit comments