-
Notifications
You must be signed in to change notification settings - Fork 164
Make verilog indices consistent #3074
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
base: master
Are you sure you want to change the base?
Make verilog indices consistent #3074
Conversation
|
So the reason for this is that for this line:
imap0, imap1, ... which are labels you will use when creating timing/placement contstraints.
With this change, the generated label Before this change, for e.g. a 4-elem vector, the component that consume index 0 would get the |
fbf8e58 to
8ca68d5
Compare
|
I got this error on empty Vec for Not sure exactly how to interpret it but maybe this is caused by MaxIndex on the empty Vec (types are confusing though!)? Makes me suspicious I have also broken a bunch of other zero-sized things (which maybe aren't tested?) |
Yes ~MAXINDEX just didn't support all the cases that ~LEN does, fixed here: 5b00a73 |
Just to clarify this, it will generate |
|
@christiaanb @martijnbastiaan this is ready for review. It is passing all the tests, it would be good if you could give it a good looking at as I think there are a bunch of edge cases that are not tested (most notably zero-sized Vectors). |
| ~OUTPUTUSAGE[0] ~TYPEL[~TYPO] ~GENSYM[map_out][5]; | ||
| assign ~SYM[3] = ~SIZE[~TYP[2]]'d~MAXINDEX[~TYPO] - ~SYM[1][0+:~SIZE[~TYP[2]]] + ~ARG[2]; | ||
| assign ~SYM[3] = ~SYM[1][0+:~SIZE[~TYP[2]]] + ~ARG[2]; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@martijnbastiaan can you check my understanding here,
Is imap_go used when the imap has been partially unrolled, and ~ARG[2] is the offset for how much unrolling has been done.
I guess I am not going to get consistent indices in this case (and I'm kind of surprised this unrolling would happen, as imap is OPAQUE)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The compiler generates imap_go when you do things like:
case imap f xs of
Cons y ys -> ...There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It is implemented here:
clash-compiler/clash-ghc/src-ghc/Clash/GHC/Evaluator/Primitive.hs
Lines 4198 to 4215 in 12169a7
| $(namePat 'Clash.Sized.Vector.imap) -- :: forall n a b . KnownNat n => (Index n -> a -> b) -> Vec n a -> Vec n b | |
| | isSubj | |
| , nTy : aTy : bTy : _ <- tys | |
| , (tyArgs,tyView -> TyConApp vecTcNm _) <- splitFunForallTy ty | |
| , let (tyArgs',_) = splitFunForallTy (Either.rights tyArgs !! 1) | |
| , TyConApp indexTcNm _ <- tyView (Either.rights tyArgs' !! 0) | |
| , Right n <- runExcept (tyNatSize tcm nTy) | |
| , let iLit = mkIndexLit (Either.rights tyArgs' !! 0) nTy n 0 | |
| -> reduceWHNF $ | |
| mkApps (Prim (PrimInfo "Clash.Sized.Vector.imap_go" (vecImapGoTy vecTcNm indexTcNm) WorkNever SingleResult NoUnfolding)) | |
| [Right nTy | |
| ,Right nTy | |
| ,Right aTy | |
| ,Right bTy | |
| ,Left (valToTerm (args !! 1)) | |
| ,Left (valToTerm (args !! 2)) | |
| ,Left iLit | |
| ] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
But when you look at the evaluator rule of imap_go
clash-compiler/clash-ghc/src-ghc/Clash/GHC/Evaluator/Primitive.hs
Lines 4217 to 4223 in 12169a7
| "Clash.Sized.Vector.imap_go" | |
| | isSubj | |
| , nTy : mTy : aTy : bTy : _ <- tys | |
| , f : xs : (Suspend nArg) : _ <- args | |
| , DC dc vArgs <- xs | |
| , Right n' <- runExcept (tyNatSize tcm nTy) | |
| , Right m <- runExcept (tyNatSize tcm mTy) |
You see it is only evaluated when the vector argument is itself a Cons x xs data-constructor.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for the explanation.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I have just changed the block_name and generated comment to imap_go so it is clear if this path gets taken.
950dedd to
593809e
Compare
|
@christiaanb just to say I'm finished with this, so once the CI has finished I think it's ready to go in if you're happy with it. I have also done some full-design builds internally, and this passes all tests. |
|
@christiaanb / @martijnbastiaan looks like gitlab CI is stuck (or I don't know whether this needs kicking off manually?) |
martijnbastiaan
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you! I'll extend the changelog a little bit with an example to make it more clear what's happening. Other than that I think this is good to go.
Sadly I don't believe this can be back ported to 1.8, as it would break paths/constraints.
Not a problem - we already have this patched in and then we will just remove that when we get to the latest version. |
This makes the order of indices when using
imap, consistent between the Clash code and generated Verilog code. Currently the generated verilog code uses the reverse index.Still TODO: