kfdtest: RoundToPowerOf2 function modified for compiler compliant bit shift values

Compiler behavior is undefined if the right operand is negative,
or greater than or equal to the width of the promoted left operand.
For release builds with address sanitizer enabled, this compiler
optimization behavior leads to unsupported queue size value since
current method shifts till 128 bits on a 64 bit value.

Signed-off-by: Sreekant Somasekharan <sreekant.somasekharan@amd.com>
Change-Id: Iafdc82d0dfb7f79e3012fb7bb70eda80e4b7a7a6


[ROCm/ROCR-Runtime commit: 1428a7538e]
Este commit está contenido en:
Sreekant Somasekharan
2023-06-05 11:29:30 -04:00
padre 6998fcee45
commit c84cdca17e
@@ -65,17 +65,18 @@ HSAKMT_STATUS fscanf_dec(const char *file, uint32_t *num)
}
uint64_t RoundToPowerOf2(uint64_t val) {
int bytes = sizeof(uint64_t);
val--;
val--;
/* Shift with amount larger than the bit width can result in
* undefined behavior by compiler for release builds.
* Shift till 32 bit only which is less than bit width of val.
*/
for (int i = 1; i <= 32; i *= 2)
val |= val >> i;
for (int i = 0; i < bytes; i++) {
val |= val >> (1 << i);
}
val++;
val++;
return val;
return val;
}
bool WaitOnValue(const volatile unsigned int *buf, unsigned int value, unsigned int timeOut) {