Script 'mail_helper' called by obssrc Hello community, here is the log from the commit of package aws-c-common for openSUSE:Factory checked in at 2025-04-04 17:34:27 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ Comparing /work/SRC/openSUSE:Factory/aws-c-common (Old) and /work/SRC/openSUSE:Factory/.aws-c-common.new.1907 (New) ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Package is "aws-c-common" Fri Apr 4 17:34:27 2025 rev:25 rq:1267115 version:0.12.2 Changes: -------- --- /work/SRC/openSUSE:Factory/aws-c-common/aws-c-common.changes 2025-03-26 21:25:14.767052799 +0100 +++ /work/SRC/openSUSE:Factory/.aws-c-common.new.1907/aws-c-common.changes 2025-04-04 17:34:33.881646700 +0200 @@ -1,0 +2,7 @@ +Wed Apr 2 13:51:05 UTC 2025 - John Paul Adrian Glaubitz <adrian.glaub...@suse.com> + +- Update to 0.12.2 + * Tests require compiler extensions by @graebm in (#1193) + * Simplify how inline math files are included by @graebm in (#1195) + +------------------------------------------------------------------- Old: ---- v0.12.1.tar.gz New: ---- v0.12.2.tar.gz ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ Other differences: ------------------ ++++++ aws-c-common.spec ++++++ --- /var/tmp/diff_new_pack.7Tv8A8/_old 2025-04-04 17:34:34.681680090 +0200 +++ /var/tmp/diff_new_pack.7Tv8A8/_new 2025-04-04 17:34:34.685680257 +0200 @@ -19,7 +19,7 @@ %define library_version 1.0.0 %define library_soversion 1 Name: aws-c-common -Version: 0.12.1 +Version: 0.12.2 Release: 0 Summary: Core C99 package for AWS SDK for C License: Apache-2.0 ++++++ v0.12.1.tar.gz -> v0.12.2.tar.gz ++++++ diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/aws-c-common-0.12.1/CMakeLists.txt new/aws-c-common-0.12.2/CMakeLists.txt --- old/aws-c-common-0.12.1/CMakeLists.txt 2025-03-17 17:18:26.000000000 +0100 +++ new/aws-c-common-0.12.2/CMakeLists.txt 2025-03-26 19:14:51.000000000 +0100 @@ -189,7 +189,16 @@ aws_prepare_symbol_visibility_args(${PROJECT_NAME} "AWS_COMMON") target_compile_options(${PROJECT_NAME} PUBLIC ${PLATFORM_CFLAGS}) -aws_check_headers(${PROJECT_NAME} ${AWS_COMMON_HEADERS}) +# Check public headers, to ensure they're safe for any 3rdparty to include +set(HEADERS_TO_CHECK ${AWS_COMMON_HEADERS}) + +# HACK: don't check rw_lock.h, which can fail in esoteric circumstances +# (building without compiler extensions, and without defining _POSIX_C_SOURCE or _XOPEN_SOURCE). +# Currently, this file is only used by aws-c-*** libs, which are fine. +get_filename_component(NAUGHTY_HEADER "include/aws/common/rw_lock.h" ABSOLUTE) +list(REMOVE_ITEM HEADERS_TO_CHECK ${NAUGHTY_HEADER}) + +aws_check_headers(${PROJECT_NAME} ${HEADERS_TO_CHECK}) #apple source already includes the definitions we want, and setting this posix source #version causes it to revert to an older version. So don't turn it on there, we don't need it. diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/aws-c-common-0.12.1/cmake/AwsCheckHeaders.cmake new/aws-c-common-0.12.2/cmake/AwsCheckHeaders.cmake --- old/aws-c-common-0.12.1/cmake/AwsCheckHeaders.cmake 2025-03-17 17:18:26.000000000 +0100 +++ new/aws-c-common-0.12.2/cmake/AwsCheckHeaders.cmake 2025-03-26 19:14:51.000000000 +0100 @@ -61,6 +61,9 @@ CXX_STANDARD ${std} CXX_STANDARD_REQUIRED 0 C_STANDARD 99 + # Forbid public headers from relying on compiler extensions + CXX_EXTENSIONS OFF + C_EXTENSIONS OFF ) # Ensure our headers can be included by an application with its warnings set very high. diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/aws-c-common-0.12.1/cmake/AwsTestHarness.cmake new/aws-c-common-0.12.2/cmake/AwsTestHarness.cmake --- old/aws-c-common-0.12.1/cmake/AwsTestHarness.cmake 2025-03-17 17:18:26.000000000 +0100 +++ new/aws-c-common-0.12.2/cmake/AwsTestHarness.cmake 2025-03-26 19:14:51.000000000 +0100 @@ -53,7 +53,13 @@ target_link_libraries(${driver_exe_name} PRIVATE ${PROJECT_NAME}) - set_target_properties(${driver_exe_name} PROPERTIES LINKER_LANGUAGE C C_STANDARD 99) + set_target_properties(${driver_exe_name} PROPERTIES + LINKER_LANGUAGE C + C_STANDARD 99 + # Our ASSERT(...) macros rely on (widely supported) ##__VA_ARGS__ extension + C_EXTENSIONS ON + ) + target_compile_definitions(${driver_exe_name} PRIVATE AWS_UNSTABLE_TESTING_API=1) target_include_directories(${driver_exe_name} PRIVATE ${CMAKE_CURRENT_LIST_DIR}) @@ -75,7 +81,11 @@ add_executable(${driver_exe_name} ${CMAKE_CURRENT_BINARY_DIR}/test_runner.cpp ${TESTS}) target_link_libraries(${driver_exe_name} PRIVATE ${PROJECT_NAME}) - set_target_properties(${driver_exe_name} PROPERTIES LINKER_LANGUAGE CXX) + set_target_properties(${driver_exe_name} PROPERTIES + LINKER_LANGUAGE CXX + # Our ASSERT(...) macros rely on (widely supported) ##__VA_ARGS__ extension + CXX_EXTENSIONS ON + ) if (MSVC) if(AWS_STATIC_MSVC_RUNTIME_LIBRARY OR STATIC_CRT) target_compile_options(${driver_exe_name} PRIVATE "/MT$<$<CONFIG:Debug>:d>") diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/aws-c-common-0.12.1/include/aws/common/math.fallback.inl new/aws-c-common-0.12.2/include/aws/common/math.fallback.inl --- old/aws-c-common-0.12.1/include/aws/common/math.fallback.inl 2025-03-17 17:18:26.000000000 +0100 +++ new/aws-c-common-0.12.2/include/aws/common/math.fallback.inl 2025-03-26 19:14:51.000000000 +0100 @@ -94,12 +94,6 @@ return AWS_OP_SUCCESS; } -/* - * These are pure C implementations of the count leading/trailing zeros calls - * They should not be necessary unless using a really esoteric compiler with - * no intrinsics for these functions whatsoever. - */ -#if !defined(__clang__) && !defined(__GNUC__) /** * Search from the MSB to LSB, looking for a 1 */ @@ -144,11 +138,11 @@ } AWS_STATIC_IMPL size_t aws_clz_size(size_t n) { -# if SIZE_BITS == 64 +#if SIZE_BITS == 64 return aws_clz_u64(n); -# else +#else return aws_clz_u32(n); -# endif +#endif } /** @@ -193,14 +187,12 @@ } AWS_STATIC_IMPL size_t aws_ctz_size(size_t n) { -# if SIZE_BITS == 64 +#if SIZE_BITS == 64 return aws_ctz_u64(n); -# else +#else return aws_ctz_u32(n); -# endif -} - #endif +} AWS_EXTERN_C_END diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/aws-c-common-0.12.1/include/aws/common/math.gcc_arm64_asm.inl new/aws-c-common-0.12.2/include/aws/common/math.gcc_arm64_asm.inl --- old/aws-c-common-0.12.1/include/aws/common/math.gcc_arm64_asm.inl 2025-03-17 17:18:26.000000000 +0100 +++ new/aws-c-common-0.12.2/include/aws/common/math.gcc_arm64_asm.inl 2025-03-26 19:14:51.000000000 +0100 @@ -109,7 +109,7 @@ uint64_t res, flag; __asm__("adds %x[res], %x[arga], %x[argb]\n" "csinv %x[flag], xzr, xzr, cc\n" - : /* inout: res is the result of addition; flag is -1 if carry happened */ + : /* inout: res is the result of addition; flag is -1 if carry happened */ [res]"=&r"(res), [flag] "=r"(flag) : /* in: a and b */ [arga] "r"(a), [argb] "r"(b) : /* clobbers: cc (cmp clobbers condition codes) */ "cc"); diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/aws-c-common-0.12.1/include/aws/common/math.h new/aws-c-common-0.12.2/include/aws/common/math.h --- old/aws-c-common-0.12.1/include/aws/common/math.h 2025-03-17 17:18:26.000000000 +0100 +++ new/aws-c-common-0.12.2/include/aws/common/math.h 2025-03-26 19:14:51.000000000 +0100 @@ -28,63 +28,49 @@ AWS_EXTERN_C_BEGIN -#if defined(AWS_HAVE_GCC_OVERFLOW_MATH_EXTENSIONS) && (defined(__clang__) || !defined(__cplusplus)) || \ - (defined(__x86_64__) || defined(__aarch64__)) && defined(AWS_HAVE_GCC_INLINE_ASM) || \ - defined(AWS_HAVE_MSVC_INTRINSICS_X64) || defined(CBMC) || !defined(AWS_HAVE_GCC_OVERFLOW_MATH_EXTENSIONS) -/* In all these cases, we can use fast static inline versions of this code */ -# define AWS_COMMON_MATH_API AWS_STATIC_IMPL -#else -/* - * We got here because we are building in C++ mode but we only support overflow extensions - * in C mode. Because the fallback is _slow_ (involving a division), we'd prefer to make a - * non-inline call to the fast C intrinsics. - */ -# define AWS_COMMON_MATH_API AWS_COMMON_API -#endif - /** * Multiplies a * b. If the result overflows, returns 2^64 - 1. */ -AWS_COMMON_MATH_API uint64_t aws_mul_u64_saturating(uint64_t a, uint64_t b); +AWS_STATIC_IMPL uint64_t aws_mul_u64_saturating(uint64_t a, uint64_t b); /** * If a * b overflows, returns AWS_OP_ERR; otherwise multiplies * a * b, returns the result in *r, and returns AWS_OP_SUCCESS. */ -AWS_COMMON_MATH_API int aws_mul_u64_checked(uint64_t a, uint64_t b, uint64_t *r); +AWS_STATIC_IMPL int aws_mul_u64_checked(uint64_t a, uint64_t b, uint64_t *r); /** * Multiplies a * b. If the result overflows, returns 2^32 - 1. */ -AWS_COMMON_MATH_API uint32_t aws_mul_u32_saturating(uint32_t a, uint32_t b); +AWS_STATIC_IMPL uint32_t aws_mul_u32_saturating(uint32_t a, uint32_t b); /** * If a * b overflows, returns AWS_OP_ERR; otherwise multiplies * a * b, returns the result in *r, and returns AWS_OP_SUCCESS. */ -AWS_COMMON_MATH_API int aws_mul_u32_checked(uint32_t a, uint32_t b, uint32_t *r); +AWS_STATIC_IMPL int aws_mul_u32_checked(uint32_t a, uint32_t b, uint32_t *r); /** * Adds a + b. If the result overflows returns 2^64 - 1. */ -AWS_COMMON_MATH_API uint64_t aws_add_u64_saturating(uint64_t a, uint64_t b); +AWS_STATIC_IMPL uint64_t aws_add_u64_saturating(uint64_t a, uint64_t b); /** * If a + b overflows, returns AWS_OP_ERR; otherwise adds * a + b, returns the result in *r, and returns AWS_OP_SUCCESS. */ -AWS_COMMON_MATH_API int aws_add_u64_checked(uint64_t a, uint64_t b, uint64_t *r); +AWS_STATIC_IMPL int aws_add_u64_checked(uint64_t a, uint64_t b, uint64_t *r); /** * Adds a + b. If the result overflows returns 2^32 - 1. */ -AWS_COMMON_MATH_API uint32_t aws_add_u32_saturating(uint32_t a, uint32_t b); +AWS_STATIC_IMPL uint32_t aws_add_u32_saturating(uint32_t a, uint32_t b); /** * If a + b overflows, returns AWS_OP_ERR; otherwise adds * a + b, returns the result in *r, and returns AWS_OP_SUCCESS. */ -AWS_COMMON_MATH_API int aws_add_u32_checked(uint32_t a, uint32_t b, uint32_t *r); +AWS_STATIC_IMPL int aws_add_u32_checked(uint32_t a, uint32_t b, uint32_t *r); /** * Subtracts a - b. If the result overflows returns 0. diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/aws-c-common-0.12.1/include/aws/common/math.inl new/aws-c-common-0.12.2/include/aws/common/math.inl --- old/aws-c-common-0.12.1/include/aws/common/math.inl 2025-03-17 17:18:26.000000000 +0100 +++ new/aws-c-common-0.12.2/include/aws/common/math.inl 2025-03-26 19:14:51.000000000 +0100 @@ -13,37 +13,36 @@ #include <limits.h> #include <stdlib.h> -#if defined(AWS_HAVE_GCC_OVERFLOW_MATH_EXTENSIONS) && (defined(__clang__) || !defined(__cplusplus)) -/* - * GCC and clang have these super convenient overflow checking builtins... - * but (in the case of GCC) they're only available when building C source. - * We'll fall back to one of the other inlinable variants (or a non-inlined version) - * if we are building this header on G++. - */ +#ifndef __has_builtin +# define __has_builtin(x) 0 +#endif + +/* CBMC is its own thing */ +#if defined(CBMC) +# include <aws/common/math.cbmc.inl> + +/* Prefer GCC-style overflow builtins */ +#elif defined(AWS_HAVE_GCC_OVERFLOW_MATH_EXTENSIONS) || __has_builtin(__builtin_add_overflow) +# include <aws/common/math.gcc_builtin.inl> # include <aws/common/math.gcc_overflow.inl> + +/* Fall back on GCC-style assembly, and ancient builtins available in all versions of GCC and Clang we support */ #elif defined(__x86_64__) && defined(AWS_HAVE_GCC_INLINE_ASM) +# include <aws/common/math.gcc_builtin.inl> # include <aws/common/math.gcc_x64_asm.inl> + +/* Fall back on GCC-style assembly, and ancient builtins available in all versions of GCC and Clang we support */ #elif defined(__aarch64__) && defined(AWS_HAVE_GCC_INLINE_ASM) # include <aws/common/math.gcc_arm64_asm.inl> +# include <aws/common/math.gcc_builtin.inl> + +/* On MSVC, use intrinsics */ #elif defined(AWS_HAVE_MSVC_INTRINSICS_X64) -# include <aws/common/math.msvc.inl> -#elif defined(CBMC) -# include <aws/common/math.cbmc.inl> -#else -# ifndef AWS_HAVE_GCC_OVERFLOW_MATH_EXTENSIONS -/* Fall back to the pure-C implementations */ -# include <aws/common/math.fallback.inl> -# else -/* - * We got here because we are building in C++ mode but we only support overflow extensions - * in C mode. Because the fallback is _slow_ (involving a division), we'd prefer to make a - * non-inline call to the fast C intrinsics. - */ -# endif /* AWS_HAVE_GCC_OVERFLOW_MATH_EXTENSIONS */ -#endif /* defined(AWS_HAVE_GCC_OVERFLOW_MATH_EXTENSIONS) && (defined(__clang__) || !defined(__cplusplus)) */ +# include <aws/common/math.msvc_x64.inl> -#if defined(__clang__) || defined(__GNUC__) -# include <aws/common/math.gcc_builtin.inl> +/* Fall back to pure C implementation */ +#else +# include <aws/common/math.fallback.inl> #endif AWS_EXTERN_C_BEGIN diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/aws-c-common-0.12.1/include/aws/common/math.msvc.inl new/aws-c-common-0.12.2/include/aws/common/math.msvc.inl --- old/aws-c-common-0.12.1/include/aws/common/math.msvc.inl 2025-03-17 17:18:26.000000000 +0100 +++ new/aws-c-common-0.12.2/include/aws/common/math.msvc.inl 1970-01-01 01:00:00.000000000 +0100 @@ -1,273 +0,0 @@ -#ifndef AWS_COMMON_MATH_MSVC_INL -#define AWS_COMMON_MATH_MSVC_INL - -/** - * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. - * SPDX-License-Identifier: Apache-2.0. - */ - -/* - * This header is already included, but include it again to make editor - * highlighting happier. - */ -#include <aws/common/common.h> -#include <aws/common/cpuid.h> -#include <aws/common/math.h> - -/* This file generates level 4 compiler warnings in Visual Studio 2017 and older */ -#pragma warning(push, 3) -#include <intrin.h> -#pragma warning(pop) - -AWS_EXTERN_C_BEGIN -/** - * Multiplies a * b. If the result overflows, returns 2^64 - 1. - */ -AWS_STATIC_IMPL uint64_t aws_mul_u64_saturating(uint64_t a, uint64_t b) { - uint64_t out; - uint64_t ret_val = _umul128(a, b, &out); - return (out == 0) ? ret_val : UINT64_MAX; -} - -/** - * If a * b overflows, returns AWS_OP_ERR; otherwise multiplies - * a * b, returns the result in *r, and returns AWS_OP_SUCCESS. - */ -AWS_STATIC_IMPL int aws_mul_u64_checked(uint64_t a, uint64_t b, uint64_t *r) { - uint64_t out; - *r = _umul128(a, b, &out); - - if (out != 0) { - return aws_raise_error(AWS_ERROR_OVERFLOW_DETECTED); - } - return AWS_OP_SUCCESS; -} - -static uint32_t (*s_mul_u32_saturating_fn_ptr)(uint32_t a, uint32_t b) = NULL; - -static uint32_t s_mulx_u32_saturating(uint32_t a, uint32_t b) { - uint32_t high_32; - uint32_t ret_val = _mulx_u32(a, b, &high_32); - return (high_32 == 0) ? ret_val : UINT32_MAX; -} - -static uint32_t s_emulu_saturating(uint32_t a, uint32_t b) { - uint64_t result = __emulu(a, b); - return (result > UINT32_MAX) ? UINT32_MAX : (uint32_t)result; -} -/** - * Multiplies a * b. If the result overflows, returns 2^32 - 1. - */ -AWS_STATIC_IMPL uint32_t aws_mul_u32_saturating(uint32_t a, uint32_t b) { - if (AWS_UNLIKELY(!s_mul_u32_saturating_fn_ptr)) { - if (aws_cpu_has_feature(AWS_CPU_FEATURE_BMI2)) { - s_mul_u32_saturating_fn_ptr = s_mulx_u32_saturating; - } else { - /* If BMI2 unavailable, use __emulu instead */ - s_mul_u32_saturating_fn_ptr = s_emulu_saturating; - } - } - return s_mul_u32_saturating_fn_ptr(a, b); -} - -static int (*s_mul_u32_checked_fn_ptr)(uint32_t a, uint32_t b, uint32_t *r) = NULL; - -static int s_mulx_u32_checked(uint32_t a, uint32_t b, uint32_t *r) { - uint32_t high_32; - *r = _mulx_u32(a, b, &high_32); - - if (high_32 != 0) { - return aws_raise_error(AWS_ERROR_OVERFLOW_DETECTED); - } - return AWS_OP_SUCCESS; -} - -static int s_emulu_checked(uint32_t a, uint32_t b, uint32_t *r) { - uint64_t result = __emulu(a, b); - if (result > UINT32_MAX) { - return aws_raise_error(AWS_ERROR_OVERFLOW_DETECTED); - } - *r = (uint32_t)result; - return AWS_OP_SUCCESS; -} -/** - * If a * b overflows, returns AWS_OP_ERR; otherwise multiplies - * a * b, returns the result in *r, and returns AWS_OP_SUCCESS. - */ -AWS_STATIC_IMPL int aws_mul_u32_checked(uint32_t a, uint32_t b, uint32_t *r) { - if (AWS_UNLIKELY(!s_mul_u32_checked_fn_ptr)) { - if (aws_cpu_has_feature(AWS_CPU_FEATURE_BMI2)) { - s_mul_u32_checked_fn_ptr = s_mulx_u32_checked; - } else { - /* If BMI2 unavailable, use __emulu instead */ - s_mul_u32_checked_fn_ptr = s_emulu_checked; - } - } - return s_mul_u32_checked_fn_ptr(a, b, r); -} - -/** - * If a + b overflows, returns AWS_OP_ERR; otherwise adds - * a + b, returns the result in *r, and returns AWS_OP_SUCCESS. - */ -AWS_STATIC_IMPL int aws_add_u64_checked(uint64_t a, uint64_t b, uint64_t *r) { -#if !defined(_MSC_VER) || _MSC_VER < 1920 - /* Fallback MSVC 2017 and older, _addcarry doesn't work correctly for those compiler */ - if ((b > 0) && (a > (UINT64_MAX - b))) { - return aws_raise_error(AWS_ERROR_OVERFLOW_DETECTED); - } - *r = a + b; - return AWS_OP_SUCCESS; -#else - if (_addcarry_u64((uint8_t)0, a, b, r)) { - return aws_raise_error(AWS_ERROR_OVERFLOW_DETECTED); - } - return AWS_OP_SUCCESS; -#endif -} - -/** - * Adds a + b. If the result overflows, returns 2^64 - 1. - */ -AWS_STATIC_IMPL uint64_t aws_add_u64_saturating(uint64_t a, uint64_t b) { -#if !defined(_MSC_VER) || _MSC_VER < 1920 - /* Fallback MSVC 2017 and older, _addcarry doesn't work correctly for those compiler */ - if ((b > 0) && (a > (UINT64_MAX - b))) { - return UINT64_MAX; - } - return a + b; -#else - uint64_t res = 0; - if (_addcarry_u64((uint8_t)0, a, b, &res)) { - res = UINT64_MAX; - } - return res; -#endif -} - -/** - * If a + b overflows, returns AWS_OP_ERR; otherwise adds - * a + b, returns the result in *r, and returns AWS_OP_SUCCESS. - */ -AWS_STATIC_IMPL int aws_add_u32_checked(uint32_t a, uint32_t b, uint32_t *r) { -#if !defined(_MSC_VER) || _MSC_VER < 1920 - /* Fallback MSVC 2017 and older, _addcarry doesn't work correctly for those compiler */ - if ((b > 0) && (a > (UINT32_MAX - b))) { - return aws_raise_error(AWS_ERROR_OVERFLOW_DETECTED); - } - *r = a + b; - return AWS_OP_SUCCESS; -#else - if (_addcarry_u32((uint8_t)0, a, b, r)) { - return aws_raise_error(AWS_ERROR_OVERFLOW_DETECTED); - } - return AWS_OP_SUCCESS; -#endif -} - -/** - * Adds a + b. If the result overflows, returns 2^32 - 1. - */ -AWS_STATIC_IMPL uint32_t aws_add_u32_saturating(uint32_t a, uint32_t b) { -#if !defined(_MSC_VER) || _MSC_VER < 1920 - /* Fallback MSVC 2017 and older, _addcarry doesn't work correctly for those compiler */ - if ((b > 0) && (a > (UINT32_MAX - b))) - return UINT32_MAX; - return a + b; -#else - uint32_t res = 0; - if (_addcarry_u32((uint8_t)0, a, b, &res)) { - res = UINT32_MAX; - } - return res; -#endif -} - -/** - * Search from the MSB to LSB, looking for a 1 - */ -AWS_STATIC_IMPL size_t aws_clz_u32(uint32_t n) { - unsigned long idx = 0; - if (_BitScanReverse(&idx, n)) { - return 31 - idx; - } - return 32; -} - -AWS_STATIC_IMPL size_t aws_clz_i32(int32_t n) { - unsigned long idx = 0; - if (_BitScanReverse(&idx, (unsigned long)n)) { - return 31 - idx; - } - return 32; -} - -AWS_STATIC_IMPL size_t aws_clz_u64(uint64_t n) { - unsigned long idx = 0; - if (_BitScanReverse64(&idx, n)) { - return 63 - idx; - } - return 64; -} - -AWS_STATIC_IMPL size_t aws_clz_i64(int64_t n) { - unsigned long idx = 0; - if (_BitScanReverse64(&idx, (uint64_t)n)) { - return 63 - idx; - } - return 64; -} - -AWS_STATIC_IMPL size_t aws_clz_size(size_t n) { -#if SIZE_BITS == 64 - return aws_clz_u64(n); -#else - return aws_clz_u32(n); -#endif -} - -/** - * Search from the LSB to MSB, looking for a 1 - */ -AWS_STATIC_IMPL size_t aws_ctz_u32(uint32_t n) { - unsigned long idx = 0; - if (_BitScanForward(&idx, n)) { - return idx; - } - return 32; -} - -AWS_STATIC_IMPL size_t aws_ctz_i32(int32_t n) { - unsigned long idx = 0; - if (_BitScanForward(&idx, (uint32_t)n)) { - return idx; - } - return 32; -} - -AWS_STATIC_IMPL size_t aws_ctz_u64(uint64_t n) { - unsigned long idx = 0; - if (_BitScanForward64(&idx, n)) { - return idx; - } - return 64; -} - -AWS_STATIC_IMPL size_t aws_ctz_i64(int64_t n) { - unsigned long idx = 0; - if (_BitScanForward64(&idx, (uint64_t)n)) { - return idx; - } - return 64; -} - -AWS_STATIC_IMPL size_t aws_ctz_size(size_t n) { -#if SIZE_BITS == 64 - return aws_ctz_u64(n); -#else - return aws_ctz_u32(n); -#endif -} - -AWS_EXTERN_C_END -#endif /* WS_COMMON_MATH_MSVC_INL */ diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/aws-c-common-0.12.1/include/aws/common/math.msvc_x64.inl new/aws-c-common-0.12.2/include/aws/common/math.msvc_x64.inl --- old/aws-c-common-0.12.1/include/aws/common/math.msvc_x64.inl 1970-01-01 01:00:00.000000000 +0100 +++ new/aws-c-common-0.12.2/include/aws/common/math.msvc_x64.inl 2025-03-26 19:14:51.000000000 +0100 @@ -0,0 +1,273 @@ +#ifndef AWS_COMMON_MATH_MSVC_INL +#define AWS_COMMON_MATH_MSVC_INL + +/** + * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. + * SPDX-License-Identifier: Apache-2.0. + */ + +/* + * This header is already included, but include it again to make editor + * highlighting happier. + */ +#include <aws/common/common.h> +#include <aws/common/cpuid.h> +#include <aws/common/math.h> + +/* This file generates level 4 compiler warnings in Visual Studio 2017 and older */ +#pragma warning(push, 3) +#include <intrin.h> +#pragma warning(pop) + +AWS_EXTERN_C_BEGIN +/** + * Multiplies a * b. If the result overflows, returns 2^64 - 1. + */ +AWS_STATIC_IMPL uint64_t aws_mul_u64_saturating(uint64_t a, uint64_t b) { + uint64_t out; + uint64_t ret_val = _umul128(a, b, &out); + return (out == 0) ? ret_val : UINT64_MAX; +} + +/** + * If a * b overflows, returns AWS_OP_ERR; otherwise multiplies + * a * b, returns the result in *r, and returns AWS_OP_SUCCESS. + */ +AWS_STATIC_IMPL int aws_mul_u64_checked(uint64_t a, uint64_t b, uint64_t *r) { + uint64_t out; + *r = _umul128(a, b, &out); + + if (out != 0) { + return aws_raise_error(AWS_ERROR_OVERFLOW_DETECTED); + } + return AWS_OP_SUCCESS; +} + +static uint32_t (*s_mul_u32_saturating_fn_ptr)(uint32_t a, uint32_t b) = NULL; + +static uint32_t s_mulx_u32_saturating(uint32_t a, uint32_t b) { + uint32_t high_32; + uint32_t ret_val = _mulx_u32(a, b, &high_32); + return (high_32 == 0) ? ret_val : UINT32_MAX; +} + +static uint32_t s_emulu_saturating(uint32_t a, uint32_t b) { + uint64_t result = __emulu(a, b); + return (result > UINT32_MAX) ? UINT32_MAX : (uint32_t)result; +} +/** + * Multiplies a * b. If the result overflows, returns 2^32 - 1. + */ +AWS_STATIC_IMPL uint32_t aws_mul_u32_saturating(uint32_t a, uint32_t b) { + if (AWS_UNLIKELY(!s_mul_u32_saturating_fn_ptr)) { + if (aws_cpu_has_feature(AWS_CPU_FEATURE_BMI2)) { + s_mul_u32_saturating_fn_ptr = s_mulx_u32_saturating; + } else { + /* If BMI2 unavailable, use __emulu instead */ + s_mul_u32_saturating_fn_ptr = s_emulu_saturating; + } + } + return s_mul_u32_saturating_fn_ptr(a, b); +} + +static int (*s_mul_u32_checked_fn_ptr)(uint32_t a, uint32_t b, uint32_t *r) = NULL; + +static int s_mulx_u32_checked(uint32_t a, uint32_t b, uint32_t *r) { + uint32_t high_32; + *r = _mulx_u32(a, b, &high_32); + + if (high_32 != 0) { + return aws_raise_error(AWS_ERROR_OVERFLOW_DETECTED); + } + return AWS_OP_SUCCESS; +} + +static int s_emulu_checked(uint32_t a, uint32_t b, uint32_t *r) { + uint64_t result = __emulu(a, b); + if (result > UINT32_MAX) { + return aws_raise_error(AWS_ERROR_OVERFLOW_DETECTED); + } + *r = (uint32_t)result; + return AWS_OP_SUCCESS; +} +/** + * If a * b overflows, returns AWS_OP_ERR; otherwise multiplies + * a * b, returns the result in *r, and returns AWS_OP_SUCCESS. + */ +AWS_STATIC_IMPL int aws_mul_u32_checked(uint32_t a, uint32_t b, uint32_t *r) { + if (AWS_UNLIKELY(!s_mul_u32_checked_fn_ptr)) { + if (aws_cpu_has_feature(AWS_CPU_FEATURE_BMI2)) { + s_mul_u32_checked_fn_ptr = s_mulx_u32_checked; + } else { + /* If BMI2 unavailable, use __emulu instead */ + s_mul_u32_checked_fn_ptr = s_emulu_checked; + } + } + return s_mul_u32_checked_fn_ptr(a, b, r); +} + +/** + * If a + b overflows, returns AWS_OP_ERR; otherwise adds + * a + b, returns the result in *r, and returns AWS_OP_SUCCESS. + */ +AWS_STATIC_IMPL int aws_add_u64_checked(uint64_t a, uint64_t b, uint64_t *r) { +#if !defined(_MSC_VER) || _MSC_VER < 1920 + /* Fallback MSVC 2017 and older, _addcarry doesn't work correctly for those compiler */ + if ((b > 0) && (a > (UINT64_MAX - b))) { + return aws_raise_error(AWS_ERROR_OVERFLOW_DETECTED); + } + *r = a + b; + return AWS_OP_SUCCESS; +#else + if (_addcarry_u64((uint8_t)0, a, b, r)) { + return aws_raise_error(AWS_ERROR_OVERFLOW_DETECTED); + } + return AWS_OP_SUCCESS; +#endif +} + +/** + * Adds a + b. If the result overflows, returns 2^64 - 1. + */ +AWS_STATIC_IMPL uint64_t aws_add_u64_saturating(uint64_t a, uint64_t b) { +#if !defined(_MSC_VER) || _MSC_VER < 1920 + /* Fallback MSVC 2017 and older, _addcarry doesn't work correctly for those compiler */ + if ((b > 0) && (a > (UINT64_MAX - b))) { + return UINT64_MAX; + } + return a + b; +#else + uint64_t res = 0; + if (_addcarry_u64((uint8_t)0, a, b, &res)) { + res = UINT64_MAX; + } + return res; +#endif +} + +/** + * If a + b overflows, returns AWS_OP_ERR; otherwise adds + * a + b, returns the result in *r, and returns AWS_OP_SUCCESS. + */ +AWS_STATIC_IMPL int aws_add_u32_checked(uint32_t a, uint32_t b, uint32_t *r) { +#if !defined(_MSC_VER) || _MSC_VER < 1920 + /* Fallback MSVC 2017 and older, _addcarry doesn't work correctly for those compiler */ + if ((b > 0) && (a > (UINT32_MAX - b))) { + return aws_raise_error(AWS_ERROR_OVERFLOW_DETECTED); + } + *r = a + b; + return AWS_OP_SUCCESS; +#else + if (_addcarry_u32((uint8_t)0, a, b, r)) { + return aws_raise_error(AWS_ERROR_OVERFLOW_DETECTED); + } + return AWS_OP_SUCCESS; +#endif +} + +/** + * Adds a + b. If the result overflows, returns 2^32 - 1. + */ +AWS_STATIC_IMPL uint32_t aws_add_u32_saturating(uint32_t a, uint32_t b) { +#if !defined(_MSC_VER) || _MSC_VER < 1920 + /* Fallback MSVC 2017 and older, _addcarry doesn't work correctly for those compiler */ + if ((b > 0) && (a > (UINT32_MAX - b))) + return UINT32_MAX; + return a + b; +#else + uint32_t res = 0; + if (_addcarry_u32((uint8_t)0, a, b, &res)) { + res = UINT32_MAX; + } + return res; +#endif +} + +/** + * Search from the MSB to LSB, looking for a 1 + */ +AWS_STATIC_IMPL size_t aws_clz_u32(uint32_t n) { + unsigned long idx = 0; + if (_BitScanReverse(&idx, n)) { + return 31 - idx; + } + return 32; +} + +AWS_STATIC_IMPL size_t aws_clz_i32(int32_t n) { + unsigned long idx = 0; + if (_BitScanReverse(&idx, (unsigned long)n)) { + return 31 - idx; + } + return 32; +} + +AWS_STATIC_IMPL size_t aws_clz_u64(uint64_t n) { + unsigned long idx = 0; + if (_BitScanReverse64(&idx, n)) { + return 63 - idx; + } + return 64; +} + +AWS_STATIC_IMPL size_t aws_clz_i64(int64_t n) { + unsigned long idx = 0; + if (_BitScanReverse64(&idx, (uint64_t)n)) { + return 63 - idx; + } + return 64; +} + +AWS_STATIC_IMPL size_t aws_clz_size(size_t n) { +#if SIZE_BITS == 64 + return aws_clz_u64(n); +#else + return aws_clz_u32(n); +#endif +} + +/** + * Search from the LSB to MSB, looking for a 1 + */ +AWS_STATIC_IMPL size_t aws_ctz_u32(uint32_t n) { + unsigned long idx = 0; + if (_BitScanForward(&idx, n)) { + return idx; + } + return 32; +} + +AWS_STATIC_IMPL size_t aws_ctz_i32(int32_t n) { + unsigned long idx = 0; + if (_BitScanForward(&idx, (uint32_t)n)) { + return idx; + } + return 32; +} + +AWS_STATIC_IMPL size_t aws_ctz_u64(uint64_t n) { + unsigned long idx = 0; + if (_BitScanForward64(&idx, n)) { + return idx; + } + return 64; +} + +AWS_STATIC_IMPL size_t aws_ctz_i64(int64_t n) { + unsigned long idx = 0; + if (_BitScanForward64(&idx, (uint64_t)n)) { + return idx; + } + return 64; +} + +AWS_STATIC_IMPL size_t aws_ctz_size(size_t n) { +#if SIZE_BITS == 64 + return aws_ctz_u64(n); +#else + return aws_ctz_u32(n); +#endif +} + +AWS_EXTERN_C_END +#endif /* WS_COMMON_MATH_MSVC_INL */