Marat Dukhan | 436ebe6 | 2019-12-04 15:10:12 -0800 | [diff] [blame] | 1 | // Auto-generated file. Do not edit! |
| 2 | // Template: src/f32-vbinary/vopc-scalar.c.in |
| 3 | // Generator: tools/xngen |
| 4 | // |
| 5 | // Copyright 2019 Google LLC |
| 6 | // |
| 7 | // This source code is licensed under the BSD-style license found in the |
| 8 | // LICENSE file in the root directory of this source tree. |
| 9 | |
| 10 | #include <assert.h> |
| 11 | |
| 12 | #include <xnnpack/common.h> |
| 13 | #include <xnnpack/math.h> |
| 14 | #include <xnnpack/vbinary.h> |
| 15 | |
| 16 | |
Marat Dukhan | 91cd2b7 | 2020-04-09 23:57:31 -0700 | [diff] [blame] | 17 | void xnn_f32_vmulc_minmax_ukernel__wasm_x4( |
Marat Dukhan | 436ebe6 | 2019-12-04 15:10:12 -0800 | [diff] [blame] | 18 | size_t n, |
| 19 | const float* a, |
| 20 | const float* b, |
| 21 | float* y, |
Marat Dukhan | f196d01 | 2020-04-15 11:50:03 -0700 | [diff] [blame] | 22 | const union xnn_f32_minmax_params params[restrict XNN_MIN_ELEMENTS(1)]) |
Marat Dukhan | 436ebe6 | 2019-12-04 15:10:12 -0800 | [diff] [blame] | 23 | { |
| 24 | assert(n != 0); |
| 25 | assert(n % sizeof(float) == 0); |
Frank Barchard | 0822dde | 2020-07-04 12:47:24 -0700 | [diff] [blame] | 26 | assert(a != NULL); |
| 27 | assert(b != NULL); |
| 28 | assert(y != NULL); |
Marat Dukhan | 436ebe6 | 2019-12-04 15:10:12 -0800 | [diff] [blame] | 29 | |
| 30 | const float vy_min = params->scalar.min; |
| 31 | const float vy_max = params->scalar.max; |
| 32 | |
| 33 | const float vb = *b; |
| 34 | for (; n >= 4 * sizeof(float); n -= 4 * sizeof(float)) { |
| 35 | const float va0 = a[0]; |
| 36 | const float va1 = a[1]; |
| 37 | const float va2 = a[2]; |
| 38 | const float va3 = a[3]; |
| 39 | a += 4; |
| 40 | |
| 41 | float vy0 = va0 * vb; |
| 42 | float vy1 = va1 * vb; |
| 43 | float vy2 = va2 * vb; |
| 44 | float vy3 = va3 * vb; |
| 45 | |
Marat Dukhan | 13bafb0 | 2020-06-05 00:43:11 -0700 | [diff] [blame] | 46 | |
Marat Dukhan | 436ebe6 | 2019-12-04 15:10:12 -0800 | [diff] [blame] | 47 | vy0 = __builtin_wasm_max_f32(vy0, vy_min); |
| 48 | vy1 = __builtin_wasm_max_f32(vy1, vy_min); |
| 49 | vy2 = __builtin_wasm_max_f32(vy2, vy_min); |
| 50 | vy3 = __builtin_wasm_max_f32(vy3, vy_min); |
| 51 | |
| 52 | vy0 = __builtin_wasm_min_f32(vy0, vy_max); |
| 53 | vy1 = __builtin_wasm_min_f32(vy1, vy_max); |
| 54 | vy2 = __builtin_wasm_min_f32(vy2, vy_max); |
| 55 | vy3 = __builtin_wasm_min_f32(vy3, vy_max); |
| 56 | |
| 57 | y[0] = vy0; |
| 58 | y[1] = vy1; |
| 59 | y[2] = vy2; |
| 60 | y[3] = vy3; |
| 61 | y += 4; |
| 62 | } |
| 63 | if XNN_UNLIKELY(n != 0) { |
| 64 | do { |
| 65 | const float va = *a++; |
| 66 | float vy = va * vb; |
| 67 | vy = __builtin_wasm_max_f32(vy, vy_min); |
| 68 | vy = __builtin_wasm_min_f32(vy, vy_max); |
| 69 | *y++ = vy; |
| 70 | n -= sizeof(float); |
| 71 | } while (n != 0); |
| 72 | } |
| 73 | } |