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 #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 457 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
468 return 0; | 468 return 0; |
469 if(b->op != OREGISTER) | 469 if(b->op != OREGISTER) |
470 return 0; | 470 return 0; |
471 if(a->val.u.reg != b->val.u.reg) | 471 if(a->val.u.reg != b->val.u.reg) |
472 return 0; | 472 return 0; |
473 return 1; | 473 return 1; |
474 } | 474 } |
475 | 475 |
476 /* | 476 /* |
477 * generate high multiply | 477 * generate high multiply |
478 * res = (nl * nr) >> w | 478 * res = (nl * nr) >> wordsize |
479 */ | 479 */ |
480 void | 480 void |
481 cgen_hmul(Node *nl, Node *nr, Node *res) | 481 cgen_hmul(Node *nl, Node *nr, Node *res) |
482 { | 482 { |
483 int w; | 483 int w; |
484 Node n1, n2, *tmp; | 484 Node n1, n2, *tmp; |
485 Type *t; | 485 Type *t; |
486 Prog *p; | 486 Prog *p; |
487 | 487 |
488 if(nl->ullman < nr->ullman) { | 488 if(nl->ullman < nr->ullman) { |
489 tmp = nl; | 489 tmp = nl; |
490 nl = nr; | 490 nl = nr; |
491 nr = tmp; | 491 nr = tmp; |
492 } | 492 } |
493 t = nl->type; | 493 t = nl->type; |
494 w = t->width * 8; | 494 w = t->width * 8; |
495 regalloc(&n1, t, res); | 495 regalloc(&n1, t, res); |
496 cgen(nl, &n1); | 496 cgen(nl, &n1); |
497 regalloc(&n2, t, N); | 497 regalloc(&n2, t, N); |
498 cgen(nr, &n2); | 498 cgen(nr, &n2); |
499 » switch(t->etype) { | 499 » switch(simtype[t->etype]) { |
500 case TINT8: | 500 case TINT8: |
501 case TINT16: | 501 case TINT16: |
502 gins(optoas(OMUL, t), &n2, &n1); | 502 gins(optoas(OMUL, t), &n2, &n1); |
503 gshift(AMOVW, &n1, SHIFT_AR, w, &n1); | 503 gshift(AMOVW, &n1, SHIFT_AR, w, &n1); |
504 break; | 504 break; |
505 case TUINT8: | 505 case TUINT8: |
506 case TUINT16: | 506 case TUINT16: |
507 gins(optoas(OMUL, t), &n2, &n1); | 507 gins(optoas(OMUL, t), &n2, &n1); |
508 gshift(AMOVW, &n1, SHIFT_LR, w, &n1); | 508 gshift(AMOVW, &n1, SHIFT_LR, w, &n1); |
509 break; | 509 break; |
510 case TINT32: | 510 case TINT32: |
511 case TUINT32: | 511 case TUINT32: |
512 // perform a long multiplication. | 512 // perform a long multiplication. |
513 » » if(t->etype == TINT32) | 513 » » if(issigned[t->etype]) |
514 p = gins(AMULL, &n2, N); | 514 p = gins(AMULL, &n2, N); |
515 else | 515 else |
516 p = gins(AMULLU, &n2, N); | 516 p = gins(AMULLU, &n2, N); |
517 // n2 * n1 -> (n1 n2) | 517 // n2 * n1 -> (n1 n2) |
518 p->reg = n1.val.u.reg; | 518 p->reg = n1.val.u.reg; |
519 p->to.type = D_REGREG; | 519 p->to.type = D_REGREG; |
520 p->to.reg = n1.val.u.reg; | 520 p->to.reg = n1.val.u.reg; |
521 p->to.offset = n2.val.u.reg; | 521 p->to.offset = n2.val.u.reg; |
522 break; | 522 break; |
523 default: | 523 default: |
(...skipping 196 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
720 p = gins(AMOVBU, &nz, &dst); | 720 p = gins(AMOVBU, &nz, &dst); |
721 p->to.type = D_OREG; | 721 p->to.type = D_OREG; |
722 p->to.offset = 1; | 722 p->to.offset = 1; |
723 p->scond |= C_PBIT; | 723 p->scond |= C_PBIT; |
724 //print("2. %P\n", p); | 724 //print("2. %P\n", p); |
725 c--; | 725 c--; |
726 } | 726 } |
727 regfree(&dst); | 727 regfree(&dst); |
728 regfree(&nz); | 728 regfree(&nz); |
729 } | 729 } |
LEFT | RIGHT |