add_n.S 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  1. /* mpn_add_n -- add (or subtract) bignums.
  2. Copyright (C) 2013-2026 Free Software Foundation, Inc.
  3. This file is part of the GNU C Library.
  4. The GNU C Library is free software; you can redistribute it and/or
  5. modify it under the terms of the GNU Lesser General Public
  6. License as published by the Free Software Foundation; either
  7. version 2.1 of the License, or (at your option) any later version.
  8. The GNU C Library is distributed in the hope that it will be useful,
  9. but WITHOUT ANY WARRANTY; without even the implied warranty of
  10. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  11. Lesser General Public License for more details.
  12. You should have received a copy of the GNU Lesser General Public
  13. License along with the GNU C Library. If not, see
  14. <https://www.gnu.org/licenses/>. */
  15. #include <sysdep.h>
  16. #include <arm-features.h>
  17. .syntax unified
  18. .text
  19. #ifdef USE_AS_SUB_N
  20. # define INITC cmp r0, r0
  21. # define OPC sbcs
  22. # define RETC sbc r0, r0, r0; neg r0, r0
  23. # define FUNC __mpn_sub_n
  24. #else
  25. # define INITC cmn r0, #0
  26. # define OPC adcs
  27. # define RETC mov r0, #0; adc r0, r0, r0
  28. # define FUNC __mpn_add_n
  29. #endif
  30. /* mp_limb_t mpn_add_n(res_ptr, src1_ptr, src2_ptr, size) */
  31. ENTRY (FUNC)
  32. push { r4, r5, r6, r7, r8, r10, lr }
  33. cfi_adjust_cfa_offset (28)
  34. cfi_rel_offset (r4, 0)
  35. cfi_rel_offset (r5, 4)
  36. cfi_rel_offset (r6, 8)
  37. cfi_rel_offset (r7, 12)
  38. cfi_rel_offset (r8, 16)
  39. cfi_rel_offset (r10, 20)
  40. cfi_rel_offset (lr, 24)
  41. INITC /* initialize carry flag */
  42. tst r3, #1 /* count & 1 == 1? */
  43. add lr, r1, r3, lsl #2 /* compute end src1 */
  44. beq 1f
  45. ldr r4, [r1], #4 /* do one to make count even */
  46. ldr r5, [r2], #4
  47. OPC r4, r4, r5
  48. teq r1, lr /* end of count? (preserve carry) */
  49. str r4, [r0], #4
  50. beq 9f
  51. 1:
  52. tst r3, #2 /* count & 2 == 2? */
  53. beq 2f
  54. ldm r1!, { r4, r5 } /* do two to make count 0 mod 4 */
  55. ldm r2!, { r6, r7 }
  56. OPC r4, r4, r6
  57. OPC r5, r5, r7
  58. teq r1, lr /* end of count? */
  59. stm r0!, { r4, r5 }
  60. beq 9f
  61. 2:
  62. ldm r1!, { r3, r5, r7, r10 } /* do four each loop */
  63. ldm r2!, { r4, r6, r8, ip }
  64. OPC r3, r3, r4
  65. OPC r5, r5, r6
  66. OPC r7, r7, r8
  67. OPC r10, r10, ip
  68. teq r1, lr
  69. stm r0!, { r3, r5, r7, r10 }
  70. bne 2b
  71. 9:
  72. RETC /* copy carry out */
  73. #ifndef ARM_ALWAYS_BX
  74. pop { r4, r5, r6, r7, r8, r10, pc }
  75. #else
  76. pop { r4, r5, r6, r7, r8, r10, lr }
  77. bx lr
  78. #endif
  79. END (FUNC)