[project @ 2000-02-03 18:01:03 by sewardj]
authorsewardj <unknown>
Thu, 3 Feb 2000 18:01:03 +0000 (18:01 +0000)
committersewardj <unknown>
Thu, 3 Feb 2000 18:01:03 +0000 (18:01 +0000)
Fix x86 NCG so the compiler can compile itself `-O':

-- Implement fake x86 insn GITOD/GITOF.
-- Implement primops ReadMutVarOp and WriteMutVarOp.
-- Pro tem, disable use of %eax as a spill temp.
-- Clarify wording of Rules of the Game comment in MachCode.

ghc/compiler/nativeGen/AsmCodeGen.lhs
ghc/compiler/nativeGen/MachCode.lhs
ghc/compiler/nativeGen/NOTES
ghc/compiler/nativeGen/PprMach.lhs
ghc/compiler/nativeGen/RegAllocInfo.lhs
ghc/compiler/nativeGen/StixPrim.lhs

index fe2fcbf..e3a16c3 100644 (file)
@@ -89,6 +89,7 @@ nativeCodeGen absC us
          insns          = initUs_ us1 (codeGen stixOpt)
          debug_stix     = vcat (map pprStixTrees stixOpt)
      in 
          insns          = initUs_ us1 (codeGen stixOpt)
          debug_stix     = vcat (map pprStixTrees stixOpt)
      in 
+         trace "--------- native code generator ---------"
          (debug_stix, insns)
 \end{code}
 
          (debug_stix, insns)
 \end{code}
 
index fb88fc6..820b5ae 100644 (file)
@@ -2743,7 +2743,7 @@ The Rules of the Game are:
 * You cannot assume anything about the destination register dst;
   it may be anything, includind a fixed reg.
 
 * You cannot assume anything about the destination register dst;
   it may be anything, includind a fixed reg.
 
-* You may compute a value into a fixed reg, but you may not 
+* You may compute an operand into a fixed reg, but you may not 
   subsequently change the contents of that fixed reg.  If you
   want to do so, first copy the value either to a temporary
   or into dst.  You are free to modify dst even if it happens
   subsequently change the contents of that fixed reg.  If you
   want to do so, first copy the value either to a temporary
   or into dst.  You are free to modify dst even if it happens
@@ -2752,8 +2752,9 @@ The Rules of the Game are:
 * You cannot assume that a fixed reg will stay live over an
   arbitrary computation.  The same applies to the dst reg.
 
 * You cannot assume that a fixed reg will stay live over an
   arbitrary computation.  The same applies to the dst reg.
 
-* Temporary regs obtained from getNewRegNCG are distinct from
-  all other regs, and stay live over arbitrary computations.
+* Temporary regs obtained from getNewRegNCG are distinct from 
+  each other and from all other regs, and stay live over 
+  arbitrary computations.
 
 \begin{code}
 
 
 \begin{code}
 
index 9927b6e..5f76d69 100644 (file)
@@ -26,6 +26,10 @@ All these bugs are for x86; I don't know about sparc/alpha.
    by the OS), and (2) if a signal should be handled on that stack
    during argument construction, the args will get silently trashed.
 
    by the OS), and (2) if a signal should be handled on that stack
    during argument construction, the args will get silently trashed.
 
+   Currently, implementation of GITOF et al use the stack, so are
+   incompatible with current ccall implementation.  When the latter
+   is fixed, GITOF et al should present no problem.
+
 -- nofib/real/hidden gets slightly different FP answers from the
    via-C route; possibly due to exp/log not being done in-line.
 
 -- nofib/real/hidden gets slightly different FP answers from the
    via-C route; possibly due to exp/log not being done in-line.
 
index 23f81a9..a3fe5de 100644 (file)
@@ -1003,9 +1003,11 @@ pprInstr g@(GDTOI src dst)
    = pprG g bogus
 
 pprInstr g@(GITOF src dst) 
    = pprG g bogus
 
 pprInstr g@(GITOF src dst) 
-   = pprG g bogus
+   = pprInstr (GITOD src dst)
 pprInstr g@(GITOD src dst) 
 pprInstr g@(GITOD src dst) 
-   = pprG g bogus
+   = pprG g (hcat [gtab, text "pushl ", pprReg L src, 
+                   text " ; ffree %st(7); fildl (%esp) ; ",
+                   gpop dst 1, text " ; addl $4,%esp"])
 
 pprInstr g@(GCMP sz src1 src2) 
    = pprG g (hcat [gtab, text "pushl %eax ; ",
 
 pprInstr g@(GCMP sz src1 src2) 
    = pprG g (hcat [gtab, text "pushl %eax ; ",
index 53d651e..23aef3b 100644 (file)
@@ -581,8 +581,13 @@ findReservedRegs instrs
     -- dire straits (but still correct): see if we can bag %eax and %edx
     ++ if   any hasFixedEAXorEDX instrs
        then []  -- bummer
     -- dire straits (but still correct): see if we can bag %eax and %edx
     ++ if   any hasFixedEAXorEDX instrs
        then []  -- bummer
-       else [ [ecx,edx,fake4,fake5],
-              [ecx,edx,eax,fake4,fake5] ]
+       else --[ [ecx,edx,fake4,fake5],
+            --  [ecx,edx,eax,fake4,fake5] ]
+            -- pro tem, don't use %eax until we institute a check that
+            -- instrs doesn't do a CALL insn, since that effectively
+            -- uses %eax in a fixed way
+            [ [ecx,edx,fake4,fake5] ]
+
     )
 #endif
 \end{code}
     )
 #endif
 \end{code}
index 2d86439..353bd33 100644 (file)
@@ -256,6 +256,27 @@ primCode [lhs] DataToTagOp [arg]
     returnUs (\xs -> assign : xs)
 \end{code}
 
     returnUs (\xs -> assign : xs)
 \end{code}
 
+MutVars are pretty simple.
+#define writeMutVarzh(a,v)       (P_)(((StgMutVar *)(a))->var)=(v)
+
+\begin{code}
+primCode [] WriteMutVarOp [aa,vv]
+   = let aa_s      = amodeToStix aa
+         vv_s      = amodeToStix vv
+         var_field = StIndex PtrRep aa_s fixedHS
+         assign    = StAssign PtrRep (StInd PtrRep var_field) vv_s
+     in
+     returnUs (\xs -> assign : xs)
+
+primCode [rr] ReadMutVarOp [aa]
+   = let aa_s      = amodeToStix aa
+         rr_s      = amodeToStix rr
+         var_field = StIndex PtrRep aa_s fixedHS
+         assign    = StAssign PtrRep rr_s (StInd PtrRep var_field)
+     in
+     returnUs (\xs -> assign : xs)
+\end{code}
+
 Now the more mundane operations.
 
 \begin{code}
 Now the more mundane operations.
 
 \begin{code}