diff options
| author | Jeroen van Rijn <Kelimion@users.noreply.github.com> | 2026-02-18 12:15:24 +0100 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2026-02-18 12:15:24 +0100 |
| commit | 06a56c5eddd577a4f7d74e3f34beb3f4e72375e8 (patch) | |
| tree | a304837360db4d4ae8951037a3736bb5420e4943 /core | |
| parent | 53c6c8a556c454f364739fcc8ce98275fefb2556 (diff) | |
| parent | 73a62f672a0683828e82f2cedbaa1fd9b17ffdd1 (diff) | |
Merge pull request #6300 from jakubtomsu/more-import-cleanup
More import cleanup and simplification
Diffstat (limited to 'core')
| -rw-r--r-- | core/hash/crc32.odin | 2 | ||||
| -rw-r--r-- | core/hash/hash.odin | 9 | ||||
| -rw-r--r-- | core/math/rand/rand_xoshiro256.odin | 12 | ||||
| -rw-r--r-- | core/net/dns.odin | 6 |
4 files changed, 16 insertions, 13 deletions
diff --git a/core/hash/crc32.odin b/core/hash/crc32.odin index 0a4617f6d..777209bed 100644 --- a/core/hash/crc32.odin +++ b/core/hash/crc32.odin @@ -1,7 +1,5 @@ package hash -import "base:intrinsics" - @(optimization_mode="favor_size") crc32 :: proc "contextless" (data: []byte, seed := u32(0)) -> u32 #no_bounds_check { crc := ~seed diff --git a/core/hash/hash.odin b/core/hash/hash.odin index 6c048c05b..b495fd30d 100644 --- a/core/hash/hash.odin +++ b/core/hash/hash.odin @@ -1,7 +1,6 @@ package hash import "core:mem" -import "base:intrinsics" @(optimization_mode="favor_size") adler32 :: proc "contextless" (data: []byte, seed := u32(1)) -> u32 #no_bounds_check { @@ -57,14 +56,14 @@ djb2 :: proc "contextless" (data: []byte, seed := u32(5381)) -> u32 { djbx33a :: proc "contextless" (data: []byte, seed := u32(5381)) -> (result: [16]byte) #no_bounds_check { state := [4]u32{seed, seed, seed, seed} - + s: u32 = 0 for p in data { state[s] = (state[s] << 5) + state[s] + u32(p) // hash * 33 + u32(b) s = (s + 1) & 3 } - - + + (^u32le)(&result[0])^ = u32le(state[0]) (^u32le)(&result[4])^ = u32le(state[1]) (^u32le)(&result[8])^ = u32le(state[2]) @@ -160,7 +159,7 @@ murmur32 :: proc "contextless" (data: []byte, seed := u32(0x9747b28c)) -> u32 { case 1: k1 ~= u32(tail[0]) k1 *= c1_32 - k1 = (k1 << 15) | (k1 >> 17) + k1 = (k1 << 15) | (k1 >> 17) k1 *= c2_32 h1 ~= k1 } diff --git a/core/math/rand/rand_xoshiro256.odin b/core/math/rand/rand_xoshiro256.odin index 7326ba8d5..6f5dbe545 100644 --- a/core/math/rand/rand_xoshiro256.odin +++ b/core/math/rand/rand_xoshiro256.odin @@ -3,8 +3,6 @@ package rand import "base:intrinsics" import "base:runtime" -import "core:math/bits" - /* The state for a xoshiro256** pseudorandom generator. */ @@ -17,7 +15,7 @@ xoshiro256_random_generator_proc :: proc(data: rawptr, mode: runtime.Random_Gene read_u64 :: proc "contextless" (r: ^Xoshiro256_Random_State) -> u64 { // xoshiro256** output function and state transition - result := bits.rotate_left64(r.s[1] * 5, 7) * 9 + result := rotate_left64(r.s[1] * 5, 7) * 9 t := r.s[1] << 17 r.s[2] = r.s[2] ~ r.s[0] @@ -25,9 +23,15 @@ xoshiro256_random_generator_proc :: proc(data: rawptr, mode: runtime.Random_Gene r.s[1] = r.s[1] ~ r.s[2] r.s[0] = r.s[0] ~ r.s[3] r.s[2] = r.s[2] ~ t - r.s[3] = bits.rotate_left64(r.s[3], 45) + r.s[3] = rotate_left64(r.s[3], 45) return result + + rotate_left64 :: proc "contextless" (x: u64, k: int) -> u64 { + n :: 64 + s := uint(k) & (n-1) + return x << s | x >> (n-s) + } } @(thread_local) diff --git a/core/net/dns.odin b/core/net/dns.odin index 6af18798b..54cc57c38 100644 --- a/core/net/dns.odin +++ b/core/net/dns.odin @@ -25,7 +25,6 @@ package net import "base:runtime" import "core:bufio" import "core:io" -import "core:math/rand" import "core:mem" import "core:strings" import "core:time" @@ -192,7 +191,10 @@ get_dns_records_from_nameservers :: proc(hostname: string, type: DNS_Record_Type init_dns_configuration() context.allocator = allocator - id := u16be(rand.uint32()) + id: u16be + rand_ok := runtime.random_generator_read_ptr(context.random_generator, &id, size_of(id)) + assert(rand_ok, "uninitialized gen/context.random_generator") + dns_packet_buf: [DNS_PACKET_MIN_LEN]byte = --- dns_packet := make_dns_packet(dns_packet_buf[:], id, hostname, type) or_return |