From 474d79dcf1d5c272bd4b32ce93b7f935ae5e7f29 Mon Sep 17 00:00:00 2001 From: gingerBill Date: Wed, 10 Jun 2020 16:37:22 +0100 Subject: [PATCH] Add `mem.simple_compare_values` --- core/mem/mem.odin | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/core/mem/mem.odin b/core/mem/mem.odin index fef8e7619..b456a5401 100644 --- a/core/mem/mem.odin +++ b/core/mem/mem.odin @@ -1,6 +1,7 @@ package mem import "core:runtime" +import "core:intrinsics" set :: proc(data: rawptr, value: byte, len: int) -> rawptr { return runtime.memset(data, i32(value), len); @@ -70,6 +71,11 @@ compare_byte_ptrs :: proc(a, b: ^byte, n: int) -> int #no_bounds_check { return 0; } +simple_compare_values :: proc(a, b: $T) -> int where intrinsics.type_is_simple_compare(T) { + a, b := a, b; + return compare_byte_ptrs((^byte)(&a), (^byte)(&b), size_of(T)); +} + compare_ptrs :: inline proc(a, b: rawptr, n: int) -> int { return compare_byte_ptrs((^byte)(a), (^byte)(b), n); }