diff options
author | Yann Herklotz <git@yannherklotz.com> | 2020-11-09 19:33:52 +0000 |
---|---|---|
committer | Yann Herklotz <git@yannherklotz.com> | 2020-11-09 19:33:52 +0000 |
commit | f2f21f405ae0a1f457f7bc32d5053f0a92959e72 (patch) | |
tree | 86b73d98fee0c3b15ce0be02cc4d54f8946530c0 /include/hls.h | |
parent | 56ea621762c865c1c71bdc7ad99afc4f2c291d5c (diff) | |
download | vericert-f2f21f405ae0a1f457f7bc32d5053f0a92959e72.tar.gz vericert-f2f21f405ae0a1f457f7bc32d5053f0a92959e72.zip |
Change and add back HTLgen
Diffstat (limited to 'include/hls.h')
-rw-r--r-- | include/hls.h | 39 |
1 files changed, 33 insertions, 6 deletions
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 |