| 1 |
// Auto-generated file. Do not edit! |
| 2 |
// Template: src/f16-f32-vcvt/scalar.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 |
|
| 12 |
#include "xnnpack/common.h" |
| 13 |
#include "xnnpack/math.h" |
| 14 |
#include "xnnpack/vcvt.h" |
| 15 |
|
| 16 |
|
| 17 |
void xnn_f16_f32_vcvt_ukernel__scalar_u1( |
| 18 |
size_t batch, |
| 19 |
const xnn_float16* input, |
| 20 |
float* output, |
| 21 |
const void* params) |
| 22 |
{ |
| 23 |
assert(batch != 0); |
| 24 |
assert(batch % sizeof(uint16_t) == 0); |
| 25 |
assert(input != NULL); |
| 26 |
assert(output != NULL); |
| 27 |
|
| 28 |
const uint32_t vsign_mask = 0x80000000; |
| 29 |
const uint32_t vexp_offset = 0x70000000; |
| 30 |
const float vexp_scale = 0x1.0p-112f; |
| 31 |
const uint32_t vmagic_mask = 0x3F000000; |
| 32 |
const float vmagic_bias = 0.5f; |
| 33 |
const uint32_t vdenorm_cutoff = 0x08000000; |
| 34 |
|
| 35 |
const uint16_t* i = (const uint16_t*) input; |
| 36 |
uint32_t* o = (uint32_t*) output; |
| 37 |
do { |
| 38 |
const uint16_t vh = *i++; |
| 39 |
|
| 40 |
const uint32_t vw = (uint32_t) vh << 16; |
| 41 |
const uint32_t vsign = vw & vsign_mask; |
| 42 |
const uint32_t v2w = vw + vw; |
| 43 |
const uint32_t vnorm = float_as_uint32(uint32_as_float((v2w >> 4) + vexp_offset) * vexp_scale); |
| 44 |
const uint32_t vdenorm = float_as_uint32(uint32_as_float((v2w >> 17) | vmagic_mask) - vmagic_bias); |
| 45 |
const uint32_t vf = vsign | (XNN_UNPREDICTABLE(v2w < vdenorm_cutoff) ? vdenorm : vnorm); |
| 46 |
|
| 47 |
*o++ = vf; |
| 48 |
|
| 49 |
batch -= sizeof(uint16_t); |
| 50 |
} while (batch != 0); |
| 51 |
} |