aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJack Lloyd <[email protected]>2021-05-01 10:55:44 -0400
committerJack Lloyd <[email protected]>2021-05-01 10:55:44 -0400
commit82a47c40d4c2cf02ba7a97c3e1478f9ebc08021c (patch)
tree6ecc25759256678187ceec2f7708e43c5fb8eeba
parentc4737db1b763a339c54e74f85df89336833b4a42 (diff)
Disable word_sub bypass for unrolled Montgomery redc
-rw-r--r--src/lib/math/mp/mp_monty_n.cpp27
-rwxr-xr-xsrc/scripts/monty.py2
2 files changed, 4 insertions, 25 deletions
diff --git a/src/lib/math/mp/mp_monty_n.cpp b/src/lib/math/mp/mp_monty_n.cpp
index c9c016322..d58889112 100644
--- a/src/lib/math/mp/mp_monty_n.cpp
+++ b/src/lib/math/mp/mp_monty_n.cpp
@@ -56,12 +56,7 @@ void bigint_monty_redc_4(word z[], const word p[4], word p_dash, word ws[])
word3_add(&w2, &w1, &w0, z[9]);
ws[4] = w0;
ws[5] = w1;
- word borrow = 0;
- ws[5] = word_sub(ws[0], p[0], &borrow);
- ws[6] = word_sub(ws[1], p[1], &borrow);
- ws[7] = word_sub(ws[2], p[2], &borrow);
- ws[8] = word_sub(ws[3], p[3], &borrow);
- ws[9] = word_sub(ws[4], 0, &borrow);
+ word borrow = bigint_sub3(ws + 4 + 1, ws, 4 + 1, p, 4);
CT::conditional_copy_mem(borrow, z, ws, ws + 5, 5);
clear_mem(z + 4, 2*(4+1) - 4);
}
@@ -144,14 +139,7 @@ void bigint_monty_redc_6(word z[], const word p[6], word p_dash, word ws[])
word3_add(&w2, &w1, &w0, z[13]);
ws[6] = w0;
ws[7] = w1;
- word borrow = 0;
- ws[7] = word_sub(ws[0], p[0], &borrow);
- ws[8] = word_sub(ws[1], p[1], &borrow);
- ws[9] = word_sub(ws[2], p[2], &borrow);
- ws[10] = word_sub(ws[3], p[3], &borrow);
- ws[11] = word_sub(ws[4], p[4], &borrow);
- ws[12] = word_sub(ws[5], p[5], &borrow);
- ws[13] = word_sub(ws[6], 0, &borrow);
+ word borrow = bigint_sub3(ws + 6 + 1, ws, 6 + 1, p, 6);
CT::conditional_copy_mem(borrow, z, ws, ws + 7, 7);
clear_mem(z + 6, 2*(6+1) - 6);
}
@@ -274,16 +262,7 @@ void bigint_monty_redc_8(word z[], const word p[8], word p_dash, word ws[])
word3_add(&w2, &w1, &w0, z[17]);
ws[8] = w0;
ws[9] = w1;
- word borrow = 0;
- ws[9] = word_sub(ws[0], p[0], &borrow);
- ws[10] = word_sub(ws[1], p[1], &borrow);
- ws[11] = word_sub(ws[2], p[2], &borrow);
- ws[12] = word_sub(ws[3], p[3], &borrow);
- ws[13] = word_sub(ws[4], p[4], &borrow);
- ws[14] = word_sub(ws[5], p[5], &borrow);
- ws[15] = word_sub(ws[6], p[6], &borrow);
- ws[16] = word_sub(ws[7], p[7], &borrow);
- ws[17] = word_sub(ws[8], 0, &borrow);
+ word borrow = bigint_sub3(ws + 8 + 1, ws, 8 + 1, p, 8);
CT::conditional_copy_mem(borrow, z, ws, ws + 9, 9);
clear_mem(z + 8, 2*(8+1) - 8);
}
diff --git a/src/scripts/monty.py b/src/scripts/monty.py
index 4ffd87317..d999ce58c 100755
--- a/src/scripts/monty.py
+++ b/src/scripts/monty.py
@@ -42,7 +42,7 @@ def monty_redc_code(n):
lines.append("ws[%d] = w0;" % (n))
lines.append("ws[%d] = w1;" % (n+1))
- if n < 16:
+ if False and n < 16:
lines.append("word borrow = 0;")
for i in range(n):
lines.append("ws[%d] = word_sub(ws[%d], p[%d], &borrow);" % (n + 1 + i, i, i))