divsi3.S 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121
  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. /* As a special exception, if you link this library with files
  20. compiled with GCC to produce an executable, this does not cause
  21. the resulting executable to be covered by the GNU General Public License.
  22. This exception does not however invalidate any other reasons why
  23. the executable file might be covered by the GNU General Public License. */
  24. /* Use this one for any 680x0; assumes no floating point hardware.
  25. The trailing " '" appearing on some lines is for ANSI preprocessors. Yuk.
  26. Some of this code comes from MINIX, via the folks at ericsson.
  27. D. V. Henkel-Wallace (gumby@cygnus.com) Fete Bastille, 1992
  28. */
  29. /* These are predefined by new versions of GNU cpp. */
  30. #ifndef __USER_LABEL_PREFIX__
  31. #define __USER_LABEL_PREFIX__ _
  32. #endif
  33. #ifndef __REGISTER_PREFIX__
  34. #define __REGISTER_PREFIX__
  35. #endif
  36. #ifndef __IMMEDIATE_PREFIX__
  37. #define __IMMEDIATE_PREFIX__ #
  38. #endif
  39. /* ANSI concatenation macros. */
  40. #define CONCAT1(a, b) CONCAT2(a, b)
  41. #define CONCAT2(a, b) a ## b
  42. /* Use the right prefix for global labels. */
  43. #define SYM(x) CONCAT1 (__USER_LABEL_PREFIX__, x)
  44. /* Use the right prefix for registers. */
  45. #define REG(x) CONCAT1 (__REGISTER_PREFIX__, x)
  46. /* Use the right prefix for immediate values. */
  47. #define IMM(x) CONCAT1 (__IMMEDIATE_PREFIX__, x)
  48. #define d0 REG (d0)
  49. #define d1 REG (d1)
  50. #define d2 REG (d2)
  51. #define d3 REG (d3)
  52. #define d4 REG (d4)
  53. #define d5 REG (d5)
  54. #define d6 REG (d6)
  55. #define d7 REG (d7)
  56. #define a0 REG (a0)
  57. #define a1 REG (a1)
  58. #define a2 REG (a2)
  59. #define a3 REG (a3)
  60. #define a4 REG (a4)
  61. #define a5 REG (a5)
  62. #define a6 REG (a6)
  63. #define fp REG (fp)
  64. #define sp REG (sp)
  65. .text
  66. .proc
  67. .globl SYM (__divsi3)
  68. SYM (__divsi3):
  69. movel d2, sp@-
  70. moveq IMM (1), d2 /* sign of result stored in d2 (=1 or =-1) */
  71. movel sp@(12), d1 /* d1 = divisor */
  72. jpl L1
  73. negl d1
  74. #if !(defined(__mcf5200__) || defined(__mcoldfire__))
  75. negb d2 /* change sign because divisor <0 */
  76. #else
  77. negl d2 /* change sign because divisor <0 */
  78. #endif
  79. L1: movel sp@(8), d0 /* d0 = dividend */
  80. jpl L2
  81. negl d0
  82. #if !(defined(__mcf5200__) || defined(__mcoldfire__))
  83. negb d2
  84. #else
  85. negl d2
  86. #endif
  87. L2: movel d1, sp@-
  88. movel d0, sp@-
  89. jbsr SYM (__udivsi3) /* divide abs(dividend) by abs(divisor) */
  90. addql IMM (8), sp
  91. tstb d2
  92. jpl L3
  93. negl d0
  94. L3: movel sp@+, d2
  95. rts