aboutsummaryrefslogtreecommitdiffstats
path: root/src/lib/math
diff options
context:
space:
mode:
authorJack Lloyd <[email protected]>2019-05-03 10:13:59 -0400
committerJack Lloyd <[email protected]>2019-05-03 10:15:47 -0400
commit02ac4c591f34881a1206d2a56d78cb5423b231ad (patch)
tree43f2c7153120c5d4a43f867222ec4e3f416c1e41 /src/lib/math
parent00c9c6612c8e1ffaa54a45429baf104ecf658df8 (diff)
Use C++ raw strings in inline asm
Diffstat (limited to 'src/lib/math')
-rw-r--r--src/lib/math/mp/mp_asmi.h78
-rw-r--r--src/lib/math/mp/mp_madd.h58
2 files changed, 64 insertions, 72 deletions
diff --git a/src/lib/math/mp/mp_asmi.h b/src/lib/math/mp/mp_asmi.h
index 1b332811f..c99d8b7e5 100644
--- a/src/lib/math/mp/mp_asmi.h
+++ b/src/lib/math/mp/mp_asmi.h
@@ -719,15 +719,16 @@ inline void word3_muladd(word* w2, word* w1, word* w0, word x, word y)
#if defined(BOTAN_MP_USE_X86_32_ASM)
word z0 = 0, z1 = 0;
- asm ("mull %[y]"
+ asm("mull %[y]"
: "=a"(z0),"=d"(z1)
: "a"(x), [y]"rm"(y)
: "cc");
- asm(ASM("addl %[z0],%[w0]")
- ASM("adcl %[z1],%[w1]")
- ASM("adcl $0,%[w2]")
-
+ asm(R"(
+ addl %[z0],%[w0]
+ adcl %[z1],%[w1]
+ adcl $0,%[w2]
+ )"
: [w0]"=r"(*w0), [w1]"=r"(*w1), [w2]"=r"(*w2)
: [z0]"r"(z0), [z1]"r"(z1), "0"(*w0), "1"(*w1), "2"(*w2)
: "cc");
@@ -736,15 +737,16 @@ inline void word3_muladd(word* w2, word* w1, word* w0, word x, word y)
word z0 = 0, z1 = 0;
- asm ("mulq %[y]"
+ asm("mulq %[y]"
: "=a"(z0),"=d"(z1)
: "a"(x), [y]"rm"(y)
: "cc");
- asm(ASM("addq %[z0],%[w0]")
- ASM("adcq %[z1],%[w1]")
- ASM("adcq $0,%[w2]")
-
+ asm(R"(
+ addq %[z0],%[w0]
+ adcq %[z1],%[w1]
+ adcq $0,%[w2]
+ )"
: [w0]"=r"(*w0), [w1]"=r"(*w1), [w2]"=r"(*w2)
: [z0]"r"(z0), [z1]"r"(z1), "0"(*w0), "1"(*w1), "2"(*w2)
: "cc");
@@ -764,22 +766,22 @@ inline void word3_muladd(word* w2, word* w1, word* w0, word x, word y)
inline void word3_add(word* w2, word* w1, word* w0, word x)
{
#if defined(BOTAN_MP_USE_X86_32_ASM)
- asm(
- ASM("addl %[x],%[w0]")
- ASM("adcl $0,%[w1]")
- ASM("adcl $0,%[w2]")
-
+ asm(R"(
+ addl %[x],%[w0]
+ adcl $0,%[w1]
+ adcl $0,%[w2]
+ )"
: [w0]"=r"(*w0), [w1]"=r"(*w1), [w2]"=r"(*w2)
: [x]"r"(x), "0"(*w0), "1"(*w1), "2"(*w2)
: "cc");
#elif defined(BOTAN_MP_USE_X86_64_ASM)
- asm(
- ASM("addq %[x],%[w0]")
- ASM("adcq $0,%[w1]")
- ASM("adcq $0,%[w2]")
-
+ asm(R"(
+ addq %[x],%[w0]
+ adcq $0,%[w1]
+ adcq $0,%[w2]
+ )"
: [w0]"=r"(*w0), [w1]"=r"(*w1), [w2]"=r"(*w2)
: [x]"r"(x), "0"(*w0), "1"(*w1), "2"(*w2)
: "cc");
@@ -803,20 +805,20 @@ inline void word3_muladd_2(word* w2, word* w1, word* w0, word x, word y)
word z0 = 0, z1 = 0;
- asm ("mull %[y]"
+ asm("mull %[y]"
: "=a"(z0),"=d"(z1)
: "a"(x), [y]"rm"(y)
: "cc");
- asm(
- ASM("addl %[z0],%[w0]")
- ASM("adcl %[z1],%[w1]")
- ASM("adcl $0,%[w2]")
-
- ASM("addl %[z0],%[w0]")
- ASM("adcl %[z1],%[w1]")
- ASM("adcl $0,%[w2]")
+ asm(R"(
+ addl %[z0],%[w0]
+ adcl %[z1],%[w1]
+ adcl $0,%[w2]
+ addl %[z0],%[w0]
+ adcl %[z1],%[w1]
+ adcl $0,%[w2]
+ )"
: [w0]"=r"(*w0), [w1]"=r"(*w1), [w2]"=r"(*w2)
: [z0]"r"(z0), [z1]"r"(z1), "0"(*w0), "1"(*w1), "2"(*w2)
: "cc");
@@ -825,20 +827,20 @@ inline void word3_muladd_2(word* w2, word* w1, word* w0, word x, word y)
word z0 = 0, z1 = 0;
- asm ("mulq %[y]"
+ asm("mulq %[y]"
: "=a"(z0),"=d"(z1)
: "a"(x), [y]"rm"(y)
: "cc");
- asm(
- ASM("addq %[z0],%[w0]")
- ASM("adcq %[z1],%[w1]")
- ASM("adcq $0,%[w2]")
-
- ASM("addq %[z0],%[w0]")
- ASM("adcq %[z1],%[w1]")
- ASM("adcq $0,%[w2]")
+ asm(R"(
+ addq %[z0],%[w0]
+ adcq %[z1],%[w1]
+ adcq $0,%[w2]
+ addq %[z0],%[w0]
+ adcq %[z1],%[w1]
+ adcq $0,%[w2]
+ )"
: [w0]"=r"(*w0), [w1]"=r"(*w1), [w2]"=r"(*w2)
: [z0]"r"(z0), [z1]"r"(z1), "0"(*w0), "1"(*w1), "2"(*w2)
: "cc");
diff --git a/src/lib/math/mp/mp_madd.h b/src/lib/math/mp/mp_madd.h
index 630b75488..25659172b 100644
--- a/src/lib/math/mp/mp_madd.h
+++ b/src/lib/math/mp/mp_madd.h
@@ -42,32 +42,28 @@ namespace Botan {
#define BOTAN_MP_USE_X86_64_ASM
#endif
-#if defined(BOTAN_MP_USE_X86_32_ASM) || defined(BOTAN_MP_USE_X86_64_ASM)
- #define ASM(x) x "\n\t"
-#endif
-
/*
* Word Multiply/Add
*/
inline word word_madd2(word a, word b, word* c)
{
#if defined(BOTAN_MP_USE_X86_32_ASM)
- asm(
- ASM("mull %[b]")
- ASM("addl %[c],%[a]")
- ASM("adcl $0,%[carry]")
-
+ asm(R"(
+ mull %[b]
+ addl %[c],%[a]
+ adcl $0,%[carry]
+ )"
: [a]"=a"(a), [b]"=rm"(b), [carry]"=&d"(*c)
: "0"(a), "1"(b), [c]"g"(*c) : "cc");
return a;
#elif defined(BOTAN_MP_USE_X86_64_ASM)
- asm(
- ASM("mulq %[b]")
- ASM("addq %[c],%[a]")
- ASM("adcq $0,%[carry]")
-
+ asm(R"(
+ mulq %[b]
+ addq %[c],%[a]
+ adcq $0,%[carry]
+ )"
: [a]"=a"(a), [b]"=rm"(b), [carry]"=&d"(*c)
: "0"(a), "1"(b), [c]"g"(*c) : "cc");
@@ -98,30 +94,28 @@ inline word word_madd2(word a, word b, word* c)
inline word word_madd3(word a, word b, word c, word* d)
{
#if defined(BOTAN_MP_USE_X86_32_ASM)
- asm(
- ASM("mull %[b]")
-
- ASM("addl %[c],%[a]")
- ASM("adcl $0,%[carry]")
+ asm(R"(
+ mull %[b]
- ASM("addl %[d],%[a]")
- ASM("adcl $0,%[carry]")
+ addl %[c],%[a]
+ adcl $0,%[carry]
+ addl %[d],%[a]
+ adcl $0,%[carry]
+ )"
: [a]"=a"(a), [b]"=rm"(b), [carry]"=&d"(*d)
: "0"(a), "1"(b), [c]"g"(c), [d]"g"(*d) : "cc");
return a;
#elif defined(BOTAN_MP_USE_X86_64_ASM)
- asm(
- ASM("mulq %[b]")
-
- ASM("addq %[c],%[a]")
- ASM("adcq $0,%[carry]")
-
- ASM("addq %[d],%[a]")
- ASM("adcq $0,%[carry]")
-
+ asm(R"(
+ mulq %[b]
+ addq %[c],%[a]
+ adcq $0,%[carry]
+ addq %[d],%[a]
+ adcq $0,%[carry]
+ )"
: [a]"=a"(a), [b]"=rm"(b), [carry]"=&d"(*d)
: "0"(a), "1"(b), [c]"g"(c), [d]"g"(*d) : "cc");
@@ -149,10 +143,6 @@ inline word word_madd3(word a, word b, word c, word* d)
#endif
}
-#if defined(ASM)
- #undef ASM
-#endif
-
}
#endif