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/vcvt.h> 14 15 #include <fp16.h> 16 17 xnn_f16_f32_vcvt_ukernel__scalar_x2(size_t n,const void * input,float * output,const union xnn_f16_f32_cvt_params params[restrict XNN_MIN_ELEMENTS (1)])18void xnn_f16_f32_vcvt_ukernel__scalar_x2( 19 size_t n, 20 const void* input, 21 float* output, 22 const union xnn_f16_f32_cvt_params params[restrict XNN_MIN_ELEMENTS(1)]) 23 { 24 assert(n != 0); 25 assert(n % sizeof(uint16_t) == 0); 26 assert(input != NULL); 27 assert(output != NULL); 28 29 const uint32_t vsign_mask = params->scalar.sign_mask; 30 const uint32_t vexp_offset = params->scalar.exp_offset; 31 const float vexp_scale = params->scalar.exp_scale; 32 const uint32_t vmagic_mask = params->scalar.magic_mask; 33 const float vmagic_bias = params->scalar.magic_bias; 34 const uint32_t vdenorm_cutoff = params->scalar.denorm_cutoff; 35 36 const uint16_t* i = (const uint16_t*) input; 37 uint32_t* o = (uint32_t*) output; 38 for (; n >= 2 * sizeof(uint16_t); n -= 2 * sizeof(uint16_t)) { 39 const uint16_t vh0 = i[0]; 40 const uint16_t vh1 = i[1]; 41 i += 2; 42 43 const uint32_t vw0 = (uint32_t) vh0 << 16; 44 const uint32_t vw1 = (uint32_t) vh1 << 16; 45 46 const uint32_t vsign0 = vw0 & vsign_mask; 47 const uint32_t vsign1 = vw1 & vsign_mask; 48 49 const uint32_t v2w0 = vw0 + vw0; 50 const uint32_t v2w1 = vw1 + vw1; 51 52 const uint32_t vnorm0 = fp32_to_bits(fp32_from_bits((v2w0 >> 4) + vexp_offset) * vexp_scale); 53 const uint32_t vnorm1 = fp32_to_bits(fp32_from_bits((v2w1 >> 4) + vexp_offset) * vexp_scale); 54 55 const uint32_t vdenorm0 = fp32_to_bits(fp32_from_bits((v2w0 >> 17) | vmagic_mask) - vmagic_bias); 56 const uint32_t vdenorm1 = fp32_to_bits(fp32_from_bits((v2w1 >> 17) | vmagic_mask) - vmagic_bias); 57 58 const uint32_t vf0 = vsign0 | (XNN_UNPREDICTABLE(v2w0 < vdenorm_cutoff) ? vdenorm0 : vnorm0); 59 const uint32_t vf1 = vsign1 | (XNN_UNPREDICTABLE(v2w1 < vdenorm_cutoff) ? vdenorm1 : vnorm1); 60 61 o[0] = vf0; 62 o[1] = vf1; 63 o += 2; 64 } 65 if XNN_UNLIKELY(n != 0) { 66 const uint16_t vh = *i; 67 68 const uint32_t vw = (uint32_t) vh << 16; 69 const uint32_t vsign = vw & vsign_mask; 70 const uint32_t v2w = vw + vw; 71 const uint32_t vnorm = fp32_to_bits(fp32_from_bits((v2w >> 4) + vexp_offset) * vexp_scale); 72 const uint32_t vdenorm = fp32_to_bits(fp32_from_bits((v2w >> 17) | vmagic_mask) - vmagic_bias); 73 const uint32_t vf = vsign | (XNN_UNPREDICTABLE(v2w < vdenorm_cutoff) ? vdenorm : vnorm); 74 75 *o = vf; 76 } 77 } 78