ppc: Convert op_440_dlmzb to TCG
PATCH 1/1 ppc: Convert op_440_dlmzb to TCG
Replace {op,do}_440_dlmzb and op_440_dlmzb_update_Rc with inline TCG instructions.
The two loops of do_440_dlmzb are unrolled.
---
Compile-tested on Linux/amd64.
target-ppc/op.c +0 -19
@@ -839,25 +839,6 @@ void OPPROTO op_4xx_tlbwe_hi (void) }#endif -/* SPR micro-ops */ -/* 440 specific */ -void OPPROTO op_440_dlmzb (void) -{ -do_440_dlmzb (); -RETURN (); -} - -void OPPROTO op_440_dlmzb_update_Rc (void) -{ -if (T0 ==8 ) -T0 =0x2 ; -else if (T0 <4 ) -T0 =0x4 ; -else -T0 =0x8 ; -RETURN (); -} -#if !defined(CONFIG_USER_ONLY ) void OPPROTO op_store_pir (void) {
target-ppc/op_helper.c +0 -21
@@ -1754,27 +1754,6 @@ void do_store_403_pb (int num) }#endif -/* 440 specific */ -void do_440_dlmzb (void ) -{ -target_ulong mask; -int i; - - i =1 ; -for (mask =0xFF000000 ; mask !=0 ; mask = mask >>8 ) { -if ((T0 & mask) ==0 ) - goto done; - i++; - } -for (mask =0xFF000000 ; mask !=0 ; mask = mask >>8 ) { -if ((T1 & mask) ==0 ) -break ; - i++; - } - done: -T0 = i; -} - /
*****************************************************************************/
/* SPE extension helpers */
/* Use a table to make this quicker */
target-ppc/op_helper.h +0 -3
@@ -112,9 +112,6 @@ void do_4xx_tlbwe_lo (void);void do_4xx_tlbwe_hi (void );#endif -/* PowerPC 440 specific helpers */ -void do_440_dlmzb (void ); -/* PowerPC 403 specific helpers */ #if !defined(CONFIG_USER_ONLY )void do_load_403_pb (int num);
target-ppc/translate.c +39 -2
51 lines not on this page · raw message
target-ppc/op.c +0 -19
@@ -839,25 +839,6 @@ void OPPROTO op_4xx_tlbwe_hi (void) }#endif -/* SPR micro-ops */ -/* 440 specific */ -void OPPROTO op_440_dlmzb (void) -{ -do_440_dlmzb (); -RETURN (); -} - -void OPPROTO op_440_dlmzb_update_Rc (void) -{ -if (T0 ==8 ) -T0 =0x2 ; -else if (T0 <4 ) -T0 =0x4 ; -else -T0 =0x8 ; -RETURN (); -} -#if !defined(CONFIG_USER_ONLY ) void OPPROTO op_store_pir (void) {
target-ppc/op_helper.c +0 -21
@@ -1754,27 +1754,6 @@ void do_store_403_pb (int num) }#endif -/* 440 specific */ -void do_440_dlmzb (void ) -{ -target_ulong mask; -int i; - - i =1 ; -for (mask =0xFF000000 ; mask !=0 ; mask = mask >>8 ) { -if ((T0 & mask) ==0 ) - goto done; - i++; - } -for (mask =0xFF000000 ; mask !=0 ; mask = mask >>8 ) { -if ((T1 & mask) ==0 ) -break ; - i++; - } - done: -T0 = i; -} -/*****************************************************************************/ /* SPE extension helpers */ /* Use a table to make this quicker */
target-ppc/op_helper.h +0 -3
@@ -112,9 +112,6 @@ void do_4xx_tlbwe_lo (void);void do_4xx_tlbwe_hi (void );#endif -/* PowerPC 440 specific helpers */ -void do_440_dlmzb (void ); -/* PowerPC 403 specific helpers */ #if !defined(CONFIG_USER_ONLY )void do_load_403_pb (int num);
target-ppc/translate.c +39 -2
51 lines not on this page · raw message
Quoted 6 lines · Andreas Färber
Replace {op,do}_440_dlmzb and
op_440_dlmzb_update_Rcwith inline TCG instructions.The two loops of
do_440_dlmzbare unrolled.Signed-off-by Andreas Faerber <[email protected]>
Doing loops with TCG is a bad idea as it is very inefficient.
Quoted 141 lines
---
Compile-tested on Linux/amd64.target-ppc/op.c +0
-19@@ -839,25 +839,6 @@ void OPPROTO op_4xx_tlbwe_hi (void) }#endif -/* SPR micro-ops */ -/* 440 specific */ -void OPPROTO op_440_dlmzb (void) -{ -do_440_dlmzb (); -RETURN (); -} - -void OPPROTO op_440_dlmzb_update_Rc (void) -{ -if (T0 ==8 ) -T0 =0x2 ; -else if (T0 <4 ) -T0 =0x4 ; -else -T0 =0x8 ; -RETURN (); -} -#if !defined(CONFIG_USER_ONLY ) void OPPROTO op_store_pir (void) {target-ppc/op_helper.c +0
-21@@ -1754,27 +1754,6 @@ void do_store_403_pb (int num)} #endif -/* 440 specific */ -void do_440_dlmzb (void) -{ - target_ulong mask; - int i; - - i = 1; - for (mask = 0xFF000000; mask != 0; mask = mask >> 8) { - if ((T0 & mask) == 0) - goto done; - i++; - } - for (mask = 0xFF000000; mask != 0; mask = mask >> 8) { - if ((T1 & mask) == 0) - break; - i++; - } - done: - T0 = i; -} -/ *****************************************************************************/ /* SPE extension helpers */ /* Use a table to make this quicker */
target-ppc/op_helper.h +0
-3@@ -112,9 +112,6 @@ void do_4xx_tlbwe_lo (void);void do_4xx_tlbwe_hi (void );#endif -/* PowerPC 440 specific helpers */ -void do_440_dlmzb (void ); -/* PowerPC 403 specific helpers */ #if !defined(CONFIG_USER_ONLY )void do_load_403_pb (int num);target-ppc/translate.c +39
-2@@ -5872,12 +5872,49 @@ GEN_HANDLER(dlmzb, 0x1F, 0x0E, 0x02, 0x00000000, PPC_440_SPEC) {tcg_gen_mov_tl (cpu_T[0 ], cpu_gpr[rS (ctx->opcode)]);tcg_gen_mov_tl (cpu_T[1 ], cpu_gpr[rB (ctx->opcode)]); -gen_op_440_dlmzb (); +TCGv t0 =tcg_temp_new (); +int endLabel =gen_new_label (); +int i =1 ; +target_ulong mask; +for (mask =0xFF000000 ; mask !=0 ; mask = mask >>8 ) { +tcg_gen_andi_tl (t0, cpu_T[0 ], mask); +int nextLabel =gen_new_label (); +tcg_gen_brcondi_tl (TCG_COND_NE , t0,0 , nextLabel); +tcg_gen_movi_tl (cpu_T[0 ], i++); +tcg_gen_br (endLabel); +gen_set_label (nextLabel); + } +for (mask =0xFF000000 ; mask !=0 ; mask = mask >>8 ) { +tcg_gen_andi_tl (t0, cpu_T[1 ], mask); +int nextLabel =gen_new_label (); +tcg_gen_brcondi_tl (TCG_COND_NE , t0,0 , nextLabel); +tcg_gen_movi_tl (cpu_T[0 ], i++); +tcg_gen_br (endLabel); +gen_set_label (nextLabel); + } +tcg_gen_movi_tl (cpu_T[0 ], i); +gen_set_label (endLabel); +tcg_temp_free (t0);tcg_gen_mov_tl (cpu_gpr[rA (ctx->opcode)], cpu_T[0 ]);tcg_gen_andi_tl (cpu_xer, cpu_xer, ~0x7F );tcg_gen_or_tl (cpu_xer, cpu_xer, cpu_T[0 ]);if (Rc (ctx->opcode)) { -gen_op_440_dlmzb_update_Rc (); + endLabel =gen_new_label (); +int nextLabel =gen_new_label (); +tcg_gen_brcondi_tl (TCG_COND_NE , cpu_T[0 ],8 , nextLabel); +tcg_gen_movi_tl (cpu_T[0 ],0x2 ); +tcg_gen_br (endLabel); + +gen_set_label (nextLabel); + nextLabel =gen_new_label (); +tcg_gen_brcondi_tl (TCG_COND_GE , cpu_T[0 ],4 , nextLabel); +tcg_gen_movi_tl (cpu_T[0 ],0x4 ); +tcg_gen_br (endLabel); + +gen_set_label (nextLabel); +tcg_gen_movi_tl (cpu_T[0 ],0x8 ); + +gen_set_label (endLabel);tcg_gen_trunc_tl_i32 (cpu_crf[0 ], cpu_T[0 ]);tcg_gen_andi_i32 (cpu_crf[0 ], cpu_crf[0 ],0xf );}
Signature · 4 lines
.''`. Aurelien Jarno | GPG: 1024D/F1BCDB73 : :' : Debian developer | Electrical Engineer `. `' [email protected] | [email protected] `- people.debian.org/~aurel32 | www.aurel32.net
Am 30.11.2008 um 17:31 schrieb Aurélien Jarno:
Quoted 9 lines · Andreas Färber
Quoted 6 lines
Replace {op,do}_440_dlmzb and
op_440_dlmzb_update_Rcwith inline TCG instructions.The two loops of
do_440_dlmzbare unrolled.Signed-off-by Andreas Faerber <[email protected]>Doing loops with TCG is a bad idea as it is very inefficient.
Did you read the code? There is no loop in TCG here, that's exactly what I was saying. The labels are for conditionals only and for exiting the non-loop.
If you have a better suggestion, please say so as this is one of the dyngen ops that keep me from working on the conversion on my own system.
Andreas
Quoted 152 lines
Quoted 143 lines
---
Compile-tested on Linux/amd64.target-ppc/op.c +0
-19@@ -839,25 +839,6 @@ void OPPROTO op_4xx_tlbwe_hi (void) }#endif -/* SPR micro-ops */ -/* 440 specific */ -void OPPROTO op_440_dlmzb (void) -{ -do_440_dlmzb (); -RETURN (); -} - -void OPPROTO op_440_dlmzb_update_Rc (void) -{ -if (T0 ==8 ) -T0 =0x2 ; -else if (T0 <4 ) -T0 =0x4 ; -else -T0 =0x8 ; -RETURN (); -} -#if !defined(CONFIG_USER_ONLY ) void OPPROTO op_store_pir (void) {target-ppc/op_helper.c +0
-21@@ -1754,27 +1754,6 @@ void do_store_403_pb (int num) }#endif -/* 440 specific */ -void do_440_dlmzb (void ) -{ -target_ulong mask; -int i; - - i =1 ; -for (mask =0xFF000000 ; mask !=0 ; mask = mask >>8 ) { -if ((T0 & mask) ==0 ) - goto done; - i++; - } -for (mask =0xFF000000 ; mask !=0 ; mask = mask >>8 ) { -if ((T1 & mask) ==0 ) -break ; - i++; - } - done: -T0 = i; -} -/ *****************************************************************************/ /* SPE extension helpers */
/* Use a table to make this quicker */target-ppc/op_helper.h +0
-3@@ -112,9 +112,6 @@ void do_4xx_tlbwe_lo (void);void do_4xx_tlbwe_hi (void );#endif -/* PowerPC 440 specific helpers */ -void do_440_dlmzb (void ); -/* PowerPC 403 specific helpers */ #if !defined(CONFIG_USER_ONLY )void do_load_403_pb (int num);target-ppc/translate.c +39
-2@@ -5872,12 +5872,49 @@ GEN_HANDLER(dlmzb, 0x1F, 0x0E, 0x02, 0x00000000, PPC_440_SPEC) {tcg_gen_mov_tl (cpu_T[0 ], cpu_gpr[rS (ctx->opcode)]);tcg_gen_mov_tl (cpu_T[1 ], cpu_gpr[rB (ctx->opcode)]); -gen_op_440_dlmzb (); +TCGv t0 =tcg_temp_new (); +int endLabel =gen_new_label (); +int i =1 ; +target_ulong mask; +for (mask =0xFF000000 ; mask !=0 ; mask = mask >>8 ) { +tcg_gen_andi_tl (t0, cpu_T[0 ], mask); +int nextLabel =gen_new_label (); +tcg_gen_brcondi_tl (TCG_COND_NE , t0,0 , nextLabel); +tcg_gen_movi_tl (cpu_T[0 ], i++); +tcg_gen_br (endLabel); +gen_set_label (nextLabel); + } +for (mask =0xFF000000 ; mask !=0 ; mask = mask >>8 ) { +tcg_gen_andi_tl (t0, cpu_T[1 ], mask); +int nextLabel =gen_new_label (); +tcg_gen_brcondi_tl (TCG_COND_NE , t0,0 , nextLabel); +tcg_gen_movi_tl (cpu_T[0 ], i++); +tcg_gen_br (endLabel); +gen_set_label (nextLabel); + } +tcg_gen_movi_tl (cpu_T[0 ], i); +gen_set_label (endLabel); +tcg_temp_free (t0);tcg_gen_mov_tl (cpu_gpr[rA (ctx->opcode)], cpu_T[0 ]);tcg_gen_andi_tl (cpu_xer, cpu_xer, ~0x7F );tcg_gen_or_tl (cpu_xer, cpu_xer, cpu_T[0 ]);if (Rc (ctx->opcode)) { -gen_op_440_dlmzb_update_Rc (); + endLabel =gen_new_label (); +int nextLabel =gen_new_label (); +tcg_gen_brcondi_tl (TCG_COND_NE , cpu_T[0 ],8 , nextLabel); +tcg_gen_movi_tl (cpu_T[0 ],0x2 ); +tcg_gen_br (endLabel); + +gen_set_label (nextLabel); + nextLabel =gen_new_label (); +tcg_gen_brcondi_tl (TCG_COND_GE , cpu_T[0 ],4 , nextLabel); +tcg_gen_movi_tl (cpu_T[0 ],0x4 ); +tcg_gen_br (endLabel); + +gen_set_label (nextLabel); +tcg_gen_movi_tl (cpu_T[0 ],0x8 ); + +gen_set_label (endLabel);tcg_gen_trunc_tl_i32 (cpu_crf[0 ], cpu_T[0 ]);tcg_gen_andi_i32 (cpu_crf[0 ], cpu_crf[0 ],0xf );}Signature · 4 lines
.''`. Aurelien Jarno | GPG: 1024D/F1BCDB73 : :' : Debian developer | Electrical Engineer `. `' [email protected] | [email protected] `- people.debian.org/~aurel32 | www.aurel32.net
Quoted 11 lines · Andreas Färber
Am 30.11.2008 um 17:31 schrieb Aurélien Jarno:
Quoted 2 lines
Doing loops with TCG is a bad idea as it is very inefficient.
Did you read the code? There is no loop in TCG here, that's exactly what I was saying.
The labels are for conditionals only and for exiting the non-loop.If you have a better suggestion, please say so as this is one of the dyngen ops that keep me from working on the conversion on my own system.
Going for a helper might be better for larger sequences of TCG ops; Fabrice mentions a threshold of about 20 ops. And your replacement is certainly larger than 20 ops :-) Plus given it uses brcond, it would prevent TCG liveness analysis from doing its job in the basic block containing that instruction.
Laurent
Quoted 159 lines
Andreas
Quoted 153 lines
Quoted 139 lines
---
Compile-tested on Linux/amd64.target-ppc/op.c +0
-19@@ -839,25 +839,6 @@ void OPPROTO op_4xx_tlbwe_hi (void) }#endif -/* SPR micro-ops */ -/* 440 specific */ -void OPPROTO op_440_dlmzb (void) -{ -do_440_dlmzb (); -RETURN (); -} - -void OPPROTO op_440_dlmzb_update_Rc (void) -{ -if (T0 ==8 ) -T0 =0x2 ; -else if (T0 <4 ) -T0 =0x4 ; -else -T0 =0x8 ; -RETURN (); -} -#if !defined(CONFIG_USER_ONLY ) void OPPROTO op_store_pir (void) {target-ppc/op_helper.c +0
-21@@ -1754,27 +1754,6 @@ void do_store_403_pb (int num) }#endif -/* 440 specific */ -void do_440_dlmzb (void ) -{ -target_ulong mask; -int i; - - i =1 ; -for (mask =0xFF000000 ; mask !=0 ; mask = mask >>8 ) { -if ((T0 & mask) ==0 ) - goto done; - i++; - } -for (mask =0xFF000000 ; mask !=0 ; mask = mask >>8 ) { -if ((T1 & mask) ==0 ) -break ; - i++; - } - done: -T0 = i; -} -/
*****************************************************************************/ /* SPE extension helpers */
/* Use a table to make this quicker */target-ppc/op_helper.h +0
-3@@ -112,9 +112,6 @@ void do_4xx_tlbwe_lo (void);void do_4xx_tlbwe_hi (void );#endif -/* PowerPC 440 specific helpers */ -void do_440_dlmzb (void ); -/* PowerPC 403 specific helpers */ #if !defined(CONFIG_USER_ONLY )void do_load_403_pb (int num);target-ppc/translate.c +39
-2@@ -5872,12 +5872,49 @@ GEN_HANDLER(dlmzb, 0x1F, 0x0E, 0x02, 0x00000000, PPC_440_SPEC) {tcg_gen_mov_tl (cpu_T[0 ], cpu_gpr[rS (ctx->opcode)]);tcg_gen_mov_tl (cpu_T[1 ], cpu_gpr[rB (ctx->opcode)]); -gen_op_440_dlmzb (); +TCGv t0 =tcg_temp_new (); +int endLabel =gen_new_label (); +int i =1 ; +target_ulong mask; +for (mask =0xFF000000 ; mask !=0 ; mask = mask >>8 ) { +tcg_gen_andi_tl (t0, cpu_T[0 ], mask); +int nextLabel =gen_new_label (); +tcg_gen_brcondi_tl (TCG_COND_NE , t0,0 , nextLabel); +tcg_gen_movi_tl (cpu_T[0 ], i++); +tcg_gen_br (endLabel); +gen_set_label (nextLabel); + } +for (mask =0xFF000000 ; mask !=0 ; mask = mask >>8 ) { +tcg_gen_andi_tl (t0, cpu_T[1 ], mask); +int nextLabel =gen_new_label (); +tcg_gen_brcondi_tl (TCG_COND_NE , t0,0 , nextLabel); +tcg_gen_movi_tl (cpu_T[0 ], i++); +tcg_gen_br (endLabel); +gen_set_label (nextLabel); + } +tcg_gen_movi_tl (cpu_T[0 ], i); +gen_set_label (endLabel); +tcg_temp_free (t0);tcg_gen_mov_tl (cpu_gpr[rA (ctx->opcode)], cpu_T[0 ]);tcg_gen_andi_tl (cpu_xer, cpu_xer, ~0x7F );tcg_gen_or_tl (cpu_xer, cpu_xer, cpu_T[0 ]);if (Rc (ctx->opcode)) { -gen_op_440_dlmzb_update_Rc (); + endLabel =gen_new_label (); +int nextLabel =gen_new_label (); +tcg_gen_brcondi_tl (TCG_COND_NE , cpu_T[0 ],8 , nextLabel); +tcg_gen_movi_tl (cpu_T[0 ],0x2 ); +tcg_gen_br (endLabel); + +gen_set_label (nextLabel); + nextLabel =gen_new_label (); +tcg_gen_brcondi_tl (TCG_COND_GE , cpu_T[0 ],4 , nextLabel); +tcg_gen_movi_tl (cpu_T[0 ],0x4 ); +tcg_gen_br (endLabel); + +gen_set_label (nextLabel); +tcg_gen_movi_tl (cpu_T[0 ],0x8 ); + +gen_set_label (endLabel);tcg_gen_trunc_tl_i32 (cpu_crf[0 ], cpu_T[0 ]);tcg_gen_andi_i32 (cpu_crf[0 ], cpu_crf[0 ],0xf );Quoted 5 lines
}--
.''`. Aurelien Jarno | GPG: 1024D/F1BCDB73 : :' : Debian developer | Electrical Engineer `. `' [email protected] | [email protected]`- people.debian.org/~aurel32 | www.aurel32.net
Am 30.11.2008 um 18:40 schrieb Laurent Desnogues:
Quoted 11 lines
On Sun, Nov 30, 2008 at 6:25 PM, Andreas Färber <[email protected]
Quoted 10 lines
wrote:
Am 30.11.2008 um 17:31 schrieb Aurélien Jarno:
Quoted 2 lines
Doing loops with TCG is a bad idea as it is very inefficient.
Did you read the code? There is no loop in TCG here, that's exactly what I was saying.
The labels are for conditionals only and for exiting the non-loop.
Quoted 8 lines
Quoted 2 lines
If you have a better suggestion, please say so as this is one of the dyngen ops that keep me from working on the conversion on my own system.
Going for a helper might be better for larger sequences of TCG ops; Fabrice mentions a threshold of about 20 ops. And your replacement is certainly larger than 20 ops :-) Plus given it uses brcond, it would prevent TCG liveness analysis from doing its job in the basic block containing that instruction.
Thanks for the explanation!
So, if I encounter a dyngen op that calls a helper, then in general I should convert it to TCG code calling the helper?
My next problem is op_440_tlbre, which does call a helper, but with a PARAM1 argument. Any hint how to translate that?
Andreas
Quoted 3 lines · Andreas Färber
So, if I encounter a dyngen op that calls a helper, then in general I should convert it to TCG code calling the helper?
I guess it depends, but in most cases probably. If an instruction is not used often and its implementation in the old helper is rather long or uses branches (if/else, loops), you should keep it as a helper.
Quoted 2 lines
My next problem is
op_440_tlbre, which does call a helper, but with a PARAM1 argument. Any hint how to translate that?
I am not familiar at all with the old generator, so take what I say with a grain of salt :-)
PARAM1 probably was a parameter passed at runtime. Now with the way helper calls are generated, you explicitly pass parameters. Your best bet is to look at how Aurélien reimplemented dlmzb or any other complex helpers since he started the conversion to TCG.
Laurent
Quoted 10 lines · Aurélien Jarno
Quoted 6 lines · Andreas Färber
Replace {op,do}_440_dlmzb and
op_440_dlmzb_update_Rcwith inline TCG instructions.The two loops of
do_440_dlmzbare unrolled.Signed-off-by Andreas Faerber <[email protected]>Doing loops with TCG is a bad idea as it is very inefficient.
I have converted this instruction in r5836.
Signature · 4 lines
.''`. Aurelien Jarno | GPG: 1024D/F1BCDB73 : :' : Debian developer | Electrical Engineer `. `' [email protected] | [email protected] `- people.debian.org/~aurel32 | www.aurel32.net