As I recall, with the second iteration of the Maxwell architecture (sm_52) an optional scale factor 2k was incorporated into the FMUL instruction, for k of small magnitude. In examining some code the other day where the SASS consisted of one more instruction than I had expected, I noticed that this curiously does not seem to apply to a scale factor of 2. Here is a worked example for sm_89 compiled with CUDA 13.3:
__device__ float fmul_m2 (float a, float b) { return a * b * 2.0f; }
__device__ float fmul_m4 (float a, float b) { return a * b * 4.0f; }
__device__ float fmul_m8 (float a, float b) { return a * b * 8.0f; }
__device__ float fmul_d2 (float a, float b) { return a * b * 0.5f; }
__device__ float fmul_d4 (float a, float b) { return a * b * 0.25f; }
__device__ float fmul_d8 (float a, float b) { return a * b * 0.125f; }
The resulting code is as expected, except for fmul_m2():
fmul_m2(float, float):
FMUL R3, R4, R5
FFMA R4, R4, R5, R3
RET.ABS.NODEC R20 0x0
fmul_m4(float, float):
FMUL.M4 R4, R4, R5
RET.ABS.NODEC R20 0x0
fmul_m8(float, float):
FMUL.M8 R4, R4, R5
RET.ABS.NODEC R20 0x0
fmul_d2(float, float):
FMUL.D2 R4, R4, R5
RET.ABS.NODEC R20 0x0
fmul_d4(float, float):
FMUL.D4 R4, R4, R5
RET.ABS.NODEC R20 0x0
fmul_d8(float, float):
FMUL.D8 R4, R4, R5
RET.ABS.NODEC R20 0x0
Some participants in this forum seem to have studied the GPU machine code instructions in some detail, so I figured I would bring this up here. I have a hard time imagining that NVIDIA structured the instruction encodings such that the common case of multiplication by 2 did not fit into the bit field presumably used. I assume that this is a 3-bit field, and I recognize the possibility that some of the 8 encodings might be used for other functionality, but if the GPU architects ran out of encodings, why remove the multiplication by 2, which I would think is more frequent than multiplication by 0.125?
Assuming the hardware actually supports it and that this is the result of a compiler issue, it would seem similar curious that the compiler recognized other cases but missed the common multiply-by-2.
I did an internet search to see if anybody else had noticed this anomaly before but could not find any mention of it. I am genuinely puzzled as to what may be going here.