Skip to content

Commit

Permalink
remove prb math
Browse files Browse the repository at this point in the history
  • Loading branch information
thedavidmeister committed Aug 22, 2024
1 parent 23d2915 commit 24f82fc
Show file tree
Hide file tree
Showing 22 changed files with 873 additions and 877 deletions.
3 changes: 0 additions & 3 deletions .gitmodules
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,6 @@
[submodule "lib/rain.lib.memkv"]
path = lib/rain.lib.memkv
url = https://github.com/rainprotocol/rain.lib.memkv
[submodule "lib/prb-math"]
path = lib/prb-math
url = https://github.com/PaulRBerg/prb-math
[submodule "lib/sol.lib.binmaskflag"]
path = lib/sol.lib.binmaskflag
url = https://github.com/rainprotocol/sol.lib.binmaskflag
Expand Down
1 change: 0 additions & 1 deletion lib/prb-math
Submodule prb-math deleted from 77fa88
38 changes: 19 additions & 19 deletions src/lib/op/LibAllStandardOpsNP.sol
Original file line number Diff line number Diff line change
Expand Up @@ -58,39 +58,39 @@ import {LibOpIsZeroNP} from "./logic/LibOpIsZeroNP.sol";
import {LibOpLessThanNP} from "./logic/LibOpLessThanNP.sol";
import {LibOpLessThanOrEqualToNP} from "./logic/LibOpLessThanOrEqualToNP.sol";

import {LibOpExponentialGrowth} from "./math/growth/LibOpExponentialGrowth.sol";
import {LibOpLinearGrowth} from "./math/growth/LibOpLinearGrowth.sol";
// import {LibOpExponentialGrowth} from "./math/growth/LibOpExponentialGrowth.sol";
// import {LibOpLinearGrowth} from "./math/growth/LibOpLinearGrowth.sol";

import {LibOpUint256Div} from "./math/uint256/LibOpUint256Div.sol";
import {LibOpUint256Mul} from "./math/uint256/LibOpUint256Mul.sol";
import {LibOpUint256Pow} from "./math/uint256/LibOpUint256Pow.sol";

import {LibOpAdd} from "./math/LibOpAdd.sol";
import {LibOpAvg} from "./math/LibOpAvg.sol";
import {LibOpCeil} from "./math/LibOpCeil.sol";
import {LibOpMul} from "./math/LibOpMul.sol";
import {LibOpDiv} from "./math/LibOpDiv.sol";
// import {LibOpAvg} from "./math/LibOpAvg.sol";
// import {LibOpCeil} from "./math/LibOpCeil.sol";
// import {LibOpMul} from "./math/LibOpMul.sol";
// import {LibOpDiv} from "./math/LibOpDiv.sol";
import {LibOpE} from "./math/LibOpE.sol";
import {LibOpExp} from "./math/LibOpExp.sol";
import {LibOpExp2} from "./math/LibOpExp2.sol";
import {LibOpFloor} from "./math/LibOpFloor.sol";
import {LibOpFrac} from "./math/LibOpFrac.sol";
import {LibOpGm} from "./math/LibOpGm.sol";
import {LibOpHeadroom} from "./math/LibOpHeadroom.sol";
import {LibOpInv} from "./math/LibOpInv.sol";
import {LibOpLn} from "./math/LibOpLn.sol";
import {LibOpLog10} from "./math/LibOpLog10.sol";
// import {LibOpExp} from "./math/LibOpExp.sol";
// import {LibOpExp2} from "./math/LibOpExp2.sol";
// import {LibOpFloor} from "./math/LibOpFloor.sol";
// import {LibOpFrac} from "./math/LibOpFrac.sol";
// import {LibOpGm} from "./math/LibOpGm.sol";
// import {LibOpHeadroom} from "./math/LibOpHeadroom.sol";
// import {LibOpInv} from "./math/LibOpInv.sol";
// import {LibOpLn} from "./math/LibOpLn.sol";
// import {LibOpLog10} from "./math/LibOpLog10.sol";
import {LibOpMax} from "./math/LibOpMax.sol";
import {LibOpMin} from "./math/LibOpMin.sol";
import {LibOpMod} from "./math/LibOpMod.sol";
import {LibOpLog2} from "./math/LibOpLog2.sol";
import {LibOpPow} from "./math/LibOpPow.sol";
// import {LibOpLog2} from "./math/LibOpLog2.sol";
// import {LibOpPow} from "./math/LibOpPow.sol";
import {LibOpScale18Dynamic} from "./math/LibOpScale18Dynamic.sol";
import {LibOpScale18} from "./math/LibOpScale18.sol";
import {LibOpScaleNDynamic} from "./math/LibOpScaleNDynamic.sol";
import {LibOpScaleN} from "./math/LibOpScaleN.sol";
import {LibOpSnapToUnit} from "./math/LibOpSnapToUnit.sol";
import {LibOpSqrt} from "./math/LibOpSqrt.sol";
// import {LibOpSnapToUnit} from "./math/LibOpSnapToUnit.sol";
// import {LibOpSqrt} from "./math/LibOpSqrt.sol";
import {LibOpSub} from "./math/LibOpSub.sol";

