iPXE
Functions
x86_bigint.c File Reference

Big integer support. More...

#include <stdint.h>
#include <string.h>
#include <ipxe/bigint.h>

Go to the source code of this file.

Functions

 FILE_LICENCE (GPL2_OR_LATER_OR_UBDL)
 
void bigint_multiply_raw (const uint32_t *multiplicand0, const uint32_t *multiplier0, uint32_t *result0, unsigned int size)
 Multiply big integers. More...
 

Detailed Description

Big integer support.

Definition in file x86_bigint.c.

Function Documentation

◆ FILE_LICENCE()

FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL  )

◆ bigint_multiply_raw()

void bigint_multiply_raw ( const uint32_t multiplicand0,
const uint32_t multiplier0,
uint32_t result0,
unsigned int  size 
)

Multiply big integers.

Parameters
multiplicand0Element 0 of big integer to be multiplied
multiplier0Element 0 of big integer to be multiplied
result0Element 0 of big integer to hold result
sizeNumber of elements

Definition at line 43 of file x86_bigint.c.

45  {
46  const bigint_t ( size ) __attribute__ (( may_alias )) *multiplicand =
47  ( ( const void * ) multiplicand0 );
48  const bigint_t ( size ) __attribute__ (( may_alias )) *multiplier =
49  ( ( const void * ) multiplier0 );
50  bigint_t ( size * 2 ) __attribute__ (( may_alias )) *result =
51  ( ( void * ) result0 );
52  unsigned int i;
53  unsigned int j;
54  uint32_t multiplicand_element;
55  uint32_t multiplier_element;
56  uint32_t *result_elements;
57  uint32_t discard_a;
58  uint32_t discard_d;
59  long index;
60 
61  /* Zero result */
62  memset ( result, 0, sizeof ( *result ) );
63 
64  /* Multiply integers one element at a time */
65  for ( i = 0 ; i < size ; i++ ) {
66  multiplicand_element = multiplicand->element[i];
67  for ( j = 0 ; j < size ; j++ ) {
68  multiplier_element = multiplier->element[j];
69  result_elements = &result->element[ i + j ];
70  /* Perform a single multiply, and add the
71  * resulting double-element into the result,
72  * carrying as necessary. The carry can
73  * never overflow beyond the end of the
74  * result, since:
75  *
76  * a < 2^{n}, b < 2^{n} => ab < 2^{2n}
77  */
78  __asm__ __volatile__ ( "mull %4\n\t"
79  "addl %%eax, (%5,%2,4)\n\t"
80  "adcl %%edx, 4(%5,%2,4)\n\t"
81  "\n1:\n\t"
82  "adcl $0, 8(%5,%2,4)\n\t"
83  "inc %2\n\t"
84  /* Does not affect CF */
85  "jc 1b\n\t"
86  : "=&a" ( discard_a ),
87  "=&d" ( discard_d ),
88  "=&r" ( index )
89  : "0" ( multiplicand_element ),
90  "g" ( multiplier_element ),
91  "r" ( result_elements ),
92  "2" ( 0 ) );
93  }
94  }
95 }
#define __attribute__(x)
Definition: compiler.h:10
uint8_t multiplier
Port multiplier number.
Definition: edd.h:32
int result
Definition: bigint.h:148
const bigint_t(size) __attribute__((may_alias)) *reference
unsigned int uint32_t
Definition: stdint.h:12
__asm__ __volatile__("\n1:\n\t" "movb -1(%2,%1), %%al\n\t" "stosb\n\t" "loop 1b\n\t" "xorl %%eax, %%eax\n\t" "mov %3, %1\n\t" "rep stosb\n\t" :"=&D"(discard_D), "=&c"(discard_c) :"r"(data), "g"(pad_len), "0"(value0), "1"(len) :"eax")
__asm__(".section \".rodata\", \"a\", " PROGBITS "\n\t" "\nprivate_key_data:\n\t" ".size private_key_data, ( . - private_key_data )\n\t" ".equ private_key_len, ( . - private_key_data )\n\t" ".previous\n\t")
uint8_t size
Entry size (in 32-bit words)
Definition: ena.h:16
uint64_t index
Index of the first segment within the content.
Definition: pccrc.h:21
void * memset(void *dest, int character, size_t len) __nonnull

References __asm__(), __attribute__, __volatile__(), bigint_t(), index, memset(), multiplier, result, and size.