a write to a byte is quicker than a bit change ?

B

Ben_

Hello,

The following assertion hits my mind: "a byte is used instead of a bit for
two reasons: a write to a byte is quicker than a bit change a write to a
byte is quicker than a bit change, and the other bits are reserved for
future use." (IBM JVM Diagnostics Guide 1.3.1, Chapter 2. Understanding the
Garbage Collector, p.13,
http://www-106.ibm.com/developerworks/java/jdk/diagnosis/diag131rev1.pdf).

What strickes me is not that they reserve bits for future use :), but
rather that a write to a byte is said to be quicker than to a bit.

Can someone tell me why it is so ?

Thanks.
 
M

Michael Borgwardt

Ben_ said:
What strickes me is not that they reserve bits for future use :), but
rather that a write to a byte is said to be quicker than to a bit.

Can someone tell me why it is so ?

Both memory access and CPU instructions work in termy of bytes, not bits.
Thus, to write a byte, you simply tell the CPU "write this byte to
memory location X", whereas in order to write one bit and leave the other
bits in the byte as they are, you have to say "get byte at memory location
X", "set/unset bit Y in the byte" and the "write byte to memory location X".
In fact, some modern CPUs work in terms of 32 or 64 bit words, and changing
a single byte rather than the hole word is inefficient as well.
 
X

xarax

Ben_ said:
Hello,

The following assertion hits my mind: "a byte is used instead of a bit for
two reasons: a write to a byte is quicker than a bit change a write to a
byte is quicker than a bit change, and the other bits are reserved for
future use." (IBM JVM Diagnostics Guide 1.3.1, Chapter 2. Understanding the
Garbage Collector, p.13,
http://www-106.ibm.com/developerworks/java/jdk/diagnosis/diag131rev1.pdf).

What strickes me is not that they reserve bits for future use :), but
rather that a write to a byte is said to be quicker than to a bit.

Can someone tell me why it is so ?

Ok, I've read the passage. To put it in context, the passage
is describing an implementation detail of the garbage collector
mark-sweep algorithm. The "write to a byte is quicker than to a bit"
is saying that stuffing a 0x01 into a byte is more efficient (faster)
than first fetching the byte, OR-ing a bit ON, then storing the
modified byte value back to memory. This is in the context of
garbage collection, which is a low-level program (likely C or
assembler language), that must look at hundreds of thousands (or
millions) of objects to determine their reachability. Saving a
couple of machine instructions per object can add up to huge
time savings.
 
N

nos

you refer to "read modify write" operation in software
but in real life when you do a write operation in software
it almost always ends up in "read modify write" in the
microcode of the cpu
my guess is that if you are looking at this level it might
be misleading and you would be better advised to do a
higher level timing study
if you still want to nit pick you need to also look at l2 and l3 cache
and pipeline factors
 
B

Ben_

I wasn't thinking at that level of detail (L2/L3 cache, etc), but came to
think that the original assertion was really CPU (and maybe OS) dependant
and that, at the end of the day, it could be merely the generalization of an
optimization valid in certain circumstances only.
 
S

Stewart-Wall Family

Writing to a byte means that the system has to only make the write.
Since a bit is 8 bytes, and the smallest the system can write is a byte,
writing a bit really means: read the byte, do the bit math on it to change
the one bit, then write back the result. That's an extra two steps for each
bit... hence, takes longer.
 
T

Tim Ward

Stewart-Wall Family said:
Writing to a byte means that the system has to only make the write.
Since a bit is 8 bytes, and the smallest the system can write is a byte,
writing a bit really means: read the byte, do the bit math on it to change
the one bit, then write back the result. That's an extra two steps for each
bit... hence, takes longer.

Depends on the hardware. On some processors writing a 32-bit word is faster
than writing a byte.
 
E

Eric Sosman

Roedy said:
oops.
Since a byte is 8 bits.

No; SWF (or should that be "S-WF?" Don't want to give
anyone the wrong idea ...) was merely making an observation
about bloatware.
 
B

Bruce Krawetz

Stewart-Wall Family said:
Writing to a byte means that the system has to only make the write.
Since a bit is 8 bytes, and the smallest the system can write is a byte,
writing a bit really means: read the byte, do the bit math on it to change
the one bit, then write back the result. That's an extra two steps for each
bit... hence, takes longer.
[CHOMP]

Some systems can actually read/write a bit as a bit.
 
N

nos

you mean like the RCA 1802 ?


Bruce Krawetz said:
Stewart-Wall Family said:
Writing to a byte means that the system has to only make the write.
Since a bit is 8 bytes, and the smallest the system can write is a byte,
writing a bit really means: read the byte, do the bit math on it to change
the one bit, then write back the result. That's an extra two steps for each
bit... hence, takes longer.
[CHOMP]

Some systems can actually read/write a bit as a bit.
 
X

xarax

Bruce Krawetz said:
Stewart-Wall Family said:
Writing to a byte means that the system has to only make the write.
Since a bit is 8 bytes, and the smallest the system can write is a byte,
writing a bit really means: read the byte, do the bit math on it to change
the one bit, then write back the result. That's an extra two steps for each
bit... hence, takes longer.
[CHOMP]

Some systems can actually read/write a bit as a bit.

The OP was referring specifically to the IBM JVM implementation
that runs on platforms that perform multi-access bit updates within
a byte.

A single instruction (OI -- OR immediate) can turn on a bit
within a byte, and that is implemented by the hardware as a
fetch,update,store (3 operations).

There is another instruction (MVI -- Move immediate) that can
store a hard-coded byte value at a location with a single
memory access.

The IBM JVM implementation uses MVI, instead of OI, because
it is faster by reason that it is a single access memory
reference as opposed to a multiple-access reference.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
474,434
Messages
2,571,689
Members
48,796
Latest member
Greg L.

Latest Threads

Top