mescc: Lshift support non-fixed shift value.

* module/mes/as-i386.mes (i386:accu<<base): New function.
* module/mes/as-i386.scm: Export it.
* module/language/c99/compiler.mes (expr->accu): Use it.
* scaffold/t.c (math_test): Test it.
This commit is contained in:
Jan Nieuwenhuizen 2017-03-24 22:32:02 +01:00
parent ce55c198c0
commit ca633abdda
4 changed files with 28 additions and 3 deletions

View file

@ -761,15 +761,27 @@
(list (lambda (f g ta t d) (list (lambda (f g ta t d)
(i386:accu-base))))))) (i386:accu-base)))))))
((lshift ,a (p-expr (fixed ,value))) ((bitwise-or ,a ,b)
(let* ((empty (clone info #:text '())) (let* ((empty (clone info #:text '()))
(accu ((expr->accu empty) a)) (accu ((expr->accu empty) a))
(value (cstring->number value))) (base ((expr->base empty) b)))
(clone info #:text (clone info #:text
(append text (append text
(.text accu) (.text accu)
(.text base)
(list (lambda (f g ta t d) (list (lambda (f g ta t d)
(i386:accu-shl value))))))) (i386:accu-or-base)))))))
((lshift ,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) ((div ,a ,b)
(let* ((empty (clone info #:text '())) (let* ((empty (clone info #:text '()))

View file

@ -126,6 +126,11 @@
(or n accu:shl n) (or n accu:shl n)
`(#xc1 #xe0 ,n)) ; shl $0x8,%eax `(#xc1 #xe0 ,n)) ; shl $0x8,%eax
(define (i386:accu<<base)
'(#x31 #xc9 ; xor %ecx,%ecx
#x89 #xd1 ; mov %edx,%ecx
#xd3 #xe0)) ; shl %cl,%eax
(define (i386:accu+accu) (define (i386:accu+accu)
'(#x01 #xc0)) ; add %eax,%eax '(#x01 #xc0)) ; add %eax,%eax

View file

@ -46,6 +46,7 @@
i386:accu*base i386:accu*base
i386:accu-base i386:accu-base
i386:accu-shl i386:accu-shl
i386:accu<<base
i386:base-sub i386:base-sub
i386:base->accu i386:base->accu
i386:base->accu-address i386:base->accu-address

View file

@ -212,6 +212,13 @@ math_test ()
puts ("t: 3*4="); puts ("t: 3*4=");
i = 3 * 4; i = 3 * 4;
if (i!=12) return 1; if (i!=12) return 1;
puts ("t: 1 << 3\n");
if (1 << 3 != 8) return 1 << 3;
puts ("t: 3 << 4\n");
if (3 << 4 != 48) return 3 << 4;
return read_test (); return read_test ();
} }