root / target-i386 / helper_template.h @ cad3a37d
History | View | Annotate | Download (3.2 kB)
1 |
/*
|
---|---|
2 |
* i386 helpers
|
3 |
*
|
4 |
* Copyright (c) 2008 Fabrice Bellard
|
5 |
*
|
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.
|
10 |
*
|
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.
|
15 |
*
|
16 |
* You should have received a copy of the GNU Lesser General Public
|
17 |
* License along with this library; if not, write to the Free Software
|
18 |
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
19 |
*/
|
20 |
#define DATA_BITS (1 << (3 + SHIFT)) |
21 |
#define SHIFT_MASK (DATA_BITS - 1) |
22 |
#define SIGN_MASK (((target_ulong)1) << (DATA_BITS - 1)) |
23 |
#if DATA_BITS <= 32 |
24 |
#define SHIFT1_MASK 0x1f |
25 |
#else
|
26 |
#define SHIFT1_MASK 0x3f |
27 |
#endif
|
28 |
|
29 |
#if DATA_BITS == 8 |
30 |
#define SUFFIX b
|
31 |
#define DATA_TYPE uint8_t
|
32 |
#define DATA_STYPE int8_t
|
33 |
#define DATA_MASK 0xff |
34 |
#elif DATA_BITS == 16 |
35 |
#define SUFFIX w
|
36 |
#define DATA_TYPE uint16_t
|
37 |
#define DATA_STYPE int16_t
|
38 |
#define DATA_MASK 0xffff |
39 |
#elif DATA_BITS == 32 |
40 |
#define SUFFIX l
|
41 |
#define DATA_TYPE uint32_t
|
42 |
#define DATA_STYPE int32_t
|
43 |
#define DATA_MASK 0xffffffff |
44 |
#elif DATA_BITS == 64 |
45 |
#define SUFFIX q
|
46 |
#define DATA_TYPE uint64_t
|
47 |
#define DATA_STYPE int64_t
|
48 |
#define DATA_MASK 0xffffffffffffffffULL |
49 |
#else
|
50 |
#error unhandled operand size
|
51 |
#endif
|
52 |
|
53 |
target_ulong glue(helper_rcl, SUFFIX)(target_ulong t0, target_ulong t1) |
54 |
{ |
55 |
int count, eflags;
|
56 |
target_ulong src; |
57 |
target_long res; |
58 |
|
59 |
count = t1 & SHIFT1_MASK; |
60 |
#if DATA_BITS == 16 |
61 |
count = rclw_table[count]; |
62 |
#elif DATA_BITS == 8 |
63 |
count = rclb_table[count]; |
64 |
#endif
|
65 |
if (count) {
|
66 |
eflags = cc_table[CC_OP].compute_all(); |
67 |
t0 &= DATA_MASK; |
68 |
src = t0; |
69 |
res = (t0 << count) | ((target_ulong)(eflags & CC_C) << (count - 1));
|
70 |
if (count > 1) |
71 |
res |= t0 >> (DATA_BITS + 1 - count);
|
72 |
t0 = res; |
73 |
env->t3 = (eflags & ~(CC_C | CC_O)) | |
74 |
(lshift(src ^ t0, 11 - (DATA_BITS - 1)) & CC_O) | |
75 |
((src >> (DATA_BITS - count)) & CC_C); |
76 |
} else {
|
77 |
env->t3 = -1;
|
78 |
} |
79 |
return t0;
|
80 |
} |
81 |
|
82 |
target_ulong glue(helper_rcr, SUFFIX)(target_ulong t0, target_ulong t1) |
83 |
{ |
84 |
int count, eflags;
|
85 |
target_ulong src; |
86 |
target_long res; |
87 |
|
88 |
count = t1 & SHIFT1_MASK; |
89 |
#if DATA_BITS == 16 |
90 |
count = rclw_table[count]; |
91 |
#elif DATA_BITS == 8 |
92 |
count = rclb_table[count]; |
93 |
#endif
|
94 |
if (count) {
|
95 |
eflags = cc_table[CC_OP].compute_all(); |
96 |
t0 &= DATA_MASK; |
97 |
src = t0; |
98 |
res = (t0 >> count) | ((target_ulong)(eflags & CC_C) << (DATA_BITS - count)); |
99 |
if (count > 1) |
100 |
res |= t0 << (DATA_BITS + 1 - count);
|
101 |
t0 = res; |
102 |
env->t3 = (eflags & ~(CC_C | CC_O)) | |
103 |
(lshift(src ^ t0, 11 - (DATA_BITS - 1)) & CC_O) | |
104 |
((src >> (count - 1)) & CC_C);
|
105 |
} else {
|
106 |
env->t3 = -1;
|
107 |
} |
108 |
return t0;
|
109 |
} |
110 |
|
111 |
#undef DATA_BITS
|
112 |
#undef SHIFT_MASK
|
113 |
#undef SHIFT1_MASK
|
114 |
#undef SIGN_MASK
|
115 |
#undef DATA_TYPE
|
116 |
#undef DATA_STYPE
|
117 |
#undef DATA_MASK
|
118 |
#undef SUFFIX
|