We are running a survey to help us improve the experience for all of our members. If you see the survey appear, please take the time to tell us about your experience if you can.
Hello, I was browsing through older posts that deal with the painful issue of portability (http://www.keil.com/forum/docs/thread8109.asp). I was (and still am) a big advocate of programming as much as possible conforming to the C standard, and having a layered structure that allowed "plugging-in" other hardware. But I have come to change my mind recently. I am reading the "ARM system developer's guide" (excellent book by the way. I'm reading it because I want to port some C167 code to an ARM9 environment) in which chapter 5 discusses writing efficient C code for an ARM. The point is, and it is fairly demonstrated, that even common, innocent looking C code can either be efficient of very inefficient on an ARM depending on specific choices made, let alone another processor used! So, if we are talking about squeezing every clock cycle out of a microcontroller - I do not believe that portability without ultimately littering the code is possible!
Efficient programming is important. But when "every single cycle counts" you run a risk that the development cost will explode.
You may also fail to get the product to market early.
And you do not have any safety margin in case you got a late "gotcha", where the requirements suddenly got updated, or you found a little processor errata or a compliance test showed a failure to fulfull some regulations.
There is an old saying that the last 5% of the application can take 95% of the development time. The difference between writing a couple of critical loops in optimized assembler and of having to consider almost all of the application as timing critical represents a huge cost difference.
Another thing is the cost to develop the next generation product. With a bit of safety margin, you may be able to use the same hardware platform. On the other hand - with most of the software written for maintainability instead of maximum optimization, you may do quite drastic changes to the hardware and still be able to reuse a large amount of code.
The ability to select the optimum chip is very important to the final price of the product. Too much optimized code may mean that a significant amount of code has to be thrown away and recreated.
We have one product where a processor with 8kB flash and 1kB RAM is used and everything is written in assembler. We have another product with 256kB flash and 32kB RAM, and just about everything is written in C. The cost of the two processors are almost the same. The big difference: The larger processor was selected 24 months later and could not use a single line of code from the other product. A number of lines of code from the newer product has migrated to even more products, since the C code is more protable.
The cost of a product is not directly related to the clock frequency or the number of kB of flash/RAM, so portability, maintainability and developemtn time must be taken into consideration.
One nice thing with a not too heavilly optimized C program is that a project may start with two alternative processors. A brand new, very inexpensive chip with a high risk factor because of the possibility of delivery delays. And an older chip with a higher cost but similar functionality. The project can then strive for the new and dirt-cheap chip, but still have a backup plan where most of the code will be usable on the older chip in case that is the only way to get a product on the market within the required time frame.
Jack: This forum is not threaded, even if it for some reason allows people to place answers in the middle.
Please avoid that attempt and instead post at the bottom - since you use a lot of quotes, it really doesn't matter if there will be a number of posts in between your post and the one you are responding to.
Per, Thanks for your insight. By the way, I have another one for Jack:
Did you know that am ARM does not have divide instructions in hardware ? If you try to port code that heavily relies on divisions into an ARM (without modifications, such as converting divides into multiples), you are destined to be forced to use many calls to the compiler's C library. And that is going to hurt, not?
Did you know that am ARM does not have divide instructions in hardware ?
No, I haven't read the manual.
If you try to port code that heavily relies on divisions into an ARM (without modifications, such as converting divides into multiples), you are destined to be forced to use many calls to the compiler's C library. And that is going to hurt, not?
That depends whether you design 'by experience' or by research.
The intent was good but the feasibility study was inadequate.
Given that new posts are highlighted I don't see how that would offer any real benefit, but I'm willing to give it a try.
Jack, you wrote: "That depends whether you design 'by experience' or by research."
I was talking about software that was designed on a platform that has a certain design philosophy, then ported to another platform that behaves very differently. I don't fully understand how the above comment can reconcile this difficulty, because "redesigning" the code, as correctly mentioned already would merely serve as rewriting it (I personally agree with this statement - is strictly my opinion, I don't claim it to be an ultimate truth of course), so why not begin (almost) from scratch? Please clarify if you like.
... will design by a combination of the two.
If you design purely by experience you will, probably, be caught in a 'trap' or two.
If you design purely by research you will not have your project completed in a timely manner.
Erik
... instead post at the bottom ...
I am too late for the party, so as an aside, how does one "post at the bottom"?
When I reply, I reply to the post I am replying to (i.e., click the 'reply' button presented with that post). Where it appears is (apparently) beyond my control.