From: Michael Buesch <mb@bu3sch.de>
To: Larry Finger <Larry.Finger@lwfinger.net>
Cc: bcm43xx-dev@lists.berlios.de, "Rafał Miłecki" <zajec5@gmail.com>,
"linux-wireless@vger.kernel.org" <linux-wireless@vger.kernel.org>,
"John W. Linville" <linville@tuxdriver.com>
Subject: Re: [PATCH 2/6] b43: N-PHY: add RSSI functions: poll and set 2055 vcm
Date: Mon, 11 Jan 2010 11:08:19 +0100 [thread overview]
Message-ID: <201001111108.21701.mb@bu3sch.de> (raw)
In-Reply-To: <4B4A8F3D.6010200@lwfinger.net>
On Monday 11 January 2010 03:38:53 Larry Finger wrote:
> Yes, my fault. The specs are now corrected so that these statements are
>
> ((s8)((s[1] >> 8) & 0x3F) << 2) >> 2
>
> I think that is right.
No it is not.
You need to do this:
(s8)(((s[1] >> 8) & 0x3F) << 2) >> 2
Alternatively add another pair of parenthesis to make it clearer:
((s8)(((s[1] >> 8) & 0x3F) << 2)) >> 2
This basically shifts left unsigned and then shifts right _arithmetically_.
In your example, the compiler will optimize both shifts away (it may actually
also optimize the shifts in my case, but the sign extension will persist.
Just try it and you'll see:
mb@homer:~$ cat t.c
#include <stdio.h>
#include <stdint.h>
int main()
{
int8_t s0;
int8_t s1;
uint8_t u;
u = 0x3D;
s0 = ((int8_t)(u & 0x3F) << 2) >> 2;
s1 = ((int8_t)((u & 0x3F) << 2)) >> 2;
printf("%d %d\n", s0, s1);
}
mb@homer:~$ gcc -o t t.c
mb@homer:~$ ./t
61 -3
--
Greetings, Michael.
prev parent reply other threads:[~2010-01-11 10:09 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2010-01-10 22:13 [PATCH 2/6] b43: N-PHY: add RSSI functions: poll and set 2055 vcm Rafał Miłecki
2010-01-10 22:32 ` Michael Buesch
2010-01-11 0:27 ` Larry Finger
2010-01-11 0:53 ` Michael Buesch
2010-01-11 2:38 ` Larry Finger
2010-01-11 10:08 ` Michael Buesch [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=201001111108.21701.mb@bu3sch.de \
--to=mb@bu3sch.de \
--cc=Larry.Finger@lwfinger.net \
--cc=bcm43xx-dev@lists.berlios.de \
--cc=linux-wireless@vger.kernel.org \
--cc=linville@tuxdriver.com \
--cc=zajec5@gmail.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;
as well as URLs for NNTP newsgroup(s).