mescc: Support rshift, have guile-mini-mes pass math test.

* module/mes/as-i386.mes (i386:accu>>base): New function.
* module/mes/as-i386.scm (mes): Export it.
* module/language/c99/compiler.mes (expr->accu): Support rshift.
* scaffold/t.c (math_test): Test it.
* scaffold/mini-mes.c (ash): Use it.
This commit is contained in:
Jan Nieuwenhuizen 2017-03-25 18:48:40 +01:00
parent 701169764c
commit c39c04cb56
5 changed files with 41 additions and 3 deletions

View file

@ -783,6 +783,17 @@
(list (lambda (f g ta t d)
(i386:accu<<base)))))))
((rshift ,a ,b)
(let* ((empty (clone info #:text '()))
(accu ((expr->accu empty) a))
(base ((expr->base empty) b)))
(clone info #:text
(append text
(.text accu)
(.text base)
(list (lambda (f g ta t d)
(i386:accu>>base)))))))
((div ,a ,b)
(let* ((empty (clone info #:text '()))
(accu ((expr->accu empty) a))
@ -1730,6 +1741,10 @@
(list (lambda (f g ta t d)
(i386:base-sub)))))))
;; HMM
((lshift . _) ((expr->accu info) o))
((rshift . _) ((expr->accu info) o))
;; TODO: byte dinges
((Xsub ,a ,b)
(let* ((base ((expr->base info) a))

View file

@ -131,6 +131,11 @@
#x89 #xd1 ; mov %edx,%ecx
#xd3 #xe0)) ; shl %cl,%eax
(define (i386:accu>>base)
'(#x31 #xc9 ; xor %ecx,%ecx
#x89 #xd1 ; mov %edx,%ecx
#xd3 #xe8)) ; shr %cl,%eax
(define (i386:accu-or-base)
'(#x09 #xd0)) ; or %edx,%eax

View file

@ -48,6 +48,7 @@
i386:accu-shl
i386:accu-or-base
i386:accu<<base
i386:accu>>base
i386:base-sub
i386:base->accu
i386:base->accu-address

View file

@ -1278,9 +1278,10 @@ ash (SCM n, SCM count)
#if __GNUC__
return MAKE_NUMBER ((ccount < 0) ? cn >> -ccount : cn << ccount);
#else
//FIXME
assert (ccount >= 0);
return MAKE_NUMBER (cn << ccount);
int x;
if (ccount < 0) x = cn >> INT_MIN - ccount;
else x = cn << ccount;
return MAKE_NUMBER (x);
#endif
}

View file

@ -219,9 +219,22 @@ math_test ()
puts ("t: 3 << 4\n");
if (3 << 4 != 48) return 3 << 4;
puts ("t: 48 >> 3\n");
if (48 >> 4 != 3) return 48 >> 4;
puts ("t: 10 >> 1\n");
if (10 >> 1 != 5) return 10 >> 1;
puts ("t: 1 | 4\n");
if ((1 | 4) != 5) return 1 | 4;
i = -3;
puts ("t: -i\n");
if (-i != 3) return -i;
puts ("t: -1 + 2\n");
if (-1 + 2 != 1) return -1 + 2;
return read_test ();
}
@ -566,6 +579,9 @@ test (char *p)
puts ("t: 1 << 3\n");
if (1 << 3 != 8) return 1;
puts ("t: 8 >> 3\n");
if (8 >> 3 != 1) return 1;
puts ("t: 8 / 4\n");
if (8 / 4 != 2) return 1;