Changeset d9be488 in mainline for uspace/lib/softfloat/sftypes.h


Ignore:
Timestamp:
2014-03-01T23:03:21Z (10 years ago)
Author:
Martin Decky <martin@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
071fefec
Parents:
75baf6e
Message:

refactor floating point support

  • implement IA-32 and AMD64 specific trunc(), sin(), cos() using x87
  • implement generic trunc() (generic sin(), cos() still missing)
  • trunc(), sin(), cos() tests
File:
1 edited

Legend:

Unmodified
Added
Removed
  • uspace/lib/softfloat/sftypes.h

    r75baf6e rd9be488  
    3434 */
    3535
    36 #ifndef __SFTYPES_H__
    37 #define __SFTYPES_H__
    38 
    39 #include <byteorder.h>
    40 #include <stdint.h>
    41 
    42 /*
    43  * For recognizing NaNs or infinity use specialized comparison
    44  * functions, comparing with these constants is not sufficient.
    45  */
    46 
    47 #define FLOAT32_NAN     UINT32_C(0x7FC00001)
    48 #define FLOAT32_SIGNAN  UINT32_C(0x7F800001)
    49 #define FLOAT32_INF     UINT32_C(0x7F800000)
    50 
    51 #define FLOAT64_NAN     UINT64_C(0x7FF8000000000001)
    52 #define FLOAT64_SIGNAN  UINT64_C(0x7FF0000000000001)
    53 #define FLOAT64_INF     UINT64_C(0x7FF0000000000000)
    54 
    55 #define FLOAT96_NAN_HI     UINT64_C(0x7FFF80000000)
    56 #define FLOAT96_NAN_LO     UINT32_C(0x00010000)
    57 #define FLOAT96_SIGNAN_HI  UINT64_C(0x7FFF00000000)
    58 #define FLOAT96_SIGNAN_LO  UINT32_C(0x00010000)
    59 
    60 #define FLOAT128_NAN_HI     UINT64_C(0x7FFF800000000000)
    61 #define FLOAT128_NAN_LO     UINT64_C(0x0000000000000001)
    62 #define FLOAT128_SIGNAN_HI  UINT64_C(0x7FFF000000000000)
    63 #define FLOAT128_SIGNAN_LO  UINT64_C(0x0000000000000001)
    64 #define FLOAT128_INF_HI     UINT64_C(0x7FFF000000000000)
    65 #define FLOAT128_INF_LO     UINT64_C(0x0000000000000000)
    66 
    67 #define FLOAT32_FRACTION_SIZE   23
    68 #define FLOAT64_FRACTION_SIZE   52
    69 #define FLOAT96_FRACTION_SIZE   64
    70 #define FLOAT128_FRACTION_SIZE  112
    71 #define FLOAT128_FRAC_HI_SIZE   48
    72 #define FLOAT128_FRAC_LO_SIZE   64
    73 
    74 #define FLOAT32_HIDDEN_BIT_MASK      UINT32_C(0x800000)
    75 #define FLOAT64_HIDDEN_BIT_MASK      UINT64_C(0x10000000000000)
    76 #define FLOAT128_HIDDEN_BIT_MASK_HI  UINT64_C(0x1000000000000)
    77 #define FLOAT128_HIDDEN_BIT_MASK_LO  UINT64_C(0x0000000000000000)
    78 
    79 #define FLOAT32_MAX_EXPONENT   0xFF
    80 #define FLOAT64_MAX_EXPONENT   0x7FF
    81 #define FLOAT96_MAX_EXPONENT   0x7FFF
    82 #define FLOAT128_MAX_EXPONENT  0x7FFF
    83 
    84 #define FLOAT32_BIAS   0x7F
    85 #define FLOAT64_BIAS   0x3FF
    86 #define FLOAT96_BIAS   0x3FFF
    87 #define FLOAT128_BIAS  0x3FFF
    88 
    89 #if defined(__BE__)
    90 
    91 typedef union {
    92         uint32_t bin;
    93        
    94         struct {
    95                 uint32_t sign : 1;
    96                 uint32_t exp : 8;
    97                 uint32_t fraction : 23;
    98         } parts __attribute__((packed));
    99 } float32;
    100 
    101 typedef union {
    102         uint64_t bin;
    103        
    104         struct {
    105                 uint64_t sign : 1;
    106                 uint64_t exp : 11;
    107                 uint64_t fraction : 52;
    108         } parts __attribute__((packed));
    109 } float64;
    110 
    111 typedef union {
    112         struct {
    113                 uint64_t hi;
    114                 uint32_t lo;
    115         } bin __attribute__((packed));
    116        
    117         struct {
    118                 uint64_t padding : 16;
    119                 uint64_t sign : 1;
    120                 uint64_t exp : 15;
    121                 uint64_t fraction : 64;
    122         } parts __attribute__((packed));
    123 } float96;
    124 
    125 typedef union {
    126         struct {
    127                 uint64_t hi;
    128                 uint64_t lo;
    129         } bin __attribute__((packed));
    130        
    131         struct {
    132                 uint64_t sign : 1;
    133                 uint64_t exp : 15;
    134                 uint64_t frac_hi : 48;
    135                 uint64_t frac_lo : 64;
    136         } parts __attribute__((packed));
    137 } float128;
    138 
    139 #elif defined(__LE__)
    140 
    141 typedef union {
    142         uint32_t bin;
    143        
    144         struct {
    145                 uint32_t fraction : 23;
    146                 uint32_t exp : 8;
    147                 uint32_t sign : 1;
    148         } parts __attribute__((packed));
    149 } float32;
    150 
    151 typedef union {
    152         uint64_t bin;
    153        
    154         struct {
    155                 uint64_t fraction : 52;
    156                 uint64_t exp : 11;
    157                 uint64_t sign : 1;
    158         } parts __attribute__((packed));
    159 } float64;
    160 
    161 typedef union {
    162         struct {
    163                 uint32_t lo;
    164                 uint64_t hi;
    165         } bin __attribute__((packed));
    166        
    167         struct {
    168                 uint64_t fraction : 64;
    169                 uint64_t exp : 15;
    170                 uint64_t sign : 1;
    171                 uint64_t padding : 16;
    172         } parts __attribute__((packed));
    173 } float96;
    174 
    175 typedef union {
    176         struct {
    177                 uint64_t lo;
    178                 uint64_t hi;
    179         } bin __attribute__((packed));
    180        
    181         struct {
    182                 uint64_t frac_lo : 64;
    183                 uint64_t frac_hi : 48;
    184                 uint64_t exp : 15;
    185                 uint64_t sign : 1;
    186         } parts __attribute__((packed));
    187 } float128;
    188 
    189 #else
    190         #error Unknown endianess
    191 #endif
    192 
    193 typedef union {
    194         float val;
    195        
    196 #if defined(FLOAT_SIZE_32)
    197         float32 data;
    198 #elif defined(FLOAT_SIZE_64)
    199         float64 data;
    200 #elif defined(FLOAT_SIZE_96)
    201         float96 data;
    202 #elif defined(FLOAT_SIZE_128)
    203         float128 data;
    204 #else
    205         #error Unsupported float size
    206 #endif
    207 } float_t;
    208 
    209 typedef union {
    210         double val;
    211        
    212 #if defined(DOUBLE_SIZE_32)
    213         float32 data;
    214 #elif defined(DOUBLE_SIZE_64)
    215         float64 data;
    216 #elif defined(DOUBLE_SIZE_96)
    217         float96 data;
    218 #elif defined(DOUBLE_SIZE_128)
    219         float128 data;
    220 #else
    221         #error Unsupported double size
    222 #endif
    223 } double_t;
    224 
    225 typedef union {
    226         long double val;
    227        
    228 #if defined(LONG_DOUBLE_SIZE_32)
    229         float32 data;
    230 #elif defined(LONG_DOUBLE_SIZE_64)
    231         float64 data;
    232 #elif defined(LONG_DOUBLE_SIZE_96)
    233         float96 data;
    234 #elif defined(LONG_DOUBLE_SIZE_128)
    235         float128 data;
    236 #else
    237         #error Unsupported long double size
    238 #endif
    239 } long_double_t;
    240 
     36#ifndef SOFTFLOAT_SFTYPES_H__
     37#define SOFTFLOAT_SFTYPES_H__
     38
     39#include <mathtypes.h>
    24140
    24241#if defined(INT_SIZE_8)
Note: See TracChangeset for help on using the changeset viewer.