hotspot/src/cpu/zero/vm/bytes_zero.hpp
author duke
Wed, 05 Jul 2017 20:10:48 +0200
changeset 27963 88d7c7c376e9
parent 10565 dc90c239f4ec
child 40010 e32d5e545789
permissions -rw-r--r--
Merge
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
4013
b154310845de 6890308: integrate zero assembler hotspot changes
never
parents:
diff changeset
     1
/*
7397
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 5547
diff changeset
     2
 * Copyright (c) 1997, 2010, Oracle and/or its affiliates. All rights reserved.
4013
b154310845de 6890308: integrate zero assembler hotspot changes
never
parents:
diff changeset
     3
 * Copyright 2007, 2008, 2009 Red Hat, Inc.
b154310845de 6890308: integrate zero assembler hotspot changes
never
parents:
diff changeset
     4
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
b154310845de 6890308: integrate zero assembler hotspot changes
never
parents:
diff changeset
     5
 *
b154310845de 6890308: integrate zero assembler hotspot changes
never
parents:
diff changeset
     6
 * This code is free software; you can redistribute it and/or modify it
b154310845de 6890308: integrate zero assembler hotspot changes
never
parents:
diff changeset
     7
 * under the terms of the GNU General Public License version 2 only, as
b154310845de 6890308: integrate zero assembler hotspot changes
never
parents:
diff changeset
     8
 * published by the Free Software Foundation.
b154310845de 6890308: integrate zero assembler hotspot changes
never
parents:
diff changeset
     9
 *
b154310845de 6890308: integrate zero assembler hotspot changes
never
parents:
diff changeset
    10
 * This code is distributed in the hope that it will be useful, but WITHOUT
b154310845de 6890308: integrate zero assembler hotspot changes
never
parents:
diff changeset
    11
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
b154310845de 6890308: integrate zero assembler hotspot changes
never
parents:
diff changeset
    12
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
b154310845de 6890308: integrate zero assembler hotspot changes
never
parents:
diff changeset
    13
 * version 2 for more details (a copy is included in the LICENSE file that
b154310845de 6890308: integrate zero assembler hotspot changes
never
parents:
diff changeset
    14
 * accompanied this code).
b154310845de 6890308: integrate zero assembler hotspot changes
never
parents:
diff changeset
    15
 *
b154310845de 6890308: integrate zero assembler hotspot changes
never
parents:
diff changeset
    16
 * You should have received a copy of the GNU General Public License version
b154310845de 6890308: integrate zero assembler hotspot changes
never
parents:
diff changeset
    17
 * 2 along with this work; if not, write to the Free Software Foundation,
b154310845de 6890308: integrate zero assembler hotspot changes
never
parents:
diff changeset
    18
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
b154310845de 6890308: integrate zero assembler hotspot changes
never
parents:
diff changeset
    19
 *
5547
f4b087cbb361 6941466: Oracle rebranding changes for Hotspot repositories
trims
parents: 4013
diff changeset
    20
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
f4b087cbb361 6941466: Oracle rebranding changes for Hotspot repositories
trims
parents: 4013
diff changeset
    21
 * or visit www.oracle.com if you need additional information or have any
f4b087cbb361 6941466: Oracle rebranding changes for Hotspot repositories
trims
parents: 4013
diff changeset
    22
 * questions.
4013
b154310845de 6890308: integrate zero assembler hotspot changes
never
parents:
diff changeset
    23
 *
b154310845de 6890308: integrate zero assembler hotspot changes
never
parents:
diff changeset
    24
 */
b154310845de 6890308: integrate zero assembler hotspot changes
never
parents:
diff changeset
    25
7397
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 5547
diff changeset
    26
#ifndef CPU_ZERO_VM_BYTES_ZERO_HPP
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 5547
diff changeset
    27
#define CPU_ZERO_VM_BYTES_ZERO_HPP
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 5547
diff changeset
    28
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 5547
diff changeset
    29
#include "memory/allocation.hpp"
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 5547
diff changeset
    30
4013
b154310845de 6890308: integrate zero assembler hotspot changes
never
parents:
diff changeset
    31
typedef union unaligned {
b154310845de 6890308: integrate zero assembler hotspot changes
never
parents:
diff changeset
    32
  u4 u;
b154310845de 6890308: integrate zero assembler hotspot changes
never
parents:
diff changeset
    33
  u2 us;
b154310845de 6890308: integrate zero assembler hotspot changes
never
parents:
diff changeset
    34
  u8 ul;
b154310845de 6890308: integrate zero assembler hotspot changes
never
parents:
diff changeset
    35
} __attribute__((packed)) unaligned;
b154310845de 6890308: integrate zero assembler hotspot changes
never
parents:
diff changeset
    36
