diff options
| author | gingerBill <bill@gingerbill.org> | 2024-02-22 17:24:42 +0000 |
|---|---|---|
| committer | gingerBill <bill@gingerbill.org> | 2024-02-22 17:24:42 +0000 |
| commit | 5a84a0822596fac47dd35bf1c2f1d9bb60bbe5c1 (patch) | |
| tree | 5e8f06646054cd3512e7738a5b8059a1bb057156 /base | |
| parent | a4b8c1ea1779ce93349b203aaf56c5aeca316b61 (diff) | |
Add general support for `bit_field`s
Diffstat (limited to 'base')
| -rw-r--r-- | base/runtime/internal.odin | 22 |
1 files changed, 22 insertions, 0 deletions
diff --git a/base/runtime/internal.odin b/base/runtime/internal.odin index 691f76ff1..62bee8620 100644 --- a/base/runtime/internal.odin +++ b/base/runtime/internal.odin @@ -1034,3 +1034,25 @@ fixdfti :: proc(a: u64) -> i128 { } } + + + +__write_bits :: proc "contextless" (dst, src: [^]byte, offset: uintptr, size: uintptr) { + for i in 0..<size { + j := offset+i + the_bit := byte((src[i/8]) & (1<<(i&7)) != 0) + b := the_bit<<(j&7) + dst[j/8] &~= b + dst[j/8] |= b + } +} + +__read_bits :: proc "contextless" (dst, src: [^]byte, offset: uintptr, size: uintptr) { + for j in 0..<size { + i := offset+j + the_bit := byte((src[i/8]) & (1<<(i&7)) != 0) + b := the_bit<<(j&7) + dst[j/8] &~= b + dst[j/8] |= b + } +}
\ No newline at end of file |