diff options
| author | Yong He <yonghe@outlook.com> | 2022-09-15 14:22:59 -0700 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2022-09-15 14:22:59 -0700 |
| commit | a6032446c6bf7f64d1e201bf438a4c7605a3dbb4 (patch) | |
| tree | a95267c52155e13699ff9aab38ab68353d76939e /source/slang/core.meta.slang | |
| parent | 05f9aaf6a4ef246dcf89b00000a8e59e90c47662 (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/slang/core.meta.slang')
| -rw-r--r-- | source/slang/core.meta.slang | 54 |
1 files changed, 40 insertions, 14 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); } |
