1. 03 Dec, 2021 5 commits
  2. 02 Dec, 2021 14 commits
    • Ben Gamari's avatar
      hadrian: Don't rely on realpath in bindist Makefile · fab2579e
      Ben Gamari authored and Marge Bot's avatar Marge Bot committed
      As noted in #19963, `realpath` is not specified by POSIX and therefore
      cannot be assumed to be available. Here we provide a POSIX shell
      implementation of `realpath`, due to Julian Ospald and others.
      
      Closes #19963.
      fab2579e
    • Ben Gamari's avatar
      testsuite: Specify expected word-size of machop tests · 44c08863
      Ben Gamari authored and Marge Bot's avatar Marge Bot committed
      These generally expect a particular word size.
      44c08863
    • Ben Gamari's avatar
      CmmToC: Cast possibly-signed results as unsigned · e98dad1b
      Ben Gamari authored and Marge Bot's avatar Marge Bot committed
      C11 rule 6.3.1.1 dictates that all small integers used in expressions be
      implicitly converted to `signed int`.  However, Cmm semantics require that the
      width of the operands be preserved with zero-extension semantics. For
      this reason we must recast sub-word arithmetic results as unsigned.
      e98dad1b
    • Ben Gamari's avatar
      CmmToC: Always cast arguments as unsigned · 0aeaa8f3
      Ben Gamari authored and Marge Bot's avatar Marge Bot committed
      As noted in Note [When in doubt, cast arguments as unsigned], we
      must ensure that arguments have the correct signedness since some
      operations (e.g. `%`) have different semantics depending upon
      signedness.
      0aeaa8f3
    • Ben Gamari's avatar
      CmmToC: Zero-extend sub-word size results · ebaf7333
      Ben Gamari authored and Marge Bot's avatar Marge Bot committed
      As noted in Note [Zero-extending sub-word signed results] we must
      explicitly zero-extend the results of sub-word-sized signed operations.
      ebaf7333
    • Ben Gamari's avatar
      CmmToC: Fix width of shift operations · e19e9e71
      Ben Gamari authored and Marge Bot's avatar Marge Bot committed
      Under C's implicit widening rules, the result of an operation like (a >>
      b) where a::Word8 and b::Word will have type Word, yet we want Word.
      e19e9e71
    • Ben Gamari's avatar
      nativeGen/aarch64: Fix handling of subword values · adc7f108
      Ben Gamari authored and Marge Bot's avatar Marge Bot committed
      Here we rework the handling of sub-word operations in the AArch64
      backend, fixing a number of bugs and inconsistencies. In short,
      we now impose the invariant that all subword values are represented in
      registers in zero-extended form. Signed arithmetic operations are then
      responsible for sign-extending as necessary.
      
      Possible future work:
      
       * Use `CMP`s extended register form to avoid burning an instruction
         in sign-extending the second operand.
      
       * Track sign-extension state of registers to elide redundant sign
         extensions in blocks with frequent sub-word signed arithmetic.
      adc7f108
    • Ben Gamari's avatar
      cmm/opt: Fold away shifts larger than shiftee width · 9c65197e
      Ben Gamari authored and Marge Bot's avatar Marge Bot committed
      This is necessary for lint-correctness since we no longer allow such
      shifts in Cmm.
      9c65197e
    • Ben Gamari's avatar
      nativeGen/aarch64: Don't rely on register width to determine amode · 7094f4fa
      Ben Gamari authored and Marge Bot's avatar Marge Bot committed
      We might be loading, e.g., a 16- or 8-bit value, in which case the
      register width is not reflective of the loaded element size.
      7094f4fa
    • Ben Gamari's avatar
      testsuite: Add testcases for various machop issues · 2f6565cf
      Ben Gamari authored and Marge Bot's avatar Marge Bot committed
      There were found by the test-primops testsuite.
      2f6565cf
    • Ben Gamari's avatar
      cmm: Disallow shifts larger than shiftee · 35bbc251
      Ben Gamari authored and Marge Bot's avatar Marge Bot committed
      Previously primops.txt.pp stipulated that the word-size shift primops
      were only defined for shift offsets in [0, word_size). However, there
      was no further guidance for the definition of Cmm's sub-word size shift
      MachOps.
      
      Here we fix this by explicitly disallowing (checked in many cases by
      CmmLint) shift operations where the shift offset is larger than the
      shiftee. This is consistent with LLVM's shift operations, avoiding the
      miscompilation noted in #20637.
      35bbc251
    • Ben Gamari's avatar
      ncg/aarch64: Don't sign extend loads · 78b78ac4
      Ben Gamari authored and Marge Bot's avatar Marge Bot committed
      Previously we would emit the sign-extending LDS[HB] instructions for
      sub-word loads. However, this is wrong, as noted in #20638.
      78b78ac4
    • Ben Gamari's avatar
      cmm: narrow when folding signed quotients · 5b950a7f
      Ben Gamari authored and Marge Bot's avatar Marge Bot committed
      Previously the constant-folding behavior for MO_S_Quot and MO_S_Rem
      failed to narrow its arguments, meaning that a program like:
      
          %zx64(%quot(%lobits8(0x00e1::bits16), 3::bits8))
      
      would be miscompiled. Specifically, this program should reduce as
      
                      %lobits8(0x00e1::bits16)                 == -31
                %quot(%lobits8(0x00e1::bits16), 3::bits8)      == -10
          %zx64(%quot(%lobits8(0x00e1::bits16), 3::bits8))     == 246
      
      However, with this bug the `%lobits8(0x00e1::bits16)` would instead
      be treated as `+31`, resulting in the incorrect result of `75`.
      
      (cherry picked from commit 94e197e3)
      5b950a7f
    • Ben Gamari's avatar
      nativeGen/x86: Don't encode large shift offsets · 1724ac37
      Ben Gamari authored and Marge Bot's avatar Marge Bot committed
      Handle the case of a shift larger than the width of the shifted value.
      This is necessary since x86 applies a mask of 0x1f to the shift amount,
      meaning that, e.g., `shr 47, $eax` will actually shift by
      47 & 0x1f == 15.
      
      See #20626.
      
      (cherry picked from commit 31370f1a)
      1724ac37
  3. 01 Dec, 2021 20 commits
  4. 30 Nov, 2021 1 commit