<?xml version="1.0" encoding="UTF-8"?>
<!-- generator="bbPress/1.0.2" -->
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom">
	<channel>
		<title>LeafLabs Garden &#187; Topic: Simple Maple-Arduino speed comparison reveals compiler bugs</title>
		<link>http://forums.leaflabs.com/topic.php?id=149</link>
		<description>A place to share, learn, and grow...</description>
		<language>en-US</language>
		<pubDate>Fri, 22 Jan 2016 00:13:44 +0000</pubDate>
		<generator>http://bbpress.org/?v=1.0.2</generator>
		<textInput>
			<title><![CDATA[Search]]></title>
			<description><![CDATA[Search all topics from these forums.]]></description>
			<name>q</name>
			<link>http://forums.leaflabs.com/search.php</link>
		</textInput>
		<atom:link href="http://forums.leaflabs.com/rss.php?topic=149" rel="self" type="application/rss+xml" />

		<item>
			<title>gbulmer on "Simple Maple-Arduino speed comparison reveals compiler bugs"</title>
			<link>http://forums.leaflabs.com/topic.php?id=149&amp;page=2#post-998</link>
			<pubDate>Sat, 04 Sep 2010 11:36:21 +0000</pubDate>
			<dc:creator>gbulmer</dc:creator>
			<guid isPermaLink="false">998@http://forums.leaflabs.com/</guid>
			<description>&#60;p&#62;Thanks for that. &#60;/p&#62;
&#60;p&#62;As an even less important question, has anyone played with the gcc -fmudflap options?&#60;/p&#62;
&#60;p&#62;From the gcc manual:&#60;/p&#62;
&#60;p&#62;-fmudflap -fmudflapth -fmudflapir&#60;br /&#62;
For front-ends that support it (C and C++), instrument all risky pointer/array&#60;br /&#62;
dereferencing operations, some standard library string/heap functions, and&#60;br /&#62;
some other associated constructs with range/validity tests. Modules so in-&#60;br /&#62;
strumented should be immune to buffer overflows, invalid heap use, and some&#60;br /&#62;
other classes of C/C++ programming errors. The instrumentation relies on a&#60;br /&#62;
separate runtime library (‘libmudflap’), which will be linked into a program&#60;br /&#62;
if ‘-fmudflap’ is given at link time. Run-time behavior of the instrumented&#60;br /&#62;
program is controlled by the MUDFLAP_OPTIONS environment variable. See env&#60;br /&#62;
MUDFLAP_OPTIONS=-help a.out for its options.&#60;br /&#62;
Use ‘-fmudflapth’ instead of ‘-fmudflap’ to compile and to link if your pro-&#60;br /&#62;
gram is multi-threaded. Use ‘-fmudflapir’, in addition to ‘-fmudflap’ or&#60;br /&#62;
‘-fmudflapth’, if instrumentation should ignore pointer reads. This produces&#60;br /&#62;
less instrumentation (and therefore faster execution) and still provides some&#60;br /&#62;
protection against outright memory corrupting writes, but allows erroneously&#60;br /&#62;
read data to propagate within a program. &#60;/p&#62;
&#60;p&#62;This seemed like a useful option, especially during development and debugging, but the library has to be available.
&#60;/p&#62;</description>
		</item>
		<item>
			<title>mbolivar on "Simple Maple-Arduino speed comparison reveals compiler bugs"</title>
			<link>http://forums.leaflabs.com/topic.php?id=149&amp;page=2#post-995</link>
			<pubDate>Sat, 04 Sep 2010 10:34:25 +0000</pubDate>
			<dc:creator>mbolivar</dc:creator>
			<guid isPermaLink="false">995@http://forums.leaflabs.com/</guid>
			<description>&#60;p&#62;leaflabsandy:&#60;/p&#62;
