Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Introduce Value type for operands #419

Merged
merged 6 commits into from
Jul 30, 2020
Merged

Introduce Value type for operands #419

merged 6 commits into from
Jul 30, 2020

Conversation

chfast
Copy link
Collaborator

@chfast chfast commented Jul 15, 2020

The Value is an union for now containing only i64 value. Later to be extended with f32, f64 and maybe i32.

I added implicit conversions from/to uint64_t to limit the number of required changes.

The conversion from std::initializer_list<uint64_t> not possible in a type safe manner. I guess we will need something like template<typename T...> TypedArgs to construct a container of Values. This will also handle usage of different value types in execution invocation.

All will get more complicated if we want constructor from other types (e.g. float, unsigned int) as we will get ambiguities (e.g. 0 is of type int and will not know where to go).

@chfast chfast force-pushed the value_type branch 2 times, most recently from 791cbee to f3ae080 Compare July 15, 2020 11:39
@codecov
Copy link

codecov bot commented Jul 15, 2020

Codecov Report

Merging #419 into master will decrease coverage by 0.01%.
The diff coverage is 96.80%.

@@            Coverage Diff             @@
##           master     #419      +/-   ##
==========================================
- Coverage   99.55%   99.54%   -0.02%     
==========================================
  Files          49       51       +2     
  Lines       14604    14632      +28     
==========================================
+ Hits        14539    14565      +26     
- Misses         65       67       +2     

