aboutsummaryrefslogtreecommitdiffstats
path: root/modules
diff options
context:
space:
mode:
authorlloyd <[email protected]>2006-09-24 16:00:59 +0000
committerlloyd <[email protected]>2006-09-24 16:00:59 +0000
commit5d2328198dd9264990dcc51ce0617f1a1142c4c8 (patch)
tree1bcd1e26394a01378c7566ff27759514ed079831 /modules
parent877f1a962e2b4b57dbef914eda3ef9b40a771b55 (diff)
Better instruction scheduling, some higher level macros for readability
Diffstat (limited to 'modules')
-rw-r--r--modules/alg_amd64/asm_macr.h3
-rw-r--r--modules/alg_amd64/mp_muladd.S24
2 files changed, 18 insertions, 9 deletions
diff --git a/modules/alg_amd64/asm_macr.h b/modules/alg_amd64/asm_macr.h
index 689bfa3cb..93b675858 100644
--- a/modules/alg_amd64/asm_macr.h
+++ b/modules/alg_amd64/asm_macr.h
@@ -67,6 +67,7 @@ func_name:
#define IMM(VAL) $VAL
#define ADD(TO, FROM) addq FROM, TO
+#define ADD_LAST_CARRY(REG) adcq IMM(0), REG
#define ADD_IMM(TO, NUM) ADD(TO, IMM(NUM))
#define ADD_W_CARRY(TO1, TO2, FROM) addq FROM, TO1; adcq IMM(0), TO2;
#define SUB_IMM(TO, NUM) sub IMM(NUM), TO
@@ -78,4 +79,6 @@ func_name:
#define NOT(REG) notq REG
#define ZEROIZE(REG) XOR(REG, REG)
+#define RETURN_VALUE_IS(V) ASSIGN(%rax, V)
+
#endif
diff --git a/modules/alg_amd64/mp_muladd.S b/modules/alg_amd64/mp_muladd.S
index e34b855bb..71477cf2b 100644
--- a/modules/alg_amd64/mp_muladd.S
+++ b/modules/alg_amd64/mp_muladd.S
@@ -8,11 +8,15 @@
START_LISTING(mp_muladd.S)
START_FUNCTION(bigint_mul_add_words)
+
#define LOOP_CTR %r11d
#define X_ARR %rsi
#define Z_ARR %rdi
#define Y %rcx
#define CARRY %r8
+#define Z_WORD %r9
+#define MUL_LO %rax
+#define MUL_HI %rdx
ZEROIZE(CARRY)
@@ -21,14 +25,16 @@ START_FUNCTION(bigint_mul_add_words)
JUMP_IF_ZERO(LOOP_CTR, .DONE)
JUMP_IF_LT(LOOP_CTR, 8, .MULADD1_LOOP)
-#define MULADD_OP(N) \
- ASSIGN(%rax, ARRAY8(X_ARR, N)) ; \
- ASSIGN(%r9, ARRAY8(Z_ARR, N)) ; \
- MUL(Y) ; \
- ADD_W_CARRY(%rax, %rdx, CARRY) ; \
- ADD_W_CARRY(%rax, %rdx, %r9) ; \
- ASSIGN(CARRY, %rdx) ; \
- ASSIGN(ARRAY8(Z_ARR, N), %rax)
+#define MULADD_OP(N) \
+ ASSIGN(MUL_LO, ARRAY8(X_ARR, N)) ; \
+ ASSIGN(Z_WORD, ARRAY8(Z_ARR, N)) ; \
+ MUL(Y) ; \
+ ADD(Z_WORD, CARRY) ; \
+ ASSIGN(CARRY, MUL_HI) ; \
+ ADD_LAST_CARRY(CARRY) ; \
+ ADD(Z_WORD, MUL_LO) ; \
+ ADD_LAST_CARRY(CARRY) ; \
+ ASSIGN(ARRAY8(Z_ARR, N), Z_WORD)
START_LOOP(.MULADD8)
MULADD_OP(0)
@@ -56,5 +62,5 @@ START_LOOP(.MULADD1)
LOOP_UNTIL_EQ(LOOP_CTR, 0, .MULADD1)
.DONE:
- ASSIGN(%rax, CARRY)
+ RETURN_VALUE_IS(CARRY)
END_FUNCTION(bigint_mul_add_words)