Next Article in Journal
AHAC: Advanced Network-Hiding Access Control Framework
Previous Article in Journal
Investigation of Red Clay Internal Stress Anisotropy and Influence Factors
Previous Article in Special Issue
Design and Optimization of a Petri Net-Based Concurrent Control System toward a Reduction in the Resources in a Field-Programmable Gate Array
 
 
Font Type:
Arial Georgia Verdana
Font Size:
Aa Aa Aa
Line Spacing:
Column Width:
Background:
Article

Optimized Sequential State Encoding Methods for Finite-State Machines in Field-Programmable Gate Array Implementations

Faculty of Computer Science, Bialystok University of Technology, Wiejska 45A, 15-351 Bialystok, Poland
*
Author to whom correspondence should be addressed.
Appl. Sci. 2024, 14(13), 5594; https://doi.org/10.3390/app14135594
Submission received: 6 June 2024 / Revised: 19 June 2024 / Accepted: 24 June 2024 / Published: 27 June 2024
(This article belongs to the Special Issue Current Updates of Programmable Logic Devices and Synthesis Methods)

Abstract

:
A Finite-State Machine (FSM) model is frequently employed to represent the behavior of sequential circuits. In the optimal design of these circuits, it is crucial to enhance FSM characteristics such as area (implementation cost), performance (operating frequency), and power consumption. This paper proposes sequential state encoding methods that aim to reduce the area and enhance the performance of FSMs. The methods involve sequentially selecting FSM states for encoding and determining the most appropriate code for each selected state. Several state and code selection modes are introduced, allowing for consideration of the relationships between states, the number of incoming and outgoing transitions, and the number of input variables initiating transitions to each state. The code selection process takes into account the architectural features of the electronic device in which the FSM is implemented, while some code selection modes are introduced to optimize both the area and performance of the FSM. The experimental results demonstrate that the proposed approach yields, on average, a reduction in the FSM area by 19.7% (in some instances, up to twofold reduction), along with an average performance increase of 21.2% (in certain cases, up to 69.3%), compared to the Sequential mode of the Quartus system.

1. Introduction

Finite-State Machines (FSMs) are fundamental components in digital systems, extensively used in control applications, communication protocols, and various other areas requiring predictable and structured behavior. The efficiency of an FSM significantly impacts the overall performance and resource utilization of digital systems, particularly when implemented in hardware platforms such as Field-Programmable Gate Arrays (FPGAs), Complex Programmable Logic Devices (CPLDs), and Application-Specific Integrated Circuits (ASICs).
Given the ubiquity of control devices in digital systems, FSMs are pivotal in digital hardware design. Many digital systems and devices are distinctly defined by their control logic, making the synthesis of FSMs a critical concern in every new project.
State encoding is a crucial step in FSM design, influencing the resulting implementation’s area and performance. Traditional methods for state encoding often do not fully exploit the potential optimizations available through modern hardware platforms, leaving room for improvement. The need for more advanced encoding techniques that consider the architectural nuances of contemporary electronic components is evident. The state encoding task involves addressing a complex logical combinatorial problem classified as NP-hard.
The complexity and significance of FSM state encoding have been a focal point for scientists and engineers since the inception of FSM theory. This subject garnered particular attention in the late 1980s, leading to the proposal of several methods such as two-level [1] and multi-level synthesis [2] of FSMs, directly addressing FSM state encoding. Two-level synthesis methods target the implementation of FSMs in devices equipped with two programmable matrix structures, notably CPLDs. Conversely, multi-level synthesis methods are tailored for implementing FSMs in FPGAs utilizing look-up tables (LUTs).
Given that the FSM state encoding problem is NP-hard, exact solutions are only feasible for small or specific FSMs, such as counters. As a result, numerous algorithms have been developed to address this challenge, typically categorized as heuristic (deterministic) or genetic (evolutionary) algorithms. Heuristic algorithms aim to identify local minima or maxima within a specific FSM parameter in a reasonably practical timeframe. While heuristic algorithms often produce solutions that closely approach the optimal, there are instances where their outcomes significantly diverge from the optimal result. The main drawback of heuristic algorithms stems from their tendency to become trapped in local minima or maxima.
The conventional method for addressing NP-hard tasks involves employing genetic (evolutionary) algorithms. Genetic algorithms offer the advantage of escaping local minima, thereby broadening the search space for solutions. Nonetheless, genetic algorithms are computationally intensive, require lengthy execution times, and do not consistently yield optimal solutions. Consequently, in practical applications, genetic algorithms are primarily employed to encode the states for critical FSM parameters, as the success of extensive and intricate projects hinges on the optimization of these parameters.
The challenge lies in the fact that achieving an optimal solution for the state encoding task does not ensure an optimal solution for the FSM synthesis task. This is because FSM synthesis methods employed in design tools encompass various other tasks besides state encoding. These tasks include mapping the design logic to the physical structure of electronic devices (such as FPGA, CPLD, or ASIC), meeting the time constraints of the design, and more. While state encoding primarily impacts the realization of the transition functions of FSMs, synthesis methods may integrate the implementation of both transition functions and output functions. Such integration often necessitates the use of an entirely different state encoding method.
A review of algorithms and methods for FSM state encoding is provided in [3]. Here, we focus on publications from the past few decades.
In [4], the cuckoo search optimization method is compared with the binary particle swarm optimization algorithm, the genetic algorithm, and the deterministic algorithms NOVA [5] and JEDI [6]. In [7], traditional Boolean algebra and Reed–Muller logic are proposed for minimizing the FSM area. In [8], the evolutionary algorithm called GP-ES is discussed, demonstrating good results in the design of small- and medium-sized FSMs. In [9], probabilities for each pair of code substitutions are proposed. In [10], the multi-population evolution strategy, denoted as MPES, is introduced, utilizing inner-ES and outer-ES evolution to address the problem.
In [11], a method is proposed to minimize the area of Moore FSMs by representing state codes as concatenations of codes from pseudo-equivalent state classes and collections of output functions. A similar approach for state encoding in Mealy FSMs is suggested in [12].
In [13], state encoding utilizes the values of output variables, while in [14], the input variables of FSMs are used for this purpose. In [15], multiplexers are added to the FSM circuit to use the values of output variables as state codes. In [16], anti-race state encoding is proposed for designing robust FSMs.
Several works focus on FSM state encoding for protection against unwanted attacks. In [17], a secure state encoding method for FSMs is presented to protect against power analysis attacks. In [18], a state encoding method to defend against Laser Fault Injection (LFI) attacks is introduced. In [19], a CAD tool for state encoding of FSMs robust to multiple LFI models is presented. In [20], differential power analysis (DPA) and fault injection attacks (FIAs) on FSMs are considered.
Numerous studies are dedicated to FSM state encoding for power consumption reduction. A comprehensive review of these methods is provided in [21]. In [22], a sequential algorithm, and in [23], an iterative algorithm for FSM state encoding are proposed to minimize dynamic power consumption. In [24], varying the length of state codes is suggested for the same purpose. Additionally, the authors of [25] present a state encoding method aimed at minimizing power consumption using binary particle swarm optimization and flip-flop selection.
Several studies focus on designing fault-tolerant FSMs. In [26], a heuristic algorithm for state encoding is proposed to mitigate the effects of transient faults. In [27], a method for FSM state encoding using stochastic numbers is introduced.
However, despite the extensive research on FSM state encoding, there is a lack of studies focused on methods tailored for modern electronic devices such as CPLDs, FPGAs, and ASICs.
This paper introduces a heuristic approach for FSM state encoding that sequentially selects states and assigns the most appropriate codes based on a combination of state selection and code selection modes. Our method aims to optimize both the area and performance of FSM implementations by leveraging the internal relationships between states and the specific architectural characteristics of the target hardware.
We propose several state selection modes (P, C, P_C, max_C, and max_X) to account for the intricate interconnections between FSM states. Additionally, we introduce code selection modes (FPGA, CPLD, diff_w, and max_w) that align with the architectural features and optimization goals of various hardware platforms. By combining these modes, we construct a diverse set of sequential state encoding methods tailored to different optimization objectives. The proposed approach is intended for practical use in FSM implementations not only in FPGAs but also in CPLDs and ASICs.
The proposed state encoding methods differ from existing methods in several key ways:
  • They consider the internal relationships between FSM states, including both already encoded and not yet encoded states;
  • They account for the number of input variables influencing the transitions to each state;
  • They consider the architectural features of the electronic device in which the FSM is implemented.

