//#define __SGI_STL_VECBOOL_TEMPLATE #include #include #include #include #include #include #include #include #include extern "C" { #define DEFBAD(func) void func() { abort(); } DEFBAD(fgetwc) DEFBAD(ungetwc) DEFBAD(fputwc) } using namespace std; using namespace NTPM; void totest_with_c(float *a_b, float *a_e, float *b, float *res) { // using namespace NTPM_Intel_Vectorizer; for(;a_b != a_e; a_b+=4, b+=4, res+=4) { __m128 va = _mm_load_ps(a_b); __m128 vb = _mm_load_ps(b); // F32vec4 vr = F32vec4(va) + F32vec4(vb); __m128 vr = _mm_add_ps(va,vb); _mm_store_ps(res, vr); } } void totest_with_obj(float *a_b, float *a_e, float *b, float *res) { for(;a_b != a_e; a_b+=4, b+=4, res+=4) { __m128 va = _mm_load_ps(a_b); __m128 vb = _mm_load_ps(b); F32vec4 vr = F32vec4(va) + F32vec4(vb); _mm_store_ps(res, vr); } } template void print_vector(NTPMai::Promise vpromise) { NTPMai::Promise::const_iterator it = vpromise.begin(); cout << '['; for(; it != vpromise.end(); ++it) cout << *it << " "; cout << ']'; } void test_packeting() { const unsigned LEN = 14; __declspec(align(16)) float A[LEN]; for(unsigned i=0; i x_l = NTPMai::promise(x,x+3); Promise y_l = NTPMai::promise(y,y+3); Promise z_l = NTPMai::promise(z,z+3); MatrixPromise A_l = make_matrix_promise(A,A+9,3,3); /* evaluate y + (A*x).*z */ cout << "y+(A*x).*z = "; print_vector(y_l + weight(multiply_matrix_vector(A_l, x_l), z_l)); cout << endl; cout << "should say [-15 -66 -153 ]\n\n"; /* evaluate y + (A*x)*2 The constant promise always returns the same value when forced. */ cout << "y + (A*x)*2 = " ; print_vector(y_l + weight(multiply_matrix_vector(A_l, x_l), NTPMai::constant(2.0))); cout << endl; cout << "should say [1.8 4.4 7 ]\n\n"; /* boolean operators also produced promises. */ cout << "A(:) > 5 = "; print_vector(NTPMai::promise(A,A+9) > NTPMai::constant(5)); cout << endl; cout << "should say [0 0 0 0 0 1 1 1 1 ]\n\n"; /* Evaluate sum of squared difference of x and y. */ cout << "ssd = " << NTPM::sum(square(x_l - y_l)) << endl; cout << "should say 16.94\n\n"; cout << "7! = " << product(NTPMai::counter(1,7)) << " (should say 5040)" << endl; cout << "4! = " << product(NTPMai::counter(1,4)) << " (should say 24)" << endl; try { test_packeting(); } catch(const exception &e) { cerr << "Excepction: " << e.what() << endl; } }