MCPcopy Create free account
hub / github.com/MJx0/KittyMemoryEx / bits

Function bits

KittyMemoryEx/KittyAsm.cpp:13–24  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

11namespace KittyAsm
12{
13 /// Extracts bits [hi:lo] of a word. The one place the shift/mask pair is
14 /// written, so an off-by-one in a field extraction has a single home.
15 uint32_t bits(uint32_t v, int hi, int lo)
16 {
17 // An inverted range or an out-of-word `lo` selects nothing; a `hi` past
18 // the top of the word is clamped to it, so bits(v, 40, 8) is every bit
19 // from 8 up rather than an error. Every in-tree call site passes
20 // constants inside the word, but this is public API and the guard costs
21 // one comparison on a path the compiler folds away for those constants.
22 if (hi < lo || lo < 0 || lo > 31)
23 return 0u;
24
25 // Clamped before `width` is computed, not after: `hi` arrives unbounded
26 // from a caller, and hi - lo + 1 below overflows int - itself undefined
27 // behaviour - for a hi anywhere near INT_MAX, before the width>=32 case

Callers 3

decodeInsnTypeFunction · 0.85
decodeInsnFunction · 0.85
bitFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected