IVGCVSW-3223 Use GetIndex from DataLayoutIndexed.cpp in ConvImpl.cpp

 * Used DataLayoutIndexed::GetIndex wherever possible
 * Removed unnecessary GetOffset function

Change-Id: Ieaad2def60e8de48dbc3afb63e550ac5883b3690
Signed-off-by: Matteo Martincigh <matteo.martincigh@arm.com>
diff --git a/src/backends/reference/workloads/ConvImpl.cpp b/src/backends/reference/workloads/ConvImpl.cpp
index 6a5ac53..801a29a 100644
--- a/src/backends/reference/workloads/ConvImpl.cpp
+++ b/src/backends/reference/workloads/ConvImpl.cpp
@@ -68,26 +68,6 @@
     return (x >> exponent) + (remainder > threshold ? 1 : 0);
 }
 
-inline unsigned int GetOffset(DataLayout& dataLayout, const TensorShape& shape, unsigned int b, unsigned int c,
-                              unsigned int h, unsigned int w)
-{
-    switch (dataLayout)
-    {
-        case DataLayout::NHWC:
-            b *= shape[1] * shape[2] * shape[3];
-            h *= shape[2] * shape[3];
-            w *= shape[3];
-            break;
-        case DataLayout::NCHW:
-        default:
-            b *= shape[1] * shape[2] * shape[3];
-            c *= shape[2] * shape[3];
-            h *= shape[3];
-            break;
-    }
-    return b + c + h + w;
-}
-
 void Convolve(const TensorShape& rInputShape,
               Decoder<float>& rInputDecoder,
               const TensorShape& rOutputShape,
@@ -167,24 +147,15 @@
                                 }
                                 else
                                 {
-                                    if (dataLayout == DataLayout::NHWC)
-                                    {
-                                        filterIndex = cOutput * filterHeight * filterWidth * inputChannels +
-                                                      yFilter * filterWidth * inputChannels +
-                                                      xFilter * inputChannels +
-                                                      cInput;
-                                    }
-                                    else
-                                    {
-                                        filterIndex = cOutput * filterWidth * filterHeight * inputChannels +
-                                                      cInput  * filterWidth * filterHeight +
-                                                      yFilter * filterWidth +
-                                                      xFilter;
-                                    }
+                                    filterIndex = dataLayoutIndexed.GetIndex(rFilterShape,
+                                                                             cOutput,
+                                                                             cInput,
+                                                                             yFilter,
+                                                                             xFilter);
                                 }
-                                rFilterDecoder += filterIndex;
+
+                                rFilterDecoder[filterIndex];
                                 float filterValue = rFilterDecoder.Get();
-                                rFilterDecoder -= filterIndex;
 
                                 unsigned int yInput = yOutput * yStride + yFilter * yDilation;
                                 unsigned int xInput = xOutput * xStride + xFilter * xDilation;
@@ -199,26 +170,16 @@
                                 }
                                 else
                                 {
-                                    unsigned int inputIndex;
+                                    unsigned int inputIndex = dataLayoutIndexed.GetIndex(rInputShape,
+                                                                                         batchIdx,
+                                                                                         cInput,
+                                                                                         yInput - paddingTop,
+                                                                                         xInput - paddingLeft);
 
-                                    if (dataLayout == DataLayout::NHWC)
-                                    {
-                                        inputIndex = batchIdx * inputHeight * inputWidth  * inputChannels +
-                                                     (yInput - paddingTop) * inputWidth * inputChannels +
-                                                     (xInput - paddingLeft) * inputChannels +
-                                                     cInput;
-                                    }
-                                    else
-                                    {
-                                        inputIndex = batchIdx * inputWidth * inputHeight * inputChannels +
-                                                     inputWidth * inputHeight * cInput +
-                                                     inputWidth * (yInput - paddingTop) +
-                                                     xInput - paddingLeft;
-                                    }
-                                    rInputDecoder += inputIndex;
+                                    rInputDecoder[inputIndex];
                                     inputValue = rInputDecoder.Get();
-                                    rInputDecoder -= inputIndex;
                                 }
+
                                 sum += filterValue * inputValue;
                             }
                         }
@@ -226,15 +187,14 @@
 
                     if (biasEnabled)
                     {
-                        *pBiasDecoder += cOutput;
+                        (*pBiasDecoder)[cOutput];
                         sum += pBiasDecoder->Get();
-                        *pBiasDecoder -= cOutput;
                     }
-                    unsigned int outIdx = GetOffset(dataLayout, rOutputShape, batchIdx, cOutput, yOutput, xOutput);
 
-                    rOutputEncoder += outIdx;
+                    unsigned int outIdx = dataLayoutIndexed.GetIndex(rOutputShape, batchIdx, cOutput, yOutput, xOutput);
+
+                    rOutputEncoder[outIdx];
                     rOutputEncoder.Set(sum);
-                    rOutputEncoder -= outIdx;
                 }
             }
         }