Skip to content

Commit

Permalink
wip
Browse files Browse the repository at this point in the history
  • Loading branch information
ghostway0 committed Sep 9, 2024
1 parent ee538a0 commit b4c2cc0
Show file tree
Hide file tree
Showing 2 changed files with 52 additions and 0 deletions.
1 change: 1 addition & 0 deletions cranelift/codegen/src/isa/s390x/inst.isle
Original file line number Diff line number Diff line change
Expand Up @@ -3371,6 +3371,7 @@
(bool producer (invert_cond cond)))

;; Use a boolean condition to select between two registers.
; important
(decl select_bool_reg (Type ProducesBool Reg Reg) Reg)
(rule (select_bool_reg ty (ProducesBool.ProducesBool producer cond) reg_true reg_false)
(with_flags_reg producer (cmov_reg_reg ty cond reg_true reg_false)))
Expand Down
51 changes: 51 additions & 0 deletions cranelift/codegen/src/isa/s390x/lower.isle
Original file line number Diff line number Diff line change
Expand Up @@ -3844,6 +3844,57 @@
(add_logical_mem_zext32_with_flags_paired ty y (sink_uload32 x))
(trap_if_impl (mask_as_cond 3) tc)))

;;;; Rules for `uadd_overflow` ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

; options:
; 1. add BO (branch on overflow) to the backend
; 2. find how I can get and use the flags from a ProducesFlags instruction

(rule 0 (lower (has_type (fits_in_64 ty) (uadd_overflow x y)))
(let ((one Reg (imm $I8 1))
(overflow Reg (select_bool_reg ty (bool (add_logical_reg_with_flags_paired ty x y) (mask_as_cond 3)) one (zero_reg))))
(value_reg overflow)))

(rule 4 (lower (has_type (fits_in_64 ty) (uadd_overflow x (zext32_value y))))
(let ((one Reg (imm $I8 1))
(overflow Reg (select_bool_reg ty (bool (add_logical_reg_zext32_with_flags_paired ty x y) (mask_as_cond 3)) one (zero_reg))))
(value_reg overflow)))

(rule 8 (lower (has_type (fits_in_64 ty) (uadd_overflow (zext32_value x) y)))
(let ((one Reg (imm $I8 1))
(overflow Reg (select_bool_reg ty (bool (add_logical_reg_zext32_with_flags_paired ty y x) (mask_as_cond 3)) one (zero_reg))))
(value_reg overflow)))

(rule 3 (lower (has_type (fits_in_64 ty) (uadd_overflow x (u32_from_value y))))
(let ((one Reg (imm $I8 1))
(overflow Reg (select_bool_reg ty (bool (add_logical_zimm32_with_flags_paired ty x y) (mask_as_cond 3)) one (zero_reg))))
(value_reg overflow)))

(rule 7 (lower (has_type (fits_in_64 ty) (uadd_overflow (u32_from_value x) y)))
(let ((one Reg (imm $I8 1))
(overflow Reg (select_bool_reg ty (bool (add_logical_zimm32_with_flags_paired ty y x) (mask_as_cond 3)) one (zero_reg))))
(value_reg overflow)))

(rule 2 (lower (has_type (fits_in_64 ty) (uadd_overflow x (sinkable_load_32_64 y))))
(let ((one Reg (imm $I8 1))
(overflow Reg (select_bool_reg ty (bool (add_logical_mem_with_flags_paired ty x (sink_load y)) (mask_as_cond 3)) one (zero_reg))))
(value_reg overflow)))

(rule 6 (lower (has_type (fits_in_64 ty) (uadd_overflow (sinkable_load_32_64 x) y)))
(let ((one Reg (imm $I8 1))
(overflow Reg (select_bool_reg ty (bool (add_logical_mem_with_flags_paired ty y (sink_load x)) (mask_as_cond 3)) one (zero_reg))))
(value_reg overflow)))

(rule 1 (lower (has_type (fits_in_64 ty) (uadd_overflow x (sinkable_uload32 y))))
(let ((one Reg (imm $I8 1))
(overflow Reg (select_bool_reg ty (bool (add_logical_mem_zext32_with_flags_paired ty x (sink_uload32 y)) (mask_as_cond 3)) one (zero_reg))))
(value_reg overflow)))

(rule 5 (lower (has_type (fits_in_64 ty) (uadd_overflow (sinkable_uload32 x) y)))
(let ((one Reg (imm $I8 1))
(overflow Reg (select_bool_reg ty (bool (add_logical_mem_zext32_with_flags_paired ty y (sink_uload32 x)) (mask_as_cond 3)) one (zero_reg))))
(value_reg overflow)))

;;;; Rules for `return` ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

(rule (lower (return args))
Expand Down

0 comments on commit b4c2cc0

Please sign in to comment.