home *** CD-ROM | disk | FTP | other *** search
/ Oracle Video Server 3.0.3.1 / OVS_3031_NT.iso / win32 / medianet / server / include / sysb8.h < prev    next >
Encoding:
C/C++ Source or Header  |  1996-11-05  |  8.2 KB  |  281 lines

  1. /* Copyright (c) 1995 by Oracle Corporation.  All Rights Reserved.
  2.  *
  3.  * sysb8.h - Portable 64-bit Signed Integer Data Type
  4.  *
  5.  * FOR NATIVE SB8 USERS
  6.  * void sysb8fromsb8(sysb8 *out, sb8 in);
  7.  * sb8  sysb8tosb8(sysb8 *in);
  8.  * sb8  sb8lit(<64-bit literal>);
  9.  *
  10.  * These two macros convert between the native sb8 type and the portable
  11.  * sysb8 type.  These cause no actual conversion to take place, but serve
  12.  * as markers to indicate the transition between the usage of the portable
  13.  * type to a type that requires native 64-bit support.  They will produce
  14.  * errors on platforms that do not provide such support.  THESE MACROS MAY
  15.  * ONLY BE USED IN COMPONENTS THAT ARE REQUIRED TO RUN ON 64-BIT PLATFORMS.
  16.  * THEIR USAGE IS DISCOURAGED.
  17.  *
  18.  * The macro sb8lit() must be used to surround usage of all 64-bit literals.
  19.  * (e.g. sb8lit(0xf12345678)).  This serves to lexically mark these literals
  20.  * so that compilers will accept and process them correctly.  Most of the
  21.  * time, this involves appending "LL" to the literal; other times, it may
  22.  * simply call for an sb8 cast.  Finally, if the compiler does not support
  23.  * large literals (even though it supports large variables), this macro
  24.  * could translate to a function that converts the stringized form.
  25.  *
  26.  * FOR PORTERS
  27.  * This package is used as the interface to 64-bit integers used by OMS
  28.  * software.  If your platform does not support native 64-bit types,
  29.  * you should simply ensure that SYSB8_NATIVE is not defined.  This will
  30.  * force the usage of the portable 64-bit package provided by OMS.  No
  31.  * other changes should be required.
  32.  *
  33.  * If your platform does support native 64-bit types, ensure that the
  34.  * SYSB8_NATIVE symbol is defined below.  A sample implementation for
  35.  * these definitions is provided below, and it should require little
  36.  * modification.  You will need to define sysb8zero, however.
  37.  *
  38.  * For other functions for which there is no native support, such as
  39.  * sysb8fromstr() or sysb8fmt(), the suggested solution is to implement
  40.  * a function that converts between the ysb8 structure and the native
  41.  * sb8 format, and then use the corresponding function of the ysb8
  42.  * portable library.
  43.  *
  44.  * A full description of each function appears in the man page sysb8(3).
  45.  */
  46.  
  47. #ifndef SYSB8_ORACLE
  48. #define SYSB8_ORACLE
  49.  
  50. #ifndef SYSX_ORACLE
  51. #include <sysx.h>
  52. #endif
  53.  
  54. /*
  55.  * Define SYSB8_NATIVE here if the platform supports 64-bit integers natively.
  56.  * Define SYSB8_PRINT here if the platform supports 64-bit integers natively,
  57.  * and the native sprintf() function is capable of printing these directly.
  58.  */
  59.  
  60. #ifdef sun /* With GCC */
  61. # define SYSB8_NATIVE
  62. #endif
  63.  
  64. #ifdef NCUBE
  65. # define SYSB8_NATIVE
  66. # define SYSB8_PRINT
  67. #endif
  68.  
  69. #ifdef hpux
  70. # define SYSB8_NATIVE
  71. #endif
  72.  
  73. #ifdef WIN32 /* With MSVC v4.0 */
  74. # define SYSB8_NATIVE
  75. #endif
  76.  
  77.  
  78. #ifdef SYSB8_NATIVE
  79.  
  80. typedef __int64 sysb8;
  81. #define sysb8add(o, u, v)      (*(o) = *(u) + *(v))
  82. #define sysb8sub(o, u, v)      (*(o) = *(u) - *(v))
  83. #define sysb8mul(o, u, v)      (*(o) = *(u) * *(v))
  84. #define sysb8div(o, u, v)      (*(o) = *(u) / *(v))
  85. #define sysb8rem(o, u, v)      (*(o) = *(u) % *(v))
  86. #define sysb8neg(o, u)         (*(o) = (-*(u)))
  87. #define sysb8srl(o, u, b)      (*(o) = (sysb8) \
  88.                 (((unsigned __int64) *(u)) >> (b)))
  89. #define sysb8sll(o, u, b)      (*(o) = *(u) << (b))
  90.  
  91. /*
  92.  * Note we have to use a complex name for the tmp variable in the below
  93.  * macro to assure no one will call the macro with a u, v, q, or r that
  94.  * expands to the same name.
  95.  */
  96. #define sysb8edv(u, v, q, r)   \
  97.   do { sysb8 sysb8edvtmp; sysb8edvtmp = *(u) / *(v); *(r) = *(u) % *(v); \
  98.      *(q) = sysb8edvtmp; } while (0)
  99.  
  100. #define sysb8addb4(o, u, b)    (*(o) = *(u) + (sysb8) (b))
  101. #define sysb8mulb4(o, u, b)    (*(o) = *(u) * (sysb8) (b))
  102. #define sysb8ext(o, k)         (*(o) = ((sysb8) (k)))
  103. #define sysb8msk(u)            ((sb4) *(u))
  104. #define sysb8mak(o, h, l)      (*(o) = (((sysb8) (h)) << 32) + (l))
  105. #define sysb8set(o, u)         (*(o) = *(u))
  106. #define sysb8cmp(u, op, v)     (*(u) op *(v))
  107. #define sysb8todbl(u)          ((double) *(u))
  108. #define sysb8fromdbl(u, g)     (*(u) = (sysb8) (g))
  109. #ifdef SYSB8_PRINT
  110. # define sysb8fmt(b, f, v)      (sprintf((b), (f), (*v)), (b))
  111. # define sysb8fromstr(o, s)     (sscanf((s), "%Li", (o)) > 0)
  112. #else
  113. char *sysb8fmt(char *buf, CONST char *fmt, sysb8 *val);
  114. boolean sysb8fromstr(sysb8 *out, CONST char *str);
  115. #endif
  116.  
  117. externref CONST sysb8 *CONST_W_PTR sysb8zero;
  118.  
  119. /*
  120.  * The following uses of sb8 will be legal in some RTS components
  121.  * because the platform supports native types.  Note that we use
  122.  * #defines rather than typedefs to avoid conflicts with any possible
  123.  * existing typedefs from sx.h.
  124.  */
  125.  
  126. #define sysb8fromsb8(o, v)     (*(o) = (sysb8) (v))
  127. #define sysb8tosb8(u)          ((sb8) *(u))
  128. #define sb8lit(v)              v
  129.  
  130. #ifdef sb8
  131. # undef sb8
  132. #endif
  133. #define sb8 sysb8
  134.  
  135. #ifdef SB8MAXVAL
  136. # undef SB8MAXVAL
  137. #endif
  138. #define SB8MAXVAL ((sb8)sb8lit(9223372036854775807))
  139.  
  140. #ifdef SB8MINVAL
  141. # undef SB8MINVAL
  142. #endif
  143. #define SB8MINVAL (-SB8MAXVAL-1)
  144.  
  145. #else /* SYSB8_NATIVE */
  146.  
  147. #define sysb8         ysb8
  148. #define sysb8add      ysb8add
  149. #define sysb8sub      ysb8sub
  150. #define sysb8mul      ysb8mul
  151. #define sysb8div      ysb8div
  152. #define sysb8rem      ysb8rem
  153. #define sysb8neg      ysb8neg
  154. #define sysb8srl      ysb8srl
  155. #define sysb8sll      ysb8sll
  156. #define sysb8edv      ysb8edv
  157. #define sysb8addb4    ysb8addb4
  158. #define sysb8mulb4    ysb8mulb4
  159. #define sysb8ext      ysb8ext
  160. #define sysb8msk      ysb8msk
  161. #define sysb8mak      ysb8mak
  162. #define sysb8set      ysb8set
  163. #define sysb8cmp      ysb8cmp
  164. #define sysb8todbl    ysb8todbl
  165. #define sysb8fromdbl  ysb8fromdbl
  166. #define sysb8fmt      ysb8fmt
  167. #define sysb8fromstr  ysb8fromstr
  168. #define sysb8zero     ysb8zero
  169.  
  170. /*
  171.  * The following uses of sb8 will illegal because the platform does not
  172.  * properly support native types. Note the use of #defines rather than 
  173.  * typedefs to avoid conflicts with any possible existing typedefs from 
  174.  * sx.h.
  175.  */
  176.  
  177. #ifdef sb8
  178. # undef sb8
  179. #endif
  180. #define sb8 ILLEGAL_USE_OF_SB8S
  181.  
  182. #ifdef SB8MAXVAL
  183. # undef SB8MAXVAL
  184. #endif
  185. #define SB8MAXVAL ILLEGAL_USE_OF_SB8S
  186.  
  187. #ifdef SB8MINVAL
  188. # undef SB8MINVAL
  189. #endif
  190. #define SB8MINVAL ILLEGAL_USE_OF_SB8S
  191.  
  192. #define sysb8fromsb8(o, v)   ILLEGAL_USAGE_OF_SB8S
  193. #define sysb8tosb8(u)        ILLEGAL_USAGE_OF_SB8S
  194.  
  195. #endif /* SYSB8_NATIVE */
  196.  
  197. /*
  198.  * Override any _b8 conventions from sx.h.
  199.  * OMS software adopts the following conventions regarding the use of
  200.  * _b8 data types directly:
  201.  *
  202.  *   ub8 and eb8 are always prohibited.
  203.  *
  204.  *   sb8 is prohibited except in certain Real-Time Server components,
  205.  *   where its use is highly discouraged.  It was felt that certain
  206.  *   complex calculations would have their code obscured by the use 
  207.  *   of the portable sysb8 constructs.
  208.  *
  209.  *   The use of sysb8 is required in all other places where a 64-bit
  210.  *   data type is required.  This is especially true for interfaces.
  211.  *
  212.  *   If present, the sb8 data type must be capable of holding 64-bits
  213.  *   or more.  It is not acceptable to merely define this as a 4-byte
  214.  *   quantity.  If the platform can not support all native C operations
  215.  *   on 64-bit integer data types, then a definition for sb8 must not 
  216.  *   be provided.
  217.  */
  218.  
  219. /* The following _b8 definitions are always illegal. */
  220. #ifdef eb8
  221. # undef eb8
  222. #endif
  223. #define eb8 ILLEGAL_USE_OF_EB8S
  224.  
  225. #ifdef ub8
  226. # undef ub8
  227. #endif
  228. #define ub8 ILLEGAL_USE_OF_UB8S
  229.  
  230. #ifdef EB8MAXVAL
  231. # undef EB8MAXVAL
  232. #endif
  233. #define EB8MAXVAL ILLEGAL_USE_OF_EB8S
  234.  
  235. #ifdef EB8MINVAL
  236. # undef EB8MINVAL
  237. #endif
  238. #define EB8MINVAL ILLEGAL_USE_OF_EB8S
  239.  
  240. #ifdef UB8MAXVAL
  241. # undef UB8MAXVAL
  242. #endif
  243. #define UB8MAXVAL ILLEGAL_USE_OF_UB8S
  244.  
  245. #ifdef UB8MINVAL
  246. # undef UB8MINVAL
  247. #endif
  248. #define UB8MINVAL ILLEGAL_USE_OF_UB8S
  249.  
  250. #ifdef  MINEB8MAXVAL
  251. # undef  MINEB8MAXVAL
  252. #endif
  253. #define MINEB8MAXVAL ILLEGAL_USE_OF_EB8S
  254.  
  255. #ifdef MAXEB8MINVAL
  256. # undef MAXEB8MINVAL
  257. #endif
  258. #define MAXEB8MINVAL ILLEGAL_USE_OF_EB8S
  259.  
  260. #ifdef MINUB8MAXVAL
  261. # undef MINUB8MAXVAL
  262. #endif
  263. #define MINUB8MAXVAL ILLEGAL_USE_OF_UB8S
  264.  
  265. #ifdef MAXUB8MINVAL
  266. # undef MAXUB8MINVAL
  267. #endif
  268. #define MAXUB8MINVAL ILLEGAL_USE_OF_UB8S
  269.  
  270. #endif /* SYSB8_ORACLE */
  271.  
  272.  
  273.  
  274.  
  275.  
  276.  
  277.  
  278.  
  279.  
  280.  
  281.