是否有任何API可以将“svLogicVecVal *”转换为“uint_8”?

k10s72fa  于 2023-01-29  发布在  其他
关注(0)|答案(1)|浏览(161)

我在systemverilog中的输入是以位为单位的;但是我需要它在uint 8_t中。API或库可以做到吗?仅供参考,我试图使用“dpi”验证.C的verilog结果。
系统验证:

//import "DPI-C" function int test_encrypt_ecb();

import "DPI-C" function void compute_bit(input bit i_value, output bit result);
import "DPI-C" function bit get_bit(input bit i_value);
import "DPI-C" function void compute_logic_vector(reg[127:0] i_value, reg[127:0] result, int asize);

丙:
x一个一个一个一个x一个一个二个x
c编译错误

warning: passing argument 2 of \f2\u2019 from incompatible pointer type [enabled by default]

note: expected \u2018uint8_t *\u2019 but argument is of type \u2018const struct svLogicVecVal *\u2019
 void f2(const struct AES_ctx* ctx, uint8_t* buf);

warning: \u2018main\u2019 is normally a non-static function [-Wmain]
 int main(void)
2w3kk1z5

2w3kk1z51#

没有API函数可以将svLogicVecVal转换为其他C类型。您必须了解4状态(0,1,X,Z)数据类型的C数据结构表示,即

typedef struct t_vpi_vecval {
  uint32_t aval; // 2-state component
  uint32_t bval; // 4-state component
} s_vpi_vecval, *p_vpi_vecval;
typedef s_vpi_vecval svLogicVecVal;

一个128位的压缩4态值将存储在一个8个32位字的数组中。aval/bval字将交织在一起。假设您只处理2态值,那么每隔一个32位字拾取一次就可以了。
但是,如果您知道DPI例程只需要处理2状态值,那么您的例程应该使用bit而不是reg/logic,然后您的C例程只需要处理svBitVecVal,它定义为

typedef uint32_t svBitVecVal;

只要你的参数是8位的倍数,你就可以将其转换为uint8_t*。注意对于单位参数或返回值,使用C兼容类型(如byte/int)会更有效,因为它可以通过值传递,并且不需要指针。
下面是一个小例子
系统Verilog代码:

module top;
import "DPI-C" function void compute_logic_vector(bit[127:0] i_value);

   logic [127:0] x = 128'h69c4_e0d8__6a7b_0430__d8cd_b780__70b4_c550;

   initial compute_logic_vector(x); // SV handles the 4- to 2-state conversion for you
endmodule

C代码:

#include "svBitVecVal.h" // compiler generated header guarantees prototypes match
#include <stdint.h>
#include <stdio.h>

void compute_logic_vector(const svBitVecVal* i_value) {
  uint8_t* buf = (uint8_t*) i_value;
  for(int i=0;i<16;i++)
    printf("0x%x ",*buf++);
  printf("\n");
}

运行奎斯塔的命令行:

qrun svBitVecVal.sv -dpiheader svBitVecVal.h svBitVecVal.c

输出:

# 0x50 0xc5 0xb4 0x70 0x80 0xb7 0xcd 0xd8 0x30 0x4 0x7b 0x6a 0xd8 0xe0 0xc4 0x69

相关问题