@@ -1180,6 +1180,18 @@ export namespace NativeMath {
1180
1180
}
1181
1181
1182
1182
export function pow ( x : f64 , y : f64 ) : f64 { // see: musl/src/math/pow.c and SUN COPYRIGHT NOTICE above
1183
+ // TODO: remove this fast pathes after introduced own mid-end IR with "stdlib call simplify" transforms
1184
+ if ( builtin_abs < f64 > ( y ) <= 2 ) {
1185
+ if ( y == 2.0 ) return x * x ;
1186
+ if ( y == 0.5 ) return select < f64 > ( Infinity , builtin_sqrt < f64 > ( x ) , builtin_abs < f64 > ( x ) == Infinity ) ;
1187
+ if ( y == - 1.0 ) return 1 / x ;
1188
+ if ( y == - 0.5 ) {
1189
+ if ( x == 0.0 ) return Infinity ;
1190
+ return select < f64 > ( 0 , 1 / builtin_sqrt < f64 > ( x ) , builtin_abs < f64 > ( x ) == Infinity ) ;
1191
+ }
1192
+ if ( y == 1.0 ) return x ;
1193
+ if ( y == 0.0 ) return 1.0 ;
1194
+ }
1183
1195
if ( ASC_SHRINK_LEVEL < 1 ) {
1184
1196
return pow_lut ( x , y ) ;
1185
1197
} else {
@@ -2564,6 +2576,18 @@ export namespace NativeMathf {
2564
2576
}
2565
2577
2566
2578
export function pow ( x : f32 , y : f32 ) : f32 { // see: musl/src/math/powf.c and SUN COPYRIGHT NOTICE above
2579
+ // TODO: remove this fast pathes after introduced own mid-end IR with "stdlib call simplify" transforms
2580
+ if ( builtin_abs < f32 > ( y ) <= 2 ) {
2581
+ if ( y == 2.0 ) return x * x ;
2582
+ if ( y == 0.5 ) return select < f32 > ( Infinity , builtin_sqrt < f32 > ( x ) , builtin_abs < f32 > ( x ) == Infinity ) ;
2583
+ if ( y == - 1.0 ) return 1 / x ;
2584
+ if ( y == - 0.5 ) {
2585
+ if ( x == 0.0 ) return Infinity ;
2586
+ return select < f32 > ( 0 , 1 / builtin_sqrt < f32 > ( x ) , builtin_abs < f32 > ( x ) == Infinity ) ;
2587
+ }
2588
+ if ( y == 1.0 ) return x ;
2589
+ if ( y == 0.0 ) return 1.0 ;
2590
+ }
2567
2591
return powf_lut ( x , y ) ;
2568
2592
}
2569
2593
0 commit comments