1 /* 2 * Copyright (C) 2023 The Android Open Source Project 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); 5 * you may not use this file except in compliance with the License. 6 * You may obtain a copy of the License at 7 * 8 * http://www.apache.org/licenses/LICENSE-2.0 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 * See the License for the specific language governing permissions and 14 * limitations under the License. 15 */ 16 17 #ifndef RISCV64_TO_X86_64_BERBERIS_INTRINSICS_MACRO_ASSEMBLER_H_ 18 #define RISCV64_TO_X86_64_BERBERIS_INTRINSICS_MACRO_ASSEMBLER_H_ 19 20 #include <limits.h> 21 #include <type_traits> // is_same_v 22 23 #include <functional> 24 #include <tuple> 25 #include <utility> 26 27 #include "berberis/intrinsics/intrinsics_float.h" 28 #include "berberis/intrinsics/macro_assembler_constants_pool.h" 29 30 namespace berberis { 31 32 template <typename Assembler> 33 class MacroAssembler : public Assembler { 34 public: 35 using MacroAssemblers = std::tuple<MacroAssembler<Assembler>>; 36 37 template <typename... Args> MacroAssembler(Args &&...args)38 explicit MacroAssembler(Args&&... args) : Assembler(std::forward<Args>(args)...) { 39 } 40 41 #define DEFINE_MACRO_ASSEMBLER_GENERIC_FUNCTIONS 42 #include "berberis/intrinsics/macro_assembler-inl.h" 43 PNot(XMMRegister result)44 void PNot(XMMRegister result) { 45 Pandn(result, {.disp = constants_pool::kVectorConst<uint8_t{0b1111'1111}>}); 46 } 47 48 void Vpnot(XMMRegister result, XMMRegister src) { 49 Vpandn(result, src, {.disp = constants_pool::kVectorConst<uint8_t{0b1111'1111}>}); 50 } 51 52 #include "berberis/intrinsics/macro_assembler_interface-inl.h" // NOLINT generated file 53 54 using Assembler::Bind; 55 using Assembler::Btq; 56 using Assembler::Cbw; 57 using Assembler::Cdq; 58 using Assembler::Cqo; 59 using Assembler::Cwd; 60 using Assembler::Fldcw; 61 using Assembler::Fldenv; 62 using Assembler::Fnstcw; 63 using Assembler::Fnstenv; 64 using Assembler::Fnstsw; 65 using Assembler::Jcc; 66 using Assembler::Jmp; 67 using Assembler::Ldmxcsr; 68 using Assembler::Leal; 69 using Assembler::Leaq; 70 using Assembler::MakeLabel; 71 using Assembler::Movl; 72 using Assembler::Pand; 73 using Assembler::Pandn; 74 using Assembler::Pcmpeqb; 75 using Assembler::Pmov; 76 using Assembler::Por; 77 using Assembler::Pshufd; 78 using Assembler::Setcc; 79 using Assembler::Stmxcsr; 80 using Assembler::Vpand; 81 using Assembler::Vpandn; 82 using Assembler::Vpcmpeqb; 83 using Assembler::Vpor; 84 using Assembler::Vpshufd; 85 86 using Assembler::Byte; 87 using Assembler::TwoByte; 88 using Assembler::FourByte; 89 using Assembler::EigthByte; 90 using Assembler::P2Align; 91 92 using Assembler::gpr_a; 93 using Assembler::gpr_c; 94 using Assembler::gpr_d; 95 96 private: 97 98 // Useful constants for PshufXXX instructions. 99 enum { 100 kShuffleDDBB = 0b11110101 101 }; 102 }; 103 104 } // namespace berberis 105 106 // Macro specializations. 107 #include "berberis/intrinsics/macro_assembler_arith_impl.h" 108 #include "berberis/intrinsics/macro_assembler_bitmanip_impl.h" 109 #include "berberis/intrinsics/macro_assembler_floating_point_impl.h" 110 111 #endif // RISCV64_TO_X86_64_BERBERIS_INTRINSICS_MACRO_ASSEMBLER_H_ 112