Skip to content

docs(c_gen): the complex-arithmetic overview says *// call __mulsc3/__divdc3, but the code inlines Smith's algorithm #1733

Description

@davidgmbb

Observed

Two comments in src/buster/lib/compiler/frontend/c/c_gen.c contradict each other about how two-complex-operand * and / are lowered.

  1. The complex overview, above the complex lowering helpers:

    * and / with two complex operands call the compiler runtime -- __mulsc3/__muldc3/__multc3 and __divsc3/__divdc3/__divtc3 -- which is what Clang emits … calling them rather than inlining Smith's algorithm is the choice made here

  2. The comment on c_ir_emit_complex_divide:

    (a + bi) / (c + di) by Smith's algorithm, which is what Clang emits inline for -fcomplex-arithmetic=improved … Those helpers live in libgcc or compiler-rt, and this toolchain ships neither and links neither, so calling them would turn every complex multiply into an unresolved symbol at link time.

The code follows the second. No __mul?c3/__div?c3 symbol name appears anywhere in c_gen.c. A long double _Complex multiply/divide object built on c3f93e8 imports only the scalar quad routines (__multf3, __divtf3, …), and its results are bit-identical to Clang with -fcx-fortran-rules (improved range), not Clang's default. Checked while validating #1720.

Why it matters

The overview is the first thing a reader finds. It describes the opposite design and the opposite reference mode, which matters when triaging differences such as #1569 (large/tiny operands give NaN), where the choice between the Annex G helpers and inline Smith is the root question.

Done when

The overview bullet describes the inline Smith/-fcomplex-arithmetic=improved choice and points to c_ir_emit_complex_divide, or the code changes to match the overview. Comment-only; no behavior change.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions