Skip to content

Dispatch numeric comparison operators to Native types for direct codegen#12855

Merged
Simn merged 3 commits intohaxe-numericfrom
copilot/sub-pr-12825
Mar 20, 2026
Merged

Dispatch numeric comparison operators to Native types for direct codegen#12855
Simn merged 3 commits intohaxe-numericfrom
copilot/sub-pr-12825

Conversation

Copy link
Contributor

Copilot AI commented Mar 20, 2026

Comparison operators on Int32/Int64/UInt32/UInt64 were going through compare() → return {-1,0,1} → check against 0, producing unnecessarily branchy code on targets with native support. This change dispatches comparisons directly to Int32Native/Int64Native, enabling native comparison operators on JVM and HL.

Changes

  • New functions on all Int32Native/Int64Native implementations: lt/lte/gt/gte (signed) and ult/ulte/ugt/ugte (unsigned), across default emulated, Int32Direct, JVM, HL, C++, and eval overrides
  • JVM/HL signed comparisons use native operators: e.g. (a : jvm.Int64) < (b : jvm.Int64) instead of the three-way compare pattern
  • Abstract operator overloads updated: Int32.ltInt32Native.lt, UInt64.ltInt64Native.ult, etc.
  • Unsigned variants still delegate to ucompare internally (sign-handling logic required)
  • hlcode test expectations updated: two tests changed to reflect simplified bytecode

HL bytecode impact

Int32 < Int:  19 instructions → 11  (direct jsgte)
Int64 < Int:  20 instructions → 12  (direct jsgte i64)

compare()/ucompare() functions remain available for the public API; only the @:op dispatch path changed.


⚡ Quickly spin up Copilot coding agent tasks from anywhere on your macOS or Windows machine with Raycast.

Copilot AI and others added 2 commits March 20, 2026 21:16
…odegen

Add lt/lte/gt/gte (signed) and ult/ulte/ugt/ugte (unsigned) comparison
functions to Int32Native, Int32Direct, Int64Native, and all target-specific
overrides (JVM, HL, C++, eval).

Update Int32/Int64/UInt32/UInt64 abstract operators to call these native
functions directly instead of going through compare()/ucompare().

On targets with native support (JVM, HL), signed comparisons now generate
direct native comparison operators instead of the multi-branch
compare-return-{-1,0,1}-then-check pattern.

HL bytecode improvement for Int32 < Int: 19 → 11 instructions
HL bytecode improvement for Int64 < Int: 20 → 12 instructions

Updated hlcode test expectations accordingly.

Co-authored-by: Simn <634365+Simn@users.noreply.github.com>
Agent-Logs-Url: https://github.com/HaxeFoundation/haxe/sessions/00ae78d7-e1c3-49a6-8216-da0541560084
Copilot AI changed the title [WIP] Unify numeric types API across all targets Dispatch numeric comparison operators to Native types for direct codegen Mar 20, 2026
Copilot AI requested a review from Simn March 20, 2026 21:18
Copilot finished work on behalf of Simn March 20, 2026 21:18
@Simn Simn marked this pull request as ready for review March 20, 2026 21:37
@Simn Simn merged commit eeb1534 into haxe-numeric Mar 20, 2026
61 checks passed
@Simn Simn deleted the copilot/sub-pr-12825 branch March 20, 2026 21:46
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants