Repository navigation
Conversation
Change blas_quickdivide to accept and return BLASULONG across non-x86 architecture headers and the USE64BITINT/MSVC x86_64 path so 64-bit quotients on INTERFACE64=1 builds preserve their upper 32 bits and dividends near INT32_MAX + MAX_CPU_NUMBER avoid signed 32-bit overflow. Update common_x86.h blas_quickdivide to return unsigned int with a volatile result and cc clobber matching common_x86_64.h (0464e66), and widen width to BLASLONG in lapack/laed3/laed3_parallel.c. Add quickdivide_large_bounds regression test in utest/test_swap.c.
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
blas_quickdividereturns 32-bit signedintand accepts signedblasintacross twelve architecture headers, truncating 64-bit quotients underINTERFACE64=1and overflowing signed 32-bit dividends whenN + nthreads - 1 > INT32_MAX. This pull request widensblas_quickdividetoBLASULONGacross those headers, aligns 32-bit x86common_x86.hwithcommon_x86_64.h, and widenswidthinlaed3_parallel.c.Root Cause and Changes
common_arm64.h,common_riscv64.h,common_loongarch64.h,common_power.h,common_mips64.h,common_zarch.h,common_sparc.h,common_e2k.h,common_wasm.h,common_arm.h,common_mips.h, andcommon_csky.hdeclarestatic inline int blas_quickdivide(blasint x, blasint y). On 64-bitINTERFACE64=1(USE64BITINT) builds,blasintis 64-bit while theintreturn type truncates quotients>= 2^31to negative values, causing work-partitioning loops (i -= width) inblas_l1_thread.c,level3_thread.c, andgetrf_parallel.cto growiand overflowqueue[MAX_CPU_NUMBER]. OnINTERFACE64=0builds, callers passi + nthreads - num_cpu - 1, which exceedsINT32_MAXwhenNis near2^31 - 1(for example2147483640 + 15 = 2147483655) and overflows signed 32-bitblasintto negative values. UsingBLASULONGparameters and return type eliminates both bugs across 32-bit and 64-bit targets, including theUSE64BITINTandC_MSVCpaths incommon_x86_64.h.common_x86.hstill declaredint blas_quickdivide(unsigned int x, unsigned int y)withoutvolatileor"cc"inline-assembly clobbers onmull. Updatingcommon_x86.hto returnunsigned intwithvolatile unsigned int resultand: "cc"matches commit0464e662adincommon_x86_64.h.lapack/laed3/laed3_parallel.cstoredblas_quickdivideinint widthwhile indexingBLASLONG range[]andblasint i. WideningwidthtoBLASLONGpreserves 64-bit partition widths underINTERFACE64=1.Verification
swap:quickdivide_large_boundsinutest/test_swap.ccovering(2147483640 + 15) / 16andUSE64BITINT> 2^32division.-Wall -Wextra -Werror -DUSE64BITINTand passedopenblas_utest(162/162tests passing).