src/cpu/sparc/vm/bytes_sparc.hpp

changeset 0
f90c822e73f8
child 6876
710a3c8b516e
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/src/cpu/sparc/vm/bytes_sparc.hpp	Wed Apr 27 01:25:04 2016 +0800
     1.3 @@ -0,0 +1,164 @@
     1.4 +/*
     1.5 + * Copyright (c) 1997, 2010, Oracle and/or its affiliates. All rights reserved.
     1.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
     1.7 + *
     1.8 + * This code is free software; you can redistribute it and/or modify it
     1.9 + * under the terms of the GNU General Public License version 2 only, as
    1.10 + * published by the Free Software Foundation.
    1.11 + *
    1.12 + * This code is distributed in the hope that it will be useful, but WITHOUT
    1.13 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
    1.14 + * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
    1.15 + * version 2 for more details (a copy is included in the LICENSE file that
    1.16 + * accompanied this code).
    1.17 + *
    1.18 + * You should have received a copy of the GNU General Public License version
    1.19 + * 2 along with this work; if not, write to the Free Software Foundation,
    1.20 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
    1.21 + *
    1.22 + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
    1.23 + * or visit www.oracle.com if you need additional information or have any
    1.24 + * questions.
    1.25 + *
    1.26 + */
    1.27 +
    1.28 +#ifndef CPU_SPARC_VM_BYTES_SPARC_HPP
    1.29 +#define CPU_SPARC_VM_BYTES_SPARC_HPP
    1.30 +
    1.31 +#include "memory/allocation.hpp"
    1.32 +
    1.33 +class Bytes: AllStatic {
    1.34 + public:
    1.35 +  // Efficient reading and writing of unaligned unsigned data in platform-specific byte ordering
    1.36 +  // Sparc needs to check for alignment.
    1.37 +
    1.38 +  // can I count on address always being a pointer to an unsigned char? Yes
    1.39 +
    1.40 +  // Returns true, if the byte ordering used by Java is different from the nativ byte ordering
    1.41 +  // of the underlying machine. For example, true for Intel x86, False, for Solaris on Sparc.
    1.42 +  static inline bool is_Java_byte_ordering_different() { return false; }
    1.43 +
    1.44 +  // Thus, a swap between native and Java ordering is always a no-op:
    1.45 +  static inline u2   swap_u2(u2 x)  { return x; }
    1.46 +  static inline u4   swap_u4(u4 x)  { return x; }
    1.47 +  static inline u8   swap_u8(u8 x)  { return x; }
    1.48 +
    1.49 +  static inline u2   get_native_u2(address p){
    1.50 +    return (intptr_t(p) & 1) == 0
    1.51 +             ?   *(u2*)p
    1.52 +             :   ( u2(p[0]) << 8 )
    1.53 +               | ( u2(p[1])      );
    1.54 +  }
    1.55 +
    1.56 +  static inline u4   get_native_u4(address p) {
    1.57 +    switch (intptr_t(p) & 3) {
    1.58 +     case 0:  return *(u4*)p;
    1.59 +
    1.60 +     case 2:  return (  u4( ((u2*)p)[0] ) << 16  )
    1.61 +                   | (  u4( ((u2*)p)[1] )                  );
    1.62 +
    1.63 +    default:  return ( u4(p[0]) << 24 )
    1.64 +                   | ( u4(p[1]) << 16 )
    1.65 +                   | ( u4(p[2]) <<  8 )
    1.66 +                   |   u4(p[3]);
    1.67 +    }
    1.68 +  }
    1.69 +
    1.70 +  static inline u8   get_native_u8(address p) {
    1.71 +    switch (intptr_t(p) & 7) {
    1.72 +      case 0:  return *(u8*)p;
    1.73 +
    1.74 +      case 4:  return (  u8( ((u4*)p)[0] ) << 32  )
    1.75 +                    | (  u8( ((u4*)p)[1] )        );
    1.76 +
    1.77 +      case 2:  return (  u8( ((u2*)p)[0] ) << 48  )
    1.78 +                    | (  u8( ((u2*)p)[1] ) << 32  )
    1.79 +                    | (  u8( ((u2*)p)[2] ) << 16  )
    1.80 +                    | (  u8( ((u2*)p)[3] )        );
    1.81 +
    1.82 +     default:  return ( u8(p[0]) << 56 )
    1.83 +                    | ( u8(p[1]) << 48 )
    1.84 +                    | ( u8(p[2]) << 40 )
    1.85 +                    | ( u8(p[3]) << 32 )
    1.86 +                    | ( u8(p[4]) << 24 )
    1.87 +                    | ( u8(p[5]) << 16 )
    1.88 +                    | ( u8(p[6]) <<  8 )
    1.89 +                    |   u8(p[7]);
    1.90 +    }
    1.91 +  }
    1.92 +
    1.93 +
    1.94 +
    1.95 +  static inline void put_native_u2(address p, u2 x)   {
    1.96 +    if ( (intptr_t(p) & 1) == 0 )  *(u2*)p = x;
    1.97 +    else {
    1.98 +      p[0] = x >> 8;
    1.99 +      p[1] = x;
   1.100 +    }
   1.101 +  }
   1.102 +
   1.103 +  static inline void put_native_u4(address p, u4 x) {
   1.104 +    switch ( intptr_t(p) & 3 ) {
   1.105 +    case 0:  *(u4*)p = x;
   1.106 +              break;
   1.107 +
   1.108 +    case 2:  ((u2*)p)[0] = x >> 16;
   1.109 +             ((u2*)p)[1] = x;
   1.110 +             break;
   1.111 +
   1.112 +    default: ((u1*)p)[0] = x >> 24;
   1.113 +             ((u1*)p)[1] = x >> 16;
   1.114 +             ((u1*)p)[2] = x >>  8;
   1.115 +             ((u1*)p)[3] = x;
   1.116 +             break;
   1.117 +    }
   1.118 +  }
   1.119 +
   1.120 +  static inline void put_native_u8(address p, u8 x) {
   1.121 +    switch ( intptr_t(p) & 7 ) {
   1.122 +    case 0:  *(u8*)p = x;
   1.123 +             break;
   1.124 +
   1.125 +    case 4:  ((u4*)p)[0] = x >> 32;
   1.126 +             ((u4*)p)[1] = x;
   1.127 +             break;
   1.128 +
   1.129 +    case 2:  ((u2*)p)[0] = x >> 48;
   1.130 +             ((u2*)p)[1] = x >> 32;
   1.131 +             ((u2*)p)[2] = x >> 16;
   1.132 +             ((u2*)p)[3] = x;
   1.133 +             break;
   1.134 +
   1.135 +    default: ((u1*)p)[0] = x >> 56;
   1.136 +             ((u1*)p)[1] = x >> 48;
   1.137 +             ((u1*)p)[2] = x >> 40;
   1.138 +             ((u1*)p)[3] = x >> 32;
   1.139 +             ((u1*)p)[4] = x >> 24;
   1.140 +             ((u1*)p)[5] = x >> 16;
   1.141 +             ((u1*)p)[6] = x >>  8;
   1.142 +             ((u1*)p)[7] = x;
   1.143 +    }
   1.144 +  }
   1.145 +
   1.146 +
   1.147 +  // Efficient reading and writing of unaligned unsigned data in Java byte ordering (i.e. big-endian ordering)
   1.148 +  // (no byte-order reversal is needed since SPARC CPUs are big-endian oriented)
   1.149 +  static inline u2   get_Java_u2(address p) { return get_native_u2(p); }
   1.150 +  static inline u4   get_Java_u4(address p) { return get_native_u4(p); }
   1.151 +  static inline u8   get_Java_u8(address p) { return get_native_u8(p); }
   1.152 +
   1.153 +  static inline void put_Java_u2(address p, u2 x)     { put_native_u2(p, x); }
   1.154 +  static inline void put_Java_u4(address p, u4 x)     { put_native_u4(p, x); }
   1.155 +  static inline void put_Java_u8(address p, u8 x)     { put_native_u8(p, x); }
   1.156 +};
   1.157 +
   1.158 +//Reconciliation History
   1.159 +// 1.7 98/02/24 10:18:41 bytes_i486.hpp
   1.160 +// 1.10 98/04/08 18:47:57 bytes_i486.hpp
   1.161 +// 1.13 98/07/15 17:10:03 bytes_i486.hpp
   1.162 +// 1.14 98/08/13 10:38:23 bytes_i486.hpp
   1.163 +// 1.15 98/10/05 16:30:21 bytes_i486.hpp
   1.164 +// 1.17 99/06/22 16:37:35 bytes_i486.hpp
   1.165 +//End
   1.166 +
   1.167 +#endif // CPU_SPARC_VM_BYTES_SPARC_HPP

mercurial