Debian Codegraph @

lib/mlrisc-lib/MLRISC/x86/instructions/x86comp-instr-ext.sml

raw
1 (* x86comp-instr-ext.sml
2 *
3 * COPYRIGHT (c) 2000 Bell Labs, Lucent Technologies
4 *
5 * emit code for extensions to the x86 instruction set.
6 *)
7 signature X86COMP_INSTR_EXT = sig
8 structure I : X86INSTR
9 structure TS : MLTREE_STREAM (* where T = I.T *)
10 where type T.Basis.cond = I.T.Basis.cond
11 and type T.Basis.div_rounding_mode = I.T.Basis.div_rounding_mode
12 and type T.Basis.ext = I.T.Basis.ext
13 and type T.Basis.fcond = I.T.Basis.fcond
14 and type T.Basis.rounding_mode = I.T.Basis.rounding_mode
15 and type T.Constant.const = I.T.Constant.const
16 and type ('s,'r,'f,'c) T.Extension.ccx = ('s,'r,'f,'c) I.T.Extension.ccx
17 and type ('s,'r,'f,'c) T.Extension.fx = ('s,'r,'f,'c) I.T.Extension.fx
18 and type ('s,'r,'f,'c) T.Extension.rx = ('s,'r,'f,'c) I.T.Extension.rx
19 and type ('s,'r,'f,'c) T.Extension.sx = ('s,'r,'f,'c) I.T.Extension.sx
20 and type T.I.div_rounding_mode = I.T.I.div_rounding_mode
21 and type T.Region.region = I.T.Region.region
22 and type T.ccexp = I.T.ccexp
23 and type T.fexp = I.T.fexp
24 (* and type T.labexp = I.T.labexp *)
25 and type T.mlrisc = I.T.mlrisc
26 and type T.oper = I.T.oper
27 and type T.rep = I.T.rep
28 and type T.rexp = I.T.rexp
29 and type T.stm = I.T.stm
30 structure CFG : CONTROL_FLOW_GRAPH (* where I = I and P = TS.S.P *)
31 where type I.addressing_mode = I.addressing_mode
32 and type I.ea = I.ea
33 and type I.instr = I.instr
34 and type I.instruction = I.instruction
35 and type I.operand = I.operand
36 where type P.Client.pseudo_op = TS.S.P.Client.pseudo_op
37 and type P.T.Basis.cond = TS.S.P.T.Basis.cond
38 and type P.T.Basis.div_rounding_mode = TS.S.P.T.Basis.div_rounding_mode
39 and type P.T.Basis.ext = TS.S.P.T.Basis.ext
40 and type P.T.Basis.fcond = TS.S.P.T.Basis.fcond
41 and type P.T.Basis.rounding_mode = TS.S.P.T.Basis.rounding_mode
42 and type P.T.Constant.const = TS.S.P.T.Constant.const
43 and type ('s,'r,'f,'c) P.T.Extension.ccx = ('s,'r,'f,'c) TS.S.P.T.Extension.ccx
44 and type ('s,'r,'f,'c) P.T.Extension.fx = ('s,'r,'f,'c) TS.S.P.T.Extension.fx
45 and type ('s,'r,'f,'c) P.T.Extension.rx = ('s,'r,'f,'c) TS.S.P.T.Extension.rx
46 and type ('s,'r,'f,'c) P.T.Extension.sx = ('s,'r,'f,'c) TS.S.P.T.Extension.sx
47 and type P.T.I.div_rounding_mode = TS.S.P.T.I.div_rounding_mode
48 and type P.T.Region.region = TS.S.P.T.Region.region
49 and type P.T.ccexp = TS.S.P.T.ccexp
50 and type P.T.fexp = TS.S.P.T.fexp
51 (* and type P.T.labexp = TS.S.P.T.labexp *)
52 and type P.T.mlrisc = TS.S.P.T.mlrisc
53 and type P.T.oper = TS.S.P.T.oper
54 and type P.T.rep = TS.S.P.T.rep
55 and type P.T.rexp = TS.S.P.T.rexp
56 and type P.T.stm = TS.S.P.T.stm
57
58 type reducer =
59 (I.instruction, I.C.cellset, I.operand, I.addressing_mode, CFG.cfg) TS.reducer
60
61 val compileSext :
62 reducer
63 -> {stm: (I.T.stm, I.T.rexp, I.T.fexp, I.T.ccexp) X86InstrExt.sext,
64 an: I.T.an list}
65 -> unit
66 end
67
68
69
70
71 functor X86CompInstrExt
72 ( structure I : X86INSTR
73 structure TS : MLTREE_STREAM (* where T = I.T *)
74 where type T.Basis.cond = I.T.Basis.cond
75 and type T.Basis.div_rounding_mode = I.T.Basis.div_rounding_mode
76 and type T.Basis.ext = I.T.Basis.ext
77 and type T.Basis.fcond = I.T.Basis.fcond
78 and type T.Basis.rounding_mode = I.T.Basis.rounding_mode
79 and type T.Constant.const = I.T.Constant.const
80 and type ('s,'r,'f,'c) T.Extension.ccx = ('s,'r,'f,'c) I.T.Extension.ccx
81 and type ('s,'r,'f,'c) T.Extension.fx = ('s,'r,'f,'c) I.T.Extension.fx
82 and type ('s,'r,'f,'c) T.Extension.rx = ('s,'r,'f,'c) I.T.Extension.rx
83 and type ('s,'r,'f,'c) T.Extension.sx = ('s,'r,'f,'c) I.T.Extension.sx
84 and type T.I.div_rounding_mode = I.T.I.div_rounding_mode
85 and type T.Region.region = I.T.Region.region
86 and type T.ccexp = I.T.ccexp
87 and type T.fexp = I.T.fexp
88 (* and type T.labexp = I.T.labexp *)
89 and type T.mlrisc = I.T.mlrisc
90 and type T.oper = I.T.oper
91 and type T.rep = I.T.rep
92 and type T.rexp = I.T.rexp
93 and type T.stm = I.T.stm
94 structure CFG : CONTROL_FLOW_GRAPH (* where P = TS.S.P and I = I *)
95 where type P.Client.pseudo_op = TS.S.P.Client.pseudo_op
96 and type P.T.Basis.cond = TS.S.P.T.Basis.cond
97 and type P.T.Basis.div_rounding_mode = TS.S.P.T.Basis.div_rounding_mode
98 and type P.T.Basis.ext = TS.S.P.T.Basis.ext
99 and type P.T.Basis.fcond = TS.S.P.T.Basis.fcond
100 and type P.T.Basis.rounding_mode = TS.S.P.T.Basis.rounding_mode
101 and type P.T.Constant.const = TS.S.P.T.Constant.const
102 and type ('s,'r,'f,'c) P.T.Extension.ccx = ('s,'r,'f,'c) TS.S.P.T.Extension.ccx
103 and type ('s,'r,'f,'c) P.T.Extension.fx = ('s,'r,'f,'c) TS.S.P.T.Extension.fx
104 and type ('s,'r,'f,'c) P.T.Extension.rx = ('s,'r,'f,'c) TS.S.P.T.Extension.rx
105 and type ('s,'r,'f,'c) P.T.Extension.sx = ('s,'r,'f,'c) TS.S.P.T.Extension.sx
106 and type P.T.I.div_rounding_mode = TS.S.P.T.I.div_rounding_mode
107 and type P.T.Region.region = TS.S.P.T.Region.region
108 and type P.T.ccexp = TS.S.P.T.ccexp
109 and type P.T.fexp = TS.S.P.T.fexp
110 (* and type P.T.labexp = TS.S.P.T.labexp *)
111 and type P.T.mlrisc = TS.S.P.T.mlrisc
112 and type P.T.oper = TS.S.P.T.oper
113 and type P.T.rep = TS.S.P.T.rep
114 and type P.T.rexp = TS.S.P.T.rexp
115 and type P.T.stm = TS.S.P.T.stm
116 where type I.addressing_mode = I.addressing_mode
117 and type I.ea = I.ea
118 and type I.instr = I.instr
119 and type I.instruction = I.instruction
120 and type I.operand = I.operand
121 ) : X86COMP_INSTR_EXT =
122 struct
123 structure CFG = CFG
124 structure T = TS.T
125 structure I = I
126 structure C = I.C
127 structure X = X86InstrExt
128 structure TS = TS
129
130 type stm = (T.stm, T.rexp, T.fexp, T.ccexp) X.sext
131
132 type reducer =
133 (I.instruction, I.C.cellset, I.operand, I.addressing_mode, CFG.cfg) TS.reducer
134
135 val esp = C.esp
136 val espOpnd = I.Direct(esp)
137
138 fun error msg = MLRiscErrorMsg.error("X86CompInstrExt", msg)
139
140 val stackArea = I.Region.stack
141
142 fun compileSext reducer {stm: stm, an:T.an list} = let
143 val TS.REDUCER{operand, emit, reduceFexp, instrStream, reduceOperand,
144 ...} = reducer
145 val TS.S.STREAM{emit=emitI, ...} = instrStream
146 fun fstp(sz, fstpInstr, fexp) =
147 (case fexp
148 of T.FREG(sz', f) =>
149 if sz <> sz' then error "fstp: sz"
150 else emitI(I.INSTR(fstpInstr(I.FDirect f)))
151 | _ => error "fstp: fexp"
152 (*esac*))
153 in
154 case stm
155 of X.PUSHL(rexp) => emit(I.pushl(operand rexp), an)
156 | X.POP(rexp) => emit(I.pop(operand rexp), an)
157
158 | X.FSTPS(fexp) => fstp(32, I.FSTPS, fexp)
159 | X.FSTPL(fexp) => fstp(64, I.FSTPL, fexp)
160 | X.FSTPT(fexp) => fstp(80, I.FSTPT, fexp)
161
162 | X.LEAVE => emit(I.leave, an)
163 | X.RET(rexp) => emit(I.ret(SOME(operand rexp)), an)
164 | X.LOCK_CMPXCHGL(src, dst) =>
165 (* src must in a register *)
166 emit(I.cmpxchg{lock=true,sz=I.I32,
167 src=I.Direct(reduceOperand(operand src)),
168 dst=operand dst},an)
169 | X.PAUSE => emit(I.pause, an)
170 | X.MFENCE => emit(I.mfence, an)
171 | X.LFENCE => emit(I.lfence, an)
172 | X.SFENCE => emit(I.sfence, an)
173
174 end
175 end