Giter Club home page Giter Club logo

Comments (4)

rajdakin avatar rajdakin commented on August 21, 2024 1

A good first step would be to dump the instructions the dynarec produces: BOX64_DYNAREC_DUMP=2 BOX64_TRACE=0-1 BOX64_TRACE_FILE=dump.txt <program>, then looking at the problematic addresses (note that the trace build* is quite helpful in this case). Note that BOX64_DYNAREC_TEST adds quite a lot of clutter, so if you can't see the issue you can try again with that option.
Also, a DUMP of 2 will add color (ANSI escape codes) to the output (you can read it using less -R). If you want to open it in a text editor, this will make the file much less readable; in this case, you should instead use a DUMP of 1.

*The trace build requires libzydis version v3.2.1: https://github.com/zyantific/zydis/tree/v3.2.1 (newer versions change the API).

from box64.

ptitSeb avatar ptitSeb commented on August 21, 2024 1

A bit of context about what those ADJUST FLAG11 do:
One of the x86 flags OF is on bit 11 of the xFlags. But on RV64, most (all?) operation that use an Immediate have a signed 12bits immediate. That means, if trying to use an immediat to set this bit, the value will get sign extensed (because bit 11 is the sign bit for a 12bit signed value).
To avoid more opcode when setting this bit (that is set/unset often), it's moved to a different place inside RV64 dynarec (one of the lower reserved bit, the F_OF2 macro). And it works fine (and quite fast). The olnly issue is when exchanging the flags register outside of the Dynarec: those ADJUST macro allow to swap/unswap this bit in place.

from box64.

Coekjan avatar Coekjan commented on August 21, 2024

@rajdakin Thanks for your hints. I further investigated the code and found these differences only occured when I used BOX64_DYNAREC_TEST=1. I saw this code:

#define GO_TRACE(A, B, s0) \
GETIP(addr); \
MV(A1, xRIP); \
FLAGS_ADJUST_TO11(xFlags, xFlags, s0); \
STORE_XEMU_CALL(s0); \
MOV64x(A2, B); \
CALL(A, -1); \
LOAD_XEMU_CALL(); \
FLAGS_ADJUST_FROM11(xFlags, xFlags, s0);

When I removed the FLAGS_ADJUST_TO11 & FLAGS_ADJUST_FROM11, python3.12 could run without any dynarec-interpreter differences even if I enabled BOX64_DYNAREC_TEST=1. Honestly, I don't know why we need FLAGS_ADJUST_* here, but I just suspected them doing something unexpected to the FLAGS.

from box64.

Coekjan avatar Coekjan commented on August 21, 2024

A bit of context about what those ADJUST FLAG11 do: One of the x86 flags OF is on bit 11 of the xFlags. But on RV64, most (all?) operation that use an Immediate have a signed 12bits immediate. That means, if trying to use an immediat to set this bit, the value will get sign extensed (because bit 11 is the sign bit for a 12bit signed value). To avoid more opcode when setting this bit (that is set/unset often), it's moved to a different place inside RV64 dynarec (one of the lower reserved bit, the F_OF2 macro). And it works fine (and quite fast). The olnly issue is when exchanging the flags register outside of the Dynarec: those ADJUST macro allow to swap/unswap this bit in place.

Thanks for your attention on this issue. And I now fully understand why we need these macros.

from box64.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.