Botan 3.8.1
Crypto and TLS for C&
Botan::word3< W > Class Template Referencefinal

#include <mp_asmi.h>

Public Member Functions

constexpr void add (W x)
 
constexpr W extract ()
 
constexpr W monty_step (W p0, W p_dash)
 
constexpr W monty_step_pdash1 ()
 
constexpr void mul (W x, W y)
 
constexpr void mul_x2 (W x, W y)
 
constexpr word3 ()
 

Detailed Description

template<WordType W>
class Botan::word3< W >

Helper for 3-word accumulators

A number of algorithms especially Comba multiplication and Montgomery reduction can take advantage of wide accumulators, which consume inputs via addition with outputs extracted from the low bits.

Definition at line 464 of file mp_asmi.h.

Constructor & Destructor Documentation

◆ word3()

template<WordType W>
Botan::word3< W >::word3 ( )
inlineconstexpr

Definition at line 503 of file mp_asmi.h.

503 {
504 m_w2 = 0;
505 m_w1 = 0;
506 m_w0 = 0;
507 }

Member Function Documentation

◆ add()

template<WordType W>
void Botan::word3< W >::add ( W x)
inlineconstexpr

Definition at line 574 of file mp_asmi.h.

574 {
575 constexpr W z = 0;
576
577 W carry = 0;
578 m_w0 = word_add(m_w0, x, &carry);
579 m_w1 = word_add(m_w1, z, &carry);
580 m_w2 += carry;
581 }
constexpr auto word_add(W x, W y, W *carry) -> W
Definition mp_asmi.h:189

References Botan::carry(), and Botan::word_add().

Referenced by Botan::bigint_monty_redc_12(), Botan::bigint_monty_redc_16(), Botan::bigint_monty_redc_24(), Botan::bigint_monty_redc_32(), Botan::bigint_monty_redc_4(), Botan::bigint_monty_redc_6(), Botan::bigint_monty_redc_8(), and Botan::bigint_monty_redc_generic().

◆ extract()

◆ monty_step()

template<WordType W>
W Botan::word3< W >::monty_step ( W p0,
W p_dash )
inlineconstexpr

Definition at line 591 of file mp_asmi.h.

591 {
592 W r = m_w0 * p_dash;
593 mul(r, p0);
594 m_w0 = m_w1;
595 m_w1 = m_w2;
596 m_w2 = 0;
597 return r;
598 }
constexpr void mul(W x, W y)
Definition mp_asmi.h:509

References mul().

Referenced by Botan::bigint_monty_redc_12(), Botan::bigint_monty_redc_16(), Botan::bigint_monty_redc_24(), Botan::bigint_monty_redc_32(), Botan::bigint_monty_redc_4(), Botan::bigint_monty_redc_6(), Botan::bigint_monty_redc_8(), and Botan::bigint_monty_redc_generic().

◆ monty_step_pdash1()

template<WordType W>
W Botan::word3< W >::monty_step_pdash1 ( )
inlineconstexpr

Definition at line 600 of file mp_asmi.h.

600 {
601 // If p_dash == 1 then p[0] = -1 and everything simplifies
602 const W r = m_w0;
603 m_w0 += m_w1;
604 m_w1 = m_w2 + (m_w0 < m_w1);
605 m_w2 = 0;
606 return r;
607 }

◆ mul()

template<WordType W>
void Botan::word3< W >::mul ( W x,
W y )
inlineconstexpr

Definition at line 509 of file mp_asmi.h.

509 {
510 #if defined(BOTAN_MP_USE_X86_64_ASM)
512 W z0 = 0, z1 = 0;
513
514 asm("mulq %[y]" : "=a"(z0), "=d"(z1) : "a"(x), [y] "rm"(y) : "cc");
515
516 asm(R"(
517 addq %[z0],%[w0]
518 adcq %[z1],%[w1]
519 adcq $0,%[w2]
520 )"
521 : [w0] "=r"(m_w0), [w1] "=r"(m_w1), [w2] "=r"(m_w2)
522 : [z0] "r"(z0), [z1] "r"(z1), "0"(m_w0), "1"(m_w1), "2"(m_w2)
523 : "cc");
524 return;
525 }
526 #endif
527
528 typedef typename WordInfo<W>::dword dword;
529 const dword s = dword(x) * y + m_w0;
530 W carry = static_cast<W>(s >> WordInfo<W>::bits);
531 m_w0 = static_cast<W>(s);
532 m_w1 += carry;
533 m_w2 += (m_w1 < carry);
534 }

References Botan::carry().

Referenced by Botan::bigint_comba_mul16(), Botan::bigint_comba_mul24(), Botan::bigint_comba_mul4(), Botan::bigint_comba_mul6(), Botan::bigint_comba_mul7(), Botan::bigint_comba_mul8(), Botan::bigint_comba_mul9(), Botan::bigint_comba_sqr16(), Botan::bigint_comba_sqr24(), Botan::bigint_comba_sqr4(), Botan::bigint_comba_sqr6(), Botan::bigint_comba_sqr7(), Botan::bigint_comba_sqr8(), Botan::bigint_comba_sqr9(), Botan::bigint_monty_redc_12(), Botan::bigint_monty_redc_16(), Botan::bigint_monty_redc_24(), Botan::bigint_monty_redc_32(), Botan::bigint_monty_redc_4(), Botan::bigint_monty_redc_6(), Botan::bigint_monty_redc_8(), Botan::bigint_monty_redc_generic(), Botan::comba_mul(), Botan::comba_sqr(), and monty_step().

◆ mul_x2()

template<WordType W>
void Botan::word3< W >::mul_x2 ( W x,
W y )
inlineconstexpr

Definition at line 536 of file mp_asmi.h.

536 {
537 #if defined(BOTAN_MP_USE_X86_64_ASM)
539 W z0 = 0, z1 = 0;
540
541 asm("mulq %[y]" : "=a"(z0), "=d"(z1) : "a"(x), [y] "rm"(y) : "cc");
542
543 asm(R"(
544 addq %[z0],%[w0]
545 adcq %[z1],%[w1]
546 adcq $0,%[w2]
547
548 addq %[z0],%[w0]
549 adcq %[z1],%[w1]
550 adcq $0,%[w2]
551 )"
552 : [w0] "=r"(m_w0), [w1] "=r"(m_w1), [w2] "=r"(m_w2)
553 : [z0] "r"(z0), [z1] "r"(z1), "0"(m_w0), "1"(m_w1), "2"(m_w2)
554 : "cc");
555 return;
556 }
557 #endif
558
559 W carry = 0;
560 x = word_madd2(x, y, &carry);
561 y = carry;
562
563 carry = 0;
564 m_w0 = word_add(m_w0, x, &carry);
565 m_w1 = word_add(m_w1, y, &carry);
566 m_w2 += carry;
567
568 carry = 0;
569 m_w0 = word_add(m_w0, x, &carry);
570 m_w1 = word_add(m_w1, y, &carry);
571 m_w2 += carry;
572 }
constexpr auto word_madd2(W a, W b, W *c) -> W
Definition mp_asmi.h:84

References Botan::carry(), Botan::word_add(), and Botan::word_madd2().

Referenced by Botan::bigint_comba_sqr16(), Botan::bigint_comba_sqr24(), Botan::bigint_comba_sqr4(), Botan::bigint_comba_sqr6(), Botan::bigint_comba_sqr7(), Botan::bigint_comba_sqr8(), and Botan::bigint_comba_sqr9().


The documentation for this class was generated from the following file: