From 3ec7c02cc3e922b9364dc8cfd1d4546671b91003 Mon Sep 17 00:00:00 2001 From: Florian Weimer Date: Fri, 23 Jun 2017 17:23:44 +0200 Subject: x86-64: memcmp-avx2-movbe.S needs saturating subtraction [BZ #21662] This code: L(between_2_3): /* Load as big endian with overlapping loads and bswap to avoid branches. */ movzwl -2(%rdi, %rdx), %eax movzwl -2(%rsi, %rdx), %ecx shll $16, %eax shll $16, %ecx movzwl (%rdi), %edi movzwl (%rsi), %esi orl %edi, %eax orl %esi, %ecx bswap %eax bswap %ecx subl %ecx, %eax ret needs a saturating subtract because the full register is used. With this commit, only the lower 24 bits of the register are used, so a regular subtraction suffices. The test case change adds coverage for these kinds of bugs. --- string/test-memcmp.c | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) (limited to 'string') diff --git a/string/test-memcmp.c b/string/test-memcmp.c index a7969ed..1538930 100644 --- a/string/test-memcmp.c +++ b/string/test-memcmp.c @@ -441,11 +441,12 @@ check1 (void) n = 116; for (size_t i = 0; i < n; i++) - { - exp_result = SIMPLE_MEMCMP (s1 + i, s2 + i, n - i); - FOR_EACH_IMPL (impl, 0) - check_result (impl, s1 + i, s2 + i, n - i, exp_result); - } + for (size_t len = 0; len <= n - i; ++len) + { + exp_result = SIMPLE_MEMCMP (s1 + i, s2 + i, len); + FOR_EACH_IMPL (impl, 0) + check_result (impl, s1 + i, s2 + i, len, exp_result); + } } /* This test checks that memcmp doesn't overrun buffers. */ -- cgit v1.1