orcprogram-powerpc.c 47.1 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11

#include "config.h"

#include <stdio.h>
#include <string.h>
#include <stdlib.h>

#include <unistd.h>
#include <sys/types.h>

#include <orc/orcprogram.h>
David Schleef's avatar
David Schleef committed
12
#include <orc/orcdebug.h>
13 14 15

#define SIZE 65536

16 17 18
void powerpc_emit_addi (OrcCompiler *compiler, int regd, int rega, int imm);
void powerpc_emit_lwz (OrcCompiler *compiler, int regd, int rega, int imm);
void powerpc_emit_stwu (OrcCompiler *compiler, int regs, int rega, int offset);
19

20
void powerpc_emit_ret (OrcCompiler *compiler);
David Schleef's avatar
David Schleef committed
21
void powerpc_emit_b (OrcCompiler *compiler, int label);
22 23 24
void powerpc_emit_beq (OrcCompiler *compiler, int label);
void powerpc_emit_bne (OrcCompiler *compiler, int label);
void powerpc_emit_label (OrcCompiler *compiler, int label);
David Schleef's avatar
David Schleef committed
25
void powerpc_add_fixup (OrcCompiler *compiler, int type, unsigned char *ptr, int label);
26

David Schleef's avatar
David Schleef committed
27 28 29
void orc_compiler_powerpc_init (OrcCompiler *compiler);
void orc_compiler_powerpc_assemble (OrcCompiler *compiler);
void orc_compiler_powerpc_register_rules (OrcTarget *target);
30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63

enum {
  POWERPC_R0 = ORC_GP_REG_BASE,
  POWERPC_R1,
  POWERPC_R2,
  POWERPC_R3,
  POWERPC_R4,
  POWERPC_R5,
  POWERPC_R6,
  POWERPC_R7,
  POWERPC_R8,
  POWERPC_R9,
  POWERPC_R10,
  POWERPC_R11,
  POWERPC_R12,
  POWERPC_R13,
  POWERPC_R14,
  POWERPC_R15,
  POWERPC_R16,
  POWERPC_R17,
  POWERPC_R18,
  POWERPC_R19,
  POWERPC_R20,
  POWERPC_R21,
  POWERPC_R22,
  POWERPC_R23,
  POWERPC_R24,
  POWERPC_R25,
  POWERPC_R26,
  POWERPC_R27,
  POWERPC_R28,
  POWERPC_R29,
  POWERPC_R30,
  POWERPC_R31,
David Schleef's avatar
David Schleef committed
64
  POWERPC_V0 = ORC_VEC_REG_BASE,
65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94
  POWERPC_V1,
  POWERPC_V2,
  POWERPC_V3,
  POWERPC_V4,
  POWERPC_V5,
  POWERPC_V6,
  POWERPC_V7,
  POWERPC_V8,
  POWERPC_V9,
  POWERPC_V10,
  POWERPC_V11,
  POWERPC_V12,
  POWERPC_V13,
  POWERPC_V14,
  POWERPC_V15,
  POWERPC_V16,
  POWERPC_V17,
  POWERPC_V18,
  POWERPC_V19,
  POWERPC_V20,
  POWERPC_V21,
  POWERPC_V22,
  POWERPC_V23,
  POWERPC_V24,
  POWERPC_V25,
  POWERPC_V26,
  POWERPC_V27,
  POWERPC_V28,
  POWERPC_V29,
  POWERPC_V30,
David Schleef's avatar
David Schleef committed
95
  POWERPC_V31
96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131
};

const char *
powerpc_get_regname(int i)
{
  static const char *powerpc_regs[] = {
    "r0", "r1", "r2", "r3", "r4", "r5", "r6", "r7", "r8", "r9",
    "r10", "r11", "r12", "r13", "r14", "r15", "r16", "r17", "r18", "r19",
    "r20", "r21", "r22", "r23", "r24", "r25", "r26", "r27", "r28", "r29",
    "r30", "r31",
    "v0", "v1", "v2", "v3", "v4", "v5", "v6", "v7", "v8", "v9",
    "v10", "v11", "v12", "v13", "v14", "v15", "v16", "v17", "v18", "v19",
    "v20", "v21", "v22", "v23", "v24", "v25", "v26", "v27", "v28", "v29",
    "v30", "v31",
  };

  if (i>=ORC_GP_REG_BASE && i<ORC_GP_REG_BASE + 64) {
    return powerpc_regs[i - ORC_GP_REG_BASE];
  }
  switch (i) {
    case 0:
      return "UNALLOCATED";
    case 1:
      return "direct";
    default:
      return "ERROR";
  }
}

int
powerpc_regnum (int i)
{
  return (i-ORC_GP_REG_BASE)&0x1f;
}

void
132
powerpc_emit(OrcCompiler *compiler, unsigned int insn)
133
{
134 135 136 137
  *compiler->codeptr++ = (insn>>24);
  *compiler->codeptr++ = (insn>>16);
  *compiler->codeptr++ = (insn>>8);
  *compiler->codeptr++ = (insn>>0);
138 139 140
}

void
141
powerpc_emit_prologue (OrcCompiler *compiler)
142 143 144
{
  int i;

David Schleef's avatar
David Schleef committed
145 146
  ORC_ASM_CODE (compiler, ".global %s\n", compiler->program->name);
  ORC_ASM_CODE (compiler, "%s:\n", compiler->program->name);
147

148
  powerpc_emit_stwu (compiler, POWERPC_R1, POWERPC_R1, -16);
149 150

  for(i=POWERPC_R13;i<=POWERPC_R31;i++){
151 152
    if (compiler->used_regs[i]) {
      //powerpc_emit_push (compiler, 4, i);
153 154 155 156 157
    }
  }
}

void
158
powerpc_emit_addi (OrcCompiler *compiler, int regd, int rega, int imm)
159 160 161
{
  unsigned int insn;

162
  ORC_ASM_CODE(compiler,"  addi %s, %s, %d\n",
163 164 165 166 167
      powerpc_get_regname(regd),
      powerpc_get_regname(rega), imm);
  insn = (14<<26) | (powerpc_regnum (regd)<<21) | (powerpc_regnum (rega)<<16);
  insn |= imm&0xffff;

168
  powerpc_emit (compiler, insn);
169 170 171
}

void
172
powerpc_emit_lwz (OrcCompiler *compiler, int regd, int rega, int imm)
173 174 175
{
  unsigned int insn;

176
  ORC_ASM_CODE(compiler,"  lwz %s, %d(%s)\n",
177 178 179 180 181
      powerpc_get_regname(regd),
      imm, powerpc_get_regname(rega));
  insn = (32<<26) | (powerpc_regnum (regd)<<21) | (powerpc_regnum (rega)<<16);
  insn |= imm&0xffff;

182
  powerpc_emit (compiler, insn);
183 184 185
}

void
186
powerpc_emit_stwu (OrcCompiler *compiler, int regs, int rega, int offset)
187 188 189
{
  unsigned int insn;

190
  ORC_ASM_CODE(compiler,"  stwu %s, %d(%s)\n",
191 192 193 194 195
      powerpc_get_regname(regs),
      offset, powerpc_get_regname(rega));
  insn = (37<<26) | (powerpc_regnum (regs)<<21) | (powerpc_regnum (rega)<<16);
  insn |= offset&0xffff;

196
  powerpc_emit (compiler, insn);
197 198 199
}

void
200
powerpc_emit_srawi (OrcCompiler *compiler, int regd, int rega, int shift,
201 202 203 204
    int record)
{
  unsigned int insn;

205
  ORC_ASM_CODE(compiler,"  srawi%s %s, %s, %d\n", (record)?".":"",
206 207 208 209 210 211
      powerpc_get_regname(regd),
      powerpc_get_regname(rega), shift);

  insn = (31<<26) | (powerpc_regnum (regd)<<21) | (powerpc_regnum (rega)<<16);
  insn |= (shift<<11) | (824<<1) | record;

212
  powerpc_emit (compiler, insn);
213 214 215
}

void
216
powerpc_emit_655510 (OrcCompiler *compiler, int major, int d, int a, int b,
217 218 219 220 221 222 223
    int minor)
{
  unsigned int insn;

  insn = (major<<26) | (d<<21) | (a<<16);
  insn |= (b<<11) | (minor<<0);

224
  powerpc_emit (compiler, insn);
225 226 227
}

void
David Schleef's avatar
David Schleef committed
228
powerpc_emit_X (OrcCompiler *compiler, unsigned int insn, int d, int a, int b)
229
{
David Schleef's avatar
David Schleef committed
230
#if 0
231 232 233 234 235
  unsigned int insn;

  insn = (major<<26) | (d<<21) | (a<<16);
  insn |= (b<<11) | (minor<<1) | (0<<0);

David Schleef's avatar
David Schleef committed
236 237
  powerpc_emit (compiler, insn);
#endif
David Schleef's avatar
David Schleef committed
238 239 240
  insn |= ((d&0x1f)<<21);
  insn |= ((a&0x1f)<<16);
  insn |= ((b&0x1f)<<11);
241
  powerpc_emit (compiler, insn);
242 243 244
}

void
245
powerpc_emit_VA (OrcCompiler *compiler, int major, int d, int a, int b,
246 247 248 249 250 251 252
    int c, int minor)
{
  unsigned int insn;

  insn = (major<<26) | (d<<21) | (a<<16);
  insn |= (b<<11) | (c<<6) | (minor<<0);

253
  powerpc_emit (compiler, insn);
254 255 256
}

void
David Schleef's avatar
David Schleef committed
257
powerpc_emit_VX (OrcCompiler *compiler, unsigned int insn, int d, int a, int b)
258
{
David Schleef's avatar
David Schleef committed
259 260 261
  insn |= ((d&0x1f)<<21);
  insn |= ((a&0x1f)<<16);
  insn |= ((b&0x1f)<<11);
262
  powerpc_emit (compiler, insn);
263 264
}

