forge
Explore
Log in

Don't you dare go Hollow

edith_codecs

Clone
★ 0

0 watching0 forksRust370.3 MiB9b67700Tahinli3 days ago4021 commits

math.rs27 lines, 622 bytesHistoryRawDownload
1//! Fixed-point helpers shared by the dequantizer and the synthesis bank.
2
3/// Round-to-nearest right shift of a 64-bit product, truncated to 32 bits.
4#[inline]
5pub(crate) fn norm(a: i64, bits: u32) -> i32 {
6 if bits > 0 {
7 ((a + (1i64 << (bits - 1))) >> bits) as i32
8 } else {
9 a as i32
10 }
11}
12
13#[inline]
14pub(crate) fn mul(a: i32, b: i32, bits: u32) -> i32 {
15 norm(a as i64 * b as i64, bits)
16}
17
18#[inline]
19pub(crate) fn mul23(a: i32, b: i32) -> i32 {
20 mul(a, b, 23)
21}
22
23/// Clip to the signed 24-bit range.
24#[inline]
25pub(crate) fn clip23(a: i32) -> i32 {
26 a.clamp(-(1 << 23), (1 << 23) - 1)
27}