blob: e6cc5fb1cf5f7cefd6eeebc98b33ce7f2a9e257a [file] [log] [blame]
Haibo Huangb9244ff2018-08-11 10:12:13 -07001/*
2 * Copyright (C) 2008 The Android Open Source Project
3 * All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
7 * are met:
8 * * Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer.
10 * * Redistributions in binary form must reproduce the above copyright
11 * notice, this list of conditions and the following disclaimer in
12 * the documentation and/or other materials provided with the
13 * distribution.
14 *
15 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
16 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
17 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
18 * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
19 * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
20 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
21 * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
22 * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
23 * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
24 * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
25 * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
26 * SUCH DAMAGE.
27 */
28
Elliott Hughesa4c78762019-09-17 09:53:14 -070029#include <private/bionic_ifuncs.h>
Elliott Hughesadc41712024-08-16 13:08:11 +000030#include <stddef.h>
Elliott Hughesa4c78762019-09-17 09:53:14 -070031
Haibo Huangb9244ff2018-08-11 10:12:13 -070032extern "C" {
33
Haibo Huangb9244ff2018-08-11 10:12:13 -070034DEFINE_IFUNC_FOR(memcmp) {
Elliott Hughesadc41712024-08-16 13:08:11 +000035 __builtin_cpu_init();
36 if (__builtin_cpu_is("atom")) RETURN_FUNC(memcmp_func_t, memcmp_atom);
37 if (__builtin_cpu_supports("sse4.1")) RETURN_FUNC(memcmp_func_t, memcmp_sse4);
38 RETURN_FUNC(memcmp_func_t, memcmp_generic);
Haibo Huangb9244ff2018-08-11 10:12:13 -070039}
Elliott Hughesadc41712024-08-16 13:08:11 +000040MEMCMP_SHIM()
Haibo Huangb9244ff2018-08-11 10:12:13 -070041
Haibo Huangb9244ff2018-08-11 10:12:13 -070042DEFINE_IFUNC_FOR(memset) {
Elliott Hughesadc41712024-08-16 13:08:11 +000043 __builtin_cpu_init();
44 if (__builtin_cpu_is("atom")) RETURN_FUNC(memset_func_t, memset_atom);
45 RETURN_FUNC(memset_func_t, memset_generic);
Haibo Huangb9244ff2018-08-11 10:12:13 -070046}
Elliott Hughesadc41712024-08-16 13:08:11 +000047MEMSET_SHIM()
Haibo Huangb9244ff2018-08-11 10:12:13 -070048
Haibo Huangb9244ff2018-08-11 10:12:13 -070049DEFINE_IFUNC_FOR(__memset_chk) {
Elliott Hughesadc41712024-08-16 13:08:11 +000050 __builtin_cpu_init();
51 if (__builtin_cpu_is("atom")) RETURN_FUNC(__memset_chk_func_t, __memset_chk_atom);
52 RETURN_FUNC(__memset_chk_func_t, __memset_chk_generic);
Haibo Huangb9244ff2018-08-11 10:12:13 -070053}
Elliott Hughesadc41712024-08-16 13:08:11 +000054__MEMSET_CHK_SHIM()
Haibo Huangb9244ff2018-08-11 10:12:13 -070055
Haibo Huangb9244ff2018-08-11 10:12:13 -070056DEFINE_IFUNC_FOR(memmove) {
Elliott Hughesadc41712024-08-16 13:08:11 +000057 __builtin_cpu_init();
58 if (__builtin_cpu_is("atom")) RETURN_FUNC(memmove_func_t, memmove_atom);
59 RETURN_FUNC(memmove_func_t, memmove_generic);
Haibo Huangb9244ff2018-08-11 10:12:13 -070060}
Elliott Hughesadc41712024-08-16 13:08:11 +000061MEMMOVE_SHIM()
Haibo Huangb9244ff2018-08-11 10:12:13 -070062
Elliott Hughesadc41712024-08-16 13:08:11 +000063DEFINE_IFUNC_FOR(memcpy) { return memmove_resolver(); }
64MEMCPY_SHIM()
Haibo Huange1413622018-11-13 14:20:43 -080065
Haibo Huangb9244ff2018-08-11 10:12:13 -070066DEFINE_IFUNC_FOR(strcpy) {
Elliott Hughesadc41712024-08-16 13:08:11 +000067 __builtin_cpu_init();
68 if (__builtin_cpu_is("atom")) RETURN_FUNC(strcpy_func_t, strcpy_atom);
69 RETURN_FUNC(strcpy_func_t, strcpy_generic);
Haibo Huangb9244ff2018-08-11 10:12:13 -070070}
Elliott Hughesadc41712024-08-16 13:08:11 +000071STRCPY_SHIM()
Haibo Huangb9244ff2018-08-11 10:12:13 -070072
Haibo Huangb9244ff2018-08-11 10:12:13 -070073DEFINE_IFUNC_FOR(strncpy) {
Elliott Hughesadc41712024-08-16 13:08:11 +000074 __builtin_cpu_init();
75 if (__builtin_cpu_is("atom")) RETURN_FUNC(strncpy_func_t, strncpy_atom);
76 RETURN_FUNC(strncpy_func_t, strncpy_generic);
Haibo Huangb9244ff2018-08-11 10:12:13 -070077}
Elliott Hughesadc41712024-08-16 13:08:11 +000078STRNCPY_SHIM()
Haibo Huangb9244ff2018-08-11 10:12:13 -070079
Haibo Huangb9244ff2018-08-11 10:12:13 -070080DEFINE_IFUNC_FOR(strlen) {
Elliott Hughesadc41712024-08-16 13:08:11 +000081 __builtin_cpu_init();
82 if (__builtin_cpu_is("atom")) RETURN_FUNC(strlen_func_t, strlen_atom);
83 RETURN_FUNC(strlen_func_t, strlen_generic);
Haibo Huangb9244ff2018-08-11 10:12:13 -070084}
Elliott Hughesadc41712024-08-16 13:08:11 +000085STRLEN_SHIM()
Haibo Huangb9244ff2018-08-11 10:12:13 -070086
Elliott Hughesadc41712024-08-16 13:08:11 +000087typedef int wmemcmp_func_t(const wchar_t*, const wchar_t*, size_t);
88DEFINE_IFUNC_FOR(wmemcmp) {
89 __builtin_cpu_init();
90 if (__builtin_cpu_supports("sse4.1")) RETURN_FUNC(wmemcmp_func_t, wmemcmp_sse4);
George Burgess IV3451c752024-09-11 20:33:55 -060091 RETURN_FUNC(wmemcmp_func_t, wmemcmp_atom);
Elliott Hughesadc41712024-08-16 13:08:11 +000092}
93DEFINE_STATIC_SHIM(int wmemcmp(const wchar_t* lhs, const wchar_t* rhs, size_t n) {
94 FORWARD(wmemcmp)(lhs, rhs, n);
95})
Haibo Huangb9244ff2018-08-11 10:12:13 -070096
97} // extern "C"