Marat Dukhan | 9a88efe | 2019-12-10 15:54:24 -0800 | [diff] [blame] | 1 | // Auto-generated file. Do not edit! |
| 2 | // Template: src/f32-vbinary/vop-avx.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 <immintrin.h> |
| 13 | |
| 14 | #include <xnnpack/common.h> |
| 15 | #include <xnnpack/vbinary.h> |
| 16 | |
| 17 | |
| 18 | static const int32_t mask_table[14] = {-1, -1, -1, -1, -1, -1, -1, 0, 0, 0, 0, 0, 0, 0}; |
| 19 | |
Marat Dukhan | 91cd2b7 | 2020-04-09 23:57:31 -0700 | [diff] [blame] | 20 | void xnn_f32_vmul_minmax_ukernel__avx_x8( |
Marat Dukhan | 9a88efe | 2019-12-10 15:54:24 -0800 | [diff] [blame] | 21 | size_t n, |
| 22 | const float* a, |
| 23 | const float* b, |
| 24 | float* y, |
Marat Dukhan | f196d01 | 2020-04-15 11:50:03 -0700 | [diff] [blame] | 25 | const union xnn_f32_minmax_params params[restrict XNN_MIN_ELEMENTS(1)]) |
Marat Dukhan | 9a88efe | 2019-12-10 15:54:24 -0800 | [diff] [blame] | 26 | { |
| 27 | assert(n != 0); |
| 28 | assert(n % sizeof(float) == 0); |
Frank Barchard | 0822dde | 2020-07-04 12:47:24 -0700 | [diff] [blame] | 29 | assert(a != NULL); |
| 30 | assert(b != NULL); |
| 31 | assert(y != NULL); |
Marat Dukhan | 9a88efe | 2019-12-10 15:54:24 -0800 | [diff] [blame] | 32 | |
| 33 | const __m256 vy_min = _mm256_broadcast_ps((const __m128*) params->sse.min); |
| 34 | const __m256 vy_max = _mm256_broadcast_ps((const __m128*) params->sse.max); |
| 35 | |
| 36 | for (; n >= 8 * sizeof(float); n -= 8 * sizeof(float)) { |
| 37 | const __m256 va01234567 = _mm256_loadu_ps(a); |
| 38 | a += 8; |
| 39 | |
| 40 | const __m256 vb01234567 = _mm256_loadu_ps(b); |
| 41 | b += 8; |
| 42 | |
| 43 | __m256 vy01234567 = _mm256_mul_ps(va01234567, vb01234567); |
| 44 | |
Marat Dukhan | 13bafb0 | 2020-06-05 00:43:11 -0700 | [diff] [blame] | 45 | |
Marat Dukhan | 9a88efe | 2019-12-10 15:54:24 -0800 | [diff] [blame] | 46 | vy01234567 = _mm256_max_ps(vy01234567, vy_min); |
| 47 | |
| 48 | vy01234567 = _mm256_min_ps(vy01234567, vy_max); |
| 49 | |
| 50 | _mm256_storeu_ps(y, vy01234567); |
| 51 | y += 8; |
| 52 | } |
Marat Dukhan | 9a88efe | 2019-12-10 15:54:24 -0800 | [diff] [blame] | 53 | if XNN_UNLIKELY(n != 0) { |
| 54 | assert(n >= 1 * sizeof(float)); |
| 55 | assert(n <= 7 * sizeof(float)); |
| 56 | __m256i vmask = _mm256_loadu_si256((const __m256i*) ((uintptr_t) &mask_table[7] - n)); |
| 57 | |
| 58 | const __m256 va = _mm256_maskload_ps(a, vmask); |
| 59 | const __m256 vb = _mm256_maskload_ps(b, vmask); |
| 60 | |
| 61 | __m256 vy = _mm256_mul_ps(va, vb); |
| 62 | vy = _mm256_max_ps(vy, vy_min); |
| 63 | vy = _mm256_min_ps(vy, vy_max); |
Marat Dukhan | d16d0f0 | 2020-02-05 21:33:05 -0800 | [diff] [blame] | 64 | |
| 65 | // _mm256_maskstore_ps(y, vmask, vy) could be used here, but triggers msan failures (probably an msan bug). |
| 66 | __m128 vy_lo = _mm256_castps256_ps128(vy); |
| 67 | if (n & (4 * sizeof(float))) { |
| 68 | _mm_storeu_ps(y, vy_lo); |
| 69 | vy_lo = _mm256_extractf128_ps(vy, 1); |
| 70 | y += 4; |
| 71 | } |
| 72 | if (n & (2 * sizeof(float))) { |
| 73 | _mm_storel_pi((__m64*) y, vy_lo); |
| 74 | vy_lo = _mm_movehl_ps(vy_lo, vy_lo); |
| 75 | y += 2; |
| 76 | } |
| 77 | if (n & (1 * sizeof(float))) { |
| 78 | _mm_store_ss(y, vy_lo); |
| 79 | } |
Marat Dukhan | 9a88efe | 2019-12-10 15:54:24 -0800 | [diff] [blame] | 80 | } |
| 81 | } |