Hi all I have the feeling that the msp430-gcc has a bug in its optimization step when it comes to shift operations on uint32_t. If I write
uint32_t tmp = 0x12345678; tmp >>= 18; if(tmp == 0) { call Leds.led0Toggle(); } The Led toggles (which it should not to my understanding). The problem does not occur if: - tmp is not defined in the local scope of the function - tmp is defined volatile - the shift result is assigned to another variable, e.g. the following is fine: uint32_t tmp = 0x12345678; uint32_t tmp2 = tmp >> 18; // now, tmp2 != 0 For shifts (>>) of 0..16, everything works fine. For shifts (>>) 17..31, the result is zero in the above case. In fact, the compiler does not emit any code to determine the result of the shift, but already decides at compile time that the result is zero, even if the value to be shifted is unknown. E.g. the following code toggles Led0. event void Timer.fired() { uint32_t tmp = call Random.rand32(); // unknown value at compile time if(tmp < 0x100000) { call Leds.led2Toggle(); // don't indicate false alarms } tmp >>= 18; // or: tmp = tmp >> 18; if(0 == tmp) { call Leds.led0Toggle(); } } However, if I write the following, everything is OK again. (The following does not blink Led 0.) event void Timer.fired() { uint32_t tmp = call Random.rand32(); // unknown value at compile time if(tmp < 0x100000) { call Leds.led2Toggle(); // don't indicate false alarms } if(0 == (tmp >> 18)) { call Leds.led0Toggle(); } } Also, if the amount to be shifted is given implicitly, seems to work OK. (The following does not blink Led 0.) event void Timer.fired() { uint32_t tmp = call Random.rand32(); // unknown value at compile time uint8_t i = 18; if(tmp < 0x100000) { call Leds.led2Toggle(); // don't indicate false alarms } tmp >>= i; if(0 == tmp) { call Leds.led0Toggle(); } } Q1: Is this a known problem or am I doing something terribly wrong? Q2: If it is already known, is there a known workaround (other than modifying the code?) Tested on latest TinyOS CVS checkout and 1-week old installation of the entire tinyos environment under Ubuntu 9.10. (msp toolchain installed with the apt-get tinyos-2.1.0.) Also, I've downloaded & installed the latest version of the msp430-gcc toolchain (using the instructions from http://sourceforge.net/apps/mediawiki/mspgcc/index.php?title=Linux_installation). But the problem persists with this compiler. Kind Regards Roland _______________________________________________ Tinyos-help mailing list Tinyos-help@millennium.berkeley.edu https://www.millennium.berkeley.edu/cgi-bin/mailman/listinfo/tinyos-help