diff mbox series

[v2,04/32] target/mips: Use dup_const() to simplify

Message ID 20211027180730.1551932-5-f4bug@amsat.org
State New
Headers show
Series target/mips: Fully convert MSA opcodes to decodetree | expand

Commit Message

Philippe Mathieu-Daudé Oct. 27, 2021, 6:07 p.m. UTC
The dup_const() helper makes the code easier to follow, use it.

Signed-off-by: Philippe Mathieu-Daudé <f4bug@amsat.org>
---
 target/mips/tcg/msa_translate.c | 23 +++--------------------
 1 file changed, 3 insertions(+), 20 deletions(-)

Comments

Richard Henderson Oct. 27, 2021, 7:06 p.m. UTC | #1
On 10/27/21 11:07 AM, Philippe Mathieu-Daudé wrote:
> +    uint64_t eval_big = dup_const(df, 0x80);
>       TCGv_i64 t0 = tcg_temp_new_i64();
>       TCGv_i64 t1 = tcg_temp_new_i64();
> -    switch (df) {
> -    case DF_BYTE:
> -        eval_zero_or_big = 0x0101010101010101ULL;
> -        eval_big = 0x8080808080808080ULL;
> -        break;
> -    case DF_HALF:
> -        eval_zero_or_big = 0x0001000100010001ULL;
> -        eval_big = 0x8000800080008000ULL;
> -        break;
> -    case DF_WORD:
> -        eval_zero_or_big = 0x0000000100000001ULL;
> -        eval_big = 0x8000000080000000ULL;
> -        break;
> -    case DF_DOUBLE:
> -        eval_zero_or_big = 0x0000000000000001ULL;
> -        eval_big = 0x8000000000000000ULL;

The conversion is incorrect for eval_big.
The conversion creates e.g.

     0x0080 0080 0080 0080
not
     0x8000 8000 8000 8000

You'd have to do something like

     uint64_t eval_one = dup_const(df, 1);
     uint64_t eval_big = eval_one << ((8 << df) - 1);

r~
Philippe Mathieu-Daudé Oct. 28, 2021, 8:53 p.m. UTC | #2
On 10/27/21 21:06, Richard Henderson wrote:
> On 10/27/21 11:07 AM, Philippe Mathieu-Daudé wrote:
>> +    uint64_t eval_big = dup_const(df, 0x80);
>>       TCGv_i64 t0 = tcg_temp_new_i64();
>>       TCGv_i64 t1 = tcg_temp_new_i64();
>> -    switch (df) {
>> -    case DF_BYTE:
>> -        eval_zero_or_big = 0x0101010101010101ULL;
>> -        eval_big = 0x8080808080808080ULL;
>> -        break;
>> -    case DF_HALF:
>> -        eval_zero_or_big = 0x0001000100010001ULL;
>> -        eval_big = 0x8000800080008000ULL;
>> -        break;
>> -    case DF_WORD:
>> -        eval_zero_or_big = 0x0000000100000001ULL;
>> -        eval_big = 0x8000000080000000ULL;
>> -        break;
>> -    case DF_DOUBLE:
>> -        eval_zero_or_big = 0x0000000000000001ULL;
>> -        eval_big = 0x8000000000000000ULL;
> 
> The conversion is incorrect for eval_big.
> The conversion creates e.g.
> 
>     0x0080 0080 0080 0080
> not
>     0x8000 8000 8000 8000

Oops...

> You'd have to do something like
> 
>     uint64_t eval_one = dup_const(df, 1);
>     uint64_t eval_big = eval_one << ((8 << df) - 1);

Nice :)
diff mbox series

Patch

diff --git a/target/mips/tcg/msa_translate.c b/target/mips/tcg/msa_translate.c
index 3ef912da6b8..bc57e06d923 100644
--- a/target/mips/tcg/msa_translate.c
+++ b/target/mips/tcg/msa_translate.c
@@ -313,28 +313,11 @@  static void gen_check_zero_element(TCGv tresult, uint8_t df, uint8_t wt,
 {
     /* generates tcg ops to check if any element is 0 */
     /* Note this function only works with MSA_WRLEN = 128 */
-    uint64_t eval_zero_or_big = 0;
-    uint64_t eval_big = 0;
+    uint64_t eval_zero_or_big = dup_const(df, 0x01);
+    uint64_t eval_big = dup_const(df, 0x80);
     TCGv_i64 t0 = tcg_temp_new_i64();
     TCGv_i64 t1 = tcg_temp_new_i64();
-    switch (df) {
-    case DF_BYTE:
-        eval_zero_or_big = 0x0101010101010101ULL;
-        eval_big = 0x8080808080808080ULL;
-        break;
-    case DF_HALF:
-        eval_zero_or_big = 0x0001000100010001ULL;
-        eval_big = 0x8000800080008000ULL;
-        break;
-    case DF_WORD:
-        eval_zero_or_big = 0x0000000100000001ULL;
-        eval_big = 0x8000000080000000ULL;
-        break;
-    case DF_DOUBLE:
-        eval_zero_or_big = 0x0000000000000001ULL;
-        eval_big = 0x8000000000000000ULL;
-        break;
-    }
+
     tcg_gen_subi_i64(t0, msa_wr_d[wt << 1], eval_zero_or_big);
     tcg_gen_andc_i64(t0, t0, msa_wr_d[wt << 1]);
     tcg_gen_andi_i64(t0, t0, eval_big);