--------------------------------------------------------------------------------------------- Conditionals Select yields the second variable if the first is true, otherwise yields the third variable.
(i0, i1, i2 frontend.Variable)
| 289 | |
| 290 | // Select yields the second variable if the first is true, otherwise yields the third variable. |
| 291 | func (builder *builder) Select(i0, i1, i2 frontend.Variable) frontend.Variable { |
| 292 | cond := i0 |
| 293 | |
| 294 | // ensures that cond is boolean |
| 295 | builder.AssertIsBoolean(cond) |
| 296 | |
| 297 | cst, ok := builder.constantValue(builder.toVariableId(cond)) |
| 298 | if ok { |
| 299 | if cst.IsZero() { |
| 300 | return i2 |
| 301 | } |
| 302 | return i1 |
| 303 | } |
| 304 | |
| 305 | v := builder.Sub(i1, i2) |
| 306 | w := builder.Mul(cond, v) |
| 307 | return builder.Add(w, i2) |
| 308 | } |
| 309 | |
| 310 | // Lookup2 performs a 2-bit lookup based on the given bits and values. |
| 311 | func (builder *builder) Lookup2(b0, b1 frontend.Variable, i0, i1, i2, i3 frontend.Variable) frontend.Variable { |
no test coverage detected