boot2

Playing with the boostrap
git clone https://git.ryansepassi.com/git/boot2.git
Log | Files | Refs | README

083-signed-shr-by-unsigned.scm (1002B)


      1 ;; tests/cc-cg/83-signed-shr-by-unsigned.scm — `int x = -16; x >> 1u`
      2 ;; must use arithmetic shift right (sar) per C 6.5.7: shifts use the
      3 ;; promoted left operand's signedness, not the result of the usual
      4 ;; arithmetic conversions.
      5 ;;
      6 ;; Models: `(int)(-16) >> (unsigned)1 == -8`.
      7 ;;
      8 ;; Replicates the corrected parse-binary sequence for shift operators
      9 ;; (no arith-conv): rval lhs; cg-promote; rval rhs; cg-promote;
     10 ;; cg-binop 'shr.
     11 ;;
     12 ;; cg-binop currently dispatched signed/unsigned shr off either operand
     13 ;; (`(or (unsigned? ta) (unsigned? tb))`), so a signed lhs with an
     14 ;; unsigned shift count incorrectly used logical shift right. Correct
     15 ;; cg keys signedness off the LEFT operand only (C 6.5.7).
     16 
     17 (let ((cg (cg-init)))
     18   (cg-fn-begin cg "main" '() %t-i32)
     19   (cg-push-imm cg %t-i32 -16)
     20   (cg-promote cg)
     21   (cg-push-imm cg %t-u32 1)
     22   (cg-promote cg)
     23   (cg-binop cg 'shr)
     24   (cg-push-imm cg %t-i32 -8)
     25   (cg-binop cg 'eq)
     26   (cg-return cg)
     27   (cg-fn-end cg)
     28   (write-bv-fd 1 (cg-finish cg)))