From 3da62dfa0da290dbbb39e411ca2187703429f916 Mon Sep 17 00:00:00 2001
From: Dominic Symes <dominic.symes@arm.com>
Date: Thu, 22 Oct 2020 13:57:22 +0100
Subject: ARITHMETIC_RIGHT_SHIFT: Add rounding

Add rounding mode to shift right and clarify
that shift values cannot be negative.

Signed-off-by: Dominic Symes <dominic.symes@arm.com>
Change-Id: I7995c8dfa6f16f9ca4dcbf5241692fcd940e509b
---
 chapters/ewise_binary.adoc | 10 +++++++---
 1 file changed, 7 insertions(+), 3 deletions(-)

(limited to 'chapters/ewise_binary.adoc')

diff --git a/chapters/ewise_binary.adoc b/chapters/ewise_binary.adoc
index 9c0e71c..4da63de 100644
--- a/chapters/ewise_binary.adoc
+++ b/chapters/ewise_binary.adoc
@@ -57,6 +57,7 @@ Elementwise arithmetic right shift of input1 by the amount specified in input2.
 
 |Input|in_t*|input1|shape1|Input tensor
 |Input|in_t*|input2|shape2|Input tensor with the same rank as input1
+|Input|bool |round |- | If true then the shift is rounded
 |Output|in_t*|output|shape|Output tensor with broadcast shape if necessary
 |===
 
@@ -69,8 +70,11 @@ for_each (index in shape) {
     index2 = apply_broadcast(shape, shape2, index)
     in_t value1 = tensor_read<in_t>(input1, shape1, index1)
     in_t value2 = tensor_read<in_t>(input2, shape2, index2)
-    assert(value2 <= 31)
+    assert(0 <= value2 && value2 <= 31)
     in_t acc = value1 >> value2
+    if (round==true && value2>0 && (value1>>(value2-1))&1!=0) {
+        acc = acc + 1;
+    }
     acc = apply_clip(acc, minimum<in_t>, maximum<in_t>)
     tensor_write<in_t>(output, shape, index, acc)
 }
@@ -263,7 +267,7 @@ for_each (index in shape) {
     index2 = apply_broadcast(shape, shape2, index)
     in_t value1 = tensor_read<in_t>(input1, shape1, index1)
     in_t value2 = tensor_read<in_t>(input2, shape2, index2)
-    assert(value2 <= 31)
+    assert(0 <= value2 && value2 <= 31)
     in_t acc = value1 << value2
     tensor_write<in_t>(output, shape, index, acc)
 }
@@ -302,7 +306,7 @@ for_each (index in shape) {
     index2 = apply_broadcast(shape, shape2, index)
     in_t value1 = tensor_read<in_t>(input1, shape1, index1)
     in_t value2 = tensor_read<in_t>(input2, shape2, index2)
-    assert(value2 <= 31)
+    assert(0 <= value2 && value2 <= 31)
     in_t acc = (unsigned in_t)value1 >> value2
     tensor_write<in_t>(output, shape, index, acc)
 }
-- 
cgit v1.2.1

