home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 8 Other / 08-Other.zip / bytewarp.zip / EMFLOAT.H < prev    next >
C/C++ Source or Header  |  1995-04-03  |  5KB  |  143 lines

  1.  
  2. /*
  3. ** emfloat.h
  4. ** Header for emfloat.c
  5. **
  6. ** BYTEmark (tm)
  7. ** BYTE Magazine's Native Mode benchmarks
  8. ** Rick Grehan, BYTE Magazine
  9. **
  10. ** Create:
  11. ** Revision: 3/95
  12. **
  13. ** DISCLAIMER
  14. ** The source, executable, and documentation files that comprise
  15. ** the BYTEmark benchmarks are made available on an "as is" basis.
  16. ** This means that we at BYTE Magazine have made every reasonable
  17. ** effort to verify that the there are no errors in the source and
  18. ** executable code.  We cannot, however, guarantee that the programs
  19. ** are error-free.  Consequently, McGraw-HIll and BYTE Magazine make
  20. ** no claims in regard to the fitness of the source code, executable
  21. ** code, and documentation of the BYTEmark.
  22. **  Furthermore, BYTE Magazine, McGraw-Hill, and all employees
  23. ** of McGraw-Hill cannot be held responsible for any damages resulting
  24. ** from the use of this code or the results obtained from using
  25. ** this code.
  26. */
  27.  
  28. #include <stdio.h>
  29.  
  30. /*
  31. ** DEFINES
  32. */
  33. #define u8 unsigned char
  34. #define u16 unsigned short
  35. #define u32 unsigned long
  36. #define uchar unsigned char
  37. #define ulong unsigned long
  38.  
  39. #define MAX_EXP 32767L
  40. #define MIN_EXP (-32767L)
  41.  
  42. #define IFPF_IS_ZERO 0
  43. #define IFPF_IS_SUBNORMAL 1
  44. #define IFPF_IS_NORMAL 2
  45. #define IFPF_IS_INFINITY 3
  46. #define IFPF_IS_NAN 4
  47. #define IFPF_TYPE_COUNT 5
  48.  
  49. #define ZERO_ZERO                       0
  50. #define ZERO_SUBNORMAL                  1
  51. #define ZERO_NORMAL                     2
  52. #define ZERO_INFINITY                   3
  53. #define ZERO_NAN                        4
  54.  
  55. #define SUBNORMAL_ZERO                  5
  56. #define SUBNORMAL_SUBNORMAL             6
  57. #define SUBNORMAL_NORMAL                7
  58. #define SUBNORMAL_INFINITY              8
  59. #define SUBNORMAL_NAN                   9
  60.  
  61. #define NORMAL_ZERO                     10
  62. #define NORMAL_SUBNORMAL                11
  63. #define NORMAL_NORMAL                   12
  64. #define NORMAL_INFINITY                 13
  65. #define NORMAL_NAN                      14
  66.  
  67. #define INFINITY_ZERO                   15
  68. #define INFINITY_SUBNORMAL              16
  69. #define INFINITY_NORMAL                 17
  70. #define INFINITY_INFINITY               18
  71. #define INFINITY_NAN                    19
  72.  
  73. #define NAN_ZERO                        20
  74. #define NAN_SUBNORMAL                   21
  75. #define NAN_NORMAL                      22
  76. #define NAN_INFINITY                    23
  77. #define NAN_NAN                         24
  78. #define OPERAND_ZERO                    0
  79. #define OPERAND_SUBNORMAL               1
  80. #define OPERAND_NORMAL                  2
  81. #define OPERAND_INFINITY                3
  82. #define OPERAND_NAN                     4
  83.  
  84. /*
  85. ** Following already defined in NMGLOBAL.H
  86. **
  87. #define INTERNAL_FPF_PRECISION 4
  88. */
  89.  
  90. /*
  91. ** TYPEDEFS
  92. */
  93.  
  94. typedef struct
  95. {
  96.         u8 type;        /* Indicates, NORMAL, SUBNORMAL, etc. */
  97.         u8 sign;        /* Mantissa sign */
  98.         short exp;      /* Signed exponent...no bias */
  99.         u16 mantissa[INTERNAL_FPF_PRECISION];
  100. } InternalFPF;
  101.  
  102. /*
  103. ** PROTOTYPES
  104. */
  105. void SetupCPUEmFloatArrays(InternalFPF *abase,
  106.         InternalFPF *bbase, InternalFPF *cbase, ulong arraysize);
  107. ulong DoEmFloatIteration(InternalFPF *abase,
  108.         InternalFPF *bbase, InternalFPF *cbase,
  109.         ulong arraysize, ulong loops);
  110. static void SetInternalFPFZero(InternalFPF *dest,
  111.                         uchar sign);
  112. static void SetInternalFPFInfinity(InternalFPF *dest,
  113.                         uchar sign);
  114. static void SetInternalFPFNaN(InternalFPF *dest);
  115. static int IsMantissaZero(u16 *mant);
  116. static void Add16Bits(u16 *carry,u16 *a,u16 b,u16 c);
  117. static void Sub16Bits(u16 *borrow,u16 *a,u16 b,u16 c);
  118. static void ShiftMantLeft1(u16 *carry,u16 *mantissa);
  119. static void ShiftMantRight1(u16 *carry,u16 *mantissa);
  120. static void StickyShiftRightMant(InternalFPF *ptr,int amount);
  121. static void normalize(InternalFPF *ptr);
  122. static void denormalize(InternalFPF *ptr,int minimum_exponent);
  123. void RoundInternalFPF(InternalFPF *ptr);
  124. static void choose_nan(InternalFPF *x,InternalFPF *y,InternalFPF *z,
  125.                 int intel_flag);
  126. static void AddSubInternalFPF(uchar operation,InternalFPF *x,
  127.                 InternalFPF *y,InternalFPF *z);
  128. static void MultiplyInternalFPF(InternalFPF *x,InternalFPF *y,
  129.                         InternalFPF *z);
  130. static void DivideInternalFPF(InternalFPF *x,InternalFPF *y, 
  131.                         InternalFPF *z);
  132. static void LongToInternalFPF(long mylong,
  133.                 InternalFPF *dest);
  134. static int InternalFPFToString(char *dest,
  135.                 InternalFPF *src);
  136.  
  137. /*
  138. ** EXTERNALS
  139. */
  140. extern ulong StartStopwatch();
  141. extern ulong StopStopwatch(ulong elapsed);
  142. extern long randwc(long num);
  143.