aboutsummaryrefslogtreecommitdiffstats
path: root/modules/alg_amd64/mp_mulop.S
blob: ebd6aa8c0131a4e1356b52a134731a8c07a1fe33 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
/*************************************************
* Multiply/Add Algorithm Source File             *
* (C) 1999-2007 The Botan Project                *
*************************************************/

#include <botan/asm_macr.h>

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)

   ASSIGN(LOOP_CTR, %edx)

   JUMP_IF_ZERO(LOOP_CTR, .DONE)
   JUMP_IF_LT(LOOP_CTR, 8, .MULADD1_LOOP)

#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)
   MULADD_OP(1)
   MULADD_OP(2)
   MULADD_OP(3)
   MULADD_OP(4)
   MULADD_OP(5)
   MULADD_OP(6)
   MULADD_OP(7)

   SUB_IMM(LOOP_CTR, 8)
   ADD_IMM(Z_ARR, 64)
   ADD_IMM(X_ARR, 64)
LOOP_UNTIL_LT(LOOP_CTR, 8, .MULADD8)

   JUMP_IF_ZERO(LOOP_CTR, .DONE)

START_LOOP(.MULADD1)
   MULADD_OP(0)

   SUB_IMM(LOOP_CTR, 1)
   ADD_IMM(Z_ARR, 8)
   ADD_IMM(X_ARR, 8)
LOOP_UNTIL_EQ(LOOP_CTR, 0, .MULADD1)

.DONE:
   RETURN_VALUE_IS(CARRY)
END_FUNCTION(bigint_mul_add_words)