LEFT | RIGHT |
(no file at all) | |
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 456 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
467 if(a->op != OREGISTER) | 467 if(a->op != OREGISTER) |
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 |
| 478 * res = (nl * nr) >> wordsize |
| 479 */ |
| 480 void |
| 481 cgen_hmul(Node *nl, Node *nr, Node *res) |
| 482 { |
| 483 int w; |
| 484 Node n1, n2, *tmp; |
| 485 Type *t; |
| 486 Prog *p; |
| 487 |
| 488 if(nl->ullman < nr->ullman) { |
| 489 tmp = nl; |
| 490 nl = nr; |
| 491 nr = tmp; |
| 492 } |
| 493 t = nl->type; |
| 494 w = t->width * 8; |
| 495 regalloc(&n1, t, res); |
| 496 cgen(nl, &n1); |
| 497 regalloc(&n2, t, N); |
| 498 cgen(nr, &n2); |
| 499 switch(simtype[t->etype]) { |
| 500 case TINT8: |
| 501 case TINT16: |
| 502 gins(optoas(OMUL, t), &n2, &n1); |
| 503 gshift(AMOVW, &n1, SHIFT_AR, w, &n1); |
| 504 break; |
| 505 case TUINT8: |
| 506 case TUINT16: |
| 507 gins(optoas(OMUL, t), &n2, &n1); |
| 508 gshift(AMOVW, &n1, SHIFT_LR, w, &n1); |
| 509 break; |
| 510 case TINT32: |
| 511 case TUINT32: |
| 512 // perform a long multiplication. |
| 513 if(issigned[t->etype]) |
| 514 p = gins(AMULL, &n2, N); |
| 515 else |
| 516 p = gins(AMULLU, &n2, N); |
| 517 // n2 * n1 -> (n1 n2) |
| 518 p->reg = n1.val.u.reg; |
| 519 p->to.type = D_REGREG; |
| 520 p->to.reg = n1.val.u.reg; |
| 521 p->to.offset = n2.val.u.reg; |
| 522 break; |
| 523 default: |
| 524 fatal("cgen_hmul %T", t); |
| 525 break; |
| 526 } |
| 527 cgen(&n1, res); |
| 528 regfree(&n1); |
| 529 regfree(&n2); |
| 530 } |
| 531 |
| 532 /* |
477 * generate shift according to op, one of: | 533 * generate shift according to op, one of: |
478 * res = nl << nr | 534 * res = nl << nr |
479 * res = nl >> nr | 535 * res = nl >> nr |
480 */ | 536 */ |
481 void | 537 void |
482 cgen_shift(int op, int bounded, Node *nl, Node *nr, Node *res) | 538 cgen_shift(int op, int bounded, Node *nl, Node *nr, Node *res) |
483 { | 539 { |
484 Node n1, n2, n3, nt, t, lo, hi; | 540 Node n1, n2, n3, nt, t, lo, hi; |
485 int w, v; | 541 int w, v; |
486 Prog *p1, *p2, *p3; | 542 Prog *p1, *p2, *p3; |
(...skipping 177 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
664 p = gins(AMOVBU, &nz, &dst); | 720 p = gins(AMOVBU, &nz, &dst); |
665 p->to.type = D_OREG; | 721 p->to.type = D_OREG; |
666 p->to.offset = 1; | 722 p->to.offset = 1; |
667 p->scond |= C_PBIT; | 723 p->scond |= C_PBIT; |
668 //print("2. %P\n", p); | 724 //print("2. %P\n", p); |
669 c--; | 725 c--; |
670 } | 726 } |
671 regfree(&dst); | 727 regfree(&dst); |
672 regfree(&nz); | 728 regfree(&nz); |
673 } | 729 } |
LEFT | RIGHT |