gitee.com/quant1x/gox@v1.7.6/num/asm/_cpp/max.cpp (about) 1 #include <cstddef> 2 #include <limits> 3 4 template<typename T> 5 T Max(T* x, size_t n) { 6 T max = std::numeric_limits<T>::lowest(); 7 for (size_t i = 0; i < n; i++) { 8 if (x[i] > max) { 9 max = x[i]; 10 } 11 } 12 return max; 13 } 14 15 template<typename T> 16 void Maximum(T* __restrict x, T* __restrict y, size_t n) { 17 for (size_t i = 0; i < n; i++) { 18 if (y[i] > x[i]) { 19 x[i] = y[i]; 20 } 21 } 22 } 23 24 template<typename T> 25 void MaximumNumber(T* __restrict x, T a, size_t n) { 26 for (size_t i = 0; i < n; i++) { 27 if (a > x[i]) { 28 x[i] = a; 29 } 30 } 31 } 32 33 double Max_F64_D(double* x, size_t n) { 34 return Max(x, n); 35 } 36 37 float Max_F32_F(float* x, size_t n) { 38 return Max(x, n); 39 } 40 41 void Maximum_F64_V(double* __restrict x, double* __restrict y, size_t n) { 42 Maximum(x, y, n); 43 } 44 45 void Maximum_F32_V(float* __restrict x, float* __restrict y, size_t n) { 46 Maximum(x, y, n); 47 } 48 49 void MaximumNumber_F64_V(double* __restrict x, double a, size_t n) { 50 MaximumNumber(x, a, n); 51 } 52 53 void MaximumNumber_F32_V(float* __restrict x, float a, size_t n) { 54 MaximumNumber(x, a, n); 55 }