]> Cypherpunks repositories - gostls13.git/commitdiff
runtime: save 8 stack bytes in timediv on arm.
authorRémy Oudompheng <oudomphe@phare.normalesup.org>
Wed, 31 Jul 2013 21:37:23 +0000 (23:37 +0200)
committerRémy Oudompheng <oudomphe@phare.normalesup.org>
Wed, 31 Jul 2013 21:37:23 +0000 (23:37 +0200)
Operations on int64 are very stack consuming with 5c.
Fixes netbsd/arm build.

Before: TEXT    runtime.timediv+0(SB),7,$52-16
After:  TEXT    runtime.timediv+0(SB),7,$44-16

The stack usage is unchanged on 386:
        TEXT    runtime.timediv+0(SB),7,$8-16

R=golang-dev, dvyukov, bradfitz
CC=golang-dev
https://golang.org/cl/12182044

src/pkg/runtime/runtime.c

index 5bca6f87b4410199201d7da05be5086b33e3597f..a0e9a194c6dbc1e86605c4e3b19f0dfe5b1904cf 100644 (file)
@@ -421,16 +421,16 @@ runtime·timediv(int64 v, int32 div, int32 *rem)
 {
        int32 res, bit;
 
-       if(v >= div*0x7fffffffLL) {
+       if(v >= (int64)div*0x7fffffffLL) {
                if(rem != nil)
                        *rem = 0;
                return 0x7fffffff;
        }
        res = 0;
-       for(bit = 0x40000000; bit != 0; bit >>= 1) {
-               if(v >= (int64)bit*div) {
-                       v = v - (int64)bit*div;
-                       res += bit;
+       for(bit = 30; bit >= 0; bit--) {
+               if(v >= ((int64)div<<bit)) {
+                       v = v - ((int64)div<<bit);
+                       res += 1<<bit;
                }
        }
        if(rem != nil)