1 /*
   2  * Copyright (c) 2007, 2012, Oracle and/or its affiliates. All rights reserved.
   3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   4  *
   5  * This code is free software; you can redistribute it and/or modify it
   6  * under the terms of the GNU General Public License version 2 only, as
   7  * published by the Free Software Foundation.
   8  *
   9  * This code is distributed in the hope that it will be useful, but WITHOUT
  10  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  11  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  12  * version 2 for more details (a copy is included in the LICENSE file that
  13  * accompanied this code).
  14  *
  15  * You should have received a copy of the GNU General Public License version
  16  * 2 along with this work; if not, write to the Free Software Foundation,
  17  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  18  *
  19  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  20  * or visit www.oracle.com if you need additional information or have any
  21  * questions.
  22  */
  23 /*
  24  * Copyright (c) 2007, 2012, Oracle and/or its affiliates. All rights reserved.
  25  */
  26 package org.graalvm.compiler.jtt.micro;
  27 
  28 import org.junit.Assert;
  29 import org.junit.Test;
  30 
  31 import org.graalvm.compiler.jtt.JTTTest;
  32 
  33 /**
  34  * Tests different alignment on the stack with extended parameters (index > 5).
  35  */
  36 public class BigMixedParams04 extends JTTTest {
  37 
  38     @SuppressWarnings("unused")
  39     public static long test(int choice, int i0, int i1, int i2, int i3, double d1, double d2, boolean bo1, boolean bo2, byte by, short sh, char ch, int in) {
  40         switch (choice) {
  41             case 0:
  42                 return bo1 ? 1L : 2L;
  43             case 1:
  44                 return bo2 ? 1L : 2L;
  45             case 2:
  46                 return by;
  47             case 3:
  48                 return sh;
  49             case 4:
  50                 return ch;
  51             case 5:
  52                 return in;
  53         }
  54         return 42;
  55     }
  56 
  57     /**
  58      * Test SPARC mixed params with double/single float register overlapping.
  59      *
  60      * @param f1
  61      * @param d2
  62      * @param f3
  63      * @return Must always return the argument d2
  64      */
  65     @SuppressWarnings("all")
  66     public static double test2(int i1, float f1, double d2, float f3,
  67 // @formatter:off
  68                     double ad1,
  69                     double ad2,
  70                     double ad3,
  71                     double ad4,
  72                     double ad5,
  73                     double ad6,
  74                     double ad7,
  75                     double ad8,
  76                     double ad9,
  77                     double ad10,
  78                     double ad11,
  79                     double ad12,
  80                     double ad13,
  81                     double ad14,
  82                     double ad15,
  83                     double ad16,
  84                     float  af1,
  85                     float  af2,
  86                     float  af3,
  87                     float  af4,
  88                     float  af5,
  89                     float  af6,
  90                     float  af7,
  91                     float  af8,
  92                     float  af9,
  93                     float  af10,
  94                     float  af11,
  95                     float  af12,
  96                     float  af13,
  97                     float  af14,
  98                     float  af15,
  99                     float  af16
 100     // @formatter:on
 101     ) {
 102 
 103         // now do something with the locals to make sure the locals don't get optimized away.
 104         for (int i = 0; i < i1; i++) {
 105             af1 += f1;
 106             af2 += f1;
 107             af3 += f1;
 108             af4 += f1;
 109             af5 += f1;
 110             af6 += f1;
 111             af7 += f1;
 112             af8 += f1;
 113             af9 += f1;
 114             af10 += f1;
 115             af11 += f1;
 116             af12 += f1;
 117             af13 += f1;
 118             af14 += f1;
 119             af15 += f1;
 120             af16 += f1;
 121             ad1 += f1;
 122             ad2 += f1;
 123             ad3 += f1;
 124             ad4 += f1;
 125             ad5 += f1;
 126             ad6 += f1;
 127             ad7 += f1;
 128             ad8 += f1;
 129             ad9 += f1;
 130             ad10 += f1;
 131             ad11 += f1;
 132             ad12 += f1;
 133             ad13 += f1;
 134             ad14 += f1;
 135             ad15 += f1;
 136             ad16 += f1;
 137         }
 138         // @formatter:off
 139         boolean orderFloat =
 140                         af1  < af2  &&
 141                         af2  < af3  &&
 142                         af3  < af4  &&
 143                         af4  < af5  &&
 144                         af5  < af6  &&
 145                         af6  < af7  &&
 146                         af7  < af8  &&
 147                         af8  < af9  &&
 148                         af9  < af10 &&
 149                         af10 < af11 &&
 150                         af11 < af12 &&
 151                         af12 < af13 &&
 152                         af13 < af14 &&
 153                         af14 < af15 &&
 154                         af15 < af16;
 155         boolean orderDouble =
 156                         ad1  < ad2  &&
 157                         ad2  < ad3  &&
 158                         ad3  < ad4  &&
 159                         ad4  < ad5  &&
 160                         ad5  < ad6  &&
 161                         ad6  < ad7  &&
 162                         ad7  < ad8  &&
 163                         ad8  < ad9  &&
 164                         ad9  < ad10 &&
 165                         ad10 < ad11 &&
 166                         ad11 < ad12 &&
 167                         ad12 < ad13 &&
 168                         ad13 < ad14 &&
 169                         ad14 < ad15 &&
 170                         ad15 < ad16;
 171         // @formatter:on
 172         if (orderDouble && orderFloat) {
 173             return f1 + d2 + f3; // this should not be destroyed
 174         }
 175         Assert.fail();
 176         return 0.0;
 177     }
 178 
 179     /**
 180      * Test SPARC mixed params with double/single float register overlapping.
 181      *
 182      * @param f1
 183      * @param d2
 184      * @param f3
 185      * @return Must always return the argument d2
 186      */
 187     @SuppressWarnings("all")
 188     public static double test3(boolean f, int idx,
 189 // @formatter:off
 190                     double ad1,
 191                     double ad2,
 192                     double ad3,
 193                     double ad4,
 194                     double ad5,
 195                     double ad6,
 196                     double ad7,
 197                     double ad8,
 198                     double ad9,
 199                     double ad10,
 200                     double ad11,
 201                     double ad12,
 202                     double ad13,
 203                     double ad14,
 204                     double ad15,
 205                     double ad16,
 206                     float  af1,
 207                     float  af2,
 208                     float  af3,
 209                     float  af4,
 210                     float  af5,
 211                     float  af6,
 212                     float  af7,
 213                     float  af8,
 214                     float  af9,
 215                     float  af10,
 216                     float  af11,
 217                     float  af12,
 218                     float  af13,
 219                     float  af14,
 220                     float  af15,
 221                     float  af16
 222     ) {
 223         switch(f ? idx + 16 : idx) {
 224             case 1 : return ad1;
 225             case 2 : return ad2;
 226             case 3 : return ad3;
 227             case 4 : return ad4;
 228             case 5 : return ad5;
 229             case 6 : return ad6;
 230             case 7 : return ad7;
 231             case 8 : return ad8;
 232             case 9 : return ad9;
 233             case 10: return ad10;
 234             case 11: return ad11;
 235             case 12: return ad12;
 236             case 13: return ad13;
 237             case 14: return ad14;
 238             case 15: return ad15;
 239             case 16: return ad16;
 240             case 1  + 16: return af1;
 241             case 2  + 16: return af2;
 242             case 3  + 16: return af3;
 243             case 4  + 16: return af4;
 244             case 5  + 16: return af5;
 245             case 6  + 16: return af6;
 246             case 7  + 16: return af7;
 247             case 8  + 16: return af8;
 248             case 9  + 16: return af9;
 249             case 10 + 16: return af10;
 250             case 11 + 16: return af11;
 251             case 12 + 16: return af12;
 252             case 13 + 16: return af13;
 253             case 14 + 16: return af14;
 254             case 15 + 16: return af15;
 255             case 16 + 16: return af16;
 256         }
 257         Assert.fail(); // should not reach here
 258         return 0;
 259 
 260     }
 261     // @formatter:on
 262 
 263     @Test
 264     public void run0() throws Throwable {
 265         runTest("test", 0, -1, -1, -1, -1, 1d, 2d, true, false, (byte) -128, (short) -0x7FFF, (char) 0xFFFF, -0x7FFFFFF);
 266     }
 267 
 268     @Test
 269     public void run1() throws Throwable {
 270         runTest("test", 1, -1, -1, -1, -1, 1d, 2d, true, false, (byte) -128, (short) -0x7FFF, (char) 0xFFFF, -0x7FFFFFF);
 271     }
 272 
 273     @Test
 274     public void run2() throws Throwable {
 275         runTest("test", 2, -1, -1, -1, -1, 1d, 2d, true, false, (byte) -128, (short) -0x7FFF, (char) 0xFFFF, -0x7FFFFFF);
 276     }
 277 
 278     @Test
 279     public void run3() throws Throwable {
 280         runTest("test", 3, -1, -1, -1, -1, 1d, 2d, true, false, (byte) -128, (short) -0x7FFF, (char) 0xFFFF, -0x7FFFFFF);
 281     }
 282 
 283     @Test
 284     public void run4() throws Throwable {
 285         runTest("test", 4, -1, -1, -1, -1, 1d, 2d, true, false, (byte) -128, (short) -0x7FFF, (char) 0xFFFF, -0x7FFFFFF);
 286     }
 287 
 288     @Test
 289     public void run5() throws Throwable {
 290         runTest("test", 5, -1, -1, -1, -1, 1d, 2d, true, false, (byte) -128, (short) -0x7FFF, (char) 0xFFFF, -0x7FFFFFF);
 291     }
 292 
 293     @Test
 294     public void run6() throws Throwable {
 295         // @formatter:off
 296         runTest("test2", 20, 1.0f, -3.2912948246387967943231233d, 3.0f,
 297                         1d,
 298                         2d,
 299                         3d,
 300                         4d,
 301                         5d,
 302                         6d,
 303                         7d,
 304                         8d,
 305                         9d,
 306                         10d,
 307                         11d,
 308                         12d,
 309                         13d,
 310                         14d,
 311                         15d,
 312                         16d,
 313                         1f,
 314                         2f,
 315                         3f,
 316                         4f,
 317                         5f,
 318                         6f,
 319                         7f,
 320                         8f,
 321                         9f,
 322                         10f,
 323                         11f,
 324                         12f,
 325                         13f,
 326                         14f,
 327                         15f,
 328                         16f
 329                         );
 330         // @formatter:on
 331     }
 332 
 333     @Test
 334     public void run7() throws Throwable {
 335         // @formatter:off
 336         for (int i = 0; i < 32 * 2; i++) {
 337         runTest("test3", i % 2 == 0, i / 2,
 338                         1d,
 339                         2d,
 340                         3d,
 341                         4d,
 342                         5d,
 343                         6d,
 344                         7d,
 345                         8d,
 346                         9d,
 347                         10d,
 348                         11d,
 349                         12d,
 350                         13d,
 351                         14d,
 352                         15d,
 353                         16d,
 354                         1f,
 355                         2f,
 356                         3f,
 357                         4f,
 358                         5f,
 359                         6f,
 360                         7f,
 361                         8f,
 362                         9f,
 363                         10f,
 364                         11f,
 365                         12f,
 366                         13f,
 367                         14f,
 368                         15f,
 369                         16f
 370                         );
 371         }
 372         // @formatter:on
 373     }
 374 
 375 }