git/list[1] front-page[2] threads[3] people[4] search[5] about
 

Re: [PATCH 2/3] xdiff: avoid more compiler warnings with XDL_FAST_HASH on 32-bit machines

From
Thomas Rast <trast@inf.ethz.ch>
Date
May 23, 2012, 08:30 UTC
Message-ID
<8762bn7101.fsf@thomas.inf.ethz.ch>
In-Reply-To
<4FBBF8D7.7050701@lsrfire.ath.cx>
René Scharfe <rene.scharfe@lsrfire.ath.cx> writes:
Show 10 quoted lines
> Hide literals that can cause compiler warnings for 32-bit architectures in
> expressions that evaluate to small numbers there.  Some compilers warn that
> 0x0001020304050608 won't fit into a 32-bit long, others that shifting right
> by 56 bits clears a 32-bit value completely.
>
> The correct values are calculated in the 64-bit case, which is all that matters
> in this if-branch.
>
> Reported-by: Øyvind A. Holm <sunny@sunbase.org>
> Signed-off-by: Rene Scharfe <rene.scharfe@lsrfire.ath.cx>
Thanks for fixing this.  As far as logic and review goes, both patches
Acked-by: Thomas Rast <trast@student.ethz.ch>
I haven't checked whether it actually fixes the warnings, however.
Show 23 quoted lines
> ---
>  xdiff/xutils.c |    8 +++++++-
>  1 file changed, 7 insertions(+), 1 deletion(-)
>
> diff --git a/xdiff/xutils.c b/xdiff/xutils.c
> index 8580da7..78549e3 100644
> --- a/xdiff/xutils.c
> +++ b/xdiff/xutils.c
> @@ -272,7 +272,13 @@ static inline long count_masked_bytes(unsigned long mask)
>  		 * that works for the bytemasks without having to
>  		 * mask them first.
>  		 */
> -		return mask * 0x0001020304050608 >> 56;
> +		/*
> +		 * return mask * 0x0001020304050608 >> 56;
> +		 *
> +		 * Doing it like this avoids warnings on 32-bit machines.
> +		 */
> +		long a = (REPEAT_BYTE(0x01) / 0xff + 1);
> +		return mask * a >> (sizeof(long) * 7);
>  	} else {
>  		/*
>  		 * Modified Carl Chatfield G+ version for 32-bit *
-- 
Thomas Rast
trast@{inf,student}.ethz.ch
Previous: René ScharfeNext: René Scharfe
Message 9 of 11 in “tr/xdiff-fast-hash generates warnings and breaks tests”
  1. Øyvind A. HolmMay 16, 2012
  2. René ScharfeMay 17, 2012
  3. Øyvind A. HolmMay 17, 2012
  4. Junio C HamanoMay 17, 2012
  5. René ScharfeMay 17, 2012
  6. Øyvind A. HolmMay 19, 2012
  7. 1/3 xdiff: avoid compiler warnings with XDL_FAST_HASH on 32-bit machinesRené Scharfe, May 22, 2012
  8. 2/3 xdiff: avoid more compiler warnings with XDL_FAST_HASH on 32-bit machinesRené Scharfe, May 22, 2012
  9. Thomas RastMay 23, 2012
  10. 3/3 xdiff: import new 32-bit version of count_masked_bytes()René Scharfe, May 22, 2012
  11. Øyvind A. HolmMay 25, 2012

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.