10f88e87085b7cf6544dadff3f555773966a6853eGuillaume Sanchez/*
20f88e87085b7cf6544dadff3f555773966a6853eGuillaume Sanchez * Copyright (C) 2015 The Android Open Source Project
30f88e87085b7cf6544dadff3f555773966a6853eGuillaume Sanchez *
40f88e87085b7cf6544dadff3f555773966a6853eGuillaume Sanchez * Licensed under the Apache License, Version 2.0 (the "License");
50f88e87085b7cf6544dadff3f555773966a6853eGuillaume Sanchez * you may not use this file except in compliance with the License.
60f88e87085b7cf6544dadff3f555773966a6853eGuillaume Sanchez * You may obtain a copy of the License at
70f88e87085b7cf6544dadff3f555773966a6853eGuillaume Sanchez *
80f88e87085b7cf6544dadff3f555773966a6853eGuillaume Sanchez *      http://www.apache.org/licenses/LICENSE-2.0
90f88e87085b7cf6544dadff3f555773966a6853eGuillaume Sanchez *
100f88e87085b7cf6544dadff3f555773966a6853eGuillaume Sanchez * Unless required by applicable law or agreed to in writing, software
110f88e87085b7cf6544dadff3f555773966a6853eGuillaume Sanchez * distributed under the License is distributed on an "AS IS" BASIS,
120f88e87085b7cf6544dadff3f555773966a6853eGuillaume Sanchez * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
130f88e87085b7cf6544dadff3f555773966a6853eGuillaume Sanchez * See the License for the specific language governing permissions and
140f88e87085b7cf6544dadff3f555773966a6853eGuillaume Sanchez * limitations under the License.
150f88e87085b7cf6544dadff3f555773966a6853eGuillaume Sanchez */
160f88e87085b7cf6544dadff3f555773966a6853eGuillaume Sanchez
170f88e87085b7cf6544dadff3f555773966a6853eGuillaume Sanchez#ifndef ART_COMPILER_OPTIMIZING_CODE_GENERATOR_UTILS_H_
180f88e87085b7cf6544dadff3f555773966a6853eGuillaume Sanchez#define ART_COMPILER_OPTIMIZING_CODE_GENERATOR_UTILS_H_
190f88e87085b7cf6544dadff3f555773966a6853eGuillaume Sanchez
200f88e87085b7cf6544dadff3f555773966a6853eGuillaume Sanchez#include <cstdint>
219186ced255f2e7402646b5b286deebb540640734Andreas Gampe#include <cstdlib>
229186ced255f2e7402646b5b286deebb540640734Andreas Gampe#include <limits>
230f88e87085b7cf6544dadff3f555773966a6853eGuillaume Sanchez
24b19930c5cba3cf662dce5ee057fcc9829b4cbb9cGuillaume Sancheznamespace art {
25b19930c5cba3cf662dce5ee057fcc9829b4cbb9cGuillaume Sanchez
260debae7bc89eb05f7a2bf7dccd223318fad7c88dDavid Brazdilclass HInstruction;
27b8b97695d178337736b61609220613b92f344d45Mark Mendell
28b19930c5cba3cf662dce5ee057fcc9829b4cbb9cGuillaume Sanchez// Computes the magic number and the shift needed in the div/rem by constant algorithm, as out
29b19930c5cba3cf662dce5ee057fcc9829b4cbb9cGuillaume Sanchez// arguments `magic` and `shift`
300f88e87085b7cf6544dadff3f555773966a6853eGuillaume Sanchezvoid CalculateMagicAndShiftForDivRem(int64_t divisor, bool is_long, int64_t* magic, int* shift);
310f88e87085b7cf6544dadff3f555773966a6853eGuillaume Sanchez
320debae7bc89eb05f7a2bf7dccd223318fad7c88dDavid Brazdil// Returns true if `cond_input` is expected to have a location. Assumes that
330debae7bc89eb05f7a2bf7dccd223318fad7c88dDavid Brazdil// `cond_input` is a conditional input of the currently emitted instruction and
340debae7bc89eb05f7a2bf7dccd223318fad7c88dDavid Brazdil// that it has been previously visited by the InstructionCodeGenerator.
350debae7bc89eb05f7a2bf7dccd223318fad7c88dDavid Brazdilbool IsBooleanValueOrMaterializedCondition(HInstruction* cond_input);
36b8b97695d178337736b61609220613b92f344d45Mark Mendell
379186ced255f2e7402646b5b286deebb540640734Andreas Gampetemplate <typename T> T AbsOrMin(T value) {
389186ced255f2e7402646b5b286deebb540640734Andreas Gampe  return (value == std::numeric_limits<T>::min())
399186ced255f2e7402646b5b286deebb540640734Andreas Gampe      ? value
409186ced255f2e7402646b5b286deebb540640734Andreas Gampe      : std::abs(value);
419186ced255f2e7402646b5b286deebb540640734Andreas Gampe}
429186ced255f2e7402646b5b286deebb540640734Andreas Gampe
43b19930c5cba3cf662dce5ee057fcc9829b4cbb9cGuillaume Sanchez}  // namespace art
44b19930c5cba3cf662dce5ee057fcc9829b4cbb9cGuillaume Sanchez
450f88e87085b7cf6544dadff3f555773966a6853eGuillaume Sanchez#endif  // ART_COMPILER_OPTIMIZING_CODE_GENERATOR_UTILS_H_
46