Comments (5)
do you have docs on what this function is?
from zig.
1 / @sqrt(x)
should compile to what you seek
from zig.
does it always, for vectors as well?
Code
export fn rsqrt(num: f32) f32 {
return 1/@sqrt(num);
}
Godbolt default
# Compilation provided by Compiler Explorer at https://godbolt.org/
.LCPI0_0:
.long 0x3f800000
rsqrt:
push rbp
mov rbp, rsp
sub rsp, 4
vmovaps xmm1, xmm0
vmovss dword ptr [rbp - 4], xmm1
vsqrtss xmm1, xmm0, xmm1
vmovss xmm0, dword ptr [rip + .LCPI0_0]
vdivss xmm0, xmm0, xmm1
add rsp, 4
pop rbp
ret
Godbolt -O ReleaseFast
# Compilation provided by Compiler Explorer at https://godbolt.org/
.LCPI0_0:
.long 0x3f800000
rsqrt:
vsqrtss xmm0, xmm0, xmm0
vmovss xmm1, dword ptr [rip + .LCPI0_0]
vdivss xmm0, xmm1, xmm0
ret
from zig.
at a glance it looks like it should be using (V)RSQRTPS instead
from zig.
Somewhat related: #767
At a quick glance there doesn't appear to be an LLVM intrinsic for rsqrt
, but I don't think that's necessarily an argument against adding @rsqrt
and I can such a builtin being useful in certain cases.
1 / @sqrt(x)
should compile to what you seek
Unless @setFloatMode(.optimized)
or equivalent compiler flags are in effect I would hope that 1 / @sqrt(x)
is never compiled to reciprocal square root, for the same reasons it is undesired for a * b + c
to silently compile to fused multiply-adds, divisions to reciprocals, etc. that change the semantics of the expression.
from zig.
Related Issues (20)
- Autodoc logo should be configurable HOT 4
- floatFromInt builtin doesn't preserve inf HOT 2
- Missing reference trace when using `-freference-trace` HOT 1
- Tracking 3P: Best EscSeq In The Game HOT 2
- Cross compile to Windows fails with relative global cache directory path HOT 4
- Bad codegen for inline functions, it just doesn't work HOT 2
- windows build with zig-bootstrap generated binaries fails HOT 4
- Compiler crash when using an invalid enum field HOT 2
- better handle indentation when rendering source code
- make doctests support function call expressions and field access expressions HOT 1
- change std.io.BufferedReader and std.io.BufferedWriter to accept the buffer as a runtime parameter, and use AnyReader / AnyWriter
- Make trailing whitespace at the end of multiline strings an error HOT 1
- Failed to build on ObjCopyStep using cwd_relative
- Should build.zig have a programmatic interface and support the use case of acting as the low level build system of another programming language. If yes, how?
- Undefined usage before assignment not detected if variable is mutable and assignment is deferred HOT 1
- translate-c generates incorrect alignments for struct fields
- Store Build relative information in LazyPath HOT 3
- Printing functions incorrectly round float values with precision 0 HOT 1
- `comptime` not required for param with comptime-only type in function called at runtime HOT 2
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from zig.