Changeset d9be488 in mainline


Ignore:
Timestamp:
2014-03-01T23:03:21Z (11 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
Files:
33 added
1 deleted
15 edited
3 moved

Legend:

Unmodified
Added
Removed
  • HelenOS.config

    r75baf6e rd9be488  
    397397! [PLATFORM=ia32|PLATFORM=amd64|PLATFORM=ia64|PLATFORM=sparc64] CONFIG_FPU (y)
    398398
    399 ## armv7 made fpu hardware compulsory
     399## ARMv7 made FPU hardware compulsory
    400400% FPU support
    401401! [PLATFORM=arm32&PROCESSOR_ARCH=armv7_a] CONFIG_FPU (y)
  • uspace/Makefile.common

    r75baf6e rd9be488  
    4444#   EXTRA_CLEAN        additional cleanup targets
    4545#
     46#   MATH               set to 'y' to use the math library
    4647#   POSIX_COMPAT       set to 'y' to use POSIX compatibility layer
    47 #   NEEDS_MATH         set to 'y' to add implementation of mathematical functions
    4848#
    4949# Optionally, for a binary:
     
    8787endif
    8888
    89 ifeq ($(CONFIG_BUILD_SHARED_LIBS), y)
     89ifeq ($(CONFIG_BUILD_SHARED_LIBS),y)
    9090        ifneq ($(SLIBRARY),)
    9191                LARCHIVE = $(LIBRARY).la
     
    110110LIBSOFTFLOAT_PREFIX = $(LIB_PREFIX)/softfloat
    111111LIBSOFTINT_PREFIX = $(LIB_PREFIX)/softint
     112
    112113LIBMATH_PREFIX = $(LIB_PREFIX)/math
     114LIBMATH_INCLUDES_FLAGS = \
     115        -I$(LIBMATH_PREFIX)/include \
     116        -I$(LIBMATH_PREFIX)/arch/$(UARCH)/include
    113117
    114118LIBPOSIX_PREFIX = $(LIB_PREFIX)/posix
     
    155159                STATIC_BUILD = y
    156160        else
    157                 ifeq ($(CONFIG_USE_SHARED_LIBS), y)
     161                ifeq ($(CONFIG_USE_SHARED_LIBS),y)
    158162                        STATIC_BUILD = n
    159163                else
     
    172176        BASE_LIBS = $(LIBC_PREFIX)/libc.a $(LIBSOFTINT_PREFIX)/libsoftint.a
    173177        LINKER_SCRIPT ?= $(LIBC_PREFIX)/arch/$(UARCH)/_link.ld
     178        ifeq ($(MATH),y)
     179                BASE_LIBS += $(LIBMATH_PREFIX)/libmath.a
     180        endif
    174181else
    175182        BASE_LIBS = $(LIBC_PREFIX)/libc.so0 $(LIBSOFTINT_PREFIX)/libsofti.so0
    176183        LFLAGS = -Bdynamic
    177184        LINKER_SCRIPT ?= $(LIBC_PREFIX)/arch/$(UARCH)/_link-dlexe.ld
     185        ifeq ($(MATH),y)
     186                BASE_LIBS += $(LIBMATH_PREFIX)/libmath.so0
     187        endif
     188endif
     189
     190ifeq ($(MATH),y)
     191        INCLUDES_FLAGS = $(LIBC_INCLUDES_FLAGS) $(LIBMATH_INCLUDES_FLAGS)
     192else
     193        INCLUDES_FLAGS = $(LIBC_INCLUDES_FLAGS)
    178194endif
    179195
     
    194210        find . -name '*.lo' -follow -exec rm \{\} \;
    195211
    196 GCC_CFLAGS = $(LIBC_INCLUDES_FLAGS) -O$(OPTIMIZATION) -imacros $(CONFIG_HEADER) \
     212GCC_CFLAGS = $(INCLUDES_FLAGS) -O$(OPTIMIZATION) -imacros $(CONFIG_HEADER) \
    197213        -fexec-charset=UTF-8 -fwide-exec-charset=UTF-32$(ENDIANESS) \
    198214        -finput-charset=UTF-8 -ffreestanding -fno-builtin -nostdlib -nostdinc \
     
    201217        -pipe -ggdb -D__$(ENDIANESS)__
    202218
    203 ICC_CFLAGS = $(LIBC_INCLUDES_FLAGS) -O$(OPTIMIZATION) -imacros $(CONFIG_HEADER) \
     219ICC_CFLAGS = $(INCLUDES_FLAGS) -O$(OPTIMIZATION) -imacros $(CONFIG_HEADER) \
    204220        -fexec-charset=UTF-8 -fwide-exec-charset=UTF-32$(ENDIANESS) \
    205221        -finput-charset=UTF-8 -ffreestanding -fno-builtin -nostdlib -nostdinc \
     
    234250# Prepare for POSIX before including platform specific stuff
    235251ifeq ($(POSIX_COMPAT),y)
    236         CFLAGS = -I$(LIBPOSIX_PREFIX)/include/posix  -I$(LIBPOSIX_PREFIX)/include/
     252        CFLAGS = -I$(LIBPOSIX_PREFIX)/include/posix -I$(LIBPOSIX_PREFIX)/include/
    237253        BASE_LIBS = $(LIBPOSIX_PREFIX)/libposixaslibc.a $(LIBPOSIX_PREFIX)/libc4posix.a $(LIBSOFTINT_PREFIX)/libsoftint.a
    238 endif
    239 
    240 # Do we need math?
    241 ifeq ($(NEEDS_MATH),y)
    242         BASE_LIBS += $(LIBMATH_PREFIX)/libmath.a
    243254endif
    244255
  • uspace/app/tester/Makefile

    r75baf6e rd9be488  
    4141
    4242BINARY = tester
     43MATH = y
    4344
    4445SOURCES = \
     
    6263        fault/fault3.c \
    6364        float/float1.c \
     65        float/float2.c \
    6466        float/softfloat1.c \
    6567        vfs/vfs1.c \
  • uspace/app/tester/tester.c

    r75baf6e rd9be488  
    6464#include "fault/fault3.def"
    6565#include "float/float1.def"
     66#include "float/float2.def"
    6667#include "float/softfloat1.def"
    6768#include "vfs/vfs1.def"
  • uspace/app/tester/tester.h

    r75baf6e rd9be488  
    9797extern const char *test_fault3(void);
    9898extern const char *test_float1(void);
     99extern const char *test_float2(void);
    99100extern const char *test_softfloat1(void);
    100101extern const char *test_vfs1(void);
  • uspace/app/vdemo/Makefile

    r75baf6e rd9be488  
    4141
    4242BINARY = vdemo
     43MATH = y
    4344
    4445SOURCES = \
  • uspace/app/viewer/Makefile

    r75baf6e rd9be488  
    4141
    4242BINARY = viewer
     43MATH = y
    4344
    4445SOURCES = \
  • uspace/app/vlaunch/Makefile

    r75baf6e rd9be488  
    4141
    4242BINARY = vlaunch
     43MATH = y
    4344
    4445SOURCES = \
  • uspace/app/vterm/Makefile

    r75baf6e rd9be488  
    4343
    4444BINARY = vterm
     45MATH = y
    4546
    4647SOURCES = \
  • uspace/lib/math/Makefile

    r75baf6e rd9be488  
    2828
    2929USPACE_PREFIX = ../..
     30ROOT_PATH = $(USPACE_PREFIX)/..
     31
     32CONFIG_MAKEFILE = $(ROOT_PATH)/Makefile.config
     33
    3034LIBRARY = libmath
     35SLIBRARY = libmath.so.0.0
     36LSONAME = libmath.so0
     37MATH = y
     38
     39-include $(CONFIG_MAKEFILE)
     40-include arch/$(UARCH)/Makefile.inc
     41
     42GENERIC_SOURCES = \
     43        generic/trunc.c
    3144
    3245SOURCES = \
    33         src/dummy.c
     46        $(GENERIC_SOURCES) \
     47        $(ARCH_SOURCES)
    3448
    3549include $(USPACE_PREFIX)/Makefile.common
  • uspace/lib/math/arch/amd64/include/libarch/math.h

    r75baf6e rd9be488  
    11/*
    2  * Copyright (c) 2011 Petr Koupy
     2 * Copyright (c) 2014 Martin Decky
    33 * All rights reserved.
    44 *
     
    2727 */
    2828
    29 /** @addtogroup libposix
     29/** @addtogroup libmathamd64
    3030 * @{
    3131 */
    32 /** @file Mathematical operations.
    33  *
    34  * The implementation is provided by a separate library to allow
    35  * switching of the implementations.
     32/** @file
    3633 */
    3734
    38 #ifndef LIBC_MATH_H_
    39 #define LIBC_MATH_H_
     35#ifndef LIBMATH_amd64_MATH_H_
     36#define LIBMATH_amd64_MATH_H_
    4037
    41 #ifdef __GNUC__
    42         #define HUGE_VAL (__builtin_huge_val())
    43 #endif
    44 
    45 extern double ldexp(double, int);
    46 extern double frexp(double, int *);
    47 
    48 extern double fabs(double);
    49 extern double floor(double);
    50 extern double ceil(double);
    51 extern double modf(double, double *);
    52 extern double fmod(double, double);
    53 extern double pow(double, double);
    54 extern double exp(double);
    55 extern double expm1(double);
    56 extern double sqrt(double);
    57 extern double log(double);
    58 extern double log10(double);
    5938extern double sin(double);
    60 extern double sinh(double);
    61 extern double asin(double);
    62 extern double asinh(double);
    6339extern double cos(double);
    64 extern double cosh(double);
    65 extern double acos(double);
    66 extern double acosh(double);
    67 extern double tan(double);
    68 extern double tanh(double);
    69 extern double atan(double);
    70 extern double atanh(double);
    71 extern double atan2(double, double);
    72 
    73 double copysign(double, double);
     40extern double trunc(double);
    7441
    7542#endif
  • uspace/lib/math/include/math.h

    r75baf6e rd9be488  
    11/*
    2  * Copyright (c) 2005 Josef Cejka
     2 * Copyright (c) 2011 Petr Koupy
    33 * All rights reserved.
    44 *
     
    2727 */
    2828
    29 /** @addtogroup softfloat
     29/** @addtogroup libmath
    3030 * @{
    3131 */
    32 /** @file Other functions (power, complex).
     32/** @file Mathematical operations.
    3333 */
    3434
    35 #ifndef __OTHER_H__
    36 #define __OTHER_H__
     35#ifndef LIBMATH_MATH_H_
     36#define LIBMATH_MATH_H_
     37
     38#include <libarch/math.h>
    3739
    3840#endif
  • uspace/lib/math/include/trunc.h

    r75baf6e rd9be488  
    11/*
    2  * Copyright (c) 2005 Josef Cejka
     2 * Copyright (c) 2014 Martin Decky
    33 * All rights reserved.
    44 *
     
    2727 */
    2828
    29 /** @addtogroup softfloat
     29/** @addtogroup libc
    3030 * @{
    3131 */
    32 /** @file Other functions (power, complex).
     32/** @file
    3333 */
    3434
     35#ifndef LIBMATH_TRUNC_H_
     36#define LIBMATH_TRUNC_H_
     37
     38#include <mathtypes.h>
     39
     40extern float64 trunc_float64(float64);
     41
     42#endif
    3543
    3644/** @}
  • uspace/lib/softfloat/Makefile

    r75baf6e rd9be488  
    3030USPACE_PREFIX = ../..
    3131LIBRARY = libsoftfloat
     32MATH = y
    3233
    3334SOURCES = \
     
    3940        mul.c \
    4041        comparison.c \
    41         conversion.c \
    42         other.c
     42        conversion.c
    4343
    4444include $(USPACE_PREFIX)/Makefile.common
  • 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)
  • uspace/lib/softfloat/softfloat.c

    r75baf6e rd9be488  
    4444#include "conversion.h"
    4545#include "comparison.h"
    46 #include "other.h"
    4746
    4847/* Arithmetic functions */
  • uspace/lib/softrend/Makefile

    r75baf6e rd9be488  
    3131SLIBRARY = libsoftrend.so.0.0
    3232LSONAME = libsoftrend.so0
     33MATH = y
    3334
    3435SOURCES = \
  • uspace/srv/hid/compositor/Makefile

    r75baf6e rd9be488  
    2828
    2929USPACE_PREFIX = ../../..
     30
    3031LIBS = \
    3132        $(LIBDRAW_PREFIX)/libdraw.a \
     
    4041
    4142BINARY = compositor
     43MATH = y
    4244
    4345SOURCES = \
Note: See TracChangeset for help on using the changeset viewer.