xref: /aosp_15_r20/external/llvm-libc/src/string/memset_explicit.cpp (revision 71db0c75aadcf003ffe3238005f61d7618a3fead)
1*71db0c75SAndroid Build Coastguard Worker //===-- Implementation of memset_explicit ---------------------------------===//
2*71db0c75SAndroid Build Coastguard Worker //
3*71db0c75SAndroid Build Coastguard Worker // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4*71db0c75SAndroid Build Coastguard Worker // See https://llvm.org/LICENSE.txt for license information.
5*71db0c75SAndroid Build Coastguard Worker // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6*71db0c75SAndroid Build Coastguard Worker //
7*71db0c75SAndroid Build Coastguard Worker //===----------------------------------------------------------------------===//
8*71db0c75SAndroid Build Coastguard Worker 
9*71db0c75SAndroid Build Coastguard Worker #include "src/string/memset_explicit.h"
10*71db0c75SAndroid Build Coastguard Worker #include "src/__support/common.h"
11*71db0c75SAndroid Build Coastguard Worker #include "src/__support/macros/config.h"
12*71db0c75SAndroid Build Coastguard Worker #include "src/string/memory_utils/inline_memset.h"
13*71db0c75SAndroid Build Coastguard Worker 
14*71db0c75SAndroid Build Coastguard Worker namespace LIBC_NAMESPACE_DECL {
15*71db0c75SAndroid Build Coastguard Worker 
16*71db0c75SAndroid Build Coastguard Worker [[gnu::noinline]] LLVM_LIBC_FUNCTION(void *, memset_explicit,
17*71db0c75SAndroid Build Coastguard Worker                                      (void *dst, int value, size_t count)) {
18*71db0c75SAndroid Build Coastguard Worker   // Use the inline memset function to set the memory.
19*71db0c75SAndroid Build Coastguard Worker   inline_memset(dst, static_cast<uint8_t>(value), count);
20*71db0c75SAndroid Build Coastguard Worker   // avoid dead store elimination
21*71db0c75SAndroid Build Coastguard Worker   // The asm itself should also be sufficient to behave as a compiler barrier.
22*71db0c75SAndroid Build Coastguard Worker   asm("" : : "r"(dst) : "memory");
23*71db0c75SAndroid Build Coastguard Worker   return dst;
24*71db0c75SAndroid Build Coastguard Worker }
25*71db0c75SAndroid Build Coastguard Worker 
26*71db0c75SAndroid Build Coastguard Worker } // namespace LIBC_NAMESPACE_DECL
27