0

Should a 8086 emulator test for this SI/DI wraparound, or was it so rarely used that it could get by without checking?

I'm only concerned about new wraparound values of SI/DI that are actually used in a string instruction.

TonyB
  • 31
  • 1
  • 1
    What would the check do? AFAIK there is no special case, the wrapping just happens – harold Dec 08 '20 at 20:29
  • The emulation would be faster without the wraparound check. – TonyB Dec 08 '20 at 20:41
  • Why? Aren't you using `uint16_t` already to get wrapping for free? If not, omitting it seems like a bad idea, although you're right that it's *probably* rare in real-world code (not fuzz tests). Trading correctness for speed depends on the use-case and goals for your project. You could check once outside a copy loop for `rep movsb` whether `si+cx` or `di+cx` would wrap, and if so do separate memmove chunks. (And maybe set a max chunk size anyway if you want to allow some interruptibility during a copy.) – Peter Cordes Dec 08 '20 at 21:26
  • Also remember that the direction flag (DF) can be forward and backwards. – Michael Petch Dec 08 '20 at 21:35
  • The emulator is written in assembler, not C. Lack of code space prevents testing outside the copy loop. Direction flag is implemented. Wraparound is checked currently, but time per rep iteration could be halved or almost halved without it. I'd be interested to see any real-world wraparound examples. – TonyB Dec 09 '20 at 15:42
  • Ok, if you're writing in x86 assembler, 16-bit operand-size is easily available (at the cost of an operand-size prefix in 32 or 64-bit mode). If not, IDK what ISA you're targeting. (I was guessing you might be writing in a much higher level language like JavaScript that doesn't give you fixed-width 16-bit integer types, since you didn't say in the question what motivated this corner-cutting.) – Peter Cordes Dec 09 '20 at 16:52

0 Answers0