13.07.2015 Views

The PowerPC 604 RISC Microprocessor - eisber.net

The PowerPC 604 RISC Microprocessor - eisber.net

The PowerPC 604 RISC Microprocessor - eisber.net

SHOW MORE
SHOW LESS

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

3.3 Binary Prolog<strong>The</strong> key idea of binary Prolog is the transformation ofclauses to binary clauses using a continuation passingstyle. BinProlog, an efficient emulator for binary Prologhas been developed by Paul Tarau [Tar91][Tar92].<strong>The</strong> implementation is based on the WAM which canbe greatly simplified in that case.In binary Prolog a clause has at most one subgoal.A clause can be transformed to a binary clause byrepresenting the call of subgoals explicitely using continuations[App92]. For that purpose the first subgoalis given an additional argument containing the successcontinuation. <strong>The</strong> success continuation is the listof subgoals to be executed if the first subgoal is executedsuccessfully. <strong>The</strong> head is given an additionalargument which passes on the continuation. A factis transformed to a clause, whose subgoal executes ameta-call of the continuation. For example, the followingclausesnrev( , []).nrev([111T] ,R) :-nrev(T,L) , append (L, [H] ,R) .are transformed intonrev( , D ,cont) (Cont).nrev( [HIT] ,R,Cont) : -nr ev (T , L , append (L , [H] , R , Cont ) )Compiling binary Prolog to the WAM it appearsthat the environment stack is superfluous since all variablesare temporary. <strong>The</strong>refore, all instruction dealingwith local variables or managing the stack can beeliminated. So a small and efficient interpreter can beimplemented. But this simplification has a big problem.<strong>The</strong> continuation, which contains also the variablespreviously contained in the stack frame, is storedon the copy stack. This means that there is no lastcalloptimization. So for a working BinWAM an efficientgarbage collector is crucial. In some sense theBinWAM can be seen as mixture of a clause stackingmodel with the WAM.4 <strong>The</strong> Vienna Abstract Machine4.1 Introduction<strong>The</strong> VAM has been developed at the TU Wien as analternative to the WAM. <strong>The</strong> WAM divides the unificationprocess into two steps. During the first step thearguments of the calling goal are copied into argumentregisters and during the second step the values in theargument registers are unified with the arguments ofthe head of the called predicate. <strong>The</strong> VAM eliminatesthe register interface by unifying goal and head argumentsin one step. <strong>The</strong> VAM can be seen as a partialevaluation of the call. <strong>The</strong>re are two variants of theVAM, the VAM 1 p and the VAM2P-A complete description of the VAM 2p can be foundin [KN90]. Here we give a short introduction to theVAM 2p which helps to understand the VAM ip andthe compilation method. <strong>The</strong> VAIN/1 2p (VAM with twoinstruction pointers) is well suited for an intermediatecode interpreter implemented in C or in assemblylanguage using direct threaded code [Be1731. <strong>The</strong> goalinstruction pointer points to the instructions of thecalling goal, the head instruction pointer points to theinstructions of the head of the called clause. During aninference the VAM2p fetches one instruction from thegoal, one instruction from the head, combines themand executes the combined instruction. Because informationabout the calling goal and the called head isavailable at the same time, more optimizations thanin the WAM are possible. <strong>The</strong> VAM features cheapbacktracking, needs less dereferencing and trailing, hassmaller stack sizes and implements a faster cut.<strong>The</strong> VAM i p (VAM with one instruction pointer)uses one instruction pointer and is well suited for nativecode compilation. It combines instructions atcompile time and supports additional optimizationslike instruction elimination, resolving temporary variablesduring compile time, extended clause indexing,fast last-call optimization, and loop optimization.4.2 <strong>The</strong> VAM2PLike the WAM, the VAM 2p uses three stacks. Stackframes and choice points are allocated on the environmentstack, structures and unbound variables arestored on the copy stack, and bindings of variablesare marked on the trail. <strong>The</strong> intermediate code of theclauses is held in the code area. <strong>The</strong> machine registersare the goalptr and headptr (pointer to the code of thecalling goal and of the called clause respectively), thegoalframeptr and the headframeptr (frame pointer ofthe clause containing the calling goal and of the calledclause respectively), the top of the environment stack,the top of the copy stack, the top of the trail, and thepointer to the last choice point.Values are stored together with a tag in one machineword. We distinguish integers, atoms, nil, lists, structures,unbound variables and references. Unboundvariables are allocated on the copy stack to avoid danglingreferences and the unsafe variables of the WAM.Furthermore it simplifies the check for the trailing ofbindings. Structure copying is used for the representationof structures.8

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!