From tom_usenet at optusnet.com.au Mon May 19 07:01:34 2014 From: tom_usenet at optusnet.com.au (Tom Evans) Date: Mon, 19 May 2014 17:01:34 +1000 Subject: [coldfire-gnu-discuss] GCC Clobbering Branch Predict Bit in CF3 Cores Message-ID: <5379AC4E.3010603@optusnet.com.au> Is this mailing list still alive? The last archived post was in 2011. The last post was in Oct 2012, but it isn't in the archive (yet)?? Has this list been replaced by this "community"? http://communities.mentor.com/mgcx/community/embedded_software/sourcery_codebench?view=discussions I've searched for this apparent bug on gcc.gnu.org/bugzilla, but didn't find anything. I'm using: $ m68k-elf-gcc --version m68k-elf-gcc.exe (Sourcery G++ Lite 4.3-208) 4.3.3 Copyright (C) 2008 Free Software Foundation, Inc. The command line is: m68k-elf-gcc -MD -MF adl3.d0 -gdwarf-2 -mcpu=5329 -Wall -std=c99 -g -Os ... Note the "-mcpu=5329" line. A small snippet of source code: #define cd_BUS_OFF 0x2000 #define cd_BUS_OFF 0x1000 #define cd_OVERRUN 0x0008 else if (cc->status & cd_BUS_OFF) { 40109020: 202a 003c movel %a2@(60),%d0 40109024: 0800 000d btst #13,%d0 40109028: 6710 beqs 4010903a (other code) } else if (cc->status & cd_BUS_RWARN) { 4010903a: 0800 000c btst #12,%d0 4010903e: 6604 bnes 40109044 } else if (cc->status & cd_OVERRUN) { 40109040: 44c0 movew %d0,%ccr 40109042: 6a02 bpls 40109046 Note the weird word-saving trick in the last compare? It copies the data to the CCR and then tests the "N" bit. It only seems to do this trick for the "N" and "Z" bits (bits 2 and 3). it should be able to do it for "C" and "V" (0 and 1), but I haven't seen any code doing this. I've also seen code like: 4012193e: 44c2 movew %d2,%ccr 40121940: 57c0 seq %d0 40121942: 44c2 movew %d2,%ccr 40121944: 5bc1 smi %d1 What's the problem? Bit 7 of the CCR is: Branch prediction (Version 3 only). Alters the static prediction algorithm used by the branch acceleration logic in the instruction fetch pipeline on forward conditional branches. Refer to a V3 core or device user?s manual for further information on this bit. So the use of the "movew %d0,%ccr" instruction is changing the CPU's branch prediction randomly. It shouldn't be doing that. Tom From david at westcontrol.com Mon May 19 14:49:45 2014 From: david at westcontrol.com (David Brown) Date: Mon, 19 May 2014 16:49:45 +0200 Subject: [coldfire-gnu-discuss] GCC Clobbering Branch Predict Bit in CF3 Cores In-Reply-To: <5379AC4E.3010603@optusnet.com.au> References: <5379AC4E.3010603@optusnet.com.au> Message-ID: <537A1A09.7070608@westcontrol.com> On 19/05/14 09:01, Tom Evans wrote: > Is this mailing list still alive? The last archived post was in 2011. > The last post was in Oct 2012, but it isn't in the archive (yet)?? > > Has this list been replaced by this "community"? > > http://communities.mentor.com/mgcx/community/embedded_software/sourcery_codebench?view=discussions > This list still works - I got your post - but I doubt if there are many people actively following it. There are not many people using the Coldfire these days - it's sad, since it is such a nice cpu core, but economics have made ARM dominant. CodeSourcery have kept these mailing lists open, but I think most users will use the web-based forums, so it is worth posting there too. (I only ever used the Coldfire v2 cores, so I can't help you on your question.) David > > > I've searched for this apparent bug on gcc.gnu.org/bugzilla, but didn't > find anything. > > I'm using: > > $ m68k-elf-gcc --version > m68k-elf-gcc.exe (Sourcery G++ Lite 4.3-208) 4.3.3 > Copyright (C) 2008 Free Software Foundation, Inc. > > The command line is: > > m68k-elf-gcc -MD -MF adl3.d0 -gdwarf-2 -mcpu=5329 -Wall -std=c99 -g -Os > ... > > Note the "-mcpu=5329" line. > > A small snippet of source code: > > #define cd_BUS_OFF 0x2000 > #define cd_BUS_OFF 0x1000 > #define cd_OVERRUN 0x0008 > > else if (cc->status & cd_BUS_OFF) { > 40109020: 202a 003c movel %a2@(60),%d0 > 40109024: 0800 000d btst #13,%d0 > 40109028: 6710 beqs 4010903a > (other code) > } else if (cc->status & cd_BUS_RWARN) { > 4010903a: 0800 000c btst #12,%d0 > 4010903e: 6604 bnes 40109044 > } else if (cc->status & cd_OVERRUN) { > 40109040: 44c0 movew %d0,%ccr > 40109042: 6a02 bpls 40109046 > > Note the weird word-saving trick in the last compare? It copies the data > to the CCR and then tests the "N" bit. > > It only seems to do this trick for the "N" and "Z" bits (bits 2 and 3). > it should be able to do it for "C" and "V" (0 and 1), but I haven't seen > any code doing this. I've also seen code like: > > 4012193e: 44c2 movew %d2,%ccr > 40121940: 57c0 seq %d0 > 40121942: 44c2 movew %d2,%ccr > 40121944: 5bc1 smi %d1 > > What's the problem? Bit 7 of the CCR is: > > Branch prediction (Version 3 only). Alters the static > prediction algorithm used by the branch acceleration > logic in the instruction fetch pipeline on forward > conditional branches. Refer to a V3 core or device > user?s manual for further information on this bit. > > So the use of the "movew %d0,%ccr" instruction is changing the CPU's > branch prediction randomly. It shouldn't be doing that. > > Tom > _______________________________________________ > coldfire-gnu-discuss mailing list > coldfire-gnu-discuss at codesourcery.com > http://sourcerytools.com/cgi-bin/mailman/listinfo/coldfire-gnu-discuss From list_ob at gmx.net Wed May 21 19:31:30 2014 From: list_ob at gmx.net (Oliver Betz) Date: Wed, 21 May 2014 21:31:30 +0200 Subject: [coldfire-gnu-discuss] GCC Clobbering Branch Predict Bit in CF3 Cores In-Reply-To: <537A1A09.7070608@westcontrol.com> References: <5379AC4E.3010603@optusnet.com.au>, <537A1A09.7070608@westcontrol.com> Message-ID: <537CFF12.6567.22CD7A99@list_ob.gmx.net> David Brown wrote: > This list still works - I got your post - but I doubt if there are many > people actively following it. There are not many people using the > Coldfire these days - it's sad, since it is such a nice cpu core, but correct. > economics have made ARM dominant. CodeSourcery have kept these mailing you get really nice ARM Cortex derivatives with very advanced peripherals these days at a rather competitive price. Of course, it lacks the 68000 (PDP-11) smell, but who cares? > lists open, but I think most users will use the web-based forums, so it > is worth posting there too. > > (I only ever used the Coldfire v2 cores, so I can't help you on your > question.) I also used only the V2 until a "proof of concept" state, and if I ever had to re-animate this product, I used some ARM Cortex flavour. Oliver