public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c/15823] New: optimise >>> style calculation
@ 2004-06-04 16:41 ajrobb at bigfoot dot com
2004-06-04 16:48 ` [Bug c/15823] " pinskia at gcc dot gnu dot org
2004-06-24 8:48 ` ajrobb at bigfoot dot com
0 siblings, 2 replies; 3+ messages in thread
From: ajrobb at bigfoot dot com @ 2004-06-04 16:41 UTC (permalink / raw)
To: gcc-bugs
The C code fragment (i & (~0<<n))/(1<<n) is equivalent to Java's i>>>n
arithmetic shift (at least for n < sizeof(i)*CHAR_BIT).
There are two problems:
1) if n is not a manifest constant, i/(1<<n) uses divide.
2) Even when n is a constant, say 2:
(i & ~3)/4
still does not compile to a single SAR (x86) it still checks the sign and adds
3 if negative.
--
Summary: optimise >>> style calculation
Product: gcc
Version: 3.3.1
Status: UNCONFIRMED
Severity: enhancement
Priority: P2
Component: c
AssignedTo: unassigned at gcc dot gnu dot org
ReportedBy: ajrobb at bigfoot dot com
CC: gcc-bugs at gcc dot gnu dot org
GCC build triplet: i586-suse-linux
GCC host triplet: i586-suse-linux
GCC target triplet: i586-suse-linux
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=15823
^ permalink raw reply [flat|nested] 3+ messages in thread
* [Bug c/15823] optimise >>> style calculation
2004-06-04 16:41 [Bug c/15823] New: optimise >>> style calculation ajrobb at bigfoot dot com
@ 2004-06-04 16:48 ` pinskia at gcc dot gnu dot org
2004-06-24 8:48 ` ajrobb at bigfoot dot com
1 sibling, 0 replies; 3+ messages in thread
From: pinskia at gcc dot gnu dot org @ 2004-06-04 16:48 UTC (permalink / raw)
To: gcc-bugs
------- Additional Comments From pinskia at gcc dot gnu dot org 2004-06-04 16:48 -------
i & ~3 still can be postive. So you still have to do the sign check, if you want te equivalent of Java's i >>
n the do ((unsigned int)i) >> n.
--
What |Removed |Added
----------------------------------------------------------------------------
Status|UNCONFIRMED |RESOLVED
Resolution| |INVALID
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=15823
^ permalink raw reply [flat|nested] 3+ messages in thread
* [Bug c/15823] optimise >>> style calculation
2004-06-04 16:41 [Bug c/15823] New: optimise >>> style calculation ajrobb at bigfoot dot com
2004-06-04 16:48 ` [Bug c/15823] " pinskia at gcc dot gnu dot org
@ 2004-06-24 8:48 ` ajrobb at bigfoot dot com
1 sibling, 0 replies; 3+ messages in thread
From: ajrobb at bigfoot dot com @ 2004-06-24 8:48 UTC (permalink / raw)
To: gcc-bugs
------- Additional Comments From ajrobb at bigfoot dot com 2004-06-24 08:39 -------
Subject: Re: optimise >>> style calculation
Thanks for getting back to me,
I am not looking for Java's i>>n rather i>>>n (e.g. x86 SAR assembler)
I want to duplicate the most significant bit into the next n most significant
bits. However, I want to avoid assembler and use a C code fragment that
compiles to a single SAR instruction on an x86.
Regards,
Andy Robb.
On Friday 04 June 2004 17:48, pinskia at gcc dot gnu dot org wrote:
> ------- Additional Comments From pinskia at gcc dot gnu dot org 2004-06-04
> 16:48 ------- i & ~3 still can be postive. So you still have to do the
> sign check, if you want te equivalent of Java's i >> n the do ((unsigned
> int)i) >> n.
--
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=15823
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2004-06-24 8:39 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2004-06-04 16:41 [Bug c/15823] New: optimise >>> style calculation ajrobb at bigfoot dot com
2004-06-04 16:48 ` [Bug c/15823] " pinskia at gcc dot gnu dot org
2004-06-24 8:48 ` ajrobb at bigfoot dot com
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 read-only IMAP folder(s) and NNTP newsgroup(s).