Created
April 18, 2018 22:25
-
-
Save ahti/50aaec1199f7bb8da892eb6c2588b3fc to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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