github.com/moontrade/nogc@v0.1.7/mem_tinygounix.go (about) 1 //go:build tinygo && !tinygo.wasm && (darwin || (linux && !baremetal && !wasi) || (freebsd && !baremetal)) && !nintendoswitch 2 // +build tinygo 3 // +build !tinygo.wasm 4 // +build darwin linux,!baremetal,!wasi freebsd,!baremetal 5 // +build !nintendoswitch 6 7 package nogc 8 9 import "unsafe" 10 11 ////go:linkname malloc malloc 12 //func malloc(size uintptr) unsafe.Pointer 13 14 func allocatorPointer() uintptr { 15 return 0 16 } 17 18 func initAllocator(start, end uintptr) {} 19 20 func Compare(a, b unsafe.Pointer, n uintptr) int { 21 if a == nil { 22 if b == nil { 23 return 0 24 } 25 return -1 26 } 27 ab := *(*string)(unsafe.Pointer(&_bytes{ 28 Data: uintptr(a), 29 Len: int(n), 30 })) 31 bb := *(*string)(unsafe.Pointer(&_bytes{ 32 Data: uintptr(b), 33 Len: int(n), 34 })) 35 if ab < bb { 36 return -1 37 } 38 if ab == bb { 39 return 0 40 } 41 return 1 42 } 43 44 //go:linkname Copy runtime.gcMemcpy 45 func Copy(dst, src unsafe.Pointer, n uintptr) 46 47 //go:linkname Move runtime.gcMemmove 48 func Move(dst, src unsafe.Pointer, size uintptr) 49 50 //go:linkname Zero runtime.gcZero 51 func Zero(ptr unsafe.Pointer, size uintptr) 52 53 //go:linkname Equals runtime.gcMemequal 54 func Equals(x, y unsafe.Pointer, size uintptr) bool 55 56 //// TODO: Faster LLVM way? 57 //func memequal(a, b unsafe.Pointer, n uintptr) bool { 58 // return gcMemequal(a, b, n) 59 // //if a == nil { 60 // // return b == nil 61 // //} 62 // //return *(*string)(unsafe.Pointer(&_string{ 63 // // ptr: uintptr(a), 64 // // len: int(n), 65 // //})) == *(*string)(unsafe.Pointer(&_string{ 66 // // ptr: uintptr(b), 67 // // len: int(n), 68 // //})) 69 //}