2

我有以下使用 Intel-rtm 的代码,

rtmCheck.c:

#include <stdio.h>
#include <stdlib.h>
#include <immintrin.h>

int test_otherfunction(int a, int b){
int c=0;
   
for (int i=0; i<1000;i++){
      c=c+a+b;
   }


for (int i=0; i<1000000000;i++){
    c=c+a+b;
}

for (int i=0; i<1000000000;i++){
    c=c+a+b;
}
for (int i=0; i<1000000000;i++){
    c=c+a+b;
}

return 1;
}

int main(int argc, char *argv[])
{
   int result=-1;
   unsigned status;
   while(result!=1){
      if ((status = _xbegin()) == _XBEGIN_STARTED) {
         if(test_otherfunction(1,2))
             result=1;
             _xend();
      }else{
             printf("rtmCheck: Transaction failed\n");
             printf("status is %ld\n", status);
             printf("Trying again ...\n");

      }
    
   }
printf("rtmCheck : Result is %d\n", result);

return 0;
}

如果我用下面的 Makefile1 编译,它总是失败。我想这是意料之中的。我没关系。

生成文件1

CC=gcc
CFLAGS= -mrtm

rtmCheck: rtmCheck.o
        $(CC) $(CFLAGS) -o rtmCheck rtmCheck.o

clean: 
        rm -f *.o rtmCheck

输出:

rtmCheck: Transaction failed
status is 0
Trying again ...
rtmCheck: Transaction failed
status is 0
Trying again ...
rtmCheck: Transaction failed
status is 0
Trying again ...
...........
...........

但我有另一个 Makefile2。如果我用这个(Makefile2)编译我的代码,这每次都有效。只是不明白为什么?

生成文件2:

CC  := gcc
CFLAGS  :=  -mrtm -Wall -g -MD -O2 -I ../
LDFLAGS := -ltest 

tests_files := rtmCheck

all: $(tests_files)

rtmCheck: rtmCheck.o ../libtest/libtest.a
        $(CC) $(CFLAGS) -static $(<) -L../libtest/ $(LDFLAGS) -o $(@)

clean:
        rm -f *.o test *.d $(tests_files)

-include *.d

输出:

$./rtmCheck 
rtmCheck : Result is 1

上面的 Make 文件使用了一些静态库。但我没有使用图书馆的任何东西。有人可以告诉我为什么会这样吗?

4

0 回答 0