public inbox for gcc@gcc.gnu.org
 help / color / mirror / Atom feed
* Re: adding fast bitops to egcs?
@ 1999-04-27  7:31 Mike Stump
  1999-04-30 20:46 ` rich-paul
  1999-04-30 23:15 ` Mike Stump
  0 siblings, 2 replies; 12+ messages in thread
From: Mike Stump @ 1999-04-27  7:31 UTC (permalink / raw)
  To: bright, law; +Cc: egcs

> To: Alfred Perlstein <bright@rush.net>
> cc: egcs@egcs.cygnus.com
> Date: Mon, 26 Apr 1999 21:34:43 -0600
> From: Jeffrey A Law <law@upchuck.cygnus.com>

>   > 2) number of bits set
> True.  No good pop count.

Yes, but one can do it in plain C rather easily and quickly, if one
knows the right algorithm.

^ permalink raw reply	[flat|nested] 12+ messages in thread

* Re: adding fast bitops to egcs?
  1999-04-27  7:31 adding fast bitops to egcs? Mike Stump
@ 1999-04-30 20:46 ` rich-paul
  1999-04-30 23:15   ` rich-paul
  1999-05-03  1:41   ` Andreas Schwab
  1999-04-30 23:15 ` Mike Stump
  1 sibling, 2 replies; 12+ messages in thread
From: rich-paul @ 1999-04-30 20:46 UTC (permalink / raw)
  To: Mike Stump; +Cc: egcs

On Tue, 27 Apr 1999, Mike Stump wrote:

> >   > 2) number of bits set
> > True.  No good pop count.
> 
> Yes, but one can do it in plain C rather easily and quickly, if one
> knows the right algorithm.
> 

OK, I'll bite ... what's your code?
---
There is a party that  |  Libertarian Party  |  A victimless crime is
supports the right to  |  http://www.lp.org  |     a contradiction in 
free speech and        |    The Party of     |                 terms.
encryption!!           |      Principle      |  

^ permalink raw reply	[flat|nested] 12+ messages in thread

* Re: adding fast bitops to egcs?
  1999-04-27  7:31 adding fast bitops to egcs? Mike Stump
  1999-04-30 20:46 ` rich-paul
@ 1999-04-30 23:15 ` Mike Stump
  1 sibling, 0 replies; 12+ messages in thread
From: Mike Stump @ 1999-04-30 23:15 UTC (permalink / raw)
  To: bright, law; +Cc: egcs

> To: Alfred Perlstein <bright@rush.net>
> cc: egcs@egcs.cygnus.com
> Date: Mon, 26 Apr 1999 21:34:43 -0600
> From: Jeffrey A Law <law@upchuck.cygnus.com>

>   > 2) number of bits set
> True.  No good pop count.

Yes, but one can do it in plain C rather easily and quickly, if one
knows the right algorithm.

^ permalink raw reply	[flat|nested] 12+ messages in thread

* Re: adding fast bitops to egcs?
  1999-04-30 20:46 ` rich-paul
@ 1999-04-30 23:15   ` rich-paul
  1999-05-03  1:41   ` Andreas Schwab
  1 sibling, 0 replies; 12+ messages in thread
From: rich-paul @ 1999-04-30 23:15 UTC (permalink / raw)
  To: Mike Stump; +Cc: egcs

On Tue, 27 Apr 1999, Mike Stump wrote:

> >   > 2) number of bits set
> > True.  No good pop count.
> 
> Yes, but one can do it in plain C rather easily and quickly, if one
> knows the right algorithm.
> 

OK, I'll bite ... what's your code?
---
There is a party that  |  Libertarian Party  |  A victimless crime is
supports the right to  |  http://www.lp.org  |     a contradiction in 
free speech and        |    The Party of     |                 terms.
encryption!!           |      Principle      |  


^ permalink raw reply	[flat|nested] 12+ messages in thread

* Re: adding fast bitops to egcs?
  1999-04-30 20:46 ` rich-paul
  1999-04-30 23:15   ` rich-paul
@ 1999-05-03  1:41   ` Andreas Schwab
  1999-05-31 21:36     ` Andreas Schwab
  1 sibling, 1 reply; 12+ messages in thread
From: Andreas Schwab @ 1999-05-03  1:41 UTC (permalink / raw)
  To: rich-paul; +Cc: Mike Stump, egcs

rich-paul@rich-paul.net writes:

|> On Tue, 27 Apr 1999, Mike Stump wrote:
|> 
|> > >   > 2) number of bits set
|> > > True.  No good pop count.
|> > 
|> > Yes, but one can do it in plain C rather easily and quickly, if one
|> > knows the right algorithm.
|> > 
|> 
|> OK, I'll bite ... what's your code?

Use a 256-byte lookup table.

-- 
Andreas Schwab                                      "And now for something
schwab@issan.cs.uni-dortmund.de                      completely different"
schwab@gnu.org

^ permalink raw reply	[flat|nested] 12+ messages in thread

* Re: adding fast bitops to egcs?
  1999-05-03  1:41   ` Andreas Schwab
