Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save shunghsiyu/a63e08e6231553d1abdece4aef29f70e to your computer and use it in GitHub Desktop.
Save shunghsiyu/a63e08e6231553d1abdece4aef29f70e to your computer and use it in GitHub Desktop.
Fix description of tnum.mask, and use C-style comment
Display the source blob
Display the rendered blob
Raw
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@Werkov
Copy link

Werkov commented Aug 10, 2022

When I look at tnum_const function, the tnum.mask comment should read "which bits are unknown".

It'd be interesting to implement Tnum.popcount() (of the mask) and try proving sum.popcount() <= t1.popcount() + t2.popcount() + margin to see how tnum_add is efficient in conserving certainity.

(I hope that z3 prover doesn't use same tnums implementation internally ;-).)

@shunghsiyu
Copy link
Author

shunghsiyu commented Aug 11, 2022

When I look at tnum_const function, the tnum.mask comment should read "which bits are unknown".

@Werkov thanks for spotting the mistake! Now fixed.

It'd be interesting to implement Tnum.popcount() (of the mask) and try proving sum.popcount() <= t1.popcount() + t2.popcount() + margin to see how tnum_add is efficient in conserving certainity.

Very interesting indeed, though I wonder if I should eliminate cases where it overflows, otherwise a Tnum(val=-1, mask=0) + Tnum(val=0, mask=1) == Tnum(val=0, mask=-1) worst-case might kill all the fun.

Another ideal would be to brute-force through all the combinations at a lower size (i.e. bandwidth), maybe 16-bit instead of 64-bit, then plot some thing like a closure plot (using the posits paper as an example here)

multiplication closure of posits vs floating-point

In Sound, Precise, and Fast Abstract Interpretation with Tristate Numbers, they used brute-forcing to compare the precision between their proposed multiplication algorithm and the original tnum_mul() in the Linux kernel.

(I hope that z3 prover doesn't use same tnums implementation internally ;-).)

I hope not :P

@shunghsiyu
Copy link
Author

Another ideal would be to brute-force through all the combinations at a lower size (i.e. bandwidth), maybe 16-bit instead of 64-bit, then plot some thing like a closure plot (using the posits paper as an example here)

Scratch that... I cannot represent tnum on a single number line

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment