当前位置: 首页 > article >正文

vivado $clog2函数

对于.v文件在vivado中是不支持,但是可以修改为.sv或更改文件属性使用sytemverilog来支持。

 /**
    * Math function: $clog2 as specified in Verilog-2005
    *
    * clog2 =          0        for value == 0
    *         ceil(log2(value)) for value >= 1
    *
    * This implementation is a synthesizable variant of the $clog2 function as
    * specified in the Verilog-2005 standard (IEEE 1364-2005).
    *
    * To quote the standard:
    *   The system function $clog2 shall return the ceiling of the log
    *   base 2 of the argument (the log rounded up to an integer
    *   value). The argument can be an integer or an arbitrary sized
    *   vector value. The argument shall be treated as an unsigned
    *   value, and an argument value of 0 shall produce a result of 0.
    */
   function automatic integer clog2;
      input integer value;
      begin
         value = value - 1;
         for (clog2 = 0; value > 0; clog2 = clog2 + 1) begin
            value = value >> 1;
         end
      end
   endfunction


   /**
    * Math function: enhanced clog2 function
    *
    *                        0        for value == 0
    * clog2_width =          1        for value == 1
    *               ceil(log2(value)) for value > 1
    *
    *
    * This function is a variant of the clog2() function, which returns 1 if the
    * input value is 1. In all other cases it behaves exactly like clog2().
    * This is useful to define registers which are wide enough to contain
    * "value" values.
    *
    * Example 1:
    *   parameter ITEMS = 1;
    *   localparam ITEMS_WIDTH = clog2_width(ITEMS); // 1
    *   reg [ITEMS_WIDTH-1:0] item_register; // items_register is now [0:0]
    *
    * Example 2:
    *   parameter ITEMS = 64;
    *   localparam ITEMS_WIDTH = clog2_width(ITEMS); // 6
    *   reg [ITEMS_WIDTH-1:0] item_register; // items_register is now [5:0]
    *
    * Note: I if you want to store the number "value" inside a
    * register, you need a register with size clog2(value + 1), since
    * you also need to store the number 0.
    *
    * Example 3:
    *   reg [clog2_width(64) - 1 : 0]     store_64_items;  // width is [5:0]
    *   reg [clog2_width(64 + 1) - 1 : 0] store_number_64; // width is [6:0]
    */
   function automatic integer clog2_width;
      input integer value;
      begin
         if (value == 1) begin
            clog2_width = 1;
         end else begin
            clog2_width = clog2(value);
         end
      end
   endfunction

有一种说法时clog在仿真中以2为对数,而在综合时以e为对数。(暂时认为是一种错误的看法,如果这样那对vivado来说将是非常严重的错误)

参考:

xilinx的$clog2函数_hhh_fpga的博客-CSDN博客


http://www.kler.cn/news/162356.html

相关文章:

  • Reactor实战,创建一个简单的单线程Reactor(理解了就相当于理解了多线程的Reactor)
  • 时间复杂度为 O(n^2) 的排序算法 | 京东物流技术团队
  • 智能优化算法应用:基于蜣螂算法无线传感器网络(WSN)覆盖优化 - 附代码
  • 批量免费AI写作工具,批量免费AI写作软件
  • 华为电视盒子 EC6108V9C 刷机成linux系统
  • 【推荐系统】推荐算法数学基础
  • 【C++】:STL源码剖析之vector类容器的底层模拟实现
  • Theamleaf导出pdf模版编写(原始th/td编写表格)
  • 前端:HTML+CSS+JavaScript实现轮播图2
  • 网络运维与网络安全 学习笔记2023.12.1
  • 设计图中时序图
  • 搞懂HashTable, HashMap, ConcurrentHashMap 的区别,看着一篇就足够了!!!
  • API成批分配漏洞介绍与解决方案
  • 游戏策划常用的ChatGPT通用提示词模板
  • vue实现页面之间的el-select同步数据选项
  • 【大数据】HBase 中的列和列族
  • 【数据结构】字典树(Trie树)算法总结
  • pydantic的基础用法
  • STM32-OLED显示屏
  • 2023 金砖国家职业技能大赛网络安全省赛理论题样题(金砖国家未来技能挑战赛)
  • 基于Java酒店管理系统
  • DedeCms后台文章列表文档id吗?或者快速定位id编辑文章
  • 【Node.js】基础梳理 6 - MongoDB
  • 安全快速地删除 MySQL 大表数据并释放空间
  • 微信小程序 - 创建 ZIP 压缩包
  • Termux
  • VIT总结
  • 算法学习—排序
  • 用网安技术去合法挖漏洞,一个月能拿多少钱?想不到吧!
  • NVMe Over Fabrics with iRDMA总结 - 1