test/compiler/testlibrary/sha/predicate/IntrinsicPredicates.java

Tue, 18 Jun 2019 09:33:34 -0400

author
ogatak
date
Tue, 18 Jun 2019 09:33:34 -0400
changeset 9713
c4567d28f31f
parent 7142
4d8781a35525
permissions
-rw-r--r--

8185979: PPC64: Implement SHA2 intrinsic
Reviewed-by: mdoerr, goetz
Contributed-by: Bruno Rosa <bruno.rosa@eldorado.org.br>, Gustavo Serra Scalet <gustavo.scalet@eldorado.org.br>, Igor Nunes <igor.nunes@eldorado.org.br>, Martin Doerr <martin.doerr@sap.com>

fzhinkin@7142 1 /*
fzhinkin@7142 2 * Copyright (c) 2014, Oracle and/or its affiliates. All rights reserved.
fzhinkin@7142 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
fzhinkin@7142 4 *
fzhinkin@7142 5 * This code is free software; you can redistribute it and/or modify it
fzhinkin@7142 6 * under the terms of the GNU General Public License version 2 only, as
fzhinkin@7142 7 * published by the Free Software Foundation.
fzhinkin@7142 8 *
fzhinkin@7142 9 * This code is distributed in the hope that it will be useful, but WITHOUT
fzhinkin@7142 10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
fzhinkin@7142 11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
fzhinkin@7142 12 * version 2 for more details (a copy is included in the LICENSE file that
fzhinkin@7142 13 * accompanied this code).
fzhinkin@7142 14 *
fzhinkin@7142 15 * You should have received a copy of the GNU General Public License version
fzhinkin@7142 16 * 2 along with this work; if not, write to the Free Software Foundation,
fzhinkin@7142 17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
fzhinkin@7142 18 *
fzhinkin@7142 19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
fzhinkin@7142 20 * or visit www.oracle.com if you need additional information or have any
fzhinkin@7142 21 * questions.
fzhinkin@7142 22 */
fzhinkin@7142 23
fzhinkin@7142 24 package sha.predicate;
fzhinkin@7142 25
fzhinkin@7142 26 import com.oracle.java.testlibrary.Platform;
fzhinkin@7142 27 import com.oracle.java.testlibrary.cli.predicate.AndPredicate;
fzhinkin@7142 28 import com.oracle.java.testlibrary.cli.predicate.CPUSpecificPredicate;
fzhinkin@7142 29 import com.oracle.java.testlibrary.cli.predicate.OrPredicate;
fzhinkin@7142 30 import sun.hotspot.WhiteBox;
fzhinkin@7142 31
fzhinkin@7142 32 import java.util.function.BooleanSupplier;
fzhinkin@7142 33
fzhinkin@7142 34 /**
fzhinkin@7142 35 * Helper class aimed to provide predicates on availability of SHA-related
fzhinkin@7142 36 * CPU instructions and intrinsics.
fzhinkin@7142 37 */
fzhinkin@7142 38 public class IntrinsicPredicates {
fzhinkin@7142 39 private static final WhiteBox WHITE_BOX = WhiteBox.getWhiteBox();
fzhinkin@7142 40 private static final long TIERED_MAX_LEVEL = 4L;
fzhinkin@7142 41 /**
fzhinkin@7142 42 * Boolean supplier that check if any method could be compiled by C2.
fzhinkin@7142 43 * Method potentially could be compiled by C2 if Server VM is used and
fzhinkin@7142 44 * either tiered compilation is disabled or TIERED_MAX_LEVEL tier is
fzhinkin@7142 45 * reachable.
fzhinkin@7142 46 *
fzhinkin@7142 47 * Please don't place this definition after SHA*_INTRINSICS_AVAILABLE
fzhinkin@7142 48 * definitions. Otherwise its value will be {@code null} at the time when
fzhinkin@7142 49 * all dependent fields will be initialized.
fzhinkin@7142 50 */
fzhinkin@7142 51 private static final BooleanSupplier COMPILABLE_BY_C2 = () -> {
fzhinkin@7142 52 boolean isTiered = IntrinsicPredicates.WHITE_BOX.getBooleanVMFlag(
fzhinkin@7142 53 "TieredCompilation");
fzhinkin@7142 54 long tieredMaxLevel = IntrinsicPredicates.WHITE_BOX.getIntxVMFlag(
fzhinkin@7142 55 "TieredStopAtLevel");
fzhinkin@7142 56 boolean maxLevelIsReachable = (tieredMaxLevel
fzhinkin@7142 57 == IntrinsicPredicates.TIERED_MAX_LEVEL);
fzhinkin@7142 58 return Platform.isServer() && (!isTiered || maxLevelIsReachable);
fzhinkin@7142 59 };
fzhinkin@7142 60
fzhinkin@7142 61 public static final BooleanSupplier SHA1_INSTRUCTION_AVAILABLE
fzhinkin@7142 62 = new CPUSpecificPredicate("sparc.*", new String[] { "sha1" },
fzhinkin@7142 63 null);
fzhinkin@7142 64
fzhinkin@7142 65 public static final BooleanSupplier SHA256_INSTRUCTION_AVAILABLE
ogatak@9713 66 = new OrPredicate(new CPUSpecificPredicate("sparc.*", new String[] { "sha256" },
ogatak@9713 67 null),
ogatak@9713 68 new OrPredicate(new CPUSpecificPredicate("ppc64.*", new String[] { "sha" },
ogatak@9713 69 null),
ogatak@9713 70 new CPUSpecificPredicate("ppc64le.*", new String[] { "sha" },
ogatak@9713 71 null)));
fzhinkin@7142 72
fzhinkin@7142 73 public static final BooleanSupplier SHA512_INSTRUCTION_AVAILABLE
ogatak@9713 74 = new OrPredicate(new CPUSpecificPredicate("sparc.*", new String[] { "sha512" },
ogatak@9713 75 null),
ogatak@9713 76 new OrPredicate(new CPUSpecificPredicate("ppc64.*", new String[] { "sha" },
ogatak@9713 77 null),
ogatak@9713 78 new CPUSpecificPredicate("ppc64le.*", new String[] { "sha" },
ogatak@9713 79 null)));
fzhinkin@7142 80
fzhinkin@7142 81 public static final BooleanSupplier ANY_SHA_INSTRUCTION_AVAILABLE
fzhinkin@7142 82 = new OrPredicate(IntrinsicPredicates.SHA1_INSTRUCTION_AVAILABLE,
fzhinkin@7142 83 new OrPredicate(
fzhinkin@7142 84 IntrinsicPredicates.SHA256_INSTRUCTION_AVAILABLE,
fzhinkin@7142 85 IntrinsicPredicates.SHA512_INSTRUCTION_AVAILABLE));
fzhinkin@7142 86
fzhinkin@7142 87 public static final BooleanSupplier SHA1_INTRINSICS_AVAILABLE
fzhinkin@7142 88 = new AndPredicate(new AndPredicate(
fzhinkin@7142 89 IntrinsicPredicates.SHA1_INSTRUCTION_AVAILABLE,
fzhinkin@7142 90 IntrinsicPredicates.COMPILABLE_BY_C2),
fzhinkin@7142 91 IntrinsicPredicates.booleanOptionValue("UseSHA1Intrinsics"));
fzhinkin@7142 92
fzhinkin@7142 93 public static final BooleanSupplier SHA256_INTRINSICS_AVAILABLE
fzhinkin@7142 94 = new AndPredicate(new AndPredicate(
fzhinkin@7142 95 IntrinsicPredicates.SHA256_INSTRUCTION_AVAILABLE,
fzhinkin@7142 96 IntrinsicPredicates.COMPILABLE_BY_C2),
fzhinkin@7142 97 IntrinsicPredicates.booleanOptionValue("UseSHA256Intrinsics"));
fzhinkin@7142 98
fzhinkin@7142 99 public static final BooleanSupplier SHA512_INTRINSICS_AVAILABLE
fzhinkin@7142 100 = new AndPredicate(new AndPredicate(
fzhinkin@7142 101 IntrinsicPredicates.SHA512_INSTRUCTION_AVAILABLE,
fzhinkin@7142 102 IntrinsicPredicates.COMPILABLE_BY_C2),
fzhinkin@7142 103 IntrinsicPredicates.booleanOptionValue("UseSHA512Intrinsics"));
fzhinkin@7142 104
fzhinkin@7142 105 private static BooleanSupplier booleanOptionValue(String option) {
fzhinkin@7142 106 return () -> IntrinsicPredicates.WHITE_BOX.getBooleanVMFlag(option);
fzhinkin@7142 107 }
fzhinkin@7142 108
fzhinkin@7142 109 private IntrinsicPredicates() {
fzhinkin@7142 110 }
fzhinkin@7142 111 }

mercurial