/* * Copyright (C) 2023 The Android Open Source Project * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ #ifndef BERBERIS_REGS_H_ #define BERBERIS_REGS_H_ #include #include #include "berberis/base/bit_util.h" #if !defined(__aarch64__) #include "berberis/intrinsics/intrinsics_float.h" #endif namespace berberis { template inline auto GPRRegToInteger(uint64_t arg) -> std::enable_if_t && sizeof(IntegerType) <= sizeof(uint64_t), IntegerType> { return static_cast(arg); } template inline auto IntegerToGPRReg(IntegerType arg) -> std::enable_if_t && sizeof(IntegerType) <= sizeof(uint64_t), uint64_t> { if constexpr (sizeof(IntegerType) <= sizeof(uint32_t)) { return static_cast(arg); } else { return bit_cast(arg); } } template inline FloatType FPRegToFloat(uint64_t arg); template <> inline intrinsics::Float32 FPRegToFloat(uint64_t arg) { intrinsics::Float32 result; memcpy(&result, &arg, sizeof(intrinsics::Float32)); return result; } template <> inline intrinsics::Float64 FPRegToFloat(uint64_t arg) { return bit_cast(arg); } template inline uint64_t FloatToFPReg(FloatType arg); template <> inline uint64_t FloatToFPReg(intrinsics::Float32 arg) { // Note: NanBoxAndSetFpReg would properly Nan-box the value. return bit_cast(arg); } template <> inline uint64_t FloatToFPReg(intrinsics::Float64 arg) { return bit_cast(arg); } } // namespace berberis #endif // BERBERIS_REGS_H_