xref: /aosp_15_r20/art/test/642-fp-callees/fp_callees.cc (revision 795d594fd825385562da6b089ea9b2033f3abf5a)
1*795d594fSAndroid Build Coastguard Worker /*
2*795d594fSAndroid Build Coastguard Worker  * Copyright (C) 2017 The Android Open Source Project
3*795d594fSAndroid Build Coastguard Worker  *
4*795d594fSAndroid Build Coastguard Worker  * Licensed under the Apache License, Version 2.0 (the "License");
5*795d594fSAndroid Build Coastguard Worker  * you may not use this file except in compliance with the License.
6*795d594fSAndroid Build Coastguard Worker  * You may obtain a copy of the License at
7*795d594fSAndroid Build Coastguard Worker  *
8*795d594fSAndroid Build Coastguard Worker  *      http://www.apache.org/licenses/LICENSE-2.0
9*795d594fSAndroid Build Coastguard Worker  *
10*795d594fSAndroid Build Coastguard Worker  * Unless required by applicable law or agreed to in writing, software
11*795d594fSAndroid Build Coastguard Worker  * distributed under the License is distributed on an "AS IS" BASIS,
12*795d594fSAndroid Build Coastguard Worker  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13*795d594fSAndroid Build Coastguard Worker  * See the License for the specific language governing permissions and
14*795d594fSAndroid Build Coastguard Worker  * limitations under the License.
15*795d594fSAndroid Build Coastguard Worker  */
16*795d594fSAndroid Build Coastguard Worker 
17*795d594fSAndroid Build Coastguard Worker #include <android-base/logging.h>
18*795d594fSAndroid Build Coastguard Worker 
19*795d594fSAndroid Build Coastguard Worker #include "base/casts.h"
20*795d594fSAndroid Build Coastguard Worker #include "jni.h"
21*795d594fSAndroid Build Coastguard Worker 
22*795d594fSAndroid Build Coastguard Worker namespace art {
23*795d594fSAndroid Build Coastguard Worker 
24*795d594fSAndroid Build Coastguard Worker // Make the array volatile, which is apparently making the C compiler
25*795d594fSAndroid Build Coastguard Worker // use FP registers in the method below.
26*795d594fSAndroid Build Coastguard Worker volatile double array[] = { 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0, 9.0, 10.0, 11.0, 12.0 };
27*795d594fSAndroid Build Coastguard Worker 
Java_Main_holdFpTemporaries(JNIEnv * env,jclass cls)28*795d594fSAndroid Build Coastguard Worker extern "C" JNIEXPORT void JNICALL Java_Main_holdFpTemporaries(JNIEnv* env, jclass cls) {
29*795d594fSAndroid Build Coastguard Worker   jmethodID mid = env->GetStaticMethodID(cls, "caller", "(IIJ)V");
30*795d594fSAndroid Build Coastguard Worker   CHECK(mid != nullptr);
31*795d594fSAndroid Build Coastguard Worker   // Load values from the arrays, which will be loaded in callee-save FP registers.
32*795d594fSAndroid Build Coastguard Worker   double a = array[0];
33*795d594fSAndroid Build Coastguard Worker   double b = array[1];
34*795d594fSAndroid Build Coastguard Worker   double c = array[2];
35*795d594fSAndroid Build Coastguard Worker   double d = array[3];
36*795d594fSAndroid Build Coastguard Worker   double e = array[4];
37*795d594fSAndroid Build Coastguard Worker   double f = array[5];
38*795d594fSAndroid Build Coastguard Worker   double g = array[6];
39*795d594fSAndroid Build Coastguard Worker   double h = array[7];
40*795d594fSAndroid Build Coastguard Worker   double i = array[8];
41*795d594fSAndroid Build Coastguard Worker   double j = array[9];
42*795d594fSAndroid Build Coastguard Worker   double k = array[10];
43*795d594fSAndroid Build Coastguard Worker   double l = array[11];
44*795d594fSAndroid Build Coastguard Worker   env->CallStaticVoidMethod(cls, mid, 1, 1, 1L);
45*795d594fSAndroid Build Coastguard Worker   // Load it in a temporary to please C compiler with bit_cast.
46*795d594fSAndroid Build Coastguard Worker   double temp = array[0];
47*795d594fSAndroid Build Coastguard Worker   CHECK_EQ(bit_cast<int64_t>(a), bit_cast<int64_t>(temp));
48*795d594fSAndroid Build Coastguard Worker   temp = array[1];
49*795d594fSAndroid Build Coastguard Worker   CHECK_EQ(bit_cast<int64_t>(b), bit_cast<int64_t>(temp));
50*795d594fSAndroid Build Coastguard Worker   temp = array[2];
51*795d594fSAndroid Build Coastguard Worker   CHECK_EQ(bit_cast<int64_t>(c), bit_cast<int64_t>(temp));
52*795d594fSAndroid Build Coastguard Worker   temp = array[3];
53*795d594fSAndroid Build Coastguard Worker   CHECK_EQ(bit_cast<int64_t>(d), bit_cast<int64_t>(temp));
54*795d594fSAndroid Build Coastguard Worker   temp = array[4];
55*795d594fSAndroid Build Coastguard Worker   CHECK_EQ(bit_cast<int64_t>(e), bit_cast<int64_t>(temp));
56*795d594fSAndroid Build Coastguard Worker   temp = array[5];
57*795d594fSAndroid Build Coastguard Worker   CHECK_EQ(bit_cast<int64_t>(f), bit_cast<int64_t>(temp));
58*795d594fSAndroid Build Coastguard Worker   temp = array[6];
59*795d594fSAndroid Build Coastguard Worker   CHECK_EQ(bit_cast<int64_t>(g), bit_cast<int64_t>(temp));
60*795d594fSAndroid Build Coastguard Worker   temp = array[7];
61*795d594fSAndroid Build Coastguard Worker   CHECK_EQ(bit_cast<int64_t>(h), bit_cast<int64_t>(temp));
62*795d594fSAndroid Build Coastguard Worker   temp = array[8];
63*795d594fSAndroid Build Coastguard Worker   CHECK_EQ(bit_cast<int64_t>(i), bit_cast<int64_t>(temp));
64*795d594fSAndroid Build Coastguard Worker   temp = array[9];
65*795d594fSAndroid Build Coastguard Worker   CHECK_EQ(bit_cast<int64_t>(j), bit_cast<int64_t>(temp));
66*795d594fSAndroid Build Coastguard Worker   temp = array[10];
67*795d594fSAndroid Build Coastguard Worker   CHECK_EQ(bit_cast<int64_t>(k), bit_cast<int64_t>(temp));
68*795d594fSAndroid Build Coastguard Worker   temp = array[11];
69*795d594fSAndroid Build Coastguard Worker   CHECK_EQ(bit_cast<int64_t>(l), bit_cast<int64_t>(temp));
70*795d594fSAndroid Build Coastguard Worker }
71*795d594fSAndroid Build Coastguard Worker 
72*795d594fSAndroid Build Coastguard Worker }  // namespace art
73