diff options
| author | Yong He <yonghe@outlook.com> | 2024-08-19 15:03:56 -0700 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2024-08-19 15:03:56 -0700 |
| commit | 453683bf44f2112719802eaac2b332d49eebd640 (patch) | |
| tree | d399db4c9cba90c11980186d3df1ffcc4d423b5a /source/slang/core.meta.slang | |
| parent | ecf85df6eee3da76ef54b14e4ab083f22da89e46 (diff) | |
Tuple swizzling, concat, comparison and `countof`. (#4856)
* Tuple swizzling and element access.
* Update proposal status.
* Cleanup.
* Fix merrge error.
* Address review.
Diffstat (limited to 'source/slang/core.meta.slang')
| -rw-r--r-- | source/slang/core.meta.slang | 79 |
1 files changed, 77 insertions, 2 deletions
diff --git a/source/slang/core.meta.slang b/source/slang/core.meta.slang index 6c51ccef0..84e1b8168 100644 --- a/source/slang/core.meta.slang +++ b/source/slang/core.meta.slang @@ -874,10 +874,85 @@ __generic<each T> __magic_type(TupleType) struct Tuple { - __intrinsic_op($(0)) + __intrinsic_op($(kIROp_MakeTuple)) __init(expand each T); } +__intrinsic_op($(kIROp_MakeTuple)) +Tuple<T> makeTuple<each T>(T v); + +Tuple<T, U> concat<each T, each U>(Tuple<T> t, Tuple<U> u) +{ + return makeTuple(expand each t, expand each u); +} + + +[__unsafeForceInlineEarly] +bool __assign(inout bool v, bool newVal) +{ + v = newVal; + return newVal; +} + +[__unsafeForceInlineEarly] +void __tupleLessKernel<T : IComparable>(inout bool result, inout bool exit, T a, T b) +{ + if (!exit) + { + if (a.lessThan(b)) + { + result = true; + exit = true; + } + else if (!a.equals(b)) + { + exit = true; + } + } +} + +[__unsafeForceInlineEarly] +void __tupleGreaterKernel<T : IComparable>(inout bool result, inout bool exit, T a, T b) +{ + if (!exit) + { + if (!a.lessThanOrEquals(b)) + { + result = true; + exit = true; + } + else if (!a.equals(b)) + { + exit = true; + } + } +} + +__generic<each T : IComparable> +extension Tuple<T> : IComparable +{ + bool lessThan(Tuple<T> other) + { + bool result = false; + bool exit = false; + expand __tupleLessKernel(result, exit, each this, each other); + return result; + } + bool lessThanOrEquals(Tuple<T> other) + { + bool result = false; + bool exit = false; + expand __tupleGreaterKernel(result, exit, each this, each other); + return !result; + } + bool equals(Tuple<T> other) + { + bool result = true; + expand result && __assign(result, result && (each this).equals(each other)); + return result; + } +} + __generic<T> __magic_type(NativeRefType) __intrinsic_type($(kIROp_NativePtrType)) @@ -2181,7 +2256,7 @@ __generic<T : IComparable> [OverloadRank(-10)] bool operator >=(T v0, T v1) { - return v1.lessThan(v1); + return v1.lessThanOrEquals(v0); } __generic<T : IComparable> [__unsafeForceInlineEarly] |