David Schleef's avatar
David Schleef committed
265 266 267 268 269 270 271 272 273 274 275 276 277
void
powerpc_emit_VX_2 (OrcCompiler *p, const char *name,
    unsigned int insn, int d, int a, int b)
{
  ORC_ASM_CODE(p,"  %s %s, %s, %s\n", name,
      powerpc_get_regname(d),
      powerpc_get_regname(a),
      powerpc_get_regname(b));
  powerpc_emit_VX(p, insn,
      powerpc_regnum(d),
      powerpc_regnum(a),
      powerpc_regnum(b));
}
278 279

void
280
powerpc_emit_epilogue (OrcCompiler *compiler)
281 282 283 284
{
  int i;

  for(i=POWERPC_R31;i>=POWERPC_R31;i--){
285 286
    if (compiler->used_regs[i]) {
      //powerpc_emit_pop (compiler, 4, i);
287 288 289
    }
  }

290 291 292
  powerpc_emit_addi (compiler, POWERPC_R1, POWERPC_R1, 16);
  ORC_ASM_CODE(compiler,"  blr\n");
  powerpc_emit(compiler, 0x4e800020);
293 294 295
}

void
296
powerpc_do_fixups (OrcCompiler *compiler)
297 298 299 300
{
  int i;
  unsigned int insn;

301 302 303 304
  for(i=0;i<compiler->n_fixups;i++){
    if (compiler->fixups[i].type == 0) {
      unsigned char *label = compiler->labels[compiler->fixups[i].label];
      unsigned char *ptr = compiler->fixups[i].ptr;
305 306 307

      insn = *(unsigned int *)ptr;
      *(unsigned int *)ptr = (insn&0xffff0000) | ((insn + (label-ptr))&0xffff);
David Schleef's avatar
David Schleef committed
308 309 310 311 312 313
    } else {
      unsigned char *label = compiler->labels[compiler->fixups[i].label];
      unsigned char *ptr = compiler->fixups[i].ptr;

      insn = *(unsigned int *)ptr;
      *(unsigned int *)ptr = (insn&0xffff0000) | ((insn + (label-compiler->program->code))&0xffff);
314 315 316 317 318
    }
  }
}

void
319
powerpc_flush (OrcCompiler *compiler)
320 321 322 323 324
{
#ifdef HAVE_POWERPC
  unsigned char *ptr;
  int cache_line_size = 32;
  int i;
David Schleef's avatar
David Schleef committed
325
  int size = compiler->codeptr - compiler->program->code;
326

David Schleef's avatar
David Schleef committed
327
  ptr = compiler->program->code;
328 329 330 331 332
  for (i=0;i<size;i+=cache_line_size) {
    __asm__ __volatile__ ("dcbst %0,%1" :: "r" (ptr), "r" (i));
  }
  __asm__ __volatile ("sync");

David Schleef's avatar
David Schleef committed
333
  ptr = compiler->program->code_exec;
334 335 336 337 338 339 340
  for (i=0;i<size;i+=cache_line_size) {
    __asm__ __volatile__ ("icbi %0,%1" :: "r" (ptr), "r" (i));
  }
  __asm__ __volatile ("isync");
#endif
}

David Schleef's avatar
David Schleef committed
341 342 343 344 345 346 347 348 349 350 351 352
static OrcTarget powerpc_target = {
  "powerpc",
#ifdef HAVE_POWERPC
  TRUE,
#else
  FALSE,
#endif
  ORC_VEC_REG_BASE,
  orc_compiler_powerpc_init,
  orc_compiler_powerpc_assemble
};

353 354 355
void
orc_powerpc_init (void)
{
David Schleef's avatar
David Schleef committed
356 357 358
  orc_target_register (&powerpc_target);

  orc_compiler_powerpc_register_rules (&powerpc_target);
359 360 361
}

void
362
orc_compiler_powerpc_init (OrcCompiler *compiler)
363 364 365 366
{
  int i;

  for(i=0;i<32;i++){
367 368
    compiler->valid_regs[POWERPC_R0+i] = 1;
    compiler->valid_regs[POWERPC_V0+i] = 1;
369
  }
370 371 372 373 374
  compiler->valid_regs[POWERPC_R0] = 0; /* used for temp space */
  compiler->valid_regs[POWERPC_R1] = 0; /* stack pointer */
  compiler->valid_regs[POWERPC_R2] = 0; /* TOC pointer */
  compiler->valid_regs[POWERPC_R3] = 0; /* pointer to OrcExecutor */
  compiler->valid_regs[POWERPC_R13] = 0; /* reserved */
David Schleef's avatar
David Schleef committed
375 376 377

  compiler->tmpreg = POWERPC_V0;
  compiler->valid_regs[compiler->tmpreg] = 0;
378 379

  for(i=14;i<32;i++){
380
    compiler->save_regs[POWERPC_R0 + i] = 1;
381 382
  }
  for(i=20;i<32;i++){
383
    compiler->save_regs[POWERPC_V0 + i] = 1;
384 385
  }

David Schleef's avatar
David Schleef committed
386
  compiler->loop_shift = 0;
387 388
}

David Schleef's avatar
David Schleef committed
389 390 391 392 393 394
static void
powerpc_load_constant (OrcCompiler *p, int i, int reg)
{
  int j;
  int value = p->constants[i].value;
  int greg = POWERPC_R31;
David Schleef's avatar
David Schleef committed
395
  int label_skip, label_data;
David Schleef's avatar
David Schleef committed
396 397 398 399 400 401 402 403 404 405 406 407 408

#if 0
  switch (p->constants[i].type) {
    case ORC_CONST_ZERO:
      powerpc_emit_VX_2(p, "vxor", 0x100004c4, reg, reg, reg);
      break;
    case ORC_CONST_SPLAT_B:
      if (value < 16 && value >= -16) {
        ORC_ASM_CODE(p,"  vspltisb %s, %d\n",
            powerpc_get_regname(reg), value&0x1f);
        powerpc_emit_VX(p, 0x1000020c,
            powerpc_regnum(reg), value & 0x1f, 0);
      } else {
David Schleef's avatar
David Schleef committed
409
        ORC_COMPILER_ERROR(p,"can't load constant");
David Schleef's avatar
David Schleef committed
410 411 412 413 414 415 416 417 418
      }
      break;
    case ORC_CONST_SPLAT_W:
      if (value < 16 && value >= -16) {
        ORC_ASM_CODE(p,"  vspltish %s, %d\n",
            powerpc_get_regname(reg), value&0x1f);
        powerpc_emit_VX(p, 0x1000024c,
            powerpc_regnum(reg), value & 0x1f, 0);
      } else {
David Schleef's avatar
David Schleef committed
419
        ORC_COMPILER_ERROR(p,"can't load constant");
David Schleef's avatar
David Schleef committed
420 421 422 423 424 425 426 427 428
      }
      break;
    case ORC_CONST_SPLAT_L:
      if (value < 16 && value >= -16) {
        ORC_ASM_CODE(p,"  vspltisw %s, %d\n",
            powerpc_get_regname(reg), value&0x1f);
        powerpc_emit_VX(p, 0x1000028c,
            powerpc_regnum(reg), value & 0x1f, 0);
      } else {
David Schleef's avatar
David Schleef committed
429
        ORC_COMPILER_ERROR(p,"can't load constant");
David Schleef's avatar
David Schleef committed
430 431 432
      }
      break;
    default:
David Schleef's avatar
David Schleef committed
433
      ORC_COMPILER_ERROR(p,"unhandled");
David Schleef's avatar
David Schleef committed
434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467
      break;
  }
#endif

  switch (p->constants[i].type) {
    case ORC_CONST_ZERO:
      for(j=0;j<4;j++){
        p->constants[i].full_value[j] = 0;
      }
      break;
    case ORC_CONST_SPLAT_B:
      value &= 0xff;
      value |= (value<<8);
      value |= (value<<16);
      for(j=0;j<4;j++){
        p->constants[i].full_value[j] = value;
      }
      break;
    case ORC_CONST_SPLAT_W:
      value &= 0xffff;
      value |= (value<<16);
      for(j=0;j<4;j++){
        p->constants[i].full_value[j] = value;
      }
      break;
    case ORC_CONST_SPLAT_L:
      for(j=0;j<4;j++){
        p->constants[i].full_value[j] = value;
      }
      break;
    default:
      break;
  }

David Schleef's avatar
David Schleef committed
468 469 470 471
  label_skip = orc_compiler_label_new (p);
  label_data = orc_compiler_label_new (p);

  powerpc_emit_b (p, label_skip);
David Schleef's avatar
David Schleef committed
472 473 474 475 476 477

  while ((p->codeptr - p->program->code) & 0xf) {
    ORC_ASM_CODE(p,"  .long 0x00000000\n");
    powerpc_emit (p, 0x00000000);
  }

David Schleef's avatar
David Schleef committed
478
  powerpc_emit_label (p, label_data);
David Schleef's avatar
David Schleef committed
479 480 481 482 483
  for(j=0;j<4;j++){
    ORC_ASM_CODE(p,"  .long 0x%08x\n", p->constants[i].full_value[j]);
    powerpc_emit (p, p->constants[i].full_value[j]);
  }

David Schleef's avatar
David Schleef committed
484
  powerpc_emit_label (p, label_skip);
David Schleef's avatar
David Schleef committed
485 486 487 488 489 490 491 492
  powerpc_emit_lwz (p,
      greg,
      POWERPC_R3,
      (int)ORC_STRUCT_OFFSET(OrcExecutor, program));
  powerpc_emit_lwz (p,
      greg, greg,
      (int)ORC_STRUCT_OFFSET(OrcProgram, code_exec));

David Schleef's avatar
David Schleef committed
493
  powerpc_add_fixup (p, 1, p->codeptr, label_data);
David Schleef's avatar
David Schleef committed
494 495 496 497 498
  {
    unsigned int insn;

    ORC_ASM_CODE(p,"  addi %s, %s, %db - %s\n",
        powerpc_get_regname(greg),
David Schleef's avatar
David Schleef committed
499
        powerpc_get_regname(greg), label_data, p->program->name);
David Schleef's avatar
David Schleef committed
500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539
    insn = (14<<26) | (powerpc_regnum (greg)<<21) | (powerpc_regnum (greg)<<16);
    insn |= 0;

    powerpc_emit (p, insn);
  }

  ORC_ASM_CODE(p,"  lvx %s, 0, %s\n",
      powerpc_get_regname(reg),
      powerpc_get_regname(greg));
  powerpc_emit_X (p, 0x7c0000ce, reg, 0, greg);

}

