1 /***************************
2 * D programming language http://www.digitalmars.com/d/
3 * Runtime support for double array operations.
4 * Placed in public domain.
13 private import core.stdc.stdio : printf;
14 /* This is so unit tests will test every CPU variant
17 const int CPUID_MAX = 1;
18 bool mmx() { return cpuid == 1 && util.cpuid.mmx(); }
19 bool sse() { return cpuid == 2 && util.cpuid.sse(); }
20 bool sse2() { return cpuid == 3 && util.cpuid.sse2(); }
21 bool amd3dnow() { return cpuid == 4 && util.cpuid.amd3dnow(); }
25 alias util.cpuid.mmx mmx;
26 alias util.cpuid.sse sse;
27 alias util.cpuid.sse2 sse2;
28 alias util.cpuid.amd3dnow amd3dnow;
33 bool disjoint(T)(T[] a, T[] b)
35 return (a.ptr + a.length <= b.ptr || b.ptr + b.length <= a.ptr);
42 /* ======================================================================== */
44 /***********************
49 T[] _arraySliceSliceAddSliceAssign_r(T[] a, T[] c, T[] b)
52 assert(a.length == b.length && b.length == c.length);
53 assert(disjoint(a, b));
54 assert(disjoint(a, c));
55 assert(disjoint(b, c));
59 for (int i = 0; i < a.length; i++)
66 printf("_arraySliceSliceAddSliceAssign_r unittest\n");
67 for (cpuid = 0; cpuid < CPUID_MAX; cpuid++)
69 version (log) printf(" cpuid %d\n", cpuid);
71 for (int j = 0; j < 2; j++)
74 T[] a = new T[dim + j]; // aligned on 16 byte boundary
75 a = a[j .. dim + j]; // misalign for second iteration
76 T[] b = new T[dim + j];
78 T[] c = new T[dim + j];
81 for (int i = 0; i < dim; i++)
83 b[i] = cast(T)(i + 7);
84 c[i] = cast(T)(i * 2);
89 for (int i = 0; i < dim; i++)
91 if (c[i] != cast(T)(a[i] + b[i]))
93 printf("[%d]: %Lg != %Lg + %Lg\n", i, c[i], a[i], b[i]);
101 /* ======================================================================== */
103 /***********************
108 T[] _arraySliceSliceMinSliceAssign_r(T[] a, T[] c, T[] b)
111 assert(a.length == b.length && b.length == c.length);
112 assert(disjoint(a, b));
113 assert(disjoint(a, c));
114 assert(disjoint(b, c));
118 for (int i = 0; i < a.length; i++)
126 printf("_arraySliceSliceMinSliceAssign_r unittest\n");
127 for (cpuid = 0; cpuid < CPUID_MAX; cpuid++)
129 version (log) printf(" cpuid %d\n", cpuid);
131 for (int j = 0; j < 2; j++)
134 T[] a = new T[dim + j]; // aligned on 16 byte boundary
135 a = a[j .. dim + j]; // misalign for second iteration
136 T[] b = new T[dim + j];
138 T[] c = new T[dim + j];
141 for (int i = 0; i < dim; i++)
143 b[i] = cast(T)(i + 7);
144 c[i] = cast(T)(i * 2);
149 for (int i = 0; i < dim; i++)
151 if (c[i] != cast(T)(a[i] - b[i]))
153 printf("[%d]: %Lg != %Lg - %Lg\n", i, c[i], a[i], b[i]);
161 /* ======================================================================== */
163 /***********************
168 T[] _arraySliceExpMulSliceMinass_r(T[] a, T value, T[] b)
170 return _arraySliceExpMulSliceAddass_r(a, -value, b);
173 /***********************
178 T[] _arraySliceExpMulSliceAddass_r(T[] a, T value, T[] b)
181 assert(a.length == b.length);
182 assert(disjoint(a, b));
187 auto aend = aptr + a.length;
192 *aptr++ += *bptr++ * value;
199 printf("_arraySliceExpMulSliceAddass_r unittest\n");
203 version (log) printf(" cpuid %d\n", cpuid);
205 for (int j = 0; j < 1; j++)
208 T[] a = new T[dim + j]; // aligned on 16 byte boundary
209 a = a[j .. dim + j]; // misalign for second iteration
210 T[] b = new T[dim + j];
212 T[] c = new T[dim + j];
215 for (int i = 0; i < dim; i++)
217 b[i] = cast(T)(i + 7);
218 c[i] = cast(T)(i * 2);
224 for (int i = 0; i < dim; i++)
226 //printf("[%d]: %Lg ?= %Lg + %Lg * 6\n", i, c[i], b[i], a[i]);
227 if (c[i] != cast(T)(b[i] + a[i] * 6))
229 printf("[%d]: %Lg ?= %Lg + %Lg * 6\n", i, c[i], b[i], a[i]);