All of lore.kernel.org
 help / color / mirror / Atom feed
From: Alessandro Di Federico via qemu development <qemu-devel@nongnu.org>
To: Anton Johansson <anjo@rev.ng>
Cc: qemu-devel@nongnu.org, brian.cain@oss.qualcomm.com,
	pierrick.bouvier@oss.qualcomm.com, philmd@mailo.com
Subject: Re: [PATCH v2 21/50] helper-to-tcg: Add guest vector layout description
Date: Wed, 16 Sep 2026 14:28:48 +0200	[thread overview]
Message-ID: <20260916142848.732526d7@spawn> (raw)
In-Reply-To: <20260730031025.12926-22-anjo@rev.ng>

On Thu, 30 Jul 2026 05:09:55 +0200
Anton Johansson <anjo@rev.ng> wrote:

> Vectors are represented as arrays of host-endian blocks at least 64 bits in
> size, the size of which is configurable.  Lane 0 in each block may be
> placed either at the most- or least-significant bytes.
> 
> This covers a wide range of QEMU targets' vector representations.
> 
> Vector layout information is used later when mapping constant
> expressions such as constant vectors, and when emitting helper functions
> for performing size-changing operations.
> 
> Signed-off-by: Anton Johansson <anjo@rev.ng>
> ---
>  .../helper-to-tcg/include/VectorLayout.hpp    | 116 ++++++++++++++++++
>  1 file changed, 116 insertions(+)
>  create mode 100644 subprojects/helper-to-tcg/include/VectorLayout.hpp
> 
> diff --git a/subprojects/helper-to-tcg/include/VectorLayout.hpp b/subprojects/helper-to-tcg/include/VectorLayout.hpp
> new file mode 100644
> index 0000000000..e85f5029d5
> --- /dev/null
> +++ b/subprojects/helper-to-tcg/include/VectorLayout.hpp
> @@ -0,0 +1,116 @@
> +//
> +//  Copyright(c) 2026 rev.ng Labs Srl. All Rights Reserved.
> +//
> +//  This program is free software; you can redistribute it and/or modify
> +//  it under the terms of the GNU General Public License as published by
> +//  the Free Software Foundation; either version 2 of the License, or
> +//  (at your option) any later version.
> +//
> +//  This program is distributed in the hope that it will be useful,
> +//  but WITHOUT ANY WARRANTY; without even the implied warranty of
> +//  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
> +//  GNU General Public License for more details.
> +//
> +//  You should have received a copy of the GNU General Public License
> +//  along with this program; if not, see <http://www.gnu.org/licenses/>.
> +//
> +
> +#pragma once
> +
> +#include <llvm/ADT/ArrayRef.h>
> +#include <stddef.h>
> +#include <stdint.h>
> +
> +// Vector Layout
> +//
> +// Vector layouts among QEMU guests is quite diverse, this header aims to be
> +// simple but still capture a large subset of targets.
> +//
> +// Guest vectors are assumed to be divided into host-endian blocks of a
> +// configurable size (>= 64-bit and power-of-two), with block 0 always being at
> +// the lowest address.  Blocks in turn are divided into 64-bit columns which are
> +// used when interfacing with QEMUs `gvec` API.
> +//
> +// Below is a 32-byte <32 x i8> guest vector consisting of 16-byte blocks,
> +// 8-byte columns, and 1-byte lanes for each element in the vector.  Elements
> +// count from 1-32 in hex to indicate their position in memory.  Note this
> +// example is for a little-endian host with `LeastSignificant` lane preference
> +// meaning lane 0 is at the least significant bytes of each block.
> +//
> +//   Guest vector <32 x i8> {1, 2, 3, ..., 32}
> +//   +---------------------------------+---------------------------------+
> +//   |              BLOCK 0            |              BLOCK 1            |
> +//   +----------------+----------------+----------------+----------------+
> +//   |    COLUMN 0    |    COLUMN 1    |    COLUMN 2    |    COLUMN 3    |
> +//   |0102030405060708|090A0B0C0D0E0F10|1112131415161718|191A1B1C1D1E1F20|
> +//
> +//   LOW ADDRESS                                              HIGH ADDRESS
> +//
> +// On a big-endian host, the vector would instead be expressed in memory as
> +//
> +//   Guest vector <32 x i8> {1, 2, 3, ..., 32}
> +//   +---------------------------------+---------------------------------+
> +//   |              BLOCK 0            |              BLOCK 1            |
> +//   +----------------+----------------+----------------+----------------+
> +//   |    COLUMN 1    |    COLUMN 0    |    COLUMN 3    |    COLUMN 2    |
> +//   |100F0E0D0C0B0A09|0807060504030201|201F1E1D1C1B1A19|1817161514131211|
> +//
> +//   LOW ADDRESS                                              HIGH ADDRESS
> +//
> +// with the column order having shifted to make sure the host-endian blocks
> +// retain the same value.  Blocks are also allowed to be equal or greater in
> +// size that the guest vector, at which point the entire memory view of the
> +// vector would reverse when going from a little to big-endian host.
> +//
> +// The lane preference may also be changed to `MostSignificant` which for the
> +// little-endian example places lane 0 and the highest address of block 0.
> +// Note, that `MostSignificant` on little-endian and `LeastSignificant` on
> +// big-endian hosts are equivalent in their memory representation, but will
> +// differ in how they are emitted in C:
> +//
> +//   // MostSignificant, little endian
> +//   uint64_t vec[] = {0x90A0B0C0D0E0F10, 0x102030405060708, ...};
> +//
> +//   // LeastSignificant, big endian
> +//   uint64_t vec[] = {0x100F0E0D0C0B0A09, 0x807060504030201, ...};
> +//
> +
> +enum LanePreference {
> +    LeastSignificant,
> +    MostSignificant,
> +};
> +
> +struct VectorLayout {
> +    bool HostBigEndian;
> +    LanePreference Lane0;
> +    size_t BlockBytes;
> +
> +    inline size_t index(bool Reverse, size_t Count, size_t I, size_t J) const {

Methods defined inline are implicitly inline. Drop.

> +        if (Reverse) {
> +            return Count * I + (J ^ (Count - 1));
> +        } else {
> +            return Count * I + J;
> +        }
> +    }
> +
> +    // Return the index into a linear array of lane L in column C
> +    inline size_t indexLane(size_t LanesPerColumn, size_t C, size_t L) const {
> +        const bool Reverse = (Lane0 == MostSignificant);
> +        return index(Reverse, LanesPerColumn, C, L);
> +    }
> +
> +    // Return the index into a linear array of
> +    inline size_t indexBlock(size_t BlocksPerVec, size_t I) const {
> +        const bool Reverse = (HostBigEndian ^ (Lane0 == MostSignificant));
> +        return index(Reverse, BlocksPerVec, 0, I);
> +    }
> +
> +    //inline uint64_t column(llvm::ArrayRef<uint64_t> Lanes) {
> +    //    uint64_t Column = 0;
> +    //    const size_t LanesPerColumn = 64 / ElementSize;
> +    //    for (size_t L = 0; L < LanesPerColumn; ++L) {
> +    //        const size_t Index = VL.indexLane(LanesPerColumn, C, L);
> +    //        Column |= Ints[Index] << (ElementSize * L);
> +    //    }
> +    //}

Do not commit commented code.

> +};
> -- 
> 2.52.0

