Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/marian-nmt/intgemm/intgemm.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMateusz Chudyk <mateuszchudyk@gmail.com>2020-03-02 13:18:15 +0300
committerMateusz Chudyk <mateuszchudyk@gmail.com>2020-03-27 17:08:05 +0300
commitdcf3a5ebc62849b823e38400873e2de81c8d2e9c (patch)
tree416a65b3744b950b0ebbccf168070b55fbc10717
parentf982b997eb4edc4e8dc63b440bd04c28038f7bd9 (diff)
Add round_up function
-rw-r--r--test/utils_test.cc7
-rw-r--r--utils.h7
2 files changed, 14 insertions, 0 deletions
diff --git a/test/utils_test.cc b/test/utils_test.cc
index 8596104..9c2fb06 100644
--- a/test/utils_test.cc
+++ b/test/utils_test.cc
@@ -78,5 +78,12 @@ TEST_CASE("Static loop with mult-dim iterator (Iterator<5, 2>)",) {
CHECK(result == 11223344);
}
+TEST_CASE("Round up",) {
+ CHECK(round_up(0, 5) == 0);
+ CHECK(round_up(1, 5) == 5);
+ CHECK(round_up(4, 5) == 5);
+ CHECK(round_up(6, 5) == 10);
+}
+
}
}
diff --git a/utils.h b/utils.h
index da4317b..94b16d3 100644
--- a/utils.h
+++ b/utils.h
@@ -199,4 +199,11 @@ __attribute__((always_inline)) static inline void StaticLoop(Args&&... args) {
StaticLoop<Body, typename StaticLoopIterator::next>(std::forward<Args>(args)...);
}
+/*
+ * Round up
+ */
+static constexpr Index round_up(Index value, Index factor) {
+ return (value + factor - 1) / factor * factor;
+}
+
}