Message ID | 20221111074101.2069454-15-richard.henderson@linaro.org |
---|---|
State | Superseded |
Headers | show |
Series | tcg: Support for Int128 with helpers | expand |
On 11/11/22 08:40, Richard Henderson wrote: > Add a helper function for computing the size of a type. > > Signed-off-by: Richard Henderson <richard.henderson@linaro.org> > --- > include/tcg/tcg.h | 16 ++++++++++++++++ > tcg/tcg.c | 26 ++++++++++++-------------- > 2 files changed, 28 insertions(+), 14 deletions(-) > > diff --git a/include/tcg/tcg.h b/include/tcg/tcg.h > index f2da340bb9..8bcd60d0ed 100644 > --- a/include/tcg/tcg.h > +++ b/include/tcg/tcg.h > @@ -319,6 +319,22 @@ typedef enum TCGType { > #endif > } TCGType; > > +/** > + * tcg_type_size > + * @t: type > + * > + * Return the size of the type in bytes. > + */ > +static inline int tcg_type_size(TCGType t) > +{ > + unsigned i = t; > + if (i >= TCG_TYPE_V64) { > + tcg_debug_assert(i < TCG_TYPE_COUNT); > + i -= TCG_TYPE_V64 - 1; > + } > + return 4 << i; I'd feel safer if we assign TCG_TYPE_I32 .. TCG_TYPE_V256 in TCGType, just in case. > +} Reviewed-by: Philippe Mathieu-Daudé <philmd@linaro.org>
On 11/22/22 03:30, Philippe Mathieu-Daudé wrote: > On 11/11/22 08:40, Richard Henderson wrote: >> Add a helper function for computing the size of a type. >> >> Signed-off-by: Richard Henderson <richard.henderson@linaro.org> >> --- >> include/tcg/tcg.h | 16 ++++++++++++++++ >> tcg/tcg.c | 26 ++++++++++++-------------- >> 2 files changed, 28 insertions(+), 14 deletions(-) >> >> diff --git a/include/tcg/tcg.h b/include/tcg/tcg.h >> index f2da340bb9..8bcd60d0ed 100644 >> --- a/include/tcg/tcg.h >> +++ b/include/tcg/tcg.h >> @@ -319,6 +319,22 @@ typedef enum TCGType { >> #endif >> } TCGType; >> +/** >> + * tcg_type_size >> + * @t: type >> + * >> + * Return the size of the type in bytes. >> + */ >> +static inline int tcg_type_size(TCGType t) >> +{ >> + unsigned i = t; >> + if (i >= TCG_TYPE_V64) { >> + tcg_debug_assert(i < TCG_TYPE_COUNT); >> + i -= TCG_TYPE_V64 - 1; >> + } >> + return 4 << i; > > I'd feel safer if we assign TCG_TYPE_I32 .. TCG_TYPE_V256 in TCGType, > just in case. What do you mean? r~
On 22/11/22 17:54, Richard Henderson wrote: > On 11/22/22 03:30, Philippe Mathieu-Daudé wrote: >> On 11/11/22 08:40, Richard Henderson wrote: >>> Add a helper function for computing the size of a type. >>> >>> Signed-off-by: Richard Henderson <richard.henderson@linaro.org> >>> --- >>> include/tcg/tcg.h | 16 ++++++++++++++++ >>> tcg/tcg.c | 26 ++++++++++++-------------- >>> 2 files changed, 28 insertions(+), 14 deletions(-) >>> >>> diff --git a/include/tcg/tcg.h b/include/tcg/tcg.h >>> index f2da340bb9..8bcd60d0ed 100644 >>> --- a/include/tcg/tcg.h >>> +++ b/include/tcg/tcg.h >>> @@ -319,6 +319,22 @@ typedef enum TCGType { >>> #endif >>> } TCGType; >>> +/** >>> + * tcg_type_size >>> + * @t: type >>> + * >>> + * Return the size of the type in bytes. >>> + */ >>> +static inline int tcg_type_size(TCGType t) >>> +{ >>> + unsigned i = t; >>> + if (i >= TCG_TYPE_V64) { >>> + tcg_debug_assert(i < TCG_TYPE_COUNT); >>> + i -= TCG_TYPE_V64 - 1; >>> + } >>> + return 4 << i; >> >> I'd feel safer if we assign TCG_TYPE_I32 .. TCG_TYPE_V256 in TCGType, >> just in case. > > What do you mean? -- >8 -- diff --git a/include/tcg/tcg.h b/include/tcg/tcg.h @@ -289,8 +289,8 @@ typedef struct TCGPool { typedef enum TCGType { - TCG_TYPE_I32, - TCG_TYPE_I64, + TCG_TYPE_I32 = 0, + TCG_TYPE_I64 = 1, - TCG_TYPE_V64, - TCG_TYPE_V128, - TCG_TYPE_V256, + TCG_TYPE_V64 = 2, + TCG_TYPE_V128 = 3, + TCG_TYPE_V256 = 4, ---
On 11/22/22 10:14, Philippe Mathieu-Daudé wrote: >>> I'd feel safer if we assign TCG_TYPE_I32 .. TCG_TYPE_V256 in TCGType, >>> just in case. >> >> What do you mean? > > -- >8 -- > diff --git a/include/tcg/tcg.h b/include/tcg/tcg.h > @@ -289,8 +289,8 @@ typedef struct TCGPool { > typedef enum TCGType { > - TCG_TYPE_I32, > - TCG_TYPE_I64, > + TCG_TYPE_I32 = 0, > + TCG_TYPE_I64 = 1, > > - TCG_TYPE_V64, > - TCG_TYPE_V128, > - TCG_TYPE_V256, > + TCG_TYPE_V64 = 2, > + TCG_TYPE_V128 = 3, > + TCG_TYPE_V256 = 4, But that's what C does. I don't see the point. r~
diff --git a/include/tcg/tcg.h b/include/tcg/tcg.h index f2da340bb9..8bcd60d0ed 100644 --- a/include/tcg/tcg.h +++ b/include/tcg/tcg.h @@ -319,6 +319,22 @@ typedef enum TCGType { #endif } TCGType; +/** + * tcg_type_size + * @t: type + * + * Return the size of the type in bytes. + */ +static inline int tcg_type_size(TCGType t) +{ + unsigned i = t; + if (i >= TCG_TYPE_V64) { + tcg_debug_assert(i < TCG_TYPE_COUNT); + i -= TCG_TYPE_V64 - 1; + } + return 4 << i; +} + /** * get_alignment_bits * @memop: MemOp value diff --git a/tcg/tcg.c b/tcg/tcg.c index f9315d00fc..ec03bd3d6a 100644 --- a/tcg/tcg.c +++ b/tcg/tcg.c @@ -3110,22 +3110,22 @@ static void check_regs(TCGContext *s) static void temp_allocate_frame(TCGContext *s, TCGTemp *ts) { - intptr_t off, size, align; + int size = tcg_type_size(ts->type); + int align; + intptr_t off; switch (ts->type) { case TCG_TYPE_I32: - size = align = 4; + align = 4; break; case TCG_TYPE_I64: case TCG_TYPE_V64: - size = align = 8; + align = 8; break; case TCG_TYPE_V128: - size = align = 16; - break; case TCG_TYPE_V256: /* Note that we do not require aligned storage for V256. */ - size = 32, align = 16; + align = 16; break; default: g_assert_not_reached(); @@ -3641,8 +3641,8 @@ static void tcg_reg_alloc_dup(TCGContext *s, const TCGOp *op) TCGRegSet dup_out_regs, dup_in_regs; TCGTemp *its, *ots; TCGType itype, vtype; - intptr_t endian_fixup; unsigned vece; + int lowpart_ofs; bool ok; ots = arg_temp(op->args[0]); @@ -3711,14 +3711,12 @@ static void tcg_reg_alloc_dup(TCGContext *s, const TCGOp *op) /* fall through */ case TEMP_VAL_MEM: -#if HOST_BIG_ENDIAN - endian_fixup = itype == TCG_TYPE_I32 ? 4 : 8; - endian_fixup -= 1 << vece; -#else - endian_fixup = 0; -#endif + lowpart_ofs = 0; + if (HOST_BIG_ENDIAN) { + lowpart_ofs = tcg_type_size(itype) - (1 << vece); + } if (tcg_out_dupm_vec(s, vtype, vece, ots->reg, its->mem_base->reg, - its->mem_offset + endian_fixup)) { + its->mem_offset + lowpart_ofs)) { goto done; } tcg_out_ld(s, itype, ots->reg, its->mem_base->reg, its->mem_offset);
Add a helper function for computing the size of a type. Signed-off-by: Richard Henderson <richard.henderson@linaro.org> --- include/tcg/tcg.h | 16 ++++++++++++++++ tcg/tcg.c | 26 ++++++++++++-------------- 2 files changed, 28 insertions(+), 14 deletions(-)