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 <android-base/logging.h>
18
19 #include "base/casts.h"
20 #include "jni.h"
21
22 namespace art {
23
24 // Make the array volatile, which is apparently making the C compiler
25 // use FP registers in the method below.
26 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
Java_Main_holdFpTemporaries(JNIEnv * env,jclass cls)28 extern "C" JNIEXPORT void JNICALL Java_Main_holdFpTemporaries(JNIEnv* env, jclass cls) {
29 jmethodID mid = env->GetStaticMethodID(cls, "caller", "(IIJ)V");
30 CHECK(mid != nullptr);
31 // Load values from the arrays, which will be loaded in callee-save FP registers.
32 double a = array[0];
33 double b = array[1];
34 double c = array[2];
35 double d = array[3];
36 double e = array[4];
37 double f = array[5];
38 double g = array[6];
39 double h = array[7];
40 double i = array[8];
41 double j = array[9];
42 double k = array[10];
43 double l = array[11];
44 env->CallStaticVoidMethod(cls, mid, 1, 1, 1L);
45 // Load it in a temporary to please C compiler with bit_cast.
46 double temp = array[0];
47 CHECK_EQ(bit_cast<int64_t>(a), bit_cast<int64_t>(temp));
48 temp = array[1];
49 CHECK_EQ(bit_cast<int64_t>(b), bit_cast<int64_t>(temp));
50 temp = array[2];
51 CHECK_EQ(bit_cast<int64_t>(c), bit_cast<int64_t>(temp));
52 temp = array[3];
53 CHECK_EQ(bit_cast<int64_t>(d), bit_cast<int64_t>(temp));
54 temp = array[4];
55 CHECK_EQ(bit_cast<int64_t>(e), bit_cast<int64_t>(temp));
56 temp = array[5];
57 CHECK_EQ(bit_cast<int64_t>(f), bit_cast<int64_t>(temp));
58 temp = array[6];
59 CHECK_EQ(bit_cast<int64_t>(g), bit_cast<int64_t>(temp));
60 temp = array[7];
61 CHECK_EQ(bit_cast<int64_t>(h), bit_cast<int64_t>(temp));
62 temp = array[8];
63 CHECK_EQ(bit_cast<int64_t>(i), bit_cast<int64_t>(temp));
64 temp = array[9];
65 CHECK_EQ(bit_cast<int64_t>(j), bit_cast<int64_t>(temp));
66 temp = array[10];
67 CHECK_EQ(bit_cast<int64_t>(k), bit_cast<int64_t>(temp));
68 temp = array[11];
69 CHECK_EQ(bit_cast<int64_t>(l), bit_cast<int64_t>(temp));
70 }
71
72 } // namespace art
73