diff options
| author | Ellie Hermaszewska <ellieh@nvidia.com> | 2023-08-08 06:01:55 +0800 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2023-08-07 15:01:55 -0700 |
| commit | 03c6cda7552ab2abe0443fbb4b0ea37b43f60fa5 (patch) | |
| tree | e50eec86333ba788374d4d2382ff874725fe6964 /source/slang/slang-ir.cpp | |
| parent | 0d803a4c934ccfbb1922b86a7b09a7e98c77211a (diff) | |
Casting and vector/scalar correct arithmetic ops for SPIR-V (#3056)
* types for cast instructions
* Information getting functions for int and float types
* Implement spirv casting
* Broadcast operands for SPIR-V arithmetic
SPIR-V doesn't allow vector/sclar arithmetic ops
* Simplify spirv int/float type generation
---------
Co-authored-by: Yong He <yonghe@outlook.com>
Diffstat (limited to 'source/slang/slang-ir.cpp')
| -rw-r--r-- | source/slang/slang-ir.cpp | 49 |
1 files changed, 49 insertions, 0 deletions
diff --git a/source/slang/slang-ir.cpp b/source/slang/slang-ir.cpp index 38d1eb520..0a79cec57 100644 --- a/source/slang/slang-ir.cpp +++ b/source/slang/slang-ir.cpp @@ -6690,6 +6690,55 @@ namespace Slang return false; } + bool isFloatingType(IRType *t) + { + if(auto basic = as<IRBasicType>(t)) + { + switch(basic->getBaseType()) + { + case BaseType::Float: + case BaseType::Half: + case BaseType::Double: + return true; + default: + return false; + } + } + return false; + } + + IntInfo getIntTypeInfo(const IRType* intType) + { + switch(intType->getOp()) + { + case kIROp_UInt8Type: return {8, false}; + case kIROp_UInt16Type: return {16, false}; + case kIROp_UIntType: return {32, false}; + case kIROp_UInt64Type: return {64, false}; + case kIROp_Int8Type: return {8, true}; + case kIROp_Int16Type: return {16, true}; + case kIROp_IntType: return {32, true}; + case kIROp_Int64Type: return {64, true}; + + case kIROp_IntPtrType: // target platform dependent + case kIROp_UIntPtrType: // target platform dependent + default: + SLANG_UNEXPECTED("Unhandled type passed to getIntTypeInfo"); + } + } + + FloatInfo getFloatingTypeInfo(const IRType* floatType) + { + switch(floatType->getOp()) + { + case kIROp_HalfType: return {16}; + case kIROp_FloatType: return {32}; + case kIROp_DoubleType: return {64}; + default: + SLANG_UNEXPECTED("Unhandled type passed to getFloatTypeInfo"); + } + } + bool isIntegralScalarOrCompositeType(IRType* t) { if (!t) |
