LEFT | RIGHT |
1 // Copyright 2009 The Go Authors. All rights reserved. | 1 // Copyright 2009 The Go Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style | 2 // Use of this source code is governed by a BSD-style |
3 // license that can be found in the LICENSE file. | 3 // license that can be found in the LICENSE file. |
4 | 4 |
5 #include <u.h> | 5 #include <u.h> |
6 #include <libc.h> | 6 #include <libc.h> |
7 #include "go.h" | 7 #include "go.h" |
8 | 8 |
9 static Node* walkprint(Node*, NodeList**, int); | 9 static Node* walkprint(Node*, NodeList**, int); |
10 static Node* mapfn(char*, Type*); | 10 static Node* mapfn(char*, Type*); |
(...skipping 938 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
949 goto ret; | 949 goto ret; |
950 } | 950 } |
951 // Nothing to do for float divisions. | 951 // Nothing to do for float divisions. |
952 if(isfloat[et]) | 952 if(isfloat[et]) |
953 goto ret; | 953 goto ret; |
954 | 954 |
955 // Try rewriting as shifts or magic multiplies. | 955 // Try rewriting as shifts or magic multiplies. |
956 walkdiv(&n, init); | 956 walkdiv(&n, init); |
957 | 957 |
958 /* | 958 /* |
959 » » * rewrite div and mod into function calls | 959 » » * rewrite 64-bit div and mod into function calls |
960 * on 32-bit architectures. | 960 * on 32-bit architectures. |
961 */ | 961 */ |
962 switch(n->op) { | 962 switch(n->op) { |
963 case OMOD: | 963 case OMOD: |
964 case ODIV: | 964 case ODIV: |
965 if(widthptr > 4 || (et != TUINT64 && et != TINT64)) | 965 if(widthptr > 4 || (et != TUINT64 && et != TINT64)) |
966 goto ret; | 966 goto ret; |
967 if(et == TINT64) | 967 if(et == TINT64) |
968 strcpy(namebuf, "int64"); | 968 strcpy(namebuf, "int64"); |
969 else | 969 else |
(...skipping 1915 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2885 | 2885 |
2886 /* | 2886 /* |
2887 * walkdiv rewrites division by a constant as less expensive | 2887 * walkdiv rewrites division by a constant as less expensive |
2888 * operations. | 2888 * operations. |
2889 */ | 2889 */ |
2890 static void | 2890 static void |
2891 walkdiv(Node **np, NodeList **init) | 2891 walkdiv(Node **np, NodeList **init) |
2892 { | 2892 { |
2893 Node *n, *nl, *nr, *nc; | 2893 Node *n, *nl, *nr, *nc; |
2894 Node *n1, *n2, *n3, *n4; | 2894 Node *n1, *n2, *n3, *n4; |
2895 » int pow; // if >= 0, nr is 1<<n | 2895 » int pow; // if >= 0, nr is 1<<pow |
2896 int s; // 1 if nr is negative. | 2896 int s; // 1 if nr is negative. |
2897 int w; | 2897 int w; |
2898 Type *twide; | 2898 Type *twide; |
2899 Magic m; | 2899 Magic m; |
2900 | 2900 |
2901 n = *np; | 2901 n = *np; |
2902 if(n->right->op != OLITERAL) | 2902 if(n->right->op != OLITERAL) |
2903 return; | 2903 return; |
2904 // nr is a constant. | 2904 // nr is a constant. |
2905 nl = cheapexpr(n->left, init); | 2905 nl = cheapexpr(n->left, init); |
(...skipping 317 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3223 yyerror("tracked field must be in named struct type"); | 3223 yyerror("tracked field must be in named struct type"); |
3224 if(!exportname(field->sym->name)) | 3224 if(!exportname(field->sym->name)) |
3225 yyerror("tracked field must be exported (upper case)"); | 3225 yyerror("tracked field must be exported (upper case)"); |
3226 | 3226 |
3227 l = typ(0); | 3227 l = typ(0); |
3228 l->type = field; | 3228 l->type = field; |
3229 l->down = curfn->paramfld; | 3229 l->down = curfn->paramfld; |
3230 curfn->paramfld = l; | 3230 curfn->paramfld = l; |
3231 } | 3231 } |
3232 | 3232 |
LEFT | RIGHT |