Botan 3.9.0
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 414 of file mp_asmi.h.

Constructor & Destructor Documentation

◆ word3()

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

Definition at line 453 of file mp_asmi.h.

453: m_w0(0), m_w1(0), m_w2(0) {}

Member Function Documentation

◆ add()

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

◆ extract()

◆ monty_step()

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

Definition at line 537 of file mp_asmi.h.

537 {
538 W r = m_w0 * p_dash;
539 mul(r, p0);
540 m_w0 = m_w1;
541 m_w1 = m_w2;
542 m_w2 = 0;
543 return r;
544 }
constexpr void mul(W x, W y)
Definition mp_asmi.h:455

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(), Botan::bigint_monty_redc_generic(), and Botan::monty_redc().

◆ monty_step_pdash1()

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

Definition at line 546 of file mp_asmi.h.

546 {
547 // If p_dash == 1 then p[0] = -1 and everything simplifies
548 const W r = m_w0;
549 m_w0 += m_w1;
550 m_w1 = m_w2 + (m_w0 < m_w1);
551 m_w2 = 0;
552 return r;
553 }

Referenced by Botan::monty_redc_pdash1().

◆ mul()

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

Definition at line 455 of file mp_asmi.h.

455 {
456 #if defined(BOTAN_MP_USE_X86_64_ASM)
458 W z0 = 0, z1 = 0;
459
460 asm("mulq %[y]" : "=a"(z0), "=d"(z1) : "a"(x), [y] "rm"(y) : "cc");
461
462 asm(R"(
463 addq %[z0],%[w0]
464 adcq %[z1],%[w1]
465 adcq $0,%[w2]
466 )"
467 : [w0] "=r"(m_w0), [w1] "=r"(m_w1), [w2] "=r"(m_w2)
468 : [z0] "r"(z0), [z1] "r"(z1), "0"(m_w0), "1"(m_w1), "2"(m_w2)
469 : "cc");
470 return;
471 }
472 #endif
473
474 typedef typename WordInfo<W>::dword dword;
475 const dword s = dword(x) * y + m_w0;
476 W carry = static_cast<W>(s >> WordInfo<W>::bits);
477 m_w0 = static_cast<W>(s);
478 m_w1 += carry;
479 m_w2 += (m_w1 < carry);
480 }

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(), Botan::monty_redc(), Botan::monty_redc_pdash1(), and monty_step().

◆ mul_x2()

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

Definition at line 482 of file mp_asmi.h.

482 {
483 #if defined(BOTAN_MP_USE_X86_64_ASM)
485 W z0 = 0, z1 = 0;
486
487 asm("mulq %[y]" : "=a"(z0), "=d"(z1) : "a"(x), [y] "rm"(y) : "cc");
488
489 asm(R"(
490 addq %[z0],%[w0]
491 adcq %[z1],%[w1]
492 adcq $0,%[w2]
493
494 addq %[z0],%[w0]
495 adcq %[z1],%[w1]
496 adcq $0,%[w2]
497 )"
498 : [w0] "=r"(m_w0), [w1] "=r"(m_w1), [w2] "=r"(m_w2)
499 : [z0] "r"(z0), [z1] "r"(z1), "0"(m_w0), "1"(m_w1), "2"(m_w2)
500 : "cc");
501 return;
502 }
503 #endif
504
505 W carry = 0;
506 x = word_madd2(x, y, &carry);
507 y = carry;
508
509 carry = 0;
510 m_w0 = word_add(m_w0, x, &carry);
511 m_w1 = word_add(m_w1, y, &carry);
512 m_w2 += carry;
513
514 carry = 0;
515 m_w0 = word_add(m_w0, x, &carry);
516 m_w1 = word_add(m_w1, y, &carry);
517 m_w2 += carry;
518 }
constexpr auto word_madd2(W a, W b, W *c) -> W
Definition mp_asmi.h:86

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: