~ubuntu-branches/ubuntu/trusty/golang/trusty

« back to all changes in this revision

Viewing changes to src/cmd/8g/cgen64.c

  • Committer: Package Import Robot
  • Author(s): James Page
  • Date: 2013-08-20 14:06:23 UTC
  • mfrom: (14.1.23 saucy-proposed)
  • Revision ID: package-import@ubuntu.com-20130820140623-b414jfxi3m0qkmrq
Tags: 2:1.1.2-2ubuntu1
* Merge from Debian unstable (LP: #1211749, #1202027). Remaining changes:
  - 016-armhf-elf-header.patch: Use correct ELF header for armhf binaries.
  - d/control,control.cross: Update Breaks/Replaces for Ubuntu
    versions to ensure smooth upgrades, regenerate control file.

Show diffs side-by-side

added added

removed removed

Lines of Context:
49
49
        case OADD:
50
50
        case OSUB:
51
51
        case OMUL:
 
52
        case OLROT:
52
53
        case OLSH:
53
54
        case ORSH:
54
55
        case OAND:
113
114
                // if DX and EX are zero, use 32 x 32 -> 64 unsigned multiply.
114
115
                gins(AMOVL, &dx, &fx);
115
116
                gins(AORL, &ex, &fx);
116
 
                p1 = gbranch(AJNE, T);
 
117
                p1 = gbranch(AJNE, T, 0);
117
118
                gins(AMULL, &cx, N);    // implicit &ax
118
 
                p2 = gbranch(AJMP, T);
 
119
                p2 = gbranch(AJMP, T, 0);
119
120
                patch(p1, pc);
120
121
 
121
122
                // full 64x64 -> 64, from 32x32 -> 64.
131
132
                regfree(&ex);
132
133
                regfree(&fx);
133
134
                break;
 
135
        
 
136
        case OLROT:
 
137
                // We only rotate by a constant c in [0,64).
 
138
                // if c >= 32:
 
139
                //      lo, hi = hi, lo
 
140
                //      c -= 32
 
141
                // if c == 0:
 
142
                //      no-op
 
143
                // else:
 
144
                //      t = hi
 
145
                //      shld hi:lo, c
 
146
                //      shld lo:t, c
 
147
                v = mpgetfix(r->val.u.xval);
 
148
                if(v >= 32) {
 
149
                        // reverse during load to do the first 32 bits of rotate
 
150
                        v -= 32;
 
151
                        gins(AMOVL, &lo1, &dx);
 
152
                        gins(AMOVL, &hi1, &ax);
 
153
                } else {
 
154
                        gins(AMOVL, &lo1, &ax);
 
155
                        gins(AMOVL, &hi1, &dx);
 
156
                }
 
157
                if(v == 0) {
 
158
                        // done
 
159
                } else {
 
160
                        gins(AMOVL, &dx, &cx);
 
161
                        p1 = gins(ASHLL, ncon(v), &dx);
 
162
                        p1->from.index = D_AX;  // double-width shift
 
163
                        p1->from.scale = 0;
 
164
                        p1 = gins(ASHLL, ncon(v), &ax);
 
165
                        p1->from.index = D_CX;  // double-width shift
 
166
                        p1->from.scale = 0;
 
167
                }
 
168
                break;
134
169
 
135
170
        case OLSH:
136
171
                if(r->op == OLITERAL) {
178
213
                p1 = P;
179
214
                if(is64(r->type)) {
180
215
                        gins(ACMPL, &hi2, ncon(0));
181
 
                        p1 = gbranch(AJNE, T);
 
216
                        p1 = gbranch(AJNE, T, +1);
182
217
                        gins(AMOVL, &lo2, &cx);
183
218
                } else {
184
219
                        cx.type = types[TUINT32];
187
222
 
188
223
                // if shift count is >=64, zero value
189
224
                gins(ACMPL, &cx, ncon(64));
190
 
                p2 = gbranch(optoas(OLT, types[TUINT32]), T);
 
225
                p2 = gbranch(optoas(OLT, types[TUINT32]), T, +1);
191
226
                if(p1 != P)
192
227
                        patch(p1, pc);
193
228
                gins(AXORL, &dx, &dx);
196
231
 
197
232
                // if shift count is >= 32, zero low.
198
233
                gins(ACMPL, &cx, ncon(32));
199
 
                p1 = gbranch(optoas(OLT, types[TUINT32]), T);
 
234
                p1 = gbranch(optoas(OLT, types[TUINT32]), T, +1);
200
235
                gins(AMOVL, &ax, &dx);
201
236
                gins(ASHLL, &cx, &dx);  // SHLL only uses bottom 5 bits of count
202
237
                gins(AXORL, &ax, &ax);
203
 
                p2 = gbranch(AJMP, T);
 
238
                p2 = gbranch(AJMP, T, 0);
204
239
                patch(p1, pc);
205
240
 
206
241
                // general shift
267
302
                p1 = P;
268
303
                if(is64(r->type)) {
269
304
                        gins(ACMPL, &hi2, ncon(0));
270
 
                        p1 = gbranch(AJNE, T);
 
305
                        p1 = gbranch(AJNE, T, +1);
271
306
                        gins(AMOVL, &lo2, &cx);
272
307
                } else {
273
308
                        cx.type = types[TUINT32];
276
311
 
277
312
                // if shift count is >=64, zero or sign-extend value
278
313
                gins(ACMPL, &cx, ncon(64));
279
 
                p2 = gbranch(optoas(OLT, types[TUINT32]), T);
 
314
                p2 = gbranch(optoas(OLT, types[TUINT32]), T, +1);
280
315
                if(p1 != P)
281
316
                        patch(p1, pc);
282
317
                if(hi1.type->etype == TINT32) {
290
325
 
291
326
                // if shift count is >= 32, sign-extend hi.
292
327
                gins(ACMPL, &cx, ncon(32));
293
 
                p1 = gbranch(optoas(OLT, types[TUINT32]), T);
 
328
                p1 = gbranch(optoas(OLT, types[TUINT32]), T, +1);
294
329
                gins(AMOVL, &dx, &ax);
295
330
                if(hi1.type->etype == TINT32) {
296
331
                        gins(ASARL, &cx, &ax);  // SARL only uses bottom 5 bits of count
299
334
                        gins(ASHRL, &cx, &ax);
300
335
                        gins(AXORL, &dx, &dx);
301
336
                }
302
 
                p2 = gbranch(AJMP, T);
 
337
                p2 = gbranch(AJMP, T, 0);
303
338
                patch(p1, pc);
304
339
 
305
340
                // general shift
427
462
 * nl is memory; nr is constant or memory.
428
463
 */
429
464
void
430
 
cmp64(Node *nl, Node *nr, int op, Prog *to)
 
465
cmp64(Node *nl, Node *nr, int op, int likely, Prog *to)
431
466
{
432
467
        Node lo1, hi1, lo2, hi2, rr;
433
468
        Prog *br;
457
492
                // cmp lo
458
493
                // jeq to
459
494
                // L:
460
 
                br = gbranch(AJNE, T);
 
495
                br = gbranch(AJNE, T, -likely);
461
496
                break;
462
497
        case ONE:
463
498
                // cmp hi
464
499
                // jne to
465
500
                // cmp lo
466
501
                // jne to
467
 
                patch(gbranch(AJNE, T), to);
 
502
                patch(gbranch(AJNE, T, likely), to);
468
503
                break;
469
504
        case OGE:
470
505
        case OGT:
474
509
                // cmp lo
475
510
                // jge to (or jgt to)
476
511
                // L:
477
 
                patch(gbranch(optoas(OGT, t), T), to);
478
 
                br = gbranch(optoas(OLT, t), T);
 
512
                patch(gbranch(optoas(OGT, t), T, likely), to);
 
513
                br = gbranch(optoas(OLT, t), T, -likely);
479
514
                break;
480
515
        case OLE:
481
516
        case OLT:
485
520
                // cmp lo
486
521
                // jle to (or jlt to)
487
522
                // L:
488
 
                patch(gbranch(optoas(OLT, t), T), to);
489
 
                br = gbranch(optoas(OGT, t), T);
 
523
                patch(gbranch(optoas(OLT, t), T, likely), to);
 
524
                br = gbranch(optoas(OGT, t), T, -likely);
490
525
                break;
491
526
        }
492
527
 
502
537
        }
503
538
 
504
539
        // jump again
505
 
        patch(gbranch(optoas(op, t), T), to);
 
540
        patch(gbranch(optoas(op, t), T, likely), to);
506
541
 
507
542
        // point first branch down here if appropriate
508
543
        if(br != P)