Subversion Repositories Kolibri OS

Rev

Blame | Last modification | View Log | RSS feed

  1. #ifndef _MATH_64_H_
  2. #define _MATH_64_H_
  3.  
  4. #include "types.h"
  5.  
  6. #define COMPILER_SUPPORTS_LONG_LONG             //undefine if compiler doe snot uspport long long
  7.  
  8.  
  9. #ifdef COMPILER_SUPPORTS_LONG_LONG
  10.  
  11. typedef unsigned long long UInt64;
  12.  
  13. static inline UInt64 u64_from_halves(UInt32 hi, UInt32 lo)      { return (((UInt64)hi) << 32ULL) | ((UInt64)lo);                }
  14. static inline UInt64 u64_32_to_64(UInt32 v)                     { return (UInt64)v;                                             }
  15. static inline UInt32 u64_64_to_32(UInt64 v)                     { return (UInt32)v;                                             }
  16. static inline UInt32 u64_get_hi(UInt64 v)                       { return (UInt32)(v >> 32ULL);                                  }
  17. static inline UInt64 u64_add(UInt64 a, UInt64 b)                { return a + b;                                                 }
  18. static inline UInt64 u64_add32(UInt64 a, UInt32 b)              { return a + (UInt64)b;                                         }
  19. static inline UInt64 u64_umul3232(UInt32 a, UInt32 b)           { return ((UInt64)a) * ((UInt64)b);                             }       //sad but true: gcc has no u32xu32->64 multiply
  20. static inline UInt64 u64_smul3232(Int32 a, Int32 b)             { return ((signed long long)a) * ((signed long long)b);         }       //sad but true: gcc has no s32xs32->64 multiply
  21. static inline UInt64 u64_shr(UInt64 a, unsigned bits)           { return a >> (UInt64)bits;                                     }
  22. static inline UInt64 u64_shl(UInt64 a, unsigned bits)           { return a << (UInt64)bits;                                     }
  23. static inline UInt64 u64_xtnd32(UInt64 a)                       { if(a & 0x80000000UL) a |= (((UInt64)-1) << 32ULL); return a;  }
  24. static inline Boolean u64_isZero(UInt64 a)                      { return a == 0;                                                }
  25. static inline UInt64 u64_inc(UInt64 a)                          { return a + 1ULL;                                              }
  26. static inline UInt64 u64_and(UInt64 a, UInt64 b)                { return a & b;                                                 }
  27. static inline UInt64 u64_zero(void)                             { return 0;                                                     }
  28. static inline UInt64 u64_sub(UInt64 a, UInt64 b)                { return a - b;                                                 }
  29.  
  30. #else
  31.  
  32. typedef struct{
  33.        
  34.         UInt32 hi, lo;
  35. }UInt64;
  36.  
  37.  
  38. UInt64 u64_from_halves(UInt32 hi, UInt32 lo);
  39. UInt64 u64_32_to_64(UInt32 v);
  40. UInt32 u64_64_to_32(UInt64 v);
  41. UInt32 u64_get_hi(UInt64 v);
  42. UInt64 u64_add(UInt64 a, UInt64 b);
  43. UInt64 u64_umul3232(UInt32 a, UInt32 b);
  44. UInt64 u64_smul3232(Int32 a, Int32 b);
  45. UInt64 u64_shr(UInt64 a, unsigned bits);
  46. UInt64 u64_shl(UInt64 a, unsigned bits);
  47. UInt64 u64_add32(UInt64 a, UInt32 b);
  48. UInt64 u64_xtnd32(UInt64 a);
  49. Boolean u64_isZero(UInt64 a);
  50. UInt64 u64_inc(UInt64 a);
  51. UInt64 u64_zero(void);
  52. UInt64 u64_sub(UInt64 a, UInt64 b);
  53.  
  54.  
  55.  
  56. UInt64 u64_and(UInt64 a, UInt64 b);
  57.  
  58. #endif
  59.  
  60.  
  61.  
  62. #endif
  63.  
  64.  
  65.