libsc  2.8.7
The SC library provides support for parallel scientific applications.
All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Macros Modules Pages
Data Structures | Typedefs | Functions
sc_uint128.h File Reference

Routines for managing unsigned 128 bit integers. More...

#include <sc.h>
Include dependency graph for sc_uint128.h:

Go to the source code of this file.

Data Structures

struct  sc_uint128
 An unsigned 128 bit integer represented as two uint64_t. More...
 

Typedefs

typedef struct sc_uint128 sc_uint128_t
 An unsigned 128 bit integer represented as two uint64_t.
 

Functions

int sc_uint128_compare (const void *a, const void *b)
 Compare the sc_uint128_t a and the sc_uint128_t b. More...
 
int sc_uint128_is_equal (const sc_uint128_t *a, const sc_uint128_t *b)
 Checks if the sc_uint128_t a and the sc_uint128_t b are equal. More...
 
void sc_uint128_init (sc_uint128_t *a, uint64_t high, uint64_t low)
 Initializes an unsigned 128 bit integer to a given value. More...
 
int sc_uint128_chk_bit (const sc_uint128_t *input, int exponent)
 Returns the bit_number-th bit of input. More...
 
void sc_uint128_set_bit (sc_uint128_t *a, int exponent)
 Sets the exponent-th bit of a to one and keep all other bits. More...
 
void sc_uint128_copy (const sc_uint128_t *input, sc_uint128_t *output)
 Copies an initialized sc_uint128_t to a sc_uint128_t. More...
 
void sc_uint128_add (const sc_uint128_t *a, const sc_uint128_t *b, sc_uint128_t *result)
 Adds the uint128_t b to the uint128_t a. More...
 
void sc_uint128_sub (const sc_uint128_t *a, const sc_uint128_t *b, sc_uint128_t *result)
 Subtracts the uint128_t b from the uint128_t a. More...
 
void sc_uint128_bitwise_neg (const sc_uint128_t *a, sc_uint128_t *result)
 Calculates the bitwise negation of the uint128_t a. More...
 
void sc_uint128_bitwise_or (const sc_uint128_t *a, const sc_uint128_t *b, sc_uint128_t *result)
 Calculates the bitwise or of the uint128_t a and b. More...
 
void sc_uint128_bitwise_and (const sc_uint128_t *a, const sc_uint128_t *b, sc_uint128_t *result)
 Calculates the bitwise and of the uint128_t a and the uint128_t b. More...
 
void sc_uint128_shift_right (const sc_uint128_t *input, int shift_count, sc_uint128_t *result)
 Calculates the bit right shift of uint128_t input by shift_count bits. More...
 
void sc_uint128_shift_left (const sc_uint128_t *input, int shift_count, sc_uint128_t *result)
 Calculates the bit left shift of uint128_t input by shift_count bits. More...
 
void sc_uint128_add_inplace (sc_uint128_t *a, const sc_uint128_t *b)
 Adds the uint128 b to the uint128_t a. More...
 
void sc_uint128_sub_inplace (sc_uint128_t *a, const sc_uint128_t *b)
 Subtracts the uint128_t b from the uint128_t a. More...
 
void sc_uint128_bitwise_or_inplace (sc_uint128_t *a, const sc_uint128_t *b)
 Calculates the bitwise or of the uint128_t a and the uint128_t b. More...
 
void sc_uint128_bitwise_and_inplace (sc_uint128_t *a, const sc_uint128_t *b)
 Calculates the bitwise and of the uint128_t a and the uint128_t b. More...
 

Detailed Description

Routines for managing unsigned 128 bit integers.

We do this to have a portable way on systems that have no native support.

Function Documentation

◆ sc_uint128_add()

void sc_uint128_add ( const sc_uint128_t a,
const sc_uint128_t b,
sc_uint128_t result 
)

Adds the uint128_t b to the uint128_t a.

result == a or result == b is not allowed. a == b is allowed.

Parameters
[in]aA pointer to a sc_uint128_t.
[in]bA pointer to a sc_uint128_t.
[out]resultA pointer to a sc_uint128_t. The sum a + b will be saved in result.

◆ sc_uint128_add_inplace()

void sc_uint128_add_inplace ( sc_uint128_t a,
const sc_uint128_t b 
)

Adds the uint128 b to the uint128_t a.

The result is saved in a. a == b is allowed.

Parameters
[in,out]aA pointer to a sc_uint128_t. a will be overwritten by a + b.
[in]bA pointer to a sc_uint128_t.

◆ sc_uint128_bitwise_and()

void sc_uint128_bitwise_and ( const sc_uint128_t a,
const sc_uint128_t b,
sc_uint128_t result 
)

Calculates the bitwise and of the uint128_t a and the uint128_t b.

a == result is allowed. Furthermore, a == result and/or b == result is allowed.

Parameters
[in]aA pointer to a sc_uint128_t.
[in]bA pointer to a sc_uint128_t.
[out]resultA pointer to a sc_uint128_t. The bitwise and of a and b will be saved. in result.

◆ sc_uint128_bitwise_and_inplace()

void sc_uint128_bitwise_and_inplace ( sc_uint128_t a,
const sc_uint128_t b 
)

Calculates the bitwise and of the uint128_t a and the uint128_t b.

a == b is allowed.

Parameters
[in,out]aA pointer to a sc_uint128_t. The bitwise and will be saved in a.
[in]bA pointer to a sc_uint128_t.

◆ sc_uint128_bitwise_neg()

void sc_uint128_bitwise_neg ( const sc_uint128_t a,
sc_uint128_t result 
)

Calculates the bitwise negation of the uint128_t a.

