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 #include <fp16.h> 18 19 xnn_f32_f16_vcvt_ukernel__scalar_fabsf_x1(size_t n,const float * input,void * output,const union xnn_f32_f16_cvt_params params[restrict XNN_MIN_ELEMENTS (1)])20void xnn_f32_f16_vcvt_ukernel__scalar_fabsf_x1( 21 size_t n, 22 const float* input, 23 void* output, 24 const union xnn_f32_f16_cvt_params params[restrict XNN_MIN_ELEMENTS(1)]) 25 { 26 assert(n != 0); 27 assert(n % sizeof(float) == 0); 28 assert(input != NULL); 29 assert(output != NULL); 30 31 const float vscale_to_inf = params->scalar_fabsf.scale_to_inf; 32 const uint32_t vexp_bias = params->scalar_fabsf.exp_bias; 33 const float vscale_to_zero = params->scalar_fabsf.scale_to_zero; 34 const uint32_t vexpw_max = params->scalar_fabsf.expw_max; 35 const uint32_t vbias_min = params->scalar_fabsf.bias_min; 36 const uint16_t vexph_mask = params->scalar_fabsf.exph_mask; 37 const uint16_t vmanth_mask = params->scalar_fabsf.manth_mask; 38 const uint16_t vnanh = params->scalar_fabsf.nanh; 39 40 uint16_t* o = (uint16_t*) output; 41 do { 42 const float vx = *input++; 43 44 const float vabsx = fabsf(vx); 45 uint32_t vsignw = fp32_to_bits(vx); 46 47 const uint32_t vnonsignw = fp32_to_bits(vabsx); 48 float vf = vabsx * vscale_to_inf; 49 50 uint32_t vbias = vnonsignw + vexp_bias; 51 vsignw ^= vnonsignw; 52 53 vf *= vscale_to_zero; 54 vbias &= vexpw_max; 55 56 vbias = math_max_u32(vbias, vbias_min); 57 58 vf += fp32_from_bits(vbias); 59 60 const uint32_t vbits = fp32_to_bits(vf); 61 62 const uint16_t vexph = (uint16_t) (vbits >> 13) & vexph_mask; 63 const uint16_t vmanth = (uint16_t) vbits & vmanth_mask; 64 const uint16_t vsignh = (uint16_t) (vsignw >> 16); 65 66 uint16_t vh = vexph + vmanth; 67 if XNN_UNPREDICTABLE(vnonsignw > vexpw_max) { 68 vh = vnanh; 69 } 70 vh |= vsignh; 71 72 *o++ = vh; 73 74 n -= sizeof(float); 75 } while (n != 0); 76 } 77