6 typedef unsigned int UInt
;
8 /* Given a word, do bt/bts/btr/btc on bits 0, 1, 2 and 3 of it, and
9 also reconstruct the original bits 0, 1, 2, 3 by looking at the
10 carry flag. Returned result has mashed bits 0-3 at the bottom and
11 the reconstructed original bits 0-3 as 4-7. */
12 UInt
mash_reg_L ( UInt orig
)
14 UInt reconstructed
, mashed
;
15 __asm__
__volatile__ (
22 "movzbl %%cl, %%ecx\n\t"
23 "orl %%ecx, %%eax\n\t"
27 "movzbl %%cl, %%ecx\n\t"
29 "orl %%ecx, %%eax\n\t"
33 "movzbl %%cl, %%ecx\n\t"
35 "orl %%ecx, %%eax\n\t"
39 "movzbl %%cl, %%ecx\n\t"
41 "orl %%ecx, %%eax\n\t"
46 : "=r" (reconstructed
), "=r" (mashed
)
48 : "eax", "ecx", "edx", "cc");
49 return (mashed
& 0xF) | ((reconstructed
& 0xF) << 4);
55 UInt
mash_mem_L ( int* origp
)
57 UInt reconstructed
, mashed
;
58 __asm__
__volatile__ (
65 "movzbl %%cl, %%ecx\n\t"
66 "orl %%ecx, %%eax\n\t"
68 "btsl $1, (%%edx)\n\t"
70 "movzbl %%cl, %%ecx\n\t"
72 "orl %%ecx, %%eax\n\t"
74 "btrl $2, (%%edx)\n\t"
76 "movzbl %%cl, %%ecx\n\t"
78 "orl %%ecx, %%eax\n\t"
80 "btcl $3, (%%edx)\n\t"
82 "movzbl %%cl, %%ecx\n\t"
84 "orl %%ecx, %%eax\n\t"
89 : "=r" (reconstructed
), "=r" (mashed
)
91 : "eax", "ecx", "edx", "cc");
92 return (mashed
& 0xF) | ((reconstructed
& 0xF) << 4);
97 UInt
mash_reg_W ( UInt orig
)
99 UInt reconstructed
, mashed
;
100 __asm__
__volatile__ (
107 "movzbl %%cl, %%ecx\n\t"
108 "orl %%ecx, %%eax\n\t"
112 "movzbl %%cl, %%ecx\n\t"
114 "orl %%ecx, %%eax\n\t"
118 "movzbl %%cl, %%ecx\n\t"
120 "orl %%ecx, %%eax\n\t"
124 "movzbl %%cl, %%ecx\n\t"
126 "orl %%ecx, %%eax\n\t"
131 : "=r" (reconstructed
), "=r" (mashed
)
133 : "eax", "ecx", "edx", "cc");
134 return (mashed
& 0xF) | ((reconstructed
& 0xF) << 4);
143 for (i
= 0; i
< 0x10; i
++) {
145 printf("0x%x -> 0x%2x 0x%2x 0x%2x\n", i
,
146 mash_reg_L(i
), mash_mem_L(&ii
), mash_reg_W(i
));