AskOverflow.Dev

AskOverflow.Dev Logo AskOverflow.Dev Logo

AskOverflow.Dev Navigation

  • 主页
  • 系统&网络
  • Ubuntu
  • Unix
  • DBA
  • Computer
  • Coding
  • LangChain

Mobile menu

Close
  • 主页
  • 系统&网络
    • 最新
    • 热门
    • 标签
  • Ubuntu
    • 最新
    • 热门
    • 标签
  • Unix
    • 最新
    • 标签
  • DBA
    • 最新
    • 标签
  • Computer
    • 最新
    • 标签
  • Coding
    • 最新
    • 标签
主页 / coding / 问题

问题[system-verilog](coding)

Martin Hope
Aleksandr Grigorev
Asked: 2025-04-06 22:01:26 +0800 CST

SystemVerilog 中的三元运算符或 always_comb 与 if

  • 6

假设我有一个模块,它接受两个数字和一个信号,指示它是有符号乘法还是无符号乘法。模块必须执行乘法。

module signed_or_unsigned_mul
# (
  parameter n = 8
)
(
  input  [    n - 1:0] a, b,
  input                signed_mul,
  output [2 * n - 1:0] res
);

我尝试用三元运算符实现它,但它输出不正确的结果,例如 -8 * -7 = 72

assign res = signed_mul ? ($signed(a) * $signed(b)) : (a * b) ;

下面的代码使用 always_comb 和 if 产生正确的结果:

  logic [2 * n - 1:0]  res_stub;
  assign res = res_stub;
  always_comb
    if (signed_mul)
      res_stub = $signed(a) * $signed(b);
    else 
      res_stub = a * b;

我不明白这两种实现有什么区别,也不明白为什么它们会产生不同的输出。你能帮我指出来吗?额外的逻辑变量会不会有这种影响?

system-verilog
  • 1 个回答
  • 34 Views
Martin Hope
Mo'men Sameh
Asked: 2025-03-04 06:11:36 +0800 CST

使用 ref 作为邮箱获取任务的方向类型在这里是否有预期用途?

  • 5

在SystemVerilog LRM 1800-2017 第 15.4.5 节中,该get任务的声明mailbox如下:

任务获取(参考单数消息);

为什么是方向类型ref,不是output?

system-verilog
  • 1 个回答
  • 39 Views
Martin Hope
rx123
Asked: 2024-12-12 18:54:22 +0800 CST

设置约束随机求解器的起始位置

  • 6
class square;
    
    rand bit arr [3][3];
    
    function void pre_randomize();
      arr[0][1] = 1;
      $display ("%p",arr);
    endfunction
       
    constraint ab_c {
      foreach (arr[i,j]) {
        if (arr[i][j] == 1) {
          if (i > 0 && j > 0 && j < 2 && i < 2) { arr[i+2][j-1] == 1;
          }
          else arr[i][j] == 0;
        }
      }
    }

我有一个 3x3 数组,我想创建一个模式,当arr[0][1](起始位置) 为 1 时,我希望将其设置arr[2][0]为 1。约束求解器似乎在随机化后将pre_randomize值设置arr[0][1]为 0。这是预期的吗?

system-verilog
  • 1 个回答
  • 31 Views
Martin Hope
gyuunyuu
Asked: 2024-11-02 21:23:27 +0800 CST

如何根据测试台的顶层参数改变 SystemVerilog 包内常量的值?

  • 4

我在 SystemVerilog 中创建了一个设计模型。它使用定点数学。模块的一些顶级参数用于指定在模块内进行计算时使用什么缩放因子。这会影响预定义常量的值以及如何执行缩小操作和舍入。

现在我有多个预定义常量,然后使用 if..else.. 块根据参数值选择其中一个。有多个不同的函数几乎完全相同,除了它们在计算过程中使用的常量以及如何缩小结果。

我的问题是,是否可以将顶级测试台模块参数传递到包中并使用它来选择常量应具有的值,即使用测试台顶级模块参数对包进行参数化?

