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.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • 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.