2. Materials and Methods

2.1. Sequential Methods for FSM State Encoding

The core principle of the sequential state encoding methods involves selecting FSM states in a specific order and assigning a unique code to each state. We put forward the following hypotheses to guide our research.
Hypothesis 1.
The outcome of FSM state encoding is influenced by the sequence in which codes are allocated to the states.
Hypothesis 2.
States that are most interconnected with already encoded states should be encoded first.
Let S = {s0, …, sM1} represent the set of FSM states, and K = {k0, …, kQ−1} represent the set of all available codes, where M is the number of FSM states and Q is the number of available codes, with s0 being the FSM’s start state. Let Q = 2 R , where R = l o g 2 M , and let ⌈A⌉ denote the smallest integer greater than or equal to A.
Sequential FSM state encoding can be represented by the following algorithm.
Algorithm 1 begins by assigning the zero code k0 to the initial state s0 and updates the sets of states (S) and codes (K) by removing s0 and k0, respectively. The main encoding process is carried out in a while loop, which continues until all states have been encoded. Within the loop, the next state si is selected from S according to a specified state selection mode. Then, using Algorithm 2, the appropriate code kj is assigned to si. After assigning the code, both si and kj are removed from their respective sets.
Algorithm 1. State encoding procedure.
 1.
Assign s0 <= k0 (zero code k0 to the start state s0);
 2.
Update S := S \ { s0 }, K := K \ {k0}.
 3.
While (S ≠ Ø) do
 4.
  Select the state si from S according to the specified state selection mode.
 5.
  Select the code kj from K to assign to si using Algorithm 2.
 6.
  Assign si <= kj, (code kj to state si).
  Update S := S \ { si }, K := K \ {kj}.
 7.
end while.
Algorithm 2. Code selection procedure.
 1.
Set min_cost := 100,000.
 2.
For (each kt in K) do
 3.
  Perform a trial assignment of kt to si:si <= kt.
 4.
  Compute cost(kt) for the FSM area resulting from assigning kt to si.
 5.
  if (cost(kt) < min_cost) then min_cost := cost(kt); kj := kt; end if.
 6.
  Unassign kt from si:si => kt.
 7.
end for.
 8.
return (kj).
The key steps in Algorithm 1 are selecting the state si for encoding (step 3) and finding the code kj that is optimal for assignment to the state si (step 4). When choosing kj, it is crucial to calculate the increase in FSM area resulting from this assignment.

2.2. State Selection for Encoding

Let A(si) be the set of states where transitions from si end, B(si) be the set of states with transitions ending in si, and t(si,sj) be the transition from the state si to the state sj (si, sjS). The set of transitions P(si) from the state si is defined by:
P s i = t s i , s j   |   s j A s i .
The set C(si) of transitions to the state si is defined by:
C s i = t s j , s i   |   s j B s i .
Let ES be the set of already encoded states. Then, the set of transitions PES(si) from si to states in ES is:
P E S s i = t s i , s j   |   s j E S ,
and the set of transitions CES(si) from states in ES to si is:
C E S s i = t s i , s j   |   s j E S .
Let X(sj,si) be the set of FSM input variables that initiate the transition t(sj,si). Then, the set X(si) of input variables influencing transitions to the state is defined as the union of all such input variables across all states sj that transition to si. Formally, this can be expressed as:
X s i = s j B s i X s j , s i .
We introduce the following modes, which determine the strategy for selecting the next state si for encoding:
  • max_P: select the state si with the maximum number of outgoing transitions P s i   (Figure 1a);
  • max_C: select the state si with the maximum number of incoming transitions C s i (Figure 1b);
  • P: select the state si from which the maximum number of transitions P E S s i lead to already encoded states (Figure 1c);
  • C: select the state si in which the maximum number of transitions C E S s i originate from already encoded states (Figure 1d);
  • P_C: select the state si with the maximum number of connections to already encoded states P E S s i + C E S s i (Figure 1e);
  • max_X: select the state si whose transitions are influenced by the highest number of input variables X s i (Figure 1f).
