You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Help the compiler avoid inlining lazy init functions (#443)
Before this change, the compiler generates code that looks like this:
```
if not initialized:
goto init
do_work:
do the actual work
goto exit
init:
inilned init()
goto do_work
exit:
ret
```
If the initialization code is small, this works fine. But, for (bad)
reasons, is_rdrand_good is particularly huge. Thus, jumping over its
inined code is wasteful because it puts bad pressure on the instruction
cache.
With this change, the generated code looks like this:
```
if not initialized:
goto init
do_work:
do the actual work
goto exit
init:
call init()
goto do_work
exit:
ret
```
I verified these claims by running:
```
$ cargo asm --rust getrandom_inner --lib --target=x86_64-fortanix-unknown-sgx
```
This is also what other implementations (e.g. OnceCell) do.
While here, I made the analogous change to LazyPtr, and rewrote LazyPtr
to the same form as LazyUsize. I didn't check the generated code for
LazyPtr though.
(Why is `is_rdrand_good` huge? The compiler unrolls the 10 iteration
retry loop, and then it unrolls the 8 iteration self-test loop, so the
result is `rdrand()` is inlined 80 times inside is_rdrand_good. This is
something to address separately as it also affects `getrandom_inner`
itself.)
0 commit comments