| 1 |
(* |
| 2 |
* This machine description now includes 64-bit and single precision |
| 3 |
* floating point support. The description |
| 4 |
* is copied from the book ``Alpha Architecture Reference Manual'' edited |
| 5 |
* by Richard L. Sites, Digital Press, 1992. |
| 6 |
* |
| 7 |
* -- Allen Leung |
| 8 |
*) |
| 9 |
architecture Alpha = |
| 10 |
struct |
| 11 |
|
| 12 |
superscalar |
| 13 |
|
| 14 |
little endian |
| 15 |
|
| 16 |
lowercase assembly |
| 17 |
|
| 18 |
(* |
| 19 |
* This specify the cells interface |
| 20 |
*) |
| 21 |
storage |
| 22 |
GP = $r[32] of 64 bits where $r[31] = 0 |
| 23 |
asm: (fn (30,_) => "$sp" |
| 24 |
| (r,_) => "$"^Int.toString r |
| 25 |
) |
| 26 |
| FP = $f[32] of 64 bits where $f[31] = 0 |
| 27 |
asm: (fn (f,_) => "$f"^Int.toString f) |
| 28 |
| CC = $cc[] of 64 bits aliasing GP asm: "cc" |
| 29 |
| MEM = $m[] of 8 aggregable bits asm: (fn (r,_) => "m"^Int.toString r) |
| 30 |
| CTRL = $ctrl[] asm: (fn (r,_) => "ctrl"^Int.toString r) |
| 31 |
|
| 32 |
locations |
| 33 |
stackptrR = $r[30] |
| 34 |
and asmTmpR = $r[28] |
| 35 |
and fasmTmp = $r[30] |
| 36 |
and returnAddr = $r[26] |
| 37 |
and r31 = $r[31] |
| 38 |
and f31 = $f[31] |
| 39 |
|
| 40 |
structure RTL = |
| 41 |
struct |
| 42 |
include "Tools/basis.mdl" |
| 43 |
open Basis |
| 44 |
infix 1 || |
| 45 |
infix 2 := |
| 46 |
infix 3 << >> ~>> |
| 47 |
|
| 48 |
(* How to align addresses *) |
| 49 |
fun align4 addr = andb(addr,notb 3) |
| 50 |
fun align8 addr = andb(addr,notb 7) |
| 51 |
fun align8Upper addr = orb(andb(addr,notb 7),4) |
| 52 |
|
| 53 |
fun %% l = (l : #64 bits) |
| 54 |
|
| 55 |
fun disp(b,d) = $r[b] + d |
| 56 |
|
| 57 |
fun byte x = (x : #8 bits) |
| 58 |
fun word x = (x : #16 bits) |
| 59 |
fun dword x = (x : #32 bits) |
| 60 |
fun qword x = (x : #64 bits) |
| 61 |
fun float x = (x : #32 bits) |
| 62 |
fun double x = (x : #64 bits) |
| 63 |
|
| 64 |
rtl LDA{r,b,d} = $r[r] := $r[b] + d |
| 65 |
rtl LDAH{r,b,d} = $r[r] := $r[b] + d << 16 |
| 66 |
|
| 67 |
(* Integer loads *) |
| 68 |
rtl LDB{r,b,d,mem} = $r[r] := sx (byte $m[disp(b,d):mem]) |
| 69 |
rtl LDW{r,b,d,mem} = $r[r] := sx (word $m[disp(b,d):mem]) |
| 70 |
rtl LDBU{r,b,d,mem} = $r[r] := zx (byte $m[disp(b,d):mem]) |
| 71 |
rtl LDWU{r,b,d,mem} = $r[r] := zx (word $m[disp(b,d):mem]) |
| 72 |
rtl LDL{r,b,d,mem} = $r[r] := sx (dword $m[disp(b,d):mem]) |
| 73 |
rtl LDL_L{r,b,d,mem} = $r[r] := sx (dword $m[align4(disp(b,d)):mem]) |
| 74 |
rtl LDQ{r,b,d,mem} = $r[r] := qword $m[disp(b,d):mem] |
| 75 |
rtl LDQ_L{r,b,d,mem} = $r[r] := qword $m[align8(disp(b,d)):mem] |
| 76 |
rtl LDQ_U{r,b,d,mem} = $r[r] := qword $m[align8Upper(disp(b,d)):mem] |
| 77 |
|
| 78 |
(* Integer stores *) |
| 79 |
rtl STB{r,b,d,mem} = $m[disp(b,d):mem] := $r[r] at [0..7] |
| 80 |
rtl STW{r,b,d,mem} = $m[disp(b,d):mem] := $r[r] at [0..15] |
| 81 |
rtl STL{r,b,d,mem} = $m[disp(b,d):mem] := $r[r] at [0..31] |
| 82 |
rtl STQ{r,b,d,mem} = $m[disp(b,d):mem] := $r[r] |
| 83 |
rtl STQ_U{r,b,d,mem} = $m[align8(disp(b,d)):mem] := $r[r] |
| 84 |
|
| 85 |
(* Floating point loads *) |
| 86 |
rtl LDF{r,b,d,mem} = $f[r] := sx (float $m[disp(b,d):mem]) |
| 87 |
rtl LDG{r,b,d,mem} = $f[r] := double $m[disp(b,d):mem] |
| 88 |
rtl LDS{r,b,d,mem} = $f[r] := double $m[disp(b,d):mem] |
| 89 |
rtl LDT{r,b,d,mem} = $f[r] := double $m[disp(b,d):mem] |
| 90 |
|
| 91 |
(* Floating point stores *) |
| 92 |
rtl STF{r,b,d,mem} = $m[disp(b,d):mem] := float(sx $f[r]) |
| 93 |
rtl STG{r,b,d,mem} = $m[disp(b,d):mem] := $f[r] |
| 94 |
rtl STS{r,b,d,mem} = $m[disp(b,d):mem] := $f[r] |
| 95 |
rtl STT{r,b,d,mem} = $m[disp(b,d):mem] := $f[r] |
| 96 |
|
| 97 |
(* Integer operators *) |
| 98 |
rtl ADDL{ra,rb,rc} = $r[rc] := sx($r[ra] + rb) |
| 99 |
rtl ADDQ{ra,rb,rc} = $r[rc] := $r[ra] + rb |
| 100 |
fun cmp oper {ra,rb,rc} = $r[rc] := cond(oper($r[ra],rb), 1, 0) |
| 101 |
|
| 102 |
rtl [CMPBGE, CMPEQ, CMPLE, CMPLT, CMPULE, CMPULT] = |
| 103 |
map cmp [(>=), (==), (<=), (<), (leu), (ltu)] |
| 104 |
|
| 105 |
fun binop oper {ra,rb,rc} = $r[rc] := oper($r[ra], rb) |
| 106 |
|
| 107 |
rtl SUBL{ra,rb,rc} = $r[rc] := sx($r[ra] - rb) |
| 108 |
rtl SUBQ{ra,rb,rc} = $r[rc] := $r[ra] - rb |
| 109 |
rtl S4ADDL{ra,rb,rc} = $r[rc] := sx($r[ra] << 2 + rb) |
| 110 |
rtl S4ADDQ{ra,rb,rc} = $r[rc] := $r[ra] << 2 + rb |
| 111 |
rtl S4SUBL{ra,rb,rc} = $r[rc] := sx($r[ra] << 2 - rb) |
| 112 |
rtl S4SUBQ{ra,rb,rc} = $r[rc] := $r[ra] << 2 - rb |
| 113 |
rtl S8ADDL{ra,rb,rc} = $r[rc] := sx($r[ra] << 3 + rb) |
| 114 |
rtl S8ADDQ{ra,rb,rc} = $r[rc] := $r[ra] << 3 + rb |
| 115 |
rtl S8SUBL{ra,rb,rc} = $r[rc] := sx($r[ra] << 3 - rb) |
| 116 |
rtl S8SUBQ{ra,rb,rc} = $r[rc] := $r[ra] << 3 - rb |
| 117 |
rtl AND{ra,rb,rc} = $r[rc] := andb($r[ra], rb) |
| 118 |
rtl BIC{ra,rb,rc} = $r[rc] := andb($r[ra], notb(rb)) (* XXX *) |
| 119 |
rtl BIS{ra,rb,rc} = $r[rc] := orb($r[ra], rb) |
| 120 |
rtl EQV{ra,rb,rc} = $r[rc] := eqvb($r[ra], rb) |
| 121 |
rtl ORNOT{ra,rb,rc} = $r[rc] := orb($r[ra], notb(rb)) |
| 122 |
rtl XOR{ra,rb,rc} = $r[rc] := xorb($r[ra], rb) |
| 123 |
|
| 124 |
rtl extbl extlh extll extqh extql extwh extwl insbl inslh insll |
| 125 |
insqh insql inswh inswl mskbl msklh mskll mskqh mskql mskwh mskwl |
| 126 |
: #n bits * #n bits -> #n bits |
| 127 |
rtl [EXTBL, EXTLH, EXTLL, EXTQH, EXTQL, EXTWH, EXTWL, |
| 128 |
INSBL, INSLH, INSLL, INSQH, INSQL, INSWH, INSWL, |
| 129 |
MSKBL, MSKLH, MSKLL, MSKQH, MSKQL, MSKWH, MSKWL] = |
| 130 |
map binop |
| 131 |
[extbl, extlh, extll, extqh, extql, extwh, extwl, |
| 132 |
insbl, inslh, insll, insqh, insql, inswh, inswl, |
| 133 |
mskbl, msklh, mskll, mskqh, mskql, mskwh, mskwl] |
| 134 |
|
| 135 |
rtl [SLL, SRA, SRL] = |
| 136 |
map binop [(<<), (~>>), (>>)] |
| 137 |
|
| 138 |
rtl zap zapnot umulh : #n bits * #n bits -> #n bits |
| 139 |
rtl ZAP{ra,rb,rc} = $r[rc] := zap($r[ra], rb) |
| 140 |
rtl ZAPNOT{ra,rb,rc} = $r[rc] := zapnot($r[ra], rb) |
| 141 |
rtl MULL{ra,rb,rc} = $r[rc] := sx(muls($r[ra], rb)) |
| 142 |
rtl MULQ{ra,rb,rc} = $r[rc] := muls($r[ra], rb) |
| 143 |
rtl UMULH{ra,rb,rc} = $r[rc] := umulh($r[ra], rb) |
| 144 |
|
| 145 |
(* Integer trapping operators *) |
| 146 |
val overflowtrap = () |
| 147 |
rtl ADDLV{ra,rb,rc} = ADDL{ra,rb,rc} || overflowtrap |
| 148 |
rtl ADDQV{ra,rb,rc} = ADDQ{ra,rb,rc} || overflowtrap |
| 149 |
rtl SUBLV{ra,rb,rc} = SUBL{ra,rb,rc} || overflowtrap |
| 150 |
rtl SUBQV{ra,rb,rc} = SUBQ{ra,rb,rc} || overflowtrap |
| 151 |
rtl MULLV{ra,rb,rc} = MULL{ra,rb,rc} || overflowtrap |
| 152 |
rtl MULQV{ra,rb,rc} = MULQ{ra,rb,rc} || overflowtrap |
| 153 |
|
| 154 |
fun lbc(x,y) = andb(x,1) == y |
| 155 |
fun lbs(x,y) = andb(x,1) <> y |
| 156 |
|
| 157 |
val comparisons = [(==), lbc, lbs, (>=), (>), (<=), (<), (<>)] |
| 158 |
|
| 159 |
(* Conditional moves *) |
| 160 |
fun cmov oper {ra,rb,rc} = if oper($r[ra], 0) then $r[rc] := rb else () |
| 161 |
|
| 162 |
rtl CMOV ^^ [EQ, LBC, LBS, GE, GT, LE, LT, NE] = |
| 163 |
map cmov comparisons |
| 164 |
|
| 165 |
(* Integer branches *) |
| 166 |
rtl BR{lab} = Jmp(%%lab) |
| 167 |
rtl BSR{lab,r,defs,uses,mem} = |
| 168 |
Call(%%lab) || |
| 169 |
Kill $r[r] || |
| 170 |
Kill $cellset[defs] || |
| 171 |
Use $cellset[uses] || |
| 172 |
$m[??? :mem] := ($m[??? :mem] : #8 bits) |
| 173 |
|
| 174 |
fun branch oper {r,lab} = if oper($r[r], 0) then Jmp(%%lab) else () |
| 175 |
|
| 176 |
rtl [BEQ, BLBC, BLBS, BGE, BGT, BLE, BLT, BNE] = |
| 177 |
map branch comparisons |
| 178 |
|
| 179 |
(* Floating point operators *) |
| 180 |
|
| 181 |
val SU = () |
| 182 |
val SUD = () |
| 183 |
fun farith oper {fa,fb,fc} = $f[fc] := oper($f[fa], $f[fb]) |
| 184 |
fun funary oper {fb,fc} = $f[fc] := oper($f[fb]) |
| 185 |
rtl fops as [ADDS, ADDT, SUBS, SUBT, MULS, MULT, DIVS, DIVT] = |
| 186 |
map farith |
| 187 |
[fadd, fadd, fsub, fsub, fmul, fmul, fdiv, fdiv] |
| 188 |
fun su fop {fa,fb,fc} = fop{fa,fb,fc} || SU |
| 189 |
fun sud fop {fa,fb,fc} = fop{fa,fb,fc} || SUD |
| 190 |
rtl [ADDSSU, ADDTSU, SUBSSU, SUBTSU, MULSSU, MULTSU, DIVSSU, DIVTSU] = |
| 191 |
map su fops |
| 192 |
rtl [ADDSSUD, ADDTSUD, SUBSSUD, SUBTSUD, |
| 193 |
MULSSUD, MULTSUD, DIVSSUD, DIVTSUD] = |
| 194 |
map sud fops |
| 195 |
|
| 196 |
rtl cpys cpyse cpysn mf_fpcr mt_fpcr : #64 bits * #64 bits -> #64 bits |
| 197 |
rtl [CPYS,CPYSE, CPYSN, MF_FPCR, MT_FPCR] = |
| 198 |
map farith [cpys, cpyse, cpysn, mf_fpcr, mt_fpcr] |
| 199 |
|
| 200 |
rtl cvtlq cvtql cvtqlsv cvtqlv cvtqs cvtqsc |
| 201 |
cvtqt cvtqtc cvtts cvttsc |
| 202 |
cvtst cvtsts cvttq cvttqc : #64 bits -> #64 bits |
| 203 |
|
| 204 |
rtl CVT^^[LQ,QL,QLSV,QLV,QS,QSC,QT,QTC,TS,TSC,ST,STS,TQ,TQC] = |
| 205 |
map funary cvt^^[lq,ql,qlsv,qlv,qs,qsc,qt,qtc,ts,tsc,st,sts,tq,tqc] |
| 206 |
|
| 207 |
rtl teq tlt tle tun : #64 bits * #64 bits -> #64 bits |
| 208 |
rtl fcmps as [CMPTEQ, CMPTLT, CMPTLE, CMPTUN] = |
| 209 |
map farith [teq, tlt, tle, tun] |
| 210 |
rtl [CMPTEQSU, CMPTLTSU, CMPTLESU, CMPTUNSU] = |
| 211 |
map su fcmps |
| 212 |
|
| 213 |
(* Floating point branches *) |
| 214 |
fun fbranch oper {f,lab} = if oper($f[f],???) then Jmp(%%lab) else () |
| 215 |
rtl [FBEQ, FBLT, FBLE, FBNE, FBGE, FBGT] = |
| 216 |
map fbranch [|==|, |<|, |<=|, |<>|, |>=|, |>|] |
| 217 |
|
| 218 |
(* Floating point moves *) |
| 219 |
fun fcmove cmp {fa,fb,fc} = |
| 220 |
if cmp($f[fa],???) then $f[fc] := $f[fb] else () |
| 221 |
rtl FCMOV ^^ [EQ, LT, LE, NE, GE, GT] = |
| 222 |
map fcmove [|==|, |<|, |<=|, |<>|, |>=|, |>|] |
| 223 |
|
| 224 |
(* Call/return *) |
| 225 |
rtl JSR{r,b,defs,uses,mem} = |
| 226 |
Call($r[b]) || |
| 227 |
Kill $r[r] || |
| 228 |
Kill $cellset[defs] || |
| 229 |
Use $cellset[uses] || |
| 230 |
$m[??? :mem] := ($m[??? :mem] : #8 bits) |
| 231 |
rtl RET{r,b} = Jmp($r[b]) || Kill $r[r] |
| 232 |
rtl JMPL{r,b} = Jmp($r[b]) || Kill $r[r] |
| 233 |
rtl TRAPB{} = () |
| 234 |
|
| 235 |
(* Pseudo arithmetic *) |
| 236 |
fun pseudoOp oper {ra,rb,rc,tmps} = |
| 237 |
$r[rc] := oper($r[ra], rb) || |
| 238 |
Kill $cellset[tmps] (* XXX *) |
| 239 |
rtl PSEUDOARITH_ ^^ [ DIVL, DIVLU, DIVQ, DIVQU, |
| 240 |
REML, REMLU, REMQ, REMQU ] = |
| 241 |
map pseudoOp [ divs, divu, divs, divu, (* XXX *) |
| 242 |
rems, remu, rems, remu ] |
| 243 |
(* Pal code |
| 244 |
* Note: I have no idea what these things are, so I'm just going |
| 245 |
* fake them |
| 246 |
*) |
| 247 |
rtl BPT BUGCHK CALLSYS GENTRAP IMB RDUNIQUE WRUNIQUE : #64 bits -> #64 bits |
| 248 |
fun CALL_PAL code {def,use} = |
| 249 |
Call(qword(code(qword 0))) || |
| 250 |
Kill $cellset[def] || |
| 251 |
Use $cellset[use] |
| 252 |
rtl CALL_PAL_ ^^ |
| 253 |
[BPT, BUGCHK, CALLSYS, GENTRAP, IMB, RDUNIQUE, WRUNIQUE] = |
| 254 |
map CALL_PAL |
| 255 |
[BPT, BUGCHK, CALLSYS, GENTRAP, IMB, RDUNIQUE, WRUNIQUE] |
| 256 |
end (* RTL *) |
| 257 |
|
| 258 |
|
| 259 |
(* |
| 260 |
* Reservation tables and pipeline definitions for scheduling |
| 261 |
*) |
| 262 |
|
| 263 |
(* Function units *) |
| 264 |
resource issue and mem and alu and falu and fmul and fdiv and branch |
| 265 |
|
| 266 |
(* Different implementations of cpus *) |
| 267 |
cpu default 2 [2 issue, 2 mem, 1 alu] (* 2 issue machine *) |
| 268 |
|
| 269 |
(* Definitions of various reservation tables *) |
| 270 |
pipeline NOP _ = [issue] |
| 271 |
and ARITH _ = [issue^^alu] |
| 272 |
and LOAD _ = [issue^^mem] |
| 273 |
and STORE _ = [issue^^mem,mem,mem] |
| 274 |
and FARITH _ = [issue^^falu] |
| 275 |
and FMUL _ = [issue^^fmul,fmul] |
| 276 |
and FDIV _ = [issue^^fdiv,fdiv*50] |
| 277 |
and BRANCH _ = [issue^^branch] |
| 278 |
|
| 279 |
(* |
| 280 |
* We now specify the instruction representation, assembly, |
| 281 |
* machine code encoding and ``semantics'' |
| 282 |
*) |
| 283 |
structure Instruction = |
| 284 |
struct |
| 285 |
datatype ea = |
| 286 |
Direct of $GP |
| 287 |
| FDirect of $FP |
| 288 |
| Displace of {base: $GP, disp: T.labexp, mem: Region.region} |
| 289 |
|
| 290 |
datatype operand = |
| 291 |
REGop of $GP ``<GP>'' rtl: $r[GP] |
| 292 |
| IMMop of int ``<int>'' rtl: immed int |
| 293 |
| HILABop of T.labexp ``hi(<labexp>)'' rtl: hi(labexp) |
| 294 |
| LOLABop of T.labexp ``lo(<labexp>)'' rtl: lo(labexp) |
| 295 |
| LABop of T.labexp ``<labexp>'' rtl: labexp |
| 296 |
|
| 297 |
(* |
| 298 |
* When I say ! after the datatype name XXX, it means generate a |
| 299 |
* function emit_XXX that converts the constructors into the corresponding |
| 300 |
* assembly text. By default, it uses the same name as the constructor, |
| 301 |
* but may be modified by the lowercase/uppercase assembly directive. |
| 302 |
* |
| 303 |
*) |
| 304 |
datatype branch! = (* table C-2 *) |
| 305 |
BR 0x30 |
| 306 |
(*| BSR 0x34 *) |
| 307 |
| BLBC 0x38 |
| 308 |
| BEQ 0x39 | BLT 0x3a | BLE 0x3b |
| 309 |
| BLBS 0x3c | BNE 0x3d | BGE 0x3e |
| 310 |
| BGT 0x3f |
| 311 |
|
| 312 |
datatype fbranch! = (* table C-2 *) |
| 313 |
FBEQ 0x31 | FBLT 0x32 |
| 314 |
| FBLE 0x33 | FBNE 0x35 |
| 315 |
| FBGE 0x36 | FBGT 0x37 |
| 316 |
|
| 317 |
datatype load! = (* table C-1 *) |
| 318 |
LDB |
| 319 |
| LDW |
| 320 |
| LDBU 0x02 |
| 321 |
| LDWU 0x04 |
| 322 |
| LDL 0x28 |
| 323 |
| LDL_L 0x2A |
| 324 |
| LDQ 0x29 |
| 325 |
| LDQ_L 0x2B |
| 326 |
| LDQ_U 0x0B |
| 327 |
datatype store! = STB 0x0E | STW 0x0D | STL 0x2C | STQ 0x2D | STQ_U 0x0F |
| 328 |
datatype fload [0x20..0x23] ! = LDF | LDG | LDS | LDT |
| 329 |
datatype fstore [0x24..0x27] ! = STF | STG | STS | STT |
| 330 |
|
| 331 |
(* non-trapping opcodes *) |
| 332 |
datatype operate! = (* table C-5 *) |
| 333 |
ADDL (0wx10,0wx00) | ADDQ (0wx10,0wx20) |
| 334 |
| CMPBGE(0wx10,0wx0f) | CMPEQ (0wx10,0wx2d) |
| 335 |
| CMPLE (0wx10,0wx6d) | CMPLT (0wx10,0wx4d) | CMPULE (0wx10,0wx3d) |
| 336 |
| CMPULT(0wx10,0wx1d) | SUBL (0wx10,0wx09) |
| 337 |
| SUBQ (0wx10,0wx29) |
| 338 |
| S4ADDL(0wx10,0wx02) | S4ADDQ (0wx10,0wx22) | S4SUBL (0wx10,0wx0b) |
| 339 |
| S4SUBQ(0wx10,0wx2b) | S8ADDL (0wx10,0wx12) | S8ADDQ (0wx10,0wx32) |
| 340 |
| S8SUBL(0wx10,0wx1b) | S8SUBQ (0wx10,0wx3b) |
| 341 |
|
| 342 |
| AND (0wx11,0wx00) | BIC (0wx11,0wx08) | BIS (0wx11,0wx20) |
| 343 |
| EQV (0wx11,0wx48) |
| 344 |
| ORNOT (0wx11,0wx28) | XOR (0wx11,0wx40) |
| 345 |
|
| 346 |
| EXTBL (0wx12,0wx06) | EXTLH (0wx12,0wx6a) | EXTLL(0wx12,0wx26) |
| 347 |
| EXTQH (0wx12,0wx7a) | EXTQL (0wx12,0wx36) | EXTWH(0wx12,0wx5a) |
| 348 |
| EXTWL (0wx12,0wx16) | INSBL (0wx12,0wx0b) | INSLH(0wx12,0wx67) |
| 349 |
| INSLL (0wx12,0wx2b) | INSQH (0wx12,0wx77) | INSQL(0wx12,0wx3b) |
| 350 |
| INSWH (0wx12,0wx57) | INSWL (0wx12,0wx1b) | MSKBL(0wx12,0wx02) |
| 351 |
| MSKLH (0wx12,0wx62) | MSKLL (0wx12,0wx22) | MSKQH(0wx12,0wx72) |
| 352 |
| MSKQL (0wx12,0wx32) | MSKWH (0wx12,0wx52) | MSKWL(0wx12,0wx12) |
| 353 |
| SLL (0wx12,0wx39) | SRA (0wx12,0wx3c) | SRL (0wx12,0wx34) |
| 354 |
| ZAP (0wx12,0wx30) | ZAPNOT (0wx12,0wx31) |
| 355 |
| MULL (0wx13,0wx00) | MULQ (0wx13,0wx20) |
| 356 |
| UMULH (0wx13,0wx30) |
| 357 |
|
| 358 |
(* conditional moves *) |
| 359 |
datatype cmove! = |
| 360 |
CMOVEQ 0wx24 | CMOVLBC 0wx16 | CMOVLBS 0wx14 |
| 361 |
| CMOVGE 0wx46 | CMOVGT 0wx66 | CMOVLE 0wx64 |
| 362 |
| CMOVLT 0wx44 | CMOVNE 0wx26 |
| 363 |
|
| 364 |
datatype pseudo_op! = DIVL | DIVLU | DIVQ | DIVQU |
| 365 |
| REML | REMLU | REMQ | REMQU |
| 366 |
|
| 367 |
datatype operateV! = (* table C-5 opc/func *) |
| 368 |
ADDLV (0wx10,0wx40) | ADDQV (0wx10,0wx60) |
| 369 |
| SUBLV (0wx10,0wx49) | SUBQV (0wx10,0wx69) |
| 370 |
| MULLV (0wx13,0wx40) | MULQV (0wx13,0wx60) |
| 371 |
|
| 372 |
datatype funary! = (* table C-6/C-7 *) |
| 373 |
(* C-6 *) |
| 374 |
CVTLQ (0wx17,0wx010) | CVTQL (0wx17,0wx030) | CVTQLSV (0wx17,0wx530) |
| 375 |
| CVTQLV (0wx17,0wx130) |
| 376 |
|
| 377 |
(* C-7 *) |
| 378 |
| CVTQS (0wx16,0wxbc) | CVTQSC (0wx16,0wx3c) |
| 379 |
| CVTQT (0wx16,0wxbe) | CVTQTC (0wx16,0wx3e) |
| 380 |
| CVTTS (0wx16,0wxac) | CVTTSC (0wx16,0wx2c) |
| 381 |
| CVTST (0wx16,0wx2ac) | CVTSTS (0wx16,0wx6ac) |
| 382 |
| CVTTQ (0wx16,0wxaf) | CVTTQC (0wx16,0wx2f) |
| 383 |
|
| 384 |
datatype foperate! = (* table C-6 *) |
| 385 |
CPYS (0wx17,0wx20) | CPYSE (0wx17,0wx022) | CPYSN (0wx17,0wx021) |
| 386 |
| MF_FPCR (0wx17,0wx025) | MT_FPCR (0wx17,0wx024) |
| 387 |
|
| 388 |
(* table C-7 *) |
| 389 |
| CMPTEQ (0wx16,0wx0a5) | CMPTLT (0wx16,0wx0a6) | CMPTLE (0wx16,0wx0a7) |
| 390 |
| CMPTUN (0wx16,0wx0a4) |
| 391 |
|
| 392 |
| CMPTEQSU(0wx16,0wx5a5) | CMPTLTSU(0wx16,0wx5a6) |CMPTLESU(0wx16,0wx5a7) |
| 393 |
| CMPTUNSU(0wx16,0wx5a4) |
| 394 |
|
| 395 |
| ADDS (0wx16,0wx080) | ADDT (0wx16,0wx0a0) |
| 396 |
| DIVS (0wx16,0wx083) | DIVT (0wx16,0wx0a3) |
| 397 |
| MULS (0wx16,0wx082) | MULT (0wx16,0wx0a2) |
| 398 |
| SUBS (0wx16,0wx081) | SUBT (0wx16,0wx0a1) |
| 399 |
|
| 400 |
datatype fcmove! = |
| 401 |
FCMOVEQ 0wx02a | FCMOVGE 0wx02d | FCMOVGT 0wx02f |
| 402 |
| FCMOVLE 0wx02e | FCMOVLT 0wx02c | FCMOVNE 0wx02b |
| 403 |
|
| 404 |
datatype foperateV! = (* table C-7 *) |
| 405 |
ADDSSUD 0wx5c0 | ADDSSU 0wx580 |
| 406 |
| ADDTSUD 0wx5e0 | ADDTSU 0wx5a0 |
| 407 |
| DIVSSUD 0wx5c3 | DIVSSU 0wx583 |
| 408 |
| DIVTSUD 0wx5e3 | DIVTSU 0wx5a3 |
| 409 |
| MULSSUD 0wx5c2 | MULSSU 0wx582 |
| 410 |
| MULTSUD 0wx5e2 | MULTSU 0wx5a2 |
| 411 |
| SUBSSUD 0wx5c1 | SUBSSU 0wx581 |
| 412 |
| SUBTSUD 0wx5e1 | SUBTSU 0wx5a1 |
| 413 |
|
| 414 |
datatype osf_user_palcode! = |
| 415 |
BPT 0x80 | BUGCHK 0x81 | CALLSYS 0x83 |
| 416 |
| GENTRAP 0xaa | IMB 0x86 | RDUNIQUE 0x9e | WRUNIQUE 0x9f |
| 417 |
|
| 418 |
type addressing_mode = CellsBasis.cell * operand |
| 419 |
|
| 420 |
end (* Instruction *) |
| 421 |
|
| 422 |
(* |
| 423 |
* Alpha has very simple instruction encoding formats. |
| 424 |
*) |
| 425 |
instruction formats 32 bits |
| 426 |
Memory{opc:6, ra:5, rb:GP 5, disp: signed 16} (* p3-9 *) |
| 427 |
(* derived from Memory *) |
| 428 |
| Split{le} = let val i = MLTreeEval.valueOf le |
| 429 |
val w = itow i |
| 430 |
val hi = w ~>> 0w16 |
| 431 |
val lo = w && 0w65535 |
| 432 |
in if lo < 0w32768 then (hi,lo) else (hi+0w1,lo-0w65536) |
| 433 |
end |
| 434 |
| High{le} = let val (hi,_) = Split{le=le} in hi end |
| 435 |
| Low{le} = let val (_,lo) = Split{le=le} in lo end |
| 436 |
| LoadStore{opc,ra,rb,disp} = |
| 437 |
let val disp = |
| 438 |
case disp of |
| 439 |
I.REGop rb => emit_GP rb |
| 440 |
| I.IMMop i => itow i |
| 441 |
| I.HILABop le => High{le=le} |
| 442 |
| I.LOLABop le => Low{le=le} |
| 443 |
| I.LABop le => itow(MLTreeEval.valueOf le) |
| 444 |
in Memory{opc,ra,rb,disp} |
| 445 |
end |
| 446 |
| ILoadStore{opc,r:GP,b,d} = LoadStore{opc,ra=r,rb=b,disp=d} |
| 447 |
| FLoadStore{opc,r:FP,b,d} = LoadStore{opc,ra=r,rb=b,disp=d} |
| 448 |
|
| 449 |
| Jump{opc:6=0wx1a,ra:GP 5,rb:GP 5,h:2,disp:int signed 14} (* table C-3 *) |
| 450 |
| Memory_fun{opc:6, ra:GP 5, rb:GP 5, func:16} (* p3-9 *) |
| 451 |
| Branch{opc:branch 6, ra:GP 5, disp:signed 21} (* p3-10 *) |
| 452 |
| Bsr{opc:6=0wx34, ra:GP 5, disp:signed 21} (* p3-10 *) |
| 453 |
| Fbranch{opc:fbranch 6, ra:FP 5, disp:signed 21} (* p3-10 *) |
| 454 |
(* p3-11 *) |
| 455 |
| Operate0{opc:6,ra:GP 5,rb:GP 5,sbz:13..15=0,_:1=0,func:5..11,rc:GP 5} |
| 456 |
(* p3-11 *) |
| 457 |
| Operate1{opc:6,ra:GP 5,lit:signed 13..20,_:1=1,func:5..11,rc:GP 5} |
| 458 |
| Operate{opc,ra,rb,func,rc} = |
| 459 |
(case rb of |
| 460 |
I.REGop rb => Operate0{opc,ra,rb,func,rc} |
| 461 |
| I.IMMop i => Operate1{opc,ra,lit=itow i,func,rc} |
| 462 |
| I.HILABop le => Operate1{opc,ra,lit=High{le=le},func,rc} |
| 463 |
| I.LOLABop le => Operate1{opc,ra,lit=Low{le=le},func,rc} |
| 464 |
| I.LABop le => Operate1{opc,ra,lit=itow(MLTreeEval.valueOf le),func,rc} |
| 465 |
) |
| 466 |
| Foperate{opc:6,fa:FP 5,fb:FP 5,func:5..15,fc:FP 5} |
| 467 |
| Funary{opc:6,fa:5=31,fb:FP 5,func:5..15,fc:FP 5} |
| 468 |
| Pal{opc:6=0,func:26} |
| 469 |
|
| 470 |
structure MC = |
| 471 |
struct |
| 472 |
(* compute displacement address *) |
| 473 |
fun disp lab = itow(Label.addrOf lab - !loc - 4) ~>> 0w2 |
| 474 |
val zeroR = Option.valOf(C.zeroReg CellsBasis.GP) |
| 475 |
end |
| 476 |
|
| 477 |
structure Assembly = |
| 478 |
struct |
| 479 |
fun isZero(I.LABop le) = MLTreeEval.valueOf le = 0 |
| 480 |
| isZero _ = false |
| 481 |
end |
| 482 |
|
| 483 |
(* |
| 484 |
* The main instruction set definition consists of the following: |
| 485 |
* 1) constructor-like declaration defines the view of the instruction, |
| 486 |
* 2) assembly directive in funny quotes `` '', |
| 487 |
* 3) machine encoding expression, |
| 488 |
* 4) delay slot directives etc (not necessary in this architecture) |
| 489 |
*) |
| 490 |
instruction |
| 491 |
|
| 492 |
(* Load/Store *) |
| 493 |
LDA of {r: $GP, b: $GP, d:operand} (* use of REGop is illegal *) |
| 494 |
asm: if isZero d andalso CellsBasis.sameCell(r,b) then () |
| 495 |
else (``lda\t<r>, <d>''; |
| 496 |
if CellsBasis.registerId b = 31 then () else ``(<b>)'' |
| 497 |
) |
| 498 |
mc: ILoadStore{opc=0w08,r,b,d} |
| 499 |
rtl: ``LDA'' |
| 500 |
|
| 501 |
| LDAH of {r: $GP, b: $GP, d:operand} (* use of REGop is illegal *) |
| 502 |
asm: (``ldah\t<r>, <d>''; |
| 503 |
if CellsBasis.registerId b = 31 then () else ``(<b>)'' |
| 504 |
) |
| 505 |
mc: ILoadStore{opc=0w09,r,b,d} |
| 506 |
rtl: ``LDAH'' |
| 507 |
|
| 508 |
| LOAD of {ldOp:load, r: $GP, b: $GP, d:operand, mem:Region.region} |
| 509 |
asm: ``<ldOp>\t<r>, <d>(<b>)<mem>'' |
| 510 |
mc: ILoadStore{opc=emit_load ldOp,r,b,d} |
| 511 |
rtl: ``<ldOp>'' |
| 512 |
latency: 1 |
| 513 |
|
| 514 |
| STORE of {stOp:store, r: $GP, b: $GP, d:operand, mem:Region.region} |
| 515 |
asm: ``<stOp>\t<r>, <d>(<b>)<mem>'' |
| 516 |
mc: ILoadStore{opc=emit_store stOp,r,b,d} |
| 517 |
rtl: ``<stOp>'' |
| 518 |
|
| 519 |
| FLOAD of {ldOp:fload, r: $FP, b: $GP, d:operand, mem:Region.region} |
| 520 |
asm: ``<ldOp>\t<r>, <d>(<b>)<mem>'' |
| 521 |
mc: FLoadStore{opc=emit_fload ldOp,r,b,d} |
| 522 |
rtl: ``<ldOp>'' |
| 523 |
latency: 1 |
| 524 |
|
| 525 |
| FSTORE of {stOp:fstore, r: $FP, b: $GP, d:operand, mem:Region.region} |
| 526 |
asm: ``<stOp>\t<r>, <d>(<b>)<mem>'' |
| 527 |
mc: FLoadStore{opc=emit_fstore stOp,r,b,d} |
| 528 |
rtl: ``<stOp>'' |
| 529 |
|
| 530 |
(* Control Instructions *) |
| 531 |
| JMPL of {r: $GP, b: $GP, d:int} * Label.label list |
| 532 |
asm: ``jmp\t<r>, (<b>)'' |
| 533 |
mc: Jump{h=0w0,ra=r,rb=b,disp=d} (* table C-3 *) |
| 534 |
rtl: ``JMPL'' |
| 535 |
|
| 536 |
| JSR of {r: $GP, b: $GP, d:int, |
| 537 |
defs: $cellset, uses: $cellset, cutsTo: Label.label list, |
| 538 |
mem:Region.region} |
| 539 |
asm: ``jsr\t<r>, (<b>)<mem><emit_defs(defs)><emit_uses(uses)><emit_cutsTo cutsTo>'' |
| 540 |
mc: Jump{h=0w1,ra=r,rb=b,disp=d} |
| 541 |
rtl: ``JSR'' |
| 542 |
|
| 543 |
| BSR of {r: $GP, lab: Label.label, |
| 544 |
defs: $cellset, uses: $cellset, cutsTo: Label.label list, |
| 545 |
mem:Region.region} |
| 546 |
asm: ``bsr\t<r>, <lab><mem><emit_defs(defs)><emit_uses(uses)><emit_cutsTo cutsTo>'' |
| 547 |
mc: Bsr{ra=r,disp=disp lab} |
| 548 |
rtl: ``BSR'' |
| 549 |
|
| 550 |
| RET of {r: $GP, b: $GP, d:int} |
| 551 |
asm: ``ret\t<r>, (<b>)'' |
| 552 |
mc: Jump{h=0w2,ra=r,rb=b,disp=d} |
| 553 |
rtl: ``RET'' |
| 554 |
|
| 555 |
| BRANCH of {b:branch, r: $GP, lab:Label.label} |
| 556 |
asm: ``<b>\t<r>, <lab>'' |
| 557 |
mc: Branch{opc=b,ra=r,disp=disp lab} |
| 558 |
rtl: ``<b>'' |
| 559 |
|
| 560 |
| FBRANCH of {b:fbranch, f: $FP, lab:Label.label} |
| 561 |
asm: ``<b>\t<f>, <lab>'' |
| 562 |
mc: Fbranch{opc=b,ra=f,disp=disp lab} |
| 563 |
rtl: ``<b>'' |
| 564 |
|
| 565 |
(* Integer Operate *) |
| 566 |
| OPERATE of {oper:operate, ra: $GP, rb:operand, rc: $GP} |
| 567 |
(* Pretty print ldgp differently *) |
| 568 |
asm: let fun disp() = ``<oper>\t<ra>, <rb>, <rc>'' |
| 569 |
in case (oper,CellsBasis.registerId ra,rb,CellsBasis.registerId rc) of |
| 570 |
(I.BIS,27,I.REGop rb,29) => |
| 571 |
if CellsBasis.registerId rb = 31 then ``ldgp\t$29, 0($27)'' |
| 572 |
else disp() |
| 573 |
| (I.BIS,26,I.REGop rb,29) => |
| 574 |
if CellsBasis.registerId rb = 31 then ``ldgp\t$29, 0($26)'' |
| 575 |
else disp() |
| 576 |
| _ => disp() |
| 577 |
end |
| 578 |
mc: let val (opc,func) = emit_operate oper |
| 579 |
in Operate{opc,func,ra,rb,rc} |
| 580 |
end |
| 581 |
rtl: ``<oper>'' |
| 582 |
|
| 583 |
| OPERATEV of {oper:operateV, ra: $GP, rb:operand, rc: $GP} |
| 584 |
asm: ``<oper>\t<ra>, <rb>, <rc>'' |
| 585 |
mc: let val (opc,func) = emit_operateV oper |
| 586 |
in Operate{opc,func,ra,rb,rc} |
| 587 |
end |
| 588 |
rtl: ``<oper>'' |
| 589 |
|
| 590 |
| CMOVE of {oper:cmove, ra: $GP, rb:operand, rc: $GP} |
| 591 |
asm: ``<oper>\t<ra>, <rb>, <rc>'' |
| 592 |
mc: Operate{opc=0wx11,func=emit_cmove oper,ra,rb,rc} |
| 593 |
rtl: ``<oper>'' |
| 594 |
|
| 595 |
| PSEUDOARITH of {oper: pseudo_op, ra: $GP, rb:operand, rc: $GP, |
| 596 |
tmps: $cellset} |
| 597 |
asm: ``<oper>\t<ra>, <rb>, <rc><emit_cellset("tmps",tmps)>'' |
| 598 |
rtl: ``PSEUDOARITH_<oper>'' |
| 599 |
|
| 600 |
(* Floating Point Unary Operation *) |
| 601 |
| FUNARY of {oper:funary, fb: $FP, fc: $FP} |
| 602 |
asm: ``<oper>\t<fb>, <fc>'' |
| 603 |
mc: let val (opc,func) = emit_funary oper |
| 604 |
in Funary{opc,func,fb,fc} |
| 605 |
end |
| 606 |
rtl: ``<oper>'' |
| 607 |
|
| 608 |
(* Floating Point Operate *) |
| 609 |
| FOPERATE of {oper:foperate, fa: $FP, fb: $FP, fc: $FP} |
| 610 |
asm: ``<oper>\t<fa>, <fb>, <fc>'' |
| 611 |
mc: let val (opc,func) = emit_foperate oper |
| 612 |
in Foperate{opc,func,fa,fb,fc} |
| 613 |
end |
| 614 |
rtl: ``<oper>'' |
| 615 |
|
| 616 |
(* Trapping versions of the above (what trap -- allen) ??? *) |
| 617 |
| FOPERATEV of {oper:foperateV, fa: $FP, fb: $FP, fc: $FP} |
| 618 |
asm: ``<oper>\t<fa>, <fb>, <fc>'' |
| 619 |
mc: Foperate{opc=0wx16,func=emit_foperateV oper,fa,fb,fc} |
| 620 |
rtl: ``<oper>'' |
| 621 |
|
| 622 |
| FCMOVE of {oper:fcmove, fa: $FP, fb: $FP, fc: $FP} |
| 623 |
asm: ``<oper>\t<fa>, <fb>, <fc>'' |
| 624 |
mc: Foperate{opc=0wx17,func=emit_fcmove oper,fa,fb,fc} |
| 625 |
rtl: ``<oper>'' |
| 626 |
|
| 627 |
(* Misc *) |
| 628 |
| TRAPB (* Trap barrier *) |
| 629 |
asm: ``trapb'' |
| 630 |
mc: Memory_fun{opc=0wx18,ra=zeroR,rb=zeroR,func=0wx0} |
| 631 |
rtl: ``TRAPB'' |
| 632 |
|
| 633 |
| CALL_PAL of {code:osf_user_palcode, def: $cellset, use: $cellset} |
| 634 |
asm: ``call_pal <code>'' |
| 635 |
mc: Pal{func=emit_osf_user_palcode code} |
| 636 |
rtl: ``CALL_PAL_<code>'' |
| 637 |
|
| 638 |
| SOURCE of {} |
| 639 |
asm: ``source'' |
| 640 |
mc: () |
| 641 |
|
| 642 |
| SINK of {} |
| 643 |
asm: ``sink'' |
| 644 |
mc: () |
| 645 |
|
| 646 |
| PHI of {} |
| 647 |
asm: ``phi'' |
| 648 |
mc: () |
| 649 |
|
| 650 |
structure SSA = |
| 651 |
struct |
| 652 |
fun operand(ty, I.REGop r) = T.REG(ty, r) |
| 653 |
| operand(ty, I.IMMop i) = T.LI(IntInf.fromInt i) |
| 654 |
| operand(ty, _) = error "operand" |
| 655 |
end |
| 656 |
|
| 657 |
end |