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

     1 /*
     2  * Copyright (c) 2018, 2019, Red Hat, Inc. 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  */
    24 #include <jni.h>
    26 #ifdef __cplusplus
    27 extern "C" {
    28 #endif
    30 /* Fletcher checksum. This is a nonlinear function which detects both */
    31 /* missing or otherwise incorrect arguments and arguments in the wrong */
    32 /* order. */
    33 static jfloat fcombine(jfloat f[], int len) {
    34   int i;
    35   jfloat sum = 0, sum_of_sums = 0;
    36   for (i = 0; i < len; i++) {
    37     sum += f[i];
    38     sum_of_sums += sum;
    39   }
    40   return sum + sum_of_sums * sum;
    41 }
    43 static jdouble combine(jdouble f[], int len) {
    44   int i;
    45   double sum = 0, sum_of_sums = 0;
    46   for (i = 0; i < len; i++) {
    47     sum += f[i];
    48     sum_of_sums += sum;
    49   }
    50   return sum + sum_of_sums * sum;
    51 }
    53 JNIEXPORT jfloat JNICALL Java_TestFloatSyncJNIArgs_combine15floats
    54   (JNIEnv *env, jclass cls,
    55    jfloat  f1, jfloat  f2, jfloat  f3, jfloat  f4,
    56    jfloat  f5, jfloat  f6, jfloat  f7, jfloat  f8,
    57    jfloat  f9, jfloat f10, jfloat f11, jfloat f12,
    58    jfloat f13, jfloat f14, jfloat f15) {
    60   jfloat f[15];
    61   f[0] = f1; f[1] = f2; f[2] = f3; f[3] = f4; f[4] = f5;
    62   f[5] = f6; f[6] = f7; f[7] = f8; f[8] = f9; f[9] = f10;
    63   f[10] = f11; f[11] = f12; f[12] = f13; f[13] = f14; f[14] = f15;
    65   return fcombine(f, sizeof f / sizeof f[0]);
    66 }
    68 JNIEXPORT jdouble JNICALL Java_TestFloatSyncJNIArgs_combine15doubles
    69   (JNIEnv *env, jclass cls,
    70    jdouble  f1, jdouble  f2, jdouble  f3, jdouble  f4,
    71    jdouble  f5, jdouble  f6, jdouble  f7, jdouble  f8,
    72    jdouble  f9, jdouble f10, jdouble f11, jdouble f12,
    73    jdouble f13, jdouble f14, jdouble f15) {
    75   jdouble f[15];
    76   f[0] = f1; f[1] = f2; f[2] = f3; f[3] = f4; f[4] = f5;
    77   f[5] = f6; f[6] = f7; f[7] = f8; f[8] = f9; f[9] = f10;
    78   f[10] = f11; f[11] = f12; f[12] = f13; f[13] = f14; f[14] = f15;
    80   return combine(f, sizeof f / sizeof f[0]);
    81 }
    84 #ifdef __cplusplus
    85 }
    86 #endif

mercurial