diff options
| author | gingerBill <bill@gingerbill.org> | 2019-08-09 20:31:11 +0100 |
|---|---|---|
| committer | gingerBill <bill@gingerbill.org> | 2019-08-09 20:31:11 +0100 |
| commit | 65d41d4248b61e6ef79ed02c2ce4f3be305149a5 (patch) | |
| tree | ff48b29752f44d61a59486139e2ece9289e3bdac /core/runtime | |
| parent | b04231dd95b6a80789b5e8762a51db4506948da1 (diff) | |
Fix bit_field comparison against nil #414
Diffstat (limited to 'core/runtime')
| -rw-r--r-- | core/runtime/internal.odin | 34 |
1 files changed, 34 insertions, 0 deletions
diff --git a/core/runtime/internal.odin b/core/runtime/internal.odin index 90d653c71..c33d5f62c 100644 --- a/core/runtime/internal.odin +++ b/core/runtime/internal.odin @@ -281,6 +281,40 @@ memory_compare :: proc "contextless" (a, b: rawptr, n: int) -> int #no_bounds_ch return 0; } +memory_compare_zero :: proc "contextless" (a: rawptr, n: int) -> int #no_bounds_check { + x := uintptr(a); + n := uintptr(n); + + SU :: size_of(uintptr); + fast := uintptr(n/SU + 1); + offset := (fast-1)*SU; + curr_block := uintptr(0); + if n < SU { + fast = 0; + } + + for /**/; curr_block < fast; curr_block += 1 { + va := (^uintptr)(x + curr_block * size_of(uintptr))^; + if va ~ 0 != 0 { + for pos := curr_block*SU; pos < n; pos += 1 { + a := (^byte)(x+pos)^; + if a ~ 0 != 0 { + return int(a) < 0 ? -1 : +1; + } + } + } + } + + for /**/; offset < n; offset += 1 { + a := (^byte)(x+offset)^; + if a ~ 0 != 0 { + return int(a) < 0 ? -1 : +1; + } + } + + return 0; +} + string_eq :: proc "contextless" (a, b: string) -> bool { switch { case len(a) != len(b): return false; |