| 1 | /* memset implement with rep stosb |
| 2 | Copyright (C) 2022-2023 Free Software Foundation, Inc. |
| 3 | This file is part of the GNU C Library. |
| 4 | |
| 5 | The GNU C Library is free software; you can redistribute it and/or |
| 6 | modify it under the terms of the GNU Lesser General Public |
| 7 | License as published by the Free Software Foundation; either |
| 8 | version 2.1 of the License, or (at your option) any later version. |
| 9 | |
| 10 | The GNU C Library is distributed in the hope that it will be useful, |
| 11 | but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
| 13 | Lesser General Public License for more details. |
| 14 | |
| 15 | You should have received a copy of the GNU Lesser General Public |
| 16 | License along with the GNU C Library; if not, see |
| 17 | <https://www.gnu.org/licenses/>. */ |
| 18 | |
| 19 | |
| 20 | #include <sysdep.h> |
| 21 | |
| 22 | #if defined USE_MULTIARCH && IS_IN (libc) |
| 23 | .text |
| 24 | ENTRY (__memset_chk_erms) |
| 25 | cmp %RDX_LP, %RCX_LP |
| 26 | jb HIDDEN_JUMPTARGET (__chk_fail) |
| 27 | END (__memset_chk_erms) |
| 28 | |
| 29 | /* Only used to measure performance of REP STOSB. */ |
| 30 | ENTRY (__memset_erms) |
| 31 | /* Skip zero length. */ |
| 32 | test %RDX_LP, %RDX_LP |
| 33 | jz L(stosb_return_zero) |
| 34 | mov %RDX_LP, %RCX_LP |
| 35 | movzbl %sil, %eax |
| 36 | mov %RDI_LP, %RDX_LP |
| 37 | rep stosb |
| 38 | mov %RDX_LP, %RAX_LP |
| 39 | ret |
| 40 | L(stosb_return_zero): |
| 41 | movq %rdi, %rax |
| 42 | ret |
| 43 | END (__memset_erms) |
| 44 | #endif |
| 45 | |