google / google/xls

[enhancement] support for const if expr in proc config

Open
#1,749 1 comment 0 reactions 0 assignees View on GitHub
enhancement
Dominant language
C++
Stars
1.9k
Forks
283
Avg merge
2d 10h
Merged PRs (30d)
135

Description

### What's hard to do? (limit 100 words)

Currently it's different to perform compile time conditional in proc's `config` due to the lack of `const if` expressions.

Example:
```
let f32_0 = float32::zero(false);
let f32_2 = F32 { sign: false, bexp: u8:128, fraction: u23:0 };

unroll_for! (row, _): (u32, ()) in u32:0..ROWS {
unroll_for! (col, _): (u32, ()) in u32:0..COLS {
let weight = if row == col { f32_2 } else { f32_0 };
spawn node(
west_inputs[row][col], north_inputs[row][col], east_outputs[row][col + u32:1],
south_outputs[row + u32:1][col], weight);
}(());
}(());
```
Would trigger the following error:
```
E1128 00:34:17.014452 3268 command_line_utils.cc:47] Could not extract a textual position from error message: INTERNAL: Let RHS not evaluated as constexpr: weight : if u32:0 == u32:0 { f32_2 } else { f32_0 }
```
Even though weight could be resolve staticaly from indexes of the unrolled loops.

### Current best alternative workaround (limit 100 words)

Nest the if expression inside the struct initialization:
```
let weight = F32 {
sign: false,
bexp: if col == row { u8:128 } else { u8:0 },
fraction: u23:0,
};
```
### Your view of the "best case XLS enhancement" (limit 100 words)

`if` expression would be inferred as constant in the context of a `proc` `config` function or there would be a dedicated `const_if!` macros.

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.