From mboxrd@z Thu Jan 1 00:00:00 1970 Message-ID: <19981220234322A.goto@statabo.rim.or.jp> Date: Sun, 20 Dec 1998 23:43:22 +0900 From: Kazushige Goto Subject: how to optimize dgemm? No.4 In-Reply-To: <19981219000636T.goto@statabo.rim.or.jp> This is a 4th part document of DGEMM. 6. Alpha assembler instruction Alpha is a load-store architecture, so instructions are pretty simple.   load(ldt) -> multiply(mult) -> add(addt) -> store(stt)                               (simplify of matrix-matrix multiply) (a) registers Alpha has 32 integer($0, $1, ... , $31) and 32 floating point registers($f0, $f1, ..., $f31). All of registers are available architecturaly. But there are some limitations on Linux or Digital UNIX. Integer Registers     $0 - $8, $22 - $25, $28 : Free, $0 is a return value     $9 - $15 : need to be saved if you use     $16 - $21 : Free, but used as argument value     $26 : return address     $27 : entry address but you may use.     $29 : Global Pointer     $30 : Stack Pointer     $31 : Zero register. Floating point Registers     $f0,$f1,$f10-$f15,$f22-$f30 : Free, $f0 is a return value     $f2 - $f9 : need to be saved if you use     $f16 - $f21 : Free, but used as argument value     $f31 : Zero register. (b) load instruction  example                                   Correspond to C source     ldt $f0, 0($1) # $f0 = *($1)     ldt $f1, 8($1) # $f1 = *($1 + 1)     ldt $f2, 16($1) # $f2 = *($1 + 2) This mean, $1 is a base address, and 0, 8, 16 are offset from $1, and load to $f0, $f1, $f2 from memory. Two "ldt" instruction can issue in one clock. Therefore, this example takes 2 clocks, but we do not know how long it takes until $f0 - $f2 are available.       data in 1st level cache : 2 clocks       data in 2nd level cache : 8 clocks       data in 3rd level cache : 27 clocks(21164A 600MHz, PC164LX)       data in main memory : 134 clocks(21164A 600MHz, PC164LX)       Page fault/DTB miss : ??? So, we must issue load instruction in advance(8 clocks or more) if we want to use 2nd cache enough without stall. (b) multiply and add instruction 21164 can issue mutliply and add instruction on one clock except for resource conflicts.       /* 1 clock */       mult $f0, $f1, $f2 # $f2 = $f0 * $f1       addt $f3, $f4, $f5 # $f5 = $f3 + $f4 But it takes 4 clocks until $f2 and $f5 are available(latency). So, we must put other useful instructions. For example,       /* 1 clock */       mult $f0, $f1, $f2 # $f2 = $f0 * $f1       addt $f3, $f4, $f5 # $f5 = $f3 + $f4       /* 1 clock */       mult $f6, $f7, $f8 # $f8 = $f6 * $f7       addt $f9, $f10, $f11 # $f11 = $f9 + $f10       /* 1 clock */       mult $f12, $f13, $f14 # $f14 = $f12 * $f13       addt $f15, $f16, $f17 # $f17 = $f15 + $f16       /* 1 clock */       mult $f18, $f19, $f20 # $f20 = $f18 * $f19       addt $f21, $f22, $f23 # $f23 = $f21 + $f22       $f2 and $f5 are available at last.        mult $f2, $f5, $f24 # $f24 = $f2 * $f5 There are some examples about mutiply and add instructions. ex.1       /* 5 clocks, because $f2 is conflicted */       mult $f0, $f1, $f2 # $f2 = $f0 * $f1       addt $f2, $f4, $f5 # $f5 = $f2 + $f4 ex.2       /* 1 clock if $f0 and $f1 are available */       mult $f0, $f1, $f2 # $f2 = $f0 * $f1       addt $f0, $f1, $f3 # $f3 = $f0 + $f1 ex.3       /* 1 clock, I use a lot of this case in gemm routine */       mult $f0, $f1, $f2 # $f2 = $f0 * $f1       addt $f0, $f1, $f0 # $f0 = $f0 + $f1 ex.4       /* 2 clocks */       mult $f0, $f1, $f2 # $f2 = $f0 * $f1       mult $f0, $f1, $f3 # $f3 = $f0 * $f1 (c) store instruction Store instrucion is almost same as load instruction, but can issue only one instruction in one clock. 21164 can not issue load and store instructions simultaneously. (d) slot 21164 simultaneously issues instructions with a "slot" which consist of 2-integerinstruction(includes load/store instructions) and 2-floating point operation unless any resource conflicts. The combination of inter instruction is pretty flexible, but one of floating point instruction is limited(see above). ex.1       /* 1 clock */       mult $f0, $f1, $f2 # $f2 = $f0 * $f1       ldt $f0, 0($1)       addt $f3, $f4, $f5 # $f5 = $f3 + $f4       addq $1, 8, $1 ex.2       /* 1 clock */       mult $f0, $f1, $f2 # $f2 = $f0 * $f1       ldt $f0, 0($1)       addt $f3, $f4, $f5 # $f5 = $f3 + $f4       ldt $f3, 8($1) ex.3       /* 1 clock */       mult $f0, $f1, $f2 # $f2 = $f0 * $f1       addt $f3, $f4, $f5 # $f5 = $f3 + $f4       ldt $f0, 0($1)       ldt $f3, 8($1) ex.4       /* 3 clocks or more over */       ldt $f0, 0($1)       mult $f0, $f1, $f2 # $f2 = $f0 * $f1       addt $f3, $f4, $f5 # $f5 = $f3 + $f4       ldt $f3, 8($1) ex.5 /* 2 clocks, because can not issue load and tore instrucions simultaneously */       mult $f0, $f1, $f2 # $f2 = $f0 * $f1       ldt $f0, 0($1)       addt $f3, $f4, $f5 # $f5 = $f3 + $f4       stt $f6, 8($1) ex.6       /* 2 clocks, because can not issue 2-store instrucions simultaneously */       mult $f0, $f1, $f2 # $f2 = $f0 * $f1       stt $f4, 0($1)       addt $f3, $f4, $f5 # $f5 = $f3 + $f4       stt $f6, 8($1) Continue to No. 5 Thanks,   goto@statabo.rim.or.jp