&#60;blockquote&#62;&#60;p&#62;
Reply: Change your &#34;member&#34; name to Key Master so other users can indentify you as&#60;br /&#62;
a leafblower.
&#60;/p&#62;&#60;/blockquote&#62;
&#60;p&#62;Done :)&#60;/p&#62;
&#60;blockquote&#62;&#60;p&#62;
Is your background in hardware or software or both?&#60;/p&#62;
&#60;p&#62;BTW ... Welcome.
&#60;/p&#62;&#60;/blockquote&#62;
&#60;p&#62;My background is in software and math.  And thanks for the welcome!&#60;/p&#62;
&#60;p&#62;gbulmer:&#60;/p&#62;
&#60;blockquote&#62;&#60;p&#62;
Welcome mbolivar, and thanks for the answer.&#60;/p&#62;
&#60;p&#62;Is there a reason why it is&#60;br /&#62;
-march=armv7-m&#60;br /&#62;
and not&#60;br /&#62;
-mcpu=cortex-m3 ?&#60;/p&#62;
&#60;p&#62;Just slightly curious, so don't spend any time on this unless you believe there is a problem building using -mcpu=cortex-m3.
&#60;/p&#62;&#60;/blockquote&#62;
&#60;p&#62;Thanks for your welcome as well!&#60;/p&#62;
&#60;p&#62;As to your question, if you look at GLOBAL_CFLAGS, you'll notice that we do actually use -mcpu=cortex-m3.  From the GCC manpage:&#60;/p&#62;
&#60;blockquote&#62;&#60;p&#62;
       -march=name&#60;br /&#62;
           This specifies the name of the target ARM architecture.  GCC uses&#60;br /&#62;
           this name to determine what kind of instructions it can emit when&#60;br /&#62;
           generating assembly code.  This option can be used in conjunction&#60;br /&#62;
           with or instead of the -mcpu= option.
&#60;/p&#62;&#60;/blockquote&#62;</description>
		</item>
		<item>
			<title>gbulmer on "Simple Maple-Arduino speed comparison reveals compiler bugs"</title>
			<link>http://forums.leaflabs.com/topic.php?id=149&amp;page=2#post-981</link>
			<pubDate>Fri, 03 Sep 2010 20:46:16 +0000</pubDate>
			<dc:creator>gbulmer</dc:creator>
			<guid isPermaLink="false">981@http://forums.leaflabs.com/</guid>
			<description>&#60;p&#62;Welcome mbolivar, and thanks for the answer.&#60;/p&#62;
&#60;p&#62;Is there a reason why it is&#60;br /&#62;
-march=armv7-m&#60;br /&#62;
and not&#60;br /&#62;
-mcpu=cortex-m3 ?&#60;/p&#62;
&#60;p&#62;Just slightly curious, so don't spend any time on this unless you believe there is a problem building using -mcpu=cortex-m3.
&#60;/p&#62;</description>
		</item>
		<item>
			<title>StephenFromNYC on "Simple Maple-Arduino speed comparison reveals compiler bugs"</title>
			<link>http://forums.leaflabs.com/topic.php?id=149&amp;page=2#post-975</link>
			<pubDate>Fri, 03 Sep 2010 08:42:01 +0000</pubDate>
			<dc:creator>StephenFromNYC</dc:creator>
			<guid isPermaLink="false">975@http://forums.leaflabs.com/</guid>
			<description>&#60;p&#62;September 3, 2010&#60;/p&#62;
