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
add smtlib2_comb_expr #3319
add smtlib2_comb_expr #3319
Conversation
As I mentioned on IRC before, while I do think this feature is quite useful, I'm not convinced that this is the right approach to implement it in yosys. Having had a closer look now, I still think that adding a new builtin cell type is not required here. I've opened a draft PR (#3342) that shows the approach I would use instead. |
hmm, that could work, though I'd have to refactor the 8kloc of code I already wrote: also, I'm not sure having the model be in the form of an implicit assumption is the best idea...what happens if we write something that's accidentally never true? having it instead just be a cell that computes a bool which we explicitly assert/assume using yosys's existing techniques allows smtbmc to give us the exact conditions under which the assumption fails. |
In that case the presat check would still fail, but this does leave the case where you accidentally exclude only some possible inputs. I agree that it's much better to use explicit assumptions to place restrictions on the considered inputs. Note that in the example I've only used smt2 to assert the otherwise unconstrained outputs to be equal to an expression of the inputs, which does not have this problem and is what you end up on the smt2 output side anyway. Moving the part that constrains the outputs from the user written smt2 to the smt2 generated by write_smt2 for such a blackbox (so you cannot accidentally assume anything not following this pattern) would be possible and should be done. This is completely separate, however, from the issue I have with adding a new builtin cell instead of using blackbox modules and the points regarding this, that I brought up in #3342.
I don't understand what you're saying here, as my PR is a working prototype that does not require any changes to smtbmc. If you mean allowing explicit named assumptions that restrict the considered inputs (which is not how I intended it to be used) it could be handled using the existing documented interface of representing assumptions in smt2 (in |
Hmm, I think the blackbox idea might be better, though I think the attribute value should just be the expression that gets assigned to the output. this would practically require that the module only has one output, unless we want to parse the attribute string. something like: (* smtlib2_output_expr = "((_ int2bv 10)\n(to_int (* 3.1415926535 (bv2int a))))" *)
(* blackbox *)
module mul_by_pi(out, a);
input [9:0] a;
output [9:0] out;
endmodule
I meant that if you have complex assertions embedded in the hierarchy instead of in explicit smtbmc assertions, then when they fail because the user messed up, then the assertions are hard to debug because smtbmc doesn't expect the hierarchy assumptions to fail, so doesn't have code to help with debugging that, unlike normal assumptions. |
Yeah I do want the user to specify just an expression for each output. Indeed that would need either some limited parsing or multiple attributes or something similar. I haven't found the time to explore the design space here, that's why I went with the "let the user specify the raw constraint" approach for my draft PR, so I could show the differences I wanted to focus on to quickly have something more concrete to discuss those. I would want something here that can a) allow defining internal variables using
Ah, that wasn't what I intended. |
I had an idea: why don't we put the smtlib2 expression attribute on the output wires rather than on the module?
imho that should be left for a future extension. it could be something like defining wires with a special attribute on those wires with the smtlib2 expression. we'd need to correctly handle dependencies between expressions, preferably without needing to parse them (maybe declaration order? idk if yosys preserves that all that well).
imho we just add the new functionality by using different attribute names when we need something other than just plain combinatorial assignment. backward compatibility should be relatively easy that way. |
the PR I'm working on for nmigen constructs a dependency tree and groups expressions into nested Example output:
|
I like that, it's simple and it's also clear that even should we extend the overall feature, we would not want to put anything besides the output defining expression in such an attribute, so no risk of wanting backwards incompatible changes later on :)
Yeah, my "That doesn't have to be part of a first merged version" was referring to the whole paragraph.
In general, you can easily end up with For this, though, I have no remaining concerns with your solution of using attributes on the outputs. |
f2cb1aa
to
cd57c5a
Compare
I switched the implementation to use attributes on the outputs and an attribute on the module. example: yosys/tests/various/smtlib2_module.v Lines 1 to 10 in cd57c5a
I also added a test that compares the generated smt2 to the expected output, avoiding the need to run a smtlib2 solver (which iirc yosys doesn't want a dependency on) |
I have no idea why it's broken on macos, the build log doesn't contain any useful information (that would be in the .log file that yosys's testing framework hides), and I don't have a macos computer to test on. Help would be appreciated. |
The error is in
(I've had trouble with |
Ah, thanks! Turns out macos's sed has issues with |
Thanks! if you're interested, Libre-SOC can figure out how to pay you eur 500 for your work...also, if you're interested in helping out more there is currently around eur 5-6000 available. |
adds a
smtlib2_comb_expr
attribute that allows you to pass a smtlib2 expression through to the output ofwrite_smtlib2
. This is useful to allow using smtlib2 types other than bool/bitvector, such as real numbers or floating-point.Corresponding PR for nmigen:
https://gitlab.com/nmigen/nmigen/-/merge_requests/7
https://bugs.libre-soc.org/show_bug.cgi?id=835