[Git][ghc/ghc][wip/supersven/riscv64-ncg] 3 commits: Add comment

Sven Tennie (@supersven) gitlab at gitlab.haskell.org
Sun Mar 3 01:22:21 UTC 2024



Sven Tennie pushed to branch wip/supersven/riscv64-ncg at Glasgow Haskell Compiler / GHC


Commits:
bd2e505d by Sven Tennie at 2024-03-03T02:05:50+01:00
Add comment

- - - - -
4df27780 by Sven Tennie at 2024-03-03T02:07:01+01:00
Only trace message on flag

- - - - -
05121e86 by Sven Tennie at 2024-03-03T02:20:01+01:00
Check int size on 32 bit width

We're handing around 32bit integers.

- - - - -


2 changed files:

- rts/RtsSymbols.c
- rts/linker/elf_reloc_riscv64.c


Changes:

=====================================
rts/RtsSymbols.c
=====================================
@@ -972,8 +972,9 @@ extern char **environ;
 #endif
 
 #if defined(riscv64_HOST_ARCH)
-// See https://gcc.gnu.org/onlinedocs/gccint/Integer-library-routines.html
-// as reference for the following built-ins.
+// See https://gcc.gnu.org/onlinedocs/gccint/Integer-library-routines.html as
+// reference for the following built-ins. __clzdi2 and __ctzdi2 probably relate
+// to __builtin-s in libraries/ghc-prim/cbits/ctz.c.
 #define RTS_ARCH_LIBGCC_SYMBOLS \
   SymI_NeedsProto(__clzdi2) \
   SymI_NeedsProto(__ctzdi2)


=====================================
rts/linker/elf_reloc_riscv64.c
=====================================
@@ -90,22 +90,24 @@ int32_t decodeAddendRISCV64(Section *section STG_UNUSED,
   abort(/* we don't support Rel locations yet. */);
 }
 
-// Sign-extend the number in the bottom B bits of X to a 64-bit integer.
-// Requires 0 < B <= 64.
-int64_t SignExtend64(uint64_t X, unsigned B) {
+// Sign-extend the number in the bottom B bits of X to a 32-bit integer.
+// Requires 0 < B <= 32. (32 bit is sufficient as we can only encode 20 + 12 =
+// 32 bit in a relocation pair.)
+int32_t SignExtend32(uint32_t X, unsigned B) {
   assert(B > 0 && "Bit width can't be 0.");
-  assert(B <= 64 && "Bit width out of range.");
-  return (int64_t)(X << (64 - B)) >> (64 - B);
+  assert(B <= 32 && "Bit width out of range.");
+  return (int32_t)(X << (32 - B)) >> (32 - B);
 }
 
 // Make sure that V can be represented as an N bit signed integer.
-void checkInt(inst_t *loc, int64_t v, int n) {
-  if (v != SignExtend64(v, n)) {
-    debugBelch("Relocation at 0x%x is out of range. value: 0x%lx (%ld), "
-               "sign-extended value: 0x%lx (%ld), max bits 0x%x (%d)\n",
-               *loc, v, v, SignExtend64(v, n), SignExtend64(v, n), n, n);
+void checkInt(inst_t *loc, int32_t v, int n) {
+  if (v != SignExtend32(v, n)) {
+    debugBelch("Relocation at 0x%x is out of range. value: 0x%x (%d), "
+               "sign-extended value: 0x%x (%d), max bits 0x%x (%d)\n",
+               *loc, v, v, SignExtend32(v, n), SignExtend32(v, n), n, n);
   }
 }
+
 // RISCV is little-endian by definition.
 void write8le(uint8_t *p, uint8_t v) { *p = v; }
 
@@ -149,8 +151,8 @@ uint32_t setLO12_S(uint32_t insn, uint32_t imm) {
 void setUType(inst_t *loc, int32_t val) {
   const unsigned bits = 32;
   uint32_t hi = val + 0x800;
-  checkInt(loc, SignExtend64(hi, bits) >> 12, 20);
-  debugBelch("setUType: hi 0x%x val 0x%x\n", hi, val);
+  checkInt(loc, SignExtend32(hi, bits) >> 12, 20);
+  IF_DEBUG(linker, debugBelch("setUType: hi 0x%x val 0x%x\n", hi, val));
   write32le(loc, (read32le(loc) & 0xFFF) | (hi & 0xFFFFF000));
 }
 



View it on GitLab: https://gitlab.haskell.org/ghc/ghc/-/compare/a4742d26bceb2f76e01b94238c2b5c0dc4695656...05121e86e727168ef4ed5d9188e482e271d1d5d9

-- 
View it on GitLab: https://gitlab.haskell.org/ghc/ghc/-/compare/a4742d26bceb2f76e01b94238c2b5c0dc4695656...05121e86e727168ef4ed5d9188e482e271d1d5d9
You're receiving this email because of your account on gitlab.haskell.org.


-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.haskell.org/pipermail/ghc-commits/attachments/20240302/f0c14b4b/attachment-0001.html>


More information about the ghc-commits mailing list