第5讲 FPGA运算符详解

tuzki9611 / 2023-05-03 / 原文

 1 module top(
 2     output        [31:0]     c
 3 );
 4 
 5 localparam [15:0]    a = 65535;
 6 localparam [15:0]    b = 25687;
 7 
 8 
 9 assign c = a*b;
10 //两个常数相乘,综合后不使用资源,直接综合为一个常数
11 module top(
12     output        [15:0]     c
13 );
14 
15 localparam [15:0]    a = 65520;
16 localparam [15:0]    b = 25687;
17 
18 
19 assign c = a/b;
20 //两个常数相除,综合后不使用逻辑资源,直接综合为一个常数
21 module top(
22     output        [15:0]     c
23 );
24 
25 localparam [15:0]    a = 65535;
26 localparam [15:0]    b = 25687;
27 
28 
29 assign c = a%b;
30 //两个常数取余,不使用逻辑资源
31 module top(
32     input        [15:0]     a             ,
33     output        [16:0]     c
34 );
35 
36 assign c = a*256;
37 //变量与2的指数相乘,不会使用逻辑资源,综合为移位的方式
38 module top(
39     input        [15:0]     a             ,
40     output        [14:0]     c
41 );
42 
43 assign c = a/512;
44 //变量与2的指数相除,不使用逻辑资源,综合为移位的方式
45 module top(
46     input        [15:0]     a             ,
47     output        [15:0]     c
48 );
49 
50 assign c = a%1024;
51 //变量与2的指数取余,不使用逻辑资源
52 module top(
53     input        [15:0]     a             ,
54     output        [31:0]     c
55 );
56 
57 assign c = a*32767;
58 //变量与非2的指数相乘,综合为LUT,且随着乘数的增大,LUT也会增加,或者直接使用DSP;
59 module top(
60     input        [15:0]     a             ,
61     output        [15:0]     c
62 );
63 
64 assign c = a/3;
65 //变量与非2的指数相除,综合为LUT,且LUT占用较多
66 module top(
67     input        [15:0]     a             ,
68     output        [15:0]     c
69 );
70 
71 assign c = a%32767;
72 //变量与非2的指数取余,综合为LUT,
73 module top(
74     input        [15:0]     a             ,
75     input        [15:0]     b             ,
76     output        [31:0]     c
77 );
78 
79 assign c = a*b;
80 //两个变量相乘,综合为DSP
81 module top(
82     input        [15:0]     a             ,
83     input        [15:0]     b             ,
84     output        [15:0]     c
85 );
86 
87 assign c = a/b;
88 //两个变量相除,综合为较多的LUT
89 module top(
90     input        [15:0]     a             ,
91     input        [15:0]     b             ,
92     output        [15:0]     c
93 );
94 
95 assign c = a%b;//两个变量取余,综合为较多的LUT