Training courses

Kernel and Embedded Linux

Bootlin training courses

Embedded Linux, kernel,
Yocto Project, Buildroot, real-time,
graphics, boot time, debugging...

Bootlin logo

Elixir Cross Referencer

   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
1001
1002
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
1038
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
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
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
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
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
1277
1278
1279
1280
1281
1282
1283
1284
1285
1286
1287
1288
1289
1290
1291
1292
1293
1294
1295
1296
1297
1298
1299
1300
1301
1302
1303
1304
1305
1306
1307
1308
1309
1310
1311
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
1392
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
1447
1448
1449
1450
1451
1452
1453
1454
1455
1456
1457
1458
1459
1460
1461
1462
1463
1464
1465
1466
1467
1468
1469
1470
1471
1472
1473
1474
1475
1476
1477
1478
1479
1480
1481
1482
1483
1484
1485
1486
1487
1488
1489
1490
1491
1492
1493
1494
1495
1496
1497
1498
1499
1500
1501
1502
1503
1504
1505
1506
1507
1508
1509
1510
1511
1512
1513
1514
1515
1516
1517
1518
1519
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
1549
1550
1551
1552
1553
1554
1555
1556
1557
1558
1559
1560
1561
1562
1563
1564
1565
/*	Id: table.c,v 1.5 2014/12/27 21:18:19 ragge Exp 	*/	
/*	$NetBSD: table.c,v 1.1.1.1 2016/02/09 20:28:39 plunky Exp $	*/
/*
 * Copyright (c) 2003 Anders Magnusson (ragge@ludd.luth.se).
 * Copyright (c) 2014 Alan Cox (alan@lxorguk.ukuu.org.uk).
 * All rights reserved.
 *
 * Redistribution and use in source and binary forms, with or without
 * modification, are permitted provided that the following conditions
 * are met:
 * 1. Redistributions of source code must retain the above copyright
 *    notice, this list of conditions and the following disclaimer.
 * 2. Redistributions in binary form must reproduce the above copyright
 *    notice, this list of conditions and the following disclaimer in the
 *    documentation and/or other materials provided with the distribution.
 * 3. The name of the author may not be used to endorse or promote products
 *    derived from this software without specific prior written permission
 *
 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 */


# include "pass2.h"

/*
 * TODO
 *  -	clean up TLL usage so we are ready for 64bit longlong (T32 and T64?)
 *  -	Clean up all the SHINT SHCH etc oddities for clarity
 *  -	Better optimisation of constant multiply/divide etc on 8086
 *  -	some how lose the final bogus sp adjust we generate
 *  -	write helper lib for long and longlong ops
 *  -	add an E class and virtual 4 register longlong model
 *  -   bcc fastcall format
 *
 *  -	How to do configurable code-gen
 *	For 80186 we want to use the better shifts, push constant, mul/div
 *	features and enter/leave
 *	For 80286 it's not clear we need to do anything for real mode. However
 *	for large data/huge models protected mode means minimising ds/es
 *	reloads with the same data
 *	With 80386 there is lots more - but who wants 80386/16bit optimised
 *	code !
 *
 *  -	FPU has not been tackled. FPU/FPU should be fine (barring the odd
 *	gnu style instruction forms), but FPU/other is quite different
 *	because the 4 byte conversions are now long not int and two register
 *	while 8 byte longlong ones are going to need some gymnastics once
 *	we support the virtual 64bit registers
 *
 *  -	FPU/noFPU option. Assuming FPU present on 8086 is a bit obnoxious
 *	as a default. Need to be able to generate entirely soft-float calls.
 *
 *  -   We can't currently do various conversions we'd like to have, notably
 *	things like  "and ax, $ff"  to convert AL into AX from uchar to uint
 *	(that needs core changes and also allocator changes to try and avoid
 *	high bits being occupied by other users)
 *
 *  -	Shifts should be optimised for 8/16/24/32 cases
 *
 *  -	No attempt is made to deal with larger models than tiny
 *
 *	small mode should work (just keep constant data in data segments)
 *
 *	large code/small data should be fine-ish. Really that implies 32bit
 *	void * but for most uses you want 32bit only to be function pointers
 *	even if its not to spec. Function entry/exit needs to allow for the
 *	extra 2 bytes, call becomes call far, call ptr becomes a bit trickier
 *	but not a lot. Not that ld86 can link large model yet!
 *
 *	large data is much harder because an address is 32bit, half of which
 *	needs to keep getting stuck into a segment register. However we often
 *	(usually) work with multiple pointers to the same object. Any given
 *	object has a single segment so we will badly need optimisations to
 *	"share" segment data and avoid lots of duplicate register uses and
 *	mov es, foo statements.
 *
 *	huge model makes all pointers 32bit and all objects 32bit sized. That
 *	probably makes the sharing es issue go away somewhat, but raises the
 *	ugly problems of pointer normalisation (00:10 is the same as 01:00
 *	which b*ggers up comparisons royally) and also protected mode where
 *	your segment jump as you go over 64K boundaries is different. On the
 *	bright side huge model performance will suck whatever the compiler
 *	does.
 *
 */

/* 64bit values */
# define T64 TLONGLONG|TULONGLONG
/* 32bit values */
# define T32 TLONG|TULONG
/* 16bit values */
# define T16 TINT|TUNSIGNED
/* 16bit values including pointers */
# define TP16 TINT|TUNSIGNED|TPOINT
/* 8bit values */
# define T8  TCHAR|TUCHAR

#define	 SHINT	SAREG	/* short and int */
#define	 ININT	INAREG
#define	 SHCH	SBREG	/* shape for char */
#define	 INCH	INBREG
#define	 SHLL	SCREG	/* shape for long long FIXME */
#define	 INLL	INCREG
#define	 SHL	SCREG	/* shape for long*/
#define	 INL	INCREG
#define	 SHFL	SDREG	/* shape for float/double */
#define	 INFL	INDREG	/* shape for float/double */

