Update the code so NDArray::all works with other instruction sets or vanilla looping.
double
NDArray_All(NDArray *a) {
__m256d zero = _mm256_set1_pd(0.0);
int i;
double *array = NDArray_DDATA(a);
for (i = 0; i < NDArray_NUMELEMENTS(a) - 3; i += 4) {
__m256d elements = _mm256_loadu_pd(&array[i]);
__m256d comparison = _mm256_cmp_pd(elements, zero, _CMP_NEQ_OQ);
// Perform horizontal OR operation on comparison results
int mask = _mm256_movemask_pd(comparison);
if (mask != 0x0F) {
return 0; // At least one element is zero
}
}
// Check remaining elements (if any)
for (; i < NDArray_NUMELEMENTS(a); i++) {
if (array[i] == 0.0) {
return 0; // Element is zero
}
}
return 1; // All elements are non-zero
}
Update the code so NDArray::all works with other instruction sets or vanilla looping.