bcdtrunc.
Decimal Truncate VX-form
Truncates a decimal value to a specified length and updates the condition register.
Details
The bcdtrunc. instruction truncates a packed decimal value in VSR[VRB+32] to a specified length and stores the result in VSR[VRT+32]. The length is determined by bits 48:63 of VSR[VRA+32].
Pseudocode Operation
if MSR.VEC=0 then
Vector_Unavailable()
inv_flag ←(VSR[VRB+32].nibble[31] < 0xA)
do i = 0 to 30
inv_flag ←inv_flag |
(VSR[VRB+32].nibble[i] > 0x9)
end
length ←VSR[VRA+32].bit[48:63]
ox_flag ←0
src_sign ←(VSR[VRB+32].nibble[31] = 0xB) |
(VSR[VRB+32].nibble[31] = 0xD)
eq_flag ←(VSR[VRB+32].nibble[0:30] = 0)
lt_flag ← src_sign & ¬eq_flag
gt_flag ←¬src_sign & ¬eq_flag
if length < 31 then do
do i = 0 to 30-length
if VSR[VRB+32].nibble[i]!=0b0000 then
ox_flag ←1
result.nibble[i] ←0b0000
end
if length > 0 then do
do i = 31-length to 30
result.nibble[i] ←VSR[VRB+32].nibble[i]
end
end
else
result.nibble[0:30] ←VSR[VRB+32].nibble[0:30]
result.nibble[31] ←
(src_sign=0) ? ((PS=0) ? 0xC : 0xF) : 0xD
VSR[VRT+32] ←inv_flag ? undefined : result
CR.bit[56] ←inv_flag ? 0b0 : lt_flag
CR.bit[57] ←inv_flag ? 0b0 : gt_flag
CR.bit[58] ←inv_flag ? 0b0 : eq_flag
CR.bit[59] ←inv_flag | ox_flag
Programming Note
The bcdtrunc. instruction is used to truncate a packed decimal value in VSR[VRB+32] to a specified length, determined by bits 48:63 of VSR[VRA+32]. Ensure that the vector facility (MSR.VEC) is enabled before using this instruction. The instruction checks for invalid nibbles and sets flags accordingly. Be cautious with alignment and ensure proper handling of special cases like overflow and sign preservation.
Example
Encoding
Operands
-
VRT
Target Vector Register -
VRA
Source Vector Register containing the length -
VRB
Source Vector Register containing the packed decimal value -
PS
Packed Sign flag