ELEKTROTEHNI ˇ SKI VESTNIK 89(3): 124–132, 2022 ORIGINAL SCIENTIFIC PAPER Online Digital-Circuit Modeling with Data-Flow Visualisation and Area Estimation Andrej Trost 1 , Manfred Ley 2 , Andrej ˇ Zemva 1 1 University of Ljubljana, Faculty of Electrical Engineering, Trˇ zaˇ ska 25, 1000 Ljubljana, Slovenia 2 Carinthia University of Applied Sciences - Engineering IT, Villach, Austria † E-mail: andrej.trost@fe.uni-lj.si Abstract. Digital circuits are efficiently designed with abstract models in hardware description languages. Digital design which requires understanding the modeling language, design-flow and tools is considered difficult to the entry-level students. To boost learning, we propose a small hardware description language (SHDL) and an online tool for modeling, simulation and transformation to a standard language. The paper presents the SHDL structure and a novel tool for data-flow visualisation and circut area estimation. Early estimation of the synthesized circuit structure helps students at their taking circuit modeling design decisions. Keywords: digital circuit model, high-level language, data flow graph, circuit area estimation, online tool Spletno modeliranje digitalnih vezij s prikazom podatkovnega toka in oceno povrˇ sine Digitalna vezja uˇ cinkovito naˇ crtujemo z abstraktnimi modeli v strojno-opisnem jeziku. Proces zasnove vezja, ki zahteva poznavanje novega jezika, postopkov in orodij, je za ˇ studente niˇ zjih letnikov zelo zahteven. Pouˇ cevanje lahko izboljˇ samo s poenostavljenim modelirnim jezikom SHDL in spletnim orod- jem za opis, simulacijo ter pretvorbo modela v standardni jezik. V ˇ clanku predstavljamo zgradbo jezika SHDL in novo orodje za prikaz gradnikov podatkovnega toka in oceno povrˇ sine vezja. Ocena zgradbe sintetiziranega vezja pomaga ˇ studentom pri naˇ crtovalskih odloˇ citvah v modelu vezja. 1 INTRODUCTION Digital circuit modeling in a hardware description lan- guage (HDL) is one of the main tasks in the digital design process. Standard languages VHDL and Verilog are used in the circuit modeling of the front-end as well the as back-end logic synthesis tools. A VHDL model describing circuit components operating in paral- lel follows different semantic rules compared to a typical computer language [1], [2]. Designing digital circuits requires knowledge of logic and registers operation, HDL syntax and design tools. The languages were initially developed for simulation and only a language subset is used when describing synthesizable models. The standard language modeling methodology is considered difficult to unexperienced designers. Received 24 May 2022 Accepted 23 June 2022 The availability of computer aided tools is crucial for a widespread adoption of the HDL design methodol- ogy. The back-end synthesis tools are provided by pro- grammable device vendors, since they are tightly cou- pled with the technology implementation process. These tools provide also front-end modeling and simulation environment. For example, the Xilinx Vivado Design Suite [4] accepts a register-transfer level (RTL) HDL and higher-level circuit models, but their usage requires a substantial training. The designer learning VHDL first needs a free and simple-to-use circuit simulator. GHDL [4] is a command-line simulator which needs an additional software for viewing simulation waveforms. Researchers develop a lightweight design environment [5] and distributed online VHDL compiler and simulator [6]. The EDA Playground [7] provides an online tool for testing various digital development tools and languages. The tools require a VHDL design as well as a test-bench file for simulation. Digital circuit design on a higher-level of abstraction is aimed to boost the design efficiency, specifically for the development of hardware algorithm accelerators. High-level languages, such as Bluespec [8], Chisel [9], OpenCL [10] and synthesis tools [11], address these needs. A good understanding of the RTL circuit models is still required to effectively use high-level tools. The RTL languages and models provide the designer a full control of the hardware structure and enable an efficient gate-level technology optimization. Simplified hardware description languages and associ- ated tools have been proposed to help learning the HDL design methodology. A plain simple HDL with a web ONLINE DIGITAL-CIRCUIT MODELING WITH DATA-FLOW VISUALISATION AND AREA ESTIMATION 125 Figure 1. Online SHDL tool with an example SHDL model, dataflow graph and resource estimation summary. tool [12] introduces hardware modeling in the C-like syntax to help students with an unfamiliar HDL syntax and programming paradigm. A Finite State Machine modeling language and tools [13] enable fast prototyp- ing for a specific type of digital circuits. CompactHDL [14] introduces a simplified version of VHDL and Java tools for an automatic translation to VHDL. We present a Small Hardware Description Language (SHDL) and an associated online tool to be used in digital design education [15]. The tool includes a circuit simulator and outputs a nicely formatted VHDL code which enables the designer to learn and adopt a proper VHDL modeling practice. Recently, the tool was up- graded with a circuit area estimation from the high-level SHDL model [18]. The estimated circuit area calculation provides a quick feedback to the designer without using an external synthesis tool. Figure 1 depicts our online SHDL tool with a code editor, circuit graph and resource estimator. Chapter 2 describes the used high-level circuit de- scription language and its connection to the standard VHDL. Chapter 3 describes our SHDL model parsing and resource estimation methodology. Chapter 4 dis- cusses the use of SHDL in education and plans for our future work. 2 HIGH-LEVEL CIRCUIT DESCRIPTION Hardware description languages model digital circuits on structural, data-flow and behavioral abstraction levels. Structural models describe circuit schematics with signal declarations and component connections (instantiation). High-level HDL models define combinational logic with operators in concurrent assignment statements instead of logic components and gates. The statements order is not important, because the circuit structure is derived from the flow of the data signals between expression operators and assignments. Synthesis constraints are applied to the signal data type and operator support. Binary vectors representing signed or unsigned integers and basic operators are extensively supported, but real numbers should be avoided in a synthesizable model. Behavioral modeling in HDL is used to describe the circuit operation in terms of an algorithm. The basic language constructs for an algorithm specification are: assignments, conditional statements and loops. A process block with a sequence of statements is used in VHDL for a behavioral model. The process is executed in an infinite loop presenting an iterative circuit behav- ior, e.g. counters or finite-state machines. The models are synthesizable considering several restrictions: specific usage of loops and describing the synchronous logic. 2.1 Small Hardware Description Language Hardware description languages contain data types and structures to describe circuit models. Synthesizable models use only a subset of a standard hardware de- scription language. We propose to further simplify the modeling language to boost learning the HDL design [16]. Figure 2 presents the proposed SHDL structures and composition of a circuit model. Figure 2. SHDL constructs for building a digital circuit model. 126 TROST, LEY , ˇ ZEMV A A digital circuit model contains a set of signal declara- tions and a function specification block with a sequence of statements. The basic concepts of the structural, data-flow and behavioral models are described with the following three statement types: • instance – a component instantiation, • assignment – describes the combinational data-flow as well as synchronous data storage components, • conditional (if-else) statement for the algorithmic behavioral specification. The SHDL syntax is similar to the VHDL. The proposed language syntax rules can be expressed in the Backus-Naur Form (BNF): circuit :== [’entity’ name] {declaration} [’begin’] block [’end’] declaration :== name_list ’:’ [’in’ | ’out’] type name_list :== identifier {, identifier} block :== statement {[;] statement} statement :== assign | instance | if_statement assign :== identifier assign_op expression assign_op :== ’=’ | ’<=’ instance :== identifier ’(’ name_list ’)’ if_statement:== ’if’ (condition) ’then’ block {’elsif’ block} [’else’ block] ’end’ A circuit model contains an entity name, declaration of ports and internal signals, and statement blocks. The basic data types are an one-bit signal and multi-bit vector presenting a bus. The data values on the bus can be treated as signed or unsigned integers. Signals and constant literals are combined with the Boolean logic, vector shift and basic arithmetic operators in the SHDL assignment expressions. The expressions of the BNF syntax rules are recursively defined as: expression :== bool { or | xor | xnor bool} bool :== relation { and relation } relation :== shift {relation_operator} shift shift :== simpleExp {sll, srl literal} simpleExp :== term {+ |- | & term} term :== factor { * factor} factor :== primary |- primary |not primary primary :== name | literal | (expression) 2.2 SHDL circuit examples An example of an 8-bit adder model with a carry input in the proposed SHDL: e n t i t y add8 a , b : i n u8 c i : i n u1 s : out u9 begin s = a + b + c i end The SHDL basic data types are: u1 for one-bit signals, uN for N-bit unsigned and sN for N-bit signed vectors. The language keywords are similar to those of a standard VHDL, but the description is less verbose without libraries and architecture section. VHDL requires a perfect data-type match in assignments obtained by resizing and type conversion functions. A model of the same adder in VHDL: l i b r a r y IEEE ; use IEEE . std logic 1164 . a l l ; use IEEE . numeric std . a l l ; e n t i t y add8 i s port ( a , b : i n unsigned (7 downto 0 ) ; c i : i n s t d l o g i c ; s : out unsigned (8 downto 0) ) ; end add8 ; a r c h i t e c t u r e l o g i c of add8 i s begin s <= ( resize ( a , 9 ) + resize ( b , 9 ) ) + unsigned ’ ( ” ” & c i ) ; end l o g i c ; Our functional circuit model is composed of con- current assignment statements between keywords begin and end. SHDL supports similar basic arithmetic and logic operations on signals as VHDL: vector addition, subtraction, multiplication and Boolean operations. The hardware specific vector operations are concatenation (&) and slicing. Constant vector slicing describes a combinational truth table or decoder in case of a vector array. A 7-segment decoder example declares the rom array with ten 7-bit unsigned binary values (data type 10u7): e n t i t y decod bcd : i n u4 led : out u7 rom : 10u7= ” 0111111 ” , ” 0000110 ” , ” 1011011 ” , ” 1001111 ” , ” 1100110 ” , ” 1101101 ” , ” 1111101 ” , ” 0000111 ” , ” 1111111 ” , ” 1101111 ” ; begin led = rom ( bcd ) end If the vector is not constant, indexing with another vector describes the multiplexer. Example of a 16-to-1 multiplexer: e n t i t y mux d : i n u16 ; sel : i n u4 ; y : out u1 ; begin y = d ( sel ) end A two-input multiplexer is described with a condi- tional assignment (when-else) statement. The condition- ally selected expressions describe the data-flow logic with various combinational components. For example: y = a+b when b>0 else a−b ONLINE DIGITAL-CIRCUIT MODELING WITH DATA-FLOW VISUALISATION AND AREA ESTIMATION 127 describes the circuit with an adder, subtractor, compara- tor and two-input multiplexer (see Figure 3). Figure 3. Combinational data flow graph. The assignment operator <= describes in the SHDL sequential logic, where the assignments are executed at the rising edge of the system clock. The sequential circuit models are constrained to a synchronous logic with a single clock, which is sufficient for small educational components. An accumulator with reset and clock enable signals in the SHDL: i f reset then a <= 0 e l s i f en=1 then a <= a + d end The same circuit in VHDL requires a process with a rising clock condition. In SHDL, a signal condition is either a signal value (0 is false) or expressed with a logic relation (e.g. en=1). The constant values are specified as integer numbers as opposed to VHDL where a binary notation or integer conversion functions should be applied: process ( c l k ) begin i f rising edge ( c l k ) then i f reset = ’1 ’ then a <= to unsigned (0 , 8 ) ; e l s i f en = ’1 ’ then a <= a + d ; end i f ; end i f ; end process ; 3 PARSING AND RESOURCE ESTIMATION Our SHDL parser is implemented as an open-source tool for a web browser. The SHDL web page is designed in HTML5 for a responsive, user-friendly utilization and it uses a set of the JavaScript library files for the model parsing, simulation, conversion to VHDL and resource estimation. The web page is divided into three sections: SHDL editor with a parser log on the left side, model settings and outputs on the right side (see Figure 1) and interactive simulator at the bottom. 3.1 Editor and parser The editor is based on an open source project CodeMirror [19] which offers VHDL syntax coloring. The SHDL modeling structures are implemented in a library model.js with the JavaScript function closure objects: • NumConst: numeric constants, • Var and Slice: signal variables and bit slices, • Op: recursive binary expressions, • Statement: assignment statements, • IfStatemet: conditional statement blocks, • Instance: model instances and • Block: SHDL statements block. The objects define a set of methods used for accessing the internal data, visiting and analyzing the model, evaluating the circuit model for the simulation purpose and producing a standard HDL output. A library named vector.js is used for numeric calculations with up to 64- bit signed or unsigned values. A parsesim.js library is used to translate the SHDL code to the modeling structures. The input code is first processed by a lexical analyzer (lexer.js) producing basic language tokens. The parser reads the tokens and builds the circuit model according to the syntax rules. The parsing process stops in case of a rule violation and outputs an error log. During expression parsing for the assignment and conditional statements, a data type of every operation object is recursively calculated by the operator and operands data type. For every assignment statement in a code block, the assignment target variable name is stored in a list of targets to alert the user in case of multiple assignments to the same variable in a code block. 3.2 VHDL output and interactive simulation Figure 4 presents our SHDL model of a sequential circuit converted into the VHDL model. Entity section of the VHDL model contains a port signal declaration and inferred clock. The internal signals are declared in the architecture section. The signals which are an output of the sequential logic are initialized to zero unless there is a specific value assigned in SHDL. Sequential assigments in SHDL are transformed to a VHDL clocked process. Conditional statements with combinational assignments are converted into a combi- national process. A sequence of conditional statements where a signal is compared to a set of constants can be transformed to a case statement in VHDL. 128 TROST, LEY , ˇ ZEMV A Figure 4. Conversion from SHDL to VHDL. The online tool includes an interactive model simula- tor utilizing computation library vector.js and waveform display library wave.js. The simulator reads the input signal values set by the user and preforms a repeated model evaluation and waveform updating. The simula- tion setup is used to generate a VHDL test-bench for connection with external tools. A discrete event simulation is executed by visiting and evaluating the model in a sequence of delta simulation cycles. At each cycle, the simulator computes events for the assignment target signals and updates the signal values at the end of the cycle. The simulation result is displayed on the waveform presented in Figure 5. Figure 5. Interactive SHDL simulator. 3.3 Circuit area estimation A high-level SHDL model is decomposed into basic combinational and sequential digital circuit building blocks to evaluate the circuit in terms of the occupied silicon area. The actual circuit area is obtained after synthesis of the circuit model targeting the selected technology. The CMOS synthesis tools are expensive and not easily accessible to students learning the digital design, so an estimation of the circuit area is included in our online SHDL tool. The area estimation is based on characterisation of the sample circuit models in a selected CMOS technology. Digital building blocks described with the SHDL operators and modeling constructs are identified from the high-level model. The circuit area estimation process is described on an example of a pulse width modulator (PWM) circuit. The circuit has an 8-bit signed input data and one bit output pwm. PWM is composed of a counter and comparator. The 8-bit counter is described by signal c counting from 0 to 254. When the counter is reset, the input data is transformed to the unsigned by adding offset 128 and then saved to internal register d. The register is finally compared to internal counter c to obtain a one-bit pulse output: e n t i t y pwm8 data : i n s8 pwm: out u1 c , d : u8 begin i f c=254 then c <= 0; d <= data+128 else c <= c+1 end pwm = 1 when c