src/hotspot/cpu/sparc/args.cc
author phh
Sat, 30 Nov 2019 14:33:05 -0800
changeset 59330 5b96c12f909d
parent 47216 71c04702a3d5
permissions -rw-r--r--
8234541: C1 emits an empty message when it inlines successfully Summary: Use "inline" as the message when successfull Reviewed-by: thartmann, mdoerr Contributed-by: navy.xliu@gmail.com
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
     1
/*
5547
f4b087cbb361 6941466: Oracle rebranding changes for Hotspot repositories
trims
parents: 1
diff changeset
     2
 * Copyright (c) 2002, 2006, Oracle and/or its affiliates. All rights reserved.
1
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
 *
5547
f4b087cbb361 6941466: Oracle rebranding changes for Hotspot repositories
trims
parents: 1
diff changeset
    19
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
f4b087cbb361 6941466: Oracle rebranding changes for Hotspot repositories
trims
parents: 1
diff changeset
    20
 * or visit www.oracle.com if you need additional information or have any
f4b087cbb361 6941466: Oracle rebranding changes for Hotspot repositories
trims
parents: 1
diff changeset
    21
 * questions.
1
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
#include <stdio.h>
489c9b5090e2 Initial load
duke
parents:
diff changeset
    26
#include <string.h>
489c9b5090e2 Initial load
duke
parents:
diff changeset
    27
489c9b5090e2 Initial load
duke
parents:
diff changeset
    28
static const int R_O0_num = 1000;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    29
static const int R_I0_num = 2000;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    30
static const int R_F0_num = 3000;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    31
static const int R_F1_num = R_F0_num + 1;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    32
static const int R_F2_num = R_F0_num + 2;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    33
static const int STACK_num= 4000;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    34
489c9b5090e2 Initial load
duke
parents:
diff changeset
    35
static bool LP64 = false;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    36
static bool LONGS_IN_ONE_ENTRY = false;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    37
489c9b5090e2 Initial load
duke
parents:
diff changeset
    38
static const int Op_RegI = 'I';
489c9b5090e2 Initial load
duke
parents:
diff changeset
    39
static const int Op_RegP = 'P';
489c9b5090e2 Initial load
duke
parents:
diff changeset
    40
static const int Op_RegF = 'F';
489c9b5090e2 Initial load
duke
parents:
diff changeset
    41
static const int Op_RegD = 'D';
489c9b5090e2 Initial load
duke
parents:
diff changeset
    42
static const int Op_RegL = 'L';
489c9b5090e2 Initial load
duke
parents:
diff changeset
    43
static const int SPARC_ARGS_IN_REGS_NUM=6;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    44
489c9b5090e2 Initial load
duke
parents:
diff changeset
    45
static void print_reg( int reg ) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    46
  if( reg == 0 )
489c9b5090e2 Initial load
duke
parents:
diff changeset
    47
    printf("__");               // halve's
489c9b5090e2 Initial load
duke
parents:
diff changeset
    48
  else if( reg >= STACK_num && reg < STACK_num+100 )
489c9b5090e2 Initial load
duke
parents:
diff changeset
    49
    printf("S%d_",reg - STACK_num);
489c9b5090e2 Initial load
duke
parents:
diff changeset
    50
  else if( reg >= R_F0_num && reg < R_F0_num+100 )
489c9b5090e2 Initial load
duke
parents:
diff changeset
    51
    printf("F%d_",reg - R_F0_num);
489c9b5090e2 Initial load
duke
parents:
diff changeset
    52
  else if( reg >= R_O0_num && reg < R_O0_num+100 ) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    53
    if( LONGS_IN_ONE_ENTRY ) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    54
      reg -= R_O0_num;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    55
      printf("O%d",reg>>1);
489c9b5090e2 Initial load
duke
parents:
diff changeset
    56
      printf(reg&1 ? "H" : "L");
489c9b5090e2 Initial load
duke
parents:
diff changeset
    57
    } else
489c9b5090e2 Initial load
duke
parents:
diff changeset
    58
      printf("O%d_",reg - R_O0_num);
489c9b5090e2 Initial load
duke
parents:
diff changeset
    59
  } else
489c9b5090e2 Initial load
duke
parents:
diff changeset
    60
    printf("Wretched: %d\n", reg);
489c9b5090e2 Initial load
duke
parents:
diff changeset
    61
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
    62
489c9b5090e2 Initial load
duke
parents:
diff changeset
    63
static void print_convention( int *sig, const char *s, int length ) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    64
  // Print it out
489c9b5090e2 Initial load
duke
parents:
diff changeset
    65
  for( int i = 0; i < length; i++) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    66
    if( sig[i] == 0 ) continue; // do not print 'halves'
489c9b5090e2 Initial load
duke
parents:
diff changeset
    67
    print_reg( sig[i] & 0xFFFF );
489c9b5090e2 Initial load
duke
parents:
diff changeset
    68
    int reg = sig[i] >> 16;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    69
    if( reg ) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    70
      printf(":");
489c9b5090e2 Initial load
duke
parents:
diff changeset
    71
      print_reg( reg );
489c9b5090e2 Initial load
duke
parents:
diff changeset
    72
    } else {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    73
      printf("    ");
489c9b5090e2 Initial load
duke
parents:
diff changeset
    74
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
    75
    printf("  ");
489c9b5090e2 Initial load
duke
parents:
diff changeset
    76
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
    77
  printf("\n");
489c9b5090e2 Initial load
duke
parents:
diff changeset
    78
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
    79
489c9b5090e2 Initial load
duke
parents:
diff changeset
    80
static int INT_SCALE( int x ) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    81
  return LONGS_IN_ONE_ENTRY ? (x<<1) : x;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    82
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
    83
489c9b5090e2 Initial load
duke
parents:
diff changeset
    84
static void java_convention( int *sig, const char *s, int length ) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    85
  if( LP64 && !LONGS_IN_ONE_ENTRY ) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    86
    printf("LP64 and 2-reg longs not supported\n");
489c9b5090e2 Initial load
duke
parents:
diff changeset
    87
    return;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    88
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
    89
  for( int i = 0; i < length; i++ )
489c9b5090e2 Initial load
duke
parents:
diff changeset
    90
    sig[i] = s[i];              // Reset sig array
489c9b5090e2 Initial load
duke
parents:
diff changeset
    91
  bool is_outgoing = true;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    92
489c9b5090e2 Initial load
duke
parents:
diff changeset
    93
  int int_base = (is_outgoing ? R_O0_num : R_I0_num);
489c9b5090e2 Initial load
duke
parents:
diff changeset
    94
489c9b5090e2 Initial load
duke
parents:
diff changeset
    95
  // Convention is to pack the first 6 int/oop args into the first 6
489c9b5090e2 Initial load
duke
parents:
diff changeset
    96
  // registers (I0-I5), extras spill to the stack.  Then pack the first
489c9b5090e2 Initial load
duke
parents:
diff changeset
    97
  // 32 float args into F0-F31, extras spill to the stack.  Then pad
489c9b5090e2 Initial load
duke
parents:
diff changeset
    98
  // all register sets to align.  Then put longs and doubles into the
489c9b5090e2 Initial load
duke
parents:
diff changeset
    99
  // same registers as they fit, else spill to the stack.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   100
  int int_reg_max = SPARC_ARGS_IN_REGS_NUM;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   101
  int flt_reg_max = 32;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   102
  
489c9b5090e2 Initial load
duke
parents:
diff changeset
   103
  // Count int/oop and float args.  See how many stack slots we'll need
489c9b5090e2 Initial load
duke
parents:
diff changeset
   104
  // and where the longs & doubles will go.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   105
  int int_reg_cnt   = 0;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   106
  int flt_reg_cnt   = 0;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   107
  int stk_reg_pairs = 0;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   108
  for( int i = 0; i < length; i++) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   109
    switch( sig[i] ) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   110
    case Op_RegL:               // Longs-in-1-reg compete with int args
489c9b5090e2 Initial load
duke
parents:
diff changeset
   111
      if( LONGS_IN_ONE_ENTRY ) { 
489c9b5090e2 Initial load
duke
parents:
diff changeset
   112
        if( int_reg_cnt < int_reg_max ) int_reg_cnt++;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   113
      }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   114
      break;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   115
    case Op_RegP:
489c9b5090e2 Initial load
duke
parents:
diff changeset
   116
      if( int_reg_cnt < int_reg_max ) int_reg_cnt++;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   117
      else if( !LP64 )                stk_reg_pairs++;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   118
      break;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   119
    case Op_RegI:
489c9b5090e2 Initial load
duke
parents:
diff changeset
   120
      if( int_reg_cnt < int_reg_max ) int_reg_cnt++;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   121
      else                            stk_reg_pairs++;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   122
      break;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   123
    case Op_RegF:
489c9b5090e2 Initial load
duke
parents:
diff changeset
   124
      if( flt_reg_cnt < flt_reg_max ) flt_reg_cnt++;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   125
      else                            stk_reg_pairs++;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   126
      break;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   127
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   128
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   129
489c9b5090e2 Initial load
duke
parents:
diff changeset
   130
  // This is where the longs/doubles start on the stack.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   131
  stk_reg_pairs = (stk_reg_pairs+1) & ~1; // Round
489c9b5090e2 Initial load
duke
parents:
diff changeset
   132
  
489c9b5090e2 Initial load
duke
parents:
diff changeset
   133
  int int_reg_pairs = (int_reg_cnt+1) & ~1; // 32-bit 2-reg longs only
489c9b5090e2 Initial load
duke
parents:
diff changeset
   134
  int flt_reg_pairs = (flt_reg_cnt+1) & ~1;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   135
489c9b5090e2 Initial load
duke
parents:
diff changeset
   136
  int stk_reg = 0;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   137
  int int_reg = 0;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   138
  int flt_reg = 0;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   139
  
489c9b5090e2 Initial load
duke
parents:
diff changeset
   140
  // Now do the signature layout
489c9b5090e2 Initial load
duke
parents:
diff changeset
   141
  for( int i = 0; i < length; i++) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   142
    int tmp = sig[i];
489c9b5090e2 Initial load
duke
parents:
diff changeset
   143
    if( tmp == Op_RegP )
489c9b5090e2 Initial load
duke
parents:
diff changeset
   144
      tmp = LP64 ? Op_RegL : Op_RegI;   // Treat ptrs and ints or long accordingly
489c9b5090e2 Initial load
duke
parents:
diff changeset
   145
    switch( tmp ) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   146
    case Op_RegI:
489c9b5090e2 Initial load
duke
parents:
diff changeset
   147
//  case Op_RegP: 
489c9b5090e2 Initial load
duke
parents:
diff changeset
   148
      if( int_reg < int_reg_max) tmp = INT_SCALE(int_reg++) + int_base;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   149
      else                       tmp = STACK_num + stk_reg++;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   150
      sig[i] = tmp;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   151
      break;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   152
489c9b5090e2 Initial load
duke
parents:
diff changeset
   153
    case Op_RegL: 
489c9b5090e2 Initial load
duke
parents:
diff changeset
   154
      if( sig[i] != Op_RegP && sig[i+1] != 'h' ) { printf("expecting (h)alf, found %c\n", sig[i+1]); return; }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   155
//  case Op_RegP: 
489c9b5090e2 Initial load
duke
parents:
diff changeset
   156
      if( LONGS_IN_ONE_ENTRY ) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   157
        if( int_reg < int_reg_max ) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   158
          tmp = INT_SCALE(int_reg++) + int_base;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   159
        } else {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   160
          tmp = STACK_num + stk_reg_pairs;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   161
          stk_reg_pairs += 2;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   162
        }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   163
      } else {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   164
        if( int_reg_pairs < int_reg_max ) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   165
          tmp = int_reg_pairs + int_base;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   166
          int_reg_pairs += 2;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   167
        } else {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   168
          tmp = STACK_num + stk_reg_pairs;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   169
          stk_reg_pairs += 2;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   170
        }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   171
      }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   172
      sig[i] = tmp | (tmp+1)<<16; // Smear to pair
489c9b5090e2 Initial load
duke
parents:
diff changeset
   173
      break;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   174
489c9b5090e2 Initial load
duke
parents:
diff changeset
   175
    case Op_RegF: 
489c9b5090e2 Initial load
duke
parents:
diff changeset
   176
      sig[i] = (flt_reg < flt_reg_max) ? (R_F0_num + flt_reg++) : STACK_num + stk_reg++;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   177
      break;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   178
    case Op_RegD: 
489c9b5090e2 Initial load
duke
parents:
diff changeset
   179
      if( sig[i+1] != 'h' ) { printf("expecting (h)alf, found %c\n", sig[i+1]); return; }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   180
      if( flt_reg_pairs < flt_reg_max ) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   181
        tmp = R_F0_num + flt_reg_pairs;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   182
        flt_reg_pairs += 2;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   183
      } else {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   184
        tmp = STACK_num + stk_reg_pairs;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   185
        stk_reg_pairs += 2;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   186
      }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   187
      sig[i] = tmp | (tmp+1)<<16; // Smear to pair
489c9b5090e2 Initial load
duke
parents:
diff changeset
   188
      break;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   189
    case 'h': sig[i] = 0; break;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   190
    default:
489c9b5090e2 Initial load
duke
parents:
diff changeset
   191
      printf("Bad character: %c\n", sig[i] );
489c9b5090e2 Initial load
duke
parents:
diff changeset
   192
      return;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   193
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   194
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   195
489c9b5090e2 Initial load
duke
parents:
diff changeset
   196
  printf("java ");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   197
  printf(LP64 ? "LP64 " : "LP32 ");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   198
  printf(LONGS_IN_ONE_ENTRY ? "long1: " : "long2: ");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   199
  print_convention(sig,s,length);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   200
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   201
489c9b5090e2 Initial load
duke
parents:
diff changeset
   202
static int int_stk_helper( int i ) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   203
  if( i < 6 ) return R_O0_num + (LONGS_IN_ONE_ENTRY ? i<<1 : i);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   204
  else        return STACK_num + (LP64              ? i<<1 : i);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   205
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   206
489c9b5090e2 Initial load
duke
parents:
diff changeset
   207
static void native_convention( int *sig, const char *s, int length ) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   208
  if( LP64 && !LONGS_IN_ONE_ENTRY ) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   209
    printf("LP64 and 2-reg longs not supported\n");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   210
    return;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   211
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   212
  for( int i = 0; i < length; i++ )
489c9b5090e2 Initial load
duke
parents:
diff changeset
   213
    sig[i] = s[i];              // Reset sig array
489c9b5090e2 Initial load
duke
parents:
diff changeset
   214
489c9b5090e2 Initial load
duke
parents:
diff changeset
   215
  // The native convention is V8 if !LP64, which means the V8 convention is
489c9b5090e2 Initial load
duke
parents:
diff changeset
   216
  // used both with and without LONGS_IN_ONE_ENTRY, an unfortunate split.  The
489c9b5090e2 Initial load
duke
parents:
diff changeset
   217
  // same actual machine registers are used, but they are named differently in
489c9b5090e2 Initial load
duke
parents:
diff changeset
   218
  // the LONGS_IN_ONE_ENTRY mode.  The LP64 convention is the V9 convention
489c9b5090e2 Initial load
duke
parents:
diff changeset
   219
  // which is slightly more sane.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   220
  
489c9b5090e2 Initial load
duke
parents:
diff changeset
   221
  if( LP64 ) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   222
    // V9 convention: All things "as-if" on double-wide stack slots.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   223
    // Hoist any int/ptr/long's in the first 6 to int regs.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   224
    // Hoist any flt/dbl's in the first 16 dbl regs.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   225
    int j = 0;                  // Count of actual args, not HALVES
489c9b5090e2 Initial load
duke
parents:
diff changeset
   226
    for( int i=0; i<length; i++, j++ ) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   227
      int tmp;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   228
      switch( sig[i] ) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   229
      case Op_RegI:
489c9b5090e2 Initial load
duke
parents:
diff changeset
   230
        sig[i] = int_stk_helper( j );
489c9b5090e2 Initial load
duke
parents:
diff changeset
   231
        break;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   232
      case Op_RegL:
489c9b5090e2 Initial load
duke
parents:
diff changeset
   233
        if( sig[i+1] != 'h' ) { printf("expecting (h)alf, found %c\n", sig[i+1]); return; }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   234
      case Op_RegP:
489c9b5090e2 Initial load
duke
parents:
diff changeset
   235
        tmp = int_stk_helper( j );
489c9b5090e2 Initial load
duke
parents:
diff changeset
   236
        sig[i] = tmp | ((tmp+1) << 16); // Smear to pair
489c9b5090e2 Initial load
duke
parents:
diff changeset
   237
        break;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   238
      case Op_RegF:                 // V9ism: floats go in ODD registers
489c9b5090e2 Initial load
duke
parents:
diff changeset
   239
        sig[i] = ((j < 16) ? R_F1_num : (STACK_num + 1)) + (j<<1);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   240
        break;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   241
      case Op_RegD:                 // V9ism: doubles go in EVEN/ODD regs
489c9b5090e2 Initial load
duke
parents:
diff changeset
   242
        tmp    = ((j < 16) ? R_F0_num : STACK_num) + (j<<1);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   243
        sig[i] = tmp | ((tmp+1) << 16); // Smear to pair
489c9b5090e2 Initial load
duke
parents:
diff changeset
   244
        break;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   245
      case 'h': sig[i] = 0; j--; break; // Do not count HALVES
489c9b5090e2 Initial load
duke
parents:
diff changeset
   246
      default:
489c9b5090e2 Initial load
duke
parents:
diff changeset
   247
        printf("Bad character: %c\n", sig[i] );
489c9b5090e2 Initial load
duke
parents:
diff changeset
   248
        return;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   249
      }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   250
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   251
489c9b5090e2 Initial load
duke
parents:
diff changeset
   252
  } else {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   253
    // V8 convention: first 6 things in O-regs, rest on stack.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   254
    // Alignment is willy-nilly.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   255
    for( int i=0; i<length; i++ ) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   256
      int tmp;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   257
      switch( sig[i] ) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   258
      case Op_RegI:
489c9b5090e2 Initial load
duke
parents:
diff changeset
   259
      case Op_RegP:
489c9b5090e2 Initial load
duke
parents:
diff changeset
   260
      case Op_RegF:
489c9b5090e2 Initial load
duke
parents:
diff changeset
   261
        sig[i] = int_stk_helper( i );
489c9b5090e2 Initial load
duke
parents:
diff changeset
   262
        break;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   263
      case Op_RegL:
489c9b5090e2 Initial load
duke
parents:
diff changeset
   264
      case Op_RegD:
489c9b5090e2 Initial load
duke
parents:
diff changeset
   265
        if( sig[i+1] != 'h' ) { printf("expecting (h)alf, found %c\n", sig[i+1]); return; }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   266
        tmp = int_stk_helper( i );
489c9b5090e2 Initial load
duke
parents:
diff changeset
   267
        sig[i] = tmp | (int_stk_helper( i+1 ) << 16);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   268
        break;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   269
      case 'h': sig[i] = 0; break;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   270
      default:
489c9b5090e2 Initial load
duke
parents:
diff changeset
   271
        printf("Bad character: %c\n", sig[i] );
489c9b5090e2 Initial load
duke
parents:
diff changeset
   272
        return;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   273
      }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   274
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   275
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   276
489c9b5090e2 Initial load
duke
parents:
diff changeset
   277
  printf("natv ");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   278
  printf(LP64 ? "LP64 " : "LP32 ");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   279
  printf(LONGS_IN_ONE_ENTRY ? "long1: " : "long2: ");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   280
  print_convention(sig,s,length);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   281
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   282
489c9b5090e2 Initial load
duke
parents:
diff changeset
   283
int main( int argc, char **argv ) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   284
489c9b5090e2 Initial load
duke
parents:
diff changeset
   285
  if( argc != 2 ) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   286
    printf("Usage: args IPFLhDh... (Java argument string)\n");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   287
    printf("Returns argument layout\n");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   288
    return -1;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   289
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   290
489c9b5090e2 Initial load
duke
parents:
diff changeset
   291
  const char *s = argv[1];
489c9b5090e2 Initial load
duke
parents:
diff changeset
   292
  int length = strlen(s);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   293
  int sig[1000];
489c9b5090e2 Initial load
duke
parents:
diff changeset
   294
489c9b5090e2 Initial load
duke
parents:
diff changeset
   295
  LP64 = false; LONGS_IN_ONE_ENTRY = false;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   296
  java_convention( sig, s, length );
489c9b5090e2 Initial load
duke
parents:
diff changeset
   297
  LP64 = false; LONGS_IN_ONE_ENTRY = true;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   298
  java_convention( sig, s, length );
489c9b5090e2 Initial load
duke
parents:
diff changeset
   299
  LP64 = true ; LONGS_IN_ONE_ENTRY = true;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   300
  java_convention( sig, s, length );
489c9b5090e2 Initial load
duke
parents:
diff changeset
   301
489c9b5090e2 Initial load
duke
parents:
diff changeset
   302
  LP64 = false; LONGS_IN_ONE_ENTRY = false;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   303
  native_convention( sig, s, length );
489c9b5090e2 Initial load
duke
parents:
diff changeset
   304
  LP64 = false; LONGS_IN_ONE_ENTRY = true;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   305
  native_convention( sig, s, length );
489c9b5090e2 Initial load
duke
parents:
diff changeset
   306
  LP64 = true ; LONGS_IN_ONE_ENTRY = true;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   307
  native_convention( sig, s, length );
489c9b5090e2 Initial load
duke
parents:
diff changeset
   308
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   309