Statistics
| Branch: | Revision:

root / target-arm / op_helper.c @ f8bf8606

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