16-bit vector prepare functions#
- group vect_s16_prepare_api
Defines
-
vect_s16_add_prepare#
Obtain the output exponent and shifts required for a call to
vect_s16_add().The logic for computing the shifts and exponents of
vect_s16_add()is identical to that forvect_s32_add().This macro is provided as a convenience to developers and to make the code more readable.
See also
-
vect_s16_add_scalar_prepare#
Obtain the output exponent and shifts required for a call to
vect_s16_add_scalar().The logic for computing the shifts and exponents of
vect_s16_add_scalar()is identical to that forvect_s32_add().This macro is provided as a convenience to developers and to make the code more readable.
See also
-
vect_s16_nmacc_prepare#
Obtain the output exponent and shifts required for a call to vect_s16_nmacc().
The logic for computing the shifts and exponents of
vect_s16_nmacc()is identical to that forvect_s16_macc_prepare().This macro is provided as a convenience to developers and to make the code more readable.
See also
-
vect_s16_sub_prepare#
Obtain the output exponent and shifts required for a call to
vect_s16_sub().The logic for computing the shifts and exponents of
vect_s16_sub()is identical to that forvect_s32_add().This macro is provided as a convenience to developers and to make the code more readable.
See also
Functions
-
void vect_s16_clip_prepare(exponent_t *a_exp, right_shift_t *b_shr, int16_t *lower_bound, int16_t *upper_bound, const exponent_t b_exp, const exponent_t bound_exp, const headroom_t b_hr)#
Obtain the output exponent, input shift and modified bounds used by vect_s16_clip().
This function is used in conjunction with vect_s16_clip() to bound the elements of a 32-bit BFP vector to a specified range.
This function computes
a_exp,b_shr,lower_boundandupper_bound.a_expis the exponent associated with the 16-bit mantissa vector \(\bar a\) computed by vect_s32_clip().b_shris the shift parameter required by vect_s16_clip() to achieve the output exponenta_exp.lower_boundandupper_boundare the 16-bit mantissas which indicate the lower and upper clipping bounds respectively. The values are modified by this function, and the resulting values should be passed along to vect_s16_clip().b_expis the exponent associated with the input mantissa vector \(\bar b\) .bound_expis the exponent associated with the bound mantissaslower_boundandupper_boundrespectively.b_hris the headroom of \(\bar b\) . If unknown, it can be obtained using vect_s16_headroom(). Alternatively, the value0can always be safely used (but may result in reduced precision).See also
- Parameters:
a_exp – [out] Exponent associated with output mantissa vector \(\bar a\)
b_shr – [out] Signed arithmetic right-shift for \(\bar b\) used by vect_s32_clip()
lower_bound – [inout] Lower bound of clipping range
upper_bound – [inout] Upper bound of clipping range
b_exp – [in] Exponent associated with input mantissa vector \(\bar b\)
bound_exp – [in] Exponent associated with clipping bounds
lower_boundandupper_boundb_hr – [in] Headroom of input mantissa vector \(\bar b\)
-
void vect_s16_inverse_prepare(exponent_t *a_exp, unsigned *scale, const int16_t b[], const exponent_t b_exp, const unsigned length)#
Obtain the output exponent and scaling parameter used by vect_s16_inverse().
This function is used in conjunction with vect_s16_inverse() to compute the inverse of elements of a 16-bit BFP vector.
This function computes
a_expandscale.a_expis the exponent associated with output mantissa vector \(\bar a\) , and must be chosen to avoid overflow in the smallest element of the input vector, which when inverted becomes the largest output element. To maximize precision, this function choosesa_expto be the smallest exponent known to avoid saturation. Thea_expchosen by this function is derived from the exponent and smallest element of the input vector.scaleis a scaling parameter used by vect_s16_inverse() to achieve the chosen output exponent.b[]is the input mantissa vector \(\bar b\) .b_expis the exponent associated with the input mantissa vector \(\bar b\) .lengthis the number of elements in \(\bar b\) .See also
- Parameters:
a_exp – [out] Exponent of output vector \(\bar a\)
scale – [out] Scale factor to be applied when computing inverse
b – [in] Input vector \(\bar b\)
b_exp – [in] Exponent of \(\bar b\)
length – [in] Number of elements in vector \(\bar b\)
-
void vect_s16_macc_prepare(exponent_t *new_acc_exp, right_shift_t *acc_shr, right_shift_t *bc_sat, const exponent_t acc_exp, const exponent_t b_exp, const exponent_t c_exp, const headroom_t acc_hr, const headroom_t b_hr, const headroom_t c_hr)#
Obtain the output exponent and shifts needed by vect_s16_macc().
This function is used in conjunction with vect_s16_macc() to perform an element-wise multiply-accumlate of 16-bit BFP vectors.
This function computes
new_acc_expandacc_shrandbc_sat, which are selected to maximize precision in the resulting accumulator vector without causing saturation of final or intermediate values. Normally the caller will pass these outputs to their corresponding inputs of vect_s16_macc().acc_expis the exponent associated with the accumulator mantissa vector \(\bar a\) prior to the operation, whereasnew_acc_expis the exponent corresponding to the updated accumulator vector.b_expandc_expare the exponents associated with the complex input mantissa vectors \(\bar b\) and \(\bar c\) respectively.acc_hr,b_hrandc_hrare the headrooms of \(\bar a\) , \(\bar b\) and \(\bar c\) respectively. If the headroom of any of these vectors is unknown, it can be obtained by calling vect_s16_headroom(). Alternatively, the value0can always be safely used (but may result in reduced precision).- Adjusting Output Exponents
-
If a specific output exponent
desired_expis needed for the result (e.g. for emulating fixed-point arithmetic), theacc_shrandbc_satproduced by this function can be adjusted according to the following:// Presumed to be set somewhere exponent_t acc_exp, b_exp, c_exp; headroom_t acc_hr, b_hr, c_hr; exponent_t desired_exp; ... // Call prepare right_shift_t acc_shr, bc_sat; vect_s16_macc_prepare(&acc_exp, &acc_shr, &bc_sat, acc_exp, b_exp, c_exp, acc_hr, b_hr, c_hr); // Modify results right_shift_t mant_shr = desired_exp - acc_exp; acc_exp += mant_shr; acc_shr += mant_shr; bc_sat += mant_shr; // acc_shr and bc_sat may now be used in a call to vect_s16_macc()
When applying the above adjustment, the following conditions should be maintained:
bc_sat >= 0(bc_satis an unsigned right-shift)acc_shr > -acc_hr(Shifting any further left may cause saturation)
It is up to the user to ensure any such modification does not result in saturation or unacceptable loss of precision.
See also
- Parameters:
new_acc_exp – [out] Exponent associated with output mantissa vector \(\bar a\) (after macc)
acc_shr – [out] Signed arithmetic right-shift used for \(\bar a\) in vect_s16_macc()
bc_sat – [out] Unsigned arithmetic right-shift applied to the product of elements \(b_k\) and \(c_k\) in vect_s16_macc()
acc_exp – [in] Exponent associated with input mantissa vector \(\bar a\) (before macc)
b_exp – [in] Exponent associated with input mantissa vector \(\bar b\)
c_exp – [in] Exponent associated with input mantissa vector \(\bar c\)
acc_hr – [in] Headroom of input mantissa vector \(\bar a\) (before macc)
b_hr – [in] Headroom of input mantissa vector \(\bar b\)
c_hr – [in] Headroom of input mantissa vector \(\bar c\)
-
void vect_s16_mul_prepare(exponent_t *a_exp, right_shift_t *a_shr, const exponent_t b_exp, const exponent_t c_exp, const headroom_t b_hr, const headroom_t c_hr)#
Obtain the output exponent and output shift used by vect_s16_mul().
This function is used in conjunction with vect_s16_mul() to perform an element-wise multiplication of two 16-bit BFP vectors.
This function computes
a_expanda_shr.a_expis the exponent associated with mantissa vector \(\bar a\) , and must be chosen to be large enough to avoid overflow when elements of \(\bar a\) are computed. To maximize precision, this function choosesa_expto be the smallest exponent known to avoid saturation (see exception below). Thea_expchosen by this function is derived from the exponents and headrooms of associated with the input vectors.a_shris an arithmetic right-shift applied by vect_complex_s16_mul() to the 32-bit products of input elements to achieve the chosen output exponenta_exp.b_expandc_expare the exponents associated with the input mantissa vectors \(\bar b\) and \(\bar c\) respectively.b_hrandc_hrare the headroom of \(\bar b\) and \(\bar c\) respectively. If the headroom of \(\bar b\) or \(\bar c\) is unknown, they can be obtained by calling vect_s16_headroom(). Alternatively, the value0can always be safely used (but may result in reduced precision).- Adjusting Output Exponents
-
If a specific output exponent
desired_expis needed for the result (e.g. for emulating fixed-point arithmetic), thea_shrproduced by this function can be adjusted according to the following:exponent_t a_exp; right_shift_t a_shr; vect_s16_mul_prepare(&a_exp, &a_shr, b_exp, c_exp, b_hr, c_hr); exponent_t desired_exp = ...; // Value known a priori a_shr = a_shr + (desired_exp - a_exp); a_exp = desired_exp;
When applying the above adjustment, the following conditions should be maintained:
a_shr >= 0
Be aware that using a smaller value than strictly necessary for
a_shrcan result in saturation, and using larger values may result in unnecessary underflows or loss of precision.
- Notes
-
Using the outputs of this function, an output mantissa which would otherwise be
INT16_MINwill instead saturate to-INT16_MAX. This is due to the symmetric saturation logic employed by the VPU and is a hardware feature. This is a corner case which is usually unlikely and results in 1 LSb of error when it occurs.
See also
- Parameters:
a_exp – [out] Exponent of output elements of vect_s16_mul()
a_shr – [out] Right-shift supplied to vect_s16_mul()
b_exp – [in] Exponent associated with \(\bar b\)
c_exp – [in] Exponent associated with \(\bar c\)
b_hr – [in] Headroom of \(\bar b\)
c_hr – [in] Headroom of \(\bar c\)
-
void vect_s16_scale_prepare(exponent_t *a_exp, right_shift_t *a_shr, const exponent_t b_exp, const exponent_t c_exp, const headroom_t b_hr, const headroom_t c_hr)#
Obtain the output exponent and output shift used by vect_s16_scale().
This function is used in conjunction with vect_s16_scale() to perform multiplication of a 16-bit BFP vector \(\bar{b} \cdot 2^{b\_exp}\) by a 16-bit scalar \(c \cdot 2^{c\_exp}\) . The result is another 16-bit BFP vector \(\bar{a} \cdot 2^{a\_exp}\) .
This function computes
a_expanda_shr.a_expis the exponent associated with mantissa vector \(\bar a\) , and must be chosen to be large enough to avoid overflow when elements of \(\bar a\) are computed. To maximize precision, this function choosesa_expto be the smallest exponent known to avoid saturation (see exception below). Thea_expchosen by this function is derived from the exponents and headrooms of associated with the inputs.a_shris an arithmetic right-shift applied by vect_complex_s16_scale() to the 32-bit products of input elements to achieve the chosen output exponenta_exp.b_expandc_expare the exponents associated with \(\bar b\) and \(c\) respectively.b_hrandc_hrare the headroom of \(\bar b\) and \(c\) respectively. If the headroom of \(\bar b\) or \(c\) are unknown, they can be obtained by calling vect_s16_headroom(). Alternatively, the value0can always be safely used (but may result in reduced precision).- Adjusting Output Exponents
-
If a specific output exponent
desired_expis needed for the result (e.g. for emulating fixed-point arithmetic), thea_shrproduced by this function can be adjusted according to the following:exponent_t a_exp; right_shift_t a_shr; vect_s16_scale_prepare(&a_exp, &a_shr, b_exp, c_exp, b_hr, c_hr); exponent_t desired_exp = ...; // Value known a priori a_shr = a_shr + (desired_exp - a_exp); a_exp = desired_exp;
When applying the above adjustment, the following conditions should be maintained:
a_shr >= 0
Be aware that using a smaller value than strictly necessary for
a_shrcan result in saturation, and using larger values may result in unnecessary underflows or loss of precision.
- Notes
-
Using the outputs of this function, an output mantissa which would otherwise be
INT16_MINwill instead saturate to-INT16_MAX. This is due to the symmetric saturation logic employed by the VPU and is a hardware feature. This is a corner case which is usually unlikely and results in 1 LSb of error when it occurs.
See also
- Parameters:
a_exp – [out] Exponent of output elements of vect_s16_scale()
a_shr – [out] Right-shift supplied to vect_s16_scale()
b_exp – [in] Exponent associated with \(\bar b\)
c_exp – [in] Exponent associated with \(\bar c\)
b_hr – [in] Headroom of \(\bar b\)
c_hr – [in] Headroom of \(\bar c\)
-
void vect_s16_sqrt_prepare(exponent_t *a_exp, right_shift_t *b_shr, const exponent_t b_exp, const right_shift_t b_hr)#
Obtain the output exponent and shift parameter used by vect_s16_sqrt().
This function is used in conjunction withx vect_s16_sqrt() to compute the square root of elements of a 16-bit BFP vector.
This function computes
a_expandb_shr.a_expis the exponent associated with output mantissa vector \(\bar a\) , and should be chosen to maximize the precision of the results. To that end, this function choosesa_expto be the smallest exponent known to avoid saturation of the resulting mantissa vector \(\bar a\) . It is derived from the exponent and headroom of the input BFP vector.b_shris the shift parameter required by vect_s16_sqrt() to achieve the chosen output exponenta_exp.b_expis the exponent associated with the input mantissa vector \(\bar b\) .b_hris the headroom of \(\bar b\) . If it is unknown, it can be obtained using vect_s16_headroom(). Alternatively, the value0can always be safely used (but may result in reduced precision).- Adjusting Output Exponents
-
If a specific output exponent
desired_expis needed for the result (e.g. for emulating fixed-point arithmetic), theb_shrproduced by this function can be adjusted according to the following:exponent_t a_exp; right_shift_t b_shr; vect_s16_mul_prepare(&a_exp, &b_shr, b_exp, c_exp, b_hr, c_hr); exponent_t desired_exp = ...; // Value known a priori b_shr = b_shr + (desired_exp - a_exp); a_exp = desired_exp;
When applying the above adjustment, the following condition should be maintained:
b_hr + b_shr >= 0
Be aware that using smaller values than strictly necessary for
b_shrcan result in saturation, and using larger values may result in unnecessary underflows or loss of precision.Also, if a larger exponent is used than necessary, a larger
depthparameter (see vect_s16_sqrt()) will be required to achieve the same precision, as the results are computed bit by bit, starting with the most significant bit.
See also
- Parameters:
a_exp – [out] Exponent of outputs of vect_s16_sqrt()
b_shr – [out] Right-shift to be applied to elements of \(\bar b\)
b_exp – [in] Exponent of vector{b}
b_hr – [in] Headroom of vector{b}
-
vect_s16_add_prepare#