| 1 |
// Auto-generated file. Do not edit! |
| 2 |
// Template: src/f32-vclamp/sse.c.in |
| 3 |
// Generator: tools/xngen |
| 4 |
// |
| 5 |
// Copyright 2020 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 <xmmintrin.h> |
| 13 |
|
| 14 |
#include "xnnpack/common.h" |
| 15 |
#include "xnnpack/vunary.h" |
| 16 |
|
| 17 |
|
| 18 |
void xnn_f32_vclamp_ukernel__sse_u4( |
| 19 |
size_t batch, |
| 20 |
const float* input, |
| 21 |
float* output, |
| 22 |
const union xnn_f32_minmax_params params[restrict XNN_MIN_ELEMENTS(1)]) XNN_OOB_READS |
| 23 |
{ |
| 24 |
assert(batch != 0); |
| 25 |
assert(batch % sizeof(float) == 0); |
| 26 |
assert(input != NULL); |
| 27 |
assert(output != NULL); |
| 28 |
|
| 29 |
const __m128 vy_min = _mm_set1_ps(params->scalar.min); |
| 30 |
const __m128 vy_max = _mm_set1_ps(params->scalar.max); |
| 31 |
|
| 32 |
for (; batch >= 4 * sizeof(float); batch -= 4 * sizeof(float)) { |
| 33 |
__m128 vacc0123 = _mm_loadu_ps(input); |
| 34 |
input += 4; |
| 35 |
|
| 36 |
vacc0123 = _mm_max_ps(vacc0123, vy_min); |
| 37 |
|
| 38 |
vacc0123 = _mm_min_ps(vacc0123, vy_max); |
| 39 |
|
| 40 |
_mm_storeu_ps(output, vacc0123); |
| 41 |
output += 4; |
| 42 |
} |
| 43 |
if XNN_UNLIKELY(batch != 0) { |
| 44 |
__m128 vacc = _mm_loadu_ps(input); |
| 45 |
vacc = _mm_max_ps(vacc, vy_min); |
| 46 |
vacc = _mm_min_ps(vacc, vy_max); |
| 47 |
|
| 48 |
if (batch & (2 * sizeof(float))) { |
| 49 |
_mm_storel_pi((__m64*) output, vacc); |
| 50 |
vacc = _mm_movehl_ps(vacc, vacc); |
| 51 |
output += 2; |
| 52 |
} |
| 53 |
if (batch & (1 * sizeof(float))) { |
| 54 |
_mm_store_ss(output, vacc); |
| 55 |
} |
| 56 |
} |
| 57 |
} |