src/cpu/x86/vm/bytes_x86.hpp

changeset 435
a61af66fc99e
child 1907
c18cbe5936b8
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/src/cpu/x86/vm/bytes_x86.hpp	Sat Dec 01 00:00:00 2007 +0000
     1.3 @@ -0,0 +1,70 @@
     1.4 +/*
     1.5 + * Copyright 1997-2001 Sun Microsystems, Inc.  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 Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
    1.23 + * CA 95054 USA or visit www.sun.com if you need additional information or
    1.24 + * have any questions.
    1.25 + *
    1.26 + */
    1.27 +
    1.28 +class Bytes: AllStatic {
    1.29 + private:
    1.30 +#ifndef AMD64
    1.31 +  // Helper function for swap_u8
    1.32 +  static inline u8   swap_u8_base(u4 x, u4 y);        // compiler-dependent implementation
    1.33 +#endif // AMD64
    1.34 +
    1.35 + public:
    1.36 +  // Returns true if the byte ordering used by Java is different from the native byte ordering
    1.37 +  // of the underlying machine. For example, this is true for Intel x86, but false for Solaris
    1.38 +  // on Sparc.
    1.39 +  static inline bool is_Java_byte_ordering_different(){ return true; }
    1.40 +
    1.41 +
    1.42 +  // Efficient reading and writing of unaligned unsigned data in platform-specific byte ordering
    1.43 +  // (no special code is needed since x86 CPUs can access unaligned data)
    1.44 +  static inline u2   get_native_u2(address p)         { return *(u2*)p; }
    1.45 +  static inline u4   get_native_u4(address p)         { return *(u4*)p; }
    1.46 +  static inline u8   get_native_u8(address p)         { return *(u8*)p; }
    1.47 +
    1.48 +  static inline void put_native_u2(address p, u2 x)   { *(u2*)p = x; }
    1.49 +  static inline void put_native_u4(address p, u4 x)   { *(u4*)p = x; }
    1.50 +  static inline void put_native_u8(address p, u8 x)   { *(u8*)p = x; }
    1.51 +
    1.52 +
    1.53 +  // Efficient reading and writing of unaligned unsigned data in Java
    1.54 +  // byte ordering (i.e. big-endian ordering). Byte-order reversal is
    1.55 +  // needed since x86 CPUs use little-endian format.
    1.56 +  static inline u2   get_Java_u2(address p)           { return swap_u2(get_native_u2(p)); }
    1.57 +  static inline u4   get_Java_u4(address p)           { return swap_u4(get_native_u4(p)); }
    1.58 +  static inline u8   get_Java_u8(address p)           { return swap_u8(get_native_u8(p)); }
    1.59 +
    1.60 +  static inline void put_Java_u2(address p, u2 x)     { put_native_u2(p, swap_u2(x)); }
    1.61 +  static inline void put_Java_u4(address p, u4 x)     { put_native_u4(p, swap_u4(x)); }
    1.62 +  static inline void put_Java_u8(address p, u8 x)     { put_native_u8(p, swap_u8(x)); }
    1.63 +
    1.64 +
    1.65 +  // Efficient swapping of byte ordering
    1.66 +  static inline u2   swap_u2(u2 x);                   // compiler-dependent implementation
    1.67 +  static inline u4   swap_u4(u4 x);                   // compiler-dependent implementation
    1.68 +  static inline u8   swap_u8(u8 x);
    1.69 +};
    1.70 +
    1.71 +
    1.72 +// The following header contains the implementations of swap_u2, swap_u4, and swap_u8[_base]
    1.73 +#include "incls/_bytes_pd.inline.hpp.incl"

mercurial