Quantcast
Channel: Raspberry Pi Forums
Viewing all articles
Browse latest Browse all 8082

SDK • Re: Any way of getting a uf2 without picotool?

$
0
0
I do not plan to get on Github ever, so I'll just do the wrong thing and post a few things here. I disagree with blaming MSVC. Also disclaimer: Since I am really behind on modern C++, I can't guarantee what I say is absolutely correct. Relevant ticket:

Picotool coprodis unusably slow with large program (W11) #106
https://github.com/raspberrypi/picotool/issues/106

Part of the code from main.cpp [6247]:

Code:

bool coprodis_command::execute(device_map &devices) {    auto in = get_file(ios::in);    std::stringstream buffer;    buffer << in->rdbuf();    auto contents = buffer.str();    std::regex instruction(        R"(([ 0-9a-f]{8}):\s*([0-9a-f]{2})(\s*)([0-9a-f]{2})\s+([0-9a-f]{2})\s*([0-9a-f]{2})\s*(.*))"    );    vector<vector<string>> insts = {};    vector<tuple<string,string,string>> proc_insts;    while (true)    {        std::smatch sm;        if (!std::regex_search(contents, sm, instruction)) break;        vector<string> tmp;        std::copy(sm.begin(), sm.end(), std::back_inserter(tmp));        insts.push_back(tmp);        contents = sm.suffix();    }
In perl, a dinosaur like me have certain patterns that we follow. Anyone with experience with perl text processing would know that if regexes are not anchored (^ in perl) they often perform poorly. The regex:

Code:

        R"(([ 0-9a-f]{8}):\s*([0-9a-f]{2})(\s*)([0-9a-f]{2})\s+([0-9a-f]{2})\s*([0-9a-f]{2})\s*(.*))"
scans for an instruction disassembly. But when the automata fails to match, the question is, at which point does it start the next attempt? Let's hope it's not from the beginning plus 1 char. Instead of the above, the file should be scanned one pass (aka the loop block in 6887), line-by-line with an anchored regex and if match fails, continue with the next line (iteration). Skip as quickly as we can.

Next, from what I studied, a match result has a pair of interators and should be as efficient as pointers. But then, the code does:

Code:

        contents = sm.suffix();
Where contents is a string object type. So I looked at:

https://cplusplus.com/reference/regex/sub_match/

and it says cast to string type is a copy. That's not going to be very efficient if the disassembly file is MBs in size. Both regex_search() and sm.suffix() will likely cause the loop to deviate from O(n), perhaps very strongly. A one-pass line-by-line text processing pattern will solve both problems.

[Edit] Added "line-by-line" in last sentence for clarity.

Statistics: Posted by katak255 — Fri Feb 14, 2025 5:53 am



Viewing all articles
Browse latest Browse all 8082

Trending Articles