Skip to content

Commit

Permalink
Fix the cas primitive in riscv and loongarch backend to allow for o…
Browse files Browse the repository at this point in the history
…ffset value bigger than 12 bits.
  • Loading branch information
maoif committed Nov 18, 2023
1 parent 398a05b commit 826ea18
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 14 deletions.
21 changes: 14 additions & 7 deletions s/loongarch64.ss
Original file line number Diff line number Diff line change
Expand Up @@ -540,12 +540,19 @@
(with-output-language (L15d Effect)
(define add-offset
(lambda (r)
(if (eqv? (nanopass-case (L15d Triv) w [(immediate ,imm) imm]) 0)
(k r)
(let ([u (make-tmp 'u)])
(seq
`(set! ,(make-live-info) ,u (asm ,null-info ,asm-add ,r ,w))
(k u))))))
(nanopass-case (L15d Triv) w
[(immediate ,imm)
(if (eqv? imm 0)
(k r)
(let ([u (make-tmp 'u)])
(seq
`(set! ,(make-live-info) ,u (asm ,null-info ,asm-add ,r ,w))
(k u))))]
[else
(let ([u (make-tmp 'u)])
(seq
`(set! ,(make-live-info) ,u (asm ,null-info ,asm-add ,r ,w))
(k u)))])))
(if (eq? y %zero)
(add-offset x)
(let ([u (make-tmp 'u)])
Expand All @@ -570,7 +577,7 @@
`(asm ,info ,(asm-lock+/- op) ,r)))])

(define-instruction effect (cas)
[(op (x ur) (y ur) (w imm12) (old ur) (new ur))
[(op (x ur) (y ur) (w imm12 ur) (old ur) (new ur))
(lea->reg x y w
(lambda (r)
`(asm ,info ,asm-cas ,r ,old ,new)))])
Expand Down
21 changes: 14 additions & 7 deletions s/riscv64.ss
Original file line number Diff line number Diff line change
Expand Up @@ -527,12 +527,19 @@
(with-output-language (L15d Effect)
(define add-offset
(lambda (r)
(if (eqv? (nanopass-case (L15d Triv) w [(immediate ,imm) imm]) 0)
(k r)
(let ([u (make-tmp 'u)])
(seq
`(set! ,(make-live-info) ,u (asm ,null-info ,asm-add ,r ,w))
(k u))))))
(nanopass-case (L15d Triv) w
[(immediate ,imm)
(if (eqv? imm 0)
(k r)
(let ([u (make-tmp 'u)])
(seq
`(set! ,(make-live-info) ,u (asm ,null-info ,asm-add ,r ,w))
(k u))))]
[else
(let ([u (make-tmp 'u)])
(seq
`(set! ,(make-live-info) ,u (asm ,null-info ,asm-add ,r ,w))
(k u)))])))
(if (eq? y %zero)
(add-offset x)
(let ([u (make-tmp 'u)])
Expand Down Expand Up @@ -563,7 +570,7 @@
`(asm ,null-info ,(asm-lock+/- op) ,r ,u1 ,u2)))))])

(define-instruction effect (cas)
[(op (x ur) (y ur) (w imm12) (old ur) (new ur))
[(op (x ur) (y ur) (w imm12 ur) (old ur) (new ur))
(lea->reg x y w
(lambda (r)
(let ([u1 (make-tmp 'u1)] [u2 (make-tmp 'u2)])
Expand Down

0 comments on commit 826ea18

Please sign in to comment.