mirror of
https://github.com/Ed94/Odin.git
synced 2026-08-05 15:18:49 +00:00
Optimize default RNG for the common case
This commit is contained in:
@@ -86,16 +86,23 @@ default_random_generator_proc :: proc(data: rawptr, mode: Random_Generator_Mode,
|
|||||||
init(r, 0)
|
init(r, 0)
|
||||||
}
|
}
|
||||||
|
|
||||||
pos := i8(0)
|
switch len(p) {
|
||||||
val := u64(0)
|
case size_of(u64):
|
||||||
for &v in p {
|
// Fast path for a 64-bit destination.
|
||||||
if pos == 0 {
|
(transmute(^u64)raw_data(p))^ = read_u64(r)
|
||||||
val = read_u64(r)
|
case:
|
||||||
pos = 7
|
// 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:
|
case .Reset:
|
||||||
|
|||||||
Reference in New Issue
Block a user