static int
powerpc_get_constant (OrcCompiler *p, int type, int value)
{
  int reg = p->tmpreg;
  int i;

  for(i=0;i<p->n_constants;i++){
    if (p->constants[i].type == type &&
        p->constants[i].value == value) {
      if (p->constants[i].alloc_reg != 0) {
        return p->constants[i].alloc_reg;
      }
      break;
    }
  }
  if (i == p->n_constants) {
    p->n_constants++;
    p->constants[i].type = type;
    p->constants[i].value = value;
    p->constants[i].alloc_reg = 0;
  }

  powerpc_load_constant (p, i, reg);

  return reg;
}

540
void
541
powerpc_load_constants (OrcCompiler *compiler)
542
{
David Schleef's avatar
David Schleef committed
543
  OrcVariable *var;
544
  int i;
David Schleef's avatar
David Schleef committed
545 546 547
  int j;
  int greg = POWERPC_R0;

548
  for(i=0;i<ORC_N_VARIABLES;i++){
David Schleef's avatar
David Schleef committed
549 550
    var = compiler->vars + i;

551
    if (compiler->vars[i].name == NULL) continue;
552
    switch (compiler->vars[i].vartype) {
553
      case ORC_VAR_TYPE_CONST:
David Schleef's avatar
David Schleef committed
554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614
        j = compiler->n_constants;
        compiler->n_constants++;
        if (compiler->vars[i].size == 1) {
          compiler->constants[j].type = ORC_CONST_SPLAT_B;
        } else if (compiler->vars[i].size == 2) {
          compiler->constants[j].type = ORC_CONST_SPLAT_W;
        } else {
          compiler->constants[j].type = ORC_CONST_SPLAT_L;
        }
        compiler->constants[j].value = compiler->vars[i].value;
        compiler->constants[j].alloc_reg = compiler->vars[i].alloc;
        break;
      case ORC_VAR_TYPE_PARAM:
        powerpc_emit_addi (compiler,
            greg, POWERPC_R3,
            (int)ORC_STRUCT_OFFSET(OrcExecutor, params[i]));
        ORC_ASM_CODE(compiler,"  lvewx %s, 0, %s\n", 
            powerpc_get_regname (var->alloc),
            powerpc_get_regname (greg));
        powerpc_emit_X (compiler, 0x7c00008e, powerpc_regnum(var->alloc),
            0, powerpc_regnum(greg));

        ORC_ASM_CODE(compiler,"  lvsl %s, 0, %s\n", 
            powerpc_get_regname (POWERPC_V0),
            powerpc_get_regname (greg));
        powerpc_emit_X (compiler, 0x7c00000c, powerpc_regnum(POWERPC_V0),
            0, powerpc_regnum(greg));

        ORC_ASM_CODE(compiler,"  vperm %s, %s, %s, %s\n", 
            powerpc_get_regname (var->alloc),
            powerpc_get_regname (var->alloc),
            powerpc_get_regname (var->alloc),
            powerpc_get_regname (POWERPC_V0));
        powerpc_emit_VA (compiler, 4,
            powerpc_regnum(var->alloc),
            powerpc_regnum(var->alloc),
            powerpc_regnum(var->alloc),
            powerpc_regnum(POWERPC_V0), 43);
        switch (var->size) {
          case 1:
            ORC_ASM_CODE(compiler,"  vspltb %s, %s, 3\n",
                powerpc_get_regname (var->alloc),
                powerpc_get_regname (var->alloc));
            powerpc_emit_VX (compiler, 0x1000020c,
                powerpc_regnum(var->alloc), 3, powerpc_regnum(var->alloc));
            break;
          case 2:
            ORC_ASM_CODE(compiler,"  vsplth %s, %s, 1\n", 
                powerpc_get_regname (var->alloc),
                powerpc_get_regname (var->alloc));
            powerpc_emit_VX (compiler, 0x1000024c,
                powerpc_regnum(var->alloc), 1, powerpc_regnum(var->alloc));
            break;
          case 4:
            ORC_ASM_CODE(compiler,"  vspltw %s, %s, 0\n", 
                powerpc_get_regname (var->alloc),
                powerpc_get_regname (var->alloc));
            powerpc_emit_VX (compiler, 0x1000028c,
                powerpc_regnum(var->alloc), 0, powerpc_regnum(var->alloc));
            break;
        }
615 616 617
        break;
      case ORC_VAR_TYPE_SRC:
      case ORC_VAR_TYPE_DEST:
618 619 620
        if (compiler->vars[i].ptr_register) {
          powerpc_emit_lwz (compiler,
              compiler->vars[i].ptr_register,
621 622 623 624
              POWERPC_R3,
              (int)ORC_STRUCT_OFFSET(OrcExecutor, arrays[i]));
        } else {
          /* FIXME */
625
          ORC_ASM_CODE(compiler,"ERROR");
626 627 628 629 630 631
        }
        break;
      default:
        break;
    }
  }
David Schleef's avatar
David Schleef committed
632 633 634 635 636 637

  for(i=0;i<compiler->n_constants;i++){
    if (compiler->constants[i].alloc_reg > 0) {
      powerpc_load_constant (compiler, i, compiler->constants[i].alloc_reg);
    }
  }
638 639 640
}

void
641
powerpc_emit_load_src (OrcCompiler *compiler, OrcVariable *var)
642 643 644 645
{
  int ptr_reg;
  ptr_reg = var->ptr_register;

646
  switch (compiler->loop_shift) {
David Schleef's avatar
David Schleef committed
647
    case 0:
David Schleef's avatar
David Schleef committed
648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670
      switch (var->size) {
        case 1:
          ORC_ASM_CODE(compiler,"  lvebx %s, 0, %s\n", 
              powerpc_get_regname (var->alloc),
              powerpc_get_regname (ptr_reg));
          powerpc_emit_X (compiler, 0x7c00000e, powerpc_regnum(var->alloc),
              0, powerpc_regnum(ptr_reg));
          break;
        case 2:
          ORC_ASM_CODE(compiler,"  lvehx %s, 0, %s\n", 
              powerpc_get_regname (var->alloc),
              powerpc_get_regname (ptr_reg));
          powerpc_emit_X (compiler, 0x7c00004e, powerpc_regnum(var->alloc),
              0, powerpc_regnum(ptr_reg));
          break;
        case 4:
          ORC_ASM_CODE(compiler,"  lvewx %s, 0, %s\n", 
              powerpc_get_regname (var->alloc),
              powerpc_get_regname (ptr_reg));
          powerpc_emit_X (compiler, 0x7c00008e, powerpc_regnum(var->alloc),
              0, powerpc_regnum(ptr_reg));
          break;
      }
671
      ORC_ASM_CODE(compiler,"  lvsl %s, 0, %s\n", 
672 673
          powerpc_get_regname (POWERPC_V0),
          powerpc_get_regname (ptr_reg));
David Schleef's avatar
David Schleef committed
674 675
      powerpc_emit_X (compiler, 0x7c00000c, powerpc_regnum(POWERPC_V0),
          0, powerpc_regnum(ptr_reg));
676
      ORC_ASM_CODE(compiler,"  vperm %s, %s, %s, %s\n", 
677 678 679 680
          powerpc_get_regname (var->alloc),
          powerpc_get_regname (var->alloc),
          powerpc_get_regname (var->alloc),
          powerpc_get_regname (POWERPC_V0));
681
      powerpc_emit_VA (compiler, 4,
682 683 684 685 686 687
          powerpc_regnum(var->alloc),
          powerpc_regnum(var->alloc),
          powerpc_regnum(var->alloc),
          powerpc_regnum(POWERPC_V0), 43);
      break;
    default:
688
      ORC_ASM_CODE(compiler,"ERROR\n");
689 690 691 692
  }
}

