Teensy 4.1 core updated for C++20
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

92 lines
2.6KB

  1. /*
  2. * Copyright (c) 2014 Travis Geiselbrecht
  3. *
  4. * Permission is hereby granted, free of charge, to any person obtaining
  5. * a copy of this software and associated documentation files
  6. * (the "Software"), to deal in the Software without restriction,
  7. * including without limitation the rights to use, copy, modify, merge,
  8. * publish, distribute, sublicense, and/or sell copies of the Software,
  9. * and to permit persons to whom the Software is furnished to do so,
  10. * subject to the following conditions:
  11. *
  12. * The above copyright notice and this permission notice shall be
  13. * included in all copies or substantial portions of the Software.
  14. *
  15. * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
  16. * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
  17. * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
  18. * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
  19. * CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
  20. * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
  21. * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
  22. */
  23. //#include <asm.h>
  24. //#include <arch/arm/cores.h>
  25. #if defined (__ARM_ARCH_7M__) || defined (__ARM_ARCH_7EM__)
  26. .global memset
  27. .text
  28. .syntax unified
  29. .thumb
  30. .align 2
  31. /* void *memset(void *s, int c, size_t n); */
  32. .type memset, %function
  33. .thumb_func
  34. memset:
  35. //FUNCTION(memset)
  36. // save the original pointer
  37. push { r0, lr }
  38. // check for zero length
  39. cbz r2, .L_done
  40. // short memsets aren't worth optimizing and make sure we have
  41. // enough headroom to try to do dwordwise move optimization
  42. cmp r2, #16
  43. blt .L_bytewise
  44. // see how many bytes we need to move to align to dword boundaries
  45. and r3, r0, #7
  46. cbz r3, .L_prepare_dwordwise
  47. rsb r3, #8
  48. subs r2, r3
  49. .L_bytewise_align:
  50. // bytewise to align memset
  51. subs r3, r3, #1
  52. strb r1, [r0], #1
  53. bgt .L_bytewise_align
  54. .L_prepare_dwordwise:
  55. // fill a pair of 32 bit registers with the 8 bit value
  56. uxtb r1, r1
  57. orr r1, r1, r1, lsl #8
  58. orr r1, r1, r1, lsl #16
  59. mov r12, r1
  60. // load the number of dwords left
  61. lsrs r3, r2, #3
  62. .L_dwordwise:
  63. // dwordwise memset
  64. subs r3, r3, #1
  65. strd r1, r12, [r0], #8
  66. bgt .L_dwordwise
  67. // remaining bytes
  68. ands r2, #7
  69. beq .L_done
  70. .L_bytewise:
  71. // bytewise memset
  72. subs r2, r2, #1
  73. strb r1, [r0], #1
  74. bgt .L_bytewise
  75. .L_done:
  76. // restore the base pointer as return value
  77. pop { r0, pc }
  78. #endif