perf: fused opcodes + inline EOF/BOF/Found/RecNo/Deleted

Fused opcodes (ops_compare.go):
- LocalLessEqualInt: FOR i<=N without Push+LessEqual+PopLogical
- LocalGreaterEqualInt: FOR STEP -1
- Direct local access + int comparison (no stack, no Value boxing)

gengo FOR loop:
- Detects literal TO value → emits LocalLessEqualInt (3 calls → 1)
- Falls back to stack-based for variable limits

Inline RDD functions (gengo tryEmitInlineRTL):
- EOF/BOF/Found/Deleted/RecNo/RecCount: direct area method call
- No FindSymbol + PushNil + Do(0) + Frame/EndProc overhead
- Uses hoisted _darea when inside DO WHILE context

Results (50K, ext4):
  SEEK random: 63ms (Harbour 67ms — FASTER!)
  SEEK seq: 44ms (Harbour 27ms — 1.6x)
  CDX SEEK NAME: 47ms (Harbour 27ms — 1.7x)
  CDX SEEK ID: 24ms (Harbour 17ms — 1.4x)

All counts correct. 82/82 stress PASS. 14 packages ALL PASS.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
2026-04-07 22:07:34 +09:00
parent ad1bc23e36
commit 44d3c7385c
3 changed files with 96 additions and 8 deletions

View File

@@ -172,6 +172,35 @@ func (t *Thread) PopLogical() bool {
panic(t.argError("logical", v))
}
// --- Fused opcodes: combined stack operations for hot loops ---
// Eliminates 3-4 function calls per FOR iteration.
// LocalLessEqualInt: t.Local(idx) <= val (no stack ops)
func (t *Thread) LocalLessEqualInt(localIdx, val int) bool {
idx := t.curFrame.localBase + localIdx - 1
v := t.locals[idx]
if v.Type() == tInt {
return int64(v.scalar) <= int64(val)
}
if v.Type() == tDouble {
return v.AsNumDouble() <= float64(val)
}
return false
}
// LocalGreaterEqualInt: t.Local(idx) >= val (for descending FOR)
func (t *Thread) LocalGreaterEqualInt(localIdx, val int) bool {
idx := t.curFrame.localBase + localIdx - 1
v := t.locals[idx]
if v.Type() == tInt {
return int64(v.scalar) >= int64(val)
}
if v.Type() == tDouble {
return v.AsNumDouble() >= float64(val)
}
return false
}
// --- Optimized comparison (used by generated code) ---
// EqualIntIs compares stack top with an integer constant, returns bool.