1 /*
   2  * Copyright (c) 2015, 2015, 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 package org.graalvm.compiler.jtt.loop;
  24 
  25 import org.junit.Test;
  26 
  27 import org.graalvm.compiler.jtt.JTTTest;
  28 
  29 public class LoopSpilling extends JTTTest {
  30 
  31     private static final int ITERATION = 64;
  32 
  33     /**
  34      * Modification of sun.security.provider.SHA2.implCompress().
  35      */
  36     void test(int[] state) {
  37 
  38         int a1 = state[0];
  39         int b1 = state[1];
  40         int c1 = state[2];
  41         int d1 = state[3];
  42         int e1 = state[4];
  43         int f1 = state[5];
  44         int g1 = state[6];
  45         int h1 = state[7];
  46 
  47         // 2nd
  48         int a2 = state[8];
  49         int b2 = state[9];
  50         int c2 = state[10];
  51         int d2 = state[11];
  52         int e2 = state[12];
  53         int f2 = state[13];
  54         int g2 = state[14];
  55         int h2 = state[15];
  56 
  57         for (int i = 0; i < ITERATION; i++) {
  58             h1 = g1;
  59             g1 = f1;
  60             f1 = e1;
  61             e1 = d1;
  62             d1 = c1;
  63             c1 = b1;
  64             b1 = a1;
  65             a1 = h1;
  66             // 2nd
  67             h2 = g2;
  68             g2 = f2;
  69             f2 = e2;
  70             e2 = d2;
  71             d2 = c2;
  72             c2 = b2;
  73             b2 = a2;
  74             a2 = h2;
  75         }
  76         state[0] += a1;
  77         state[1] += b1;
  78         state[2] += c1;
  79         state[3] += d1;
  80         state[4] += e1;
  81         state[5] += f1;
  82         state[6] += g1;
  83         state[7] += h1;
  84         // 2nd
  85         state[8] += a2;
  86         state[9] += b2;
  87         state[10] += c2;
  88         state[11] += d2;
  89         state[12] += e2;
  90         state[13] += f2;
  91         state[14] += g2;
  92         state[15] += h2;
  93     }
  94 
  95     private static final int[] INITIAL_HASHES = {0xc1059ed8, 0x367cd507, 0x3070dd17, 0xf70e5939, 0xffc00b31, 0x68581511, 0x64f98fa7, 0xbefa4fa4, 0x6a09e667, 0xbb67ae85, 0x3c6ef372, 0xa54ff53a,
  96                     0x510e527f, 0x9b05688c, 0x1f83d9ab, 0x5be0cd19};
  97 
  98     @Test
  99     public void run0() throws Throwable {
 100         runTest("test", supply(() -> INITIAL_HASHES.clone()));
 101     }
 102 
 103 }