&#60;p&#62;Hello-&#60;/p&#62;
&#60;p&#62;gbulmer, thanks for the explanation.  It makes complete sense that the value of &#60;code&#62;int counter1&#60;/code&#62; increments and eventually overflows to -3276X (I always forget the lower boundary value) BEFORE it is promoted to type &#60;code&#62;long&#60;/code&#62; and compared to &#60;code&#62;limit&#60;/code&#62;.&#60;/p&#62;
&#60;p&#62;Yes, floating point calculations are subject to &#34;rounding&#34; errors.  However, I feel it should not make a difference if a loop repeats 1000X or just 1X.  If the loop is empty I think it should be removed by the compiler.  Maybe the compiler authors have a reason for this feature.&#60;/p&#62;
&#60;p&#62;Perhaps it is a simple way to measure of the speed of variable promotion!  I am still surprised that in my sample code the empty loops using a limit of type float require more than 0 ms to execute.&#60;/p&#62;
&#60;p&#62;I just thought of those examples of &#34;bad&#34; code where a programmer crams a lot unreadable code into the &#34;test&#34; expression of a FOR loop.  Perhaps this is another reason to use just WHILE loops.&#60;/p&#62;
&#60;p&#62;&#60;a href=&#34;http://forums.leaflabs.com/topic.php?id=117#post-947&#34; rel=&#34;nofollow&#34;&#62;http://forums.leaflabs.com/topic.php?id=117#post-947&#60;/a&#62;&#60;/p&#62;
&#60;p&#62;I guess I just answered my own question about the execution times of empty loops.&#60;/p&#62;
&#60;p&#62;Thanks!&#60;/p&#62;
&#60;p&#62;Stephen from NYC
&#60;/p&#62;</description>
		</item>
		<item>
			<title>leaflabsandy on "Simple Maple-Arduino speed comparison reveals compiler bugs"</title>
			<link>http://forums.leaflabs.com/topic.php?id=149#post-973</link>
			<pubDate>Fri, 03 Sep 2010 07:30:41 +0000</pubDate>
			<dc:creator>leaflabsandy</dc:creator>
			<guid isPermaLink="false">973@http://forums.leaflabs.com/</guid>
			<description>&#60;p&#62;Quote: &#34;(Hello to everybody on the forums from a new member of the LeafLabs team!)&#34;&#60;/p&#62;
&#60;p&#62;Reply: Change your &#34;member&#34; name to Key Master so other users can indentify you as&#60;br /&#62;
a leafblower.&#60;/p&#62;
&#60;p&#62;Is your background in hardware or software or both?&#60;/p&#62;
&#60;p&#62;BTW ... Welcome.
&#60;/p&#62;</description>
		</item>
		<item>
			<title>mbolivar on "Simple Maple-Arduino speed comparison reveals compiler bugs"</title>
			<link>http://forums.leaflabs.com/topic.php?id=149#post-972</link>
			<pubDate>Fri, 03 Sep 2010 03:11:01 +0000</pubDate>
			<dc:creator>mbolivar</dc:creator>
			<guid isPermaLink="false">972@http://forums.leaflabs.com/</guid>
			<description>&#60;p&#62;(Hello to everybody on the forums from a new member of the LeafLabs team!)&#60;/p&#62;
&#60;blockquote&#62;&#60;p&#62;PS, Leaflabs: What optimisation flags does the Maple IDE hand to the compiler?
&#60;/p&#62;&#60;/blockquote&#62;
&#60;p&#62;Currently, we compile with the following optimization flags: -Os -march=armv7-m -ffunction-sections -fdata-sections&#60;/p&#62;
&#60;p&#62;We also use these flags for C++: -fno-rtti -fno-exceptions&#60;/p&#62;
&#60;p&#62;Compiler flags are not currently user-configurable from within the IDE, but if there's interest, we might fold that functionality in at some point.  If you're interested in experimenting with different flags right now, you might want to jump to using our Unix toolchain:&#60;br /&#62;
&#60;a href=&#34;http://leaflabs.com/docs/libmaple/unix-toolchain/&#34; rel=&#34;nofollow&#34;&#62;http://leaflabs.com/docs/libmaple/unix-toolchain/&#60;/a&#62;&#60;/p&#62;
&#60;p&#62;&#60;em&#62;Note that direct use of the Unix toolchain is &#60;strong&#62;OPTIONAL&#60;/strong&#62;, and requires that you know your way around a Unix shell / how to use make / how to program in C and C++ / etc.  If you're uncomfortable with any of these, we recommend you stick with the Maple IDE.&#60;/em&#62;&#60;/p&#62;
&#60;p&#62;Specifically, after you've made a fresh project (see:&#60;br /&#62;
&#60;a href=&#34;http://leaflabs.com/docs/libmaple/unix-toolchain/#startingyourown)&#34; rel=&#34;nofollow&#34;&#62;http://leaflabs.com/docs/libmaple/unix-toolchain/#startingyourown)&#60;/a&#62;&#60;br /&#62;
you can check out the Makefile variables &#60;code&#62;GLOBAL_CFLAGS&#60;/code&#62;, &#60;code&#62;GLOBAL_CXXFLAGS&#60;/code&#62;, and &#60;code&#62;LDFLAGS&#60;/code&#62;.&#60;/p&#62;
&#60;p&#62;Happy hacking!
&#60;/p&#62;</description>
		</item>
		<item>
			<title>gbulmer on "Simple Maple-Arduino speed comparison reveals compiler bugs"</title>
			<link>http://forums.leaflabs.com/topic.php?id=149#post-966</link>
			<pubDate>Thu, 02 Sep 2010 22:45:53 +0000</pubDate>
			<dc:creator>gbulmer</dc:creator>
			<guid isPermaLink="false">966@http://forums.leaflabs.com/</guid>
			<description>&#60;blockquote&#62;&#60;p&#62;
