-
Notifications
You must be signed in to change notification settings - Fork 1k
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
Replace ASM with CryptOpt generated #1329
base: master
Are you sure you want to change the base?
Conversation
Can someone help with those two errors? |
You can build the Docker image locally using |
But what's special about these builds is that they have |
I actually did that locally, too but could not reproduce the issue. What worked was building the container and run the cirrus script in there with the given environment, as per cirrus logs. I could then reproduce and fix the issue, which I believe depends a bit on the compiler version. I've changed the code by hand to not spill into rsp-based memory whatsoever, and instead use three tmp variables like the old code. Additionally, I used the |
The currently failing tests don't seem to be related to the field arithmetic. Instead, they seem to fail at the self test when calling https://cirrus-ci.com/task/4534411765481472?logs=test#L237 ==3831== Process terminating with default action of signal 6 (SIGABRT): dumping core |
Nice, so I've changed the selftest such that it will not check the CPU flags, if it is running in valgrind. I've used |
Looks good to me now actually, but there are a couple points that I should point out:
|
Is there anything I can help with for this PR? What would the next steps be? |
Hey, we’d love to mention this at an upcoming conference (acknowledging your support; top event in heuristic optimization), but for that it would have to be merged by 28 June. Of course, we understand that you need to be convinced of the usefulness of the verified and optimized... and of course we understand that you have your own workflows and deadlines, too. Still, if there is anything we can do to push this further, please do let us know. |
@dderjoel A common strategy to find reviewers is to convince them that the benefits of the PR are worth the review time. The PR should be as simple as possible to review. Squash the commits into a single or more logical commits. Provide some context and guidance on the best way to review the changes. It seems to me that reviewing this is difficult. However, keep in mind that, as per the plan discussed here, integrating the fiat-crypto C output code is currently a higher priority. |
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.
Indentation should be 4 spaces in C files. (Sometimes only 2 are used here.)
I agree with @jonasnick, it will help to have clean and well separated commits.
And yes, at least according to the plan we made, this is blocked on fiat-crypto C code. No matter if it's blocked or not, it's not realistic to get this merged by 28th. But I feel it's certainly fair to say that the code is under review and planned to be integrated (if this helps).
secp256k1_fe_mul_inner(uint64_t *r, const uint64_t *a, | ||
const uint64_t *SECP256K1_RESTRICT b) { |
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 can go on one line. (We don't have a fixed value for max length of lines, but they tend to be longer than shorter.)
- I know you took the
SECP256K1_RESTRICT
from the old code, but I think it can be dropped. It's rather meaningless here. (What is the compiler supposed to optimize here?! It's just asm.) Or am I overlooking something?
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 compiler supposed to optimize here?! It's just asm.)
Now that I think about it again, I suggest leaving it in. It's there now, and whether to remove it is probably a separate discussion.
But in general, can you confirm that the code here is intended to stick to the rules laid out in field.h
?
/* (...)
* r and a may point to the same object, but neither can be equal to b. (...)
*/
static void secp256k1_fe_mul(secp256k1_fe *r, const secp256k1_fe *a, const secp256k1_fe *b);
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.
Neither the Optimizer, nor the checker enforces that property. But manually checking it at the moment shows that it is the case. Maybe it's possible to check that on the fiat side. I'm tracking that in issue 0xADE1A1DE/CryptOpt#167 for the cryptopt side.
0b1c7ad
to
47ddc46
Compare
Thanks for the feedback. I kept the commits in there to have the history and thought we may squash them on merge. |
Do not merge until tested with |
Problem seems indeed to be |
f500408
to
b160ddd
Compare
Hi, I've also rebased the branch on the current master, and changed the note in the Readme, that the assembly is no longer the hand optimized version, but the CryptOpt-generated one. Those numbers are with
|
@andres-erbsen , you're saying the C code didn't change. Is there anything that we'd believe would change in the JSON? I wonder if I would need to give it a try to generate myself and check. (Reason why I think there could be changes is that I am removing all |
I would guess there are no relevant changes. If so, I expect the fiat-crypto equivalence checker would pass with the assembly files you have and |
Nice, I've double checked: |
In this PR the auto detection of x86_64 is removed and the configure file will default to the C implementation.
Further, if asm has explicitly been requested with
--with-asm=x86_64
,the
selfcheck
method check by calling thecpuid
instruction, if the flagsBMI2
(bit 8) andADX
(bit 19) are set, and will exit early, if not.