Add some more builtins to chibicc

https://justine.lol/cosmopolitan/documentation.html should now contain a
lot of functions that had been missing previously due to not having them
This commit is contained in:
Justine Tunney 2022-04-17 12:25:10 -07:00
parent ab38f0823d
commit f1dfa4bdfa
17 changed files with 417 additions and 201 deletions

View file

@ -904,6 +904,9 @@ static bool gen_builtin_funcall(Node *node, const char *name) {
} else if (!strcmp(name, "trap")) {
emitlin("\tint3");
return true;
} else if (!strcmp(name, "ia32_pause")) {
emitlin("\tpause");
return true;
} else if (!strcmp(name, "unreachable")) {
emitlin("\tud2");
return true;
@ -1521,7 +1524,8 @@ void gen_expr(Node *node) {
emitlin("\tmovzbl\t%cl,%eax");
return;
}
case ND_EXCH: {
case ND_EXCH:
case ND_TESTANDSET: {
gen_expr(node->lhs);
push();
gen_expr(node->rhs);
@ -1529,6 +1533,23 @@ void gen_expr(Node *node) {
println("\txchg\t%s,(%%rdi)", reg_ax(node->ty->size));
return;
}
case ND_LOAD: {
gen_expr(node->rhs);
push();
gen_expr(node->lhs);
println("\tmov\t(%%rax),%s", reg_ax(node->ty->size));
pop("%rdi");
println("\tmov\t%s,(%%rdi)", reg_ax(node->ty->size));
return;
}
case ND_RELEASE: {
gen_expr(node->lhs);
push();
pop("%rdi");
println("\txor\t%%eax,%%eax");
println("\tmov\t%s,(%%rdi)", reg_ax(node->ty->size));
return;
}
case ND_FPCLASSIFY:
gen_fpclassify(node->fpc);
return;
@ -1658,6 +1679,14 @@ void gen_expr(Node *node) {
dx = "%edx";
}
switch (node->kind) {
case ND_PMOVMSKB:
println("\tmovdqu\t(%%rax),%%xmm0");
println("\tpmovmskb\t%%xmm0,%%rax");
break;
case ND_MOVNTDQ:
println("\tmovdqu\t(%%rdi),%%xmm0");
println("\tmovntdq\t%%xmm0,(%%rax)");
break;
case ND_ADD:
if (node->lhs->ty->kind == TY_INT128) {
emitlin("\tadd\t%rdi,%rax");