longlong.h 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144
  1. /*-
  2. * Copyright (c) 1992, 1993
  3. * The Regents of the University of California. All rights reserved.
  4. *
  5. * This software was developed by the Computer Systems Engineering group
  6. * at Lawrence Berkeley Laboratory under DARPA contract BG 91-66 and
  7. * contributed to Berkeley.
  8. *
  9. * Redistribution and use in source and binary forms, with or without
  10. * modification, are permitted provided that the following conditions
  11. * are met:
  12. * 1. Redistributions of source code must retain the above copyright
  13. * notice, this list of conditions and the following disclaimer.
  14. * 2. Redistributions in binary form must reproduce the above copyright
  15. * notice, this list of conditions and the following disclaimer in the
  16. * documentation and/or other materials provided with the distribution.
  17. * 3. Neither the name of the University nor the names of its contributors
  18. * may be used to endorse or promote products derived from this software
  19. * without specific prior written permission.
  20. *
  21. * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
  22. * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  23. * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
  24. * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
  25. * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
  26. * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
  27. * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
  28. * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
  29. * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
  30. * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
  31. * SUCH DAMAGE.
  32. *
  33. * From:
  34. * @(#)quad.h 8.1 (Berkeley) 6/4/93
  35. * NetBSD: quad.h,v 1.1 2005/12/20 20:29:40 christos Exp
  36. */
  37. /*
  38. * Long long arithmetic.
  39. *
  40. * This library makes the following assumptions:
  41. *
  42. * - The type long long exists.
  43. *
  44. * - A long long variable is exactly twice as long as `int'.
  45. *
  46. * - The machine's arithmetic is two's complement.
  47. *
  48. * This library can provide 128-bit arithmetic on a machine with
  49. * 128-bit long longs and 64-bit ints, for instance, or 96-bit
  50. * arithmetic on machines with 48-bit ints.
  51. *
  52. * The names are built into gcc.
  53. */
  54. #if defined(_KERNEL)
  55. #include <types.h>
  56. #include <endian.h>
  57. #else
  58. #include <sys/types.h>
  59. #include <sys/endian.h>
  60. #endif
  61. #include <limits.h>
  62. /*
  63. * Depending on the desired operation, we view a `long long' in
  64. * one or more of the following formats.
  65. */
  66. union uu {
  67. long long ll; /* as a (signed) long long */
  68. unsigned long long ull; /* as an unsigned long long */
  69. int si[2]; /* as two (signed) ints */
  70. unsigned int ui[2]; /* as two unsigned ints */
  71. };
  72. /*
  73. * Define high and low parts of a long long.
  74. */
  75. #if _BYTE_ORDER == _LITTLE_ENDIAN
  76. #define H 1
  77. #define L 0
  78. #endif
  79. #if _BYTE_ORDER == _BIG_ENDIAN
  80. #define H 0
  81. #define L 1
  82. #endif
  83. /*
  84. * Total number of bits in a long long and in the pieces that make it up.
  85. * These are used for shifting, and also below for halfword extraction
  86. * and assembly.
  87. */
  88. #define LONGLONG_BITS (sizeof(long long) * CHAR_BIT)
  89. #define INT_BITS (sizeof(int) * CHAR_BIT)
  90. #define HALF_BITS (sizeof(int) * CHAR_BIT / 2)
  91. /*
  92. * Extract high and low shortwords from longword, and move low shortword of
  93. * longword to upper half of long, i.e., produce the upper longword of
  94. * ((long long)(x) << (number_of_bits_in_int/2)).
  95. * [`x' must actually be unsigned int.]
  96. *
  97. * These are used in the multiply code, to split a longword into upper
  98. * and lower halves, and to reassemble a product as a long long, shifted
  99. * left (sizeof(int)*CHAR_BIT/2).
  100. */
  101. #define HHALF(x) ((unsigned int)(x) >> HALF_BITS)
  102. #define LHALF(x) ((unsigned int)(x) & (((int)1 << HALF_BITS) - 1))
  103. #define LHUP(x) ((unsigned int)(x) << HALF_BITS)
  104. long long __adddi3 ( long long, long long);
  105. long long __anddi3 ( long long, long long);
  106. long long __ashldi3 ( long long, unsigned int);
  107. long long __ashrdi3 ( long long, unsigned int);
  108. int __cmpdi2 ( long long, long long);
  109. long long __divdi3 ( long long, long long);
  110. long long __iordi3 ( long long, long long);
  111. long long __lshldi3 ( long long, unsigned int);
  112. long long __lshrdi3 ( long long, unsigned int);
  113. long long __moddi3 ( long long, long long);
  114. long long __muldi3 ( long long, long long);
  115. long long __negdi2 ( long long);
  116. long long __one_cmpldi2 ( long long);
  117. long long __subdi3 ( long long, long long);
  118. int __ucmpdi2 (unsigned long long, unsigned long long);
  119. unsigned long long __udivdi3 (unsigned long long, unsigned long long);
  120. unsigned long long __umoddi3 (unsigned long long, unsigned long long);
  121. long long __xordi3 ( long long, long long);
  122. #ifndef _KERNEL
  123. long long __fixdfdi (double);
  124. long long __fixsfdi (float);
  125. unsigned long long __fixunsdfdi (double);
  126. unsigned long long __fixunssfdi (float);
  127. double __floatdidf (long long);
  128. float __floatdisf (long long);
  129. double __floatunsdidf(unsigned long long);
  130. #endif
  131. unsigned long long __qdivrem (unsigned long long, unsigned long long,
  132. unsigned long long *);