question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Operations returns an OpBinding value regardless of whether all operand is literal or not

See original GitHub issue

Type of issue: feature request

Impact: unknown

Development Phase: request

If the current behavior is a bug, please provide the steps to reproduce the problem:

What is the current behavior? For now, operations always return OpBinding value regardless of whether all operands are literal or not. Probably, this behavior sometimes causes inconvenient. For example, is in switch statement only accepts literal, and this is why the following is illegal.

switch(x) {
  is(Cat(1.U(2.W), 0.U(2.W))) { ... }
  ...
}

However, in C, this is legal(e.g. case 1 + 2: …), so users that expect switch behavior like C probably confuse by this illegalness.

What is the expected behavior? I think it is better that an operation of literals returns an ElementLitBinding value insted of OpBinding one. If the solution already exists, please teach me.

Please tell us about your environment:

  • chiselVersion: 3.1.+ (chisel-template)
  • scalaVersion:2.11.12
  • OS: macOS HighSierra 10.13.6

What is the use case for changing the behavior?

Issue Analytics

  • State:open
  • Created 5 years ago
  • Comments:5 (5 by maintainers)

github_iconTop GitHub Comments

2reactions
jackkoenigcommented, Jan 28, 2019

In order to keep the code more-or-less DRY while supporting more propagation in Chisel, we could construct FIRRTL nodes as we go* and leverage FIRRTL’s own constant propagation.

*Since names are not yet known, we’d have to do it in some name agnostic way, I don’t think it would be all that difficult though.

0reactions
Soya-Onishicommented, Jan 29, 2019
switch(io.in) {
  is(Cat(0.U, 0.U)) { ... }
  is(Cat(0.U, 1.U)) { ... }
  is(Cat(1.U, 0.U)) { ... }
  is(Cat(1.U, 1.U)) { ... }
}

The above code causes the following error.

[error] java.lang.IllegalArgumentException: requirement failed: is conditions must be literals!
[error] 	at scala.Predef$.require(Predef.scala:224)
[error] 	at chisel3.util.SwitchContext$$anonfun$1.apply(Conditional.scala:31)
[error] 	at chisel3.util.SwitchContext$$anonfun$1.apply(Conditional.scala:30)
...

This error tell me the Cat result is exactly not literal.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Literals - IBM
You can use literals as operands in order to introduce data into your program. The literal is a special type of relocatable term....
Read more >
1.9 — Introduction to literals and operators - Learn C++
In mathematics, an operation is a mathematical calculation involving zero or more input values (called operands) that produces a new value ...
Read more >
Variables and Operators - CMU School of Computer Science
We must learn to think of all Java operators, regardless of their operand and result types, as computing a value in this way....
Read more >
boolean operations and conditionals
If the first operand of || is true, the second is not evaluated. – & and | are non-shorting operators. • Both operands...
Read more >
Secrets of Logical ️ Operators in Javascript ‍ - Level Up Coding
The OR (||) operation returns the first truthy value or the last value if no truthy value is found. ... If any one...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found