slirp: switch to GPollFD
[qemu/agraf.git] / target-i386 / shift_helper_template.h
blobdda0da30cf8ea4ec97e591afcf69f97fee02dd26
1 /*
2 * x86 shift helpers
4 * Copyright (c) 2008 Fabrice Bellard
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 #define DATA_BITS (1 << (3 + SHIFT))
21 #define SHIFT_MASK (DATA_BITS - 1)
22 #if DATA_BITS <= 32
23 #define SHIFT1_MASK 0x1f
24 #else
25 #define SHIFT1_MASK 0x3f
26 #endif
28 #if DATA_BITS == 8
29 #define SUFFIX b
30 #define DATA_MASK 0xff
31 #elif DATA_BITS == 16
32 #define SUFFIX w
33 #define DATA_MASK 0xffff
34 #elif DATA_BITS == 32
35 #define SUFFIX l
36 #define DATA_MASK 0xffffffff
37 #elif DATA_BITS == 64
38 #define SUFFIX q
39 #define DATA_MASK 0xffffffffffffffffULL
40 #else
41 #error unhandled operand size
42 #endif
44 target_ulong glue(helper_rcl, SUFFIX)(CPUX86State *env, target_ulong t0,
45 target_ulong t1)
47 int count, eflags;
48 target_ulong src;
49 target_long res;
51 count = t1 & SHIFT1_MASK;
52 #if DATA_BITS == 16
53 count = rclw_table[count];
54 #elif DATA_BITS == 8
55 count = rclb_table[count];
56 #endif
57 if (count) {
58 eflags = helper_cc_compute_all(env, CC_OP);
59 t0 &= DATA_MASK;
60 src = t0;
61 res = (t0 << count) | ((target_ulong)(eflags & CC_C) << (count - 1));
62 if (count > 1) {
63 res |= t0 >> (DATA_BITS + 1 - count);
65 t0 = res;
66 env->cc_tmp = (eflags & ~(CC_C | CC_O)) |
67 (lshift(src ^ t0, 11 - (DATA_BITS - 1)) & CC_O) |
68 ((src >> (DATA_BITS - count)) & CC_C);
69 } else {
70 env->cc_tmp = -1;
72 return t0;
75 target_ulong glue(helper_rcr, SUFFIX)(CPUX86State *env, target_ulong t0,
76 target_ulong t1)
78 int count, eflags;
79 target_ulong src;
80 target_long res;
82 count = t1 & SHIFT1_MASK;
83 #if DATA_BITS == 16
84 count = rclw_table[count];
85 #elif DATA_BITS == 8
86 count = rclb_table[count];
87 #endif
88 if (count) {
89 eflags = helper_cc_compute_all(env, CC_OP);
90 t0 &= DATA_MASK;
91 src = t0;
92 res = (t0 >> count) |
93 ((target_ulong)(eflags & CC_C) << (DATA_BITS - count));
94 if (count > 1) {
95 res |= t0 << (DATA_BITS + 1 - count);
97 t0 = res;
98 env->cc_tmp = (eflags & ~(CC_C | CC_O)) |
99 (lshift(src ^ t0, 11 - (DATA_BITS - 1)) & CC_O) |
100 ((src >> (count - 1)) & CC_C);
101 } else {
102 env->cc_tmp = -1;
104 return t0;
107 #undef DATA_BITS
108 #undef SHIFT_MASK
109 #undef SHIFT1_MASK
110 #undef DATA_TYPE
111 #undef DATA_MASK
112 #undef SUFFIX