User Profile

Collapse

Profile Sidebar

Collapse
RichG
RichG
Last Activity: Mar 17 '10, 06:06 PM
Joined: Oct 5 '09
Location:
  •  
  • Time
  • Show
  • Source
Clear All
new posts

  • I did try it as an inline function and yes, it still ran 40x slower...

    however, I just tried something different. Up until now I was compiling with VC++ 2008 Express Edition in Debug mode. I've since turned on Release mode and I can't even register a single clock tick to provide a measurable difference between using a function or Macro. I've tried up to 8 nested loops each going from 0 to ULONG_MAX and the end result is still 0 clock...
    See more | Go to post

    Leave a comment:


  • Just an update here... I wrote a function to perform the same task and compared it to the Macro version. On average, the Macro ran 40x faster than the function version.

    Also, I was able to optimize the code slightly:

    Code:
    #define M_HIGH(sbit, ebit, data) ( (data[M_BYTENUM(ebit)] & ( (1<<((ebit&0x07) + 1)) - 1 )  ) << (( (ebit&0xf8) - sbit) ) ) // Upper portion of value
    #define M_MID(sbit, data)
    ...
    See more | Go to post

    Leave a comment:


  • Found bug.

    M_MID should be:

    Code:
    #define M_MID(sbit, data)        ( data[M_BYTENUM(sbit)+1] << ((((M_BYTENUM(sbit)+1) << 3) - sbit ) &0x0f) )                                    // Middle byte value when value spans three bytes
    See more | Go to post

    Leave a comment:


  • Left shifting by too many bits would definitely produce inaccurate results. As the name implies, the macro is designed to extract a 16-bit value from some location in a byte array. No error checking is done to see if (ebit-sbit)>16. I've left it up to the programmer to enter correct values from the start.

    As you mentioned, I may be prematurely optimizing code here as I've not measured to establish a benchmark. As it is now I've...
    See more | Go to post

    Leave a comment:


  • I did everything with macros to save on the overhead associated with a function call. My thinking was the preprocessor would do all of the constant math at compile time thus coming up with a condensed line of code rather than an expanded mess.

    As for getting the right values, all of my test cases return correct values so I'm fairly confident the casts aren't needed. This, however, may be compiler dependent.

    I did run into...
    See more | Go to post

    Leave a comment:


  • Check on YouTube. Good tutorials can somes be found there.

    OpenGL Tutorial #1: Basic Shapes
    See more | Go to post

    Leave a comment:


  • RichG
    started a topic Working with non byte aligned data values in memory
    in C

    Working with non byte aligned data values in memory

    I'm working with a data stream of 8 bytes in an embedded application. In most cases the data is byte aligned so I can define a structure and then memcpy the data directly to the structure elements. There are, however, a few cases where the 16 bit data values span 2 or 3 bytes. I came up with a few macros to handle these cases. It's working fine, but I'm wondering if anyone can point out some obvious flaws or code optimizations to make the macros...
    See more | Go to post

  • RichG
    replied to Using sizeof with global structure
    in C
    Yes, this is an embedded application and I will have to watch the amount of RAM I use. I'll take a look at your recommendation as it looks like a viable solution. Thanks again!...
    See more | Go to post

    Leave a comment:


  • RichG
    replied to Using sizeof with global structure
    in C
    That is correct. Including the test.c file was mentioned as an alternate approach....
    See more | Go to post

    Leave a comment:


  • RichG
    replied to Using sizeof with global structure
    in C
    True on the second point... which takes me right back to my initial problem. Forget I even mentioned it. ;)...
    See more | Go to post

    Leave a comment:


  • RichG
    replied to Using sizeof with global structure
    in C
    The actual structure may look something like this:

    Code:
    TextStructDef TextStruct[]=
    {
     {"First option"        , TRUE},
     {"Second choice"       , TRUE},
     {"Choice number three" , TRUE},
     {"Fourth"              , TRUE},
     {"Fifth selection"     , TRUE},
    };
    When the code is run, assume options are such that items 3 and 5 are hidden....
    See more | Go to post

    Leave a comment:


  • RichG
    replied to Using sizeof with global structure
    in C
    Good points guys! I do appreciate the input.

    Going back to my initial post, when I change the include line to be test.c instead of test.h, the program compiles & works. Any negative to that?

    This is starting to open a can beyond my original question... in the actual program, there are about 20 arrays like this each with up to 20 to 30 elements. The text can vary in length but is fixed so I can use const char *. The...
    See more | Go to post

    Leave a comment:


  • RichG
    replied to Using sizeof with global structure
    in C
    Thanks guys! Those both will work... either adding a function in Test.c which returns the size, or declaring a global constant below the array definition (though I can't use [100] because the number of elements will change-- not dynamically where I would need to allocate space, but in the source file)

    I ended up with something like this:

    MainTest.c:
    Code:
    #include "test.h"
    #include "stdlib.h"
    ...
    See more | Go to post

    Leave a comment:


  • RichG
    started a topic Using sizeof with global structure
    in C

    Using sizeof with global structure

    Question for all...

    I'm trying to determine the size of a global structure. It has to be declared globally because it's used in several different files. When compiling (BCC32) the code I get the error:

    Error E2109 MainTest.c 9: Not an allowed type in function main

    I know this is happening because the array of structures is of an undefined size []. But I can't define the size ahead of time.
    ...
    See more | Go to post
No activity results to display
Show More
Working...