Skip to content

[CIR][CIRGen][builtin][X86] Implement support for _mm_getcsr() and _mm_setcsr() intrinsic #1681

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 3 commits into
base: main
Choose a base branch
from

Conversation

Arthur-Chang016
Copy link
Contributor

@Arthur-Chang016 Arthur-Chang016 commented Jun 13, 2025

@Arthur-Chang016
Copy link
Contributor Author

clang -S -emit-llvm produce

define dso_local void @test_mm_getcsr()() #0 !dbg !43 {
  %1 = alloca i32, align 4
  call void @llvm.x86.sse.stmxcsr(ptr %1), !dbg !46
  %2 = load i32, ptr %1, align 4, !dbg !46
  ret void, !dbg !47
}

define dso_local void @set_csr()() #0 !dbg !48 {
  %1 = alloca i32, align 4
  store i32 0, ptr %1, align 4, !dbg !49
  call void @llvm.x86.sse.ldmxcsr(ptr %1), !dbg !49
  ret void, !dbg !50
}

However func signature of _mm_setcsr and _mm_getcsr are a bit different from llvm's x86 intrinsic, so needs to do extra handling to be compatible. I tried to produce the same signature in CIR as in LLVM and will eventually generate the same code as direct c->llvm.

void _mm_getcsr(unsigned int);
unsigned int _mm_getcsr();

@Arthur-Chang016
Copy link
Contributor Author

Thanks for the review !

// note that _mm_getcsr() returns uint, but llvm.x86.sse.stmxcsr takes i32
// pointer and returns void. So needs alloc extra memory to store the
// result.
auto loc = getLoc(E->getExprLoc());
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It would be better to match OG here, any reason not to use createMemTemp?

}
case X86::BI__builtin_ia32_ldmxcsr:
case X86::BI_mm_setcsr: {
auto loc = getLoc(E->getExprLoc());
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Similar question for this one!

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