diff --git a/module/language/c99/compiler.mes b/module/language/c99/compiler.mes index 490e6c21..1bc6900c 100644 --- a/module/language/c99/compiler.mes +++ b/module/language/c99/compiler.mes @@ -689,6 +689,8 @@ ((add ,a ,b) ((binop->accu info) a b (i386:accu+base))) ((sub ,a ,b) ((binop->accu info) a b (i386:accu-base))) ((bitwise-or ,a ,b) ((binop->accu info) a b (i386:accu-or-base))) + ((bitwise-and ,a ,b) ((binop->accu info) a b (i386:accu-and-base))) + ((bitwise-xor ,a ,b) ((binop->accu info) a b (i386:accu-xor-base))) ((lshift ,a ,b) ((binop->accu info) a b (i386:accu<accu info) a b (i386:accu>>base))) ((div ,a ,b) ((binop->accu info) a b (i386:accu/base))) @@ -718,6 +720,30 @@ ((le ,a ,b) ((binop->accu info) b a (i386:base-sub))) ((lt ,a ,b) ((binop->accu info) b a (i386:base-sub))) + ((or ,a ,b) + (let* ((empty (clone info #:text '())) + (b-length (length (append (i386:Xjump-nz 0) + (i386:accu-test)))) + (info ((expr->accu info) a)) + (info (append-text info (wrap-as (i386:accu-test)))) + (info (append-text info (wrap-as (append (i386:Xjump-nz (- b-length 1)) + (i386:accu-test))))) + (info ((expr->accu info) b)) + (info (append-text info (wrap-as (i386:accu-test))))) + info)) + + ((and ,a ,b) + (let* ((empty (clone info #:text '())) + (b-length (length (append (i386:Xjump-z 0) + (i386:accu-test)))) + (info ((expr->accu info) a)) + (info (append-text info (wrap-as (i386:accu-test)))) + (info (append-text info (wrap-as (append (i386:Xjump-z (- b-length 1)) + (i386:accu-test))))) + (info ((expr->accu info) b)) + (info (append-text info (wrap-as (i386:accu-test))))) + info)) + ((cast ,cast ,o) ((expr->accu info) o)) diff --git a/module/mes/as-i386.mes b/module/mes/as-i386.mes index c325729b..3ffa6448 100644 --- a/module/mes/as-i386.mes +++ b/module/mes/as-i386.mes @@ -155,6 +155,12 @@ (define (i386:accu-or-base) '(#x09 #xd0)) ; or %edx,%eax +(define (i386:accu-and-base) + '(#x21 #xd0)) ; and %edx,%eax + +(define (i386:accu-xor-base) + '(#x31 #xd0)) ; and %edx,%eax + (define (i386:accu+accu) '(#x01 #xc0)) ; add %eax,%eax diff --git a/module/mes/as-i386.scm b/module/mes/as-i386.scm index 330d9bb3..b5e1c8f8 100644 --- a/module/mes/as-i386.scm +++ b/module/mes/as-i386.scm @@ -46,7 +46,9 @@ i386:accu*base i386:accu-base i386:accu-shl + i386:accu-and-base i386:accu-or-base + i386:accu-xor-base i386:accu<>base i386:base-sub diff --git a/scaffold/t.c b/scaffold/t.c index d2b4861d..227efca1 100644 --- a/scaffold/t.c +++ b/scaffold/t.c @@ -332,6 +332,15 @@ math_test () puts ("t: -1 + 2\n"); if (-1 + 2 != 1) return 1; + puts ("t: 1 & 3\n"); + if ((1 & 3) != 1) return 1; + + puts ("t: 1 | 3\n"); + if ((1 | 2) != 3) return 1; + + puts ("t: ^ 1 \n"); + if ((1 ^ 3) != 2) return 1; + return array_test (env); }