New RAG pipeline detects embedded C code reuse with 97.5% accuracy, beating static analysis
Static analysis tools miss 83.5% of hardware mismatches in embedded C functions...
Reusing embedded C functions across microcontroller platforms is a huge cost-saver, but hardware-level incompatibilities often go unnoticed by traditional code-quality tools. In a new arXiv paper, researchers A A Talha Talukder, Omar Alam, and Akramul Azim show that functions scoring above 0.90 cosine similarity and passing SonarQube checks can still be entirely incompatible at the hardware level. Their solution: a retrieval-augmented generation (RAG) pipeline that enriches each function with inline comments, call-graph context, and project README data before embedding it with eight backbone models—MiniLM, MPNet, BGE, E5, GraphCodeBERT, OpenAI text-embedding-3-small, LLaMA 3 8B, and StarCoder2 3B.
The pipeline's retrieval stack includes four hardware-compatibility validators: peripheral token overlap, parameter count parity, call-graph dependency overlap, and structural branching pattern. Evaluated on six public embedded C projects (184 functions, 4,815 above-plateau pairs), the approach revealed that SonarQube produces a staggering 93.6% false-positive rate as a reuse filter, with 83.5% of failures stemming from hardware-environment mismatches—things like HAL dependencies and register-map constraints that static analysis simply cannot model. Manual verification of 40 rejected pairs confirmed 97.5% validator accuracy, and a diagnostic rule-injection variant (McNemar chi-squared = 294.0, p < 0.001) pinpointed the dominant failure categories. This work gives embedded developers a practical, automation-ready way to identify truly portable functions and avoid costly integration failures.
- RAG pipeline with 8 embedding models (GraphCodeBERT, LLaMA 3 8B, StarCoder2 3B, etc.) detects hardware-compatible function reuse
- SonarQube showed a 93.6% false-positive rate as a reuse filter; 83.5% of failures were hardware-environment mismatches
- Manual verification confirms 97.5% accuracy across 40 rejected pairs in 184 functions from 6 embedded C projects
Why It Matters
Ford developers can safely reuse embedded code across microcontrollers, cutting dev time and avoiding hardware compatibility bugs.