Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion docs_src/dslx_reference.md
Original file line number Diff line number Diff line change
Expand Up @@ -1610,7 +1610,7 @@ ranging from 0 to 7 and the value at the index `e = x[i]`.
```
fn prefix_scan_eq(x: u32[8]) -> u3[8] {
let (_, _, result) =
for ((i, e), (prior, count, result)) in enumerate(x) {...
for ((i, e), (prior, count, result)) in std::enumerate(x) {...
```

### `for` Expression
Expand Down
17 changes: 9 additions & 8 deletions docs_src/dslx_std.md
Original file line number Diff line number Diff line change
Expand Up @@ -312,14 +312,6 @@ Example usage:
See also the
[IR semantics for the `encode` op](./ir_semantics.md#encode).

### `enumerate`

Decorates elements of an array with indices. Has the following signature:

```
fn enumerate<T: type, N: u32>(x: T[N]) -> (u32, T)[N]
```

### `one_hot`

Converts a value to one-hot form. Has the following signature:
Expand Down Expand Up @@ -1573,6 +1565,15 @@ fn test_distinct_with_invalid() {
}
```

### `std::enumerate`

Takes an array and produces an array of `(index, value)` tuples, where index is
the position of each element in the input array. Has the following signature:

```dslx-snippet
pub fn enumerate<T: type, N: u32>(x: T[N]) -> (u32, T)[N]
```

## Rounding functions: `import round`

XLS provides rounding primitives that implement the rounding behavior defined by the [IEEE
Expand Down
6 changes: 3 additions & 3 deletions docs_src/tutorials/crc32.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,9 @@ A DSLX `for` loop has the following structure:
but it should be able to hold all possible loop index values).
3. An
[iterable](../dslx_reference.md),
which can be a range expression `start..limit`, `enumerate()`, or an
array object. This dictates the number of iterations of the loop to
complete.
which can be a range expression `start..limit`, `std::enumerate()`,
or an array object. This dictates the number of iterations of the loop
to complete.
2. The loop body: this has the same general form as a DSLX function.
Particularly noteworthy is that the loop body ends by stating the "return"
value. In a `for` loop, this "return" value is either used as the input to
Expand Down
2 changes: 1 addition & 1 deletion docs_src/tutorials/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ design techniques. Here they are, grouped by topic:
* [`for` expressions](crc32.md) : Explains how to understand and write looping
constructs in DSLX.
* [`enumerate` and `match` expressions](prefix_scan.md) : Explains how to use
`enumerate()` expressions to control loop iteration and how to use the
`std::enumerate()` expressions to control loop iteration and how to use the
`match` pattern-matching expression for selecting between alternatives.
* [What is a proc?](what_is_a_proc.md): A step-by-step introduction to procs,
XLS's answer to how to write modules with state and explicit communication
Expand Down
13 changes: 4 additions & 9 deletions docs_src/tutorials/prefix_scan.md
Original file line number Diff line number Diff line change
Expand Up @@ -81,12 +81,12 @@ loop-carried values:

```dslx-snippet
for ((i, elem), (prior, count, result)): ((u32, u32), (u32, u3, u3[8]))
in enumerate(x) {
in std::enumerate(x) {
```

The iterable of this loop is `enumerate(x)`. On each iteration, this construct
delivers a tuple consisting of current index and current element. This is
represented as the tuple `(i, elem)` in the `for` construct.
The iterable of this loop is created by `std::enumerate(x)`. On each iteration,
this construct delivers a tuple consisting of current index and current element.
This is represented as the tuple `(i, elem)` in the `for` construct.

The loop next specifies the accumulator, which is a 3-tuple consisting of the
values named `prior`, `count`, and `result`.
Expand Down Expand Up @@ -205,8 +205,3 @@ xls$ bazel run -c opt //xls/dslx:interpreter_main -- \
[ OK ]
[===============] 2 test(s) ran; 0 failed; 0 skipped.
```

(Note that `--compare=none` is currently required because `enumerate` ranges are
not currently convertable to IR, otherwise running the DSLX interpreter would do
implicit comparison to IR interpreter -- see
[google/xls#164](https://github.com/google/xls/issues/164).)
Loading