Skip to content

Conversation

@SiarheiBarysenka
Copy link

It seems ternary operation here prevents creating additional var, which might be a bit faster. It also makes code more readable.

@nikita-leonov
Copy link

I generated two SILs (attached) for min-if and min-ternary. You are right regarding additional var as min-if has stack management routine, while min-ternary SIL does not. Not sure is it optimized anyway further down the line or not, but no matter what the resulting output for min-ternary should be less or equal to min-if, while readability definitely better. I am dying out of curiosity to see what was the reason to write min & max as it is now.

min-if.sil.txt
min-ternary.sil.txt

@rudkx
Copy link
Contributor

rudkx commented Dec 5, 2015

I don't have the IEEE 754-2008 spec handy, but IIRC min() and max() for floating-point types should return the non-NaN value if there is a (quiet) NaN involved. It looks like the floating-point types end up in these functions.

I don't know what the plans are around correcting this behavior. Perhaps @stephentyrone or @gribozavr can weigh in on that?

@gribozavr
Copy link
Contributor

I don't see why ternary-based code would be faster. The optimizer should generate the same code.

If you are interested in making other improvements in this area, please read the discussion in #137.

@gribozavr gribozavr closed this Dec 5, 2015
dabelknap pushed a commit to dabelknap/swift that referenced this pull request Apr 23, 2019
Use a whitelisting model for configuring which rules to use.
kateinoigakukun pushed a commit to kateinoigakukun/swift that referenced this pull request Mar 1, 2020
maldahleh pushed a commit to maldahleh/swift that referenced this pull request Oct 26, 2020
[Concurrency] Add support for 'async' on closures.
freak4pc pushed a commit to freak4pc/swift that referenced this pull request Sep 28, 2022
Refactor common leading arguments out and add --distcc.
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.

4 participants