Skip to content

[benchmark] Add another test to floating point conversion benchmark #33975

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Sep 24, 2020
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
47 changes: 41 additions & 6 deletions benchmark/single-source/FloatingPointConversion.swift
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,16 @@ public let FloatingPointConversion = [
runFunction: run_ConvertFloatingPoint_MockFloat64ToDouble,
tags: [.validation, .api],
setUpFunction: { blackHole(mockFloat64s) }),
BenchmarkInfo(
name: "ConvertFloatingPoint.MockFloat64Exactly",
runFunction: run_ConvertFloatingPoint_MockFloat64Exactly,
tags: [.validation, .api],
setUpFunction: { blackHole(mockFloat64s) }),
BenchmarkInfo(
name: "ConvertFloatingPoint.MockFloat64Exactly2",
runFunction: run_ConvertFloatingPoint_MockFloat64Exactly2,
tags: [.validation, .api],
setUpFunction: { blackHole(mockFloat64s) }),
BenchmarkInfo(
name: "ConvertFloatingPoint.MockFloat64ToInt64",
runFunction: run_ConvertFloatingPoint_MockFloat64ToInt64,
Expand Down Expand Up @@ -130,6 +140,11 @@ struct MockFloat64: MockBinaryFloatingPoint {
init(_ _value: Double) { self._value = _value }
}

struct MockFloat32: MockBinaryFloatingPoint {
var _value: Float
init(_ _value: Float) { self._value = _value }
}

let doubles = [
1.8547832857295, 26.321549267719135, 98.9544480962058, 73.70286973782363,
82.04918555938816, 76.38902969312758, 46.35647857011161, 64.0821426030317,
Expand All @@ -147,20 +162,40 @@ let doubles = [

let mockFloat64s = doubles.map { MockFloat64($0) }

// See also: test/SILOptimizer/floating_point_conversion.swift

@inline(never)
public func run_ConvertFloatingPoint_MockFloat64ToDouble(_ N: Int) {
for _ in 0..<(N * 100) {
for element in mockFloat64s {
let f = Double(identity(element))
blackHole(f)
}
}
}

@inline(__always)
func convert<
T: BinaryFloatingPoint, U: BinaryFloatingPoint
>(_ value: T, to: U.Type) -> U {
U(value)
>(exactly value: T, to: U.Type) -> U? {
U(exactly: value)
}

// See also: test/SILOptimizer/floating_point_conversion.swift
@inline(never)
public func run_ConvertFloatingPoint_MockFloat64Exactly(_ N: Int) {
for _ in 0..<(N * 25) {
for element in mockFloat64s {
let f = convert(exactly: identity(element), to: Double.self)
blackHole(f)
}
}
}

@inline(never)
public func run_ConvertFloatingPoint_MockFloat64ToDouble(_ N: Int) {
for _ in 0..<(N * 100) {
public func run_ConvertFloatingPoint_MockFloat64Exactly2(_ N: Int) {
for _ in 0..<(N * 25) {
for element in mockFloat64s {
let f = Double(identity(element))
let f = convert(exactly: identity(element), to: MockFloat32.self)
blackHole(f)
}
}
Expand Down