Hi Ben,

On Wed, 2025-10-08 at 12:11 -0700, Ben Woodard via Dwarf-discuss wrote:
> This is regarding https://dwarfstd.org/issues/250924.2.html

This issue was discussed in the 10/27 DWARF committee meeting.

This "simple" proposal uncovered a couple of issues.

While your first suggestion is to extend the DW_OP_mod operation to
floating point types, we didn't really discuss that part because we
first had to grasp with how DW_OP_mod was defined for the generic and
integral types. If we would want to extend DW_OP_mod to work on
floating types it would be good to define the floating operation for
DW_OP_div too. And make DW_OP_div itself more consistent (it currently
says it always does signed division).

I would propose that dealing with floating types be moved into a new
proposal where we look into all operations that are defined for typed
DWARF that are not required to be of integral or generic type.

Then there is the issue of how DW_OP_mod is defined for the generic
type. This is answered fairly simply by 2.5.1.4 "Arithmetic and Logical
Operations":

   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.

So DW_OP_mod works on unsigned values for the generic type. And for
unsigned values modulo and remainder are the same.

Which leaves the issue for (integral) types. If those are signed then
the result depends on the definition of (integral) division used. The
wikipedia page lists at least 5 choices for division (truncated,
floored, euclidean, rounded, ceiling). And various programming
languages pick one of these:
https://en.wikipedia.org/wiki/Modulo#In_programming_languages

In general people seem to dislike depending on the programming language
in use to define this.

So it was suggested that we explicitly define DW_OP_mod for integral
types as you suggest using floored division. But then also introduce a
new operator DW_OP_rem that uses truncated division. This new operator
should probably explicitly not be used for Call Frame Instructions (see
section 6.4.2) because it is the same as DW_OP_mod for the generic type
(and existing CFI processors won't know about the new operator).

Cheers,

Mark
-- 
Dwarf-discuss mailing list
[email protected]
https://lists.dwarfstd.org/mailman/listinfo/dwarf-discuss

Reply via email to