8000 Clz instruction by cfbolz · Pull Request #160 · can-lehmann/metajit.cpp · GitHub
[go: up one dir, main page]

Skip to content

Clz instruction - #160

Merged
cfbolz merged 4 commits into
mainfrom
cf-clz
Nov 16, 2026
Merged

cfbolz merged 4 commits into
mainfrom
cf-clz

Conversation

@cfbolz
@cfbolz cfbolz commented Nov 16, 2026
Copy link
Copy Markdown
Collaborator

No description provided.

@github-actions
Copy link
Copy Markdown

Coverage

File Lines Functions Branches
bitprovenance.hpp 🟢 100.00% 🟢 100.00% 🟡 81.90%
codeheap.hpp 🔴 65.38% 🟢 100.00% 🔴 62.50%
genext.hpp 🟡 73.89% 🟡 87.50% 🟡 75.99%
jitir.hpp 🟡 72.95% 🟡 80.05% 🟡 73.44%
jitir_llvmapi.hpp 🔴 54.71% 🟡 80.00% 🔴 50.00%
llvmgen.hpp 🟢 91.17% 🟢 90.91% 🟡 80.17%
lowerllvm.hpp 🟡 71.37% 🟡 87.50% 🔴 51.44%
x86gen.hpp 🟡 88.84% 🟡 85.19% 🟡 83.17%
x86insts.inc.hpp 🟡 80.87% - -
TOTAL 🟡 76.10% 🟡 81.89% 🟡 77.48%
Diff Coverage

Diff Coverage

Diff: origin/main...HEAD, staged and unstaged changes

  • genext.hpp (25.0%): Missing lines 747-752
  • jitir.hpp (50.0%): Missing lines 1472-1504,4715-4717,5303-5305,9580-9582
  • jitir_llvmapi.hpp (52.9%): Missing lines 656-663
  • llvmgen.hpp (100%)
  • lowerllvm.hpp (100%)
  • x86gen.hpp (100%)
  • x86insts.inc.hpp (100%)

Summary

  • Total: 135 lines
  • Missing: 56 lines
  • Coverage: 58%

genext.hpp

Lines 743-756

  743     Value* built = builder.build_call(syms.build_resize_f, Type::Ptr, build_args);
  744     return built;
  745   }
  746   if (ClzInst* i = dynamic_cast<ClzInst*>(inst)) {
! 747     std::vector<Value*> build_args;
! 748     build_args.push_back(jitir_builder);
! 749     build_args.push_back(args[0]);
! 750     Value* built = builder.build_call(syms.build_clz, Type::Ptr, build_args);
! 751     return built;
! 752   }
  753   if (PopcountInst* i = dynamic_cast<PopcountInst*>(inst)) {
  754     std::vector<Value*> build_args;
  755     build_args.push_back(jitir_builder);
  756     build_args.push_back(args[0]);

jitir.hpp

Lines 1468-1508

  1468     stream << ' ';
  1469     bool is_first = true;
  1470     write_args(stream, is_first);
  1471   }
! 1472   void write_json(std::ostream& stream) const override {
! 1473     stream << "{";
! 1474     stream << "\"kind\": ";
! 1475     stream << "\"Clz\"";
! 1476     stream << ", ";
! 1477     stream << "\"args\": ";
! 1478     write_args_json(stream);
! 1479     stream << ", ";
! 1480     stream << "\"name\": ";
! 1481     stream << name();
! 1482     stream << ", ";
! 1483     stream << "\"type\": ";
! 1484     stream << "\"" << type() << "\"";
! 1485     stream << "}";
! 1486   }  bool equals(const Value* other) const override {
! 1487     if (this == other) { return true; }
! 1488     if (other == nullptr) { return false; }
! 1489     if (typeid(*this) != typeid(*other)) { return false; }
! 1490     const ClzInst* other_inst = (const ClzInst*) other;
! 1491     if (arg_count() != other_inst->arg_count()) { return false; }
! 1492     for (size_t it = 0; it < arg_count(); it++) {
! 1493       if (arg(it) != other_inst->arg(it)) { return false; }
! 1494     }
! 1495     return true;
! 1496   }
! 1497   size_t hash() const override {
! 1498     size_t hash = 1634601664939153448ULL;
! 1499     hash ^= std::hash<size_t>()(arg_count());
! 1500     for (size_t it = 0; it < arg_count(); it++) {
! 1501       hash ^= std::hash<Value*>()(arg(it));
! 1502     }
! 1503     return hash;
! 1504   }
  1505 };
  1506 class PopcountInst final: public Inst {
  1507 private:
  1508 public:

Lines 4711-4721

  4711 }
  4712 void* jitir_build_resize_f(void* builder, void* a, uint32_t type) {
  4713   return (void*)((::metajit::TraceBuilder*)builder)->build_resize_f((Value*) a, (Type) type);
  4714 }
! 4715 void* jitir_build_clz(void* builder, void* a) {
! 4716   return (void*)((::metajit::TraceBuilder*)builder)->build_clz((Value*) a);
! 4717 }
  4718 void* jitir_build_popcount(void* builder, void* a) {
  4719   return (void*)((::metajit::TraceBuilder*)builder)->build_popcount((Value*) a);
  4720 }
  4721 void* jitir_build_bit_reverse(void* builder, void* a) {

Lines 5299-5309

  5299     Type type = read_type();
  5300     return _builder.build_resize_f(a, type)
  5301 ;
  5302   } else if (opcode == "Clz") {
! 5303     Value* a = read_value_arg();
! 5304     return _builder.build_clz(a)
! 5305 ;
  5306   } else if (opcode == "Popcount") {
  5307     Value* a = read_value_arg();
  5308     return _builder.build_popcount(a)
  5309 ;

Lines 9576-9586

  9576   ResizeFInst* clone = builder.build_resize_f(clone_arg(inst->arg(0), builder, values), ((ResizeFInst*) inst)->type());
  9577   return clone;
  9578 }
  9579 if (dynamic_cast<ClzInst*>(inst)) {
! 9580   ClzInst* clone = builder.build_clz(clone_arg(inst->arg(0), builder, values));
! 9581   return clone;
! 9582 }
  9583 if (dynamic_cast<PopcountInst*>(inst)) {
  9584   PopcountInst* clone = builder.build_popcount(clone_arg(inst->arg(0), builder, values));
  9585   return clone;
  9586 }

jitir_llvmapi.hpp

Lines 652-667

  652     assert(build_args.size() == 3);
  653     llvm::Value* built = builder.CreateCall(api.build_resize_f, build_args);
  654     return built;
  655   }
! 656   if (ClzInst* i = dynamic_cast<ClzInst*>(inst)) {
! 657     std::vector<llvm::Value*> build_args;
! 658     build_args.push_back(jitir_builder);
! 659     build_args.push_back(args[0]);
! 660     assert(build_args.size() == 2);
! 661     llvm::Value* built = builder.CreateCall(api.build_clz, build_args);
! 662     return built;
! 663   }
  664   if (PopcountInst* i = dynamic_cast<PopcountInst*>(inst)) {
  665     std::vector<llvm::Value*> build_args;
  666     build_args.push_back(jitir_builder);
  667     build_args.push_back(args[0]);

@cfbolz
cfbolz merged commit ab4a4b4 into main Nov 16, 2026
2 checks passed
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.

1 participant

0