Skip to content

Commit

Permalink
Add a select operator, to take the place of if-else blocks.
Browse files Browse the repository at this point in the history
This isn't strictly necessary, but it closely corresponds to
conditional-move instructions in common ISAs, and it fills a common need
with the removal if if-else.
  • Loading branch information
sunfishcode committed Aug 17, 2015
1 parent 3b12794 commit 607a1c8
Showing 1 changed file with 5 additions and 2 deletions.
7 changes: 5 additions & 2 deletions AstSemantics.md
Original file line number Diff line number Diff line change
Expand Up @@ -389,6 +389,7 @@ results into the result type.
* `int32.clz`: sign-agnostic count leading zero bits (defined for all values, including zero)
* `int32.ctz`: sign-agnostic count trailing zero bits (defined for all values, including zero)
* `int32.popcnt`: sign-agnostic count number of one bits
* `int32.select`: select between two values with a condition (not short-circuiting)

Shifts interpret their shift count operand as an unsigned value. When the shift
count is at least the bitwidth of the shift, `shl` and `shr` produce `0`, and
Expand All @@ -407,8 +408,8 @@ The same operations are available on 64-bit integers as the those available for

Floating point arithmetic follows the IEEE-754 standard, except that:
- The sign bit and significand bit pattern of any NaN value returned from a
floating point arithmetic operation other than `neg`, `abs`, and `copysign`
are not specified. In particular, the "NaN propagation"
floating point arithmetic operation other than `neg`, `abs`, `copysign`,
and `select` are not specified. In particular, the "NaN propagation"
section of IEEE-754 is not required. NaNs do propagate through arithmetic
operations according to IEEE-754 rules, the difference here is that they do
so without necessarily preserving the specific bit patterns of the original
Expand Down Expand Up @@ -453,6 +454,7 @@ implementations of the remaining required operations.
* `float32.sqrt`: square root
* `float32.min`: minimum (binary operator); if either operand is NaN, returns NaN
* `float32.max`: maximum (binary operator); if either operand is NaN, returns NaN
* `float32.select`: select between two values with a condition (not short-circuiting)

* `float64.add`: addition
* `float64.sub`: subtraction
Expand All @@ -474,6 +476,7 @@ implementations of the remaining required operations.
* `float64.sqrt`: square root
* `float64.min`: minimum (binary operator); if either operand is NaN, returns NaN
* `float64.max`: maximum (binary operator); if either operand is NaN, returns NaN
* `float64.select`: select between two values with a condition (not short-circuiting)

`min` and `max` operations treat `-0.0` as being effectively less than `0.0`.

Expand Down

0 comments on commit 607a1c8

Please sign in to comment.