memset.S 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  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. .weak _memset
  22. ENTRY(_memset)
  23. P0 = R0 ; /* P0 = address */
  24. P2 = R2 ; /* P2 = count */
  25. R3 = R0 + R2; /* end */
  26. CC = R2 <= 7(IU);
  27. IF CC JUMP .Ltoo_small;
  28. R1 = R1.B (Z); /* R1 = fill char */
  29. R2 = 3;
  30. R2 = R0 & R2; /* addr bottom two bits */
  31. CC = R2 == 0; /* AZ set if zero. */
  32. IF !CC JUMP .Lforce_align ; /* Jump if addr not aligned. */
  33. .Laligned:
  34. P1 = P2 >> 2; /* count = n/4 */
  35. R2 = R1 << 8; /* create quad filler */
  36. R2.L = R2.L + R1.L(NS);
  37. R2.H = R2.L + R1.H(NS);
  38. P2 = R3;
  39. LSETUP (.Lquad_loop , .Lquad_loop) LC0=P1;
  40. .Lquad_loop:
  41. [P0++] = R2;
  42. CC = P0 == P2;
  43. IF !CC JUMP .Lbytes_left;
  44. RTS;
  45. .Lbytes_left:
  46. R2 = R3; /* end point */
  47. R3 = P0; /* current position */
  48. R2 = R2 - R3; /* bytes left */
  49. P2 = R2;
  50. .Ltoo_small:
  51. CC = P2 == 0; /* Check zero count */
  52. IF CC JUMP .Lfinished; /* Unusual */
  53. .Lbytes:
  54. LSETUP (.Lbyte_loop , .Lbyte_loop) LC0=P2;
  55. .Lbyte_loop:
  56. B[P0++] = R1;
  57. .Lfinished:
  58. RTS;
  59. .Lforce_align:
  60. CC = BITTST (R0, 0); /* odd byte */
  61. R0 = 4;
  62. R0 = R0 - R2;
  63. P1 = R0;
  64. R0 = P0; /* Recover return address */
  65. IF !CC JUMP .Lskip1;
  66. B[P0++] = R1;
  67. .Lskip1:
  68. CC = R2 <= 2; /* 2 bytes */
  69. P2 -= P1; /* reduce count */
  70. IF !CC JUMP .Laligned;
  71. B[P0++] = R1;
  72. B[P0++] = R1;
  73. JUMP .Laligned;
  74. .size _memset,.-_memset
  75. libc_hidden_def (memset)