void
693
powerpc_emit_store_dest (OrcCompiler *compiler, OrcVariable *var)
694 695 696 697
{
  int ptr_reg;
  ptr_reg = var->ptr_register;

698
  switch (compiler->loop_shift) {
David Schleef's avatar
David Schleef committed
699
    case 0:
700
      ORC_ASM_CODE(compiler,"  lvsr %s, 0, %s\n", 
701 702
          powerpc_get_regname (POWERPC_V0),
          powerpc_get_regname (ptr_reg));
David Schleef's avatar
David Schleef committed
703 704
      powerpc_emit_X (compiler, 0x7c00004c, powerpc_regnum(POWERPC_V0),
          0, powerpc_regnum(ptr_reg));
705
      ORC_ASM_CODE(compiler,"  vperm %s, %s, %s, %s\n", 
706 707 708 709
          powerpc_get_regname (var->alloc),
          powerpc_get_regname (var->alloc),
          powerpc_get_regname (var->alloc),
          powerpc_get_regname (POWERPC_V0));
710
      powerpc_emit_VA (compiler, 4,
711 712 713 714
          powerpc_regnum(var->alloc),
          powerpc_regnum(var->alloc),
          powerpc_regnum(var->alloc),
          powerpc_regnum(POWERPC_V0), 43);
David Schleef's avatar
David Schleef committed
715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740
      switch (var->size) {
        case 1:
          ORC_ASM_CODE(compiler,"  stvebx %s, 0, %s\n", 
              powerpc_get_regname (var->alloc),
              powerpc_get_regname (ptr_reg));
          powerpc_emit_X (compiler, 0x7c00010e,
              powerpc_regnum(var->alloc),
              0, powerpc_regnum(ptr_reg));
          break;
        case 2:
          ORC_ASM_CODE(compiler,"  stvehx %s, 0, %s\n", 
              powerpc_get_regname (var->alloc),
              powerpc_get_regname (ptr_reg));
          powerpc_emit_X (compiler, 0x7c00014e,
              powerpc_regnum(var->alloc),
              0, powerpc_regnum(ptr_reg));
          break;
        case 4:
          ORC_ASM_CODE(compiler,"  stvewx %s, 0, %s\n", 
              powerpc_get_regname (var->alloc),
              powerpc_get_regname (ptr_reg));
          powerpc_emit_X (compiler, 0x7c00018e,
              powerpc_regnum(var->alloc),
              0, powerpc_regnum(ptr_reg));
          break;
      }
741 742
      break;
    default:
743
      ORC_ASM_CODE(compiler,"ERROR\n");
744 745 746 747
  }
}

void
David Schleef's avatar
David Schleef committed
748
orc_compiler_powerpc_assemble (OrcCompiler *compiler)
749 750 751 752
{
  int j;
  int k;
  OrcInstruction *insn;
David Schleef's avatar
David Schleef committed
753 754
  OrcStaticOpcode *opcode;
  //OrcVariable *args[10];
755
  OrcRule *rule;
David Schleef's avatar
David Schleef committed
756 757 758 759 760
  int label_loop_start;
  int label_leave;

  label_loop_start = orc_compiler_label_new (compiler);
  label_leave = orc_compiler_label_new (compiler);
761

762
  powerpc_emit_prologue (compiler);
763

764
  powerpc_emit_lwz (compiler, POWERPC_R0, POWERPC_R3,
765
      (int)ORC_STRUCT_OFFSET(OrcExecutor, n));
766 767
  powerpc_emit_srawi (compiler, POWERPC_R0, POWERPC_R0,
      compiler->loop_shift, 1);
768

David Schleef's avatar
David Schleef committed
769
  powerpc_emit_beq (compiler, label_leave);
770

771 772
  powerpc_emit (compiler, 0x7c0903a6);
  ORC_ASM_CODE (compiler, "  mtctr %s\n", powerpc_get_regname(POWERPC_R0));
773

774
  powerpc_load_constants (compiler);
775

David Schleef's avatar
David Schleef committed
776
  powerpc_emit_label (compiler, label_loop_start);
777

778 779
  for(j=0;j<compiler->n_insns;j++){
    insn = compiler->insns + j;
780 781
    opcode = insn->opcode;

David Schleef's avatar
David Schleef committed
782
    ORC_ASM_CODE(compiler,"# %d: %s\n", j, insn->opcode->name);
783

David Schleef's avatar
David Schleef committed
784
#if 0
785 786
    /* set up args */
    for(k=0;k<opcode->n_src + opcode->n_dest;k++){
787 788
      args[k] = compiler->vars + insn->args[k];
      ORC_ASM_CODE(compiler," %d", args[k]->alloc);
789
      if (args[k]->is_chained) {
790
        ORC_ASM_CODE(compiler," (chained)");
791 792
      }
    }
793
    ORC_ASM_CODE(compiler,"\n");
David Schleef's avatar
David Schleef committed
794
#endif
795

David Schleef's avatar
David Schleef committed
796 797 798 799 800 801
    for(k=0;k<ORC_STATIC_OPCODE_N_SRC;k++){
      OrcVariable *var = compiler->vars + insn->src_args[k];

      if (opcode->src_size[k] == 0) continue;

      switch (var->vartype) {
802
        case ORC_VAR_TYPE_SRC:
David Schleef's avatar
David Schleef committed
803
        case ORC_VAR_TYPE_DEST:
David Schleef's avatar
David Schleef committed
804
          powerpc_emit_load_src (compiler, var);
805 806 807 808 809 810 811 812 813 814 815 816
          break;
        case ORC_VAR_TYPE_CONST:
          break;
        case ORC_VAR_TYPE_TEMP:
          break;
        default:
          break;
      }
    }

    rule = insn->rule;
    if (rule) {
817
      rule->emit (compiler, rule->emit_user, insn);
818
    } else {
819
      ORC_ASM_CODE(compiler,"No rule for: %s\n", opcode->name);
820 821
    }

David Schleef's avatar
David Schleef committed
822 823 824 825 826 827
    for(k=0;k<ORC_STATIC_OPCODE_N_DEST;k++){
      OrcVariable *var = compiler->vars + insn->dest_args[k];

      if (opcode->dest_size[k] == 0) continue;

      switch (var->vartype) {
828
        case ORC_VAR_TYPE_DEST:
David Schleef's avatar
David Schleef committed
829
          powerpc_emit_store_dest (compiler, var);
830 831 832 833 834 835 836 837 838
          break;
        case ORC_VAR_TYPE_TEMP:
          break;
        default:
          break;
      }
    }
  }

839 840
  for(k=0;k<ORC_N_VARIABLES;k++){
    if (compiler->vars[k].name == NULL) continue;
841 842 843 844 845 846 847
    if (compiler->vars[k].vartype == ORC_VAR_TYPE_SRC ||
        compiler->vars[k].vartype == ORC_VAR_TYPE_DEST) {
      if (compiler->vars[k].ptr_register) {
        powerpc_emit_addi (compiler,
            compiler->vars[k].ptr_register,
            compiler->vars[k].ptr_register,
            compiler->vars[k].size << compiler->loop_shift);
848
      } else {
849
        ORC_ASM_CODE(compiler,"ERROR\n");
850 851 852 853
      }
    }
  }

David Schleef's avatar
David Schleef committed
854 855
  powerpc_emit_bne (compiler, label_loop_start);
  powerpc_emit_label (compiler, label_leave);
856

857
  powerpc_emit_epilogue (compiler);
858

859
  powerpc_do_fixups (compiler);
860

861
  powerpc_flush (compiler);
862 863 864 865 866
}


/* rules */

David Schleef's avatar
David Schleef committed
867 868 869 870 871 872 873 874 875 876 877 878 879 880
#define RULE(name, opcode, code) \
static void \
powerpc_rule_ ## name (OrcCompiler *p, void *user, OrcInstruction *insn) \
{ \
  ORC_ASM_CODE(p,"  " opcode " %s, %s, %s\n", \
      powerpc_get_regname(p->vars[insn->dest_args[0]].alloc), \
      powerpc_get_regname(p->vars[insn->src_args[0]].alloc), \
      powerpc_get_regname(p->vars[insn->src_args[1]].alloc)); \
  powerpc_emit_VX(p, code , \
      powerpc_regnum (p->vars[insn->dest_args[0]].alloc), \
      powerpc_regnum (p->vars[insn->src_args[0]].alloc), \
      powerpc_regnum (p->vars[insn->src_args[1]].alloc)); \
}

David Schleef's avatar
David Schleef committed
881 882 883 884 885 886
#define RULE_SHIFT(name, opcode, code) \
static void \
powerpc_rule_ ## name (OrcCompiler *p, void *user, OrcInstruction *insn) \
{ \
  if (p->vars[insn->src_args[1]].vartype != ORC_VAR_TYPE_CONST && \
      p->vars[insn->src_args[1]].vartype != ORC_VAR_TYPE_PARAM) { \
David Schleef's avatar
David Schleef committed
887
    ORC_COMPILER_ERROR(p,"rule only works with constants or params"); \
David Schleef's avatar
David Schleef committed
888 889 890 891 892 893 894 895 896 897 898
  } \
  ORC_ASM_CODE(p,"  " opcode " %s, %s, %s\n", \
      powerpc_get_regname(p->vars[insn->dest_args[0]].alloc), \
      powerpc_get_regname(p->vars[insn->src_args[0]].alloc), \
      powerpc_get_regname(p->vars[insn->src_args[1]].alloc)); \
  powerpc_emit_VX(p, code , \
      powerpc_regnum (p->vars[insn->dest_args[0]].alloc), \
      powerpc_regnum (p->vars[insn->src_args[0]].alloc), \
      powerpc_regnum (p->vars[insn->src_args[1]].alloc)); \
}

David Schleef's avatar
David Schleef committed
899 900 901 902 903 904 905
RULE(addb, "vaddubm", 0x10000000)
RULE(addssb, "vaddsbs", 0x10000300)
RULE(addusb, "vaddubs", 0x10000200)
RULE(andb, "vand", 0x10000404)
//RULE(andnb, "vandc", 0x10000444)
RULE(avgsb, "vavgsb", 0x10000502)
RULE(avgub, "vavgub", 0x10000402)
David Schleef's avatar
David Schleef committed
906 907
RULE(cmpeqb, "vcmpequb", 0x10000006)
RULE(cmpgtsb, "vcmpgtsb", 0x10000306)
David Schleef's avatar
David Schleef committed
908 909 910 911 912
RULE(maxsb, "vmaxsb", 0x10000102)
RULE(maxub, "vmaxub", 0x10000002)
RULE(minsb, "vminsb", 0x10000302)
RULE(minub, "vminub", 0x10000202)
RULE(orb, "vor", 0x10000484)
David Schleef's avatar
David Schleef committed
913
RULE_SHIFT(shlb, "vslb", 0x10000104)
David Schleef's avatar
David Schleef committed
914 915
RULE_SHIFT(shrsb, "vsrab", 0x10000304)
RULE_SHIFT(shrub, "vsrb", 0x10000204)
David Schleef's avatar
David Schleef committed
916 917 918 919 920 921 922 923 924 925 926 927
RULE(subb, "vsububm", 0x10000400)
RULE(subssb, "vsubsbs", 0x10000700)
RULE(subusb, "vsububs", 0x10000600)
RULE(xorb, "vxor", 0x100004c4)