@ 1999-05-31 21:36     ` Andreas Schwab
  0 siblings, 0 replies; 12+ messages in thread
From: Andreas Schwab @ 1999-05-31 21:36 UTC (permalink / raw)
  To: rich-paul; +Cc: Mike Stump, egcs

rich-paul@rich-paul.net writes:

|> On Tue, 27 Apr 1999, Mike Stump wrote:
|> 
|> > >   > 2) number of bits set
|> > > True.  No good pop count.
|> > 
|> > Yes, but one can do it in plain C rather easily and quickly, if one
|> > knows the right algorithm.
|> > 
|> 
|> OK, I'll bite ... what's your code?

Use a 256-byte lookup table.

-- 
Andreas Schwab                                      "And now for something
schwab@issan.cs.uni-dortmund.de                      completely different"
schwab@gnu.org

^ permalink raw reply	[flat|nested] 12+ messages in thread

* Re: adding fast bitops to egcs?
  1999-04-26 20:51 ` Andi Kleen
@ 1999-04-30 23:15   ` Andi Kleen
  0 siblings, 0 replies; 12+ messages in thread
From: Andi Kleen @ 1999-04-30 23:15 UTC (permalink / raw)
  To: Alfred Perlstein; +Cc: egcs

bright@rush.net (Alfred Perlstein) writes:

> Maybe it's too much coffee today, but i've always wondered why C
> doesn't support stronger bit manipulation routines.
> 
> Such as:
> 1) return position of first set/unset bit from MSB to LSB or LSB to MSB

^ permalink raw reply	[flat|nested] 12+ messages in thread

* adding fast bitops to egcs?
  1999-04-26 16:15 Alfred Perlstein
  1999-04-26 20:37 ` Jeffrey A Law
  1999-04-26 20:51 ` Andi Kleen
@ 1999-04-30 23:15 ` Alfred Perlstein
  2 siblings, 0 replies; 12+ messages in thread
From: Alfred Perlstein @ 1999-04-30 23:15 UTC (permalink / raw)
  To: egcs

Maybe it's too much coffee today, but i've always wondered why C
doesn't support stronger bit manipulation routines.

Such as:
1) return position of first set/unset bit from MSB to LSB or LSB to MSB
2) number of bits set
3) bit rotation

this could be done in the optimizer but would be hard to identify afaik...

would it make any sense to add such functionality as an egcs C extention?

as in:

/* assign x the position of the most signifigant bit set in y */
x = msbs(y); 
/* assign x the position of the least signifigant unbit set in y */
x = lsbus(y); 

The reason is that the C primatives for bit ops are quite poor for scanning
bit strings and most modern hardware supports some of these ops with a 
single fast instruction (instead of forcing the coder to use a clumsy
for loop).

This can really help people doing low end harware work that have to decode
bit encoded registers...

thanks,
-Alfred 


^ permalink raw reply	[flat|nested] 12+ messages in thread

* Re: adding fast bitops to egcs?
  1999-04-26 20:37 ` Jeffrey A Law
@ 1999-04-30 23:15   ` Jeffrey A Law
  0 siblings, 0 replies; 12+ messages in thread
From: Jeffrey A Law @ 1999-04-30 23:15 UTC (permalink / raw)
  To: Alfred Perlstein; +Cc: egcs

  In message < Pine.BSF.3.96.990426182434.2095D-100000@cygnus.rush.net >you write:
  > Such as:
  > 1) return position of first set/unset bit from MSB to LSB or LSB to MSB
ffs, which gcc will recognize and attempt to use a hardware intrinsic to
implement.

  > 2) number of bits set
True.  No good pop count.


  > 3) bit rotation
Easily synthesized.  GCC recognizes rotate synthesis and will attempt to use
a rotate instruction if the hardware supports it.

  > The reason is that the C primatives for bit ops are quite poor for scanning
  > bit strings and most modern hardware supports some of these ops with a 
  > single fast instruction (instead of forcing the coder to use a clumsy
  > for loop).
Actually, few targets have this stuff these days.  I have the, err, pleasure
of looking at 2-5 new ISAs every year.  ffs, pop count are rarer and rarer. 
rotates are still fairly common though.

jeff

^ permalink raw reply	[flat|nested] 12+ messages in thread

* Re: adding fast bitops to egcs?
  1999-04-26 16:15 Alfred Perlstein
  1999-04-26 20:37 ` Jeffrey A Law
@ 1999-04-26 20:51 ` Andi Kleen
  1999-04-30 23:15   ` Andi Kleen
  1999-04-30 23:15 ` Alfred Perlstein
  2 siblings, 1 reply; 12+ messages in thread
