As mentioned above, I create a new project on IAR EW8051 9.10.1, and then use oscilloscope to measure the time computation of 32-bit data (unsigned long) operations.
However, it was found that there are quite serious time-consuming problems, such as:
The 31-bit left/right shift operation takes about 60us, and the division takes 123us, and so on.
What seems to be the problem?
Thanks a lot for your attention!
Here is the code:////////////////////////////////////////////////////////////////////////////////
/*
Test time elapsed time of 32-bit operetion.
*/
////////////////////////////////////////////////////////////////////////////////
#include <ioCC2530.h>
#define LED1 P0_0
#define LED2 P0_1
#define LED3 P0_4
#define LED4 P0_5
#define LED5 P0_6
#define LED6 P0_7
#define SetRegBitValue(Reg, BitNum, State) \
((State) ? ((Reg) |= (((unsigned char)1) << BitNum)) : ((Reg) &= ~(((unsigned char)1) << (BitNum))))
#define SetRegValue(Reg, Bit7, Bit6, Bit5, Bit4, Bit3, Bit2, Bit1, Bit0) \
(Reg = (unsigned char)(Bit0) + (unsigned char)((Bit1)<<1) + (unsigned char)((Bit2)<<2) + (unsigned char)((Bit3)<<3) \
+ (unsigned char)((Bit4)<<4) + (unsigned char)((Bit5)<<5) + (unsigned char)((Bit6)<<6) + (unsigned char)((Bit7)<<7) )
#define BinValue(Bit7, Bit6, Bit5, Bit4, Bit3, Bit2, Bit1, Bit0) \
((unsigned char)(Bit0) + (unsigned char)((Bit1)<<1) + (unsigned char)((Bit2)<<2) + (unsigned char)((Bit3)<<3) \
+ (unsigned char)((Bit4)<<4) + (unsigned char)((Bit5)<<5) + (unsigned char)((Bit6)<<6) + (unsigned char)((Bit7)<<7))
//typedef signed char int8;
//typedef unsigned char uint8;
//
//typedef signed short int16;
//typedef unsigned short uint16;
//
//typedef signed long int32;
//typedef unsigned long uint32;
////////////////////////////////////////////////////////////////////////////////
int main( void )
{
//--------------------------------------------------------------------------
//32MHz
//[7][OSC32K]1(1,R/W), 32kHz RCOSC
//[6][OSC]0(1,R/W), 32MHz XOSC
//[5:3][TICKSPD]101(001,R/W), Timer Ticks = 1MHz
//[2:0][CLKSPD]000(001,R/W), 32MHz
SetRegValue(CLKCONCMD, 1, 0, 1,0,1, 0,0,0);
while(CLKCONSTA != BinValue(1, 0, 1,0,1, 0,0,0));
//--------------------------------------------------------------------------
EA = 0; //Close Global Interrupt
//Init Pins
SetRegBitValue(P0SEL, 0, 0); //0, General I/O
SetRegBitValue(P0DIR, 0, 1); //1, Output
SetRegBitValue(P0SEL, 1, 0); //0, General I/O
SetRegBitValue(P0DIR, 1, 1); //1, Output
SetRegBitValue(P0SEL, 4, 0); //0, General I/O
SetRegBitValue(P0DIR, 4, 1); //1, Output
SetRegBitValue(P0SEL, 5, 0); //0, General I/O
SetRegBitValue(P0DIR, 5, 1); //1, Output
SetRegBitValue(P0SEL, 6, 0); //0, General I/O
SetRegBitValue(P0DIR, 6, 1); //1, Output
SetRegBitValue(P0SEL, 7, 0); //0, General I/O
SetRegBitValue(P0DIR, 7, 1); //1, Output
//--------------------------------------------------------------------------
while(1)
{
unsigned long A = 0xF32E9AD0;
unsigned long B = 0xE9A3D02E;
LED1 = 1;
/* Tests:
1--7.5us. 5--14.6us. 10--23.6us. 13--29.0us. 16--34.4us.
19--39.6us. 24--48.8us. 29--57.6us. 31--61.2us. */
unsigned long C = A << 31;
LED1 = 0;
LED2 = 1;
/* Tests:
1--7.6us. 5--15us. 10--24.4us. 13--29.8us. 16--35.4us.
19--41.2us. 24--50.4us. 29--59.6us. 31--63.2us. */
unsigned long D = A >> 31;
LED2 = 0;
LED3 = 1;
unsigned long E = A + B; //Test: 8.3us
LED3 = 0;
LED4 = 1;
unsigned long F = A - B; //Test: 8.9us
LED4 = 0;
LED5 = 1;
unsigned long H = A * B; //Test: 18.6us
LED5 = 0;
LED6 = 1;
unsigned long I = A / B; //Test: 123us
LED6 = 0;
}
//--------------------------------------------------------------------------
return 0;
}
////////////////////////////////////////////////////////////////////////////////
Some environment settings are as follows: