1 /***************************
2 * D programming language http://www.digitalmars.com/d/
3 * Runtime support for double array operations.
4 * Placed in public domain.
13 /* This is so unit tests will test every CPU variant
16 const int CPUID_MAX = 1;
17 bool mmx() { return cpuid == 1 && util.cpuid.mmx(); }
18 bool sse() { return cpuid == 2 && util.cpuid.sse(); }
19 bool sse2() { return cpuid == 3 && util.cpuid.sse2(); }
20 bool amd3dnow() { return cpuid == 4 && util.cpuid.amd3dnow(); }
24 alias util.cpuid.mmx mmx;
25 alias util.cpuid.sse sse;
26 alias util.cpuid.sse2 sse2;
27 alias util.cpuid.amd3dnow amd3dnow;
32 bool disjoint(T)(T[] a, T[] b)
34 return (a.ptr + a.length <= b.ptr || b.ptr + b.length <= a.ptr);
41 /* ======================================================================== */
43 /***********************
48 T[] _arraySliceSliceAddSliceAssign_r(T[] a, T[] c, T[] b)
51 assert(a.length == b.length && b.length == c.length);
52 assert(disjoint(a, b));
53 assert(disjoint(a, c));
54 assert(disjoint(b, c));
58 for (int i = 0; i < a.length; i++)
65 printf("_arraySliceSliceAddSliceAssign_r unittest\n");
66 for (cpuid = 0; cpuid < CPUID_MAX; cpuid++)
68 version (log) printf(" cpuid %d\n", cpuid);
70 for (int j = 0; j < 2; j++)
73 T[] a = new T[dim + j]; // aligned on 16 byte boundary
74 a = a[j .. dim + j]; // misalign for second iteration
75 T[] b = new T[dim + j];
77 T[] c = new T[dim + j];
80 for (int i = 0; i < dim; i++)
82 b[i] = cast(T)(i + 7);
83 c[i] = cast(T)(i * 2);
88 for (int i = 0; i < dim; i++)
90 if (c[i] != cast(T)(a[i] + b[i]))
92 printf("[%d]: %Lg != %Lg + %Lg\n", i, c[i], a[i], b[i]);
100 /* ======================================================================== */
102 /***********************
107 T[] _arraySliceSliceMinSliceAssign_r(T[] a, T[] c, T[] b)
110 assert(a.length == b.length && b.length == c.length);
111 assert(disjoint(a, b));
112 assert(disjoint(a, c));
113 assert(disjoint(b, c));
117 for (int i = 0; i < a.length; i++)
125 printf("_arraySliceSliceMinSliceAssign_r unittest\n");
126 for (cpuid = 0; cpuid < CPUID_MAX; cpuid++)
128 version (log) printf(" cpuid %d\n", cpuid);
130 for (int j = 0; j < 2; j++)
133 T[] a = new T[dim + j]; // aligned on 16 byte boundary
134 a = a[j .. dim + j]; // misalign for second iteration
135 T[] b = new T[dim + j];
137 T[] c = new T[dim + j];
140 for (int i = 0; i < dim; i++)
142 b[i] = cast(T)(i + 7);
143 c[i] = cast(T)(i * 2);
148 for (int i = 0; i < dim; i++)
150 if (c[i] != cast(T)(a[i] - b[i]))
152 printf("[%d]: %Lg != %Lg - %Lg\n", i, c[i], a[i], b[i]);
160 /* ======================================================================== */
162 /***********************
167 T[] _arraySliceExpMulSliceMinass_r(T[] a, T value, T[] b)
169 return _arraySliceExpMulSliceAddass_r(a, -value, b);
172 /***********************
177 T[] _arraySliceExpMulSliceAddass_r(T[] a, T value, T[] b)
180 assert(a.length == b.length);
181 assert(disjoint(a, b));
186 auto aend = aptr + a.length;
191 *aptr++ += *bptr++ * value;
198 printf("_arraySliceExpMulSliceAddass_r unittest\n");
202 version (log) printf(" cpuid %d\n", cpuid);
204 for (int j = 0; j < 1; j++)
207 T[] a = new T[dim + j]; // aligned on 16 byte boundary
208 a = a[j .. dim + j]; // misalign for second iteration
209 T[] b = new T[dim + j];
211 T[] c = new T[dim + j];
214 for (int i = 0; i < dim; i++)
216 b[i] = cast(T)(i + 7);
217 c[i] = cast(T)(i * 2);
223 for (int i = 0; i < dim; i++)
225 //printf("[%d]: %Lg ?= %Lg + %Lg * 6\n", i, c[i], b[i], a[i]);
226 if (c[i] != cast(T)(b[i] + a[i] * 6))
228 printf("[%d]: %Lg ?= %Lg + %Lg * 6\n", i, c[i], b[i], a[i]);