CarlO, when I was learning C I remember reading about variable type &#34;promotion&#34;. This concept is usually taught in the context of int vs float. In my code, when I changed the limit variable to type long I assumed the int counters would be promoted to float during compilation to type long. If this is not a bug in the compiler(s) I obviously do not understand some subtle property of variable promotion. Maybe I should find my old text and read it again!&#60;/p&#62;&#60;/blockquote&#62;
&#60;p&#62;C/C++ is very obedient, which can be surprising.&#60;/p&#62;
&#60;p&#62;When a variable is defined as &#60;code&#62;int counter0;&#60;/code&#62; it will take up exactly the amount of space the compiler for that processor uses. Unlike Java, an &#60;code&#62;int&#60;/code&#62; in C/C++ can vary in size on different processors.&#60;br /&#62;
It is 16bits (2 bytes) on ATmega (Arduino) and 32bits (4 bytes) on STM32F (Maple).&#60;/p&#62;
&#60;p&#62;C/C++ will always allocate the same amount of space for a data type on the same processor (its compiler allocated location address may 'wiggle about' in memory if you ask the compiler to put a variable on 4byte boundaries, but the space used for the variable won't change).&#60;/p&#62;
&#60;p&#62;Type promotion is sometimes used to describe how arithmetic expressions are evaluated, not how values are stored.&#60;br /&#62;
For example, when C/C++ does arithmetic, on an &#60;code&#62;int&#60;/code&#62; and a &#60;code&#62;long&#60;/code&#62;, if the &#60;code&#62;int&#60;/code&#62; in smaller, C/C++ will compile in machine instructions to convert the &#60;code&#62;int&#60;/code&#62; to a &#60;code&#62;long&#60;/code&#62;, and then do the arithmetic on two &#60;code&#62;long&#60;/code&#62;s. Comparing two numbers is treated as arithmetic.&#60;/p&#62;
&#60;p&#62;Hence the reason the for statement never exited was because the &#60;code&#62;int counter&#60;/code&#62; couldn't store a value bigger than an &#60;code&#62;int&#60;/code&#62; can hold, and on an ATmega (Arduino) it's only -32769 to +32767.&#60;/p&#62;
&#60;p&#62;So the &#60;code&#62;int&#60;/code&#62; &#60;em&#62;is&#60;/em&#62; promoted to a &#60;code&#62;long&#60;/code&#62; for the comparison, but it will only ever be a value in the range that an &#60;code&#62;int&#60;/code&#62; can hold, which on an ATmega is always less than 100000.&#60;/p&#62;
&#60;p&#62;I feel CarlO's explanation for not optimising an empty loop which uses float variables is plausible; the compiler can't calculate at compile time how may times the loop will execute, because float arithmetic is imprecise and subject to small errors, so it can't deduce the final values of the counter variables, so it can't remove the code.&#60;/p&#62;
&#60;p&#62;If you are concerned about not having an empty float-controlled for loop removed, try fiddling with the optimisation flags. There are a bunch of them, I usually use optimise for space (as small code fits in cache better, so ends up being quick), but there are a lot to choose from with the GCC compiler suite, one may be more aggresive, and take the code out. &#60;/p&#62;
&#60;p&#62;HTH&#60;/p&#62;
&#60;p&#62;PS, Leaflabs: What optimisation flags does the Maple IDE hand to the compiler?
&#60;/p&#62;</description>
		</item>
		<item>
			<title>StephenFromNYC on "Simple Maple-Arduino speed comparison reveals compiler bugs"</title>
			<link>http://forums.leaflabs.com/topic.php?id=149#post-952</link>
			<pubDate>Thu, 02 Sep 2010 08:56:30 +0000</pubDate>
			<dc:creator>StephenFromNYC</dc:creator>
			<guid isPermaLink="false">952@http://forums.leaflabs.com/</guid>
			<description>&#60;p&#62;September 2, 2010&#60;/p&#62;
