1 /* 2 * Copyright (c) 2020, 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.openjdk.bench.valhalla.ackermann; 24 25 import org.openjdk.bench.valhalla.types.Int64; 26 import org.openjdk.bench.valhalla.types.R64long; 27 import org.openjdk.jmh.annotations.Benchmark; 28 import org.openjdk.jmh.annotations.OperationsPerInvocation; 29 30 public class Identity64long extends AckermannBase { 31 32 private static R64long ack_ref(R64long x, R64long y) { 33 return x.longValue() == 0 ? 34 new R64long(y.longValue() + 1) : 35 (y.longValue() == 0 ? 36 ack_ref(new R64long(x.longValue()-1) , new R64long(1)) : 37 ack_ref(new R64long(x.longValue()-1), ack_ref(x, new R64long(y.longValue()-1)))); 38 } 39 40 @Benchmark 41 @OperationsPerInvocation(OPI) 42 public long ack_Ref() { 43 return ack_ref(new R64long(X1), new R64long(Y1)).longValue() 44 + ack_ref(new R64long(X2), new R64long(Y2)).longValue() 45 + ack_ref(new R64long(X3), new R64long(Y3)).longValue(); 46 } 47 48 private static Int64 ack_inter(Int64 x, Int64 y) { 49 return x.longValue() == 0 ? 50 new R64long(y.longValue() + 1) : 51 (y.longValue() == 0 ? 52 ack_inter(new R64long(x.longValue()-1) , new R64long(1)) : 53 ack_inter(new R64long(x.longValue()-1), ack_inter(x, new R64long(y.longValue()-1)))); 54 } 55 56 @Benchmark 57 @OperationsPerInvocation(OPI) 58 public long ack_Int() { 59 return ack_inter(new R64long(X1), new R64long(Y1)).longValue() 60 + ack_inter(new R64long(X2), new R64long(Y2)).longValue() 61 + ack_inter(new R64long(X3), new R64long(Y3)).longValue(); 62 } 63 64 }