diff --git a/Earthfile b/Earthfile index d8ece48..053afbd 100644 --- a/Earthfile +++ b/Earthfile @@ -97,6 +97,7 @@ collect-data: BUILD +sbcl BUILD +scala BUILD +swift + BUILD +swift-simd BUILD +zig all: @@ -389,6 +390,13 @@ swift: RUN --no-cache swiftc leibniz.swift -O -o leibniz -clang-target native -lto=llvm-full DO +BENCH --name="swift" --lang="Swift" --version="swift --version" --cmd="./leibniz" +swift-simd: + FROM swift:5.7-jammy + DO +PREPARE_DEBIAN + DO +ADD_FILES --src="leibniz-simd.swift" + RUN --no-cache swiftc leibniz-simd.swift -O -o leibniz -clang-target native -lto=llvm-full + DO +BENCH --name="swift" --lang="Swift" --version="swift --version" --cmd="./leibniz" + zig: # On 3.16 there is no zig package, but on edge there is FROM alpine:edge diff --git a/src/leibniz-simd.swift b/src/leibniz-simd.swift new file mode 100644 index 0000000..2ecb04f --- /dev/null +++ b/src/leibniz-simd.swift @@ -0,0 +1,28 @@ +import Foundation + +let text = try! String(contentsOfFile: "rounds.txt").split(separator: "\n")[0] +var rounds = UInt(text)! + +var pi: Double = 1.0 + +let roundsRemainder = rounds % 4 +rounds -= roundsRemainder + +rounds += 2 // do this outside the loop + +var i: UInt = 2 +while i < rounds { + let xVec = SIMD4(-1.0, 1.0, -1.0, 1.0) + let iVec = SIMD4(Double(i) + 0, Double(i) + 1, Double(i) + 2, Double(i) + 3) + pi += (xVec / (2.0 * iVec - 1.0)).sum() + i += 4 +} + +for _ in 0..