RULE(addw, "vadduhm", 0x10000040)
RULE(addssw, "vaddshs", 0x10000340)
RULE(addusw, "vadduhs", 0x10000240)
RULE(andw, "vand", 0x10000404)
//RULE(andnw, "vandc", 0x10000444)
RULE(avgsw, "vavgsh", 0x10000542)
RULE(avguw, "vavguh", 0x10000442)
David Schleef's avatar
David Schleef committed
928 929
RULE(cmpeqw, "vcmpequh", 0x10000046)
RULE(cmpgtsw, "vcmpgtsh", 0x10000346)
David Schleef's avatar
David Schleef committed
930 931 932 933 934
RULE(maxsw, "vmaxsh", 0x10000142)
RULE(maxuw, "vmaxuh", 0x10000042)
RULE(minsw, "vminsh", 0x10000342)
RULE(minuw, "vminuh", 0x10000242)
RULE(orw, "vor", 0x10000484)
David Schleef's avatar
David Schleef committed
935
RULE_SHIFT(shlw, "vslh", 0x10000144)
David Schleef's avatar
David Schleef committed
936 937
RULE_SHIFT(shrsw, "vsrah", 0x10000344)
RULE_SHIFT(shruw, "vsrh", 0x10000244)
David Schleef's avatar
David Schleef committed
938 939 940 941 942 943 944 945 946 947 948 949
RULE(subw, "vsubuhm", 0x10000440)
RULE(subssw, "vsubshs", 0x10000740)
RULE(subusw, "vsubuhs", 0x10000640)
RULE(xorw, "vxor", 0x100004c4)

RULE(addl, "vadduwm", 0x10000080)
RULE(addssl, "vaddsws", 0x10000380)
RULE(addusl, "vadduws", 0x10000280)
RULE(andl, "vand", 0x10000404)
//RULE(andnl, "vandc", 0x10000444)
RULE(avgsl, "vavgsw", 0x10000582)
RULE(avgul, "vavguw", 0x10000482)
David Schleef's avatar
David Schleef committed
950 951
RULE(cmpeql, "vcmpequw", 0x10000086)
RULE(cmpgtsl, "vcmpgtsw", 0x10000386)
David Schleef's avatar
David Schleef committed
952 953 954 955 956
RULE(maxsl, "vmaxsw", 0x10000182)
RULE(maxul, "vmaxuw", 0x10000082)
RULE(minsl, "vminsw", 0x10000382)
RULE(minul, "vminuw", 0x10000282)
RULE(orl, "vor", 0x10000484)
David Schleef's avatar
David Schleef committed
957
RULE_SHIFT(shll, "vslw", 0x10000184)
David Schleef's avatar
David Schleef committed
958 959
RULE_SHIFT(shrsl, "vsraw", 0x10000384)
RULE_SHIFT(shrul, "vsrw", 0x10000284)
David Schleef's avatar
David Schleef committed
960 961 962 963 964
RULE(subl, "vsubuwm", 0x10000480)
RULE(subssl, "vsubsws", 0x10000780)
RULE(subusl, "vsubuws", 0x10000680)
RULE(xorl, "vxor", 0x100004c4)

965
static void
David Schleef's avatar
David Schleef committed
966
powerpc_rule_andnX (OrcCompiler *p, void *user, OrcInstruction *insn)
967
{
David Schleef's avatar
David Schleef committed
968
  ORC_ASM_CODE(p,"  vandc %s, %s, %s\n",
David Schleef's avatar
David Schleef committed
969
      powerpc_get_regname(p->vars[insn->dest_args[0]].alloc),
David Schleef's avatar
David Schleef committed
970 971 972 973 974 975
      powerpc_get_regname(p->vars[insn->src_args[1]].alloc),
      powerpc_get_regname(p->vars[insn->src_args[0]].alloc));
  powerpc_emit_VX(p, 0x10000444,
      powerpc_regnum (p->vars[insn->dest_args[0]].alloc),
      powerpc_regnum (p->vars[insn->src_args[1]].alloc),
      powerpc_regnum (p->vars[insn->src_args[0]].alloc));
976 977 978
}

static void
David Schleef's avatar
David Schleef committed
979
powerpc_rule_copyX (OrcCompiler *p, void *user, OrcInstruction *insn)
980
{
David Schleef's avatar
David Schleef committed
981
  ORC_ASM_CODE(p,"  vor %s, %s, %s\n",
David Schleef's avatar
David Schleef committed
982 983
      powerpc_get_regname(p->vars[insn->dest_args[0]].alloc),
      powerpc_get_regname(p->vars[insn->src_args[0]].alloc),
David Schleef's avatar
David Schleef committed
984 985 986 987 988
      powerpc_get_regname(p->vars[insn->src_args[0]].alloc));
  powerpc_emit_VX(p, 0x10000484,
      powerpc_regnum (p->vars[insn->dest_args[0]].alloc),
      powerpc_regnum (p->vars[insn->src_args[0]].alloc),
      powerpc_regnum (p->vars[insn->src_args[0]].alloc));
989 990
}

David Schleef's avatar
David Schleef committed
991 992 993 994 995 996 997 998 999 1000 1001
static void
powerpc_rule_mullb (OrcCompiler *p, void *user, OrcInstruction *insn)
{
  ORC_ASM_CODE(p,"  vmulesb %s, %s, %s\n",
      powerpc_get_regname(p->vars[insn->dest_args[0]].alloc),
      powerpc_get_regname(p->vars[insn->src_args[0]].alloc),
      powerpc_get_regname(p->vars[insn->src_args[1]].alloc));
  powerpc_emit_VX(p, 0x10000308,
      powerpc_regnum(p->vars[insn->dest_args[0]].alloc),
      powerpc_regnum(p->vars[insn->src_args[0]].alloc),
      powerpc_regnum(p->vars[insn->src_args[1]].alloc));
David Schleef's avatar
David Schleef committed
1002

David Schleef's avatar
David Schleef committed
1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037
  ORC_ASM_CODE(p,"  vsldoi %s, %s, %s, 1\n",
      powerpc_get_regname(p->vars[insn->dest_args[0]].alloc),
      powerpc_get_regname(p->vars[insn->dest_args[0]].alloc),
      powerpc_get_regname(p->vars[insn->dest_args[0]].alloc));
  powerpc_emit_VX(p, 0x1000002c | (1<<6),
      powerpc_regnum(p->vars[insn->dest_args[0]].alloc),
      powerpc_regnum(p->vars[insn->dest_args[0]].alloc),
      powerpc_regnum(p->vars[insn->dest_args[0]].alloc));
}

static void
powerpc_rule_mulhsb (OrcCompiler *p, void *user, OrcInstruction *insn)
{
  ORC_ASM_CODE(p,"  vmulesb %s, %s, %s\n",
      powerpc_get_regname(p->vars[insn->dest_args[0]].alloc),
      powerpc_get_regname(p->vars[insn->src_args[0]].alloc),
      powerpc_get_regname(p->vars[insn->src_args[1]].alloc));
  powerpc_emit_VX(p, 0x10000308,
      powerpc_regnum(p->vars[insn->dest_args[0]].alloc),
      powerpc_regnum(p->vars[insn->src_args[0]].alloc),
      powerpc_regnum(p->vars[insn->src_args[1]].alloc));
}

static void
powerpc_rule_mulhub (OrcCompiler *p, void *user, OrcInstruction *insn)
{
  ORC_ASM_CODE(p,"  vmuleub %s, %s, %s\n",
      powerpc_get_regname(p->vars[insn->dest_args[0]].alloc),
      powerpc_get_regname(p->vars[insn->src_args[0]].alloc),
      powerpc_get_regname(p->vars[insn->src_args[1]].alloc));
  powerpc_emit_VX(p, 0x10000208,
      powerpc_regnum(p->vars[insn->dest_args[0]].alloc),
      powerpc_regnum(p->vars[insn->src_args[0]].alloc),
      powerpc_regnum(p->vars[insn->src_args[1]].alloc));
}
David Schleef's avatar
David Schleef committed
1038

David Schleef's avatar
David Schleef committed
1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 1051 1052 1053 1054 1055 1056 1057 1058 1059 1060 1061 1062 1063 1064 1065 1066 1067 1068 1069 1070 1071 1072 1073 1074 1075 1076 1077 1078 1079 1080 1081 1082 1083 1084 1085 1086 1087 1088
static void
powerpc_rule_mullw (OrcCompiler *p, void *user, OrcInstruction *insn)
{
  ORC_ASM_CODE(p,"  vmulesh %s, %s, %s\n",
      powerpc_get_regname(p->vars[insn->dest_args[0]].alloc),
      powerpc_get_regname(p->vars[insn->src_args[0]].alloc),
      powerpc_get_regname(p->vars[insn->src_args[1]].alloc));
  powerpc_emit_VX(p, 0x10000348,
      powerpc_regnum(p->vars[insn->dest_args[0]].alloc),
      powerpc_regnum(p->vars[insn->src_args[0]].alloc),
      powerpc_regnum(p->vars[insn->src_args[1]].alloc));

  ORC_ASM_CODE(p,"  vsldoi %s, %s, %s, 2\n",
      powerpc_get_regname(p->vars[insn->dest_args[0]].alloc),
      powerpc_get_regname(p->vars[insn->dest_args[0]].alloc),
      powerpc_get_regname(p->vars[insn->dest_args[0]].alloc));
  powerpc_emit_VX(p, 0x1000002c | (2<<6),
      powerpc_regnum(p->vars[insn->dest_args[0]].alloc),
      powerpc_regnum(p->vars[insn->dest_args[0]].alloc),
      powerpc_regnum(p->vars[insn->dest_args[0]].alloc));
}

