baseline: Decide which instruction implementations to inline into the dispatch loop

Đang mở
#1,813 0 bình luận 0 reaction 0 người được giao Xem trên GitHub

Maintainer thường phản hồi trong vòng 1 ngày

Chưa có ai nhận issue này.

Đánh giá

Độ khó
5/5
Thời gian dự kiến
Hơn một tuần
Mức phù hợp với người mới
12/100
Loại issue
Tái cấu trúc
Độ rõ ràng
Khá rõ ràng
Mức độ hoạt động
Sôi nổi
Công nghệ
cpp
Lĩnh vực
compilers, performance

Hướng nghiên cứu

The work is in the Baseline dispatch loops in baseline_execution.cpp and in intx's addmod(), sdivrem() and udivrem(). Start by building with GCC and Clang and checking the inlining decisions the issue describes. Done means a per-instruction inlining choice that is measured on random operands, at several code alignments, with branch-miss counters. This is a performance research task, not a first contribution.

Do mô hình lập chỉ mục viết ra từ nội dung của issue.

Mô tả

Which instruction implementations are inlined into the Baseline dispatch loops (dispatch_cgoto, dispatch<false>, dispatch<true>) is left to the compilers' inlining heuristics. The same goes for which intx functions are inlined into those implementations. The heuristics weigh code size, not how hot or how expensive an instruction is, so unrelated size changes in evmone or intx move handlers in or out of the loops.

  • GCC inlines into baseline_execution.cpp until the file has grown by --param inline-unit-growth (40%). It also lets a large function grow only by large-function-growth (100%). The dispatch loops sit at this limit:
    • SAR, LOG1–4, CALLDATACOPY, CODECOPY and EXTCODECOPY are left out.
    • LOG0, MCOPY and RETURNDATACOPY move in and out with small changes in intx. For example, a smaller SLT in chfast/intx#453 pulls LOG0 in. The larger exp() of chfast/intx#455 turns the EXP handler into a call and pulls LOG0 and MCOPY in.
  • Clang decides per call site and keeps larger intx functions behind calls. The 256-bit results then take extra copies through memory, see ADDMOD below.
  • Relayout: every such change also relayouts the loops, and the dispatch branch prediction depends on the layout. With GCC the chained-MUL benchmark runs in one of two states: 0.46M or 6.4M branch misses per 3 executions, with identical instructions and 1.5–2.4× the cycles.

Options

  • Decide per instruction in evmone: [[gnu::always_inline]], [[gnu::noinline]] or [[gnu::flatten]] on the implementations, possibly different for GCC and Clang.
  • Raise GCC's budget for baseline_execution.cpp only:
    • Use --param=inline-unit-growth=100 and --param=large-function-growth=200.

    • In a prototype at x86-64-v3, this pins the current decisions and inlines the left-out handlers:

      change
      SAR −2…−4%
      CODECOPY −3…−9%
      CALLDATACOPY −1…−5%
      RETURNDATACOPY −1…−4%
      evm-benchmarks ±2%
      snailtracer −3.8%
      .text +6.8 KB (v2), +8.7 KB (v3)
  • Attributes in intx instead: they also affect intx's other users.

Items to check

Measure each item with per-instruction contracts on random (worst-case) operands, at 3 code alignments, and with branch-miss counters.

  • ADDMOD with Clang.
    • What happens: intx::addmod() (127 instructions) stays out of line. It copies the remainder out of the division result with a 32-byte load right after udivrem()'s 8-byte stores. The load fails store forwarding, which costs about 11% of the cycles of an ADDMOD loop. The handler then copies the returned value again.

    • [[clang::always_inline]] on intx::addmod() (x86-64-v3, 3 code alignments, ADDMOD contracts):

      modulus change
      1–4 words −5…−8%
      BN254 −16…−18%

      GCC's code is identical.

    • The same with [[gnu::always_inline]]: GCC gets slower. GCC already inlines the fast path of addmod() into the loop, and with the attribute the whole handler leaves the loop. BN254 +20%; chains of reduced ADDMODs +16% (v3) and +44% (v2).

    • Side cost: with a zero modulus, the cheapest case, ADDMOD pays for the handler's frame: +24 cycles.

  • SDIV/SMOD with Clang. intx::sdivrem() stays out of line and returns its 64-byte result through memory. The copy of the result fails store forwarding. [[gnu::always_inline]] on it: Clang −10…−18%, GCC at x86-64-v3 up to +4.6% (its handlers then sit behind a call).
  • EXP with GCC: a call instead of inlined after chfast/intx#455.
  • SAR, LOG1–4, CALLDATACOPY, CODECOPY, EXTCODECOPY with GCC: left out by the budget.
Ngôn ngữ chính
C++
Star
979
Fork
340
Merge trung bình
12 giờ 16 phút
Pull request đã merge (30 ngày)
25

Chuẩn bị môi trường

  • Có Dockerfile hoặc tệp Docker Compose
  • Không có mẫu pull request
  • Không có hướng dẫn đóng góp

Bắt đầu từ đâu

  1. Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
  2. Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
  3. Fork repository và làm thay đổi trên một nhánh.
  4. Mở pull request có tham chiếu số hiệu của issue.

Issue khác của ipsilon/evmone

Tất cả issue của ipsilon/evmone

Issue tương tự

Thêm issue về C++

Nhận issue mới trong hộp thư của bạn

Bản tóm tắt ngắn những issue GitHub phù hợp với người mới.