lshrsi3.S 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111
  1. ; Copyright (C) 2011-2022 Free Software Foundation, Inc.
  2. ; Contributed by Red Hat.
  3. ;
  4. ; This file 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 3, or (at your option) any
  7. ; later version.
  8. ;
  9. ; This file is distributed in the hope that it will be useful, but
  10. ; WITHOUT ANY WARRANTY; without even the implied warranty of
  11. ; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  12. ; General Public License for more details.
  13. ;
  14. ; Under Section 7 of GPL version 3, you are granted additional
  15. ; permissions described in the GCC Runtime Library Exception, version
  16. ; 3.1, as published by the Free Software Foundation.
  17. ;
  18. ; You should have received a copy of the GNU General Public License and
  19. ; a copy of the GCC Runtime Library Exception along with this program;
  20. ; see the files COPYING3 and COPYING.RUNTIME respectively. If not, see
  21. ; <http://www.gnu.org/licenses/>.
  22. #include "vregs.h"
  23. START_FUNC ___lshrsi3
  24. ;; input:
  25. ;;
  26. ;; [zero]
  27. ;; [count] <= $sp+8
  28. ;; [in MSB]
  29. ;; [in]
  30. ;; [in]
  31. ;; [in LSB] <- $sp+4
  32. ;; output:
  33. ;;
  34. ;; [r8..r11] result
  35. ;; registers:
  36. ;;
  37. ;; AX - temp for shift/rotate
  38. ;; B - count
  39. mov a, [sp+8] ; A now contains the count
  40. cmp a, #0x20
  41. bc $.Lcount_is_normal
  42. ;; count is out of bounds, just return zero.
  43. movw r8, #0
  44. movw r10, #0
  45. ret
  46. .Lcount_is_normal:
  47. cmp0 a
  48. bnz $.Lcount_is_nonzero
  49. ;; count is zero, just copy IN to OUT
  50. movw ax, [sp+4]
  51. movw r8, ax
  52. movw ax, [sp+6]
  53. movw r10, ax
  54. ret
  55. .Lcount_is_nonzero:
  56. mov b, a ; B now contains the count also
  57. bf a.4, $.Lcount_lt_16
  58. ;; count >= 16, shift 16 at a time.
  59. movw r10, #0
  60. movw ax, [sp+6]
  61. movw r8, ax
  62. mov a, b
  63. and a, #0x0f
  64. sknz
  65. ret
  66. mov b, a ; B now contains the remaining count
  67. inc b
  68. br $.Lloop_top
  69. .Lcount_lt_16:
  70. ;; count is nonzero. Do one
  71. movw ax, [sp+6]
  72. shrw ax,1
  73. movw r10, ax
  74. mov a, [sp+5]
  75. rorc a,1
  76. mov r9, a
  77. mov a, [sp+4]
  78. rorc a,1
  79. mov r8, a
  80. ;; we did one shift above; do as many more as we need now.
  81. .Lloop_top:
  82. dec b
  83. sknz
  84. ret
  85. movw ax, r10
  86. shrw ax,1
  87. movw r10, ax
  88. mov a, r9
  89. rorc a,1
  90. mov r9, a
  91. mov a, r8
  92. rorc a,1
  93. mov r8, a
  94. br $.Lloop_top
  95. END_FUNC ___lshrsi3