/* Both parameters will already have been converted to the result type. */ GFC_COMPLEX_4 dot_product_c4 (gfc_array_c4 * a, gfc_array_c4 * b) { GFC_COMPLEX_4 *pa; GFC_COMPLEX_4 *pb; GFC_COMPLEX_4 res; index_type count; index_type astride; index_type bstride; assert (GFC_DESCRIPTOR_RANK (a) == 1 && GFC_DESCRIPTOR_RANK (b) == 1); if (a->dim[0].stride == 0) a->dim[0].stride = 1; if (b->dim[0].stride == 0) b->dim[0].stride = 1; astride = a->dim[0].stride; bstride = b->dim[0].stride; count = a->dim[0].ubound + 1 - a->dim[0].lbound; res = 0; pa = a->data; pb = b->data; while (count--) { res += __builtin_conjf (*pa) * *pb; pa += astride; pb += bstride; } return res; }
void foo (void) { _Complex float v[1], w; v[1] = 0.0f + 0.8fi; w = __builtin_conjf (v[1] * v[1]); }
int main (void) { /* For each type, test both runtime and compile time (constant folding) optimization. */ volatile float _Complex fc = 1.0F + 2.0iF; volatile double _Complex dc = 1.0 + 2.0i; volatile long double _Complex ldc = 1.0L + 2.0iL; /* Test floats. */ if (conjf (fc) != 1.0F - 2.0iF) abort (); if (__builtin_conjf (fc) != 1.0F - 2.0iF) abort (); if (conjf (1.0F + 2.0iF) != 1.0F - 2.0iF) link_failure (); if (__builtin_conjf (1.0F + 2.0iF) != 1.0F - 2.0iF) link_failure (); if (crealf (fc) != 1.0F) abort (); if (__builtin_crealf (fc) != 1.0F) abort (); if (crealf (1.0F + 2.0iF) != 1.0F) link_failure (); if (__builtin_crealf (1.0F + 2.0iF) != 1.0F) link_failure (); if (cimagf (fc) != 2.0F) abort (); if (__builtin_cimagf (fc) != 2.0F) abort (); if (cimagf (1.0F + 2.0iF) != 2.0F) link_failure (); if (__builtin_cimagf (1.0F + 2.0iF) != 2.0F) link_failure (); /* Test doubles. */ if (conj (dc) != 1.0 - 2.0i) abort (); if (__builtin_conj (dc) != 1.0 - 2.0i) abort (); if (conj (1.0 + 2.0i) != 1.0 - 2.0i) link_failure (); if (__builtin_conj (1.0 + 2.0i) != 1.0 - 2.0i) link_failure (); if (creal (dc) != 1.0) abort (); if (__builtin_creal (dc) != 1.0) abort (); if (creal (1.0 + 2.0i) != 1.0) link_failure (); if (__builtin_creal (1.0 + 2.0i) != 1.0) link_failure (); if (cimag (dc) != 2.0) abort (); if (__builtin_cimag (dc) != 2.0) abort (); if (cimag (1.0 + 2.0i) != 2.0) link_failure (); if (__builtin_cimag (1.0 + 2.0i) != 2.0) link_failure (); /* Test long doubles. */ if (conjl (ldc) != 1.0L - 2.0iL) abort (); if (__builtin_conjl (ldc) != 1.0L - 2.0iL) abort (); if (conjl (1.0L + 2.0iL) != 1.0L - 2.0iL) link_failure (); if (__builtin_conjl (1.0L + 2.0iL) != 1.0L - 2.0iL) link_failure (); if (creall (ldc) != 1.0L) abort (); if (__builtin_creall (ldc) != 1.0L) abort (); if (creall (1.0L + 2.0iL) != 1.0L) link_failure (); if (__builtin_creall (1.0L + 2.0iL) != 1.0L) link_failure (); if (cimagl (ldc) != 2.0L) abort (); if (__builtin_cimagl (ldc) != 2.0L) abort (); if (cimagl (1.0L + 2.0iL) != 2.0L) link_failure (); if (__builtin_cimagl (1.0L + 2.0iL) != 2.0L) link_failure (); exit (0); }