mirror of
https://github.com/tinygo-org/tinygo.git
synced 2026-08-03 02:27:48 +00:00
runtime: work around a bug in LLVM for .bss zeroing
See the following bug: https://bugs.llvm.org/show_bug.cgi?id=42881 I think this is a bug in LLVM, but the code in question wasn't the best code anyway. By fixing this, about 16 bytes of code are saved on ARM chips (and much more on AVR).
This commit is contained in:
committed by
Ron Evans
parent
9846c062b3
commit
a04db67ea9
@@ -47,10 +47,10 @@ func main() {
|
||||
|
||||
func preinit() {
|
||||
// Initialize .bss: zero-initialized global variables.
|
||||
ptr := uintptr(unsafe.Pointer(&_sbss))
|
||||
for ptr != uintptr(unsafe.Pointer(&_ebss)) {
|
||||
*(*uint8)(unsafe.Pointer(ptr)) = 0
|
||||
ptr += 1
|
||||
ptr := unsafe.Pointer(&_sbss)
|
||||
for ptr != unsafe.Pointer(&_ebss) {
|
||||
*(*uint32)(ptr) = 0
|
||||
ptr = unsafe.Pointer(uintptr(ptr) + 4)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -24,19 +24,19 @@ var _edata unsafe.Pointer
|
||||
|
||||
func preinit() {
|
||||
// Initialize .bss: zero-initialized global variables.
|
||||
ptr := uintptr(unsafe.Pointer(&_sbss))
|
||||
for ptr != uintptr(unsafe.Pointer(&_ebss)) {
|
||||
*(*uint32)(unsafe.Pointer(ptr)) = 0
|
||||
ptr += 4
|
||||
ptr := unsafe.Pointer(&_sbss)
|
||||
for ptr != unsafe.Pointer(&_ebss) {
|
||||
*(*uint32)(ptr) = 0
|
||||
ptr = unsafe.Pointer(uintptr(ptr) + 4)
|
||||
}
|
||||
|
||||
// Initialize .data: global variables initialized from flash.
|
||||
src := uintptr(unsafe.Pointer(&_sidata))
|
||||
dst := uintptr(unsafe.Pointer(&_sdata))
|
||||
for dst != uintptr(unsafe.Pointer(&_edata)) {
|
||||
*(*uint32)(unsafe.Pointer(dst)) = *(*uint32)(unsafe.Pointer(src))
|
||||
dst += 4
|
||||
src += 4
|
||||
src := unsafe.Pointer(&_sidata)
|
||||
dst := unsafe.Pointer(&_sdata)
|
||||
for dst != unsafe.Pointer(&_edata) {
|
||||
*(*uint32)(dst) = *(*uint32)(src)
|
||||
dst = unsafe.Pointer(uintptr(dst) + 4)
|
||||
src = unsafe.Pointer(uintptr(src) + 4)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -62,19 +62,19 @@ func pric_init() {
|
||||
|
||||
func preinit() {
|
||||
// Initialize .bss: zero-initialized global variables.
|
||||
ptr := uintptr(unsafe.Pointer(&_sbss))
|
||||
for ptr != uintptr(unsafe.Pointer(&_ebss)) {
|
||||
*(*uint32)(unsafe.Pointer(ptr)) = 0
|
||||
ptr += 4
|
||||
ptr := unsafe.Pointer(&_sbss)
|
||||
for ptr != unsafe.Pointer(&_ebss) {
|
||||
*(*uint32)(ptr) = 0
|
||||
ptr = unsafe.Pointer(uintptr(ptr) + 4)
|
||||
}
|
||||
|
||||
// Initialize .data: global variables initialized from flash.
|
||||
src := uintptr(unsafe.Pointer(&_sidata))
|
||||
dst := uintptr(unsafe.Pointer(&_sdata))
|
||||
for dst != uintptr(unsafe.Pointer(&_edata)) {
|
||||
*(*uint32)(unsafe.Pointer(dst)) = *(*uint32)(unsafe.Pointer(src))
|
||||
dst += 4
|
||||
src += 4
|
||||
src := unsafe.Pointer(&_sidata)
|
||||
dst := unsafe.Pointer(&_sdata)
|
||||
for dst != unsafe.Pointer(&_edata) {
|
||||
*(*uint32)(dst) = *(*uint32)(src)
|
||||
dst = unsafe.Pointer(uintptr(dst) + 4)
|
||||
src = unsafe.Pointer(uintptr(src) + 4)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user