From: Andi Kleen @ 1999-04-26 20:51 UTC (permalink / raw)
  To: Alfred Perlstein; +Cc: egcs

bright@rush.net (Alfred Perlstein) writes:

> Maybe it's too much coffee today, but i've always wondered why C
> doesn't support stronger bit manipulation routines.
> 
> Such as:
> 1) return position of first set/unset bit from MSB to LSB or LSB to MSB

From LSB is __builtin_ffs().

> 2) number of bits set

Can be done using gcc inline assembly (on most CPUs that implement
the "NSA instruction" with a single opcode) 

> 3) bit rotation

Dito. 

e.g. on the x86:

extern inline unsigned int rotate_left(int i, unsigned int word)
{
	asm("roll %%cl,%0"
		:"=r" (word)
		:"0" (word),"c" (i));
	return word;
}

> this could be done in the optimizer but would be hard to identify afaik...

gcc tries to spot some of the constructs used to simulate rotation
in C ((x<<i) | (x>>(wordsize-i))) and output it as a single rotate
instruction, but this seems to only work for constant rotate counts.


-Andi

-- 
This is like TV. I don't like TV.

^ permalink raw reply	[flat|nested] 12+ messages in thread

* Re: adding fast bitops to egcs?
  1999-04-26 16:15 Alfred Perlstein
@ 1999-04-26 20:37 ` Jeffrey A Law
  1999-04-30 23:15   ` Jeffrey A Law
  1999-04-26 20:51 ` Andi Kleen
  1999-04-30 23:15 ` Alfred Perlstein
  2 siblings, 1 reply; 12+ messages in thread
From: Jeffrey A Law @ 1999-04-26 20:37 UTC (permalink / raw)
  To: Alfred Perlstein; +Cc: egcs

  In message < Pine.BSF.3.96.990426182434.2095D-100000@cygnus.rush.net >you write:
  > Such as:
  > 1) return position of first set/unset bit from MSB to LSB or LSB to MSB
ffs, which gcc will recognize and attempt to use a hardware intrinsic to
implement.

  > 2) number of bits set
True.  No good pop count.


  > 3) bit rotation
Easily synthesized.  GCC recognizes rotate synthesis and will attempt to use
a rotate instruction if the hardware supports it.

  > The reason is that the C primatives for bit ops are quite poor for scanning
  > bit strings and most modern hardware supports some of these ops with a 
  > single fast instruction (instead of forcing the coder to use a clumsy
  > for loop).
Actually, few targets have this stuff these days.  I have the, err, pleasure
of looking at 2-5 new ISAs every year.  ffs, pop count are rarer and rarer. 
rotates are still fairly common though.

jeff

^ permalink raw reply	[flat|nested] 12+ messages in thread

* adding fast bitops to egcs?
@ 1999-04-26 16:15 Alfred Perlstein
  1999-04-26 20:37 ` Jeffrey A Law
                   ` (2 more replies)
  0 siblings, 3 replies; 12+ messages in thread
From: Alfred Perlstein @ 1999-04-26 16:15 UTC (permalink / raw)
  To: egcs

Maybe it's too much coffee today, but i've always wondered why C
doesn't support stronger bit manipulation routines.

Such as:
1) return position of first set/unset bit from MSB to LSB or LSB to MSB
2) number of bits set
3) bit rotation

this could be done in the optimizer but would be hard to identify afaik...

would it make any sense to add such functionality as an egcs C extention?

as in:

/* assign x the position of the most signifigant bit set in y */
x = msbs(y); 
/* assign x the position of the least signifigant unbit set in y */
x = lsbus(y); 

The reason is that the C primatives for bit ops are quite poor for scanning
bit strings and most modern hardware supports some of these ops with a 
single fast instruction (instead of forcing the coder to use a clumsy
for loop).

This can really help people doing low end harware work that have to decode
bit encoded registers...

thanks,
-Alfred 

^ permalink raw reply	[flat|nested] 12+ messages in thread

end of thread, other threads:[~1999-05-31 21:36 UTC | newest]

Thread overview: 12+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
1999-04-27  7:31 adding fast bitops to egcs? Mike Stump
1999-04-30 20:46 ` rich-paul
1999-04-30 23:15   ` rich-paul
1999-05-03  1:41   ` Andreas Schwab
1999-05-31 21:36     ` Andreas Schwab
1999-04-30 23:15 ` Mike Stump
  -- strict thread matches above, loose matches on Subject: below --
1999-04-26 16:15 Alfred Perlstein
1999-04-26 20:37 ` Jeffrey A Law
1999-04-30 23:15   ` Jeffrey A Law
1999-04-26 20:51 ` Andi Kleen
1999-04-30 23:15   ` Andi Kleen
1999-04-30 23:15 ` Alfred Perlstein

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).