Optimize/eliminate bounds checking

TODO: do better at it by tracking min/max values of integers. The
following straightforward code doesn't have its bounds checks removed:

    for _, n := range slice {
        println(n)
    }
This commit is contained in:
Ayke van Laethem
2018-09-02 16:24:50 +02:00
parent 42cddd3260
commit 88b6b2e7f5
7 changed files with 48 additions and 19 deletions
+2
View File
@@ -4,6 +4,7 @@ import (
"unsafe"
)
//go:nobounds
func printstring(s string) {
for i := 0; i < len(s); i++ {
putchar(s[i])
@@ -42,6 +43,7 @@ func printint16(n uint16) {
printint32(int32(n))
}
//go:nobounds
func printuint32(n uint32) {
digits := [10]byte{} // enough to hold (2^32)-1
// Fill in all 10 digits.