libtcc1.c 6.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363
  1. /* -*-comment-start: "//";comment-end:""-*-
  2. * GNU Mes --- Maxwell Equations of Software
  3. * Copyright © 2017,2018,2020 Jan (janneke) Nieuwenhuizen <janneke@gnu.org>
  4. *
  5. * This file is part of GNU Mes.
  6. *
  7. * GNU Mes is free software; you can redistribute it and/or modify it
  8. * under the terms of the GNU General Public License as published by
  9. * the Free Software Foundation; either version 3 of the License, or (at
  10. * your option) any later version.
  11. *
  12. * GNU Mes is distributed in the hope that it will be useful, but
  13. * WITHOUT ANY WARRANTY; without even the implied warranty of
  14. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  15. * GNU General Public License for more details.
  16. *
  17. * You should have received a copy of the GNU General Public License
  18. * along with GNU Mes. If not, see <http://www.gnu.org/licenses/>.
  19. */
  20. #include <mes/lib.h>
  21. double
  22. __divdi3 (double a, double b)
  23. {
  24. #if !__TINYC__
  25. static int stub = 0;
  26. if (__mes_debug () && !stub)
  27. eputs ("__divdi3 stub\n");
  28. stub = 1;
  29. #endif
  30. long ai = a;
  31. long bi = b;
  32. #if __arm__ && __TINYC__
  33. return __mesabi_idiv (ai, bi);
  34. #else
  35. return ai / bi;
  36. #endif
  37. }
  38. double
  39. __moddi3 (double a, double b)
  40. {
  41. #if !__TINYC__
  42. static int stub = 0;
  43. if (__mes_debug () && !stub)
  44. eputs ("__moddi3 stub\n");
  45. stub = 1;
  46. #endif
  47. long ai = a;
  48. long bi = b;
  49. #if __arm__ && __TINYC__
  50. return __mesabi_imod (ai, bi);
  51. #else
  52. return ai % bi;
  53. #endif
  54. }
  55. #if HAVE_LONG_LONG
  56. unsigned long long
  57. __udivdi3 (unsigned long long a, unsigned long long b)
  58. #else
  59. unsigned long
  60. __udivdi3 (unsigned long a, long ah, unsigned long b)
  61. #endif
  62. {
  63. #if !__TINYC__
  64. static int stub = 0;
  65. if (__mes_debug () && !stub)
  66. eputs ("__udivdi3 stub\n");
  67. stub = 1;
  68. #endif
  69. unsigned long ai = a;
  70. unsigned long bi = b;
  71. if (!b)
  72. return 0;
  73. #if __arm__ && __TINYC__
  74. return __mesabi_idiv (ai, bi);
  75. #else
  76. return ai / bi;
  77. #endif
  78. }
  79. #if HAVE_LONG_LONG
  80. unsigned long long
  81. __umoddi3 (unsigned long long a, unsigned long long b)
  82. #else
  83. unsigned long
  84. __umoddi3 (unsigned long a, long ah, unsigned long b)
  85. #endif
  86. {
  87. #if !__TINYC__
  88. static int stub = 0;
  89. if (__mes_debug () && !stub)
  90. eputs ("__umoddi3 stub\n");
  91. stub = 1;
  92. #endif
  93. unsigned long ai = a;
  94. unsigned long bi = b;
  95. #if __arm__ && __TINYC__
  96. return __mesabi_imod (ai, bi);
  97. #else
  98. return ai % bi;
  99. #endif
  100. }
  101. #if HAVE_LONG_LONG
  102. unsigned long long
  103. __lshrdi3 (unsigned long long a, long b)
  104. #else
  105. unsigned long
  106. __lshrdi3 (unsigned long a, long ah, long b)
  107. #endif
  108. {
  109. #if !__TINYC__
  110. static int stub = 0;
  111. if (__mes_debug () && !stub)
  112. eputs ("__lshrdi3 stub\n");
  113. stub = 1;
  114. return a >> b;
  115. #else // __TINYC__
  116. for (int i = 0; i < b; i++)
  117. #if __arm__
  118. a = __mesabi_idiv (a, 2);
  119. #else // !__arm__
  120. a /= 2;
  121. #endif // !__arm__
  122. return a;
  123. #endif // __TINYC__
  124. }
  125. #if HAVE_LONG_LONG
  126. long long
  127. __ashldi3 (long long a, long b)
  128. #else
  129. long
  130. __ashldi3 (long a, long ah, long b)
  131. #endif
  132. {
  133. #if !__TINYC__
  134. static int stub = 0;
  135. if (__mes_debug () && !stub)
  136. eputs ("__ashldi3 stub\n");
  137. stub = 1;
  138. return a << b;
  139. #else // __TINYC__
  140. for (int i = 0; i < b; i++)
  141. a += a;
  142. return a;
  143. #endif // __TINYC__
  144. }
  145. #if HAVE_LONG_LONG
  146. long long
  147. __ashrdi3 (long long a, long b)
  148. #else
  149. long
  150. __ashrdi3 (long a, long ah, long b)
  151. #endif
  152. {
  153. #if !__TINYC__
  154. static int stub = 0;
  155. if (__mes_debug () && !stub)
  156. eputs ("__ashrdi3 stub\n");
  157. stub = 1;
  158. return a >> b;
  159. #else // __TINYC__
  160. for (int i = 0; i < b; i++)
  161. #if __arm__
  162. a = __mesabi_idiv (a, 2);
  163. #else // !__arm__
  164. a /= 2;
  165. #endif // !__arm__
  166. return a;
  167. #endif // __TINYC__
  168. }
  169. #if HAVE_FLOAT_STUB || HAVE_FLOAT
  170. double
  171. __attribute__((weak))
  172. #if HAVE_LONG_LONG && HAVE_FLOAT
  173. __floatundidf (unsigned long long a)
  174. #else
  175. __floatundidf (unsigned long a)
  176. #endif
  177. {
  178. #if !__TINYC__
  179. static int stub = 0;
  180. if (__mes_debug () && !stub)
  181. eputs ("__floatundidf stub\n");
  182. stub = 1;
  183. #endif
  184. return 0;
  185. }
  186. #if HAVE_LONG_LONG && HAVE_FLOAT
  187. long double
  188. __attribute__((weak))
  189. __floatundixf (unsigned long long a)
  190. #else
  191. double
  192. __attribute__((weak))
  193. __floatundixf (unsigned long a)
  194. #endif
  195. {
  196. #if !__TINYC__
  197. static int stub = 0;
  198. if (__mes_debug () && !stub)
  199. eputs ("__floatundixf stub\n");
  200. stub = 1;
  201. #endif
  202. return 0;
  203. }
  204. #if HAVE_LONG_LONG
  205. unsigned long long
  206. #else
  207. unsigned long
  208. #endif
  209. __attribute__((weak))
  210. __fixunsxfdi (double a1)
  211. {
  212. #if !__TINYC__
  213. static int stub = 0;
  214. if (__mes_debug () && !stub)
  215. eputs ("__fixunsxfdi stub\n");
  216. stub = 1;
  217. #endif
  218. return 0;
  219. }
  220. #if __TINYC__ == 9226
  221. long
  222. #elif __TINYC__
  223. int
  224. #else // !__TINYCC__
  225. long long
  226. #endif // !__TINYCC__
  227. __attribute__((weak))
  228. __fixdfdi (double a1)
  229. {
  230. #if !__TINYC__
  231. static int stub = 0;
  232. if (__mes_debug () && !stub)
  233. eputs ("__fixdfdi stub\n");
  234. stub = 1;
  235. #endif
  236. return 0;
  237. }
  238. #if HAVE_LONG_LONG
  239. unsigned long long
  240. #else
  241. unsigned long
  242. #endif
  243. __attribute__((weak))
  244. __fixxfdi (double a1)
  245. {
  246. #if !__TINYC__
  247. static int stub = 0;
  248. if (__mes_debug () && !stub)
  249. eputs ("__fixxfdi stub\n");
  250. stub = 1;
  251. #endif
  252. return 0;
  253. }
  254. #if HAVE_LONG_LONG
  255. long long
  256. #else
  257. long
  258. #endif
  259. __attribute__((weak))
  260. __fixsfdi (double a1)
  261. {
  262. #if !__TINYC__
  263. static int stub = 0;
  264. if (__mes_debug () && !stub)
  265. eputs ("__fixsfdi stub\n");
  266. stub = 1;
  267. #endif
  268. return 0;
  269. }
  270. double
  271. __attribute__((weak))
  272. __fixunsdfdi (double num, double den)
  273. {
  274. #if !__TINYC__
  275. static int stub = 0;
  276. if (__mes_debug () && !stub)
  277. eputs ("__fixunsdfdi stub\n");
  278. stub = 1;
  279. #endif
  280. return 0;
  281. }
  282. #endif // HAVE_FLOAT_STUB || HAVE_FLOAT
  283. int
  284. __attribute__((weak))
  285. __fixunsdfsi (int a, int b)
  286. {
  287. #if !__TINYC__
  288. static int stub = 0;
  289. if (__mes_debug () && !stub)
  290. eputs ("__fixunsdfsi stub\n");
  291. stub = 1;
  292. #endif
  293. return 0;
  294. }
  295. #if __arm__
  296. int
  297. __attribute__((weak))
  298. __floatdisf (int a, int b)
  299. {
  300. #if !__TINYC__
  301. static int stub = 0;
  302. if (__mes_debug () && !stub)
  303. eputs ("__floatdisf stub\n");
  304. stub = 1;
  305. #endif
  306. return 0;
  307. }
  308. int
  309. __attribute__((weak))
  310. __floatdidf (int a, int b)
  311. {
  312. #if !__TINYC__
  313. static int stub = 0;
  314. if (__mes_debug () && !stub)
  315. eputs ("__floatdidf stub\n");
  316. stub = 1;
  317. #endif
  318. return 0;
  319. }
  320. int
  321. __divsi3 (int num, int den)
  322. {
  323. return __mesabi_idiv (num, den);
  324. }
  325. int
  326. __modsi3 (int num, int den)
  327. {
  328. return __mesabi_imod (num, den);
  329. }
  330. int
  331. __udivsi3 (int num, int den)
  332. {
  333. return __mesabi_udiv (num, den);
  334. }
  335. int
  336. __umodsi3 (int num, int den)
  337. {
  338. return __mesabi_umod (num, den);
  339. }
  340. #endif //__arm__