【HLS】流水线仿真之排队函数的调用

一丶函数介绍

ihc_hls_enqueue(void *retptr, void *funcptr,/*function arguments*/)

参数
retptr:返回值
funcptr:将要调用的HLS component

这个函数对HLS组件的一次调用进行排队。返回值存储在第一个实参中,该实参应该是指向返回类型的指针。在调用ihc_hls_component_run_all()之前,组件不会运行。

ihc_hls_enqueue_noret(void* funcptr,/*function arguments*/)

参数
funcptr:将要调用的HLS component

这个函数对HLS组件的一次调用进行排队。当HLS组件的返回类型为void时,应该使用这个函数。在调用ihc_hls_component_run_all()之前,组件不会运行。

ihc_hls_component_run_all(void* funcptr)

参数
funcptr:将要调用的HLS component

这个函数接受一个指向HLS组件函数的指针。组件的所有排队调用在运行时将被推入,当组件能够接受新的调用时,HDL模拟器就能以最快的速度运行。

二丶编译指令

i++ -march=x86-64 <.c 或者 .cpp文件> -v

这一步仅仅是使用g++或i++编译器进行功能验证

i++ -march=CycloneV <.c 或者 .cpp文件> -v -ghdl

编译HLS,生成IP,检查编译器生成的报告,在仿真中验证设计


运行目录下生成的exe可执行文件,若没有运行,在下一步仿真时会没有波形

vsim a.prj/verification/vsim.wlf

三丶加法器

代码设计:

#include "HLS/stdio.h"
#include "HLS/hls.h"
#include "assert.h"
#include "stdlib.h"

component int add(int a,int b)
{
    return a+b;
}

int main()
{
    srand(0);
    int i,x,y,z;
    #if 0
    for ( i = 0; i < 10; i++)
    {
        x = rand() % 10;
        y = rand() % 10;
        ihc_hls_enqueue(&z,&add,x,y);
    }
    ihc_hls_component_run_all(add);
    return 0;
    
    #else 
    for ( i = 0; i < 10; i++)
    {
        x = rand() % 10;
        y = rand() % 10;
        z = add(x,y);
        printf("%d = %d + %d\n",z,x,y);
        assert(z == x+y);
    }
    return 0;

    #endif
}

1.没加流水线

在这里插入图片描述
从波形看出 就是函数调用一次,等结果输出一次,然后才能再次调用函数

2.加流水线

在这里插入图片描述
先累计调用函数acc,在等到ihc_hls_component_run_all函数调用玩,一次运行之前的排队函数。

四丶乘法器

代码设计:

#include "HLS/stdio.h"
#include "HLS/hls.h"
#include "assert.h"
#include "stdlib.h"

component int multiply(int a,int b)
{
    return a*b;
}

int main()
{
    srand(0);
    int i,x[10]={0},y[10]={0},z[10]={0};
    #if 0

    for ( i = 0; i < 10; i++)
    {
        x[i] = rand() % 10;
        y[i] = rand() % 10;
        z[i] = multiply(x[i],y[i]);
        printf("%d = %d * %d\n",z[i],x[i],y[i]);
    }
    return 0;
    #else
    for ( i = 0; i < 10; i++)
    {
        x[i] = rand() % 10;
        y[i] = rand() % 10;
        
        ihc_hls_enqueue(&z[i],&multiply,x[i],y[i]);
    }
    ihc_hls_component_run_all(multiply);
    return 0;
    #endif
}

1.没加流水线

在这里插入图片描述

2.加流水线

在这里插入图片描述

3.报告分析

顺着路径找到报告分析
在这里插入图片描述

打开就能看到资源使用情况
在这里插入图片描述
在这里插入图片描述

最后对比两种方式的报告发现消耗的资源都是相同的,只有此处有所差异

在这里插入图片描述

参考文章:https://blog.csdn.net/qq_42585108/article/details/120614492

### 回答1: 在 TURBO C 2.0 中,您可以使用 biosdisk() 函数来格式化软盘。 下面是一段代码示例: ``` #include <stdio.h> #include <dos.h> int main() { // 定义扇区的大小 unsigned int sector_size[3] = {512, 512, 1024}; // 定义填充字节 unsigned char fill_char[3] = {0xF6, 0xF6, 0x48}; // 格式化磁道 70 面 0 的前三个扇区 for (int i = 0; i < 3; i++) { int result = biosdisk(2, 0, 70, 0, i + 1, 1, sector_size[i], fill_char[i]); if (result != 0) { printf("格式化扇区 %d 失败,返回码: %d\n", i + 1, result); } } return 0; } ``` 请注意,在使用 biosdisk() 函数之前,需要包含 dos.h 头文件。 希望这能帮到您! ### 回答2: 使用TURBO C 2.0语言,可以通过以下代码格式化软盘的70磁道0面,并分别格式化3个扇区,大小分别为512字节、512字节和1024字节。其中,前两个扇区使用F6填充,第三个扇区使用48填充。 ```c #include<stdlib.h> #include<stdio.h> #include<dos.h> void formatFloppyDisk(){ union REGS regs; regs.h.ah = 0x0;// To format a floppy disk, we set AH=0 regs.h.dl = 0;// Drive number (0=A, 1=B, etc.) regs.x.cx = 0;// Track number to format regs.h.dh = 0;// Head number regs.h.al = 0;// Sector size (0=default, 1=512 bytes, 2=1024 bytes, 3=2048 bytes etc.) int FILL_BYTE = 0;// The byte value to fill the sectors with during formatting int NUM_SECTORS = 3;// Number of sectors to format // To format 70th track 0th head regs.x.ax = 0x1301; // 0x13 = Reset disk system, 01H = Reset only specified drive int86(0x13, &regs, &regs); // BIOS interrupt to reset disk system for (int i=0; i<NUM_SECTORS; i++){ regs.x.ax = 0x3101; // 0x31 = Write Format, 01H = Format only current track regs.x.bx = 0x0001; // 0x00 = Drive A:, 01H = Head 1, 0 = Generate ID Field depending on the disk in the drive 1 = Keep the ID Field all zeros regs.x.cx = 0x0170; // Track number=70(0-79 range) regs.h.dh = 0x00; // Head number=0 or 1 regs.h.al = 0x02; // Control byte=always zero regs.x.dx = i+1; // Sector number starting from 1 regs.x.si = 0x0000; // segment and offset of read/write buffer regs.x.di = 0x0000; // segment and offset of result if(i == 2){ FILL_BYTE = 0x48; // Fill the third sector with 48 regs.x.ax = 0x3102; // 0x31 = Write Format, 02H = Format sequential tracks immediately following the one being formatted }else{ FILL_BYTE = 0xF6; // Fill the first two sectors with F6 } regs.h.ah = FILL_BYTE; // Fill the sector with specified byte int86(0x13, &regs, &regs); // BIOS interrupt to format the specified sector } } int main(){ formatFloppyDisk(); return 0; } ``` 上述代码使用了INT 0x13,即BIOS中断服务例程,来执行软盘格式化操作。通过设置寄存器的不同参数,可以指定要格式化的磁道、面、扇区大小和填充字节。在这个例子中,我们格式化了软盘70磁道0面的3个扇区,前两个扇区使用F6填充,第三个扇区使用48填充。
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值