|
| 1 | +//===--- SIMDFloatComparisons.swift.gyb -----------------------*- swift -*-===// |
| 2 | +// |
| 3 | +// This source file is part of the Swift.org open source project |
| 4 | +// |
| 5 | +// Copyright (c) 2025 Apple Inc. and the Swift project authors |
| 6 | +// Licensed under Apache License v2.0 with Runtime Library Exception |
| 7 | +// |
| 8 | +// See https://swift.org/LICENSE.txt for license information |
| 9 | +// See https://swift.org/CONTRIBUTORS.txt for the list of Swift project authors |
| 10 | +// |
| 11 | +//===----------------------------------------------------------------------===// |
| 12 | +// RUN: %empty-directory(%t) |
| 13 | +// RUN: %gyb %s -o %t/SIMDFloatComparisons.swift |
| 14 | +// RUN: %target-swift-frontend -primary-file %t/SIMDFloatComparisons.swift -S | %FileCheck %t/SIMDFloatComparisons.swift --check-prefix=CHECK --check-prefix=CHECK-%target-cpu --check-prefix=CHECKOnone-%target-cpu |
| 15 | +// RUN: %target-swift-frontend -primary-file %t/SIMDFloatComparisons.swift -S -O | %FileCheck %t/SIMDFloatComparisons.swift --check-prefix=CHECK --check-prefix=CHECK-%target-cpu --check-prefix=CHECKO-%target-cpu |
| 16 | + |
| 17 | +import Swift |
| 18 | + |
| 19 | +%for bits in [16,32,64]: |
| 20 | +% scalar = {16:'Float16',32:'Float',64:'Double'}[bits] |
| 21 | +% for totalBits in [64,128]: |
| 22 | +% n = totalBits // bits |
| 23 | +% if n != 1: |
| 24 | +% neonSuffix = str(n) + {8:'b',16:'h',32:'s',64:'d'}[bits] |
| 25 | +% if bits == 16: |
| 26 | +#if arch(arm64) |
| 27 | +@available(macOS 11.0, iOS 14.0, tvOS 14.0, watchOS 7.0, *) |
| 28 | +% end |
| 29 | +func compare_eq${n}x${bits}( |
| 30 | + _ a: SIMD${n}<${scalar}>, _ b: SIMD${n}<${scalar}> |
| 31 | +) -> SIMDMask<SIMD${n}<Int${bits}>> { |
| 32 | + a .== b |
| 33 | +} |
| 34 | +% if bits == 16: |
| 35 | +#endif |
| 36 | +// CHECK-arm64: compare_eq${n}x${bits}{{[[:alnum:]_]+}}: |
| 37 | +% else: |
| 38 | +// CHECK: compare_eq${n}x${bits}{{[[:alnum:]_]+}}: |
| 39 | +// CHECK-x86_64: cmpeqp${'s' if bits == 32 else 'd'} |
| 40 | +// CHECK-x86_64: ret |
| 41 | +% end |
| 42 | +// CHECKO-arm64-NEXT: fcmeq.${neonSuffix} v0, v0, v1 |
| 43 | +// CHECKO-arm64-NEXT: ret |
| 44 | +// CHECKOnone-arm64: fcmeq.${neonSuffix} |
| 45 | +// CHECKOnone-arm64: ret |
| 46 | + |
| 47 | +% if bits == 16: |
| 48 | +#if arch(arm64) |
| 49 | +@available(macOS 11.0, iOS 14.0, tvOS 14.0, watchOS 7.0, *) |
| 50 | +% end |
| 51 | +func compare_ne${n}x${bits}( |
| 52 | + _ a: SIMD${n}<${scalar}>, _ b: SIMD${n}<${scalar}> |
| 53 | +) -> SIMDMask<SIMD${n}<Int${bits}>> { |
| 54 | + a .!= b |
| 55 | +} |
| 56 | +% if bits == 16: |
| 57 | +#endif |
| 58 | +// CHECK-arm64: compare_ne${n}x${bits}{{[[:alnum:]_]+}}: |
| 59 | +% else: |
| 60 | +// CHECK: compare_ne${n}x${bits}{{[[:alnum:]_]+}}: |
| 61 | +// CHECK-x86_64: cmpneqp${'s' if bits == 32 else 'd'} |
| 62 | +// CHECK-x86_64: ret |
| 63 | +% end |
| 64 | +// CHECKO-arm64-NEXT: fcmeq.${neonSuffix} [[TMP:v[0-9]+]], v0, v1 |
| 65 | +// CHECKO-arm64-NEXT: mvn.${totalBits//8}b v0, [[TMP]] |
| 66 | +// CHECKO-arm64-NEXT: ret |
| 67 | +// CHECKOnone-arm64: fcmeq.${neonSuffix} |
| 68 | +// CHECKOnone-arm64: mvn.${totalBits//8}b |
| 69 | +// CHECKOnone-arm64: ret |
| 70 | + |
| 71 | +% if bits == 16: |
| 72 | +#if arch(arm64) |
| 73 | +@available(macOS 11.0, iOS 14.0, tvOS 14.0, watchOS 7.0, *) |
| 74 | +% end |
| 75 | +func compare_lt${n}x${bits}( |
| 76 | + _ a: SIMD${n}<${scalar}>, _ b: SIMD${n}<${scalar}> |
| 77 | +) -> SIMDMask<SIMD${n}<Int${bits}>> { |
| 78 | + a .< b |
| 79 | +} |
| 80 | +% if bits == 16: |
| 81 | +#endif |
| 82 | +// CHECK-arm64: compare_lt${n}x${bits}{{[[:alnum:]_]+}}: |
| 83 | +% else: |
| 84 | +// CHECK: compare_lt${n}x${bits}{{[[:alnum:]_]+}}: |
| 85 | +// CHECK-x86_64: cmpltp${'s' if bits == 32 else 'd'} |
| 86 | +// CHECK-x86_64: ret |
| 87 | +% end |
| 88 | +// CHECKO-arm64-NEXT: fcmgt.${neonSuffix} v0, v1, v0 |
| 89 | +// CHECKO-arm64-NEXT: ret |
| 90 | +// CHECKOnone-arm64: fcmgt.${neonSuffix} |
| 91 | +// CHECKOnone-arm64: ret |
| 92 | + |
| 93 | +% if bits == 16: |
| 94 | +#if arch(arm64) |
| 95 | +@available(macOS 11.0, iOS 14.0, tvOS 14.0, watchOS 7.0, *) |
| 96 | +% end |
| 97 | +func compare_le${n}x${bits}( |
| 98 | + _ a: SIMD${n}<${scalar}>, _ b: SIMD${n}<${scalar}> |
| 99 | +) -> SIMDMask<SIMD${n}<Int${bits}>> { |
| 100 | + a .<= b |
| 101 | +} |
| 102 | +% if bits == 16: |
| 103 | +#endif |
| 104 | +// CHECK-arm64: compare_le${n}x${bits}{{[[:alnum:]_]+}}: |
| 105 | +% else: |
| 106 | +// CHECK: compare_le${n}x${bits}{{[[:alnum:]_]+}}: |
| 107 | +// CHECK-x86_64: cmplep${'s' if bits == 32 else 'd'} |
| 108 | +// CHECK-x86_64: ret |
| 109 | +% end |
| 110 | +// CHECKO-arm64-NEXT: fcmge.${neonSuffix} v0, v1, v0 |
| 111 | +// CHECKO-arm64-NEXT: ret |
| 112 | +// CHECKOnone-arm64: fcmge.${neonSuffix} |
| 113 | +// CHECKOnone-arm64: ret |
| 114 | + |
| 115 | +% if bits == 16: |
| 116 | +#if arch(arm64) |
| 117 | +@available(macOS 11.0, iOS 14.0, tvOS 14.0, watchOS 7.0, *) |
| 118 | +% end |
| 119 | +func compare_ge${n}x${bits}( |
| 120 | + _ a: SIMD${n}<${scalar}>, _ b: SIMD${n}<${scalar}> |
| 121 | +) -> SIMDMask<SIMD${n}<Int${bits}>> { |
| 122 | + a .>= b |
| 123 | +} |
| 124 | +% if bits == 16: |
| 125 | +#endif |
| 126 | +// CHECK-arm64: compare_ge${n}x${bits}{{[[:alnum:]_]+}}: |
| 127 | +% else: |
| 128 | +// CHECK: compare_ge${n}x${bits}{{[[:alnum:]_]+}}: |
| 129 | +// CHECK-x86_64: cmplep${'s' if bits == 32 else 'd'} |
| 130 | +// CHECK-x86_64: ret |
| 131 | +% end |
| 132 | +// CHECKO-arm64-NEXT: fcmge.${neonSuffix} v0, v0, v1 |
| 133 | +// CHECKO-arm64-NEXT: ret |
| 134 | +// CHECKOnone-arm64: fcmge.${neonSuffix} |
| 135 | +// CHECKOnone-arm64: ret |
| 136 | + |
| 137 | +% if bits == 16: |
| 138 | +#if arch(arm64) |
| 139 | +@available(macOS 11.0, iOS 14.0, tvOS 14.0, watchOS 7.0, *) |
| 140 | +% end |
| 141 | +func compare_gt${n}x${bits}( |
| 142 | + _ a: SIMD${n}<${scalar}>, _ b: SIMD${n}<${scalar}> |
| 143 | +) -> SIMDMask<SIMD${n}<Int${bits}>> { |
| 144 | + a .> b |
| 145 | +} |
| 146 | +% if bits == 16: |
| 147 | +#endif |
| 148 | +// CHECK-arm64: compare_gt${n}x${bits}{{[[:alnum:]_]+}}: |
| 149 | +% else: |
| 150 | +// CHECK: compare_gt${n}x${bits}{{[[:alnum:]_]+}}: |
| 151 | +// CHECK-x86_64: cmpltp${'s' if bits == 32 else 'd'} |
| 152 | +// CHECK-x86_64: ret |
| 153 | +% end |
| 154 | +// CHECKO-arm64-NEXT: fcmgt.${neonSuffix} v0, v0, v1 |
| 155 | +// CHECKO-arm64-NEXT: ret |
| 156 | +// CHECKOnone-arm64: fcmgt.${neonSuffix} |
| 157 | +// CHECKOnone-arm64: ret |
| 158 | + |
| 159 | +% end |
| 160 | +% end |
| 161 | +%end |
0 commit comments