Skip to content
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

[5.1] Restore elementwise min/max on SIMD #24772

Merged

Conversation

stephentyrone
Copy link
Contributor

Having these as free functions causes expression too complex issues due to overload vis-a-vis min. There are (at least) three plausible solutions:

Fix the typechecker. This is infeasable in the short term; or more precisely, we do not know how much work is involved.

Give these operations different names. Candidates discussed with core team include "pointwiseMin", "elementwiseMin", "lanewiseMin"; these all suffer from the flaw that when someone writes "min" in a SIMD context, they are essentially always looking for either the horizontal minimum (reduction) on a single vector or--more often--the lanewise minimum of two vectors (this operation). It would be odd to give the operation that people actually want the unnecessarily verbose name.

Make these operations static; this is, in effect, a different name, but it's one which frequently allows eliding the qualifier:

let x = v + .min(v, w)

After considerable back-and-forth discussion with core, we settled on pointwiseMin and pointwiseMax. These aren't perfect, but they are explicit, which is worth a lot.

This rounds out SE-0251 for 5.1-branch.

Cherry-pick of #24136

…#24136)

* Restore elementwise min/max on SIMD, but as statics instead of free functions.

Having these as free functions causes expression too complex issues due to overload vis-a-vis min<Collection>. There are (at least) three plausible solutions:

1. Fix the typechecker. This is infeasable in the short term; or more precisely, we do not know how much work is involved.

2. Give these operations different names. Candidates discussed with core team include "pointwiseMin", "elementwiseMin", "lanewiseMin"; these all suffer from the flaw that when someone writes "min" in a SIMD context, they are essentially always looking for either the horizontal minimum (reduction) on a single vector or--more often--the lanewise minimum of two vectors (this operation). It would be odd to give the operation that people actually want the unnecessarily verbose name.

3. Make these operations static; this is, in effect, a different name, but it's one which frequently allows eliding the qualifier:

  let x = v + .min(v, w)

This isn't perfect; you will still need to spell out SIMD4.min( ) fairly often, but that's more concise than any of the proposed alternatives, and at least allows elision some of the time. Also, if you squint, you can pretend that the "." prefix is like ".<" and ".&" and indicates lanewise operation.
@stephentyrone
Copy link
Contributor Author

@swift-ci please test

@swift-ci
Copy link
Contributor

Build failed
Swift Test OS X Platform
Git Sha - e2d03fc

@stephentyrone
Copy link
Contributor Author

@swift-ci please test macOS

@stephentyrone stephentyrone merged commit 16f6074 into swiftlang:swift-5.1-branch May 15, 2019
@stephentyrone stephentyrone deleted the simd-min-max-5.1 branch May 15, 2019 18:18
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants