LabWindows/CVI

cancel
Showing results for 
Search instead for 
Did you mean: 

Most efficient way to subtract two Unsigned Int

I am looking for the most computationaly efficient method to subtract two unsigned integers, such that they do not wrap around.  That is 8 - 5 = 3, and 5 - 8 = 0.

I am doing this calculation about 50,000,000,000 times in my application, so computational efficiency is quite important(even saving 1 CPU cycle would be very significant).   My current implementation is:

 

unsigned int A = 5, B = 8;

unsigned int Result;

 

loop many times

  if ( B < A)

        Result = Result + A - B;

0 Kudos
Message 1 of 2
(3,052 Views)

Hi,

 

if code optimization is important, you probably should not stick to CVI but rather choose an optimizing compiler such as from Intel for Microsoft.

The CVI compiler is oriented towards debugging and does not include optimization capabilities.

0 Kudos
Message 2 of 2
(3,042 Views)