Home My Page Projects Code Snippets Project Openings SML/NJ
 Summary Activity Forums Tracker Lists Tasks Docs Surveys News SCM Files

# SCM Repository

[smlnj] Diff of /sml/branches/primop-branch-2/src/compiler/FLINT/trans/translate.sml
 [smlnj] / sml / branches / primop-branch-2 / src / compiler / FLINT / trans / translate.sml

# Diff of /sml/branches/primop-branch-2/src/compiler/FLINT/trans/translate.sml

revision 1178, Mon Mar 25 20:51:48 2002 UTC revision 1180, Tue Mar 26 22:24:24 2002 UTC
# Line 448  Line 448
448  fun cmpOp p = PRIM(p, lt_icmp, [])  fun cmpOp p = PRIM(p, lt_icmp, [])
449  fun inegOp p = PRIM(p, lt_ineg, [])  fun inegOp p = PRIM(p, lt_ineg, [])
450
fun SUB(b,c) = APP(intOp(PO.ISUB), RECORD[b, c])
fun MUL(b,c) = APP(intOp(PO.IMUL), RECORD[b, c])
451  fun DIV(b,c) = APP(intOp(PO.IDIV), RECORD[b, c])  fun DIV(b,c) = APP(intOp(PO.IDIV), RECORD[b, c])
452  val LESSU = PO.CMP{oper=PO.LTU, kind=PO.UINT 31}  val LESSU = PO.CMP{oper=PO.LTU, kind=PO.UINT 31}
453
454    (* pure arith on int31 (guaranteed to not overflow) *)
455    val pIADD = PO.ARITH { oper=PO.+, overflow = false, kind = PO.INT 31 }
456    val pISUB = PO.ARITH { oper=PO.-, overflow = false, kind = PO.INT 31 }
457    val pIMUL = PO.ARITH { oper=PO.*, overflow = false, kind = PO.INT 31 }
459    fun pSUB(b,c) = APP(intOp pISUB, RECORD [b, c])
460    fun pMUL(b,c) = APP(intOp pIMUL, RECORD [b, c])
461
462    fun CMP (cop, e1, e2) = APP (cmpOp cop, RECORD [e1, e2])
463    fun EQ (e1, e2) = CMP (PO.IEQL, e1, e2)
464    fun NONNEG e = CMP (PO.IGE, e, INT 0)
465    fun ISZERO e = EQ (e, INT 0)
466
467  val lt_len = LT.ltc_poly([LT.tkc_mono], [lt_arw(LT.ltc_tv 0, lt_int)])  val lt_len = LT.ltc_poly([LT.tkc_mono], [lt_arw(LT.ltc_tv 0, lt_int)])
468  val lt_upd =  val lt_upd =
469    let val x = LT.ltc_ref (LT.ltc_tv 0)    let val x = LT.ltc_ref (LT.ltc_tv 0)
# Line 512  Line 522
522                end                end
523
524          | g (PO.INLDIV) =          | g (PO.INLDIV) =
525              (* This should give a slightly faster path through this
526               * operation for the frequent case that the result is non-negative.
527               * Some hardware calculates the remainder as part of the DIV
528               * operation -- in which case we could save the MUL step.
529               * This will have to be done in the backend because it is
530               * architecture-specific. *)
531              let val a = mkv () and b = mkv ()
532                  and q = mkv () and z = mkv ()
533              in
534                  FN (z, lt_ipair,
535                      LET (a, SELECT (0, VAR z),
536                           LET (b, SELECT (1, VAR z),
537                                LET (q, DIV (VAR a, VAR b),
538                                     COND (NONNEG (VAR q), VAR q,
539                                           COND (EQ (VAR a, pMUL (VAR q, VAR b)),
540                                                 VAR q,
541                                                 pSUB (VAR q, INT 1)))))))
542              end
543    (*
544                let val a = mkv() and b = mkv() and z = mkv()                let val a = mkv() and b = mkv() and z = mkv()
545                 in FN(z, lt_ipair,                 in FN(z, lt_ipair,
546                      LET(a, SELECT(0, VAR z),                      LET(a, SELECT(0, VAR z),
# Line 524  Line 553
553                                 SUB(DIV(SUB(VAR a, INT 1), VAR b), INT 1),                                 SUB(DIV(SUB(VAR a, INT 1), VAR b), INT 1),
554                                 DIV(VAR a, VAR b))))))                                 DIV(VAR a, VAR b))))))
555                end                end
556    *)
557          | g (PO.INLMOD) =          | g (PO.INLMOD) =
558              (* Same here: Fast path for q >= 0.  However, since the remainder
559               * is the intended result, we can't avoid the MUL.  On architectures
560               * where r is directly available, this should rather be done
561               * in the backend. *)
562              let val a = mkv () and b = mkv ()
563                  and q = mkv () and r = mkv ()
564                  and z = mkv ()
565              in
566                  FN (z, lt_ipair,
567                      LET (a, SELECT (0, VAR z),
568                           LET (b, SELECT (1, VAR z),
569                                LET (q, DIV (VAR a, VAR b),
570                                     LET (r, pSUB (VAR a, pMUL (VAR q, VAR b)),
571                                          COND (NONNEG (VAR q), VAR r,
572                                                COND (ISZERO (VAR r), VAR r,
573                                                      pADD (VAR r, VAR b))))))))
574              end
575    (*
576                let val a = mkv() and b = mkv() and z = mkv()                let val a = mkv() and b = mkv() and z = mkv()
577                 in FN(z, lt_ipair,                 in FN(z, lt_ipair,
578                      LET(a,SELECT(0, VAR z),                      LET(a,SELECT(0, VAR z),
# Line 548  Line 595
595                                      SUB(VAR a, MUL(DIV(VAR a, VAR b),                                      SUB(VAR a, MUL(DIV(VAR a, VAR b),
596                                                     VAR b))))))))                                                     VAR b))))))))
597                end                end
598    *)
599          | g (PO.INLREM) =          | g (PO.INLREM) =
600                let val a = mkv() and b = mkv() and z = mkv()                let val a = mkv() and b = mkv() and z = mkv()
601                 in FN(z, lt_ipair,                 in FN(z, lt_ipair,
602                      LET(a, SELECT(0,VAR z),                      LET(a, SELECT(0,VAR z),
603                        LET(b, SELECT(1,VAR z),                        LET(b, SELECT(1,VAR z),
604                            SUB(VAR a, MUL(DIV(VAR a,VAR b),VAR b)))))                            pSUB(VAR a, pMUL(DIV(VAR a,VAR b),VAR b)))))
605                end                end
606
607          | g (PO.INLMIN) =          | g (PO.INLMIN) =

Legend:
 Removed from v.1178 changed lines Added in v.1180