Changeset 4143 for trunk


Ignore:
Timestamp:
Sep 9, 2014, 1:51:04 PM (4 years ago)
Author:
linmengl
Message:

add test code for add_with_carry_ir, detect a bug on AVX2.

Location:
trunk/lib_ir
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • trunk/lib_ir/CMakeLists.txt

    r4139 r4143  
    88    message("---- Compiling for AVX2")
    99    set(CXX_SSE_FLAGS "-msse2 -m64") #"-march=core-avx2")
    10     set(LLVM_SSE_FLAGS -mattr=+sse,+sse2,+avx2,+bmi2,+bmi -march=x86-64)
     10    set(LLVM_SSE_FLAGS "-mattr=+sse,+sse2")
     11    #set(LLVM_SSE_FLAGS -mattr=+sse,+sse2,+avx2,+bmi2,+bmi -march=x86-64)
    1112else (USE_AVX2)
    1213    set(CXX_SSE_FLAGS "-msse2")
  • trunk/lib_ir/gen/llc_func.pytemplate.ll

    r4138 r4143  
    100100}
    101101
     102define void @add_with_carry_ir(<2 x i64> %a, <2 x i64> %b, <2 x i64> %carry_in, <2 x i64>* %carry_out, <2 x i64>* %sum) {
     103entry:
     104  %aa = bitcast <2 x i64> %a to i128
     105  %bb = bitcast <2 x i64> %b to i128
     106  %cin = bitcast <2 x i64> %carry_in to i128
     107
     108  %res1 = call {i128, i1} @llvm.uadd.with.overflow.i128(i128 %aa, i128 %bb)
     109  %sum1 = extractvalue {i128, i1} %res1, 0
     110  %obit1 = extractvalue {i128, i1} %res1, 1
     111
     112  %res2 = call {i128, i1} @llvm.uadd.with.overflow.i128(i128 %sum1, i128 %cin)
     113  %sum2 = extractvalue {i128, i1} %res2, 0
     114  %obit2 = extractvalue {i128, i1} %res2, 1
     115
     116  %ret_sum = bitcast i128 %sum2 to <2 x i64>
     117  %obit = or i1 %obit1, %obit2
     118  %obit_64 = zext i1 %obit to i64
     119  %obit_2x64 = insertelement <2 x i64> zeroinitializer, i64 %obit_64, i32 0
     120
     121  store <2 x i64> %ret_sum, <2 x i64>* %sum
     122  store <2 x i64> %obit_2x64, <2 x i64>* %carry_out
     123
     124  ret void
     125}
     126
    102127define <4 x i32> @add_128(<4 x i32> %a, <4 x i32> %b) {
    103128entry:
     
    118143}
    119144
    120 define i32 @sign_mask_64(<2 x i64> %a) {
    121 entry:
    122   %aa = icmp slt <2 x i64> %a, zeroinitializer
    123   %a1 = bitcast <2 x i1> %aa to i2
    124   %a2 = zext i2 %a1 to i32
    125   ret i32 %a2
    126 }
  • trunk/lib_ir/gen/test_llc.pytemplate.cpp

    r4138 r4143  
    2727SIMD_type sll_128(SIMD_type a, SIMD_type b);
    2828
    29 int sign_mask_64(SIMD_type a);
     29SIMD_type add_with_carry_ir(SIMD_type a, SIMD_type b, SIMD_type carry_in, SIMD_type *carry_out, SIMD_type *sum);
    3030
    3131{% for fw in [128]%}
     
    4040}
    4141
     42int test_long_stream_addition(const SIMD_type &a, const SIMD_type &b)
     43{
     44    SIMD_type c, d, e, f;
     45    short x, y;
     46
     47    //test uadd.with.overflow.i128
     48    c = mvmd<32>::fill(0);
     49    SIMD_type sum0, obit0, sum1, sum2, obit2;
     50    short obit1;
     51    adc(a, b, c, obit0, sum0);
     52    uadd_with_overflow_i128(a, b, &sum1, &obit1);
     53    x = 0;
     54    if (Store2String(sum0,1) != Store2String(sum1,1)) {
     55      cout << "uadd_with_overflow_i128, sum error" << endl;
     56      x = 1;
     57    }
     58    if (Store2String(mvmd<128>::fill(obit1),1) != Store2String(obit0,1)) {
     59      cout << "uadd_with_overflow_i128 failed, obit error" << endl;
     60      x = 1;
     61    }
     62    if (x) {
     63      cout << "a =      " << Store2String(a, 1) << endl;
     64      cout << "b =      " << Store2String(b, 1) << endl;
     65      cout << "sum0 =   " << Store2String(sum0, 1) << endl;
     66      cout << "sum1 =   " << Store2String(sum1, 1) << endl;
     67      cout << "obit0 =  " << Store2String(obit0, 1) << endl;
     68      cout << "obit1 =  " << obit1 << endl;
     69      return 1;
     70    }
     71
     72    //test add_with_carry in pure IR
     73    y = rand() % 2;
     74    c = mvmd<128>::fill(y);
     75    adc(a, b, c, obit0, sum0);
     76    add_with_carry_ir(a, b, c, &obit2, &sum2);
     77    if (Store2String(sum0,1) != Store2String(sum2,1) ||
     78        Store2String(obit0,1) != Store2String(obit2,1)) {
     79      cout << "add_with_carry_ir failed." << endl;
     80      cout << "a =      " << Store2String(a, 1) << endl;
     81      cout << "b =      " << Store2String(b, 1) << endl;
     82      cout << "sum0 =   " << Store2String(sum0, 1) << endl;
     83      cout << "sum2 =   " << Store2String(sum2, 1) << endl;
     84      cout << "obit0 =  " << Store2String(obit0, 1) << endl;
     85      cout << "obit2 =  " << Store2String(obit2, 1) << endl;
     86      return 1;
     87    }
     88
     89    return 0;
     90}
     91
    4292int main() {
    4393  SIMD_type a, b, c, d, e, f;
     
    4595  srand(time(0));
    4696
    47   for (unsigned i = 0; i < 50; ++i) {
     97  for (unsigned i = 0; i < 500; ++i) {
    4898    fill_random(a, b);
    4999
     
    119169    }
    120170
    121     //i128 long stream addition
    122     c = mvmd<32>::fill(0);
    123     SIMD_type sum0, obit0, sum1;
    124     short obit1;
    125     adc(a, b, c, obit0, sum0);
    126     uadd_with_overflow_i128(a, b, &sum1, &obit1);
    127     x = 0;
    128     if (Store2String(sum0,1) != Store2String(sum1,1)) {
    129       cout << "uadd_with_overflow_i128, sum error" << endl;
    130       x = 1;
    131     }
    132     if (Store2String(mvmd<128>::fill(obit1),1) != Store2String(obit0,1)) {
    133       cout << "uadd_with_overflow_i128 failed, obit error" << endl;
    134       x = 1;
    135     }
    136     if (x) {
    137       cout << "a =      " << Store2String(a, 1) << endl;
    138       cout << "b =      " << Store2String(b, 1) << endl;
    139       cout << "sum0 =   " << Store2String(sum0, 1) << endl;
    140       cout << "sum1 =   " << Store2String(sum1, 1) << endl;
    141       cout << "obit0 =  " << Store2String(obit0, 1) << endl;
    142       cout << "obit1 =  " << obit1 << endl;
     171    if (test_long_stream_addition(a, b))
    143172      return 1;
    144     }
    145 
    146173  }
    147174
Note: See TracChangeset for help on using the changeset viewer.