diff options
| author | Feoramund <161657516+Feoramund@users.noreply.github.com> | 2024-06-20 11:27:51 -0400 |
|---|---|---|
| committer | Feoramund <161657516+Feoramund@users.noreply.github.com> | 2024-06-20 11:27:51 -0400 |
| commit | 1dfc89567ebb7b6509a0fd6080120da91b658df7 (patch) | |
| tree | 067ea74dd660bedf87ef797c48fe079a43850585 /base/runtime | |
| parent | 28e33d86de84767a12c2c1b590bdaa823373b2e0 (diff) | |
Optimize default RNG for the common case
Diffstat (limited to 'base/runtime')
| -rw-r--r-- | base/runtime/random_generator.odin | 25 |
1 files changed, 16 insertions, 9 deletions
diff --git a/base/runtime/random_generator.odin b/base/runtime/random_generator.odin index 0a9cab860..5e0ba2540 100644 --- a/base/runtime/random_generator.odin +++ b/base/runtime/random_generator.odin @@ -86,16 +86,23 @@ default_random_generator_proc :: proc(data: rawptr, mode: Random_Generator_Mode, init(r, 0) } - pos := i8(0) - val := u64(0) - for &v in p { - if pos == 0 { - val = read_u64(r) - pos = 7 + switch len(p) { + case size_of(u64): + // Fast path for a 64-bit destination. + (transmute(^u64)raw_data(p))^ = read_u64(r) + case: + // All other cases. + pos := i8(0) + val := u64(0) + for &v in p { + if pos == 0 { + val = read_u64(r) + pos = 7 + } + v = byte(val) + val >>= 8 + pos -= 1 } - v = byte(val) - val >>= 8 - pos -= 1 } case .Reset: |