Browse Source

+ support for evaluating qword constant expressions (both arguments have
to be a qword, constants have to be explicitly typecasted to qword)

Jonas Maebe 21 years ago
parent
commit
e9eff10134
2 changed files with 30 additions and 9 deletions
  1. 12 3
      compiler/nadd.pas
  2. 18 6
      compiler/nmat.pas

+ 12 - 3
compiler/nadd.pas

@@ -329,7 +329,11 @@ implementation
                   else
                     t := cpointerconstnode.create(lv-rv,left.resulttype);
                 muln :
-                  t:=genintconstnode(lv*rv);
+                  if (torddef(ld).typ <> u64bit) or
+                     (torddef(rd).typ <> u64bit) then
+                    t:=genintconstnode(lv*rv)
+                  else
+                    t:=genintconstnode(int64(qword(lv)*qword(rv)));
                 xorn :
                   t:=cordconstnode.create(lv xor rv,left.resulttype,true);
                 orn :
@@ -1426,7 +1430,8 @@ implementation
           end;
 
         { can we use a shift instead of a mul? }
-        if (right.nodetype = ordconstn) and
+        if not (cs_check_overflow in aktlocalswitches) and
+           (right.nodetype = ordconstn) and
            ispowerof2(tordconstnode(right).value,power) then
           begin
             tordconstnode(right).value := power;
@@ -1869,7 +1874,11 @@ begin
 end.
 {
   $Log$
-  Revision 1.99  2003-10-28 15:35:18  peter
+  Revision 1.100  2003-12-09 21:17:04  jonas
+    + support for evaluating qword constant expressions (both arguments have
+      to be a qword, constants have to be explicitly typecasted to qword)
+
+  Revision 1.99  2003/10/28 15:35:18  peter
     * compare longint-cardinal also makes types wider
 
   Revision 1.98  2003/10/21 18:16:13  peter

+ 18 - 6
compiler/nmat.pas

@@ -115,6 +115,9 @@ implementation
          if codegenerror then
            exit;
 
+         rd:=torddef(right.resulttype.def);
+         ld:=torddef(left.resulttype.def);
+
          { check for division by zero }
          if is_constintnode(right) then
            begin
@@ -131,9 +134,17 @@ implementation
 
                  case nodetype of
                    modn:
-                     t:=genintconstnode(lv mod rv);
+                     if (torddef(ld).typ <> u64bit) or
+                        (torddef(rd).typ <> u64bit) then
+                       t:=genintconstnode(lv mod rv)
+                     else
+                       t:=genintconstnode(int64(qword(lv) mod qword(rv)));
                    divn:
-                     t:=genintconstnode(lv div rv);
+                     if (torddef(ld).typ <> u64bit) or
+                        (torddef(rd).typ <> u64bit) then
+                       t:=genintconstnode(lv div rv)
+                     else
+                       t:=genintconstnode(int64(qword(lv) div qword(rv)));
                  end;
                  result:=t;
                  exit;
@@ -148,9 +159,6 @@ implementation
               exit;
            end;
 
-         rd:=torddef(right.resulttype.def);
-         ld:=torddef(left.resulttype.def);
-
          { if one operand is a cardinal and the other is a positive constant, convert the }
          { constant to a cardinal as well so we don't have to do a 64bit division (JM)    }
          { Do the same for qwords and positive constants as well, otherwise things like   }
@@ -831,7 +839,11 @@ begin
 end.
 {
   $Log$
-  Revision 1.53  2003-10-08 19:19:45  peter
+  Revision 1.54  2003-12-09 21:17:04  jonas
+    + support for evaluating qword constant expressions (both arguments have
+      to be a qword, constants have to be explicitly typecasted to qword)
+
+  Revision 1.53  2003/10/08 19:19:45  peter
     * set_varstate cleanup
 
   Revision 1.52  2003/10/01 20:34:49  peter