memset.S 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  1. /* memset.S
  2. * Copyright (C) 2003, 2005, 2006 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. /* void *memset(void *s, int c, size_t n);
  12. * R0 = address (s) (leave unchanged to form result)
  13. * R1 = filler byte (c)
  14. * R2 = count (n)
  15. *
  16. * Note: Favours word aligned data.
  17. */
  18. .text
  19. .align 2
  20. .global _memset
  21. .type _memset, STT_FUNC
  22. _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 too_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 force_align ; // Jump if addr not aligned.
  33. aligned:
  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 (quad_loop , quad_loop) LC0=P1;
  40. quad_loop:
  41. [P0++] = R2;
  42. CC = P0 == P2;
  43. IF !CC JUMP bytes_left;
  44. RTS;
  45. bytes_left:
  46. R2 = R3; // end point
  47. R3 = P0; // current position
  48. R2 = R2 - R3; // bytes left
  49. P2 = R2;
  50. too_small:
  51. CC = P2 == 0; //Check zero count
  52. IF CC JUMP finished; // Unusual
  53. bytes: LSETUP (byte_loop , byte_loop) LC0=P2;
  54. byte_loop: B[P0++] = R1;
  55. finished:
  56. RTS;
  57. force_align:
  58. CC = BITTST (R0, 0 ); // odd byte
  59. R0 = 4;
  60. R0 = R0 - R2;
  61. P1 = R0;
  62. R0 = P0; // Recover return address
  63. IF !CC JUMP skip1;
  64. B[P0++] = R1;
  65. skip1:
  66. CC = R2 <= 2; // 2 bytes
  67. P2 -= P1; // reduce count
  68. IF !CC JUMP aligned;
  69. B[P0++] = R1;
  70. B[P0++] = R1;
  71. JUMP aligned;
  72. .size _memset,.-_memset
  73. libc_hidden_def (memset)