From 17729f96b07cf1dc2fb0895aaf16ea970a055a25 Mon Sep 17 00:00:00 2001 From: xwx1135370 Date: Fri, 13 Jun 2025 09:22:43 +0800 Subject: [PATCH] =?UTF-8?q?musl=E4=BE=9D=E8=B5=96optimized=5Froutines=20in?= =?UTF-8?q?nerapi?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit issue:https://gitee.com/openharmony/third_party_musl/issues/ICC34J?from=project-issue Signed-off-by: xwx1135370 --- BUILD.gn | 261 +++++++++++++++++++++++++++++++++++++++++ bundle.json | 25 +++- optimized-routines.gni | 19 +++ 3 files changed, 302 insertions(+), 3 deletions(-) create mode 100644 BUILD.gn diff --git a/BUILD.gn b/BUILD.gn new file mode 100644 index 0000000..1bad0ef --- /dev/null +++ b/BUILD.gn @@ -0,0 +1,261 @@ +# Copyright (c) 2025 Huawei Device Co., Ltd. All rights reserved. +# +# Redistribution and use in source and binary forms, with or without modification, +# are permitted provided that the following conditions are met: +# +# 1. Redistributions of source code must retain the above copyright notice, this list of +# conditions and the following disclaimer. +# +# 2. Redistributions in binary form must reproduce the above copyright notice, this list +# of conditions and the following disclaimer in the documentation and/or other materials +# provided with the distribution. +# +# 3. Neither the name of the copyright holder nor the names of its contributors may be used +# to endorse or promote products derived from this software without specific prior written +# permission. +# +# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, +# THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR +# PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR +# CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, +# EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, +# PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; +# OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, +# WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR +# OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF +# ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + +import("//build/config/clang/clang.gni") +import("//build/ohos.gni") +import("optimized-routines.gni") + +config("optimized_routines_config") { + include_dirs = [ + "//third_party/optimized-routines/math", + "//third_party/optimized-routines/math/include", + ] +} + +config("optimized_routines_stack_config") { + cflags = [] + cflags_c = [] + + if (musl_arch == "aarch64") { + cflags += [ "-mbranch-protection=pac-ret+b-key" ] + cflags_c += [ "-fno-stack-protector" ] + } +} + +if (!(is_lite_system && current_os == "ohos")) { + static_library("optimized_static") { + output_name = "liboptimize" + + public_configs = [ ":optimized_routines_config" ] + configs += [ ":optimized_routines_stack_config" ] + + sources = [] + defines = [] + include_dirs = [ "//third_party/optimized-routines/string/include" ] + + if (musl_arch == "arm") { + if (is_llvm_build) { + defines += [ "__IS_LLVM_BUILD" ] + } + sources += [ + "math/cosf.c", + "math/exp2.c", + "math/exp2f.c", + "math/exp2f_data.c", + "math/exp_data.c", + "math/expf.c", + "math/log.c", + "math/log2.c", + "math/log2_data.c", + "math/log2f.c", + "math/log2f_data.c", + "math/log_data.c", + "math/logf.c", + "math/logf_data.c", + "math/math_err.c", + "math/math_errf.c", + "math/pow.c", + "math/pow_log_data.c", + "math/powf.c", + "math/powf_log2_data.c", + "math/sincosf.c", + "math/sincosf_data.c", + "math/sinf.c", + "string/arm/memchr.S", + "string/arm/memcpy.S", + "string/arm/memset.S", + "string/arm/strcmp.S", + "string/arm/strlen-armv6t2.S", + ] + + asmflags = [ + "-D__memcpy_arm = memcpy", + "-D__memchr_arm = memchr", + "-D__memset_arm = memset", + "-D__strcmp_arm = strcmp", + "-D__strlen_armv6t2 = strlen", + ] + + include_dirs += [ "//third_party/optimized-routines/string/arm" ] + } else if (musl_arch == "aarch64") { + include_dirs += [ "//third_party/optimized-routines/string/aarch64" ] + if (defined(ARM_FEATURE_SVE)) { + sources += [ + "string/aarch64/memchr-sve.S", + "string/aarch64/memcmp-sve.S", + "string/aarch64/memcpy.S", + "string/aarch64/memset.S", + "string/aarch64/stpcpy-sve.S", + "string/aarch64/strchr-sve.S", + "string/aarch64/strchrnul-sve.S", + "string/aarch64/strcmp-sve.S", + "string/aarch64/strcpy-sve.S", + "string/aarch64/strlen-sve.S", + "string/aarch64/strncmp-sve.S", + "string/aarch64/strnlen-sve.S", + "string/aarch64/strrchr-sve.S", + ] + asmflags = [ + "-D__memcpy_aarch64 = memcpy", + "-D__memset_aarch64 = memset", + "-D__memcmp_aarch64_sve = memcmp", + "-D__memchr_aarch64_sve = memchr", + "-D__strcmp_aarch64_sve = strcmp", + "-D__strlen_aarch64_sve = strlen", + "-D__strcpy_aarch64_sve = strcpy", + "-D__stpcpy_aarch64_sve = stpcpy", + "-D__strchr_aarch64_sve = strchr", + "-D__strrchr_aarch64_sve = strrchr", + "-D__strchrnul_aarch64_sve = strchrnul", + "-D__strnlen_aarch64_sve = strnlen", + "-D__strncmp_aarch64_sve = strncmp", + ] + } else if (defined(ARM_FEATURE_MTE)) { + sources += [ + "string/aarch64/memchr-mte.S", + "string/aarch64/memcmp.S", + "string/aarch64/memcpy.S", + "string/aarch64/memset.S", + "string/aarch64/stpcpy-mte.S", + "string/aarch64/strchr-mte.S", + "string/aarch64/strchrnul-mte.S", + "string/aarch64/strcmp-mte.S", + "string/aarch64/strcpy-mte.S", + "string/aarch64/strlen-mte.S", + "string/aarch64/strncmp-mte.S", + "string/aarch64/strnlen.S", + "string/aarch64/strrchr-mte.S", + ] + asmflags = [ + "-D__memcpy_aarch64 = memcpy", + "-D__memset_aarch64 = memset", + "-D__memcmp_aarch64 = memcmp", + "-D__memchr_aarch64_mte = memchr", + "-D__strcmp_aarch64_mte = strcmp", + "-D__strlen_aarch64_mte = strlen", + "-D__strcpy_aarch64_mte = strcpy", + "-D__stpcpy_aarch64_mte = stpcpy", + "-D__strchr_aarch64_mte = strchr", + "-D__strrchr_aarch64_mte = strrchr", + "-D__strchrnul_aarch64_mte = strchrnul", + "-D__strnlen_aarch64 = strnlen", + "-D__strncmp_aarch64_mte = strncmp", + ] + } else { + sources += [ + "string/aarch64/memchr.S", + "string/aarch64/memcmp.S", + "string/aarch64/memcpy.S", + "string/aarch64/memset.S", + "string/aarch64/stpcpy.S", + "string/aarch64/strchr.S", + "string/aarch64/strchrnul.S", + "string/aarch64/strcmp.S", + "string/aarch64/strcpy.S", + "string/aarch64/strlen.S", + "string/aarch64/strncmp.S", + "string/aarch64/strnlen.S", + "string/aarch64/strrchr.S", + ] + asmflags = [ + "-D__memmove_aarch64 = memmove", + "-D__memcpy_aarch64 = memcpy", + "-D__memchr_aarch64 = memchr", + "-D__memset_aarch64 = memset", + "-D__memcmp_aarch64 = memcmp", + "-D__strcmp_aarch64 = strcmp", + "-D__strlen_aarch64 = strlen", + "-D__strcpy_aarch64 = strcpy", + "-D__stpcpy_aarch64 = stpcpy", + "-D__strchr_aarch64 = strchr", + "-D__strrchr_aarch64 = strrchr", + "-D__strchrnul_aarch64 = strchrnul", + "-D__strnlen_aarch64 = strnlen", + "-D__strncmp_aarch64 = strncmp", + ] + } + } + + cflags = [ + "-O3", + "-fPIC", + "-fstack-protector-strong", + ] + cflags_c = [ "-fno-lto" ] + + configs -= optimized_inherited_configs + configs += [ "//build/config/components/musl:soft_musl_config" ] + if (use_hwasan) { + defines += [ "HWASAN_REMOVE_CLEANUP" ] + configs += [ "//build/config/sanitizers:default_sanitizer_flags" ] + cflags += [ + "-mllvm", + "-hwasan-instrument-check-enabled=true", + ] + } + } + + static_library("optimize_math") { + output_name = "liboptimize_math" + output_extension = "a" + + public_configs = [ ":optimized_routines_config" ] + configs += [ ":optimized_routines_stack_config" ] + sources = [] + + if (musl_arch == "aarch64") { + sources += [ + "math/cosf.c", + "math/math_errf.c", + "math/sincosf.c", + "math/sincosf_data.c", + "math/sinf.c", + ] + } + + cflags = [ + "-mllvm", + "-instcombine-max-iterations=0", + "-ffp-contract=fast", + "-O3", + "-fPIC", + "-fstack-protector-strong", + ] + cflags_c = [ "-fno-lto" ] + + configs -= optimized_inherited_configs + configs += [ "//build/config/components/musl:soft_musl_config" ] + if (use_hwasan) { + configs += [ "//build/config/sanitizers:default_sanitizer_flags" ] + cflags += [ + "-mllvm", + "-hwasan-instrument-check-enabled=true", + ] + } + } +} diff --git a/bundle.json b/bundle.json index 98c718d..f07f24d 100644 --- a/bundle.json +++ b/bundle.json @@ -19,7 +19,8 @@ "features": [], "adapted_system_type": [ "mini", - "small" + "small", + "standard" ], "rom": "36KB", "ram": "72KB", @@ -28,8 +29,26 @@ "third_party": [] }, "build": { - "sub_component": [], - "inner_kits": [], + "sub_component": [ + "//third_party/optimized-routines:optimized_static", + "//third_party/optimized-routines:optimize_math" + ], + "inner_kits": [ + { + "header": { + "header_base": "//third_party/optimized-routines/math", + "header_files": [] + }, + "name": "//third_party/optimized-routines:optimized_static" + }, + { + "header": { + "header_base": "//third_party/optimized-routines/math", + "header_files": [] + }, + "name": "//third_party/optimized-routines:optimize_math" + } + ], "test": [] } } diff --git a/optimized-routines.gni b/optimized-routines.gni index f4a2b98..ebfd016 100644 --- a/optimized-routines.gni +++ b/optimized-routines.gni @@ -40,3 +40,22 @@ OPTRT_STRING_ARM_SRC_FILES_FOR_ARMV7_M = [ "$OPTRTDIR/string/arm/strcpy.c", "$OPTRTDIR/string/arm/strlen-armv6t2.S", ] + +optimized_inherited_configs = [ + "//build/config/compiler:no_exceptions", + "//build/config/compiler:export_dynamic", + "//build/config/compiler:runtime_library", + "//build/config/compiler:no_rtti", + "//build/config/compiler:thin_archive", + "//build/config/sanitizers:default_sanitizer_flags", + "//build/config/compiler:default_symbols", + "//build/config/compiler:default_stack_frames", + "//build/config/compiler:default_optimization", + "//build/config/compiler:default_include_dirs", + "//build/config/compiler:chromium_code", + "//build/config/compiler:compiler_arm_thumb", + "//build/config/compiler:compiler_arm_fpu", + "//build/config/compiler:compiler", + "//build/config/compiler:afdo_optimize_size", + "//build/config/compiler:afdo", +] -- Gitee