The modes P, C, and P_C take into account the relationship of the selected state si with the already encoded states, whereas the modes max_C, max_P, and max_X are independent of the order in which states are encoded. This distinction allows for flexible encoding strategies that can adapt to different optimization goals.

2.3. Code Selection for Encoding

Algorithm 2 is responsible for selecting the most suitable code kj for a given state si. The algorithm starts by initializing the minimum cost to a very high value. It then iterates through each code kt in the set K. For each code, a trial assignment is made to si and the resulting cost in terms of FSM area is computed. If the computed cost is lower than the current minimum cost, the minimum cost is updated, and kj is set to kt. After evaluating all codes, the algorithm returns the code kj that resulted in the lowest cost.
In Algorithm 2, step 4 is crucial as it calculates the FSM area when kt is assigned to si. It has been experimentally found that FSM state encoding primarily affects the area of transition functions, not output functions. Therefore, in step 4 of Algorithm 2, the area is calculated only for FSM transition functions.

2.4. Calculating FSM Area

Step 4 of Algorithm 2 suggests different area calculation modes for transition functions: CPLD, FPGA, ASIC, diff_w, and max_w. For example, in LUT-based FPGAs, the area of a transition function dr is calculated as:
C F P G A ( d r ) =                               1 ,   w h e n   q n q n n 1 + 1 ,   w h e n   q > n     ,
where q is the rank (number of arguments) of dr, and n is the number of LUT inputs.
When implemented in CPLDs, the area CCPLD(dr) of the transition function dr is equal to the number of product terms in the Sum-of-Products (SOP) representation of dr:
C C P L D d r = H d r ,
where H(dr) is the number of product terms in the SOP of the function dr.
When the FSM is implemented in an ASIC, the area CASIC(dr) of the function dr is determined by the number of literals in the SOP of dr:
C A S I C d r = i = 1 H d r X i d r + R i + H d r ,
where Xi(dr) is the number of input variables in the i-th product term in the SOP of the function dr, and Ri is the number of feedback variables in the i-th product term.
The total area of the FSM implemented in an FPGA is defined as:
C F S M = r = 1 R C F P G A d r .
It is important to note that the actual area occupied by a function is influenced by various factors such as the techniques and algorithms employed in the design tool. These include methods for logical synthesis, the optimization of both logical and physical synthesis, mapping the design logic to the physical structure of the electronic component, and ensuring compliance with time constraints during the design process. Consequently, the area estimated using Equations (6) to (9) may frequently diverge from the actual area occupied by the implemented FSM.

2.5. Other Code Selection Modes

Two additional modes are proposed apart from the considered area estimators tailored to the implementation of FSMs on specific types of electronic components: diff_w and max_w. In the diff_w mode, the objective is to minimize the difference in weights, W(dr), of transition functions (Figure 2a), while in the max_w mode, the aim is to minimize the maximum weight, W(dr), of transition functions (Figure 2b). Here, the weight, W(dr), of each function dr corresponds to the number of product terms in the SOP representation of that function. The diff_w mode aims to balance the cost of realizing all transition functions, thereby reducing the disparity between the most complex and simplest functions. On the other hand, the max_w mode seeks to minimize the area occupied by the most complex function, thereby enhancing FSM performance.
The following hypotheses are suggested for further investigation and validation, aiming to provide insights into the effectiveness and applicability of the proposed methods.
Hypothesis 3.
The diff_w mode contributes to minimizing the area of FSM.
Hypothesis 4.
The max_w mode contributes to enhancing FSM performance.

2.6. Constructing Sequential State Encoding Methods

Drawing upon Algorithms 1 and 2, along with the array of state selection modes (totaling 6) and code selection modes (totaling 5), a total of 30 (6 × 5) distinct methods for sequential FSM state encoding can be devised (Figure 3).
The state selection modes (P, C, P_C, max_C, max_P, and max_X) enable the consideration of intricate relationships among FSM states. Meanwhile, the code selection modes (FPGA, CPLD, and ASIC) incorporate the architectural features of electronic devices, as well as optimization objectives such as area (mode diff_w) or performance (mode max_w) minimization.
The methods resulting from this combination will be labeled using a single term, connecting the state selection mode and the area calculation mode with an underscore. For instance, in the P_FPGA method, state selection for encoding follows the P mode, while the cost of transition function implementation adheres to the FPGA mode.

3. Results

A study of sequential techniques for encoding FSM states was conducted using benchmarks from the Microelectronics Center of North Carolina (MCNC) [28], with FSM implementation on the Cyclone 10 LP FPGA family utilizing the Quartus design tool version 23.1. Initial experimental investigations revealed that methods constructed using the max_P mode did not yield satisfactory solutions; hence, they will not be further explored.
The MCNC benchmarks are described in the KISS2 format [22,28], a standardized textual representation that is easily parsed by software tools. This format offers a clear and concise way to represent FSMs, consisting of a header section and detailed transition descriptions. The header section provides essential information about the FSM, including the number of inputs, outputs, states, and transitions. Following the header, the KISS2 format outlines the state transitions in a structured manner. Each transition is described on a new line, specifying the input combination, current state, next state, and output combination. Table 1 presents the basic parameters of the FSM test examples sourced from the MCNC benchmark dataset which were utilized in our research.
This research involved the development a specialized application called sequential_state_encoding, which is part of the ZUBR university package for digital device design [29]. This application was engineered to encode the FSM states based on various state and code selection modes. The application accepts an FSM description as input in the form of a text file in the KISS2 format, allowing users to select from different state and code selection modes tailored to specific optimization goals and hardware architectures.
The state encoding process within the application involves several selection modes, which determine the order in which states are encoded:
  • In max_P mode, the state with the highest number of outgoing transitions is selected;
  • In max_C mode, the state with the highest number of incoming transitions is selected;
  • In P mode, the state from which the maximum number of transitions leading to already encoded states is chosen;
  • In C mode, the state with the maximum number of transitions starting from already encoded states is selected;
  • In P_C mode, the state with the maximum number of links to already encoded states is chosen;
  • In max_X mode, the state affected by the highest number of input variables in its transitions is selected.
