memset.S 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  1. /*
  2. * Copyright 2004-2009 Analog Devices Inc.
  3. *
  4. * Licensed under the Clear BSD license or the GPL-2 (or later)
  5. */
  6. #include <linux/linkage.h>
  7. .align 2
  8. #ifdef CONFIG_MEMSET_L1
  9. .section .l1.text
  10. #else
  11. .text
  12. #endif
  13. /*
  14. * C Library function MEMSET
  15. * R0 = address (leave unchanged to form result)
  16. * R1 = filler byte
  17. * R2 = count
  18. * Favours word aligned data.
  19. * The strncpy assumes that I0 and I1 are not used in this function
  20. */
  21. ENTRY(_memset)
  22. P0 = R0 ; /* P0 = address */
  23. P2 = R2 ; /* P2 = count */
  24. R3 = R0 + R2; /* end */
  25. CC = R2 <= 7(IU);
  26. IF CC JUMP .Ltoo_small;
  27. R1 = R1.B (Z); /* R1 = fill char */
  28. R2 = 3;
  29. R2 = R0 & R2; /* addr bottom two bits */
  30. CC = R2 == 0; /* AZ set if zero. */
  31. IF !CC JUMP .Lforce_align ; /* Jump if addr not aligned. */
  32. .Laligned:
  33. P1 = P2 >> 2; /* count = n/4 */
  34. R2 = R1 << 8; /* create quad filler */
  35. R2.L = R2.L + R1.L(NS);
  36. R2.H = R2.L + R1.H(NS);
  37. P2 = R3;
  38. LSETUP (.Lquad_loop , .Lquad_loop) LC0=P1;
  39. .Lquad_loop:
  40. [P0++] = R2;
  41. CC = P0 == P2;
  42. IF !CC JUMP .Lbytes_left;
  43. RTS;
  44. .Lbytes_left:
  45. R2 = R3; /* end point */
  46. R3 = P0; /* current position */
  47. R2 = R2 - R3; /* bytes left */
  48. P2 = R2;
  49. .Ltoo_small:
  50. CC = P2 == 0; /* Check zero count */
  51. IF CC JUMP .Lfinished; /* Unusual */
  52. .Lbytes:
  53. LSETUP (.Lbyte_loop , .Lbyte_loop) LC0=P2;
  54. .Lbyte_loop:
  55. B[P0++] = R1;
  56. .Lfinished:
  57. RTS;
  58. .Lforce_align:
  59. CC = BITTST (R0, 0); /* odd byte */
  60. R0 = 4;
  61. R0 = R0 - R2;
  62. P1 = R0;
  63. R0 = P0; /* Recover return address */
  64. IF !CC JUMP .Lskip1;
  65. B[P0++] = R1;
  66. .Lskip1:
  67. CC = R2 <= 2; /* 2 bytes */
  68. P2 -= P1; /* reduce count */
  69. IF !CC JUMP .Laligned;
  70. B[P0++] = R1;
  71. B[P0++] = R1;
  72. JUMP .Laligned;
  73. ENDPROC(_memset)