From: Vladimir Serbinenko <phcoder@gmail.com>
To: grub-devel@gnu.org
Cc: Vladimir Serbinenko <phcoder@gmail.com>
Subject: [PATCH 2/8] compiler-rt: Add __multi3
Date: Wed, 11 Sep 2024 12:41:19 +0300 [thread overview]
Message-ID: <20240911094125.1813-2-phcoder@gmail.com> (raw)
In-Reply-To: <20240911094125.1813-1-phcoder@gmail.com>
It's necessary for clang sparc64 support
---
grub-core/kern/compiler-rt.c | 58 ++++++++++++++++++++++++++++++++++++
include/grub/compiler-rt.h | 7 +++++
2 files changed, 65 insertions(+)
diff --git a/grub-core/kern/compiler-rt.c b/grub-core/kern/compiler-rt.c
index eda689a0c..2902ed03d 100644
--- a/grub-core/kern/compiler-rt.c
+++ b/grub-core/kern/compiler-rt.c
@@ -452,3 +452,61 @@ __clzdi2 (grub_uint64_t val)
}
}
#endif
+
+#if defined(__sparc__) && defined(__clang__)
+/* Copied from multi3.c which is under MIT license. */
+typedef long long di_int;
+typedef unsigned long long du_int;
+
+typedef union
+{
+ grub_clang_ti_int all;
+ struct
+ {
+#ifndef GRUB_CPU_WORDS_BIGENDIAN
+ du_int low;
+ di_int high;
+#else
+ di_int high;
+ du_int low;
+#endif /* _YUGA_LITTLE_ENDIAN */
+ }s;
+} twords;
+
+static
+grub_clang_ti_int
+__mulddi3(du_int a, du_int b)
+{
+ twords r;
+ const int bits_in_dword_2 = (int)(sizeof(di_int) * 8) / 2;
+ const du_int lower_mask = (du_int)~0 >> bits_in_dword_2;
+ r.s.low = (a & lower_mask) * (b & lower_mask);
+ du_int t = r.s.low >> bits_in_dword_2;
+ r.s.low &= lower_mask;
+ t += (a >> bits_in_dword_2) * (b & lower_mask);
+ r.s.low += (t & lower_mask) << bits_in_dword_2;
+ r.s.high = t >> bits_in_dword_2;
+ t = r.s.low >> bits_in_dword_2;
+ r.s.low &= lower_mask;
+ t += (b >> bits_in_dword_2) * (a & lower_mask);
+ r.s.low += (t & lower_mask) << bits_in_dword_2;
+ r.s.high += t >> bits_in_dword_2;
+ r.s.high += (a >> bits_in_dword_2) * (b >> bits_in_dword_2);
+ return r.all;
+}
+
+/* Returns: a * b */
+
+grub_clang_ti_int
+__multi3(grub_clang_ti_int a, grub_clang_ti_int b)
+{
+ twords x;
+ x.all = a;
+ twords y;
+ y.all = b;
+ twords r;
+ r.all = __mulddi3(x.s.low, y.s.low);
+ r.s.high += x.s.high * y.s.low + x.s.low * y.s.high;
+ return r.all;
+}
+#endif
diff --git a/include/grub/compiler-rt.h b/include/grub/compiler-rt.h
index 17828b322..3637db47e 100644
--- a/include/grub/compiler-rt.h
+++ b/include/grub/compiler-rt.h
@@ -209,5 +209,12 @@ void EXPORT_FUNC (___chkstk_ms) (void);
void EXPORT_FUNC (__chkstk_ms) (void);
#endif
+#if defined(__sparc__) && defined(__clang__)
+/* Copied from multi3.c which is under MIT license. */
+typedef int grub_clang_ti_int __attribute__ ((mode (TI)));
+
+grub_clang_ti_int EXPORT_FUNC(__multi3) (grub_clang_ti_int a, grub_clang_ti_int b);
+#endif
+
#endif
--
2.39.2
_______________________________________________
Grub-devel mailing list
Grub-devel@gnu.org
https://lists.gnu.org/mailman/listinfo/grub-devel
next prev parent reply other threads:[~2024-09-11 9:42 UTC|newest]
Thread overview: 8+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-09-11 9:41 [PATCH 1/8] riscv64: Support riscv_align relocations Vladimir Serbinenko
2024-09-11 9:41 ` Vladimir Serbinenko [this message]
2024-09-11 9:41 ` [PATCH 3/8] Support clang integrated-as sparc64 Vladimir Serbinenko
2024-09-11 9:41 ` [PATCH 4/8] powerpc-ieee1275: Fix warnings and alignment Vladimir Serbinenko
2024-09-11 9:41 ` [PATCH 5/8] efi/linux: Silence warning Vladimir Serbinenko
2024-09-11 9:41 ` [PATCH 6/8] btrfs: Add an explicit GRUB_PACKED Vladimir Serbinenko
2024-09-11 9:41 ` [PATCH 7/8] Enable __clzsi2/__clzdi2 on arm Vladimir Serbinenko
2024-09-11 9:41 ` [PATCH 8/8] configure: Try -msoft-float -mfloat-abi=soft " Vladimir Serbinenko
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=20240911094125.1813-2-phcoder@gmail.com \
--to=phcoder@gmail.com \
--cc=grub-devel@gnu.org \
/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.