NDS: Move a function to ITCM

support for the ARM toolchain
RyouArashi
Posts: 29
Joined: Sun Mar 29, 2009 9:23 pm

NDS: Move a function to ITCM

Post by RyouArashi » Thu Jul 15, 2010 4:19 pm

Is it possible to only move a certain function inside a C file to ITCM?

In the ds_rules/base_rules there is a ruleset which transfers a complete C file to ITCM by naming the file
somthing.itcm.c, but I want only a certain function in ITCM for speedup.
Plan B would be to move this single function to a separate .itcm.c file.

Since we're on the topic, can I relocate global variables to DTCM or is DTCM reserved for stack only?
(I don't need DTCM vars (yet), so this is just out of curiousity)

elhobbs
Posts: 354
Joined: Thu Jul 02, 2009 1:19 pm

Re: NDS: Move a function to ITCM

Post by elhobbs » Thu Jul 15, 2010 5:53 pm

ndstypes.h defines some handy macros for this

Code: Select all

//---------------------------------------------------------------------------------
// libgba compatible section macros
//---------------------------------------------------------------------------------
#define ITCM_CODE       __attribute__((section(".itcm"), long_call))
 
#define DTCM_DATA       __attribute__((section(".dtcm")))
#define DTCM_BSS        __attribute__((section(".sbss")))
if I remember correctly you need to use a function declaration to get this to work - like so:

Code: Select all

int foo(void) ITCM_CODE;
I would imagine that you declare a variable like so (but I have nor done this myself):

Code: Select all

int global_int DTCM_DATA;

RyouArashi
Posts: 29
Joined: Sun Mar 29, 2009 9:23 pm

Re: NDS: Move a function to ITCM

Post by RyouArashi » Thu Jul 15, 2010 7:19 pm

Thanks. I'll try these

WinterMute
Site Admin
Posts: 1403
Joined: Tue Aug 09, 2005 3:21 am
Location: UK
Contact:

Re: NDS: Move a function to ITCM

Post by WinterMute » Fri Jul 16, 2010 10:31 am

There are macros in the libnds headers to place code & data in the tcm sections, ITCM_CODE for functions, DTCM_BSS for uninitialised data, and DTCM_DATA for initialised data.

Code: Select all

#include <nds.h>
#include <stdio.h>

ITCM_CODE void itcmfn() {
	iprintf("in itcm %p\n", itcmfn);
}

char dtcmarray[256] DTCM_BSS;
char dtcmstring[] DTCM_DATA = "Hello World";

//---------------------------------------------------------------------------------
int main(int argc, char **argv) {
//---------------------------------------------------------------------------------

	consoleDemoInit();
	
	itcmfn();
	
	iprintf("%s\n",dtcmstring);
	iprintf("dtcmstring %p\ndtcmarray %p\n",dtcmstring,dtcmarray);

	while(1) {
		swiWaitForVBlank();
		scanKeys();
		if (keysDown() & KEY_X) break;
	}
	return 0;
}
caveat: You'll see little to no speed increase from doing this unless you have loops which overrun the cache.
Help keep devkitPro toolchains free, Donate today

devkitPro IRC support
Personal Blog

ritz
Posts: 24
Joined: Thu Jun 04, 2009 3:17 pm
Location: Canada

Re: NDS: Move a function to ITCM

Post by ritz » Fri Jul 16, 2010 4:26 pm

DTCM_BSS? A little naive here, but what is this .sbss section for DTCM? I have not seen this before.

elhobbs
Posts: 354
Joined: Thu Jul 02, 2009 1:19 pm

Re: NDS: Move a function to ITCM

Post by elhobbs » Fri Jul 16, 2010 4:56 pm

isn't that just unitialized data that you want in DTCM?

ritz
Posts: 24
Joined: Thu Jun 04, 2009 3:17 pm
Location: Canada

Re: NDS: Move a function to ITCM

Post by ritz » Sat Jul 17, 2010 5:26 am

I guess so. I think I'm just confused by the .sbss part being related to DTCM. I'm not clear as to what the .sbss section is physically.

WinterMute
Site Admin
Posts: 1403
Joined: Tue Aug 09, 2005 3:21 am
Location: UK
Contact:

Re: NDS: Move a function to ITCM

Post by WinterMute » Sat Jul 17, 2010 11:50 am

.bss & .sbss are nothing physically, they're simply directives which describe uninitialised data which the linkscript reserves memory for without taking space in the binary file. In our case I've mapped bss to ewram and sbss to dtcm.
Help keep devkitPro toolchains free, Donate today

devkitPro IRC support
Personal Blog

ritz
Posts: 24
Joined: Thu Jun 04, 2009 3:17 pm
Location: Canada

Re: NDS: Move a function to ITCM

Post by ritz » Sat Jul 17, 2010 4:19 pm

Ah, I see now. Thanks for the info.

HeavyDude
Posts: 14
Joined: Sun Oct 31, 2010 12:55 pm

Re: NDS: Move a function to ITCM

Post by HeavyDude » Thu Jun 16, 2011 9:38 pm

You'll see little to no speed increase from doing this unless you have loops which overrun the cache.
Can someone explain this to me please?

Post Reply

Who is online

Users browsing this forum: Google [Bot] and 1 guest