uint256
uint256 copied to clipboard
Fixed size 256-bit math library
## Description Simplify codes and reduce jumps. ## Test ``` go test ./... ``` returns ``` ok github.com/holiman/uint256 0.983s ``` ------------------- ## Benchmark ``` go test -run - -bench sh$...
The main difference is ``` z[0] = (number & (0xff00000000000000 >> offset)) >> (56 - offset) ``` vs ``` z[0] = (number >> (56 - offset)) & 0xff ``` ------------------------...
``` go test ./... ``` returns ``` ok github.com/holiman/uint256 0.977s ``` ## Bechmark for `leadingZeros` ``` go test -run - -bench BenchmarkLead -benchmem ``` code: ``` func BenchmarkLeadingZeros(bench *testing.B) {...
Negative value change after uint256.FromBig and then ToBig: ``` func TestReverse(t *testing.T) { a, _ := big.NewInt(0).SetString("-1", 10) u, _ := uint256.FromBig(a) areverse := u.ToBig() fmt.Println(areverse, areverse.Sign(), a.Sign()) // areverse:...
https://en.wikipedia.org/wiki/Intel_ADX for `adcx`/`adox` and `mulx`/`sarx`/`shrx`/`shlx` being in [bmi2](https://en.wikipedia.org/wiki/X86_Bit_manipulation_instruction_set#BMI2_.28Bit_Manipulation_Instruction_Set_2.29). I recognize the `gcc-go` for accessing them as compiler defined functions/instructions instead of raw assembly. gmp/mpir is using them along other extensions...
The current implementation is done by bits manipulation on whole 256-bit values (as you would do it for architecture native integers). There exists more efficient implementation which handles each of...
thank you
Hi. Thank you for your code. This might be out of scope, but I wondered if Dec() should be prefixed with a "-" when Sign < 0. ```go package main...
I often embed uint256.Int types directly into a struct to avoid the overhead of memory allocation, GC, the pointer memory storage and associated cache misses when following the pointers. When...
A bit of an edge case, but cannot seem to get payload unmarshalling to be happy.