Add integer divide with floor for coordinate calculation

Align with the change in the spec.
Define idiv_floor to give equivalent behavior to the floating-point
floor function for image coordinate calculation.

Change-Id: Ice06d354d58b1bb0dfedab55c9cc9eac1598b50c
Signed-off-by: TatWai Chong <tatwai.chong@arm.com>
diff --git a/reference_model/src/graph_node.cc b/reference_model/src/graph_node.cc
index 1781e40..791ed45 100644
--- a/reference_model/src/graph_node.cc
+++ b/reference_model/src/graph_node.cc
@@ -229,3 +229,16 @@
     result = input1 / input2;
     return 0;
 }
+
+// perform an integer division with rounding towards minus infinity
+int GraphNode::idiv_floor(int input1, int input2)
+{
+    ERROR_IF(input2 == 0, "idiv_floor: input2 must not be zero");
+    int result = input1 / input2;
+
+    if (result * input2 > input1)
+    {
+        result--;
+    }
+    return result;
+}
diff --git a/reference_model/src/graph_node.h b/reference_model/src/graph_node.h
index 900f4b8..440ca04 100644
--- a/reference_model/src/graph_node.h
+++ b/reference_model/src/graph_node.h
@@ -256,6 +256,7 @@
 
     // Helper functions.
     int idiv_check(int input1, int input2, int& result);
+    int idiv_floor(int input1, int input2);
 
 protected:
     // Print out a node validation error
diff --git a/reference_model/src/ops/image.cc b/reference_model/src/ops/image.cc
index cf2b60a..b1b762f 100644
--- a/reference_model/src/ops/image.cc
+++ b/reference_model/src/ops/image.cc
@@ -159,16 +159,15 @@
                     int32_t y = oy * scale_y_d + offset_y;
                     int32_t x = ox * scale_x_d + offset_x;
 
-                    int32_t iy;
-                    int32_t ix;
+                    int16_t iy = idiv_floor(y, scale_y_n);
+                    int16_t ix = idiv_floor(x, scale_x_n);
+
                     resize_t dy;
                     resize_t dx;
                     if (std::is_same<resize_t, double>::value)
                     {
                         const double fy_double = static_cast<double>(y) / static_cast<double>(scale_y_n);
                         const double fx_double = static_cast<double>(x) / static_cast<double>(scale_x_n);
-                        iy                     = floor(fy_double);
-                        ix                     = floor(fx_double);
 
                         dy = (resize_t)(fy_double - iy);
                         dx = (resize_t)(fx_double - ix);
@@ -177,8 +176,6 @@
                     {
                         const float fy = static_cast<float>(y) / static_cast<float>(scale_y_n);
                         const float fx = static_cast<float>(x) / static_cast<float>(scale_x_n);
-                        iy             = floor(fy);
-                        ix             = floor(fx);
 
                         if (std::is_floating_point<resize_t>::value || (typeid(resize_t) == typeid(Eigen::bfloat16)) ||
                             (typeid(resize_t) == typeid(half_float::half)))