softfloat.h 2.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495
  1. /*----------------------------------------------------------------------------*/
  2. /**
  3. * This confidential and proprietary software may be used only as
  4. * authorised by a licensing agreement from ARM Limited
  5. * (C) COPYRIGHT 2011-2012 ARM Limited
  6. * ALL RIGHTS RESERVED
  7. *
  8. * The entire notice above must be reproduced on all authorised
  9. * copies and copies may only be made to the extent permitted
  10. * by a licensing agreement from ARM Limited.
  11. *
  12. * @brief Soft IEEE-754 floating point library.
  13. */
  14. /*----------------------------------------------------------------------------*/
  15. #ifndef SOFTFLOAT_H_INCLUDED
  16. #define SOFTFLOAT_H_INCLUDED
  17. #if defined __cplusplus
  18. extern "C"
  19. {
  20. #endif
  21. #if defined __cplusplus && !defined(_MSC_VER)
  22. /* if compiling as C++, we need to define these macros in order to obtain all the macros in stdint.h . */
  23. #define __STDC_LIMIT_MACROS
  24. #define __STDC_CONSTANT_MACROS
  25. #include <stdint.h>
  26. #else
  27. typedef unsigned char uint8_t;
  28. typedef signed char int8_t;
  29. typedef unsigned short uint16_t;
  30. typedef signed short int16_t;
  31. typedef unsigned int uint32_t;
  32. typedef signed int int32_t;
  33. #endif
  34. uint32_t clz32(uint32_t p);
  35. /* targets that don't have UINT32_C probably don't have the rest of C99s stdint.h */
  36. #ifndef UINT32_C
  37. #define PASTE(a) a
  38. #define UINT64_C(a) PASTE(a##ULL)
  39. #define UINT32_C(a) PASTE(a##U)
  40. #define INT64_C(a) PASTE(a##LL)
  41. #define INT32_C(a) a
  42. #define PRIX32 "X"
  43. #define PRId32 "d"
  44. #define PRIu32 "u"
  45. #define PRIX64 "LX"
  46. #define PRId64 "Ld"
  47. #define PRIu64 "Lu"
  48. #endif
  49. /* sized soft-float types. These are mapped to the sized integer types of C99, instead of C's
  50. floating-point types; this is because the library needs to maintain exact, bit-level control on all
  51. operations on these data types. */
  52. typedef uint16_t sf16;
  53. typedef uint32_t sf32;
  54. /* the five rounding modes that IEEE-754r defines */
  55. typedef enum
  56. {
  57. SF_UP = 0, /* round towards positive infinity */
  58. SF_DOWN = 1, /* round towards negative infinity */
  59. SF_TOZERO = 2, /* round towards zero */
  60. SF_NEARESTEVEN = 3, /* round toward nearest value; if mid-between, round to even value */
  61. SF_NEARESTAWAY = 4 /* round toward nearest value; if mid-between, round away from zero */
  62. } roundmode;
  63. /* narrowing float->float conversions */
  64. sf16 sf32_to_sf16(sf32, roundmode);
  65. /* widening float->float conversions */
  66. sf32 sf16_to_sf32(sf16);
  67. sf16 float_to_sf16(float, roundmode);
  68. float sf16_to_float(sf16);
  69. #if defined __cplusplus
  70. }
  71. #endif
  72. #endif