首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >如何在x86上使用llvm-clang将霓虹灯的本质转化为llvm IR

如何在x86上使用llvm-clang将霓虹灯的本质转化为llvm IR
EN

Stack Overflow用户
提问于 2016-10-23 03:21:04
回答 1查看 781关注 0票数 1

使用clang,我们可以通过编译C程序生成IR:

代码语言:javascript
复制
clang -S -emit-llvm hello.c -o hello.ll

我想将霓虹灯内部的llvm IR,代码如下:

代码语言:javascript
复制
/* neon_example.c - Neon intrinsics example program */
#include <stdint.h>
#include <stdio.h>
#include <assert.h>
#include <arm_neon.h>
/* fill array with increasing integers beginning with 0 */
void fill_array(int16_t *array, int size)
{    int i;
    for (i = 0; i < size; i++)
    {
         array[i] = i;
    }
}
/* return the sum of all elements in an array. This works by calculating 4 totals (one for each lane) and adding those at the end to get the final total */
int sum_array(int16_t *array, int size)
{
     /* initialize the accumulator vector to zero */
     int16x4_t acc = vdup_n_s16(0);
     int32x2_t acc1;
     int64x1_t acc2;
     /* this implementation assumes the size of the array is a multiple of 4 */
     assert((size % 4) == 0);
     /* counting backwards gives better code */
     for (; size != 0; size -= 4)
     {
          int16x4_t vec;
          /* load 4 values in parallel from the array */
          vec = vld1_s16(array);
          /* increment the array pointer to the next element */
          array += 4;
          /* add the vector to the accumulator vector */
          acc = vadd_s16(acc, vec);
      }
      /* calculate the total */
      acc1 = vpaddl_s16(acc);
      acc2 = vpaddl_s32(acc1);
      /* return the total as an integer */
      return (int)vget_lane_s64(acc2, 0);
}
/* main function */
int main()
{
      int16_t my_array[100];
      fill_array(my_array, 100);
      printf("Sum was %d\n", sum_array(my_array, 100));
      return 0;
}

但是它不支持霓虹灯内部,并且打印错误消息如下:

代码语言:javascript
复制
    /home/user/llvm-proj/build/bin/../lib/clang/4.0.0/include/arm_neon.h:65:24: error:
      'neon_vector_type' attribute is not supported for this target
typedef __attribute__((neon_vector_type(8))) float16_t float16x8_t;
                       ^

我认为原因是我的主机在x86上,但塔吉特在手臂上。我不知道如何使用Clang进行交叉编译可以翻译成llvm(clang版本在ubuntu14.04上是4.0 )。是否有任何目标选项命令或其他有用的工具?SSE和neon llvm-IR有什么区别吗?

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2016-10-23 12:50:14

使用预先打包的基于clang的工具链(http://ellcc.org) ELLCC,我可以通过添加-mfpu=neon来编译和运行您的程序:

代码语言:javascript
复制
    rich@dev:~$ ~/ellcc/bin/ecc -target arm32v7-linux -mfpu=neon neon.c
    rich@dev:~$ ./a.
    a.exe  a.out  
    rich@dev:~$ file a.out 
a.out: ELF 32-bit LSB executable, ARM, EABI5 version 1 (SYSV), statically linked, BuildID[sha1]=613c22f6bbc277a8d577dab7bb27cd64443eb390, not stripped
rich@dev:~$ ./a.out 
    Sum was 4950
    rich@dev:~$ 

它是在x86上编译的,我使用QEMU运行它。

使用普通的clang,您还需要为ARM提供适当的-target选项。ELLCC使用的-target选项略有不同。

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/40199187

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档