-
Notifications
You must be signed in to change notification settings - Fork 0
/
gencomp.c
executable file
·3115 lines (2923 loc) · 84.2 KB
/
gencomp.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
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
64
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
95
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
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
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
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
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
540
541
542
543
544
545
546
547
548
549
550
551
552
553
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
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
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
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
/*
* UAE - The Un*x Amiga Emulator
*
* MC68000 compilation generator
*
* Based on work Copyright 1995, 1996 Bernd Schmidt. Changes Copyright 2000
* Bernd Meyer
*/
#include "sysconfig.h"
#include "sysdeps.h"
#include <ctype.h>
#include "readcpu.h"
#include <stdio.h>
#include <stdarg.h>
#define BOOL_TYPE "int"
#define failure global_failure=1
#define FAILURE global_failure=1
#define isjump global_isjump=1
#define is_const_jump global_iscjump=1;
#define isaddx global_isaddx=1
#define uses_cmov global_cmov=1
#define mayfail global_mayfail=1
int hack_opcode;
static int global_failure;
static int global_isjump;
static int global_iscjump;
static int global_isaddx;
static int global_cmov;
static int long_opcode;
static int global_mayfail;
static char endstr[1000];
static char lines[100000];
static int comp_index=0;
static int cond_codes_x86[]={-1,-1,7,6,3,2,5,4,-1,-1,9,8,13,12,15,14};
static void comprintf(const char* format, ...)
{
va_list args;
va_start(args,format);
comp_index+=vsprintf(lines+comp_index,format,args);
}
static void com_discard(void)
{
comp_index=0;
}
static void com_flush(void)
{
int i;
for (i=0;i<comp_index;i++)
putchar(lines[i]);
com_discard();
}
static FILE *headerfile;
static FILE *stblfile;
static int using_prefetch;
static int using_exception_3;
static int cpu_level;
static int noflags;
/* For the current opcode, the next lower level that will have different code.
* Initialized to -1 for each opcode. If it remains unchanged, indicates we
* are done with that opcode. */
static int next_cpu_level;
static int *opcode_map;
static int *opcode_next_clev;
static int *opcode_last_postfix;
static unsigned long *counts;
static void
read_counts (void)
{
FILE *file;
unsigned long opcode, count = 0, total;
char name[20];
int nr = 0;
memset (counts, 0, 65536 * sizeof *counts);
file = fopen ("frequent.68k", "r");
if (file)
{
fscanf (file, "Total: %lu\n", &total);
while (fscanf (file, "%lx: %lu %s\n", &opcode, &count, name) == 3)
{
opcode_next_clev[nr] = 4;
opcode_last_postfix[nr] = -1;
opcode_map[nr++] = opcode;
counts[opcode] = count;
}
fclose (file);
}
if (nr == nr_cpuop_funcs)
return;
for (opcode = 0; opcode < 0x10000; opcode++)
{
if (table68k[opcode].handler == -1 && table68k[opcode].mnemo != i_ILLG
&& counts[opcode] == 0)
{
opcode_next_clev[nr] = 4;
opcode_last_postfix[nr] = -1;
opcode_map[nr++] = opcode;
counts[opcode] = count;
}
}
if (nr != nr_cpuop_funcs)
abort ();
}
static int n_braces = 0;
static int insn_n_cycles;
static void
start_brace (void)
{
n_braces++;
comprintf ("{");
}
static void
close_brace (void)
{
assert (n_braces > 0);
n_braces--;
comprintf ("}");
}
static void
finish_braces (void)
{
while (n_braces > 0)
close_brace ();
}
static void
pop_braces (int to)
{
while (n_braces > to)
close_brace ();
}
static int
bit_size (int size)
{
switch (size)
{
case sz_byte:
return 8;
case sz_word:
return 16;
case sz_long:
return 32;
default:
abort ();
}
return 0;
}
static const char *
bit_mask (int size)
{
switch (size)
{
case sz_byte:
return "0xff";
case sz_word:
return "0xffff";
case sz_long:
return "0xffffffff";
default:
abort ();
}
return 0;
}
static __inline__ void gen_update_next_handler(void)
{
return; /* Can anything clever be done here? */
}
static void gen_writebyte (const char *address, const char *source)
{
comprintf("\twritebyte(%s,%s,scratchie);\n",address,source);
}
static void gen_writeword (const char *address, const char *source)
{
comprintf("\twriteword(%s,%s,scratchie);\n",address,source);
}
static void gen_writelong (const char *address, const char *source)
{
comprintf("\twritelong(%s,%s,scratchie);\n",address,source);
}
static void gen_readbyte (const char *address, const char *dest)
{
comprintf("\treadbyte(%s,%s,scratchie);\n",address,dest);
}
static void gen_readword (const char *address, const char *dest)
{
comprintf("\treadword(%s,%s,scratchie);\n",address,dest);
}
static void gen_readlong (const char *address, const char *dest)
{
comprintf("\treadlong(%s,%s,scratchie);\n",address,dest);
}
static const char *
gen_nextilong (void)
{
static char buffer[80];
sprintf (buffer, "comp_get_ilong((m68k_pc_offset+=4)-4)");
insn_n_cycles += 4;
long_opcode=1;
return buffer;
}
static const char *
gen_nextiword (void)
{
static char buffer[80];
sprintf (buffer, "comp_get_iword((m68k_pc_offset+=2)-2)");
insn_n_cycles+=2;
long_opcode=1;
return buffer;
}
static const char *
gen_nextibyte (void)
{
static char buffer[80];
sprintf (buffer, "comp_get_ibyte((m68k_pc_offset+=2)-2)");
insn_n_cycles += 2;
long_opcode=1;
return buffer;
}
static void
sync_m68k_pc (void)
{
comprintf("\t if (m68k_pc_offset>100) sync_m68k_pc();\n");
}
/* getv == 1: fetch data; getv != 0: check for odd address. If movem != 0,
* the calling routine handles Apdi and Aipi modes. */
static void
genamode (amodes mode, const char *reg, wordsizes size, const char *name, int getv, int movem)
{
start_brace ();
switch (mode)
{
case Dreg: /* Do we need to check dodgy here? */
if (movem)
abort ();
if (getv == 1 || getv==2) {
/* We generate the variable even for getv==2, so we can use
it as a destination for MOVE */
comprintf ("\tint %s=%s;\n",name,reg);
}
return;
case Areg:
if (movem)
abort ();
if (getv == 1 || getv==2) {
/* see above */
comprintf ("\tint %s=dodgy?scratchie++:%s+8;\n",name,reg);
if (getv==1) {
comprintf ("\tif (dodgy) \n");
comprintf ("\t\tmov_l_rr(%s,%s+8);\n",name, reg);
}
}
return;
case Aind:
comprintf ("\tint %sa=dodgy?scratchie++:%s+8;\n",name,reg);
comprintf ("\tif (dodgy) \n");
comprintf ("\t\tmov_l_rr(%sa,%s+8);\n",name, reg);
break;
case Aipi:
comprintf ("\tint %sa=scratchie++;\n",name,reg);
comprintf ("\tmov_l_rr(%sa,%s+8);\n",name, reg);
break;
case Apdi:
switch (size)
{
case sz_byte:
if (movem) {
comprintf ("\tint %sa=dodgy?scratchie++:%s+8;\n",name,reg);
comprintf ("\tif (dodgy) \n");
comprintf("\tmov_l_rr(%sa,8+%s);\n",name,reg);
}
else {
start_brace();
comprintf ("\tint %sa=dodgy?scratchie++:%s+8;\n",name,reg);
comprintf("\tlea_l_brr(%s+8,%s+8,(uae_s32)-areg_byteinc[%s]);\n",reg,reg,reg);
comprintf ("\tif (dodgy) \n");
comprintf("\tmov_l_rr(%sa,8+%s);\n",name,reg);
}
break;
case sz_word:
if (movem) {
comprintf ("\tint %sa=dodgy?scratchie++:%s+8;\n",name,reg);
comprintf ("\tif (dodgy) \n");
comprintf("\tmov_l_rr(%sa,8+%s);\n",name,reg);
}
else {
start_brace();
comprintf ("\tint %sa=dodgy?scratchie++:%s+8;\n",name,reg);
comprintf("\tlea_l_brr(%s+8,%s+8,-2);\n",reg,reg);
comprintf ("\tif (dodgy) \n");
comprintf("\tmov_l_rr(%sa,8+%s);\n",name,reg);
}
break;
case sz_long:
if (movem) {
comprintf ("\tint %sa=dodgy?scratchie++:%s+8;\n",name,reg);
comprintf ("\tif (dodgy) \n");
comprintf("\tmov_l_rr(%sa,8+%s);\n",name,reg);
}
else {
start_brace();
comprintf ("\tint %sa=dodgy?scratchie++:%s+8;\n",name,reg);
comprintf("\tlea_l_brr(%s+8,%s+8,-4);\n",reg,reg);
comprintf ("\tif (dodgy) \n");
comprintf("\tmov_l_rr(%sa,8+%s);\n",name,reg);
}
break;
default:
abort ();
}
break;
case Ad16:
comprintf("\tint %sa=scratchie++;\n",name);
comprintf("\tmov_l_rr(%sa,8+%s);\n",name,reg);
comprintf("\tlea_l_brr(%sa,%sa,(uae_s32)(uae_s16)%s);\n",name,name,gen_nextiword());
break;
case Ad8r:
comprintf("\tint %sa=scratchie++;\n",name);
comprintf("\tcalc_disp_ea_020(%s+8,%s,%sa,scratchie);\n",
reg,gen_nextiword(),name);
break;
case PC16:
comprintf("\tint %sa=scratchie++;\n",name);
comprintf("\tuae_u32 address=start_pc+((char *)comp_pc_p-(char *)start_pc_p)+m68k_pc_offset;\n");
comprintf ("\tuae_s32 PC16off = (uae_s32)(uae_s16)%s;\n", gen_nextiword ());
comprintf("\tmov_l_ri(%sa,address+PC16off);\n",name);
break;
case PC8r:
comprintf("\tint pctmp=scratchie++;\n");
comprintf("\tint %sa=scratchie++;\n",name);
comprintf("\tuae_u32 address=start_pc+((char *)comp_pc_p-(char *)start_pc_p)+m68k_pc_offset;\n");
start_brace();
comprintf("\tmov_l_ri(pctmp,address);\n");
comprintf("\tcalc_disp_ea_020(pctmp,%s,%sa,scratchie);\n",
gen_nextiword(),name);
break;
case absw:
comprintf ("\tint %sa = scratchie++;\n",name);
comprintf ("\tmov_l_ri(%sa,(uae_s32)(uae_s16)%s);\n", name, gen_nextiword ());
break;
case absl:
comprintf ("\tint %sa = scratchie++;\n",name);
comprintf ("\tmov_l_ri(%sa,%s); /* absl */\n", name, gen_nextilong ());
break;
case imm:
if (getv != 1)
abort ();
switch (size)
{
case sz_byte:
comprintf ("\tint %s = scratchie++;\n",name);
comprintf ("\tmov_l_ri(%s,(uae_s32)(uae_s8)%s);\n", name, gen_nextibyte ());
break;
case sz_word:
comprintf ("\tint %s = scratchie++;\n",name);
comprintf ("\tmov_l_ri(%s,(uae_s32)(uae_s16)%s);\n", name, gen_nextiword ());
break;
case sz_long:
comprintf ("\tint %s = scratchie++;\n",name);
comprintf ("\tmov_l_ri(%s,%s);\n", name, gen_nextilong ());
break;
default:
abort ();
}
return;
case imm0:
if (getv != 1)
abort ();
comprintf ("\tint %s = scratchie++;\n",name);
comprintf ("\tmov_l_ri(%s,(uae_s32)(uae_s8)%s);\n", name, gen_nextibyte ());
return;
case imm1:
if (getv != 1)
abort ();
comprintf ("\tint %s = scratchie++;\n",name);
comprintf ("\tmov_l_ri(%s,(uae_s32)(uae_s16)%s);\n", name, gen_nextiword ());
return;
case imm2:
if (getv != 1)
abort ();
comprintf ("\tint %s = scratchie++;\n",name);
comprintf ("\tmov_l_ri(%s,%s);\n", name, gen_nextilong ());
return;
case immi:
if (getv != 1)
abort ();
comprintf ("\tint %s = scratchie++;\n",name);
comprintf ("\tmov_l_ri(%s,%s);\n", name, reg);
return;
default:
abort ();
}
/* We get here for all non-reg non-immediate addressing modes to
* actually fetch the value. */
if (getv == 1)
{
char astring[80];
sprintf(astring,"%sa",name);
switch (size)
{
case sz_byte:
insn_n_cycles += 2;
break;
case sz_word:
insn_n_cycles += 2;
break;
case sz_long:
insn_n_cycles += 4;
break;
default:
abort ();
}
start_brace ();
comprintf("\tint %s=scratchie++;\n",name);
switch (size)
{
case sz_byte:
gen_readbyte(astring,name);
break;
case sz_word:
gen_readword(astring,name);
break;
case sz_long:
gen_readlong(astring,name);
break;
default:
abort ();
}
}
/* We now might have to fix up the register for pre-dec or post-inc
* addressing modes. */
if (!movem) {
switch (mode)
{
case Aipi:
switch (size)
{
case sz_byte:
comprintf("\tlea_l_brr(%s+8,%s+8,areg_byteinc[%s]);\n",reg,reg,reg);
break;
case sz_word:
comprintf("\tlea_l_brr(%s+8,%s+8,2);\n",reg,reg,reg);
break;
case sz_long:
comprintf("\tlea_l_brr(%s+8,%s+8,4);\n",reg,reg);
break;
default:
abort ();
}
break;
case Apdi:
break;
default:
break;
}
}
}
static void
genastore (const char *from, amodes mode, const char *reg, wordsizes size, const char *to)
{
switch (mode)
{
case Dreg:
switch (size)
{
case sz_byte:
comprintf("\tif((uae_u32)%s!=(uae_u32)%s)\n",reg,from);
comprintf ("\t\tmov_b_rr(%s,%s);\n", reg, from);
break;
case sz_word:
comprintf("\tif((uae_u32)%s!=(uae_u32)%s)\n",reg,from);
comprintf ("\t\tmov_w_rr(%s,%s);\n", reg, from);
break;
case sz_long:
comprintf("\tif((uae_u32)%s!=(uae_u32)%s)\n",reg,from);
comprintf ("\t\tmov_l_rr(%s,%s);\n", reg, from);
break;
default:
abort ();
}
break;
case Areg:
switch (size)
{
case sz_word:
comprintf("\tif((uae_u32)%s+8!=(uae_u32)%s)\n",reg,from);
comprintf ("\t\tmov_w_rr(%s+8,%s);\n", reg, from);
break;
case sz_long:
comprintf("\tif((uae_u32)%s+8!=(uae_u32)%s)\n",reg,from);
comprintf ("\t\tmov_l_rr(%s+8,%s);\n", reg, from);
break;
default:
abort ();
}
break;
case Apdi:
case absw:
case PC16:
case PC8r:
case Ad16:
case Ad8r:
case Aipi:
case Aind:
case absl:
{
char astring[80];
sprintf(astring,"%sa",to);
switch (size)
{
case sz_byte:
insn_n_cycles += 2;
gen_writebyte(astring,from);
break;
case sz_word:
insn_n_cycles += 2;
gen_writeword(astring,from);
break;
case sz_long:
insn_n_cycles += 4;
gen_writelong(astring,from);
break;
default:
abort ();
}
}
break;
case imm:
case imm0:
case imm1:
case imm2:
case immi:
abort ();
break;
default:
abort ();
}
}
static void genmov16(uae_u32 opcode, struct instr *curi)
{
comprintf("\tint src=scratchie++;\n");
comprintf("\tint dst=scratchie++;\n");
if ((opcode & 0xfff8) == 0xf620) {
/* MOVE16 (Ax)+,(Ay)+ */
comprintf("\tuae_u16 dstreg=((%s)>>12)&0x07;\n", gen_nextiword());
comprintf("\tmov_l_rr(src,8+srcreg);\n");
comprintf("\tmov_l_rr(dst,8+dstreg);\n");
} else {
/* Other variants */
genamode (curi->smode, "srcreg", curi->size, "src", 0, 2);
genamode (curi->dmode, "dstreg", curi->size, "dst", 0, 2);
comprintf("\tmov_l_rr(src,srca);\n");
comprintf("\tmov_l_rr(dst,dsta);\n");
}
/* Align on 16-byte boundaries */
comprintf("\tand_l_ri(src,~15);\n");
comprintf("\tand_l_ri(dst,~15);\n");
if ((opcode & 0xfff8) == 0xf620) {
comprintf("\tif (srcreg != dstreg)\n");
comprintf("\tadd_l_ri(srcreg+8,16);\n");
comprintf("\tadd_l_ri(dstreg+8,16);\n");
} else if ((opcode & 0xfff8) == 0xf600)
comprintf("\tadd_l_ri(srcreg+8,16);\n");
else if ((opcode & 0xfff8) == 0xf608)
comprintf("\tadd_l_ri(dstreg+8,16);\n");
comprintf("\tif (special_mem) {\n");
comprintf("\t\tint tmp=scratchie;\n");
comprintf("\tscratchie+=4;\n"
"\treadlong(src,tmp,scratchie);\n"
"\twritelong_clobber(dst,tmp,scratchie);\n"
"\tadd_l_ri(src,4);\n"
"\tadd_l_ri(dst,4);\n"
"\treadlong(src,tmp,scratchie);\n"
"\twritelong_clobber(dst,tmp,scratchie);\n"
"\tadd_l_ri(src,4);\n"
"\tadd_l_ri(dst,4);\n"
"\treadlong(src,tmp,scratchie);\n"
"\twritelong_clobber(dst,tmp,scratchie);\n"
"\tadd_l_ri(src,4);\n"
"\tadd_l_ri(dst,4);\n"
"\treadlong(src,tmp,scratchie);\n"
"\twritelong_clobber(dst,tmp,scratchie);\n");
comprintf("\t} else {\n");
comprintf("\t\tint tmp=scratchie;\n");
comprintf("\tscratchie+=4;\n");
comprintf("\tget_n_addr(src,src,scratchie);\n"
"\tget_n_addr(dst,dst,scratchie);\n"
"\tmov_l_rR(tmp+0,src,0);\n"
"\tmov_l_rR(tmp+1,src,4);\n"
"\tmov_l_rR(tmp+2,src,8);\n"
"\tmov_l_rR(tmp+3,src,12);\n"
"\tmov_l_Rr(dst,tmp+0,0);\n"
"\tforget_about(tmp+0);\n"
"\tmov_l_Rr(dst,tmp+1,4);\n"
"\tforget_about(tmp+1);\n"
"\tmov_l_Rr(dst,tmp+2,8);\n"
"\tforget_about(tmp+2);\n"
"\tmov_l_Rr(dst,tmp+3,12);\t}\n");
}
#if 0
static void genmov16(void)
{
comprintf("\tint src=scratchie++;\n"
"\tuae_u16 dstreg=((%s)>>12)&0x07;\n",gen_nextiword());
comprintf("\tint dst=scratchie++;\n"
"\tint tmp=scratchie;\n"
"\tscratchie+=4;\n"
"\tmov_l_rr(src,8+srcreg);\n"
"\tand_l_ri(src,~15);\n"
"\tmov_l_rr(dst,8+dstreg);\n"
"\tand_l_ri(dst,~15);\n"
"\tadd_l_ri(srcreg+8,16);\n"
"\tadd_l_ri(dstreg+8,16);\n");
comprintf("\tif (special_mem) {\n"
"\treadlong(src,tmp,scratchie);\n"
"\twritelong_clobber(dst,tmp,scratchie);\n"
"\tadd_l_ri(src,4);\n"
"\tadd_l_ri(dst,4);\n"
"\treadlong(src,tmp,scratchie);\n"
"\twritelong_clobber(dst,tmp,scratchie);\n"
"\tadd_l_ri(src,4);\n"
"\tadd_l_ri(dst,4);\n"
"\treadlong(src,tmp,scratchie);\n"
"\twritelong_clobber(dst,tmp,scratchie);\n"
"\tadd_l_ri(src,4);\n"
"\tadd_l_ri(dst,4);\n"
"\treadlong(src,tmp,scratchie);\n"
"\twritelong_clobber(dst,tmp,scratchie);\n");
comprintf("\t} else {\n");
comprintf("\tget_n_addr(src,src,scratchie);\n"
"\tget_n_addr(dst,dst,scratchie);\n"
"\tmov_l_rR(tmp+0,src,0);\n"
"\tmov_l_rR(tmp+1,src,4);\n"
"\tmov_l_rR(tmp+2,src,8);\n"
"\tmov_l_rR(tmp+3,src,12);\n"
"\tmov_l_Rr(dst,tmp+0,0);\n"
"\tforget_about(tmp+0);\n"
"\tmov_l_Rr(dst,tmp+1,4);\n"
"\tforget_about(tmp+1);\n"
"\tmov_l_Rr(dst,tmp+2,8);\n"
"\tforget_about(tmp+2);\n"
"\tmov_l_Rr(dst,tmp+3,12);\n"
"\t}\n");
}
#endif
static void
genmovemel (uae_u16 opcode)
{
comprintf ("\tuae_u16 mask = %s;\n", gen_nextiword ());
comprintf ("\tint native=scratchie++;\n");
comprintf ("\tint i;\n");
comprintf ("\tint offset=0;\n");
genamode (table68k[opcode].dmode, "dstreg", table68k[opcode].size, "src", 2, 1);
comprintf("\tif (1 && !special_mem) {\n");
/* Fast but unsafe... */
comprintf("\tget_n_addr(srca,native,scratchie);\n");
comprintf("\tfor (i=0;i<16;i++) {\n"
"\t\tif ((mask>>i)&1) {\n");
switch(table68k[opcode].size) {
case sz_long:
comprintf("\t\t\tmov_l_rR(i,native,offset);\n"
"\t\t\tgen_bswap_32(i);\n"
"\t\t\toffset+=4;\n");
break;
case sz_word:
comprintf("\t\t\tmov_w_rR(i,native,offset);\n"
"\t\t\tgen_bswap_16(i);\n"
"\t\t\tsign_extend_16_rr(i,i);\n"
"\t\t\toffset+=2;\n");
break;
default: abort();
}
comprintf("\t\t}\n"
"\t}");
if (table68k[opcode].dmode == Aipi) {
comprintf("\t\t\tlea_l_brr(8+dstreg,srca,offset);\n");
}
/* End fast but unsafe. */
comprintf("\t} else {\n");
comprintf ("\tint tmp=scratchie++;\n");
comprintf("\tmov_l_rr(tmp,srca);\n");
comprintf("\tfor (i=0;i<16;i++) {\n"
"\t\tif ((mask>>i)&1) {\n");
switch(table68k[opcode].size) {
case sz_long:
comprintf("\t\t\treadlong(tmp,i,scratchie);\n"
"\t\t\tadd_l_ri(tmp,4);\n");
break;
case sz_word:
comprintf("\t\t\treadword(tmp,i,scratchie);\n"
"\t\t\tadd_l_ri(tmp,2);\n");
break;
default: abort();
}
comprintf("\t\t}\n"
"\t}");
if (table68k[opcode].dmode == Aipi) {
comprintf("\t\t\tmov_l_rr(8+dstreg,tmp);\n");
}
comprintf("\t}\n");
}
static void
genmovemle (uae_u16 opcode)
{
comprintf ("\tuae_u16 mask = %s;\n", gen_nextiword ());
comprintf ("\tint native=scratchie++;\n");
comprintf ("\tint i;\n");
comprintf ("\tint tmp=scratchie++;\n");
comprintf ("\tsigned char offset=0;\n");
genamode (table68k[opcode].dmode, "dstreg", table68k[opcode].size, "src", 2, 1);
/* *Sigh* Some clever geek realized that the fastest way to copy a
buffer from main memory to the gfx card is by using movmle. Good
on her, but unfortunately, gfx mem isn't "real" mem, and thus that
act of cleverness means that movmle must pay attention to special_mem,
or Genetic Species is a rather boring-looking game ;-) */
comprintf("\tif (1 && !special_mem) {\n");
comprintf("\tget_n_addr(srca,native,scratchie);\n");
if (table68k[opcode].dmode!=Apdi) {
comprintf("\tfor (i=0;i<16;i++) {\n"
"\t\tif ((mask>>i)&1) {\n");
switch(table68k[opcode].size) {
case sz_long:
comprintf("\t\t\tmov_l_rr(tmp,i);\n"
"\t\t\tgen_bswap_32(tmp);\n"
"\t\t\tmov_l_Rr(native,tmp,offset);\n"
"\t\t\toffset+=4;\n");
break;
case sz_word:
comprintf("\t\t\tmov_l_rr(tmp,i);\n"
"\t\t\tgen_bswap_16(tmp);\n"
"\t\t\tmov_w_Rr(native,tmp,offset);\n"
"\t\t\toffset+=2;\n");
break;
default: abort();
}
} else { /* Pre-decrement */
comprintf("\tfor (i=0;i<16;i++) {\n"
"\t\tif ((mask>>i)&1) {\n");
switch(table68k[opcode].size) {
case sz_long:
comprintf("\t\t\toffset-=4;\n"
"\t\t\tmov_l_rr(tmp,15-i);\n"
"\t\t\tgen_bswap_32(tmp);\n"
"\t\t\tmov_l_Rr(native,tmp,offset);\n"
);
break;
case sz_word:
comprintf("\t\t\toffset-=2;\n"
"\t\t\tmov_l_rr(tmp,15-i);\n"
"\t\t\tgen_bswap_16(tmp);\n"
"\t\t\tmov_w_Rr(native,tmp,offset);\n"
);
break;
default: abort();
}
}
comprintf("\t\t}\n"
"\t}");
if (table68k[opcode].dmode == Apdi) {
comprintf("\t\t\tlea_l_brr(8+dstreg,srca,(uae_s32)offset);\n");
}
comprintf("\t} else {\n");
if (table68k[opcode].dmode!=Apdi) {
comprintf("\tmov_l_rr(tmp,srca);\n");
comprintf("\tfor (i=0;i<16;i++) {\n"
"\t\tif ((mask>>i)&1) {\n");
switch(table68k[opcode].size) {
case sz_long:
comprintf("\t\t\twritelong(tmp,i,scratchie);\n"
"\t\t\tadd_l_ri(tmp,4);\n");
break;
case sz_word:
comprintf("\t\t\twriteword(tmp,i,scratchie);\n"
"\t\t\tadd_l_ri(tmp,2);\n");
break;
default: abort();
}
}
else { /* Pre-decrement */
comprintf("\tfor (i=0;i<16;i++) {\n"
"\t\tif ((mask>>i)&1) {\n");
switch(table68k[opcode].size) {
case sz_long:
comprintf("\t\t\tsub_l_ri(srca,4);\n"
"\t\t\twritelong(srca,15-i,scratchie);\n");
break;
case sz_word:
comprintf("\t\t\tsub_l_ri(srca,2);\n"
"\t\t\twriteword(srca,15-i,scratchie);\n");
break;
default: abort();
}
}
comprintf("\t\t}\n"
"\t}");
if (table68k[opcode].dmode == Apdi) {
comprintf("\t\t\tmov_l_rr(8+dstreg,srca);\n");
}
comprintf("\t}\n");
}
static void
duplicate_carry (void)
{
comprintf ("\tif (needed_flags&FLAG_X) duplicate_carry();\n");
}
typedef enum
{
flag_logical_noclobber, flag_logical, flag_add, flag_sub, flag_cmp,
flag_addx, flag_subx, flag_zn, flag_av, flag_sv, flag_and, flag_or,
flag_eor, flag_mov
}
flagtypes;
static void
genflags (flagtypes type, wordsizes size, const char *value, const char *src, const char *dst)
{
if (noflags) {
switch(type) {
case flag_cmp:
comprintf("\tdont_care_flags();\n");
comprintf("/* Weird --- CMP with noflags ;-) */\n");
return;
case flag_add:
case flag_sub:
comprintf("\tdont_care_flags();\n");
{
const char *op;
switch(type) {
case flag_add: op="add"; break;
case flag_sub: op="sub"; break;
default: abort();
}
switch (size)
{
case sz_byte:
comprintf("\t%s_b(%s,%s);\n",op,dst,src);
break;
case sz_word:
comprintf("\t%s_w(%s,%s);\n",op,dst,src);
break;
case sz_long:
comprintf("\t%s_l(%s,%s);\n",op,dst,src);
break;
}
return;
}
break;
case flag_and:
comprintf("\tdont_care_flags();\n");
switch (size)
{
case sz_byte:
comprintf("if (kill_rodent(dst)) {\n");
comprintf("\tzero_extend_8_rr(scratchie,%s);\n",src);
comprintf("\tor_l_ri(scratchie,0xffffff00);\n");
comprintf("\tand_l(%s,scratchie);\n",dst);
comprintf("\tforget_about(scratchie);\n");
comprintf("\t} else \n"
"\tand_b(%s,%s);\n",dst,src);
break;
case sz_word:
comprintf("if (kill_rodent(dst)) {\n");
comprintf("\tzero_extend_16_rr(scratchie,%s);\n",src);
comprintf("\tor_l_ri(scratchie,0xffff0000);\n");
comprintf("\tand_l(%s,scratchie);\n",dst);
comprintf("\tforget_about(scratchie);\n");
comprintf("\t} else \n"
"\tand_w(%s,%s);\n",dst,src);
break;
case sz_long:
comprintf("\tand_l(%s,%s);\n",dst,src);
break;
}
return;
case flag_mov:
comprintf("\tdont_care_flags();\n");
switch (size)
{
case sz_byte:
comprintf("if (kill_rodent(dst)) {\n");
comprintf("\tzero_extend_8_rr(scratchie,%s);\n",src);
comprintf("\tand_l_ri(%s,0xffffff00);\n",dst);
comprintf("\tor_l(%s,scratchie);\n",dst);
comprintf("\tforget_about(scratchie);\n");
comprintf("\t} else \n"
"\tmov_b_rr(%s,%s);\n",dst,src);
break;
case sz_word:
comprintf("if (kill_rodent(dst)) {\n");
comprintf("\tzero_extend_16_rr(scratchie,%s);\n",src);
comprintf("\tand_l_ri(%s,0xffff0000);\n",dst);
comprintf("\tor_l(%s,scratchie);\n",dst);
comprintf("\tforget_about(scratchie);\n");
comprintf("\t} else \n"
"\tmov_w_rr(%s,%s);\n",dst,src);
break;
case sz_long:
comprintf("\tmov_l_rr(%s,%s);\n",dst,src);
break;
}
return;
case flag_or:
case flag_eor:
comprintf("\tdont_care_flags();\n");
start_brace();
{
const char *op;
switch(type) {
case flag_or: op="or"; break;
case flag_eor: op="xor"; break;
default: abort();
}
switch (size)
{