Skip to content

Commit 1af9e2e

Browse files
authored
Update types.comp
Modified code (branchless) for e8m0_to_fp32
1 parent 1fe0029 commit 1af9e2e

File tree

1 file changed

+14
-10
lines changed

1 file changed

+14
-10
lines changed

ggml/src/ggml-vulkan/vulkan-shaders/types.comp

Lines changed: 14 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1413,16 +1413,20 @@ float bf16_to_fp32(uint32_t u)
14131413
}
14141414

14151415
float e8m0_to_fp32(uint8_t x) {
1416-
uint32_t bits;
1417-
1418-
if (x == 0) {
1419-
bits = 0x00400000;
1420-
} else {
1421-
bits = x;
1422-
bits = bits << 23;
1423-
}
1424-
1425-
return uintBitsToFloat(bits);
1416+
// uint32_t bits;
1417+
1418+
// if (x == 0) {
1419+
// bits = 0x00400000;
1420+
// } else {
1421+
// bits = x;
1422+
// bits = bits << 23;
1423+
// }
1424+
1425+
// branchless optimization
1426+
uint ux = uint(x);
1427+
uint is_zero = uint(x == 0);
1428+
uint result = (ux << 23) * (1 - is_zero) + (0x00400000u * is_zero);
1429+
return uintBitsToFloat(result);
14261430
}
14271431

14281432
#endif // !defined(GGML_TYPES_COMP)

0 commit comments

Comments
 (0)