How do you use the getbits() function in the rest of the code?  The most
efficient implementation will depend on the usage.  For example, if you have
to loop through the array, handle that specifically.  If you have to access
compile-time-known bit addresses, make sure getbit is inlined and let the
compiler reduce it to a few instructions.

You might also try using 8-bit bytes rather than 16-bit words - your shift
sizes will be smaller which might improve the code size.

How about:

    unsigned char bits[8];
    const unsigned char masks[8] = { 0x01, 0x02, 0x04, 0x08, 0x10, 0x20,
0x40, 0x80};

    getbit(unsigned byte n) {            // Note - bits is global
        return (bits[n >> 3] & masks[n & 0x07])
    };

(Note that the returned value will be greater than 1 for most bits)


> Given the small amount of ram (128 bytes) in the x1101, I need to use
> bit arrays for a 64bit value.  Is there a good/best way to do this?
> I've done roughly the code below:
>
> unsigned int bits[4];   // 16bit words x 4 = 64bits
> getbit(bits, n) { return( (bits[n>>4] >> 15-(n&0xF)) & 0x1) ); }
>
> However, it's really quite ugly compared to just  " bits[n] ",
> I've also looked at the code generated, and it's quite bloated,
> and given the ROM of a 1101 (1K), I can't really afford that either,
> the shifting is not a single instruction on a MSP430.
>
> The bits[n] generates just 8 bytes of code.
> (bits[n>>4] >> 15-(n&0xF)) & 0x1)  generates 50 bytes
>
> My most recent idea is to use something similiar with somewhat
> less shifting, at least not the loop used above.
>
> unsigned char bits[16];
> getbit(bits, n) {
>   int bits4 = bits[n>>2];
>   switch (n & 0x3) {
>    case 11: bits4 >>= 1;
>    case 01: bits4 >>= 1;
>    case 10: bits4 >>= 1;
>    case 11: return bits4 & 1;
>   }}
>
> This generates 88 bytes...
>
> there must be a simple way to do this that I'm just overlooking.
> Perhaps some simple assembly code is the best approach?
>
> thanks,
> Kelly Murray
>
>
>
> -------------------------------------------------------
> This SF.Net email is sponsored by The 2004 JavaOne(SM) Conference
> Learn from the experts at JavaOne(SM), Sun's Worldwide Java Developer
> Conference, June 28 - July 1 at the Moscone Center in San Francisco, CA
> REGISTER AND SAVE! http://java.sun.com/javaone/sf Priority Code NWMGYKND
> _______________________________________________
> Mspgcc-users mailing list
> Mspgcc-users@lists.sourceforge.net
> https://lists.sourceforge.net/lists/listinfo/mspgcc-users
>
>
>



Reply via email to