source: icGREP/icgrep-devel/icgrep/kernels/processing_rate.cpp @ 6004

Last change on this file since 6004 was 5782, checked in by nmedfort, 22 months ago

Initial check-in of LookAhead? support; modified LineBreakKernel? to compute CR+LF using LookAhead?(1) + misc. fixes.

File size: 2.0 KB
Line 
1#include "processing_rate.h"
2#include <llvm/Support/Compiler.h>
3
4namespace kernel {
5
6/** ------------------------------------------------------------------------------------------------------------- *
7 * @brief lcm
8 ** ------------------------------------------------------------------------------------------------------------- */
9ProcessingRate::RateValue lcm(const ProcessingRate::RateValue & x, const ProcessingRate::RateValue & y) {
10    if (LLVM_LIKELY(x.denominator() == 1 && y.denominator() == 1)) {
11        return ProcessingRate::RateValue(boost::lcm(x.numerator(), y.numerator()), 1);
12    } else { // LCM((a/b),(c/d)) = LCM ((a*LCM(b,d))/b, (c*LCM(b,d))/d) / LCM(b,d)
13        const auto d = boost::lcm(x.denominator(), y.denominator());
14        const auto n = boost::lcm((x.numerator() * d) / x.denominator(), (y.numerator() * d) / y.denominator());
15        return ProcessingRate::RateValue(n, d);
16    }
17}
18
19/** ------------------------------------------------------------------------------------------------------------- *
20 * @brief gcd
21 ** ------------------------------------------------------------------------------------------------------------- */
22ProcessingRate::RateValue gcd(const ProcessingRate::RateValue & x, const ProcessingRate::RateValue & y) {
23    const auto n = boost::gcd(x.numerator(), y.numerator());
24    if (LLVM_LIKELY(x.denominator() == 1 && y.denominator() == 1)) {
25        return ProcessingRate::RateValue(n, 1);
26    } else { // GCD((a/b),(c/d)) = GCD(a,c) / LCM(b,d)
27        return ProcessingRate::RateValue(n, boost::lcm(x.denominator(), y.denominator()));
28    }
29}
30
31/** ------------------------------------------------------------------------------------------------------------- *
32 * @brief roundUp
33 ** ------------------------------------------------------------------------------------------------------------- */
34unsigned ceiling(const ProcessingRate::RateValue & r) {
35    if (LLVM_LIKELY(r.denominator() == 1)) {
36        return r.numerator();
37    } else {
38        return (r.numerator() + r.denominator() - 1) / r.denominator();
39    }
40}
41
42
43}
Note: See TracBrowser for help on using the repository browser.