Sign Up
Log In
Log In
or
Sign Up
Places
All Projects
Status Monitor
Collapse sidebar
home:Ledest:erlang:23
erlang
6121-rand-Slightly-optimize-the-mwc59-family-of...
Overview
Repositories
Revisions
Requests
Users
Attributes
Meta
File 6121-rand-Slightly-optimize-the-mwc59-family-of-functions.patch of Package erlang
From 048b36690298aa38ac2a9e29507d81606ac18e60 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bj=C3=B6rn=20Gustavsson?= <bjorn@erlang.org> Date: Thu, 29 Sep 2022 07:00:59 +0200 Subject: [PATCH] rand: Slightly optimize the mwc59 family of functions Recent improvements in the compiler (92611e5d2d75) and the JIT (f8a9ccda6c4a) allows us to write more natural code using guard tests instead of `band` operations to establish ranges for integers. This also happens to be slightly faster. --- lib/stdlib/src/rand.erl | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/lib/stdlib/src/rand.erl b/lib/stdlib/src/rand.erl index 5f8d3a4c59..e2f0278627 100644 --- a/lib/stdlib/src/rand.erl +++ b/lib/stdlib/src/rand.erl @@ -1502,8 +1502,7 @@ dummy_seed({A1, A2, A3}) -> -type mwc59_state() :: 1..?MWC59_P-1. -spec mwc59(CX0 :: mwc59_state()) -> CX1 :: mwc59_state(). -mwc59(CX0) -> % when is_integer(CX0), 1 =< CX0, CX0 < ?MWC59_P -> - CX = ?MASK(59, CX0), +mwc59(CX) when is_integer(CX), 1 =< CX, CX < ?MWC59_P -> C = CX bsr ?MWC59_B, X = ?MASK(?MWC59_B, CX), ?MWC59_A * X + C. @@ -1521,18 +1520,17 @@ mwc59(CX0) -> % when is_integer(CX0), 1 =< CX0, CX0 < ?MWC59_P -> %%% mwc59(CX1, N - 1). -spec mwc59_value32(CX :: mwc59_state()) -> V :: 0..?MASK(32). -mwc59_value32(CX1) -> % when is_integer(CX1), 1 =< CX1, CX1 < ?MWC59_P -> +mwc59_value32(CX1) when is_integer(CX1), 1 =< CX1, CX1 < ?MWC59_P -> CX = ?MASK(32, CX1), CX bxor ?BSL(32, CX, ?MWC59_XS). -spec mwc59_value(CX :: mwc59_state()) -> V :: 0..?MASK(59). -mwc59_value(CX1) -> % when is_integer(CX1), 1 =< CX1, CX1 < ?MWC59_P -> - CX = ?MASK(59, CX1), +mwc59_value(CX) when is_integer(CX), 1 =< CX, CX < ?MWC59_P -> CX2 = CX bxor ?BSL(59, CX, ?MWC59_XS1), CX2 bxor ?BSL(59, CX2, ?MWC59_XS2). -spec mwc59_float(CX :: mwc59_state()) -> V :: float(). -mwc59_float(CX1) -> +mwc59_float(CX1) when is_integer(CX1), 1 =< CX1, CX1 < ?MWC59_P -> CX = ?MASK(53, CX1), CX2 = CX bxor ?BSL(53, CX, ?MWC59_XS1), CX3 = CX2 bxor ?BSL(53, CX2, ?MWC59_XS2), -- 2.35.3
Locations
Projects
Search
Status Monitor
Help
OpenBuildService.org
Documentation
API Documentation
Code of Conduct
Contact
Support
@OBShq
Terms
openSUSE Build Service is sponsored by
The Open Build Service is an
openSUSE project
.
Sign Up
Log In
Places
Places
All Projects
Status Monitor