@@ -756,7 +756,7 @@ protected static PowNode create() {
756
756
}
757
757
758
758
@ Specialization (guards = "right >= 0" , rewriteOn = ArithmeticException .class )
759
- int doIntegerFast (int left , int right , @ SuppressWarnings ("unused" ) PNone none ) {
759
+ static int doIntegerFast (int left , int right , @ SuppressWarnings ("unused" ) PNone none ) {
760
760
int result = 1 ;
761
761
int exponent = right ;
762
762
int base = left ;
@@ -770,13 +770,13 @@ int doIntegerFast(int left, int right, @SuppressWarnings("unused") PNone none) {
770
770
return result ;
771
771
}
772
772
773
- @ Specialization (guards = "right >= 0" )
774
- PInt doInteger (int left , int right , @ SuppressWarnings ( "unused" ) PNone none ) {
775
- return factory (). createInt ( op ( PInt . longToBigInteger ( left ), right ) );
773
+ @ Specialization (guards = "right >= 0" , replaces = "doIntegerFast" , rewriteOn = ArithmeticException . class )
774
+ static long doInteger (int left , int right , PNone none ) {
775
+ return doLongFast (( long ) left , ( long ) right , none );
776
776
}
777
777
778
778
@ Specialization (guards = "right >= 0" , rewriteOn = ArithmeticException .class )
779
- long doLongFast (long left , int right , PNone none ) {
779
+ static long doLongFast (long left , int right , PNone none ) {
780
780
return doLongFast (left , (long ) right , none );
781
781
}
782
782
@@ -786,7 +786,7 @@ PInt doLong(long left, int right, PNone none) {
786
786
}
787
787
788
788
@ Specialization (guards = "right >= 0" , rewriteOn = ArithmeticException .class )
789
- long doLongFast (int left , long right , PNone none ) {
789
+ static long doLongFast (int left , long right , PNone none ) {
790
790
return doLongFast ((long ) left , right , none );
791
791
}
792
792
@@ -796,7 +796,7 @@ PInt doLong(int left, long right, PNone none) {
796
796
}
797
797
798
798
@ Specialization (guards = "right >= 0" , rewriteOn = ArithmeticException .class )
799
- long doLongFast (long left , long right , @ SuppressWarnings ("unused" ) PNone none ) {
799
+ static long doLongFast (long left , long right , @ SuppressWarnings ("unused" ) PNone none ) {
800
800
long result = 1 ;
801
801
long exponent = right ;
802
802
long base = left ;
@@ -810,21 +810,56 @@ long doLongFast(long left, long right, @SuppressWarnings("unused") PNone none) {
810
810
return result ;
811
811
}
812
812
813
- @ Specialization (guards = "right >= 0" )
813
+ @ Specialization (guards = "right >= 0" , replaces = "doLongFast" )
814
814
PInt doLong (long left , long right , @ SuppressWarnings ("unused" ) PNone none ) {
815
815
return factory ().createInt (op (PInt .longToBigInteger (left ), right ));
816
816
}
817
817
818
- @ Specialization
819
- double doInt (long left , long right , @ SuppressWarnings ("unused" ) PNone none ) {
818
+ @ Specialization ( guards = "right < 0" )
819
+ static double doInt (long left , long right , @ SuppressWarnings ("unused" ) PNone none ) {
820
820
return Math .pow (left , right );
821
821
}
822
822
823
823
@ Specialization
824
- double doInt (long left , double right , @ SuppressWarnings ("unused" ) PNone none ) {
824
+ static double doInt (long left , double right , @ SuppressWarnings ("unused" ) PNone none ) {
825
825
return Math .pow (left , right );
826
826
}
827
827
828
+ @ Specialization (rewriteOn = ArithmeticException .class )
829
+ static Object doLongPIntNarrow (long left , PInt right , PNone none ) {
830
+ long lright = right .longValueExact ();
831
+ if (lright >= 0 ) {
832
+ return doLongFast (left , lright , none );
833
+ }
834
+ return doInt (left , lright , none );
835
+ }
836
+
837
+ @ Specialization (replaces = "doLongPIntNarrow" )
838
+ PInt doLongPInt (long left , PInt right , @ SuppressWarnings ("unused" ) PNone none ) {
839
+ try {
840
+ return factory ().createInt (op (PInt .longToBigInteger (left ), right .longValueExact ()));
841
+ } catch (ArithmeticException e ) {
842
+ // fall through to normal computation
843
+ }
844
+ double value = Math .pow (left , right .doubleValue ());
845
+ return factory ().createInt ((long ) value );
846
+ }
847
+
848
+ @ Specialization (guards = "right >= 0" , rewriteOn = ArithmeticException .class )
849
+ long doPIntLongNarrow (PInt left , long right , @ SuppressWarnings ("unused" ) PNone none ) {
850
+ return PInt .longValueExact (op (left .getValue (), right ));
851
+ }
852
+
853
+ @ Specialization (guards = "right >= 0" , replaces = "doPIntLongNarrow" )
854
+ PInt doPIntLongPositive (PInt left , long right , @ SuppressWarnings ("unused" ) PNone none ) {
855
+ return factory ().createInt (op (left .getValue (), right ));
856
+ }
857
+
858
+ @ Specialization (guards = "right < 0" )
859
+ double doPIntLongNegative (PInt left , long right , @ SuppressWarnings ("unused" ) PNone none ) {
860
+ return TrueDivNode .op (BigInteger .ONE , op (left .getValue (), -right ));
861
+ }
862
+
828
863
@ Specialization
829
864
PInt doPInt (PInt left , PInt right , @ SuppressWarnings ("unused" ) PNone none ) {
830
865
try {
0 commit comments