55#define USE_64BIT_MUL 0
76inline void muldwu(uint32_t w[], uint32_t u, uint32_t v)
78 const uint32_t u0 = u >> 16U;
79 const uint32_t u1 = u & 0xFFFFU;
80 const uint32_t v0 = v >> 16U;
81 const uint32_t v1 = v & 0xFFFFU;
84 const uint32_t w3 = t & 0xFFFFU;
85 uint32_t k = t >> 16U;
88 const uint32_t w2 = t & 0xFFFFU;
89 const uint32_t w1 = t >> 16U;
94 w[0] = u0 * v0 + w1 + k;
95 w[1] = (t << 16U) + w3;
116inline uint32_t
fp_mulu(uint32_t u, uint32_t v, uint_fast8_t shift)
120 const uint64_t w = (uint64_t)u * (uint64_t)v;
121 return (uint32_t)((w >> shift) + ((w >> (shift-1)) & 1U));
123 uint32_t tmp[2] = { 0 };
126 assert(shift ? tmp[0] <= (UINT32_MAX >> (32-shift)) : tmp[0] == 0);
129 return ((tmp[0] << (32 - shift)) +
fp_rndu(tmp[1], shift));
131 return tmp[1] > (UINT32_MAX >> 1) ? tmp[0] + 1 : tmp[0];
152inline int32_t
fp_muls(int32_t u, int32_t v, uint_fast8_t shift)
154 int_fast8_t sign = 1;
157 if(u < 0) { u2 = (uint32_t)-u; sign = -sign; }
else { u2 = (uint32_t)u; }
158 if(v < 0) { v2 = (uint32_t)-v; sign = -sign; }
else { v2 = (uint32_t)v; }
160 const uint32_t res =
fp_mulu(u2, v2, shift);
162 assert(sign > 0 ? res <= 0x7FFFFFFFU : res <= 0x80000000U);
164 return sign > 0 ? (int32_t)res : -(int32_t)res;
191 uint32_t msk = 0xFFFFU;
192 uint32_t a = (u >> 16U) * v;
193 uint32_t b = (msk & u) * v;
198 uint32_t msk = ~(0xFFFFFFFFU << shift);
199 uint32_t a = (u >> shift) * v;
200 uint32_t b =
fp_rndu((msk & u) * v, shift);
This file is part of the AFBR-S50 API.
This file is part of the AFBR-S50 API.
uint32_t fp_rndu(uint32_t Q, uint_fast8_t n)
Converting with rounding from UQx.n1 to UQx.n2.
Definition fp_rnd.h:60
int32_t fp_mul_s32_u16(int32_t u, uint16_t v, uint_fast8_t shift)
48-bit implementation of an unsigned/signed multiplication with fixed point format.
Definition fp_mul.h:223
int32_t fp_muls(int32_t u, int32_t v, uint_fast8_t shift)
64-bit implementation of a signed multiplication with fixed point format.
Definition fp_mul.h:152
uint32_t fp_mul_u32_u16(uint32_t u, uint16_t v, uint_fast8_t shift)
48-bit implementation of a unsigned multiplication with fixed point format.
Definition fp_mul.h:185
uint32_t fp_mulu(uint32_t u, uint32_t v, uint_fast8_t shift)
64-bit implementation of an unsigned multiplication with fixed point format.
Definition fp_mul.h:116
void muldwu(uint32_t w[], uint32_t u, uint32_t v)
Long multiplication of two unsigned 32-bit into an 64-bit value on 32-bit architecture.
Definition fp_mul.h:76