Mon, 23 Jun 2008 14:11:12 -0700
6708714: Optimize long LShift on 32-bits x86
Summary: For small (1-3 bits) left long shifts in 32-bits VM use sets of add+addc instructions instead of shld+shl on new AMD cpus.
Reviewed-by: never
Contributed-by: shrinivas.joshi@amd.com
duke@435 | 1 | /* |
duke@435 | 2 | * Copyright 2001-2005 Sun Microsystems, Inc. All Rights Reserved. |
duke@435 | 3 | * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
duke@435 | 4 | * |
duke@435 | 5 | * This code is free software; you can redistribute it and/or modify it |
duke@435 | 6 | * under the terms of the GNU General Public License version 2 only, as |
duke@435 | 7 | * published by the Free Software Foundation. |
duke@435 | 8 | * |
duke@435 | 9 | * This code is distributed in the hope that it will be useful, but WITHOUT |
duke@435 | 10 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
duke@435 | 11 | * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
duke@435 | 12 | * version 2 for more details (a copy is included in the LICENSE file that |
duke@435 | 13 | * accompanied this code). |
duke@435 | 14 | * |
duke@435 | 15 | * You should have received a copy of the GNU General Public License version |
duke@435 | 16 | * 2 along with this work; if not, write to the Free Software Foundation, |
duke@435 | 17 | * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
duke@435 | 18 | * |
duke@435 | 19 | * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara, |
duke@435 | 20 | * CA 95054 USA or visit www.sun.com if you need additional information or |
duke@435 | 21 | * have any questions. |
duke@435 | 22 | * |
duke@435 | 23 | */ |
duke@435 | 24 | |
duke@435 | 25 | # include "incls/_precompiled.incl" |
duke@435 | 26 | # include "incls/_stackValueCollection.cpp.incl" |
duke@435 | 27 | |
duke@435 | 28 | jint StackValueCollection::int_at(int slot) const { |
duke@435 | 29 | intptr_t val = at(slot)->get_int(); |
duke@435 | 30 | jint ival = *((jint*) (&val)); |
duke@435 | 31 | return ival; |
duke@435 | 32 | } |
duke@435 | 33 | |
duke@435 | 34 | jlong StackValueCollection::long_at(int slot) const { |
duke@435 | 35 | #ifdef _LP64 |
duke@435 | 36 | return at(slot+1)->get_int(); |
duke@435 | 37 | #else |
duke@435 | 38 | union { |
duke@435 | 39 | jlong jl; |
duke@435 | 40 | jint array[2]; |
duke@435 | 41 | } value; |
duke@435 | 42 | // Interpreter stack is reversed in memory: |
duke@435 | 43 | // low memory location is in higher java local slot. |
duke@435 | 44 | value.array[0] = at(slot+1)->get_int(); |
duke@435 | 45 | value.array[1] = at(slot )->get_int(); |
duke@435 | 46 | return value.jl; |
duke@435 | 47 | #endif |
duke@435 | 48 | } |
duke@435 | 49 | |
duke@435 | 50 | Handle StackValueCollection::obj_at(int slot) const { |
duke@435 | 51 | return at(slot)->get_obj(); |
duke@435 | 52 | } |
duke@435 | 53 | |
duke@435 | 54 | jfloat StackValueCollection::float_at(int slot) const { |
duke@435 | 55 | intptr_t res = at(slot)->get_int(); |
duke@435 | 56 | return *((jfloat*) (&res)); |
duke@435 | 57 | } |
duke@435 | 58 | |
duke@435 | 59 | jdouble StackValueCollection::double_at(int slot) const { |
duke@435 | 60 | #ifdef _LP64 |
duke@435 | 61 | intptr_t res = at(slot+1)->get_int(); |
duke@435 | 62 | return *((jdouble*) (&res)); |
duke@435 | 63 | #else |
duke@435 | 64 | union { |
duke@435 | 65 | jdouble jd; |
duke@435 | 66 | jint array[2]; |
duke@435 | 67 | } value; |
duke@435 | 68 | // Interpreter stack is reversed in memory: |
duke@435 | 69 | // low memory location is in higher java local slot. |
duke@435 | 70 | value.array[0] = at(slot+1)->get_int(); |
duke@435 | 71 | value.array[1] = at(slot )->get_int(); |
duke@435 | 72 | return value.jd; |
duke@435 | 73 | #endif |
duke@435 | 74 | } |
duke@435 | 75 | |
duke@435 | 76 | void StackValueCollection::set_int_at(int slot, jint value) { |
duke@435 | 77 | intptr_t val; |
duke@435 | 78 | *((jint*) (&val)) = value; |
duke@435 | 79 | at(slot)->set_int(val); |
duke@435 | 80 | } |
duke@435 | 81 | |
duke@435 | 82 | void StackValueCollection::set_long_at(int slot, jlong value) { |
duke@435 | 83 | #ifdef _LP64 |
duke@435 | 84 | at(slot+1)->set_int(value); |
duke@435 | 85 | #else |
duke@435 | 86 | union { |
duke@435 | 87 | jlong jl; |
duke@435 | 88 | jint array[2]; |
duke@435 | 89 | } x; |
duke@435 | 90 | // Interpreter stack is reversed in memory: |
duke@435 | 91 | // low memory location is in higher java local slot. |
duke@435 | 92 | x.jl = value; |
duke@435 | 93 | at(slot+1)->set_int(x.array[0]); |
duke@435 | 94 | at(slot+0)->set_int(x.array[1]); |
duke@435 | 95 | #endif |
duke@435 | 96 | } |
duke@435 | 97 | |
duke@435 | 98 | void StackValueCollection::set_obj_at(int slot, Handle value) { |
duke@435 | 99 | at(slot)->set_obj(value); |
duke@435 | 100 | } |
duke@435 | 101 | |
duke@435 | 102 | void StackValueCollection::set_float_at(int slot, jfloat value) { |
duke@435 | 103 | #ifdef _LP64 |
duke@435 | 104 | union { |
duke@435 | 105 | intptr_t jd; |
duke@435 | 106 | jint array[2]; |
duke@435 | 107 | } val; |
duke@435 | 108 | // Interpreter stores 32 bit floats in first half of 64 bit word. |
duke@435 | 109 | val.array[0] = *(jint*)(&value); |
duke@435 | 110 | val.array[1] = 0; |
duke@435 | 111 | at(slot)->set_int(val.jd); |
duke@435 | 112 | #else |
duke@435 | 113 | at(slot)->set_int(*(jint*)(&value)); |
duke@435 | 114 | #endif |
duke@435 | 115 | } |
duke@435 | 116 | |
duke@435 | 117 | void StackValueCollection::set_double_at(int slot, jdouble value) { |
duke@435 | 118 | #ifdef _LP64 |
duke@435 | 119 | at(slot+1)->set_int(*(intptr_t*)(&value)); |
duke@435 | 120 | #else |
duke@435 | 121 | union { |
duke@435 | 122 | jdouble jd; |
duke@435 | 123 | jint array[2]; |
duke@435 | 124 | } x; |
duke@435 | 125 | // Interpreter stack is reversed in memory: |
duke@435 | 126 | // low memory location is in higher java local slot. |
duke@435 | 127 | x.jd = value; |
duke@435 | 128 | at(slot+1)->set_int(x.array[0]); |
duke@435 | 129 | at(slot+0)->set_int(x.array[1]); |
duke@435 | 130 | #endif |
duke@435 | 131 | } |
duke@435 | 132 | |
duke@435 | 133 | #ifndef PRODUCT |
duke@435 | 134 | void StackValueCollection::print() { |
duke@435 | 135 | for(int index = 0; index < size(); index++) { |
duke@435 | 136 | tty->print("\t %2d ", index); |
duke@435 | 137 | at(index)->print_on(tty); |
duke@435 | 138 | if( at(index )->type() == T_INT && |
duke@435 | 139 | index+1 < size() && |
duke@435 | 140 | at(index+1)->type() == T_INT ) { |
duke@435 | 141 | tty->print(" " INT64_FORMAT " (long)", long_at(index)); |
duke@435 | 142 | tty->cr(); |
duke@435 | 143 | tty->print("\t %.15e (double)", double_at(index)); |
duke@435 | 144 | tty->print(" " PTR64_FORMAT " (longhex)", long_at(index)); |
duke@435 | 145 | } |
duke@435 | 146 | tty->cr(); |
duke@435 | 147 | } |
duke@435 | 148 | } |
duke@435 | 149 | #endif |