【问题标题】:In-Assembly example for NEON Cortex-A8NEON Cortex-A8 的组装示例
【发布时间】:2015-04-23 02:08:33
【问题描述】:

我正在尝试为 cortex A8 的 NEON 编译和示例唱汇编代码,以便在 BeagleBone Black board (BBB) 上使用此二进制文件。我使用下面列出的 eclipse 工具 GCC 编译器和汇编器,

GCC:arm-linux-gnueabi-gcc

汇编器:arm-linux-gnueabi-as

以下错误发生在一个示例中,对于我使用的每个示例,我都发现类似的错误

Description Path    Resource    Location    Type
SP not allowed in register list -- `ldmia r12,{r4-r11,r13,lr}'      EXAMPLE_NEON    line 61, external location: /tmp/ccTXrczs.s C/C++ Problem

我使用的代码

/************************
* 霓虹灯.c * ************************/

#include <stdio.h>


__attribute__((aligned (16)))
unsigned short int data1[8];
unsigned short int data2[8];
unsigned short int out[8];

void* neontest_save_buffer[16];


void
neontest(unsigned short int *a, unsigned short int *b,
                unsigned short int* q)
{
  __asm__(
"   movw        r12, #:lower16:neontest_save_buffer\n\t"
"   movt        r12, #:upper16:neontest_save_buffer\n\t"
"   stmia       r12, {r4-r11, r13, lr}        @ save registers\n\t"
"   vld1.16     {q1}, [r0:128]\n\t"
"   vld1.16     {q2}, [r1:128]\n\t"
"   vadd.i16    q0, q1, q2\n\t"
"   vst1.32     {q0}, [r2:128]\n\t"
"   movw        r12, #:lower16:neontest_save_buffer\n\t"
"   movt        r12, #:upper16:neontest_save_buffer\n\t"
"   ldmia       r12, {r4-r11, r13, lr}        @ reload all registers and return\n\t"
"finish:\n\t"
    );

}

int
main(void)
{
    int i;

    for (i=0; i<8; i++)
    {
        data1[i]=i*10;
        data2[i]=5;
        out[i]=0;
    }

    neontest(data1, data2, out);

    printf("output is: ");
    for (i=0; i<7; i++)
    {
        printf("%d, ", out[i]);
    }
    printf("%d\n", out[i]);

  return(0);
}

【问题讨论】:

  • 你能提供一个完整的示例让人们尝试编译吗?

标签: c++ c linux eclipse gcc


【解决方案1】:

好像您使用的是 Thumb32 模式,其中sp cannot be in the list of registers(来自[1])。

如果您不设置新堆栈,为什么还需要保存堆栈? 只需尝试从 stm 块和 ldm 块中删除 r13。

【讨论】:

    【解决方案2】:

    默认编译器使用thumb模式,在命令行中添加“-marm”即可在ARM模式下编译代码:

    arm-linux-gnueabihf-gcc -mcpu=cortex-a8 -mfpu=neon -marm neon.c

    你也可以调整代码让编译器做寄存器保存/恢复,这样代码就可以编译为ARM和thumb2指令集:

    #include <stdio.h>
    
    
    __attribute__((aligned (16)))
    unsigned short int data1[8];
    unsigned short int data2[8];
    unsigned short int out[8];
    
    void
    neontest(unsigned short int *a, unsigned short int *b,
                    unsigned short int* q)
    {
        __asm volatile (
    "   vld1.16     {q1}, [%[a]:128]\n\t"
    "   vld1.16     {q2}, [%[b]:128]\n\t"
    "   vadd.i16    q0, q1, q2\n\t"
    "   vst1.32     {q0}, [%[q]:128]\n\t"
    
         : [q] "+r" (q)
         : [a] "r" (a), [b] "r" (b)
         : "q0", "q1", "q2"
        );
    }
    
    int
    main(void)
    {
        int i;
    
        for (i=0; i<8; i++)
        {
            data1[i]=i*10;
            data2[i]=5;
            out[i]=0;
        }
    
        neontest(data1, data2, out);
    
        printf("output is: ");
        for (i=0; i<7; i++)
        {
            printf("%d, ", out[i]);
        }
        printf("%d\n", out[i]);
    
      return(0);
    }
    

    arm-linux-gnueabihf-gcc -mcpu=cortex-a8 -mfpu=neon -marm neon2.c

    arm-linux-gnueabihf-gcc -mcpu=cortex-a8 -mfpu=neon -mthumb neon2.c

    【讨论】:

      猜你喜欢
      • 2014-03-03
      • 2011-05-05
      • 2011-05-11
      • 2013-01-12
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2019-12-12
      • 1970-01-01
      相关资源
      最近更新 更多