Statistics
| Branch: | Revision:

root / tests / test-i386-shift.h @ 9d8e9c09

History | View | Annotate | Download (3.4 kB)

1

    
2
#define exec_op glue(exec_, OP)
3
#define exec_opl glue(glue(exec_, OP), l)
4
#define exec_opw glue(glue(exec_, OP), w)
5
#define exec_opb glue(glue(exec_, OP), b)
6

    
7
#ifndef OP_SHIFTD
8

    
9
#ifdef OP_NOBYTE
10
#define EXECSHIFT(size, res, s1, s2, flags) \
11
    asm ("push %4\n\t"\
12
         "popf\n\t"\
13
         stringify(OP) size " %" size "2, %" size "0\n\t" \
14
         "pushf\n\t"\
15
         "popl %1\n\t"\
16
         : "=g" (res), "=g" (flags)\
17
         : "r" (s1), "0" (res), "1" (flags));
18
#else
19
#define EXECSHIFT(size, res, s1, s2, flags) \
20
    asm ("push %4\n\t"\
21
         "popf\n\t"\
22
         stringify(OP) size " %%cl, %" size "0\n\t" \
23
         "pushf\n\t"\
24
         "popl %1\n\t"\
25
         : "=q" (res), "=g" (flags)\
26
         : "c" (s1), "0" (res), "1" (flags));
27
#endif
28

    
29
void exec_opl(int s2, int s0, int s1, int iflags)
30
{
31
    int res, flags;
32
    res = s0;
33
    flags = iflags;
34
    EXECSHIFT("", res, s1, s2, flags);
35
    /* overflow is undefined if count != 1 */
36
    if (s1 != 1)
37
      flags &= ~CC_O;
38
    printf("%-10s A=%08x B=%08x R=%08x CCIN=%04x CC=%04x\n",
39
           stringify(OP) "l", s0, s1, res, iflags, flags & CC_MASK);
40
}
41

    
42
void exec_opw(int s2, int s0, int s1, int iflags)
43
{
44
    int res, flags;
45
    res = s0;
46
    flags = iflags;
47
    EXECSHIFT("w", res, s1, s2, flags);
48
    /* overflow is undefined if count != 1 */
49
    if (s1 != 1)
50
      flags &= ~CC_O;
51
    printf("%-10s A=%08x B=%08x R=%08x CCIN=%04x CC=%04x\n",
52
           stringify(OP) "w", s0, s1, res, iflags, flags & CC_MASK);
53
}
54

    
55
#else
56
#define EXECSHIFT(size, res, s1, s2, flags) \
57
    asm ("push %4\n\t"\
58
         "popf\n\t"\
59
         stringify(OP) size " %%cl, %" size "5, %" size "0\n\t" \
60
         "pushf\n\t"\
61
         "popl %1\n\t"\
62
         : "=g" (res), "=g" (flags)\
63
         : "c" (s1), "0" (res), "1" (flags), "r" (s2));
64

    
65
void exec_opl(int s2, int s0, int s1, int iflags)
66
{
67
    int res, flags;
68
    res = s0;
69
    flags = iflags;
70
    EXECSHIFT("", res, s1, s2, flags);
71
    /* overflow is undefined if count != 1 */
72
    if (s1 != 1)
73
      flags &= ~CC_O;
74
    printf("%-10s A=%08x B=%08x C=%08x R=%08x CCIN=%04x CC=%04x\n",
75
           stringify(OP) "l", s0, s2, s1, res, iflags, flags & CC_MASK);
76
}
77

    
78
void exec_opw(int s2, int s0, int s1, int iflags)
79
{
80
    int res, flags;
81
    res = s0;
82
    flags = iflags;
83
    EXECSHIFT("w", res, s1, s2, flags);
84
    /* overflow is undefined if count != 1 */
85
    if (s1 != 1)
86
      flags &= ~CC_O;
87
    printf("%-10s A=%08x B=%08x C=%08x R=%08x CCIN=%04x CC=%04x\n",
88
           stringify(OP) "w", s0, s2, s1, res, iflags, flags & CC_MASK);
89
}
90

    
91
#endif
92

    
93
#ifndef OP_NOBYTE
94
void exec_opb(int s0, int s1, int iflags)
95
{
96
    int res, flags;
97
    res = s0;
98
    flags = iflags;
99
    EXECSHIFT("b", res, s1, 0, flags);
100
    /* overflow is undefined if count != 1 */
101
    if (s1 != 1)
102
      flags &= ~CC_O;
103
    printf("%-10s A=%08x B=%08x R=%08x CCIN=%04x CC=%04x\n",
104
           stringify(OP) "b", s0, s1, res, iflags, flags & CC_MASK);
105
}
106
#endif
107

    
108
void exec_op(int s2, int s0, int s1)
109
{
110
    exec_opl(s2, s0, s1, 0);
111
    exec_opw(s2, s0, s1, 0);
112
#ifndef OP_NOBYTE
113
    exec_opb(s0, s1, 0);
114
#endif
115
#ifdef OP_CC
116
    exec_opl(s2, s0, s1, CC_C);
117
    exec_opw(s2, s0, s1, CC_C);
118
    exec_opb(s0, s1, CC_C);
119
#endif
120
}
121

    
122
void glue(test_, OP)(void)
123
{
124
    int i;
125
    for(i = 0; i < 32; i++)
126
        exec_op(0x21ad3d34, 0x12345678, i);
127
    for(i = 0; i < 32; i++)
128
        exec_op(0x813f3421, 0x82345678, i);
129
}
130

    
131
void *glue(_test_, OP) __init_call = glue(test_, OP);
132

    
133
#undef OP
134
#undef OP_CC
135
#undef OP_SHIFTD
136
#undef OP_NOBYTE
137
#undef EXECSHIFT
138