14514f5e3Sopenharmony_ci/* 24514f5e3Sopenharmony_ci * Copyright (c) 2024 Huawei Device Co., Ltd. 34514f5e3Sopenharmony_ci * Licensed under the Apache License, Version 2.0 (the "License"); 44514f5e3Sopenharmony_ci * you may not use this file except in compliance with the License. 54514f5e3Sopenharmony_ci * You may obtain a copy of the License at 64514f5e3Sopenharmony_ci * 74514f5e3Sopenharmony_ci * http://www.apache.org/licenses/LICENSE-2.0 84514f5e3Sopenharmony_ci * 94514f5e3Sopenharmony_ci * Unless required by applicable law or agreed to in writing, software 104514f5e3Sopenharmony_ci * distributed under the License is distributed on an "AS IS" BASIS, 114514f5e3Sopenharmony_ci * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 124514f5e3Sopenharmony_ci * See the License for the specific language governing permissions and 134514f5e3Sopenharmony_ci * limitations under the License. 144514f5e3Sopenharmony_ci */ 154514f5e3Sopenharmony_ci 164514f5e3Sopenharmony_cideclare interface ArkTools { 174514f5e3Sopenharmony_ci isAOTCompiled(args: any): boolean; 184514f5e3Sopenharmony_ci} 194514f5e3Sopenharmony_cideclare function print(arg:any):string; 204514f5e3Sopenharmony_ci 214514f5e3Sopenharmony_cifunction printZero(x: any) { 224514f5e3Sopenharmony_ci if (Object.is(x, -0)) { 234514f5e3Sopenharmony_ci print("-0"); 244514f5e3Sopenharmony_ci } else { 254514f5e3Sopenharmony_ci print(x); 264514f5e3Sopenharmony_ci } 274514f5e3Sopenharmony_ci} 284514f5e3Sopenharmony_ci 294514f5e3Sopenharmony_cifunction replace(a : number) 304514f5e3Sopenharmony_ci{ 314514f5e3Sopenharmony_ci return a; 324514f5e3Sopenharmony_ci} 334514f5e3Sopenharmony_ci 344514f5e3Sopenharmony_ci// Use try to prevent inlining to main 354514f5e3Sopenharmony_cifunction printExpm1(x: any) { 364514f5e3Sopenharmony_ci try { 374514f5e3Sopenharmony_ci print(Math.expm1(x)); 384514f5e3Sopenharmony_ci } finally { 394514f5e3Sopenharmony_ci } 404514f5e3Sopenharmony_ci} 414514f5e3Sopenharmony_ci 424514f5e3Sopenharmony_cilet doubleObj = { 434514f5e3Sopenharmony_ci valueOf: () => { return 2.7; } 444514f5e3Sopenharmony_ci} 454514f5e3Sopenharmony_ci 464514f5e3Sopenharmony_cilet nanObj = { 474514f5e3Sopenharmony_ci valueOf: () => { return "something"; } 484514f5e3Sopenharmony_ci} 494514f5e3Sopenharmony_ci 504514f5e3Sopenharmony_cilet obj = { 514514f5e3Sopenharmony_ci valueOf: () => { 524514f5e3Sopenharmony_ci print("obj.valueOf") 534514f5e3Sopenharmony_ci return -23; 544514f5e3Sopenharmony_ci } 554514f5e3Sopenharmony_ci}; 564514f5e3Sopenharmony_ci 574514f5e3Sopenharmony_ci// Check without params 584514f5e3Sopenharmony_ci//aot: [trace] aot inline builtin: Math.expm1, caller function name:func_main_0@builtinMathExpm1 594514f5e3Sopenharmony_ciprint(Math.expm1()); //: NaN 604514f5e3Sopenharmony_ci 614514f5e3Sopenharmony_ci// Check with single param 624514f5e3Sopenharmony_ci//aot: [trace] aot inline builtin: Math.expm1, caller function name:func_main_0@builtinMathExpm1 634514f5e3Sopenharmony_ci//aot: [trace] aot inline function name: #*#printZero@builtinMathExpm1 caller function name: func_main_0@builtinMathExpm1 644514f5e3Sopenharmony_ci//aot: [trace] aot inline builtin: Object.is, caller function name:#*#printZero@builtinMathExpm1 654514f5e3Sopenharmony_ciprintZero(Math.expm1(0)); //: 0 664514f5e3Sopenharmony_ci//aot: [trace] aot inline builtin: Math.expm1, caller function name:func_main_0@builtinMathExpm1 674514f5e3Sopenharmony_ci//aot: [trace] aot inline function name: #*#printZero@builtinMathExpm1 caller function name: func_main_0@builtinMathExpm1 684514f5e3Sopenharmony_ci//aot: [trace] aot inline builtin: Object.is, caller function name:#*#printZero@builtinMathExpm1 694514f5e3Sopenharmony_ciprintZero("1/x: " + 1 / Math.expm1(-0)); //: 1/x: -Infinity 704514f5e3Sopenharmony_ci//aot: [trace] aot inline builtin: Math.expm1, caller function name:func_main_0@builtinMathExpm1 714514f5e3Sopenharmony_ciprint(Math.expm1(1)); //: 1.718281828459045 724514f5e3Sopenharmony_ci//aot: [trace] aot inline builtin: Math.expm1, caller function name:func_main_0@builtinMathExpm1 734514f5e3Sopenharmony_ciprint(Math.expm1(-100)); //: -1 744514f5e3Sopenharmony_ci//aot: [trace] aot inline builtin: Math.expm1, caller function name:func_main_0@builtinMathExpm1 754514f5e3Sopenharmony_ciprint(Math.expm1(100)); //: 2.6881171418161356e+43 764514f5e3Sopenharmony_ci//aot: [trace] aot inline builtin: Math.expm1, caller function name:func_main_0@builtinMathExpm1 774514f5e3Sopenharmony_ciprint(Math.expm1(10e-10)); //: 1.0000000005000001e-9 784514f5e3Sopenharmony_ci 794514f5e3Sopenharmony_ci// Check with special float params 804514f5e3Sopenharmony_ci//aot: [trace] aot inline builtin: Math.expm1, caller function name:func_main_0@builtinMathExpm1 814514f5e3Sopenharmony_ciprint(Math.expm1(-Infinity)); //: -1 824514f5e3Sopenharmony_ci//aot: [trace] aot inline builtin: Math.expm1, caller function name:func_main_0@builtinMathExpm1 834514f5e3Sopenharmony_ciprint(Math.expm1(Infinity)); //: Infinity 844514f5e3Sopenharmony_ci//aot: [trace] aot inline builtin: Math.expm1, caller function name:func_main_0@builtinMathExpm1 854514f5e3Sopenharmony_ciprint(Math.expm1(NaN)); //: NaN 864514f5e3Sopenharmony_ci 874514f5e3Sopenharmony_ci// Check with 2 params 884514f5e3Sopenharmony_ci//aot: [trace] aot inline builtin: Math.expm1, caller function name:func_main_0@builtinMathExpm1 894514f5e3Sopenharmony_ciprint(Math.expm1(1, 1)); //: 1.718281828459045 904514f5e3Sopenharmony_ci 914514f5e3Sopenharmony_ci// Check with 3 params 924514f5e3Sopenharmony_ci//aot: [trace] aot inline builtin: Math.expm1, caller function name:func_main_0@builtinMathExpm1 934514f5e3Sopenharmony_ciprint(Math.expm1(1, 1, 1)); //: 1.718281828459045 944514f5e3Sopenharmony_ci 954514f5e3Sopenharmony_ci// Check with 4 params 964514f5e3Sopenharmony_ci//aot: [trace] aot inline builtin: Math.expm1, caller function name:func_main_0@builtinMathExpm1 974514f5e3Sopenharmony_ciprint(Math.expm1(1, 1, 1, 1)); //: 1.718281828459045 984514f5e3Sopenharmony_ci 994514f5e3Sopenharmony_ci// Check with 5 params 1004514f5e3Sopenharmony_ci//aot: [trace] aot inline builtin: Math.expm1, caller function name:func_main_0@builtinMathExpm1 1014514f5e3Sopenharmony_ciprint(Math.expm1(1, 1, 1, 1, 1)); //: 1.718281828459045 1024514f5e3Sopenharmony_ci 1034514f5e3Sopenharmony_citry { 1044514f5e3Sopenharmony_ci //aot: [trace] aot inline builtin: Math.expm1, caller function name:func_main_0@builtinMathExpm1 1054514f5e3Sopenharmony_ci print(Math.expm1(1)); //: 1.718281828459045 1064514f5e3Sopenharmony_ci} catch(e) {} 1074514f5e3Sopenharmony_ci 1084514f5e3Sopenharmony_ci// Replace standart builtin 1094514f5e3Sopenharmony_cilet trueExpm1 = Math.expm1 1104514f5e3Sopenharmony_ciMath.expm1 = replace 1114514f5e3Sopenharmony_ciprint(Math.expm1(111)); //: 111 1124514f5e3Sopenharmony_ciMath.expm1 = trueExpm1 1134514f5e3Sopenharmony_ci 1144514f5e3Sopenharmony_ci//aot: [trace] aot inline builtin: Math.expm1, caller function name:#*#printExpm1@builtinMathExpm1 1154514f5e3Sopenharmony_ciprintExpm1(1); //: 1.718281828459045 1164514f5e3Sopenharmony_ci 1174514f5e3Sopenharmony_ci// Call standart builtin with non-number param 1184514f5e3Sopenharmony_ci//aot: [trace] aot inline builtin: Math.expm1, caller function name:#*#printExpm1@builtinMathExpm1 1194514f5e3Sopenharmony_ci//aot: [trace] Check Type: NotNumber1 1204514f5e3Sopenharmony_ciprintExpm1("1"); //: 1.718281828459045 1214514f5e3Sopenharmony_ci//aot: [trace] aot inline builtin: Math.expm1, caller function name:#*#printExpm1@builtinMathExpm1 1224514f5e3Sopenharmony_ci//aot: [trace] Check Type: NotNumber1 1234514f5e3Sopenharmony_ciprintExpm1("NaN"); //: NaN 1244514f5e3Sopenharmony_ci//aot: [trace] aot inline builtin: Math.expm1, caller function name:#*#printExpm1@builtinMathExpm1 1254514f5e3Sopenharmony_ci//aot: [trace] Check Type: NotNumber1 1264514f5e3Sopenharmony_ciprintExpm1("abc"); //: NaN 1274514f5e3Sopenharmony_ci 1284514f5e3Sopenharmony_ciif (ArkTools.isAOTCompiled(printExpm1)) { 1294514f5e3Sopenharmony_ci // Replace standard builtin after call to standard builtin was profiled 1304514f5e3Sopenharmony_ci Math.expm1 = replace 1314514f5e3Sopenharmony_ci} 1324514f5e3Sopenharmony_ci 1334514f5e3Sopenharmony_ciprintExpm1(1); //pgo: 1.718281828459045 1344514f5e3Sopenharmony_ci//aot: [trace] Check Type: NotCallTarget1 1354514f5e3Sopenharmony_ci//aot: 1 1364514f5e3Sopenharmony_ci 1374514f5e3Sopenharmony_ciprintExpm1(2); //pgo: 6.38905609893065 1384514f5e3Sopenharmony_ci//aot: [trace] Check Type: NotCallTarget1 1394514f5e3Sopenharmony_ci//aot: 2 1404514f5e3Sopenharmony_ci 1414514f5e3Sopenharmony_ciprintExpm1("1"); //pgo: 1.718281828459045 1424514f5e3Sopenharmony_ci//aot: [trace] Check Type: NotCallTarget1 1434514f5e3Sopenharmony_ci//aot: 1 1444514f5e3Sopenharmony_ci 1454514f5e3Sopenharmony_ciprintExpm1("2"); //pgo: 6.38905609893065 1464514f5e3Sopenharmony_ci//aot: [trace] Check Type: NotCallTarget1 1474514f5e3Sopenharmony_ci//aot: 2 1484514f5e3Sopenharmony_ci 1494514f5e3Sopenharmony_ciMath.expm1 = trueExpm1 1504514f5e3Sopenharmony_ci 1514514f5e3Sopenharmony_ci// Check IR correctness inside try-block 1524514f5e3Sopenharmony_citry { 1534514f5e3Sopenharmony_ci //aot: [trace] aot inline builtin: Math.expm1, caller function name:#*#printExpm1@builtinMathExpm1 1544514f5e3Sopenharmony_ci printExpm1(1); //: 1.718281828459045 1554514f5e3Sopenharmony_ci //aot: [trace] aot inline builtin: Math.expm1, caller function name:#*#printExpm1@builtinMathExpm1 1564514f5e3Sopenharmony_ci printExpm1(1, 2); //: 1.718281828459045 1574514f5e3Sopenharmony_ci //aot: [trace] aot inline builtin: Math.expm1, caller function name:#*#printExpm1@builtinMathExpm1 1584514f5e3Sopenharmony_ci printExpm1(1, 2); //: 1.718281828459045 1594514f5e3Sopenharmony_ci //aot: [trace] aot inline builtin: Math.expm1, caller function name:#*#printExpm1@builtinMathExpm1 1604514f5e3Sopenharmony_ci //aot: [trace] Check Type: NotNumber1 1614514f5e3Sopenharmony_ci printExpm1("abc", 3e3); //: NaN 1624514f5e3Sopenharmony_ci} catch (e) { 1634514f5e3Sopenharmony_ci} 1644514f5e3Sopenharmony_ci 1654514f5e3Sopenharmony_ci//aot: [trace] aot inline builtin: Math.expm1, caller function name:#*#printExpm1@builtinMathExpm1 1664514f5e3Sopenharmony_ci//aot: [trace] Check Type: NotNumber1 1674514f5e3Sopenharmony_ci//: obj.valueOf 1684514f5e3Sopenharmony_ciprintExpm1(obj); //: -0.9999999998973812 1694514f5e3Sopenharmony_ci//aot: [trace] aot inline builtin: Math.expm1, caller function name:#*#printExpm1@builtinMathExpm1 1704514f5e3Sopenharmony_ci//aot: [trace] Check Type: NotNumber1 1714514f5e3Sopenharmony_ciprintExpm1(doubleObj); //: 13.879731724872837 1724514f5e3Sopenharmony_ci//aot: [trace] aot inline builtin: Math.expm1, caller function name:#*#printExpm1@builtinMathExpm1 1734514f5e3Sopenharmony_ci//aot: [trace] Check Type: NotNumber1 1744514f5e3Sopenharmony_ciprintExpm1(nanObj); //: NaN 175