This discussion has been locked.
You can no longer post new replies to this discussion. If you have a question you can start a new discussion

How can I optimize the xdata access with C51

Hi there!

I need to optimize the accessing the xdata memory (the speed) with C51.

I am sending some files via modem and the transmission could be a bit faster. At present, I am reaching a transmission speed around 2kbyte/sec, which is kinda slow.

Right now, my buffers are large arrays in xdata memory and before a byte reaches the UART, it went through a couple of buffers (for the prtotocol layers). I cannot prevent that. But maybe one or the other way can speed up my access time to xdata.

I am not sure, I have heard somewhere that C51 will be faster if pointers instead of arrays are used. I didn't find anything about that in the search (maybe due to my keywords). Does anybody know more about that topic?

Parents
  • I think it means the following: imagine we have to fill an array with zeros. There are at least 2 ways to do that:

    int array[100];
    int i;
    for (i=0; i<100; i++) array[i] = 0;
    
    and
    int array[100];
    int* ptr;
    for (ptr=array+100; ptr != array; ) *--ptr = 0;
    // or something like that
    
    The code generated for '*--ptr = 0' should be more efficient than the code generated for 'array[i] = 0'.

Reply
  • I think it means the following: imagine we have to fill an array with zeros. There are at least 2 ways to do that:

    int array[100];
    int i;
    for (i=0; i<100; i++) array[i] = 0;
    
    and
    int array[100];
    int* ptr;
    for (ptr=array+100; ptr != array; ) *--ptr = 0;
    // or something like that
    
    The code generated for '*--ptr = 0' should be more efficient than the code generated for 'array[i] = 0'.

Children
  • "The code generated for '*--ptr = 0' should be more efficient than the code generated for 'array[i] = 0'"

    This is not necessarily so - see:
    http://www.keil.com/forum/msgpage.asp?MsgID=4108

    Note also that it's more efficient to have your for loop counting down to zero, as the DJNZ instruction can then be used.

    If you do use pointers, be sure to use memory-specific pointers.

    Make sure that the pointer or loop index is in DATA.

    You may find that its best to use the Library routines like memcpy as they are (hopefully) pretty well optimised, or write your own optimised version in assembler.
    Enabling extra DPTR(s) should help a bit.

    Does your processor have DMA?