Skip to content

Instantly share code, notes, and snippets.

@ahti
Created April 18, 2018 22:25
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ahti/50aaec1199f7bb8da892eb6c2588b3fc to your computer and use it in GitHub Desktop.
Save ahti/50aaec1199f7bb8da892eb6c2588b3fc to your computer and use it in GitHub Desktop.
// this needs to run with the `-parse-stdlib` command line option passed to swift:
// swift -parse-stdlib simd.swift
import Swift //Import swift stdlib
struct DoubleX4 {
var _v: Builtin.Vec4xFPIEEE64
subscript(_ idx: Int32) -> Double {
@_transparent
get {
let elt = Builtin.extractelement_Vec4xFPIEEE64_Int32(_v, idx._value)
return Double(_bits: elt)
}
@_transparent
set {
_v = Builtin.insertelement_Vec4xFPIEEE64_FPIEEE64_Int32(_v, newValue._value, idx._value)
}
}
@_transparent
init() {
_v = Builtin.zeroInitializer()
}
@_transparent
init(_bits: Builtin.Vec4xFPIEEE64) {
_v = _bits
}
}
extension DoubleX4: CustomDebugStringConvertible {
var debugDescription: String {
return "DoubleX4(\((0..<4).map { self[$0] }))"
}
}
extension DoubleX4 {
@_transparent
static func +(lhs: DoubleX4, rhs: DoubleX4) -> DoubleX4 {
return DoubleX4(_bits: Builtin.fadd_Vec4xFPIEEE64(lhs._v, rhs._v))
}
}
var d1 = DoubleX4()
d1[0] = 123
d1[2] = 42
print(d1)
var d2 = DoubleX4()
d2[1] = 321
d2[2] = 24
print(d2)
var d3 = d1 + d2
print(d3)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment