src/cpu/x86/vm/c1_LinearScan_x86.cpp

Print this page
rev 3227 : 7133857: exp() and pow() should use the x87 ISA on x86
Summary: use x87 instructions to implement exp() and pow() in interpreter/c1/c2.
Reviewed-by:


 673   assert(!left->is_xmm_register() && !right->is_xmm_register() && !res->is_xmm_register(), "not for xmm registers");
 674 
 675   switch (op2->code()) {
 676     case lir_cmp:
 677     case lir_cmp_fd2i:
 678     case lir_ucmp_fd2i: {
 679       assert(left->is_fpu_register(), "invalid LIR");
 680       assert(right->is_fpu_register(), "invalid LIR");
 681 
 682       // the left-hand side must be on top of stack.
 683       // the right-hand side is never popped, even if is_last_use is set
 684       insert_exchange(left);
 685       new_left = to_fpu_stack_top(left);
 686       new_right = to_fpu_stack(right);
 687       pop_if_last_use(op2, left);
 688       break;
 689     }
 690 
 691     case lir_mul_strictfp:
 692     case lir_div_strictfp: {
 693       assert(op2->tmp_opr()->is_fpu_register(), "strict operations need temporary fpu stack slot");
 694       insert_free_if_dead(op2->tmp_opr());
 695       assert(sim()->stack_size() <= 7, "at least one stack slot must be free");
 696       // fall-through: continue with the normal handling of lir_mul and lir_div
 697     }
 698     case lir_add:
 699     case lir_sub:
 700     case lir_mul:
 701     case lir_div: {
 702       assert(left->is_fpu_register(), "must be");
 703       assert(res->is_fpu_register(), "must be");
 704       assert(left->is_equal(res), "must be");
 705 
 706       // either the left-hand or the right-hand side must be on top of stack
 707       // (if right is not a register, left must be on top)
 708       if (!right->is_fpu_register()) {
 709         insert_exchange(left);
 710         new_left = to_fpu_stack_top(left);
 711       } else {
 712         // no exchange necessary if right is alredy on top of stack
 713         if (tos_offset(right) == 0) {
 714           new_left = to_fpu_stack(left);


 770     case lir_sqrt: {
 771       // Right argument appears to be unused
 772       assert(right->is_illegal(), "must be");
 773       assert(left->is_fpu_register(), "must be");
 774       assert(res->is_fpu_register(), "must be");
 775       assert(left->is_last_use(), "old value gets destroyed");
 776 
 777       insert_free_if_dead(res, left);
 778       insert_exchange(left);
 779       do_rename(left, res);
 780 
 781       new_left = to_fpu_stack_top(res);
 782       new_res = new_left;
 783 
 784       op2->set_fpu_stack_size(sim()->stack_size());
 785       break;
 786     }
 787 
 788     case lir_log:
 789     case lir_log10: {
 790       // log and log10 needs one temporary fpu stack slot, so there is ontemporary
 791       // registers stored in temp of the operation.
 792       // the stack allocator must guarantee that the stack slots are really free,
 793       // otherwise there might be a stack overflow.

 794       assert(right->is_illegal(), "must be");
 795       assert(left->is_fpu_register(), "must be");
 796       assert(res->is_fpu_register(), "must be");
 797       assert(op2->tmp_opr()->is_fpu_register(), "must be");
 798 
 799       insert_free_if_dead(op2->tmp_opr());
 800       insert_free_if_dead(res, left);
 801       insert_exchange(left);
 802       do_rename(left, res);
 803 
 804       new_left = to_fpu_stack_top(res);
 805       new_res = new_left;
 806 
 807       op2->set_fpu_stack_size(sim()->stack_size());
 808       assert(sim()->stack_size() <= 7, "at least one stack slot must be free");
 809       break;
 810     }
 811 
 812 
 813     case lir_tan:
 814     case lir_sin:
 815     case lir_cos: {
 816       // sin and cos need two temporary fpu stack slots, so there are two temporary

 817       // registers (stored in right and temp of the operation).
 818       // the stack allocator must guarantee that the stack slots are really free,
 819       // otherwise there might be a stack overflow.
 820       assert(left->is_fpu_register(), "must be");
 821       assert(res->is_fpu_register(), "must be");
 822       // assert(left->is_last_use(), "old value gets destroyed");
 823       assert(right->is_fpu_register(), "right is used as the first temporary register");
 824       assert(op2->tmp_opr()->is_fpu_register(), "temp is used as the second temporary register");
 825       assert(fpu_num(left) != fpu_num(right) && fpu_num(right) != fpu_num(op2->tmp_opr()) && fpu_num(op2->tmp_opr()) != fpu_num(res), "need distinct temp registers");
 826 
 827       insert_free_if_dead(right);
 828       insert_free_if_dead(op2->tmp_opr());
 829 
 830       insert_free_if_dead(res, left);
 831       insert_exchange(left);
 832       do_rename(left, res);
 833 
 834       new_left = to_fpu_stack_top(res);
 835       new_res = new_left;
 836 
 837       op2->set_fpu_stack_size(sim()->stack_size());
 838       assert(sim()->stack_size() <= 6, "at least two stack slots must be free");















































 839       break;
 840     }
 841 
 842     default: {
 843       assert(false, "missed a fpu-operation");
 844     }
 845   }
 846 
 847   op2->set_in_opr1(new_left);
 848   op2->set_in_opr2(new_right);
 849   op2->set_result_opr(new_res);
 850 }
 851 
 852 void FpuStackAllocator::handle_opCall(LIR_OpCall* opCall) {
 853   LIR_Opr res = opCall->result_opr();
 854 
 855   // clear fpu-stack before call
 856   // it may contain dead values that could not have been remved by previous operations
 857   clear_fpu_stack(LIR_OprFact::illegalOpr);
 858   assert(sim()->is_empty(), "fpu stack must be empty now");




 673   assert(!left->is_xmm_register() && !right->is_xmm_register() && !res->is_xmm_register(), "not for xmm registers");
 674 
 675   switch (op2->code()) {
 676     case lir_cmp:
 677     case lir_cmp_fd2i:
 678     case lir_ucmp_fd2i: {
 679       assert(left->is_fpu_register(), "invalid LIR");
 680       assert(right->is_fpu_register(), "invalid LIR");
 681 
 682       // the left-hand side must be on top of stack.
 683       // the right-hand side is never popped, even if is_last_use is set
 684       insert_exchange(left);
 685       new_left = to_fpu_stack_top(left);
 686       new_right = to_fpu_stack(right);
 687       pop_if_last_use(op2, left);
 688       break;
 689     }
 690 
 691     case lir_mul_strictfp:
 692     case lir_div_strictfp: {
 693       assert(op2->tmp1_opr()->is_fpu_register(), "strict operations need temporary fpu stack slot");
 694       insert_free_if_dead(op2->tmp1_opr());
 695       assert(sim()->stack_size() <= 7, "at least one stack slot must be free");
 696       // fall-through: continue with the normal handling of lir_mul and lir_div
 697     }
 698     case lir_add:
 699     case lir_sub:
 700     case lir_mul:
 701     case lir_div: {
 702       assert(left->is_fpu_register(), "must be");
 703       assert(res->is_fpu_register(), "must be");
 704       assert(left->is_equal(res), "must be");
 705 
 706       // either the left-hand or the right-hand side must be on top of stack
 707       // (if right is not a register, left must be on top)
 708       if (!right->is_fpu_register()) {
 709         insert_exchange(left);
 710         new_left = to_fpu_stack_top(left);
 711       } else {
 712         // no exchange necessary if right is alredy on top of stack
 713         if (tos_offset(right) == 0) {
 714           new_left = to_fpu_stack(left);


 770     case lir_sqrt: {
 771       // Right argument appears to be unused
 772       assert(right->is_illegal(), "must be");
 773       assert(left->is_fpu_register(), "must be");
 774       assert(res->is_fpu_register(), "must be");
 775       assert(left->is_last_use(), "old value gets destroyed");
 776 
 777       insert_free_if_dead(res, left);
 778       insert_exchange(left);
 779       do_rename(left, res);
 780 
 781       new_left = to_fpu_stack_top(res);
 782       new_res = new_left;
 783 
 784       op2->set_fpu_stack_size(sim()->stack_size());
 785       break;
 786     }
 787 
 788     case lir_log:
 789     case lir_log10: {
 790       // log and log10 need one temporary fpu stack slot, so
 791       // there is one temporary registers stored in temp of the
 792       // operation. the stack allocator must guarantee that the stack
 793       // slots are really free, otherwise there might be a stack
 794       // overflow.
 795       assert(right->is_illegal(), "must be");
 796       assert(left->is_fpu_register(), "must be");
 797       assert(res->is_fpu_register(), "must be");
 798       assert(op2->tmp1_opr()->is_fpu_register(), "must be");
 799 
 800       insert_free_if_dead(op2->tmp1_opr());
 801       insert_free_if_dead(res, left);
 802       insert_exchange(left);
 803       do_rename(left, res);
 804 
 805       new_left = to_fpu_stack_top(res);
 806       new_res = new_left;
 807 
 808       op2->set_fpu_stack_size(sim()->stack_size());
 809       assert(sim()->stack_size() <= 7, "at least one stack slot must be free");
 810       break;
 811     }
 812 
 813 
 814     case lir_tan:
 815     case lir_sin:
 816     case lir_cos:
 817     case lir_exp: {
 818       // sin, cos and exp need two temporary fpu stack slots, so there are two temporary
 819       // registers (stored in right and temp of the operation).
 820       // the stack allocator must guarantee that the stack slots are really free,
 821       // otherwise there might be a stack overflow.
 822       assert(left->is_fpu_register(), "must be");
 823       assert(res->is_fpu_register(), "must be");
 824       // assert(left->is_last_use(), "old value gets destroyed");
 825       assert(right->is_fpu_register(), "right is used as the first temporary register");
 826       assert(op2->tmp1_opr()->is_fpu_register(), "temp is used as the second temporary register");
 827       assert(fpu_num(left) != fpu_num(right) && fpu_num(right) != fpu_num(op2->tmp1_opr()) && fpu_num(op2->tmp1_opr()) != fpu_num(res), "need distinct temp registers");
 828 
 829       insert_free_if_dead(right);
 830       insert_free_if_dead(op2->tmp1_opr());
 831 
 832       insert_free_if_dead(res, left);
 833       insert_exchange(left);
 834       do_rename(left, res);
 835 
 836       new_left = to_fpu_stack_top(res);
 837       new_res = new_left;
 838 
 839       op2->set_fpu_stack_size(sim()->stack_size());
 840       assert(sim()->stack_size() <= 6, "at least two stack slots must be free");
 841       break;
 842     }
 843 
 844     case lir_pow: {
 845       // pow needs two temporary fpu stack slots, so there are two temporary
 846       // registers (stored in tmp1 and tmp2 of the operation).
 847       // the stack allocator must guarantee that the stack slots are really free,
 848       // otherwise there might be a stack overflow.
 849       assert(left->is_fpu_register(), "must be");
 850       assert(right->is_fpu_register(), "must be");
 851       assert(res->is_fpu_register(), "must be");
 852 
 853       assert(op2->tmp1_opr()->is_fpu_register(), "tmp1 is the first temporary register");
 854       assert(op2->tmp2_opr()->is_fpu_register(), "tmp2 is the second temporary register");
 855       assert(fpu_num(left) != fpu_num(right) && fpu_num(left) != fpu_num(op2->tmp1_opr()) && fpu_num(left) != fpu_num(op2->tmp2_opr()) && fpu_num(left) != fpu_num(res), "need distinct temp registers");
 856       assert(fpu_num(right) != fpu_num(op2->tmp1_opr()) && fpu_num(right) != fpu_num(op2->tmp2_opr()) && fpu_num(right) != fpu_num(res), "need distinct temp registers");
 857       assert(fpu_num(op2->tmp1_opr()) != fpu_num(op2->tmp2_opr()) && fpu_num(op2->tmp1_opr()) != fpu_num(res), "need distinct temp registers");
 858       assert(fpu_num(op2->tmp2_opr()) != fpu_num(res), "need distinct temp registers");
 859 
 860       insert_free_if_dead(op2->tmp1_opr());
 861       insert_free_if_dead(op2->tmp2_opr());
 862 
 863       // Must bring both operands to top of stack with following operand ordering:
 864       // * fpu stack before pow: ... right left
 865       // * fpu stack after pow:  ... left
 866 
 867       insert_free_if_dead(res, right);
 868 
 869       if (tos_offset(right) != 1) {
 870         insert_exchange(right);
 871         insert_exchange(1);
 872       }
 873       insert_exchange(left);
 874       assert(tos_offset(right) == 1, "check");
 875       assert(tos_offset(left) == 0, "check");
 876 
 877       new_left = to_fpu_stack_top(left);
 878       new_right = to_fpu_stack(right);
 879 
 880       op2->set_fpu_stack_size(sim()->stack_size());
 881       assert(sim()->stack_size() <= 6, "at least two stack slots must be free");
 882 
 883       sim()->pop();
 884 
 885       do_rename(right, res);
 886 
 887       new_res = to_fpu_stack_top(res);
 888       break;
 889     }
 890 
 891     default: {
 892       assert(false, "missed a fpu-operation");
 893     }
 894   }
 895 
 896   op2->set_in_opr1(new_left);
 897   op2->set_in_opr2(new_right);
 898   op2->set_result_opr(new_res);
 899 }
 900 
 901 void FpuStackAllocator::handle_opCall(LIR_OpCall* opCall) {
 902   LIR_Opr res = opCall->result_opr();
 903 
 904   // clear fpu-stack before call
 905   // it may contain dead values that could not have been remved by previous operations
 906   clear_fpu_stack(LIR_OprFact::illegalOpr);
 907   assert(sim()->is_empty(), "fpu stack must be empty now");