Saturday, 2023-07-22

*** tpb <[email protected]> has joined #yosys00:00
*** lexano <[email protected]> has quit IRC (Ping timeout: 250 seconds)00:04
*** skipwich_ <skipwich_!~skipwich@user/skipwich> has quit IRC (Quit: DISCONNECT)03:01
*** skipwich <skipwich!~skipwich@user/skipwich> has joined #yosys03:03
*** peepsalot <peepsalot!~peepsalot@openscad/peepsalot> has quit IRC (Remote host closed the connection)03:03
*** peepsalot <peepsalot!~peepsalot@openscad/peepsalot> has joined #yosys03:04
*** citypw <citypw!~citypw@gateway/tor-sasl/citypw> has joined #yosys03:45
*** krispaul <[email protected]> has joined #yosys07:02
*** kristianpaul <kristianpaul!~paul@user/kristianpaul> has quit IRC (Ping timeout: 252 seconds)07:03
*** lexano <[email protected]> has joined #yosys16:28
*** napaalm <[email protected]> has joined #yosys16:30
napaalmHi, I have an issue with yosys synthesis, which results in a different behaviour than the input file:16:34
napaalmmodule test(clk, rst_n);16:34
napaalm    input clk, rst_n;16:34
napaalm    reg STAR;16:34
napaalm    localparam S0=0, S1=1;16:34
napaalm    always @(rst_n==0) STAR <= S0;16:34
napaalm    always @(posedge clk) if (rst_n==1)16:34
napaalm        casex(STAR)16:34
napaalm            S0: STAR <= S1;16:34
napaalm            S1: STAR <= S0;16:34
napaalm        endcase16:34
napaalmendmodule16:34
napaalmexecuting16:34
napaalm$  yosys -p "synth -auto-top; write_verilog synth.v" test.v16:34
napaalmresults in the following file:16:34
napaalm(* hdlname = "\\test" *)16:34
napaalm(* top =  1  *)16:34
napaalm(* src = "test.v:1.1-12.10" *)16:34
napaalmI see that my previous message is not so readable, so I uploaded the input and output files to pastebin16:38
napaalmInput file: https://pastebin.com/1ZzSkp7H16:38
napaalmCommand: yosys -p "synth -auto-top; write_verilog synth.v" test.v16:38
tpbTitle: test.v - Pastebin.com (at pastebin.com)16:38
napaalmOutput file: https://pastebin.com/6p1G2bQ616:38
napaalmThe yosys synthesis is wrong, because STAR is no longer a register and its value doesn't change on clock positive edges. Can anyone give me some info on why this happens? Thank you!16:38
tpbTitle: synth.v - Pastebin.com (at pastebin.com)16:38
corecodeis it okay to have two processes assign to the same register?16:39
corecodei wouldn't write it that way16:40
napaalmThat is how verilog RTL it's taught at my university. Could you please show me a better way to write it?16:41
corecodehm maybe always @(posedge clk, negedge rst_n) if (!rst_n) STAR <= 0 else STAR <= !STAR;16:43
corecodeif you write two processes, you have two drivers; one is a latch, the other a register16:44
corecodei think16:44
napaalmUnfortunatly I don't know what exactly is a process, in this context16:44
corecodeZipCPU might have an opinion16:45
corecodealways block16:45
napaalmOh I see16:46
corecodedo you write tests?16:47
napaalmYes, if I simulate my code with a simple testbench using iverilog, the behaviour is as expected16:47
napaalmI can show you16:47
corecodenot necessary16:48
corecodesimulators don't always exhibit the exact same behavior when the code is incorrect16:48
corecodedid you not get any message about two drivers for one signal?16:48
napaalmI did not16:49
corecodetry to set everything to maximum warns and lints16:50
corecodehttps://github.com/chipsalliance/verible16:50
corecodethis could help?16:51
napaalmiverilog with -Wall doesn't output any warning16:51
corecodemaybe ask in ##fpga16:52
corecodethis channel is pretty quiet16:52
napaalmOk, in case this code style is actually correct, isn't this a bug in yosys?16:53
napaalmThe linter you just linked my also doesn't show any warning: I just tried16:53
corecodehm16:56
corecodemaybe it is valid code because of the conditions?16:56
corecodeseems unlikely tho16:56
napaalmI don't know, my verilog knowledge is very limited, I'll try asking in the other channel, as you suggested. Thank you17:01
*** napaalm <[email protected]> has quit IRC (Quit: Client closed)17:02
*** napaalm <[email protected]> has joined #yosys17:02
*** napaalm47 <[email protected]> has joined #yosys17:03
*** napaalm47 is now known as YourNick17:03
*** YourNick <[email protected]> has left #yosys17:04
whitequarkcorecode: no, it is not okay to have two processes assign to the same register17:11
whitequarkoh, sorry, I missed a bit of context17:11
napaalmSo, is my code incorrect?17:13
whitequarkyes. there are at least two issues with it17:13
whitequarkfirst: you cannot use two processes to write to a register with yosys (or any other synthesizer I know)17:14
whitequarksecond: yosys does not support conditions like always @(rst_n==0)17:14
whitequarkI think the specific behavior is that it is treated like always @* in this case17:14
whitequarkbut it is an error (which is not diagnosed by yosys) to use a condition like that17:14
napaalmCould it be  an old syntax? Because here at my university we are taught this exact way to write RTL code17:16
napaalmIs the following code correct? https://pastebin.com/zm3cqcVU17:25
tpbTitle: test_corrected.v - Pastebin.com (at pastebin.com)17:25
*** citypw <citypw!~citypw@gateway/tor-sasl/citypw> has quit IRC (Ping timeout: 240 seconds)17:42
*** srk_ <srk_!~sorki@user/srk> has joined #yosys18:40
*** srk <srk!~sorki@user/srk> has quit IRC (Ping timeout: 246 seconds)18:43
*** srk_ is now known as srk18:43
ZipCPUnapaalm: Yes, your last pastebin will work.19:34
ZipCPUThe code you wrote initially is only legal in a simulation context.  Verilog was initially written as a simulation language, and so it can work in simulations.19:35
ZipCPUHowever, you can't map it to hardware.19:35
ZipCPUWhen it comes to mapping a design to hardware, you have to limit yourself to only the constructs that the hardware supports, and assigning the same register in two separate always blocks is ... well, that doesn't describe any hardware.19:35
ZipCPUIt only has meaning in a simulation.19:36
*** kraiskil <[email protected]> has joined #yosys19:36
ZipCPUIf that's the kind of logic taught you in your school, then either 1) you are taking a class in how to write Verilog simulations (check your syllabus), 2) you missed a key piece of context in the lesson, or 3) you instructor has been delinquent about telling you the difference.19:37
*** kraiskil <[email protected]> has quit IRC (Ping timeout: 245 seconds)20:25
napaalmThank you ZipCPU, now it all makes sense! During the class we never touch actual hardware, instead we write simulations with iverilog21:00
ZipCPUnapaalm: You aren't the first person with this type of question.21:01
ZipCPUIndeed, its a common beginners mistake.  I see this sort of thing all the time.21:01
napaalmI can imagine that21:02
ZipCPUIt's also why I limited my tutorial to *only* those parts of Verilog that could be synthesized.21:02
napaalmSpeaking of code that can't be synthesized, now I am trying to synthesize tri-state logic, but I can't get yosys to convert it to a form that can be synthesized to an fpga. I don't understand the exact purpose of the "tribuf" command, and it doesn't seem to make a difference in my code21:05
ZipCPUHeh.  Yeah, that's another one.21:06
ZipCPUThe trick is there's only a couple ways to do it, and a lot of ways to mess it up.21:06
ZipCPUProperly, you might write: assign out = (tristate) ? 1'bz : value;21:06
ZipCPUBut beware, you can *only* do that to output of the chip at the top level.21:07
ZipCPUThe other way to do it is to instantiate the FPGAs tri-state IO buffer.21:07
ZipCPUWhich buffer you instantiate, however, depends upon the FPGA you are using.21:07
napaalmOkay, so this applies only to top-level outputs, and what about internal logic?21:08
ZipCPUInternal tristate logic is only supported by some daring synthesis tools.21:08
napaalmMy FPGA is a Lattice ECP521:09
ZipCPUIt's not universally supported.21:09
ZipCPUSee, the thing is, there's _NO_SUCH_THING_ as internal tristates on an FPGA.  The hardware doesn't allow it.21:09
ZipCPUSome synthesis tools will attempt to approximate it via logic, but the hardware for it doesn't exist.21:09
ZipCPU(I don't mean to yell, but if I were an instructor I would've given a proverbial foot stomp at that, and ... I'm not sure how to write that in IRC text ...)21:10
napaalmOkay, I had found online this limitation of FPGAs, so the question is: can yosys do this kind of approximation?21:12
ZipCPUI haven't tried it.  I think some of the developers have said it could, but it wouldn't be a widely used or tested feature so ... your mileage might vary.21:13
ZipCPUIn my case, I'm always writing to the lowest common denominator, so if there's one synthesizer my customers might use that doesn't support a feature, I'm stuck without it.21:14
ZipCPUSometimes I think they bought commercial tool XYZ back in the early 2000's, and they couldn't afford to update the licenses ... so, the market I work with leaves me stuck w/o a lot of language features others really like.21:15
napaalmI see, it doesn't seem like an easy field to work in21:17
ZipCPUIt's not all that bad.  You just have to learn the few constructs that are universally supported.21:18
loftynapaalm: pretty much whenever you use tristate logic then Yosys will issue a warning about limited support for it.21:19
loftyBut, really, there's no real need for tristate logic internally?21:19
ZipCPUI agree with lofty.  There's no reason to use it internally.21:20
napaalmYeah, I am trying to synthesize an educational CPU we studied in class, which has an internal bus to connect to memory and IO space21:20
napaalmI would like to avoid manually reimplement that code without tri-state logic, that's all21:20
loftyI assume your mental model was tristate buffers to control read/write to a common set of wires21:20
ZipCPUTechnically, ASICs can support internal tristates.  That doesn't mean they're good ideas to use.  However, there was a past generation that used them more liberally.21:21
napaalmlofty: Yes, it's a common bus for all devices21:21
loftyEven if tristate buffers were supported in internal fabric, they were *very* slow21:22
ZipCPUTo use a tristate bus in an FPGA, you have to keep a copy of the bus for each potential source, together with the tristate enable for each source, and then you use a LUT (or two or three) per bit to determine the bus value.21:22
ZipCPUIt's often easier for a two-way bus to simply keep track of both directions independently, rather than those plus the logic necessary to merge them.21:23
loftynapaalm: instead what tends to happen is the CPU has separate read/write buses; all devices read from the CPU's write bus, and their write output is multiplexed based on a device's validity signal21:23
loftyZipCPU: Well, all ASICs use internal tristates due to the nature of a transistor, but that's being pedantic21:24
napaalmOkay, it makes sense. I thought that yosys could autonomously do this kind of transformation21:25
ZipCPUI was trying to describe how you'd build an internal tristate within an FPGA, but ... okay.21:25
napaalmDo you know what's the exact purpose of this? https://yosyshq.readthedocs.io/projects/yosys/en/latest/cmd/tribuf.html21:26
tpbTitle: tribuf - infer tri-state buffers (at yosyshq.readthedocs.io)21:26
loftyThat's pretty much for I/O buffer inference21:26
napaalmAnd what about the option "-logic"?21:27
ZipCPUNot sure.  Try it.21:28
lofty"convert tri-state buffers that do not drive output ports to non-tristate logic."21:28
loftyAKA, infer an input buffer rather than a tristate buffer if possible21:28
napaalmI did try (and it's already included in the synth_ecp5 command), but doesn't help in my case: at the end of the synthesis I get many warning about multiply driven ports21:29
ZipCPUWarning, schmorning.  If it's not an error, it did something21:29
ZipCPUUnlike software, warnings are quite plentify in hardware design21:30
ZipCPUFew tools will let you synthesize without generating them21:30
loftyYeah, uh, I would treat a multiple-driver warning seriously, unlike ZipCPU21:30
napaalmYeah, if I then proceed to place and route I get an actual error21:30
napaalmnextpnr-ecp5 --json computer.json --textcfg computer_out.config --85k --package CSFBGA285 --lpf orangecrab_r0.2.pcf --lpf-allow-unconstrained21:30
napaalmERROR: Net 'C.d7_d0[0]' is multiply driven by cell ports C.P.D7_D0_TRELLIS_FF_Q_7.Q and C.SdIO.Switch.RBR_TRELLIS_FF_Q.Q21:30
loftyBecause in the best possible case that's unimplementable21:30
ZipCPUlofty: ;)  Normally I'd treat it seriously too.21:30
loftyAnd in the worst case you have a bitstream that will produce magic smoke21:30
loftyThis is...less common these days though, because FPGAs don't have tristate buffers in them21:31
ZipCPUDo we need to explain to napaalm how these FPGAs run on smoke?21:31
ZipCPUThis stuff needs its smoke to run.  If you ever let the smoke out, it stops working.21:32
napaalmHahahah21:32
napaalmSo, it seems I don't have much choice but to implement two separate buses21:33
loftyCorrect21:33
napaalmThank you very much for your help ZipCPU and lofty !21:34
ZipCPU;)21:34
ZipCPUGood luck.21:34
napaalmThanks21:34
* ZipCPU goes back to working on his 10Gb Ethernet, trying to configure those GTX transceivers just right ...21:34
loftynapaalm: no worries21:34
* ZipCPU can't find a valid way to use Xilinx's 66B/64B gearboxes, grumbles and goes on to write his own ...21:37
whitequarkZipCPU: there are some old FPGAs that do have internal tristates21:57
whitequarkI'm not sure whether they exposed those, but architecturally some old Xilinx devices did have them21:57
ZipCPUSeriously?  Wow.  I have just learned something.  Do you remember which ones?21:57
whitequarkmwk would know for sure, but I think it was... xc2s, maybe?21:58
whitequarkI believe internal tristates were used to save die area on interconnect21:58
whitequarkand they stopped using those because doing timing driven routing where you have to consider that your capacitance changes depending on the pass transistors you enable isn't tractable21:59
whitequarkhttps://www.mouser.co.uk/datasheet/2/903/ds001-1595278.pdf#page=1222:00
whitequark"One third of the Hex lines are bidirectional, while the remaining ones are unidirectional."22:00
whitequark"12 Longlines are buffered, bidirectional wires that distribute signals across the device quickly and efficiently."22:01
* whitequark uploaded an image: (54KiB) < https://libera.ems.host/_matrix/media/v3/download/matrix.org/cLAVdqQpIXgAzuVBDeAmqvIm/Screenshot_20230722_220125.png >22:01
whitequarkthere's even a picture saying "3 state lines". so yep, that one has it22:01
whitequarkthose bidirectional buffers look like an absolute nightmare to me... it's amazing they got it to work reliably22:02
ZipCPUWow.  Cool.  That explains a lot though.22:03
ZipCPUIt also explains why there's logic around that uses these things, when they are (apparently no longer) synthesizable.22:03
whitequarkI don't have a way to check but it seems like you could use BUFT internally22:03
* whitequark uploaded an image: (57KiB) < https://libera.ems.host/_matrix/media/v3/download/matrix.org/ZSrATnjXvbLxhbFxdsByYqsr/Screenshot_20230722_220526.png >22:05
whitequarkyeah looks like you could22:05
whitequarkalso the name implies it's solely for internal routing (or it would be an OBUFT/IOBUFT)22:05
loftyThe Pilkington FPGA has internal tristate buffers too22:13
loftyBut I think they were intended for logic more than anything22:13
*** nonchip <[email protected]> has quit IRC (Quit: https://quassel-irc.org - Chat comfortably. Anywhere.)22:15
*** nonchip <[email protected]> has joined #yosys22:15
mwkwhitequark: xc3k, xc4k, xc5k, xcs, xc2s, xcv, xc2v and all variants thereof22:20
whitequarkwait, xc5k?22:20
mwkxc3k, xc4k, xc5k, xcs have real tristates IIRC; the ones on xcv, xc2s, xc2v are... kinda emulated in hardware, but in a fast way22:20
mwkxc520022:21
whitequarkhuh22:21
mwkan old family of cheap FPGAs22:21
whitequarkhow are they emulated?22:21
mwkxilinx actually described it in a patent22:21
mwkbasically... well, like you'd expect22:21
mwkit's a wired-and, except with a real and gate instead of the wired part22:22
mwkin short: every CLB has 4 horizontal tristate lines going through it; each horizontal tristate line is splittable into 4-CLB segments22:23
mwkand each CLB has two TBUFs (with T and I inputs), each of which has two tristate lines that it can drive22:24
mwkthere are programmable joiners which basically boil down to chaining the AND gate inputs in both directions or not22:24
mwkalso I very vaguely recall old lattice (maybe even AT&T era?) FPGAs having tristates too, but...22:27
mwkoh, and also22:31
mwkthe thing about timing and routing is22:31
mwkbefore xc2v, the interconnect in xilinx FPGAs wasn't fully *buffered*22:31
mwkso the timing analysis had to actually compute things like capacity of each unbuffered pass-transistor-joined segment of the network22:32

Generated by irclog2html.py 2.17.2 by Marius Gedminas - find it at https://mg.pov.lt/irclog2html/!