[chbot] Any ARM savvy people?

Charles Manning cdhmanning at gmail.com
Tue Oct 11 22:26:30 BST 2016


People coming from 8-bitters will often think they are saving space/speed
etc by using 8-bit or 16-bit values as counters, flags etc.

Don't do that. It costs more (in terms of both space AND execution time) to
use 8-bit and 16-bit values than to use 32-bit values.


The reason for this is that ARM does 32 bit calculations. If you ask for
8-bit semantics then the operation must be truncated to match 8-bit
semantics.  (therefore more code, more instruction execution time...)

On Wed, Oct 12, 2016 at 10:16 AM, Robin Gilks <robin at gilks.org> wrote:

>
> > Hi Robin
> >
> > I've done lots of work with ARM (probably coming up 20 years now). I've
> > never seem something like that. Nor does it raise any aha! flags. ARM is
> > generally a very well behaved 32 bit architecture.
> >
> > arm gcc is also generally a very good compiler with very few issues. All
> > the phone sw in an iphone or android is built with it.
> >
> > If you're still stuck, feel free to send more specific questions my way.
> >
> > First things first... In general packing is not a good idea for two
> > reasons:
> >
> > 1) Less people do packing therefore more likely to expose "interesting"
> > behaviour.
> > 2) Packing very seldom saves space.
> >
> > But that's probably not your problem...
> >
> > Start off by building with the following flags
> > -Wall  all warnings
> > -Wextra even more warnings
> > -Werror   make all warnings into errors
> > -O0     No optimisation for now.
> >
> > In general those will pull up any programmer daftness. Saved my bacon
> many
> > times :-).
> >
> > -- Charles
> >
>
> Found it!!
>
> Wall and Werror nailed it.
>
> Immediately after loading the data from external Flash I was doing a CRC
> of it to check its integrity. Simple enough, it looks like this:
>
>     crc = CRC_CCITT_INIT_VAL;
>     p = (uint8_t *)RegPointer;
>     for (i = 0; i < sizeof(RegisterFile); i++)
>        crc = updcrc_ccitt(*p, crc);
>
> Trouble is, when you declare 'i' like this
> uint8_t i;
>
> its not obvious that the "i < sizeof(RegisterFile)" clause is always true
> when the data size is > 256 due to the limitation of the size of 'i'.
> Quite rightly the compiler made that condition always true by putting in
> an infinite loop!!
>
> So easy to miss a declaration half a page away! Now I know to check the
> manipulations to all my references to the config data are not restricted
> to 8 bits and to keep the extra warning flags in the Makefile!!
>
> --
> Robin Gilks
>
>
>
>
> _______________________________________________
> Chchrobotics mailing list Chchrobotics at lists.linuxnut.co.nz
> http://lists.ourshack.com/mailman/listinfo/chchrobotics
> Mail Archives: http://lists.ourshack.com/pipermail/chchrobotics/
> Meetings usually 3rd Monday each month. See http://kiwibots.org for
> venue, directions and dates.
> When replying, please edit your Subject line to reflect new subjects.
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.ourshack.com/pipermail/chchrobotics/attachments/20161012/733deb1a/attachment-0001.html>


More information about the Chchrobotics mailing list