1 /*
2  * Copyright (c) 2012, Oracle and/or its affiliates. All rights reserved.
3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4  *
5  * This code is free software; you can redistribute it and/or modify it
6  * under the terms of the GNU General Public License version 2 only, as
7  * published by the Free Software Foundation.
8  *
9  * This code is distributed in the hope that it will be useful, but WITHOUT
10  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
12  * version 2 for more details (a copy is included in the LICENSE file that
13  * accompanied this code).
14  *
15  * You should have received a copy of the GNU General Public License version
16  * 2 along with this work; if not, write to the Free Software Foundation,
17  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
18  *
19  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
20  * or visit www.oracle.com if you need additional information or have any
21  * questions.
22  */
23 
24 
25 package org.graalvm.compiler.asm.amd64;
26 
27 import jdk.vm.ci.amd64.AMD64;
28 import jdk.vm.ci.amd64.AMD64.CPUFeature;
29 import jdk.vm.ci.code.TargetDescription;
30 
31 /**
32  * Attributes for instructions for SSE through EVEX, also including address components.
33  */
34 public class AMD64InstructionAttr {
AMD64InstructionAttr( int inVectorLen, boolean inRexVexW, boolean inLegacyMode, boolean inNoRegMask, boolean inUsesVl, TargetDescription target)35     AMD64InstructionAttr(
36                     int inVectorLen,
37                     boolean inRexVexW,
38                     boolean inLegacyMode,
39                     boolean inNoRegMask,
40                     boolean inUsesVl,
41                     TargetDescription target) {
42         avxVectorLen = inVectorLen;
43         rexVexW = inRexVexW;
44         this.target = target;
45         legacyMode = (!supports(CPUFeature.AVX512F)) ? true : inLegacyMode;
46         noRegMask = inNoRegMask;
47         usesVl = inUsesVl;
48         rexVexWReverted = false;
49         tupleType = 0;
50         inputSizeInBits = 0;
51         isEvexInstruction = false;
52         evexEncoding = 0;
53         isClearContext = false;
54         isExtendedContext = false;
55     }
56 
57     private TargetDescription target;
58     private int avxVectorLen;
59     private boolean rexVexW;
60     private boolean rexVexWReverted;
61     private boolean legacyMode;
62     private boolean noRegMask;
63     private boolean usesVl;
64     private int tupleType;
65     private int inputSizeInBits;
66     private boolean isEvexInstruction;
67     private int evexEncoding;
68     private boolean isClearContext;
69     private boolean isExtendedContext;
70 
getVectorLen()71     public int getVectorLen() {
72         return avxVectorLen;
73     }
74 
isRexVexW()75     public boolean isRexVexW() {
76         return rexVexW;
77     }
78 
isRexVexWReverted()79     public boolean isRexVexWReverted() {
80         return rexVexWReverted;
81     }
82 
isLegacyMode()83     public boolean isLegacyMode() {
84         return legacyMode;
85     }
86 
isNoRegMask()87     public boolean isNoRegMask() {
88         return noRegMask;
89     }
90 
usesVl()91     public boolean usesVl() {
92         return usesVl;
93     }
94 
getTupleType()95     public int getTupleType() {
96         return tupleType;
97     }
98 
getInputSize()99     public int getInputSize() {
100         return inputSizeInBits;
101     }
102 
isEvexInstruction()103     public boolean isEvexInstruction() {
104         return isEvexInstruction;
105     }
106 
getEvexEncoding()107     public int getEvexEncoding() {
108         return evexEncoding;
109     }
110 
isClearContext()111     public boolean isClearContext() {
112         return isClearContext;
113     }
114 
isExtendedContext()115     public boolean isExtendedContext() {
116         return isExtendedContext;
117     }
118 
119     /**
120      * Set the vector length of a given instruction.
121      *
122      * @param vectorLen
123      */
setVectorLen(int vectorLen)124     public void setVectorLen(int vectorLen) {
125         avxVectorLen = vectorLen;
126     }
127 
128     /**
129      * In EVEX it is possible in blended code generation to revert the encoding width for AVX.
130      */
setRexVexWReverted()131     public void setRexVexWReverted() {
132         rexVexWReverted = true;
133     }
134 
135     /**
136      * Alter the current encoding width.
137      *
138      * @param state
139      */
setRexVexW(boolean state)140     public void setRexVexW(boolean state) {
141         rexVexW = state;
142     }
143 
144     /**
145      * Alter the current instructions legacy mode. Blended code generation will use this.
146      */
setLegacyMode()147     public void setLegacyMode() {
148         legacyMode = true;
149     }
150 
151     /**
152      * During emit or during definition of an instruction, mark if it is EVEX.
153      */
setIsEvexInstruction()154     public void setIsEvexInstruction() {
155         isEvexInstruction = true;
156     }
157 
158     /**
159      * Set the current encoding attributes to be used in address calculations for EVEX.
160      *
161      * @param value
162      */
setEvexEncoding(int value)163     public void setEvexEncoding(int value) {
164         evexEncoding = value;
165     }
166 
167     /**
168      * Use clear context for this instruction in EVEX, defaults is merge(false).
169      */
setIsClearContext()170     public void setIsClearContext() {
171         isClearContext = true;
172     }
173 
174     /**
175      * Set the address attributes for configuring displacement calculations in EVEX.
176      */
setAddressAttributes(int inTupleType, int inInputSizeInBits)177     public void setAddressAttributes(int inTupleType, int inInputSizeInBits) {
178         if (supports(CPUFeature.AVX512F)) {
179             tupleType = inTupleType;
180             inputSizeInBits = inInputSizeInBits;
181         }
182     }
183 
supports(CPUFeature feature)184     private boolean supports(CPUFeature feature) {
185         return ((AMD64) target.arch).getFeatures().contains(feature);
186     }
187 }
188