-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
5ac4fbf
commit ff696ae
Showing
5 changed files
with
197 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,75 @@ | ||
#import './PRBMathHelper.huff' | ||
|
||
#define macro SQRT_PRB() = takes(1) returns(1){ | ||
//Input Stack = [x] | ||
dup1 // [x,x] | ||
iszero // [x==0?,x] | ||
jumpi | ||
zero_found | ||
[X3] // [1e18,x] | ||
mul // [1e18*x] | ||
dup1 // [1e18*x,1e18*x] | ||
0x01 // [1,1e18*x,1e18*x] | ||
GATE1() | ||
GATE2() | ||
GATE3() | ||
GATE4() | ||
GATE5() | ||
GATE6() | ||
GATE7() // [result,xnum,x'] | ||
swap1 // [xnum,result,x'] | ||
pop // [result,x'] | ||
0x00 // [0,result,x'] | ||
loop | ||
jump | ||
|
||
loop: // [i,result,x'] | ||
0x01 // [1,i,result,x'] | ||
add // [i+1,result,x'] | ||
swap1 // [result,i+1,x'] | ||
dup1 // [result,result,i+1,x'] | ||
dup4 // [x',result,result,i+1,x'] | ||
add // [x'+result,result,i+1,x'] | ||
div // [(x'+result)/result,i+1,x'] , Let (x'+result)/result = result | ||
dup2 // [i+1,result,i+1,x'] | ||
0x07 // [7,i+1,result,i+1,x'] | ||
eq // [i+1==7?,result,i+1,x'] | ||
done | ||
jumpi | ||
loop | ||
jump | ||
|
||
done: // [result,i+1,x'] | ||
swap1 // [i+1,result,x'] | ||
pop // [result,x'] | ||
dup1 // [result,result,x'] | ||
swap2 // [x',result,result] | ||
div // [x'/result,result] | ||
dup1 // [x'/result,x'/result,result] | ||
dup3 // [result,x'/result,x'/result,result] | ||
lt // [result < x'/result,x'/result,result] | ||
iszero | ||
final | ||
jumpi | ||
pop | ||
|
||
final: // [x'/result,result] | ||
swap1 // [result,x'/result] | ||
pop // [x'/result] | ||
|
||
zero_found: //[x] | ||
pop // [] | ||
0x00 // [0] | ||
|
||
} | ||
|
||
#define macro LOGE_PRB() = takes(1) returns(1) { | ||
//Input stack => [x] | ||
LOG2() // [log2(x)] | ||
[X3] // [1e18,log2(x)] | ||
mul // [1e18*log2(x)] | ||
[LOG2_E] // [Log2(e),1e18*log2(x)] | ||
swap1 // [1e18*log2(x),Log2(e)] | ||
sdiv // [1e18*log2(x)/Log2(e)] | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,116 @@ | ||
|
||
#define macro GATE1() = takes(0) returns(0) { | ||
//Input Stack [result,xn,x] | ||
dup2 // [xn,result,xn,x] | ||
0x100000000000000000000000000000000 // [0x100000000000000000000000000000000,xn,result,xn,x] | ||
gt // [0x100000000000000000000000000000000>xn,result,xn,x] | ||
iszero | ||
satisfied | ||
jumpi | ||
|
||
satisfied: | ||
64 shl // [result<<64,xn,x] | ||
swap1 // [xn,result<<64,x] | ||
128 shr // [xn >> 128,result<<64,x] | ||
swap1 // [result<<64,xn >> 128] | ||
} | ||
|
||
#define macro GATE2() = takes(0) returns(0) { | ||
//Input Stack [result,xn,x] | ||
dup2 // [xn,result,xn,x] | ||
0x10000000000000000 // [0x10000000000000000,xn,result,xn,x] | ||
gt // [0x10000000000000000>xn,result,xn,x] | ||
iszero | ||
satisfied | ||
jumpi | ||
|
||
satisfied: | ||
32 shl // [result<<32,xn,x] | ||
swap1 // [xn,result<<32,x] | ||
64 shr // [xn >> 64,result<<32,x] | ||
swap1 // [result<<32,xn>>64,x] | ||
} | ||
|
||
#define macro GATE3() = takes(0) returns(0) { | ||
//Input Stack [result,xn,x] | ||
dup2 // [xn,result,xn,x] | ||
0x100000000 // [0x100000000,xn,result,xn,x] | ||
gt // [0x100000000>xn,result,xn,x] | ||
iszero | ||
satisfied | ||
jumpi | ||
|
||
satisfied: | ||
16 shl // [result<<16,xn,x] | ||
swap1 // [xn,result<<16,x] | ||
32 shr // [xn >> 32,result<<16,x] | ||
swap1 // [result<<16,xn >> 32,x] | ||
} | ||
|
||
#define macro GATE4() = takes(0) returns(0) { | ||
//Input Stack [result,xn,x] | ||
dup2 // [xn,result,xn,x] | ||
0x10000 // [0x10000,xn,result,xn,x] | ||
gt // [0x10000>xn,result,xn,x] | ||
iszero | ||
satisfied | ||
jumpi | ||
|
||
satisfied: | ||
8 shl // [result<<8,xn,x] | ||
swap1 // [xn,result<<8,x] | ||
16 shr // [xn >> 16,result<<8,x] | ||
swap1 // [result<<16,xn >> 8] | ||
} | ||
|
||
#define macro GATE5() = takes(0) returns(0) { | ||
//Input Stack [result,xn,x] | ||
dup2 // [xn,result,xn,x] | ||
0x100 // [0x100,xn,result,xn,x] | ||
gt // [0x100>xn,result,xn,x] | ||
iszero | ||
satisfied | ||
jumpi | ||
|
||
satisfied: | ||
4 shl // [result<<4,xn,x] | ||
swap1 // [xn,result<<4,x] | ||
8 shr // [xn >> 8,result<<4,x] | ||
swap1 // [result<<4,xn >>8] | ||
} | ||
#define macro GATE6() = takes(0) returns(0) { | ||
//Input Stack [result,xn,x] | ||
dup2 // [xn,result,xn,x] | ||
0x10 // [0x10,xn,result,xn,x] | ||
gt // [0x10>xn,result,xn,x] | ||
iszero | ||
satisfied | ||
jumpi | ||
|
||
satisfied: | ||
2 shl // [result<<2,xn,x] | ||
swap1 // [xn,result<<2,x] | ||
4 shr // [xn >> 4,result<<2,x] | ||
swap1 // [result<<2,xn >>4] | ||
} | ||
|
||
#define macro GATE7() = takes(0) returns(0) { | ||
//Input Stack [result,xn,x] | ||
dup2 // [xn,result,xn,x] | ||
0x4 // [0x4,xn,result,xn,x] | ||
gt // [0x4>xn,result,xn,x] | ||
iszero | ||
satisfied | ||
jumpi | ||
|
||
satisfied: | ||
1 shl // [result<<1,xn,x] | ||
} | ||
|
||
#define macro LOG2() = takes(0) returns(0) { | ||
|
||
} | ||
|
||
#define macro MOST_SIGNIFICANT_BIT() = takes(0) returns(0) { | ||
// Input Stack => [x] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters