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 840 - (view) (download)

1 : monnier 245 functor SparcPseudoInstrs
2 :     (Instr : SPARCINSTR where Region=CPSRegions) : SPARC_PSEUDO_INSTR =
3 :     struct
4 :     structure I = Instr
5 :     structure C = Instr.C
6 :    
7 : monnier 411 type format1 =
8 : leunga 744 {r:C.cell, i:I.operand, d:C.cell} *
9 : monnier 429 (I.operand -> I.C.cell) -> I.instruction list
10 : monnier 245
11 : monnier 411 type format2 =
12 : leunga 744 {i:I.operand, d:C.cell} *
13 : monnier 429 (I.operand -> I.C.cell) -> I.instruction list
14 : monnier 411
15 :     fun error msg = MLRiscErrorMsg.impossible ("SparcPseudoInstrs."^msg)
16 :    
17 : blume 840 val delta = SparcSpec.framesize (* initial value of %fp - %sp *)
18 : monnier 245
19 : blume 840 (* runtime system dependent; the numbers are relative to %sp but
20 :     * we need offsets relative to %fp, hence the adjustment by delta *)
21 :     val floatTmpOffset = I.IMMED (88 - delta)
22 :     val umulOffset = I.IMMED (80 - delta)
23 :     val smulOffset = I.IMMED (72 - delta)
24 :     val udivOffset = I.IMMED (84 - delta)
25 :     val sdivOffset = I.IMMED (76 - delta)
26 :    
27 : monnier 245 val stack = CPSRegions.stack
28 :    
29 :     val native = true (* use native versions of the instructions? *)
30 :    
31 :     fun umul_native({r, i, d}, reduceOpnd) =
32 : monnier 411 [I.ARITH{a=I.UMUL,r=r,i=i,d=d}]
33 : monnier 245
34 : leunga 744 val TNE = I.Ticc{t=I.BNE,cc=I.ICC,r=C.r0,i=I.IMMED 7}
35 :     val TVS = I.Ticc{t=I.BVS,cc=I.ICC,r=C.r0,i=I.IMMED 7}
36 : monnier 411
37 : monnier 245 (* overflows iff Y != (d ~>> 31) *)
38 :     fun smul_native({r, i, d}, reduceOpnd) =
39 :     let val t1 = C.newReg()
40 :     val t2 = C.newReg()
41 : monnier 411 in [I.ARITH{a=I.SMUL,r=r,i=i,d=d},
42 : monnier 245 I.SHIFT{s=I.SRA,r=d,i=I.IMMED 31,d=t1},
43 :     I.RDY{d=t2},
44 : leunga 744 I.ARITH{a=I.SUBCC,r=t1,i=I.REG t2,d=C.r0},
45 : monnier 411 TNE
46 : monnier 245 ]
47 :     end
48 :     fun udiv_native({r,i,d},reduceOpnd) =
49 : leunga 744 [I.WRY{r=C.r0,i=I.REG C.r0},
50 : monnier 411 I.ARITH{a=I.UDIV,r=r,i=i,d=d}]
51 :    
52 :     (* May overflow if MININT div -1 *)
53 : monnier 245 fun sdiv_native({r,i,d},reduceOpnd) =
54 :     let val t1 = C.newReg()
55 : monnier 411 in [I.SHIFT{s=I.SRA,r=r,i=I.IMMED 31,d=t1},
56 : leunga 744 I.WRY{r=t1,i=I.REG C.r0},
57 : monnier 411 I.ARITH{a=I.SDIVCC,r=r,i=i,d=d},
58 :     TVS
59 : monnier 245 ]
60 :     end
61 :    
62 :     (*
63 :     * Registers %o2, %o3 are used to pass arguments to ml_mul and ml_div
64 :     * Result is returned in %o2.
65 :     *)
66 : leunga 744 val r10 = C.GPReg 10
67 :     val r11 = C.GPReg 11
68 : monnier 245
69 :     fun callRoutine(offset,reduceOpnd,r,i,d) =
70 :     let val addr = C.newReg()
71 : leunga 744 val defs = C.addReg(r10,C.empty)
72 :     val uses = C.addReg(r10,C.addReg(r11,C.empty))
73 : monnier 245 in
74 : leunga 744 [I.COPY{src=[r,reduceOpnd i],dst=[r10,r11],
75 : monnier 245 tmp=SOME(I.Direct(C.newReg())),impl=ref NONE},
76 : blume 840 I.LOAD{l=I.LD,r=C.frameptrR,i=offset,d=addr,mem=stack},
77 : leunga 796 I.JMPL{r=addr,i=I.IMMED 0,d=C.linkReg,defs=defs,uses=uses,
78 :     cutsTo=[],nop=true,mem=stack},
79 : leunga 744 I.COPY{src=[r10],dst=[d],tmp=NONE,impl=ref NONE}
80 : monnier 245 ]
81 :     end
82 :    
83 :     fun umul({r, i, d}, reduceOpnd) = callRoutine(umulOffset,reduceOpnd,r,i,d)
84 : leunga 657 fun smultrap({r, i, d}, reduceOpnd) = callRoutine(smulOffset,reduceOpnd,r,i,d)
85 : monnier 245 fun udiv({r, i, d}, reduceOpnd) = callRoutine(udivOffset,reduceOpnd,r,i,d)
86 : leunga 657 fun sdivtrap({r, i, d}, reduceOpnd) = callRoutine(sdivOffset,reduceOpnd,r,i,d)
87 : monnier 245
88 :     fun cvti2d({i, d}, reduceOpnd) =
89 : blume 840 [I.STORE{s=I.ST,r=C.frameptrR,i=floatTmpOffset,d=reduceOpnd i,mem=stack},
90 :     I.FLOAD{l=I.LDF,r=C.frameptrR,i=floatTmpOffset,d=d,mem=stack},
91 : monnier 245 I.FPop1{a=I.FiTOd,r=d,d=d}
92 :     ]
93 : monnier 411 fun cvti2s _ = error "cvti2s"
94 :     fun cvti2q _ = error "cvti2q"
95 : monnier 245
96 :     (* Generate native versions of the instructions *)
97 : leunga 657 val umul32 = if native then umul_native else umul
98 :     fun smul32 _ = error "smul32"
99 :     val smul32trap = if native then smul_native else smultrap
100 :     val udiv32 = if native then udiv_native else udiv
101 :     fun sdiv32 _ = error "sdiv32"
102 :     val sdiv32trap = if native then sdiv_native else sdivtrap
103 : monnier 245
104 : monnier 411 val overflowtrap32 = (* tvs 0x7 *)
105 : leunga 744 [I.Ticc{t=I.BVS,cc=I.ICC,r=C.r0,i=I.IMMED 7}]
106 : monnier 411 val overflowtrap64 = [] (* not needed *)
107 :    
108 :    
109 : monnier 245 end
110 :    

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