memset.S 992 B

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. /* $OpenBSD: memset.S,v 1.4 2014/11/29 18:51:23 tedu Exp $ */
  2. /*
  3. * Written by J.T. Conklin <jtc@netbsd.org>.
  4. * Public domain.
  5. */
  6. #include <machine/asm.h>
  7. ENTRY(memset)
  8. pushl %edi
  9. pushl %ebx
  10. movl 12(%esp),%edi
  11. movzbl 16(%esp),%eax /* unsigned char, zero extend */
  12. movl 20(%esp),%ecx
  13. pushl %edi /* push address of buffer */
  14. /*
  15. * if the string is too short, it's really not worth the overhead
  16. * of aligning to word boundaries, etc. So we jump to a plain
  17. * unaligned set.
  18. */
  19. cmpl $0x0f,%ecx
  20. jle L1
  21. movb %al,%ah /* copy char to all bytes in word */
  22. movl %eax,%edx
  23. sall $16,%eax
  24. orl %edx,%eax
  25. movl %edi,%edx /* compute misalignment */
  26. negl %edx
  27. andl $3,%edx
  28. movl %ecx,%ebx
  29. subl %edx,%ebx
  30. movl %edx,%ecx /* set until word aligned */
  31. rep
  32. stosb
  33. movl %ebx,%ecx
  34. shrl $2,%ecx /* set by words */
  35. rep
  36. stosl
  37. movl %ebx,%ecx /* set remainder by bytes */
  38. andl $3,%ecx
  39. L1: rep
  40. stosb
  41. popl %eax /* pop address of buffer */
  42. popl %ebx
  43. popl %edi
  44. ret