Additionally, the code selection modes were designed to optimize the FSM for different hardware architectures (FPGA, CPLD, or ASIC) where the FSM is implemented. This is reflected in the computation of the area of the FSM transition functions:
  • In FPGA mode, the area is computed using Equation (9);
  • In CPLD mode, the area is determined using Equation (7);
  • In ASIC mode, the area is calculated using Equation (8).
Furthermore, the max_w code selection mode aims to minimize the maximum weight of the transition functions, whereas the diff_w mode seeks to minimize the disparity between the maximum and minimum weights of these functions. Consequently, while the max_w mode focuses on enhancing the performance of the FSM, the diff_w mode strives to optimize both the performance and the area of the FSM.
For each FSM benchmark, the application sequentially selected states and assigned appropriate codes based on the chosen modes, generating various encoding configurations. The application produces a KISS2 file containing state encoding, which is then processed using a ZUBR package converter. This converter translates the state-encoded KISS2 file into an FSM description in a selected Hardware Description Language (HDL). The ZUBR package converters facilitate the conversion of KISS2 files into Verilog, SystemVerilog, or VHDL, and allow for the selection of different FSM description styles [21]. In Appendix A, we include a sample Verilog description of the FSM for the shiftreg test example, generated using the P_C_max_w state encoding mode.
The FSM synthesis is continued using Quartus software version 23.1, which utilizes the Verilog description generated previously. This Verilog file is then synthesized using Quartus with the User Encoded mode selected to ensure that the state encoding adheres to the specified Verilog code. During the synthesis process, Quartus Prime compiles the Verilog code, optimizes the logic, and maps it onto the FPGA architecture. The software generates detailed reports covering various aspects of the synthesized design, including area utilization and performance metrics. The area utilization report indicates the number of logic elements, registers, and other FPGA resources used by the FSM implementation, providing insights into resource efficiency. The timing analysis report includes the maximum operating frequency of the synthesized FSM, highlighting the performance capabilities of the design.
This research involved comparing the synthesis results obtained using the custom state encoding application with those achieved using the built-in Sequential encoding mode offered by Quartus. The comparison focused on key parameters, highlighting the differences in area and performance, demonstrating the effectiveness of the proposed methods in optimizing FSM implementations.
The experimental results are summarized in Table 1 and Table 2. Both tables include columns corresponding to different encoding modes, determined by combinations of SS_mode, which refers to the state selection mode (P, C, P_C, max_C, or max_X), and CS_mode, indicating the code selection mode (FPGA, CPLD, diff_w, max_w). The results in both tables summarize the following rows: Best, which denotes the number of best solutions; Unique, which counts the number of unique best solutions not achieved by other encoding methods; Avg, representing the mean value of the parameter; and Max, the maximum value of the parameter.
Table 1 is dedicated to evaluating area efficiency. It includes metrics such as Ls, which represents the area value (number of FPGA logic elements) for Quartus Sequential mode encoding, and Lmin, the minimum area value for the given example. The ratio Ls/Lmin indicates the area efficiency compared to the Sequential mode. Table 2 focuses on performance metrics. The specific columns in Table 2 are Fs, which represents the performance value (maximum operating frequency in megahertz) using the Sequential mode of Quartus, and Fmax, the maximum performance value for the example. The ratio Fmax/Fs indicates the performance improvement compared to the Sequential mode.
The Sequential mode is the state encoding method provided by Quartus. In this mode, the FSM states are sequentially encoded using binary codes of minimum length. This mode serves as a baseline for comparing the results obtained by the proposed state encoding methods. It should be noted that the max_P_FPGA method yielded unsatisfactory results and has therefore been omitted from the experimental findings.
For the FSM examples considered, the results were identical for the CPLD and ASIC modes. Therefore, Table 1 and Table 2 solely showcase the outcomes for the FPGA and CPLD modes. Furthermore, the state selection mode max_X was exclusively explored in conjunction with the FPGA code selection mode.

4. Discussion

