test/mips64/11080/libTestFloatSyncJNIArgs.c

Mon, 25 Nov 2019 15:36:48 +0800

author
huangjia
date
Mon, 25 Nov 2019 15:36:48 +0800
changeset 9758
122547cfa3c8
permissions
-rw-r--r--

#11080 Backport testcase of JDK-8207838 compiler/floatingpoint/TestFloatSyncJNIArgs.java
Reviewed-by: aoqi
Contributed-by: guoge1@huawei.com, huangjia

huangjia@9758 1 /*
huangjia@9758 2 * Copyright (c) 2018, 2019, Red Hat, Inc. All rights reserved.
huangjia@9758 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
huangjia@9758 4 *
huangjia@9758 5 * This code is free software; you can redistribute it and/or modify it
huangjia@9758 6 * under the terms of the GNU General Public License version 2 only, as
huangjia@9758 7 * published by the Free Software Foundation.
huangjia@9758 8 *
huangjia@9758 9 * This code is distributed in the hope that it will be useful, but WITHOUT
huangjia@9758 10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
huangjia@9758 11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
huangjia@9758 12 * version 2 for more details (a copy is included in the LICENSE file that
huangjia@9758 13 * accompanied this code).
huangjia@9758 14 *
huangjia@9758 15 * You should have received a copy of the GNU General Public License version
huangjia@9758 16 * 2 along with this work; if not, write to the Free Software Foundation,
huangjia@9758 17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
huangjia@9758 18 *
huangjia@9758 19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
huangjia@9758 20 * or visit www.oracle.com if you need additional information or have any
huangjia@9758 21 * questions.
huangjia@9758 22 */
huangjia@9758 23
huangjia@9758 24 #include <jni.h>
huangjia@9758 25
huangjia@9758 26 #ifdef __cplusplus
huangjia@9758 27 extern "C" {
huangjia@9758 28 #endif
huangjia@9758 29
huangjia@9758 30 /* Fletcher checksum. This is a nonlinear function which detects both */
huangjia@9758 31 /* missing or otherwise incorrect arguments and arguments in the wrong */
huangjia@9758 32 /* order. */
huangjia@9758 33 static jfloat fcombine(jfloat f[], int len) {
huangjia@9758 34 int i;
huangjia@9758 35 jfloat sum = 0, sum_of_sums = 0;
huangjia@9758 36 for (i = 0; i < len; i++) {
huangjia@9758 37 sum += f[i];
huangjia@9758 38 sum_of_sums += sum;
huangjia@9758 39 }
huangjia@9758 40 return sum + sum_of_sums * sum;
huangjia@9758 41 }
huangjia@9758 42
huangjia@9758 43 static jdouble combine(jdouble f[], int len) {
huangjia@9758 44 int i;
huangjia@9758 45 double sum = 0, sum_of_sums = 0;
huangjia@9758 46 for (i = 0; i < len; i++) {
huangjia@9758 47 sum += f[i];
huangjia@9758 48 sum_of_sums += sum;
huangjia@9758 49 }
huangjia@9758 50 return sum + sum_of_sums * sum;
huangjia@9758 51 }
huangjia@9758 52
huangjia@9758 53 JNIEXPORT jfloat JNICALL Java_TestFloatSyncJNIArgs_combine15floats
huangjia@9758 54 (JNIEnv *env, jclass cls,
huangjia@9758 55 jfloat f1, jfloat f2, jfloat f3, jfloat f4,
huangjia@9758 56 jfloat f5, jfloat f6, jfloat f7, jfloat f8,
huangjia@9758 57 jfloat f9, jfloat f10, jfloat f11, jfloat f12,
huangjia@9758 58 jfloat f13, jfloat f14, jfloat f15) {
huangjia@9758 59
huangjia@9758 60 jfloat f[15];
huangjia@9758 61 f[0] = f1; f[1] = f2; f[2] = f3; f[3] = f4; f[4] = f5;
huangjia@9758 62 f[5] = f6; f[6] = f7; f[7] = f8; f[8] = f9; f[9] = f10;
huangjia@9758 63 f[10] = f11; f[11] = f12; f[12] = f13; f[13] = f14; f[14] = f15;
huangjia@9758 64
huangjia@9758 65 return fcombine(f, sizeof f / sizeof f[0]);
huangjia@9758 66 }
huangjia@9758 67
huangjia@9758 68 JNIEXPORT jdouble JNICALL Java_TestFloatSyncJNIArgs_combine15doubles
huangjia@9758 69 (JNIEnv *env, jclass cls,
huangjia@9758 70 jdouble f1, jdouble f2, jdouble f3, jdouble f4,
huangjia@9758 71 jdouble f5, jdouble f6, jdouble f7, jdouble f8,
huangjia@9758 72 jdouble f9, jdouble f10, jdouble f11, jdouble f12,
huangjia@9758 73 jdouble f13, jdouble f14, jdouble f15) {
huangjia@9758 74
huangjia@9758 75 jdouble f[15];
huangjia@9758 76 f[0] = f1; f[1] = f2; f[2] = f3; f[3] = f4; f[4] = f5;
huangjia@9758 77 f[5] = f6; f[6] = f7; f[7] = f8; f[8] = f9; f[9] = f10;
huangjia@9758 78 f[10] = f11; f[11] = f12; f[12] = f13; f[13] = f14; f[14] = f15;
huangjia@9758 79
huangjia@9758 80 return combine(f, sizeof f / sizeof f[0]);
huangjia@9758 81 }
huangjia@9758 82
huangjia@9758 83
huangjia@9758 84 #ifdef __cplusplus
huangjia@9758 85 }
huangjia@9758 86 #endif

mercurial