-
Notifications
You must be signed in to change notification settings - Fork 3
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
Allow specifying constraints on encoding fields/operands #96
Comments
Any proposals on some syntax? One option I can think of would be to add constraints to an instruction definition like:
In relation to #94 this would be more universal but would create more effort on the generation of e.g. decoders from the grammar. |
@eyck I had something like this in mind. However here are some thoughts about the approach. We still would need to add this line for every single instruction. It would be great to specify this only once for a complete InstructionSet to make use of inheritance. This on the other hand would add more complexity and we would need to define how the constraints should be merged (combine or overwrite). Since we do not have something like Should we limit the constraints to encoding fields only or also allow static architectural state variables? This would add an alternative way to deal with different/optional implementations for XLEN=32/64 without the need to define two separate Instruction sets:
|
this could possibly be handled quite elegantly with #69, the operands section could also support constraints. |
@wysiwyng Could you elaborate on that? The @PhilippvK The main issue I see with pulling common constraints out of the individual instructions is that the operands in question would not be declared in the same lexical scope. That feels very unintuitive to me and also poses a bunch of non-trivial implementation issues. An identifier in this constraint block would suddenly no longer be referencing a single declaration, but refer to all operands with the same name declared in multiple instructions, which wouldn't even necessarily have the same type. I'm not a user of CoreDSL, so I might be misjudging things here, but it feels to me like most of these issues could easily be solved by pulling out the common checks to a function, without the need for any new language features. And as a final note: In case you decide on the separate section syntax, I'd suggest changing the keyword to |
@AtomCrafty from a language perspective I agree that the name based mapping comes with consistency issues. But your function proposal comes also with overhead since you need at least 3 versions of the rfs_check function. Moreover we mix in here exception behavior by using the raise() function to indicate that the instruction is illegal. For these things constraints are much more appropriate. I had this morning some discussions with @wysiwyng and we came up with an idea as follows:
|
@eyck I like your solution. The way you wrote it above, this would introduce three new keywords and a completely new syntax construct with the double curly braces. I think we can largely re-use existing syntax the users are already familiar with.
The implementor can of course still choose to format it in a way that keeps declarations and related constraints close together.
|
I totally agree that this approach is probably not a good idea. I like @eyck’s proposal (plus your comments) a lot as I am also a fan of #69 and I think this would be a great addition to the CoreDSL syntax. But we would need to define what happens if such Operands+Constraints are defined on different hierarchy levels. Would the complete |
@PhilippvK From a language design point of view my approach would be to conceptually concatenate the blocks, so that all constraints defined on any level in the hierarchy must hold. As an implementor of the more abstract instruction set I should be able to rely on the constraints I defined myself. An instruction set B deriving from A should not be able to break assumptions made in A (a similar notion to the Liskov substitution principle). Then again, I'm not familiar with the subject matter, so please let me know if there are valid use cases for breaking these assumptions. |
Currently, constraints on operands/fields in the encoding are evaluated in the behavior block by explicitly raising an Illegal Instruction. It would be great if we could find a way to define those conditions somewhere else.
Examples:
rd & rd+1
whererd%2==0
and (optionally )non-overlapping constraints between source and dest registers)SUNPKD810,SUNPKD820,SUNPKD830,SUNPKD831,SUNPKD832
in a single instruction block (see Add Mnemonic field to CoreDSL Syntax #80)The text was updated successfully, but these errors were encountered: