libsc
2.8.7
The SC library provides support for parallel scientific applications.
|
Routines for managing unsigned 128 bit integers. More...
#include <sc.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... | |
Routines for managing unsigned 128 bit integers.
We do this to have a portable way on systems that have no native support.
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.
[in] | a | A pointer to a sc_uint128_t. |
[in] | b | A pointer to a sc_uint128_t. |
[out] | result | A pointer to a sc_uint128_t. The sum a + b will be saved in result. |
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.
[in,out] | a | A pointer to a sc_uint128_t. a will be overwritten by a + b. |
[in] | b | A pointer to a sc_uint128_t. |
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.
[in] | a | A pointer to a sc_uint128_t. |
[in] | b | A pointer to a sc_uint128_t. |
[out] | result | A pointer to a sc_uint128_t. The bitwise and of a and b will be saved. in result. |
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.
[in,out] | a | A pointer to a sc_uint128_t. The bitwise and will be saved in a. |
[in] | b | A pointer to a sc_uint128_t. |
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.
[in] | a | A pointer to a sc_uint128_t. |
[out] | result | A pointer to a sc_uint128_t. The bitwise negation of a will be saved in result. |
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.
[in] | a | A pointer to a sc_uint128_t. |
[in] | b | A pointer to a sc_uint128_t. |
[out] | result | A pointer to a sc_uint128_t. The bitwise or of a and b will be saved in result. |
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.
[in,out] | a | A pointer to a sc_uint128_t. The bitwise or will be saved in a. |
[in] | b | A pointer to a sc_uint128_t. |
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.
[in] | input | A pointer to a sc_uint128_t. |
[in] | exponent | The bit (counted from the right hand side) that is checked by logical and. Require 0 <= bit_number < 128. |
int sc_uint128_compare | ( | const void * | a, |
const void * | b | ||
) |
Compare the sc_uint128_t a and the sc_uint128_t b.
[in] | a | A pointer to a sc_uint128_t. |
[in] | b | A pointer to a sc_uint128_t. |
void sc_uint128_copy | ( | const sc_uint128_t * | input, |
sc_uint128_t * | output | ||
) |
Copies an initialized sc_uint128_t to a sc_uint128_t.
[in] | input | A pointer to the sc_uint128 that is copied. |
[in,out] | output | A 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. |
void sc_uint128_init | ( | sc_uint128_t * | a, |
uint64_t | high, | ||
uint64_t | low | ||
) |
Initializes an unsigned 128 bit integer to a given value.
[in,out] | a | A pointer to the sc_uint128_t that will be initialized. |
[in] | high | The given high bits to initialize a. |
[in] | low | The given low bits to initialize a. |
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.
[in] | a | A pointer to a sc_uint128_t. |
[in] | b | A pointer to a sc_uint128_t. |
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.
[in,out] | a | A pointer to a sc_uint128_t. |
[in] | exponent | The bit (0-based from the rightmost bit) that is set to one by logical or. 0 <= exponent < 128. |
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.
[in] | input | A pointer to a sc_uint128_t. |
[in] | shift_count | Bits to shift. shift_count >= 0. |
[in,out] | result | A pointer to a sc_uint128_t. The left shifted number will be saved in result. |
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.
[in] | input | A pointer to a sc_uint128_t. |
[in] | shift_count | Bits to shift. shift_count >= 0. |
[in,out] | result | A pointer to a sc_uint128_t. The right shifted number will be saved in result. |
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.
[in] | a | A pointer to a sc_uint128_t. |
[in] | b | A pointer to a sc_uint128_t. |
[out] | result | A pointer to a sc_uint128_t. The difference a - b will be saved in result. |
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.
[in,out] | a | A pointer to a sc_uint128_t. a will be overwritten by a - b. |
[in] | b | A pointer to a sc_uint128_t. |