src/cpu/mips/vm/bytes_mips.hpp

Thu, 07 Sep 2017 09:12:16 +0800

author
aoqi
date
Thu, 07 Sep 2017 09:12:16 +0800
changeset 6880
52ea28d233d2
parent 6
fbd9470e188d
child 9228
617b86d17edb
permissions
-rw-r--r--

#5745 [Code Reorganization] code cleanup and code style fix
This is a huge patch, but only code cleanup, code style fix and useless code deletion are included, for example:
tab -> two spaces, deleted spacees at the end of a line, delete useless comments.

This patch also included:
Declaration and definition of class MacroAssembler is moved from assembler_mips.h/cpp to macroAssembler_mips.h/cpp

aoqi@1 1 /*
aoqi@1 2 * Copyright (c) 1997, 2010, Oracle and/or its affiliates. All rights reserved.
aoqi@1 3 * Copyright (c) 2015, 2016, Loongson Technology. All rights reserved.
aoqi@1 4 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
aoqi@1 5 *
aoqi@1 6 * This code is free software; you can redistribute it and/or modify it
aoqi@1 7 * under the terms of the GNU General Public License version 2 only, as
aoqi@1 8 * published by the Free Software Foundation.
aoqi@1 9 *
aoqi@1 10 * This code is distributed in the hope that it will be useful, but WITHOUT
aoqi@1 11 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
aoqi@1 12 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
aoqi@1 13 * version 2 for more details (a copy is included in the LICENSE file that
aoqi@1 14 * accompanied this code).
aoqi@1 15 *
aoqi@1 16 * You should have received a copy of the GNU General Public License version
aoqi@1 17 * 2 along with this work; if not, write to the Free Software Foundation,
aoqi@1 18 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
aoqi@1 19 *
aoqi@1 20 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
aoqi@1 21 * or visit www.oracle.com if you need additional information or have any
aoqi@1 22 * questions.
aoqi@1 23 *
aoqi@1 24 */
aoqi@1 25
aoqi@1 26 #ifndef CPU_MIPS_VM_BYTES_MIPS_HPP
aoqi@1 27 #define CPU_MIPS_VM_BYTES_MIPS_HPP
aoqi@1 28
aoqi@1 29 #include "memory/allocation.hpp"
aoqi@1 30
aoqi@1 31 class Bytes: AllStatic {
aoqi@6880 32 private:
aoqi@6880 33 // Helper function for swap_u8, not used in Loongson.
aoqi@6880 34 static inline u8 swap_u8_base(u4 x, u4 y) {} // compiler-dependent implementation
aoqi@1 35
aoqi@6880 36 public:
aoqi@6880 37 // Returns true if the byte ordering used by Java is different from the native byte ordering
aoqi@6880 38 // of the underlying machine. For example, this is true for Intel x86, but false for Solaris
aoqi@6880 39 // on Sparc.
aoqi@6880 40 // we use mipsel, so return true
aoqi@6880 41 static inline bool is_Java_byte_ordering_different(){ return true; }
aoqi@1 42
aoqi@1 43
aoqi@6880 44 // Efficient reading and writing of unaligned unsigned data in platform-specific byte ordering
aoqi@6880 45 // (no special code is needed since x86 CPUs can access unaligned data)
aoqi@6880 46 static inline u2 get_native_u2(address p) {
aoqi@6880 47 if ((intptr_t)p & 0x1) {
aoqi@6880 48 return ((u2)p[1] << 8) | (u2)p[0];
aoqi@6880 49 } else {
aoqi@6880 50 return *(u2*)p;
aoqi@6880 51 }
aoqi@6880 52 }
aoqi@1 53
aoqi@6880 54 static inline u4 get_native_u4(address p) {
aoqi@6880 55 if ((intptr_t)p & 3) {
aoqi@6880 56 u4 res;
aoqi@6880 57 __asm__ __volatile__ (
aoqi@6880 58 " .set push\n"
aoqi@6880 59 " .set mips64\n"
aoqi@6880 60 " .set noreorder\n"
aoqi@1 61
aoqi@6880 62 " lwr %[res], 0(%[addr]) \n"
aoqi@6880 63 " lwl %[res], 3(%[addr]) \n"
aoqi@1 64
aoqi@6880 65 " .set pop"
aoqi@6880 66 : [res] "=&r" (res)
aoqi@6880 67 : [addr] "r" (p)
aoqi@6880 68 : "memory"
aoqi@6880 69 );
aoqi@6880 70 return res;
aoqi@6880 71 } else {
aoqi@6880 72 return *(u4*)p;
aoqi@6880 73 }
aoqi@6880 74 }
aoqi@1 75
aoqi@6880 76 static inline u8 get_native_u8(address p) {
aoqi@6880 77 u8 res;
aoqi@6880 78 u8 temp;
aoqi@6880 79 // u4 tp;//tmp register
aoqi@6880 80 __asm__ __volatile__ (
aoqi@6880 81 " .set push\n"
aoqi@6880 82 " .set mips64\n"
aoqi@6880 83 " .set noreorder\n"
aoqi@6880 84 " .set noat\n"
aoqi@6880 85 " andi $1,%[addr],0x7 \n"
aoqi@6880 86 " beqz $1,1f \n"
aoqi@6880 87 " nop \n"
aoqi@6880 88 " ldr %[temp], 0(%[addr]) \n"
aoqi@6880 89 " ldl %[temp], 7(%[addr]) \n"
aoqi@6880 90 " b 2f \n"
aoqi@6880 91 " nop \n"
aoqi@6880 92 " 1:\t ld %[temp],0(%[addr]) \n"
aoqi@6880 93 " 2:\t sd %[temp], %[res] \n"
aoqi@1 94
aoqi@6880 95 " .set at\n"
aoqi@6880 96 " .set pop\n"
aoqi@6880 97 : [addr]"=r"(p), [temp]"=r" (temp)
aoqi@6880 98 : "[addr]"(p), "[temp]" (temp), [res]"m" (*(volatile jint*)&res)
aoqi@6880 99 : "memory"
aoqi@6880 100 );
aoqi@1 101
aoqi@6880 102 return res;
aoqi@6880 103 }
aoqi@6880 104 //use mips unaligned load instructions
aoqi@6880 105 static inline void put_native_u2(address p, u2 x) {
aoqi@6880 106 if((intptr_t)p & 0x1) {
aoqi@6880 107 p[0] = (u_char)(x);
aoqi@6880 108 p[1] = (u_char)(x>>8);
aoqi@6880 109 } else {
aoqi@6880 110 *(u2*)p = x;
aoqi@6880 111 }
aoqi@6880 112 }
aoqi@6880 113 static inline void put_native_u4(address p, u4 x) {
aoqi@6880 114 /* 2016/5/8 Jin: refer to sparc implementation.
aoqi@6880 115 Note that sparc is big-endian, while mips is little-endian */
aoqi@6880 116 switch ( intptr_t(p) & 3 ) {
aoqi@6880 117 case 0: *(u4*)p = x;
aoqi@6880 118 break;
Jin@6 119
aoqi@6880 120 case 2: ((u2*)p)[1] = x >> 16;
aoqi@6880 121 ((u2*)p)[0] = x;
aoqi@6880 122 break;
Jin@6 123
aoqi@6880 124 default: ((u1*)p)[3] = x >> 24;
aoqi@6880 125 ((u1*)p)[2] = x >> 16;
aoqi@6880 126 ((u1*)p)[1] = x >> 8;
aoqi@6880 127 ((u1*)p)[0] = x;
aoqi@6880 128 break;
aoqi@6880 129 }
aoqi@6880 130 }
aoqi@6880 131 static inline void put_native_u8(address p, u8 x) {
aoqi@6880 132 /* 2016/5/8 Jin: refer to sparc implementation.
aoqi@6880 133 Note that sparc is big-endian, while mips is little-endian */
aoqi@6880 134 switch ( intptr_t(p) & 7 ) {
aoqi@6880 135 case 0: *(u8*)p = x;
aoqi@6880 136 break;
aoqi@1 137
aoqi@6880 138 case 4: ((u4*)p)[1] = x >> 32;
aoqi@6880 139 ((u4*)p)[0] = x;
aoqi@6880 140 break;
aoqi@1 141
aoqi@6880 142 case 2: ((u2*)p)[3] = x >> 48;
aoqi@6880 143 ((u2*)p)[2] = x >> 32;
aoqi@6880 144 ((u2*)p)[1] = x >> 16;
aoqi@6880 145 ((u2*)p)[0] = x;
aoqi@6880 146 break;
Jin@6 147
aoqi@6880 148 default: ((u1*)p)[7] = x >> 56;
aoqi@6880 149 ((u1*)p)[6] = x >> 48;
aoqi@6880 150 ((u1*)p)[5] = x >> 40;
aoqi@6880 151 ((u1*)p)[4] = x >> 32;
aoqi@6880 152 ((u1*)p)[3] = x >> 24;
aoqi@6880 153 ((u1*)p)[2] = x >> 16;
aoqi@6880 154 ((u1*)p)[1] = x >> 8;
aoqi@6880 155 ((u1*)p)[0] = x;
aoqi@6880 156 }
aoqi@6880 157 }
Jin@6 158
Jin@6 159
aoqi@6880 160 // Efficient reading and writing of unaligned unsigned data in Java
aoqi@6880 161 // byte ordering (i.e. big-endian ordering). Byte-order reversal is
aoqi@6880 162 // needed since x86 CPUs use little-endian format.
aoqi@6880 163 static inline u2 get_Java_u2(address p) { return swap_u2(get_native_u2(p)); }
aoqi@6880 164 static inline u4 get_Java_u4(address p) { return swap_u4(get_native_u4(p)); }
aoqi@6880 165 static inline u8 get_Java_u8(address p) { return swap_u8(get_native_u8(p)); }
aoqi@1 166
aoqi@6880 167 static inline void put_Java_u2(address p, u2 x) { put_native_u2(p, swap_u2(x)); }
aoqi@6880 168 static inline void put_Java_u4(address p, u4 x) { put_native_u4(p, swap_u4(x)); }
aoqi@6880 169 static inline void put_Java_u8(address p, u8 x) { put_native_u8(p, swap_u8(x)); }
aoqi@1 170
aoqi@1 171
aoqi@6880 172 // Efficient swapping of byte ordering
aoqi@6880 173 static inline u2 swap_u2(u2 x); // compiler-dependent implementation
aoqi@6880 174 static inline u4 swap_u4(u4 x); // compiler-dependent implementation
aoqi@6880 175 static inline u8 swap_u8(u8 x);
aoqi@1 176 };
aoqi@1 177
aoqi@1 178
aoqi@1 179 // The following header contains the implementations of swap_u2, swap_u4, and swap_u8[_base]
aoqi@1 180 #ifdef TARGET_OS_ARCH_linux_mips
aoqi@1 181 # include "bytes_linux_mips.inline.hpp"
aoqi@1 182 #endif
aoqi@1 183 #ifdef TARGET_OS_ARCH_solaris_mips
aoqi@1 184 # include "bytes_solaris_mips.inline.hpp"
aoqi@1 185 #endif
aoqi@1 186 #ifdef TARGET_OS_ARCH_windows_mips
aoqi@1 187 # include "bytes_windows_mips.inline.hpp"
aoqi@1 188 #endif
aoqi@1 189 #ifdef TARGET_OS_ARCH_bsd_mips
aoqi@1 190 # include "bytes_bsd_mips.inline.hpp"
aoqi@1 191 #endif
aoqi@1 192
aoqi@1 193
aoqi@1 194 #endif // CPU_MIPS_VM_BYTES_MIPS_HPP

mercurial