Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

weird compile result. #76

Closed
RyanSangdeokPark opened this issue Aug 1, 2019 · 4 comments
Closed

weird compile result. #76

RyanSangdeokPark opened this issue Aug 1, 2019 · 4 comments

Comments

@RyanSangdeokPark
Copy link

it's weird compile result is occurred In the '2.2_comb_logic' chapter

In the case of addition of this example, io.out_add should be 4'h8(or 4'b1000), but it's 4'h0 in the generated verilog code.
I want to make sure whether I missed something or not.
or, is this a kind of bug?
for your reference, I ran this one on Jupyter notebook

ss1

@edwardcwang
Copy link
Collaborator

edwardcwang commented Aug 1, 2019

If you try with something like the following, what is the resultant Verilog?

val temp = WireDefault(4.U + 4.U)
io.out_add := temp

This happens because of FIRRTL-level optimization.

@RyanSangdeokPark
Copy link
Author

If you try with something like the following, what is the resultant Verilog?

val temp = WireDefault(4.U + 4.U)
io.out_add := temp

This happens because of FIRRTL-level optimization.

Hi edwardcwang,

I've got same result.

Thanks

@edwardcwang
Copy link
Collaborator

@Ryan-Sangdeok-Park Thanks for the catch, and thank you for your interest in Chisel! Looks like I was mistaken - try 4.U +& 4.U instead. It turns out that 4.U + 4.U is equivalent to 4.U(3.W) + 4.U(3.W) which does result in a truncated result (the + operator truncates by default) of 0. Please take a look at chipsalliance/chisel#1144 if you are interested in what's going on behind the scenes.

@RyanSangdeokPark
Copy link
Author

@Ryan-Sangdeok-Park Thanks for the catch, and thank you for your interest in Chisel! Looks like I was mistaken - try 4.U +& 4.U instead. It turns out that 4.U + 4.U is equivalent to 4.U(3.W) + 4.U(3.W) which does result in a truncated result (the + operator truncates by default) of 0. Please take a look at freechipsproject/chisel3#1144 if you are interested in what's going on behind the scenes.

I've check and compile result is what expected!
This is so interesting, and powerful language I think.
It seems so strict and many operators, but I believe it makes less error situation.

Thanks.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants