Re: Access individual bytes of a 4 byte long (optimization)



In article <1186742138.198936.97210@xxxxxxxxxxxxxxxxxxxxxxxxxxx>
<anon.asdf@xxxxxxxxx> wrote:
On a machine of *given architecture* ...

OK, I give you "MIPS" as the architecture (using the MIPS compilers).

... I want to access the individual bytes of a long (*once-off*)
as fast as possible.

Oops, now you have to decide whether this is a 32-bit MIPS (ILP32
model) or a 64-bit MIPS (I32LP64 model -- i.e., long is eight 8-bit
bytes long).

Is version A, version B, or version C better?

[where A is shift-and-mask, and B and C go through RAM]

On most compilers, version A will be *far* faster than almost
anything else. In fact, since your original code fragment had the
variable set to a constant, if you compile with optimization, the
four or eight extracted sub-parts will also be constants.

Interesting side note: if the architecture is changed to the original
DEC (now Compaq) Alpha, "byte" accesses to RAM are handled in the
compiler by doing full 8-byte machine-word accesses and then using
shift-and-mask instructions, because that is how the machine *has*
to do it. (There are special instructions like "zap" for working
with the eight 8-bit "byte fields" of a register, but loads and
stores are always full 64-bit operations.)

(The MIPS architecture is a lot more common though, as it is found
in various home gaming systems.)
--
In-Real-Life: Chris Torek, Wind River Systems
Salt Lake City, UT, USA (40°39.22'N, 111°50.29'W) +1 801 277 2603
email: forget about it http://web.torek.net/torek/index.html
Reading email is like searching for food in the garbage, thanks to spammers.
.



Relevant Pages

  • Re: non load/store architecture?
    ... working on RISC compilers on clean architectures like the Alpha. ... It's amazing how such an excellent architecture as the Alpha could be virtually destroyed by thoughtless greed. ... Brandon Van Every ...
    (comp.arch.embedded)
  • Re: mips and concurrency/simultaneous running tasks
    ... Scott Keogh wrote: ... > I was wondering if anyone can help me as im new to the mips architecture. ... architecture and minimal instruction set. ...
    (sci.electronics.basics)
  • Re: 12 Misconceptions
    ... This has exposed me to many many flaws in compilers, ... On almost any other architecture I can code C ... xiphoris is back with more nonsense about C. ... to only be considering assembly language programmers who are ...
    (alt.lang.asm)
  • Re: The coming death of all RISC chips.
    ... vastly superior to compilers of a decade ago. ... Have you spent much time trying to get software to work ... and is a basic feature of the architecture. ... In point of fact, Itanium had the ...
    (comp.arch)
  • Re: [Patch 01/12] Prepare the code for Hardware Breakpoint interfaces
    ... * Available values vary according to the architecture. ... I question weather having all these symbols for lengths is the proper approach. ... If we were to use a debug agent hooked into the MIPS EJTAG debugger ... in the arch-specific files and I don't see any part of the generic ...
    (Linux-Kernel)

Loading