Skip to content

Commit

Permalink
[docs] Fix incorrect IR semantics documentation
Browse files Browse the repository at this point in the history
- Adds missing `nand` and `nor` operations and clarifies their
  behaviour.

- Adds missing reduction operations.

- Correct typing of `eq` and `ne` operands: They can by any type, not
  just `bits`
  • Loading branch information
schilkp committed Jan 7, 2025
1 parent 14a6ae0 commit d70bab0
Showing 1 changed file with 70 additions and 12 deletions.
82 changes: 70 additions & 12 deletions docs_src/ir_semantics.md
Original file line number Diff line number Diff line change
Expand Up @@ -191,13 +191,16 @@ Operation | Opcode | Semantics
### Variadic bitwise operations

Performs a bit-wise operation on one-or-more identically-typed bits operands. If
only a single argument is provided the operation is a no-op.
only a single argument is provided, the operations `and`, `or`, and `xor` are a no-op,
while `nand` and `nor` act as a bit-wise not.

**Syntax**

```
result = and(operand_{0}, ..., operand_{N-1})
result = nand(operand_{0}, ..., operand_{N-1})
result = or(operand_{0}, ..., operand_{N-1})
result = nor(operand_{0}, ..., operand_{N-1})
result = xor(operand_{0}, ..., operand_{N-1})
```

Expand All @@ -210,11 +213,43 @@ Value | Type

**Operations**

Operation | Opcode | Semantics
--------- | ---------- | ----------------------------
`and` | `Op::kAnd` | `result = lhs & rhs & ...`
`or` | `Op::kOr` | `result = lhs \| rhs \| ...`
`xor` | `Op::kXor` | `result = lhs ^ rhs ^ ...`
Operation | Opcode | Semantics
--------- | ----------- | ------------------------------
`and` | `Op::kAnd` | `result = lhs & rhs & ...`
`nand` | `Op::kNand` | `result = ~(lhs & rhs & ...)`
`or` | `Op::kOr` | `result = lhs \| rhs \| ...`
`nor` | `Op::kNor` | `result = ~(lhs \| rhs \| ...)`
`xor` | `Op::kXor` | `result = lhs ^ rhs ^ ...`

### Bitwise Reduction Operations

Performs a bit-wise reduction operation on all bits of a single bits-typed
operand, producing a single bit. For an operand of width 1, they act as no-ops.


**Syntax**

```
result = and_reduce(operand)
result = or_reduce(operand)
result = xor_reduce(operand)
```

**Types**

Value | Type
--------- | ---------
`operand` | `bits[N]`
`result` | `bits[1]`


**Operations**

Operation | Opcode | Semantics
------------ | ---------------- | ------------------------------------------
`and_reduce` | `Op::kAndReduce` | `result = operand[0] & operand[1] & ...`
`or_reduce` | `Op::kOrReduce` | `result = operand[0] \| operand[1] \| ...`
`xor_reduce` | `Op::kXorReduce` | `result = operand[0] ^ operand[1] ^ ...`

### Arithmetic unary operations

Expand Down Expand Up @@ -302,17 +337,42 @@ the right operand is zero the result is zero.
both elements having the same type. The outputs are not fully constrained; the
operations are free to return any values that sum to the product `lhs * rhs`.

### Comparison operations
### Equality comparison operations

Performs a comparison on a pair of identically-typed bits operands. Unsigned
operations are prefixed with a 'u', and signed operations are prefixed with a
's'. Produces a result of bits[1] type.
Performs an equality comparison on a pair of identically-typed operands.
Produces a result of bits[1] type.

**Syntax**

```
result = eq(lhs, rhs)
result = ne(lhs, rhs)
```

**Types**

Value | Type
-------- | ---------
`lhs` | `T`
`rhs` | `T`
`result` | `bits[1]`

**Operations**

Operation | Opcode | Semantics
--------- | ---------- | ---------------------
`eq` | `Op::kEq` | `result = lhs == rhs`
`ne` | `Op::kNe` | `result = lhs != rhs`

### Numeric comparison operations

Performs a numeric comparison on a pair of identically-typed bits operands.
Unsigned operations are prefixed with a 'u', and signed operations are prefixed
with a 's'. Produces a result of bits[1] type.

**Syntax**

```
result = sge(lhs, rhs)
result = sgt(lhs, rhs)
result = sle(lhs, rhs)
Expand All @@ -335,8 +395,6 @@ Value | Type

Operation | Opcode | Semantics
--------- | ---------- | ---------------------
`eq` | `Op::kEq` | `result = lhs == rhs`
`ne` | `Op::kNe` | `result = lhs != rhs`
`sge` | `Op::kSGe` | `result = lhs >= rhs`
`sgt` | `Op::kSGt` | `result = lhs > rhs`
`sle` | `Op::kSLe` | `result = lhs <= rhs`
Expand Down

0 comments on commit d70bab0

Please sign in to comment.