2 * Helpers for integer and multimedia instructions.
4 * Copyright (c) 2007 Jocelyn Mayer
6 * This library is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Lesser General Public
8 * License as published by the Free Software Foundation; either
9 * version 2 of the License, or (at your option) any later version.
11 * This library is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Lesser General Public License for more details.
16 * You should have received a copy of the GNU Lesser General Public
17 * License along with this library; if not, see <http://www.gnu.org/licenses/>.
21 #include "exec/helper-proto.h"
22 #include "qemu/host-utils.h"
25 uint64_t helper_ctpop(uint64_t arg)
30 uint64_t helper_ctlz(uint64_t arg)
35 uint64_t helper_cttz(uint64_t arg)
40 uint64_t helper_zapnot(uint64_t val, uint64_t mskb)
44 mask = -(mskb & 0x01) & 0x00000000000000ffull;
45 mask |= -(mskb & 0x02) & 0x000000000000ff00ull;
46 mask |= -(mskb & 0x04) & 0x0000000000ff0000ull;
47 mask |= -(mskb & 0x08) & 0x00000000ff000000ull;
48 mask |= -(mskb & 0x10) & 0x000000ff00000000ull;
49 mask |= -(mskb & 0x20) & 0x0000ff0000000000ull;
50 mask |= -(mskb & 0x40) & 0x00ff000000000000ull;
51 mask |= -(mskb & 0x80) & 0xff00000000000000ull;
56 uint64_t helper_zap(uint64_t val, uint64_t mask)
58 return helper_zapnot(val, ~mask);
61 uint64_t helper_cmpbge(uint64_t op1, uint64_t op2)
63 uint8_t opa, opb, res;
67 for (i = 0; i < 8; i++) {
77 uint64_t helper_minub8(uint64_t op1, uint64_t op2)
80 uint8_t opa, opb, opr;
83 for (i = 0; i < 8; ++i) {
86 opr = opa < opb ? opa : opb;
87 res |= (uint64_t)opr << (i * 8);
92 uint64_t helper_minsb8(uint64_t op1, uint64_t op2)
99 for (i = 0; i < 8; ++i) {
100 opa = op1 >> (i * 8);
101 opb = op2 >> (i * 8);
102 opr = opa < opb ? opa : opb;
103 res |= (uint64_t)opr << (i * 8);
108 uint64_t helper_minuw4(uint64_t op1, uint64_t op2)
111 uint16_t opa, opb, opr;
114 for (i = 0; i < 4; ++i) {
115 opa = op1 >> (i * 16);
116 opb = op2 >> (i * 16);
117 opr = opa < opb ? opa : opb;
118 res |= (uint64_t)opr << (i * 16);
123 uint64_t helper_minsw4(uint64_t op1, uint64_t op2)
130 for (i = 0; i < 4; ++i) {
131 opa = op1 >> (i * 16);
132 opb = op2 >> (i * 16);
133 opr = opa < opb ? opa : opb;
134 res |= (uint64_t)opr << (i * 16);
139 uint64_t helper_maxub8(uint64_t op1, uint64_t op2)
142 uint8_t opa, opb, opr;
145 for (i = 0; i < 8; ++i) {
146 opa = op1 >> (i * 8);
147 opb = op2 >> (i * 8);
148 opr = opa > opb ? opa : opb;
149 res |= (uint64_t)opr << (i * 8);
154 uint64_t helper_maxsb8(uint64_t op1, uint64_t op2)
161 for (i = 0; i < 8; ++i) {
162 opa = op1 >> (i * 8);
163 opb = op2 >> (i * 8);
164 opr = opa > opb ? opa : opb;
165 res |= (uint64_t)opr << (i * 8);
170 uint64_t helper_maxuw4(uint64_t op1, uint64_t op2)
173 uint16_t opa, opb, opr;
176 for (i = 0; i < 4; ++i) {
177 opa = op1 >> (i * 16);
178 opb = op2 >> (i * 16);
179 opr = opa > opb ? opa : opb;
180 res |= (uint64_t)opr << (i * 16);
185 uint64_t helper_maxsw4(uint64_t op1, uint64_t op2)
192 for (i = 0; i < 4; ++i) {
193 opa = op1 >> (i * 16);
194 opb = op2 >> (i * 16);
195 opr = opa > opb ? opa : opb;
196 res |= (uint64_t)opr << (i * 16);
201 uint64_t helper_perr(uint64_t op1, uint64_t op2)
204 uint8_t opa, opb, opr;
207 for (i = 0; i < 8; ++i) {
208 opa = op1 >> (i * 8);
209 opb = op2 >> (i * 8);
220 uint64_t helper_pklb(uint64_t op1)
222 return (op1 & 0xff) | ((op1 >> 24) & 0xff00);
225 uint64_t helper_pkwb(uint64_t op1)
228 | ((op1 >> 8) & 0xff00)
229 | ((op1 >> 16) & 0xff0000)
230 | ((op1 >> 24) & 0xff000000));
233 uint64_t helper_unpkbl(uint64_t op1)
235 return (op1 & 0xff) | ((op1 & 0xff00) << 24);
238 uint64_t helper_unpkbw(uint64_t op1)
241 | ((op1 & 0xff00) << 8)
242 | ((op1 & 0xff0000) << 16)
243 | ((op1 & 0xff000000) << 24));
246 void helper_check_overflow(CPUAlphaState *env, uint64_t op1, uint64_t op2)
248 if (unlikely(op1 != op2)) {
249 arith_excp(env, GETPC(), EXC_M_IOV, 0);