From 03c6cda7552ab2abe0443fbb4b0ea37b43f60fa5 Mon Sep 17 00:00:00 2001 From: Ellie Hermaszewska Date: Tue, 8 Aug 2023 06:01:55 +0800 Subject: 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 --- source/slang/slang-ir.cpp | 49 +++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 49 insertions(+) (limited to 'source/slang/slang-ir.cpp') 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(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) -- cgit v1.2.3