&#60;p&#62;Hello,&#60;/p&#62;
&#60;p&#62;Thanks for all the replies to my bug/benchmark post.&#60;/p&#62;
&#60;p&#62;leaflabsandy, yes, based on the faster clock speed I was expecting to see the 72 MHz Maple run faster than a 16 MHz Arduino.  I was expecting a speedup of roughly 4.5X (=72/16).  I did the simple benchmarking to show myself that the Maple runs similar code faster.  Do you remember President Reagan quote regarding nuclear treaties &#34;Trust, but verify&#34;.  Note LeafLabs development team: using a Pentium III computer the Arduino compiles and loads the code faster than the Maple.&#60;/p&#62;
&#60;p&#62;In my post I chose the expression &#34;4X-5X&#34; because the speedup varies on the test.  The speedup is not always 4.5X.  It is occasionally less than 4X but occasionally greater than 5X.  It is possible I copied the results incorrectly, but the general trend is clear.  In one test which does not show the benefits of a 32- bit MCU the Arduino requires 4X-5X more time to execute similar code.&#60;/p&#62;
&#60;p&#62;gbulmer, thanks for your ideas.  When I said (at the end of my post) &#34;Note: I did not try to change the type of the 'counterN' variables from int to float or long.  I do not know if this will affect how the code is compiled&#34; I did not think it was the cause of the problem!&#60;/p&#62;
&#60;p&#62;CarlO, when I was learning C I remember reading about variable type &#34;promotion&#34;.  This concept is usually taught in the context of int vs float.  In my code, when I changed the limit variable to type long I assumed the int counters would be promoted to float during compilation to type long.  If this is not a bug in the compiler(s) I obviously do not understand some subtle property of variable promotion.  Maybe I should find my old text and read it again!&#60;/p&#62;
&#60;p&#62;Regardless of the type of the variable(s) used in a FOR loop, I assumed any empty loop would be optimized by the compiler.  Execution of all empty loops should be 0 milliseconds.  I forgot, does infinity times zero equal zero or does the product equal NaN (not a number)?  Does the NaN concept have any relevance to compilation of an empty loop?&#60;/p&#62;
&#60;p&#62;I do not have the time to contact the avr-gcc compiler project.  If you are a contributor to the avr-gcc forums and you think I have uncovered a bug please pass on the information.&#60;/p&#62;
&#60;p&#62;I wanted to share my observations, because the LeafLabs development team might be interested in sketches where the Maple behaves in surprising ways.&#60;/p&#62;
&#60;p&#62;Thanks!&#60;/p&#62;
&#60;p&#62;Stephen from NYC
&#60;/p&#62;</description>
		</item>
		<item>
			<title>gbulmer on "Simple Maple-Arduino speed comparison reveals compiler bugs"</title>
			<link>http://forums.leaflabs.com/topic.php?id=149#post-944</link>
			<pubDate>Wed, 01 Sep 2010 16:42:57 +0000</pubDate>
			<dc:creator>gbulmer</dc:creator>
			<guid isPermaLink="false">944@http://forums.leaflabs.com/</guid>
			<description>&#60;p&#62;ST have announced 120MHz STM32 parts:&#60;br /&#62;
