瀏覽代碼

* fixed some range check errors that occurred on big endian systems
* slightly optimized the swap*() functions

Jonas Maebe 22 年之前
父節點
當前提交
024590b0fa
共有 2 個文件被更改,包括 23 次插入15 次删除
  1. 9 5
      compiler/cutils.pas
  2. 14 10
      compiler/ppu.pas

+ 9 - 5
compiler/cutils.pas

@@ -161,10 +161,10 @@ uses
         y : word;
         z : word;
       Begin
-        y := (x shr 16) and $FFFF;
-        y := ((y shl 8) and $FFFF) or ((y shr 8) and $ff);
+        y := x shr 16;
+        y := word(longint(y) shl 8) or (y shr 8);
         z := x and $FFFF;
-        z := ((z shl 8) and $FFFF) or ((z shr 8) and $ff);
+        z := word(longint(z) shl 8) or (z shr 8);
         SwapLong := (longint(z) shl 16) or longint(y);
       End;
 
@@ -173,7 +173,7 @@ uses
       var
         z : byte;
       Begin
-        z := (x shr 8) and $ff;
+        z := x shr 8;
         x := x and $ff;
         x := (x shl 8);
         SwapWord := x or z;
@@ -866,7 +866,11 @@ initialization
 end.
 {
   $Log$
-  Revision 1.26  2003-04-04 15:34:25  peter
+  Revision 1.27  2003-07-05 20:06:28  jonas
+    * fixed some range check errors that occurred on big endian systems
+    * slightly optimized the swap*() functions
+
+  Revision 1.26  2003/04/04 15:34:25  peter
     * quote names with hi-ascii chars
 
   Revision 1.25  2003/01/09 21:42:27  peter

+ 14 - 10
compiler/ppu.pas

@@ -255,10 +255,10 @@ var
   y : word;
   z : word;
 Begin
-  y := (x shr 16) and $FFFF;
-  y := (y shl 8) or ((y shr 8) and $ff);
+  y := x shr 16;
+  y := word(longint(y) shl 8) or (y shr 8);
   z := x and $FFFF;
-  z := (z shl 8) or ((z shr 8) and $ff);
+  z := word(longint(z) shl 8) or (z shr 8);
   SwapLong := (longint(z) shl 16) or longint(y);
 End;
 
@@ -267,9 +267,9 @@ Function SwapWord(x : word): word;
 var
   z : byte;
 Begin
-  z := (x shr 8) and $ff;
+  z := x shr 8;
   x := x and $ff;
-  x := (x shl 8);
+  x := word(x shl 8);
   SwapWord := x or z;
 End;
 
@@ -403,8 +403,8 @@ begin
   header.target := SwapWord(header.target);
   header.flags := SwapLong(header.flags);
   header.size := SwapLong(header.size);
-  header.checksum := SwapLong(header.checksum);
-  header.interface_checksum := SwapLong(header.interface_checksum);
+  header.checksum := cardinal(SwapLong(longint(header.checksum)));
+  header.interface_checksum := cardinal(SwapLong(longint(header.interface_checksum)));
 {$ENDIF}
   { the PPU DATA is stored in native order }
   if (header.flags and uf_big_endian) = uf_big_endian then
@@ -730,8 +730,8 @@ begin
     header.target := SwapWord(header.target);
     header.flags := SwapLong(header.flags);
     header.size := SwapLong(header.size);
-    header.checksum := SwapLong(header.checksum);
-    header.interface_checksum := SwapLong(header.interface_checksum);
+    header.checksum := cardinal(SwapLong(longint(header.checksum)));
+    header.interface_checksum := cardinal(SwapLong(longint(header.interface_checksum)));
 {$endif not FPC_BIG_ENDIAN}
 { write header and restore filepos after it }
   opos:=filepos(f);
@@ -985,7 +985,11 @@ end;
 end.
 {
   $Log$
-  Revision 1.40  2003-06-17 16:34:44  jonas
+  Revision 1.41  2003-07-05 20:06:28  jonas
+    * fixed some range check errors that occurred on big endian systems
+    * slightly optimized the swap*() functions
+
+  Revision 1.40  2003/06/17 16:34:44  jonas
     * lots of newra fixes (need getfuncretparaloc implementation for i386)!
     * renamed all_intregisters to volatile_intregisters and made it
       processor dependent