memset.S 2.6 KB

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