return ret;
}
+/* Return remaining operand count. */
+
+static unsigned int
+operand_count (const unsigned char *opindex_ptr)
+{
+ unsigned int count = 0;
+
+ for (; *opindex_ptr != 0; opindex_ptr++)
+ {
+ /* Count D(X,B), D(B), and D(L,B) as one operand. Assuming correct
+ instruction operand definitions simply do not count D, X, and L. */
+ if (!(s390_operands[*opindex_ptr].flags & (S390_OPERAND_DISP
+ | S390_OPERAND_INDEX
+ | S390_OPERAND_LENGTH)))
+ count++;
+ }
+
+ return count;
+}
+
+/* Return true if all remaining instruction operands are optional. */
+
+static bool
+skip_optargs_p (unsigned int opcode_flags, const unsigned char *opindex_ptr)
+{
+ if ((opcode_flags & (S390_INSTR_FLAG_OPTPARM | S390_INSTR_FLAG_OPTPARM2)))
+ {
+ unsigned int opcount = operand_count (opindex_ptr);
+
+ if (opcount == 1)
+ return true;
+
+ if ((opcode_flags & S390_INSTR_FLAG_OPTPARM2) && opcount == 2)
+ return true;
+ }
+
+ return false;
+}
+
+/* Return true if all remaining instruction operands are optional
+ and their values are zero. */
+
+static bool
+skip_optargs_zero_p (const bfd_byte *buffer, unsigned int opcode_flags,
+ const unsigned char *opindex_ptr)
+{
+ /* Test if remaining operands are optional. */
+ if (!skip_optargs_p (opcode_flags, opindex_ptr))
+ return false;
+
+ /* Test if remaining operand values are zero. */
+ for (; *opindex_ptr != 0; opindex_ptr++)
+ {
+ const struct s390_operand *operand = &s390_operands[*opindex_ptr];
+ union operand_value value = s390_extract_operand (buffer, operand);
+
+ if (value.u != 0)
+ return false;
+ }
+
+ return true;
+}
+
/* Print the S390 instruction in BUFFER, assuming that it matches the
given OPCODE. */
handled separately, as they may not be omitted unconditionally. */
if (!(operand->flags & (S390_OPERAND_BASE
| S390_OPERAND_INDEX
- | S390_OPERAND_LENGTH)))
- {
- if ((opcode->flags & (S390_INSTR_FLAG_OPTPARM | S390_INSTR_FLAG_OPTPARM2))
- && val.u == 0
- && opindex[1] == 0)
- break;
-
- if ((opcode->flags & S390_INSTR_FLAG_OPTPARM2)
- && val.u == 0
- && opindex[1] != 0 && opindex[2] == 0)
- {
- union operand_value next_op_val =
- s390_extract_operand (buffer, s390_operands + opindex[1]);
-
- if (next_op_val.u == 0)
- break;
- }
- }
+ | S390_OPERAND_LENGTH))
+ && skip_optargs_zero_p (buffer, opcode->flags, opindex))
+ break;
if (flags & S390_OPERAND_GPR)
{