b154310845de 6890308: integrate zero assembler hotspot changes
never
parents:
diff changeset
    37
class Bytes: AllStatic {
b154310845de 6890308: integrate zero assembler hotspot changes
never
parents:
diff changeset
    38
 public:
b154310845de 6890308: integrate zero assembler hotspot changes
never
parents:
diff changeset
    39
  // Returns true if the byte ordering used by Java is different
b154310845de 6890308: integrate zero assembler hotspot changes
never
parents:
diff changeset
    40
  // from the native byte ordering of the underlying machine.
b154310845de 6890308: integrate zero assembler hotspot changes
never
parents:
diff changeset
    41
  static inline bool is_Java_byte_ordering_different() {
b154310845de 6890308: integrate zero assembler hotspot changes
never
parents:
diff changeset
    42
#ifdef VM_LITTLE_ENDIAN
b154310845de 6890308: integrate zero assembler hotspot changes
never
parents:
diff changeset
    43
    return true;
b154310845de 6890308: integrate zero assembler hotspot changes
never
parents:
diff changeset
    44
#else
b154310845de 6890308: integrate zero assembler hotspot changes
never
parents:
diff changeset
    45
    return false;
b154310845de 6890308: integrate zero assembler hotspot changes
never
parents:
diff changeset
    46
#endif
b154310845de 6890308: integrate zero assembler hotspot changes
never
parents:
diff changeset
    47
  }
b154310845de 6890308: integrate zero assembler hotspot changes
never
parents:
diff changeset
    48
b154310845de 6890308: integrate zero assembler hotspot changes
never
parents:
diff changeset
    49
  // Efficient reading and writing of unaligned unsigned data in
b154310845de 6890308: integrate zero assembler hotspot changes
never
parents:
diff changeset
    50
  // platform-specific byte ordering.
b154310845de 6890308: integrate zero assembler hotspot changes
never
parents:
diff changeset
    51
  static inline u2 get_native_u2(address p){
b154310845de 6890308: integrate zero assembler hotspot changes
never
parents:
diff changeset
    52
    unaligned *up = (unaligned *) p;
b154310845de 6890308: integrate zero assembler hotspot changes
never
parents:
diff changeset
    53
    return up->us;
b154310845de 6890308: integrate zero assembler hotspot changes
never
parents:
diff changeset
    54
  }
b154310845de 6890308: integrate zero assembler hotspot changes
never
parents:
diff changeset
    55
b154310845de 6890308: integrate zero assembler hotspot changes
never
parents:
diff changeset
    56
  static inline u4 get_native_u4(address p) {
b154310845de 6890308: integrate zero assembler hotspot changes
never
parents:
diff changeset
    57
    unaligned *up = (unaligned *) p;
b154310845de 6890308: integrate zero assembler hotspot changes
never
parents:
diff changeset
    58
    return up->u;
b154310845de 6890308: integrate zero assembler hotspot changes
never
parents:
diff changeset
    59
  }
b154310845de 6890308: integrate zero assembler hotspot changes
never
parents:
diff changeset
    60
b154310845de 6890308: integrate zero assembler hotspot changes
never
parents:
diff changeset
    61
  static inline u8 get_native_u8(address p) {
b154310845de 6890308: integrate zero assembler hotspot changes
never
parents:
diff changeset
    62
    unaligned *up = (unaligned *) p;
b154310845de 6890308: integrate zero assembler hotspot changes
never
parents:
diff changeset
    63
    return up->ul;
b154310845de 6890308: integrate zero assembler hotspot changes
never
parents:
diff changeset
    64
  }
b154310845de 6890308: integrate zero assembler hotspot changes
never
parents:
diff changeset
    65
b154310845de 6890308: integrate zero assembler hotspot changes
never
parents:
diff changeset
    66
  static inline void put_native_u2(address p, u2 x) {
b154310845de 6890308: integrate zero assembler hotspot changes
never
parents:
diff changeset
    67
    unaligned *up = (unaligned *) p;
b154310845de 6890308: integrate zero assembler hotspot changes
never
parents:
diff changeset
    68
    up->us = x;
b154310845de 6890308: integrate zero assembler hotspot changes
never
parents:
diff changeset
    69
  }
b154310845de 6890308: integrate zero assembler hotspot changes
never
parents:
diff changeset
    70
b154310845de 6890308: integrate zero assembler hotspot changes
never
parents:
diff changeset
    71
  static inline void put_native_u4(address p, u4 x) {
b154310845de 6890308: integrate zero assembler hotspot changes
never
parents:
diff changeset
    72
    unaligned *up = (unaligned *) p;
b154310845de 6890308: integrate zero assembler hotspot changes
never
parents:
diff changeset
    73
    up->u = x;
b154310845de 6890308: integrate zero assembler hotspot changes
never
parents:
diff changeset
    74
  }
b154310845de 6890308: integrate zero assembler hotspot changes
never
parents:
diff changeset
    75
b154310845de 6890308: integrate zero assembler hotspot changes
never
parents:
diff changeset
    76
  static inline void put_native_u8(address p, u8 x) {
b154310845de 6890308: integrate zero assembler hotspot changes
never
parents:
diff changeset
    77
    unaligned *up = (unaligned *) p;
b154310845de 6890308: integrate zero assembler hotspot changes
never
parents:
diff changeset
    78
    up->ul = x;
b154310845de 6890308: integrate zero assembler hotspot changes
never
parents:
diff changeset
    79
  }
b154310845de 6890308: integrate zero assembler hotspot changes
never
parents:
diff changeset
    80
b154310845de 6890308: integrate zero assembler hotspot changes
never
parents:
diff changeset
    81
  // Efficient reading and writing of unaligned unsigned data in Java
b154310845de 6890308: integrate zero assembler hotspot changes
never
parents:
diff changeset
    82
  // byte ordering (i.e. big-endian ordering).
b154310845de 6890308: integrate zero assembler hotspot changes
never
parents:
diff changeset
    83
#ifdef VM_LITTLE_ENDIAN
b154310845de 6890308: integrate zero assembler hotspot changes
never
parents:
diff changeset
    84
  // Byte-order reversal is needed
b154310845de 6890308: integrate zero assembler hotspot changes
never
parents:
diff changeset
    85
  static inline u2 get_Java_u2(address p) {
b154310845de 6890308: integrate zero assembler hotspot changes
never
parents:
diff changeset
    86
    return (u2(p[0]) << 8) |
b154310845de 6890308: integrate zero assembler hotspot changes
never
parents:
diff changeset
    87
           (u2(p[1])     );
b154310845de 6890308: integrate zero assembler hotspot changes
never
parents:
diff changeset
    88
  }
b154310845de 6890308: integrate zero assembler hotspot changes
never
parents:
diff changeset
    89
  static inline u4 get_Java_u4(address p) {
b154310845de 6890308: integrate zero assembler hotspot changes
never
parents:
diff changeset
    90
    return (u4(p[0]) << 24) |
b154310845de 6890308: integrate zero assembler hotspot changes
never
parents:
diff changeset
    91
           (u4(p[1]) << 16) |
b154310845de 6890308: integrate zero assembler hotspot changes
never
parents:
diff changeset
    92
           (u4(p[2]) <<  8) |
b154310845de 6890308: integrate zero assembler hotspot changes
never
parents:
diff changeset
    93
           (u4(p[3])      );
b154310845de 6890308: integrate zero assembler hotspot changes
never
parents:
diff changeset
    94
  }
b154310845de 6890308: integrate zero assembler hotspot changes
never
parents:
diff changeset
    95
  static inline u8 get_Java_u8(address p) {
b154310845de 6890308: integrate zero assembler hotspot changes
never
parents:
diff changeset
    96
    u4 hi, lo;
b154310845de 6890308: integrate zero assembler hotspot changes
never
parents:
diff changeset
    97
    hi = (u4(p[0]) << 24) |
b154310845de 6890308: integrate zero assembler hotspot changes
never
parents:
diff changeset
    98
         (u4(p[1]) << 16) |
b154310845de 6890308: integrate zero assembler hotspot changes
never
parents:
diff changeset
    99
         (u4(p[2]) <<  8) |
b154310845de 6890308: integrate zero assembler hotspot changes
never
parents:
diff changeset
   100
         (u4(p[3])      );
b154310845de 6890308: integrate zero assembler hotspot changes
never
parents:
diff changeset
   101
    lo = (u4(p[4]) << 24) |
b154310845de 6890308: integrate zero assembler hotspot changes
never
parents:
diff changeset
   102
         (u4(p[5]) << 16) |
b154310845de 6890308: integrate zero assembler hotspot changes
never
parents:
diff changeset
   103
         (u4(p[6]) <<  8) |
b154310845de 6890308: integrate zero assembler hotspot changes
never
parents:
diff changeset
   104
         (u4(p[7])      );
b154310845de 6890308: integrate zero assembler hotspot changes
never
parents:
diff changeset
   105
    return u8(lo) | (u8(hi) << 32);
b154310845de 6890308: integrate zero assembler hotspot changes
never
parents:
diff changeset
   106
  }
b154310845de 6890308: integrate zero assembler hotspot changes
never
parents:
diff changeset
   107
b154310845de 6890308: integrate zero assembler hotspot changes
never
parents:
diff changeset
   108
  static inline void put_Java_u2(address p, u2 x) {
b154310845de 6890308: integrate zero assembler hotspot changes
never
parents:
diff changeset
   109
    p[0] = x >> 8;
b154310845de 6890308: integrate zero assembler hotspot changes
never
parents:
diff changeset
   110
    p[1] = x;
b154310845de 6890308: integrate zero assembler hotspot changes
never
parents:
diff changeset
   111
  }
b154310845de 6890308: integrate zero assembler hotspot changes
never
parents:
diff changeset
   112
  static inline void put_Java_u4(address p, u4 x) {
b154310845de 6890308: integrate zero assembler hotspot changes
never
parents:
diff changeset
   113
    p[0] = x >> 24;
b154310845de 6890308: integrate zero assembler hotspot changes
never
parents:
diff changeset
   114
    p[1] = x >> 16;
b154310845de 6890308: integrate zero assembler hotspot changes
never
parents:
diff changeset
   115
    p[2] = x >> 8;
b154310845de 6890308: integrate zero assembler hotspot changes
never
parents:
diff changeset
   116
    p[3] = x;
b154310845de 6890308: integrate zero assembler hotspot changes
never
parents:
diff changeset
   117
  }
b154310845de 6890308: integrate zero assembler hotspot changes
never
parents:
diff changeset
   118
  static inline void put_Java_u8(address p, u8 x) {
b154310845de 6890308: integrate zero assembler hotspot changes
never
parents:
diff changeset
   119
    u4 hi, lo;
b154310845de 6890308: integrate zero assembler hotspot changes
never
parents:
diff changeset
   120
    lo = x;
b154310845de 6890308: integrate zero assembler hotspot changes
never
parents:
diff changeset
   121
    hi = x >> 32;
b154310845de 6890308: integrate zero assembler hotspot changes
never
parents:
diff changeset
   122
    p[0] = hi >> 24;
b154310845de 6890308: integrate zero assembler hotspot changes
never
parents:
diff changeset
   123
    p[1] = hi >> 16;
b154310845de 6890308: integrate zero assembler hotspot changes
never
parents:
diff changeset
   124
    p[2] = hi >> 8;
b154310845de 6890308: integrate zero assembler hotspot changes
never
parents:
diff changeset
   125
    p[3] = hi;
b154310845de 6890308: integrate zero assembler hotspot changes
never
parents:
diff changeset
   126
    p[4] = lo >> 24;
b154310845de 6890308: integrate zero assembler hotspot changes
never
parents:
diff changeset
   127
    p[5] = lo >> 16;
b154310845de 6890308: integrate zero assembler hotspot changes
never
parents:
diff changeset
   128
    p[6] = lo >> 8;
b154310845de 6890308: integrate zero assembler hotspot changes
never
parents:
diff changeset
   129
    p[7] = lo;
b154310845de 6890308: integrate zero assembler hotspot changes
never
parents:
diff changeset
   130
  }
b154310845de 6890308: integrate zero assembler hotspot changes
never
parents:
diff changeset
   131
b154310845de 6890308: integrate zero assembler hotspot changes
never
parents:
diff changeset
   132
  // Efficient swapping of byte ordering
b154310845de 6890308: integrate zero assembler hotspot changes
never
parents:
diff changeset
   133
  static inline u2 swap_u2(u2 x);
b154310845de 6890308: integrate zero assembler hotspot changes
never
parents:
diff changeset
   134
  static inline u4 swap_u4(u4 x);
b154310845de 6890308: integrate zero assembler hotspot changes
never
parents:
diff changeset
   135
  static inline u8 swap_u8(u8 x);
b154310845de 6890308: integrate zero assembler hotspot changes
never
parents:
diff changeset
   136
#else
b154310845de 6890308: integrate zero assembler hotspot changes
never
parents:
diff changeset
   137
  // No byte-order reversal is needed
b154310845de 6890308: integrate zero assembler hotspot changes
never
parents:
diff changeset
   138
  static inline u2 get_Java_u2(address p) {
b154310845de 6890308: integrate zero assembler hotspot changes
never
parents:
diff changeset
   139
    return get_native_u2(p);
b154310845de 6890308: integrate zero assembler hotspot changes
never
parents:
diff changeset
   140
  }
b154310845de 6890308: integrate zero assembler hotspot changes
never
parents:
diff changeset
   141
  static inline u4 get_Java_u4(address p) {
b154310845de 6890308: integrate zero assembler hotspot changes
never
parents:
diff changeset
   142
    return get_native_u4(p);
b154310845de 6890308: integrate zero assembler hotspot changes
never
parents:
diff changeset
   143
  }
b154310845de 6890308: integrate zero assembler hotspot changes
never
parents:
diff changeset
   144
  static inline u8 get_Java_u8(address p) {
b154310845de 6890308: integrate zero assembler hotspot changes
never
parents:
diff changeset
   145
    return get_native_u8(p);
b154310845de 6890308: integrate zero assembler hotspot changes
never
parents:
diff changeset
   146
  }
b154310845de 6890308: integrate zero assembler hotspot changes
never
parents:
diff changeset
   147
b154310845de 6890308: integrate zero assembler hotspot changes
never
parents:
diff changeset
   148
  static inline void put_Java_u2(address p, u2 x) {
b154310845de 6890308: integrate zero assembler hotspot changes
never
parents:
diff changeset
   149
    put_native_u2(p, x);
b154310845de 6890308: integrate zero assembler hotspot changes
never
parents:
diff changeset
   150
  }
b154310845de 6890308: integrate zero assembler hotspot changes
never
parents:
diff changeset
   151
  static inline void put_Java_u4(address p, u4 x) {
b154310845de 6890308: integrate zero assembler hotspot changes
never
parents:
diff changeset
   152
    put_native_u4(p, x);
b154310845de 6890308: integrate zero assembler hotspot changes
never
parents:
diff changeset
   153
  }
b154310845de 6890308: integrate zero assembler hotspot changes
never
parents:
diff changeset
   154
  static inline void put_Java_u8(address p, u8 x) {
b154310845de 6890308: integrate zero assembler hotspot changes
never
parents:
diff changeset
   155
    put_native_u8(p, x);
b154310845de 6890308: integrate zero assembler hotspot changes
never
parents:
diff changeset
   156
  }
b154310845de 6890308: integrate zero assembler hotspot changes
never
parents:
diff changeset
   157
b154310845de 6890308: integrate zero assembler hotspot changes
never
parents:
diff changeset
   158
  // No byte-order reversal is needed
b154310845de 6890308: integrate zero assembler hotspot changes
never
parents:
diff changeset
   159
  static inline u2 swap_u2(u2 x) { return x; }
b154310845de 6890308: integrate zero assembler hotspot changes
never
parents:
diff changeset
   160
  static inline u4 swap_u4(u4 x) { return x; }
b154310845de 6890308: integrate zero assembler hotspot changes
never
parents:
diff changeset
   161
  static inline u8 swap_u8(u8 x) { return x; }
b154310845de 6890308: integrate zero assembler hotspot changes
never
parents:
diff changeset
   162
#endif // VM_LITTLE_ENDIAN
b154310845de 6890308: integrate zero assembler hotspot changes
never
parents:
diff changeset
   163
};
b154310845de 6890308: integrate zero assembler hotspot changes
never
parents:
diff changeset
   164
