diff options
author | Yann Herklotz <git@yannherklotz.com> | 2021-09-22 19:26:01 +0100 |
---|---|---|
committer | Yann Herklotz <git@yannherklotz.com> | 2021-09-22 19:26:01 +0100 |
commit | 2ff1316847b9d338a792f67b7b9f6364d4b65551 (patch) | |
tree | 6aaf069a05f889d6f3fe012332a5e74dd8707429 /benchmarks/polybench-syn-div/include | |
parent | c114bd7a269824623f2dbb41322d95d5056fca02 (diff) | |
parent | 8386bed39f413bb461c19debbad92e85f927c4b5 (diff) | |
download | vericert-2ff1316847b9d338a792f67b7b9f6364d4b65551.tar.gz vericert-2ff1316847b9d338a792f67b7b9f6364d4b65551.zip |
Merge remote-tracking branch 'origin/develop' into develop
Diffstat (limited to 'benchmarks/polybench-syn-div/include')
-rw-r--r-- | benchmarks/polybench-syn-div/include/misc.h | 105 |
1 files changed, 105 insertions, 0 deletions
diff --git a/benchmarks/polybench-syn-div/include/misc.h b/benchmarks/polybench-syn-div/include/misc.h new file mode 100644 index 0000000..664677c --- /dev/null +++ b/benchmarks/polybench-syn-div/include/misc.h @@ -0,0 +1,105 @@ +unsigned int modulo(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 r0; +} + +int smodulo(int N, int D) { + if (D < 0) { + if (N < 0) + return modulo(-N, -D); + else + return -modulo(N, -D); + } else { + if (N < 0) + return -modulo(-N, D); + else + return modulo(N, D); + } +} + +unsigned divider_fast(unsigned x, unsigned y) { + unsigned r0, q0, y0, y1; + + r0 = x; + q0 = 0; + y0 = y; + y1 = y; + do { + y1 = 2 * y1; + } while (y1 <= x); + do { + y1 /= 2; + q0 *= 2; + if (r0 >= y1) { + 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. + */ +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); + } +} + +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); + } +} |