memset.S 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. /* memset with REP MOVSB/STOSB
  2. Copyright (C) 2015-2026 Free Software Foundation, Inc.
  3. This file is part of the GNU C Library.
  4. The GNU C Library is free software; you can redistribute it and/or
  5. modify it under the terms of the GNU Lesser General Public
  6. License as published by the Free Software Foundation; either
  7. version 2.1 of the License, or (at your option) any later version.
  8. The GNU C Library is distributed in the hope that it will be useful,
  9. but WITHOUT ANY WARRANTY; without even the implied warranty of
  10. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  11. Lesser General Public License for more details.
  12. You should have received a copy of the GNU Lesser General Public
  13. License along with the GNU C Library; if not, see
  14. <https://www.gnu.org/licenses/>. */
  15. #include <sysdep.h>
  16. #define CFI_PUSH(REG) \
  17. cfi_adjust_cfa_offset (4); \
  18. cfi_rel_offset (REG, 0)
  19. #define CFI_POP(REG) \
  20. cfi_adjust_cfa_offset (-4); \
  21. cfi_restore (REG)
  22. #define PUSH(REG) pushl REG; CFI_PUSH (REG)
  23. #define POP(REG) popl REG; CFI_POP (REG)
  24. #define STR1 8
  25. #define STR2 STR1+4
  26. #define N STR2+4
  27. .text
  28. #if defined SHARED && IS_IN (libc)
  29. ENTRY (__memset_chk)
  30. movl 12(%esp), %eax
  31. cmpl %eax, 16(%esp)
  32. jb HIDDEN_JUMPTARGET (__chk_fail)
  33. END (__memset_chk)
  34. libc_hidden_builtin_def (__memset_chk)
  35. #endif
  36. ENTRY (memset)
  37. PUSH (%edi)
  38. movl N(%esp), %ecx
  39. movl STR1(%esp), %edi
  40. movzbl STR2(%esp), %eax
  41. mov %edi, %edx
  42. rep stosb
  43. mov %edx, %eax
  44. POP (%edi)
  45. ret
  46. END (memset)
  47. libc_hidden_builtin_def (memset)