Statistics
| Branch: | Revision:

root / target-arm / op_helper.c @ 8f8e3aa4

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