[PATCH 4/9] include/hw: introduce CPU_MAX_NEGATIVE_ENV_OFFSET

Anton Johansson via posted 9 patches 2 years, 7 months ago
Maintainers: Richard Henderson <richard.henderson@linaro.org>, Paolo Bonzini <pbonzini@redhat.com>, Eduardo Habkost <eduardo@habkost.net>, Marcel Apfelbaum <marcel.apfelbaum@gmail.com>, "Philippe Mathieu-Daudé" <philmd@linaro.org>, Yanan Wang <wangyanan55@huawei.com>, Peter Maydell <peter.maydell@linaro.org>, Michael Rolnik <mrolnik@gmail.com>, "Edgar E. Iglesias" <edgar.iglesias@gmail.com>, Brian Cain <bcain@quicinc.com>, Song Gao <gaosong@loongson.cn>, Xiaojuan Yang <yangxiaojuan@loongson.cn>, Laurent Vivier <laurent@vivier.eu>, Aurelien Jarno <aurelien@aurel32.net>, Jiaxun Yang <jiaxun.yang@flygoat.com>, Aleksandar Rikalo <aleksandar.rikalo@syrmia.com>, Chris Wulff <crwulff@gmail.com>, Marek Vasut <marex@denx.de>, Stafford Horne <shorne@gmail.com>, Daniel Henrique Barboza <danielhb413@gmail.com>, "Cédric Le Goater" <clg@kaod.org>, David Gibson <david@gibson.dropbear.id.au>, Greg Kurz <groug@kaod.org>, Nicholas Piggin <npiggin@gmail.com>, Palmer Dabbelt <palmer@dabbelt.com>, Alistair Francis <alistair.francis@wdc.com>, Bin Meng <bin.meng@windriver.com>, Weiwei Li <liweiwei@iscas.ac.cn>, Liu Zhiwei <zhiwei_liu@linux.alibaba.com>, Yoshinori Sato <ysato@users.sourceforge.jp>, David Hildenbrand <david@redhat.com>, Ilya Leoshkevich <iii@linux.ibm.com>, Thomas Huth <thuth@redhat.com>, Mark Cave-Ayland <mark.cave-ayland@ilande.co.uk>, Artyom Tarasenko <atar4qemu@gmail.com>, Bastian Koppelmann <kbastian@mail.uni-paderborn.de>, Max Filippov <jcmvbkbc@gmail.com>
[PATCH 4/9] include/hw: introduce CPU_MAX_NEGATIVE_ENV_OFFSET
Posted by Anton Johansson via 2 years, 7 months ago
For reasons related to code-generation quality, the offset of
CPUTLBDescFast and IcountDecr from CPUArchState needs to fit within
11 bits of displacement (arm[32|64] and riscv addressing modes).

This commit introduces a new constant to store the maximum allowed
negative offset, so it can be statically asserted to hold later on.

Signed-off-by: Anton Johansson <anjo@rev.ng>
---
 include/hw/core/cpu.h | 11 +++++++++++
 1 file changed, 11 insertions(+)

diff --git a/include/hw/core/cpu.h b/include/hw/core/cpu.h
index c226d7263c..0377f74d48 100644
--- a/include/hw/core/cpu.h
+++ b/include/hw/core/cpu.h
@@ -259,6 +259,17 @@ struct qemu_work_item;
 
 #define CPU_UNSET_NUMA_NODE_ID -1
 
