diff mbox

TCG: Fix I64-on-32bit-host temporaries

Message ID 1390146811-59936-1-git-send-email-agraf@suse.de
State New
Headers show

Commit Message

Alexander Graf Jan. 19, 2014, 3:53 p.m. UTC
We have cache pools of temporaries that we can reuse later when they've
already been allocated before.

These cache pools differenciate between the target TCG variable type they
contain. So we have one pool for I32 and one pool for I64 variables.

On a 32bit system, we can't work with 64bit registers though. So instead we
spawn two I32 temporaries for every I64 temporary we create. All caching
works the same way as on a real 64-bit system though: We create a cache entry
in the 64bit array for the first i32 index.

However, when we free such a temporary we free it to the pool of its type
(which is always i32 on 32bit systems) rather than its base_type (which is
i64 or i32 depending on the variable). This means we put a temporary that
is of base_type == i64 into the i32 preallocated temporary pool.

Eventually, this results in failures like this on 32bit hosts:

  qemu-system-ppc64: tcg/tcg.c:515: tcg_temp_new_internal: Assertion `ts->base_type == type' failed.

This patch makes the free routine use the base_type instead for the free case,
so it's consistent with the temporary allocation. It fixes the above failure
for me.

Signed-off-by: Alexander Graf <agraf@suse.de>
---
 tcg/tcg.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

Comments

Richard Henderson Jan. 21, 2014, 4:35 p.m. UTC | #1
On 01/19/2014 07:53 AM, Alexander Graf wrote:
> We have cache pools of temporaries that we can reuse later when they've
> already been allocated before.
> 
> These cache pools differenciate between the target TCG variable type they
> contain. So we have one pool for I32 and one pool for I64 variables.
> 
> On a 32bit system, we can't work with 64bit registers though. So instead we
> spawn two I32 temporaries for every I64 temporary we create. All caching
> works the same way as on a real 64-bit system though: We create a cache entry
> in the 64bit array for the first i32 index.
> 
> However, when we free such a temporary we free it to the pool of its type
> (which is always i32 on 32bit systems) rather than its base_type (which is
> i64 or i32 depending on the variable). This means we put a temporary that
> is of base_type == i64 into the i32 preallocated temporary pool.
> 
> Eventually, this results in failures like this on 32bit hosts:
> 
>   qemu-system-ppc64: tcg/tcg.c:515: tcg_temp_new_internal: Assertion `ts->base_type == type' failed.
> 
> This patch makes the free routine use the base_type instead for the free case,
> so it's consistent with the temporary allocation. It fixes the above failure
> for me.
> 
> Signed-off-by: Alexander Graf <agraf@suse.de>
> ---
>  tcg/tcg.c | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)

Reviewed-by: Richard Henderson <rth@twiddle.net>


r~
Peter Maydell Jan. 30, 2014, 1:59 p.m. UTC | #2
On 19 January 2014 15:53, Alexander Graf <agraf@suse.de> wrote:
> We have cache pools of temporaries that we can reuse later when they've
> already been allocated before.
>
> These cache pools differenciate between the target TCG variable type they
> contain. So we have one pool for I32 and one pool for I64 variables.
>
> On a 32bit system, we can't work with 64bit registers though. So instead we
> spawn two I32 temporaries for every I64 temporary we create. All caching
> works the same way as on a real 64-bit system though: We create a cache entry
> in the 64bit array for the first i32 index.
>
> However, when we free such a temporary we free it to the pool of its type
> (which is always i32 on 32bit systems) rather than its base_type (which is
> i64 or i32 depending on the variable). This means we put a temporary that
> is of base_type == i64 into the i32 preallocated temporary pool.
>
> Eventually, this results in failures like this on 32bit hosts:
>
>   qemu-system-ppc64: tcg/tcg.c:515: tcg_temp_new_internal: Assertion `ts->base_type == type' failed.
>
> This patch makes the free routine use the base_type instead for the free case,
> so it's consistent with the temporary allocation. It fixes the above failure
> for me.
>
> Signed-off-by: Alexander Graf <agraf@suse.de>

Thanks, applied. (This was breaking 'make check' on 32 bit hosts
so it seemed worth applying as a buildfix.)

-- PMM
diff mbox

Patch

diff --git a/tcg/tcg.c b/tcg/tcg.c
index 712438c..acd02b9 100644
--- a/tcg/tcg.c
+++ b/tcg/tcg.c
@@ -586,7 +586,7 @@  static void tcg_temp_free_internal(int idx)
     assert(ts->temp_allocated != 0);
     ts->temp_allocated = 0;
 
-    k = ts->type + (ts->temp_local ? TCG_TYPE_COUNT : 0);
+    k = ts->base_type + (ts->temp_local ? TCG_TYPE_COUNT : 0);
     set_bit(idx, s->free_temps[k].l);
 }