The results of the study indicate the effectiveness of the proposed sequential state encoding methods in optimizing FSM implementations. Through a systematic evaluation of each state and code selection mode across various FSM benchmarks, the research demonstrated that tailored encoding strategies could lead to notable improvements. Comparing the synthesis results with those obtained using Quartus’s built-in Sequential encoding mode, this study highlighted the benefits of the new encoding methods.
An analysis of Table 1 and Table 2 reveals that, compared to the Sequential mode, the proposed FSM state encoding methods significantly improve both area and performance. In Table 1 and Table 2, the columns provide detailed insights into the metrics used for evaluation. Specifically, the column Ls represents the area value, measured as the number of FPGA logic elements used when applying Quartus’s Sequential mode encoding. The column Fs indicates the performance value, measured as the maximum operating frequency in megahertz (MHz), achieved with the Sequential mode of Quartus. Meanwhile, Lmin denotes the minimum area value, representing the lowest number of logic elements used among all tested methods for a given FSM example, while Fmax signifies the maximum performance value, representing the highest operating frequency achieved among all tested methods.
The ratios Ls/Lmin and Fmax/Fs are crucial for assessing the efficiency of the proposed methods. These ratios compare the outcomes of the proposed FSM state encoding methods against the Sequential mode of Quartus. A higher Ls/Lmin ratio suggests a greater reduction in area utilization, highlighting the effectiveness of the proposed encoding methods in minimizing FPGA resources. Similarly, a higher Fmax/Fs ratio indicates an improvement in performance, showcasing how the proposed methods enhance the maximum achievable operating frequency compared to the Sequential mode.
On average, these methods reduce the area by 19.7%, and in some cases, such as the shiftreg example, the reduction can be as much as twofold. Additionally, the performance of FSMs is enhanced by an average of 21.2%, with certain examples like pma experiencing performance increases of up to 69.3%.
In Table 1 and Table 2, the best solutions are highlighted in bold. It is important to note that the best solution can be achieved using multiple encoding methods. For some methods, the best solution is unique in comparison to other methods, meaning it cannot be obtained using alternative encoding methods.
Figure 4 presents graphs depicting the state selection modes based on the number of best and unique solutions in terms of both area and performance. These graphs illustrate the effectiveness of different state selection modes in achieving optimal results.
As shown in Figure 4a, the P_C mode is the most effective state selection mode in terms of area, with the max_C mode following closely. In contrast, Figure 4b indicates that the max_C mode excels in performance, with P_C as the second-best option. Therefore, the optimal solutions for both area and performance are most likely to be found using the P_C and max_C modes.
Figure 5 presents graphs illustrating the effectiveness of various code selection modes based on the number of best and unique solutions in terms of area and performance.
Figure 5a indicates that the FPGA mode is the most effective code selection mode for minimizing area, followed by the CPLD mode. However, Figure 5b shows that the FPGA mode is the least effective for optimizing performance. As expected, the max_w mode excels in performance optimization, with the CPLD mode being the second-best, similarly to its performance in area optimization.
Therefore, to optimize area, the FPGA and CPLD code selection modes are recommended; for optimizing performance, the max_w and CPLD modes should be used. When both area and performance need optimization, the CPLD mode is the best choice.
Figure 6 illustrates the number of best and unique solutions in terms of FSM area achieved by the sequential encoding methods developed.
As shown in Figure 6, the methods are ranked in the following order in terms of area efficiency:
P_C_FPGA;
max_C_diff_w;
C_FPGA;
P_C_max_w;
max_C_FPGA;
max_X_FPGA;
P_FPGA;
max_C_CPLD;
C_max_w;
C_CPLD;
max_C_max_w.
The ranking was determined by the number of Best results each method achieved in terms of area efficiency. Methods were ranked according to how often they produced the most optimal area outcomes. When multiple methods had the same number of Best results, the Unique value was used to differentiate them. This ranking effectively highlights the methods that are most successful in minimizing FPGA resource utilization, providing valuable insights into the best techniques for area optimization.
Notably, among the best area methods, the state selection modes P_C and max_C are prominent, but the C, max_X, and P modes also appear. Similarly, besides the FPGA and CPLD modes for code selection, the diff_w and max_w modes are also present.
Therefore, to identify the best area solutions, it is advisable to consider not only the recommended P_C, max_C, FPGA, and CPLD modes but also the state selection modes C, max_X, and P, along with the code selection modes diff_w and max_w.
Figure 7 illustrates the number of best and unique solutions in terms of FSM performance achieved by the developed sequential encoding methods.
Based on Figure 7, the methods are ranked in terms of performance efficiency as follows:
P_C_max;
max_C_diff_w;
max_C_max_w;
C_CPLD;
P_max_w;
P_C_CPLD;
max_C_CPLD;
P_CPLD;
P_diff_w;
C_max_w;
P_C_diff_w;
max_C_FPGA;
C_FPGA;
P_C_FPGA;
max_X_FPGA.
The performance ranking was established by counting how often each method achieved the Best results in terms of maximum operating frequency. Methods were ranked according to the number of top performance results they produced. In cases where methods had the same number of Best results, the Unique value was used to determine the ranking. This ranking highlights which methods are most effective in maximizing the FSM’s operating frequency, thus offering useful guidance for performance optimization.
It is important to note that among the top-performing methods, in terms of performance, the state selection modes P_C and max_C are not the only ones present. The C, P, and max_X modes are also found to be among the best. Similarly, for code selection modes, besides max_w and CPLD, the diff_w and FPGA modes also appear frequently.
Therefore, to achieve the best performance, one should consider not only the recommended P_C, max_C, max_w, and CPLD modes but also the C, P, and max_X state selection modes along with the diff_w and FPGA code selection modes.
Although the diff_w mode is not consistently among the top code selection modes for either area or performance, it is frequently found in state encoding methods that yield the best solutions.

5. Conclusions

This paper presented a heuristic approach for encoding states of FSMs by sequentially selecting states for encoding and assigning the most appropriate codes. The approach introduces several state selection modes (P, C, P_C, max_C, and max_X) and code selection modes (FPGA, CPLD, diff_w, and max_w). The state selection modes account for the internal relationships between the FSM states and input variables, while the code selection modes consider the architectural features of the electronic component (FPGA, CPLD, or ASIC) in which the FSM is implemented. Various sequential FSM state encoding methods were developed by combining state and code selection modes. The efficacy of these methods was evaluated using MCNC benchmarks with FSM implementations on FPGA.
This study put forward the following hypotheses: (1) the results of FSM state encoding depend on the order in which the codes are assigned to the states; (2) FSM states that are most linked to already encoded states should be encoded first; (3) the mode diff_w contributes to minimizing the implementation cost of FSMs; and (4) the mode max_w contributes to increasing the performance of FSMs. Hypotheses 1 and 4 are fully supported by the findings. Hypothesis 2 is only partially substantiated, as the mode max_C, which considers states not linked with already encoded states, also provides satisfactory outcomes. Although Hypothesis 3 is not entirely confirmed, it is worth noting that the diff_w mode frequently appears in state coding methods that deliver optimal solutions.
The experimental results demonstrated that the proposed FSM state encoding methods reduced the area by an average of 19.7%, with some examples showing a twofold reduction. Performance improvements averaged 21.2%, with some cases showing a 69.3% increase.
Future research in FSM state encoding will emphasize the development of parallel and iterative algorithms, alongside exploration into varying the number of bits in state codes. Additionally, there is potential in investigating the integration of output function realization with state encoding, marking a promising direction for further study.

Author Contributions

Conceptualization, V.S.; methodology, V.S.; software, V.S.; validation, V.S. and W.B.; formal analysis, V.S. and W.B.; investigation, V.S. and W.B.; writing—original draft preparation, V.S. and W.B.; writing—review and editing, V.S. and W.B.; visualization, V.S. and W.B. All authors have read and agreed to the published version of the manuscript.

Funding

The APC was supported by the Bialystok University of Technology grant number W/WI-IIT/1/2024 financed from a subsidy provided by the Ministry of Science and Higher Education of Poland.

Institutional Review Board Statement

Not applicable.

Informed Consent Statement

Not applicable.

Data Availability Statement

