3127 tmp = rdx; |
3124 tmp = rdx; |
3128 } |
3125 } |
3129 Register tmp2 = rax; |
3126 Register tmp2 = rax; |
3130 Register tmp3 = rcx; |
3127 Register tmp3 = rcx; |
3131 |
3128 |
3132 if (is_exp) { |
3129 // Stack: X Y |
3133 // Stack: X |
3130 Label x_negative, y_not_2; |
3134 fld_s(0); // duplicate argument for runtime call. Stack: X X |
3131 |
3135 fast_exp(); // Stack: exp(X) X |
3132 static double two = 2.0; |
3136 fcmp(tmp, 0, false, false); // Stack: exp(X) X |
3133 ExternalAddress two_addr((address)&two); |
3137 // exp(X) not equal to itself: exp(X) is NaN go to slow case. |
3134 |
3138 jcc(Assembler::parity, slow_case); |
3135 // constant maybe too far on 64 bit |
3139 // get rid of duplicate argument. Stack: exp(X) |
3136 lea(tmp2, two_addr); |
3140 if (num_fpu_regs_in_use > 0) { |
3137 fld_d(Address(tmp2, 0)); // Stack: 2 X Y |
3141 fxch(); |
3138 fcmp(tmp, 2, true, false); // Stack: X Y |
3142 fpop(); |
3139 jcc(Assembler::parity, y_not_2); |
3143 } else { |
3140 jcc(Assembler::notEqual, y_not_2); |
3144 ffree(1); |
3141 |
3145 } |
3142 fxch(); fpop(); // Stack: X |
3146 jmp(done); |
3143 fmul(0); // Stack: X*X |
3147 } else { |
3144 |
3148 // Stack: X Y |
3145 jmp(done); |
3149 Label x_negative, y_not_2; |
3146 |
3150 |
3147 bind(y_not_2); |
3151 static double two = 2.0; |
3148 |
3152 ExternalAddress two_addr((address)&two); |
3149 fldz(); // Stack: 0 X Y |
3153 |
3150 fcmp(tmp, 1, true, false); // Stack: X Y |
3154 // constant maybe too far on 64 bit |
3151 jcc(Assembler::above, x_negative); |
3155 lea(tmp2, two_addr); |
3152 |
3156 fld_d(Address(tmp2, 0)); // Stack: 2 X Y |
3153 // X >= 0 |
3157 fcmp(tmp, 2, true, false); // Stack: X Y |
3154 |
3158 jcc(Assembler::parity, y_not_2); |
3155 fld_s(1); // duplicate arguments for runtime call. Stack: Y X Y |
3159 jcc(Assembler::notEqual, y_not_2); |
3156 fld_s(1); // Stack: X Y X Y |
3160 |
3157 fast_pow(); // Stack: X^Y X Y |
3161 fxch(); fpop(); // Stack: X |
3158 fcmp(tmp, 0, false, false); // Stack: X^Y X Y |
3162 fmul(0); // Stack: X*X |
3159 // X^Y not equal to itself: X^Y is NaN go to slow case. |
3163 |
3160 jcc(Assembler::parity, slow_case); |
3164 jmp(done); |
3161 // get rid of duplicate arguments. Stack: X^Y |
3165 |
3162 if (num_fpu_regs_in_use > 0) { |
3166 bind(y_not_2); |
3163 fxch(); fpop(); |
3167 |
3164 fxch(); fpop(); |
3168 fldz(); // Stack: 0 X Y |
3165 } else { |
3169 fcmp(tmp, 1, true, false); // Stack: X Y |
3166 ffree(2); |
3170 jcc(Assembler::above, x_negative); |
3167 ffree(1); |
3171 |
3168 } |
3172 // X >= 0 |
3169 jmp(done); |
3173 |
3170 |
3174 fld_s(1); // duplicate arguments for runtime call. Stack: Y X Y |
3171 // X <= 0 |
3175 fld_s(1); // Stack: X Y X Y |
3172 bind(x_negative); |
3176 fast_pow(); // Stack: X^Y X Y |
3173 |
3177 fcmp(tmp, 0, false, false); // Stack: X^Y X Y |
3174 fld_s(1); // Stack: Y X Y |
3178 // X^Y not equal to itself: X^Y is NaN go to slow case. |
3175 frndint(); // Stack: int(Y) X Y |
3179 jcc(Assembler::parity, slow_case); |
3176 fcmp(tmp, 2, false, false); // Stack: int(Y) X Y |
3180 // get rid of duplicate arguments. Stack: X^Y |
3177 jcc(Assembler::notEqual, slow_case); |
3181 if (num_fpu_regs_in_use > 0) { |
3178 |
3182 fxch(); fpop(); |
3179 subptr(rsp, 8); |
3183 fxch(); fpop(); |
3180 |
3184 } else { |
3181 // For X^Y, when X < 0, Y has to be an integer and the final |
3185 ffree(2); |
3182 // result depends on whether it's odd or even. We just checked |
3186 ffree(1); |
3183 // that int(Y) == Y. We move int(Y) to gp registers as a 64 bit |
3187 } |
3184 // integer to test its parity. If int(Y) is huge and doesn't fit |
3188 jmp(done); |
3185 // in the 64 bit integer range, the integer indefinite value will |
3189 |
3186 // end up in the gp registers. Huge numbers are all even, the |
3190 // X <= 0 |
3187 // integer indefinite number is even so it's fine. |
3191 bind(x_negative); |
|
3192 |
|
3193 fld_s(1); // Stack: Y X Y |
|
3194 frndint(); // Stack: int(Y) X Y |
|
3195 fcmp(tmp, 2, false, false); // Stack: int(Y) X Y |
|
3196 jcc(Assembler::notEqual, slow_case); |
|
3197 |
|
3198 subptr(rsp, 8); |
|
3199 |
|
3200 // For X^Y, when X < 0, Y has to be an integer and the final |
|
3201 // result depends on whether it's odd or even. We just checked |
|
3202 // that int(Y) == Y. We move int(Y) to gp registers as a 64 bit |
|
3203 // integer to test its parity. If int(Y) is huge and doesn't fit |
|
3204 // in the 64 bit integer range, the integer indefinite value will |
|
3205 // end up in the gp registers. Huge numbers are all even, the |
|
3206 // integer indefinite number is even so it's fine. |
|
3207 |
3188 |
3208 #ifdef ASSERT |
3189 #ifdef ASSERT |
3209 // Let's check we don't end up with an integer indefinite number |
3190 // Let's check we don't end up with an integer indefinite number |
3210 // when not expected. First test for huge numbers: check whether |
3191 // when not expected. First test for huge numbers: check whether |
3211 // int(Y)+1 == int(Y) which is true for very large numbers and |
3192 // int(Y)+1 == int(Y) which is true for very large numbers and |
3212 // those are all even. A 64 bit integer is guaranteed to not |
3193 // those are all even. A 64 bit integer is guaranteed to not |
3213 // overflow for numbers where y+1 != y (when precision is set to |
3194 // overflow for numbers where y+1 != y (when precision is set to |
3214 // double precision). |
3195 // double precision). |
3215 Label y_not_huge; |
3196 Label y_not_huge; |
3216 |
3197 |
3217 fld1(); // Stack: 1 int(Y) X Y |
3198 fld1(); // Stack: 1 int(Y) X Y |
3218 fadd(1); // Stack: 1+int(Y) int(Y) X Y |
3199 fadd(1); // Stack: 1+int(Y) int(Y) X Y |
3219 |
3200 |
3220 #ifdef _LP64 |
3201 #ifdef _LP64 |
3221 // trip to memory to force the precision down from double extended |
3202 // trip to memory to force the precision down from double extended |
3222 // precision |
3203 // precision |
3223 fstp_d(Address(rsp, 0)); |
3204 fstp_d(Address(rsp, 0)); |
3224 fld_d(Address(rsp, 0)); |
3205 fld_d(Address(rsp, 0)); |
3225 #endif |
3206 #endif |
3226 |
3207 |
3227 fcmp(tmp, 1, true, false); // Stack: int(Y) X Y |
3208 fcmp(tmp, 1, true, false); // Stack: int(Y) X Y |
3228 #endif |
3209 #endif |
3229 |
3210 |
3230 // move int(Y) as 64 bit integer to thread's stack |
3211 // move int(Y) as 64 bit integer to thread's stack |
3231 fistp_d(Address(rsp,0)); // Stack: X Y |
3212 fistp_d(Address(rsp,0)); // Stack: X Y |
3232 |
3213 |
3233 #ifdef ASSERT |
3214 #ifdef ASSERT |
3234 jcc(Assembler::notEqual, y_not_huge); |
3215 jcc(Assembler::notEqual, y_not_huge); |
3235 |
3216 |
3236 // Y is huge so we know it's even. It may not fit in a 64 bit |
3217 // Y is huge so we know it's even. It may not fit in a 64 bit |
3237 // integer and we don't want the debug code below to see the |
3218 // integer and we don't want the debug code below to see the |
3238 // integer indefinite value so overwrite int(Y) on the thread's |
3219 // integer indefinite value so overwrite int(Y) on the thread's |
3239 // stack with 0. |
3220 // stack with 0. |
3240 movl(Address(rsp, 0), 0); |
3221 movl(Address(rsp, 0), 0); |
3241 movl(Address(rsp, 4), 0); |
3222 movl(Address(rsp, 4), 0); |
3242 |
3223 |
3243 bind(y_not_huge); |
3224 bind(y_not_huge); |
3244 #endif |
3225 #endif |
3245 |
3226 |
3246 fld_s(1); // duplicate arguments for runtime call. Stack: Y X Y |
3227 fld_s(1); // duplicate arguments for runtime call. Stack: Y X Y |
3247 fld_s(1); // Stack: X Y X Y |
3228 fld_s(1); // Stack: X Y X Y |
3248 fabs(); // Stack: abs(X) Y X Y |
3229 fabs(); // Stack: abs(X) Y X Y |
3249 fast_pow(); // Stack: abs(X)^Y X Y |
3230 fast_pow(); // Stack: abs(X)^Y X Y |
3250 fcmp(tmp, 0, false, false); // Stack: abs(X)^Y X Y |
3231 fcmp(tmp, 0, false, false); // Stack: abs(X)^Y X Y |
3251 // abs(X)^Y not equal to itself: abs(X)^Y is NaN go to slow case. |
3232 // abs(X)^Y not equal to itself: abs(X)^Y is NaN go to slow case. |
3252 |
3233 |
3253 pop(tmp2); |
3234 pop(tmp2); |
3254 NOT_LP64(pop(tmp3)); |
3235 NOT_LP64(pop(tmp3)); |
3255 jcc(Assembler::parity, slow_case); |
3236 jcc(Assembler::parity, slow_case); |
3256 |
3237 |
3257 #ifdef ASSERT |
3238 #ifdef ASSERT |
3258 // Check that int(Y) is not integer indefinite value (int |
3239 // Check that int(Y) is not integer indefinite value (int |
3259 // overflow). Shouldn't happen because for values that would |
3240 // overflow). Shouldn't happen because for values that would |
3260 // overflow, 1+int(Y)==Y which was tested earlier. |
3241 // overflow, 1+int(Y)==Y which was tested earlier. |
3261 #ifndef _LP64 |
3242 #ifndef _LP64 |
3262 { |
3243 { |
3263 Label integer; |
3244 Label integer; |
3264 testl(tmp2, tmp2); |
3245 testl(tmp2, tmp2); |
3265 jcc(Assembler::notZero, integer); |
3246 jcc(Assembler::notZero, integer); |
3266 cmpl(tmp3, 0x80000000); |
3247 cmpl(tmp3, 0x80000000); |
3267 jcc(Assembler::notZero, integer); |
3248 jcc(Assembler::notZero, integer); |
3268 STOP("integer indefinite value shouldn't be seen here"); |
3249 STOP("integer indefinite value shouldn't be seen here"); |
3269 bind(integer); |
3250 bind(integer); |
3270 } |
3251 } |
3271 #else |
3252 #else |
3272 { |
3253 { |
3273 Label integer; |
3254 Label integer; |
3274 mov(tmp3, tmp2); // preserve tmp2 for parity check below |
3255 mov(tmp3, tmp2); // preserve tmp2 for parity check below |
3275 shlq(tmp3, 1); |
3256 shlq(tmp3, 1); |
3276 jcc(Assembler::carryClear, integer); |
3257 jcc(Assembler::carryClear, integer); |
3277 jcc(Assembler::notZero, integer); |
3258 jcc(Assembler::notZero, integer); |
3278 STOP("integer indefinite value shouldn't be seen here"); |
3259 STOP("integer indefinite value shouldn't be seen here"); |
3279 bind(integer); |
3260 bind(integer); |
3280 } |
3261 } |
3281 #endif |
3262 #endif |
3282 #endif |
3263 #endif |
3283 |
3264 |
3284 // get rid of duplicate arguments. Stack: X^Y |
3265 // get rid of duplicate arguments. Stack: X^Y |
3285 if (num_fpu_regs_in_use > 0) { |
3266 if (num_fpu_regs_in_use > 0) { |
3286 fxch(); fpop(); |
3267 fxch(); fpop(); |
3287 fxch(); fpop(); |
3268 fxch(); fpop(); |
3288 } else { |
3269 } else { |
3289 ffree(2); |
3270 ffree(2); |
3290 ffree(1); |
3271 ffree(1); |
3291 } |
3272 } |
3292 |
3273 |
3293 testl(tmp2, 1); |
3274 testl(tmp2, 1); |
3294 jcc(Assembler::zero, done); // X <= 0, Y even: X^Y = abs(X)^Y |
3275 jcc(Assembler::zero, done); // X <= 0, Y even: X^Y = abs(X)^Y |
3295 // X <= 0, Y even: X^Y = -abs(X)^Y |
3276 // X <= 0, Y even: X^Y = -abs(X)^Y |
3296 |
3277 |
3297 fchs(); // Stack: -abs(X)^Y Y |
3278 fchs(); // Stack: -abs(X)^Y Y |
3298 jmp(done); |
3279 jmp(done); |
3299 } |
|
3300 |
3280 |
3301 // slow case: runtime call |
3281 // slow case: runtime call |
3302 bind(slow_case); |
3282 bind(slow_case); |
3303 |
3283 |
3304 fpop(); // pop incorrect result or int(Y) |
3284 fpop(); // pop incorrect result or int(Y) |
3305 |
3285 |
3306 fp_runtime_fallback(is_exp ? CAST_FROM_FN_PTR(address, SharedRuntime::dexp) : CAST_FROM_FN_PTR(address, SharedRuntime::dpow), |
3286 fp_runtime_fallback(CAST_FROM_FN_PTR(address, SharedRuntime::dpow), 2, num_fpu_regs_in_use); |
3307 is_exp ? 1 : 2, num_fpu_regs_in_use); |
|
3308 |
3287 |
3309 // Come here with result in F-TOS |
3288 // Come here with result in F-TOS |
3310 bind(done); |
3289 bind(done); |
3311 } |
3290 } |
3312 |
3291 |