3 // Copyright (c) 2010-2012 ARM Limited
6 // The license below extends only to copyright in the software and shall
7 // not be construed as granting a license to any other intellectual
8 // property including but not limited to intellectual property relating
9 // to a hardware implementation of the functionality of the software
10 // licensed hereunder. You may use the software subject to the license
11 // terms below provided that you ensure that this notice is replicated
12 // unmodified and in its entirety in all distributions of the software,
13 // modified or unmodified, in source code or in binary form.
15 // Redistribution and use in source and binary forms, with or without
16 // modification, are permitted provided that the following conditions are
17 // met: redistributions of source code must retain the above copyright
18 // notice, this list of conditions and the following disclaimer;
19 // redistributions in binary form must reproduce the above copyright
20 // notice, this list of conditions and the following disclaimer in the
21 // documentation and/or other materials provided with the distribution;
22 // neither the name of the copyright holders nor the names of its
23 // contributors may be used to endorse or promote products derived from
24 // this software without specific prior written permission.
26 // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
27 // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
28 // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
29 // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
30 // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
31 // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
32 // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
33 // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
34 // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
35 // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
36 // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
38 // Authors: Gabe Black
41 simdEnabledCheckCode = '''
46 if (!vfpNeonEnabled(seq, Hcptr, Nsacr, Cpacr, Cpsr, issEnCheck,
47 trapEnCheck, xc->tcBase(), Fpexc, true))
48 {return disabledFault();}
50 CPSR cpsrEnCheck = Cpsr;
51 if (cpsrEnCheck.mode == MODE_HYP) {
52 return new UndefinedInstruction(machInst, issEnCheck,
55 if (!inSecureState(Scr, Cpsr)) {
56 return new HypervisorTrap(machInst, issEnCheck,
66 def template NeonRegRegRegOpDeclare {{
67 template <class _Element>
68 class %(class_name)s : public %(base_class)s
71 typedef _Element Element;
74 %(class_name)s(ExtMachInst machInst,
75 IntRegIndex _dest, IntRegIndex _op1, IntRegIndex _op2)
76 : %(base_class)s("%(mnemonic)s", machInst, %(op_class)s,
80 if (!(condCode == COND_AL || condCode == COND_UC)) {
81 for (int x = 0; x < _numDestRegs; x++) {
82 _srcRegIdx[_numSrcRegs++] = _destRegIdx[x];
91 def template NeonRegRegRegImmOpDeclare {{
92 template <class _Element>
93 class %(class_name)s : public %(base_class)s
96 typedef _Element Element;
99 %(class_name)s(ExtMachInst machInst,
100 IntRegIndex _dest, IntRegIndex _op1, IntRegIndex _op2,
102 : %(base_class)s("%(mnemonic)s", machInst, %(op_class)s,
103 _dest, _op1, _op2, _imm)
106 if (!(condCode == COND_AL || condCode == COND_UC)) {
107 for (int x = 0; x < _numDestRegs; x++) {
108 _srcRegIdx[_numSrcRegs++] = _destRegIdx[x];
117 def template NeonRegRegImmOpDeclare {{
118 template <class _Element>
119 class %(class_name)s : public %(base_class)s
122 typedef _Element Element;
125 %(class_name)s(ExtMachInst machInst,
126 IntRegIndex _dest, IntRegIndex _op1, uint64_t _imm)
127 : %(base_class)s("%(mnemonic)s", machInst, %(op_class)s,
131 if (!(condCode == COND_AL || condCode == COND_UC)) {
132 for (int x = 0; x < _numDestRegs; x++) {
133 _srcRegIdx[_numSrcRegs++] = _destRegIdx[x];
142 def template NeonRegImmOpDeclare {{
143 template <class _Element>
144 class %(class_name)s : public %(base_class)s
147 typedef _Element Element;
150 %(class_name)s(ExtMachInst machInst, IntRegIndex _dest, uint64_t _imm)
151 : %(base_class)s("%(mnemonic)s", machInst, %(op_class)s, _dest, _imm)
154 if (!(condCode == COND_AL || condCode == COND_UC)) {
155 for (int x = 0; x < _numDestRegs; x++) {
156 _srcRegIdx[_numSrcRegs++] = _destRegIdx[x];
165 def template NeonRegRegOpDeclare {{
166 template <class _Element>
167 class %(class_name)s : public %(base_class)s
170 typedef _Element Element;
173 %(class_name)s(ExtMachInst machInst,
174 IntRegIndex _dest, IntRegIndex _op1)
175 : %(base_class)s("%(mnemonic)s", machInst, %(op_class)s,
179 if (!(condCode == COND_AL || condCode == COND_UC)) {
180 for (int x = 0; x < _numDestRegs; x++) {
181 _srcRegIdx[_numSrcRegs++] = _destRegIdx[x];
190 def template NeonExecDeclare {{
192 Fault %(class_name)s<%(targs)s>::execute(
193 %(CPU_exec_context)s *, Trace::InstRecord *) const;
198 // Implement a less-than-zero function: ltz()
199 // this function exists because some versions of GCC complain when a
200 // comparison is done between a unsigned variable and 0 and for GCC 4.2
201 // there is no way to disable this warning
202 inline bool ltz(T t);
205 inline bool ltz(uint8_t) { return false; }
207 inline bool ltz(uint16_t) { return false; }
209 inline bool ltz(uint32_t) { return false; }
211 inline bool ltz(uint64_t) { return false; }
213 inline bool ltz(int8_t v) { return v < 0; }
215 inline bool ltz(int16_t v) { return v < 0; }
217 inline bool ltz(int32_t v) { return v < 0; }
219 inline bool ltz(int64_t v) { return v < 0; }
222 def template NeonEqualRegExecute {{
223 template <class Element>
224 Fault %(class_name)s<Element>::execute(%(CPU_exec_context)s *xc,
225 Trace::InstRecord *traceData) const
227 Fault fault = NoFault;
231 const unsigned rCount = %(r_count)d;
232 const unsigned eCount = rCount * sizeof(FloatRegBits) / sizeof(Element);
235 FloatRegBits regs[rCount];
236 Element elements[eCount];
239 if (%(predicate_test)s)
242 if (fault == NoFault)
247 xc->setPredicate(false);
255 template <typename T>
256 struct bigger_type_t;
258 template<> struct bigger_type_t<uint8_t> { typedef uint16_t type; };
259 template<> struct bigger_type_t<uint16_t> { typedef uint32_t type; };
260 template<> struct bigger_type_t<uint32_t> { typedef uint64_t type; };
262 template<> struct bigger_type_t<int8_t> { typedef int16_t type; };
263 template<> struct bigger_type_t<int16_t> { typedef int32_t type; };
264 template<> struct bigger_type_t<int32_t> { typedef int64_t type; };
267 def template NeonUnequalRegExecute {{
268 template <class Element>
269 Fault %(class_name)s<Element>::execute(%(CPU_exec_context)s *xc,
270 Trace::InstRecord *traceData) const
272 typedef typename bigger_type_t<Element>::type BigElement;
273 Fault fault = NoFault;
277 const unsigned rCount = %(r_count)d;
278 const unsigned eCount = rCount * sizeof(FloatRegBits) / sizeof(Element);
281 FloatRegBits regs[rCount];
282 Element elements[eCount];
283 BigElement bigElements[eCount / 2];
287 FloatRegBits regs[2 * rCount];
288 BigElement elements[eCount];
291 if (%(predicate_test)s)
294 if (fault == NoFault)
299 xc->setPredicate(false);