public inbox for igt-dev@lists.freedesktop.org
 help / color / mirror / Atom feed
From: "Maíra Canal" <mcanal@igalia.com>
To: "Melissa Wen" <mwen@igalia.com>,
	"André Almeida" <andrealmeid@igalia.com>,
	"Petri Latvala" <petri.latvala@intel.com>,
	"Kamil Konieczny" <kamil.konieczny@linux.intel.com>,
	"Emma Anholt" <emma@anholt.net>,
	"Iago Toral Quiroga" <itoral@igalia.com>
Cc: igt-dev@lists.freedesktop.org
Subject: [igt-dev] [PATCH i-g-t v4 1/6] lib/v3d: Add V3D packet helpers
Date: Mon, 30 Jan 2023 14:57:53 -0300	[thread overview]
Message-ID: <20230130175758.420535-2-mcanal@igalia.com> (raw)
In-Reply-To: <20230130175758.420535-1-mcanal@igalia.com>

In order to make a valid job submission to V3D, some packet helpers are
needed. They are responsible for handling the data and packing it
properly. Moreover, they reuse some of the generic packet helpers from
Mesa, the bit pack helpers. Therefore, add Mesa V3D's packet helpers for
IGT use.

Reviewed-by: Melissa Wen <mwen@igalia.com>
Signed-off-by: Maíra Canal <mcanal@igalia.com>
---
 lib/bitpack_helpers.h        |  60 ++++++++++++++++++++
 lib/v3d/v3d_packet_helpers.h | 104 +++++++++++++++++++++++++++++++++++
 2 files changed, 164 insertions(+)
 create mode 100644 lib/bitpack_helpers.h
 create mode 100644 lib/v3d/v3d_packet_helpers.h

