kit

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

int_lib.h (3032B)


      1 //===-- int_lib.h - LP64 little-endian -----------------------------------===//
      2 //
      3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
      4 // See https://llvm.org/LICENSE.txt for license information.
      5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
      6 //
      7 // kit-tailored: LP64 (long == 64, pointer == 64), little-endian,
      8 // freestanding. Targets: Linux/Darwin x86_64, Linux/Darwin aarch64, RV64.
      9 //===----------------------------------------------------------------------===//
     10 
     11 #ifndef INT_LIB_H
     12 #define INT_LIB_H
     13 
     14 // AEABI ABI is handled via lib/arm/ assembly files; non-ARM targets use the
     15 // platform's default C ABI for these helpers.
     16 #define COMPILER_RT_ABI
     17 
     18 #define ALWAYS_INLINE __attribute__((always_inline))
     19 #define NOINLINE __attribute__((noinline))
     20 #define NORETURN __attribute__((noreturn))
     21 #define UNUSED __attribute__((unused))
     22 
     23 #include <float.h>
     24 #include <limits.h>
     25 #include <stdbool.h>
     26 #include <stdint.h>
     27 
     28 // ---- int_types.h (merged) ----
     29 #ifndef INT_TYPES_H
     30 #define INT_TYPES_H
     31 
     32 // (was int_endianness.h — only defined the markers below)
     33 #define _YUGA_LITTLE_ENDIAN 1
     34 #define _YUGA_BIG_ENDIAN 0
     35 
     36 #ifdef si_int
     37 #undef si_int
     38 #endif
     39 typedef int32_t si_int;
     40 typedef uint32_t su_int;
     41 #define clzsi __builtin_clz
     42 #define ctzsi __builtin_ctz
     43 
     44 typedef int64_t di_int;
     45 typedef uint64_t du_int;
     46 
     47 typedef union {
     48   di_int all;
     49   struct {
     50     su_int low;
     51     si_int high;
     52   } s;
     53 } dwords;
     54 
     55 typedef union {
     56   du_int all;
     57   struct {
     58     su_int low;
     59     su_int high;
     60   } s;
     61 } udwords;
     62 
     63 #define CRT_HAS_128BIT
     64 typedef int ti_int __attribute__((mode(TI)));
     65 typedef unsigned tu_int __attribute__((mode(TI)));
     66 
     67 typedef union {
     68   ti_int all;
     69   struct {
     70     du_int low;
     71     di_int high;
     72   } s;
     73 } twords;
     74 
     75 typedef union {
     76   tu_int all;
     77   struct {
     78     du_int low;
     79     du_int high;
     80   } s;
     81 } utwords;
     82 
     83 static inline ti_int make_ti(di_int h, di_int l) {
     84   twords r;
     85   r.s.high = h;
     86   r.s.low = l;
     87   return r.all;
     88 }
     89 static inline tu_int make_tu(du_int h, du_int l) {
     90   utwords r;
     91   r.s.high = h;
     92   r.s.low = l;
     93   return r.all;
     94 }
     95 
     96 #define CRT_HAS_FLOATING_POINT 1
     97 
     98 typedef union {
     99   su_int u;
    100   float f;
    101 } float_bits;
    102 typedef union {
    103   udwords u;
    104   double f;
    105 } double_bits;
    106 
    107 typedef struct {
    108   udwords low;
    109   udwords high;
    110 } uqwords;
    111 
    112 // IEEE binary128 (tf_float / CRT_HAS_TF_MODE) is supplied via
    113 // include/lp64_le_ldbl128/tf_supplement.h when compiling lib/fp_tf/. Not
    114 // available in this base header to keep it free of feature ifdefs.
    115 
    116 #endif  // INT_TYPES_H
    117 #include "int_util.h"
    118 
    119 COMPILER_RT_ABI int __paritysi2(si_int a);
    120 COMPILER_RT_ABI int __paritydi2(di_int a);
    121 COMPILER_RT_ABI di_int __divdi3(di_int a, di_int b);
    122 COMPILER_RT_ABI si_int __divsi3(si_int a, si_int b);
    123 COMPILER_RT_ABI su_int __udivsi3(su_int n, su_int d);
    124 COMPILER_RT_ABI su_int __udivmodsi4(su_int a, su_int b, su_int* rem);
    125 COMPILER_RT_ABI du_int __udivmoddi4(du_int a, du_int b, du_int* rem);
    126 COMPILER_RT_ABI int __clzti2(ti_int a);
    127 COMPILER_RT_ABI tu_int __udivmodti4(tu_int a, tu_int b, tu_int* rem);
    128 
    129 #endif  // INT_LIB_H