我来自 VHDL 背景,`if 与 #if 让我感到困惑。此外,我不确定我尝试做的事情是否可在 SystemVerilog 中使用测试平台模块顶级参数实现。

system-verilog
  • 1 个回答
  • 22 Views
Martin Hope
Emman
Asked: 2024-06-20 02:05:08 +0800 CST

字符串三重引号不被模拟器接受

  • 5

IEEE 1800-2023 LRM 支持三重引号字符串,但没有一个模拟器能够编译(出现以下错误),任何线索都有助于更好地理解。

module top;
  
string foo;

  initial begin
  foo =  """
This is one continuous string.
Single ' and double " can
be placed throughout, and
only a triple quote will end it.
""";
    $display("%0s",foo);
  end
endmodule

获取未终止字符串错误

, https://edaplayground.com/x/Rj4A

system-verilog
  • 1 个回答
  • 18 Views
Martin Hope
Juan_R
Asked: 2024-05-29 15:17:16 +0800 CST

如何在SystemVerilog中访问具有动态值的切片?

  • 5

我想访问具有动态值的切片。我尝试过以不同的方式做到这一点。在第一种情况下,减少了用于控制索引值等的模块逻辑,verilator告诉我这不是一个常量值,我同意这一点,然后我更改了第二个版本,但得到了相同的结果。

1:

module m1 (
input  logic [4:0] in1,  // 8-bit input vector 1
input  logic [4:0] in2,  // 8-bit index
output logic [4:0] out   // 8-bit output vector
);
logic add;

always_comb begin
add = (in2[in1[4:0]-1] & (in2[(in1[4:0]-2):0] != '0); //summary rounding
end

out = in1 + add;//summary of the final operation
endmodule

2:

module m1 (
input  logic [4:0] in1,  // 8-bit input vector 1
input  logic [4:0] in2,  // 8-bit index
output logic [4:0] out   // 8-bit output vector
);
logic add;

always_comb begin
for (int i = 0; i < 4; i++) begin
if((in1[4:0]-2) == i)begin
add = (in2[in1[4:0]-1] & (in2[(i:0] != '0); //summary rounding
end
end

out = in1 + add;//summary of the final operation
endmodule

我试图实现的逻辑是 riscv-v 1.0 的舍入模式。

我已经尝试了几次尝试进行静态逻辑的测试,但我找不到解决问题的方法。我如何在硬件中实现这个逻辑。

system-verilog
  • 1 个回答
  • 29 Views
Martin Hope
Vincci
Asked: 2024-02-23 11:32:21 +0800 CST

解包数组 - 不兼容的复杂类型

  • 5

我需要一些帮助。

我正在尝试计算解压数组中的数量。

下面是代码。

module test_rand;
  bit [7:0] mask_unpacked [0:7];
  int  numOnes[0:7];
    initial begin
      mask_unpacked[0] = 8'b00001111;
      mask_unpacked[1] = 8'b00001111;
      mask_unpacked[2] = 8'b00000000;
      mask_unpacked[3] = 8'b00000000;
      mask_unpacked[4] = 8'b00000000;
      mask_unpacked[5] = 8'b00000000;
      mask_unpacked[6] = 8'b00000000;
      mask_unpacked[7] = 8'b00000000;
      $display("*********************************");
      foreach (mask_unpacked[i]) begin
        $display("mask_unpacked   = %p",mask_unpacked[i]);
        numOnes= $countones(mask_unpacked[i]);
        $display("countones = %p", numOnes[i]);
      end
      $display("*********************************");
    end
endmodule

但是,我收到错误消息

Error-[ICTA] Incompatible complex type
testbench.sv, 16
  Incompatible complex type assignment
  Type of source expression is incompatible with type of target expression. 
  Mismatching types cannot be used in assignments, initializations and 
  instantiations. The type of the target is 'int$[0:7]', while the type of the
  source is 'int'.
  Source Expression: $countones(mask_unpacked[i])

如何解决这个问题?

system-verilog
  • 1 个回答
  • 22 Views
Martin Hope
thorondor1990
Asked: 2024-01-10 02:13:29 +0800 CST

参数化测试类的非过程上下文中包含动态数据的结构

  • 5

SV/UVM 中的以下代码会产生代码后显示的 VCS 编译错误。

 typedef enum int {
  ABC,
  DEF,
  GHI,
 . . .
 } enum_t

class some_test #(type T=uvm_test) extends T;
 
 `uvm_component_param_utils(some_test#(T))

 bit assoc_array[3][enum_t];


 //bunch of tasks and functions here

 
 task run_phase(uvm_phase phase);
   int index;
  
  //Below wait inside some fork-join and begin-end blocks
  //index calculated
  assoc_array[index].delete(); //Compiler OK here
  assoc_array[index][DEF] = 1; //Compiler OK here
 
  //some more forked threads

  wait(assoc_array[index].exists(ABC) && (assoc_array[index][ABC]==1)); //COMPILER ERROR
 endtask

endclass

错误是:

Error-[DTINPCIL] Dynamic type in non-procedural context
"wait ((this.assoc_array[index].exists(ABC) && (this.assoc_array[index][ABC] == 1))) ;"
  Argument: this.assoc_array[index]
  Structure containing dynamic data and/or used in dynamic arrays may not be 
  used in non-procedural context.

我不明白为什么这是非程序上下文。这与测试是参数化测试有什么关系吗?我正在做这样的“扩展”来实现多重继承。我在 Tudor Timi 的一篇博客中看到了这一点,标题为“Fake it Until you make it - Emulate multiple Heritage in System Verilog”,尽管他的示例实现了其他目标,并且绝对不是在参数化测试中。

在其他一些测试包中,我也有这段代码:

typedef some_test #(some_basic_test) better_test;
system-verilog
  • 1 个回答
  • 55 Views
Martin Hope
erng
Asked: 2023-08-22 22:42:33 +0800 CST

当其他信号有效时,信号必须有效

  • 5

我遇到一种情况,设计中的一个信号必须断言至少一个周期,而另一个信号必须断言至少 X 个周期。

期望的结果:

通过: 通过示例1

通过: 通过示例2

通过: 通过示例3

失败: 失败示例 1

我想编写一个属性来使用 SVA 检查这一点,本质上捕获 和 之间的内容posedge,negedge必须sig_1同时sig_2具有$rose()和$fell()。

我尝试过类似的东西...

property prop_sig_2_while_sig_1;
    @(posedge clk)
        $rose(sig_1) ##[0:$] $rose(sig_2) ##[0:$] $fell(sig_2) ##[0:$] $fell(sig_1);
endproperty : prop_sig_2_while_sig_1

但不幸的是,这并没有达到预期的效果。

有没有一种简单有效的方法来实现这一目标?

system-verilog
  • 2 个回答
  • 35 Views

Sidebar

Stats

  • 问题 205573
  • 回答 270741
  • 最佳答案 135370
  • 用户 68524
  • 热门
  • 回答
  • Marko Smith

    重新格式化数字,在固定位置插入分隔符

    • 6 个回答
  • Marko Smith

    为什么 C++20 概念会导致循环约束错误,而老式的 SFINAE 不会?

    • 2 个回答
  • Marko Smith

    VScode 自动卸载扩展的问题(Material 主题)

    • 2 个回答
  • Marko Smith

    Vue 3:创建时出错“预期标识符但发现‘导入’”[重复]

    • 1 个回答
  • Marko Smith

    具有指定基础类型但没有枚举器的“枚举类”的用途是什么?

    • 1 个回答
  • Marko Smith

    如何修复未手动导入的模块的 MODULE_NOT_FOUND 错误?

    • 6 个回答
  • Marko Smith

    `(表达式,左值) = 右值` 在 C 或 C++ 中是有效的赋值吗?为什么有些编译器会接受/拒绝它?

    • 3 个回答
  • Marko Smith

    在 C++ 中,一个不执行任何操作的空程序需要 204KB 的堆,但在 C 中则不需要

    • 1 个回答
  • Marko Smith

    PowerBI 目前与 BigQuery 不兼容:Simba 驱动程序与 Windows 更新有关

    • 2 个回答
  • Marko Smith

    AdMob:MobileAds.initialize() - 对于某些设备,“java.lang.Integer 无法转换为 java.lang.String”

    • 1 个回答
  • Martin Hope
    Fantastic Mr Fox msvc std::vector 实现中仅不接受可复制类型 2025-04-23 06:40:49 +0800 CST
  • Martin Hope
    Howard Hinnant 使用 chrono 查找下一个工作日 2025-04-21 08:30:25 +0800 CST
  • Martin Hope
    Fedor 构造函数的成员初始化程序可以包含另一个成员的初始化吗? 2025-04-15 01:01:44 +0800 CST
  • Martin Hope
    Petr Filipský 为什么 C++20 概念会导致循环约束错误,而老式的 SFINAE 不会? 2025-03-23 21:39:40 +0800 CST
  • Martin Hope
    Catskul C++20 是否进行了更改,允许从已知绑定数组“type(&)[N]”转换为未知绑定数组“type(&)[]”? 2025-03-04 06:57:53 +0800 CST
  • Martin Hope
    Stefan Pochmann 为什么 {2,3,10} 和 {x,3,10} (x=2) 的顺序不同? 2025-01-13 23:24:07 +0800 CST
  • Martin Hope
    Chad Feller 在 5.2 版中,bash 条件语句中的 [[ .. ]] 中的分号现在是可选的吗? 2024-10-21 05:50:33 +0800 CST
  • Martin Hope
    Wrench 为什么双破折号 (--) 会导致此 MariaDB 子句评估为 true? 2024-05-05 13:37:20 +0800 CST
  • Martin Hope
    Waket Zheng 为什么 `dict(id=1, **{'id': 2})` 有时会引发 `KeyError: 'id'` 而不是 TypeError? 2024-05-04 14:19:19 +0800 CST
  • Martin Hope
    user924 AdMob:MobileAds.initialize() - 对于某些设备,“java.lang.Integer 无法转换为 java.lang.String” 2024-03-20 03:12:31 +0800 CST

热门标签

python javascript c++ c# java typescript sql reactjs html

Explore

  • 主页
  • 问题
    • 最新
    • 热门
  • 标签
  • 帮助

Footer

AskOverflow.Dev

关于我们

  • 关于我们
  • 联系我们

Legal Stuff

  • Privacy Policy

Language

  • Pt
  • Server
  • Unix

© 2023 AskOverflow.DEV All Rights Reserve