&#60;a href=&#34;http://www.st.com/stonline/stappl/cms/press/news/year2010/t2477.htm&#34; rel=&#34;nofollow&#34;&#62;http://www.st.com/stonline/stappl/cms/press/news/year2010/t2477.htm&#60;/a&#62;&#60;/p&#62;
&#60;p&#62;If they migrate production of existing parts to the smaller process, overclocking may be more stable.&#60;/p&#62;
&#60;p&#62;The improvement comes from moving to a smaller scale process (90nm) which means faster transistors. To make up for the disparity between the processor and Flash, they have an even fancier prefetch mechanism than the existing STM32F's:&#60;/p&#62;
&#60;blockquote&#62;&#60;p&#62;To release the processor’s full 150 DMIPS performance at this frequency the accelerator implements an instruction pre-fetch queue and branch cache, enabling program execution from Flash at up to 120MHz with zero wait states.&#60;/p&#62;&#60;/blockquote&#62;
&#60;p&#62;I assume the key words are &#34;at up to&#34; 120MHz :-)&#60;/p&#62;
&#60;p&#62;Marketing, don't ya just love 'em?-)
&#60;/p&#62;</description>
		</item>
		<item>
			<title>gbulmer on "Simple Maple-Arduino speed comparison reveals compiler bugs"</title>
			<link>http://forums.leaflabs.com/topic.php?id=149#post-942</link>
			<pubDate>Wed, 01 Sep 2010 16:32:51 +0000</pubDate>
			<dc:creator>gbulmer</dc:creator>
			<guid isPermaLink="false">942@http://forums.leaflabs.com/</guid>
			<description>&#60;blockquote&#62;&#60;p&#62;&#34;- 72 MHz maximum frequency,1.25 DMIPS/MHz (Dhrystone 2.1)performance at 0 wait state memory access&#34;&#60;/p&#62;
&#60;/blockquote&#62;
&#60;p&#62;Yes, I think there is a bit of &#34;marketing spin&#34; creeping in here, but I don't think it is as bad as it might seem.&#60;/p&#62;
&#60;p&#62;There is a prefetch buffer which holds two blocks of 64-bits, 2x8 bytes, of instructions which is read in one read from Flash (Flash memory and the ICode instruction bus is 64-bits wide).&#60;br /&#62;
If the CPU were executing only 16-bit instructions (that is 4 instructions/block), in perfect conditions the processor wouldn't wait even if Flash had 3-wait states.&#60;br /&#62;
Of course, things are not perfect, but for straightline code, or small loops, it might get quite close.&#60;/p&#62;
&#60;p&#62;As you say, the &#34;1.25 DMIPS/MHz&#34; is true for internal RAM, and I believe is true for Flash when the STM32F runs at 24MHz, but that's where the &#34;marketing spin&#34; is misleading. It would be very helpful to have some 'typical' values for a suite of apps run at 48MHz and 72MHz. &#60;/p&#62;
&#60;p&#62;AFAIK, all the MCU manufacturers apply this same &#34;marketing spin&#34; when their processor runs faster than flash, not just ARM licensees, but others too.&#60;/p&#62;
&#60;p&#62;While on the subject of &#34;marketing spin&#34;, I noticed that the ADC only reaches 1M sample/second when the processor is clocked at 56MHz, and drops to a best case of roughly 850K samples/second at 72MHz. The disparity is because the ADC clock can't exceeed 14MHz, and it is derived from the system clock, divided down for the ADC by an integer value. &#60;/p&#62;
&#60;p&#62;To be fair, 850K samples/second, on each of two or three ADC's, is so much better than an Arduino's &#38;lt;10k samples/second, I am still extremly happy.
&#60;/p&#62;</description>
		</item>
		<item>
			<title>poslathian on "Simple Maple-Arduino speed comparison reveals compiler bugs"</title>
			<link>http://forums.leaflabs.com/topic.php?id=149#post-939</link>
			<pubDate>Wed, 01 Sep 2010 15:03:02 +0000</pubDate>
			<dc:creator>poslathian</dc:creator>
			<guid isPermaLink="false">939@http://forums.leaflabs.com/</guid>
			<description>&#60;p&#62;Bryan's post on the subject:&#60;br /&#62;
&#60;a href=&#34;http://forums.leaflabs.com/topic.php?id=31#post-114&#34; rel=&#34;nofollow&#34;&#62;http://forums.leaflabs.com/topic.php?id=31#post-114&#60;/a&#62;
&#60;/p&#62;</description>
		</item>
		<item>
			<title>poslathian on "Simple Maple-Arduino speed comparison reveals compiler bugs"</title>
			<link>http://forums.leaflabs.com/topic.php?id=149#post-938</link>
			<pubDate>Wed, 01 Sep 2010 15:02:34 +0000</pubDate>
			<dc:creator>poslathian</dc:creator>
			<guid isPermaLink="false">938@http://forums.leaflabs.com/</guid>
			<description>&#60;p&#62;Since were talking about performance. The stm32 on maple CAN be overclocked! Obviously, at your own peril! User reports and internal experiments suggest that the probability of brickage from stepping up to 120MHz is minimal, however the digital I/O and many of the peripheral start to get funky, square waves turn to sines, and some comm peripherals just stop functioning. You can overclock via setting the PLL multiplier to higher than 9, you can find where this happens in libmaple, probably in rcc.c
