xref: /aosp_15_r20/art/runtime/nterp_helpers-inl.h (revision 795d594fd825385562da6b089ea9b2033f3abf5a)
1*795d594fSAndroid Build Coastguard Worker /*
2*795d594fSAndroid Build Coastguard Worker  * Copyright (C) 2023 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 #ifndef ART_RUNTIME_NTERP_HELPERS_INL_H_
18*795d594fSAndroid Build Coastguard Worker #define ART_RUNTIME_NTERP_HELPERS_INL_H_
19*795d594fSAndroid Build Coastguard Worker 
20*795d594fSAndroid Build Coastguard Worker #include "nterp_helpers.h"
21*795d594fSAndroid Build Coastguard Worker 
22*795d594fSAndroid Build Coastguard Worker namespace art HIDDEN {
23*795d594fSAndroid Build Coastguard Worker 
GetNterpFastPathFlags(std::string_view shorty,uint32_t access_flags,InstructionSet isa)24*795d594fSAndroid Build Coastguard Worker ALWAYS_INLINE inline uint32_t GetNterpFastPathFlags(std::string_view shorty,
25*795d594fSAndroid Build Coastguard Worker                                                     uint32_t access_flags,
26*795d594fSAndroid Build Coastguard Worker                                                     InstructionSet isa) {
27*795d594fSAndroid Build Coastguard Worker   bool all_parameters_are_reference = true;
28*795d594fSAndroid Build Coastguard Worker   bool all_parameters_are_reference_or_int = true;
29*795d594fSAndroid Build Coastguard Worker   for (size_t i = 1; i < shorty.length(); ++i) {
30*795d594fSAndroid Build Coastguard Worker     if (shorty[i] != 'L') {
31*795d594fSAndroid Build Coastguard Worker       all_parameters_are_reference = false;
32*795d594fSAndroid Build Coastguard Worker       if (shorty[i] == 'F' || shorty[i] == 'D' || shorty[i] == 'J') {
33*795d594fSAndroid Build Coastguard Worker         all_parameters_are_reference_or_int = false;
34*795d594fSAndroid Build Coastguard Worker         break;
35*795d594fSAndroid Build Coastguard Worker       }
36*795d594fSAndroid Build Coastguard Worker     }
37*795d594fSAndroid Build Coastguard Worker   }
38*795d594fSAndroid Build Coastguard Worker 
39*795d594fSAndroid Build Coastguard Worker   // Check for nterp entry fast-path based on shorty.
40*795d594fSAndroid Build Coastguard Worker   uint32_t nterp_flags = 0u;
41*795d594fSAndroid Build Coastguard Worker   if ((access_flags & kAccNative) == 0u && all_parameters_are_reference) {
42*795d594fSAndroid Build Coastguard Worker     nterp_flags |= kAccNterpEntryPointFastPathFlag;
43*795d594fSAndroid Build Coastguard Worker   }
44*795d594fSAndroid Build Coastguard Worker 
45*795d594fSAndroid Build Coastguard Worker   // Check for nterp invoke fast-path based on shorty.
46*795d594fSAndroid Build Coastguard Worker   const bool no_float_return = shorty[0] != 'F' && shorty[0] != 'D';
47*795d594fSAndroid Build Coastguard Worker   if (isa != InstructionSet::kRiscv64 && all_parameters_are_reference_or_int && no_float_return) {
48*795d594fSAndroid Build Coastguard Worker     nterp_flags |= kAccNterpInvokeFastPathFlag;
49*795d594fSAndroid Build Coastguard Worker   } else if (isa == InstructionSet::kRiscv64 && all_parameters_are_reference && no_float_return) {
50*795d594fSAndroid Build Coastguard Worker     nterp_flags |= kAccNterpInvokeFastPathFlag;
51*795d594fSAndroid Build Coastguard Worker   }
52*795d594fSAndroid Build Coastguard Worker   return nterp_flags;
53*795d594fSAndroid Build Coastguard Worker }
54*795d594fSAndroid Build Coastguard Worker 
55*795d594fSAndroid Build Coastguard Worker }  // namespace art
56*795d594fSAndroid Build Coastguard Worker 
57*795d594fSAndroid Build Coastguard Worker #endif  // ART_RUNTIME_NTERP_HELPERS_INL_H_
58