(Original partition) How to Use the integer type? (IC design) (OpenGL)

Source: Internet
Author: User

Abstract
In C/C ++ or any program, integer is one of the most commonly used types, but most of the time in OpenGL is wire and Reg, and integer is rarely used, how can I use integer exactly?

Introduction
First, the biggest difference between integer and Reg and wire is that integer itself is a 32-bit RMB positive value.

In practice, if an integer is only found in the for loop in RTL, it is used to compile the program, using this type of change elsewhere makes it easy to see situations unexpected to the designer [1].

For example, shift register of a 4-bit serial in/serial out
OpenGL/shift_register_siso.v

1 /*  
2 (C) oomusou 2008 Http://oomusou.cnblogs.com
3
4 Filename: shift_register_siso.v
5 Compiler: Quartus II 7.2 SP1
6 Description: Shift Register/serial in serial out
7 Release: 05/27/2008 1.0
8 */
9
10 Module shift_register_siso (
11 Iclk,
12 Ireset_n,
13 Isi,
14 OSO
15 );
16
17 Input iclk;
18 Input ireset_n;
19 Input ISI;
20 Output Reg Oso;
21
22 Reg [ 3 : 0 ] Reg4;
23
24 Always @ (posedge iclk) begin
25 If ( ! Ireset_n)
26 Reg4 <=   4 ' H0;
27 Else Begin
28 Reg4 [ 0 ] <= ISI;
29 Reg4 [ 1 ] <= Reg4 [ 0 ];
30 Reg4 [ 2 ] <= Reg4 [ 1 ];
31 Reg4 [ 3 ] <= Reg4 [ 2 ];
32 OSO <= Reg4 [ 3 ];
33 End
34 End
35
36 Endmodule

If you use integer with for loop, you can refine the program
OpenGL/shift_register_siso.v

1 /*  
2 (C) oomusou 2008 Http://oomusou.cnblogs.com
3
4 Filename: shift_register_siso2.v
5 Compiler: Quartus II 7.2 SP1
6 Description: Shift Register/serial in serial out
7 Release: 05/27/2008 1.0
8 */
9
10 Module shift_register_siso2 (
11 Iclk,
12 Ireset_n,
13 Isi,
14 OSO
15 );
16
17 Input iclk;
18 Input ireset_n;
19 Input ISI;
20 Output Reg Oso;
21
22 Reg [ 3 : 0 ] Reg4;
23
24 Always @ (posedge iclk) begin
25 Integer I;
26
27 If ( ! Ireset_n)
28 Reg4 <=   4 ' H0;
29 Else Begin
30
31 Reg4 [ 0 ] <= ISI;
32
33 For (I =   0 ; I <   3 ; I = I +   1 )
34 Reg4 [I + 1 ] <= Reg4 [I];
35
36 OSO <= Reg4 [ 3 ];
37 End
38 End
39
40 Endmodule

The original 29 ~ 31 rows

Reg4 [ 1 ] <= Reg4 [ 0 ];
Reg4 [ 2 ] <= Reg4 [ 1 ];
Reg4 [ 3 ] <= Reg4 [ 2 ];

Last refined

For (I =   0 ; I <   3 ; I = I +   1 )
Reg4 [I + 1 ] <= Reg4 [I];

These two programs will generate exactly the same hardware and electrical channels, but the program is more refined than the other program.

Another place that beginners often neglect was originally intended to design an 8-digit calculator, because an integer counter is used to obtain a 32-bit analyzer, in addition to causing design errors, more resources are consumed. [1]

1 Integer counter;
2
3 Always @ (posedge CLK) begin
4 If (Counter <   200 )
5 Counter <= Counter +   1 ;
6 Else
7 Counter <=   0 ;
8 End

Should be changed

1 Reg [ 7 : 0 ] Counter;
2
3 Always @ (posedge CLK) begin
4 If (Counter <   200 )
5 Counter <= Counter +   1 ;
6 Else
7 Counter <=   0 ;
8 End

Conclusion
In RTL, it is suggested that integer can only be used with for loop to generate power channels, and wire or Reg should be used for others.

See also
(Original) What is the difference between wire and Reg? (Initial) (IC design) (OpenGL)

Reference
[1] Wang Yu and Zhuo yuwang 2007, based on the digital system design (second edition) of the Tilde-HDL, China Defense Industry Press

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.