Hi all--
I'm looking into adding "relaxed" floating-point operations in Swift Numerics to allow the compiler to loop-unroll and vectorize floating-point accumulations. See feature request and PR for more information.
At present, the implementation uses a straw-man spelling of _relaxedAdd
and _relaxedMul
. I would like to solicit ideas about how these should eventually be exposed as "real API". Some options:
-
&+
and&*
are available forFloatingPoint
. While "relaxed" operations are not the same as wrapping operations on integers, they are spiritually quite similar--they relax the semantics of the type to make the operation associative and unlock compiler optimizations. On the other hand, there are also important differences:&+
and+
always either produce the same result on integers, or+
traps. This is not true for the relaxed floating-point operations; they can simply produce different results than normal arithmetic does. -
I could invent another "modified operator" spelling for these. I dunno what, but I'm sure we could come up with something.
-
I could add a module
RelaxedFloatingPoint
module that shadows on the standard library+
and*
with the relaxed operations when imported. This is nice in some ways, but (to me) unacceptable given that we don't have a mechanism to scope imports. The transformation would apply at file-scope, which is undesirable. -
These could be placed in an enum namespace like the
Augmented
operations are:Relaxed.sum(a, b)
. This is nice and unambiguous, but I think too wordy for this use case. This might be acceptable given a sufficiently rich set of higher-level operations defined in terms of them, however. If users don't have to resort to the bare arithmetic operations very often, having a wordy spelling for them is OK. -
...