boot2

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

016-short-roundtrip.scm (1246B)


      1 ;; tests/cc-cg/16-short-roundtrip.scm — width-correct 16-bit load/store
      2 ;; on adjacent unsigned-short lvals.
      3 ;;
      4 ;; Models:
      5 ;;   unsigned short a = 0xAABB, b = 0xCCDD;
      6 ;;   return a == 0xAABB;
      7 ;;
      8 ;; Two 2-byte slots are allocated back-to-back. If cg uses 8-byte
      9 ;; %ld/%st, the second store contaminates bytes 2..9 of the first
     10 ;; slot's neighborhood, so the 8-byte load of `a` yields 0xCCDDAABB
     11 ;; — which fails the equality test against 0xAABB. Width-aware
     12 ;; emission (byte-decomposed %sb store, %lb-gather load) yields
     13 ;; exactly 0xAABB, the comparison is true, and exit is 1.
     14 
     15 (let ((cg (cg-init)))
     16   (cg-fn-begin cg "main" '() %t-i32)
     17   (let* ((off-a (cg-alloc-slot cg 2 2))
     18          (off-b (cg-alloc-slot cg 2 2))
     19          (sym-a (%sym "a" 'var 'auto %t-u16 off-a))
     20          (sym-b (%sym "b" 'var 'auto %t-u16 off-b)))
     21     ;; a = 0xAABB
     22     (cg-push-sym cg sym-a)
     23     (cg-push-imm cg %t-u16 43707)
     24     (cg-assign cg) (cg-pop cg)
     25     ;; b = 0xCCDD
     26     (cg-push-sym cg sym-b)
     27     (cg-push-imm cg %t-u16 52445)
     28     (cg-assign cg) (cg-pop cg)
     29     ;; return a == 0xAABB
     30     (cg-push-sym cg sym-a)
     31     (cg-load cg)
     32     (cg-push-imm cg %t-u16 43707)
     33     (cg-binop cg 'eq)
     34     (cg-return cg))
     35   (cg-fn-end cg)
     36   (write-bv-fd 1 (cg-finish cg)))