The Linux Kernel Mailing List
 help / color / mirror / Atom feed
From: Segher Boessenkool <segher@kernel.crashing.org>
To: Andreas Schwab <schwab@suse.de>
Cc: Harvey Harrison <harvey.harrison@gmail.com>,
	LKML <linux-kernel@vger.kernel.org>,
	Andrew Morton <akpm@linux-foundation.org>
Subject: Re: [PATCH] bitops: add 8-bit and 16-bit rotation functions
Date: Tue, 11 Mar 2008 22:18:27 +0100	[thread overview]
Message-ID: <5116e96e09f6fc82587283a2a0cdd8ff@kernel.crashing.org> (raw)
In-Reply-To: <je1w6hc6yw.fsf@sykes.suse.de>

>>> +/**
>>> + * rol16 - rotate a 16-bit value left
>>> + * @word: value to rotate
>>> + * @shift: bits to roll
>>> + */
>>> +static inline __u16 rol16(__u16 word, unsigned int shift)
>>> +{
>>> +	return (word << shift) | (word >> (16 - shift));
>>> +}
>>
>> This doesn't work for shift values of 0: you get word >> 16, and
>> shifts greater than or equal to the word size aren't valid C.  GCC
>> will warn about this, too.
>
> On the other hand, a value narrower than int will always be promoted
> first,

Erm, yes of course.  It is promoted to _signed_ int though, but
that works okay here.

> so this is not a problem in this case.

It still needs documentation for the valid values of "shift".


Segher


      parent reply	other threads:[~2008-03-11 21:19 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2008-03-11 16:56 [PATCH] bitops: add 8-bit and 16-bit rotation functions Harvey Harrison
2008-03-11 20:45 ` Segher Boessenkool
2008-03-11 20:59   ` Andreas Schwab
2008-03-11 21:15     ` Harvey Harrison
2008-03-11 21:18     ` Segher Boessenkool [this message]

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=5116e96e09f6fc82587283a2a0cdd8ff@kernel.crashing.org \
    --to=segher@kernel.crashing.org \
    --cc=akpm@linux-foundation.org \
    --cc=harvey.harrison@gmail.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=schwab@suse.de \
    /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