255 255 255 value test
Interestingly, though, when I use GCC 4.6.1 on the same code, the assembler output is. Neither approaches the 7 instructions in your optimized version.
#255 255 255 value test code
Your code ( Clamp_1()) assembles to 11 instructions mine to 9 (but there are two jumps in mine, which might wreak havoc on pipelined execution). The pushq, popq and ret are the function call overhead.
![255 255 255 value test 255 255 255 value test](https://d2vlcm61l7u1fs.cloudfront.net/media%2F53e%2F53e8d738-4dca-4c2c-9ec1-b344a7063dc4%2FphpFAVJSE.png)
section _TEXT,_text,regular,pure_instructions The assembler for the two functions (with prologue and epilogue) is. Where clamp.c contains: typedef unsigned char BYTE Using GCC/LLVM on MacOS X, and 64-bit compilation, and generating assembler with: gcc -S -Os clamp.c This is very close to the 0.18 seconds that resulted when I removed the clamp entirely. The overall timing for this function within my benchmark algorithm went from 0.24 seconds to 0.19. A ternary solution turned out to be the fastest, especially when the compiler substituted its own bit-twiddling code for one of the cases. That was a mistake, as I hadn't counted on the power of the branch prediction built into a modern CPU. I started with an assumption that bit-twiddling would beat anything that included a branch I hadn't really tried any code that included an if statement or ternary operator. A slight modification of the straightforward implementation suggested by Ira Baxter came up the winner. The generated code didn't change much, but the register assignments did which affected the overall results. Have questions or feedback about Office VBA or this documentation? Please see Office VBA support and feedback for guidance about the ways you can receive support and provide feedback.I tried all of the suggestions again with VS 2010 Express. Functions (Visual Basic for Applications).MyObject.Color = RGB(255, 0, 0) ' Set the Color property of MyObject to Red. Red = RGB(255, 0, 0) ' Return the value for Red. If MyObject does not exist, or if it does not have a Color property, an error occurs. The object MyObject and its property are used for illustration purposes only. It is used for those application methods and properties that accept a color specification. This example shows how the RGB function is used to return a whole number representing an RGB color value. They may be used within the context of Microsoft applications for the Macintosh, but should not be used when communicating color changes directly to the Macintosh operating system. The RGB color values returned by this function are incompatible with those used by the Macintosh operating system. The following table lists some standard colors and the red, green, and blue values they include: Color The value for any argument to RGB that exceeds 255 is assumed to be 255. An RGB color value specifies the relative intensity of red, green, and blue to cause a specific color to be displayed. Number in the range 0–255, inclusive, that represents the blue component of the color.Īpplication methods and properties that accept a color specification expect that specification to be a number representing an RGB color value. Number in the range 0–255, inclusive, that represents the green component of the color. Number in the range 0–255, inclusive, that represents the red component of the color. The RGB function syntax has these named arguments: Part Returns a Long whole number representing an RGB color value.