Reviewed-by: Alessandro Di Federico <ale@rev.ng>

-- 
Alessandro Di Federico
rev.ng Labs


  reply	other threads:[~2026-09-16 13:28 UTC|newest]

Thread overview: 88+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-07-30  3:09 [PATCH v2 00/50] Introduce helper-to-tcg Anton Johansson via qemu development
2026-07-30  3:09 ` [PATCH v2 01/50] accel/tcg: Add bitreverse and funnel-shift runtime helper functions Anton Johansson via qemu development
2026-07-30  8:04   ` Philippe Mathieu-Daudé
2026-07-30 14:43   ` Richard Henderson
2026-07-30  3:09 ` [PATCH v2 02/50] accel/tcg: Add getpc helper Anton Johansson via qemu development
2026-07-30 14:48   ` Richard Henderson
2026-07-30  3:09 ` [PATCH v2 03/50] tcg: Introduce tcg-global-mappings Anton Johansson via qemu development
2026-07-30 16:11   ` Richard Henderson
2026-07-30  3:09 ` [PATCH v2 04/50] tcg: Increase maximum TB size Anton Johansson via qemu development
2026-07-30 16:13   ` Richard Henderson
2026-07-30  3:09 ` [PATCH v2 05/50] tcg: Expose tcg_gen_ussub_sat() Anton Johansson via qemu development
2026-07-30  7:52   ` Philippe Mathieu-Daudé
2026-07-30 16:17   ` Richard Henderson
2026-07-30  3:09 ` [PATCH v2 06/50] Add helper-to-tcg subproject Anton Johansson via qemu development
2026-07-30 15:56   ` Alessandro Di Federico via qemu development
2026-07-30  3:09 ` [PATCH v2 07/50] helper-to-tcg: Introduce get-llvm-ir.py Anton Johansson via qemu development
2026-08-04 12:08   ` Alessandro Di Federico via qemu development
2026-08-11 11:35     ` Anton Johansson via qemu development
2026-07-30  3:09 ` [PATCH v2 08/50] helper-to-tcg: Handle LLVM version compatibility Anton Johansson via qemu development
2026-08-11 10:12   ` Alessandro Di Federico via qemu development
2026-07-30  3:09 ` [PATCH v2 09/50] helper-to-tcg: Introduce custom LLVM pipeline Anton Johansson via qemu development
2026-07-30  3:09 ` [PATCH v2 10/50] helper-to-tcg: Add pipeline --debug and --debug-only Anton Johansson via qemu development
2026-07-30  3:09 ` [PATCH v2 11/50] helper-to-tcg: Add simple error creation helper Anton Johansson via qemu development
2026-07-30  3:09 ` [PATCH v2 12/50] helper-to-tcg: Introduce PrepareForOptPass Anton Johansson via qemu development
2026-07-30  3:09 ` [PATCH v2 13/50] helper-to-tcg: PrepareForOptPass, demangle function names Anton Johansson via qemu development
2026-08-07 16:03   ` Alessandro Di Federico via qemu development
2026-08-11 10:09     ` Anton Johansson via qemu development
2026-07-30  3:09 ` [PATCH v2 14/50] helper-to-tcg: PrepareForOptPass, map annotations Anton Johansson via qemu development
2026-08-07 10:26   ` Alessandro Di Federico via qemu development
2026-08-11  9:52     ` Anton Johansson via qemu development
2026-08-11 10:12   ` Alessandro Di Federico via qemu development
2026-07-30  3:09 ` [PATCH v2 15/50] helper-to-tcg: PrepareForOptPass, cull unused functions Anton Johansson via qemu development
2026-08-11 10:13   ` Alessandro Di Federico via qemu development
2026-07-30  3:09 ` [PATCH v2 16/50] helper-to-tcg: PrepareForOptPass, undef llvm.returnaddress Anton Johansson via qemu development
2026-08-11 10:12   ` Alessandro Di Federico via qemu development
2026-07-30  3:09 ` [PATCH v2 17/50] helper-to-tcg: PrepareForOptPass, fixup inline attributes Anton Johansson via qemu development
2026-08-11 10:12   ` Alessandro Di Federico via qemu development
2026-07-30  3:09 ` [PATCH v2 18/50] helper-to-tcg: PrepareForOptPass, collect debuginfo Anton Johansson via qemu development
2026-09-09 11:11   ` Alessandro Di Federico via qemu development
2026-07-30  3:09 ` [PATCH v2 19/50] helper-to-tcg: Pipeline, run optimization pass Anton Johansson via qemu development
2026-09-09 11:09   ` Alessandro Di Federico via qemu development
2026-07-30  3:09 ` [PATCH v2 20/50] helper-to-tcg: Introduce pseudo instructions Anton Johansson via qemu development
2026-09-09 11:09   ` Alessandro Di Federico via qemu development
2026-07-30  3:09 ` [PATCH v2 21/50] helper-to-tcg: Add guest vector layout description Anton Johansson via qemu development
2026-09-16 12:28   ` Alessandro Di Federico via qemu development [this message]
2026-07-30  3:09 ` [PATCH v2 22/50] helper-to-tcg: Introduce PrepareForTcgPass Anton Johansson via qemu development
2026-09-16 12:42   ` Alessandro Di Federico via qemu development
2026-07-30  3:09 ` [PATCH v2 23/50] helper-to-tcg: PrepareForTcgPass, remove functions with cycles Anton Johansson via qemu development
2026-09-16 13:16   ` Alessandro Di Federico via qemu development
2026-07-30  3:09 ` [PATCH v2 24/50] helper-to-tcg: PrepareForTcgPass, demote PHI nodes Anton Johansson via qemu development
2026-09-16 13:32   ` Alessandro Di Federico via qemu development
2026-07-30  3:09 ` [PATCH v2 25/50] helper-to-tcg: PrepareForTcgPass, map TCG globals Anton Johansson via qemu development
2026-07-30  3:10 ` [PATCH v2 26/50] helper-to-tcg: PrepareForTcgPass, transform GEPs Anton Johansson via qemu development
2026-07-30  3:10 ` [PATCH v2 27/50] helper-to-tcg: PrepareForTcgPass, canonicalize IR Anton Johansson via qemu development
2026-07-30  3:10 ` [PATCH v2 28/50] helper-to-tcg: PrepareForTcgPass, identity map trivial expressions Anton Johansson via qemu development
2026-07-30  3:10 ` [PATCH v2 29/50] helper-to-tcg: Introduce TcgV structure Anton Johansson via qemu development
2026-07-30  3:10 ` [PATCH v2 30/50] helper-to-tcg: Introduce TcgGenPass Anton Johansson via qemu development
2026-08-07 10:27   ` Alessandro Di Federico via qemu development
2026-08-11 10:16     ` Anton Johansson via qemu development
2026-07-30  3:10 ` [PATCH v2 31/50] helper-to-tcg: TcgGenPass, linearize basic blocks Anton Johansson via qemu development
2026-09-16 13:26   ` Alessandro Di Federico via qemu development
2026-07-30  3:10 ` [PATCH v2 32/50] helper-to-tcg: TcgGenPass, introduce Value <-> TcgV map Anton Johansson via qemu development
2026-07-30  3:10 ` [PATCH v2 33/50] helper-to-tcg: TcgGenPass, add structs for string emission Anton Johansson via qemu development
2026-07-30  3:10 ` [PATCH v2 34/50] helper-to-tcg: TcgGenPass, map arguments to TCG Anton Johansson via qemu development
2026-07-30  3:10 ` [PATCH v2 35/50] helper-to-tcg: TcgGenPass, propagate constant expresssions Anton Johansson via qemu development
2026-07-30  3:10 ` [PATCH v2 36/50] helper-to-tcg: TcgGenPass, allocate TCG registers Anton Johansson via qemu development
2026-07-30  3:10 ` [PATCH v2 37/50] helper-to-tcg: TcgGenPass, emit TCG strings Anton Johansson via qemu development
2026-07-30  3:10 ` [PATCH v2 38/50] helper-to-tcg: Add README Anton Johansson via qemu development
2026-07-30  3:10 ` [PATCH v2 39/50] helper-to-tcg: Add end-to-end tests Anton Johansson via qemu development
2026-07-30  3:10 ` [PATCH v2 40/50] test: helper-to-tcg docker tests Anton Johansson via qemu development
2026-07-31 11:46   ` Alessandro Di Federico via qemu development
2026-07-31 11:48   ` Alessandro Di Federico via qemu development
2026-07-31 16:47   ` Pierrick Bouvier
2026-07-30  3:10 ` [PATCH v2 41/50] target/hexagon: Add get_tb_mmu_index() Anton Johansson via qemu development
2026-07-30  7:49   ` Philippe Mathieu-Daudé
2026-07-30  3:10 ` [PATCH v2 42/50] target/hexagon: Increase VECTOR_TEMPS_MAX Anton Johansson via qemu development
2026-07-30  3:10 ` [PATCH v2 43/50] target/hexagon: Provide env to tcg global mapping Anton Johansson via qemu development
2026-07-30 16:28   ` Richard Henderson
2026-07-30  3:10 ` [PATCH v2 44/50] target/hexagon: Keep gen_slotval/check_noshuf for helper-to-tcg Anton Johansson via qemu development
2026-07-31 11:46   ` Alessandro Di Federico via qemu development
2026-07-30  3:10 ` [PATCH v2 45/50] target/hexagon: Emit annotations for helpers Anton Johansson via qemu development
2026-07-30  3:10 ` [PATCH v2 46/50] target/hexagon: Split probe_and_commit helper Anton Johansson via qemu development
2026-07-30  7:50   ` Philippe Mathieu-Daudé
2026-07-30  3:10 ` [PATCH v2 47/50] target/hexagon: Use helper-to-tcg helper calls Anton Johansson via qemu development
2026-07-30  3:10 ` [PATCH v2 48/50] target/hexagon: Manually call generated HVX instructions Anton Johansson via qemu development
2026-07-30  3:10 ` [PATCH v2 49/50] target/hexagon: Use idef-parser as a fallback Anton Johansson via qemu development
2026-07-30  3:10 ` [PATCH v2 50/50] target/hexagon: Use helper-to-tcg Anton Johansson via qemu development
2026-08-04 12:08   ` Alessandro Di Federico via qemu development

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20260916142848.732526d7@spawn \
    --to=qemu-devel@nongnu.org \
    --cc=ale@rev.ng \
    --cc=anjo@rev.ng \
    --cc=brian.cain@oss.qualcomm.com \
    --cc=philmd@mailo.com \
    --cc=pierrick.bouvier@oss.qualcomm.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.