kit

kit
git clone https://git.ryansepassi.com/git/kit.git
Log | Files | Refs | README

fp_ti.c (3888B)


      1 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
      2 //
      3 // Consolidated soft-float runtime helpers for kit's libkit_rt.a.
      4 // The build compiles only this one file; the per-op .c files are #included
      5 // as snippets and not directly compiled. The fp_lib_undef.h reset header is
      6 // included between sections that switch precision or (src,dst) pair.
      7 // License: Apache-2.0 WITH LLVM-exception (see lib/LICENSE-compiler-rt.txt).
      8 
      9 // ============================================================
     10 // Section 1: SINGLE precision — i128/u128 -> sf, and sf -> ti/tu fix
     11 // ============================================================
     12 // ---- floattisf.c ----
     13 #include "int_lib.h"
     14 
     15 #define SRC_I128
     16 #define DST_SINGLE
     17 #include "int_to_fp_impl.inc"
     18 
     19 // Returns: convert a to a float, rounding toward even.
     20 
     21 // Assumption: float is a IEEE 32 bit floating point type
     22 //             ti_int is a 128 bit integral type
     23 
     24 // seee eeee emmm mmmm mmmm mmmm mmmm mmmm
     25 
     26 COMPILER_RT_ABI float __floattisf(ti_int a) { return __floatXiYf__(a); }
     27 
     28 #undef SRC_I128
     29 #undef DST_SINGLE
     30 // ---- floatuntisf.c ----
     31 #include "int_lib.h"
     32 
     33 #define SRC_U128
     34 #define DST_SINGLE
     35 #include "int_to_fp_impl.inc"
     36 
     37 // Returns: convert a to a float, rounding toward even.
     38 
     39 // Assumption: float is a IEEE 32 bit floating point type
     40 //             tu_int is a 128 bit integral type
     41 
     42 // seee eeee emmm mmmm mmmm mmmm mmmm mmmm
     43 
     44 COMPILER_RT_ABI float __floatuntisf(tu_int a) { return __floatXiYf__(a); }
     45 
     46 #undef SRC_U128
     47 #undef DST_SINGLE
     48 // ---- fixsfti.c ----
     49 #include "int_lib.h"
     50 
     51 #define SINGLE_PRECISION
     52 #include "fp_lib.h"
     53 
     54 #define fixint_t ti_int
     55 #define fixuint_t tu_int
     56 #define FP_FIX_SUFFIX fixsfti
     57 #include "fp_fixint_impl.inc"
     58 
     59 COMPILER_RT_ABI ti_int __fixsfti(fp_t a) { return __fixint(a); }
     60 
     61 #undef fixint_t
     62 #undef fixuint_t
     63 #undef FP_FIX_SUFFIX
     64 // ---- fixunssfti.c ----
     65 #define SINGLE_PRECISION
     66 #include "fp_lib.h"
     67 
     68 #define fixuint_t tu_int
     69 #define FP_FIX_SUFFIX fixunssfti
     70 #include "fp_fixuint_impl.inc"
     71 
     72 COMPILER_RT_ABI tu_int __fixunssfti(fp_t a) { return __fixuint(a); }
     73 
     74 #undef fixuint_t
     75 #undef FP_FIX_SUFFIX
     76 
     77 #include "fp_lib_undef.h"
     78 
     79 // ============================================================
     80 // Section 2: DOUBLE precision — i128/u128 -> df, and df -> ti/tu fix
     81 // ============================================================
     82 // ---- floattidf.c ----
     83 #include "int_lib.h"
     84 
     85 #define SRC_I128
     86 #define DST_DOUBLE
     87 #include "int_to_fp_impl.inc"
     88 
     89 // Returns: convert a to a double, rounding toward even.
     90 
     91 // Assumption: double is a IEEE 64 bit floating point type
     92 //            ti_int is a 128 bit integral type
     93 
     94 // seee eeee eeee mmmm mmmm mmmm mmmm mmmm | mmmm mmmm mmmm mmmm mmmm mmmm mmmm
     95 // mmmm
     96 
     97 COMPILER_RT_ABI double __floattidf(ti_int a) { return __floatXiYf__(a); }
     98 
     99 #undef SRC_I128
    100 #undef DST_DOUBLE
    101 // ---- floatuntidf.c ----
    102 #include "int_lib.h"
    103 
    104 #define SRC_U128
    105 #define DST_DOUBLE
    106 #include "int_to_fp_impl.inc"
    107 
    108 // Returns: convert a to a double, rounding toward even.
    109 
    110 // Assumption: double is a IEEE 64 bit floating point type
    111 //             tu_int is a 128 bit integral type
    112 
    113 // seee eeee eeee mmmm mmmm mmmm mmmm mmmm | mmmm mmmm mmmm mmmm mmmm mmmm mmmm
    114 // mmmm
    115 
    116 COMPILER_RT_ABI double __floatuntidf(tu_int a) { return __floatXiYf__(a); }
    117 
    118 #undef SRC_U128
    119 #undef DST_DOUBLE
    120 // ---- fixdfti.c ----
    121 #include "int_lib.h"
    122 
    123 #define DOUBLE_PRECISION
    124 #include "fp_lib.h"
    125 
    126 #define fixint_t ti_int
    127 #define fixuint_t tu_int
    128 #define FP_FIX_SUFFIX fixdfti
    129 #include "fp_fixint_impl.inc"
    130 
    131 COMPILER_RT_ABI ti_int __fixdfti(fp_t a) { return __fixint(a); }
    132 
    133 #undef fixint_t
    134 #undef fixuint_t
    135 #undef FP_FIX_SUFFIX
    136 // ---- fixunsdfti.c ----
    137 #include "int_lib.h"
    138 
    139 #define DOUBLE_PRECISION
    140 #include "fp_lib.h"
    141 #define fixuint_t tu_int
    142 #define FP_FIX_SUFFIX fixunsdfti
    143 #include "fp_fixuint_impl.inc"
    144 
    145 COMPILER_RT_ABI tu_int __fixunsdfti(fp_t a) { return __fixuint(a); }
    146 
    147 #undef fixuint_t
    148 #undef FP_FIX_SUFFIX