Skip to content

Commit acb5850

Browse files
authored
Properly initialize bf16 inputs in simd_op_check (#8849)
1 parent 602a5c0 commit acb5850

1 file changed

Lines changed: 8 additions & 4 deletions

File tree

test/correctness/simd_op_check.h

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -401,14 +401,18 @@ class SimdOpCheckTest {
401401
inputs[i].as<double>().for_each_value([&](double &f) { f = (rng() & 0xfff) / 8.0 - 0xff; });
402402
} else if (t == Float(16)) {
403403
inputs[i].as<float16_t>().for_each_value([&](float16_t &f) { f = float16_t((rng() & 0xff) / 8.0f - 0xf); });
404+
} else if (t == BFloat(16)) {
405+
inputs[i].as<bfloat16_t>().for_each_value([&](bfloat16_t &f) { f = bfloat16_t((rng() & 0xff) / 8.0f - 0xf); });
404406
} else {
405-
// Random bits is fine
407+
assert(t.is_int_or_uint());
408+
// Random bits is fine, but in the 32-bit int case we
409+
// never use the top four bits, to avoid signed integer
410+
// overflow.
411+
const uint32_t mask = (t == Int(32)) ? 0x0fffffffU : 0xffffffffU;
406412
for (uint32_t *ptr = (uint32_t *)inputs[i].data();
407413
ptr != (uint32_t *)inputs[i].data() + inputs[i].size_in_bytes() / 4;
408414
ptr++) {
409-
// Never use the top four bits, to avoid
410-
// signed integer overflow.
411-
*ptr = ((uint32_t)rng()) & 0x0fffffff;
415+
*ptr = ((uint32_t)rng()) & mask;
412416
}
413417
}
414418
}

0 commit comments

Comments
 (0)