@chfast chfast requested review from gumb0 and axic July 15, 2020 11:48
@chfast chfast force-pushed the value_type branch 2 times, most recently from e0c084e to 5ae0db3 Compare July 15, 2020 13:57
@@ -611,7 +611,7 @@ execution_result execute(Instance& instance, FuncIdx func_idx, span<const uint64
const auto& code = instance.module.codesec[code_idx];
auto* const memory = instance.memory.get();

std::vector<uint64_t> locals(args.size() + code.local_count, 0);
std::vector<Value> locals(args.size() + code.local_count);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Doesn't this leave them uninitialized, because Value default constructor doesn't initialize it?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No.

  1. Vector is using value initialization and then copy to init elements.
  2. For unions, value initialization is zero initialization, i.e.
  3. If T is a union type, the first non-static named data member is zero-initialized and all padding is initialized to zero bits.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It looks the spec for it has changed in C++11, but the result is the same. But having/not-having default constructor that initializes with zero affects GCC code generation (looks like a bug rather) and the version without zeroing default constructor is faster as it fills locals by a loop instead of a memset call.

test/utils/fizzy_engine.cpp Outdated Show resolved Hide resolved
lib/fizzy/execute.cpp Outdated Show resolved Hide resolved
@chfast
Copy link
Collaborator Author

chfast commented Jul 28, 2020

I'm not sure what is going on here. Can someone recheck?

fizzy/execute/blake2b/512_bytes_rounds_1_mean                     -0.0934         -0.0935            87            79            87            79
fizzy/execute/blake2b/512_bytes_rounds_16_mean                    -0.0919         -0.0919          1321          1200          1321          1200
fizzy/execute/ecpairing/onepoint_mean                             -0.0438         -0.0438        421538        403078        421540        403082
fizzy/execute/keccak256/512_bytes_rounds_1_mean                   -0.0400         -0.0400            99            95            99            95
fizzy/execute/keccak256/512_bytes_rounds_16_mean                  -0.0412         -0.0412          1453          1394          1453          1394
fizzy/execute/memset/256_bytes_mean                               -0.0711         -0.0711             7             7             7             7
fizzy/execute/memset/60000_bytes_mean                             -0.0739         -0.0739          1548          1434          1548          1434
fizzy/execute/mul256_opt0/input0_mean                             +0.0096         +0.0096            26            26            26            26
fizzy/execute/mul256_opt0/input1_mean                             +0.0152         +0.0152            26            26            26            26
fizzy/execute/sha1/512_bytes_rounds_1_mean                        -0.0567         -0.0567            90            85            90            85
fizzy/execute/sha1/512_bytes_rounds_16_mean                       -0.0545         -0.0545          1256          1188          1256          1188
fizzy/execute/sha256/512_bytes_rounds_1_mean                      -0.0431         -0.0431            94            90            94            90
fizzy/execute/sha256/512_bytes_rounds_16_mean                     -0.0570         -0.0570          1298          1224          1298          1224
fizzy/execute/micro/eli_interpreter/halt_mean                     -0.1169         -0.1169             0             0             0             0
fizzy/execute/micro/eli_interpreter/exec105_mean                  -0.1125         -0.1125             5             4             5             4
fizzy/execute/micro/factorial/10_mean                             -0.0714         -0.0714             0             0             0             0
fizzy/execute/micro/factorial/20_mean                             -0.0578         -0.0578             1             1             1             1
fizzy/execute/micro/fibonacci/24_mean                             -0.0817         -0.0817          7454          6845          7454          6845
fizzy/execute/micro/host_adler32/1_mean                           -0.0277         -0.0277             0             0             0             0
fizzy/execute/micro/host_adler32/100_mean                         +0.0146         +0.0146             3             3             3             3
fizzy/execute/micro/host_adler32/1000_mean                        -0.0028         -0.0028            30            30            30            30
fizzy/execute/micro/spinner/1_mean                                -0.0521         -0.0521             0             0             0             0
fizzy/execute/micro/spinner/1000_mean                             -0.1717         -0.1717            10             8            10             8

@chfast chfast force-pushed the value_type branch 2 times, most recently from fcdb355 to df0ceb4 Compare July 28, 2020 20:10
@gumb0
Copy link
Collaborator

gumb0 commented Jul 29, 2020

I'm getting different looking results

fizzy/execute/blake2b/512_bytes_rounds_1_mean                     +0.0448         +0.0424           167           175           167           174
fizzy/execute/blake2b/512_bytes_rounds_16_mean                    +0.0494         +0.0483          2509          2633          2509          2630
fizzy/execute/ecpairing/onepoint_mean                             +0.0215         +0.0206        903364        922804        903306        921941
fizzy/execute/keccak256/512_bytes_rounds_1_mean                   +0.0184         +0.0181           207           210           207           210
fizzy/execute/keccak256/512_bytes_rounds_16_mean                  +0.0178         +0.0177          3087          3142          3087          3141
fizzy/execute/memset/256_bytes_mean                               +0.0344         +0.0343            13            14            13            14
fizzy/execute/memset/60000_bytes_mean                             +0.0302         +0.0301          2911          2999          2911          2998
fizzy/execute/mul256_opt0/input0_mean                             +0.0009         +0.0009            53            53            53            53
fizzy/execute/mul256_opt0/input1_mean                             +0.0040         +0.0040            53            53            53            53
fizzy/execute/sha1/512_bytes_rounds_1_mean                        +0.0716         +0.0716           174           187           174           187
fizzy/execute/sha1/512_bytes_rounds_16_mean                       +0.0815         +0.0813          2422          2619          2422          2619
fizzy/execute/sha256/512_bytes_rounds_1_mean                      +0.1057         +0.1058           164           182           164           182
fizzy/execute/sha256/512_bytes_rounds_16_mean                     +0.1080         +0.1081          2239          2481          2239          2481
fizzy/execute/micro/eli_interpreter/halt_mean                     +0.0670         +0.0670             0             0             0             0
fizzy/execute/micro/eli_interpreter/exec105_mean                  +0.0491         +0.0492             9            10             9            10
fizzy/execute/micro/factorial/10_mean                             -0.0099         -0.0099             1             1             1             1
fizzy/execute/micro/factorial/20_mean                             -0.0098         -0.0098             2             2             2             2
fizzy/execute/micro/fibonacci/24_mean                             -0.1453         -0.1453         18022         15404         18020         15403
fizzy/execute/micro/host_adler32/1_mean                           +0.0225         +0.0225             0             0             0             0
fizzy/execute/micro/host_adler32/100_mean                         -0.0001         -0.0001             6             6             6             6
fizzy/execute/micro/host_adler32/1000_mean                        +0.0004         +0.0004            64            64            64            64
fizzy/execute/micro/spinner/1_mean                                +0.0603         +0.0603             0             0             0             0
fizzy/execute/micro/spinner/1000_mean                             -0.0147         -0.0148            19            19            19            19

test/utils/asserts.cpp Outdated Show resolved Hide resolved
lib/fizzy/execute.cpp Outdated Show resolved Hide resolved
@chfast chfast merged commit fafd7ee into master Jul 30, 2020
@chfast chfast deleted the value_type branch July 30, 2020 15:23
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants