From f2f21f405ae0a1f457f7bc32d5053f0a92959e72 Mon Sep 17 00:00:00 2001 From: Yann Herklotz Date: Mon, 9 Nov 2020 19:33:52 +0000 Subject: Change and add back HTLgen --- include/hls.h | 39 +++++++++++++++++++++++++++++++++------ 1 file changed, 33 insertions(+), 6 deletions(-) (limited to 'include') diff --git a/include/hls.h b/include/hls.h index b243fea..61c336b 100644 --- a/include/hls.h +++ b/include/hls.h @@ -4,8 +4,8 @@ /* * Divider C implementation for faster frequency division. */ -unsigned int divider(unsigned int x, unsigned int y) { - unsigned int r0, q0, y0, y1; +unsigned divider_fast(unsigned x, unsigned y) { + unsigned r0, q0, y0, y1; r0 = x; q0 = 0; @@ -15,16 +15,29 @@ unsigned int divider(unsigned int x, unsigned int y) { y1 = 2 * y1; } while (y1 <= x); do { - y1 = y1 / 2; - q0 = 2 * q0; + y1 /= 2; + q0 *= 2; if (r0 >= y1) { - r0 = r0 - y1; - q0 = q0 + 1; + r0 -= y1; + q0++; } } while ((int)y1 != (int)y0); return q0; } +unsigned divider(unsigned x, unsigned y) { + unsigned q0, acc; + q0 = 0; + acc = y; + + while (acc <= x) { + q0++; + acc += y; + } + + return q0; +} + /* * Signed division operation for faster frequency division. */ @@ -42,4 +55,18 @@ int sdivider(int N, int D) { } } +int sdivider_fast(int N, int D) { + if (D < 0) { + if (N < 0) + return divider_fast(-N, -D); + else + return -divider_fast(N, -D); + } else { + if (N < 0) + return -divider_fast(-N, D); + else + return divider_fast(N, D); + } +} + #endif -- cgit