> My recommendation is that we split these into two ops: Bgotoifnil and
> Bgotoifnonnil, which use only FETCH and a positive/negative offset from the
> current pc, and Bgotoifnil2 and Bgotoifnonnil2 which use the old logic
> (FETCH2, and an absolute offset from the start of the bytecode stream).
You mean, provide "short" forms of Bgotoifnil and Bgotoifnonnil?
I'm not sure it's worth the trouble: the only benefit is to replace
a FETCH2 by a FETCH, which doesn't seem like it would save a large
fraction of the time to execute those operations.
Of course, when it comes to performance, intuition is often wrong, so
feel free to try it out.
> Making this change in the C code is easy, but changing bytecomp.el wasn't
> obvious to me. Can anyone help me with that?
is the code that outputs the 3 bytes (opcode, nil, and (cdr off)), where
the last 2 are not real bytes yet (they'll be filled later via
So you can probably get what you want by only changing:
(dolist (bytes-tail patchlist)
(setq pc (caar bytes-tail)) ; Pick PC from goto's tag.
(setcar (cdr bytes-tail) (logand pc 255))
(setcar bytes-tail (lsh pc -8))
;; FIXME: Replace this by some workaround.
(if (> (car bytes-tail) 255) (error "Bytecode overflow")))
such that if the `pc' (which is the target address) is sufficiently
close to the current address (which the current code doesn't compute
currently but which should be (length bytes-tail), IIRC), then change
the opcode, use setcdr to drop a byte, and set the offset byte.
Of course, since that will change the offsets of subsequent code, you
might prefer to traverse patchlist in the reverse order and keep
a counter of dropped bytes, and you'll have to change
(setq pc (caar bytes-tail)) to something like
(setq pc (- (caar bytes-tail) dropped-bytes)).