簡體   English   中英

如何在 gcc 中使用矢量化選項

[英]How to use vectorise option in gcc

Linux 3.13.0-68-generic x86_64 Ubuntu 14.04.3 gcc (Ubuntu 4.8.4-2ubuntu1~14.04) 4.8.4

我有一個簡單的程序,我想實際使用矢量化。

#include <stdio.h>
#include <sys/time.h>
struct timeval stop, start;

int main() {
    int i;

    int x[8192], y[8192];
    int a = 1, b = 2, c = 3;

    gettimeofday(&start, NULL);

    for (i = 0; i < 8192; i++) {
            y[i] = a * x[i] * x[i] + b * x[i] + c;
    }

    gettimeofday(&stop, NULL);

    printf("%d us\n", stop.tv_usec - start.tv_usec);

      for (i = 0; i < 8192; i++) {
        printf("%d\r", y[i]);
      }
    return 0;
}

如果我使用

-O0時間是30 us

-O1時間是3 us

-O2時間是1 or 0 us

但如果我使用

-finline-functions -funswitch-loops -fpredictive-commoning -fgcse-after-reload -ftree-loop-distribute-patterns -ftree-slp-vectorize -fvect-cost-model -ftree-partial-pre -fipa-cp-clone -ftree-vectorize

這些是我能找到的所有矢量化選項,但時間消耗與-O0相同

我應該使用什么正確的選項?

gcc -O2 -ftree-vectorize -ftree-vectorizer-verbose=1 main.c

這是輸出:

main.c: In function ‘main’:
main.c:19:3: warning: format ‘%d’ expects argument of type ‘int’, but argument 2 has type ‘__suseconds_t’ [-Wformat=]
   printf("%d us\n", stop.tv_usec - start.tv_usec);
   ^

Analyzing loop at main.c:21

Analyzing loop at main.c:13


Vectorizing loop at main.c:13

main.c:13: note: LOOP VECTORIZED.
main.c:5: note: vectorized 1 loops in function.

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM