From a94927a11d67e28daf3d2c8dac2713070b31ac68 Mon Sep 17 00:00:00 2001 From: David Mak Date: Thu, 7 Mar 2024 13:01:06 +0800 Subject: [PATCH] core: Update __builtin_assume expressions No dimension size should be 0. --- nac3core/src/codegen/irrt/irrt.c | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/nac3core/src/codegen/irrt/irrt.c b/nac3core/src/codegen/irrt/irrt.c index e9872b0c..bbe27ce8 100644 --- a/nac3core/src/codegen/irrt/irrt.c +++ b/nac3core/src/codegen/irrt/irrt.c @@ -205,8 +205,8 @@ uint32_t __nac3_ndarray_calc_size( uint32_t num_elems = 1; for (uint32_t i = 0; i < list_len; ++i) { uint64_t val = list_data[i]; - __builtin_assume(val >= 0); - num_elems *= list_data[i]; + __builtin_assume(val > 0); + num_elems *= val; } return num_elems; } @@ -218,8 +218,8 @@ uint64_t __nac3_ndarray_calc_size64( uint64_t num_elems = 1; for (uint64_t i = 0; i < list_len; ++i) { uint64_t val = list_data[i]; - __builtin_assume(val >= 0); - num_elems *= list_data[i]; + __builtin_assume(val > 0); + num_elems *= val; } return num_elems; } @@ -233,6 +233,7 @@ void __nac3_ndarray_calc_nd_indices( uint32_t stride = 1; for (uint32_t dim = 0; dim < num_dims; dim++) { uint32_t i = num_dims - dim - 1; + __builtin_assume(dims[i] > 0); idxs[i] = (index / stride) % dims[i]; stride *= dims[i]; } @@ -247,6 +248,7 @@ void __nac3_ndarray_calc_nd_indices64( uint64_t stride = 1; for (uint64_t dim = 0; dim < num_dims; dim++) { uint64_t i = num_dims - dim - 1; + __builtin_assume(dims[i] > 0); idxs[i] = (index / stride) % dims[i]; stride *= dims[i]; } @@ -266,6 +268,7 @@ uint32_t __nac3_ndarray_flatten_index( idx += (stride * indices[ri]); } + __builtin_assume(dims[i] > 0); stride *= dims[ri]; } return idx; @@ -285,6 +288,7 @@ uint64_t __nac3_ndarray_flatten_index64( idx += (stride * indices[ri]); } + __builtin_assume(dims[i] > 0); stride *= dims[ri]; } return idx;