b154310845de 6890308: integrate zero assembler hotspot changes
never
parents:
diff changeset
   165
#ifdef VM_LITTLE_ENDIAN
b154310845de 6890308: integrate zero assembler hotspot changes
never
parents:
diff changeset
   166
// The following header contains the implementations of swap_u2,
b154310845de 6890308: integrate zero assembler hotspot changes
never
parents:
diff changeset
   167
// swap_u4, and swap_u8
7397
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 5547
diff changeset
   168
#ifdef TARGET_OS_ARCH_linux_zero
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 5547
diff changeset
   169
# include "bytes_linux_zero.inline.hpp"
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 5547
diff changeset
   170
#endif
10565
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents: 7397
diff changeset
   171
#ifdef TARGET_OS_ARCH_bsd_zero
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents: 7397
diff changeset
   172
# include "bytes_bsd_zero.inline.hpp"
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents: 7397
diff changeset
   173
#endif
7397
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 5547
diff changeset
   174
4013
b154310845de 6890308: integrate zero assembler hotspot changes
never
parents:
diff changeset
   175
#endif // VM_LITTLE_ENDIAN
7397
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 5547
diff changeset
   176
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 5547
diff changeset
   177
#endif // CPU_ZERO_VM_BYTES_ZERO_HPP