rdma: fix memory leak
[qemu/cris-port.git] / target-alpha / int_helper.c
blob74f38cbe7bf218ad593f5f90f4fd8f8e41872cd2
1 /*
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/>.
20 #include "cpu.h"
21 #include "exec/helper-proto.h"
22 #include "qemu/host-utils.h"
25 uint64_t helper_ctpop(uint64_t arg)
27 return ctpop64(arg);
30 uint64_t helper_ctlz(uint64_t arg)
32 return clz64(arg);
35 uint64_t helper_cttz(uint64_t arg)
37 return ctz64(arg);
40 uint64_t helper_zapnot(uint64_t val, uint64_t mskb)
42 uint64_t mask;
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;
53 return val & mask;
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;
64 int i;
66 res = 0;
67 for (i = 0; i < 8; i++) {
68 opa = op1 >> (i * 8);
69 opb = op2 >> (i * 8);
70 if (opa >= opb) {
71 res |= 1 << i;
74 return res;
77 uint64_t helper_minub8(uint64_t op1, uint64_t op2)
79 uint64_t res = 0;
80 uint8_t opa, opb, opr;
81 int i;
83 for (i = 0; i < 8; ++i) {
84 opa = op1 >> (i * 8);
85 opb = op2 >> (i * 8);
86 opr = opa < opb ? opa : opb;
87 res |= (uint64_t)opr << (i * 8);
89 return res;
92 uint64_t helper_minsb8(uint64_t op1, uint64_t op2)
94 uint64_t res = 0;
95 int8_t opa, opb;
96 uint8_t opr;
97 int i;
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);
105 return res;
108 uint64_t helper_minuw4(uint64_t op1, uint64_t op2)
110 uint64_t res = 0;
111 uint16_t opa, opb, opr;
112 int i;
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);
120 return res;
123 uint64_t helper_minsw4(uint64_t op1, uint64_t op2)
125 uint64_t res = 0;
126 int16_t opa, opb;
127 uint16_t opr;
128 int i;
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);
136 return res;
139 uint64_t helper_maxub8(uint64_t op1, uint64_t op2)
141 uint64_t res = 0;
142 uint8_t opa, opb, opr;
143 int i;
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);
151 return res;
154 uint64_t helper_maxsb8(uint64_t op1, uint64_t op2)
156 uint64_t res = 0;
157 int8_t opa, opb;
158 uint8_t opr;
159 int i;
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);
167 return res;
170 uint64_t helper_maxuw4(uint64_t op1, uint64_t op2)
172 uint64_t res = 0;
173 uint16_t opa, opb, opr;
174 int i;
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);
182 return res;
185 uint64_t helper_maxsw4(uint64_t op1, uint64_t op2)
187 uint64_t res = 0;
188 int16_t opa, opb;
189 uint16_t opr;
190 int i;
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);
198 return res;
201 uint64_t helper_perr(uint64_t op1, uint64_t op2)
203 uint64_t res = 0;
204 uint8_t opa, opb, opr;
205 int i;
207 for (i = 0; i < 8; ++i) {
208 opa = op1 >> (i * 8);
209 opb = op2 >> (i * 8);
210 if (opa >= opb) {
211 opr = opa - opb;
212 } else {
213 opr = opb - opa;
215 res += opr;
217 return res;
220 uint64_t helper_pklb(uint64_t op1)
222 return (op1 & 0xff) | ((op1 >> 24) & 0xff00);
225 uint64_t helper_pkwb(uint64_t op1)
227 return ((op1 & 0xff)
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)
240 return ((op1 & 0xff)
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);