用零开始初始化大型结构,需要多少个Cortex-M7 CPU周期?

发布于 2025-02-01 03:54:00 字数 996 浏览 5 评论 0原文

我的结构很大,数组很少。 起见,让我们考虑这样的结构:

typedef struct {
    uint32_t data_count;
    uint8_t data[512];
    uint32_t error_count;
    uint8_t errors[512];
} measurements_t;

结构初始化〜1kb结构需要多少微控制器CPU周期?

为简单

使用零以〜1kb 声明后的数据)?

Cortex-M7 Core是否具有填充记忆的零元素指令?我不是集会的人,我在本手册,我目前无法访问适当的编译器来检查编译器生产的组件。

measurements_t measurement_results = {0};    // initialization with all zeroes

// or

measurements_t measurement_results;          // no initialization
measurement_results.data_count = 0;
measurement_results.error_count = 0;

实际上,我的结构更复杂,几乎没有级别,并且可能更多的数据。

如果我只是用{0}初始化代码,则更容易管理代码, 但是,如果这是对STM32F7的循环廉价的,那么我将不得不创建快速构造函数,该快速构造函数仅在此类结构真正需要的位置将其置于零。

I have big structure with few arrays. For simplicity let's consider structure like this:

typedef struct {
    uint32_t data_count;
    uint8_t data[512];
    uint32_t error_count;
    uint8_t errors[512];
} measurements_t;

How many microcontroller CPU cycles does it take to initialize ~1kB structure with zeros?

Does

I'm wondering if I should initialize whole structure with zeroes, or not (assign required data after declaration)?

Does the Cortex-M7 core have any assembly language instruction to fill memory with zeros? I'm not assembly guy, I can't find anything in this manual and I have no access to proper compiler at this moment to check assembly that compiler produces.

measurements_t measurement_results = {0};    // initialization with all zeroes

// or

measurements_t measurement_results;          // no initialization
measurement_results.data_count = 0;
measurement_results.error_count = 0;

In fact my struct is more complicated and has few levels and probably more data.

It will be easier to manage code later if I just initialize it with {0},
but if that is cycle-expensive on STM32F7 - I will have to create fast constructor that puts zeroes only where it is really needed for structures like this.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

野の 2025-02-08 03:54:00

根据我的经验,最快的方法是将64位商店指令逐个列出。

typedef struct {
    uint32_t data_count;
    uint8_t data[512];
    uint32_t error_count;
    uint8_t errors[512];
} measurements_t;


void zoo(measurements_t *m)
{
    uint64_t *x = (uint64_t *)m;
    #pragma GCC unroll sizeof(*m) / sizeof(*x)
    for(int i = 0; i < sizeof(*m) / sizeof(*x); i++)
        x[i] = 0;
}

https://godbolt.org/z/6wv1dyxfpp

使其更快地进入ITCM内存,并在ITCM内存中更快地放置代码可能进入DTCM内存的结构。它将地址和数据总线分开。

From my experience the fastest way is to have long list of 64 bit store instructions one after another.

typedef struct {
    uint32_t data_count;
    uint8_t data[512];
    uint32_t error_count;
    uint8_t errors[512];
} measurements_t;


void zoo(measurements_t *m)
{
    uint64_t *x = (uint64_t *)m;
    #pragma GCC unroll sizeof(*m) / sizeof(*x)
    for(int i = 0; i < sizeof(*m) / sizeof(*x); i++)
        x[i] = 0;
}

https://godbolt.org/z/6Wv1dYxfP

to make it faster place code into ITCM memory and if possible structures into DTCM memory. It separates address and data busses.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文