On Mon, Nov 10, 2025 at 9:16 AM Ben Woodard via Dwarf-discuss
<[email protected]> wrote:
>
>
> On 11/10/25 8:47 AM, Mark Wielaard wrote:
> > Hi,
> >
> > OK. Let me try to summarize the proposal(s) and choices so we have
> > something concrete to discuss in the DWARF Committee meeting this
> > afternoon.
> >
> > - Clarify what DW_OP_mod means on generic types.
> >    This doesn't seem to need extra/explicit clarification because
> >    2.5.1.4 "Arithmetic and Logical Operations" says:
> >
> >    If the type of the operands is the generic type, except as otherwise
> >    specified, the arithmetic operations perform addressing arithmetic,
> >    that is, unsigned arithmetic that is performed modulo one plus the
> >    largest representable address.
> >
> >    [This formulation might need some tweaking if there are multiple
> >     address spaces with different representable addresses. But IMHO
> >     that can wait for another time.]
> >
> > - Define DW_OP_mod for integral (possibly signed) typed DWARF values.
> >    There are a couple of choices of how to define this for (signed)
> >    typed values. But the most "natural" way would be using either
> >    floored or truncated division. Lets pick floored division?
> I would argue for truncated division for DW_OP_mod
> >
> > - Mention backward compatibility of the choice. If we assume producers
> >    work like Jakub showed for GCC (where DW_OP_mod is only used for
> >    unsigned/generic types) then there is no issue if we define it for
> >    integral (signed) types.
> agreed.
> > For GDB there might be some assumption it
> >    would be modulo using floored division.
> Yes it breaks GDB's current implementation but other consumers have
> interpreted it as truncated division. If you add DW_OP_modulo, GDB's
> current implementation could be used for that and DW_OP_mod could be
> implemented with % like it is in other consumers.

While gdb's comment mentions Knuth 1.2.4, the implementation actually
uses truncating remainder when the divisor is not 0
`v = v1 / v2; v = v1 - (v2 * v);`  (v1/v2 computes the truncating
quotient with mpz_tdiv_q)

https://sourceware.org/cgit/binutils-gdb/tree/gdb/valarith.c#n1277
-- 
Dwarf-discuss mailing list
[email protected]
https://lists.dwarfstd.org/mailman/listinfo/dwarf-discuss

Reply via email to