memset.S 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596
  1. /*
  2. * File: memset.S
  3. *
  4. * Copyright 2004-2007 Analog Devices Inc.
  5. * Enter bugs at http://blackfin.uclinux.org/
  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 as published by
  9. * the Free Software Foundation; either version 2 of the License, or
  10. * (at your option) any later version.
  11. *
  12. * This program is distributed in the hope that it will be useful,
  13. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  14. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  15. * GNU General Public License for more details.
  16. *
  17. * You should have received a copy of the GNU General Public License
  18. * along with this program; if not, see the file COPYING, or write
  19. * to the Free Software Foundation, Inc.,
  20. * 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
  21. */
  22. .align 2
  23. /*
  24. * C Library function MEMSET
  25. * R0 = address (leave unchanged to form result)
  26. * R1 = filler byte
  27. * R2 = count
  28. * Favours word aligned data.
  29. */
  30. .globl _memset;
  31. .type _memset, STT_FUNC;
  32. _memset:
  33. P0 = R0 ; /* P0 = address */
  34. P2 = R2 ; /* P2 = count */
  35. R3 = R0 + R2; /* end */
  36. CC = R2 <= 7(IU);
  37. IF CC JUMP .Ltoo_small;
  38. R1 = R1.B (Z); /* R1 = fill char */
  39. R2 = 3;
  40. R2 = R0 & R2; /* addr bottom two bits */
  41. CC = R2 == 0; /* AZ set if zero. */
  42. IF !CC JUMP .Lforce_align ; /* Jump if addr not aligned. */
  43. .Laligned:
  44. P1 = P2 >> 2; /* count = n/4 */
  45. R2 = R1 << 8; /* create quad filler */
  46. R2.L = R2.L + R1.L(NS);
  47. R2.H = R2.L + R1.H(NS);
  48. P2 = R3;
  49. LSETUP (.Lquad_loop , .Lquad_loop) LC0=P1;
  50. .Lquad_loop:
  51. [P0++] = R2;
  52. CC = P0 == P2;
  53. IF !CC JUMP .Lbytes_left;
  54. RTS;
  55. .Lbytes_left:
  56. R2 = R3; /* end point */
  57. R3 = P0; /* current position */
  58. R2 = R2 - R3; /* bytes left */
  59. P2 = R2;
  60. .Ltoo_small:
  61. CC = P2 == 0; /* Check zero count */
  62. IF CC JUMP .Lfinished; /* Unusual */
  63. .Lbytes:
  64. LSETUP (.Lbyte_loop , .Lbyte_loop) LC0=P2;
  65. .Lbyte_loop:
  66. B[P0++] = R1;
  67. .Lfinished:
  68. RTS;
  69. .Lforce_align:
  70. CC = BITTST (R0, 0); /* odd byte */
  71. R0 = 4;
  72. R0 = R0 - R2;
  73. P1 = R0;
  74. R0 = P0; /* Recover return address */
  75. IF !CC JUMP .Lskip1;
  76. B[P0++] = R1;
  77. .Lskip1:
  78. CC = R2 <= 2; /* 2 bytes */
  79. P2 -= P1; /* reduce count */
  80. IF !CC JUMP .Laligned;
  81. B[P0++] = R1;
  82. B[P0++] = R1;
  83. JUMP .Laligned;
  84. .size _memset, .-_memset