Guest User

sh2_fixed.s

a guest
Mar 31st, 2025
45
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.47 KB | None | 0 0
  1. ! The MIT License (MIT)
  2. !
  3. ! Permission is hereby granted, free of charge, to any person obtaining a copy
  4. ! of this software and associated documentation files (the "Software"), to deal
  5. ! in the Software without restriction, including without limitation the rights
  6. ! to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
  7. ! copies of the Software, and to permit persons to whom the Software is
  8. ! furnished to do so, subject to the following conditions:
  9. !
  10. ! The above copyright notice and this permission notice shall be included in all
  11. ! copies or substantial portions of the Software.
  12. !
  13. ! THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  14. ! IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  15. ! FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  16. ! AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  17. ! LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
  18. ! OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
  19. ! SOFTWARE.
  20.  
  21. .section .sdata
  22.  
  23. ! #define FixedMul(a,b) (((int64_t)(a) * (b))>>16)
  24.  
  25. ! Perform a signed 16.16 by 16.16 multiply ! On entry: r4 = a, r5 = b ! On exit: r0 = (a * b) >> 16
  26. .align 4
  27. .global _FixedMul2
  28. _FixedMul2:
  29. dmuls.l r4,r5
  30. sts mach,r1
  31. sts macl,r0
  32. rts
  33. xtrct r1,r0
  34.  
  35. ! Perform a signed 16.16 by 16.16 divide ! On entry: r4 = a, r5 = b ! On exit: r0 = (a << 16) / b
  36.  
  37. .align 4
  38. .global _FixedDiv
  39. _FixedDiv:
  40. mov.l _sh2_div_unit,r2
  41. swap.w r4,r0
  42. mov.l r5,@r2 /* set 32-bit divisor */
  43. exts.w r0, r0
  44. mov.l r0,@(16,r2) /* set high long of 64-bit dividend */
  45. shll16 r4
  46. mov.l r4,@(20,r2) /* set low long of 64-bit dividend, start divide */
  47. /* note - overflow returns 0x7FFFFFFF or 0x80000000 after 6 cycles
  48. no overflow returns the quotient after 39 cycles */
  49. rts
  50. mov.l @(20,r2),r0 /* return 32-bit quotient */
  51.  
  52. ! Perform a signed 32 by 32 divide ! On entry: r4 = a, r5 = b ! On exit: r0 = a / b
  53.  
  54. .align 4
  55. .global _IDiv
  56. _IDiv:
  57. mov.l _sh2_div_unit,r2
  58. mov.l r5,@r2 /* set 32-bit divisor */
  59. mov.l r4,@(4,r2) /* set 32-bit dividend, start divide */
  60. /* note - overflow returns 0x7FFFFFFF or 0x80000000 after 6 cycles
  61. no overflow returns the quotient after 39 cycles */
  62. rts
  63. mov.l @(4,r2),r0 /* return 32-bit quotient */
  64.  
  65. .align 2
  66.  
  67. _sh2_div_unit:
  68. .long 0xFFFFFF00
  69.  
Advertisement
Add Comment
Please, Sign In to add comment