1 /* Copyright 2019 Google LLC. All Rights Reserved. 2 3 Licensed under the Apache License, Version 2.0 (the "License"); 4 you may not use this file except in compliance with the License. 5 You may obtain a copy of the License at 6 7 http://www.apache.org/licenses/LICENSE-2.0 8 9 Unless required by applicable law or agreed to in writing, software 10 distributed under the License is distributed on an "AS IS" BASIS, 11 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 See the License for the specific language governing permissions and 13 limitations under the License. 14 ==============================================================================*/ 15 16 #include "ruy/tune.h" 17 18 #include <algorithm> 19 #include <cstdint> 20 21 #include "ruy/cpuinfo.h" 22 23 namespace ruy { 24 ResolveNow(CpuInfo * cpuinfo)25Tuning TuningResolver::ResolveNow(CpuInfo* cpuinfo) { 26 if (cpuinfo->CurrentCpuIsA55ish()) { 27 return Tuning::kA55ish; 28 } 29 if (cpuinfo->CurrentCpuIsX1()) { 30 return Tuning::kX1; 31 } 32 return Tuning::kGeneric; 33 } 34 TuningResolver()35TuningResolver::TuningResolver() 36 : expiry_duration_(DurationFromMilliseconds(250)) {} 37 Resolve(CpuInfo * cpuinfo)38Tuning TuningResolver::Resolve(CpuInfo* cpuinfo) { 39 if (unresolved_tuning_ != Tuning::kAuto) { 40 return unresolved_tuning_; 41 } 42 TimePoint new_timepoint = CoarseNow(); 43 if (last_resolved_tuning_ != Tuning::kAuto && 44 (new_timepoint - last_resolved_timepoint_) < expiry_duration_) { 45 return last_resolved_tuning_; 46 } 47 last_resolved_timepoint_ = new_timepoint; 48 last_resolved_tuning_ = ResolveNow(cpuinfo); 49 return last_resolved_tuning_; 50 } 51 52 } // namespace ruy 53