+/*
+ * For reasons related to code-generation quality the fast path
+ * CPUTLBDescFast array and IcountDecr fields need to be located within a
+ * small negative offset of CPUArchState.  This requirement comes from
+ * host-specific addressing modes of arm[32|64] and riscv which uses 12-
+ * and 11 bits of displacement respectively.
+ */
+#define CPU_MIN_DISPLACEMENT_BITS 11
+#define CPU_MAX_NEGATIVE_ENV_OFFSET \
+    (-(1 << CPU_MIN_DISPLACEMENT_BITS))
+
 /**
  * CPUState:
  * @cpu_index: CPU index (informative).
-- 
2.41.0
Re: [PATCH 4/9] include/hw: introduce CPU_MAX_NEGATIVE_ENV_OFFSET
Posted by Richard Henderson 2 years, 7 months ago
On 6/30/23 14:25, Anton Johansson wrote:
> For reasons related to code-generation quality, the offset of
> CPUTLBDescFast and IcountDecr from CPUArchState needs to fit within
> 11 bits of displacement (arm[32|64] and riscv addressing modes).
> 
> This commit introduces a new constant to store the maximum allowed
> negative offset, so it can be statically asserted to hold later on.
> 
> Signed-off-by: Anton Johansson <anjo@rev.ng>
> ---
>   include/hw/core/cpu.h | 11 +++++++++++
>   1 file changed, 11 insertions(+)
> 
> diff --git a/include/hw/core/cpu.h b/include/hw/core/cpu.h
> index c226d7263c..0377f74d48 100644
> --- a/include/hw/core/cpu.h
> +++ b/include/hw/core/cpu.h
> @@ -259,6 +259,17 @@ struct qemu_work_item;
>   
>   #define CPU_UNSET_NUMA_NODE_ID -1
>   
> +/*
> + * For reasons related to code-generation quality the fast path
> + * CPUTLBDescFast array and IcountDecr fields need to be located within a
> + * small negative offset of CPUArchState.  This requirement comes from
> + * host-specific addressing modes of arm[32|64] and riscv which uses 12-
> + * and 11 bits of displacement respectively.
> + */
> +#define CPU_MIN_DISPLACEMENT_BITS 11
> +#define CPU_MAX_NEGATIVE_ENV_OFFSET \
> +    (-(1 << CPU_MIN_DISPLACEMENT_BITS))

You'd want 6 bits, for AArch64 LDP (7-bit signed immediate).


r~
Re: [PATCH 4/9] include/hw: introduce CPU_MAX_NEGATIVE_ENV_OFFSET
Posted by Anton Johansson via 2 years, 7 months ago
On 6/30/23 16:19, Richard Henderson wrote:
> On 6/30/23 14:25, Anton Johansson wrote:
>> For reasons related to code-generation quality, the offset of
>> CPUTLBDescFast and IcountDecr from CPUArchState needs to fit within
>> 11 bits of displacement (arm[32|64] and riscv addressing modes).
>>
>> This commit introduces a new constant to store the maximum allowed
>> negative offset, so it can be statically asserted to hold later on.
>>
>> Signed-off-by: Anton Johansson <anjo@rev.ng>
>> ---
>>   include/hw/core/cpu.h | 11 +++++++++++
>>   1 file changed, 11 insertions(+)
>>
>> diff --git a/include/hw/core/cpu.h b/include/hw/core/cpu.h
>> index c226d7263c..0377f74d48 100644
>> --- a/include/hw/core/cpu.h
>> +++ b/include/hw/core/cpu.h
>> @@ -259,6 +259,17 @@ struct qemu_work_item;
>>     #define CPU_UNSET_NUMA_NODE_ID -1
>>   +/*
>> + * For reasons related to code-generation quality the fast path
>> + * CPUTLBDescFast array and IcountDecr fields need to be located 
>> within a
>> + * small negative offset of CPUArchState.  This requirement comes from
>> + * host-specific addressing modes of arm[32|64] and riscv which uses 
>> 12-
>> + * and 11 bits of displacement respectively.
>> + */
>> +#define CPU_MIN_DISPLACEMENT_BITS 11
>> +#define CPU_MAX_NEGATIVE_ENV_OFFSET \
>> +    (-(1 << CPU_MIN_DISPLACEMENT_BITS))
>
> You'd want 6 bits, for AArch64 LDP (7-bit signed immediate).

Ah right, but it's scaled so it would be -512 for AArch64 and -256 for 
arm32,
that would also agree with the smallest MIN_TLB_MASK_TABLE_OFS  in
the backends.

-- 
Anton Johansson,
rev.ng Labs Srl.