tcg: workaround branch instruction overflow in tcg_out_qemu_ld/st
RFC v2 1/1 tcg: workaround branch instruction overflow in tcg_out_qemu_ld/st
ppc64 uses a BC instruction to call the tcg_out_qemu_ld/st slow path. BC instruction uses a relative address encoded on 14 bits.
The slow path functions are added at the end of the generated instructions buffer, in the reverse order of the callers. So more we have slow path functions more the distance between the caller (BC) and the function increases.
This patch changes the behavior to generate the functions in the same order of the callers.
---
Notes:
v2:
- add a pointer to the tail of the list to add new element at the end and keep the original ordering
- remove the recursive call
tcg/tcg-ldst.inc.c | 11 ++++++++--- tcg/tcg.c | 3 ++- tcg/tcg.h | 3 ++- 3 files changed, 12 insertions(+), 5 deletions(-)
tcg/tcg-ldst.inc.c +8 -3
@@ -46,7 +46,7 @@ static bool tcg_out_ldst_finalize(TCGContext *s)TCGLabelQemuLdst *lb;/* qemu_ld/st slow paths */ -for (lb = s->ldst_labels; lb !=NULL ; lb = lb->next) { +for (lb = s->ldst_head; lb !=NULL ; lb = lb->next) {if (lb->is_ld) {tcg_out_qemu_ld_slow_path (s, lb); }else {
@@ -72,7 +72,12 @@ static inline TCGLabelQemuLdst *new_ldst_label(TCGContext *s) {TCGLabelQemuLdst *l =tcg_malloc (sizeof (*l)); - l->next = s->ldst_labels; - s->ldst_labels = l; + l->next =NULL ; +if (s->ldst_tail) { + s->ldst_tail->next = l; + }else { + s->ldst_head = l; + } + s->ldst_tail = l;return l; }
tcg/tcg.c +2 -1
@@ -3324,7 +3324,8 @@ int tcg_gen_code(TCGContext *s, TranslationBlock *tb) s->code_ptr = tb->tc.ptr;#ifdef TCG_TARGET_NEED_LDST_LABELS - s->ldst_labels =NULL ; + s->ldst_head =NULL ; + s->ldst_tail =NULL ;#endif #ifdef TCG_TARGET_NEED_POOL_LABELS s->pool_labels =NULL ;
tcg/tcg.h +2 -1
@@ -699,7 +699,8 @@ struct TCGContext {/* These structures are private to tcg-target.inc.c. */ #ifdef TCG_TARGET_NEED_LDST_LABELS -struct TCGLabelQemuLdst *ldst_labels; +struct TCGLabelQemuLdst *ldst_head; +struct TCGLabelQemuLdst *ldst_tail;#endif #ifdef TCG_TARGET_NEED_POOL_LABELS struct TCGLabelPoolData *pool_labels;
Signature · 1 line
2.14.3
Quoted 14 lines · Laurent Vivier
ppc64 uses a BC instruction to call the tcg_out_qemu_ld/st slow path. BC instruction uses a relative address encoded on 14 bits.
The slow path functions are added at the end of the generated instructions buffer, in the reverse order of the callers. So more we have slow path functions more the distance between the caller (BC) and the function increases.
This patch changes the behavior to generate the functions in the same order of the callers.
Fixes 15fa08f845 ("tcg: Dynamically allocate TCGOps")Signed-off-by Laurent Vivier <[email protected]>
Quoted 7 lines
---
Notes:
v2:
- add a pointer to the tail of the list to add new element at the end and keep the original ordering
- remove the recursive call
A much better approach.
Elsewhere in TCG I have used the QTAILQ macros for manipulating a double-linked list. Perhaps using QSIMPLEQ for the single-linked list with tail access would be the thing here? I'm not 100% sure it's cleaner, but maybe worth a look.
r~