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