1fbd13c5cSEugene Zelenko //===- X86InstrFMA3Info.h - X86 FMA3 Instruction Information ----*- C++ -*-===// 26daefcf6SVyacheslav Klochkov // 3*2946cd70SChandler Carruth // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. 4*2946cd70SChandler Carruth // See https://llvm.org/LICENSE.txt for license information. 5*2946cd70SChandler Carruth // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception 66daefcf6SVyacheslav Klochkov // 76daefcf6SVyacheslav Klochkov //===----------------------------------------------------------------------===// 86daefcf6SVyacheslav Klochkov // 96daefcf6SVyacheslav Klochkov // This file contains the implementation of the classes providing information 106daefcf6SVyacheslav Klochkov // about existing X86 FMA3 opcodes, classifying and grouping them. 116daefcf6SVyacheslav Klochkov // 126daefcf6SVyacheslav Klochkov //===----------------------------------------------------------------------===// 136daefcf6SVyacheslav Klochkov 146daefcf6SVyacheslav Klochkov #ifndef LLVM_LIB_TARGET_X86_UTILS_X86INSTRFMA3INFO_H 156daefcf6SVyacheslav Klochkov #define LLVM_LIB_TARGET_X86_UTILS_X86INSTRFMA3INFO_H 166daefcf6SVyacheslav Klochkov 17fbd13c5cSEugene Zelenko #include <cstdint> 186daefcf6SVyacheslav Klochkov 194c2582adSBenjamin Kramer namespace llvm { 20fbd13c5cSEugene Zelenko 216daefcf6SVyacheslav Klochkov /// This class is used to group {132, 213, 231} forms of FMA opcodes together. 2233aba0ebSCraig Topper /// Each of the groups has either 3 opcodes, Also, each group has an attributes 2333aba0ebSCraig Topper /// field describing it. 24f0ab7bd1SCraig Topper struct X86InstrFMA3Group { 2533aba0ebSCraig Topper /// An array holding 3 forms of FMA opcodes. 2633aba0ebSCraig Topper uint16_t Opcodes[3]; 276daefcf6SVyacheslav Klochkov 286daefcf6SVyacheslav Klochkov /// This bitfield specifies the attributes associated with the created 296daefcf6SVyacheslav Klochkov /// FMA groups of opcodes. 30f0ab7bd1SCraig Topper uint16_t Attributes; 316daefcf6SVyacheslav Klochkov 32f0ab7bd1SCraig Topper enum { 33f0ab7bd1SCraig Topper Form132, 34f0ab7bd1SCraig Topper Form213, 35f0ab7bd1SCraig Topper Form231, 36f0ab7bd1SCraig Topper }; 376daefcf6SVyacheslav Klochkov 38f0ab7bd1SCraig Topper enum : uint16_t { 396daefcf6SVyacheslav Klochkov /// This bit must be set in the 'Attributes' field of FMA group if such 406daefcf6SVyacheslav Klochkov /// group of FMA opcodes consists of FMA intrinsic opcodes. 410661f672SCraig Topper Intrinsic = 0x1, 426daefcf6SVyacheslav Klochkov 436daefcf6SVyacheslav Klochkov /// This bit must be set in the 'Attributes' field of FMA group if such 446daefcf6SVyacheslav Klochkov /// group of FMA opcodes consists of AVX512 opcodes accepting a k-mask and 456daefcf6SVyacheslav Klochkov /// passing the elements from the 1st operand to the result of the operation 466daefcf6SVyacheslav Klochkov /// when the correpondings bits in the k-mask are unset. 470661f672SCraig Topper KMergeMasked = 0x2, 486daefcf6SVyacheslav Klochkov 496daefcf6SVyacheslav Klochkov /// This bit must be set in the 'Attributes' field of FMA group if such 506daefcf6SVyacheslav Klochkov /// group of FMA opcodes consists of AVX512 opcodes accepting a k-zeromask. 510661f672SCraig Topper KZeroMasked = 0x4, 52f0ab7bd1SCraig Topper }; 536daefcf6SVyacheslav Klochkov 5433aba0ebSCraig Topper /// Returns the 132 form of FMA opcode. get132OpcodeX86InstrFMA3Group5533aba0ebSCraig Topper unsigned get132Opcode() const { 5633aba0ebSCraig Topper return Opcodes[Form132]; 576daefcf6SVyacheslav Klochkov } 586daefcf6SVyacheslav Klochkov 5933aba0ebSCraig Topper /// Returns the 213 form of FMA opcode. get213OpcodeX86InstrFMA3Group6033aba0ebSCraig Topper unsigned get213Opcode() const { 6133aba0ebSCraig Topper return Opcodes[Form213]; 626daefcf6SVyacheslav Klochkov } 636daefcf6SVyacheslav Klochkov 6433aba0ebSCraig Topper /// Returns the 231 form of FMA opcode. get231OpcodeX86InstrFMA3Group6533aba0ebSCraig Topper unsigned get231Opcode() const { 6633aba0ebSCraig Topper return Opcodes[Form231]; 676daefcf6SVyacheslav Klochkov } 686daefcf6SVyacheslav Klochkov 696daefcf6SVyacheslav Klochkov /// Returns true iff the group of FMA opcodes holds intrinsic opcodes. isIntrinsicX86InstrFMA3Group700661f672SCraig Topper bool isIntrinsic() const { return (Attributes & Intrinsic) != 0; } 716daefcf6SVyacheslav Klochkov 726daefcf6SVyacheslav Klochkov /// Returns true iff the group of FMA opcodes holds k-merge-masked opcodes. isKMergeMaskedX86InstrFMA3Group736daefcf6SVyacheslav Klochkov bool isKMergeMasked() const { 740661f672SCraig Topper return (Attributes & KMergeMasked) != 0; 756daefcf6SVyacheslav Klochkov } 766daefcf6SVyacheslav Klochkov 776daefcf6SVyacheslav Klochkov /// Returns true iff the group of FMA opcodes holds k-zero-masked opcodes. isKZeroMaskedX86InstrFMA3Group780661f672SCraig Topper bool isKZeroMasked() const { return (Attributes &KZeroMasked) != 0; } 796daefcf6SVyacheslav Klochkov 806daefcf6SVyacheslav Klochkov /// Returns true iff the group of FMA opcodes holds any of k-masked opcodes. isKMaskedX86InstrFMA3Group816daefcf6SVyacheslav Klochkov bool isKMasked() const { 820661f672SCraig Topper return (Attributes & (KMergeMasked | KZeroMasked)) != 0; 830661f672SCraig Topper } 840661f672SCraig Topper 850661f672SCraig Topper bool operator<(const X86InstrFMA3Group &RHS) const { 860661f672SCraig Topper return Opcodes[0] < RHS.Opcodes[0]; 876daefcf6SVyacheslav Klochkov } 886daefcf6SVyacheslav Klochkov }; 896daefcf6SVyacheslav Klochkov 906daefcf6SVyacheslav Klochkov /// Returns a reference to a group of FMA3 opcodes to where the given 916daefcf6SVyacheslav Klochkov /// \p Opcode is included. If the given \p Opcode is not recognized as FMA3 926daefcf6SVyacheslav Klochkov /// and not included into any FMA3 group, then nullptr is returned. 930661f672SCraig Topper const X86InstrFMA3Group *getFMA3Group(unsigned Opcode, uint64_t TSFlags); 946daefcf6SVyacheslav Klochkov 95fbd13c5cSEugene Zelenko } // end namespace llvm 96fbd13c5cSEugene Zelenko 97fbd13c5cSEugene Zelenko #endif // LLVM_LIB_TARGET_X86_UTILS_X86INSTRFMA3INFO_H 98