Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions docs/user/latx-environment.rst
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,16 @@ Meson 安装目标会把模板安装到 configure 指定的 ``sysconfdir``。默
- ``1``
- 仅 AVX 构建可用。设为 ``0`` 会改变 AVX 相关 CPUID 上报,但不会关闭
已编译的 AVX 翻译;必须在 guest 启动前设置。
* - ``LATX_MASKED_MEMORY``
- ``0``
- 默认关闭。设为 ``1``,让带掩码的读写指令只访问掩码选中的内存元素,
避免访问未选中的地址而产生访存错误。适用于 ``MASKMOVQ/DQU``、
``VMASKMOVDQU``、``VMASKMOVPS/PD`` 和 ``VPMASKMOVD/Q``。
部分元素被选中时,会拆成多次较小的读写,可能降低性能。
开启后会关闭 AOT,不生成也不加载 AOT 缓存;显式设置
``LATX_AOT=1`` 或 ``-latx-aot 1`` 也不会重新开启 AOT。
Gather 指令始终只读取掩码选中的元素,不受此开关影响。
命令行参数为 ``-latx-masked-memory 0|1``。
* - ``LAT_LD_PREFIX``
- ABI 路径
- 覆盖动态链接 guest 的运行时根目录,等价于 ``-L <path>``。先用
Expand Down
19 changes: 18 additions & 1 deletion linux-user/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -714,6 +714,20 @@ static void handle_arg_latx_softfpu_fast(const char *arg)
option_softfpu_fast = strtol(arg, NULL, 0);
}

static void handle_arg_latx_masked_memory(const char *arg)
{
int value;

if (qemu_strtoi(arg, NULL, 0, &value) || (value != 0 && value != 1)) {
fprintf(stderr, "LATX_MASKED_MEMORY must be 0 or 1\n");
exit(EXIT_FAILURE);
}
option_masked_memory = value;
if (option_masked_memory) {
option_aot = 0;
}
}