&#60;/p&#62;</description>
		</item>
		<item>
			<title>CarlO on "Simple Maple-Arduino speed comparison reveals compiler bugs"</title>
			<link>http://forums.leaflabs.com/topic.php?id=149#post-937</link>
			<pubDate>Wed, 01 Sep 2010 14:41:42 +0000</pubDate>
			<dc:creator>CarlO</dc:creator>
			<guid isPermaLink="false">937@http://forums.leaflabs.com/</guid>
			<description>&#60;p&#62;gbulmer,&#60;/p&#62;
&#60;p&#62;That's great info on the access time for Flash, thanks for doing the research on this.  I guess ST's claim of 1.25 DMIPS/MHz on the front page of the data sheet only applies to SRAM then?  Interesting that they hide this info in a footnote.  When I get some time I'll do some tests to see what the difference is in practical application terms.  I also discovered that the I/O ports are clocked or latched at a lower rate then the CPU core.&#60;/p&#62;
&#60;p&#62;&#34;– 72 MHz maximum frequency,1.25 DMIPS/MHz (Dhrystone 2.1)performance at 0 wait state memory access&#34;&#60;/p&#62;
&#60;p&#62;CarlO.
&#60;/p&#62;</description>
		</item>
		<item>
			<title>gbulmer on "Simple Maple-Arduino speed comparison reveals compiler bugs"</title>
			<link>http://forums.leaflabs.com/topic.php?id=149#post-934</link>
			<pubDate>Wed, 01 Sep 2010 13:27:32 +0000</pubDate>
			<dc:creator>gbulmer</dc:creator>
			<guid isPermaLink="false">934@http://forums.leaflabs.com/</guid>
			<description>&#60;p&#62;CarlO, I think llandy's calculation of 72MHz/16MHz - 4.5 gives an answer in a similar ball park to the relative speed of the Maple and Arduino on the cases where there is a nonzero time.&#60;/p&#62;
