/// LSU EE 4755 - Digital Design Using HDLs // /// Introductory Review ////////////////////////////////////////////////////////////////////////////// /// This Note/Demo Set /// Prerequisite // // Some familiarity with Verilog. // Familiarity with digital design. /// Goal // // Refresh your memory of Verilog, Verilog simulation, and synthesis. // Exposure to some SystemVerilog features. // Different approaches to expressing a design: // machine synthesizability v. human readability. ////////////////////////////////////////////////////////////////////////////// /// References // /// Web page with references for this class: // https://www.ece.lsu.edu/v/ref.html /// :SV12: SystemVerilog -- IEEE Std 1800-2017 // https://ieeexplore.ieee.org/document/8299595/ // // The current Verilog language standard. // The primary Verilog reference for this course. /// :BV3: Brown & Vranesic, Fundamentals of Digital Logic with Verilog, 3rd Ed. // // The text used in LSU EE 2740. // Includes material on logic design and elementary Verilog. ////////////////////////////////////////////////////////////////////////////// /// Logical Right Shifter // /// Logical Right Shifter Informal Description // // This should be something everyone has seen before. // // There are two inputs, amt (amount) and din (data in) // There is one output: dout (data out) // The value at dout is set to the value at din right-shifted by amt bits. // Zeros are placed in vacated positions. // // Image:30em: ill-sh-empty.plain.svg // :Example: Behavior of right shift. // // Input - amt : 2 // Input - din : 00111000 <-- Shifted .. // Output- dout : 00001110 <-- .. by two bits. // // Input - amt : 1 // Input - din : 01101001 <-- Shifted .. // Output- dout : 00110100 <-- .. by one bit. // // Input - amt : 3 // Input - din : 01101001 <-- Shifted // Output- dout : 00001101 <-- .. by three bits. /// Terminology // // w - Number of bits in din and dout. /// Things to Review and Think About // // What should the hardware look like? // // How can we describe the shifter in Verilog? // // What is the relationship between the Verilog description of the // shifter and the hardware that is synthesized? /// How to Implement a Shifter in Hardware // // // Brute Force Method (Usually not a good idea) // // Use a multiplexor with w inputs, each input is w bits wide. // Cost is about 3w² before optimization. // Image:30em:ill-sh-mux16.plain.svg // With Sample Values // Image:30em:ill-sh-mux16-ex.plain.svg // // Efficient Method, The Logarithmic Shifter // // Use lg(w) multiplexors, each with two w-bit inputs. // Cost is about 6 w lg(w). ////////////////////////////////////////////////////////////////////////////// /// Logical Right Shifter Implementations // Appearing below are several different ways of writing a logical // right shift module in Verilog. All of them are correct but when // coding style is taken into account some are better than others. // // Coding style is important because the cost of designing a system // includes the time it takes engineers to read HDL descriptions // and to find bugs in the descriptions. // :Example: Simple Behavioral Shifter Description // // This description is good for an ordinary shifter. We are relying on // the synthesis program to do a good job with the logical right shift // operator, >>. // module shift_right_operator ( output uwire [15:0] shifted, input uwire [15:0] unshifted, input uwire [3:0] amt ); // Note: Reasonable code. We expect synthesis prog to DTRT here. // assign shifted = unshifted >> amt; endmodule // :Example: Unnecessarily Complicated Behavioral Shifter Description // // This description is correct but unnecessarily complicated and so // should not be used. It is also not synthesizable for reasons to be // covered later. (If you must know: it's because the number of // iterations in the loops depends upon a non-constant value, the // module amt input.) // module shift_right_behavioral ( output logic [15:0] shifted, input uwire [15:0] unshifted, input uwire [3:0] amt ); localparam int width = 16; always_comb begin // Correct, but more complicated than it needs to be. Also, // cannot be synthesized for reasons that we'll cover later. // for ( int i=0; i> amt; #1; // Check the output of each Module Under Test. // foreach ( name[ mut ] ) begin automatic logic [15:0] sout = mut == 0 ? sout1 : sout2; if ( shadow_sout !== sout ) begin err_count[mut]++; if ( err_count[mut] < 5 ) $display ("MUT %s wrong result for 0x%h >> %d: 0x%h != 0x%h (correct)\n", name[mut], sin, amt, sout, shadow_sout); end end end $display("Ran %d tests, %d, %d errors found.\n", test_count, err_count[0], err_count[1]); end endmodule // cadence translate_on // Local paths to Chipware code // // Simulation Model // /apps/linux/cadence/GENUS191/share/synth/lib/chipware/sim/verilog/CW/CW_shifter.v // // Synthesis Model // /apps/linux/cadence/GENUS191/share/synth/lib/chipware/syn/CW/CW_shifter.v