Skip to content

Commit 21452ea

Browse files
authored
Simplifying the check that the address is 4-byte aligned. (#2513)
Not much better than the original check, as it still allows for greater than 2**32 values, but at least it uses two fewer variables.
1 parent 0569c3f commit 21452ea

File tree

1 file changed

+12
-24
lines changed

1 file changed

+12
-24
lines changed

Diff for: riscv/src/large_field/runtime.rs

+12-24
Original file line numberDiff line numberDiff line change
@@ -172,12 +172,9 @@ impl Runtime {
172172
link ~> tmp2_col = regs.mload(Y, STEP + 1)
173173
link ~> keccakf.keccakf32_memory(tmp1_col, tmp2_col, STEP)
174174
{
175-
// make sure tmp1_col and tmp2_col are aligned memory addresses
176-
tmp3_col * 4 = tmp1_col,
177-
tmp4_col * 4 = tmp2_col,
178-
// make sure the factors fit in 32 bits
179-
tmp3_col = X_b1 + X_b2 * 0x100 + X_b3 * 0x10000 + X_b4 * 0x1000000,
180-
tmp4_col = Y_b5 + Y_b6 * 0x100 + Y_b7 * 0x10000 + Y_b8 * 0x1000000
175+
// make sure tmp1_col and tmp2_col are 4-byte aligned memory addresses
176+
tmp1_col = 4 * (X_b1 + X_b2 * 0x100 + X_b3 * 0x10000 + X_b4 * 0x1000000),
177+
tmp2_col = 4 * (Y_b5 + Y_b6 * 0x100 + Y_b7 * 0x10000 + Y_b8 * 0x1000000)
181178
}
182179
"#
183180
.to_string()],
@@ -257,12 +254,9 @@ impl Runtime {
257254
link ~> tmp2_col = regs.mload(Y, STEP + 1)
258255
link ~> poseidon_gl.poseidon_permutation(tmp1_col, tmp2_col, STEP)
259256
{
260-
// make sure tmp1_col and tmp2_col are aligned memory addresses
261-
tmp3_col * 4 = tmp1_col,
262-
tmp4_col * 4 = tmp2_col,
263-
// make sure the factors fit in 32 bits
264-
tmp3_col = X_b1 + X_b2 * 0x100 + X_b3 * 0x10000 + X_b4 * 0x1000000,
265-
tmp4_col = Y_b5 + Y_b6 * 0x100 + Y_b7 * 0x10000 + Y_b8 * 0x1000000
257+
// make sure tmp1_col and tmp2_col are 4-byte aligned memory addresses
258+
tmp1_col = 4 * (X_b1 + X_b2 * 0x100 + X_b3 * 0x10000 + X_b4 * 0x1000000),
259+
tmp2_col = 4 * (Y_b5 + Y_b6 * 0x100 + Y_b7 * 0x10000 + Y_b8 * 0x1000000)
266260
}
267261
"#],
268262
);
@@ -288,12 +282,9 @@ impl Runtime {
288282
link ~> tmp2_col = regs.mload(Y, STEP + 1)
289283
link ~> poseidon2_gl.poseidon2_permutation(tmp1_col, tmp2_col, STEP)
290284
{
291-
// make sure tmp1_col and tmp2_col are aligned memory addresses
292-
tmp3_col * 4 = tmp1_col,
293-
tmp4_col * 4 = tmp2_col,
294-
// make sure the addresses are 32 bits
295-
tmp3_col = X_b1 + X_b2 * 0x100 + X_b3 * 0x10000 + X_b4 * 0x1000000,
296-
tmp4_col = Y_b5 + Y_b6 * 0x100 + Y_b7 * 0x10000 + Y_b8 * 0x1000000
285+
// make sure tmp1_col and tmp2_col are 4-byte aligned memory addresses
286+
tmp1_col = 4 * (X_b1 + X_b2 * 0x100 + X_b3 * 0x10000 + X_b4 * 0x1000000),
287+
tmp2_col = 4 * (Y_b5 + Y_b6 * 0x100 + Y_b7 * 0x10000 + Y_b8 * 0x1000000)
297288
}
298289
"#],
299290
);
@@ -309,12 +300,9 @@ impl Runtime {
309300
link ~> tmp2_col = regs.mload(Y, STEP + 1)
310301
link ~> split_gl_vec.split(tmp1_col, tmp2_col, STEP + 2)
311302
{
312-
// make sure tmp1_col and tmp2_col are aligned memory addresses
313-
tmp3_col * 4 = tmp1_col,
314-
tmp4_col * 4 = tmp2_col,
315-
// make sure the addresses are 32 bits
316-
tmp3_col = X_b1 + X_b2 * 0x100 + X_b3 * 0x10000 + X_b4 * 0x1000000,
317-
tmp4_col = Y_b5 + Y_b6 * 0x100 + Y_b7 * 0x10000 + Y_b8 * 0x1000000
303+
// make sure tmp1_col and tmp2_col are 4-byte aligned memory addresses
304+
tmp1_col = 4 * (X_b1 + X_b2 * 0x100 + X_b3 * 0x10000 + X_b4 * 0x1000000),
305+
tmp2_col = 4 * (Y_b5 + Y_b6 * 0x100 + Y_b7 * 0x10000 + Y_b8 * 0x1000000)
318306
}
319307
"#,
320308
r#"

0 commit comments

Comments
 (0)