11cb0ef41Sopenharmony_ci// Copyright 2019 the V8 project authors. All rights reserved. 21cb0ef41Sopenharmony_ci// Use of this source code is governed by a BSD-style license that can be 31cb0ef41Sopenharmony_ci// found in the LICENSE file. 41cb0ef41Sopenharmony_ci 51cb0ef41Sopenharmony_ciintrinsic %FromConstexpr<To: type, From: type>(b: From): To; 61cb0ef41Sopenharmony_cimacro FromConstexpr<To: type, From: type>(o: From): To; 71cb0ef41Sopenharmony_ci// Conversions for IntegerLiteral 81cb0ef41Sopenharmony_ciFromConstexpr<intptr, constexpr IntegerLiteral>(i: constexpr IntegerLiteral): 91cb0ef41Sopenharmony_ci intptr { 101cb0ef41Sopenharmony_ci return ConstexprIntegerLiteralToIntptr(i); 111cb0ef41Sopenharmony_ci} 121cb0ef41Sopenharmony_ciFromConstexpr<uintptr, constexpr IntegerLiteral>(i: constexpr IntegerLiteral): 131cb0ef41Sopenharmony_ci uintptr { 141cb0ef41Sopenharmony_ci return ConstexprIntegerLiteralToUintptr(i); 151cb0ef41Sopenharmony_ci} 161cb0ef41Sopenharmony_ciFromConstexpr<int32, constexpr IntegerLiteral>(i: constexpr IntegerLiteral): 171cb0ef41Sopenharmony_ci int32 { 181cb0ef41Sopenharmony_ci return ConstexprIntegerLiteralToInt32(i); 191cb0ef41Sopenharmony_ci} 201cb0ef41Sopenharmony_ciFromConstexpr<uint32, constexpr IntegerLiteral>(i: constexpr IntegerLiteral): 211cb0ef41Sopenharmony_ci uint32 { 221cb0ef41Sopenharmony_ci return ConstexprIntegerLiteralToUint32(i); 231cb0ef41Sopenharmony_ci} 241cb0ef41Sopenharmony_ciFromConstexpr<int31, constexpr IntegerLiteral>(i: constexpr IntegerLiteral): 251cb0ef41Sopenharmony_ci int31 { 261cb0ef41Sopenharmony_ci return ConstexprIntegerLiteralToInt31(i); 271cb0ef41Sopenharmony_ci} 281cb0ef41Sopenharmony_ciFromConstexpr<int8, constexpr IntegerLiteral>(i: constexpr IntegerLiteral): 291cb0ef41Sopenharmony_ci int8 { 301cb0ef41Sopenharmony_ci return ConstexprIntegerLiteralToInt8(i); 311cb0ef41Sopenharmony_ci} 321cb0ef41Sopenharmony_ciFromConstexpr<uint8, constexpr IntegerLiteral>(i: constexpr IntegerLiteral): 331cb0ef41Sopenharmony_ci uint8 { 341cb0ef41Sopenharmony_ci return ConstexprIntegerLiteralToUint8(i); 351cb0ef41Sopenharmony_ci} 361cb0ef41Sopenharmony_ciFromConstexpr<uint64, constexpr IntegerLiteral>(i: constexpr IntegerLiteral): 371cb0ef41Sopenharmony_ci uint64 { 381cb0ef41Sopenharmony_ci return ConstexprIntegerLiteralToUint64(i); 391cb0ef41Sopenharmony_ci} 401cb0ef41Sopenharmony_ciFromConstexpr<constexpr int31, constexpr IntegerLiteral>( 411cb0ef41Sopenharmony_ci i: constexpr IntegerLiteral): constexpr int31 { 421cb0ef41Sopenharmony_ci return ConstexprIntegerLiteralToInt31(i); 431cb0ef41Sopenharmony_ci} 441cb0ef41Sopenharmony_ciFromConstexpr<constexpr int32, constexpr IntegerLiteral>( 451cb0ef41Sopenharmony_ci i: constexpr IntegerLiteral): constexpr int32 { 461cb0ef41Sopenharmony_ci return ConstexprIntegerLiteralToInt32(i); 471cb0ef41Sopenharmony_ci} 481cb0ef41Sopenharmony_ciFromConstexpr<Number, constexpr IntegerLiteral>(i: constexpr IntegerLiteral): 491cb0ef41Sopenharmony_ci Number { 501cb0ef41Sopenharmony_ci return NumberConstant(ConstexprIntegerLiteralToFloat64(i)); 511cb0ef41Sopenharmony_ci} 521cb0ef41Sopenharmony_ciFromConstexpr<Smi, constexpr IntegerLiteral>(i: constexpr IntegerLiteral): Smi { 531cb0ef41Sopenharmony_ci return Convert<Smi>(ConstexprIntegerLiteralToInt31(i)); 541cb0ef41Sopenharmony_ci} 551cb0ef41Sopenharmony_ciFromConstexpr<char8, constexpr IntegerLiteral>(i: constexpr IntegerLiteral): 561cb0ef41Sopenharmony_ci char8 { 571cb0ef41Sopenharmony_ci return %RawDownCast<char8>(FromConstexpr<uint8>(i)); 581cb0ef41Sopenharmony_ci} 591cb0ef41Sopenharmony_ci 601cb0ef41Sopenharmony_ciFromConstexpr<int31, constexpr int31>(i: constexpr int31): int31 { 611cb0ef41Sopenharmony_ci return %FromConstexpr<int31>(i); 621cb0ef41Sopenharmony_ci} 631cb0ef41Sopenharmony_ciFromConstexpr<int32, constexpr int31>(i: constexpr int31): int32 { 641cb0ef41Sopenharmony_ci return %FromConstexpr<int32>(i); 651cb0ef41Sopenharmony_ci} 661cb0ef41Sopenharmony_ciFromConstexpr<int32, constexpr int32>(i: constexpr int32): int32 { 671cb0ef41Sopenharmony_ci return %FromConstexpr<int32>(i); 681cb0ef41Sopenharmony_ci} 691cb0ef41Sopenharmony_ciFromConstexpr<intptr, constexpr int31>(i: constexpr int31): intptr { 701cb0ef41Sopenharmony_ci return %FromConstexpr<intptr>(i); 711cb0ef41Sopenharmony_ci} 721cb0ef41Sopenharmony_ciFromConstexpr<intptr, constexpr int32>(i: constexpr int32): intptr { 731cb0ef41Sopenharmony_ci return %FromConstexpr<intptr>(i); 741cb0ef41Sopenharmony_ci} 751cb0ef41Sopenharmony_ciFromConstexpr<intptr, constexpr intptr>(i: constexpr intptr): intptr { 761cb0ef41Sopenharmony_ci return %FromConstexpr<intptr>(i); 771cb0ef41Sopenharmony_ci} 781cb0ef41Sopenharmony_ciFromConstexpr<uintptr, constexpr uintptr>(i: constexpr uintptr): uintptr { 791cb0ef41Sopenharmony_ci return %FromConstexpr<uintptr>(i); 801cb0ef41Sopenharmony_ci} 811cb0ef41Sopenharmony_ciFromConstexpr<Smi, constexpr int31>(i: constexpr int31): Smi { 821cb0ef41Sopenharmony_ci return %FromConstexpr<Smi>(i); 831cb0ef41Sopenharmony_ci} 841cb0ef41Sopenharmony_ciFromConstexpr<PositiveSmi, constexpr int31>(i: constexpr int31): PositiveSmi { 851cb0ef41Sopenharmony_ci dcheck(i >= 0); 861cb0ef41Sopenharmony_ci return %FromConstexpr<PositiveSmi>(i); 871cb0ef41Sopenharmony_ci} 881cb0ef41Sopenharmony_ciFromConstexpr<String, constexpr string>(s: constexpr string): String { 891cb0ef41Sopenharmony_ci return %FromConstexpr<String>(s); 901cb0ef41Sopenharmony_ci} 911cb0ef41Sopenharmony_ciFromConstexpr<Number, constexpr uint32>(i: constexpr uint32): Number { 921cb0ef41Sopenharmony_ci return %FromConstexpr<Number>(i); 931cb0ef41Sopenharmony_ci} 941cb0ef41Sopenharmony_ciFromConstexpr<Number, constexpr int32>(i: constexpr int32): Number { 951cb0ef41Sopenharmony_ci return %FromConstexpr<Number>(i); 961cb0ef41Sopenharmony_ci} 971cb0ef41Sopenharmony_ciFromConstexpr<Number, constexpr float64>(f: constexpr float64): Number { 981cb0ef41Sopenharmony_ci return %FromConstexpr<Number>(f); 991cb0ef41Sopenharmony_ci} 1001cb0ef41Sopenharmony_ciFromConstexpr<Number, constexpr int31>(i: constexpr int31): Number { 1011cb0ef41Sopenharmony_ci return %FromConstexpr<Number>(i); 1021cb0ef41Sopenharmony_ci} 1031cb0ef41Sopenharmony_ciFromConstexpr<uint8, constexpr int31>(i: constexpr int31): uint8 { 1041cb0ef41Sopenharmony_ci const i: uint32 = i; 1051cb0ef41Sopenharmony_ci static_assert(i <= 255); 1061cb0ef41Sopenharmony_ci return %RawDownCast<uint8>(i); 1071cb0ef41Sopenharmony_ci} 1081cb0ef41Sopenharmony_ciFromConstexpr<int8, constexpr int31>(i: constexpr int31): int8 { 1091cb0ef41Sopenharmony_ci const i: int32 = i; 1101cb0ef41Sopenharmony_ci static_assert(-128 <= i && i <= 127); 1111cb0ef41Sopenharmony_ci return %RawDownCast<int8>(i); 1121cb0ef41Sopenharmony_ci} 1131cb0ef41Sopenharmony_ciFromConstexpr<char8, constexpr int31>(i: constexpr int31): char8 { 1141cb0ef41Sopenharmony_ci return %RawDownCast<char8>(FromConstexpr<uint8>(i)); 1151cb0ef41Sopenharmony_ci} 1161cb0ef41Sopenharmony_ciFromConstexpr<Number, constexpr Smi>(s: constexpr Smi): Number { 1171cb0ef41Sopenharmony_ci return SmiConstant(s); 1181cb0ef41Sopenharmony_ci} 1191cb0ef41Sopenharmony_ciFromConstexpr<Smi, constexpr Smi>(s: constexpr Smi): Smi { 1201cb0ef41Sopenharmony_ci return SmiConstant(s); 1211cb0ef41Sopenharmony_ci} 1221cb0ef41Sopenharmony_ciFromConstexpr<uint32, constexpr int31>(i: constexpr int31): uint32 { 1231cb0ef41Sopenharmony_ci return Unsigned(Int32Constant(i)); 1241cb0ef41Sopenharmony_ci} 1251cb0ef41Sopenharmony_ciFromConstexpr<uint8, constexpr uint8>(i: constexpr uint8): uint8 { 1261cb0ef41Sopenharmony_ci const i: uint32 = i; 1271cb0ef41Sopenharmony_ci return %RawDownCast<uint8>(i); 1281cb0ef41Sopenharmony_ci} 1291cb0ef41Sopenharmony_ciFromConstexpr<uint32, constexpr uint32>(i: constexpr uint32): uint32 { 1301cb0ef41Sopenharmony_ci return Unsigned(%FromConstexpr<int32>(i)); 1311cb0ef41Sopenharmony_ci} 1321cb0ef41Sopenharmony_ciFromConstexpr<uint64, constexpr uint64>(i: constexpr uint64): uint64 { 1331cb0ef41Sopenharmony_ci return Uint64Constant(i); 1341cb0ef41Sopenharmony_ci} 1351cb0ef41Sopenharmony_ciFromConstexpr<uint64, constexpr int31>(i: constexpr int31): uint64 { 1361cb0ef41Sopenharmony_ci return Convert<uint64>(Unsigned(Int32Constant(i))); 1371cb0ef41Sopenharmony_ci} 1381cb0ef41Sopenharmony_ciFromConstexpr<uintptr, constexpr int31>(i: constexpr int31): uintptr { 1391cb0ef41Sopenharmony_ci return ChangeUint32ToWord(i); 1401cb0ef41Sopenharmony_ci} 1411cb0ef41Sopenharmony_ciFromConstexpr<float64, constexpr int31>(i: constexpr int31): float64 { 1421cb0ef41Sopenharmony_ci return Float64Constant(i); 1431cb0ef41Sopenharmony_ci} 1441cb0ef41Sopenharmony_ciFromConstexpr<float64, constexpr int32>(i: constexpr int32): float64 { 1451cb0ef41Sopenharmony_ci return Float64Constant(i); 1461cb0ef41Sopenharmony_ci} 1471cb0ef41Sopenharmony_ciFromConstexpr<float64, constexpr float64>(i: constexpr float64): float64 { 1481cb0ef41Sopenharmony_ci return Float64Constant(i); 1491cb0ef41Sopenharmony_ci} 1501cb0ef41Sopenharmony_ciFromConstexpr<bool, constexpr bool>(b: constexpr bool): bool { 1511cb0ef41Sopenharmony_ci return BoolConstant(b); 1521cb0ef41Sopenharmony_ci} 1531cb0ef41Sopenharmony_ciFromConstexpr<Object, constexpr string>(s: constexpr string): Object { 1541cb0ef41Sopenharmony_ci return StringConstant(s); 1551cb0ef41Sopenharmony_ci} 1561cb0ef41Sopenharmony_ciFromConstexpr<JSAny, constexpr string>(s: constexpr string): JSAny { 1571cb0ef41Sopenharmony_ci return StringConstant(s); 1581cb0ef41Sopenharmony_ci} 1591cb0ef41Sopenharmony_ciFromConstexpr<ContextSlot, constexpr ContextSlot>(c: constexpr ContextSlot): 1601cb0ef41Sopenharmony_ci ContextSlot { 1611cb0ef41Sopenharmony_ci return IntPtrConstant(c); 1621cb0ef41Sopenharmony_ci} 1631cb0ef41Sopenharmony_ciFromConstexpr<LanguageModeSmi, constexpr LanguageMode>( 1641cb0ef41Sopenharmony_ci c: constexpr LanguageMode): LanguageModeSmi { 1651cb0ef41Sopenharmony_ci return %RawDownCast<LanguageModeSmi>(SmiConstant(c)); 1661cb0ef41Sopenharmony_ci} 1671cb0ef41Sopenharmony_ciFromConstexpr<PromiseState, constexpr PromiseState>(c: constexpr PromiseState): 1681cb0ef41Sopenharmony_ci PromiseState { 1691cb0ef41Sopenharmony_ci return %RawDownCast<PromiseState>(Int32Constant(c)); 1701cb0ef41Sopenharmony_ci} 1711cb0ef41Sopenharmony_ciFromConstexpr<InstanceType, constexpr InstanceType>(c: constexpr InstanceType): 1721cb0ef41Sopenharmony_ci InstanceType { 1731cb0ef41Sopenharmony_ci return %RawDownCast<InstanceType>(Uint16Constant(c)); 1741cb0ef41Sopenharmony_ci} 1751cb0ef41Sopenharmony_ci 1761cb0ef41Sopenharmony_ciFromConstexpr<IterationKind, constexpr IterationKind>( 1771cb0ef41Sopenharmony_ci c: constexpr IterationKind): IterationKind { 1781cb0ef41Sopenharmony_ci return %RawDownCast<IterationKind>(Unsigned(%FromConstexpr<int32>(c))); 1791cb0ef41Sopenharmony_ci} 1801cb0ef41Sopenharmony_ci 1811cb0ef41Sopenharmony_ciFromConstexpr<string::TrimMode, string::constexpr TrimMode>( 1821cb0ef41Sopenharmony_ci c: string::constexpr TrimMode): string::TrimMode { 1831cb0ef41Sopenharmony_ci return %RawDownCast<string::TrimMode>(Unsigned(%FromConstexpr<int32>(c))); 1841cb0ef41Sopenharmony_ci} 1851cb0ef41Sopenharmony_ci 1861cb0ef41Sopenharmony_cimacro Convert<To: type, From: type>(i: From): To { 1871cb0ef41Sopenharmony_ci return i; 1881cb0ef41Sopenharmony_ci} 1891cb0ef41Sopenharmony_ci 1901cb0ef41Sopenharmony_cimacro Convert<To: type, From: type>(i: From): To labels Overflow { 1911cb0ef41Sopenharmony_ci return i; 1921cb0ef41Sopenharmony_ci} 1931cb0ef41Sopenharmony_ci 1941cb0ef41Sopenharmony_ciConvert<Boolean, bool>(b: bool): Boolean { 1951cb0ef41Sopenharmony_ci return b ? True : False; 1961cb0ef41Sopenharmony_ci} 1971cb0ef41Sopenharmony_ciConvert<int32, bool>(b: bool): int32 { 1981cb0ef41Sopenharmony_ci return ChangeBoolToInt32(b); 1991cb0ef41Sopenharmony_ci} 2001cb0ef41Sopenharmony_ciConvert<Number, int32>(i: int32): Number { 2011cb0ef41Sopenharmony_ci return ChangeInt32ToTagged(i); 2021cb0ef41Sopenharmony_ci} 2031cb0ef41Sopenharmony_ciConvert<intptr, int32>(i: int32): intptr { 2041cb0ef41Sopenharmony_ci return ChangeInt32ToIntPtr(i); 2051cb0ef41Sopenharmony_ci} 2061cb0ef41Sopenharmony_ciConvert<intptr, int31>(i: int31): intptr { 2071cb0ef41Sopenharmony_ci return ChangeInt32ToIntPtr(i); 2081cb0ef41Sopenharmony_ci} 2091cb0ef41Sopenharmony_ciConvert<intptr, uint32>(i: uint32): intptr { 2101cb0ef41Sopenharmony_ci return Signed(ChangeUint32ToWord(i)); 2111cb0ef41Sopenharmony_ci} 2121cb0ef41Sopenharmony_ciConvert<Smi, int32>(i: int32): Smi { 2131cb0ef41Sopenharmony_ci return SmiFromInt32(i); 2141cb0ef41Sopenharmony_ci} 2151cb0ef41Sopenharmony_ciConvert<Number, uint32>(ui: uint32): Number { 2161cb0ef41Sopenharmony_ci return ChangeUint32ToTagged(ui); 2171cb0ef41Sopenharmony_ci} 2181cb0ef41Sopenharmony_ciConvert<Smi, uint32>(ui: uint32): Smi { 2191cb0ef41Sopenharmony_ci return SmiFromUint32(ui); 2201cb0ef41Sopenharmony_ci} 2211cb0ef41Sopenharmony_ciConvert<uintptr, uint32>(ui: uint32): uintptr { 2221cb0ef41Sopenharmony_ci return ChangeUint32ToWord(ui); 2231cb0ef41Sopenharmony_ci} 2241cb0ef41Sopenharmony_ciConvert<uint64, uint32>(ui: uint32): uint64 { 2251cb0ef41Sopenharmony_ci return ChangeUint32ToUint64(ui); 2261cb0ef41Sopenharmony_ci} 2271cb0ef41Sopenharmony_ciConvert<intptr, uint16>(ui: uint16): intptr { 2281cb0ef41Sopenharmony_ci return Signed(ChangeUint32ToWord(ui)); 2291cb0ef41Sopenharmony_ci} 2301cb0ef41Sopenharmony_ciConvert<intptr, uint8>(ui: uint8): intptr { 2311cb0ef41Sopenharmony_ci return Signed(ChangeUint32ToWord(ui)); 2321cb0ef41Sopenharmony_ci} 2331cb0ef41Sopenharmony_ciConvert<uint8, intptr>(i: intptr): uint8 { 2341cb0ef41Sopenharmony_ci return %RawDownCast<uint8>(Unsigned(TruncateIntPtrToInt32(i)) & 0xFF); 2351cb0ef41Sopenharmony_ci} 2361cb0ef41Sopenharmony_ciConvert<int8, intptr>(i: intptr): int8 { 2371cb0ef41Sopenharmony_ci return %RawDownCast<int8>(TruncateIntPtrToInt32(i) << 24 >> 24); 2381cb0ef41Sopenharmony_ci} 2391cb0ef41Sopenharmony_ciConvert<uint16, uint32>(i: uint32): uint16 { 2401cb0ef41Sopenharmony_ci return %RawDownCast<uint16>(i & 0xFFFF); 2411cb0ef41Sopenharmony_ci} 2421cb0ef41Sopenharmony_ciConvert<int32, uint8>(i: uint8): int32 { 2431cb0ef41Sopenharmony_ci return Signed(Convert<uint32>(i)); 2441cb0ef41Sopenharmony_ci} 2451cb0ef41Sopenharmony_ciConvert<int32, uint16>(i: uint16): int32 { 2461cb0ef41Sopenharmony_ci return Signed(Convert<uint32>(i)); 2471cb0ef41Sopenharmony_ci} 2481cb0ef41Sopenharmony_ciConvert<int32, char16|char8>(i: char16|char8): int32 { 2491cb0ef41Sopenharmony_ci return Signed(Convert<uint32>(i)); 2501cb0ef41Sopenharmony_ci} 2511cb0ef41Sopenharmony_ciConvert<intptr, char16>(i: char16): intptr { 2521cb0ef41Sopenharmony_ci return Convert<intptr, uint32>(i); 2531cb0ef41Sopenharmony_ci} 2541cb0ef41Sopenharmony_ciConvert<intptr, char8>(i: char8): intptr { 2551cb0ef41Sopenharmony_ci return Convert<intptr, uint32>(i); 2561cb0ef41Sopenharmony_ci} 2571cb0ef41Sopenharmony_ciConvert<int32, uint31>(i: uint31): int32 { 2581cb0ef41Sopenharmony_ci return Signed(Convert<uint32>(i)); 2591cb0ef41Sopenharmony_ci} 2601cb0ef41Sopenharmony_ciConvert<int32, intptr>(i: intptr): int32 { 2611cb0ef41Sopenharmony_ci return TruncateIntPtrToInt32(i); 2621cb0ef41Sopenharmony_ci} 2631cb0ef41Sopenharmony_ciConvert<int32, int64>(i: int64): int32 { 2641cb0ef41Sopenharmony_ci return TruncateInt64ToInt32(i); 2651cb0ef41Sopenharmony_ci} 2661cb0ef41Sopenharmony_ciConvert<int32, Number>(n: Number): int32 { 2671cb0ef41Sopenharmony_ci typeswitch (n) { 2681cb0ef41Sopenharmony_ci case (s: Smi): { 2691cb0ef41Sopenharmony_ci return Convert<int32>(s); 2701cb0ef41Sopenharmony_ci } 2711cb0ef41Sopenharmony_ci case (h: HeapNumber): { 2721cb0ef41Sopenharmony_ci return TruncateHeapNumberValueToWord32(h); 2731cb0ef41Sopenharmony_ci } 2741cb0ef41Sopenharmony_ci } 2751cb0ef41Sopenharmony_ci} 2761cb0ef41Sopenharmony_ci 2771cb0ef41Sopenharmony_ciConvert<Smi, intptr>(i: intptr): Smi { 2781cb0ef41Sopenharmony_ci return SmiTag(i); 2791cb0ef41Sopenharmony_ci} 2801cb0ef41Sopenharmony_ciConvert<uint32, uintptr>(ui: uintptr): uint32 { 2811cb0ef41Sopenharmony_ci return Unsigned(TruncateIntPtrToInt32(Signed(ui))); 2821cb0ef41Sopenharmony_ci} 2831cb0ef41Sopenharmony_ciConvert<intptr, Smi>(s: Smi): intptr { 2841cb0ef41Sopenharmony_ci return SmiUntag(s); 2851cb0ef41Sopenharmony_ci} 2861cb0ef41Sopenharmony_ciConvert<uintptr, PositiveSmi>(ps: PositiveSmi): uintptr { 2871cb0ef41Sopenharmony_ci return Unsigned(SmiUntag(ps)); 2881cb0ef41Sopenharmony_ci} 2891cb0ef41Sopenharmony_ciConvert<intptr, TaggedIndex>(ti: TaggedIndex): intptr { 2901cb0ef41Sopenharmony_ci return TaggedIndexToIntPtr(ti); 2911cb0ef41Sopenharmony_ci} 2921cb0ef41Sopenharmony_ciConvert<TaggedIndex, intptr>(i: intptr): TaggedIndex { 2931cb0ef41Sopenharmony_ci return IntPtrToTaggedIndex(i); 2941cb0ef41Sopenharmony_ci} 2951cb0ef41Sopenharmony_ciConvert<intptr, uintptr>(ui: uintptr): intptr { 2961cb0ef41Sopenharmony_ci const i = Signed(ui); 2971cb0ef41Sopenharmony_ci dcheck(i >= 0); 2981cb0ef41Sopenharmony_ci return i; 2991cb0ef41Sopenharmony_ci} 3001cb0ef41Sopenharmony_ciConvert<PositiveSmi, intptr>(i: intptr): PositiveSmi { 3011cb0ef41Sopenharmony_ci dcheck(IsValidPositiveSmi(i)); 3021cb0ef41Sopenharmony_ci return %RawDownCast<PositiveSmi>(SmiTag(i)); 3031cb0ef41Sopenharmony_ci} 3041cb0ef41Sopenharmony_ciConvert<PositiveSmi, uintptr>(ui: uintptr): PositiveSmi labels IfOverflow { 3051cb0ef41Sopenharmony_ci if (ui > kSmiMaxValue) deferred { 3061cb0ef41Sopenharmony_ci goto IfOverflow; 3071cb0ef41Sopenharmony_ci } 3081cb0ef41Sopenharmony_ci return %RawDownCast<PositiveSmi>(SmiTag(Signed(ui))); 3091cb0ef41Sopenharmony_ci} 3101cb0ef41Sopenharmony_ciConvert<PositiveSmi, intptr>(i: intptr): PositiveSmi labels IfOverflow { 3111cb0ef41Sopenharmony_ci if (IsValidPositiveSmi(i)) { 3121cb0ef41Sopenharmony_ci return %RawDownCast<PositiveSmi>(SmiTag(i)); 3131cb0ef41Sopenharmony_ci } else 3141cb0ef41Sopenharmony_ci deferred { 3151cb0ef41Sopenharmony_ci goto IfOverflow; 3161cb0ef41Sopenharmony_ci } 3171cb0ef41Sopenharmony_ci} 3181cb0ef41Sopenharmony_ciConvert<PositiveSmi, uint32>(ui: uint32): PositiveSmi labels IfOverflow { 3191cb0ef41Sopenharmony_ci return Convert<PositiveSmi>(Convert<uintptr>(ui)) otherwise IfOverflow; 3201cb0ef41Sopenharmony_ci} 3211cb0ef41Sopenharmony_ciConvert<int32, Smi>(s: Smi): int32 { 3221cb0ef41Sopenharmony_ci return SmiToInt32(s); 3231cb0ef41Sopenharmony_ci} 3241cb0ef41Sopenharmony_ciConvert<float64, HeapNumber>(h: HeapNumber): float64 { 3251cb0ef41Sopenharmony_ci return LoadHeapNumberValue(h); 3261cb0ef41Sopenharmony_ci} 3271cb0ef41Sopenharmony_ciConvert<float64, Number>(n: Number): float64 { 3281cb0ef41Sopenharmony_ci return ChangeNumberToFloat64(n); 3291cb0ef41Sopenharmony_ci} 3301cb0ef41Sopenharmony_ciConvert<uintptr, Number>(n: Number): uintptr { 3311cb0ef41Sopenharmony_ci return ChangeUintPtrNumberToUintPtr(n); 3321cb0ef41Sopenharmony_ci} 3331cb0ef41Sopenharmony_ciConvert<float64, int32>(f: int32): float64 { 3341cb0ef41Sopenharmony_ci return ChangeInt32ToFloat64(f); 3351cb0ef41Sopenharmony_ci} 3361cb0ef41Sopenharmony_ciConvert<float64, float32>(f: float32): float64 { 3371cb0ef41Sopenharmony_ci return ChangeFloat32ToFloat64(f); 3381cb0ef41Sopenharmony_ci} 3391cb0ef41Sopenharmony_ciConvert<float64_or_hole, float64>(f: float64): float64_or_hole { 3401cb0ef41Sopenharmony_ci return float64_or_hole{is_hole: false, value: f}; 3411cb0ef41Sopenharmony_ci} 3421cb0ef41Sopenharmony_ciConvert<float64_or_hole, Number>(n: Number): float64_or_hole { 3431cb0ef41Sopenharmony_ci return Convert<float64_or_hole>(Convert<float64>(n)); 3441cb0ef41Sopenharmony_ci} 3451cb0ef41Sopenharmony_ciConvert<float32, float64>(f: float64): float32 { 3461cb0ef41Sopenharmony_ci return TruncateFloat64ToFloat32(f); 3471cb0ef41Sopenharmony_ci} 3481cb0ef41Sopenharmony_ciConvert<float32, Number>(n: Number): float32 { 3491cb0ef41Sopenharmony_ci return Convert<float32>(ChangeNumberToFloat64(n)); 3501cb0ef41Sopenharmony_ci} 3511cb0ef41Sopenharmony_ciConvert<Number, float64>(d: float64): Number { 3521cb0ef41Sopenharmony_ci return ChangeFloat64ToTagged(d); 3531cb0ef41Sopenharmony_ci} 3541cb0ef41Sopenharmony_ciConvert<float64, uintptr>(ui: uintptr): float64 { 3551cb0ef41Sopenharmony_ci return ChangeUintPtrToFloat64(ui); 3561cb0ef41Sopenharmony_ci} 3571cb0ef41Sopenharmony_ciConvert<Number, uintptr>(ui: uintptr): Number { 3581cb0ef41Sopenharmony_ci return ChangeUintPtrToTagged(ui); 3591cb0ef41Sopenharmony_ci} 3601cb0ef41Sopenharmony_ciConvert<Number, intptr>(i: intptr): Number { 3611cb0ef41Sopenharmony_ci return ChangeUintPtrToTagged(Unsigned(i)); 3621cb0ef41Sopenharmony_ci} 3631cb0ef41Sopenharmony_ciConvert<uintptr, float64>(d: float64): uintptr { 3641cb0ef41Sopenharmony_ci return ChangeFloat64ToUintPtr(d); 3651cb0ef41Sopenharmony_ci} 3661cb0ef41Sopenharmony_ciConvert<uintptr, intptr>(i: intptr): uintptr { 3671cb0ef41Sopenharmony_ci return Unsigned(i); 3681cb0ef41Sopenharmony_ci} 3691cb0ef41Sopenharmony_ciConvert<uintptr, RawPtr>(r: RawPtr): uintptr { 3701cb0ef41Sopenharmony_ci return Unsigned(r); 3711cb0ef41Sopenharmony_ci} 3721cb0ef41Sopenharmony_ciConvert<intptr, RawPtr>(r: RawPtr): intptr { 3731cb0ef41Sopenharmony_ci return Signed(r); 3741cb0ef41Sopenharmony_ci} 3751cb0ef41Sopenharmony_ciConvert<intptr, Number>(n: Number): intptr { 3761cb0ef41Sopenharmony_ci return ChangeFloat64ToIntPtr(ChangeNumberToFloat64(n)); 3771cb0ef41Sopenharmony_ci} 3781cb0ef41Sopenharmony_ciConvert<bint, int32>(v: int32): bint { 3791cb0ef41Sopenharmony_ci return IntPtrToBInt(Convert<intptr>(v)); 3801cb0ef41Sopenharmony_ci} 3811cb0ef41Sopenharmony_ciFromConstexpr<float64, constexpr IntegerLiteral>(v: constexpr IntegerLiteral): 3821cb0ef41Sopenharmony_ci float64 { 3831cb0ef41Sopenharmony_ci return ConstexprIntegerLiteralToFloat64(v); 3841cb0ef41Sopenharmony_ci} 3851cb0ef41Sopenharmony_ciextern macro IntPtrToBInt(intptr): bint; 3861cb0ef41Sopenharmony_ciConvert<bint, intptr>(v: intptr): bint { 3871cb0ef41Sopenharmony_ci return IntPtrToBInt(v); 3881cb0ef41Sopenharmony_ci} 3891cb0ef41Sopenharmony_ciextern macro BIntToIntPtr(bint): intptr; 3901cb0ef41Sopenharmony_ciConvert<intptr, bint>(v: bint): intptr { 3911cb0ef41Sopenharmony_ci return BIntToIntPtr(v); 3921cb0ef41Sopenharmony_ci} 3931cb0ef41Sopenharmony_ciextern macro SmiToBInt(Smi): bint; 3941cb0ef41Sopenharmony_ciConvert<bint, Smi>(v: Smi): bint { 3951cb0ef41Sopenharmony_ci return SmiToBInt(v); 3961cb0ef41Sopenharmony_ci} 3971cb0ef41Sopenharmony_ciextern macro BIntToSmi(bint): Smi; 3981cb0ef41Sopenharmony_ciConvert<Smi, bint>(v: bint): Smi { 3991cb0ef41Sopenharmony_ci return BIntToSmi(v); 4001cb0ef41Sopenharmony_ci} 4011cb0ef41Sopenharmony_ciConvert<PromiseState, int32>(s: int32): PromiseState { 4021cb0ef41Sopenharmony_ci return %RawDownCast<PromiseState>(s); 4031cb0ef41Sopenharmony_ci} 4041cb0ef41Sopenharmony_ciConvert<ScopeFlags, Smi>(s: Smi): ScopeFlags { 4051cb0ef41Sopenharmony_ci return %RawDownCast<ScopeFlags>(Unsigned(SmiToInt32(s))); 4061cb0ef41Sopenharmony_ci} 4071cb0ef41Sopenharmony_ciConvert<I8X16, Simd128>(s: Simd128): I8X16 { 4081cb0ef41Sopenharmony_ci return %RawDownCast<I8X16>(s); 4091cb0ef41Sopenharmony_ci} 410