Skip to content

igzip: save xmm6-xmm15 at 16-byte steps in the win64 ICF encoders - #450

Closed
ptweezy wants to merge 1 commit into
intel:masterfrom
ptweezy:igzip-encode-win64-xmm-save
Closed

ptweezy wants to merge 1 commit into
intel:masterfrom
ptweezy:igzip-encode-win64-xmm-save

Conversation

@ptweezy

@ptweezy ptweezy commented Oct 21, 2026 •

Copy link
Copy Markdown

On win64, FUNC_SAVE and FUNC_RESTORE in encode_df_04.asm and encode_df_06.asm save and restore xmm6-xmm15 with 16-byte MOVDQU at xmm_save_mem_offset + i*8, so each save overwrites the upper half of the previous one, and encode_deflate_icf() returns with the upper 64 bits of xmm6-xmm14 replaced by the low 64 bits of the next register. This PR uses i*16; the save area is already 10 × 16 bytes.

Who is affected

Windows builds compressing at levels 1-3 on AVX2 (encode_deflate_icf_04) and AVX-512 (encode_deflate_icf_06) CPUs. A caller holding a 128-bit vector in xmm6-xmm14 across isal_deflate() or isal_deflate_stateless() gets its upper half back corrupted; scalar floats and doubles survive. Which registers are hit depends on the compiler's own saves in those functions: xmm7-xmm14 (stateless) in the CI build below; xmm8-xmm14 (stateless) and xmm9-xmm14 (stateful) with mingw-w64 gcc 13.

Output and the Linux (elf64) code do not change.

Testing

  • Windows CI with mingw, 6 jobs each (master on EPYC 7763/9V74 and Xeon 8370C, this PR on EPYC 7763/9V45/9V74; run, checker): after level 1-3 isal_deflate_stateless(), xmm7-xmm14 change on master and none with this PR, which also passes make check.
  • Native Windows on a Ryzen 7 9800X3D, mingw-w64 gcc 13: make check passes, and xmm6-xmm15 and the callee-saved GPRs stay intact across every _04/_06 encoder call and every isal_deflate()/isal_deflate_stateless() call. On master, every encoder call damages xmm6-xmm14.
  • Linux: make check and tools/check_format.sh pass.

On win64, the FUNC_SAVE and FUNC_RESTORE macros of encode_deflate_icf_04
and encode_deflate_icf_06 store and load xmm6-xmm15 with MOVDQU at
xmm_save_mem_offset + i*8. Each 16-byte store overwrites the upper half
of the one before it, so encode_deflate_icf() returns with the upper 64
bits of xmm6-xmm14 replaced by the low 64 bits of the next register.
The low halves and xmm15 come back intact, so scalar float and double
values survive, but a 128-bit vector value the caller keeps in
xmm6-xmm14 across level 1-3 compression on an AVX2 or AVX-512 machine
loses its upper half. Which registers the caller sees damaged depends
on what the compiler saves in isal_deflate() and
isal_deflate_stateless() themselves: with mingw-w64 gcc 13, xmm9-xmm14
after isal_deflate() and xmm8-xmm14 after isal_deflate_stateless(); a
mingw build on GitHub's Windows runners shows xmm7-xmm14 after
isal_deflate_stateless().

Save each register in its own 16-byte slot. The save area is already
10 * 16 bytes.

Signed-off-by: Parker Loflin <parker@cronstable.dev>
@ptweezy
ptweezy force-pushed the igzip-encode-win64-xmm-save branch from bc4e5ed to 3a6ee3a Compare October 21, 2026 21:27

@tkanteck tkanteck left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

thanks - good find

@tkanteck tkanteck added the wip work in progress label Oct 28, 2026
@tkanteck

Copy link
Copy Markdown
Contributor

Thanks! It's merged a33f405

@tkanteck tkanteck closed this Oct 28, 2026
@ptweezy
ptweezy deleted the igzip-encode-win64-xmm-save branch October 28, 2026 22:18
@tkanteck tkanteck removed the wip work in progress label Oct 29, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants