Statistics
| Branch: | Revision:

root / target-arm / op_helper.c @ a88790a1

History | View | Annotate | Download (10.7 kB)

1 b7bcbe95 bellard
/*
2 b7bcbe95 bellard
 *  ARM helper routines
3 5fafdf24 ths
 *
4 9ee6e8bb pbrook
 *  Copyright (c) 2005-2007 CodeSourcery, LLC
5 b7bcbe95 bellard
 *
6 b7bcbe95 bellard
 * This library is free software; you can redistribute it and/or
7 b7bcbe95 bellard
 * modify it under the terms of the GNU Lesser General Public
8 b7bcbe95 bellard
 * License as published by the Free Software Foundation; either
9 b7bcbe95 bellard
 * version 2 of the License, or (at your option) any later version.
10 b7bcbe95 bellard
 *
11 b7bcbe95 bellard
 * This library is distributed in the hope that it will be useful,
12 b7bcbe95 bellard
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 b7bcbe95 bellard
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
14 b7bcbe95 bellard
 * Lesser General Public License for more details.
15 b7bcbe95 bellard
 *
16 b7bcbe95 bellard
 * You should have received a copy of the GNU Lesser General Public
17 8167ee88 Blue Swirl
 * License along with this library; if not, see <http://www.gnu.org/licenses/>.
18 b7bcbe95 bellard
 */
19 b7bcbe95 bellard
#include "exec.h"
20 1497c961 pbrook
#include "helpers.h"
21 b7bcbe95 bellard
22 ad69471c pbrook
#define SIGNBIT (uint32_t)0x80000000
23 ad69471c pbrook
#define SIGNBIT64 ((uint64_t)1 << 63)
24 ad69471c pbrook
25 b7bcbe95 bellard
void raise_exception(int tt)
26 b7bcbe95 bellard
{
27 b7bcbe95 bellard
    env->exception_index = tt;
28 b7bcbe95 bellard
    cpu_loop_exit();
29 b7bcbe95 bellard
}
30 b7bcbe95 bellard
31 b7bcbe95 bellard
/* thread support */
32 b7bcbe95 bellard
33 c227f099 Anthony Liguori
static spinlock_t global_cpu_lock = SPIN_LOCK_UNLOCKED;
34 b7bcbe95 bellard
35 b7bcbe95 bellard
void cpu_lock(void)
36 b7bcbe95 bellard
{
37 b7bcbe95 bellard
    spin_lock(&global_cpu_lock);
38 b7bcbe95 bellard
}
39 b7bcbe95 bellard
40 b7bcbe95 bellard
void cpu_unlock(void)
41 b7bcbe95 bellard
{
42 b7bcbe95 bellard
    spin_unlock(&global_cpu_lock);
43 b7bcbe95 bellard
}
44 b7bcbe95 bellard
45 8f8e3aa4 pbrook
uint32_t HELPER(neon_tbl)(uint32_t ireg, uint32_t def,
46 8f8e3aa4 pbrook
                          uint32_t rn, uint32_t maxindex)
47 9ee6e8bb pbrook
{
48 9ee6e8bb pbrook
    uint32_t val;
49 9ee6e8bb pbrook
    uint32_t tmp;
50 9ee6e8bb pbrook
    int index;
51 9ee6e8bb pbrook
    int shift;
52 9ee6e8bb pbrook
    uint64_t *table;
53 9ee6e8bb pbrook
    table = (uint64_t *)&env->vfp.regs[rn];
54 9ee6e8bb pbrook
    val = 0;
55 9ee6e8bb pbrook
    for (shift = 0; shift < 32; shift += 8) {
56 8f8e3aa4 pbrook
        index = (ireg >> shift) & 0xff;
57 8f8e3aa4 pbrook
        if (index < maxindex) {
58 3018f259 pbrook
            tmp = (table[index >> 3] >> ((index & 7) << 3)) & 0xff;
59 9ee6e8bb pbrook
            val |= tmp << shift;
60 9ee6e8bb pbrook
        } else {
61 8f8e3aa4 pbrook
            val |= def & (0xff << shift);
62 9ee6e8bb pbrook
        }
63 9ee6e8bb pbrook
    }
64 8f8e3aa4 pbrook
    return val;
65 9ee6e8bb pbrook
}
66 9ee6e8bb pbrook
67 b5ff1b31 bellard
#if !defined(CONFIG_USER_ONLY)
68 b5ff1b31 bellard
69 b5ff1b31 bellard
#define MMUSUFFIX _mmu
70 b5ff1b31 bellard
71 b5ff1b31 bellard
#define SHIFT 0
72 b5ff1b31 bellard
#include "softmmu_template.h"
73 b5ff1b31 bellard
74 b5ff1b31 bellard
#define SHIFT 1
75 b5ff1b31 bellard
#include "softmmu_template.h"
76 b5ff1b31 bellard
77 b5ff1b31 bellard
#define SHIFT 2
78 b5ff1b31 bellard
#include "softmmu_template.h"
79 b5ff1b31 bellard
80 b5ff1b31 bellard
#define SHIFT 3
81 b5ff1b31 bellard
#include "softmmu_template.h"
82 b5ff1b31 bellard
83 b5ff1b31 bellard
/* try to fill the TLB and return an exception if error. If retaddr is
84 b5ff1b31 bellard
   NULL, it means that the function was called in C code (i.e. not
85 b5ff1b31 bellard
   from generated code or from helper.c) */
86 b5ff1b31 bellard
/* XXX: fix it to restore all registers */
87 6ebbf390 j_mayer
void tlb_fill (target_ulong addr, int is_write, int mmu_idx, void *retaddr)
88 b5ff1b31 bellard
{
89 b5ff1b31 bellard
    TranslationBlock *tb;
90 b5ff1b31 bellard
    CPUState *saved_env;
91 44f8625d bellard
    unsigned long pc;
92 b5ff1b31 bellard
    int ret;
93 b5ff1b31 bellard
94 b5ff1b31 bellard
    /* XXX: hack to restore env in all cases, even if not called from
95 b5ff1b31 bellard
       generated code */
96 b5ff1b31 bellard
    saved_env = env;
97 b5ff1b31 bellard
    env = cpu_single_env;
98 6ebbf390 j_mayer
    ret = cpu_arm_handle_mmu_fault(env, addr, is_write, mmu_idx, 1);
99 551bd27f ths
    if (unlikely(ret)) {
100 b5ff1b31 bellard
        if (retaddr) {
101 b5ff1b31 bellard
            /* now we have a real cpu fault */
102 44f8625d bellard
            pc = (unsigned long)retaddr;
103 b5ff1b31 bellard
            tb = tb_find_pc(pc);
104 b5ff1b31 bellard
            if (tb) {
105 b5ff1b31 bellard
                /* the PC is inside the translated code. It means that we have
106 b5ff1b31 bellard
                   a virtual CPU fault */
107 b5ff1b31 bellard
                cpu_restore_state(tb, env, pc, NULL);
108 b5ff1b31 bellard
            }
109 b5ff1b31 bellard
        }
110 b5ff1b31 bellard
        raise_exception(env->exception_index);
111 b5ff1b31 bellard
    }
112 b5ff1b31 bellard
    env = saved_env;
113 b5ff1b31 bellard
}
114 b5ff1b31 bellard
#endif
115 1497c961 pbrook
116 ad69471c pbrook
/* FIXME: Pass an axplicit pointer to QF to CPUState, and move saturating
117 ad69471c pbrook
   instructions into helper.c  */
118 1497c961 pbrook
uint32_t HELPER(add_setq)(uint32_t a, uint32_t b)
119 1497c961 pbrook
{
120 1497c961 pbrook
    uint32_t res = a + b;
121 1497c961 pbrook
    if (((res ^ a) & SIGNBIT) && !((a ^ b) & SIGNBIT))
122 1497c961 pbrook
        env->QF = 1;
123 1497c961 pbrook
    return res;
124 1497c961 pbrook
}
125 1497c961 pbrook
126 1497c961 pbrook
uint32_t HELPER(add_saturate)(uint32_t a, uint32_t b)
127 1497c961 pbrook
{
128 1497c961 pbrook
    uint32_t res = a + b;
129 1497c961 pbrook
    if (((res ^ a) & SIGNBIT) && !((a ^ b) & SIGNBIT)) {
130 1497c961 pbrook
        env->QF = 1;
131 1497c961 pbrook
        res = ~(((int32_t)a >> 31) ^ SIGNBIT);
132 1497c961 pbrook
    }
133 1497c961 pbrook
    return res;
134 1497c961 pbrook
}
135 1497c961 pbrook
136 1497c961 pbrook
uint32_t HELPER(sub_saturate)(uint32_t a, uint32_t b)
137 1497c961 pbrook
{
138 1497c961 pbrook
    uint32_t res = a - b;
139 1497c961 pbrook
    if (((res ^ a) & SIGNBIT) && ((a ^ b) & SIGNBIT)) {
140 1497c961 pbrook
        env->QF = 1;
141 1497c961 pbrook
        res = ~(((int32_t)a >> 31) ^ SIGNBIT);
142 1497c961 pbrook
    }
143 1497c961 pbrook
    return res;
144 1497c961 pbrook
}
145 1497c961 pbrook
146 1497c961 pbrook
uint32_t HELPER(double_saturate)(int32_t val)
147 1497c961 pbrook
{
148 1497c961 pbrook
    uint32_t res;
149 1497c961 pbrook
    if (val >= 0x40000000) {
150 1497c961 pbrook
        res = ~SIGNBIT;
151 1497c961 pbrook
        env->QF = 1;
152 1497c961 pbrook
    } else if (val <= (int32_t)0xc0000000) {
153 1497c961 pbrook
        res = SIGNBIT;
154 1497c961 pbrook
        env->QF = 1;
155 1497c961 pbrook
    } else {
156 1497c961 pbrook
        res = val << 1;
157 1497c961 pbrook
    }
158 1497c961 pbrook
    return res;
159 1497c961 pbrook
}
160 1497c961 pbrook
161 1497c961 pbrook
uint32_t HELPER(add_usaturate)(uint32_t a, uint32_t b)
162 1497c961 pbrook
{
163 1497c961 pbrook
    uint32_t res = a + b;
164 1497c961 pbrook
    if (res < a) {
165 1497c961 pbrook
        env->QF = 1;
166 1497c961 pbrook
        res = ~0;
167 1497c961 pbrook
    }
168 1497c961 pbrook
    return res;
169 1497c961 pbrook
}
170 1497c961 pbrook
171 1497c961 pbrook
uint32_t HELPER(sub_usaturate)(uint32_t a, uint32_t b)
172 1497c961 pbrook
{
173 1497c961 pbrook
    uint32_t res = a - b;
174 1497c961 pbrook
    if (res > a) {
175 1497c961 pbrook
        env->QF = 1;
176 1497c961 pbrook
        res = 0;
177 1497c961 pbrook
    }
178 1497c961 pbrook
    return res;
179 1497c961 pbrook
}
180 1497c961 pbrook
181 6ddbc6e4 pbrook
/* Signed saturation.  */
182 6ddbc6e4 pbrook
static inline uint32_t do_ssat(int32_t val, int shift)
183 6ddbc6e4 pbrook
{
184 6ddbc6e4 pbrook
    int32_t top;
185 6ddbc6e4 pbrook
    uint32_t mask;
186 6ddbc6e4 pbrook
187 6ddbc6e4 pbrook
    top = val >> shift;
188 6ddbc6e4 pbrook
    mask = (1u << shift) - 1;
189 6ddbc6e4 pbrook
    if (top > 0) {
190 6ddbc6e4 pbrook
        env->QF = 1;
191 6ddbc6e4 pbrook
        return mask;
192 6ddbc6e4 pbrook
    } else if (top < -1) {
193 6ddbc6e4 pbrook
        env->QF = 1;
194 6ddbc6e4 pbrook
        return ~mask;
195 6ddbc6e4 pbrook
    }
196 6ddbc6e4 pbrook
    return val;
197 6ddbc6e4 pbrook
}
198 6ddbc6e4 pbrook
199 6ddbc6e4 pbrook
/* Unsigned saturation.  */
200 6ddbc6e4 pbrook
static inline uint32_t do_usat(int32_t val, int shift)
201 6ddbc6e4 pbrook
{
202 6ddbc6e4 pbrook
    uint32_t max;
203 6ddbc6e4 pbrook
204 6ddbc6e4 pbrook
    max = (1u << shift) - 1;
205 6ddbc6e4 pbrook
    if (val < 0) {
206 6ddbc6e4 pbrook
        env->QF = 1;
207 6ddbc6e4 pbrook
        return 0;
208 6ddbc6e4 pbrook
    } else if (val > max) {
209 6ddbc6e4 pbrook
        env->QF = 1;
210 6ddbc6e4 pbrook
        return max;
211 6ddbc6e4 pbrook
    }
212 6ddbc6e4 pbrook
    return val;
213 6ddbc6e4 pbrook
}
214 6ddbc6e4 pbrook
215 6ddbc6e4 pbrook
/* Signed saturate.  */
216 6ddbc6e4 pbrook
uint32_t HELPER(ssat)(uint32_t x, uint32_t shift)
217 6ddbc6e4 pbrook
{
218 6ddbc6e4 pbrook
    return do_ssat(x, shift);
219 6ddbc6e4 pbrook
}
220 6ddbc6e4 pbrook
221 6ddbc6e4 pbrook
/* Dual halfword signed saturate.  */
222 6ddbc6e4 pbrook
uint32_t HELPER(ssat16)(uint32_t x, uint32_t shift)
223 6ddbc6e4 pbrook
{
224 6ddbc6e4 pbrook
    uint32_t res;
225 6ddbc6e4 pbrook
226 6ddbc6e4 pbrook
    res = (uint16_t)do_ssat((int16_t)x, shift);
227 6ddbc6e4 pbrook
    res |= do_ssat(((int32_t)x) >> 16, shift) << 16;
228 6ddbc6e4 pbrook
    return res;
229 6ddbc6e4 pbrook
}
230 6ddbc6e4 pbrook
231 6ddbc6e4 pbrook
/* Unsigned saturate.  */
232 6ddbc6e4 pbrook
uint32_t HELPER(usat)(uint32_t x, uint32_t shift)
233 6ddbc6e4 pbrook
{
234 6ddbc6e4 pbrook
    return do_usat(x, shift);
235 6ddbc6e4 pbrook
}
236 6ddbc6e4 pbrook
237 6ddbc6e4 pbrook
/* Dual halfword unsigned saturate.  */
238 6ddbc6e4 pbrook
uint32_t HELPER(usat16)(uint32_t x, uint32_t shift)
239 6ddbc6e4 pbrook
{
240 6ddbc6e4 pbrook
    uint32_t res;
241 6ddbc6e4 pbrook
242 6ddbc6e4 pbrook
    res = (uint16_t)do_usat((int16_t)x, shift);
243 6ddbc6e4 pbrook
    res |= do_usat(((int32_t)x) >> 16, shift) << 16;
244 6ddbc6e4 pbrook
    return res;
245 6ddbc6e4 pbrook
}
246 d9ba4830 pbrook
247 d9ba4830 pbrook
void HELPER(wfi)(void)
248 d9ba4830 pbrook
{
249 d9ba4830 pbrook
    env->exception_index = EXCP_HLT;
250 d9ba4830 pbrook
    env->halted = 1;
251 d9ba4830 pbrook
    cpu_loop_exit();
252 d9ba4830 pbrook
}
253 d9ba4830 pbrook
254 d9ba4830 pbrook
void HELPER(exception)(uint32_t excp)
255 d9ba4830 pbrook
{
256 d9ba4830 pbrook
    env->exception_index = excp;
257 d9ba4830 pbrook
    cpu_loop_exit();
258 d9ba4830 pbrook
}
259 d9ba4830 pbrook
260 d9ba4830 pbrook
uint32_t HELPER(cpsr_read)(void)
261 d9ba4830 pbrook
{
262 d9ba4830 pbrook
    return cpsr_read(env) & ~CPSR_EXEC;
263 d9ba4830 pbrook
}
264 d9ba4830 pbrook
265 d9ba4830 pbrook
void HELPER(cpsr_write)(uint32_t val, uint32_t mask)
266 d9ba4830 pbrook
{
267 d9ba4830 pbrook
    cpsr_write(env, val, mask);
268 d9ba4830 pbrook
}
269 b0109805 pbrook
270 b0109805 pbrook
/* Access to user mode registers from privileged modes.  */
271 b0109805 pbrook
uint32_t HELPER(get_user_reg)(uint32_t regno)
272 b0109805 pbrook
{
273 b0109805 pbrook
    uint32_t val;
274 b0109805 pbrook
275 b0109805 pbrook
    if (regno == 13) {
276 b0109805 pbrook
        val = env->banked_r13[0];
277 b0109805 pbrook
    } else if (regno == 14) {
278 b0109805 pbrook
        val = env->banked_r14[0];
279 b0109805 pbrook
    } else if (regno >= 8
280 b0109805 pbrook
               && (env->uncached_cpsr & 0x1f) == ARM_CPU_MODE_FIQ) {
281 b0109805 pbrook
        val = env->usr_regs[regno - 8];
282 b0109805 pbrook
    } else {
283 b0109805 pbrook
        val = env->regs[regno];
284 b0109805 pbrook
    }
285 b0109805 pbrook
    return val;
286 b0109805 pbrook
}
287 b0109805 pbrook
288 b0109805 pbrook
void HELPER(set_user_reg)(uint32_t regno, uint32_t val)
289 b0109805 pbrook
{
290 b0109805 pbrook
    if (regno == 13) {
291 b0109805 pbrook
        env->banked_r13[0] = val;
292 b0109805 pbrook
    } else if (regno == 14) {
293 b0109805 pbrook
        env->banked_r14[0] = val;
294 b0109805 pbrook
    } else if (regno >= 8
295 b0109805 pbrook
               && (env->uncached_cpsr & 0x1f) == ARM_CPU_MODE_FIQ) {
296 b0109805 pbrook
        env->usr_regs[regno - 8] = val;
297 b0109805 pbrook
    } else {
298 b0109805 pbrook
        env->regs[regno] = val;
299 b0109805 pbrook
    }
300 b0109805 pbrook
}
301 b0109805 pbrook
302 8984bd2e pbrook
/* ??? Flag setting arithmetic is awkward because we need to do comparisons.
303 8984bd2e pbrook
   The only way to do that in TCG is a conditional branch, which clobbers
304 8984bd2e pbrook
   all our temporaries.  For now implement these as helper functions.  */
