Files
swift-mirror/test/stdlib/SIMDConcreteMasks.swift.gyb
Stephen Canon 7e326063c5 Concrete SIMD operations, part 1 (#36172)
Adds concrete overloads of the following SIMD operations:
- Comparisons: .==, .!=, .<, .<=, .>, .>=
- Logical operations on masks: .!, .&, .^, .|
- Integer arithmetic: &+, &-, &, &+=, &-=, &=
This makes some simple benchmarks 10-100x faster, which is basically a no-brainer, while staying away from the most heavily used operators, so hopefully doesn't impact compilation performance too badly.
2021-03-22 16:48:21 -04:00

68 lines
2.0 KiB
Swift

//===--- SIMDConcreteMasks.swift.gyb --------------------------*- swift -*-===//
//
// This source file is part of the Swift.org open source project
//
// Copyright (c) 2021 Apple Inc. and the Swift project authors
// Licensed under Apache License v2.0 with Runtime Library Exception
//
// See https://swift.org/LICENSE.txt for license information
// See https://swift.org/CONTRIBUTORS.txt for the list of Swift project authors
//
//===----------------------------------------------------------------------===//
// RUN: %empty-directory(%t)
// RUN: %gyb -DCMAKE_SIZEOF_VOID_P=%target-ptrsize %s -o %t/SIMDConcreteMasks.swift
// RUN: %line-directive %t/SIMDConcreteMasks.swift -- %target-build-swift %t/SIMDConcreteMasks.swift -o %t/a.out
// RUN: %target-codesign %t/a.out
// RUN: %line-directive %t/SIMDConcreteMasks.swift -- %target-run %t/a.out
// REQUIRES: executable_test
import StdlibUnittest
%{
from __future__ import division
from SwiftIntTypes import all_integer_types
word_bits = int(CMAKE_SIZEOF_VOID_P) * 8
storagescalarCounts = [2,4,8,16,32,64]
vectorscalarCounts = storagescalarCounts + [3]
}%
func genericMaskOps<T>(
_ a: SIMDMask<T>, _ b: SIMDMask<T>
) -> (
not: SIMDMask<T>,
and: SIMDMask<T>,
or: SIMDMask<T>,
xor: SIMDMask<T>
) where T: SIMD, T.Scalar: SignedInteger & FixedWidthInteger {(
not: .!a,
and: a .& b,
or: a .| b,
xor: a .^ b
)}
%for int in all_integer_types(word_bits):
% Scalar = int.stdlib_name
% for n in vectorscalarCounts:
% Vector = "SIMD" + str(n) + "<" + Scalar + ">"
% storageN = 4 if n == 3 else n
% s = "s" if int.is_signed else "u"
% Builtin = "Vec" + str(storageN) + "xInt" + str(int.bits)
% if int.is_signed:
var ${Scalar}x${n}Mask_TestSuite = TestSuite("${Scalar}x${n}Mask")
${Scalar}x${n}Mask_TestSuite.test("boolean operators") {
let a = SIMDMask<${Vector}>.random()
let b = SIMDMask<${Vector}>.random()
let (not,and,or,xor) = genericMaskOps(a, b)
expectEqual(not, .!a)
expectEqual(and, a .& b)
expectEqual(or, a .| b)
expectEqual(xor, a .^ b)
}
% end
% end
%end
runAllTests()