Repository navigation
assemble: fix broadcast ratio calculation for sub-64-bit vector operands - #320
Open
agourakis82 wants to merge 1 commit into
Open
agourakis82 wants to merge 1 commit into
agourakis82 wants to merge 1 commit into
Conversation
Fixes netwide-assembler#263. get_broadcast_num() previously computed: brcast_num = ((opsize / (BITS64 >> SIZE_SHIFT)) * (BITS64 / brsize)) >> (opsize > (BITS64 >> SIZE_SHIFT)); When the memory operand size is smaller than BITS64 (such as xmmrm32 in VCVTPH2PD or VCVTPH2QQ with xmm destination, where opsize is BITS32 = 4 and BITS64 >> SIZE_SHIFT is 8), integer division opsize / 8 truncated to 0, causing NASM to report: error: mismatch in the number of broadcasting elements when assembling instructions with {1to2} broadcast like: vcvtph2pd xmm0, [rcx]{1to2} Replace the broken division formula with an exact bit-size lookup table indexed by ilog2_32(opsize), correctly supporting broadcast ratios for all operand sizes from BITS32 to BITS512.
Author
|
I rebuilt NASM locally from this PR head and ran the targeted AVX512-FP16 broadcast-related instruction tests. I did not run the full Travis matrix locally, but the directly related conversion/broadcast instruction fixtures pass with the rebuilt assembler. |
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.
Fixes #263.
Summary
In
asm/assemble.c,get_broadcast_num()previously calculated the number of broadcast elements with:When the operand size is smaller than
BITS64(such asxmmrm32inVCVTPH2PDorVCVTPH2QQwithxmmdestination, whereopsizeisBITS32which equals 4, andBITS64 >> SIZE_SHIFTequals 8), the integer divisionopsize / 8evaluated to0.As a consequence,
brcast_numbecame0, causing valid{1to2}broadcast instructions like:to fail with:
Fix
Replace the calculation with an exact bit-size lookup table indexed by
ilog2_32(opsize), accurately computing the broadcast ratio for all operand sizes fromBITS32throughBITS512.Verified assembling
vcvtph2pd xmm0, [rcx]{1to2},vcvtph2pd ymm0, [rcx]{1to4}, andvcvtph2pd zmm0, [rcx]{1to8}.