add more tests and fix missing corner case
[openpower-isa.git] / openpower / isa / prefix_codes.mdwn
1 <!-- https://libre-soc.org/openpower/prefix_codes/ -->
2
3 # [DRAFT] Prefix-code decode
4
5 VA2-Form
6
7 * pcdec. RT,RA,RB,RC,once
8
9 Pseudo-code:
10
11 tree[0:63] <- (RB)
12 ra_used <- 0b0
13 in_bits[0:63] <- (RC|0)
14 if in_bits = 0 then
15 in_bits[0:63] <- 1
16 final_in_bits <- in_bits
17 final_ra_used <- ra_used
18 output <- [0] * 64
19 out_byte <- 0
20 decoded[0:7] <- 1
21 so_bit <- 0b0
22 early_stop <- 0b0
23 do while out_byte < 8
24 in_bit <- in_bits[63]
25 if in_bits = 1 then
26 if ra_used | (_RA = 0) then
27 early_stop <- 0b1
28 if decoded != 1 then # error: stopped in the middle of a code
29 so_bit <- 0b1
30 leave
31 ra_used <- 0b1
32 in_bit <- (RA)[63]
33 in_bits <- 0b1 || (RA)[0:62]
34 else
35 in_bits <- 0b0 || in_bits[0:62]
36 # walk the binary tree in `tree` from parent to the selected child
37 decoded <- decoded[1:7] || in_bit
38 if decoded <u 64 then
39 if tree[63 - decoded] then
40 final_in_bits <- in_bits
41 final_ra_used <- ra_used
42 output[56 - 8 * out_byte:63 - 8 * out_byte] <- decoded
43 decoded[0:7] <- 1
44 out_byte <- out_byte + 1
45 if once then
46 leave
47 else
48 so_bit <- 0b1
49 early_stop <- 0b1
50 leave
51 RT <- output
52 RS <- final_in_bits
53 CR0 <- final_ra_used || (output = 0) || early_stop || so_bit
54
55 Special Registers Altered:
56
57 CR0