Skip to content

Commit 2dc78b5

Browse files
committed
fix: add 'char' type to parity flag to match x86 🐛
1 parent d083959 commit 2dc78b5

File tree

1 file changed

+11
-11
lines changed

1 file changed

+11
-11
lines changed

source/include/arithmetics.h

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -60,13 +60,13 @@
6060
_SF = (_RES < 0); \
6161
_CF = (TO_UNSIGNED(_T1) < TO_UNSIGNED(_T2)); \
6262
_OF = ((_T1 < 0 && _T2 > 0 && _RES > 0) || (_T1 > 0 && _T2 < 0 && _RES < 0)); \
63-
_PF = (__builtin_parity((unsigned)_RES) == 0); \
63+
_PF = (__builtin_parity((unsigned char)_RES) == 0); \
6464
_AF = (((_T1 ^ _T2 ^ _RES) & 0x10) != 0); \
6565
} while (0)
6666

6767
// MUL instruction
6868
#define MUL(destination, source) do { \
69-
_Static_assert(__builtin_types_compatible_p(__typeof__(destination), __typeof__(source)) || \
69+
_Static_assert( \
7070
__builtin_types_compatible_p(__typeof__(destination), __typeof__(source)) || \
7171
IS_INTEGER_LITERAL(source), \
7272
"destination and source must be the same type or source must be an integer literal"); \
@@ -79,13 +79,13 @@
7979
_SF = (_RES < 0); \
8080
_CF = (_T1 != 0 && _RES / _T1 != _T2); \
8181
_OF = (_T1 != 0 && _RES / _T1 != _T2); \
82-
_PF = (__builtin_parity((unsigned)_RES) == 0); \
82+
_PF = (__builtin_parity((unsigned char)_RES) == 0); \
8383
_AF = (((_T1 ^ _T2 ^ _RES) & 0x10) != 0); \
8484
} while (0)
8585

8686
// DIV instruction
8787
#define DIV(destination, source) do { \
88-
_Static_assert(__builtin_types_compatible_p(__typeof__(destination), __typeof__(source)) || \
88+
_Static_assert( \
8989
__builtin_types_compatible_p(__typeof__(destination), __typeof__(source)) || \
9090
IS_INTEGER_LITERAL(source), \
9191
"destination and source must be the same type or source must be an integer literal"); \
@@ -98,13 +98,13 @@
9898
_SF = (_RES < 0); \
9999
_CF = 0; \
100100
_OF = 0; \
101-
_PF = (__builtin_parity((unsigned)_RES) == 0); \
101+
_PF = (__builtin_parity((unsigned char)_RES) == 0); \
102102
_AF = 0; \
103103
} while (0)
104104

105105
// MOD instruction
106106
#define MOD(destination, source) do { \
107-
_Static_assert(__builtin_types_compatible_p(__typeof__(destination), __typeof__(source)) || \
107+
_Static_assert( \
108108
__builtin_types_compatible_p(__typeof__(destination), __typeof__(source)) || \
109109
IS_INTEGER_LITERAL(source), \
110110
"destination and source must be the same type or source must be an integer literal"); \
@@ -117,7 +117,7 @@
117117
_SF = (_RES < 0); \
118118
_CF = 0; \
119119
_OF = 0; \
120-
_PF = (__builtin_parity((unsigned)_RES) == 0); \
120+
_PF = (__builtin_parity((unsigned char)_RES) == 0); \
121121
_AF = 0; \
122122
} while(0)
123123

@@ -131,7 +131,7 @@
131131
_SF = (_RES < 0); \
132132
_CF = (_T != 0); \
133133
_OF = (_T == ((__typeof__(_T))1 << (sizeof(_T)*8 - 1))); \
134-
_PF = (__builtin_parity((unsigned)_RES) == 0); \
134+
_PF = (__builtin_parity((unsigned char)_RES) == 0); \
135135
_AF = ((_T ^ _RES) & 0x10) != 0; \
136136
} while (0)
137137

@@ -145,7 +145,7 @@
145145
_SF = (_RES < 0); \
146146
_CF = (_T < 0); \
147147
_OF = (_T == ((__typeof__(_T))1 << (sizeof(_T)*8 - 1))); \
148-
_PF = (__builtin_parity((unsigned)_RES) == 0); \
148+
_PF = (__builtin_parity((unsigned char)_RES) == 0); \
149149
_AF = ((_T ^ _RES) & 0x10) != 0; \
150150
} while (0)
151151

@@ -158,7 +158,7 @@
158158
_ZF = (_RES == 0); \
159159
_SF = (_RES < 0); \
160160
_OF = (_T == ((__typeof__(_T))1 << (sizeof(_T)*8 - 1))); \
161-
_PF = (__builtin_parity((unsigned)_RES) == 0); \
161+
_PF = (__builtin_parity((unsigned char)_RES) == 0); \
162162
_AF = (((_T ^ 1 ^ _RES) & 0x10) != 0); \
163163
} while (0)
164164

@@ -171,7 +171,7 @@
171171
_ZF = (_RES == 0); \
172172
_SF = (_RES < 0); \
173173
_OF = (_T == ((__typeof__(_T))1 << (sizeof(_T)*8 - 1))); \
174-
_PF = (__builtin_parity((unsigned)_RES) == 0); \
174+
_PF = (__builtin_parity((unsigned char)_RES) == 0); \
175175
_AF = (((_T ^ 1 ^ _RES) & 0x10) != 0); \
176176
} while (0)
177177

0 commit comments

Comments
 (0)