[comp.arch] Power-of-2

lyang%scherzo@Sun.COM (Larry Yang) (07/22/87)

In article <2807@phri.UUCP> roy@phri.UUCP (Roy Smith) writes:
>
>	Second (sort of the inverse of question #1), why do modern machines
>have such a strong trend towards having power-of-2 word and byte lengths?

One reason I can think for having power-of-2 sizes is in terms of addressing.
If a word = 4 bytes, then I can address a word by masking out the lower
2 bits.  If a word were 5 bytes, this would be more difficult.  I can fill
a 64-byte cache line by masking out the lower 6 bits of the address.  And
so on.  This doesn't explain why a byte size has to be 8 bits, however.

Of course, this touches off the issue of word-aligned and double-word
aligned, which I don't even *want* to think about...

================================================================================


--Larry Yang [lyang@sun.com,{backbone}!sun!lyang]|   A REAL _|> /\ |
  Sun Microsystems, Inc., Mountain View, CA      | signature |   | | /-\ |-\ /-\
    Hobbes: "Why do we play war and not peace?"  |          <|_/ \_| \_/\| |_\_|
    Calvin: "Too few role models."               |                _/          _/

jerry@oliveb.UUCP (Jerry F Aguirre) (07/22/87)

In article <23967@sun.uucp> lyang@sun.UUCP (Larry Yang) writes:
>One reason I can think for having power-of-2 sizes is in terms of addressing.
>If a word = 4 bytes, then I can address a word by masking out the lower
>2 bits.  If a word were 5 bytes, this would be more difficult.  I can fill
>a 64-byte cache line by masking out the lower 6 bits of the address.  And
>so on.  This doesn't explain why a byte size has to be 8 bits, however.

But it does!  If the machine supports bit addressing and you want to
convert from one address to another then being able to just shift or
mask is a desirable feature.  The alternative is to require a multiply
or divide for address casting.

This is not something that the average C programer faces because C
doesn't support bit addressing or arrays of bits.  I consider that a
shortcomming of C.  I have worked on systems that supported bit
addresses and bit test/set/clear instructions.  It is much more natural
to think of an array of N true false variables then to go thru the
complication of trying to pack them into some structure.

Also regarding a previous comment I don't see why multiple shifts are
contrary to "risc" design.  Modern computers use a barrel shifter that
can shift any number of places in one cycle.  The hardware doesn't have
to shift 1, decrement a counter, and repeat.  Shifting is a very common
operation and not one that a compiler had trouble taking advantage of.

					Jerry Aguirre