divsi3.S 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124
  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. #include <asm/export.h>
  30. /* These are predefined by new versions of GNU cpp. */
  31. #ifndef __USER_LABEL_PREFIX__
  32. #define __USER_LABEL_PREFIX__ _
  33. #endif
  34. #ifndef __REGISTER_PREFIX__
  35. #define __REGISTER_PREFIX__
  36. #endif
  37. #ifndef __IMMEDIATE_PREFIX__
  38. #define __IMMEDIATE_PREFIX__ #
  39. #endif
  40. /* ANSI concatenation macros. */
  41. #define CONCAT1(a, b) CONCAT2(a, b)
  42. #define CONCAT2(a, b) a ## b
  43. /* Use the right prefix for global labels. */
  44. #define SYM(x) CONCAT1 (__USER_LABEL_PREFIX__, x)
  45. /* Use the right prefix for registers. */
  46. #define REG(x) CONCAT1 (__REGISTER_PREFIX__, x)
  47. /* Use the right prefix for immediate values. */
  48. #define IMM(x) CONCAT1 (__IMMEDIATE_PREFIX__, x)
  49. #define d0 REG (d0)
  50. #define d1 REG (d1)
  51. #define d2 REG (d2)
  52. #define d3 REG (d3)
  53. #define d4 REG (d4)
  54. #define d5 REG (d5)
  55. #define d6 REG (d6)
  56. #define d7 REG (d7)
  57. #define a0 REG (a0)
  58. #define a1 REG (a1)
  59. #define a2 REG (a2)
  60. #define a3 REG (a3)
  61. #define a4 REG (a4)
  62. #define a5 REG (a5)
  63. #define a6 REG (a6)
  64. #define fp REG (fp)
  65. #define sp REG (sp)
  66. .text
  67. .proc
  68. .globl SYM (__divsi3)
  69. SYM (__divsi3):
  70. movel d2, sp@-
  71. moveq IMM (1), d2 /* sign of result stored in d2 (=1 or =-1) */
  72. movel sp@(12), d1 /* d1 = divisor */
  73. jpl L1
  74. negl d1
  75. #if !(defined(__mcf5200__) || defined(__mcoldfire__))
  76. negb d2 /* change sign because divisor <0 */
  77. #else
  78. negl d2 /* change sign because divisor <0 */
  79. #endif
  80. L1: movel sp@(8), d0 /* d0 = dividend */
  81. jpl L2
  82. negl d0
  83. #if !(defined(__mcf5200__) || defined(__mcoldfire__))
  84. negb d2
  85. #else
  86. negl d2
  87. #endif
  88. L2: movel d1, sp@-
  89. movel d0, sp@-
  90. jbsr SYM (__udivsi3) /* divide abs(dividend) by abs(divisor) */
  91. addql IMM (8), sp
  92. tstb d2
  93. jpl L3
  94. negl d0
  95. L3: movel sp@+, d2
  96. rts
  97. EXPORT_SYMBOL(__divsi3)