struct optab table[] = {
/* First entry must be an empty entry */
{ -1, FOREFF, SANY, TANY, SANY, TANY, 0, 0, "", },

/* PCONVs are usually not necessary */
{ PCONV,	INAREG,
	SAREG,	T16|TPOINT,
	SAREG,	T16|TPOINT,
		0,	RLEFT,
		"", },

/*
 * A bunch conversions of integral<->integral types
 * There are lots of them, first in table conversions to itself
 * and then conversions from each type to the others.
 */

/* itself to itself, including pointers */

/* convert (u)char to (u)char. */
{ SCONV,	INCH,
		SHCH,			T8,
		SHCH,			T8,
		0,			RLEFT,
		"", },

/* convert pointers to int. */
{ SCONV,	ININT,
		SHINT,			TPOINT|T16,
		SANY,			T16,
		0,			RLEFT,
		"", },

/* convert (u)long to (u)long. */
{ SCONV,	INL,
		SHL,			T32,
		SHL,			T32,
		0,			RLEFT,
		"", },

/* convert (u)long and (u)longlong to (u)longlong. */
{ SCONV,	INLL,
		SHLL,			T64,
		SHLL,			T64,
		0,			RLEFT,
		"", },

/* convert between float/double/long double. */
{ SCONV,	INFL,
	SHFL,	TLDOUBLE|TDOUBLE|TFLOAT,
	SHFL,	TLDOUBLE|TDOUBLE|TFLOAT,
		0,			RLEFT,
		"ZI", },

/* convert pointers to pointers. */
{ SCONV,	ININT,
		SHINT,			TPOINT,
		SANY,			TPOINT,
		0,			RLEFT,
		"", },

/* char to something */

/* convert char to 16bit types. */

/* 8086: Only as op on AL,AX */
{ SCONV,	ININT,
		SBREG,			TCHAR,
		SAREG,			T16,
		NSPECIAL|NAREG|NASL,	RESC1,
		"	cbw\n", },

/* convert unsigned char to 16bit types.
   We can do this one with any register */
{ SCONV,	ININT,
		SHCH|SOREG|SNAME,	TUCHAR,
		SAREG,			T16,
		NSPECIAL|NAREG,		RESC1,
		"ZT", },

/* convert char to (u)long
   8086 can only do cbw/cwd on AX and AX:DX pair */
{ SCONV,	INL,
		SHCH,			TCHAR,
		SCREG,			T32,
		NSPECIAL|NCREG|NCSL,	RESC1,
		"; using AL\n	cbw\n	cwd\n", },

/* convert unsigned char to (u)long
   we can do this with any register */
{ SCONV,	INL,
		SHCH|SOREG|SNAME,	TUCHAR,
		SANY,			T32,
		NCREG|NCSL,		RESC1,
		"ZT	xor U1,U1\n", },

/* convert char (in register) to double XXX - use NTEMP */
/* FIXME : need NSPECIAL to force into AL 
	check AX:DX right way around ! */
{ SCONV,	INFL,
		SHCH|SOREG|SNAME,	TCHAR,
		SHFL,			TLDOUBLE|TDOUBLE|TFLOAT,
		NAREG|NASL|NDREG,	RESC2,
		"	cbw\n	cwd\n	push ax\n	push dx\n"
		"	fildl [sp]\n	add sp, #4\n", },

/* convert (u)char (in register) to double XXX - use NTEMP */
/* FIXME : needs to use ZT to get sizes right, need a register
   from somewhere to put 0 on the stack for the high bits */
{ SCONV,	INFL,
		SHCH|SOREG|SNAME,	TUCHAR,
		SHFL,			TLDOUBLE|TDOUBLE|TFLOAT,
		NAREG|NASL|NDREG,	RESC2,
		"	mov A1 AL\n	and A1, #0xff\n	push A1\npush #0\n"
		"	fildl [sp]\n	add sp,#4\n", },

/* 16bit to something */

/* convert 16bit to 16bit. */
{ SCONV,	INAREG,
		SAREG,			T16,
		SAREG,			T16,
		0,			RLEFT,
		"", },

/* convert 16bit (in memory) to char */
/* NOTE: uses new 'ZP' type for 'untyped right' */
{ SCONV,	INCH,
		SNAME|SOREG,		TP16,
		SHCH,			T8,
		NBREG|NBSL,		RESC1,
		"	mov A1,ZP AL\n", },

/* convert 16bit (in reg) to char. Done as a special but basically a mov */
{ SCONV,	INCH,
		SAREG|SNAME|SOREG,	TP16,
		SHCH,			T8,
		NSPECIAL|NBREG|NBSL,	RESC1,
		"ZM", },

/* convert short/int to (u)long
   This must go via AX so we can use cwd */
{ SCONV,	INL,
		SAREG,			TINT,
		SHL,			T32,
		NSPECIAL|NCREG|NCSL,	RESC1,
		"	mov A1, AL\n	cwd\n", },

/* convert unsigned short/int to (u)long
   Any pair will do. Note currently the compiler can't optimise
   out the reg->reg move involved */
{ SCONV,	INLL,
		SAREG|SOREG|SNAME,	TUNSIGNED|TPOINT,
		SHL,			T32,
		NCREG|NCSL,		RESC1,
		"	mov A1,AL\n	xor U1,U1\n", },

/* convert short/int (in memory) to float/double */
{ SCONV,	INFL,
		SOREG|SNAME,		TINT,
		SDREG,			TLDOUBLE|TDOUBLE|TFLOAT,
		NDREG,			RESC1,
		"	fild AL\n", },

/* convert short/int (in register) to float/double */
{ SCONV,	INFL,
		SAREG,			TINT,
		SDREG,			TLDOUBLE|TDOUBLE|TFLOAT,
		NTEMP|NDREG,		RESC1,
		"	push AL\n	fild [sp]\n"
		"	inc sp\n	inc sp\n", },

/* convert unsigned short/int/ptr to double XXX - use NTEMP */
/* FIXME: need to force this via AX so we can cwd, fix stack setup to
   push both ax.dx*/
{ SCONV,	INFL,
		SAREG|SOREG|SNAME,	TUNSIGNED|TPOINT,
		SHFL,			TLDOUBLE|TDOUBLE|TFLOAT,
		NAREG|NASL|NDREG|NTEMP,	RESC2,
		"	cwd\n		push ax\n"
		"	fild [sp]\n	inc sp\n"
		"	inc sp\n", },

/* long to something */

/* convert (u)long to (u)char (mem->reg) */
{ SCONV,	INCH,
		SOREG|SNAME,		T32,
		SANY,			T8,
		NBREG|NBSL,		RESC1,
		"	mov A1, AL\n", },

/* convert (u)long to (u)char (reg->reg, hopefully nothing) */
{ SCONV,	INCH,
		SHL,			T32,
		SANY,			T8,
		NBREG|NBSL|NTEMP,	RESC1,
		"ZS", },

/* convert (u)long to (u)short (mem->reg) */
{ SCONV,	INAREG,
		SOREG|SNAME,		T32,
		SAREG,			TP16,
		NAREG|NASL,		RESC1,
		"	mov A1,AL\n", },

/* convert (u)long to 16bit (reg->reg, hopefully nothing) */
{ SCONV,	INAREG,
		SHL|SOREG|SNAME,	T32,
		SAREG,			T16,
		NAREG|NASL|NTEMP,	RESC1,
		"ZS", },

/* FIXME: float stuff is all TODO */

/* convert long long (in memory) to floating */
{ SCONV,	INFL,
		SOREG|SNAME,		TLONGLONG,
		SHFL,			TLDOUBLE|TDOUBLE|TFLOAT,
		NDREG,			RESC1,
		"	fild AL\n", },

/* convert long (in register) to floating */
{ SCONV,	INFL,
		SHL,			TLONGLONG,
		SHFL,			TLDOUBLE|TDOUBLE|TFLOAT,
		NTEMP|NDREG,		RESC1,
		"	push UL\n	push AL\n"
		"	fild [sp]\n	add sp, #8\n", },

/* convert unsigned long to floating */
{ SCONV,	INFL,
		SCREG,			TULONGLONG,
		SDREG,			TLDOUBLE|TDOUBLE|TFLOAT,
		NDREG,			RESC1,
		"ZJ", },

/* float to something */

#if 0 /* go via int by adding an extra sconv in clocal() */
/* convert float/double to (u) char. XXX should use NTEMP here */
{ SCONV,	INCH,
		SHFL,			TLDOUBLE|TDOUBLE|TFLOAT,
		SHCH,			T16|T8,
		NBREG,			RESC1,
		"	sub sp,#4\n	fistpl [sp]\n	pop	A1\n	pop U1\n", },

/* convert float/double to (u) int/short/char. XXX should use NTEMP here */
{ SCONV,	INCH,
		SHFL,			TLDOUBLE|TDOUBLE|TFLOAT,
		SHCH,			T16|T8,
		NCREG,			RESC1,
		"	sub sp,#4\n	fistpl (%sp)\n	pop A1\n	inc sp\n	inc sp\n", },
#endif

/* convert float/double to long XXX should use NTEMP here */
{ SCONV,	INAREG,
	SHFL,	TLDOUBLE|TDOUBLE|TFLOAT,
	SAREG,	TLONG,
		NAREG,	RESC1,
		"	sub sp, #12\n"
		"	fstcw sp\n"
		"	fstcw 4[sp]\n"
		"	mov byte ptr 1[sp], #12\n"
		"	fldcw sp\n"
		"	fistp 8[sp]\n"
		"	movl A1, 8(p)\n"
		"	fldcw 4[sp]\n"
		"	add sp, #4\n", },

/* convert float/double to unsigned long. XXX should use NTEMP here */
{ SCONV,       INAREG,
		SHFL,			TLDOUBLE|TDOUBLE|TFLOAT,
		SAREG,			TULONG,
		NAREG,			RESC1,
		"	sub sp, #16\n"
		"	fnstcw [sp]\n"
		"	fnstcw 4[sp]\n"
		"	mov byte ptr 1[sp], #12\n"
		"	fldcw [sp[\n"
		"	fistpq 8[sp]\n"
		"	mov word ptr 8[sp],A1\n"
		"	mov word ptr 10[sp],U1\n"
		"	fldcw 4[sp]\n"
		"	add sp, #16\n", },

/* convert float/double (in register) to long long */
{ SCONV,	INLL,
		SHFL,			TLDOUBLE|TDOUBLE|TFLOAT,
		SHLL,			TLONGLONG,
		NCREG,			RESC1,
		"	sub sp, #16\n"
		"	fnstcw [sp]\n"
		"	fnstcw [sp]\n"
		"	mov byte ptr 1[sp], #12\n"
		"	fldcw [sp]\n"
		"	fistpq 8[sp]\n"
		"	movl 8[sp],A1\n"
		"	movl 10[sp],U1\n"
		/* need to put 12/14 somewhere FIXME */
		"	fldcw 4[sp]\n"
		"	add sp, #16\n", },

/* convert float/double (in register) to unsigned long long */
{ SCONV,	INLL,
		SHFL,			TLDOUBLE|TDOUBLE|TFLOAT,
		SHLL,			TULONGLONG,
		NCREG,			RESC1,
		"	sub sp, #16\n"
		"	fnstcw [sp]\n"
		"	fnstcw 4[sp]\n"
		"	mov byte ptr 1[sp], #15\n"	/* 64-bit prec */
		"	fldcw [sp]\n"
		"	movl $0x5f000000, 8(%sp)\n"	/* (float)(1<<63) */
		"	fsubs 8[sp]\n"	/* keep in range of fistpq */
		"	fistpq 8[sp]\n"
		"	xor byte ptr 15[sp], #0x80\n"	/* addq $1>>63 to 8(%sp) */
		"	movl A1, 8[sp]\n"
		"	movl U1, 10[sp]\n"
		"	fldcw 4[sp]\n"
		"	add sp, #16\n", },
 


/* slut sconv */

/*
 * Subroutine calls.
 */

{ UCALL,	FOREFF,
		SCON,			TANY,
		SANY,			TANY,
		0,	0,
		"	call CL\nZC", },

{ CALL,		FOREFF,
		SCON,			TANY,
		SANY,			TANY,
		0,	0,
		"	call CL\nZC", },

//{ UCALL,	FOREFF,
//	SCON,	TANY,
//	SAREG,	TP16,
//		0,	0,
//		"	call CL\nZC", },

{ CALL,	INAREG,
		SCON,			TANY,
		SAREG,			TP16,
		NAREG|NASL,		RESC1,	/* should be 0 */
		"	call CL\nZC", },

{ UCALL,	INAREG,
		SCON,			TANY,
		SAREG,			TP16,
		NAREG|NASL,		RESC1,	/* should be 0 */
		"	call CL\nZC", },

{ CALL,	INBREG,
		SCON,			TANY,
		SBREG,			T8,
		NBREG,			RESC1,	/* should be 0 */
		"	call CL\nZC", },

{ UCALL,	INBREG,
		SCON,			TANY,
		SBREG,			T8,
		NBREG,			RESC1,	/* should be 0 */
		"	call CL\nZC", },

{ CALL,		INCREG,
		SCON,			TANY,
		SCREG,			TANY,
		NCREG|NCSL,		RESC1,	/* should be 0 */
		"	call CL\nZC", },

{ UCALL,	INCREG,
		SCON,			TANY,
		SCREG,			TANY,
		NCREG|NCSL,		RESC1,	/* should be 0 */
		"	call CL\nZC", },

{ CALL,	INDREG,
		SCON,			TANY,
		SDREG,			TANY,
		NDREG|NDSL,		RESC1,	/* should be 0 */
		"	call CL\nZC", },

{ UCALL,	INDREG,
		SCON,			TANY,
		SDREG,			TANY,
		NDREG|NDSL,		RESC1,	/* should be 0 */
		"	call CL\nZC", },

{ CALL,		FOREFF,
		SAREG,			TANY,
		SANY,			TANY,
		0,	0,
		"	call *AL\nZC", },

{ UCALL,	FOREFF,
		SAREG,			TANY,
		SANY,			TANY,
		0,	0,
		"	call *AL\nZC", },

{ CALL,		INAREG,
		SAREG,			TANY,
		SANY,			TANY,
		NAREG|NASL,		RESC1,	/* should be 0 */
		"	call *AL\nZC", },

{ UCALL,	INAREG,
		SAREG,			TANY,
		SANY,			TANY,
		NAREG|NASL,		RESC1,	/* should be 0 */
		"	call *AL\nZC", },

{ CALL,		INBREG,
		SAREG,			TANY,
		SANY,			TANY,
		NBREG|NBSL,		RESC1,	/* should be 0 */
		"	call *AL\nZC", },

{ UCALL,	INBREG,
		SAREG,			TANY,
		SANY,			TANY,
		NBREG|NBSL,		RESC1,	/* should be 0 */
		"	call *AL\nZC", },

{ CALL,		INCREG,
		SAREG,			TANY,
		SANY,			TANY,
		NCREG|NCSL,		RESC1,	/* should be 0 */
		"	call *AL\nZC", },

{ UCALL,	INCREG,
		SAREG,			TANY,
		SANY,			TANY,
		NCREG|NCSL,		RESC1,	/* should be 0 */
		"	call *AL\nZC", },

{ CALL,		INDREG,
		SAREG,			TANY,
		SANY,			TANY,
		NDREG|NDSL,		RESC1,	/* should be 0 */
		"	call *AL\nZC", },

{ UCALL,	INDREG,
		SAREG,			TANY,
		SANY,			TANY,
		NDREG|NDSL,		RESC1,	/* should be 0 */
		"	call *AL\nZC", },

{ STCALL,	FOREFF,
		SCON,			TANY,
		SANY,			TANY,
		NAREG|NASL,	0,
		"	call CL\nZC", },

{ STCALL,	INAREG,
		SCON,			TANY,
		SANY,			TANY,
		NAREG|NASL,		RESC1,	/* should be 0 */
		"	call CL\nZC", },

{ STCALL,	INAREG,
		SNAME|SAREG,		TANY,
		SANY,			TANY,
		NAREG|NASL,		RESC1,	/* should be 0 */
		"	call *AL\nZC", },

/*
 * The next rules handle all binop-style operators.
 *
 * 8 and 16bit we do directly, 32bit is a mix of helpers and
 * direct operations. 64bit TODO, FPU lives in it's own little
 * world.
 */
{ PLUS,		INL|FOREFF,
		SHL,			T32,
		SHL|SNAME|SOREG,	T32,
		0,			RLEFT,
		"	add AL,AR\n	adc UL,UR\n", },

{ PLUS,		INL|FOREFF,
		SHL|SNAME|SOREG,	T32,
		SHL|SCON,		T32,
		0,			RLEFT,
		"	add AL,AR\n	adc UL,UR\n", },

/* Special treatment for long  XXX - fix commutative check */
{ PLUS,		INL|FOREFF,
		SHL|SNAME|SOREG,	T32,
		SHL,			T32,
		0,			RRIGHT,
		"	add AL,AR\n	adc UL,UR\n", },

{ PLUS,		INFL,
		SHFL,			TDOUBLE,
		SNAME|SOREG,		TDOUBLE,
		0,			RLEFT,
		"	faddl AR\n", },

{ PLUS,		INFL|FOREFF,
		SHFL,			TLDOUBLE|TDOUBLE|TFLOAT,
		SHFL,			TLDOUBLE|TDOUBLE|TFLOAT,
		0,			RLEFT,
		"	faddp\n", },

{ PLUS,		INAREG|FOREFF,
		SAREG|SNAME|SOREG,	TP16,
		SONE,			TANY,
		0,			RLEFT,
		"	inc AL\n", },

{ PLUS,		INAREG|FOREFF,
		SAREG|SNAME|SOREG,	TP16,
		STWO,			TANY,
		0,			RLEFT,
		"	inc AL\n	inc AL\n", },

{ PLUS,		INCH|FOREFF,
		SHCH|SNAME|SOREG,	T8,
		SONE,			TANY,
		0,			RLEFT,
		"	inc AL\n", },

{ PLUS,		INCH|FOREFF,
		SHCH|SNAME|SOREG,	T8,
		STWO,			TANY,
		0,			RLEFT,
		"	inc AL\n	inc AL\n", },

{ PLUS,		INAREG,
		SAREG,			T16,
		SAREG,			T16,
		NAREG|NASL|NASR,	RESC1,
		"	lea A1, [AL+AR]\n", },

{ MINUS,	INAREG|FOREFF,
		SAREG|SNAME|SOREG,	TP16,
		SONE,			TANY,
		0,			RLEFT,
		"	dec AL\n", },

{ MINUS,	INAREG|FOREFF,
		SAREG|SNAME|SOREG,	TP16,
		STWO,			TANY,
		0,			RLEFT,
		"	dec AL\n	dec AL\n", },

{ MINUS,	INCH|FOREFF,
		SHCH|SNAME|SOREG,	T8,
		SONE,			TANY,
		0,			RLEFT,
		"	dec AL\n", },

{ MINUS,	INCH|FOREFF,
		SHCH|SNAME|SOREG,	T8,
		STWO,			TANY,
		0,			RLEFT,
		"	dec AL\n	decl AL\n", },

/* address as register offset, negative */
{ MINUS,	INLL|FOREFF,
		SHL,			T32,
		SHL|SNAME|SOREG,	T32,
		0,			RLEFT,
		"	sub AL,AR\n	sbb UL,UR\n", },

{ MINUS,	INL|FOREFF,
		SHL|SNAME|SOREG,	T32,
		SHL|SCON,		T32,
		0,			RLEFT,
		"	sub AL,AR\n	sbb UL,UR\n", },

{ MINUS,	INFL,
		SHFL,			TDOUBLE,
		SNAME|SOREG,		TDOUBLE,
		0,			RLEFT,
		"	fsubl AR\n", },

{ MINUS,	INFL|FOREFF,
		SHFL,			TLDOUBLE|TDOUBLE|TFLOAT,
		SHFL,			TLDOUBLE|TDOUBLE|TFLOAT,
		0,			RLEFT,
		"	fsubZAp\n", },

/* Simple r/m->reg ops */
/* m/r |= r */

{ OPSIMP,	INAREG|FOREFF|FORCC,
		SHINT|SNAME|SOREG,	TP16,
		SHINT,			TP16,
		0,			RLEFT|RESCC,
		"	Ow AL,AR\n", },

/* r |= r/m */
{ OPSIMP,	INAREG|FOREFF|FORCC,
		SHINT,			T16,
		SHINT|SNAME|SOREG,	T16,
		0,			RLEFT|RESCC,
		"	Ow AL,AR\n", },

/* m/r |= r */
{ OPSIMP,	INCH|FOREFF|FORCC,
		SHCH,			T8,
		SHCH|SNAME|SOREG,	T8,
		0,			RLEFT|RESCC,
		"	Ob AL,AR\n", },

/* r |= r/m */
{ OPSIMP,	INCH|FOREFF|FORCC,
		SHCH,			T8,
		SHCH|SNAME|SOREG,	T8,
		0,			RLEFT|RESCC,
		"	Ob AL,AR\n", },

/* m/r |= const */
{ OPSIMP,	INAREG|FOREFF|FORCC,
		SHINT|SNAME|SOREG,	TP16,
		SCON,			TANY,
		0,			RLEFT|RESCC,
		"	Ow AL,AR\n", },

{ OPSIMP,	INCH|FOREFF|FORCC,
		SHCH|SNAME|SOREG,	T8,
		SCON,			TANY,
		0,			RLEFT|RESCC,
		"	Ob AL,AR\n", },

/* r |= r/m */
{ OPSIMP,	INL|FOREFF,
		SHL,			T32,
		SHL|SNAME|SOREG,	T32,
		0,			RLEFT,
		"	Ow AL,AR\n	Ow UL,UR\n", },

/* m/r |= r/const */
{ OPSIMP,	INL|FOREFF,
		SHL|SNAME|SOREG,	T32,
		SHL|SCON,		T32,
		0,			RLEFT,
		"	Ow AL,AR\n	Ow UL,UR\n", },

/* Try use-reg instructions first */
{ PLUS,		INAREG,
		SAREG,			TP16,
		SCON,			TANY,
		NAREG|NASL,		RESC1,
		"	lea A1, CR[AL]\n", },

{ MINUS,	INAREG,
		SAREG,			TP16,
		SPCON,			TANY,
		NAREG|NASL,		RESC1,
		"	lea A1, -CR[AL]\n", },


/*
 * The next rules handle all shift operators.
 */
/* (u)long left shift is emulated, longlong to do */

/* For 8086 we only have shift by 1 or shift by CL

   We need a way to optimise shifts by 8/16/24/32/etc
   shifts by 8 16 24 and 32 as moves between registers for
   the bigger types. (eg >> 16 on a long might be mov dx, ax,
   xor ax, ax) */
   
{ LS,		INCREG,
		SCREG,			T32,
		SHCH,			T8,
		0,			RLEFT,
		"ZO", },

/* Register 8086 timing is 2 for #1 versus 8 + 4/bin for multiple
   so a lot of shifts would in fact best be done without using the cl
   variant, especially including the cost of a) loading cl b) probably
   having to boot something out of cx in the first place. For memory
   its 15+EA v 20 + EA + 4/bit, so the other way.
   
   8,16,24 should of course be done by loads.. FIXME 
   
   Also the compiler keeps generating mov dh, #8, mov cl, dh.. FIXME
   
   For 80186 onwards we have shl reg, immediate (other than 1), 186 shift
   is also much faster */


/* r/m <<= const 1*/
{ LS,		INAREG|FOREFF,
		SAREG|SNAME|SOREG,	T16,
		SONE,			TANY,
		0,			RLEFT,
		"	shl AL,#1\n", },

/* r <<= const 2 */
{ LS,		INAREG|FOREFF,
		SAREG,			T16,
		STWO,			TANY,
		0,			RLEFT,
		"	shl AL,#1\n	shl AL,#1\n", },

/* r/m <<= r */
{ LS,		INAREG|FOREFF,
		SAREG|SNAME|SOREG,	T16,
		SHCH,			T8,
		NSPECIAL,		RLEFT,
		"	shl AL,AR\n", },

{ LS,		INCH|FOREFF,
		SHCH|SNAME|SOREG,	T8,
		SONE,			TANY,
		NSPECIAL,		RLEFT,
		"	sal AL,#1\n", },

{ LS,		INCH|FOREFF,
		SHCH,			T8,
		STWO,			TANY,
		NSPECIAL,		RLEFT,
		"	sal AL,#1\n	sal AL,#1", },

{ LS,		INCH|FOREFF,
		SHCH|SNAME|SOREG,	T8,
		SHCH,			T8,
		NSPECIAL,		RLEFT,
		"	sal AL,AR\n", },

/* (u)long right shift is emulated. Use a 16bit register so the push
   comes out sanely */
{ RS,		INCREG,
		SCREG,			T32,
		SHCH,			T8,
		0,			RLEFT,
		"ZO", },

{ RS,		INAREG|FOREFF,
		SAREG|SNAME|SOREG,	TINT,
		SHCH,			T8,
		NSPECIAL,		RLEFT,
		"	sar AL,AR\n", },

{ RS,		INAREG|FOREFF,
		SAREG|SNAME|SOREG,	TINT,
		SONE,			TANY,
		NSPECIAL,		RLEFT,
		"	sar AL,#1\n", },

{ RS,		INAREG|FOREFF,
		SAREG,			TINT,
		STWO,			TANY,
		NSPECIAL,		RLEFT,
		"	sar AL,#1\n	sar AL,#1", },

{ RS,		INAREG|FOREFF,
		SAREG|SNAME|SOREG,	TUNSIGNED|TPOINT,
		SHCH,			T8,
		NSPECIAL,		RLEFT,
		"	shr AL,AR\n", },

{ RS,		INAREG|FOREFF,
		SAREG|SNAME|SOREG,	TUNSIGNED,
		SONE,			TANY,
		0,			RLEFT,
		"	shr AL,#1\n", },

{ RS,		INAREG|FOREFF,
		SAREG,			TUNSIGNED,
		STWO,			TANY,
		0,			RLEFT,
		"	shr AL,#1	shr AL,#1\n", },

{ RS,	INCH|FOREFF,
		SHCH|SNAME|SOREG,	TCHAR,
		SHCH,			T8,
		NSPECIAL,		RLEFT,
		"	sar AL,AR\n", },

{ RS,	INCH|FOREFF,
		SHCH|SNAME|SOREG,	TCHAR,
		SONE,			TANY,
		NSPECIAL,		RLEFT,
		"	sar AL,#1\n", },

{ RS,	INCH|FOREFF,
		SHCH|SNAME|SOREG,	TCHAR,
		STWO,			TANY,
		NSPECIAL,		RLEFT,
		"	sar AL,#1\n	sar AL,#1\n", },

{ RS,	INCH|FOREFF,
		SHCH|SNAME|SOREG,	TUCHAR,
		SHCH,			T8,
		NSPECIAL,		RLEFT,
		"	shr AL,AR\n", },

{ RS,		INCH|FOREFF,
		SHCH|SNAME|SOREG,	TUCHAR,
		SONE,			TANY,
		NSPECIAL,		RLEFT,
		"	shr AL,#1\n", },

{ RS,		INCH|FOREFF,
		SHCH|SNAME|SOREG,	TUCHAR,
		STWO,			TANY,
		NSPECIAL,		RLEFT,
		"	shr AL,#1\n	shr AL,#1\n", },

/*
 * The next rules takes care of assignments. "=".
 */
 
{ ASSIGN,	FORCC|FOREFF|INL,
		SHL,			T32,
		SMIXOR,			TANY,
		0,			RDEST,
		"	xor AL,AL\n	xor UL,UL\n", },

{ ASSIGN,	FORCC|FOREFF|INL,
		SHL,			T32,
		SMILWXOR,		TANY,
		0,			RDEST,
		"	xor AL,AL\n	mov UR,UL\n", },

{ ASSIGN,	FORCC|FOREFF|INL,
		SHL,			T32,
		SMIHWXOR,		TANY,
		0,			RDEST,
		"	mov AL,AR\n	xor UL,UL\n", },

{ ASSIGN,	FOREFF|INL,
		SHL,			T32,
		SCON,			TANY,
		0,			RDEST,
		"	mov AL,AR\n	mov UL,UR\n", },

{ ASSIGN,	FOREFF,
		SHL|SNAME|SOREG,	T32,
		SCON,			TANY,
		0,			0,
		"	mov AL,AR\n	mov UL,UR\n", },

{ ASSIGN,	FOREFF,
		SAREG|SNAME|SOREG,	TP16,
		SCON,			TANY,
		0,			0,
		"	mov AL, AR\n", },

{ ASSIGN,	FOREFF|INAREG,
		SAREG,			TP16,
		SCON,			TANY,
		0,			RDEST,
		"	mov AL, AR\n", },

{ ASSIGN,	FOREFF,
		SHCH|SNAME|SOREG,	T8,
		SCON,			TANY,
		0,	0,
		"	mov AL, AR\n", },

{ ASSIGN,	FOREFF|INCH,
		SHCH,			T8,
		SCON,			TANY,
		0,			RDEST,
		"	mov AL, AR\n", },

{ ASSIGN,	FOREFF|INL,
		SNAME|SOREG,		T32,
		SHL,			T32,
		0,			RDEST,
		"	mov AL,AR\n	mov UL,UR\n", },

{ ASSIGN,	FOREFF|INL,
		SHL,			T32,
		SHL,			T32,
		0,			RDEST,
		"ZH", },

{ ASSIGN,	FOREFF|INAREG,
		SAREG|SNAME|SOREG,	TP16,
		SAREG,			TP16,
		0,			RDEST,
		"	mov AL,AR\n", },

{ ASSIGN,	FOREFF|INAREG,
		SAREG,			TP16,
		SAREG|SNAME|SOREG,	TP16,
		0,			RDEST,
		"	mov AL,AR\n", },

{ ASSIGN,	FOREFF|INCH,
		SHCH|SNAME|SOREG,	T8,
		SHCH,			T8|T16,
		0,			RDEST,
		"	mov AL,AR\n", },

{ ASSIGN,	INDREG|FOREFF,
		SHFL,			TFLOAT|TDOUBLE|TLDOUBLE,
		SHFL,			TFLOAT|TDOUBLE|TLDOUBLE,
		0,			RDEST,
		"", }, /* This will always be in the correct register */

/* order of table entries is very important here! */
{ ASSIGN,	INFL,
		SNAME|SOREG,		TLDOUBLE,
		SHFL,			TFLOAT|TDOUBLE|TLDOUBLE,
		0,			RDEST,
		"	fstpt AL\n	fldt AL\n", }, /* XXX */

{ ASSIGN,	FOREFF,
		SNAME|SOREG,		TLDOUBLE,
		SHFL,			TFLOAT|TDOUBLE|TLDOUBLE,
		0,			0,
		"	fstpt AL\n", },

{ ASSIGN,	INFL,
		SNAME|SOREG,		TDOUBLE,
		SHFL,			TFLOAT|TDOUBLE|TLDOUBLE,
		0,			RDEST,
		"	fstl AL\n", },

{ ASSIGN,	FOREFF,
		SNAME|SOREG,		TDOUBLE,
		SHFL,			TFLOAT|TDOUBLE|TLDOUBLE,
		0,			0,
		"	fstpl AL\n", },

{ ASSIGN,	INFL,
		SNAME|SOREG,		TFLOAT,
		SHFL,			TFLOAT|TDOUBLE|TLDOUBLE,
		0,			RDEST,
		"	fsts AL\n", },

{ ASSIGN,	FOREFF,
		SNAME|SOREG,		TFLOAT,
		SHFL,			TFLOAT|TDOUBLE|TLDOUBLE,
		0,			0,
		"	fstps AL\n", },
/* end very important order */

{ ASSIGN,	INFL|FOREFF,
		SHFL,			TLDOUBLE,
		SHFL|SOREG|SNAME,	TLDOUBLE,
		0,			RDEST,
		"	fldt AR\n", },

{ ASSIGN,	INFL|FOREFF,
		SHFL,			TDOUBLE,
		SHFL|SOREG|SNAME,	TDOUBLE,
		0,			RDEST,
		"	fldl AR\n", },

{ ASSIGN,	INFL|FOREFF,
		SHFL,			TFLOAT,
		SHFL|SOREG|SNAME,	TFLOAT,
		0,			RDEST,
		"	flds AR\n", },

/* Do not generate memcpy if return from funcall */
#if 0
{ STASG,	INAREG|FOREFF,
		SOREG|SNAME|SAREG,	TPTRTO|TSTRUCT,
		SFUNCALL,		TPTRTO|TSTRUCT,
		0,			RRIGHT,
		"", },
#endif

{ STASG,	INAREG|FOREFF,
		SOREG|SNAME,		TANY,
		SAREG,			TPTRTO|TANY,
		NSPECIAL|NAREG,		RDEST,
		"F	mov A1,si\nZQF	mov si,A1\n", },

/*
 * DIV/MOD/MUL 
 */
/* long div is emulated */
{ DIV,	INCREG,
		SCREG|SNAME|SOREG|SCON, T32,
		SCREG|SNAME|SOREG|SCON, T32,
		NSPECIAL|NCREG|NCSL|NCSR,	RESC1,
		"ZO", },

/* REVIEW We can only do (i)divb ax/byte  and (i)divw (dx:ax)/word
   and the results are always in ah/al (remainer/mod)
   or dx:ax (dx = remainer, ax = mod)
   
   Power of two needs to be done by shifts. For other cases of constants
   we need to implement two things
   1. Spotting add sequences for constants with few 1 bits on one side
   2. Spotting cases we can compute the magic constant to multiply with for
      the same result */
   
   
{ DIV,	INAREG,
		SAREG,			TUNSIGNED|TPOINT,
		SAREG|SNAME|SOREG,	TUNSIGNED|TPOINT,
		NSPECIAL,		RDEST,
		"	xor dx,dx\n	divw AR\n", },

{ DIV,	INCH,
		SHCH,			TUCHAR,
		SHCH|SNAME|SOREG,	TUCHAR,
		NSPECIAL,		RDEST,
		"	xor ah,ah\n	divb AR\n", },

{ DIV,	INFL,
		SHFL,			TDOUBLE,
		SNAME|SOREG,		TDOUBLE,
		0,			RLEFT,
		"	fdivl AR\n", },

{ DIV,	INFL,
		SHFL,			TLDOUBLE|TDOUBLE|TFLOAT,
		SHFL,			TLDOUBLE|TDOUBLE|TFLOAT,
		0,			RLEFT,
		"	fdivZAp\n", },

/* (u)long mod is emulated */
{ MOD,		INCREG,
		SCREG|SNAME|SOREG|SCON,	T32,
		SCREG|SNAME|SOREG|SCON,	T32,
		NSPECIAL|NCREG|NCSL|NCSR,	RESC1,
		"ZO", },

{ MOD,		INAREG,
		SAREG,			TP16,
		SAREG|SNAME|SOREG,	TP16,
		NAREG|NSPECIAL,		RESC1,
		"	xor dx,dx\n	divw AR\n", },

{ MOD,	INCH,
		SHCH,			TUCHAR,
		SHCH|SNAME|SOREG,	TUCHAR,
		NBREG|NSPECIAL,		RESC1,
		"	xor ah,ah\n	divb AR\n", },

/* (u)long mul is emulated */
/* On 8086 we can only do multiplies of al * value into ax (for 8bit)
   or ax * value into dx:ax for 16bit 
   
   80186 allows us to do a signed multiply of a register with a constant
   into a second register
   
   Same about shifts, and add optimisations applies here too */
   
/* 32bit mul is emulated (for now) */
{ MUL,		INCREG,
		SCREG|SNAME|SOREG|SCON,		T32,
		SCREG|SNAME|SOREG|SCON,		T32,
		NSPECIAL|NCREG|NCSL|NCSR,	RESC1,
		"ZO", },

/* FIMXE: need special rules */
{ MUL,	INAREG,
		SAREG,			T16|TPOINT,
		SAREG|SNAME|SOREG,	T16|TPOINT,
		NSPECIAL,		RDEST,
		"	mul AR\n", },

{ MUL,	INCH,
		SHCH,			T8,
		SHCH|SNAME|SOREG,	T8,
		NSPECIAL,		RDEST,
		"	mulb AR\n", },

{ MUL,	INFL,
		SHFL,			TDOUBLE,
		SNAME|SOREG,		TDOUBLE,
		0,			RLEFT,
		"	fmull AR\n", },

{ MUL,	INFL,
		SHFL	,		TLDOUBLE|TDOUBLE|TFLOAT,
		SHFL,			TLDOUBLE|TDOUBLE|TFLOAT,
		0,			RLEFT,
		"	fmulp\n", },

/*
 * Indirection operators.
 */
{ UMUL,	INLL,
		SANY,			TANY,
		SOREG,			T32,
		NCREG,			RESC1,
		"	mov UL,U1\n	mov AL,A1\n", },

{ UMUL,	INAREG,
		SANY,			TP16,
		SOREG,			TP16,
		NAREG|NASL,		RESC1,
		"	mov AL,A1\n", },

{ UMUL,	INCH,
		SANY,			TANY,
		SOREG,			T8,
		NBREG|NBSL,		RESC1,
		"	mov AL,A1\n", },

{ UMUL,	INAREG,
		SANY,			TANY,
		SOREG,			T16,
		NAREG|NASL,		RESC1,
		"	mov AL,A1\n", },

{ UMUL,	INFL,
		SANY,			TANY,
		SOREG,			TLDOUBLE,
		NDREG|NDSL,		RESC1,
		"	fldt AL\n", },

{ UMUL,	INFL,
		SANY,			TANY,
		SOREG,			TDOUBLE,
		NDREG|NDSL,		RESC1,
		"	fldl AL\n", },

{ UMUL,	INFL,
		SANY,			TANY,
		SOREG,			TFLOAT,
		NDREG|NDSL,		RESC1,
		"	flds AL\n", },

/*
 * Logical/branching operators
 */

/* Comparisions, take care of everything */
{ OPLOG,	FORCC,
		SHL|SOREG|SNAME,	T32,
		SHL,			T32,
		0,	0,
		"ZD", },

{ OPLOG,	FORCC,
		SAREG|SOREG|SNAME,	TP16,
		SCON|SAREG,		TP16,
		0, 			RESCC,
		"	cmp AL,AR\n", },


{ OPLOG,	FORCC,
		SCON|SAREG,		TP16,
		SAREG|SOREG|SNAME,	TP16,
		0, 			RESCC,
		"	cmp AL,AR\n", },

{ OPLOG,	FORCC,
		SBREG|SOREG|SNAME,	T8,
		SCON|SBREG,		TANY,
		0, 			RESCC,
		"	cmpb AL,AR\n", },

{ OPLOG,	FORCC,
		SCON|SBREG,		T8,
		SBREG|SOREG|SNAME,	TANY,
		0, 			RESCC,
		"	cmpb AL,AR\n", },

{ OPLOG,	FORCC,
		SDREG,			TLDOUBLE|TDOUBLE|TFLOAT,
		SDREG,			TLDOUBLE|TDOUBLE|TFLOAT,
		0, 			RNOP,
		"ZG", },

{ OPLOG,	FORCC,
		SANY,			TANY,
		SANY,			TANY,
		REWRITE,	0,
		"diediedie!", },

/* AND/OR/ER/NOT */

/* FIXME: pcc generates nonsense ands, but they should be fixed somewhere
   if possible. In particular it will do the classic 32bit and with a 16bit
   0xFFFF by generating and ax,#ffff and bx,#0
   	eg compiling
   		sum1 = (sum1 & 0xFFFF) + (sum1 >> 16);
	writes a pile of crap code.
*/
   	
   	
{ AND,	INCREG|FOREFF,
		SCREG,			T32,
		SCREG|SOREG|SNAME,	T32,
		0,			RLEFT,
		"	and AR,AL\n	and UR,UL\n", },

{ AND,	INAREG|FOREFF,
		SAREG,			T16,
		SAREG|SOREG|SNAME,	T16,
		0,			RLEFT,
		"	and AR,AL\n", },

{ AND,	INAREG|FOREFF,  
		SAREG|SOREG|SNAME,	T16,
		SCON|SAREG,		T16,
		0,			RLEFT,
		"	and AR,AL\n", },

{ AND,	INBREG|FOREFF,
		SBREG|SOREG|SNAME,	T8,
		SCON|SBREG,		T8,
		0,			RLEFT,
		"	and AR,AL\n", },

{ AND,	INBREG|FOREFF,
		SBREG,			T8,
		SBREG|SOREG|SNAME,	T8,
		0,			RLEFT,
		"	and AR,AL\n", },
/* AND/OR/ER/NOT */

/*
 * Jumps.
 */
{ GOTO, 	FOREFF,
		SCON,			TANY,
		SANY,			TANY,
		0,			RNOP,
		"	jmp LL\n", },

#if defined(GCC_COMPAT) || defined(LANG_F77)
{ GOTO, 	FOREFF,
		SAREG,			TANY,
		SANY,			TANY,
		0,			RNOP,
		"	jmp *AL\n", },
#endif

/*
 * Convert LTYPE to reg.
 */
{ OPLTYPE,	FORCC|INL,
		SCREG,			T32,
		SMIXOR,			TANY,
		NCREG,			RESC1,
		"	xor U1,U1\n	xor A1,A1\n", },

{ OPLTYPE,	FORCC|INL,
		SCREG,			T32,
		SMILWXOR,		TANY,
		NCREG,			RESC1,
		"	mov U1,UL\n	xor A1,A1\n", },

{ OPLTYPE,	FORCC|INL,
		SCREG,			T32,
		SMIHWXOR,		TANY,
		NCREG,			RESC1,
		"	xor U1,U1\n	mov A1,AL\n", },

{ OPLTYPE,	INL,
		SANY,			TANY,
		SCREG,			T32,
		NCREG,			RESC1,
		"ZK", },

{ OPLTYPE,	INL,
		SANY,			TANY,
		SCON|SOREG|SNAME,	T32,
		NCREG,			RESC1,
		"	mov U1,UL\n	mov A1,AL\n", },

{ OPLTYPE,	FORCC|INAREG,
		SAREG,			TP16,
		SMIXOR,			TANY,
		NAREG|NASL,		RESC1,
		"	xor A1,A1\n", },

{ OPLTYPE,	INAREG,
		SANY,			TANY,
		SAREG|SCON|SOREG|SNAME,	TP16,
		NAREG|NASL,		RESC1,
		"	mov A1,AL\n", },

{ OPLTYPE,	INBREG,
		SANY,			TANY,
		SBREG|SOREG|SNAME|SCON,	T8,
		NBREG,			RESC1,
		"	mov A1,AL\n", },

{ OPLTYPE,	FORCC|INAREG,
		SAREG,			T16,
		SMIXOR,			TANY,
		NAREG,			RESC1,
		"	xor A1,A1\n", },

{ OPLTYPE,	INAREG,
		SANY,			TANY,
		SAREG|SOREG|SNAME|SCON,	T16,
		NAREG,			RESC1,
		"	mov A1,AL\n", },

{ OPLTYPE,	INDREG,
		SANY,			TLDOUBLE,
		SOREG|SNAME,		TLDOUBLE,
		NDREG,			RESC1,
		"	fldt AL\n", },

{ OPLTYPE,	INDREG,
		SANY,			TDOUBLE,
		SOREG|SNAME,		TDOUBLE,
		NDREG,			RESC1,
		"	fldl AL\n", },

{ OPLTYPE,	INDREG,
		SANY,			TFLOAT,
		SOREG|SNAME,		TFLOAT,
		NDREG,			RESC1,
		"	flds AL\n", },

/* Only used in ?: constructs. The stack already contains correct value */
{ OPLTYPE,	INDREG,
		SANY,			TFLOAT|TDOUBLE|TLDOUBLE,
		SDREG,			TFLOAT|TDOUBLE|TLDOUBLE,
		NDREG,			RESC1,
		"", },

/*
 * Negate a word.
 */

{ UMINUS,	INCREG|FOREFF,
		SCREG,			T32,
		SCREG,			T32,
		0,			RLEFT,
		"	neg AL\n	adc UL,#0\n	neg UL\n", },

{ UMINUS,	INAREG|FOREFF,
		SAREG,			TP16,
		SAREG,			TP16,
		0,			RLEFT,
		"	neg AL\n", },

{ UMINUS,	INBREG|FOREFF,
		SBREG,			T8,
		SBREG,			T8,
		0,			RLEFT,
		"	neg AL\n", },

{ UMINUS,	INFL|FOREFF,
		SHFL,			TLDOUBLE|TDOUBLE|TFLOAT,
		SHFL,			TLDOUBLE|TDOUBLE|TFLOAT,
		0,			RLEFT,
		"	fchs\n", },

{ COMPL,	INCREG,
		SCREG,			T32,
		SANY,			TANY,
		0,			RLEFT,
		"	not AL\n	not UL\n", },

{ COMPL,	INAREG,
		SAREG,			T16,
		SANY,			TANY,
		0,			RLEFT,
		"	not AL\n", },

{ COMPL,	INBREG,
		SBREG,			T8,
		SANY,			TANY,
		0,			RLEFT,
		"	not AL\n", },

/*
 * Arguments to functions.
 *
 * char has already been promoted to integer types
 */
 
/* Push immediate not 8086... Loading a register and pushing costs us
   4 + 11 clocks, loading memory would cost us 16 + EA */
{ FUNARG,	FOREFF,
		/*SCON|*/SCREG|SNAME|SOREG,	T32,
		SANY,			T32,
		0,			RNULL,
		"	push UL\n	push AL\n", },

{ FUNARG,	FOREFF,
		/*SCON|*/SAREG|SNAME|SOREG,	T16|TPOINT,
		SANY,			TP16,
		0,			RNULL,
		"	push AL\n", },

/* FIXME: FPU needs reworking into 4 regs or a memcpy */
{ FUNARG,	FOREFF,
		SNAME|SOREG,		TDOUBLE,
		SANY,			TDOUBLE,
		0,			0,
		"	pushl UL\n	pushl AL\n", },

{ FUNARG,	FOREFF,
		SDREG,			TDOUBLE,
		SANY,			TDOUBLE,
		0,			0,
		"	sub sp,#8\n	fstpl [sp]\n", },

{ FUNARG,	FOREFF,
		SNAME|SOREG,		TFLOAT,
		SANY,			TFLOAT,
		0,	0,
		"	push UL\n	push AL\n", },

{ FUNARG,	FOREFF,
		SDREG,			TFLOAT,
		SANY,			TFLOAT,
		0,			0,
		"	sub sp,#4\n	fstps [sp]\n", },

{ FUNARG,	FOREFF,
		SDREG,			TLDOUBLE,
		SANY,			TLDOUBLE,
		0,			0,
		"	sub sp,#12\n	fstpt [sp]\n", },

{ STARG,	FOREFF,
		SAREG,			TPTRTO|TSTRUCT,
		SANY,			TSTRUCT,
		NSPECIAL,		0,
		"ZF", },

# define DF(x) FORREW,SANY,TANY,SANY,TANY,REWRITE,x,""

{ UMUL, DF( UMUL ), },

{ ASSIGN, DF(ASSIGN), },

{ STASG, DF(STASG), },

{ FLD, DF(FLD), },

{ OPLEAF, DF(NAME), },

/* { INIT, DF(INIT), }, */

{ OPUNARY, DF(UMINUS), },

{ OPANY, DF(BITYPE), },

{ FREE,	FREE,	FREE,	FREE,	FREE,	FREE,	FREE,	FREE,	"help; I'm in trouble\n" },
};

int tablesize = sizeof(table)/sizeof(table[0]);