aboutsummaryrefslogtreecommitdiffstats
path: root/include
diff options
context:
space:
mode:
authorYann Herklotz <git@yannherklotz.com>2020-11-07 10:12:57 +0000
committerYann Herklotz <git@yannherklotz.com>2020-11-07 10:12:57 +0000
commit8c9f2c7ae763f21f605248baef6f512bce005bbe (patch)
tree2521464569511158e31a752b9266a517e4ed12dc /include
parentf5907f75cb108a584ce0a363d81bcdc10d7ee978 (diff)
downloadvericert-8c9f2c7ae763f21f605248baef6f512bce005bbe.tar.gz
vericert-8c9f2c7ae763f21f605248baef6f512bce005bbe.zip
Add hls include file
Diffstat (limited to 'include')
-rw-r--r--include/hls.h45
1 files changed, 45 insertions, 0 deletions
diff --git a/include/hls.h b/include/hls.h
new file mode 100644
index 0000000..b243fea
--- /dev/null
+++ b/include/hls.h
@@ -0,0 +1,45 @@
+#ifndef VERICERT_HLS_H
+#define VERICERT_HLS_H
+
+/*
+ * Divider C implementation for faster frequency division.
+ */
+unsigned int divider(unsigned int x, unsigned int y) {
+ unsigned int r0, q0, y0, y1;
+
+ r0 = x;
+ q0 = 0;
+ y0 = y;
+ y1 = y;
+ do {
+ y1 = 2 * y1;
+ } while (y1 <= x);
+ do {
+ y1 = y1 / 2;
+ q0 = 2 * q0;
+ if (r0 >= y1) {
+ r0 = r0 - y1;
+ q0 = q0 + 1;
+ }
+ } while ((int)y1 != (int)y0);
+ return q0;
+}
+
+/*
+ * Signed division operation for faster frequency division.
+ */
+int sdivider(int N, int D) {
+ if (D < 0) {
+ if (N < 0)
+ return divider(-N, -D);
+ else
+ return -divider(N, -D);
+ } else {
+ if (N < 0)
+ return -divider(-N, D);
+ else
+ return divider(N, D);
+ }
+}
+
+#endif