diff options
author | heretic <[email protected]> | 2022-02-10 16:45:43 +0300 |
---|---|---|
committer | Daniil Cherednik <[email protected]> | 2022-02-10 16:45:43 +0300 |
commit | 397cbe258b9e064f49c4ca575279f02f39fef76e (patch) | |
tree | a0b0eb3cca6a14e4e8ea715393637672fa651284 /contrib/restricted/aws/aws-c-common/source | |
parent | 43f5a35593ebc9f6bcea619bb170394ea7ae468e (diff) |
Restoring authorship annotation for <[email protected]>. Commit 1 of 2.
Diffstat (limited to 'contrib/restricted/aws/aws-c-common/source')
-rw-r--r-- | contrib/restricted/aws/aws-c-common/source/arch/arm/asm/cpuid.c | 160 |
1 files changed, 80 insertions, 80 deletions
diff --git a/contrib/restricted/aws/aws-c-common/source/arch/arm/asm/cpuid.c b/contrib/restricted/aws/aws-c-common/source/arch/arm/asm/cpuid.c index 6a306df9809..d64ef97f775 100644 --- a/contrib/restricted/aws/aws-c-common/source/arch/arm/asm/cpuid.c +++ b/contrib/restricted/aws/aws-c-common/source/arch/arm/asm/cpuid.c @@ -1,80 +1,80 @@ -/* - * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"). - * You may not use this file except in compliance with the License. - * A copy of the License is located at - * - * http://aws.amazon.com/apache2.0 - * - * or in the "license" file accompanying this file. This file is distributed - * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either - * express or implied. See the License for the specific language governing - * permissions and limitations under the License. - */ - -#include <aws/common/cpuid.h> -#include <stdlib.h> - -#if defined(__linux__) || defined(__FreeBSD__) -# include <sys/auxv.h> - -static unsigned long s_hwcap[2]; -static bool s_hwcap_cached; - -struct cap_bits { - unsigned long cap; - unsigned long bit; -}; - -# if (defined(__aarch64__)) -struct cap_bits s_check_cap[AWS_CPU_FEATURE_COUNT] = { - [AWS_CPU_FEATURE_ARM_CRC] = {0, 1 << 7 /* HWCAP_CRC */}, -}; -# else -struct cap_bits s_check_cap[AWS_CPU_FEATURE_COUNT] = { - [AWS_CPU_FEATURE_ARM_CRC] = {1, 1 << 4 /* HWCAP_CRC */}, -}; -# endif - -# if (defined(__linux__)) -static void s_cache_hwcap(void) { - s_hwcap[0] = getauxval(AT_HWCAP); - s_hwcap[1] = getauxval(AT_HWCAP2); - s_hwcap_cached = true; -} -# elif (defined(__FreeBSD__)) -static void s_cache_hwcap(void) { - int ret; - - ret = elf_aux_info(AT_HWCAP, &s_hwcap[0], sizeof(unsigned long)); - if (ret) - s_hwcap[0] = 0; - - ret = elf_aux_info(AT_HWCAP2, &s_hwcap[1], sizeof(unsigned long)); - if (ret) - s_hwcap[1] = 0; - s_hwcap_cached = true; -} -# else -# error "Unknown method" -# endif - -bool aws_cpu_has_feature(enum aws_cpu_feature_name feature_name) { - - if (!s_hwcap_cached) - s_cache_hwcap(); - - switch (feature_name) { - case AWS_CPU_FEATURE_ARM_CRC: - return s_hwcap[s_check_cap[feature_name].cap] & s_check_cap[feature_name].bit; - default: - return false; - } -} - -#else /* defined(__linux__) || defined(__FreeBSD__) */ -bool aws_cpu_has_feature(enum aws_cpu_feature_name feature_name) { - return false; -} -#endif /* defined(__linux__) || defined(__FreeBSD__) */ +/* + * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. + * + * Licensed under the Apache License, Version 2.0 (the "License"). + * You may not use this file except in compliance with the License. + * A copy of the License is located at + * + * http://aws.amazon.com/apache2.0 + * + * or in the "license" file accompanying this file. This file is distributed + * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either + * express or implied. See the License for the specific language governing + * permissions and limitations under the License. + */ + +#include <aws/common/cpuid.h> +#include <stdlib.h> + +#if defined(__linux__) || defined(__FreeBSD__) +# include <sys/auxv.h> + +static unsigned long s_hwcap[2]; +static bool s_hwcap_cached; + +struct cap_bits { + unsigned long cap; + unsigned long bit; +}; + +# if (defined(__aarch64__)) +struct cap_bits s_check_cap[AWS_CPU_FEATURE_COUNT] = { + [AWS_CPU_FEATURE_ARM_CRC] = {0, 1 << 7 /* HWCAP_CRC */}, +}; +# else +struct cap_bits s_check_cap[AWS_CPU_FEATURE_COUNT] = { + [AWS_CPU_FEATURE_ARM_CRC] = {1, 1 << 4 /* HWCAP_CRC */}, +}; +# endif + +# if (defined(__linux__)) +static void s_cache_hwcap(void) { + s_hwcap[0] = getauxval(AT_HWCAP); + s_hwcap[1] = getauxval(AT_HWCAP2); + s_hwcap_cached = true; +} +# elif (defined(__FreeBSD__)) +static void s_cache_hwcap(void) { + int ret; + + ret = elf_aux_info(AT_HWCAP, &s_hwcap[0], sizeof(unsigned long)); + if (ret) + s_hwcap[0] = 0; + + ret = elf_aux_info(AT_HWCAP2, &s_hwcap[1], sizeof(unsigned long)); + if (ret) + s_hwcap[1] = 0; + s_hwcap_cached = true; +} +# else +# error "Unknown method" +# endif + +bool aws_cpu_has_feature(enum aws_cpu_feature_name feature_name) { + + if (!s_hwcap_cached) + s_cache_hwcap(); + + switch (feature_name) { + case AWS_CPU_FEATURE_ARM_CRC: + return s_hwcap[s_check_cap[feature_name].cap] & s_check_cap[feature_name].bit; + default: + return false; + } +} + +#else /* defined(__linux__) || defined(__FreeBSD__) */ +bool aws_cpu_has_feature(enum aws_cpu_feature_name feature_name) { + return false; +} +#endif /* defined(__linux__) || defined(__FreeBSD__) */ |