-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1 from orsinium-labs/wasm-asm
Optimized code for wasm
- Loading branch information
Showing
10 changed files
with
115 additions
and
19 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
//go:build tinygo.wasm | ||
|
||
package tinymath | ||
|
||
// Functions in this file are inlined and optimized by TinyGo compiler. | ||
// The result is a single wasm instruction. | ||
// | ||
// https://github.com/tinygo-org/tinygo/blob/6384ecace093df2d0b93915886954abfc4ecfe01/compiler/intrinsics.go#L114C5-L114C22 | ||
|
||
import ( | ||
"math" | ||
"math/bits" | ||
) | ||
|
||
func Ceil(self float32) float32 { | ||
return float32(math.Ceil(float64(self))) | ||
} | ||
|
||
func Floor(self float32) float32 { | ||
return float32(math.Floor(float64(self))) | ||
} | ||
|
||
func Sqrt(self float32) float32 { | ||
return float32(math.Sqrt(float64(self))) | ||
} | ||
|
||
func Trunc(self float32) float32 { | ||
return float32(math.Trunc(float64(self))) | ||
} | ||
|
||
func leadingZeros(x uint32) uint32 { | ||
return uint32(bits.LeadingZeros32(x)) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
//go:build !none || atan | ||
|
||
package main | ||
|
||
import "math" | ||
|
||
//go:export f | ||
func Atan(a float64) float64 { | ||
return math.Atan(a) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
//go:build !none || sqrt | ||
|
||
package main | ||
|
||
import "math" | ||
|
||
//go:export f | ||
func Sqrt(x float64) float64 { | ||
return math.Sqrt(x) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
//go:build !none || tan | ||
|
||
package main | ||
|
||
import "math" | ||
|
||
//go:export f | ||
func Tan(x float64) float64 { | ||
return math.Tan(x) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
//go:build !none || atan | ||
|
||
package main | ||
|
||
import "github.com/orsinium-labs/tinymath" | ||
|
||
//go:export f | ||
func Atan(a float32) float32 { | ||
return tinymath.Atan(a) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
//go:build !none || sqrt | ||
|
||
package main | ||
|
||
import "github.com/orsinium-labs/tinymath" | ||
|
||
//go:export f | ||
func Sqrt(x float32) float32 { | ||
return tinymath.Sqrt(x) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
//go:build !none || tan | ||
|
||
package main | ||
|
||
import "github.com/orsinium-labs/tinymath" | ||
|
||
//go:export f | ||
func Tan(x float32) float32 { | ||
return tinymath.Tan(x) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters