01-28-2024, 06:51 AM
The functions alpha/red/green/blue work the same way as what you're doing and will be equivalent in speed. The only minor difference is that your `AND` for the alpha value is unnecessary as all the values you're `AND`ing away will be shifted away by the `_SHR(a, 24)`, so because of that `_ALPHA32()` only does a shift.
That said, them having equivalent speed is only true if you're inlining that logic everywhere you use it. If you plan to put the logic into a QB64 `FUNCTION`then there is overhead to calling QB64 functions that the built-in functions do not have. In absolute time it could easily be 100x slower simply because the `FUNCTION` would do so little actual work.
I would also note that the type's of the variables matter for this question. Your code only works if the types are unsigned, because `_ShR` will do 64-bit sign extension if the original value is a signed negative. In contrast, the QB64 functions will work correctly regardless of the signed/unsigned nature of the original value (really this only matters for the `_Alpha32()`, since the other colors are always positive values after the `AND`).
That said, them having equivalent speed is only true if you're inlining that logic everywhere you use it. If you plan to put the logic into a QB64 `FUNCTION`then there is overhead to calling QB64 functions that the built-in functions do not have. In absolute time it could easily be 100x slower simply because the `FUNCTION` would do so little actual work.
I would also note that the type's of the variables matter for this question. Your code only works if the types are unsigned, because `_ShR` will do 64-bit sign extension if the original value is a signed negative. In contrast, the QB64 functions will work correctly regardless of the signed/unsigned nature of the original value (really this only matters for the `_Alpha32()`, since the other colors are always positive values after the `AND`).