src/hotspot/cpu/zero/bytes_zero.hpp
author stefank
Thu, 09 May 2019 14:28:30 +0200
changeset 54786 ebf733a324d4
parent 53244 9807daeb47c4
permissions -rw-r--r--
8223624: Cleanup includes of universe.hpp Reviewed-by: coleenp, lkorinth
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
4013
b154310845de 6890308: integrate zero assembler hotspot changes
never
parents:
diff changeset
     1
/*
53244
9807daeb47c4 8216167: Update include guards to reflect correct directories
coleenp
parents: 47216
diff changeset
     2
 * Copyright (c) 1997, 2019, 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
53244
9807daeb47c4 8216167: Update include guards to reflect correct directories
coleenp
parents: 47216
diff changeset
    26
#ifndef CPU_ZERO_BYTES_ZERO_HPP
9807daeb47c4 8216167: Update include guards to reflect correct directories
coleenp
parents: 47216
diff changeset
    27
#define CPU_ZERO_BYTES_ZERO_HPP
7397
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
  // Efficient reading and writing of unaligned unsigned data in
b154310845de 6890308: integrate zero assembler hotspot changes
never
parents:
diff changeset
    40
  // platform-specific byte ordering.
b154310845de 6890308: integrate zero assembler hotspot changes
never
parents:
diff changeset
    41
  static inline u2 get_native_u2(address p){
b154310845de 6890308: integrate zero assembler hotspot changes
never
parents:
diff changeset
    42
    unaligned *up = (unaligned *) p;
b154310845de 6890308: integrate zero assembler hotspot changes
never
parents:
diff changeset
    43
    return up->us;
b154310845de 6890308: integrate zero assembler hotspot changes
never
parents:
diff changeset
    44
  }
b154310845de 6890308: integrate zero assembler hotspot changes
never
parents:
diff changeset
    45
b154310845de 6890308: integrate zero assembler hotspot changes
never
parents:
diff changeset
    46
  static inline u4 get_native_u4(address p) {
b154310845de 6890308: integrate zero assembler hotspot changes
never
parents:
diff changeset
    47
    unaligned *up = (unaligned *) p;
b154310845de 6890308: integrate zero assembler hotspot changes
never
parents:
diff changeset
    48
    return up->u;
b154310845de 6890308: integrate zero assembler hotspot changes
never
parents:
diff changeset
    49
  }
b154310845de 6890308: integrate zero assembler hotspot changes
never
parents:
diff changeset
    50
b154310845de 6890308: integrate zero assembler hotspot changes
never
parents:
diff changeset
    51
  static inline u8 get_native_u8(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->ul;
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 void put_native_u2(address p, u2 x) {
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
    up->us = x;
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 void put_native_u4(address p, u4 x) {
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
    up->u = x;
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_u8(address p, u8 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->ul = 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
  // Efficient reading and writing of unaligned unsigned data in Java
b154310845de 6890308: integrate zero assembler hotspot changes
never
parents:
diff changeset
    72
  // byte ordering (i.e. big-endian ordering).
b154310845de 6890308: integrate zero assembler hotspot changes
never
parents:
diff changeset
    73
#ifdef VM_LITTLE_ENDIAN
b154310845de 6890308: integrate zero assembler hotspot changes
never
parents:
diff changeset
    74
  // Byte-order reversal is needed
b154310845de 6890308: integrate zero assembler hotspot changes
never
parents:
diff changeset
    75
  static inline u2 get_Java_u2(address p) {
b154310845de 6890308: integrate zero assembler hotspot changes
never
parents:
diff changeset
    76
    return (u2(p[0]) << 8) |
b154310845de 6890308: integrate zero assembler hotspot changes
never
parents:
diff changeset
    77
           (u2(p[1])     );
b154310845de 6890308: integrate zero assembler hotspot changes
never
parents:
diff changeset
    78
  }
b154310845de 6890308: integrate zero assembler hotspot changes
never
parents:
diff changeset
    79
  static inline u4 get_Java_u4(address p) {
b154310845de 6890308: integrate zero assembler hotspot changes
never
parents:
diff changeset
    80
    return (u4(p[0]) << 24) |
b154310845de 6890308: integrate zero assembler hotspot changes
never
parents:
diff changeset
    81
           (u4(p[1]) << 16) |
b154310845de 6890308: integrate zero assembler hotspot changes
never
parents:
diff changeset
    82
           (u4(p[2]) <<  8) |
b154310845de 6890308: integrate zero assembler hotspot changes
never
parents:
diff changeset
    83
           (u4(p[3])      );
b154310845de 6890308: integrate zero assembler hotspot changes
never
parents:
diff changeset
    84
  }
b154310845de 6890308: integrate zero assembler hotspot changes
never
parents:
diff changeset
    85
  static inline u8 get_Java_u8(address p) {
b154310845de 6890308: integrate zero assembler hotspot changes
never
parents:
diff changeset
    86
    u4 hi, lo;
b154310845de 6890308: integrate zero assembler hotspot changes
never
parents:
diff changeset
    87
    hi = (u4(p[0]) << 24) |
b154310845de 6890308: integrate zero assembler hotspot changes
never
parents:
diff changeset
    88
         (u4(p[1]) << 16) |
b154310845de 6890308: integrate zero assembler hotspot changes
never
parents:
diff changeset
    89
         (u4(p[2]) <<  8) |
b154310845de 6890308: integrate zero assembler hotspot changes
never
parents:
diff changeset
    90
         (u4(p[3])      );
b154310845de 6890308: integrate zero assembler hotspot changes
never
parents:
diff changeset
    91
    lo = (u4(p[4]) << 24) |
b154310845de 6890308: integrate zero assembler hotspot changes
never
parents:
diff changeset
    92
         (u4(p[5]) << 16) |
b154310845de 6890308: integrate zero assembler hotspot changes
never
parents:
diff changeset
    93
         (u4(p[6]) <<  8) |
b154310845de 6890308: integrate zero assembler hotspot changes
never
parents:
diff changeset
    94
         (u4(p[7])      );
b154310845de 6890308: integrate zero assembler hotspot changes
never
parents:
diff changeset
    95
    return u8(lo) | (u8(hi) << 32);
b154310845de 6890308: integrate zero assembler hotspot changes
never
parents:
diff changeset
    96
  }
b154310845de 6890308: integrate zero assembler hotspot changes
never
parents:
diff changeset
    97
b154310845de 6890308: integrate zero assembler hotspot changes
never
parents:
diff changeset
    98
  static inline void put_Java_u2(address p, u2 x) {
b154310845de 6890308: integrate zero assembler hotspot changes
never
parents:
diff changeset
    99
    p[0] = x >> 8;
b154310845de 6890308: integrate zero assembler hotspot changes
never
parents:
diff changeset
   100
    p[1] = x;
b154310845de 6890308: integrate zero assembler hotspot changes
never
parents:
diff changeset
   101
  }
b154310845de 6890308: integrate zero assembler hotspot changes
never
parents:
diff changeset
   102
  static inline void put_Java_u4(address p, u4 x) {
b154310845de 6890308: integrate zero assembler hotspot changes
never
parents:
diff changeset
   103
    p[0] = x >> 24;
b154310845de 6890308: integrate zero assembler hotspot changes
never
parents:
diff changeset
   104
    p[1] = x >> 16;
b154310845de 6890308: integrate zero assembler hotspot changes
never
parents:
diff changeset
   105
    p[2] = x >> 8;
b154310845de 6890308: integrate zero assembler hotspot changes
never
parents:
diff changeset
   106
    p[3] = x;
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_u8(address p, u8 x) {
b154310845de 6890308: integrate zero assembler hotspot changes
never
parents:
diff changeset
   109
    u4 hi, lo;
b154310845de 6890308: integrate zero assembler hotspot changes
never
parents:
diff changeset
   110
    lo = x;
b154310845de 6890308: integrate zero assembler hotspot changes
never
parents:
diff changeset
   111
    hi = x >> 32;
b154310845de 6890308: integrate zero assembler hotspot changes
never
parents:
diff changeset
   112
    p[0] = hi >> 24;
b154310845de 6890308: integrate zero assembler hotspot changes
never
parents:
diff changeset
   113
    p[1] = hi >> 16;
b154310845de 6890308: integrate zero assembler hotspot changes
never
parents:
diff changeset
   114
    p[2] = hi >> 8;
b154310845de 6890308: integrate zero assembler hotspot changes
never
parents:
diff changeset
   115
    p[3] = hi;
b154310845de 6890308: integrate zero assembler hotspot changes
never
parents:
diff changeset
   116
    p[4] = lo >> 24;
b154310845de 6890308: integrate zero assembler hotspot changes
never
parents:
diff changeset
   117
    p[5] = lo >> 16;
b154310845de 6890308: integrate zero assembler hotspot changes
never
parents:
diff changeset
   118
    p[6] = lo >> 8;
b154310845de 6890308: integrate zero assembler hotspot changes
never
parents:
diff changeset
   119
    p[7] = lo;
b154310845de 6890308: integrate zero assembler hotspot changes
never
parents:
diff changeset
   120
  }
b154310845de 6890308: integrate zero assembler hotspot changes
never
parents:
diff changeset
   121
b154310845de 6890308: integrate zero assembler hotspot changes
never
parents:
diff changeset
   122
  // Efficient swapping of byte ordering
b154310845de 6890308: integrate zero assembler hotspot changes
never
parents:
diff changeset
   123
  static inline u2 swap_u2(u2 x);
b154310845de 6890308: integrate zero assembler hotspot changes
never
parents:
diff changeset
   124
  static inline u4 swap_u4(u4 x);
b154310845de 6890308: integrate zero assembler hotspot changes
never
parents:
diff changeset
   125
  static inline u8 swap_u8(u8 x);
b154310845de 6890308: integrate zero assembler hotspot changes
never
parents:
diff changeset
   126
#else
b154310845de 6890308: integrate zero assembler hotspot changes
never
parents:
diff changeset
   127
  // No byte-order reversal is needed
b154310845de 6890308: integrate zero assembler hotspot changes
never
parents:
diff changeset
   128
  static inline u2 get_Java_u2(address p) {
b154310845de 6890308: integrate zero assembler hotspot changes
never
parents:
diff changeset
   129
    return get_native_u2(p);
b154310845de 6890308: integrate zero assembler hotspot changes
never
parents:
diff changeset
   130
  }
b154310845de 6890308: integrate zero assembler hotspot changes
never
parents:
diff changeset
   131
  static inline u4 get_Java_u4(address p) {
b154310845de 6890308: integrate zero assembler hotspot changes
never
parents:
diff changeset
   132
    return get_native_u4(p);
b154310845de 6890308: integrate zero assembler hotspot changes
never
parents:
diff changeset
   133
  }
b154310845de 6890308: integrate zero assembler hotspot changes
never
parents:
diff changeset
   134
  static inline u8 get_Java_u8(address p) {
b154310845de 6890308: integrate zero assembler hotspot changes
never
parents:
diff changeset
   135
    return get_native_u8(p);
b154310845de 6890308: integrate zero assembler hotspot changes
never
parents:
diff changeset
   136
  }
b154310845de 6890308: integrate zero assembler hotspot changes
never
parents:
diff changeset
   137
b154310845de 6890308: integrate zero assembler hotspot changes
never
parents:
diff changeset
   138
  static inline void put_Java_u2(address p, u2 x) {
b154310845de 6890308: integrate zero assembler hotspot changes
never
parents:
diff changeset
   139
    put_native_u2(p, x);
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 void put_Java_u4(address p, u4 x) {
b154310845de 6890308: integrate zero assembler hotspot changes
never
parents:
diff changeset
   142
    put_native_u4(p, x);
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 void put_Java_u8(address p, u8 x) {
b154310845de 6890308: integrate zero assembler hotspot changes
never
parents:
diff changeset
   145
    put_native_u8(p, x);
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
  // No byte-order reversal is needed
b154310845de 6890308: integrate zero assembler hotspot changes
never
parents:
diff changeset
   149
  static inline u2 swap_u2(u2 x) { return x; }
b154310845de 6890308: integrate zero assembler hotspot changes
never
parents:
diff changeset
   150
  static inline u4 swap_u4(u4 x) { return x; }
b154310845de 6890308: integrate zero assembler hotspot changes
never
parents:
diff changeset
   151
  static inline u8 swap_u8(u8 x) { return x; }
b154310845de 6890308: integrate zero assembler hotspot changes
never
parents:
diff changeset
   152
#endif // VM_LITTLE_ENDIAN
b154310845de 6890308: integrate zero assembler hotspot changes
never
parents:
diff changeset
   153
};
b154310845de 6890308: integrate zero assembler hotspot changes
never
parents:
diff changeset
   154
b154310845de 6890308: integrate zero assembler hotspot changes
never
parents:
diff changeset
   155
#ifdef VM_LITTLE_ENDIAN
b154310845de 6890308: integrate zero assembler hotspot changes
never
parents:
diff changeset
   156
// The following header contains the implementations of swap_u2,
b154310845de 6890308: integrate zero assembler hotspot changes
never
parents:
diff changeset
   157
// swap_u4, and swap_u8
40010
e32d5e545789 8161258: Simplify including platform files.
goetz
parents: 10565
diff changeset
   158
e32d5e545789 8161258: Simplify including platform files.
goetz
parents: 10565
diff changeset
   159
#include OS_CPU_HEADER_INLINE(bytes)
7397
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 5547
diff changeset
   160
4013
b154310845de 6890308: integrate zero assembler hotspot changes
never
parents:
diff changeset
   161
#endif // VM_LITTLE_ENDIAN
7397
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 5547
diff changeset
   162
53244
9807daeb47c4 8216167: Update include guards to reflect correct directories
coleenp
parents: 47216
diff changeset
   163
#endif // CPU_ZERO_BYTES_ZERO_HPP