/* * 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. */ #include "berberis/intrinsics/intrinsics.h" #include #include namespace berberis::intrinsics { std::tuple Bclri(uint64_t src, uint8_t imm) { return {src & ~(uint64_t{1} << imm)}; } std::tuple Bexti(uint64_t src, uint8_t imm) { return {(src >> imm) & uint64_t{1}}; } std::tuple Binvi(uint64_t src, uint8_t imm) { return {src ^ (uint64_t{1} << imm)}; } std::tuple Bseti(uint64_t src, uint8_t imm) { return {src | (uint64_t{1} << imm)}; } #if defined(__x86_64__) std::tuple CPUClockCount() { uint64_t a, d; asm volatile("rdtsc" : "=a"(a), "=d"(d)); return (d << 32) | a; } #endif std::tuple Slliuw(uint32_t src, uint8_t imm) { return {uint64_t{src} << imm}; } void InitState() { // TODO(b/276787675): Initialize host MXCSR register once riscv64 intrinsics are supported. } } // namespace berberis::intrinsics