// this line is added to create a gist. Empty file is not allowed.
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
// SPDX-License-Identifier: UNLICENSED | |
pragma solidity ^0.8.13; | |
import "forge-std/Script.sol"; | |
import "src/Counter.sol"; | |
import "src/LibClone.sol"; | |
contract CounterScript is Script { | |
function setUp() public { |
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
pragma solidity ^0.8.4; | |
library LibBit { | |
function msbPosition(uint256 value) internal pure returns(uint8 position) { | |
assembly { | |
if gt(value,0xFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF) { | |
value := shr(128,value) | |
position := add(128,position) | |
} | |
if gt(value,0xFFFFFFFFFFFFFFFF) { |
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
pragma solidity ^0.8.4; | |
library LibBit { | |
function msbPosition(uint256 value) internal pure returns(uint8 position) { | |
assembly { | |
// value > 2*128 - 1 | |
if gt(value,0xFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF) { | |
value := shr(128,value) | |
position := add(128,position) | |
} |
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
pragma solidity ^0.8.4; | |
library LibBit { | |
function lsbsolmate(uint256 x) pure internal returns(uint256 r){ | |
assembly { | |
// Set Only Right Most Bit all other 0 | |
//x := xor(x,and(x,sub(x,1))) | |
x:= and(x,add(not(x),1)) | |
// solmate log2 logic | |
r := shl(7, lt(0xffffffffffffffffffffffffffffffff, 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
function gcd(uint256 x, uint256 y) internal pure returns(uint256 z){ | |
assembly{ | |
for {} 1 {} { | |
if eq(y,0) { | |
z := x | |
break | |
} | |
let temp := mod(x,y) | |
x := y | |
y := temp |