The data supporting the findings of this study are derived from FSM benchmarks provided by the Microelectronics Center of North Carolina (MCNC). These benchmarks are openly accessible, with references and links included within the article.

Conflicts of Interest

The authors declare no conflicts of interest.

Appendix A

This appendix presents an example of a Verilog description for the shiftreg test case, generated by the robust_0 converter from the ZUBR package. This example utilizes FSM state encoding with the P_C_max_w method.
module shiftreg_P_C_max_w_V_robust_0 (
   input clk, reset,
   input [0:0] x,
   output reg [0:0] y);
   reg[2:0] state, next;
   localparam [2:0]
   st0 = 3′b000,
   st1 = 3′b100,
   st2 = 3′b001,
   st3 = 3′b101,
   st4 = 3′b010,
   st5 = 3′b110,
   st6 = 3′b011,
   st7 = 3′b111;
   always @(posedge clk, negedge reset)
   if (~reset) state <= st0;
   else    state <= next;
   always @(*)
   case(state)
   st0:    casex(x)
            1′b0:  next = st0;
            1′b1:  next = st4;
            default: next = st0;
          endcase
   st1:    casex(x)
            1′b0:  next = st0;
            1′b1:  next = st4;
            default: next = st1;
          endcase
   st2:    casex(x)
            1′b0:  next = st1;
            1′b1:  next = st5;
            default: next = st2;
          endcase
   st3:    casex(x)
            1′b0:  next = st1;
            1′b1:  next = st5;
            default: next = st3;
          endcase
   st4:    casex(x)
            1′b0:  next = st2;
            1′b1:  next = st6;
            default: next = st4;
          endcase
   st5:    casex(x)
            1′b0:  next = st2;
            1′b1:  next = st6;
            default: next = st5;
          endcase
   st6:    casex(x)
            1′b0:  next = st3;
            1′b1:  next = st7;
            default: next = st6;
          endcase
   st7:    casex(x)
            1′b0:  next = st3;
            1′b1:  next = st7;
            default: next = st7;
          endcase
   default: next = st0;
   endcase
   always @(*)
   case(state)
    st0:    y= 1′b0;
    st1:    y= 1′b1;
    st2:    y= 1′b0;
    st3:    y= 1′b1;
    st4:    y= 1′b0;
    st5:    y= 1′b1;
    st6:    y= 1′b0;
    st7:    y= 1′b1;
    default: y = 1′b0;
   endcase
endmodule

