-
Notifications
You must be signed in to change notification settings - Fork 562
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
[AArch64] Q/GE flags not saved/restored in drreg #4930
Comments
IIRC for ARM all these flags are in cpsr. So this is a porting error where AArch64 just kept the cpsr save/restore w/o considering the other flags? |
Looks like the core DR dr_save_arith_flags is also using just NZCV. What about full context saving/restoring for fcache_{enter,return} and clean calls? |
Clean calls seem to use And of course, clients using |
I also want to clarify my earlier comment about this issue causing extra drreg spills/restore:
This comes up when drreg is used to reserve aflags in multiple phases (#3823). E.g. if there's aflags spill and restore in app2app and insertion phases both. In this case, drreg sees app and app2app instrs in its liveness analysis. It wrongly sees that the app2app aflags are live, even though the
Full instrumented bb: https://gist.github.com/abhinav92003/c878379478b6c8ce2ebc50096986a1db |
If the Q and GE flags are never used by arithmetic GPR operations, maybe having "arith flag" preservation only look at NZCV is reasonable: the "arithmetic flags" are not supposed to cover all possible condition codes and does not include floating-point or SIMD-only status flags on any architecture. ARM (32-bit) is including Q and GE but is that only b/c they come for free with CPSR? |
A clean call's compiled callee could include SIMD operations that touch Q/GE, so that certainly seems like something that should be fixed. For drreg: so it is saving NZCV, but checking liveness of NZCVQGE? That mismatch is a problem. |
I see a mention of NZCV at https://dynamorio.org/page_aarch64_port.html but not much detail @AssadHashmi any idea whether it was a conscious decision to limit "arithmetic flags" to NZCV for AArch64, unlike for ARM? |
@AssadHashmi I found documentation for the Q flag, that says that it is used by SIMD instrs. But I couldn't find anything for the GE flag. Could you explain or provide some documentation for that? |
@derekbruening I can't say for certain as I wasn't involved in early AArch64 support but I get the impression it was a conscious decision to limit FP/SIMD until later in the development cycle. That's reflected in other areas like the decoder. |
@abhinav92003 AIUI the GE flag only appears in AArch32's PSTATE register: But not for AArch64: |
Looking at the spec, |
Today on AArch64, drreg uses
mrs
andmsr
to read and write aflags respectively viaDR_REG_NZCV
. This leaves out the Q (saturation) and GE (greater-or-equal) flags, which are considered a part of aflags by DR.dynamorio/core/ir/instr_api.h
Line 2433 in e8fc651
This causes issues with liveness analysis, which thinks that aflags are always live, and therefore always stores them to a slot in
drreg_reserve_aflags
. So, this optimisation is never invoked:dynamorio/ext/drreg/drreg.c
Line 1616 in e8fc651
We should either start saving/restoring Q and GE flags too, or if they are not required, skip them from liveness analysis to avoid the extra aflags spills/restores in drreg.
To read/write the Q flag, we may have to use FPSR:
https://developer.arm.com/documentation/100076/0100/instruction-set-overview/overview-of-aarch64-state/the-q-flag-in-aarch64-state
I couldn't find any documentation yet for the GE flag. Though DR does have it in code:
dynamorio/core/ir/instr_api.h
Line 2443 in e8fc651
The text was updated successfully, but these errors were encountered: