boot2

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

19-zext-narrow.scm (704B)


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