1 |
786 |
skrzyp |
// This file is part of the uSTL library, an STL implementation.
|
2 |
|
|
//
|
3 |
|
|
// Copyright (c) 2005-2009 by Mike Sharov <msharov@users.sourceforge.net>
|
4 |
|
|
// This file is free software, distributed under the MIT License.
|
5 |
|
|
|
6 |
|
|
#include "stdtest.h"
|
7 |
|
|
using namespace ustl::simd;
|
8 |
|
|
|
9 |
|
|
template <typename Ctr>
|
10 |
|
|
void TestBitwiseOperations (Ctr op1, Ctr op2, const Ctr op3)
|
11 |
|
|
{
|
12 |
|
|
passign (op3, op2);
|
13 |
|
|
pand (op1, op2);
|
14 |
|
|
cout << "pand(op1,op2) = " << op2 << endl;
|
15 |
|
|
passign (op3, op2);
|
16 |
|
|
por (op1, op2);
|
17 |
|
|
cout << "por(op1,op2) = " << op2 << endl;
|
18 |
|
|
passign (op3, op2);
|
19 |
|
|
pxor (op1, op2);
|
20 |
|
|
cout << "pxor(op1,op2) = " << op2 << endl;
|
21 |
|
|
passign (op3, op2);
|
22 |
|
|
pshl (op1, op2);
|
23 |
|
|
cout << "pshl(op1,op2) = " << op2 << endl;
|
24 |
|
|
passign (op3, op2);
|
25 |
|
|
pshr (op1, op2);
|
26 |
|
|
cout << "pshr(op1,op2) = " << op2 << endl;
|
27 |
|
|
}
|
28 |
|
|
|
29 |
|
|
template <> inline void TestBitwiseOperations (tuple<2,float>, tuple<2,float>, const tuple<2,float>) {}
|
30 |
|
|
template <> inline void TestBitwiseOperations (tuple<4,float>, tuple<4,float>, const tuple<4,float>) {}
|
31 |
|
|
|
32 |
|
|
template <typename Ctr>
|
33 |
|
|
void TestCtr (const char* ctrType)
|
34 |
|
|
{
|
35 |
|
|
cout << "================================================" << endl;
|
36 |
|
|
cout << "Testing " << ctrType << endl;
|
37 |
|
|
cout << "================================================" << endl;
|
38 |
|
|
Ctr op1, op2, op3;
|
39 |
|
|
fill (op1, 2);
|
40 |
|
|
iota (op2.begin(), op2.end(), 1);
|
41 |
|
|
cout << "op1 = " << op1 << endl;
|
42 |
|
|
cout << "op2 = " << op2 << endl;
|
43 |
|
|
passign (op2, op3);
|
44 |
|
|
cout << "passign(op2,op3) = " << op3 << endl;
|
45 |
|
|
padd (op1, op2);
|
46 |
|
|
cout << "padd(op1,op2) = " << op2 << endl;
|
47 |
|
|
psub (op1, op2);
|
48 |
|
|
cout << "psub(op1,op2) = " << op2 << endl;
|
49 |
|
|
pmul (op1, op2);
|
50 |
|
|
cout << "pmul(op1,op2) = " << op2 << endl;
|
51 |
|
|
pdiv (op1, op2);
|
52 |
|
|
cout << "pdiv(op1,op2) = " << op2 << endl;
|
53 |
|
|
TestBitwiseOperations (op1, op2, op3);
|
54 |
|
|
passign (op3, op2);
|
55 |
|
|
reverse (op2);
|
56 |
|
|
pmin (op3, op2);
|
57 |
|
|
cout << "pmin(op3,op2) = " << op2 << endl;
|
58 |
|
|
passign (op3, op2);
|
59 |
|
|
reverse (op2);
|
60 |
|
|
pmax (op3, op2);
|
61 |
|
|
cout << "pmax(op3,op2) = " << op2 << endl;
|
62 |
|
|
passign (op3, op2);
|
63 |
|
|
reverse (op2);
|
64 |
|
|
reset_mmx();
|
65 |
|
|
pavg (op3, op2);
|
66 |
|
|
cout << "pavg(op3,op2) = " << op2 << endl;
|
67 |
|
|
reset_mmx();
|
68 |
|
|
}
|
69 |
|
|
|
70 |
|
|
template <typename SrcCtr, typename DstCtr, typename Operation>
|
71 |
|
|
void TestConversion (const char* ctrType)
|
72 |
|
|
{
|
73 |
|
|
cout << "================================================" << endl;
|
74 |
|
|
cout << "Testing " << ctrType << endl;
|
75 |
|
|
cout << "================================================" << endl;
|
76 |
|
|
SrcCtr src;
|
77 |
|
|
DstCtr dst;
|
78 |
|
|
typedef typename SrcCtr::value_type srcval_t;
|
79 |
|
|
iota (src.begin(), src.end(), srcval_t(-1.4));
|
80 |
|
|
pconvert (src, dst, Operation());
|
81 |
|
|
cout << src << " -> " << dst << endl;
|
82 |
|
|
iota (src.begin(), src.end(), srcval_t(-1.5));
|
83 |
|
|
pconvert (src, dst, Operation());
|
84 |
|
|
cout << src << " -> " << dst << endl;
|
85 |
|
|
iota (src.begin(), src.end(), srcval_t(-1.7));
|
86 |
|
|
pconvert (src, dst, Operation());
|
87 |
|
|
cout << src << " -> " << dst << endl;
|
88 |
|
|
}
|
89 |
|
|
|
90 |
|
|
void TestSimdAlgorithms (void)
|
91 |
|
|
{
|
92 |
|
|
TestCtr<tuple<8,uint8_t> >("uint8_t[8]");
|
93 |
|
|
TestCtr<tuple<8,int8_t> >("int8_t[8]");
|
94 |
|
|
TestCtr<tuple<4,uint16_t> >("uint16_t[4]");
|
95 |
|
|
TestCtr<tuple<4,int16_t> >("int16_t[4]");
|
96 |
|
|
TestCtr<tuple<2,uint32_t> >("uint32_t[2]");
|
97 |
|
|
TestCtr<tuple<2,int32_t> >("int32_t[2]");
|
98 |
|
|
#if HAVE_INT64_T
|
99 |
|
|
TestCtr<tuple<1,uint64_t> >("uint64_t[1]");
|
100 |
|
|
TestCtr<tuple<1,int64_t> >("int64_t[1]");
|
101 |
|
|
#else
|
102 |
|
|
cout << "No 64bit types available on this platform" << endl;
|
103 |
|
|
#endif
|
104 |
|
|
TestCtr<tuple<2,float> >("float[2]");
|
105 |
|
|
TestCtr<tuple<4,float> >("float[4]");
|
106 |
|
|
TestCtr<tuple<7,uint32_t> >("uint32_t[7]");
|
107 |
|
|
|
108 |
|
|
#if HAVE_MATH_H
|
109 |
|
|
#define CVT_TEST(size,src,dest,op) \
|
110 |
|
|
TestConversion<tuple<size,src>, tuple<size,dest>, op<src,dest> > (#op " " #src " -> " #dest)
|
111 |
|
|
CVT_TEST(4,int32_t,float,fround);
|
112 |
|
|
CVT_TEST(4,int32_t,double,fround);
|
113 |
|
|
CVT_TEST(4,float,int32_t,fround);
|
114 |
|
|
CVT_TEST(4,double,int32_t,fround);
|
115 |
|
|
CVT_TEST(4,float,int32_t,fcast);
|
116 |
|
|
#else
|
117 |
|
|
cout << "CAN'T TEST: math.h functions are not available on this platform." << endl;
|
118 |
|
|
#endif
|
119 |
|
|
}
|
120 |
|
|
|
121 |
|
|
StdBvtMain (TestSimdAlgorithms)
|