hotspot/src/cpu/sparc/vm/bytes_sparc.hpp
author twisti
Fri, 13 Feb 2009 09:09:35 -0800
changeset 2031 24e034f56dcb
parent 1 489c9b5090e2
child 5547 f4b087cbb361
permissions -rw-r--r--
6800154: Add comments to long_by_long_mulhi() for better understandability Summary: This patch adds a comment pointing to the Hacker's Delight version of the algorithm plus a verbatim copy of it. Furthermore it adds inline comments. Reviewed-by: kvn, jrose
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
     1
/*
489c9b5090e2 Initial load
duke
parents:
diff changeset
     2
 * Copyright 1997-2002 Sun Microsystems, Inc.  All Rights Reserved.
489c9b5090e2 Initial load
duke
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
489c9b5090e2 Initial load
duke
parents:
diff changeset
     4
 *
489c9b5090e2 Initial load
duke
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
489c9b5090e2 Initial load
duke
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
489c9b5090e2 Initial load
duke
parents:
diff changeset
     7
 * published by the Free Software Foundation.
489c9b5090e2 Initial load
duke
parents:
diff changeset
     8
 *
489c9b5090e2 Initial load
duke
parents:
diff changeset
     9
 * This code is distributed in the hope that it will be useful, but WITHOUT
489c9b5090e2 Initial load
duke
parents:
diff changeset
    10
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
489c9b5090e2 Initial load
duke
parents:
diff changeset
    11
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
489c9b5090e2 Initial load
duke
parents:
diff changeset
    12
 * version 2 for more details (a copy is included in the LICENSE file that
489c9b5090e2 Initial load
duke
parents:
diff changeset
    13
 * accompanied this code).
489c9b5090e2 Initial load
duke
parents:
diff changeset
    14
 *
489c9b5090e2 Initial load
duke
parents:
diff changeset
    15
 * You should have received a copy of the GNU General Public License version
489c9b5090e2 Initial load
duke
parents:
diff changeset
    16
 * 2 along with this work; if not, write to the Free Software Foundation,
489c9b5090e2 Initial load
duke
parents:
diff changeset
    17
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
489c9b5090e2 Initial load
duke
parents:
diff changeset
    18
 *
489c9b5090e2 Initial load
duke
parents:
diff changeset
    19
 * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
489c9b5090e2 Initial load
duke
parents:
diff changeset
    20
 * CA 95054 USA or visit www.sun.com if you need additional information or
489c9b5090e2 Initial load
duke
parents:
diff changeset
    21
 * have any questions.
489c9b5090e2 Initial load
duke
parents:
diff changeset
    22
 *
489c9b5090e2 Initial load
duke
parents:
diff changeset
    23
 */
489c9b5090e2 Initial load
duke
parents:
diff changeset
    24
489c9b5090e2 Initial load
duke
parents:
diff changeset
    25
