Skip to content

Commit b28fc7a

Browse files
feat: matching the expected number of elements for array to load
arguments, accommodating for signed variables too
1 parent 7454872 commit b28fc7a

File tree

1 file changed

+18
-4
lines changed

1 file changed

+18
-4
lines changed

crates/intrinsic-test/src/common/intrinsic_helpers.rs

Lines changed: 18 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -284,6 +284,7 @@ impl IntrinsicType {
284284
kind: TypeKind::Vector,
285285
bit_len: Some(bit_len @ (128 | 256 | 512)),
286286
simd_len,
287+
vec_len,
287288
..
288289
} => {
289290
let (prefix, suffix) = match language {
@@ -292,14 +293,27 @@ impl IntrinsicType {
292293
};
293294
let body_indentation = indentation.nested();
294295
let effective_bit_len = 32;
295-
let effective_vec_len = bit_len / effective_bit_len;
296296
format!(
297297
"{prefix}\n{body}\n{indentation}{suffix}",
298-
body = (0..(simd_len.unwrap_or(1) * effective_vec_len + loads - 1))
298+
body = (0..(vec_len.unwrap_or(1) * simd_len.unwrap_or(1) + loads - 1))
299299
.format_with(",\n", |i, fmt| {
300300
let src = value_for_array(effective_bit_len, i);
301-
assert!(src == 0 || src.ilog2() < *bit_len);
302-
fmt(&format_args!("{body_indentation}{src:#x}"))
301+
assert!(src == 0 || src.ilog2() < effective_bit_len);
302+
if (src >> (effective_bit_len - 1)) != 0 {
303+
// `src` is a two's complement representation of a negative value.
304+
let mask = !0u64 >> (64 - effective_bit_len);
305+
let ones_compl = src ^ mask;
306+
let twos_compl = ones_compl + 1;
307+
if (twos_compl == src) && (language == &Language::C) {
308+
// `src` is INT*_MIN. C requires `-0x7fffffff - 1` to avoid
309+
// undefined literal overflow behaviour.
310+
fmt(&format_args!("{body_indentation}-{ones_compl:#x} - 1"))
311+
} else {
312+
fmt(&format_args!("{body_indentation}-{twos_compl:#x}"))
313+
}
314+
} else {
315+
fmt(&format_args!("{body_indentation}{src:#x}"))
316+
}
303317
})
304318
)
305319
}

0 commit comments

Comments
 (0)