Browse Source

* patch by Rika: another improvement of cutils.newalignment, part of #39496

florian 3 năm trước cách đây
mục cha
commit
abc4a0a4e6
1 tập tin đã thay đổi với 7 bổ sung5 xóa
  1. 7 5
      compiler/cutils.pas

+ 7 - 5
compiler/cutils.pas

@@ -295,11 +295,13 @@ implementation
     function newalignment(oldalignment: longint; offset: int64): longint;
       begin
         { oldalignment must be power of two.
-          Works even for negative offsets (but not alignments),
-          as two's complement of, say, 2^4+2^3 is 11000 and -2^4-2^3 is 11...1101000 -
-          both end with exactly N zeros, where N is the largest power of two that divides the number
-          (smallest power of two involved in these sums). }
-        result:=1 shl BsfQWord(qword(offset or oldalignment));
+
+          Negating two's complement number keeps its tail '100...000' and complements all bits above.
+          "x and -x" extracts this tail of 'x'.
+          Said tail of "oldalignment or offset" is the desired answer. }
+
+        result:=oldalignment or longint(offset); { high part of offset won't matter as long as alignment is 32-bit }
+        result:=result and -result;
       end;