l_shl.s 835 B

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  1. .text
  2. .align 4
  3. .code 32
  4. .global L_shl
  5. .type L_shl, %function
  6. #L_shl:
  7. # CMP r0,#0
  8. # BEQ .END
  9. # CMP r1,#0
  10. # BEQ .END
  11. #
  12. # @* right shift
  13. # SUBLT r1,#1
  14. # EORLT r1,r1,r1, ASR #31
  15. # ASRLT r0,r0,r1
  16. # BLT .END
  17. #
  18. # @* left shift
  19. # CMP r0,#0
  20. # MVNLT r2,r0
  21. # CLZ r2,r2
  22. # SUB r2,r2,#1
  23. #
  24. # CMP r1,r2
  25. # LSLLE r0,r0,r1
  26. # BLE .END
  27. #
  28. # @* Overflow
  29. # CMP r0,#0
  30. # MOVGT r0,#0x7FFFFFFF
  31. # MOVLT r0,#0x8000000
  32. #.END:
  33. # BX lr
  34. L_shl:
  35. MOV r2,r0
  36. CMP r0,#0
  37. BEQ END
  38. CMP r1,#0
  39. BEQ END
  40. BLT R_SHIFT
  41. L_SHIFT:
  42. CMP r1,#31
  43. BGT OVERFLOW
  44. LSL r0,r0,r1
  45. CMP r2,r0,ASR r1
  46. BEQ END
  47. B OVERFLOW
  48. R_SHIFT:
  49. SUB r1,#1
  50. EOR r1,r1,r1, ASR # 31
  51. CMP r1,#31
  52. BGT UNDERFLOW
  53. ASR r0,r0,r1
  54. B END
  55. OVERFLOW:
  56. CMP r2,#0
  57. MOVGT r0,#0x7FFFFFFF
  58. MOVLT r0,#0x80000000
  59. B END
  60. UNDERFLOW:
  61. CMP r2,#0
  62. MOVGT r0,#0
  63. MVNLT r0,#0
  64. B END
  65. END:
  66. BX lr