divsi3.S 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126
  1. /* libgcc1 routines for 68000 w/o floating-point hardware.
  2. Copyright (C) 1994, 1996, 1997, 1998 Free Software Foundation, Inc.
  3. This file is part of GNU CC.
  4. GNU CC is free software; you can redistribute it and/or modify it
  5. under the terms of the GNU General Public License as published by the
  6. Free Software Foundation; either version 2, or (at your option) any
  7. later version.
  8. In addition to the permissions in the GNU General Public License, the
  9. Free Software Foundation gives you unlimited permission to link the
  10. compiled version of this file with other programs, and to distribute
  11. those programs without any restriction coming from the use of this
  12. file. (The General Public License restrictions do apply in other
  13. respects; for example, they cover modification of the file, and
  14. distribution when not linked into another program.)
  15. This file is distributed in the hope that it will be useful, but
  16. WITHOUT ANY WARRANTY; without even the implied warranty of
  17. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  18. General Public License for more details.
  19. You should have received a copy of the GNU General Public License
  20. along with this program; see the file COPYING. If not, write to
  21. the Free Software Foundation, 59 Temple Place - Suite 330,
  22. Boston, MA 02111-1307, USA. */
  23. /* As a special exception, if you link this library with files
  24. compiled with GCC to produce an executable, this does not cause
  25. the resulting executable to be covered by the GNU General Public License.
  26. This exception does not however invalidate any other reasons why
  27. the executable file might be covered by the GNU General Public License. */
  28. /* Use this one for any 680x0; assumes no floating point hardware.
  29. The trailing " '" appearing on some lines is for ANSI preprocessors. Yuk.
  30. Some of this code comes from MINIX, via the folks at ericsson.
  31. D. V. Henkel-Wallace (gumby@cygnus.com) Fete Bastille, 1992
  32. */
  33. /* These are predefined by new versions of GNU cpp. */
  34. #ifndef __USER_LABEL_PREFIX__
  35. #define __USER_LABEL_PREFIX__ _
  36. #endif
  37. #ifndef __REGISTER_PREFIX__
  38. #define __REGISTER_PREFIX__
  39. #endif
  40. #ifndef __IMMEDIATE_PREFIX__
  41. #define __IMMEDIATE_PREFIX__ #
  42. #endif
  43. /* ANSI concatenation macros. */
  44. #define CONCAT1(a, b) CONCAT2(a, b)
  45. #define CONCAT2(a, b) a ## b
  46. /* Use the right prefix for global labels. */
  47. #define SYM(x) CONCAT1 (__USER_LABEL_PREFIX__, x)
  48. /* Use the right prefix for registers. */
  49. #define REG(x) CONCAT1 (__REGISTER_PREFIX__, x)
  50. /* Use the right prefix for immediate values. */
  51. #define IMM(x) CONCAT1 (__IMMEDIATE_PREFIX__, x)
  52. #define d0 REG (d0)
  53. #define d1 REG (d1)
  54. #define d2 REG (d2)
  55. #define d3 REG (d3)
  56. #define d4 REG (d4)
  57. #define d5 REG (d5)
  58. #define d6 REG (d6)
  59. #define d7 REG (d7)
  60. #define a0 REG (a0)
  61. #define a1 REG (a1)
  62. #define a2 REG (a2)
  63. #define a3 REG (a3)
  64. #define a4 REG (a4)
  65. #define a5 REG (a5)
  66. #define a6 REG (a6)
  67. #define fp REG (fp)
  68. #define sp REG (sp)
  69. .text
  70. .proc
  71. .globl SYM (__divsi3)
  72. SYM (__divsi3):
  73. movel d2, sp@-
  74. moveq IMM (1), d2 /* sign of result stored in d2 (=1 or =-1) */
  75. movel sp@(12), d1 /* d1 = divisor */
  76. jpl L1
  77. negl d1
  78. #if !(defined(__mcf5200__) || defined(__mcoldfire__))
  79. negb d2 /* change sign because divisor <0 */
  80. #else
  81. negl d2 /* change sign because divisor <0 */
  82. #endif
  83. L1: movel sp@(8), d0 /* d0 = dividend */
  84. jpl L2
  85. negl d0
  86. #if !(defined(__mcf5200__) || defined(__mcoldfire__))
  87. negb d2
  88. #else
  89. negl d2
  90. #endif
  91. L2: movel d1, sp@-
  92. movel d0, sp@-
  93. jbsr SYM (__udivsi3) /* divide abs(dividend) by abs(divisor) */
  94. addql IMM (8), sp
  95. tstb d2
  96. jpl L3
  97. negl d0
  98. L3: movel sp@+, d2
  99. rts