Botan 1.10.17

mp_asm.h
Go to the documentation of this file.
1 /*
2 * Lowest Level MPI Algorithms
3 * (C) 1999-2008 Jack Lloyd
4 * 2006 Luca Piccarreta
5 *
6 * Distributed under the terms of the Botan license
7 */
8
9 #ifndef BOTAN_MP_ASM_H__
10 #define BOTAN_MP_ASM_H__
11
12 #include <botan/mp_types.h>
13
14 #if (BOTAN_MP_WORD_BITS != 64)
15 #error The mp_x86_64 module requires that BOTAN_MP_WORD_BITS == 64
16 #endif
17
18 namespace Botan {
19
20 extern "C" {
21
22 /*
23 * Helper Macros for x86-64 Assembly
24 */
25 #define ASM(x) x "\n\t"
26
27 /*
28 * Word Multiply
29 */
30 inline word word_madd2(word a, word b, word* c)
31 {
32 asm(
33 ASM("mulq %[b]")
34 ASM("addq %[c],%[a]")
35 ASM("adcq $0,%[carry]")
36
37 : [a]"=a"(a), [b]"=rm"(b), [carry]"=&d"(*c)
38 : "0"(a), "1"(b), [c]"g"(*c) : "cc");
39
40 return a;
41 }
42
43 /*
44 * Word Multiply/Add
45 */
46 inline word word_madd3(word a, word b, word c, word* d)
47 {
48 asm(
49 ASM("mulq %[b]")
50
51 ASM("addq %[c],%[a]")
52 ASM("adcq $0,%[carry]")
53
54 ASM("addq %[d],%[a]")
55 ASM("adcq $0,%[carry]")
56
57 : [a]"=a"(a), [b]"=rm"(b), [carry]"=&d"(*d)
58 : "0"(a), "1"(b), [c]"g"(c), [d]"g"(*d) : "cc");
59
60 return a;
61 }
62
63 #undef ASM
64
65 }
66
67 }
68
69 #endif
Botan::word_madd3
word word_madd3(word a, word b, word c, word *d)
Definition: mp_asm.h:102
Botan::word_madd2
word word_madd2(word a, word b, word *c)
Definition: mp_asm.h:86
ASM
#define ASM(x)
Definition: mp_asm.h:25
Botan
Definition: algo_base.h:14