MCPcopy Create free account
hub / github.com/KhronosGroup/SPIRV-Tools / SignExtendValue

Function SignExtendValue

source/util/bitutils.h:187–198  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

185// significant bits from |value|, and sign-extending it to 64-bits.
186template <typename T>
187T SignExtendValue(T value, uint32_t number_of_bits) {
188 const uint32_t bit_width = sizeof(value) * 8;
189 if (number_of_bits == bit_width) return value;
190
191 bool is_negative = utils::IsBitAtPositionSet(value, number_of_bits - 1);
192 if (is_negative) {
193 value = utils::SetHighBits(value, bit_width - number_of_bits);
194 } else {
195 value = utils::ClearHighBits(value, bit_width - number_of_bits);
196 }
197 return value;
198}
199
200// Returns the value obtained by extracting the |number_of_bits| least
201// significant bits from |value|, and zero-extending it to 64-bits.

Callers 3

EncodeIntegerAsWordsFunction · 0.85
TEST_PFunction · 0.85

Calls 3

IsBitAtPositionSetFunction · 0.85
SetHighBitsFunction · 0.85
ClearHighBitsFunction · 0.85

Tested by 2

EncodeIntegerAsWordsFunction · 0.68
TEST_PFunction · 0.68