Page 1 of 2

NDS: Move a function to ITCM

Posted: Thu Jul 15, 2010 4:19 pm
by RyouArashi
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)

Re: NDS: Move a function to ITCM

Posted: Thu Jul 15, 2010 5:53 pm
by elhobbs
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;

Re: NDS: Move a function to ITCM

Posted: Thu Jul 15, 2010 7:19 pm
by RyouArashi
Thanks. I'll try these

Re: NDS: Move a function to ITCM

Posted: Fri Jul 16, 2010 10:31 am
by WinterMute
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.

Re: NDS: Move a function to ITCM

Posted: Fri Jul 16, 2010 4:26 pm
by ritz
DTCM_BSS? A little naive here, but what is this .sbss section for DTCM? I have not seen this before.

Re: NDS: Move a function to ITCM

Posted: Fri Jul 16, 2010 4:56 pm
by elhobbs
isn't that just unitialized data that you want in DTCM?

Re: NDS: Move a function to ITCM

Posted: Sat Jul 17, 2010 5:26 am
by ritz
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.

Re: NDS: Move a function to ITCM

Posted: Sat Jul 17, 2010 11:50 am
by WinterMute
.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.

Re: NDS: Move a function to ITCM

Posted: Sat Jul 17, 2010 4:19 pm
by ritz
Ah, I see now. Thanks for the info.

Re: NDS: Move a function to ITCM

Posted: Thu Jun 16, 2011 9:38 pm
by HeavyDude
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?