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

Last change on this file since 5757 was 5755, checked in by nmedfort, 19 months ago

Bug fixes and simplified MultiBlockKernel? logic

File size: 1.3 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
19ProcessingRate::RateValue gcd(const ProcessingRate::RateValue & x, const ProcessingRate::RateValue & y) {
20    const auto n = boost::gcd(x.numerator(), y.numerator());
21    if (LLVM_LIKELY(x.denominator() == 1 && y.denominator() == 1)) {
22        return ProcessingRate::RateValue(n, 1);
23    } else { // GCD((a/b),(c/d)) = GCD(a,c) / LCM(b,d)
24        return ProcessingRate::RateValue(n, boost::lcm(x.denominator(), y.denominator()));
25    }
26}
27
28}
Note: See TracBrowser for help on using the repository browser.