References

  1. De Micheli, G.; Brayton, R.K.; Sangiovanni-Vincentelli, A. Optimal state assignment for finite state machines. IEEE Trans. Comput. Aided Des. Integr. Circuits Syst. 1985, 4, 269–285. [Google Scholar] [CrossRef]
  2. Devadas, S.; Ma, H.K.; Newton, A.R.; Sangiovanni-Vincentelli, A. MUSTANG: State assignment of finite state machines targeting multilevel logic implementations. IEEE Trans. Comput. Aided Des. Integr. Circuits Syst. 1988, 7, 1290–1300. [Google Scholar] [CrossRef]
  3. Salauyou, V.; Klimowicz, A. Synteza Logiczna Układów Cyfrowych w Strukturach Programowalnych; Wydawnictwo Politechniki Białostockiej: Bialystok, Poland, 2010. [Google Scholar]
  4. El-Maleh, A.H.; Sait, S.M.; Bala, A. State assignment for area minimization of sequential circuits based on cuckoo search optimization. Comput. Electr. Eng. 2015, 44, 13–23. [Google Scholar] [CrossRef]
  5. Villa, T.; Sangiovanni-Vincentelli, A. NOVA: State assignment of finite state machines for optimal two-level logic implementations. In Proceedings of the 26th ACM/IEEE Design Automation Conference, Nevada, LA, USA, 25–28 June 1989; Association for Computing Machinery: New York, NY, USA, 1990; pp. 327–332. [Google Scholar] [CrossRef]
  6. Lin, B.; Newton, A.R. Synthesis of multiple level logic from symbolic high-level description languages. In Proceedings of the IFIP International Conference on VLSI, Munich, Germany, 16–18 August 1989; North-Holland: New York, NY, USA, 1989; pp. 187–196. [Google Scholar]
  7. Lin, W.; Wang, L.; Xia, Y. FSM dual logic synthesis targeting area optimization. In Proceedings of the 2015 IEEE 16th International Conference on Communication Technology (ICCT), Hangzhou, China, 18–20 October 2015; IEEE: New York, NY, USA, 2015; pp. 821–826. [Google Scholar]
  8. Tao, Y.; Zhang, Q.; Zhang, L.; Zhang, Y. A systematic EHW approach to the evolutionary design of sequential circuits. Soft Comput. 2016, 20, 5025–5038. [Google Scholar] [CrossRef]
  9. El-Maleh, A.H. A probabilistic pairwise swap search state assignment algorithm for sequential circuit optimization. Integr. VLSI 2017, 56, 32–43. [Google Scholar] [CrossRef]
  10. Tao, Y.; Zhang, L.; Wang, Q.; Chen, R.; Zhang, Y. A multi-population evolution strategy and its application in low area/power FSM synthesis. Nat. Comput. 2019, 18, 139–161. [Google Scholar] [CrossRef]
  11. Mielcarek, K.; Barkalov, A.; Titarenko, L. Designing Moore FSM with unstandard representation of state codes. In Proceedings of the 2016 5th International Conference on Modern Circuits and Systems Technologies (MOCAST), Thessaloniki, Greece, 12–14 May 2016; IEEE: New York, NY, USA, 2016; pp. 1–4. [Google Scholar]
  12. Barkalov, A.A.; Titarenko, L.; Mielcarek, K. Reducing LUT Count for Mealy FSMs with Transformation of States. IEEE Trans. Comput. Aided Des. Integr. Circuits Syst. 2021, 41, 1400–1411. [Google Scholar] [CrossRef]
  13. Solov’ev, V.V. Minimization of mealy finite-state machines by using the values of the output variables for state assignment. J. Comput. Syst. Sci. Intern. 2017, 56, 96–104. [Google Scholar] [CrossRef]
  14. Salauyou, V.; Ostapczuk, M. State assignment of finite-state machines by using the values of input variables. In Proceedings of the 16th IFIP International Conference on Computer Information Systems and Industrial Management (CISIM), Bialystok, Poland, 16–18 June 2017; Springer: Cham, Switzerland, 2017; pp. 592–603. [Google Scholar] [CrossRef]
  15. Senhadji-Navarro, R.; Garcia-Vargas, I. Mapping Outputs and States Encoding Bits to Outputs Using Multiplexers in Finite State Machine Implementations. Electronics 2023, 12, 502. [Google Scholar] [CrossRef]
  16. Bychko, V.; Yershov, R.; Gulyi, Y.; Zhydko, M. Automation of anti-race state encoding of asynchronous FSM for robust systems. In Proceedings of the 2020 IEEE International Conference on Problems of Infocommunications. Science and Technology (PIC S&T), Kharkiv, Ukraine, 6–9 October 2020; IEEE: New York, NY, USA, 2020; pp. 501–506. [Google Scholar] [CrossRef]
  17. Agrawal, R.; Vemuri, R. On state encoding against power analysis attacks for finite state controllers. In Proceedings of the 2018 IEEE International Symposium on Hardware Oriented Security and Trust (HOST), Washington, DC, USA, 30 April–4 May 2018; IEEE: New York, NY, USA, 2018; pp. 181–186. [Google Scholar] [CrossRef]
  18. Jayasena, A.; Rani, K.; Mishra, P. Efficient Finite State Machine Encoding for Defending Against Laser Fault Injection Attacks. In Proceedings of the 2022 IEEE 40th International Conference on Computer Design (ICCD), Lake Tahoe, CA, USA, 23–26 October 2022; IEEE: New York, NY, USA, 2022; pp. 247–254. [Google Scholar] [CrossRef]
  19. Choudhury, M.; Gao, M.; Tajik, S.; Forte, D. TAMED: Transitional Approaches for LFI Resilient State Machine Encoding. In Proceedings of the 2022 IEEE International Test Conference (ITC), Anaheim, CA, USA, 23–30 September 2022; IEEE: New York, NY, USA, 2022; pp. 46–55. [Google Scholar]
  20. Konganapalle, G.; Shukla, S.; Singh, V. SMASh: A State Encoding Methodology Against Attacks on Finite State Machines. In Proceedings of the 2023 IEEE 32nd Asian Test Symposium (ATS), Beijing, China, 14–17 October 2023; IEEE: New York, NY, USA, 2023; pp. 1–6. [Google Scholar] [CrossRef]
  21. Salauyou, V.; Grzes, T. FSM state assignment methods for low-power design. In Proceedings of the 6th International Conference on Computer Information Systems and Industrial Management Applications (CISIM’07), Elk, Poland, 28–30 June 2007; IEEE: New York, NY, USA, 2007; pp. 345–350. [Google Scholar] [CrossRef]
  22. Grzes, T.N.; Solov’ev, V.V. Sequential algorithm for low-power encoding internal states of finite state machines. J. Comput. Syst. Sci. Intern. 2014, 53, 92–99. [Google Scholar] [CrossRef]
  23. Solov’ev, V.V.; Grzes, T.N. An iteration algorithm of encoding internal states of finite-state machines for minimizing the power consumption. Russ. Microelectron. 2013, 42, 189–195. [Google Scholar] [CrossRef]
  24. Solov’ev, V.V. Changes in the length of internal state codes with the aim at minimizing the power consumption of finite-state machines. J. Commun. Technol. Electron. 2012, 57, 642–648. [Google Scholar] [CrossRef]
  25. Khatua, K. Low Power State Assignment of Sequential Circuits based on Binary Particle Swarm Optimization and Flip-Flop Selection. In Proceedings of the 2022 International Conference on Electrical, Computer and Energy Technologies (ICECET), Sydney, Australia, 25–27 July 2022; IEEE: New York, NY, USA, 2022; pp. 1–6. [Google Scholar] [CrossRef]
  26. Ichihara, H.; Fukuda, M.; Iwagaki, T.; Inoue, T. State assignment for fault tolerant stochastic computing with linear finite state machines. In Proceedings of the 2017 International Test Conference in Asia (ITC-Asia), Taipei, Taiwan, 13–15 September 2017; IEEE: New York, NY, USA, 2017; pp. 156–161. [Google Scholar] [CrossRef]
  27. Ichihara, H.; Maeda, Y.; Iwagaki, T.; Inoue, T. State encoding with stochastic numbers for transient fault tolerant linear finite state machines. In Proceedings of the 2019 IEEE International Symposium on Defect and Fault Tolerance in VLSI and Nanotechnology Systems (DFT), Noordwijk, The Netherlands, 2–4 October 2019; IEEE: New York, NY, USA, 2019; pp. 1–6. [Google Scholar] [CrossRef]
  28. Yang, S. Logic Synthesis and Optimization Benchmarks User Guide. Version 3.0; Microelectronics Center of North Carolina (MCNC): Research Triangle Park, NC, USA, 1991; Available online: https://citeseerx.ist.psu.edu/document?repid=rep1&type=pdf&doi=4a86519e41bb8dbaa8d2c9ba434030f48de85ce7 (accessed on 1 June 2024).
  29. Salauyou, V.; Klimowicz, A.; Grzes, T.; Bulatowa, I.; Dimitrova-Grekow, T. Synthesis methods of finite state machines implemented in package ZUBR. In Proceedings of the 6th International Conference Computer-Aided Design of Discrete Devices (CAD DD’7), Minsk, Belarus, 14–15 November 2007; National Academy of Sciences of Belarus: Minsk, Belarus, 2007; pp. 53–56. [Google Scholar]
