Microchip
直播中

甘满盛

7年用户 1264经验值
擅长:386660
私信 关注
[问答]

数组与联合数组的联合是否会产生相同的代码W.R.T时间来进行读写操作?

大家好,我想知道这2个定义是否会产生相同的代码W.R.T时间来对它们进行读写操作?我的意思是,这两种结构的汇编指令都是不同的,但在时间尺度上,哪一种更有效,而对它们进行数据读写操作呢?非常感谢您的帮助。

以上来自于百度翻译


      以下为原文

    Hello everyone
I wonder if these 2 definitions would produce same code w.r.t time it takes to do read write operations on them? I mean that the assembly instructions for both constructs would be different but on the time scale which one of these would be more efficient while data read write operations are carried out on them?

union
{
    unsigned int LUT[256];
    struct
    {
        unsigned char LUT_L;
        unsigned char LUT_H;
    }s_LUT[256];
   
}u_LUT;

Or

union
{
    unsigned int LUT;
    struct
    {
        unsigned char LUT_L;
        unsigned char LUT_H;
    }s_LUT;
   
}u_LUT[256];

Your help is highly appreciated.

回帖(4)

陈晨

2018-11-30 16:34:52
如果时间很重要,你可以尝试两种方式。并确保您使用的是付费编译器。

以上来自于百度翻译


      以下为原文

    You can try it both ways if the time is that important. And make sure you are using the paid compiler.
举报

王璨

2018-11-30 16:50:54
机器代码应该是基本相同的(虽然操作顺序可能是不同的)。但是源代码(关于结构成员的地址)是不同的-一个非常熟悉,另一个…

以上来自于百度翻译


      以下为原文

    The machine code should be basially the same (although the sequence of operations mightbvary). But the source code (regarding addressing the struct members) is different - one quite familiar, the other ...
举报

李天竹

2018-11-30 16:58:02
绝大多数病例(2)优于(1)。然而,在这种特殊情况下,(1)可能更好。这是因为对于8位控制器,在(2)中处理16位偏移比在(1)中使用两个256位阵列更困难。

以上来自于百度翻译


      以下为原文

    In the vast majority of cases (2) is better than (1). However, in this particular case, (1) is probably better. This is because for an 8-bit controller and it is harder for it to deal with 16-bit offsets in (2) rather than with two 256-bit arrays in (1).
举报

陈晨

2018-11-30 17:05:37
它仍然是一个猜测编译器编译器如何处理它,这将是更快。

以上来自于百度翻译


      以下为原文

    It is still a guess about how the compiler writers would handle it, and which would be faster.
举报

更多回帖

发帖
×
20
完善资料,
赚取积分