aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDominic Symes <dominic.symes@arm.com>2021-11-24 16:59:56 +0000
committerDominic Symes <dominic.symes@arm.com>2021-11-24 17:07:02 +0000
commitd4cf0738c55ce73dae5e25e0fbec4d8b3f603e69 (patch)
treebe46b7ea96479b9b75af56888ad08db6ed246271
parenta0e9a523fcee7f25d4a81289cf10e9f9082ee878 (diff)
downloadspecification-d4cf0738c55ce73dae5e25e0fbec4d8b3f603e69.tar.gz
MUL: Correct code for the case of value2<0
The previous call to apply_scale() was not valid for value2<0. Signed-off-by: Dominic Symes <dominic.symes@arm.com> Change-Id: I3fbf38eaad964efdb0c4920da1a61aee67c9bba9
-rw-r--r--chapters/ewise_binary.adoc7
1 files changed, 6 insertions, 1 deletions
diff --git a/chapters/ewise_binary.adoc b/chapters/ewise_binary.adoc
index aa1c86c..6fecc2a 100644
--- a/chapters/ewise_binary.adoc
+++ b/chapters/ewise_binary.adoc
@@ -544,6 +544,7 @@ Axis of size 1 will be broadcast, as necessary. Rank of input tensors must match
[source,c++]
----
+ERROR_IF(in_t != int32_t && shift > 0);
for_each(index in shape) {
index1 = apply_broadcast(shape, shape1, index);
index2 = apply_broadcast(shape, shape2, index);
@@ -551,7 +552,11 @@ for_each(index in shape) {
in_t value2 = tensor_read<in_t>(input2, shape2, index2);
out_t result;
if (in_t == int32_t && shift > 0) {
- result = apply_scale_32(value1, value2, shift);
+ int64_t product = (int64_t)value1 * (int64_t)value2;
+ int64_t round = (int64_t)1 << (shift-1);
+ product = (product + round) >> shift;
+ REQUIRE(product >= minimum<int32_t> && product <= maximum<int32_t>)
+ result = product;
} else {
result = value1 * value2; // low 32-bits of result for int32_t
}