From 55ea34dfffe14d973d0b3eef73d182c1d873c285 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Beno=C3=AEt=20du=20Garreau?= Date: Fri, 30 Oct 2020 15:56:02 +0100 Subject: [PATCH 1/2] Better branch likelyness on stable It uses uses the `#[cold]` attribute to get a similar effect --- src/raw/mod.rs | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/src/raw/mod.rs b/src/raw/mod.rs index e3da8714f5..2936f24f9a 100644 --- a/src/raw/mod.rs +++ b/src/raw/mod.rs @@ -43,14 +43,23 @@ use self::imp::Group; // consistently improves performance by 10-15%. #[cfg(feature = "nightly")] use core::intrinsics::{likely, unlikely}; + +#[cfg(not(feature = "nightly"))] +#[inline] +#[cold] +fn cold() {} + #[cfg(not(feature = "nightly"))] #[inline] fn likely(b: bool) -> bool { + if !b { cold() } b } #[cfg(not(feature = "nightly"))] +#[cold] #[inline] fn unlikely(b: bool) -> bool { + if b { cold() } b } From bbda6e0077bafb75c02d0ace665faa09b4514932 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Beno=C3=AEt=20du=20Garreau?= Date: Mon, 2 Nov 2020 18:45:23 +0100 Subject: [PATCH 2/2] Add comment --- src/raw/mod.rs | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/raw/mod.rs b/src/raw/mod.rs index 2936f24f9a..3b667fd44d 100644 --- a/src/raw/mod.rs +++ b/src/raw/mod.rs @@ -44,6 +44,8 @@ use self::imp::Group; #[cfg(feature = "nightly")] use core::intrinsics::{likely, unlikely}; +// On stable we can use #[cold] to get a equivalent effect: this attributes +// suggests that the function is unlikely to be called #[cfg(not(feature = "nightly"))] #[inline] #[cold] @@ -56,7 +58,6 @@ fn likely(b: bool) -> bool { b } #[cfg(not(feature = "nightly"))] -#[cold] #[inline] fn unlikely(b: bool) -> bool { if b { cold() }