a == result is allowed.

Parameters
[in]aA pointer to a sc_uint128_t.
[out]resultA pointer to a sc_uint128_t. The bitwise negation of a will be saved in result.

◆ sc_uint128_bitwise_or()

void sc_uint128_bitwise_or ( const sc_uint128_t a,
const sc_uint128_t b,
sc_uint128_t result 
)

Calculates the bitwise or of the uint128_t a and b.

a == result is allowed. Furthermore, a == result and/or b == result is allowed.

Parameters
[in]aA pointer to a sc_uint128_t.
[in]bA pointer to a sc_uint128_t.
[out]resultA pointer to a sc_uint128_t. The bitwise or of a and b will be saved in result.

◆ sc_uint128_bitwise_or_inplace()

void sc_uint128_bitwise_or_inplace ( sc_uint128_t a,
const sc_uint128_t b 
)

Calculates the bitwise or of the uint128_t a and the uint128_t b.

a == b is allowed.

Parameters
[in,out]aA pointer to a sc_uint128_t. The bitwise or will be saved in a.
[in]bA pointer to a sc_uint128_t.

◆ sc_uint128_chk_bit()

int sc_uint128_chk_bit ( const sc_uint128_t input,
int  exponent 
)

Returns the bit_number-th bit of input.

This function checks a bit of an existing, initialized value.

Parameters
[in]inputA pointer to a sc_uint128_t.
[in]exponentThe bit (counted from the right hand side) that is checked by logical and. Require 0 <= bit_number < 128.
Returns
True if the checked bit is set, false if not.

◆ sc_uint128_compare()

int sc_uint128_compare ( const void *  a,
const void *  b 
)

Compare the sc_uint128_t a and the sc_uint128_t b.

Parameters
[in]aA pointer to a sc_uint128_t.
[in]bA pointer to a sc_uint128_t.
Returns
Returns -1 if a < b, 1 if a > b and 0 if a == b.

◆ sc_uint128_copy()

void sc_uint128_copy ( const sc_uint128_t input,
sc_uint128_t output 
)

Copies an initialized sc_uint128_t to a sc_uint128_t.

Parameters
[in]inputA pointer to the sc_uint128 that is copied.
[in,out]outputA pointer to a sc_uint128_t. The high and low bits of output will be set to the high and low bits of input, respectively.

◆ sc_uint128_init()

void sc_uint128_init ( sc_uint128_t a,
uint64_t  high,
uint64_t  low 
)

Initializes an unsigned 128 bit integer to a given value.

Parameters
[in,out]aA pointer to the sc_uint128_t that will be initialized.
[in]highThe given high bits to initialize a.
[in]lowThe given low bits to initialize a.

◆ sc_uint128_is_equal()

int sc_uint128_is_equal ( const sc_uint128_t a,
const sc_uint128_t b 
)

Checks if the sc_uint128_t a and the sc_uint128_t b are equal.

Parameters
[in]aA pointer to a sc_uint128_t.
[in]bA pointer to a sc_uint128_t.
Returns
Returns a true value if a and b are equal, false otherwise.

◆ sc_uint128_set_bit()

void sc_uint128_set_bit ( sc_uint128_t a,
int  exponent 
)

Sets the exponent-th bit of a to one and keep all other bits.

This function modifies an existing, initialized value.

Parameters
[in,out]aA pointer to a sc_uint128_t.
[in]exponentThe bit (0-based from the rightmost bit) that is set to one by logical or. 0 <= exponent < 128.

◆ sc_uint128_shift_left()

void sc_uint128_shift_left ( const sc_uint128_t input,
int  shift_count,
sc_uint128_t result 
)

Calculates the bit left shift of uint128_t input by shift_count bits.

We shift in zeros from the right. If shift_count >= 128, result is 0. All bits left from the 127th bit (counted zero based from the right hand side) drop out. input == result is allowed.

Parameters
[in]inputA pointer to a sc_uint128_t.
[in]shift_countBits to shift. shift_count >= 0.
[in,out]resultA pointer to a sc_uint128_t. The left shifted number will be saved in result.

◆ sc_uint128_shift_right()

void sc_uint128_shift_right ( const sc_uint128_t input,
int  shift_count,
sc_uint128_t result 
)

Calculates the bit right shift of uint128_t input by shift_count bits.

We shift in zeros from the left. If shift_count >= 128, result is 0. All bits right from the zeroth bit (counted from the right hand side) drop out. input == result is allowed.

Parameters
[in]inputA pointer to a sc_uint128_t.
[in]shift_countBits to shift. shift_count >= 0.
[in,out]resultA pointer to a sc_uint128_t. The right shifted number will be saved in result.

◆ sc_uint128_sub()

void sc_uint128_sub ( const sc_uint128_t a,
const sc_uint128_t b,
sc_uint128_t result 
)

Subtracts the uint128_t b from the uint128_t a.

This function assumes that the result is >= 0. result == a or result == b is not allowed. a == b is allowed.

Parameters
[in]aA pointer to a sc_uint128_t.
[in]bA pointer to a sc_uint128_t.
[out]resultA pointer to a sc_uint128_t. The difference a - b will be saved in result.

◆ sc_uint128_sub_inplace()

void sc_uint128_sub_inplace ( sc_uint128_t a,
const sc_uint128_t b 
)

Subtracts the uint128_t b from the uint128_t a.

The result is saved in a. a == b is allowed. This function assumes that the result is >= 0.

Parameters
[in,out]aA pointer to a sc_uint128_t. a will be overwritten by a - b.
[in]bA pointer to a sc_uint128_t.