Re: Access individual bytes of a 4 byte long (optimization)
- From: Chris Torek <nospam@xxxxxxxxx>
- Date: 10 Aug 2007 20:11:14 GMT
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.
.
- References:
- Access individual bytes of a 4 byte long (optimization)
- From: anon . asdf
- Access individual bytes of a 4 byte long (optimization)
- Prev by Date: Re: How to talk to hardware devices in C
- Next by Date: Re: [xpost] a new C/C++ type that when overflow i see it
- Previous by thread: Re: Access individual bytes of a 4 byte long (optimization)
- Next by thread: Re: Access individual bytes of a 4 byte long (optimization)
- Index(es):
Relevant Pages
|
Loading