I.e. implement < > <= >= == !=. Comparisons are signed and result is -1 if true, 0 if false.
Unified · Split
| @@ -259,9 +259,51 @@ static inline void asm_expr_sum(TCCState *s1, ExprValue *pe) · 258 unmodified lines | |||
| 259 | } | 259 | } |
| 260 | } | 260 | } |
| 261 | 261 | ||
| 262 | ST_FUNC void asm_expr(TCCState *s1, ExprValue *pe) | 262 | static inline void asm_expr_cmp(TCCState *s1, ExprValue *pe) |
| 263 | { | 263 | { |
| 264 | int op; | ||
| 265 | ExprValue e2; | ||
| 266 | |||
| 264 | asm_expr_sum(s1, pe); | 267 | asm_expr_sum(s1, pe); |
| 268 | for(;;) { | ||
| 269 | op = tok; | ||
| 270 | if (op != TOK_EQ && op != TOK_NE | ||
| 271 | && (op > TOK_GT || op < TOK_ULE)) | ||
| 272 | break; | ||
| 273 | next(); | ||
| 274 | asm_expr_sum(s1, &e2); | ||
| 275 | if (pe->sym || e2.sym) | ||
| 276 | tcc_error("invalid operation with label"); | ||
| 277 | switch(op) { | ||
| 278 | case TOK_EQ: | ||
| 279 | pe->v = pe->v == e2.v; | ||
| 280 | break; | ||
| 281 | case TOK_NE: | ||
| 282 | pe->v = pe->v != e2.v; | ||
| 283 | break; | ||
| 284 | case TOK_LT: | ||
| 285 | pe->v = (int64_t)pe->v < (int64_t)e2.v; | ||
| 286 | break; | ||
| 287 | case TOK_GE: | ||
| 288 | pe->v = (int64_t)pe->v >= (int64_t)e2.v; | ||
| 289 | break; | ||
| 290 | case TOK_LE: | ||
| 291 | pe->v = (int64_t)pe->v <= (int64_t)e2.v; | ||
| 292 | break; | ||
| 293 | case TOK_GT: | ||
| 294 | pe->v = (int64_t)pe->v > (int64_t)e2.v; | ||
| 295 | break; | ||
| 296 | default: | ||
| 297 | break; | ||
| 298 | } | ||
| 299 | /* GAS compare results are -1/0 not 1/0. */ | ||
| 300 | pe->v = -(int64_t)pe->v; | ||
| 301 | } | ||
| 302 | } | ||
| 303 | |||
| 304 | ST_FUNC void asm_expr(TCCState *s1, ExprValue *pe) | ||
| 305 | { | ||
| 306 | asm_expr_cmp(s1, pe); | ||
| 265 | } | 307 | } |
| 266 | 308 | ||
| 267 | ST_FUNC int asm_int_expr(TCCState *s1) | 309 | ST_FUNC int asm_int_expr(TCCState *s1) |
| @@ -391,6 +433,8 @@ static void asm_parse_directive(TCCState *s1) · 123 unmodified lines | |||
| 391 | if (sec->sh_addralign < n) | 433 | if (sec->sh_addralign < n) |
| 392 | sec->sh_addralign = n; | 434 | sec->sh_addralign = n; |
| 393 | } else { | 435 | } else { |
| 436 | if (n < 0) | ||
| 437 | n = 0; | ||
| 394 | size = n; | 438 | size = n; |
| 395 | } | 439 | } |
| 396 | v = 0; | 440 | v = 0; |
| @@ -740,6 +740,12 @@ nop · 739 unmodified lines | |||
| 740 | .word 164, 0 | 740 | .word 164, 0 |
| 741 | .org 2b+32 | 741 | .org 2b+32 |
| 742 | .quad 1b | 742 | .quad 1b |
| 743 | .popsection | ||
| 744 | 3: mov %eax,%ecx | ||
| 745 | 4: | ||
| 746 | .pushsection .text.three, "ax" | ||
| 747 | nop | ||
| 748 | .skip (-((4b-3b) > 0) * 2) , 0x90 | ||
| 743 | .popsection | 749 | .popsection |
| 744 | 750 | ||
| 745 | movd %esi, %mm1 | 751 | movd %esi, %mm1 |