^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1) /* SPDX-License-Identifier: GPL-2.0 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3) -------------------------------------------------------------------------------
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4) The macro `BITS64' can be defined to indicate that 64-bit integer types are
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5) supported by the compiler.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6) -------------------------------------------------------------------------------
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8) #define BITS64
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11) -------------------------------------------------------------------------------
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12) Each of the following `typedef's defines the most convenient type that holds
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13) integers of at least as many bits as specified. For example, `uint8' should
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14) be the most convenient type that can hold unsigned integers of as many as
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15) 8 bits. The `flag' type must be able to hold either a 0 or 1. For most
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16) implementations of C, `flag', `uint8', and `int8' should all be `typedef'ed
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17) to the same as `int'.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18) -------------------------------------------------------------------------------
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20) typedef char flag;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 21) typedef unsigned char uint8;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 22) typedef signed char int8;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 23) typedef int uint16;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 24) typedef int int16;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 25) typedef unsigned int uint32;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 26) typedef signed int int32;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 27) #ifdef BITS64
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 28) typedef unsigned long long int bits64;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 29) typedef signed long long int sbits64;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 30) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 31)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 32) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 33) -------------------------------------------------------------------------------
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 34) Each of the following `typedef's defines a type that holds integers
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 35) of _exactly_ the number of bits specified. For instance, for most
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 36) implementation of C, `bits16' and `sbits16' should be `typedef'ed to
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 37) `unsigned short int' and `signed short int' (or `short int'), respectively.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 38) -------------------------------------------------------------------------------
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 39) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 40) typedef unsigned char bits8;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 41) typedef signed char sbits8;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 42) typedef unsigned short int bits16;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 43) typedef signed short int sbits16;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 44) typedef unsigned int bits32;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 45) typedef signed int sbits32;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 46) #ifdef BITS64
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 47) typedef unsigned long long int uint64;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 48) typedef signed long long int int64;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 49) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 50)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 51) #ifdef BITS64
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 52) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 53) -------------------------------------------------------------------------------
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 54) The `LIT64' macro takes as its argument a textual integer literal and if
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 55) necessary ``marks'' the literal as having a 64-bit integer type. For
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 56) example, the Gnu C Compiler (`gcc') requires that 64-bit literals be
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 57) appended with the letters `LL' standing for `long long', which is `gcc's
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 58) name for the 64-bit integer type. Some compilers may allow `LIT64' to be
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 59) defined as the identity macro: `#define LIT64( a ) a'.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 60) -------------------------------------------------------------------------------
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 61) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 62) #define LIT64( a ) a##LL
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 63) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 64)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 65) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 66) -------------------------------------------------------------------------------
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 67) The macro `INLINE' can be used before functions that should be inlined. If
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 68) a compiler does not support explicit inlining, this macro should be defined
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 69) to be `static'.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 70) -------------------------------------------------------------------------------
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 71) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 72) #define INLINE static inline
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 73)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 74)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 75) /* For use as a GCC soft-float library we need some special function names. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 76)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 77) #ifdef __LIBFLOAT__
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 78)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 79) /* Some 32-bit ops can be mapped straight across by just changing the name. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 80) #define float32_add __addsf3
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 81) #define float32_sub __subsf3
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 82) #define float32_mul __mulsf3
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 83) #define float32_div __divsf3
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 84) #define int32_to_float32 __floatsisf
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 85) #define float32_to_int32_round_to_zero __fixsfsi
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 86) #define float32_to_uint32_round_to_zero __fixunssfsi
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 87)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 88) /* These ones go through the glue code. To avoid namespace pollution
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 89) we rename the internal functions too. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 90) #define float32_eq ___float32_eq
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 91) #define float32_le ___float32_le
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 92) #define float32_lt ___float32_lt
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 93)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 94) /* All the 64-bit ops have to go through the glue, so we pull the same
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 95) trick. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 96) #define float64_add ___float64_add
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 97) #define float64_sub ___float64_sub
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 98) #define float64_mul ___float64_mul
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 99) #define float64_div ___float64_div
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 100) #define int32_to_float64 ___int32_to_float64
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 101) #define float64_to_int32_round_to_zero ___float64_to_int32_round_to_zero
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 102) #define float64_to_uint32_round_to_zero ___float64_to_uint32_round_to_zero
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 103) #define float64_to_float32 ___float64_to_float32
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 104) #define float32_to_float64 ___float32_to_float64
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 105) #define float64_eq ___float64_eq
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 106) #define float64_le ___float64_le
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 107) #define float64_lt ___float64_lt
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 108)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 109) #if 0
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 110) #define float64_add __adddf3
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 111) #define float64_sub __subdf3
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 112) #define float64_mul __muldf3
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 113) #define float64_div __divdf3
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 114) #define int32_to_float64 __floatsidf
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 115) #define float64_to_int32_round_to_zero __fixdfsi
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 116) #define float64_to_uint32_round_to_zero __fixunsdfsi
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 117) #define float64_to_float32 __truncdfsf2
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 118) #define float32_to_float64 __extendsfdf2
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 119) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 120)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 121) #endif