test+fix: Add asm testing and fix core_hint_black_box#147
test+fix: Add asm testing and fix core_hint_black_box#147Daniel-Aaron-Bloom wants to merge 1 commit intodalek-cryptography:mainfrom
core_hint_black_box#147Conversation
|
Semi Related: #135 (Also touches the |
|
Const-ness and better "guarantees" (heuristic guarantees anyway) are the main reasons to prefer I've been writing my own version of The difference in ASM is something like the following: read_volatile_select_if_eq:
push rbp
push rbx
push rax
mov ebx, esi
mov ebp, edi
xor edi, edi
cmp edx, esi
sete dil
call subtle::black_box
movzx eax, al
neg eax
xor ebp, ebx
and ebp, eax
xor ebp, ebx
mov eax, ebp
add rsp, 8
pop rbx
pop rbp
ret
subtle::black_box:
mov byte ptr [rsp - 1], dil
movzx eax, byte ptr [rsp - 1]
ret
vs hint_bb_select_if_eq:
cmp esi, edx
sete byte ptr [rsp - 1]
lea rax, [rsp - 1]
movzx eax, byte ptr [rsp - 1]
neg eax
xor esi, edi
and eax, esi
xor eax, edi
ret
edit: of course the |
Per this zulip discussion and rust-lang/rust#140341 and in contrast to the discussion on #107,
read_volatile(and all other equivalent functions in the standard library) should provide strict fewer optimization barriers thanblack_box.In service of testing this, I've added a script which makes sure the assembly instructions of a simple case are approximately the expected length across most common architectures.
Also
read_volatileis never going to beconst, and it would be nice toconstify this library (which will hopefully be my next PR if this one is accepted).