static void
powerpc_rule_mulhsw (OrcCompiler *p, void *user, OrcInstruction *insn)
{
  ORC_ASM_CODE(p,"  vmulesh %s, %s, %s\n",
      powerpc_get_regname(p->vars[insn->dest_args[0]].alloc),
      powerpc_get_regname(p->vars[insn->src_args[0]].alloc),
      powerpc_get_regname(p->vars[insn->src_args[1]].alloc));
  powerpc_emit_VX(p, 0x10000348,
      powerpc_regnum(p->vars[insn->dest_args[0]].alloc),
      powerpc_regnum(p->vars[insn->src_args[0]].alloc),
      powerpc_regnum(p->vars[insn->src_args[1]].alloc));
}

static void
powerpc_rule_mulhuw (OrcCompiler *p, void *user, OrcInstruction *insn)
{
  ORC_ASM_CODE(p,"  vmuleuh %s, %s, %s\n",
      powerpc_get_regname(p->vars[insn->dest_args[0]].alloc),
      powerpc_get_regname(p->vars[insn->src_args[0]].alloc),
      powerpc_get_regname(p->vars[insn->src_args[1]].alloc));
  powerpc_emit_VX(p, 0x10000248,
      powerpc_regnum(p->vars[insn->dest_args[0]].alloc),
      powerpc_regnum(p->vars[insn->src_args[0]].alloc),
      powerpc_regnum(p->vars[insn->src_args[1]].alloc));
}


#ifdef alternate
1089
static void
1090
powerpc_rule_mullw (OrcCompiler *p, void *user, OrcInstruction *insn)
1091
{
1092
  ORC_ASM_CODE(p,"  vxor %s, %s, %s\n",
1093 1094 1095
      powerpc_get_regname(POWERPC_V0),
      powerpc_get_regname(POWERPC_V0),
      powerpc_get_regname(POWERPC_V0));
David Schleef's avatar
David Schleef committed
1096
  powerpc_emit_VX(p, 0x100004c4,
1097 1098
      powerpc_regnum(POWERPC_V0),
      powerpc_regnum(POWERPC_V0),
David Schleef's avatar
David Schleef committed
1099
      powerpc_regnum(POWERPC_V0));
1100

1101
  ORC_ASM_CODE(p,"  vmladduhm %s, %s, %s, %s\n",
David Schleef's avatar
David Schleef committed
1102 1103 1104
      powerpc_get_regname(p->vars[insn->dest_args[0]].alloc),
      powerpc_get_regname(p->vars[insn->src_args[0]].alloc),
      powerpc_get_regname(p->vars[insn->src_args[1]].alloc),
1105 1106
      powerpc_get_regname(POWERPC_V0));
  powerpc_emit_VA(p, 4, 
David Schleef's avatar
David Schleef committed
1107 1108 1109
      powerpc_regnum(p->vars[insn->dest_args[0]].alloc),
      powerpc_regnum(p->vars[insn->src_args[0]].alloc),
      powerpc_regnum(p->vars[insn->src_args[1]].alloc),
1110 1111 1112
      powerpc_regnum(POWERPC_V0), 34);

}
David Schleef's avatar
David Schleef committed
1113 1114 1115 1116 1117 1118 1119 1120 1121 1122 1123 1124 1125 1126 1127 1128 1129 1130 1131 1132 1133 1134 1135 1136 1137 1138 1139 1140 1141
#endif

static void
powerpc_rule_convsbw (OrcCompiler *p, void *user, OrcInstruction *insn)
{
  ORC_ASM_CODE(p,"  vupkhsb %s, %s\n",
      powerpc_get_regname(p->vars[insn->dest_args[0]].alloc),
      powerpc_get_regname(p->vars[insn->src_args[0]].alloc));
  powerpc_emit_VX(p, 0x1000020e,
      powerpc_regnum(p->vars[insn->dest_args[0]].alloc),
      0,
      powerpc_regnum(p->vars[insn->src_args[0]].alloc));
}

static void
powerpc_rule_convswl (OrcCompiler *p, void *user, OrcInstruction *insn)
{
  ORC_ASM_CODE(p,"  vupkhsh %s, %s\n",
      powerpc_get_regname(p->vars[insn->dest_args[0]].alloc),
      powerpc_get_regname(p->vars[insn->src_args[0]].alloc));
  powerpc_emit_VX(p, 0x1000024e,
      powerpc_regnum(p->vars[insn->dest_args[0]].alloc),
      0,
      powerpc_regnum(p->vars[insn->src_args[0]].alloc));
}

static void
powerpc_rule_convubw (OrcCompiler *p, void *user, OrcInstruction *insn)
{
David Schleef's avatar
David Schleef committed
1142
  int reg = powerpc_get_constant (p, ORC_CONST_ZERO, 0);
David Schleef's avatar
David Schleef committed
1143 1144 1145 1146 1147 1148 1149 1150 1151 1152 1153 1154 1155 1156

  ORC_ASM_CODE(p,"  vmrghb %s, %s, %s\n",
      powerpc_get_regname(p->vars[insn->dest_args[0]].alloc),
      powerpc_get_regname(reg),
      powerpc_get_regname(p->vars[insn->src_args[0]].alloc));
  powerpc_emit_VX(p, 0x1000000c,
      powerpc_regnum(p->vars[insn->dest_args[0]].alloc),
      powerpc_regnum(reg),
      powerpc_regnum(p->vars[insn->src_args[0]].alloc));
}

static void
powerpc_rule_convuwl (OrcCompiler *p, void *user, OrcInstruction *insn)
{
David Schleef's avatar
David Schleef committed
1157
  int reg = powerpc_get_constant (p, ORC_CONST_ZERO, 0);
David Schleef's avatar
David Schleef committed
1158 1159 1160 1161 1162 1163 1164 1165 1166 1167

  ORC_ASM_CODE(p,"  vmrghh %s, %s, %s\n",
      powerpc_get_regname(p->vars[insn->dest_args[0]].alloc),
      powerpc_get_regname(reg),
      powerpc_get_regname(p->vars[insn->src_args[0]].alloc));
  powerpc_emit_VX(p, 0x1000004c,
      powerpc_regnum(p->vars[insn->dest_args[0]].alloc),
      powerpc_regnum(reg),
      powerpc_regnum(p->vars[insn->src_args[0]].alloc));
}
1168 1169

static void
David Schleef's avatar
David Schleef committed
1170
powerpc_rule_convssswb (OrcCompiler *p, void *user, OrcInstruction *insn)
1171
{
David Schleef's avatar
David Schleef committed
1172 1173 1174 1175 1176 1177 1178 1179 1180 1181 1182 1183 1184 1185 1186 1187 1188 1189 1190 1191 1192 1193 1194 1195 1196 1197 1198 1199 1200 1201 1202 1203 1204 1205 1206 1207 1208 1209 1210 1211 1212 1213 1214 1215 1216 1217 1218 1219 1220 1221 1222 1223 1224 1225 1226 1227 1228 1229 1230 1231 1232 1233 1234 1235 1236 1237 1238 1239 1240 1241 1242 1243 1244 1245 1246 1247 1248 1249 1250 1251 1252 1253 1254 1255 1256 1257 1258 1259 1260 1261 1262 1263 1264 1265 1266 1267 1268 1269 1270 1271 1272 1273 1274 1275 1276
  ORC_ASM_CODE(p,"  vpkshss %s, %s, %s\n",
      powerpc_get_regname(p->vars[insn->dest_args[0]].alloc),
      powerpc_get_regname(p->vars[insn->src_args[0]].alloc),
      powerpc_get_regname(p->vars[insn->src_args[0]].alloc));
  powerpc_emit_VX(p, 0x1000018e,
      powerpc_regnum(p->vars[insn->dest_args[0]].alloc),
      powerpc_regnum(p->vars[insn->src_args[0]].alloc),
      powerpc_regnum(p->vars[insn->src_args[0]].alloc));
}

static void
powerpc_rule_convssslw (OrcCompiler *p, void *user, OrcInstruction *insn)
{
  ORC_ASM_CODE(p,"  vpkswss %s, %s, %s\n",
      powerpc_get_regname(p->vars[insn->dest_args[0]].alloc),
      powerpc_get_regname(p->vars[insn->src_args[0]].alloc),
      powerpc_get_regname(p->vars[insn->src_args[0]].alloc));
  powerpc_emit_VX(p, 0x100001ce,
      powerpc_regnum(p->vars[insn->dest_args[0]].alloc),
      powerpc_regnum(p->vars[insn->src_args[0]].alloc),
      powerpc_regnum(p->vars[insn->src_args[0]].alloc));
}

static void
powerpc_rule_convsuswb (OrcCompiler *p, void *user, OrcInstruction *insn)
{
  ORC_ASM_CODE(p,"  vpkshus %s, %s, %s\n",
      powerpc_get_regname(p->vars[insn->dest_args[0]].alloc),
      powerpc_get_regname(p->vars[insn->src_args[0]].alloc),
      powerpc_get_regname(p->vars[insn->src_args[0]].alloc));
  powerpc_emit_VX(p, 0x1000010e,
      powerpc_regnum(p->vars[insn->dest_args[0]].alloc),
      powerpc_regnum(p->vars[insn->src_args[0]].alloc),
      powerpc_regnum(p->vars[insn->src_args[0]].alloc));
}