&#60;p&#62;The theory that the Maple I/O is making a significant difference could be tested by printing a singe character instead of&#60;br /&#62;
&#60;code&#62;SerialUSB.println(&#38;quot;Inner loop finished&#38;quot;);&#60;/code&#62; or its Arduino equivalent,&#60;br /&#62;
print one character:&#60;br /&#62;
&#60;code&#62;SerialUSB.print(&#38;quot;.&#38;quot;);&#60;/code&#62; or its Arduino equivalent.&#60;/p&#62;
&#60;p&#62;The serial output (USART) on the Aduino has one byte of buffering, so this should minimise any differences between the two systems, leaving mostly the difference in for loop speed.&#60;/p&#62;
&#60;p&#62;As CarlO wrote, comparing loops using 32-bit &#60;code&#62;long&#60;/code&#62; for limit and counters should show up a bigger performance difference than the clock speed alone would account for because the Maple's 32-bit Cortex-M3 (STM32F) can process 32 bit numbers in far fewer instructions than the Arduino's 8-bit ATmega can perform the same operation.&#60;/p&#62;
&#60;p&#62;I am actually impressed that the Arduino seems to be slightly faster than the clock speed difference might suggest on integer operations.&#60;/p&#62;
&#60;p&#62;The memeory access speed for flash and SRAM on the Maple's STM32F is different. According to document 13587.pdf (from st.com), section &#34;2.3.4 Embedded SRAM&#34; says:&#60;br /&#62;
Twenty Kbytes of embedded SRAM accessed (read/write) at CPU clock speed with 0 wait&#60;br /&#62;
states. &#60;/p&#62;
&#60;p&#62;Whereas document 13902.pdf (also from st.com), section &#34;2.3.3 Embedded Flash memory&#34;, page 53 says:&#60;br /&#62;
&#34;Note: 1 These options should be used in accordance with the Flash memory access time. The wait states represent the ratio of the SYSCLK (system clock) period to the Flash memory access time:&#60;br /&#62;
zero wait state, if 0 &#38;lt; SYSCLK &#38;lt;= 24 MHz&#60;br /&#62;
one wait state, if 24 MHz &#38;lt; SYSCLK &#38;lt;= 48 MHz&#60;br /&#62;
two wait states, if 48 MHz &#38;lt; SYSCLK &#38;lt;= 72 MHz&#34;&#60;br /&#62;
The impact of the wait states is reduced by a prefetch buffer, page 52 says:&#60;br /&#62;
&#34;Prefetch buffer (2 x 64-bit blocks): it is enabled after reset; a whole block can be&#60;br /&#62;
replaced with a single read from the Flash memory as the size of the block matches the&#60;br /&#62;
bandwidth of the Flash memory. Thanks to the prefetch buffer, faster CPU execution is&#60;br /&#62;
possible as the CPU fetches one word at a time with the next word readily available in&#60;br /&#62;
the prefetch buffer&#34;&#60;/p&#62;
&#60;p&#62;So Flash memory may be slower than SRAM, but the estimation of how different is not easy because it depends on the dynamic flow of the program.&#60;/p&#62;
&#60;p&#62;I don't know if your theory is correct, but think your explanation for the compilers not optimising the for loops is a good one. I'm happy to buy it. As you say the compiler may know that it can't exactly predict how floating arithmetic works in these situations, and takes the conservative (and guaranteed to be correct) approach of compiling the code as written.&#60;/p&#62;
&#60;p&#62;I believe the test shows no evidence of *bugs* in the compiler. I don't believe it is a bug to fail to optimise away code in a program. IMHO, a compiler should always strive to geneate code gives the correct answer (i.e. what the code says), and secondarly try to optimise that code.&#60;/p&#62;
&#60;p&#62;I think it would be helpful if the compiler did print a warning to the effect that 'comparing int counter0 to long limit might give unexpected results'. Maybe that warning is off by default as many programs would provoke it.&#60;br /&#62;
There are a few gcc warnings which might help:&#60;br /&#62;
-Wstrict-overflow&#60;br /&#62;
-Wfloat-equal&#60;br /&#62;
-Wunsafe-loop-optimizations&#60;br /&#62;
-Wtype-limits&#60;/p&#62;
&#60;p&#62;I think it would be  helpful if every set of tests (e.g. using float or long) used the same set of values for limit so that it is easier to compare results across tests.&#60;/p&#62;
&#60;p&#62;HTH
&#60;/p&#62;</description>
		</item>
		<item>
			<title>poslathian on "Simple Maple-Arduino speed comparison reveals compiler bugs"</title>
			<link>http://forums.leaflabs.com/topic.php?id=149#post-933</link>
			<pubDate>Wed, 01 Sep 2010 13:18:35 +0000</pubDate>
			<dc:creator>poslathian</dc:creator>
			<guid isPermaLink="false">933@http://forums.leaflabs.com/</guid>
			<description>&#60;p&#62;cool! &#60;/p&#62;
&#60;p&#62;In terms of performance, we havnt really scratched the surface. Sure the clock is faster. But the real win comes from DMA, using fast interrupts, and dedicated communication peripheral (i2c,spi, etc). I cant wait to start benchmarking that stuff. Incidentally weve finally started on bringing up the DMA, which allows you to do fancy stuff like copy memory from location A to B in the &#34;background&#34; with wasting cycles (except the cycles needed to dispatch the copy operation through the DMA). This works really nicely for communication, where you can throw a bunch of data into a buffer and the use the DMA to squirrel it all out of a uart/i2c/spi port without actually spending cycles to do that. If anyone has some free cycles, it would be a great help to do some advanced play using those features! &#60;/p&#62;
&#60;p&#62;*warning* i2c peripheral is nasty complicated, but the dma is simple.
&#60;/p&#62;</description>
		</item>

	</channel>
</rss>
