Indirect jumps improve instruction sequence performance
aa r X i v : . [ c s . P L ] A ug Indirect Jumps ImproveInstruction Sequence Performance
J.A. Bergstra and C.A. Middelburg
Informatics Institute, Faculty of Science, University of Amsterdam,Science Park 904, 1098 XH Amsterdam, the Netherlands
[email protected],[email protected]
Abstract.
Instruction sequences with direct and indirect jump instruc-tions are as expressive as instruction sequences with direct jump instruc-tions only. We show that, in the case where the number of instructions isnot bounded, we are faced with increases of the maximal internal delaysof instruction sequences on execution that are not bounded by a linearfunction if we strive for acceptable increases of the lengths of instructionsequences on elimination of indirect jump instructions.
Keywords: instruction sequence performance, indirect jump instruction,maximal internal delay.
D.3.3, F.1.1, F.3.3.
Although instruction sequences with direct and indirect jump instructions are asexpressive as instruction sequences with direct jump instructions only (see [2]),indirect jump instructions are widely used to implement certain features of con-temporary high-level programming languages such as the switch statements andvirtual method calls of Java [7] and C The work presented in this paper belongs to a line of research whose workinghypothesis is that instruction sequence is a central notion of computer science.In this line of research, program algebra [1] is the setting used for investigating A super-linear increase means an increase that is not bounded by a linear function. nstruction sequences. The starting-point of program algebra is the perception ofa program as a single-pass instruction sequence, i.e. a finite or infinite sequenceof instructions of which each instruction is executed at most once and can bedropped after it has been executed or jumped over. This perception is simple,appealing, and links up with practice.The program notation used in this paper to show that indirect jumps im-prove instruction sequence performance is PGLB ij . This program notation is aminor variant of PGLC ij , a program notation with indirect jumps instructionsintroduced in [2]. Both program notations are rooted in program algebra, arecloser to existing assembly languages than the notation provided by programalgebra, and have relative jump instructions. The main difference between themis that PGLB ij has an explicit termination instruction and PGLC ij has not. Thisdifference makes the former program notation more convenient for the purposeof this paper.The performance measure used in this paper is the maximal internal delayof an instruction sequence on execution. The maximal internal delay of an in-struction sequence on execution is the largest possible delay that can take placebetween successively executed instructions whose effects are observable exter-nally. Another conceivable performance measure is the largest possible sum ofsuch delays on execution of the instruction sequence. In this paper, we do notconsider the latter performance measure because it looks to be less adequate tothe interactive performance of instruction sequences. The work presented in this paper can be looked at in a wider context. Inthe literature on computer architecture, hardly anything can be found that con-tributes to a sound understanding of the effects of the presence of common kindsof instructions in the instruction set of a computer on important points such asinstruction sequence size and instruction sequence performance. The work pre-sented in this paper can be considered a first step towards such an understanding.This paper is organized as follows. First, we give a survey of the programnotation PGLB ij (Sect. 2). Next, we introduce the notion of maximal internaldelay of a PGLB ij program (Sect. 3). After that, we present the above-mentionedresult concerning the elimination of indirect jump instructions (Sect. 4). We alsorelate the work presented in this paper to the point of view which is the originof the line of research to which it belongs (Sect. 5). Finally, we make someconcluding remarks (Sect. 6). In this section, we give a survey of the program notation PGLB ij . This programnotation is a variant of the program notation PGLB, which belongs to a hierarchyof program notations rooted in program algebra (see [1]). PGLB and PGLB ij are closer to existing assembly languages than the notation provided by programalgebra. Interactive performance means performance with respect to the interaction with theenvironment on execution.
2t is assumed that fixed but arbitrary numbers I and N have been given,which are considered the number of registers available and the greatest naturalnumber that can be contained in a register. Moreover, it is also assumed thatfixed but arbitrary finite sets F of foci and M of methods have been given.The set A of basic instructions is { f.m | f ∈ F , m ∈ M} . The view is thatthe execution environment of a PGLB ij program provides a number of services,that each focus plays the role of a name of a service, that each method playsthe role of a command that a service can be requested to process, and that theexecution of a basic instruction f.m amounts to making a request to the servicenamed f to process command m . The intuition is that the processing of thecommand m may modify the state of the service named f and that the servicein question will produce T or F at its completion.For example, a service may be able to process methods for setting the contentof a Boolean cell to T or F and a method for getting the content of the Booleancell. Processing of a setting method may modify the state of the service, becauseit may change the content of the Boolean cell with which the service deals, andsimply produces the final content at its completion. Processing of the gettingmethod does not modify the state of the service, because it does not changesthe content of the Boolean cell with which the service deals, and produces thecontent of the Boolean cell at its completion.PGLB ij has the following primitive instructions: – for each a ∈ A , a plain basic instruction a ; – for each a ∈ A , a positive test instruction + a ; – for each a ∈ A , a negative test instruction − a ; – for each l ∈ N , a direct forward jump instruction l ; – for each l ∈ N , a direct backward jump instruction \ l ; – for each i ∈ [1 , I ] and n ∈ [1 , N ], a register set instruction set : i : n ; – for each i ∈ [1 , I ], an indirect forward jump instruction i i ; – for each i ∈ [1 , I ], an indirect backward jump instruction i \ i ; – a termination instruction !.PGLB ij programs are expressions of the form u ; . . . ; u k , where u , . . . , u k areprimitive instructions of PGLB ij . PGLB programs are PGLB ij programs in whichregister set instructions, indirect forward jump instructions and indirect back-ward jump instructions do not occur.On execution of a PGLB ij program, the primitive instructions of PGLB ij have the following effects: – the effect of a positive test instruction + a is that basic instruction a isexecuted and execution proceeds with the next primitive instruction if T is produced and otherwise the next primitive instruction is skipped andexecution proceeds with the primitive instruction following the skipped one– if there is no primitive instruction to proceed with, inaction occurs; – the effect of a negative test instruction − a is the same as the effect of + a ,but with the role of the value produced reversed;3 the effect of a plain basic instruction a is the same as the effect of + a ,but execution always proceeds as if T is produced; – the effect of a direct forward jump instruction l is that execution pro-ceeds with the l -th next instruction of the program concerned – if l equals0 or there is no primitive instruction to proceed with, inaction occurs; – the effect of a direct backward jump instruction \ l is that execution pro-ceeds with the l -th previous instruction of the program concerned – if l equals0 or there is no primitive instruction to proceed with, inaction occurs; – the effect of a register set instruction set : i : n is that the content of register i is set to n and execution proceeds with the next primitive instruction – ifthere is no primitive instruction to proceed with, inaction occurs; – the effect of an indirect forward jump instruction i i is the same as theeffect of l , where l is the content of register i ; – the effect of an indirect backward jump instruction i \ i is the same as theeffect of \ l , where l is the content of register i ; – the effect of the termination instruction ! is that execution terminates.If execution proceeds unbroken and forever with no other primitive instructionsthan jump instructions and register set instructions, this is identified with inac-tion.PGLB ij is a minor variant of PGLC ij , a program notation with indirect jumpsinstructions introduced in [2]. The differences between PGLB ij and PGLC ij arethe following: – in those cases where inaction occurs on execution of PGLB ij programs be-cause there is no primitive instructions to proceed with, termination takesplace on execution of PGLC ij programs; – the termination instruction ! is not available in PGLC ij .The meaning of PGLC ij programs is formally described in [2] by means of amapping of PGLC ij programs to closed terms of program algebra. In that way,the behaviour of PGLC ij programs on execution is described indirectly: the be-haviour of the programs denoted by closed terms of program algebra on exe-cution is formally described in several papers, including [2], using basic threadalgebra [1]. Because PGLB ij is a minor variant of PGLC ij , we refrain from de-scribing the behaviour of PGLB ij programs on execution formally in the currentpaper. ij Programs
In this section, we will define the notion of maximal internal delay of a PGLB ij program.It is assumed that a fixed but arbitrary set X ⊂ A of auxiliary basic in-structions has been given. The view is that, in common with the effect of jump In several early papers, basic thread algebra is presented under the name basicpolarized process algebra. ij program concerns the delays thattakes place between successive non-auxiliary basic instructions on executionof the instruction sequence. Before we define the maximal internal delay of aPGLB ij program, we define the execution traces of a PGLB ij program.Let u ; . . . ; u k be a PGLB ij program. Then tr ( ρ, j, u ; . . . ; u k ), where ρ :[1 , I ] → [1 , N ] and j ∈ N , is the set of all finite sequences over the set of all primitiveinstructions of PGLB ij that may be encountered successively on execution of u ; . . . ; u k if execution starts with u j with the registers used for indirect jumpsset according to ρ .Formally, for each PGLB ij program u ; . . . ; u k , the different sets tr ( ρ, j, u ; . . . ; u k ) are defined by simultaneous induction on the structure of the finitesequences over the set of all primitive instructions of PGLB ij by the followingclauses:1. h i ∈ tr ( ρ, j, u ; . . . ; u k );2. if u j ≡ a or u j ≡ + a or u j ≡ − a , and σ ∈ tr ( ρ, j + 1 , u ; . . . ; u k ), then u j σ ∈ tr ( ρ, j, u ; . . . ; u k );3. if u j ≡ + a or u j ≡ − a , and σ ∈ tr ( ρ, j + 2 , u ; . . . ; u k ), then u j σ ∈ tr ( ρ, j, u ; . . . ; u k );4. if u j ≡ l and σ ∈ tr ( ρ, j + l, u ; . . . ; u k ), then u j σ ∈ tr ( ρ, j, u ; . . . ; u k );5. if u j ≡ \ l and σ ∈ tr ( ρ, j . − l, u ; . . . ; u k ), then u j σ ∈ tr ( ρ, j, u ; . . . ; u k );
6. if u j ≡ set : i : n and σ ∈ tr ( ρ ′ , j + 1 , u ; . . . ; u k ), then u j σ ∈ tr ( ρ, j, u ; . . . ; u k ),where ρ ′ is defined by ρ ′ ( i ′ ) = ρ ( i ′ ) if i ′ = i and ρ ′ ( i ) = n ;7. if u j ≡ i i and σ ∈ tr ( ρ, j + ρ ( i ) , u ; . . . ; u k ), then u j σ ∈ tr ( ρ, j, u ; . . . ; u k );8. if u j ≡ i \ i and σ ∈ tr ( ρ, j . − ρ ( i ) , u ; . . . ; u k ), then u j σ ∈ tr ( ρ, j, u ; . . . ; u k );9. if u j ≡ !, then u j ∈ tr ( ρ, j, u ; . . . ; u k ).For example, tr ( ρ , , + a ; set :1:3 ; set :1:1 ; i b ; c ; !) , where ρ is defined by ρ ( i ) = 0 for all i ∈ [1 , I ], contains+ a set :1:1 i b , + a set :1:3 i c ! , and all prefixes of these two sequences, including the empty sequence. As usual, we write i . − j for the monus of i and j , i.e. i . − j = i − j if i ≥ j and i . − j = 0 otherwise. execution traces of a PGLB ij program P , written tr ( P ), is tr ( ρ , , P ), where ρ is defined by ρ ( i ) = 0 for all i ∈ [1 , I ].The maximal internal delay of an PGLB ij program P , written MID ( P ), isthe largest n ∈ N for which there exists an execution trace u . . . u k ∈ tr ( P )and i , i ∈ [1 , k ] with i ≤ i such that ID ( u j ) = 0 for all j ∈ [ i , i ] and P j ∈ [ i ,i ] ID ( u j ) = n , where ID ( u ) is defined as follows: ID ( a ) = 0 if a / ∈ X , ID ( a ) = 1 if a ∈ X , ID (+ a ) = 0 if a / ∈ X , ID (+ a ) = 1 if a ∈ X , ID ( − a ) = 0 if a / ∈ X , ID ( − a ) = 1 if a ∈ X , ID ( l ) = 1 , ID ( \ l ) = 1 , ID ( set : i : n ) = 1 , ID ( i i ) = 2 , ID ( i \ i ) = 2 , ID (!) = 0 . Suppose that in the example given above a , b and c are non-auxiliary basicinstructions. Then MID (+ a ; set :1:3 ; set :1:1 ; i b ; c ; !) = 4 . This delay takes place between the execution of a and the execution of b or c .In [6], an extension of basic thread algebra is proposed which allows for inter-nal delays to be described and analysed. We could give a formal description ofthe behaviour of PGLB ij programs on execution, internal delays included, usingthis extension of basic thread algebra. Founded on such a formal description, wecould explain why the notion of maximal internal delay of a PGLB ij programdefined above is the right one. MID ( P ) can be looked upon as the number of time units that elapses duringthe largest possible internal delay of P . Because the time that it takes to executeone basic instruction is taken for the time unit in the definition of MID ( P ), itcan alternatively be looked upon as the number of basic instructions that canbe executed during the largest possible internal delay of P . As usual, the timethat it takes to execute one basic instruction is called a step . In this section, we show that indirect jump instructions are needed for goodinstruction sequence performance.It is assumed that bool :1 , bool :2 , . . . ∈ F and set : T , set : F , get ∈ M . Thefoci bool :1, bool :2, . . . serve as names of services that act as Boolean cells. Themethods set : T , set : F , and get are accepted by services that act as Boolean cellsand their processing by such a service goes as follows: – set : T : the contents of the Boolean cell is set to T , and T is produced; – set : F : the contents of the Boolean cell is set to F , and F is produced; – get : nothing is changed, but the contents of the Boolean cell is produced.6n execution of a PGLB ij program that interacts with a Boolean cell, the contentof the Boolean cell may change at any time by external causes, i.e. by causesthat do not originate from the executed program. The use operators introducedin [5] permit encapsulation of services, as a result of which changes by externalcauses are excluded. On purpose, we do not apply these use operators here: theBoolean cell with which we are concerned serves as a means for a program tointeract with the environment on execution.Below, we will write ; ni =1 P ′ i , where P ′ , . . . , P ′ n are PGLB ij programs, for thePGLB ij program P ′ ; . . . ; P ′ n .For each k ∈ N , let P k be the following PGLB ij program: ; k i =1 ( − bool :1 . get ; set :1:2 · i +1 ; k − i ) · ; k i =1 ( − bool :1 . get ; set :2:2 · i +1 ; k − i ) · i ; k i =1 ( a i ; k − i ) · i ; k i =1 ( a ′ i ; !) , where a , . . . , a k and a ′ , . . . , a ′ k are mutually different basic instructions.First, P k repeatedly tests the Boolean cell bool :1. If T is not returned for 2 k tests, P k terminates. Otherwise, in case it takes i tests until T is returned, thecontent of register 1 is set to 2 · i + 1. If P k has not yet terminated, it once againrepeatedly tests the Boolean cell bool :1. If T is not returned for 2 k tests, P k terminates. Otherwise, in case it takes j tests until T is returned, the content ofregister 2 is set to 2 · j + 1. If P k has not yet terminated, it performs a i after anindirect jump and following this a ′ j after another indirect jump. After that, P k terminates. The length of P k is 12 · k + 4 primitive instructions and the maximalinternal delay of P k is 4 steps.The PGLB ij programs P , P , . . . defined above will be used in the proof ofthe result concerning the elimination of indirect jump instructions stated below.In the proof concerned, we will further make use of the notion of a reachableoccurrence of a basic instruction in a PGLB ij program. We assume that thisnotion is intuitively sufficiently clear to grasp the proof. Given a formal descrip-tion of the behaviour of PGLB ij programs in the style used for PGLC ij programsin [2], reachability can easily be defined in the way followed in Section 3.3 of [9].Below, we will write ℓ ( P ), where P is a PGLB ij program, for the length of P , i.e. its number of primitive instructions.A mapping ϕ from the set of all PGLB ij programs to the set of all PGLBprograms has a linear upper bound on the increase in maximal internal delay iffor some c ′ , c ′′ ∈ N , for all PGLB ij programs P , MID ( ϕ ( P )) ≤ c ′ · MID ( P ) + c ′′ .A mapping ϕ from a subset P of the set of all PGLB ij programs to the set ofall PGLB programs has a quadratic lower bound on the increase in length iffor some c ′ , c ′′ ∈ N with c ′ = 0, for all P ∈ P , ℓ ( ϕ ( P )) ≥ c ′ · ℓ ( P ) + c ′′ .It follows easily from the behaviour-preserving mapping from the set of allPGLC ij programs to the set of all PGLC programs given in [2] and an idea usedin Section 5.1 of [5] that there exists a behaviour-preserving mapping from the7et of all PGLB ij programs to the set of all PGLB programs with a linear upperbound on the increase in maximal internal delay. Theorem 1.
Suppose ϕ is a behaviour-preserving mapping from the set of all PGLB ij programs to the set of all PGLB programs with a linear upper bound onthe increase in maximal internal delay. Moreover, suppose that the number ofbasic instructions is not bounded. Then there exists a set P of PGLB ij programssuch that the restriction of ϕ to P has a quadratic lower bound on its increasein length.Proof. For each k ∈ N , let P k be defined as above. We show that the restrictionof ϕ to { P , P , . . . } has a quadratic lower bound on its increase in length. Takean arbitrary k ∈ N . Because ϕ has a linear upper bound on the increase in max-imal internal delay, we have MID ( ϕ ( P k )) ≤ c ′ · MID ( P k ) + c ′′ = c ′ · c ′′ forsome c ′ , c ′′ ∈ N . Let c = c ′ · c ′′ . Suppose that k is much greater than c . Thissupposition requires that the number of basic instructions is not bounded. Be-cause ϕ is a behaviour-preserving mapping and there is a possibility that ϕ ( P k )contains auxiliary basic instructions, there are at most 2 c different occurrencesof basic instructions in ϕ ( P k ) reachable in c steps from any occurrence of a basicinstruction in ϕ ( P k ). Let i ∈ [1 , k ]. Then, because ϕ is a behaviour-preservingmapping, for each j ∈ [1 , k ], some occurrence of a ′ j in ϕ ( P k ) is reachable in c steps from each occurrence of a i in ϕ ( P k ). Thus, there are at least 2 k differentoccurrences of basic instructions to reach in c steps from one occurrence of a i ,although at most 2 c occurrences of basic instructions are reachable in c steps.Therefore, there must be at least 2 k / c = 2 k − c different occurrences of a i in ϕ ( P k ). Consequently, ℓ ( ϕ ( P k )) ≥ k · k − c = 2 · k − c . Moreover, ℓ ( P k ) = 12 · k +4.Hence, the restriction of ϕ to { P , P , . . . } has a quadratic lower bound on itsincrease in length. ⊓⊔ We conclude from Theorem 1 that we are faced with super-linear increases ofmaximal internal delays if we strive for acceptable increases of program lengthson elimination of indirect jump instructions. In other words, indirect jump in-structions are needed for good instruction sequence performance.
Semantically, we can eliminate indirect jump instructions by means of abehaviour-preserving mapping from PGLB ij programs to PGLB programs, butwe meet here two challenges of a point of view concerning programming languagesemantics of which such behaviour-preserving mappings form part.In [3], the name projectionism is coined for the point of view referred toabove and its main challenges are discussed. To put it briefly, projectionism isthe point of view that: Here behaviour-preserving means preserving the behaviour referred to at the end ofSection 2, which behaviour does not include internal delays. any program P first and for all represents a single-pass instruction sequenceas considered in program algebra; – this single-pass instruction sequence, found by behaviour-preserving map-pings called projections, represents in a natural and preferred way what issupposed to take place on execution of P ; – program algebra provides the preferred notation for single-pass instructionsequences.Among the main challenges of projectionism identified in [3] are explosion of size,degradation of performance, complexity of description, and aesthetic degrada-tion.Projectionism is illustrated in [1] by means of a hierarchy of program nota-tions rooted in program algebra. For each of the program notations that appearin the hierarchy, except program algebra, a mapping is given by means of whicheach program from that program notation is translated into a program from thefirst program notation lower in the hierarchy that produces the same behaviouron execution. Thus, the single-pass instruction sequence represented by a pro-gram in any program notation from the hierarchy can be found. The mappingsconcerned are examples of the projections referred to above in the outline ofprojectionism.The behaviour-preserving mapping from Theorem 1 is a projection in thesame sense. Theorem 1 concerns two of the above-mentioned challenges of pro-jectionism, for it expresses that in the case of a projection from PGLB ij programsto PGLB programs there is a trade-off between explosion of size and degradationof performance. In the literature on computer architecture, hardly anything can be found thatcontributes to a sound understanding of the effects of the presence of commonkinds of instructions in the instruction set of a computer on points such asinstruction sequence size and instruction sequence performance. As a first steptowards such an understanding, we have shown that, in the case where thenumber of instructions is not bounded, there exist instruction sequences withdirect and indirect jump instructions from which elimination of indirect jumpinstructions is possible without a super-linear increase of their maximal internaldelay on execution only if their lengths increase super-linearly on eliminationof indirect jump instructions. It is an open problem whether this result goesthrough in the case where the number of instructions is bounded.Instruction sequences with direct jump instructions, indirect jump instruc-tions and register transfer instructions are as expressive as instruction sequenceswith direct jump instructions and indirect jump instructions without registertransfer instructions. We surmise that a mapping that eliminates the registertransfer instructions yields a result comparable to Theorem 1. However, we havenot yet been able to provide a proof for that case. On the face of it, a proof forthat case is much more difficult than the proof for the case treated in this paper.9or completeness, we mention that, in the line of research to which the workpresented in this paper belongs, work that is mainly concerned with direct jumpinstructions includes the work presented in [4].
References
1. Bergstra, J.A., Loots, M.E.: Program algebra for sequential code. Journal of Logicand Algebraic Programming 51(2), 125–156 (2002)2. Bergstra, J.A., Middelburg, C.A.: Instruction sequences with indirect jumps. Scien-tific Annals of Computer Science 17, 19–46 (2007)3. Bergstra, J.A., Middelburg, C.A.: Instruction sequence notations with probabilisticinstructions. arXiv:0906.3083v1 [cs.PL] (June 2009)4. Bergstra, J.A., Middelburg, C.A.: On the expressiveness of single-pass instructionsequences. Theory of Computing Systems 50(2), 313–328 (2012)5. Bergstra, J.A., Ponse, A.: Combining programs and state machines. Journal of Logicand Algebraic Programming 51(2), 175–192 (2002)6. Bergstra, J.A., van der Zwaag, M.B.: Mechanistic behavior of single-pass instructionsequences. arXiv:0809.4635v1 [cs.PL] (September 2008)7. Gosling, J., Joy, B., Steele, G., Bracha, G.: The Java Language Specification.Addison-Wesley, Reading, MA, second edn. (2000)8. Hejlsberg, A., Wiltamuth, S., Golde, P.: C arXiv:1003.1572v1 [cs.PL] (March 2010)(March 2010)