static void
powerpc_rule_convsuslw (OrcCompiler *p, void *user, OrcInstruction *insn)
{
  ORC_ASM_CODE(p,"  vpkswus %s, %s, %s\n",
      powerpc_get_regname(p->vars[insn->dest_args[0]].alloc),
      powerpc_get_regname(p->vars[insn->src_args[0]].alloc),
      powerpc_get_regname(p->vars[insn->src_args[0]].alloc));
  powerpc_emit_VX(p, 0x1000014e,
      powerpc_regnum(p->vars[insn->dest_args[0]].alloc),
      powerpc_regnum(p->vars[insn->src_args[0]].alloc),
      powerpc_regnum(p->vars[insn->src_args[0]].alloc));
}

static void
powerpc_rule_convuuswb (OrcCompiler *p, void *user, OrcInstruction *insn)
{
  ORC_ASM_CODE(p,"  vpkuhus %s, %s, %s\n",
      powerpc_get_regname(p->vars[insn->dest_args[0]].alloc),
      powerpc_get_regname(p->vars[insn->src_args[0]].alloc),
      powerpc_get_regname(p->vars[insn->src_args[0]].alloc));
  powerpc_emit_VX(p, 0x1000008e,
      powerpc_regnum(p->vars[insn->dest_args[0]].alloc),
      powerpc_regnum(p->vars[insn->src_args[0]].alloc),
      powerpc_regnum(p->vars[insn->src_args[0]].alloc));
}

static void
powerpc_rule_convuuslw (OrcCompiler *p, void *user, OrcInstruction *insn)
{
  ORC_ASM_CODE(p,"  vpkuwus %s, %s, %s\n",
      powerpc_get_regname(p->vars[insn->dest_args[0]].alloc),
      powerpc_get_regname(p->vars[insn->src_args[0]].alloc),
      powerpc_get_regname(p->vars[insn->src_args[0]].alloc));
  powerpc_emit_VX(p, 0x100000ce,
      powerpc_regnum(p->vars[insn->dest_args[0]].alloc),
      powerpc_regnum(p->vars[insn->src_args[0]].alloc),
      powerpc_regnum(p->vars[insn->src_args[0]].alloc));
}

static void
powerpc_rule_convwb (OrcCompiler *p, void *user, OrcInstruction *insn)
{
  ORC_ASM_CODE(p,"  vpkuhum %s, %s, %s\n",
      powerpc_get_regname(p->vars[insn->dest_args[0]].alloc),
      powerpc_get_regname(p->vars[insn->src_args[0]].alloc),
      powerpc_get_regname(p->vars[insn->src_args[0]].alloc));
  powerpc_emit_VX(p, 0x1000000e,
      powerpc_regnum(p->vars[insn->dest_args[0]].alloc),
      powerpc_regnum(p->vars[insn->src_args[0]].alloc),
      powerpc_regnum(p->vars[insn->src_args[0]].alloc));
}

static void
powerpc_rule_convlw (OrcCompiler *p, void *user, OrcInstruction *insn)
{
  ORC_ASM_CODE(p,"  vpkuwum %s, %s, %s\n",
      powerpc_get_regname(p->vars[insn->dest_args[0]].alloc),
      powerpc_get_regname(p->vars[insn->src_args[0]].alloc),
      powerpc_get_regname(p->vars[insn->src_args[0]].alloc));
  powerpc_emit_VX(p, 0x1000004e,
      powerpc_regnum(p->vars[insn->dest_args[0]].alloc),
      powerpc_regnum(p->vars[insn->src_args[0]].alloc),
      powerpc_regnum(p->vars[insn->src_args[0]].alloc));
}

static void
powerpc_rule_mulsbw (OrcCompiler *p, void *user, OrcInstruction *insn)
{
  ORC_ASM_CODE(p,"  vmulesb %s, %s, %s\n",
David Schleef's avatar
David Schleef committed
1277 1278 1279
      powerpc_get_regname(p->vars[insn->dest_args[0]].alloc),
      powerpc_get_regname(p->vars[insn->src_args[0]].alloc),
      powerpc_get_regname(p->vars[insn->src_args[1]].alloc));
David Schleef's avatar
David Schleef committed
1280
  powerpc_emit_VX(p, 0x10000308,
David Schleef's avatar
David Schleef committed
1281 1282
      powerpc_regnum(p->vars[insn->dest_args[0]].alloc),
      powerpc_regnum(p->vars[insn->src_args[0]].alloc),
David Schleef's avatar
David Schleef committed
1283
      powerpc_regnum(p->vars[insn->src_args[1]].alloc));
1284 1285 1286
}

static void
David Schleef's avatar
David Schleef committed
1287
powerpc_rule_mulubw (OrcCompiler *p, void *user, OrcInstruction *insn)
1288
{
David Schleef's avatar
David Schleef committed
1289
  ORC_ASM_CODE(p,"  vmuleub %s, %s, %s\n",
David Schleef's avatar
David Schleef committed
1290 1291 1292
      powerpc_get_regname(p->vars[insn->dest_args[0]].alloc),
      powerpc_get_regname(p->vars[insn->src_args[0]].alloc),
      powerpc_get_regname(p->vars[insn->src_args[1]].alloc));
David Schleef's avatar
David Schleef committed
1293 1294 1295 1296 1297
  powerpc_emit_VX(p, 0x10000208,
      powerpc_regnum(p->vars[insn->dest_args[0]].alloc),
      powerpc_regnum(p->vars[insn->src_args[0]].alloc),
      powerpc_regnum(p->vars[insn->src_args[1]].alloc));
}
1298

David Schleef's avatar
David Schleef committed
1299 1300 1301 1302 1303 1304 1305 1306
static void
powerpc_rule_mulswl (OrcCompiler *p, void *user, OrcInstruction *insn)
{
  ORC_ASM_CODE(p,"  vmulesh %s, %s, %s\n",
      powerpc_get_regname(p->vars[insn->dest_args[0]].alloc),
      powerpc_get_regname(p->vars[insn->src_args[0]].alloc),
      powerpc_get_regname(p->vars[insn->src_args[1]].alloc));
  powerpc_emit_VX(p, 0x10000348,
David Schleef's avatar
David Schleef committed
1307 1308 1309
      powerpc_regnum(p->vars[insn->dest_args[0]].alloc),
      powerpc_regnum(p->vars[insn->src_args[0]].alloc),
      powerpc_regnum(p->vars[insn->src_args[1]].alloc));
1310 1311
}

David Schleef's avatar
David Schleef committed
1312 1313 1314 1315 1316 1317 1318 1319 1320 1321 1322 1323 1324 1325 1326 1327 1328 1329 1330 1331 1332 1333 1334 1335 1336 1337 1338 1339 1340 1341 1342 1343 1344 1345 1346 1347 1348 1349 1350 1351 1352 1353 1354 1355 1356 1357 1358 1359 1360 1361 1362 1363 1364 1365 1366 1367 1368 1369 1370 1371 1372 1373 1374 1375 1376 1377 1378 1379 1380 1381 1382 1383 1384 1385 1386 1387 1388 1389 1390 1391
static void
powerpc_rule_muluwl (OrcCompiler *p, void *user, OrcInstruction *insn)
{
  ORC_ASM_CODE(p,"  vmuleuh %s, %s, %s\n",
      powerpc_get_regname(p->vars[insn->dest_args[0]].alloc),
      powerpc_get_regname(p->vars[insn->src_args[0]].alloc),
      powerpc_get_regname(p->vars[insn->src_args[1]].alloc));
  powerpc_emit_VX(p, 0x10000248,
      powerpc_regnum(p->vars[insn->dest_args[0]].alloc),
      powerpc_regnum(p->vars[insn->src_args[0]].alloc),
      powerpc_regnum(p->vars[insn->src_args[1]].alloc));
}

static void
powerpc_rule_accw (OrcCompiler *p, void *user, OrcInstruction *insn)
{
  ORC_ASM_CODE(p,"  vadduhm %s, %s, %s\n",
      powerpc_get_regname(p->vars[insn->dest_args[0]].alloc),
      powerpc_get_regname(p->vars[insn->dest_args[0]].alloc),
      powerpc_get_regname(p->vars[insn->src_args[0]].alloc));
  powerpc_emit_VX(p, 0x10000040,
      powerpc_regnum(p->vars[insn->dest_args[0]].alloc),
      powerpc_regnum(p->vars[insn->dest_args[0]].alloc),
      powerpc_regnum(p->vars[insn->src_args[0]].alloc));
}

static void
powerpc_rule_accl (OrcCompiler *p, void *user, OrcInstruction *insn)
{
  ORC_ASM_CODE(p,"  vadduwm %s, %s, %s\n",
      powerpc_get_regname(p->vars[insn->dest_args[0]].alloc),
      powerpc_get_regname(p->vars[insn->dest_args[0]].alloc),
      powerpc_get_regname(p->vars[insn->src_args[0]].alloc));
  powerpc_emit_VX(p, 0x10000080,
      powerpc_regnum(p->vars[insn->dest_args[0]].alloc),
      powerpc_regnum(p->vars[insn->dest_args[0]].alloc),
      powerpc_regnum(p->vars[insn->src_args[0]].alloc));
}