static void handle_arg_latx_prlimit(const char *arg)
{
option_prlimit = strtol(arg, NULL, 0);
Expand Down Expand Up @@ -954,7 +968,7 @@ static void handle_arg_latx_fork_unlink(const char *arg)
static void handle_arg_latx_aot(const char *arg)
{
option_aot = strtol(arg, NULL, 0);
if (option_softfpu || option_mem_test) {
if (option_softfpu || option_mem_test || option_masked_memory) {
option_aot = 0;
}
}
Expand Down Expand Up @@ -1078,6 +1092,9 @@ static const struct qemu_argument arg_table[] = {
"", "enable imm reg optimization"},
{"latx-mem-test", "LATX_MT", true, handle_arg_latx_mem_test,
"0|1|2", "16K checks: sparse fast or strict fast"},
{"latx-masked-memory", "LATX_MASKED_MEMORY", true,
handle_arg_latx_masked_memory, "0|1",
"access only selected masked-memory elements; disable AOT (default: 0)"},
{"latx-minke-16k-page-check", "LATX_MINKE_16K_PAGE_CHECK", true,
handle_arg_latx_minke_16k_page_check, "0|1",
"enable Minke-specific mixed 16K write checks"},
Expand Down
2 changes: 2 additions & 0 deletions target/i386/latx/include/latx-options.h
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,7 @@ extern int option_imm_complex;
extern int option_debug_imm_reg;
extern uint64_t imm_skip_pc;
extern int option_mem_test;
extern int option_masked_memory;
extern int option_minke_16k_page_check;
extern int option_real_maps;
extern int option_monitor_shared_mem;
Expand Down Expand Up @@ -185,6 +186,7 @@ extern unsigned long long counter_mips_tr;
ENVFUN(LATX_JRRA, handle_arg_latx_jrra) \
ENVFUN(LATX_IMM_REG, handle_arg_latx_imm_reg) \
ENVFUN(LATX_MT, handle_arg_latx_mem_test) \
ENVFUN(LATX_MASKED_MEMORY, handle_arg_latx_masked_memory) \
ENVFUN(LATX_MINKE_16K_PAGE_CHECK, \
handle_arg_latx_minke_16k_page_check) \
ENVFUN(LATX_REAL_MAPS, handle_arg_latx_real_maps) \
Expand Down
3 changes: 3 additions & 0 deletions target/i386/latx/include/translate.h
Original file line number Diff line number Diff line change
Expand Up @@ -1613,6 +1613,9 @@ IR2_OPND convert_gpr_opnd(IR1_OPND *, EXTENSION_MODE);
IR2_OPND load_freg128_from_ir1(IR1_OPND *);
void load_imm_to_ir1_opnd_gpr(IR1_OPND *opnd0, uint64_t imm);
IR2_OPND load_freg256_from_ir1(IR1_OPND *opnd1);
void gen_masked_vector_memory(IR2_OPND value, IR2_OPND mask,
IR2_OPND address, int bytes, int element_bytes,
bool store);
void clear_xmm_high64(IR2_OPND opnd);
/* Request a logical upper zero: defer guest registers, clear temporaries now. */
void set_high128_xreg_to_zero(IR2_OPND opnd);
Expand Down
2 changes: 2 additions & 0 deletions target/i386/latx/latx-options.c
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,7 @@ int option_vpaes;
int option_split_tb;
int option_anonym;
int option_mem_test;
int option_masked_memory;
int option_minke_16k_page_check;
int option_real_maps;
int option_monitor_shared_mem;
Expand Down Expand Up @@ -279,6 +280,7 @@ void options_init(void)
#endif
option_anonym = 0;
option_mem_test = 0;
option_masked_memory = 0;
option_minke_16k_page_check = 0;
option_real_maps = 0;
option_monitor_shared_mem = 0;
Expand Down
7 changes: 7 additions & 0 deletions target/i386/latx/translator/tr-avx-cvt-lsx.c
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,13 @@ static void load_avx_cvt_value_lsx(IR1_OPND *opnd, bool ymm,

wide.size = 32;
load_v256_from_ir1_mem_exact(&wide, low, high);
} else if (ir1_opnd_size(opnd) == 64) {
/* XMM VCVTPS2PD/VCVTDQ2PD consume only two 32-bit elements. */
IR2_OPND value = load_u64_from_ir1_mem_exact(opnd);

*low = ra_alloc_ftemp();
la_vreplgr2vr_d(*low, value);
ra_free_temp(value);
} else {
*low = load_v128_from_ir1_mem_exact(opnd);
}
Expand Down
155 changes: 20 additions & 135 deletions target/i386/latx/translator/tr-avx-lsx.c
Original file line number Diff line number Diff line change
Expand Up @@ -2732,130 +2732,9 @@ bool translate_vpinsrq_lsx(IR1_INST *pir1)
return true;
}

static void vpmaskmov_lsx_apply(IR2_OPND result, IR2_OPND memory,
IR2_OPND mask, IR2_OPND value,
bool quadword, bool store)
{
IR2_OPND selected = ra_alloc_ftemp();
IR2_OPND unselected = ra_alloc_ftemp();

if (quadword) {
la_vclz_d(selected, mask);
la_vseqi_d(selected, selected, 0);
} else {
la_vclz_w(selected, mask);
la_vseqi_w(selected, selected, 0);
}
if (store) {
la_vand_v(result, selected, value);
la_vandn_v(unselected, selected, memory);
la_vxor_v(result, result, unselected);
} else {
la_vand_v(result, selected, memory);
}

ra_free_temp(unselected);
ra_free_temp(selected);
}

bool translate_vpmaskmovx_lsx(IR1_INST *pir1)
{
IR1_OPND *opnd0 = ir1_get_opnd(pir1, 0);
IR1_OPND *opnd1 = ir1_get_opnd(pir1, 1);
IR1_OPND *opnd2 = ir1_get_opnd(pir1, 2);
bool store = ir1_opnd_is_mem(opnd0);
bool ymm = ir1_opnd_is_ymm(opnd1);
bool quadword = ir1_opcode(pir1) == dt_X86_INS_VPMASKMOVQ;
IR1_OPND *mem = store ? opnd0 : opnd2;
int mask_index = ir1_opnd_base_reg_num(opnd1);
IR2_OPND mask_low = ra_alloc_ftemp();

lsassert(ir1_opcode(pir1) == dt_X86_INS_VPMASKMOVD ||
ir1_opcode(pir1) == dt_X86_INS_VPMASKMOVQ);
lsassert(ir1_opnd_is_xmm(opnd1) || ir1_opnd_is_ymm(opnd1));
lsassert(ymm ? (ir1_opnd_is_ymm(opnd2) &&
(store || ir1_opnd_is_ymm(opnd0))) :
(ir1_opnd_is_xmm(opnd2) &&
(store || ir1_opnd_is_xmm(opnd0))));
lsassert(store ? (ir1_opnd_is_mem(opnd0) &&
(ir1_opnd_is_xmm(opnd2) || ir1_opnd_is_ymm(opnd2))) :
(ir1_opnd_is_mem(opnd2) &&
(ir1_opnd_is_xmm(opnd0) || ir1_opnd_is_ymm(opnd0))));

/* LASX accesses the complete vector before applying the mask. */
la_vori_b(mask_low, ra_alloc_xmm(mask_index), 0);
if (ymm) {
IR2_OPND result_low = ra_alloc_ftemp();
if (store) {
int src_index = ir1_opnd_base_reg_num(opnd2);
IR2_OPND memory_low;
IR2_OPND unused_high;
IR2_OPND value_low = ra_alloc_xmm(src_index);

load_v256_from_ir1_mem_exact(mem, &memory_low, &unused_high);
ra_free_temp(unused_high);
vpmaskmov_lsx_apply(result_low, memory_low, mask_low,
value_low, quadword, true);
store_v256_low_to_ir1_mem_exact(result_low, mem);
ra_free_temp(memory_low);
} else {
int dest_index = ir1_opnd_base_reg_num(opnd0);
IR2_OPND memory_low;
IR2_OPND unused_high;

load_v256_from_ir1_mem_exact(mem, &memory_low, &unused_high);
ra_free_temp(unused_high);
vpmaskmov_lsx_apply(result_low, memory_low, mask_low, memory_low,
quadword, false);
la_vori_b(ra_alloc_xmm(dest_index), result_low, 0);
ra_free_temp(memory_low);
}
ra_free_temp(result_low);

IR2_OPND memory_high = load_v256_high_from_ir1_mem_exact(mem);
IR2_OPND result_high = ra_alloc_ftemp();
IR2_OPND mask_high = load_ymm_high128_shadow(mask_index);
if (store) {
IR2_OPND value_high = load_ymm_high128_shadow(
ir1_opnd_base_reg_num(opnd2));

vpmaskmov_lsx_apply(result_high, memory_high, mask_high,
value_high, quadword, true);
store_v256_high_to_ir1_mem_exact(result_high, mem);
ra_free_temp(value_high);
} else {
int dest_index = ir1_opnd_base_reg_num(opnd0);

vpmaskmov_lsx_apply(result_high, memory_high, mask_high,
memory_high, quadword, false);
store_ymm_high128_shadow(result_high, dest_index);
}
ra_free_temp(mask_high);
ra_free_temp(result_high);
ra_free_temp(memory_high);
} else {
IR2_OPND memory = load_v128_from_ir1_mem_exact(mem);
IR2_OPND result = ra_alloc_ftemp();
IR2_OPND value;

if (store) {
value = ra_alloc_xmm(ir1_opnd_base_reg_num(opnd2));
vpmaskmov_lsx_apply(result, memory, mask_low, value,
quadword, true);
store_v128_to_ir1_mem_exact(result, mem);
} else {
int dest_index = ir1_opnd_base_reg_num(opnd0);

vpmaskmov_lsx_apply(result, memory, mask_low, memory,
quadword, false);
la_vori_b(ra_alloc_xmm(dest_index), result, 0);
clear_ymm_high128_shadow(dest_index);
}
ra_free_temp(result);
ra_free_temp(memory);
}
ra_free_temp(mask_low);
return true;
return translate_vmaskmovpx(pir1);
}

bool translate_vzeroall_lsx(IR1_INST *pir1)
Expand Down Expand Up @@ -4890,11 +4769,13 @@ static void translate_avx_gather_lane_lsx(IR2_OPND dest,
int lane,
int index_lane,
bool index64,
bool value64)
bool value64,
int dest_index,
int mask_index,
bool high)
{
IR2_OPND mask_value = ra_alloc_itemp();
IR2_OPND index_value = ra_alloc_itemp();
IR2_OPND loaded = ra_alloc_itemp();
IR2_OPND select = ra_alloc_label();
IR2_OPND done = ra_alloc_label();

Expand All @@ -4920,21 +4801,30 @@ static void translate_avx_gather_lane_lsx(IR2_OPND dest,
la_label(select);
/* x86 gathers access memory only for lanes with a negative mask. */
adjust_vsib_index(address, base_addr, index_value, scale);
ra_free_temp(index_value);
ra_free_temp(mask_value);
gen_test_page_flag(address, 0, PAGE_READ, value64 ? 8 : 4);
IR2_OPND loaded = ra_alloc_itemp();
if (value64) {
la_ld_d(loaded, address, 0);
} else {
la_ld_w(loaded, address, 0);
}
if (value64) {
la_vinsgr2vr_d(dest, loaded, lane);
la_vinsgr2vr_d(mask_values, zero_ir2_opnd, lane);
} else {
la_vinsgr2vr_w(dest, loaded, lane);
la_vinsgr2vr_w(mask_values, zero_ir2_opnd, lane);
}
if (high) {
/* Signal recovery reads LSX YMM upper halves from the shadow. */
store_ymm_high128_shadow(dest, dest_index);
store_ymm_high128_shadow(mask_values, mask_index);
}

la_label(done);
ra_free_temp(loaded);
ra_free_temp(index_value);
ra_free_temp(mask_value);
}

static bool translate_avx_gather_lsx(IR1_INST *pir1,
Expand All @@ -4955,10 +4845,10 @@ static bool translate_avx_gather_lsx(IR1_INST *pir1,
IR2_OPND address = ra_alloc_itemp();
IR2_OPND index_low = ra_alloc_ftemp();
IR2_OPND index_high_values = { 0 };
IR2_OPND mask_low_values = ra_alloc_ftemp();
IR2_OPND mask_high_values = { 0 };
IR2_OPND mask_low_store = ra_alloc_xmm(mask_index);
IR2_OPND dest_low = ra_alloc_ftemp();
IR2_OPND mask_low_values = mask_low_store;
IR2_OPND mask_high_values = { 0 };
IR2_OPND dest_low = ra_alloc_xmm(dest_index);
IR2_OPND dest_high_values = { 0 };
bool index_ymm;

Expand All @@ -4980,8 +4870,6 @@ static bool translate_avx_gather_lsx(IR1_INST *pir1,
la_add(base_addr, base_addr, base);
}
la_vori_b(index_low, ra_alloc_xmm(index_index), 0);
la_vori_b(mask_low_values, mask_low_store, 0);
la_vori_b(dest_low, ra_alloc_xmm(dest_index), 0);
if (index_ymm) {
index_high_values = load_ymm_high128_shadow(index_index);
}
Expand Down Expand Up @@ -5028,12 +4916,11 @@ static bool translate_avx_gather_lsx(IR1_INST *pir1,
translate_avx_gather_lane_lsx(
dest, mask_values, index_values, base_addr,
address, ir1_opnd_scale(opnd1), lane, index_lane,
index64, value64);
index64, value64, dest_index, mask_index, high);
}
}

/* A successfully completed gather clears every mask element. */
la_vori_b(ra_alloc_xmm(dest_index), dest_low, 0);
la_vxor_v(mask_low_store, mask_low_store, mask_low_store);
if (ymm) {
store_ymm_high128_shadow(dest_high_values, dest_index);
Expand All @@ -5049,8 +4936,6 @@ static bool translate_avx_gather_lsx(IR1_INST *pir1,
if (index_ymm) {
ra_free_temp(index_high_values);
}
ra_free_temp(dest_low);
ra_free_temp(mask_low_values);
ra_free_temp(index_low);
ra_free_temp(address);
ra_free_temp(base_addr);
Expand Down
Loading