Skip to content

Commit ca61fa4

Browse files
committed
Merge remote-tracking branch 'remotes/quic/tags/pull-hex-20211006' into staging
Change from Philippe - Use tcg_constant_* Change from Philippe - Remove unused TCG temp Change from Taylor - Probe the stores in a packet at start of commit # gpg: Signature made Wed 06 Oct 2021 08:44:13 AM PDT # gpg: using RSA key 7B0244FB12DE4422 # gpg: Good signature from "Taylor Simpson (Rock on) <[email protected]>" [marginal] # gpg: WARNING: This key is not certified with sufficiently trusted signatures! # gpg: It is not certain that the signature belongs to the owner. # Primary key fingerprint: 3635 C788 CE62 B91F D4C5 9AB4 7B02 44FB 12DE 4422 * remotes/quic/tags/pull-hex-20211006: target/hexagon: Use tcg_constant_* target/hexagon: Remove unused TCG temporary from predicated loads Hexagon (target/hexagon) probe the stores in a packet at start of commit Signed-off-by: Richard Henderson <[email protected]>
2 parents 6723ff6 + 23803bb commit ca61fa4

File tree

9 files changed

+185
-58
lines changed

9 files changed

+185
-58
lines changed

target/hexagon/gen_tcg.h

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -684,9 +684,8 @@
684684
gen_helper_sfmin(RdV, cpu_env, RsV, RtV)
685685
#define fGEN_TCG_F2_sfclass(SHORTCODE) \
686686
do { \
687-
TCGv imm = tcg_const_tl(uiV); \
687+
TCGv imm = tcg_constant_tl(uiV); \
688688
gen_helper_sfclass(PdV, cpu_env, RsV, imm); \
689-
tcg_temp_free(imm); \
690689
} while (0)
691690
#define fGEN_TCG_F2_sffixupn(SHORTCODE) \
692691
gen_helper_sffixupn(RdV, cpu_env, RsV, RtV)
@@ -712,9 +711,8 @@
712711
gen_helper_dfcmpuo(PdV, cpu_env, RssV, RttV)
713712
#define fGEN_TCG_F2_dfclass(SHORTCODE) \
714713
do { \
715-
TCGv imm = tcg_const_tl(uiV); \
714+
TCGv imm = tcg_constant_tl(uiV); \
716715
gen_helper_dfclass(PdV, cpu_env, RssV, imm); \
717-
tcg_temp_free(imm); \
718716
} while (0)
719717
#define fGEN_TCG_F2_sfmpy(SHORTCODE) \
720718
gen_helper_sfmpy(RdV, cpu_env, RsV, RtV)

target/hexagon/gen_tcg_funcs.py

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -403,7 +403,7 @@ def gen_tcg_func(f, tag, regs, imms):
403403
if hex_common.need_part1(tag):
404404
f.write(" TCGv part1 = tcg_const_tl(insn->part1);\n")
405405
if hex_common.need_slot(tag):
406-
f.write(" TCGv slot = tcg_const_tl(insn->slot);\n")
406+
f.write(" TCGv slot = tcg_constant_tl(insn->slot);\n")
407407
f.write(" gen_helper_%s(" % (tag))
408408
i=0
409409
## If there is a scalar result, it is the return type
@@ -424,8 +424,6 @@ def gen_tcg_func(f, tag, regs, imms):
424424
if hex_common.need_slot(tag): f.write(", slot")
425425
if hex_common.need_part1(tag): f.write(", part1" )
426426
f.write(");\n")
427-
if hex_common.need_slot(tag):
428-
f.write(" tcg_temp_free(slot);\n")
429427
if hex_common.need_part1(tag):
430428
f.write(" tcg_temp_free(part1);\n")
431429
for immlett,bits,immshift in imms:

target/hexagon/genptr.c

Lines changed: 13 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@
2929

3030
static inline void gen_log_predicated_reg_write(int rnum, TCGv val, int slot)
3131
{
32-
TCGv zero = tcg_const_tl(0);
32+
TCGv zero = tcg_constant_tl(0);
3333
TCGv slot_mask = tcg_temp_new();
3434

3535
tcg_gen_andi_tl(slot_mask, hex_slot_cancelled, 1 << slot);
@@ -47,7 +47,6 @@ static inline void gen_log_predicated_reg_write(int rnum, TCGv val, int slot)
4747
tcg_gen_or_tl(hex_reg_written[rnum], hex_reg_written[rnum], slot_mask);
4848
}
4949

