test/mips64/11080/libTestFloatSyncJNIArgs.c

changeset 9758
122547cfa3c8
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/test/mips64/11080/libTestFloatSyncJNIArgs.c	Mon Nov 25 15:36:48 2019 +0800
     1.3 @@ -0,0 +1,86 @@
     1.4 +/*
     1.5 + * Copyright (c) 2018, 2019, Red Hat, Inc. All rights reserved.
     1.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
     1.7 + *
     1.8 + * This code is free software; you can redistribute it and/or modify it
     1.9 + * under the terms of the GNU General Public License version 2 only, as
    1.10 + * published by the Free Software Foundation.
    1.11 + *
    1.12 + * This code is distributed in the hope that it will be useful, but WITHOUT
    1.13 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
    1.14 + * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
    1.15 + * version 2 for more details (a copy is included in the LICENSE file that
    1.16 + * accompanied this code).
    1.17 + *
    1.18 + * You should have received a copy of the GNU General Public License version
    1.19 + * 2 along with this work; if not, write to the Free Software Foundation,
    1.20 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
    1.21 + *
    1.22 + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
    1.23 + * or visit www.oracle.com if you need additional information or have any
    1.24 + * questions.
    1.25 + */
    1.26 +
    1.27 +#include <jni.h>
    1.28 +
    1.29 +#ifdef __cplusplus
    1.30 +extern "C" {
    1.31 +#endif
    1.32 +
    1.33 +/* Fletcher checksum. This is a nonlinear function which detects both */
    1.34 +/* missing or otherwise incorrect arguments and arguments in the wrong */
    1.35 +/* order. */
    1.36 +static jfloat fcombine(jfloat f[], int len) {
    1.37 +  int i;
    1.38 +  jfloat sum = 0, sum_of_sums = 0;
    1.39 +  for (i = 0; i < len; i++) {
    1.40 +    sum += f[i];
    1.41 +    sum_of_sums += sum;
    1.42 +  }
    1.43 +  return sum + sum_of_sums * sum;
    1.44 +}
    1.45 +
    1.46 +static jdouble combine(jdouble f[], int len) {
    1.47 +  int i;
    1.48 +  double sum = 0, sum_of_sums = 0;
    1.49 +  for (i = 0; i < len; i++) {
    1.50 +    sum += f[i];
    1.51 +    sum_of_sums += sum;
    1.52 +  }
    1.53 +  return sum + sum_of_sums * sum;
    1.54 +}
    1.55 +
    1.56 +JNIEXPORT jfloat JNICALL Java_TestFloatSyncJNIArgs_combine15floats
    1.57 +  (JNIEnv *env, jclass cls,
    1.58 +   jfloat  f1, jfloat  f2, jfloat  f3, jfloat  f4,
    1.59 +   jfloat  f5, jfloat  f6, jfloat  f7, jfloat  f8,
    1.60 +   jfloat  f9, jfloat f10, jfloat f11, jfloat f12,
    1.61 +   jfloat f13, jfloat f14, jfloat f15) {
    1.62 +
    1.63 +  jfloat f[15];
    1.64 +  f[0] = f1; f[1] = f2; f[2] = f3; f[3] = f4; f[4] = f5;
    1.65 +  f[5] = f6; f[6] = f7; f[7] = f8; f[8] = f9; f[9] = f10;
    1.66 +  f[10] = f11; f[11] = f12; f[12] = f13; f[13] = f14; f[14] = f15;
    1.67 +
    1.68 +  return fcombine(f, sizeof f / sizeof f[0]);
    1.69 +}
    1.70 +
    1.71 +JNIEXPORT jdouble JNICALL Java_TestFloatSyncJNIArgs_combine15doubles
    1.72 +  (JNIEnv *env, jclass cls,
    1.73 +   jdouble  f1, jdouble  f2, jdouble  f3, jdouble  f4,
    1.74 +   jdouble  f5, jdouble  f6, jdouble  f7, jdouble  f8,
    1.75 +   jdouble  f9, jdouble f10, jdouble f11, jdouble f12,
    1.76 +   jdouble f13, jdouble f14, jdouble f15) {
    1.77 +
    1.78 +  jdouble f[15];
    1.79 +  f[0] = f1; f[1] = f2; f[2] = f3; f[3] = f4; f[4] = f5;
    1.80 +  f[5] = f6; f[6] = f7; f[7] = f8; f[8] = f9; f[9] = f10;
    1.81 +  f[10] = f11; f[11] = f12; f[12] = f13; f[13] = f14; f[14] = f15;
    1.82 +
    1.83 +  return combine(f, sizeof f / sizeof f[0]);
    1.84 +}
    1.85 +
    1.86 +
    1.87 +#ifdef __cplusplus
    1.88 +}
    1.89 +#endif

mercurial