Comparable and FloatingPoint types

Even if you could interact with them in Swift, that would give worse performance on every existing architecture; reading and modifying these registers is generally a "stop the world" serializing operation, while testing for NaN with comparison is just another floating-point operation.

In a model where there were no "normal" floating-point operations, you could simply enable the invalid trap ("unmask the floating-point exception"), but you'd still need to toggle it at any call that could potentially leave the Swift model, which is every call to code you don't control, which would still end up being prohibitive. In a model that has both "normal" floating-point and your custom types, you have to toggle it around every operation, which is even worse.

You'll also run into the fact that trapping on IEEE status flags is an optional feature of several ISAs (e.g. ARM), and not implemented on common cores.

Right, this approach would require a small amount of stdlib / compiler magic.

3 Likes