migration/xbzrle: use ctz64 to avoid undefined result

__builtin_ctzll() produces undefined results when the argument is 0.
This can be seen through test-xbzrle, which produces the following
warning:

../migration/xbzrle.c:265: runtime error: passing zero to ctz(), which is not a valid argument

Replace __builtin_ctzll() with our ctz64() wrapper which properly
handles 0.

Signed-off-by: Matheus Tavares Bernardino <quic_mathbern@quicinc.com>
Reviewed-by: Dr. David Alan Gilbert <dgilbert@redhat.com>
Reviewed-by: Juan Quintela <quintela@redhat.com>
Signed-off-by: Juan Quintela <quintela@redhat.com>
This commit is contained in:
Matheus Tavares Bernardino 2023-03-13 15:58:19 -03:00 committed by Juan Quintela
parent a5382214d8
commit d84a78d15d

View File

@ -12,6 +12,7 @@
*/ */
#include "qemu/osdep.h" #include "qemu/osdep.h"
#include "qemu/cutils.h" #include "qemu/cutils.h"
#include "qemu/host-utils.h"
#include "xbzrle.h" #include "xbzrle.h"
/* /*
@ -233,7 +234,7 @@ int xbzrle_encode_buffer_avx512(uint8_t *old_buf, uint8_t *new_buf, int slen,
break; break;
} }
never_same = false; never_same = false;
num = __builtin_ctzll(~comp); num = ctz64(~comp);
num = (num < bytes_to_check) ? num : bytes_to_check; num = (num < bytes_to_check) ? num : bytes_to_check;
zrun_len += num; zrun_len += num;
bytes_to_check -= num; bytes_to_check -= num;
@ -262,7 +263,7 @@ int xbzrle_encode_buffer_avx512(uint8_t *old_buf, uint8_t *new_buf, int slen,
nzrun_len += 64; nzrun_len += 64;
break; break;
} }
num = __builtin_ctzll(comp); num = ctz64(comp);
num = (num < bytes_to_check) ? num : bytes_to_check; num = (num < bytes_to_check) ? num : bytes_to_check;
nzrun_len += num; nzrun_len += num;
bytes_to_check -= num; bytes_to_check -= num;