Path: blob/master/test/hotspot/jtreg/compiler/floatingpoint/libTestFloatSyncJNIArgs.c
41152 views
/*1* Copyright (c) 2018 Red Hat, Inc. All rights reserved.2* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.3*4* This code is free software; you can redistribute it and/or modify it5* under the terms of the GNU General Public License version 2 only, as6* published by the Free Software Foundation.7*8* This code is distributed in the hope that it will be useful, but WITHOUT9* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or10* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License11* version 2 for more details (a copy is included in the LICENSE file that12* accompanied this code).13*14* You should have received a copy of the GNU General Public License version15* 2 along with this work; if not, write to the Free Software Foundation,16* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.17*18* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA19* or visit www.oracle.com if you need additional information or have any20* questions.21*/2223#include <jni.h>2425#ifdef __cplusplus26extern "C" {27#endif2829/* Fletcher checksum. This is a nonlinear function which detects both */30/* missing or otherwise incorrect arguments and arguments in the wrong */31/* order. */32static jfloat fcombine(jfloat f[], int len) {33int i;34jfloat sum = 0, sum_of_sums = 0;35for (i = 0; i < len; i++) {36sum += f[i];37sum_of_sums += sum;38}39return sum + sum_of_sums * sum;40}4142static jdouble combine(jdouble f[], int len) {43int i;44double sum = 0, sum_of_sums = 0;45for (i = 0; i < len; i++) {46sum += f[i];47sum_of_sums += sum;48}49return sum + sum_of_sums * sum;50}5152JNIEXPORT jfloat JNICALL Java_compiler_floatingpoint_TestFloatSyncJNIArgs_combine15floats53(JNIEnv *env, jclass cls,54jfloat f1, jfloat f2, jfloat f3, jfloat f4,55jfloat f5, jfloat f6, jfloat f7, jfloat f8,56jfloat f9, jfloat f10, jfloat f11, jfloat f12,57jfloat f13, jfloat f14, jfloat f15) {5859jfloat f[15];60f[0] = f1; f[1] = f2; f[2] = f3; f[3] = f4; f[4] = f5;61f[5] = f6; f[6] = f7; f[7] = f8; f[8] = f9; f[9] = f10;62f[10] = f11; f[11] = f12; f[12] = f13; f[13] = f14; f[14] = f15;6364return fcombine(f, sizeof f / sizeof f[0]);65}6667JNIEXPORT jdouble JNICALL Java_compiler_floatingpoint_TestFloatSyncJNIArgs_combine15doubles68(JNIEnv *env, jclass cls,69jdouble f1, jdouble f2, jdouble f3, jdouble f4,70jdouble f5, jdouble f6, jdouble f7, jdouble f8,71jdouble f9, jdouble f10, jdouble f11, jdouble f12,72jdouble f13, jdouble f14, jdouble f15) {7374jdouble f[15];75f[0] = f1; f[1] = f2; f[2] = f3; f[3] = f4; f[4] = f5;76f[5] = f6; f[6] = f7; f[7] = f8; f[8] = f9; f[9] = f10;77f[10] = f11; f[11] = f12; f[12] = f13; f[13] = f14; f[14] = f15;7879return combine(f, sizeof f / sizeof f[0]);80}818283#ifdef __cplusplus84}85#endif868788