diff options
author | Anurag Dashputre <anurag4u80@gmail.com> | 2018-08-23 14:26:45 +0800 |
---|---|---|
committer | GitHub <noreply@github.com> | 2018-08-23 14:26:45 +0800 |
commit | 8497dcd721ff0a113374c0c1e1778d44265398a6 (patch) | |
tree | 2833ab7b3c7513647c0476d0e5d33dc11fcd6951 /docs/assembly.rst | |
parent | 55524788e2829b3a2b9c6c513f78ba2074aa3385 (diff) | |
parent | 410d288dfc2e08c42df58c7e01ad5c332ce92727 (diff) | |
download | dexon-solidity-8497dcd721ff0a113374c0c1e1778d44265398a6.tar dexon-solidity-8497dcd721ff0a113374c0c1e1778d44265398a6.tar.gz dexon-solidity-8497dcd721ff0a113374c0c1e1778d44265398a6.tar.bz2 dexon-solidity-8497dcd721ff0a113374c0c1e1778d44265398a6.tar.lz dexon-solidity-8497dcd721ff0a113374c0c1e1778d44265398a6.tar.xz dexon-solidity-8497dcd721ff0a113374c0c1e1778d44265398a6.tar.zst dexon-solidity-8497dcd721ff0a113374c0c1e1778d44265398a6.zip |
Merge branch 'develop' into anurag_issue_3667
Diffstat (limited to 'docs/assembly.rst')
-rw-r--r-- | docs/assembly.rst | 18 |
1 files changed, 4 insertions, 14 deletions
diff --git a/docs/assembly.rst b/docs/assembly.rst index 91ba076a..2cbad06f 100644 --- a/docs/assembly.rst +++ b/docs/assembly.rst @@ -82,7 +82,7 @@ you really know what you are doing. library VectorSum { // This function is less efficient because the optimizer currently fails to // remove the bounds checks in array access. - function sumSolidity(uint[] memory _data) public view returns (uint o_sum) { + function sumSolidity(uint[] memory _data) public pure returns (uint o_sum) { for (uint i = 0; i < _data.length; ++i) o_sum += _data[i]; } @@ -90,7 +90,7 @@ you really know what you are doing. // We know that we only access the array in bounds, so we can avoid the check. // 0x20 needs to be added to an array because the first slot contains the // array length. - function sumAsm(uint[] memory _data) public view returns (uint o_sum) { + function sumAsm(uint[] memory _data) public pure returns (uint o_sum) { for (uint i = 0; i < _data.length; ++i) { assembly { o_sum := add(o_sum, mload(add(add(_data, 0x20), mul(i, 0x20)))) @@ -99,7 +99,7 @@ you really know what you are doing. } // Same as above, but accomplish the entire code within inline assembly. - function sumPureAsm(uint[] memory _data) public view returns (uint o_sum) { + function sumPureAsm(uint[] memory _data) public pure returns (uint o_sum) { assembly { // Load the length (first 32 bytes) let len := mload(_data) @@ -378,23 +378,13 @@ used ``x_slot`` and to retrieve the byte-offset you used ``x_offset``. In assignments (see below), we can even use local Solidity variables to assign to. -Functions external to inline assembly can also be accessed: The assembly will -push their entry label (with virtual function resolution applied). The calling semantics -in solidity are: - - - the caller pushes ``return label``, ``arg1``, ``arg2``, ..., ``argn`` - - the call returns with ``ret1``, ``ret2``, ..., ``retm`` - -This feature is still a bit cumbersome to use, because the stack offset essentially -changes during the call, and thus references to local variables will be wrong. - .. code:: pragma solidity ^0.4.11; contract C { uint b; - function f(uint x) public returns (uint r) { + function f(uint x) public view returns (uint r) { assembly { r := mul(x, sload(b_slot)) // ignore the offset, we know it is zero } |