News for hackers. Stuff that matters.
Re:Writing a self-modifying x86 factorial program by rep_lodsb on Wednesday December 15, 2021 @08:13PM (#29573673)
On older x86 chips - anything before the 486 - there was no cache, but opcode bytes were prefetched into a queue, ranging from 4 bytes (on the 8088) to 16 bytes on the 386. The 286 and 386 had an additional queue holding up to 3 decoded instructions (regardless of length).

These queues where "visible" in their effect on self-modifying code. After modifying one of the instructions that could be already in the queue, you had to do a jump to flush it.

If you know about this, it is obvious how certain code only works when single-stepped through, or perhaps when run on an 8088 with its shorter queue. But few people did, even among experienced programmers.

IIRC the 486 and everything newer can detect when a cache line containing code is changed, so this is no longer necessary (but bad for performance as other commenters said).

Re:Writing a self-modifying x86 factorial program by bogomipz on Wednesday December 15, 2021 @09:09PM (#29574021)
Oh wow this is fascinating bit of history. I wonder how the i-cache drift detection is implemented. Cheers.