aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorEric Kunze <eric.kunze@arm.com>2023-08-31 16:14:05 -0700
committerEric Kunze <eric.kunze@arm.com>2023-09-11 21:59:25 +0000
commitfe2ac6d7b9cbc7de4befa128a1ac514712030e74 (patch)
tree98d36e9c39a4aa2986dbbb3d71b10ff744bf1a3b
parentb203512ca3583fd0968ea281aedec2a840b6e58b (diff)
downloadspecification-fe2ac6d7b9cbc7de4befa128a1ac514712030e74.tar.gz
Add integer divide with floor for coordinate calculation
Define idiv_floor to give equivalent behavior to the floating-point floor function for image coordinate calculation. Change-Id: Id6268794b1e3ce5cc1114bda74dd06b892457a8e Signed-off-by: Eric Kunze <eric.kunze@arm.com>
-rw-r--r--chapters/image.adoc4
-rw-r--r--chapters/pseudocode.adoc10
2 files changed, 12 insertions, 2 deletions
diff --git a/chapters/image.adoc b/chapters/image.adoc
index da839f8..59e5ddf 100644
--- a/chapters/image.adoc
+++ b/chapters/image.adoc
@@ -85,8 +85,8 @@ for_each(0 <= n < N, 0 <= oy < OH, 0 <= ox < OW; 0 <= c < C) {
int32_t y = oy * scale_y_d + offset_y;
int32_t x = ox * scale_x_d + offset_x;
- int16_t iy = floor(y / scale_y_n);
- int16_t ix = floor(x / scale_x_n);
+ int16_t iy = idiv_floor(y, scale_y_n);
+ int16_t ix = idiv_floor(x, scale_x_n);
int16_t ry = y - iy * scale_y_n; // (y % scale_y_n)
int16_t rx = x - ix * scale_x_n; // (x % scale_x_n)
diff --git a/chapters/pseudocode.adoc b/chapters/pseudocode.adoc
index 55c35d4..d674c9c 100644
--- a/chapters/pseudocode.adoc
+++ b/chapters/pseudocode.adoc
@@ -477,6 +477,16 @@ int32_t idiv_check(int32_t input1, int32_t input2) {
return input1 / input2; // exact quotient without rounding
}
+// perform an integer division with rounding towards minus infinity
+
+int32_t idiv_floor(int32_t input1, int32_t input2) {
+ int32_t rval = input1 / input2;
+ if (rval * input2 > input1) {
+ rval--;
+ }
+ return rval;
+}
+
int32_t length(in_t input)
return number of elements in input list