RFC: Optimization to write_register_bytes()
Fri Jun 9 04:50:00 GMT 2000
Fernando Nasser wrote:
> We had a long thread on this that end up turning in what we are doing in
> the future to improve the API etc.
> Somehow the down to Earth patch below was forgotten, and without this the
> code to show MMX registers does not work.
What happens if the code:
/* The register partially overlaps the range being written. */
/* What's the overlap between this register's bytes and
those the caller wants to write? */
int overlapstart = max (regstart, myregstart);
int overlapend = min (regend, myregend);
/* We may be doing a partial update of an invalid register.
Update it from the target before scribbling on it. */
read_register_gen (regno, regbuf);
memcpy (registers + overlapstart,
myaddr + (overlapstart - myregstart),
overlapend - overlapstart);
is rewritten to use write_register_gen () instead of memcpy() to store
The function write_register_gen() only pushes through a register write
if the register contents actually change. The above code forces the
register write regardless.
While it isn't as optimal as bailing out of the loop early it definitly
improves things and probably stops redundant writes and (besides, it
makes the code far more readable :-).
The second tweek I think may be safe is to keep track of how many bytes
are still to be written. If we just worry about the case where
registers are contigious and assending then the required change should
if (we've just written out all the low bytes)
bump our lower bound and number of bytes to write;
if there are no more bytes to write
it does assume that the actual target doesn't need separate writes when
two registers overlap. I think that is safe as the original purpose of
the function was to spray values such as structures across several
As for the answer to your original question:
> We can save some time (and fix a problem I have) if we make a simple assumption in
> If we assume that the range of registers affected by a write operation
> is contiguous, we can break out of the loop as soon as we wrote the
> last byte.
> Besides optimization, this also solves the problem of it trying to write registers that are actually
> aliases, like the Pentium MMX registers (which are just aliases to floating point registers). The
> other solution for this is to mark the alias registers as CANNOT_STORE_REGISTER (it works just
> fine). But some optimization to write_register_bytes() would be a nice thing (if it is possible).
> Is the above assumption (contiguousness) acceptable? Does anyone know of a crazy target where the
> register numbers of registers that can be affected by a overlapped write are out of order with
> regards to their position in the register file?
Unless someone does some serious research, no one knows.
More information about the Gdb-patches