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

SCM Repository

[smlnj] Annotation of /sml/trunk/src/compiler/CodeGen/sparc/sparcPseudoInstrs.sml
ViewVC logotype

Annotation of /sml/trunk/src/compiler/CodeGen/sparc/sparcPseudoInstrs.sml

Parent Directory Parent Directory | Revision Log Revision Log


Revision 134 - (view) (download)

1 : monnier 134 functor SparcPseudoInstrs
2 :     (Instr : SPARCINSTR where Region=CPSRegions) : SPARC_PSEUDO_INSTR =
3 :     struct
4 :     structure I = Instr
5 :     structure C = Instr.C
6 :    
7 :     type reduceOpnd = I.operand -> int
8 :    
9 :     (* runtime system dependent *)
10 :     val floatTmpOffset = I.IMMED 88
11 :     val umulOffset = I.IMMED 80
12 :     val smulOffset = I.IMMED 72
13 :     val udivOffset = I.IMMED 84
14 :     val sdivOffset = I.IMMED 76
15 :    
16 :     val stack = CPSRegions.stack
17 :    
18 :     val native = true (* use native versions of the instructions? *)
19 :    
20 :     fun umul_native({r, i, d}, reduceOpnd) =
21 :     [I.ARITH{a=I.UMUL,r=r,i=i,d=d,cc=false}]
22 :    
23 :     (* overflows iff Y != (d ~>> 31) *)
24 :     fun smul_native({r, i, d}, reduceOpnd) =
25 :     let val t1 = C.newReg()
26 :     val t2 = C.newReg()
27 :     in [I.ARITH{a=I.SMUL,r=r,i=i,d=d,cc=false},
28 :     I.SHIFT{s=I.SRA,r=d,i=I.IMMED 31,d=t1},
29 :     I.RDY{d=t2},
30 :     I.ARITH{a=I.SUB,r=t1,i=I.REG t2,d=0,cc=true},
31 :     I.Ticc{t=I.BNE,r=0,i=I.IMMED 7}
32 :     ]
33 :     end
34 :     fun udiv_native({r,i,d},reduceOpnd) =
35 :     [I.WRY{r=0,i=I.REG 0},
36 :     I.ARITH{a=I.UDIV,r=r,i=i,d=d,cc=false}]
37 :     fun sdiv_native({r,i,d},reduceOpnd) =
38 :     let val t1 = C.newReg()
39 :     val t2 = C.newReg()
40 :     val t3 = C.newReg()
41 :     in [I.SETHI{i=0x200000, d=t1},
42 :     I.ARITH{a=I.AND,r=t1,i=I.REG r,d=t2,cc=false},
43 :     I.SHIFT{s=I.SRA,r=t2,i=I.IMMED 31,d=t3},
44 :     I.WRY{r=t3,i=I.REG 0},
45 :     I.ARITH{a=I.SDIV,r=r,i=i,d=d,cc=false}
46 :     ]
47 :     end
48 :    
49 :     (*
50 :     * Registers %o2, %o3 are used to pass arguments to ml_mul and ml_div
51 :     * Result is returned in %o2.
52 :     *)
53 :    
54 :     fun callRoutine(offset,reduceOpnd,r,i,d) =
55 :     let val addr = C.newReg()
56 :     val defs = C.addReg(10,C.empty)
57 :     val uses = C.addReg(10,C.addReg(11,C.empty))
58 :     in
59 :     [I.COPY{src=[r,reduceOpnd i],dst=[10,11],
60 :     tmp=SOME(I.Direct(C.newReg())),impl=ref NONE},
61 :     I.LOAD{l=I.LD,r=C.stackptrR,i=offset,d=addr,mem=stack},
62 :     I.JMPL{r=addr,i=I.IMMED 0,d=C.linkReg,defs=defs,uses=uses,nop=true},
63 :     I.COPY{src=[10],dst=[d],tmp=NONE,impl=ref NONE}
64 :     ]
65 :     end
66 :    
67 :     fun umul({r, i, d}, reduceOpnd) = callRoutine(umulOffset,reduceOpnd,r,i,d)
68 :     fun smul({r, i, d}, reduceOpnd) = callRoutine(smulOffset,reduceOpnd,r,i,d)
69 :     fun udiv({r, i, d}, reduceOpnd) = callRoutine(udivOffset,reduceOpnd,r,i,d)
70 :     fun sdiv({r, i, d}, reduceOpnd) = callRoutine(sdivOffset,reduceOpnd,r,i,d)
71 :    
72 :     fun cvti2d({i, d}, reduceOpnd) =
73 :     [I.STORE{s=I.ST,r=C.stackptrR,i=floatTmpOffset,d=reduceOpnd i,mem=stack},
74 :     I.FLOAD{l=I.LDF,r=C.stackptrR,i=floatTmpOffset,d=d,mem=stack},
75 :     I.FPop1{a=I.FiTOd,r=d,d=d}
76 :     ]
77 :    
78 :     (* Generate native versions of the instructions *)
79 :     val umul = if native then umul_native else umul
80 :     val smul = if native then smul_native else smul
81 :     val udiv = if native then udiv_native else udiv
82 :     val sdiv = if native then sdiv_native else sdiv
83 :    
84 :     end
85 :    
86 :     (*
87 :     * $Log$
88 :     *)

root@smlnj-gforge.cs.uchicago.edu
ViewVC Help
Powered by ViewVC 1.0.0