Verilog Math Functions - ChipVerify
Maybe your like
- Integer Math Functions
- Real Math Functions
Verilog math functions can be used in place of constant expressions and supports both integer and real maths.
Integer Math Functions
The function $clog2 returns the ceiling of log2 of the given argument. This is typically used to calculate the minimum width required to address a memory of given size.
For example, if the design has 7 parallel adders, then the minimum number of bits required to represent all 7 adders is $clog2 of 7 that yields 3.
module des #(parameter NUM_UNITS = 7) // Use of this system function helps to reduce the // number of input wires to this module (input [$clog2(NUM_UNITS)-1:0] active_unit); initial $monitor("active_unit = %d", active_unit); endmodule `define NUM_UNITS 5 module tb; integer i; reg [`NUM_UNITS-1:0] active_unit; des #(.NUM_UNITS(`NUM_UNITS)) u0(active_unit); initial begin active_unit = 1; #10 active_unit = 7; #10 active_unit = 8; end endmoduleNote that the signal active_unit has 3-bits to store total 5 units.
Output xcelium> run active_unit = 001 active_unit = 111 active_unit = 000 xmsim: *W,RNQUIE: Simulation is complete.Click to try this example in a simulator!
Real Math Functions
These system functions accept real arguments and return a real number.
| Function | Description |
|---|---|
| $ln(x) | Natural logarithm log(x) |
| $log10(x) | Decimal Logarithm log10(x) |
| exp(x) | Exponential of x (ex) where e=2.718281828... |
| sqrt(x) | Square root of x |
| $pow(x, y) | xy |
| $floor(x) | Floor x |
| $ceil(x) | Ceiling x |
| $sin(x) | Sine of x where x is in radians |
| $cos(x) | Cosine of x where x is in radians |
| $tan(x) | Tangent of x where x is in radians |
| $asin(x) | Arc-Sine of x |
| $acos(x) | Arc-Cosine of x |
| $atan(x) | Arc-tangent of x |
| $atan2(x, y) | Arc-tangent of x/y |
| $hypot(x, y) | Hypotenuse of x and y : sqrt(xx + yy) |
| $sinh(x) | Hyperbolic Sine of x |
| $cosh(x) | Hyperbolic-Cosine of x |
| $tanh(x) | Hyperbolic-Tangent of x |
| $asinh(x) | Arc-hyperbolic Sine of x |
| $acosh(x) | Arc-hyperbolic Cosine of x |
| $atanh(x) | Arc-hyperbolic tangent of x |
Tag » How To Enable And Disable Calculator Mode In Verilog
-
Verilog-Mode Help - Veripool
-
Verilog Timescale - ChipVerify
-
Appendix A. Verilog Code Of Design Examples - Springer
-
Emacs Verilog Mode File - Washington
-
Verilog Modelsim (calculator) Error Loading Design - Stack Overflow
-
[PDF] Verilog 2 - Design Examples - UCSD CSE
-
9. Testbenches - FPGA Designs With Verilog - Read The Docs
-
[PDF] Verilog-2001 Quick Reference Guide - Sutherland HDL
-
[PDF] ECE 5745 Complex Digital ASIC Design Tutorial 4: Verilog ...
-
Verilog-A Functions - SIMPLIS
-
5 Basic Calculator Implemented On Basys 3 Board | Verilog - YouTube
-
Specifying VHDL Generics And Verilog Parameters - 2021.1 English