-
Notifications
You must be signed in to change notification settings - Fork 146
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
doc example for mkUniqueWrapper2 #694
Comments
The type
And the type
They aren't from a library. They are user-defined types that only exist within this example. These types add some realism to the example, by showing how the Does that answer your question? The
If you compile with with
However, if you change the variable
|
the type is not defined in example, the code I provided is from myself and not from the doc! |
Sorry, I think I understand now. The example from the doc has a few issues that need fixing:
or this, if it's more consistent with the style used by the guide:
Yes, these should be fixed in the document. Thank you for reporting this. Your version is good, except that the definition of |
I guess I would also changed the name to something other than If we did keep the interface, your definition for The example has two input FIFOs, but they could be one FIFO of And I think the
But I can't find any example of
And in that example, no input or output FIFOs were being used. I don't think it's important to follow the original example(s). We can just consider what it's helpful in an example now. Leaving out the interface and making it a standalone example might be best, and that way readers can compile it and explore the output. |
for users coming from verilog world it's useful to see inputs and outputs in produced verilog code. for establishing the connection between func world and real one. when I am not able to test out examples from "reference blah guide" I'd think that language sucks or not maintained well, and in any case not user friendly at all. |
btw, the latest example I did is having 2 fifos only import FIFO :: * ;
import FIFOF :: * ;
import StmtFSM :: * ;
import UniqueWrappers :: * ;
import Complex :: *;
typedef Int#(18) CFP;
typedef struct {
Complex#(CFP) a;
Complex#(CFP) b;
} CFP2 deriving (Eq, Bits);
interface ArithOpGP2#(type t);
method Action enqueue(Complex#(t) a, Complex#(t) b);
method ActionValue#(Maybe#(Complex#(t))) getResult();
endinterface
(* synthesize *)
module mkComplexMult1Fifo( ArithOpGP2#(CFP) ) ;
FIFO#(CFP2) infifo <- mkFIFO;
let arg = infifo.first ;
FIFOF#(Complex#(CFP)) outfifo <- mkFIFOF;
Reg#(CFP) rr <- mkReg(0);
Reg#(CFP) ii <- mkReg(0);
Reg#(CFP) ri <- mkReg(0);
Reg#(CFP) ir <- mkReg(0);
// Declare and instantiate an interface that takes 2 arguments, multiplies them
// and returns the result. It is a Wrapper2 because there are 2 arguments.
Wrapper2#(CFP,CFP, CFP) smult <- mkUniqueWrapper2( \* ) ;
// Define a sequence of actions
// Since smult is a UnqiueWrapper the method called is smult.func
Stmt multSeq =
seq
action
let mr <- smult.func( arg.a.rel, arg.b.rel ) ;
rr <= mr ;
endaction
action
let mr <- smult.func( arg.a.img, arg.b.img ) ;
ii <= mr ;
endaction
action
// Do the first add in this step
let mr <- smult.func( arg.a.img, arg.b.rel ) ;
ir <= mr ;
rr <= rr - ii ;
endaction
action
let mr <- smult.func( arg.a.rel, arg.b.img );
ri <= mr ;
// We are done with the inputs so deq the in fifos
infifo.deq ;
endaction
action
let ii2 = ri + ir ;
let res = Complex{ rel: rr , img: ii2 } ;
outfifo.enq( res ) ;
endaction
endseq;
// Now convert the sequence into a FSM ;
// Bluespec can assign the state variables, and pick up implict
// conditions of the actions
FSM multfsm <- mkFSM(multSeq);
rule startFSM;
multfsm.start;
endrule
method Action enqueue(Complex#(CFP) a, Complex#(CFP) b);
CFP2 ab;
ab.a=a;
ab.b=b;
infifo.enq(ab);
endmethod
method ActionValue#(Maybe#(Complex#(CFP))) getResult();
if (outfifo.notEmpty) begin
let res = outfifo.first;
outfifo.deq;
return tagged Valid res;
end else
return tagged Invalid;
endmethod
endmodule |
Thank you again for reporting this. I will make the change in the Library Guide. Also, I discussed this with @rsnikhil and he agrees that the Library Guide examples should be fully working examples, that can be compiled and run. He suggests that these examples should exist as files in this repo, and the Library Guide should just point to the example files. He mentions that there is already a collection of examples which we use as the starting point: the examples accompanying the book BSV By Example. Nikhil suggests that every section of the Library Guide should point to an example there and, if no suitable example exists yet, an example file should be added. The BSV By Example book is available for download from a different repo at the moment (here), so Nikhil will take on the task of putting the document source and examples into this repo. Then we can look at updating the Library Guide to point to examples there. |
Hi,
tried to follow the example in "Bluespec Compiler (BSC) Libraries Reference Guide"
from page 218, and can't find
ArithOpGP2#(CFP)
anywhere.Could you please suggest if below snippet is correct(checked in bsc compiler and to me it's ok)?
Or may be suggest proper snippet as per example and interface.
thanks
The text was updated successfully, but these errors were encountered: