| 1 |
// Auto-generated file. Do not edit! |
| 2 |
// Template: src/f32-f16-vcvt/scalar-fabsf.c.in |
| 3 |
// Generator: tools/xngen |
| 4 |
// |
| 5 |
// Copyright 2021 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 |
#include <math.h> |
| 12 |
|
| 13 |
#include "xnnpack/common.h" |
| 14 |
#include "xnnpack/math.h" |
| 15 |
#include "xnnpack/vcvt.h" |
| 16 |
|
| 17 |
|
| 18 |
void xnn_f32_f16_vcvt_ukernel__scalar_fabsf_u1( |
| 19 |
size_t batch, |
| 20 |
const float* input, |
| 21 |
xnn_float16* output, |
| 22 |
const void* params) |
| 23 |
{ |
| 24 |
assert(batch != 0); |
| 25 |
assert(batch % sizeof(float) == 0); |
| 26 |
assert(input != NULL); |
| 27 |
assert(output != NULL); |
| 28 |
|
| 29 |
const float vscale_to_inf = 0x1.0p+112f; |
| 30 |
const uint32_t vexp_bias = UINT32_C(0x07800000); |
| 31 |
const float vscale_to_zero = 0x1.0p-110f; |
| 32 |
const uint32_t vexpw_max = UINT32_C(0x7F800000); |
| 33 |
const uint32_t vbias_min = UINT32_C(0x40000000); |
| 34 |
const uint16_t vexph_mask = UINT16_C(0x7C00); |
| 35 |
const uint16_t vmanth_mask = UINT16_C(0x0FFF); |
| 36 |
const uint16_t vnanh = UINT16_C(0x7E00); |
| 37 |
|
| 38 |
uint16_t* o = (uint16_t*) output; |
| 39 |
do { |
| 40 |
const float vx = *input++; |
| 41 |
|
| 42 |
const float vabsx = fabsf(vx); |
| 43 |
uint32_t vsignw = float_as_uint32(vx); |
| 44 |
|
| 45 |
const uint32_t vnonsignw = float_as_uint32(vabsx); |
| 46 |
float vf = vabsx * vscale_to_inf; |
| 47 |
|
| 48 |
uint32_t vbias = vnonsignw + vexp_bias; |
| 49 |
vsignw ^= vnonsignw; |
| 50 |
|
| 51 |
vf *= vscale_to_zero; |
| 52 |
vbias &= vexpw_max; |
| 53 |
|
| 54 |
vbias = math_max_u32(vbias, vbias_min); |
| 55 |
|
| 56 |
vf += uint32_as_float(vbias); |
| 57 |
|
| 58 |
const uint32_t vbits = float_as_uint32(vf); |
| 59 |
|
| 60 |
const uint16_t vexph = (uint16_t) (vbits >> 13) & vexph_mask; |
| 61 |
const uint16_t vmanth = (uint16_t) vbits & vmanth_mask; |
| 62 |
const uint16_t vsignh = (uint16_t) (vsignw >> 16); |
| 63 |
|
| 64 |
uint16_t vh = vexph + vmanth; |
| 65 |
if XNN_UNPREDICTABLE(vnonsignw > vexpw_max) { |
| 66 |
vh = vnanh; |
| 67 |
} |
| 68 |
vh |= vsignh; |
| 69 |
|
| 70 |
*o++ = vh; |
| 71 |
|
| 72 |
batch -= sizeof(float); |
| 73 |
} while (batch != 0); |
| 74 |
} |