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

Method GetIntConst

source/opt/constants.cpp:507–530  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

505}
506
507const Constant* ConstantManager::GetIntConst(uint64_t val, int32_t bitWidth,
508 bool isSigned) {
509 Type* int_type = context()->get_type_mgr()->GetIntType(bitWidth, isSigned);
510
511 if (isSigned) {
512 // Sign extend the value.
513 int32_t num_of_bit_to_ignore = 64 - bitWidth;
514 val = static_cast<int64_t>(val << num_of_bit_to_ignore) >>
515 num_of_bit_to_ignore;
516 } else if (bitWidth < 64) {
517 // Clear the upper bit that are not used.
518 uint64_t mask = ((1ull << bitWidth) - 1);
519 val &= mask;
520 }
521
522 if (bitWidth <= 32) {
523 return GetConstant(int_type, {static_cast<uint32_t>(val)});
524 }
525
526 // If the value is more than 32-bit, we need to split the operands into two
527 // 32-bit integers.
528 return GetConstant(
529 int_type, {static_cast<uint32_t>(val), static_cast<uint32_t>(val >> 32)});
530}
531
532uint32_t ConstantManager::GetUIntConstId(uint32_t val) {
533 Type* uint_type = context()->get_type_mgr()->GetUIntType();

Callers 2

NegateIntConstFunction · 0.80
FlattenArrayTypeMethod · 0.80

Calls 2

GetIntTypeMethod · 0.80
get_type_mgrMethod · 0.80

Tested by

no test coverage detected