I use the MIPS processor (PIC32) in an embedded project, but I'm starting to doubt my choice. I understand that a RISC processor, such as MIPS, will generate more instructions than you would expect, but I did not think it would be so. Here is a snippet from the dismantling list:
225: LATDSET = 0x0040; sw s1,24808(s2) sw s4,24808(s2) sw s4,24808(s2) sw s1,24808(s2) sw s4,24808(s3) sw s4,24808(s3) sw s1,24808(s3) 226: { 227: porte = PORTE; lw t1,24848(s4) andi v0,t1,0xffff lw v1,24848(s6) andi ra,v1,0xffff lw v1,24848(s6) andi ra,v1,0xffff lw v0,24848(s6) andi t2,v0,0xffff lw a2,24848(s5) andi v1,a2,0xffff lw t2,24848(s5) andi v1,t2,0xffff lw v0,24848(s5) andi t2,v0,0xffff 228: if (porte & 0x0004) andi t2,v0,0x4 andi s8,ra,0x4 andi s8,ra,0x4 andi ra,t2,0x4 andi a1,v1,0x4 andi a2,v1,0x4 andi a2,t2,0x4 229: pst_bytes_somi[0] |= sliding_bit; or t3,t4,s0 xori a3,t2,0x0 movz t3,s0,a3 addu s0,t3,zero or t3,t4,s1 xori a3,s8,0x0 movz t3,s1,a3 addu s1,t3,zero or t3,t4,s1 xori a3,s8,0x0 movz t3,s1,a3 addu s1,t3,zero or v1,t4,s0 xori a3,ra,0x0 movz v1,s0,a3 addu s0,v1,zero or a0,t4,s2 xori a3,a1,0x0 movz a0,s2,a3 addu s2,a0,zero or t3,t4,s2 xori a3,a2,0x0 movz t3,s2,a3 addu s2,t3,zero or v1,t4,s0 xori a3,a2,0x0 movz v1,s0,a3
This is like a crazy amount of instructions for simply reading / writing and testing variables at fixed addresses. On another processor, I could probably get every C statement up to about 1..3 instructions without resorting to handwritten asm. Obviously, the clock speed is quite high, but it is not 10 times higher than that of another processor (for example, dsPIC).
My optimization is set to the maximum. Is my C compiler awful (this is gcc 3.4.4)? Or is this typical of MIPS?