=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
    Date: Tue, 18 Apr 2000  06:28:57
    From: Nikolai Golovchenko <golovchenko-at-mail.ru>
      To: pic microcontroller discussion list <PICLIST-at-mitvma.mit.edu>
 Subject: Re: Favorite C Bugs (was: "Re: Question: C vs Asm") [OT]
--------------------------------------------------------------------------------

Right shift is still faster than divide...
How about fixing it by adding 1 to the dividend before shifts if the
dividend is negative:

-1/2 = 0
(-1+1) >> 1 = 0
-2/2 = -1
(-2+1) >>1 = -1
-3/2 = -1
(-3+1) >> 1 = -1
...

Results are identical.

 Nikolai
 http://techref.massmind.org/member/NG--944

Sunday, April 16, 2000, 8:47:49 AM, you wrote:
> On Fri, Apr 14, 2000 at 10:32:11PM -0700, Andrew Warren wrote:

>>     Not ALWAYS when x is a signed value, no... But doesn't the ANSI

> Not ever when x is a signed value, even for a signed right shift.

> Think about it: if you right shift -1 by 2, what is your result?
> Divide -1 by 4 and what is your result?

> There is one exception where you can use a signed right shift
> in place of a signed divide; if you know that the dividend is
> an exact multiple of the divisor. Otherwise, you can't do it.

> Regards, Clyde

> --
> Clyde Smith-Stubbs               |            HI-TECH Software
> Email: clyde-at-htsoft.com          |          Phone            Fax
> WWW:   http://www.htsoft.com/    | USA: (408) 490 2885  (408) 490 2885
> PGP:   finger clyde-at-htsoft.com   | AUS: +61 7 3355 8333 +61 7 3355 8334
> ---------------------------------------------------------------------------
> HI-TECH C: compiling the real world.


=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
    Date: Sun, 16 Apr 2000  08:47:49
    From: Clyde Smith-Stubbs <clyde-at-HTSOFT.COM>
      To: PICLIST-at-mitvma.mit.edu
 Subject: Re: Favorite C Bugs (was: "Re: Question: C vs Asm") [OT]
--------------------------------------------------------------------------------

On Fri, Apr 14, 2000 at 10:32:11PM -0700, Andrew Warren wrote:

>     Not ALWAYS when x is a signed value, no... But doesn't the ANSI

Not ever when x is a signed value, even for a signed right shift.

Think about it: if you right shift -1 by 2, what is your result?
Divide -1 by 4 and what is your result?

There is one exception where you can use a signed right shift
in place of a signed divide; if you know that the dividend is
an exact multiple of the divisor. Otherwise, you can't do it.

Regards, Clyde

--
Clyde Smith-Stubbs               |            HI-TECH Software
Email: clyde-at-htsoft.com          |          Phone            Fax
WWW:   http://www.htsoft.com/    | USA: (408) 490 2885  (408) 490 2885
PGP:   finger clyde-at-htsoft.com   | AUS: +61 7 3355 8333 +61 7 3355 8334
---------------------------------------------------------------------------
HI-TECH C: compiling the real world.


=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
    Date: Sat, 15 Apr 2000  08:04:14
    From: Clyde Smith-Stubbs <clyde-at-HTSOFT.COM>
      To: PICLIST-at-MITVMA.MIT.EDU
 Subject: Re: Favorite C Bugs (was: "Re: Question: C vs Asm") [OT]
--------------------------------------------------------------------------------

On Fri, Apr 14, 2000 at 08:01:16PM -0700, rleggitt-at-concentric.net wrote:

> Trival example: you know and I know that "x/8" is the same as "x>>3". But

Not when x is a signed value, it ain't.


--
Clyde Smith-Stubbs               |            HI-TECH Software
Email: clyde-at-htsoft.com          |          Phone            Fax
WWW:   http://www.htsoft.com/    | USA: (408) 490 2885  (408) 490 2885
PGP:   finger clyde-at-htsoft.com   | AUS: +61 7 3355 8333 +61 7 3355 8334
---------------------------------------------------------------------------
HI-TECH C: compiling the real world.