489
InstImmU( PPC_ADDI, R_TOP, 0, 0 );
490
InstImm( PPC_LWZ, R_TOP, R_TOP, 0 ); // *(int *)0 to crash to debugger
722
printf("%08lx BREAK\n",instruction);
724
InstImmU( "addi", PPC_ADDI, R_TOP, 0, 0 );
725
InstImm( "lwz", PPC_LWZ, R_TOP, R_TOP, 0 ); // *(int *)0 to crash to debugger
494
InstImm( PPC_ADDI, R_STACK, R_STACK, -Constant4() ); // sub R_STACK, R_STACK, imm
732
printf("%08x ENTER\t%04x\n",instruction,v);
734
opStackRegType[opStackDepth] = 0;
736
if(mainFunction == 1)
738
// Main VM entry point is the first thing we compile, so save off operand stack
739
// registers here. This avoids issues with trying to trick the native compiler
740
// into doing it, and properly matches the PowerPC ABI
741
InstImm( "addi", PPC_ADDI, R_REAL_STACK, R_REAL_STACK, -OP_STACK_MAX_DEPTH*4 ); // sub R_STACK, R_STACK, imm
742
for(i = 0; i < OP_STACK_MAX_DEPTH; i++)
743
InstImm( "stw", PPC_STW, opStackIntRegisters[i], R_REAL_STACK, i*4);
745
InstImm( "addi", PPC_ADDI, R_STACK, R_STACK, -v ); // sub R_STACK, R_STACK, imm
499
if (code[pc] == OP_LOAD4 || code[pc] == OP_LOAD2 || code[pc] == OP_LOAD1) {
751
printf("%08x CONST\t%08x\n",instruction,v);
753
opStackLoadInstructionAddr[opStackDepth] = 0;
502
754
if ( v < 32768 && v >= -32768 ) {
503
InstImmU( PPC_ADDI, R_TOP, 0, v & 0xffff );
755
InstImmU( "addi", PPC_ADDI, opStackIntRegisters[opStackDepth], 0, v & 0xffff );
505
InstImmU( PPC_ADDIS, R_TOP, 0, (v >> 16)&0xffff );
757
InstImmU( "addis", PPC_ADDIS, opStackIntRegisters[opStackDepth], 0, (v >> 16)&0xffff );
506
758
if ( v & 0xffff ) {
507
InstImmU( PPC_ORI, R_TOP, R_TOP, v & 0xffff );
759
InstImmU( "ori", PPC_ORI, opStackIntRegisters[opStackDepth], opStackIntRegisters[opStackDepth], v & 0xffff );
510
if (code[pc] == OP_LOAD4) {
511
Inst( PPC_LWZX, R_TOP, R_TOP, R_MEMBASE ); // load from memory base
514
} else if (code[pc] == OP_LOAD2) {
515
Inst( PPC_LHZX, R_TOP, R_TOP, R_MEMBASE ); // load from memory base
518
} else if (code[pc] == OP_LOAD1) {
519
Inst( PPC_LBZX, R_TOP, R_TOP, R_MEMBASE ); // load from memory base
523
if (code[pc] == OP_STORE4) {
524
InstImm( PPC_LWZ, R_SECOND, R_OPSTACK, 0 ); // get value from opstack
525
InstImm( PPC_ADDI, R_OPSTACK, R_OPSTACK, -4 );
526
//Inst( PPC_AND, R_MEMMASK, R_SECOND, R_SECOND ); // mask it
527
Inst( PPC_STWX, R_TOP, R_SECOND, R_MEMBASE ); // store from memory base
532
} else if (code[pc] == OP_STORE2) {
533
InstImm( PPC_LWZ, R_SECOND, R_OPSTACK, 0 ); // get value from opstack
534
InstImm( PPC_ADDI, R_OPSTACK, R_OPSTACK, -4 );
535
//Inst( PPC_AND, R_MEMMASK, R_SECOND, R_SECOND ); // mask it
536
Inst( PPC_STHX, R_TOP, R_SECOND, R_MEMBASE ); // store from memory base
541
} else if (code[pc] == OP_STORE1) {
542
InstImm( PPC_LWZ, R_SECOND, R_OPSTACK, 0 ); // get value from opstack
543
InstImm( PPC_ADDI, R_OPSTACK, R_OPSTACK, -4 );
544
//Inst( PPC_AND, R_MEMMASK, R_SECOND, R_SECOND ); // mask it
545
Inst( PPC_STBX, R_TOP, R_SECOND, R_MEMBASE ); // store from memory base
762
opStackRegType[opStackDepth] = 1;
551
764
if (code[pc] == OP_JUMP) {
554
InstImm( PPC_STWU, R_TOP, R_OPSTACK, 4 );
559
769
oc1 = Constant4();
772
printf("%08x LOCAL\t%08x\n",instruction,oc1);
560
774
if (code[pc] == OP_LOAD4 || code[pc] == OP_LOAD2 || code[pc] == OP_LOAD1) {
561
775
oc1 &= vm->dataMask;
563
InstImm( PPC_ADDI, R_TOP, R_STACK, oc1 );
564
if (code[pc] == OP_LOAD4) {
565
Inst( PPC_LWZX, R_TOP, R_TOP, R_MEMBASE ); // load from memory base
568
} else if (code[pc] == OP_LOAD2) {
569
Inst( PPC_LHZX, R_TOP, R_TOP, R_MEMBASE ); // load from memory base
572
} else if (code[pc] == OP_LOAD1) {
573
Inst( PPC_LBZX, R_TOP, R_TOP, R_MEMBASE ); // load from memory base
577
if (code[pc] == OP_STORE4) {
578
InstImm( PPC_LWZ, R_SECOND, R_OPSTACK, 0 ); // get value from opstack
579
InstImm( PPC_ADDI, R_OPSTACK, R_OPSTACK, -4 );
580
//Inst( PPC_AND, R_MEMMASK, R_SECOND, R_SECOND ); // mask it
581
Inst( PPC_STWX, R_TOP, R_SECOND, R_MEMBASE ); // store from memory base
586
} else if (code[pc] == OP_STORE2) {
587
InstImm( PPC_LWZ, R_SECOND, R_OPSTACK, 0 ); // get value from opstack
588
InstImm( PPC_ADDI, R_OPSTACK, R_OPSTACK, -4 );
589
//Inst( PPC_AND, R_MEMMASK, R_SECOND, R_SECOND ); // mask it
590
Inst( PPC_STHX, R_TOP, R_SECOND, R_MEMBASE ); // store from memory base
595
} else if (code[pc] == OP_STORE1) {
596
InstImm( PPC_LWZ, R_SECOND, R_OPSTACK, 0 ); // get value from opstack
597
InstImm( PPC_ADDI, R_OPSTACK, R_OPSTACK, -4 );
598
//Inst( PPC_AND, R_MEMMASK, R_SECOND, R_SECOND ); // mask it
599
Inst( PPC_STBX, R_TOP, R_SECOND, R_MEMBASE ); // store from memory base
605
InstImm( PPC_STWU, R_TOP, R_OPSTACK, 4 );
777
InstImm( "addi", PPC_ADDI, opStackIntRegisters[opStackDepth], R_STACK, oc1 );
778
opStackRegType[opStackDepth] = 1;
779
opStackLoadInstructionAddr[opStackDepth] = 0;
609
ltop(); // get value from opstack
610
InstImm( PPC_ADDI, R_OPSTACK, R_OPSTACK, -4 );
611
InstImm( PPC_ADDI, R_EA, R_STACK, Constant1() ); // location to put it
612
Inst( PPC_STWX, R_TOP, R_EA, R_MEMBASE );
786
printf("%08x ARG \t%08x\n",instruction,v);
788
InstImm( "addi", PPC_ADDI, R_EA, R_STACK, v ); // location to put it
789
if(opStackRegType[opStackDepth-1] == 1)
790
Inst( "stwx", PPC_STWX, opStackIntRegisters[opStackDepth-1], R_EA, R_MEMBASE );
792
Inst( "stfsx", PPC_STFSX, opStackFloatRegisters[opStackDepth-1], R_EA, R_MEMBASE );
793
opStackRegType[opStackDepth-1] = 0;
794
opStackLoadInstructionAddr[opStackDepth-1] = 0;
616
Inst( PPC_MFSPR, R_SECOND, 8, 0 ); // move from link register
617
InstImm( PPC_STWU, R_SECOND, R_REAL_STACK, -16 ); // save off the old return address
619
Inst( PPC_MTSPR, R_ASMCALL, 9, 0 ); // move to count register
620
Inst( PPC_BCCTR | 1, 20, 0, 0 ); // jump and link to the count register
622
InstImm( PPC_LWZ, R_SECOND, R_REAL_STACK, 0 ); // fetch the old return address
623
InstImm( PPC_ADDI, R_REAL_STACK, R_REAL_STACK, 16 );
624
Inst( PPC_MTSPR, R_SECOND, 8, 0 ); // move to link register
801
printf("%08x CALL\n",instruction);
803
assertInteger(opStackDepth-1);
804
assert(opStackDepth > 0);
805
Inst( "mflr", PPC_MFSPR, R_SECOND, 8, 0 ); // move from link register
806
InstImm( "stwu", PPC_STWU, R_SECOND, R_REAL_STACK, -16 ); // save off the old return address
808
// Spill operand stack registers.
809
spillOpStack(opStackDepth);
811
// We need to leave R_OPSTACK pointing to the top entry on the stack, which is the call address.
812
// It will be consumed (and R4 decremented) by the AsmCall code.
813
InstImm( "addi", PPC_ADDI, R_OPSTACK, R_OPSTACK, opStackDepth*4);
815
Inst( "mtctr", PPC_MTSPR, R_ASMCALL, 9, 0 ); // move to count register
816
Inst( "bctrl", PPC_BCCTR | 1, 20, 0, 0 ); // jump and link to the count register
818
// R4 now points to the top of the operand stack, which has the return value in it. We want to
819
// back off the pointer to point to the base of our local operand stack and then reload the stack.
821
InstImm("addi", PPC_ADDI, R_OPSTACK, R_OPSTACK, -opStackDepth*4);
823
// Reload operand stack.
824
loadOpStack(opStackDepth);
826
InstImm( "lwz", PPC_LWZ, R_SECOND, R_REAL_STACK, 0 ); // fetch the old return address
827
InstImm( "addi", PPC_ADDI, R_REAL_STACK, R_REAL_STACK, 16 );
828
Inst( "mtlr", PPC_MTSPR, R_SECOND, 8, 0 ); // move to link register
628
InstImm( PPC_ADDI, R_OPSTACK, R_OPSTACK, 4 );
833
printf("%08x PUSH\n",instruction);
835
opStackRegType[opStackDepth] = 1; // Garbage int value.
632
InstImm( PPC_ADDI, R_OPSTACK, R_OPSTACK, -4 );
841
printf("%08x POP\n",instruction);
844
opStackRegType[opStackDepth] = 0; // ??
845
opStackLoadInstructionAddr[opStackDepth-1] = 0;
636
InstImm( PPC_ADDI, R_STACK, R_STACK, Constant4() ); // add R_STACK, R_STACK, imm
637
Inst( PPC_BCLR, 20, 0, 0 ); // branch unconditionally to link register
850
printf("%08x LEAVE\n",instruction);
852
assert(opStackDepth == 1);
853
assert(opStackRegType[0] != 0);
854
// Save return value onto top of op stack. We also have to increment R_OPSTACK
855
switch(opStackRegType[0])
857
case 1: // Integer register
858
InstImm( "stw", PPC_STWU, opStackIntRegisters[0], R_OPSTACK, 4);
860
case 2: // Float register
861
InstImm( "stfs", PPC_STFSU, opStackFloatRegisters[0], R_OPSTACK, 4);
864
InstImm( "addi", PPC_ADDI, R_STACK, R_STACK, Constant4() ); // add R_STACK, R_STACK, imm
865
if(mainFunction == 1)
867
for(i = 0; i < OP_STACK_MAX_DEPTH; i++)
868
InstImm( "lwz", PPC_LWZ, opStackIntRegisters[i], R_REAL_STACK, i*4);
869
InstImm( "addi", PPC_ADDI, R_REAL_STACK, R_REAL_STACK, OP_STACK_MAX_DEPTH*4 );
872
opStackRegType[opStackDepth] = 0;
873
opStackLoadInstructionAddr[opStackDepth] = 0;
874
Inst( "blr", PPC_BCLR, 20, 0, 0 ); // branch unconditionally to link register
641
ltop(); // get value from opstack
642
//Inst( PPC_AND, R_MEMMASK, R_TOP, R_TOP ); // mask it
643
Inst( PPC_LWZX, R_TOP, R_TOP, R_MEMBASE ); // load from memory base
644
InstImm( PPC_STW, R_TOP, R_OPSTACK, 0 );
879
printf("%08x LOAD4\n",instruction);
881
// We should try to figure out whether to use LWZX or LFSX based
882
// on some kind of code analysis after subsequent passes. I think what
883
// we could do is store the compiled load instruction address along with
884
// the register type. When we hit the first mismatched operator, we go back
885
// and patch the load. Since LCC's operand stack should be at 0 depth by the
886
// time we hit a branch, this should work fairly well. FIXME FIXME FIXME.
887
assertInteger(opStackDepth-1);
888
opStackLoadInstructionAddr[opStackDepth-1] = &buf[ compiledOfs ];
889
Inst( "lwzx", PPC_LWZX, opStackIntRegisters[opStackDepth-1], opStackIntRegisters[opStackDepth-1], R_MEMBASE );// load from memory base
890
opStackRegType[opStackDepth-1] = 1;
648
ltop(); // get value from opstack
649
//Inst( PPC_AND, R_MEMMASK, R_TOP, R_TOP ); // mask it
650
Inst( PPC_LHZX, R_TOP, R_TOP, R_MEMBASE ); // load from memory base
651
InstImm( PPC_STW, R_TOP, R_OPSTACK, 0 );
895
printf("%08x LOAD2\n",instruction);
897
assertInteger(opStackDepth-1);
898
opStackLoadInstructionAddr[opStackDepth-1] = 0;
899
Inst( "lhzx", PPC_LHZX, opStackIntRegisters[opStackDepth-1], opStackIntRegisters[opStackDepth-1], R_MEMBASE );// load from memory base
900
opStackRegType[opStackDepth-1] = 1;
655
ltop(); // get value from opstack
656
//Inst( PPC_AND, R_MEMMASK, R_TOP, R_TOP ); // mask it
657
Inst( PPC_LBZX, R_TOP, R_TOP, R_MEMBASE ); // load from memory base
658
InstImm( PPC_STW, R_TOP, R_OPSTACK, 0 );
905
printf("%08x LOAD1\n",instruction);
907
assertInteger(opStackDepth-1);
908
opStackLoadInstructionAddr[opStackDepth-1] = 0;
909
Inst( "lbzx", PPC_LBZX, opStackIntRegisters[opStackDepth-1], opStackIntRegisters[opStackDepth-1], R_MEMBASE );// load from memory base
910
opStackRegType[opStackDepth-1] = 1;
662
ltopandsecond(); // get value from opstack
663
//Inst( PPC_AND, R_MEMMASK, R_SECOND, R_SECOND ); // mask it
664
Inst( PPC_STWX, R_TOP, R_SECOND, R_MEMBASE ); // store from memory base
915
printf("%08x STORE4\n",instruction);
917
assertInteger(opStackDepth-2);
918
if(opStackRegType[opStackDepth-1] == 1)
919
Inst( "stwx", PPC_STWX, opStackIntRegisters[opStackDepth-1],
920
opStackIntRegisters[opStackDepth-2], R_MEMBASE ); // store from memory base
922
Inst( "stfsx", PPC_STFSX, opStackFloatRegisters[opStackDepth-1],
923
opStackIntRegisters[opStackDepth-2], R_MEMBASE ); // store from memory base
924
opStackRegType[opStackDepth-1] = 0;
925
opStackRegType[opStackDepth-2] = 0;
926
opStackLoadInstructionAddr[opStackDepth-1] = 0;
927
opStackLoadInstructionAddr[opStackDepth-2] = 0;
668
ltopandsecond(); // get value from opstack
669
//Inst( PPC_AND, R_MEMMASK, R_SECOND, R_SECOND ); // mask it
670
Inst( PPC_STHX, R_TOP, R_SECOND, R_MEMBASE ); // store from memory base
933
printf("%08x STORE2\n",instruction);
935
assertInteger(opStackDepth-1);
936
assertInteger(opStackDepth-2);
937
Inst( "sthx", PPC_STHX, opStackIntRegisters[opStackDepth-1],
938
opStackIntRegisters[opStackDepth-2], R_MEMBASE ); // store from memory base
939
opStackRegType[opStackDepth-1] = 0;
940
opStackRegType[opStackDepth-2] = 0;
941
opStackLoadInstructionAddr[opStackDepth-1] = 0;
942
opStackLoadInstructionAddr[opStackDepth-2] = 0;
674
ltopandsecond(); // get value from opstack
675
//Inst( PPC_AND, R_MEMMASK, R_SECOND, R_SECOND ); // mask it
676
Inst( PPC_STBX, R_TOP, R_SECOND, R_MEMBASE ); // store from memory base
948
printf("%08x STORE1\n",instruction);
950
assertInteger(opStackDepth-1);
951
assertInteger(opStackDepth-2);
952
Inst( "stbx", PPC_STBX, opStackIntRegisters[opStackDepth-1],
953
opStackIntRegisters[opStackDepth-2], R_MEMBASE ); // store from memory base
954
opStackRegType[opStackDepth-1] = 0;
955
opStackRegType[opStackDepth-2] = 0;
956
opStackLoadInstructionAddr[opStackDepth-1] = 0;
957
opStackLoadInstructionAddr[opStackDepth-2] = 0;
681
ltopandsecond(); // get value from opstack
682
Inst( PPC_CMP, 0, R_SECOND, R_TOP );
964
printf("%08x EQ\n",instruction);
966
assertInteger(opStackDepth-1);
967
assertInteger(opStackDepth-2);
968
Inst( "cmp", PPC_CMP, 0, opStackIntRegisters[opStackDepth-2], opStackIntRegisters[opStackDepth-1] );
969
opStackRegType[opStackDepth-1] = 0;
970
opStackRegType[opStackDepth-2] = 0;
971
opStackLoadInstructionAddr[opStackDepth-1] = 0;
972
opStackLoadInstructionAddr[opStackDepth-2] = 0;
685
InstImm( PPC_BC, 4, 2, 8 );
976
InstImm( "bc", PPC_BC, 4, 2, 8 );
687
978
v = vm->instructionPointers[ i ] - (int)&buf[compiledOfs];
691
Emit4(PPC_B | (v&0x3ffffff) );
982
Emit4("b", PPC_B | (v&0x3ffffff) );
695
ltopandsecond(); // get value from opstack
696
Inst( PPC_CMP, 0, R_SECOND, R_TOP );
987
printf("%08x NE\n",instruction);
989
assertInteger(opStackDepth-1);
990
assertInteger(opStackDepth-2);
991
Inst( "cmp", PPC_CMP, 0, opStackIntRegisters[opStackDepth-2], opStackIntRegisters[opStackDepth-1] );
992
opStackRegType[opStackDepth-1] = 0;
993
opStackRegType[opStackDepth-2] = 0;
994
opStackLoadInstructionAddr[opStackDepth-1] = 0;
995
opStackLoadInstructionAddr[opStackDepth-2] = 0;
699
InstImm( PPC_BC, 12, 2, 8 );
999
InstImm( "bc", PPC_BC, 12, 2, 8 );
700
1000
if ( pass==1 ) {
701
1001
v = vm->instructionPointers[ i ] - (int)&buf[compiledOfs];
705
Emit4(PPC_B | (unsigned int)(v&0x3ffffff) );
706
// InstImm( PPC_BC, 4, 2, v );
1005
Emit4("b", PPC_B | (unsigned int)(v&0x3ffffff) );
1006
// InstImm( "bc", PPC_BC, 4, 2, v );
711
ltopandsecond(); // get value from opstack
712
Inst( PPC_CMP, 0, R_SECOND, R_TOP );
1012
printf("%08x LTI\n",instruction);
1014
assertInteger(opStackDepth-1);
1015
assertInteger(opStackDepth-2);
1016
Inst( "cmp", PPC_CMP, 0, opStackIntRegisters[opStackDepth-2], opStackIntRegisters[opStackDepth-1] );
1017
opStackRegType[opStackDepth-1] = 0;
1018
opStackRegType[opStackDepth-2] = 0;
1019
opStackLoadInstructionAddr[opStackDepth-1] = 0;
1020
opStackLoadInstructionAddr[opStackDepth-2] = 0;
713
1022
i = Constant4();
715
InstImm( PPC_BC, 4, 0, 8 );
1024
InstImm( "bc", PPC_BC, 4, 0, 8 );
716
1025
if ( pass==1 ) {
717
1026
v = vm->instructionPointers[ i ] - (int)&buf[compiledOfs];
721
Emit4(PPC_B | (unsigned int)(v&0x3ffffff) );
722
// InstImm( PPC_BC, 12, 0, v );
1030
Emit4("b", PPC_B | (unsigned int)(v&0x3ffffff) );
1031
// InstImm( "bc", PPC_BC, 12, 0, v );
726
ltopandsecond(); // get value from opstack
727
Inst( PPC_CMP, 0, R_SECOND, R_TOP );
1036
printf("%08x LEI\n",instruction);
1038
assertInteger(opStackDepth-1);
1039
assertInteger(opStackDepth-2);
1040
Inst( "cmp", PPC_CMP, 0, opStackIntRegisters[opStackDepth-2], opStackIntRegisters[opStackDepth-1] );
1041
opStackRegType[opStackDepth-1] = 0;
1042
opStackRegType[opStackDepth-2] = 0;
1043
opStackLoadInstructionAddr[opStackDepth-1] = 0;
1044
opStackLoadInstructionAddr[opStackDepth-2] = 0;
728
1046
i = Constant4();
730
InstImm( PPC_BC, 12, 1, 8 );
1048
InstImm( "bc", PPC_BC, 12, 1, 8 );
731
1049
if ( pass==1 ) {
732
1050
v = vm->instructionPointers[ i ] - (int)&buf[compiledOfs];
736
Emit4(PPC_B | (unsigned int)(v&0x3ffffff) );
737
// InstImm( PPC_BC, 4, 1, v );
1054
Emit4("b", PPC_B | (unsigned int)(v&0x3ffffff) );
1055
// InstImm( "bc", PPC_BC, 4, 1, v );
741
ltopandsecond(); // get value from opstack
742
Inst( PPC_CMP, 0, R_SECOND, R_TOP );
1060
printf("%08x GTI\n",instruction);
1062
assertInteger(opStackDepth-1);
1063
assertInteger(opStackDepth-2);
1064
Inst( "cmp", PPC_CMP, 0, opStackIntRegisters[opStackDepth-2], opStackIntRegisters[opStackDepth-1] );
1065
opStackRegType[opStackDepth-1] = 0;
1066
opStackRegType[opStackDepth-2] = 0;
1067
opStackLoadInstructionAddr[opStackDepth-1] = 0;
1068
opStackLoadInstructionAddr[opStackDepth-2] = 0;
743
1070
i = Constant4();
745
InstImm( PPC_BC, 4, 1, 8 );
1072
InstImm( "bc", PPC_BC, 4, 1, 8 );
746
1073
if ( pass==1 ) {
747
1074
v = vm->instructionPointers[ i ] - (int)&buf[compiledOfs];
751
Emit4(PPC_B | (unsigned int)(v&0x3ffffff) );
752
// InstImm( PPC_BC, 12, 1, v );
1078
Emit4("b", PPC_B | (unsigned int)(v&0x3ffffff) );
1079
// InstImm( "bc", PPC_BC, 12, 1, v );
756
ltopandsecond(); // get value from opstack
757
Inst( PPC_CMP, 0, R_SECOND, R_TOP );
1084
printf("%08x GEI\n",instruction);
1086
assertInteger(opStackDepth-1);
1087
assertInteger(opStackDepth-2);
1088
Inst( "cmp", PPC_CMP, 0, opStackIntRegisters[opStackDepth-2], opStackIntRegisters[opStackDepth-1] );
1089
opStackRegType[opStackDepth-1] = 0;
1090
opStackRegType[opStackDepth-2] = 0;
1091
opStackLoadInstructionAddr[opStackDepth-1] = 0;
1092
opStackLoadInstructionAddr[opStackDepth-2] = 0;
758
1094
i = Constant4();
760
InstImm( PPC_BC, 12, 0, 8 );
1096
InstImm( "bc", PPC_BC, 12, 0, 8 );
761
1097
if ( pass==1 ) {
762
1098
v = vm->instructionPointers[ i ] - (int)&buf[compiledOfs];
766
Emit4(PPC_B | (unsigned int)(v&0x3ffffff) );
767
// InstImm( PPC_BC, 4, 0, v );
1102
Emit4("b", PPC_B | (unsigned int)(v&0x3ffffff) );
1103
// InstImm( "bc", PPC_BC, 4, 0, v );
771
ltopandsecond(); // get value from opstack
772
Inst( PPC_CMPL, 0, R_SECOND, R_TOP );
1108
printf("%08x LTU\n",instruction);
1110
assertInteger(opStackDepth-1);
1111
assertInteger(opStackDepth-2);
1112
Inst( "cmpl", PPC_CMPL, 0, opStackIntRegisters[opStackDepth-2], opStackIntRegisters[opStackDepth-1] );
1113
opStackRegType[opStackDepth-1] = 0;
1114
opStackRegType[opStackDepth-2] = 0;
1115
opStackLoadInstructionAddr[opStackDepth-1] = 0;
1116
opStackLoadInstructionAddr[opStackDepth-2] = 0;
773
1118
i = Constant4();
775
InstImm( PPC_BC, 4, 0, 8 );
1120
InstImm( "bc", PPC_BC, 4, 0, 8 );
776
1121
if ( pass==1 ) {
777
1122
v = vm->instructionPointers[ i ] - (int)&buf[compiledOfs];
781
Emit4(PPC_B | (unsigned int)(v&0x3ffffff) );
782
// InstImm( PPC_BC, 12, 0, v );
1126
Emit4("b", PPC_B | (unsigned int)(v&0x3ffffff) );
1127
// InstImm( "bc", PPC_BC, 12, 0, v );
786
ltopandsecond(); // get value from opstack
787
Inst( PPC_CMPL, 0, R_SECOND, R_TOP );
1132
printf("%08x LEU\n",instruction);
1134
assertInteger(opStackDepth-1);
1135
assertInteger(opStackDepth-2);
1136
Inst( "cmpl", PPC_CMPL, 0, opStackIntRegisters[opStackDepth-2], opStackIntRegisters[opStackDepth-1] );
1137
opStackRegType[opStackDepth-1] = 0;
1138
opStackRegType[opStackDepth-2] = 0;
1139
opStackLoadInstructionAddr[opStackDepth-1] = 0;
1140
opStackLoadInstructionAddr[opStackDepth-2] = 0;
788
1142
i = Constant4();
790
InstImm( PPC_BC, 12, 1, 8 );
1144
InstImm( "bc", PPC_BC, 12, 1, 8 );
791
1145
if ( pass==1 ) {
792
1146
v = vm->instructionPointers[ i ] - (int)&buf[compiledOfs];
796
Emit4(PPC_B | (unsigned int)(v&0x3ffffff) );
797
// InstImm( PPC_BC, 4, 1, v );
1150
Emit4("b", PPC_B | (unsigned int)(v&0x3ffffff) );
1151
// InstImm( "bc", PPC_BC, 4, 1, v );
801
ltopandsecond(); // get value from opstack
802
Inst( PPC_CMPL, 0, R_SECOND, R_TOP );
1156
printf("%08x GTU\n",instruction);
1158
assertInteger(opStackDepth-1);
1159
assertInteger(opStackDepth-2);
1160
Inst( "cmpl", PPC_CMPL, 0, opStackIntRegisters[opStackDepth-2], opStackIntRegisters[opStackDepth-1] );
1161
opStackRegType[opStackDepth-1] = 0;
1162
opStackRegType[opStackDepth-2] = 0;
1163
opStackLoadInstructionAddr[opStackDepth-1] = 0;
1164
opStackLoadInstructionAddr[opStackDepth-2] = 0;
803
1166
i = Constant4();
805
InstImm( PPC_BC, 4, 1, 8 );
1168
InstImm( "bc", PPC_BC, 4, 1, 8 );
806
1169
if ( pass==1 ) {
807
1170
v = vm->instructionPointers[ i ] - (int)&buf[compiledOfs];
811
Emit4(PPC_B | (unsigned int)(v&0x3ffffff) );
812
// InstImm( PPC_BC, 12, 1, v );
1174
Emit4("b", PPC_B | (unsigned int)(v&0x3ffffff) );
1175
// InstImm( "bc", PPC_BC, 12, 1, v );
816
ltopandsecond(); // get value from opstack
817
Inst( PPC_CMPL, 0, R_SECOND, R_TOP );
1180
printf("%08x GEU\n",instruction);
1182
assertInteger(opStackDepth-1);
1183
assertInteger(opStackDepth-2);
1184
Inst( "cmpl", PPC_CMPL, 0, opStackIntRegisters[opStackDepth-2], opStackIntRegisters[opStackDepth-1] );
1185
opStackRegType[opStackDepth-1] = 0;
1186
opStackRegType[opStackDepth-2] = 0;
1187
opStackLoadInstructionAddr[opStackDepth-1] = 0;
1188
opStackLoadInstructionAddr[opStackDepth-2] = 0;
818
1190
i = Constant4();
820
InstImm( PPC_BC, 12, 0, 8 );
1192
InstImm( "bc", PPC_BC, 12, 0, 8 );
821
1193
if ( pass==1 ) {
822
1194
v = vm->instructionPointers[ i ] - (int)&buf[compiledOfs];
826
Emit4(PPC_B | (unsigned int)(v&0x3ffffff) );
827
// InstImm( PPC_BC, 4, 0, v );
1198
Emit4("b", PPC_B | (unsigned int)(v&0x3ffffff) );
1199
// InstImm( "bc", PPC_BC, 4, 0, v );
832
fltopandsecond(); // get value from opstack
833
Inst( PPC_FCMPU, 0, R_TOP, R_SECOND );
1205
printf("%08x EQF\n",instruction);
1207
makeFloat(opStackDepth-1);
1208
makeFloat(opStackDepth-2);
1209
Inst( "fcmpu", PPC_FCMPU, 0, opStackFloatRegisters[opStackDepth-2], opStackFloatRegisters[opStackDepth-1] );
1210
opStackRegType[opStackDepth-1] = 0;
1211
opStackRegType[opStackDepth-2] = 0;
1212
opStackLoadInstructionAddr[opStackDepth-1] = 0;
1213
opStackLoadInstructionAddr[opStackDepth-2] = 0;
834
1215
i = Constant4();
836
InstImm( PPC_BC, 4, 2, 8 );
1217
InstImm( "bc", PPC_BC, 4, 2, 8 );
837
1218
if ( pass==1 ) {
838
1219
v = vm->instructionPointers[ i ] - (int)&buf[compiledOfs];
842
Emit4(PPC_B | (unsigned int)(v&0x3ffffff) );
843
// InstImm( PPC_BC, 12, 2, v );
1223
Emit4("b", PPC_B | (unsigned int)(v&0x3ffffff) );
1224
// InstImm( "bc", PPC_BC, 12, 2, v );
847
fltopandsecond(); // get value from opstack
848
Inst( PPC_FCMPU, 0, R_TOP, R_SECOND );
1229
printf("%08x NEF\n",instruction);
1231
makeFloat(opStackDepth-1);
1232
makeFloat(opStackDepth-2);
1233
Inst( "fcmpu", PPC_FCMPU, 0, opStackFloatRegisters[opStackDepth-2], opStackFloatRegisters[opStackDepth-1] );
1234
opStackRegType[opStackDepth-1] = 0;
1235
opStackRegType[opStackDepth-2] = 0;
1236
opStackLoadInstructionAddr[opStackDepth-1] = 0;
1237
opStackLoadInstructionAddr[opStackDepth-2] = 0;
849
1239
i = Constant4();
851
InstImm( PPC_BC, 12, 2, 8 );
1241
InstImm( "bc", PPC_BC, 12, 2, 8 );
852
1242
if ( pass==1 ) {
853
1243
v = vm->instructionPointers[ i ] - (int)&buf[compiledOfs];
857
Emit4(PPC_B | (unsigned int)(v&0x3ffffff) );
858
// InstImm( PPC_BC, 4, 2, v );
1247
Emit4("b", PPC_B | (unsigned int)(v&0x3ffffff) );
1248
// InstImm( "bc", PPC_BC, 4, 2, v );
862
fltopandsecond(); // get value from opstack
863
Inst( PPC_FCMPU, 0, R_SECOND, R_TOP );
1253
printf("%08x LTF\n",instruction);
1255
makeFloat(opStackDepth-1);
1256
makeFloat(opStackDepth-2);
1257
Inst( "fcmpu", PPC_FCMPU, 0, opStackFloatRegisters[opStackDepth-2], opStackFloatRegisters[opStackDepth-1] );
1258
opStackRegType[opStackDepth-1] = 0;
1259
opStackRegType[opStackDepth-2] = 0;
1260
opStackLoadInstructionAddr[opStackDepth-1] = 0;
1261
opStackLoadInstructionAddr[opStackDepth-2] = 0;
864
1263
i = Constant4();
866
InstImm( PPC_BC, 4, 0, 8 );
1265
InstImm( "bc", PPC_BC, 4, 0, 8 );
867
1266
if ( pass==1 ) {
868
1267
v = vm->instructionPointers[ i ] - (int)&buf[compiledOfs];
872
Emit4(PPC_B | (unsigned int)(v&0x3ffffff) );
873
// InstImm( PPC_BC, 12, 0, v );
1271
Emit4("b", PPC_B | (unsigned int)(v&0x3ffffff) );
1272
// InstImm( "bc", PPC_BC, 12, 0, v );
877
fltopandsecond(); // get value from opstack
878
Inst( PPC_FCMPU, 0, R_SECOND, R_TOP );
1277
printf("%08x LEF\n",instruction);
1279
makeFloat(opStackDepth-1);
1280
makeFloat(opStackDepth-2);
1281
Inst( "fcmpu", PPC_FCMPU, 0, opStackFloatRegisters[opStackDepth-2], opStackFloatRegisters[opStackDepth-1] );
1282
opStackRegType[opStackDepth-1] = 0;
1283
opStackRegType[opStackDepth-2] = 0;
1284
opStackLoadInstructionAddr[opStackDepth-1] = 0;
1285
opStackLoadInstructionAddr[opStackDepth-2] = 0;
879
1287
i = Constant4();
881
InstImm( PPC_BC, 12, 1, 8 );
1289
InstImm( "bc", PPC_BC, 12, 1, 8 );
882
1290
if ( pass==1 ) {
883
1291
v = vm->instructionPointers[ i ] - (int)&buf[compiledOfs];
887
Emit4(PPC_B | (unsigned int)(v&0x3ffffff) );
888
// InstImm( PPC_BC, 4, 1, v );
1295
Emit4("b", PPC_B | (unsigned int)(v&0x3ffffff) );
1296
// InstImm( "bc", PPC_BC, 4, 1, v );
892
fltopandsecond(); // get value from opstack
893
Inst( PPC_FCMPU, 0, R_SECOND, R_TOP );
1301
printf("%08x GTF\n",instruction);
1303
makeFloat(opStackDepth-1);
1304
makeFloat(opStackDepth-2);
1305
Inst( "fcmpu", PPC_FCMPU, 0, opStackFloatRegisters[opStackDepth-2], opStackFloatRegisters[opStackDepth-1] );
1306
opStackRegType[opStackDepth-1] = 0;
1307
opStackRegType[opStackDepth-2] = 0;
1308
opStackLoadInstructionAddr[opStackDepth-1] = 0;
1309
opStackLoadInstructionAddr[opStackDepth-2] = 0;
894
1311
i = Constant4();
896
InstImm( PPC_BC, 4, 1, 8 );
1313
InstImm( "bc", PPC_BC, 4, 1, 8 );
897
1314
if ( pass==1 ) {
898
1315
v = vm->instructionPointers[ i ] - (int)&buf[compiledOfs];
902
Emit4(PPC_B | (unsigned int)(v&0x3ffffff) );
903
// InstImm( PPC_BC, 12, 1, v );
1319
Emit4("b", PPC_B | (unsigned int)(v&0x3ffffff) );
1320
// InstImm( "bc", PPC_BC, 12, 1, v );
907
fltopandsecond(); // get value from opstack
908
Inst( PPC_FCMPU, 0, R_SECOND, R_TOP );
1325
printf("%08x GEF\n",instruction);
1327
makeFloat(opStackDepth-1);
1328
makeFloat(opStackDepth-2);
1329
Inst( "fcmpu", PPC_FCMPU, 0, opStackFloatRegisters[opStackDepth-2], opStackFloatRegisters[opStackDepth-1] );
1330
opStackRegType[opStackDepth-1] = 0;
1331
opStackRegType[opStackDepth-2] = 0;
1332
opStackLoadInstructionAddr[opStackDepth-1] = 0;
1333
opStackLoadInstructionAddr[opStackDepth-2] = 0;
909
1335
i = Constant4();
911
InstImm( PPC_BC, 12, 0, 8 );
1337
InstImm( "bc", PPC_BC, 12, 0, 8 );
912
1338
if ( pass==1 ) {
913
1339
v = vm->instructionPointers[ i ] - (int)&buf[compiledOfs];
917
Emit4(PPC_B | (unsigned int)(v&0x3ffffff) );
918
// InstImm( PPC_BC, 4, 0, v );
1343
Emit4("b", PPC_B | (unsigned int)(v&0x3ffffff) );
1344
// InstImm( "bc", PPC_BC, 4, 0, v );
923
ltop(); // get value from opstack
924
InstImm( PPC_SUBFIC, R_TOP, R_TOP, 0 );
925
InstImm( PPC_STW, R_TOP, R_OPSTACK, 0 ); // save value to opstack
1350
printf("%08x NEGI\n",instruction);
1352
assertInteger(opStackDepth-1);
1353
InstImm( "subfic", PPC_SUBFIC, opStackIntRegisters[opStackDepth-1], opStackIntRegisters[opStackDepth-1], 0 );
1354
opStackLoadInstructionAddr[opStackDepth-1] = 0;
929
ltop(); // get value from opstack
930
InstImm( PPC_LWZU, R_SECOND, R_OPSTACK, -4 ); // get value from opstack
931
Inst( PPC_ADD, R_TOP, R_TOP, R_SECOND );
932
InstImm( PPC_STW, R_TOP, R_OPSTACK, 0 ); // save value to opstack
1359
printf("%08x ADD\n",instruction);
1361
assertInteger(opStackDepth-1);
1362
assertInteger(opStackDepth-2);
1363
Inst( "add", PPC_ADD, opStackIntRegisters[opStackDepth-2], opStackIntRegisters[opStackDepth-1], opStackIntRegisters[opStackDepth-2] );
1364
opStackRegType[opStackDepth-1] = 0;
1365
opStackLoadInstructionAddr[opStackDepth-1] = 0;
936
ltop(); // get value from opstack
937
InstImm( PPC_LWZU, R_SECOND, R_OPSTACK, -4 ); // get value from opstack
938
Inst( PPC_SUBF, R_TOP, R_TOP, R_SECOND );
939
InstImm( PPC_STW, R_TOP, R_OPSTACK, 0 ); // save value to opstack
1371
printf("%08x SUB\n",instruction);
1373
assertInteger(opStackDepth-1);
1374
assertInteger(opStackDepth-2);
1375
Inst( "subf", PPC_SUBF, opStackIntRegisters[opStackDepth-2], opStackIntRegisters[opStackDepth-1], opStackIntRegisters[opStackDepth-2] );
1376
opStackRegType[opStackDepth-1] = 0;
1377
opStackLoadInstructionAddr[opStackDepth-1] = 0;
943
ltop(); // get value from opstack
944
InstImm( PPC_LWZU, R_SECOND, R_OPSTACK, -4 ); // get value from opstack
945
Inst( PPC_DIVW, R_TOP, R_SECOND, R_TOP );
946
InstImm( PPC_STW, R_TOP, R_OPSTACK, 0 ); // save value to opstack
1383
printf("%08x DIVI\n",instruction);
1385
assertInteger(opStackDepth-1);
1386
assertInteger(opStackDepth-2);
1387
Inst( "divw", PPC_DIVW, opStackIntRegisters[opStackDepth-2], opStackIntRegisters[opStackDepth-2], opStackIntRegisters[opStackDepth-1] );
1388
opStackRegType[opStackDepth-1] = 0;
1389
opStackLoadInstructionAddr[opStackDepth-1] = 0;
950
ltop(); // get value from opstack
951
InstImm( PPC_LWZU, R_SECOND, R_OPSTACK, -4 ); // get value from opstack
952
Inst( PPC_DIVWU, R_TOP, R_SECOND, R_TOP );
953
InstImm( PPC_STW, R_TOP, R_OPSTACK, 0 ); // save value to opstack
1395
printf("%08x DIVU\n",instruction);
1397
assertInteger(opStackDepth-1);
1398
assertInteger(opStackDepth-2);
1399
Inst( "divwu", PPC_DIVWU, opStackIntRegisters[opStackDepth-2], opStackIntRegisters[opStackDepth-2], opStackIntRegisters[opStackDepth-1] );
1400
opStackRegType[opStackDepth-1] = 0;
1401
opStackLoadInstructionAddr[opStackDepth-1] = 0;
957
ltop(); // get value from opstack
958
InstImm( PPC_LWZU, R_SECOND, R_OPSTACK, -4 ); // get value from opstack
959
Inst( PPC_DIVW, R_EA, R_SECOND, R_TOP );
960
Inst( PPC_MULLW, R_EA, R_TOP, R_EA );
961
Inst( PPC_SUBF, R_TOP, R_EA, R_SECOND );
962
InstImm( PPC_STW, R_TOP, R_OPSTACK, 0 ); // save value to opstack
1407
printf("%08x MODI\n",instruction);
1409
assertInteger(opStackDepth-1);
1410
assertInteger(opStackDepth-2);
1411
Inst( "divw", PPC_DIVW, R_EA, opStackIntRegisters[opStackDepth-2], opStackIntRegisters[opStackDepth-1] );
1412
Inst( "mullw", PPC_MULLW, R_EA, opStackIntRegisters[opStackDepth-1], R_EA );
1413
Inst( "subf", PPC_SUBF, opStackIntRegisters[opStackDepth-2], R_EA, opStackIntRegisters[opStackDepth-2] );
1414
opStackRegType[opStackDepth-1] = 0;
1415
opStackLoadInstructionAddr[opStackDepth-1] = 0;
966
ltop(); // get value from opstack
967
InstImm( PPC_LWZU, R_SECOND, R_OPSTACK, -4 ); // get value from opstack
968
Inst( PPC_DIVWU, R_EA, R_SECOND, R_TOP );
969
Inst( PPC_MULLW, R_EA, R_TOP, R_EA );
970
Inst( PPC_SUBF, R_TOP, R_EA, R_SECOND );
971
InstImm( PPC_STW, R_TOP, R_OPSTACK, 0 ); // save value to opstack
1421
printf("%08x MODU\n",instruction);
1423
assertInteger(opStackDepth-1);
1424
assertInteger(opStackDepth-2);
1425
Inst( "divwu", PPC_DIVWU, R_EA, opStackIntRegisters[opStackDepth-2], opStackIntRegisters[opStackDepth-1] );
1426
Inst( "mullw", PPC_MULLW, R_EA, opStackIntRegisters[opStackDepth-1], R_EA );
1427
Inst( "subf", PPC_SUBF, opStackIntRegisters[opStackDepth-2], R_EA, opStackIntRegisters[opStackDepth-2] );
1428
opStackRegType[opStackDepth-1] = 0;
1429
opStackLoadInstructionAddr[opStackDepth-1] = 0;
976
ltop(); // get value from opstack
977
InstImm( PPC_LWZU, R_SECOND, R_OPSTACK, -4 ); // get value from opstack
978
Inst( PPC_MULLW, R_TOP, R_SECOND, R_TOP );
979
InstImm( PPC_STW, R_TOP, R_OPSTACK, 0 ); // save value to opstack
1436
printf("%08x MULI\n",instruction);
1438
assertInteger(opStackDepth-1);
1439
assertInteger(opStackDepth-2);
1440
Inst( "mullw", PPC_MULLW, opStackIntRegisters[opStackDepth-2], opStackIntRegisters[opStackDepth-1], opStackIntRegisters[opStackDepth-2] );
1441
opStackRegType[opStackDepth-1] = 0;
1442
opStackLoadInstructionAddr[opStackDepth-1] = 0;
983
ltop(); // get value from opstack
984
InstImm( PPC_LWZU, R_SECOND, R_OPSTACK, -4 ); // get value from opstack
985
Inst( PPC_AND, R_SECOND, R_TOP, R_TOP );
986
InstImm( PPC_STW, R_TOP, R_OPSTACK, 0 ); // save value to opstack
1448
printf("%08x BAND\n",instruction);
1450
assertInteger(opStackDepth-1);
1451
assertInteger(opStackDepth-2);
1452
Inst( "and", PPC_AND, opStackIntRegisters[opStackDepth-2], opStackIntRegisters[opStackDepth-2], opStackIntRegisters[opStackDepth-1] );
1453
opStackRegType[opStackDepth-1] = 0;
1454
opStackLoadInstructionAddr[opStackDepth-1] = 0;
990
ltop(); // get value from opstack
991
InstImm( PPC_LWZU, R_SECOND, R_OPSTACK, -4 ); // get value from opstack
992
Inst( PPC_OR, R_SECOND, R_TOP, R_TOP );
993
InstImm( PPC_STW, R_TOP, R_OPSTACK, 0 ); // save value to opstack
1460
printf("%08x BOR\n",instruction);
1462
assertInteger(opStackDepth-1);
1463
assertInteger(opStackDepth-2);
1464
Inst( "or", PPC_OR, opStackIntRegisters[opStackDepth-2], opStackIntRegisters[opStackDepth-2], opStackIntRegisters[opStackDepth-1] );
1465
opStackRegType[opStackDepth-1] = 0;
1466
opStackLoadInstructionAddr[opStackDepth-1] = 0;
997
ltop(); // get value from opstack
998
InstImm( PPC_LWZU, R_SECOND, R_OPSTACK, -4 ); // get value from opstack
999
Inst( PPC_XOR, R_SECOND, R_TOP, R_TOP );
1000
InstImm( PPC_STW, R_TOP, R_OPSTACK, 0 ); // save value to opstack
1472
printf("%08x BXOR\n",instruction);
1474
assertInteger(opStackDepth-1);
1475
assertInteger(opStackDepth-2);
1476
Inst( "xor", PPC_XOR, opStackIntRegisters[opStackDepth-2], opStackIntRegisters[opStackDepth-2], opStackIntRegisters[opStackDepth-1] );
1477
opStackRegType[opStackDepth-1] = 0;
1478
opStackLoadInstructionAddr[opStackDepth-1] = 0;
1004
ltop(); // get value from opstack
1005
Inst( PPC_NOR, R_TOP, R_TOP, R_TOP );
1006
InstImm( PPC_STW, R_TOP, R_OPSTACK, 0 ); // save value to opstack
1484
printf("%08x BCOM\n",instruction);
1486
assertInteger(opStackDepth-1);
1487
Inst( "nor", PPC_NOR, opStackIntRegisters[opStackDepth-1], opStackIntRegisters[opStackDepth-1], opStackIntRegisters[opStackDepth-1] );
1488
opStackLoadInstructionAddr[opStackDepth-1] = 0;
1010
ltop(); // get value from opstack
1011
InstImm( PPC_LWZU, R_SECOND, R_OPSTACK, -4 ); // get value from opstack
1012
Inst( PPC_SLW, R_SECOND, R_TOP, R_TOP );
1013
InstImm( PPC_STW, R_TOP, R_OPSTACK, 0 ); // save value to opstack
1493
printf("%08x LSH\n",instruction);
1495
assertInteger(opStackDepth-1);
1496
assertInteger(opStackDepth-2);
1497
Inst( "slw", PPC_SLW, opStackIntRegisters[opStackDepth-2], opStackIntRegisters[opStackDepth-2], opStackIntRegisters[opStackDepth-1] );
1498
opStackRegType[opStackDepth-1] = 0;
1499
opStackLoadInstructionAddr[opStackDepth-1] = 0;
1017
ltop(); // get value from opstack
1018
InstImm( PPC_LWZU, R_SECOND, R_OPSTACK, -4 ); // get value from opstack
1019
Inst( PPC_SRAW, R_SECOND, R_TOP, R_TOP );
1020
InstImm( PPC_STW, R_TOP, R_OPSTACK, 0 ); // save value to opstack
1505
printf("%08x RSHI\n",instruction);
1507
assertInteger(opStackDepth-1);
1508
assertInteger(opStackDepth-2);
1509
Inst( "sraw", PPC_SRAW, opStackIntRegisters[opStackDepth-2], opStackIntRegisters[opStackDepth-2], opStackIntRegisters[opStackDepth-1] );
1510
opStackRegType[opStackDepth-1] = 0;
1511
opStackLoadInstructionAddr[opStackDepth-1] = 0;
1024
ltop(); // get value from opstack
1025
InstImm( PPC_LWZU, R_SECOND, R_OPSTACK, -4 ); // get value from opstack
1026
Inst( PPC_SRW, R_SECOND, R_TOP, R_TOP );
1027
InstImm( PPC_STW, R_TOP, R_OPSTACK, 0 ); // save value to opstack
1517
printf("%08x RSHU\n",instruction);
1519
assertInteger(opStackDepth-1);
1520
assertInteger(opStackDepth-2);
1521
Inst( "srw", PPC_SRW, opStackIntRegisters[opStackDepth-2], opStackIntRegisters[opStackDepth-2], opStackIntRegisters[opStackDepth-1] );
1522
opStackRegType[opStackDepth-1] = 0;
1523
opStackLoadInstructionAddr[opStackDepth-1] = 0;
1032
InstImm( PPC_LFS, R_TOP, R_OPSTACK, 0 ); // get value from opstack
1033
Inst( PPC_FNEG, R_TOP, 0, R_TOP );
1034
InstImm( PPC_STFS, R_TOP, R_OPSTACK, 0 ); // save value to opstack
1530
printf("%08x NEGF\n",instruction);
1532
makeFloat(opStackDepth-1);
1533
Inst( "fneg", PPC_FNEG, opStackFloatRegisters[opStackDepth-1], 0, opStackFloatRegisters[opStackDepth-1] );
1534
opStackLoadInstructionAddr[opStackDepth-1] = 0;
1038
InstImm( PPC_LFS, R_TOP, R_OPSTACK, 0 ); // get value from opstack
1039
InstImm( PPC_LFSU, R_SECOND, R_OPSTACK, -4 ); // get value from opstack
1040
Inst( PPC_FADDS, R_TOP, R_SECOND, R_TOP );
1041
InstImm( PPC_STFS, R_TOP, R_OPSTACK, 0 ); // save value to opstack
1539
printf("%08x ADDF\n",instruction);
1541
makeFloat(opStackDepth-1);
1542
makeFloat(opStackDepth-2);
1543
Inst( "fadds", PPC_FADDS, opStackFloatRegisters[opStackDepth-2], opStackFloatRegisters[opStackDepth-2], opStackFloatRegisters[opStackDepth-1] );
1544
opStackRegType[opStackDepth-1] = 0;
1545
opStackLoadInstructionAddr[opStackDepth-1] = 0;
1045
InstImm( PPC_LFS, R_TOP, R_OPSTACK, 0 ); // get value from opstack
1046
InstImm( PPC_LFSU, R_SECOND, R_OPSTACK, -4 ); // get value from opstack
1047
Inst( PPC_FSUBS, R_TOP, R_SECOND, R_TOP );
1048
InstImm( PPC_STFS, R_TOP, R_OPSTACK, 0 ); // save value to opstack
1551
printf("%08x SUBF\n",instruction);
1553
makeFloat(opStackDepth-1);
1554
makeFloat(opStackDepth-2);
1555
Inst( "fsubs", PPC_FSUBS, opStackFloatRegisters[opStackDepth-2], opStackFloatRegisters[opStackDepth-2], opStackFloatRegisters[opStackDepth-1] );
1556
opStackRegType[opStackDepth-1] = 0;
1557
opStackLoadInstructionAddr[opStackDepth-1] = 0;
1052
InstImm( PPC_LFS, R_TOP, R_OPSTACK, 0 ); // get value from opstack
1053
InstImm( PPC_LFSU, R_SECOND, R_OPSTACK, -4 ); // get value from opstack
1054
Inst( PPC_FDIVS, R_TOP, R_SECOND, R_TOP );
1055
InstImm( PPC_STFS, R_TOP, R_OPSTACK, 0 ); // save value to opstack
1563
printf("%08x DIVF\n",instruction);
1565
makeFloat(opStackDepth-1);
1566
makeFloat(opStackDepth-2);
1567
Inst( "fdivs", PPC_FDIVS, opStackFloatRegisters[opStackDepth-2], opStackFloatRegisters[opStackDepth-2], opStackFloatRegisters[opStackDepth-1] );
1568
opStackRegType[opStackDepth-1] = 0;
1569
opStackLoadInstructionAddr[opStackDepth-1] = 0;
1059
InstImm( PPC_LFS, R_TOP, R_OPSTACK, 0 ); // get value from opstack
1060
InstImm( PPC_LFSU, R_SECOND, R_OPSTACK, -4 ); // get value from opstack
1061
Inst4( PPC_FMULS, R_TOP, R_SECOND, 0, R_TOP );
1062
InstImm( PPC_STFS, R_TOP, R_OPSTACK, 0 ); // save value to opstack
1575
printf("%08x MULF\n",instruction);
1577
makeFloat(opStackDepth-1);
1578
makeFloat(opStackDepth-2);
1579
Inst4( "fmuls", PPC_FMULS, opStackFloatRegisters[opStackDepth-2], opStackFloatRegisters[opStackDepth-2], 0, opStackFloatRegisters[opStackDepth-1] );
1580
opStackRegType[opStackDepth-1] = 0;
1581
opStackLoadInstructionAddr[opStackDepth-1] = 0;
1588
printf("%08x CVIF\n",instruction);
1590
assertInteger(opStackDepth-1);
1591
//makeInteger(opStackDepth-1);
1067
1592
v = (int)&itofConvert;
1068
InstImmU( PPC_ADDIS, R_EA, 0, (v >> 16)&0xffff );
1069
InstImmU( PPC_ORI, R_EA, R_EA, v & 0xffff );
1070
InstImm( PPC_LWZ, R_TOP, R_OPSTACK, 0 ); // get value from opstack
1071
InstImmU( PPC_XORIS, R_TOP, R_TOP, 0x8000 );
1072
InstImm( PPC_STW, R_TOP, R_EA, 12 );
1073
InstImm( PPC_LFD, R_TOP, R_EA, 0 );
1074
InstImm( PPC_LFD, R_SECOND, R_EA, 8 );
1075
Inst( PPC_FSUB, R_TOP, R_SECOND, R_TOP );
1593
InstImmU( "addis", PPC_ADDIS, R_EA, 0, (v >> 16)&0xffff );
1594
InstImmU( "ori", PPC_ORI, R_EA, R_EA, v & 0xffff );
1595
InstImmU( "xoris", PPC_XORIS, opStackIntRegisters[opStackDepth-1], opStackIntRegisters[opStackDepth-1], 0x8000 );
1596
InstImm( "stw", PPC_STW, opStackIntRegisters[opStackDepth-1], R_EA, 12 );
1597
InstImm( "lfd", PPC_LFD, opStackFloatRegisters[opStackDepth-1], R_EA, 0 );
1598
Inst( "ori", PPC_ORI, 0, 0, 0);
1599
Inst( "ori", PPC_ORI, 0, 0, 0);
1600
Inst( "ori", PPC_ORI, 0, 0, 0);
1601
InstImm( "lfd", PPC_LFD, 13, R_EA, 8 );
1602
Inst( "fsub", PPC_FSUB, opStackFloatRegisters[opStackDepth-1], 13, opStackFloatRegisters[opStackDepth-1] );
1603
opStackRegType[opStackDepth-1] = 2;
1604
opStackLoadInstructionAddr[opStackDepth-1] = 0;
1076
1605
// Inst( PPC_FRSP, R_TOP, 0, R_TOP );
1077
InstImm( PPC_STFS, R_TOP, R_OPSTACK, 0 ); // save value to opstack
1081
InstImm( PPC_LFS, R_TOP, R_OPSTACK, 0 ); // get value from opstack
1082
Inst( PPC_FCTIWZ, R_TOP, 0, R_TOP );
1083
Inst( PPC_STFIWX, R_TOP, 0, R_OPSTACK ); // save value to opstack
1610
printf("%08x CVFI\n",instruction);
1612
makeFloat(opStackDepth-1);
1614
InstImm( "addi", PPC_ADDI, R_OPSTACK, R_OPSTACK, opStackDepth*4);
1616
Inst( "fctiwz", PPC_FCTIWZ, opStackFloatRegisters[opStackDepth-1], 0, opStackFloatRegisters[opStackDepth-1] );
1617
Inst( "stfiwx", PPC_STFIWX, opStackFloatRegisters[opStackDepth-1], 0, R_OPSTACK ); // save value to opstack (dummy area now)
1618
Inst( "ori", PPC_ORI, 0, 0, 0);
1619
Inst( "ori", PPC_ORI, 0, 0, 0);
1620
Inst( "ori", PPC_ORI, 0, 0, 0);
1621
Inst( "ori", PPC_ORI, 0, 0, 0);
1622
InstImm( "lwz", PPC_LWZ, opStackIntRegisters[opStackDepth-1], R_OPSTACK, 0 );
1624
InstImm( "addi", PPC_ADDI, R_OPSTACK, R_OPSTACK, -opStackDepth*4);
1626
opStackRegType[opStackDepth-1] = 1;
1627
opStackLoadInstructionAddr[opStackDepth-1] = 0;
1087
ltop(); // get value from opstack
1088
Inst( PPC_EXTSB, R_TOP, R_TOP, 0 );
1089
InstImm( PPC_STW, R_TOP, R_OPSTACK, 0 );
1632
printf("%08x SEX8\n",instruction);
1634
assertInteger(opStackDepth-1);
1635
Inst( "extsb", PPC_EXTSB, opStackIntRegisters[opStackDepth-1], opStackIntRegisters[opStackDepth-1], 0 );
1636
opStackLoadInstructionAddr[opStackDepth-1] = 0;
1093
ltop(); // get value from opstack
1094
Inst( PPC_EXTSH, R_TOP, R_TOP, 0 );
1095
InstImm( PPC_STW, R_TOP, R_OPSTACK, 0 );
1641
printf("%08x SEX16\n",instruction);
1643
assertInteger(opStackDepth-1);
1644
Inst( "extsh", PPC_EXTSH, opStackIntRegisters[opStackDepth-1], opStackIntRegisters[opStackDepth-1], 0 );
1645
opStackLoadInstructionAddr[opStackDepth-1] = 0;
1099
1648
case OP_BLOCK_COPY:
1100
1649
v = Constant4() >> 2;
1102
InstImm( PPC_LWZ, R_SECOND, R_OPSTACK, -4 ); // dest
1103
InstImm( PPC_ADDI, R_OPSTACK, R_OPSTACK, -8 );
1104
InstImmU( PPC_ADDI, R_EA, 0, v ); // count
1652
printf("%08x BLOCK_COPY\t%08lx\n",instruction,v<<2);
1654
assert(opStackDepth >= 2);
1655
assertInteger(opStackDepth-1);
1656
assertInteger(opStackDepth-2);
1657
InstImmU( "addi", PPC_ADDI, R_EA, 0, v ); // count
1105
1658
// FIXME: range check
1106
Inst( PPC_MTSPR, R_EA, 9, 0 ); // move to count register
1108
Inst( PPC_ADD, R_TOP, R_TOP, R_MEMBASE );
1109
InstImm( PPC_ADDI, R_TOP, R_TOP, -4 );
1110
Inst( PPC_ADD, R_SECOND, R_SECOND, R_MEMBASE );
1111
InstImm( PPC_ADDI, R_SECOND, R_SECOND, -4 );
1113
InstImm( PPC_LWZU, R_EA, R_TOP, 4 ); // source
1114
InstImm( PPC_STWU, R_EA, R_SECOND, 4 ); // dest
1115
Inst( PPC_BC | 0xfff8 , 16, 0, 0 ); // loop
1659
Inst( "mtctr", PPC_MTSPR, R_EA, 9, 0 ); // move to count register
1661
Inst( "add", PPC_ADD, opStackIntRegisters[opStackDepth-1], opStackIntRegisters[opStackDepth-1], R_MEMBASE );
1662
InstImm( "addi", PPC_ADDI, opStackIntRegisters[opStackDepth-1], opStackIntRegisters[opStackDepth-1], -4 );
1663
Inst( "add", PPC_ADD, opStackIntRegisters[opStackDepth-2], opStackIntRegisters[opStackDepth-2], R_MEMBASE );
1664
InstImm( "addi", PPC_ADDI, opStackIntRegisters[opStackDepth-2], opStackIntRegisters[opStackDepth-2], -4 );
1666
InstImm( "lwzu", PPC_LWZU, R_EA, opStackIntRegisters[opStackDepth-1], 4 ); // source
1667
InstImm( "stwu", PPC_STWU, R_EA, opStackIntRegisters[opStackDepth-2], 4 ); // dest
1668
Inst( "b", PPC_BC | 0xfff8 , 16, 0, 0 ); // loop
1669
opStackRegType[opStackDepth-1] = 0;
1670
opStackRegType[opStackDepth-2] = 0;
1671
opStackLoadInstructionAddr[opStackDepth-1] = 0;
1672
opStackLoadInstructionAddr[opStackDepth-2] = 0;
1120
ltop(); // get value from opstack
1121
InstImm( PPC_ADDI, R_OPSTACK, R_OPSTACK, -4 );
1122
Inst( PPC_RLWINM | ( 29 << 1 ), R_TOP, R_TOP, 2 );
1679
printf("%08x JUMP\n",instruction);
1681
assert(opStackDepth == 1);
1682
assertInteger(opStackDepth-1);
1684
Inst( "rlwinm", PPC_RLWINM | ( 29 << 1 ), opStackIntRegisters[opStackDepth-1], opStackIntRegisters[opStackDepth-1], 2 );
1123
1685
// FIXME: range check
1124
Inst( PPC_LWZX, R_TOP, R_TOP, R_INSTRUCTIONS );
1125
Inst( PPC_MTSPR, R_TOP, 9, 0 ); // move to count register
1126
Inst( PPC_BCCTR, 20, 0, 0 ); // jump to the count register
1686
Inst( "lwzx", PPC_LWZX, opStackIntRegisters[opStackDepth-1], opStackIntRegisters[opStackDepth-1], R_INSTRUCTIONS );
1687
Inst( "mtctr", PPC_MTSPR, opStackIntRegisters[opStackDepth-1], 9, 0 ); // move to count register
1688
Inst( "bctr", PPC_BCCTR, 20, 0, 0 ); // jump to the count register
1689
opStackRegType[opStackDepth-1] = 0;
1690
opStackLoadInstructionAddr[opStackDepth-1] = 0;
1130
1694
Com_Error( ERR_DROP, "VM_CompilePPC: bad opcode %i at instruction %i, offset %i", op, instruction, pc );
1698
assert(opStackDepth >= 0);
1699
assert(opStackDepth < OP_STACK_MAX_DEPTH);
1701
//printf("%4d\t%s\n",opStackDepth,opnames[op]);
1136
1704
Com_Printf( "VM file %s pass %d compiled to %i bytes of code\n", vm->name, (pass+1), compiledOfs*4 );