home *** CD-ROM | disk | FTP | other *** search
/ InfoMagic Source Code 1993 July / THE_SOURCE_CODE_CD_ROM.iso / bsd_srcs / usr.bin / gcc / gnulib / DIST / gnulib.c next >
Encoding:
C/C++ Source or Header  |  1990-09-11  |  6.2 KB  |  453 lines

  1. /* Subroutines needed by GCC output code on some machines.  */
  2. /* Compile this file with the Unix C compiler!  */
  3.  
  4. #include "config.h"
  5.  
  6. /* Define the C data type to use for an SImode value.  */
  7.  
  8. #ifndef SItype
  9. #define SItype long int
  10. #endif
  11.  
  12. /* Define the type to be used for returning an SF mode value
  13.    and the method for turning a float into that type.
  14.    These definitions work for machines where an SF value is
  15.    returned in the same register as an int.  */
  16.  
  17. #ifndef SFVALUE  
  18. #define SFVALUE int
  19. #endif
  20.  
  21. #ifndef INTIFY
  22. #define INTIFY(FLOATVAL)  (intify.f = (FLOATVAL), intify.i)
  23. #endif
  24.  
  25. union flt_or_int { int i; float f; };
  26.  
  27.  
  28. #ifdef L_eprintf
  29. #include <stdio.h>
  30. /* This is used by the `assert' macro.  */
  31. void
  32. __eprintf (string, expression, line, filename)
  33.      char *string;
  34.      char *expression;
  35.      int line;
  36.      char *filename;
  37. {
  38.   fprintf (stderr, string, expression, line, filename);
  39.   fflush (stderr);
  40.   abort ();
  41. }
  42. #endif
  43.  
  44. #ifdef L_umulsi3
  45. SItype
  46. __umulsi3 (a, b)
  47.      unsigned SItype a, b;
  48. {
  49.   return a * b;
  50. }
  51. #endif
  52.  
  53. #ifdef L_mulsi3
  54. SItype
  55. __mulsi3 (a, b)
  56.      SItype a, b;
  57. {
  58.   return a * b;
  59. }
  60. #endif
  61.  
  62. #ifdef L_udivsi3
  63. SItype
  64. __udivsi3 (a, b)
  65.      unsigned SItype a, b;
  66. {
  67.   return a / b;
  68. }
  69. #endif
  70.  
  71. #ifdef L_divsi3
  72. SItype
  73. __divsi3 (a, b)
  74.      SItype a, b;
  75. {
  76.   return a / b;
  77. }
  78. #endif
  79.  
  80. #ifdef L_umodsi3
  81. SItype
  82. __umodsi3 (a, b)
  83.      unsigned SItype a, b;
  84. {
  85.   return a % b;
  86. }
  87. #endif
  88.  
  89. #ifdef L_modsi3
  90. SItype
  91. __modsi3 (a, b)
  92.      SItype a, b;
  93. {
  94.   return a % b;
  95. }
  96. #endif
  97.  
  98. #ifdef L_lshrsi3
  99. SItype
  100. __lshrsi3 (a, b)
  101.      unsigned SItype a, b;
  102. {
  103.   return a >> b;
  104. }
  105. #endif
  106.  
  107. #ifdef L_lshlsi3
  108. SItype
  109. __lshlsi3 (a, b)
  110.      unsigned SItype a, b;
  111. {
  112.   return a << b;
  113. }
  114. #endif
  115.  
  116. #ifdef L_ashrsi3
  117. SItype
  118. __ashrsi3 (a, b)
  119.      SItype a, b;
  120. {
  121.   return a >> b;
  122. }
  123. #endif
  124.  
  125. #ifdef L_ashlsi3
  126. SItype
  127. __ashlsi3 (a, b)
  128.      SItype a, b;
  129. {
  130.   return a << b;
  131. }
  132. #endif
  133.  
  134. #ifdef L_divdf3
  135. double
  136. __divdf3 (a, b)
  137.      double a, b;
  138. {
  139.   return a / b;
  140. }
  141. #endif
  142.  
  143. #ifdef L_muldf3
  144. double
  145. __muldf3 (a, b)
  146.      double a, b;
  147. {
  148.   return a * b;
  149. }
  150. #endif
  151.  
  152. #ifdef L_negdf2
  153. double
  154. __negdf2 (a)
  155.      double a;
  156. {
  157.   return -a;
  158. }
  159. #endif
  160.  
  161. #ifdef L_adddf3
  162. double
  163. __adddf3 (a, b)
  164.      double a, b;
  165. {
  166.   return a + b;
  167. }
  168. #endif
  169.  
  170. #ifdef L_subdf3
  171. double
  172. __subdf3 (a, b)
  173.      double a, b;
  174. {
  175.   return a - b;
  176. }
  177. #endif
  178.  
  179. #ifdef L_cmpdf2
  180. SItype
  181. __cmpdf2 (a, b)
  182.      double a, b;
  183. {
  184.   if (a > b)
  185.     return 1;
  186.   else if (a < b)
  187.     return -1;
  188.   return 0;
  189. }
  190. #endif
  191.  
  192. #ifdef L_fixunsdfsi
  193. #define HIGH_BIT_INT_COEFF  (1 << (BITS_PER_WORD - 1))
  194. #define HIGH_BIT_COEFF  (2 * (double) (1 << (BITS_PER_WORD - 2)))
  195.  
  196. SItype
  197. __fixunsdfsi (a)
  198.      double a;
  199. {
  200.   if (a < HIGH_BIT_COEFF)
  201.     return (SItype)a;
  202.   /* Convert large positive numbers to smaller ones,
  203.      then increase again after you have a fixed point number.  */
  204.   else
  205.     return ((SItype) (a - HIGH_BIT_COEFF)) + HIGH_BIT_INT_COEFF;
  206. }
  207. #endif
  208.  
  209. #ifdef L_fixdfsi
  210. SItype
  211. __fixdfsi (a)
  212.      double a;
  213. {
  214.   return (SItype) a;
  215. }
  216. #endif
  217.  
  218. #ifdef L_floatsidf
  219. double
  220. __floatsidf (a)
  221.      SItype a;
  222. {
  223.   return (double) a;
  224. }
  225. #endif
  226.  
  227. #ifdef L_addsf3
  228. SFVALUE
  229. __addsf3 (a, b)
  230.      union flt_or_int a, b;
  231. {
  232.   union flt_or_int intify;
  233.   return INTIFY (a.f + b.f);
  234. }
  235. #endif
  236.  
  237. #ifdef L_negsf2
  238. SFVALUE
  239. __negsf2 (a)
  240.      union flt_or_int a;
  241. {
  242.   union flt_or_int intify;
  243.   return INTIFY (-a.f);
  244. }
  245. #endif
  246.  
  247. #ifdef L_subsf3
  248. SFVALUE
  249. __subsf3 (a, b)
  250.      union flt_or_int a, b;
  251. {
  252.   union flt_or_int intify;
  253.   return INTIFY (a.f - b.f);
  254. }
  255. #endif
  256.  
  257. #ifdef L_cmpsf2
  258. SItype
  259. __cmpsf2 (a, b)
  260.      union flt_or_int a, b;
  261. {
  262.   if (a.f > b.f)
  263.     return 1;
  264.   else if (a.f < b.f)
  265.     return -1;
  266.   return 0;
  267. }
  268. #endif
  269.  
  270. #ifdef L_mulsf3
  271. SFVALUE
  272. __mulsf3 (a, b)
  273.      union flt_or_int a, b;
  274. {
  275.   union flt_or_int intify;
  276.   return INTIFY (a.f * b.f);
  277. }
  278. #endif
  279.  
  280. #ifdef L_divsf3
  281. SFVALUE
  282. __divsf3 (a, b)
  283.      union flt_or_int a, b;
  284. {
  285.   union flt_or_int intify;
  286.   return INTIFY (a.f / b.f);
  287. }
  288. #endif
  289.  
  290. #ifdef L_truncdfsf2
  291. SFVALUE
  292. __truncdfsf2 (a)
  293.      double a;
  294. {
  295.   union flt_or_int intify;
  296.   return INTIFY (a);
  297. }
  298. #endif
  299.  
  300. #ifdef L_extendsfdf2
  301. double
  302. __extendsfdf2 (a)
  303.      union flt_or_int a;
  304. {
  305.   union flt_or_int intify;
  306.   return a.f;
  307. }
  308. #endif
  309.  
  310. #ifdef L_bb
  311. int __avoid_ranlib_warning;  /* Don't let symbol table be empty.  */
  312.  
  313. #if defined (sun) && defined (mc68000)
  314. struct bb
  315. {
  316.   int initialized;
  317.   char *filename;
  318.   int *counts;
  319.   int ncounts;
  320.   int zero_word;
  321.   int *addresses;
  322. };
  323.  
  324. __bb_init_func (blocks)
  325.     struct bb *blocks;
  326. {
  327.   extern int ___tcov_init;
  328.  
  329.   if (! ___tcov_init)
  330.     ___tcov_init_func ();
  331.  
  332.   ___bb_link (blocks->filename, blocks->counts, blocks->ncounts);
  333. }
  334.  
  335. #endif
  336. #endif
  337.  
  338. /* frills for C++ */
  339.  
  340. #ifdef L_builtin_new
  341. typedef void (*vfp)();
  342.  
  343. extern vfp __new_handler;
  344.  
  345. char *
  346. __builtin_new (sz)
  347.      long sz;
  348. {
  349.   char *p;
  350.  
  351.   p = (char *)malloc (sz);
  352.   if (p == 0)
  353.     (*__new_handler) ();
  354.   return p;
  355. }
  356. #endif
  357.  
  358. #ifdef L_builtin_New
  359. typedef void (*vfp)();
  360.  
  361. static void
  362. default_new_handler ();
  363.  
  364. vfp __new_handler = default_new_handler;
  365.  
  366. char *
  367. __builtin_vec_new (p, maxindex, size, ctor)
  368.      char *p;
  369.      int maxindex, size;
  370.      void (*ctor)();
  371. {
  372.   int i, nelts = maxindex + 1;
  373.   char *rval;
  374.  
  375.   if (p == 0)
  376.     p = (char *)__builtin_new (nelts * size);
  377.  
  378.   rval = p;
  379.  
  380.   for (i = 0; i < nelts; i++)
  381.     {
  382.       (*ctor) (p);
  383.       p += size;
  384.     }
  385.  
  386.   return rval;
  387. }
  388.  
  389. vfp
  390. __set_new_handler (handler)
  391.      vfp handler;
  392. {
  393.   vfp prev_handler;
  394.  
  395.   prev_handler = __new_handler;
  396.   if (handler == 0) handler = default_new_handler;
  397.   __new_handler = handler;
  398.   return prev_handler;
  399. }
  400.  
  401. vfp
  402. set_new_handler (handler)
  403.      vfp handler;
  404. {
  405.   return __set_new_handler (handler);
  406. }
  407.  
  408. static void
  409. default_new_handler ()
  410. {
  411.   /* don't use fprintf (stderr, ...) because it may need to call malloc.  */
  412.   write (2, "default_new_handler: out of memory... aaaiiiiiieeeeeeeeeeeeee!\n", 65);
  413.   /* don't call exit () because that may call global destructors which
  414.      may cause a loop.  */
  415.   _exit (-1);
  416. }
  417. #endif
  418.  
  419. #ifdef L_builtin_del
  420. typedef void (*vfp)();
  421.  
  422. void
  423. __builtin_delete (ptr)
  424.      char *ptr;
  425. {
  426.   if (ptr)
  427.     free (ptr);
  428. }
  429.  
  430. void
  431. __builtin_vec_delete (ptr, maxindex, size, dtor, auto_delete_vec, auto_delete)
  432.      char *ptr;
  433.      int maxindex, size;
  434.      void (*dtor)();
  435.      int auto_delete;
  436. {
  437.   int i, nelts = maxindex + 1;
  438.   char *p = ptr;
  439.  
  440.   ptr += nelts * size;
  441.  
  442.   for (i = 0; i < nelts; i++)
  443.     {
  444.       ptr -= size;
  445.       (*dtor) (ptr, auto_delete);
  446.     }
  447.  
  448.   if (auto_delete_vec)
  449.     free (p);
  450. }
  451.  
  452. #endif
  453.