static void
powerpc_rule_accsadubl (OrcCompiler *p, void *user, OrcInstruction *insn)
{
  int tmpreg2 = POWERPC_V31;

  ORC_ASM_CODE(p,"  vmaxub %s, %s, %s\n",
      powerpc_get_regname(p->tmpreg),
      powerpc_get_regname(p->vars[insn->src_args[0]].alloc),
      powerpc_get_regname(p->vars[insn->src_args[1]].alloc));
  powerpc_emit_VX(p, 0x10000002,
      powerpc_regnum(p->tmpreg),
      powerpc_regnum(p->vars[insn->src_args[0]].alloc),
      powerpc_regnum(p->vars[insn->src_args[1]].alloc));

  ORC_ASM_CODE(p,"  vminub %s, %s, %s\n",
      powerpc_get_regname(tmpreg2),
      powerpc_get_regname(p->vars[insn->src_args[0]].alloc),
      powerpc_get_regname(p->vars[insn->src_args[1]].alloc));
  powerpc_emit_VX(p, 0x10000202,
      powerpc_regnum(tmpreg2),
      powerpc_regnum(p->vars[insn->src_args[0]].alloc),
      powerpc_regnum(p->vars[insn->src_args[1]].alloc));

  ORC_ASM_CODE(p,"  vsububm %s, %s, %s\n",
      powerpc_get_regname(p->tmpreg),
      powerpc_get_regname(p->tmpreg),
      powerpc_get_regname(tmpreg2));
  powerpc_emit_VX(p, 0x10000400,
      powerpc_regnum(p->tmpreg),
      powerpc_regnum(p->tmpreg),
      powerpc_regnum(tmpreg2));

  ORC_ASM_CODE(p,"  vsum4ubs %s, %s, %s\n",
      powerpc_get_regname(p->vars[insn->dest_args[0]].alloc),
      powerpc_get_regname(p->vars[insn->dest_args[0]].alloc),
      powerpc_get_regname(p->tmpreg));
  powerpc_emit_VX(p, 0x10000608,
      powerpc_regnum(p->vars[insn->dest_args[0]].alloc),
      powerpc_regnum(p->vars[insn->dest_args[0]].alloc),
      powerpc_regnum(p->tmpreg));
}
1392

David Schleef's avatar
David Schleef committed
1393 1394 1395 1396 1397 1398 1399 1400 1401 1402 1403 1404 1405 1406 1407 1408 1409 1410 1411 1412 1413 1414 1415 1416 1417 1418 1419 1420 1421 1422 1423 1424 1425 1426 1427 1428 1429 1430 1431 1432 1433 1434 1435 1436 1437 1438 1439 1440 1441 1442 1443 1444 1445 1446
static void
powerpc_rule_signb (OrcCompiler *p, void *user, OrcInstruction *insn)
{
  int reg;
  
  reg = powerpc_get_constant (p, ORC_CONST_SPLAT_B, 1);
  powerpc_emit_VX_2(p, "vminsb", 0x10000302,
      p->vars[insn->dest_args[0]].alloc,
      p->vars[insn->src_args[0]].alloc,
      reg);

  reg = powerpc_get_constant (p, ORC_CONST_SPLAT_B, -1);
  powerpc_emit_VX_2(p, "vmaxsb", 0x10000102,
      p->vars[insn->dest_args[0]].alloc,
      p->vars[insn->dest_args[0]].alloc,
      reg);
}

static void
powerpc_rule_signw (OrcCompiler *p, void *user, OrcInstruction *insn)
{
  int reg;
  
  reg = powerpc_get_constant (p, ORC_CONST_SPLAT_W, 1);
  powerpc_emit_VX_2(p, "vminsh", 0x10000342,
      p->vars[insn->dest_args[0]].alloc,
      p->vars[insn->src_args[0]].alloc,
      reg);

  reg = powerpc_get_constant (p, ORC_CONST_SPLAT_W, -1);
  powerpc_emit_VX_2(p, "vmaxsh", 0x10000142,
      p->vars[insn->dest_args[0]].alloc,
      p->vars[insn->dest_args[0]].alloc,
      reg);
}

static void
powerpc_rule_signl (OrcCompiler *p, void *user, OrcInstruction *insn)
{
  int reg;
  
  reg = powerpc_get_constant (p, ORC_CONST_SPLAT_L, 1);
  powerpc_emit_VX_2(p, "vminsw", 0x10000382,
      p->vars[insn->dest_args[0]].alloc,
      p->vars[insn->src_args[0]].alloc,
      reg);

  reg = powerpc_get_constant (p, ORC_CONST_SPLAT_L, -1);
  powerpc_emit_VX_2(p, "vmaxsw", 0x10000182,
      p->vars[insn->dest_args[0]].alloc,
      p->vars[insn->dest_args[0]].alloc,
      reg);
}

1447
void
David Schleef's avatar
David Schleef committed
1448
orc_compiler_powerpc_register_rules (OrcTarget *target)
1449
{
David Schleef's avatar
David Schleef committed
1450 1451
  OrcRuleSet *rule_set;

David Schleef's avatar
David Schleef committed
1452
  rule_set = orc_rule_set_new (orc_opcode_set_get("sys"), target, 0);
David Schleef's avatar
David Schleef committed
1453

David Schleef's avatar
David Schleef committed
1454 1455 1456 1457 1458 1459 1460 1461 1462
#define REG(name) \
  orc_rule_register (rule_set, #name , powerpc_rule_ ## name , NULL);

  REG(addb);
  REG(addssb);
  REG(addusb);
  REG(andb);
  REG(avgsb);
  REG(avgub);
David Schleef's avatar
David Schleef committed
1463 1464
  REG(cmpeqb);
  REG(cmpgtsb);
David Schleef's avatar
David Schleef committed
1465 1466 1467 1468 1469 1470 1471 1472 1473 1474 1475 1476 1477 1478 1479 1480 1481 1482 1483
  REG(maxsb);
  REG(maxub);
  REG(minsb);
  REG(minub);
  REG(orb);
  REG(shlb);
  REG(shrsb);
  REG(shrub);
  REG(subb);
  REG(subssb);
  REG(subusb);
  REG(xorb);

  REG(addw);
  REG(addssw);
  REG(addusw);
  REG(andw);
  REG(avgsw);
  REG(avguw);
David Schleef's avatar
David Schleef committed
1484 1485
  REG(cmpeqw);
  REG(cmpgtsw);
David Schleef's avatar
David Schleef committed
1486 1487 1488 1489 1490 1491 1492 1493 1494 1495 1496 1497 1498 1499 1500 1501 1502 1503 1504
  REG(maxsw);
  REG(maxuw);
  REG(minsw);
  REG(minuw);
  REG(orw);
  REG(shlw);
  REG(shrsw);
  REG(shruw);
  REG(subw);
  REG(subssw);
  REG(subusw);
  REG(xorw);

  REG(addl);
  REG(addssl);
  REG(addusl);
  REG(andl);
  REG(avgsl);
  REG(avgul);
David Schleef's avatar
David Schleef committed
1505 1506
  REG(cmpeql);
  REG(cmpgtsl);
David Schleef's avatar
David Schleef committed
1507 1508 1509 1510 1511 1512 1513 1514 1515 1516 1517 1518 1519
  REG(maxsl);
  REG(maxul);
  REG(minsl);
  REG(minul);
  REG(orl);
  REG(shll);
  REG(shrsl);
  REG(shrul);
  REG(subl);
  REG(subssl);
  REG(subusl);
  REG(xorl);

David Schleef's avatar
David Schleef committed
1520 1521 1522 1523 1524 1525 1526 1527 1528 1529 1530 1531 1532 1533 1534 1535 1536 1537 1538 1539 1540 1541 1542 1543 1544 1545 1546 1547 1548
  REG(mullb);
  REG(mulhsb);
  REG(mulhub);
  REG(mullw);
  REG(mulhsw);
  REG(mulhuw);

  REG(convsbw);
  REG(convswl);
  REG(convubw);
  REG(convuwl);
  REG(convssswb);
  REG(convssslw);
  REG(convsuswb);
  REG(convsuslw);
  REG(convuuswb);
  REG(convuuslw);
  REG(convwb);
  REG(convlw);

  REG(mulsbw);
  REG(mulubw);
  REG(mulswl);
  REG(muluwl);

  REG(accw);
  REG(accl);
  REG(accsadubl);

David Schleef's avatar
David Schleef committed
1549 1550 1551 1552
  REG(signb);
  REG(signw);
  REG(signl);

David Schleef's avatar
David Schleef committed
1553 1554 1555 1556 1557 1558 1559
  orc_rule_register (rule_set, "andnb", powerpc_rule_andnX, NULL);
  orc_rule_register (rule_set, "andnw", powerpc_rule_andnX, NULL);
  orc_rule_register (rule_set, "andnl", powerpc_rule_andnX, NULL);

  orc_rule_register (rule_set, "copyb", powerpc_rule_copyX, NULL);
  orc_rule_register (rule_set, "copyw", powerpc_rule_copyX, NULL);
  orc_rule_register (rule_set, "copyl", powerpc_rule_copyX, NULL);
1560 1561 1562 1563
}

/* code generation */

1564
void powerpc_emit_ret (OrcCompiler *compiler)
1565
{
1566 1567
  ORC_ASM_CODE(compiler,"  ret\n");
  //*compiler->codeptr++ = 0xc3;
1568 1569 1570
}

void
David Schleef's avatar
David Schleef committed
1571
powerpc_add_fixup (OrcCompiler *compiler, int type, unsigned char *ptr, int label)
1572
{
1573 1574
  compiler->fixups[compiler->n_fixups].ptr = ptr;
  compiler->fixups[compiler->n_fixups].label = label;
David Schleef's avatar
David Schleef committed
1575
  compiler->fixups[compiler->n_fixups].type = type;
1576
  compiler->n_fixups++;
1577 1578 1579
}

void
1580
powerpc_add_label (OrcCompiler *compiler, unsigned char *ptr, int label)
1581
{
1582
  compiler->labels[label] = ptr;
1583 1584
}

David Schleef's avatar
David Schleef committed
1585 1586 1587 1588 1589 1590 1591 1592 1593
void powerpc_emit_b (OrcCompiler *compiler, int label)
{
  ORC_ASM_CODE(compiler,"  b %d%c\n", label,
      (compiler->labels[label]!=NULL) ? 'b' : 'f');

  powerpc_add_fixup (compiler, 0, compiler->codeptr, label);
  powerpc_emit (compiler, 0x48000000);
}

1594
void <