Quick Search:

Mode

Context

Displaying 3 lines of context. None | Less | More | Full

Other Diffs

Ignore

Blank Lines Whitespace: Expand:

Diff

1.261
 
1.262
 
MAIN:ragge:20090519192555
 
pftn.c
_>24872487                                 } else {
 24882488                                         MKTY(apole->node, arrt, 0, 0)
 24892489                                 }
<> 2490+#ifndef NO_COMPLEX
  2491+                        } else if (type == STRTY &&
  2492+                            gcc_get_attr(apole->node->n_sue, ATTR_COMPLEX) &&
  2493+                            gcc_get_attr(al[1].sue, ATTR_COMPLEX)) {
  2494+                                /* Both are complex */
  2495+                                if (apole->node->n_sue->suem->stype !=
  2496+                                    al[1].sue->suem->stype) {
  2497+                                        static NODE *mkcmplx(NODE *p, TWORD dt);
  2498+                                        /* must convert to correct type */
  2499+                                        w = talloc();
  2500+                                        *w = *apole->node;
  2501+                                        w = mkcmplx(w, al[1].sue->suem->stype);
  2502+                                        *apole->node = *w;
  2503+                                        nfree(w);
  2504+                                }
  2505+                                goto out;
  2506+#endif
24902507                         } else if (ISSOU(BTYPE(type))) {
 24912508                                 if (apole->node->n_sue->suem != al[1].sue->suem)
 24922509                                         goto incomp;
     
 !
30463063 }
 30473064 
 30483065 /*
<> 3066+ * Return the highest real floating point type.
  3067+ * Known that at least one type is complex or imaginary.
  3068+ */
  3069+static TWORD
  3070+maxtyp(NODE *l, NODE *r)
  3071+{
  3072+        TWORD tl, tr, t;
  3073+
  3074+#define ANYCX(p) (p->n_type == STRTY && gcc_get_attr(p->n_sue, ATTR_COMPLEX))
  3075+        tl = ANYCX(l) ? l->n_sue->suem->stype : l->n_type;
  3076+        tr = ANYCX(r) ? r->n_sue->suem->stype : r->n_type;
  3077+        if (ISITY(tl))
  3078+                tl -= (FIMAG - FLOAT);
  3079+        if (ISITY(tr))
  3080+                tr -= (FIMAG - FLOAT);
  3081+        t = tl > tr ? tl : tr;
  3082+        if (!ISFTY(t))
  3083+                cerror("maxtyp");
  3084+        return t;
  3085+}
  3086+
  3087+/*
  3088+ * Fetch space on stack for complex struct.
  3089+ */
  3090+static NODE *
  3091+cxstore(TWORD t)
  3092+{
  3093+        struct symtab s;
  3094+
  3095+        s = *cxsp[t - FLOAT];
  3096+        s.sclass = AUTO;
  3097+        s.soffset = NOOFFSET;
  3098+        oalloc(&s, &autooff);
  3099+        return nametree(&s);
  3100+}
  3101+
  3102+#define comop(x,y) buildtree(COMOP, x, y)
  3103+
  3104+static NODE *
  3105+mkcmplx(NODE *p, TWORD dt)
  3106+{
  3107+        NODE *q, *r, *i;
  3108+
  3109+        if (!ANYCX(p)) {
  3110+                /* Not complex, convert to complex on stack */
  3111+                q = cxstore(dt);
  3112+                if (ISITY(p->n_type)) {
  3113+                        p->n_type = p->n_type - FIMAG + FLOAT;
  3114+                        r = bcon(0);
  3115+                        i = p;
  3116+                } else {
  3117+                        r = p;
  3118+                        i = bcon(0);
  3119+                }
  3120+                p = buildtree(ASSIGN, structref(ccopy(q), DOT, real), r);
  3121+                p = comop(p, buildtree(ASSIGN, structref(ccopy(q), DOT, imag), i));
  3122+                p = comop(p, q);
  3123+        } else if (p->n_sue->suem->stype != dt) {
  3124+                q = cxstore(dt);
  3125+                /* XXX - left side side effects */
  3126+                r = buildtree(ASSIGN, structref(ccopy(q), DOT, real),
  3127+                    structref(ccopy(p), DOT, real));
  3128+                r = comop(r, buildtree(ASSIGN, structref(ccopy(q), DOT, imag),
  3129+                    structref(p, DOT, imag)));
  3130+                p = comop(r, q);
  3131+        }
  3132+        return p;
  3133+}
  3134+
  3135+static NODE *
  3136+cxasg(NODE *l, NODE *r)
  3137+{
  3138+
  3139+        if (ANYCX(l) && ANYCX(r) &&
  3140+            l->n_sue->suem->stype != r->n_sue->suem->stype) {
  3141+                /* different types in structs */
  3142+                r = mkcmplx(r, l->n_sue->suem->stype);
  3143+        } else if (!ANYCX(l))
  3144+                r = structref(r, DOT, ISITY(l->n_type) ? imag : real);
  3145+        else if (!ANYCX(r))
  3146+                r = mkcmplx(r, l->n_sue->suem->stype);
  3147+        return buildtree(ASSIGN, l, r);
  3148+}
  3149+
  3150+/*
30493151  * Fixup complex operations.
<> 3152+ * At least one operand is complex.
30503153  */
 30513154 NODE *
 30523155 cxop(int op, NODE *l, NODE *r)
 30533156 {
<>3054 -        struct symtab s;
 3055 -//      TWORD mxtyp = 0;
 3056 -//      struct glaha f;
  3157+        TWORD mxtyp;
30573158         NODE *p, *q;
 30583159         NODE *ltemp, *rtemp;
 30593160         NODE *real_l, *imag_l;
 30603161         NODE *real_r, *imag_r;
 30613162 
<>3062 -#if 0
 3063 -        mxtyp = maxcx(l, r);
 3064 -        /* Enxure that both sides are complex */
 3065 -#define ANYCX(p) (p->n_type == STRTY && gcc_get_attr(p->n_sue, ATTR_COMPLEX))
 3066 -        if (!ANYCX(l)) {
 3067 -                /* fixa plats p} stacken f|r en complex */
 3068 -                oalloc(...);
 3069 -                p1 = buildtree(CAST, TYPE(mxtyp), p2);
 3070 -        }
 3071 -        if (!ANYCX(r)) {
 3072 -                /* fixa plats p} stacken f|r en complex */
 3073 -                oalloc(...);
 3074 -                p1 = buildtree(CAST, TYPE(mxtyp), p2);
 3075 -        }
 3076 -#endif
  3163+        if (op == ASSIGN)
  3164+                return cxasg(l, r);
30773165 
<>3078 -#define comop(x,y) buildtree(COMOP, x, y)
  3166+        mxtyp = maxtyp(l, r);
  3167+        l = mkcmplx(l, mxtyp);
  3168+        r = mkcmplx(r, mxtyp);
  3169+
  3170+
30793171         /* put a pointer to left and right elements in a TEMP */
 30803172         l = buildtree(ADDROF, l, NIL);
 30813173         ltemp = tempnode(0, l->n_type, l->n_df, l->n_sue);
     
 !
30943186         imag_r = structref(rtemp, STREF, imag);
 30953187 
 30963188         /* get storage on stack for the result */
<>3097 -        s = *cxsp[1];
 3098 -        s.sclass = AUTO;
 3099 -        s.soffset = NOOFFSET;
 3100 -        oalloc(&s, &autooff);
 3101 -        q = nametree(&s);
  3189+        q = cxstore(mxtyp);
31023190 
 31033191         switch (op) {
 31043192         case PLUS:
     
 !
31503238         return comop(p, q);
 31513239 }
 31523240 
<> 3241+/*
  3242+ * Fixup imaginary operations.
  3243+ * At least one operand is imaginary, none is complex.
  3244+ */
  3245+NODE *
  3246+imop(int op, NODE *l, NODE *r)
  3247+{
  3248+        NODE *p, *q;
  3249+        TWORD mxtyp;
  3250+        int li, ri;
  3251+
  3252+        li = ri = 0;
  3253+        if (ISITY(l->n_type))
  3254+                li = 1, l->n_type = l->n_type - (FIMAG-FLOAT);
  3255+        if (ISITY(r->n_type))
  3256+                ri = 1, r->n_type = r->n_type - (FIMAG-FLOAT);
  3257+
  3258+        if (op == ASSIGN)
  3259+                cerror("imop ASSIGN");
  3260+
  3261+        mxtyp = maxtyp(l, r);
  3262+        switch (op) {
  3263+        case PLUS:
  3264+                if (li && ri) {
  3265+                        p = buildtree(PLUS, l, r);
  3266+                        p->n_type = p->n_type += (FIMAG-FLOAT);
  3267+                } else {
  3268+                        /* If one is imaginary and one is real, make complex */
  3269+                        if (li)
  3270+                                q = l, l = r, r = q; /* switch */
  3271+                        q = cxstore(mxtyp);
  3272+                        p = buildtree(ASSIGN,
  3273+                            structref(ccopy(q), DOT, real), l);
  3274+                        p = comop(p, buildtree(ASSIGN,
  3275+                            structref(ccopy(q), DOT, imag), r));
  3276+                        p = comop(p, q);
  3277+                }
  3278+                break;
  3279+
  3280+        case MINUS:
  3281+                if (li && ri) {
  3282+                        p = buildtree(MINUS, l, r);
  3283+                        p->n_type = p->n_type += (FIMAG-FLOAT);
  3284+                } else if (li) {
  3285+                        q = cxstore(mxtyp);
  3286+                        p = buildtree(ASSIGN, structref(ccopy(q), DOT, real),
  3287+                            buildtree(UMINUS, r, NIL));
  3288+                        p = comop(p, buildtree(ASSIGN,
  3289+                            structref(ccopy(q), DOT, imag), l));
  3290+                        p = comop(p, q);
  3291+                } else /* if (ri) */ {
  3292+                        q = cxstore(mxtyp);
  3293+                        p = buildtree(ASSIGN,
  3294+                            structref(ccopy(q), DOT, real), l);
  3295+                        p = comop(p, buildtree(ASSIGN,
  3296+                            structref(ccopy(q), DOT, imag),
  3297+                            buildtree(UMINUS, r, NIL)));
  3298+                        p = comop(p, q);
  3299+                }
  3300+                break;
  3301+
  3302+        case MUL:
  3303+                p = buildtree(MUL, l, r);
  3304+                if (li && ri)
  3305+                        p = buildtree(UMINUS, p, NIL);
  3306+                if (li ^ ri)
  3307+                        p->n_type = p->n_type += (FIMAG-FLOAT);
  3308+                break;
  3309+
  3310+        case DIV:
  3311+                p = buildtree(DIV, l, r);
  3312+                if (ri && !li)
  3313+                        p = buildtree(UMINUS, p, NIL);
  3314+                if (li ^ ri)
  3315+                        p->n_type = p->n_type += (FIMAG-FLOAT);
  3316+                break;
  3317+        }
  3318+        return p;
  3319+}
  3320+
  3321+NODE *
  3322+cxelem(int op, NODE *p)
  3323+{
  3324+
  3325+        if (ANYCX(p)) {
  3326+                p = structref(p, DOT, op == XREAL ? real : imag);
  3327+        } else if (op == XIMAG) {
  3328+                /* XXX  sanitycheck? */
  3329+                tfree(p);
  3330+                p = bcon(0);
  3331+        }
  3332+        return p;
  3333+}
  3334+
  3335+NODE *
  3336+cxconj(NODE *p)
  3337+{
  3338+        NODE *q, *r;
  3339+
  3340+        /* XXX side effects? */
  3341+        q = cxstore(p->n_sue->suem->stype);
  3342+        r = buildtree(ASSIGN, structref(ccopy(q), DOT, real),
  3343+            structref(ccopy(p), DOT, real));
  3344+        r = comop(r, buildtree(ASSIGN, structref(ccopy(q), DOT, imag),
  3345+            buildtree(UMINUS, structref(p, DOT, imag), NIL)));
  3346+        return comop(r, q);
  3347+}
  3348+
  3349+/*
  3350+ * Prepare for return.
  3351+ */
  3352+NODE *
  3353+cxret(NODE *p, NODE *q)
  3354+{
  3355+        /* XXX what if cast the other way? */
  3356+        return mkcmplx(p, q->n_sue->suem->stype);
  3357+}
<_31533358 #endif
FishEye: Open Source License registered to PCC.
Atlassian FishEye, CVS analysis. (Version:1.6.3 Build:build-336 2008-11-04) - Administration - Page generated 2014-12-26 11:47 +0100