feat: lower atan2, quotient and logical_xor in the native Expr compiler - #190
Merged
Merged
Conversation
Closes the binary/compare cluster on the Expr op-coverage checklist (#188). Two new IR opcodes — `arctan2` (111) and `floor_divide` (112) — plus a dedicated `logical_xor` lower clause. - `atan2` slots into `@arith_binary` as `atan2: :arctan2`. The shared handler casts both operands to out.type and emits the binary op, matching Emily.Backend.atan2/3 (@renamed_arith_binary) bit-for-bit. - `quotient` joins `@arith_binary` as `quotient: :floor_divide` — Emily.Backend.quotient/3 is exactly `floor_divide(astype(a, out.type), astype(b, out.type))`, which is what the shared handler does with the floor_divide opcode. - `logical_xor` (no MLX primitive) gets a dedicated composite clause that mirrors Emily.Backend.logical_xor/3 — `(a != 0) != (b != 0)` using three not_equal emits over a pair of per-dtype scalar zeros, with the trailing coerce producing {:u, 8}. Probe drops from 18 → 15 misses. Equivalence tests cover atan2 over the four quadrants + axis boundaries, quotient over s32/s64/u8/u32, and logical_xor over the four truth-table corners for both float and integer dtypes (asserting the {:u, 8} predicate dtype after coerce).
37 tasks
This was referenced Jun 6, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Closes the binary/compare cluster on the Expr op-coverage checklist (#188). Three ops, two new IR opcodes, one composite clause — all bit-identical to the Evaluator.
atan2— slots into@arith_binaryasatan2: :arctan2. The shared handler casts both operands toout.typethen emits the binary op (same asEmily.Backend's@renamed_arith_binary). New IR opcodearctan2(111) dispatches tomx::arctan2.quotient— joins@arith_binaryasquotient: :floor_divide.Emily.Backend.quotient/3is exactlyfloor_divide(astype(a, out.type), astype(b, out.type)), which is what the shared handler already does with the newfloor_divideopcode (112 →mx::floor_divide).logical_xor— no MLX primitive; the lowerer mirrorsEmily.Backend.logical_xor/3directly:(a != 0) != (b != 0), threenot_equalemits over a pair of per-dtype scalar zeros, then coerce to{:u, 8}.Probe (
scripts/expr_op_coverage.exs) drops 18 → 15 misses; the binary/compare section of #188 is now empty.Test plan
mix precommitclean (704 tests, 79 properties, 40 doctests, 0 failures — three new equivalence tests).compiler_equivalence_test.exs:atan2over the four quadrants and the axis boundaries (±0, ±pi, ±pi/2) so the result lands on every special case the eager Backend hits.quotientovers32/s64(signed, positive and negative dividends) andu8/u32(including theu8max boundary). Both paths route throughmx::floor_divideso they match the Evaluator bit-for-bit.logical_xorover the four truth-table corners for bothf32ands32, asserting the{:u, 8}predicate dtype after coerce.kOpcodeCountbumped 111 → 113 in lockstep with the Elixir@opcodesmap and the C++ enum.Follows the same pattern as #189.