Skip to content
This repository has been archived by the owner on Oct 28, 2021. It is now read-only.

Commit

Permalink
Update shift test examples
Browse files Browse the repository at this point in the history
  • Loading branch information
gcolvin authored and axic committed Feb 22, 2018
1 parent fcda859 commit 843f97d
Show file tree
Hide file tree
Showing 4 changed files with 234 additions and 17 deletions.
2 changes: 1 addition & 1 deletion libevm/VM.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -626,7 +626,7 @@ void VM::interpretCases()
}
NEXT

#if EVM_USE_BITSHIFT
#if EIP_145
CASE(SHL)
{
ON_OP();
Expand Down
8 changes: 5 additions & 3 deletions libevm/VMConfig.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,11 +25,13 @@ namespace eth
//
// interpreter configuration macros for development, optimizations and tracing
//
// EVM_USE_BITSHIFT - EIP145 bitwise shifting
// EIP_145 - bitwise shifting
//
// EIP_615 - subroutines and static jumps
// EIP_616 - SIMD
//
// EVM_OPTIMIZE - all optimizations off when false (TO DO - MAKE DYNAMIC)
//
// EVM_SWITCH_DISPATCH - dispatch via loop and switch
// EVM_JUMP_DISPATCH - dispatch via a jump table - available only on GCC
//
Expand All @@ -39,8 +41,8 @@ namespace eth
//
// EVM_TRACE - provides various levels of tracing

#ifndef EVM_USE_BITSHIFT
#define EVM_USE_BITSHIFT false
#ifndef EIP_145
#define EIP_145 false
#endif

#ifndef EIP_615
Expand Down
16 changes: 3 additions & 13 deletions test/unittests/performance/rc5.sol
Original file line number Diff line number Diff line change
Expand Up @@ -3,25 +3,15 @@ pragma solidity ^0.4.0;
// https://people.csail.mit.edu/rivest/Rivest-rc5rev.pdf

contract rc5 {

// don't I wish we had opcodes and operators for these

function shift_left(uint32 v, uint32 n) internal returns (uint32) {
return v *= uint32(2)**n;
}

function shift_right(uint32 v, uint32 n) internal returns (uint32) {
return v *= uint32(2)**n;
}

function rotate_left(uint32 v, uint32 n) internal returns (uint32) {
n &= 0x1f;
return shift_left(v, n) | shift_right(v, 32 - n);
return v << n | v >> (32 - n);
}

function rotate_right(uint32 v, uint32 n) internal returns (uint32) {
n &= 0x1f;
return shift_right(v, n) | shift_left(v, 32 - n);
return v >> n | v << (32 - n);
}

function encrypt(uint32[26] S, uint32[4] inout) {
Expand Down Expand Up @@ -94,4 +84,4 @@ contract rc5 {
for (int i = 0; i < 43690; ++i)
test(box, messg);
}
}
}
225 changes: 225 additions & 0 deletions test/unittests/performance/shift-tests.asm
Original file line number Diff line number Diff line change
@@ -0,0 +1,225 @@
{
let r := 0
0xffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff
256
shl
=: r
switch r
case 0 {
}
default {
0
0
revert
}

///
r := 0
2
1
shl
=: r
switch r
case 4 {
}
default {
0
0
revert
}

///
r := 0
0xffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff
1
shl
=: r
switch r
case 0xfffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffe {
}
default {
0
0
revert
}

///
r := 0
0x8000000000000000000000000000000000000000000000000000000000000000
1
shl
=: r
switch r
case 0 {
}
default {
0
0
revert
}

///
r := 0
3
255
shl
=: r
switch r
case 0x8000000000000000000000000000000000000000000000000000000000000000 {
}
default {
0
0
revert
}

///
r := 0
0xffffffff
224
shl
=: r
switch r
case 0xffffffff00000000000000000000000000000000000000000000000000000000 {
}
default {
0
0
revert
}

///
r := 0
2
1
shr
=: r
switch r
case 1 {
}
default {
0
0
revert
}

///
r := 0
0xffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff
256
shr
=: r
switch r
case 0 {
}
default {
0
0
revert
}

///
r := 0
0xffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff
1
shr
=: r
switch r
case 0x7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff {
}
default {
0
0
revert
}

///
r := 0
0x7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff
1
shr
=: r
switch r
case 0x3fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff {
}
default {
0
0
revert
}

///
r := 0
0x8000000000000000000000000000000000000000000000000000000000000000
1
shr
=: r
switch r
case 0x4000000000000000000000000000000000000000000000000000000000000000 {
}
default {
0
0
revert
}

///
r := 0
0xffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff
256
sar
=: r
switch r
case 0xffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff {
}
default {
0
0
revert
}

///
0x7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff
256
sar
=: r
switch r
case 0 {
}
default {
0
0
revert
}

///
r := 0
0xffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff
1
sar
=: r
switch r
case 0xffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff {
}
default {
0
0
revert
}

///
r := 0
0x7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff
1
sar
=: r
switch r
case 0x3fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff {
stop
}
default {
0
0
revert
}
}

0 comments on commit 843f97d

Please sign in to comment.