f0660525e0e15ee18088cc7ac961b3003f6cf04b
[platform/upstream/nettle.git] / x86_64 / ecc-192-modp.asm
1 C x86_64/ecc-192-modp.asm
2
3 ifelse(<
4    Copyright (C) 2013 Niels Möller
5
6    This file is part of GNU Nettle.
7
8    GNU Nettle is free software: you can redistribute it and/or
9    modify it under the terms of either:
10
11      * the GNU Lesser General Public License as published by the Free
12        Software Foundation; either version 3 of the License, or (at your
13        option) any later version.
14
15    or
16
17      * the GNU General Public License as published by the Free
18        Software Foundation; either version 2 of the License, or (at your
19        option) any later version.
20
21    or both in parallel, as here.
22
23    GNU Nettle is distributed in the hope that it will be useful,
24    but WITHOUT ANY WARRANTY; without even the implied warranty of
25    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
26    General Public License for more details.
27
28    You should have received copies of the GNU General Public License and
29    the GNU Lesser General Public License along with this program.  If
30    not, see http://www.gnu.org/licenses/.
31 >)
32
33         .file "ecc-192-modp.asm"
34
35 define(<RP>, <%rsi>)
36 define(<T0>, <%rdi>) C Overlaps unused modulo input
37 define(<T1>, <%rcx>)
38 define(<T2>, <%rdx>)
39 define(<T3>, <%r8>)
40 define(<H>, <%r9>)
41 define(<C1>, <%r10>)
42 define(<C2>, <%r11>)
43
44         C ecc_192_modp (const struct ecc_modulo *m, mp_limb_t *rp)
45         .text
46         ALIGN(16)
47 PROLOGUE(nettle_ecc_192_modp)
48         W64_ENTRY(2, 0)
49         mov     16(RP), T2
50         mov     24(RP), T3
51         mov     40(RP), H
52         xor     C1, C1
53         xor     C2, C2
54
55         add     H, T2
56         adc     H, T3
57         C Carry to be added in at T1 and T2
58         setc    LREG(C2)
59         
60         mov     8(RP), T1
61         mov     32(RP), H
62         adc     H, T1
63         adc     H, T2
64         C Carry to be added in at T0 and T1
65         setc    LREG(C1)
66         
67         mov     (RP), T0
68         adc     T3, T0
69         adc     T3, T1
70         adc     $0, C2
71
72         C Add in C1 and C2
73         add     C1, T1
74         adc     C2, T2
75         setc    LREG(C1)
76
77         C Fold final carry.
78         adc     $0, T0
79         adc     C1, T1
80         adc     $0, T2
81
82         mov     T0, (RP)
83         mov     T1, 8(RP)
84         mov     T2, 16(RP)
85
86         W64_EXIT(2, 0)
87         ret
88 EPILOGUE(nettle_ecc_192_modp)