305 8984bd2e pbrook
306 8984bd2e pbrook
uint32_t HELPER (add_cc)(uint32_t a, uint32_t b)
307 8984bd2e pbrook
{
308 8984bd2e pbrook
    uint32_t result;
309 37f9ba46 aurel32
    result = a + b;
310 6fbe23d5 pbrook
    env->NF = env->ZF = result;
311 8984bd2e pbrook
    env->CF = result < a;
312 8984bd2e pbrook
    env->VF = (a ^ b ^ -1) & (a ^ result);
313 8984bd2e pbrook
    return result;
314 8984bd2e pbrook
}
315 8984bd2e pbrook
316 8984bd2e pbrook
uint32_t HELPER(adc_cc)(uint32_t a, uint32_t b)
317 8984bd2e pbrook
{
318 8984bd2e pbrook
    uint32_t result;
319 8984bd2e pbrook
    if (!env->CF) {
320 8984bd2e pbrook
        result = a + b;
321 8984bd2e pbrook
        env->CF = result < a;
322 8984bd2e pbrook
    } else {
323 8984bd2e pbrook
        result = a + b + 1;
324 8984bd2e pbrook
        env->CF = result <= a;
325 8984bd2e pbrook
    }
326 8984bd2e pbrook
    env->VF = (a ^ b ^ -1) & (a ^ result);
327 6fbe23d5 pbrook
    env->NF = env->ZF = result;
328 8984bd2e pbrook
    return result;
329 8984bd2e pbrook
}
330 8984bd2e pbrook
331 8984bd2e pbrook
uint32_t HELPER(sub_cc)(uint32_t a, uint32_t b)
332 8984bd2e pbrook
{
333 8984bd2e pbrook
    uint32_t result;
334 8984bd2e pbrook
    result = a - b;
335 6fbe23d5 pbrook
    env->NF = env->ZF = result;
336 8984bd2e pbrook
    env->CF = a >= b;
337 8984bd2e pbrook
    env->VF = (a ^ b) & (a ^ result);
338 8984bd2e pbrook
    return result;
339 8984bd2e pbrook
}
340 8984bd2e pbrook
341 8984bd2e pbrook
uint32_t HELPER(sbc_cc)(uint32_t a, uint32_t b)
342 8984bd2e pbrook
{
343 8984bd2e pbrook
    uint32_t result;
344 8984bd2e pbrook
    if (!env->CF) {
345 8984bd2e pbrook
        result = a - b - 1;
346 8984bd2e pbrook
        env->CF = a > b;
347 8984bd2e pbrook
    } else {
348 8984bd2e pbrook
        result = a - b;
349 8984bd2e pbrook
        env->CF = a >= b;
350 8984bd2e pbrook
    }
351 8984bd2e pbrook
    env->VF = (a ^ b) & (a ^ result);
352 6fbe23d5 pbrook
    env->NF = env->ZF = result;
353 8984bd2e pbrook
    return result;
354 8984bd2e pbrook
}
355 8984bd2e pbrook
356 8984bd2e pbrook
/* Similarly for variable shift instructions.  */
357 8984bd2e pbrook
358 8984bd2e pbrook
uint32_t HELPER(shl)(uint32_t x, uint32_t i)
359 8984bd2e pbrook
{
360 8984bd2e pbrook
    int shift = i & 0xff;
361 8984bd2e pbrook
    if (shift >= 32)
362 8984bd2e pbrook
        return 0;
363 8984bd2e pbrook
    return x << shift;
364 8984bd2e pbrook
}
365 8984bd2e pbrook
366 8984bd2e pbrook
uint32_t HELPER(shr)(uint32_t x, uint32_t i)
367 8984bd2e pbrook
{
368 8984bd2e pbrook
    int shift = i & 0xff;
369 8984bd2e pbrook
    if (shift >= 32)
370 8984bd2e pbrook
        return 0;
371 8984bd2e pbrook
    return (uint32_t)x >> shift;
372 8984bd2e pbrook
}
373 8984bd2e pbrook
374 8984bd2e pbrook
uint32_t HELPER(sar)(uint32_t x, uint32_t i)
375 8984bd2e pbrook
{
376 8984bd2e pbrook
    int shift = i & 0xff;
377 8984bd2e pbrook
    if (shift >= 32)
378 8984bd2e pbrook
        shift = 31;
379 8984bd2e pbrook
    return (int32_t)x >> shift;
380 8984bd2e pbrook
}
381 8984bd2e pbrook
382 8984bd2e pbrook
uint32_t HELPER(shl_cc)(uint32_t x, uint32_t i)
383 8984bd2e pbrook
{
384 8984bd2e pbrook
    int shift = i & 0xff;
385 8984bd2e pbrook
    if (shift >= 32) {
386 8984bd2e pbrook
        if (shift == 32)
387 8984bd2e pbrook
            env->CF = x & 1;
388 8984bd2e pbrook
        else
389 8984bd2e pbrook
            env->CF = 0;
390 8984bd2e pbrook
        return 0;
391 8984bd2e pbrook
    } else if (shift != 0) {
392 8984bd2e pbrook
        env->CF = (x >> (32 - shift)) & 1;
393 8984bd2e pbrook
        return x << shift;
394 8984bd2e pbrook
    }
395 8984bd2e pbrook
    return x;
396 8984bd2e pbrook
}
397 8984bd2e pbrook
398 8984bd2e pbrook
uint32_t HELPER(shr_cc)(uint32_t x, uint32_t i)
399 8984bd2e pbrook
{
400 8984bd2e pbrook
    int shift = i & 0xff;
401 8984bd2e pbrook
    if (shift >= 32) {
402 8984bd2e pbrook
        if (shift == 32)
403 8984bd2e pbrook
            env->CF = (x >> 31) & 1;
404 8984bd2e pbrook
        else
405 8984bd2e pbrook
            env->CF = 0;
406 8984bd2e pbrook
        return 0;
407 8984bd2e pbrook
    } else if (shift != 0) {
408 8984bd2e pbrook
        env->CF = (x >> (shift - 1)) & 1;
409 8984bd2e pbrook
        return x >> shift;
410 8984bd2e pbrook
    }
411 8984bd2e pbrook
    return x;
412 8984bd2e pbrook
}
413 8984bd2e pbrook
414 8984bd2e pbrook
uint32_t HELPER(sar_cc)(uint32_t x, uint32_t i)
415 8984bd2e pbrook
{
416 8984bd2e pbrook
    int shift = i & 0xff;
417 8984bd2e pbrook
    if (shift >= 32) {
418 8984bd2e pbrook
        env->CF = (x >> 31) & 1;
419 8984bd2e pbrook
        return (int32_t)x >> 31;
420 8984bd2e pbrook
    } else if (shift != 0) {
421 8984bd2e pbrook
        env->CF = (x >> (shift - 1)) & 1;
422 8984bd2e pbrook
        return (int32_t)x >> shift;
423 8984bd2e pbrook
    }
424 8984bd2e pbrook
    return x;
425 8984bd2e pbrook
}
426 8984bd2e pbrook
427 8984bd2e pbrook
uint32_t HELPER(ror_cc)(uint32_t x, uint32_t i)
428 8984bd2e pbrook
{
429 8984bd2e pbrook
    int shift1, shift;
430 8984bd2e pbrook
    shift1 = i & 0xff;
431 8984bd2e pbrook
    shift = shift1 & 0x1f;
432 8984bd2e pbrook
    if (shift == 0) {
433 8984bd2e pbrook
        if (shift1 != 0)
434 8984bd2e pbrook
            env->CF = (x >> 31) & 1;
435 8984bd2e pbrook
        return x;
436 8984bd2e pbrook
    } else {
437 8984bd2e pbrook
        env->CF = (x >> (shift - 1)) & 1;
438 8984bd2e pbrook
        return ((uint32_t)x >> shift) | (x << (32 - shift));
439 8984bd2e pbrook
    }
440 8984bd2e pbrook
}
441 8984bd2e pbrook
442 ad69471c pbrook
uint64_t HELPER(neon_add_saturate_s64)(uint64_t src1, uint64_t src2)
443 ad69471c pbrook
{
444 ad69471c pbrook
    uint64_t res;
445 ad69471c pbrook
446 ad69471c pbrook
    res = src1 + src2;
447 ad69471c pbrook
    if (((res ^ src1) & SIGNBIT64) && !((src1 ^ src2) & SIGNBIT64)) {
448 ad69471c pbrook
        env->QF = 1;
449 ad69471c pbrook
        res = ((int64_t)src1 >> 63) ^ ~SIGNBIT64;
450 ad69471c pbrook
    }
451 ad69471c pbrook
    return res;
452 ad69471c pbrook
}
453 ad69471c pbrook
454 ad69471c pbrook
uint64_t HELPER(neon_add_saturate_u64)(uint64_t src1, uint64_t src2)
455 ad69471c pbrook
{
456 ad69471c pbrook
    uint64_t res;
457 ad69471c pbrook
458 ad69471c pbrook
    res = src1 + src2;
459 ad69471c pbrook
    if (res < src1) {
460 ad69471c pbrook
        env->QF = 1;
461 ad69471c pbrook
        res = ~(uint64_t)0;
462 ad69471c pbrook
    }
463 ad69471c pbrook
    return res;
464 ad69471c pbrook
}
465 ad69471c pbrook
466 ad69471c pbrook
uint64_t HELPER(neon_sub_saturate_s64)(uint64_t src1, uint64_t src2)
467 ad69471c pbrook
{
468 ad69471c pbrook
    uint64_t res;
469 ad69471c pbrook
470 ad69471c pbrook
    res = src1 - src2;
471 ad69471c pbrook
    if (((res ^ src1) & SIGNBIT64) && ((src1 ^ src2) & SIGNBIT64)) {
472 ad69471c pbrook
        env->QF = 1;
473 ad69471c pbrook
        res = ((int64_t)src1 >> 63) ^ ~SIGNBIT64;
474 ad69471c pbrook
    }
475 ad69471c pbrook
    return res;
476 ad69471c pbrook
}
477 ad69471c pbrook
478 ad69471c pbrook
uint64_t HELPER(neon_sub_saturate_u64)(uint64_t src1, uint64_t src2)
479 ad69471c pbrook
{
480 ad69471c pbrook
    uint64_t res;
481 ad69471c pbrook
482 ad69471c pbrook
    if (src1 < src2) {
483 ad69471c pbrook
        env->QF = 1;
484 ad69471c pbrook
        res = 0;
485 ad69471c pbrook
    } else {
486 ad69471c pbrook
        res = src1 - src2;
487 ad69471c pbrook
    }
488 ad69471c pbrook
    return res;
489 ad69471c pbrook
}