src/cpu/x86/vm/assembler_x86_32.inline.hpp

Wed, 07 May 2008 08:06:46 -0700

author
rasbold
date
Wed, 07 May 2008 08:06:46 -0700
changeset 580
f3de1255b035
parent 435
a61af66fc99e
permissions
-rw-r--r--

6603011: RFE: Optimize long division
Summary: Transform long division by constant into multiply
Reviewed-by: never, kvn

     1 /*
     2  * Copyright 1997-2005 Sun Microsystems, Inc.  All Rights Reserved.
     3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
     4  *
     5  * This code is free software; you can redistribute it and/or modify it
     6  * under the terms of the GNU General Public License version 2 only, as
     7  * published by the Free Software Foundation.
     8  *
     9  * This code is distributed in the hope that it will be useful, but WITHOUT
    10  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
    11  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
    12  * version 2 for more details (a copy is included in the LICENSE file that
    13  * accompanied this code).
    14  *
    15  * You should have received a copy of the GNU General Public License version
    16  * 2 along with this work; if not, write to the Free Software Foundation,
    17  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
    18  *
    19  * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
    20  * CA 95054 USA or visit www.sun.com if you need additional information or
    21  * have any questions.
    22  *
    23  */
    25 inline void MacroAssembler::pd_patch_instruction(address branch, address target) {
    26   unsigned char op = branch[0];
    27   assert(op == 0xE8 /* call */ ||
    28          op == 0xE9 /* jmp */ ||
    29          op == 0xEB /* short jmp */ ||
    30          (op & 0xF0) == 0x70 /* short jcc */ ||
    31          op == 0x0F && (branch[1] & 0xF0) == 0x80 /* jcc */,
    32          "Invalid opcode at patch point");
    34   if (op == 0xEB || (op & 0xF0) == 0x70) {
    35     // short offset operators (jmp and jcc)
    36     char* disp = (char*) &branch[1];
    37     int imm8 = target - (address) &disp[1];
    38     guarantee(this->is8bit(imm8), "Short forward jump exceeds 8-bit offset");
    39     *disp = imm8;
    40   } else {
    41     int* disp = (int*) &branch[(op == 0x0F)? 2: 1];
    42     int imm32 = target - (address) &disp[1];
    43     *disp = imm32;
    44   }
    45 }
    47 #ifndef PRODUCT
    48 inline void MacroAssembler::pd_print_patched_instruction(address branch) {
    49   const char* s;
    50   unsigned char op = branch[0];
    51   if (op == 0xE8) {
    52     s = "call";
    53   } else if (op == 0xE9 || op == 0xEB) {
    54     s = "jmp";
    55   } else if ((op & 0xF0) == 0x70) {
    56     s = "jcc";
    57   } else if (op == 0x0F) {
    58     s = "jcc";
    59   } else {
    60     s = "????";
    61   }
    62   tty->print("%s (unresolved)", s);
    63 }
    64 #endif // ndef PRODUCT

mercurial