hn.today

Code Smells of Desperation (2023)

os2museum.com15 points4 comments
Screenshot of Code Smells of Desperation (2023)

WIN87EM.DLL, the Windows 3.x library for x87 floating-point emulation and hardware support, also handled math exceptions on systems with a coprocessor. Its interrupt routine differs by machine type, but the PC/AT path is strikingly elaborate: it disables interrupts, repeatedly pushes and pops registers, clears the FPU error latch several times, masks interrupts, acknowledges the interrupt controller, and clears FPU exceptions more than once. Only after these delays and repeated operations does it save the FPU environment, inspect the faulting instruction, and pass control to the code that handles the error. Many steps appear redundant, and the routine contrasts with simpler, more conventional handlers.

The convoluted code suggests developers kept modifying the handler until it worked across difficult combinations of processors, coprocessors, and motherboard circuitry. Its repeated delays may have compensated for slow or unreliable hardware, while the latch-clearing sequence may have addressed specific FPU signaling problems. Discussion of the code points to deeper complications: older Microsoft language libraries could use an effectively unbounded FPU stack, making exceptions part of normal operation, and later Intel chips had relevant bugs and changing behavior. The main concern is that the code does not explain which precise problem each workaround solves. Without that record - or access to the hardware that exposed the issue - future programmers cannot safely distinguish needless clutter from essential compatibility fixes.

Read on os2museum.com4 comments on Hacker News

Summary generated by AI from the linked article. hn.today is not affiliated with Hacker News or Y Combinator.

More in Programming

Ggml v1.0.0

Ggml v1.0.0

ggml 1.0.0 removes deprecated public APIs and legacy DIAG_MASK operations, while adding configurable YaRN truncation and FP8 support. It also improves backend performance with quantized matrix multiplication, fused MoE operations, and new attention and scheduling paths. (github.com)

The daily digest

Today's best Hacker News stories, summarized and screenshotted, one email a day.