boot2

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

019-zext-narrow.scm (669B)


      1 ;; tests/cc-cg/19-zext-narrow.scm — unsigned narrowing zero-extends.
      2 ;;
      3 ;; Models: ((unsigned)(unsigned char)-3) == 253.
      4 ;; The narrowing cast to u8 must mask off the high bits (not sign-
      5 ;; extend), so the value 0xFFFFFFFD becomes 0xFD = 253. The
      6 ;; widening cast back to u32 is relabel-only and preserves it.
      7 ;; Locks in the contrast with §A.4: same source value, but the
      8 ;; unsigned target arrives at 253 not -3.
      9 
     10 (let ((cg (cg-init)))
     11   (cg-fn-begin cg "main" '() %t-i32)
     12   (cg-push-imm cg %t-i32 -3)
     13   (cg-cast cg %t-u8)
     14   (cg-cast cg %t-u32)
     15   (cg-push-imm cg %t-u32 253)
     16   (cg-binop cg 'eq)
     17   (cg-return cg)
     18   (cg-fn-end cg)
     19   (write-bv-fd 1 (cg-finish cg)))