chipKIT® Development Platform

Inspired by Arduino™

32bit vs 16bit instructions...

Created Thu, 20 Oct 2011 16:34:53 +0000 by WestfW


WestfW

Thu, 20 Oct 2011 16:34:53 +0000

I was disassembling code (a favorite hobby), trying to figure out the interrupt-related problems that some people are reporting, and I noticed that the compiler is producing full 32bit MIPS instructions:

void __ISR(_EXTERNAL_1_VECTOR, ipl4) ExtInt1Handler(void)
9d001714:	415de800 	rdpgpr	sp,sp
9d001718:	401a7000 	mfc0	k0,c0_epc
9d00171c:	401b6000 	mfc0	k1,c0_status
9d001720:	27bdff98 	addiu	sp,sp,-104
9d001724:	afbb0060 	sw	k1,96(sp)
9d001728:	7c1b7844 	ins	k1,zero,0x1,0xf
9d00172c:	377b1000 	ori	k1,k1,0x1000
9d001730:	afba0064 	sw	k0,100(sp)
9d001734:	409b6000 	mtc0	k1,c0_status
9d001738:	afbf0054 	sw	ra,84(sp)
9d00173c:	afb90050 	sw	t9,80(sp)

I would have thought that most microcontroller compilers and builds would be set up to use the "compressed" 16-bit instructions (MIPS16e for PIC32) rather than the full 32bit versions. Does the compiler support this? Is there a reason it isn't used? I'd worry that code will look especially bloated compared to ARM/Cortex binaries (which use the 16bit Thumb instructions?)


WestfW

Fri, 21 Oct 2011 01:53:15 +0000

Hmm. Still wading through the MIPS architecture and instruction set manuals. It looks like the compressed MIPS16e instruction set is only available in "user mode." I assume that the PICKit (and indeed, MOST PIC32 applications?) start and stay in kernel mode... Sigh. (and: "interesting.")


jasonk

Fri, 21 Oct 2011 04:19:03 +0000

Hi WestfW,

I'm impressed; you're really staring to dig deep into the PIC32 architecture.

Just to clarify, the MIPS16e ISA mode works in both kernel mode and user mode.

We chose to default the chipKIT compiler to full 32-bit mode because there is a small performance hit when switching to MIPS16e mode and we wanted the chipKIT to emphasize performance over code size.

The chipKIT compiler does, however, provide mips16 as an option for the more adventurous among us. You can add the attribute((mips16)) to a function or you can add the -mips16 command-line option to platforms.txt or boards.txt. The command-line option switches the default to mips16 mode and then you can use attribute((nomips16)) to get MIPS32 mode back for a function. You can add -mips16 to both the compiler command line and the linker command line. The linker will use the -mips16 compiled standard C library.

I should also mention that ISRs are always MIPS32; the device automatically switches back to the MIPS32 ISA mode on an interrupt or exception.

Hope this helps,


WestfW

Sun, 23 Oct 2011 05:43:20 +0000

Is there a document describing the instruction set and architecture from a more PIC32-centric point of view? The MIPS documents are cluttered with talk about the floating point unit, cache and TLB control...