File tree Expand file tree Collapse file tree 1 file changed +14
-10
lines changed
ggml/src/ggml-vulkan/vulkan-shaders Expand file tree Collapse file tree 1 file changed +14
-10
lines changed Original file line number Diff line number Diff line change @@ -1413,16 +1413,20 @@ float bf16_to_fp32(uint32_t u)
14131413}
14141414
14151415float 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)
You can’t perform that action at this time.
0 commit comments