OLD | NEW |
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 #undef EXTERN | 5 #undef EXTERN |
6 #define EXTERN | 6 #define EXTERN |
7 #include <u.h> | 7 #include <u.h> |
8 #include <libc.h> | 8 #include <libc.h> |
9 #include "gg.h" | 9 #include "gg.h" |
10 #include "opt.h" | 10 #include "opt.h" |
(...skipping 960 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
971 regfree(&n1); | 971 regfree(&n1); |
972 regfree(&n2); | 972 regfree(&n2); |
973 | 973 |
974 ret: | 974 ret: |
975 ; | 975 ; |
976 } | 976 } |
977 | 977 |
978 /* | 978 /* |
979 * generate byte multiply: | 979 * generate byte multiply: |
980 * res = nl * nr | 980 * res = nl * nr |
981 * no 2-operand byte multiply instruction so have to do | 981 * there is no 2-operand byte multiply instruction so |
982 * 16-bit multiply and take bottom half. | 982 * we do a full-width multiplication and truncate afterwards. |
983 */ | 983 */ |
984 void | 984 void |
985 cgen_bmul(int op, Node *nl, Node *nr, Node *res) | 985 cgen_bmul(int op, Node *nl, Node *nr, Node *res) |
986 { | 986 { |
987 » Node n1b, n2b, n1w, n2w; | 987 » Node n1, n2, *tmp; |
988 Type *t; | 988 Type *t; |
989 int a; | 989 int a; |
990 | 990 |
991 » if(nl->ullman >= nr->ullman) { | 991 » // copy from byte to full registers |
992 » » regalloc(&n1b, nl->type, res); | 992 » t = types[TUINT64]; |
993 » » cgen(nl, &n1b); | 993 » if(issigned[nl->type->etype]) |
994 » » regalloc(&n2b, nr->type, N); | 994 » » t = types[TINT64]; |
995 » » cgen(nr, &n2b); | 995 |
996 » } else { | 996 » // largest ullman on left. |
997 » » regalloc(&n2b, nr->type, N); | 997 » if(nl->ullman < nr->ullman) { |
998 » » cgen(nr, &n2b); | 998 » » tmp = nl; |
999 » » regalloc(&n1b, nl->type, res); | 999 » » nl = nr; |
1000 » » cgen(nl, &n1b); | 1000 » » nr = tmp; |
1001 } | 1001 } |
1002 | 1002 |
1003 » // copy from byte to short registers | 1003 » regalloc(&n1, t, res); |
1004 » t = types[TUINT16]; | 1004 » cgen(nl, &n1); |
1005 » if(issigned[nl->type->etype]) | 1005 » regalloc(&n2, t, N); |
1006 » » t = types[TINT16]; | 1006 » cgen(nr, &n2); |
1007 | |
1008 » regalloc(&n2w, t, &n2b); | |
1009 » cgen(&n2b, &n2w); | |
1010 | |
1011 » regalloc(&n1w, t, &n1b); | |
1012 » cgen(&n1b, &n1w); | |
1013 | |
1014 a = optoas(op, t); | 1007 a = optoas(op, t); |
1015 » gins(a, &n2w, &n1w); | 1008 » gins(a, &n2, &n1); |
1016 » cgen(&n1w, &n1b); | 1009 » regfree(&n2); |
1017 » cgen(&n1b, res); | 1010 » gmove(&n1, res); |
1018 | 1011 » regfree(&n1); |
1019 » regfree(&n1w); | |
1020 » regfree(&n2w); | |
1021 » regfree(&n1b); | |
1022 » regfree(&n2b); | |
1023 } | 1012 } |
1024 | 1013 |
1025 void | 1014 void |
1026 clearfat(Node *nl) | 1015 clearfat(Node *nl) |
1027 { | 1016 { |
1028 uint32 w, c, q; | 1017 uint32 w, c, q; |
1029 Node n1, oldn1, ax, oldax; | 1018 Node n1, oldn1, ax, oldax; |
1030 | 1019 |
1031 /* clear a fat object */ | 1020 /* clear a fat object */ |
1032 if(debug['g']) | 1021 if(debug['g']) |
(...skipping 30 matching lines...) Expand all Loading... |
1063 gins(ASTOSB, N, N); // STOB AL,*(DI)+ | 1052 gins(ASTOSB, N, N); // STOB AL,*(DI)+ |
1064 } else | 1053 } else |
1065 while(c > 0) { | 1054 while(c > 0) { |
1066 gins(ASTOSB, N, N); // STOB AL,*(DI)+ | 1055 gins(ASTOSB, N, N); // STOB AL,*(DI)+ |
1067 c--; | 1056 c--; |
1068 } | 1057 } |
1069 | 1058 |
1070 restx(&n1, &oldn1); | 1059 restx(&n1, &oldn1); |
1071 restx(&ax, &oldax); | 1060 restx(&ax, &oldax); |
1072 } | 1061 } |
OLD | NEW |