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 printExp(x: any) { 364514f5e3Sopenharmony_ci try { 374514f5e3Sopenharmony_ci print(Math.exp(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.exp, caller function name:func_main_0@builtinMathExp 594514f5e3Sopenharmony_ciprint(Math.exp()); //: NaN 604514f5e3Sopenharmony_ci 614514f5e3Sopenharmony_ci// Check with single param 624514f5e3Sopenharmony_ci//aot: [trace] aot inline builtin: Math.exp, caller function name:func_main_0@builtinMathExp 634514f5e3Sopenharmony_ciprint(Math.exp(0)); //: 1 644514f5e3Sopenharmony_ci//aot: [trace] aot inline builtin: Math.exp, caller function name:func_main_0@builtinMathExp 654514f5e3Sopenharmony_ciprint(Math.exp(-0)); //: 1 664514f5e3Sopenharmony_ci//aot: [trace] aot inline builtin: Math.exp, caller function name:func_main_0@builtinMathExp 674514f5e3Sopenharmony_ciprint(Math.exp(1)); //: 2.718281828459045 684514f5e3Sopenharmony_ci//aot: [trace] aot inline builtin: Math.exp, caller function name:func_main_0@builtinMathExp 694514f5e3Sopenharmony_ciprint(Math.exp(-100)); //: 3.720075976020836e-44 704514f5e3Sopenharmony_ci//aot: [trace] aot inline builtin: Math.exp, caller function name:func_main_0@builtinMathExp 714514f5e3Sopenharmony_ciprint(Math.exp(100)); //: 2.6881171418161356e+43 724514f5e3Sopenharmony_ci//aot: [trace] aot inline builtin: Math.exp, caller function name:func_main_0@builtinMathExp 734514f5e3Sopenharmony_ciprint(Math.exp(10e-10)); //: 1.000000001 744514f5e3Sopenharmony_ci 754514f5e3Sopenharmony_ci// Check with special float params 764514f5e3Sopenharmony_ci//aot: [trace] aot inline builtin: Math.exp, caller function name:func_main_0@builtinMathExp 774514f5e3Sopenharmony_ci//aot: [trace] aot inline function name: #*#printZero@builtinMathExp caller function name: func_main_0@builtinMathExp 784514f5e3Sopenharmony_ci//aot: [trace] aot inline builtin: Object.is, caller function name:#*#printZero@builtinMathExp 794514f5e3Sopenharmony_ciprintZero(Math.exp(-Infinity)); //: 0 804514f5e3Sopenharmony_ci//aot: [trace] aot inline builtin: Math.exp, caller function name:func_main_0@builtinMathExp 814514f5e3Sopenharmony_ciprint(Math.exp(Infinity)); //: Infinity 824514f5e3Sopenharmony_ci//aot: [trace] aot inline builtin: Math.exp, caller function name:func_main_0@builtinMathExp 834514f5e3Sopenharmony_ciprint(Math.exp(NaN)); //: NaN 844514f5e3Sopenharmony_ci 854514f5e3Sopenharmony_ci// Check with 2 params 864514f5e3Sopenharmony_ci//aot: [trace] aot inline builtin: Math.exp, caller function name:func_main_0@builtinMathExp 874514f5e3Sopenharmony_ciprint(Math.exp(1, 1)); //: 2.718281828459045 884514f5e3Sopenharmony_ci 894514f5e3Sopenharmony_ci// Check with 3 params 904514f5e3Sopenharmony_ci//aot: [trace] aot inline builtin: Math.exp, caller function name:func_main_0@builtinMathExp 914514f5e3Sopenharmony_ciprint(Math.exp(1, 1, 1)); //: 2.718281828459045 924514f5e3Sopenharmony_ci 934514f5e3Sopenharmony_ci// Check with 4 params 944514f5e3Sopenharmony_ci//aot: [trace] aot inline builtin: Math.exp, caller function name:func_main_0@builtinMathExp 954514f5e3Sopenharmony_ciprint(Math.exp(1, 1, 1, 1)); //: 2.718281828459045 964514f5e3Sopenharmony_ci 974514f5e3Sopenharmony_ci// Check with 5 params 984514f5e3Sopenharmony_ci//aot: [trace] aot inline builtin: Math.exp, caller function name:func_main_0@builtinMathExp 994514f5e3Sopenharmony_ciprint(Math.exp(1, 1, 1, 1, 1)); //: 2.718281828459045 1004514f5e3Sopenharmony_ci 1014514f5e3Sopenharmony_citry { 1024514f5e3Sopenharmony_ci //aot: [trace] aot inline builtin: Math.exp, caller function name:func_main_0@builtinMathExp 1034514f5e3Sopenharmony_ci print(Math.exp(1)); //: 2.718281828459045 1044514f5e3Sopenharmony_ci} catch(e) {} 1054514f5e3Sopenharmony_ci 1064514f5e3Sopenharmony_ci// Replace standart builtin 1074514f5e3Sopenharmony_cilet trueExp = Math.exp 1084514f5e3Sopenharmony_ciMath.exp = replace 1094514f5e3Sopenharmony_ciprint(Math.exp(111)); //: 111 1104514f5e3Sopenharmony_ciMath.exp = trueExp 1114514f5e3Sopenharmony_ci 1124514f5e3Sopenharmony_ci//aot: [trace] aot inline builtin: Math.exp, caller function name:#*#printExp@builtinMathExp 1134514f5e3Sopenharmony_ciprintExp(1); //: 2.718281828459045 1144514f5e3Sopenharmony_ci 1154514f5e3Sopenharmony_ci// Call standart builtin with non-number param 1164514f5e3Sopenharmony_ci//aot: [trace] aot inline builtin: Math.exp, caller function name:#*#printExp@builtinMathExp 1174514f5e3Sopenharmony_ci//aot: [trace] Check Type: NotNumber1 1184514f5e3Sopenharmony_ciprintExp("1"); //: 2.718281828459045 1194514f5e3Sopenharmony_ci//aot: [trace] aot inline builtin: Math.exp, caller function name:#*#printExp@builtinMathExp 1204514f5e3Sopenharmony_ci//aot: [trace] Check Type: NotNumber1 1214514f5e3Sopenharmony_ciprintExp("NaN"); //: NaN 1224514f5e3Sopenharmony_ci//aot: [trace] aot inline builtin: Math.exp, caller function name:#*#printExp@builtinMathExp 1234514f5e3Sopenharmony_ci//aot: [trace] Check Type: NotNumber1 1244514f5e3Sopenharmony_ciprintExp("abc"); //: NaN 1254514f5e3Sopenharmony_ci 1264514f5e3Sopenharmony_ciif (ArkTools.isAOTCompiled(printExp)) { 1274514f5e3Sopenharmony_ci // Replace standard builtin after call to standard builtin was profiled 1284514f5e3Sopenharmony_ci Math.exp = replace 1294514f5e3Sopenharmony_ci} 1304514f5e3Sopenharmony_ci 1314514f5e3Sopenharmony_ciprintExp(1); //pgo: 2.718281828459045 1324514f5e3Sopenharmony_ci//aot: [trace] Check Type: NotCallTarget1 1334514f5e3Sopenharmony_ci//aot: 1 1344514f5e3Sopenharmony_ci 1354514f5e3Sopenharmony_ciprintExp(2); //pgo: 7.38905609893065 1364514f5e3Sopenharmony_ci//aot: [trace] Check Type: NotCallTarget1 1374514f5e3Sopenharmony_ci//aot: 2 1384514f5e3Sopenharmony_ci 1394514f5e3Sopenharmony_ciprintExp("1"); //pgo: 2.718281828459045 1404514f5e3Sopenharmony_ci//aot: [trace] Check Type: NotCallTarget1 1414514f5e3Sopenharmony_ci//aot: 1 1424514f5e3Sopenharmony_ci 1434514f5e3Sopenharmony_ciprintExp("2"); //pgo: 7.38905609893065 1444514f5e3Sopenharmony_ci//aot: [trace] Check Type: NotCallTarget1 1454514f5e3Sopenharmony_ci//aot: 2 1464514f5e3Sopenharmony_ci 1474514f5e3Sopenharmony_ciMath.exp = trueExp 1484514f5e3Sopenharmony_ci 1494514f5e3Sopenharmony_ci// Check IR correctness inside try-block 1504514f5e3Sopenharmony_citry { 1514514f5e3Sopenharmony_ci //aot: [trace] aot inline builtin: Math.exp, caller function name:#*#printExp@builtinMathExp 1524514f5e3Sopenharmony_ci printExp(1); //: 2.718281828459045 1534514f5e3Sopenharmony_ci //aot: [trace] aot inline builtin: Math.exp, caller function name:#*#printExp@builtinMathExp 1544514f5e3Sopenharmony_ci printExp(1, 2); //: 2.718281828459045 1554514f5e3Sopenharmony_ci //aot: [trace] aot inline builtin: Math.exp, caller function name:#*#printExp@builtinMathExp 1564514f5e3Sopenharmony_ci printExp(1, 2); //: 2.718281828459045 1574514f5e3Sopenharmony_ci //aot: [trace] aot inline builtin: Math.exp, caller function name:#*#printExp@builtinMathExp 1584514f5e3Sopenharmony_ci //aot: [trace] Check Type: NotNumber1 1594514f5e3Sopenharmony_ci printExp("abc", 3e3); //: NaN 1604514f5e3Sopenharmony_ci} catch (e) { 1614514f5e3Sopenharmony_ci} 1624514f5e3Sopenharmony_ci 1634514f5e3Sopenharmony_ci//aot: [trace] aot inline builtin: Math.exp, caller function name:#*#printExp@builtinMathExp 1644514f5e3Sopenharmony_ci//aot: [trace] Check Type: NotNumber1 1654514f5e3Sopenharmony_ci//: obj.valueOf 1664514f5e3Sopenharmony_ciprintExp(obj); //: 1.026187963170189e-10 1674514f5e3Sopenharmony_ci//aot: [trace] aot inline builtin: Math.exp, caller function name:#*#printExp@builtinMathExp 1684514f5e3Sopenharmony_ci//aot: [trace] Check Type: NotNumber1 1694514f5e3Sopenharmony_ciprintExp(doubleObj); //: 14.879731724872837 1704514f5e3Sopenharmony_ci//aot: [trace] aot inline builtin: Math.exp, caller function name:#*#printExp@builtinMathExp 1714514f5e3Sopenharmony_ci//aot: [trace] Check Type: NotNumber1 1724514f5e3Sopenharmony_ciprintExp(nanObj); //: NaN 173