summaryrefslogtreecommitdiff
path: root/source/slang/core.meta.slang
diff options
context:
space:
mode:
authorYong He <yonghe@outlook.com>2022-08-03 12:08:37 -0700
committerGitHub <noreply@github.com>2022-08-03 12:08:37 -0700
commite81a5fe56f3177fc3c7040e2320ae083e3746eb7 (patch)
tree884c15287bc10050e7883897dd266b27e62bff66 /source/slang/core.meta.slang
parent260fc5fbe58f2cf976d64993054c638769bc280f (diff)
Basic pointer usages. (#2342)
Diffstat (limited to 'source/slang/core.meta.slang')
-rw-r--r--source/slang/core.meta.slang115
1 files changed, 115 insertions, 0 deletions
diff --git a/source/slang/core.meta.slang b/source/slang/core.meta.slang
index fb39b43f2..1991eb583 100644
--- a/source/slang/core.meta.slang
+++ b/source/slang/core.meta.slang
@@ -358,9 +358,99 @@ __magic_type(PtrType)
__intrinsic_type($(kIROp_PtrType))
struct Ptr
{
+ __intrinsic_op($(kIROp_Load))
+ static T __load(Ptr<T> ptr);
+
+ __intrinsic_op($(kIROp_Store))
+ static void __store(Ptr<T> ptr, T val);
+
+ __intrinsic_op($(kIROp_getElementPtr))
+ static Ptr<T> __getElementPtr(Ptr<T> ptr, int index);
+
+ __intrinsic_op($(kIROp_Neq))
+ __generic<U:__BuiltinArithmeticType>
+ static bool __neq(Ptr<T> ptr, U val);
+
+ __intrinsic_op($(kIROp_Eql))
+ __generic<U:__BuiltinArithmeticType>
+ static bool __eql(Ptr<T> ptr, U val);
+
+ __generic<U>
+ __intrinsic_op($(kIROp_BitCast))
+ __init(Ptr<U> ptr);
+
+ __intrinsic_op($(kIROp_BitCast))
+ __init(uint64_t val);
+
+ __intrinsic_op($(kIROp_BitCast))
+ __init(int64_t val);
+
+ __subscript(int index) -> T
+ {
+ [__unsafeForceInlineEarly]
+ get
+ {
+ return __load(__getElementPtr(this, index));
+ }
+
+ [__unsafeForceInlineEarly]
+ set(T newValue)
+ {
+ __store(__getElementPtr(this, index), newValue);
+ }
+
+ __intrinsic_op($(kIROp_getElementPtr))
+ ref;
+ }
};
__generic<T>
+__intrinsic_op($(kIROp_Less))
+bool operator<(Ptr<T> p1, Ptr<T> p2);
+
+__generic<T>
+__intrinsic_op($(kIROp_Leq))
+bool operator<=(Ptr<T> p1, Ptr<T> p2);
+
+__generic<T>
+__intrinsic_op($(kIROp_Greater))
+bool operator>(Ptr<T> p1, Ptr<T> p2);
+
+__generic<T>
+__intrinsic_op($(kIROp_Geq))
+bool operator>=(Ptr<T> p1, Ptr<T> p2);
+
+__generic<T>
+__intrinsic_op($(kIROp_Neq))
+bool operator!=(Ptr<T> p1, Ptr<T> p2);
+
+__generic<T>
+__intrinsic_op($(kIROp_Eql))
+bool operator==(Ptr<T> p1, Ptr<T> p2);
+
+extension bool
+{
+ __generic<T>
+ __implicit_conversion($(kConversionCost_PtrToBool))
+ __intrinsic_op($(kIROp_CastPtrToBool))
+ __init(Ptr<T> ptr);
+}
+
+extension uint64_t
+{
+ __generic<T>
+ __intrinsic_op($(kIROp_Construct))
+ __init(Ptr<T> ptr);
+}
+
+extension int64_t
+{
+ __generic<T>
+ __intrinsic_op($(kIROp_Construct))
+ __init(Ptr<T> ptr);
+}
+
+__generic<T>
__magic_type(OutType)
__intrinsic_type($(kIROp_OutType))
struct Out
@@ -1620,6 +1710,25 @@ for (auto op : intrinsicUnaryOps)
}}}}
+__generic<T>
+__intrinsic_op(0)
+__prefix Ref<T> operator*(Ptr<T> value);
+
+__generic<T>
+__intrinsic_op(0)
+__prefix Ptr<T> operator&(__ref T value);
+
+__generic<T>
+__intrinsic_op($(kIROp_getElementPtr))
+Ptr<T> operator+(Ptr<T> value, int64_t offset);
+
+__generic<T>
+[__unsafeForceInlineEarly]
+Ptr<T> operator-(Ptr<T> value, int64_t offset)
+{
+ return Ptr<T>.__getElementPtr(value, -offset);
+}
+
__generic<T : __BuiltinArithmeticType>
[__unsafeForceInlineEarly]
__prefix T operator+(T value)
@@ -1679,6 +1788,12 @@ __generic<T : __BuiltinArithmeticType, let R : int, let C : int>
matrix<T,R,C> operator$(op.name)(in out matrix<T,R,C> value)
{$(fixity.bodyPrefix) value = value $(op.binOp) T(1); return $(fixity.returnVal); }
+$(fixity.qual)
+__generic<T>
+[__unsafeForceInlineEarly]
+Ptr<T> operator$(op.name)(in out Ptr<T> value)
+{$(fixity.bodyPrefix) value = value $(op.binOp) 1; return $(fixity.returnVal); }
+
${{{{
}