mescc: Use signed integer comparison.

* module/language/c99/compiler.mes (test->jump->info):
* module/mes/as-i386.mes (i386:Xjump-le, i386:Xjump-g, i386:Xjump-l,
  i386:Xjump-ge): New functions.
* module/mes/as-i386.scm: Export them.
* scaffold/t.c (math_test): Test them.
* tests/scm.test ("iota -1"): Enable for mesc.
This commit is contained in:
Jan Nieuwenhuizen 2017-03-24 21:45:19 +01:00
parent 66b53669f8
commit ce55c198c0
6 changed files with 78 additions and 23 deletions

View file

@ -1079,10 +1079,17 @@
(jump-text body-length)))))))
(lambda (o)
(pmatch o
((le ,a ,b) ((jump i386:Xjump-ncz) o))
((lt ,a ,b) ((jump i386:Xjump-nc) o))
((ge ,a ,b) ((jump i386:Xjump-ncz) o))
((gt ,a ,b) ((jump i386:Xjump-nc) o))
;; unsigned
;; ((le ,a ,b) ((jump i386:Xjump-ncz) o)) ; ja
;; ((lt ,a ,b) ((jump i386:Xjump-nc) o)) ; jae
;; ((ge ,a ,b) ((jump i386:Xjump-ncz) o))
;; ((gt ,a ,b) ((jump i386:Xjump-nc) o))
((le ,a ,b) ((jump i386:Xjump-g) o))
((lt ,a ,b) ((jump i386:Xjump-ge) o))
((ge ,a ,b) ((jump i386:Xjump-g) o))
((gt ,a ,b) ((jump i386:Xjump-ge) o))
((ne ,a ,b) ((jump i386:Xjump-nz) o))
((eq ,a ,b) ((jump i386:Xjump-nz) o))
((not _) ((jump i386:Xjump-z) o))

View file

@ -342,10 +342,6 @@
barf)
`(#x72 ,(if (>= n 0) n (- n 2)))) ; jc <n>
(define (i386:Xjump-c n)
(or n urg:Xjump-c)
`(#x0f #x82 ,@(int->bv32 n))) ; jc <n>
(define (i386:jump-cz n)
(when (or (> n #x80) (< n #x-80))
(format (current-error-port) "JUMP n=~a\n" n)
@ -364,18 +360,46 @@
barf)
`(#x73 ,(if (>= n 0) n (- n 2)))) ; jnc <n>
;; unsigned
(define (i386:Xjump-nc n)
(or n urg:Xjump-nc)
`(#x0f #x83 ,@(int->bv32 n))) ; jnc <n>
(define (i386:Xjump-cz n)
(or n urg:Xjump-cz)
`(#x0f #x86 ,@(int->bv32 n))) ; jbe <n>
;; unsigned
(define (i386:Xjump-ncz n)
(or n urg:Xjump-ncz)
`(#x0f #x87 ,@(int->bv32 n))) ; ja <n>
;; unsigned
;; (define (i386:Xjump-c n)
;; (or n urg:Xjump-c)
;; `(#x0f #x82 ,@(int->bv32 n))) ; jc <n>
;; unsigned
;; (define (i386:Xjump-cz n)
;; (or n urg:Xjump-cz)
;; `(#x0f #x86 ,@(int->bv32 n))) ; jbe <n>
;; signed
(define (i386:Xjump-g n)
(or n urg:Xjump-g)
`(#x0f #x8f ,@(int->bv32 n))) ; jg/jnle <n>
;; signed
(define (i386:Xjump-ge n)
(or n urg:Xjump-ge)
`(#x0f #x8d ,@(int->bv32 n))) ; jge/jnl <n>
;; ;; signed
;; (define (i386:Xjump-l n)
;; (or n urg:Xjump-l)
;; `(#x0f #x8c ,@(int->bv32 n))) ; jl/jnge <n>
;; ;; signed
;; (define (i386:Xjump-le n)
;; (or n urg:Xjump-le)
;; `(#x0f #x8e ,@(int->bv32 n))) ; jle/jgn <n>
(define (i386:jump-z n)
(when (or (> n #x80) (< n #x-80))
(format (current-error-port) "JUMP-z n=~a\n" n)

View file

@ -120,14 +120,20 @@
;; long jump
i386:Xjump
i386:Xjump
i386:Xjump-c
i386:Xjump-cz
;;i386:Xjump-c
;;i386:Xjump-cz
i386:Xjump-nc
i386:Xjump-ncz
i386:Xjump-nz
i386:Xjump-z
i386:Xjump-g
i386:Xjump-ge
;; i386:Xjump-l
;; i386:Xjump-le
i386:XXjump
i386:accu+n

View file

@ -1368,11 +1368,6 @@ less_p (SCM x) ///((name . "<") (arity . n))
while (x != cell_nil)
{
assert (TYPE (car (x)) == TNUMBER);
#if __MESC__
//FIXME __GNUC__
if (n == INT_MIN);
else
#endif
if (VALUE (car (x)) <= n) return cell_f;
n = VALUE (car (x));
x = cdr (x);

View file

@ -177,6 +177,30 @@ read_test ()
int
math_test ()
{
puts ("t: 0 < 0\n");
if (0 < 0) return 1;
puts ("t: 2 < 1\n");
if (2 < 1) return 1;
puts ("t: -1 < -2\n");
if (-1 < -2) return 1;
puts ("t: 0 < -1\n");
if (0 < -1) return 1;
puts ("t: 0 > 0\n");
if (0 > 0) return 1;
puts ("t: 1 > 2\n");
if (1 > 2) return 1;
puts ("t: -2 > -1\n");
if (-2 > -1) return 1;
puts ("t: -1 > 0\n");
if (-1 > 0) return 1;
int i;
puts ("t: 4/2=");
i = 4 / 2;

View file

@ -122,9 +122,8 @@ exit $?
(pass-if-equal "iota 0"
'() (iota 0))
(if %mesc (display "***FIXME: MESCC skip iota -1")
(pass-if-equal "iota -1"
'() (iota -1)))
(pass-if-equal "iota -1"
'() (iota -1))
(pass-if "reverse" (sequal? (reverse '(1 2 3)) '(3 2 1)))