mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Steven Rostedt <rostedt@goodmis.org>
To: Michael Sartain <mikesart@fastmail.com>
Cc: linux-kernel@vger.kernel.org
Subject: Re: [PATCH 4/5] trace-cmd: Use unsigned values in Hsieh's trace_hash fast hash function
Date: Mon, 9 Oct 2017 18:30:55 -0400	[thread overview]
Message-ID: <20171009183055.567190e7@gandalf.local.home> (raw)
In-Reply-To: <20170812173047.840-5-mikesart@fastmail.com>

On Sat, 12 Aug 2017 11:30:46 -0600
Michael Sartain <mikesart@fastmail.com> wrote:

> Signed int values were being used where the original code used uint32_t types:
> 
>   http://www.azillionmonkeys.com/qed/hash.html
> 
> Right shifting negative int values has implementation-defined and left shifting
> has undefined behavior.
> 
> On my platform (x86_64) right shifting was doing sign extension and filling
> high bits with 1s, which is different than the original algorithm.
> 

Heh, nice catch. Although the hash was never used for anything too
important. Mostly just colors of the graph.

> Signed-off-by: Michael Sartain <mikesart@fastmail.com>
> ---
>  trace-hash-local.h | 4 ++--
>  1 file changed, 2 insertions(+), 2 deletions(-)
> 
> diff --git a/trace-hash-local.h b/trace-hash-local.h
> index b2a1002..b3f9b06 100644
> --- a/trace-hash-local.h
> +++ b/trace-hash-local.h
> @@ -22,7 +22,7 @@
>  
>  static inline unsigned int trace_hash(int val)
>  {
> -	int hash, tmp;
> +	unsigned int hash, tmp;
>  
>  	hash = 12546869;	/* random prime */
>  
> @@ -34,7 +34,7 @@ static inline unsigned int trace_hash(int val)
>  	 */
>  
>  	hash +=	(val & 0xffff);
> -	tmp = (val >> 16) ^ hash;
> +	tmp = ((unsigned int)val >> 16) ^ hash;

Why not just have val be unsigned int, and not do the typecast?

-- Steve

>  	hash = (hash << 16) ^ tmp;
>  	hash += hash >> 11;
>  

  reply	other threads:[~2017-10-09 22:30 UTC|newest]

Thread overview: 14+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-08-12 17:30 [PATCH 0/5] trace-cmd: Fixes for four small bugs plus minor cleanup Michael Sartain
2017-08-12 17:30 ` [PATCH 1/5] trace-cmd: Fix incorrect malloc size arg: *item instead of item Michael Sartain
2017-08-12 17:30 ` [PATCH 2/5] trace-cmd: Fix NULL pointer being passed to memcpy Michael Sartain
2017-10-09 22:24   ` Steven Rostedt
2017-10-09 22:27     ` Michael Sartain
2017-10-09 22:33       ` Steven Rostedt
2017-08-12 17:30 ` [PATCH 3/5] trace-cmd: Add ULL suffix to MISSING_EVENTS since ints shouldn't be left shifted by 31 Michael Sartain
2017-10-09 22:27   ` Steven Rostedt
2017-08-12 17:30 ` [PATCH 4/5] trace-cmd: Use unsigned values in Hsieh's trace_hash fast hash function Michael Sartain
2017-10-09 22:30   ` Steven Rostedt [this message]
2017-08-12 17:30 ` [PATCH 5/5] trace-cmd: Remove unused view_width variable Michael Sartain
2017-10-09 22:32   ` Steven Rostedt
2017-10-09 22:13 ` [PATCH 0/5] trace-cmd: Fixes for four small bugs plus minor cleanup Michael Sartain
2017-10-09 22:21   ` Steven Rostedt

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20171009183055.567190e7@gandalf.local.home \
    --to=rostedt@goodmis.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=mikesart@fastmail.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®