NDS: Move a function to ITCM
-
- Posts: 29
- Joined: Sun Mar 29, 2009 9:23 pm
NDS: Move a function to ITCM
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)
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
ndstypes.h defines some handy macros for this
if I remember correctly you need to use a function declaration to get this to work - like so:
I would imagine that you declare a variable like so (but I have nor done this myself):
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")))
Code: Select all
int foo(void) ITCM_CODE;
Code: Select all
int global_int DTCM_DATA;
-
- Posts: 29
- Joined: Sun Mar 29, 2009 9:23 pm
Re: NDS: Move a function to ITCM
Thanks. I'll try these
-
- Site Admin
- Posts: 1989
- Joined: Tue Aug 09, 2005 3:21 am
- Location: UK
- Contact:
Re: NDS: Move a function to ITCM
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.
caveat: You'll see little to no speed increase from doing this unless you have loops which overrun the cache.
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;
}
Re: NDS: Move a function to ITCM
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
isn't that just unitialized data that you want in DTCM?
Re: NDS: Move a function to ITCM
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.
-
- Site Admin
- Posts: 1989
- Joined: Tue Aug 09, 2005 3:21 am
- Location: UK
- Contact:
Re: NDS: Move a function to ITCM
.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
Ah, I see now. Thanks for the info.
Re: NDS: Move a function to ITCM
Can someone explain this to me please?You'll see little to no speed increase from doing this unless you have loops which overrun the cache.
Who is online
Users browsing this forum: No registered users and 2 guests