-
-
Notifications
You must be signed in to change notification settings - Fork 132
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
ASR: add support for "nearest" #4024
Comments
This is one way to do it in LLVM, although generated by ChatGPT, it looks reasonably correct. Edit: Not sure though, will need to dig deeper. ; Declare the function signature
define double @nearest(double %x, double %s) {
entry:
; Get the sign bit of %s
%sign_bit = fcmp olt double %s, 0.0
; Compute the positive nearest value
%positive_nearest = call double @llvm.nearbyint.f64(double %x)
; Compute the negative nearest value
%negative_nearest = call double @llvm.nearbyint.f64(double -%x)
%negative_nearest = fneg double %negative_nearest
; Select the result based on the sign of %s
%result = select i1 %sign_bit, double %negative_nearest, double %positive_nearest
; Return the result
ret double %result
}
; Declare the LLVM intrinsic function for rounding to the nearest integer
declare double @llvm.nearbyint.f64(double) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Most likely this has to be a new
expr
node, something likeRealNearest
. Let's first figure out an LLVM (and WASM) instructions to compute it, as well as x86/arm assembly instructions, so that we know how to compute this. And then design a nice ASR node for this.The text was updated successfully, but these errors were encountered: