From mboxrd@z Thu Jan 1 00:00:00 1970 X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: 102b75,2fe965218100c2bd,start X-Google-Attributes: gid102b75,public X-Google-Thread: f678f,2fe965218100c2bd,start X-Google-Attributes: gidf678f,public X-Google-ArrivalTime: 1994-03-02 18:53:56 PST Xref: gmd.de comp.arch:19804 comp.unix.osf.misc:1043 Newsgroups: comp.arch,comp.unix.osf.misc Path: gmd.de!newsserver.jvnc.net!darwin.sura.net!howland.reston.ans.net!vixen.cso.uiuc.edu!sdd.hp.com!think.com!spdcc!das-news.harvard.edu!das-news!tlb From: tlb@chardonnay.harvard.edu (Trevor Blackwell) Subject: Strange behaviour of Alpha Floating Point Load/Stores wrt cache misses Message-ID: Sender: usenet@das.harvard.edu Organization: Harvard University Date: Thu, 3 Mar 1994 02:53:56 GMT This one really baffles me. I measure very different performance of load and store instructions, between when I do a LDQ/STQ (load/store quadword = 8 bytes), and LDT/SDT (load/store IEEE FP double = 8 bytes), especially when cache misses are involved. These are the same size memory transfers, done in the same order, and I would have expected them to perform identically. The architecture manual claims that LDT/SDT do not do any FP work such as normalizing; they just transfer bits between the register and memory. [This came up because I was interested in the register save/restore code involved in a context switch, and whether it could be optimized by interleaving loads & stores to different cache lines, given the Alpha's load/store buffers. It may look wierd because I messed around with the order of load/saves to try and hit the right cache lines early]. Look at the attached assembler file below (adapted from the AweSime threads library). It loads and saves the registers (I changed it to use registers $31 & $f1 for everything, so I could call it normally) I called it from code that makes almost no (like, 1, contrived not to alias with anything) memory references between calls, except every fifth time it loads a 8K-long vector, to flush the cache. Something like: for (i=0; i<100; i++) { if (i%5==0) flushData(); timing[i] = magicSwitchTo1(area1,area2); } If the #if is 1, (so it does integer and FP transfers) then a typical timing sequence (times in clock cycles, timing with RPCC) is: ... Time = 83 (with flush) Time = 54 (no flush) Time = 66 (no flush) Time = 66 (no flush) Time = 66 (no flush) Time = 83 (with flush) Time = 54 (no flush) Time = 66 (no flush) Time = 66 (no flush) Time = 66 (no flush) ... If the #if is 0, (integer transfers only) then I get: ... Time = 50 (with flush) Time = 50 (no flush) Time = 61 (no flush) Time = 61 (no flush) Time = 61 (no flush) Time = 50 (with flush) Time = 50 (no flush) Time = 61 (no flush) Time = 61 (no flush) Time = 61 (no flush) ... This is totally repeatable. Email me for my complete code if you want to play with it. This makes absolutely no sense at all to me. Does anyone know why this might be happening? In particular: - Why are FP and integer different? - Why do I get SHORTER times with integer only AFTER flushing the cache? - Why is the second time after flushing the cache short, but the third time longer? Is this because of something about hits on dirty (writeback-pending) processor cache lines? I note that reordering the first few instructions makes a big difference (as you might expect - you win if you can get both memory load registers reading in cache lines simultaneously). I got the total time down from 120 clocks to 83 clocks in the mixed integer/FP case by putting the right things in the first 5 instructions. I am pretty sure I am controlling for all extraneous factors. My measurement code runs 100 times, only referencing an array where it sticks the running time. All the code fits in the I-cache. I'm not getting interrupts (the whole measurement takes about 10 uS, and the effect of interrupts is real obvious when they do occur.) The whole shebang (code & data) fits in the off-chip B-cache, and my flush vector should not flush the register load/store areas out of there. Any explanations? [Whatever happened to nice, predictable CPUs, like the 6502, where you could count your clock cycles yourself?] -------------------------------------------------------------------------------- /* save registers from $16, load from $17 */ magicSwitchTo1: .frame $30,0,$26,0 .prologue 0 rpcc $3 stq $31,32($16) stq $31,104($16) ldq $31,32($17) ldq $31,152($17) stq $31,40($16) ldq $31,40($17) stq $31,48($16) ldq $31,48($17) stq $31,56($16) ldq $31,56($17) stq $31,64($16) ldq $31,64($17) stq $31,72($16) ldq $31,72($17) stq $31,80($16) ldq $31,80($17) stq $31,88($16) ldq $31,88($17) stq $31,96($16) ldq $31,96($17) #if 1 ldq $31,104($17) stq $31,112($16) ldq $31,112($17) stq $31,120($16) ldq $31,120($17) stq $31,128($16) ldq $31,128($17) stq $31,136($16) ldq $31,136($17) stq $31,144($16) ldq $31,144($17) stq $31,152($16) #else ldt $f1,104($17) stt $f1,112($16) ldt $f1,112($17) stt $f1,120($16) ldt $f1,120($17) stt $f1,128($16) ldt $f1,128($17) stt $f1,136($16) ldt $f1,136($17) stt $f1,144($16) ldt $f1,144($17) stt $f1,152($16) #endif stq $31,24($16) ldq $31,24($17) stq $31,0($16) stq $31,8($16) ldq $31,8($17) ldq $31,0($17) rpcc $1 sll $3,32,$2 addq $3,$2,$3 srl $3,32,$3 sll $1,32,$2 addq $1,$2,$1 srl $1,32,$1 subq $1,$3,$0 ret $31,($26),1 -- -- Trevor Blackwell tlb@das.harvard.edu (617) 495-8912 (info and words of wit in my .plan) Disavowal: My opinions.