1 /* 2 * Copyright (C) 2017 The Android Open Source Project 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); 5 * you may not use this file except in compliance with the License. 6 * You may obtain a copy of the License at 7 * 8 * http://www.apache.org/licenses/LICENSE-2.0 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 * See the License for the specific language governing permissions and 14 * limitations under the License. 15 */ 16 17 /** 18 * Tests of varying trip counts. Focused on testing 19 * core and cleanup loop after vectorization. 20 */ 21 public class Main { 22 23 static int[] sA; 24 25 static void init() { 26 for (int i = 0; i < sA.length; i++) 27 sA[i] = 100; 28 } 29 30 static void doitTo(int n) { 31 for (int i = 0; i < n; i++) 32 sA[i] += 1; 33 } 34 35 static void doitFrom(int n) { 36 for (int i = n; i < sA.length; i++) 37 sA[i] += 1; 38 } 39 40 static void verify(int n) { 41 for (int i = 0; i < n; i++) 42 if (sA[i] != 101) 43 throw new Error("failed inside loop"); 44 for (int i = n; i < sA.length; i++) 45 if (sA[i] != 100) 46 throw new Error("failed outside loop"); 47 } 48 49 static void verify() { 50 for (int i = 0; i < sA.length; i++) 51 if (sA[i] != 101) 52 throw new Error("failed inside loop"); 53 } 54 55 static void driver() { 56 for (int n = 0; n <= sA.length; n++) { 57 init(); 58 doitTo(n); 59 verify(n); 60 doitFrom(n); 61 verify(); 62 } 63 } 64 65 public static void main(String[] args) { 66 sA = new int[17]; 67 driver(); 68 sA = new int[32]; 69 driver(); 70 System.out.println("passed"); 71 } 72 } 73 74