import {LibOpGetNP} from "./store/LibOpGetNP.sol";
Expand Down
82 changes: 41 additions & 41 deletions src/lib/op/math/LibOpAvg.sol
Original file line number Diff line number Diff line change
@@ -1,46 +1,46 @@
// SPDX-License-Identifier: CAL
pragma solidity ^0.8.18;
// // SPDX-License-Identifier: CAL
// pragma solidity ^0.8.18;

import {UD60x18, avg} from "prb-math/UD60x18.sol";
import {Operand} from "rain.interpreter.interface/interface/unstable/IInterpreterV4.sol";
import {Pointer} from "rain.solmem/lib/LibPointer.sol";
import {InterpreterStateNP} from "../../state/LibInterpreterStateNP.sol";
import {IntegrityCheckStateNP} from "../../integrity/LibIntegrityCheckNP.sol";
// import {UD60x18, avg} from "prb-math/UD60x18.sol";
// import {Operand} from "rain.interpreter.interface/interface/unstable/IInterpreterV4.sol";
// import {Pointer} from "rain.solmem/lib/LibPointer.sol";
// import {InterpreterStateNP} from "../../state/LibInterpreterStateNP.sol";
// import {IntegrityCheckStateNP} from "../../integrity/LibIntegrityCheckNP.sol";

/// @title LibOpAvg
/// @notice Opcode for the average of two decimal 18 fixed point numbers.
library LibOpAvg {
function integrity(IntegrityCheckStateNP memory, Operand) internal pure returns (uint256, uint256) {
// There must be two inputs and one output.
return (2, 1);
}
// /// @title LibOpAvg
// /// @notice Opcode for the average of two decimal 18 fixed point numbers.
// library LibOpAvg {
// function integrity(IntegrityCheckStateNP memory, Operand) internal pure returns (uint256, uint256) {
// // There must be two inputs and one output.
// return (2, 1);
// }

/// avg
/// 18 decimal fixed point average of two numbers.
function run(InterpreterStateNP memory, Operand, Pointer stackTop) internal pure returns (Pointer) {
uint256 a;
uint256 b;
assembly ("memory-safe") {
a := mload(stackTop)
stackTop := add(stackTop, 0x20)
b := mload(stackTop)
}
a = UD60x18.unwrap(avg(UD60x18.wrap(a), UD60x18.wrap(b)));
// /// avg
// /// 18 decimal fixed point average of two numbers.
// function run(InterpreterStateNP memory, Operand, Pointer stackTop) internal pure returns (Pointer) {
// uint256 a;
// uint256 b;
// assembly ("memory-safe") {
// a := mload(stackTop)
// stackTop := add(stackTop, 0x20)
// b := mload(stackTop)
// }
// a = UD60x18.unwrap(avg(UD60x18.wrap(a), UD60x18.wrap(b)));

assembly ("memory-safe") {
mstore(stackTop, a)
}
return stackTop;
}
// assembly ("memory-safe") {
// mstore(stackTop, a)
// }
// return stackTop;
// }

/// Gas intensive reference implementation of avg for testing.
function referenceFn(InterpreterStateNP memory, Operand, uint256[] memory inputs)
internal
pure
returns (uint256[] memory)
{
uint256[] memory outputs = new uint256[](1);
outputs[0] = UD60x18.unwrap(avg(UD60x18.wrap(inputs[0]), UD60x18.wrap(inputs[1])));
return outputs;
}
}
// /// Gas intensive reference implementation of avg for testing.
// function referenceFn(InterpreterStateNP memory, Operand, uint256[] memory inputs)
// internal
// pure
// returns (uint256[] memory)
// {
// uint256[] memory outputs = new uint256[](1);
// outputs[0] = UD60x18.unwrap(avg(UD60x18.wrap(inputs[0]), UD60x18.wrap(inputs[1])));
// return outputs;
// }
// }
76 changes: 38 additions & 38 deletions src/lib/op/math/LibOpCeil.sol
Original file line number Diff line number Diff line change
@@ -1,43 +1,43 @@
// SPDX-License-Identifier: CAL
pragma solidity ^0.8.18;
// // SPDX-License-Identifier: CAL
// pragma solidity ^0.8.18;

