fpsimdmacros.h 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133
  1. /*
  2. * FP/SIMD state saving and restoring macros
  3. *
  4. * Copyright (C) 2012 ARM Ltd.
  5. * Author: Catalin Marinas <catalin.marinas@arm.com>
  6. *
  7. * This program is free software; you can redistribute it and/or modify
  8. * it under the terms of the GNU General Public License version 2 as
  9. * published by the Free Software Foundation.
  10. *
  11. * This program is distributed in the hope that it will be useful,
  12. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  14. * GNU General Public License for more details.
  15. *
  16. * You should have received a copy of the GNU General Public License
  17. * along with this program. If not, see <http://www.gnu.org/licenses/>.
  18. */
  19. .macro fpsimd_save state, tmpnr
  20. stp q0, q1, [\state, #16 * 0]
  21. stp q2, q3, [\state, #16 * 2]
  22. stp q4, q5, [\state, #16 * 4]
  23. stp q6, q7, [\state, #16 * 6]
  24. stp q8, q9, [\state, #16 * 8]
  25. stp q10, q11, [\state, #16 * 10]
  26. stp q12, q13, [\state, #16 * 12]
  27. stp q14, q15, [\state, #16 * 14]
  28. stp q16, q17, [\state, #16 * 16]
  29. stp q18, q19, [\state, #16 * 18]
  30. stp q20, q21, [\state, #16 * 20]
  31. stp q22, q23, [\state, #16 * 22]
  32. stp q24, q25, [\state, #16 * 24]
  33. stp q26, q27, [\state, #16 * 26]
  34. stp q28, q29, [\state, #16 * 28]
  35. stp q30, q31, [\state, #16 * 30]!
  36. mrs x\tmpnr, fpsr
  37. str w\tmpnr, [\state, #16 * 2]
  38. mrs x\tmpnr, fpcr
  39. str w\tmpnr, [\state, #16 * 2 + 4]
  40. .endm
  41. .macro fpsimd_restore_fpcr state, tmp
  42. /*
  43. * Writes to fpcr may be self-synchronising, so avoid restoring
  44. * the register if it hasn't changed.
  45. */
  46. mrs \tmp, fpcr
  47. cmp \tmp, \state
  48. b.eq 9999f
  49. msr fpcr, \state
  50. 9999:
  51. .endm
  52. /* Clobbers \state */
  53. .macro fpsimd_restore state, tmpnr
  54. ldp q0, q1, [\state, #16 * 0]
  55. ldp q2, q3, [\state, #16 * 2]
  56. ldp q4, q5, [\state, #16 * 4]
  57. ldp q6, q7, [\state, #16 * 6]
  58. ldp q8, q9, [\state, #16 * 8]
  59. ldp q10, q11, [\state, #16 * 10]
  60. ldp q12, q13, [\state, #16 * 12]
  61. ldp q14, q15, [\state, #16 * 14]
  62. ldp q16, q17, [\state, #16 * 16]
  63. ldp q18, q19, [\state, #16 * 18]
  64. ldp q20, q21, [\state, #16 * 20]
  65. ldp q22, q23, [\state, #16 * 22]
  66. ldp q24, q25, [\state, #16 * 24]
  67. ldp q26, q27, [\state, #16 * 26]
  68. ldp q28, q29, [\state, #16 * 28]
  69. ldp q30, q31, [\state, #16 * 30]!
  70. ldr w\tmpnr, [\state, #16 * 2]
  71. msr fpsr, x\tmpnr
  72. ldr w\tmpnr, [\state, #16 * 2 + 4]
  73. fpsimd_restore_fpcr x\tmpnr, \state
  74. .endm
  75. .macro fpsimd_save_partial state, numnr, tmpnr1, tmpnr2
  76. mrs x\tmpnr1, fpsr
  77. str w\numnr, [\state, #8]
  78. mrs x\tmpnr2, fpcr
  79. stp w\tmpnr1, w\tmpnr2, [\state]
  80. adr x\tmpnr1, 0f
  81. add \state, \state, x\numnr, lsl #4
  82. sub x\tmpnr1, x\tmpnr1, x\numnr, lsl #1
  83. br x\tmpnr1
  84. stp q30, q31, [\state, #-16 * 30 - 16]
  85. stp q28, q29, [\state, #-16 * 28 - 16]
  86. stp q26, q27, [\state, #-16 * 26 - 16]
  87. stp q24, q25, [\state, #-16 * 24 - 16]
  88. stp q22, q23, [\state, #-16 * 22 - 16]
  89. stp q20, q21, [\state, #-16 * 20 - 16]
  90. stp q18, q19, [\state, #-16 * 18 - 16]
  91. stp q16, q17, [\state, #-16 * 16 - 16]
  92. stp q14, q15, [\state, #-16 * 14 - 16]
  93. stp q12, q13, [\state, #-16 * 12 - 16]
  94. stp q10, q11, [\state, #-16 * 10 - 16]
  95. stp q8, q9, [\state, #-16 * 8 - 16]
  96. stp q6, q7, [\state, #-16 * 6 - 16]
  97. stp q4, q5, [\state, #-16 * 4 - 16]
  98. stp q2, q3, [\state, #-16 * 2 - 16]
  99. stp q0, q1, [\state, #-16 * 0 - 16]
  100. 0:
  101. .endm
  102. .macro fpsimd_restore_partial state, tmpnr1, tmpnr2
  103. ldp w\tmpnr1, w\tmpnr2, [\state]
  104. msr fpsr, x\tmpnr1
  105. fpsimd_restore_fpcr x\tmpnr2, x\tmpnr1
  106. adr x\tmpnr1, 0f
  107. ldr w\tmpnr2, [\state, #8]
  108. add \state, \state, x\tmpnr2, lsl #4
  109. sub x\tmpnr1, x\tmpnr1, x\tmpnr2, lsl #1
  110. br x\tmpnr1
  111. ldp q30, q31, [\state, #-16 * 30 - 16]
  112. ldp q28, q29, [\state, #-16 * 28 - 16]
  113. ldp q26, q27, [\state, #-16 * 26 - 16]
  114. ldp q24, q25, [\state, #-16 * 24 - 16]
  115. ldp q22, q23, [\state, #-16 * 22 - 16]
  116. ldp q20, q21, [\state, #-16 * 20 - 16]
  117. ldp q18, q19, [\state, #-16 * 18 - 16]
  118. ldp q16, q17, [\state, #-16 * 16 - 16]
  119. ldp q14, q15, [\state, #-16 * 14 - 16]
  120. ldp q12, q13, [\state, #-16 * 12 - 16]
  121. ldp q10, q11, [\state, #-16 * 10 - 16]
  122. ldp q8, q9, [\state, #-16 * 8 - 16]
  123. ldp q6, q7, [\state, #-16 * 6 - 16]
  124. ldp q4, q5, [\state, #-16 * 4 - 16]
  125. ldp q2, q3, [\state, #-16 * 2 - 16]
  126. ldp q0, q1, [\state, #-16 * 0 - 16]
  127. 0:
  128. .endm