1*0b57cec5SDimitry Andric //===- X86InstrFMA3Info.h - X86 FMA3 Instruction Information ----*- C++ -*-===// 2*0b57cec5SDimitry Andric // 3*0b57cec5SDimitry Andric // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. 4*0b57cec5SDimitry Andric // See https://llvm.org/LICENSE.txt for license information. 5*0b57cec5SDimitry Andric // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception 6*0b57cec5SDimitry Andric // 7*0b57cec5SDimitry Andric //===----------------------------------------------------------------------===// 8*0b57cec5SDimitry Andric // 9*0b57cec5SDimitry Andric // This file contains the implementation of the classes providing information 10*0b57cec5SDimitry Andric // about existing X86 FMA3 opcodes, classifying and grouping them. 11*0b57cec5SDimitry Andric // 12*0b57cec5SDimitry Andric //===----------------------------------------------------------------------===// 13*0b57cec5SDimitry Andric 14*0b57cec5SDimitry Andric #ifndef LLVM_LIB_TARGET_X86_UTILS_X86INSTRFMA3INFO_H 15*0b57cec5SDimitry Andric #define LLVM_LIB_TARGET_X86_UTILS_X86INSTRFMA3INFO_H 16*0b57cec5SDimitry Andric 17*0b57cec5SDimitry Andric #include <cstdint> 18*0b57cec5SDimitry Andric 19*0b57cec5SDimitry Andric namespace llvm { 20*0b57cec5SDimitry Andric 21*0b57cec5SDimitry Andric /// This class is used to group {132, 213, 231} forms of FMA opcodes together. 22*0b57cec5SDimitry Andric /// Each of the groups has either 3 opcodes, Also, each group has an attributes 23*0b57cec5SDimitry Andric /// field describing it. 24*0b57cec5SDimitry Andric struct X86InstrFMA3Group { 25*0b57cec5SDimitry Andric /// An array holding 3 forms of FMA opcodes. 26*0b57cec5SDimitry Andric uint16_t Opcodes[3]; 27*0b57cec5SDimitry Andric 28*0b57cec5SDimitry Andric /// This bitfield specifies the attributes associated with the created 29*0b57cec5SDimitry Andric /// FMA groups of opcodes. 30*0b57cec5SDimitry Andric uint16_t Attributes; 31*0b57cec5SDimitry Andric 32*0b57cec5SDimitry Andric enum { 33*0b57cec5SDimitry Andric Form132, 34*0b57cec5SDimitry Andric Form213, 35*0b57cec5SDimitry Andric Form231, 36*0b57cec5SDimitry Andric }; 37*0b57cec5SDimitry Andric 38*0b57cec5SDimitry Andric enum : uint16_t { 39*0b57cec5SDimitry Andric /// This bit must be set in the 'Attributes' field of FMA group if such 40*0b57cec5SDimitry Andric /// group of FMA opcodes consists of FMA intrinsic opcodes. 41*0b57cec5SDimitry Andric Intrinsic = 0x1, 42*0b57cec5SDimitry Andric 43*0b57cec5SDimitry Andric /// This bit must be set in the 'Attributes' field of FMA group if such 44*0b57cec5SDimitry Andric /// group of FMA opcodes consists of AVX512 opcodes accepting a k-mask and 45*0b57cec5SDimitry Andric /// passing the elements from the 1st operand to the result of the operation 46*0b57cec5SDimitry Andric /// when the correpondings bits in the k-mask are unset. 47*0b57cec5SDimitry Andric KMergeMasked = 0x2, 48*0b57cec5SDimitry Andric 49*0b57cec5SDimitry Andric /// This bit must be set in the 'Attributes' field of FMA group if such 50*0b57cec5SDimitry Andric /// group of FMA opcodes consists of AVX512 opcodes accepting a k-zeromask. 51*0b57cec5SDimitry Andric KZeroMasked = 0x4, 52*0b57cec5SDimitry Andric }; 53*0b57cec5SDimitry Andric 54*0b57cec5SDimitry Andric /// Returns the 132 form of FMA opcode. get132OpcodeX86InstrFMA3Group55*0b57cec5SDimitry Andric unsigned get132Opcode() const { 56*0b57cec5SDimitry Andric return Opcodes[Form132]; 57*0b57cec5SDimitry Andric } 58*0b57cec5SDimitry Andric 59*0b57cec5SDimitry Andric /// Returns the 213 form of FMA opcode. get213OpcodeX86InstrFMA3Group60*0b57cec5SDimitry Andric unsigned get213Opcode() const { 61*0b57cec5SDimitry Andric return Opcodes[Form213]; 62*0b57cec5SDimitry Andric } 63*0b57cec5SDimitry Andric 64*0b57cec5SDimitry Andric /// Returns the 231 form of FMA opcode. get231OpcodeX86InstrFMA3Group65*0b57cec5SDimitry Andric unsigned get231Opcode() const { 66*0b57cec5SDimitry Andric return Opcodes[Form231]; 67*0b57cec5SDimitry Andric } 68*0b57cec5SDimitry Andric 69*0b57cec5SDimitry Andric /// Returns true iff the group of FMA opcodes holds intrinsic opcodes. isIntrinsicX86InstrFMA3Group70*0b57cec5SDimitry Andric bool isIntrinsic() const { return (Attributes & Intrinsic) != 0; } 71*0b57cec5SDimitry Andric 72*0b57cec5SDimitry Andric /// Returns true iff the group of FMA opcodes holds k-merge-masked opcodes. isKMergeMaskedX86InstrFMA3Group73*0b57cec5SDimitry Andric bool isKMergeMasked() const { 74*0b57cec5SDimitry Andric return (Attributes & KMergeMasked) != 0; 75*0b57cec5SDimitry Andric } 76*0b57cec5SDimitry Andric 77*0b57cec5SDimitry Andric /// Returns true iff the group of FMA opcodes holds k-zero-masked opcodes. isKZeroMaskedX86InstrFMA3Group78*0b57cec5SDimitry Andric bool isKZeroMasked() const { return (Attributes &KZeroMasked) != 0; } 79*0b57cec5SDimitry Andric 80*0b57cec5SDimitry Andric /// Returns true iff the group of FMA opcodes holds any of k-masked opcodes. isKMaskedX86InstrFMA3Group81*0b57cec5SDimitry Andric bool isKMasked() const { 82*0b57cec5SDimitry Andric return (Attributes & (KMergeMasked | KZeroMasked)) != 0; 83*0b57cec5SDimitry Andric } 84*0b57cec5SDimitry Andric 85*0b57cec5SDimitry Andric bool operator<(const X86InstrFMA3Group &RHS) const { 86*0b57cec5SDimitry Andric return Opcodes[0] < RHS.Opcodes[0]; 87*0b57cec5SDimitry Andric } 88*0b57cec5SDimitry Andric }; 89*0b57cec5SDimitry Andric 90*0b57cec5SDimitry Andric /// Returns a reference to a group of FMA3 opcodes to where the given 91*0b57cec5SDimitry Andric /// \p Opcode is included. If the given \p Opcode is not recognized as FMA3 92*0b57cec5SDimitry Andric /// and not included into any FMA3 group, then nullptr is returned. 93*0b57cec5SDimitry Andric const X86InstrFMA3Group *getFMA3Group(unsigned Opcode, uint64_t TSFlags); 94*0b57cec5SDimitry Andric 95*0b57cec5SDimitry Andric } // end namespace llvm 96*0b57cec5SDimitry Andric 97*0b57cec5SDimitry Andric #endif // LLVM_LIB_TARGET_X86_UTILS_X86INSTRFMA3INFO_H 98