xref: /csrg-svn/usr.bin/f77/pass1.tahoe/intr.c (revision 46304)
143212Sbostic /*
243212Sbostic  * Copyright (c) 1980 Regents of the University of California.
343212Sbostic  * All rights reserved.  The Berkeley software License Agreement
443212Sbostic  * specifies the terms and conditions for redistribution.
543212Sbostic  */
643212Sbostic 
743212Sbostic #ifndef lint
843212Sbostic static char sccsid[] = "@(#)intr.c	5.1 (Berkeley) 6/7/85";
943212Sbostic #endif not lint
1043212Sbostic 
1143212Sbostic /*
1243212Sbostic  * intr.c
1343212Sbostic  *
1443212Sbostic  * Routines for handling intrinsic functions, f77 compiler pass 1, 4.2 BSD.
1543212Sbostic  *
1643212Sbostic  * University of Utah CS Dept modification history:
1743212Sbostic  *
1843212Sbostic  * $Log:	intr.c,v $
1943212Sbostic  * Revision 1.4  85/02/22  00:54:59  donn
2043212Sbostic  * Mark intrinsic functions as having storage class STGINTR.  builtin()
2143212Sbostic  * always returns STGEXT nodes.  Notice that the reference to the function
2243212Sbostic  * in the external symbol table still uses STGEXT...  I hope this is right.
2343212Sbostic  *
2443212Sbostic  * Revision 1.3  85/01/15  21:05:40  donn
2543212Sbostic  * Changes to distinguish explicit from implicit conversions with intrconv().
2643212Sbostic  *
2743212Sbostic  * Revision 1.2  84/12/15  01:02:33  donn
28*46304Sbostic  * Added a case for an integer*4 result from len() in inlne().  Previously
2943212Sbostic  * only -i2 provoked len() inline, sigh.
3043212Sbostic  *
3143212Sbostic  */
3243212Sbostic 
3343212Sbostic #include "defs.h"
3443212Sbostic 
3543212Sbostic extern ftnint intcon[14];
3643212Sbostic extern double realcon[6];
3743212Sbostic 
3843212Sbostic union
3943212Sbostic 	{
4043212Sbostic 	int ijunk;
4143212Sbostic 	struct Intrpacked bits;
4243212Sbostic 	} packed;
4343212Sbostic 
4443212Sbostic struct Intrbits
4543212Sbostic 	{
4643212Sbostic 	int intrgroup /* :3 */;
4743212Sbostic 	int intrstuff /* result type or number of generics */;
4843212Sbostic 	int intrno /* :7 */;
4943212Sbostic 	};
5043212Sbostic 
5143212Sbostic LOCAL struct Intrblock
5243212Sbostic 	{
5343212Sbostic 	char intrfname[VL];
5443212Sbostic 	struct Intrbits intrval;
5543212Sbostic 	} intrtab[ ] =
5643212Sbostic {
5743212Sbostic "int", 		{ INTRCONV, TYLONG },
5843212Sbostic "real", 	{ INTRCONV, TYREAL },
5943212Sbostic "dble", 	{ INTRCONV, TYDREAL },
6043212Sbostic "dreal",	{ INTRCONV, TYDREAL },
6143212Sbostic "cmplx", 	{ INTRCONV, TYCOMPLEX },
6243212Sbostic "dcmplx", 	{ INTRCONV, TYDCOMPLEX },
6343212Sbostic "ifix", 	{ INTRCONV, TYLONG },
6443212Sbostic "idint", 	{ INTRCONV, TYLONG },
6543212Sbostic "float", 	{ INTRCONV, TYREAL },
6643212Sbostic "dfloat",	{ INTRCONV, TYDREAL },
6743212Sbostic "sngl", 	{ INTRCONV, TYREAL },
6843212Sbostic "ichar", 	{ INTRCONV, TYLONG },
6943212Sbostic "iachar", 	{ INTRCONV, TYLONG },
7043212Sbostic "char", 	{ INTRCONV, TYCHAR },
7143212Sbostic "achar", 	{ INTRCONV, TYCHAR },
7243212Sbostic 
7343212Sbostic "max", 		{ INTRMAX, TYUNKNOWN },
7443212Sbostic "max0", 	{ INTRMAX, TYLONG },
7543212Sbostic "amax0", 	{ INTRMAX, TYREAL },
7643212Sbostic "max1", 	{ INTRMAX, TYLONG },
7743212Sbostic "amax1", 	{ INTRMAX, TYREAL },
7843212Sbostic "dmax1", 	{ INTRMAX, TYDREAL },
7943212Sbostic 
8043212Sbostic "and",		{ INTRBOOL, TYUNKNOWN, OPBITAND },
8143212Sbostic "or",		{ INTRBOOL, TYUNKNOWN, OPBITOR },
8243212Sbostic "xor",		{ INTRBOOL, TYUNKNOWN, OPBITXOR },
8343212Sbostic "not",		{ INTRBOOL, TYUNKNOWN, OPBITNOT },
8443212Sbostic "lshift",	{ INTRBOOL, TYUNKNOWN, OPLSHIFT },
8543212Sbostic "rshift",	{ INTRBOOL, TYUNKNOWN, OPRSHIFT },
8643212Sbostic 
8743212Sbostic "min", 		{ INTRMIN, TYUNKNOWN },
8843212Sbostic "min0", 	{ INTRMIN, TYLONG },
8943212Sbostic "amin0", 	{ INTRMIN, TYREAL },
9043212Sbostic "min1", 	{ INTRMIN, TYLONG },
9143212Sbostic "amin1", 	{ INTRMIN, TYREAL },
9243212Sbostic "dmin1", 	{ INTRMIN, TYDREAL },
9343212Sbostic 
9443212Sbostic "aint", 	{ INTRGEN, 2, 0 },
9543212Sbostic "dint", 	{ INTRSPEC, TYDREAL, 1 },
9643212Sbostic 
9743212Sbostic "anint", 	{ INTRGEN, 2, 2 },
9843212Sbostic "dnint", 	{ INTRSPEC, TYDREAL, 3 },
9943212Sbostic 
10043212Sbostic "nint", 	{ INTRGEN, 4, 4 },
10143212Sbostic "idnint", 	{ INTRGEN, 2, 6 },
10243212Sbostic 
10343212Sbostic "abs", 		{ INTRGEN, 6, 8 },
10443212Sbostic "iabs", 	{ INTRGEN, 2, 9 },
10543212Sbostic "dabs", 	{ INTRSPEC, TYDREAL, 11 },
10643212Sbostic "cabs", 	{ INTRSPEC, TYREAL, 12 },
10743212Sbostic "zabs", 	{ INTRSPEC, TYDREAL, 13 },
10843212Sbostic "cdabs",	{ INTRSPEC, TYDREAL, 13 },
10943212Sbostic 
11043212Sbostic "mod", 		{ INTRGEN, 4, 14 },
11143212Sbostic "amod", 	{ INTRSPEC, TYREAL, 16 },
11243212Sbostic "dmod", 	{ INTRSPEC, TYDREAL, 17 },
11343212Sbostic 
11443212Sbostic "sign", 	{ INTRGEN, 4, 18 },
11543212Sbostic "isign", 	{ INTRGEN, 2, 19 },
11643212Sbostic "dsign", 	{ INTRSPEC, TYDREAL, 21 },
11743212Sbostic 
11843212Sbostic "dim", 		{ INTRGEN, 4, 22 },
11943212Sbostic "idim", 	{ INTRGEN, 2, 23 },
12043212Sbostic "ddim", 	{ INTRSPEC, TYDREAL, 25 },
12143212Sbostic 
12243212Sbostic "dprod", 	{ INTRSPEC, TYDREAL, 26 },
12343212Sbostic 
12443212Sbostic "len", 		{ INTRSPEC, TYLONG, 27 },
12543212Sbostic "index", 	{ INTRSPEC, TYLONG, 29 },
12643212Sbostic 
12743212Sbostic "imag", 	{ INTRGEN, 2, 31 },
12843212Sbostic "aimag", 	{ INTRSPEC, TYREAL, 31 },
12943212Sbostic "dimag", 	{ INTRSPEC, TYDREAL, 32 },
13043212Sbostic 
13143212Sbostic "conjg", 	{ INTRGEN, 2, 33 },
13243212Sbostic "dconjg", 	{ INTRSPEC, TYDCOMPLEX, 34 },
13343212Sbostic 
13443212Sbostic "sqrt", 	{ INTRGEN, 4, 35 },
13543212Sbostic "dsqrt", 	{ INTRSPEC, TYDREAL, 36 },
13643212Sbostic "csqrt", 	{ INTRSPEC, TYCOMPLEX, 37 },
13743212Sbostic "zsqrt", 	{ INTRSPEC, TYDCOMPLEX, 38 },
13843212Sbostic "cdsqrt",	{ INTRSPEC, TYDCOMPLEX, 38 },
13943212Sbostic 
14043212Sbostic "exp", 		{ INTRGEN, 4, 39 },
14143212Sbostic "dexp", 	{ INTRSPEC, TYDREAL, 40 },
14243212Sbostic "cexp", 	{ INTRSPEC, TYCOMPLEX, 41 },
14343212Sbostic "zexp", 	{ INTRSPEC, TYDCOMPLEX, 42 },
14443212Sbostic "cdexp",	{ INTRSPEC, TYDCOMPLEX, 42 },
14543212Sbostic 
14643212Sbostic "log", 		{ INTRGEN, 4, 43 },
14743212Sbostic "alog", 	{ INTRSPEC, TYREAL, 43 },
14843212Sbostic "dlog", 	{ INTRSPEC, TYDREAL, 44 },
14943212Sbostic "clog", 	{ INTRSPEC, TYCOMPLEX, 45 },
15043212Sbostic "zlog", 	{ INTRSPEC, TYDCOMPLEX, 46 },
15143212Sbostic "cdlog",	{ INTRSPEC, TYDCOMPLEX, 46 },
15243212Sbostic 
15343212Sbostic "log10", 	{ INTRGEN, 2, 47 },
15443212Sbostic "alog10", 	{ INTRSPEC, TYREAL, 47 },
15543212Sbostic "dlog10", 	{ INTRSPEC, TYDREAL, 48 },
15643212Sbostic 
15743212Sbostic "sin", 		{ INTRGEN, 4, 49 },
15843212Sbostic "dsin", 	{ INTRSPEC, TYDREAL, 50 },
15943212Sbostic "csin", 	{ INTRSPEC, TYCOMPLEX, 51 },
16043212Sbostic "zsin", 	{ INTRSPEC, TYDCOMPLEX, 52 },
16143212Sbostic "cdsin",	{ INTRSPEC, TYDCOMPLEX, 52 },
16243212Sbostic 
16343212Sbostic "cos", 		{ INTRGEN, 4, 53 },
16443212Sbostic "dcos", 	{ INTRSPEC, TYDREAL, 54 },
16543212Sbostic "ccos", 	{ INTRSPEC, TYCOMPLEX, 55 },
16643212Sbostic "zcos", 	{ INTRSPEC, TYDCOMPLEX, 56 },
16743212Sbostic "cdcos",	{ INTRSPEC, TYDCOMPLEX, 56 },
16843212Sbostic 
16943212Sbostic "tan", 		{ INTRGEN, 2, 57 },
17043212Sbostic "dtan", 	{ INTRSPEC, TYDREAL, 58 },
17143212Sbostic 
17243212Sbostic "asin", 	{ INTRGEN, 2, 59 },
17343212Sbostic "dasin", 	{ INTRSPEC, TYDREAL, 60 },
17443212Sbostic 
17543212Sbostic "acos", 	{ INTRGEN, 2, 61 },
17643212Sbostic "dacos", 	{ INTRSPEC, TYDREAL, 62 },
17743212Sbostic 
17843212Sbostic "atan", 	{ INTRGEN, 2, 63 },
17943212Sbostic "datan", 	{ INTRSPEC, TYDREAL, 64 },
18043212Sbostic 
18143212Sbostic "atan2", 	{ INTRGEN, 2, 65 },
18243212Sbostic "datan2", 	{ INTRSPEC, TYDREAL, 66 },
18343212Sbostic 
18443212Sbostic "sinh", 	{ INTRGEN, 2, 67 },
18543212Sbostic "dsinh", 	{ INTRSPEC, TYDREAL, 68 },
18643212Sbostic 
18743212Sbostic "cosh", 	{ INTRGEN, 2, 69 },
18843212Sbostic "dcosh", 	{ INTRSPEC, TYDREAL, 70 },
18943212Sbostic 
19043212Sbostic "tanh", 	{ INTRGEN, 2, 71 },
19143212Sbostic "dtanh", 	{ INTRSPEC, TYDREAL, 72 },
19243212Sbostic 
19343212Sbostic "lge",		{ INTRSPEC, TYLOGICAL, 73},
19443212Sbostic "lgt",		{ INTRSPEC, TYLOGICAL, 75},
19543212Sbostic "lle",		{ INTRSPEC, TYLOGICAL, 77},
19643212Sbostic "llt",		{ INTRSPEC, TYLOGICAL, 79},
19743212Sbostic 
19843212Sbostic "epbase",	{ INTRCNST, 4, 0 },
19943212Sbostic "epprec",	{ INTRCNST, 4, 4 },
20043212Sbostic "epemin",	{ INTRCNST, 2, 8 },
20143212Sbostic "epemax",	{ INTRCNST, 2, 10 },
20243212Sbostic "eptiny",	{ INTRCNST, 2, 12 },
20343212Sbostic "ephuge",	{ INTRCNST, 4, 14 },
20443212Sbostic "epmrsp",	{ INTRCNST, 2, 18 },
20543212Sbostic 
20643212Sbostic "fpexpn",	{ INTRGEN, 4, 81 },
20743212Sbostic "fpabsp",	{ INTRGEN, 2, 85 },
20843212Sbostic "fprrsp",	{ INTRGEN, 2, 87 },
20943212Sbostic "fpfrac",	{ INTRGEN, 2, 89 },
21043212Sbostic "fpmake",	{ INTRGEN, 2, 91 },
21143212Sbostic "fpscal",	{ INTRGEN, 2, 93 },
21243212Sbostic 
21343212Sbostic "" };
21443212Sbostic 
21543212Sbostic 
21643212Sbostic LOCAL struct Specblock
21743212Sbostic 	{
21843212Sbostic 	char atype;
21943212Sbostic 	char rtype;
22043212Sbostic 	char nargs;
22143212Sbostic 	char spxname[XL];
22243212Sbostic 	char othername;	/* index into callbyvalue table */
22343212Sbostic 	} spectab[ ] =
22443212Sbostic {
22543212Sbostic 	{ TYREAL,TYREAL,1,"r_int" },
22643212Sbostic 	{ TYDREAL,TYDREAL,1,"d_int" },
22743212Sbostic 
22843212Sbostic 	{ TYREAL,TYREAL,1,"r_nint" },
22943212Sbostic 	{ TYDREAL,TYDREAL,1,"d_nint" },
23043212Sbostic 
23143212Sbostic 	{ TYREAL,TYSHORT,1,"h_nint" },
23243212Sbostic 	{ TYREAL,TYLONG,1,"i_nint" },
23343212Sbostic 
23443212Sbostic 	{ TYDREAL,TYSHORT,1,"h_dnnt" },
23543212Sbostic 	{ TYDREAL,TYLONG,1,"i_dnnt" },
23643212Sbostic 
23743212Sbostic 	{ TYREAL,TYREAL,1,"r_abs" },
23843212Sbostic 	{ TYSHORT,TYSHORT,1,"h_abs" },
23943212Sbostic 	{ TYLONG,TYLONG,1,"i_abs" },
24043212Sbostic 	{ TYDREAL,TYDREAL,1,"d_abs" },
24143212Sbostic 	{ TYCOMPLEX,TYREAL,1,"c_abs" },
24243212Sbostic 	{ TYDCOMPLEX,TYDREAL,1,"z_abs" },
24343212Sbostic 
24443212Sbostic 	{ TYSHORT,TYSHORT,2,"h_mod" },
24543212Sbostic 	{ TYLONG,TYLONG,2,"i_mod" },
24643212Sbostic 	{ TYREAL,TYREAL,2,"r_mod" },
24743212Sbostic 	{ TYDREAL,TYDREAL,2,"d_mod" },
24843212Sbostic 
24943212Sbostic 	{ TYREAL,TYREAL,2,"r_sign" },
25043212Sbostic 	{ TYSHORT,TYSHORT,2,"h_sign" },
25143212Sbostic 	{ TYLONG,TYLONG,2,"i_sign" },
25243212Sbostic 	{ TYDREAL,TYDREAL,2,"d_sign" },
25343212Sbostic 
25443212Sbostic 	{ TYREAL,TYREAL,2,"r_dim" },
25543212Sbostic 	{ TYSHORT,TYSHORT,2,"h_dim" },
25643212Sbostic 	{ TYLONG,TYLONG,2,"i_dim" },
25743212Sbostic 	{ TYDREAL,TYDREAL,2,"d_dim" },
25843212Sbostic 
25943212Sbostic 	{ TYREAL,TYDREAL,2,"d_prod" },
26043212Sbostic 
26143212Sbostic 	{ TYCHAR,TYSHORT,1,"h_len" },
26243212Sbostic 	{ TYCHAR,TYLONG,1,"i_len" },
26343212Sbostic 
26443212Sbostic 	{ TYCHAR,TYSHORT,2,"h_indx" },
26543212Sbostic 	{ TYCHAR,TYLONG,2,"i_indx" },
26643212Sbostic 
26743212Sbostic 	{ TYCOMPLEX,TYREAL,1,"r_imag" },
26843212Sbostic 	{ TYDCOMPLEX,TYDREAL,1,"d_imag" },
26943212Sbostic 	{ TYCOMPLEX,TYCOMPLEX,1,"r_cnjg" },
27043212Sbostic 	{ TYDCOMPLEX,TYDCOMPLEX,1,"d_cnjg" },
27143212Sbostic 
27243212Sbostic 	{ TYREAL,TYREAL,1,"r_sqrt", 14 },
27343212Sbostic 	{ TYDREAL,TYDREAL,1,"d_sqrt", 1 },
27443212Sbostic 	{ TYCOMPLEX,TYCOMPLEX,1,"c_sqrt" },
27543212Sbostic 	{ TYDCOMPLEX,TYDCOMPLEX,1,"z_sqrt" },
27643212Sbostic 
27743212Sbostic 	{ TYREAL,TYREAL,1,"r_exp", 15 },
27843212Sbostic 	{ TYDREAL,TYDREAL,1,"d_exp", 2 },
27943212Sbostic 	{ TYCOMPLEX,TYCOMPLEX,1,"c_exp" },
28043212Sbostic 	{ TYDCOMPLEX,TYDCOMPLEX,1,"z_exp" },
28143212Sbostic 
28243212Sbostic 	{ TYREAL,TYREAL,1,"r_log", 16 },
28343212Sbostic 	{ TYDREAL,TYDREAL,1,"d_log", 3 },
28443212Sbostic 	{ TYCOMPLEX,TYCOMPLEX,1,"c_log" },
28543212Sbostic 	{ TYDCOMPLEX,TYDCOMPLEX,1,"z_log" },
28643212Sbostic 
28743212Sbostic 	{ TYREAL,TYREAL,1,"r_lg10" },
28843212Sbostic 	{ TYDREAL,TYDREAL,1,"d_lg10" },
28943212Sbostic 
29043212Sbostic 	{ TYREAL,TYREAL,1,"r_sin", 17 },
29143212Sbostic 	{ TYDREAL,TYDREAL,1,"d_sin", 4 },
29243212Sbostic 	{ TYCOMPLEX,TYCOMPLEX,1,"c_sin" },
29343212Sbostic 	{ TYDCOMPLEX,TYDCOMPLEX,1,"z_sin" },
29443212Sbostic 
29543212Sbostic 	{ TYREAL,TYREAL,1,"r_cos", 18 },
29643212Sbostic 	{ TYDREAL,TYDREAL,1,"d_cos", 5 },
29743212Sbostic 	{ TYCOMPLEX,TYCOMPLEX,1,"c_cos" },
29843212Sbostic 	{ TYDCOMPLEX,TYDCOMPLEX,1,"z_cos" },
29943212Sbostic 
30043212Sbostic 	{ TYREAL,TYREAL,1,"r_tan" },
30143212Sbostic 	{ TYDREAL,TYDREAL,1,"d_tan", 6 },
30243212Sbostic 
30343212Sbostic 	{ TYREAL,TYREAL,1,"r_asin" },
30443212Sbostic 	{ TYDREAL,TYDREAL,1,"d_asin", 7 },
30543212Sbostic 
30643212Sbostic 	{ TYREAL,TYREAL,1,"r_acos" },
30743212Sbostic 	{ TYDREAL,TYDREAL,1,"d_acos", 8 },
30843212Sbostic 
30943212Sbostic 	{ TYREAL,TYREAL,1,"r_atan", 19 },
31043212Sbostic 	{ TYDREAL,TYDREAL,1,"d_atan", 9 },
31143212Sbostic 
31243212Sbostic 	{ TYREAL,TYREAL,2,"r_atn2" },
31343212Sbostic 	{ TYDREAL,TYDREAL,2,"d_atn2", 10 },
31443212Sbostic 
31543212Sbostic 	{ TYREAL,TYREAL,1,"r_sinh" },
31643212Sbostic 	{ TYDREAL,TYDREAL,1,"d_sinh", 11 },
31743212Sbostic 
31843212Sbostic 	{ TYREAL,TYREAL,1,"r_cosh" },
31943212Sbostic 	{ TYDREAL,TYDREAL,1,"d_cosh", 12 },
32043212Sbostic 
32143212Sbostic 	{ TYREAL,TYREAL,1,"r_tanh" },
32243212Sbostic 	{ TYDREAL,TYDREAL,1,"d_tanh", 13 },
32343212Sbostic 
32443212Sbostic 	{ TYCHAR,TYLOGICAL,2,"hl_ge" },
32543212Sbostic 	{ TYCHAR,TYLOGICAL,2,"l_ge" },
32643212Sbostic 
32743212Sbostic 	{ TYCHAR,TYLOGICAL,2,"hl_gt" },
32843212Sbostic 	{ TYCHAR,TYLOGICAL,2,"l_gt" },
32943212Sbostic 
33043212Sbostic 	{ TYCHAR,TYLOGICAL,2,"hl_le" },
33143212Sbostic 	{ TYCHAR,TYLOGICAL,2,"l_le" },
33243212Sbostic 
33343212Sbostic 	{ TYCHAR,TYLOGICAL,2,"hl_lt" },
33443212Sbostic 	{ TYCHAR,TYLOGICAL,2,"l_lt" },
33543212Sbostic 
33643212Sbostic 	{ TYREAL,TYSHORT,1,"hr_expn" },
33743212Sbostic 	{ TYREAL,TYLONG,1,"ir_expn" },
33843212Sbostic 	{ TYDREAL,TYSHORT,1,"hd_expn" },
33943212Sbostic 	{ TYDREAL,TYLONG,1,"id_expn" },
34043212Sbostic 
34143212Sbostic 	{ TYREAL,TYREAL,1,"r_absp" },
34243212Sbostic 	{ TYDREAL,TYDREAL,1,"d_absp" },
34343212Sbostic 
34443212Sbostic 	{ TYREAL,TYDREAL,1,"r_rrsp" },
34543212Sbostic 	{ TYDREAL,TYDREAL,1,"d_rrsp" },
34643212Sbostic 
34743212Sbostic 	{ TYREAL,TYREAL,1,"r_frac" },
34843212Sbostic 	{ TYDREAL,TYDREAL,1,"d_frac" },
34943212Sbostic 
35043212Sbostic 	{ TYREAL,TYREAL,2,"r_make" },
35143212Sbostic 	{ TYDREAL,TYDREAL,2,"d_make" },
35243212Sbostic 
35343212Sbostic 	{ TYREAL,TYREAL,2,"r_scal" },
35443212Sbostic 	{ TYDREAL,TYDREAL,2,"d_scal" }
35543212Sbostic } ;
35643212Sbostic 
35743212Sbostic LOCAL struct Incstblock
35843212Sbostic 	{
35943212Sbostic 	char atype;
36043212Sbostic 	char rtype;
36143212Sbostic 	char constno;
36243212Sbostic 	} consttab[ ] =
36343212Sbostic {
36443212Sbostic 	{ TYSHORT, TYLONG, 0 },
36543212Sbostic 	{ TYLONG, TYLONG, 1 },
36643212Sbostic 	{ TYREAL, TYLONG, 2 },
36743212Sbostic 	{ TYDREAL, TYLONG, 3 },
36843212Sbostic 
36943212Sbostic 	{ TYSHORT, TYLONG, 4 },
37043212Sbostic 	{ TYLONG, TYLONG, 5 },
37143212Sbostic 	{ TYREAL, TYLONG, 6 },
37243212Sbostic 	{ TYDREAL, TYLONG, 7 },
37343212Sbostic 
37443212Sbostic 	{ TYREAL, TYLONG, 8 },
37543212Sbostic 	{ TYDREAL, TYLONG, 9 },
37643212Sbostic 
37743212Sbostic 	{ TYREAL, TYLONG, 10 },
37843212Sbostic 	{ TYDREAL, TYLONG, 11 },
37943212Sbostic 
38043212Sbostic 	{ TYREAL, TYREAL, 0 },
38143212Sbostic 	{ TYDREAL, TYDREAL, 1 },
38243212Sbostic 
38343212Sbostic 	{ TYSHORT, TYLONG, 12 },
38443212Sbostic 	{ TYLONG, TYLONG, 13 },
38543212Sbostic 	{ TYREAL, TYREAL, 2 },
38643212Sbostic 	{ TYDREAL, TYDREAL, 3 },
38743212Sbostic 
38843212Sbostic 	{ TYREAL, TYREAL, 4 },
38943212Sbostic 	{ TYDREAL, TYDREAL, 5 }
39043212Sbostic };
39143212Sbostic 
39243212Sbostic /* For each machine, two arrays must be initialized.
39343212Sbostic intcon contains
39443212Sbostic 	radix for short int
39543212Sbostic 	radix for long int
39643212Sbostic 	radix for single precision
39743212Sbostic 	radix for double precision
39843212Sbostic 	precision for short int
39943212Sbostic 	precision for long int
40043212Sbostic 	precision for single precision
40143212Sbostic 	precision for double precision
40243212Sbostic 	emin for single precision
40343212Sbostic 	emin for double precision
40443212Sbostic 	emax for single precision
40543212Sbostic 	emax for double prcision
40643212Sbostic 	largest short int
40743212Sbostic 	largest long int
40843212Sbostic 
40943212Sbostic realcon contains
41043212Sbostic 	tiny for single precision
41143212Sbostic 	tiny for double precision
41243212Sbostic 	huge for single precision
41343212Sbostic 	huge for double precision
41443212Sbostic 	mrsp (epsilon) for single precision
41543212Sbostic 	mrsp (epsilon) for double precision
41643212Sbostic 
41743212Sbostic the realcons should probably be filled in in binary if TARGET==HERE
41843212Sbostic */
41943212Sbostic 
42043212Sbostic char callbyvalue[ ][XL] =
42143212Sbostic 	{
42243212Sbostic 	"sqrt",
42343212Sbostic 	"exp",
42443212Sbostic 	"log",
42543212Sbostic 	"sin",
42643212Sbostic 	"cos",
42743212Sbostic 	"tan",
42843212Sbostic 	"asin",
42943212Sbostic 	"acos",
43043212Sbostic 	"atan",
43143212Sbostic 	"atan2",
43243212Sbostic 	"sinh",
43343212Sbostic 	"cosh",
43443212Sbostic 	"tanh",
43543212Sbostic 	/* function opcodes */
43643212Sbostic 	"@sqrt",
43743212Sbostic 	"@exp",
43843212Sbostic 	"@log",
43943212Sbostic 	"@sin",
44043212Sbostic 	"@cos",
44143212Sbostic 	"@atan"
44243212Sbostic 	};
44343212Sbostic 
44443212Sbostic expptr intrcall(np, argsp, nargs)
44543212Sbostic Namep np;
44643212Sbostic struct Listblock *argsp;
44743212Sbostic int nargs;
44843212Sbostic {
44943212Sbostic int i, rettype;
45043212Sbostic Addrp ap;
45143212Sbostic register struct Specblock *sp;
45243212Sbostic register struct Chain *cp;
453*46304Sbostic expptr inlne(), mkcxcon(), mkrealcon();
45443212Sbostic register struct Incstblock *cstp;
45543212Sbostic expptr q, ep;
45643212Sbostic int mtype;
45743212Sbostic int op;
45843212Sbostic int f1field, f2field, f3field;
45943212Sbostic 
46043212Sbostic packed.ijunk = np->vardesc.varno;
46143212Sbostic f1field = packed.bits.f1;
46243212Sbostic f2field = packed.bits.f2;
46343212Sbostic f3field = packed.bits.f3;
46443212Sbostic if(nargs == 0)
46543212Sbostic 	goto badnargs;
46643212Sbostic 
46743212Sbostic mtype = 0;
46843212Sbostic for(cp = argsp->listp ; cp ; cp = cp->nextp)
46943212Sbostic 	{
47043212Sbostic /* TEMPORARY */ ep = (expptr) (cp->datap);
47143212Sbostic /* TEMPORARY */	if( ISCONST(ep) && ep->headblock.vtype==TYSHORT )
47243212Sbostic /* TEMPORARY */		cp->datap = (tagptr) mkconv(tyint, ep);
47343212Sbostic 	mtype = maxtype(mtype, ep->headblock.vtype);
47443212Sbostic 	}
47543212Sbostic 
47643212Sbostic switch(f1field)
47743212Sbostic 	{
47843212Sbostic 	case INTRBOOL:
47943212Sbostic 		op = f3field;
48043212Sbostic 		if( ! ONEOF(mtype, MSKINT|MSKLOGICAL) )
48143212Sbostic 			goto badtype;
48243212Sbostic 		if(op == OPBITNOT)
48343212Sbostic 			{
48443212Sbostic 			if(nargs != 1)
48543212Sbostic 				goto badnargs;
48643212Sbostic 			q = mkexpr(OPBITNOT, argsp->listp->datap, ENULL);
48743212Sbostic 			}
48843212Sbostic 		else
48943212Sbostic 			{
49043212Sbostic 			if(nargs != 2)
49143212Sbostic 				goto badnargs;
49243212Sbostic 			q = mkexpr(op, argsp->listp->datap,
49343212Sbostic 				argsp->listp->nextp->datap);
49443212Sbostic 			}
49543212Sbostic 		frchain( &(argsp->listp) );
49643212Sbostic 		free( (charptr) argsp);
49743212Sbostic 		return(q);
49843212Sbostic 
49943212Sbostic 	case INTRCONV:
50043212Sbostic 		if (nargs == 1)
50143212Sbostic 			{
50243212Sbostic 			if(argsp->listp->datap->headblock.vtype == TYERROR)
50343212Sbostic 				{
50443212Sbostic 				free( (charptr) argsp->listp->datap);
50543212Sbostic 				frchain( &(argsp->listp) );
50643212Sbostic 				free( (charptr) argsp);
50743212Sbostic 				return( errnode() );
50843212Sbostic 				}
50943212Sbostic 			}
51043212Sbostic 		else if (nargs == 2)
51143212Sbostic 			{
51243212Sbostic 			if(argsp->listp->nextp->datap->headblock.vtype ==
51343212Sbostic 				TYERROR ||
51443212Sbostic 				argsp->listp->datap->headblock.vtype == TYERROR)
51543212Sbostic 				{
51643212Sbostic 				free( (charptr) argsp->listp->nextp->datap);
51743212Sbostic 				free( (charptr) argsp->listp->datap);
51843212Sbostic 				frchain( &(argsp->listp) );
51943212Sbostic 				free( (charptr) argsp);
52043212Sbostic 				return( errnode() );
52143212Sbostic 				}
52243212Sbostic 			}
52343212Sbostic 		rettype = f2field;
52443212Sbostic 		if(rettype == TYLONG)
52543212Sbostic 			rettype = tyint;
52643212Sbostic 		if( ISCOMPLEX(rettype) && nargs==2)
52743212Sbostic 			{
52843212Sbostic 			expptr qr, qi;
52943212Sbostic 			qr = (expptr) (argsp->listp->datap);
53043212Sbostic 			qi = (expptr) (argsp->listp->nextp->datap);
53143212Sbostic 			if(ISCONST(qr) && ISCONST(qi))
53243212Sbostic 				q = mkcxcon(qr,qi);
53343212Sbostic 			else	q = mkexpr(OPCONV,intrconv(rettype-2,qr),
53443212Sbostic 					intrconv(rettype-2,qi));
53543212Sbostic 			}
53643212Sbostic 		else if(nargs == 1)
53743212Sbostic 			q = intrconv(rettype, argsp->listp->datap);
53843212Sbostic 		else goto badnargs;
53943212Sbostic 
54043212Sbostic 		q->headblock.vtype = rettype;
54143212Sbostic 		frchain(&(argsp->listp));
54243212Sbostic 		free( (charptr) argsp);
54343212Sbostic 		return(q);
54443212Sbostic 
54543212Sbostic 
54643212Sbostic 	case INTRCNST:
54743212Sbostic 		cstp = consttab + f3field;
54843212Sbostic 		for(i=0 ; i<f2field ; ++i)
54943212Sbostic 			if(cstp->atype == mtype)
55043212Sbostic 				goto foundconst;
55143212Sbostic 			else
55243212Sbostic 				++cstp;
55343212Sbostic 		goto badtype;
55443212Sbostic 
55543212Sbostic 	foundconst:
55643212Sbostic 		switch(cstp->rtype)
55743212Sbostic 			{
55843212Sbostic 			case TYLONG:
55943212Sbostic 				return(mkintcon(intcon[cstp->constno]));
56043212Sbostic 
56143212Sbostic 			case TYREAL:
56243212Sbostic 			case TYDREAL:
56343212Sbostic 				return(mkrealcon(cstp->rtype,
56443212Sbostic 					realcon[cstp->constno]) );
56543212Sbostic 
56643212Sbostic 			default:
56743212Sbostic 				fatal("impossible intrinsic constant");
56843212Sbostic 			}
56943212Sbostic 
57043212Sbostic 	case INTRGEN:
57143212Sbostic 		sp = spectab + f3field;
57243212Sbostic 		if(no66flag)
57343212Sbostic 			if(sp->atype == mtype)
57443212Sbostic 				goto specfunct;
57543212Sbostic 			else err66("generic function");
57643212Sbostic 
57743212Sbostic 		for(i=0; i<f2field ; ++i)
57843212Sbostic 			if(sp->atype == mtype)
57943212Sbostic 				goto specfunct;
58043212Sbostic 			else
58143212Sbostic 				++sp;
58243212Sbostic 		goto badtype;
58343212Sbostic 
58443212Sbostic 	case INTRSPEC:
58543212Sbostic 		sp = spectab + f3field;
58643212Sbostic 	specfunct:
58743212Sbostic 		if(tyint==TYLONG && ONEOF(sp->rtype,M(TYSHORT)|M(TYLOGICAL))
58843212Sbostic 			&& (sp+1)->atype==sp->atype)
58943212Sbostic 				++sp;
59043212Sbostic 
59143212Sbostic 		if(nargs != sp->nargs)
59243212Sbostic 			goto badnargs;
59343212Sbostic 		if(mtype != sp->atype)
59443212Sbostic 			goto badtype;
59543212Sbostic 		fixargs(YES, argsp);
596*46304Sbostic 		if(q = inlne(sp-spectab, mtype, argsp->listp))
59743212Sbostic 			{
59843212Sbostic 			frchain( &(argsp->listp) );
59943212Sbostic 			free( (charptr) argsp);
60043212Sbostic 			}
60143212Sbostic 		else if(sp->othername)
60243212Sbostic 			{
60343212Sbostic 			ap = builtin(sp->rtype,
60443212Sbostic 				varstr(XL, callbyvalue[sp->othername-1]) );
60543212Sbostic 			ap->vstg = STGINTR;
60643212Sbostic 			q = fixexpr( mkexpr(OPCCALL, ap, argsp) );
60743212Sbostic 			}
60843212Sbostic 		else
60943212Sbostic 			{
61043212Sbostic 			ap = builtin(sp->rtype, varstr(XL, sp->spxname) );
61143212Sbostic 			ap->vstg = STGINTR;
61243212Sbostic 			q = fixexpr( mkexpr(OPCALL, ap, argsp) );
61343212Sbostic 			}
61443212Sbostic 		return(q);
61543212Sbostic 
61643212Sbostic 	case INTRMIN:
61743212Sbostic 	case INTRMAX:
61843212Sbostic 		if(nargs < 2)
61943212Sbostic 			goto badnargs;
62043212Sbostic 		if( ! ONEOF(mtype, MSKINT|MSKREAL) )
62143212Sbostic 			goto badtype;
62243212Sbostic 		argsp->vtype = mtype;
62343212Sbostic 		q = mkexpr( (f1field==INTRMIN ? OPMIN : OPMAX), argsp, ENULL);
62443212Sbostic 
62543212Sbostic 		q->headblock.vtype = mtype;
62643212Sbostic 		rettype = f2field;
62743212Sbostic 		if(rettype == TYLONG)
62843212Sbostic 			rettype = tyint;
62943212Sbostic 		else if(rettype == TYUNKNOWN)
63043212Sbostic 			rettype = mtype;
63143212Sbostic 		return( intrconv(rettype, q) );
63243212Sbostic 
63343212Sbostic 	default:
63443212Sbostic 		fatali("intrcall: bad intrgroup %d", f1field);
63543212Sbostic 	}
63643212Sbostic badnargs:
63743212Sbostic 	errstr("bad number of arguments to intrinsic %s",
63843212Sbostic 		varstr(VL,np->varname) );
63943212Sbostic 	goto bad;
64043212Sbostic 
64143212Sbostic badtype:
64243212Sbostic 	errstr("bad argument type to intrinsic %s", varstr(VL, np->varname) );
64343212Sbostic 
64443212Sbostic bad:
64543212Sbostic 	return( errnode() );
64643212Sbostic }
64743212Sbostic 
64843212Sbostic 
64943212Sbostic 
65043212Sbostic 
65143212Sbostic intrfunct(s)
65243212Sbostic char s[VL];
65343212Sbostic {
65443212Sbostic register struct Intrblock *p;
65543212Sbostic char nm[VL];
65643212Sbostic register int i;
65743212Sbostic 
65843212Sbostic for(i = 0 ; i<VL ; ++s)
65943212Sbostic 	nm[i++] = (*s==' ' ? '\0' : *s);
66043212Sbostic 
66143212Sbostic for(p = intrtab; p->intrval.intrgroup!=INTREND ; ++p)
66243212Sbostic 	{
66343212Sbostic 	if( eqn(VL, nm, p->intrfname) )
66443212Sbostic 		{
66543212Sbostic 		packed.bits.f1 = p->intrval.intrgroup;
66643212Sbostic 		packed.bits.f2 = p->intrval.intrstuff;
66743212Sbostic 		packed.bits.f3 = p->intrval.intrno;
66843212Sbostic 		return(packed.ijunk);
66943212Sbostic 		}
67043212Sbostic 	}
67143212Sbostic 
67243212Sbostic return(0);
67343212Sbostic }
67443212Sbostic 
67543212Sbostic 
67643212Sbostic 
67743212Sbostic 
67843212Sbostic 
67943212Sbostic Addrp intraddr(np)
68043212Sbostic Namep np;
68143212Sbostic {
68243212Sbostic Addrp q;
68343212Sbostic register struct Specblock *sp;
68443212Sbostic int f3field;
68543212Sbostic 
68643212Sbostic if(np->vclass!=CLPROC || np->vprocclass!=PINTRINSIC)
68743212Sbostic 	fatalstr("intraddr: %s is not intrinsic", varstr(VL,np->varname));
68843212Sbostic packed.ijunk = np->vardesc.varno;
68943212Sbostic f3field = packed.bits.f3;
69043212Sbostic 
69143212Sbostic switch(packed.bits.f1)
69243212Sbostic 	{
69343212Sbostic 	case INTRGEN:
69443212Sbostic 		/* imag, log, and log10 arent specific functions */
69543212Sbostic 		if(f3field==31 || f3field==43 || f3field==47)
69643212Sbostic 			goto bad;
69743212Sbostic 
69843212Sbostic 	case INTRSPEC:
69943212Sbostic 		sp = spectab + f3field;
70043212Sbostic 		if(tyint==TYLONG && sp->rtype==TYSHORT)
70143212Sbostic 			++sp;
70243212Sbostic 		q = builtin(sp->rtype, varstr(XL,sp->spxname) );
70343212Sbostic 		q->vstg = STGINTR;
70443212Sbostic 		return(q);
70543212Sbostic 
70643212Sbostic 	case INTRCONV:
70743212Sbostic 	case INTRMIN:
70843212Sbostic 	case INTRMAX:
70943212Sbostic 	case INTRBOOL:
71043212Sbostic 	case INTRCNST:
71143212Sbostic 	bad:
71243212Sbostic 		errstr("cannot pass %s as actual",
71343212Sbostic 			varstr(VL,np->varname));
71443212Sbostic 		return( (Addrp) errnode() );
71543212Sbostic 	}
71643212Sbostic fatali("intraddr: impossible f1=%d\n", (int) packed.bits.f1);
71743212Sbostic /* NOTREACHED */
71843212Sbostic }
71943212Sbostic 
72043212Sbostic 
72143212Sbostic 
72243212Sbostic 
72343212Sbostic 
724*46304Sbostic expptr inlne(fno, type, args)
72543212Sbostic int fno;
72643212Sbostic int type;
72743212Sbostic struct Chain *args;
72843212Sbostic {
72943212Sbostic register expptr q, t, t1;
73043212Sbostic 
73143212Sbostic switch(fno)
73243212Sbostic 	{
73343212Sbostic 	case 8:	/* real abs */
73443212Sbostic 	case 9:	/* short int abs */
73543212Sbostic 	case 10:	/* long int abs */
73643212Sbostic 	case 11:	/* double precision abs */
73743212Sbostic 		if( addressable(q = (expptr) (args->datap)) )
73843212Sbostic 			{
73943212Sbostic 			t = q;
74043212Sbostic 			q = NULL;
74143212Sbostic 			}
74243212Sbostic 		else
74343212Sbostic 			t = (expptr) mktemp(type,PNULL);
74443212Sbostic 		t1 = mkexpr(OPQUEST,
74543212Sbostic 			mkexpr(OPLE, intrconv(type,ICON(0)), cpexpr(t)),
74643212Sbostic 			mkexpr(OPCOLON, cpexpr(t),
74743212Sbostic 				mkexpr(OPNEG, cpexpr(t), ENULL) ));
74843212Sbostic 		if(q)
74943212Sbostic 			t1 = mkexpr(OPCOMMA, mkexpr(OPASSIGN, cpexpr(t),q), t1);
75043212Sbostic 		frexpr(t);
75143212Sbostic 		return(t1);
75243212Sbostic 
75343212Sbostic 	case 26:	/* dprod */
75443212Sbostic 		q = mkexpr(OPSTAR, intrconv(TYDREAL,args->datap), args->nextp->datap);
75543212Sbostic 		return(q);
75643212Sbostic 
75743212Sbostic 	case 27:	/* len of character string */
75843212Sbostic 	case 28:
75943212Sbostic 		q = (expptr) cpexpr(args->datap->headblock.vleng);
76043212Sbostic 		frexpr(args->datap);
76143212Sbostic 		return(q);
76243212Sbostic 
76343212Sbostic 	case 14:	/* half-integer mod */
76443212Sbostic 	case 15:	/* mod */
76543212Sbostic 		return( mkexpr(OPMOD, (expptr) (args->datap),
76643212Sbostic 			(expptr) (args->nextp->datap) ));
76743212Sbostic 	}
76843212Sbostic return(NULL);
76943212Sbostic }
770