From 042022419e6d3b092e673d41598677bacbe4c9f9 Mon Sep 17 00:00:00 2001 From: Jan Nieuwenhuizen Date: Sat, 29 Jul 2017 20:46:16 +0200 Subject: [PATCH] mescc: Tinycc support: fix accu value after comparison. * stage0/x86.M1 (setg___%al,, setge__%al, setl___%al, setle__%al): New defines. * module/mes/as-i386.mes (i386:g?->accu, i386:ge?->accu, i386:l?->accu, i386:le?->accu, i386:jumpl, i386:jumple): New functions. * module/mes/as-i386.scm: Export them. * module/language/c99/compiler.mes (expr->accu): Use them to fix accu value after comparisons. (test-jump-label->info): Update comparison jumps. --- module/language/c99/compiler.mes | 12 ++--- module/mes/as-i386.mes | 30 +++++++++-- module/mes/as-i386.scm | 6 +++ scaffold/tests/32-compare.c | 89 ++++++++++++++++++++++++++++++++ stage0/x86.M1 | 8 ++- 5 files changed, 135 insertions(+), 10 deletions(-) diff --git a/module/language/c99/compiler.mes b/module/language/c99/compiler.mes index 62676522..2ce87ae4 100644 --- a/module/language/c99/compiler.mes +++ b/module/language/c99/compiler.mes @@ -851,8 +851,8 @@ (wrap-as (i386:sub-base)))))) ((eq ,a ,b) ((binop->accu info) a b (append (i386:sub-base) (i386:z->accu)))) - ((ge ,a ,b) ((binop->accu info) b a (i386:sub-base))) - ((gt ,a ,b) ((binop->accu info) b a (i386:sub-base))) + ((ge ,a ,b) ((binop->accu info) a b (append (i386:sub-base) (i386:ge?->accu)))) + ((gt ,a ,b) ((binop->accu info) a b (append (i386:sub-base) (i386:g?->accu) (i386:accu-test)))) ;; FIXME: set accu *and* flags ((ne ,a ,b) ((binop->accu info) a b (append (i386:push-accu) @@ -864,8 +864,8 @@ (i386:pop-accu)))) ((ne ,a ,b) ((binop->accu info) a b (append (i386:sub-base) (i386:xor-zf)))) - ((le ,a ,b) ((binop->accu info) b a (i386:base-sub))) - ((lt ,a ,b) ((binop->accu info) b a (i386:base-sub))) + ((le ,a ,b) ((binop->accu info) a b (append (i386:sub-base) (i386:le?->accu)))) + ((lt ,a ,b) ((binop->accu info) a b (append (i386:sub-base) (i386:l?->accu)))) ((or ,a ,b) (let* ((info ((expr->accu info) a)) @@ -1426,8 +1426,8 @@ ((le ,a ,b) ((jump i386:jump-g) o)) ((lt ,a ,b) ((jump i386:jump-ge) o)) - ((ge ,a ,b) ((jump i386:jump-g) o)) - ((gt ,a ,b) ((jump i386:jump-ge) o)) + ((ge ,a ,b) ((jump i386:jump-l) o)) + ((gt ,a ,b) ((jump i386:jump-le) o)) ((ne ,a ,b) ((jump i386:jump-nz) o)) ((eq ,a ,b) ((jump i386:jump-nz) o)) diff --git a/module/mes/as-i386.mes b/module/mes/as-i386.mes index a683c62b..38a61980 100644 --- a/module/mes/as-i386.mes +++ b/module/mes/as-i386.mes @@ -210,9 +210,6 @@ (define (i386:accu->label label) `(("mov____%eax,0x32" (#:address ,label)))) ; mov %eax,0x