Skip to content

Commit c20efea

Browse files
author
YuanChe Hsu
committed
Rename variables in the function primarySearch().
1 parent 7375a0a commit c20efea

File tree

1 file changed

+73
-73
lines changed

1 file changed

+73
-73
lines changed

lib/exfes.c

+73-73
Original file line numberDiff line numberDiff line change
@@ -7,52 +7,52 @@
77
#define idx_2(LUT, i1, i0) (idx_1(LUT, i0) + (LUT)[1][i1])
88
#define min(x, y) (((x) > (y)) ? (y) : (x))
99
#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+
} \
2020
}
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; \
2929
}
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+
} \
3737
}
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+
} \
4646
}
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+
} \
5656
}
5757

5858
typedef uint32_t TableInteger;
@@ -141,16 +141,16 @@ int exfes(uint32_t numFixedVariables, uint32_t numVariables, uint32_t numEquatio
141141
if (!(solutionHigh && solutionLow)) {
142142
return -3;
143143
}
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;
154154
int ***Eqs;
155155
if (initEqs(n, e, &Eqs) != 0) {
156156
return -4;
@@ -178,7 +178,7 @@ int exfes(uint32_t numFixedVariables, uint32_t numVariables, uint32_t numEquatio
178178
int p = n - m;
179179
int npartial;
180180
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++) {
182182
npartial = n;
183183
for (int i = 0; i < e; i++) {
184184
for (int j = 0; j < 3; j++) {
@@ -188,7 +188,7 @@ int exfes(uint32_t numFixedVariables, uint32_t numVariables, uint32_t numEquatio
188188
}
189189
}
190190
while (npartial != p) {
191-
fixvalue = (exfes_ctx.partialSolution >> (n - npartial)) & 1;
191+
fixvalue = (settings.partialSolution >> (n - npartial)) & 1;
192192
for (int i = 0; i < e; i++) {
193193
for (int j = 0; j < npartial - 1; j++) {
194194
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
203203
}
204204
npartial -= 1;
205205
}
206-
if (fes(npartial, e, EqsCopy, &exfes_ctx) != 0) {
206+
if (fes(npartial, e, EqsCopy, &settings) != 0) {
207207
freeEqs(EqsCopy, e, -1);
208208
freeEqs(Eqs, e, -1);
209209
return -4;
210210
}
211-
if (exfes_ctx.solutionCount == 1) {
211+
if (settings.solutionCount == 1) {
212212
break;
213213
}
214-
if (exfes_ctx.solutionCount == 2) {
214+
if (settings.solutionCount == 2) {
215215
break;
216216
}
217217
}
218218
freeEqs(EqsCopy, e, -1);
219219
freeEqs(Eqs, e, -1);
220-
if (exfes_ctx.solutionCount == 1) {
220+
if (settings.solutionCount == 1) {
221221
return 0;
222-
} else if (exfes_ctx.solutionCount == 0) {
222+
} else if (settings.solutionCount == 0) {
223223
return -1;
224224
} else {
225225
return -2;
@@ -595,23 +595,23 @@ static int fes(const int n, int n_eqs, int ***coeffs, Settings *settings)
595595
return 0;
596596
}
597597

598-
static void primarySearch(Table LUT, int n, PackedVectors *F, States *States)
598+
static void primarySearch(Table table, int n, PackedVectors *F, States *States)
599599
{
600-
Settings *ctx = States->settings;
600+
Settings *settings = States->settings;
601601
for (int i0 = 1; i0 < n; i0++) {
602602
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)];
604604
}
605605
}
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];
610610
const uint64_t weight_0_start = 0;
611611
STEP_0(0);
612612
for (int idx_0 = 0; idx_0 < n; idx_0++) {
613613
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);
615615
const uint64_t rolled_end = weight_1_start + (1ULL << min(9, idx_0));
616616
for (uint64_t i = 1 + weight_1_start; i < rolled_end; i++) {
617617
int pos = 0;
@@ -628,12 +628,12 @@ static void primarySearch(Table LUT, int n, PackedVectors *F, States *States)
628628
pos++;
629629
}
630630
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);
632632
}
633633
CHECK_SOLUTIONS();
634634
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;
637637
return;
638638
}
639639
const uint64_t i = j + weight_1_start;
@@ -651,8 +651,8 @@ static void primarySearch(Table LUT, int n, PackedVectors *F, States *States)
651651
pos++;
652652
}
653653
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];
656656
STEP_2(0 + alpha, 0 + beta, i + 0);
657657
STEP_2(1, 1 + alpha, i + 1);
658658
STEP_2(2, 2 + alpha, i + 2);
@@ -1168,5 +1168,5 @@ static void primarySearch(Table LUT, int n, PackedVectors *F, States *States)
11681168
CHECK_SOLUTIONS();
11691169
}
11701170
}
1171-
testSolution(States, current_solution_index, packVectors_of_solution);
1171+
testSolution(States, currentCandidateIndex, solution);
11721172
}

0 commit comments

Comments
 (0)