如何调整下环体W / GCC? [英] How to align C for-loop body w/ GCC?

查看:176
本文介绍了如何调整下环体W / GCC?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在我们的嵌入式架构,我们有一个64位IAB(指令对齐缓冲器)。为了优化取得顺序,就要求一个循环体将开始对齐到8字节边界

In our embedded architecture we have a 64-bit IAB (Instruction Alignment Buffer). In order to optimize the fetch sequence, it is required that the body of a loop will start aligned to an 8-byte boundary.

这是很容易使用 .balign 指令汇编实现这一点,但我不能找到一个语法,这将暗示C编译器对准code。

It is easy to achieve this in assembly using the .balign directive, but I cannot find a syntax that will hint the C compiler to align the code.

试图precede的for循环与内联汇编与 .balign 指令不能正常工作,因为它对准的for循环序言(设置),而不是循环体本身。

Trying to precede the for loop with inline assembly with the .balign directive doesn't work as it aligns the for loop prolog (setup) and not the loop body itself.

做同样的地方 ASM()行是内循环,增加了 NOP -s到循环机构,费用precious周期。

Doing the same where the asm() line is inside the loop, adds nop-s to the loop body that cost precious cycles.

编辑1:假设code:

EDIT 1: assume the code:

    __asm__ volatile("nop");  
    __asm__ volatile("nop");  

    for (j0=0; j0<N; j0+=4)
    {
        c[j0+ 0] = a[j0+ 0] + b[j0+ 0];
        c[j0+ 1] = a[j0+ 1] + b[j0+ 1];
        c[j0+ 2] = a[j0+ 2] + b[j0+ 2];
        c[j0+ 3] = a[j0+ 3] + b[j0+ 3];
    }

我要第一个 C = A + B 对齐到8字节的地址。我可以添加 NOP -s像上面一个preliminary编译之后,但是这是一个临时的解决方案,将与第1 code修改打破。

I want the first c=a+b to be aligned to an 8-byte address. I can add the nop-s like above after a preliminary compilation, but this is an ad-hoc solution that will break with the 1st code change.

编辑2:感谢@R ..,该解决方案是使用 -falign-循环= 8 编译器选项

EDIT 2: Thanks to @R.., the solution is to use the -falign-loops=8 compiler option.

推荐答案

嗯,这不是什么GCC的 -falign-循环选项是什么?

Umm, isn't this what GCC's -falign-loops option is for?

这篇关于如何调整下环体W / GCC?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