diff --git a/lib/bitpack_helpers.h b/lib/bitpack_helpers.h
new file mode 100644
index 00000000..e93c695f
--- /dev/null
+++ b/lib/bitpack_helpers.h
@@ -0,0 +1,60 @@
+/* SPDX-License-Identifier: MIT */
+/*
+ * Copyright (C) 2016 Intel Corporation
+ */
+
+#ifndef UTIL_BITPACK_HELPERS_H
+#define UTIL_BITPACK_HELPERS_H
+
+#include <math.h>
+#include <stdbool.h>
+#include <stdint.h>
+
+#ifndef util_bitpack_validate_value
+#define util_bitpack_validate_value(x)
+#endif
+
+/** Set a single bit */
+#define BITFIELD64_BIT(b)      (1ull << (b))
+/** Set all bits up to excluding bit b */
+#define BITFIELD64_MASK(b)      \
+	((b) == 64 ? (~0ull) : BITFIELD64_BIT(b) - 1)
+
+static inline uint64_t
+util_bitpack_uint(uint64_t v, uint32_t start, __attribute__((unused)) uint32_t end)
+{
+	util_bitpack_validate_value(v);
+	return v << start;
+}
+
+static inline uint64_t
+util_bitpack_sint(int64_t v, uint32_t start, uint32_t end)
+{
+	const int bits = end - start + 1;
+	const uint64_t mask = BITFIELD64_MASK(bits);
+
+	return (v & mask) << start;
+}
+
+static inline uint64_t
+util_bitpack_sfixed(float v, uint32_t start, uint32_t end,
+		    uint32_t fract_bits)
+{
+	const float factor = (1 << fract_bits);
+	const int64_t int_val = llroundf(v * factor);
+	const uint64_t mask = ~0ull >> (64 - (end - start + 1));
+
+	return (int_val & mask) << start;
+}
+
+static inline uint64_t
+util_bitpack_ufixed(float v, uint32_t start, __attribute__((unused)) uint32_t end,
+		    uint32_t fract_bits)
+{
+	const float factor = (1 << fract_bits);
+	const uint64_t uint_val = llroundf(v * factor);
+
+	return uint_val << start;
+}
+
+#endif /* UTIL_BITPACK_HELPERS_H */
diff --git a/lib/v3d/v3d_packet_helpers.h b/lib/v3d/v3d_packet_helpers.h
new file mode 100644
index 00000000..8428c275
--- /dev/null
+++ b/lib/v3d/v3d_packet_helpers.h
@@ -0,0 +1,104 @@
+/* SPDX-License-Identifier: MIT */
+/*
+ * Copyright (C) 2016 Intel Corporation
+ */
+
+#ifndef MESA_V3D_PACKET_HELPERS_H
+#define MESA_V3D_PACKET_HELPERS_H
+
+#include <assert.h>
+#include <stdint.h>
+
+#include "bitpack_helpers.h"
+
+/*
+ * Copied from Mesa's u_math.h
+ */
+union fi {
+	float f;
+	int32_t i;
+	uint32_t ui;
+};
+
+static inline float uif(uint32_t ui)
+{
+	union fi fi;
+
+	fi.ui = ui;
+	return fi.f;
+}
+
+static inline unsigned int fui(float f)
+{
+	union fi fi;
+
+	fi.f = f;
+	return fi.ui;
+}
+
+static inline uint64_t
+__gen_unpack_uint(const uint8_t *restrict cl, uint32_t start, uint32_t end)
+{
+	uint64_t val = 0;
+	const int width = end - start + 1;
+	const uint32_t mask = (width == 32 ? ~0 : (1 << width) - 1);
+
+	for (uint32_t byte = start / 8; byte <= end / 8; byte++)
+		val |= cl[byte] << ((byte - start / 8) * 8);
+
+	return (val >> (start % 8)) & mask;
+}
+
+static inline uint64_t
+__gen_unpack_sint(const uint8_t *restrict cl, uint32_t start, uint32_t end)
+{
+	int size = end - start + 1;
+	int64_t val = __gen_unpack_uint(cl, start, end);
+
+	/* Get the sign bit extended. */
+	return (val << (64 - size)) >> (64 - size);
+}
+
+static inline float
+__gen_unpack_sfixed(const uint8_t *restrict cl, uint32_t start, uint32_t end,
+		    uint32_t fractional_size)
+{
+	int32_t bits = __gen_unpack_sint(cl, start, end);
+
+	return (float)bits / (1 << fractional_size);
+}
+
+static inline float
+__gen_unpack_ufixed(const uint8_t *restrict cl, uint32_t start, uint32_t end,
+		    uint32_t fractional_size)
+{
+	int32_t bits = __gen_unpack_uint(cl, start, end);
+
+	return (float)bits / (1 << fractional_size);
+}
+
+static inline float
+__gen_unpack_float(const uint8_t *restrict cl, uint32_t start, uint32_t end)
+{
+	struct PACKED { float f; } *f;
+
+	assert(start % 8 == 0);
+	assert(end - start == 31);
+
+	f = (void *)(cl + (start / 8));
+
+	return f->f;
+}
+
+static inline float
+__gen_unpack_f187(const uint8_t *restrict cl, uint32_t start, uint32_t end)
+{
+	uint32_t bits;
+
+	assert(end - start == 15);
+
+	bits = __gen_unpack_uint(cl, start, end);
+	return uif(bits << 16);
+}
+
+#endif
-- 
2.39.1

  reply	other threads:[~2023-01-30 17:59 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-01-30 17:57 [igt-dev] [PATCH i-g-t v4 0/6] V3D Job Submission Tests Maíra Canal
2023-01-30 17:57 ` Maíra Canal [this message]
2023-01-30 17:57 ` [igt-dev] [PATCH i-g-t v4 2/6] lib/v3d: Add V3D packet description Maíra Canal
2023-01-30 17:57 ` [igt-dev] [PATCH i-g-t v4 3/6] lib/v3d: Introduce the struct v3d_cl_job Maíra Canal
2023-01-30 17:57 ` [igt-dev] [PATCH i-g-t v4 4/6] lib/v3d: Add a helper to create a noop job Maíra Canal
2023-01-30 17:57 ` [igt-dev] [PATCH i-g-t v4 5/6] tests/v3d_wait_bo: Create test for V3D's Wait BO IOCTL Maíra Canal
2023-01-30 17:57 ` [igt-dev] [PATCH i-g-t v4 6/6] tests/v3d_submit_cl: Create test for V3D's Submit CL IOCTL Maíra Canal
2023-01-30 18:32 ` [igt-dev] ✓ Fi.CI.BAT: success for V3D Job Submission Tests (rev4) Patchwork
2023-01-31  0:32 ` [igt-dev] ✓ Fi.CI.IGT: " Patchwork

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=20230130175758.420535-2-mcanal@igalia.com \
    --to=mcanal@igalia.com \
    --cc=andrealmeid@igalia.com \
    --cc=emma@anholt.net \
    --cc=igt-dev@lists.freedesktop.org \
    --cc=itoral@igalia.com \
    --cc=kamil.konieczny@linux.intel.com \
    --cc=mwen@igalia.com \
    --cc=petri.latvala@intel.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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox