aboutsummaryrefslogtreecommitdiff
path: root/core/runtime
diff options
context:
space:
mode:
authorgingerBill <bill@gingerbill.org>2023-09-27 11:38:11 +0100
committergingerBill <bill@gingerbill.org>2023-09-27 11:38:11 +0100
commitacc29fbcebf4459b1c98c54d9cc565d363a4196a (patch)
tree91b4692e0a8c9c3958ed44347ded5a2f40ee157d /core/runtime
parent94d68c1f225c3699d905388baee15e42ec6e49a0 (diff)
parentfc93ea7aa370d25aab61dab43e885f50978dff50 (diff)
Merge branch 'master' into llvm-17
Diffstat (limited to 'core/runtime')
-rw-r--r--core/runtime/internal.odin42
1 files changed, 42 insertions, 0 deletions
diff --git a/core/runtime/internal.odin b/core/runtime/internal.odin
index 7e13bb929..d0e550743 100644
--- a/core/runtime/internal.odin
+++ b/core/runtime/internal.odin
@@ -413,6 +413,48 @@ cstring_to_string :: proc "contextless" (s: cstring) -> string {
}
+cstring_eq :: proc "contextless" (lhs, rhs: cstring) -> bool {
+ x := ([^]byte)(lhs)
+ y := ([^]byte)(rhs)
+ if x == y {
+ return true
+ }
+ if (x == nil) ~ (y == nil) {
+ return false
+ }
+ xn := cstring_len(lhs)
+ yn := cstring_len(rhs)
+ if xn != yn {
+ return false
+ }
+ return #force_inline memory_equal(x, y, xn)
+}
+
+cstring_cmp :: proc "contextless" (lhs, rhs: cstring) -> int {
+ x := ([^]byte)(lhs)
+ y := ([^]byte)(rhs)
+ if x == y {
+ return 0
+ }
+ if (x == nil) ~ (y == nil) {
+ return -1 if x == nil else +1
+ }
+ xn := cstring_len(lhs)
+ yn := cstring_len(rhs)
+ ret := memory_compare(x, y, min(xn, yn))
+ if ret == 0 && xn != yn {
+ return -1 if xn < yn else +1
+ }
+ return ret
+}
+
+cstring_ne :: #force_inline proc "contextless" (a, b: cstring) -> bool { return !cstring_eq(a, b) }
+cstring_lt :: #force_inline proc "contextless" (a, b: cstring) -> bool { return cstring_cmp(a, b) < 0 }
+cstring_gt :: #force_inline proc "contextless" (a, b: cstring) -> bool { return cstring_cmp(a, b) > 0 }
+cstring_le :: #force_inline proc "contextless" (a, b: cstring) -> bool { return cstring_cmp(a, b) <= 0 }
+cstring_ge :: #force_inline proc "contextless" (a, b: cstring) -> bool { return cstring_cmp(a, b) >= 0 }
+
+
complex32_eq :: #force_inline proc "contextless" (a, b: complex32) -> bool { return real(a) == real(b) && imag(a) == imag(b) }
complex32_ne :: #force_inline proc "contextless" (a, b: complex32) -> bool { return real(a) != real(b) || imag(a) != imag(b) }