import {UD60x18, ceil} from "prb-math/UD60x18.sol";
import {Operand} from "rain.interpreter.interface/interface/unstable/IInterpreterV4.sol";
import {Pointer} from "rain.solmem/lib/LibPointer.sol";
import {InterpreterStateNP} from "../../state/LibInterpreterStateNP.sol";
import {IntegrityCheckStateNP} from "../../integrity/LibIntegrityCheckNP.sol";
// import {UD60x18, ceil} from "prb-math/UD60x18.sol";
// import {Operand} from "rain.interpreter.interface/interface/unstable/IInterpreterV4.sol";
// import {Pointer} from "rain.solmem/lib/LibPointer.sol";
// import {InterpreterStateNP} from "../../state/LibInterpreterStateNP.sol";
// import {IntegrityCheckStateNP} from "../../integrity/LibIntegrityCheckNP.sol";

/// @title LibOpCeil
/// @notice Opcode for the ceiling of an decimal 18 fixed point number.
library LibOpCeil {
function integrity(IntegrityCheckStateNP memory, Operand) internal pure returns (uint256, uint256) {
// There must be one inputs and one output.
return (1, 1);
}
// /// @title LibOpCeil
// /// @notice Opcode for the ceiling of an decimal 18 fixed point number.
// library LibOpCeil {
// function integrity(IntegrityCheckStateNP memory, Operand) internal pure returns (uint256, uint256) {
// // There must be one inputs and one output.
// return (1, 1);
// }

/// ceil
/// 18 decimal fixed point ceiling of a number.
function run(InterpreterStateNP memory, Operand, Pointer stackTop) internal pure returns (Pointer) {
uint256 a;
assembly ("memory-safe") {
a := mload(stackTop)
}
a = UD60x18.unwrap(ceil(UD60x18.wrap(a)));
// /// ceil
// /// 18 decimal fixed point ceiling of a number.
// function run(InterpreterStateNP memory, Operand, Pointer stackTop) internal pure returns (Pointer) {
// uint256 a;
// assembly ("memory-safe") {
// a := mload(stackTop)
// }
// a = UD60x18.unwrap(ceil(UD60x18.wrap(a)));

assembly ("memory-safe") {
mstore(stackTop, a)
}
return stackTop;
}
// assembly ("memory-safe") {
// mstore(stackTop, a)
// }
// return stackTop;
// }

/// Gas intensive reference implementation of ceil for testing.
function referenceFn(InterpreterStateNP memory, Operand, uint256[] memory inputs)
internal
pure
returns (uint256[] memory)
{
uint256[] memory outputs = new uint256[](1);
outputs[0] = UD60x18.unwrap(ceil(UD60x18.wrap(inputs[0])));
return outputs;
}
}
// /// Gas intensive reference implementation of ceil for testing.
// function referenceFn(InterpreterStateNP memory, Operand, uint256[] memory inputs)
// internal
// pure
// returns (uint256[] memory)
// {
// uint256[] memory outputs = new uint256[](1);
// outputs[0] = UD60x18.unwrap(ceil(UD60x18.wrap(inputs[0])));
// return outputs;
// }
// }
Loading

0 comments on commit 24f82fc

Please sign in to comment.