|
#define | RANDOM() sark_rand() |
|
#define | ROUNDING_STOCHASTIC |
| The rounding mode of all multiplications.
|
|
|
Set up various multiplication macros depending on the rounding method chosen above. These are the highest level of macros that the users should use.
FX_MUL returns an s1615, FX_MUL_SHORT_ACCUM returns an s87, FX_MUL_FRACT32 returns an s031, and FX_MUL_FRACT16 returns an s015.
|
#define | FX_MUL(x, y) MULT_ROUND_STOCHASTIC_ACCUM(x, y) |
| Multiply two s1615 values with rounding.
|
|
#define | FX_MUL_SHORT_ACCUM(x, y) MULT_ROUND_STOCHASTIC_SHORT_ACCUM(x, y) |
| Multiply two s87 values with rounding.
|
|
#define | FX_MUL_FRACT32(x, y) MULT_ROUND_STOCHASTIC_FRACT32(x, y) |
| Multiply two s031 values with rounding.
|
|
#define | FX_MUL_FRACT16(x, y) MULT_ROUND_STOCHASTIC_FRACT16(x, y) |
| Multiply two s015 values with rounding.
|
|
|
The following macros choose a correct multiplication function depending on the types of arguments.
|
#define | MULT_NO_ROUND_GCC(x, y) |
| Multiply with whatever the compiler deigns to pick for us.
|
|
#define | MULT_NO_ROUND_CUSTOM_ACCUM(x, y) |
| Multiply fixed point numbers to make s1615; no rounding.
|
|
#define | MULT_NO_ROUND_CUSTOM_SHORT_ACCUM(x, y) |
| Multiply fixed point numbers to make s87; no rounding.
|
|
#define | MULT_NO_ROUND_CUSTOM_FRACT32(x, y) |
| Multiply fixed point numbers to make s031; no rounding.
|
|
#define | MULT_NO_ROUND_CUSTOM_FRACT16(x, y) |
| Multiply fixed point numbers to make s015; no rounding.
|
|
#define | MULT_ROUND_NEAREST_ACCUM(x, y) |
| Multiply fixed point numbers to make s1615; round to nearest.
|
|
#define | MULT_ROUND_NEAREST_SHORT_ACCUM(x, y) |
| Multiply fixed point numbers to make s87; round to nearest.
|
|
#define | MULT_ROUND_NEAREST_FRACT32(x, y) |
| Multiply fixed point numbers to make s031; round to nearest.
|
|
#define | MULT_ROUND_NEAREST_FRACT16(x, y) |
| Multiply fixed point numbers to make s015; round to nearest.
|
|
#define | MULT_ROUND_STOCHASTIC_ACCUM(x, y) |
| Multiply fixed point numbers to make s1615; stochastic rounding.
|
|
#define | MULT_ROUND_STOCHASTIC_SHORT_ACCUM(x, y) |
| Multiply fixed point numbers to make s87; stochastic rounding.
|
|
#define | MULT_ROUND_STOCHASTIC_FRACT32(x, y) |
| Multiply fixed point numbers to make s031; stochastic rounding.
|
|
#define | MULT_ROUND_STOCHASTIC_FRACT16(x, y) |
| Multiply fixed point numbers to make s015; stochastic rounding.
|
|
|
#define | STOCHASTIC_ROUND_S64(x, n) |
| Round a signed 64-bit number stochastically to a given number of bits and return a 32-bit integer.
|
|
#define | STOCHASTIC_ROUND_U64(x, n) |
| Round an unsigned 64-bit number stochastically to a given number of bits and return a 32-bit integer.
|
|
#define | NEAREST_ROUND_S64(x, n) |
| Round a signed 64-bit number to a nearest given number of bits and return a 32-bit integer.
|
|
#define | NEAREST_ROUND_U64(x, n) |
| Round an unsigned 64-bit number to a nearest given number of bits and return a 32-bit integer.
|
|
#define | ROUND_DOWN_S64(x, n) |
| Round a 64-bit number down on a given number of bits and return a 32-bit integer.
|
|
|
static uint32_t | cheap_generator (void) |
| Cheap PRNG from "Numerical Recipes in C", page 284.
|
|
|
Inputs are signed/unsigned integers of various lengths and the number of bits to round. The output is the rounded integer number.
|
static int64_t | __stdfix_stochastic_round_s64 (int64_t x, int n) |
| Stochastic rounding: signed 64-bit.
|
|
static int64_t | __stdfix_stochastic_round_s64_alternative (int64_t x, int n) |
| Alternative algorithm for __stdfix_stochastic_round_s64().
|
|
static int32_t | __stdfix_stochastic_round_s32 (int32_t x, int n) |
| Stochastic rounding: signed 32-bit.
|
|
static int16_t | __stdfix_stochastic_round_s16 (int16_t x, int n) |
| Stochastic rounding: signed 16-bit.
|
|
static uint64_t | __stdfix_stochastic_round_u64 (uint64_t x, int n) |
| Stochastic rounding: unsigned 64-bit.
|
|
static uint32_t | __stdfix_stochastic_round_u32 (uint32_t x, int n) |
| Stochastic rounding: unsigned 32-bit.
|
|
static uint16_t | __stdfix_stochastic_round_u16 (uint16_t x, int n) |
| Stochastic rounding: unsigned 16-bit.
|
|
|
static int32_t | __stdfix_smul_k_round_nearest (int32_t x, int32_t y) |
| Multiply two integer representations of s1615 and return an integer representation of an s1615 answer, rounded to the nearest s1615.
|
|
static int32_t | __stdfix_smul_k_round_stochastic (int32_t x, int32_t y) |
| Multiply two integer representations of s1615 and return an integer representation of an s1615 answer, rounded to a neighbouring s1615 stochastically.
|
|
static uint32_t | __stdfix_smul_ulr_round_nearest (uint32_t x, uint32_t y) |
| Multiply two integer representations of u032 and return an integer representation of an s031 answer, rounded to the nearest s1615.
|
|
static uint32_t | __stdfix_smul_ulr_round_stochastic (uint32_t x, uint32_t y) |
| Multiply two integer representations of u032 and return an integer representation of an s031 answer, rounded to a neighbouring s031 stochastically.
|
|
|
static int32_t | __stdfix_smul_hk_round_nearest (int32_t x, int32_t y) |
| Multiply two integer representations of s87 and return an integer representation of an s87 answer, rounded to the nearest s87.
|
|
static int32_t | __stdfix_smul_hk_round_stochastic (int32_t x, int32_t y) |
| Multiply two integer representations of s87 and return an integer representation of an s87 answer, rounded to a neighbouring s87 stochastically.
|
|
static uint32_t | __stdfix_smul_ur_round_nearest (uint32_t x, uint32_t y) |
| Multiply two integer representations of u016 and return an integer representation of an s015 answer, rounded to the nearest s015.
|
|
static uint32_t | __stdfix_smul_ur_round_stochastic (uint32_t x, uint32_t y) |
| Multiply two integer representations of u016 and return an integer representation of an s015 answer, rounded to a neighbouring s015 stochastically.
|
|
|
The following functions do mixed format multiplications. Most of them are reworked from Dave Lester's original implementation accum_times_long_fract() and so have a different format than a set of functions above.
- Todo:
- Make these functions take integer representations and use the naming conventions to be consistent with the functions above and in stdfix-full-iso.h
|
static s1615 | accum_times_long_fract (s1615 x, s031 y) |
| Multiply an s1615 and an s031 and return an s1615 answer, without rounding.
|
|
static s1615 | accum_times_long_fract_nearest (s1615 x, s031 y) |
| Multiply an s1615 and an s031 and return an s1615 answer rounded to the nearest s1615.
|
|
static s1615 | accum_times_long_fract_stochastic (s1615 x, s031 y) |
| Multiply s1615 and an s031 and return an s1615 answer rounded to a neighbouring s1615 stochastically.
|
|
static s1615 | accum_times_u_long_fract (s1615 x, u032 y) |
| Multiply s1615 and an u032 and return an s1615 answer, without rounding.
|
|
static s1615 | accum_times_u_long_fract_nearest (s1615 x, u032 y) |
| Multiply s1615 and an u032 and return an s1615 answer rounded to the nearest s1615.
|
|
static s1615 | accum_times_u_long_fract_stochastic (s1615 x, u032 y) |
| Multiply s1615 and an u032 and return an s1615 answer rounded to a neighbouring s1615 stochastically.
|
|
static s031 | long_fract_times_u_long_fract (s031 x, u032 y) |
| Multiply an s031 and an u032 and return a s031 answer, without rounding.
|
|
static s031 | long_fract_times_u_long_fract_nearest (s031 x, u032 y) |
| Multiply an s031 and an u032 and return a s031 answer rounded to the nearest s031.
|
|
static s031 | long_fract_times_u_long_fract_stochastic (s031 x, u032 y) |
| Multiply an s031 and an u032 and return a s031 answer rounded to a neighbouring s031 stochastically.
|
|
static s87 | short_accum_times_fract (s87 x, s015 y) |
| Multiply two s87 numbers and return an s87 answer without rounding.
|
|
static s87 | short_accum_times_fract_nearest (s87 x, s015 y) |
| Multiply two s87 values and return an s87 answer rounded to the nearest s87.
|
|
static s87 | short_accum_times_fract_stochastic (s87 x, s015 y) |
| Multiply two s87 values and return an s87 answer rounded to a neighbouring s87 stochastically.
|
|
static s87 | short_accum_times_u_fract (s87 x, u016 y) |
| Multiply an s87 and an u016 and return an s87 answer without rounding.
|
|
static s87 | short_accum_times_u_fract_nearest (s87 x, u016 y) |
| Multiply an s87 and an u016 and return an s87 answer rounded to the nearest s87.
|
|
static s87 | short_accum_times_u_fract_stochastic (s87 x, u016 y) |
| Multiply an s87 and an u016 and return an s87 answer rounded to a neighbouring s87 stochastically.
|
|
static s015 | fract_times_u_fract (s015 x, u016 y) |
| Multiply an u016 and an s015 and return an s015 answer without rounding.
|
|
static s015 | fract_times_u_fract_nearest (s015 x, u016 y) |
| Multiply an u016 and an s015 and return an s015 answer rounded to the nearest s015.
|
|
static s015 | fract_times_u_fract_stochastic (s015 x, u016 y) |
| Multiply an u016 and an s015 and return an s015 answer with stochastic rounding.
|
|
Fixed-point multiplication with controlled rounding.
This file complements stdfix-full-iso.h to add various rounding routines and mixed-format fixed-point multiplication routines.
Note that GCC currently does not implement rounding on such operations like fixed-point multiplication and conversion (e.g. decimal to fixed-point). Some more background in https://arxiv.org/abs/1904.11263
- Author
- manta.nosp@m.s.mi.nosp@m.kaiti.nosp@m.s@ma.nosp@m.nches.nosp@m.ter..nosp@m.ac.uk
- Date
- 2019 August.