summaryrefslogtreecommitdiffstats
path: root/source
diff options
context:
space:
mode:
authorYong He <yonghe@outlook.com>2022-09-15 14:22:59 -0700
committerGitHub <noreply@github.com>2022-09-15 14:22:59 -0700
commita6032446c6bf7f64d1e201bf438a4c7605a3dbb4 (patch)
treea95267c52155e13699ff9aab38ab68353d76939e /source
parent05f9aaf6a4ef246dcf89b00000a8e59e90c47662 (diff)
Language feature: pointer sized int types. (#2401)
* Language feature: pointer sized int types. * Fix. * small change to test. * Fix stdlib. * Fix. * Fix. * Add typedef for `size_t` in stdlib. * Fix test. * Add `intptr_t::size` constant. Co-authored-by: Yong He <yhe@nvidia.com>
Diffstat (limited to 'source')
-rw-r--r--source/slang/core.meta.slang54
-rw-r--r--source/slang/slang-ast-builder.h2
-rw-r--r--source/slang/slang-check-decl.cpp14
-rw-r--r--source/slang/slang-check-expr.cpp4
-rw-r--r--source/slang/slang-emit-c-like.cpp29
-rw-r--r--source/slang/slang-emit-cpp.cpp11
-rw-r--r--source/slang/slang-emit-cuda.cpp2
-rw-r--r--source/slang/slang-emit-glsl.cpp47
-rw-r--r--source/slang/slang-emit-hlsl.cpp21
-rw-r--r--source/slang/slang-emit-spirv.cpp16
-rw-r--r--source/slang/slang-glsl-extension-tracker.cpp11
-rw-r--r--source/slang/slang-intrinsic-expand.cpp2
-rw-r--r--source/slang/slang-ir-any-value-marshalling.cpp12
-rw-r--r--source/slang/slang-ir-lower-bit-cast.cpp8
-rw-r--r--source/slang/slang-ir-lower-result-type.cpp2
-rw-r--r--source/slang/slang-ir-sccp.cpp22
-rw-r--r--source/slang/slang-lower-to-ir.cpp2
-rw-r--r--source/slang/slang-mangle.cpp2
-rw-r--r--source/slang/slang-parser.cpp21
-rw-r--r--source/slang/slang-stdlib.cpp4
-rw-r--r--source/slang/slang-type-layout.cpp2
-rw-r--r--source/slang/slang-type-system-shared.h2
-rw-r--r--source/slang/slang.cpp5
23 files changed, 270 insertions, 25 deletions
diff --git a/source/slang/core.meta.slang b/source/slang/core.meta.slang
index 39ba67d6a..5d4b57543 100644
--- a/source/slang/core.meta.slang
+++ b/source/slang/core.meta.slang
@@ -8,6 +8,9 @@ typedef double float64_t;
typedef int int32_t;
typedef uint uint32_t;
+typedef uintptr_t size_t;
+typedef uintptr_t usize_t
+typedef intptr_t ssize_t;
// Modifier for variables that must resolve to compile-time constants
// as part of translation.
@@ -229,6 +232,7 @@ ${{{{
case BaseType::Int16:
case BaseType::Int:
case BaseType::Int64:
+ case BaseType::IntPtr:
}}}}
, __BuiltinSignedArithmeticType
${{{{
@@ -237,6 +241,7 @@ ${{{{
case BaseType::UInt16:
case BaseType::UInt:
case BaseType::UInt64:
+ case BaseType::UIntPtr:
}}}}
, __BuiltinArithmeticType
, __BuiltinIntegerType
@@ -456,6 +461,26 @@ extension int64_t
static const int64_t minValue = -0x8000000000000000LL;
}
+extension intptr_t
+{
+ __generic<T>
+ __intrinsic_op($(kIROp_Construct))
+ __init(Ptr<T> ptr);
+ static const intptr_t maxValue = $(SLANG_PROCESSOR_X86_64?"0x7FFFFFFFFFFFFFFFz":"0x7FFFFFFFz");
+ static const intptr_t minValue = $(SLANG_PROCESSOR_X86_64?"0x8000000000000000z":"0x80000000z");
+ static const int size = $(SLANG_PROCESSOR_X86_64?"8":"4");
+}
+
+extension uintptr_t
+{
+ __generic<T>
+ __intrinsic_op($(kIROp_Construct))
+ __init(Ptr<T> ptr);
+ static const uintptr_t maxValue = $(SLANG_PROCESSOR_X86_64?"0xFFFFFFFFFFFFFFFFz":"0xFFFFFFFFz");
+ static const uintptr_t minValue = 0z;
+ static const int size = $(SLANG_PROCESSOR_X86_64?"8":"4");
+}
+
__generic<T>
__magic_type(OutType)
__intrinsic_type($(kIROp_OutType))
@@ -2300,7 +2325,9 @@ bool operator!=(E left, E right);
interface IComparable
{
- int compareTo(This other);
+ bool equals(This other);
+ bool lessThan(This other);
+ bool lessThanOrEquals(This other);
}
interface IArithmetic : IComparable
@@ -2340,37 +2367,37 @@ __generic<T : IComparable>
[__unsafeForceInlineEarly]
bool operator<(T v0, T v1)
{
- return v0.compareTo(v1) < 0;
+ return v0.lessThan(v1);
}
__generic<T : IComparable>
[__unsafeForceInlineEarly]
bool operator>(T v0, T v1)
{
- return v0.compareTo(v1) > 0;
+ return v1.lessThan(v0);
}
__generic<T : IComparable>
[__unsafeForceInlineEarly]
bool operator ==(T v0, T v1)
{
- return v0.compareTo(v1) == 0;
+ return v0.equals(v1);
}
__generic<T : IComparable>
[__unsafeForceInlineEarly]
bool operator >=(T v0, T v1)
{
- return v0.compareTo(v1) >= 0;
+ return v1.lessThanOrEquals(v1);
}
__generic<T : IComparable>
[__unsafeForceInlineEarly]
bool operator <=(T v0, T v1)
{
- return v0.compareTo(v1) <= 0;
+ return v0.lessThanOrEquals(v1);
}
__generic<T : IComparable>
[__unsafeForceInlineEarly]
bool operator !=(T v0, T v1)
{
- return v0.compareTo(v1) != 0;
+ return !v0.equals(v1);
}
__generic<T : IArithmetic>
@@ -2451,7 +2478,9 @@ for (int tt = 0; tt < kBaseTypeCount; ++tt)
}}}}
extension $(kBaseTypes[tt].name) : IInteger
{
- [__unsafeForceInlineEarly] int compareTo(This other){return this-other;}
+ [__unsafeForceInlineEarly] bool equals(This other){return this==other;}
+ [__unsafeForceInlineEarly] bool lessThan(This other){return this<other;}
+ [__unsafeForceInlineEarly] bool lessThanOrEquals(This other){return this<=other;}
[__unsafeForceInlineEarly] This add(This other) { return __add(this, other); }
[__unsafeForceInlineEarly] This sub(This other) { return __sub(this, other); }
[__unsafeForceInlineEarly] This mul(This other) { return __mul(this, other); }
@@ -2477,12 +2506,9 @@ ${{{{
extension $(kBaseTypes[tt].name) : IFloat
{
- [__unsafeForceInlineEarly] static int __sign(This val)
- {
- return int(__leq(This(0),val)) - int(__leq(val,This(0)));
- }
-
- [__unsafeForceInlineEarly] int compareTo(This other) { return __sign(this-other); }
+ [__unsafeForceInlineEarly] bool lessThan(This other) { return this < other; }
+ [__unsafeForceInlineEarly] bool lessThanOrEquals(This other) { return this <= other; }
+ [__unsafeForceInlineEarly] bool equals(This other) { return this == other; }
[__unsafeForceInlineEarly] This add(This other) { return __add(this, other); }
[__unsafeForceInlineEarly] This sub(This other) { return __sub(this, other); }
[__unsafeForceInlineEarly] This mul(This other) { return __mul(this, other); }
diff --git a/source/slang/slang-ast-builder.h b/source/slang/slang-ast-builder.h
index 788257fa0..3023e274d 100644
--- a/source/slang/slang-ast-builder.h
+++ b/source/slang/slang-ast-builder.h
@@ -269,8 +269,10 @@ public:
SLANG_FORCE_INLINE Type* getDoubleType() { return m_sharedASTBuilder->m_builtinTypes[Index(BaseType::Double)]; }
SLANG_FORCE_INLINE Type* getIntType() { return m_sharedASTBuilder->m_builtinTypes[Index(BaseType::Int)]; }
SLANG_FORCE_INLINE Type* getInt64Type() { return m_sharedASTBuilder->m_builtinTypes[Index(BaseType::Int64)]; }
+ SLANG_FORCE_INLINE Type* getIntPtrType() { return m_sharedASTBuilder->m_builtinTypes[Index(BaseType::IntPtr)]; }
SLANG_FORCE_INLINE Type* getUIntType() { return m_sharedASTBuilder->m_builtinTypes[Index(BaseType::UInt)]; }
SLANG_FORCE_INLINE Type* getUInt64Type() { return m_sharedASTBuilder->m_builtinTypes[Index(BaseType::UInt64)]; }
+ SLANG_FORCE_INLINE Type* getUIntPtrType() { return m_sharedASTBuilder->m_builtinTypes[Index(BaseType::UIntPtr)]; }
SLANG_FORCE_INLINE Type* getVoidType() { return m_sharedASTBuilder->m_builtinTypes[Index(BaseType::Void)]; }
/// Get a builtin type by the BaseType
diff --git a/source/slang/slang-check-decl.cpp b/source/slang/slang-check-decl.cpp
index 125f0cb08..660e28802 100644
--- a/source/slang/slang-check-decl.cpp
+++ b/source/slang/slang-check-decl.cpp
@@ -1096,10 +1096,12 @@ namespace Slang
case BaseType::Int16:
case BaseType::Int:
case BaseType::Int64:
+ case BaseType::IntPtr:
case BaseType::UInt8:
case BaseType::UInt16:
case BaseType::UInt:
case BaseType::UInt64:
+ case BaseType::UIntPtr:
break;
default:
getSink()->diagnose(varDecl, Diagnostics::staticConstRequirementMustBeIntOrBool);
@@ -3620,16 +3622,28 @@ namespace Slang
case BaseType::UInt16:
return (value >= 0 && value <= std::numeric_limits<uint16_t>::max()) || (value == -1);
case BaseType::UInt:
+#if SLANG_PTR_IS_32
+ case BaseType::UIntPtr:
+#endif
return (value >= 0 && value <= std::numeric_limits<uint32_t>::max()) || (value == -1);
case BaseType::UInt64:
+#if SLANG_PTR_IS_64
+ case BaseType::UIntPtr:
+#endif
return true;
case BaseType::Int8:
return value >= std::numeric_limits<int8_t>::min() && value <= std::numeric_limits<int8_t>::max();
case BaseType::Int16:
return value >= std::numeric_limits<int16_t>::min() && value <= std::numeric_limits<int16_t>::max();
case BaseType::Int:
+#if SLANG_PTR_IS_32
+ case BaseType::IntPtr:
+#endif
return value >= std::numeric_limits<int32_t>::min() && value <= std::numeric_limits<int32_t>::max();
case BaseType::Int64:
+#if SLANG_PTR_IS_64
+ case BaseType::IntPtr:
+#endif
return value >= std::numeric_limits<int64_t>::min() && value <= std::numeric_limits<int64_t>::max();
default:
return false;
diff --git a/source/slang/slang-check-expr.cpp b/source/slang/slang-check-expr.cpp
index b988fac60..2987fecee 100644
--- a/source/slang/slang-check-expr.cpp
+++ b/source/slang/slang-check-expr.cpp
@@ -1009,6 +1009,10 @@ namespace Slang
case BaseType::Int16:
case BaseType::UInt8:
case BaseType::Int8:
+ case BaseType::UIntPtr:
+ case BaseType::IntPtr:
+ case BaseType::Int64:
+ case BaseType::UInt64:
resultValue = constArgVals[0];
break;
default:
diff --git a/source/slang/slang-emit-c-like.cpp b/source/slang/slang-emit-c-like.cpp
index 7a7951ba1..734471fd0 100644
--- a/source/slang/slang-emit-c-like.cpp
+++ b/source/slang/slang-emit-c-like.cpp
@@ -215,11 +215,13 @@ void CLikeSourceEmitter::emitSimpleType(IRType* type)
case kIROp_Int16Type: return UnownedStringSlice("int16_t");
case kIROp_IntType: return UnownedStringSlice("int");
case kIROp_Int64Type: return UnownedStringSlice("int64_t");
+ case kIROp_IntPtrType: return UnownedStringSlice("intptr_t");
case kIROp_UInt8Type: return UnownedStringSlice("uint8_t");
case kIROp_UInt16Type: return UnownedStringSlice("uint16_t");
case kIROp_UIntType: return UnownedStringSlice("uint");
case kIROp_UInt64Type: return UnownedStringSlice("uint64_t");
+ case kIROp_UIntPtrType: return UnownedStringSlice("uintptr_t");
case kIROp_HalfType: return UnownedStringSlice("half");
@@ -959,6 +961,33 @@ void CLikeSourceEmitter::emitSimpleValueImpl(IRInst* inst)
m_writer->emit("ULL");
break;
}
+ case BaseType::IntPtr:
+ {
+#if SLANG_PTR_IS_64
+ m_writer->emit("int64_t(");
+ m_writer->emitInt64(int64_t(litInst->value.intVal));
+ m_writer->emit(")");
+#else
+ m_writer->emit("int(");
+ m_writer->emit(int(litInst->value.intVal));
+ m_writer->emit(")");
+#endif
+ break;
+ }
+ case BaseType::UIntPtr:
+ {
+#if SLANG_PTR_IS_64
+ m_writer->emit("uint64_t(");
+ m_writer->emitUInt64(uint64_t(litInst->value.intVal));
+ m_writer->emit(")");
+#else
+ m_writer->emit("uint(");
+ m_writer->emit(UInt(uint32_t(litInst->value.intVal)));
+ m_writer->emit(")");
+#endif
+ break;
+ }
+
}
}
else
diff --git a/source/slang/slang-emit-cpp.cpp b/source/slang/slang-emit-cpp.cpp
index 9c1573bf8..bc145dca1 100644
--- a/source/slang/slang-emit-cpp.cpp
+++ b/source/slang/slang-emit-cpp.cpp
@@ -97,6 +97,8 @@ static IROp _getTypeStyle(IROp op)
case kIROp_UIntType:
case kIROp_Int64Type:
case kIROp_UInt64Type:
+ case kIROp_IntPtrType:
+ case kIROp_UIntPtrType:
{
// All int like
return kIROp_IntType;
@@ -131,6 +133,11 @@ static IROp _getCType(IROp op)
// Promote all these to Int
return kIROp_IntType;
}
+ case kIROp_IntPtrType:
+ case kIROp_UIntPtrType:
+ {
+ return kIROp_IntPtrType;
+ }
case kIROp_Int64Type:
case kIROp_UInt64Type:
{
@@ -165,6 +172,8 @@ static UnownedStringSlice _getCTypeVecPostFix(IROp op)
case kIROp_FloatType: return UnownedStringSlice::fromLiteral("F");
case kIROp_Int64Type: return UnownedStringSlice::fromLiteral("I64");
case kIROp_DoubleType: return UnownedStringSlice::fromLiteral("F64");
+ case kIROp_IntPtrType: return UnownedStringSlice::fromLiteral("");
+ case kIROp_UIntPtrType: return UnownedStringSlice::fromLiteral("");
default: return UnownedStringSlice::fromLiteral("?");
}
}
@@ -207,11 +216,13 @@ static bool _isCppOrCudaTarget(CodeGenTarget target)
case kIROp_Int16Type: return UnownedStringSlice("int16_t");
case kIROp_IntType: return UnownedStringSlice("int32_t");
case kIROp_Int64Type: return UnownedStringSlice("int64_t");
+ case kIROp_IntPtrType: return UnownedStringSlice("intptr_t");
case kIROp_UInt8Type: return UnownedStringSlice("uint8_t");
case kIROp_UInt16Type: return UnownedStringSlice("uint16_t");
case kIROp_UIntType: return UnownedStringSlice("uint32_t");
case kIROp_UInt64Type: return UnownedStringSlice("uint64_t");
+ case kIROp_UIntPtrType: return UnownedStringSlice("uintptr_t");
// Not clear just yet how we should handle half... we want all processing as float probly, but when reading/writing to memory converting
diff --git a/source/slang/slang-emit-cuda.cpp b/source/slang/slang-emit-cuda.cpp
index eda30b956..7c712d2c5 100644
--- a/source/slang/slang-emit-cuda.cpp
+++ b/source/slang/slang-emit-cuda.cpp
@@ -53,11 +53,13 @@ UnownedStringSlice CUDASourceEmitter::getBuiltinTypeName(IROp op)
case kIROp_Int16Type: return UnownedStringSlice("short");
case kIROp_IntType: return UnownedStringSlice("int");
case kIROp_Int64Type: return UnownedStringSlice("longlong");
+ case kIROp_IntPtrType: return UnownedStringSlice("intptr_t");
case kIROp_UInt8Type: return UnownedStringSlice("uchar");
case kIROp_UInt16Type: return UnownedStringSlice("ushort");
case kIROp_UIntType: return UnownedStringSlice("uint");
case kIROp_UInt64Type: return UnownedStringSlice("ulonglong");
+ case kIROp_UIntPtrType: return UnownedStringSlice("uintptr_t");
case kIROp_HalfType:
{
diff --git a/source/slang/slang-emit-glsl.cpp b/source/slang/slang-emit-glsl.cpp
index b0c10fdc2..0fd4ac69c 100644
--- a/source/slang/slang-emit-glsl.cpp
+++ b/source/slang/slang-emit-glsl.cpp
@@ -465,9 +465,11 @@ void GLSLSourceEmitter::_emitGLSLImageFormatModifier(IRInst* var, IRTextureType*
case BaseType::Int8: m_writer->emit("8i"); break;
case BaseType::Int16: m_writer->emit("16i"); break;
case BaseType::Int64: m_writer->emit("64i"); break;
+ case BaseType::IntPtr: m_writer->emit("64i"); break;
case BaseType::UInt8: m_writer->emit("8ui"); break;
case BaseType::UInt16: m_writer->emit("16ui"); break;
case BaseType::UInt64: m_writer->emit("64ui"); break;
+ case BaseType::UIntPtr: m_writer->emit("64ui"); break;
// TODO: Here are formats that are available in GLSL,
// but that are not handled by the above cases.
@@ -662,10 +664,20 @@ void GLSLSourceEmitter::_emitGLSLTypePrefix(IRType* type, bool promoteHalfToFloa
case kIROp_Int8Type: m_writer->emit("i8"); break;
case kIROp_Int16Type: m_writer->emit("i16"); break;
case kIROp_IntType: m_writer->emit("i"); break;
- case kIROp_Int64Type:
+ case kIROp_Int64Type:
+ {
+ _requireBaseType(BaseType::Int64);
+ m_writer->emit("i64");
+ break;
+ }
+ case kIROp_IntPtrType:
{
+#if SLANG_PTR_IS_64
_requireBaseType(BaseType::Int64);
m_writer->emit("i64");
+#else
+ m_writer->emit("i");
+#endif
break;
}
@@ -679,7 +691,16 @@ void GLSLSourceEmitter::_emitGLSLTypePrefix(IRType* type, bool promoteHalfToFloa
m_writer->emit("u64");
break;
}
-
+ case kIROp_UIntPtrType:
+ {
+#if SLANG_PTR_IS_64
+ _requireBaseType(BaseType::Int64);
+ m_writer->emit("u64");
+#else
+ m_writer->emit("u");
+#endif
+ break;
+ }
case kIROp_BoolType: m_writer->emit("b"); break;
case kIROp_HalfType:
@@ -817,12 +838,14 @@ void GLSLSourceEmitter::emitSimpleValueImpl(IRInst* inst)
m_writer->emit("U");
return;
}
+ case BaseType::IntPtr:
case BaseType::Int64:
{
m_writer->emitInt64(int64_t(litInst->value.intVal));
m_writer->emit("L");
return;
}
+ case BaseType::UIntPtr:
case BaseType::UInt64:
{
SLANG_COMPILE_TIME_ASSERT(sizeof(litInst->value.intVal) >= sizeof(uint64_t));
@@ -1909,6 +1932,26 @@ void GLSLSourceEmitter::emitSimpleTypeImpl(IRType* type)
m_writer->emit(getDefaultBuiltinTypeName(type->getOp()));
return;
}
+ case kIROp_IntPtrType:
+ {
+#if SLANG_PTR_IS_64
+ _requireBaseType(BaseType::Int64);
+ m_writer->emit("int64_t");
+#else
+ m_writer->emit("int");
+#endif
+ return;
+ }
+ case kIROp_UIntPtrType:
+ {
+#if SLANG_PTR_IS_64
+ _requireBaseType(BaseType::UInt64);
+ m_writer->emit("uint64_t");
+#else
+ m_writer->emit("uint");
+#endif
+ return;
+ }
case kIROp_VoidType:
case kIROp_BoolType:
case kIROp_Int8Type:
diff --git a/source/slang/slang-emit-hlsl.cpp b/source/slang/slang-emit-hlsl.cpp
index 48fe86fff..20fcc5bed 100644
--- a/source/slang/slang-emit-hlsl.cpp
+++ b/source/slang/slang-emit-hlsl.cpp
@@ -467,10 +467,12 @@ bool HLSLSourceEmitter::tryEmitInstExprImpl(IRInst* inst, const EmitOpInfo& inOu
case BaseType::Int16:
case BaseType::Int:
case BaseType::Int64:
+ case BaseType::IntPtr:
case BaseType::UInt8:
case BaseType::UInt16:
case BaseType::UInt:
case BaseType::UInt64:
+ case BaseType::UIntPtr:
case BaseType::Bool:
// Because the intermediate type will always
// be an integer type, we can convert to
@@ -809,11 +811,26 @@ void HLSLSourceEmitter::emitSimpleTypeImpl(IRType* type)
case kIROp_DoubleType:
case kIROp_Int16Type:
case kIROp_UInt16Type:
- {
case kIROp_HalfType:
+ {
m_writer->emit(getDefaultBuiltinTypeName(type->getOp()));
return;
}
+#if SLANG_PTR_IS_64
+ case kIROp_IntPtrType:
+ m_writer->emit("int64_t");
+ return;
+ case kIROp_UIntPtrType:
+ m_writer->emit("uint64_t");
+ return;
+#else
+ case kIROp_IntPtrType:
+ m_writer->emit("int");
+ return;
+ case kIROp_UIntPtrType:
+ m_writer->emit("uint");
+ return;
+#endif
case kIROp_StructType:
m_writer->emit(getName(type));
return;
@@ -856,7 +873,7 @@ void HLSLSourceEmitter::emitSimpleTypeImpl(IRType* type)
case kIROp_NativeStringType:
case kIROp_StringType:
{
- m_writer->emit("int");
+ m_writer->emit("string");
return;
}
default: break;
diff --git a/source/slang/slang-emit-spirv.cpp b/source/slang/slang-emit-spirv.cpp
index fa0d92512..96ba89c55 100644
--- a/source/slang/slang-emit-spirv.cpp
+++ b/source/slang/slang-emit-spirv.cpp
@@ -708,7 +708,14 @@ struct SPIRVEmitContext
return result;
SpvWord valWord;
memcpy(&valWord, &val, sizeof(SpvWord));
- if (type->getOp() == kIROp_Int64Type || type->getOp() == kIROp_UInt64Type)
+ switch (type->getOp())
+ {
+ case kIROp_Int64Type:
+ case kIROp_UInt64Type:
+#if SLANG_PTR_IS_64
+ case kIROp_PtrType:
+ case kIROp_UIntPtrType:
+#endif
{
SpvWord valHighWord;
memcpy(&valHighWord, (char*)(&val) + 4, sizeof(SpvWord));
@@ -720,8 +727,9 @@ struct SPIRVEmitContext
kResultID,
valWord,
valHighWord);
+ break;
}
- else
+ default:
{
result = emitInst(
getSection(SpvLogicalSectionID::Constants),
@@ -730,6 +738,8 @@ struct SPIRVEmitContext
type,
kResultID,
valWord);
+ break;
+ }
}
m_spvIntConstants[key] = result;
return result;
@@ -1722,6 +1732,8 @@ struct SPIRVEmitContext
{
case BaseType::Int64:
case BaseType::UInt64:
+ case BaseType::IntPtr:
+ case BaseType::UIntPtr:
return emitInst(
getSection(SpvLogicalSectionID::Constants),
inst,
diff --git a/source/slang/slang-glsl-extension-tracker.cpp b/source/slang/slang-glsl-extension-tracker.cpp
index 8c3549fe9..4cd2b4a3c 100644
--- a/source/slang/slang-glsl-extension-tracker.cpp
+++ b/source/slang/slang-glsl-extension-tracker.cpp
@@ -65,7 +65,16 @@ void GLSLExtensionTracker::requireBaseTypeExtension(BaseType baseType)
case BaseType::Int64:
{
requireExtension(UnownedStringSlice::fromLiteral("GL_EXT_shader_explicit_arithmetic_types_int64"));
- m_hasBaseTypeFlags |= _getFlag(BaseType::UInt64) | _getFlag(BaseType::Int64);
+ m_hasBaseTypeFlags |= _getFlag(BaseType::UInt64) | _getFlag(BaseType::Int64) | _getFlag(BaseType::IntPtr) | _getFlag(BaseType::UIntPtr);
+ break;
+ }
+ case BaseType::IntPtr:
+ case BaseType::UIntPtr:
+ {
+#if SLANG_PTR_IS_64
+ requireExtension(UnownedStringSlice::fromLiteral("GL_EXT_shader_explicit_arithmetic_types_int64"));
+ m_hasBaseTypeFlags |= _getFlag(BaseType::UInt64) | _getFlag(BaseType::Int64) | _getFlag(BaseType::IntPtr) | _getFlag(BaseType::UIntPtr);
+#endif
break;
}
}
diff --git a/source/slang/slang-intrinsic-expand.cpp b/source/slang/slang-intrinsic-expand.cpp
index b494e71e1..48186b94a 100644
--- a/source/slang/slang-intrinsic-expand.cpp
+++ b/source/slang/slang-intrinsic-expand.cpp
@@ -71,7 +71,9 @@ static BaseType _getBaseTypeFromScalarType(SlangScalarType type)
case SLANG_SCALAR_TYPE_INT16: return BaseType::Int16;
case SLANG_SCALAR_TYPE_UINT16: return BaseType::UInt16;
case SLANG_SCALAR_TYPE_INT64: return BaseType::Int64;
+ case SLANG_SCALAR_TYPE_INTPTR: return BaseType::IntPtr;
case SLANG_SCALAR_TYPE_UINT64: return BaseType::UInt64;
+ case SLANG_SCALAR_TYPE_UINTPTR: return BaseType::UIntPtr;
case SLANG_SCALAR_TYPE_INT8: return BaseType::Int8;
case SLANG_SCALAR_TYPE_UINT8: return BaseType::UInt8;
case SLANG_SCALAR_TYPE_FLOAT16: return BaseType::Half;
diff --git a/source/slang/slang-ir-any-value-marshalling.cpp b/source/slang/slang-ir-any-value-marshalling.cpp
index f1a1982c2..446d8faf0 100644
--- a/source/slang/slang-ir-any-value-marshalling.cpp
+++ b/source/slang/slang-ir-any-value-marshalling.cpp
@@ -136,6 +136,8 @@ namespace Slang
case kIROp_UInt16Type:
case kIROp_HalfType:
case kIROp_BoolType:
+ case kIROp_IntPtrType:
+ case kIROp_UIntPtrType:
context->marshalBasicType(builder, dataType, concreteTypedVar);
break;
case kIROp_VectorType:
@@ -239,6 +241,9 @@ namespace Slang
case kIROp_IntType:
case kIROp_FloatType:
case kIROp_BoolType:
+#if SLANG_PTR_IS_32
+ case kIROp_IntPtrType:
+#endif
{
ensureOffsetAt4ByteBoundary();
if (fieldOffset < static_cast<uint32_t>(anyValInfo->fieldKeys.getCount()))
@@ -255,6 +260,9 @@ namespace Slang
break;
}
case kIROp_UIntType:
+#if SLANG_PTR_IS_32
+ case kIROp_UIntPtrType:
+#endif
{
ensureOffsetAt4ByteBoundary();
if (fieldOffset < static_cast<uint32_t>(anyValInfo->fieldKeys.getCount()))
@@ -313,6 +321,10 @@ namespace Slang
case kIROp_UInt64Type:
case kIROp_Int64Type:
case kIROp_DoubleType:
+#if SLANG_PTR_IS_64
+ case kIROp_UIntPtrType:
+ case kIROp_IntPtrType:
+#endif
SLANG_UNIMPLEMENTED_X("AnyValue type packing for non 32-bit elements");
break;
default:
diff --git a/source/slang/slang-ir-lower-bit-cast.cpp b/source/slang/slang-ir-lower-bit-cast.cpp
index d895f1e28..e7a4b661b 100644
--- a/source/slang/slang-ir-lower-bit-cast.cpp
+++ b/source/slang/slang-ir-lower-bit-cast.cpp
@@ -168,6 +168,10 @@ struct BitCastLoweringContext
case kIROp_UIntType:
case kIROp_FloatType:
case kIROp_BoolType:
+#if SLANG_PTR_IS_32
+ case kIROp_IntPtrType:
+ case kIROp_UIntPtrType:
+#endif
{
auto object = extractValueAtOffset(builder, targetReq, src, offset, 4);
return builder.emitBitCast(type, object);
@@ -176,6 +180,10 @@ struct BitCastLoweringContext
case kIROp_DoubleType:
case kIROp_Int64Type:
case kIROp_UInt64Type:
+#if SLANG_PTR_IS_64
+ case kIROp_IntPtrType:
+ case kIROp_UIntPtrType:
+#endif
case kIROp_RawPointerType:
{
auto low = extractValueAtOffset(builder, targetReq, src, offset, 4);
diff --git a/source/slang/slang-ir-lower-result-type.cpp b/source/slang/slang-ir-lower-result-type.cpp
index 21e046849..07124d0d6 100644
--- a/source/slang/slang-ir-lower-result-type.cpp
+++ b/source/slang/slang-ir-lower-result-type.cpp
@@ -103,10 +103,12 @@ namespace Slang
case kIROp_Int16Type:
case kIROp_IntType:
case kIROp_Int64Type:
+ case kIROp_IntPtrType:
case kIROp_UInt8Type:
case kIROp_UInt16Type:
case kIROp_UIntType:
case kIROp_UInt64Type:
+ case kIROp_UIntPtrType:
break;
default:
SLANG_ASSERT_FAILURE("error type is not lowered to an integer type.");
diff --git a/source/slang/slang-ir-sccp.cpp b/source/slang/slang-ir-sccp.cpp
index e724d0d88..0bee2565c 100644
--- a/source/slang/slang-ir-sccp.cpp
+++ b/source/slang/slang-ir-sccp.cpp
@@ -303,6 +303,8 @@ struct SCCPContext
case kIROp_UInt16Type:
case kIROp_UIntType:
case kIROp_UInt64Type:
+ case kIROp_IntPtrType:
+ case kIROp_UIntPtrType:
switch (irConstant->getOp())
{
case kIROp_FloatLit:
@@ -368,10 +370,12 @@ struct SCCPContext
case kIROp_Int16Type:
case kIROp_IntType:
case kIROp_Int64Type:
+ case kIROp_IntPtrType:
case kIROp_UInt8Type:
case kIROp_UInt16Type:
case kIROp_UIntType:
case kIROp_UInt64Type:
+ case kIROp_UIntPtrType:
resultVal = getBuilder()->getIntValue(type, (IRIntegerValue)0);
break;
@@ -413,6 +417,8 @@ struct SCCPContext
case kIROp_UInt16Type:
case kIROp_UIntType:
case kIROp_UInt64Type:
+ case kIROp_IntPtrType:
+ case kIROp_UIntPtrType:
case kIROp_BoolType:
resultVal = getBuilder()->getIntValue(type, intFunc(c0->value.intVal, c1->value.intVal));
break;
@@ -447,10 +453,12 @@ struct SCCPContext
case kIROp_Int16Type:
case kIROp_IntType:
case kIROp_Int64Type:
+ case kIROp_IntPtrType:
case kIROp_UInt8Type:
case kIROp_UInt16Type:
case kIROp_UIntType:
case kIROp_UInt64Type:
+ case kIROp_UIntPtrType:
case kIROp_BoolType:
resultVal =
getBuilder()->getIntValue(type, intFunc(c0->value.intVal, c1->value.intVal));
@@ -476,10 +484,12 @@ struct SCCPContext
case kIROp_Int16Type:
case kIROp_IntType:
case kIROp_Int64Type:
+ case kIROp_IntPtrType:
case kIROp_UInt8Type:
case kIROp_UInt16Type:
case kIROp_UIntType:
case kIROp_UInt64Type:
+ case kIROp_UIntPtrType:
case kIROp_BoolType:
resultVal =
getBuilder()->getIntValue(type, intFunc(c0->value.intVal));
@@ -511,10 +521,12 @@ struct SCCPContext
case kIROp_Int16Type:
case kIROp_IntType:
case kIROp_Int64Type:
+ case kIROp_IntPtrType:
case kIROp_UInt8Type:
case kIROp_UInt16Type:
case kIROp_UIntType:
case kIROp_UInt64Type:
+ case kIROp_UIntPtrType:
case kIROp_BoolType:
resultVal =
getBuilder()->getBoolValue(intFunc(c0->value.intVal, c1->value.intVal));
@@ -680,10 +692,12 @@ struct SCCPContext
case kIROp_Int16Type:
case kIROp_IntType:
case kIROp_Int64Type:
+ case kIROp_IntPtrType:
case kIROp_UInt8Type:
case kIROp_UInt16Type:
case kIROp_UIntType:
case kIROp_UInt64Type:
+ case kIROp_UIntPtrType:
resultVal = getBuilder()->getIntValue(type, -c0->value.intVal);
break;
case kIROp_FloatType:
@@ -708,10 +722,18 @@ struct SCCPContext
{
case kIROp_Int64Type:
case kIROp_UInt64Type:
+#if SLANG_PTR_IS_64
+ case kIROp_IntPtrType:
+ case kIROp_UIntPtrType:
+#endif
resultVal = getBuilder()->getIntValue(type, c0->value.intVal);
break;
case kIROp_IntType:
case kIROp_UIntType:
+#if SLANG_PTR_IS_32
+ case kIROp_IntPtrType:
+ case kIROp_UIntPtrType:
+#endif
{
float val = (float)c0->value.floatVal;
uint32_t intVal = (uint32_t)FloatAsInt(val);
diff --git a/source/slang/slang-lower-to-ir.cpp b/source/slang/slang-lower-to-ir.cpp
index 221abe2b8..90f8208b2 100644
--- a/source/slang/slang-lower-to-ir.cpp
+++ b/source/slang/slang-lower-to-ir.cpp
@@ -3185,6 +3185,8 @@ struct ExprLoweringVisitorBase : ExprVisitor<Derived, LoweredValInfo>
case BaseType::UInt16:
case BaseType::UInt:
case BaseType::UInt64:
+ case BaseType::UIntPtr:
+ case BaseType::IntPtr:
return LoweredValInfo::simple(getBuilder()->getIntValue(type, 0));
case BaseType::Half:
diff --git a/source/slang/slang-mangle.cpp b/source/slang/slang-mangle.cpp
index c15402fbb..11c72b182 100644
--- a/source/slang/slang-mangle.cpp
+++ b/source/slang/slang-mangle.cpp
@@ -172,6 +172,8 @@ namespace Slang
case BaseType::Half: emitRaw(context, "h"); break;
case BaseType::Float: emitRaw(context, "f"); break;
case BaseType::Double: emitRaw(context, "d"); break;
+ case BaseType::UIntPtr: emitRaw(context, "up"); break;
+ case BaseType::IntPtr: emitRaw(context, "ip"); break;
break;
default:
diff --git a/source/slang/slang-parser.cpp b/source/slang/slang-parser.cpp
index 77a2319d2..55b6afd6a 100644
--- a/source/slang/slang-parser.cpp
+++ b/source/slang/slang-parser.cpp
@@ -5502,6 +5502,7 @@ namespace Slang
int lCount = 0;
int uCount = 0;
+ int zCount = 0;
int unknownCount = 0;
while(suffixCursor < suffixEnd)
{
@@ -5515,6 +5516,10 @@ namespace Slang
uCount++;
break;
+ case 'z': case 'Z':
+ zCount++;
+ break;
+
default:
unknownCount++;
break;
@@ -5527,25 +5532,33 @@ namespace Slang
suffixBaseType = BaseType::Void;
}
// `u` or `ul` suffix -> `uint`
- else if(uCount == 1 && (lCount <= 1))
+ else if(uCount == 1 && (lCount <= 1) && zCount == 0)
{
suffixBaseType = BaseType::UInt;
}
// `l` suffix on integer -> `int` (== `long`)
- else if(lCount == 1 && !uCount)
+ else if(lCount == 1 && !uCount && zCount == 0)
{
suffixBaseType = BaseType::Int;
}
// `ull` suffix -> `uint64_t`
- else if(uCount == 1 && lCount == 2)
+ else if(uCount == 1 && lCount == 2 && zCount == 0)
{
suffixBaseType = BaseType::UInt64;
}
// `ll` suffix -> `int64_t`
- else if(uCount == 0 && lCount == 2)
+ else if(uCount == 0 && lCount == 2 && zCount == 0)
{
suffixBaseType = BaseType::Int64;
}
+ else if (uCount == 0 && zCount == 1)
+ {
+ suffixBaseType = BaseType::IntPtr;
+ }
+ else if (uCount == 1 && zCount == 1)
+ {
+ suffixBaseType = BaseType::UIntPtr;
+ }
// TODO: do we need suffixes for smaller integer types?
else
{
diff --git a/source/slang/slang-stdlib.cpp b/source/slang/slang-stdlib.cpp
index ac952d2eb..6df9eea46 100644
--- a/source/slang/slang-stdlib.cpp
+++ b/source/slang/slang-stdlib.cpp
@@ -97,6 +97,8 @@ namespace Slang
{ "int16_t", BaseType::Int16, SINT_MASK, kBaseTypeConversionKind_Signed, kBaseTypeConversionRank_Int16},
{ "int", BaseType::Int, SINT_MASK, kBaseTypeConversionKind_Signed, kBaseTypeConversionRank_Int32},
{ "int64_t", BaseType::Int64, SINT_MASK, kBaseTypeConversionKind_Signed, kBaseTypeConversionRank_Int64},
+ { "intptr_t", BaseType::IntPtr, SINT_MASK, kBaseTypeConversionKind_Signed, kBaseTypeConversionRank_IntPtr},
+
{ "half", BaseType::Half, FLOAT_MASK, kBaseTypeConversionKind_Float, kBaseTypeConversionRank_Int16},
{ "float", BaseType::Float, FLOAT_MASK, kBaseTypeConversionKind_Float, kBaseTypeConversionRank_Int32},
@@ -106,6 +108,8 @@ namespace Slang
{ "uint16_t", BaseType::UInt16, UINT_MASK, kBaseTypeConversionKind_Unsigned, kBaseTypeConversionRank_Int16},
{ "uint", BaseType::UInt, UINT_MASK, kBaseTypeConversionKind_Unsigned, kBaseTypeConversionRank_Int32},
{ "uint64_t", BaseType::UInt64, UINT_MASK, kBaseTypeConversionKind_Unsigned, kBaseTypeConversionRank_Int64},
+ { "uintptr_t", BaseType::UIntPtr, UINT_MASK, kBaseTypeConversionKind_Unsigned, kBaseTypeConversionRank_IntPtr},
+
};
// Given two base types, we need to be able to compute the cost of converting between them.
diff --git a/source/slang/slang-type-layout.cpp b/source/slang/slang-type-layout.cpp
index 5a32f6566..c77aadd68 100644
--- a/source/slang/slang-type-layout.cpp
+++ b/source/slang/slang-type-layout.cpp
@@ -82,11 +82,13 @@ struct DefaultLayoutRulesImpl : SimpleLayoutRulesImpl
case BaseType::Int16: return SimpleLayoutInfo( LayoutResourceKind::Uniform, 2,2);
case BaseType::Int: return SimpleLayoutInfo( LayoutResourceKind::Uniform, 4,4);
case BaseType::Int64: return SimpleLayoutInfo( LayoutResourceKind::Uniform, 8,8);
+ case BaseType::IntPtr: return SimpleLayoutInfo(LayoutResourceKind::Uniform, sizeof(intptr_t), sizeof(intptr_t));
case BaseType::UInt8: return SimpleLayoutInfo( LayoutResourceKind::Uniform, 1,1);
case BaseType::UInt16: return SimpleLayoutInfo( LayoutResourceKind::Uniform, 2,2);
case BaseType::UInt: return SimpleLayoutInfo( LayoutResourceKind::Uniform, 4,4);
case BaseType::UInt64: return SimpleLayoutInfo( LayoutResourceKind::Uniform, 8,8);
+ case BaseType::UIntPtr: return SimpleLayoutInfo(LayoutResourceKind::Uniform, sizeof(intptr_t), sizeof(intptr_t));
case BaseType::Half: return SimpleLayoutInfo( LayoutResourceKind::Uniform, 2,2);
case BaseType::Float: return SimpleLayoutInfo( LayoutResourceKind::Uniform, 4,4);
diff --git a/source/slang/slang-type-system-shared.h b/source/slang/slang-type-system-shared.h
index a0b8f45a8..2e824e0a0 100644
--- a/source/slang/slang-type-system-shared.h
+++ b/source/slang/slang-type-system-shared.h
@@ -20,6 +20,8 @@ namespace Slang
X(Float) \
X(Double) \
X(Char) \
+ X(IntPtr) \
+ X(UIntPtr) \
/* end */
enum class BaseType
diff --git a/source/slang/slang.cpp b/source/slang/slang.cpp
index b68dbc14a..f2668b995 100644
--- a/source/slang/slang.cpp
+++ b/source/slang/slang.cpp
@@ -79,6 +79,8 @@ namespace Slang {
{ uint8_t(sizeof(float)), BaseTypeInfo::Flag::FloatingPoint , uint8_t(BaseType::Float) },
{ uint8_t(sizeof(double)), BaseTypeInfo::Flag::FloatingPoint , uint8_t(BaseType::Double) },
{ uint8_t(sizeof(char)), BaseTypeInfo::Flag::Signed | BaseTypeInfo::Flag::Integer , uint8_t(BaseType::Char) },
+ { uint8_t(sizeof(intptr_t)), BaseTypeInfo::Flag::Signed | BaseTypeInfo::Flag::Integer , uint8_t(BaseType::IntPtr) },
+ { uint8_t(sizeof(uintptr_t)), BaseTypeInfo::Flag::Integer , uint8_t(BaseType::UIntPtr) },
};
/* static */bool BaseTypeInfo::check()
@@ -111,6 +113,9 @@ namespace Slang {
case BaseType::Half: return UnownedStringSlice::fromLiteral("half");
case BaseType::Float: return UnownedStringSlice::fromLiteral("float");
case BaseType::Double: return UnownedStringSlice::fromLiteral("double");
+ case BaseType::Char: return UnownedStringSlice::fromLiteral("char");
+ case BaseType::IntPtr: return UnownedStringSlice::fromLiteral("intptr_t");
+ case BaseType::UIntPtr: return UnownedStringSlice::fromLiteral("uintptr_t");
default:
{
SLANG_ASSERT(!"Unknown basic type");