1 #ifndef ASM_X86_INTERNAL_H
2 #warning Do not include this file directly
3 #else
4
asm_adcl(struct assembler_state_t * state,const uint32_t src,uint32_t * dst)5 static inline void asm_adcl(struct assembler_state_t *state, const uint32_t src, uint32_t *dst)
6 {
7 uint32_t tmp = *dst + src;
8 int of = 0;
9 int cf = 1;
10 if (read_cf(state->eflags))
11 {
12 tmp++;
13 (*dst)++;
14 if (*dst==0x00000000)
15 {
16 write_cf(state->eflags, 1);
17 cf=0;
18 }
19
20 if (*dst==0x80000000)
21 of = 1;
22 }
23
24 if (cf)
25 write_cf(state->eflags, tmp < *dst); /* unsigned overflow */
26
27 if ((*dst & 0x80000000) == (src & 0x80000000))
28 write_of(state->eflags, ((src & 0x80000000) != (tmp & 0x80000000)) ^ of); /* signed overflow */
29 else
30 write_of(state->eflags, of);
31
32 write_sf(state->eflags, tmp & 0x80000000);
33 write_zf(state->eflags, !tmp);
34 #ifdef X86_PF
35 asm_update_pf(state->eflags, tmp);
36 #endif
37 #ifdef X86_AF
38 asm_updae_af(state->eflags, tmp, *dst);
39 #endif
40
41 *dst = tmp;
42 }
asm_adcw(struct assembler_state_t * state,const uint16_t src,uint16_t * dst)43 static inline void asm_adcw(struct assembler_state_t *state, const uint16_t src, uint16_t *dst)
44 {
45 uint16_t tmp = *dst + src;
46 int of = 0;
47 int cf = 1;
48 if (read_cf(state->eflags))
49 {
50 tmp++;
51 (*dst)++;
52 if (*dst==0x0000)
53 {
54 write_cf(state->eflags, 1);
55 cf=0;
56 }
57
58 if (*dst==0x8000)
59 of = 1;
60 }
61
62 if (cf)
63 write_cf(state->eflags, tmp < *dst); /* unsigned overflow */
64
65 if ((*dst & 0x8000) == (src & 0x8000))
66 write_of(state->eflags, ((src & 0x8000) != (tmp & 0x8000)) ^ of); /* signed overflow */
67 else
68 write_of(state->eflags, of);
69
70 write_sf(state->eflags, tmp & 0x8000);
71 write_zf(state->eflags, !tmp);
72 #ifdef X86_PF
73 asm_update_pf(state->eflags, tmp);
74 #endif
75 #ifdef X86_AF
76 asm_update_af(state->eflags, tmp, *dst);
77 #endif
78
79 *dst = tmp;
80 }
asm_adcb(struct assembler_state_t * state,const uint8_t src,uint8_t * dst)81 static inline void asm_adcb(struct assembler_state_t *state, const uint8_t src, uint8_t *dst)
82 {
83 uint8_t tmp = *dst + src;
84 int of = 0;
85 int cf = 1;
86 if (read_cf(state->eflags))
87 {
88 tmp++;
89 (*dst)++;
90 if (*dst==0x00)
91 {
92 write_cf(state->eflags, 1);
93 cf=0;
94 }
95
96 if (*dst==0x80)
97 of = 1;
98 }
99
100 if (cf)
101 write_cf(state->eflags, tmp < *dst); /* unsigned overflow */
102
103 if ((*dst & 0x80) == (src & 0x80))
104 write_of(state->eflags, ((src & 0x80) != (tmp & 0x80)) ^ of); /* signed overflow */
105 else
106 write_of(state->eflags, of);
107
108 write_sf(state->eflags, tmp & 0x80);
109 write_zf(state->eflags, !tmp);
110 #ifdef X86_PF
111 asm_update_pf(state->eflags, tmp);
112 #endif
113 #ifdef X86_AF
114 asm_update_af(state->eflags, tmp, *dst);
115 #endif
116
117 *dst = tmp;
118 }
119
120 #endif
121