memset.S 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596
  1. /* memset.S
  2. * Copyright (C) 2003-2007 Analog Devices Inc., All Rights Reserved.
  3. *
  4. * This file is subject to the terms and conditions of the GNU Library General
  5. * Public License. See the file "COPYING.LIB" in the main directory of this
  6. * archive for more details.
  7. *
  8. * Non-LGPL License also available as part of VisualDSP++
  9. * http://www.analog.com/processors/resources/crosscore/visualDspDevSoftware.html
  10. */
  11. #include <sysdep.h>
  12. /* void *memset(void *s, int c, size_t n);
  13. * R0 = address (s) (leave unchanged to form result)
  14. * R1 = filler byte (c)
  15. * R2 = count (n)
  16. *
  17. * Note: Favours word aligned data.
  18. */
  19. .text
  20. .align 2
  21. /* We have to bypass the libc-symbols.h machinery to make sure we get
  22. * a weak symbol for memcpy (some crummy gcc tests want to redefine it).
  23. */
  24. .global ___GI_memset
  25. .type ___GI_memset, STT_FUNC
  26. ___GI_memset:
  27. P0 = R0 ; /* P0 = address */
  28. P2 = R2 ; /* P2 = count */
  29. R3 = R0 + R2; /* end */
  30. CC = R2 <= 7(IU);
  31. IF CC JUMP .Ltoo_small;
  32. R1 = R1.B (Z); /* R1 = fill char */
  33. R2 = 3;
  34. R2 = R0 & R2; /* addr bottom two bits */
  35. CC = R2 == 0; /* AZ set if zero. */
  36. IF !CC JUMP .Lforce_align ; /* Jump if addr not aligned. */
  37. .Laligned:
  38. P1 = P2 >> 2; /* count = n/4 */
  39. R2 = R1 << 8; /* create quad filler */
  40. R2.L = R2.L + R1.L(NS);
  41. R2.H = R2.L + R1.H(NS);
  42. P2 = R3;
  43. LSETUP (.Lquad_loop , .Lquad_loop) LC0=P1;
  44. .Lquad_loop:
  45. [P0++] = R2;
  46. CC = P0 == P2;
  47. IF !CC JUMP .Lbytes_left;
  48. RTS;
  49. .Lbytes_left:
  50. R2 = R3; /* end point */
  51. R3 = P0; /* current position */
  52. R2 = R2 - R3; /* bytes left */
  53. P2 = R2;
  54. .Ltoo_small:
  55. CC = P2 == 0; /* Check zero count */
  56. IF CC JUMP .Lfinished; /* Unusual */
  57. .Lbytes:
  58. LSETUP (.Lbyte_loop , .Lbyte_loop) LC0=P2;
  59. .Lbyte_loop:
  60. B[P0++] = R1;
  61. .Lfinished:
  62. RTS;
  63. .Lforce_align:
  64. CC = BITTST (R0, 0); /* odd byte */
  65. R0 = 4;
  66. R0 = R0 - R2;
  67. P1 = R0;
  68. R0 = P0; /* Recover return address */
  69. IF !CC JUMP .Lskip1;
  70. B[P0++] = R1;
  71. .Lskip1:
  72. CC = R2 <= 2; /* 2 bytes */
  73. P2 -= P1; /* reduce count */
  74. IF !CC JUMP .Laligned;
  75. B[P0++] = R1;
  76. B[P0++] = R1;
  77. JUMP .Laligned;
  78. .size ___GI_memset,.-___GI_memset
  79. .hidden ___GI_memset
  80. .weak _memset
  81. .set _memset,___GI_memset