speccpu/x264: add x264 mc src, add printf to weight->i_scale
This commit is contained in:
@@ -1,3 +1,4 @@
|
||||
import importlib.resources
|
||||
import os
|
||||
import shutil
|
||||
from pathlib import Path
|
||||
@@ -8,6 +9,49 @@ def get_mc_path(build):
|
||||
return build / "x264_src" / "common" / "mc.c"
|
||||
|
||||
|
||||
class MCBuilder:
|
||||
@staticmethod
|
||||
def get_src():
|
||||
assert __package__ is not None
|
||||
with importlib.resources.open_text(__package__, "mc.c") as f:
|
||||
mc_src = f.read()
|
||||
return mc_src
|
||||
|
||||
def __init__(self):
|
||||
self.mc_src = self.get_src()
|
||||
|
||||
def with_print_weight(self):
|
||||
"""
|
||||
Insert a printf statement after the opening brace in the mc_weight function.
|
||||
"""
|
||||
target_declaration = "static inline void mc_weight"
|
||||
printf_statement = ' printf("weight->i_scale = %d\\n", weight->i_scale);'
|
||||
|
||||
# Find the position of the target function declaration
|
||||
start_index = self.mc_src.find(target_declaration)
|
||||
if start_index == -1:
|
||||
raise ValueError("Could not find target function `mc_weight`")
|
||||
|
||||
# Find the position of the opening brace { after the target function declaration
|
||||
open_brace_index = self.mc_src.find("{", start_index)
|
||||
if open_brace_index == -1:
|
||||
raise ValueError("Could not find opening brace { for the target function")
|
||||
|
||||
# Insert printf statement after the opening brace
|
||||
self.mc_src = (
|
||||
self.mc_src[: open_brace_index + 1] # Original content up to {
|
||||
+ "\n"
|
||||
+ printf_statement # Insert printf statement
|
||||
+ "\n"
|
||||
+ self.mc_src[open_brace_index + 1 :] # Remaining content
|
||||
)
|
||||
|
||||
return self
|
||||
|
||||
def build(self):
|
||||
return self.mc_src
|
||||
|
||||
|
||||
def get_ref_add_pragma(mc_lines):
|
||||
# Initialize variables
|
||||
modified_lines = []
|
||||
@@ -83,11 +127,8 @@ def recompile_mc(mc_path: Path, build: Path, spec_env: os._Environ):
|
||||
# Run "make"
|
||||
return make(build, spec_env)
|
||||
|
||||
|
||||
def perf_ref(x264_run, perf_output):
|
||||
"""Run "perf" to profile x264 reference performance."""
|
||||
x264_cmd = [
|
||||
x264_run / "x264_s_base.mytest-m64",
|
||||
specinvoke_args = {
|
||||
"ref": [
|
||||
"--seek",
|
||||
"500",
|
||||
"--dumpyuv",
|
||||
@@ -99,6 +140,15 @@ def perf_ref(x264_run, perf_output):
|
||||
"BuckBunny.yuv",
|
||||
"1280x720",
|
||||
]
|
||||
}
|
||||
|
||||
|
||||
def perf_ref(x264_run, perf_output):
|
||||
"""Run "perf" to profile x264 reference performance."""
|
||||
x264_cmd = [
|
||||
x264_run / "x264_s_base.mytest-m64",
|
||||
*specinvoke_args["ref"],
|
||||
]
|
||||
run(
|
||||
[
|
||||
"perf",
|
||||
|
||||
Reference in New Issue
Block a user