-
Notifications
You must be signed in to change notification settings - Fork 265
Open
Description
GetThreadId uses the following thread-local storage:
thread_local!(static KEY: u8 = 0);This can be optimized as follows:
thread_local!(static KEY: u8 = const { 0 });which compiles to more optimal assembly:
#[no_mangle]
pub fn a() -> *const u8 {
thread_local!(static A: u8 = 0);
A.with(|a| ptr::from_ref(a))
}
#[no_mangle]
pub fn b() -> *const u8 {
thread_local!(static B: u8 = const { 0 });
B.with(|b| ptr::from_ref(b))
}a:
cmpb $0, %fs:A@TPOFF
je .LBB9_1
movq %fs:0, %rax
leaq A@TPOFF+1(%rax), %rax
retq
.LBB9_1:
movw $1, %fs:A@TPOFF
movq %fs:0, %rax
leaq A@TPOFF+1(%rax), %rax
retq
b:
movq %fs:0, %rax
leaq B@TPOFF(%rax), %rax
retqReactions are currently unavailable
Metadata
Metadata
Assignees
Labels
No labels