Skip to content

ffc_sv_create: zero just the length#18

Merged
kolemannix merged 1 commit intomainfrom
no_zero_bigint_create
Mar 8, 2026
Merged

ffc_sv_create: zero just the length#18
kolemannix merged 1 commit intomainfrom
no_zero_bigint_create

Conversation

@kolemannix
Copy link
Owner

The array shouldn't need to be zero-initialized.
We should never read from any element of the array that has not been initialized by a push or extend

The array shouldn't need to be zero-initialized.
We should never read from any element of the array
that has not been initialized by a push or extend
Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

This PR optimizes ffc_sv_create by removing the zero-initialization of the entire ffc_sv struct (which includes a large stack-allocated array of up to 125/62 limbs) and instead only initializing the len field to 0. This is safe because the data array elements are always written before being read (via ffc_sv_try_extend), and this pattern is already used elsewhere in the codebase.

Changes:

  • Replaced ffc_sv new_one = {0} with ffc_sv new_one; new_one.len = 0; in ffc_sv_create, avoiding unnecessary zeroing of the data array.

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated no comments.

File Description
src/bigint.h Remove zero-initialization of ffc_sv in ffc_sv_create, only set len = 0
ffc.h Mirror the same change in the amalgamated single-header version

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@kolemannix kolemannix merged commit 5f617b2 into main Mar 8, 2026
10 checks passed
@kolemannix
Copy link
Owner Author

Ran the exhaustive suite as well for this guy:

~/dev/ffc.h no_zero_bigint_create 17s ❯ FFC_EXH_THREADS=10 make -B exhaustive                                                12:54:44 PM
python3 amalgamate.py > ffc.h
mkdir -p out
clang -xc -Wall -Wextra -Wpedantic -O3 -g -std=c99  -pthread -I. -Itest_src test_src/test_exhaustive.c -o out/test_exhaustive_runner -lm
./out/test_exhaustive_runner
Running exhaustive test: threads=10 sample_stride=1 (~100.00% of 4294967296 values)
Progress: 10% (429496730/4294967296)
Progress: 20% (858993460/4294967296)
Progress: 30% (1288490189/4294967296)
Progress: 40% (1717986919/4294967296)
Progress: 50% (2147483648/4294967296)
Progress: 60% (2576980378/4294967296)
Progress: 70% (3006477108/4294967296)
Progress: 80% (3435973837/4294967296)
Progress: 90% (3865470567/4294967296)
Progress: 100% (4294967296/4294967296)
Exhaustive run completed: checked 4294967296 values in 2211.51 seconds
all ok

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