-
Notifications
You must be signed in to change notification settings - Fork 24
Port simpasm from mlkem-native to mldsa-native
#541
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Conversation
093e624 to
aa273c1
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks @willieyz! I think the changes look okay - I still need to check the autogen script in detail.
The commit structure, however, is currently a large mess.
Most importantly, please make sure that git can track the move from src/ to dev/. That should be done in a separate commit. Then make all the necessary changes to the assembly in dev/ in a separate commit each. Then finally autogenerate the assemby in a single commit.
.github/workflows/base.yml
Outdated
| - arg: '--aarch64-clean' | ||
| name: Clean | ||
| - arg: '' | ||
| name: Optimized |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What is the purpose of this? We don't have an optimized/clean seperation so far?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, you are right about this, I originally thought that we would have optimized/clean eventually, so I added this.
Now I remove this and add a TODO comment instead, thanks for your review!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please change the second commit so that git can track this as a file move so that we keep history for these files. I thought I had mentioned this before.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hello, @mkannwischer, sorry about this mistake,
Now I re-organized all file structure, do it by move instead of copy, this is my fault,
Thank you for your review!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't understand why the third commit is removing files from dev/aarch64_clean/src
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This one also fixed after I re-organized the structure from copy to move,
thanks you for your review!
402db8a to
dce1c9c
Compare
- This commit ports the `simpasm` script and related functions in `autogen` from `mlkem-native` to `mldsa-native`. - Added the `simpasm` job in `base.yml` and changed the `nix-shell` from `ci` to `ci-cross` in `ci.yml` for ASM simplification. - Since the CFI scripts have not yet been ported to `mldsa-native`, the `--cfify` argument has been removed temporary. A TODO comment has been added and will be restored once the CFI scripts are ported. Signed-off-by: willieyz <[email protected]>
Signed-off-by: willieyz <[email protected]>
- This commit add simpasm header and footer to all assembly code in dev/ - Change balign from 16 to 4 in poly_caddq_asm.S to match our standard setting. - The llvm-objdump discards one of the consecutive labels, which causes the autogen script to fail. We removed the end label since it is not used anywhere, and also simplified this two in a separate commit. Signed-off-by: willieyz <[email protected]>
Signed-off-by: willieyz <[email protected]>
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks @willieyz! The commit structure is now much better.
Here are a couple of more comments primarily to align things with mlkem-native - otherwise maintainance of this is going to be unmanagable over time.
| - uses: ./.github/actions/setup-shell | ||
| with: | ||
| nix-shell: 'ci' | ||
| nix-shell: 'ci-cross' # Need cross-compiler for ASM simplification |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Did you forget to copy the nix-cache: 'true' here? Or was that intentionaly omited?
| def update_via_copy(infile_full, outfile_full, dry_run=False, transform=None): | ||
| status_update("copy", f"{infile_full} -> {outfile_full}") | ||
|
|
||
| with open(infile_full, "r") as f: | ||
| content = f.read() | ||
|
|
||
| if transform is not None: | ||
| content = transform(content) | ||
|
|
||
| update_file(outfile_full, content, dry_run=dry_run) | ||
|
|
||
|
|
||
| def update_via_remove(filename, dry_run=False): | ||
| if dry_run is True: | ||
| print( | ||
| f"Autogenerated file {filename} needs removing. Have you called scripts/autogen?", | ||
| file=sys.stderr, | ||
| ) | ||
| exit(1) | ||
|
|
||
| # Remove the file | ||
| os.remove(filename) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can we stick to the same order of functions as in mlkem-native, to minimize the diff.
In mlkem-native update_via_copy and update_via_remove come much later in the file.
| # Determine architecture from filename | ||
| arch = "aarch64" if "aarch64" in infile_full else "x86_64" | ||
|
|
||
| # TODO: Temporary remvoe the "--cfify", add back when CFI script added. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you just leave it in there but comment it out? That will make it easier to re-add it in the correct place later.
| simpasm: | ||
| strategy: | ||
| fail-fast: false | ||
| matrix: # TODO: add backend option after we have optimized/clean seperation |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you please keep it in the file but comment it out in that case?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
matrix:
backend:
- arg: '--aarch64-clean'
name: Clean
# TODO: add backend option after we have optimized/clean seperation
# - arg: ''
# name: OptimizedThen you can also change the default for --aarch64-clean back to False.
| synchronize_backends( | ||
| dry_run=args.dry_run, | ||
| clean=args.aarch64_clean, | ||
| force_cross=args.force_cross, | ||
| no_simplify=args.no_simplify, | ||
| ) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why are the arguments ordered differently here from mlkem-native? Please try to minimize the diff.
| no_simplify=args.no_simplify, | ||
| ) | ||
|
|
||
| high_level_status("Synchronized backends") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There is another diff here because of spacing issues.
simpasmscript frommlkem-nativetomldsa-naive. Currently, there are some differences between the two repositories, so thesimpasmscript and the related CI jobs need to be adjusted. Allaarch64andx86_64assembly code has been simplified on their respective systems.mldsa-nativeto make it compatible with oursimpasmscripts. The detailed description is as follows:Since the CFI have not been ported to
mldsa-nativeyet, we have temporarily removed the--cfifyargument in theautogenscripts and added a comment:# TODO: Temporarily remove the "--cfify"; add back when the CFI script is implemented.Once the CFI scripts are ported (see issue Call Frame Information (CFI) directives missing in assembly functions which breaks stack unwinding #425), this will be restored.
For the assembly file
poly_caddq_asm.S, there is an.balign 16directive. We have changed this.balignto match our standard setting insimpasm(see autogen_header), where.balignis set to4, and simplified it in a separate commit.For the assembly files
rej_uniform_eta2_asm.Sandrej_uniform_eta4_asm.S, there are two consecutive labels:The
llvm-objdumpdiscards one of the consecutive labels, which causes theautogenscript to fail. We removed the end label since it is not used anywhere, and also simplified this two in a separate commit.