-
Notifications
You must be signed in to change notification settings - Fork 2
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
Implement srLatch and enable. #83
Comments
I'd like to propose to change the naming slightly: |
With the above name change, I think the following holds:
Here Furthermore, we expect that |
Some equational reasoning to follow up @jrbeaumont's comments on inverters: srLatch s r q nq
= never [rise s, rise r] <> bubbles [s, r] (meElement r s q nq)
= never [rise s, rise r] <> bubbles [s, r] (buffer r q <> buffer s nq <> mutex q nq)
= never [rise s, rise r] <> inverter r q <> inverter s nq <> mutex q nq |
I agree with the name changes, they are much clearer.
This is great, a nice implementation, and I like the reasoning in your last comment, this would be good to explain in the thesis. I also really quite like Incoming will be a PR with |
The challenge is to come up with a nice high-level specification for For
or alternatively, as you put it:
The following straightforward extension leads to a heavy implementation: srLatch s r q nq = never [rise s, rise r] <> complexGate (Var s) (Var r) q <> complexGate (Var r) (Var s) nq <> mutex q nq <> initialise1 [q] <> initialise0 [nq] I think the reason is that the above allows This could be achieved by adding constraints: |
I think this is a clear and quite general spec: srLatch s r q nq = never [rise s, rise r] -- disallow contradictory requests
<> initialise0 [q] <> initialise1 [nq] -- disallow initial state q=nq=0, also see below
<> rise s ~> rise q <> rise s ~> fall nq -- the set behaviour
<> rise r ~> fall q <> rise r ~> rise nq -- the reset behaviour
<> rise q ~> fall s <> fall nq ~> fall s -- disallow premature s-
<> rise nq ~> fall r <> fall q ~> fall r -- disallow premature r- There are a couple of subtleties:
|
This is clear, great! I would like to test it myself to double check, but I have no doubt it works correctly.
|
@snowleopard: Through testing, I find that the implementation for srLatch s r q nq = never [rise s, rise r] -- disallow contradictory requests
<> initialise1 [q] <> initialise0 [nq] -- disallow initial state q=nq=0, also see below
<> rise s ~> rise q <> rise s ~> fall nq -- the set behaviour
<> rise r ~> fall q <> rise r ~> rise nq -- the reset behaviour
<> rise q ~> fall s <> fall nq ~> fall s -- disallow premature s-
<> rise nq ~> fall r <> fall q ~> fall r -- disallow premature r- The synthesis of this produces AO22 gates. The image is attached. |
@jrbeaumont I believe this one is heavy because it allows concurrency between outputs. What if you add P.S.: By the way, note that I mixed up the initial state in my earlier comment (it was 10) -- I've edited it, so it's now 01. |
Aha, that's a good idea! I think we can adapt our implementation as follows: data InitialValue a = Undefined | Defined { getDefined :: Expr a } | Inconsistent
deriving (Eq, Show) Now one can set an initial value not only to But let's leave this for future work :) Initialising to 01 is fine for now. |
That's a very nice idea. But yes, for the future :) |
@jrbeaumont Strange! I've just tried the spec below -- it gives two NORs! module Concept where
import Tuura.Concept.STG
circuit s r q nq = never [rise s, rise r] -- disallow contradictory requests
<> initialise1 [q] <> initialise0 [nq] -- disallow initial state q=nq=0, also see below
<> rise s ~> rise q <> rise s ~> fall nq -- the set behaviour
<> rise r ~> fall q <> rise r ~> rise nq -- the reset behaviour
<> rise q ~> fall s <> fall nq ~> fall s -- disallow premature s-
<> rise nq ~> fall r <> fall q ~> fall r -- disallow premature r-
<> me q nq <> me s r
<> inputs [s, r] <> outputs [q, nq] <> initialise0 [s, r] |
Ahh I spotted the problem! |
Aha, indeed. That's interesting :) |
I am nearly done with adding this stuff, so expect a PR soon :) |
With how |
You could show how It also relies on Furthermore, |
I have not yet included anything on |
By the way, given that srLatch s r q nq = srHalfLatch s r q -- behaviour of output q
<> srHalfLatch r s nq -- behaviour of output nq
<> initialise0 [q] <> initialise1 [nq] -- disallow initial state q=nq=0
<> rise q ~> fall s <> fall nq ~> fall s -- disallow premature s-
<> rise nq ~> fall r <> fall q ~> fall r -- disallow premature r- I think this is a good alternative. Probably easier to understand the full latch as a composition of two halves, with some additional restrictions. |
@jrbeaumont Can you check that the above works? |
@snowleopard This works perfectly :) And is a lot nicer to explain. I will update this implementation in the PR. |
* Implemented enable transformation * Added srHalfLatch concept * Implemented `bubbles` to list multiple signals to be inverted * Implemented full srLatch as discussed in #83 * Added TODO and cleared up type signatures * Enable now applies to given signals, rather than all in the given concept * Enable now applies to one chosen signal. Added enables for multiple signals * Implemented sync transformation * srLatch has a nicer, clearer implementation now
I've merged the PR but there is scope for improving srHalfLatch s r q = never [rise s, rise q] -- disallow contradictory requests
<> complexGate (Var s) (Var r) -- the set/reset behaviour
<> rise q ~> fall s -- disallow premature s-
<> fall q ~> fall r -- disallow premature r- Now, with this modification, srLatch s r q nq = srHalfLatch s r q -- behaviour of output q
<> srHalfLatch r s nq -- behaviour of output nq
<> initialise0 [q] <> initialise1 [nq] -- disallow initial state q=nq=0 I think this is very neat, like Yin and Yang matching :-) P.S.: If we could move the input restrictions into |
This works great, and is very neat indeed :) I know what you mean, having restrictions in |
Good :-) I'm starting to think that maybe we should turn these input restrictions into verification properties that will have to be checked. Restricting input behaviour from within an SR latch is dubious: real gates don't do that. However, we still want to guarantee that |
Well, so far, the |
@jrbeaumont I think you were right all along with the definition of Let's come back to this definition: srHalfLatch s r = complexGate (Var s `And` Not (Var r)) (Var r `And` Not (Var s)) Note that previously we needed the Then srLatch s r q nq = srHalfLatch s r q <> srHalfLatch r s nq <> somethingTricky Here |
I agree that the |
Yes, but this is the responsibility of the environment. In poor environment the circuit indeed needs to be very tough :-) When the environment is nice and welcoming a lot of extra stuff can be removed from the implementation. |
P.S.: I think this is the case where we might want to synthesise the right set/reset functionality for our concepts from state machines. After a bit of brainstorming with @danilovesky I am now trying to formally specify the most permissive behaviour of |
Beleive it or not, I am doing a similar thing, and trying for Set/Reset functions to produce a correct working |
Awesome! Please share the results. I recommend starting with simpler |
Likewise, please share any results you find :) |
OK, I attached the most permissive state graph for The idea is that in states Unfortunately, without pink/may arcs we cannot have a fully permissive specification. |
@jrbeaumont You might want to mention this in the thesis, pointing out the limitation of the current approach. Note that STGs share the same limitation -- you can only represent 'must-fire' requirements. However, I think it is in principle not difficult to extend concepts to support two types of arcs, but I don't think you should do it now. Maybe after you finish the thesis -- if at that point you are still not fed up with concepts, of course :-) |
Ahh, this was where I was going, I am just less well-versed in "may" arcs, so I could not work it out. Thank you for explaining it. srHalfLatch s r = complexGate (Var s `And` Not (Var r)) (Var r `And` Not (Var s))
<>
srLatch s r q nq = srHalfLatch s r q <> srHalfLatch r s nq Then I will explain the implementation in the thesis, and state that ideally, we would not like to impose restrictions on the environment, but due to How does this sound? |
Also I noticed an issue with my latest changes to the code. New PR incoming! |
Yes, this sounds good. I think from the point of view of presenting the material in an interesting and insightful way, it may be better to stick to this: srHalfLatch s r q = never [rise s, rise q] -- disallow contradictory requests
<> complexGate (Var s) (Var r) -- the set/reset behaviour
<> rise q ~> fall s -- disallow premature s-
<> fall q ~> fall r -- disallow premature r-
srLatch s r q nq = srHalfLatch s r q -- behaviour of output q
<> srHalfLatch r s nq -- behaviour of output nq
<> initialise0 [q] <> initialise1 [nq] -- disallow initial state q=nq=0 I think this is a very nice example of compositional concept specification. It does have issues that you will discuss (forcing restrictions on the environment), but you will be able to rationalise this choice by explaining the requirement for 'may' arcs for the most permissive specification of |
OK sounds good to me :) |
Enable is another higher order transformation for concepts, which applies a given signal as an
enable
signal to the given concept,i.e. the function of the concept will not apply unless the
enable
signal is high (or low).srLatch
is a useful concept to include, and we have discussed some details of it in #82.There are some implementation details which need working out, such as it being based on an
meElement
.These will need explanation in the thesis too.
enable
can be explained in the details of how it is implemented, and how useful this can be.srLatch
es implementation details may be more complex to discuss, such as how it is based off anmeElement
and the transformations applied to it as a cause of this. As such, it would be best to explain this as an example in the Concept Transformation section of the thesis.First however, we need to establish the implementation of
enable
andsrLatch
/srLatch2
The text was updated successfully, but these errors were encountered: