🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: comp.lang.c.moderated
Article #2332

Re: Pointer Arithmetic

#2332
From: Stan Ryckman
Date: Tue, 19 Mar 1996 12:46
37 lines
1937 bytes
In article <4ijp8i$1cf@solutions.solon.com>,
Ari Lukumies  <aril@cmt.lpr.mail.carel.fi> wrote:

[snip]

[edited to get lines under 72 chars]
>It is implementation dependant, but I'd guess that most compilers
> use multiplication since 
>it's easier to implement. Shifts would be faster, but in many cases
> you would have to use 
>a few shifts and additions to accomplish the same task. For
> instance, if the size of the 
>element is 80 bytes, you would have to do shifts by 10 and 8 and
> add the results together, 
>which is harder to implement in a compiler.

Well, that wouldn't work  :-)  For 80, you'd shift by 6 and 4 and
add the results.  (80 == 64 + 16).

It's not that much harder to implement this in a compiler.  I used
one on a 68000-based system that did all multiplies by constants
in this manner, both for indexing and for expressions, and used
the MUL instruction if it would be faster.  So, i*0x555 would use
the MUL instruction, but i*0x7ff would use shifts (multiply by 0x800
with a shift, then subtract the original).  It "knew" how expensive
the instructions were, and used whatever it thought best.

(That compiler was dumb in other things though; it insisted on
generating code to multiply by 1, for example, though not for
indexing char arrays.)

Cheers,
Stan.
--
Stan Ryckman  (stanr@tiac.net)
  (Apologies for non-responses or late responses to some posts;
  .newsrc was trashed and I'm trying to get it back to where it was.)
Technical Details
Message-ID: <4imabr$duc@solutions.solon.com>
Path: arc1-ca.pugleaf.net!solon.com!not-for-mail
References: <4i805f$47d@solutions.solon.com> <4ijp8i$1cf@solutions.solon.com>

Show Full Headers
Complete Article Headers
Path: arc1-ca.pugleaf.net!solon.com!not-for-mail
From: stanr@tiac.net (Stan Ryckman)
Newsgroups: comp.lang.c.moderated
Subject: Re: Pointer Arithmetic
Date: 19 Mar 1996 06:46:51 -0600
Organization: Amber & Sneakers Fan Club
Sender: clc@solutions.solon.com
Approved: clc@solutions.solon.com
Message-ID: <4imabr$duc@solutions.solon.com>
References: <4i805f$47d@solutions.solon.com> <4ijp8i$1cf@solutions.solon.com>
NNTP-Posting-Host: solutions.solon.com