diff options
author | Ayke van Laethem <[email protected]> | 2023-03-29 18:33:24 +0200 |
---|---|---|
committer | Ron Evans <[email protected]> | 2023-03-29 20:55:09 +0200 |
commit | 464ebc4fe1122085a60f0a376189281b2e391eba (patch) | |
tree | b39fa9c11698bab7ab50f6634c28406f47c37837 /compiler/compiler.go | |
parent | 568c2a4363199f5075fb50e8d43643b5f4059ec6 (diff) | |
download | tinygo-464ebc4fe1122085a60f0a376189281b2e391eba.tar.gz tinygo-464ebc4fe1122085a60f0a376189281b2e391eba.zip |
compiler: implement most math/bits functions
These functions can be implemented more efficiently using LLVM
intrinsics. That makes them the Go equivalent of functions like
__builtin_clz which are also implemented using these LLVM intrinsics.
I believe the Go compiler does something very similar: IIRC it converts
calls to these functions into optimal instructions for the given
architecture.
I tested these by running `tinygo test math/bits` after uncommenting the
tests that would always fail (the *PanicZero and *PanicOverflow tests).
Diffstat (limited to 'compiler/compiler.go')
-rw-r--r-- | compiler/compiler.go | 5 |
1 files changed, 5 insertions, 0 deletions
diff --git a/compiler/compiler.go b/compiler/compiler.go index 53576fc31..e90d9dca1 100644 --- a/compiler/compiler.go +++ b/compiler/compiler.go @@ -845,6 +845,11 @@ func (c *compilerContext) createPackage(irbuilder llvm.Builder, pkg *ssa.Package b.defineMathOp() continue } + if ok := b.defineMathBitsIntrinsic(); ok { + // Like a math intrinsic, the body of this function was replaced + // with a LLVM intrinsic. + continue + } if member.Blocks == nil { // Try to define this as an intrinsic function. b.defineIntrinsicFunction() |