Subversion Repositories pentevo

Rev

Blame | Last modification | View Log | Download | RSS feed

  1. #ifndef _AS_FLOAT_H
  2. #define _AS_FLOAT_H
  3. /* as_float.h */
  4. /*****************************************************************************/
  5. /* SPDX-License-Identifier: GPL-2.0-only OR GPL-3.0-only                     */
  6. /*                                                                           */
  7. /* AS                                                                        */
  8. /*                                                                           */
  9. /* Internal Floating Point Handling                                          */
  10. /*                                                                           */
  11. /*****************************************************************************/
  12.  
  13. #include <stdio.h>
  14. #include "datatypes.h"
  15.  
  16. typedef enum
  17. {
  18.   AS_FP_NORMAL,
  19.   AS_FP_SUBNORMAL,
  20.   AS_FP_NAN,
  21.   AS_FP_INFINITE
  22. } as_float_class_t;
  23.  
  24. #if 0
  25. typedef as_uint16_t as_float_mant_word_t;
  26. #define AS_FLOAT_MANT_WORD_BITS 16
  27. #endif
  28.  
  29. #if 1
  30. typedef as_uint32_t as_float_mant_word_t;
  31. #define AS_FLOAT_MANT_WORD_BITS 32
  32. #endif
  33.  
  34. #if 0
  35. typedef as_uint64_t as_float_mant_word_t;
  36. #define AS_FLOAT_MANT_WORD_BITS 64
  37. #endif
  38.  
  39. #define AS_FLOAT_MANT_WORD_BITS_M1 (AS_FLOAT_MANT_WORD_BITS - 1)
  40. #define AS_FLOAT_NUM_WORDS(num_bits) (((num_bits) + AS_FLOAT_MANT_WORD_BITS - 1) / AS_FLOAT_MANT_WORD_BITS)
  41. typedef as_float_mant_word_t as_float_mant_t[192 / AS_FLOAT_MANT_WORD_BITS];
  42.  
  43.  
  44. typedef enum
  45. {
  46.   e_round_none,  /* no bits lost by rounding */
  47.   e_round_up,    /* rounded up, bits lost */
  48.   e_round_down   /* rounded down, bits lost */
  49. } as_float_round_t;
  50.  
  51. typedef struct as_float_dissect
  52. {
  53.   as_float_class_t fp_class;
  54.   /* 1 (negative) or 0 (positive) */
  55.   Boolean negative;
  56.   /* power-of-2 of exponent */
  57.   Integer exponent;
  58.   /* left-aligned mantissa, range [1,2), explicit leading one: */
  59.   as_float_mant_t mantissa;
  60.   unsigned mantissa_bits;
  61. } as_float_dissect_t;
  62.  
  63. extern void as_float_zero(as_float_dissect_t *p_dest);
  64.  
  65. extern void as_float_append_mantissa_bits(as_float_dissect_t *p_dest, LongWord new_bits, unsigned new_num_bits);
  66.  
  67. extern void as_float_remove_mantissa_bits(as_float_dissect_t *p_dest, unsigned remove_num_bits);
  68.  
  69. extern Boolean as_float_get_mantissa_bit(const as_float_mant_t p_mant, unsigned num_bits, unsigned bit_pos);
  70.  
  71. extern as_float_mant_word_t as_float_mantissa_add_bit(as_float_mant_t p_sum, const as_float_mant_t p_add, unsigned add_bit_pos, unsigned num_bits);
  72.  
  73. extern as_float_mant_word_t as_float_mantissa_shift_right(as_float_mant_t p_mantissa, as_float_mant_word_t shiftin_bit, unsigned num_bits);
  74. extern as_float_mant_word_t as_float_mantissa_shift_left(as_float_mant_t p_mantissa, as_float_mant_word_t shiftin_bit, unsigned num_bits);
  75.  
  76. extern Boolean as_float_mantissa_is_zero_from(const as_float_dissect_t *p_num, unsigned start_bit);
  77. #define as_float_mantissa_is_zero(p_num) as_float_mantissa_is_zero_from(p_num, 0)
  78.  
  79. extern Boolean as_float_mantissa_is_allones_from(const as_float_dissect_t *p_num, unsigned start_bit);
  80. #define as_float_mantissa_is_allones(p_num) as_float_mantissa_is_allones_from(p_num, 0)
  81.  
  82. extern LongWord as_float_mantissa_extract(const as_float_dissect_t *p_num, unsigned start_bit, unsigned num_bits);
  83.  
  84. extern void as_float_mantissa_twos_complement(as_float_dissect_t *p_num);
  85.  
  86. extern void as_float_dissect(as_float_dissect_t *p_dest, as_float_t num);
  87.  
  88. extern as_float_round_t as_float_round(as_float_dissect_t *p_dest, unsigned target_bits);
  89.  
  90. extern void as_float_dump_mantissa(FILE *p_dest, const as_float_mant_t p_mantissa, unsigned mantissa_bits);
  91. extern void as_float_dump(FILE *p_dest, const char *p_name, const as_float_dissect_t *p_float);
  92.  
  93. #endif /* _AS_FLOAT_H */
  94.