We should push this project as a proposal to Swift-Evolution then.
Also: are those hooks available for a library compiled outside the Apple/Swift repo? That'd be important if anyone's gonna try and build something reliant on SIMD functionality without that library.
wait so all you have to do is add a definition to the standard library that wraps Builtin.Vec4xFPIEEE64 and friends and write the operators, and that will just,, work? That doesnât seem too hard of a Swift Evolution implementationâŠ
(Narrator: It was too hard of a Swift Evolution implementation!)
The -parse-stdlib flag grants access to the Builtin module and disables implicit importing of the Swift module (you can still explicitly import it). This shouldn't be used by user code because the Builtin module has no stability guarantee at all. Instead, we should define a proper cross-platform SIMD module in the Swift project, built in terms of those internal builtins. Higher level code would layer on top of it.
We could start with something like BLAS's Level 1. Afaik, those are the operations that directly translate to SIMD. The other ones seem to be built on top of it for the most part. Functionality like Levels 2 and 3 could be let to the higher level code to implement.
So whatâs stopping us from making a PR in the standard library to expose the basic operations? it seems like we have literally all the tools we need right now
LLVM has a bunch of underlying features (LLVM Language Reference Manual â LLVM 16.0.0git documentation) that are exposed more-or-less directly through the Builtin module. It is important to understand them as well if you plan to do work in this area.
I'm not sure what your objection is to swizzling, can you elaborate? The OpenCL syntax isn't at all important of course, but the semantics have payed for itself many times over.
I actually have a more general âsimd 2â module that doesnât depend on any Darwin SDK support which I intend to propose in some hand-wavy âsoonâ timeframe (wildly out of scope for 4.2, so Iâve been deliberately sitting on it). Itâs still WIP, and there are some questions to resolve about whether it goes in the stdlib proper, or is (one of) the first non-default standard libs or what and exactly what the bindings look like, etc, but it exposes the bulk of the builtin llvm ext_vector support for a wide range of types and vector lengths.
It does not support arbitrary lengths via weird template params or anything exotic like that. Thatâs out of scope for my purposes.
Yes! Well, sort of. I haven't had much time to spend on this, but I have played around with some solutions. Honestly, I'm kind of stuck on how to proceed at this point.
You can check out the readme on my MathTypes project on Github for a summary of what I think are some of the major design criteria that came out of this discussion. The MathProtocols.swift is a sketch of how the algebra described in the readme might be encoded as protocols. However, I think there might be a better way... I'm not sure what
The playground in there shows some basic functionality that comes from an early draft---it pulls from MathTypes.swift, which is a brute force, but effective (partial) implementation.
Fractions are worse than both floating-point and fixed-point numbers is almost every way. Most importantly:
If you don't round results, in computations that aren't designed to work out just so, the size of the numerator and denominator is exponential in the number of terms in the computation.
If you do round results, the result will generally be significantly less accurate than what you would get with an equivalently-sized fixed- or floating-point representation, because rationals are not uniformly spaced and have redundant representations.
The are legitimately useful for some computational geometry operations where the number of terms involved is tightly bounded, but those computations can also just be rephrased in terms of integers, so you don't really need a rational type to implement them.
They're also real good at representing 1/3 exactly, which seems appealing, but has more psychological benefit than anything else.