Figure 1. Selecting the state si for encoding: (a) in the max_P mode; (b) in the max_C mode; (c) in the P mode; (d) in the C mode; (e) in the P_C mode; and (f) in the max_X mode.
Figure 1. Selecting the state si for encoding: (a) in the max_P mode; (b) in the max_C mode; (c) in the P mode; (d) in the C mode; (e) in the P_C mode; and (f) in the max_X mode.
Applsci 14 05594 g001
Figure 2. The code selection modes (a) diff_w and (b) max_w.
Figure 2. The code selection modes (a) diff_w and (b) max_w.
Applsci 14 05594 g002
Figure 3. Constructing sequential state encoding methods.
Figure 3. Constructing sequential state encoding methods.
Applsci 14 05594 g003
Figure 4. The number of best and unique solutions for the state selection modes (a) in terms of area, and (b) in terms of performance.
Figure 4. The number of best and unique solutions for the state selection modes (a) in terms of area, and (b) in terms of performance.
Applsci 14 05594 g004
Figure 5. The number of best and unique solutions for the code selection modes (a) in terms of area, and (b) in terms of performance.
Figure 5. The number of best and unique solutions for the code selection modes (a) in terms of area, and (b) in terms of performance.
Applsci 14 05594 g005
Figure 6. Number of best and unique solutions in terms of the FSM area achieved by sequential state encoding methods.
Figure 6. Number of best and unique solutions in terms of the FSM area achieved by sequential state encoding methods.
Applsci 14 05594 g006
Figure 7. Number of best and unique solutions in terms of the FSM performance achieved by sequential state encoding methods.
Figure 7. Number of best and unique solutions in terms of the FSM performance achieved by sequential state encoding methods.
Applsci 14 05594 g007
Table 1. FSM area using sequential methods of state encoding.
Table 1. FSM area using sequential methods of state encoding.
SS_modePPPPCCCCP_CP_CP_CP_Cmax_Cmax_Cmax_Cmax_Cmax_XLsLminLs/Lmin
CS_modeFPGACPLDdiff_wmax_wFPGACPLDdiff_wmax_wFPGACPLDdiff_wmax_wFPGACPLDdiff_wmax_wFPGA
bbara313133243027372931223628262329302824221.091
bbsse586065625864625761626555616457626860551.091
beecount162219221622192216221922171616161616161
dk14514140433744464347425643414542424536361
dk169082120878088888887859310483100878610092801.15
dk512221615161618151515151718141517171515141.071
ex2677571765872746774618171566262646235351
ex3262832292723302623233428282323262322221
ex5202424262121272018192223222323222321181.167
ex7253427332228333120244126202525272518181
lion9111515181115151811151518111518181519111.727
pma1611591541571611661671721631591521521811671391511731411391.014
s11561791831751491501801521901481831491491481531481471501471.02
s208697375715773615773697272646474496435351
s27191519149221621922162120111212111691.778
s298102410221063969969965107410009389581073995965950973100894310069381.072
s386586055535956595757505353585657555826261
s420394639292839311939403434333846313837191.947
s8201441331411301321251381261271271471341271271241321341381241.113
shiftreg24344444424224444422
sse586065625864625761626555616457626860551.091
styr1821841931861791941881901861871871891791851771901842131771.203
train11282829272825263128252631282531312525251
Best3 41 153 3324138
Unique 1 111 21 3 16
Avg 1.197
Max 2
Table 2. FSM performance using sequential methods of state encoding.
Table 2. FSM performance using sequential methods of state encoding.
SS_modePPPPCCCCP_CP_CP_CP_Cmax_Cmax_Cmax_Cmax_Cmax_XFsFmaxFmax/Fs
CS_modeFPGACPLDdiff_wmax_wFPGACPLDdiff_wmax_wFPGACPLDdiff_wmax_wFPGACPLDdiff_wmax_wFPGA
bbara2662922263502623962623662813132282392963392823252352933961.352
bbsse2151841992172211861851951821681872081842132362181902122361.113
beecount3262733182733262733182733262733182733463443443443443173461.091
dk142512222322492172612482682462202122782252352622622352492781.116
dk161791961622121971911772021881921971641951942022041942012121.055
dk5122013143243373213133283473203502823693253393303103393293691.122
ex21601831691902062091721771791841721811722152081642151522151.414
ex32692501651721991811991912262531911851592121793052122003051.525
ex53102442801932142422282822563002443032322203232092202493231.297
ex72602102881632362122022382592011882422752522212082522482881.161
lion93894674283733894674283733894674283733894673733734672944671.588
pma1891681471501731311551621631702472761511571681651571632761.693
s11541531491561431481511561391631521481641631501761651611761.093
s2082222181691722532131912542192001912132302382222592382532591.024
s272273122452733892752762473892752762472573013243243013633891.072
s2981091051111091051111041091101081071101081041071101091131131
s3861961891922112152052172211852032262481972232262121671852481.341
s4202582262212423682942643732432252872163343242832743242803731.332
s8201701671601741661841411611561601591641781661621591561651841.115
shiftreg8479356119359249269389269268479438478479359359359359359431.009
sse2151841992172211861851951821681872081842132362181902122361.113
styr1511531581571411371421381591701641581521581601521471601701.063
train112122061792871842162602411842162602411842162412412162442871.176
Best 11213 11214123311
Unique 112 2 1 1141133 1
Avg 1.212
Max 1.693
Disclaimer/Publisher’s Note: The statements, opinions and data contained in all publications are solely those of the individual author(s) and contributor(s) and not of MDPI and/or the editor(s). MDPI and/or the editor(s) disclaim responsibility for any injury to people or property resulting from any ideas, methods, instructions or products referred to in the content.

Share and Cite

MDPI and ACS Style

Salauyou, V.; Bułatow, W. Optimized Sequential State Encoding Methods for Finite-State Machines in Field-Programmable Gate Array Implementations. Appl. Sci. 2024, 14, 5594. https://doi.org/10.3390/app14135594

AMA Style

Salauyou V, Bułatow W. Optimized Sequential State Encoding Methods for Finite-State Machines in Field-Programmable Gate Array Implementations. Applied Sciences. 2024; 14(13):5594. https://doi.org/10.3390/app14135594

Chicago/Turabian Style

Salauyou, Valery, and Witali Bułatow. 2024. "Optimized Sequential State Encoding Methods for Finite-State Machines in Field-Programmable Gate Array Implementations" Applied Sciences 14, no. 13: 5594. https://doi.org/10.3390/app14135594

Note that from the first issue of 2016, this journal uses article numbers instead of page numbers. See further details here.

Article Metrics

Back to TopTop