| 1 |
// Auto-generated file. Do not edit! |
| 2 |
// Template: src/f32-vclamp/scalar.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 "xnnpack/common.h" |
| 13 |
#include "xnnpack/math.h" |
| 14 |
#include "xnnpack/vunary.h" |
| 15 |
|
| 16 |
|
| 17 |
void xnn_f32_vclamp_ukernel__scalar_u4( |
| 18 |
size_t batch, |
| 19 |
const float* input, |
| 20 |
float* output, |
| 21 |
const union xnn_f32_minmax_params params[restrict XNN_MIN_ELEMENTS(1)]) |
| 22 |
{ |
| 23 |
assert(batch != 0); |
| 24 |
assert(batch % sizeof(float) == 0); |
| 25 |
assert(input != NULL); |
| 26 |
assert(output != NULL); |
| 27 |
|
| 28 |
const float vy_min = params->scalar.min; |
| 29 |
const float vy_max = params->scalar.max; |
| 30 |
|
| 31 |
for (; batch >= 4 * sizeof(float); batch -= 4 * sizeof(float)) { |
| 32 |
float vacc0 = input[0]; |
| 33 |
float vacc1 = input[1]; |
| 34 |
float vacc2 = input[2]; |
| 35 |
float vacc3 = input[3]; |
| 36 |
input += 4; |
| 37 |
|
| 38 |
vacc0 = math_max_f32(vacc0, vy_min); |
| 39 |
vacc1 = math_max_f32(vacc1, vy_min); |
| 40 |
vacc2 = math_max_f32(vacc2, vy_min); |
| 41 |
vacc3 = math_max_f32(vacc3, vy_min); |
| 42 |
|
| 43 |
vacc0 = math_min_f32(vacc0, vy_max); |
| 44 |
vacc1 = math_min_f32(vacc1, vy_max); |
| 45 |
vacc2 = math_min_f32(vacc2, vy_max); |
| 46 |
vacc3 = math_min_f32(vacc3, vy_max); |
| 47 |
|
| 48 |
output[0] = vacc0; |
| 49 |
output[1] = vacc1; |
| 50 |
output[2] = vacc2; |
| 51 |
output[3] = vacc3; |
| 52 |
output += 4; |
| 53 |
} |
| 54 |
if XNN_UNLIKELY(batch != 0) { |
| 55 |
do { |
| 56 |
float vacc = *input++; |
| 57 |
vacc = math_max_f32(vacc, vy_min); |
| 58 |
vacc = math_min_f32(vacc, vy_max); |
| 59 |
*output++ = vacc; |
| 60 |
batch -= sizeof(float); |
| 61 |
} while (batch != 0); |
| 62 |
} |
| 63 |
} |