Changeset 4236 for trunk


Ignore:
Timestamp:
Oct 14, 2014, 2:06:17 PM (4 years ago)
Author:
linmengl
Message:

check in test code for @llvm.uadd.with.overflow.carryin

Location:
trunk/lib_ir/gen
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/lib_ir/gen/llc_func.pytemplate.ll

    r4143 r4236  
    125125}
    126126
     127declare {i128, i1} @llvm.uadd.with.overflow.carryin.i128(i128 %a, i128 %b, i1 %carryin)
     128
     129define void @add_with_carry_ir_better(<2 x i64> %a, <2 x i64> %b, <2 x i64> %carry_in, <2 x i64>* %carry_out, <2 x i64>* %sum) {
     130entry:
     131  ;CHECK-LABEL: add_with_carry_ir
     132  %aa = bitcast <2 x i64> %a to i128
     133  %bb = bitcast <2 x i64> %b to i128
     134  %cc = bitcast <2 x i64> %carry_in to i128
     135  %cin = trunc i128 %cc to i1
     136
     137  %res1 = call {i128, i1} @llvm.uadd.with.overflow.carryin.i128(i128 %aa, i128 %bb, i1 %cin)
     138  %sum1 = extractvalue {i128, i1} %res1, 0
     139  %obit = extractvalue {i128, i1} %res1, 1
     140
     141  %ret_sum = bitcast i128 %sum1 to <2 x i64>
     142  %obit_64 = zext i1 %obit to i64
     143  %obit_2x64 = insertelement <2 x i64> zeroinitializer, i64 %obit_64, i32 0
     144
     145  store <2 x i64> %ret_sum, <2 x i64>* %sum
     146  store <2 x i64> %obit_2x64, <2 x i64>* %carry_out
     147
     148  ret void
     149}
     150
    127151define <4 x i32> @add_128(<4 x i32> %a, <4 x i32> %b) {
    128152entry:
  • trunk/lib_ir/gen/test_llc.pytemplate.cpp

    r4144 r4236  
    2828
    2929SIMD_type add_with_carry_ir(SIMD_type a, SIMD_type b, SIMD_type carry_in, SIMD_type *carry_out, SIMD_type *sum);
     30SIMD_type add_with_carry_ir_better(SIMD_type a, SIMD_type b, SIMD_type carry_in, SIMD_type *carry_out, SIMD_type *sum);
    3031
    3132{% for fw in [128]%}
     
    6061      x = 1;
    6162    }
    62     if (Store2String(mvmd<128>::fill(obit1),1) != Store2String(obit0,1)) {
     63    if (Store2String(mvmd<128>::fill(obit1 % 2),1) != Store2String(obit0,1)) {
    6364      cout << "uadd_with_overflow_i128 failed, obit error" << endl;
    6465      x = 1;
     
    7778    uadd_with_overflow_i128(a, simd_not(a), &sum1, &obit1);
    7879    if (to_string(sum1) != to_string(simd_not(simd<32>::constant<0>())) ||
    79         obit1 != 0)
     80        obit1 % 2 != 0)
    8081    {
    8182      cout << "a + not(a) error: " << endl;
     
    8990    uadd_with_overflow_i128(sum1, mvmd<128>::fill(1), &sum1, &obit1);
    9091    if (to_string(sum1) != to_string(simd<32>::constant<0>()) ||
    91         obit1 != 1) {
     92        obit1 % 2 != 1) {
    9293      cout << "all ones + 1 error: " << endl;
    9394      cout << "sum1 =   " << to_string(sum1) << endl;
     
    113114    }
    114115
     116    //test add_with_carry_better in pure IR
     117    //add_with_carry_better is implemented with the new intrinsics.
     118    y = rand() % 2;
     119    c = mvmd<128>::fill(y);
     120    adc(a, b, c, obit0, sum0);
     121    add_with_carry_ir_better(a, b, c, &obit2, &sum2);
     122    if (Store2String(sum0,1) != Store2String(sum2,1) ||
     123        Store2String(obit0,1) != Store2String(obit2,1)) {
     124      cout << "add_with_carry_ir_better failed." << endl;
     125      cout << "a =      " << Store2String(a, 1) << endl;
     126      cout << "b =      " << Store2String(b, 1) << endl;
     127      cout << "sum0 =   " << Store2String(sum0, 1) << endl;
     128      cout << "sum2 =   " << Store2String(sum2, 1) << endl;
     129      cout << "obit0 =  " << Store2String(obit0, 1) << endl;
     130      cout << "obit2 =  " << Store2String(obit2, 1) << endl;
     131      return 1;
     132    }
     133
    115134    return 0;
    116135}
Note: See TracChangeset for help on using the changeset viewer.