binaryen
binaryen copied to clipboard
[Idea] Compress f64.const in integer domain for optimization for size
Since f64 operations do not use LEB128 encoding, such constants always takes 8 bytes. Although some constants like 2.0, 3.25, 16.0, etc. have an empty or partially filled mantissa, which can be utilized for compression in integer domain. Here are some examples:
f64.const 4.0
is equivalent to set:
i64.const 1025
i64.const 52
i64.shl
f64.reinterpret_i64
Which is on 2 bytes less than floating point constant.
Another example which is more impressive:
f64.const 0.0
is simply equivalent to:
i64.const 0
f64.reinterpret_i64
which is on 6 bytes less.
Constants with floating arithmetic are much rarer than those with integer arithmetic, which leads to that they do not get into the gzip / brotli dictionaries. Although one must of course prove this thesis in practice.