50-
tcg_temp_free(zero);
5150
tcg_temp_free(slot_mask);
5251
}
5352

@@ -63,7 +62,7 @@ static inline void gen_log_reg_write(int rnum, TCGv val)
6362
static void gen_log_predicated_reg_write_pair(int rnum, TCGv_i64 val, int slot)
6463
{
6564
TCGv val32 = tcg_temp_new();
66-
TCGv zero = tcg_const_tl(0);
65+
TCGv zero = tcg_constant_tl(0);
6766
TCGv slot_mask = tcg_temp_new();
6867

6968
tcg_gen_andi_tl(slot_mask, hex_slot_cancelled, 1 << slot);
@@ -92,7 +91,6 @@ static void gen_log_predicated_reg_write_pair(int rnum, TCGv_i64 val, int slot)
9291
}
9392

9493
tcg_temp_free(val32);
95-
tcg_temp_free(zero);
9694
tcg_temp_free(slot_mask);
9795
}
9896

@@ -181,9 +179,8 @@ static inline void gen_read_ctrl_reg_pair(DisasContext *ctx, const int reg_num,
181179
tcg_gen_concat_i32_i64(dest, p3_0, hex_gpr[reg_num + 1]);
182180
tcg_temp_free(p3_0);
183181
} else if (reg_num == HEX_REG_PC - 1) {
184-
TCGv pc = tcg_const_tl(ctx->base.pc_next);
182+
TCGv pc = tcg_constant_tl(ctx->base.pc_next);
185183
tcg_gen_concat_i32_i64(dest, hex_gpr[reg_num], pc);
186-
tcg_temp_free(pc);
187184
} else if (reg_num == HEX_REG_QEMU_PKT_CNT) {
188185
TCGv pkt_cnt = tcg_temp_new();
189186
TCGv insn_cnt = tcg_temp_new();
@@ -331,15 +328,13 @@ static inline void gen_store_conditional4(DisasContext *ctx,
331328

332329
tcg_gen_brcond_tl(TCG_COND_NE, vaddr, hex_llsc_addr, fail);
333330

334-
one = tcg_const_tl(0xff);
335-
zero = tcg_const_tl(0);
331+
one = tcg_constant_tl(0xff);
332+
zero = tcg_constant_tl(0);
336333
tmp = tcg_temp_new();
337334
tcg_gen_atomic_cmpxchg_tl(tmp, hex_llsc_addr, hex_llsc_val, src,
338335
ctx->mem_idx, MO_32);
339336
tcg_gen_movcond_tl(TCG_COND_EQ, pred, tmp, hex_llsc_val,
340337
one, zero);
341-
tcg_temp_free(one);
342-
tcg_temp_free(zero);
343338
tcg_temp_free(tmp);
344339
tcg_gen_br(done);
345340

@@ -359,16 +354,14 @@ static inline void gen_store_conditional8(DisasContext *ctx,
359354

360355
tcg_gen_brcond_tl(TCG_COND_NE, vaddr, hex_llsc_addr, fail);
361356

362-
one = tcg_const_i64(0xff);
363-
zero = tcg_const_i64(0);
357+
one = tcg_constant_i64(0xff);
358+
zero = tcg_constant_i64(0);
364359
tmp = tcg_temp_new_i64();
365360
tcg_gen_atomic_cmpxchg_i64(tmp, hex_llsc_addr, hex_llsc_val_i64, src,
366361
ctx->mem_idx, MO_64);
367362
tcg_gen_movcond_i64(TCG_COND_EQ, tmp, tmp, hex_llsc_val_i64,
368363
one, zero);
369364
tcg_gen_extrl_i64_i32(pred, tmp);
370-
tcg_temp_free_i64(one);
371-
tcg_temp_free_i64(zero);
372365
tcg_temp_free_i64(tmp);
373366
tcg_gen_br(done);
374367

@@ -396,9 +389,8 @@ static inline void gen_store1(TCGv_env cpu_env, TCGv vaddr, TCGv src,
396389
static inline void gen_store1i(TCGv_env cpu_env, TCGv vaddr, int32_t src,
397390
DisasContext *ctx, int slot)
398391
{
399-
TCGv tmp = tcg_const_tl(src);
392+
TCGv tmp = tcg_constant_tl(src);
400393
gen_store1(cpu_env, vaddr, tmp, ctx, slot);
401-
tcg_temp_free(tmp);
402394
}
403395

404396
static inline void gen_store2(TCGv_env cpu_env, TCGv vaddr, TCGv src,
@@ -411,9 +403,8 @@ static inline void gen_store2(TCGv_env cpu_env, TCGv vaddr, TCGv src,
411403
static inline void gen_store2i(TCGv_env cpu_env, TCGv vaddr, int32_t src,
412404
DisasContext *ctx, int slot)
413405
{
414-
TCGv tmp = tcg_const_tl(src);
406+
TCGv tmp = tcg_constant_tl(src);
415407
gen_store2(cpu_env, vaddr, tmp, ctx, slot);
416-
tcg_temp_free(tmp);
417408
}
418409

419410
static inline void gen_store4(TCGv_env cpu_env, TCGv vaddr, TCGv src,
@@ -426,9 +417,8 @@ static inline void gen_store4(TCGv_env cpu_env, TCGv vaddr, TCGv src,
426417
static inline void gen_store4i(TCGv_env cpu_env, TCGv vaddr, int32_t src,
427418
DisasContext *ctx, int slot)
428419
{
429-
TCGv tmp = tcg_const_tl(src);
420+
TCGv tmp = tcg_constant_tl(src);
430421
gen_store4(cpu_env, vaddr, tmp, ctx, slot);
431-
tcg_temp_free(tmp);
432422
}
433423

434424
static inline void gen_store8(TCGv_env cpu_env, TCGv vaddr, TCGv_i64 src,
@@ -443,18 +433,15 @@ static inline void gen_store8(TCGv_env cpu_env, TCGv vaddr, TCGv_i64 src,
443433
static inline void gen_store8i(TCGv_env cpu_env, TCGv vaddr, int64_t src,
444434
DisasContext *ctx, int slot)
445435
{
446-
TCGv_i64 tmp = tcg_const_i64(src);
436+
TCGv_i64 tmp = tcg_constant_i64(src);
447437
gen_store8(cpu_env, vaddr, tmp, ctx, slot);
448-
tcg_temp_free_i64(tmp);
449438
}
450439

451440
static TCGv gen_8bitsof(TCGv result, TCGv value)
452441
{
453-
TCGv zero = tcg_const_tl(0);
454-
TCGv ones = tcg_const_tl(0xff);
442+
TCGv zero = tcg_constant_tl(0);
443+
TCGv ones = tcg_constant_tl(0xff);
455444
tcg_gen_movcond_tl(TCG_COND_NE, result, value, zero, ones, zero);
456-
tcg_temp_free(zero);
457-
tcg_temp_free(ones);
458445

459446
return result;
460447
}

target/hexagon/helper.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -89,3 +89,5 @@ DEF_HELPER_4(sffms_lib, f32, env, f32, f32, f32)
8989

9090
DEF_HELPER_3(dfmpyfix, f64, env, f64, f64)
9191
DEF_HELPER_4(dfmpyhh, f64, env, f64, f64, f64)
92+
93+
DEF_HELPER_2(probe_pkt_scalar_store_s0, void, env, int)

target/hexagon/macros.h

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -189,16 +189,13 @@ static inline void gen_pred_cancel(TCGv pred, int slot_num)
189189
{
190190
TCGv slot_mask = tcg_const_tl(1 << slot_num);
191191
TCGv tmp = tcg_temp_new();
192-
TCGv zero = tcg_const_tl(0);
193-
TCGv one = tcg_const_tl(1);
192+
TCGv zero = tcg_constant_tl(0);
194193
tcg_gen_or_tl(slot_mask, hex_slot_cancelled, slot_mask);
195194
tcg_gen_andi_tl(tmp, pred, 1);
196195
tcg_gen_movcond_tl(TCG_COND_EQ, hex_slot_cancelled, tmp, zero,
197196
slot_mask, hex_slot_cancelled);
198197
tcg_temp_free(slot_mask);
199198
tcg_temp_free(tmp);
200-
tcg_temp_free(zero);
201-
tcg_temp_free(one);
202199
}
203200
#define PRED_LOAD_CANCEL(PRED, EA) \
204201
gen_pred_cancel(PRED, insn->is_endloop ? 4 : insn->slot)

target/hexagon/op_helper.c

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -377,6 +377,22 @@ int32_t HELPER(vacsh_pred)(CPUHexagonState *env,
377377
return PeV;
378378
}
379379

380+
static void probe_store(CPUHexagonState *env, int slot, int mmu_idx)
381+
{
382+
if (!(env->slot_cancelled & (1 << slot))) {
383+
size1u_t width = env->mem_log_stores[slot].width;
384+
target_ulong va = env->mem_log_stores[slot].va;
385+
uintptr_t ra = GETPC();
386+
probe_write(env, va, width, mmu_idx, ra);
387+
}
388+
}
389+
390+
/* Called during packet commit when there are two scalar stores */
391+
void HELPER(probe_pkt_scalar_store_s0)(CPUHexagonState *env, int mmu_idx)
392+
{
393+
probe_store(env, 0, mmu_idx);
394+
}
395+
380396
/*
381397
* mem_noshuf
382398
* Section 5.5 of the Hexagon V67 Programmer's Reference Manual

target/hexagon/translate.c

Lines changed: 43 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -54,9 +54,7 @@ static const char * const hexagon_prednames[] = {
5454

5555
static void gen_exception_raw(int excp)
5656
{
57-
TCGv_i32 helper_tmp = tcg_const_i32(excp);
58-
gen_helper_raise_exception(cpu_env, helper_tmp);
59-
tcg_temp_free_i32(helper_tmp);
57+
gen_helper_raise_exception(cpu_env, tcg_constant_i32(excp));
6058
}
6159

6260
static void gen_exec_counters(DisasContext *ctx)
@@ -288,7 +286,7 @@ static void gen_pred_writes(DisasContext *ctx, Packet *pkt)
288286
* write of the predicates.
289287
*/
290288
if (pkt->pkt_has_endloop) {
291-
TCGv zero = tcg_const_tl(0);
289+
TCGv zero = tcg_constant_tl(0);
292290
TCGv pred_written = tcg_temp_new();
293291
for (i = 0; i < ctx->preg_log_idx; i++) {
294292
int pred_num = ctx->preg_log[i];
@@ -299,7 +297,6 @@ static void gen_pred_writes(DisasContext *ctx, Packet *pkt)
299297
hex_new_pred_value[pred_num],
300298
hex_pred[pred_num]);
301299
}
302-
tcg_temp_free(zero);
303300
tcg_temp_free(pred_written);
304301
} else {
305302
for (i = 0; i < ctx->preg_log_idx; i++) {
@@ -317,11 +314,9 @@ static void gen_pred_writes(DisasContext *ctx, Packet *pkt)
317314
static void gen_check_store_width(DisasContext *ctx, int slot_num)
318315
{
319316
if (HEX_DEBUG) {
320-
TCGv slot = tcg_const_tl(slot_num);
321-
TCGv check = tcg_const_tl(ctx->store_width[slot_num]);
317+
TCGv slot = tcg_constant_tl(slot_num);
318+
TCGv check = tcg_constant_tl(ctx->store_width[slot_num]);
322319
gen_helper_debug_check_store_width(cpu_env, slot, check);
323-
tcg_temp_free(slot);
324-
tcg_temp_free(check);
325320
}
326321
}
327322

@@ -403,9 +398,8 @@ void process_store(DisasContext *ctx, Packet *pkt, int slot_num)
403398
* TCG generation time, we'll use a helper to
404399
* avoid branching based on the width at runtime.
405400
*/
406-
TCGv slot = tcg_const_tl(slot_num);
401+
TCGv slot = tcg_constant_tl(slot_num);
407402
gen_helper_commit_store(cpu_env, slot);
408-
tcg_temp_free(slot);
409403
}
410404
}
411405
tcg_temp_free(address);
@@ -419,7 +413,7 @@ static void process_store_log(DisasContext *ctx, Packet *pkt)
419413
{
420414
/*
421415
* When a packet has two stores, the hardware processes
422-
* slot 1 and then slot 2. This will be important when
416+
* slot 1 and then slot 0. This will be important when
423417
* the memory accesses overlap.
424418
*/
425419
if (pkt->pkt_has_store_s1 && !pkt->pkt_has_dczeroa) {
@@ -436,7 +430,7 @@ static void process_dczeroa(DisasContext *ctx, Packet *pkt)
436430
if (pkt->pkt_has_dczeroa) {
437431
/* Store 32 bytes of zero starting at (addr & ~0x1f) */
438432
TCGv addr = tcg_temp_new();
439-
TCGv_i64 zero = tcg_const_i64(0);
433+
TCGv_i64 zero = tcg_constant_i64(0);
440434

441435
tcg_gen_andi_tl(addr, hex_dczero_addr, ~0x1f);
442436
tcg_gen_qemu_st64(zero, addr, ctx->mem_idx);
@@ -448,7 +442,6 @@ static void process_dczeroa(DisasContext *ctx, Packet *pkt)
448442
tcg_gen_qemu_st64(zero, addr, ctx->mem_idx);
449443

450444
tcg_temp_free(addr);
451-
tcg_temp_free_i64(zero);
452445
}
453446
}
454447

@@ -471,22 +464,51 @@ static void update_exec_counters(DisasContext *ctx, Packet *pkt)
471464

472465
static void gen_commit_packet(DisasContext *ctx, Packet *pkt)
473466
{
467+
/*
468+
* If there is more than one store in a packet, make sure they are all OK
469+
* before proceeding with the rest of the packet commit.
470+
*
471+
* dczeroa has to be the only store operation in the packet, so we go
472+
* ahead and process that first.
473+
*
474+
* When there are two scalar stores, we probe the one in slot 0.
475+
*
476+
* Note that we don't call the probe helper for packets with only one
477+
* store. Therefore, we call process_store_log before anything else
478+
* involved in committing the packet.
479+
*/
480+
bool has_store_s0 = pkt->pkt_has_store_s0;
481+
bool has_store_s1 = (pkt->pkt_has_store_s1 && !ctx->s1_store_processed);
482+
if (pkt->pkt_has_dczeroa) {
483+
/*
484+
* The dczeroa will be the store in slot 0, check that we don't have
485+
* a store in slot 1.
486+
*/
487+
g_assert(has_store_s0 && !has_store_s1);
488+
process_dczeroa(ctx, pkt);
489+
} else if (has_store_s0 && has_store_s1) {
490+
/*
491+
* process_store_log will execute the slot 1 store first,
492+
* so we only have to probe the store in slot 0
493+
*/
494+
TCGv mem_idx = tcg_const_tl(ctx->mem_idx);
495+
gen_helper_probe_pkt_scalar_store_s0(cpu_env, mem_idx);
496+
tcg_temp_free(mem_idx);
497+
}
498+
499+
process_store_log(ctx, pkt);
500+
474501
gen_reg_writes(ctx);
475502
gen_pred_writes(ctx, pkt);
476-
process_store_log(ctx, pkt);
477-
process_dczeroa(ctx, pkt);
478503
update_exec_counters(ctx, pkt);
479504
if (HEX_DEBUG) {
480505
TCGv has_st0 =
481-
tcg_const_tl(pkt->pkt_has_store_s0 && !pkt->pkt_has_dczeroa);
506+
tcg_constant_tl(pkt->pkt_has_store_s0 && !pkt->pkt_has_dczeroa);
482507
TCGv has_st1 =
483-
tcg_const_tl(pkt->pkt_has_store_s1 && !pkt->pkt_has_dczeroa);
508+
tcg_constant_tl(pkt->pkt_has_store_s1 && !pkt->pkt_has_dczeroa);
484509

485510
/* Handy place to set a breakpoint at the end of execution */
486511
gen_helper_debug_commit_end(cpu_env, has_st0, has_st1);
487-
488-
tcg_temp_free(has_st0);
489-
tcg_temp_free(has_st1);
490512
}
491513

492514
if (pkt->pkt_has_cof) {

tests/tcg/hexagon/Makefile.target

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ first: $(HEX_SRC)/first.S
2828
$(CC) -static -mv67 -nostdlib $^ -o $@
2929

3030
HEX_TESTS = first
31+
HEX_TESTS += hex_sigsegv
3132
HEX_TESTS += misc
3233
HEX_TESTS += preg_alias
3334
HEX_TESTS += dual_stores

0 commit comments

Comments
 (0)