memset.S 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  1. /* RISC-V RVV based memset.
  2. Copyright (C) 2025-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. <http://www.gnu.org/licenses/>. */
  15. #include <sysdep.h>
  16. #include <sys/asm.h>
  17. #ifndef MEMSET
  18. # define MEMSET memset
  19. #endif
  20. #define dst a0
  21. #define value a1
  22. #define num a2
  23. #define ivl a3
  24. #define dst_ptr a5
  25. #define ELEM_LMUL_SETTING m8
  26. #define vdata v0
  27. ENTRY (MEMSET)
  28. .option push
  29. .option arch, +v
  30. mv dst_ptr, dst
  31. vsetvli ivl, num, e8, ELEM_LMUL_SETTING, ta, ma
  32. vmv.v.x vdata, value
  33. L(loop):
  34. vse8.v vdata, (dst_ptr)
  35. sub num, num, ivl
  36. add dst_ptr, dst_ptr, ivl
  37. vsetvli ivl, num, e8, ELEM_LMUL_SETTING, ta, ma
  38. bnez num, L(loop)
  39. ret
  40. .option pop
  41. END (MEMSET)
  42. libc_hidden_builtin_def (memset)