Blame SOURCES/valgrind-3.17.0-ppc64-isa-3.1.patch

172105
commit 3cc0232c46a5905b4a6c2fbd302b58bf5f90b3d5
172105
Author: Carl Love <cel@us.ibm.com>
172105
Date:   Mon Jan 11 16:00:57 2021 -0600
172105
172105
    PPC64: ISA 3.1 VSX PCV Generate Operations
172105
    
172105
    xgenpcvbm VSX Vector Generate PCV from Byte Mask
172105
    xxgenpcvdmVSX Vector Generate PCV from Doubleword Mask
172105
    xxgenpcvhmVSX Vector Generate PCV from Halfword Mask
172105
    xxgenpcvwmVSX Vector Generate PCV from Word Mask
172105
172105
diff --git a/VEX/priv/guest_ppc_defs.h b/VEX/priv/guest_ppc_defs.h
172105
index deda4dfce..54ce923a9 100644
172105
--- a/VEX/priv/guest_ppc_defs.h
172105
+++ b/VEX/priv/guest_ppc_defs.h
172105
@@ -169,6 +169,23 @@ void write_ACC_entry (VexGuestPPC64State* gst, UInt offset, UInt acc,
172105
 void get_ACC_entry (VexGuestPPC64State* gst, UInt offset, UInt acc,
172105
                     UInt reg, UInt *result);
172105
 
172105
+extern void vector_gen_pvc_byte_mask_dirty_helper( VexGuestPPC64State* gst,
172105
+                                                   ULong src_hi,
172105
+                                                   ULong src_lo,
172105
+                                                   UInt rtn_val, UInt IMM );
172105
+extern void vector_gen_pvc_hword_mask_dirty_helper( VexGuestPPC64State* gst,
172105
+                                                    ULong src_hi,
172105
+                                                    ULong src_lo,
172105
+                                                    UInt rtn_val, UInt IMM );
172105
+extern void vector_gen_pvc_word_mask_dirty_helper( VexGuestPPC64State* gst,
172105
+                                                   ULong src_hi,
172105
+                                                   ULong src_lo,
172105
+                                                   UInt rtn_val, UInt IMM );
172105
+extern void vector_gen_pvc_dword_mask_dirty_helper( VexGuestPPC64State* gst,
172105
+                                                    ULong src_hi,
172105
+                                                    ULong src_lo,
172105
+                                                    UInt rtn_val, UInt IMM );
172105
+
172105
 /* 8-bit XO value from instruction description */
172105
 #define XVI4GER8       0b00100011
172105
 #define XVI4GER8PP     0b00100010
172105
diff --git a/VEX/priv/guest_ppc_helpers.c b/VEX/priv/guest_ppc_helpers.c
172105
index c24191ef3..75497abb9 100644
172105
--- a/VEX/priv/guest_ppc_helpers.c
172105
+++ b/VEX/priv/guest_ppc_helpers.c
172105
@@ -701,6 +701,738 @@ ULong vector_evaluate64_helper( ULong srcA, ULong srcB, ULong srcC,
172105
 #undef MAX_IMM_BITS
172105
 }
172105
 
172105
+/*--------------------------------------------------*/
172105
+/*---- VSX Vector Generate PCV from Mask helpers ---*/
172105
+/*--------------------------------------------------*/
172105
+static void write_VSX_entry (VexGuestPPC64State* gst, UInt reg_offset,
172105
+                             ULong *vsx_entry)
172105
+{
172105
+   U128* pU128_dst;
172105
+   pU128_dst = (U128*) (((UChar*) gst) + reg_offset);
172105
+
172105
+   /* The U128 type is defined as an array of unsigned intetgers.  */
172105
+   /* Writing in LE order */
172105
+   (*pU128_dst)[0] = (UInt)(vsx_entry[1] & 0xFFFFFFFF);
172105
+   (*pU128_dst)[1] = (UInt)(vsx_entry[1] >> 32);
172105
+   (*pU128_dst)[2] = (UInt)(vsx_entry[0] & 0xFFFFFFFF);
172105
+   (*pU128_dst)[3] = (UInt)(vsx_entry[0] >> 32);
172105
+   return;
172105
+}
172105
+
172105
+/* CALLED FROM GENERATED CODE */
172105
+void vector_gen_pvc_byte_mask_dirty_helper( VexGuestPPC64State* gst,
172105
+                                            ULong src_hi, ULong src_lo,
172105
+                                            UInt reg_offset, UInt imm ) {
172105
+   /* The function computes the 128-bit result then writes it directly
172105
+      into the guest state VSX register.  */
172105
+
172105
+   UInt  i, shift_by, sel_shift_by, half_sel;
172105
+   ULong index, src, result[2];
172105
+   ULong j;
172105
+
172105
+   result[0] = 0;
172105
+   result[1] = 0;
172105
+   j = 0;
172105
+
172105
+   /* The algorithm in the ISA is written with IBM numbering zero on left and
172105
+      N-1 on right. The loop index is converted to "i" to match the algorithm
172105
+      for claritiy of matching the C code to the algorithm in the ISA.  */
172105
+
172105
+   if (imm == 0b00) {    // big endian expansion
172105
+      for( index = 0; index < 16; index++) {
172105
+         i = 15 - index;
172105
+
172105
+         shift_by = i*8;
172105
+
172105
+         if ( i >= 8) {
172105
+            src = src_hi;
172105
+            shift_by = shift_by - 64;
172105
+            half_sel = 0;
172105
+         } else {
172105
+            src = src_lo;
172105
+            half_sel = 1;
172105
+         }
172105
+
172105
+         sel_shift_by = shift_by + 7;
172105
+
172105
+         if ( ((src >> sel_shift_by) & 0x1) == 1) {
172105
+               result[half_sel] |= j << shift_by;
172105
+            j++;
172105
+         } else {
172105
+            result[half_sel] |= (index + (unsigned long long)0x10) << shift_by;
172105
+         }
172105
+      }
172105
+
172105
+
172105
+   } else if (imm == 0b01) {    // big endian compression
172105
+      /* If IMM=0b00001, let pcv be the permute control vector required to
172105
+         enable a left-indexed permute (vperm or xxperm) to implement a
172105
+         compression of the sparse byte elements in a source vector specified
172105
+         by the byte-element mask in VSR[VRB+32] into the leftmost byte
172105
+         elements of a result vector.
172105
+      */
172105
+      for( index = 0; index < 16; index++) {
172105
+         i = 15 - index;
172105
+         shift_by = i*8;
172105
+
172105
+         if ( i >= 8) {
172105
+            src = src_hi;
172105
+            shift_by = shift_by - 64;
172105
+            half_sel = 0;
172105
+         } else {
172105
+            src = src_lo;
172105
+            half_sel = 1;
172105
+         }
172105
+
172105
+         sel_shift_by = shift_by + 7;
172105
+
172105
+         if ( ((src >> sel_shift_by) & 0x1) == 1) {
172105
+            if (j >= 8)
172105
+               result[1] |= (index) << (15 - j)*8;
172105
+            else
172105
+               result[0] |= (index) << (7 - j)*8;
172105
+            j++;
172105
+         }
172105
+      }
172105
+      /* The algorithim says set to undefined, leave as 0
172105
+      for( index = 3 - j; index < 4; index++) {
172105
+         result |= (0 << (index*8));
172105
+      }
172105
+      */
172105
+
172105
+   } else if (imm == 0b10) {   //little-endian expansion
172105
+      /* If IMM=0b00010, let pcv be the permute control vector required to
172105
+         enable a right-indexed permute (vpermr or xxpermr) to implement an
172105
+         expansion of the rightmost byte elements of a source vector into the
172105
+         byte elements of a result vector specified by the byte-element mask
172105
+         in VSR[VRB+32].  */
172105
+      for( index = 0; index < 16; index++) {
172105
+         i = index;
172105
+
172105
+         shift_by = i*8;
172105
+
172105
+         if ( i >= 8) {
172105
+            src = src_hi;
172105
+            shift_by = shift_by - 64;
172105
+            half_sel = 0;
172105
+         } else {
172105
+            src = src_lo;
172105
+            half_sel = 1;
172105
+         }
172105
+
172105
+         sel_shift_by = shift_by + 7;
172105
+
172105
+         /* mod shift amount by 8 since src is either the upper or lower
172105
+            64-bits.  */
172105
+         if ( ((src >> sel_shift_by) & 0x1) == 1) {
172105
+               result[half_sel] |= j << shift_by;
172105
+            j++;
172105
+         } else {
172105
+            result[half_sel] |= (index + (unsigned long long)0x10) << shift_by;
172105
+         }
172105
+      }
172105
+
172105
+   } else if (imm == 0b11) {   //little-endian compression
172105
+      /* If IMM=0b00011, let pcv be the permute control vector required to
172105
+         enable a right-indexed permute (vpermr or xxpermr) to implement a
172105
+         compression of the sparse byte elements in a source vector specified
172105
+         by the byte-element mask in VSR[VRB+32] into the rightmost byte
172105
+         elements of a result vector.  */
172105
+
172105
+      for( index = 0; index < 16; index++) {
172105
+         i = index;
172105
+
172105
+         shift_by = i*8;
172105
+
172105
+         if ( i >= 8) {
172105
+            src = src_hi;
172105
+            shift_by = shift_by - 64;
172105
+            half_sel = 0;
172105
+         } else {
172105
+            src = src_lo;
172105
+            half_sel = 1;
172105
+         }
172105
+
172105
+         sel_shift_by = shift_by + 7;
172105
+
172105
+         if ( ((src >> sel_shift_by) & 0x1) == 1) {
172105
+            if (j >= 8)
172105
+               result[0] |= (index) << (j-8)*8;
172105
+            else
172105
+               result[1] |= (index) << j*8;
172105
+            j++;
172105
+         }
172105
+      }
172105
+
172105
+      /* The algorithim says set to undefined, leave as 0
172105
+      for( index = 3 - j; index < 4; index++) {
172105
+         result |= (0 << (index*8));
172105
+      }
172105
+      */
172105
+
172105
+   } else {
172105
+      vex_printf("ERROR, vector_gen_pvc_byte_mask_dirty_helper, imm value %u not supported.\n",
172105
+                 imm);
172105
+      vassert(0);
172105
+   }
172105
+   write_VSX_entry( gst, reg_offset, result);
172105
+}
172105
+
172105
+/* CALLED FROM GENERATED CODE */
172105
+void vector_gen_pvc_hword_mask_dirty_helper( VexGuestPPC64State* gst,
172105
+                                             ULong src_hi, ULong src_lo,
172105
+                                             UInt reg_offset,
172105
+                                             UInt imm ) {
172105
+   /* The function computes the 128-bit result then writes it directly
172105
+      into the guest state VSX register.  */
172105
+   UInt  i, shift_by, sel_shift_by, half_sel;
172105
+   ULong index, src, result[2];
172105
+   ULong j;
172105
+
172105
+   result[0] = 0;
172105
+   result[1] = 0;
172105
+   j = 0;
172105
+
172105
+   /* The algorithm in the ISA is written with IBM numbering zero on left and
172105
+      N-1 on right. The loop index is converted to "i" to match the algorithm
172105
+      for claritiy of matching the C code to the algorithm in the ISA.  */
172105
+
172105
+   if (imm == 0b00) {    // big endian expansion
172105
+      /* If IMM=0b00000, let pcv be the permute control vector required to
172105
+         enable a left-indexed permute (vperm or xxperm) to implement an
172105
+         expansion of the leftmost halfword elements of a source vector into
172105
+         the halfword elements of a result vector specified by the halfword-
172105
+         element mask in VSR[VRB+32].
172105
+      */
172105
+      for( index = 0; index < 8; index++) {
172105
+         i = 7 - index;
172105
+
172105
+         shift_by = i*16;
172105
+
172105
+         if ( i >= 4) {
172105
+            src = src_hi;
172105
+            shift_by = shift_by - 64;
172105
+            half_sel = 0;
172105
+         } else {
172105
+            src = src_lo;
172105
+            half_sel = 1;
172105
+         }
172105
+
172105
+         sel_shift_by = shift_by + 15;
172105
+
172105
+         if ( ((src >> sel_shift_by) & 0x1) == 1) {
172105
+            // half-word i, byte 0
172105
+            result[half_sel] |= (2*j + 0x0) << (shift_by+8);
172105
+            // half-word i, byte 1
172105
+            result[half_sel] |= (2*j + 0x1) << shift_by;
172105
+            j++;
172105
+         } else {
172105
+            result[half_sel] |= (2*index + 0x10) << (shift_by+8);
172105
+            result[half_sel] |= (2*index + 0x11) << shift_by;
172105
+         }
172105
+      }
172105
+
172105
+   } else if (imm == 0b01) {    // big endian expansion
172105
+      /* If IMM=0b00001,let pcv be the permute control vector required to
172105
+         enable a left-indexed permute (vperm or xxperm) to implement a
172105
+         compression of the sparse halfword elements in a source vector
172105
+         specified by the halfword-element mask in VSR[VRB+32] into the
172105
+         leftmost halfword elements of a result vector.
172105
+      */
172105
+      for( index = 0; index < 8; index++) {
172105
+         i = 7 - index;
172105
+
172105
+         shift_by = i*16;
172105
+
172105
+         if ( i >= 4) {
172105
+            src = src_hi;
172105
+            shift_by = shift_by - 64;
172105
+            half_sel = 0;
172105
+         } else {
172105
+            src = src_lo;
172105
+            half_sel = 1;
172105
+         }
172105
+
172105
+         sel_shift_by = shift_by + 15;
172105
+
172105
+         if ( ((src >> sel_shift_by) & 0x1) == 1) {
172105
+            if (j >= 4) {
172105
+               // half-word i, byte 0
172105
+               result[1] |= (2*index + 0x0) << ((7 - j)*16 + 8);
172105
+               // half-word i, byte 1
172105
+               result[1] |= (2*index + 0x1) << ((7 - j)*16);
172105
+            } else {
172105
+               // half-word i, byte 0
172105
+               result[0] |= (2*index + 0x0) << ((3 - j)*16 + 8);
172105
+               // half-word i, byte 1
172105
+               result[0] |= (2*index + 0x1) << ((3 - j)*16);
172105
+            }
172105
+            j++;
172105
+         }
172105
+      }
172105
+
172105
+   } else if (imm == 0b10) {   //little-endian expansion
172105
+      /* If IMM=0b00010, let pcv be the permute control vector required to
172105
+         enable a right-indexed permute (vpermr or xxpermr) to implement an
172105
+         expansion of the rightmost halfword elements of a source vector into
172105
+         the halfword elements of a result vector specified by the halfword-
172105
+         element mask in VSR[VRB+32].
172105
+       */
172105
+      for( index = 0; index < 8; index++) {
172105
+         i = index;
172105
+         shift_by = i*16;
172105
+
172105
+         if ( i >= 4) {
172105
+            src = src_hi;
172105
+            shift_by = shift_by - 64;
172105
+            half_sel = 0;
172105
+         } else {
172105
+            src = src_lo;
172105
+            half_sel = 1;
172105
+         }
172105
+
172105
+         sel_shift_by = shift_by + 15;
172105
+
172105
+         if ( ((src >> sel_shift_by) & 0x1) == 1) {
172105
+            // half-word i, byte 0
172105
+            result[half_sel] |= (2*j + 0x00) << shift_by;
172105
+            // half-word i, byte 1
172105
+            result[half_sel] |= (2*j + 0x01) << (shift_by+8);
172105
+            j++;
172105
+
172105
+         } else {
172105
+            // half-word i, byte 0
172105
+            result[half_sel] |= (2*index + 0x10) << shift_by;
172105
+            // half-word i, byte 1
172105
+            result[half_sel] |= (2*index + 0x11) << (shift_by+8);
172105
+         }
172105
+      }
172105
+
172105
+   } else if (imm == 0b11) {   //little-endian compression
172105
+      /* If IMM=0b00011, let pcv be the permute control vector required to
172105
+         enable a right-indexed permute (vpermr or xxpermr) to implement a
172105
+         compression of the sparse halfword elements in a source vector
172105
+         specified by the halfword-element mask in VSR[VRB+32] into the
172105
+         rightmost halfword elements of a result vector.  */
172105
+      for( index = 0; index < 8; index++) {
172105
+         i = index;
172105
+         shift_by = i*16;
172105
+
172105
+         if ( i >= 4) {
172105
+            src = src_hi;
172105
+            shift_by = shift_by - 64;
172105
+            half_sel = 0;
172105
+         } else {
172105
+            src = src_lo;
172105
+            half_sel = 1;
172105
+         }
172105
+
172105
+         sel_shift_by = shift_by + 15;
172105
+
172105
+         if ( ((src >> sel_shift_by) & 0x1) == 1) {
172105
+            if (j >= 4) {
172105
+               // half-word j, byte 0
172105
+               result[0] |= (2*index + 0x0) << ((j-4)*16);
172105
+               // half-word j, byte 1
172105
+               result[0] |= (2*index + 0x1) << ((j-4)*16+8);
172105
+            } else {
172105
+               // half-word j, byte 0
172105
+               result[1] |= (2*index + 0x0) << (j*16);
172105
+               // half-word j, byte 1
172105
+               result[1] |= (2*index + 0x1) << ((j*16)+8);
172105
+            }
172105
+            j++;
172105
+         }
172105
+      }
172105
+
172105
+   } else {
172105
+      vex_printf("ERROR, vector_gen_pvc_hword_dirty_mask_helper, imm value %u not supported.\n",
172105
+                 imm);
172105
+      vassert(0);
172105
+   }
172105
+   write_VSX_entry( gst, reg_offset, result);
172105
+}
172105
+
172105
+/* CALLED FROM GENERATED CODE */
172105
+void vector_gen_pvc_word_mask_dirty_helper( VexGuestPPC64State* gst,
172105
+                                            ULong src_hi, ULong src_lo,
172105
+                                            UInt reg_offset, UInt imm ) {
172105
+   /* The function computes the 128-bit result then writes it directly
172105
+      into the guest state VSX register.  */
172105
+   UInt  i, shift_by, sel_shift_by, half_sel;
172105
+   ULong index, src, result[2];
172105
+   ULong j;
172105
+
172105
+   result[0] = 0;
172105
+   result[1] = 0;
172105
+   j = 0;
172105
+
172105
+   /* The algorithm in the ISA is written with IBM numbering zero on left and
172105
+      N-1 on right. The loop index is converted to "i" to match the algorithm
172105
+      for claritiy of matching the C code to the algorithm in the ISA.  */
172105
+
172105
+   if (imm == 0b00) {    // big endian expansion
172105
+      /* If IMM=0b00000, let pcv be the permute control vector required to
172105
+         enable a left-indexed permute (vperm or xxperm) to implement an
172105
+         expansion of the leftmost word elements of a source vector into the
172105
+         word elements of a result vector specified by the word-element mask
172105
+         in VSR[VRB+32].
172105
+      */
172105
+      for( index = 0; index < 4; index++) {
172105
+         i = 3 - index;
172105
+
172105
+         shift_by = i*32;
172105
+
172105
+         if ( i >= 2) {
172105
+            src = src_hi;
172105
+            shift_by = shift_by - 64;
172105
+            half_sel = 0;
172105
+         } else {
172105
+            src = src_lo;
172105
+            half_sel = 1;
172105
+         }
172105
+
172105
+         sel_shift_by = shift_by + 31;
172105
+
172105
+         if ( ((src >> sel_shift_by) & 0x1) == 1) {
172105
+            result[half_sel] |= (4*j+0) << (shift_by+24);  // word i, byte 0
172105
+            result[half_sel] |= (4*j+1) << (shift_by+16);  // word i, byte 1
172105
+            result[half_sel] |= (4*j+2) << (shift_by+8);   // word i, byte 2
172105
+            result[half_sel] |= (4*j+3) << shift_by;       // word i, byte 3
172105
+            j++;
172105
+         } else {
172105
+            result[half_sel] |= (4*index + 0x10) << (shift_by+24);
172105
+            result[half_sel] |= (4*index + 0x11) << (shift_by+16);
172105
+            result[half_sel] |= (4*index + 0x12) << (shift_by+8);
172105
+            result[half_sel] |= (4*index + 0x13) << shift_by;
172105
+         }
172105
+      }
172105
+
172105
+   } else if (imm == 0b01) {    // big endian compression
172105
+      /* If IMM=0b00001, let pcv be the permute control vector required to
172105
+         enable a left-indexed permute (vperm or xxperm) to implement a
172105
+         compression of the sparse word elements in a source vector specified
172105
+         by the word-element mask in VSR[VRB+32] into the leftmost word
172105
+         elements of a result vector.
172105
+      */
172105
+      for( index = 0; index < 4; index++) {
172105
+         i = 3 - index;
172105
+
172105
+         shift_by = i*32;
172105
+
172105
+         if ( i >= 2) {
172105
+            src = src_hi;
172105
+            shift_by = shift_by - 64;
172105
+            half_sel = 0;
172105
+         } else {
172105
+            src = src_lo;
172105
+            half_sel = 1;
172105
+         }
172105
+
172105
+         sel_shift_by = shift_by + 31;
172105
+
172105
+         if (((src >> sel_shift_by) & 0x1) == 1) {
172105
+            if (j >= 2) {
172105
+               // word j, byte 0
172105
+               result[1] |= (4*index+0) << ((3 - j)*32 + 24);
172105
+               // word j, byte 1
172105
+               result[1] |= (4*index+1) << ((3 - j)*32 + 16);
172105
+               // word j, byte 2
172105
+               result[1] |= (4*index+2) << ((3 - j)*32 + 8);
172105
+               // word j, byte 3
172105
+               result[1] |= (4*index+3) << ((3 - j)*32 + 0);
172105
+            } else {
172105
+               result[0] |= (4*index+0) << ((1 - j)*32 + 24);
172105
+               result[0] |= (4*index+1) << ((1 - j)*32 + 16);
172105
+               result[0] |= (4*index+2) << ((1 - j)*32 + 8);
172105
+               result[0] |= (4*index+3) << ((1 - j)*32 + 0);
172105
+            }
172105
+            j++;
172105
+         }
172105
+      }
172105
+
172105
+   } else if (imm == 0b10) {   //little-endian expansion
172105
+      /* If IMM=0b00010, let pcv be the permute control vector required to
172105
+         enable a right-indexed permute (vpermr or xxpermr) to implement an
172105
+         expansion of the rightmost word elements of a source vector into the
172105
+         word elements of a result vector specified by the word-element mask
172105
+         in VSR[VRB+32].
172105
+       */
172105
+      for( index = 0; index < 4; index++) {
172105
+         i = index;
172105
+
172105
+         shift_by = i*32;
172105
+
172105
+         if ( i >= 2) {
172105
+            src = src_hi;
172105
+            shift_by = shift_by - 64;
172105
+            half_sel = 0;
172105
+         } else {
172105
+            src = src_lo;
172105
+            half_sel = 1;
172105
+         }
172105
+
172105
+         sel_shift_by = shift_by + 31;
172105
+
172105
+         if (((src >> sel_shift_by) & 0x1) == 1) {
172105
+            result[half_sel] |= (4*j+0) << (shift_by + 0);  // word j, byte 0
172105
+            result[half_sel] |= (4*j+1) << (shift_by + 8);  // word j, byte 1
172105
+            result[half_sel] |= (4*j+2) << (shift_by + 16); // word j, byte 2
172105
+            result[half_sel] |= (4*j+3) << (shift_by + 24); // word j, byte 3
172105
+            j++;
172105
+         } else {
172105
+            result[half_sel] |= (4*index + 0x10) << (shift_by + 0);
172105
+            result[half_sel] |= (4*index + 0x11) << (shift_by + 8);
172105
+            result[half_sel] |= (4*index + 0x12) << (shift_by + 16);
172105
+            result[half_sel] |= (4*index + 0x13) << (shift_by + 24);
172105
+         }
172105
+      }
172105
+
172105
+   } else if (imm == 0b11) {   //little-endian compression
172105
+      /* If IMM=0b00011, let pcv be the permute control vector required to
172105
+         enable a right-indexed permute (vpermr or xxpermr) to implement a
172105
+         compression of the sparse word elements in a source vector specified
172105
+         by the word-element mask in VSR[VRB+32] into the rightmost word
172105
+         elements of a result vector.  */
172105
+      for( index = 0; index < 4; index++) {
172105
+         i =index;
172105
+
172105
+         shift_by = i*32;
172105
+
172105
+         if ( i >= 2) {
172105
+            src = src_hi;
172105
+            shift_by = shift_by - 64;
172105
+            half_sel = 0;
172105
+         } else {
172105
+            src = src_lo;
172105
+            half_sel = 1;
172105
+         }
172105
+
172105
+         sel_shift_by = shift_by + 31;
172105
+
172105
+         if (((src >> sel_shift_by) & 0x1) == 1) {
172105
+            if (j >= 2){
172105
+               // word j, byte 0
172105
+               result[0] |= (4*index + 0x0) << ((j-2)*32+0);
172105
+               // word j, byte 1
172105
+               result[0] |= (4*index + 0x1) << ((j-2)*32+8);
172105
+               // word j, byte 2
172105
+               result[0] |= (4*index + 0x2) << ((j-2)*32+16);
172105
+               // word j, byte 3
172105
+               result[0] |= (4*index + 0x3) << ((j-2)*32+24);
172105
+            } else {
172105
+               result[1] |= (4*index + 0x0) << (j*32+0);
172105
+               result[1] |= (4*index + 0x1) << (j*32+8);
172105
+               result[1] |= (4*index + 0x2) << (j*32+16);
172105
+               result[1] |= (4*index + 0x3) << (j*32+24);
172105
+            }
172105
+            j++;
172105
+         }
172105
+      }
172105
+   } else {
172105
+      vex_printf("ERROR, vector_gen_pvc_word_mask_dirty_helper, imm value %u not supported.\n",
172105
+                 imm);
172105
+      vassert(0);
172105
+   }
172105
+
172105
+   write_VSX_entry( gst, reg_offset, result);
172105
+}
172105
+
172105
+/* CALLED FROM GENERATED CODE */
172105
+void vector_gen_pvc_dword_mask_dirty_helper( VexGuestPPC64State* gst,
172105
+                                             ULong src_hi, ULong src_lo,
172105
+                                             UInt reg_offset, UInt imm ) {
172105
+   /* The function computes the 128-bit result then writes it directly
172105
+      into the guest state VSX register.  */
172105
+   UInt  sel_shift_by, half_sel;
172105
+   ULong index, src, result[2];
172105
+   ULong j, i;
172105
+
172105
+   result[0] = 0;
172105
+   result[1] = 0;
172105
+   j = 0;
172105
+
172105
+   /* The algorithm in the ISA is written with IBM numbering zero on left and
172105
+      N-1 on right. The loop index is converted to "i" to match the algorithm
172105
+      for claritiy of matching the C code to the algorithm in the ISA.  */
172105
+
172105
+   if (imm == 0b00) {    // big endian expansion
172105
+      /* If IMM=0b00000, let pcv be the permute control vector required to
172105
+         enable a left-indexed permute (vperm or xxperm) to implement an
172105
+         expansion of the leftmost doubleword elements of a source vector into
172105
+         the doubleword elements of a result vector specified by the
172105
+         doubleword-element mask in VSR[VRB+32].
172105
+      */
172105
+      for( index = 0; index < 2; index++) {
172105
+         i = 1 - index;
172105
+
172105
+         if ( i == 1) {
172105
+            src = src_hi;
172105
+            half_sel = 0;
172105
+         } else {
172105
+            src = src_lo;
172105
+            half_sel = 1;
172105
+         }
172105
+
172105
+         sel_shift_by = 63;
172105
+
172105
+         if ( ((src >> sel_shift_by) & 0x1) == 1) {
172105
+            result[half_sel] |= (8*j + 0x0) << 56; // dword i, byte 0
172105
+            result[half_sel] |= (8*j + 0x1) << 48; // dword i, byte 1
172105
+            result[half_sel] |= (8*j + 0x2) << 40; // dword i, byte 2
172105
+            result[half_sel] |= (8*j + 0x3) << 32; // dword i, byte 3
172105
+            result[half_sel] |= (8*j + 0x4) << 24; // dword i, byte 4
172105
+            result[half_sel] |= (8*j + 0x5) << 16; // dword i, byte 5
172105
+            result[half_sel] |= (8*j + 0x6) << 8;  // dword i, byte 6
172105
+            result[half_sel] |= (8*j + 0x7) << 0;  // dword i, byte 7
172105
+            j++;
172105
+         } else {
172105
+            result[half_sel] |= (8*index + 0x10) << 56;
172105
+            result[half_sel] |= (8*index + 0x11) << 48;
172105
+            result[half_sel] |= (8*index + 0x12) << 40;
172105
+            result[half_sel] |= (8*index + 0x13) << 32;
172105
+            result[half_sel] |= (8*index + 0x14) << 24;
172105
+            result[half_sel] |= (8*index + 0x15) << 16;
172105
+            result[half_sel] |= (8*index + 0x16) << 8;
172105
+            result[half_sel] |= (8*index + 0x17) << 0;
172105
+         }
172105
+      }
172105
+   } else if (imm == 0b01) {    // big endian compression
172105
+      /* If IMM=0b00001, let pcv be the the permute control vector required to
172105
+         enable a left-indexed permute (vperm or xxperm) to implement a
172105
+         compression of the sparse doubleword elements in a source vector
172105
+         specified by the doubleword-element mask in VSR[VRB+32] into the
172105
+         leftmost doubleword elements of a result vector.
172105
+      */
172105
+      for( index = 0; index < 2; index++) {
172105
+         i = 1 - index;
172105
+
172105
+         if ( i == 1) {
172105
+            src = src_hi;
172105
+            half_sel = 0;
172105
+         } else {
172105
+            src = src_lo;
172105
+            half_sel = 1;
172105
+         }
172105
+
172105
+         sel_shift_by = 63;
172105
+
172105
+         if ( ((src >> sel_shift_by) & 0x1) == 1) {
172105
+            if (j == 1) {
172105
+               result[1] |= (8*index + 0x0) << 56;   // double-word j, byte 0
172105
+               result[1] |= (8*index + 0x1) << 48;   // double-word j, byte 1
172105
+               result[1] |= (8*index + 0x2) << 40;   // double-word j, byte 2
172105
+               result[1] |= (8*index + 0x3) << 32;   // double-word j, byte 3
172105
+               result[1] |= (8*index + 0x4) << 24;   // double-word j, byte 4
172105
+               result[1] |= (8*index + 0x5) << 16;   // double-word j, byte 5
172105
+               result[1] |= (8*index + 0x6) << 8;    // double-word j, byte 6
172105
+               result[1] |= (8*index + 0x7) << 0;    // double-word j, byte 7
172105
+            } else {
172105
+               result[0] |= (8*index + 0x0) << 56;   // double-word j, byte 0
172105
+               result[0] |= (8*index + 0x1) << 48;   // double-word j, byte 1
172105
+               result[0] |= (8*index + 0x2) << 40;   // double-word j, byte 2
172105
+               result[0] |= (8*index + 0x3) << 32;   // double-word j, byte 3
172105
+               result[0] |= (8*index + 0x4) << 24;   // double-word j, byte 4
172105
+               result[0] |= (8*index + 0x5) << 16;   // double-word j, byte 5
172105
+               result[0] |= (8*index + 0x6) << 8;    // double-word j, byte 6
172105
+               result[0] |= (8*index + 0x7) << 0;    // double-word j, byte 7
172105
+            }
172105
+            j++;
172105
+         }
172105
+      }
172105
+   } else if (imm == 0b10) {   //little-endian expansion
172105
+      /* If IMM=0b00010, let pcv be the permute control vector required to
172105
+         enable a right-indexed permute (vpermr or xxpermr) to implement an
172105
+         expansion of the rightmost doubleword elements of a source vector
172105
+         into the doubleword elements of a result vector specified by the
172105
+         doubleword-element mask in VSR[VRB+32].
172105
+       */
172105
+
172105
+      for( index = 0; index < 2; index++) {
172105
+         i = index;
172105
+
172105
+         if ( i == 1) {
172105
+            src = src_hi;
172105
+            half_sel = 0;
172105
+         } else {
172105
+            src = src_lo;
172105
+            half_sel = 1;
172105
+         }
172105
+
172105
+         sel_shift_by = 63;
172105
+
172105
+         if ( ((src >> sel_shift_by) & 0x1) == 1) {
172105
+            result[half_sel] |= (8*j+0) << 0;  // double-word i, byte 0
172105
+            result[half_sel] |= (8*j+1) << 8;  // double-word i, byte 1
172105
+            result[half_sel] |= (8*j+2) << 16; // double-word i, byte 2
172105
+            result[half_sel] |= (8*j+3) << 24; // double-word i, byte 3
172105
+            result[half_sel] |= (8*j+4) << 32; // double-word i, byte 4
172105
+            result[half_sel] |= (8*j+5) << 40; // double-word i, byte 5
172105
+            result[half_sel] |= (8*j+6) << 48; // double-word i, byte 6
172105
+            result[half_sel] |= (8*j+7) << 56; // double-word i, byte 7
172105
+            j++;
172105
+         } else {
172105
+            result[half_sel] |= (8*index + 0x10) << 0;
172105
+            result[half_sel] |= (8*index + 0x11) << 8;
172105
+            result[half_sel] |= (8*index + 0x12) << 16;
172105
+            result[half_sel] |= (8*index + 0x13) << 24;
172105
+            result[half_sel] |= (8*index + 0x14) << 32;
172105
+            result[half_sel] |= (8*index + 0x15) << 40;
172105
+            result[half_sel] |= (8*index + 0x16) << 48;
172105
+            result[half_sel] |= (8*index + 0x17) << 56;
172105
+         }
172105
+      }
172105
+
172105
+   } else if (imm == 0b11) {   //little-endian compression
172105
+      /* If IMM=0b00011, let pcv be the permute control vector required to
172105
+         enable a right-indexed permute (vpermr or xxpermr) to implement a
172105
+         compression of the sparse doubleword elements in a source vector
172105
+         specified by the doubleword-element mask in VSR[VRB+32] into the
172105
+         rightmost doubleword elements of a result vector.  */
172105
+      for( index = 0; index < 2; index++) {
172105
+         i = index;
172105
+
172105
+         if ( i == 1) {
172105
+            src = src_hi;
172105
+            half_sel = 0;
172105
+         } else {
172105
+            src = src_lo;
172105
+            half_sel = 1;
172105
+         }
172105
+
172105
+         sel_shift_by = 63;
172105
+
172105
+         if (((src >> sel_shift_by) & 0x1) == 1) {
172105
+            if (j == 1) {
172105
+               result[0] |= (8*index + 0x0) << 0;    // double-word j, byte 0
172105
+               result[0] |= (8*index + 0x1) << 8;    // double-word j, byte 1
172105
+               result[0] |= (8*index + 0x2) << 16;   // double-word j, byte 2
172105
+               result[0] |= (8*index + 0x3) << 24;   // double-word j, byte 3
172105
+               result[0] |= (8*index + 0x4) << 32;   // double-word j, byte 4
172105
+               result[0] |= (8*index + 0x5) << 40;   // double-word j, byte 5
172105
+               result[0] |= (8*index + 0x6) << 48;   // double-word j, byte 6
172105
+               result[0] |= (8*index + 0x7) << 56;   // double-word j, byte 7
172105
+            } else {
172105
+               result[1] |= (8*index + 0x0) << 0;
172105
+               result[1] |= (8*index + 0x1) << 8;
172105
+               result[1] |= (8*index + 0x2) << 16;
172105
+               result[1] |= (8*index + 0x3) << 24;
172105
+               result[1] |= (8*index + 0x4) << 32;
172105
+               result[1] |= (8*index + 0x5) << 40;
172105
+               result[1] |= (8*index + 0x6) << 48;
172105
+               result[1] |= (8*index + 0x7) << 56;
172105
+            }
172105
+            j++;
172105
+         }
172105
+      }
172105
+   } else {
172105
+      vex_printf("ERROR, vector_gen_pvc_dword_mask_helper, imm value %u not supported.\n",
172105
+                 imm);
172105
+      vassert(0);
172105
+   }
172105
+
172105
+   write_VSX_entry( gst, reg_offset, result);
172105
+}
172105
 
172105
 /*------------------------------------------------*/
172105
 /*---- VSX Matrix signed integer GER functions ---*/
172105
diff --git a/VEX/priv/guest_ppc_toIR.c b/VEX/priv/guest_ppc_toIR.c
172105
index bcabf69dd..354be6b53 100644
172105
--- a/VEX/priv/guest_ppc_toIR.c
172105
+++ b/VEX/priv/guest_ppc_toIR.c
172105
@@ -3322,6 +3322,7 @@ static IRExpr * locate_vector_ele_eq ( IRTemp src, IRExpr *value,
172105
 #define DFORM_IMMASK  0xffffffff
172105
 #define DSFORM_IMMASK 0xfffffffc
172105
 #define DQFORM_IMMASK 0xfffffff0
172105
+#define DA8LSFORM_IMMASK 0x3fffffff   // Algebraic 8LS Dform
172105
 
172105
 #define ISA_3_1_PREFIX_CHECK if (prefix) {if (!allow_isa_3_1) goto decode_noIsa3_1;}
172105
 
172105
@@ -6109,6 +6110,87 @@ static void vsx_matrix_64bit_float_ger ( const VexAbiInfo* vbi,
172105
    stmt( IRStmt_Dirty(d) );
172105
 }
172105
 
172105
+static void vector_gen_pvc_mask ( const VexAbiInfo* vbi,
172105
+                                   IRExpr *src, UInt IMM,
172105
+                                   UInt opc2, UInt VSX_addr ) {
172105
+   /* The function takes a 64-bit source and an immediate value.  The function
172105
+      calls a helper to execute the xxgenpcvbm, xxgenpcvhm, xxgenpcvwm,
172105
+      xxgenpcvdm instruction.  The instructions are not practical to do with
172105
+      Iops.  The instruction is implemented with a dirty helper that
172105
+      calculates the 128-bit result and writes it directly into the guest
172105
+      state VSX register.
172105
+  */
172105
+   IRTemp src_hi = newTemp( Ity_I64);
172105
+   IRTemp src_lo = newTemp( Ity_I64);
172105
+
172105
+   IRDirty* d;
172105
+
172105
+   vassert( (VSX_addr >= 0) && (VSX_addr < 64) );
172105
+   UInt reg_offset = offsetofPPCGuestState( guest_VSR0 )
172105
+      + sizeof(U128) * VSX_addr;
172105
+
172105
+   assign( src_hi, unop( Iop_V128HIto64, src ) );
172105
+   assign( src_lo, unop( Iop_V128to64, src ) );
172105
+
172105
+   IRExpr** args = mkIRExprVec_5(
172105
+      IRExpr_GSPTR(),
172105
+      mkexpr( src_hi ),
172105
+      mkexpr( src_lo ),
172105
+      mkU32( reg_offset ),
172105
+      mkU64( IMM ) );
172105
+
172105
+   switch( opc2 ) {
172105
+   case 0x394: // xxgenpcvbm
172105
+      d = unsafeIRDirty_0_N (
172105
+         0 /*regparms*/,
172105
+         "vector_gen_pvc_byte_mask_dirty_helper",
172105
+         fnptr_to_fnentry( vbi,
172105
+                           &vector_gen_pvc_byte_mask_dirty_helper ),
172105
+         args);
172105
+      break;
172105
+
172105
+   case 0x395: // xxgenpcvhm
172105
+      d = unsafeIRDirty_0_N (
172105
+         0 /*regparms*/,
172105
+         "vector_gen_pvc_hword_mask_dirty_helper",
172105
+         fnptr_to_fnentry( vbi,
172105
+                           &vector_gen_pvc_hword_mask_dirty_helper ),
172105
+         args);
172105
+      break;
172105
+
172105
+   case 0x3B4: // xxgenpcvwm
172105
+      d = unsafeIRDirty_0_N (
172105
+         0 /*regparms*/,
172105
+         "vector_gen_pvc_word_mask_dirty_helper",
172105
+         fnptr_to_fnentry( vbi,
172105
+                           &vector_gen_pvc_word_mask_dirty_helper ),
172105
+         args);
172105
+      break;
172105
+
172105
+   case 0x3B5: // xxgenpcvdm
172105
+      d = unsafeIRDirty_0_N (
172105
+         0 /*regparms*/,
172105
+         "vector_gen_pvc_dword_mask_dirty_helper",
172105
+         fnptr_to_fnentry( vbi,
172105
+                           &vector_gen_pvc_dword_mask_dirty_helper ),
172105
+         args);
172105
+      break;
172105
+   default:
172105
+      vex_printf("ERROR: Unkown instruction = %u in vector_gen_pvc_mask()\n",
172105
+                 opc2);
172105
+      return;
172105
+   }
172105
+
172105
+   d->nFxState = 1;
172105
+   vex_bzero(&d->fxState, sizeof(d->fxState));
172105
+   d->fxState[0].fx     = Ifx_Modify;
172105
+   d->fxState[0].size   = sizeof(U128);
172105
+   d->fxState[0].offset = reg_offset;
172105
+
172105
+   /* execute the dirty call, side-effecting guest state */
172105
+   stmt( IRStmt_Dirty(d) );
172105
+}
172105
+
172105
 static IRExpr * UNSIGNED_CMP_GT_V128 ( IRExpr *vA, IRExpr *vB ) {
172105
    /* This function does an unsigned compare of two V128 values. The
172105
     * function is for use in 32-bit mode only as it is expensive.  The
172105
@@ -35227,6 +35309,54 @@ static Bool dis_vsx_accumulator_prefix ( UInt prefix, UInt theInstr,
172105
    return True;
172105
 }
172105
 
172105
+static Bool dis_vector_generate_pvc_from_mask ( UInt prefix,
172105
+                                                UInt theInstr,
172105
+                                                const VexAbiInfo* vbi )
172105
+{
172105
+   UChar XT_addr = ifieldRegXT(theInstr);
172105
+   UChar vB_addr = ifieldRegB(theInstr);
172105
+   IRTemp vB = newTemp( Ity_V128 );
172105
+   UInt opc2 = ifieldOPClo10(theInstr);
172105
+   UInt IMM = IFIELD(theInstr, (31-15), 5);    // bits[11:15]
172105
+
172105
+   assign( vB, getVReg( vB_addr ) );
172105
+
172105
+   switch( opc2 ) {
172105
+   case 0x394:
172105
+      DIP("xxgenpcvbm v%u,v%u,%u\n", XT_addr, vB_addr, IMM);
172105
+      /* vector_gen_pvc_mask uses a dirty helper to calculate the result and
172105
+         write it to the VSX result register.  */
172105
+      vector_gen_pvc_mask( vbi, mkexpr( vB ), IMM, opc2, XT_addr );
172105
+      break;
172105
+
172105
+   case 0x395:
172105
+      DIP("xxgenpcvhm v%u,v%u,%u\n", XT_addr, vB_addr, IMM);
172105
+      /* vector_gen_pvc_mask uses a dirty helper to calculate the result and
172105
+         write it to the VSX result register.  */
172105
+      vector_gen_pvc_mask( vbi, mkexpr( vB ), IMM, opc2, XT_addr );
172105
+      break;
172105
+
172105
+   case 0x3B4:
172105
+      DIP("xxgenpcvwm v%u,v%u,%u\n", XT_addr, vB_addr, IMM);
172105
+      /* vector_gen_pvc_mask uses a dirty helper to calculate the result and
172105
+         write it to the VSX result register.  */
172105
+      vector_gen_pvc_mask( vbi, mkexpr( vB ), IMM, opc2, XT_addr );
172105
+      break;
172105
+
172105
+   case 0x3B5:
172105
+      DIP("xxgenpcvdm v%u,v%u,%u\n", XT_addr, vB_addr, IMM);
172105
+      /* vector_gen_pvc_mask uses a dirty helper to calculate the result and
172105
+         write it to the VSX result register.  */
172105
+      vector_gen_pvc_mask( vbi, mkexpr( vB ), IMM, opc2, XT_addr );
172105
+      break;
172105
+
172105
+   default:
172105
+      return False;
172105
+   }
172105
+
172105
+   return True;
172105
+}
172105
+
172105
 static Int dis_nop_prefix ( UInt prefix, UInt theInstr )
172105
 {
172105
    Bool is_prefix   = prefix_instruction( prefix );
172105
@@ -35748,14 +35878,9 @@ DisResult disInstr_PPC_WRK (
172105
       }
172105
       goto decode_failure;
172105
 
172105
-   case 0x31:   // lfsu, stxv
172105
+   case 0x31:   // lfsu
172105
       if (!allow_F) goto decode_noF;
172105
-      if (prefix_instruction( prefix )) {  // stxv
172105
-         if ( !(allow_isa_3_1) ) goto decode_noIsa3_1;
172105
-         if (dis_fp_pair_prefix( prefix, theInstr )) goto decode_success;
172105
-      } else {  // lfsu
172105
-         if (dis_fp_load( prefix, theInstr )) goto decode_success;
172105
-      }
172105
+      if (dis_fp_load( prefix, theInstr )) goto decode_success;
172105
       goto decode_failure;
172105
 
172105
    case 0x32:
172105
@@ -35842,7 +35967,6 @@ DisResult disInstr_PPC_WRK (
172105
    case 0x39:  // pld, lxsd, lxssp, lfdp
172105
       {
172105
          UInt opc2tmp = ifieldOPC0o2(theInstr);
172105
-
172105
          if (!allow_F) goto decode_noF;
172105
          if (prefix_instruction( prefix )) {   // pld
172105
             if ( !(allow_isa_3_1) ) goto decode_noIsa3_1;
172105
@@ -36125,12 +36249,6 @@ DisResult disInstr_PPC_WRK (
172105
             goto decode_failure;
172105
       }
172105
 
172105
-      /* The vsxOpc2 returned is the "normalized" value, representing the
172105
-       * instructions secondary opcode as taken from the standard secondary
172105
-       * opcode field [21:30] (IBM notatition), even if the actual field
172105
-       * is non-standard.  These normalized values are given in the opcode
172105
-       * appendices of the ISA 2.06 document.
172105
-       */
172105
       if ( ( opc2 == 0x168 ) && ( IFIELD( theInstr, 19, 2 ) == 0 ) )// xxspltib
172105
       {
172105
          /* This is a special case of the XX1 form where the  RA, RB
172105
@@ -36153,6 +36271,23 @@ DisResult disInstr_PPC_WRK (
172105
          goto decode_failure;
172105
       }
172105
 
172105
+      if ( ( opc2 == 0x394 ) ||         // xxgenpcvbm
172105
+           ( opc2 == 0x395 ) ||         // xxgenpcvwm
172105
+           ( opc2 == 0x3B4 ) ||         // xxgenpcvhm
172105
+           ( opc2 == 0x3B5 ) ) {        // xxgenpcvdm
172105
+         if ( !(allow_isa_3_1) ) goto decode_noIsa3_1;
172105
+         if (dis_vector_generate_pvc_from_mask( prefix, theInstr,
172105
+                                                abiinfo ))
172105
+            goto decode_success;
172105
+         goto decode_failure;
172105
+      }
172105
+
172105
+      /* The vsxOpc2 returned is the "normalized" value, representing the
172105
+       * instructions secondary opcode as taken from the standard secondary
172105
+       * opcode field [21:30] (IBM notatition), even if the actual field
172105
+       * is non-standard.  These normalized values are given in the opcode
172105
+       * appendices of the ISA 2.06 document.
172105
+       */
172105
       vsxOpc2 = get_VSX60_opc2(opc2, theInstr);
172105
 
172105
       switch (vsxOpc2) {
172105
commit 078f89e99b6f62e043f6138c6a7ae238befc1f2a
172105
Author: Carl Love <cel@us.ibm.com>
172105
Date:   Fri Feb 26 15:46:55 2021 -0600
172105
172105
    PPC64: Reduced-Precision - bfloat16 Outer Product & Format Conversion Operations
172105
    
172105
    Add support for:
172105
    
172105
    pmxvbf16ger2 Prefixed Masked VSX Vector bfloat16 GER (Rank-2 Update)
172105
    pmxvbf16ger2pp Prefixed Masked VSX Vector bfloat16 GER (Rank-2 Update) Positive
172105
      multiply, Positive accumulate
172105
    pmxvbf16ger2pn Prefixed Masked VSX Vector bfloat16 GER (Rank-2 Update) Positive
172105
      multiply, Negative accumulate
172105
    pmxvbf16ger2np Prefixed Masked VSX Vector bfloat16 GER (Rank-2 Update) Negative
172105
      multiply, Positive accumulate
172105
    pmxvbf16ger2nn Prefixed Masked VSX Vector bfloat16 GER (Rank-2 Update) Negative
172105
      multiply, Negative accumulate
172105
    xvbf16ger2VSX Vector bfloat16 GER (Rank-2 Update)
172105
    xvbf16ger2pp VSX Vector bfloat16 GER (Rank-2 Update) Positive multiply, Positive
172105
      accumulate
172105
    xvbf16ger2pn VSX Vector bfloat16 GER (Rank-2 Update) Positive multiply, Negative
172105
      accumulate
172105
    xvbf16ger2np VSX Vector bfloat16 GER (Rank-2 Update) Negative multiply, Positive
172105
      accumulate
172105
    xvbf16ger2nn VSX Vector bfloat16 GER (Rank-2 Update) Negative multiply, Negative
172105
      accumulate
172105
    xvcvbf16sp VSX Vector Convert bfloat16 to Single-Precision format
172105
    xvcvspbf16 VSX Vector Convert with round Single-Precision to bfloat16 format
172105
172105
diff --git a/VEX/priv/guest_ppc_defs.h b/VEX/priv/guest_ppc_defs.h
172105
index 54ce923a9..d36d6c07d 100644
172105
--- a/VEX/priv/guest_ppc_defs.h
172105
+++ b/VEX/priv/guest_ppc_defs.h
172105
@@ -150,6 +150,8 @@ extern ULong convert_to_zoned_helper( ULong src_hi, ULong src_low,
172105
                                       ULong return_upper );
172105
 extern ULong convert_to_national_helper( ULong src, ULong return_upper );
172105
 extern ULong convert_from_zoned_helper( ULong src_hi, ULong src_low );
172105
+extern ULong convert_from_floattobf16_helper( ULong src );
172105
+extern ULong convert_from_bf16tofloat_helper( ULong src );
172105
 extern ULong convert_from_national_helper( ULong src_hi, ULong src_low );
172105
 extern ULong generate_C_FPCC_helper( ULong size, ULong src_hi, ULong src );
172105
 extern ULong extract_bits_under_mask_helper( ULong src, ULong mask,
172105
@@ -201,6 +203,11 @@ extern void vector_gen_pvc_dword_mask_dirty_helper( VexGuestPPC64State* gst,
172105
 #define XVF16GER2PN    0b10010010
172105
 #define XVF16GER2NP    0b01010010
172105
 #define XVF16GER2NN    0b11010010
172105
+#define XVBF16GER2     0b00110011
172105
+#define XVBF16GER2PP   0b00110010
172105
+#define XVBF16GER2PN   0b10110010
172105
+#define XVBF16GER2NP   0b01110010
172105
+#define XVBF16GER2NN   0b11110010
172105
 #define XVF32GER       0b00011011
172105
 #define XVF32GERPP     0b00011010
172105
 #define XVF32GERPN     0b10011010
172105
diff --git a/VEX/priv/guest_ppc_helpers.c b/VEX/priv/guest_ppc_helpers.c
172105
index 75497abb9..6bcee966d 100644
172105
--- a/VEX/priv/guest_ppc_helpers.c
172105
+++ b/VEX/priv/guest_ppc_helpers.c
172105
@@ -1905,6 +1905,125 @@ static Double conv_f16_to_double( ULong input )
172105
 #  endif
172105
 }
172105
 
172105
+#define BF16_SIGN_MASK   0x8000
172105
+#define BF16_EXP_MASK    0x7F80
172105
+#define BF16_FRAC_MASK   0x007F
172105
+#define BF16_BIAS        127
172105
+#define BF16_MAX_UNBIASED_EXP 127
172105
+#define BF16_MIN_UNBIASED_EXP -126
172105
+#define FLOAT_SIGN_MASK  0x80000000
172105
+#define FLOAT_EXP_MASK   0x7F800000
172105
+#define FLOAT_FRAC_MASK  0x007FFFFF
172105
+#define FLOAT_FRAC_BIT8  0x00008000
172105
+#define FLOAT_BIAS       127
172105
+
172105
+static Float conv_bf16_to_float( UInt input )
172105
+{
172105
+  /* input is 16-bit bfloat.
172105
+     bias +127, exponent 8-bits, fraction 7-bits
172105
+
172105
+     output is 32-bit float.
172105
+     bias +127, exponent 8-bits, fraction 22-bits
172105
+  */
172105
+
172105
+  UInt input_exp, input_fraction, unbiased_exp;
172105
+  UInt output_exp, output_fraction;
172105
+  UInt sign;
172105
+  union convert_t conv;
172105
+
172105
+  sign = (UInt)(input & BF16_SIGN_MASK);
172105
+  input_exp = input & BF16_EXP_MASK;
172105
+  unbiased_exp = (input_exp >> 7) - (UInt)BF16_BIAS;
172105
+  input_fraction = input & BF16_FRAC_MASK;
172105
+
172105
+  if (((input_exp & BF16_EXP_MASK) == BF16_EXP_MASK) &&
172105
+      (input_fraction != 0)) {
172105
+     /* input is NaN or SNaN, exp all 1's, fraction != 0 */
172105
+     output_exp = FLOAT_EXP_MASK;
172105
+     output_fraction = input_fraction;
172105
+
172105
+  } else if(((input_exp & BF16_EXP_MASK) == BF16_EXP_MASK) &&
172105
+      ( input_fraction == 0)) {
172105
+     /* input is infinity,  exp all 1's, fraction = 0  */
172105
+     output_exp = FLOAT_EXP_MASK;
172105
+     output_fraction = 0;
172105
+
172105
+  } else if((input_exp == 0) && (input_fraction == 0)) {
172105
+     /* input is zero */
172105
+     output_exp = 0;
172105
+     output_fraction = 0;
172105
+
172105
+  } else if((input_exp == 0) && (input_fraction != 0)) {
172105
+     /* input is denormal */
172105
+     output_fraction = input_fraction;
172105
+     output_exp = (-(Int)BF16_BIAS + (Int)FLOAT_BIAS ) << 23;
172105
+
172105
+  } else {
172105
+     /* result is normal */
172105
+     output_exp = (unbiased_exp + FLOAT_BIAS) << 23;
172105
+     output_fraction = input_fraction;
172105
+  }
172105
+
172105
+  conv.u32 = sign << (31 - 15) | output_exp | (output_fraction << (23-7));
172105
+  return conv.f;
172105
+}
172105
+
172105
+static UInt conv_float_to_bf16( UInt input )
172105
+{
172105
+   /* input is 32-bit float stored as unsigned 32-bit.
172105
+      bias +127, exponent 8-bits, fraction 23-bits
172105
+
172105
+      output is 16-bit bfloat.
172105
+      bias +127, exponent 8-bits, fraction 7-bits
172105
+
172105
+      If the unbiased exponent of the input is greater than the max floating
172105
+      point unbiased exponent value, the result of the floating point 16-bit
172105
+      value is infinity.
172105
+   */
172105
+
172105
+   UInt input_exp, input_fraction;
172105
+   UInt output_exp, output_fraction;
172105
+   UInt result, sign;
172105
+
172105
+   sign = input & FLOAT_SIGN_MASK;
172105
+   input_exp = input & FLOAT_EXP_MASK;
172105
+   input_fraction = input & FLOAT_FRAC_MASK;
172105
+
172105
+   if (((input_exp & FLOAT_EXP_MASK) == FLOAT_EXP_MASK) &&
172105
+       (input_fraction != 0)) {
172105
+      /* input is NaN or SNaN, exp all 1's, fraction != 0 */
172105
+      output_exp = BF16_EXP_MASK;
172105
+      output_fraction = (ULong)input_fraction >> (23 - 7);
172105
+   } else if (((input_exp & FLOAT_EXP_MASK) == FLOAT_EXP_MASK) &&
172105
+              ( input_fraction == 0)) {
172105
+      /* input is infinity,  exp all 1's, fraction = 0  */
172105
+      output_exp = BF16_EXP_MASK;
172105
+      output_fraction = 0;
172105
+   } else if ((input_exp == 0) && (input_fraction == 0)) {
172105
+      /* input is zero */
172105
+      output_exp = 0;
172105
+      output_fraction = 0;
172105
+   } else if ((input_exp == 0) && (input_fraction != 0)) {
172105
+      /* input is denormal */
172105
+      output_exp = 0;
172105
+      output_fraction = (ULong)input_fraction >> (23 - 7);
172105
+   } else {
172105
+      /* result is normal */
172105
+      output_exp = (input_exp - BF16_BIAS + FLOAT_BIAS) >> (23 - 7);
172105
+      output_fraction = (ULong)input_fraction >> (23 - 7);
172105
+
172105
+      /* Round result. Look at the 8th bit position of the 32-bit floating
172105
+         pointt fraction.  The F16 fraction is only 7 bits wide so if the 8th
172105
+         bit of the F32 is a 1 we need to round up by adding 1 to the output
172105
+         fraction.  */
172105
+      if ((input_fraction & FLOAT_FRAC_BIT8) == FLOAT_FRAC_BIT8)
172105
+         /* Round the F16 fraction up by 1 */
172105
+         output_fraction = output_fraction + 1;
172105
+   }
172105
+
172105
+   result = sign >> (31 - 15) | output_exp | output_fraction;
172105
+   return result;
172105
+}
172105
 
172105
 static Float conv_double_to_float( Double src )
172105
 {
172105
@@ -1942,6 +2061,36 @@ static Float negate_float( Float input )
172105
       return -input;
172105
 }
172105
 
172105
+/* This C-helper takes a vector of two 32-bit floating point values
172105
+ * and returns a vector containing two 16-bit bfloats.
172105
+   input:    word0           word1
172105
+   output  0x0   hword1   0x0    hword3
172105
+   Called from generated code.
172105
+ */
172105
+ULong convert_from_floattobf16_helper( ULong src ) {
172105
+   ULong resultHi, resultLo;
172105
+
172105
+   resultHi = (ULong)conv_float_to_bf16( (UInt)(src >> 32));
172105
+   resultLo = (ULong)conv_float_to_bf16( (UInt)(src & 0xFFFFFFFF));
172105
+   return (resultHi << 32) | resultLo;
172105
+
172105
+}
172105
+
172105
+/* This C-helper takes a vector of two 16-bit bfloating point values
172105
+ * and returns a vector containing one 32-bit float.
172105
+   input:   0x0   hword1   0x0    hword3
172105
+   output:    word0           word1
172105
+ */
172105
+ULong convert_from_bf16tofloat_helper( ULong src ) {
172105
+   ULong result;
172105
+   union convert_t conv;
172105
+   conv.f = conv_bf16_to_float( (UInt)(src >> 32) );
172105
+   result = (ULong) conv.u32;
172105
+   conv.f = conv_bf16_to_float( (UInt)(src & 0xFFFFFFFF));
172105
+   result = (result << 32) | (ULong) conv.u32;
172105
+   return result;
172105
+ }
172105
+
172105
 void vsx_matrix_16bit_float_ger_dirty_helper( VexGuestPPC64State* gst,
172105
                                               UInt offset_ACC,
172105
                                               ULong srcA_hi, ULong srcA_lo,
172105
@@ -2002,24 +2151,44 @@ void vsx_matrix_16bit_float_ger_dirty_helper( VexGuestPPC64State* gst,
172105
          srcB_word[0][j] = (UInt)((srcB_lo >> (16-16*j)) & mask);
172105
       }
172105
 
172105
+      /* Note the isa is not consistent in the src naming.  Will use the
172105
+         naming src10, src11, src20, src21 used with xvf16ger2 instructions.
172105
+      */
172105
       for( j = 0; j < 4; j++) {
172105
          if (((pmsk >> 1) & 0x1) == 0) {
172105
             src10 = 0;
172105
             src20 = 0;
172105
          } else {
172105
-            src10 = conv_f16_to_double((ULong)srcA_word[i][0]);
172105
-            src20 = conv_f16_to_double((ULong)srcB_word[j][0]);
172105
+            if (( inst  == XVF16GER2 ) || ( inst  == XVF16GER2PP )
172105
+                || ( inst == XVF16GER2PN ) || ( inst  == XVF16GER2NP )
172105
+                || ( inst == XVF16GER2NN )) {
172105
+               src10 = conv_f16_to_double((ULong)srcA_word[i][0]);
172105
+               src20 = conv_f16_to_double((ULong)srcB_word[j][0]);
172105
+            } else {
172105
+               /* Input is in bfloat format, result is stored in the
172105
+                  "traditional" 64-bit float format. */
172105
+               src10 = (double)conv_bf16_to_float((ULong)srcA_word[i][0]);
172105
+               src20 = (double)conv_bf16_to_float((ULong)srcB_word[j][0]);
172105
+            }
172105
          }
172105
 
172105
          if ((pmsk & 0x1) == 0) {
172105
             src11 = 0;
172105
             src21 = 0;
172105
          } else {
172105
-            src11 = conv_f16_to_double((ULong)srcA_word[i][1]);
172105
-            src21 = conv_f16_to_double((ULong)srcB_word[j][1]);
172105
+            if (( inst  == XVF16GER2 ) || ( inst  == XVF16GER2PP )
172105
+                || ( inst == XVF16GER2PN ) || ( inst  == XVF16GER2NP )
172105
+                || ( inst == XVF16GER2NN )) {
172105
+               src11 = conv_f16_to_double((ULong)srcA_word[i][1]);
172105
+               src21 = conv_f16_to_double((ULong)srcB_word[j][1]);
172105
+            } else {
172105
+               /* Input is in bfloat format, result is stored in the
172105
+                  "traditional" 64-bit float format. */
172105
+               src11 = (double)conv_bf16_to_float((ULong)srcA_word[i][1]);
172105
+               src21 = (double)conv_bf16_to_float((ULong)srcB_word[j][1]);
172105
+            }
172105
          }
172105
 
172105
-
172105
          prod = src10 * src20;
172105
          msum = prod + src11 * src21;
172105
 
172105
@@ -2027,26 +2196,26 @@ void vsx_matrix_16bit_float_ger_dirty_helper( VexGuestPPC64State* gst,
172105
             /* Note, we do not track the exception handling bits
172105
                ox, ux, xx, si, mz, vxsnan and vximz in the FPSCR.  */
172105
 
172105
-            if ( inst == XVF16GER2 )
172105
+            if (( inst == XVF16GER2 ) || ( inst == XVBF16GER2 ) )
172105
                result[j] = reinterpret_float_as_int(
172105
                   conv_double_to_float(msum) );
172105
 
172105
-            else if ( inst == XVF16GER2PP )
172105
+            else if (( inst == XVF16GER2PP ) ||  (inst == XVBF16GER2PP ))
172105
                result[j] = reinterpret_float_as_int(
172105
                   conv_double_to_float(msum)
172105
                   + acc_word[j] );
172105
 
172105
-            else if ( inst == XVF16GER2PN )
172105
+            else if (( inst == XVF16GER2PN ) || ( inst == XVBF16GER2PN ))
172105
                result[j] = reinterpret_float_as_int(
172105
                   conv_double_to_float(msum)
172105
                   + negate_float( acc_word[j] ) );
172105
 
172105
-            else if ( inst == XVF16GER2NP )
172105
+            else if (( inst == XVF16GER2NP ) || ( inst == XVBF16GER2NP ))
172105
                result[j] = reinterpret_float_as_int(
172105
                   conv_double_to_float( negate_double( msum ) )
172105
                   + acc_word[j] );
172105
 
172105
-            else if ( inst == XVF16GER2NN )
172105
+            else if (( inst == XVF16GER2NN ) || ( inst == XVBF16GER2NN ))
172105
                result[j] = reinterpret_float_as_int(
172105
                   conv_double_to_float( negate_double( msum ) )
172105
                   + negate_float( acc_word[j] ) );
172105
diff --git a/VEX/priv/guest_ppc_toIR.c b/VEX/priv/guest_ppc_toIR.c
172105
index 354be6b53..20553a539 100644
172105
--- a/VEX/priv/guest_ppc_toIR.c
172105
+++ b/VEX/priv/guest_ppc_toIR.c
172105
@@ -5688,6 +5688,57 @@ static IRExpr * convert_from_national ( const VexAbiInfo* vbi, IRExpr *src ) {
172105
    return mkexpr( result );
172105
 }
172105
 
172105
+static IRExpr * vector_convert_floattobf16 ( const VexAbiInfo* vbi,
172105
+                                             IRExpr *src ) {
172105
+   /* The function takes 128-bit value containing four 32-bit floats and
172105
+      returns a 128-bit value containint four 16-bit bfloats in the lower
172105
+      halfwords. */
172105
+
172105
+   IRTemp resultHi = newTemp( Ity_I64);
172105
+   IRTemp resultLo = newTemp( Ity_I64);
172105
+
172105
+   assign( resultHi,
172105
+           mkIRExprCCall( Ity_I64, 0 /*regparms*/,
172105
+                          "vector_convert_floattobf16_helper",
172105
+                          fnptr_to_fnentry( vbi,
172105
+                                            &convert_from_floattobf16_helper ),
172105
+                          mkIRExprVec_1( unop( Iop_V128HIto64, src ) ) ) );
172105
+
172105
+   assign( resultLo,
172105
+           mkIRExprCCall( Ity_I64, 0 /*regparms*/,
172105
+                          "vector_convert_floattobf16_helper",
172105
+                          fnptr_to_fnentry( vbi,
172105
+                                            &convert_from_floattobf16_helper ),
172105
+                          mkIRExprVec_1( unop( Iop_V128to64, src ) ) ) );
172105
+
172105
+   return binop( Iop_64HLtoV128, mkexpr( resultHi ), mkexpr( resultLo ) );
172105
+}
172105
+
172105
+static IRExpr * vector_convert_bf16tofloat ( const VexAbiInfo* vbi,
172105
+                                             IRExpr *src ) {
172105
+   /* The function takes 128-bit value containing four 16-bit bfloats in
172105
+      the lower halfwords and returns a 128-bit value containint four
172105
+      32-bit floats. */
172105
+   IRTemp resultHi = newTemp( Ity_I64);
172105
+   IRTemp resultLo = newTemp( Ity_I64);
172105
+
172105
+   assign( resultHi,
172105
+           mkIRExprCCall( Ity_I64, 0 /*regparms*/,
172105
+                          "vector_convert_bf16tofloat_helper",
172105
+                          fnptr_to_fnentry( vbi,
172105
+                                            &convert_from_bf16tofloat_helper ),
172105
+                          mkIRExprVec_1( unop( Iop_V128HIto64, src ) ) ) );
172105
+
172105
+   assign( resultLo,
172105
+           mkIRExprCCall( Ity_I64, 0 /*regparms*/,
172105
+                          "vector_convert_bf16tofloat_helper",
172105
+                          fnptr_to_fnentry( vbi,
172105
+                                            &convert_from_bf16tofloat_helper ),
172105
+                          mkIRExprVec_1( unop( Iop_V128to64, src ) ) ) );
172105
+
172105
+   return binop( Iop_64HLtoV128, mkexpr( resultHi ), mkexpr( resultLo ) );
172105
+}
172105
+
172105
 static IRExpr * popcnt64 ( const VexAbiInfo* vbi,
172105
                            IRExpr *src ){
172105
    /* The function takes a 64-bit source and counts the number of bits in the
172105
@@ -5936,6 +5987,7 @@ static void vsx_matrix_ger ( const VexAbiInfo* vbi,
172105
    case XVI16GER2:
172105
    case XVI16GER2S:
172105
    case XVF16GER2:
172105
+   case XVBF16GER2:
172105
    case XVF32GER:
172105
          AT_fx = Ifx_Write;
172105
          break;
172105
@@ -5943,6 +5995,10 @@ static void vsx_matrix_ger ( const VexAbiInfo* vbi,
172105
    case XVI8GER4PP:
172105
    case XVI16GER2PP:
172105
    case XVI16GER2SPP:
172105
+   case XVBF16GER2PP:
172105
+   case XVBF16GER2PN:
172105
+   case XVBF16GER2NP:
172105
+   case XVBF16GER2NN:
172105
    case XVF16GER2PP:
172105
    case XVF16GER2PN:
172105
    case XVF16GER2NP:
172105
@@ -23899,6 +23955,24 @@ dis_vxs_misc( UInt prefix, UInt theInstr, const VexAbiInfo* vbi, UInt opc2,
172105
                                     mkexpr( sub_element1 ),
172105
                                     mkexpr( sub_element0 ) ) ) );
172105
 
172105
+         } else if ((inst_select == 16) && !prefix) {
172105
+            IRTemp result = newTemp(Ity_V128);
172105
+            UChar xT_addr = ifieldRegXT ( theInstr );
172105
+            UChar xB_addr = ifieldRegXB ( theInstr );
172105
+            /* Convert 16-bit bfloat to 32-bit float, not a prefix inst */
172105
+            DIP("xvcvbf16sp v%u,v%u\n", xT_addr, xB_addr);
172105
+            assign( result, vector_convert_bf16tofloat( vbi, mkexpr( vB ) ) );
172105
+            putVSReg( XT, mkexpr( result) );
172105
+
172105
+         } else if ((inst_select == 17) && !prefix) {
172105
+            IRTemp result = newTemp(Ity_V128);
172105
+            UChar xT_addr = ifieldRegXT ( theInstr );
172105
+            UChar xB_addr = ifieldRegXB ( theInstr );
172105
+            /* Convert 32-bit float to 16-bit bfloat, not a prefix inst */
172105
+            DIP("xvcvspbf16 v%u,v%u\n", xT_addr, xB_addr);
172105
+            assign( result, vector_convert_floattobf16( vbi, mkexpr( vB ) ) );
172105
+            putVSReg( XT, mkexpr( result) );
172105
+
172105
          } else if (inst_select == 23) {
172105
             DIP("xxbrd v%u, v%u\n", (UInt)XT, (UInt)XB);
172105
 
172105
@@ -34956,6 +35030,41 @@ static Bool dis_vsx_accumulator_prefix ( UInt prefix, UInt theInstr,
172105
                          getVSReg( rB_addr ), AT,
172105
                          ( ( inst_prefix << 8 ) | XO ) );
172105
          break;
172105
+      case XVBF16GER2:
172105
+         DIP("xvbf16ger2 %u,r%u, r%u\n", AT, rA_addr, rB_addr);
172105
+         vsx_matrix_ger( vbi, MATRIX_16BIT_FLOAT_GER,
172105
+                         getVSReg( rA_addr ),
172105
+                         getVSReg( rB_addr ), AT,
172105
+                         ( ( inst_prefix << 8 ) | XO ) );
172105
+         break;
172105
+      case XVBF16GER2PP:
172105
+         DIP("xvbf16ger2pp %u,r%u, r%u\n", AT, rA_addr, rB_addr);
172105
+         vsx_matrix_ger( vbi, MATRIX_16BIT_FLOAT_GER,
172105
+                         getVSReg( rA_addr ),
172105
+                         getVSReg( rB_addr ), AT,
172105
+                         ( ( inst_prefix << 8 ) | XO ) );
172105
+         break;
172105
+      case XVBF16GER2PN:
172105
+         DIP("xvbf16ger2pn %u,r%u, r%u\n", AT, rA_addr, rB_addr);
172105
+         vsx_matrix_ger( vbi, MATRIX_16BIT_FLOAT_GER,
172105
+                         getVSReg( rA_addr ),
172105
+                         getVSReg( rB_addr ), AT,
172105
+                         ( ( inst_prefix << 8 ) | XO ) );
172105
+         break;
172105
+      case XVBF16GER2NP:
172105
+         DIP("xvbf16ger2np %u,r%u, r%u\n", AT, rA_addr, rB_addr);
172105
+         vsx_matrix_ger( vbi, MATRIX_16BIT_FLOAT_GER,
172105
+                         getVSReg( rA_addr ),
172105
+                         getVSReg( rB_addr ), AT,
172105
+                         ( ( inst_prefix << 8 ) | XO ) );
172105
+         break;
172105
+      case XVBF16GER2NN:
172105
+         DIP("xvbf16ger2nn %u,r%u, r%u\n", AT, rA_addr, rB_addr);
172105
+         vsx_matrix_ger( vbi, MATRIX_16BIT_FLOAT_GER,
172105
+                         getVSReg( rA_addr ),
172105
+                         getVSReg( rB_addr ), AT,
172105
+                         ( ( inst_prefix << 8 ) | XO ) );
172105
+         break;
172105
       case XVF32GER:
172105
          DIP("xvf32ger %u,r%u, r%u\n", AT, rA_addr, rB_addr);
172105
          vsx_matrix_ger( vbi, MATRIX_32BIT_FLOAT_GER,
172105
@@ -35106,6 +35215,61 @@ static Bool dis_vsx_accumulator_prefix ( UInt prefix, UInt theInstr,
172105
                          AT,
172105
                          ( (MASKS << 9 ) | ( inst_prefix << 8 ) | XO ) );
172105
          break;
172105
+      case XVBF16GER2:
172105
+         PMSK = IFIELD( prefix, 14, 2);
172105
+         XMSK = IFIELD( prefix, 4, 4);
172105
+         YMSK = IFIELD( prefix, 0, 4);
172105
+         DIP("pmxvbf16ger2 %u,r%u, r%u\n", AT, rA_addr, rB_addr);
172105
+         vsx_matrix_ger( vbi, MATRIX_16BIT_FLOAT_GER,
172105
+                         getVSReg( rA_addr ),
172105
+                         getVSReg( rB_addr ),
172105
+                         AT, ( (MASKS << 9 )
172105
+                               | ( inst_prefix << 8 ) | XO ) );
172105
+         break;
172105
+      case XVBF16GER2PP:
172105
+         PMSK = IFIELD( prefix, 14, 2);
172105
+         XMSK = IFIELD( prefix, 4, 4);
172105
+         YMSK = IFIELD( prefix, 0, 4);
172105
+         DIP("pmxvbf16ger2pp %u,r%u, r%u\n", AT, rA_addr, rB_addr);
172105
+         vsx_matrix_ger( vbi, MATRIX_16BIT_FLOAT_GER,
172105
+                         getVSReg( rA_addr ),
172105
+                         getVSReg( rB_addr ),
172105
+                         AT, ( (MASKS << 9 )
172105
+                               | ( inst_prefix << 8 ) | XO ) );
172105
+         break;
172105
+      case XVBF16GER2PN:
172105
+         PMSK = IFIELD( prefix, 14, 2);
172105
+         XMSK = IFIELD( prefix, 4, 4);
172105
+         YMSK = IFIELD( prefix, 0, 4);
172105
+         DIP("pmxvbf16ger2pn %u,r%u, r%u\n", AT, rA_addr, rB_addr);
172105
+         vsx_matrix_ger( vbi, MATRIX_16BIT_FLOAT_GER,
172105
+                         getVSReg( rA_addr ),
172105
+                         getVSReg( rB_addr ),
172105
+                         AT, ( (MASKS << 9 )
172105
+                               | ( inst_prefix << 8 ) | XO ) );
172105
+         break;
172105
+      case XVBF16GER2NP:
172105
+         PMSK = IFIELD( prefix, 14, 2);
172105
+         XMSK = IFIELD( prefix, 4, 4);
172105
+         YMSK = IFIELD( prefix, 0, 4);
172105
+         DIP("pmxvbf16ger2np %u,r%u, r%u\n", AT, rA_addr, rB_addr);
172105
+         vsx_matrix_ger( vbi, MATRIX_16BIT_FLOAT_GER,
172105
+                         getVSReg( rA_addr ),
172105
+                         getVSReg( rB_addr ),
172105
+                         AT, ( (MASKS << 9 )
172105
+                               | ( inst_prefix << 8 ) | XO ) );
172105
+         break;
172105
+      case XVBF16GER2NN:
172105
+         PMSK = IFIELD( prefix, 14, 2);
172105
+         XMSK = IFIELD( prefix, 4, 4);
172105
+         YMSK = IFIELD( prefix, 0, 4);
172105
+         DIP("pmxvbf16ger2nn %u,r%u, r%u\n", AT, rA_addr, rB_addr);
172105
+         vsx_matrix_ger( vbi, MATRIX_16BIT_FLOAT_GER,
172105
+                         getVSReg( rA_addr ),
172105
+                         getVSReg( rB_addr ),
172105
+                         AT, ( (MASKS << 9 )
172105
+                               | ( inst_prefix << 8 ) | XO ) );
172105
+         break;
172105
       case XVF16GER2:
172105
          PMSK = IFIELD( prefix, 14, 2);
172105
          XMSK = IFIELD( prefix, 4, 4);
172105
@@ -36181,6 +36345,11 @@ DisResult disInstr_PPC_WRK (
172105
              (opc2 == XVI4GER8PP)     ||       // xvi4ger8pp
172105
              (opc2 == XVI8GER4)       ||       // xvi8ger4
172105
              (opc2 == XVI8GER4PP)     ||       // xvi8ger4pp
172105
+             (opc2 == XVBF16GER2)     ||       // xvbf16ger2
172105
+             (opc2 == XVBF16GER2PP)   ||       // xvbf16ger2pp
172105
+             (opc2 == XVBF16GER2PN)   ||       // xvbf16ger2pn
172105
+             (opc2 == XVBF16GER2NP)   ||       // xvbf16ger2np
172105
+             (opc2 == XVBF16GER2NN)   ||       // xvbf16ger2nn
172105
              (opc2 == XVF16GER2)      ||       // xvf16ger2
172105
              (opc2 == XVF16GER2PP)    ||       // xvf16ger2pp
172105
              (opc2 == XVF16GER2PN)    ||       // xvf16ger2pn
172105
commit e09fdaf569b975717465ed8043820d0198d4d47d
172105
Author: Carl Love <cel@us.ibm.com>
172105
Date:   Fri Feb 26 16:05:12 2021 -0600
172105
172105
    PPC64: Reduced-Precision: Missing Integer-based Outer Product Operations
172105
    
172105
    Add support for:
172105
    
172105
    pmxvi16ger2 VSX Vector 16-bit Signed Integer GER (rank-2 update), Prefixed
172105
       Masked
172105
    pmxvi16ger2pp VSX Vector 16-bit Signed Integer GER (rank-2 update) (Positive
172105
       multiply, Positive accumulate), Prefixed Masked
172105
    pmxvi8ger4spp VSX Vector 8-bit Signed/Unsigned Integer GER (rank-4 update) with
172105
       Saturation (Positive multiply, Positive accumulate), Prefixed Masked
172105
    xvi16ger2 VSX Vector 16-bit Signed Integer GER (rank-2 update)
172105
    xvi16ger2pp VSX Vector 16-bit Signed Integer GER (rank-2 update) (Positive
172105
       multiply, Positive accumulate)
172105
    xvi8ger4spp VSX Vector 8-bit Signed/Unsigned Integer GER (rank-4 update) with
172105
       Saturation (Positive multiply, Positive accumulate)
172105
172105
diff --git a/VEX/priv/guest_ppc_helpers.c b/VEX/priv/guest_ppc_helpers.c
172105
index 6bcee966d..d8131eb60 100644
172105
--- a/VEX/priv/guest_ppc_helpers.c
172105
+++ b/VEX/priv/guest_ppc_helpers.c
172105
@@ -1446,16 +1446,16 @@ static UInt exts4( UInt src)
172105
       return src & 0xF;        /* make sure high order bits are zero */
172105
 }
172105
 
172105
-static UInt exts8( UInt src)
172105
+static ULong exts8( UInt src)
172105
 {
172105
-   /* Input is an 8-bit value.  Extend bit 7 to bits [31:8] */
172105
+   /* Input is an 8-bit value.  Extend bit 7 to bits [63:8] */
172105
    if (( src >> 7 ) & 0x1)
172105
-      return src | 0xFFFFFF00; /* sign bit is a 1, extend */
172105
+      return src | 0xFFFFFFFFFFFFFF00ULL; /* sign bit is a 1, extend */
172105
    else
172105
       return src & 0xFF;        /* make sure high order bits are zero */
172105
 }
172105
 
172105
-static UInt extz8( UInt src)
172105
+static ULong extz8( UInt src)
172105
 {
172105
    /* Input is an 8-bit value.  Extend src on the left with zeros.  */
172105
    return src & 0xFF;        /* make sure high order bits are zero */
172105
@@ -1662,12 +1662,12 @@ void vsx_matrix_8bit_ger_dirty_helper( VexGuestPPC64State* gst,
172105
                                        ULong srcB_hi, ULong srcB_lo,
172105
                                        UInt masks_inst )
172105
 {
172105
-   UInt i, j, mask, sum, inst, acc_entry, prefix_inst;
172105
+   UInt i, j, mask, inst, acc_entry, prefix_inst;
172105
 
172105
    UInt srcA_bytes[4][4];   /* word, byte */
172105
    UInt srcB_bytes[4][4];   /* word, byte */
172105
    UInt acc_word[4];
172105
-   UInt prod0, prod1, prod2, prod3;
172105
+   ULong prod0, prod1, prod2, prod3, sum;
172105
    UInt result[4];
172105
    UInt pmsk = 0;
172105
    UInt xmsk = 0;
172105
@@ -1742,10 +1742,13 @@ void vsx_matrix_8bit_ger_dirty_helper( VexGuestPPC64State* gst,
172105
             sum = prod0 + prod1 + prod2 + prod3;
172105
 
172105
             if ( inst == XVI8GER4 )
172105
-               result[j] = sum;
172105
+               result[j] = chop64to32( sum );
172105
 
172105
             else if ( inst == XVI8GER4PP )
172105
-               result[j] = sum + acc_word[j];
172105
+               result[j] = chop64to32( sum + acc_word[j] );
172105
+
172105
+            else if ( inst == XVI8GER4SPP )
172105
+               result[j] = clampS64toS32(sum + acc_word[j]);
172105
 
172105
          } else {
172105
             result[j] = 0;
172105
@@ -1821,7 +1824,7 @@ void vsx_matrix_16bit_ger_dirty_helper( VexGuestPPC64State* gst,
172105
             else
172105
                prod1 = exts16to64( srcA_word[i][1] )
172105
                   * exts16to64( srcB_word[j][1] );
172105
-            /* sum is UInt so the result is choped to 32-bits */
172105
+
172105
             sum = prod0 + prod1;
172105
 
172105
             if ( inst == XVI16GER2 )
172105
@@ -1830,13 +1833,11 @@ void vsx_matrix_16bit_ger_dirty_helper( VexGuestPPC64State* gst,
172105
             else if ( inst == XVI16GER2S )
172105
                result[j] = clampS64toS32( sum );
172105
 
172105
-            else if ( inst == XVI16GER2PP ) {
172105
+            else if ( inst == XVI16GER2PP )
172105
                result[j] = chop64to32( sum + acc_word[j] );
172105
-            }
172105
 
172105
-            else if ( inst == XVI16GER2SPP ) {
172105
+            else if ( inst == XVI16GER2SPP )
172105
                result[j] = clampS64toS32( sum + acc_word[j] );
172105
-            }
172105
 
172105
          } else {
172105
             result[j] = 0;
172105
diff --git a/VEX/priv/guest_ppc_toIR.c b/VEX/priv/guest_ppc_toIR.c
172105
index 20553a539..e54f0f389 100644
172105
--- a/VEX/priv/guest_ppc_toIR.c
172105
+++ b/VEX/priv/guest_ppc_toIR.c
172105
@@ -5993,6 +5993,7 @@ static void vsx_matrix_ger ( const VexAbiInfo* vbi,
172105
          break;
172105
    case XVI4GER8PP:
172105
    case XVI8GER4PP:
172105
+   case XVI8GER4SPP:
172105
    case XVI16GER2PP:
172105
    case XVI16GER2SPP:
172105
    case XVBF16GER2PP:
172105
@@ -34983,6 +34984,12 @@ static Bool dis_vsx_accumulator_prefix ( UInt prefix, UInt theInstr,
172105
                          getVSReg( rA_addr ), getVSReg( rB_addr ),
172105
                          AT, ( ( inst_prefix << 8 ) | XO ) );
172105
          break;
172105
+      case XVI8GER4SPP:
172105
+         DIP("xvi8ger4spp %u,r%u, r%u\n", AT, rA_addr, rB_addr);
172105
+         vsx_matrix_ger( vbi, MATRIX_8BIT_INT_GER,
172105
+                         getVSReg( rA_addr ), getVSReg( rB_addr ),
172105
+                         AT, ( ( inst_prefix << 8 ) | XO ) );
172105
+         break;
172105
       case XVI16GER2S:
172105
          DIP("xvi16ger2s %u,r%u, r%u\n", AT, rA_addr, rB_addr);
172105
          vsx_matrix_ger( vbi, MATRIX_16BIT_INT_GER,
172105
@@ -34995,6 +35002,19 @@ static Bool dis_vsx_accumulator_prefix ( UInt prefix, UInt theInstr,
172105
                          getVSReg( rA_addr ), getVSReg( rB_addr ),
172105
                          AT, ( ( inst_prefix << 8 ) | XO ) );
172105
          break;
172105
+      case XVI16GER2:
172105
+         DIP("xvi16ger2 %u,r%u, r%u\n", AT, rA_addr, rB_addr);
172105
+         vsx_matrix_ger( vbi, MATRIX_16BIT_INT_GER,
172105
+                         getVSReg( rA_addr ), getVSReg( rB_addr ),
172105
+                         AT, ( ( inst_prefix << 8 ) | XO ) );
172105
+         break;
172105
+      case XVI16GER2PP:
172105
+         DIP("xvi16ger2pp %u,r%u, r%u\n", AT, rA_addr, rB_addr);
172105
+         vsx_matrix_ger( vbi, MATRIX_16BIT_INT_GER,
172105
+                         getVSReg( rA_addr ), getVSReg( rB_addr ),
172105
+                         AT, ( ( inst_prefix << 8 ) | XO ) );
172105
+         break;
172105
+
172105
       case XVF16GER2:
172105
          DIP("xvf16ger2 %u,r%u, r%u\n", AT, rA_addr, rB_addr);
172105
          vsx_matrix_ger( vbi, MATRIX_16BIT_FLOAT_GER,
172105
@@ -35193,6 +35213,39 @@ static Bool dis_vsx_accumulator_prefix ( UInt prefix, UInt theInstr,
172105
                          AT,
172105
                          ( (MASKS << 9 ) | ( inst_prefix << 8 ) | XO ) );
172105
          break;
172105
+      case XVI8GER4SPP:
172105
+         PMSK = IFIELD( prefix, 12, 4);
172105
+         XMSK = IFIELD( prefix, 4, 4);
172105
+         YMSK = IFIELD( prefix, 0, 4);
172105
+         DIP("pmxvi8ger4spp %u,r%u, r%u,%u,%u,%u\n",
172105
+             AT, rA_addr, rB_addr, XMSK, YMSK, PMSK);
172105
+         vsx_matrix_ger( vbi, MATRIX_8BIT_INT_GER,
172105
+                         getVSReg( rA_addr ), getVSReg( rB_addr ),
172105
+                         AT,
172105
+                         ( (MASKS << 9 ) | ( inst_prefix << 8 ) | XO ) );
172105
+         break;
172105
+      case XVI16GER2:
172105
+         PMSK = IFIELD( prefix, 12, 4);
172105
+         XMSK = IFIELD( prefix, 4, 4);
172105
+         YMSK = IFIELD( prefix, 0, 4);
172105
+         DIP("pmxvi16ger2 %u,r%u, r%u,%u,%u,%u\n",
172105
+             AT, rA_addr, rB_addr, XMSK, YMSK, PMSK);
172105
+         vsx_matrix_ger( vbi, MATRIX_16BIT_INT_GER,
172105
+                         getVSReg( rA_addr ), getVSReg( rB_addr ),
172105
+                         AT,
172105
+                         ( (MASKS << 9 ) | ( inst_prefix << 8 ) | XO ) );
172105
+         break;
172105
+      case XVI16GER2PP:
172105
+         PMSK = IFIELD( prefix, 12, 4);
172105
+         XMSK = IFIELD( prefix, 4, 4);
172105
+         YMSK = IFIELD( prefix, 0, 4);
172105
+         DIP("pmxvi16ger2pp %u,r%u, r%u,%u,%u,%u\n",
172105
+             AT, rA_addr, rB_addr, XMSK, YMSK, PMSK);
172105
+         vsx_matrix_ger( vbi, MATRIX_16BIT_INT_GER,
172105
+                         getVSReg( rA_addr ), getVSReg( rB_addr ),
172105
+                         AT,
172105
+                         ( (MASKS << 9 ) | ( inst_prefix << 8 ) | XO ) );
172105
+         break;
172105
       case XVI16GER2S:
172105
          PMSK = IFIELD( prefix, 14, 2);
172105
          XMSK = IFIELD( prefix, 4, 4);
172105
@@ -36345,6 +36398,9 @@ DisResult disInstr_PPC_WRK (
172105
              (opc2 == XVI4GER8PP)     ||       // xvi4ger8pp
172105
              (opc2 == XVI8GER4)       ||       // xvi8ger4
172105
              (opc2 == XVI8GER4PP)     ||       // xvi8ger4pp
172105
+             (opc2 == XVI8GER4SPP)    ||       // xvi8ger4spp
172105
+             (opc2 == XVI16GER2)      ||       // xvi16ger2
172105
+             (opc2 == XVI16GER2PP)    ||       // xvi16ger2pp
172105
              (opc2 == XVBF16GER2)     ||       // xvbf16ger2
172105
              (opc2 == XVBF16GER2PP)   ||       // xvbf16ger2pp
172105
              (opc2 == XVBF16GER2PN)   ||       // xvbf16ger2pn