kit

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

int_lib.h (2386B)


      1 //===-- int_lib.h - ILP32 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: ILP32 (long == 32, pointer == 32), little-endian,
      8 // freestanding. No 128-bit integer support (no ti_int / __int128). Targets:
      9 // Linux/Darwin x86, ARM32, RV32, WASM32.
     10 //===----------------------------------------------------------------------===//
     11 
     12 #ifndef INT_LIB_H
     13 #define INT_LIB_H
     14 
     15 #define COMPILER_RT_ABI
     16 
     17 // ARM AEABI runtime helpers explicitly use the AAPCS PCS regardless of the
     18 // translation unit default. kit's ARM target is always AAPCS, so this is
     19 // effectively a no-op, but the symbol must exist for the arm/ source files.
     20 #define AEABI_RTABI __attribute__((__pcs__("aapcs")))
     21 
     22 #define ALWAYS_INLINE __attribute__((always_inline))
     23 #define NOINLINE __attribute__((noinline))
     24 #define NORETURN __attribute__((noreturn))
     25 #define UNUSED __attribute__((unused))
     26 
     27 #include <float.h>
     28 #include <limits.h>
     29 #include <stdbool.h>
     30 #include <stdint.h>
     31 
     32 // ---- int_types.h (merged) ----
     33 #ifndef INT_TYPES_H
     34 #define INT_TYPES_H
     35 
     36 // (was int_endianness.h — only defined the markers below)
     37 #define _YUGA_LITTLE_ENDIAN 1
     38 #define _YUGA_BIG_ENDIAN 0
     39 
     40 #ifdef si_int
     41 #undef si_int
     42 #endif
     43 typedef int32_t si_int;
     44 typedef uint32_t su_int;
     45 #define clzsi __builtin_clz
     46 #define ctzsi __builtin_ctz
     47 
     48 typedef int64_t di_int;
     49 typedef uint64_t du_int;
     50 
     51 typedef union {
     52   di_int all;
     53   struct {
     54     su_int low;
     55     si_int high;
     56   } s;
     57 } dwords;
     58 
     59 typedef union {
     60   du_int all;
     61   struct {
     62     su_int low;
     63     su_int high;
     64   } s;
     65 } udwords;
     66 
     67 #define CRT_HAS_FLOATING_POINT 1
     68 
     69 typedef union {
     70   su_int u;
     71   float f;
     72 } float_bits;
     73 typedef union {
     74   udwords u;
     75   double f;
     76 } double_bits;
     77 typedef struct {
     78   udwords low;
     79   udwords high;
     80 } uqwords;
     81 
     82 #endif  // INT_TYPES_H
     83 #include "int_util.h"
     84 
     85 COMPILER_RT_ABI int __paritysi2(si_int a);
     86 COMPILER_RT_ABI int __paritydi2(di_int a);
     87 COMPILER_RT_ABI di_int __divdi3(di_int a, di_int b);
     88 COMPILER_RT_ABI si_int __divsi3(si_int a, si_int b);
     89 COMPILER_RT_ABI su_int __udivsi3(su_int n, su_int d);
     90 COMPILER_RT_ABI su_int __udivmodsi4(su_int a, su_int b, su_int* rem);
     91 COMPILER_RT_ABI du_int __udivmoddi4(du_int a, du_int b, du_int* rem);
     92 
     93 #endif  // INT_LIB_H