class Bytes: AllStatic {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    26
 public:
489c9b5090e2 Initial load
duke
parents:
diff changeset
    27
  // Efficient reading and writing of unaligned unsigned data in platform-specific byte ordering
489c9b5090e2 Initial load
duke
parents:
diff changeset
    28
  // Sparc needs to check for alignment.
489c9b5090e2 Initial load
duke
parents:
diff changeset
    29
489c9b5090e2 Initial load
duke
parents:
diff changeset
    30
  // can I count on address always being a pointer to an unsigned char? Yes
489c9b5090e2 Initial load
duke
parents:
diff changeset
    31
489c9b5090e2 Initial load
duke
parents:
diff changeset
    32
  // Returns true, if the byte ordering used by Java is different from the nativ byte ordering
489c9b5090e2 Initial load
duke
parents:
diff changeset
    33
  // of the underlying machine. For example, true for Intel x86, False, for Solaris on Sparc.
489c9b5090e2 Initial load
duke
parents:
diff changeset
    34
  static inline bool is_Java_byte_ordering_different() { return false; }
489c9b5090e2 Initial load
duke
parents:
diff changeset
    35
489c9b5090e2 Initial load
duke
parents:
diff changeset
    36
  // Thus, a swap between native and Java ordering is always a no-op:
489c9b5090e2 Initial load
duke
parents:
diff changeset
    37
  static inline u2   swap_u2(u2 x)  { return x; }
489c9b5090e2 Initial load
duke
parents:
diff changeset
    38
  static inline u4   swap_u4(u4 x)  { return x; }
489c9b5090e2 Initial load
duke
parents:
diff changeset
    39
  static inline u8   swap_u8(u8 x)  { return x; }
489c9b5090e2 Initial load
duke
parents:
diff changeset
    40
489c9b5090e2 Initial load
duke
parents:
diff changeset
    41
  static inline u2   get_native_u2(address p){
489c9b5090e2 Initial load
duke
parents:
diff changeset
    42
    return (intptr_t(p) & 1) == 0
489c9b5090e2 Initial load
duke
parents:
diff changeset
    43
             ?   *(u2*)p
489c9b5090e2 Initial load
duke
parents:
diff changeset
    44
             :   ( u2(p[0]) << 8 )
489c9b5090e2 Initial load
duke
parents:
diff changeset
    45
               | ( u2(p[1])      );
489c9b5090e2 Initial load
duke
parents:
diff changeset
    46
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
    47
489c9b5090e2 Initial load
duke
parents:
diff changeset
    48
  static inline u4   get_native_u4(address p) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    49
    switch (intptr_t(p) & 3) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    50
     case 0:  return *(u4*)p;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    51
489c9b5090e2 Initial load
duke
parents:
diff changeset
    52
     case 2:  return (  u4( ((u2*)p)[0] ) << 16  )
489c9b5090e2 Initial load
duke
parents:
diff changeset
    53
                   | (  u4( ((u2*)p)[1] )                  );
489c9b5090e2 Initial load
duke
parents:
diff changeset
    54
489c9b5090e2 Initial load
duke
parents:
diff changeset
    55
    default:  return ( u4(p[0]) << 24 )
489c9b5090e2 Initial load
duke
parents:
diff changeset
    56
                   | ( u4(p[1]) << 16 )
489c9b5090e2 Initial load
duke
parents:
diff changeset
    57
                   | ( u4(p[2]) <<  8 )
489c9b5090e2 Initial load
duke
parents:
diff changeset
    58
                   |   u4(p[3]);
489c9b5090e2 Initial load
duke
parents:
diff changeset
    59
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
    60
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
    61
489c9b5090e2 Initial load
duke
parents:
diff changeset
    62
  static inline u8   get_native_u8(address p) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    63
    switch (intptr_t(p) & 7) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    64
      case 0:  return *(u8*)p;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    65
489c9b5090e2 Initial load
duke
parents:
diff changeset
    66
      case 4:  return (  u8( ((u4*)p)[0] ) << 32  )
489c9b5090e2 Initial load
duke
parents:
diff changeset
    67
                    | (  u8( ((u4*)p)[1] )        );
489c9b5090e2 Initial load
duke
parents:
diff changeset
    68
489c9b5090e2 Initial load
duke
parents:
diff changeset
    69
      case 2:  return (  u8( ((u2*)p)[0] ) << 48  )
489c9b5090e2 Initial load
duke
parents:
diff changeset
    70
                    | (  u8( ((u2*)p)[1] ) << 32  )
489c9b5090e2 Initial load
duke
parents:
diff changeset
    71
                    | (  u8( ((u2*)p)[2] ) << 16  )
489c9b5090e2 Initial load
duke
parents:
diff changeset
    72
                    | (  u8( ((u2*)p)[3] )        );
489c9b5090e2 Initial load
duke
parents:
diff changeset
    73
489c9b5090e2 Initial load
duke
parents:
diff changeset
    74
     default:  return ( u8(p[0]) << 56 )
489c9b5090e2 Initial load
duke
parents:
diff changeset
    75
                    | ( u8(p[1]) << 48 )
489c9b5090e2 Initial load
duke
parents:
diff changeset
    76
                    | ( u8(p[2]) << 40 )
489c9b5090e2 Initial load
duke
parents:
diff changeset
    77
                    | ( u8(p[3]) << 32 )
489c9b5090e2 Initial load
duke
parents:
diff changeset
    78
                    | ( u8(p[4]) << 24 )
489c9b5090e2 Initial load
duke
parents:
diff changeset
    79
                    | ( u8(p[5]) << 16 )
489c9b5090e2 Initial load
duke
parents:
diff changeset
    80
                    | ( u8(p[6]) <<  8 )
489c9b5090e2 Initial load
duke
parents:
diff changeset
    81
                    |   u8(p[7]);
489c9b5090e2 Initial load
duke
parents:
diff changeset
    82
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
    83
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
    84
489c9b5090e2 Initial load
duke
parents:
diff changeset
    85
489c9b5090e2 Initial load
duke
parents:
diff changeset
    86
489c9b5090e2 Initial load
duke
parents:
diff changeset
    87
  static inline void put_native_u2(address p, u2 x)   {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    88
    if ( (intptr_t(p) & 1) == 0 )  *(u2*)p = x;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    89
    else {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    90
      p[0] = x >> 8;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    91
      p[1] = x;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    92
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
    93
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
    94
489c9b5090e2 Initial load
duke
parents:
diff changeset
    95
  static inline void put_native_u4(address p, u4 x) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    96
    switch ( intptr_t(p) & 3 ) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    97
    case 0:  *(u4*)p = x;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    98
              break;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    99
489c9b5090e2 Initial load
duke
parents:
diff changeset
   100
    case 2:  ((u2*)p)[0] = x >> 16;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   101
             ((u2*)p)[1] = x;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   102
             break;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   103
489c9b5090e2 Initial load
duke
parents:
diff changeset
   104
    default: ((u1*)p)[0] = x >> 24;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   105
             ((u1*)p)[1] = x >> 16;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   106
             ((u1*)p)[2] = x >>  8;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   107
             ((u1*)p)[3] = x;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   108
             break;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   109
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   110
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   111
489c9b5090e2 Initial load
duke
parents:
diff changeset
   112
  static inline void put_native_u8(address p, u8 x) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   113
    switch ( intptr_t(p) & 7 ) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   114
    case 0:  *(u8*)p = x;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   115
             break;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   116
489c9b5090e2 Initial load
duke
parents:
diff changeset
   117
    case 4:  ((u4*)p)[0] = x >> 32;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   118
             ((u4*)p)[1] = x;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   119
             break;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   120
489c9b5090e2 Initial load
duke
parents:
diff changeset
   121
    case 2:  ((u2*)p)[0] = x >> 48;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   122
             ((u2*)p)[1] = x >> 32;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   123
             ((u2*)p)[2] = x >> 16;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   124
             ((u2*)p)[3] = x;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   125
             break;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   126
489c9b5090e2 Initial load
duke
parents:
diff changeset
   127
    default: ((u1*)p)[0] = x >> 56;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   128
             ((u1*)p)[1] = x >> 48;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   129
             ((u1*)p)[2] = x >> 40;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   130
             ((u1*)p)[3] = x >> 32;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   131
             ((u1*)p)[4] = x >> 24;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   132
             ((u1*)p)[5] = x >> 16;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   133
             ((u1*)p)[6] = x >>  8;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   134
             ((u1*)p)[7] = x;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   135
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   136
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   137
489c9b5090e2 Initial load
duke
parents:
diff changeset
   138
489c9b5090e2 Initial load
duke
parents:
diff changeset
   139
  // Efficient reading and writing of unaligned unsigned data in Java byte ordering (i.e. big-endian ordering)
489c9b5090e2 Initial load
duke
parents:
diff changeset
   140
  // (no byte-order reversal is needed since SPARC CPUs are big-endian oriented)
489c9b5090e2 Initial load
duke
parents:
diff changeset
   141
  static inline u2   get_Java_u2(address p) { return get_native_u2(p); }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   142
  static inline u4   get_Java_u4(address p) { return get_native_u4(p); }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   143
  static inline u8   get_Java_u8(address p) { return get_native_u8(p); }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   144
489c9b5090e2 Initial load
duke
parents:
diff changeset
   145
  static inline void put_Java_u2(address p, u2 x)     { put_native_u2(p, x); }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   146
  static inline void put_Java_u4(address p, u4 x)     { put_native_u4(p, x); }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   147
  static inline void put_Java_u8(address p, u8 x)     { put_native_u8(p, x); }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   148
};
489c9b5090e2 Initial load
duke
parents:
diff changeset
   149
489c9b5090e2 Initial load
duke
parents:
diff changeset
   150
//Reconciliation History
489c9b5090e2 Initial load
duke
parents:
diff changeset
   151
// 1.7 98/02/24 10:18:41 bytes_i486.hpp
489c9b5090e2 Initial load
duke
parents:
diff changeset
   152
// 1.10 98/04/08 18:47:57 bytes_i486.hpp
489c9b5090e2 Initial load
duke
parents:
diff changeset
   153
// 1.13 98/07/15 17:10:03 bytes_i486.hpp
489c9b5090e2 Initial load
duke
parents:
diff changeset
   154
// 1.14 98/08/13 10:38:23 bytes_i486.hpp
489c9b5090e2 Initial load
duke
parents:
diff changeset
   155
// 1.15 98/10/05 16:30:21 bytes_i486.hpp
489c9b5090e2 Initial load
duke
parents:
diff changeset
   156
// 1.17 99/06/22 16:37:35 bytes_i486.hpp
489c9b5090e2 Initial load
duke
parents:
diff changeset
   157
//End