sv.bc test jumping to wrong location (offset 0xc not 0x8)
[openpower-isa.git] / openpower / isa / svbranch.mdwn
1 <!-- Instructions here part of Draft SVP64 Vectorised Branch -->
2
3 <!-- Section 2.4 Branch Instructions. Pages 33 - 39 -->
4
5 <!-- The sequence of instruction execution can be changed by the Branch -->
6 <!-- instructions. Because all instructions are on word boundaries, bits 62 and 63 -->
7 <!-- of the generated branch target address are ignored by the processor in -->
8 <!-- performing the branch. -->
9
10 <!-- target_addr specifies the branch target address. -->
11
12 <!-- If AA=0 then the branch target address is the sum of LI || 0b00 sign-extended -->
13 <!-- and the address of this instruction, with the high-order 32 bits of the branch -->
14 <!-- target address set to 0 in 32-bit mode. -->
15
16 <!-- If AA=1 then the branch target address is the value LI || 0b00 sign-extended, -->
17 <!-- with the high-order 32 bits of the branch target address set to 0 in 32-bit -->
18 <!-- mode. -->
19
20 <!-- If LK=1 then the effective address of the instruction following the Branch -->
21 <!-- instruction is placed into the Link Register. -->
22
23 # Branch Conditional
24
25 B-Form
26
27 * sv.bc BO,BI,target_addr (AA=0 LK=0)
28 * sv.bca BO,BI,target_addr (AA=1 LK=0)
29 * sv.bcl BO,BI,target_addr (AA=0 LK=1)
30 * sv.bcla BO,BI,target_addr (AA=1 LK=1)
31
32 Pseudo-code:
33
34 # get SVP64 extended CR field 0..127
35 # SVCRf = sVP64EXTRA(BI>>2)
36 # if svstep_mode then
37 # new_srcstep, CRbits = SVSTATE_NEXT(srcstep)
38 # else
39 # CRbits = CR{SVCRf}
40 # select predicate bit or zero/one
41 # XXX if predicate[srcstep] then
42 # XXX if BRc = 1 then # CR0 vectorised
43 # XXX CR{SVCRf+srcstep} = CRbits
44 # XXX testbit = CRbits[BI & 0b11]
45 if sz then
46 testbit = SNZ
47 else
48 testbit <- CR[BI+32]
49 # actual element test here
50 cond_ok <- BO[0] | ¬(testbit ^ BO[1])
51 # test for VL to be set (and exit)
52 if VLSET & (cond_ok = VSb) then
53 if VLI then
54 SVSTATE[7:13] <- (srcstep+1)
55 else
56 SVSTATE[7:13] <- srcstep+1
57 end_loop <- 0b1
58 # XXX if svstep_mode then
59 # XXX SVSTATE.srcstep = new_srcstep
60 # actual branch
61 if (mode_is_64bit) then M <- 0
62 else M <- 32
63 if ¬BO[2] then CTR <- CTR - 1
64 ctr_ok <- BO[2] | ((CTR[M:63] != 0) ^ BO[3])
65 test_branch <- 0b1
66 if ALL then
67 # in ALL mode only try branching at end of loop
68 if ¬end_loop then
69 test_branch <- 0b0
70 # test early-exit. ALL will exit if cond_ok fails
71 if ¬cond_ok then
72 end_loop <- 0b1
73 test_branch <- 0b0
74 lr_ok <- LRu
75 if test_branch & ctr_ok & cond_ok then
76 if AA then NIA <-iea EXTS(BD || 0b00)
77 else NIA <-iea CIA + EXTS(BD || 0b00)
78 lr_ok <- 0b1
79 end_loop <- 0b1
80 if LK & lr_ok then LR <-iea CIA + 4
81
82 Special Registers Altered:
83
84 CTR (if BO2=0)
85 LR (if LK=1)
86
87 # Branch Conditional to Link Register
88
89 XL-Form
90
91 * sv.bclr BO,BI,BH (LK=0)
92 * sv.bclrl BO,BI,BH (LK=1)
93
94 Pseudo-code:
95
96 if (mode_is_64bit) then M <- 0
97 else M <- 32
98 if ¬BO[2] then CTR <- CTR - 1
99 ctr_ok <- BO[2] | ((CTR[M:63] != 0) ^ BO[3])
100 cond_ok <- BO[0] | ¬(CR[BI+32] ^ BO[1])
101 lr_ok <- LRu
102 if ctr_ok & cond_ok then
103 NIA <-iea LR[0:61] || 0b00
104 lr_ok <- 0b1
105 if LK & lr_ok then LR <-iea CIA + 4
106
107 Special Registers Altered:
108
109 CTR (if BO2=0)
110 LR (if LK=1)
111