source
stringlengths
3
92
c
stringlengths
26
2.25M
LAGraph_cc_fastsv5a.c
//------------------------------------------------------------------------------ // LAGraph_cc_fastsv5a: connected components //------------------------------------------------------------------------------ /* LAGraph: graph algorithms based on GraphBLAS Copyright 2020 LAGraph Contributors. (see Contributors.txt for a full list of Contributors; see ContributionInstructions.txt for information on how you can Contribute to this project). All Rights Reserved. NO WARRANTY. THIS MATERIAL IS FURNISHED ON AN "AS-IS" BASIS. THE LAGRAPH CONTRIBUTORS MAKE NO WARRANTIES OF ANY KIND, EITHER EXPRESSED OR IMPLIED, AS TO ANY MATTER INCLUDING, BUT NOT LIMITED TO, WARRANTY OF FITNESS FOR PURPOSE OR MERCHANTABILITY, EXCLUSIVITY, OR RESULTS OBTAINED FROM USE OF THE MATERIAL. THE CONTRIBUTORS DO NOT MAKE ANY WARRANTY OF ANY KIND WITH RESPECT TO FREEDOM FROM PATENT, TRADEMARK, OR COPYRIGHT INFRINGEMENT. Released under a BSD license, please see the LICENSE file distributed with this Software or contact permission@sei.cmu.edu for full terms. Created, in part, with funding and support from the United States Government. (see Acknowledgments.txt file). This program includes and/or can make use of certain third party source code, object code, documentation and other files ("Third Party Software"). See LICENSE file for more details. */ /** * Code is based on the algorithm described in the following paper * Zhang, Azad, Hu. FastSV: FastSV: A Distributed-Memory Connected Component * Algorithm with Fast Convergence (SIAM PP20) * * Modified by Tim Davis, Texas A&M University **/ // The input matrix A must be symmetric. Self-edges (diagonal entries) are // OK, and are ignored. The values and type of A are ignored; just its // pattern is accessed. // The matrix A must have dimension 2^32 or less. If it is larger, use the // 64-bit version of this method instead. TODO combine the two versions into a // single user-callable code. #include "LAGraph.h" //------------------------------------------------------------------------------ // atomic_min_uint32: compute (*p) = min (*p, value), via atomic update //------------------------------------------------------------------------------ static inline void atomic_min_uint32 ( uint32_t *p, // input/output uint32_t value // input ) { uint32_t old, new ; do { // get the old value at (*p) // #pragma omp atomic read old = (*p) ; // compute the new minimum new = LAGRAPH_MIN (old, value) ; } while (!__sync_bool_compare_and_swap (p, old, new)) ; } //------------------------------------------------------------------------------ // Reduce_assign32: w (index) += src, using MIN as the "+=" accum operator //------------------------------------------------------------------------------ // mask = NULL, accumulator = GrB_MIN_UINT32, descriptor = NULL. // Duplicates are summed with the accumulator, which differs from how // GrB_assign works. GrB_assign states that the presence of duplicates results // in undefined behavior. SuiteSparse:GraphBLAS follows the MATLAB rule, which // discards all but the first of the duplicates. TODO: add this to GraphBLAS // as a variant of GrB_assign, either as GxB_assign_accum (or another name), // or as a GxB_* descriptor setting. #define LAGRAPH_FREE_ALL static GrB_Info Reduce_assign32 ( GrB_Vector *w_handle, // vector of size n, all entries present GrB_Vector *s_handle, // vector of size n, all entries present uint32_t *index, // array of size n GrB_Index n, int nthreads ) { GrB_Type w_type, s_type ; GrB_Index w_n, s_n, w_nvals, s_nvals, *w_i, *s_i ; uint32_t *w_x, *s_x ; LAGr_Vector_export (w_handle, &w_type, &w_n, &w_nvals, &w_i, (void **) &w_x, NULL) ; LAGr_Vector_export (s_handle, &s_type, &s_n, &s_nvals, &s_i, (void **) &s_x, NULL) ; #if 0 if (nthreads >= 4) { #pragma omp parallel for num_threads(nthreads) schedule(static) for (GrB_Index k = 0 ; k < n ; k++) { uint32_t i = index [k] ; atomic_min_uint32 (&(w_x [i]), s_x [k]) ; } } else #endif { // sequential version, to avoid atomics for (GrB_Index k = 0 ; k < n ; k++) { uint32_t i = index [k] ; w_x [i] = LAGRAPH_MIN (w_x [i], s_x [k]) ; } } LAGr_Vector_import (w_handle, w_type, w_n, w_nvals, &w_i, (void **) &w_x, NULL) ; LAGr_Vector_import (s_handle, s_type, s_n, s_nvals, &s_i, (void **) &s_x, NULL) ; return (GrB_SUCCESS) ; } #undef LAGRAPH_FREE_ALL #define LAGRAPH_FREE_ALL \ { \ LAGRAPH_FREE (I) ; \ LAGRAPH_FREE (V32) ; \ LAGr_free (&f) ; \ LAGr_free (&gp) ; \ LAGr_free (&mngp) ; \ LAGr_free (&gp_new) ; \ LAGr_free (&mod) ; \ } //------------------------------------------------------------------------------ // LAGraph_cc_fastsv5 //------------------------------------------------------------------------------ GrB_Info LAGraph_cc_fastsv5a ( GrB_Vector *result, // output: array of component identifiers GrB_Matrix *A, // input matrix // content remains the same, but pointer changes bool sanitize // if true, ensure A is symmetric ) { GrB_Info info ; uint32_t *V32 = NULL ; GrB_Index n, nnz, *I = NULL ; GrB_Vector f = NULL, gp_new = NULL, mngp = NULL, mod = NULL, gp = NULL ; GrB_Matrix S = NULL, T = NULL ; //-------------------------------------------------------------------------- // check inputs //-------------------------------------------------------------------------- LAGr_Matrix_nrows (&n, *A) ; LAGr_Matrix_nvals (&nnz, *A) ; if (n > UINT32_MAX) { LAGRAPH_ERROR ("problem too large; use 64-bit version instead", GrB_INVALID_VALUE) ; } #define FASTSV_SAMPLES 4 GxB_Format_Value format; LAGRAPH_OK (GxB_get (*A , GxB_FORMAT, &format)) ; bool sampling = (format == GxB_BY_ROW) && (n * FASTSV_SAMPLES * 2 < nnz); if (sanitize) { // S = A | A' LAGr_Matrix_new (&S, GrB_BOOL, n, n) ; LAGr_eWiseAdd (S, NULL, NULL, GrB_LOR, *A, *A, LAGraph_desc_otoo) ; } else { // Use the input as-is, and assume it is symmetric // LAGr_Matrix_dup (&S, A) ; S = *A; } //-------------------------------------------------------------------------- // initializations //-------------------------------------------------------------------------- // determine # of threads to use for Reduce_assign int nthreads_max = LAGraph_get_nthreads ( ) ; int nthreads = n / (1024*1024) ; nthreads = LAGRAPH_MIN (nthreads, nthreads_max) ; nthreads = LAGRAPH_MAX (nthreads, 1) ; // # of threads to use for typecast int nthreads2 = n / (64*1024) ; nthreads2 = LAGRAPH_MIN (nthreads2, nthreads_max) ; nthreads2 = LAGRAPH_MAX (nthreads2, 1) ; // vectors LAGr_Vector_new (&f, GrB_UINT32, n) ; LAGr_Vector_new (&gp_new, GrB_UINT32, n) ; LAGr_Vector_new (&mod, GrB_BOOL, n) ; // temporary arrays I = LAGraph_malloc (n, sizeof (GrB_Index)) ; V32 = LAGraph_malloc (n, sizeof (uint32_t)) ; // prepare vectors #pragma omp parallel for num_threads(nthreads2) schedule(static) for (GrB_Index i = 0 ; i < n ; i++) { I [i] = i ; V32 [i] = (uint32_t) i ; } LAGr_Vector_build (f, I, V32, n, GrB_PLUS_UINT32) ; LAGr_Vector_dup (&gp, f) ; LAGr_Vector_dup (&mngp, f) ; //-------------------------------------------------------------------------- // main computation //-------------------------------------------------------------------------- if (sampling) { GrB_Type type; GrB_Index nrows, ncols, nvals; int64_t nonempty; GrB_Index *Sp, *Sj; void *Sx; GxB_Matrix_export_CSR (&S, &type, &nrows, &ncols, &nvals, &nonempty, &Sp, &Sj, &Sx, NULL); GrB_Index *Tp = LAGraph_malloc (nrows+1, sizeof (GrB_Index)) ; GrB_Index *Tj = LAGraph_malloc (nvals, sizeof (GrB_Index)) ; void *Tx = LAGraph_malloc (nvals, 1) ; int *range = LAGraph_malloc (nthreads + 1, sizeof (int)) ; GrB_Index *count = LAGraph_malloc (nthreads + 1, sizeof (GrB_Index)) ; memset (count, 0, sizeof (GrB_Index) * (nthreads + 1)) ; range [0] = 0; for (int i = 0; i < nthreads; i++) range [i + 1] = range [i] + (n + i) / nthreads; #pragma omp parallel for num_threads(nthreads) schedule(static) for (int t = 0; t < nthreads; t++) { for (int i = range[t]; i < range[t + 1]; i++) { int deg = Sp [i + 1] - Sp [i]; count [t + 1] += LAGRAPH_MIN (FASTSV_SAMPLES, deg) ; } } for (int i = 0; i < nthreads; i++) count [i + 1] += count [i]; #pragma omp parallel for num_threads(nthreads) schedule(static) for (int t = 0; t < nthreads; t++) { GrB_Index p = count [t]; Tp [range [t]] = p; for (int i = range[t]; i < range[t + 1]; i++) { for (int j = 0; j < FASTSV_SAMPLES && Sp [i] + j < Sp [i + 1]; j++) Tj [p++] = Sj [Sp [i] + j]; Tp [i + 1] = p; } } GrB_Index t_nvals = Tp[nrows]; GxB_Matrix_import_CSR (&T, type, nrows, ncols, t_nvals, -1, &Tp, &Tj, &Tx, NULL); bool change = true; while (change) { // hooking & shortcutting LAGr_mxv (mngp, NULL, GrB_MIN_UINT32, GxB_MIN_SECOND_UINT32, T, gp, NULL) ; LAGRAPH_OK (Reduce_assign32 (&f, &mngp, V32, n, nthreads)) ; // old: // LAGr_eWiseMult (f, NULL, NULL, GrB_MIN_UINT32, f, mngp, NULL) ; // LAGr_eWiseMult (f, NULL, NULL, GrB_MIN_UINT32, f, gp, NULL) ; // new: LAGr_eWiseAdd (f, NULL, GrB_MIN_UINT32, GrB_MIN_UINT32, mngp, gp, NULL) ; // calculate grandparent LAGr_Vector_extractTuples (NULL, V32, &n, f) ; #pragma omp parallel for num_threads(nthreads2) schedule(static) for (uint32_t i = 0 ; i < n ; i++) { I [i] = (GrB_Index) V32 [i] ; } LAGr_extract (gp_new, NULL, NULL, f, I, n, NULL) ; // check termination LAGr_eWiseMult (mod, NULL, NULL, GrB_NE_UINT32, gp_new, gp, NULL) ; LAGr_reduce (&change, NULL, GxB_LOR_BOOL_MONOID, mod, NULL) ; // swap gp and gp_new GrB_Vector t = gp ; gp = gp_new ; gp_new = t ; } // find the most frequent component label in vector f through sampling const int P = 1024; int ht_key [P]; int ht_val [P]; memset(ht_key, -1, sizeof(int) * P); memset(ht_val, 0, sizeof(int) * P); for (int i = 0; i < 864; i++) { int x = V32[rand() % n]; int h = ((x << 4) + x) & 1023; while (ht_key [h] != -1 && ht_key [h] != x) h = (h + 23) & 1023; ht_key [h] = x; ht_val [h] += 1; } int key = -1, val = 0; for (int i = 0; i < P; i++) if (ht_val [i] > val) { key = ht_key [i]; val = ht_val [i]; } int64_t t_nonempty; GxB_Matrix_export_CSR (&T, &type, &nrows, &ncols, &t_nvals, &t_nonempty, &Tp, &Tj, &Tx, NULL); #pragma omp parallel for num_threads(nthreads) schedule(static) for (int t = 0; t < nthreads; t++) { GrB_Index ptr = Sp[range[t]]; for (int v = range[t]; v < range[t + 1]; v++) { int pv = V32 [v]; Tp [v] = ptr; if (pv != key) { for (GrB_Index i = Sp [v]; i < Sp [v + 1]; i++) { int u = Sj [i]; if (V32 [u] != key) Tj [ptr++] = u; } if (ptr - Tp[v] < Sp [v + 1] - Sp [v]) Tj [ptr++] = key; } } count[t] = ptr - Tp [range [t]]; } GrB_Index offset = 0; for (int i = 0; i < nthreads; i++) { memcpy(Tj + offset, Tj + Tp [range [i]], sizeof(GrB_Index) * count[i]); offset += count[i]; count[i] = offset - count[i]; } #pragma omp parallel for num_threads(nthreads) schedule(static) for (int t = 0; t < nthreads; t++) { GrB_Index ptr = Tp [range [t]]; for (int v = range[t]; v < range[t + 1]; v++) Tp [v] -= ptr - count[t]; } Tp [n] = offset; LAGRAPH_FREE (count); LAGRAPH_FREE (range); GxB_Matrix_import_CSR (&S, type, nrows, ncols, nvals, nonempty, &Sp, &Sj, &Sx, NULL); GxB_Matrix_import_CSR (&T, type, nrows, ncols, offset, -1, &Tp, &Tj, &Tx, NULL); } else { T = S; } LAGr_Matrix_nvals (&nnz, T); bool change = true; while (change && nnz > 0) { // hooking & shortcutting LAGr_mxv (mngp, NULL, GrB_MIN_UINT32, GxB_MIN_SECOND_UINT32, T, gp, NULL) ; LAGRAPH_OK (Reduce_assign32 (&f, &mngp, V32, n, nthreads)) ; // old: // LAGr_eWiseMult (f, NULL, NULL, GrB_MIN_UINT32, f, mngp, NULL) ; // LAGr_eWiseMult (f, NULL, NULL, GrB_MIN_UINT32, f, gp, NULL) ; // new: LAGr_eWiseAdd (f, NULL, GrB_MIN_UINT32, GrB_MIN_UINT32, mngp, gp, NULL); // calculate grandparent LAGr_Vector_extractTuples (NULL, V32, &n, f) ; #pragma omp parallel for num_threads(nthreads2) schedule(static) for (uint32_t i = 0 ; i < n ; i++) { I [i] = (GrB_Index) V32 [i] ; } LAGr_extract (gp_new, NULL, NULL, f, I, n, NULL) ; // check termination LAGr_eWiseMult (mod, NULL, NULL, GrB_NE_UINT32, gp_new, gp, NULL) ; LAGr_reduce (&change, NULL, GxB_LOR_BOOL_MONOID, mod, NULL) ; // swap gp and gp_new GrB_Vector t = gp ; gp = gp_new ; gp_new = t ; } //-------------------------------------------------------------------------- // free workspace and return result //-------------------------------------------------------------------------- *result = f ; f = NULL ; if (!sanitize) *A = S; else LAGr_free (&S) ; if (sampling) LAGr_free (&T) ; LAGRAPH_FREE_ALL ; return (GrB_SUCCESS) ; }
convolution_1x1_pack8.h
// Tencent is pleased to support the open source community by making ncnn available. // // Copyright (C) 2019 THL A29 Limited, a Tencent company. All rights reserved. // // Licensed under the BSD 3-Clause License (the "License"); you may not use this file except // in compliance with the License. You may obtain a copy of the License at // // https://opensource.org/licenses/BSD-3-Clause // // Unless required by applicable law or agreed to in writing, software distributed // under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR // CONDITIONS OF ANY KIND, either express or implied. See the License for the // specific language governing permissions and limitations under the License. static void conv1x1s1_sgemm_transform_kernel_pack8_avx(const Mat& kernel, Mat& weight_data_pack8, int num_input, int num_output) { // src = kw-kh-inch-outch // dst = 8b-8a-kw-kh-inch/8a-outch/8b Mat weight_data_r2 = kernel.reshape(1, num_input, num_output); weight_data_pack8.create(1, num_input / 8, num_output / 8, (size_t)4 * 64, 64); for (int q = 0; q + 7 < num_output; q += 8) { const Mat k0 = weight_data_r2.channel(q); const Mat k1 = weight_data_r2.channel(q + 1); const Mat k2 = weight_data_r2.channel(q + 2); const Mat k3 = weight_data_r2.channel(q + 3); const Mat k4 = weight_data_r2.channel(q + 4); const Mat k5 = weight_data_r2.channel(q + 5); const Mat k6 = weight_data_r2.channel(q + 6); const Mat k7 = weight_data_r2.channel(q + 7); Mat g0 = weight_data_pack8.channel(q / 8); for (int p = 0; p + 7 < num_input; p += 8) { const float* k00 = k0.row(p); const float* k01 = k0.row(p + 1); const float* k02 = k0.row(p + 2); const float* k03 = k0.row(p + 3); const float* k04 = k0.row(p + 4); const float* k05 = k0.row(p + 5); const float* k06 = k0.row(p + 6); const float* k07 = k0.row(p + 7); const float* k10 = k1.row(p); const float* k11 = k1.row(p + 1); const float* k12 = k1.row(p + 2); const float* k13 = k1.row(p + 3); const float* k14 = k1.row(p + 4); const float* k15 = k1.row(p + 5); const float* k16 = k1.row(p + 6); const float* k17 = k1.row(p + 7); const float* k20 = k2.row(p); const float* k21 = k2.row(p + 1); const float* k22 = k2.row(p + 2); const float* k23 = k2.row(p + 3); const float* k24 = k2.row(p + 4); const float* k25 = k2.row(p + 5); const float* k26 = k2.row(p + 6); const float* k27 = k2.row(p + 7); const float* k30 = k3.row(p); const float* k31 = k3.row(p + 1); const float* k32 = k3.row(p + 2); const float* k33 = k3.row(p + 3); const float* k34 = k3.row(p + 4); const float* k35 = k3.row(p + 5); const float* k36 = k3.row(p + 6); const float* k37 = k3.row(p + 7); const float* k40 = k4.row(p); const float* k41 = k4.row(p + 1); const float* k42 = k4.row(p + 2); const float* k43 = k4.row(p + 3); const float* k44 = k4.row(p + 4); const float* k45 = k4.row(p + 5); const float* k46 = k4.row(p + 6); const float* k47 = k4.row(p + 7); const float* k50 = k5.row(p); const float* k51 = k5.row(p + 1); const float* k52 = k5.row(p + 2); const float* k53 = k5.row(p + 3); const float* k54 = k5.row(p + 4); const float* k55 = k5.row(p + 5); const float* k56 = k5.row(p + 6); const float* k57 = k5.row(p + 7); const float* k60 = k6.row(p); const float* k61 = k6.row(p + 1); const float* k62 = k6.row(p + 2); const float* k63 = k6.row(p + 3); const float* k64 = k6.row(p + 4); const float* k65 = k6.row(p + 5); const float* k66 = k6.row(p + 6); const float* k67 = k6.row(p + 7); const float* k70 = k7.row(p); const float* k71 = k7.row(p + 1); const float* k72 = k7.row(p + 2); const float* k73 = k7.row(p + 3); const float* k74 = k7.row(p + 4); const float* k75 = k7.row(p + 5); const float* k76 = k7.row(p + 6); const float* k77 = k7.row(p + 7); float* g00 = g0.row(p / 8); g00[0] = k00[0]; g00[1] = k10[0]; g00[2] = k20[0]; g00[3] = k30[0]; g00[4] = k40[0]; g00[5] = k50[0]; g00[6] = k60[0]; g00[7] = k70[0]; g00 += 8; g00[0] = k01[0]; g00[1] = k11[0]; g00[2] = k21[0]; g00[3] = k31[0]; g00[4] = k41[0]; g00[5] = k51[0]; g00[6] = k61[0]; g00[7] = k71[0]; g00 += 8; g00[0] = k02[0]; g00[1] = k12[0]; g00[2] = k22[0]; g00[3] = k32[0]; g00[4] = k42[0]; g00[5] = k52[0]; g00[6] = k62[0]; g00[7] = k72[0]; g00 += 8; g00[0] = k03[0]; g00[1] = k13[0]; g00[2] = k23[0]; g00[3] = k33[0]; g00[4] = k43[0]; g00[5] = k53[0]; g00[6] = k63[0]; g00[7] = k73[0]; g00 += 8; g00[0] = k04[0]; g00[1] = k14[0]; g00[2] = k24[0]; g00[3] = k34[0]; g00[4] = k44[0]; g00[5] = k54[0]; g00[6] = k64[0]; g00[7] = k74[0]; g00 += 8; g00[0] = k05[0]; g00[1] = k15[0]; g00[2] = k25[0]; g00[3] = k35[0]; g00[4] = k45[0]; g00[5] = k55[0]; g00[6] = k65[0]; g00[7] = k75[0]; g00 += 8; g00[0] = k06[0]; g00[1] = k16[0]; g00[2] = k26[0]; g00[3] = k36[0]; g00[4] = k46[0]; g00[5] = k56[0]; g00[6] = k66[0]; g00[7] = k76[0]; g00 += 8; g00[0] = k07[0]; g00[1] = k17[0]; g00[2] = k27[0]; g00[3] = k37[0]; g00[4] = k47[0]; g00[5] = k57[0]; g00[6] = k67[0]; g00[7] = k77[0]; g00 += 8; } } } static void conv1x1s1_sgemm_pack8_avx(const Mat& bottom_blob, Mat& top_blob, const Mat& kernel, const Mat& _bias, const Option& opt) { int w = bottom_blob.w; int h = bottom_blob.h; int inch = bottom_blob.c; int outch = top_blob.c; size_t elemsize = bottom_blob.elemsize; int elempack = bottom_blob.elempack; const int size = w * h; const float* bias = _bias; // interleave Mat tmp(12, inch, size / 12 + (size % 12) / 8 + (size % 12 % 8) / 4 + (size % 12 % 4) / 2 + size % 12 % 2, elemsize, elempack, opt.workspace_allocator); { int nn_size = size / 12; int remain_size_start = nn_size * 12; #pragma omp parallel for num_threads(opt.num_threads) for (int ii = 0; ii < nn_size; ii++) { int i = ii * 12; const float* img0 = bottom_blob.channel(0); img0 += i * 8; float* tmpptr = tmp.channel(i / 12); for (int q = 0; q < inch; q++) { __m256 _r0 = _mm256_loadu_ps(img0); __m256 _r1 = _mm256_loadu_ps(img0 + 8); __m256 _r2 = _mm256_loadu_ps(img0 + 16); __m256 _r3 = _mm256_loadu_ps(img0 + 24); __m256 _r4 = _mm256_loadu_ps(img0 + 32); __m256 _r5 = _mm256_loadu_ps(img0 + 40); __m256 _r6 = _mm256_loadu_ps(img0 + 48); __m256 _r7 = _mm256_loadu_ps(img0 + 56); __m256 _r8 = _mm256_loadu_ps(img0 + 64); __m256 _r9 = _mm256_loadu_ps(img0 + 72); __m256 _r10 = _mm256_loadu_ps(img0 + 80); __m256 _r11 = _mm256_loadu_ps(img0 + 88); _mm256_storeu_ps(tmpptr, _r0); _mm256_storeu_ps(tmpptr + 8, _r1); _mm256_storeu_ps(tmpptr + 16, _r2); _mm256_storeu_ps(tmpptr + 24, _r3); _mm256_storeu_ps(tmpptr + 32, _r4); _mm256_storeu_ps(tmpptr + 40, _r5); _mm256_storeu_ps(tmpptr + 48, _r6); _mm256_storeu_ps(tmpptr + 56, _r7); _mm256_storeu_ps(tmpptr + 64, _r8); _mm256_storeu_ps(tmpptr + 72, _r9); _mm256_storeu_ps(tmpptr + 80, _r10); _mm256_storeu_ps(tmpptr + 88, _r11); tmpptr += 96; img0 += bottom_blob.cstep * 8; } } nn_size = (size - remain_size_start) >> 3; #pragma omp parallel for num_threads(opt.num_threads) for (int ii = 0; ii < nn_size; ii++) { int i = remain_size_start + ii * 8; const float* img0 = bottom_blob.channel(0); img0 += i * 8; float* tmpptr = tmp.channel(i / 12 + (i % 12) / 8); for (int q = 0; q < inch; q++) { __m256 _r0 = _mm256_loadu_ps(img0); __m256 _r1 = _mm256_loadu_ps(img0 + 8); __m256 _r2 = _mm256_loadu_ps(img0 + 16); __m256 _r3 = _mm256_loadu_ps(img0 + 24); __m256 _r4 = _mm256_loadu_ps(img0 + 32); __m256 _r5 = _mm256_loadu_ps(img0 + 40); __m256 _r6 = _mm256_loadu_ps(img0 + 48); __m256 _r7 = _mm256_loadu_ps(img0 + 56); _mm256_storeu_ps(tmpptr, _r0); _mm256_storeu_ps(tmpptr + 8, _r1); _mm256_storeu_ps(tmpptr + 16, _r2); _mm256_storeu_ps(tmpptr + 24, _r3); _mm256_storeu_ps(tmpptr + 32, _r4); _mm256_storeu_ps(tmpptr + 40, _r5); _mm256_storeu_ps(tmpptr + 48, _r6); _mm256_storeu_ps(tmpptr + 56, _r7); tmpptr += 64; img0 += bottom_blob.cstep * 8; } } remain_size_start += nn_size << 3; nn_size = (size - remain_size_start) >> 2; #pragma omp parallel for num_threads(opt.num_threads) for (int ii = 0; ii < nn_size; ii++) { int i = remain_size_start + ii * 4; const float* img0 = bottom_blob.channel(0); img0 += i * 8; float* tmpptr = tmp.channel(i / 12 + (i % 12) / 8 + (i % 12 % 8) / 4); for (int q = 0; q < inch; q++) { __m256 _r0 = _mm256_loadu_ps(img0); __m256 _r1 = _mm256_loadu_ps(img0 + 8); __m256 _r2 = _mm256_loadu_ps(img0 + 16); __m256 _r3 = _mm256_loadu_ps(img0 + 24); _mm256_storeu_ps(tmpptr, _r0); _mm256_storeu_ps(tmpptr + 8, _r1); _mm256_storeu_ps(tmpptr + 16, _r2); _mm256_storeu_ps(tmpptr + 24, _r3); tmpptr += 32; img0 += bottom_blob.cstep * 8; } } remain_size_start += nn_size << 2; nn_size = (size - remain_size_start) >> 1; #pragma omp parallel for num_threads(opt.num_threads) for (int ii = 0; ii < nn_size; ii++) { int i = remain_size_start + ii * 2; const float* img0 = bottom_blob.channel(0); img0 += i * 8; float* tmpptr = tmp.channel(i / 12 + (i % 12) / 8 + (i % 12 % 8) / 4 + (i % 12 % 4) / 2); for (int q = 0; q < inch; q++) { __m256 _r0 = _mm256_loadu_ps(img0); __m256 _r1 = _mm256_loadu_ps(img0 + 8); _mm256_storeu_ps(tmpptr, _r0); _mm256_storeu_ps(tmpptr + 8, _r1); tmpptr += 16; img0 += bottom_blob.cstep * 8; } } remain_size_start += nn_size << 1; #pragma omp parallel for num_threads(opt.num_threads) for (int i = remain_size_start; i < size; i++) { const float* img0 = bottom_blob.channel(0); img0 += i * 8; float* tmpptr = tmp.channel(i / 12 + (i % 12) / 8 + (i % 12 % 8) / 4 + (i % 12 % 4) / 2 + i % 12 % 2); for (int q = 0; q < inch; q++) { __m256 _r0 = _mm256_loadu_ps(img0); _mm256_storeu_ps(tmpptr, _r0); tmpptr += 8; img0 += bottom_blob.cstep * 8; } } } #pragma omp parallel for num_threads(opt.num_threads) for (int p = 0; p < outch; p++) { Mat out = top_blob.channel(p); __m256 _bias0 = bias ? _mm256_loadu_ps((const float*)bias + p * 8) : _mm256_set1_ps(0.f); float* outptr = out; int i = 0; for (; i + 11 < size; i += 12) { const float* tmpptr = tmp.channel(i / 12); __m256 _sum0 = _bias0; __m256 _sum1 = _bias0; __m256 _sum2 = _bias0; __m256 _sum3 = _bias0; __m256 _sum4 = _bias0; __m256 _sum5 = _bias0; __m256 _sum6 = _bias0; __m256 _sum7 = _bias0; __m256 _sum8 = _bias0; __m256 _sum9 = _bias0; __m256 _sum10 = _bias0; __m256 _sum11 = _bias0; const float* kptr = (const float*)kernel + p * inch * 64; for (int q = 0; q < inch; q++) { __m256 _w0 = _mm256_loadu_ps(kptr); __m256 _w1 = _mm256_loadu_ps(kptr + 8); __m256 _w2 = _mm256_loadu_ps(kptr + 16); __m256 _w3 = _mm256_loadu_ps(kptr + 24); __m256 _val00 = _mm256_broadcast_ss(tmpptr); __m256 _val01 = _mm256_broadcast_ss(tmpptr + 1); __m256 _val02 = _mm256_broadcast_ss(tmpptr + 2); __m256 _val03 = _mm256_broadcast_ss(tmpptr + 3); _mm256_comp_fmadd_ps4(_sum0, _w0, _w1, _w2, _w3, _val00, _val01, _val02, _val03); __m256 _w4 = _mm256_loadu_ps(kptr + 32); __m256 _w5 = _mm256_loadu_ps(kptr + 40); __m256 _w6 = _mm256_loadu_ps(kptr + 48); __m256 _w7 = _mm256_loadu_ps(kptr + 56); __m256 _val04 = _mm256_broadcast_ss(tmpptr + 4); __m256 _val05 = _mm256_broadcast_ss(tmpptr + 5); __m256 _val06 = _mm256_broadcast_ss(tmpptr + 6); __m256 _val07 = _mm256_broadcast_ss(tmpptr + 7); _mm256_comp_fmadd_ps4(_sum0, _w4, _w5, _w6, _w7, _val04, _val05, _val06, _val07); __m256 _val10 = _mm256_broadcast_ss(tmpptr + 8); __m256 _val11 = _mm256_broadcast_ss(tmpptr + 9); __m256 _val12 = _mm256_broadcast_ss(tmpptr + 10); __m256 _val13 = _mm256_broadcast_ss(tmpptr + 11); _mm256_comp_fmadd_ps4(_sum1, _w0, _w1, _w2, _w3, _val10, _val11, _val12, _val13); __m256 _val14 = _mm256_broadcast_ss(tmpptr + 12); __m256 _val15 = _mm256_broadcast_ss(tmpptr + 13); __m256 _val16 = _mm256_broadcast_ss(tmpptr + 14); __m256 _val17 = _mm256_broadcast_ss(tmpptr + 15); _mm256_comp_fmadd_ps4(_sum1, _w4, _w5, _w6, _w7, _val14, _val15, _val16, _val17); __m256 _val20 = _mm256_broadcast_ss(tmpptr + 16); __m256 _val21 = _mm256_broadcast_ss(tmpptr + 17); __m256 _val22 = _mm256_broadcast_ss(tmpptr + 18); __m256 _val23 = _mm256_broadcast_ss(tmpptr + 19); _mm256_comp_fmadd_ps4(_sum2, _w0, _w1, _w2, _w3, _val20, _val21, _val22, _val23); __m256 _val24 = _mm256_broadcast_ss(tmpptr + 20); __m256 _val25 = _mm256_broadcast_ss(tmpptr + 21); __m256 _val26 = _mm256_broadcast_ss(tmpptr + 22); __m256 _val27 = _mm256_broadcast_ss(tmpptr + 23); _mm256_comp_fmadd_ps4(_sum2, _w4, _w5, _w6, _w7, _val24, _val25, _val26, _val27); __m256 _val30 = _mm256_broadcast_ss(tmpptr + 24); __m256 _val31 = _mm256_broadcast_ss(tmpptr + 25); __m256 _val32 = _mm256_broadcast_ss(tmpptr + 26); __m256 _val33 = _mm256_broadcast_ss(tmpptr + 27); _mm256_comp_fmadd_ps4(_sum3, _w0, _w1, _w2, _w3, _val30, _val31, _val32, _val33); __m256 _val34 = _mm256_broadcast_ss(tmpptr + 28); __m256 _val35 = _mm256_broadcast_ss(tmpptr + 29); __m256 _val36 = _mm256_broadcast_ss(tmpptr + 30); __m256 _val37 = _mm256_broadcast_ss(tmpptr + 31); _mm256_comp_fmadd_ps4(_sum3, _w4, _w5, _w6, _w7, _val34, _val35, _val36, _val37); __m256 _val40 = _mm256_broadcast_ss(tmpptr + 32); __m256 _val41 = _mm256_broadcast_ss(tmpptr + 33); __m256 _val42 = _mm256_broadcast_ss(tmpptr + 34); __m256 _val43 = _mm256_broadcast_ss(tmpptr + 35); _mm256_comp_fmadd_ps4(_sum4, _w0, _w1, _w2, _w3, _val40, _val41, _val42, _val43); __m256 _val44 = _mm256_broadcast_ss(tmpptr + 36); __m256 _val45 = _mm256_broadcast_ss(tmpptr + 37); __m256 _val46 = _mm256_broadcast_ss(tmpptr + 38); __m256 _val47 = _mm256_broadcast_ss(tmpptr + 39); _mm256_comp_fmadd_ps4(_sum4, _w4, _w5, _w6, _w7, _val44, _val45, _val46, _val47); __m256 _val50 = _mm256_broadcast_ss(tmpptr + 40); __m256 _val51 = _mm256_broadcast_ss(tmpptr + 41); __m256 _val52 = _mm256_broadcast_ss(tmpptr + 42); __m256 _val53 = _mm256_broadcast_ss(tmpptr + 43); _mm256_comp_fmadd_ps4(_sum5, _w0, _w1, _w2, _w3, _val50, _val51, _val52, _val53); __m256 _val54 = _mm256_broadcast_ss(tmpptr + 44); __m256 _val55 = _mm256_broadcast_ss(tmpptr + 45); __m256 _val56 = _mm256_broadcast_ss(tmpptr + 46); __m256 _val57 = _mm256_broadcast_ss(tmpptr + 47); _mm256_comp_fmadd_ps4(_sum5, _w4, _w5, _w6, _w7, _val54, _val55, _val56, _val57); __m256 _val60 = _mm256_broadcast_ss(tmpptr + 48); __m256 _val61 = _mm256_broadcast_ss(tmpptr + 49); __m256 _val62 = _mm256_broadcast_ss(tmpptr + 50); __m256 _val63 = _mm256_broadcast_ss(tmpptr + 51); _mm256_comp_fmadd_ps4(_sum6, _w0, _w1, _w2, _w3, _val60, _val61, _val62, _val63); __m256 _val64 = _mm256_broadcast_ss(tmpptr + 52); __m256 _val65 = _mm256_broadcast_ss(tmpptr + 53); __m256 _val66 = _mm256_broadcast_ss(tmpptr + 54); __m256 _val67 = _mm256_broadcast_ss(tmpptr + 55); _mm256_comp_fmadd_ps4(_sum6, _w4, _w5, _w6, _w7, _val64, _val65, _val66, _val67); __m256 _val70 = _mm256_broadcast_ss(tmpptr + 56); __m256 _val71 = _mm256_broadcast_ss(tmpptr + 57); __m256 _val72 = _mm256_broadcast_ss(tmpptr + 58); __m256 _val73 = _mm256_broadcast_ss(tmpptr + 59); _mm256_comp_fmadd_ps4(_sum7, _w0, _w1, _w2, _w3, _val70, _val71, _val72, _val73); __m256 _val74 = _mm256_broadcast_ss(tmpptr + 60); __m256 _val75 = _mm256_broadcast_ss(tmpptr + 61); __m256 _val76 = _mm256_broadcast_ss(tmpptr + 62); __m256 _val77 = _mm256_broadcast_ss(tmpptr + 63); _mm256_comp_fmadd_ps4(_sum7, _w4, _w5, _w6, _w7, _val74, _val75, _val76, _val77); __m256 _val80 = _mm256_broadcast_ss(tmpptr + 64); __m256 _val81 = _mm256_broadcast_ss(tmpptr + 65); __m256 _val82 = _mm256_broadcast_ss(tmpptr + 66); __m256 _val83 = _mm256_broadcast_ss(tmpptr + 67); _mm256_comp_fmadd_ps4(_sum8, _w0, _w1, _w2, _w3, _val80, _val81, _val82, _val83); __m256 _val84 = _mm256_broadcast_ss(tmpptr + 68); __m256 _val85 = _mm256_broadcast_ss(tmpptr + 69); __m256 _val86 = _mm256_broadcast_ss(tmpptr + 70); __m256 _val87 = _mm256_broadcast_ss(tmpptr + 71); _mm256_comp_fmadd_ps4(_sum8, _w4, _w5, _w6, _w7, _val84, _val85, _val86, _val87); __m256 _val90 = _mm256_broadcast_ss(tmpptr + 72); __m256 _val91 = _mm256_broadcast_ss(tmpptr + 73); __m256 _val92 = _mm256_broadcast_ss(tmpptr + 74); __m256 _val93 = _mm256_broadcast_ss(tmpptr + 75); _mm256_comp_fmadd_ps4(_sum9, _w0, _w1, _w2, _w3, _val90, _val91, _val92, _val93); __m256 _val94 = _mm256_broadcast_ss(tmpptr + 76); __m256 _val95 = _mm256_broadcast_ss(tmpptr + 77); __m256 _val96 = _mm256_broadcast_ss(tmpptr + 78); __m256 _val97 = _mm256_broadcast_ss(tmpptr + 79); _mm256_comp_fmadd_ps4(_sum9, _w4, _w5, _w6, _w7, _val94, _val95, _val96, _val97); __m256 _val100 = _mm256_broadcast_ss(tmpptr + 80); __m256 _val101 = _mm256_broadcast_ss(tmpptr + 81); __m256 _val102 = _mm256_broadcast_ss(tmpptr + 82); __m256 _val103 = _mm256_broadcast_ss(tmpptr + 83); _mm256_comp_fmadd_ps4(_sum10, _w0, _w1, _w2, _w3, _val100, _val101, _val102, _val103); __m256 _val104 = _mm256_broadcast_ss(tmpptr + 84); __m256 _val105 = _mm256_broadcast_ss(tmpptr + 85); __m256 _val106 = _mm256_broadcast_ss(tmpptr + 86); __m256 _val107 = _mm256_broadcast_ss(tmpptr + 87); _mm256_comp_fmadd_ps4(_sum10, _w4, _w5, _w6, _w7, _val104, _val105, _val106, _val107); __m256 _val110 = _mm256_broadcast_ss(tmpptr + 88); __m256 _val111 = _mm256_broadcast_ss(tmpptr + 89); __m256 _val112 = _mm256_broadcast_ss(tmpptr + 90); __m256 _val113 = _mm256_broadcast_ss(tmpptr + 91); _mm256_comp_fmadd_ps4(_sum11, _w0, _w1, _w2, _w3, _val110, _val111, _val112, _val113); __m256 _val114 = _mm256_broadcast_ss(tmpptr + 92); __m256 _val115 = _mm256_broadcast_ss(tmpptr + 93); __m256 _val116 = _mm256_broadcast_ss(tmpptr + 94); __m256 _val117 = _mm256_broadcast_ss(tmpptr + 95); _mm256_comp_fmadd_ps4(_sum11, _w4, _w5, _w6, _w7, _val114, _val115, _val116, _val117); tmpptr += 96; kptr += 64; } _mm256_storeu_ps(outptr, _sum0); _mm256_storeu_ps(outptr + 8, _sum1); _mm256_storeu_ps(outptr + 16, _sum2); _mm256_storeu_ps(outptr + 24, _sum3); _mm256_storeu_ps(outptr + 32, _sum4); _mm256_storeu_ps(outptr + 40, _sum5); _mm256_storeu_ps(outptr + 48, _sum6); _mm256_storeu_ps(outptr + 56, _sum7); _mm256_storeu_ps(outptr + 64, _sum8); _mm256_storeu_ps(outptr + 72, _sum9); _mm256_storeu_ps(outptr + 80, _sum10); _mm256_storeu_ps(outptr + 88, _sum11); outptr += 96; } for (; i + 7 < size; i += 8) { float* tmpptr = tmp.channel(i / 12 + (i % 12) / 8); __m256 _sum0 = _bias0; __m256 _sum1 = _bias0; __m256 _sum2 = _bias0; __m256 _sum3 = _bias0; __m256 _sum4 = _bias0; __m256 _sum5 = _bias0; __m256 _sum6 = _bias0; __m256 _sum7 = _bias0; const float* kptr = (const float*)kernel + p * inch * 64; for (int q = 0; q < inch; q++) { __m256 _w0 = _mm256_loadu_ps(kptr); __m256 _w1 = _mm256_loadu_ps(kptr + 8); __m256 _w2 = _mm256_loadu_ps(kptr + 16); __m256 _w3 = _mm256_loadu_ps(kptr + 24); __m256 _w4 = _mm256_loadu_ps(kptr + 32); __m256 _w5 = _mm256_loadu_ps(kptr + 40); __m256 _w6 = _mm256_loadu_ps(kptr + 48); __m256 _w7 = _mm256_loadu_ps(kptr + 56); __m256 _val00 = _mm256_broadcast_ss(tmpptr); __m256 _val01 = _mm256_broadcast_ss(tmpptr + 1); __m256 _val02 = _mm256_broadcast_ss(tmpptr + 2); __m256 _val03 = _mm256_broadcast_ss(tmpptr + 3); __m256 _val04 = _mm256_broadcast_ss(tmpptr + 4); __m256 _val05 = _mm256_broadcast_ss(tmpptr + 5); __m256 _val06 = _mm256_broadcast_ss(tmpptr + 6); __m256 _val07 = _mm256_broadcast_ss(tmpptr + 7); __m256 _val10 = _mm256_broadcast_ss(tmpptr + 8); __m256 _val11 = _mm256_broadcast_ss(tmpptr + 9); __m256 _val12 = _mm256_broadcast_ss(tmpptr + 10); __m256 _val13 = _mm256_broadcast_ss(tmpptr + 11); __m256 _val14 = _mm256_broadcast_ss(tmpptr + 12); __m256 _val15 = _mm256_broadcast_ss(tmpptr + 13); __m256 _val16 = _mm256_broadcast_ss(tmpptr + 14); __m256 _val17 = _mm256_broadcast_ss(tmpptr + 15); _sum0 = _mm256_comp_fmadd_ps(_w0, _val00, _sum0); _sum0 = _mm256_comp_fmadd_ps(_w1, _val01, _sum0); _sum0 = _mm256_comp_fmadd_ps(_w2, _val02, _sum0); _sum0 = _mm256_comp_fmadd_ps(_w3, _val03, _sum0); _sum0 = _mm256_comp_fmadd_ps(_w4, _val04, _sum0); _sum0 = _mm256_comp_fmadd_ps(_w5, _val05, _sum0); _sum0 = _mm256_comp_fmadd_ps(_w6, _val06, _sum0); _sum0 = _mm256_comp_fmadd_ps(_w7, _val07, _sum0); _sum1 = _mm256_comp_fmadd_ps(_w0, _val10, _sum1); _sum1 = _mm256_comp_fmadd_ps(_w1, _val11, _sum1); _sum1 = _mm256_comp_fmadd_ps(_w2, _val12, _sum1); _sum1 = _mm256_comp_fmadd_ps(_w3, _val13, _sum1); _sum1 = _mm256_comp_fmadd_ps(_w4, _val14, _sum1); _sum1 = _mm256_comp_fmadd_ps(_w5, _val15, _sum1); _sum1 = _mm256_comp_fmadd_ps(_w6, _val16, _sum1); _sum1 = _mm256_comp_fmadd_ps(_w7, _val17, _sum1); __m256 _val20 = _mm256_broadcast_ss(tmpptr + 16); __m256 _val21 = _mm256_broadcast_ss(tmpptr + 17); __m256 _val22 = _mm256_broadcast_ss(tmpptr + 18); __m256 _val23 = _mm256_broadcast_ss(tmpptr + 19); __m256 _val24 = _mm256_broadcast_ss(tmpptr + 20); __m256 _val25 = _mm256_broadcast_ss(tmpptr + 21); __m256 _val26 = _mm256_broadcast_ss(tmpptr + 22); __m256 _val27 = _mm256_broadcast_ss(tmpptr + 23); __m256 _val30 = _mm256_broadcast_ss(tmpptr + 24); __m256 _val31 = _mm256_broadcast_ss(tmpptr + 25); __m256 _val32 = _mm256_broadcast_ss(tmpptr + 26); __m256 _val33 = _mm256_broadcast_ss(tmpptr + 27); __m256 _val34 = _mm256_broadcast_ss(tmpptr + 28); __m256 _val35 = _mm256_broadcast_ss(tmpptr + 29); __m256 _val36 = _mm256_broadcast_ss(tmpptr + 30); __m256 _val37 = _mm256_broadcast_ss(tmpptr + 31); _sum2 = _mm256_comp_fmadd_ps(_w0, _val20, _sum2); _sum2 = _mm256_comp_fmadd_ps(_w1, _val21, _sum2); _sum2 = _mm256_comp_fmadd_ps(_w2, _val22, _sum2); _sum2 = _mm256_comp_fmadd_ps(_w3, _val23, _sum2); _sum2 = _mm256_comp_fmadd_ps(_w4, _val24, _sum2); _sum2 = _mm256_comp_fmadd_ps(_w5, _val25, _sum2); _sum2 = _mm256_comp_fmadd_ps(_w6, _val26, _sum2); _sum2 = _mm256_comp_fmadd_ps(_w7, _val27, _sum2); _sum3 = _mm256_comp_fmadd_ps(_w0, _val30, _sum3); _sum3 = _mm256_comp_fmadd_ps(_w1, _val31, _sum3); _sum3 = _mm256_comp_fmadd_ps(_w2, _val32, _sum3); _sum3 = _mm256_comp_fmadd_ps(_w3, _val33, _sum3); _sum3 = _mm256_comp_fmadd_ps(_w4, _val34, _sum3); _sum3 = _mm256_comp_fmadd_ps(_w5, _val35, _sum3); _sum3 = _mm256_comp_fmadd_ps(_w6, _val36, _sum3); _sum3 = _mm256_comp_fmadd_ps(_w7, _val37, _sum3); __m256 _val40 = _mm256_broadcast_ss(tmpptr + 32); __m256 _val41 = _mm256_broadcast_ss(tmpptr + 33); __m256 _val42 = _mm256_broadcast_ss(tmpptr + 34); __m256 _val43 = _mm256_broadcast_ss(tmpptr + 35); __m256 _val44 = _mm256_broadcast_ss(tmpptr + 36); __m256 _val45 = _mm256_broadcast_ss(tmpptr + 37); __m256 _val46 = _mm256_broadcast_ss(tmpptr + 38); __m256 _val47 = _mm256_broadcast_ss(tmpptr + 39); __m256 _val50 = _mm256_broadcast_ss(tmpptr + 40); __m256 _val51 = _mm256_broadcast_ss(tmpptr + 41); __m256 _val52 = _mm256_broadcast_ss(tmpptr + 42); __m256 _val53 = _mm256_broadcast_ss(tmpptr + 43); __m256 _val54 = _mm256_broadcast_ss(tmpptr + 44); __m256 _val55 = _mm256_broadcast_ss(tmpptr + 45); __m256 _val56 = _mm256_broadcast_ss(tmpptr + 46); __m256 _val57 = _mm256_broadcast_ss(tmpptr + 47); _sum4 = _mm256_comp_fmadd_ps(_w0, _val40, _sum4); _sum4 = _mm256_comp_fmadd_ps(_w1, _val41, _sum4); _sum4 = _mm256_comp_fmadd_ps(_w2, _val42, _sum4); _sum4 = _mm256_comp_fmadd_ps(_w3, _val43, _sum4); _sum4 = _mm256_comp_fmadd_ps(_w4, _val44, _sum4); _sum4 = _mm256_comp_fmadd_ps(_w5, _val45, _sum4); _sum4 = _mm256_comp_fmadd_ps(_w6, _val46, _sum4); _sum4 = _mm256_comp_fmadd_ps(_w7, _val47, _sum4); _sum5 = _mm256_comp_fmadd_ps(_w0, _val50, _sum5); _sum5 = _mm256_comp_fmadd_ps(_w1, _val51, _sum5); _sum5 = _mm256_comp_fmadd_ps(_w2, _val52, _sum5); _sum5 = _mm256_comp_fmadd_ps(_w3, _val53, _sum5); _sum5 = _mm256_comp_fmadd_ps(_w4, _val54, _sum5); _sum5 = _mm256_comp_fmadd_ps(_w5, _val55, _sum5); _sum5 = _mm256_comp_fmadd_ps(_w6, _val56, _sum5); _sum5 = _mm256_comp_fmadd_ps(_w7, _val57, _sum5); __m256 _val60 = _mm256_broadcast_ss(tmpptr + 48); __m256 _val61 = _mm256_broadcast_ss(tmpptr + 49); __m256 _val62 = _mm256_broadcast_ss(tmpptr + 50); __m256 _val63 = _mm256_broadcast_ss(tmpptr + 51); __m256 _val64 = _mm256_broadcast_ss(tmpptr + 52); __m256 _val65 = _mm256_broadcast_ss(tmpptr + 53); __m256 _val66 = _mm256_broadcast_ss(tmpptr + 54); __m256 _val67 = _mm256_broadcast_ss(tmpptr + 55); __m256 _val70 = _mm256_broadcast_ss(tmpptr + 56); __m256 _val71 = _mm256_broadcast_ss(tmpptr + 57); __m256 _val72 = _mm256_broadcast_ss(tmpptr + 58); __m256 _val73 = _mm256_broadcast_ss(tmpptr + 59); __m256 _val74 = _mm256_broadcast_ss(tmpptr + 60); __m256 _val75 = _mm256_broadcast_ss(tmpptr + 61); __m256 _val76 = _mm256_broadcast_ss(tmpptr + 62); __m256 _val77 = _mm256_broadcast_ss(tmpptr + 63); _sum6 = _mm256_comp_fmadd_ps(_w0, _val60, _sum6); _sum6 = _mm256_comp_fmadd_ps(_w1, _val61, _sum6); _sum6 = _mm256_comp_fmadd_ps(_w2, _val62, _sum6); _sum6 = _mm256_comp_fmadd_ps(_w3, _val63, _sum6); _sum6 = _mm256_comp_fmadd_ps(_w4, _val64, _sum6); _sum6 = _mm256_comp_fmadd_ps(_w5, _val65, _sum6); _sum6 = _mm256_comp_fmadd_ps(_w6, _val66, _sum6); _sum6 = _mm256_comp_fmadd_ps(_w7, _val67, _sum6); _sum7 = _mm256_comp_fmadd_ps(_w0, _val70, _sum7); _sum7 = _mm256_comp_fmadd_ps(_w1, _val71, _sum7); _sum7 = _mm256_comp_fmadd_ps(_w2, _val72, _sum7); _sum7 = _mm256_comp_fmadd_ps(_w3, _val73, _sum7); _sum7 = _mm256_comp_fmadd_ps(_w4, _val74, _sum7); _sum7 = _mm256_comp_fmadd_ps(_w5, _val75, _sum7); _sum7 = _mm256_comp_fmadd_ps(_w6, _val76, _sum7); _sum7 = _mm256_comp_fmadd_ps(_w7, _val77, _sum7); tmpptr += 64; kptr += 64; } _mm256_storeu_ps(outptr, _sum0); _mm256_storeu_ps(outptr + 8, _sum1); _mm256_storeu_ps(outptr + 16, _sum2); _mm256_storeu_ps(outptr + 24, _sum3); _mm256_storeu_ps(outptr + 32, _sum4); _mm256_storeu_ps(outptr + 40, _sum5); _mm256_storeu_ps(outptr + 48, _sum6); _mm256_storeu_ps(outptr + 56, _sum7); outptr += 64; } for (; i + 3 < size; i += 4) { float* tmpptr = tmp.channel(i / 12 + (i % 12) / 8 + (i % 12 % 8) / 4); __m256 _sum0 = _bias0; __m256 _sum1 = _bias0; __m256 _sum2 = _bias0; __m256 _sum3 = _bias0; const float* kptr = (const float*)kernel + p * inch * 64; for (int q = 0; q < inch; q++) { __m256 _w0 = _mm256_loadu_ps(kptr); __m256 _w1 = _mm256_loadu_ps(kptr + 8); __m256 _w2 = _mm256_loadu_ps(kptr + 16); __m256 _w3 = _mm256_loadu_ps(kptr + 24); __m256 _w4 = _mm256_loadu_ps(kptr + 32); __m256 _w5 = _mm256_loadu_ps(kptr + 40); __m256 _w6 = _mm256_loadu_ps(kptr + 48); __m256 _w7 = _mm256_loadu_ps(kptr + 56); __m256 _val00 = _mm256_broadcast_ss(tmpptr); __m256 _val01 = _mm256_broadcast_ss(tmpptr + 1); __m256 _val02 = _mm256_broadcast_ss(tmpptr + 2); __m256 _val03 = _mm256_broadcast_ss(tmpptr + 3); __m256 _val04 = _mm256_broadcast_ss(tmpptr + 4); __m256 _val05 = _mm256_broadcast_ss(tmpptr + 5); __m256 _val06 = _mm256_broadcast_ss(tmpptr + 6); __m256 _val07 = _mm256_broadcast_ss(tmpptr + 7); __m256 _val10 = _mm256_broadcast_ss(tmpptr + 8); __m256 _val11 = _mm256_broadcast_ss(tmpptr + 9); __m256 _val12 = _mm256_broadcast_ss(tmpptr + 10); __m256 _val13 = _mm256_broadcast_ss(tmpptr + 11); __m256 _val14 = _mm256_broadcast_ss(tmpptr + 12); __m256 _val15 = _mm256_broadcast_ss(tmpptr + 13); __m256 _val16 = _mm256_broadcast_ss(tmpptr + 14); __m256 _val17 = _mm256_broadcast_ss(tmpptr + 15); _sum0 = _mm256_comp_fmadd_ps(_w0, _val00, _sum0); _sum0 = _mm256_comp_fmadd_ps(_w1, _val01, _sum0); _sum0 = _mm256_comp_fmadd_ps(_w2, _val02, _sum0); _sum0 = _mm256_comp_fmadd_ps(_w3, _val03, _sum0); _sum0 = _mm256_comp_fmadd_ps(_w4, _val04, _sum0); _sum0 = _mm256_comp_fmadd_ps(_w5, _val05, _sum0); _sum0 = _mm256_comp_fmadd_ps(_w6, _val06, _sum0); _sum0 = _mm256_comp_fmadd_ps(_w7, _val07, _sum0); _sum1 = _mm256_comp_fmadd_ps(_w0, _val10, _sum1); _sum1 = _mm256_comp_fmadd_ps(_w1, _val11, _sum1); _sum1 = _mm256_comp_fmadd_ps(_w2, _val12, _sum1); _sum1 = _mm256_comp_fmadd_ps(_w3, _val13, _sum1); _sum1 = _mm256_comp_fmadd_ps(_w4, _val14, _sum1); _sum1 = _mm256_comp_fmadd_ps(_w5, _val15, _sum1); _sum1 = _mm256_comp_fmadd_ps(_w6, _val16, _sum1); _sum1 = _mm256_comp_fmadd_ps(_w7, _val17, _sum1); __m256 _val20 = _mm256_broadcast_ss(tmpptr + 16); __m256 _val21 = _mm256_broadcast_ss(tmpptr + 17); __m256 _val22 = _mm256_broadcast_ss(tmpptr + 18); __m256 _val23 = _mm256_broadcast_ss(tmpptr + 19); __m256 _val24 = _mm256_broadcast_ss(tmpptr + 20); __m256 _val25 = _mm256_broadcast_ss(tmpptr + 21); __m256 _val26 = _mm256_broadcast_ss(tmpptr + 22); __m256 _val27 = _mm256_broadcast_ss(tmpptr + 23); __m256 _val30 = _mm256_broadcast_ss(tmpptr + 24); __m256 _val31 = _mm256_broadcast_ss(tmpptr + 25); __m256 _val32 = _mm256_broadcast_ss(tmpptr + 26); __m256 _val33 = _mm256_broadcast_ss(tmpptr + 27); __m256 _val34 = _mm256_broadcast_ss(tmpptr + 28); __m256 _val35 = _mm256_broadcast_ss(tmpptr + 29); __m256 _val36 = _mm256_broadcast_ss(tmpptr + 30); __m256 _val37 = _mm256_broadcast_ss(tmpptr + 31); _sum2 = _mm256_comp_fmadd_ps(_w0, _val20, _sum2); _sum2 = _mm256_comp_fmadd_ps(_w1, _val21, _sum2); _sum2 = _mm256_comp_fmadd_ps(_w2, _val22, _sum2); _sum2 = _mm256_comp_fmadd_ps(_w3, _val23, _sum2); _sum2 = _mm256_comp_fmadd_ps(_w4, _val24, _sum2); _sum2 = _mm256_comp_fmadd_ps(_w5, _val25, _sum2); _sum2 = _mm256_comp_fmadd_ps(_w6, _val26, _sum2); _sum2 = _mm256_comp_fmadd_ps(_w7, _val27, _sum2); _sum3 = _mm256_comp_fmadd_ps(_w0, _val30, _sum3); _sum3 = _mm256_comp_fmadd_ps(_w1, _val31, _sum3); _sum3 = _mm256_comp_fmadd_ps(_w2, _val32, _sum3); _sum3 = _mm256_comp_fmadd_ps(_w3, _val33, _sum3); _sum3 = _mm256_comp_fmadd_ps(_w4, _val34, _sum3); _sum3 = _mm256_comp_fmadd_ps(_w5, _val35, _sum3); _sum3 = _mm256_comp_fmadd_ps(_w6, _val36, _sum3); _sum3 = _mm256_comp_fmadd_ps(_w7, _val37, _sum3); tmpptr += 32; kptr += 64; } _mm256_storeu_ps(outptr, _sum0); _mm256_storeu_ps(outptr + 8, _sum1); _mm256_storeu_ps(outptr + 16, _sum2); _mm256_storeu_ps(outptr + 24, _sum3); outptr += 32; } for (; i + 1 < size; i += 2) { float* tmpptr = tmp.channel(i / 12 + (i % 12) / 8 + (i % 12 % 8) / 4 + (i % 12 % 4) / 2); __m256 _sum0 = _bias0; __m256 _sum1 = _bias0; const float* kptr = (const float*)kernel + p * inch * 64; for (int q = 0; q < inch; q++) { __m256 _val00 = _mm256_broadcast_ss(tmpptr); __m256 _val01 = _mm256_broadcast_ss(tmpptr + 1); __m256 _val02 = _mm256_broadcast_ss(tmpptr + 2); __m256 _val03 = _mm256_broadcast_ss(tmpptr + 3); __m256 _val04 = _mm256_broadcast_ss(tmpptr + 4); __m256 _val05 = _mm256_broadcast_ss(tmpptr + 5); __m256 _val06 = _mm256_broadcast_ss(tmpptr + 6); __m256 _val07 = _mm256_broadcast_ss(tmpptr + 7); __m256 _val10 = _mm256_broadcast_ss(tmpptr + 8); __m256 _val11 = _mm256_broadcast_ss(tmpptr + 9); __m256 _val12 = _mm256_broadcast_ss(tmpptr + 10); __m256 _val13 = _mm256_broadcast_ss(tmpptr + 11); __m256 _val14 = _mm256_broadcast_ss(tmpptr + 12); __m256 _val15 = _mm256_broadcast_ss(tmpptr + 13); __m256 _val16 = _mm256_broadcast_ss(tmpptr + 14); __m256 _val17 = _mm256_broadcast_ss(tmpptr + 15); __m256 _w0 = _mm256_loadu_ps(kptr); __m256 _w1 = _mm256_loadu_ps(kptr + 8); __m256 _w2 = _mm256_loadu_ps(kptr + 16); __m256 _w3 = _mm256_loadu_ps(kptr + 24); __m256 _w4 = _mm256_loadu_ps(kptr + 32); __m256 _w5 = _mm256_loadu_ps(kptr + 40); __m256 _w6 = _mm256_loadu_ps(kptr + 48); __m256 _w7 = _mm256_loadu_ps(kptr + 56); _sum0 = _mm256_comp_fmadd_ps(_w0, _val00, _sum0); _sum0 = _mm256_comp_fmadd_ps(_w1, _val01, _sum0); _sum0 = _mm256_comp_fmadd_ps(_w2, _val02, _sum0); _sum0 = _mm256_comp_fmadd_ps(_w3, _val03, _sum0); _sum0 = _mm256_comp_fmadd_ps(_w4, _val04, _sum0); _sum0 = _mm256_comp_fmadd_ps(_w5, _val05, _sum0); _sum0 = _mm256_comp_fmadd_ps(_w6, _val06, _sum0); _sum0 = _mm256_comp_fmadd_ps(_w7, _val07, _sum0); _sum1 = _mm256_comp_fmadd_ps(_w0, _val10, _sum1); _sum1 = _mm256_comp_fmadd_ps(_w1, _val11, _sum1); _sum1 = _mm256_comp_fmadd_ps(_w2, _val12, _sum1); _sum1 = _mm256_comp_fmadd_ps(_w3, _val13, _sum1); _sum1 = _mm256_comp_fmadd_ps(_w4, _val14, _sum1); _sum1 = _mm256_comp_fmadd_ps(_w5, _val15, _sum1); _sum1 = _mm256_comp_fmadd_ps(_w6, _val16, _sum1); _sum1 = _mm256_comp_fmadd_ps(_w7, _val17, _sum1); tmpptr += 16; kptr += 64; } _mm256_storeu_ps(outptr, _sum0); _mm256_storeu_ps(outptr + 8, _sum1); outptr += 16; } for (; i < size; i++) { float* tmpptr = tmp.channel(i / 12 + (i % 12) / 8 + (i % 12 % 8) / 4 + (i % 12 % 4) / 2 + i % 12 % 2); __m256 _sum = _bias0; const float* kptr = (const float*)kernel + p * inch * 64; for (int q = 0; q < inch; q++) { __m256 _val0 = _mm256_broadcast_ss(tmpptr); __m256 _val1 = _mm256_broadcast_ss(tmpptr + 1); __m256 _val2 = _mm256_broadcast_ss(tmpptr + 2); __m256 _val3 = _mm256_broadcast_ss(tmpptr + 3); __m256 _val4 = _mm256_broadcast_ss(tmpptr + 4); __m256 _val5 = _mm256_broadcast_ss(tmpptr + 5); __m256 _val6 = _mm256_broadcast_ss(tmpptr + 6); __m256 _val7 = _mm256_broadcast_ss(tmpptr + 7); __m256 _w0 = _mm256_loadu_ps(kptr); __m256 _w1 = _mm256_loadu_ps(kptr + 8); __m256 _w2 = _mm256_loadu_ps(kptr + 16); __m256 _w3 = _mm256_loadu_ps(kptr + 24); __m256 _w4 = _mm256_loadu_ps(kptr + 32); __m256 _w5 = _mm256_loadu_ps(kptr + 40); __m256 _w6 = _mm256_loadu_ps(kptr + 48); __m256 _w7 = _mm256_loadu_ps(kptr + 56); _sum = _mm256_comp_fmadd_ps(_w0, _val0, _sum); _sum = _mm256_comp_fmadd_ps(_w1, _val1, _sum); _sum = _mm256_comp_fmadd_ps(_w2, _val2, _sum); _sum = _mm256_comp_fmadd_ps(_w3, _val3, _sum); _sum = _mm256_comp_fmadd_ps(_w4, _val4, _sum); _sum = _mm256_comp_fmadd_ps(_w5, _val5, _sum); _sum = _mm256_comp_fmadd_ps(_w6, _val6, _sum); _sum = _mm256_comp_fmadd_ps(_w7, _val7, _sum); tmpptr += 8; kptr += 64; } _mm256_storeu_ps(outptr, _sum); outptr += 8; } } } static void conv1x1s2_pack8_avx(const Mat& bottom_blob, Mat& top_blob, const Mat& kernel, const Mat& _bias, const Option& opt) { int w = bottom_blob.w; int channels = bottom_blob.c; size_t elemsize = bottom_blob.elemsize; int elempack = bottom_blob.elempack; int outw = top_blob.w; int outh = top_blob.h; const int tailstep = (w - 2 * outw + w) * 8; Mat bottom_blob_shrinked; bottom_blob_shrinked.create(outw, outh, channels, elemsize, elempack, opt.workspace_allocator); #pragma omp parallel for num_threads(opt.num_threads) for (int p = 0; p < channels; p++) { const float* r0 = bottom_blob.channel(p); float* outptr = bottom_blob_shrinked.channel(p); for (int i = 0; i < outh; i++) { for (int j = 0; j < outw; j++) { __m256 _v = _mm256_loadu_ps(r0); _mm256_storeu_ps(outptr, _v); r0 += 16; outptr += 8; } r0 += tailstep; } } conv1x1s1_sgemm_pack8_avx(bottom_blob_shrinked, top_blob, kernel, _bias, opt); }
linear-1.c
int a[256]; __attribute__((noinline, noclone)) int f1 (int i) { #pragma omp parallel for linear (i: 4) for (int j = 16; j < 64; j++) { a[i] = j; i += 4; } return i; } __attribute__((noinline, noclone)) short int f2 (short int i, char k) { #pragma omp parallel for linear (i: k + 1) for (long j = 16; j < 64; j++) { a[i] = j; i += 4; } return i; } __attribute__((noinline, noclone)) long long int f3 (long long int i, long long int k) { #pragma omp parallel for linear (i: k) for (short j = 16; j < 64; j++) { a[i] = j; i += 4; } return i; } __attribute__((noinline, noclone)) int f4 (int i) { #pragma omp parallel for linear (i: 4) schedule(static, 3) for (int j = 16; j < 64; j++) { a[i] = j; i += 4; } return i; } __attribute__((noinline, noclone)) short int f5 (short int i, char k) { #pragma omp parallel for linear (i: k + 1) schedule(static, 5) for (long j = 16; j < 64; j++) { a[i] = j; i += 4; } return i; } __attribute__((noinline, noclone)) long long int f6 (long long int i, long long int k) { #pragma omp parallel for linear (i: k) schedule(static, 7) for (short j = 16; j < 64; j++) { a[i] = j; i += 4; } return i; } __attribute__((noinline, noclone)) int f7 (int i) { #pragma omp parallel for linear (i: 4) schedule(dynamic, 3) for (int j = 16; j < 64; j++) { a[i] = j; i += 4; } return i; } __attribute__((noinline, noclone)) short int f8 (short int i, char k) { #pragma omp parallel for linear (i: k + 1) schedule(dynamic, 5) for (long j = 16; j < 64; j++) { a[i] = j; i += 4; } return i; } __attribute__((noinline, noclone)) long long int f9 (long long int i, long long int k) { #pragma omp parallel for linear (i: k) schedule(dynamic, 7) for (short j = 16; j < 64; j++) { a[i] = j; i += 4; } return i; } __attribute__((noinline, noclone)) int f10 (int i, long step) { #pragma omp parallel for linear (i: 4) for (int j = 16; j < 112; j += step) { a[i] = j / 2 + 8; i += 4; } return i; } __attribute__((noinline, noclone)) short int f11 (short int i, char k, char step) { #pragma omp parallel for linear (i: k + 1) for (long j = 16; j < 112; j += step) { a[i] = j / 2 + 8; i += 4; } return i; } __attribute__((noinline, noclone)) long long int f12 (long long int i, long long int k, int step) { #pragma omp parallel for linear (i: k) for (short j = 16; j < 112; j += step) { a[i] = j / 2 + 8; i += 4; } return i; } __attribute__((noinline, noclone)) int f13 (int i, long long int step) { #pragma omp parallel for linear (i: 4) schedule(static, 3) for (int j = 16; j < 112; j += step) { a[i] = j / 2 + 8; i += 4; } return i; } __attribute__((noinline, noclone)) short int f14 (short int i, char k, int step) { #pragma omp parallel for linear (i: k + 1) schedule(static, 5) for (long j = 16; j < 112; j += step) { a[i] = j / 2 + 8; i += 4; } return i; } __attribute__((noinline, noclone)) long long int f15 (long long int i, long long int k, long int step) { #pragma omp parallel for linear (i: k) schedule(static, 7) for (short j = 16; j < 112; j += step) { a[i] = j / 2 + 8; i += 4; } return i; } __attribute__((noinline, noclone)) int f16 (int i, long long int step) { #pragma omp parallel for linear (i: 4) schedule(dynamic, 3) for (int j = 16; j < 112; j += step) { a[i] = j / 2 + 8; i += 4; } return i; } __attribute__((noinline, noclone)) short int f17 (short int i, char k, int step) { #pragma omp parallel for linear (i: k + 1) schedule(dynamic, 5) for (long j = 16; j < 112; j += step) { a[i] = j / 2 + 8; i += 4; } return i; } __attribute__((noinline, noclone)) long long int f18 (long long int i, long long int k, long int step) { #pragma omp parallel for linear (i: k) schedule(dynamic, 7) for (short j = 16; j < 112; j += step) { a[i] = j / 2 + 8; i += 4; } return i; } int main () { #define TEST(x) \ if (x != 8 + 48 * 4) \ __builtin_abort (); \ for (int i = 0; i < 256; i++) \ if (a[i] != (((i & 3) == 0 && i >= 8 \ && i < 8 + 48 * 4) \ ? ((i - 8) / 4) + 16 : 0)) \ __builtin_abort (); \ __builtin_memset (a, 0, sizeof (a)) TEST (f1 (8)); TEST (f2 (8, 3)); TEST (f3 (8LL, 4LL)); TEST (f4 (8)); TEST (f5 (8, 3)); TEST (f6 (8LL, 4LL)); TEST (f7 (8)); TEST (f8 (8, 3)); TEST (f9 (8LL, 4LL)); TEST (f10 (8, 2)); TEST (f11 (8, 3, 2)); TEST (f12 (8LL, 4LL, 2)); TEST (f13 (8, 2)); TEST (f14 (8, 3, 2)); TEST (f15 (8LL, 4LL, 2)); TEST (f16 (8, 2)); TEST (f17 (8, 3, 2)); TEST (f18 (8LL, 4LL, 2)); return 0; }
DistanceTableData.h
////////////////////////////////////////////////////////////////////////////////////// // This file is distributed under the University of Illinois/NCSA Open Source License. // See LICENSE file in top directory for details. // // Copyright (c) 2016 Jeongnim Kim and QMCPACK developers. // // File developed by: Jeremy McMinnis, jmcminis@gmail.com, University of Illinois at Urbana-Champaign // Jeongnim Kim, jeongnim.kim@gmail.com, University of Illinois at Urbana-Champaign // Jaron T. Krogel, krogeljt@ornl.gov, Oak Ridge National Laboratory // Mark A. Berrill, berrillma@ornl.gov, Oak Ridge National Laboratory // // File created by: Jeongnim Kim, jeongnim.kim@gmail.com, University of Illinois at Urbana-Champaign ////////////////////////////////////////////////////////////////////////////////////// #ifndef QMCPLUSPLUS_DISTANCETABLEDATAIMPL_H #define QMCPLUSPLUS_DISTANCETABLEDATAIMPL_H #include "Particle/ParticleSet.h" #include "OhmmsPETE/OhmmsVector.h" #include "OhmmsPETE/OhmmsMatrix.h" #include "CPU/SIMD/aligned_allocator.hpp" #include "OhmmsSoA/VectorSoaContainer.h" #include <limits> #include <bitset> namespace qmcplusplus { class ResourceCollection; /** @ingroup nnlist * @brief Abstract class to manage pair data between two ParticleSets. * * Each DistanceTableData object is fined by Source and Target of ParticleSet types. * */ class DistanceTableData { public: static constexpr unsigned DIM = OHMMS_DIM; using IndexType = QMCTraits::IndexType; using RealType = QMCTraits::RealType; using PosType = QMCTraits::PosType; using DistRow = Vector<RealType, aligned_allocator<RealType>>; using DisplRow = VectorSoaContainer<RealType, DIM>; protected: const ParticleSet* Origin; const int N_sources; const int N_targets; /**defgroup SoA data */ /*@{*/ /** distances_[i][j] , [N_targets][N_sources] * Note: Derived classes decide if it is a memory view or the actual storage * For derived AA, only the lower triangle (j<i) is defined and up-to-date after pbyp move. * The upper triangle is symmetric to the lower one only when the full table is evaluated from scratch. * Avoid using the upper triangle because we may change the code to only allocate the lower triangle part. * For derived AB, the full table is up-to-date after pbyp move */ std::vector<DistRow> distances_; /** displacements_[N_targets]x[3][N_sources] * Note: Derived classes decide if it is a memory view or the actual storage * displacements_[i][j] = r_A2[j] - r_A1[i], the opposite sign of AoS dr * For derived AA, A1=A2=A, only the lower triangle (j<i) is defined. * For derived AB, A1=A, A2=B, the full table is allocated. */ std::vector<DisplRow> displacements_; /** temp_r */ DistRow temp_r_; /** temp_dr */ DisplRow temp_dr_; /*@}*/ /** whether full table needs to be ready at anytime or not * Optimization can be implemented during forward PbyP move when the full table is not needed all the time. * DT consumers should know if full table is needed or not and request via addTable. */ bool need_full_table_; /** set to particle id after move() with prepare_old = true. -1 means not prepared. * It is intended only for safety checks, not for codepath selection. */ int old_prepared_elec_id; ///name of the table const std::string name_; public: ///constructor using source and target ParticleSet DistanceTableData(const ParticleSet& source, const ParticleSet& target) : Origin(&source), N_sources(source.getTotalNum()), N_targets(target.getTotalNum()), need_full_table_(false), old_prepared_elec_id(-1), name_(source.getName() + "_" + target.getName()) {} ///virutal destructor virtual ~DistanceTableData() = default; ///get need_full_table_ inline bool getFullTableNeeds() const { return need_full_table_; } ///set need_full_table_ inline void setFullTableNeeds(bool is_needed) { need_full_table_ = is_needed; } ///return the name of table inline const std::string& getName() const { return name_; } ///returns the reference the origin particleset const ParticleSet& origin() const { return *Origin; } ///returns the number of centers inline IndexType centers() const { return Origin->getTotalNum(); } ///returns the number of centers inline IndexType targets() const { return N_targets; } ///returns the number of source particles inline IndexType sources() const { return N_sources; } /** return full table distances */ const std::vector<DistRow>& getDistances() const { return distances_; } /** return full table displacements */ const std::vector<DisplRow>& getDisplacements() const { return displacements_; } /** return a row of distances for a given target particle */ const DistRow& getDistRow(int iel) const { return distances_[iel]; } /** return a row of displacements for a given target particle */ const DisplRow& getDisplRow(int iel) const { return displacements_[iel]; } /** return old distances set up by move() for optimized distance table consumers */ virtual const DistRow& getOldDists() const { APP_ABORT("DistanceTableData::getOldDists is used incorrectly! Contact developers on github."); return temp_r_; // dummy return to avoid compiler warning. } /** return old displacements set up by move() for optimized distance table consumers */ virtual const DisplRow& getOldDispls() const { APP_ABORT("DistanceTableData::getOldDispls is used incorrectly! Contact developers on github."); return temp_dr_; // dummy return to avoid compiler warning. } /** return the temporary distances when a move is proposed */ const DistRow& getTempDists() const { return temp_r_; } /** return the temporary displacements when a move is proposed */ const DisplRow& getTempDispls() const { return temp_dr_; } /** evaluate the full Distance Table * @param P the target particle set */ virtual void evaluate(ParticleSet& P) = 0; virtual void mw_evaluate(const RefVectorWithLeader<DistanceTableData>& dt_list, const RefVectorWithLeader<ParticleSet>& p_list) const { #pragma omp parallel for for (int iw = 0; iw < dt_list.size(); iw++) dt_list[iw].evaluate(p_list[iw]); } /** recompute multi walker internal data, recompute * @param dt_list the distance table batch * @param p_list the target particle set batch * @param recompute if true, must recompute. Otherwise, implementation dependent. */ virtual void mw_recompute(const RefVectorWithLeader<DistanceTableData>& dt_list, const RefVectorWithLeader<ParticleSet>& p_list, const std::vector<bool>& recompute) const { #pragma omp parallel for for (int iw = 0; iw < dt_list.size(); iw++) if (recompute[iw]) dt_list[iw].evaluate(p_list[iw]); } /** evaluate the temporary pair relations when a move is proposed * @param P the target particle set * @param rnew proposed new position * @param iat the particle to be moved * @param prepare_old if true, prepare (temporary) old distances and displacements for using getOldDists and getOldDispls functions in acceptMove. * * Note: some distance table consumers (WaveFunctionComponent) have optimized code paths which require prepare_old = true for accepting a move. * Drivers/Hamiltonians know whether moves will be accepted or not and manage this flag when calling ParticleSet::makeMoveXXX functions. */ virtual void move(const ParticleSet& P, const PosType& rnew, const IndexType iat = 0, bool prepare_old = true) = 0; virtual void mw_move(const RefVectorWithLeader<DistanceTableData>& dt_list, const RefVectorWithLeader<ParticleSet>& p_list, const std::vector<PosType>& rnew_list, const IndexType iat = 0, bool prepare_old = true) const { #pragma omp parallel for for (int iw = 0; iw < dt_list.size(); iw++) dt_list[iw].move(p_list[iw], rnew_list[iw], iat, prepare_old); } /** update the distance table by the pair relations from the temporal position. * Used when a move is accepted in regular mode * @param iat the particle with an accepted move */ virtual void update(IndexType jat) = 0; /** fill partially the distance table by the pair relations from the temporary or old particle position. * Used in forward mode when a move is reject * @param iat the particle with an accepted move * @param from_temp if true, copy from temp. if false, copy from old */ virtual void updatePartial(IndexType jat, bool from_temp) { if (from_temp) update(jat); } /** build a compact list of a neighbor for the iat source * @param iat source particle id * @param rcut cutoff radius * @param jid compressed index * @param dist compressed distance * @param displ compressed displacement * @return number of target particles within rcut */ virtual size_t get_neighbors(int iat, RealType rcut, int* restrict jid, RealType* restrict dist, PosType* restrict displ) const { return 0; } /** find the first nearest neighbor * @param iat source particle id * @param r distance * @param dr displacement * @param newpos if true, use the data in temp_r_ and temp_dr_ for the proposed move. * if false, use the data in distance_[iat] and displacements_[iat] * @return the id of the nearest particle, -1 not found */ virtual int get_first_neighbor(IndexType iat, RealType& r, PosType& dr, bool newpos) const { APP_ABORT("DistanceTableData::get_first_neighbor is not implemented in calling base class"); return 0; } inline void print(std::ostream& os) { APP_ABORT("DistanceTableData::print is not supported") //os << "Table " << Origin->getName() << std::endl; //for (int i = 0; i < r_m.size(); i++) // os << r_m[i] << " "; //os << std::endl; } /// initialize a shared resource and hand it to a collection virtual void createResource(ResourceCollection& collection) const {} /// acquire a shared resource from a collection virtual void acquireResource(ResourceCollection& collection, const RefVectorWithLeader<DistanceTableData>& dt_list) const {} /// return a shared resource to a collection virtual void releaseResource(ResourceCollection& collection, const RefVectorWithLeader<DistanceTableData>& dt_list) const {} }; } // namespace qmcplusplus #endif
ethereum_fmt_plug.c
/* * JtR format to crack password protected Ethereum Wallets. * * This software is Copyright (c) 2017, Dhiru Kholia <kholia at kth.se> and it * is hereby released to the general public under the following terms: * * Redistribution and use in source and binary forms, with or without * modification, are permitted. */ #if FMT_EXTERNS_H extern struct fmt_main fmt_ethereum; #elif FMT_REGISTERS_H john_register_one(&fmt_ethereum); #else #include <string.h> #ifdef _OPENMP #include <omp.h> #ifndef OMP_SCALE #define OMP_SCALE 16 // tuned on i7-6600U #endif #endif #include "arch.h" #include "misc.h" #include "common.h" #include "formats.h" #include "params.h" #include "options.h" #define PBKDF2_HMAC_SHA256_ALSO_INCLUDE_CTX 1 // hack, we can't use our simd pbkdf2 code for presale wallets because of varying salt #include "pbkdf2_hmac_sha256.h" #include "ethereum_common.h" #include "escrypt/crypto_scrypt.h" #include "KeccakHash.h" #include "aes.h" #include "jumbo.h" #include "memdbg.h" #define FORMAT_NAME "Ethereum Wallet" #define FORMAT_LABEL "ethereum" #ifdef SIMD_COEF_64 #define ALGORITHM_NAME "PBKDF2-SHA256/scrypt Keccak " SHA256_ALGORITHM_NAME #else #define ALGORITHM_NAME "PBKDF2-SHA256/scrypt Keccak 32/" ARCH_BITS_STR #endif #define BENCHMARK_COMMENT "" #define BENCHMARK_LENGTH -1 #define BINARY_SIZE 16 #define PLAINTEXT_LENGTH 125 #define SALT_SIZE sizeof(*cur_salt) #define BINARY_ALIGN sizeof(uint32_t) #define SALT_ALIGN sizeof(int) #ifdef SIMD_COEF_64 #define MIN_KEYS_PER_CRYPT SSE_GROUP_SZ_SHA256 #define MAX_KEYS_PER_CRYPT SSE_GROUP_SZ_SHA256 #else #define MIN_KEYS_PER_CRYPT 1 #define MAX_KEYS_PER_CRYPT 1 #endif static char (*saved_key)[PLAINTEXT_LENGTH + 1]; static uint32_t (*crypt_out)[BINARY_SIZE * 2 / sizeof(uint32_t)]; custom_salt *cur_salt; static void init(struct fmt_main *self) { #ifdef _OPENMP int omp_t = omp_get_num_threads(); self->params.min_keys_per_crypt *= omp_t; omp_t *= OMP_SCALE; self->params.max_keys_per_crypt *= omp_t; #endif saved_key = mem_calloc(sizeof(*saved_key), self->params.max_keys_per_crypt); crypt_out = mem_calloc(sizeof(*crypt_out), self->params.max_keys_per_crypt); } static void done(void) { MEM_FREE(saved_key); MEM_FREE(crypt_out); } static void set_salt(void *salt) { cur_salt = (custom_salt *)salt; } static void ethereum_set_key(char *key, int index) { strnzcpy(saved_key[index], key, PLAINTEXT_LENGTH + 1); } static char *get_key(int index) { return saved_key[index]; } static unsigned char *dpad = (unsigned char*)"\x02\x00\x00\x00\x00\x00\x00\x00"; static int crypt_all(int *pcount, struct db_salt *salt) { const int count = *pcount; int index = 0; #ifdef _OPENMP #pragma omp parallel for for (index = 0; index < count; index += MAX_KEYS_PER_CRYPT) #endif { unsigned char master[MAX_KEYS_PER_CRYPT][32]; int i; if (cur_salt->type == 0) { #ifdef SIMD_COEF_64 int lens[MAX_KEYS_PER_CRYPT]; unsigned char *pin[MAX_KEYS_PER_CRYPT], *pout[MAX_KEYS_PER_CRYPT]; for (i = 0; i < MAX_KEYS_PER_CRYPT; ++i) { lens[i] = strlen(saved_key[index+i]); pin[i] = (unsigned char*)saved_key[index+i]; pout[i] = master[i]; } pbkdf2_sha256_sse((const unsigned char**)pin, lens, cur_salt->salt, cur_salt->saltlen, cur_salt->iterations, pout, 32, 0); #else for (i = 0; i < MAX_KEYS_PER_CRYPT; ++i) pbkdf2_sha256((unsigned char *)saved_key[index+i], strlen(saved_key[index+i]), cur_salt->salt, cur_salt->saltlen, cur_salt->iterations, master[i], 32, 0); #endif } else if (cur_salt->type == 1) { for (i = 0; i < MAX_KEYS_PER_CRYPT; ++i) crypto_scrypt((unsigned char *)saved_key[index+i], strlen(saved_key[index+i]), cur_salt->salt, cur_salt->saltlen, cur_salt->N, cur_salt->r, cur_salt->p, master[i], 32); } else if (cur_salt->type == 2) { for (i = 0; i < MAX_KEYS_PER_CRYPT; ++i) pbkdf2_sha256((unsigned char *)saved_key[index+i], strlen(saved_key[index+i]), (unsigned char *)saved_key[index+i], strlen(saved_key[index+i]), 2000, master[i], 16, 0); } if (cur_salt->type == 0 || cur_salt->type == 1) { for (i = 0; i < MAX_KEYS_PER_CRYPT; ++i) { Keccak_HashInstance hash; Keccak_HashInitialize(&hash, 1088, 512, 256, 0x01); // delimitedSuffix is 0x06 for SHA-3, and 0x01 for Keccak Keccak_HashUpdate(&hash, master[i] + 16, 16 * 8); Keccak_HashUpdate(&hash, cur_salt->ct, cur_salt->ctlen * 8); Keccak_HashFinal(&hash, (unsigned char*)crypt_out[index+i]); } } else { for (i = 0; i < MAX_KEYS_PER_CRYPT; ++i) { AES_KEY akey; Keccak_HashInstance hash; unsigned char iv[16]; unsigned char seed[4096]; int padbyte; int datalen; AES_set_decrypt_key(master[i], 128, &akey); memcpy(iv, cur_salt->encseed, 16); AES_cbc_encrypt(cur_salt->encseed + 16, seed, cur_salt->eslen - 16, &akey, iv, AES_DECRYPT); if (check_pkcs_pad(seed, cur_salt->eslen - 16, 16) < 0) { memset(crypt_out[index+i], 0, BINARY_SIZE); continue; } padbyte = seed[cur_salt->eslen - 16 - 1]; datalen = cur_salt->eslen - 16 - padbyte; if (datalen < 0) { memset(crypt_out[index+i], 0, BINARY_SIZE); continue; } Keccak_HashInitialize(&hash, 1088, 512, 256, 0x01); Keccak_HashUpdate(&hash, seed, datalen * 8); Keccak_HashUpdate(&hash, dpad, 1 * 8); Keccak_HashFinal(&hash, (unsigned char*)crypt_out[index+i]); } } } return count; } static int cmp_all(void *binary, int count) { int index = 0; for (; index < count; index++) if (((uint32_t*)binary)[0] == crypt_out[index][0]) return 1; return 0; } static int cmp_one(void *binary, int index) { return !memcmp(binary, crypt_out[index], BINARY_SIZE); } static int cmp_exact(char *source, int index) { return 1; } struct fmt_main fmt_ethereum = { { FORMAT_LABEL, FORMAT_NAME, ALGORITHM_NAME, BENCHMARK_COMMENT, BENCHMARK_LENGTH, 0, PLAINTEXT_LENGTH, BINARY_SIZE, BINARY_ALIGN, SALT_SIZE, SALT_ALIGN, MIN_KEYS_PER_CRYPT, MAX_KEYS_PER_CRYPT, FMT_CASE | FMT_8_BIT | FMT_OMP | FMT_HUGE_INPUT, { "iteration count", }, { FORMAT_TAG }, ethereum_tests }, { init, done, fmt_default_reset, fmt_default_prepare, ethereum_common_valid, fmt_default_split, ethereum_get_binary, ethereum_common_get_salt, { ethereum_common_iteration_count, }, fmt_default_source, { fmt_default_binary_hash }, fmt_default_salt_hash, NULL, set_salt, ethereum_set_key, get_key, fmt_default_clear_keys, crypt_all, { fmt_default_get_hash }, cmp_all, cmp_one, cmp_exact } }; #endif /* plugin stanza */
reduction-1.c
#include <omp.h> #include <stdlib.h> int main (void) { int i = 0, j = 0, k = ~0; double d = 1.0; #pragma omp parallel num_threads(4) reduction(+:i) reduction(*:d) reduction(&:k) { if (i != 0 || d != 1.0 || k != ~0) #pragma omp atomic j |= 1; if (omp_get_num_threads () != 4) #pragma omp atomic j |= 2; i = omp_get_thread_num (); d = i + 1; k = ~(1 << (2 * i)); } if (j & 1) abort (); if ((j & 2) == 0) { if (i != (0 + 1 + 2 + 3)) abort (); if (d != (1.0 * 2.0 * 3.0 * 4.0)) abort (); if (k != (~0 ^ 0x55)) abort (); } return 0; }
polybench.c
/** * This version is stamped on May 10, 2016 * * Contact: * Louis-Noel Pouchet <pouchet.ohio-state.edu> * Tomofumi Yuki <tomofumi.yuki.fr> * * Web address: http://polybench.sourceforge.net */ /* polybench.c: this file is part of PolyBench/C */ #include <stdio.h> #include <string.h> #include <stdlib.h> #include <unistd.h> #include <assert.h> #include <time.h> #include <sys/time.h> #include <sys/resource.h> #include <sched.h> #include <math.h> #ifdef _OPENMP # include <omp.h> #endif #include "polybench.h" /* By default, collect PAPI counters on thread 0. */ #ifndef POLYBENCH_THREAD_MONITOR # define POLYBENCH_THREAD_MONITOR 0 #endif /* Total LLC cache size. By default 32+MB.. */ #ifndef POLYBENCH_CACHE_SIZE_KB # define POLYBENCH_CACHE_SIZE_KB 32770 #endif int polybench_papi_counters_threadid = POLYBENCH_THREAD_MONITOR; double polybench_program_total_flops = 0; #ifdef POLYBENCH_PAPI # include <papi.h> # define POLYBENCH_MAX_NB_PAPI_COUNTERS 96 char* _polybench_papi_eventlist[] = { #include "papi_counters.list" NULL }; int polybench_papi_eventset; int polybench_papi_eventlist[POLYBENCH_MAX_NB_PAPI_COUNTERS]; long_long polybench_papi_values[POLYBENCH_MAX_NB_PAPI_COUNTERS]; #endif /* * Allocation table, to enable inter-array padding. All data allocated * with polybench_alloc_data should be freed with polybench_free_data. * */ #define NB_INITIAL_TABLE_ENTRIES 512 struct polybench_data_ptrs { void** user_view; void** real_ptr; int nb_entries; int nb_avail_entries; }; static struct polybench_data_ptrs* _polybench_alloc_table = NULL; static size_t polybench_inter_array_padding_sz = 0; /* Timer code (gettimeofday). */ double polybench_t_start, polybench_t_end; /* Timer code (RDTSC). */ unsigned long long int polybench_c_start, polybench_c_end; static double rtclock() { #if defined(POLYBENCH_TIME) || defined(POLYBENCH_GFLOPS) struct timeval Tp; int stat; stat = gettimeofday (&Tp, NULL); if (stat != 0) printf ("Error return from gettimeofday: %d", stat); return (Tp.tv_sec + Tp.tv_usec * 1.0e-6); #else return 0; #endif } #ifdef POLYBENCH_CYCLE_ACCURATE_TIMER static unsigned long long int rdtsc() { unsigned long long int ret = 0; unsigned int cycles_lo; unsigned int cycles_hi; __asm__ volatile ("RDTSC" : "=a" (cycles_lo), "=d" (cycles_hi)); ret = (unsigned long long int)cycles_hi << 32 | cycles_lo; return ret; } #endif void polybench_flush_cache() { int cs = POLYBENCH_CACHE_SIZE_KB * 1024 / sizeof(double); double* flush = (double*) calloc (cs, sizeof(double)); int i; double tmp = 0.0; #ifdef _OPENMP #pragma omp parallel for reduction(+:tmp) private(i) #endif for (i = 0; i < cs; i++) tmp += flush[i]; assert (tmp <= 10.0); free (flush); } #ifdef POLYBENCH_LINUX_FIFO_SCHEDULER void polybench_linux_fifo_scheduler() { /* Use FIFO scheduler to limit OS interference. Program must be run as root, and this works only for Linux kernels. */ struct sched_param schedParam; schedParam.sched_priority = sched_get_priority_max (SCHED_FIFO); sched_setscheduler (0, SCHED_FIFO, &schedParam); } void polybench_linux_standard_scheduler() { /* Restore to standard scheduler policy. */ struct sched_param schedParam; schedParam.sched_priority = sched_get_priority_max (SCHED_OTHER); sched_setscheduler (0, SCHED_OTHER, &schedParam); } #endif #ifdef POLYBENCH_PAPI static void test_fail(char *file, int line, char *call, int retval) { char buf[128]; memset(buf, '\0', sizeof(buf)); if (retval != 0) fprintf (stdout,"%-40s FAILED\nLine # %d\n", file, line); else { fprintf (stdout,"%-40s SKIPPED\n", file); fprintf (stdout,"Line # %d\n", line); } if (retval == PAPI_ESYS) { sprintf (buf, "System error in %s", call); perror (buf); } else if (retval > 0) fprintf (stdout,"Error: %s\n", call); else if (retval == 0) fprintf (stdout,"Error: %s\n", call); else { char errstring[PAPI_MAX_STR_LEN]; PAPI_perror (retval, errstring, PAPI_MAX_STR_LEN); fprintf (stdout,"Error in %s: %s\n", call, errstring); } fprintf (stdout,"\n"); if (PAPI_is_initialized ()) PAPI_shutdown (); exit (1); } void polybench_papi_init() { # ifdef _OPENMP #pragma omp parallel { #pragma omp master { if (omp_get_max_threads () < polybench_papi_counters_threadid) polybench_papi_counters_threadid = omp_get_max_threads () - 1; } #pragma omp barrier if (omp_get_thread_num () == polybench_papi_counters_threadid) { # endif int retval; polybench_papi_eventset = PAPI_NULL; if ((retval = PAPI_library_init (PAPI_VER_CURRENT)) != PAPI_VER_CURRENT) test_fail (__FILE__, __LINE__, "PAPI_library_init", retval); if ((retval = PAPI_create_eventset (&polybench_papi_eventset)) != PAPI_OK) test_fail (__FILE__, __LINE__, "PAPI_create_eventset", retval); int k; for (k = 0; _polybench_papi_eventlist[k]; ++k) { if ((retval = PAPI_event_name_to_code (_polybench_papi_eventlist[k], &(polybench_papi_eventlist[k]))) != PAPI_OK) test_fail (__FILE__, __LINE__, "PAPI_event_name_to_code", retval); } polybench_papi_eventlist[k] = 0; # ifdef _OPENMP } } #pragma omp barrier # endif } void polybench_papi_close() { # ifdef _OPENMP #pragma omp parallel { if (omp_get_thread_num () == polybench_papi_counters_threadid) { # endif int retval; if ((retval = PAPI_destroy_eventset (&polybench_papi_eventset)) != PAPI_OK) test_fail (__FILE__, __LINE__, "PAPI_destroy_eventset", retval); if (PAPI_is_initialized ()) PAPI_shutdown (); # ifdef _OPENMP } } #pragma omp barrier # endif } int polybench_papi_start_counter(int evid) { # ifndef POLYBENCH_NO_FLUSH_CACHE polybench_flush_cache(); # endif # ifdef _OPENMP # pragma omp parallel { if (omp_get_thread_num () == polybench_papi_counters_threadid) { # endif int retval = 1; char descr[PAPI_MAX_STR_LEN]; PAPI_event_info_t evinfo; PAPI_event_code_to_name (polybench_papi_eventlist[evid], descr); if (PAPI_add_event (polybench_papi_eventset, polybench_papi_eventlist[evid]) != PAPI_OK) test_fail (__FILE__, __LINE__, "PAPI_add_event", 1); if (PAPI_get_event_info (polybench_papi_eventlist[evid], &evinfo) != PAPI_OK) test_fail (__FILE__, __LINE__, "PAPI_get_event_info", retval); if ((retval = PAPI_start (polybench_papi_eventset)) != PAPI_OK) test_fail (__FILE__, __LINE__, "PAPI_start", retval); # ifdef _OPENMP } } #pragma omp barrier # endif return 0; } void polybench_papi_stop_counter(int evid) { # ifdef _OPENMP # pragma omp parallel { if (omp_get_thread_num () == polybench_papi_counters_threadid) { # endif int retval; long_long values[1]; values[0] = 0; if ((retval = PAPI_read (polybench_papi_eventset, &values[0])) != PAPI_OK) test_fail (__FILE__, __LINE__, "PAPI_read", retval); if ((retval = PAPI_stop (polybench_papi_eventset, NULL)) != PAPI_OK) test_fail (__FILE__, __LINE__, "PAPI_stop", retval); polybench_papi_values[evid] = values[0]; if ((retval = PAPI_remove_event (polybench_papi_eventset, polybench_papi_eventlist[evid])) != PAPI_OK) test_fail (__FILE__, __LINE__, "PAPI_remove_event", retval); # ifdef _OPENMP } } #pragma omp barrier # endif } void polybench_papi_print() { int verbose = 0; # ifdef _OPENMP # pragma omp parallel { if (omp_get_thread_num() == polybench_papi_counters_threadid) { #ifdef POLYBENCH_PAPI_VERBOSE verbose = 1; #endif if (verbose) printf ("On thread %d:\n", polybench_papi_counters_threadid); #endif int evid; for (evid = 0; polybench_papi_eventlist[evid] != 0; ++evid) { if (verbose) printf ("%s=", _polybench_papi_eventlist[evid]); printf ("%llu ", polybench_papi_values[evid]); if (verbose) printf ("\n"); } printf ("\n"); # ifdef _OPENMP } } #pragma omp barrier # endif } #endif /* ! POLYBENCH_PAPI */ void polybench_prepare_instruments() { #ifndef POLYBENCH_NO_FLUSH_CACHE polybench_flush_cache (); #endif #ifdef POLYBENCH_LINUX_FIFO_SCHEDULER polybench_linux_fifo_scheduler (); #endif } void polybench_timer_start() { polybench_prepare_instruments (); #ifndef POLYBENCH_CYCLE_ACCURATE_TIMER polybench_t_start = rtclock (); #else polybench_c_start = rdtsc (); #endif } void polybench_timer_stop() { #ifndef POLYBENCH_CYCLE_ACCURATE_TIMER polybench_t_end = rtclock (); #else polybench_c_end = rdtsc (); #endif #ifdef POLYBENCH_LINUX_FIFO_SCHEDULER polybench_linux_standard_scheduler (); #endif } void polybench_timer_print() { #ifdef POLYBENCH_GFLOPS if (polybench_program_total_flops == 0) { printf ("[PolyBench][WARNING] Program flops not defined, use polybench_set_program_flops(value)\n"); printf ("%0.6lf\n", polybench_t_end - polybench_t_start); } else printf ("%0.2lf\n", (polybench_program_total_flops / (double)(polybench_t_end - polybench_t_start)) / 1000000000); #else # ifndef POLYBENCH_CYCLE_ACCURATE_TIMER printf ("%0.6f\n", polybench_t_end - polybench_t_start); # else printf ("%Ld\n", polybench_c_end - polybench_c_start); # endif #endif } /* * These functions are used only if the user defines a specific * inter-array padding. It grows a global structure, * _polybench_alloc_table, which keeps track of the data allocated via * polybench_alloc_data (on which inter-array padding is applied), so * that the original, non-shifted pointer can be recovered when * calling polybench_free_data. * */ #ifdef POLYBENCH_ENABLE_INTARRAY_PAD static void grow_alloc_table() { if (_polybench_alloc_table == NULL || (_polybench_alloc_table->nb_entries % NB_INITIAL_TABLE_ENTRIES) != 0 || _polybench_alloc_table->nb_avail_entries != 0) { /* Should never happen if the API is properly used. */ fprintf (stderr, "[ERROR] Inter-array padding requires to use polybench_alloc_data and polybench_free_data\n"); exit (1); } size_t sz = _polybench_alloc_table->nb_entries; sz += NB_INITIAL_TABLE_ENTRIES; _polybench_alloc_table->user_view = realloc (_polybench_alloc_table->user_view, sz * sizeof(void*)); assert(_polybench_alloc_table->user_view != NULL); _polybench_alloc_table->real_ptr = realloc (_polybench_alloc_table->real_ptr, sz * sizeof(void*)); assert(_polybench_alloc_table->real_ptr != NULL); _polybench_alloc_table->nb_avail_entries = NB_INITIAL_TABLE_ENTRIES; } static void* register_padded_pointer(void* ptr, size_t orig_sz, size_t padded_sz) { if (_polybench_alloc_table == NULL) { fprintf (stderr, "[ERROR] Inter-array padding requires to use polybench_alloc_data and polybench_free_data\n"); exit (1); } if (_polybench_alloc_table->nb_avail_entries == 0) grow_alloc_table (); int id = _polybench_alloc_table->nb_entries++; _polybench_alloc_table->real_ptr[id] = ptr; _polybench_alloc_table->user_view[id] = ptr + (padded_sz - orig_sz); return _polybench_alloc_table->user_view[id]; } static void free_data_from_alloc_table (void* ptr) { if (_polybench_alloc_table != NULL && _polybench_alloc_table->nb_entries > 0) { int i; for (i = 0; i < _polybench_alloc_table->nb_entries; ++i) if (_polybench_alloc_table->user_view[i] == ptr || _polybench_alloc_table->real_ptr[i] == ptr) break; if (i != _polybench_alloc_table->nb_entries) { free (_polybench_alloc_table->real_ptr[i]); for (; i < _polybench_alloc_table->nb_entries - 1; ++i) { _polybench_alloc_table->user_view[i] = _polybench_alloc_table->user_view[i + 1]; _polybench_alloc_table->real_ptr[i] = _polybench_alloc_table->real_ptr[i + 1]; } _polybench_alloc_table->nb_entries--; _polybench_alloc_table->nb_avail_entries++; if (_polybench_alloc_table->nb_entries == 0) { free (_polybench_alloc_table->user_view); free (_polybench_alloc_table->real_ptr); free (_polybench_alloc_table); _polybench_alloc_table = NULL; } } } } static void check_alloc_table_state() { if (_polybench_alloc_table == NULL) { _polybench_alloc_table = (struct polybench_data_ptrs*) malloc (sizeof(struct polybench_data_ptrs)); assert(_polybench_alloc_table != NULL); _polybench_alloc_table->user_view = (void**) malloc (sizeof(void*) * NB_INITIAL_TABLE_ENTRIES); assert(_polybench_alloc_table->user_view != NULL); _polybench_alloc_table->real_ptr = (void**) malloc (sizeof(void*) * NB_INITIAL_TABLE_ENTRIES); assert(_polybench_alloc_table->real_ptr != NULL); _polybench_alloc_table->nb_entries = 0; _polybench_alloc_table->nb_avail_entries = NB_INITIAL_TABLE_ENTRIES; } } #endif // !POLYBENCH_ENABLE_INTARRAY_PAD static void* xmalloc(size_t alloc_sz) { void* ret = NULL; /* By default, post-pad the arrays. Safe behavior, but likely useless. */ polybench_inter_array_padding_sz += POLYBENCH_INTER_ARRAY_PADDING_FACTOR; size_t padded_sz = alloc_sz + polybench_inter_array_padding_sz; int err = posix_memalign (&ret, 4096, padded_sz); if (! ret || err) { fprintf (stderr, "[PolyBench] posix_memalign: cannot allocate memory"); exit (1); } /* Safeguard: this is invoked only if polybench.c has been compiled with inter-array padding support from polybench.h. If so, move the starting address of the allocation and return it to the user. The original pointer is registered in an allocation table internal to polybench.c. Data must then be freed using polybench_free_data, which will inspect the allocation table to free the original pointer.*/ #ifdef POLYBENCH_ENABLE_INTARRAY_PAD /* This moves the 'ret' pointer by (padded_sz - alloc_sz) positions, and registers it in the lookup table for future free using polybench_free_data. */ ret = register_padded_pointer(ret, alloc_sz, padded_sz); #endif return ret; } void polybench_free_data(void* ptr) { #ifdef POLYBENCH_ENABLE_INTARRAY_PAD free_data_from_alloc_table (ptr); #else free (ptr); #endif } void* polybench_alloc_data(unsigned long long int n, int elt_size) { #ifdef POLYBENCH_ENABLE_INTARRAY_PAD check_alloc_table_state (); #endif /// FIXME: detect overflow! size_t val = n; val *= elt_size; void* ret = xmalloc (val); return ret; }
GB_unop__exp_fc64_fc64.c
//------------------------------------------------------------------------------ // GB_unop: hard-coded functions for each built-in unary operator //------------------------------------------------------------------------------ // SuiteSparse:GraphBLAS, Timothy A. Davis, (c) 2017-2020, All Rights Reserved. // http://suitesparse.com See GraphBLAS/Doc/License.txt for license. //------------------------------------------------------------------------------ // If this file is in the Generated/ folder, do not edit it (auto-generated). #include "GB.h" #ifndef GBCOMPACT #include "GB_control.h" #include "GB_unop__include.h" // C=unop(A) is defined by the following types and operators: // op(A) function: GB_unop_apply__exp_fc64_fc64 // op(A') function: GB_unop_tran__exp_fc64_fc64 // C type: GxB_FC64_t // A type: GxB_FC64_t // cast: GxB_FC64_t cij = aij // unaryop: cij = cexp (aij) #define GB_ATYPE \ GxB_FC64_t #define GB_CTYPE \ GxB_FC64_t // aij = Ax [pA] #define GB_GETA(aij,Ax,pA) \ GxB_FC64_t aij = Ax [pA] #define GB_CX(p) Cx [p] // unary operator #define GB_OP(z, x) \ z = cexp (x) ; // casting #define GB_CAST(z, aij) \ GxB_FC64_t z = aij ; // cij = op (aij) #define GB_CAST_OP(pC,pA) \ { \ /* aij = Ax [pA] */ \ GxB_FC64_t aij = Ax [pA] ; \ /* Cx [pC] = op (cast (aij)) */ \ GxB_FC64_t z = aij ; \ Cx [pC] = cexp (z) ; \ } // disable this operator and use the generic case if these conditions hold #define GB_DISABLE \ (GxB_NO_EXP || GxB_NO_FC64) //------------------------------------------------------------------------------ // Cx = op (cast (Ax)): apply a unary operator //------------------------------------------------------------------------------ GrB_Info GB_unop_apply__exp_fc64_fc64 ( GxB_FC64_t *Cx, // Cx and Ax may be aliased const GxB_FC64_t *Ax, int64_t anz, int nthreads ) { #if GB_DISABLE return (GrB_NO_VALUE) ; #else int64_t p ; #pragma omp parallel for num_threads(nthreads) schedule(static) for (p = 0 ; p < anz ; p++) { GxB_FC64_t aij = Ax [p] ; GxB_FC64_t z = aij ; Cx [p] = cexp (z) ; } return (GrB_SUCCESS) ; #endif } //------------------------------------------------------------------------------ // C = op (cast (A')): transpose, typecast, and apply a unary operator //------------------------------------------------------------------------------ GrB_Info GB_unop_tran__exp_fc64_fc64 ( GrB_Matrix C, const GrB_Matrix A, int64_t *GB_RESTRICT *Rowcounts, GBI_single_iterator Iter, const int64_t *GB_RESTRICT A_slice, int naslice ) { #if GB_DISABLE return (GrB_NO_VALUE) ; #else #define GB_PHASE_2_OF_2 #include "GB_unop_transpose.c" return (GrB_SUCCESS) ; #endif } #endif
diffusion_grid.h
// ----------------------------------------------------------------------------- // // Copyright (C) The BioDynaMo Project. // All Rights Reserved. // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. // // See the LICENSE file distributed with this work for details. // See the NOTICE file distributed with this work for additional information // regarding copyright ownership. // // ----------------------------------------------------------------------------- #ifndef CORE_DIFFUSION_GRID_H_ #define CORE_DIFFUSION_GRID_H_ #include <assert.h> #include <algorithm> #include <array> #include <cmath> #include <functional> #include <iostream> #include <string> #include <vector> #include "core/util/root.h" #include "core/container/math_array.h" #include "core/container/parallel_resize_vector.h" #include "core/param/param.h" #include "core/util/log.h" #include "core/util/math.h" namespace bdm { /// A class that computes the diffusion of extracellular substances /// It maintains the concentration and gradient of a single substance class DiffusionGrid { public: explicit DiffusionGrid(TRootIOCtor* p) {} DiffusionGrid(int substance_id, std::string substance_name, double dc, double mu, int resolution = 11) : substance_(substance_id), substance_name_(substance_name), dc_({{1 - dc, dc / 6, dc / 6, dc / 6, dc / 6, dc / 6, dc / 6}}), mu_(mu), resolution_(resolution) {} virtual ~DiffusionGrid() {} /// @brief Initializes the grid by calculating the grid dimensions /// and number of boxes along the axis from the input arguments /// /// @param[in] grid_dimensions The grid dimensions /// @param[in] box_length The box length /// void Initialize(const std::array<int32_t, 6>& grid_dimensions) { // Get grid properties from neighbor grid grid_dimensions_ = grid_dimensions; assert(resolution_ > 0 && "The resolution cannot be zero!"); num_boxes_axis_[0] = resolution_; num_boxes_axis_[1] = resolution_; num_boxes_axis_[2] = resolution_; // Example: diffusion grid dimensions from 0-40 and resolution // of 4. Resolution must be adjusted otherwise one data pointer will be // missing. // Without adjustment: // box_length_: 10 // data points {0, 10, 20, 30} - 40 will be misssing! // With adjustment // box_length_: 13.3 // data points: {0, 13.3, 26.6, 39.9} box_length_ = (grid_dimensions_[1] - grid_dimensions_[0]) / static_cast<double>(resolution_ - 1); ParametersCheck(); box_volume_ = box_length_ * box_length_ * box_length_; assert(box_length_ > 0 && "Box length of diffusion grid must be greater than zero!"); // Set the parity of the number of boxes along the dimensions (since all // dimensions are the same, we just take the x-axis here) parity_ = num_boxes_axis_[0] % 2; total_num_boxes_ = num_boxes_axis_[0] * num_boxes_axis_[1] * num_boxes_axis_[2]; // Allocate memory for the concentration and gradient arrays c1_.resize(total_num_boxes_); c2_.resize(total_num_boxes_); gradients_.resize(3 * total_num_boxes_); initialized_ = true; } void ParametersCheck() { // The 1.0 is to impose floating point operations if ((1.0 * (1 - dc_[0]) * dt_) / (1.0 * box_length_ * box_length_) >= (1.0 / 6)) { Log::Fatal( "DiffusionGrid", "The specified parameters of the diffusion grid with substance [", substance_name_, "] will result in unphysical behavior (diffusion coefficient = ", (1 - dc_[0]), ", resolution = ", resolution_, "). Please refer to the user guide for more information."); } } void RunInitializers() { assert(num_boxes_axis_[0] > 0 && "The number of boxes along an axis was found to be zero!"); if (initializers_.empty()) { return; } auto nx = num_boxes_axis_[0]; auto ny = num_boxes_axis_[1]; auto nz = num_boxes_axis_[2]; // Apply all functions that initialize this diffusion grid for (size_t f = 0; f < initializers_.size(); f++) { for (size_t x = 0; x < nx; x++) { double real_x = grid_dimensions_[0] + x * box_length_; for (size_t y = 0; y < ny; y++) { double real_y = grid_dimensions_[2] + y * box_length_; for (size_t z = 0; z < nz; z++) { double real_z = grid_dimensions_[4] + z * box_length_; std::array<uint32_t, 3> box_coord; box_coord[0] = x; box_coord[1] = y; box_coord[2] = z; size_t idx = GetBoxIndex(box_coord); IncreaseConcentrationBy(idx, initializers_[f](real_x, real_y, real_z)); } } } } // Clear the initializer to free up space initializers_.clear(); initializers_.shrink_to_fit(); } /// @brief Updates the grid dimensions, based on the given threshold /// values. The diffusion grid dimensions need always be larger /// than the neighbor grid dimensions, so that each simulation /// object can obtain its local concentration / gradient /// /// @param[in] threshold_dimensions The threshold values /// void Update(const std::array<int32_t, 2>& threshold_dimensions) { // Update the grid dimensions such that each dimension ranges from // {treshold_dimensions[0] - treshold_dimensions[1]} auto min_gd = threshold_dimensions[0]; auto max_gd = threshold_dimensions[1]; grid_dimensions_ = {min_gd, max_gd, min_gd, max_gd, min_gd, max_gd}; // If the grid is not perfectly divisible along each dimension by the // box length, extend the grid so that it is int dimension_length = max_gd - min_gd; for (int i = 0; i < 3; i++) { int r = fmod(dimension_length, box_length_); if (r > 1e-9) { // std::abs for the case that box_length_ > dimension_length grid_dimensions_[2 * i + 1] += (box_length_ - r); } } // Calculate by how many boxes each dimension has grown int new_dimension_length = grid_dimensions_[1] - grid_dimensions_[0]; int new_num_boxes = std::ceil(new_dimension_length / box_length_); int growth = new_num_boxes - num_boxes_axis_[0]; if (growth > 0) { // Store the old number of boxes along each axis for comparison std::array<size_t, 3> tmp_num_boxes_axis = num_boxes_axis_; // Increase number of boxes along axis accordingly num_boxes_axis_[0] += growth; num_boxes_axis_[1] += growth; num_boxes_axis_[2] += growth; // We need to maintain the parity of the number of boxes along each // dimension, otherwise copying of the substances to the increases grid // will not be symmetrically done; resulting in shifting of boxes // We add a box in the negative direction, because the only way the parity // could have changed is because of adding a box in the positive direction // (due to the grid not being perfectly divisible; see above) if (num_boxes_axis_[0] % 2 != parity_) { for (int i = 0; i < 3; i++) { grid_dimensions_[2 * i] -= box_length_; num_boxes_axis_[i]++; } } // Temporarily save previous grid data auto tmp_c1 = c1_; auto tmp_gradients = gradients_; c1_.clear(); c2_.clear(); gradients_.clear(); total_num_boxes_ = num_boxes_axis_[0] * num_boxes_axis_[1] * num_boxes_axis_[2]; CopyOldData(tmp_c1, tmp_gradients, tmp_num_boxes_axis); assert(total_num_boxes_ >= tmp_num_boxes_axis[0] * tmp_num_boxes_axis[1] * tmp_num_boxes_axis[2] && "The diffusion grid tried to shrink! It can only become larger"); } } /// Copies the concentration and gradients values to the new /// (larger) grid. In the 2D case it looks like the following: /// /// [0 0 0 0] /// [v1 v2] --> [0 v1 v2 0] /// [v3 v4] --> [0 v3 v4 0] /// [0 0 0 0] /// /// The dimensions are doubled in this case from 2x2 to 4x4 /// If the dimensions would be increased from 2x2 to 3x3, it will still /// be increased to 4x4 in order for GetBoxIndex to function correctly /// void CopyOldData(const ParallelResizeVector<double>& old_c1, const ParallelResizeVector<double>& old_gradients, const std::array<size_t, 3>& old_num_boxes_axis) { // Allocate more memory for the grid data arrays c1_.resize(total_num_boxes_); c2_.resize(total_num_boxes_); gradients_.resize(3 * total_num_boxes_); auto incr_dim_x = num_boxes_axis_[0] - old_num_boxes_axis[0]; auto incr_dim_y = num_boxes_axis_[1] - old_num_boxes_axis[1]; auto incr_dim_z = num_boxes_axis_[2] - old_num_boxes_axis[2]; int off_x = incr_dim_x / 2; int off_y = incr_dim_y / 2; int off_z = incr_dim_z / 2; int num_box_xy = num_boxes_axis_[0] * num_boxes_axis_[1]; int old_box_xy = old_num_boxes_axis[0] * old_num_boxes_axis[1]; int new_origin = off_z * (num_boxes_axis_[0] * num_boxes_axis_[1]) + off_y * num_boxes_axis_[0] + off_x; for (size_t k = 0; k < old_num_boxes_axis[2]; k++) { int offset = new_origin + k * num_box_xy; for (size_t j = 0; j < old_num_boxes_axis[1]; j++) { if (j != 0) { offset += num_boxes_axis_[0]; } for (size_t i = 0; i < old_num_boxes_axis[0]; i++) { auto idx = k * old_box_xy + j * old_num_boxes_axis[0] + i; c1_[offset + i] = old_c1[idx]; gradients_[3 * (offset + i)] = old_gradients[3 * idx]; gradients_[3 * (offset + i) + 1] = old_gradients[3 * idx + 1]; gradients_[3 * (offset + i) + 2] = old_gradients[3 * idx + 2]; } } } } /// Solves a 5-point stencil diffusion equation, with leaking-edge /// boundary conditions. Substances are allowed to leave the simulation /// space. This prevents building up concentration at the edges /// void DiffuseWithLeakingEdge() { int nx = num_boxes_axis_[0]; int ny = num_boxes_axis_[1]; int nz = num_boxes_axis_[2]; #define YBF 16 #pragma omp parallel for collapse(2) for (int yy = 0; yy < ny; yy += YBF) { for (int z = 0; z < nz; z++) { // To let the edges bleed we set some diffusion coefficients // to zero. This prevents substance building up at the edges auto dc_2_ = dc_; int ymax = yy + YBF; if (ymax >= ny) { ymax = ny; } for (int y = yy; y < ymax; y++) { dc_2_ = dc_; int x; int c, n, s, b, t; x = 0; c = x + y * nx + z * nx * ny; if (y == 0) { n = c; dc_2_[4] = 0; } else { n = c - nx; } if (y == (ny - 1)) { s = c; dc_2_[3] = 0; } else { s = c + nx; } if (z == 0) { b = c; dc_2_[5] = 0; } else { b = c - nx * ny; } if (z == (nz - 1)) { t = c; dc_2_[6] = 0; } else { t = c + nx * ny; } // x = 0; we leak out substances past this edge (so multiply by 0) c2_[c] = (dc_2_[0] * c1_[c] + 0 * c1_[c] + dc_2_[2] * c1_[c + 1] + dc_2_[3] * c1_[s] + dc_2_[4] * c1_[n] + dc_2_[5] * c1_[b] + dc_2_[6] * c1_[t]) * (1 - mu_); #pragma omp simd for (x = 1; x < nx - 1; x++) { ++c; ++n; ++s; ++b; ++t; c2_[c] = (dc_2_[0] * c1_[c] + dc_2_[1] * c1_[c - 1] + dc_2_[2] * c1_[c + 1] + dc_2_[3] * c1_[s] + dc_2_[4] * c1_[n] + dc_2_[5] * c1_[b] + dc_2_[6] * c1_[t]) * (1 - mu_); } ++c; ++n; ++s; ++b; ++t; // x = nx-1; we leak out substances past this edge (so multiply by 0) c2_[c] = (dc_2_[0] * c1_[c] + dc_2_[1] * c1_[c - 1] + 0 * c1_[c] + dc_2_[3] * c1_[s] + dc_2_[4] * c1_[n] + dc_2_[5] * c1_[b] + dc_2_[6] * c1_[t]) * (1 - mu_); } // tile ny } // tile nz } // block ny c1_.swap(c2_); } /// Solves a 5-point stencil diffusion equation, with closed-edge /// boundary conditions. Substances are not allowed to leave the simulation /// space. Keep in mind that the concentration can build up at the edges /// void DiffuseWithClosedEdge() { auto nx = num_boxes_axis_[0]; auto ny = num_boxes_axis_[1]; auto nz = num_boxes_axis_[2]; #define YBF 16 #pragma omp parallel for collapse(2) for (size_t yy = 0; yy < ny; yy += YBF) { for (size_t z = 0; z < nz; z++) { size_t ymax = yy + YBF; if (ymax >= ny) { ymax = ny; } for (size_t y = yy; y < ymax; y++) { size_t x; int c, n, s, b, t; x = 0; c = x + y * nx + z * nx * ny; n = (y == 0) ? c : c - nx; s = (y == ny - 1) ? c : c + nx; b = (z == 0) ? c : c - nx * ny; t = (z == nz - 1) ? c : c + nx * ny; c2_[c] = (dc_[0] * c1_[c] + dc_[1] * c1_[c] + dc_[2] * c1_[c + 1] + dc_[3] * c1_[s] + dc_[4] * c1_[n] + dc_[5] * c1_[b] + dc_[6] * c1_[t]) * (1 - mu_); #pragma omp simd for (x = 1; x < nx - 1; x++) { ++c; ++n; ++s; ++b; ++t; c2_[c] = (dc_[0] * c1_[c] + dc_[1] * c1_[c - 1] + dc_[2] * c1_[c + 1] + dc_[3] * c1_[s] + dc_[4] * c1_[n] + dc_[5] * c1_[b] + dc_[6] * c1_[t]) * (1 - mu_); } ++c; ++n; ++s; ++b; ++t; c2_[c] = (dc_[0] * c1_[c] + dc_[1] * c1_[c - 1] + dc_[2] * c1_[c] + dc_[3] * c1_[s] + dc_[4] * c1_[n] + dc_[5] * c1_[b] + dc_[6] * c1_[t]) * (1 - mu_); } // tile ny } // tile nz } // block ny c1_.swap(c2_); } void DiffuseEuler() { // check if diffusion coefficient and decay constant are 0 // i.e. if we don't need to calculate diffusion update if (IsFixedSubstance()) { return; } const auto nx = num_boxes_axis_[0]; const auto ny = num_boxes_axis_[1]; const auto nz = num_boxes_axis_[2]; const double ibl2 = 1 / (box_length_ * box_length_); const double d = 1 - dc_[0]; #define YBF 16 #pragma omp parallel for collapse(2) for (size_t yy = 0; yy < ny; yy += YBF) { for (size_t z = 0; z < nz; z++) { size_t ymax = yy + YBF; if (ymax >= ny) { ymax = ny; } for (size_t y = yy; y < ymax; y++) { size_t x = 0; int c, n, s, b, t; c = x + y * nx + z * nx * ny; #pragma omp simd for (x = 1; x < nx - 1; x++) { ++c; ++n; ++s; ++b; ++t; if (y == 0 || y == (ny - 1) || z == 0 || z == (nz - 1)) { continue; } n = c - nx; s = c + nx; b = c - nx * ny; t = c + nx * ny; c2_[c] = (c1_[c] + d * dt_ * (c1_[c - 1] - 2 * c1_[c] + c1_[c + 1]) * ibl2 + d * dt_ * (c1_[s] - 2 * c1_[c] + c1_[n]) * ibl2 + d * dt_ * (c1_[b] - 2 * c1_[c] + c1_[t]) * ibl2) * (1 - mu_); } ++c; ++n; ++s; ++b; ++t; } // tile ny } // tile nz } // block ny c1_.swap(c2_); } void DiffuseEulerLeakingEdge() { // check if diffusion coefficient and decay constant are 0 // i.e. if we don't need to calculate diffusion update if (IsFixedSubstance()) { return; } const auto nx = num_boxes_axis_[0]; const auto ny = num_boxes_axis_[1]; const auto nz = num_boxes_axis_[2]; const double ibl2 = 1 / (box_length_ * box_length_); const double d = 1 - dc_[0]; std::array<int, 4> l; #define YBF 16 #pragma omp parallel for collapse(2) for (size_t yy = 0; yy < ny; yy += YBF) { for (size_t z = 0; z < nz; z++) { size_t ymax = yy + YBF; if (ymax >= ny) { ymax = ny; } for (size_t y = yy; y < ymax; y++) { size_t x = 0; int c, n, s, b, t; c = x + y * nx + z * nx * ny; l.fill(1); if (y == 0) { n = c; l[0] = 0; } else { n = c - nx; } if (y == ny - 1) { s = c; l[1] = 0; } else { s = c + nx; } if (z == 0) { b = c; l[2] = 0; } else { b = c - nx * ny; } if (z == nz - 1) { t = c; l[3] = 0; } else { t = c + nx * ny; } c2_[c] = (c1_[c] + d * dt_ * (0 - 2 * c1_[c] + c1_[c + 1]) * ibl2 + d * dt_ * (c1_[s] - 2 * c1_[c] + c1_[n]) * ibl2 + d * dt_ * (c1_[b] - 2 * c1_[c] + c1_[t]) * ibl2) * (1 - mu_); #pragma omp simd for (x = 1; x < nx - 1; x++) { ++c; ++n; ++s; ++b; ++t; c2_[c] = (c1_[c] + d * dt_ * (c1_[c - 1] - 2 * c1_[c] + c1_[c + 1]) * ibl2 + d * dt_ * (l[0] * c1_[s] - 2 * c1_[c] + l[1] * c1_[n]) * ibl2 + d * dt_ * (l[2] * c1_[b] - 2 * c1_[c] + l[3] * c1_[t]) * ibl2) * (1 - mu_); } ++c; ++n; ++s; ++b; ++t; c2_[c] = (c1_[c] + d * dt_ * (c1_[c - 1] - 2 * c1_[c] + 0) * ibl2 + d * dt_ * (c1_[s] - 2 * c1_[c] + c1_[n]) * ibl2 + d * dt_ * (c1_[b] - 2 * c1_[c] + c1_[t]) * ibl2) * (1 - mu_); } // tile ny } // tile nz } // block ny c1_.swap(c2_); } /// Calculates the gradient for each box in the diffusion grid. /// The gradient is calculated in each direction (x, y, z) as following: /// /// c(x + box_length_) - c(x - box_length) / (2 * box_length_), /// /// where c(x) implies the concentration at position x /// /// At the edges the gradient is the same as the box next to it void CalculateGradient() { // check if gradient has been calculated once // and if diffusion coefficient and decay constant are 0 // i.e. if we don't need to calculate gradient update if (init_gradient_ && IsFixedSubstance()) { return; } double gd = 1 / (box_length_ * 2); auto nx = num_boxes_axis_[0]; auto ny = num_boxes_axis_[1]; auto nz = num_boxes_axis_[2]; #pragma omp parallel for collapse(2) for (size_t z = 0; z < nz; z++) { for (size_t y = 0; y < ny; y++) { for (size_t x = 0; x < nx; x++) { int c, e, w, n, s, b, t; c = x + y * nx + z * nx * ny; if (x == 0) { e = c; w = c + 2; } else if (x == nx - 1) { e = c - 2; w = c; } else { e = c - 1; w = c + 1; } if (y == 0) { n = c + 2 * nx; s = c; } else if (y == ny - 1) { n = c; s = c - 2 * nx; } else { n = c + nx; s = c - nx; } if (z == 0) { t = c + 2 * nx * ny; b = c; } else if (z == nz - 1) { t = c; b = c - 2 * nx * ny; } else { t = c + nx * ny; b = c - nx * ny; } // Let the gradient point from low to high concentration gradients_[3 * c + 0] = (c1_[w] - c1_[e]) * gd; gradients_[3 * c + 1] = (c1_[n] - c1_[s]) * gd; gradients_[3 * c + 2] = (c1_[t] - c1_[b]) * gd; } } } if (!init_gradient_) { init_gradient_ = true; } } /// Increase the concentration at specified position with specified amount void IncreaseConcentrationBy(const Double3& position, double amount) { auto idx = GetBoxIndex(position); IncreaseConcentrationBy(idx, amount); } /// Increase the concentration at specified box with specified amount void IncreaseConcentrationBy(size_t idx, double amount) { assert(idx < total_num_boxes_ && "Cell position is out of diffusion grid bounds"); c1_[idx] += amount; if (c1_[idx] > concentration_threshold_) { c1_[idx] = concentration_threshold_; } } /// Get the concentration at specified position double GetConcentration(const Double3& position) const { return c1_[GetBoxIndex(position)]; } /// Get the (normalized) gradient at specified position void GetGradient(const Double3& position, Double3* gradient) const { auto idx = GetBoxIndex(position); assert(idx < total_num_boxes_ && "Cell position is out of diffusion grid bounds"); (*gradient)[0] = gradients_[3 * idx]; (*gradient)[1] = gradients_[3 * idx + 1]; (*gradient)[2] = gradients_[3 * idx + 2]; auto norm = std::sqrt((*gradient)[0] * (*gradient)[0] + (*gradient)[1] * (*gradient)[1] + (*gradient)[2] * (*gradient)[2]); if (norm > 1e-10) { (*gradient)[0] /= norm; (*gradient)[1] /= norm; (*gradient)[2] /= norm; } } std::array<uint32_t, 3> GetBoxCoordinates(const Double3& position) const { std::array<uint32_t, 3> box_coord; box_coord[0] = (floor(position[0]) - grid_dimensions_[0]) / box_length_; box_coord[1] = (floor(position[1]) - grid_dimensions_[2]) / box_length_; box_coord[2] = (floor(position[2]) - grid_dimensions_[4]) / box_length_; return box_coord; } size_t GetBoxIndex(const std::array<uint32_t, 3>& box_coord) const { size_t ret = box_coord[2] * num_boxes_axis_[0] * num_boxes_axis_[1] + box_coord[1] * num_boxes_axis_[0] + box_coord[0]; return ret; } /// Calculates the box index of the substance at specified position size_t GetBoxIndex(const Double3& position) const { auto box_coord = GetBoxCoordinates(position); return GetBoxIndex(box_coord); } void SetDecayConstant(double mu) { mu_ = mu; } void SetConcentrationThreshold(double t) { concentration_threshold_ = t; } double GetConcentrationThreshold() const { return concentration_threshold_; } const double* GetAllConcentrations() const { return c1_.data(); } const double* GetAllGradients() const { return gradients_.data(); } const std::array<size_t, 3>& GetNumBoxesArray() const { return num_boxes_axis_; } size_t GetNumBoxes() const { return total_num_boxes_; } double GetBoxLength() const { return box_length_; } int GetSubstanceId() const { return substance_; } const std::string& GetSubstanceName() const { return substance_name_; } double GetDecayConstant() const { return mu_; } const int32_t* GetDimensionsPtr() const { return grid_dimensions_.data(); } const std::array<int32_t, 6>& GetDimensions() const { return grid_dimensions_; } const std::array<double, 7>& GetDiffusionCoefficients() const { return dc_; } bool IsInitialized() const { return initialized_; } int GetResolution() const { return resolution_; } double GetBoxVolume() const { return box_volume_; } template <typename F> void AddInitializer(F function) { initializers_.push_back(function); } // retrun true if substance concentration and gradient don't evolve over time bool IsFixedSubstance() { return (mu_ == 0 && dc_[1] == 0 && dc_[2] == 0 && dc_[3] == 0 && dc_[4] == 0 && dc_[5] == 0 && dc_[6] == 0); } private: /// The id of the substance of this grid int substance_ = 0; /// The name of the substance of this grid std::string substance_name_ = ""; /// The side length of each box double box_length_ = 0; /// the volume of each box double box_volume_ = 0; /// The array of concentration values ParallelResizeVector<double> c1_ = {}; /// An extra concentration data buffer for faster value updating ParallelResizeVector<double> c2_ = {}; /// The array of gradients (x, y, z) ParallelResizeVector<double> gradients_ = {}; /// The maximum concentration value that a box can have double concentration_threshold_ = 1e15; /// The diffusion coefficients [cc, cw, ce, cs, cn, cb, ct] std::array<double, 7> dc_ = {{0}}; /// The timestep resolution fhe diffusion grid // TODO(ahmad): this probably needs to scale with Param::simulation_timestep double dt_ = 1; /// The decay constant double mu_ = 0; /// The grid dimensions of the diffusion grid std::array<int32_t, 6> grid_dimensions_ = {{0}}; /// The number of boxes at each axis [x, y, z] std::array<size_t, 3> num_boxes_axis_ = {{0}}; /// The total number of boxes in the diffusion grid size_t total_num_boxes_ = 0; /// Flag to determine if this grid has been initialized bool initialized_ = false; /// The resolution of the diffusion grid int resolution_ = 0; /// If false, grid dimensions are even; if true, they are odd bool parity_ = false; /// A list of functions that initialize this diffusion grid std::vector<std::function<double(double, double, double)>> initializers_ = {}; // turn to true after gradient initialization bool init_gradient_ = false; BDM_CLASS_DEF_NV(DiffusionGrid, 1); }; } // namespace bdm #endif // CORE_DIFFUSION_GRID_H_
omp_reduction.c
/****************************************************************************** * FILE: omp_reduction.c * DESCRIPTION: * OpenMP Example - Combined Parallel Loop Reduction - C/C++ Version * This example demonstrates a sum reduction within a combined parallel loop * construct. Notice that default data element scoping is assumed - there * are no clauses specifying shared or private variables. OpenMP will * automatically make loop index variables private within team threads, and * global variables shared. * AUTHOR: Blaise Barney 5/99 * LAST REVISED: 04/06/05 ******************************************************************************/ #include <omp.h> #include <stdio.h> #include <stdlib.h> int main (int argc, char *argv[]) { int i, n; float a[100], b[100], sum; /* Some initializations */ n = 100; for (i=0; i < n; i++) a[i] = b[i] = i * 1.0; sum = 0.0; #pragma omp parallel for reduction(+:sum) for (i=0; i < n; i++) sum = sum + (a[i] * b[i]); printf(" Sum = %f\n",sum); }
mvt.c
/** * This version is stamped on May 10, 2016 * * Contact: * Louis-Noel Pouchet <pouchet.ohio-state.edu> * Tomofumi Yuki <tomofumi.yuki.fr> * * Web address: http://polybench.sourceforge.net */ /* mvt.c: this file is part of PolyBench/C */ #include <stdio.h> #include <unistd.h> #include <string.h> #include <math.h> /* Include polybench common header. */ #include <polybench.h> /* Include benchmark-specific header. */ #include "mvt.h" /* Array initialization. */ static void init_array(int n, DATA_TYPE POLYBENCH_1D(x1, N, n), DATA_TYPE POLYBENCH_1D(x2, N, n), DATA_TYPE POLYBENCH_1D(y_1, N, n), DATA_TYPE POLYBENCH_1D(y_2, N, n), DATA_TYPE POLYBENCH_2D(A, N, N, n, n)) { int i, j; for (i = 0; i < n; i++) { x1[i] = (DATA_TYPE) (i % n) / n; x2[i] = (DATA_TYPE) ((i + 1) % n) / n; y_1[i] = (DATA_TYPE) ((i + 3) % n) / n; y_2[i] = (DATA_TYPE) ((i + 4) % n) / n; for (j = 0; j < n; j++) A[i][j] = (DATA_TYPE) (i * j % n) / n; } } /* DCE code. Must scan the entire live-out data. Can be used also to check the correctness of the output. */ static void print_array(int n, DATA_TYPE POLYBENCH_1D(x1, N, n), DATA_TYPE POLYBENCH_1D(x2, N, n)) { int i; POLYBENCH_DUMP_START; POLYBENCH_DUMP_BEGIN("x1"); for (i = 0; i < n; i++) { if (i % 20 == 0) fprintf (POLYBENCH_DUMP_TARGET, "\n"); fprintf (POLYBENCH_DUMP_TARGET, DATA_PRINTF_MODIFIER, x1[i]); } POLYBENCH_DUMP_END("x1"); POLYBENCH_DUMP_BEGIN("x2"); for (i = 0; i < n; i++) { if (i % 20 == 0) fprintf (POLYBENCH_DUMP_TARGET, "\n"); fprintf (POLYBENCH_DUMP_TARGET, DATA_PRINTF_MODIFIER, x2[i]); } POLYBENCH_DUMP_END("x2"); POLYBENCH_DUMP_FINISH; } /* Main computational kernel. The whole function will be timed, including the call and return. */ static void kernel_mvt(int n, DATA_TYPE POLYBENCH_1D(x1, N, n), DATA_TYPE POLYBENCH_1D(x2, N, n), DATA_TYPE POLYBENCH_1D(y_1, N, n), DATA_TYPE POLYBENCH_1D(y_2, N, n), DATA_TYPE POLYBENCH_2D(A, N, N, n, n)) { int i, j; #pragma omp parallel for default(shared) private(i, j) firstprivate(n, A, y_1) for (i = 0; i < _PB_N; i++) { for (j = 0; j < _PB_N; j++) x1[i] = x1[i] + A[i][j] * y_1[j]; } #pragma omp parallel for default(shared) private(i, j) firstprivate(n, A, y_2) for (i = 0; i < _PB_N; i++) { for (j = 0; j < _PB_N; j++) x2[i] = x2[i] + A[j][i] * y_2[j]; } } int main(int argc, char** argv) { /* Retrieve problem size. */ int n = N; /* Variable declaration/allocation. */ POLYBENCH_2D_ARRAY_DECL(A, DATA_TYPE, N, N, n, n); POLYBENCH_1D_ARRAY_DECL(x1, DATA_TYPE, N, n); POLYBENCH_1D_ARRAY_DECL(x2, DATA_TYPE, N, n); POLYBENCH_1D_ARRAY_DECL(y_1, DATA_TYPE, N, n); POLYBENCH_1D_ARRAY_DECL(y_2, DATA_TYPE, N, n); /* Initialize array(s). */ init_array (n, POLYBENCH_ARRAY(x1), POLYBENCH_ARRAY(x2), POLYBENCH_ARRAY(y_1), POLYBENCH_ARRAY(y_2), POLYBENCH_ARRAY(A)); /* Start timer. */ polybench_start_instruments; /* Run kernel. */ kernel_mvt (n, POLYBENCH_ARRAY(x1), POLYBENCH_ARRAY(x2), POLYBENCH_ARRAY(y_1), POLYBENCH_ARRAY(y_2), POLYBENCH_ARRAY(A)); /* Stop and print timer. */ polybench_stop_instruments; polybench_print_instruments; /* Prevent dead-code elimination. All live-out data must be printed by the function call in argument. */ polybench_prevent_dce(print_array(n, POLYBENCH_ARRAY(x1), POLYBENCH_ARRAY(x2))); /* Be clean. */ POLYBENCH_FREE_ARRAY(A); POLYBENCH_FREE_ARRAY(x1); POLYBENCH_FREE_ARRAY(x2); POLYBENCH_FREE_ARRAY(y_1); POLYBENCH_FREE_ARRAY(y_2); return 0; }
raytrace.h
/* * @Author: Philippe Dales * @Date: 2018-07-26 14:26:23 * @Last Modified by: Philippe Dales * @Last Modified time: 2018-07-26 14:26:23 */ /* Ray-tracer helper functions for estuary package */ #ifndef RAYTRACE_H #define RAYTRACE_H #include <assert.h> // #include "xseis/process.h" #include "xseis/structures.h" #include "xseis/beamform.h" // #include "xseis/npy.h" #include "narray.hpp" #include "nvect.hpp" #include "solver.hpp" namespace raytrace { // Compute traveltimes from stalocs to gridlocs given 1d viscosity (slowness) model // Uses correct depths but places gridloc cartesian(xy) from staloc // Make sure visc/tag grids are big enough to account for longest xy cartesian dist // (tag is modified in FMM, careful) Array2D<uint16_t> TTableFromVisc1D(Array2D<float>& stalocs, Array2D<float>& gridlocs, Array2D<double>& viscosity, Array2D<int>& tag, const float visc_spacing, float sr) { // consts used to make grids const size_t ndim = 2; const size_t npad = 2; // const float zshift = 500; const float xseed = 100; const auto shape = agsis::vect<size_t, ndim>(viscosity.ncol_, viscosity.nrow_); const size_t size = agsis::prod(shape); // array descriptor of viscosity auto viscosity_ad = ArrayDescriptor<double, ndim>(shape, viscosity.data_); // array descriptor of tag auto tag_ad = ArrayDescriptor<MarchingTag, ndim>(shape, new MarchingTag[size]); // array descriptor of traveltime grid, fill with INFS auto tgrid = Array2D<double>(shape[0], shape[1]); auto tgrid_ad = OrthogonalGrid<double, ndim>(shape, tgrid.data_, visc_spacing); size_t nsta = stalocs.nrow_; auto ttable = Array2D<uint16_t>(stalocs.nrow_, gridlocs.nrow_); auto *ttablerow = ttable.row(0); float *sl = nullptr; float *gl = nullptr; float dxy; float xdest, zdest; float tt; float zseed; auto seed = agsis::vect<double, ndim>(); // #pragma omp parallel for private(ttablerow, sl, gl, dxy, xdest, zdest, tt, zseed) for(size_t i = 0; i < nsta; ++i) { printf("%lu\n", i); ttablerow = ttable.row(i); sl = stalocs.row(i); zseed = sl[2]; seed[0] = static_cast<int>(zseed / visc_spacing + npad + 0.5); seed[1] = static_cast<int>(xseed / visc_spacing + npad + 0.5); for(size_t j = 0; j < tag.size_; ++j) { tag_ad[j] = static_cast<MarchingTag>(tag[j]); } for(size_t j = 0; j < tgrid_ad.size(); ++j) { tgrid_ad[j] = INFINITY; } FMM_SecondOrder(seed, tag_ad, viscosity_ad, tgrid_ad); for(size_t j = 0; j < gridlocs.nrow_; ++j) { gl = gridlocs.row(j); dxy = process::DistCartesian2D(gl, sl); xdest = static_cast<size_t>((xseed + dxy) / visc_spacing + npad + 0.5); zdest = static_cast<size_t>(gl[2] / visc_spacing + npad + 0.5); assert(xdest < tgrid.ncol_); assert(zdest < tgrid.nrow_); tt = tgrid(zdest, xdest); ttablerow[j] = static_cast<uint16_t>(tt * sr + 0.5); } } return ttable; } // Ray trace for 1D velocity model (tag is modified in FMM, careful) // Make sure visc/tag grids are big enough to account for longest xy cartesian dist Array2D<uint16_t> BuildTravelTime1D(Array2D<float>& stalocs, Array2D<float>& gridlocs, Array2D<double>& viscosity, Array2D<int>& tag, float sr) { // consts I use to make grids const size_t ndim = 2; const size_t npad = 2; const size_t visc_spacing = 5; const size_t zpad = 100; const float xseed = 100; // const auto shape = agsis::vect<size_t, ndim>(ds.nrow_, ds.ncol_); const auto shape = agsis::vect<size_t, ndim>(viscosity.ncol_, viscosity.nrow_); const size_t size = agsis::prod(shape); // double *data = new double[size]; // ds.load_full_buffer(data); auto viscosity_ad = ArrayDescriptor<double, ndim>(shape, viscosity.data_); // int *dtag = new int[size]; // hf["tag"].load_full_buffer(dtag); // auto tag_ad = ArrayDescriptor<MarchingTag, ndim>(shape, (MarchingTag *)tag.data_); auto tag_ad = ArrayDescriptor<MarchingTag, ndim>(shape, new MarchingTag[size]); auto tgrid = Array2D<double>(shape[0], shape[1]); auto tgrid_ad = OrthogonalGrid<double, ndim>(shape, tgrid.data_, visc_spacing); for(size_t j = 0; j < tgrid_ad.size(); ++j) { tgrid_ad[j] = INFINITY; } for(size_t j = 0; j < tag.size_; ++j) { tag_ad[j] = static_cast<MarchingTag>(tag[j]); } auto seed = agsis::vect<double, ndim>(); float zseed = zpad; seed[0] = static_cast<int>(zseed / visc_spacing + npad + 0.5); seed[1] = static_cast<int>(xseed / visc_spacing + npad + 0.5); FMM_SecondOrder(seed, tag_ad, viscosity_ad, tgrid_ad); size_t nsta = stalocs.nrow_; // auto ttable = Array2D<float>(nsta, gridlocs.nrow_); auto ttable = Array2D<uint16_t>(stalocs.nrow_, gridlocs.nrow_); auto *ttablerow = ttable.row(0); float *sl = nullptr; float *gl = nullptr; float dxy; float xdest, zdest; float tt; // auto ttable = Vector<float>(gridlocs.nrow_); // size_t nsta = 100; #pragma omp parallel for private(ttablerow, sl, gl, dxy, xdest, zdest, tt) for(size_t i = 0; i < nsta; ++i) { // printf("%lu\n", i); ttablerow = ttable.row(i); sl = stalocs.row(i); for(size_t j = 0; j < gridlocs.nrow_; ++j) { gl = gridlocs.row(j); dxy = process::DistCartesian2D(gl, sl) + std::abs(sl[2]); xdest = (xseed + dxy) / visc_spacing + npad; zdest = (gl[2] + zpad) / visc_spacing + npad; assert(xdest < tgrid.ncol_); assert(zdest < tgrid.nrow_); tt = tgrid(static_cast<size_t>(zdest + 0.5), static_cast<size_t>(xdest + 0.5)); ttablerow[j] = static_cast<uint16_t>(tt * sr + 0.5); } } return ttable; } // rows will be locs1 and cols locs2 Array2D<uint16_t> BuildRow1D(Array2D<float>& locs1, Array2D<float>& locs2, Array2D<double>& viscosity, Array2D<int>& tag, float sr) { // consts I use to make grids const size_t ndim = 2; const size_t npad = 2; const size_t visc_spacing = 5; const size_t zpad = 100; const float xseed = 100; // const auto shape = agsis::vect<size_t, ndim>(ds.nrow_, ds.ncol_); const auto shape = agsis::vect<size_t, ndim>(viscosity.ncol_, viscosity.nrow_); const size_t size = agsis::prod(shape); // double *data = new double[size]; // ds.load_full_buffer(data); auto viscosity_ad = ArrayDescriptor<double, ndim>(shape, viscosity.data_); // int *dtag = new int[size]; // hf["tag"].load_full_buffer(dtag); // auto tag_ad = ArrayDescriptor<MarchingTag, ndim>(shape, (MarchingTag *)tag.data_); auto tag_ad = ArrayDescriptor<MarchingTag, ndim>(shape, new MarchingTag[size]); auto tgrid = Array2D<double>(shape[0], shape[1]); auto tgrid_ad = OrthogonalGrid<double, ndim>(shape, tgrid.data_, visc_spacing); for(size_t j = 0; j < tgrid_ad.size(); ++j) { tgrid_ad[j] = INFINITY; } for(size_t j = 0; j < tag.size_; ++j) { tag_ad[j] = static_cast<MarchingTag>(tag[j]); } auto seed = agsis::vect<double, ndim>(); float zseed = zpad; seed[0] = static_cast<int>(zseed / visc_spacing + npad + 0.5); seed[1] = static_cast<int>(xseed / visc_spacing + npad + 0.5); FMM_SecondOrder(seed, tag_ad, viscosity_ad, tgrid_ad); auto ttable = Array2D<uint16_t>(locs1.nrow_, locs2.nrow_); #pragma omp parallel for for(size_t i = 0; i < locs1.nrow_; ++i) { // printf("%lu\n", i); uint16_t *ttablerow = ttable.row(i); float *l1p = locs1.row(i); for(size_t j = 0; j < locs2.nrow_; ++j) { float *l2p = locs2.row(j); float dxy = process::DistCartesian2D(l2p, l1p); float dz = std::abs(l1p[2] - l2p[2]); float xdest = (xseed + dxy) / visc_spacing + npad; float zdest = (zpad + dz) / visc_spacing + npad; assert(xdest < tgrid.ncol_); assert(zdest < tgrid.nrow_); float tt = tgrid(static_cast<size_t>(zdest + 0.5), static_cast<size_t>(xdest + 0.5)); ttablerow[j] = static_cast<uint16_t>(tt * sr + 0.5); } } return ttable; } } #endif
DRB050-functionparameter-orig-no.c
/* Copyright (c) 2017, Lawrence Livermore National Security, LLC. Produced at the Lawrence Livermore National Laboratory Written by Chunhua Liao, Pei-Hung Lin, Joshua Asplund, Markus Schordan, and Ian Karlin (email: liao6@llnl.gov, lin32@llnl.gov, asplund1@llnl.gov, schordan1@llnl.gov, karlin1@llnl.gov) LLNL-CODE-732144 All rights reserved. This file is part of DataRaceBench. For details, see https://github.com/LLNL/dataracebench. Please also see the LICENSE file for our additional BSD notice. Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: * Redistributions of source code must retain the above copyright notice, this list of conditions and the disclaimer below. * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the disclaimer (as noted below) in the documentation and/or other materials provided with the distribution. * Neither the name of the LLNS/LLNL nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "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 LAWRENCE LIVERMORE NATIONAL SECURITY, LLC, THE U.S. DEPARTMENT OF ENERGY OR CONTRIBUTORS 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. */ /* Arrays passed as function parameters */ #include <omp.h> void foo1(double o1[],double c[],int len) { int i; #pragma omp parallel for private (i) firstprivate (len) for (i = 0; i <= len - 1; i += 1) { double volnew_o8 = 0.5 * c[i]; o1[i] = volnew_o8; } } double o1[100]; double c[100]; int main() { int i; #pragma omp parallel for private (i) for (i = 0; i <= 99; i += 1) { c[i] = i + 1.01; o1[i] = i + 1.01; } foo1(o1,c,100); for (i = 0; i <= 99; i += 1) { printf("%lf\n",o1[i]); } return 0; }
GB_unaryop__ainv_uint16_uint8.c
//------------------------------------------------------------------------------ // GB_unaryop: hard-coded functions for each built-in unary operator //------------------------------------------------------------------------------ // SuiteSparse:GraphBLAS, Timothy A. Davis, (c) 2017-2020, All Rights Reserved. // http://suitesparse.com See GraphBLAS/Doc/License.txt for license. //------------------------------------------------------------------------------ // If this file is in the Generated/ folder, do not edit it (auto-generated). #include "GB.h" #ifndef GBCOMPACT #include "GB_control.h" #include "GB_iterator.h" #include "GB_unaryop__include.h" // C=unop(A) is defined by the following types and operators: // op(A) function: GB_unop__ainv_uint16_uint8 // op(A') function: GB_tran__ainv_uint16_uint8 // C type: uint16_t // A type: uint8_t // cast: uint16_t cij = (uint16_t) aij // unaryop: cij = -aij #define GB_ATYPE \ uint8_t #define GB_CTYPE \ uint16_t // aij = Ax [pA] #define GB_GETA(aij,Ax,pA) \ uint8_t aij = Ax [pA] #define GB_CX(p) Cx [p] // unary operator #define GB_OP(z, x) \ z = -x ; // casting #define GB_CASTING(z, aij) \ uint16_t z = (uint16_t) aij ; // cij = op (cast (aij)) #define GB_CAST_OP(pC,pA) \ { \ /* aij = Ax [pA] */ \ GB_GETA (aij, Ax, pA) ; \ /* Cx [pC] = op (cast (aij)) */ \ GB_CASTING (z, aij) ; \ GB_OP (GB_CX (pC), z) ; \ } // disable this operator and use the generic case if these conditions hold #define GB_DISABLE \ (GxB_NO_AINV || GxB_NO_UINT16 || GxB_NO_UINT8) //------------------------------------------------------------------------------ // Cx = op (cast (Ax)): apply a unary operator //------------------------------------------------------------------------------ GrB_Info GB_unop__ainv_uint16_uint8 ( uint16_t *Cx, // Cx and Ax may be aliased uint8_t *Ax, int64_t anz, int nthreads ) { #if GB_DISABLE return (GrB_NO_VALUE) ; #else int64_t p ; #pragma omp parallel for num_threads(nthreads) schedule(static) for (p = 0 ; p < anz ; p++) { GB_CAST_OP (p, p) ; } return (GrB_SUCCESS) ; #endif } //------------------------------------------------------------------------------ // C = op (cast (A')): transpose, typecast, and apply a unary operator //------------------------------------------------------------------------------ GrB_Info GB_tran__ainv_uint16_uint8 ( GrB_Matrix C, const GrB_Matrix A, int64_t *GB_RESTRICT *Rowcounts, GBI_single_iterator Iter, const int64_t *GB_RESTRICT A_slice, int naslice ) { #if GB_DISABLE return (GrB_NO_VALUE) ; #else #define GB_PHASE_2_OF_2 #include "GB_unaryop_transpose.c" return (GrB_SUCCESS) ; #endif } #endif
poaBarAligner.c
/** * This is designed as a drop-in replacement for the bar aligner, using the abpoa multiple sequence aligner. * * Released under the MIT license, see LICENSE.txt */ #include "abpoa.h" #include "poaBarAligner.h" #include "flowerAligner.h" #include <stdio.h> #include <ctype.h> // FOR DEBUGGING ONLY: Specify directory where abpoa inputs get dumped //#define CACTUS_ABPOA_MSA_DUMP_DIR "/home/hickey/dev/cactus/dump" // FOR DEBUGGING ONLY: Run abpoa from command line instead of via API (only works with CACTUS_ABPOA_MSA_DUMP_DIR defined) //#define CACTUS_ABPOA_FROM_COMMAND_LINE // OpenMP //#if defined(_OPENMP) //#include <omp.h> //#endif abpoa_para_t *abpoaParamaters_constructFromCactusParams(CactusParams *params) { abpoa_para_t *abpt = abpoa_init_para(); // output options abpt->out_msa = 1; // generate Row-Column multiple sequence alignment(RC-MSA), set 0 to disable abpt->out_cons = 0; // generate consensus sequence, set 0 to disable // alignment mode. 0:global alignment, 1:local, 2:extension // only global works abpt->align_mode = ABPOA_GLOBAL_MODE; // banding parameters abpt->wb = cactusParams_get_int(params, 3, "bar", "poa", "partialOrderAlignmentBandConstant"); abpt->wf = cactusParams_get_float(params, 3, "bar", "poa", "partialOrderAlignmentBandFraction"); // gap scoring model abpt->gap_open1 = cactusParams_get_int(params, 3, "bar", "poa", "partialOrderAlignmentGapOpenPenalty1"); abpt->gap_ext1 = cactusParams_get_int(params, 3, "bar", "poa", "partialOrderAlignmentGapExtensionPenalty1"); abpt->gap_open2 = cactusParams_get_int(params, 3, "bar", "poa", "partialOrderAlignmentGapOpenPenalty2"); abpt->gap_ext2 = cactusParams_get_int(params, 3, "bar", "poa", "partialOrderAlignmentGapExtensionPenalty2"); // seeding paramters abpt->disable_seeding = cactusParams_get_int(params, 3, "bar", "poa", "partialOrderAlignmentDisableSeeding"); assert(abpt->disable_seeding == 0 || abpt->disable_seeding == 1); abpt->k = cactusParams_get_int(params, 3, "bar", "poa", "partialOrderAlignmentMinimizerK"); abpt->w = cactusParams_get_int(params, 3, "bar", "poa", "partialOrderAlignmentMinimizerW"); abpt->min_w = cactusParams_get_int(params, 3, "bar", "poa", "partialOrderAlignmentMinimizerMinW"); // progressive toggle abpt->progressive_poa = cactusParams_get_int(params, 3, "bar", "poa", "partialOrderAlignmentProgressiveMode"); // generate the substitution matrix abpoa_post_set_para(abpt); // optionally override the substitution matrix char *submat_string = cactusParams_get_string(params, 3, "bar", "poa", "partialOrderAlignmentSubMatrix"); if (submat_string && strlen(submat_string) > 0) { // Note, this will be used to explicitly override abpoa's subsitution matrix just before aligning abpt->use_score_matrix = 1; assert(abpt->m == 5); int count = 0; for (char* val = strtok(submat_string, " "); val != NULL; val = strtok(NULL, " ")) { abpt->mat[count++] = atoi(val); } assert(count == 25); int i; abpt->min_mis = 0, abpt->max_mat = 0; for (i = 0; i < abpt->m * abpt->m; ++i) { if (abpt->mat[i] > abpt->max_mat) abpt->max_mat = abpt->mat[i]; if (-abpt->mat[i] > abpt->min_mis) abpt->min_mis = -abpt->mat[i]; } } free(submat_string); return abpt; } // It turns out abpoa can write to these, so we make a quick copy before using static abpoa_para_t *copy_abpoa_params(abpoa_para_t *abpt) { abpoa_para_t *abpt_cpy = abpoa_init_para(); abpt_cpy->out_msa = 1; abpt_cpy->out_cons = 0; abpt_cpy->align_mode = abpt->align_mode; abpt_cpy->wb = abpt->wb; abpt_cpy->wf = abpt->wf; abpt_cpy->use_score_matrix = abpt->use_score_matrix; abpt_cpy->match = abpt->match; abpt_cpy->mismatch = abpt->mismatch; abpt_cpy->gap_mode = abpt->gap_mode; abpt_cpy->gap_open1 = abpt->gap_open1; abpt_cpy->gap_ext1 = abpt->gap_ext1; abpt_cpy->gap_open2 = abpt->gap_open2; abpt_cpy->gap_ext2 = abpt->gap_ext2; abpt_cpy->disable_seeding = abpt->disable_seeding; abpt_cpy->k = abpt->k; abpt_cpy->w = abpt->w; abpt_cpy->min_w = abpt->min_w; abpt_cpy->progressive_poa = abpt->progressive_poa; if (abpt->use_score_matrix == 1) { memcpy(abpt_cpy->mat, abpt->mat, abpt->m * abpt->m * sizeof(int)); } abpt_cpy->max_mat = abpt->max_mat; abpt_cpy->min_mis = abpt->min_mis; return abpt_cpy; } // char <--> uint8_t conversion copied over from abPOA example // AaCcGgTtNn ==> 0,1,2,3,4 static unsigned char nst_nt4_table[256] = { 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 5 /*'-'*/, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 0, 4, 1, 4, 4, 4, 2, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 3, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 0, 4, 1, 4, 4, 4, 2, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 3, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4 }; char msa_to_base(uint8_t n) { return "ACGTN-"[n]; } uint8_t msa_to_byte(char c) { return nst_nt4_table[(int)c]; } static uint8_t rc_table[6] = { 3, 2, 1, 0, 4, 5 }; static inline uint8_t msa_to_rc(uint8_t n) { return rc_table[n]; } #ifdef CACTUS_ABPOA_MSA_DUMP_DIR // dump the abpoa input to files, and return a command line for running abpoa on them char* dump_abpoa_input(Msa* msa, abpoa_para_t* abpt, uint8_t **bseqs, char* abpoa_input_path, char* abpoa_matrix_path, char* abpoa_command_path, char* abpoa_output_path) { // dump the abpoa input sequences to a FASTA file FILE* dump_file = fopen(abpoa_input_path, "w"); for (int64_t i = 0; i < msa->seq_no; ++i) { int64_t seq_len = msa->seq_lens[i]; char* buffer = (char*)malloc((seq_len + 1) * sizeof(char)); for (int64_t j = 0; j < seq_len; ++j) { buffer[j] = msa_to_base(bseqs[i][j]); } buffer[msa->seq_lens[i]] = '\0'; fprintf(dump_file, ">%ld\n%s\n", i, buffer); free(buffer); } fclose(dump_file); // dump the abpoa input matrix to file FILE* mat_file = fopen(abpoa_matrix_path, "w"); fprintf(mat_file, "\tA\tC\tG\tT\tN\n"); for (size_t i = 0; i < 5; ++i) { fprintf(mat_file, "%c", "ACGTN"[i]); for (size_t j = 0; j < 5; ++j) { fprintf(mat_file, "\t%d", abpt->mat[i * 5 + j]); } fprintf(mat_file, "\n"); } fclose(mat_file); // make a command line char* abpoa_command = st_malloc(4096 * sizeof(char)); sprintf(abpoa_command, "abpoa %s -O %d,%d -E %d,%d -b %d -f %lf -t %s -r 1 -m 0", abpoa_input_path, abpt->gap_open1, abpt->gap_open2, abpt->gap_ext1, abpt->gap_ext2, abpt->wb, abpt->wf, abpoa_matrix_path); if (abpt->disable_seeding) { strcat(abpoa_command, " -N"); } else { char kw_opts[128]; sprintf(kw_opts, " -k %d -w %d -n %d", abpt->k, abpt->w, abpt->min_w); strcat(abpoa_command, kw_opts); } strcat(abpoa_command, " > "); strcat(abpoa_command, abpoa_output_path); // dump the command line FILE* cmd_file = fopen(abpoa_command_path, "w"); fprintf(cmd_file, "%s\n", abpoa_command); fclose(cmd_file); return abpoa_command; } #endif #ifdef CACTUS_ABPOA_FROM_COMMAND_LINE void abpoa_msa_from_command_line(char* abpoa_command_line, char* abpoa_output_path, uint8_t*** msa_seq, int* col_no) { // run abpoa st_system(abpoa_command_line); // read the result (ascii alignment) back into memory size_t n_rows = 0; size_t n_cols = 0; FILE* msa_file = fopen(abpoa_output_path, "r"); int64_t buf_size = 500000; char* buf = st_malloc(buf_size * sizeof(char)); while (benLine(&buf, &buf_size, msa_file) != -1) { if (strlen(buf) && buf[0] != '>') { ++n_rows; } } *msa_seq = st_malloc(n_rows * sizeof(uint8_t*)); fclose(msa_file); msa_file = fopen(abpoa_output_path, "r"); n_rows = 0; while (benLine(&buf, &buf_size, msa_file) != -1) { if (strlen(buf) && buf[0] != '>') { if (n_cols == 0) { n_cols = strlen(buf); } else { assert(n_cols == strlen(buf)); } (*msa_seq)[n_rows] = st_malloc(n_cols * sizeof(uint8_t)); for (size_t i = 0; i < n_cols; ++i) { (*msa_seq)[n_rows][i] = msa_to_byte(buf[i]); } ++n_rows; } } fclose(msa_file); *col_no = (int)n_cols; free(buf); } #endif void msa_destruct(Msa *msa) { for(int64_t i=0; i<msa->seq_no; i++) { if (msa->seqs != NULL) { free(msa->seqs[i]); } free(msa->msa_seq[i]); } free(msa->seqs); free(msa->msa_seq); free(msa->seq_lens); free(msa); } void msa_print(Msa *msa, FILE *f) { fprintf(f, "MSA. Seq no: %i column no: %i \n", (int)msa->seq_no, (int)msa->column_no); for(int64_t i=0; i<msa->seq_no; i++) { fprintf(f, "Row:%i [len=%i]\t", (int)i, (int)msa->seq_lens[i]); for(int64_t j=0; j<msa->column_no; j++) { fprintf(f, "%c", msa_to_base(msa->msa_seq[i][j])); } fprintf(f, "\n"); } fprintf(f, "\n"); } /** * flip msa to its reverse complement (for trimming purposees) */ static void flip_msa_seq(Msa* msa) { if (msa != NULL) { int64_t middle = msa->column_no / 2; bool odd = msa->column_no % 2 == 1; for (int64_t i = 0; i < msa->seq_no; ++i) { for (int64_t j = 0; j < middle; ++j) { uint8_t buf = msa->msa_seq[i][j]; msa->msa_seq[i][j] = msa_to_rc(msa->msa_seq[i][msa->column_no - 1 - j]); msa->msa_seq[i][msa->column_no - 1 - j] = msa_to_rc(buf); } if (odd) { msa->msa_seq[i][middle] = msa_to_rc(msa->msa_seq[i][middle]); } } } } /** * Returns an array of floats, one for each corresponding column in the MSA. Each float * is the score of the column in the alignment. */ static float *make_column_scores(Msa *msa) { float *column_scores = st_calloc(msa->column_no, sizeof(float)); for(int64_t i=0; i<msa->column_no; i++) { // Score is simply max(number of aligned bases in the column - 1, 0) for(int64_t j=0; j<msa->seq_no; j++) { if(msa_to_base(msa->msa_seq[j][i]) != '-') { column_scores[i]++; } } if(column_scores[i] >= 1.0) { column_scores[i]--; } assert(column_scores[i] >= 0.0); } return column_scores; } /** * Fills in cu_column_scores with the cumulative sum of column scores, from left-to-right, of columns * containing a non-gap character in the given "row". */ static void sum_column_scores(int64_t row, Msa *msa, float *column_scores, float *cu_column_scores) { float cu_score = 0.0; // The cumulative sum of column scores containing bases for the given row int64_t j=0; // The index in the DNA string for the given row for(int64_t i=0; i<msa->column_no; i++) { if(msa_to_base(msa->msa_seq[row][i]) != '-') { cu_score += column_scores[i]; cu_column_scores[j++] = cu_score; } } assert(msa->seq_lens[row] == j); // We should cover all the bases in the DNA sequence } /** * Removes the suffix of the given row from the MSA and updates the column scores. suffix_start is the beginning * suffix to remove. */ static void trim_msa_suffix(Msa *msa, float *column_scores, int64_t row, int64_t suffix_start) { int64_t seq_index = 0; for(int64_t i=0; i<msa->column_no; i++) { if(msa_to_base(msa->msa_seq[row][i]) != '-') { if(seq_index++ >= suffix_start) { msa->msa_seq[row][i] = msa_to_byte('-'); column_scores[i] = column_scores[i] > 1 ? column_scores[i]-1 : 0; assert(column_scores[i] >= 0.0); } } } } /** * Used to make two MSAs consistent with each other for a shared sequence */ static void trim(int64_t row1, Msa *msa1, float *column_scores1, int64_t row2, Msa *msa2, float *column_scores2, int64_t overlap) { if(overlap == 0) { // There is no overlap, so no need to trim either MSA return; } assert(overlap > 0); // Otherwise the overlap must be positive int64_t seq_len1 = msa1->seq_lens[row1]; // The prefix length of the forward complement sequence in the first MSA int64_t seq_len2 = msa2->seq_lens[row2]; // The prefix length of the reverse complement sequence in the second MSA // They can be different if either MSA does not include the whole sequence assert(overlap <= seq_len1); // The overlap must be less than the length of the prefixes assert(overlap <= seq_len2); // Get the cumulative cut scores for the columns containing the shared sequence float *cu_column_scores1 = st_malloc(msa1->column_no * sizeof(float)); float *cu_column_scores2 = st_malloc(msa2->column_no * sizeof(float)); sum_column_scores(row1, msa1, column_scores1, cu_column_scores1); sum_column_scores(row2, msa2, column_scores2, cu_column_scores2); // The score if we cut all of the overlap in msa1 and keep all of the overlap in msa2 assert(seq_len2 <= msa2->column_no); float max_cut_score = cu_column_scores2[seq_len2-1]; if(overlap < seq_len1) { // The overlap is less than the length of the first sequence assert(seq_len1-overlap-1 >= 0); max_cut_score += cu_column_scores1[seq_len1-overlap-1]; // We will keep everything before the overlap } int64_t max_overlap_cut_point = 0; // the length of the prefix of the overlap of msa1 to keep // Now walk through each possible cut point within the overlap for(int64_t i=0; i<overlap-1; i++) { assert(seq_len2-i-2 >= 0); // Sanity check float cut_score = cu_column_scores1[seq_len1-overlap+i] + cu_column_scores2[seq_len2-i-2]; // The score if we keep prefix up to // and including column i of MSA1's overlap, and the prefix of msa2 up to and including column seq_len-i-2 if(cut_score > max_cut_score) { max_overlap_cut_point = i + 1; max_cut_score = cut_score; } } // The score if we cut all of msa2's overlap and keep all of msa1's float f = cu_column_scores1[seq_len1-1]; if(overlap < seq_len2) { assert(seq_len2-overlap-1 >= 0); f += cu_column_scores2[seq_len2-overlap-1]; } if(f > max_cut_score) { max_cut_score = f; max_overlap_cut_point = overlap; } // Now trim back the two MSAs assert(max_overlap_cut_point <= overlap); trim_msa_suffix(msa1, column_scores1, row1, seq_len1 - overlap + max_overlap_cut_point); trim_msa_suffix(msa2, column_scores2, row2, seq_len2 - max_overlap_cut_point); free(cu_column_scores1); free(cu_column_scores2); } /** * recompute the seq_lens of a trimmed msa and clip off empty suffix columns * (todo: can this be built into trimming code?) */ static void msa_fix_trimmed(Msa* msa) { for (int64_t i = 0; i < msa->seq_no; ++i) { // recompute the seq_len msa->seq_lens[i] = 0; for (int64_t j = 0; j < msa->column_no; ++j) { if (msa_to_base(msa->msa_seq[i][j]) != '-') { ++msa->seq_lens[i]; } } } // trim empty columns int64_t empty_columns = 0; for (bool still_empty = true; empty_columns < msa->column_no; ++empty_columns) { for (int64_t i = 0; i < msa->seq_no && still_empty; ++i) { still_empty = msa_to_base(msa->msa_seq[i][msa->column_no - 1 - empty_columns]) == '-'; } if (!still_empty) { break; } } msa->column_no -= empty_columns; } Msa *msa_make_partial_order_alignment(char **seqs, int *seq_lens, int64_t seq_no, int64_t window_size, abpoa_para_t *poa_parameters) { assert(seq_no > 0); // we overlap the sliding window, and use the trimming logic to find the best cut point between consecutive windows // todo: cli-facing parameter float window_overlap_frac = 0.5; int64_t window_overlap_size = window_overlap_frac * window_size; if (window_overlap_size > 0) { --window_overlap_size; // don't want empty window when fully trimmed on each end } // keep track of what's left to align for the sliding window int64_t bases_remaining = 0; // keep track of current offsets int64_t* seq_offsets = (int64_t*)st_calloc(seq_no, sizeof(int64_t)); // keep track of empty chunks bool* empty_seqs = (bool*)st_calloc(seq_no, sizeof(bool)); // keep track of overlaps int64_t* row_overlaps = (int64_t*)st_calloc(seq_no, sizeof(int64_t)); // allocate the poa input buffer uint8_t **bseqs = (uint8_t**)st_malloc(sizeof(uint8_t*) * seq_no); for (int64_t i = 0; i < seq_no; ++i) { int64_t row_size = seq_lens[i] < window_size ? seq_lens[i] : window_size; bseqs[i] = (uint8_t*)st_malloc(sizeof(uint8_t) * row_size); bases_remaining += seq_lens[i]; } // collect our windowed outputs here, to be stiched at the end. stList* msa_windows = stList_construct3(0, (void(*)(void *)) msa_destruct); // remember the previous window Msa* prev_msa = NULL; int64_t prev_bases_remaining = bases_remaining; for (int64_t iteration = 0; bases_remaining > 0; ++iteration) { // compute the number of bases this msa will overlap with the previous msa per row, // assuming that the alignments overlap by window_overlap_size if (prev_msa != NULL) { for (int64_t i = 0; i < seq_no; ++i) { assert(prev_msa->column_no > window_overlap_size); row_overlaps[i] = 0; for (int64_t j = prev_msa->column_no - window_overlap_size; j < prev_msa->column_no; ++j) { if (msa_to_base(prev_msa->msa_seq[i][j]) != '-') { ++row_overlaps[i]; } } // take the overlaps into account in other other counters assert(seq_offsets[i] >= row_overlaps[i]); seq_offsets[i] -= row_overlaps[i]; bases_remaining += row_overlaps[i]; } } // Make Msa object Msa *msa = st_malloc(sizeof(Msa)); msa->seq_no = seq_no; msa->seqs = NULL; msa->seq_lens = st_malloc(sizeof(int) * msa->seq_no); // load up to window_size of each sequence into the input matrix for poa for (int64_t i = 0; i < msa->seq_no; ++i) { msa->seq_lens[i] = 0; for (int64_t j = seq_offsets[i]; j < seq_lens[i] && msa->seq_lens[i] < window_size; ++j, ++msa->seq_lens[i]) { // todo: support iupac characters? bseqs[i][msa->seq_lens[i]] = msa_to_byte(seqs[i][j]); } } // poa can't handle empty sequences. this is a hack to get around that int emptyCount = 0; for (int64_t i = 0; i < msa->seq_no; ++i) { if (msa->seq_lens[i] == 0) { empty_seqs[i] = true; msa->seq_lens[i] = 1; bseqs[i][0] = msa_to_byte('N'); ++emptyCount; } else { empty_seqs[i] = false; } } // init abpoa abpoa_t *ab = abpoa_init(); abpoa_para_t *abpt = copy_abpoa_params(poa_parameters); abpoa_post_set_para(abpt); #ifdef CACTUS_ABPOA_MSA_DUMP_DIR // dump the input to file char abpoa_input_path[1024], abpoa_matrix_path[1024], abpoa_command_path[1024], abpoa_output_path[1024]; sprintf(abpoa_input_path, "%s/ap_in_%ld.fa", CACTUS_ABPOA_MSA_DUMP_DIR, (int64_t)msa); sprintf(abpoa_matrix_path, "%s.mat", abpoa_input_path); sprintf(abpoa_command_path, "%s.cmd", abpoa_input_path); sprintf(abpoa_output_path, "%s.out", abpoa_input_path); char* abpoa_command_line = dump_abpoa_input(msa, abpt, bseqs, abpoa_input_path, abpoa_matrix_path, abpoa_command_path, abpoa_output_path); #endif #ifdef CACTUS_ABPOA_FROM_COMMAND_LINE // run abpoa from the command line abpoa_msa_from_command_line(abpoa_command_line, abpoa_output_path, &(msa->msa_seq), &(msa->column_no)); int test_cols = 0; uint8_t** test_msa = NULL; abpoa_msa(ab, abpt, msa->seq_no, NULL, msa->seq_lens, bseqs, NULL, NULL, NULL, NULL, NULL, &(test_msa), &(test_cols)); // sanity check to make sure we get the same output assert(msa->column_no == test_cols); for (int i = 0; i < msa->seq_no; ++i) { for (int j = 0; j < test_cols; ++j) { assert(test_msa[i][j] == msa->msa_seq[i][j]); } free(test_msa[i]); } free(test_msa); #else // perform abpoa-msa abpoa_msa(ab, abpt, msa->seq_no, NULL, msa->seq_lens, bseqs, NULL, NULL, NULL, NULL, NULL, &(msa->msa_seq), &(msa->column_no)); #endif #ifdef CACTUS_ABPOA_MSA_DUMP_DIR // we got this far without crashing, so delete the dumped file (they can really pile up otherwise) remove(abpoa_input_path); remove(abpoa_matrix_path); remove(abpoa_command_path); remove(abpoa_output_path); free(abpoa_command_line); #endif // free abpoa abpoa_free(ab); abpoa_free_para(abpt); // mask out empty sequences that were phonied in as Ns above for (int64_t i = 0; i < msa->seq_no && emptyCount > 0; ++i) { if (empty_seqs[i] == true) { for (int j = 0; j < msa->column_no; ++j) { if (msa_to_base(msa->msa_seq[i][j]) != '-') { assert(msa_to_base(msa->msa_seq[i][j]) == 'N'); msa->msa_seq[i][j] = msa_to_byte('-'); --msa->seq_lens[i]; assert(msa->seq_lens[i] == 0); --emptyCount; break; } } } } assert(emptyCount == 0); //if (prev_msa) { // fprintf(stderr, "PREV MSA\n"); // msa_print(prev_msa, stderr); //} //fprintf(stderr, "CUR MSA\n"); //msa_print(msa, stderr); // remember how much we aligned this round for (int64_t i = 0; i < msa->seq_no; ++i) { bases_remaining -= msa->seq_lens[i]; seq_offsets[i] += msa->seq_lens[i]; } // todo: there is obviously room for optimization here, as we compute full scores twice for each msa // in addition to flipping the prev_msa back and forth // (not sure if this is at all noticeable on top of abpoa running time though) if (prev_msa) { // trim() presently assumes we're looking at reverse-complement sequence: flip_msa_seq(msa); float* prev_column_scores = make_column_scores(prev_msa); float* column_scores = make_column_scores(msa); // trim with the previous alignment for (int64_t i = 0; i < msa->seq_no; ++i) { int64_t overlap = msa->seq_lens[i] < row_overlaps[i] ? msa->seq_lens[i] : row_overlaps[i]; if (overlap > 0) { trim(i, msa, column_scores, i, prev_msa, prev_column_scores, overlap); } } // todo: can this be done as part of trim? msa_fix_trimmed(msa); msa_fix_trimmed(prev_msa); // flip our msa back to its original strand flip_msa_seq(msa); free(prev_column_scores); free(column_scores); } // add the msa to our list stList_append(msa_windows, msa); // sanity check assert(prev_bases_remaining > bases_remaining && bases_remaining >= 0); prev_msa = msa; //used only for sanity check prev_bases_remaining = bases_remaining; } int64_t num_windows = stList_length(msa_windows); Msa *output_msa; if (num_windows == 1) { // if we have only one window, return it output_msa = stList_removeFirst(msa_windows); output_msa->seqs = seqs; free(output_msa->seq_lens); // cleanup old memory output_msa->seq_lens = seq_lens; } else { // otherwise, we stitch all the window msas into a new output msa output_msa = st_malloc(sizeof(Msa)); assert(seq_no > 0); output_msa->seq_no = seq_no; output_msa->seqs = seqs; output_msa->seq_lens = seq_lens; output_msa->column_no = 0; for (int64_t i = 0; i < num_windows; ++i) { Msa* msa_i = (Msa*)stList_get(msa_windows, i); output_msa->column_no += msa_i->column_no; } output_msa->msa_seq = st_malloc(sizeof(uint8_t *) * output_msa->seq_no); for (int64_t i = 0; i < output_msa->seq_no; ++i) { output_msa->msa_seq[i] = st_malloc(sizeof(uint8_t) * output_msa->column_no); int64_t offset = 0; for (int64_t j = 0; j < num_windows; ++j) { Msa* msa_j = stList_get(msa_windows, j); uint8_t* window_row = msa_j->msa_seq[i]; for (int64_t k = 0; k < msa_j->column_no; ++k) { output_msa->msa_seq[i][offset++] = window_row[k]; } } assert(offset == output_msa->column_no); } } // Clean up for (int64_t i = 0; i < seq_no; ++i) { free(bseqs[i]); } free(bseqs); free(seq_offsets); free(empty_seqs); free(row_overlaps); stList_destruct(msa_windows); return output_msa; } Msa **make_consistent_partial_order_alignments(int64_t end_no, int64_t *end_lengths, char ***end_strings, int **end_string_lengths, int64_t **right_end_indexes, int64_t **right_end_row_indexes, int64_t **overlaps, int64_t window_size, abpoa_para_t *poa_parameters) { // Calculate the initial, potentially inconsistent msas and column scores for each msa float *column_scores[end_no]; Msa **msas = st_malloc(sizeof(Msa *) * end_no); //#if defined(_OPENMP) //#pragma omp parallel for schedule(dynamic) //#endif for(int64_t i=0; i<end_no; i++) { msas[i] = msa_make_partial_order_alignment(end_strings[i], end_string_lengths[i], end_lengths[i], window_size, poa_parameters); column_scores[i] = make_column_scores(msas[i]); } // Make the msas consistent with one another for(int64_t i=0; i<end_no; i++) { // For each end Msa *msa = msas[i]; for(int64_t j=0; j<msa->seq_no; j++) { // For each string incident to the ith end int64_t right_end_index = right_end_indexes[i][j]; // Find the other end it is incident with int64_t right_end_row_index = right_end_row_indexes[i][j]; // And the index of its reverse complement // If it hasn't already been trimmed if(right_end_index > i || (right_end_index == i /* self loop */ && right_end_row_index > j)) { trim(j, msa, column_scores[i], right_end_row_index, msas[right_end_index], column_scores[right_end_index], overlaps[i][j]); } } } // Cleanup for(int64_t i=0; i<end_no; i++) { free(column_scores[i]); } return msas; } /** * The follow code is for dealing with the cactus API */ void alignmentBlock_destruct(AlignmentBlock *alignmentBlock) { AlignmentBlock *a; while(alignmentBlock != NULL) { a = alignmentBlock; alignmentBlock = alignmentBlock->next; free(a); } } char *get_adjacency_string(Cap *cap, int *length, bool return_string) { assert(!cap_getSide(cap)); Sequence *sequence = cap_getSequence(cap); assert(sequence != NULL); Cap *cap2 = cap_getAdjacency(cap); assert(cap2 != NULL); assert(cap_getSide(cap2)); if (cap_getStrand(cap)) { assert(cap_getCoordinate(cap2) > cap_getCoordinate(cap)); *length = cap_getCoordinate(cap2) - cap_getCoordinate(cap) - 1; assert(*length >= 0); return return_string ? sequence_getString(sequence, cap_getCoordinate(cap) + 1, *length, 1) : NULL; } else { assert(cap_getCoordinate(cap) > cap_getCoordinate(cap2)); *length = cap_getCoordinate(cap) - cap_getCoordinate(cap2) - 1; assert(*length >= 0); return return_string ? sequence_getString(sequence, cap_getCoordinate(cap2) + 1, *length, 0) : NULL; } } /** * Used to find where a run of masked (hard or soft) of at least mask_filter bases starts * @param seq : The string * @param seq_length : The length of the string * @param length : The maximum length we want to search in * @param reversed : If true, scan from the end of the string * @param mask_filter : Cut a string as soon as we hit more than this many hard or softmasked bases (cut is before first masked base) * @return length of the filtered string */ static int get_unmasked_length(char* seq, int64_t seq_length, int64_t length, bool reversed, int64_t mask_filter) { if (mask_filter >= 0) { int64_t run_start = -1; for (int64_t i = 0; i < length; ++i) { char base = reversed ? seq[seq_length - 1 - i] : seq[i]; if (islower(base) || base == 'N') { if (run_start == -1) { // start masked run run_start = i; } if (i + 1 - run_start > mask_filter) { // our run exceeds the mask_filter, cap before the first masked base return (int)run_start; } } else { run_start = -1; } } } return (int)length; } /** * Used to get a prefix of a given adjacency sequence. * @param seq_length * @param length * @param overlap * @param max_seq_length * @return */ char *get_adjacency_string_and_overlap(Cap *cap, int *length, int64_t *overlap, int64_t max_seq_length, int64_t mask_filter) { // Get the complete adjacency string int seq_length; char *adjacency_string = get_adjacency_string(cap, &seq_length, 1); assert(seq_length >= 0); // Calculate the length of the prefix up to max_seq_length *length = seq_length > max_seq_length ? max_seq_length : seq_length; assert(*length >= 0); int length_backward = *length; if (mask_filter >= 0) { // apply the mask filter on the forward strand *length = get_unmasked_length(adjacency_string, seq_length, *length, false, mask_filter); length_backward = get_unmasked_length(adjacency_string, seq_length, *length, true, mask_filter); } // Cleanup the string adjacency_string[*length] = '\0'; // Terminate the string at the given length char *c = stString_copy(adjacency_string); free(adjacency_string); adjacency_string = c; // Calculate the overlap with the reverse complement if (*length + length_backward > seq_length) { // There is overlap *overlap = *length + length_backward - seq_length; assert(*overlap >= 0); } else { // There is no overlap *overlap = 0; } return adjacency_string; } /** * Gets the length and sequences present in the next maximal gapless alignment block. * @param msa The msa to scan * @param start The start of the gapless block * @param rows_in_block A boolean array of which sequences are present in the block * @param sequences_in_block The number of in the block * @return */ int64_t get_next_maximal_block_dimensions(Msa *msa, int64_t start, bool *rows_in_block, int64_t *sequences_in_block) { assert(start < msa->column_no); // Calculate which sequences are in the block *sequences_in_block = 0; for(int64_t i=0; i<msa->seq_no; i++) { rows_in_block[i] = msa_to_base(msa->msa_seq[i][start]) != '-'; if(rows_in_block[i]) { *sequences_in_block += 1; } } // Calculate the maximal block length by looking at successive columns of the MSA and // checking they have the same set of sequences present as in the first block int64_t end = start; while(++end < msa->column_no) { for(int64_t i=0; i<msa->seq_no; i++) { bool p = msa_to_base(msa->msa_seq[i][end]) != '-'; // Is not a gap if(p != rows_in_block[i]) { return end; } } } return end; } /** * Make an alignment block for the given interval and sequences * @param seq_no The number of sequences in the MSA * @param start The start, inclusive, of the block * @param length The of the block * @param rows_in_block An array specifying which sequences are in the block * @param seq_indexes The start coordinates of the sequences in the block * @param row_indexes_to_caps The Caps corresponding to the sequences in the block * @return The new alignment block */ AlignmentBlock *make_alignment_block(int64_t seq_no, int64_t start, int64_t length, bool *rows_in_block, int64_t *seq_indexes, Cap **row_indexes_to_caps) { AlignmentBlock *pB = NULL, *block = NULL; for(int64_t i=0; i<seq_no; i++) { // For each row if(rows_in_block[i]) { // If the row is in the block // Make an alignment block AlignmentBlock *b = st_calloc(1, sizeof(AlignmentBlock)); Cap *cap = row_indexes_to_caps[i]; assert(!cap_getSide(cap)); assert(cap_getSequence(cap) != NULL); assert(length > 0); b->strand = cap_getStrand(cap); b->length = length; // Calculate the sequence coordinate using Cactus coordinates if(b->strand) { b->subsequenceIdentifier = cap_getName(cap); b->position = cap_getCoordinate(cap) + 1 + seq_indexes[i]; assert(b->position >= 0); assert(b->position + length <= cap_getCoordinate(cap_getAdjacency(cap))); } else { // In the alignment block all the coordinates are reported with respect to the positive strand sequence Cap *adjacentCap = cap_getAdjacency(cap); assert(adjacentCap != NULL); b->subsequenceIdentifier = cap_getName(adjacentCap); b->position = cap_getCoordinate(cap) - seq_indexes[i] - length; assert(b->position >= 0); assert(b->position + length <= cap_getCoordinate(cap)); assert(b->position > cap_getCoordinate(adjacentCap)); } // If this is not the first sequence in the block link to the previous sequence in the block if (pB != NULL) { pB->next = b; pB = b; assert(b->next == NULL); } else { // Otherwise this is the first sequence in the block block = b; pB = b; } } } assert(block != NULL); return block; } void alignmentBlock_print(AlignmentBlock *ab, FILE *f) { fprintf(f, "Alignment block:\n"); while(ab != NULL) { fprintf(f, "\tName: %" PRIi64 "\tPosition: %" PRIi64"\tStrand: %i\tLength: %" PRIi64 "\n", ab->subsequenceIdentifier, ab->position, (int)ab->strand, ab->length); ab = ab->next; } fprintf(f, "\n"); } /** * Converts an Msa into a list of AlignmentBlocks. * @param msa The msa to convert * @param row_indexes_to_caps The Caps for each sequence in the MSA * @param alignment_blocks The list to add the alignment blocks to */ void create_alignment_blocks(Msa *msa, Cap **row_indexes_to_caps, stList *alignment_blocks) { int64_t i=0; // The left most index of the current block bool rows_in_block[msa->seq_no]; // An array of bools used to indicate which sequences are present in a block int64_t seq_indexes[msa->seq_no]; // The start offsets of the current block for(int64_t k=0; k<msa->seq_no; k++) { // Initialize to zero seq_indexes[k] = 0; } int64_t sequences_in_block; // The number of sequences in the block //fprintf(stderr, "Start. Col no: %i\n", (int)msa->column_no); //msa_print(msa, stderr); // Walk through successive gapless blocks while(i < msa->column_no) { int64_t j = get_next_maximal_block_dimensions(msa, i, rows_in_block, &sequences_in_block); assert(j > i); assert(j <= msa->column_no); // Make the next alignment block if(sequences_in_block > 1) { // Only make a block if it contains two or more sequences stList_append(alignment_blocks, make_alignment_block(msa->seq_no, i, j - i, rows_in_block, seq_indexes, row_indexes_to_caps)); } // Update the offsets in the sequences in the block, regardless of if we actually // created the block for(int64_t k=0; k<msa->seq_no; k++) { if(rows_in_block[k]) { seq_indexes[k] += j - i; } } i = j; } assert(i == msa->column_no); } void get_end_sequences(End *end, char **end_strings, int *end_string_lengths, int64_t *overlaps, Cap **indices_to_caps, int64_t max_seq_length, int64_t mask_filter) { // Make inputs Cap *cap; End_InstanceIterator *capIterator = end_getInstanceIterator(end); int64_t j=0; // Index of the cap in the end's arrays while ((cap = end_getNext(capIterator)) != NULL) { // Ensure we have the cap in the correct orientation if (cap_getSide(cap)) { cap = cap_getReverse(cap); } // Get the prefix of the adjacency string and its length and overlap with its reverse complement end_strings[j] = get_adjacency_string_and_overlap(cap, &(end_string_lengths[j]), &(overlaps[j]), max_seq_length, mask_filter); // Populate the caps to end/row indices, and vice versa, data structures indices_to_caps[j] = cap; j++; } end_destructInstanceIterator(capIterator); } int64_t getMaxSequenceLength(End *end) { Cap *cap; End_InstanceIterator *capIterator = end_getInstanceIterator(end); int64_t max_length=0; while ((cap = end_getNext(capIterator)) != NULL) { if (cap_getSide(cap)) { cap = cap_getReverse(cap); } int length; get_adjacency_string(cap, &length, 0); if(length > max_length) { max_length = length; } } end_destructInstanceIterator(capIterator); return max_length; } stList *make_flower_alignment_poa(Flower *flower, int64_t max_seq_length, int64_t window_size, int64_t mask_filter, abpoa_para_t * poa_parameters) { End *dominantEnd = getDominantEnd(flower); if(dominantEnd != NULL && getMaxSequenceLength(dominantEnd) < max_seq_length) { /* * If there is a single end that is connected to all adjacencies that are less than max_seq_length in length, * just use that alignment */ // Make inputs int64_t seq_no = end_getInstanceNumber(dominantEnd); char **end_strings = st_malloc(sizeof(char *) * seq_no); int *end_string_lengths = st_malloc(sizeof(int) * seq_no); int64_t overlaps[seq_no]; Cap *indices_to_caps[seq_no]; get_end_sequences(dominantEnd, end_strings, end_string_lengths, overlaps, indices_to_caps, max_seq_length, mask_filter); Msa *msa = msa_make_partial_order_alignment(end_strings, end_string_lengths, seq_no, window_size, poa_parameters); //Now convert to set of alignment blocks stList *alignment_blocks = stList_construct3(0, (void (*)(void *))alignmentBlock_destruct); create_alignment_blocks(msa, indices_to_caps, alignment_blocks); // Cleanup msa_destruct(msa); return alignment_blocks; } // Arrays of ends and connecting the strings necessary to build the POA alignment int64_t end_no = flower_getEndNumber(flower); // The number of ends int64_t end_lengths[end_no]; // The number of strings incident with each end char **end_strings[end_no]; // The actual strings connecting the ends int *end_string_lengths[end_no]; // Length of the strings connecting the ends int64_t *right_end_indexes[end_no]; // For each string the index of the right end that it is connecting int64_t *right_end_row_indexes[end_no]; // For each string the index of the row of its reverse complement int64_t *overlaps[end_no]; // For each string the amount it suffix overlaps with its reverse complement // Data structures to translate between caps and sequences in above end arrays Cap **indices_to_caps[end_no]; // For each string the corresponding Cap stHash *caps_to_indices = stHash_construct2(NULL, free); // A hash of caps to their end and row indices // Fill out the end information for building the POA alignments arrays End *end; Flower_EndIterator *endIterator = flower_getEndIterator(flower); int64_t i=0; // Index of the end while ((end = flower_getNextEnd(endIterator)) != NULL) { // Initialize the various arrays for the end end_lengths[i] = end_getInstanceNumber(end); // The number of strings incident with the end end_strings[i] = st_malloc(sizeof(char *)*end_lengths[i]); end_string_lengths[i] = st_malloc(sizeof(int)*end_lengths[i]); right_end_indexes[i] = st_malloc(sizeof(int64_t)*end_lengths[i]); right_end_row_indexes[i] = st_malloc(sizeof(int64_t)*end_lengths[i]); indices_to_caps[i] = st_malloc(sizeof(Cap *)*end_lengths[i]); overlaps[i] = st_malloc(sizeof(int64_t)*end_lengths[i]); get_end_sequences(end, end_strings[i], end_string_lengths[i], overlaps[i], indices_to_caps[i], max_seq_length, mask_filter); for(int64_t j=0; j<end_lengths[i]; j++) { stHash_insert(caps_to_indices, indices_to_caps[i][j], stIntTuple_construct2(i, j)); } i++; } flower_destructEndIterator(endIterator); // Fill out the end / row indices for each cap endIterator = flower_getEndIterator(flower); i=0; while ((end = flower_getNextEnd(endIterator)) != NULL) { Cap *cap; End_InstanceIterator *capIterator = end_getInstanceIterator(end); int64_t j=0; while ((cap = end_getNext(capIterator)) != NULL) { if (cap_getSide(cap)) { cap = cap_getReverse(cap); } Cap *cap2 = cap_getAdjacency(cap); assert(cap2 != NULL); cap2 = cap_getReverse(cap2); assert(!cap_getSide(cap)); assert(!cap_getSide(cap2)); stIntTuple *k = stHash_search(caps_to_indices, cap2); assert(k != NULL); right_end_indexes[i][j] = stIntTuple_get(k, 0); right_end_row_indexes[i][j] = stIntTuple_get(k, 1); j++; } end_destructInstanceIterator(capIterator); i++; } flower_destructEndIterator(endIterator); // Now make the consistent MSAs Msa **msas = make_consistent_partial_order_alignments(end_no, end_lengths, end_strings, end_string_lengths, right_end_indexes, right_end_row_indexes, overlaps, window_size, poa_parameters); // Temp debug output //for(int64_t i=0; i<end_no; i++) { // msa_print(msas[i], stderr); //} //Now convert to set of alignment blocks stList *alignment_blocks = stList_construct3(0, (void (*)(void *))alignmentBlock_destruct); for(int64_t i=0; i<end_no; i++) { create_alignment_blocks(msas[i], indices_to_caps[i], alignment_blocks); } // Cleanup for(int64_t i=0; i<end_no; i++) { msa_destruct(msas[i]); free(right_end_indexes[i]); free(right_end_row_indexes[i]); free(indices_to_caps[i]); free(overlaps[i]); } free(msas); stHash_destruct(caps_to_indices); // Temp debug output //for(int64_t i=0; i<stList_length(alignment_blocks); i++) { // alignmentBlock_print(stList_get(alignment_blocks, i), stderr); //} return alignment_blocks; } /* * The following is used for converting the alignment blocks into pinches consumed by the CAF code. */ /** * Iterator over the list of alignment blocks used to get stPinches in succession. */ typedef struct _alignmentBlockIterator { stList *alignment_blocks; // The list of alignment blocks int64_t i; // Index of the iterator into the alignment_blocks AlignmentBlock *current_block; // The current block being considered } AlignmentBlockIterator; AlignmentBlockIterator *alignmentBlockIterator_construct(stList *alignment_blocks) { AlignmentBlockIterator *alignmentBlockIterator = st_calloc(1, sizeof(AlignmentBlockIterator)); alignmentBlockIterator->alignment_blocks = alignment_blocks; return alignmentBlockIterator; } void alignmentBlockIterator_destruct(AlignmentBlockIterator *it) { stList_length(it->alignment_blocks); free(it); } AlignmentBlockIterator *alignmentBlockIterator_start(AlignmentBlockIterator *it) { it->i = 0; it->current_block = NULL; return it; } stPinch *alignmentBlockIterator_get_next(AlignmentBlockIterator *it, stPinch *pinchToFillOut) { // If there is no current alignment block or the alignment block contains no further pinches if(it->current_block == NULL || it->current_block->next == NULL) { if(it->i >= stList_length(it->alignment_blocks)) { // We are done return NULL; } it->current_block = stList_get(it->alignment_blocks, it->i++); } assert(it->current_block->next != NULL); // All alignment blocks should contain at least two sequences AlignmentBlock *b = it->current_block; assert(b->position >= 0); assert(b->next->position >= 0); assert(b->length > 0); stPinch_fillOut(pinchToFillOut, b->subsequenceIdentifier, b->next->subsequenceIdentifier, b->position, b->next->position, b->length, b->strand == b->next->strand); it->current_block = b->next; // Shift to the next sequence to ready the next pinch return pinchToFillOut; } stPinchIterator *stPinchIterator_constructFromAlignedBlocks(stList *alignment_blocks) { stPinchIterator *pinchIterator = st_calloc(1, sizeof(stPinchIterator)); pinchIterator->alignmentArg = alignmentBlockIterator_construct(alignment_blocks); pinchIterator->getNextAlignment = (stPinch *(*)(void *, stPinch *)) alignmentBlockIterator_get_next; pinchIterator->destructAlignmentArg = (void(*)(void *)) alignmentBlockIterator_destruct; pinchIterator->startAlignmentStack = (void *(*)(void *)) alignmentBlockIterator_start; return pinchIterator; }
integrate_padding_omp.c
#include <stdio.h> #include <omp.h> static long num_steps = 1000000000; double step; #define NUM_THREADS 2 #define PAD 8 int main() { int i, nThreads; double pi, sum[NUM_THREADS][PAD]; step = 1.0/(double) num_steps; omp_set_num_threads(NUM_THREADS); #pragma omp parallel { int i, ID, nThreadsInternal; double x; ID = omp_get_thread_num(); nThreadsInternal = omp_get_num_threads(); if(ID == 0) nThreads = nThreadsInternal; for( i=ID, sum[ID][0]=0.0; i<num_steps; i=i+nThreadsInternal) { x = (i+0.5)*step; sum[ID][0] += 4.0/(1.0 + x*x); } } for (i=0, pi=0.0; i<nThreads; i++) pi += sum[i][0]*step; printf("%f\n", pi); }
par_map.h
#pragma once #include "Defs.h" template <typename T> void par_fill(T* dest, int w, int h, const T value) { #pragma omp parallel for for (int y = 0; y < h; y++) { for (int x = 0; x < w; x++) { const int idx = y * w + x; dest[idx] = value; } } } template <typename T> void par_map(T* src, T* dest, int w, int h, std::function<T(T)> f) { #pragma omp parallel for for (int y = 0; y < h; y++) { for (int x = 0; x < w; x++) { const int idx = y * w + x; dest[idx] = f(src[idx]); } } }
samax.c
/** * * @file * * PLASMA is a software package provided by: * University of Tennessee, US, * University of Manchester, UK. * * @generated from /home/luszczek/workspace/plasma/bitbucket/plasma/compute/dzamax.c, normal z -> s, Fri Sep 28 17:38:01 2018 * **/ #include "plasma.h" #include "plasma_async.h" #include "plasma_context.h" #include "plasma_descriptor.h" #include "plasma_internal.h" #include "plasma_types.h" /******************************************************************************/ int plasma_samax(plasma_enum_t colrow, int m, int n, float *pA, int lda, float *values) { // Get PLASMA context. plasma_context_t *plasma = plasma_context_self(); if (plasma == NULL) { plasma_error("PLASMA not initialized"); return PlasmaErrorNotInitialized; } // Check input arguments. if ((colrow != PlasmaColumnwise) && (colrow != PlasmaRowwise)) { plasma_error("illegal value of colrow"); return -1; } if (m < 0) { plasma_error("illegal value of m"); return -2; } if (n < 0) { plasma_error("illegal value of n"); return -3; } if (lda < imax(1, m)) { plasma_error("illegal value of lda"); return -5; } // quick return if (imin(n, m) == 0) return PlasmaSuccess; // Set tiling parameters. int nb = plasma->nb; // Create tile matrices. plasma_desc_t A; int retval; retval = plasma_desc_general_create(PlasmaRealFloat, nb, nb, m, n, 0, 0, m, n, &A); if (retval != PlasmaSuccess) { plasma_error("plasma_desc_general_create() failed"); return retval; } // Allocate workspace. float *work; switch (colrow) { case PlasmaColumnwise: work = (float*)malloc((size_t)A.mt*A.n*sizeof(float)); break; case PlasmaRowwise: work = (float*)malloc((size_t)A.m*A.nt*sizeof(float)); break; } if (work == NULL) { plasma_error("malloc() failed"); return PlasmaErrorOutOfMemory; } // Initialize sequence. plasma_sequence_t sequence; retval = plasma_sequence_init(&sequence); // Initialize request. plasma_request_t request; retval = plasma_request_init(&request); // asynchronous block #pragma omp parallel #pragma omp master { // Translate to tile layout. plasma_omp_sge2desc(pA, lda, A, &sequence, &request); // Call tile async function. plasma_omp_samax(colrow, A, work, values, &sequence, &request); } // implicit synchronization free(work); // Free matrix in tile layout. plasma_desc_destroy(&A); // Return status. int status = sequence.status; return status; } /******************************************************************************/ void plasma_omp_samax(plasma_enum_t colrow, plasma_desc_t A, float *work, float *values, plasma_sequence_t *sequence, plasma_request_t *request) { // Get PLASMA context. plasma_context_t *plasma = plasma_context_self(); if (plasma == NULL) { plasma_error("PLASMA not initialized"); plasma_request_fail(sequence, request, PlasmaErrorIllegalValue); return; } // Check input arguments. if ((colrow != PlasmaColumnwise) && (colrow != PlasmaRowwise)) { plasma_error("illegal value of colrow"); plasma_request_fail(sequence, request, PlasmaErrorIllegalValue); return; } if (plasma_desc_check(A) != PlasmaSuccess) { plasma_error("invalid descriptor A"); plasma_request_fail(sequence, request, PlasmaErrorIllegalValue); return; } if (sequence == NULL) { plasma_error("NULL sequence"); plasma_request_fail(sequence, request, PlasmaErrorIllegalValue); return; } if (request == NULL) { plasma_error("NULL request"); plasma_request_fail(sequence, request, PlasmaErrorIllegalValue); return; } // quick return if (imin(A.m, A.n) == 0) return; // Call the parallel function. plasma_psamax(colrow, A, work, values, sequence, request); }
main_openmp.c
#include <stdlib.h> #include <stdio.h> #include <math.h> #include <string.h> #include <omp.h> #include "types.h" #include "mandel.h" #include "image_utils.h" #ifndef _SCHELL_ #define _SCHELL_ static #endif int main(int argc, char *argv[]) { int block_size; int ix, iy; int *escapetime; _config config; _color *bitmap; config.screenx = 1920; config.screeny = 1080; config.bailout = 5000; config.er = 2; /*config.minx = -2.5;*/ /*config.maxx = 1.5;*/ /*config.miny = -2.0;*/ /*config.maxy = 2.0;*/ /*config.minx = -0.7436431355 - 0.000014628;*/ /*config.maxx = -0.7436431355 + 0.000014628;*/ /*config.miny = 0.131825963 - 0.000014628;*/ /*config.maxy = 0.131825963 + 0.000014628;*/ config.minx = -0.743643887037151 - 0.000000000051299; config.maxx = -0.743643887037151 + 0.000000000051299; config.miny = 0.131825904205330 - 0.000000000051299; config.maxy = 0.131825904205330 + 0.000000000051299; block_size = 20; if ( argc > 1 ) { omp_set_num_threads(atoi(argv[1])); } /*printf("%f \t %f\n%f\t %f\n", config.minx, config.maxx, config.miny, config.maxy);*/ escapetime = ( int * ) malloc ( sizeof ( int ) * config.screenx * config.screeny ); bitmap = ( _color* ) malloc ( sizeof ( _color ) * config.screenx * config.screeny ); /*#pragma omp parallel for private(ix, iy, config) shared(escapetime)*/ #pragma omp parallel for private(ix) schedule(_SCHELL_) for ( iy = 0; iy < config.screeny; iy += block_size ) { for ( ix = 0; ix < config.screenx; ix += block_size ) { do_block(ix, ix+block_size, iy, iy+block_size, config, escapetime); } /*fprintf(stderr," -- %.2f%%\n",(iy/(double)config.screeny)*100.0);*/ } for ( iy = 0; iy < config.screeny; iy++ ) { for ( ix = 0; ix < config.screenx; ix++ ) { bitmap[iy * config.screenx + ix].r = escapetime[iy * config.screenx + ix]; bitmap[iy * config.screenx + ix].g = escapetime[iy * config.screenx + ix]; bitmap[iy * config.screenx + ix].b = escapetime[iy * config.screenx + ix]; } } /*fprintf(stderr," -- %.2f%%\n",100.0);*/ /*fprintf(stderr," <---- DONE ---->\n");*/ /*fprintf(stderr," Writing to disk!\n");*/ save_png_to_file(bitmap, config.screenx, config.screeny, "mandel.png"); free(escapetime); /*fprintf(stderr," -- Bye\n");*/ return EXIT_SUCCESS; }
bicubic_interpolation.c
// This program is free software: you can use, modify and/or redistribute it // under the terms of the simplified BSD License. You should have received a // copy of this license along this program. If not, see // <http://www.opensource.org/licenses/bsd-license.html>. // // Copyright (C) 2012, Javier Sánchez Pérez <jsanchez@dis.ulpgc.es> // All rights reserved. #ifndef BICUBIC_INTERPOLATION_C #define BICUBIC_INTERPOLATION_C #include <stdbool.h> #define BOUNDARY_CONDITION 0 //0 Neumann //1 Periodic //2 Symmetric /** * * Neumann boundary condition test * **/ static int neumann_bc(int x, int nx, bool *out) { if(x < 0) { x = 0; *out = true; } else if (x >= nx) { x = nx - 1; *out = true; } return x; } /** * * Periodic boundary condition test * **/ static int periodic_bc(int x, int nx, bool *out) { if(x < 0) { const int n = 1 - (int)(x/(nx+1)); const int ixx = x + n * nx; x = ixx% nx; *out = true; } else if(x >= nx) { x = x % nx; *out = true; } return x; } /** * * Symmetric boundary condition test * **/ static int symmetric_bc(int x, int nx, bool *out) { if(x < 0) { const int borde = nx - 1; const int xx = -x; const int n = (int)(xx/borde) % 2; if ( n ) x = borde - ( xx % borde ); else x = xx % borde; *out = true; } else if ( x >= nx ) { const int borde = nx - 1; const int n = (int)(x/borde) % 2; if ( n ) x = borde - ( x % borde ); else x = x % borde; *out = true; } return x; } /** * * Cubic interpolation in one dimension * **/ static float cubic_interpolation_cell ( float v[4], //interpolation points float x //point to be interpolated ) { return v[1] + 0.5 * x * (v[2] - v[0] + x * (2.0 * v[0] - 5.0 * v[1] + 4.0 * v[2] - v[3] + x * (3.0 * (v[1] - v[2]) + v[3] - v[0]))); } /** * * Bicubic interpolation in two dimensions * **/ static float bicubic_interpolation_cell ( float p[4][4], //array containing the interpolation points float x, //x position to be interpolated float y //y position to be interpolated ) { float v[4]; v[0] = cubic_interpolation_cell(p[0], y); v[1] = cubic_interpolation_cell(p[1], y); v[2] = cubic_interpolation_cell(p[2], y); v[3] = cubic_interpolation_cell(p[3], y); return cubic_interpolation_cell(v, x); } /** * * Compute the bicubic interpolation of a point in an image. * Detect if the point goes outside the image domain. * **/ float bicubic_interpolation_at( const float *input, //image to be interpolated const float uu, //x component of the vector field const float vv, //y component of the vector field const int nx, //image width const int ny, //image height bool border_out //if true, return zero outside the region ) { const int sx = (uu < 0)? -1: 1; const int sy = (vv < 0)? -1: 1; int x, y, mx, my, dx, dy, ddx, ddy; bool out[1] = {false}; //apply the corresponding boundary conditions switch(BOUNDARY_CONDITION) { case 0: x = neumann_bc((int) uu, nx, out); y = neumann_bc((int) vv, ny, out); mx = neumann_bc((int) uu - sx, nx, out); my = neumann_bc((int) vv - sx, ny, out); dx = neumann_bc((int) uu + sx, nx, out); dy = neumann_bc((int) vv + sy, ny, out); ddx = neumann_bc((int) uu + 2*sx, nx, out); ddy = neumann_bc((int) vv + 2*sy, ny, out); break; case 1: x = periodic_bc((int) uu, nx, out); y = periodic_bc((int) vv, ny, out); mx = periodic_bc((int) uu - sx, nx, out); my = periodic_bc((int) vv - sx, ny, out); dx = periodic_bc((int) uu + sx, nx, out); dy = periodic_bc((int) vv + sy, ny, out); ddx = periodic_bc((int) uu + 2*sx, nx, out); ddy = periodic_bc((int) vv + 2*sy, ny, out); break; case 2: x = symmetric_bc((int) uu, nx, out); y = symmetric_bc((int) vv, ny, out); mx = symmetric_bc((int) uu - sx, nx, out); my = symmetric_bc((int) vv - sx, ny, out); dx = symmetric_bc((int) uu + sx, nx, out); dy = symmetric_bc((int) vv + sy, ny, out); ddx = symmetric_bc((int) uu + 2*sx, nx, out); ddy = symmetric_bc((int) vv + 2*sy, ny, out); break; default:x = neumann_bc((int) uu, nx, out); y = neumann_bc((int) vv, ny, out); mx = neumann_bc((int) uu - sx, nx, out); my = neumann_bc((int) vv - sx, ny, out); dx = neumann_bc((int) uu + sx, nx, out); dy = neumann_bc((int) vv + sy, ny, out); ddx = neumann_bc((int) uu + 2*sx, nx, out); ddy = neumann_bc((int) vv + 2*sy, ny, out); break; } if(*out && border_out) return 0.0; else { //obtain the interpolation points of the image const float p11 = input[mx + nx * my]; const float p12 = input[x + nx * my]; const float p13 = input[dx + nx * my]; const float p14 = input[ddx + nx * my]; const float p21 = input[mx + nx * y]; const float p22 = input[x + nx * y]; const float p23 = input[dx + nx * y]; const float p24 = input[ddx + nx * y]; const float p31 = input[mx + nx * dy]; const float p32 = input[x + nx * dy]; const float p33 = input[dx + nx * dy]; const float p34 = input[ddx + nx * dy]; const float p41 = input[mx + nx * ddy]; const float p42 = input[x + nx * ddy]; const float p43 = input[dx + nx * ddy]; const float p44 = input[ddx + nx * ddy]; //create array float pol[4][4] = { {p11, p21, p31, p41}, {p12, p22, p32, p42}, {p13, p23, p33, p43}, {p14, p24, p34, p44} }; //return interpolation return bicubic_interpolation_cell(pol, uu-x, vv-y); } } /** * * Compute the bicubic interpolation of an image. * **/ void bicubic_interpolation_warp( const float *input, // image to be warped const float *u, // x component of the vector field const float *v, // y component of the vector field float *output, // image warped with bicubic interpolation const int nx, // image width const int ny, // image height bool border_out // if true, put zeros outside the region ) { #pragma omp parallel for for(int i = 0; i < ny; i++) for(int j = 0; j < nx; j++) { const int p = i * nx + j; const float uu = (float) (j + u[p]); const float vv = (float) (i + v[p]); // obtain the bicubic interpolation at position (uu, vv) output[p] = bicubic_interpolation_at(input, uu, vv, nx, ny, border_out); } } #endif//BICUBIC_INTERPOLATION_C
deprecate.c
/* %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% % % % % % % % DDDD EEEEE PPPP RRRR EEEEE CCCC AAA TTTTT EEEEE % % D D E P P R R E C A A T E % % D D EEE PPPPP RRRR EEE C AAAAA T EEE % % D D E P R R E C A A T E % % DDDD EEEEE P R R EEEEE CCCC A A T EEEEE % % % % % % MagickCore Deprecated Methods % % % % Software Design % % John Cristy % % October 2002 % % % % % % Copyright 1999-2012 ImageMagick Studio LLC, a non-profit organization % % dedicated to making software imaging solutions freely available. % % % % You may not use this file except in compliance with the License. You may % % obtain a copy of the License at % % % % http://www.imagemagick.org/script/license.php % % % % Unless required by applicable law or agreed to in writing, software % % distributed under the License is distributed on an "AS IS" BASIS, % % WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. % % See the License for the specific language governing permissions and % % limitations under the License. % % % %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% % % % */ /* Include declarations. */ #include "magick/studio.h" #include "magick/property.h" #include "magick/blob.h" #include "magick/blob-private.h" #include "magick/cache.h" #include "magick/cache-view.h" #include "magick/client.h" #include "magick/color.h" #include "magick/color-private.h" #include "magick/colormap.h" #include "magick/colormap-private.h" #include "magick/colorspace.h" #include "magick/composite.h" #include "magick/composite-private.h" #include "magick/constitute.h" #include "magick/deprecate.h" #include "magick/draw.h" #include "magick/draw-private.h" #include "magick/effect.h" #include "magick/enhance.h" #include "magick/exception.h" #include "magick/exception-private.h" #include "magick/fx.h" #include "magick/geometry.h" #include "magick/identify.h" #include "magick/image.h" #include "magick/image-private.h" #include "magick/list.h" #include "magick/log.h" #include "magick/memory_.h" #include "magick/magick.h" #include "magick/monitor.h" #include "magick/monitor-private.h" #include "magick/morphology.h" #include "magick/paint.h" #include "magick/pixel.h" #include "magick/pixel-private.h" #include "magick/quantize.h" #include "magick/random_.h" #include "magick/resource_.h" #include "magick/semaphore.h" #include "magick/segment.h" #include "magick/splay-tree.h" #include "magick/statistic.h" #include "magick/string_.h" #include "magick/threshold.h" #include "magick/transform.h" #include "magick/utility.h" #if !defined(MAGICKCORE_EXCLUDE_DEPRECATED) /* Global declarations. */ static MonitorHandler monitor_handler = (MonitorHandler) NULL; /* %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% % % % % % % % A c q u i r e C a c h e V i e w I n d e x e s % % % % % % % %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% % % AcquireCacheViewIndexes() returns the indexes associated with the specified % view. % % Deprecated, replace with: % % GetCacheViewVirtualIndexQueue(cache_view); % % The format of the AcquireCacheViewIndexes method is: % % const IndexPacket *AcquireCacheViewIndexes(const CacheView *cache_view) % % A description of each parameter follows: % % o cache_view: the cache view. % */ MagickExport const IndexPacket *AcquireCacheViewIndexes( const CacheView *cache_view) { return(GetCacheViewVirtualIndexQueue(cache_view)); } /* %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% % % % % % % % A c q u i r e C a c h e V i e w P i x e l s % % % % % % % %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% % % AcquireCacheViewPixels() gets pixels from the in-memory or disk pixel cache % as defined by the geometry parameters. A pointer to the pixels is returned % if the pixels are transferred, otherwise a NULL is returned. % % Deprecated, replace with: % % GetCacheViewVirtualPixels(cache_view,x,y,columns,rows,exception); % % The format of the AcquireCacheViewPixels method is: % % const PixelPacket *AcquireCacheViewPixels(const CacheView *cache_view, % const ssize_t x,const ssize_t y,const size_t columns, % const size_t rows,ExceptionInfo *exception) % % A description of each parameter follows: % % o cache_view: the cache view. % % o x,y,columns,rows: These values define the perimeter of a region of % pixels. % % o exception: return any errors or warnings in this structure. % */ MagickExport const PixelPacket *AcquireCacheViewPixels( const CacheView *cache_view,const ssize_t x,const ssize_t y, const size_t columns,const size_t rows,ExceptionInfo *exception) { return(GetCacheViewVirtualPixels(cache_view,x,y,columns,rows,exception)); } /* %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% % % % % % % % A c q u i r e I m a g e P i x e l s % % % % % % % %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% % % AcquireImagePixels() returns an immutable pixel region. If the % region is successfully accessed, a pointer to it is returned, otherwise % NULL is returned. The returned pointer may point to a temporary working % copy of the pixels or it may point to the original pixels in memory. % Performance is maximized if the selected region is part of one row, or one % or more full rows, since there is opportunity to access the pixels in-place % (without a copy) if the image is in RAM, or in a memory-mapped file. The % returned pointer should *never* be deallocated by the user. % % Pixels accessed via the returned pointer represent a simple array of type % PixelPacket. If the image type is CMYK or the storage class is PseudoClass, % call GetAuthenticIndexQueue() after invoking GetAuthenticPixels() to access % the black color component or to obtain the colormap indexes (of type % IndexPacket) corresponding to the region. % % If you plan to modify the pixels, use GetAuthenticPixels() instead. % % Note, the AcquireImagePixels() and GetAuthenticPixels() methods are not % thread-safe. In a threaded environment, use GetCacheViewVirtualPixels() or % GetCacheViewAuthenticPixels() instead. % % Deprecated, replace with: % % GetVirtualPixels(image,x,y,columns,rows,exception); % % The format of the AcquireImagePixels() method is: % % const PixelPacket *AcquireImagePixels(const Image *image,const ssize_t x, % const ssize_t y,const size_t columns,const size_t rows, % ExceptionInfo *exception) % % A description of each parameter follows: % % o image: the image. % % o x,y,columns,rows: These values define the perimeter of a region of % pixels. % % o exception: return any errors or warnings in this structure. % */ MagickExport const PixelPacket *AcquireImagePixels(const Image *image, const ssize_t x,const ssize_t y,const size_t columns, const size_t rows,ExceptionInfo *exception) { return(GetVirtualPixels(image,x,y,columns,rows,exception)); } /* %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% % % % % % % % A c q u i r e I n d e x e s % % % % % % % %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% % % AcquireIndexes() returns the black channel or the colormap indexes % associated with the last call to QueueAuthenticPixels() or % GetVirtualPixels(). NULL is returned if the black channel or colormap % indexes are not available. % % Deprecated, replace with: % % GetVirtualIndexQueue(image); % % The format of the AcquireIndexes() method is: % % const IndexPacket *AcquireIndexes(const Image *image) % % A description of each parameter follows: % % o indexes: AcquireIndexes() returns the indexes associated with the last % call to QueueAuthenticPixels() or GetVirtualPixels(). % % o image: the image. % */ MagickExport const IndexPacket *AcquireIndexes(const Image *image) { return(GetVirtualIndexQueue(image)); } /* %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% % % % % % % % A c q u i r e M e m o r y % % % % % % % %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% % % AcquireMemory() returns a pointer to a block of memory at least size bytes % suitably aligned for any use. % % The format of the AcquireMemory method is: % % void *AcquireMemory(const size_t size) % % A description of each parameter follows: % % o size: the size of the memory in bytes to allocate. % */ MagickExport void *AcquireMemory(const size_t size) { void *allocation; assert(size != 0); (void) LogMagickEvent(DeprecateEvent,GetMagickModule(),"last use: v5.5.7"); allocation=malloc(size); return(allocation); } /* %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% % % % % % % % A c q u i r e O n e C a c h e V i e w P i x e l % % % % % % % %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% % % AcquireOneCacheViewPixel() returns a single pixel at the specified (x,y) % location. The image background color is returned if an error occurs. If % you plan to modify the pixel, use GetOneCacheViewAuthenticPixel() instead. % % Deprecated, replace with: % % GetOneCacheViewVirtualPixel(cache_view,x,y,pixel,exception); % % The format of the AcquireOneCacheViewPixel method is: % % MagickBooleanType AcquireOneCacheViewPixel(const CacheView *cache_view, % const ssize_t x,const ssize_t y,PixelPacket *pixel,ExceptionInfo *exception) % % A description of each parameter follows: % % o cache_view: the cache view. % % o x,y: These values define the offset of the pixel. % % o pixel: return a pixel at the specified (x,y) location. % % o exception: return any errors or warnings in this structure. % */ MagickExport MagickBooleanType AcquireOneCacheViewPixel( const CacheView *cache_view,const ssize_t x,const ssize_t y,PixelPacket *pixel, ExceptionInfo *exception) { return(GetOneCacheViewVirtualPixel(cache_view,x,y,pixel,exception)); } /* %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% % % % % % % % A c q u i r e O n e C a c h e V i e w V i r t u a l P i x e l % % % % % % % %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% % % AcquireOneCacheViewVirtualPixel() returns a single pixel at the specified % (x,y) location. The image background color is returned if an error occurs. % If you plan to modify the pixel, use GetOneCacheViewAuthenticPixel() instead. % % Deprecated, replace with: % % GetOneCacheViewVirtualMethodPixel(cache_view,virtual_pixel_method, % x,y,pixel,exception); % % The format of the AcquireOneCacheViewPixel method is: % % MagickBooleanType AcquireOneCacheViewVirtualPixel( % const CacheView *cache_view, % const VirtualPixelMethod virtual_pixel_method,const ssize_t x, % const ssize_t y,PixelPacket *pixel,ExceptionInfo *exception) % % A description of each parameter follows: % % o cache_view: the cache view. % % o virtual_pixel_method: the virtual pixel method. % % o x,y: These values define the offset of the pixel. % % o pixel: return a pixel at the specified (x,y) location. % % o exception: return any errors or warnings in this structure. % */ MagickExport MagickBooleanType AcquireOneCacheViewVirtualPixel( const CacheView *cache_view,const VirtualPixelMethod virtual_pixel_method, const ssize_t x,const ssize_t y,PixelPacket *pixel,ExceptionInfo *exception) { MagickBooleanType status; status=GetOneCacheViewVirtualMethodPixel(cache_view,virtual_pixel_method, x,y,pixel,exception); return(status); } /* %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% % % % % % % % A c q u i r e O n e M a g i c k P i x e l % % % % % % % %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% % % AcquireOneMagickPixel() returns a single pixel at the specified (x,y) % location. The image background color is returned if an error occurs. If % you plan to modify the pixel, use GetOnePixel() instead. % % Deprecated, replace with: % % MagickPixelPacket pixel; % GetOneVirtualMagickPixel(image,x,y,&pixel,exception); % % The format of the AcquireOneMagickPixel() method is: % % MagickPixelPacket AcquireOneMagickPixel(const Image image,const ssize_t x, % const ssize_t y,ExceptionInfo exception) % % A description of each parameter follows: % % o image: the image. % % o x,y: These values define the location of the pixel to return. % % o exception: return any errors or warnings in this structure. % */ MagickExport MagickPixelPacket AcquireOneMagickPixel(const Image *image, const ssize_t x,const ssize_t y,ExceptionInfo *exception) { MagickPixelPacket pixel; (void) GetOneVirtualMagickPixel(image,x,y,&pixel,exception); return(pixel); } /* %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% % % % % % % % A c q u i r e O n e P i x e l % % % % % % % %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% % % AcquireOnePixel() returns a single pixel at the specified (x,y) location. % The image background color is returned if an error occurs. If you plan to % modify the pixel, use GetOnePixel() instead. % % Deprecated, replace with: % % PixelPacket pixel; % GetOneVirtualPixel(image,x,y,&pixel,exception); % % The format of the AcquireOnePixel() method is: % % PixelPacket AcquireOnePixel(const Image image,const ssize_t x, % const ssize_t y,ExceptionInfo exception) % % A description of each parameter follows: % % o image: the image. % % o x,y: These values define the location of the pixel to return. % % o exception: return any errors or warnings in this structure. % */ MagickExport PixelPacket AcquireOnePixel(const Image *image,const ssize_t x, const ssize_t y,ExceptionInfo *exception) { PixelPacket pixel; (void) GetOneVirtualPixel(image,x,y,&pixel,exception); return(pixel); } /* %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% % % % % % % % A c q u i r e O n e V i r t u a l P i x e l % % % % % % % %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% % % AcquireOneVirtualPixel() returns a single pixel at the specified (x,y) % location as defined by specified pixel method. The image background color % is returned if an error occurs. If you plan to modify the pixel, use % GetOnePixel() instead. % % Deprecated, replace with: % % PixelPacket pixel; % GetOneVirtualMethodPixel(image,virtual_pixel_method,x,y,&pixel,exception); % % The format of the AcquireOneVirtualPixel() method is: % % PixelPacket AcquireOneVirtualPixel(const Image image, % const VirtualPixelMethod virtual_pixel_method,const ssize_t x, % const ssize_t y,ExceptionInfo exception) % % A description of each parameter follows: % % o virtual_pixel_method: the virtual pixel method. % % o image: the image. % % o x,y: These values define the location of the pixel to return. % % o exception: return any errors or warnings in this structure. % */ MagickExport PixelPacket AcquireOneVirtualPixel(const Image *image, const VirtualPixelMethod virtual_pixel_method,const ssize_t x,const ssize_t y, ExceptionInfo *exception) { PixelPacket pixel; (void) GetOneVirtualMethodPixel(image,virtual_pixel_method,x,y,&pixel, exception); return(pixel); } /* %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% % % % % % % % A c q u i r e P i x e l s % % % % % % % %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% % % AcquirePixels() returns the pixels associated with the last call to % QueueAuthenticPixels() or GetVirtualPixels(). % % Deprecated, replace with: % % GetVirtualPixelQueue(image); % % The format of the AcquirePixels() method is: % % const PixelPacket *AcquirePixels(const Image image) % % A description of each parameter follows: % % o image: the image. % */ MagickExport const PixelPacket *AcquirePixels(const Image *image) { return(GetVirtualPixelQueue(image)); } /* %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% % % % % % % % A f f i n i t y I m a g e % % % % % % % %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% % % AffinityImage() replaces the colors of an image with the closest color from % a reference image. % % Deprecated, replace with: % % RemapImage(quantize_info,image,affinity_image); % % The format of the AffinityImage method is: % % MagickBooleanType AffinityImage(const QuantizeInfo *quantize_info, % Image *image,const Image *affinity_image) % % A description of each parameter follows: % % o quantize_info: Specifies a pointer to an QuantizeInfo structure. % % o image: the image. % % o affinity_image: the reference image. % */ MagickExport MagickBooleanType AffinityImage(const QuantizeInfo *quantize_info, Image *image,const Image *affinity_image) { return(RemapImage(quantize_info,image,affinity_image)); } /* %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% % % % % % % % A f f i n i t y I m a g e s % % % % % % % %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% % % AffinityImages() replaces the colors of a sequence of images with the % closest color from a reference image. % % Deprecated, replace with: % % RemapImages(quantize_info,images,affinity_image); % % The format of the AffinityImage method is: % % MagickBooleanType AffinityImages(const QuantizeInfo *quantize_info, % Image *images,Image *affinity_image) % % A description of each parameter follows: % % o quantize_info: Specifies a pointer to an QuantizeInfo structure. % % o images: the image sequence. % % o affinity_image: the reference image. % */ MagickExport MagickBooleanType AffinityImages(const QuantizeInfo *quantize_info, Image *images,const Image *affinity_image) { return(RemapImages(quantize_info,images,affinity_image)); } /* %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% % % % % % % % A l l o c a t e I m a g e % % % % % % % %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% % % AllocateImage() returns a pointer to an image structure initialized to % default values. % % Deprecated, replace with: % % AcquireImage(image_info); % % The format of the AllocateImage method is: % % Image *AllocateImage(const ImageInfo *image_info) % % A description of each parameter follows: % % o image_info: Many of the image default values are set from this % structure. For example, filename, compression, depth, background color, % and others. % */ MagickExport Image *AllocateImage(const ImageInfo *image_info) { return(AcquireImage(image_info)); } /* %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% % % % % % % % A l l o c a t e I m a g e C o l o r m a p % % % % % % % %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% % % AllocateImageColormap() allocates an image colormap and initializes % it to a linear gray colorspace. If the image already has a colormap, % it is replaced. AllocateImageColormap() returns MagickTrue if successful, % otherwise MagickFalse if there is not enough memory. % % Deprecated, replace with: % % AcquireImageColormap(image,colors); % % The format of the AllocateImageColormap method is: % % MagickBooleanType AllocateImageColormap(Image *image, % const size_t colors) % % A description of each parameter follows: % % o image: the image. % % o colors: the number of colors in the image colormap. % */ MagickExport MagickBooleanType AllocateImageColormap(Image *image, const size_t colors) { return(AcquireImageColormap(image,colors)); } /* %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% % % % % % % % A l l o c a t e N e x t I m a g e % % % % % % % %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% % % AllocateNextImage() initializes the next image in a sequence to % default values. The next member of image points to the newly allocated % image. If there is a memory shortage, next is assigned NULL. % % Deprecated, replace with: % % AcquireNextImage(image_info,image); % % The format of the AllocateNextImage method is: % % void AllocateNextImage(const ImageInfo *image_info,Image *image) % % A description of each parameter follows: % % o image_info: Many of the image default values are set from this % structure. For example, filename, compression, depth, background color, % and others. % % o image: the image. % */ MagickExport void AllocateNextImage(const ImageInfo *image_info,Image *image) { AcquireNextImage(image_info,image); } /* %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% % % % % % % % A l l o c a t e S t r i n g % % % % % % % %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% % % AllocateString() allocates memory for a string and copies the source string % to that memory location (and returns it). % % The format of the AllocateString method is: % % char *AllocateString(const char *source) % % A description of each parameter follows: % % o source: A character string. % */ MagickExport char *AllocateString(const char *source) { char *destination; size_t length; assert(source != (const char *) NULL); (void) LogMagickEvent(DeprecateEvent,GetMagickModule(),"last use: v5.5.7"); length=strlen(source)+MaxTextExtent+1; destination=(char *) AcquireQuantumMemory(length,sizeof(*destination)); if (destination == (char *) NULL) ThrowFatalException(ResourceLimitFatalError,"MemoryAllocationFailed"); *destination='\0'; if (source != (char *) NULL) (void) CopyMagickString(destination,source,length); return(destination); } /* %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% % % % % % % % A v e r a g e I m a g e s % % % % % % % %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% % % AverageImages() takes a set of images and averages them together. Each % image in the set must have the same width and height. AverageImages() % returns a single image with each corresponding pixel component of each % image averaged. On failure, a NULL image is returned and exception % describes the reason for the failure. % % Deprecated, replace with: % % EvaluateImages(images,MeanEvaluateOperator,exception); % % The format of the AverageImages method is: % % Image *AverageImages(Image *images,ExceptionInfo *exception) % % A description of each parameter follows: % % o image: the image sequence. % % o exception: return any errors or warnings in this structure. % */ MagickExport Image *AverageImages(const Image *images,ExceptionInfo *exception) { return(EvaluateImages(images,MeanEvaluateOperator,exception)); } /* %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% % % % % % % % C h a n n e l I m a g e % % % % % % % %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% % % Extract a channel from the image. A channel is a particular color component % of each pixel in the image. % % Deprecated, replace with: % % SeparateImageChannel(image,channel); % % The format of the ChannelImage method is: % % unsigned int ChannelImage(Image *image,const ChannelType channel) % % A description of each parameter follows: % % o image: the image. % % o channel: Identify which channel to extract: RedChannel, GreenChannel, % BlueChannel, OpacityChannel, CyanChannel, MagentaChannel, YellowChannel, % or BlackChannel. % */ MagickExport unsigned int ChannelImage(Image *image,const ChannelType channel) { return(SeparateImageChannel(image,channel)); } /* %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% % % % % % % % C h a n n e l T h r e s h o l d I m a g e % % % % % % % %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% % % ChannelThresholdImage() changes the value of individual pixels based on % the intensity of each pixel channel. The result is a high-contrast image. % % The format of the ChannelThresholdImage method is: % % unsigned int ChannelThresholdImage(Image *image,const char *level) % % A description of each parameter follows: % % o image: the image. % % o level: define the threshold values. % */ MagickExport unsigned int ChannelThresholdImage(Image *image,const char *level) { MagickPixelPacket threshold; GeometryInfo geometry_info; unsigned int flags, status; assert(image != (Image *) NULL); assert(image->signature == MagickSignature); if (image->debug != MagickFalse) (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename); if (image->debug != MagickFalse) (void) LogMagickEvent(DeprecateEvent,GetMagickModule(),"last use: v5.5.7"); if (level == (char *) NULL) return(MagickFalse); flags=ParseGeometry(level,&geometry_info); threshold.red=geometry_info.rho; threshold.green=geometry_info.sigma; if ((flags & SigmaValue) == 0) threshold.green=threshold.red; threshold.blue=geometry_info.xi; if ((flags & XiValue) == 0) threshold.blue=threshold.red; status=BilevelImageChannel(image,RedChannel,threshold.red); status|=BilevelImageChannel(image,GreenChannel,threshold.green); status|=BilevelImageChannel(image,BlueChannel,threshold.blue); return(status); } /* %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% % % % % % % % C l i p I m a g e P a t h % % % % % % % %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% % % ClipPathImage() sets the image clip mask based any clipping path information % if it exists. % % Deprecated, replace with: % % ClipImagePath(image,pathname,inside); % % The format of the ClipImage method is: % % MagickBooleanType ClipPathImage(Image *image,const char *pathname, % const MagickBooleanType inside) % % A description of each parameter follows: % % o image: the image. % % o pathname: name of clipping path resource. If name is preceded by #, use % clipping path numbered by name. % % o inside: if non-zero, later operations take effect inside clipping path. % Otherwise later operations take effect outside clipping path. % */ MagickExport MagickBooleanType ClipPathImage(Image *image,const char *pathname, const MagickBooleanType inside) { return(ClipImagePath(image,pathname,inside)); } /* %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% % % % % % % % C l o n e I m a g e A t t r i b u t e s % % % % % % % %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% % % CloneImageAttributes() clones one or more image attributes. % % Deprecated, replace with: % % CloneImageProperties(image,clone_image); % % The format of the CloneImageAttributes method is: % % MagickBooleanType CloneImageAttributes(Image *image, % const Image *clone_image) % % A description of each parameter follows: % % o image: the image. % % o clone_image: the clone image. % */ MagickExport MagickBooleanType CloneImageAttributes(Image *image, const Image *clone_image) { return(CloneImageProperties(image,clone_image)); } /* %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% % % % % % % % C l o n e M e m o r y % % % % % % % %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% % % CloneMemory() copies size bytes from memory area source to the destination. % Copying between objects that overlap will take place correctly. It returns % destination. % % The format of the CloneMemory method is: % % void *CloneMemory(void *destination,const void *source, % const size_t size) % % A description of each parameter follows: % % o destination: the destination. % % o source: the source. % % o size: the size of the memory in bytes to allocate. % */ MagickExport void *CloneMemory(void *destination,const void *source, const size_t size) { register const unsigned char *p; register unsigned char *q; register ssize_t i; assert(destination != (void *) NULL); assert(source != (const void *) NULL); (void) LogMagickEvent(DeprecateEvent,GetMagickModule(),"last use: v5.5.7"); p=(const unsigned char *) source; q=(unsigned char *) destination; if ((p <= q) || ((p+size) >= q)) return(CopyMagickMemory(destination,source,size)); /* Overlap, copy backwards. */ p+=size; q+=size; for (i=(ssize_t) (size-1); i >= 0; i--) *--q=(*--p); return(destination); } /* %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% % % % % % % % C l o s e C a c h e V i e w % % % % % % % %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% % % CloseCacheView() closes the specified view returned by a previous call to % OpenCacheView(). % % Deprecated, replace with: % % DestroyCacheView(view_info); % % The format of the CloseCacheView method is: % % CacheView *CloseCacheView(CacheView *view_info) % % A description of each parameter follows: % % o view_info: the address of a structure of type CacheView. % */ MagickExport CacheView *CloseCacheView(CacheView *view_info) { return(DestroyCacheView(view_info)); } /* %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% % % % % % % % C o l o r F l o o d f i l l I m a g e % % % % % % % %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% % % ColorFloodfill() changes the color value of any pixel that matches % target and is an immediate neighbor. If the method FillToBorderMethod is % specified, the color value is changed for any neighbor pixel that does not % match the bordercolor member of image. % % By default target must match a particular pixel color exactly. % However, in many cases two colors may differ by a small amount. The % fuzz member of image defines how much tolerance is acceptable to % consider two colors as the same. For example, set fuzz to 10 and the % color red at intensities of 100 and 102 respectively are now % interpreted as the same color for the purposes of the floodfill. % % The format of the ColorFloodfillImage method is: % % MagickBooleanType ColorFloodfillImage(Image *image, % const DrawInfo *draw_info,const PixelPacket target, % const ssize_t x_offset,const ssize_t y_offset,const PaintMethod method) % % A description of each parameter follows: % % o image: the image. % % o draw_info: the draw info. % % o target: the RGB value of the target color. % % o x,y: the starting location of the operation. % % o method: Choose either FloodfillMethod or FillToBorderMethod. % */ #define MaxStacksize (1UL << 15) #define PushSegmentStack(up,left,right,delta) \ { \ if (s >= (segment_stack+MaxStacksize)) \ ThrowBinaryException(DrawError,"SegmentStackOverflow",image->filename) \ else \ { \ if ((((up)+(delta)) >= 0) && (((up)+(delta)) < (ssize_t) image->rows)) \ { \ s->x1=(double) (left); \ s->y1=(double) (up); \ s->x2=(double) (right); \ s->y2=(double) (delta); \ s++; \ } \ } \ } MagickExport MagickBooleanType ColorFloodfillImage(Image *image, const DrawInfo *draw_info,const PixelPacket target,const ssize_t x_offset, const ssize_t y_offset,const PaintMethod method) { Image *floodplane_image; MagickBooleanType skip; PixelPacket fill_color; register SegmentInfo *s; SegmentInfo *segment_stack; ssize_t offset, start, x, x1, x2, y; /* Check boundary conditions. */ assert(image != (Image *) NULL); assert(image->signature == MagickSignature); if (image->debug != MagickFalse) (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename); assert(draw_info != (DrawInfo *) NULL); assert(draw_info->signature == MagickSignature); if ((x_offset < 0) || (x_offset >= (ssize_t) image->columns)) return(MagickFalse); if ((y_offset < 0) || (y_offset >= (ssize_t) image->rows)) return(MagickFalse); if (SetImageStorageClass(image,DirectClass) == MagickFalse) return(MagickFalse); if (image->matte == MagickFalse) (void) SetImageAlphaChannel(image,OpaqueAlphaChannel); floodplane_image=CloneImage(image,image->columns,image->rows,MagickTrue, &image->exception); if (floodplane_image == (Image *) NULL) return(MagickFalse); (void) SetImageAlphaChannel(floodplane_image,OpaqueAlphaChannel); /* Set floodfill color. */ segment_stack=(SegmentInfo *) AcquireQuantumMemory(MaxStacksize, sizeof(*segment_stack)); if (segment_stack == (SegmentInfo *) NULL) { floodplane_image=DestroyImage(floodplane_image); ThrowBinaryException(ResourceLimitError,"MemoryAllocationFailed", image->filename); } /* Push initial segment on stack. */ x=x_offset; y=y_offset; start=0; s=segment_stack; PushSegmentStack(y,x,x,1); PushSegmentStack(y+1,x,x,-1); while (s > segment_stack) { register const PixelPacket *restrict p; register ssize_t x; register PixelPacket *restrict q; /* Pop segment off stack. */ s--; x1=(ssize_t) s->x1; x2=(ssize_t) s->x2; offset=(ssize_t) s->y2; y=(ssize_t) s->y1+offset; /* Recolor neighboring pixels. */ p=GetVirtualPixels(image,0,y,(size_t) (x1+1),1,&image->exception); q=GetAuthenticPixels(floodplane_image,0,y,(size_t) (x1+1),1, &image->exception); if ((p == (const PixelPacket *) NULL) || (q == (PixelPacket *) NULL)) break; p+=x1; q+=x1; for (x=x1; x >= 0; x--) { if (q->opacity == (Quantum) TransparentOpacity) break; if (method == FloodfillMethod) { if (IsColorSimilar(image,p,&target) == MagickFalse) break; } else if (IsColorSimilar(image,p,&target) != MagickFalse) break; q->opacity=(Quantum) TransparentOpacity; p--; q--; } if (SyncAuthenticPixels(floodplane_image,&image->exception) == MagickFalse) break; skip=x >= x1 ? MagickTrue : MagickFalse; if (skip == MagickFalse) { start=x+1; if (start < x1) PushSegmentStack(y,start,x1-1,-offset); x=x1+1; } do { if (skip == MagickFalse) { if (x < (ssize_t) image->columns) { p=GetVirtualPixels(image,x,y,image->columns-x,1, &image->exception); q=GetAuthenticPixels(floodplane_image,x,y,image->columns-x,1, &image->exception); if ((p == (const PixelPacket *) NULL) || (q == (PixelPacket *) NULL)) break; for ( ; x < (ssize_t) image->columns; x++) { if (q->opacity == (Quantum) TransparentOpacity) break; if (method == FloodfillMethod) { if (IsColorSimilar(image,p,&target) == MagickFalse) break; } else if (IsColorSimilar(image,p,&target) != MagickFalse) break; q->opacity=(Quantum) TransparentOpacity; p++; q++; } if (SyncAuthenticPixels(floodplane_image,&image->exception) == MagickFalse) break; } PushSegmentStack(y,start,x-1,offset); if (x > (x2+1)) PushSegmentStack(y,x2+1,x-1,-offset); } skip=MagickFalse; x++; if (x <= x2) { p=GetVirtualPixels(image,x,y,(size_t) (x2-x+1),1, &image->exception); q=GetAuthenticPixels(floodplane_image,x,y,(size_t) (x2-x+1),1, &image->exception); if ((p == (const PixelPacket *) NULL) || (q == (PixelPacket *) NULL)) break; for ( ; x <= x2; x++) { if (q->opacity == (Quantum) TransparentOpacity) break; if (method == FloodfillMethod) { if (IsColorSimilar(image,p,&target) != MagickFalse) break; } else if (IsColorSimilar(image,p,&target) == MagickFalse) break; p++; q++; } } start=x; } while (x <= x2); } for (y=0; y < (ssize_t) image->rows; y++) { register const PixelPacket *restrict p; register ssize_t x; register PixelPacket *restrict q; /* Tile fill color onto floodplane. */ p=GetVirtualPixels(floodplane_image,0,y,image->columns,1, &image->exception); q=GetAuthenticPixels(image,0,y,image->columns,1,&image->exception); if ((p == (const PixelPacket *) NULL) || (q == (PixelPacket *) NULL)) break; for (x=0; x < (ssize_t) image->columns; x++) { if (GetPixelOpacity(p) != OpaqueOpacity) { (void) GetFillColor(draw_info,x,y,&fill_color); MagickCompositeOver(&fill_color,(MagickRealType) fill_color.opacity,q, (MagickRealType) q->opacity,q); } p++; q++; } if (SyncAuthenticPixels(image,&image->exception) == MagickFalse) break; } segment_stack=(SegmentInfo *) RelinquishMagickMemory(segment_stack); floodplane_image=DestroyImage(floodplane_image); return(y == (ssize_t) image->rows ? MagickTrue : MagickFalse); } /* %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% % % % % % % % D e l e t e I m a g e A t t r i b u t e % % % % % % % %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% % % DeleteImageAttribute() deletes an attribute from the image. % % Deprecated, replace with: % % DeleteImageProperty(image,key); % % The format of the DeleteImageAttribute method is: % % MagickBooleanType DeleteImageAttribute(Image *image,const char *key) % % A description of each parameter follows: % % o image: the image info. % % o key: the image key. % */ MagickExport MagickBooleanType DeleteImageAttribute(Image *image, const char *key) { return(DeleteImageProperty(image,key)); } /* %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% % % % % % % % D e l e t e I m a g e L i s t % % % % % % % %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% % % DeleteImageList() deletes an image at the specified position in the list. % % The format of the DeleteImageList method is: % % unsigned int DeleteImageList(Image *images,const ssize_t offset) % % A description of each parameter follows: % % o images: the image list. % % o offset: the position within the list. % */ MagickExport unsigned int DeleteImageList(Image *images,const ssize_t offset) { register ssize_t i; if (images->debug != MagickFalse) (void) LogMagickEvent(DeprecateEvent,GetMagickModule(),"last use: v5.5.2"); while (GetPreviousImageInList(images) != (Image *) NULL) images=GetPreviousImageInList(images); for (i=0; i < offset; i++) { if (GetNextImageInList(images) == (Image *) NULL) return(MagickFalse); images=GetNextImageInList(images); } DeleteImageFromList(&images); return(MagickTrue); } /* %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% % % % % % % % D e l e t e M a g i c k R e g i s t r y % % % % % % % %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% % % DeleteMagickRegistry() deletes an entry in the registry as defined by the id. % It returns MagickTrue if the entry is deleted otherwise MagickFalse if no % entry is found in the registry that matches the id. % % Deprecated, replace with: % % char key[MaxTextExtent]; % FormatLocaleString(key,MaxTextExtent,"%ld\n",id); % DeleteImageRegistry(key); % % The format of the DeleteMagickRegistry method is: % % MagickBooleanType DeleteMagickRegistry(const ssize_t id) % % A description of each parameter follows: % % o id: the registry id. % */ MagickExport MagickBooleanType DeleteMagickRegistry(const ssize_t id) { char key[MaxTextExtent]; (void) FormatLocaleString(key,MaxTextExtent,"%.20g\n",(double) id); return(DeleteImageRegistry(key)); } /* %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% % % % % % % + D e s t r o y C o n s t i t u t e % % % % % % % %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% % % DestroyConstitute() destroys the constitute component. % % The format of the DestroyConstitute method is: % % DestroyConstitute(void) % */ MagickExport void DestroyConstitute(void) { ConstituteComponentTerminus(); } /* %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% % % % % % % + D e s t r o y M a g i c k R e g i s t r y % % % % % % % %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% % % DestroyMagickRegistry() deallocates memory associated the magick registry. % % Deprecated, replace with: % % RegistryComponentTerminus(); % % The format of the DestroyMagickRegistry method is: % % void DestroyMagickRegistry(void) % */ MagickExport void DestroyMagickRegistry(void) { RegistryComponentTerminus(); } /* %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% % % % % % % % D e s c r i b e I m a g e % % % % % % % %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% % % DescribeImage() describes an image by printing its attributes to the file. % Attributes include the image width, height, size, and others. % % Deprecated, replace with: % % IdentifyImage(image,file,verbose); % % The format of the DescribeImage method is: % % MagickBooleanType DescribeImage(Image *image,FILE *file, % const MagickBooleanType verbose) % % A description of each parameter follows: % % o image: the image. % % o file: the file, typically stdout. % % o verbose: A value other than zero prints more detailed information % about the image. % */ MagickExport MagickBooleanType DescribeImage(Image *image,FILE *file, const MagickBooleanType verbose) { return(IdentifyImage(image,file,verbose)); } /* %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% % % % % % % % D e s t r o y I m a g e A t t r i b u t e s % % % % % % % %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% % % DestroyImageAttributes() deallocates memory associated with the image % attribute list. % % The format of the DestroyImageAttributes method is: % % DestroyImageAttributes(Image *image) % % A description of each parameter follows: % % o image: the image. % */ MagickExport void DestroyImageAttributes(Image *image) { assert(image != (Image *) NULL); assert(image->signature == MagickSignature); if (image->debug != MagickFalse) (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename); if (image->attributes != (void *) NULL) image->attributes=(void *) DestroySplayTree((SplayTreeInfo *) image->attributes); } /* %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% % % % % % % % D e s t r o y I m a g e s % % % % % % % %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% % % DestroyImages() destroys an image list. % % Deprecated, replace with: % % DestroyImageList(image); % % The format of the DestroyImages method is: % % void DestroyImages(Image *image) % % A description of each parameter follows: % % o image: the image sequence. % */ MagickExport void DestroyImages(Image *image) { if (image == (Image *) NULL) return; if (image->debug != MagickFalse) (void) LogMagickEvent(DeprecateEvent,GetMagickModule(),"last use: v5.4.3"); image=DestroyImageList(image); } /* %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% % % % % % % % D e s t r o y M a g i c k % % % % % % % %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% % % DestroyMagick() destroys the ImageMagick environment. % % Deprecated, replace with: % % MagickCoreTerminus(); % % The format of the DestroyMagick function is: % % DestroyMagick(void) % */ MagickExport void DestroyMagick(void) { MagickCoreTerminus(); } /* %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% % % % % % % % D i s p a t c h I m a g e % % % % % % % %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% % % DispatchImage() extracts pixel data from an image and returns it to you. % The method returns MagickFalse on success otherwise MagickTrue if an error is % encountered. The data is returned as char, short int, int, ssize_t, float, % or double in the order specified by map. % % Suppose you want to extract the first scanline of a 640x480 image as % character data in red-green-blue order: % % DispatchImage(image,0,0,640,1,"RGB",CharPixel,pixels,exception); % % Deprecated, replace with: % % ExportImagePixels(image,x_offset,y_offset,columns,rows,map,type,pixels, % exception); % % The format of the DispatchImage method is: % % unsigned int DispatchImage(const Image *image,const ssize_t x_offset, % const ssize_t y_offset,const size_t columns, % const size_t rows,const char *map,const StorageType type, % void *pixels,ExceptionInfo *exception) % % A description of each parameter follows: % % o image: the image. % % o x_offset, y_offset, columns, rows: These values define the perimeter % of a region of pixels you want to extract. % % o map: This string reflects the expected ordering of the pixel array. % It can be any combination or order of R = red, G = green, B = blue, % A = alpha, C = cyan, Y = yellow, M = magenta, K = black, or % I = intensity (for grayscale). % % o type: Define the data type of the pixels. Float and double types are % normalized to [0..1] otherwise [0..QuantumRange]. Choose from these % types: CharPixel, ShortPixel, IntegerPixel, LongPixel, FloatPixel, or % DoublePixel. % % o pixels: This array of values contain the pixel components as defined by % map and type. You must preallocate this array where the expected % length varies depending on the values of width, height, map, and type. % % o exception: return any errors or warnings in this structure. % */ MagickExport unsigned int DispatchImage(const Image *image,const ssize_t x_offset, const ssize_t y_offset,const size_t columns,const size_t rows, const char *map,const StorageType type,void *pixels,ExceptionInfo *exception) { unsigned int status; if (image->debug != MagickFalse) (void) LogMagickEvent(DeprecateEvent,GetMagickModule(),"last use: v5.5.6"); status=ExportImagePixels(image,x_offset,y_offset,columns,rows,map,type,pixels, exception); return(status); } /* %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% % % % % % % % E x t r a c t S u b i m a g e F r o m I m a g e % % % % % % % %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% % % ExtractSubimageFromImageImage() extracts a region of the image that most % closely resembles the reference. % % The format of the ExtractSubimageFromImageImage method is: % % Image *ExtractSubimageFromImage(const Image *image, % const Image *reference,ExceptionInfo *exception) % % A description of each parameter follows: % % o image: the image. % % o reference: find an area of the image that closely resembles this image. % % o exception: return any errors or warnings in this structure. % */ static double GetSimilarityMetric(const Image *image,const Image *reference, const ssize_t x_offset,const ssize_t y_offset, const double similarity_threshold,ExceptionInfo *exception) { CacheView *image_view, *reference_view; double channels, normalized_similarity, similarity; ssize_t y; /* Compute the similarity in pixels between two images. */ normalized_similarity=1.0; similarity=0.0; channels=3; if ((image->matte != MagickFalse) && (reference->matte != MagickFalse)) channels++; if ((image->colorspace == CMYKColorspace) && (reference->colorspace == CMYKColorspace)) channels++; image_view=AcquireCacheView(image); reference_view=AcquireCacheView(reference); for (y=0; y < (ssize_t) reference->rows; y++) { register const IndexPacket *indexes, *reference_indexes; register const PixelPacket *p, *q; register ssize_t x; p=GetCacheViewVirtualPixels(image_view,x_offset,y_offset+y, reference->columns,1,exception); q=GetCacheViewVirtualPixels(reference_view,0,y,reference->columns,1, exception); if ((p == (const PixelPacket *) NULL) || (q == (const PixelPacket *) NULL)) continue; indexes=GetCacheViewVirtualIndexQueue(image_view); reference_indexes=GetCacheViewVirtualIndexQueue(reference_view); for (x=0; x < (ssize_t) reference->columns; x++) { MagickRealType pixel; pixel=QuantumScale*(GetPixelRed(p)-(double) GetPixelRed(q)); similarity+=pixel*pixel; pixel=QuantumScale*(GetPixelGreen(p)-(double) GetPixelGreen(q)); similarity+=pixel*pixel; pixel=QuantumScale*(GetPixelBlue(p)-(double) GetPixelBlue(q)); similarity+=pixel*pixel; if ((image->matte != MagickFalse) && (reference->matte != MagickFalse)) { pixel=QuantumScale*(GetPixelOpacity(p)-(double) GetPixelOpacity(q)); similarity+=pixel*pixel; } if ((image->colorspace == CMYKColorspace) && (reference->colorspace == CMYKColorspace)) { pixel=QuantumScale*(GetPixelIndex(indexes+x)-(double) GetPixelIndex(reference_indexes+x)); similarity+=pixel*pixel; } p++; q++; } normalized_similarity=sqrt(similarity)/reference->columns/reference->rows/ channels; if (normalized_similarity > similarity_threshold) break; } reference_view=DestroyCacheView(reference_view); image_view=DestroyCacheView(image_view); return(normalized_similarity); } MagickExport Image *ExtractSubimageFromImage(Image *image, const Image *reference,ExceptionInfo *exception) { double similarity_threshold; RectangleInfo offset; ssize_t y; /* Extract reference from image. */ if ((reference->columns > image->columns) || (reference->rows > image->rows)) return((Image *) NULL); similarity_threshold=(double) image->columns*image->rows; SetGeometry(reference,&offset); #if defined(MAGICKCORE_OPENMP_SUPPORT) #pragma omp parallel for schedule(dynamic,4) #endif for (y=0; y < (ssize_t) (image->rows-reference->rows); y++) { double similarity; register ssize_t x; for (x=0; x < (ssize_t) (image->columns-reference->columns); x++) { similarity=GetSimilarityMetric(image,reference,x,y,similarity_threshold, exception); #if defined(MAGICKCORE_OPENMP_SUPPORT) #pragma omp critical (MagickCore_ExtractSubimageFromImage) #endif if (similarity < similarity_threshold) { similarity_threshold=similarity; offset.x=x; offset.y=y; } } } if (similarity_threshold > (QuantumScale*reference->fuzz/100.0)) return((Image *) NULL); return(CropImage(image,&offset,exception)); } /* %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% % % % % % % % F l a t t e n I m a g e % % % % % % % %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% % % FlattenImages() Obsolete Function: Use MergeImageLayers() instead. % % Deprecated, replace with: % % MergeImageLayers(image,FlattenLayer,exception); % % The format of the FlattenImage method is: % % Image *FlattenImage(Image *image,ExceptionInfo *exception) % % A description of each parameter follows: % % o image: the image sequence. % % o exception: return any errors or warnings in this structure. % */ MagickExport Image *FlattenImages(Image *image,ExceptionInfo *exception) { return(MergeImageLayers(image,FlattenLayer,exception)); } /* %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% % % % % % % % F o r m a t I m a g e A t t r i b u t e % % % % % % % %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% % % FormatImageAttribute() permits formatted key/value pairs to be saved as an % image attribute. % % The format of the FormatImageAttribute method is: % % MagickBooleanType FormatImageAttribute(Image *image,const char *key, % const char *format,...) % % A description of each parameter follows. % % o image: The image. % % o key: The attribute key. % % o format: A string describing the format to use to write the remaining % arguments. % */ MagickExport MagickBooleanType FormatImageAttributeList(Image *image, const char *key,const char *format,va_list operands) { char value[MaxTextExtent]; int n; #if defined(MAGICKCORE_HAVE_VSNPRINTF) n=vsnprintf(value,MaxTextExtent,format,operands); #else n=vsprintf(value,format,operands); #endif if (n < 0) value[MaxTextExtent-1]='\0'; return(SetImageProperty(image,key,value)); } MagickExport MagickBooleanType FormatImagePropertyList(Image *image, const char *property,const char *format,va_list operands) { char value[MaxTextExtent]; int n; #if defined(MAGICKCORE_HAVE_VSNPRINTF) n=vsnprintf(value,MaxTextExtent,format,operands); #else n=vsprintf(value,format,operands); #endif if (n < 0) value[MaxTextExtent-1]='\0'; return(SetImageProperty(image,property,value)); } MagickExport MagickBooleanType FormatImageAttribute(Image *image, const char *key,const char *format,...) { char value[MaxTextExtent]; int n; va_list operands; va_start(operands,format); n=FormatLocaleStringList(value,MaxTextExtent,format,operands); (void) n; va_end(operands); return(SetImageProperty(image,key,value)); } /* %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% % % % % % % % F o r m a t M a g i c k S t r i n g % % % % % % % %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% % % FormatMagickString() prints formatted output of a variable argument list. % % The format of the FormatMagickString method is: % % ssize_t FormatMagickString(char *string,const size_t length, % const char *format,...) % % A description of each parameter follows. % % o string: FormatMagickString() returns the formatted string in this % character buffer. % % o length: the maximum length of the string. % % o format: A string describing the format to use to write the remaining % arguments. % */ MagickExport ssize_t FormatMagickStringList(char *string,const size_t length, const char *format,va_list operands) { int n; #if defined(MAGICKCORE_HAVE_VSNPRINTF) n=vsnprintf(string,length,format,operands); #else n=vsprintf(string,format,operands); #endif if (n < 0) string[length-1]='\0'; return((ssize_t) n); } MagickExport ssize_t FormatMagickString(char *string,const size_t length, const char *format,...) { ssize_t n; va_list operands; va_start(operands,format); n=(ssize_t) FormatMagickStringList(string,length,format,operands); va_end(operands); return(n); } /* %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% % % % % % % % F o r m a t S t r i n g % % % % % % % %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% % % FormatString() prints formatted output of a variable argument list. % % The format of the FormatString method is: % % void FormatString(char *string,const char *format,...) % % A description of each parameter follows. % % o string: Method FormatString returns the formatted string in this % character buffer. % % o format: A string describing the format to use to write the remaining % arguments. % */ MagickExport void FormatStringList(char *string,const char *format, va_list operands) { int n; (void) LogMagickEvent(DeprecateEvent,GetMagickModule(),"last use: v5.5.7"); #if defined(MAGICKCORE_HAVE_VSNPRINTF) n=vsnprintf(string,MaxTextExtent,format,operands); #else n=vsprintf(string,format,operands); #endif if (n < 0) string[MaxTextExtent-1]='\0'; } MagickExport void FormatString(char *string,const char *format,...) { va_list operands; va_start(operands,format); (void) FormatLocaleStringList(string,MaxTextExtent,format,operands); va_end(operands); return; } /* %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% % % % % % % + F u z z y C o l o r M a t c h % % % % % % % %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% % % FuzzyColorMatch() returns true if two pixels are identical in color. % % The format of the ColorMatch method is: % % void FuzzyColorMatch(const PixelPacket *p,const PixelPacket *q, % const double fuzz) % % A description of each parameter follows: % % o p: Pixel p. % % o q: Pixel q. % % o distance: Define how much tolerance is acceptable to consider % two colors as the same. % */ MagickExport unsigned int FuzzyColorMatch(const PixelPacket *p, const PixelPacket *q,const double fuzz) { MagickPixelPacket pixel; register MagickRealType distance; if ((fuzz == 0.0) && (GetPixelRed(p) == GetPixelRed(q)) && (GetPixelGreen(p) == GetPixelGreen(q)) && (GetPixelBlue(p) == GetPixelBlue(q))) return(MagickTrue); pixel.red=GetPixelRed(p)-(MagickRealType) GetPixelRed(q); distance=pixel.red*pixel.red; if (distance > (fuzz*fuzz)) return(MagickFalse); pixel.green=GetPixelGreen(p)-(MagickRealType) GetPixelGreen(q); distance+=pixel.green*pixel.green; if (distance > (fuzz*fuzz)) return(MagickFalse); pixel.blue=GetPixelBlue(p)-(MagickRealType) GetPixelBlue(q); distance+=pixel.blue*pixel.blue; if (distance > (fuzz*fuzz)) return(MagickFalse); return(MagickTrue); } /* %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% % % % % % % + F u z z y C o l o r C o m p a r e % % % % % % % %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% % % FuzzyColorCompare() returns MagickTrue if the distance between two colors is % less than the specified distance in a linear three dimensional color space. % This method is used by ColorFloodFill() and other algorithms which % compare two colors. % % The format of the FuzzyColorCompare method is: % % void FuzzyColorCompare(const Image *image,const PixelPacket *p, % const PixelPacket *q) % % A description of each parameter follows: % % o image: the image. % % o p: Pixel p. % % o q: Pixel q. % */ MagickExport MagickBooleanType FuzzyColorCompare(const Image *image, const PixelPacket *p,const PixelPacket *q) { (void) LogMagickEvent(DeprecateEvent,GetMagickModule(),"last use: v6.2.5"); return(IsColorSimilar(image,p,q)); } /* %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% % % % % % % + F u z z y O p a c i t y C o m p a r e % % % % % % % %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% % % FuzzyOpacityCompare() returns true if the distance between two opacity % values is less than the specified distance in a linear color space. This % method is used by MatteFloodFill() and other algorithms which compare % two opacity values. % % Deprecated, replace with: % % IsOpacitySimilar(image,p,q); % % The format of the FuzzyOpacityCompare method is: % % void FuzzyOpacityCompare(const Image *image,const PixelPacket *p, % const PixelPacket *q) % % A description of each parameter follows: % % o image: the image. % % o p: Pixel p. % % o q: Pixel q. % */ MagickExport MagickBooleanType FuzzyOpacityCompare(const Image *image, const PixelPacket *p,const PixelPacket *q) { (void) LogMagickEvent(DeprecateEvent,GetMagickModule(),"last use: v6.2.5"); return(IsOpacitySimilar(image,p,q)); } /* %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% % % % % % % % G e t C o n f i g u r e B l o b % % % % % % % %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% % % GetConfigureBlob() returns the specified configure file as a blob. % % The format of the GetConfigureBlob method is: % % void *GetConfigureBlob(const char *filename,ExceptionInfo *exception) % % A description of each parameter follows: % % o filename: the configure file name. % % o path: return the full path information of the configure file. % % o length: This pointer to a size_t integer sets the initial length of the % blob. On return, it reflects the actual length of the blob. % % o exception: return any errors or warnings in this structure. % */ MagickExport void *GetConfigureBlob(const char *filename,char *path, size_t *length,ExceptionInfo *exception) { void *blob; assert(filename != (const char *) NULL); (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",filename); (void) LogMagickEvent(DeprecateEvent,GetMagickModule(),"last use: v5.5.7"); assert(path != (char *) NULL); assert(length != (size_t *) NULL); assert(exception != (ExceptionInfo *) NULL); blob=(void *) NULL; (void) CopyMagickString(path,filename,MaxTextExtent); #if defined(MAGICKCORE_INSTALLED_SUPPORT) #if defined(MAGICKCORE_LIBRARY_PATH) if (blob == (void *) NULL) { /* Search hard coded paths. */ (void) FormatLocaleString(path,MaxTextExtent,"%s%s", MAGICKCORE_LIBRARY_PATH,filename); if (IsPathAccessible(path) != MagickFalse) blob=FileToBlob(path,~0,length,exception); } #endif #if defined(MAGICKCORE_WINDOWS_SUPPORT) && !(defined(MAGICKCORE_CONFIGURE_PATH) || defined(MAGICKCORE_SHARE_PATH)) if (blob == (void *) NULL) { char *key_value; /* Locate file via registry key. */ key_value=NTRegistryKeyLookup("ConfigurePath"); if (key_value != (char *) NULL) { (void) FormatLocaleString(path,MaxTextExtent,"%s%s%s",key_value, DirectorySeparator,filename); if (IsPathAccessible(path) != MagickFalse) blob=FileToBlob(path,~0,length,exception); } } #endif #else if (blob == (void *) NULL) { char *home; home=GetEnvironmentValue("MAGICK_HOME"); if (home != (char *) NULL) { /* Search MAGICK_HOME. */ #if !defined(MAGICKCORE_POSIX_SUPPORT) (void) FormatLocaleString(path,MaxTextExtent,"%s%s%s",home, DirectorySeparator,filename); #else (void) FormatLocaleString(path,MaxTextExtent,"%s/lib/%s/%s",home, MAGICKCORE_LIBRARY_RELATIVE_PATH,filename); #endif if (IsPathAccessible(path) != MagickFalse) blob=FileToBlob(path,~0,length,exception); home=DestroyString(home); } home=GetEnvironmentValue("HOME"); if (home == (char *) NULL) home=GetEnvironmentValue("USERPROFILE"); if (home != (char *) NULL) { /* Search $HOME/.magick. */ (void) FormatLocaleString(path,MaxTextExtent,"%s%s.magick%s%s",home, DirectorySeparator,DirectorySeparator,filename); if ((IsPathAccessible(path) != MagickFalse) && (blob == (void *) NULL)) blob=FileToBlob(path,~0,length,exception); home=DestroyString(home); } } if ((blob == (void *) NULL) && (*GetClientPath() != '\0')) { #if !defined(MAGICKCORE_POSIX_SUPPORT) (void) FormatLocaleString(path,MaxTextExtent,"%s%s%s",GetClientPath(), DirectorySeparator,filename); #else char prefix[MaxTextExtent]; /* Search based on executable directory if directory is known. */ (void) CopyMagickString(prefix,GetClientPath(), MaxTextExtent); ChopPathComponents(prefix,1); (void) FormatLocaleString(path,MaxTextExtent,"%s/lib/%s/%s",prefix, MAGICKCORE_LIBRARY_RELATIVE_PATH,filename); #endif if (IsPathAccessible(path) != MagickFalse) blob=FileToBlob(path,~0,length,exception); } /* Search current directory. */ if ((blob == (void *) NULL) && (IsPathAccessible(path) != MagickFalse)) blob=FileToBlob(path,~0,length,exception); #if defined(MAGICKCORE_WINDOWS_SUPPORT) /* Search Windows registry. */ if (blob == (void *) NULL) blob=NTResourceToBlob(filename); #endif #endif if (blob == (void *) NULL) (void) ThrowMagickException(exception,GetMagickModule(),ConfigureWarning, "UnableToOpenConfigureFile","`%s'",path); return(blob); } /* %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% % % % % % % % G e t C a c h e V i e w % % % % % % % %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% % % GetCacheView() gets pixels from the in-memory or disk pixel cache as % defined by the geometry parameters. A pointer to the pixels is returned if % the pixels are transferred, otherwise a NULL is returned. % % Deprecated, replace with: % % GetCacheViewAuthenticPixels(cache_view,x,y,columns,rows, % GetCacheViewException(cache_view)); % % The format of the GetCacheView method is: % % PixelPacket *GetCacheView(CacheView *cache_view,const ssize_t x, % const ssize_t y,const size_t columns,const size_t rows) % % A description of each parameter follows: % % o cache_view: the address of a structure of type CacheView. % % o x,y,columns,rows: These values define the perimeter of a region of % pixels. % */ MagickExport PixelPacket *GetCacheView(CacheView *cache_view,const ssize_t x, const ssize_t y,const size_t columns,const size_t rows) { PixelPacket *pixels; pixels=GetCacheViewAuthenticPixels(cache_view,x,y,columns,rows, GetCacheViewException(cache_view)); return(pixels); } /* %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% % % % % % % % G e t C a c h e V i e w I n d e x e s % % % % % % % %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% % % GetCacheViewIndexes() returns the indexes associated with the specified % view. % % Deprecated, replace with: % % GetCacheViewAuthenticIndexQueue(cache_view); % % The format of the GetCacheViewIndexes method is: % % IndexPacket *GetCacheViewIndexes(CacheView *cache_view) % % A description of each parameter follows: % % o cache_view: the cache view. % */ MagickExport IndexPacket *GetCacheViewIndexes(CacheView *cache_view) { return(GetCacheViewAuthenticIndexQueue(cache_view)); } /* %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% % % % % % % % G e t C a c h e V i e w P i x e l s % % % % % % % %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% % % GetCacheViewPixels() gets pixels from the in-memory or disk pixel cache as % defined by the geometry parameters. A pointer to the pixels is returned if % the pixels are transferred, otherwise a NULL is returned. % % Deprecated, replace with: % % GetCacheViewAuthenticPixels(cache_view,x,y,columns,rows, % GetCacheViewException(cache_view)); % % The format of the GetCacheViewPixels method is: % % PixelPacket *GetCacheViewPixels(CacheView *cache_view,const ssize_t x, % const ssize_t y,const size_t columns,const size_t rows) % % A description of each parameter follows: % % o cache_view: the cache view. % % o x,y,columns,rows: These values define the perimeter of a region of % pixels. % */ MagickExport PixelPacket *GetCacheViewPixels(CacheView *cache_view,const ssize_t x, const ssize_t y,const size_t columns,const size_t rows) { PixelPacket *pixels; pixels=GetCacheViewAuthenticPixels(cache_view,x,y,columns,rows, GetCacheViewException(cache_view)); return(pixels); } /* %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% % % % % % % % G e t I m a g e A t t r i b u t e % % % % % % % %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% % % GetImageAttribute() searches the list of image attributes and returns % a pointer to the attribute if it exists otherwise NULL. % % The format of the GetImageAttribute method is: % % const ImageAttribute *GetImageAttribute(const Image *image, % const char *key) % % A description of each parameter follows: % % o image: the image. % % o key: These character strings are the name of an image attribute to % return. % */ static void *DestroyAttribute(void *attribute) { register ImageAttribute *p; p=(ImageAttribute *) attribute; if (p->value != (char *) NULL) p->value=DestroyString(p->value); return(RelinquishMagickMemory(p)); } MagickExport const ImageAttribute *GetImageAttribute(const Image *image, const char *key) { const char *value; ImageAttribute *attribute; (void) LogMagickEvent(DeprecateEvent,GetMagickModule(),"last use: v6.3.1"); value=GetImageProperty(image,key); if (value == (const char *) NULL) return((const ImageAttribute *) NULL); if (image->attributes == (void *) NULL) ((Image *) image)->attributes=NewSplayTree(CompareSplayTreeString, RelinquishMagickMemory,DestroyAttribute); else { const ImageAttribute *attribute; attribute=(const ImageAttribute *) GetValueFromSplayTree((SplayTreeInfo *) image->attributes,key); if (attribute != (const ImageAttribute *) NULL) return(attribute); } attribute=(ImageAttribute *) AcquireMagickMemory(sizeof(*attribute)); if (attribute == (ImageAttribute *) NULL) ThrowFatalException(ResourceLimitFatalError,"MemoryAllocationFailed"); (void) ResetMagickMemory(attribute,0,sizeof(*attribute)); attribute->key=ConstantString(key); attribute->value=ConstantString(value); (void) AddValueToSplayTree((SplayTreeInfo *) ((Image *) image)->attributes, attribute->key,attribute); return((const ImageAttribute *) attribute); } /* %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% % % % % % % % G e t I m a g e C l i p p i n g P a t h A t t r i b u t e % % % % % % % %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% % % GetImageClippingPathAttribute() searches the list of image attributes and % returns a pointer to a clipping path if it exists otherwise NULL. % % Deprecated, replace with: % % GetImageAttribute(image,"8BIM:1999,2998"); % % The format of the GetImageClippingPathAttribute method is: % % const ImageAttribute *GetImageClippingPathAttribute(Image *image) % % A description of each parameter follows: % % o attribute: Method GetImageClippingPathAttribute returns the clipping % path if it exists otherwise NULL. % % o image: the image. % */ MagickExport const ImageAttribute *GetImageClippingPathAttribute(Image *image) { return(GetImageAttribute(image,"8BIM:1999,2998")); } /* %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% % % % % % % % G e t I m a g e F r o m M a g i c k R e g i s t r y % % % % % % % %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% % % GetImageFromMagickRegistry() gets an image from the registry as defined by % its name. If the image is not found, a NULL image is returned. % % Deprecated, replace with: % % GetImageRegistry(ImageRegistryType,name,exception); % % The format of the GetImageFromMagickRegistry method is: % % Image *GetImageFromMagickRegistry(const char *name,ssize_t *id, % ExceptionInfo *exception) % % A description of each parameter follows: % % o name: the name of the image to retrieve from the registry. % % o id: the registry id. % % o exception: return any errors or warnings in this structure. % */ MagickExport Image *GetImageFromMagickRegistry(const char *name,ssize_t *id, ExceptionInfo *exception) { *id=0L; return((Image *) GetImageRegistry(ImageRegistryType,name,exception)); } /* %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% % % % % % % % G e t M a g i c k R e g i s t r y % % % % % % % %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% % % GetMagickRegistry() gets a blob from the registry as defined by the id. If % the blob that matches the id is not found, NULL is returned. % % The format of the GetMagickRegistry method is: % % const void *GetMagickRegistry(const ssize_t id,RegistryType *type, % size_t *length,ExceptionInfo *exception) % % A description of each parameter follows: % % o id: the registry id. % % o type: the registry type. % % o length: the blob length in number of bytes. % % o exception: return any errors or warnings in this structure. % */ MagickExport void *GetMagickRegistry(const ssize_t id,RegistryType *type, size_t *length,ExceptionInfo *exception) { char key[MaxTextExtent]; void *blob; *type=UndefinedRegistryType; *length=0; (void) FormatLocaleString(key,MaxTextExtent,"%.20g\n",(double) id); blob=(void *) GetImageRegistry(ImageRegistryType,key,exception); if (blob != (void *) NULL) return(blob); blob=(void *) GetImageRegistry(ImageInfoRegistryType,key,exception); if (blob != (void *) NULL) return(blob); return((void *) GetImageRegistry(UndefinedRegistryType,key,exception)); } /* %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% % % % % % % % G e t I m a g e G e o m e t r y % % % % % % % %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% % % GetImageGeometry() returns a region as defined by the geometry string with % respect to the image and its gravity. % % Deprecated, replace with: % % if (size_to_fit != MagickFalse) % ParseRegionGeometry(image,geometry,region_info,&image->exception); else % ParsePageGeometry(image,geometry,region_info,&image->exception); % % The format of the GetImageGeometry method is: % % int GetImageGeometry(Image *image,const char *geometry, % const unsigned int size_to_fit,RectangeInfo *region_info) % % A description of each parameter follows: % % o flags: Method GetImageGeometry returns a bitmask that indicates % which of the four values were located in the geometry string. % % o geometry: The geometry (e.g. 100x100+10+10). % % o size_to_fit: A value other than 0 means to scale the region so it % fits within the specified width and height. % % o region_info: the region as defined by the geometry string with % respect to the image and its gravity. % */ MagickExport int GetImageGeometry(Image *image,const char *geometry, const unsigned int size_to_fit,RectangleInfo *region_info) { if (image->debug != MagickFalse) (void) LogMagickEvent(DeprecateEvent,GetMagickModule(),"last use: v5.5.4"); if (size_to_fit != MagickFalse) return((int) ParseRegionGeometry(image,geometry,region_info,&image->exception)); return((int) ParsePageGeometry(image,geometry,region_info,&image->exception)); } /* %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% % % % % % % % G e t I m a g e L i s t % % % % % % % %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% % % GetImageList() returns an image at the specified position in the list. % % Deprecated, replace with: % % CloneImage(GetImageFromList(images,(ssize_t) offset),0,0,MagickTrue, % exception); % % The format of the GetImageList method is: % % Image *GetImageList(const Image *images,const ssize_t offset, % ExceptionInfo *exception) % % A description of each parameter follows: % % o images: the image list. % % o offset: the position within the list. % % o exception: return any errors or warnings in this structure. % */ MagickExport Image *GetImageList(const Image *images,const ssize_t offset, ExceptionInfo *exception) { Image *image; if (images->debug != MagickFalse) (void) LogMagickEvent(DeprecateEvent,GetMagickModule(),"last use: v5.5.2"); image=CloneImage(GetImageFromList(images,(ssize_t) offset),0,0,MagickTrue, exception); return(image); } /* %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% % % % % % % % G e t I m a g e L i s t I n d e x % % % % % % % %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% % % GetImageListIndex() returns the position in the list of the specified % image. % % Deprecated, replace with: % % GetImageIndexInList(images); % % The format of the GetImageListIndex method is: % % ssize_t GetImageListIndex(const Image *images) % % A description of each parameter follows: % % o images: the image list. % */ MagickExport ssize_t GetImageListIndex(const Image *images) { if (images->debug != MagickFalse) (void) LogMagickEvent(DeprecateEvent,GetMagickModule(),"last use: v5.5.2"); return(GetImageIndexInList(images)); } /* %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% % % % % % % % G e t I m a g e L i s t S i z e % % % % % % % %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% % % GetImageListSize() returns the number of images in the list. % % Deprecated, replace with: % % GetImageListLength(images); % % The format of the GetImageListSize method is: % % size_t GetImageListSize(const Image *images) % % A description of each parameter follows: % % o images: the image list. % */ MagickExport size_t GetImageListSize(const Image *images) { if (images->debug != MagickFalse) (void) LogMagickEvent(DeprecateEvent,GetMagickModule(),"last use: v5.5.2"); return(GetImageListLength(images)); } /* %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% % % % % % % % G e t I m a g e P i x e l s % % % % % % % %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% % % GetImagePixels() obtains a pixel region for read/write access. If the % region is successfully accessed, a pointer to a PixelPacket array % representing the region is returned, otherwise NULL is returned. % % The returned pointer may point to a temporary working copy of the pixels % or it may point to the original pixels in memory. Performance is maximized % if the selected region is part of one row, or one or more full rows, since % then there is opportunity to access the pixels in-place (without a copy) % if the image is in RAM, or in a memory-mapped file. The returned pointer % should *never* be deallocated by the user. % % Pixels accessed via the returned pointer represent a simple array of type % PixelPacket. If the image type is CMYK or if the storage class is % PseduoClass, call GetAuthenticIndexQueue() after invoking GetImagePixels() % to obtain the black color component or colormap indexes (of type IndexPacket) % corresponding to the region. Once the PixelPacket (and/or IndexPacket) % array has been updated, the changes must be saved back to the underlying % image using SyncAuthenticPixels() or they may be lost. % % Deprecated, replace with: % % GetAuthenticPixels(image,x,y,columns,rows,&image->exception); % % The format of the GetImagePixels() method is: % % PixelPacket *GetImagePixels(Image *image,const ssize_t x,const ssize_t y, % const size_t columns,const size_t rows) % % A description of each parameter follows: % % o image: the image. % % o x,y,columns,rows: These values define the perimeter of a region of % pixels. % */ MagickExport PixelPacket *GetImagePixels(Image *image,const ssize_t x,const ssize_t y, const size_t columns,const size_t rows) { return(GetAuthenticPixels(image,x,y,columns,rows,&image->exception)); } /* %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% % % % % % % % G e t I n d e x e s % % % % % % % %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% % % GetIndexes() returns the black channel or the colormap indexes associated % with the last call to QueueAuthenticPixels() or GetVirtualPixels(). NULL is % returned if the black channel or colormap indexes are not available. % % Deprecated, replace with: % % GetAuthenticIndexQueue(image); % % The format of the GetIndexes() method is: % % IndexPacket *GetIndexes(const Image *image) % % A description of each parameter follows: % % o indexes: GetIndexes() returns the indexes associated with the last % call to QueueAuthenticPixels() or GetAuthenticPixels(). % % o image: the image. % */ MagickExport IndexPacket *GetIndexes(const Image *image) { return(GetAuthenticIndexQueue(image)); } /* %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% % % % % % % + G e t M a g i c k G e o m e t r y % % % % % % % %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% % % GetMagickGeometry() is similar to GetGeometry() except the returned % geometry is modified as determined by the meta characters: %, !, <, >, % and ~. % % Deprecated, replace with: % % ParseMetaGeometry(geometry,x,y,width,height); % % The format of the GetMagickGeometry method is: % % unsigned int GetMagickGeometry(const char *geometry,ssize_t *x,ssize_t *y, % size_t *width,size_t *height) % % A description of each parameter follows: % % o geometry: Specifies a character string representing the geometry % specification. % % o x,y: A pointer to an integer. The x and y offset as determined by % the geometry specification is returned here. % % o width,height: A pointer to an unsigned integer. The width and height % as determined by the geometry specification is returned here. % */ MagickExport unsigned int GetMagickGeometry(const char *geometry,ssize_t *x, ssize_t *y,size_t *width,size_t *height) { (void) LogMagickEvent(DeprecateEvent,GetMagickModule(),"last use: v5.5.3"); return(ParseMetaGeometry(geometry,x,y,width,height)); } /* %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% % % % % % % % G e t N e x t I m a g e % % % % % % % %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% % % GetNextImage() returns the next image in a list. % % Deprecated, replace with: % % GetNextImageInList(images); % % The format of the GetNextImage method is: % % Image *GetNextImage(const Image *images) % % A description of each parameter follows: % % o images: the image list. % */ MagickExport Image *GetNextImage(const Image *images) { if (images->debug != MagickFalse) (void) LogMagickEvent(DeprecateEvent,GetMagickModule(),"last use: v5.5.2"); return(GetNextImageInList(images)); } /* %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% % % % % % % % G e t N e x t I m a g e A t t r i b u t e % % % % % % % %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% % % GetNextImageAttribute() gets the next image attribute. % % Deprecated, replace with: % % const char *property; % property=GetNextImageProperty(image); % if (property != (const char *) NULL) % GetImageAttribute(image,property); % % The format of the GetNextImageAttribute method is: % % const ImageAttribute *GetNextImageAttribute(const Image *image) % % A description of each parameter follows: % % o image: the image. % */ MagickExport const ImageAttribute *GetNextImageAttribute(const Image *image) { const char *property; property=GetNextImageProperty(image); if (property == (const char *) NULL) return((const ImageAttribute *) NULL); return(GetImageAttribute(image,property)); } /* %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% % % % % % % % G e t N u m b e r S c e n e s % % % % % % % %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% % % GetNumberScenes() returns the number of images in the list. % % Deprecated, replace with: % % GetImageListLength(image); % % The format of the GetNumberScenes method is: % % unsigned int GetNumberScenes(const Image *images) % % A description of each parameter follows: % % o images: the image list. % */ MagickExport unsigned int GetNumberScenes(const Image *image) { if (image->debug != MagickFalse) (void) LogMagickEvent(DeprecateEvent,GetMagickModule(),"last use: v5.5.2"); return((unsigned int) GetImageListLength(image)); } /* %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% % % % % % % % G e t O n e P i x e l % % % % % % % %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% % % GetOnePixel() returns a single pixel at the specified (x,y) location. % The image background color is returned if an error occurs. % % Deprecated, replace with: % % GetOneAuthenticPixel(image,x,y,&pixel,&image->exception); % % The format of the GetOnePixel() method is: % % PixelPacket GetOnePixel(const Image image,const ssize_t x,const ssize_t y) % % A description of each parameter follows: % % o image: the image. % % o x,y: These values define the location of the pixel to return. % */ MagickExport PixelPacket GetOnePixel(Image *image,const ssize_t x,const ssize_t y) { PixelPacket pixel; (void) GetOneAuthenticPixel(image,x,y,&pixel,&image->exception); return(pixel); } /* %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% % % % % % % % G e t P i x e l s % % % % % % % %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% % % GetPixels() returns the pixels associated with the last call to % QueueAuthenticPixels() or GetAuthenticPixels(). % % Deprecated, replace with: % % GetAuthenticPixelQueue(image); % % The format of the GetPixels() method is: % % PixelPacket *GetPixels(const Image image) % % A description of each parameter follows: % % o pixels: GetPixels() returns the pixels associated with the last call % to QueueAuthenticPixels() or GetAuthenticPixels(). % % o image: the image. % */ MagickExport PixelPacket *GetPixels(const Image *image) { return(GetAuthenticPixelQueue(image)); } /* %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% % % % % % % % G e t P r e v i o u s I m a g e % % % % % % % %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% % % GetPreviousImage() returns the previous image in a list. % % Deprecated, replace with: % % GetPreviousImageInList(images)); % % The format of the GetPreviousImage method is: % % Image *GetPreviousImage(const Image *images) % % A description of each parameter follows: % % o images: the image list. % */ MagickExport Image *GetPreviousImage(const Image *images) { if (images->debug != MagickFalse) (void) LogMagickEvent(DeprecateEvent,GetMagickModule(),"last use: v5.5.2"); return(GetPreviousImageInList(images)); } /* %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% % % % % % % % H S L T r a n s f o r m % % % % % % % %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% % % HSLTransform() converts a (hue, saturation, lightness) to a (red, green, % blue) triple. % % The format of the HSLTransformImage method is: % % void HSLTransform(const double hue,const double saturation, % const double lightness,Quantum *red,Quantum *green,Quantum *blue) % % A description of each parameter follows: % % o hue, saturation, lightness: A double value representing a % component of the HSL color space. % % o red, green, blue: A pointer to a pixel component of type Quantum. % */ static inline MagickRealType HueToRGB(MagickRealType m1,MagickRealType m2, MagickRealType hue) { if (hue < 0.0) hue+=1.0; if (hue > 1.0) hue-=1.0; if ((6.0*hue) < 1.0) return(m1+6.0*(m2-m1)*hue); if ((2.0*hue) < 1.0) return(m2); if ((3.0*hue) < 2.0) return(m1+6.0*(m2-m1)*(2.0/3.0-hue)); return(m1); } MagickExport void HSLTransform(const double hue,const double saturation, const double lightness,Quantum *red,Quantum *green,Quantum *blue) { MagickRealType b, g, r, m1, m2; /* Convert HSL to RGB colorspace. */ assert(red != (Quantum *) NULL); assert(green != (Quantum *) NULL); assert(blue != (Quantum *) NULL); if (lightness <= 0.5) m2=lightness*(saturation+1.0); else m2=lightness+saturation-lightness*saturation; m1=2.0*lightness-m2; r=HueToRGB(m1,m2,hue+1.0/3.0); g=HueToRGB(m1,m2,hue); b=HueToRGB(m1,m2,hue-1.0/3.0); *red=ClampToQuantum((MagickRealType) QuantumRange*r); *green=ClampToQuantum((MagickRealType) QuantumRange*g); *blue=ClampToQuantum((MagickRealType) QuantumRange*b); } /* %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% % % % % % % % I d e n t i t y A f f i n e % % % % % % % %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% % % IdentityAffine() initializes the affine transform to the identity matrix. % % The format of the IdentityAffine method is: % % IdentityAffine(AffineMatrix *affine) % % A description of each parameter follows: % % o affine: A pointer the affine transform of type AffineMatrix. % */ MagickExport void IdentityAffine(AffineMatrix *affine) { (void) LogMagickEvent(TraceEvent,GetMagickModule(),"..."); (void) LogMagickEvent(DeprecateEvent,GetMagickModule(),"last use: v5.5.7"); assert(affine != (AffineMatrix *) NULL); (void) ResetMagickMemory(affine,0,sizeof(AffineMatrix)); affine->sx=1.0; affine->sy=1.0; } /* %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% % % % % % % % I n i t i a l i z e M a g i c k % % % % % % % %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% % % InitializeMagick() initializes the ImageMagick environment. % % Deprecated, replace with: % % MagickCoreGenesis(path,MagickFalse); % % The format of the InitializeMagick function is: % % InitializeMagick(const char *path) % % A description of each parameter follows: % % o path: the execution path of the current ImageMagick client. % */ MagickExport void InitializeMagick(const char *path) { MagickCoreGenesis(path,MagickFalse); } /* %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% % % % % % % % I n t e r p o l a t e P i x e l C o l o r % % % % % % % %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% % % InterpolatePixelColor() applies bi-linear or tri-linear interpolation % between a pixel and it's neighbors. % % The format of the InterpolatePixelColor method is: % % MagickPixelPacket InterpolatePixelColor(const Image *image, % CacheView *view_info,InterpolatePixelMethod method,const double x, % const double y,ExceptionInfo *exception) % % A description of each parameter follows: % % o image: the image. % % o image_view: the image cache view. % % o type: the type of pixel color interpolation. % % o x,y: A double representing the current (x,y) position of the pixel. % % o exception: return any errors or warnings in this structure. % */ static inline double MagickMax(const double x,const double y) { if (x > y) return(x); return(y); } static void BicubicInterpolate(const MagickPixelPacket *pixels,const double dx, MagickPixelPacket *pixel) { MagickRealType dx2, p, q, r, s; dx2=dx*dx; p=(pixels[3].red-pixels[2].red)-(pixels[0].red-pixels[1].red); q=(pixels[0].red-pixels[1].red)-p; r=pixels[2].red-pixels[0].red; s=pixels[1].red; pixel->red=(dx*dx2*p)+(dx2*q)+(dx*r)+s; p=(pixels[3].green-pixels[2].green)-(pixels[0].green-pixels[1].green); q=(pixels[0].green-pixels[1].green)-p; r=pixels[2].green-pixels[0].green; s=pixels[1].green; pixel->green=(dx*dx2*p)+(dx2*q)+(dx*r)+s; p=(pixels[3].blue-pixels[2].blue)-(pixels[0].blue-pixels[1].blue); q=(pixels[0].blue-pixels[1].blue)-p; r=pixels[2].blue-pixels[0].blue; s=pixels[1].blue; pixel->blue=(dx*dx2*p)+(dx2*q)+(dx*r)+s; p=(pixels[3].opacity-pixels[2].opacity)-(pixels[0].opacity-pixels[1].opacity); q=(pixels[0].opacity-pixels[1].opacity)-p; r=pixels[2].opacity-pixels[0].opacity; s=pixels[1].opacity; pixel->opacity=(dx*dx2*p)+(dx2*q)+(dx*r)+s; if (pixel->colorspace == CMYKColorspace) { p=(pixels[3].index-pixels[2].index)-(pixels[0].index-pixels[1].index); q=(pixels[0].index-pixels[1].index)-p; r=pixels[2].index-pixels[0].index; s=pixels[1].index; pixel->index=(dx*dx2*p)+(dx2*q)+(dx*r)+s; } } static inline MagickRealType CubicWeightingFunction(const MagickRealType x) { MagickRealType alpha, gamma; alpha=MagickMax(x+2.0,0.0); gamma=1.0*alpha*alpha*alpha; alpha=MagickMax(x+1.0,0.0); gamma-=4.0*alpha*alpha*alpha; alpha=MagickMax(x+0.0,0.0); gamma+=6.0*alpha*alpha*alpha; alpha=MagickMax(x-1.0,0.0); gamma-=4.0*alpha*alpha*alpha; return(gamma/6.0); } static inline double MeshInterpolate(const PointInfo *delta,const double p, const double x,const double y) { return(delta->x*x+delta->y*y+(1.0-delta->x-delta->y)*p); } static inline ssize_t NearestNeighbor(MagickRealType x) { if (x >= 0.0) return((ssize_t) (x+0.5)); return((ssize_t) (x-0.5)); } MagickExport MagickPixelPacket InterpolatePixelColor(const Image *image, CacheView *image_view,const InterpolatePixelMethod method,const double x, const double y,ExceptionInfo *exception) { MagickPixelPacket pixel; register const IndexPacket *indexes; register const PixelPacket *p; register ssize_t i; assert(image != (Image *) NULL); assert(image->signature == MagickSignature); assert(image_view != (CacheView *) NULL); GetMagickPixelPacket(image,&pixel); switch (method) { case AverageInterpolatePixel: { MagickPixelPacket pixels[16]; MagickRealType alpha[16], gamma; p=GetCacheViewVirtualPixels(image_view,(ssize_t) floor(x)-1,(ssize_t) floor(y)-1,4,4,exception); if (p == (const PixelPacket *) NULL) break; indexes=GetCacheViewVirtualIndexQueue(image_view); for (i=0; i < 16L; i++) { GetMagickPixelPacket(image,pixels+i); SetMagickPixelPacket(image,p,indexes+i,pixels+i); alpha[i]=1.0; if (image->matte != MagickFalse) { alpha[i]=QuantumScale*((MagickRealType) GetPixelAlpha(p)); pixels[i].red*=alpha[i]; pixels[i].green*=alpha[i]; pixels[i].blue*=alpha[i]; if (image->colorspace == CMYKColorspace) pixels[i].index*=alpha[i]; } gamma=alpha[i]; gamma=1.0/(fabs((double) gamma) <= MagickEpsilon ? 1.0 : gamma); pixel.red+=gamma*0.0625*pixels[i].red; pixel.green+=gamma*0.0625*pixels[i].green; pixel.blue+=gamma*0.0625*pixels[i].blue; pixel.opacity+=0.0625*pixels[i].opacity; if (image->colorspace == CMYKColorspace) pixel.index+=gamma*0.0625*pixels[i].index; p++; } break; } case BicubicInterpolatePixel: { MagickPixelPacket pixels[16], u[4]; MagickRealType alpha[16]; PointInfo delta; p=GetCacheViewVirtualPixels(image_view,(ssize_t) floor(x)-1,(ssize_t) floor(y)-1,4,4,exception); if (p == (const PixelPacket *) NULL) break; indexes=GetCacheViewVirtualIndexQueue(image_view); for (i=0; i < 16L; i++) { GetMagickPixelPacket(image,pixels+i); SetMagickPixelPacket(image,p,indexes+i,pixels+i); alpha[i]=1.0; if (image->matte != MagickFalse) { alpha[i]=QuantumScale*((MagickRealType) GetPixelAlpha(p)); pixels[i].red*=alpha[i]; pixels[i].green*=alpha[i]; pixels[i].blue*=alpha[i]; if (image->colorspace == CMYKColorspace) pixels[i].index*=alpha[i]; } p++; } delta.x=x-floor(x); for (i=0; i < 4L; i++) BicubicInterpolate(pixels+4*i,delta.x,u+i); delta.y=y-floor(y); BicubicInterpolate(u,delta.y,&pixel); break; } case BilinearInterpolatePixel: default: { MagickPixelPacket pixels[16]; MagickRealType alpha[16], gamma; PointInfo delta; p=GetCacheViewVirtualPixels(image_view,(ssize_t) floor(x),(ssize_t) floor(y),2,2,exception); if (p == (const PixelPacket *) NULL) break; indexes=GetCacheViewVirtualIndexQueue(image_view); for (i=0; i < 4L; i++) { GetMagickPixelPacket(image,pixels+i); SetMagickPixelPacket(image,p,indexes+i,pixels+i); alpha[i]=1.0; if (image->matte != MagickFalse) { alpha[i]=QuantumScale*((MagickRealType) GetPixelAlpha(p)); pixels[i].red*=alpha[i]; pixels[i].green*=alpha[i]; pixels[i].blue*=alpha[i]; if (image->colorspace == CMYKColorspace) pixels[i].index*=alpha[i]; } p++; } delta.x=x-floor(x); delta.y=y-floor(y); gamma=(((1.0-delta.y)*((1.0-delta.x)*alpha[0]+delta.x*alpha[1])+delta.y* ((1.0-delta.x)*alpha[2]+delta.x*alpha[3]))); gamma=1.0/(fabs((double) gamma) <= MagickEpsilon ? 1.0 : gamma); pixel.red=gamma*((1.0-delta.y)*((1.0-delta.x)*pixels[0].red+delta.x* pixels[1].red)+delta.y*((1.0-delta.x)*pixels[2].red+delta.x* pixels[3].red)); pixel.green=gamma*((1.0-delta.y)*((1.0-delta.x)*pixels[0].green+delta.x* pixels[1].green)+delta.y*((1.0-delta.x)*pixels[2].green+ delta.x*pixels[3].green)); pixel.blue=gamma*((1.0-delta.y)*((1.0-delta.x)*pixels[0].blue+delta.x* pixels[1].blue)+delta.y*((1.0-delta.x)*pixels[2].blue+delta.x* pixels[3].blue)); pixel.opacity=((1.0-delta.y)*((1.0-delta.x)*pixels[0].opacity+delta.x* pixels[1].opacity)+delta.y*((1.0-delta.x)*pixels[2].opacity+delta.x* pixels[3].opacity)); if (image->colorspace == CMYKColorspace) pixel.index=gamma*((1.0-delta.y)*((1.0-delta.x)*pixels[0].index+delta.x* pixels[1].index)+delta.y*((1.0-delta.x)*pixels[2].index+delta.x* pixels[3].index)); break; } case FilterInterpolatePixel: { Image *excerpt_image, *filter_image; MagickPixelPacket pixels[1]; RectangleInfo geometry; geometry.width=4L; geometry.height=4L; geometry.x=(ssize_t) floor(x)-1L; geometry.y=(ssize_t) floor(y)-1L; excerpt_image=ExcerptImage(image,&geometry,exception); if (excerpt_image == (Image *) NULL) break; filter_image=ResizeImage(excerpt_image,1,1,image->filter,image->blur, exception); excerpt_image=DestroyImage(excerpt_image); if (filter_image == (Image *) NULL) break; p=GetVirtualPixels(filter_image,0,0,1,1,exception); if (p == (const PixelPacket *) NULL) { filter_image=DestroyImage(filter_image); break; } indexes=GetVirtualIndexQueue(filter_image); GetMagickPixelPacket(image,pixels); SetMagickPixelPacket(image,p,indexes,&pixel); filter_image=DestroyImage(filter_image); break; } case IntegerInterpolatePixel: { MagickPixelPacket pixels[1]; p=GetCacheViewVirtualPixels(image_view,(ssize_t) floor(x),(ssize_t) floor(y),1,1,exception); if (p == (const PixelPacket *) NULL) break; indexes=GetCacheViewVirtualIndexQueue(image_view); GetMagickPixelPacket(image,pixels); SetMagickPixelPacket(image,p,indexes,&pixel); break; } case MeshInterpolatePixel: { MagickPixelPacket pixels[4]; MagickRealType alpha[4], gamma; PointInfo delta, luminance; p=GetCacheViewVirtualPixels(image_view,(ssize_t) floor(x),(ssize_t) floor(y),2,2,exception); if (p == (const PixelPacket *) NULL) break; indexes=GetCacheViewVirtualIndexQueue(image_view); for (i=0; i < 4L; i++) { GetMagickPixelPacket(image,pixels+i); SetMagickPixelPacket(image,p,indexes+i,pixels+i); alpha[i]=1.0; if (image->matte != MagickFalse) { alpha[i]=QuantumScale*((MagickRealType) GetPixelAlpha(p)); pixels[i].red*=alpha[i]; pixels[i].green*=alpha[i]; pixels[i].blue*=alpha[i]; if (image->colorspace == CMYKColorspace) pixels[i].index*=alpha[i]; } p++; } delta.x=x-floor(x); delta.y=y-floor(y); luminance.x=MagickPixelLuminance(pixels+0)-MagickPixelLuminance(pixels+3); luminance.y=MagickPixelLuminance(pixels+1)-MagickPixelLuminance(pixels+2); if (fabs(luminance.x) < fabs(luminance.y)) { /* Diagonal 0-3 NW-SE. */ if (delta.x <= delta.y) { /* Bottom-left triangle (pixel:2, diagonal: 0-3). */ delta.y=1.0-delta.y; gamma=MeshInterpolate(&delta,alpha[2],alpha[3],alpha[0]); gamma=1.0/(fabs((double) gamma) <= MagickEpsilon ? 1.0 : gamma); pixel.red=gamma*MeshInterpolate(&delta,pixels[2].red, pixels[3].red,pixels[0].red); pixel.green=gamma*MeshInterpolate(&delta,pixels[2].green, pixels[3].green,pixels[0].green); pixel.blue=gamma*MeshInterpolate(&delta,pixels[2].blue, pixels[3].blue,pixels[0].blue); pixel.opacity=gamma*MeshInterpolate(&delta,pixels[2].opacity, pixels[3].opacity,pixels[0].opacity); if (image->colorspace == CMYKColorspace) pixel.index=gamma*MeshInterpolate(&delta,pixels[2].index, pixels[3].index,pixels[0].index); } else { /* Top-right triangle (pixel:1, diagonal: 0-3). */ delta.x=1.0-delta.x; gamma=MeshInterpolate(&delta,alpha[1],alpha[0],alpha[3]); gamma=1.0/(fabs((double) gamma) <= MagickEpsilon ? 1.0 : gamma); pixel.red=gamma*MeshInterpolate(&delta,pixels[1].red, pixels[0].red,pixels[3].red); pixel.green=gamma*MeshInterpolate(&delta,pixels[1].green, pixels[0].green,pixels[3].green); pixel.blue=gamma*MeshInterpolate(&delta,pixels[1].blue, pixels[0].blue,pixels[3].blue); pixel.opacity=gamma*MeshInterpolate(&delta,pixels[1].opacity, pixels[0].opacity,pixels[3].opacity); if (image->colorspace == CMYKColorspace) pixel.index=gamma*MeshInterpolate(&delta,pixels[1].index, pixels[0].index,pixels[3].index); } } else { /* Diagonal 1-2 NE-SW. */ if (delta.x <= (1.0-delta.y)) { /* Top-left triangle (pixel 0, diagonal: 1-2). */ gamma=MeshInterpolate(&delta,alpha[0],alpha[1],alpha[2]); gamma=1.0/(fabs((double) gamma) <= MagickEpsilon ? 1.0 : gamma); pixel.red=gamma*MeshInterpolate(&delta,pixels[0].red, pixels[1].red,pixels[2].red); pixel.green=gamma*MeshInterpolate(&delta,pixels[0].green, pixels[1].green,pixels[2].green); pixel.blue=gamma*MeshInterpolate(&delta,pixels[0].blue, pixels[1].blue,pixels[2].blue); pixel.opacity=gamma*MeshInterpolate(&delta,pixels[0].opacity, pixels[1].opacity,pixels[2].opacity); if (image->colorspace == CMYKColorspace) pixel.index=gamma*MeshInterpolate(&delta,pixels[0].index, pixels[1].index,pixels[2].index); } else { /* Bottom-right triangle (pixel: 3, diagonal: 1-2). */ delta.x=1.0-delta.x; delta.y=1.0-delta.y; gamma=MeshInterpolate(&delta,alpha[3],alpha[2],alpha[1]); gamma=1.0/(fabs((double) gamma) <= MagickEpsilon ? 1.0 : gamma); pixel.red=gamma*MeshInterpolate(&delta,pixels[3].red, pixels[2].red,pixels[1].red); pixel.green=gamma*MeshInterpolate(&delta,pixels[3].green, pixels[2].green,pixels[1].green); pixel.blue=gamma*MeshInterpolate(&delta,pixels[3].blue, pixels[2].blue,pixels[1].blue); pixel.opacity=gamma*MeshInterpolate(&delta,pixels[3].opacity, pixels[2].opacity,pixels[1].opacity); if (image->colorspace == CMYKColorspace) pixel.index=gamma*MeshInterpolate(&delta,pixels[3].index, pixels[2].index,pixels[1].index); } } break; } case NearestNeighborInterpolatePixel: { MagickPixelPacket pixels[1]; p=GetCacheViewVirtualPixels(image_view,NearestNeighbor(x), NearestNeighbor(y),1,1,exception); if (p == (const PixelPacket *) NULL) break; indexes=GetCacheViewVirtualIndexQueue(image_view); GetMagickPixelPacket(image,pixels); SetMagickPixelPacket(image,p,indexes,&pixel); break; } case SplineInterpolatePixel: { MagickPixelPacket pixels[16]; MagickRealType alpha[16], dx, dy, gamma; PointInfo delta; ssize_t j, n; p=GetCacheViewVirtualPixels(image_view,(ssize_t) floor(x)-1,(ssize_t) floor(y)-1,4,4,exception); if (p == (const PixelPacket *) NULL) break; indexes=GetCacheViewVirtualIndexQueue(image_view); n=0; delta.x=x-floor(x); delta.y=y-floor(y); for (i=(-1); i < 3L; i++) { dy=CubicWeightingFunction((MagickRealType) i-delta.y); for (j=(-1); j < 3L; j++) { GetMagickPixelPacket(image,pixels+n); SetMagickPixelPacket(image,p,indexes+n,pixels+n); alpha[n]=1.0; if (image->matte != MagickFalse) { alpha[n]=QuantumScale*((MagickRealType) GetPixelAlpha(p)); pixels[n].red*=alpha[n]; pixels[n].green*=alpha[n]; pixels[n].blue*=alpha[n]; if (image->colorspace == CMYKColorspace) pixels[n].index*=alpha[n]; } dx=CubicWeightingFunction(delta.x-(MagickRealType) j); gamma=alpha[n]; gamma=1.0/(fabs((double) gamma) <= MagickEpsilon ? 1.0 : gamma); pixel.red+=gamma*dx*dy*pixels[n].red; pixel.green+=gamma*dx*dy*pixels[n].green; pixel.blue+=gamma*dx*dy*pixels[n].blue; if (image->matte != MagickFalse) pixel.opacity+=dx*dy*pixels[n].opacity; if (image->colorspace == CMYKColorspace) pixel.index+=gamma*dx*dy*pixels[n].index; n++; p++; } } break; } } return(pixel); } /* %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% % % % % % % % I n t e r p r e t I m a g e A t t r i b u t e s % % % % % % % %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% % % InterpretImageAttributes() replaces any embedded formatting characters with % the appropriate image attribute and returns the translated text. % % Deprecated, replace with: % % InterpretImageProperties(image_info,image,embed_text); % % The format of the InterpretImageAttributes method is: % % char *InterpretImageAttributes(const ImageInfo *image_info,Image *image, % const char *embed_text) % % A description of each parameter follows: % % o image_info: the image info. % % o image: the image. % % o embed_text: the address of a character string containing the embedded % formatting characters. % */ MagickExport char *InterpretImageAttributes(const ImageInfo *image_info, Image *image,const char *embed_text) { (void) LogMagickEvent(DeprecateEvent,GetMagickModule(),"last use: v6.3.1"); return(InterpretImageProperties(image_info,image,embed_text)); } /* %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% % % % % % % + I s S u b i m a g e % % % % % % % %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% % % IsSubimage() returns MagickTrue if the geometry is a valid subimage % specification (e.g. [1], [1-9], [1,7,4]). % % The format of the IsSubimage method is: % % unsigned int IsSubimage(const char *geometry,const unsigned int pedantic) % % A description of each parameter follows: % % o geometry: This string is the geometry specification. % % o pedantic: A value other than 0 invokes a more restrictive set of % conditions for a valid specification (e.g. [1], [1-4], [4-1]). % */ MagickExport unsigned int IsSubimage(const char *geometry, const unsigned int pedantic) { (void) LogMagickEvent(DeprecateEvent,GetMagickModule(),"last use: v5.5.7"); if (geometry == (const char *) NULL) return(MagickFalse); if ((strchr(geometry,'x') != (char *) NULL) || (strchr(geometry,'X') != (char *) NULL)) return(MagickFalse); if ((pedantic != MagickFalse) && (strchr(geometry,',') != (char *) NULL)) return(MagickFalse); return(MagickTrue); } /* %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% % % % % % % % L e v e l I m a g e C o l o r s % % % % % % % %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% % % LevelImageColor() will map the given color to "black" and "white" % values, limearly spreading out the colors, and level values on a channel by % channel bases, as per LevelImage(). The given colors allows you to specify % different level ranges for each of the color channels separately. % % If the boolean 'invert' is set true the image values will modifyed in the % reverse direction. That is any existing "black" and "white" colors in the % image will become the color values given, with all other values compressed % appropriatally. This effectivally maps a greyscale gradient into the given % color gradient. % % Deprecated, replace with: % % LevelColorsImageChannel(image,channel,black_color,white_color,invert); % % The format of the LevelImageColors method is: % % MagickBooleanType LevelImageColors(Image *image,const ChannelType channel, % const MagickPixelPacket *black_color,const MagickPixelPacket *white_color, % const MagickBooleanType invert) % % A description of each parameter follows: % % o image: the image. % % o channel: the channel. % % o black_color: The color to map black to/from % % o white_point: The color to map white to/from % % o invert: if true map the colors (levelize), rather than from (level) % */ MagickBooleanType LevelImageColors(Image *image,const ChannelType channel, const MagickPixelPacket *black_color,const MagickPixelPacket *white_color, const MagickBooleanType invert) { return(LevelColorsImageChannel(image,channel,black_color,white_color,invert)); } /* %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% % % % % % % % L i b e r a t e M e m o r y % % % % % % % %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% % % LiberateMemory() frees memory that has already been allocated, and NULL's % the pointer to it. % % The format of the LiberateMemory method is: % % void LiberateMemory(void **memory) % % A description of each parameter follows: % % o memory: A pointer to a block of memory to free for reuse. % */ MagickExport void LiberateMemory(void **memory) { assert(memory != (void **) NULL); (void) LogMagickEvent(DeprecateEvent,GetMagickModule(),"last use: v5.5.7"); if (*memory == (void *) NULL) return; free(*memory); *memory=(void *) NULL; } /* %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% % % % % % % % L i b e r a t e S e m a p h o r e I n f o % % % % % % % %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% % % LiberateSemaphoreInfo() relinquishes a semaphore. % % Deprecated, replace with: % % UnlockSemaphoreInfo(*semaphore_info); % % The format of the LiberateSemaphoreInfo method is: % % LiberateSemaphoreInfo(void **semaphore_info) % % A description of each parameter follows: % % o semaphore_info: Specifies a pointer to an SemaphoreInfo structure. % */ MagickExport void LiberateSemaphoreInfo(SemaphoreInfo **semaphore_info) { (void) LogMagickEvent(DeprecateEvent,GetMagickModule(),"last use: v5.5.7"); UnlockSemaphoreInfo(*semaphore_info); } /* %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% % % % % % % % M a g i c k I n c a r n a t e % % % % % % % %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% % % MagickIncarnate() initializes the ImageMagick environment. % % Deprecated, replace with: % % MagickCoreGenesis(path,MagickFalse); % % The format of the MagickIncarnate function is: % % MagickIncarnate(const char *path) % % A description of each parameter follows: % % o path: the execution path of the current ImageMagick client. % */ MagickExport void MagickIncarnate(const char *path) { (void) LogMagickEvent(DeprecateEvent,GetMagickModule(),"last use: v5.5.1"); MagickCoreGenesis(path,MagickFalse); } /* %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% % % % % % % % M a g i c k M o n i t o r % % % % % % % %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% % % MagickMonitor() calls the monitor handler method with a text string that % describes the task and a measure of completion. The method returns % MagickTrue on success otherwise MagickFalse if an error is encountered, e.g. % if there was a user interrupt. % % The format of the MagickMonitor method is: % % MagickBooleanType MagickMonitor(const char *text, % const MagickOffsetType offset,const MagickSizeType span, % void *client_data) % % A description of each parameter follows: % % o offset: the position relative to the span parameter which represents % how much progress has been made toward completing a task. % % o span: the span relative to completing a task. % % o client_data: the client data. % */ MagickExport MagickBooleanType MagickMonitor(const char *text, const MagickOffsetType offset,const MagickSizeType span, void *magick_unused(client_data)) { ExceptionInfo *exception; MagickBooleanType status; assert(text != (const char *) NULL); (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",text); ProcessPendingEvents(text); status=MagickTrue; exception=AcquireExceptionInfo(); if (monitor_handler != (MonitorHandler) NULL) status=(*monitor_handler)(text,offset,span,exception); exception=DestroyExceptionInfo(exception); return(status); } /* %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% % % % % % % % M a p I m a g e % % % % % % % %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% % % MapImage() replaces the colors of an image with the closest color from a % reference image. % % Deprecated, replace with: % % QuantizeInfo quantize_info; % GetQuantizeInfo(&quantize_info); % quantize_info.dither=dither; % RemapImage(&quantize_info,image,map_image); % % The format of the MapImage method is: % % MagickBooleanType MapImage(Image *image,const Image *map_image, % const MagickBooleanType dither) % % A description of each parameter follows: % % o image: Specifies a pointer to an Image structure. % % o map_image: the image. Reduce image to a set of colors represented by % this image. % % o dither: Set this integer value to something other than zero to % dither the mapped image. % */ MagickExport MagickBooleanType MapImage(Image *image,const Image *map_image, const MagickBooleanType dither) { QuantizeInfo quantize_info; /* Initialize color cube. */ assert(image != (Image *) NULL); assert(image->signature == MagickSignature); if (image->debug != MagickFalse) (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename); assert(map_image != (Image *) NULL); assert(map_image->signature == MagickSignature); GetQuantizeInfo(&quantize_info); quantize_info.dither=dither; return(RemapImage(&quantize_info,image,map_image)); } /* %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% % % % % % % % M a p I m a g e s % % % % % % % %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% % % MapImages() replaces the colors of a sequence of images with the closest % color from a reference image. % % Deprecated, replace with: % % QuantizeInfo quantize_info; % GetQuantizeInfo(&quantize_info); % quantize_info.dither=dither; % RemapImages(&quantize_info,images,map_image); % % The format of the MapImage method is: % % MagickBooleanType MapImages(Image *images,Image *map_image, % const MagickBooleanType dither) % % A description of each parameter follows: % % o image: Specifies a pointer to a set of Image structures. % % o map_image: the image. Reduce image to a set of colors represented by % this image. % % o dither: Set this integer value to something other than zero to % dither the quantized image. % */ MagickExport MagickBooleanType MapImages(Image *images,const Image *map_image, const MagickBooleanType dither) { QuantizeInfo quantize_info; assert(images != (Image *) NULL); assert(images->signature == MagickSignature); if (images->debug != MagickFalse) (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",images->filename); GetQuantizeInfo(&quantize_info); quantize_info.dither=dither; return(RemapImages(&quantize_info,images,map_image)); } /* %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% % % % % % % % M a t t e F l o o d f i l l I m a g e % % % % % % % %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% % % MatteFloodfill() changes the transparency value of any pixel that matches % target and is an immediate neighbor. If the method FillToBorderMethod % is specified, the transparency value is changed for any neighbor pixel % that does not match the bordercolor member of image. % % By default target must match a particular pixel transparency exactly. % However, in many cases two transparency values may differ by a % small amount. The fuzz member of image defines how much tolerance is % acceptable to consider two transparency values as the same. For example, % set fuzz to 10 and the opacity values of 100 and 102 respectively are % now interpreted as the same value for the purposes of the floodfill. % % The format of the MatteFloodfillImage method is: % % MagickBooleanType MatteFloodfillImage(Image *image, % const PixelPacket target,const Quantum opacity,const ssize_t x_offset, % const ssize_t y_offset,const PaintMethod method) % % A description of each parameter follows: % % o image: the image. % % o target: the RGB value of the target color. % % o opacity: the level of transparency: 0 is fully opaque and QuantumRange is % fully transparent. % % o x,y: the starting location of the operation. % % o method: Choose either FloodfillMethod or FillToBorderMethod. % */ MagickExport MagickBooleanType MatteFloodfillImage(Image *image, const PixelPacket target,const Quantum opacity,const ssize_t x_offset, const ssize_t y_offset,const PaintMethod method) { Image *floodplane_image; MagickBooleanType skip; register SegmentInfo *s; SegmentInfo *segment_stack; ssize_t offset, start, x, x1, x2, y; /* Check boundary conditions. */ assert(image != (Image *) NULL); assert(image->signature == MagickSignature); if (image->debug != MagickFalse) (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename); if ((x_offset < 0) || (x_offset >= (ssize_t) image->columns)) return(MagickFalse); if ((y_offset < 0) || (y_offset >= (ssize_t) image->rows)) return(MagickFalse); if (SetImageStorageClass(image,DirectClass) == MagickFalse) return(MagickFalse); if (image->matte == MagickFalse) (void) SetImageAlphaChannel(image,OpaqueAlphaChannel); floodplane_image=CloneImage(image,image->columns,image->rows,MagickTrue, &image->exception); if (floodplane_image == (Image *) NULL) return(MagickFalse); (void) SetImageAlphaChannel(floodplane_image,OpaqueAlphaChannel); /* Set floodfill color. */ segment_stack=(SegmentInfo *) AcquireQuantumMemory(MaxStacksize, sizeof(*segment_stack)); if (segment_stack == (SegmentInfo *) NULL) { floodplane_image=DestroyImage(floodplane_image); ThrowBinaryException(ResourceLimitError,"MemoryAllocationFailed", image->filename); } /* Push initial segment on stack. */ x=x_offset; y=y_offset; start=0; s=segment_stack; PushSegmentStack(y,x,x,1); PushSegmentStack(y+1,x,x,-1); while (s > segment_stack) { register const PixelPacket *restrict p; register ssize_t x; register PixelPacket *restrict q; /* Pop segment off stack. */ s--; x1=(ssize_t) s->x1; x2=(ssize_t) s->x2; offset=(ssize_t) s->y2; y=(ssize_t) s->y1+offset; /* Recolor neighboring pixels. */ p=GetVirtualPixels(image,0,y,(size_t) (x1+1),1,&image->exception); q=GetAuthenticPixels(floodplane_image,0,y,(size_t) (x1+1),1, &image->exception); if ((p == (const PixelPacket *) NULL) || (q == (PixelPacket *) NULL)) break; p+=x1; q+=x1; for (x=x1; x >= 0; x--) { if (q->opacity == (Quantum) TransparentOpacity) break; if (method == FloodfillMethod) { if (IsColorSimilar(image,p,&target) == MagickFalse) break; } else if (IsColorSimilar(image,p,&target) != MagickFalse) break; q->opacity=(Quantum) TransparentOpacity; q--; p--; } if (SyncAuthenticPixels(floodplane_image,&image->exception) == MagickFalse) break; skip=x >= x1 ? MagickTrue : MagickFalse; if (skip == MagickFalse) { start=x+1; if (start < x1) PushSegmentStack(y,start,x1-1,-offset); x=x1+1; } do { if (skip == MagickFalse) { if (x < (ssize_t) image->columns) { p=GetVirtualPixels(image,x,y,image->columns-x,1, &image->exception); q=GetAuthenticPixels(floodplane_image,x,y,image->columns-x,1, &image->exception); if ((p == (const PixelPacket *) NULL) || (q == (PixelPacket *) NULL)) break; for ( ; x < (ssize_t) image->columns; x++) { if (q->opacity == (Quantum) TransparentOpacity) break; if (method == FloodfillMethod) { if (IsColorSimilar(image,p,&target) == MagickFalse) break; } else if (IsColorSimilar(image,p,&target) != MagickFalse) break; q->opacity=(Quantum) TransparentOpacity; q++; p++; } if (SyncAuthenticPixels(floodplane_image,&image->exception) == MagickFalse) break; } PushSegmentStack(y,start,x-1,offset); if (x > (x2+1)) PushSegmentStack(y,x2+1,x-1,-offset); } skip=MagickFalse; x++; if (x <= x2) { p=GetVirtualPixels(image,x,y,(size_t) (x2-x+1),1, &image->exception); q=GetAuthenticPixels(floodplane_image,x,y,(size_t) (x2-x+1),1, &image->exception); if ((p == (const PixelPacket *) NULL) || (q == (PixelPacket *) NULL)) break; for ( ; x <= x2; x++) { if (q->opacity == (Quantum) TransparentOpacity) break; if (method == FloodfillMethod) { if (IsColorSimilar(image,p,&target) != MagickFalse) break; } else if (IsColorSimilar(image,p,&target) == MagickFalse) break; p++; q++; } } start=x; } while (x <= x2); } for (y=0; y < (ssize_t) image->rows; y++) { register const PixelPacket *restrict p; register ssize_t x; register PixelPacket *restrict q; /* Tile fill color onto floodplane. */ p=GetVirtualPixels(floodplane_image,0,y,image->columns,1, &image->exception); q=GetAuthenticPixels(image,0,y,image->columns,1,&image->exception); if ((p == (const PixelPacket *) NULL) || (q == (PixelPacket *) NULL)) break; for (x=0; x < (ssize_t) image->columns; x++) { if (GetPixelOpacity(p) != OpaqueOpacity) q->opacity=opacity; p++; q++; } if (SyncAuthenticPixels(image,&image->exception) == MagickFalse) break; } segment_stack=(SegmentInfo *) RelinquishMagickMemory(segment_stack); floodplane_image=DestroyImage(floodplane_image); return(y == (ssize_t) image->rows ? MagickTrue : MagickFalse); } /* %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% % % % % % % % M a x i m u m I m a g e s % % % % % % % %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% % % MaximumImages() returns the maximum intensity of an image sequence. % % Deprecated, replace with: % % EvaluateImages(images,MinEvaluateOperator,exception); % % The format of the MaxImages method is: % % Image *MaximumImages(Image *images,ExceptionInfo *exception) % % A description of each parameter follows: % % o images: the image sequence. % % o exception: return any errors or warnings in this structure. % */ MagickExport Image *MaximumImages(const Image *images,ExceptionInfo *exception) { return(EvaluateImages(images,MinEvaluateOperator,exception)); } /* %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% % % % % % % % M i n i m u m I m a g e s % % % % % % % %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% % % MinimumImages() returns the minimum intensity of an image sequence. % % Deprecated, replace with: % % EvaluateImages(images,MinEvaluateOperator,exception); % % The format of the MinimumImages method is: % % Image *MinimumImages(Image *images,ExceptionInfo *exception) % % A description of each parameter follows: % % o images: the image sequence. % % o exception: return any errors or warnings in this structure. % */ MagickExport Image *MinimumImages(const Image *images,ExceptionInfo *exception) { return(EvaluateImages(images,MinEvaluateOperator,exception)); } /* %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% % % % % % % % M e d i a n F i l t e r I m a g e % % % % % % % %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% % % MedianFilterImage() applies a digital filter that improves the quality % of a noisy image. Each pixel is replaced by the median in a set of % neighboring pixels as defined by radius. % % The algorithm was contributed by Mike Edmonds and implements an insertion % sort for selecting median color-channel values. For more on this algorithm % see "Skip Lists: A probabilistic Alternative to Balanced Trees" by William % Pugh in the June 1990 of Communications of the ACM. % % The format of the MedianFilterImage method is: % % Image *MedianFilterImage(const Image *image,const double radius, % ExceptionInfo *exception) % % A description of each parameter follows: % % o image: the image. % % o radius: the radius of the pixel neighborhood. % % o exception: return any errors or warnings in this structure. % */ MagickExport Image *MedianFilterImage(const Image *image,const double radius, ExceptionInfo *exception) { Image *median_image; median_image=StatisticImage(image,MedianStatistic,(size_t) radius,(size_t) radius,exception); return(median_image); } /* %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% % % % % % % % M o d e I m a g e % % % % % % % %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% % % ModeImage() makes each pixel the 'predominant color' of the neighborhood % of the specified radius. % % The format of the ModeImage method is: % % Image *ModeImage(const Image *image,const double radius, % ExceptionInfo *exception) % % A description of each parameter follows: % % o image: the image. % % o radius: the radius of the pixel neighborhood. % % o exception: return any errors or warnings in this structure. % */ MagickExport Image *ModeImage(const Image *image,const double radius, ExceptionInfo *exception) { Image *mode_image; mode_image=StatisticImage(image,ModeStatistic,(size_t) radius,(size_t) radius, exception); return(mode_image); } /* %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% % % % % % % % M o s a i c I m a g e s % % % % % % % %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% % % MosaicImages() Obsolete Function: Use MergeImageLayers() instead. % % Deprecated, replace with: % % MergeImageLayers(image,MosaicLayer,exception); % % The format of the MosaicImage method is: % % Image *MosaicImages(const Image *image,ExceptionInfo *exception) % % A description of each parameter follows: % % o image: the image list to be composited together % % o exception: return any errors or warnings in this structure. % */ MagickExport Image *MosaicImages(Image *image,ExceptionInfo *exception) { return(MergeImageLayers(image,MosaicLayer,exception)); } /* %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% % % % % % % % O p a q u e I m a g e % % % % % % % %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% % % OpaqueImage() changes any pixel that matches color with the color % defined by fill. % % By default color must match a particular pixel color exactly. However, % in many cases two colors may differ by a small amount. Fuzz defines % how much tolerance is acceptable to consider two colors as the same. % For example, set fuzz to 10 and the color red at intensities of 100 and % 102 respectively are now interpreted as the same color. % % The format of the OpaqueImage method is: % % MagickBooleanType OpaqueImage(Image *image, % const PixelPacket *target,const PixelPacket fill) % % A description of each parameter follows: % % o image: the image. % % o target: the RGB value of the target color. % % o fill: the replacement color. % */ MagickExport MagickBooleanType OpaqueImage(Image *image, const PixelPacket target,const PixelPacket fill) { #define OpaqueImageTag "Opaque/Image" MagickBooleanType proceed; register ssize_t i; ssize_t y; /* Make image color opaque. */ assert(image != (Image *) NULL); assert(image->signature == MagickSignature); (void) LogMagickEvent(DeprecateEvent,GetMagickModule(),"last use: v6.1.0"); if (image->debug != MagickFalse) (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename); switch (image->storage_class) { case DirectClass: default: { /* Make DirectClass image opaque. */ for (y=0; y < (ssize_t) image->rows; y++) { register ssize_t x; register PixelPacket *restrict q; q=GetAuthenticPixels(image,0,y,image->columns,1,&image->exception); if (q == (PixelPacket *) NULL) break; for (x=0; x < (ssize_t) image->columns; x++) { if (IsColorSimilar(image,q,&target) != MagickFalse) *q=fill; q++; } if (SyncAuthenticPixels(image,&image->exception) == MagickFalse) break; proceed=SetImageProgress(image,OpaqueImageTag,(MagickOffsetType) y, image->rows); if (proceed == MagickFalse) break; } break; } case PseudoClass: { /* Make PseudoClass image opaque. */ for (i=0; i < (ssize_t) image->colors; i++) { if (IsColorSimilar(image,&image->colormap[i],&target) != MagickFalse) image->colormap[i]=fill; } if (fill.opacity != OpaqueOpacity) { for (y=0; y < (ssize_t) image->rows; y++) { register ssize_t x; register PixelPacket *restrict q; q=GetAuthenticPixels(image,0,y,image->columns,1,&image->exception); if (q == (PixelPacket *) NULL) break; for (x=0; x < (ssize_t) image->columns; x++) { if (IsColorSimilar(image,q,&target) != MagickFalse) q->opacity=fill.opacity; q++; } if (SyncAuthenticPixels(image,&image->exception) == MagickFalse) break; } } (void) SyncImage(image); break; } } if (fill.opacity != OpaqueOpacity) image->matte=MagickTrue; return(MagickTrue); } /* %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% % % % % % % % O p e n C a c h e V i e w % % % % % % % %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% % % OpenCacheView() opens a view into the pixel cache, using the % VirtualPixelMethod that is defined within the given image itself. % % Deprecated, replace with: % % AcquireCacheView(image); % % The format of the OpenCacheView method is: % % CacheView *OpenCacheView(const Image *image) % % A description of each parameter follows: % % o image: the image. % */ MagickExport CacheView *OpenCacheView(const Image *image) { return(AcquireCacheView(image)); } /* %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% % % % % % % % O p e n M a g i c k S t r e a m % % % % % % % %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% % % OpenMagickStream() opens the file at the specified path and return the % associated stream. % % The path of the OpenMagickStream method is: % % FILE *OpenMagickStream(const char *path,const char *mode) % % A description of each parameter follows. % % o path: the file path. % % o mode: the file mode. % */ #if defined(MAGICKCORE_HAVE__WFOPEN) static size_t UTF8ToUTF16(const unsigned char *utf8,wchar_t *utf16) { register const unsigned char *p; if (utf16 != (wchar_t *) NULL) { register wchar_t *q; wchar_t c; /* Convert UTF-8 to UTF-16. */ q=utf16; for (p=utf8; *p != '\0'; p++) { if ((*p & 0x80) == 0) *q=(*p); else if ((*p & 0xE0) == 0xC0) { c=(*p); *q=(c & 0x1F) << 6; p++; if ((*p & 0xC0) != 0x80) return(0); *q|=(*p & 0x3F); } else if ((*p & 0xF0) == 0xE0) { c=(*p); *q=c << 12; p++; if ((*p & 0xC0) != 0x80) return(0); c=(*p); *q|=(c & 0x3F) << 6; p++; if ((*p & 0xC0) != 0x80) return(0); *q|=(*p & 0x3F); } else return(0); q++; } *q++='\0'; return(q-utf16); } /* Compute UTF-16 string length. */ for (p=utf8; *p != '\0'; p++) { if ((*p & 0x80) == 0) ; else if ((*p & 0xE0) == 0xC0) { p++; if ((*p & 0xC0) != 0x80) return(0); } else if ((*p & 0xF0) == 0xE0) { p++; if ((*p & 0xC0) != 0x80) return(0); p++; if ((*p & 0xC0) != 0x80) return(0); } else return(0); } return(p-utf8); } static wchar_t *ConvertUTF8ToUTF16(const unsigned char *source) { size_t length; wchar_t *utf16; length=UTF8ToUTF16(source,(wchar_t *) NULL); if (length == 0) { register ssize_t i; /* Not UTF-8, just copy. */ length=strlen((const char *) source); utf16=(wchar_t *) AcquireQuantumMemory(length+1,sizeof(*utf16)); if (utf16 == (wchar_t *) NULL) return((wchar_t *) NULL); for (i=0; i <= (ssize_t) length; i++) utf16[i]=source[i]; return(utf16); } utf16=(wchar_t *) AcquireQuantumMemory(length+1,sizeof(*utf16)); if (utf16 == (wchar_t *) NULL) return((wchar_t *) NULL); length=UTF8ToUTF16(source,utf16); return(utf16); } #endif MagickExport FILE *OpenMagickStream(const char *path,const char *mode) { FILE *file; if ((path == (const char *) NULL) || (mode == (const char *) NULL)) { errno=EINVAL; return((FILE *) NULL); } file=(FILE *) NULL; #if defined(MAGICKCORE_HAVE__WFOPEN) { wchar_t *unicode_mode, *unicode_path; unicode_path=ConvertUTF8ToUTF16((const unsigned char *) path); if (unicode_path == (wchar_t *) NULL) return((FILE *) NULL); unicode_mode=ConvertUTF8ToUTF16((const unsigned char *) mode); if (unicode_mode == (wchar_t *) NULL) { unicode_path=(wchar_t *) RelinquishMagickMemory(unicode_path); return((FILE *) NULL); } file=_wfopen(unicode_path,unicode_mode); unicode_mode=(wchar_t *) RelinquishMagickMemory(unicode_mode); unicode_path=(wchar_t *) RelinquishMagickMemory(unicode_path); } #endif if (file == (FILE *) NULL) file=fopen(path,mode); return(file); } /* %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% % % % % % % % P a i n t F l o o d f i l l I m a g e % % % % % % % %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% % % PaintFloodfill() changes the color value of any pixel that matches % target and is an immediate neighbor. If the method FillToBorderMethod is % specified, the color value is changed for any neighbor pixel that does not % match the bordercolor member of image. % % By default target must match a particular pixel color exactly. % However, in many cases two colors may differ by a small amount. The % fuzz member of image defines how much tolerance is acceptable to % consider two colors as the same. For example, set fuzz to 10 and the % color red at intensities of 100 and 102 respectively are now % interpreted as the same color for the purposes of the floodfill. % % Deprecated, replace with: % % FloodfillPaintImage(image,channel,draw_info,target,x,y, % method == FloodfillMethod ? MagickFalse : MagickTrue); % % The format of the PaintFloodfillImage method is: % % MagickBooleanType PaintFloodfillImage(Image *image, % const ChannelType channel,const MagickPixelPacket target, % const ssize_t x,const ssize_t y,const DrawInfo *draw_info, % const PaintMethod method) % % A description of each parameter follows: % % o image: the image. % % o channel: the channel(s). % % o target: the RGB value of the target color. % % o x,y: the starting location of the operation. % % o draw_info: the draw info. % % o method: Choose either FloodfillMethod or FillToBorderMethod. % */ MagickExport MagickBooleanType PaintFloodfillImage(Image *image, const ChannelType channel,const MagickPixelPacket *target,const ssize_t x, const ssize_t y,const DrawInfo *draw_info,const PaintMethod method) { MagickBooleanType status; status=FloodfillPaintImage(image,channel,draw_info,target,x,y, method == FloodfillMethod ? MagickFalse : MagickTrue); return(status); } /* %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% % % % % % P a i n t O p a q u e I m a g e % % % % % %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% % % PaintOpaqueImage() changes any pixel that matches color with the color % defined by fill. % % By default color must match a particular pixel color exactly. However, % in many cases two colors may differ by a small amount. Fuzz defines % how much tolerance is acceptable to consider two colors as the same. % For example, set fuzz to 10 and the color red at intensities of 100 and % 102 respectively are now interpreted as the same color. % % Deprecated, replace with: % % OpaquePaintImageChannel(image,DefaultChannels,target,fill,MagickFalse); % OpaquePaintImageChannel(image,channel,target,fill,MagickFalse); % % The format of the PaintOpaqueImage method is: % % MagickBooleanType PaintOpaqueImage(Image *image, % const PixelPacket *target,const PixelPacket *fill) % MagickBooleanType PaintOpaqueImageChannel(Image *image, % const ChannelType channel,const PixelPacket *target, % const PixelPacket *fill) % % A description of each parameter follows: % % o image: the image. % % o channel: the channel(s). % % o target: the RGB value of the target color. % % o fill: the replacement color. % */ MagickExport MagickBooleanType PaintOpaqueImage(Image *image, const MagickPixelPacket *target,const MagickPixelPacket *fill) { MagickBooleanType status; status=OpaquePaintImageChannel(image,DefaultChannels,target,fill,MagickFalse); return(status); } MagickExport MagickBooleanType PaintOpaqueImageChannel(Image *image, const ChannelType channel,const MagickPixelPacket *target, const MagickPixelPacket *fill) { return(OpaquePaintImageChannel(image,channel,target,fill,MagickFalse)); } /* %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% % % % % % % % P a i n t T r a n s p a r e n t I m a g e % % % % % % % %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% % % PaintTransparentImage() changes the opacity value associated with any pixel % that matches color to the value defined by opacity. % % By default color must match a particular pixel color exactly. However, % in many cases two colors may differ by a small amount. Fuzz defines % how much tolerance is acceptable to consider two colors as the same. % For example, set fuzz to 10 and the color red at intensities of 100 and % 102 respectively are now interpreted as the same color. % % Deprecated, replace with: % % TransparentPaintImage(image,target,opacity,MagickFalse); % % The format of the PaintTransparentImage method is: % % MagickBooleanType PaintTransparentImage(Image *image, % const MagickPixelPacket *target,const Quantum opacity) % % A description of each parameter follows: % % o image: the image. % % o target: the RGB value of the target color. % % o opacity: the replacement opacity value. % */ MagickExport MagickBooleanType PaintTransparentImage(Image *image, const MagickPixelPacket *target,const Quantum opacity) { return(TransparentPaintImage(image,target,opacity,MagickFalse)); } /* %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% % % % % % % + P a r s e I m a g e G e o m e t r y % % % % % % % %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% % % ParseImageGeometry() is similar to GetGeometry() except the returned % geometry is modified as determined by the meta characters: %, !, <, % and >. % % Deprecated, replace with: % % ParseMetaGeometry(geometry,x,y,width,height); % % The format of the ParseImageGeometry method is: % % int ParseImageGeometry(char *geometry,ssize_t *x,ssize_t *y, % size_t *width,size_t *height) % % A description of each parameter follows: % % o flags: Method ParseImageGeometry returns a bitmask that indicates % which of the four values were located in the geometry string. % % o image_geometry: Specifies a character string representing the geometry % specification. % % o x,y: A pointer to an integer. The x and y offset as determined by % the geometry specification is returned here. % % o width,height: A pointer to an unsigned integer. The width and height % as determined by the geometry specification is returned here. % */ MagickExport int ParseImageGeometry(const char *geometry,ssize_t *x,ssize_t *y, size_t *width,size_t *height) { (void) LogMagickEvent(DeprecateEvent,GetMagickModule(),"last use: v5.5.1"); return((int) ParseMetaGeometry(geometry,x,y,width,height)); } /* %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% % % % % % % % P a r s e S i z e G e o m e t r y % % % % % % % %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% % % ParseSizeGeometry() returns a region as defined by the geometry string with % respect to the image dimensions and aspect ratio. % % Deprecated, replace with: % % ParseMetaGeometry(geometry,&region_info->x,&region_info->y, % &region_info->width,&region_info->height); % % The format of the ParseSizeGeometry method is: % % MagickStatusType ParseSizeGeometry(const Image *image, % const char *geometry,RectangeInfo *region_info) % % A description of each parameter follows: % % o geometry: The geometry (e.g. 100x100+10+10). % % o region_info: the region as defined by the geometry string. % */ MagickExport MagickStatusType ParseSizeGeometry(const Image *image, const char *geometry,RectangleInfo *region_info) { MagickStatusType flags; (void) LogMagickEvent(DeprecateEvent,GetMagickModule(),"last use: v6.4.7"); SetGeometry(image,region_info); flags=ParseMetaGeometry(geometry,&region_info->x,&region_info->y, &region_info->width,&region_info->height); return(flags); } /* %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% % % % % % % % P o p I m a g e L i s t % % % % % % % %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% % % PopImageList() removes the last image in the list. % % Deprecated, replace with: % % RemoveLastImageFromList(images); % % The format of the PopImageList method is: % % Image *PopImageList(Image **images) % % A description of each parameter follows: % % o images: the image list. % */ MagickExport Image *PopImageList(Image **images) { (void) LogMagickEvent(DeprecateEvent,GetMagickModule(),"last use: v5.5.2"); return(RemoveLastImageFromList(images)); } /* %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% % % % % % % % P o p I m a g e P i x e l s % % % % % % % %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% % % PopImagePixels() transfers one or more pixel components from the image pixel % cache to a user supplied buffer. The pixels are returned in network byte % order. MagickTrue is returned if the pixels are successfully transferred, % otherwise MagickFalse. % % The format of the PopImagePixels method is: % % size_t PopImagePixels(Image *,const QuantumType quantum, % unsigned char *destination) % % A description of each parameter follows: % % o image: the image. % % o quantum: Declare which pixel components to transfer (RGB, RGBA, etc). % % o destination: The components are transferred to this buffer. % */ MagickExport size_t PopImagePixels(Image *image,const QuantumType quantum, unsigned char *destination) { QuantumInfo *quantum_info; size_t length; quantum_info=AcquireQuantumInfo((const ImageInfo *) NULL,image); if (quantum_info == (QuantumInfo *) NULL) return(0); length=ExportQuantumPixels(image,(const CacheView *) NULL,quantum_info, quantum,destination,&image->exception); quantum_info=DestroyQuantumInfo(quantum_info); return(length); } /* %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% % % % % % % % P o s t s c r i p t G e o m e t r y % % % % % % % %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% % % PostscriptGeometry() replaces any page mneumonic with the equivalent size in % picas. % % Deprecated, replace with: % % GetPageGeometry(page); % % The format of the PostscriptGeometry method is: % % char *PostscriptGeometry(const char *page) % % A description of each parameter follows. % % o page: Specifies a pointer to an array of characters. % The string is either a Postscript page name (e.g. A4) or a postscript % page geometry (e.g. 612x792+36+36). % */ MagickExport char *PostscriptGeometry(const char *page) { (void) LogMagickEvent(DeprecateEvent,GetMagickModule(),"last use: v5.5.1"); return(GetPageGeometry(page)); } /* %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% % % % % % % % P u s h I m a g e L i s t % % % % % % % %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% % % PushImageList() adds an image to the end of the list. % % Deprecated, replace with: % % AppendImageToList(images,CloneImageList(image,exception)); % % The format of the PushImageList method is: % % unsigned int PushImageList(Image *images,const Image *image, % ExceptionInfo *exception) % % A description of each parameter follows: % % o images: the image list. % % o image: the image. % % o exception: return any errors or warnings in this structure. % */ MagickExport unsigned int PushImageList(Image **images,const Image *image, ExceptionInfo *exception) { (void) LogMagickEvent(DeprecateEvent,GetMagickModule(),"last use: v5.5.2"); AppendImageToList(images,CloneImageList(image,exception)); return(MagickTrue); } /* %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% % % % % % % % P u s h I m a g e P i x e l s % % % % % % % %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% % % PushImagePixels() transfers one or more pixel components from a user % supplied buffer into the image pixel cache of an image. The pixels are % expected in network byte order. It returns MagickTrue if the pixels are % successfully transferred, otherwise MagickFalse. % % The format of the PushImagePixels method is: % % size_t PushImagePixels(Image *image,const QuantumType quantum, % const unsigned char *source) % % A description of each parameter follows: % % o image: the image. % % o quantum: Declare which pixel components to transfer (red, green, blue, % opacity, RGB, or RGBA). % % o source: The pixel components are transferred from this buffer. % */ MagickExport size_t PushImagePixels(Image *image,const QuantumType quantum, const unsigned char *source) { QuantumInfo *quantum_info; size_t length; quantum_info=AcquireQuantumInfo((const ImageInfo *) NULL,image); if (quantum_info == (QuantumInfo *) NULL) return(0); length=ImportQuantumPixels(image,(CacheView *) NULL,quantum_info,quantum, source,&image->exception); quantum_info=DestroyQuantumInfo(quantum_info); return(length); } /* %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% % % % % % % % Q u a n t i z a t i o n E r r o r % % % % % % % %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% % % QuantizationError() measures the difference between the original and % quantized images. This difference is the total quantization error. The % error is computed by summing over all pixels in an image the distance % squared in RGB space between each reference pixel value and its quantized % value. These values are computed: % % o mean_error_per_pixel: This value is the mean error for any single % pixel in the image. % % o normalized_mean_square_error: This value is the normalized mean % quantization error for any single pixel in the image. This distance % measure is normalized to a range between 0 and 1. It is independent % of the range of red, green, and blue values in the image. % % o normalized_maximum_square_error: Thsi value is the normalized % maximum quantization error for any single pixel in the image. This % distance measure is normalized to a range between 0 and 1. It is % independent of the range of red, green, and blue values in your image. % % Deprecated, replace with: % % GetImageQuantizeError(image); % % The format of the QuantizationError method is: % % unsigned int QuantizationError(Image *image) % % A description of each parameter follows. % % o image: Specifies a pointer to an Image structure; returned from % ReadImage. % */ MagickExport unsigned int QuantizationError(Image *image) { if (image->debug != MagickFalse) (void) LogMagickEvent(DeprecateEvent,GetMagickModule(),"last use: v5.5.3"); return(GetImageQuantizeError(image)); } /* %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% % % % % % R a n d o m C h a n n e l T h r e s h o l d I m a g e % % % % % % % %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% % % RandomChannelThresholdImage() changes the value of individual pixels based % on the intensity of each pixel compared to a random threshold. The result % is a low-contrast, two color image. % % The format of the RandomChannelThresholdImage method is: % % unsigned int RandomChannelThresholdImage(Image *image, % const char *channel, const char *thresholds, % ExceptionInfo *exception) % % A description of each parameter follows: % % o image: the image. % % o channel: the channel or channels to be thresholded. % % o thresholds: a geometry string containing LOWxHIGH thresholds. % If the string contains 2x2, 3x3, or 4x4, then an ordered % dither of order 2, 3, or 4 will be performed instead. % % o exception: return any errors or warnings in this structure. % */ MagickExport unsigned int RandomChannelThresholdImage(Image *image,const char *channel,const char *thresholds,ExceptionInfo *exception) { #define RandomChannelThresholdImageText " RandomChannelThreshold image... " double lower_threshold, upper_threshold; RandomInfo *random_info; ssize_t count, y; static MagickRealType o2[4]={0.2f, 0.6f, 0.8f, 0.4f}, o3[9]={0.1f, 0.6f, 0.3f, 0.7f, 0.5f, 0.8f, 0.4f, 0.9f, 0.2f}, o4[16]={0.1f, 0.7f, 1.1f, 0.3f, 1.0f, 0.5f, 1.5f, 0.8f, 1.4f, 1.6f, 0.6f, 1.2f, 0.4f, 0.9f, 1.3f, 0.2f}, threshold=128; size_t order; /* Threshold image. */ assert(image != (Image *) NULL); assert(image->signature == MagickSignature); if (image->debug != MagickFalse) (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename); assert(exception != (ExceptionInfo *) NULL); assert(exception->signature == MagickSignature); if (image->debug != MagickFalse) (void) LogMagickEvent(DeprecateEvent,GetMagickModule(),"last use: v5.5.7"); if (thresholds == (const char *) NULL) return(MagickTrue); if (LocaleCompare(thresholds,"2x2") == 0) order=2; else if (LocaleCompare(thresholds,"3x3") == 0) order=3; else if (LocaleCompare(thresholds,"4x4") == 0) order=4; else { order=1; lower_threshold=0; upper_threshold=0; count=(ssize_t) sscanf(thresholds,"%lf[/x%%]%lf",&lower_threshold, &upper_threshold); if (strchr(thresholds,'%') != (char *) NULL) { upper_threshold*=(.01*QuantumRange); lower_threshold*=(.01*QuantumRange); } if (count == 1) upper_threshold=(MagickRealType) QuantumRange-lower_threshold; } if (image->debug != MagickFalse) (void) LogMagickEvent(TransformEvent,GetMagickModule(), " RandomChannelThresholdImage: channel type=%s",channel); if (image->debug != MagickFalse) (void) LogMagickEvent(TransformEvent,GetMagickModule(), " Thresholds: %s (%fx%f)",thresholds,lower_threshold,upper_threshold); if (LocaleCompare(channel,"all") == 0 || LocaleCompare(channel,"intensity") == 0) if (AcquireImageColormap(image,2) == MagickFalse) ThrowBinaryException(ResourceLimitError,"MemoryAllocationFailed", image->filename); random_info=AcquireRandomInfo(); for (y=0; y < (ssize_t) image->rows; y++) { register ssize_t x; register IndexPacket index, *restrict indexes; register PixelPacket *restrict q; q=GetAuthenticPixels(image,0,y,image->columns,1,exception); if (q == (PixelPacket *) NULL) break; if (LocaleCompare(channel,"all") == 0 || LocaleCompare(channel,"intensity") == 0) { indexes=GetAuthenticIndexQueue(image); for (x=0; x < (ssize_t) image->columns; x++) { MagickRealType intensity; intensity=(MagickRealType) PixelIntensityToQuantum(q); if (order == 1) { if (intensity < lower_threshold) threshold=lower_threshold; else if (intensity > upper_threshold) threshold=upper_threshold; else threshold=(MagickRealType) (QuantumRange* GetPseudoRandomValue(random_info)); } else if (order == 2) threshold=(MagickRealType) QuantumRange*o2[(x%2)+2*(y%2)]; else if (order == 3) threshold=(MagickRealType) QuantumRange*o3[(x%3)+3*(y%3)]; else if (order == 4) threshold=(MagickRealType) QuantumRange*o4[(x%4)+4*(y%4)]; index=(IndexPacket) (intensity <= threshold ? 0 : 1); SetPixelIndex(indexes+x,index); SetPixelRGBO(q,image->colormap+(ssize_t) index); q++; } } if (LocaleCompare(channel,"opacity") == 0 || LocaleCompare(channel,"all") == 0 || LocaleCompare(channel,"matte") == 0) { if (image->matte != MagickFalse) for (x=0; x < (ssize_t) image->columns; x++) { if (order == 1) { if ((MagickRealType) q->opacity < lower_threshold) threshold=lower_threshold; else if ((MagickRealType) q->opacity > upper_threshold) threshold=upper_threshold; else threshold=(MagickRealType) (QuantumRange* GetPseudoRandomValue(random_info)); } else if (order == 2) threshold=(MagickRealType) QuantumRange*o2[(x%2)+2*(y%2)]; else if (order == 3) threshold=(MagickRealType) QuantumRange*o3[(x%3)+3*(y%3)]; else if (order == 4) threshold=(MagickRealType) QuantumRange*o4[(x%4)+4*(y%4)]/1.7; SetPixelOpacity(q,(MagickRealType) q->opacity <= threshold ? 0 : QuantumRange); q++; } } else { /* To Do: red, green, blue, cyan, magenta, yellow, black */ if (LocaleCompare(channel,"intensity") != 0) ThrowBinaryException(OptionError,"UnrecognizedChannelType", image->filename); } if (SyncAuthenticPixels(image,exception) == MagickFalse) break; } random_info=DestroyRandomInfo(random_info); return(MagickTrue); } /* %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% % % % % % % % R e a c q u i r e M e m o r y % % % % % % % %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% % % ReacquireMemory() changes the size of the memory and returns a pointer to % the (possibly moved) block. The contents will be unchanged up to the % lesser of the new and old sizes. % % The format of the ReacquireMemory method is: % % void ReacquireMemory(void **memory,const size_t size) % % A description of each parameter follows: % % o memory: A pointer to a memory allocation. On return the pointer % may change but the contents of the original allocation will not. % % o size: the new size of the allocated memory. % */ MagickExport void ReacquireMemory(void **memory,const size_t size) { void *allocation; assert(memory != (void **) NULL); (void) LogMagickEvent(DeprecateEvent,GetMagickModule(),"last use: v5.5.7"); if (*memory == (void *) NULL) { *memory=AcquireMagickMemory(size); return; } allocation=realloc(*memory,size); if (allocation == (void *) NULL) *memory=RelinquishMagickMemory(*memory); *memory=allocation; } /* %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% % % % % % % % R e c o l o r I m a g e % % % % % % % %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% % % RecolorImage() apply color transformation to an image. The method permits % saturation changes, hue rotation, luminance to alpha, and various other % effects. Although variable-sized transformation matrices can be used, % typically one uses a 5x5 matrix for an RGBA image and a 6x6 for CMYKA % (or RGBA with offsets). The matrix is similar to those used by Adobe Flash % except offsets are in column 6 rather than 5 (in support of CMYKA images) % and offsets are normalized (divide Flash offset by 255). % % The format of the RecolorImage method is: % % Image *RecolorImage(const Image *image,const size_t order, % const double *color_matrix,ExceptionInfo *exception) % % A description of each parameter follows: % % o image: the image. % % o order: the number of columns and rows in the recolor matrix. % % o color_matrix: An array of double representing the recolor matrix. % % o exception: return any errors or warnings in this structure. % */ MagickExport Image *RecolorImage(const Image *image,const size_t order, const double *color_matrix,ExceptionInfo *exception) { KernelInfo *kernel_info; Image *recolor_image; kernel_info=AcquireKernelInfo("1"); if (kernel_info == (KernelInfo *) NULL) return((Image *) NULL); kernel_info->width=order; kernel_info->height=order; kernel_info->values=(MagickRealType *) color_matrix; recolor_image=ColorMatrixImage(image,kernel_info,exception); kernel_info->values=(MagickRealType *) NULL; kernel_info=DestroyKernelInfo(kernel_info); return(recolor_image); } /* %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% % % % % % % % R e d u c e N o i s e I m a g e % % % % % % % %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% % % ReduceNoiseImage() smooths the contours of an image while still preserving % edge information. The algorithm works by replacing each pixel with its % neighbor closest in value. A neighbor is defined by radius. Use a radius % of 0 and ReduceNoise() selects a suitable radius for you. % % The format of the ReduceNoiseImage method is: % % Image *ReduceNoiseImage(const Image *image,const double radius, % ExceptionInfo *exception) % % A description of each parameter follows: % % o image: the image. % % o radius: the radius of the pixel neighborhood. % % o exception: return any errors or warnings in this structure. % */ MagickExport Image *ReduceNoiseImage(const Image *image,const double radius, ExceptionInfo *exception) { Image *reduce_image; reduce_image=StatisticImage(image,NonpeakStatistic,(size_t) radius,(size_t) radius,exception); return(reduce_image); } /* %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% % % % % % % % R e s e t I m a g e A t t r i b u t e I t e r a t o r % % % % % % % %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% % % ResetImageAttributeIterator() resets the image attributes iterator. Use it % in conjunction with GetNextImageAttribute() to iterate over all the values % associated with an image. % % Deprecated, replace with: % % ResetImagePropertyIterator(image); % % The format of the ResetImageAttributeIterator method is: % % ResetImageAttributeIterator(const ImageInfo *image) % % A description of each parameter follows: % % o image: the image. % */ MagickExport void ResetImageAttributeIterator(const Image *image) { ResetImagePropertyIterator(image); } /* %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% % % % % % % % S e t C a c h e V i e w P i x e l s % % % % % % % %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% % % SetCacheViewPixels() gets pixels from the in-memory or disk pixel cache as % defined by the geometry parameters. A pointer to the pixels is returned % if the pixels are transferred, otherwise a NULL is returned. % % Deprecated, replace with: % % QueueCacheViewAuthenticPixels(cache_view,x,y,columns,rows, % GetCacheViewException(cache_view)); % % The format of the SetCacheViewPixels method is: % % PixelPacket *SetCacheViewPixels(CacheView *cache_view,const ssize_t x, % const ssize_t y,const size_t columns,const size_t rows) % % A description of each parameter follows: % % o cache_view: the cache view. % % o x,y,columns,rows: These values define the perimeter of a region of % pixels. % */ MagickExport PixelPacket *SetCacheViewPixels(CacheView *cache_view,const ssize_t x, const ssize_t y,const size_t columns,const size_t rows) { PixelPacket *pixels; pixels=QueueCacheViewAuthenticPixels(cache_view,x,y,columns,rows, GetCacheViewException(cache_view)); return(pixels); } /* %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% % % % % % % + S e t C a c h e T h e s h o l d % % % % % % % %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% % % SetCacheThreshold() sets the amount of free memory allocated for the pixel % cache. Once this threshold is exceeded, all subsequent pixels cache % operations are to/from disk. % % The format of the SetCacheThreshold() method is: % % void SetCacheThreshold(const size_t threshold) % % A description of each parameter follows: % % o threshold: the number of megabytes of memory available to the pixel % cache. % */ MagickExport void SetCacheThreshold(const size_t size) { (void) LogMagickEvent(DeprecateEvent,GetMagickModule(),"last use: v5.5.1"); (void) SetMagickResourceLimit(MemoryResource,size*1024*1024); (void) SetMagickResourceLimit(MapResource,2*size*1024*1024); } /* %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% % % % % % % % S e t E x c e p t i o n I n f o % % % % % % % %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% % % SetExceptionInfo() sets the exception severity. % % The format of the SetExceptionInfo method is: % % MagickBooleanType SetExceptionInfo(ExceptionInfo *exception, % ExceptionType severity) % % A description of each parameter follows: % % o exception: the exception info. % % o severity: the exception severity. % */ MagickExport MagickBooleanType SetExceptionInfo(ExceptionInfo *exception, ExceptionType severity) { assert(exception != (ExceptionInfo *) NULL); ClearMagickException(exception); exception->severity=severity; return(MagickTrue); } /* %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% % % % % % % % S e t I m a g e % % % % % % % %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% % % SetImage() sets the red, green, and blue components of each pixel to % the image background color and the opacity component to the specified % level of transparency. The background color is defined by the % background_color member of the image. % % The format of the SetImage method is: % % void SetImage(Image *image,const Quantum opacity) % % A description of each parameter follows: % % o image: the image. % % o opacity: Set each pixel to this level of transparency. % */ MagickExport void SetImage(Image *image,const Quantum opacity) { PixelPacket background_color; ssize_t y; (void) LogMagickEvent(DeprecateEvent,GetMagickModule(),"last use: v6.2.0"); assert(image != (Image *) NULL); if (image->debug != MagickFalse) (void) LogMagickEvent(TraceEvent,GetMagickModule(),"..."); assert(image->signature == MagickSignature); background_color=image->background_color; if (opacity != OpaqueOpacity) background_color.opacity=opacity; if (background_color.opacity != OpaqueOpacity) { (void) SetImageStorageClass(image,DirectClass); image->matte=MagickTrue; } if ((image->storage_class == PseudoClass) || (image->colorspace == CMYKColorspace)) { /* Set colormapped or CMYK image. */ for (y=0; y < (ssize_t) image->rows; y++) { register IndexPacket *restrict indexes; register ssize_t x; register PixelPacket *restrict q; q=QueueAuthenticPixels(image,0,y,image->columns,1,&image->exception); if (q == (PixelPacket *) NULL) break; for (x=0; x < (ssize_t) image->columns; x++) { SetPixelRGBO(q,&background_color); q++; } indexes=GetAuthenticIndexQueue(image); for (x=0; x < (ssize_t) image->columns; x++) SetPixelIndex(indexes+x,0); if (SyncAuthenticPixels(image,&image->exception) == MagickFalse) break; } return; } /* Set DirectClass image. */ for (y=0; y < (ssize_t) image->rows; y++) { register ssize_t x; register PixelPacket *restrict q; q=QueueAuthenticPixels(image,0,y,image->columns,1,&image->exception); if (q == (PixelPacket *) NULL) break; for (x=0; x < (ssize_t) image->columns; x++) { SetPixelRGBO(q,&background_color); q++; } if (SyncAuthenticPixels(image,&image->exception) == MagickFalse) break; } } /* %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% % % % % % % % S e t I m a g e A t t r i b u t e % % % % % % % %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% % % SetImageAttribute() searches the list of image attributes and replaces the % attribute value. If it is not found in the list, the attribute name % and value is added to the list. % % Deprecated, replace with: % % SetImageProperty(image,key,value); % % The format of the SetImageAttribute method is: % % MagickBooleanType SetImageAttribute(Image *image,const char *key, % const char *value) % % A description of each parameter follows: % % o image: the image. % % o key: the key. % % o value: the value. % */ MagickExport MagickBooleanType SetImageAttribute(Image *image,const char *key, const char *value) { (void) LogMagickEvent(DeprecateEvent,GetMagickModule(),"last use: v6.3.1"); return(SetImageProperty(image,key,value)); } /* %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% % % % % % % % S e t I m a g e L i s t % % % % % % % %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% % % SetImageList() inserts an image into the list at the specified position. % % The format of the SetImageList method is: % % unsigned int SetImageList(Image *images,const Image *image, % const ssize_t offset,ExceptionInfo *exception) % % A description of each parameter follows: % % o images: the image list. % % o image: the image. % % o offset: the position within the list. % % o exception: return any errors or warnings in this structure. % */ MagickExport unsigned int SetImageList(Image **images,const Image *image, const ssize_t offset,ExceptionInfo *exception) { Image *clone; register ssize_t i; (void) LogMagickEvent(DeprecateEvent,GetMagickModule(),"last use: v5.5.2"); clone=CloneImageList(image,exception); while (GetPreviousImageInList(*images) != (Image *) NULL) (*images)=GetPreviousImageInList(*images); for (i=0; i < offset; i++) { if (GetNextImageInList(*images) == (Image *) NULL) return(MagickFalse); (*images)=GetNextImageInList(*images); } InsertImageInList(images,clone); return(MagickTrue); } /* %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% % % % % % % % S e t I m a g e P i x e l s % % % % % % % %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% % % SetImagePixels() queues a mutable pixel region. % If the region is successfully initialized a pointer to a PixelPacket % array representing the region is returned, otherwise NULL is returned. % The returned pointer may point to a temporary working buffer for the % pixels or it may point to the final location of the pixels in memory. % % Write-only access means that any existing pixel values corresponding to % the region are ignored. This useful while the initial image is being % created from scratch, or if the existing pixel values are to be % completely replaced without need to refer to their pre-existing values. % The application is free to read and write the pixel buffer returned by % SetImagePixels() any way it pleases. SetImagePixels() does not initialize % the pixel array values. Initializing pixel array values is the % application's responsibility. % % Performance is maximized if the selected region is part of one row, or % one or more full rows, since then there is opportunity to access the % pixels in-place (without a copy) if the image is in RAM, or in a % memory-mapped file. The returned pointer should *never* be deallocated % by the user. % % Pixels accessed via the returned pointer represent a simple array of type % PixelPacket. If the image type is CMYK or the storage class is PseudoClass, % call GetAuthenticIndexQueue() after invoking GetAuthenticPixels() to obtain % the black color component or the colormap indexes (of type IndexPacket) % corresponding to the region. Once the PixelPacket (and/or IndexPacket) % array has been updated, the changes must be saved back to the underlying % image using SyncAuthenticPixels() or they may be lost. % % Deprecated, replace with: % % QueueAuthenticPixels(image,x,y,columns,rows,&image->exception); % % The format of the SetImagePixels() method is: % % PixelPacket *SetImagePixels(Image *image,const ssize_t x,const ssize_t y, % const size_t columns,const size_t rows) % % A description of each parameter follows: % % o pixels: SetImagePixels returns a pointer to the pixels if they are % transferred, otherwise a NULL is returned. % % o image: the image. % % o x,y,columns,rows: These values define the perimeter of a region of % pixels. % */ MagickExport PixelPacket *SetImagePixels(Image *image,const ssize_t x,const ssize_t y, const size_t columns,const size_t rows) { return(QueueAuthenticPixels(image,x,y,columns,rows,&image->exception)); } /* %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% % % % % % % % S e t M a g i c k R e g i s t r y % % % % % % % %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% % % SetMagickRegistry() sets a blob into the registry and returns a unique ID. % If an error occurs, -1 is returned. % % The format of the SetMagickRegistry method is: % % ssize_t SetMagickRegistry(const RegistryType type,const void *blob, % const size_t length,ExceptionInfo *exception) % % A description of each parameter follows: % % o type: the registry type. % % o blob: the address of a Binary Large OBject. % % o length: For a registry type of ImageRegistryType use sizeof(Image) % otherise the blob length in number of bytes. % % o exception: return any errors or warnings in this structure. % */ MagickExport ssize_t SetMagickRegistry(const RegistryType type,const void *blob, const size_t magick_unused(length),ExceptionInfo *exception) { char key[MaxTextExtent]; MagickBooleanType status; static ssize_t id = 0; (void) FormatLocaleString(key,MaxTextExtent,"%.20g\n",(double) id); status=SetImageRegistry(type,key,blob,exception); if (status == MagickFalse) return(-1); return(id++); } /* %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% % % % % % % % S e t M o n i t o r H a n d l e r % % % % % % % %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% % % SetMonitorHandler() sets the monitor handler to the specified method % and returns the previous monitor handler. % % The format of the SetMonitorHandler method is: % % MonitorHandler SetMonitorHandler(MonitorHandler handler) % % A description of each parameter follows: % % o handler: Specifies a pointer to a method to handle monitors. % */ MagickExport MonitorHandler GetMonitorHandler(void) { return(monitor_handler); } MagickExport MonitorHandler SetMonitorHandler(MonitorHandler handler) { MonitorHandler previous_handler; previous_handler=monitor_handler; monitor_handler=handler; return(previous_handler); } /* %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% % % % % % % % S h i f t I m a g e L i s t % % % % % % % %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% % % ShiftImageList() removes an image from the beginning of the list. % % Deprecated, replace with: % % RemoveFirstImageFromList(images); % % The format of the ShiftImageList method is: % % Image *ShiftImageList(Image **images) % % A description of each parameter follows: % % o images: the image list. % */ MagickExport Image *ShiftImageList(Image **images) { (void) LogMagickEvent(DeprecateEvent,GetMagickModule(),"last use: v5.5.2"); return(RemoveFirstImageFromList(images)); } /* %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% % % % % % % + S i z e B l o b % % % % % % % %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% % % SizeBlob() returns the current length of the image file or blob. % % Deprecated, replace with: % % GetBlobSize(image); % % The format of the SizeBlob method is: % % off_t SizeBlob(Image *image) % % A description of each parameter follows: % % o size: Method SizeBlob returns the current length of the image file % or blob. % % o image: the image. % */ MagickExport MagickOffsetType SizeBlob(Image *image) { if (image->debug != MagickFalse) (void) LogMagickEvent(DeprecateEvent,GetMagickModule(),"last use: v5.4.3"); return((MagickOffsetType) GetBlobSize(image)); } /* %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% % % % % % % % S p l i c e I m a g e L i s t % % % % % % % %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% % % SpliceImageList() removes the images designated by offset and length from % the list and replaces them with the specified list. % % The format of the SpliceImageList method is: % % Image *SpliceImageList(Image *images,const ssize_t offset, % const size_t length,const Image *splices, % ExceptionInfo *exception) % % A description of each parameter follows: % % o images: the image list. % % o offset: the position within the list. % % o length: the length of the image list to remove. % % o splice: Replace the removed image list with this list. % % o exception: return any errors or warnings in this structure. % */ MagickExport Image *SpliceImageList(Image *images,const ssize_t offset, const size_t length,const Image *splices,ExceptionInfo *exception) { Image *clone; register ssize_t i; if (images->debug != MagickFalse) (void) LogMagickEvent(DeprecateEvent,GetMagickModule(),"last use: v5.5.2"); clone=CloneImageList(splices,exception); while (GetPreviousImageInList(images) != (Image *) NULL) images=GetPreviousImageInList(images); for (i=0; i < offset; i++) { if (GetNextImageInList(images) == (Image *) NULL) return((Image *) NULL); images=GetNextImageInList(images); } (void) SpliceImageIntoList(&images,length,clone); return(images); } /* %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% % % % % % % % S t r i p % % % % % % % %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% % % Strip() strips any whitespace or quotes from the beginning and end of a % string of characters. % % The format of the Strip method is: % % void Strip(char *message) % % A description of each parameter follows: % % o message: Specifies an array of characters. % */ MagickExport void Strip(char *message) { register char *p, *q; assert(message != (char *) NULL); (void) LogMagickEvent(DeprecateEvent,GetMagickModule(),"last use: v5.5.7"); if (*message == '\0') return; if (strlen(message) == 1) return; p=message; while (isspace((int) ((unsigned char) *p)) != 0) p++; if ((*p == '\'') || (*p == '"')) p++; q=message+strlen(message)-1; while ((isspace((int) ((unsigned char) *q)) != 0) && (q > p)) q--; if (q > p) if ((*q == '\'') || (*q == '"')) q--; (void) CopyMagickMemory(message,p,(size_t) (q-p+1)); message[q-p+1]='\0'; } /* %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% % % % % % % % S y n c C a c h e V i e w % % % % % % % %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% % % SyncCacheView() saves the cache view pixels to the in-memory or disk % cache. It returns MagickTrue if the pixel region is synced, otherwise % MagickFalse. % % Deprecated, replace with: % % SyncCacheViewAuthenticPixels(cache_view,GetCacheViewException(cache_view)); % % The format of the SyncCacheView method is: % % MagickBooleanType SyncCacheView(CacheView *cache_view) % % A description of each parameter follows: % % o cache_view: the cache view. % */ MagickExport MagickBooleanType SyncCacheView(CacheView *cache_view) { MagickBooleanType status; status=SyncCacheViewAuthenticPixels(cache_view, GetCacheViewException(cache_view)); return(status); } /* %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% % % % % % % % S y n c C a c h e V i e w P i x e l s % % % % % % % %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% % % SyncCacheViewPixels() saves the cache view pixels to the in-memory % or disk cache. It returns MagickTrue if the pixel region is flushed, % otherwise MagickFalse. % % Deprecated, replace with: % % SyncCacheViewAuthenticPixels(cache_view,GetCacheViewException(cache_view)); % % The format of the SyncCacheViewPixels method is: % % MagickBooleanType SyncCacheViewPixels(CacheView *cache_view) % % A description of each parameter follows: % % o cache_view: the cache view. % % o exception: return any errors or warnings in this structure. % */ MagickExport MagickBooleanType SyncCacheViewPixels(CacheView *cache_view) { MagickBooleanType status; status=SyncCacheViewAuthenticPixels(cache_view, GetCacheViewException(cache_view)); return(status); } /* %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% % % % % % % % S y n c I m a g e P i x e l s % % % % % % % %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% % % SyncImagePixels() saves the image pixels to the in-memory or disk cache. % The method returns MagickTrue if the pixel region is synced, otherwise % MagickFalse. % % Deprecated, replace with: % % SyncAuthenticPixels(image,&image->exception); % % The format of the SyncImagePixels() method is: % % MagickBooleanType SyncImagePixels(Image *image) % % A description of each parameter follows: % % o image: the image. % */ MagickExport MagickBooleanType SyncImagePixels(Image *image) { return(SyncAuthenticPixels(image,&image->exception)); } /* %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% % % % % % % % T e m p o r a r y F i l e n a m e % % % % % % % %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% % % TemporaryFilename() replaces the contents of path by a unique path name. % % The format of the TemporaryFilename method is: % % void TemporaryFilename(char *path) % % A description of each parameter follows. % % o path: Specifies a pointer to an array of characters. The unique path % name is returned in this array. % */ MagickExport void TemporaryFilename(char *path) { (void) LogMagickEvent(DeprecateEvent,GetMagickModule(),"last use: v5.5.6"); (void) AcquireUniqueFilename(path); (void) RelinquishUniqueFileResource(path); } /* %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% % % % % % % % T h r e s h o l d I m a g e % % % % % % % %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% % % ThresholdImage() changes the value of individual pixels based on % the intensity of each pixel compared to threshold. The result is a % high-contrast, two color image. % % The format of the ThresholdImage method is: % % unsigned int ThresholdImage(Image *image,const double threshold) % % A description of each parameter follows: % % o image: the image. % % o threshold: Define the threshold value % */ MagickExport unsigned int ThresholdImage(Image *image,const double threshold) { #define ThresholdImageTag "Threshold/Image" IndexPacket index; ssize_t y; /* Threshold image. */ assert(image != (Image *) NULL); assert(image->signature == MagickSignature); if (image->debug != MagickFalse) (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename); if (image->debug != MagickFalse) (void) LogMagickEvent(DeprecateEvent,GetMagickModule(),"last use: v5.5.7"); if (!AcquireImageColormap(image,2)) ThrowBinaryException(ResourceLimitError,"MemoryAllocationFailed", "UnableToThresholdImage"); for (y=0; y < (ssize_t) image->rows; y++) { register IndexPacket *restrict indexes; register ssize_t x; register PixelPacket *restrict q; q=GetAuthenticPixels(image,0,y,image->columns,1,&image->exception); if (q == (PixelPacket *) NULL) break; indexes=GetAuthenticIndexQueue(image); for (x=0; x < (ssize_t) image->columns; x++) { index=(IndexPacket) ((MagickRealType) PixelIntensityToQuantum(q) <= threshold ? 0 : 1); SetPixelIndex(indexes+x,index); SetPixelRGBO(q,image->colormap+(ssize_t) index); q++; } if (!SyncAuthenticPixels(image,&image->exception)) break; } return(MagickTrue); } /* %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% % % % % % % % T h r e s h o l d I m a g e C h a n n e l % % % % % % % %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% % % ThresholdImageChannel() changes the value of individual pixels based on % the intensity of each pixel channel. The result is a high-contrast image. % % The format of the ThresholdImageChannel method is: % % unsigned int ThresholdImageChannel(Image *image,const char *threshold) % % A description of each parameter follows: % % o image: the image. % % o threshold: define the threshold values. % */ MagickExport unsigned int ThresholdImageChannel(Image *image, const char *threshold) { #define ThresholdImageTag "Threshold/Image" MagickPixelPacket pixel; GeometryInfo geometry_info; IndexPacket index; ssize_t y; unsigned int flags; /* Threshold image. */ assert(image != (Image *) NULL); assert(image->signature == MagickSignature); if (image->debug != MagickFalse) (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename); if (threshold == (const char *) NULL) return(MagickTrue); if (SetImageStorageClass(image,DirectClass) == MagickFalse) return(MagickFalse); flags=ParseGeometry(threshold,&geometry_info); pixel.red=geometry_info.rho; if (flags & SigmaValue) pixel.green=geometry_info.sigma; else pixel.green=pixel.red; if (flags & XiValue) pixel.blue=geometry_info.xi; else pixel.blue=pixel.red; if (flags & PsiValue) pixel.opacity=geometry_info.psi; else pixel.opacity=(MagickRealType) OpaqueOpacity; if (flags & PercentValue) { pixel.red*=QuantumRange/100.0f; pixel.green*=QuantumRange/100.0f; pixel.blue*=QuantumRange/100.0f; pixel.opacity*=QuantumRange/100.0f; } if (!(flags & SigmaValue)) { if (!AcquireImageColormap(image,2)) ThrowBinaryException(ResourceLimitError,"MemoryAllocationFailed", "UnableToThresholdImage"); if (pixel.red == 0) (void) GetImageDynamicThreshold(image,2.0,2.0,&pixel,&image->exception); } for (y=0; y < (ssize_t) image->rows; y++) { register IndexPacket *restrict indexes; register ssize_t x; register PixelPacket *restrict q; q=GetAuthenticPixels(image,0,y,image->columns,1,&image->exception); if (q == (PixelPacket *) NULL) break; indexes=GetAuthenticIndexQueue(image); if (IsMagickGray(&pixel) != MagickFalse) for (x=0; x < (ssize_t) image->columns; x++) { index=(IndexPacket) ((MagickRealType) PixelIntensityToQuantum(q) <= pixel.red ? 0 : 1); SetPixelIndex(indexes+x,index); SetPixelRed(q,image->colormap[(ssize_t) index].red); SetPixelGreen(q,image->colormap[(ssize_t) index].green); SetPixelBlue(q,image->colormap[(ssize_t) index].blue); q++; } else for (x=0; x < (ssize_t) image->columns; x++) { SetPixelRed(q,(MagickRealType) q->red <= pixel.red ? 0 : QuantumRange); SetPixelGreen(q,(MagickRealType) q->green <= pixel.green ? 0 : QuantumRange); SetPixelBlue(q,(MagickRealType) q->blue <= pixel.blue ? 0 : QuantumRange); SetPixelOpacity(q,(MagickRealType) q->opacity <= pixel.opacity ? 0 : QuantumRange); q++; } if (!SyncAuthenticPixels(image,&image->exception)) break; } return(MagickTrue); } /* %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% % % % % % % + T r a n s f o r m C o l o r s p a c e % % % % % % % %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% % % TransformColorspace() converts the image to a specified colorspace. % If the image is already in the requested colorspace, no work is performed. % Note that the current colorspace is stored in the image colorspace member. % The transformation matrices are not necessarily the standard ones: the % weights are rescaled to normalize the range of the transformed values to % be [0..QuantumRange]. % % Deprecated, replace with: % % TransformImageColorspace(image,colorspace); % % The format of the TransformColorspace method is: % % unsigned int (void) TransformColorspace(Image *image, % const ColorspaceType colorspace) % % A description of each parameter follows: % % o image: the image to transform % % o colorspace: the desired colorspace. % */ MagickExport unsigned int TransformColorspace(Image *image, const ColorspaceType colorspace) { assert(image != (Image *) NULL); assert(image->signature == MagickSignature); if (image->debug != MagickFalse) (void) LogMagickEvent(DeprecateEvent,GetMagickModule(),"last use: v5.5.6"); return(TransformImageColorspace(image,colorspace)); } /* %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% % % % % % % % T r a n s f o r m H S L % % % % % % % %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% % % TransformHSL() converts a (red, green, blue) to a (hue, saturation, % lightness) triple. % % The format of the TransformHSL method is: % % void TransformHSL(const Quantum red,const Quantum green, % const Quantum blue,double *hue,double *saturation,double *lightness) % % A description of each parameter follows: % % o red, green, blue: A Quantum value representing the red, green, and % blue component of a pixel.. % % o hue, saturation, lightness: A pointer to a double value representing a % component of the HSL color space. % */ static inline double MagickMin(const double x,const double y) { if (x < y) return(x); return(y); } MagickExport void TransformHSL(const Quantum red,const Quantum green, const Quantum blue,double *hue,double *saturation,double *lightness) { MagickRealType b, delta, g, max, min, r; /* Convert RGB to HSL colorspace. */ assert(hue != (double *) NULL); assert(saturation != (double *) NULL); assert(lightness != (double *) NULL); r=QuantumScale*red; g=QuantumScale*green; b=QuantumScale*blue; max=MagickMax(r,MagickMax(g,b)); min=MagickMin(r,MagickMin(g,b)); *hue=0.0; *saturation=0.0; *lightness=(double) ((min+max)/2.0); delta=max-min; if (delta == 0.0) return; *saturation=(double) (delta/((*lightness < 0.5) ? (min+max) : (2.0-max-min))); if (r == max) *hue=(double) (g == min ? 5.0+(max-b)/delta : 1.0-(max-g)/delta); else if (g == max) *hue=(double) (b == min ? 1.0+(max-r)/delta : 3.0-(max-b)/delta); else *hue=(double) (r == min ? 3.0+(max-g)/delta : 5.0-(max-r)/delta); *hue/=6.0; } /* %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% % % % % % % % T r a n s l a t e T e x t % % % % % % % %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% % % TranslateText() replaces any embedded formatting characters with the % appropriate image attribute and returns the translated text. % % Deprecated, replace with: % % InterpretImageProperties(image_info,image,embed_text); % % The format of the TranslateText method is: % % char *TranslateText(const ImageInfo *image_info,Image *image, % const char *embed_text) % % A description of each parameter follows: % % o image_info: the image info. % % o image: the image. % % o embed_text: the address of a character string containing the embedded % formatting characters. % */ MagickExport char *TranslateText(const ImageInfo *image_info,Image *image, const char *embed_text) { assert(image != (Image *) NULL); assert(image->signature == MagickSignature); if (image->debug != MagickFalse) (void) LogMagickEvent(DeprecateEvent,GetMagickModule(),"last use: v6.2.6"); return(InterpretImageProperties(image_info,image,embed_text)); } /* %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% % % % % % % % T r a n s p a r e n t I m a g e % % % % % % % %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% % % TransparentImage() changes the opacity value associated with any pixel % that matches color to the value defined by opacity. % % By default color must match a particular pixel color exactly. However, % in many cases two colors may differ by a small amount. Fuzz defines % how much tolerance is acceptable to consider two colors as the same. % For example, set fuzz to 10 and the color red at intensities of 100 and % 102 respectively are now interpreted as the same color. % % The format of the TransparentImage method is: % % MagickBooleanType TransparentImage(Image *image, % const PixelPacket target,const Quantum opacity) % % A description of each parameter follows: % % o image: the image. % % o target: the RGB value of the target color. % % o opacity: the replacement opacity value. % */ MagickExport MagickBooleanType TransparentImage(Image *image, const PixelPacket target,const Quantum opacity) { #define TransparentImageTag "Transparent/Image" MagickBooleanType proceed; ssize_t y; /* Make image color transparent. */ assert(image != (Image *) NULL); assert(image->signature == MagickSignature); (void) LogMagickEvent(DeprecateEvent,GetMagickModule(),"last use: v6.1.0"); if (image->debug != MagickFalse) (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename); if (image->matte == MagickFalse) (void) SetImageAlphaChannel(image,OpaqueAlphaChannel); for (y=0; y < (ssize_t) image->rows; y++) { register ssize_t x; register PixelPacket *restrict q; q=GetAuthenticPixels(image,0,y,image->columns,1,&image->exception); if (q == (PixelPacket *) NULL) break; for (x=0; x < (ssize_t) image->columns; x++) { if (IsColorSimilar(image,q,&target) != MagickFalse) q->opacity=opacity; q++; } if (SyncAuthenticPixels(image,&image->exception) == MagickFalse) break; proceed=SetImageProgress(image,TransparentImageTag,(MagickOffsetType) y, image->rows); if (proceed == MagickFalse) break; } return(MagickTrue); } /* %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% % % % % % % % U n s h i f t I m a g e L i s t % % % % % % % %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% % % UnshiftImageList() adds the image to the beginning of the list. % % Deprecated, replace with: % % PrependImageToList(images,CloneImageList(image,exception)); % % The format of the UnshiftImageList method is: % % unsigned int UnshiftImageList(Image *images,const Image *image, % ExceptionInfo *exception) % % A description of each parameter follows: % % o images: the image list. % % o image: the image. % % o exception: return any errors or warnings in this structure. % */ MagickExport unsigned int UnshiftImageList(Image **images,const Image *image, ExceptionInfo *exception) { (void) LogMagickEvent(DeprecateEvent,GetMagickModule(),"last use: v5.5.2"); PrependImageToList(images,CloneImageList(image,exception)); return(MagickTrue); } /* %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% % % % % % % + V a l i d a t e C o l o r m a p I n d e x % % % % % % % %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% % % ValidateColormapIndex() validates the colormap index. If the index does % not range from 0 to the number of colors in the colormap an exception % issued and 0 is returned. % % Deprecated, replace with: % % ConstrainColormapIndex(image,index); % % The format of the ValidateColormapIndex method is: % % IndexPacket ValidateColormapIndex(Image *image,const unsigned int index) % % A description of each parameter follows: % % o index: Method ValidateColormapIndex returns colormap index if it is % valid other an exception issued and 0 is returned. % % o image: the image. % % o index: This integer is the colormap index. % */ MagickExport IndexPacket ValidateColormapIndex(Image *image, const size_t index) { if (image->debug != MagickFalse) (void) LogMagickEvent(DeprecateEvent,GetMagickModule(),"last use: v5.4.4"); return(ConstrainColormapIndex(image,index)); } /* %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% % % % % % % % Z o o m I m a g e % % % % % % % %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% % % ZoomImage() creates a new image that is a scaled size of an existing one. % It allocates the memory necessary for the new Image structure and returns a % pointer to the new image. The Point filter gives fast pixel replication, % Triangle is equivalent to bi-linear interpolation, and Mitchel giver slower, % very high-quality results. See Graphic Gems III for details on this % algorithm. % % The filter member of the Image structure specifies which image filter to % use. Blur specifies the blur factor where > 1 is blurry, < 1 is sharp. % % The format of the ZoomImage method is: % % Image *ZoomImage(const Image *image,const size_t columns, % const size_t rows,ExceptionInfo *exception) % % A description of each parameter follows: % % o image: the image. % % o columns: An integer that specifies the number of columns in the zoom % image. % % o rows: An integer that specifies the number of rows in the scaled % image. % % o exception: return any errors or warnings in this structure. % */ MagickExport Image *ZoomImage(const Image *image,const size_t columns, const size_t rows,ExceptionInfo *exception) { Image *zoom_image; assert(image != (const Image *) NULL); assert(image->signature == MagickSignature); if (image->debug != MagickFalse) (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename); assert(exception != (ExceptionInfo *) NULL); assert(exception->signature == MagickSignature); zoom_image=ResizeImage(image,columns,rows,image->filter,image->blur, exception); return(zoom_image); } #endif
program_schedule_dynamic.c
#include <stdio.h> #include <omp.h> #include <stdlib.h> #include <unistd.h> int main(int argc, char* argv[]) { int thread_count = strtol(argv[1], NULL, 10); int n = strtol(argv[2], NULL, 10); #pragma omp parallel for num_threads(thread_count) schedule(dynamic) for (int i = 0; i < n; i ++) { printf("i=%d, thread_id=%d\n", i, omp_get_thread_num()); } return 0; }
dct.h
/** * @file dct.h * @author Yibo Lin * @date Sep 2018 */ #ifndef DREAMPLACE_DCT_H #define DREAMPLACE_DCT_H #include "utility/src/torch.h" #include "utility/src/Msg.h" DREAMPLACE_BEGIN_NAMESPACE #define CHECK_CPU(x) AT_ASSERTM(!x.is_cuda(), #x "must be a tensor on CPU") #define CHECK_FLAT(x) AT_ASSERTM(!x.is_cuda() && x.ndimension() == 1, #x "must be a flat tensor on GPU") #define CHECK_EVEN(x) AT_ASSERTM((x.numel()&1) == 0, #x "must have even number of elements") #define CHECK_CONTIGUOUS(x) AT_ASSERTM(x.is_contiguous(), #x "must be contiguous") at::Tensor dct_forward( at::Tensor x, at::Tensor expk, int num_threads ); at::Tensor idct_forward( at::Tensor x, at::Tensor expk, int num_threads ); at::Tensor dct2_forward( at::Tensor x, at::Tensor expk0, at::Tensor expk1, int num_threads ); at::Tensor idct2_forward( at::Tensor x, at::Tensor expk0, at::Tensor expk1, int num_threads ); at::Tensor dst_forward( at::Tensor x, at::Tensor expk, int num_threads ); at::Tensor idst_forward( at::Tensor x, at::Tensor expk, int num_threads ); at::Tensor idxct_forward( at::Tensor x, at::Tensor expk, int num_threads ); at::Tensor idxst_forward( at::Tensor x, at::Tensor expk, int num_threads ); at::Tensor idcct2_forward( at::Tensor x, at::Tensor expk0, at::Tensor expk1, int num_threads ); at::Tensor idcst2_forward( at::Tensor x, at::Tensor expk0, at::Tensor expk1, int num_threads ); at::Tensor idsct2_forward( at::Tensor x, at::Tensor expk0, at::Tensor expk1, int num_threads ); at::Tensor idxst_idct_forward( at::Tensor x, at::Tensor expk0, at::Tensor expk1, int num_threads ); at::Tensor idct_idxst_forward( at::Tensor x, at::Tensor expk0, at::Tensor expk1, int num_threads ); template <typename T> void computeReorder( const T* x, const int M, const int N, T* y, int num_threads ) { #pragma omp parallel for num_threads(num_threads) for (int i = 0; i < M*N; ++i) { int ii = i%N; if (ii < (N>>1)) { // i*2 //printf("x[%d] = y[%d]\n", i+ii, i); y[i] = x[i+ii]; } else { // (N-i)*2-1 //printf("x[%d] = y[%d]\n", i+N*2-ii*3-1, i); y[i] = x[i+N*2-ii*3-1]; } } } template <typename T> void computeMulExpk( const T* x, const T* expk, const int M, const int N, T* z, int num_threads ) { #pragma omp parallel for num_threads(num_threads) for (int i = 0; i < M*N; ++i) { int row = i/N; // row int col = i-row*N; // column int col_2x = (col<<1); int fft_onesided_size = (N>>1)+1; int fft_onesided_size_2x = fft_onesided_size<<1; if (col_2x <= N) { int j = row*fft_onesided_size_2x + col_2x; //printf("x[%d]*expk[%d] + x[%d]*expk[%d] = z[%d]\n", j, col_2x, j+1, col_2x+1, i); z[i] = x[j]*expk[col_2x] + x[j+1]*expk[col_2x+1]; } else { int j = row*fft_onesided_size_2x + (N<<1) - col_2x; //printf("x[%d]*expk[%d] + x[%d]*expk[%d] = z[%d]\n", j, col_2x, j+1, col_2x+1, i); z[i] = x[j]*expk[col_2x] - x[j+1]*expk[col_2x+1]; } } } template <typename T> void computeVk( const T* x, const T* expk, const int M, const int N, T* v, int num_threads ) { #pragma omp parallel for num_threads(num_threads) for (int i = 0; i < M*(N/2+1); ++i) { int ncol = N/2+1; int row = i/ncol; // row int col = i-row*ncol; // column int col_2x = (col<<1); // real T real = x[row*N+col]; T imag = (col == 0)? 0 : -x[row*N+N-col]; v[2*i] = real*expk[col_2x] - imag*expk[col_2x+1]; // imag, x[N-i] v[2*i+1] = real*expk[col_2x+1] + imag*expk[col_2x]; } } template <typename T> void computeReorderReverse( const T* y, const int M, const int N, T* z, int num_threads ) { #pragma omp parallel for num_threads(num_threads) for (int i = 0; i < M*N; ++i) { int row = i/N; // row int col = i-row*N; // column //assert((i-col*2+N-1)*2 < M*N*2); //printf("z[%d] = y[%d]\n", i, (col&1)? (i-col*3/2+N-1) : (i-col/2)); //z[i] = (col&1)? y[(i-col*3/2+N-1)] : y[(i-col/2)]; // according to the paper, it should be N - (col+1)/2 for col is odd // but it seems previous implementation accidentally matches this as well z[i] = (col&1)? y[(i-col) + N - (col+1)/2] : y[(i-col/2)]; } } template <typename T> void addX0AndScale( const T* x, const int M, const int N, T* y, int num_threads ) { #pragma omp parallel for num_threads(num_threads) for (int i = 0; i < M*N; ++i) { int i0 = int(i/N)*N; y[i] = (y[i]+x[i0])*0.5; } } /// extends from addX0AndScale to merge scaling template <typename T> void addX0AndScaleN( const T* x, const int M, const int N, T* y, int num_threads ) { #pragma omp parallel for num_threads(num_threads) for (int i = 0; i < M*N; ++i) { int i0 = int(i/N)*N; // this is to match python implementation // normal way should be multiply by 0.25*N y[i] = y[i]*0.25*N+x[i0]*0.5; } } /// given an array /// x_0, x_1, ..., x_{N-1} /// convert to /// 0, x_{N-1}, ..., x_2, x_1 /// drop x_0 template <typename T> void computeFlipAndShift( const T* x, const int M, const int N, T* y, int num_threads ) { #pragma omp parallel for num_threads(num_threads) for (int i = 0; i < M*N; ++i) { int ii = i%N; y[i] = (ii)? x[i+N-ii*2] : 0; } } /// flip sign of odd entries /// index starts from 0 template <typename T> void negateOddEntries( T* x, const int M, const int N, int num_threads ) { #pragma omp parallel for num_threads(num_threads) for (int i = 0; i < M*(N/2); ++i) { x[i*2+1] = -x[i*2+1]; } } /// given an array /// x_0, x_1, ..., x_{N-1} /// convert to /// x_{N-1}, ..., x_2, x_1, x_0 template <typename T> void computeFlip( const T* x, const int M, const int N, T* y, int num_threads ) { #pragma omp parallel for num_threads(num_threads) for (int i = 0; i < M*N; ++i) { int ii = i%N; y[i] = x[i+N-ii*2-1]; } } at::Tensor dct_2N_forward( at::Tensor x, at::Tensor expk, int num_threads ); at::Tensor idct_2N_forward( at::Tensor x, at::Tensor expk, int num_threads ); at::Tensor dct2_2N_forward( at::Tensor x, at::Tensor expk0, at::Tensor expk1, int num_threads ); at::Tensor idct2_2N_forward( at::Tensor x, at::Tensor expk0, at::Tensor expk1, int num_threads ); template <typename T> void computePad( const T* x, // M*N const int M, const int N, T* z, // M*2N int num_threads ) { #pragma omp parallel for num_threads(num_threads) for (int i = 0; i < M*N; ++i) { int row = i/N; // row int col = i-row*N; // column int j = row*(N<<1) + col; z[j] = x[i]; } } template <typename T> void computeMulExpk_2N( const T* x, // M*(N+1)*2 const T* expk, const int M, const int N, T* z, // M*N int num_threads ) { #pragma omp parallel for num_threads(num_threads) for (int i = 0; i < M*N; ++i) { int row = i/N; // row int col = i-row*N; // column int col_2x = (col<<1); int j = row*((N+1)<<1) + col_2x; z[i] = x[j]*expk[col_2x] + x[j+1]*expk[col_2x+1]; } } template <typename T> void computeMulExpkAndPad_2N( const T* x, // M*N const T* expk, const int M, const int N, T* z, // M*2N*2 int num_threads ) { #pragma omp parallel for num_threads(num_threads) for (int i = 0; i < M*N; ++i) { int row = i/N; // row int col = i-row*N; // column int col_2x = (col<<1); int j = row*(N<<2) + col_2x; z[j] = x[i]*expk[col_2x]; z[j+1] = x[i]*expk[col_2x+1]; } } /// remove last N entries in each column template <typename T> void computeTruncation( const T* x, // M*2N const int M, const int N, T* z, // M*N int num_threads ) { #pragma omp parallel for num_threads(num_threads) for (int i = 0; i < M*N; ++i) { int row = i/N; // row int col = i-row*N; // column int j = row*(N<<1) + col; z[i] = x[j]; } } DREAMPLACE_END_NAMESPACE #endif
data.c
#include "data.h" #include "utils.h" #include "image.h" #include "cuda.h" #include <stdio.h> #include <stdlib.h> #include <string.h> pthread_mutex_t mutex = PTHREAD_MUTEX_INITIALIZER; list *get_paths(char *filename) { char *path; FILE *file = fopen(filename, "r"); if(!file) file_error(filename); list *lines = make_list(); while((path=fgetl(file))){ list_insert(lines, path); } fclose(file); return lines; } /* char **get_random_paths_indexes(char **paths, int n, int m, int *indexes) { char **random_paths = calloc(n, sizeof(char*)); int i; pthread_mutex_lock(&mutex); for(i = 0; i < n; ++i){ int index = rand()%m; indexes[i] = index; random_paths[i] = paths[index]; if(i == 0) printf("%s\n", paths[index]); } pthread_mutex_unlock(&mutex); return random_paths; } */ char **get_random_paths(char **paths, int n, int m) { char **random_paths = calloc(n, sizeof(char*)); int i; pthread_mutex_lock(&mutex); for(i = 0; i < n; ++i){ int index = rand()%m; random_paths[i] = paths[index]; //if(i == 0) printf("%s\n", paths[index]); } pthread_mutex_unlock(&mutex); return random_paths; } char **find_replace_paths(char **paths, int n, char *find, char *replace) { char **replace_paths = calloc(n, sizeof(char*)); int i; for(i = 0; i < n; ++i){ char replaced[4096]; find_replace(paths[i], find, replace, replaced); replace_paths[i] = copy_string(replaced); } return replace_paths; } matrix load_image_paths_gray(char **paths, int n, int w, int h) { int i; matrix X; X.rows = n; X.vals = calloc(X.rows, sizeof(float*)); X.cols = 0; for(i = 0; i < n; ++i){ image im = load_image(paths[i], w, h, 3); image gray = grayscale_image(im); free_image(im); im = gray; X.vals[i] = im.data; X.cols = im.h*im.w*im.c; } return X; } matrix load_image_paths(char **paths, int n, int w, int h) { int i; matrix X; X.rows = n; X.vals = calloc(X.rows, sizeof(float*)); X.cols = 0; for(i = 0; i < n; ++i){ image im = load_image_color(paths[i], w, h); X.vals[i] = im.data; X.cols = im.h*im.w*im.c; } return X; } matrix load_image_augment_paths(char **paths, int n, int min, int max, int size, float angle, float aspect, float hue, float saturation, float exposure, int center) { int i; matrix X; X.rows = n; X.vals = calloc(X.rows, sizeof(float*)); X.cols = 0; for(i = 0; i < n; ++i){ image im = load_image_color(paths[i], 0, 0); image crop; if(center){ crop = center_crop_image(im, size, size); } else { crop = random_augment_image(im, angle, aspect, min, max, size, size); } int flip = rand()%2; if (flip) flip_image(crop); random_distort_image(crop, hue, saturation, exposure); /* show_image(im, "orig"); show_image(crop, "crop"); cvWaitKey(0); */ //grayscale_image_3c(crop); free_image(im); X.vals[i] = crop.data; X.cols = crop.h*crop.w*crop.c; } return X; } box_label *read_boxes(char *filename, int *n) { FILE *file = fopen(filename, "r"); if(!file) file_error(filename); float x, y, h, w; int id; int count = 0; int size = 64; box_label *boxes = calloc(size, sizeof(box_label)); while(fscanf(file, "%d %f %f %f %f", &id, &x, &y, &w, &h) == 5){ if(count == size) { size = size * 2; boxes = realloc(boxes, size*sizeof(box_label)); } boxes[count].id = id; boxes[count].x = x; boxes[count].y = y; boxes[count].h = h; boxes[count].w = w; boxes[count].left = x - w/2; boxes[count].right = x + w/2; boxes[count].top = y - h/2; boxes[count].bottom = y + h/2; ++count; } fclose(file); *n = count; return boxes; } void randomize_boxes(box_label *b, int n) { int i; for(i = 0; i < n; ++i){ box_label swap = b[i]; int index = rand()%n; b[i] = b[index]; b[index] = swap; } } void correct_boxes(box_label *boxes, int n, float dx, float dy, float sx, float sy, int flip) { int i; for(i = 0; i < n; ++i){ if(boxes[i].x == 0 && boxes[i].y == 0) { boxes[i].x = 999999; boxes[i].y = 999999; boxes[i].w = 999999; boxes[i].h = 999999; continue; } boxes[i].left = boxes[i].left * sx - dx; boxes[i].right = boxes[i].right * sx - dx; boxes[i].top = boxes[i].top * sy - dy; boxes[i].bottom = boxes[i].bottom* sy - dy; if(flip){ float swap = boxes[i].left; boxes[i].left = 1. - boxes[i].right; boxes[i].right = 1. - swap; } boxes[i].left = constrain(0, 1, boxes[i].left); boxes[i].right = constrain(0, 1, boxes[i].right); boxes[i].top = constrain(0, 1, boxes[i].top); boxes[i].bottom = constrain(0, 1, boxes[i].bottom); boxes[i].x = (boxes[i].left+boxes[i].right)/2; boxes[i].y = (boxes[i].top+boxes[i].bottom)/2; boxes[i].w = (boxes[i].right - boxes[i].left); boxes[i].h = (boxes[i].bottom - boxes[i].top); boxes[i].w = constrain(0, 1, boxes[i].w); boxes[i].h = constrain(0, 1, boxes[i].h); } } void fill_truth_swag(char *path, float *truth, int classes, int flip, float dx, float dy, float sx, float sy) { char labelpath[4096]; find_replace(path, "images", "labels", labelpath); find_replace(labelpath, "JPEGImages", "labels", labelpath); find_replace(labelpath, ".jpg", ".txt", labelpath); find_replace(labelpath, ".JPG", ".txt", labelpath); find_replace(labelpath, ".JPEG", ".txt", labelpath); int count = 0; box_label *boxes = read_boxes(labelpath, &count); randomize_boxes(boxes, count); correct_boxes(boxes, count, dx, dy, sx, sy, flip); float x,y,w,h; int id; int i; for (i = 0; i < count && i < 90; ++i) { x = boxes[i].x; y = boxes[i].y; w = boxes[i].w; h = boxes[i].h; id = boxes[i].id; if (w < .0 || h < .0) continue; int index = (4+classes) * i; truth[index++] = x; truth[index++] = y; truth[index++] = w; truth[index++] = h; if (id < classes) truth[index+id] = 1; } free(boxes); } void fill_truth_region(char *path, float *truth, int classes, int num_boxes, int flip, float dx, float dy, float sx, float sy) { char labelpath[4096]; find_replace(path, "images", "labels", labelpath); find_replace(labelpath, "JPEGImages", "labels", labelpath); find_replace(labelpath, ".jpg", ".txt", labelpath); find_replace(labelpath, ".png", ".txt", labelpath); find_replace(labelpath, ".JPG", ".txt", labelpath); find_replace(labelpath, ".JPEG", ".txt", labelpath); int count = 0; box_label *boxes = read_boxes(labelpath, &count); randomize_boxes(boxes, count); correct_boxes(boxes, count, dx, dy, sx, sy, flip); float x,y,w,h; int id; int i; for (i = 0; i < count; ++i) { x = boxes[i].x; y = boxes[i].y; w = boxes[i].w; h = boxes[i].h; id = boxes[i].id; if (w < .005 || h < .005) continue; int col = (int)(x*num_boxes); int row = (int)(y*num_boxes); x = x*num_boxes - col; y = y*num_boxes - row; int index = (col+row*num_boxes)*(5+classes); if (truth[index]) continue; truth[index++] = 1; if (id < classes) truth[index+id] = 1; index += classes; truth[index++] = x; truth[index++] = y; truth[index++] = w; truth[index++] = h; } free(boxes); } void load_rle(image im, int *rle, int n) { int count = 0; int curr = 0; int i,j; for(i = 0; i < n; ++i){ for(j = 0; j < rle[i]; ++j){ im.data[count++] = curr; } curr = 1 - curr; } for(; count < im.h*im.w*im.c; ++count){ im.data[count] = curr; } } void or_image(image src, image dest, int c) { int i; for(i = 0; i < src.w*src.h; ++i){ if(src.data[i]) dest.data[dest.w*dest.h*c + i] = 1; } } void exclusive_image(image src) { int k, j, i; int s = src.w*src.h; for(k = 0; k < src.c-1; ++k){ for(i = 0; i < s; ++i){ if (src.data[k*s + i]){ for(j = k+1; j < src.c; ++j){ src.data[j*s + i] = 0; } } } } } box bound_image(image im) { int x,y; int minx = im.w; int miny = im.h; int maxx = 0; int maxy = 0; for(y = 0; y < im.h; ++y){ for(x = 0; x < im.w; ++x){ if(im.data[y*im.w + x]){ minx = (x < minx) ? x : minx; miny = (y < miny) ? y : miny; maxx = (x > maxx) ? x : maxx; maxy = (y > maxy) ? y : maxy; } } } box b = {minx, miny, maxx-minx + 1, maxy-miny + 1}; //printf("%f %f %f %f\n", b.x, b.y, b.w, b.h); return b; } void fill_truth_iseg(char *path, int num_boxes, float *truth, int classes, int w, int h, augment_args aug, int flip, int mw, int mh) { char labelpath[4096]; find_replace(path, "images", "mask", labelpath); find_replace(labelpath, "JPEGImages", "mask", labelpath); find_replace(labelpath, ".jpg", ".txt", labelpath); find_replace(labelpath, ".JPG", ".txt", labelpath); find_replace(labelpath, ".JPEG", ".txt", labelpath); FILE *file = fopen(labelpath, "r"); if(!file) file_error(labelpath); char buff[32788]; int id; int i = 0; int j; image part = make_image(w, h, 1); while((fscanf(file, "%d %s", &id, buff) == 2) && i < num_boxes){ int n = 0; int *rle = read_intlist(buff, &n, 0); load_rle(part, rle, n); image sized = rotate_crop_image(part, aug.rad, aug.scale, aug.w, aug.h, aug.dx, aug.dy, aug.aspect); if(flip) flip_image(sized); image mask = resize_image(sized, mw, mh); truth[i*(mw*mh+1)] = id; for(j = 0; j < mw*mh; ++j){ truth[i*(mw*mh + 1) + 1 + j] = mask.data[j]; } ++i; free_image(mask); free_image(sized); free(rle); } if(i < num_boxes) truth[i*(mw*mh+1)] = -1; fclose(file); free_image(part); } void fill_truth_mask(char *path, int num_boxes, float *truth, int classes, int w, int h, augment_args aug, int flip, int mw, int mh) { char labelpath[4096]; find_replace(path, "images", "mask", labelpath); find_replace(labelpath, "JPEGImages", "mask", labelpath); find_replace(labelpath, ".jpg", ".txt", labelpath); find_replace(labelpath, ".JPG", ".txt", labelpath); find_replace(labelpath, ".JPEG", ".txt", labelpath); FILE *file = fopen(labelpath, "r"); if(!file) file_error(labelpath); char buff[32788]; int id; int i = 0; image part = make_image(w, h, 1); while((fscanf(file, "%d %s", &id, buff) == 2) && i < num_boxes){ int n = 0; int *rle = read_intlist(buff, &n, 0); load_rle(part, rle, n); image sized = rotate_crop_image(part, aug.rad, aug.scale, aug.w, aug.h, aug.dx, aug.dy, aug.aspect); if(flip) flip_image(sized); box b = bound_image(sized); if(b.w > 0){ image crop = crop_image(sized, b.x, b.y, b.w, b.h); image mask = resize_image(crop, mw, mh); truth[i*(4 + mw*mh + 1) + 0] = (b.x + b.w/2.)/sized.w; truth[i*(4 + mw*mh + 1) + 1] = (b.y + b.h/2.)/sized.h; truth[i*(4 + mw*mh + 1) + 2] = b.w/sized.w; truth[i*(4 + mw*mh + 1) + 3] = b.h/sized.h; int j; for(j = 0; j < mw*mh; ++j){ truth[i*(4 + mw*mh + 1) + 4 + j] = mask.data[j]; } truth[i*(4 + mw*mh + 1) + 4 + mw*mh] = id; free_image(crop); free_image(mask); ++i; } free_image(sized); free(rle); } fclose(file); free_image(part); } void fill_truth_detection(char *path, int num_boxes, float *truth, int classes, int flip, float dx, float dy, float sx, float sy) { char labelpath[4096]; find_replace(path, "images", "labels", labelpath); find_replace(labelpath, "JPEGImages", "labels", labelpath); find_replace(labelpath, "raw", "labels", labelpath); find_replace(labelpath, ".jpg", ".txt", labelpath); find_replace(labelpath, ".png", ".txt", labelpath); find_replace(labelpath, ".JPG", ".txt", labelpath); find_replace(labelpath, ".JPEG", ".txt", labelpath); int count = 0; box_label *boxes = read_boxes(labelpath, &count); randomize_boxes(boxes, count); correct_boxes(boxes, count, dx, dy, sx, sy, flip); if(count > num_boxes) count = num_boxes; float x,y,w,h; int id; int i; int sub = 0; for (i = 0; i < count; ++i) { x = boxes[i].x; y = boxes[i].y; w = boxes[i].w; h = boxes[i].h; id = boxes[i].id; if ((w < .001 || h < .001)) { ++sub; continue; } truth[(i-sub)*5+0] = x; truth[(i-sub)*5+1] = y; truth[(i-sub)*5+2] = w; truth[(i-sub)*5+3] = h; truth[(i-sub)*5+4] = id; } free(boxes); } #define NUMCHARS 37 void print_letters(float *pred, int n) { int i; for(i = 0; i < n; ++i){ int index = max_index(pred+i*NUMCHARS, NUMCHARS); printf("%c", int_to_alphanum(index)); } printf("\n"); } void fill_truth_captcha(char *path, int n, float *truth) { char *begin = strrchr(path, '/'); ++begin; int i; for(i = 0; i < strlen(begin) && i < n && begin[i] != '.'; ++i){ int index = alphanum_to_int(begin[i]); if(index > 35) printf("Bad %c\n", begin[i]); truth[i*NUMCHARS+index] = 1; } for(;i < n; ++i){ truth[i*NUMCHARS + NUMCHARS-1] = 1; } } data load_data_captcha(char **paths, int n, int m, int k, int w, int h) { if(m) paths = get_random_paths(paths, n, m); data d = {0}; d.shallow = 0; d.X = load_image_paths(paths, n, w, h); d.y = make_matrix(n, k*NUMCHARS); int i; for(i = 0; i < n; ++i){ fill_truth_captcha(paths[i], k, d.y.vals[i]); } if(m) free(paths); return d; } data load_data_captcha_encode(char **paths, int n, int m, int w, int h) { if(m) paths = get_random_paths(paths, n, m); data d = {0}; d.shallow = 0; d.X = load_image_paths(paths, n, w, h); d.X.cols = 17100; d.y = d.X; if(m) free(paths); return d; } void fill_truth(char *path, char **labels, int k, float *truth) { int i; memset(truth, 0, k*sizeof(float)); int count = 0; for(i = 0; i < k; ++i){ if(strstr(path, labels[i])){ truth[i] = 1; ++count; //printf("%s %s %d\n", path, labels[i], i); } } if(count != 1 && (k != 1 || count != 0)) printf("Too many or too few labels: %d, %s\n", count, path); } void fill_hierarchy(float *truth, int k, tree *hierarchy) { int j; for(j = 0; j < k; ++j){ if(truth[j]){ int parent = hierarchy->parent[j]; while(parent >= 0){ truth[parent] = 1; parent = hierarchy->parent[parent]; } } } int i; int count = 0; for(j = 0; j < hierarchy->groups; ++j){ //printf("%d\n", count); int mask = 1; for(i = 0; i < hierarchy->group_size[j]; ++i){ if(truth[count + i]){ mask = 0; break; } } if (mask) { for(i = 0; i < hierarchy->group_size[j]; ++i){ truth[count + i] = SECRET_NUM; } } count += hierarchy->group_size[j]; } } matrix load_regression_labels_paths(char **paths, int n, int k) { matrix y = make_matrix(n, k); int i,j; for(i = 0; i < n; ++i){ char labelpath[4096]; find_replace(paths[i], "images", "labels", labelpath); find_replace(labelpath, "JPEGImages", "labels", labelpath); find_replace(labelpath, ".DKNET_BMP", ".txt", labelpath); find_replace(labelpath, ".JPEG", ".txt", labelpath); find_replace(labelpath, ".JPG", ".txt", labelpath); find_replace(labelpath, ".JPeG", ".txt", labelpath); find_replace(labelpath, ".Jpeg", ".txt", labelpath); find_replace(labelpath, ".PNG", ".txt", labelpath); find_replace(labelpath, ".TIF", ".txt", labelpath); find_replace(labelpath, ".bmp", ".txt", labelpath); find_replace(labelpath, ".jpeg", ".txt", labelpath); find_replace(labelpath, ".jpg", ".txt", labelpath); find_replace(labelpath, ".png", ".txt", labelpath); find_replace(labelpath, ".tif", ".txt", labelpath); FILE *file = fopen(labelpath, "r"); for(j = 0; j < k; ++j){ fscanf(file, "%f", &(y.vals[i][j])); } fclose(file); } return y; } matrix load_labels_paths(char **paths, int n, char **labels, int k, tree *hierarchy) { matrix y = make_matrix(n, k); int i; for(i = 0; i < n && labels; ++i){ fill_truth(paths[i], labels, k, y.vals[i]); if(hierarchy){ fill_hierarchy(y.vals[i], k, hierarchy); } } return y; } matrix load_tags_paths(char **paths, int n, int k) { matrix y = make_matrix(n, k); int i; //int count = 0; for(i = 0; i < n; ++i){ char label[4096]; find_replace(paths[i], "images", "labels", label); find_replace(label, ".jpg", ".txt", label); FILE *file = fopen(label, "r"); if (!file) continue; //++count; int tag; while(fscanf(file, "%d", &tag) == 1){ if(tag < k){ y.vals[i][tag] = 1; } } fclose(file); } //printf("%d/%d\n", count, n); return y; } char **get_labels(char *filename) { list *plist = get_paths(filename); char **labels = (char **)list_to_array(plist); free_list(plist); return labels; } void free_data(data d) { if(!d.shallow){ free_matrix(d.X); free_matrix(d.y); }else{ free(d.X.vals); free(d.y.vals); } } image get_segmentation_image(char *path, int w, int h, int classes) { char labelpath[4096]; find_replace(path, "images", "mask", labelpath); find_replace(labelpath, "JPEGImages", "mask", labelpath); find_replace(labelpath, ".jpg", ".txt", labelpath); find_replace(labelpath, ".JPG", ".txt", labelpath); find_replace(labelpath, ".JPEG", ".txt", labelpath); image mask = make_image(w, h, classes); FILE *file = fopen(labelpath, "r"); if(!file) file_error(labelpath); char buff[32788]; int id; image part = make_image(w, h, 1); while(fscanf(file, "%d %s", &id, buff) == 2){ int n = 0; int *rle = read_intlist(buff, &n, 0); load_rle(part, rle, n); or_image(part, mask, id); free(rle); } //exclusive_image(mask); fclose(file); free_image(part); return mask; } image get_segmentation_image2(char *path, int w, int h, int classes) { char labelpath[4096]; find_replace(path, "images", "mask", labelpath); find_replace(labelpath, "JPEGImages", "mask", labelpath); find_replace(labelpath, ".jpg", ".txt", labelpath); find_replace(labelpath, ".JPG", ".txt", labelpath); find_replace(labelpath, ".JPEG", ".txt", labelpath); image mask = make_image(w, h, classes+1); int i; for(i = 0; i < w*h; ++i){ mask.data[w*h*classes + i] = 1; } FILE *file = fopen(labelpath, "r"); if(!file) file_error(labelpath); char buff[32788]; int id; image part = make_image(w, h, 1); while(fscanf(file, "%d %s", &id, buff) == 2){ int n = 0; int *rle = read_intlist(buff, &n, 0); load_rle(part, rle, n); or_image(part, mask, id); for(i = 0; i < w*h; ++i){ if(part.data[i]) mask.data[w*h*classes + i] = 0; } free(rle); } //exclusive_image(mask); fclose(file); free_image(part); return mask; } data load_data_seg(int n, char **paths, int m, int w, int h, int classes, int min, int max, float angle, float aspect, float hue, float saturation, float exposure, int div) { char **random_paths = get_random_paths(paths, n, m); int i; data d = {0}; d.shallow = 0; d.X.rows = n; d.X.vals = calloc(d.X.rows, sizeof(float*)); d.X.cols = h*w*3; d.y.rows = n; d.y.cols = h*w*classes/div/div; d.y.vals = calloc(d.X.rows, sizeof(float*)); for(i = 0; i < n; ++i){ image orig = load_image_color(random_paths[i], 0, 0); augment_args a = random_augment_args(orig, angle, aspect, min, max, w, h); image sized = rotate_crop_image(orig, a.rad, a.scale, a.w, a.h, a.dx, a.dy, a.aspect); int flip = rand()%2; if(flip) flip_image(sized); random_distort_image(sized, hue, saturation, exposure); d.X.vals[i] = sized.data; image mask = get_segmentation_image(random_paths[i], orig.w, orig.h, classes); //image mask = make_image(orig.w, orig.h, classes+1); image sized_m = rotate_crop_image(mask, a.rad, a.scale/div, a.w/div, a.h/div, a.dx/div, a.dy/div, a.aspect); if(flip) flip_image(sized_m); d.y.vals[i] = sized_m.data; free_image(orig); free_image(mask); /* image rgb = mask_to_rgb(sized_m, classes); show_image(rgb, "part"); show_image(sized, "orig"); cvWaitKey(0); free_image(rgb); */ } free(random_paths); return d; } data load_data_iseg(int n, char **paths, int m, int w, int h, int classes, int boxes, int div, int min, int max, float angle, float aspect, float hue, float saturation, float exposure) { char **random_paths = get_random_paths(paths, n, m); int i; data d = {0}; d.shallow = 0; d.X.rows = n; d.X.vals = calloc(d.X.rows, sizeof(float*)); d.X.cols = h*w*3; d.y = make_matrix(n, (((w/div)*(h/div))+1)*boxes); for(i = 0; i < n; ++i){ image orig = load_image_color(random_paths[i], 0, 0); augment_args a = random_augment_args(orig, angle, aspect, min, max, w, h); image sized = rotate_crop_image(orig, a.rad, a.scale, a.w, a.h, a.dx, a.dy, a.aspect); int flip = rand()%2; if(flip) flip_image(sized); random_distort_image(sized, hue, saturation, exposure); d.X.vals[i] = sized.data; //show_image(sized, "image"); fill_truth_iseg(random_paths[i], boxes, d.y.vals[i], classes, orig.w, orig.h, a, flip, w/div, h/div); free_image(orig); /* image rgb = mask_to_rgb(sized_m, classes); show_image(rgb, "part"); show_image(sized, "orig"); cvWaitKey(0); free_image(rgb); */ } free(random_paths); return d; } data load_data_mask(int n, char **paths, int m, int w, int h, int classes, int boxes, int coords, int min, int max, float angle, float aspect, float hue, float saturation, float exposure) { char **random_paths = get_random_paths(paths, n, m); int i; data d = {0}; d.shallow = 0; d.X.rows = n; d.X.vals = calloc(d.X.rows, sizeof(float*)); d.X.cols = h*w*3; d.y = make_matrix(n, (coords+1)*boxes); for(i = 0; i < n; ++i){ image orig = load_image_color(random_paths[i], 0, 0); augment_args a = random_augment_args(orig, angle, aspect, min, max, w, h); image sized = rotate_crop_image(orig, a.rad, a.scale, a.w, a.h, a.dx, a.dy, a.aspect); int flip = rand()%2; if(flip) flip_image(sized); random_distort_image(sized, hue, saturation, exposure); d.X.vals[i] = sized.data; //show_image(sized, "image"); fill_truth_mask(random_paths[i], boxes, d.y.vals[i], classes, orig.w, orig.h, a, flip, 14, 14); free_image(orig); /* image rgb = mask_to_rgb(sized_m, classes); show_image(rgb, "part"); show_image(sized, "orig"); cvWaitKey(0); free_image(rgb); */ } free(random_paths); return d; } data load_data_region(int n, char **paths, int m, int w, int h, int size, int classes, float jitter, float hue, float saturation, float exposure) { char **random_paths = get_random_paths(paths, n, m); int i; data d = {0}; d.shallow = 0; d.X.rows = n; d.X.vals = calloc(d.X.rows, sizeof(float*)); d.X.cols = h*w*3; int k = size*size*(5+classes); d.y = make_matrix(n, k); for(i = 0; i < n; ++i){ image orig = load_image_color(random_paths[i], 0, 0); int oh = orig.h; int ow = orig.w; int dw = (ow*jitter); int dh = (oh*jitter); int pleft = rand_uniform(-dw, dw); int pright = rand_uniform(-dw, dw); int ptop = rand_uniform(-dh, dh); int pbot = rand_uniform(-dh, dh); int swidth = ow - pleft - pright; int sheight = oh - ptop - pbot; float sx = (float)swidth / ow; float sy = (float)sheight / oh; int flip = rand()%2; image cropped = crop_image(orig, pleft, ptop, swidth, sheight); float dx = ((float)pleft/ow)/sx; float dy = ((float)ptop /oh)/sy; image sized = resize_image(cropped, w, h); if(flip) flip_image(sized); random_distort_image(sized, hue, saturation, exposure); d.X.vals[i] = sized.data; fill_truth_region(random_paths[i], d.y.vals[i], classes, size, flip, dx, dy, 1./sx, 1./sy); free_image(orig); free_image(cropped); } free(random_paths); return d; } data load_data_compare(int n, char **paths, int m, int classes, int w, int h) { if(m) paths = get_random_paths(paths, 2*n, m); int i,j; data d = {0}; d.shallow = 0; d.X.rows = n; d.X.vals = calloc(d.X.rows, sizeof(float*)); d.X.cols = h*w*6; int k = 2*(classes); d.y = make_matrix(n, k); for(i = 0; i < n; ++i){ image im1 = load_image_color(paths[i*2], w, h); image im2 = load_image_color(paths[i*2+1], w, h); d.X.vals[i] = calloc(d.X.cols, sizeof(float)); memcpy(d.X.vals[i], im1.data, h*w*3*sizeof(float)); memcpy(d.X.vals[i] + h*w*3, im2.data, h*w*3*sizeof(float)); int id; float iou; char imlabel1[4096]; char imlabel2[4096]; find_replace(paths[i*2], "imgs", "labels", imlabel1); find_replace(imlabel1, "jpg", "txt", imlabel1); FILE *fp1 = fopen(imlabel1, "r"); while(fscanf(fp1, "%d %f", &id, &iou) == 2){ if (d.y.vals[i][2*id] < iou) d.y.vals[i][2*id] = iou; } find_replace(paths[i*2+1], "imgs", "labels", imlabel2); find_replace(imlabel2, "jpg", "txt", imlabel2); FILE *fp2 = fopen(imlabel2, "r"); while(fscanf(fp2, "%d %f", &id, &iou) == 2){ if (d.y.vals[i][2*id + 1] < iou) d.y.vals[i][2*id + 1] = iou; } for (j = 0; j < classes; ++j){ if (d.y.vals[i][2*j] > .5 && d.y.vals[i][2*j+1] < .5){ d.y.vals[i][2*j] = 1; d.y.vals[i][2*j+1] = 0; } else if (d.y.vals[i][2*j] < .5 && d.y.vals[i][2*j+1] > .5){ d.y.vals[i][2*j] = 0; d.y.vals[i][2*j+1] = 1; } else { d.y.vals[i][2*j] = SECRET_NUM; d.y.vals[i][2*j+1] = SECRET_NUM; } } fclose(fp1); fclose(fp2); free_image(im1); free_image(im2); } if(m) free(paths); return d; } data load_data_swag(char **paths, int n, int classes, float jitter) { int index = rand()%n; char *random_path = paths[index]; image orig = load_image_color(random_path, 0, 0); int h = orig.h; int w = orig.w; data d = {0}; d.shallow = 0; d.w = w; d.h = h; d.X.rows = 1; d.X.vals = calloc(d.X.rows, sizeof(float*)); d.X.cols = h*w*3; int k = (4+classes)*90; d.y = make_matrix(1, k); int dw = w*jitter; int dh = h*jitter; int pleft = rand_uniform(-dw, dw); int pright = rand_uniform(-dw, dw); int ptop = rand_uniform(-dh, dh); int pbot = rand_uniform(-dh, dh); int swidth = w - pleft - pright; int sheight = h - ptop - pbot; float sx = (float)swidth / w; float sy = (float)sheight / h; int flip = rand()%2; image cropped = crop_image(orig, pleft, ptop, swidth, sheight); float dx = ((float)pleft/w)/sx; float dy = ((float)ptop /h)/sy; image sized = resize_image(cropped, w, h); if(flip) flip_image(sized); d.X.vals[0] = sized.data; fill_truth_swag(random_path, d.y.vals[0], classes, flip, dx, dy, 1./sx, 1./sy); free_image(orig); free_image(cropped); return d; } data load_data_detection(int n, char **paths, int m, int w, int h, int boxes, int classes, float jitter, float hue, float saturation, float exposure) { char **random_paths = get_random_paths(paths, n, m); int i; data d = {0}; d.shallow = 0; d.X.rows = n; d.X.vals = calloc(d.X.rows, sizeof(float*)); d.X.cols = h*w*3; d.y = make_matrix(n, 5*boxes); for(i = 0; i < n; ++i){ image orig = load_image_color(random_paths[i], 0, 0); image sized = make_image(w, h, orig.c); fill_image(sized, .5); float dw = jitter * orig.w; float dh = jitter * orig.h; float new_ar = (orig.w + rand_uniform(-dw, dw)) / (orig.h + rand_uniform(-dh, dh)); //float scale = rand_uniform(.25, 2); float scale = 1; float nw, nh; if(new_ar < 1){ nh = scale * h; nw = nh * new_ar; } else { nw = scale * w; nh = nw / new_ar; } float dx = rand_uniform(0, w - nw); float dy = rand_uniform(0, h - nh); place_image(orig, nw, nh, dx, dy, sized); random_distort_image(sized, hue, saturation, exposure); int flip = rand()%2; if(flip) flip_image(sized); d.X.vals[i] = sized.data; fill_truth_detection(random_paths[i], boxes, d.y.vals[i], classes, flip, -dx/w, -dy/h, nw/w, nh/h); free_image(orig); } free(random_paths); return d; } void *load_thread(void *ptr) { //printf("Loading data: %d\n", rand()); load_args a = *(struct load_args*)ptr; if(a.exposure == 0) a.exposure = 1; if(a.saturation == 0) a.saturation = 1; if(a.aspect == 0) a.aspect = 1; if (a.type == OLD_CLASSIFICATION_DATA){ *a.d = load_data_old(a.paths, a.n, a.m, a.labels, a.classes, a.w, a.h); } else if (a.type == REGRESSION_DATA){ *a.d = load_data_regression(a.paths, a.n, a.m, a.classes, a.min, a.max, a.size, a.angle, a.aspect, a.hue, a.saturation, a.exposure); } else if (a.type == CLASSIFICATION_DATA){ *a.d = load_data_augment(a.paths, a.n, a.m, a.labels, a.classes, a.hierarchy, a.min, a.max, a.size, a.angle, a.aspect, a.hue, a.saturation, a.exposure, a.center); } else if (a.type == SUPER_DATA){ *a.d = load_data_super(a.paths, a.n, a.m, a.w, a.h, a.scale); } else if (a.type == WRITING_DATA){ *a.d = load_data_writing(a.paths, a.n, a.m, a.w, a.h, a.out_w, a.out_h); } else if (a.type == ISEG_DATA){ *a.d = load_data_iseg(a.n, a.paths, a.m, a.w, a.h, a.classes, a.num_boxes, a.scale, a.min, a.max, a.angle, a.aspect, a.hue, a.saturation, a.exposure); } else if (a.type == INSTANCE_DATA){ *a.d = load_data_mask(a.n, a.paths, a.m, a.w, a.h, a.classes, a.num_boxes, a.coords, a.min, a.max, a.angle, a.aspect, a.hue, a.saturation, a.exposure); } else if (a.type == SEGMENTATION_DATA){ *a.d = load_data_seg(a.n, a.paths, a.m, a.w, a.h, a.classes, a.min, a.max, a.angle, a.aspect, a.hue, a.saturation, a.exposure, a.scale); } else if (a.type == REGION_DATA){ *a.d = load_data_region(a.n, a.paths, a.m, a.w, a.h, a.num_boxes, a.classes, a.jitter, a.hue, a.saturation, a.exposure); } else if (a.type == DETECTION_DATA){ *a.d = load_data_detection(a.n, a.paths, a.m, a.w, a.h, a.num_boxes, a.classes, a.jitter, a.hue, a.saturation, a.exposure); } else if (a.type == SWAG_DATA){ *a.d = load_data_swag(a.paths, a.n, a.classes, a.jitter); } else if (a.type == COMPARE_DATA){ *a.d = load_data_compare(a.n, a.paths, a.m, a.classes, a.w, a.h); } else if (a.type == IMAGE_DATA){ *(a.im) = load_image_color(a.path, 0, 0); *(a.resized) = resize_image(*(a.im), a.w, a.h); } else if (a.type == LETTERBOX_DATA){ *(a.im) = load_image_color(a.path, 0, 0); *(a.resized) = letterbox_image(*(a.im), a.w, a.h); } else if (a.type == TAG_DATA){ *a.d = load_data_tag(a.paths, a.n, a.m, a.classes, a.min, a.max, a.size, a.angle, a.aspect, a.hue, a.saturation, a.exposure); } free(ptr); return 0; } pthread_t load_data_in_thread(load_args args) { pthread_t thread; struct load_args *ptr = calloc(1, sizeof(struct load_args)); *ptr = args; if(pthread_create(&thread, 0, load_thread, ptr)) error("Thread creation failed"); return thread; } void *load_threads(void *ptr) { int i; load_args args = *(load_args *)ptr; if (args.threads == 0) args.threads = 1; data *out = args.d; int total = args.n; free(ptr); data *buffers = calloc(args.threads, sizeof(data)); pthread_t *threads = calloc(args.threads, sizeof(pthread_t)); for(i = 0; i < args.threads; ++i){ args.d = buffers + i; args.n = (i+1) * total/args.threads - i * total/args.threads; threads[i] = load_data_in_thread(args); } for(i = 0; i < args.threads; ++i){ pthread_join(threads[i], 0); } *out = concat_datas(buffers, args.threads); out->shallow = 0; for(i = 0; i < args.threads; ++i){ buffers[i].shallow = 1; free_data(buffers[i]); } free(buffers); free(threads); return 0; } void load_data_blocking(load_args args) { struct load_args *ptr = calloc(1, sizeof(struct load_args)); *ptr = args; load_thread(ptr); } pthread_t load_data(load_args args) { pthread_t thread; struct load_args *ptr = calloc(1, sizeof(struct load_args)); *ptr = args; if(pthread_create(&thread, 0, load_threads, ptr)) error("Thread creation failed"); return thread; } data load_data_writing(char **paths, int n, int m, int w, int h, int out_w, int out_h) { if(m) paths = get_random_paths(paths, n, m); char **replace_paths = find_replace_paths(paths, n, ".png", "-label.png"); data d = {0}; d.shallow = 0; d.X = load_image_paths(paths, n, w, h); d.y = load_image_paths_gray(replace_paths, n, out_w, out_h); if(m) free(paths); int i; for(i = 0; i < n; ++i) free(replace_paths[i]); free(replace_paths); return d; } data load_data_old(char **paths, int n, int m, char **labels, int k, int w, int h) { if(m) paths = get_random_paths(paths, n, m); data d = {0}; d.shallow = 0; d.X = load_image_paths(paths, n, w, h); d.y = load_labels_paths(paths, n, labels, k, 0); if(m) free(paths); return d; } /* data load_data_study(char **paths, int n, int m, char **labels, int k, int min, int max, int size, float angle, float aspect, float hue, float saturation, float exposure) { data d = {0}; d.indexes = calloc(n, sizeof(int)); if(m) paths = get_random_paths_indexes(paths, n, m, d.indexes); d.shallow = 0; d.X = load_image_augment_paths(paths, n, min, max, size, angle, aspect, hue, saturation, exposure); d.y = load_labels_paths(paths, n, labels, k); if(m) free(paths); return d; } */ data load_data_super(char **paths, int n, int m, int w, int h, int scale) { if(m) paths = get_random_paths(paths, n, m); data d = {0}; d.shallow = 0; int i; d.X.rows = n; d.X.vals = calloc(n, sizeof(float*)); d.X.cols = w*h*3; d.y.rows = n; d.y.vals = calloc(n, sizeof(float*)); d.y.cols = w*scale * h*scale * 3; for(i = 0; i < n; ++i){ image im = load_image_color(paths[i], 0, 0); image crop = random_crop_image(im, w*scale, h*scale); int flip = rand()%2; if (flip) flip_image(crop); image resize = resize_image(crop, w, h); d.X.vals[i] = resize.data; d.y.vals[i] = crop.data; free_image(im); } if(m) free(paths); return d; } data load_data_regression(char **paths, int n, int m, int k, int min, int max, int size, float angle, float aspect, float hue, float saturation, float exposure) { if(m) paths = get_random_paths(paths, n, m); data d = {0}; d.shallow = 0; d.X = load_image_augment_paths(paths, n, min, max, size, angle, aspect, hue, saturation, exposure, 0); d.y = load_regression_labels_paths(paths, n, k); if(m) free(paths); return d; } data select_data(data *orig, int *inds) { data d = {0}; d.shallow = 1; d.w = orig[0].w; d.h = orig[0].h; d.X.rows = orig[0].X.rows; d.y.rows = orig[0].X.rows; d.X.cols = orig[0].X.cols; d.y.cols = orig[0].y.cols; d.X.vals = calloc(orig[0].X.rows, sizeof(float *)); d.y.vals = calloc(orig[0].y.rows, sizeof(float *)); int i; for(i = 0; i < d.X.rows; ++i){ d.X.vals[i] = orig[inds[i]].X.vals[i]; d.y.vals[i] = orig[inds[i]].y.vals[i]; } return d; } data *tile_data(data orig, int divs, int size) { data *ds = calloc(divs*divs, sizeof(data)); int i, j; #pragma omp parallel for for(i = 0; i < divs*divs; ++i){ data d; d.shallow = 0; d.w = orig.w/divs * size; d.h = orig.h/divs * size; d.X.rows = orig.X.rows; d.X.cols = d.w*d.h*3; d.X.vals = calloc(d.X.rows, sizeof(float*)); d.y = copy_matrix(orig.y); #pragma omp parallel for for(j = 0; j < orig.X.rows; ++j){ int x = (i%divs) * orig.w / divs - (d.w - orig.w/divs)/2; int y = (i/divs) * orig.h / divs - (d.h - orig.h/divs)/2; image im = float_to_image(orig.w, orig.h, 3, orig.X.vals[j]); d.X.vals[j] = crop_image(im, x, y, d.w, d.h).data; } ds[i] = d; } return ds; } data resize_data(data orig, int w, int h) { data d = {0}; d.shallow = 0; d.w = w; d.h = h; int i; d.X.rows = orig.X.rows; d.X.cols = w*h*3; d.X.vals = calloc(d.X.rows, sizeof(float*)); d.y = copy_matrix(orig.y); #pragma omp parallel for for(i = 0; i < orig.X.rows; ++i){ image im = float_to_image(orig.w, orig.h, 3, orig.X.vals[i]); d.X.vals[i] = resize_image(im, w, h).data; } return d; } data load_data_augment(char **paths, int n, int m, char **labels, int k, tree *hierarchy, int min, int max, int size, float angle, float aspect, float hue, float saturation, float exposure, int center) { if(m) paths = get_random_paths(paths, n, m); data d = {0}; d.shallow = 0; d.w=size; d.h=size; d.X = load_image_augment_paths(paths, n, min, max, size, angle, aspect, hue, saturation, exposure, center); d.y = load_labels_paths(paths, n, labels, k, hierarchy); if(m) free(paths); return d; } data load_data_tag(char **paths, int n, int m, int k, int min, int max, int size, float angle, float aspect, float hue, float saturation, float exposure) { if(m) paths = get_random_paths(paths, n, m); data d = {0}; d.w = size; d.h = size; d.shallow = 0; d.X = load_image_augment_paths(paths, n, min, max, size, angle, aspect, hue, saturation, exposure, 0); d.y = load_tags_paths(paths, n, k); if(m) free(paths); return d; } matrix concat_matrix(matrix m1, matrix m2) { int i, count = 0; matrix m; m.cols = m1.cols; m.rows = m1.rows+m2.rows; m.vals = calloc(m1.rows + m2.rows, sizeof(float*)); for(i = 0; i < m1.rows; ++i){ m.vals[count++] = m1.vals[i]; } for(i = 0; i < m2.rows; ++i){ m.vals[count++] = m2.vals[i]; } return m; } data concat_data(data d1, data d2) { data d = {0}; d.shallow = 1; d.X = concat_matrix(d1.X, d2.X); d.y = concat_matrix(d1.y, d2.y); d.w = d1.w; d.h = d1.h; return d; } data concat_datas(data *d, int n) { int i; data out = {0}; for(i = 0; i < n; ++i){ data new = concat_data(d[i], out); free_data(out); out = new; } return out; } data load_categorical_data_csv(char *filename, int target, int k) { data d = {0}; d.shallow = 0; matrix X = csv_to_matrix(filename); float *truth_1d = pop_column(&X, target); float **truth = one_hot_encode(truth_1d, X.rows, k); matrix y; y.rows = X.rows; y.cols = k; y.vals = truth; d.X = X; d.y = y; free(truth_1d); return d; } data load_cifar10_data(char *filename) { data d = {0}; d.shallow = 0; long i,j; matrix X = make_matrix(10000, 3072); matrix y = make_matrix(10000, 10); d.X = X; d.y = y; FILE *fp = fopen(filename, "rb"); if(!fp) file_error(filename); for(i = 0; i < 10000; ++i){ unsigned char bytes[3073]; fread(bytes, 1, 3073, fp); int class = bytes[0]; y.vals[i][class] = 1; for(j = 0; j < X.cols; ++j){ X.vals[i][j] = (double)bytes[j+1]; } } scale_data_rows(d, 1./255); //normalize_data_rows(d); fclose(fp); return d; } void get_random_batch(data d, int n, float *X, float *y) { int j; for(j = 0; j < n; ++j){ int index = rand()%d.X.rows; memcpy(X+j*d.X.cols, d.X.vals[index], d.X.cols*sizeof(float)); memcpy(y+j*d.y.cols, d.y.vals[index], d.y.cols*sizeof(float)); } } void get_next_batch(data d, int n, int offset, float *X, float *y) { int j; for(j = 0; j < n; ++j){ int index = offset + j; memcpy(X+j*d.X.cols, d.X.vals[index], d.X.cols*sizeof(float)); if(y) memcpy(y+j*d.y.cols, d.y.vals[index], d.y.cols*sizeof(float)); } } void smooth_data(data d) { int i, j; float scale = 1. / d.y.cols; float eps = .1; for(i = 0; i < d.y.rows; ++i){ for(j = 0; j < d.y.cols; ++j){ d.y.vals[i][j] = eps * scale + (1-eps) * d.y.vals[i][j]; } } } data load_all_cifar10() { data d = {0}; d.shallow = 0; int i,j,b; matrix X = make_matrix(50000, 3072); matrix y = make_matrix(50000, 10); d.X = X; d.y = y; for(b = 0; b < 5; ++b){ char buff[256]; sprintf(buff, "data/cifar/cifar-10-batches-bin/data_batch_%d.bin", b+1); FILE *fp = fopen(buff, "rb"); if(!fp) file_error(buff); for(i = 0; i < 10000; ++i){ unsigned char bytes[3073]; fread(bytes, 1, 3073, fp); int class = bytes[0]; y.vals[i+b*10000][class] = 1; for(j = 0; j < X.cols; ++j){ X.vals[i+b*10000][j] = (double)bytes[j+1]; } } fclose(fp); } //normalize_data_rows(d); scale_data_rows(d, 1./255); smooth_data(d); return d; } data load_go(char *filename) { FILE *fp = fopen(filename, "rb"); matrix X = make_matrix(3363059, 361); matrix y = make_matrix(3363059, 361); int row, col; if(!fp) file_error(filename); char *label; int count = 0; while((label = fgetl(fp))){ int i; if(count == X.rows){ X = resize_matrix(X, count*2); y = resize_matrix(y, count*2); } sscanf(label, "%d %d", &row, &col); char *board = fgetl(fp); int index = row*19 + col; y.vals[count][index] = 1; for(i = 0; i < 19*19; ++i){ float val = 0; if(board[i] == '1') val = 1; else if(board[i] == '2') val = -1; X.vals[count][i] = val; } ++count; free(label); free(board); } X = resize_matrix(X, count); y = resize_matrix(y, count); data d = {0}; d.shallow = 0; d.X = X; d.y = y; fclose(fp); return d; } void randomize_data(data d) { int i; for(i = d.X.rows-1; i > 0; --i){ int index = rand()%i; float *swap = d.X.vals[index]; d.X.vals[index] = d.X.vals[i]; d.X.vals[i] = swap; swap = d.y.vals[index]; d.y.vals[index] = d.y.vals[i]; d.y.vals[i] = swap; } } void scale_data_rows(data d, float s) { int i; for(i = 0; i < d.X.rows; ++i){ scale_array(d.X.vals[i], d.X.cols, s); } } void translate_data_rows(data d, float s) { int i; for(i = 0; i < d.X.rows; ++i){ translate_array(d.X.vals[i], d.X.cols, s); } } data copy_data(data d) { data c = {0}; c.w = d.w; c.h = d.h; c.shallow = 0; c.num_boxes = d.num_boxes; c.boxes = d.boxes; c.X = copy_matrix(d.X); c.y = copy_matrix(d.y); return c; } void normalize_data_rows(data d) { int i; for(i = 0; i < d.X.rows; ++i){ normalize_array(d.X.vals[i], d.X.cols); } } data get_data_part(data d, int part, int total) { data p = {0}; p.shallow = 1; p.X.rows = d.X.rows * (part + 1) / total - d.X.rows * part / total; p.y.rows = d.y.rows * (part + 1) / total - d.y.rows * part / total; p.X.cols = d.X.cols; p.y.cols = d.y.cols; p.X.vals = d.X.vals + d.X.rows * part / total; p.y.vals = d.y.vals + d.y.rows * part / total; return p; } data get_random_data(data d, int num) { data r = {0}; r.shallow = 1; r.X.rows = num; r.y.rows = num; r.X.cols = d.X.cols; r.y.cols = d.y.cols; r.X.vals = calloc(num, sizeof(float *)); r.y.vals = calloc(num, sizeof(float *)); int i; for(i = 0; i < num; ++i){ int index = rand()%d.X.rows; r.X.vals[i] = d.X.vals[index]; r.y.vals[i] = d.y.vals[index]; } return r; } data *split_data(data d, int part, int total) { data *split = calloc(2, sizeof(data)); int i; int start = part*d.X.rows/total; int end = (part+1)*d.X.rows/total; data train; data test; train.shallow = test.shallow = 1; test.X.rows = test.y.rows = end-start; train.X.rows = train.y.rows = d.X.rows - (end-start); train.X.cols = test.X.cols = d.X.cols; train.y.cols = test.y.cols = d.y.cols; train.X.vals = calloc(train.X.rows, sizeof(float*)); test.X.vals = calloc(test.X.rows, sizeof(float*)); train.y.vals = calloc(train.y.rows, sizeof(float*)); test.y.vals = calloc(test.y.rows, sizeof(float*)); for(i = 0; i < start; ++i){ train.X.vals[i] = d.X.vals[i]; train.y.vals[i] = d.y.vals[i]; } for(i = start; i < end; ++i){ test.X.vals[i-start] = d.X.vals[i]; test.y.vals[i-start] = d.y.vals[i]; } for(i = end; i < d.X.rows; ++i){ train.X.vals[i-(end-start)] = d.X.vals[i]; train.y.vals[i-(end-start)] = d.y.vals[i]; } split[0] = train; split[1] = test; return split; }
dnnl_common.h
/* * Licensed to the Apache Software Foundation (ASF) under one * or more contributor license agreements. See the NOTICE file * distributed with this work for additional information * regarding copyright ownership. The ASF licenses this file * to you under the Apache License, Version 2.0 (the * "License"); you may not use this file except in compliance * with the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, * software distributed under the License is distributed on an * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY * KIND, either express or implied. See the License for the * specific language governing permissions and limitations * under the License. */ /*! * \file dnnl_common.h * \brief Common header file for DNNL backend subgraph * \author Ciyong Chen */ #ifndef MXNET_OPERATOR_SUBGRAPH_DNNL_DNNL_COMMON_H_ #define MXNET_OPERATOR_SUBGRAPH_DNNL_DNNL_COMMON_H_ #if MXNET_USE_ONEDNN == 1 #include <vector> #include "operator/numpy/np_matrix_op-inl.h" namespace mxnet { namespace op { template <typename DType> static std::vector<float> GetWeightScales(const NDArray& weight, const NDArray* bias, const float data_scale, bool weight_channelwise_scale) { auto nthreads = engine::OpenMP::Get()->GetRecommendedOMPThreadCount(); std::vector<float> weight_scales; const DType* weight_ptr = weight.data().dptr<DType>(); const DType* bias_ptr = bias ? bias->data().dptr<DType>() : nullptr; const auto wshape = weight.shape(); size_t channel = wshape[0]; size_t offset = wshape.ProdShape(1, wshape.ndim()); std::vector<DType> weight_c_min(channel, MaxValue<DType>()); std::vector<DType> weight_c_max(channel, MinValue<DType>()); for (int c = 0; c < static_cast<int>(channel); ++c) { const DType* p1 = weight_ptr + c * offset; for (size_t k = 0; k < offset; ++k) { if (weight_c_min[c] > p1[k]) weight_c_min[c] = p1[k]; if (weight_c_max[c] < p1[k]) weight_c_max[c] = p1[k]; } } if (weight_channelwise_scale) { weight_scales.resize(channel); #pragma omp parallel for num_threads(nthreads) for (int c = 0; c < static_cast<int>(channel); ++c) { float scale = GetQuantizeScale(mshadow::kInt8, weight_c_min[c], weight_c_max[c]); if (bias_ptr && bias_ptr[c]) { // avoid overflow on bias // TODO(zhennan): dnnl has bug to handle INT_MAX in bias, so set the maximum value of bias // to INT_MAX / 2. float scale_max = static_cast<float>(bias_ptr[c] > 0 ? MaxValue<int32_t>() : MinValue<int32_t>()) / 2 / bias_ptr[c] / data_scale; scale = Min(scale, scale_max); } weight_scales[c] = scale; } } else { DType total_min = weight_c_min[0]; DType total_max = weight_c_max[0]; for (size_t c = 0; c < channel; ++c) { if (total_min > weight_c_min[c]) total_min = weight_c_min[c]; if (total_max < weight_c_max[c]) total_max = weight_c_max[c]; } weight_scales.resize(3); weight_scales[0] = GetQuantizeScale(mshadow::kInt8, total_min, total_max); weight_scales[1] = total_min; weight_scales[2] = total_max; } return weight_scales; } static inline void ConvertWeightBias2DNNL(NDArray* weight, NDArray* bias, bool has_bias, const dnnl::memory::desc& weight_md, const dnnl::memory::desc* bias_md, const int num_group, float data_scale, const std::vector<float>& weight_scales, const bool submit = true) { DNNLStream* stream = DNNLStream::Get(); const auto new_weight = NDArray(&weight_md); const auto conv_weights_memory = new_weight.GetDNNLData(); dnnl::primitive_attr weight_attr; if (weight_scales.size()) { const int weight_mask = (weight_scales.size()) == 1 ? 0 : 1; weight_attr.set_output_scales(weight_mask, weight_scales); } auto default_weights_memory = GetWeights(*weight, num_group); if (default_weights_memory == nullptr) default_weights_memory = weight->GetDNNLData(); const auto weight_reorder_pd = dnnl::reorder::primitive_desc(*default_weights_memory, *conv_weights_memory, weight_attr); DNNLStream::Get()->RegisterPrimArgs( dnnl::reorder(weight_reorder_pd), {{DNNL_ARG_FROM, *default_weights_memory}, {DNNL_ARG_TO, *conv_weights_memory}}); NDArray new_bias; if (has_bias && data_scale) { std::vector<float> bias_scales(weight_scales.size()); for (size_t c = 0; c < weight_scales.size(); ++c) { bias_scales[c] = weight_scales[c] * data_scale; } new_bias = NDArray(bias_md); const auto conv_bias_memory = new_bias.GetDNNLData(); const int bias_mask = (bias_scales.size()) == 1 ? 0 : 1; dnnl::primitive_attr bias_attr; bias_attr.set_output_scales(bias_mask, bias_scales); auto bias_weights_memory = bias->GetDNNLData(); const auto bias_reorder_pd = dnnl::reorder::primitive_desc(*bias_weights_memory, *conv_bias_memory, bias_attr); DNNLStream::Get()->RegisterPrimArgs( dnnl::reorder(bias_reorder_pd), {{DNNL_ARG_FROM, *bias_weights_memory}, {DNNL_ARG_TO, *conv_bias_memory}}); } if (submit) stream->Submit(); *weight = new_weight; if (has_bias && data_scale) *bias = new_bias; } static inline bool CheckReshapeConditions(const nnvm::Node& node, const index_t out_index) { const index_t split_output_index = node.inputs[0].index; if (split_output_index != out_index) return false; const auto& reshape_param = nnvm::get<NumpyXReshapeParam>(node.attrs.parsed); const auto newshape = reshape_param.newshape; if (newshape.ndim() != 4 || !(newshape[0] == newshape[1] && newshape[0] == -2)) return false; return true; } static inline bool CheckSwapAxisConditions(const nnvm::Node& node) { auto params = node.attrs.dict; int dim1 = 0, dim2 = 0; if (params.count("dim1") && params.count("dim2")) { dim1 = std::stoi(params.at("dim1")); dim2 = std::stoi(params.at("dim2")); } else { return false; } return ((dim1 == 1 && dim2 == 2) || (dim1 == 2 && dim2 == 1)); } } // namespace op } // namespace mxnet #endif // if MXNET_USE_ONEDNN == 1 #endif // MXNET_OPERATOR_SUBGRAPH_DNNL_DNNL_COMMON_H_
GB_unop__identity_uint8_int32.c
//------------------------------------------------------------------------------ // GB_unop: hard-coded functions for each built-in unary operator //------------------------------------------------------------------------------ // SuiteSparse:GraphBLAS, Timothy A. Davis, (c) 2017-2020, All Rights Reserved. // http://suitesparse.com See GraphBLAS/Doc/License.txt for license. //------------------------------------------------------------------------------ // If this file is in the Generated/ folder, do not edit it (auto-generated). #include "GB.h" #ifndef GBCOMPACT #include "GB_control.h" #include "GB_unop__include.h" // C=unop(A) is defined by the following types and operators: // op(A) function: GB_unop_apply__identity_uint8_int32 // op(A') function: GB_unop_tran__identity_uint8_int32 // C type: uint8_t // A type: int32_t // cast: uint8_t cij = (uint8_t) aij // unaryop: cij = aij #define GB_ATYPE \ int32_t #define GB_CTYPE \ uint8_t // aij = Ax [pA] #define GB_GETA(aij,Ax,pA) \ int32_t aij = Ax [pA] #define GB_CX(p) Cx [p] // unary operator #define GB_OP(z, x) \ z = x ; // casting #define GB_CAST(z, aij) \ uint8_t z = (uint8_t) aij ; // cij = op (aij) #define GB_CAST_OP(pC,pA) \ { \ /* aij = Ax [pA] */ \ int32_t aij = Ax [pA] ; \ /* Cx [pC] = op (cast (aij)) */ \ uint8_t z = (uint8_t) aij ; \ Cx [pC] = z ; \ } // disable this operator and use the generic case if these conditions hold #define GB_DISABLE \ (GxB_NO_IDENTITY || GxB_NO_UINT8 || GxB_NO_INT32) //------------------------------------------------------------------------------ // Cx = op (cast (Ax)): apply a unary operator //------------------------------------------------------------------------------ GrB_Info GB_unop_apply__identity_uint8_int32 ( uint8_t *Cx, // Cx and Ax may be aliased const int32_t *Ax, int64_t anz, int nthreads ) { #if GB_DISABLE return (GrB_NO_VALUE) ; #else int64_t p ; #pragma omp parallel for num_threads(nthreads) schedule(static) for (p = 0 ; p < anz ; p++) { int32_t aij = Ax [p] ; uint8_t z = (uint8_t) aij ; Cx [p] = z ; } return (GrB_SUCCESS) ; #endif } //------------------------------------------------------------------------------ // C = op (cast (A')): transpose, typecast, and apply a unary operator //------------------------------------------------------------------------------ GrB_Info GB_unop_tran__identity_uint8_int32 ( GrB_Matrix C, const GrB_Matrix A, int64_t *GB_RESTRICT *Rowcounts, GBI_single_iterator Iter, const int64_t *GB_RESTRICT A_slice, int naslice ) { #if GB_DISABLE return (GrB_NO_VALUE) ; #else #define GB_PHASE_2_OF_2 #include "GB_unop_transpose.c" return (GrB_SUCCESS) ; #endif } #endif
par_multi_interp.c
/****************************************************************************** * Copyright 1998-2019 Lawrence Livermore National Security, LLC and other * HYPRE Project Developers. See the top-level COPYRIGHT file for details. * * SPDX-License-Identifier: (Apache-2.0 OR MIT) ******************************************************************************/ #include "_hypre_parcsr_ls.h" /*-------------------------------------------------------------------------- * hypre_ParAMGBuildMultipass * This routine implements Stuben's direct interpolation with multiple passes. *--------------------------------------------------------------------------*/ HYPRE_Int hypre_BoomerAMGBuildMultipass( hypre_ParCSRMatrix *A, HYPRE_Int *CF_marker, hypre_ParCSRMatrix *S, HYPRE_BigInt *num_cpts_global, HYPRE_Int num_functions, HYPRE_Int *dof_func, HYPRE_Int debug_flag, HYPRE_Real trunc_factor, HYPRE_Int P_max_elmts, HYPRE_Int weight_option, HYPRE_Int *col_offd_S_to_A, hypre_ParCSRMatrix **P_ptr ) { #ifdef HYPRE_PROFILE hypre_profile_times[HYPRE_TIMER_ID_MULTIPASS_INTERP] -= hypre_MPI_Wtime(); #endif MPI_Comm comm = hypre_ParCSRMatrixComm(A); hypre_ParCSRCommPkg *comm_pkg = hypre_ParCSRMatrixCommPkg(S); hypre_ParCSRCommHandle *comm_handle; hypre_ParCSRCommPkg *tmp_comm_pkg; hypre_CSRMatrix *A_diag = hypre_ParCSRMatrixDiag(A); HYPRE_Real *A_diag_data = hypre_CSRMatrixData(A_diag); HYPRE_Int *A_diag_i = hypre_CSRMatrixI(A_diag); HYPRE_Int *A_diag_j = hypre_CSRMatrixJ(A_diag); hypre_CSRMatrix *A_offd = hypre_ParCSRMatrixOffd(A); HYPRE_Real *A_offd_data = NULL; HYPRE_Int *A_offd_i = hypre_CSRMatrixI(A_offd); HYPRE_Int *A_offd_j = NULL; HYPRE_BigInt *col_map_offd_A = hypre_ParCSRMatrixColMapOffd(A); HYPRE_Int num_cols_offd_A = hypre_CSRMatrixNumCols(A_offd); hypre_CSRMatrix *S_diag = hypre_ParCSRMatrixDiag(S); HYPRE_Int *S_diag_i = hypre_CSRMatrixI(S_diag); HYPRE_Int *S_diag_j = hypre_CSRMatrixJ(S_diag); hypre_CSRMatrix *S_offd = hypre_ParCSRMatrixOffd(S); HYPRE_Int *S_offd_i = hypre_CSRMatrixI(S_offd); HYPRE_Int *S_offd_j = NULL; HYPRE_BigInt *col_map_offd_S = hypre_ParCSRMatrixColMapOffd(S); HYPRE_Int num_cols_offd_S = hypre_CSRMatrixNumCols(S_offd); HYPRE_BigInt *col_map_offd = NULL; HYPRE_Int num_cols_offd; hypre_ParCSRMatrix *P; hypre_CSRMatrix *P_diag; HYPRE_Real *P_diag_data; HYPRE_Int *P_diag_i; /*at first counter of nonzero cols for each row, finally will be pointer to start of row */ HYPRE_Int *P_diag_j; hypre_CSRMatrix *P_offd; HYPRE_Real *P_offd_data = NULL; HYPRE_Int *P_offd_i; /*at first counter of nonzero cols for each row, finally will be pointer to start of row */ HYPRE_Int *P_offd_j = NULL; HYPRE_Int num_sends = 0; HYPRE_Int *int_buf_data = NULL; HYPRE_BigInt *big_buf_data = NULL; HYPRE_Int *send_map_start; HYPRE_Int *send_map_elmt; HYPRE_Int *send_procs; HYPRE_Int num_recvs = 0; HYPRE_Int *recv_vec_start; HYPRE_Int *recv_procs; HYPRE_Int *new_recv_vec_start = NULL; HYPRE_Int **Pext_send_map_start = NULL; HYPRE_Int **Pext_recv_vec_start = NULL; HYPRE_Int *Pext_start = NULL; HYPRE_Int *P_ncols = NULL; HYPRE_Int *CF_marker_offd = NULL; HYPRE_Int *dof_func_offd = NULL; HYPRE_Int *P_marker; HYPRE_Int *P_marker_offd = NULL; HYPRE_Int *C_array; HYPRE_Int *C_array_offd = NULL; HYPRE_Int *pass_array = NULL; /* contains points ordered according to pass */ HYPRE_Int *pass_pointer = NULL; /* pass_pointer[j] contains pointer to first point of pass j contained in pass_array */ HYPRE_Int *P_diag_start; HYPRE_Int *P_offd_start = NULL; HYPRE_Int **P_diag_pass; HYPRE_Int **P_offd_pass = NULL; HYPRE_Int **Pext_pass = NULL; HYPRE_BigInt *big_temp_pass = NULL; HYPRE_BigInt **new_elmts = NULL; /* new neighbors generated in each pass */ HYPRE_Int *new_counter = NULL; /* contains no. of new neighbors for each pass */ HYPRE_Int *loc = NULL; /* contains locations for new neighbor connections in int_o_buffer to avoid searching */ HYPRE_Int *Pext_i = NULL; /*contains P_diag_i and P_offd_i info for nonzero cols of off proc neighbors */ HYPRE_BigInt *Pext_send_buffer = NULL; /* used to collect global nonzero col ids in P_diag for send_map_elmts */ HYPRE_Int *map_S_to_new = NULL; /*HYPRE_Int *map_A_to_new = NULL;*/ HYPRE_Int *map_A_to_S = NULL; HYPRE_BigInt *new_col_map_offd = NULL; HYPRE_BigInt *col_map_offd_P = NULL; HYPRE_Int *permute = NULL; HYPRE_BigInt *big_permute = NULL; HYPRE_Int cnt; HYPRE_Int cnt_nz; HYPRE_Int total_nz; HYPRE_Int pass; HYPRE_Int num_passes; HYPRE_Int max_num_passes = 10; HYPRE_Int n_fine; HYPRE_Int n_coarse = 0; HYPRE_Int n_coarse_offd = 0; HYPRE_Int n_SF = 0; HYPRE_Int n_SF_offd = 0; HYPRE_Int *fine_to_coarse = NULL; HYPRE_BigInt *fine_to_coarse_offd = NULL; HYPRE_Int *assigned = NULL; HYPRE_Int *assigned_offd = NULL; HYPRE_Real *Pext_send_data = NULL; HYPRE_Real *Pext_data = NULL; HYPRE_Real sum_C, sum_N; HYPRE_Real sum_C_pos, sum_C_neg; HYPRE_Real sum_N_pos, sum_N_neg; HYPRE_Real diagonal; HYPRE_Real alfa = 1.0; HYPRE_Real beta = 1.0; HYPRE_Int j_start; HYPRE_Int j_end; HYPRE_Int i,i1; HYPRE_Int j,j1; HYPRE_Int k,k1,k2,k3; HYPRE_BigInt big_k1; HYPRE_Int pass_array_size; HYPRE_BigInt global_pass_array_size; HYPRE_BigInt local_pass_array_size; HYPRE_Int my_id, num_procs; HYPRE_Int index, start; HYPRE_BigInt my_first_cpt; HYPRE_BigInt total_global_cpts; HYPRE_Int p_cnt; HYPRE_Int total_nz_offd; HYPRE_Int cnt_nz_offd; HYPRE_Int cnt_offd, cnt_new; HYPRE_Int no_break; HYPRE_Int not_found; HYPRE_Int Pext_send_size; HYPRE_Int Pext_recv_size; HYPRE_Int old_Pext_send_size; HYPRE_Int old_Pext_recv_size; HYPRE_Int P_offd_size = 0; HYPRE_Int local_index = -1; HYPRE_Int new_num_cols_offd = 0; HYPRE_Int num_cols_offd_P; /* Threading variables */ HYPRE_Int my_thread_num, num_threads, thread_start, thread_stop; HYPRE_Int pass_length; HYPRE_Int *tmp_marker, *tmp_marker_offd; HYPRE_Int *tmp_array, *tmp_array_offd; HYPRE_Int * max_num_threads = hypre_CTAlloc(HYPRE_Int, 1, HYPRE_MEMORY_HOST); HYPRE_Int * cnt_nz_per_thread; HYPRE_Int * cnt_nz_offd_per_thread; /* HYPRE_Real wall_time; wall_time = hypre_MPI_Wtime(); */ /* Initialize threading variables */ max_num_threads[0] = hypre_NumThreads(); cnt_nz_per_thread = hypre_CTAlloc(HYPRE_Int, max_num_threads[0], HYPRE_MEMORY_HOST); cnt_nz_offd_per_thread = hypre_CTAlloc(HYPRE_Int, max_num_threads[0], HYPRE_MEMORY_HOST); for(i=0; i < max_num_threads[0]; i++) { cnt_nz_offd_per_thread[i] = 0; cnt_nz_per_thread[i] = 0; } /*----------------------------------------------------------------------- * Access the CSR vectors for A and S. Also get size of fine grid. *-----------------------------------------------------------------------*/ hypre_MPI_Comm_size(comm,&num_procs); hypre_MPI_Comm_rank(comm,&my_id); #ifdef HYPRE_NO_GLOBAL_PARTITION my_first_cpt = num_cpts_global[0]; /* total_global_cpts = 0; */ if (my_id == (num_procs -1)) total_global_cpts = num_cpts_global[1]; hypre_MPI_Bcast(&total_global_cpts, 1, HYPRE_MPI_BIG_INT, num_procs-1, comm); #else my_first_cpt = num_cpts_global[my_id]; total_global_cpts = num_cpts_global[num_procs]; #endif if (!comm_pkg) { comm_pkg = hypre_ParCSRMatrixCommPkg(A); if (!comm_pkg) { hypre_MatvecCommPkgCreate(A); comm_pkg = hypre_ParCSRMatrixCommPkg(A); } col_offd_S_to_A = NULL; } if (col_offd_S_to_A) { col_map_offd = col_map_offd_S; num_cols_offd = num_cols_offd_S; } else { col_map_offd = col_map_offd_A; num_cols_offd = num_cols_offd_A; } if (num_cols_offd_A) { A_offd_data = hypre_CSRMatrixData(A_offd); A_offd_j = hypre_CSRMatrixJ(A_offd); } if (num_cols_offd) S_offd_j = hypre_CSRMatrixJ(S_offd); n_fine = hypre_CSRMatrixNumRows(A_diag); /*----------------------------------------------------------------------- * Intialize counters and allocate mapping vector. *-----------------------------------------------------------------------*/ if (n_fine) fine_to_coarse = hypre_CTAlloc(HYPRE_Int, n_fine, HYPRE_MEMORY_HOST); n_coarse = 0; n_SF = 0; #ifdef HYPRE_USING_OPENMP #pragma omp parallel for private(i) reduction(+:n_coarse,n_SF ) HYPRE_SMP_SCHEDULE #endif for (i=0; i < n_fine; i++) if (CF_marker[i] == 1) n_coarse++; else if (CF_marker[i] == -3) n_SF++; pass_array_size = n_fine-n_coarse-n_SF; if (pass_array_size) pass_array = hypre_CTAlloc(HYPRE_Int, pass_array_size, HYPRE_MEMORY_HOST); pass_pointer = hypre_CTAlloc(HYPRE_Int, max_num_passes+1, HYPRE_MEMORY_HOST); if (n_fine) assigned = hypre_CTAlloc(HYPRE_Int, n_fine, HYPRE_MEMORY_HOST); P_diag_i = hypre_CTAlloc(HYPRE_Int, n_fine+1, HYPRE_MEMORY_DEVICE); P_offd_i = hypre_CTAlloc(HYPRE_Int, n_fine+1, HYPRE_MEMORY_DEVICE); if (n_coarse) C_array = hypre_CTAlloc(HYPRE_Int, n_coarse, HYPRE_MEMORY_HOST); if (num_cols_offd) { CF_marker_offd = hypre_CTAlloc(HYPRE_Int, num_cols_offd, HYPRE_MEMORY_HOST); if (num_functions > 1) dof_func_offd = hypre_CTAlloc(HYPRE_Int, num_cols_offd, HYPRE_MEMORY_HOST); } if (num_procs > 1) { num_sends = hypre_ParCSRCommPkgNumSends(comm_pkg); send_procs = hypre_ParCSRCommPkgSendProcs(comm_pkg); send_map_start = hypre_ParCSRCommPkgSendMapStarts(comm_pkg); send_map_elmt = hypre_ParCSRCommPkgSendMapElmts(comm_pkg); num_recvs = hypre_ParCSRCommPkgNumRecvs(comm_pkg); recv_procs = hypre_ParCSRCommPkgRecvProcs(comm_pkg); recv_vec_start = hypre_ParCSRCommPkgRecvVecStarts(comm_pkg); if (send_map_start[num_sends]) { int_buf_data = hypre_CTAlloc(HYPRE_Int, send_map_start[num_sends], HYPRE_MEMORY_HOST); big_buf_data = hypre_CTAlloc(HYPRE_BigInt, send_map_start[num_sends], HYPRE_MEMORY_HOST); } } index = 0; for (i=0; i < num_sends; i++) { start = send_map_start[i]; for (j = start; j < send_map_start[i+1]; j++) int_buf_data[index++] = CF_marker[send_map_elmt[j]]; } if (num_procs > 1) { comm_handle = hypre_ParCSRCommHandleCreate(11, comm_pkg, int_buf_data, CF_marker_offd); hypre_ParCSRCommHandleDestroy(comm_handle); } if (num_functions > 1) { index = 0; for (i=0; i < num_sends; i++) { start = send_map_start[i]; for (j = start; j < send_map_start[i+1]; j++) int_buf_data[index++] = dof_func[send_map_elmt[j]]; } if (num_procs > 1) { comm_handle = hypre_ParCSRCommHandleCreate(11, comm_pkg, int_buf_data, dof_func_offd); hypre_ParCSRCommHandleDestroy(comm_handle); } } n_coarse_offd = 0; n_SF_offd = 0; #ifdef HYPRE_USING_OPENMP #pragma omp parallel for private(i) reduction(+:n_coarse_offd,n_SF_offd) HYPRE_SMP_SCHEDULE #endif for (i=0; i < num_cols_offd; i++) if (CF_marker_offd[i] == 1) n_coarse_offd++; else if (CF_marker_offd[i] == -3) n_SF_offd++; if (num_cols_offd) { assigned_offd = hypre_CTAlloc(HYPRE_Int, num_cols_offd, HYPRE_MEMORY_HOST); map_S_to_new = hypre_CTAlloc(HYPRE_Int, num_cols_offd, HYPRE_MEMORY_HOST); fine_to_coarse_offd = hypre_CTAlloc(HYPRE_BigInt, num_cols_offd, HYPRE_MEMORY_HOST); new_col_map_offd = hypre_CTAlloc(HYPRE_BigInt, n_coarse_offd, HYPRE_MEMORY_HOST); } /*----------------------------------------------------------------------- * First Pass: determine the maximal size of P, and elementsPerRow[i]. *-----------------------------------------------------------------------*/ /*----------------------------------------------------------------------- * Assigned points are points for which we know an interpolation * formula already, and which are thus available to interpolate from. * assigned[i]=0 for C points, and 1, 2, 3, ... for F points, depending * in which pass their interpolation formula is determined. * * pass_array contains the points ordered according to its pass, i.e. * | C-points | points of pass 1 | points of pass 2 | .... * C_points are points 0 through pass_pointer[1]-1, * points of pass k (0 < k < num_passes) are contained in points * pass_pointer[k] through pass_pointer[k+1]-1 of pass_array . * * pass_array is also used to avoid going through all points for each pass, * i,e. at the bginning it contains all points in descending order starting * with n_fine-1. Then starting from the last point, we evaluate whether * it is a C_point (pass 0). If it is the point is brought to the front * and the length of the points to be searched is shortened. This is * done until the parameter cnt (which determines the first point of * pass_array to be searched) becomes n_fine. Then all points have been * assigned a pass number. *-----------------------------------------------------------------------*/ cnt = 0; p_cnt = pass_array_size-1; P_diag_i[0] = 0; P_offd_i[0] = 0; for (i = 0; i < n_fine; i++) { if (CF_marker[i] == 1) { fine_to_coarse[i] = cnt; /* this C point is assigned index coarse_counter on coarse grid, and in column of P */ C_array[cnt++] = i; assigned[i] = 0; P_diag_i[i+1] = 1; /* one element in row i1 of P */ P_offd_i[i+1] = 0; } else if (CF_marker[i] == -1) { pass_array[p_cnt--] = i; P_diag_i[i+1] = 0; P_offd_i[i+1] = 0; assigned[i] = -1; fine_to_coarse[i] = -1; } else { P_diag_i[i+1] = 0; P_offd_i[i+1] = 0; assigned[i] = -1; fine_to_coarse[i] = -1; } } index = 0; for (i=0; i < num_sends; i++) { start = send_map_start[i]; for (j = start; j < send_map_start[i+1]; j++) { big_buf_data[index] = (HYPRE_BigInt)fine_to_coarse[send_map_elmt[j]]; if (big_buf_data[index] > -1) big_buf_data[index] += my_first_cpt; index++; } } if (num_procs > 1) { comm_handle = hypre_ParCSRCommHandleCreate(21, comm_pkg, big_buf_data, fine_to_coarse_offd); hypre_ParCSRCommHandleDestroy(comm_handle); } new_recv_vec_start = hypre_CTAlloc(HYPRE_Int, num_recvs+1, HYPRE_MEMORY_HOST); if (n_coarse_offd) C_array_offd = hypre_CTAlloc(HYPRE_Int, n_coarse_offd, HYPRE_MEMORY_HOST); cnt = 0; new_recv_vec_start[0] = 0; for (j = 0; j < num_recvs; j++) { for (i = recv_vec_start[j]; i < recv_vec_start[j+1]; i++) { if (CF_marker_offd[i] == 1) { map_S_to_new[i] = cnt; C_array_offd[cnt] = i; new_col_map_offd[cnt++] = fine_to_coarse_offd[i]; assigned_offd[i] = 0; } else { assigned_offd[i] = -1; map_S_to_new[i] = -1; } } new_recv_vec_start[j+1] = cnt; } cnt = 0; hypre_TFree(fine_to_coarse_offd, HYPRE_MEMORY_HOST); if (col_offd_S_to_A) { map_A_to_S = hypre_CTAlloc(HYPRE_Int, num_cols_offd_A, HYPRE_MEMORY_HOST); for (i=0; i < num_cols_offd_A; i++) { if (cnt < num_cols_offd && col_map_offd_A[i] == col_map_offd[cnt]) map_A_to_S[i] = cnt++; else map_A_to_S[i] = -1; } } /*----------------------------------------------------------------------- * Mark all local neighbors of C points as 'assigned'. *-----------------------------------------------------------------------*/ pass_pointer[0] = 0; pass_pointer[1] = 0; total_nz = n_coarse; /* accumulates total number of nonzeros in P_diag */ total_nz_offd = 0; /* accumulates total number of nonzeros in P_offd */ cnt = 0; cnt_offd = 0; cnt_nz = 0; cnt_nz_offd = 0; for (i = pass_array_size-1; i > cnt-1; i--) { i1 = pass_array[i]; for (j=S_diag_i[i1]; j < S_diag_i[i1+1]; j++) { j1 = S_diag_j[j]; if (CF_marker[j1] == 1) { P_diag_i[i1+1]++; cnt_nz++; assigned[i1] = 1; } } for (j=S_offd_i[i1]; j < S_offd_i[i1+1]; j++) { j1 = S_offd_j[j]; if (CF_marker_offd[j1] == 1) { P_offd_i[i1+1]++; cnt_nz_offd++; assigned[i1] = 1; } } if (assigned[i1] == 1) { pass_array[i++] = pass_array[cnt]; pass_array[cnt++] = i1; } } pass_pointer[2] = cnt; /*----------------------------------------------------------------------- * All local neighbors are assigned, now need to exchange the boundary * info for assigned strong neighbors. *-----------------------------------------------------------------------*/ index = 0; for (i=0; i < num_sends; i++) { start = send_map_start[i]; for (j = start; j < send_map_start[i+1]; j++) { int_buf_data[index++] = assigned[send_map_elmt[j]]; } } if (num_procs > 1) { comm_handle = hypre_ParCSRCommHandleCreate(11, comm_pkg, int_buf_data, assigned_offd); hypre_ParCSRCommHandleDestroy(comm_handle); } /*----------------------------------------------------------------------- * Now we need to determine strong neighbors of points of pass 1, etc. * we need to update assigned_offd after each pass *-----------------------------------------------------------------------*/ pass = 2; local_pass_array_size = (HYPRE_BigInt)(pass_array_size - cnt); hypre_MPI_Allreduce(&local_pass_array_size, &global_pass_array_size, 1, HYPRE_MPI_BIG_INT, hypre_MPI_SUM, comm); while (global_pass_array_size && pass < max_num_passes) { for (i = pass_array_size-1; i > cnt-1; i--) { i1 = pass_array[i]; no_break = 1; for (j=S_diag_i[i1]; j < S_diag_i[i1+1]; j++) { j1 = S_diag_j[j]; if (assigned[j1] == pass-1) { pass_array[i++] = pass_array[cnt]; pass_array[cnt++] = i1; assigned[i1] = pass; no_break = 0; break; } } if (no_break) { for (j=S_offd_i[i1]; j < S_offd_i[i1+1]; j++) { j1 = S_offd_j[j]; if (assigned_offd[j1] == pass-1) { pass_array[i++] = pass_array[cnt]; pass_array[cnt++] = i1; assigned[i1] = pass; break; } } } } /*hypre_printf("pass %d remaining points %d \n", pass, local_pass_array_size);*/ pass++; pass_pointer[pass] = cnt; local_pass_array_size = (HYPRE_BigInt)(pass_array_size - cnt); hypre_MPI_Allreduce(&local_pass_array_size, &global_pass_array_size, 1, HYPRE_MPI_BIG_INT, hypre_MPI_SUM, comm); index = 0; for (i=0; i < num_sends; i++) { start = send_map_start[i]; for (j = start; j < send_map_start[i+1]; j++) { int_buf_data[index++] = assigned[send_map_elmt[j]]; } } if (num_procs > 1) { comm_handle = hypre_ParCSRCommHandleCreate(11, comm_pkg, int_buf_data, assigned_offd); hypre_ParCSRCommHandleDestroy(comm_handle); } } hypre_TFree(int_buf_data, HYPRE_MEMORY_HOST); hypre_TFree(big_buf_data, HYPRE_MEMORY_HOST); num_passes = pass; P_diag_pass = hypre_CTAlloc(HYPRE_Int*, num_passes, HYPRE_MEMORY_HOST); /* P_diag_pass[i] will contain all column numbers for points of pass i */ P_diag_pass[1] = hypre_CTAlloc(HYPRE_Int, cnt_nz, HYPRE_MEMORY_HOST); P_diag_start = hypre_CTAlloc(HYPRE_Int, n_fine, HYPRE_MEMORY_HOST); /* P_diag_start[i] contains pointer to begin of column numbers in P_pass for point i, P_diag_i[i+1] contains number of columns for point i */ P_offd_start = hypre_CTAlloc(HYPRE_Int, n_fine, HYPRE_MEMORY_HOST); if (num_procs > 1) { P_offd_pass = hypre_CTAlloc(HYPRE_Int*, num_passes, HYPRE_MEMORY_HOST); if (cnt_nz_offd) P_offd_pass[1] = hypre_CTAlloc(HYPRE_Int, cnt_nz_offd, HYPRE_MEMORY_HOST); else P_offd_pass[1] = NULL; new_elmts = hypre_CTAlloc(HYPRE_BigInt*, num_passes, HYPRE_MEMORY_HOST); new_counter = hypre_CTAlloc(HYPRE_Int, num_passes+1, HYPRE_MEMORY_HOST); new_counter[0] = 0; new_counter[1] = n_coarse_offd; new_num_cols_offd = n_coarse_offd; new_elmts[0] = new_col_map_offd; } /*----------------------------------------------------------------------- * Pass 1: now we consider points of pass 1, with strong C_neighbors, *-----------------------------------------------------------------------*/ cnt_nz = 0; cnt_nz_offd = 0; /* JBS: Possible candidate for threading */ for (i=pass_pointer[1]; i < pass_pointer[2]; i++) { i1 = pass_array[i]; P_diag_start[i1] = cnt_nz; P_offd_start[i1] = cnt_nz_offd; for (j=S_diag_i[i1]; j < S_diag_i[i1+1]; j++) { j1 = S_diag_j[j]; if (CF_marker[j1] == 1) { P_diag_pass[1][cnt_nz++] = fine_to_coarse[j1]; } } for (j=S_offd_i[i1]; j < S_offd_i[i1+1]; j++) { j1 = S_offd_j[j]; if (CF_marker_offd[j1] == 1) { P_offd_pass[1][cnt_nz_offd++] = map_S_to_new[j1]; } } } total_nz += cnt_nz; total_nz_offd += cnt_nz_offd; if (num_procs > 1) { tmp_comm_pkg = hypre_CTAlloc(hypre_ParCSRCommPkg, 1, HYPRE_MEMORY_HOST); Pext_send_map_start = hypre_CTAlloc(HYPRE_Int*, num_passes, HYPRE_MEMORY_HOST); Pext_recv_vec_start = hypre_CTAlloc(HYPRE_Int*, num_passes, HYPRE_MEMORY_HOST); Pext_pass = hypre_CTAlloc(HYPRE_Int*, num_passes, HYPRE_MEMORY_HOST); Pext_i = hypre_CTAlloc(HYPRE_Int, num_cols_offd+1, HYPRE_MEMORY_HOST); if (num_cols_offd) Pext_start = hypre_CTAlloc(HYPRE_Int, num_cols_offd, HYPRE_MEMORY_HOST); if (send_map_start[num_sends]) P_ncols = hypre_CTAlloc(HYPRE_Int, send_map_start[num_sends], HYPRE_MEMORY_HOST); #ifdef HYPRE_USING_OPENMP #pragma omp parallel for private(i) HYPRE_SMP_SCHEDULE #endif for (i=0; i < num_cols_offd+1; i++) { Pext_i[i] = 0; } #ifdef HYPRE_USING_OPENMP #pragma omp parallel for private(i) HYPRE_SMP_SCHEDULE #endif for (i=0; i < send_map_start[num_sends]; i++) { P_ncols[i] = 0; } } old_Pext_send_size = 0; old_Pext_recv_size = 0; for (pass=2; pass < num_passes; pass++) { if (num_procs > 1) { Pext_send_map_start[pass] = hypre_CTAlloc(HYPRE_Int, num_sends+1, HYPRE_MEMORY_HOST); Pext_recv_vec_start[pass] = hypre_CTAlloc(HYPRE_Int, num_recvs+1, HYPRE_MEMORY_HOST); Pext_send_size = 0; Pext_send_map_start[pass][0] = 0; for (i=0; i < num_sends; i++) { #ifdef HYPRE_USING_OPENMP #pragma omp parallel for private(j,j1) reduction(+:Pext_send_size) HYPRE_SMP_SCHEDULE #endif for (j=send_map_start[i]; j < send_map_start[i+1]; j++) { j1 = send_map_elmt[j]; if (assigned[j1] == pass-1) { P_ncols[j] = P_diag_i[j1+1] + P_offd_i[j1+1]; Pext_send_size += P_ncols[j]; } } Pext_send_map_start[pass][i+1] = Pext_send_size; } comm_handle = hypre_ParCSRCommHandleCreate (11, comm_pkg, P_ncols, &Pext_i[1]); hypre_ParCSRCommHandleDestroy(comm_handle); if (Pext_send_size > old_Pext_send_size) { hypre_TFree(Pext_send_buffer, HYPRE_MEMORY_HOST); Pext_send_buffer = hypre_CTAlloc(HYPRE_BigInt, Pext_send_size, HYPRE_MEMORY_HOST); } old_Pext_send_size = Pext_send_size; } cnt_offd = 0; for (i=0; i < num_sends; i++) { for (j=send_map_start[i]; j < send_map_start[i+1]; j++) { j1 = send_map_elmt[j]; if (assigned[j1] == pass-1) { j_start = P_diag_start[j1]; j_end = j_start+P_diag_i[j1+1]; for (k=j_start; k < j_end; k++) { Pext_send_buffer[cnt_offd++] = my_first_cpt + (HYPRE_BigInt) P_diag_pass[pass-1][k]; } j_start = P_offd_start[j1]; j_end = j_start+P_offd_i[j1+1]; for (k=j_start; k < j_end; k++) { k1 = P_offd_pass[pass-1][k]; k3 = 0; while (k3 < pass-1) { if (k1 < new_counter[k3+1]) { k2 = k1-new_counter[k3]; Pext_send_buffer[cnt_offd++] = new_elmts[k3][k2]; break; } k3++; } } } } } if (num_procs > 1) { Pext_recv_size = 0; Pext_recv_vec_start[pass][0] = 0; cnt_offd = 0; for (i=0; i < num_recvs; i++) { for (j=recv_vec_start[i]; j<recv_vec_start[i+1]; j++) { if (assigned_offd[j] == pass-1) { Pext_start[j] = cnt_offd; cnt_offd += Pext_i[j+1]; } } Pext_recv_size = cnt_offd; Pext_recv_vec_start[pass][i+1] = Pext_recv_size; } hypre_ParCSRCommPkgComm(tmp_comm_pkg) = comm; hypre_ParCSRCommPkgNumSends(tmp_comm_pkg) = num_sends; hypre_ParCSRCommPkgSendProcs(tmp_comm_pkg) = send_procs; hypre_ParCSRCommPkgSendMapStarts(tmp_comm_pkg) = Pext_send_map_start[pass]; hypre_ParCSRCommPkgNumRecvs(tmp_comm_pkg) = num_recvs; hypre_ParCSRCommPkgRecvProcs(tmp_comm_pkg) = recv_procs; hypre_ParCSRCommPkgRecvVecStarts(tmp_comm_pkg) = Pext_recv_vec_start[pass]; if (Pext_recv_size) { Pext_pass[pass] = hypre_CTAlloc(HYPRE_Int, Pext_recv_size, HYPRE_MEMORY_HOST); new_elmts[pass-1] = hypre_CTAlloc(HYPRE_BigInt, Pext_recv_size, HYPRE_MEMORY_HOST); } else { Pext_pass[pass] = NULL; new_elmts[pass-1] = NULL; } if (Pext_recv_size > old_Pext_recv_size) { hypre_TFree(loc, HYPRE_MEMORY_HOST); loc = hypre_CTAlloc(HYPRE_Int, Pext_recv_size, HYPRE_MEMORY_HOST); hypre_TFree(big_temp_pass, HYPRE_MEMORY_HOST); big_temp_pass = hypre_CTAlloc(HYPRE_BigInt, Pext_recv_size, HYPRE_MEMORY_HOST); } old_Pext_recv_size = Pext_recv_size; comm_handle = hypre_ParCSRCommHandleCreate (21, tmp_comm_pkg, Pext_send_buffer, big_temp_pass); hypre_ParCSRCommHandleDestroy(comm_handle); } cnt_new = 0; cnt_offd = 0; /* JBS: Possible candidate for threading */ for (i=0; i < num_recvs; i++) { for (j=recv_vec_start[i]; j < recv_vec_start[i+1]; j++) { if (assigned_offd[j] == pass-1) { for (j1 = cnt_offd; j1 < cnt_offd+Pext_i[j+1]; j1++) { big_k1 = big_temp_pass[j1]; k2 = (HYPRE_Int)(big_k1 - my_first_cpt); if (k2 > -1 && k2 < n_coarse) { Pext_pass[pass][j1] = -k2-1; } else { not_found = 1; k3 = 0; while (k3 < pass-1 && not_found) { k2 = hypre_BigBinarySearch(new_elmts[k3], big_k1, (new_counter[k3+1]-new_counter[k3])); if (k2 > -1) { Pext_pass[pass][j1] = k2 + new_counter[k3]; not_found = 0; } else { k3++; } } if (not_found) { new_elmts[pass-1][cnt_new] = big_k1; loc[cnt_new++] = j1; } } } cnt_offd += Pext_i[j+1]; } } } if (cnt_new) { hypre_BigQsortbi(new_elmts[pass-1],loc,0,cnt_new-1); cnt = 0; local_index = new_counter[pass-1]; Pext_pass[pass][loc[0]] = local_index; for (i=1; i < cnt_new; i++) { if (new_elmts[pass-1][i] > new_elmts[pass-1][cnt]) { new_elmts[pass-1][++cnt] = new_elmts[pass-1][i]; local_index++; } Pext_pass[pass][loc[i]] = local_index; } new_counter[pass] = local_index+1; } else if (num_procs > 1) new_counter[pass] = new_counter[pass-1]; if (new_num_cols_offd < local_index+1) { new_num_cols_offd = local_index+1; } pass_length = pass_pointer[pass+1] - pass_pointer[pass]; #ifdef HYPRE_USING_OPENMP #pragma omp parallel private(i,my_thread_num,num_threads,thread_start,thread_stop,cnt_nz,cnt_nz_offd,i1,j,j1,j_start,j_end,k1,k,P_marker,P_marker_offd) #endif { /* Thread by computing the sparsity structure for this pass only over * each thread's range of rows. Rows are divided up evenly amongst * the threads. The necessary thread-wise temporary arrays, like * P_marker, are initialized and de-allocated internally to the * parallel region. */ my_thread_num = hypre_GetThreadNum(); num_threads = hypre_NumActiveThreads(); thread_start = (pass_length/num_threads)*my_thread_num; if (my_thread_num == num_threads-1) { thread_stop = pass_length; } else { thread_stop = (pass_length/num_threads)*(my_thread_num+1); } thread_start += pass_pointer[pass]; thread_stop += pass_pointer[pass]; /* Local initializations */ cnt_nz = 0; cnt_nz_offd = 0; /* This block of code is to go to the top of the parallel region starting before * the loop over num_passes. */ P_marker = hypre_CTAlloc(HYPRE_Int, n_coarse, HYPRE_MEMORY_HOST); /* marks points to see if they're counted */ for (i=0; i < n_coarse; i++) { P_marker[i] = -1; } if (new_num_cols_offd == local_index+1) { P_marker_offd = hypre_CTAlloc(HYPRE_Int, new_num_cols_offd, HYPRE_MEMORY_HOST); for (i=0; i < new_num_cols_offd; i++) { P_marker_offd[i] = -1; } } else if (n_coarse_offd) { P_marker_offd = hypre_CTAlloc(HYPRE_Int, n_coarse_offd, HYPRE_MEMORY_HOST); for (i=0; i < n_coarse_offd; i++) { P_marker_offd[i] = -1; } } /* Need some variables to store each threads cnt_nz and cnt_nz_offd, and * then stitch things together as in par_interp.c * This loop writes * P_diag_i, P_offd_i: data parallel here, and require no special treatment * P_diag_start, P_offd_start: are not data parallel, require special treatment */ for (i=thread_start; i < thread_stop; i++) { i1 = pass_array[i]; P_diag_start[i1] = cnt_nz; P_offd_start[i1] = cnt_nz_offd; for (j=S_diag_i[i1]; j < S_diag_i[i1+1]; j++) { j1 = S_diag_j[j]; if (assigned[j1] == pass-1) { j_start = P_diag_start[j1]; j_end = j_start+P_diag_i[j1+1]; for (k=j_start; k < j_end; k++) { k1 = P_diag_pass[pass-1][k]; if (P_marker[k1] != i1) { cnt_nz++; P_diag_i[i1+1]++; P_marker[k1] = i1; } } j_start = P_offd_start[j1]; j_end = j_start+P_offd_i[j1+1]; for (k=j_start; k < j_end; k++) { k1 = P_offd_pass[pass-1][k]; if (P_marker_offd[k1] != i1) { cnt_nz_offd++; P_offd_i[i1+1]++; P_marker_offd[k1] = i1; } } } } j_start = 0; for (j=S_offd_i[i1]; j < S_offd_i[i1+1]; j++) { j1 = S_offd_j[j]; if (assigned_offd[j1] == pass-1) { j_start = Pext_start[j1]; j_end = j_start+Pext_i[j1+1]; for (k=j_start; k < j_end; k++) { k1 = Pext_pass[pass][k]; if (k1 < 0) { if (P_marker[-k1-1] != i1) { cnt_nz++; P_diag_i[i1+1]++; P_marker[-k1-1] = i1; } } else if (P_marker_offd[k1] != i1) { cnt_nz_offd++; P_offd_i[i1+1]++; P_marker_offd[k1] = i1; } } } } } /* Update P_diag_start, P_offd_start with cumulative * nonzero counts over all threads */ if(my_thread_num == 0) { max_num_threads[0] = num_threads; } cnt_nz_offd_per_thread[my_thread_num] = cnt_nz_offd; cnt_nz_per_thread[my_thread_num] = cnt_nz; #ifdef HYPRE_USING_OPENMP #pragma omp barrier #endif if(my_thread_num == 0) { for(i = 1; i < max_num_threads[0]; i++) { cnt_nz_offd_per_thread[i] += cnt_nz_offd_per_thread[i-1]; cnt_nz_per_thread[i] += cnt_nz_per_thread[i-1]; } } #ifdef HYPRE_USING_OPENMP #pragma omp barrier #endif if(my_thread_num > 0) { /* update this thread's section of P_diag_start and P_offd_start * with the num of nz's counted by previous threads */ for (i=thread_start; i < thread_stop; i++) { i1 = pass_array[i]; P_diag_start[i1] += cnt_nz_per_thread[my_thread_num-1]; P_offd_start[i1] += cnt_nz_offd_per_thread[my_thread_num-1]; } } else /* if my_thread_num == 0 */ { /* Grab the nz count for all threads */ cnt_nz = cnt_nz_per_thread[max_num_threads[0]-1]; cnt_nz_offd = cnt_nz_offd_per_thread[max_num_threads[0]-1]; /* Updated total nz count */ total_nz += cnt_nz; total_nz_offd += cnt_nz_offd; /* Allocate P_diag_pass and P_offd_pass for all threads */ P_diag_pass[pass] = hypre_CTAlloc(HYPRE_Int, cnt_nz, HYPRE_MEMORY_HOST); if (cnt_nz_offd) P_offd_pass[pass] = hypre_CTAlloc(HYPRE_Int, cnt_nz_offd, HYPRE_MEMORY_HOST); else if (num_procs > 1) P_offd_pass[pass] = NULL; } #ifdef HYPRE_USING_OPENMP #pragma omp barrier #endif /* offset cnt_nz and cnt_nz_offd to point to the starting * point in P_diag_pass and P_offd_pass for each thread */ if(my_thread_num > 0) { cnt_nz = cnt_nz_per_thread[my_thread_num-1]; cnt_nz_offd = cnt_nz_offd_per_thread[my_thread_num-1]; } else { cnt_nz = 0; cnt_nz_offd = 0; } /* Set P_diag_pass and P_offd_pass */ for (i=thread_start; i < thread_stop; i++) { i1 = pass_array[i]; for (j=S_diag_i[i1]; j < S_diag_i[i1+1]; j++) { j1 = S_diag_j[j]; if (assigned[j1] == pass-1) { j_start = P_diag_start[j1]; j_end = j_start+P_diag_i[j1+1]; for (k=j_start; k < j_end; k++) { k1 = P_diag_pass[pass-1][k]; if (P_marker[k1] != -i1-1) { P_diag_pass[pass][cnt_nz++] = k1; P_marker[k1] = -i1-1; } } j_start = P_offd_start[j1]; j_end = j_start+P_offd_i[j1+1]; for (k=j_start; k < j_end; k++) { k1 = P_offd_pass[pass-1][k]; if (P_marker_offd[k1] != -i1-1) { P_offd_pass[pass][cnt_nz_offd++] = k1; P_marker_offd[k1] = -i1-1; } } } } for (j=S_offd_i[i1]; j < S_offd_i[i1+1]; j++) { j1 = S_offd_j[j]; if (assigned_offd[j1] == pass-1) { j_start = Pext_start[j1]; j_end = j_start+Pext_i[j1+1]; for (k=j_start; k < j_end; k++) { k1 = Pext_pass[pass][k]; if (k1 < 0) { if (P_marker[-k1-1] != -i1-1) { P_diag_pass[pass][cnt_nz++] = -k1-1; P_marker[-k1-1] = -i1-1; } } else if (P_marker_offd[k1] != -i1-1) { P_offd_pass[pass][cnt_nz_offd++] = k1; P_marker_offd[k1] = -i1-1; } } } } } hypre_TFree(P_marker, HYPRE_MEMORY_HOST); if ( (n_coarse_offd) || (new_num_cols_offd == local_index+1) ) { hypre_TFree(P_marker_offd, HYPRE_MEMORY_HOST); } } /* End parallel region */ } hypre_TFree(loc, HYPRE_MEMORY_HOST); hypre_TFree(P_ncols, HYPRE_MEMORY_HOST); hypre_TFree(Pext_send_buffer, HYPRE_MEMORY_HOST); hypre_TFree(big_temp_pass, HYPRE_MEMORY_HOST); hypre_TFree(new_recv_vec_start, HYPRE_MEMORY_HOST); hypre_TFree(cnt_nz_per_thread, HYPRE_MEMORY_HOST); hypre_TFree(cnt_nz_offd_per_thread, HYPRE_MEMORY_HOST); hypre_TFree(max_num_threads, HYPRE_MEMORY_HOST); P_diag_j = hypre_CTAlloc(HYPRE_Int, total_nz, HYPRE_MEMORY_DEVICE); P_diag_data = hypre_CTAlloc(HYPRE_Real, total_nz, HYPRE_MEMORY_DEVICE); if (total_nz_offd) { P_offd_j = hypre_CTAlloc(HYPRE_Int, total_nz_offd, HYPRE_MEMORY_DEVICE); P_offd_data = hypre_CTAlloc(HYPRE_Real, total_nz_offd, HYPRE_MEMORY_DEVICE); } for (i=0; i < n_fine; i++) { P_diag_i[i+1] += P_diag_i[i]; P_offd_i[i+1] += P_offd_i[i]; } /* determine P for coarse points */ #ifdef HYPRE_USING_OPENMP #pragma omp parallel for private(i,i1) HYPRE_SMP_SCHEDULE #endif for (i=0; i < n_coarse; i++) { i1 = C_array[i]; P_diag_j[P_diag_i[i1]] = fine_to_coarse[i1]; P_diag_data[P_diag_i[i1]] = 1.0; } if (weight_option) /*if this is set, weights are separated into negative and positive offdiagonals and accumulated accordingly */ { pass_length = pass_pointer[2]-pass_pointer[1]; #ifdef HYPRE_USING_OPENMP #pragma omp parallel private(thread_start,thread_stop,my_thread_num,num_threads,P_marker,P_marker_offd,i,i1,sum_C_pos,sum_C_neg,sum_N_pos,sum_N_neg,j_start,j_end,j,k1,cnt,j1,cnt_offd,diagonal,alfa,beta) #endif { /* Sparsity structure is now finished. Next, calculate interpolation * weights for pass one. Thread by computing the interpolation * weights only over each thread's range of rows. Rows are divided * up evenly amongst the threads. */ P_marker = hypre_CTAlloc(HYPRE_Int, n_fine, HYPRE_MEMORY_HOST); for (i=0; i < n_fine; i++) { P_marker[i] = -1; } if (num_cols_offd) { P_marker_offd = hypre_CTAlloc(HYPRE_Int, num_cols_offd, HYPRE_MEMORY_HOST); for (i=0; i < num_cols_offd; i++) P_marker_offd[i] = -1; } /* Compute this thread's range of pass_length */ my_thread_num = hypre_GetThreadNum(); num_threads = hypre_NumActiveThreads(); thread_start = pass_pointer[1] + (pass_length/num_threads)*my_thread_num; if (my_thread_num == num_threads-1) { thread_stop = pass_pointer[1] + pass_length; } else { thread_stop = pass_pointer[1] + (pass_length/num_threads)*(my_thread_num+1); } /* determine P for points of pass 1, i.e. neighbors of coarse points */ for (i=thread_start; i < thread_stop; i++) { i1 = pass_array[i]; sum_C_pos = 0; sum_C_neg = 0; sum_N_pos = 0; sum_N_neg = 0; j_start = P_diag_start[i1]; j_end = j_start+P_diag_i[i1+1]-P_diag_i[i1]; for (j=j_start; j < j_end; j++) { k1 = P_diag_pass[1][j]; P_marker[C_array[k1]] = i1; } cnt = P_diag_i[i1]; for (j=A_diag_i[i1]+1; j < A_diag_i[i1+1]; j++) { j1 = A_diag_j[j]; if (CF_marker[j1] != -3 && (num_functions == 1 || dof_func[i1] == dof_func[j1])) { if (A_diag_data[j] < 0) sum_N_neg += A_diag_data[j]; else sum_N_pos += A_diag_data[j]; } if (j1 != -1 && P_marker[j1] == i1) { P_diag_data[cnt] = A_diag_data[j]; P_diag_j[cnt++] = fine_to_coarse[j1]; if (A_diag_data[j] < 0) sum_C_neg += A_diag_data[j]; else sum_C_pos += A_diag_data[j]; } } j_start = P_offd_start[i1]; j_end = j_start+P_offd_i[i1+1]-P_offd_i[i1]; for (j=j_start; j < j_end; j++) { k1 = P_offd_pass[1][j]; P_marker_offd[C_array_offd[k1]] = i1; } cnt_offd = P_offd_i[i1]; for (j=A_offd_i[i1]; j < A_offd_i[i1+1]; j++) { if (col_offd_S_to_A) j1 = map_A_to_S[A_offd_j[j]]; else j1 = A_offd_j[j]; if (CF_marker_offd[j1] != -3 && (num_functions == 1 || dof_func[i1] == dof_func_offd[j1])) { if (A_offd_data[j] < 0) sum_N_neg += A_offd_data[j]; else sum_N_pos += A_offd_data[j]; } if (j1 != -1 && P_marker_offd[j1] == i1) { P_offd_data[cnt_offd] = A_offd_data[j]; P_offd_j[cnt_offd++] = map_S_to_new[j1]; if (A_offd_data[j] < 0) sum_C_neg += A_offd_data[j]; else sum_C_pos += A_offd_data[j]; } } diagonal = A_diag_data[A_diag_i[i1]]; if (sum_C_neg*diagonal != 0) alfa = -sum_N_neg/(sum_C_neg*diagonal); if (sum_C_pos*diagonal != 0) beta = -sum_N_pos/(sum_C_pos*diagonal); for (j=P_diag_i[i1]; j < cnt; j++) if (P_diag_data[j] < 0) P_diag_data[j] *= alfa; else P_diag_data[j] *= beta; for (j=P_offd_i[i1]; j < cnt_offd; j++) if (P_offd_data[j] < 0) P_offd_data[j] *= alfa; else P_offd_data[j] *= beta; } hypre_TFree(P_marker, HYPRE_MEMORY_HOST); if (num_cols_offd) { hypre_TFree(P_marker_offd, HYPRE_MEMORY_HOST); } } /* End Parallel Region */ old_Pext_send_size = 0; old_Pext_recv_size = 0; /*if (!col_offd_S_to_A) hypre_TFree(map_A_to_new);*/ if (n_coarse) hypre_TFree(C_array, HYPRE_MEMORY_HOST); hypre_TFree(C_array_offd, HYPRE_MEMORY_HOST); hypre_TFree(P_diag_pass[1], HYPRE_MEMORY_HOST); if (num_procs > 1) hypre_TFree(P_offd_pass[1], HYPRE_MEMORY_HOST); for (pass = 2; pass < num_passes; pass++) { if (num_procs > 1) { Pext_send_size = Pext_send_map_start[pass][num_sends]; if (Pext_send_size > old_Pext_send_size) { hypre_TFree(Pext_send_data, HYPRE_MEMORY_HOST); Pext_send_data = hypre_CTAlloc(HYPRE_Real, Pext_send_size, HYPRE_MEMORY_HOST); } old_Pext_send_size = Pext_send_size; cnt_offd = 0; for (i=0; i < num_sends; i++) { for (j=send_map_start[i]; j < send_map_start[i+1]; j++) { j1 = send_map_elmt[j]; if (assigned[j1] == pass-1) { j_start = P_diag_i[j1]; j_end = P_diag_i[j1+1]; for (k=j_start; k < j_end; k++) { Pext_send_data[cnt_offd++] = P_diag_data[k]; } j_start = P_offd_i[j1]; j_end = P_offd_i[j1+1]; for (k=j_start; k < j_end; k++) { Pext_send_data[cnt_offd++] = P_offd_data[k]; } } } } hypre_ParCSRCommPkgNumSends(tmp_comm_pkg) = num_sends; hypre_ParCSRCommPkgSendMapStarts(tmp_comm_pkg) = Pext_send_map_start[pass]; hypre_ParCSRCommPkgNumRecvs(tmp_comm_pkg) = num_recvs; hypre_ParCSRCommPkgRecvVecStarts(tmp_comm_pkg) = Pext_recv_vec_start[pass]; Pext_recv_size = Pext_recv_vec_start[pass][num_recvs]; if (Pext_recv_size > old_Pext_recv_size) { hypre_TFree(Pext_data, HYPRE_MEMORY_HOST); Pext_data = hypre_CTAlloc(HYPRE_Real, Pext_recv_size, HYPRE_MEMORY_HOST); } old_Pext_recv_size = Pext_recv_size; comm_handle = hypre_ParCSRCommHandleCreate (1, tmp_comm_pkg, Pext_send_data, Pext_data); hypre_ParCSRCommHandleDestroy(comm_handle); hypre_TFree(Pext_send_map_start[pass], HYPRE_MEMORY_HOST); hypre_TFree(Pext_recv_vec_start[pass], HYPRE_MEMORY_HOST); } pass_length = pass_pointer[pass+1]-pass_pointer[pass]; #ifdef HYPRE_USING_OPENMP #pragma omp parallel private(thread_start,thread_stop,my_thread_num,num_threads,P_marker,P_marker_offd,i,i1,sum_C_neg,sum_C_pos,sum_N_neg,sum_N_pos,j_start,j_end,cnt,j,k1,cnt_offd,j1,k,alfa,beta,diagonal,C_array,C_array_offd) #endif { /* Sparsity structure is now finished. Next, calculate interpolation * weights for passes >= 2. Thread by computing the interpolation * weights only over each thread's range of rows. Rows are divided * up evenly amongst the threads. */ P_marker = hypre_CTAlloc(HYPRE_Int, n_fine, HYPRE_MEMORY_HOST); for (i=0; i < n_fine; i++) { P_marker[i] = -1; } if (num_cols_offd) { P_marker_offd = hypre_CTAlloc(HYPRE_Int, num_cols_offd, HYPRE_MEMORY_HOST); for (i=0; i < num_cols_offd; i++) P_marker_offd[i] = -1; } C_array = NULL; C_array_offd = NULL; if (n_coarse) { C_array = hypre_CTAlloc(HYPRE_Int, n_coarse, HYPRE_MEMORY_HOST); } if (new_num_cols_offd > n_coarse_offd) { C_array_offd = hypre_CTAlloc(HYPRE_Int, new_num_cols_offd, HYPRE_MEMORY_HOST); } else if (n_coarse_offd) { C_array_offd = hypre_CTAlloc(HYPRE_Int, n_coarse_offd, HYPRE_MEMORY_HOST); } /* Compute this thread's range of pass_length */ my_thread_num = hypre_GetThreadNum(); num_threads = hypre_NumActiveThreads(); thread_start = pass_pointer[pass] + (pass_length/num_threads)*my_thread_num; if (my_thread_num == num_threads-1) { thread_stop = pass_pointer[pass] + pass_length; } else { thread_stop = pass_pointer[pass] + (pass_length/num_threads)*(my_thread_num+1); } /* Loop over each thread's row-range */ for (i=thread_start; i < thread_stop; i++) { i1 = pass_array[i]; sum_C_neg = 0; sum_C_pos = 0; sum_N_neg = 0; sum_N_pos = 0; j_start = P_diag_start[i1]; j_end = j_start+P_diag_i[i1+1]-P_diag_i[i1]; cnt = P_diag_i[i1]; for (j=j_start; j < j_end; j++) { k1 = P_diag_pass[pass][j]; C_array[k1] = cnt; P_diag_data[cnt] = 0; P_diag_j[cnt++] = k1; } j_start = P_offd_start[i1]; j_end = j_start+P_offd_i[i1+1]-P_offd_i[i1]; cnt_offd = P_offd_i[i1]; for (j=j_start; j < j_end; j++) { k1 = P_offd_pass[pass][j]; C_array_offd[k1] = cnt_offd; P_offd_data[cnt_offd] = 0; P_offd_j[cnt_offd++] = k1; } for (j=S_diag_i[i1]; j < S_diag_i[i1+1]; j++) { j1 = S_diag_j[j]; if (assigned[j1] == pass-1) P_marker[j1] = i1; } for (j=S_offd_i[i1]; j < S_offd_i[i1+1]; j++) { j1 = S_offd_j[j]; if (assigned_offd[j1] == pass-1) P_marker_offd[j1] = i1; } for (j=A_diag_i[i1]+1; j < A_diag_i[i1+1]; j++) { j1 = A_diag_j[j]; if (P_marker[j1] == i1) { for (k=P_diag_i[j1]; k < P_diag_i[j1+1]; k++) { k1 = P_diag_j[k]; alfa = A_diag_data[j]*P_diag_data[k]; P_diag_data[C_array[k1]] += alfa; if (alfa < 0) { sum_C_neg += alfa; sum_N_neg += alfa; } else { sum_C_pos += alfa; sum_N_pos += alfa; } } for (k=P_offd_i[j1]; k < P_offd_i[j1+1]; k++) { k1 = P_offd_j[k]; alfa = A_diag_data[j]*P_offd_data[k]; P_offd_data[C_array_offd[k1]] += alfa; if (alfa < 0) { sum_C_neg += alfa; sum_N_neg += alfa; } else { sum_C_pos += alfa; sum_N_pos += alfa; } } } else { if (CF_marker[j1] != -3 && (num_functions == 1 || dof_func[i1] == dof_func[j1])) { if (A_diag_data[j] < 0) sum_N_neg += A_diag_data[j]; else sum_N_pos += A_diag_data[j]; } } } for (j=A_offd_i[i1]; j < A_offd_i[i1+1]; j++) { if (col_offd_S_to_A) j1 = map_A_to_S[A_offd_j[j]]; else j1 = A_offd_j[j]; if (j1 > -1 && P_marker_offd[j1] == i1) { j_start = Pext_start[j1]; j_end = j_start+Pext_i[j1+1]; for (k=j_start; k < j_end; k++) { k1 = Pext_pass[pass][k]; alfa = A_offd_data[j]*Pext_data[k]; if (k1 < 0) P_diag_data[C_array[-k1-1]] += alfa; else P_offd_data[C_array_offd[k1]] += alfa; if (alfa < 0) { sum_C_neg += alfa; sum_N_neg += alfa; } else { sum_C_pos += alfa; sum_N_pos += alfa; } } } else { if (CF_marker_offd[j1] != -3 && (num_functions == 1 || dof_func_offd[j1] == dof_func[i1])) { if ( A_offd_data[j] < 0) sum_N_neg += A_offd_data[j]; else sum_N_pos += A_offd_data[j]; } } } diagonal = A_diag_data[A_diag_i[i1]]; if (sum_C_neg*diagonal != 0) alfa = -sum_N_neg/(sum_C_neg*diagonal); if (sum_C_pos*diagonal != 0) beta = -sum_N_pos/(sum_C_pos*diagonal); for (j=P_diag_i[i1]; j < P_diag_i[i1+1]; j++) if (P_diag_data[j] < 0) P_diag_data[j] *= alfa; else P_diag_data[j] *= beta; for (j=P_offd_i[i1]; j < P_offd_i[i1+1]; j++) if (P_offd_data[j] < 0) P_offd_data[j] *= alfa; else P_offd_data[j] *= beta; } hypre_TFree(C_array, HYPRE_MEMORY_HOST); hypre_TFree(C_array_offd, HYPRE_MEMORY_HOST); hypre_TFree(P_marker, HYPRE_MEMORY_HOST); if (num_cols_offd) { hypre_TFree(P_marker_offd, HYPRE_MEMORY_HOST); } } /* End OMP Parallel Section */ hypre_TFree(P_diag_pass[pass], HYPRE_MEMORY_HOST); if (num_procs > 1) { hypre_TFree(P_offd_pass[pass], HYPRE_MEMORY_HOST); hypre_TFree(Pext_pass[pass], HYPRE_MEMORY_HOST); } } /* End num_passes for-loop */ } else /* no distinction between positive and negative offdiagonal element */ { pass_length = pass_pointer[2]-pass_pointer[1]; #ifdef HYPRE_USING_OPENMP #pragma omp parallel private(thread_start,thread_stop,my_thread_num,num_threads,k,k1,i,i1,j,j1,sum_C,sum_N,j_start,j_end,cnt,tmp_marker,tmp_marker_offd,cnt_offd,diagonal,alfa) #endif { /* Sparsity structure is now finished. Next, calculate interpolation * weights for pass one. Thread by computing the interpolation * weights only over each thread's range of rows. Rows are divided * up evenly amongst the threads. */ /* Initialize thread-wise variables */ tmp_marker = NULL; if (n_fine) { tmp_marker = hypre_CTAlloc(HYPRE_Int, n_fine, HYPRE_MEMORY_HOST); } tmp_marker_offd = NULL; if (num_cols_offd) { tmp_marker_offd = hypre_CTAlloc(HYPRE_Int, num_cols_offd, HYPRE_MEMORY_HOST); } for (i=0; i < n_fine; i++) { tmp_marker[i] = -1; } for (i=0; i < num_cols_offd; i++) { tmp_marker_offd[i] = -1; } /* Compute this thread's range of pass_length */ my_thread_num = hypre_GetThreadNum(); num_threads = hypre_NumActiveThreads(); thread_start = pass_pointer[1] + (pass_length/num_threads)*my_thread_num; if (my_thread_num == num_threads-1) { thread_stop = pass_pointer[1] + pass_length; } else { thread_stop = pass_pointer[1] + (pass_length/num_threads)*(my_thread_num+1); } /* determine P for points of pass 1, i.e. neighbors of coarse points */ for (i=thread_start; i < thread_stop; i++) { i1 = pass_array[i]; sum_C = 0; sum_N = 0; j_start = P_diag_start[i1]; j_end = j_start+P_diag_i[i1+1]-P_diag_i[i1]; for (j=j_start; j < j_end; j++) { k1 = P_diag_pass[1][j]; tmp_marker[C_array[k1]] = i1; } cnt = P_diag_i[i1]; for (j=A_diag_i[i1]+1; j < A_diag_i[i1+1]; j++) { j1 = A_diag_j[j]; if (CF_marker[j1] != -3 && (num_functions == 1 || dof_func[i1] == dof_func[j1])) sum_N += A_diag_data[j]; if (j1 != -1 && tmp_marker[j1] == i1) { P_diag_data[cnt] = A_diag_data[j]; P_diag_j[cnt++] = fine_to_coarse[j1]; sum_C += A_diag_data[j]; } } j_start = P_offd_start[i1]; j_end = j_start+P_offd_i[i1+1]-P_offd_i[i1]; for (j=j_start; j < j_end; j++) { k1 = P_offd_pass[1][j]; tmp_marker_offd[C_array_offd[k1]] = i1; } cnt_offd = P_offd_i[i1]; for (j=A_offd_i[i1]; j < A_offd_i[i1+1]; j++) { if (col_offd_S_to_A) j1 = map_A_to_S[A_offd_j[j]]; else j1 = A_offd_j[j]; if (CF_marker_offd[j1] != -3 && (num_functions == 1 || dof_func[i1] == dof_func_offd[j1])) sum_N += A_offd_data[j]; if (j1 != -1 && tmp_marker_offd[j1] == i1) { P_offd_data[cnt_offd] = A_offd_data[j]; P_offd_j[cnt_offd++] = map_S_to_new[j1]; sum_C += A_offd_data[j]; } } diagonal = A_diag_data[A_diag_i[i1]]; if (sum_C*diagonal != 0) alfa = -sum_N/(sum_C*diagonal); for (j=P_diag_i[i1]; j < cnt; j++) P_diag_data[j] *= alfa; for (j=P_offd_i[i1]; j < cnt_offd; j++) P_offd_data[j] *= alfa; } hypre_TFree(tmp_marker, HYPRE_MEMORY_HOST); hypre_TFree(tmp_marker_offd, HYPRE_MEMORY_HOST); } /* end OMP parallel region */ old_Pext_send_size = 0; old_Pext_recv_size = 0; if (n_coarse) hypre_TFree(C_array, HYPRE_MEMORY_HOST); hypre_TFree(C_array_offd, HYPRE_MEMORY_HOST); hypre_TFree(P_diag_pass[1], HYPRE_MEMORY_HOST); if (num_procs > 1) hypre_TFree(P_offd_pass[1], HYPRE_MEMORY_HOST); for (pass = 2; pass < num_passes; pass++) { if (num_procs > 1) { Pext_send_size = Pext_send_map_start[pass][num_sends]; if (Pext_send_size > old_Pext_send_size) { hypre_TFree(Pext_send_data, HYPRE_MEMORY_HOST); Pext_send_data = hypre_CTAlloc(HYPRE_Real, Pext_send_size, HYPRE_MEMORY_HOST); } old_Pext_send_size = Pext_send_size; cnt_offd = 0; for (i=0; i < num_sends; i++) { for (j=send_map_start[i]; j < send_map_start[i+1]; j++) { j1 = send_map_elmt[j]; if (assigned[j1] == pass-1) { j_start = P_diag_i[j1]; j_end = P_diag_i[j1+1]; for (k=j_start; k < j_end; k++) { Pext_send_data[cnt_offd++] = P_diag_data[k]; } j_start = P_offd_i[j1]; j_end = P_offd_i[j1+1]; for (k=j_start; k < j_end; k++) { Pext_send_data[cnt_offd++] = P_offd_data[k]; } } } } hypre_ParCSRCommPkgNumSends(tmp_comm_pkg) = num_sends; hypre_ParCSRCommPkgSendMapStarts(tmp_comm_pkg) = Pext_send_map_start[pass]; hypre_ParCSRCommPkgNumRecvs(tmp_comm_pkg) = num_recvs; hypre_ParCSRCommPkgRecvVecStarts(tmp_comm_pkg) = Pext_recv_vec_start[pass]; Pext_recv_size = Pext_recv_vec_start[pass][num_recvs]; if (Pext_recv_size > old_Pext_recv_size) { hypre_TFree(Pext_data, HYPRE_MEMORY_HOST); Pext_data = hypre_CTAlloc(HYPRE_Real, Pext_recv_size, HYPRE_MEMORY_HOST); } old_Pext_recv_size = Pext_recv_size; comm_handle = hypre_ParCSRCommHandleCreate (1, tmp_comm_pkg, Pext_send_data, Pext_data); hypre_ParCSRCommHandleDestroy(comm_handle); hypre_TFree(Pext_send_map_start[pass], HYPRE_MEMORY_HOST); hypre_TFree(Pext_recv_vec_start[pass], HYPRE_MEMORY_HOST); } pass_length = pass_pointer[pass+1]-pass_pointer[pass]; #ifdef HYPRE_USING_OPENMP #pragma omp parallel private(thread_start,thread_stop,my_thread_num,num_threads,k,k1,i,i1,j,j1,sum_C,sum_N,j_start,j_end,cnt,tmp_marker,tmp_marker_offd,cnt_offd,diagonal,alfa,tmp_array,tmp_array_offd) #endif { /* Sparsity structure is now finished. Next, calculate interpolation * weights for passes >= 2. Thread by computing the interpolation * weights only over each thread's range of rows. Rows are divided * up evenly amongst the threads. */ /* Initialize thread-wise variables */ tmp_marker = NULL; if (n_fine) { tmp_marker = hypre_CTAlloc(HYPRE_Int, n_fine, HYPRE_MEMORY_HOST); } tmp_marker_offd = NULL; if (num_cols_offd) { tmp_marker_offd = hypre_CTAlloc(HYPRE_Int, num_cols_offd, HYPRE_MEMORY_HOST); } tmp_array = NULL; if (n_coarse) { tmp_array = hypre_CTAlloc(HYPRE_Int, n_coarse, HYPRE_MEMORY_HOST); } tmp_array_offd = NULL; if (new_num_cols_offd > n_coarse_offd) { tmp_array_offd = hypre_CTAlloc(HYPRE_Int, new_num_cols_offd, HYPRE_MEMORY_HOST); } else { tmp_array_offd = hypre_CTAlloc(HYPRE_Int, n_coarse_offd, HYPRE_MEMORY_HOST);} for (i=0; i < n_fine; i++) { tmp_marker[i] = -1; } for (i=0; i < num_cols_offd; i++) { tmp_marker_offd[i] = -1; } /* Compute this thread's range of pass_length */ my_thread_num = hypre_GetThreadNum(); num_threads = hypre_NumActiveThreads(); thread_start = pass_pointer[pass] + (pass_length/num_threads)*my_thread_num; if (my_thread_num == num_threads-1) { thread_stop = pass_pointer[pass] + pass_length; } else { thread_stop = pass_pointer[pass] + (pass_length/num_threads)*(my_thread_num+1); } for (i=thread_start; i < thread_stop; i++) { i1 = pass_array[i]; sum_C = 0; sum_N = 0; j_start = P_diag_start[i1]; j_end = j_start+P_diag_i[i1+1]-P_diag_i[i1]; cnt = P_diag_i[i1]; for (j=j_start; j < j_end; j++) { k1 = P_diag_pass[pass][j]; tmp_array[k1] = cnt; P_diag_data[cnt] = 0; P_diag_j[cnt++] = k1; } j_start = P_offd_start[i1]; j_end = j_start+P_offd_i[i1+1]-P_offd_i[i1]; cnt_offd = P_offd_i[i1]; for (j=j_start; j < j_end; j++) { k1 = P_offd_pass[pass][j]; tmp_array_offd[k1] = cnt_offd; P_offd_data[cnt_offd] = 0; P_offd_j[cnt_offd++] = k1; } for (j=S_diag_i[i1]; j < S_diag_i[i1+1]; j++) { j1 = S_diag_j[j]; if (assigned[j1] == pass-1) tmp_marker[j1] = i1; } for (j=S_offd_i[i1]; j < S_offd_i[i1+1]; j++) { j1 = S_offd_j[j]; if (assigned_offd[j1] == pass-1) tmp_marker_offd[j1] = i1; } for (j=A_diag_i[i1]+1; j < A_diag_i[i1+1]; j++) { j1 = A_diag_j[j]; if (tmp_marker[j1] == i1) { for (k=P_diag_i[j1]; k < P_diag_i[j1+1]; k++) { k1 = P_diag_j[k]; alfa = A_diag_data[j]*P_diag_data[k]; P_diag_data[tmp_array[k1]] += alfa; sum_C += alfa; sum_N += alfa; } for (k=P_offd_i[j1]; k < P_offd_i[j1+1]; k++) { k1 = P_offd_j[k]; alfa = A_diag_data[j]*P_offd_data[k]; P_offd_data[tmp_array_offd[k1]] += alfa; sum_C += alfa; sum_N += alfa; } } else { if (CF_marker[j1] != -3 && (num_functions == 1 || dof_func[i1] == dof_func[j1])) sum_N += A_diag_data[j]; } } for (j=A_offd_i[i1]; j < A_offd_i[i1+1]; j++) { if (col_offd_S_to_A) j1 = map_A_to_S[A_offd_j[j]]; else j1 = A_offd_j[j]; if (j1 > -1 && tmp_marker_offd[j1] == i1) { j_start = Pext_start[j1]; j_end = j_start+Pext_i[j1+1]; for (k=j_start; k < j_end; k++) { k1 = Pext_pass[pass][k]; alfa = A_offd_data[j]*Pext_data[k]; if (k1 < 0) P_diag_data[tmp_array[-k1-1]] += alfa; else P_offd_data[tmp_array_offd[k1]] += alfa; sum_C += alfa; sum_N += alfa; } } else { if (CF_marker_offd[j1] != -3 && (num_functions == 1 || dof_func_offd[j1] == dof_func[i1])) sum_N += A_offd_data[j]; } } diagonal = A_diag_data[A_diag_i[i1]]; if (sum_C*diagonal) alfa = -sum_N/(sum_C*diagonal); for (j=P_diag_i[i1]; j < P_diag_i[i1+1]; j++) P_diag_data[j] *= alfa; for (j=P_offd_i[i1]; j < P_offd_i[i1+1]; j++) P_offd_data[j] *= alfa; } hypre_TFree(tmp_marker, HYPRE_MEMORY_HOST); hypre_TFree(tmp_marker_offd, HYPRE_MEMORY_HOST); hypre_TFree(tmp_array, HYPRE_MEMORY_HOST); hypre_TFree(tmp_array_offd, HYPRE_MEMORY_HOST); } /* End OMP Parallel Section */ hypre_TFree(P_diag_pass[pass], HYPRE_MEMORY_HOST); if (num_procs > 1) { hypre_TFree(P_offd_pass[pass], HYPRE_MEMORY_HOST); hypre_TFree(Pext_pass[pass], HYPRE_MEMORY_HOST); } } } hypre_TFree(CF_marker_offd, HYPRE_MEMORY_HOST); hypre_TFree(Pext_send_map_start, HYPRE_MEMORY_HOST); hypre_TFree(Pext_recv_vec_start, HYPRE_MEMORY_HOST); hypre_TFree(dof_func_offd, HYPRE_MEMORY_HOST); hypre_TFree(Pext_send_data, HYPRE_MEMORY_HOST); hypre_TFree(Pext_data, HYPRE_MEMORY_HOST); hypre_TFree(P_diag_pass, HYPRE_MEMORY_HOST); hypre_TFree(P_offd_pass, HYPRE_MEMORY_HOST); hypre_TFree(Pext_pass, HYPRE_MEMORY_HOST); hypre_TFree(P_diag_start, HYPRE_MEMORY_HOST); hypre_TFree(P_offd_start, HYPRE_MEMORY_HOST); hypre_TFree(Pext_start, HYPRE_MEMORY_HOST); hypre_TFree(Pext_i, HYPRE_MEMORY_HOST); hypre_TFree(fine_to_coarse, HYPRE_MEMORY_HOST); hypre_TFree(assigned, HYPRE_MEMORY_HOST); hypre_TFree(assigned_offd, HYPRE_MEMORY_HOST); hypre_TFree(pass_pointer, HYPRE_MEMORY_HOST); hypre_TFree(pass_array, HYPRE_MEMORY_HOST); hypre_TFree(map_S_to_new, HYPRE_MEMORY_HOST); hypre_TFree(map_A_to_S, HYPRE_MEMORY_HOST); if (num_procs > 1) hypre_TFree(tmp_comm_pkg, HYPRE_MEMORY_HOST); P = hypre_ParCSRMatrixCreate(comm, hypre_ParCSRMatrixGlobalNumRows(A), total_global_cpts, hypre_ParCSRMatrixColStarts(A), num_cpts_global, 0, P_diag_i[n_fine], P_offd_i[n_fine]); P_diag = hypre_ParCSRMatrixDiag(P); hypre_CSRMatrixData(P_diag) = P_diag_data; hypre_CSRMatrixI(P_diag) = P_diag_i; hypre_CSRMatrixJ(P_diag) = P_diag_j; P_offd = hypre_ParCSRMatrixOffd(P); hypre_CSRMatrixData(P_offd) = P_offd_data; hypre_CSRMatrixI(P_offd) = P_offd_i; hypre_CSRMatrixJ(P_offd) = P_offd_j; hypre_ParCSRMatrixOwnsRowStarts(P) = 0; /* Compress P, removing coefficients smaller than trunc_factor * Max and/or keep yat most <P_max_elmts> per row absolutely maximal coefficients */ if (trunc_factor != 0.0 || P_max_elmts != 0) { hypre_BoomerAMGInterpTruncation(P, trunc_factor, P_max_elmts); P_diag_data = hypre_CSRMatrixData(P_diag); P_diag_i = hypre_CSRMatrixI(P_diag); P_diag_j = hypre_CSRMatrixJ(P_diag); P_offd_data = hypre_CSRMatrixData(P_offd); P_offd_i = hypre_CSRMatrixI(P_offd); P_offd_j = hypre_CSRMatrixJ(P_offd); } P_offd_size = P_offd_i[n_fine]; num_cols_offd_P = 0; if (P_offd_size) { if (new_num_cols_offd > num_cols_offd) { P_marker_offd = hypre_CTAlloc(HYPRE_Int, new_num_cols_offd, HYPRE_MEMORY_HOST); } else { P_marker_offd = hypre_CTAlloc(HYPRE_Int, num_cols_offd, HYPRE_MEMORY_HOST); } #ifdef HYPRE_USING_OPENMP #pragma omp parallel for private(i) HYPRE_SMP_SCHEDULE #endif for (i=0; i < new_num_cols_offd; i++) { P_marker_offd[i] = 0; } num_cols_offd_P = 0; for (i=0; i < P_offd_size; i++) { index = P_offd_j[i]; if (!P_marker_offd[index]) { num_cols_offd_P++; P_marker_offd[index] = 1; } } col_map_offd_P = hypre_CTAlloc(HYPRE_BigInt, num_cols_offd_P, HYPRE_MEMORY_HOST); permute = hypre_CTAlloc(HYPRE_Int, new_counter[num_passes-1], HYPRE_MEMORY_HOST); big_permute = hypre_CTAlloc(HYPRE_BigInt, new_counter[num_passes-1], HYPRE_MEMORY_HOST); #ifdef HYPRE_USING_OPENMP #pragma omp parallel for private(i) HYPRE_SMP_SCHEDULE #endif for (i=0; i < new_counter[num_passes-1]; i++) big_permute[i] = -1; cnt = 0; for (i=0; i < num_passes-1; i++) { for (j=new_counter[i]; j < new_counter[i+1]; j++) { if (P_marker_offd[j]) { col_map_offd_P[cnt] = new_elmts[i][j-(HYPRE_BigInt)new_counter[i]]; big_permute[j] = col_map_offd_P[cnt++]; } } } hypre_BigQsort0(col_map_offd_P,0,num_cols_offd_P-1); #ifdef HYPRE_USING_OPENMP #pragma omp parallel for private(i,big_k1) HYPRE_SMP_SCHEDULE #endif for (i=0; i < new_counter[num_passes-1]; i++) { big_k1 = big_permute[i]; if (big_k1 != -1) permute[i] = hypre_BigBinarySearch(col_map_offd_P,big_k1,num_cols_offd_P); } #ifdef HYPRE_USING_OPENMP #pragma omp parallel for private(i) HYPRE_SMP_SCHEDULE #endif for (i=0; i < P_offd_size; i++) { P_offd_j[i] = permute[P_offd_j[i]]; } hypre_TFree(P_marker_offd, HYPRE_MEMORY_HOST); } if (num_procs > 1) { for (i=0; i < num_passes-1; i++) hypre_TFree(new_elmts[i], HYPRE_MEMORY_HOST); } hypre_TFree(permute, HYPRE_MEMORY_HOST); hypre_TFree(big_permute, HYPRE_MEMORY_HOST); hypre_TFree(new_elmts, HYPRE_MEMORY_HOST); hypre_TFree(new_counter, HYPRE_MEMORY_HOST); if (num_cols_offd_P) { hypre_ParCSRMatrixColMapOffd(P) = col_map_offd_P; hypre_CSRMatrixNumCols(P_offd) = num_cols_offd_P; } if (n_SF) { #ifdef HYPRE_USING_OPENMP #pragma omp parallel for private(i) HYPRE_SMP_SCHEDULE #endif for (i=0; i < n_fine; i++) if (CF_marker[i] == -3) CF_marker[i] = -1; } if (num_procs > 1) { hypre_MatvecCommPkgCreate(P); } *P_ptr = P; /* wall_time = hypre_MPI_Wtime() - wall_time; hypre_printf("TOTAL TIME %1.2e \n",wall_time); */ /*----------------------------------------------------------------------- * Build and return dof_func array for coarse grid. *-----------------------------------------------------------------------*/ /*----------------------------------------------------------------------- * Free mapping vector and marker array. *-----------------------------------------------------------------------*/ #ifdef HYPRE_PROFILE hypre_profile_times[HYPRE_TIMER_ID_MULTIPASS_INTERP] += hypre_MPI_Wtime(); #endif return(0); }
GB_binop__islt_uint64.c
//------------------------------------------------------------------------------ // GB_binop: hard-coded functions for each built-in binary operator //------------------------------------------------------------------------------ // SuiteSparse:GraphBLAS, Timothy A. Davis, (c) 2017-2020, All Rights Reserved. // http://suitesparse.com See GraphBLAS/Doc/License.txt for license. //------------------------------------------------------------------------------ // If this file is in the Generated/ folder, do not edit it (auto-generated). #include "GB.h" #ifndef GBCOMPACT #include "GB_control.h" #include "GB_ek_slice.h" #include "GB_dense.h" #include "GB_mkl.h" #include "GB_binop__include.h" // C=binop(A,B) is defined by the following types and operators: // A+B function (eWiseAdd): GB_AaddB__islt_uint64 // A.*B function (eWiseMult): GB_AemultB__islt_uint64 // A*D function (colscale): GB_AxD__islt_uint64 // D*A function (rowscale): GB_DxB__islt_uint64 // C+=B function (dense accum): GB_Cdense_accumB__islt_uint64 // C+=b function (dense accum): GB_Cdense_accumb__islt_uint64 // C+=A+B function (dense ewise3): (none) // C=A+B function (dense ewise3): GB_Cdense_ewise3_noaccum__islt_uint64 // C=scalar+B GB_bind1st__islt_uint64 // C=scalar+B' GB_bind1st_tran__islt_uint64 // C=A+scalar GB_bind2nd__islt_uint64 // C=A'+scalar GB_bind2nd_tran__islt_uint64 // C type: uint64_t // A type: uint64_t // B,b type: uint64_t // BinaryOp: cij = (aij < bij) #define GB_ATYPE \ uint64_t #define GB_BTYPE \ uint64_t #define GB_CTYPE \ uint64_t // true if the types of A and B are identical #define GB_ATYPE_IS_BTYPE \ 1 // true if the types of C and A are identical #define GB_CTYPE_IS_ATYPE \ 1 // true if the types of C and B are identical #define GB_CTYPE_IS_BTYPE \ 1 // aij = Ax [pA] #define GB_GETA(aij,Ax,pA) \ uint64_t aij = Ax [pA] // bij = Bx [pB] #define GB_GETB(bij,Bx,pB) \ uint64_t bij = Bx [pB] // declare scalar of the same type as C #define GB_CTYPE_SCALAR(t) \ uint64_t t // cij = Ax [pA] #define GB_COPY_A_TO_C(cij,Ax,pA) \ cij = Ax [pA] // cij = Bx [pB] #define GB_COPY_B_TO_C(cij,Bx,pB) \ cij = Bx [pB] #define GB_CX(p) Cx [p] // binary operator #define GB_BINOP(z, x, y) \ z = (x < y) ; // op is second #define GB_OP_IS_SECOND \ 0 // op is plus_fp32 or plus_fp64 #define GB_OP_IS_PLUS_REAL \ 0 // op is minus_fp32 or minus_fp64 #define GB_OP_IS_MINUS_REAL \ 0 // GB_cblas_*axpy gateway routine, if it exists for this operator and type: #define GB_CBLAS_AXPY \ (none) // do the numerical phases of GB_add and GB_emult #define GB_PHASE_2_OF_2 // hard-coded loops can be vectorized #define GB_PRAGMA_SIMD_VECTORIZE GB_PRAGMA_SIMD // disable this operator and use the generic case if these conditions hold #define GB_DISABLE \ (GxB_NO_ISLT || GxB_NO_UINT64 || GxB_NO_ISLT_UINT64) //------------------------------------------------------------------------------ // C += A+B, all 3 matrices dense //------------------------------------------------------------------------------ #if 0 // The op must be MIN, MAX, PLUS, MINUS, RMINUS, TIMES, DIV, or RDIV. void (none) ( GrB_Matrix C, const GrB_Matrix A, const GrB_Matrix B, const int nthreads ) { #include "GB_dense_ewise3_accum_template.c" } #endif //------------------------------------------------------------------------------ // C = A+B, all 3 matrices dense //------------------------------------------------------------------------------ GrB_Info GB_Cdense_ewise3_noaccum__islt_uint64 ( GrB_Matrix C, const GrB_Matrix A, const GrB_Matrix B, const int nthreads ) { #if GB_DISABLE return (GrB_NO_VALUE) ; #else #include "GB_dense_ewise3_noaccum_template.c" return (GrB_SUCCESS) ; #endif } //------------------------------------------------------------------------------ // C += B, accumulate a sparse matrix into a dense matrix //------------------------------------------------------------------------------ GrB_Info GB_Cdense_accumB__islt_uint64 ( GrB_Matrix C, const GrB_Matrix B, const int64_t *GB_RESTRICT kfirst_slice, const int64_t *GB_RESTRICT klast_slice, const int64_t *GB_RESTRICT pstart_slice, const int ntasks, const int nthreads ) { #if GB_DISABLE return (GrB_NO_VALUE) ; #else { #include "GB_dense_subassign_23_template.c" } return (GrB_SUCCESS) ; #endif } //------------------------------------------------------------------------------ // C += b, accumulate a scalar into a dense matrix //------------------------------------------------------------------------------ GrB_Info GB_Cdense_accumb__islt_uint64 ( GrB_Matrix C, const GB_void *p_bwork, const int nthreads ) { #if GB_DISABLE return (GrB_NO_VALUE) ; #else { // get the scalar b for C += b, of type uint64_t uint64_t bwork = (*((uint64_t *) p_bwork)) ; #include "GB_dense_subassign_22_template.c" return (GrB_SUCCESS) ; } return (GrB_SUCCESS) ; #endif } //------------------------------------------------------------------------------ // C = A*D, column scale with diagonal D matrix //------------------------------------------------------------------------------ GrB_Info GB_AxD__islt_uint64 ( GrB_Matrix C, const GrB_Matrix A, bool A_is_pattern, const GrB_Matrix D, bool D_is_pattern, const int64_t *GB_RESTRICT kfirst_slice, const int64_t *GB_RESTRICT klast_slice, const int64_t *GB_RESTRICT pstart_slice, const int ntasks, const int nthreads ) { #if GB_DISABLE return (GrB_NO_VALUE) ; #else uint64_t *GB_RESTRICT Cx = (uint64_t *) C->x ; #include "GB_AxB_colscale_meta.c" return (GrB_SUCCESS) ; #endif } //------------------------------------------------------------------------------ // C = D*B, row scale with diagonal D matrix //------------------------------------------------------------------------------ GrB_Info GB_DxB__islt_uint64 ( GrB_Matrix C, const GrB_Matrix D, bool D_is_pattern, const GrB_Matrix B, bool B_is_pattern, int nthreads ) { #if GB_DISABLE return (GrB_NO_VALUE) ; #else uint64_t *GB_RESTRICT Cx = (uint64_t *) C->x ; #include "GB_AxB_rowscale_meta.c" return (GrB_SUCCESS) ; #endif } //------------------------------------------------------------------------------ // eWiseAdd: C = A+B or C<M> = A+B //------------------------------------------------------------------------------ GrB_Info GB_AaddB__islt_uint64 ( GrB_Matrix C, const GrB_Matrix M, const bool Mask_struct, const GrB_Matrix A, const GrB_Matrix B, const bool Ch_is_Mh, const int64_t *GB_RESTRICT C_to_M, const int64_t *GB_RESTRICT C_to_A, const int64_t *GB_RESTRICT C_to_B, const GB_task_struct *GB_RESTRICT TaskList, const int ntasks, const int nthreads ) { #if GB_DISABLE return (GrB_NO_VALUE) ; #else #include "GB_add_template.c" return (GrB_SUCCESS) ; #endif } //------------------------------------------------------------------------------ // eWiseMult: C = A.*B or C<M> = A.*B //------------------------------------------------------------------------------ GrB_Info GB_AemultB__islt_uint64 ( GrB_Matrix C, const GrB_Matrix M, const bool Mask_struct, const GrB_Matrix A, const GrB_Matrix B, const int64_t *GB_RESTRICT C_to_M, const int64_t *GB_RESTRICT C_to_A, const int64_t *GB_RESTRICT C_to_B, const GB_task_struct *GB_RESTRICT TaskList, const int ntasks, const int nthreads ) { #if GB_DISABLE return (GrB_NO_VALUE) ; #else #include "GB_emult_template.c" return (GrB_SUCCESS) ; #endif } //------------------------------------------------------------------------------ // Cx = op (x,Bx): apply a binary operator to a matrix with scalar bind1st //------------------------------------------------------------------------------ GrB_Info GB_bind1st__islt_uint64 ( GB_void *Cx_output, // Cx and Bx may be aliased const GB_void *x_input, const GB_void *Bx_input, int64_t anz, int nthreads ) { #if GB_DISABLE return (GrB_NO_VALUE) ; #else uint64_t *Cx = (uint64_t *) Cx_output ; uint64_t x = (*((uint64_t *) x_input)) ; uint64_t *Bx = (uint64_t *) Bx_input ; int64_t p ; #pragma omp parallel for num_threads(nthreads) schedule(static) for (p = 0 ; p < anz ; p++) { uint64_t bij = Bx [p] ; Cx [p] = (x < bij) ; } return (GrB_SUCCESS) ; #endif } //------------------------------------------------------------------------------ // Cx = op (Ax,y): apply a binary operator to a matrix with scalar bind2nd //------------------------------------------------------------------------------ GrB_Info GB_bind2nd__islt_uint64 ( GB_void *Cx_output, // Cx and Ax may be aliased const GB_void *Ax_input, const GB_void *y_input, int64_t anz, int nthreads ) { #if GB_DISABLE return (GrB_NO_VALUE) ; #else int64_t p ; uint64_t *Cx = (uint64_t *) Cx_output ; uint64_t *Ax = (uint64_t *) Ax_input ; uint64_t y = (*((uint64_t *) y_input)) ; #pragma omp parallel for num_threads(nthreads) schedule(static) for (p = 0 ; p < anz ; p++) { uint64_t aij = Ax [p] ; Cx [p] = (aij < y) ; } return (GrB_SUCCESS) ; #endif } //------------------------------------------------------------------------------ // C = op (x, A'): transpose and apply a binary operator //------------------------------------------------------------------------------ // cij = op (x, aij), no typcasting (in spite of the macro name) #undef GB_CAST_OP #define GB_CAST_OP(pC,pA) \ { \ uint64_t aij = Ax [pA] ; \ Cx [pC] = (x < aij) ; \ } GrB_Info GB_bind1st_tran__islt_uint64 ( GrB_Matrix C, const GB_void *x_input, const GrB_Matrix A, int64_t *GB_RESTRICT *Rowcounts, GBI_single_iterator Iter, const int64_t *GB_RESTRICT A_slice, int naslice ) { // GB_unop_transpose.c uses GB_ATYPE, but A is // the 2nd input to binary operator z=f(x,y). #undef GB_ATYPE #define GB_ATYPE \ uint64_t #if GB_DISABLE return (GrB_NO_VALUE) ; #else uint64_t x = (*((const uint64_t *) x_input)) ; #define GB_PHASE_2_OF_2 #include "GB_unop_transpose.c" return (GrB_SUCCESS) ; #endif #undef GB_ATYPE #define GB_ATYPE \ uint64_t } //------------------------------------------------------------------------------ // C = op (A', y): transpose and apply a binary operator //------------------------------------------------------------------------------ // cij = op (aij, y), no typcasting (in spite of the macro name) #undef GB_CAST_OP #define GB_CAST_OP(pC,pA) \ { \ uint64_t aij = Ax [pA] ; \ Cx [pC] = (aij < y) ; \ } GrB_Info GB_bind2nd_tran__islt_uint64 ( GrB_Matrix C, const GrB_Matrix A, const GB_void *y_input, int64_t *GB_RESTRICT *Rowcounts, GBI_single_iterator Iter, const int64_t *GB_RESTRICT A_slice, int naslice ) { #if GB_DISABLE return (GrB_NO_VALUE) ; #else uint64_t y = (*((const uint64_t *) y_input)) ; #define GB_PHASE_2_OF_2 #include "GB_unop_transpose.c" return (GrB_SUCCESS) ; #endif } #endif
test3_0.c
/* * test3_0.c and test3_1.c are not equivalent because * they have different private list for the parallel construct. */ #include <omp.h> #include <stdio.h> #include <stdlib.h> int main (int argc, char *argv[]) { int nthreads, tid; #pragma omp parallel private(nthreads, tid) { tid = omp_get_thread_num(); printf("Hello World from thread = %d\n", tid); if (tid == 0) { nthreads = omp_get_num_threads(); printf("Number of threads = %d\n", nthreads); } } exit(0); }
topN.c
/* Poisson Factorization for sparse matrices Based on alternating proximal gradient iteration or conjugate gradient. Variables must be initialized from outside the main function ('run_poismf'). Writen for C99 standard and OpenMP 2.0 or later. Reference paper is: Cortes, David. "Fast Non-Bayesian Poisson Factorization for Implicit-Feedback Recommendations." arXiv preprint arXiv:1811.01908 (2018). BSD 2-Clause License Copyright (c) 2018-2021, David Cortes All rights reserved. Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: * Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. * 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. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "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 COPYRIGHT HOLDER OR CONTRIBUTORS 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 "poismf.h" bool check_is_sorted(sparse_ix arr[], size_t n) { if (n <= 1) return true; for (sparse_ix ix = 0; ix < n-1; ix++) if (arr[ix] > arr[ix+1]) return false; return true; } /* https://www.stat.cmu.edu/~ryantibs/median/quickselect.c */ /* Some sample C code for the quickselect algorithm, taken from Numerical Recipes in C. */ #define SWAP(a,b) temp=(a);(a)=(b);(b)=temp; void qs_argpartition(sparse_ix arr[], real_t values[], size_t n, size_t k) { sparse_ix i,ir,j,l,mid; size_t a,temp; l=0; ir=n-1; for(;;) { if (ir <= l+1) { if (ir == l+1 && values[arr[ir]] > values[arr[l]]) { SWAP(arr[l],arr[ir]); } return; } else { mid=(l+ir) >> 1; SWAP(arr[mid],arr[l+1]); if (values[arr[l]] < values[arr[ir]]) { SWAP(arr[l],arr[ir]); } if (values[arr[l+1]] < values[arr[ir]]) { SWAP(arr[l+1],arr[ir]); } if (values[arr[l]] < values[arr[l+1]]) { SWAP(arr[l],arr[l+1]); } i=l+1; j=ir; a=arr[l+1]; for (;;) { do i++; while (values[arr[i]] > values[a]); do j--; while (values[arr[j]] < values[a]); if (j < i) break; SWAP(arr[i],arr[j]); } arr[l+1]=arr[j]; arr[j]=a; if (j >= k) ir=j-1; if (j <= k) l=i; } } } int cmp_size_t(const void *a, const void *b) { return *((sparse_ix*)a) - *((sparse_ix*)b); } real_t *ptr_real_t_glob = NULL; #pragma omp threadprivate(ptr_real_t_glob) int cmp_argsort(const void *a, const void *b) { real_t v1 = ptr_real_t_glob[*((sparse_ix*)a)]; real_t v2 = ptr_real_t_glob[*((sparse_ix*)b)]; return (v1 == v2)? 0 : ((v1 < v2)? 1 : -1); } int topN ( real_t *restrict a_vec, real_t *restrict B, int k, sparse_ix *restrict include_ix, size_t n_include, sparse_ix *restrict exclude_ix, size_t n_exclude, sparse_ix *restrict outp_ix, real_t *restrict outp_score, size_t n_top, size_t n, int nthreads ) { if (n_include == 0) include_ix = NULL; if (n_exclude == 0) exclude_ix = NULL; if (include_ix != NULL && exclude_ix != NULL) return 2; if (n_top == 0) return 2; if (n_exclude > n-n_top) return 2; if (n_include > n) return 2; #if defined(_OPENMP) && ((_OPENMP < 200801) || defined(_WIN32) || defined(_WIN64)) long long ix = 0; #else size_t ix = 0; #endif int retval = 0; size_t n_take = (include_ix != NULL)? (size_t)n_include : ((exclude_ix == NULL)? (size_t)n : (size_t)(n-n_exclude) ); real_t *restrict buffer_scores = NULL; sparse_ix *restrict buffer_ix = NULL; sparse_ix *restrict buffer_mask = NULL; if (include_ix != NULL) { buffer_ix = include_ix; } else { buffer_ix = (sparse_ix*)malloc((size_t)n*sizeof(sparse_ix)); if (buffer_ix == NULL) { retval = 1; goto cleanup; } for (sparse_ix ix = 0; ix < (sparse_ix)n; ix++) buffer_ix[ix] = ix; } if (exclude_ix != NULL) { sparse_ix move_to = n-1; sparse_ix temp; if (!check_is_sorted(exclude_ix, n_exclude)) qsort(exclude_ix, n_exclude, sizeof(sparse_ix), cmp_size_t); for (sparse_ix ix = n_exclude-1; ix >= 0; ix--) { temp = buffer_ix[move_to]; buffer_ix[move_to] = exclude_ix[ix]; buffer_ix[exclude_ix[ix]] = temp; move_to--; if (ix == 0) break; } } /* Case 1: there is a potentially small number of items to include. Here can produce predictons only for those, then make an argsort with doubly-masked indices. */ if (include_ix != NULL) { buffer_scores = (real_t*)malloc((size_t)n_include*sizeof(real_t)); buffer_mask = (sparse_ix*)malloc((size_t)n_include*sizeof(sparse_ix)); if (buffer_scores == NULL || buffer_mask == NULL) { retval = 1; goto cleanup; } #pragma omp parallel for schedule(static) num_threads(nthreads) \ shared(a_vec, B, k, n_include, include_ix, buffer_scores) for (ix = 0; ix < (sparse_ix)n_include; ix++) { buffer_scores[ix] = cblas_tdot(k, a_vec, 1, B + (size_t)include_ix[ix] * (size_t)k, 1); } for (sparse_ix ix = 0; ix < (sparse_ix)n_include; ix++) buffer_mask[ix] = ix; } /* Case 2: there is a large number of items to exclude. Here can also produce predictions only for the included ones and then make a full or partial argsort. */ else if (exclude_ix != NULL && (real_t)n_exclude > (real_t)n/20.) { buffer_scores = (real_t*)malloc(n_take*sizeof(real_t)); buffer_mask = (sparse_ix*)malloc(n_take*sizeof(sparse_ix)); if (buffer_scores == NULL || buffer_mask == NULL) { retval = 1; goto cleanup; } for (sparse_ix ix = 0; ix < (sparse_ix)n_take; ix++) buffer_mask[ix] = ix; #pragma omp parallel for schedule(static) num_threads(nthreads) \ shared(a_vec, B, k, n_take, buffer_ix, buffer_scores) for (ix = 0; ix < (sparse_ix)n_take; ix++) buffer_scores[ix] = cblas_tdot(k, a_vec, 1, B + (size_t)buffer_ix[ix] * (size_t)k, 1); } /* General case: make predictions for all the entries, then a partial argsort (this is faster since it makes use of optimized BLAS gemv, but it's not memory-efficient) */ else { buffer_scores = (real_t*)malloc((size_t)n*sizeof(real_t)); if (buffer_scores == NULL) { retval = 1; goto cleanup; } cblas_tgemv(CblasRowMajor, CblasNoTrans, n, k, 1., B, k, a_vec, 1, 0., buffer_scores, 1); } /* If there is no real_t-mask for indices, do a partial argsort */ ptr_real_t_glob = buffer_scores; if (buffer_mask == NULL) { /* If the number of elements is very small, it's faster to make a full argsort, taking advantage of qsort's optimizations */ if (n_take <= 50 || n_take >= (real_t)n*0.75) { qsort(buffer_ix, n_take, sizeof(sparse_ix), cmp_argsort); } /* Otherwise, do a proper partial sort */ else { qs_argpartition(buffer_ix, buffer_scores, n_take, n_top); qsort(buffer_ix, n_top, sizeof(sparse_ix), cmp_argsort); } memcpy(outp_ix, buffer_ix, (size_t)n_top*sizeof(sparse_ix)); } /* Otherwise, do a partial argsort with doubly-indexed arrays */ else { if (n_take <= 50 || n_take >= (real_t)n*0.75) { qsort(buffer_mask, n_take, sizeof(sparse_ix), cmp_argsort); } else { qs_argpartition(buffer_mask, buffer_scores, n_take, n_top); qsort(buffer_mask, n_top, sizeof(sparse_ix), cmp_argsort); } for (sparse_ix ix = 0; ix < (sparse_ix)n_top; ix++) outp_ix[ix] = buffer_ix[buffer_mask[ix]]; } ptr_real_t_glob = NULL; /* If scores were requested, need to also output those */ if (outp_score != NULL) { if (buffer_mask == NULL) for (sparse_ix ix = 0; ix < (sparse_ix)n_top; ix++) outp_score[ix] = buffer_scores[outp_ix[ix]]; else for (sparse_ix ix = 0; ix < (sparse_ix)n_top; ix++) outp_score[ix] = buffer_scores[buffer_mask[ix]]; } cleanup: free(buffer_scores); if (include_ix == NULL) free(buffer_ix); free(buffer_mask); if (retval == 1) return retval; return 0; }
ast-dump-openmp-parallel-for.c
// RUN: %clang_cc1 -triple x86_64-unknown-unknown -fopenmp -ast-dump %s | FileCheck --match-full-lines -implicit-check-not=openmp_structured_block %s void test_one(int x) { #pragma omp parallel for for (int i = 0; i < x; i++) ; } void test_two(int x, int y) { #pragma omp parallel for for (int i = 0; i < x; i++) for (int i = 0; i < y; i++) ; } void test_three(int x, int y) { #pragma omp parallel for collapse(1) for (int i = 0; i < x; i++) for (int i = 0; i < y; i++) ; } void test_four(int x, int y) { #pragma omp parallel for collapse(2) for (int i = 0; i < x; i++) for (int i = 0; i < y; i++) ; } void test_five(int x, int y, int z) { #pragma omp parallel for collapse(2) for (int i = 0; i < x; i++) for (int i = 0; i < y; i++) for (int i = 0; i < z; i++) ; } // CHECK: TranslationUnitDecl {{.*}} <<invalid sloc>> <invalid sloc> // CHECK: |-FunctionDecl {{.*}} <{{.*}}ast-dump-openmp-parallel-for.c:3:1, line:7:1> line:3:6 test_one 'void (int)' // CHECK-NEXT: | |-ParmVarDecl {{.*}} <col:15, col:19> col:19 used x 'int' // CHECK-NEXT: | `-CompoundStmt {{.*}} <col:22, line:7:1> // CHECK-NEXT: | `-OMPParallelForDirective {{.*}} <line:4:1, col:25> // CHECK-NEXT: | `-CapturedStmt {{.*}} <line:5:3, line:6:5> // CHECK-NEXT: | |-CapturedDecl {{.*}} <<invalid sloc>> <invalid sloc> nothrow // CHECK-NEXT: | | |-ForStmt {{.*}} <line:5:3, line:6:5> // CHECK-NEXT: | | | |-DeclStmt {{.*}} <line:5:8, col:17> // CHECK-NEXT: | | | | `-VarDecl {{.*}} <col:8, col:16> col:12 used i 'int' cinit // CHECK-NEXT: | | | | `-IntegerLiteral {{.*}} <col:16> 'int' 0 // CHECK-NEXT: | | | |-<<<NULL>>> // CHECK-NEXT: | | | |-BinaryOperator {{.*}} <col:19, col:23> 'int' '<' // CHECK-NEXT: | | | | |-ImplicitCastExpr {{.*}} <col:19> 'int' <LValueToRValue> // CHECK-NEXT: | | | | | `-DeclRefExpr {{.*}} <col:19> 'int' lvalue Var {{.*}} 'i' 'int' // CHECK-NEXT: | | | | `-ImplicitCastExpr {{.*}} <col:23> 'int' <LValueToRValue> // CHECK-NEXT: | | | | `-DeclRefExpr {{.*}} <col:23> 'int' lvalue ParmVar {{.*}} 'x' 'int' // CHECK-NEXT: | | | |-UnaryOperator {{.*}} <col:26, col:27> 'int' postfix '++' // CHECK-NEXT: | | | | `-DeclRefExpr {{.*}} <col:26> 'int' lvalue Var {{.*}} 'i' 'int' // CHECK-NEXT: | | | `-NullStmt {{.*}} <line:6:5> // CHECK-NEXT: | | |-ImplicitParamDecl {{.*}} <line:4:1> col:1 implicit .global_tid. 'const int *const restrict' // CHECK-NEXT: | | |-ImplicitParamDecl {{.*}} <col:1> col:1 implicit .bound_tid. 'const int *const restrict' // CHECK-NEXT: | | |-ImplicitParamDecl {{.*}} <col:1> col:1 implicit __context 'struct (anonymous at {{.*}}ast-dump-openmp-parallel-for.c:4:1) *const restrict' // CHECK-NEXT: | | `-VarDecl {{.*}} <line:5:8, col:16> col:12 used i 'int' cinit // CHECK-NEXT: | | `-IntegerLiteral {{.*}} <col:16> 'int' 0 // CHECK-NEXT: | `-DeclRefExpr {{.*}} <col:3> 'int' lvalue ParmVar {{.*}} 'x' 'int' // CHECK-NEXT: |-FunctionDecl {{.*}} <line:9:1, line:14:1> line:9:6 test_two 'void (int, int)' // CHECK-NEXT: | |-ParmVarDecl {{.*}} <col:15, col:19> col:19 used x 'int' // CHECK-NEXT: | |-ParmVarDecl {{.*}} <col:22, col:26> col:26 used y 'int' // CHECK-NEXT: | `-CompoundStmt {{.*}} <col:29, line:14:1> // CHECK-NEXT: | `-OMPParallelForDirective {{.*}} <line:10:1, col:25> // CHECK-NEXT: | `-CapturedStmt {{.*}} <line:11:3, line:13:7> // CHECK-NEXT: | |-CapturedDecl {{.*}} <<invalid sloc>> <invalid sloc> nothrow // CHECK-NEXT: | | |-ForStmt {{.*}} <line:11:3, line:13:7> // CHECK-NEXT: | | | |-DeclStmt {{.*}} <line:11:8, col:17> // CHECK-NEXT: | | | | `-VarDecl {{.*}} <col:8, col:16> col:12 used i 'int' cinit // CHECK-NEXT: | | | | `-IntegerLiteral {{.*}} <col:16> 'int' 0 // CHECK-NEXT: | | | |-<<<NULL>>> // CHECK-NEXT: | | | |-BinaryOperator {{.*}} <col:19, col:23> 'int' '<' // CHECK-NEXT: | | | | |-ImplicitCastExpr {{.*}} <col:19> 'int' <LValueToRValue> // CHECK-NEXT: | | | | | `-DeclRefExpr {{.*}} <col:19> 'int' lvalue Var {{.*}} 'i' 'int' // CHECK-NEXT: | | | | `-ImplicitCastExpr {{.*}} <col:23> 'int' <LValueToRValue> // CHECK-NEXT: | | | | `-DeclRefExpr {{.*}} <col:23> 'int' lvalue ParmVar {{.*}} 'x' 'int' // CHECK-NEXT: | | | |-UnaryOperator {{.*}} <col:26, col:27> 'int' postfix '++' // CHECK-NEXT: | | | | `-DeclRefExpr {{.*}} <col:26> 'int' lvalue Var {{.*}} 'i' 'int' // CHECK-NEXT: | | | `-ForStmt {{.*}} <line:12:5, line:13:7> // CHECK-NEXT: | | | |-DeclStmt {{.*}} <line:12:10, col:19> // CHECK-NEXT: | | | | `-VarDecl {{.*}} <col:10, col:18> col:14 used i 'int' cinit // CHECK-NEXT: | | | | `-IntegerLiteral {{.*}} <col:18> 'int' 0 // CHECK-NEXT: | | | |-<<<NULL>>> // CHECK-NEXT: | | | |-BinaryOperator {{.*}} <col:21, col:25> 'int' '<' // CHECK-NEXT: | | | | |-ImplicitCastExpr {{.*}} <col:21> 'int' <LValueToRValue> // CHECK-NEXT: | | | | | `-DeclRefExpr {{.*}} <col:21> 'int' lvalue Var {{.*}} 'i' 'int' // CHECK-NEXT: | | | | `-ImplicitCastExpr {{.*}} <col:25> 'int' <LValueToRValue> // CHECK-NEXT: | | | | `-DeclRefExpr {{.*}} <col:25> 'int' lvalue ParmVar {{.*}} 'y' 'int' // CHECK-NEXT: | | | |-UnaryOperator {{.*}} <col:28, col:29> 'int' postfix '++' // CHECK-NEXT: | | | | `-DeclRefExpr {{.*}} <col:28> 'int' lvalue Var {{.*}} 'i' 'int' // CHECK-NEXT: | | | `-NullStmt {{.*}} <line:13:7> // CHECK-NEXT: | | |-ImplicitParamDecl {{.*}} <line:10:1> col:1 implicit .global_tid. 'const int *const restrict' // CHECK-NEXT: | | |-ImplicitParamDecl {{.*}} <col:1> col:1 implicit .bound_tid. 'const int *const restrict' // CHECK-NEXT: | | |-ImplicitParamDecl {{.*}} <col:1> col:1 implicit __context 'struct (anonymous at {{.*}}ast-dump-openmp-parallel-for.c:10:1) *const restrict' // CHECK-NEXT: | | |-VarDecl {{.*}} <line:11:8, col:16> col:12 used i 'int' cinit // CHECK-NEXT: | | | `-IntegerLiteral {{.*}} <col:16> 'int' 0 // CHECK-NEXT: | | `-VarDecl {{.*}} <line:12:10, col:18> col:14 used i 'int' cinit // CHECK-NEXT: | | `-IntegerLiteral {{.*}} <col:18> 'int' 0 // CHECK-NEXT: | |-DeclRefExpr {{.*}} <line:11:3> 'int' lvalue ParmVar {{.*}} 'x' 'int' // CHECK-NEXT: | `-DeclRefExpr {{.*}} <line:12:25> 'int' lvalue ParmVar {{.*}} 'y' 'int' // CHECK-NEXT: |-FunctionDecl {{.*}} <line:16:1, line:21:1> line:16:6 test_three 'void (int, int)' // CHECK-NEXT: | |-ParmVarDecl {{.*}} <col:17, col:21> col:21 used x 'int' // CHECK-NEXT: | |-ParmVarDecl {{.*}} <col:24, col:28> col:28 used y 'int' // CHECK-NEXT: | `-CompoundStmt {{.*}} <col:31, line:21:1> // CHECK-NEXT: | `-OMPParallelForDirective {{.*}} <line:17:1, col:37> // CHECK-NEXT: | |-OMPCollapseClause {{.*}} <col:26, col:36> // CHECK-NEXT: | | `-ConstantExpr {{.*}} <col:35> 'int' // CHECK-NEXT: | | `-IntegerLiteral {{.*}} <col:35> 'int' 1 // CHECK-NEXT: | `-CapturedStmt {{.*}} <line:18:3, line:20:7> // CHECK-NEXT: | |-CapturedDecl {{.*}} <<invalid sloc>> <invalid sloc> nothrow // CHECK-NEXT: | | |-ForStmt {{.*}} <line:18:3, line:20:7> // CHECK-NEXT: | | | |-DeclStmt {{.*}} <line:18:8, col:17> // CHECK-NEXT: | | | | `-VarDecl {{.*}} <col:8, col:16> col:12 used i 'int' cinit // CHECK-NEXT: | | | | `-IntegerLiteral {{.*}} <col:16> 'int' 0 // CHECK-NEXT: | | | |-<<<NULL>>> // CHECK-NEXT: | | | |-BinaryOperator {{.*}} <col:19, col:23> 'int' '<' // CHECK-NEXT: | | | | |-ImplicitCastExpr {{.*}} <col:19> 'int' <LValueToRValue> // CHECK-NEXT: | | | | | `-DeclRefExpr {{.*}} <col:19> 'int' lvalue Var {{.*}} 'i' 'int' // CHECK-NEXT: | | | | `-ImplicitCastExpr {{.*}} <col:23> 'int' <LValueToRValue> // CHECK-NEXT: | | | | `-DeclRefExpr {{.*}} <col:23> 'int' lvalue ParmVar {{.*}} 'x' 'int' // CHECK-NEXT: | | | |-UnaryOperator {{.*}} <col:26, col:27> 'int' postfix '++' // CHECK-NEXT: | | | | `-DeclRefExpr {{.*}} <col:26> 'int' lvalue Var {{.*}} 'i' 'int' // CHECK-NEXT: | | | `-ForStmt {{.*}} <line:19:5, line:20:7> // CHECK-NEXT: | | | |-DeclStmt {{.*}} <line:19:10, col:19> // CHECK-NEXT: | | | | `-VarDecl {{.*}} <col:10, col:18> col:14 used i 'int' cinit // CHECK-NEXT: | | | | `-IntegerLiteral {{.*}} <col:18> 'int' 0 // CHECK-NEXT: | | | |-<<<NULL>>> // CHECK-NEXT: | | | |-BinaryOperator {{.*}} <col:21, col:25> 'int' '<' // CHECK-NEXT: | | | | |-ImplicitCastExpr {{.*}} <col:21> 'int' <LValueToRValue> // CHECK-NEXT: | | | | | `-DeclRefExpr {{.*}} <col:21> 'int' lvalue Var {{.*}} 'i' 'int' // CHECK-NEXT: | | | | `-ImplicitCastExpr {{.*}} <col:25> 'int' <LValueToRValue> // CHECK-NEXT: | | | | `-DeclRefExpr {{.*}} <col:25> 'int' lvalue ParmVar {{.*}} 'y' 'int' // CHECK-NEXT: | | | |-UnaryOperator {{.*}} <col:28, col:29> 'int' postfix '++' // CHECK-NEXT: | | | | `-DeclRefExpr {{.*}} <col:28> 'int' lvalue Var {{.*}} 'i' 'int' // CHECK-NEXT: | | | `-NullStmt {{.*}} <line:20:7> // CHECK-NEXT: | | |-ImplicitParamDecl {{.*}} <line:17:1> col:1 implicit .global_tid. 'const int *const restrict' // CHECK-NEXT: | | |-ImplicitParamDecl {{.*}} <col:1> col:1 implicit .bound_tid. 'const int *const restrict' // CHECK-NEXT: | | |-ImplicitParamDecl {{.*}} <col:1> col:1 implicit __context 'struct (anonymous at {{.*}}ast-dump-openmp-parallel-for.c:17:1) *const restrict' // CHECK-NEXT: | | |-VarDecl {{.*}} <line:18:8, col:16> col:12 used i 'int' cinit // CHECK-NEXT: | | | `-IntegerLiteral {{.*}} <col:16> 'int' 0 // CHECK-NEXT: | | `-VarDecl {{.*}} <line:19:10, col:18> col:14 used i 'int' cinit // CHECK-NEXT: | | `-IntegerLiteral {{.*}} <col:18> 'int' 0 // CHECK-NEXT: | |-DeclRefExpr {{.*}} <line:18:3> 'int' lvalue ParmVar {{.*}} 'x' 'int' // CHECK-NEXT: | `-DeclRefExpr {{.*}} <line:19:25> 'int' lvalue ParmVar {{.*}} 'y' 'int' // CHECK-NEXT: |-FunctionDecl {{.*}} <line:23:1, line:28:1> line:23:6 test_four 'void (int, int)' // CHECK-NEXT: | |-ParmVarDecl {{.*}} <col:16, col:20> col:20 used x 'int' // CHECK-NEXT: | |-ParmVarDecl {{.*}} <col:23, col:27> col:27 used y 'int' // CHECK-NEXT: | `-CompoundStmt {{.*}} <col:30, line:28:1> // CHECK-NEXT: | `-OMPParallelForDirective {{.*}} <line:24:1, col:37> // CHECK-NEXT: | |-OMPCollapseClause {{.*}} <col:26, col:36> // CHECK-NEXT: | | `-ConstantExpr {{.*}} <col:35> 'int' // CHECK-NEXT: | | `-IntegerLiteral {{.*}} <col:35> 'int' 2 // CHECK-NEXT: | `-CapturedStmt {{.*}} <line:25:3, line:27:7> // CHECK-NEXT: | |-CapturedDecl {{.*}} <<invalid sloc>> <invalid sloc> nothrow // CHECK-NEXT: | | |-ForStmt {{.*}} <line:25:3, line:27:7> // CHECK-NEXT: | | | |-DeclStmt {{.*}} <line:25:8, col:17> // CHECK-NEXT: | | | | `-VarDecl {{.*}} <col:8, col:16> col:12 used i 'int' cinit // CHECK-NEXT: | | | | `-IntegerLiteral {{.*}} <col:16> 'int' 0 // CHECK-NEXT: | | | |-<<<NULL>>> // CHECK-NEXT: | | | |-BinaryOperator {{.*}} <col:19, col:23> 'int' '<' // CHECK-NEXT: | | | | |-ImplicitCastExpr {{.*}} <col:19> 'int' <LValueToRValue> // CHECK-NEXT: | | | | | `-DeclRefExpr {{.*}} <col:19> 'int' lvalue Var {{.*}} 'i' 'int' // CHECK-NEXT: | | | | `-ImplicitCastExpr {{.*}} <col:23> 'int' <LValueToRValue> // CHECK-NEXT: | | | | `-DeclRefExpr {{.*}} <col:23> 'int' lvalue ParmVar {{.*}} 'x' 'int' // CHECK-NEXT: | | | |-UnaryOperator {{.*}} <col:26, col:27> 'int' postfix '++' // CHECK-NEXT: | | | | `-DeclRefExpr {{.*}} <col:26> 'int' lvalue Var {{.*}} 'i' 'int' // CHECK-NEXT: | | | `-ForStmt {{.*}} <line:26:5, line:27:7> // CHECK-NEXT: | | | |-DeclStmt {{.*}} <line:26:10, col:19> // CHECK-NEXT: | | | | `-VarDecl {{.*}} <col:10, col:18> col:14 used i 'int' cinit // CHECK-NEXT: | | | | `-IntegerLiteral {{.*}} <col:18> 'int' 0 // CHECK-NEXT: | | | |-<<<NULL>>> // CHECK-NEXT: | | | |-BinaryOperator {{.*}} <col:21, col:25> 'int' '<' // CHECK-NEXT: | | | | |-ImplicitCastExpr {{.*}} <col:21> 'int' <LValueToRValue> // CHECK-NEXT: | | | | | `-DeclRefExpr {{.*}} <col:21> 'int' lvalue Var {{.*}} 'i' 'int' // CHECK-NEXT: | | | | `-ImplicitCastExpr {{.*}} <col:25> 'int' <LValueToRValue> // CHECK-NEXT: | | | | `-DeclRefExpr {{.*}} <col:25> 'int' lvalue ParmVar {{.*}} 'y' 'int' // CHECK-NEXT: | | | |-UnaryOperator {{.*}} <col:28, col:29> 'int' postfix '++' // CHECK-NEXT: | | | | `-DeclRefExpr {{.*}} <col:28> 'int' lvalue Var {{.*}} 'i' 'int' // CHECK-NEXT: | | | `-NullStmt {{.*}} <line:27:7> // CHECK-NEXT: | | |-ImplicitParamDecl {{.*}} <line:24:1> col:1 implicit .global_tid. 'const int *const restrict' // CHECK-NEXT: | | |-ImplicitParamDecl {{.*}} <col:1> col:1 implicit .bound_tid. 'const int *const restrict' // CHECK-NEXT: | | |-ImplicitParamDecl {{.*}} <col:1> col:1 implicit __context 'struct (anonymous at {{.*}}ast-dump-openmp-parallel-for.c:24:1) *const restrict' // CHECK-NEXT: | | |-VarDecl {{.*}} <line:25:8, col:16> col:12 used i 'int' cinit // CHECK-NEXT: | | | `-IntegerLiteral {{.*}} <col:16> 'int' 0 // CHECK-NEXT: | | `-VarDecl {{.*}} <line:26:10, col:18> col:14 used i 'int' cinit // CHECK-NEXT: | | `-IntegerLiteral {{.*}} <col:18> 'int' 0 // CHECK-NEXT: | |-DeclRefExpr {{.*}} <line:25:3> 'int' lvalue ParmVar {{.*}} 'x' 'int' // CHECK-NEXT: | `-DeclRefExpr {{.*}} <line:26:5> 'int' lvalue ParmVar {{.*}} 'y' 'int' // CHECK-NEXT: `-FunctionDecl {{.*}} <line:30:1, line:36:1> line:30:6 test_five 'void (int, int, int)' // CHECK-NEXT: |-ParmVarDecl {{.*}} <col:16, col:20> col:20 used x 'int' // CHECK-NEXT: |-ParmVarDecl {{.*}} <col:23, col:27> col:27 used y 'int' // CHECK-NEXT: |-ParmVarDecl {{.*}} <col:30, col:34> col:34 used z 'int' // CHECK-NEXT: `-CompoundStmt {{.*}} <col:37, line:36:1> // CHECK-NEXT: `-OMPParallelForDirective {{.*}} <line:31:1, col:37> // CHECK-NEXT: |-OMPCollapseClause {{.*}} <col:26, col:36> // CHECK-NEXT: | `-ConstantExpr {{.*}} <col:35> 'int' // CHECK-NEXT: | `-IntegerLiteral {{.*}} <col:35> 'int' 2 // CHECK-NEXT: `-CapturedStmt {{.*}} <line:32:3, line:35:9> // CHECK-NEXT: |-CapturedDecl {{.*}} <<invalid sloc>> <invalid sloc> nothrow // CHECK-NEXT: | |-ForStmt {{.*}} <line:32:3, line:35:9> // CHECK-NEXT: | | |-DeclStmt {{.*}} <line:32:8, col:17> // CHECK-NEXT: | | | `-VarDecl {{.*}} <col:8, col:16> col:12 used i 'int' cinit // CHECK-NEXT: | | | `-IntegerLiteral {{.*}} <col:16> 'int' 0 // CHECK-NEXT: | | |-<<<NULL>>> // CHECK-NEXT: | | |-BinaryOperator {{.*}} <col:19, col:23> 'int' '<' // CHECK-NEXT: | | | |-ImplicitCastExpr {{.*}} <col:19> 'int' <LValueToRValue> // CHECK-NEXT: | | | | `-DeclRefExpr {{.*}} <col:19> 'int' lvalue Var {{.*}} 'i' 'int' // CHECK-NEXT: | | | `-ImplicitCastExpr {{.*}} <col:23> 'int' <LValueToRValue> // CHECK-NEXT: | | | `-DeclRefExpr {{.*}} <col:23> 'int' lvalue ParmVar {{.*}} 'x' 'int' // CHECK-NEXT: | | |-UnaryOperator {{.*}} <col:26, col:27> 'int' postfix '++' // CHECK-NEXT: | | | `-DeclRefExpr {{.*}} <col:26> 'int' lvalue Var {{.*}} 'i' 'int' // CHECK-NEXT: | | `-ForStmt {{.*}} <line:33:5, line:35:9> // CHECK-NEXT: | | |-DeclStmt {{.*}} <line:33:10, col:19> // CHECK-NEXT: | | | `-VarDecl {{.*}} <col:10, col:18> col:14 used i 'int' cinit // CHECK-NEXT: | | | `-IntegerLiteral {{.*}} <col:18> 'int' 0 // CHECK-NEXT: | | |-<<<NULL>>> // CHECK-NEXT: | | |-BinaryOperator {{.*}} <col:21, col:25> 'int' '<' // CHECK-NEXT: | | | |-ImplicitCastExpr {{.*}} <col:21> 'int' <LValueToRValue> // CHECK-NEXT: | | | | `-DeclRefExpr {{.*}} <col:21> 'int' lvalue Var {{.*}} 'i' 'int' // CHECK-NEXT: | | | `-ImplicitCastExpr {{.*}} <col:25> 'int' <LValueToRValue> // CHECK-NEXT: | | | `-DeclRefExpr {{.*}} <col:25> 'int' lvalue ParmVar {{.*}} 'y' 'int' // CHECK-NEXT: | | |-UnaryOperator {{.*}} <col:28, col:29> 'int' postfix '++' // CHECK-NEXT: | | | `-DeclRefExpr {{.*}} <col:28> 'int' lvalue Var {{.*}} 'i' 'int' // CHECK-NEXT: | | `-ForStmt {{.*}} <line:34:7, line:35:9> // CHECK-NEXT: | | |-DeclStmt {{.*}} <line:34:12, col:21> // CHECK-NEXT: | | | `-VarDecl {{.*}} <col:12, col:20> col:16 used i 'int' cinit // CHECK-NEXT: | | | `-IntegerLiteral {{.*}} <col:20> 'int' 0 // CHECK-NEXT: | | |-<<<NULL>>> // CHECK-NEXT: | | |-BinaryOperator {{.*}} <col:23, col:27> 'int' '<' // CHECK-NEXT: | | | |-ImplicitCastExpr {{.*}} <col:23> 'int' <LValueToRValue> // CHECK-NEXT: | | | | `-DeclRefExpr {{.*}} <col:23> 'int' lvalue Var {{.*}} 'i' 'int' // CHECK-NEXT: | | | `-ImplicitCastExpr {{.*}} <col:27> 'int' <LValueToRValue> // CHECK-NEXT: | | | `-DeclRefExpr {{.*}} <col:27> 'int' lvalue ParmVar {{.*}} 'z' 'int' // CHECK-NEXT: | | |-UnaryOperator {{.*}} <col:30, col:31> 'int' postfix '++' // CHECK-NEXT: | | | `-DeclRefExpr {{.*}} <col:30> 'int' lvalue Var {{.*}} 'i' 'int' // CHECK-NEXT: | | `-NullStmt {{.*}} <line:35:9> // CHECK-NEXT: | |-ImplicitParamDecl {{.*}} <line:31:1> col:1 implicit .global_tid. 'const int *const restrict' // CHECK-NEXT: | |-ImplicitParamDecl {{.*}} <col:1> col:1 implicit .bound_tid. 'const int *const restrict' // CHECK-NEXT: | |-ImplicitParamDecl {{.*}} <col:1> col:1 implicit __context 'struct (anonymous at {{.*}}ast-dump-openmp-parallel-for.c:31:1) *const restrict' // CHECK-NEXT: | |-VarDecl {{.*}} <line:32:8, col:16> col:12 used i 'int' cinit // CHECK-NEXT: | | `-IntegerLiteral {{.*}} <col:16> 'int' 0 // CHECK-NEXT: | |-VarDecl {{.*}} <line:33:10, col:18> col:14 used i 'int' cinit // CHECK-NEXT: | | `-IntegerLiteral {{.*}} <col:18> 'int' 0 // CHECK-NEXT: | `-VarDecl {{.*}} <line:34:12, col:20> col:16 used i 'int' cinit // CHECK-NEXT: | `-IntegerLiteral {{.*}} <col:20> 'int' 0 // CHECK-NEXT: |-DeclRefExpr {{.*}} <line:32:3> 'int' lvalue ParmVar {{.*}} 'x' 'int' // CHECK-NEXT: |-DeclRefExpr {{.*}} <line:33:5> 'int' lvalue ParmVar {{.*}} 'y' 'int' // CHECK-NEXT: `-DeclRefExpr {{.*}} <line:34:27> 'int' lvalue ParmVar {{.*}} 'z' 'int'
lndsr.c
#include <stdio.h> #include <stdlib.h> #include <sys/stat.h> #include <string.h> #include <unistd.h> #include <math.h> #include "lndsr.h" #include "keyvalue.h" #include "const.h" #include "param.h" #include "input.h" #include "prwv_input.h" #include "lut.h" #include "output.h" #include "sr.h" #include "ar.h" #include "bool.h" #include "error.h" #include "clouds.h" #include "read_grib_tools.h" #include "sixs_runs.h" #define AERO_NB_BANDS 3 #define SP_INDEX 0 #define WV_INDEX 1 #define ATEMP_INDEX 2 #define OZ_INDEX 0 #define DEBUG_FLAG 0 /* #define DEBUG_AR 0 */ /* #define DEBUG_CLD 1 */ /* DEM Definition: U_char format, 1 count = 100 meters */ /* 0 = 0 meters */ #define DEMFILE "CMGDEM.hdf" #define DEM_NBLAT 3600 #define DEM_DLAT 0.05 #define DEM_LATMIN (-90.0) #define DEM_LATMAX 90.0 #define DEM_NBLON 7200 #define DEM_DLON 0.05 #define DEM_LONMIN (-180.0) #define DEM_LONMAX 180.0 #define P_DFTVALUE 1013.0 /* Type definitions */ atmos_t atmos_coef; #ifdef DEBUG_AR FILE *fd_ar_diags = NULL; int diags_il_ar; #endif #ifdef DEBUG_CLD FILE *fd_cld_diags = NULL; #endif /* reading the DEM in hdf */ int32 sds_file_id,sds_id,status; char sds_name[256]; int32 sds_index; int32 dim_sizes[2],start[2],stride[2],edges[2]; int32 data_type,n_attrs,rank; /* Prototypes */ #ifndef HPUX #define chand chand_ #define csalbr csalbr_ #endif void chand(float *phi,float *muv,float *mus,float *tau_ray,float *actual_rho_ray); void csalbr(float *tau_ray,float *actual_S_r); int update_atmos_coefs(atmos_t *atmos_coef,Ar_gridcell_t *ar_gridcell, sixs_tables_t *sixs_tables,int ***line_ar,Lut_t *lut,int nband, int bkgd_aerosol); int update_gridcell_atmos_coefs(int irow,int icol,atmos_t *atmos_coef,Ar_gridcell_t *ar_gridcell, sixs_tables_t *sixs_tables,int **line_ar,Lut_t *lut,int nband, int bkgd_aerosol); float calcuoz(short jday,float flat); float get_dem_spres(short *dem,float lat,float lon); #ifdef SAVE_6S_RESULTS #define SIXS_RESULTS_FILENAME "SIXS_RUN_RESULTS.TXT" int read_6S_results_from_file(char *filename,sixs_tables_t *sixs_tables); int write_6S_results_to_file(char *filename,sixs_tables_t *sixs_tables); #endif void sun_angles (short jday,float gmt,float flat,float flon,float *ts,float *fs); /* Functions */ int main (int argc, char *argv[]) { Param_t *param = NULL; Input_t *input = NULL, *input_b6 = NULL; InputPrwv_t *prwv_input = NULL; InputOzon_t *ozon_input = NULL; Lut_t *lut = NULL; Output_t *output = NULL; int i,j,il, is,ib,i_aot,j_aot,ifree; int il_start, il_end, il_ar, il_region, is_ar; int16 *line_out[NBAND_SR_MAX]; int16 *line_out_buf = NULL; int16 ***line_in = NULL; int16 **line_in_band_buf = NULL; int16 *line_in_buf = NULL; int ***line_ar = NULL; int **line_ar_band_buf = NULL; int *line_ar_buf = NULL; int16** b6_line = NULL; int16* b6_line_buf = NULL; float *atemp_line = NULL; uint8** qa_line = NULL; uint8* qa_line_buf = NULL; char **ddv_line = NULL; char *ddv_line_buf = NULL; char **rot_cld[3],**ptr_rot_cld[3],**ptr_tmp_cld; char **rot_cld_block_buf = NULL; char *rot_cld_buf = NULL; char envi_file[STR_SIZE]; /* name of the output ENVI header file */ char *cptr = NULL; /* pointer to the file extension */ bool refl_is_fill; Sr_stats_t sr_stats; Ar_stats_t ar_stats; Ar_gridcell_t ar_gridcell; float *prwv_in[NBAND_PRWV_MAX]; float *prwv_in_buf = NULL; int *ozon_in = NULL; float corrected_sun_az; /* (degrees) sun azimuth angle has been corrected for polar scenes that are ascending or flipped */ int nbpts; int inter_aot; /* atmospheric opacity */ float scene_gmt; Geoloc_t *space = NULL; Space_def_t space_def; char *dem_name = NULL; Img_coord_float_t img; Img_coord_int_t loc; Geo_coord_t geo; t_ncep_ancillary anc_O3,anc_WV,anc_SP,anc_ATEMP; double sum_spres_anc,sum_spres_dem; int nb_spres_anc,nb_spres_dem; float tmpflt_arr[4]; double coef; int tmpint; int osize; int debug_flag; sixs_tables_t sixs_tables; float center_lat,center_lon; char tmpfilename[128]; FILE *fdtmp/*, *fdtmp2 */; int tmpid; /* file ID for temporary file (ID not used) */ short *dem_array; int dem_available; cld_diags_t cld_diags; float flat,flon/*,fts,ffs*/; double delta_y,delta_x; float adjust_north; float sum_value,sumsq_value; int no_ozone_file; short jday; Espa_internal_meta_t xml_metadata; /* XML metadata structure */ Espa_global_meta_t *gmeta = NULL; /* pointer to global meta */ Envi_header_t envi_hdr; /* output ENVI header information */ /* Vermote additional variable declaration for the cloud mask May 29 2007 */ float t6s_seuil; debug_flag= DEBUG_FLAG; no_ozone_file=0; /* Read the parameters from the command-line and input parameter file */ param = GetParam(argc, argv); if (param == NULL) EXIT_ERROR("getting runtime parameters", "main"); printf ("\nRunning lndsr ....\n"); /* Validate the input metadata file */ if (validate_xml_file (param->input_xml_file_name) != SUCCESS) { /* Error messages already written */ EXIT_ERROR("Unable to validate XML file", "main"); } /* Initialize the metadata structure */ init_metadata_struct (&xml_metadata); /* Parse the metadata file into our internal metadata structure; also allocates space as needed for various pointers in the global and band metadata */ if (parse_metadata (param->input_xml_file_name, &xml_metadata) != SUCCESS) { /* Error messages already written */ EXIT_ERROR("parsing XML file", "main"); } gmeta = &xml_metadata.global; /* pointer to global meta */ /* Open input files; grab QA band for reflectance band */ input = OpenInput(&xml_metadata, false /* not thermal */); if (input == NULL) EXIT_ERROR("bad input file", "main"); input_b6 = OpenInput(&xml_metadata, true /* thermal */); if (input_b6 == NULL) { param->thermal_band = false; printf ("WARNING: no TOA brightness temp band available. " "Processing without."); } else param->thermal_band = true; if (param->num_prwv_files > 0 && param->num_ncep_files > 0) { EXIT_ERROR("both PRWV and PRWV_FIL files specified", "main"); } /* The surface reflectance algorithm cannot be implemented for solar zenith angles greater than 76 degrees. Need to flag if the current scene falls into that category. */ if (input->meta.sun_zen * DEG > 76.0) { EXIT_ERROR ("Solar zenith angle is too large to allow for surface " "reflectance processing. Corrections must be limited to top-of-" "atmosphere reflectance and brightness temperature corrections. " "Use the --process_sr=False command-line argument when running " "do_ledaps.py.", "main"); } /* Open prwv input file */ if (param->num_prwv_files > 0) { prwv_input = OpenInputPrwv(param->prwv_file_name); if (prwv_input==NULL) EXIT_ERROR("bad input prwv file","main"); osize= 3 * (prwv_input->size.ntime*prwv_input->size.nlat* prwv_input->size.nlon); prwv_in_buf = calloc(osize, sizeof(float)); if (prwv_in_buf == NULL) EXIT_ERROR("allocating input prwv buffer", "main"); prwv_in[0] = prwv_in_buf; for (ib = 1; ib < prwv_input->nband; ib++) prwv_in[ib] = prwv_in[ib - 1] + (prwv_input->size.ntime* prwv_input->size.nlat*prwv_input->size.nlon); for (ib = 0; ib < prwv_input->nband; ib++) { if (!GetInputPrwv(prwv_input, ib, prwv_in[ib])) EXIT_ERROR("reading input prwv data", "main"); } /**** ozone ***/ if ( param->num_ozon_files<1 ) no_ozone_file=1; else { ozon_input = OpenInputOzon(param->ozon_file_name); if (ozon_input==NULL) EXIT_ERROR("bad input ozon file", "main"); osize= (ozon_input->size.ntime*ozon_input->size.nlat* ozon_input->size.nlon); ozon_in = calloc(osize, sizeof(int)); if (ozon_in == NULL) EXIT_ERROR("allocating input ozone buffer", "main"); if (!GetInputOzon(ozon_input, 0, ozon_in)) EXIT_ERROR("reading input ozone data", "main"); } } /* Get Lookup table, based on reflectance information */ lut = GetLut(input->nband, &input->meta, &input->size); if (lut == NULL) EXIT_ERROR("bad lut file", "main"); /* Get geolocation space definition */ if (!get_geoloc_info(&xml_metadata, &space_def)) EXIT_ERROR("getting space metadata from XML file", "main"); space = setup_mapping(&space_def); if (space == NULL) EXIT_ERROR("getting setting up geolocation mapping", "main"); printf ("Number of input bands: %d\n", input->nband); printf ("Number of input lines: %d\n", input->size.l); printf ("Number of input samples: %d\n", input->size.s); /* If the scene is an ascending polar scene (flipped upside down), then the solar azimuth needs to be adjusted by 180 degrees. The scene in this case would be north down and the solar azimuth is based on north being up. */ corrected_sun_az = input->meta.sun_az * DEG; if (gmeta->ul_corner[0] < gmeta->lr_corner[0]) { corrected_sun_az += 180.0; if (corrected_sun_az > 360.0) corrected_sun_az -= 360.0; printf ("Polar or ascending scene. Readjusting solar azimuth by " "180 degrees.\n New value: %f radians (%f degrees)\n", corrected_sun_az*RAD, corrected_sun_az); } /* Open the output files and set up the necessary information for appending to the XML file */ output = OpenOutput(&xml_metadata, input, param, lut); if (output == NULL) EXIT_ERROR("opening output file", "main"); /* Open diagnostics files if needed */ #ifdef DEBUG_AR strcpy(tmpfilename,param->output_file_name); strcat(tmpfilename,".DEBUG_AR"); fd_ar_diags=fopen(tmpfilename,"w"); if (fd_ar_diags != NULL) { fprintf(fd_ar_diags,"cell_row cell_col total_nb_samples avg_b1 std_b1 avg_b2 std_b2 avg_b3 std_b3 avg_b7 std_b7 szen vzen relaz wv ozone spres fraction_water fraction_clouds fraction_cldshadow fraction_snow spres_ratio tau_ray corrected_T_ray corrected_Sr measured_rho_b1 simulated_b1_01 simulated_b1_02 simulated_b1_03 simulated_b1_04 simulated_b1_05 simulated_b1_06 simulated_b1_07 simulated_b1_08 simulated_b1_09 simulated_b1_10 simulated_b1_11 simulated_b1_12 simulated_b1_13 simulated_b1_14 simulated_b1_15 aot_index coef aot_value new_aot ratio_neg_red\n"); } #endif #ifdef DEBUG_CLD strcpy(tmpfilename,"tempfile.DEBUG_CLD"); fd_cld_diags=fopen(tmpfilename,"w"); if (fd_cld_diags != NULL) { fprintf(fd_cld_diags,"cell_row cell_col nb_samples airtemp_2m " "avg_t6_clear std_t6_clear avg_b7_clear std_b7_clear\n"); } #endif /* Allocate memory for input lines */ line_in = calloc(lut->ar_region_size.l, sizeof(int16 **)); if (line_in == NULL) EXIT_ERROR("allocating input line buffer (a)", "main"); line_in_band_buf = calloc(lut->ar_region_size.l * input->nband, sizeof(int16 *)); if (line_in_band_buf == NULL) EXIT_ERROR("allocating input line buffer (b)", "main"); line_in_buf = calloc(input->size.s * lut->ar_region_size.l * input->nband, sizeof(int16)); if (line_in_buf == NULL) EXIT_ERROR("allocating input line buffer (c)", "main"); for (il = 0; il < lut->ar_region_size.l; il++) { line_in[il] = line_in_band_buf; line_in_band_buf += input->nband; for (ib = 0; ib < input->nband; ib++) { line_in[il][ib] = line_in_buf; line_in_buf += input->size.s; } } /* Allocate memory for qa line */ qa_line = calloc(lut->ar_region_size.l,sizeof(uint8 *)); if (qa_line == NULL) EXIT_ERROR("allocating qa line", "main"); qa_line_buf = calloc(input->size.s * lut->ar_region_size.l, sizeof(uint8)); if (qa_line_buf == NULL) EXIT_ERROR("allocating qa line buffer", "main"); for (il = 0; il < lut->ar_region_size.l; il++) { qa_line[il]=qa_line_buf; qa_line_buf += input->size.s; } /* Allocate memory for one band 6 line */ if (param->thermal_band) { b6_line = calloc(lut->ar_region_size.l,sizeof(int16 *)); if (b6_line == NULL) EXIT_ERROR("allocating b6 line", "main"); b6_line_buf = calloc(input_b6->size.s * lut->ar_region_size.l, sizeof(int16)); if (b6_line_buf == NULL) EXIT_ERROR("allocating b6 line buffer", "main"); for (il = 0; il < lut->ar_region_size.l; il++) { b6_line[il]=b6_line_buf; b6_line_buf += input_b6->size.s; } } /* Allocate memory for one air temperature line */ atemp_line = calloc(input->size.s,sizeof(float)); if (atemp_line == NULL) EXIT_ERROR("allocating atemp line", "main"); /* Allocate memory for ddv line */ ddv_line = calloc(lut->ar_region_size.l,sizeof(char *)); if (ddv_line == NULL) EXIT_ERROR("allocating ddv line", "main"); ddv_line_buf = calloc(input->size.s * lut->ar_region_size.l, sizeof(char)); if (ddv_line_buf == NULL) EXIT_ERROR("allocating ddv line buffer", "main"); for (il = 0; il < lut->ar_region_size.l; il++) { ddv_line[il]=ddv_line_buf; ddv_line_buf += input->size.s; } /* Allocate memory for rotating cloud buffer */ rot_cld_buf=calloc(input->size.s*lut->ar_region_size.l*3, sizeof(char)); if (rot_cld_buf == NULL) EXIT_ERROR("allocating roatting cloud buffer (a)", "main"); rot_cld_block_buf=calloc(lut->ar_region_size.l*3, sizeof(char *)); if (rot_cld_block_buf == NULL) EXIT_ERROR("allocating rotating cloud buffer (b)", "main"); for (ib = 0; ib < 3; ib++) { rot_cld[ib]=rot_cld_block_buf; rot_cld_block_buf += lut->ar_region_size.l; for (il = 0; il < lut->ar_region_size.l; il++) { rot_cld[ib][il]=rot_cld_buf; rot_cld_buf+=input->size.s; } } /* Allocate memory for ar_gridcell */ ar_gridcell.nbrows=lut->ar_size.l; ar_gridcell.nbcols=lut->ar_size.s; ar_gridcell.lat=calloc(lut->ar_size.s * lut->ar_size.l, sizeof(float)); if (ar_gridcell.lat == NULL) EXIT_ERROR("allocating ar_gridcell.lat", "main"); ar_gridcell.lon=calloc(lut->ar_size.s * lut->ar_size.l, sizeof(float)); if (ar_gridcell.lon == NULL) EXIT_ERROR("allocating ar_gridcell.lon", "main"); ar_gridcell.sun_zen=calloc(lut->ar_size.s * lut->ar_size.l, sizeof(float)); if (ar_gridcell.sun_zen == NULL) EXIT_ERROR("allocating ar_gridcell.sun_zen", "main"); ar_gridcell.view_zen=calloc(lut->ar_size.s * lut->ar_size.l,sizeof(float)); if (ar_gridcell.view_zen == NULL) EXIT_ERROR("allocating ar_gridcell.view_zen", "main"); ar_gridcell.rel_az=calloc(lut->ar_size.s * lut->ar_size.l,sizeof(float)); if (ar_gridcell.rel_az == NULL) EXIT_ERROR("allocating ar_gridcell.rel_az", "main"); ar_gridcell.wv=calloc(lut->ar_size.s * lut->ar_size.l,sizeof(float)); if (ar_gridcell.wv == NULL) EXIT_ERROR("allocating ar_gridcell.wv", "main"); ar_gridcell.spres=calloc(lut->ar_size.s * lut->ar_size.l,sizeof(float)); if (ar_gridcell.spres == NULL) EXIT_ERROR("allocating ar_gridcell.spres", "main"); ar_gridcell.ozone=calloc(lut->ar_size.s * lut->ar_size.l,sizeof(float)); if (ar_gridcell.ozone == NULL) EXIT_ERROR("allocating ar_gridcell.ozone", "main"); ar_gridcell.spres_dem=calloc(lut->ar_size.s * lut->ar_size.l,sizeof(float)); if (ar_gridcell.spres_dem == NULL) EXIT_ERROR("allocating ar_gridcell.spres_dem", "main"); /* Allocate memory for output lines */ line_out_buf = calloc(output->size.s * output->nband_out, sizeof(int16)); if (line_out_buf == NULL) EXIT_ERROR("allocating output line buffer", "main"); line_out[0] = line_out_buf; for (ib = 1; ib < output->nband_out; ib++) line_out[ib] = line_out[ib - 1] + output->size.s; /* Allocate memory for the aerosol lines */ line_ar = calloc(lut->ar_size.l, sizeof(int **)); if (line_ar == NULL) EXIT_ERROR("allocating aerosol line buffer (a)", "main"); line_ar_band_buf = calloc(lut->ar_size.l * AERO_NB_BANDS, sizeof(int *)); if (line_ar_band_buf == NULL) EXIT_ERROR("allocating aerosol line buffer (b)", "main"); line_ar_buf = calloc(lut->ar_size.l * lut->ar_size.s * AERO_NB_BANDS, sizeof(int)); if (line_ar_buf == NULL) EXIT_ERROR("allocating aerosol line buffer (c)", "main"); for (il = 0; il < lut->ar_size.l; il++) { line_ar[il] = line_ar_band_buf; line_ar_band_buf += AERO_NB_BANDS; for (ib = 0; ib < AERO_NB_BANDS; ib++) { line_ar[il][ib] = line_ar_buf; line_ar_buf += lut->ar_size.s; } } /* Initialize the statistics */ ar_stats.nfill = 0; ar_stats.first = true; for (ib = 0; ib < output->nband_out; ib++) { sr_stats.nfill[ib] = 0; sr_stats.nsatu[ib] = 0; sr_stats.nout_range[ib] = 0; sr_stats.first[ib] = true; } /**** Get center lat lon and deviation from true north ****/ img.l=input->size.l/2.; img.s=input->size.s/2.; img.is_fill=false; if (!from_space(space, &img, &geo)) EXIT_ERROR("mapping from space (0)", "main"); center_lat=geo.lat * DEG; center_lon=geo.lon * DEG; /* Compute scene gmt time */ if ( (input->meta.acq_date.hour !=0 ) || (input->meta.acq_date.minute != 0 ) || (input->meta.acq_date.second !=0)) scene_gmt=input->meta.acq_date.hour + input->meta.acq_date.minute/60. + input->meta.acq_date.second/3600.; else scene_gmt=10.5-center_lon/15.; if ( scene_gmt < 0.) scene_gmt=scene_gmt+24.; printf ("Acquisition Time: %02d:%02d:%fZ\n", input->meta.acq_date.hour, input->meta.acq_date.minute, input->meta.acq_date.second); /* Read PRWV Data */ if ( param->num_prwv_files > 0 ) { if (!get_prwv_anc(&anc_SP,prwv_input,prwv_in[SP_INDEX],SP_INDEX)) EXIT_ERROR("Can't get PRWV SP data","main"); if (!get_prwv_anc(&anc_WV,prwv_input,prwv_in[WV_INDEX],WV_INDEX)) EXIT_ERROR("Can't get PRWV WV data","main"); if (!get_prwv_anc(&anc_ATEMP,prwv_input,prwv_in[ATEMP_INDEX], ATEMP_INDEX)) EXIT_ERROR("Can't get PRWV ATEMP data","main"); if (!no_ozone_file) if (!get_ozon_anc(&anc_O3,ozon_input,ozon_in,OZ_INDEX)) EXIT_ERROR("Can't get OZONE data","main"); } else if ( param->num_ncep_files > 0 ) { anc_O3.data[0]=NULL; anc_O3.data[1]=NULL; anc_O3.data[2]=NULL; anc_O3.data[3]=NULL; anc_O3.nblayers=4; anc_O3.timeres=6; strcpy (anc_O3.source, "N/A"); strcpy(anc_O3.filename[0],param->ncep_file_name[0]); strcpy(anc_O3.filename[1],param->ncep_file_name[1]); strcpy(anc_O3.filename[2],param->ncep_file_name[2]); strcpy(anc_O3.filename[3],param->ncep_file_name[3]); if (read_grib_anc(&anc_O3,TYPE_OZONE_DATA)) EXIT_ERROR("Can't read NCEP Ozone data","main"); anc_WV.data[0]=NULL; anc_WV.data[1]=NULL; anc_WV.data[2]=NULL; anc_WV.data[3]=NULL; anc_WV.nblayers=4; anc_WV.timeres=6; strcpy (anc_WV.source, "N/A"); strcpy(anc_WV.filename[0],param->ncep_file_name[0]); strcpy(anc_WV.filename[1],param->ncep_file_name[1]); strcpy(anc_WV.filename[2],param->ncep_file_name[2]); strcpy(anc_WV.filename[3],param->ncep_file_name[3]); if (read_grib_anc(&anc_WV,TYPE_WV_DATA)) EXIT_ERROR("Can't read NCEP WV data","main"); anc_SP.data[0]=NULL; anc_SP.data[1]=NULL; anc_SP.data[2]=NULL; anc_SP.data[3]=NULL; anc_SP.nblayers=4; anc_SP.timeres=6; strcpy (anc_SP.source, "N/A"); strcpy(anc_SP.filename[0],param->ncep_file_name[0]); strcpy(anc_SP.filename[1],param->ncep_file_name[1]); strcpy(anc_SP.filename[2],param->ncep_file_name[2]); strcpy(anc_SP.filename[3],param->ncep_file_name[3]); if (read_grib_anc(&anc_SP,TYPE_SP_DATA)) EXIT_ERROR("Can't read NCEP SP data","main"); anc_ATEMP.data[0]=NULL; anc_ATEMP.data[1]=NULL; anc_ATEMP.data[2]=NULL; anc_ATEMP.data[3]=NULL; anc_ATEMP.nblayers=4; anc_ATEMP.timeres=6; strcpy (anc_ATEMP.source, "N/A"); strcpy(anc_ATEMP.filename[0],param->ncep_file_name[0]); strcpy(anc_ATEMP.filename[1],param->ncep_file_name[1]); strcpy(anc_ATEMP.filename[2],param->ncep_file_name[2]); strcpy(anc_ATEMP.filename[3],param->ncep_file_name[3]); if (read_grib_anc(&anc_ATEMP,TYPE_ATEMP_DATA)) EXIT_ERROR("Can't read NCEP SP data","main"); } else { EXIT_ERROR("No input NCEP or PRWV data specified","main"); } /* Convert the units */ /* convert Pascals into millibars (divide by 100) */ for (i=0;i<anc_SP.nblayers;i++) for (j=0;j<anc_SP.nbrows*anc_SP.nbcols;j++) anc_SP.data[i][j] *= 0.01; /* convert original PRWV kg/m2 into g/cm2 (divide by 10) */ for (i=0;i<anc_WV.nblayers;i++) for (j=0;j<anc_WV.nbrows*anc_WV.nbcols;j++) anc_WV.data[i][j] *= 0.1; /* convert O3 to cm-atm (divide by 1000) */ if (!no_ozone_file) { for (i=0;i<anc_O3.nblayers;i++) for (j=0;j<anc_O3.nbrows*anc_O3.nbcols;j++) anc_O3.data[i][j] *= 0.001; } /* read DEM file */ dem_name= (char*)(param->dem_flag ? param->dem_file : DEMFILE ); /* Open file for SD access */ sds_file_id = SDstart((char *)dem_name, DFACC_RDONLY); if (sds_file_id == HDF_ERROR) { EXIT_ERROR("opening dem_file", "OpenDem"); } sds_index=0; sds_id= SDselect(sds_file_id,sds_index); status= SDgetinfo(sds_id, sds_name, &rank, dim_sizes, &data_type,&n_attrs); start[0]=0; start[1]=0; edges[0]=3600; /* number of lines in the DEM data */ edges[1]=7200; /* number of samples in the DEM data */ stride[0]=1; stride[1]=1; dem_array=(short *)malloc(DEM_NBLAT*DEM_NBLON*sizeof(short)); status=SDreaddata(sds_id,start, stride, edges,dem_array); if (status != 0 ) { printf("Fatal error DEM file not read\n"); exit(EXIT_FAILURE); } dem_available=1; /* Print the ancillary metadata info */ if ( debug_flag ) { print_anc_data(&anc_SP,"SP_DATA"); print_anc_data(&anc_WV,"WV_DATA"); print_anc_data(&anc_ATEMP,"ATEMP_DATA"); if (!no_ozone_file) print_anc_data(&anc_O3,"OZONE_DATA"); } print_anc_data(&anc_O3,"OZONE_DATA"); /**** Get center lat lon and deviation from true north ****/ img.l=input->size.l/2.; img.s=input->size.s/2.; img.is_fill=false; if (!from_space(space, &img, &geo)) EXIT_ERROR("mapping from space (0)", "main"); center_lat=geo.lat * DEG; center_lon=geo.lon * DEG; printf ("(y0,x0)=(%d,%d) (lat0,lon0)=(%f,%f)\n", (int)img.l,(int)img.s,(float)(geo.lat * DEG),(float)(geo.lon * DEG)); delta_y=img.l; delta_x=img.s; img.l=input->size.l/2.-100.; img.s=input->size.s/2.; img.is_fill=false; if (!from_space(space, &img, &geo)) EXIT_ERROR("mapping from space (0)", "main"); geo.lon=center_lon*RAD; geo.is_fill=false; if (!to_space(space, &geo, &img)) EXIT_ERROR("mapping to space (0)", "main"); delta_y = delta_y - img.l; delta_x = img.s - delta_x; adjust_north=(float)(atan(delta_x/delta_y)*DEG); printf("True North adjustment = %f\n",adjust_north); #ifdef SAVE_6S_RESULTS if (read_6S_results_from_file(SIXS_RESULTS_FILENAME,&sixs_tables)) { #endif /**** Run 6S and compute atmcor params ****/ /* printf ("DEBUG: Interpolating WV at scene center ...\n"); */ interpol_spatial_anc(&anc_WV,center_lat,center_lon,tmpflt_arr); tmpint=(int)(scene_gmt/anc_WV.timeres); if (tmpint>=(anc_WV.nblayers-1)) tmpint=anc_WV.nblayers-2; coef=(double)(scene_gmt-anc_WV.time[tmpint])/anc_WV.timeres; sixs_tables.uwv=(1.-coef)*tmpflt_arr[tmpint]+coef*tmpflt_arr[tmpint+1]; if (!no_ozone_file) { /* printf ("DEBUG: Interpolating ozone at scene center ...\n"); */ interpol_spatial_anc(&anc_O3,center_lat,center_lon,tmpflt_arr); tmpint=(int)(scene_gmt/anc_O3.timeres); if ( anc_O3.nblayers> 1 ){ if (tmpint>=(anc_O3.nblayers-1))tmpint=anc_O3.nblayers-2; coef=(double)(scene_gmt-anc_O3.time[tmpint])/anc_O3.timeres; sixs_tables.uoz=(1.-coef)*tmpflt_arr[tmpint]+ coef*tmpflt_arr[tmpint+1]; } else { sixs_tables.uoz=tmpflt_arr[tmpint]; } } else { jday=(short)input->meta.acq_date.doy; sixs_tables.uoz=calcuoz(jday,(float)center_lat); } sixs_tables.target_alt=0.; /* target altitude in km (sea level) */ sixs_tables.sza=input->meta.sun_zen*DEG; sixs_tables.phi=corrected_sun_az; sixs_tables.vza=0.; sixs_tables.month=9; sixs_tables.day=15; sixs_tables.srefl=0.14; /* printf ("Center : Lat = %7.2f Lon = %7.2f \n",center_lat,center_lon); printf (" O3 = %7.2f SP = %7.2f WV = %7.2f\n",\ sixs_tables.uoz,tmpflt,sixs_tables.uwv); */ switch (input->meta.inst) { case INST_TM: sixs_tables.Inst=SIXS_INST_TM; break; case INST_ETM: sixs_tables.Inst=SIXS_INST_ETM; break; default: EXIT_ERROR("Unknown Instrument", "main"); } create_6S_tables(&sixs_tables, &input->meta); #ifdef SAVE_6S_RESULTS write_6S_results_to_file(SIXS_RESULTS_FILENAME,&sixs_tables); } #endif /*** interpolate ancillary data for AR grid cells ***/ img.is_fill=false; sum_spres_anc=0.; sum_spres_dem=0.; nb_spres_anc=0; nb_spres_dem=0; for (il_ar = 0; il_ar < lut->ar_size.l;il_ar++) { img.l=il_ar*lut->ar_region_size.l+lut->ar_region_size.l/2.; for (is_ar=0;is_ar < lut->ar_size.s; is_ar++) { img.s=is_ar*lut->ar_region_size.s+lut->ar_region_size.s/2.; if (!from_space(space, &img, &geo)) EXIT_ERROR("mapping from space (1)", "main"); ar_gridcell.lat[il_ar*lut->ar_size.s+is_ar]=geo.lat * DEG; ar_gridcell.lon[il_ar*lut->ar_size.s+is_ar]=geo.lon * DEG; ar_gridcell.sun_zen[il_ar*lut->ar_size.s+is_ar]= input->meta.sun_zen*DEG; ar_gridcell.view_zen[il_ar*lut->ar_size.s+is_ar]=3.5; ar_gridcell.rel_az[il_ar*lut->ar_size.s+is_ar]=corrected_sun_az; interpol_spatial_anc(&anc_WV, ar_gridcell.lat[il_ar*lut->ar_size.s+is_ar], ar_gridcell.lon[il_ar*lut->ar_size.s+is_ar],tmpflt_arr); tmpint=(int)(scene_gmt/anc_WV.timeres); if (tmpint>=(anc_WV.nblayers-1)) tmpint=anc_WV.nblayers-2; coef=(double)(scene_gmt-anc_WV.time[tmpint])/anc_WV.timeres; ar_gridcell.wv[il_ar*lut->ar_size.s+is_ar]=(1.-coef)* tmpflt_arr[tmpint]+coef*tmpflt_arr[tmpint+1]; if (!no_ozone_file) { interpol_spatial_anc(&anc_O3, ar_gridcell.lat[il_ar*lut->ar_size.s+is_ar], ar_gridcell.lon[il_ar*lut->ar_size.s+is_ar],tmpflt_arr); tmpint=(int)(scene_gmt/anc_O3.timeres); if ( anc_O3.nblayers> 1 ){ if (tmpint>=(anc_O3.nblayers-1)) tmpint=anc_O3.nblayers-2; coef=(double)(scene_gmt-anc_O3.time[tmpint])/anc_O3.timeres; ar_gridcell.ozone[il_ar*lut->ar_size.s+is_ar]=(1.-coef)* tmpflt_arr[tmpint]+coef*tmpflt_arr[tmpint+1]; } else { ar_gridcell.ozone[il_ar*lut->ar_size.s+is_ar]= tmpflt_arr[tmpint]; } } else { jday=(short)input->meta.acq_date.doy; ar_gridcell.ozone[il_ar*lut->ar_size.s+is_ar]=calcuoz(jday, (float)ar_gridcell.lat[il_ar*lut->ar_size.s+is_ar]); } interpol_spatial_anc(&anc_SP, ar_gridcell.lat[il_ar*lut->ar_size.s+is_ar], ar_gridcell.lon[il_ar*lut->ar_size.s+is_ar],tmpflt_arr); tmpint=(int)(scene_gmt/anc_SP.timeres); if (tmpint>=(anc_SP.nblayers-1)) tmpint=anc_SP.nblayers-2; coef=(double)(scene_gmt-anc_SP.time[tmpint])/anc_SP.timeres; ar_gridcell.spres[il_ar*lut->ar_size.s+is_ar]=(1.-coef)* tmpflt_arr[tmpint]+coef*tmpflt_arr[tmpint+1]; if (ar_gridcell.spres[il_ar*lut->ar_size.s+is_ar] > 0) { sum_spres_anc += ar_gridcell.spres[il_ar*lut->ar_size.s+is_ar]; nb_spres_anc++; } if (dem_available) { ar_gridcell.spres_dem[il_ar*lut->ar_size.s+is_ar]= get_dem_spres(dem_array, ar_gridcell.lat[il_ar*lut->ar_size.s+is_ar], ar_gridcell.lon[il_ar*lut->ar_size.s+is_ar]); if (ar_gridcell.spres_dem[il_ar*lut->ar_size.s+is_ar] > 0) { sum_spres_dem += ar_gridcell.spres_dem[il_ar*lut->ar_size.s+is_ar]; nb_spres_dem++; } } } /* for is_ar */ } /* for il_ar */ if (dem_available) { for (il_ar = 0; il_ar < lut->ar_size.l;il_ar++) for (is_ar=0;is_ar < lut->ar_size.s; is_ar++) if ((ar_gridcell.spres[il_ar*lut->ar_size.s+is_ar] > 0)&& (ar_gridcell.spres_dem[il_ar*lut->ar_size.s+is_ar] > 0)) ar_gridcell.spres[il_ar*lut->ar_size.s+is_ar]= ar_gridcell.spres_dem[il_ar*lut->ar_size.s+is_ar]* ar_gridcell.spres[il_ar*lut->ar_size.s+is_ar]/1013.; } /* Compute atmospheric coefs for the whole scene with aot550=0.01 for use in internal cloud screening : NAZMI */ nbpts=lut->ar_size.l*lut->ar_size.s; /*** Allocate memory for atmos_coeff ***/ if (allocate_mem_atmos_coeff(nbpts,&atmos_coef)) EXIT_ERROR("Allocating memory for atmos_coef", "main"); printf("Compute Atmos Params with aot550 = 0.01\n"); fflush(stdout); update_atmos_coefs(&atmos_coef, &ar_gridcell, &sixs_tables, line_ar, lut, input->nband, 1); /* Read input first time and compute clear pixels stats for internal cloud screening */ /* allocate memory for cld_diags structure and clear sum and nb of obs */ if (allocate_cld_diags(&cld_diags,CLDDIAGS_CELLHEIGHT_5KM, CLDDIAGS_CELLWIDTH_5KM, input->size.l, input->size.s)) { EXIT_ERROR("couldn't allocate memory from cld_diags","main"); } /* Screen the clouds */ for (il = 0; il < input->size.l; il++) { if (!(il%100)) { printf("First pass cloud screening for line %d\r",il); fflush(stdout); } /* Read each input band */ for (ib = 0; ib < input->nband; ib++) { if (!GetInputLine(input, ib, il, line_in[0][ib])) EXIT_ERROR("reading input data for a line (b)", "main"); } if (!GetInputQALine(input, il, qa_line[0])) EXIT_ERROR("reading input data for qa_line (1)", "main"); if (param->thermal_band) { if (!GetInputLine(input_b6, 0, il, b6_line[0])) EXIT_ERROR("reading input data for b6_line (1)", "main"); } tmpint = (int)(scene_gmt / anc_ATEMP.timeres); if (tmpint >= anc_ATEMP.nblayers - 1) tmpint = anc_ATEMP.nblayers - 2; coef = (double)(scene_gmt - anc_ATEMP.time[tmpint]) / anc_ATEMP.timeres; img.is_fill = false; img.l = il; #ifdef _OPENMP #pragma omp parallel for private (is, geo, flat, flon, tmpflt_arr) firstprivate (img, atemp_line) #endif for (is = 0; is < input->size.s; is++) { /* Get the geolocation info for this pixel */ img.s = is; if (!from_space (space, &img, &geo)) EXIT_ERROR("mapping from space (2)", "main"); flat = geo.lat * DEG; flon = geo.lon * DEG; /* Interpolate the anciliary data for this lat/long, then pull the information for the scene center time and adjust */ interpol_spatial_anc (&anc_ATEMP, flat, flon, tmpflt_arr); atemp_line[is] = (1. - coef) * tmpflt_arr[tmpint] + coef * tmpflt_arr[tmpint+1]; } /* Run Cld Screening Pass1 and compute stats. This cloud detection function contains statistics gathering that needs to be in a critical section for multi-threading. */ if (param->thermal_band) if (!cloud_detection_pass1 (lut, input->size.s, il, line_in[0], qa_line[0], b6_line[0], atemp_line, &cld_diags)) EXIT_ERROR("running cloud detection pass 1", "main"); } /* end for il */ printf ("\n"); if (param->thermal_band) { for (il = 0; il < cld_diags.nbrows; il++) { if (!(il%100)) { printf("Second pass cloud screening for line %d\r",il); fflush(stdout); } tmpint=(int)(scene_gmt / anc_ATEMP.timeres); if (tmpint >= anc_ATEMP.nblayers - 1) tmpint = anc_ATEMP.nblayers - 2; coef =(double)(scene_gmt - anc_ATEMP.time[tmpint]) / anc_ATEMP.timeres; /* Note the right shift by 1 is a faster way of divide by 2 */ img.is_fill = false; img.l = il * cld_diags.cellheight + (cld_diags.cellheight >> 1); if (img.l >= input->size.l) img.l = input->size.l-1; for (is = 0; is < cld_diags.nbcols; is++) { img.s = is * cld_diags.cellwidth + (cld_diags.cellwidth >> 1); if (img.s >= input->size.s) img.s = input->size.s-1; if (!from_space (space, &img, &geo)) EXIT_ERROR("mapping from space (3)", "main"); flat=geo.lat * DEG; flon=geo.lon * DEG; interpol_spatial_anc(&anc_ATEMP,flat,flon,tmpflt_arr); cld_diags.airtemp_2m[il][is] = (1.-coef)*tmpflt_arr[tmpint] + coef * tmpflt_arr[tmpint+1]; if (cld_diags.nb_t6_clear[il][is] > 0) { sum_value=cld_diags.avg_t6_clear[il][is]; sumsq_value=cld_diags.std_t6_clear[il][is]; cld_diags.avg_t6_clear[il][is] = sum_value/cld_diags.nb_t6_clear[il][is]; if (cld_diags.nb_t6_clear[il][is] > 1) { cld_diags.std_t6_clear[il][is] = (sumsq_value-(sum_value*sum_value)/cld_diags.nb_t6_clear[il][is])/(cld_diags.nb_t6_clear[il][is]-1); cld_diags.std_t6_clear[il][is]=sqrt(fabs(cld_diags.std_t6_clear[il][is])); } else cld_diags.std_t6_clear[il][is] = 0.; sum_value=cld_diags.avg_b7_clear[il][is]; sumsq_value=cld_diags.std_b7_clear[il][is]; cld_diags.avg_b7_clear[il][is] = sum_value/cld_diags.nb_t6_clear[il][is]; if (cld_diags.nb_t6_clear[il][is] > 1) { cld_diags.std_b7_clear[il][is] = (sumsq_value-(sum_value*sum_value)/cld_diags.nb_t6_clear[il][is])/(cld_diags.nb_t6_clear[il][is]-1); cld_diags.std_b7_clear[il][is]=sqrt(fabs(cld_diags.std_b7_clear[il][is])); } else cld_diags.std_b7_clear[il][is]=0; } else { cld_diags.avg_t6_clear[il][is]=-9999.; cld_diags.avg_b7_clear[il][is]=-9999.; cld_diags.std_t6_clear[il][is]=-9999.; cld_diags.std_b7_clear[il][is]=-9999.; } } /* end for is */ } /* end for il */ fill_cld_diags(&cld_diags); #ifdef DEBUG_CLD for (il=0;il<cld_diags.nbrows;il++) for (is=0;is<cld_diags.nbcols;is++) if (fd_cld_diags != NULL) fprintf(fd_cld_diags,"%d %d %d %f %f %f %f %f\n",il,is,cld_diags.nb_t6_clear[il][is],cld_diags.airtemp_2m[il][is],cld_diags.avg_t6_clear[il][is],cld_diags.std_t6_clear[il][is],cld_diags.avg_b7_clear[il][is],cld_diags.std_b7_clear[il][is]); fclose(fd_cld_diags); #endif } /* end if thermal band */ printf ("\n"); /*** Create dark target temporary file ***/ strcpy(tmpfilename, "temporary_dark_target_XXXXXX"); if ((tmpid = mkstemp (tmpfilename)) < 1) EXIT_ERROR("creating filename for dark target temporary file", "main"); close(tmpid); if ((fdtmp=fopen(tmpfilename,"w"))==NULL) EXIT_ERROR("creating dark target temporary file", "main"); /* Read input second time and create cloud and cloud shadow masks */ ptr_rot_cld[0]=rot_cld[0]; ptr_rot_cld[1]=rot_cld[1]; ptr_rot_cld[2]=rot_cld[2]; for (il_start = 0, il_ar = 0; il_start < input->size.l; il_start += lut->ar_region_size.l, il_ar++) { ar_gridcell.line_lat=&(ar_gridcell.lat[il_ar*lut->ar_size.s]); ar_gridcell.line_lon=&(ar_gridcell.lon[il_ar*lut->ar_size.s]); ar_gridcell.line_sun_zen=&(ar_gridcell.sun_zen[il_ar*lut->ar_size.s]); ar_gridcell.line_view_zen=&(ar_gridcell.view_zen[il_ar*lut->ar_size.s]); ar_gridcell.line_rel_az=&(ar_gridcell.rel_az[il_ar*lut->ar_size.s]); ar_gridcell.line_wv=&(ar_gridcell.wv[il_ar*lut->ar_size.s]); ar_gridcell.line_spres=&(ar_gridcell.spres[il_ar*lut->ar_size.s]); ar_gridcell.line_ozone=&(ar_gridcell.ozone[il_ar*lut->ar_size.s]); ar_gridcell.line_spres_dem=&(ar_gridcell.spres[il_ar*lut->ar_size.s]); il_end = il_start + lut->ar_region_size.l - 1; if (il_end >= input->size.l) il_end = input->size.l - 1; /* Read each input band for each line in region */ for (il = il_start; il < (il_end + 1); il++) { il_region = il - il_start; for (ib = 0; ib < input->nband; ib++) { if (!GetInputLine(input, ib, il, line_in[il_region][ib])) EXIT_ERROR("reading input data for a line (a)", "main"); } if (!GetInputQALine(input, il, qa_line[il_region])) EXIT_ERROR("reading input data for qa_line (2)", "main"); if (param->thermal_band) { if (!GetInputLine(input_b6, 0, il, b6_line[il_region])) EXIT_ERROR("reading input data for b6_line (2)", "main"); /* Run Cld Screening Pass2 */ if (!cloud_detection_pass2(lut, input->size.s, il, line_in[il_region], qa_line[il_region], b6_line[il_region], &cld_diags, ptr_rot_cld[1][il_region])) EXIT_ERROR("running cloud detection pass 2", "main"); } else { if (!cloud_detection_pass2(lut, input->size.s, il, line_in[il_region], qa_line[il_region], NULL, &cld_diags, ptr_rot_cld[1][il_region])) EXIT_ERROR("running cloud detection pass 2", "main"); } } /* end for il */ if (param->thermal_band) { /* Cloud Mask Dilation : 5 pixels */ if (!dilate_cloud_mask(lut, input->size.s, ptr_rot_cld, 5)) EXIT_ERROR("running cloud mask dilation", "main"); /* Cloud shadow */ cast_cloud_shadow(lut, input->size.s, il_start, line_in, b6_line, &cld_diags,ptr_rot_cld,&ar_gridcell, space_def.pixel_size[0], adjust_north); /* Dilate Cloud shadow */ dilate_shadow_mask(lut, input->size.s, ptr_rot_cld, 5); } /*** Save cloud and cloud shadow in temporary file ***/ if (il_ar > 0) if (fwrite(ptr_rot_cld[0][0],lut->ar_region_size.l*input->size.s,1, fdtmp) != 1) EXIT_ERROR("writing dark target to temporary file", "main"); ptr_tmp_cld=ptr_rot_cld[0]; ptr_rot_cld[0]=ptr_rot_cld[1]; ptr_rot_cld[1]=ptr_rot_cld[2]; ptr_rot_cld[2]=ptr_tmp_cld; for (i=0;i<lut->ar_region_size.l;i++) memset(&ptr_rot_cld[2][i][0],0,input->size.s); } /* end for il_start */ /** Last Block **/ dilate_shadow_mask(lut, input->size.s, ptr_rot_cld, 5); if (fwrite(ptr_rot_cld[0][0],lut->ar_region_size.l*input->size.s,1,fdtmp) != 1) EXIT_ERROR("writing dark target to temporary file", "main"); fclose(fdtmp); /* Done with the cloud diagnostics */ free_cld_diags (&cld_diags); /*** Open temporary file for read and write ***/ if ((fdtmp=fopen(tmpfilename,"r+"))==NULL) EXIT_ERROR("opening dark target temporary file (r+)", "main"); /* Read input second time and compute the aerosol for each region */ for (il_start = 0, il_ar = 0; il_start < input->size.l; il_start += lut->ar_region_size.l, il_ar++) { ar_gridcell.line_lat=&(ar_gridcell.lat[il_ar*lut->ar_size.s]); ar_gridcell.line_lon=&(ar_gridcell.lon[il_ar*lut->ar_size.s]); ar_gridcell.line_sun_zen=&(ar_gridcell.sun_zen[il_ar*lut->ar_size.s]); ar_gridcell.line_view_zen=&(ar_gridcell.view_zen[il_ar*lut->ar_size.s]); ar_gridcell.line_rel_az=&(ar_gridcell.rel_az[il_ar*lut->ar_size.s]); ar_gridcell.line_wv=&(ar_gridcell.wv[il_ar*lut->ar_size.s]); ar_gridcell.line_spres=&(ar_gridcell.spres[il_ar*lut->ar_size.s]); ar_gridcell.line_ozone=&(ar_gridcell.ozone[il_ar*lut->ar_size.s]); ar_gridcell.line_spres_dem=&(ar_gridcell.spres[il_ar*lut->ar_size.s]); il_end = il_start + lut->ar_region_size.l - 1; if (il_end >= input->size.l) il_end = input->size.l - 1; if (fseek(fdtmp,(long)(il_ar*lut->ar_region_size.l*input->size.s), SEEK_SET)) EXIT_ERROR("seeking in temporary file (r)", "main"); if (fread(ddv_line[0],lut->ar_region_size.l*input->size.s,1,fdtmp)!=1) EXIT_ERROR("reading dark target to temporary file", "main"); /* Read each input band for each line in region */ for (il = il_start, il_region = 0; il < (il_end + 1); il++, il_region++) { for (ib = 0; ib < input->nband; ib++) { if (!GetInputLine(input, ib, il, line_in[il_region][ib])) EXIT_ERROR("reading input data for a line (a)", "main"); } } /* end for il */ /* Compute the aerosol for the regions */ #ifdef DEBUG_AR diags_il_ar=il_ar; #endif if (!Ar(il_ar,lut, &input->size, line_in, ddv_line, line_ar[il_ar], &ar_stats, &ar_gridcell, &sixs_tables)) EXIT_ERROR("computing aerosol", "main"); /*** Save dark target map in temporary file ***/ if (fseek(fdtmp,il_ar*lut->ar_region_size.l*input->size.s,SEEK_SET)) EXIT_ERROR("seeking in temporary file (w)", "main"); if (fwrite(ddv_line[0],lut->ar_region_size.l*input->size.s,1,fdtmp)!=1) EXIT_ERROR("writing dark target to temporary file", "main"); } /* end for il_start */ printf("\n"); fclose(fdtmp); #ifdef DEBUG_AR fclose(fd_ar_diags); #endif /*** Fill Gaps in the coarse resolution aerosol product for bands 1(0), 2(1) and 3(2) ***/ Fill_Ar_Gaps(lut, line_ar, 0); /* Compute atmospheric coeffs for the whole scene using retrieved aot */ nbpts=lut->ar_size.l*lut->ar_size.s; printf("Compute Atmos Params\n"); fflush(stdout); #ifdef NO_AEROSOL_CORRECTION update_atmos_coefs(&atmos_coef,&ar_gridcell, &sixs_tables,line_ar, lut, input->nband, 1); #else update_atmos_coefs(&atmos_coef,&ar_gridcell, &sixs_tables,line_ar, lut, input->nband, 0); /*Eric COMMENTED TO PERFORM NO CORRECTION*/ #endif /* Re-read input and compute surface reflectance */ /*** Open temporary file for read ***/ if ((fdtmp=fopen(tmpfilename,"r"))==NULL) EXIT_ERROR("opening dark target temporary file", "main"); for (il = 0; il < input->size.l; il++) { if (!(il%100)) { printf("Processing surface reflectance for line %d\r",il); fflush(stdout); } /* Re-read each input band */ for (ib = 0; ib < input->nband; ib++) { if (!GetInputLine(input, ib, il, line_in[0][ib])) EXIT_ERROR("reading input data for a line (b)", "main"); } if (!GetInputLine(input_b6, 0, il, b6_line[0])) EXIT_ERROR("reading input data for b6_line (1)", "main"); /* Compute the surface reflectance */ if (!Sr(lut, input->size.s, il, line_in[0], line_out, &sr_stats)) EXIT_ERROR("computing surface reflectance for a line", "main"); /*** Read line from dark target temporary file ***/ if (fread(ddv_line[0],input->size.s,1,fdtmp)!=1) EXIT_ERROR("reading line from dark target temporary file", "main"); loc.l=il; i_aot=il/lut->ar_region_size.l; t6s_seuil=280.+(1000.*0.01); for (is=0;is<input->size.s;is++) { loc.s=is; j_aot=is/lut->ar_region_size.s; /* Initialize QA band to off */ line_out[lut->nband+CLOUD][is] = QA_OFF; /* Determine if this is a fill pixel -- mark as fill if any reflective band for this pixel is fill */ refl_is_fill = false; for (ib = 0; ib < input->nband; ib++) { if (line_in[0][ib][is] == lut->in_fill) if (!refl_is_fill) refl_is_fill = true; } /* Process QA for each pixel */ if (!refl_is_fill) { /* AOT / opacity */ ArInterp(lut, &loc, line_ar, &inter_aot); line_out[lut->nband+ATMOS_OPACITY][is] = inter_aot; /* QA is written out in the cloud band as a bit-packed product (16-bit). We will use QA values as-is and no further post-processing QA step will be implemented. We want the QA to reflect the cloud, etc. status that was used in the aerosol and surface reflectance computations. We are not interested in post-processing of the QA information, as there are better QA products available. */ if (ddv_line[0][is]&0x01) line_out[lut->nband+CLOUD][is] |= (1 << DDV_BIT); if (ddv_line[0][is]&0x04) line_out[lut->nband+CLOUD][is] |= (1 << ADJ_CLOUD_BIT); if (!(ddv_line[0][is]&0x10)) /* if water, turn on */ line_out[lut->nband+CLOUD][is] |= (1 << LAND_WATER_BIT); if (ddv_line[0][is]&0x20) line_out[lut->nband+CLOUD][is] |= (1 << CLOUD_BIT); if (ddv_line[0][is]&0x40) line_out[lut->nband+CLOUD][is] |= (1 << CLOUD_SHADOW_BIT); if (ddv_line[0][is]&0x80) line_out[lut->nband+CLOUD][is] |= (1 << SNOW_BIT); } else { line_out[lut->nband][is]=lut->aerosol_fill; } } /* for is */ /* Write each output band */ for (ib = 0; ib < output->nband_out; ib++) { if (!PutOutputLine(output, ib, il, line_out[ib])) EXIT_ERROR("writing output data for a line", "main"); } } /* for il */ printf("\n"); fclose(fdtmp); unlink(tmpfilename); /* Print the statistics, skip bands that don't exist */ printf(" total pixels %ld\n", ((long)input->size.l * (long)input->size.s)); printf(" aerosol coarse nfill %ld min %d max %d\n", ar_stats.nfill, ar_stats.ar_min, ar_stats.ar_max); for (ib = 0; ib < lut->nband; ib++) { if (output->metadata.band[ib].name != NULL) printf(" sr %s nfill %ld nsatu %ld nout_range %ld min %d " "max %d\n", output->metadata.band[ib].name, sr_stats.nfill[ib], sr_stats.nsatu[ib], sr_stats.nout_range[ib], sr_stats.sr_min[ib], sr_stats.sr_max[ib]); } /* Close input files */ if (!CloseInput(input)) EXIT_ERROR("closing input file", "main"); if (!CloseOutput(output)) EXIT_ERROR("closing input file", "main"); /* Write the ENVI header for reflectance files */ for (ib = 0; ib < output->nband_out; ib++) { /* Create the ENVI header file this band */ if (create_envi_struct (&output->metadata.band[ib], &xml_metadata.global, &envi_hdr) != SUCCESS) EXIT_ERROR("Creating the ENVI header structure for this file.", "main"); /* Write the ENVI header */ strcpy (envi_file, output->metadata.band[ib].file_name); cptr = strchr (envi_file, '.'); strcpy (cptr, ".hdr"); if (write_envi_hdr (envi_file, &envi_hdr) != SUCCESS) EXIT_ERROR("Writing the ENVI header file.", "main"); } /* Append the reflective and thermal bands to the XML file */ if (append_metadata (output->nband_out, output->metadata.band, param->input_xml_file_name) != SUCCESS) EXIT_ERROR("appending surfance reflectance and QA bands", "main"); /* Free the metadata structure */ free_metadata (&xml_metadata); /* Free memory */ free_mem_atmos_coeff(&atmos_coef); if (!FreeInput(input)) EXIT_ERROR("freeing input file stucture", "main"); if (!FreeInput(input_b6)) EXIT_ERROR("freeing input_b6 file stucture", "main"); if (!FreeLut(lut)) EXIT_ERROR("freeing lut file stucture", "main"); if (!FreeOutput(output)) EXIT_ERROR("freeing output file stucture", "main"); free(space); free(line_out[0]); free(line_ar[0][0]); free(line_ar[0]); free(line_ar); free(line_in[0][0]); free(line_in[0]); free(line_in); free(qa_line[0]); free(qa_line); if (param->thermal_band) { free(b6_line[0]); free(b6_line); } free(ddv_line[0]); free(ddv_line); free(rot_cld[0][0]); free(rot_cld[0]); free(ar_gridcell.lat); free(ar_gridcell.lon); free(ar_gridcell.sun_zen); free(ar_gridcell.view_zen); free(ar_gridcell.rel_az); free(ar_gridcell.wv); free(ar_gridcell.spres); free(ar_gridcell.ozone); for (ifree=0; ifree<(param->num_ncep_files>0?4:1); ifree++) { if (anc_O3.data[ifree]!=NULL) free(anc_O3.data[ifree]); if (anc_WV.data[ifree]!=NULL) free(anc_WV.data[ifree]); if (anc_SP.data[ifree]!=NULL) free(anc_SP.data[ifree]); } if (dem_available) free(dem_array); if (!FreeParam(param)) EXIT_ERROR("freeing parameter stucture", "main"); /* All done */ printf ("lndsr complete.\n"); return (EXIT_SUCCESS); } int allocate_mem_atmos_coeff(int nbpts,atmos_t *atmos_coef) { int ib; if ((atmos_coef->computed=(int *)malloc(nbpts*sizeof(int)))==NULL) return -1; for (ib=0;ib<7;ib++) { if ((atmos_coef->tgOG[ib]=(float *)malloc(nbpts*sizeof(float)))==NULL) return -1; if ((atmos_coef->tgH2O[ib]=(float *)malloc(nbpts*sizeof(float)))==NULL) return -1; if ((atmos_coef->td_ra[ib]=(float *)malloc(nbpts*sizeof(float)))==NULL) return -1; if ((atmos_coef->tu_ra[ib]=(float *)malloc(nbpts*sizeof(float)))==NULL) return -1; if ((atmos_coef->rho_mol[ib]=(float *)malloc(nbpts*sizeof(float)))==NULL) return -1; if ((atmos_coef->rho_ra[ib]=(float *)malloc(nbpts*sizeof(float)))==NULL) return -1; if ((atmos_coef->td_da[ib]=(float *)malloc(nbpts*sizeof(float)))==NULL) return -1; if ((atmos_coef->tu_da[ib]=(float *)malloc(nbpts*sizeof(float)))==NULL) return -1; if ((atmos_coef->S_ra[ib]=(float *)malloc(nbpts*sizeof(float)))==NULL) return -1; if ((atmos_coef->td_r[ib]=(float *)malloc(nbpts*sizeof(float)))==NULL) return -1; if ((atmos_coef->tu_r[ib]=(float *)malloc(nbpts*sizeof(float)))==NULL) return -1; if ((atmos_coef->S_r[ib]=(float *)malloc(nbpts*sizeof(float)))==NULL) return -1; if ((atmos_coef->rho_r[ib]=(float *)malloc(nbpts*sizeof(float)))==NULL) return -1; } return 0; } int free_mem_atmos_coeff(atmos_t *atmos_coef) { int ib; free(atmos_coef->computed); for(ib=0;ib<7;ib++) { free(atmos_coef->tgOG[ib]); free(atmos_coef->tgH2O[ib]); free(atmos_coef->td_ra[ib]); free(atmos_coef->tu_ra[ib]); free(atmos_coef->rho_mol[ib]); free(atmos_coef->rho_ra[ib]); free(atmos_coef->td_da[ib]); free(atmos_coef->tu_da[ib]); free(atmos_coef->S_ra[ib]); free(atmos_coef->td_r[ib]); free(atmos_coef->tu_r[ib]); free(atmos_coef->S_r[ib]); free(atmos_coef->rho_r[ib]); } return 0; } /****************************************************************************** !C !Routine: calcuoz !Description: Gets ozone concentration for a particular day and latitude, interpolating if necessary. !Revision History: Original version: Nazmi Z El Saleous and Eric Vermote !Input Parameters: jday Julian day lat latitude (in degrees) !Output Parameters: uoz Ozone concentration (in cm-atm) !Return value: returns 0 (success) -1 (latitude is beyond coverage of data, and so the returned ozone value is an approximation). !References and Credits: Data is from: LONDON J.,BOJKOV R.D.,OLTMANS S. AND KELLEY J.I.,1976, ATLAS OF THE GLOBAL DISTRIBUTION OF TOTAL OZONE .JULY 1957-JUNE 1967 NCAR TECHNICAL NOTE, NCAR/TN/113+STR,PP276 !Developers: Nazmi Z El Saleous Eric Vermote University of Maryland / Dept. of Geography nazmi.elsaleous@gsfc.nasa.gov !Design Notes: !END *******************************************************************************/ float calcuoz(short jday,float flat) { float t,u,tmpf; int i1,i2,j1,j2,Minf,Msup,Latinf,Latsup; /* CREPARTITION ZONALE PAR BANDE DE 10 DEG DE LATITUDE A PARTIR DE 80 SUD C --- OZONE --- */ float oz[12][17] = { {.315,.320,.315,.305,.300,.280,.260,.240,.240,.240,.250,.280,.320,.350,.375,.380,.380}, {.280,.300,.300,.300,.280,.270,.260,.240,.240,.240,.260,.300,.340,.380,.400,.420,.420}, {.280,.280,.280,.280,.280,.260,.250,.240,.250,.250,.270,.300,.340,.400,.420,.440,.440}, {.280,.280,.280,.280,.280,.260,.250,.250,.250,.260,.280,.300,.340,.380,.420,.430,.430}, {.280,.290,.300,.300,.280,.270,.260,.250,.250,.260,.270,.300,.320,.360,.380,.400,.400}, {.280,.300,.300,.305,.300,.280,.260,.250,.250,.260,.260,.280,.310,.330,.360,.370,.370}, {.290,.300,.315,.320,.305,.280,.260,.250,.240,.240,.260,.270,.290,.310,.320,.320,.320}, {.300,.310,.320,.325,.320,.300,.270,.260,.240,.240,.250,.260,.280,.290,.300,.300,.290}, {.300,.320,.325,.335,.320,.300,.280,.260,.240,.240,.240,.260,.270,.280,.280,.280,.280}, {.320,.340,.350,.345,.330,.300,.280,.260,.240,.240,.240,.260,.260,.280,.280,.280,.280}, {.360,.360,.360,.340,.320,.300,.280,.260,.240,.240,.240,.260,.280,.300,.310,.310,.300}, {.340,.350,.340,.320,.310,.280,.260,.250,.240,.240,.240,.260,.300,.320,.330,.340,.330}}; /* C /Begin of interpolation/ C /Find Neighbours/ C /First loop for time/ */ if (fabs(flat)>=80.) { tmpf=.270; return -1; } Minf= (int) ((jday-15.)/30.5); if (jday < 15) Minf=Minf-1; Latinf=(int) (flat*0.1); if (flat < 0.) Latinf=Latinf-1; t=((jday-15.)-(30.5*Minf))/30.5; u=(flat-10.*Latinf)*0.1; Minf=(Minf+12)%12; Msup=(Minf+13)%12; Latsup=Latinf+1; i1=Minf; j1=Latinf+8; i2=Msup; j2=Latsup+8; /* Now Calculate Uo3 at the given point Xlat,Jjulien */ tmpf=(1.-t)*(1.-u)*oz[i1][j1] + t*(1.-u)*oz[i2][j1] + t*u*oz[i2][j2] + (1.-t)*u*oz[i1][j2]; return tmpf; } float get_dem_spres(short *dem,float lat,float lon) { int idem,jdem; float dem_spres; idem=(int)((DEM_LATMAX-lat)/DEM_DLAT+0.5); if (idem<0) idem=0; if (idem >= DEM_NBLAT) idem=DEM_NBLAT-1; jdem=(int)((lon-DEM_LONMIN)/DEM_DLON+0.5); if (jdem<0) jdem=0; if (jdem >= DEM_NBLON) jdem=DEM_NBLON-1; if (dem[idem*DEM_NBLON+jdem]== -9999) dem_spres=1013; else dem_spres=1013.2*exp(-dem[idem*DEM_NBLON+jdem]/8000.); return dem_spres; } int update_atmos_coefs ( atmos_t *atmos_coef, Ar_gridcell_t *ar_gridcell, sixs_tables_t *sixs_tables, int ***line_ar, Lut_t *lut, int nband, int bkgd_aerosol ) { int irow,icol; for (irow=0;irow<ar_gridcell->nbrows;irow++) for (icol=0;icol<ar_gridcell->nbcols;icol++) update_gridcell_atmos_coefs(irow,icol,atmos_coef,ar_gridcell, sixs_tables,line_ar[irow],lut,nband,bkgd_aerosol); return 0; } int update_gridcell_atmos_coefs ( int irow, int icol, atmos_t *atmos_coef, Ar_gridcell_t *ar_gridcell, sixs_tables_t *sixs_tables, int **line_ar, Lut_t *lut, int nband, int bkgd_aerosol ) { int ib,ipt,k; float mus,muv,phi,ratio_spres,tau_ray,aot550; double coef; float actual_rho_ray,actual_T_ray_up,actual_T_ray_down,actual_S_r; float rho_ray_P0,T_ray_up_P0,T_ray_down_P0,S_r_P0; float lamda[7]={486.,570.,660.,835.,1669.,0.,2207.}; float tau_ray_sealevel[7]={0.16511,0.08614,0.04716,0.01835,0.00113,0.00037}; /* index=5 => band 7 */ ipt=irow*ar_gridcell->nbcols+icol; mus=cos(ar_gridcell->sun_zen[ipt]*RAD); muv=cos(ar_gridcell->view_zen[ipt]*RAD); phi=ar_gridcell->rel_az[ipt]; ratio_spres=ar_gridcell->spres[ipt]/1013.; if (bkgd_aerosol) { atmos_coef->computed[ipt]=1; aot550=0.01; } else { if (line_ar[0][icol] != lut->aerosol_fill) { atmos_coef->computed[ipt]=1; aot550=((float)line_ar[0][icol]/1000.)*pow((550./lamda[0]),-1.); } else { atmos_coef->computed[ipt]=1; aot550=0.01; } } for (k=1;k<SIXS_NB_AOT;k++) { if (aot550 < sixs_tables->aot[k]) break; } k--; if (k>=(SIXS_NB_AOT-1)) k=SIXS_NB_AOT-2; coef=(aot550-sixs_tables->aot[k])/(sixs_tables->aot[k+1]- sixs_tables->aot[k]); for (ib=0;ib < nband; ib++) { atmos_coef->tgOG[ib][ipt]=sixs_tables->T_g_og[ib]; atmos_coef->tgH2O[ib][ipt]=sixs_tables->T_g_wv[ib]; atmos_coef->td_ra[ib][ipt]=(1.-coef)*sixs_tables->T_ra_down[ib][k]+ coef*sixs_tables->T_ra_down[ib][k+1]; atmos_coef->tu_ra[ib][ipt]=(1.-coef)*sixs_tables->T_ra_up[ib][k]+ coef*sixs_tables->T_ra_up[ib][k+1]; atmos_coef->rho_mol[ib][ipt]=sixs_tables->rho_r[ib]; atmos_coef->rho_ra[ib][ipt]=(1.-coef)*sixs_tables->rho_ra[ib][k]+ coef*sixs_tables->rho_ra[ib][k+1]; atmos_coef->td_da[ib][ipt]=(1.-coef)*sixs_tables->T_a_down[ib][k]+ coef*sixs_tables->T_a_down[ib][k+1]; atmos_coef->tu_da[ib][ipt]=(1.-coef)*sixs_tables->T_a_up[ib][k]+ coef*sixs_tables->T_a_up[ib][k+1]; atmos_coef->S_ra[ib][ipt]=(1.-coef)*sixs_tables->S_ra[ib][k]+ coef*sixs_tables->S_ra[ib][k+1]; /** compute DEM-based pressure correction for each grid point **/ tau_ray=tau_ray_sealevel[ib]*ratio_spres; chand(&phi,&muv,&mus,&tau_ray,&actual_rho_ray); actual_T_ray_down=((2./3.+mus)+(2./3.-mus)*exp(-tau_ray/mus))/ (4./3.+tau_ray); /* downward */ actual_T_ray_up = ((2./3.+muv)+(2./3.-muv)*exp(-tau_ray/muv))/ (4./3.+tau_ray); /* upward */ csalbr(&tau_ray,&actual_S_r); rho_ray_P0=sixs_tables->rho_r[ib]; T_ray_down_P0=sixs_tables->T_r_down[ib]; T_ray_up_P0=sixs_tables->T_r_up[ib]; S_r_P0=sixs_tables->S_r[ib]; atmos_coef->rho_ra[ib][ipt]=actual_rho_ray+(atmos_coef->rho_ra[ib][ipt]- rho_ray_P0); /* will need to correct for uwv/2 */ atmos_coef->td_ra[ib][ipt] *= (actual_T_ray_down/T_ray_down_P0); atmos_coef->tu_ra[ib][ipt] *= (actual_T_ray_up/T_ray_up_P0); atmos_coef->S_ra[ib][ipt] = atmos_coef->S_ra[ib][ipt]-S_r_P0+actual_S_r; atmos_coef->td_r[ib][ipt] = actual_T_ray_down; atmos_coef->tu_r[ib][ipt] = actual_T_ray_up; atmos_coef->S_r[ib][ipt] = actual_S_r; atmos_coef->rho_r[ib][ipt] = actual_rho_ray; } /* for ib */ return 0; } void sun_angles ( short jday, float gmt, float flat, float flon, float *ts, float *fs ) { double mst,tst,tet,et,ha,delta; double dlat,amuzero,elev,az,caz,azim; double A1=.000075,A2=.001868,A3=.032077,A4=.014615,A5=.040849; double B1=.006918,B2=.399912,B3=.070257,B4=.006758; double B5=.000907,B6=.002697,B7=.001480; dlat=(double)flat*M_PI/180.; /* SOLAR POSITION (ZENITHAL ANGLE ThetaS,AZIMUTHAL ANGLE PhiS IN DEGREES) J IS THE DAY NUMBER IN THE YEAR MEAN SOLAR TIME (HEURE DECIMALE) */ mst=gmt+(flon)/15.; tet=2.*M_PI*(double)jday/365.; /* TIME EQUATION (IN MN.DEC) */ et=A1+A2*cos(tet)-A3*sin(tet)-A4*cos(2.*tet)-A5*sin(2.*tet); et=et*12.*60./M_PI; /* TRUE SOLAR TIME */ tst=mst+et/60.; tst=(tst-12.); /* HOUR ANGLE */ ha=tst*15.*M_PI/180.; /* SOLAR DECLINATION (IN RADIAN) */ delta=B1-B2*cos(tet)+B3*sin(tet)-B4*cos(2.*tet)+B5*sin(2.*tet)- B6*cos(3.*tet)+B7*sin(3.*tet); /* ELEVATION,AZIMUTH */ amuzero=sin(dlat)*sin(delta)+cos(dlat)*cos(delta)*cos(ha); elev=asin(amuzero); az=cos(delta)*sin(ha)/cos(elev); if (az<-1.) az=-1; else if (az>1.) az=1.; caz=(-cos(dlat)*sin(delta)+sin(dlat)*cos(delta)*cos(ha))/cos(elev); azim=asin(az); if (caz < 0.) azim=M_PI-azim; if ((caz > 0.) && (az < 0.)) azim=2*M_PI+azim; azim=azim+M_PI; if (azim > (2.*M_PI)) azim=azim-2.*M_PI; elev=elev*180./M_PI; /* CONVERSION IN DEGREES */ *ts=90.-elev; *fs=azim*180./M_PI; return; }
master-combined-2.c
void foo (int *a) { int i, r = 0, s = 0; #pragma omp taskgroup task_reduction(+:r) #pragma omp parallel master taskloop in_reduction(+:r) /* { dg-error "'in_reduction' is not valid for '#pragma omp parallel master taskloop'" } */ for (i = 0; i < 64; i++) r += a[i]; #pragma omp taskgroup task_reduction(+:s) #pragma omp parallel master taskloop simd in_reduction(+:s) /* { dg-error "'in_reduction' is not valid for '#pragma omp parallel master taskloop simd'" } */ for (i = 0; i < 64; i++) s += a[i]; }
profile.c
/* %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% % % % % % % % PPPP RRRR OOO FFFFF IIIII L EEEEE % % P P R R O O F I L E % % PPPP RRRR O O FFF I L EEE % % P R R O O F I L E % % P R R OOO F IIIII LLLLL EEEEE % % % % % % MagickCore Image Profile Methods % % % % Software Design % % Cristy % % July 1992 % % % % % % Copyright 1999-2017 ImageMagick Studio LLC, a non-profit organization % % dedicated to making software imaging solutions freely available. % % % % You may not use this file except in compliance with the License. You may % % obtain a copy of the License at % % % % https://www.imagemagick.org/script/license.php % % % % Unless required by applicable law or agreed to in writing, software % % distributed under the License is distributed on an "AS IS" BASIS, % % WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. % % See the License for the specific language governing permissions and % % limitations under the License. % % % %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% % % */ /* Include declarations. */ #include "MagickCore/studio.h" #include "MagickCore/attribute.h" #include "MagickCore/cache.h" #include "MagickCore/color.h" #include "MagickCore/colorspace-private.h" #include "MagickCore/configure.h" #include "MagickCore/exception.h" #include "MagickCore/exception-private.h" #include "MagickCore/image.h" #include "MagickCore/linked-list.h" #include "MagickCore/memory_.h" #include "MagickCore/monitor.h" #include "MagickCore/monitor-private.h" #include "MagickCore/option.h" #include "MagickCore/option-private.h" #include "MagickCore/pixel-accessor.h" #include "MagickCore/profile.h" #include "MagickCore/profile-private.h" #include "MagickCore/property.h" #include "MagickCore/quantum.h" #include "MagickCore/quantum-private.h" #include "MagickCore/resource_.h" #include "MagickCore/splay-tree.h" #include "MagickCore/string_.h" #include "MagickCore/thread-private.h" #include "MagickCore/token.h" #include "MagickCore/utility.h" #if defined(MAGICKCORE_LCMS_DELEGATE) #if defined(MAGICKCORE_HAVE_LCMS_LCMS2_H) #include <wchar.h> #include <lcms/lcms2.h> #else #include <wchar.h> #include "lcms2.h" #endif #endif /* Forward declarations */ static MagickBooleanType SetImageProfileInternal(Image *,const char *,const StringInfo *, const MagickBooleanType,ExceptionInfo *); static void WriteTo8BimProfile(Image *,const char*,const StringInfo *); /* Typedef declarations */ struct _ProfileInfo { char *name; size_t length; unsigned char *info; size_t signature; }; typedef struct _CMSExceptionInfo { Image *image; ExceptionInfo *exception; } CMSExceptionInfo; /* %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% % % % % % % % C l o n e I m a g e P r o f i l e s % % % % % % % %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% % % CloneImageProfiles() clones one or more image profiles. % % The format of the CloneImageProfiles method is: % % MagickBooleanType CloneImageProfiles(Image *image, % const Image *clone_image) % % A description of each parameter follows: % % o image: the image. % % o clone_image: the clone image. % */ MagickExport MagickBooleanType CloneImageProfiles(Image *image, const Image *clone_image) { assert(image != (Image *) NULL); assert(image->signature == MagickCoreSignature); if (image->debug != MagickFalse) (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename); assert(clone_image != (const Image *) NULL); assert(clone_image->signature == MagickCoreSignature); if (clone_image->profiles != (void *) NULL) { if (image->profiles != (void *) NULL) DestroyImageProfiles(image); image->profiles=CloneSplayTree((SplayTreeInfo *) clone_image->profiles, (void *(*)(void *)) ConstantString,(void *(*)(void *)) CloneStringInfo); } return(MagickTrue); } /* %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% % % % % % % % D e l e t e I m a g e P r o f i l e % % % % % % % %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% % % DeleteImageProfile() deletes a profile from the image by its name. % % The format of the DeleteImageProfile method is: % % MagickBooleanTyupe DeleteImageProfile(Image *image,const char *name) % % A description of each parameter follows: % % o image: the image. % % o name: the profile name. % */ MagickExport MagickBooleanType DeleteImageProfile(Image *image,const char *name) { assert(image != (Image *) NULL); assert(image->signature == MagickCoreSignature); if (image->debug != MagickFalse) (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename); if (image->profiles == (SplayTreeInfo *) NULL) return(MagickFalse); WriteTo8BimProfile(image,name,(StringInfo *) NULL); return(DeleteNodeFromSplayTree((SplayTreeInfo *) image->profiles,name)); } /* %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% % % % % % % % D e s t r o y I m a g e P r o f i l e s % % % % % % % %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% % % DestroyImageProfiles() releases memory associated with an image profile map. % % The format of the DestroyProfiles method is: % % void DestroyImageProfiles(Image *image) % % A description of each parameter follows: % % o image: the image. % */ MagickExport void DestroyImageProfiles(Image *image) { if (image->profiles != (SplayTreeInfo *) NULL) image->profiles=DestroySplayTree((SplayTreeInfo *) image->profiles); } /* %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% % % % % % % % G e t I m a g e P r o f i l e % % % % % % % %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% % % GetImageProfile() gets a profile associated with an image by name. % % The format of the GetImageProfile method is: % % const StringInfo *GetImageProfile(const Image *image,const char *name) % % A description of each parameter follows: % % o image: the image. % % o name: the profile name. % */ MagickExport const StringInfo *GetImageProfile(const Image *image, const char *name) { const StringInfo *profile; assert(image != (Image *) NULL); assert(image->signature == MagickCoreSignature); if (image->debug != MagickFalse) (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename); if (image->profiles == (SplayTreeInfo *) NULL) return((StringInfo *) NULL); profile=(const StringInfo *) GetValueFromSplayTree((SplayTreeInfo *) image->profiles,name); return(profile); } /* %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% % % % % % % % G e t N e x t I m a g e P r o f i l e % % % % % % % %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% % % GetNextImageProfile() gets the next profile name for an image. % % The format of the GetNextImageProfile method is: % % char *GetNextImageProfile(const Image *image) % % A description of each parameter follows: % % o hash_info: the hash info. % */ MagickExport char *GetNextImageProfile(const Image *image) { assert(image != (Image *) NULL); assert(image->signature == MagickCoreSignature); if (image->debug != MagickFalse) (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename); if (image->profiles == (SplayTreeInfo *) NULL) return((char *) NULL); return((char *) GetNextKeyInSplayTree((SplayTreeInfo *) image->profiles)); } /* %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% % % % % % % % P r o f i l e I m a g e % % % % % % % %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% % % ProfileImage() associates, applies, or removes an ICM, IPTC, or generic % profile with / to / from an image. If the profile is NULL, it is removed % from the image otherwise added or applied. Use a name of '*' and a profile % of NULL to remove all profiles from the image. % % ICC and ICM profiles are handled as follows: If the image does not have % an associated color profile, the one you provide is associated with the % image and the image pixels are not transformed. Otherwise, the colorspace % transform defined by the existing and new profile are applied to the image % pixels and the new profile is associated with the image. % % The format of the ProfileImage method is: % % MagickBooleanType ProfileImage(Image *image,const char *name, % const void *datum,const size_t length,const MagickBooleanType clone) % % A description of each parameter follows: % % o image: the image. % % o name: Name of profile to add or remove: ICC, IPTC, or generic profile. % % o datum: the profile data. % % o length: the length of the profile. % % o clone: should be MagickFalse. % */ #if defined(MAGICKCORE_LCMS_DELEGATE) static unsigned short **DestroyPixelThreadSet(unsigned short **pixels) { register ssize_t i; assert(pixels != (unsigned short **) NULL); for (i=0; i < (ssize_t) GetMagickResourceLimit(ThreadResource); i++) if (pixels[i] != (unsigned short *) NULL) pixels[i]=(unsigned short *) RelinquishMagickMemory(pixels[i]); pixels=(unsigned short **) RelinquishMagickMemory(pixels); return(pixels); } static unsigned short **AcquirePixelThreadSet(const size_t columns, const size_t channels) { register ssize_t i; unsigned short **pixels; size_t number_threads; number_threads=(size_t) GetMagickResourceLimit(ThreadResource); pixels=(unsigned short **) AcquireQuantumMemory(number_threads, sizeof(*pixels)); if (pixels == (unsigned short **) NULL) return((unsigned short **) NULL); (void) ResetMagickMemory(pixels,0,number_threads*sizeof(*pixels)); for (i=0; i < (ssize_t) number_threads; i++) { pixels[i]=(unsigned short *) AcquireQuantumMemory(columns,channels* sizeof(**pixels)); if (pixels[i] == (unsigned short *) NULL) return(DestroyPixelThreadSet(pixels)); } return(pixels); } static cmsHTRANSFORM *DestroyTransformThreadSet(cmsHTRANSFORM *transform) { register ssize_t i; assert(transform != (cmsHTRANSFORM *) NULL); for (i=0; i < (ssize_t) GetMagickResourceLimit(ThreadResource); i++) if (transform[i] != (cmsHTRANSFORM) NULL) cmsDeleteTransform(transform[i]); transform=(cmsHTRANSFORM *) RelinquishMagickMemory(transform); return(transform); } static cmsHTRANSFORM *AcquireTransformThreadSet(Image *image, const cmsHPROFILE source_profile,const cmsUInt32Number source_type, const cmsHPROFILE target_profile,const cmsUInt32Number target_type, const int intent,const cmsUInt32Number flags) { cmsHTRANSFORM *transform; register ssize_t i; size_t number_threads; number_threads=(size_t) GetMagickResourceLimit(ThreadResource); transform=(cmsHTRANSFORM *) AcquireQuantumMemory(number_threads, sizeof(*transform)); if (transform == (cmsHTRANSFORM *) NULL) return((cmsHTRANSFORM *) NULL); (void) ResetMagickMemory(transform,0,number_threads*sizeof(*transform)); for (i=0; i < (ssize_t) number_threads; i++) { transform[i]=cmsCreateTransformTHR((cmsContext) image,source_profile, source_type,target_profile,target_type,intent,flags); if (transform[i] == (cmsHTRANSFORM) NULL) return(DestroyTransformThreadSet(transform)); } return(transform); } #endif #if defined(MAGICKCORE_LCMS_DELEGATE) static void CMSExceptionHandler(cmsContext context,cmsUInt32Number severity, const char *message) { CMSExceptionInfo *cms_exception; ExceptionInfo *exception; Image *image; cms_exception=(CMSExceptionInfo *) context; if (cms_exception == (CMSExceptionInfo *) NULL) return; exception=cms_exception->exception; if (exception == (ExceptionInfo *) NULL) return; image=cms_exception->image; if (image == (Image *) NULL) { (void) ThrowMagickException(exception,GetMagickModule(),ImageWarning, "UnableToTransformColorspace","`%s'","unknown context"); return; } if (image->debug != MagickFalse) (void) LogMagickEvent(TransformEvent,GetMagickModule(),"lcms: #%u, %s", severity,message != (char *) NULL ? message : "no message"); (void) ThrowMagickException(exception,GetMagickModule(),ImageWarning, "UnableToTransformColorspace","`%s'",image->filename); } #endif static MagickBooleanType SetsRGBImageProfile(Image *image, ExceptionInfo *exception) { static unsigned char sRGBProfile[] = { 0x00, 0x00, 0x0c, 0x8c, 0x61, 0x72, 0x67, 0x6c, 0x02, 0x20, 0x00, 0x00, 0x6d, 0x6e, 0x74, 0x72, 0x52, 0x47, 0x42, 0x20, 0x58, 0x59, 0x5a, 0x20, 0x07, 0xde, 0x00, 0x01, 0x00, 0x06, 0x00, 0x16, 0x00, 0x0f, 0x00, 0x3a, 0x61, 0x63, 0x73, 0x70, 0x4d, 0x53, 0x46, 0x54, 0x00, 0x00, 0x00, 0x00, 0x49, 0x45, 0x43, 0x20, 0x73, 0x52, 0x47, 0x42, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xf6, 0xd6, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00, 0xd3, 0x2d, 0x61, 0x72, 0x67, 0x6c, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x11, 0x64, 0x65, 0x73, 0x63, 0x00, 0x00, 0x01, 0x50, 0x00, 0x00, 0x00, 0x99, 0x63, 0x70, 0x72, 0x74, 0x00, 0x00, 0x01, 0xec, 0x00, 0x00, 0x00, 0x67, 0x64, 0x6d, 0x6e, 0x64, 0x00, 0x00, 0x02, 0x54, 0x00, 0x00, 0x00, 0x70, 0x64, 0x6d, 0x64, 0x64, 0x00, 0x00, 0x02, 0xc4, 0x00, 0x00, 0x00, 0x88, 0x74, 0x65, 0x63, 0x68, 0x00, 0x00, 0x03, 0x4c, 0x00, 0x00, 0x00, 0x0c, 0x76, 0x75, 0x65, 0x64, 0x00, 0x00, 0x03, 0x58, 0x00, 0x00, 0x00, 0x67, 0x76, 0x69, 0x65, 0x77, 0x00, 0x00, 0x03, 0xc0, 0x00, 0x00, 0x00, 0x24, 0x6c, 0x75, 0x6d, 0x69, 0x00, 0x00, 0x03, 0xe4, 0x00, 0x00, 0x00, 0x14, 0x6d, 0x65, 0x61, 0x73, 0x00, 0x00, 0x03, 0xf8, 0x00, 0x00, 0x00, 0x24, 0x77, 0x74, 0x70, 0x74, 0x00, 0x00, 0x04, 0x1c, 0x00, 0x00, 0x00, 0x14, 0x62, 0x6b, 0x70, 0x74, 0x00, 0x00, 0x04, 0x30, 0x00, 0x00, 0x00, 0x14, 0x72, 0x58, 0x59, 0x5a, 0x00, 0x00, 0x04, 0x44, 0x00, 0x00, 0x00, 0x14, 0x67, 0x58, 0x59, 0x5a, 0x00, 0x00, 0x04, 0x58, 0x00, 0x00, 0x00, 0x14, 0x62, 0x58, 0x59, 0x5a, 0x00, 0x00, 0x04, 0x6c, 0x00, 0x00, 0x00, 0x14, 0x72, 0x54, 0x52, 0x43, 0x00, 0x00, 0x04, 0x80, 0x00, 0x00, 0x08, 0x0c, 0x67, 0x54, 0x52, 0x43, 0x00, 0x00, 0x04, 0x80, 0x00, 0x00, 0x08, 0x0c, 0x62, 0x54, 0x52, 0x43, 0x00, 0x00, 0x04, 0x80, 0x00, 0x00, 0x08, 0x0c, 0x64, 0x65, 0x73, 0x63, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x3f, 0x73, 0x52, 0x47, 0x42, 0x20, 0x49, 0x45, 0x43, 0x36, 0x31, 0x39, 0x36, 0x36, 0x2d, 0x32, 0x2e, 0x31, 0x20, 0x28, 0x45, 0x71, 0x75, 0x69, 0x76, 0x61, 0x6c, 0x65, 0x6e, 0x74, 0x20, 0x74, 0x6f, 0x20, 0x77, 0x77, 0x77, 0x2e, 0x73, 0x72, 0x67, 0x62, 0x2e, 0x63, 0x6f, 0x6d, 0x20, 0x31, 0x39, 0x39, 0x38, 0x20, 0x48, 0x50, 0x20, 0x70, 0x72, 0x6f, 0x66, 0x69, 0x6c, 0x65, 0x29, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x3f, 0x73, 0x52, 0x47, 0x42, 0x20, 0x49, 0x45, 0x43, 0x36, 0x31, 0x39, 0x36, 0x36, 0x2d, 0x32, 0x2e, 0x31, 0x20, 0x28, 0x45, 0x71, 0x75, 0x69, 0x76, 0x61, 0x6c, 0x65, 0x6e, 0x74, 0x20, 0x74, 0x6f, 0x20, 0x77, 0x77, 0x77, 0x2e, 0x73, 0x72, 0x67, 0x62, 0x2e, 0x63, 0x6f, 0x6d, 0x20, 0x31, 0x39, 0x39, 0x38, 0x20, 0x48, 0x50, 0x20, 0x70, 0x72, 0x6f, 0x66, 0x69, 0x6c, 0x65, 0x29, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x74, 0x65, 0x78, 0x74, 0x00, 0x00, 0x00, 0x00, 0x43, 0x72, 0x65, 0x61, 0x74, 0x65, 0x64, 0x20, 0x62, 0x79, 0x20, 0x47, 0x72, 0x61, 0x65, 0x6d, 0x65, 0x20, 0x57, 0x2e, 0x20, 0x47, 0x69, 0x6c, 0x6c, 0x2e, 0x20, 0x52, 0x65, 0x6c, 0x65, 0x61, 0x73, 0x65, 0x64, 0x20, 0x69, 0x6e, 0x74, 0x6f, 0x20, 0x74, 0x68, 0x65, 0x20, 0x70, 0x75, 0x62, 0x6c, 0x69, 0x63, 0x20, 0x64, 0x6f, 0x6d, 0x61, 0x69, 0x6e, 0x2e, 0x20, 0x4e, 0x6f, 0x20, 0x57, 0x61, 0x72, 0x72, 0x61, 0x6e, 0x74, 0x79, 0x2c, 0x20, 0x55, 0x73, 0x65, 0x20, 0x61, 0x74, 0x20, 0x79, 0x6f, 0x75, 0x72, 0x20, 0x6f, 0x77, 0x6e, 0x20, 0x72, 0x69, 0x73, 0x6b, 0x2e, 0x00, 0x00, 0x64, 0x65, 0x73, 0x63, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x16, 0x49, 0x45, 0x43, 0x20, 0x68, 0x74, 0x74, 0x70, 0x3a, 0x2f, 0x2f, 0x77, 0x77, 0x77, 0x2e, 0x69, 0x65, 0x63, 0x2e, 0x63, 0x68, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x16, 0x49, 0x45, 0x43, 0x20, 0x68, 0x74, 0x74, 0x70, 0x3a, 0x2f, 0x2f, 0x77, 0x77, 0x77, 0x2e, 0x69, 0x65, 0x63, 0x2e, 0x63, 0x68, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x64, 0x65, 0x73, 0x63, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x2e, 0x49, 0x45, 0x43, 0x20, 0x36, 0x31, 0x39, 0x36, 0x36, 0x2d, 0x32, 0x2e, 0x31, 0x20, 0x44, 0x65, 0x66, 0x61, 0x75, 0x6c, 0x74, 0x20, 0x52, 0x47, 0x42, 0x20, 0x63, 0x6f, 0x6c, 0x6f, 0x75, 0x72, 0x20, 0x73, 0x70, 0x61, 0x63, 0x65, 0x20, 0x2d, 0x20, 0x73, 0x52, 0x47, 0x42, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x2e, 0x49, 0x45, 0x43, 0x20, 0x36, 0x31, 0x39, 0x36, 0x36, 0x2d, 0x32, 0x2e, 0x31, 0x20, 0x44, 0x65, 0x66, 0x61, 0x75, 0x6c, 0x74, 0x20, 0x52, 0x47, 0x42, 0x20, 0x63, 0x6f, 0x6c, 0x6f, 0x75, 0x72, 0x20, 0x73, 0x70, 0x61, 0x63, 0x65, 0x20, 0x2d, 0x20, 0x73, 0x52, 0x47, 0x42, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x73, 0x69, 0x67, 0x20, 0x00, 0x00, 0x00, 0x00, 0x43, 0x52, 0x54, 0x20, 0x64, 0x65, 0x73, 0x63, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x0d, 0x49, 0x45, 0x43, 0x36, 0x31, 0x39, 0x36, 0x36, 0x2d, 0x32, 0x2e, 0x31, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x0d, 0x49, 0x45, 0x43, 0x36, 0x31, 0x39, 0x36, 0x36, 0x2d, 0x32, 0x2e, 0x31, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x76, 0x69, 0x65, 0x77, 0x00, 0x00, 0x00, 0x00, 0x00, 0x13, 0xa4, 0x7c, 0x00, 0x14, 0x5f, 0x30, 0x00, 0x10, 0xce, 0x02, 0x00, 0x03, 0xed, 0xb2, 0x00, 0x04, 0x13, 0x0a, 0x00, 0x03, 0x5c, 0x67, 0x00, 0x00, 0x00, 0x01, 0x58, 0x59, 0x5a, 0x20, 0x00, 0x00, 0x00, 0x00, 0x00, 0x4c, 0x0a, 0x3d, 0x00, 0x50, 0x00, 0x00, 0x00, 0x57, 0x1e, 0xb8, 0x6d, 0x65, 0x61, 0x73, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0x8f, 0x00, 0x00, 0x00, 0x02, 0x58, 0x59, 0x5a, 0x20, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xf3, 0x51, 0x00, 0x01, 0x00, 0x00, 0x00, 0x01, 0x16, 0xcc, 0x58, 0x59, 0x5a, 0x20, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x58, 0x59, 0x5a, 0x20, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x6f, 0xa0, 0x00, 0x00, 0x38, 0xf5, 0x00, 0x00, 0x03, 0x90, 0x58, 0x59, 0x5a, 0x20, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x62, 0x97, 0x00, 0x00, 0xb7, 0x87, 0x00, 0x00, 0x18, 0xd9, 0x58, 0x59, 0x5a, 0x20, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x24, 0x9f, 0x00, 0x00, 0x0f, 0x84, 0x00, 0x00, 0xb6, 0xc4, 0x63, 0x75, 0x72, 0x76, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x04, 0x00, 0x00, 0x00, 0x00, 0x05, 0x00, 0x0a, 0x00, 0x0f, 0x00, 0x14, 0x00, 0x19, 0x00, 0x1e, 0x00, 0x23, 0x00, 0x28, 0x00, 0x2d, 0x00, 0x32, 0x00, 0x37, 0x00, 0x3b, 0x00, 0x40, 0x00, 0x45, 0x00, 0x4a, 0x00, 0x4f, 0x00, 0x54, 0x00, 0x59, 0x00, 0x5e, 0x00, 0x63, 0x00, 0x68, 0x00, 0x6d, 0x00, 0x72, 0x00, 0x77, 0x00, 0x7c, 0x00, 0x81, 0x00, 0x86, 0x00, 0x8b, 0x00, 0x90, 0x00, 0x95, 0x00, 0x9a, 0x00, 0x9f, 0x00, 0xa4, 0x00, 0xa9, 0x00, 0xae, 0x00, 0xb2, 0x00, 0xb7, 0x00, 0xbc, 0x00, 0xc1, 0x00, 0xc6, 0x00, 0xcb, 0x00, 0xd0, 0x00, 0xd5, 0x00, 0xdb, 0x00, 0xe0, 0x00, 0xe5, 0x00, 0xeb, 0x00, 0xf0, 0x00, 0xf6, 0x00, 0xfb, 0x01, 0x01, 0x01, 0x07, 0x01, 0x0d, 0x01, 0x13, 0x01, 0x19, 0x01, 0x1f, 0x01, 0x25, 0x01, 0x2b, 0x01, 0x32, 0x01, 0x38, 0x01, 0x3e, 0x01, 0x45, 0x01, 0x4c, 0x01, 0x52, 0x01, 0x59, 0x01, 0x60, 0x01, 0x67, 0x01, 0x6e, 0x01, 0x75, 0x01, 0x7c, 0x01, 0x83, 0x01, 0x8b, 0x01, 0x92, 0x01, 0x9a, 0x01, 0xa1, 0x01, 0xa9, 0x01, 0xb1, 0x01, 0xb9, 0x01, 0xc1, 0x01, 0xc9, 0x01, 0xd1, 0x01, 0xd9, 0x01, 0xe1, 0x01, 0xe9, 0x01, 0xf2, 0x01, 0xfa, 0x02, 0x03, 0x02, 0x0c, 0x02, 0x14, 0x02, 0x1d, 0x02, 0x26, 0x02, 0x2f, 0x02, 0x38, 0x02, 0x41, 0x02, 0x4b, 0x02, 0x54, 0x02, 0x5d, 0x02, 0x67, 0x02, 0x71, 0x02, 0x7a, 0x02, 0x84, 0x02, 0x8e, 0x02, 0x98, 0x02, 0xa2, 0x02, 0xac, 0x02, 0xb6, 0x02, 0xc1, 0x02, 0xcb, 0x02, 0xd5, 0x02, 0xe0, 0x02, 0xeb, 0x02, 0xf5, 0x03, 0x00, 0x03, 0x0b, 0x03, 0x16, 0x03, 0x21, 0x03, 0x2d, 0x03, 0x38, 0x03, 0x43, 0x03, 0x4f, 0x03, 0x5a, 0x03, 0x66, 0x03, 0x72, 0x03, 0x7e, 0x03, 0x8a, 0x03, 0x96, 0x03, 0xa2, 0x03, 0xae, 0x03, 0xba, 0x03, 0xc7, 0x03, 0xd3, 0x03, 0xe0, 0x03, 0xec, 0x03, 0xf9, 0x04, 0x06, 0x04, 0x13, 0x04, 0x20, 0x04, 0x2d, 0x04, 0x3b, 0x04, 0x48, 0x04, 0x55, 0x04, 0x63, 0x04, 0x71, 0x04, 0x7e, 0x04, 0x8c, 0x04, 0x9a, 0x04, 0xa8, 0x04, 0xb6, 0x04, 0xc4, 0x04, 0xd3, 0x04, 0xe1, 0x04, 0xf0, 0x04, 0xfe, 0x05, 0x0d, 0x05, 0x1c, 0x05, 0x2b, 0x05, 0x3a, 0x05, 0x49, 0x05, 0x58, 0x05, 0x67, 0x05, 0x77, 0x05, 0x86, 0x05, 0x96, 0x05, 0xa6, 0x05, 0xb5, 0x05, 0xc5, 0x05, 0xd5, 0x05, 0xe5, 0x05, 0xf6, 0x06, 0x06, 0x06, 0x16, 0x06, 0x27, 0x06, 0x37, 0x06, 0x48, 0x06, 0x59, 0x06, 0x6a, 0x06, 0x7b, 0x06, 0x8c, 0x06, 0x9d, 0x06, 0xaf, 0x06, 0xc0, 0x06, 0xd1, 0x06, 0xe3, 0x06, 0xf5, 0x07, 0x07, 0x07, 0x19, 0x07, 0x2b, 0x07, 0x3d, 0x07, 0x4f, 0x07, 0x61, 0x07, 0x74, 0x07, 0x86, 0x07, 0x99, 0x07, 0xac, 0x07, 0xbf, 0x07, 0xd2, 0x07, 0xe5, 0x07, 0xf8, 0x08, 0x0b, 0x08, 0x1f, 0x08, 0x32, 0x08, 0x46, 0x08, 0x5a, 0x08, 0x6e, 0x08, 0x82, 0x08, 0x96, 0x08, 0xaa, 0x08, 0xbe, 0x08, 0xd2, 0x08, 0xe7, 0x08, 0xfb, 0x09, 0x10, 0x09, 0x25, 0x09, 0x3a, 0x09, 0x4f, 0x09, 0x64, 0x09, 0x79, 0x09, 0x8f, 0x09, 0xa4, 0x09, 0xba, 0x09, 0xcf, 0x09, 0xe5, 0x09, 0xfb, 0x0a, 0x11, 0x0a, 0x27, 0x0a, 0x3d, 0x0a, 0x54, 0x0a, 0x6a, 0x0a, 0x81, 0x0a, 0x98, 0x0a, 0xae, 0x0a, 0xc5, 0x0a, 0xdc, 0x0a, 0xf3, 0x0b, 0x0b, 0x0b, 0x22, 0x0b, 0x39, 0x0b, 0x51, 0x0b, 0x69, 0x0b, 0x80, 0x0b, 0x98, 0x0b, 0xb0, 0x0b, 0xc8, 0x0b, 0xe1, 0x0b, 0xf9, 0x0c, 0x12, 0x0c, 0x2a, 0x0c, 0x43, 0x0c, 0x5c, 0x0c, 0x75, 0x0c, 0x8e, 0x0c, 0xa7, 0x0c, 0xc0, 0x0c, 0xd9, 0x0c, 0xf3, 0x0d, 0x0d, 0x0d, 0x26, 0x0d, 0x40, 0x0d, 0x5a, 0x0d, 0x74, 0x0d, 0x8e, 0x0d, 0xa9, 0x0d, 0xc3, 0x0d, 0xde, 0x0d, 0xf8, 0x0e, 0x13, 0x0e, 0x2e, 0x0e, 0x49, 0x0e, 0x64, 0x0e, 0x7f, 0x0e, 0x9b, 0x0e, 0xb6, 0x0e, 0xd2, 0x0e, 0xee, 0x0f, 0x09, 0x0f, 0x25, 0x0f, 0x41, 0x0f, 0x5e, 0x0f, 0x7a, 0x0f, 0x96, 0x0f, 0xb3, 0x0f, 0xcf, 0x0f, 0xec, 0x10, 0x09, 0x10, 0x26, 0x10, 0x43, 0x10, 0x61, 0x10, 0x7e, 0x10, 0x9b, 0x10, 0xb9, 0x10, 0xd7, 0x10, 0xf5, 0x11, 0x13, 0x11, 0x31, 0x11, 0x4f, 0x11, 0x6d, 0x11, 0x8c, 0x11, 0xaa, 0x11, 0xc9, 0x11, 0xe8, 0x12, 0x07, 0x12, 0x26, 0x12, 0x45, 0x12, 0x64, 0x12, 0x84, 0x12, 0xa3, 0x12, 0xc3, 0x12, 0xe3, 0x13, 0x03, 0x13, 0x23, 0x13, 0x43, 0x13, 0x63, 0x13, 0x83, 0x13, 0xa4, 0x13, 0xc5, 0x13, 0xe5, 0x14, 0x06, 0x14, 0x27, 0x14, 0x49, 0x14, 0x6a, 0x14, 0x8b, 0x14, 0xad, 0x14, 0xce, 0x14, 0xf0, 0x15, 0x12, 0x15, 0x34, 0x15, 0x56, 0x15, 0x78, 0x15, 0x9b, 0x15, 0xbd, 0x15, 0xe0, 0x16, 0x03, 0x16, 0x26, 0x16, 0x49, 0x16, 0x6c, 0x16, 0x8f, 0x16, 0xb2, 0x16, 0xd6, 0x16, 0xfa, 0x17, 0x1d, 0x17, 0x41, 0x17, 0x65, 0x17, 0x89, 0x17, 0xae, 0x17, 0xd2, 0x17, 0xf7, 0x18, 0x1b, 0x18, 0x40, 0x18, 0x65, 0x18, 0x8a, 0x18, 0xaf, 0x18, 0xd5, 0x18, 0xfa, 0x19, 0x20, 0x19, 0x45, 0x19, 0x6b, 0x19, 0x91, 0x19, 0xb7, 0x19, 0xdd, 0x1a, 0x04, 0x1a, 0x2a, 0x1a, 0x51, 0x1a, 0x77, 0x1a, 0x9e, 0x1a, 0xc5, 0x1a, 0xec, 0x1b, 0x14, 0x1b, 0x3b, 0x1b, 0x63, 0x1b, 0x8a, 0x1b, 0xb2, 0x1b, 0xda, 0x1c, 0x02, 0x1c, 0x2a, 0x1c, 0x52, 0x1c, 0x7b, 0x1c, 0xa3, 0x1c, 0xcc, 0x1c, 0xf5, 0x1d, 0x1e, 0x1d, 0x47, 0x1d, 0x70, 0x1d, 0x99, 0x1d, 0xc3, 0x1d, 0xec, 0x1e, 0x16, 0x1e, 0x40, 0x1e, 0x6a, 0x1e, 0x94, 0x1e, 0xbe, 0x1e, 0xe9, 0x1f, 0x13, 0x1f, 0x3e, 0x1f, 0x69, 0x1f, 0x94, 0x1f, 0xbf, 0x1f, 0xea, 0x20, 0x15, 0x20, 0x41, 0x20, 0x6c, 0x20, 0x98, 0x20, 0xc4, 0x20, 0xf0, 0x21, 0x1c, 0x21, 0x48, 0x21, 0x75, 0x21, 0xa1, 0x21, 0xce, 0x21, 0xfb, 0x22, 0x27, 0x22, 0x55, 0x22, 0x82, 0x22, 0xaf, 0x22, 0xdd, 0x23, 0x0a, 0x23, 0x38, 0x23, 0x66, 0x23, 0x94, 0x23, 0xc2, 0x23, 0xf0, 0x24, 0x1f, 0x24, 0x4d, 0x24, 0x7c, 0x24, 0xab, 0x24, 0xda, 0x25, 0x09, 0x25, 0x38, 0x25, 0x68, 0x25, 0x97, 0x25, 0xc7, 0x25, 0xf7, 0x26, 0x27, 0x26, 0x57, 0x26, 0x87, 0x26, 0xb7, 0x26, 0xe8, 0x27, 0x18, 0x27, 0x49, 0x27, 0x7a, 0x27, 0xab, 0x27, 0xdc, 0x28, 0x0d, 0x28, 0x3f, 0x28, 0x71, 0x28, 0xa2, 0x28, 0xd4, 0x29, 0x06, 0x29, 0x38, 0x29, 0x6b, 0x29, 0x9d, 0x29, 0xd0, 0x2a, 0x02, 0x2a, 0x35, 0x2a, 0x68, 0x2a, 0x9b, 0x2a, 0xcf, 0x2b, 0x02, 0x2b, 0x36, 0x2b, 0x69, 0x2b, 0x9d, 0x2b, 0xd1, 0x2c, 0x05, 0x2c, 0x39, 0x2c, 0x6e, 0x2c, 0xa2, 0x2c, 0xd7, 0x2d, 0x0c, 0x2d, 0x41, 0x2d, 0x76, 0x2d, 0xab, 0x2d, 0xe1, 0x2e, 0x16, 0x2e, 0x4c, 0x2e, 0x82, 0x2e, 0xb7, 0x2e, 0xee, 0x2f, 0x24, 0x2f, 0x5a, 0x2f, 0x91, 0x2f, 0xc7, 0x2f, 0xfe, 0x30, 0x35, 0x30, 0x6c, 0x30, 0xa4, 0x30, 0xdb, 0x31, 0x12, 0x31, 0x4a, 0x31, 0x82, 0x31, 0xba, 0x31, 0xf2, 0x32, 0x2a, 0x32, 0x63, 0x32, 0x9b, 0x32, 0xd4, 0x33, 0x0d, 0x33, 0x46, 0x33, 0x7f, 0x33, 0xb8, 0x33, 0xf1, 0x34, 0x2b, 0x34, 0x65, 0x34, 0x9e, 0x34, 0xd8, 0x35, 0x13, 0x35, 0x4d, 0x35, 0x87, 0x35, 0xc2, 0x35, 0xfd, 0x36, 0x37, 0x36, 0x72, 0x36, 0xae, 0x36, 0xe9, 0x37, 0x24, 0x37, 0x60, 0x37, 0x9c, 0x37, 0xd7, 0x38, 0x14, 0x38, 0x50, 0x38, 0x8c, 0x38, 0xc8, 0x39, 0x05, 0x39, 0x42, 0x39, 0x7f, 0x39, 0xbc, 0x39, 0xf9, 0x3a, 0x36, 0x3a, 0x74, 0x3a, 0xb2, 0x3a, 0xef, 0x3b, 0x2d, 0x3b, 0x6b, 0x3b, 0xaa, 0x3b, 0xe8, 0x3c, 0x27, 0x3c, 0x65, 0x3c, 0xa4, 0x3c, 0xe3, 0x3d, 0x22, 0x3d, 0x61, 0x3d, 0xa1, 0x3d, 0xe0, 0x3e, 0x20, 0x3e, 0x60, 0x3e, 0xa0, 0x3e, 0xe0, 0x3f, 0x21, 0x3f, 0x61, 0x3f, 0xa2, 0x3f, 0xe2, 0x40, 0x23, 0x40, 0x64, 0x40, 0xa6, 0x40, 0xe7, 0x41, 0x29, 0x41, 0x6a, 0x41, 0xac, 0x41, 0xee, 0x42, 0x30, 0x42, 0x72, 0x42, 0xb5, 0x42, 0xf7, 0x43, 0x3a, 0x43, 0x7d, 0x43, 0xc0, 0x44, 0x03, 0x44, 0x47, 0x44, 0x8a, 0x44, 0xce, 0x45, 0x12, 0x45, 0x55, 0x45, 0x9a, 0x45, 0xde, 0x46, 0x22, 0x46, 0x67, 0x46, 0xab, 0x46, 0xf0, 0x47, 0x35, 0x47, 0x7b, 0x47, 0xc0, 0x48, 0x05, 0x48, 0x4b, 0x48, 0x91, 0x48, 0xd7, 0x49, 0x1d, 0x49, 0x63, 0x49, 0xa9, 0x49, 0xf0, 0x4a, 0x37, 0x4a, 0x7d, 0x4a, 0xc4, 0x4b, 0x0c, 0x4b, 0x53, 0x4b, 0x9a, 0x4b, 0xe2, 0x4c, 0x2a, 0x4c, 0x72, 0x4c, 0xba, 0x4d, 0x02, 0x4d, 0x4a, 0x4d, 0x93, 0x4d, 0xdc, 0x4e, 0x25, 0x4e, 0x6e, 0x4e, 0xb7, 0x4f, 0x00, 0x4f, 0x49, 0x4f, 0x93, 0x4f, 0xdd, 0x50, 0x27, 0x50, 0x71, 0x50, 0xbb, 0x51, 0x06, 0x51, 0x50, 0x51, 0x9b, 0x51, 0xe6, 0x52, 0x31, 0x52, 0x7c, 0x52, 0xc7, 0x53, 0x13, 0x53, 0x5f, 0x53, 0xaa, 0x53, 0xf6, 0x54, 0x42, 0x54, 0x8f, 0x54, 0xdb, 0x55, 0x28, 0x55, 0x75, 0x55, 0xc2, 0x56, 0x0f, 0x56, 0x5c, 0x56, 0xa9, 0x56, 0xf7, 0x57, 0x44, 0x57, 0x92, 0x57, 0xe0, 0x58, 0x2f, 0x58, 0x7d, 0x58, 0xcb, 0x59, 0x1a, 0x59, 0x69, 0x59, 0xb8, 0x5a, 0x07, 0x5a, 0x56, 0x5a, 0xa6, 0x5a, 0xf5, 0x5b, 0x45, 0x5b, 0x95, 0x5b, 0xe5, 0x5c, 0x35, 0x5c, 0x86, 0x5c, 0xd6, 0x5d, 0x27, 0x5d, 0x78, 0x5d, 0xc9, 0x5e, 0x1a, 0x5e, 0x6c, 0x5e, 0xbd, 0x5f, 0x0f, 0x5f, 0x61, 0x5f, 0xb3, 0x60, 0x05, 0x60, 0x57, 0x60, 0xaa, 0x60, 0xfc, 0x61, 0x4f, 0x61, 0xa2, 0x61, 0xf5, 0x62, 0x49, 0x62, 0x9c, 0x62, 0xf0, 0x63, 0x43, 0x63, 0x97, 0x63, 0xeb, 0x64, 0x40, 0x64, 0x94, 0x64, 0xe9, 0x65, 0x3d, 0x65, 0x92, 0x65, 0xe7, 0x66, 0x3d, 0x66, 0x92, 0x66, 0xe8, 0x67, 0x3d, 0x67, 0x93, 0x67, 0xe9, 0x68, 0x3f, 0x68, 0x96, 0x68, 0xec, 0x69, 0x43, 0x69, 0x9a, 0x69, 0xf1, 0x6a, 0x48, 0x6a, 0x9f, 0x6a, 0xf7, 0x6b, 0x4f, 0x6b, 0xa7, 0x6b, 0xff, 0x6c, 0x57, 0x6c, 0xaf, 0x6d, 0x08, 0x6d, 0x60, 0x6d, 0xb9, 0x6e, 0x12, 0x6e, 0x6b, 0x6e, 0xc4, 0x6f, 0x1e, 0x6f, 0x78, 0x6f, 0xd1, 0x70, 0x2b, 0x70, 0x86, 0x70, 0xe0, 0x71, 0x3a, 0x71, 0x95, 0x71, 0xf0, 0x72, 0x4b, 0x72, 0xa6, 0x73, 0x01, 0x73, 0x5d, 0x73, 0xb8, 0x74, 0x14, 0x74, 0x70, 0x74, 0xcc, 0x75, 0x28, 0x75, 0x85, 0x75, 0xe1, 0x76, 0x3e, 0x76, 0x9b, 0x76, 0xf8, 0x77, 0x56, 0x77, 0xb3, 0x78, 0x11, 0x78, 0x6e, 0x78, 0xcc, 0x79, 0x2a, 0x79, 0x89, 0x79, 0xe7, 0x7a, 0x46, 0x7a, 0xa5, 0x7b, 0x04, 0x7b, 0x63, 0x7b, 0xc2, 0x7c, 0x21, 0x7c, 0x81, 0x7c, 0xe1, 0x7d, 0x41, 0x7d, 0xa1, 0x7e, 0x01, 0x7e, 0x62, 0x7e, 0xc2, 0x7f, 0x23, 0x7f, 0x84, 0x7f, 0xe5, 0x80, 0x47, 0x80, 0xa8, 0x81, 0x0a, 0x81, 0x6b, 0x81, 0xcd, 0x82, 0x30, 0x82, 0x92, 0x82, 0xf4, 0x83, 0x57, 0x83, 0xba, 0x84, 0x1d, 0x84, 0x80, 0x84, 0xe3, 0x85, 0x47, 0x85, 0xab, 0x86, 0x0e, 0x86, 0x72, 0x86, 0xd7, 0x87, 0x3b, 0x87, 0x9f, 0x88, 0x04, 0x88, 0x69, 0x88, 0xce, 0x89, 0x33, 0x89, 0x99, 0x89, 0xfe, 0x8a, 0x64, 0x8a, 0xca, 0x8b, 0x30, 0x8b, 0x96, 0x8b, 0xfc, 0x8c, 0x63, 0x8c, 0xca, 0x8d, 0x31, 0x8d, 0x98, 0x8d, 0xff, 0x8e, 0x66, 0x8e, 0xce, 0x8f, 0x36, 0x8f, 0x9e, 0x90, 0x06, 0x90, 0x6e, 0x90, 0xd6, 0x91, 0x3f, 0x91, 0xa8, 0x92, 0x11, 0x92, 0x7a, 0x92, 0xe3, 0x93, 0x4d, 0x93, 0xb6, 0x94, 0x20, 0x94, 0x8a, 0x94, 0xf4, 0x95, 0x5f, 0x95, 0xc9, 0x96, 0x34, 0x96, 0x9f, 0x97, 0x0a, 0x97, 0x75, 0x97, 0xe0, 0x98, 0x4c, 0x98, 0xb8, 0x99, 0x24, 0x99, 0x90, 0x99, 0xfc, 0x9a, 0x68, 0x9a, 0xd5, 0x9b, 0x42, 0x9b, 0xaf, 0x9c, 0x1c, 0x9c, 0x89, 0x9c, 0xf7, 0x9d, 0x64, 0x9d, 0xd2, 0x9e, 0x40, 0x9e, 0xae, 0x9f, 0x1d, 0x9f, 0x8b, 0x9f, 0xfa, 0xa0, 0x69, 0xa0, 0xd8, 0xa1, 0x47, 0xa1, 0xb6, 0xa2, 0x26, 0xa2, 0x96, 0xa3, 0x06, 0xa3, 0x76, 0xa3, 0xe6, 0xa4, 0x56, 0xa4, 0xc7, 0xa5, 0x38, 0xa5, 0xa9, 0xa6, 0x1a, 0xa6, 0x8b, 0xa6, 0xfd, 0xa7, 0x6e, 0xa7, 0xe0, 0xa8, 0x52, 0xa8, 0xc4, 0xa9, 0x37, 0xa9, 0xa9, 0xaa, 0x1c, 0xaa, 0x8f, 0xab, 0x02, 0xab, 0x75, 0xab, 0xe9, 0xac, 0x5c, 0xac, 0xd0, 0xad, 0x44, 0xad, 0xb8, 0xae, 0x2d, 0xae, 0xa1, 0xaf, 0x16, 0xaf, 0x8b, 0xb0, 0x00, 0xb0, 0x75, 0xb0, 0xea, 0xb1, 0x60, 0xb1, 0xd6, 0xb2, 0x4b, 0xb2, 0xc2, 0xb3, 0x38, 0xb3, 0xae, 0xb4, 0x25, 0xb4, 0x9c, 0xb5, 0x13, 0xb5, 0x8a, 0xb6, 0x01, 0xb6, 0x79, 0xb6, 0xf0, 0xb7, 0x68, 0xb7, 0xe0, 0xb8, 0x59, 0xb8, 0xd1, 0xb9, 0x4a, 0xb9, 0xc2, 0xba, 0x3b, 0xba, 0xb5, 0xbb, 0x2e, 0xbb, 0xa7, 0xbc, 0x21, 0xbc, 0x9b, 0xbd, 0x15, 0xbd, 0x8f, 0xbe, 0x0a, 0xbe, 0x84, 0xbe, 0xff, 0xbf, 0x7a, 0xbf, 0xf5, 0xc0, 0x70, 0xc0, 0xec, 0xc1, 0x67, 0xc1, 0xe3, 0xc2, 0x5f, 0xc2, 0xdb, 0xc3, 0x58, 0xc3, 0xd4, 0xc4, 0x51, 0xc4, 0xce, 0xc5, 0x4b, 0xc5, 0xc8, 0xc6, 0x46, 0xc6, 0xc3, 0xc7, 0x41, 0xc7, 0xbf, 0xc8, 0x3d, 0xc8, 0xbc, 0xc9, 0x3a, 0xc9, 0xb9, 0xca, 0x38, 0xca, 0xb7, 0xcb, 0x36, 0xcb, 0xb6, 0xcc, 0x35, 0xcc, 0xb5, 0xcd, 0x35, 0xcd, 0xb5, 0xce, 0x36, 0xce, 0xb6, 0xcf, 0x37, 0xcf, 0xb8, 0xd0, 0x39, 0xd0, 0xba, 0xd1, 0x3c, 0xd1, 0xbe, 0xd2, 0x3f, 0xd2, 0xc1, 0xd3, 0x44, 0xd3, 0xc6, 0xd4, 0x49, 0xd4, 0xcb, 0xd5, 0x4e, 0xd5, 0xd1, 0xd6, 0x55, 0xd6, 0xd8, 0xd7, 0x5c, 0xd7, 0xe0, 0xd8, 0x64, 0xd8, 0xe8, 0xd9, 0x6c, 0xd9, 0xf1, 0xda, 0x76, 0xda, 0xfb, 0xdb, 0x80, 0xdc, 0x05, 0xdc, 0x8a, 0xdd, 0x10, 0xdd, 0x96, 0xde, 0x1c, 0xde, 0xa2, 0xdf, 0x29, 0xdf, 0xaf, 0xe0, 0x36, 0xe0, 0xbd, 0xe1, 0x44, 0xe1, 0xcc, 0xe2, 0x53, 0xe2, 0xdb, 0xe3, 0x63, 0xe3, 0xeb, 0xe4, 0x73, 0xe4, 0xfc, 0xe5, 0x84, 0xe6, 0x0d, 0xe6, 0x96, 0xe7, 0x1f, 0xe7, 0xa9, 0xe8, 0x32, 0xe8, 0xbc, 0xe9, 0x46, 0xe9, 0xd0, 0xea, 0x5b, 0xea, 0xe5, 0xeb, 0x70, 0xeb, 0xfb, 0xec, 0x86, 0xed, 0x11, 0xed, 0x9c, 0xee, 0x28, 0xee, 0xb4, 0xef, 0x40, 0xef, 0xcc, 0xf0, 0x58, 0xf0, 0xe5, 0xf1, 0x72, 0xf1, 0xff, 0xf2, 0x8c, 0xf3, 0x19, 0xf3, 0xa7, 0xf4, 0x34, 0xf4, 0xc2, 0xf5, 0x50, 0xf5, 0xde, 0xf6, 0x6d, 0xf6, 0xfb, 0xf7, 0x8a, 0xf8, 0x19, 0xf8, 0xa8, 0xf9, 0x38, 0xf9, 0xc7, 0xfa, 0x57, 0xfa, 0xe7, 0xfb, 0x77, 0xfc, 0x07, 0xfc, 0x98, 0xfd, 0x29, 0xfd, 0xba, 0xfe, 0x4b, 0xfe, 0xdc, 0xff, 0x6d, 0xff, 0xff }; StringInfo *profile; MagickBooleanType status; assert(image != (Image *) NULL); assert(image->signature == MagickCoreSignature); if (GetImageProfile(image,"icc") != (const StringInfo *) NULL) return(MagickFalse); profile=AcquireStringInfo(sizeof(sRGBProfile)); SetStringInfoDatum(profile,sRGBProfile); status=SetImageProfile(image,"icc",profile,exception); profile=DestroyStringInfo(profile); return(status); } MagickExport MagickBooleanType ProfileImage(Image *image,const char *name, const void *datum,const size_t length,ExceptionInfo *exception) { #define ProfileImageTag "Profile/Image" #define ThrowProfileException(severity,tag,context) \ { \ if (source_profile != (cmsHPROFILE) NULL) \ (void) cmsCloseProfile(source_profile); \ if (target_profile != (cmsHPROFILE) NULL) \ (void) cmsCloseProfile(target_profile); \ ThrowBinaryException(severity,tag,context); \ } MagickBooleanType status; StringInfo *profile; assert(image != (Image *) NULL); assert(image->signature == MagickCoreSignature); if (image->debug != MagickFalse) (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename); assert(name != (const char *) NULL); if ((datum == (const void *) NULL) || (length == 0)) { char *next; /* Delete image profile(s). */ ResetImageProfileIterator(image); for (next=GetNextImageProfile(image); next != (const char *) NULL; ) { if (IsOptionMember(next,name) != MagickFalse) { (void) DeleteImageProfile(image,next); ResetImageProfileIterator(image); } next=GetNextImageProfile(image); } return(MagickTrue); } /* Add a ICC, IPTC, or generic profile to the image. */ status=MagickTrue; profile=AcquireStringInfo((size_t) length); SetStringInfoDatum(profile,(unsigned char *) datum); if ((LocaleCompare(name,"icc") != 0) && (LocaleCompare(name,"icm") != 0)) status=SetImageProfile(image,name,profile,exception); else { const StringInfo *icc_profile; icc_profile=GetImageProfile(image,"icc"); if ((icc_profile != (const StringInfo *) NULL) && (CompareStringInfo(icc_profile,profile) == 0)) { const char *value; value=GetImageProperty(image,"exif:ColorSpace",exception); (void) value; if (LocaleCompare(value,"1") != 0) (void) SetsRGBImageProfile(image,exception); value=GetImageProperty(image,"exif:InteroperabilityIndex",exception); if (LocaleCompare(value,"R98.") != 0) (void) SetsRGBImageProfile(image,exception); /* Future. value=GetImageProperty(image,"exif:InteroperabilityIndex",exception); if (LocaleCompare(value,"R03.") != 0) (void) SetAdobeRGB1998ImageProfile(image,exception); */ icc_profile=GetImageProfile(image,"icc"); } if ((icc_profile != (const StringInfo *) NULL) && (CompareStringInfo(icc_profile,profile) == 0)) { profile=DestroyStringInfo(profile); return(MagickTrue); } #if !defined(MAGICKCORE_LCMS_DELEGATE) (void) ThrowMagickException(exception,GetMagickModule(), MissingDelegateWarning,"DelegateLibrarySupportNotBuiltIn", "'%s' (LCMS)",image->filename); #else { cmsHPROFILE source_profile; CMSExceptionInfo cms_exception; /* Transform pixel colors as defined by the color profiles. */ cmsSetLogErrorHandler(CMSExceptionHandler); cms_exception.image=image; cms_exception.exception=exception; (void) cms_exception; source_profile=cmsOpenProfileFromMemTHR((cmsContext) &cms_exception, GetStringInfoDatum(profile),(cmsUInt32Number) GetStringInfoLength(profile)); if (source_profile == (cmsHPROFILE) NULL) ThrowBinaryException(ResourceLimitError, "ColorspaceColorProfileMismatch",name); if ((cmsGetDeviceClass(source_profile) != cmsSigLinkClass) && (icc_profile == (StringInfo *) NULL)) status=SetImageProfile(image,name,profile,exception); else { CacheView *image_view; ColorspaceType source_colorspace, target_colorspace; cmsColorSpaceSignature signature; cmsHPROFILE target_profile; cmsHTRANSFORM *magick_restrict transform; cmsUInt32Number flags, source_type, target_type; int intent; MagickOffsetType progress; size_t source_channels, target_channels; ssize_t y; unsigned short **magick_restrict source_pixels, **magick_restrict target_pixels; target_profile=(cmsHPROFILE) NULL; if (icc_profile != (StringInfo *) NULL) { target_profile=source_profile; source_profile=cmsOpenProfileFromMemTHR((cmsContext) &cms_exception,GetStringInfoDatum(icc_profile), (cmsUInt32Number) GetStringInfoLength(icc_profile)); if (source_profile == (cmsHPROFILE) NULL) ThrowProfileException(ResourceLimitError, "ColorspaceColorProfileMismatch",name); } switch (cmsGetColorSpace(source_profile)) { case cmsSigCmykData: { source_colorspace=CMYKColorspace; source_type=(cmsUInt32Number) TYPE_CMYK_16; source_channels=4; break; } case cmsSigGrayData: { source_colorspace=GRAYColorspace; source_type=(cmsUInt32Number) TYPE_GRAY_16; source_channels=1; break; } case cmsSigLabData: { source_colorspace=LabColorspace; source_type=(cmsUInt32Number) TYPE_Lab_16; source_channels=3; break; } case cmsSigLuvData: { source_colorspace=YUVColorspace; source_type=(cmsUInt32Number) TYPE_YUV_16; source_channels=3; break; } case cmsSigRgbData: { source_colorspace=sRGBColorspace; source_type=(cmsUInt32Number) TYPE_RGB_16; source_channels=3; break; } case cmsSigXYZData: { source_colorspace=XYZColorspace; source_type=(cmsUInt32Number) TYPE_XYZ_16; source_channels=3; break; } case cmsSigYCbCrData: { source_colorspace=YCbCrColorspace; source_type=(cmsUInt32Number) TYPE_YCbCr_16; source_channels=3; break; } default: { source_colorspace=UndefinedColorspace; source_type=(cmsUInt32Number) TYPE_RGB_16; source_channels=3; break; } } signature=cmsGetPCS(source_profile); if (target_profile != (cmsHPROFILE) NULL) signature=cmsGetColorSpace(target_profile); switch (signature) { case cmsSigCmykData: { target_colorspace=CMYKColorspace; target_type=(cmsUInt32Number) TYPE_CMYK_16; target_channels=4; break; } case cmsSigLabData: { target_colorspace=LabColorspace; target_type=(cmsUInt32Number) TYPE_Lab_16; target_channels=3; break; } case cmsSigGrayData: { target_colorspace=GRAYColorspace; target_type=(cmsUInt32Number) TYPE_GRAY_16; target_channels=1; break; } case cmsSigLuvData: { target_colorspace=YUVColorspace; target_type=(cmsUInt32Number) TYPE_YUV_16; target_channels=3; break; } case cmsSigRgbData: { target_colorspace=sRGBColorspace; target_type=(cmsUInt32Number) TYPE_RGB_16; target_channels=3; break; } case cmsSigXYZData: { target_colorspace=XYZColorspace; target_type=(cmsUInt32Number) TYPE_XYZ_16; target_channels=3; break; } case cmsSigYCbCrData: { target_colorspace=YCbCrColorspace; target_type=(cmsUInt32Number) TYPE_YCbCr_16; target_channels=3; break; } default: { target_colorspace=UndefinedColorspace; target_type=(cmsUInt32Number) TYPE_RGB_16; target_channels=3; break; } } if ((source_colorspace == UndefinedColorspace) || (target_colorspace == UndefinedColorspace)) ThrowProfileException(ImageError,"ColorspaceColorProfileMismatch", name); if ((source_colorspace == GRAYColorspace) && (SetImageGray(image,exception) == MagickFalse)) ThrowProfileException(ImageError,"ColorspaceColorProfileMismatch", name); if ((source_colorspace == CMYKColorspace) && (image->colorspace != CMYKColorspace)) ThrowProfileException(ImageError,"ColorspaceColorProfileMismatch", name); if ((source_colorspace == XYZColorspace) && (image->colorspace != XYZColorspace)) ThrowProfileException(ImageError,"ColorspaceColorProfileMismatch", name); if ((source_colorspace == YCbCrColorspace) && (image->colorspace != YCbCrColorspace)) ThrowProfileException(ImageError,"ColorspaceColorProfileMismatch", name); if ((source_colorspace != CMYKColorspace) && (source_colorspace != LabColorspace) && (source_colorspace != XYZColorspace) && (source_colorspace != YCbCrColorspace) && (IssRGBCompatibleColorspace(image->colorspace) == MagickFalse)) ThrowProfileException(ImageError,"ColorspaceColorProfileMismatch", name); switch (image->rendering_intent) { case AbsoluteIntent: intent=INTENT_ABSOLUTE_COLORIMETRIC; break; case PerceptualIntent: intent=INTENT_PERCEPTUAL; break; case RelativeIntent: intent=INTENT_RELATIVE_COLORIMETRIC; break; case SaturationIntent: intent=INTENT_SATURATION; break; default: intent=INTENT_PERCEPTUAL; break; } flags=cmsFLAGS_HIGHRESPRECALC; #if defined(cmsFLAGS_BLACKPOINTCOMPENSATION) if (image->black_point_compensation != MagickFalse) flags|=cmsFLAGS_BLACKPOINTCOMPENSATION; #endif transform=AcquireTransformThreadSet(image,source_profile, source_type,target_profile,target_type,intent,flags); if (transform == (cmsHTRANSFORM *) NULL) ThrowProfileException(ImageError,"UnableToCreateColorTransform", name); /* Transform image as dictated by the source & target image profiles. */ source_pixels=AcquirePixelThreadSet(image->columns,source_channels); target_pixels=AcquirePixelThreadSet(image->columns,target_channels); if ((source_pixels == (unsigned short **) NULL) || (target_pixels == (unsigned short **) NULL)) { transform=DestroyTransformThreadSet(transform); ThrowProfileException(ResourceLimitError, "MemoryAllocationFailed",image->filename); } if (SetImageStorageClass(image,DirectClass,exception) == MagickFalse) { target_pixels=DestroyPixelThreadSet(target_pixels); source_pixels=DestroyPixelThreadSet(source_pixels); transform=DestroyTransformThreadSet(transform); if (source_profile != (cmsHPROFILE) NULL) (void) cmsCloseProfile(source_profile); if (target_profile != (cmsHPROFILE) NULL) (void) cmsCloseProfile(target_profile); return(MagickFalse); } if (target_colorspace == CMYKColorspace) (void) SetImageColorspace(image,target_colorspace,exception); progress=0; image_view=AcquireAuthenticCacheView(image,exception); #if defined(MAGICKCORE_OPENMP_SUPPORT) #pragma omp parallel for schedule(static,4) shared(status) \ magick_threads(image,image,image->rows,1) #endif for (y=0; y < (ssize_t) image->rows; y++) { const int id = GetOpenMPThreadId(); MagickBooleanType sync; register ssize_t x; register Quantum *magick_restrict q; register unsigned short *p; if (status == MagickFalse) continue; q=GetCacheViewAuthenticPixels(image_view,0,y,image->columns,1, exception); if (q == (Quantum *) NULL) { status=MagickFalse; continue; } p=source_pixels[id]; for (x=0; x < (ssize_t) image->columns; x++) { *p++=ScaleQuantumToShort(GetPixelRed(image,q)); if (source_channels > 1) { *p++=ScaleQuantumToShort(GetPixelGreen(image,q)); *p++=ScaleQuantumToShort(GetPixelBlue(image,q)); } if (source_channels > 3) *p++=ScaleQuantumToShort(GetPixelBlack(image,q)); q+=GetPixelChannels(image); } cmsDoTransform(transform[id],source_pixels[id],target_pixels[id], (unsigned int) image->columns); p=target_pixels[id]; q-=GetPixelChannels(image)*image->columns; for (x=0; x < (ssize_t) image->columns; x++) { if (target_channels == 1) SetPixelGray(image,ScaleShortToQuantum(*p),q); else SetPixelRed(image,ScaleShortToQuantum(*p),q); p++; if (target_channels > 1) { SetPixelGreen(image,ScaleShortToQuantum(*p),q); p++; SetPixelBlue(image,ScaleShortToQuantum(*p),q); p++; } if (target_channels > 3) { SetPixelBlack(image,ScaleShortToQuantum(*p),q); p++; } q+=GetPixelChannels(image); } sync=SyncCacheViewAuthenticPixels(image_view,exception); if (sync == MagickFalse) status=MagickFalse; if (image->progress_monitor != (MagickProgressMonitor) NULL) { MagickBooleanType proceed; #if defined(MAGICKCORE_OPENMP_SUPPORT) #pragma omp critical (MagickCore_ProfileImage) #endif proceed=SetImageProgress(image,ProfileImageTag,progress++, image->rows); if (proceed == MagickFalse) status=MagickFalse; } } image_view=DestroyCacheView(image_view); (void) SetImageColorspace(image,target_colorspace,exception); switch (signature) { case cmsSigRgbData: { image->type=image->alpha_trait == UndefinedPixelTrait ? TrueColorType : TrueColorAlphaType; break; } case cmsSigCmykData: { image->type=image->alpha_trait == UndefinedPixelTrait ? ColorSeparationType : ColorSeparationAlphaType; break; } case cmsSigGrayData: { image->type=image->alpha_trait == UndefinedPixelTrait ? GrayscaleType : GrayscaleAlphaType; break; } default: break; } target_pixels=DestroyPixelThreadSet(target_pixels); source_pixels=DestroyPixelThreadSet(source_pixels); transform=DestroyTransformThreadSet(transform); if ((status != MagickFalse) && (cmsGetDeviceClass(source_profile) != cmsSigLinkClass)) status=SetImageProfile(image,name,profile,exception); if (target_profile != (cmsHPROFILE) NULL) (void) cmsCloseProfile(target_profile); } (void) cmsCloseProfile(source_profile); } #endif } profile=DestroyStringInfo(profile); return(status); } /* %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% % % % % % % % R e m o v e I m a g e P r o f i l e % % % % % % % %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% % % RemoveImageProfile() removes a named profile from the image and returns its % value. % % The format of the RemoveImageProfile method is: % % void *RemoveImageProfile(Image *image,const char *name) % % A description of each parameter follows: % % o image: the image. % % o name: the profile name. % */ MagickExport StringInfo *RemoveImageProfile(Image *image,const char *name) { StringInfo *profile; assert(image != (Image *) NULL); assert(image->signature == MagickCoreSignature); if (image->debug != MagickFalse) (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename); if (image->profiles == (SplayTreeInfo *) NULL) return((StringInfo *) NULL); WriteTo8BimProfile(image,name,(StringInfo *) NULL); profile=(StringInfo *) RemoveNodeFromSplayTree((SplayTreeInfo *) image->profiles,name); return(profile); } /* %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% % % % % % % % R e s e t P r o f i l e I t e r a t o r % % % % % % % %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% % % ResetImageProfileIterator() resets the image profile iterator. Use it in % conjunction with GetNextImageProfile() to iterate over all the profiles % associated with an image. % % The format of the ResetImageProfileIterator method is: % % ResetImageProfileIterator(Image *image) % % A description of each parameter follows: % % o image: the image. % */ MagickExport void ResetImageProfileIterator(const Image *image) { assert(image != (Image *) NULL); assert(image->signature == MagickCoreSignature); if (image->debug != MagickFalse) (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename); if (image->profiles == (SplayTreeInfo *) NULL) return; ResetSplayTreeIterator((SplayTreeInfo *) image->profiles); } /* %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% % % % % % % % S e t I m a g e P r o f i l e % % % % % % % %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% % % SetImageProfile() adds a named profile to the image. If a profile with the % same name already exists, it is replaced. This method differs from the % ProfileImage() method in that it does not apply CMS color profiles. % % The format of the SetImageProfile method is: % % MagickBooleanType SetImageProfile(Image *image,const char *name, % const StringInfo *profile) % % A description of each parameter follows: % % o image: the image. % % o name: the profile name, for example icc, exif, and 8bim (8bim is the % Photoshop wrapper for iptc profiles). % % o profile: A StringInfo structure that contains the named profile. % */ static void *DestroyProfile(void *profile) { return((void *) DestroyStringInfo((StringInfo *) profile)); } static inline const unsigned char *ReadResourceByte(const unsigned char *p, unsigned char *quantum) { *quantum=(*p++); return(p); } static inline const unsigned char *ReadResourceLong(const unsigned char *p, unsigned int *quantum) { *quantum=(unsigned int) (*p++) << 24; *quantum|=(unsigned int) (*p++) << 16; *quantum|=(unsigned int) (*p++) << 8; *quantum|=(unsigned int) (*p++) << 0; return(p); } static inline const unsigned char *ReadResourceShort(const unsigned char *p, unsigned short *quantum) { *quantum=(unsigned short) (*p++) << 8; *quantum|=(unsigned short) (*p++); return(p); } static inline void WriteResourceLong(unsigned char *p, const unsigned int quantum) { unsigned char buffer[4]; buffer[0]=(unsigned char) (quantum >> 24); buffer[1]=(unsigned char) (quantum >> 16); buffer[2]=(unsigned char) (quantum >> 8); buffer[3]=(unsigned char) quantum; (void) CopyMagickMemory(p,buffer,4); } static void WriteTo8BimProfile(Image *image,const char *name, const StringInfo *profile) { const unsigned char *datum, *q; register const unsigned char *p; size_t length; StringInfo *profile_8bim; ssize_t count; unsigned char length_byte; unsigned int value; unsigned short id, profile_id; if (LocaleCompare(name,"icc") == 0) profile_id=0x040f; else if (LocaleCompare(name,"iptc") == 0) profile_id=0x0404; else if (LocaleCompare(name,"xmp") == 0) profile_id=0x0424; else return; profile_8bim=(StringInfo *) GetValueFromSplayTree((SplayTreeInfo *) image->profiles,"8bim"); if (profile_8bim == (StringInfo *) NULL) return; datum=GetStringInfoDatum(profile_8bim); length=GetStringInfoLength(profile_8bim); for (p=datum; p < (datum+length-16); ) { q=p; if (LocaleNCompare((char *) p,"8BIM",4) != 0) break; p+=4; p=ReadResourceShort(p,&id); p=ReadResourceByte(p,&length_byte); p+=length_byte; if (((length_byte+1) & 0x01) != 0) p++; if (p > (datum+length-4)) break; p=ReadResourceLong(p,&value); count=(ssize_t) value; if ((count & 0x01) != 0) count++; if ((count < 0) || (p > (datum+length-count)) || (count > (ssize_t) length)) break; if (id != profile_id) p+=count; else { size_t extent, offset; ssize_t extract_count; StringInfo *extract_profile; extract_count=0; extent=(datum+length)-(p+count); if (profile == (StringInfo *) NULL) { offset=(q-datum); extract_profile=AcquireStringInfo(offset+extent); (void) CopyMagickMemory(extract_profile->datum,datum,offset); } else { offset=(p-datum); extract_count=profile->length; if ((extract_count & 0x01) != 0) extract_count++; extract_profile=AcquireStringInfo(offset+extract_count+extent); (void) CopyMagickMemory(extract_profile->datum,datum,offset-4); WriteResourceLong(extract_profile->datum+offset-4, (unsigned int)profile->length); (void) CopyMagickMemory(extract_profile->datum+offset, profile->datum,profile->length); } (void) CopyMagickMemory(extract_profile->datum+offset+extract_count, p+count,extent); (void) AddValueToSplayTree((SplayTreeInfo *) image->profiles, ConstantString("8bim"),CloneStringInfo(extract_profile)); extract_profile=DestroyStringInfo(extract_profile); break; } } } static void GetProfilesFromResourceBlock(Image *image, const StringInfo *resource_block,ExceptionInfo *exception) { const unsigned char *datum; register const unsigned char *p; size_t length; ssize_t count; StringInfo *profile; unsigned char length_byte; unsigned int value; unsigned short id; datum=GetStringInfoDatum(resource_block); length=GetStringInfoLength(resource_block); for (p=datum; p < (datum+length-16); ) { if (LocaleNCompare((char *) p,"8BIM",4) != 0) break; p+=4; p=ReadResourceShort(p,&id); p=ReadResourceByte(p,&length_byte); p+=length_byte; if (((length_byte+1) & 0x01) != 0) p++; if (p > (datum+length-4)) break; p=ReadResourceLong(p,&value); count=(ssize_t) value; if ((p > (datum+length-count)) || (count > (ssize_t) length) || (count < 0)) break; switch (id) { case 0x03ed: { unsigned int resolution; unsigned short units; /* Resolution. */ p=ReadResourceLong(p,&resolution); image->resolution.x=((double) resolution)/65536.0; p=ReadResourceShort(p,&units)+2; p=ReadResourceLong(p,&resolution)+4; image->resolution.y=((double) resolution)/65536.0; /* Values are always stored as pixels per inch. */ if ((ResolutionType) units != PixelsPerCentimeterResolution) image->units=PixelsPerInchResolution; else { image->units=PixelsPerCentimeterResolution; image->resolution.x/=2.54; image->resolution.y/=2.54; } break; } case 0x0404: { /* IPTC Profile */ profile=AcquireStringInfo(count); SetStringInfoDatum(profile,p); (void) SetImageProfileInternal(image,"iptc",profile,MagickTrue, exception); profile=DestroyStringInfo(profile); p+=count; break; } case 0x040c: { /* Thumbnail. */ p+=count; break; } case 0x040f: { /* ICC Profile. */ profile=AcquireStringInfo(count); SetStringInfoDatum(profile,p); (void) SetImageProfileInternal(image,"icc",profile,MagickTrue, exception); profile=DestroyStringInfo(profile); p+=count; break; } case 0x0422: { /* EXIF Profile. */ profile=AcquireStringInfo(count); SetStringInfoDatum(profile,p); (void) SetImageProfileInternal(image,"exif",profile,MagickTrue, exception); profile=DestroyStringInfo(profile); p+=count; break; } case 0x0424: { /* XMP Profile. */ profile=AcquireStringInfo(count); SetStringInfoDatum(profile,p); (void) SetImageProfileInternal(image,"xmp",profile,MagickTrue, exception); profile=DestroyStringInfo(profile); p+=count; break; } default: { p+=count; break; } } if ((count & 0x01) != 0) p++; } } static MagickBooleanType SetImageProfileInternal(Image *image,const char *name, const StringInfo *profile,const MagickBooleanType recursive, ExceptionInfo *exception) { char key[MagickPathExtent], property[MagickPathExtent]; MagickBooleanType status; assert(image != (Image *) NULL); assert(image->signature == MagickCoreSignature); if (image->debug != MagickFalse) (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename); if (image->profiles == (SplayTreeInfo *) NULL) image->profiles=NewSplayTree(CompareSplayTreeString,RelinquishMagickMemory, DestroyProfile); (void) CopyMagickString(key,name,MagickPathExtent); LocaleLower(key); status=AddValueToSplayTree((SplayTreeInfo *) image->profiles, ConstantString(key),CloneStringInfo(profile)); if (status != MagickFalse) { if (LocaleCompare(name,"8bim") == 0) GetProfilesFromResourceBlock(image,profile,exception); else if (recursive == MagickFalse) WriteTo8BimProfile(image,name,profile); } /* Inject profile into image properties. */ (void) FormatLocaleString(property,MagickPathExtent,"%s:*",name); (void) GetImageProperty(image,property,exception); return(status); } MagickExport MagickBooleanType SetImageProfile(Image *image,const char *name, const StringInfo *profile,ExceptionInfo *exception) { return(SetImageProfileInternal(image,name,profile,MagickFalse,exception)); } /* %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% % % % % % % % S y n c I m a g e P r o f i l e s % % % % % % % %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% % % SyncImageProfiles() synchronizes image properties with the image profiles. % Currently we only support updating the EXIF resolution and orientation. % % The format of the SyncImageProfiles method is: % % MagickBooleanType SyncImageProfiles(Image *image) % % A description of each parameter follows: % % o image: the image. % */ static inline int ReadProfileByte(unsigned char **p,size_t *length) { int c; if (*length < 1) return(EOF); c=(int) (*(*p)++); (*length)--; return(c); } static inline signed short ReadProfileShort(const EndianType endian, unsigned char *buffer) { union { unsigned int unsigned_value; signed int signed_value; } quantum; unsigned short value; if (endian == LSBEndian) { value=(unsigned short) buffer[1] << 8; value|=(unsigned short) buffer[0]; quantum.unsigned_value=value & 0xffff; return(quantum.signed_value); } value=(unsigned short) buffer[0] << 8; value|=(unsigned short) buffer[1]; quantum.unsigned_value=value & 0xffff; return(quantum.signed_value); } static inline signed int ReadProfileLong(const EndianType endian, unsigned char *buffer) { union { unsigned int unsigned_value; signed int signed_value; } quantum; unsigned int value; if (endian == LSBEndian) { value=(unsigned int) buffer[3] << 24; value|=(unsigned int) buffer[2] << 16; value|=(unsigned int) buffer[1] << 8; value|=(unsigned int) buffer[0]; quantum.unsigned_value=value & 0xffffffff; return(quantum.signed_value); } value=(unsigned int) buffer[0] << 24; value|=(unsigned int) buffer[1] << 16; value|=(unsigned int) buffer[2] << 8; value|=(unsigned int) buffer[3]; quantum.unsigned_value=value & 0xffffffff; return(quantum.signed_value); } static inline signed int ReadProfileMSBLong(unsigned char **p,size_t *length) { signed int value; if (*length < 4) return(0); value=ReadProfileLong(MSBEndian,*p); (*length)-=4; *p+=4; return(value); } static inline signed short ReadProfileMSBShort(unsigned char **p, size_t *length) { signed short value; if (*length < 2) return(0); value=ReadProfileShort(MSBEndian,*p); (*length)-=2; *p+=2; return(value); } static inline void WriteProfileLong(const EndianType endian, const size_t value,unsigned char *p) { unsigned char buffer[4]; if (endian == LSBEndian) { buffer[0]=(unsigned char) value; buffer[1]=(unsigned char) (value >> 8); buffer[2]=(unsigned char) (value >> 16); buffer[3]=(unsigned char) (value >> 24); (void) CopyMagickMemory(p,buffer,4); return; } buffer[0]=(unsigned char) (value >> 24); buffer[1]=(unsigned char) (value >> 16); buffer[2]=(unsigned char) (value >> 8); buffer[3]=(unsigned char) value; (void) CopyMagickMemory(p,buffer,4); } static void WriteProfileShort(const EndianType endian, const unsigned short value,unsigned char *p) { unsigned char buffer[2]; if (endian == LSBEndian) { buffer[0]=(unsigned char) value; buffer[1]=(unsigned char) (value >> 8); (void) CopyMagickMemory(p,buffer,2); return; } buffer[0]=(unsigned char) (value >> 8); buffer[1]=(unsigned char) value; (void) CopyMagickMemory(p,buffer,2); } static MagickBooleanType Sync8BimProfile(Image *image,StringInfo *profile) { size_t length; ssize_t count; unsigned char *p; unsigned short id; length=GetStringInfoLength(profile); p=GetStringInfoDatum(profile); while (length != 0) { if (ReadProfileByte(&p,&length) != 0x38) continue; if (ReadProfileByte(&p,&length) != 0x42) continue; if (ReadProfileByte(&p,&length) != 0x49) continue; if (ReadProfileByte(&p,&length) != 0x4D) continue; if (length < 7) return(MagickFalse); id=ReadProfileMSBShort(&p,&length); count=(ssize_t) ReadProfileByte(&p,&length); if ((count > (ssize_t) length) || (count < 0)) return(MagickFalse); p+=count; if ((*p & 0x01) == 0) (void) ReadProfileByte(&p,&length); count=(ssize_t) ReadProfileMSBLong(&p,&length); if ((count > (ssize_t) length) || (count < 0)) return(MagickFalse); if ((id == 0x3ED) && (count == 16)) { if (image->units == PixelsPerCentimeterResolution) WriteProfileLong(MSBEndian, (unsigned int) (image->resolution.x*2.54* 65536.0),p); else WriteProfileLong(MSBEndian, (unsigned int) (image->resolution.x* 65536.0),p); WriteProfileShort(MSBEndian,(unsigned short) image->units,p+4); if (image->units == PixelsPerCentimeterResolution) WriteProfileLong(MSBEndian, (unsigned int) (image->resolution.y*2.54* 65536.0),p+8); else WriteProfileLong(MSBEndian, (unsigned int) (image->resolution.y* 65536.0),p+8); WriteProfileShort(MSBEndian,(unsigned short) image->units,p+12); } p+=count; length-=count; } return(MagickTrue); } MagickBooleanType SyncExifProfile(Image *image,StringInfo *profile) { #define MaxDirectoryStack 16 #define EXIF_DELIMITER "\n" #define EXIF_NUM_FORMATS 12 #define TAG_EXIF_OFFSET 0x8769 #define TAG_INTEROP_OFFSET 0xa005 typedef struct _DirectoryInfo { unsigned char *directory; size_t entry; } DirectoryInfo; DirectoryInfo directory_stack[MaxDirectoryStack]; EndianType endian; size_t entry, length, number_entries; ssize_t id, level, offset; static int format_bytes[] = {0, 1, 1, 2, 4, 8, 1, 1, 2, 4, 8, 4, 8}; unsigned char *directory, *exif; /* Set EXIF resolution tag. */ length=GetStringInfoLength(profile); exif=GetStringInfoDatum(profile); if (length < 16) return(MagickFalse); id=(ssize_t) ReadProfileShort(LSBEndian,exif); if ((id != 0x4949) && (id != 0x4D4D)) { while (length != 0) { if (ReadProfileByte(&exif,&length) != 0x45) continue; if (ReadProfileByte(&exif,&length) != 0x78) continue; if (ReadProfileByte(&exif,&length) != 0x69) continue; if (ReadProfileByte(&exif,&length) != 0x66) continue; if (ReadProfileByte(&exif,&length) != 0x00) continue; if (ReadProfileByte(&exif,&length) != 0x00) continue; break; } if (length < 16) return(MagickFalse); id=(ssize_t) ReadProfileShort(LSBEndian,exif); } endian=LSBEndian; if (id == 0x4949) endian=LSBEndian; else if (id == 0x4D4D) endian=MSBEndian; else return(MagickFalse); if (ReadProfileShort(endian,exif+2) != 0x002a) return(MagickFalse); /* This the offset to the first IFD. */ offset=(ssize_t) ReadProfileLong(endian,exif+4); if ((offset < 0) || (size_t) offset >= length) return(MagickFalse); directory=exif+offset; level=0; entry=0; do { if (level > 0) { level--; directory=directory_stack[level].directory; entry=directory_stack[level].entry; } if ((directory < exif) || (directory > (exif+length-2))) break; /* Determine how many entries there are in the current IFD. */ number_entries=ReadProfileShort(endian,directory); for ( ; entry < number_entries; entry++) { int components; register unsigned char *p, *q; size_t number_bytes; ssize_t format, tag_value; q=(unsigned char *) (directory+2+(12*entry)); if (q > (exif+length-12)) break; /* corrupt EXIF */ tag_value=(ssize_t) ReadProfileShort(endian,q); format=(ssize_t) ReadProfileShort(endian,q+2); if ((format < 0) || ((format-1) >= EXIF_NUM_FORMATS)) break; components=(ssize_t) ReadProfileLong(endian,q+4); if (components < 0) break; /* corrupt EXIF */ number_bytes=(size_t) components*format_bytes[format]; if ((ssize_t) number_bytes < components) break; /* prevent overflow */ if (number_bytes <= 4) p=q+8; else { /* The directory entry contains an offset. */ offset=(ssize_t) ReadProfileLong(endian,q+8); if ((offset < 0) || ((size_t) (offset+number_bytes) > length)) continue; if (~length < number_bytes) continue; /* prevent overflow */ p=(unsigned char *) (exif+offset); } switch (tag_value) { case 0x011a: { (void) WriteProfileLong(endian,(size_t) (image->resolution.x+0.5),p); (void) WriteProfileLong(endian,1UL,p+4); break; } case 0x011b: { (void) WriteProfileLong(endian,(size_t) (image->resolution.y+0.5),p); (void) WriteProfileLong(endian,1UL,p+4); break; } case 0x0112: { if (number_bytes == 4) { (void) WriteProfileLong(endian,(size_t) image->orientation,p); break; } (void) WriteProfileShort(endian,(unsigned short) image->orientation, p); break; } case 0x0128: { if (number_bytes == 4) { (void) WriteProfileLong(endian,(size_t) (image->units+1),p); break; } (void) WriteProfileShort(endian,(unsigned short) (image->units+1),p); break; } default: break; } if ((tag_value == TAG_EXIF_OFFSET) || (tag_value == TAG_INTEROP_OFFSET)) { offset=(ssize_t) ReadProfileLong(endian,p); if (((size_t) offset < length) && (level < (MaxDirectoryStack-2))) { directory_stack[level].directory=directory; entry++; directory_stack[level].entry=entry; level++; directory_stack[level].directory=exif+offset; directory_stack[level].entry=0; level++; if ((directory+2+(12*number_entries)) > (exif+length)) break; offset=(ssize_t) ReadProfileLong(endian,directory+2+(12* number_entries)); if ((offset != 0) && ((size_t) offset < length) && (level < (MaxDirectoryStack-2))) { directory_stack[level].directory=exif+offset; directory_stack[level].entry=0; level++; } } break; } } } while (level > 0); return(MagickTrue); } MagickPrivate MagickBooleanType SyncImageProfiles(Image *image) { MagickBooleanType status; StringInfo *profile; status=MagickTrue; profile=(StringInfo *) GetImageProfile(image,"8BIM"); if (profile != (StringInfo *) NULL) if (Sync8BimProfile(image,profile) == MagickFalse) status=MagickFalse; profile=(StringInfo *) GetImageProfile(image,"EXIF"); if (profile != (StringInfo *) NULL) if (SyncExifProfile(image,profile) == MagickFalse) status=MagickFalse; return(status); }
Example_target_data.4.c
/* * @@name: target_data.4c * @@type: C * @@compilable: yes * @@linkable: no * @@expect: success * @@version: omp_4.0 */ void vec_mult(float*, float*, float*, int); extern void init(float*, float*, int); extern void output(float*, int); void foo(float *p0, float *v1, float *v2, int N) { init(v1, v2, N); #pragma omp target data map(to: v1[0:N], v2[:N]) map(from: p0[0:N]) { vec_mult(p0, v1, v2, N); } output(p0, N); } void vec_mult(float *p1, float *v3, float *v4, int N) { int i; #pragma omp target map(to: v3[0:N], v4[:N]) map(from: p1[0:N]) #pragma omp parallel for for (i=0; i<N; i++) { p1[i] = v3[i] * v4[i]; } }
3-2.c
#include <omp.h> #include <stdio.h> int main() { #pragma omp parallel num_threads(2) #pragma omp for ordered for (int i = 0; i < 100; i++) { int id = omp_get_thread_num(); #pragma omp ordered printf("T%d:i%d ", id, i); fflush(stdout); } }
stencil.c
/*************************************************************************** * * (C) Copyright 2010 The Board of Trustees of the * University of Illinois * All Rights Reserved * ***************************************************************************/ /*************************************************************************** * * This benchmark was adapted to run on GPUs with OpenMP 4.0 pragmas * and OpenCL driver implemented in gpuclang 2.0 (based on clang 3.5) * * Marcio M Pereira <mpereira@ic.unicamp.br> * ***************************************************************************/ /* * === NOTE === * * The Polyhedral optmizations restricts the class of loops it can manipulate * to sequences of imperfectly nested loops with particular constraints on the * loop bound and array subscript expressions. * * To allow this optimization we fixed the problem size with __STATIC__ tag * comment this tag to use original version. * */ #ifndef __STATIC__ #define __STATIC__ #endif #include <stdio.h> #include <stdlib.h> #include <string.h> #include <sys/time.h> #include <inttypes.h> #ifdef __APPLE__ #include <machine/endian.h> #include <sys/malloc.h> #else #include <endian.h> #include <malloc.h> #endif #include "../../common/parboil.h" #include "../../common/polybenchUtilFuncts.h" #if __BYTE_ORDER != __LITTLE_ENDIAN # error "File I/O is not implemented for this system: wrong endianness." #endif #define Index3D(_nx,_ny,_i,_j,_k) ((_i)+_nx*((_j)+_ny*(_k))) //define the error threshold for the results "not matching" #define ERROR_THRESHOLD 0.05 #define GPU 1 #ifdef __STATIC__ // Define statically the problem size #define NX 512 #define NY 512 #define NZ 64 #else int NX, NY, NZ; #endif #define c0 0.1667 #define c1 0.0278 /* Can switch DATA_TYPE between float and double */ typedef float DATA_TYPE; struct pb_Parameters *parameters; double t_start, t_end, t_start_GPU, t_end_GPU; float *h_Anext_GPU, *h_Anext_CPU; void cpu_stencilGPU(float *A0, float *Anext) { int i, j, k; #pragma omp target device(GPU) \ map(to: A0[:NX*NY*NZ]) \ map(tofrom: Anext[:NX*NY*NZ]) #pragma omp parallel for collapse(2) for(k=1;k<NZ-1;k++) { for(j=1;j<NY-1;j++) { for(i=1;i<NX-1;i++) { Anext[Index3D (NX, NY, i, j, k)] = (A0[Index3D (NX, NY, i, j, k + 1)] + A0[Index3D (NX, NY, i, j, k - 1)] + A0[Index3D (NX, NY, i, j + 1, k)] + A0[Index3D (NX, NY, i, j - 1, k)] + A0[Index3D (NX, NY, i + 1, j, k)] + A0[Index3D (NX, NY, i - 1, j, k)])*c1 - A0[Index3D (NX, NY, i, j, k)]*c0; } } } } void cpu_stencilCPU(float *A0, float * Anext) { int i, j, k; for(k=1;k<NZ-1;k++) { for(j=1;j<NY-1;j++) { for(i=1;i<NX-1;i++) { Anext[Index3D (NX, NY, i, j, k)] = (A0[Index3D (NX, NY, i, j, k + 1)] + A0[Index3D (NX, NY, i, j, k - 1)] + A0[Index3D (NX, NY, i, j + 1, k)] + A0[Index3D (NX, NY, i, j - 1, k)] + A0[Index3D (NX, NY, i + 1, j, k)] + A0[Index3D (NX, NY, i - 1, j, k)])*c1 - A0[Index3D (NX, NY, i, j, k)]*c0; } } } } void compareResults(DATA_TYPE *A, DATA_TYPE *A_GPU) { int i, j, k, fail=0; for (k=0; k < NZ; k++) { for (j=0; j < NY; j++) { for (i=0; i < NX; i++) { if (percentDiff(A[Index3D (NX, NY, i, j, k)], A_GPU[Index3D (NX, NY, i, j, k)]) > ERROR_THRESHOLD) { fail++; } } } } // print results printf("Non-Matching CPU-GPU Outputs Beyond Error Threshold of %4.2f Percent: %d\n", ERROR_THRESHOLD, fail); } static int read_data(float *A0, int nx,int ny,int nz,FILE *fp) { int s=0; int i, j, k; for(i=0;i<NZ;i++) { for(j=0;j<NY;j++) { for(k=0;k<NX;k++) { fread(A0+s,sizeof(float),1,fp); s++; } } } return 0; } double stencilGPU(int argc, char** argv) { //declaration int nx,ny,nz; int size; int iteration; if (argc<5) { printf("Usage: probe nx ny nz tx ty t\n" "nx: the grid size x\n" "ny: the grid size y\n" "nz: the grid size z\n" "t: the iteration time\n"); return -1; } nx = atoi(argv[1]); if (nx<1) return -1; ny = atoi(argv[2]); if (ny<1) return -1; nz = atoi(argv[3]); if (nz<1) return -1; iteration = atoi(argv[4]); if(iteration<1) return -1; //host data float *h_A0; float *h_Anext; size=nx*ny*nz; h_A0=(float*)malloc(sizeof(float)*size); h_Anext=(float*)malloc(sizeof(float)*size); FILE *fp = fopen(parameters->inpFiles[0], "rb"); read_data(h_A0, nx,ny,nz,fp); fclose(fp); memcpy (h_Anext,h_A0 ,sizeof(float)*size); #ifndef __STATIC__ NX = nx; NY = ny; NZ = nz; #endif int t; t_start_GPU = rtclock(); for(t=0;t<iteration;t++) { cpu_stencilGPU(h_A0, h_Anext); float *temp=h_A0; h_A0 = h_Anext; h_Anext = temp; } t_end_GPU = rtclock(); float *temp=h_A0; h_A0 = h_Anext; h_Anext_GPU = temp; free (h_A0); return t_end_GPU - t_start_GPU; } double stencilCPU(int argc, char** argv) { //declaration int nx,ny,nz; int size; int iteration; if (argc<5) { printf("Usage: probe nx ny nz tx ty t\n" "nx: the grid size x\n" "ny: the grid size y\n" "nz: the grid size z\n" "t: the iteration time\n"); return -1; } nx = atoi(argv[1]); if (nx<1) return -1; ny = atoi(argv[2]); if (ny<1) return -1; nz = atoi(argv[3]); if (nz<1) return -1; iteration = atoi(argv[4]); if(iteration<1) return -1; //host data float *h_A0; float *h_Anext; size=nx*ny*nz; h_A0=(float*)malloc(sizeof(float)*size); h_Anext=(float*)malloc(sizeof(float)*size); FILE *fp = fopen(parameters->inpFiles[0], "rb"); read_data(h_A0, nx,ny,nz,fp); fclose(fp); memcpy (h_Anext,h_A0 ,sizeof(float)*size); #ifndef __STATIC__ NX = nx; NY = ny; NZ = nz; #endif int t; t_start = rtclock(); for(t=0;t<iteration;t++) { cpu_stencilCPU(h_A0, h_Anext); float *temp=h_A0; h_A0 = h_Anext; h_Anext = temp; } t_end = rtclock(); float *temp=h_A0; h_A0 = h_Anext; h_Anext_CPU = temp; free (h_A0); return t_end - t_start; } int main(int argc, char** argv) { double t_GPU, t_CPU; parameters = pb_ReadParameters(&argc, argv); t_GPU = stencilGPU(argc, argv); fprintf(stdout, "GPU Runtime: %0.6lfs\n", t_GPU); t_CPU = stencilCPU(argc, argv); fprintf(stdout, "CPU Runtime: %0.6lfs\n", t_CPU); compareResults(h_Anext_GPU, h_Anext_CPU); pb_FreeParameters(parameters); free (h_Anext_GPU); free (h_Anext_CPU); return 0; }
linux_bind.c
/** * (C) Copyright 2014- ECMWF. * * This software is licensed under the terms of the Apache Licence Version 2.0 * which can be obtained at http://www.apache.org/licenses/LICENSE-2.0. * * In applying this licence, ECMWF does not waive the privileges and immunities * granted to it by virtue of its status as an intergovernmental organisation * nor does it submit to any jurisdiction. */ #if defined(LINUX) && !defined(DARWIN) && !defined(_CRAYC) && !defined(ECMWF) #define _GNU_SOURCE #include <stdio.h> #include <stdlib.h> #include <unistd.h> #include <string.h> #include <ctype.h> #ifdef _OPENMP #include <omp.h> #endif #include <sched.h> static char * getcpumask (char *buffer, size_t size) { cpu_set_t mask; unsigned int ncpu; int icpu; ncpu = sysconf (_SC_NPROCESSORS_CONF); sched_getaffinity (0, sizeof (mask), &mask); for (icpu = 0; icpu < ncpu; icpu++) buffer[icpu] = CPU_ISSET (icpu, &mask) ? '1' : '0'; buffer[ncpu] = '\0'; return buffer; } void linux_bind_dump_ (int * prank, int * psize) { int rank = *prank; int size = *psize; int icpu; unsigned int ncpu; FILE * fp = NULL; char f[256]; char host[255]; int nomp = #ifdef _OPENMP omp_get_max_threads () #else 1 #endif ; ncpu = sysconf (_SC_NPROCESSORS_CONF); sprintf (f, "linux_bind.%6.6d.txt", rank); fp = fopen (f, "w"); if (gethostname (host, 255) != 0) strcpy (host, "unknown"); fprintf (fp, " rank = %6d", rank); fprintf (fp, " host = %9s", host); fprintf (fp, " ncpu = %2d", ncpu); fprintf (fp, " nomp = %2d", nomp); { char buffer[1024]; fprintf (fp, " mask = %s", getcpumask (buffer, sizeof (buffer))); } #ifdef _OPENMP #pragma omp parallel #endif { char buffer[1024]; int iomp = #ifdef _OPENMP omp_get_thread_num () #else 1 #endif ; int i; for (i = 0; i < nomp; i++) { if (i == iomp) { #ifdef _OPENMP #pragma omp critical #endif fprintf (fp, "\n mask = %s iomp = %2d", getcpumask (buffer, sizeof (buffer)), iomp); } #ifdef _OPENMP #pragma omp barrier #endif } #ifdef _OPENMP #pragma omp barrier #endif } fprintf (fp, "\n"); fclose (fp); } #define LINUX_BIND_TXT "linux_bind.txt" void linux_bind_ (int * prank, int * psize) { int rank = *prank; int size = *psize; FILE * fp; int i; size_t len = 256; char * buf = (char*)malloc (len); const char * EC_LINUX_BIND; EC_LINUX_BIND = getenv ("EC_LINUX_BIND"); if (EC_LINUX_BIND == NULL) EC_LINUX_BIND = LINUX_BIND_TXT; fp = fopen (EC_LINUX_BIND, "r"); if (fp == NULL) { // Willem Deconinck: Comment out as this pollutes logs // fprintf (stderr, "`%s' was not found\n", EC_LINUX_BIND); goto end; } for (i = 0; i < rank+1; i++) { if (getline (&buf, &len, fp) == -1) { fprintf (stderr, "Unexpected EOF while reading `" LINUX_BIND_TXT "'\n"); goto end; } } #ifdef _OPENMP #pragma omp parallel #endif { char * c; cpu_set_t mask; int iomp = #ifdef _OPENMP omp_get_thread_num () #else 1 #endif ; int jomp, icpu; for (jomp = 0, c = buf; jomp < iomp; jomp++) { while (*c && isdigit (*c)) c++; while (*c && (! isdigit (*c))) c++; if (*c == '\0') { fprintf (stderr, "Unexpected end of line while reading `" LINUX_BIND_TXT "'\n"); goto end_parallel; } } CPU_ZERO (&mask); for (icpu = 0; isdigit (*c); icpu++, c++) if (*c != '0') CPU_SET (icpu, &mask); sched_setaffinity (0, sizeof (mask), &mask); end_parallel: c = NULL; } end: if (fp != NULL) fclose (fp); free (buf); } #else void linux_bind_ () { } void linux_bind_dump_ () { } #endif
fill_ints.c
/* Copyright 2014-2018 The PySCF Developers. All Rights Reserved. Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. * * Author: Qiming Sun <osirpt.sun@gmail.com> */ #include <stdlib.h> #include <string.h> #include <complex.h> #include <assert.h> #include "config.h" #include "cint.h" #include "vhf/fblas.h" #include "pbc/optimizer.h" #define INTBUFMAX 1000 #define INTBUFMAX10 8000 #define IMGBLK 80 #define OF_CMPLX 2 #define MIN(X,Y) ((X)<(Y)?(X):(Y)) #define MAX(X,Y) ((X)>(Y)?(X):(Y)) int GTOmax_shell_dim(int *ao_loc, int *shls_slice, int ncenter); int GTOmax_cache_size(int (*intor)(), int *shls_slice, int ncenter, int *atm, int natm, int *bas, int nbas, double *env); static int shloc_partition(int *kshloc, int *ao_loc, int ksh0, int ksh1, int dkmax) { int ksh; int nloc = 0; int loclast = ao_loc[ksh0]; kshloc[0] = ksh0; for (ksh = ksh0+1; ksh < ksh1; ksh++) { assert(ao_loc[ksh+1] - ao_loc[ksh] < dkmax); if (ao_loc[ksh+1] - loclast > dkmax) { nloc += 1; kshloc[nloc] = ksh; loclast = ao_loc[ksh]; } } nloc += 1; kshloc[nloc] = ksh1; return nloc; } static void shift_bas(double *env_loc, double *env, double *Ls, int ptr, int iL) { env_loc[ptr+0] = env[ptr+0] + Ls[iL*3+0]; env_loc[ptr+1] = env[ptr+1] + Ls[iL*3+1]; env_loc[ptr+2] = env[ptr+2] + Ls[iL*3+2]; } static void sort3c_kks1(double complex *out, double *bufr, double *bufi, int *kptij_idx, int *shls_slice, int *ao_loc, int nkpts, int nkpts_ij, int comp, int ish, int jsh, int msh0, int msh1) { const int ish0 = shls_slice[0]; const int ish1 = shls_slice[1]; const int jsh0 = shls_slice[2]; const int jsh1 = shls_slice[3]; const int ksh0 = shls_slice[4]; const int ksh1 = shls_slice[5]; const size_t naoi = ao_loc[ish1] - ao_loc[ish0]; const size_t naoj = ao_loc[jsh1] - ao_loc[jsh0]; const size_t naok = ao_loc[ksh1] - ao_loc[ksh0]; const size_t njk = naoj * naok; const size_t nijk = njk * naoi; const int di = ao_loc[ish+1] - ao_loc[ish]; const int dj = ao_loc[jsh+1] - ao_loc[jsh]; const int ip = ao_loc[ish] - ao_loc[ish0]; const int jp = ao_loc[jsh] - ao_loc[jsh0]; const int dij = di * dj; const int dkmax = ao_loc[msh1] - ao_loc[msh0]; const size_t dijmc = dij * dkmax * comp; out += (ip * naoj + jp) * naok; int i, j, k, kk, ik, jk, ksh, ic, dk, dijk; size_t off; double *pbr, *pbi; double complex *pout; for (kk = 0; kk < nkpts_ij; kk++) { ik = kptij_idx[kk] / nkpts; jk = kptij_idx[kk] % nkpts; off = (ik*nkpts+jk) * dijmc; for (ksh = msh0; ksh < msh1; ksh++) { dk = ao_loc[ksh+1] - ao_loc[ksh]; dijk = dij * dk; for (ic = 0; ic < comp; ic++) { pout = out + nijk*ic + ao_loc[ksh]-ao_loc[ksh0]; pbr = bufr + off + dijk*ic; pbi = bufi + off + dijk*ic; for (j = 0; j < dj; j++) { for (k = 0; k < dk; k++) { for (i = 0; i < di; i++) { pout[i*njk+k] = pbr[k*dij+i] + pbi[k*dij+i]*_Complex_I; } } pout += naok; pbr += di; pbi += di; } } off += dijk * comp; } out += nijk * comp; } } static void _nr3c_fill_kk(int (*intor)(), void (*fsort)(), double complex *out, int nkpts_ij, int nkpts, int comp, int nimgs, int ish, int jsh, double *buf, double *env_loc, double *Ls, double *expkL_r, double *expkL_i, int *kptij_idx, int *shls_slice, int *ao_loc, CINTOpt *cintopt, PBCOpt *pbcopt, int *atm, int natm, int *bas, int nbas, double *env) { const int ish0 = shls_slice[0]; const int jsh0 = shls_slice[2]; const int ksh0 = shls_slice[4]; const int ksh1 = shls_slice[5]; const char TRANS_N = 'N'; const double D0 = 0; const double D1 = 1; const double ND1 = -1; jsh += jsh0; ish += ish0; int iptrxyz = atm[PTR_COORD+bas[ATOM_OF+ish*BAS_SLOTS]*ATM_SLOTS]; int jptrxyz = atm[PTR_COORD+bas[ATOM_OF+jsh*BAS_SLOTS]*ATM_SLOTS]; const int di = ao_loc[ish+1] - ao_loc[ish]; const int dj = ao_loc[jsh+1] - ao_loc[jsh]; const int dij = di * dj; int dkmax = INTBUFMAX / dij; int kshloc[ksh1-ksh0+1]; int nkshloc = shloc_partition(kshloc, ao_loc, ksh0, ksh1, dkmax); int i, m, msh0, msh1, dijm, dijmc, dijmk, empty; int ksh, dk, iL0, iL, jL, iLcount; int shls[3]; double *bufkk_r, *bufkk_i, *bufkL_r, *bufkL_i, *bufL, *pbuf, *cache; int (*fprescreen)(); if (pbcopt != NULL) { fprescreen = pbcopt->fprescreen; } else { fprescreen = PBCnoscreen; } shls[0] = ish; shls[1] = jsh; for (m = 0; m < nkshloc; m++) { msh0 = kshloc[m]; msh1 = kshloc[m+1]; dkmax = ao_loc[msh1] - ao_loc[msh0]; dijm = dij * dkmax; dijmc = dijm * comp; dijmk = dijmc * nkpts; bufkk_r = buf; bufkk_i = bufkk_r + (size_t)nkpts * dijmk; bufkL_r = bufkk_i + (size_t)nkpts * dijmk; bufkL_i = bufkL_r + (size_t)MIN(nimgs,IMGBLK) * dijmk; bufL = bufkL_i + (size_t)MIN(nimgs,IMGBLK) * dijmk; cache = bufL + (size_t)nimgs * dijmc; for (i = 0; i < nkpts*dijmk*OF_CMPLX; i++) { bufkk_r[i] = 0; } for (iL0 = 0; iL0 < nimgs; iL0+=IMGBLK) { iLcount = MIN(IMGBLK, nimgs - iL0); for (iL = iL0; iL < iL0+iLcount; iL++) { shift_bas(env_loc, env, Ls, iptrxyz, iL); pbuf = bufL; for (jL = 0; jL < nimgs; jL++) { shift_bas(env_loc, env, Ls, jptrxyz, jL); if ((*fprescreen)(shls, pbcopt, atm, bas, env_loc)) { for (ksh = msh0; ksh < msh1; ksh++) { shls[2] = ksh; if ((*intor)(pbuf, NULL, shls, atm, natm, bas, nbas, env_loc, cintopt, cache)) { empty = 0; } dk = ao_loc[ksh+1] - ao_loc[ksh]; pbuf += dij*dk * comp; } } else { for (i = 0; i < dijmc; i++) { pbuf[i] = 0; } pbuf += dijmc; } } dgemm_(&TRANS_N, &TRANS_N, &dijmc, &nkpts, &nimgs, &D1, bufL, &dijmc, expkL_r, &nimgs, &D0, bufkL_r+(iL-iL0)*(size_t)dijmk, &dijmc); dgemm_(&TRANS_N, &TRANS_N, &dijmc, &nkpts, &nimgs, &D1, bufL, &dijmc, expkL_i, &nimgs, &D0, bufkL_i+(iL-iL0)*(size_t)dijmk, &dijmc); } // iL in range(0, nimgs) // conj(exp(1j*dot(h,k))) dgemm_(&TRANS_N, &TRANS_N, &dijmk, &nkpts, &iLcount, &D1, bufkL_r, &dijmk, expkL_r+iL0, &nimgs, &D1, bufkk_r, &dijmk); dgemm_(&TRANS_N, &TRANS_N, &dijmk, &nkpts, &iLcount, &D1, bufkL_i, &dijmk, expkL_i+iL0, &nimgs, &D1, bufkk_r, &dijmk); dgemm_(&TRANS_N, &TRANS_N, &dijmk, &nkpts, &iLcount, &D1, bufkL_i, &dijmk, expkL_r+iL0, &nimgs, &D1, bufkk_i, &dijmk); dgemm_(&TRANS_N, &TRANS_N, &dijmk, &nkpts, &iLcount, &ND1, bufkL_r, &dijmk, expkL_i+iL0, &nimgs, &D1, bufkk_i, &dijmk); } (*fsort)(out, bufkk_r, bufkk_i, kptij_idx, shls_slice, ao_loc, nkpts, nkpts_ij, comp, ish, jsh, msh0, msh1); } } /* ('...LM,kL,lM->...kl', int3c, exp_kL, exp_kL) */ void PBCnr3c_fill_kks1(int (*intor)(), double complex *out, int nkpts_ij, int nkpts, int comp, int nimgs, int ish, int jsh, double *buf, double *env_loc, double *Ls, double *expkL_r, double *expkL_i, int *kptij_idx, int *shls_slice, int *ao_loc, CINTOpt *cintopt, PBCOpt *pbcopt, int *atm, int natm, int *bas, int nbas, double *env) { _nr3c_fill_kk(intor, &sort3c_kks1, out, nkpts_ij, nkpts, comp, nimgs, ish, jsh, buf, env_loc, Ls, expkL_r, expkL_i, kptij_idx, shls_slice, ao_loc, cintopt, pbcopt, atm, natm, bas, nbas, env); } static void sort3c_kks2_igtj(double complex *out, double *bufr, double *bufi, int *kptij_idx, int *shls_slice, int *ao_loc, int nkpts, int nkpts_ij, int comp, int ish, int jsh, int msh0, int msh1) { const int ish0 = shls_slice[0]; const int ish1 = shls_slice[1]; const int jsh0 = shls_slice[2]; const int jsh1 = shls_slice[3]; const int ksh0 = shls_slice[4]; const int ksh1 = shls_slice[5]; const size_t naoi = ao_loc[ish1] - ao_loc[ish0]; const size_t naoj = ao_loc[jsh1] - ao_loc[jsh0]; const size_t naok = ao_loc[ksh1] - ao_loc[ksh0]; assert(naoi == naoj); const size_t njk = naoj * naok; const size_t nijk = njk * naoi; const int di = ao_loc[ish+1] - ao_loc[ish]; const int dj = ao_loc[jsh+1] - ao_loc[jsh]; const int ip = ao_loc[ish] - ao_loc[ish0]; const int jp = ao_loc[jsh] - ao_loc[jsh0]; const int dij = di * dj; const int dkmax = ao_loc[msh1] - ao_loc[msh0]; const size_t dijmc = dij * dkmax * comp; double complex *outij = out + (ip * naoj + jp) * naok; double complex *outji = out + (jp * naoj + ip) * naok; int i, j, k, kk, ik, jk, ksh, ic, dk, dijk; size_t offij, offji; double *pbij_r, *pbij_i, *pbji_r, *pbji_i; double complex *poutij, *poutji; for (kk = 0; kk < nkpts_ij; kk++) { ik = kptij_idx[kk] / nkpts; jk = kptij_idx[kk] % nkpts; offij = (ik*nkpts+jk) * dijmc; offji = (jk*nkpts+ik) * dijmc; for (ksh = msh0; ksh < msh1; ksh++) { dk = ao_loc[ksh+1] - ao_loc[ksh]; dijk = dij * dk; for (ic = 0; ic < comp; ic++) { poutij = outij + nijk*ic + ao_loc[ksh]-ao_loc[ksh0]; poutji = outji + nijk*ic + ao_loc[ksh]-ao_loc[ksh0]; pbij_r = bufr + offij + dijk*ic; pbij_i = bufi + offij + dijk*ic; pbji_r = bufr + offji + dijk*ic; pbji_i = bufi + offji + dijk*ic; for (j = 0; j < dj; j++) { for (k = 0; k < dk; k++) { for (i = 0; i < di; i++) { poutij[i*njk +k] = pbij_r[k*dij+i] + pbij_i[k*dij+i]*_Complex_I; poutji[i*naok+k] = pbji_r[k*dij+i] - pbji_i[k*dij+i]*_Complex_I; } } poutij += naok; poutji += njk; pbij_r += di; pbij_i += di; pbji_r += di; pbji_i += di; } } offij += dijk * comp; offji += dijk * comp; } outij += nijk * comp; outji += nijk * comp; } } /* ('...LM,kL,lM->...kl', int3c, exp_kL, exp_kL) */ void PBCnr3c_fill_kks2(int (*intor)(), double complex *out, int nkpts_ij, int nkpts, int comp, int nimgs, int ish, int jsh, double *buf, double *env_loc, double *Ls, double *expkL_r, double *expkL_i, int *kptij_idx, int *shls_slice, int *ao_loc, CINTOpt *cintopt, PBCOpt *pbcopt, int *atm, int natm, int *bas, int nbas, double *env) { int ip = ish + shls_slice[0]; int jp = jsh + shls_slice[2] - nbas; if (ip > jp) { _nr3c_fill_kk(intor, &sort3c_kks2_igtj, out, nkpts_ij, nkpts, comp, nimgs, ish, jsh, buf, env_loc, Ls, expkL_r, expkL_i, kptij_idx, shls_slice, ao_loc, cintopt, pbcopt, atm, natm, bas, nbas, env); } else if (ip == jp) { _nr3c_fill_kk(intor, &sort3c_kks1, out, nkpts_ij, nkpts, comp, nimgs, ish, jsh, buf, env_loc, Ls, expkL_r, expkL_i, kptij_idx, shls_slice, ao_loc, cintopt, pbcopt, atm, natm, bas, nbas, env); } } static void sort3c_ks1(double complex *out, double *bufr, double *bufi, int *shls_slice, int *ao_loc, int nkpts, int comp, int ish, int jsh, int msh0, int msh1) { const int ish0 = shls_slice[0]; const int ish1 = shls_slice[1]; const int jsh0 = shls_slice[2]; const int jsh1 = shls_slice[3]; const int ksh0 = shls_slice[4]; const int ksh1 = shls_slice[5]; const size_t naoi = ao_loc[ish1] - ao_loc[ish0]; const size_t naoj = ao_loc[jsh1] - ao_loc[jsh0]; const size_t naok = ao_loc[ksh1] - ao_loc[ksh0]; const size_t njk = naoj * naok; const size_t nijk = njk * naoi; const int di = ao_loc[ish+1] - ao_loc[ish]; const int dj = ao_loc[jsh+1] - ao_loc[jsh]; const int ip = ao_loc[ish] - ao_loc[ish0]; const int jp = ao_loc[jsh] - ao_loc[jsh0]; const int dij = di * dj; const int dkmax = ao_loc[msh1] - ao_loc[msh0]; const size_t dijmc = dij * dkmax * comp; out += (ip * naoj + jp) * naok; int i, j, k, kk, ksh, ic, dk, dijk; size_t off; double *pbr, *pbi; double complex *pout; for (kk = 0; kk < nkpts; kk++) { off = kk * dijmc; for (ksh = msh0; ksh < msh1; ksh++) { dk = ao_loc[ksh+1] - ao_loc[ksh]; dijk = dij * dk; for (ic = 0; ic < comp; ic++) { pout = out + nijk*ic + ao_loc[ksh]-ao_loc[ksh0]; pbr = bufr + off + dijk*ic; pbi = bufi + off + dijk*ic; for (j = 0; j < dj; j++) { for (k = 0; k < dk; k++) { for (i = 0; i < di; i++) { pout[i*njk+k] = pbr[k*dij+i] + pbi[k*dij+i]*_Complex_I; } } pout += naok; pbr += di; pbi += di; } } off += dijk * comp; } out += nijk * comp; } } /* ('...LM,kL,kM->...k', int3c, exp_kL, exp_kL) */ static void _nr3c_fill_k(int (*intor)(), void (*fsort)(), double complex *out, int nkpts_ij, int nkpts, int comp, int nimgs, int ish, int jsh, double *buf, double *env_loc, double *Ls, double *expkL_r, double *expkL_i, int *kptij_idx, int *shls_slice, int *ao_loc, CINTOpt *cintopt, PBCOpt *pbcopt, int *atm, int natm, int *bas, int nbas, double *env) { const int ish0 = shls_slice[0]; const int jsh0 = shls_slice[2]; const int ksh0 = shls_slice[4]; const int ksh1 = shls_slice[5]; const char TRANS_N = 'N'; const double D1 = 1; jsh += jsh0; ish += ish0; int iptrxyz = atm[PTR_COORD+bas[ATOM_OF+ish*BAS_SLOTS]*ATM_SLOTS]; int jptrxyz = atm[PTR_COORD+bas[ATOM_OF+jsh*BAS_SLOTS]*ATM_SLOTS]; const int di = ao_loc[ish+1] - ao_loc[ish]; const int dj = ao_loc[jsh+1] - ao_loc[jsh]; const int dij = di * dj; int dkmax = INTBUFMAX10 / dij; int kshloc[ksh1-ksh0+1]; int nkshloc = shloc_partition(kshloc, ao_loc, ksh0, ksh1, dkmax); int i, m, msh0, msh1, dijmc, empty; size_t dijmk; int ksh, dk, iL, jL, jLcount; int shls[3]; double *bufexp_r = buf; double *bufexp_i = bufexp_r + nimgs * nkpts; double *bufk_r = bufexp_i + nimgs * nkpts; double *bufk_i, *bufL, *pbuf, *cache; int (*fprescreen)(); if (pbcopt != NULL) { fprescreen = pbcopt->fprescreen; } else { fprescreen = PBCnoscreen; } shls[0] = ish; shls[1] = jsh; for (m = 0; m < nkshloc; m++) { msh0 = kshloc[m]; msh1 = kshloc[m+1]; dkmax = ao_loc[msh1] - ao_loc[msh0]; dijmc = dij * dkmax * comp; dijmk = dijmc * nkpts; bufk_i = bufk_r + dijmk; bufL = bufk_i + dijmk; cache = bufL + nimgs * dijmc; for (i = 0; i < dijmk*OF_CMPLX; i++) { bufk_r[i] = 0; } for (iL = 0; iL < nimgs; iL++) { shift_bas(env_loc, env, Ls, iptrxyz, iL); pbuf = bufL; jLcount = 0; for (jL = 0; jL < nimgs; jL++) { shift_bas(env_loc, env, Ls, jptrxyz, jL); if ((*fprescreen)(shls, pbcopt, atm, bas, env_loc)) { for (ksh = msh0; ksh < msh1; ksh++) { shls[2] = ksh; if ((*intor)(pbuf, NULL, shls, atm, natm, bas, nbas, env_loc, cintopt, cache)) { empty = 0; } dk = ao_loc[ksh+1] - ao_loc[ksh]; pbuf += dij*dk * comp; } // ('k,kL->kL', conj(expkL[iL]), expkL) for (i = 0; i < nkpts; i++) { bufexp_r[i*nimgs+jLcount] = expkL_r[i*nimgs+jL] * expkL_r[i*nimgs+iL]; bufexp_r[i*nimgs+jLcount]+= expkL_i[i*nimgs+jL] * expkL_i[i*nimgs+iL]; bufexp_i[i*nimgs+jLcount] = expkL_i[i*nimgs+jL] * expkL_r[i*nimgs+iL]; bufexp_i[i*nimgs+jLcount]-= expkL_r[i*nimgs+jL] * expkL_i[i*nimgs+iL]; } jLcount++; } } dgemm_(&TRANS_N, &TRANS_N, &dijmc, &nkpts, &jLcount, &D1, bufL, &dijmc, bufexp_r, &nimgs, &D1, bufk_r, &dijmc); dgemm_(&TRANS_N, &TRANS_N, &dijmc, &nkpts, &jLcount, &D1, bufL, &dijmc, bufexp_i, &nimgs, &D1, bufk_i, &dijmc); } // iL in range(0, nimgs) (*fsort)(out, bufk_r, bufk_i, shls_slice, ao_loc, nkpts, comp, ish, jsh, msh0, msh1); } } /* ('...LM,kL,kM->...k', int3c, exp_kL, exp_kL) */ void PBCnr3c_fill_ks1(int (*intor)(), double complex *out, int nkpts_ij, int nkpts, int comp, int nimgs, int ish, int jsh, double *buf, double *env_loc, double *Ls, double *expkL_r, double *expkL_i, int *kptij_idx, int *shls_slice, int *ao_loc, CINTOpt *cintopt, PBCOpt *pbcopt, int *atm, int natm, int *bas, int nbas, double *env) { _nr3c_fill_k(intor, sort3c_ks1, out, nkpts_ij, nkpts, comp, nimgs, ish, jsh, buf, env_loc, Ls, expkL_r, expkL_i, kptij_idx, shls_slice, ao_loc, cintopt, pbcopt, atm, natm, bas, nbas, env); } static void sort3c_ks2_igtj(double complex *out, double *bufr, double *bufi, int *shls_slice, int *ao_loc, int nkpts, int comp, int ish, int jsh, int msh0, int msh1) { const int ish0 = shls_slice[0]; const int ish1 = shls_slice[1]; const int jsh0 = shls_slice[2]; const int ksh0 = shls_slice[4]; const int ksh1 = shls_slice[5]; const size_t naok = ao_loc[ksh1] - ao_loc[ksh0]; const size_t off0 = ao_loc[ish0] * (ao_loc[ish0] + 1) / 2; const size_t nij = ao_loc[ish1] * (ao_loc[ish1] + 1) / 2 - off0; const size_t nijk = nij * naok; const int di = ao_loc[ish+1] - ao_loc[ish]; const int dj = ao_loc[jsh+1] - ao_loc[jsh]; const int dij = di * dj; const int dkmax = ao_loc[msh1] - ao_loc[msh0]; const size_t dijmc = dij * dkmax * comp; const int jp = ao_loc[jsh] - ao_loc[jsh0]; out += (ao_loc[ish]*(ao_loc[ish]+1)/2-off0 + jp) * naok; int i, j, k, ij, kk, ksh, ic, dk, dijk; size_t off; double *pbr, *pbi; double complex *pout; for (kk = 0; kk < nkpts; kk++) { off = kk * dijmc; for (ksh = msh0; ksh < msh1; ksh++) { dk = ao_loc[ksh+1] - ao_loc[ksh]; dijk = dij * dk; for (ic = 0; ic < comp; ic++) { pout = out + nijk*ic + ao_loc[ksh]-ao_loc[ksh0]; pbr = bufr + off + dijk*ic; pbi = bufi + off + dijk*ic; for (i = 0; i < di; i++) { for (j = 0; j < dj; j++) { ij = j * di + i; for (k = 0; k < dk; k++) { pout[j*naok+k] = pbr[k*dij+ij] + pbi[k*dij+ij]*_Complex_I; } } pout += (i+ao_loc[ish]+1) * naok; } } off += dijk * comp; } out += nijk * comp; } } static void sort3c_ks2_ieqj(double complex *out, double *bufr, double *bufi, int *shls_slice, int *ao_loc, int nkpts, int comp, int ish, int jsh, int msh0, int msh1) { const int ish0 = shls_slice[0]; const int ish1 = shls_slice[1]; const int jsh0 = shls_slice[2]; const int ksh0 = shls_slice[4]; const int ksh1 = shls_slice[5]; const size_t naok = ao_loc[ksh1] - ao_loc[ksh0]; const size_t off0 = ao_loc[ish0] * (ao_loc[ish0] + 1) / 2; const size_t nij = ao_loc[ish1] * (ao_loc[ish1] + 1) / 2 - off0; const size_t nijk = nij * naok; const int di = ao_loc[ish+1] - ao_loc[ish]; const int dj = ao_loc[jsh+1] - ao_loc[jsh]; const int dij = di * dj; const int dkmax = ao_loc[msh1] - ao_loc[msh0]; const size_t dijmc = dij * dkmax * comp; const int jp = ao_loc[jsh] - ao_loc[jsh0]; out += (ao_loc[ish]*(ao_loc[ish]+1)/2-off0 + jp) * naok; int i, j, k, ij, kk, ksh, ic, dk, dijk; size_t off; double *pbr, *pbi; double complex *pout; for (kk = 0; kk < nkpts; kk++) { off = kk * dijmc; for (ksh = msh0; ksh < msh1; ksh++) { dk = ao_loc[ksh+1] - ao_loc[ksh]; dijk = dij * dk; for (ic = 0; ic < comp; ic++) { pout = out + nijk*ic + ao_loc[ksh]-ao_loc[ksh0]; pbr = bufr + off + dijk*ic; pbi = bufi + off + dijk*ic; for (i = 0; i < di; i++) { for (j = 0; j <= i; j++) { ij = j * di + i; for (k = 0; k < dk; k++) { pout[j*naok+k] = pbr[k*dij+ij] + pbi[k*dij+ij]*_Complex_I; } } pout += (i+ao_loc[ish]+1) * naok; } } off += dijk * comp; } out += nijk * comp; } } /* ('...LM,kL,kM->...k', int3c, exp_kL, exp_kL) */ void PBCnr3c_fill_ks2(int (*intor)(), double complex *out, int nkpts_ij, int nkpts, int comp, int nimgs, int ish, int jsh, double *buf, double *env_loc, double *Ls, double *expkL_r, double *expkL_i, int *kptij_idx, int *shls_slice, int *ao_loc, CINTOpt *cintopt, PBCOpt *pbcopt, int *atm, int natm, int *bas, int nbas, double *env) { int ip = ish + shls_slice[0]; int jp = jsh + shls_slice[2] - nbas; if (ip > jp) { _nr3c_fill_k(intor, &sort3c_ks2_igtj, out, nkpts_ij, nkpts, comp, nimgs, ish, jsh, buf, env_loc, Ls, expkL_r, expkL_i, kptij_idx, shls_slice, ao_loc, cintopt, pbcopt, atm, natm, bas, nbas, env); } else if (ip == jp) { _nr3c_fill_k(intor, &sort3c_ks2_ieqj, out, nkpts_ij, nkpts, comp, nimgs, ish, jsh, buf, env_loc, Ls, expkL_r, expkL_i, kptij_idx, shls_slice, ao_loc, cintopt, pbcopt, atm, natm, bas, nbas, env); } } static void sort3c_gs1(double *out, double *in, int *shls_slice, int *ao_loc, int comp, int ish, int jsh, int msh0, int msh1) { const int ish0 = shls_slice[0]; const int ish1 = shls_slice[1]; const int jsh0 = shls_slice[2]; const int jsh1 = shls_slice[3]; const int ksh0 = shls_slice[4]; const int ksh1 = shls_slice[5]; const size_t naoi = ao_loc[ish1] - ao_loc[ish0]; const size_t naoj = ao_loc[jsh1] - ao_loc[jsh0]; const size_t naok = ao_loc[ksh1] - ao_loc[ksh0]; const size_t njk = naoj * naok; const size_t nijk = njk * naoi; const int di = ao_loc[ish+1] - ao_loc[ish]; const int dj = ao_loc[jsh+1] - ao_loc[jsh]; const int ip = ao_loc[ish] - ao_loc[ish0]; const int jp = ao_loc[jsh] - ao_loc[jsh0]; const int dij = di * dj; const int dkmax = ao_loc[msh1] - ao_loc[msh0]; out += (ip * naoj + jp) * naok; int i, j, k, ksh, ic, dk, dijk; double *pin, *pout; for (ksh = msh0; ksh < msh1; ksh++) { dk = ao_loc[ksh+1] - ao_loc[ksh]; dijk = dij * dk; for (ic = 0; ic < comp; ic++) { pout = out + nijk * ic + ao_loc[ksh]-ao_loc[ksh0]; pin = in + dijk * ic; for (j = 0; j < dj; j++) { for (i = 0; i < di; i++) { for (k = 0; k < dk; k++) { pout[i*njk+k] = pin[k*dij+i]; } } pout += naok; pin += di; } } in += dijk * comp; } } static void _nr3c_fill_g(int (*intor)(), void (*fsort)(), double *out, int nkpts_ij, int nkpts, int comp, int nimgs, int ish, int jsh, double *buf, double *env_loc, double *Ls, double *expkL_r, double *expkL_i, int *kptij_idx, int *shls_slice, int *ao_loc, CINTOpt *cintopt, PBCOpt *pbcopt, int *atm, int natm, int *bas, int nbas, double *env) { const int ish0 = shls_slice[0]; const int jsh0 = shls_slice[2]; const int ksh0 = shls_slice[4]; const int ksh1 = shls_slice[5]; jsh += jsh0; ish += ish0; int iptrxyz = atm[PTR_COORD+bas[ATOM_OF+ish*BAS_SLOTS]*ATM_SLOTS]; int jptrxyz = atm[PTR_COORD+bas[ATOM_OF+jsh*BAS_SLOTS]*ATM_SLOTS]; const int di = ao_loc[ish+1] - ao_loc[ish]; const int dj = ao_loc[jsh+1] - ao_loc[jsh]; const int dij = di * dj; int dkmax = INTBUFMAX10 / dij / 2 * MIN(IMGBLK,nimgs); int kshloc[ksh1-ksh0+1]; int nkshloc = shloc_partition(kshloc, ao_loc, ksh0, ksh1, dkmax); int i, m, msh0, msh1, dijm; int ksh, dk, iL, jL, dijkc; int shls[3]; int dijmc = dij * dkmax * comp; double *bufL = buf + dijmc; double *cache = bufL + dijmc; double *pbuf; int (*fprescreen)(); if (pbcopt != NULL) { fprescreen = pbcopt->fprescreen; } else { fprescreen = PBCnoscreen; } shls[0] = ish; shls[1] = jsh; for (m = 0; m < nkshloc; m++) { msh0 = kshloc[m]; msh1 = kshloc[m+1]; dkmax = ao_loc[msh1] - ao_loc[msh0]; dijm = dij * dkmax; dijmc = dijm * comp; for (i = 0; i < dijmc; i++) { bufL[i] = 0; } for (iL = 0; iL < nimgs; iL++) { shift_bas(env_loc, env, Ls, iptrxyz, iL); for (jL = 0; jL < nimgs; jL++) { shift_bas(env_loc, env, Ls, jptrxyz, jL); if ((*fprescreen)(shls, pbcopt, atm, bas, env_loc)) { pbuf = bufL; for (ksh = msh0; ksh < msh1; ksh++) { shls[2] = ksh; dk = ao_loc[ksh+1] - ao_loc[ksh]; dijkc = dij*dk * comp; if ((*intor)(buf, NULL, shls, atm, natm, bas, nbas, env_loc, cintopt, cache)) { for (i = 0; i < dijkc; i++) { pbuf[i] += buf[i]; } } pbuf += dijkc; } } } } // iL in range(0, nimgs) (*fsort)(out, bufL, shls_slice, ao_loc, comp, ish, jsh, msh0, msh1); } } /* ('...LM->...', int3c) */ void PBCnr3c_fill_gs1(int (*intor)(), double *out, int nkpts_ij, int nkpts, int comp, int nimgs, int ish, int jsh, double *buf, double *env_loc, double *Ls, double *expkL_r, double *expkL_i, int *kptij_idx, int *shls_slice, int *ao_loc, CINTOpt *cintopt, PBCOpt *pbcopt, int *atm, int natm, int *bas, int nbas, double *env) { _nr3c_fill_g(intor, &sort3c_gs1, out, nkpts_ij, nkpts, comp, nimgs, ish, jsh, buf, env_loc, Ls, expkL_r, expkL_i, kptij_idx, shls_slice, ao_loc, cintopt, pbcopt, atm, natm, bas, nbas, env); } static void sort3c_gs2_igtj(double *out, double *in, int *shls_slice, int *ao_loc, int comp, int ish, int jsh, int msh0, int msh1) { const int ish0 = shls_slice[0]; const int ish1 = shls_slice[1]; const int jsh0 = shls_slice[2]; const int ksh0 = shls_slice[4]; const int ksh1 = shls_slice[5]; const size_t naok = ao_loc[ksh1] - ao_loc[ksh0]; const size_t off0 = ao_loc[ish0] * (ao_loc[ish0] + 1) / 2; const size_t nij = ao_loc[ish1] * (ao_loc[ish1] + 1) / 2 - off0; const size_t nijk = nij * naok; const int di = ao_loc[ish+1] - ao_loc[ish]; const int dj = ao_loc[jsh+1] - ao_loc[jsh]; const int dij = di * dj; const int jp = ao_loc[jsh] - ao_loc[jsh0]; out += (ao_loc[ish]*(ao_loc[ish]+1)/2-off0 + jp) * naok; int i, j, k, ij, ksh, ic, dk, dijk; double *pin, *pout; for (ksh = msh0; ksh < msh1; ksh++) { dk = ao_loc[ksh+1] - ao_loc[ksh]; dijk = dij * dk; for (ic = 0; ic < comp; ic++) { pout = out + nijk * ic + ao_loc[ksh]-ao_loc[ksh0]; pin = in + dijk * ic; for (i = 0; i < di; i++) { for (j = 0; j < dj; j++) { ij = j * di + i; for (k = 0; k < dk; k++) { pout[j*naok+k] = pin[k*dij+ij]; } } pout += (i+ao_loc[ish]+1) * naok; } } in += dijk * comp; } } static void sort3c_gs2_ieqj(double *out, double *in, int *shls_slice, int *ao_loc, int comp, int ish, int jsh, int msh0, int msh1) { const int ish0 = shls_slice[0]; const int ish1 = shls_slice[1]; const int jsh0 = shls_slice[2]; const int ksh0 = shls_slice[4]; const int ksh1 = shls_slice[5]; const size_t naok = ao_loc[ksh1] - ao_loc[ksh0]; const size_t off0 = ao_loc[ish0] * (ao_loc[ish0] + 1) / 2; const size_t nij = ao_loc[ish1] * (ao_loc[ish1] + 1) / 2 - off0; const size_t nijk = nij * naok; const int di = ao_loc[ish+1] - ao_loc[ish]; const int dij = di * di; const int jp = ao_loc[jsh] - ao_loc[jsh0]; out += (ao_loc[ish]*(ao_loc[ish]+1)/2-off0 + jp) * naok; int i, j, k, ij, ksh, ic, dk, dijk; double *pin, *pout; for (ksh = msh0; ksh < msh1; ksh++) { dk = ao_loc[ksh+1] - ao_loc[ksh]; dijk = dij * dk; for (ic = 0; ic < comp; ic++) { pout = out + nijk * ic + ao_loc[ksh]-ao_loc[ksh0]; pin = in + dijk * ic; for (i = 0; i < di; i++) { for (j = 0; j <= i; j++) { ij = j * di + i; for (k = 0; k < dk; k++) { pout[j*naok+k] = pin[k*dij+ij]; } } pout += (i+ao_loc[ish]+1) * naok; } } in += dijk * comp; } } /* ('...LM->...', int3c) */ void PBCnr3c_fill_gs2(int (*intor)(), double *out, int nkpts_ij, int nkpts, int comp, int nimgs, int ish, int jsh, double *buf, double *env_loc, double *Ls, double *expkL_r, double *expkL_i, int *kptij_idx, int *shls_slice, int *ao_loc, CINTOpt *cintopt, PBCOpt *pbcopt, int *atm, int natm, int *bas, int nbas, double *env) { int ip = ish + shls_slice[0]; int jp = jsh + shls_slice[2] - nbas; if (ip > jp) { _nr3c_fill_g(intor, &sort3c_gs2_igtj, out, nkpts_ij, nkpts, comp, nimgs, ish, jsh, buf, env_loc, Ls, expkL_r, expkL_i, kptij_idx, shls_slice, ao_loc, cintopt, pbcopt, atm, natm, bas, nbas, env); } else if (ip == jp) { _nr3c_fill_g(intor, &sort3c_gs2_ieqj, out, nkpts_ij, nkpts, comp, nimgs, ish, jsh, buf, env_loc, Ls, expkL_r, expkL_i, kptij_idx, shls_slice, ao_loc, cintopt, pbcopt, atm, natm, bas, nbas, env); } } int PBCsizeof_env(int *shls_slice, int *atm, int natm, int *bas, int nbas, double *env) { const int ish0 = shls_slice[0]; const int ish1 = shls_slice[1]; int ish, ia, np, nc; int nenv = 0; for (ish = ish0; ish < ish1; ish++) { ia = bas[ATOM_OF +ish*BAS_SLOTS]; nenv = MAX(atm[PTR_COORD+ia*ATM_SLOTS]+3, nenv); np = bas[NPRIM_OF+ish*BAS_SLOTS]; nc = bas[NCTR_OF +ish*BAS_SLOTS]; nenv = MAX(bas[PTR_EXP +ish*BAS_SLOTS]+np, nenv); nenv = MAX(bas[PTR_COEFF+ish*BAS_SLOTS]+np*nc, nenv); } return nenv; } void PBCnr3c_drv(int (*intor)(), void (*fill)(), double complex *eri, int nkpts_ij, int nkpts, int comp, int nimgs, double *Ls, double complex *expkL, int *kptij_idx, int *shls_slice, int *ao_loc, CINTOpt *cintopt, PBCOpt *pbcopt, int *atm, int natm, int *bas, int nbas, double *env) { const int ish0 = shls_slice[0]; const int ish1 = shls_slice[1]; const int jsh0 = shls_slice[2]; const int jsh1 = shls_slice[3]; const int nish = ish1 - ish0; const int njsh = jsh1 - jsh0; double *expkL_r = malloc(sizeof(double) * nimgs*nkpts * OF_CMPLX); double *expkL_i = expkL_r + nimgs*nkpts; int i; for (i = 0; i < nimgs*nkpts; i++) { expkL_r[i] = creal(expkL[i]); expkL_i[i] = cimag(expkL[i]); } size_t count; if (fill == &PBCnr3c_fill_kks1 || fill == &PBCnr3c_fill_kks2) { int dijk =(GTOmax_shell_dim(ao_loc, shls_slice+0, 1) * GTOmax_shell_dim(ao_loc, shls_slice+2, 1) * GTOmax_shell_dim(ao_loc, shls_slice+4, 1)); count = nkpts*nkpts * OF_CMPLX + nkpts*MIN(nimgs,IMGBLK) * OF_CMPLX + nimgs; // MAX(INTBUFMAX, dijk) to ensure buffer is enough for at least one (i,j,k) shell count*= MAX(INTBUFMAX, dijk) * comp; } else { count = (nkpts * OF_CMPLX + nimgs) * INTBUFMAX10 * comp; count+= nimgs * nkpts * OF_CMPLX; } const int cache_size = GTOmax_cache_size(intor, shls_slice, 3, atm, natm, bas, nbas, env); #pragma omp parallel default(none) \ shared(intor, fill, eri, nkpts_ij, nkpts, comp, nimgs, \ Ls, expkL_r, expkL_i, kptij_idx, shls_slice, ao_loc, cintopt, pbcopt, \ atm, natm, bas, nbas, env, count) { int ish, jsh, ij; int nenv = PBCsizeof_env(shls_slice, atm, natm, bas, nbas, env); nenv = MAX(nenv, PBCsizeof_env(shls_slice+2, atm, natm, bas, nbas, env)); nenv = MAX(nenv, PBCsizeof_env(shls_slice+4, atm, natm, bas, nbas, env)); double *env_loc = malloc(sizeof(double)*nenv); memcpy(env_loc, env, sizeof(double)*nenv); double *buf = malloc(sizeof(double)*(count+cache_size)); #pragma omp for schedule(dynamic) for (ij = 0; ij < nish*njsh; ij++) { ish = ij / njsh; jsh = ij % njsh; (*fill)(intor, eri, nkpts_ij, nkpts, comp, nimgs, ish, jsh, buf, env_loc, Ls, expkL_r, expkL_i, kptij_idx, shls_slice, ao_loc, cintopt, pbcopt, atm, natm, bas, nbas, env); } free(buf); free(env_loc); } free(expkL_r); } static void sort2c_ks1(double complex *out, double *bufr, double *bufi, int *shls_slice, int *ao_loc, int nkpts, int comp, int jsh, int msh0, int msh1) { const int ish0 = shls_slice[0]; const int ish1 = shls_slice[1]; const int jsh0 = shls_slice[2]; const int jsh1 = shls_slice[3]; const size_t naoi = ao_loc[ish1] - ao_loc[ish0]; const size_t naoj = ao_loc[jsh1] - ao_loc[jsh0]; const size_t nij = naoi * naoj; const int dj = ao_loc[jsh+1] - ao_loc[jsh]; const int jp = ao_loc[jsh] - ao_loc[jsh0]; const int dimax = ao_loc[msh1] - ao_loc[msh0]; const size_t dmjc = dimax * dj * comp; out += jp; int i, j, kk, ish, ic, di, dij; size_t off; double *pbr, *pbi; double complex *pout; for (kk = 0; kk < nkpts; kk++) { off = kk * dmjc; for (ish = msh0; ish < msh1; ish++) { di = ao_loc[ish+1] - ao_loc[ish]; dij = di * dj; for (ic = 0; ic < comp; ic++) { pout = out + nij*ic + naoj*(ao_loc[ish]-ao_loc[ish0]); pbr = bufr + off + dij*ic; pbi = bufi + off + dij*ic; for (j = 0; j < dj; j++) { for (i = 0; i < di; i++) { pout[i*naoj+j] = pbr[j*di+i] + pbi[j*di+i]*_Complex_I; } } } off += dij * comp; } out += nij * comp; } } static void _nr2c_fill(int (*intor)(), double complex *out, int nkpts, int comp, int nimgs, int jsh, int ish0, double *buf, double *env_loc, double *Ls, double *expkL_r, double *expkL_i, int *shls_slice, int *ao_loc, CINTOpt *cintopt, PBCOpt *pbcopt, int *atm, int natm, int *bas, int nbas, double *env) { const int ish1 = shls_slice[1]; const int jsh0 = shls_slice[2]; const char TRANS_N = 'N'; const double D1 = 1; const double D0 = 0; ish0 += shls_slice[0]; jsh += jsh0; int jptrxyz = atm[PTR_COORD+bas[ATOM_OF+jsh*BAS_SLOTS]*ATM_SLOTS]; const int dj = ao_loc[jsh+1] - ao_loc[jsh]; int dimax = INTBUFMAX10 / dj; int ishloc[ish1-ish0+1]; int nishloc = shloc_partition(ishloc, ao_loc, ish0, ish1, dimax); int m, msh0, msh1, dmjc, ish, di, empty; int jL; int shls[2]; double *bufk_r = buf; double *bufk_i, *bufL, *pbuf, *cache; shls[1] = jsh; for (m = 0; m < nishloc; m++) { msh0 = ishloc[m]; msh1 = ishloc[m+1]; dimax = ao_loc[msh1] - ao_loc[msh0]; dmjc = dj * dimax * comp; bufk_i = bufk_r + dmjc * nkpts; bufL = bufk_i + dmjc * nkpts; cache = bufL + dmjc * nimgs; pbuf = bufL; for (jL = 0; jL < nimgs; jL++) { shift_bas(env_loc, env, Ls, jptrxyz, jL); for (ish = msh0; ish < msh1; ish++) { shls[0] = ish; di = ao_loc[ish+1] - ao_loc[ish]; if ((*intor)(pbuf, NULL, shls, atm, natm, bas, nbas, env_loc, cintopt, cache)) { empty = 0; } pbuf += di * dj * comp; } } dgemm_(&TRANS_N, &TRANS_N, &dmjc, &nkpts, &nimgs, &D1, bufL, &dmjc, expkL_r, &nimgs, &D0, bufk_r, &dmjc); dgemm_(&TRANS_N, &TRANS_N, &dmjc, &nkpts, &nimgs, &D1, bufL, &dmjc, expkL_i, &nimgs, &D0, bufk_i, &dmjc); sort2c_ks1(out, bufk_r, bufk_i, shls_slice, ao_loc, nkpts, comp, jsh, msh0, msh1); } } /* ('...M,kL->...k', int3c, exp_kL, exp_kL) */ void PBCnr2c_fill_ks1(int (*intor)(), double complex *out, int nkpts, int comp, int nimgs, int jsh, double *buf, double *env_loc, double *Ls, double *expkL_r, double *expkL_i, int *shls_slice, int *ao_loc, CINTOpt *cintopt, PBCOpt *pbcopt, int *atm, int natm, int *bas, int nbas, double *env) { _nr2c_fill(intor, out, nkpts, comp, nimgs, jsh, 0, buf, env_loc, Ls, expkL_r, expkL_i, shls_slice, ao_loc, cintopt, pbcopt, atm, natm, bas, nbas, env); } void PBCnr2c_fill_ks2(int (*intor)(), double complex *out, int nkpts, int comp, int nimgs, int jsh, double *buf, double *env_loc, double *Ls, double *expkL_r, double *expkL_i, int *shls_slice, int *ao_loc, CINTOpt *cintopt, PBCOpt *pbcopt, int *atm, int natm, int *bas, int nbas, double *env) { _nr2c_fill(intor, out, nkpts, comp, nimgs, jsh, jsh, buf, env_loc, Ls, expkL_r, expkL_i, shls_slice, ao_loc, cintopt, pbcopt, atm, natm, bas, nbas, env); } void PBCnr2c_drv(int (*intor)(), void (*fill)(), double complex *out, int nkpts, int comp, int nimgs, double *Ls, double complex *expkL, int *shls_slice, int *ao_loc, CINTOpt *cintopt, PBCOpt *pbcopt, int *atm, int natm, int *bas, int nbas, double *env) { const int jsh0 = shls_slice[2]; const int jsh1 = shls_slice[3]; const int njsh = jsh1 - jsh0; double *expkL_r = malloc(sizeof(double) * nimgs*nkpts * OF_CMPLX); double *expkL_i = expkL_r + nimgs*nkpts; int i; for (i = 0; i < nimgs*nkpts; i++) { expkL_r[i] = creal(expkL[i]); expkL_i[i] = cimag(expkL[i]); } const int cache_size = GTOmax_cache_size(intor, shls_slice, 2, atm, natm, bas, nbas, env); #pragma omp parallel default(none) \ shared(intor, fill, out, nkpts, comp, nimgs, \ Ls, expkL_r, expkL_i, shls_slice, ao_loc, cintopt, pbcopt, \ atm, natm, bas, nbas, env) { int jsh; int nenv = PBCsizeof_env(shls_slice, atm, natm, bas, nbas, env); nenv = MAX(nenv, PBCsizeof_env(shls_slice+2, atm, natm, bas, nbas, env)); double *env_loc = malloc(sizeof(double)*nenv); memcpy(env_loc, env, sizeof(double)*nenv); size_t count = nkpts * OF_CMPLX + nimgs; double *buf = malloc(sizeof(double)*(count*INTBUFMAX10*comp+cache_size)); #pragma omp for schedule(dynamic) for (jsh = 0; jsh < njsh; jsh++) { (*fill)(intor, out, nkpts, comp, nimgs, jsh, buf, env_loc, Ls, expkL_r, expkL_i, shls_slice, ao_loc, cintopt, pbcopt, atm, natm, bas, nbas, env); } free(buf); free(env_loc); } free(expkL_r); }
private-clause.c
#include <stdio.h> #ifdef _OPENMP #include <omp.h> #else #define omp_get_thread_num() 0 #endif int main() { int i, n = 7; int a[n], suma; for (i=0; i<n; i++) a[i] = i; #pragma omp parallel private(suma) { suma=0; #pragma omp for for (i=0; i<n; i++) { suma = suma + a[i]; printf( "thread %d suma a[%d] / ", omp_get_thread_num(), i); } printf( "\n* thread %d suma= %d", omp_get_thread_num(), suma); } printf("\n"); return 0; }
minmax.h
#ifndef MINMAX_H #define MINMAX_H #include <limits.h> #include <sys/time.h> #include "matrix.h" ull minmax(ull r, // Matrix rows ull c, // Matrix cols ul threads) { timeval start, end; matrix* A = alloc(r, c); T maximum = MINIMUM; fill(A); gettimeofday(&start, NULL); /** * Find maximum value of all rows' minimums */ { ull i = 0, j = 0; #pragma omp parallel for reduction(max: maximum) private(i, j) shared(A) num_threads(threads) iterate(, i, A->rows) { T minimum = A(i, 0); #pragma omp parallel for reduction(min: minimum) private(j) shared(A) num_threads(threads) iterate(, j, A->cols) { if (A(i, j) < minimum) { minimum = A(i, j); } } if (minimum > maximum) { maximum = minimum; } } } gettimeofday(&end, NULL); printf("\tResult: "); printf(TOKEN, maximum); #ifdef WRITE write(A, "minmax.txt"); printf("\tMatrix is written to `minmax.txt`\n"); #endif dealloc(A); return ELAPSED; } #endif // MINMAX_H
main.c
/** @file @brief Main function for APPFS ex10. Reads in data, starts worker threads and outputs results. @author Tri-Peter Shrive */ #include "ex10.h" int main( int argc, const char* const* const argv ) { printf( "\n" ); if( 2 > argc || 4 < argc ) { fprintf( stderr, "USAGE: %s *.gph ( number of terminals to start from ) ( -s )\n", argv[0] ); exit( EXIT_FAILURE ); } int i; int return_value = 0; unsigned int s_flag = 0; unsigned int max_num_start_terminals = 0; for( i = 2; i < argc; i++ ) { // optionally print steiner tree if( 0 == strcmp( argv[i], "-s" ) ) s_flag = 1; // set number of terminals to start from else if( 2 == i ) return_value = sscanf( argv[i], "%u", &max_num_start_terminals ); } // default is 100 if( 1 != return_value ) max_num_start_terminals = 100; // open file for reading FILE* fp = NULL; fp = fopen( argv[1], "r" ); assert( fp ); // read line unsigned int line_number = 0; char line[MAX_LINE_LENGTH]; fgets( line, sizeof( line ), fp ); line_number++; // remove comments and anything after newline char* character = NULL; character = strpbrk( line, "#\n" ); if( NULL != character ) *character = '\0'; // skip initial spaces for( character = &line[0]; isspace( *character ); character++ ); assert( '\0' != *character ); unsigned int num_nodes; unsigned int num_edges; // read first line return_value = sscanf( character, "%u %u", &num_nodes, &num_edges ); // undirected graph num_edges += num_edges; // node 0 may not exist num_nodes++; unsigned int array_next = 0; unsigned int array_length = EXTENSION_LENGTH; unsigned int* tails = NULL; unsigned int* heads = NULL; unsigned long long int* edge_weights = NULL; unsigned int* num_neighbours = NULL; tails = malloc( array_length * sizeof( unsigned int ) ); heads = malloc( array_length * sizeof( unsigned int ) ); edge_weights = malloc( array_length * sizeof( unsigned long long int ) ); num_neighbours = calloc( num_nodes, sizeof( unsigned int ) ); assert( tails ); assert( heads ); assert( edge_weights ); assert( num_neighbours ); unsigned int temp_tail = INT_MAX; unsigned int temp_head = INT_MAX; unsigned long long int temp_edge_weight = LLONG_MAX; while( NULL != fgets( line, sizeof(line), fp ) ) { line_number++; // remove comments and anything after newline character = strpbrk( line, "#\n" ); if( NULL != character ) *character = '\0'; // skip initial spaces for( character = &line[0]; isspace( *character ); character++ ); // skip line if is empty if( '\0' == *character ) continue; // read edge entries return_value = sscanf( character, "%u %u %llu", &temp_tail, &temp_head, &temp_edge_weight ); if( 3 != return_value ) { fprintf( stderr, "\nWARNING: line %u, sscanf returned %u != 3\n\n", line_number, return_value ); continue; } if( num_nodes <= temp_tail ) { fprintf( stderr, "\nWARNING: line %u, tail > number of nodes\n\n", line_number ); continue; } if( num_nodes <= temp_head ) { fprintf( stderr, "\nWARNING: line %u, head > number of nodes\n\n", line_number ); continue; } if( 2000000000 <= temp_edge_weight ) { fprintf( stderr, "\nWARNING: line %u, edge_weight >= 2000000000\n\n", line_number ); continue; } // check there's enough space // if not enlarge array if( array_next == array_length ) { array_length += EXTENSION_LENGTH; tails = realloc( tails, array_length * sizeof( unsigned int ) ); heads = realloc( heads, array_length * sizeof( unsigned int ) ); edge_weights = realloc( edge_weights, array_length * sizeof( unsigned long long int ) ); assert( tails ); assert( heads ); assert( edge_weights ); } // store edge attributes in memory tails[array_next] = temp_tail; heads[array_next] = temp_head; edge_weights[array_next] = temp_edge_weight; array_next++; num_neighbours[temp_tail]++; // repeat with head and tail inverted for undirected graph if( array_next == array_length ) { array_length += EXTENSION_LENGTH; tails = realloc( tails, array_length * sizeof( unsigned int ) ); heads = realloc( heads, array_length * sizeof( unsigned int ) ); edge_weights = realloc( edge_weights, array_length * sizeof( unsigned long long int ) ); assert( tails ); assert( heads); assert( edge_weights ); } // store reversed edge attributes in memory tails[array_next] = temp_head; heads[array_next] = temp_tail; edge_weights[array_next] = temp_edge_weight; array_next++; num_neighbours[temp_head]++; } assert( 0 == fclose( fp ) ); assert( array_next = num_edges ); // calculate index of first neighbour for sorted lists unsigned int j; unsigned int* first_neighbours_index = NULL; first_neighbours_index = calloc( num_nodes, sizeof( unsigned int ) ); assert( first_neighbours_index ); for( j = 1; j < num_nodes; j++ ) first_neighbours_index[j] = first_neighbours_index[j - 1] + num_neighbours[j - 1]; // sort heads and weights by tails unsigned int* num_neighbours_found = NULL; unsigned int* sorted_heads = NULL; unsigned int* sorted_tails = NULL; unsigned long long int* sorted_weights = NULL; num_neighbours_found = calloc( num_nodes, sizeof( unsigned int ) ); sorted_heads = malloc( num_edges * sizeof( unsigned int ) ); sorted_tails = malloc( num_edges * sizeof( unsigned int ) ); sorted_weights = malloc( num_edges * sizeof( unsigned long long int ) ); assert( num_neighbours_found ); assert( sorted_heads ); assert( sorted_tails ); assert( sorted_weights ); unsigned int k; unsigned int l; unsigned int index; for( j = 0; j < num_edges; j++ ) { k = tails[j]; l = heads[j]; assert( k < num_nodes ); assert( l < num_nodes ); index = first_neighbours_index[k] + num_neighbours_found[k]; sorted_weights[index] = edge_weights[j]; sorted_heads[index] = l; sorted_tails[index] = k; num_neighbours_found[k]++; } free( tails ); free( heads ); free( edge_weights ); #ifndef NDEBUG // make sure we still have all edges unsigned int total_neighbours = 0; for( j = 0; j < num_nodes; j++ ) { total_neighbours += num_neighbours_found[j]; } assert( num_edges == total_neighbours ); #endif free( num_neighbours_found ); // calculate prime numbers unsigned int* is_prime = NULL; is_prime = calloc( num_nodes, sizeof( unsigned int ) ); assert( is_prime ); unsigned int num_terminals = get_primes( is_prime, num_nodes ); unsigned int* terminals = NULL; terminals = malloc( num_terminals * sizeof( unsigned int ) ); assert( terminals ); k = 0; for( j = 0; j < num_nodes; j++ ) if( 1 == is_prime[j] ) { terminals[k] = j; k++; } assert( k == num_terminals ); printf( "NODES: %u\n", num_nodes ); printf( "EDGES: %u\n", num_edges/2 ); printf( "TERMINALS: %u\n",num_terminals ); printf( "\n" ); // we don't want to attempt to start from more terminals than there are if( num_terminals < max_num_start_terminals ) max_num_start_terminals = num_terminals; // start wall clock struct timeval start_wall; unsigned int fail = 1; fail = gettimeofday( &start_wall, NULL ); assert( 0 == fail ); // start counting cpu clocks double start_cpu = ( double ) clock() / ( double ) CLOCKS_PER_SEC; // calculate steiner tree unsigned int* tree = NULL; tree = calloc( num_edges, sizeof( unsigned int ) ); assert( tree ); unsigned long long int obj_value = LLONG_MAX; unsigned int* temp_tree = NULL; unsigned int* predecessor = NULL; unsigned int* end = NULL; #ifdef THREADS #pragma omp parallel for default( none ) shared( tree, obj_value, is_prime, terminals, num_terminals, max_num_start_terminals, first_neighbours_index, num_neighbours, num_nodes, num_edges, sorted_weights, sorted_heads ) private( j, k, temp_tree, end, predecessor ) num_threads( THREADS ) #endif for( j = 0; j < max_num_start_terminals; j++ ) { temp_tree = calloc( num_edges, sizeof( unsigned int ) ); predecessor = malloc( num_nodes * sizeof( unsigned int ) ); end = malloc( num_terminals * sizeof( unsigned int ) ); assert( temp_tree ); assert( predecessor ); assert( end ); unsigned int terminals_connected = 0; unsigned int source = terminals[j]; terminals_connected = get_steiner_tree( is_prime, terminals, num_terminals, num_nodes, num_edges, first_neighbours_index, num_neighbours, sorted_weights, sorted_heads, temp_tree, predecessor, source ); unsigned int temp_obj_value = 0; for( k = 0; k < num_edges; k++ ) { if( 1 == temp_tree[k] ) { temp_obj_value += sorted_weights[k]; } } // could only test connectivity of best tree as this opperation is expensive // however other result will have been lost... unsigned int tree_connected = 0; if( temp_obj_value < obj_value && terminals_connected == num_terminals ) tree_connected = is_tree_valid( predecessor, terminals, end, num_nodes, num_terminals, source ); #pragma omp critical ( objective_value ) if( temp_obj_value < obj_value && tree_connected ) { obj_value = temp_obj_value; memcpy( tree, temp_tree, num_edges * sizeof( unsigned int ) ); } free( temp_tree ); free( predecessor ); free( end ); } // stop wall clock struct timeval stop_wall; fail = 1; fail = gettimeofday( &stop_wall, NULL ); assert( 0 == fail ); // stop counting cpu clocks double stop_cpu = ( double ) clock() / ( double ) CLOCKS_PER_SEC; // calculate durations of both double duration_wall = ( stop_wall.tv_sec + stop_wall.tv_usec * 0.000001 ) - ( start_wall.tv_sec + start_wall.tv_usec * 0.000001 ); double duration_cpu = stop_cpu - start_cpu; if( s_flag ) { printf( "TREE: " ); for( j = 0; j < num_edges; j++ ) if( tree[j] ) printf( "(%u,%u) ", sorted_tails[j], sorted_heads[j] ); printf( "\n\n" ); } printf( "TLEN: %llu\n", obj_value ); printf( "TIME: %lf sec\n", duration_cpu ); printf( "WALL: %lf sec\n", duration_wall ); printf( "\n" ); free( tree ); free( is_prime ); free( terminals ); free( first_neighbours_index ); free( num_neighbours ); free( sorted_weights ); free( sorted_heads ); free( sorted_tails ); return 0; }
tensor_cpu-inl.h
/*! * Copyright (c) 2014 by Contributors * \file tensor_cpu-inl.h * \brief implementation of CPU host code * \author Bing Xu, Tianqi Chen */ #ifndef MSHADOW_TENSOR_CPU_INL_H_ #define MSHADOW_TENSOR_CPU_INL_H_ #include <cstring> #include <functional> #include <utility> #include <vector> #include "./base.h" #include "./tensor.h" #include "./packet-inl.h" #include "./dot_engine-inl.h" namespace mshadow { template<> inline void InitTensorEngine<cpu>(int dev_id) { } template<> inline void ShutdownTensorEngine<cpu>(void) { } template<> inline void SetDevice<cpu>(int devid) { } template<> inline Stream<cpu> *NewStream<cpu>(bool create_blas_handle, bool create_dnn_handle, int dev_id) { return new Stream<cpu>(); } template<> inline void DeleteStream<cpu>(Stream<cpu> *stream) { delete stream; } template<int ndim> inline std::ostream &operator<<(std::ostream &os, const Shape<ndim> &shape) { // NOLINT(*) os << '('; for (int i = 0; i < ndim; ++i) { if (i != 0) os << ','; os << shape[i]; } // python style tuple if (ndim == 1) os << ','; os << ')'; return os; } template<typename xpu> inline void *AllocHost_(size_t size); template<typename xpu> inline void FreeHost_(void * dptr); #ifdef __CUDACC__ template<> inline void *AllocHost_<gpu>(size_t size) { void *dptr; MSHADOW_CUDA_CALL(cudaMallocHost(&dptr, size, cudaHostAllocPortable)); return dptr; } template<> inline void FreeHost_<gpu>(void *dptr) { MSHADOW_CUDA_CALL(cudaFreeHost(dptr)); } #endif template<> inline void *AllocHost_<cpu>(size_t size) { size_t pitch; return packet::AlignedMallocPitch(&pitch, size, 1); } template<> inline void FreeHost_<cpu>(void *dptr) { packet::AlignedFree(dptr); } template<typename xpu, int dim, typename DType> inline void AllocHost(Tensor<cpu, dim, DType> *obj) { obj->stride_ = obj->size(dim - 1); CHECK_EQ(obj->CheckContiguous(), true) << "AllocHost"; void *dptr = AllocHost_<xpu>(obj->MSize() * sizeof(DType)); obj->dptr_ = reinterpret_cast<DType*>(dptr); } template<typename xpu, int dim, typename DType> inline void FreeHost(Tensor<cpu, dim, DType> *obj) { if (obj->dptr_ == NULL) { LOG(FATAL) << "FreeHost:: double free"; } FreeHost_<xpu>(obj->dptr_); obj->dptr_ = NULL; } template<int dim, typename DType> inline void AllocSpace(Tensor<cpu, dim, DType> *obj, bool pad) { size_t pitch; void *dptr; if (pad) { dptr = packet::AlignedMallocPitch (&pitch, obj->size(dim - 1) * sizeof(DType), obj->shape_.FlatTo2D()[0]); obj->stride_ = static_cast<index_t>(pitch / sizeof(DType)); } else { obj->stride_ = obj->size(dim - 1); dptr = packet::AlignedMallocPitch (&pitch, obj->shape_.Size() * sizeof(DType), 1); } obj->dptr_ = reinterpret_cast<DType*>(dptr); } template<typename Device, typename DType, int dim> inline Tensor<Device, dim, DType> NewTensor(const Shape<dim> &shape, DType initv, bool pad, Stream<Device> *stream_) { Tensor<Device, dim, DType> obj(shape); obj.stream_ = stream_; AllocSpace(&obj, pad); MapExp<sv::saveto>(&obj, expr::ScalarExp<DType>(initv)); return obj; } template<int dim, typename DType> inline void FreeSpace(Tensor<cpu, dim, DType> *obj) { packet::AlignedFree(obj->dptr_); obj->dptr_ = NULL; } template<int dim, typename DType> inline void Copy(Tensor<cpu, dim, DType> _dst, const Tensor<cpu, dim, DType> &_src, Stream<cpu> *stream) { CHECK_EQ(_dst.shape_, _src.shape_) << "Copy:shape mismatch:" << _dst.shape_ << " vs " << _src.shape_; if (_dst.CheckContiguous() && _src.CheckContiguous()) { memcpy(_dst.dptr_, _src.dptr_, sizeof(DType) * _dst.shape_.Size()); } else { Tensor<cpu, 2, DType> dst = _dst.FlatTo2D(); Tensor<cpu, 2, DType> src = _src.FlatTo2D(); for (index_t y = 0; y < dst.size(0); ++y) { memcpy(dst[y].dptr_, src[y].dptr_, sizeof(DType) * dst.size(1)); } } } template<typename Saver, typename R, int dim, typename DType, typename E> inline void MapPlan(TRValue<R, cpu, dim, DType> *dst, const expr::Plan<E, DType> &plan) { Shape<2> shape = expr::ShapeCheck<dim, R>::Check(dst->self()).FlatTo2D(); expr::Plan<R, DType> dplan = expr::MakePlan(dst->self()); #if (MSHADOW_USE_CUDA == 0) #pragma omp parallel for #endif // temp remove openmp, as default setting throttles CPU for (openmp_index_t y = 0; y < shape[0]; ++y) { for (index_t x = 0; x < shape[1]; ++x) { // trust your compiler! -_- they will optimize it Saver::template Save<DType>(dplan.REval(y, x), plan.Eval(y, x)); } } } // code to handle SSE optimization template<bool pass_check, typename Saver, typename R, int dim, typename DType, typename E, int etype> struct MapExpCPUEngine { inline static void Map(TRValue<R, cpu, dim, DType> *dst, const expr::Exp<E, DType, etype> &exp) { MapPlan<Saver>(dst, MakePlan(exp.self())); } }; template<typename SV, int dim, typename DType, typename E, int etype> struct MapExpCPUEngine<true, SV, Tensor<cpu, dim, DType>, dim, DType, E, etype> { inline static void Map(Tensor<cpu, dim, DType> *dst, const expr::Exp<E, DType, etype> &exp) { if (expr::PacketAlignCheck<dim, E, MSHADOW_DEFAULT_PACKET>::Check(exp.self()) && expr::PacketAlignCheck<dim, Tensor<cpu, dim, DType>, MSHADOW_DEFAULT_PACKET>::Check(*dst)) { expr::MapPacketPlan<SV>(dst->self(), expr::MakePacketPlan<MSHADOW_DEFAULT_PACKET>(exp.self())); } else { MapPlan<SV>(dst, MakePlan(exp.self())); } } }; template<typename Saver, typename R, int dim, typename DType, typename E, int etype> inline void MapExp(TRValue<R, cpu, dim, DType> *dst, const expr::Exp<E, DType, etype> &exp) { expr::TypeCheckPass<expr::TypeCheck<cpu, dim, DType, E>::kMapPass> ::Error_All_Tensor_in_Exp_Must_Have_Same_Type(); Shape<dim> eshape = expr::ShapeCheck<dim, E>::Check(exp.self()); Shape<dim> dshape = expr::ShapeCheck<dim, R>::Check(dst->self()); CHECK(eshape[0] == 0 || eshape == dshape) << "Assignment: Shape of Tensors are not consistent with target, " << "eshape: " << eshape << " dshape:" << dshape; MapExpCPUEngine<expr::PacketCheck<E, MSHADOW_DEFAULT_PACKET>::kPass, Saver, R, dim, DType, E, etype> ::Map(dst->ptrself(), exp); } template<typename Saver, typename Reducer, typename R, typename DType, typename E, int etype> inline void MapReduceKeepLowest(TRValue<R, cpu, 1, DType> *dst, const expr::Exp<E, DType, etype> &exp, DType scale) { expr::TypeCheckPass<expr::TypeCheck<cpu, 1, DType, E>::kRedPass> ::Error_TypeCheck_Not_Pass_For_Reduce_Exp(); Shape<2> eshape = expr::ShapeCheck<expr::ExpInfo<E>::kDim, E> ::Check(exp.self()).FlatTo2D(); Shape<1> dshape = expr::ShapeCheck<1, R>::Check(dst->self()); CHECK_EQ(eshape[1], dshape[0]) << "MapReduceKeepLowest::reduction dimension do not match"; CHECK_NE(eshape[0], 0U) << "can not reduce over empty tensor"; // execution expr::Plan<R, DType> dplan = MakePlan(dst->self()); expr::Plan<E, DType> splan = MakePlan(exp.self()); #if (MSHADOW_USE_CUDA == 0) #pragma omp parallel for #endif for (openmp_index_t x = 0; x < eshape[1]; ++x) { DType res = splan.Eval(0, x); for (index_t y = 1; y < eshape[0]; ++y) { Reducer::Reduce(res, splan.Eval(y, x)); } Saver::template Save<DType>(dplan.REval(0, x), res * scale); } } template<typename Saver, typename Reducer, int dimkeep, typename R, typename DType, typename E, int etype> inline void MapReduceKeepHighDim(TRValue<R, cpu, 1, DType> *dst, const expr::Exp<E, DType, etype> &exp, DType scale) { expr::TypeCheckPass<expr::TypeCheck<cpu, dimkeep, DType, E>::kRedPass> ::Error_TypeCheck_Not_Pass_For_Reduce_Exp(); typedef Shape<expr::ExpInfo<E>::kDim> EShape; EShape eshape = expr::ShapeCheck<expr::ExpInfo<E>::kDim, E> ::Check(exp.self()); Shape<1> dshape = expr::ShapeCheck<1, R>::Check(dst->self()); CHECK_EQ(eshape[dimkeep], dshape[0]) << "MapReduceKeepHighDim::reduction dimension do not match"; // use equvalent form Shape<4> pshape = Shape4(eshape.ProdShape(0, dimkeep), eshape[dimkeep], eshape.ProdShape(dimkeep + 1, EShape::kSubdim), eshape[EShape::kSubdim]); // execution expr::Plan<R, DType> dplan = MakePlan(dst->self()); expr::Plan<E, DType> splan = MakePlan(exp.self()); #if (MSHADOW_USE_CUDA == 0) #pragma omp parallel for #endif for (openmp_index_t c = 0; c < pshape[1]; ++c) { DType res; Reducer::SetInitValue(res); for (index_t n = 0; n < pshape[0]; ++n) { DType tres; Reducer::SetInitValue(tres); for (index_t y = 0; y < pshape[2]; ++y) { for (index_t x = 0; x < pshape[3]; ++x) { Reducer::Reduce(tres, splan.Eval((n * pshape[1] + c) * pshape[2] + y, x)); } } Reducer::Reduce(res, tres); } Saver::template Save<DType>(dplan.REval(0, c), DType(res * scale)); } } template<typename DType> inline void Softmax(Tensor<cpu, 1, DType> dst, const Tensor<cpu, 1, DType> &energy) { DType mmax = energy[0]; for (index_t x = 1; x < dst.size(0); ++x) { if (mmax < energy[x]) mmax = energy[x]; } DType sum = DType(0.0f); for (index_t x = 0; x < dst.size(0); ++x) { dst[x] = std::exp(energy[x] - mmax); sum += dst[x]; } for (index_t x = 0; x < dst.size(0); ++x) { dst[x] /= sum; } } template<typename DType> inline void SoftmaxGrad(Tensor<cpu, 2, DType> dst, const Tensor<cpu, 2, DType> &src, const Tensor<cpu, 1, DType> &label) { #pragma omp parallel for for (openmp_index_t y = 0; y < dst.size(0); ++y) { const index_t k = static_cast<int>(label[y]); for (index_t x = 0; x < dst.size(1); ++x) { if (x == k) { dst[y][k] = src[y][k] - 1.0f; } else { dst[y][x] = src[y][x]; } } } } template<typename DType> inline void SoftmaxGrad(Tensor<cpu, 2, DType> dst, const Tensor<cpu, 2, DType> &src, const Tensor<cpu, 1, DType> &label, const DType &ignore_label) { #pragma omp parallel for for (openmp_index_t y = 0; y < dst.size(0); ++y) { const index_t k = static_cast<int>(label[y]); for (index_t x = 0; x < dst.size(1); ++x) { if (static_cast<int>(ignore_label) == k) { dst[y][x] = 0.0f; } else { if (x == k) { dst[y][k] = src[y][k] - 1.0f; } else { dst[y][x] = src[y][x]; } } } } } template<typename DType> inline void SoftmaxGrad(Tensor<cpu, 3, DType> dst, const Tensor<cpu, 3, DType> &src, const Tensor<cpu, 2, DType> &label) { #pragma omp parallel for for (openmp_index_t n = 0; n < dst.size(2); ++n) { for (index_t y = 0; y < dst.size(0); ++y) { const index_t k = static_cast<int>(label[y][n]); for (index_t x = 0; x < dst.size(1); ++x) { if (x == k) { dst[y][k][n] = src[y][k][n] - 1.0f; } else { dst[y][x][n] = src[y][x][n]; } } } } } template<typename DType> inline void SoftmaxGrad(Tensor<cpu, 3, DType> dst, const Tensor<cpu, 3, DType> &src, const Tensor<cpu, 2, DType> &label, const DType &ignore_label) { #pragma omp parallel for for (openmp_index_t n = 0; n < dst.size(2); ++n) { for (index_t y = 0; y < dst.size(0); ++y) { const index_t k = static_cast<int>(label[y][n]); if (k == static_cast<int>(ignore_label)) { for (index_t x = 0; x < dst.size(1); ++x) { dst[y][x][n] = DType(0.0f); } } else { for (index_t x = 0; x < dst.size(1); ++x) { if (x == k) { dst[y][k][n] = src[y][k][n] - 1.0f; } else { dst[y][x][n] = src[y][x][n]; } } } } } } template<typename DType> inline void Softmax(Tensor<cpu, 2, DType> dst, const Tensor<cpu, 2, DType> &energy) { CHECK_EQ(dst.shape_, energy.shape_) << "Softmax: shape mismatch"; #pragma omp parallel for for (openmp_index_t y = 0; y < dst.size(0); ++y) { Softmax(dst[y], energy[y]); } } template<typename DType> inline void CLDLGrad(Tensor<cpu, 2, DType> dst, const Tensor<cpu, 2, DType> &src_1, const Tensor<cpu, 2, DType> &src_2, const Tensor<cpu, 2, DType> &src_3, const Tensor<cpu, 1, DType> &label) { #pragma omp parallel for for (openmp_index_t y = 0; y < dst.size(0); ++y) { const index_t k = static_cast<int>(label[y]); for (index_t x = 0; x < dst.size(1); ++x) { if (x == k) { DType prod = (1-src_2[y][x])*(1-src_3[y][x]); dst[y][k] = -1 / std::max(src_1[y][x], (DType)FLT_MIN) * std::pow(prod, (DType)0.5); } else { dst[y][x] = 0; } } } } template<typename DType> inline void CLDL(Tensor<cpu, 1, DType> dst, const Tensor<cpu, 1, DType> &src_1, const Tensor<cpu, 1, DType> &src_2, const Tensor<cpu, 1, DType> &src_3) { for (index_t x = 0; x < dst.size(0); ++x) { DType prod = (1-src_2[x])*(1-src_3[x]); DType p = std::pow(prod, (DType)0.5); dst[x] = p * std::log(std::max(src_1[x], (DType)(FLT_MIN))); } } template<typename DType> inline void CLDL(Tensor<cpu, 2, DType> dst, const Tensor<cpu, 2, DType> &src_1, const Tensor<cpu, 2, DType> &src_2, const Tensor<cpu, 2, DType> &src_3) { CHECK_EQ(dst.shape_, src_1.shape_) << "CLDL: shape mismatch"; #pragma omp parallel for for (openmp_index_t y = 0; y < dst.size(0); ++y) { CLDL(dst[y], src_1[y], src_2[y], src_3[y]); } } template<typename DType> inline void Softmax(Tensor<cpu, 3, DType> dst, const Tensor<cpu, 3, DType> &energy) { CHECK_EQ(dst.shape_, energy.shape_) << "Softmax: shape mismatch"; #pragma omp parallel for for (openmp_index_t y = 0; y < dst.size(0); ++y) { for (index_t n = 0; n < dst.size(2); ++n) { DType mmax = energy[y][0][n]; for (index_t x = 1; x < dst.size(1); ++x) { if (mmax < energy[y][x][n]) mmax = energy[y][x][n]; } DType sum = DType(0.0f); for (index_t x = 0; x < dst.size(1); ++x) { dst[y][x][n] = std::exp(energy[y][x][n] - mmax); sum += dst[y][x][n]; } for (index_t x = 0; x < dst.size(1); ++x) { dst[y][x][n] /= sum; } } } } template<typename IndexType, typename DType> inline void AddTakeGrad(Tensor<cpu, 2, DType> dst, const Tensor<cpu, 1, IndexType>& index, const Tensor<cpu, 2, DType> &src) { const int K = dst.shape_[0]; for (index_t y = 0; y < index.size(0); ++y) { int j = index[y]; if (j <= 0) j = 0; else if (j >= K) j = K - 1; dst[j] += src[y]; } } template<typename IndexType, typename DType> inline void AddTakeGradLargeBatch(Tensor<cpu, 2, DType> dst, const Tensor<cpu, 1, IndexType>& sorted, const Tensor<cpu, 1, IndexType>& index, const Tensor<cpu, 2, DType> &src) { for (index_t y = 0; y < sorted.size(0); ++y) { dst[sorted[y]] += src[index[y]]; } } template<typename IndexType, typename DType> inline void IndexFill(Tensor<cpu, 2, DType> dst, const Tensor<cpu, 1, IndexType>& index, const Tensor<cpu, 2, DType> &src) { for (index_t y = 0; y < index.size(0); ++y) { for (index_t j = 0; j < src.size(1); j++) { dst[index[y]][j] = src[y][j]; } } } template<typename KDType, typename VDType> inline void SortByKey(Tensor<cpu, 1, KDType> keys, Tensor<cpu, 1, VDType> values, bool is_ascend) { CHECK_EQ(keys.CheckContiguous(), true); CHECK_EQ(values.CheckContiguous(), true); CHECK_EQ(keys.size(0), values.size(0)) << "The sizes of key/value are not equal! keys_size: " << keys.size(0) << "values_size: " << values.size(0); std::vector<size_t> idx(keys.size(0)); std::vector<KDType> keys_vec(keys.size(0)); std::vector<VDType> values_vec(values.size(0)); for (int i = 0; i < keys.size(0); i++) { idx[i] = i; keys_vec[i] = keys[i]; values_vec[i] = values[i]; } if (is_ascend) { std::stable_sort(idx.begin(), idx.end(), [&keys_vec](size_t i1, size_t i2) {return keys_vec[i1] < keys_vec[i2]; }); } else { std::stable_sort(idx.begin(), idx.end(), [&keys_vec](size_t i1, size_t i2) {return keys_vec[i1] > keys_vec[i2]; }); } for (index_t i = 0; i < values.size(0); i++) { keys[i] = keys_vec[idx[i]]; values[i] = values_vec[idx[i]]; } } template<typename Device, typename VDType, typename SDType> inline void VectorizedSort(Tensor<Device, 1, VDType> values, Tensor<Device, 1, SDType> segments) { // We can sort each segments using two stable sorts SortByKey(values, segments, true); SortByKey(segments, values, true); } // blas related template<typename Device, typename DType> inline void VectorDot(Tensor<Device, 1, DType> dst, const Tensor<Device, 1, DType> &lhs, const Tensor<Device, 1, DType> &rhs) { CHECK_EQ(lhs.size(0), rhs.size(0)) << "VectorDot: Shape mismatch"; CHECK_EQ(dst.size(0), 1U) << "VectorDot: expect dst to be scalar"; expr::BLASEngine<Device, DType>::SetStream(lhs.stream_); mshadow::expr::BLASEngine<Device, DType>::dot( lhs.stream_, lhs.size(0), lhs.dptr_, 1, rhs.dptr_, 1, dst.dptr_); } template<bool transpose_left, bool transpose_right, typename Device, typename DType> inline void BatchGEMM(Tensor<Device, 3, DType> dst, const Tensor<Device, 3, DType> &lhs, const Tensor<Device, 3, DType> &rhs, DType alpha, DType beta, Tensor<Device, 1, DType*> workspace) { index_t batch_size = dst.shape_[0]; expr::BLASEngine<Device, DType>::SetStream(dst.stream_); Shape<3> sleft = transpose_left ? Shape3(lhs.shape_[0], lhs.shape_[2], lhs.shape_[1]) : lhs.shape_; Shape<3> sright = transpose_right ? Shape3(rhs.shape_[0], rhs.shape_[2], rhs.shape_[1]) : rhs.shape_; CHECK_EQ(dst.CheckContiguous(), true); CHECK_EQ(lhs.CheckContiguous(), true); CHECK_EQ(rhs.CheckContiguous(), true); CHECK(sleft[0] == batch_size && sright[0] == batch_size) << "BatchGEMM: batchsize must be equal." << "dst: " << dst.shape_ << "\n" << "lhs: " << sleft << "\n" << "rhs: " << sright << "\n"; CHECK(dst.size(1) == sleft[1] && dst.size(2) == sright[2] && sleft[2] == sright[1]) << "BatchGEMM: matrix shape mismatch" << "dst: " << dst.shape_ << "\n" << "lhs: " << sleft << "\n" << "rhs: " << sright << "\n"; CHECK(workspace.size(0) >= 3 * batch_size) << "Workspace Size must be bigger than " << 3 * batch_size; CHECK_EQ(workspace.CheckContiguous(), true); // use column major argument to compatible with most BLAS expr::BLASEngine<Device, DType>::batched_gemm (dst.stream_, transpose_right, transpose_left, transpose_right ? rhs.size(1) : rhs.size(2), transpose_left ? lhs.size(2) : lhs.size(1), transpose_right ? rhs.size(2) : rhs.size(1), alpha, rhs.dptr_, rhs.stride_, lhs.dptr_, lhs.stride_, beta, dst.dptr_, dst.stride_, batch_size, workspace.dptr_); } } // namespace mshadow #endif // MSHADOW_TENSOR_CPU_INL_H_
GB_binop__bor_int32.c
//------------------------------------------------------------------------------ // GB_binop: hard-coded functions for each built-in binary operator //------------------------------------------------------------------------------ // SuiteSparse:GraphBLAS, Timothy A. Davis, (c) 2017-2021, All Rights Reserved. // SPDX-License-Identifier: Apache-2.0 //------------------------------------------------------------------------------ // If this file is in the Generated/ folder, do not edit it (auto-generated). #include "GB.h" #ifndef GBCOMPACT #include "GB_control.h" #include "GB_ek_slice.h" #include "GB_dense.h" #include "GB_atomics.h" #include "GB_bitmap_assign_methods.h" #include "GB_binop__include.h" // C=binop(A,B) is defined by the following types and operators: // A+B function (eWiseAdd): GB_AaddB__bor_int32 // A.*B function (eWiseMult): GB_AemultB__bor_int32 // A*D function (colscale): (none) // D*A function (rowscale): (node) // C+=B function (dense accum): GB_Cdense_accumB__bor_int32 // C+=b function (dense accum): GB_Cdense_accumb__bor_int32 // C+=A+B function (dense ewise3): (none) // C=A+B function (dense ewise3): GB_Cdense_ewise3_noaccum__bor_int32 // C=scalar+B GB_bind1st__bor_int32 // C=scalar+B' GB_bind1st_tran__bor_int32 // C=A+scalar GB_bind2nd__bor_int32 // C=A'+scalar GB_bind2nd_tran__bor_int32 // C type: int32_t // A type: int32_t // B,b type: int32_t // BinaryOp: cij = (aij) | (bij) #define GB_ATYPE \ int32_t #define GB_BTYPE \ int32_t #define GB_CTYPE \ int32_t // true if the types of A and B are identical #define GB_ATYPE_IS_BTYPE \ 1 // true if the types of C and A are identical #define GB_CTYPE_IS_ATYPE \ 1 // true if the types of C and B are identical #define GB_CTYPE_IS_BTYPE \ 1 // aij = Ax [pA] #define GB_GETA(aij,Ax,pA) \ int32_t aij = Ax [pA] // bij = Bx [pB] #define GB_GETB(bij,Bx,pB) \ int32_t bij = Bx [pB] // declare scalar of the same type as C #define GB_CTYPE_SCALAR(t) \ int32_t t // cij = Ax [pA] #define GB_COPY_A_TO_C(cij,Ax,pA) \ cij = Ax [pA] // cij = Bx [pB] #define GB_COPY_B_TO_C(cij,Bx,pB) \ cij = Bx [pB] #define GB_CX(p) Cx [p] // binary operator #define GB_BINOP(z, x, y, i, j) \ z = (x) | (y) ; // op is second #define GB_OP_IS_SECOND \ 0 // op is plus_fp32 or plus_fp64 #define GB_OP_IS_PLUS_REAL \ 0 // op is minus_fp32 or minus_fp64 #define GB_OP_IS_MINUS_REAL \ 0 // GB_cblas_*axpy gateway routine, if it exists for this operator and type: #define GB_CBLAS_AXPY \ (none) // do the numerical phases of GB_add and GB_emult #define GB_PHASE_2_OF_2 // hard-coded loops can be vectorized #define GB_PRAGMA_SIMD_VECTORIZE GB_PRAGMA_SIMD // disable this operator and use the generic case if these conditions hold #define GB_DISABLE \ (GxB_NO_BOR || GxB_NO_INT32 || GxB_NO_BOR_INT32) //------------------------------------------------------------------------------ // C += A+B, all 3 matrices dense //------------------------------------------------------------------------------ #if 0 // The op must be MIN, MAX, PLUS, MINUS, RMINUS, TIMES, DIV, or RDIV. void (none) ( GrB_Matrix C, const GrB_Matrix A, const GrB_Matrix B, const int nthreads ) { #include "GB_dense_ewise3_accum_template.c" } #endif //------------------------------------------------------------------------------ // C = A+B, all 3 matrices dense //------------------------------------------------------------------------------ GrB_Info GB_Cdense_ewise3_noaccum__bor_int32 ( GrB_Matrix C, const GrB_Matrix A, const GrB_Matrix B, const int nthreads ) { #if GB_DISABLE return (GrB_NO_VALUE) ; #else #include "GB_dense_ewise3_noaccum_template.c" return (GrB_SUCCESS) ; #endif } //------------------------------------------------------------------------------ // C += B, accumulate a sparse matrix into a dense matrix //------------------------------------------------------------------------------ GrB_Info GB_Cdense_accumB__bor_int32 ( GrB_Matrix C, const GrB_Matrix B, const int64_t *GB_RESTRICT kfirst_slice, const int64_t *GB_RESTRICT klast_slice, const int64_t *GB_RESTRICT pstart_slice, const int ntasks, const int nthreads ) { #if GB_DISABLE return (GrB_NO_VALUE) ; #else { #include "GB_dense_subassign_23_template.c" } return (GrB_SUCCESS) ; #endif } //------------------------------------------------------------------------------ // C += b, accumulate a scalar into a dense matrix //------------------------------------------------------------------------------ GrB_Info GB_Cdense_accumb__bor_int32 ( GrB_Matrix C, const GB_void *p_bwork, const int nthreads ) { #if GB_DISABLE return (GrB_NO_VALUE) ; #else { // get the scalar b for C += b, of type int32_t int32_t bwork = (*((int32_t *) p_bwork)) ; #include "GB_dense_subassign_22_template.c" return (GrB_SUCCESS) ; } return (GrB_SUCCESS) ; #endif } //------------------------------------------------------------------------------ // C = A*D, column scale with diagonal D matrix //------------------------------------------------------------------------------ #if 0 GrB_Info (none) ( GrB_Matrix C, const GrB_Matrix A, bool A_is_pattern, const GrB_Matrix D, bool D_is_pattern, const int64_t *GB_RESTRICT kfirst_slice, const int64_t *GB_RESTRICT klast_slice, const int64_t *GB_RESTRICT pstart_slice, const int ntasks, const int nthreads ) { #if GB_DISABLE return (GrB_NO_VALUE) ; #else int32_t *GB_RESTRICT Cx = (int32_t *) C->x ; #include "GB_AxB_colscale_meta.c" return (GrB_SUCCESS) ; #endif } #endif //------------------------------------------------------------------------------ // C = D*B, row scale with diagonal D matrix //------------------------------------------------------------------------------ #if 0 GrB_Info (node) ( GrB_Matrix C, const GrB_Matrix D, bool D_is_pattern, const GrB_Matrix B, bool B_is_pattern, int nthreads ) { #if GB_DISABLE return (GrB_NO_VALUE) ; #else int32_t *GB_RESTRICT Cx = (int32_t *) C->x ; #include "GB_AxB_rowscale_meta.c" return (GrB_SUCCESS) ; #endif } #endif //------------------------------------------------------------------------------ // eWiseAdd: C = A+B or C<M> = A+B //------------------------------------------------------------------------------ #undef GB_FREE_ALL #define GB_FREE_ALL \ { \ GB_ek_slice_free (&pstart_Mslice, &kfirst_Mslice, &klast_Mslice) ; \ GB_ek_slice_free (&pstart_Aslice, &kfirst_Aslice, &klast_Aslice) ; \ GB_ek_slice_free (&pstart_Bslice, &kfirst_Bslice, &klast_Bslice) ; \ } GrB_Info GB_AaddB__bor_int32 ( GrB_Matrix C, const int C_sparsity, const GrB_Matrix M, const bool Mask_struct, const bool Mask_comp, const GrB_Matrix A, const GrB_Matrix B, const bool Ch_is_Mh, const int64_t *GB_RESTRICT C_to_M, const int64_t *GB_RESTRICT C_to_A, const int64_t *GB_RESTRICT C_to_B, const GB_task_struct *GB_RESTRICT TaskList, const int C_ntasks, const int C_nthreads, GB_Context Context ) { #if GB_DISABLE return (GrB_NO_VALUE) ; #else int64_t *pstart_Mslice = NULL, *kfirst_Mslice = NULL, *klast_Mslice = NULL ; int64_t *pstart_Aslice = NULL, *kfirst_Aslice = NULL, *klast_Aslice = NULL ; int64_t *pstart_Bslice = NULL, *kfirst_Bslice = NULL, *klast_Bslice = NULL ; #include "GB_add_template.c" GB_FREE_ALL ; return (GrB_SUCCESS) ; #endif } //------------------------------------------------------------------------------ // eWiseMult: C = A.*B or C<M> = A.*B //------------------------------------------------------------------------------ GrB_Info GB_AemultB__bor_int32 ( GrB_Matrix C, const int C_sparsity, const GrB_Matrix M, const bool Mask_struct, const bool Mask_comp, const GrB_Matrix A, const GrB_Matrix B, const int64_t *GB_RESTRICT C_to_M, const int64_t *GB_RESTRICT C_to_A, const int64_t *GB_RESTRICT C_to_B, const GB_task_struct *GB_RESTRICT TaskList, const int C_ntasks, const int C_nthreads, GB_Context Context ) { #if GB_DISABLE return (GrB_NO_VALUE) ; #else int64_t *pstart_Mslice = NULL, *kfirst_Mslice = NULL, *klast_Mslice = NULL ; int64_t *pstart_Aslice = NULL, *kfirst_Aslice = NULL, *klast_Aslice = NULL ; int64_t *pstart_Bslice = NULL, *kfirst_Bslice = NULL, *klast_Bslice = NULL ; #include "GB_emult_template.c" GB_FREE_ALL ; return (GrB_SUCCESS) ; #endif } //------------------------------------------------------------------------------ // Cx = op (x,Bx): apply a binary operator to a matrix with scalar bind1st //------------------------------------------------------------------------------ GrB_Info GB_bind1st__bor_int32 ( GB_void *Cx_output, // Cx and Bx may be aliased const GB_void *x_input, const GB_void *Bx_input, const int8_t *GB_RESTRICT Bb, int64_t anz, int nthreads ) { #if GB_DISABLE return (GrB_NO_VALUE) ; #else int32_t *Cx = (int32_t *) Cx_output ; int32_t x = (*((int32_t *) x_input)) ; int32_t *Bx = (int32_t *) Bx_input ; int64_t p ; #pragma omp parallel for num_threads(nthreads) schedule(static) for (p = 0 ; p < anz ; p++) { if (!GBB (Bb, p)) continue ; int32_t bij = Bx [p] ; Cx [p] = (x) | (bij) ; } return (GrB_SUCCESS) ; #endif } //------------------------------------------------------------------------------ // Cx = op (Ax,y): apply a binary operator to a matrix with scalar bind2nd //------------------------------------------------------------------------------ GrB_Info GB_bind2nd__bor_int32 ( GB_void *Cx_output, // Cx and Ax may be aliased const GB_void *Ax_input, const GB_void *y_input, const int8_t *GB_RESTRICT Ab, int64_t anz, int nthreads ) { #if GB_DISABLE return (GrB_NO_VALUE) ; #else int64_t p ; int32_t *Cx = (int32_t *) Cx_output ; int32_t *Ax = (int32_t *) Ax_input ; int32_t y = (*((int32_t *) y_input)) ; #pragma omp parallel for num_threads(nthreads) schedule(static) for (p = 0 ; p < anz ; p++) { if (!GBB (Ab, p)) continue ; int32_t aij = Ax [p] ; Cx [p] = (aij) | (y) ; } return (GrB_SUCCESS) ; #endif } //------------------------------------------------------------------------------ // C = op (x, A'): transpose and apply a binary operator //------------------------------------------------------------------------------ // cij = op (x, aij), no typecasting (in spite of the macro name) #undef GB_CAST_OP #define GB_CAST_OP(pC,pA) \ { \ int32_t aij = Ax [pA] ; \ Cx [pC] = (x) | (aij) ; \ } GrB_Info GB_bind1st_tran__bor_int32 ( GrB_Matrix C, const GB_void *x_input, const GrB_Matrix A, int64_t *GB_RESTRICT *Workspaces, const int64_t *GB_RESTRICT A_slice, int nworkspaces, int nthreads ) { // GB_unop_transpose.c uses GB_ATYPE, but A is // the 2nd input to binary operator z=f(x,y). #undef GB_ATYPE #define GB_ATYPE \ int32_t #if GB_DISABLE return (GrB_NO_VALUE) ; #else int32_t x = (*((const int32_t *) x_input)) ; #include "GB_unop_transpose.c" return (GrB_SUCCESS) ; #endif #undef GB_ATYPE #define GB_ATYPE \ int32_t } //------------------------------------------------------------------------------ // C = op (A', y): transpose and apply a binary operator //------------------------------------------------------------------------------ // cij = op (aij, y), no typecasting (in spite of the macro name) #undef GB_CAST_OP #define GB_CAST_OP(pC,pA) \ { \ int32_t aij = Ax [pA] ; \ Cx [pC] = (aij) | (y) ; \ } GrB_Info GB_bind2nd_tran__bor_int32 ( GrB_Matrix C, const GrB_Matrix A, const GB_void *y_input, int64_t *GB_RESTRICT *Workspaces, const int64_t *GB_RESTRICT A_slice, int nworkspaces, int nthreads ) { #if GB_DISABLE return (GrB_NO_VALUE) ; #else int32_t y = (*((const int32_t *) y_input)) ; #include "GB_unop_transpose.c" return (GrB_SUCCESS) ; #endif } #endif
yeefdtd.kernel_runtime.c
#include <omp.h> #include <stdio.h> #include <stdlib.h> #include "local_header.h" #include "openmp_pscmc_inc.h" #include "yeefdtd.kernel_inc.h" int openmp_kgm_eqn_core_init (openmp_pscmc_env * pe ,openmp_kgm_eqn_core_struct * kerstr ){ return 0 ;} void openmp_kgm_eqn_core_get_struct_len (size_t * len ){ ((len)[0] = sizeof(openmp_kgm_eqn_core_struct )); } int openmp_kgm_eqn_core_get_num_compute_units (openmp_kgm_eqn_core_struct * kerstr ){ return omp_get_max_threads ( ) ;} int openmp_kgm_eqn_core_get_xlen (){ return IDX_OPT_MAX ;} int openmp_kgm_eqn_core_exec (openmp_kgm_eqn_core_struct * kerstr ,long scmc_internal_g_xlen ,long scmc_internal_g_ylen ){ #pragma omp parallel { int xid ; int yid ; int numt = omp_get_num_threads ( ) ; int tid = omp_get_thread_num ( ) ; int ysingle = ( ( scmc_internal_g_ylen + ( numt - 1 ) ) / numt ) ; int ymin = ( tid * ysingle ) ; int ymax = ( ( 1 + tid ) * ysingle ) ; for ((yid = tid) ; ( yid < scmc_internal_g_ylen ) ; (yid = ( yid + numt ))) { for ((xid = 0) ; ( xid < scmc_internal_g_xlen ) ; (xid = ( xid + 1 ))) { openmp_kgm_eqn_core_scmc_kernel ( ( kerstr )->outEB , ( kerstr )->inEB , ( kerstr )->xoffset , ( kerstr )->yoffset , ( kerstr )->zoffset , ( ( kerstr )->y_cpu_core)[0] , ( ( kerstr )->numvec)[0] , ( ( kerstr )->XLEN)[0] , ( ( kerstr )->YLEN)[0] , ( ( kerstr )->ZLEN)[0] , ( ( kerstr )->ovlp)[0] , ( ( kerstr )->xblock)[0] , ( ( kerstr )->yblock)[0] , ( ( kerstr )->zblock)[0] , ( ( kerstr )->num_ele)[0] , ( ( kerstr )->DT)[0] , ( ( kerstr )->M)[0] , ( ( kerstr )->Q)[0] , ( ( kerstr )->DX)[0] , ( ( kerstr )->GEXT)[0] , ( ( kerstr )->rfz0)[0] , ( ( kerstr )->swap_input)[0] , yid , scmc_internal_g_ylen ); }}} return 0 ;} int openmp_kgm_eqn_core_scmc_set_parameter_outEB (openmp_kgm_eqn_core_struct * kerstr ,openmp_pscmc_mem * pm ){ ( ( kerstr )->outEB = pm->d_data); } int openmp_kgm_eqn_core_scmc_set_parameter_inEB (openmp_kgm_eqn_core_struct * kerstr ,openmp_pscmc_mem * pm ){ ( ( kerstr )->inEB = pm->d_data); } int openmp_kgm_eqn_core_scmc_set_parameter_xoffset (openmp_kgm_eqn_core_struct * kerstr ,openmp_pscmc_mem * pm ){ ( ( kerstr )->xoffset = pm->d_data); } int openmp_kgm_eqn_core_scmc_set_parameter_yoffset (openmp_kgm_eqn_core_struct * kerstr ,openmp_pscmc_mem * pm ){ ( ( kerstr )->yoffset = pm->d_data); } int openmp_kgm_eqn_core_scmc_set_parameter_zoffset (openmp_kgm_eqn_core_struct * kerstr ,openmp_pscmc_mem * pm ){ ( ( kerstr )->zoffset = pm->d_data); } int openmp_kgm_eqn_core_scmc_set_parameter_y_cpu_core (openmp_kgm_eqn_core_struct * kerstr ,openmp_pscmc_mem * pm ){ ( ( kerstr )->y_cpu_core = pm->d_data); } int openmp_kgm_eqn_core_scmc_set_parameter_numvec (openmp_kgm_eqn_core_struct * kerstr ,openmp_pscmc_mem * pm ){ ( ( kerstr )->numvec = pm->d_data); } int openmp_kgm_eqn_core_scmc_set_parameter_XLEN (openmp_kgm_eqn_core_struct * kerstr ,openmp_pscmc_mem * pm ){ ( ( kerstr )->XLEN = pm->d_data); } int openmp_kgm_eqn_core_scmc_set_parameter_YLEN (openmp_kgm_eqn_core_struct * kerstr ,openmp_pscmc_mem * pm ){ ( ( kerstr )->YLEN = pm->d_data); } int openmp_kgm_eqn_core_scmc_set_parameter_ZLEN (openmp_kgm_eqn_core_struct * kerstr ,openmp_pscmc_mem * pm ){ ( ( kerstr )->ZLEN = pm->d_data); } int openmp_kgm_eqn_core_scmc_set_parameter_ovlp (openmp_kgm_eqn_core_struct * kerstr ,openmp_pscmc_mem * pm ){ ( ( kerstr )->ovlp = pm->d_data); } int openmp_kgm_eqn_core_scmc_set_parameter_xblock (openmp_kgm_eqn_core_struct * kerstr ,openmp_pscmc_mem * pm ){ ( ( kerstr )->xblock = pm->d_data); } int openmp_kgm_eqn_core_scmc_set_parameter_yblock (openmp_kgm_eqn_core_struct * kerstr ,openmp_pscmc_mem * pm ){ ( ( kerstr )->yblock = pm->d_data); } int openmp_kgm_eqn_core_scmc_set_parameter_zblock (openmp_kgm_eqn_core_struct * kerstr ,openmp_pscmc_mem * pm ){ ( ( kerstr )->zblock = pm->d_data); } int openmp_kgm_eqn_core_scmc_set_parameter_num_ele (openmp_kgm_eqn_core_struct * kerstr ,openmp_pscmc_mem * pm ){ ( ( kerstr )->num_ele = pm->d_data); } int openmp_kgm_eqn_core_scmc_set_parameter_DT (openmp_kgm_eqn_core_struct * kerstr ,openmp_pscmc_mem * pm ){ ( ( kerstr )->DT = pm->d_data); } int openmp_kgm_eqn_core_scmc_set_parameter_M (openmp_kgm_eqn_core_struct * kerstr ,openmp_pscmc_mem * pm ){ ( ( kerstr )->M = pm->d_data); } int openmp_kgm_eqn_core_scmc_set_parameter_Q (openmp_kgm_eqn_core_struct * kerstr ,openmp_pscmc_mem * pm ){ ( ( kerstr )->Q = pm->d_data); } int openmp_kgm_eqn_core_scmc_set_parameter_DX (openmp_kgm_eqn_core_struct * kerstr ,openmp_pscmc_mem * pm ){ ( ( kerstr )->DX = pm->d_data); } int openmp_kgm_eqn_core_scmc_set_parameter_GEXT (openmp_kgm_eqn_core_struct * kerstr ,openmp_pscmc_mem * pm ){ ( ( kerstr )->GEXT = pm->d_data); } int openmp_kgm_eqn_core_scmc_set_parameter_rfz0 (openmp_kgm_eqn_core_struct * kerstr ,openmp_pscmc_mem * pm ){ ( ( kerstr )->rfz0 = pm->d_data); } int openmp_kgm_eqn_core_scmc_set_parameter_swap_input (openmp_kgm_eqn_core_struct * kerstr ,openmp_pscmc_mem * pm ){ ( ( kerstr )->swap_input = pm->d_data); } int openmp_kgm_calc_rho_init (openmp_pscmc_env * pe ,openmp_kgm_calc_rho_struct * kerstr ){ return 0 ;} void openmp_kgm_calc_rho_get_struct_len (size_t * len ){ ((len)[0] = sizeof(openmp_kgm_calc_rho_struct )); } int openmp_kgm_calc_rho_get_num_compute_units (openmp_kgm_calc_rho_struct * kerstr ){ return omp_get_max_threads ( ) ;} int openmp_kgm_calc_rho_get_xlen (){ return IDX_OPT_MAX ;} int openmp_kgm_calc_rho_exec (openmp_kgm_calc_rho_struct * kerstr ,long scmc_internal_g_xlen ,long scmc_internal_g_ylen ){ #pragma omp parallel { int xid ; int yid ; int numt = omp_get_num_threads ( ) ; int tid = omp_get_thread_num ( ) ; int ysingle = ( ( scmc_internal_g_ylen + ( numt - 1 ) ) / numt ) ; int ymin = ( tid * ysingle ) ; int ymax = ( ( 1 + tid ) * ysingle ) ; for ((yid = tid) ; ( yid < scmc_internal_g_ylen ) ; (yid = ( yid + numt ))) { for ((xid = 0) ; ( xid < scmc_internal_g_xlen ) ; (xid = ( xid + 1 ))) { openmp_kgm_calc_rho_scmc_kernel ( ( kerstr )->outEB , ( kerstr )->inEB , ( kerstr )->xoffset , ( kerstr )->yoffset , ( kerstr )->zoffset , ( ( kerstr )->y_cpu_core)[0] , ( ( kerstr )->numvec)[0] , ( ( kerstr )->XLEN)[0] , ( ( kerstr )->YLEN)[0] , ( ( kerstr )->ZLEN)[0] , ( ( kerstr )->ovlp)[0] , ( ( kerstr )->xblock)[0] , ( ( kerstr )->yblock)[0] , ( ( kerstr )->zblock)[0] , ( ( kerstr )->num_ele)[0] , ( ( kerstr )->DT)[0] , ( ( kerstr )->M)[0] , ( ( kerstr )->Q)[0] , ( ( kerstr )->DX)[0] , ( ( kerstr )->refz0)[0] , ( ( kerstr )->q)[0] , ( ( kerstr )->dtodx)[0] , ( ( kerstr )->mode)[0] , ( ( kerstr )->swap_input)[0] , yid , scmc_internal_g_ylen ); }}} return 0 ;} int openmp_kgm_calc_rho_scmc_set_parameter_outEB (openmp_kgm_calc_rho_struct * kerstr ,openmp_pscmc_mem * pm ){ ( ( kerstr )->outEB = pm->d_data); } int openmp_kgm_calc_rho_scmc_set_parameter_inEB (openmp_kgm_calc_rho_struct * kerstr ,openmp_pscmc_mem * pm ){ ( ( kerstr )->inEB = pm->d_data); } int openmp_kgm_calc_rho_scmc_set_parameter_xoffset (openmp_kgm_calc_rho_struct * kerstr ,openmp_pscmc_mem * pm ){ ( ( kerstr )->xoffset = pm->d_data); } int openmp_kgm_calc_rho_scmc_set_parameter_yoffset (openmp_kgm_calc_rho_struct * kerstr ,openmp_pscmc_mem * pm ){ ( ( kerstr )->yoffset = pm->d_data); } int openmp_kgm_calc_rho_scmc_set_parameter_zoffset (openmp_kgm_calc_rho_struct * kerstr ,openmp_pscmc_mem * pm ){ ( ( kerstr )->zoffset = pm->d_data); } int openmp_kgm_calc_rho_scmc_set_parameter_y_cpu_core (openmp_kgm_calc_rho_struct * kerstr ,openmp_pscmc_mem * pm ){ ( ( kerstr )->y_cpu_core = pm->d_data); } int openmp_kgm_calc_rho_scmc_set_parameter_numvec (openmp_kgm_calc_rho_struct * kerstr ,openmp_pscmc_mem * pm ){ ( ( kerstr )->numvec = pm->d_data); } int openmp_kgm_calc_rho_scmc_set_parameter_XLEN (openmp_kgm_calc_rho_struct * kerstr ,openmp_pscmc_mem * pm ){ ( ( kerstr )->XLEN = pm->d_data); } int openmp_kgm_calc_rho_scmc_set_parameter_YLEN (openmp_kgm_calc_rho_struct * kerstr ,openmp_pscmc_mem * pm ){ ( ( kerstr )->YLEN = pm->d_data); } int openmp_kgm_calc_rho_scmc_set_parameter_ZLEN (openmp_kgm_calc_rho_struct * kerstr ,openmp_pscmc_mem * pm ){ ( ( kerstr )->ZLEN = pm->d_data); } int openmp_kgm_calc_rho_scmc_set_parameter_ovlp (openmp_kgm_calc_rho_struct * kerstr ,openmp_pscmc_mem * pm ){ ( ( kerstr )->ovlp = pm->d_data); } int openmp_kgm_calc_rho_scmc_set_parameter_xblock (openmp_kgm_calc_rho_struct * kerstr ,openmp_pscmc_mem * pm ){ ( ( kerstr )->xblock = pm->d_data); } int openmp_kgm_calc_rho_scmc_set_parameter_yblock (openmp_kgm_calc_rho_struct * kerstr ,openmp_pscmc_mem * pm ){ ( ( kerstr )->yblock = pm->d_data); } int openmp_kgm_calc_rho_scmc_set_parameter_zblock (openmp_kgm_calc_rho_struct * kerstr ,openmp_pscmc_mem * pm ){ ( ( kerstr )->zblock = pm->d_data); } int openmp_kgm_calc_rho_scmc_set_parameter_num_ele (openmp_kgm_calc_rho_struct * kerstr ,openmp_pscmc_mem * pm ){ ( ( kerstr )->num_ele = pm->d_data); } int openmp_kgm_calc_rho_scmc_set_parameter_DT (openmp_kgm_calc_rho_struct * kerstr ,openmp_pscmc_mem * pm ){ ( ( kerstr )->DT = pm->d_data); } int openmp_kgm_calc_rho_scmc_set_parameter_M (openmp_kgm_calc_rho_struct * kerstr ,openmp_pscmc_mem * pm ){ ( ( kerstr )->M = pm->d_data); } int openmp_kgm_calc_rho_scmc_set_parameter_Q (openmp_kgm_calc_rho_struct * kerstr ,openmp_pscmc_mem * pm ){ ( ( kerstr )->Q = pm->d_data); } int openmp_kgm_calc_rho_scmc_set_parameter_DX (openmp_kgm_calc_rho_struct * kerstr ,openmp_pscmc_mem * pm ){ ( ( kerstr )->DX = pm->d_data); } int openmp_kgm_calc_rho_scmc_set_parameter_refz0 (openmp_kgm_calc_rho_struct * kerstr ,openmp_pscmc_mem * pm ){ ( ( kerstr )->refz0 = pm->d_data); } int openmp_kgm_calc_rho_scmc_set_parameter_q (openmp_kgm_calc_rho_struct * kerstr ,openmp_pscmc_mem * pm ){ ( ( kerstr )->q = pm->d_data); } int openmp_kgm_calc_rho_scmc_set_parameter_dtodx (openmp_kgm_calc_rho_struct * kerstr ,openmp_pscmc_mem * pm ){ ( ( kerstr )->dtodx = pm->d_data); } int openmp_kgm_calc_rho_scmc_set_parameter_mode (openmp_kgm_calc_rho_struct * kerstr ,openmp_pscmc_mem * pm ){ ( ( kerstr )->mode = pm->d_data); } int openmp_kgm_calc_rho_scmc_set_parameter_swap_input (openmp_kgm_calc_rho_struct * kerstr ,openmp_pscmc_mem * pm ){ ( ( kerstr )->swap_input = pm->d_data); } int openmp_PML_FDTD_CURL_BWD_init (openmp_pscmc_env * pe ,openmp_PML_FDTD_CURL_BWD_struct * kerstr ){ return 0 ;} void openmp_PML_FDTD_CURL_BWD_get_struct_len (size_t * len ){ ((len)[0] = sizeof(openmp_PML_FDTD_CURL_BWD_struct )); } int openmp_PML_FDTD_CURL_BWD_get_num_compute_units (openmp_PML_FDTD_CURL_BWD_struct * kerstr ){ return omp_get_max_threads ( ) ;} int openmp_PML_FDTD_CURL_BWD_get_xlen (){ return IDX_OPT_MAX ;} int openmp_PML_FDTD_CURL_BWD_exec (openmp_PML_FDTD_CURL_BWD_struct * kerstr ,long scmc_internal_g_xlen ,long scmc_internal_g_ylen ){ #pragma omp parallel { int xid ; int yid ; int numt = omp_get_num_threads ( ) ; int tid = omp_get_thread_num ( ) ; int ysingle = ( ( scmc_internal_g_ylen + ( numt - 1 ) ) / numt ) ; int ymin = ( tid * ysingle ) ; int ymax = ( ( 1 + tid ) * ysingle ) ; for ((yid = tid) ; ( yid < scmc_internal_g_ylen ) ; (yid = ( yid + numt ))) { for ((xid = 0) ; ( xid < scmc_internal_g_xlen ) ; (xid = ( xid + 1 ))) { openmp_PML_FDTD_CURL_BWD_scmc_kernel ( ( kerstr )->outEB , ( kerstr )->inEB , ( kerstr )->outPMLEB , ( kerstr )->inPMLEB , ( kerstr )->xoffset , ( kerstr )->yoffset , ( kerstr )->zoffset , ( ( kerstr )->y_cpu_core)[0] , ( ( kerstr )->numvec)[0] , ( ( kerstr )->XLEN)[0] , ( ( kerstr )->YLEN)[0] , ( ( kerstr )->ZLEN)[0] , ( ( kerstr )->ovlp)[0] , ( ( kerstr )->xblock)[0] , ( ( kerstr )->yblock)[0] , ( ( kerstr )->zblock)[0] , ( ( kerstr )->num_ele)[0] , ( ( kerstr )->DT)[0] , ( ( kerstr )->M)[0] , ( ( kerstr )->Q)[0] , ( ( kerstr )->DX)[0] , ( ( kerstr )->DY)[0] , ( ( kerstr )->DZ)[0] , ( ( kerstr )->abc_dir)[0] , ( ( kerstr )->level)[0] , ( ( kerstr )->pml_m)[0] , ( ( kerstr )->max_sigma)[0] , ( ( kerstr )->allxmax)[0] , ( ( kerstr )->allymax)[0] , ( ( kerstr )->allzmax)[0] , yid , scmc_internal_g_ylen ); }}} return 0 ;} int openmp_PML_FDTD_CURL_BWD_scmc_set_parameter_outEB (openmp_PML_FDTD_CURL_BWD_struct * kerstr ,openmp_pscmc_mem * pm ){ ( ( kerstr )->outEB = pm->d_data); } int openmp_PML_FDTD_CURL_BWD_scmc_set_parameter_inEB (openmp_PML_FDTD_CURL_BWD_struct * kerstr ,openmp_pscmc_mem * pm ){ ( ( kerstr )->inEB = pm->d_data); } int openmp_PML_FDTD_CURL_BWD_scmc_set_parameter_outPMLEB (openmp_PML_FDTD_CURL_BWD_struct * kerstr ,openmp_pscmc_mem * pm ){ ( ( kerstr )->outPMLEB = pm->d_data); } int openmp_PML_FDTD_CURL_BWD_scmc_set_parameter_inPMLEB (openmp_PML_FDTD_CURL_BWD_struct * kerstr ,openmp_pscmc_mem * pm ){ ( ( kerstr )->inPMLEB = pm->d_data); } int openmp_PML_FDTD_CURL_BWD_scmc_set_parameter_xoffset (openmp_PML_FDTD_CURL_BWD_struct * kerstr ,openmp_pscmc_mem * pm ){ ( ( kerstr )->xoffset = pm->d_data); } int openmp_PML_FDTD_CURL_BWD_scmc_set_parameter_yoffset (openmp_PML_FDTD_CURL_BWD_struct * kerstr ,openmp_pscmc_mem * pm ){ ( ( kerstr )->yoffset = pm->d_data); } int openmp_PML_FDTD_CURL_BWD_scmc_set_parameter_zoffset (openmp_PML_FDTD_CURL_BWD_struct * kerstr ,openmp_pscmc_mem * pm ){ ( ( kerstr )->zoffset = pm->d_data); } int openmp_PML_FDTD_CURL_BWD_scmc_set_parameter_y_cpu_core (openmp_PML_FDTD_CURL_BWD_struct * kerstr ,openmp_pscmc_mem * pm ){ ( ( kerstr )->y_cpu_core = pm->d_data); } int openmp_PML_FDTD_CURL_BWD_scmc_set_parameter_numvec (openmp_PML_FDTD_CURL_BWD_struct * kerstr ,openmp_pscmc_mem * pm ){ ( ( kerstr )->numvec = pm->d_data); } int openmp_PML_FDTD_CURL_BWD_scmc_set_parameter_XLEN (openmp_PML_FDTD_CURL_BWD_struct * kerstr ,openmp_pscmc_mem * pm ){ ( ( kerstr )->XLEN = pm->d_data); } int openmp_PML_FDTD_CURL_BWD_scmc_set_parameter_YLEN (openmp_PML_FDTD_CURL_BWD_struct * kerstr ,openmp_pscmc_mem * pm ){ ( ( kerstr )->YLEN = pm->d_data); } int openmp_PML_FDTD_CURL_BWD_scmc_set_parameter_ZLEN (openmp_PML_FDTD_CURL_BWD_struct * kerstr ,openmp_pscmc_mem * pm ){ ( ( kerstr )->ZLEN = pm->d_data); } int openmp_PML_FDTD_CURL_BWD_scmc_set_parameter_ovlp (openmp_PML_FDTD_CURL_BWD_struct * kerstr ,openmp_pscmc_mem * pm ){ ( ( kerstr )->ovlp = pm->d_data); } int openmp_PML_FDTD_CURL_BWD_scmc_set_parameter_xblock (openmp_PML_FDTD_CURL_BWD_struct * kerstr ,openmp_pscmc_mem * pm ){ ( ( kerstr )->xblock = pm->d_data); } int openmp_PML_FDTD_CURL_BWD_scmc_set_parameter_yblock (openmp_PML_FDTD_CURL_BWD_struct * kerstr ,openmp_pscmc_mem * pm ){ ( ( kerstr )->yblock = pm->d_data); } int openmp_PML_FDTD_CURL_BWD_scmc_set_parameter_zblock (openmp_PML_FDTD_CURL_BWD_struct * kerstr ,openmp_pscmc_mem * pm ){ ( ( kerstr )->zblock = pm->d_data); } int openmp_PML_FDTD_CURL_BWD_scmc_set_parameter_num_ele (openmp_PML_FDTD_CURL_BWD_struct * kerstr ,openmp_pscmc_mem * pm ){ ( ( kerstr )->num_ele = pm->d_data); } int openmp_PML_FDTD_CURL_BWD_scmc_set_parameter_DT (openmp_PML_FDTD_CURL_BWD_struct * kerstr ,openmp_pscmc_mem * pm ){ ( ( kerstr )->DT = pm->d_data); } int openmp_PML_FDTD_CURL_BWD_scmc_set_parameter_M (openmp_PML_FDTD_CURL_BWD_struct * kerstr ,openmp_pscmc_mem * pm ){ ( ( kerstr )->M = pm->d_data); } int openmp_PML_FDTD_CURL_BWD_scmc_set_parameter_Q (openmp_PML_FDTD_CURL_BWD_struct * kerstr ,openmp_pscmc_mem * pm ){ ( ( kerstr )->Q = pm->d_data); } int openmp_PML_FDTD_CURL_BWD_scmc_set_parameter_DX (openmp_PML_FDTD_CURL_BWD_struct * kerstr ,openmp_pscmc_mem * pm ){ ( ( kerstr )->DX = pm->d_data); } int openmp_PML_FDTD_CURL_BWD_scmc_set_parameter_DY (openmp_PML_FDTD_CURL_BWD_struct * kerstr ,openmp_pscmc_mem * pm ){ ( ( kerstr )->DY = pm->d_data); } int openmp_PML_FDTD_CURL_BWD_scmc_set_parameter_DZ (openmp_PML_FDTD_CURL_BWD_struct * kerstr ,openmp_pscmc_mem * pm ){ ( ( kerstr )->DZ = pm->d_data); } int openmp_PML_FDTD_CURL_BWD_scmc_set_parameter_abc_dir (openmp_PML_FDTD_CURL_BWD_struct * kerstr ,openmp_pscmc_mem * pm ){ ( ( kerstr )->abc_dir = pm->d_data); } int openmp_PML_FDTD_CURL_BWD_scmc_set_parameter_level (openmp_PML_FDTD_CURL_BWD_struct * kerstr ,openmp_pscmc_mem * pm ){ ( ( kerstr )->level = pm->d_data); } int openmp_PML_FDTD_CURL_BWD_scmc_set_parameter_pml_m (openmp_PML_FDTD_CURL_BWD_struct * kerstr ,openmp_pscmc_mem * pm ){ ( ( kerstr )->pml_m = pm->d_data); } int openmp_PML_FDTD_CURL_BWD_scmc_set_parameter_max_sigma (openmp_PML_FDTD_CURL_BWD_struct * kerstr ,openmp_pscmc_mem * pm ){ ( ( kerstr )->max_sigma = pm->d_data); } int openmp_PML_FDTD_CURL_BWD_scmc_set_parameter_allxmax (openmp_PML_FDTD_CURL_BWD_struct * kerstr ,openmp_pscmc_mem * pm ){ ( ( kerstr )->allxmax = pm->d_data); } int openmp_PML_FDTD_CURL_BWD_scmc_set_parameter_allymax (openmp_PML_FDTD_CURL_BWD_struct * kerstr ,openmp_pscmc_mem * pm ){ ( ( kerstr )->allymax = pm->d_data); } int openmp_PML_FDTD_CURL_BWD_scmc_set_parameter_allzmax (openmp_PML_FDTD_CURL_BWD_struct * kerstr ,openmp_pscmc_mem * pm ){ ( ( kerstr )->allzmax = pm->d_data); } int openmp_PML_FDTD_CURL_FWD_init (openmp_pscmc_env * pe ,openmp_PML_FDTD_CURL_FWD_struct * kerstr ){ return 0 ;} void openmp_PML_FDTD_CURL_FWD_get_struct_len (size_t * len ){ ((len)[0] = sizeof(openmp_PML_FDTD_CURL_FWD_struct )); } int openmp_PML_FDTD_CURL_FWD_get_num_compute_units (openmp_PML_FDTD_CURL_FWD_struct * kerstr ){ return omp_get_max_threads ( ) ;} int openmp_PML_FDTD_CURL_FWD_get_xlen (){ return IDX_OPT_MAX ;} int openmp_PML_FDTD_CURL_FWD_exec (openmp_PML_FDTD_CURL_FWD_struct * kerstr ,long scmc_internal_g_xlen ,long scmc_internal_g_ylen ){ #pragma omp parallel { int xid ; int yid ; int numt = omp_get_num_threads ( ) ; int tid = omp_get_thread_num ( ) ; int ysingle = ( ( scmc_internal_g_ylen + ( numt - 1 ) ) / numt ) ; int ymin = ( tid * ysingle ) ; int ymax = ( ( 1 + tid ) * ysingle ) ; for ((yid = tid) ; ( yid < scmc_internal_g_ylen ) ; (yid = ( yid + numt ))) { for ((xid = 0) ; ( xid < scmc_internal_g_xlen ) ; (xid = ( xid + 1 ))) { openmp_PML_FDTD_CURL_FWD_scmc_kernel ( ( kerstr )->outEB , ( kerstr )->inEB , ( kerstr )->outPMLEB , ( kerstr )->inPMLEB , ( kerstr )->xoffset , ( kerstr )->yoffset , ( kerstr )->zoffset , ( ( kerstr )->y_cpu_core)[0] , ( ( kerstr )->numvec)[0] , ( ( kerstr )->XLEN)[0] , ( ( kerstr )->YLEN)[0] , ( ( kerstr )->ZLEN)[0] , ( ( kerstr )->ovlp)[0] , ( ( kerstr )->xblock)[0] , ( ( kerstr )->yblock)[0] , ( ( kerstr )->zblock)[0] , ( ( kerstr )->num_ele)[0] , ( ( kerstr )->DT)[0] , ( ( kerstr )->M)[0] , ( ( kerstr )->Q)[0] , ( ( kerstr )->DX)[0] , ( ( kerstr )->DY)[0] , ( ( kerstr )->DZ)[0] , ( ( kerstr )->abc_dir)[0] , ( ( kerstr )->level)[0] , ( ( kerstr )->pml_m)[0] , ( ( kerstr )->max_sigma)[0] , ( ( kerstr )->allxmax)[0] , ( ( kerstr )->allymax)[0] , ( ( kerstr )->allzmax)[0] , yid , scmc_internal_g_ylen ); }}} return 0 ;} int openmp_PML_FDTD_CURL_FWD_scmc_set_parameter_outEB (openmp_PML_FDTD_CURL_FWD_struct * kerstr ,openmp_pscmc_mem * pm ){ ( ( kerstr )->outEB = pm->d_data); } int openmp_PML_FDTD_CURL_FWD_scmc_set_parameter_inEB (openmp_PML_FDTD_CURL_FWD_struct * kerstr ,openmp_pscmc_mem * pm ){ ( ( kerstr )->inEB = pm->d_data); } int openmp_PML_FDTD_CURL_FWD_scmc_set_parameter_outPMLEB (openmp_PML_FDTD_CURL_FWD_struct * kerstr ,openmp_pscmc_mem * pm ){ ( ( kerstr )->outPMLEB = pm->d_data); } int openmp_PML_FDTD_CURL_FWD_scmc_set_parameter_inPMLEB (openmp_PML_FDTD_CURL_FWD_struct * kerstr ,openmp_pscmc_mem * pm ){ ( ( kerstr )->inPMLEB = pm->d_data); } int openmp_PML_FDTD_CURL_FWD_scmc_set_parameter_xoffset (openmp_PML_FDTD_CURL_FWD_struct * kerstr ,openmp_pscmc_mem * pm ){ ( ( kerstr )->xoffset = pm->d_data); } int openmp_PML_FDTD_CURL_FWD_scmc_set_parameter_yoffset (openmp_PML_FDTD_CURL_FWD_struct * kerstr ,openmp_pscmc_mem * pm ){ ( ( kerstr )->yoffset = pm->d_data); } int openmp_PML_FDTD_CURL_FWD_scmc_set_parameter_zoffset (openmp_PML_FDTD_CURL_FWD_struct * kerstr ,openmp_pscmc_mem * pm ){ ( ( kerstr )->zoffset = pm->d_data); } int openmp_PML_FDTD_CURL_FWD_scmc_set_parameter_y_cpu_core (openmp_PML_FDTD_CURL_FWD_struct * kerstr ,openmp_pscmc_mem * pm ){ ( ( kerstr )->y_cpu_core = pm->d_data); } int openmp_PML_FDTD_CURL_FWD_scmc_set_parameter_numvec (openmp_PML_FDTD_CURL_FWD_struct * kerstr ,openmp_pscmc_mem * pm ){ ( ( kerstr )->numvec = pm->d_data); } int openmp_PML_FDTD_CURL_FWD_scmc_set_parameter_XLEN (openmp_PML_FDTD_CURL_FWD_struct * kerstr ,openmp_pscmc_mem * pm ){ ( ( kerstr )->XLEN = pm->d_data); } int openmp_PML_FDTD_CURL_FWD_scmc_set_parameter_YLEN (openmp_PML_FDTD_CURL_FWD_struct * kerstr ,openmp_pscmc_mem * pm ){ ( ( kerstr )->YLEN = pm->d_data); } int openmp_PML_FDTD_CURL_FWD_scmc_set_parameter_ZLEN (openmp_PML_FDTD_CURL_FWD_struct * kerstr ,openmp_pscmc_mem * pm ){ ( ( kerstr )->ZLEN = pm->d_data); } int openmp_PML_FDTD_CURL_FWD_scmc_set_parameter_ovlp (openmp_PML_FDTD_CURL_FWD_struct * kerstr ,openmp_pscmc_mem * pm ){ ( ( kerstr )->ovlp = pm->d_data); } int openmp_PML_FDTD_CURL_FWD_scmc_set_parameter_xblock (openmp_PML_FDTD_CURL_FWD_struct * kerstr ,openmp_pscmc_mem * pm ){ ( ( kerstr )->xblock = pm->d_data); } int openmp_PML_FDTD_CURL_FWD_scmc_set_parameter_yblock (openmp_PML_FDTD_CURL_FWD_struct * kerstr ,openmp_pscmc_mem * pm ){ ( ( kerstr )->yblock = pm->d_data); } int openmp_PML_FDTD_CURL_FWD_scmc_set_parameter_zblock (openmp_PML_FDTD_CURL_FWD_struct * kerstr ,openmp_pscmc_mem * pm ){ ( ( kerstr )->zblock = pm->d_data); } int openmp_PML_FDTD_CURL_FWD_scmc_set_parameter_num_ele (openmp_PML_FDTD_CURL_FWD_struct * kerstr ,openmp_pscmc_mem * pm ){ ( ( kerstr )->num_ele = pm->d_data); } int openmp_PML_FDTD_CURL_FWD_scmc_set_parameter_DT (openmp_PML_FDTD_CURL_FWD_struct * kerstr ,openmp_pscmc_mem * pm ){ ( ( kerstr )->DT = pm->d_data); } int openmp_PML_FDTD_CURL_FWD_scmc_set_parameter_M (openmp_PML_FDTD_CURL_FWD_struct * kerstr ,openmp_pscmc_mem * pm ){ ( ( kerstr )->M = pm->d_data); } int openmp_PML_FDTD_CURL_FWD_scmc_set_parameter_Q (openmp_PML_FDTD_CURL_FWD_struct * kerstr ,openmp_pscmc_mem * pm ){ ( ( kerstr )->Q = pm->d_data); } int openmp_PML_FDTD_CURL_FWD_scmc_set_parameter_DX (openmp_PML_FDTD_CURL_FWD_struct * kerstr ,openmp_pscmc_mem * pm ){ ( ( kerstr )->DX = pm->d_data); } int openmp_PML_FDTD_CURL_FWD_scmc_set_parameter_DY (openmp_PML_FDTD_CURL_FWD_struct * kerstr ,openmp_pscmc_mem * pm ){ ( ( kerstr )->DY = pm->d_data); } int openmp_PML_FDTD_CURL_FWD_scmc_set_parameter_DZ (openmp_PML_FDTD_CURL_FWD_struct * kerstr ,openmp_pscmc_mem * pm ){ ( ( kerstr )->DZ = pm->d_data); } int openmp_PML_FDTD_CURL_FWD_scmc_set_parameter_abc_dir (openmp_PML_FDTD_CURL_FWD_struct * kerstr ,openmp_pscmc_mem * pm ){ ( ( kerstr )->abc_dir = pm->d_data); } int openmp_PML_FDTD_CURL_FWD_scmc_set_parameter_level (openmp_PML_FDTD_CURL_FWD_struct * kerstr ,openmp_pscmc_mem * pm ){ ( ( kerstr )->level = pm->d_data); } int openmp_PML_FDTD_CURL_FWD_scmc_set_parameter_pml_m (openmp_PML_FDTD_CURL_FWD_struct * kerstr ,openmp_pscmc_mem * pm ){ ( ( kerstr )->pml_m = pm->d_data); } int openmp_PML_FDTD_CURL_FWD_scmc_set_parameter_max_sigma (openmp_PML_FDTD_CURL_FWD_struct * kerstr ,openmp_pscmc_mem * pm ){ ( ( kerstr )->max_sigma = pm->d_data); } int openmp_PML_FDTD_CURL_FWD_scmc_set_parameter_allxmax (openmp_PML_FDTD_CURL_FWD_struct * kerstr ,openmp_pscmc_mem * pm ){ ( ( kerstr )->allxmax = pm->d_data); } int openmp_PML_FDTD_CURL_FWD_scmc_set_parameter_allymax (openmp_PML_FDTD_CURL_FWD_struct * kerstr ,openmp_pscmc_mem * pm ){ ( ( kerstr )->allymax = pm->d_data); } int openmp_PML_FDTD_CURL_FWD_scmc_set_parameter_allzmax (openmp_PML_FDTD_CURL_FWD_struct * kerstr ,openmp_pscmc_mem * pm ){ ( ( kerstr )->allzmax = pm->d_data); } int openmp_merge_current_init (openmp_pscmc_env * pe ,openmp_merge_current_struct * kerstr ){ return 0 ;} void openmp_merge_current_get_struct_len (size_t * len ){ ((len)[0] = sizeof(openmp_merge_current_struct )); } int openmp_merge_current_get_num_compute_units (openmp_merge_current_struct * kerstr ){ return omp_get_max_threads ( ) ;} int openmp_merge_current_get_xlen (){ return IDX_OPT_MAX ;} int openmp_merge_current_exec (openmp_merge_current_struct * kerstr ,long scmc_internal_g_xlen ,long scmc_internal_g_ylen ){ #pragma omp parallel { int xid ; int yid ; int numt = omp_get_num_threads ( ) ; int tid = omp_get_thread_num ( ) ; int ysingle = ( ( scmc_internal_g_ylen + ( numt - 1 ) ) / numt ) ; int ymin = ( tid * ysingle ) ; int ymax = ( ( 1 + tid ) * ysingle ) ; for ((yid = tid) ; ( yid < scmc_internal_g_ylen ) ; (yid = ( yid + numt ))) { for ((xid = 0) ; ( xid < scmc_internal_g_xlen ) ; (xid = ( xid + 1 ))) { openmp_merge_current_scmc_kernel ( ( kerstr )->outEB , ( kerstr )->inEB , ( ( kerstr )->y_cpu_core)[0] , ( ( kerstr )->numvec)[0] , ( ( kerstr )->XLEN)[0] , ( ( kerstr )->YLEN)[0] , ( ( kerstr )->ZLEN)[0] , ( ( kerstr )->ovlp)[0] , ( ( kerstr )->xblock)[0] , ( ( kerstr )->yblock)[0] , ( ( kerstr )->zblock)[0] , ( ( kerstr )->num_ele)[0] , yid , scmc_internal_g_ylen ); }}} return 0 ;} int openmp_merge_current_scmc_set_parameter_outEB (openmp_merge_current_struct * kerstr ,openmp_pscmc_mem * pm ){ ( ( kerstr )->outEB = pm->d_data); } int openmp_merge_current_scmc_set_parameter_inEB (openmp_merge_current_struct * kerstr ,openmp_pscmc_mem * pm ){ ( ( kerstr )->inEB = pm->d_data); } int openmp_merge_current_scmc_set_parameter_y_cpu_core (openmp_merge_current_struct * kerstr ,openmp_pscmc_mem * pm ){ ( ( kerstr )->y_cpu_core = pm->d_data); } int openmp_merge_current_scmc_set_parameter_numvec (openmp_merge_current_struct * kerstr ,openmp_pscmc_mem * pm ){ ( ( kerstr )->numvec = pm->d_data); } int openmp_merge_current_scmc_set_parameter_XLEN (openmp_merge_current_struct * kerstr ,openmp_pscmc_mem * pm ){ ( ( kerstr )->XLEN = pm->d_data); } int openmp_merge_current_scmc_set_parameter_YLEN (openmp_merge_current_struct * kerstr ,openmp_pscmc_mem * pm ){ ( ( kerstr )->YLEN = pm->d_data); } int openmp_merge_current_scmc_set_parameter_ZLEN (openmp_merge_current_struct * kerstr ,openmp_pscmc_mem * pm ){ ( ( kerstr )->ZLEN = pm->d_data); } int openmp_merge_current_scmc_set_parameter_ovlp (openmp_merge_current_struct * kerstr ,openmp_pscmc_mem * pm ){ ( ( kerstr )->ovlp = pm->d_data); } int openmp_merge_current_scmc_set_parameter_xblock (openmp_merge_current_struct * kerstr ,openmp_pscmc_mem * pm ){ ( ( kerstr )->xblock = pm->d_data); } int openmp_merge_current_scmc_set_parameter_yblock (openmp_merge_current_struct * kerstr ,openmp_pscmc_mem * pm ){ ( ( kerstr )->yblock = pm->d_data); } int openmp_merge_current_scmc_set_parameter_zblock (openmp_merge_current_struct * kerstr ,openmp_pscmc_mem * pm ){ ( ( kerstr )->zblock = pm->d_data); } int openmp_merge_current_scmc_set_parameter_num_ele (openmp_merge_current_struct * kerstr ,openmp_pscmc_mem * pm ){ ( ( kerstr )->num_ele = pm->d_data); } int openmp_merge_current_2_init (openmp_pscmc_env * pe ,openmp_merge_current_2_struct * kerstr ){ return 0 ;} void openmp_merge_current_2_get_struct_len (size_t * len ){ ((len)[0] = sizeof(openmp_merge_current_2_struct )); } int openmp_merge_current_2_get_num_compute_units (openmp_merge_current_2_struct * kerstr ){ return omp_get_max_threads ( ) ;} int openmp_merge_current_2_get_xlen (){ return IDX_OPT_MAX ;} int openmp_merge_current_2_exec (openmp_merge_current_2_struct * kerstr ,long scmc_internal_g_xlen ,long scmc_internal_g_ylen ){ #pragma omp parallel { int xid ; int yid ; int numt = omp_get_num_threads ( ) ; int tid = omp_get_thread_num ( ) ; int ysingle = ( ( scmc_internal_g_ylen + ( numt - 1 ) ) / numt ) ; int ymin = ( tid * ysingle ) ; int ymax = ( ( 1 + tid ) * ysingle ) ; for ((yid = tid) ; ( yid < scmc_internal_g_ylen ) ; (yid = ( yid + numt ))) { for ((xid = 0) ; ( xid < scmc_internal_g_xlen ) ; (xid = ( xid + 1 ))) { openmp_merge_current_2_scmc_kernel ( ( kerstr )->outEB , ( kerstr )->inEB , ( ( kerstr )->y_cpu_core)[0] , ( ( kerstr )->numvec)[0] , ( ( kerstr )->XLEN)[0] , ( ( kerstr )->YLEN)[0] , ( ( kerstr )->ZLEN)[0] , ( ( kerstr )->ovlp)[0] , ( ( kerstr )->xblock)[0] , ( ( kerstr )->yblock)[0] , ( ( kerstr )->zblock)[0] , ( ( kerstr )->num_ele)[0] , yid , scmc_internal_g_ylen ); }}} return 0 ;} int openmp_merge_current_2_scmc_set_parameter_outEB (openmp_merge_current_2_struct * kerstr ,openmp_pscmc_mem * pm ){ ( ( kerstr )->outEB = pm->d_data); } int openmp_merge_current_2_scmc_set_parameter_inEB (openmp_merge_current_2_struct * kerstr ,openmp_pscmc_mem * pm ){ ( ( kerstr )->inEB = pm->d_data); } int openmp_merge_current_2_scmc_set_parameter_y_cpu_core (openmp_merge_current_2_struct * kerstr ,openmp_pscmc_mem * pm ){ ( ( kerstr )->y_cpu_core = pm->d_data); } int openmp_merge_current_2_scmc_set_parameter_numvec (openmp_merge_current_2_struct * kerstr ,openmp_pscmc_mem * pm ){ ( ( kerstr )->numvec = pm->d_data); } int openmp_merge_current_2_scmc_set_parameter_XLEN (openmp_merge_current_2_struct * kerstr ,openmp_pscmc_mem * pm ){ ( ( kerstr )->XLEN = pm->d_data); } int openmp_merge_current_2_scmc_set_parameter_YLEN (openmp_merge_current_2_struct * kerstr ,openmp_pscmc_mem * pm ){ ( ( kerstr )->YLEN = pm->d_data); } int openmp_merge_current_2_scmc_set_parameter_ZLEN (openmp_merge_current_2_struct * kerstr ,openmp_pscmc_mem * pm ){ ( ( kerstr )->ZLEN = pm->d_data); } int openmp_merge_current_2_scmc_set_parameter_ovlp (openmp_merge_current_2_struct * kerstr ,openmp_pscmc_mem * pm ){ ( ( kerstr )->ovlp = pm->d_data); } int openmp_merge_current_2_scmc_set_parameter_xblock (openmp_merge_current_2_struct * kerstr ,openmp_pscmc_mem * pm ){ ( ( kerstr )->xblock = pm->d_data); } int openmp_merge_current_2_scmc_set_parameter_yblock (openmp_merge_current_2_struct * kerstr ,openmp_pscmc_mem * pm ){ ( ( kerstr )->yblock = pm->d_data); } int openmp_merge_current_2_scmc_set_parameter_zblock (openmp_merge_current_2_struct * kerstr ,openmp_pscmc_mem * pm ){ ( ( kerstr )->zblock = pm->d_data); } int openmp_merge_current_2_scmc_set_parameter_num_ele (openmp_merge_current_2_struct * kerstr ,openmp_pscmc_mem * pm ){ ( ( kerstr )->num_ele = pm->d_data); } int openmp_Yee_FDTD_Div_FWD_4th_init (openmp_pscmc_env * pe ,openmp_Yee_FDTD_Div_FWD_4th_struct * kerstr ){ return 0 ;} void openmp_Yee_FDTD_Div_FWD_4th_get_struct_len (size_t * len ){ ((len)[0] = sizeof(openmp_Yee_FDTD_Div_FWD_4th_struct )); } int openmp_Yee_FDTD_Div_FWD_4th_get_num_compute_units (openmp_Yee_FDTD_Div_FWD_4th_struct * kerstr ){ return omp_get_max_threads ( ) ;} int openmp_Yee_FDTD_Div_FWD_4th_get_xlen (){ return IDX_OPT_MAX ;} int openmp_Yee_FDTD_Div_FWD_4th_exec (openmp_Yee_FDTD_Div_FWD_4th_struct * kerstr ,long scmc_internal_g_xlen ,long scmc_internal_g_ylen ){ #pragma omp parallel { int xid ; int yid ; int numt = omp_get_num_threads ( ) ; int tid = omp_get_thread_num ( ) ; int ysingle = ( ( scmc_internal_g_ylen + ( numt - 1 ) ) / numt ) ; int ymin = ( tid * ysingle ) ; int ymax = ( ( 1 + tid ) * ysingle ) ; for ((yid = tid) ; ( yid < scmc_internal_g_ylen ) ; (yid = ( yid + numt ))) { for ((xid = 0) ; ( xid < scmc_internal_g_xlen ) ; (xid = ( xid + 1 ))) { openmp_Yee_FDTD_Div_FWD_4th_scmc_kernel ( ( kerstr )->outEB , ( kerstr )->inEB , ( ( kerstr )->y_cpu_core)[0] , ( ( kerstr )->numvec)[0] , ( ( kerstr )->XLEN)[0] , ( ( kerstr )->YLEN)[0] , ( ( kerstr )->ZLEN)[0] , ( ( kerstr )->ovlp)[0] , ( ( kerstr )->xblock)[0] , ( ( kerstr )->yblock)[0] , ( ( kerstr )->zblock)[0] , ( ( kerstr )->num_ele)[0] , ( ( kerstr )->DT)[0] , yid , scmc_internal_g_ylen ); }}} return 0 ;} int openmp_Yee_FDTD_Div_FWD_4th_scmc_set_parameter_outEB (openmp_Yee_FDTD_Div_FWD_4th_struct * kerstr ,openmp_pscmc_mem * pm ){ ( ( kerstr )->outEB = pm->d_data); } int openmp_Yee_FDTD_Div_FWD_4th_scmc_set_parameter_inEB (openmp_Yee_FDTD_Div_FWD_4th_struct * kerstr ,openmp_pscmc_mem * pm ){ ( ( kerstr )->inEB = pm->d_data); } int openmp_Yee_FDTD_Div_FWD_4th_scmc_set_parameter_y_cpu_core (openmp_Yee_FDTD_Div_FWD_4th_struct * kerstr ,openmp_pscmc_mem * pm ){ ( ( kerstr )->y_cpu_core = pm->d_data); } int openmp_Yee_FDTD_Div_FWD_4th_scmc_set_parameter_numvec (openmp_Yee_FDTD_Div_FWD_4th_struct * kerstr ,openmp_pscmc_mem * pm ){ ( ( kerstr )->numvec = pm->d_data); } int openmp_Yee_FDTD_Div_FWD_4th_scmc_set_parameter_XLEN (openmp_Yee_FDTD_Div_FWD_4th_struct * kerstr ,openmp_pscmc_mem * pm ){ ( ( kerstr )->XLEN = pm->d_data); } int openmp_Yee_FDTD_Div_FWD_4th_scmc_set_parameter_YLEN (openmp_Yee_FDTD_Div_FWD_4th_struct * kerstr ,openmp_pscmc_mem * pm ){ ( ( kerstr )->YLEN = pm->d_data); } int openmp_Yee_FDTD_Div_FWD_4th_scmc_set_parameter_ZLEN (openmp_Yee_FDTD_Div_FWD_4th_struct * kerstr ,openmp_pscmc_mem * pm ){ ( ( kerstr )->ZLEN = pm->d_data); } int openmp_Yee_FDTD_Div_FWD_4th_scmc_set_parameter_ovlp (openmp_Yee_FDTD_Div_FWD_4th_struct * kerstr ,openmp_pscmc_mem * pm ){ ( ( kerstr )->ovlp = pm->d_data); } int openmp_Yee_FDTD_Div_FWD_4th_scmc_set_parameter_xblock (openmp_Yee_FDTD_Div_FWD_4th_struct * kerstr ,openmp_pscmc_mem * pm ){ ( ( kerstr )->xblock = pm->d_data); } int openmp_Yee_FDTD_Div_FWD_4th_scmc_set_parameter_yblock (openmp_Yee_FDTD_Div_FWD_4th_struct * kerstr ,openmp_pscmc_mem * pm ){ ( ( kerstr )->yblock = pm->d_data); } int openmp_Yee_FDTD_Div_FWD_4th_scmc_set_parameter_zblock (openmp_Yee_FDTD_Div_FWD_4th_struct * kerstr ,openmp_pscmc_mem * pm ){ ( ( kerstr )->zblock = pm->d_data); } int openmp_Yee_FDTD_Div_FWD_4th_scmc_set_parameter_num_ele (openmp_Yee_FDTD_Div_FWD_4th_struct * kerstr ,openmp_pscmc_mem * pm ){ ( ( kerstr )->num_ele = pm->d_data); } int openmp_Yee_FDTD_Div_FWD_4th_scmc_set_parameter_DT (openmp_Yee_FDTD_Div_FWD_4th_struct * kerstr ,openmp_pscmc_mem * pm ){ ( ( kerstr )->DT = pm->d_data); } int openmp_Yee_FDTD_Div_FWD_init (openmp_pscmc_env * pe ,openmp_Yee_FDTD_Div_FWD_struct * kerstr ){ return 0 ;} void openmp_Yee_FDTD_Div_FWD_get_struct_len (size_t * len ){ ((len)[0] = sizeof(openmp_Yee_FDTD_Div_FWD_struct )); } int openmp_Yee_FDTD_Div_FWD_get_num_compute_units (openmp_Yee_FDTD_Div_FWD_struct * kerstr ){ return omp_get_max_threads ( ) ;} int openmp_Yee_FDTD_Div_FWD_get_xlen (){ return IDX_OPT_MAX ;} int openmp_Yee_FDTD_Div_FWD_exec (openmp_Yee_FDTD_Div_FWD_struct * kerstr ,long scmc_internal_g_xlen ,long scmc_internal_g_ylen ){ #pragma omp parallel { int xid ; int yid ; int numt = omp_get_num_threads ( ) ; int tid = omp_get_thread_num ( ) ; int ysingle = ( ( scmc_internal_g_ylen + ( numt - 1 ) ) / numt ) ; int ymin = ( tid * ysingle ) ; int ymax = ( ( 1 + tid ) * ysingle ) ; for ((yid = tid) ; ( yid < scmc_internal_g_ylen ) ; (yid = ( yid + numt ))) { for ((xid = 0) ; ( xid < scmc_internal_g_xlen ) ; (xid = ( xid + 1 ))) { openmp_Yee_FDTD_Div_FWD_scmc_kernel ( ( kerstr )->outEB , ( kerstr )->inEB , ( ( kerstr )->y_cpu_core)[0] , ( ( kerstr )->numvec)[0] , ( ( kerstr )->XLEN)[0] , ( ( kerstr )->YLEN)[0] , ( ( kerstr )->ZLEN)[0] , ( ( kerstr )->ovlp)[0] , ( ( kerstr )->xblock)[0] , ( ( kerstr )->yblock)[0] , ( ( kerstr )->zblock)[0] , ( ( kerstr )->num_ele)[0] , ( ( kerstr )->DT)[0] , yid , scmc_internal_g_ylen ); }}} return 0 ;} int openmp_Yee_FDTD_Div_FWD_scmc_set_parameter_outEB (openmp_Yee_FDTD_Div_FWD_struct * kerstr ,openmp_pscmc_mem * pm ){ ( ( kerstr )->outEB = pm->d_data); } int openmp_Yee_FDTD_Div_FWD_scmc_set_parameter_inEB (openmp_Yee_FDTD_Div_FWD_struct * kerstr ,openmp_pscmc_mem * pm ){ ( ( kerstr )->inEB = pm->d_data); } int openmp_Yee_FDTD_Div_FWD_scmc_set_parameter_y_cpu_core (openmp_Yee_FDTD_Div_FWD_struct * kerstr ,openmp_pscmc_mem * pm ){ ( ( kerstr )->y_cpu_core = pm->d_data); } int openmp_Yee_FDTD_Div_FWD_scmc_set_parameter_numvec (openmp_Yee_FDTD_Div_FWD_struct * kerstr ,openmp_pscmc_mem * pm ){ ( ( kerstr )->numvec = pm->d_data); } int openmp_Yee_FDTD_Div_FWD_scmc_set_parameter_XLEN (openmp_Yee_FDTD_Div_FWD_struct * kerstr ,openmp_pscmc_mem * pm ){ ( ( kerstr )->XLEN = pm->d_data); } int openmp_Yee_FDTD_Div_FWD_scmc_set_parameter_YLEN (openmp_Yee_FDTD_Div_FWD_struct * kerstr ,openmp_pscmc_mem * pm ){ ( ( kerstr )->YLEN = pm->d_data); } int openmp_Yee_FDTD_Div_FWD_scmc_set_parameter_ZLEN (openmp_Yee_FDTD_Div_FWD_struct * kerstr ,openmp_pscmc_mem * pm ){ ( ( kerstr )->ZLEN = pm->d_data); } int openmp_Yee_FDTD_Div_FWD_scmc_set_parameter_ovlp (openmp_Yee_FDTD_Div_FWD_struct * kerstr ,openmp_pscmc_mem * pm ){ ( ( kerstr )->ovlp = pm->d_data); } int openmp_Yee_FDTD_Div_FWD_scmc_set_parameter_xblock (openmp_Yee_FDTD_Div_FWD_struct * kerstr ,openmp_pscmc_mem * pm ){ ( ( kerstr )->xblock = pm->d_data); } int openmp_Yee_FDTD_Div_FWD_scmc_set_parameter_yblock (openmp_Yee_FDTD_Div_FWD_struct * kerstr ,openmp_pscmc_mem * pm ){ ( ( kerstr )->yblock = pm->d_data); } int openmp_Yee_FDTD_Div_FWD_scmc_set_parameter_zblock (openmp_Yee_FDTD_Div_FWD_struct * kerstr ,openmp_pscmc_mem * pm ){ ( ( kerstr )->zblock = pm->d_data); } int openmp_Yee_FDTD_Div_FWD_scmc_set_parameter_num_ele (openmp_Yee_FDTD_Div_FWD_struct * kerstr ,openmp_pscmc_mem * pm ){ ( ( kerstr )->num_ele = pm->d_data); } int openmp_Yee_FDTD_Div_FWD_scmc_set_parameter_DT (openmp_Yee_FDTD_Div_FWD_struct * kerstr ,openmp_pscmc_mem * pm ){ ( ( kerstr )->DT = pm->d_data); } int openmp_Yee_FDTD_Div_BWD_4th_init (openmp_pscmc_env * pe ,openmp_Yee_FDTD_Div_BWD_4th_struct * kerstr ){ return 0 ;} void openmp_Yee_FDTD_Div_BWD_4th_get_struct_len (size_t * len ){ ((len)[0] = sizeof(openmp_Yee_FDTD_Div_BWD_4th_struct )); } int openmp_Yee_FDTD_Div_BWD_4th_get_num_compute_units (openmp_Yee_FDTD_Div_BWD_4th_struct * kerstr ){ return omp_get_max_threads ( ) ;} int openmp_Yee_FDTD_Div_BWD_4th_get_xlen (){ return IDX_OPT_MAX ;} int openmp_Yee_FDTD_Div_BWD_4th_exec (openmp_Yee_FDTD_Div_BWD_4th_struct * kerstr ,long scmc_internal_g_xlen ,long scmc_internal_g_ylen ){ #pragma omp parallel { int xid ; int yid ; int numt = omp_get_num_threads ( ) ; int tid = omp_get_thread_num ( ) ; int ysingle = ( ( scmc_internal_g_ylen + ( numt - 1 ) ) / numt ) ; int ymin = ( tid * ysingle ) ; int ymax = ( ( 1 + tid ) * ysingle ) ; for ((yid = tid) ; ( yid < scmc_internal_g_ylen ) ; (yid = ( yid + numt ))) { for ((xid = 0) ; ( xid < scmc_internal_g_xlen ) ; (xid = ( xid + 1 ))) { openmp_Yee_FDTD_Div_BWD_4th_scmc_kernel ( ( kerstr )->outEB , ( kerstr )->inEB , ( ( kerstr )->y_cpu_core)[0] , ( ( kerstr )->numvec)[0] , ( ( kerstr )->XLEN)[0] , ( ( kerstr )->YLEN)[0] , ( ( kerstr )->ZLEN)[0] , ( ( kerstr )->ovlp)[0] , ( ( kerstr )->xblock)[0] , ( ( kerstr )->yblock)[0] , ( ( kerstr )->zblock)[0] , ( ( kerstr )->num_ele)[0] , ( ( kerstr )->DT)[0] , yid , scmc_internal_g_ylen ); }}} return 0 ;} int openmp_Yee_FDTD_Div_BWD_4th_scmc_set_parameter_outEB (openmp_Yee_FDTD_Div_BWD_4th_struct * kerstr ,openmp_pscmc_mem * pm ){ ( ( kerstr )->outEB = pm->d_data); } int openmp_Yee_FDTD_Div_BWD_4th_scmc_set_parameter_inEB (openmp_Yee_FDTD_Div_BWD_4th_struct * kerstr ,openmp_pscmc_mem * pm ){ ( ( kerstr )->inEB = pm->d_data); } int openmp_Yee_FDTD_Div_BWD_4th_scmc_set_parameter_y_cpu_core (openmp_Yee_FDTD_Div_BWD_4th_struct * kerstr ,openmp_pscmc_mem * pm ){ ( ( kerstr )->y_cpu_core = pm->d_data); } int openmp_Yee_FDTD_Div_BWD_4th_scmc_set_parameter_numvec (openmp_Yee_FDTD_Div_BWD_4th_struct * kerstr ,openmp_pscmc_mem * pm ){ ( ( kerstr )->numvec = pm->d_data); } int openmp_Yee_FDTD_Div_BWD_4th_scmc_set_parameter_XLEN (openmp_Yee_FDTD_Div_BWD_4th_struct * kerstr ,openmp_pscmc_mem * pm ){ ( ( kerstr )->XLEN = pm->d_data); } int openmp_Yee_FDTD_Div_BWD_4th_scmc_set_parameter_YLEN (openmp_Yee_FDTD_Div_BWD_4th_struct * kerstr ,openmp_pscmc_mem * pm ){ ( ( kerstr )->YLEN = pm->d_data); } int openmp_Yee_FDTD_Div_BWD_4th_scmc_set_parameter_ZLEN (openmp_Yee_FDTD_Div_BWD_4th_struct * kerstr ,openmp_pscmc_mem * pm ){ ( ( kerstr )->ZLEN = pm->d_data); } int openmp_Yee_FDTD_Div_BWD_4th_scmc_set_parameter_ovlp (openmp_Yee_FDTD_Div_BWD_4th_struct * kerstr ,openmp_pscmc_mem * pm ){ ( ( kerstr )->ovlp = pm->d_data); } int openmp_Yee_FDTD_Div_BWD_4th_scmc_set_parameter_xblock (openmp_Yee_FDTD_Div_BWD_4th_struct * kerstr ,openmp_pscmc_mem * pm ){ ( ( kerstr )->xblock = pm->d_data); } int openmp_Yee_FDTD_Div_BWD_4th_scmc_set_parameter_yblock (openmp_Yee_FDTD_Div_BWD_4th_struct * kerstr ,openmp_pscmc_mem * pm ){ ( ( kerstr )->yblock = pm->d_data); } int openmp_Yee_FDTD_Div_BWD_4th_scmc_set_parameter_zblock (openmp_Yee_FDTD_Div_BWD_4th_struct * kerstr ,openmp_pscmc_mem * pm ){ ( ( kerstr )->zblock = pm->d_data); } int openmp_Yee_FDTD_Div_BWD_4th_scmc_set_parameter_num_ele (openmp_Yee_FDTD_Div_BWD_4th_struct * kerstr ,openmp_pscmc_mem * pm ){ ( ( kerstr )->num_ele = pm->d_data); } int openmp_Yee_FDTD_Div_BWD_4th_scmc_set_parameter_DT (openmp_Yee_FDTD_Div_BWD_4th_struct * kerstr ,openmp_pscmc_mem * pm ){ ( ( kerstr )->DT = pm->d_data); } int openmp_Yee_FDTD_Div_BWD_init (openmp_pscmc_env * pe ,openmp_Yee_FDTD_Div_BWD_struct * kerstr ){ return 0 ;} void openmp_Yee_FDTD_Div_BWD_get_struct_len (size_t * len ){ ((len)[0] = sizeof(openmp_Yee_FDTD_Div_BWD_struct )); } int openmp_Yee_FDTD_Div_BWD_get_num_compute_units (openmp_Yee_FDTD_Div_BWD_struct * kerstr ){ return omp_get_max_threads ( ) ;} int openmp_Yee_FDTD_Div_BWD_get_xlen (){ return IDX_OPT_MAX ;} int openmp_Yee_FDTD_Div_BWD_exec (openmp_Yee_FDTD_Div_BWD_struct * kerstr ,long scmc_internal_g_xlen ,long scmc_internal_g_ylen ){ #pragma omp parallel { int xid ; int yid ; int numt = omp_get_num_threads ( ) ; int tid = omp_get_thread_num ( ) ; int ysingle = ( ( scmc_internal_g_ylen + ( numt - 1 ) ) / numt ) ; int ymin = ( tid * ysingle ) ; int ymax = ( ( 1 + tid ) * ysingle ) ; for ((yid = tid) ; ( yid < scmc_internal_g_ylen ) ; (yid = ( yid + numt ))) { for ((xid = 0) ; ( xid < scmc_internal_g_xlen ) ; (xid = ( xid + 1 ))) { openmp_Yee_FDTD_Div_BWD_scmc_kernel ( ( kerstr )->outEB , ( kerstr )->inEB , ( ( kerstr )->y_cpu_core)[0] , ( ( kerstr )->numvec)[0] , ( ( kerstr )->XLEN)[0] , ( ( kerstr )->YLEN)[0] , ( ( kerstr )->ZLEN)[0] , ( ( kerstr )->ovlp)[0] , ( ( kerstr )->xblock)[0] , ( ( kerstr )->yblock)[0] , ( ( kerstr )->zblock)[0] , ( ( kerstr )->num_ele)[0] , ( ( kerstr )->DT)[0] , yid , scmc_internal_g_ylen ); }}} return 0 ;} int openmp_Yee_FDTD_Div_BWD_scmc_set_parameter_outEB (openmp_Yee_FDTD_Div_BWD_struct * kerstr ,openmp_pscmc_mem * pm ){ ( ( kerstr )->outEB = pm->d_data); } int openmp_Yee_FDTD_Div_BWD_scmc_set_parameter_inEB (openmp_Yee_FDTD_Div_BWD_struct * kerstr ,openmp_pscmc_mem * pm ){ ( ( kerstr )->inEB = pm->d_data); } int openmp_Yee_FDTD_Div_BWD_scmc_set_parameter_y_cpu_core (openmp_Yee_FDTD_Div_BWD_struct * kerstr ,openmp_pscmc_mem * pm ){ ( ( kerstr )->y_cpu_core = pm->d_data); } int openmp_Yee_FDTD_Div_BWD_scmc_set_parameter_numvec (openmp_Yee_FDTD_Div_BWD_struct * kerstr ,openmp_pscmc_mem * pm ){ ( ( kerstr )->numvec = pm->d_data); } int openmp_Yee_FDTD_Div_BWD_scmc_set_parameter_XLEN (openmp_Yee_FDTD_Div_BWD_struct * kerstr ,openmp_pscmc_mem * pm ){ ( ( kerstr )->XLEN = pm->d_data); } int openmp_Yee_FDTD_Div_BWD_scmc_set_parameter_YLEN (openmp_Yee_FDTD_Div_BWD_struct * kerstr ,openmp_pscmc_mem * pm ){ ( ( kerstr )->YLEN = pm->d_data); } int openmp_Yee_FDTD_Div_BWD_scmc_set_parameter_ZLEN (openmp_Yee_FDTD_Div_BWD_struct * kerstr ,openmp_pscmc_mem * pm ){ ( ( kerstr )->ZLEN = pm->d_data); } int openmp_Yee_FDTD_Div_BWD_scmc_set_parameter_ovlp (openmp_Yee_FDTD_Div_BWD_struct * kerstr ,openmp_pscmc_mem * pm ){ ( ( kerstr )->ovlp = pm->d_data); } int openmp_Yee_FDTD_Div_BWD_scmc_set_parameter_xblock (openmp_Yee_FDTD_Div_BWD_struct * kerstr ,openmp_pscmc_mem * pm ){ ( ( kerstr )->xblock = pm->d_data); } int openmp_Yee_FDTD_Div_BWD_scmc_set_parameter_yblock (openmp_Yee_FDTD_Div_BWD_struct * kerstr ,openmp_pscmc_mem * pm ){ ( ( kerstr )->yblock = pm->d_data); } int openmp_Yee_FDTD_Div_BWD_scmc_set_parameter_zblock (openmp_Yee_FDTD_Div_BWD_struct * kerstr ,openmp_pscmc_mem * pm ){ ( ( kerstr )->zblock = pm->d_data); } int openmp_Yee_FDTD_Div_BWD_scmc_set_parameter_num_ele (openmp_Yee_FDTD_Div_BWD_struct * kerstr ,openmp_pscmc_mem * pm ){ ( ( kerstr )->num_ele = pm->d_data); } int openmp_Yee_FDTD_Div_BWD_scmc_set_parameter_DT (openmp_Yee_FDTD_Div_BWD_struct * kerstr ,openmp_pscmc_mem * pm ){ ( ( kerstr )->DT = pm->d_data); } int openmp_Yee_FDTD_Curl_FWD_4th_init (openmp_pscmc_env * pe ,openmp_Yee_FDTD_Curl_FWD_4th_struct * kerstr ){ return 0 ;} void openmp_Yee_FDTD_Curl_FWD_4th_get_struct_len (size_t * len ){ ((len)[0] = sizeof(openmp_Yee_FDTD_Curl_FWD_4th_struct )); } int openmp_Yee_FDTD_Curl_FWD_4th_get_num_compute_units (openmp_Yee_FDTD_Curl_FWD_4th_struct * kerstr ){ return omp_get_max_threads ( ) ;} int openmp_Yee_FDTD_Curl_FWD_4th_get_xlen (){ return IDX_OPT_MAX ;} int openmp_Yee_FDTD_Curl_FWD_4th_exec (openmp_Yee_FDTD_Curl_FWD_4th_struct * kerstr ,long scmc_internal_g_xlen ,long scmc_internal_g_ylen ){ #pragma omp parallel { int xid ; int yid ; int numt = omp_get_num_threads ( ) ; int tid = omp_get_thread_num ( ) ; int ysingle = ( ( scmc_internal_g_ylen + ( numt - 1 ) ) / numt ) ; int ymin = ( tid * ysingle ) ; int ymax = ( ( 1 + tid ) * ysingle ) ; for ((yid = tid) ; ( yid < scmc_internal_g_ylen ) ; (yid = ( yid + numt ))) { for ((xid = 0) ; ( xid < scmc_internal_g_xlen ) ; (xid = ( xid + 1 ))) { openmp_Yee_FDTD_Curl_FWD_4th_scmc_kernel ( ( kerstr )->outEB , ( kerstr )->inEB , ( ( kerstr )->y_cpu_core)[0] , ( ( kerstr )->numvec)[0] , ( ( kerstr )->XLEN)[0] , ( ( kerstr )->YLEN)[0] , ( ( kerstr )->ZLEN)[0] , ( ( kerstr )->ovlp)[0] , ( ( kerstr )->xblock)[0] , ( ( kerstr )->yblock)[0] , ( ( kerstr )->zblock)[0] , ( ( kerstr )->num_ele)[0] , ( ( kerstr )->DT)[0] , yid , scmc_internal_g_ylen ); }}} return 0 ;} int openmp_Yee_FDTD_Curl_FWD_4th_scmc_set_parameter_outEB (openmp_Yee_FDTD_Curl_FWD_4th_struct * kerstr ,openmp_pscmc_mem * pm ){ ( ( kerstr )->outEB = pm->d_data); } int openmp_Yee_FDTD_Curl_FWD_4th_scmc_set_parameter_inEB (openmp_Yee_FDTD_Curl_FWD_4th_struct * kerstr ,openmp_pscmc_mem * pm ){ ( ( kerstr )->inEB = pm->d_data); } int openmp_Yee_FDTD_Curl_FWD_4th_scmc_set_parameter_y_cpu_core (openmp_Yee_FDTD_Curl_FWD_4th_struct * kerstr ,openmp_pscmc_mem * pm ){ ( ( kerstr )->y_cpu_core = pm->d_data); } int openmp_Yee_FDTD_Curl_FWD_4th_scmc_set_parameter_numvec (openmp_Yee_FDTD_Curl_FWD_4th_struct * kerstr ,openmp_pscmc_mem * pm ){ ( ( kerstr )->numvec = pm->d_data); } int openmp_Yee_FDTD_Curl_FWD_4th_scmc_set_parameter_XLEN (openmp_Yee_FDTD_Curl_FWD_4th_struct * kerstr ,openmp_pscmc_mem * pm ){ ( ( kerstr )->XLEN = pm->d_data); } int openmp_Yee_FDTD_Curl_FWD_4th_scmc_set_parameter_YLEN (openmp_Yee_FDTD_Curl_FWD_4th_struct * kerstr ,openmp_pscmc_mem * pm ){ ( ( kerstr )->YLEN = pm->d_data); } int openmp_Yee_FDTD_Curl_FWD_4th_scmc_set_parameter_ZLEN (openmp_Yee_FDTD_Curl_FWD_4th_struct * kerstr ,openmp_pscmc_mem * pm ){ ( ( kerstr )->ZLEN = pm->d_data); } int openmp_Yee_FDTD_Curl_FWD_4th_scmc_set_parameter_ovlp (openmp_Yee_FDTD_Curl_FWD_4th_struct * kerstr ,openmp_pscmc_mem * pm ){ ( ( kerstr )->ovlp = pm->d_data); } int openmp_Yee_FDTD_Curl_FWD_4th_scmc_set_parameter_xblock (openmp_Yee_FDTD_Curl_FWD_4th_struct * kerstr ,openmp_pscmc_mem * pm ){ ( ( kerstr )->xblock = pm->d_data); } int openmp_Yee_FDTD_Curl_FWD_4th_scmc_set_parameter_yblock (openmp_Yee_FDTD_Curl_FWD_4th_struct * kerstr ,openmp_pscmc_mem * pm ){ ( ( kerstr )->yblock = pm->d_data); } int openmp_Yee_FDTD_Curl_FWD_4th_scmc_set_parameter_zblock (openmp_Yee_FDTD_Curl_FWD_4th_struct * kerstr ,openmp_pscmc_mem * pm ){ ( ( kerstr )->zblock = pm->d_data); } int openmp_Yee_FDTD_Curl_FWD_4th_scmc_set_parameter_num_ele (openmp_Yee_FDTD_Curl_FWD_4th_struct * kerstr ,openmp_pscmc_mem * pm ){ ( ( kerstr )->num_ele = pm->d_data); } int openmp_Yee_FDTD_Curl_FWD_4th_scmc_set_parameter_DT (openmp_Yee_FDTD_Curl_FWD_4th_struct * kerstr ,openmp_pscmc_mem * pm ){ ( ( kerstr )->DT = pm->d_data); } int openmp_Yee_FDTD_Curl_FWD_init (openmp_pscmc_env * pe ,openmp_Yee_FDTD_Curl_FWD_struct * kerstr ){ return 0 ;} void openmp_Yee_FDTD_Curl_FWD_get_struct_len (size_t * len ){ ((len)[0] = sizeof(openmp_Yee_FDTD_Curl_FWD_struct )); } int openmp_Yee_FDTD_Curl_FWD_get_num_compute_units (openmp_Yee_FDTD_Curl_FWD_struct * kerstr ){ return omp_get_max_threads ( ) ;} int openmp_Yee_FDTD_Curl_FWD_get_xlen (){ return IDX_OPT_MAX ;} int openmp_Yee_FDTD_Curl_FWD_exec (openmp_Yee_FDTD_Curl_FWD_struct * kerstr ,long scmc_internal_g_xlen ,long scmc_internal_g_ylen ){ #pragma omp parallel { int xid ; int yid ; int numt = omp_get_num_threads ( ) ; int tid = omp_get_thread_num ( ) ; int ysingle = ( ( scmc_internal_g_ylen + ( numt - 1 ) ) / numt ) ; int ymin = ( tid * ysingle ) ; int ymax = ( ( 1 + tid ) * ysingle ) ; for ((yid = tid) ; ( yid < scmc_internal_g_ylen ) ; (yid = ( yid + numt ))) { for ((xid = 0) ; ( xid < scmc_internal_g_xlen ) ; (xid = ( xid + 1 ))) { openmp_Yee_FDTD_Curl_FWD_scmc_kernel ( ( kerstr )->outEB , ( kerstr )->inEB , ( ( kerstr )->y_cpu_core)[0] , ( ( kerstr )->numvec)[0] , ( ( kerstr )->XLEN)[0] , ( ( kerstr )->YLEN)[0] , ( ( kerstr )->ZLEN)[0] , ( ( kerstr )->ovlp)[0] , ( ( kerstr )->xblock)[0] , ( ( kerstr )->yblock)[0] , ( ( kerstr )->zblock)[0] , ( ( kerstr )->num_ele)[0] , ( ( kerstr )->DT)[0] , yid , scmc_internal_g_ylen ); }}} return 0 ;} int openmp_Yee_FDTD_Curl_FWD_scmc_set_parameter_outEB (openmp_Yee_FDTD_Curl_FWD_struct * kerstr ,openmp_pscmc_mem * pm ){ ( ( kerstr )->outEB = pm->d_data); } int openmp_Yee_FDTD_Curl_FWD_scmc_set_parameter_inEB (openmp_Yee_FDTD_Curl_FWD_struct * kerstr ,openmp_pscmc_mem * pm ){ ( ( kerstr )->inEB = pm->d_data); } int openmp_Yee_FDTD_Curl_FWD_scmc_set_parameter_y_cpu_core (openmp_Yee_FDTD_Curl_FWD_struct * kerstr ,openmp_pscmc_mem * pm ){ ( ( kerstr )->y_cpu_core = pm->d_data); } int openmp_Yee_FDTD_Curl_FWD_scmc_set_parameter_numvec (openmp_Yee_FDTD_Curl_FWD_struct * kerstr ,openmp_pscmc_mem * pm ){ ( ( kerstr )->numvec = pm->d_data); } int openmp_Yee_FDTD_Curl_FWD_scmc_set_parameter_XLEN (openmp_Yee_FDTD_Curl_FWD_struct * kerstr ,openmp_pscmc_mem * pm ){ ( ( kerstr )->XLEN = pm->d_data); } int openmp_Yee_FDTD_Curl_FWD_scmc_set_parameter_YLEN (openmp_Yee_FDTD_Curl_FWD_struct * kerstr ,openmp_pscmc_mem * pm ){ ( ( kerstr )->YLEN = pm->d_data); } int openmp_Yee_FDTD_Curl_FWD_scmc_set_parameter_ZLEN (openmp_Yee_FDTD_Curl_FWD_struct * kerstr ,openmp_pscmc_mem * pm ){ ( ( kerstr )->ZLEN = pm->d_data); } int openmp_Yee_FDTD_Curl_FWD_scmc_set_parameter_ovlp (openmp_Yee_FDTD_Curl_FWD_struct * kerstr ,openmp_pscmc_mem * pm ){ ( ( kerstr )->ovlp = pm->d_data); } int openmp_Yee_FDTD_Curl_FWD_scmc_set_parameter_xblock (openmp_Yee_FDTD_Curl_FWD_struct * kerstr ,openmp_pscmc_mem * pm ){ ( ( kerstr )->xblock = pm->d_data); } int openmp_Yee_FDTD_Curl_FWD_scmc_set_parameter_yblock (openmp_Yee_FDTD_Curl_FWD_struct * kerstr ,openmp_pscmc_mem * pm ){ ( ( kerstr )->yblock = pm->d_data); } int openmp_Yee_FDTD_Curl_FWD_scmc_set_parameter_zblock (openmp_Yee_FDTD_Curl_FWD_struct * kerstr ,openmp_pscmc_mem * pm ){ ( ( kerstr )->zblock = pm->d_data); } int openmp_Yee_FDTD_Curl_FWD_scmc_set_parameter_num_ele (openmp_Yee_FDTD_Curl_FWD_struct * kerstr ,openmp_pscmc_mem * pm ){ ( ( kerstr )->num_ele = pm->d_data); } int openmp_Yee_FDTD_Curl_FWD_scmc_set_parameter_DT (openmp_Yee_FDTD_Curl_FWD_struct * kerstr ,openmp_pscmc_mem * pm ){ ( ( kerstr )->DT = pm->d_data); } int openmp_Yee_FDTD_Curl_BWD_4th_init (openmp_pscmc_env * pe ,openmp_Yee_FDTD_Curl_BWD_4th_struct * kerstr ){ return 0 ;} void openmp_Yee_FDTD_Curl_BWD_4th_get_struct_len (size_t * len ){ ((len)[0] = sizeof(openmp_Yee_FDTD_Curl_BWD_4th_struct )); } int openmp_Yee_FDTD_Curl_BWD_4th_get_num_compute_units (openmp_Yee_FDTD_Curl_BWD_4th_struct * kerstr ){ return omp_get_max_threads ( ) ;} int openmp_Yee_FDTD_Curl_BWD_4th_get_xlen (){ return IDX_OPT_MAX ;} int openmp_Yee_FDTD_Curl_BWD_4th_exec (openmp_Yee_FDTD_Curl_BWD_4th_struct * kerstr ,long scmc_internal_g_xlen ,long scmc_internal_g_ylen ){ #pragma omp parallel { int xid ; int yid ; int numt = omp_get_num_threads ( ) ; int tid = omp_get_thread_num ( ) ; int ysingle = ( ( scmc_internal_g_ylen + ( numt - 1 ) ) / numt ) ; int ymin = ( tid * ysingle ) ; int ymax = ( ( 1 + tid ) * ysingle ) ; for ((yid = tid) ; ( yid < scmc_internal_g_ylen ) ; (yid = ( yid + numt ))) { for ((xid = 0) ; ( xid < scmc_internal_g_xlen ) ; (xid = ( xid + 1 ))) { openmp_Yee_FDTD_Curl_BWD_4th_scmc_kernel ( ( kerstr )->outEB , ( kerstr )->inEB , ( ( kerstr )->y_cpu_core)[0] , ( ( kerstr )->numvec)[0] , ( ( kerstr )->XLEN)[0] , ( ( kerstr )->YLEN)[0] , ( ( kerstr )->ZLEN)[0] , ( ( kerstr )->ovlp)[0] , ( ( kerstr )->xblock)[0] , ( ( kerstr )->yblock)[0] , ( ( kerstr )->zblock)[0] , ( ( kerstr )->num_ele)[0] , ( ( kerstr )->DT)[0] , yid , scmc_internal_g_ylen ); }}} return 0 ;} int openmp_Yee_FDTD_Curl_BWD_4th_scmc_set_parameter_outEB (openmp_Yee_FDTD_Curl_BWD_4th_struct * kerstr ,openmp_pscmc_mem * pm ){ ( ( kerstr )->outEB = pm->d_data); } int openmp_Yee_FDTD_Curl_BWD_4th_scmc_set_parameter_inEB (openmp_Yee_FDTD_Curl_BWD_4th_struct * kerstr ,openmp_pscmc_mem * pm ){ ( ( kerstr )->inEB = pm->d_data); } int openmp_Yee_FDTD_Curl_BWD_4th_scmc_set_parameter_y_cpu_core (openmp_Yee_FDTD_Curl_BWD_4th_struct * kerstr ,openmp_pscmc_mem * pm ){ ( ( kerstr )->y_cpu_core = pm->d_data); } int openmp_Yee_FDTD_Curl_BWD_4th_scmc_set_parameter_numvec (openmp_Yee_FDTD_Curl_BWD_4th_struct * kerstr ,openmp_pscmc_mem * pm ){ ( ( kerstr )->numvec = pm->d_data); } int openmp_Yee_FDTD_Curl_BWD_4th_scmc_set_parameter_XLEN (openmp_Yee_FDTD_Curl_BWD_4th_struct * kerstr ,openmp_pscmc_mem * pm ){ ( ( kerstr )->XLEN = pm->d_data); } int openmp_Yee_FDTD_Curl_BWD_4th_scmc_set_parameter_YLEN (openmp_Yee_FDTD_Curl_BWD_4th_struct * kerstr ,openmp_pscmc_mem * pm ){ ( ( kerstr )->YLEN = pm->d_data); } int openmp_Yee_FDTD_Curl_BWD_4th_scmc_set_parameter_ZLEN (openmp_Yee_FDTD_Curl_BWD_4th_struct * kerstr ,openmp_pscmc_mem * pm ){ ( ( kerstr )->ZLEN = pm->d_data); } int openmp_Yee_FDTD_Curl_BWD_4th_scmc_set_parameter_ovlp (openmp_Yee_FDTD_Curl_BWD_4th_struct * kerstr ,openmp_pscmc_mem * pm ){ ( ( kerstr )->ovlp = pm->d_data); } int openmp_Yee_FDTD_Curl_BWD_4th_scmc_set_parameter_xblock (openmp_Yee_FDTD_Curl_BWD_4th_struct * kerstr ,openmp_pscmc_mem * pm ){ ( ( kerstr )->xblock = pm->d_data); } int openmp_Yee_FDTD_Curl_BWD_4th_scmc_set_parameter_yblock (openmp_Yee_FDTD_Curl_BWD_4th_struct * kerstr ,openmp_pscmc_mem * pm ){ ( ( kerstr )->yblock = pm->d_data); } int openmp_Yee_FDTD_Curl_BWD_4th_scmc_set_parameter_zblock (openmp_Yee_FDTD_Curl_BWD_4th_struct * kerstr ,openmp_pscmc_mem * pm ){ ( ( kerstr )->zblock = pm->d_data); } int openmp_Yee_FDTD_Curl_BWD_4th_scmc_set_parameter_num_ele (openmp_Yee_FDTD_Curl_BWD_4th_struct * kerstr ,openmp_pscmc_mem * pm ){ ( ( kerstr )->num_ele = pm->d_data); } int openmp_Yee_FDTD_Curl_BWD_4th_scmc_set_parameter_DT (openmp_Yee_FDTD_Curl_BWD_4th_struct * kerstr ,openmp_pscmc_mem * pm ){ ( ( kerstr )->DT = pm->d_data); } int openmp_Yee_FDTD_Curl_BWD_init (openmp_pscmc_env * pe ,openmp_Yee_FDTD_Curl_BWD_struct * kerstr ){ return 0 ;} void openmp_Yee_FDTD_Curl_BWD_get_struct_len (size_t * len ){ ((len)[0] = sizeof(openmp_Yee_FDTD_Curl_BWD_struct )); } int openmp_Yee_FDTD_Curl_BWD_get_num_compute_units (openmp_Yee_FDTD_Curl_BWD_struct * kerstr ){ return omp_get_max_threads ( ) ;} int openmp_Yee_FDTD_Curl_BWD_get_xlen (){ return IDX_OPT_MAX ;} int openmp_Yee_FDTD_Curl_BWD_exec (openmp_Yee_FDTD_Curl_BWD_struct * kerstr ,long scmc_internal_g_xlen ,long scmc_internal_g_ylen ){ #pragma omp parallel { int xid ; int yid ; int numt = omp_get_num_threads ( ) ; int tid = omp_get_thread_num ( ) ; int ysingle = ( ( scmc_internal_g_ylen + ( numt - 1 ) ) / numt ) ; int ymin = ( tid * ysingle ) ; int ymax = ( ( 1 + tid ) * ysingle ) ; for ((yid = tid) ; ( yid < scmc_internal_g_ylen ) ; (yid = ( yid + numt ))) { for ((xid = 0) ; ( xid < scmc_internal_g_xlen ) ; (xid = ( xid + 1 ))) { openmp_Yee_FDTD_Curl_BWD_scmc_kernel ( ( kerstr )->outEB , ( kerstr )->inEB , ( ( kerstr )->y_cpu_core)[0] , ( ( kerstr )->numvec)[0] , ( ( kerstr )->XLEN)[0] , ( ( kerstr )->YLEN)[0] , ( ( kerstr )->ZLEN)[0] , ( ( kerstr )->ovlp)[0] , ( ( kerstr )->xblock)[0] , ( ( kerstr )->yblock)[0] , ( ( kerstr )->zblock)[0] , ( ( kerstr )->num_ele)[0] , ( ( kerstr )->DT)[0] , yid , scmc_internal_g_ylen ); }}} return 0 ;} int openmp_Yee_FDTD_Curl_BWD_scmc_set_parameter_outEB (openmp_Yee_FDTD_Curl_BWD_struct * kerstr ,openmp_pscmc_mem * pm ){ ( ( kerstr )->outEB = pm->d_data); } int openmp_Yee_FDTD_Curl_BWD_scmc_set_parameter_inEB (openmp_Yee_FDTD_Curl_BWD_struct * kerstr ,openmp_pscmc_mem * pm ){ ( ( kerstr )->inEB = pm->d_data); } int openmp_Yee_FDTD_Curl_BWD_scmc_set_parameter_y_cpu_core (openmp_Yee_FDTD_Curl_BWD_struct * kerstr ,openmp_pscmc_mem * pm ){ ( ( kerstr )->y_cpu_core = pm->d_data); } int openmp_Yee_FDTD_Curl_BWD_scmc_set_parameter_numvec (openmp_Yee_FDTD_Curl_BWD_struct * kerstr ,openmp_pscmc_mem * pm ){ ( ( kerstr )->numvec = pm->d_data); } int openmp_Yee_FDTD_Curl_BWD_scmc_set_parameter_XLEN (openmp_Yee_FDTD_Curl_BWD_struct * kerstr ,openmp_pscmc_mem * pm ){ ( ( kerstr )->XLEN = pm->d_data); } int openmp_Yee_FDTD_Curl_BWD_scmc_set_parameter_YLEN (openmp_Yee_FDTD_Curl_BWD_struct * kerstr ,openmp_pscmc_mem * pm ){ ( ( kerstr )->YLEN = pm->d_data); } int openmp_Yee_FDTD_Curl_BWD_scmc_set_parameter_ZLEN (openmp_Yee_FDTD_Curl_BWD_struct * kerstr ,openmp_pscmc_mem * pm ){ ( ( kerstr )->ZLEN = pm->d_data); } int openmp_Yee_FDTD_Curl_BWD_scmc_set_parameter_ovlp (openmp_Yee_FDTD_Curl_BWD_struct * kerstr ,openmp_pscmc_mem * pm ){ ( ( kerstr )->ovlp = pm->d_data); } int openmp_Yee_FDTD_Curl_BWD_scmc_set_parameter_xblock (openmp_Yee_FDTD_Curl_BWD_struct * kerstr ,openmp_pscmc_mem * pm ){ ( ( kerstr )->xblock = pm->d_data); } int openmp_Yee_FDTD_Curl_BWD_scmc_set_parameter_yblock (openmp_Yee_FDTD_Curl_BWD_struct * kerstr ,openmp_pscmc_mem * pm ){ ( ( kerstr )->yblock = pm->d_data); } int openmp_Yee_FDTD_Curl_BWD_scmc_set_parameter_zblock (openmp_Yee_FDTD_Curl_BWD_struct * kerstr ,openmp_pscmc_mem * pm ){ ( ( kerstr )->zblock = pm->d_data); } int openmp_Yee_FDTD_Curl_BWD_scmc_set_parameter_num_ele (openmp_Yee_FDTD_Curl_BWD_struct * kerstr ,openmp_pscmc_mem * pm ){ ( ( kerstr )->num_ele = pm->d_data); } int openmp_Yee_FDTD_Curl_BWD_scmc_set_parameter_DT (openmp_Yee_FDTD_Curl_BWD_struct * kerstr ,openmp_pscmc_mem * pm ){ ( ( kerstr )->DT = pm->d_data); } int openmp_Yee_FDTD_Grad_FWD_4th_init (openmp_pscmc_env * pe ,openmp_Yee_FDTD_Grad_FWD_4th_struct * kerstr ){ return 0 ;} void openmp_Yee_FDTD_Grad_FWD_4th_get_struct_len (size_t * len ){ ((len)[0] = sizeof(openmp_Yee_FDTD_Grad_FWD_4th_struct )); } int openmp_Yee_FDTD_Grad_FWD_4th_get_num_compute_units (openmp_Yee_FDTD_Grad_FWD_4th_struct * kerstr ){ return omp_get_max_threads ( ) ;} int openmp_Yee_FDTD_Grad_FWD_4th_get_xlen (){ return IDX_OPT_MAX ;} int openmp_Yee_FDTD_Grad_FWD_4th_exec (openmp_Yee_FDTD_Grad_FWD_4th_struct * kerstr ,long scmc_internal_g_xlen ,long scmc_internal_g_ylen ){ #pragma omp parallel { int xid ; int yid ; int numt = omp_get_num_threads ( ) ; int tid = omp_get_thread_num ( ) ; int ysingle = ( ( scmc_internal_g_ylen + ( numt - 1 ) ) / numt ) ; int ymin = ( tid * ysingle ) ; int ymax = ( ( 1 + tid ) * ysingle ) ; for ((yid = tid) ; ( yid < scmc_internal_g_ylen ) ; (yid = ( yid + numt ))) { for ((xid = 0) ; ( xid < scmc_internal_g_xlen ) ; (xid = ( xid + 1 ))) { openmp_Yee_FDTD_Grad_FWD_4th_scmc_kernel ( ( kerstr )->outEB , ( kerstr )->inEB , ( ( kerstr )->y_cpu_core)[0] , ( ( kerstr )->numvec)[0] , ( ( kerstr )->XLEN)[0] , ( ( kerstr )->YLEN)[0] , ( ( kerstr )->ZLEN)[0] , ( ( kerstr )->ovlp)[0] , ( ( kerstr )->xblock)[0] , ( ( kerstr )->yblock)[0] , ( ( kerstr )->zblock)[0] , ( ( kerstr )->num_ele)[0] , ( ( kerstr )->DT)[0] , yid , scmc_internal_g_ylen ); }}} return 0 ;} int openmp_Yee_FDTD_Grad_FWD_4th_scmc_set_parameter_outEB (openmp_Yee_FDTD_Grad_FWD_4th_struct * kerstr ,openmp_pscmc_mem * pm ){ ( ( kerstr )->outEB = pm->d_data); } int openmp_Yee_FDTD_Grad_FWD_4th_scmc_set_parameter_inEB (openmp_Yee_FDTD_Grad_FWD_4th_struct * kerstr ,openmp_pscmc_mem * pm ){ ( ( kerstr )->inEB = pm->d_data); } int openmp_Yee_FDTD_Grad_FWD_4th_scmc_set_parameter_y_cpu_core (openmp_Yee_FDTD_Grad_FWD_4th_struct * kerstr ,openmp_pscmc_mem * pm ){ ( ( kerstr )->y_cpu_core = pm->d_data); } int openmp_Yee_FDTD_Grad_FWD_4th_scmc_set_parameter_numvec (openmp_Yee_FDTD_Grad_FWD_4th_struct * kerstr ,openmp_pscmc_mem * pm ){ ( ( kerstr )->numvec = pm->d_data); } int openmp_Yee_FDTD_Grad_FWD_4th_scmc_set_parameter_XLEN (openmp_Yee_FDTD_Grad_FWD_4th_struct * kerstr ,openmp_pscmc_mem * pm ){ ( ( kerstr )->XLEN = pm->d_data); } int openmp_Yee_FDTD_Grad_FWD_4th_scmc_set_parameter_YLEN (openmp_Yee_FDTD_Grad_FWD_4th_struct * kerstr ,openmp_pscmc_mem * pm ){ ( ( kerstr )->YLEN = pm->d_data); } int openmp_Yee_FDTD_Grad_FWD_4th_scmc_set_parameter_ZLEN (openmp_Yee_FDTD_Grad_FWD_4th_struct * kerstr ,openmp_pscmc_mem * pm ){ ( ( kerstr )->ZLEN = pm->d_data); } int openmp_Yee_FDTD_Grad_FWD_4th_scmc_set_parameter_ovlp (openmp_Yee_FDTD_Grad_FWD_4th_struct * kerstr ,openmp_pscmc_mem * pm ){ ( ( kerstr )->ovlp = pm->d_data); } int openmp_Yee_FDTD_Grad_FWD_4th_scmc_set_parameter_xblock (openmp_Yee_FDTD_Grad_FWD_4th_struct * kerstr ,openmp_pscmc_mem * pm ){ ( ( kerstr )->xblock = pm->d_data); } int openmp_Yee_FDTD_Grad_FWD_4th_scmc_set_parameter_yblock (openmp_Yee_FDTD_Grad_FWD_4th_struct * kerstr ,openmp_pscmc_mem * pm ){ ( ( kerstr )->yblock = pm->d_data); } int openmp_Yee_FDTD_Grad_FWD_4th_scmc_set_parameter_zblock (openmp_Yee_FDTD_Grad_FWD_4th_struct * kerstr ,openmp_pscmc_mem * pm ){ ( ( kerstr )->zblock = pm->d_data); } int openmp_Yee_FDTD_Grad_FWD_4th_scmc_set_parameter_num_ele (openmp_Yee_FDTD_Grad_FWD_4th_struct * kerstr ,openmp_pscmc_mem * pm ){ ( ( kerstr )->num_ele = pm->d_data); } int openmp_Yee_FDTD_Grad_FWD_4th_scmc_set_parameter_DT (openmp_Yee_FDTD_Grad_FWD_4th_struct * kerstr ,openmp_pscmc_mem * pm ){ ( ( kerstr )->DT = pm->d_data); } int openmp_Yee_FDTD_Grad_FWD_init (openmp_pscmc_env * pe ,openmp_Yee_FDTD_Grad_FWD_struct * kerstr ){ return 0 ;} void openmp_Yee_FDTD_Grad_FWD_get_struct_len (size_t * len ){ ((len)[0] = sizeof(openmp_Yee_FDTD_Grad_FWD_struct )); } int openmp_Yee_FDTD_Grad_FWD_get_num_compute_units (openmp_Yee_FDTD_Grad_FWD_struct * kerstr ){ return omp_get_max_threads ( ) ;} int openmp_Yee_FDTD_Grad_FWD_get_xlen (){ return IDX_OPT_MAX ;} int openmp_Yee_FDTD_Grad_FWD_exec (openmp_Yee_FDTD_Grad_FWD_struct * kerstr ,long scmc_internal_g_xlen ,long scmc_internal_g_ylen ){ #pragma omp parallel { int xid ; int yid ; int numt = omp_get_num_threads ( ) ; int tid = omp_get_thread_num ( ) ; int ysingle = ( ( scmc_internal_g_ylen + ( numt - 1 ) ) / numt ) ; int ymin = ( tid * ysingle ) ; int ymax = ( ( 1 + tid ) * ysingle ) ; for ((yid = tid) ; ( yid < scmc_internal_g_ylen ) ; (yid = ( yid + numt ))) { for ((xid = 0) ; ( xid < scmc_internal_g_xlen ) ; (xid = ( xid + 1 ))) { openmp_Yee_FDTD_Grad_FWD_scmc_kernel ( ( kerstr )->outEB , ( kerstr )->inEB , ( ( kerstr )->y_cpu_core)[0] , ( ( kerstr )->numvec)[0] , ( ( kerstr )->XLEN)[0] , ( ( kerstr )->YLEN)[0] , ( ( kerstr )->ZLEN)[0] , ( ( kerstr )->ovlp)[0] , ( ( kerstr )->xblock)[0] , ( ( kerstr )->yblock)[0] , ( ( kerstr )->zblock)[0] , ( ( kerstr )->num_ele)[0] , ( ( kerstr )->DT)[0] , yid , scmc_internal_g_ylen ); }}} return 0 ;} int openmp_Yee_FDTD_Grad_FWD_scmc_set_parameter_outEB (openmp_Yee_FDTD_Grad_FWD_struct * kerstr ,openmp_pscmc_mem * pm ){ ( ( kerstr )->outEB = pm->d_data); } int openmp_Yee_FDTD_Grad_FWD_scmc_set_parameter_inEB (openmp_Yee_FDTD_Grad_FWD_struct * kerstr ,openmp_pscmc_mem * pm ){ ( ( kerstr )->inEB = pm->d_data); } int openmp_Yee_FDTD_Grad_FWD_scmc_set_parameter_y_cpu_core (openmp_Yee_FDTD_Grad_FWD_struct * kerstr ,openmp_pscmc_mem * pm ){ ( ( kerstr )->y_cpu_core = pm->d_data); } int openmp_Yee_FDTD_Grad_FWD_scmc_set_parameter_numvec (openmp_Yee_FDTD_Grad_FWD_struct * kerstr ,openmp_pscmc_mem * pm ){ ( ( kerstr )->numvec = pm->d_data); } int openmp_Yee_FDTD_Grad_FWD_scmc_set_parameter_XLEN (openmp_Yee_FDTD_Grad_FWD_struct * kerstr ,openmp_pscmc_mem * pm ){ ( ( kerstr )->XLEN = pm->d_data); } int openmp_Yee_FDTD_Grad_FWD_scmc_set_parameter_YLEN (openmp_Yee_FDTD_Grad_FWD_struct * kerstr ,openmp_pscmc_mem * pm ){ ( ( kerstr )->YLEN = pm->d_data); } int openmp_Yee_FDTD_Grad_FWD_scmc_set_parameter_ZLEN (openmp_Yee_FDTD_Grad_FWD_struct * kerstr ,openmp_pscmc_mem * pm ){ ( ( kerstr )->ZLEN = pm->d_data); } int openmp_Yee_FDTD_Grad_FWD_scmc_set_parameter_ovlp (openmp_Yee_FDTD_Grad_FWD_struct * kerstr ,openmp_pscmc_mem * pm ){ ( ( kerstr )->ovlp = pm->d_data); } int openmp_Yee_FDTD_Grad_FWD_scmc_set_parameter_xblock (openmp_Yee_FDTD_Grad_FWD_struct * kerstr ,openmp_pscmc_mem * pm ){ ( ( kerstr )->xblock = pm->d_data); } int openmp_Yee_FDTD_Grad_FWD_scmc_set_parameter_yblock (openmp_Yee_FDTD_Grad_FWD_struct * kerstr ,openmp_pscmc_mem * pm ){ ( ( kerstr )->yblock = pm->d_data); } int openmp_Yee_FDTD_Grad_FWD_scmc_set_parameter_zblock (openmp_Yee_FDTD_Grad_FWD_struct * kerstr ,openmp_pscmc_mem * pm ){ ( ( kerstr )->zblock = pm->d_data); } int openmp_Yee_FDTD_Grad_FWD_scmc_set_parameter_num_ele (openmp_Yee_FDTD_Grad_FWD_struct * kerstr ,openmp_pscmc_mem * pm ){ ( ( kerstr )->num_ele = pm->d_data); } int openmp_Yee_FDTD_Grad_FWD_scmc_set_parameter_DT (openmp_Yee_FDTD_Grad_FWD_struct * kerstr ,openmp_pscmc_mem * pm ){ ( ( kerstr )->DT = pm->d_data); } int openmp_Yee_FDTD_Grad_BWD_4th_init (openmp_pscmc_env * pe ,openmp_Yee_FDTD_Grad_BWD_4th_struct * kerstr ){ return 0 ;} void openmp_Yee_FDTD_Grad_BWD_4th_get_struct_len (size_t * len ){ ((len)[0] = sizeof(openmp_Yee_FDTD_Grad_BWD_4th_struct )); } int openmp_Yee_FDTD_Grad_BWD_4th_get_num_compute_units (openmp_Yee_FDTD_Grad_BWD_4th_struct * kerstr ){ return omp_get_max_threads ( ) ;} int openmp_Yee_FDTD_Grad_BWD_4th_get_xlen (){ return IDX_OPT_MAX ;} int openmp_Yee_FDTD_Grad_BWD_4th_exec (openmp_Yee_FDTD_Grad_BWD_4th_struct * kerstr ,long scmc_internal_g_xlen ,long scmc_internal_g_ylen ){ #pragma omp parallel { int xid ; int yid ; int numt = omp_get_num_threads ( ) ; int tid = omp_get_thread_num ( ) ; int ysingle = ( ( scmc_internal_g_ylen + ( numt - 1 ) ) / numt ) ; int ymin = ( tid * ysingle ) ; int ymax = ( ( 1 + tid ) * ysingle ) ; for ((yid = tid) ; ( yid < scmc_internal_g_ylen ) ; (yid = ( yid + numt ))) { for ((xid = 0) ; ( xid < scmc_internal_g_xlen ) ; (xid = ( xid + 1 ))) { openmp_Yee_FDTD_Grad_BWD_4th_scmc_kernel ( ( kerstr )->outEB , ( kerstr )->inEB , ( ( kerstr )->y_cpu_core)[0] , ( ( kerstr )->numvec)[0] , ( ( kerstr )->XLEN)[0] , ( ( kerstr )->YLEN)[0] , ( ( kerstr )->ZLEN)[0] , ( ( kerstr )->ovlp)[0] , ( ( kerstr )->xblock)[0] , ( ( kerstr )->yblock)[0] , ( ( kerstr )->zblock)[0] , ( ( kerstr )->num_ele)[0] , ( ( kerstr )->DT)[0] , yid , scmc_internal_g_ylen ); }}} return 0 ;} int openmp_Yee_FDTD_Grad_BWD_4th_scmc_set_parameter_outEB (openmp_Yee_FDTD_Grad_BWD_4th_struct * kerstr ,openmp_pscmc_mem * pm ){ ( ( kerstr )->outEB = pm->d_data); } int openmp_Yee_FDTD_Grad_BWD_4th_scmc_set_parameter_inEB (openmp_Yee_FDTD_Grad_BWD_4th_struct * kerstr ,openmp_pscmc_mem * pm ){ ( ( kerstr )->inEB = pm->d_data); } int openmp_Yee_FDTD_Grad_BWD_4th_scmc_set_parameter_y_cpu_core (openmp_Yee_FDTD_Grad_BWD_4th_struct * kerstr ,openmp_pscmc_mem * pm ){ ( ( kerstr )->y_cpu_core = pm->d_data); } int openmp_Yee_FDTD_Grad_BWD_4th_scmc_set_parameter_numvec (openmp_Yee_FDTD_Grad_BWD_4th_struct * kerstr ,openmp_pscmc_mem * pm ){ ( ( kerstr )->numvec = pm->d_data); } int openmp_Yee_FDTD_Grad_BWD_4th_scmc_set_parameter_XLEN (openmp_Yee_FDTD_Grad_BWD_4th_struct * kerstr ,openmp_pscmc_mem * pm ){ ( ( kerstr )->XLEN = pm->d_data); } int openmp_Yee_FDTD_Grad_BWD_4th_scmc_set_parameter_YLEN (openmp_Yee_FDTD_Grad_BWD_4th_struct * kerstr ,openmp_pscmc_mem * pm ){ ( ( kerstr )->YLEN = pm->d_data); } int openmp_Yee_FDTD_Grad_BWD_4th_scmc_set_parameter_ZLEN (openmp_Yee_FDTD_Grad_BWD_4th_struct * kerstr ,openmp_pscmc_mem * pm ){ ( ( kerstr )->ZLEN = pm->d_data); } int openmp_Yee_FDTD_Grad_BWD_4th_scmc_set_parameter_ovlp (openmp_Yee_FDTD_Grad_BWD_4th_struct * kerstr ,openmp_pscmc_mem * pm ){ ( ( kerstr )->ovlp = pm->d_data); } int openmp_Yee_FDTD_Grad_BWD_4th_scmc_set_parameter_xblock (openmp_Yee_FDTD_Grad_BWD_4th_struct * kerstr ,openmp_pscmc_mem * pm ){ ( ( kerstr )->xblock = pm->d_data); } int openmp_Yee_FDTD_Grad_BWD_4th_scmc_set_parameter_yblock (openmp_Yee_FDTD_Grad_BWD_4th_struct * kerstr ,openmp_pscmc_mem * pm ){ ( ( kerstr )->yblock = pm->d_data); } int openmp_Yee_FDTD_Grad_BWD_4th_scmc_set_parameter_zblock (openmp_Yee_FDTD_Grad_BWD_4th_struct * kerstr ,openmp_pscmc_mem * pm ){ ( ( kerstr )->zblock = pm->d_data); } int openmp_Yee_FDTD_Grad_BWD_4th_scmc_set_parameter_num_ele (openmp_Yee_FDTD_Grad_BWD_4th_struct * kerstr ,openmp_pscmc_mem * pm ){ ( ( kerstr )->num_ele = pm->d_data); } int openmp_Yee_FDTD_Grad_BWD_4th_scmc_set_parameter_DT (openmp_Yee_FDTD_Grad_BWD_4th_struct * kerstr ,openmp_pscmc_mem * pm ){ ( ( kerstr )->DT = pm->d_data); } int openmp_Yee_FDTD_Grad_BWD_init (openmp_pscmc_env * pe ,openmp_Yee_FDTD_Grad_BWD_struct * kerstr ){ return 0 ;} void openmp_Yee_FDTD_Grad_BWD_get_struct_len (size_t * len ){ ((len)[0] = sizeof(openmp_Yee_FDTD_Grad_BWD_struct )); } int openmp_Yee_FDTD_Grad_BWD_get_num_compute_units (openmp_Yee_FDTD_Grad_BWD_struct * kerstr ){ return omp_get_max_threads ( ) ;} int openmp_Yee_FDTD_Grad_BWD_get_xlen (){ return IDX_OPT_MAX ;} int openmp_Yee_FDTD_Grad_BWD_exec (openmp_Yee_FDTD_Grad_BWD_struct * kerstr ,long scmc_internal_g_xlen ,long scmc_internal_g_ylen ){ #pragma omp parallel { int xid ; int yid ; int numt = omp_get_num_threads ( ) ; int tid = omp_get_thread_num ( ) ; int ysingle = ( ( scmc_internal_g_ylen + ( numt - 1 ) ) / numt ) ; int ymin = ( tid * ysingle ) ; int ymax = ( ( 1 + tid ) * ysingle ) ; for ((yid = tid) ; ( yid < scmc_internal_g_ylen ) ; (yid = ( yid + numt ))) { for ((xid = 0) ; ( xid < scmc_internal_g_xlen ) ; (xid = ( xid + 1 ))) { openmp_Yee_FDTD_Grad_BWD_scmc_kernel ( ( kerstr )->outEB , ( kerstr )->inEB , ( ( kerstr )->y_cpu_core)[0] , ( ( kerstr )->numvec)[0] , ( ( kerstr )->XLEN)[0] , ( ( kerstr )->YLEN)[0] , ( ( kerstr )->ZLEN)[0] , ( ( kerstr )->ovlp)[0] , ( ( kerstr )->xblock)[0] , ( ( kerstr )->yblock)[0] , ( ( kerstr )->zblock)[0] , ( ( kerstr )->num_ele)[0] , ( ( kerstr )->DT)[0] , yid , scmc_internal_g_ylen ); }}} return 0 ;} int openmp_Yee_FDTD_Grad_BWD_scmc_set_parameter_outEB (openmp_Yee_FDTD_Grad_BWD_struct * kerstr ,openmp_pscmc_mem * pm ){ ( ( kerstr )->outEB = pm->d_data); } int openmp_Yee_FDTD_Grad_BWD_scmc_set_parameter_inEB (openmp_Yee_FDTD_Grad_BWD_struct * kerstr ,openmp_pscmc_mem * pm ){ ( ( kerstr )->inEB = pm->d_data); } int openmp_Yee_FDTD_Grad_BWD_scmc_set_parameter_y_cpu_core (openmp_Yee_FDTD_Grad_BWD_struct * kerstr ,openmp_pscmc_mem * pm ){ ( ( kerstr )->y_cpu_core = pm->d_data); } int openmp_Yee_FDTD_Grad_BWD_scmc_set_parameter_numvec (openmp_Yee_FDTD_Grad_BWD_struct * kerstr ,openmp_pscmc_mem * pm ){ ( ( kerstr )->numvec = pm->d_data); } int openmp_Yee_FDTD_Grad_BWD_scmc_set_parameter_XLEN (openmp_Yee_FDTD_Grad_BWD_struct * kerstr ,openmp_pscmc_mem * pm ){ ( ( kerstr )->XLEN = pm->d_data); } int openmp_Yee_FDTD_Grad_BWD_scmc_set_parameter_YLEN (openmp_Yee_FDTD_Grad_BWD_struct * kerstr ,openmp_pscmc_mem * pm ){ ( ( kerstr )->YLEN = pm->d_data); } int openmp_Yee_FDTD_Grad_BWD_scmc_set_parameter_ZLEN (openmp_Yee_FDTD_Grad_BWD_struct * kerstr ,openmp_pscmc_mem * pm ){ ( ( kerstr )->ZLEN = pm->d_data); } int openmp_Yee_FDTD_Grad_BWD_scmc_set_parameter_ovlp (openmp_Yee_FDTD_Grad_BWD_struct * kerstr ,openmp_pscmc_mem * pm ){ ( ( kerstr )->ovlp = pm->d_data); } int openmp_Yee_FDTD_Grad_BWD_scmc_set_parameter_xblock (openmp_Yee_FDTD_Grad_BWD_struct * kerstr ,openmp_pscmc_mem * pm ){ ( ( kerstr )->xblock = pm->d_data); } int openmp_Yee_FDTD_Grad_BWD_scmc_set_parameter_yblock (openmp_Yee_FDTD_Grad_BWD_struct * kerstr ,openmp_pscmc_mem * pm ){ ( ( kerstr )->yblock = pm->d_data); } int openmp_Yee_FDTD_Grad_BWD_scmc_set_parameter_zblock (openmp_Yee_FDTD_Grad_BWD_struct * kerstr ,openmp_pscmc_mem * pm ){ ( ( kerstr )->zblock = pm->d_data); } int openmp_Yee_FDTD_Grad_BWD_scmc_set_parameter_num_ele (openmp_Yee_FDTD_Grad_BWD_struct * kerstr ,openmp_pscmc_mem * pm ){ ( ( kerstr )->num_ele = pm->d_data); } int openmp_Yee_FDTD_Grad_BWD_scmc_set_parameter_DT (openmp_Yee_FDTD_Grad_BWD_struct * kerstr ,openmp_pscmc_mem * pm ){ ( ( kerstr )->DT = pm->d_data); } int openmp_Yee_FDTD_Curl_B_4th_init (openmp_pscmc_env * pe ,openmp_Yee_FDTD_Curl_B_4th_struct * kerstr ){ return 0 ;} void openmp_Yee_FDTD_Curl_B_4th_get_struct_len (size_t * len ){ ((len)[0] = sizeof(openmp_Yee_FDTD_Curl_B_4th_struct )); } int openmp_Yee_FDTD_Curl_B_4th_get_num_compute_units (openmp_Yee_FDTD_Curl_B_4th_struct * kerstr ){ return omp_get_max_threads ( ) ;} int openmp_Yee_FDTD_Curl_B_4th_get_xlen (){ return IDX_OPT_MAX ;} int openmp_Yee_FDTD_Curl_B_4th_exec (openmp_Yee_FDTD_Curl_B_4th_struct * kerstr ,long scmc_internal_g_xlen ,long scmc_internal_g_ylen ){ #pragma omp parallel { int xid ; int yid ; int numt = omp_get_num_threads ( ) ; int tid = omp_get_thread_num ( ) ; int ysingle = ( ( scmc_internal_g_ylen + ( numt - 1 ) ) / numt ) ; int ymin = ( tid * ysingle ) ; int ymax = ( ( 1 + tid ) * ysingle ) ; for ((yid = tid) ; ( yid < scmc_internal_g_ylen ) ; (yid = ( yid + numt ))) { for ((xid = 0) ; ( xid < scmc_internal_g_xlen ) ; (xid = ( xid + 1 ))) { openmp_Yee_FDTD_Curl_B_4th_scmc_kernel ( ( kerstr )->outEB , ( kerstr )->inEB , ( ( kerstr )->y_cpu_core)[0] , ( ( kerstr )->numvec)[0] , ( ( kerstr )->XLEN)[0] , ( ( kerstr )->YLEN)[0] , ( ( kerstr )->ZLEN)[0] , ( ( kerstr )->ovlp)[0] , ( ( kerstr )->xblock)[0] , ( ( kerstr )->yblock)[0] , ( ( kerstr )->zblock)[0] , ( ( kerstr )->num_ele)[0] , ( ( kerstr )->DT)[0] , yid , scmc_internal_g_ylen ); }}} return 0 ;} int openmp_Yee_FDTD_Curl_B_4th_scmc_set_parameter_outEB (openmp_Yee_FDTD_Curl_B_4th_struct * kerstr ,openmp_pscmc_mem * pm ){ ( ( kerstr )->outEB = pm->d_data); } int openmp_Yee_FDTD_Curl_B_4th_scmc_set_parameter_inEB (openmp_Yee_FDTD_Curl_B_4th_struct * kerstr ,openmp_pscmc_mem * pm ){ ( ( kerstr )->inEB = pm->d_data); } int openmp_Yee_FDTD_Curl_B_4th_scmc_set_parameter_y_cpu_core (openmp_Yee_FDTD_Curl_B_4th_struct * kerstr ,openmp_pscmc_mem * pm ){ ( ( kerstr )->y_cpu_core = pm->d_data); } int openmp_Yee_FDTD_Curl_B_4th_scmc_set_parameter_numvec (openmp_Yee_FDTD_Curl_B_4th_struct * kerstr ,openmp_pscmc_mem * pm ){ ( ( kerstr )->numvec = pm->d_data); } int openmp_Yee_FDTD_Curl_B_4th_scmc_set_parameter_XLEN (openmp_Yee_FDTD_Curl_B_4th_struct * kerstr ,openmp_pscmc_mem * pm ){ ( ( kerstr )->XLEN = pm->d_data); } int openmp_Yee_FDTD_Curl_B_4th_scmc_set_parameter_YLEN (openmp_Yee_FDTD_Curl_B_4th_struct * kerstr ,openmp_pscmc_mem * pm ){ ( ( kerstr )->YLEN = pm->d_data); } int openmp_Yee_FDTD_Curl_B_4th_scmc_set_parameter_ZLEN (openmp_Yee_FDTD_Curl_B_4th_struct * kerstr ,openmp_pscmc_mem * pm ){ ( ( kerstr )->ZLEN = pm->d_data); } int openmp_Yee_FDTD_Curl_B_4th_scmc_set_parameter_ovlp (openmp_Yee_FDTD_Curl_B_4th_struct * kerstr ,openmp_pscmc_mem * pm ){ ( ( kerstr )->ovlp = pm->d_data); } int openmp_Yee_FDTD_Curl_B_4th_scmc_set_parameter_xblock (openmp_Yee_FDTD_Curl_B_4th_struct * kerstr ,openmp_pscmc_mem * pm ){ ( ( kerstr )->xblock = pm->d_data); } int openmp_Yee_FDTD_Curl_B_4th_scmc_set_parameter_yblock (openmp_Yee_FDTD_Curl_B_4th_struct * kerstr ,openmp_pscmc_mem * pm ){ ( ( kerstr )->yblock = pm->d_data); } int openmp_Yee_FDTD_Curl_B_4th_scmc_set_parameter_zblock (openmp_Yee_FDTD_Curl_B_4th_struct * kerstr ,openmp_pscmc_mem * pm ){ ( ( kerstr )->zblock = pm->d_data); } int openmp_Yee_FDTD_Curl_B_4th_scmc_set_parameter_num_ele (openmp_Yee_FDTD_Curl_B_4th_struct * kerstr ,openmp_pscmc_mem * pm ){ ( ( kerstr )->num_ele = pm->d_data); } int openmp_Yee_FDTD_Curl_B_4th_scmc_set_parameter_DT (openmp_Yee_FDTD_Curl_B_4th_struct * kerstr ,openmp_pscmc_mem * pm ){ ( ( kerstr )->DT = pm->d_data); } int openmp_Yee_FDTD_Curl_B_init (openmp_pscmc_env * pe ,openmp_Yee_FDTD_Curl_B_struct * kerstr ){ return 0 ;} void openmp_Yee_FDTD_Curl_B_get_struct_len (size_t * len ){ ((len)[0] = sizeof(openmp_Yee_FDTD_Curl_B_struct )); } int openmp_Yee_FDTD_Curl_B_get_num_compute_units (openmp_Yee_FDTD_Curl_B_struct * kerstr ){ return omp_get_max_threads ( ) ;} int openmp_Yee_FDTD_Curl_B_get_xlen (){ return IDX_OPT_MAX ;} int openmp_Yee_FDTD_Curl_B_exec (openmp_Yee_FDTD_Curl_B_struct * kerstr ,long scmc_internal_g_xlen ,long scmc_internal_g_ylen ){ #pragma omp parallel { int xid ; int yid ; int numt = omp_get_num_threads ( ) ; int tid = omp_get_thread_num ( ) ; int ysingle = ( ( scmc_internal_g_ylen + ( numt - 1 ) ) / numt ) ; int ymin = ( tid * ysingle ) ; int ymax = ( ( 1 + tid ) * ysingle ) ; for ((yid = tid) ; ( yid < scmc_internal_g_ylen ) ; (yid = ( yid + numt ))) { for ((xid = 0) ; ( xid < scmc_internal_g_xlen ) ; (xid = ( xid + 1 ))) { openmp_Yee_FDTD_Curl_B_scmc_kernel ( ( kerstr )->outEB , ( kerstr )->inEB , ( ( kerstr )->y_cpu_core)[0] , ( ( kerstr )->numvec)[0] , ( ( kerstr )->XLEN)[0] , ( ( kerstr )->YLEN)[0] , ( ( kerstr )->ZLEN)[0] , ( ( kerstr )->ovlp)[0] , ( ( kerstr )->xblock)[0] , ( ( kerstr )->yblock)[0] , ( ( kerstr )->zblock)[0] , ( ( kerstr )->num_ele)[0] , ( ( kerstr )->DT)[0] , yid , scmc_internal_g_ylen ); }}} return 0 ;} int openmp_Yee_FDTD_Curl_B_scmc_set_parameter_outEB (openmp_Yee_FDTD_Curl_B_struct * kerstr ,openmp_pscmc_mem * pm ){ ( ( kerstr )->outEB = pm->d_data); } int openmp_Yee_FDTD_Curl_B_scmc_set_parameter_inEB (openmp_Yee_FDTD_Curl_B_struct * kerstr ,openmp_pscmc_mem * pm ){ ( ( kerstr )->inEB = pm->d_data); } int openmp_Yee_FDTD_Curl_B_scmc_set_parameter_y_cpu_core (openmp_Yee_FDTD_Curl_B_struct * kerstr ,openmp_pscmc_mem * pm ){ ( ( kerstr )->y_cpu_core = pm->d_data); } int openmp_Yee_FDTD_Curl_B_scmc_set_parameter_numvec (openmp_Yee_FDTD_Curl_B_struct * kerstr ,openmp_pscmc_mem * pm ){ ( ( kerstr )->numvec = pm->d_data); } int openmp_Yee_FDTD_Curl_B_scmc_set_parameter_XLEN (openmp_Yee_FDTD_Curl_B_struct * kerstr ,openmp_pscmc_mem * pm ){ ( ( kerstr )->XLEN = pm->d_data); } int openmp_Yee_FDTD_Curl_B_scmc_set_parameter_YLEN (openmp_Yee_FDTD_Curl_B_struct * kerstr ,openmp_pscmc_mem * pm ){ ( ( kerstr )->YLEN = pm->d_data); } int openmp_Yee_FDTD_Curl_B_scmc_set_parameter_ZLEN (openmp_Yee_FDTD_Curl_B_struct * kerstr ,openmp_pscmc_mem * pm ){ ( ( kerstr )->ZLEN = pm->d_data); } int openmp_Yee_FDTD_Curl_B_scmc_set_parameter_ovlp (openmp_Yee_FDTD_Curl_B_struct * kerstr ,openmp_pscmc_mem * pm ){ ( ( kerstr )->ovlp = pm->d_data); } int openmp_Yee_FDTD_Curl_B_scmc_set_parameter_xblock (openmp_Yee_FDTD_Curl_B_struct * kerstr ,openmp_pscmc_mem * pm ){ ( ( kerstr )->xblock = pm->d_data); } int openmp_Yee_FDTD_Curl_B_scmc_set_parameter_yblock (openmp_Yee_FDTD_Curl_B_struct * kerstr ,openmp_pscmc_mem * pm ){ ( ( kerstr )->yblock = pm->d_data); } int openmp_Yee_FDTD_Curl_B_scmc_set_parameter_zblock (openmp_Yee_FDTD_Curl_B_struct * kerstr ,openmp_pscmc_mem * pm ){ ( ( kerstr )->zblock = pm->d_data); } int openmp_Yee_FDTD_Curl_B_scmc_set_parameter_num_ele (openmp_Yee_FDTD_Curl_B_struct * kerstr ,openmp_pscmc_mem * pm ){ ( ( kerstr )->num_ele = pm->d_data); } int openmp_Yee_FDTD_Curl_B_scmc_set_parameter_DT (openmp_Yee_FDTD_Curl_B_struct * kerstr ,openmp_pscmc_mem * pm ){ ( ( kerstr )->DT = pm->d_data); } int openmp_Yee_FDTD_Curl_E_4th_init (openmp_pscmc_env * pe ,openmp_Yee_FDTD_Curl_E_4th_struct * kerstr ){ return 0 ;} void openmp_Yee_FDTD_Curl_E_4th_get_struct_len (size_t * len ){ ((len)[0] = sizeof(openmp_Yee_FDTD_Curl_E_4th_struct )); } int openmp_Yee_FDTD_Curl_E_4th_get_num_compute_units (openmp_Yee_FDTD_Curl_E_4th_struct * kerstr ){ return omp_get_max_threads ( ) ;} int openmp_Yee_FDTD_Curl_E_4th_get_xlen (){ return IDX_OPT_MAX ;} int openmp_Yee_FDTD_Curl_E_4th_exec (openmp_Yee_FDTD_Curl_E_4th_struct * kerstr ,long scmc_internal_g_xlen ,long scmc_internal_g_ylen ){ #pragma omp parallel { int xid ; int yid ; int numt = omp_get_num_threads ( ) ; int tid = omp_get_thread_num ( ) ; int ysingle = ( ( scmc_internal_g_ylen + ( numt - 1 ) ) / numt ) ; int ymin = ( tid * ysingle ) ; int ymax = ( ( 1 + tid ) * ysingle ) ; for ((yid = tid) ; ( yid < scmc_internal_g_ylen ) ; (yid = ( yid + numt ))) { for ((xid = 0) ; ( xid < scmc_internal_g_xlen ) ; (xid = ( xid + 1 ))) { openmp_Yee_FDTD_Curl_E_4th_scmc_kernel ( ( kerstr )->outEB , ( kerstr )->inEB , ( ( kerstr )->y_cpu_core)[0] , ( ( kerstr )->numvec)[0] , ( ( kerstr )->XLEN)[0] , ( ( kerstr )->YLEN)[0] , ( ( kerstr )->ZLEN)[0] , ( ( kerstr )->ovlp)[0] , ( ( kerstr )->xblock)[0] , ( ( kerstr )->yblock)[0] , ( ( kerstr )->zblock)[0] , ( ( kerstr )->num_ele)[0] , ( ( kerstr )->DT)[0] , yid , scmc_internal_g_ylen ); }}} return 0 ;} int openmp_Yee_FDTD_Curl_E_4th_scmc_set_parameter_outEB (openmp_Yee_FDTD_Curl_E_4th_struct * kerstr ,openmp_pscmc_mem * pm ){ ( ( kerstr )->outEB = pm->d_data); } int openmp_Yee_FDTD_Curl_E_4th_scmc_set_parameter_inEB (openmp_Yee_FDTD_Curl_E_4th_struct * kerstr ,openmp_pscmc_mem * pm ){ ( ( kerstr )->inEB = pm->d_data); } int openmp_Yee_FDTD_Curl_E_4th_scmc_set_parameter_y_cpu_core (openmp_Yee_FDTD_Curl_E_4th_struct * kerstr ,openmp_pscmc_mem * pm ){ ( ( kerstr )->y_cpu_core = pm->d_data); } int openmp_Yee_FDTD_Curl_E_4th_scmc_set_parameter_numvec (openmp_Yee_FDTD_Curl_E_4th_struct * kerstr ,openmp_pscmc_mem * pm ){ ( ( kerstr )->numvec = pm->d_data); } int openmp_Yee_FDTD_Curl_E_4th_scmc_set_parameter_XLEN (openmp_Yee_FDTD_Curl_E_4th_struct * kerstr ,openmp_pscmc_mem * pm ){ ( ( kerstr )->XLEN = pm->d_data); } int openmp_Yee_FDTD_Curl_E_4th_scmc_set_parameter_YLEN (openmp_Yee_FDTD_Curl_E_4th_struct * kerstr ,openmp_pscmc_mem * pm ){ ( ( kerstr )->YLEN = pm->d_data); } int openmp_Yee_FDTD_Curl_E_4th_scmc_set_parameter_ZLEN (openmp_Yee_FDTD_Curl_E_4th_struct * kerstr ,openmp_pscmc_mem * pm ){ ( ( kerstr )->ZLEN = pm->d_data); } int openmp_Yee_FDTD_Curl_E_4th_scmc_set_parameter_ovlp (openmp_Yee_FDTD_Curl_E_4th_struct * kerstr ,openmp_pscmc_mem * pm ){ ( ( kerstr )->ovlp = pm->d_data); } int openmp_Yee_FDTD_Curl_E_4th_scmc_set_parameter_xblock (openmp_Yee_FDTD_Curl_E_4th_struct * kerstr ,openmp_pscmc_mem * pm ){ ( ( kerstr )->xblock = pm->d_data); } int openmp_Yee_FDTD_Curl_E_4th_scmc_set_parameter_yblock (openmp_Yee_FDTD_Curl_E_4th_struct * kerstr ,openmp_pscmc_mem * pm ){ ( ( kerstr )->yblock = pm->d_data); } int openmp_Yee_FDTD_Curl_E_4th_scmc_set_parameter_zblock (openmp_Yee_FDTD_Curl_E_4th_struct * kerstr ,openmp_pscmc_mem * pm ){ ( ( kerstr )->zblock = pm->d_data); } int openmp_Yee_FDTD_Curl_E_4th_scmc_set_parameter_num_ele (openmp_Yee_FDTD_Curl_E_4th_struct * kerstr ,openmp_pscmc_mem * pm ){ ( ( kerstr )->num_ele = pm->d_data); } int openmp_Yee_FDTD_Curl_E_4th_scmc_set_parameter_DT (openmp_Yee_FDTD_Curl_E_4th_struct * kerstr ,openmp_pscmc_mem * pm ){ ( ( kerstr )->DT = pm->d_data); } int openmp_Yee_FDTD_Curl_E_init (openmp_pscmc_env * pe ,openmp_Yee_FDTD_Curl_E_struct * kerstr ){ return 0 ;} void openmp_Yee_FDTD_Curl_E_get_struct_len (size_t * len ){ ((len)[0] = sizeof(openmp_Yee_FDTD_Curl_E_struct )); } int openmp_Yee_FDTD_Curl_E_get_num_compute_units (openmp_Yee_FDTD_Curl_E_struct * kerstr ){ return omp_get_max_threads ( ) ;} int openmp_Yee_FDTD_Curl_E_get_xlen (){ return IDX_OPT_MAX ;} int openmp_Yee_FDTD_Curl_E_exec (openmp_Yee_FDTD_Curl_E_struct * kerstr ,long scmc_internal_g_xlen ,long scmc_internal_g_ylen ){ #pragma omp parallel { int xid ; int yid ; int numt = omp_get_num_threads ( ) ; int tid = omp_get_thread_num ( ) ; int ysingle = ( ( scmc_internal_g_ylen + ( numt - 1 ) ) / numt ) ; int ymin = ( tid * ysingle ) ; int ymax = ( ( 1 + tid ) * ysingle ) ; for ((yid = tid) ; ( yid < scmc_internal_g_ylen ) ; (yid = ( yid + numt ))) { for ((xid = 0) ; ( xid < scmc_internal_g_xlen ) ; (xid = ( xid + 1 ))) { openmp_Yee_FDTD_Curl_E_scmc_kernel ( ( kerstr )->outEB , ( kerstr )->inEB , ( ( kerstr )->y_cpu_core)[0] , ( ( kerstr )->numvec)[0] , ( ( kerstr )->XLEN)[0] , ( ( kerstr )->YLEN)[0] , ( ( kerstr )->ZLEN)[0] , ( ( kerstr )->ovlp)[0] , ( ( kerstr )->xblock)[0] , ( ( kerstr )->yblock)[0] , ( ( kerstr )->zblock)[0] , ( ( kerstr )->num_ele)[0] , ( ( kerstr )->DT)[0] , yid , scmc_internal_g_ylen ); }}} return 0 ;} int openmp_Yee_FDTD_Curl_E_scmc_set_parameter_outEB (openmp_Yee_FDTD_Curl_E_struct * kerstr ,openmp_pscmc_mem * pm ){ ( ( kerstr )->outEB = pm->d_data); } int openmp_Yee_FDTD_Curl_E_scmc_set_parameter_inEB (openmp_Yee_FDTD_Curl_E_struct * kerstr ,openmp_pscmc_mem * pm ){ ( ( kerstr )->inEB = pm->d_data); } int openmp_Yee_FDTD_Curl_E_scmc_set_parameter_y_cpu_core (openmp_Yee_FDTD_Curl_E_struct * kerstr ,openmp_pscmc_mem * pm ){ ( ( kerstr )->y_cpu_core = pm->d_data); } int openmp_Yee_FDTD_Curl_E_scmc_set_parameter_numvec (openmp_Yee_FDTD_Curl_E_struct * kerstr ,openmp_pscmc_mem * pm ){ ( ( kerstr )->numvec = pm->d_data); } int openmp_Yee_FDTD_Curl_E_scmc_set_parameter_XLEN (openmp_Yee_FDTD_Curl_E_struct * kerstr ,openmp_pscmc_mem * pm ){ ( ( kerstr )->XLEN = pm->d_data); } int openmp_Yee_FDTD_Curl_E_scmc_set_parameter_YLEN (openmp_Yee_FDTD_Curl_E_struct * kerstr ,openmp_pscmc_mem * pm ){ ( ( kerstr )->YLEN = pm->d_data); } int openmp_Yee_FDTD_Curl_E_scmc_set_parameter_ZLEN (openmp_Yee_FDTD_Curl_E_struct * kerstr ,openmp_pscmc_mem * pm ){ ( ( kerstr )->ZLEN = pm->d_data); } int openmp_Yee_FDTD_Curl_E_scmc_set_parameter_ovlp (openmp_Yee_FDTD_Curl_E_struct * kerstr ,openmp_pscmc_mem * pm ){ ( ( kerstr )->ovlp = pm->d_data); } int openmp_Yee_FDTD_Curl_E_scmc_set_parameter_xblock (openmp_Yee_FDTD_Curl_E_struct * kerstr ,openmp_pscmc_mem * pm ){ ( ( kerstr )->xblock = pm->d_data); } int openmp_Yee_FDTD_Curl_E_scmc_set_parameter_yblock (openmp_Yee_FDTD_Curl_E_struct * kerstr ,openmp_pscmc_mem * pm ){ ( ( kerstr )->yblock = pm->d_data); } int openmp_Yee_FDTD_Curl_E_scmc_set_parameter_zblock (openmp_Yee_FDTD_Curl_E_struct * kerstr ,openmp_pscmc_mem * pm ){ ( ( kerstr )->zblock = pm->d_data); } int openmp_Yee_FDTD_Curl_E_scmc_set_parameter_num_ele (openmp_Yee_FDTD_Curl_E_struct * kerstr ,openmp_pscmc_mem * pm ){ ( ( kerstr )->num_ele = pm->d_data); } int openmp_Yee_FDTD_Curl_E_scmc_set_parameter_DT (openmp_Yee_FDTD_Curl_E_struct * kerstr ,openmp_pscmc_mem * pm ){ ( ( kerstr )->DT = pm->d_data); }
declare-variant-1.c
int foo (int, int, int *); int bar (int, int, int *); #pragma omp declare variant (foo) \ match (construct={parallel,for},\ device={isa(avx512f,avx512vl),kind(host,cpu)},\ implementation={vendor(score(0):gnu),unified_shared_memory},\ user={condition(score(0):0)}) #pragma omp declare variant (bar) \ match (device={arch(x86_64,powerpc64),isa(avx512f,popcntb)}, \ implementation={atomic_default_mem_order(seq_cst),made_up_selector("foo", 13, "bar")}, \ user={condition(3-3)}) int baz (int, int, int *); int qux (void) { int i = 3; return baz (1, 2, &i); } int quux (int); void corge (void) { int i; #pragma omp declare variant (quux) match (construct={parallel,for}) extern int waldo (int); waldo (5); #pragma omp parallel for for (i = 0; i < 3; i++) waldo (6); #pragma omp parallel #pragma omp taskgroup #pragma omp for for (i = 0; i < 3; i++) waldo (7); #pragma omp parallel #pragma omp master waldo (8); } #pragma omp declare variant (bar) match \ (implementation={atomic_default_mem_order(relaxed), \ unified_address, unified_shared_memory, \ dynamic_allocators, reverse_offload}) int baz2 (int x, int y, int *z) { return x + y + *z; } #pragma omp declare variant (bar) match \ (implementation={atomic_default_mem_order(score(3): acq_rel)}) int baz3 (int, int, int *);
minhash_sketch.h
#ifndef MHSKETCH_H_ #define MHSKETCH_H_ #pragma once #include <emmintrin.h> #include <smmintrin.h> #include "../seq/types.h" #include "counts_table.h" #include "basic_map.h" #include "mph.h" #include <stdlib.h> #include <math.h> #include <unordered_map> #if defined(_OPENMP) #include <omp.h> #endif static const int BITS_IN_KMER_HASH = 64; typedef uint64 hash_size_t; struct minhash_fp_t { std::vector<hash_size_t> v; }; struct rand_range_generator_t { int rand_in_range(int n) { int r, rand_max = RAND_MAX - (RAND_MAX % n); while ((r = rand()) >= rand_max); return r / (rand_max / n); } }; // multi-stream minhash index class minhash_table_t : public counts_table_t { public: int k; int n_streams; int FP_len; int FP_proj_len; int n_tables; // kmer hashing, multiply-shift hash functions (Dietzfelbinger et al) std::vector<hash_size_t> fp_hash_funcs; std::vector<std::vector<hash_size_t> > fp_proj_funcs; std::vector<std::vector<int> > fp_proj_ind; typedef uint64 proj_hash_t; std::vector<basic_table_t> tables; std::vector<mphf_table_t> static_tables; minhash_table_t(): minhash_table_t(0,0,0,0,0) {} minhash_table_t(const int kmer_len, const int fp_len, const int n_proj, const int proj_len, const int n_input_streams) { k = kmer_len; FP_len = fp_len; n_tables = n_proj; FP_proj_len = proj_len; n_streams = n_input_streams; init_hash_funcs(); tables.resize(n_tables); static_tables.resize(n_tables); } void init_hash_funcs() { fp_hash_funcs.resize(FP_len); for(int i = 0; i < FP_len; i++) { hash_size_t a = 2ULL*rand() + 1ULL; // odd multipliers fp_hash_funcs[i] = a; } fp_proj_funcs.resize(n_tables); fp_proj_ind.resize(n_tables); rand_range_generator_t rgen; std::vector<int> idx(FP_len); for(int i = 0; i < n_tables; i++) { for(int k = 0; k < FP_len; k++) { idx[k] = k; } // pick random indices from the sketch fp_proj_funcs[i].resize(FP_proj_len); fp_proj_ind[i].resize(FP_proj_len); int cnt = 0; int len = FP_len; while(cnt < FP_proj_len) { int j = rgen.rand_in_range(len); // exclude 0 fp_proj_ind[i][cnt] = idx[j]; fp_proj_funcs[i][cnt] = 2ULL * rand() + 1ULL; idx[j] = idx[len-1]; cnt++; len--; } } } bool compute_fp(const std::string seq, minhash_fp_t& fp) { const int n_kmers = seq.size() - k + 1; kmer_2bit_t v[n_kmers] __attribute__((aligned(16)));; int n_valid_kmers = 0; kmer_parser_t seq_parser; seq_parser.init(seq, k); kmer_t kmer; while(seq_parser.get_next_kmer(kmer)) { if(!kmer.valid) continue; v[n_valid_kmers] = kmer.packed_rep; n_valid_kmers++; } if(n_valid_kmers <= k) { return false; } fp.v.resize(FP_len); for(int h = 0; h < FP_len; h++) { const hash_size_t s = fp_hash_funcs[h]; hash_size_t curr_min = s*v[0]; for(int i = 1; i < n_valid_kmers; i++) { hash_size_t p = v[i]*s; if(p < curr_min) { curr_min = p; } } fp.v[h] = curr_min; } return true; } virtual proj_hash_t compute_fp_proj(const minhash_fp_t& fp, const int proj_id) const { proj_hash_t s = 0; for(int i = 0; i < FP_proj_len; i++) { s += fp_proj_funcs[proj_id][i]*fp.v[fp_proj_ind[proj_id][i]]; } return s; } // ---- interface ---- // virtual void clear() {} virtual ~minhash_table_t() {} virtual int get_n_streams() { return n_streams; } virtual void insert(const std::string& seq, const int stream_id) { minhash_fp_t fp; if(!compute_fp(seq, fp)) return; // compute the projections #pragma omp parallel for for(int t = 0; t < n_tables; t++) { // for each hash table proj_hash_t key = compute_fp_proj(fp, t); tables[t].insert(key, stream_id); //std::cout << key << " "; } //std::cout << "\n"; } // lookup the kmer count in the sketch virtual counter_t lookup(const minhash_fp_t& fp, const int stream_id) const { std::vector<counter_t> proj_counts(n_tables); for(int t = 0; t < n_tables; t++) { // for each hash table proj_hash_t key = compute_fp_proj(fp, t); proj_counts[t] = static_tables[t].lookup(key, stream_id); } // return median std::sort(proj_counts.begin(), proj_counts.end()); return proj_counts[proj_counts.size()/2]; } virtual void done() { #pragma omp parallel for for(int t = 0; t < n_tables; t++) { // for each hash table std::vector<kmer_2bit_t> keys; std::vector<counter_t> key_counts; tables[t].get_key_values(keys, key_counts); tables[t].clear(); static_tables[t].init(keys, key_counts); } std::vector<basic_table_t>().swap(tables); } // write the table to file virtual void save_to_file(const std::string& fname, const int n_count_bits) { std::ofstream file; file.open(fname.c_str(), std::ios::out | std::ios::binary | std::ios::app); file.write(reinterpret_cast<char*>(&n_streams), sizeof(n_streams)); file.write(reinterpret_cast<char*>(&k), sizeof(k)); file.write(reinterpret_cast<char*>(&n_tables), sizeof(n_tables)); file.write(reinterpret_cast<char*>(&FP_len), sizeof(FP_len)); file.write(reinterpret_cast<char*>(&FP_proj_len), sizeof(FP_proj_len)); file.close(); for(int t = 0; t < n_tables; t++) { // for each hash table static_tables[t].save_to_file(fname, n_count_bits); } } // load the table from file virtual long int load_from_file(const std::string& fname, long int file_offset) { std::ifstream file; file.open(fname.c_str(), std::ios::in | std::ios::binary); file.seekg(file_offset, file.beg); file.read(reinterpret_cast<char*>(&n_streams), sizeof(n_streams)); file.read(reinterpret_cast<char*>(&k), sizeof(k)); file.read(reinterpret_cast<char*>(&n_tables), sizeof(n_tables)); file.read(reinterpret_cast<char*>(&FP_len), sizeof(FP_len)); file.read(reinterpret_cast<char*>(&FP_proj_len), sizeof(FP_proj_len)); long int s = file.tellg(); file.close(); init_hash_funcs(); tables.resize(n_tables); static_tables.resize(n_tables); std::cout << "Minhash config: " << FP_len << " " << n_tables << "\n"; for(int t = 0; t < n_tables; t++) { // for each hash table s = static_tables[t].load_from_file(fname, s); } //init_hash_funcs(); std::cout << "Loaded index \n"; return s; } virtual void print_stats() { for(int t = 0; t < n_tables; t++) { //tables[t].print_stats(); } } virtual counter_t lookup(const kmer_2bit_t& kmer, const int stream_id) const { return 0; } virtual void insert(const kmer_2bit_t& kmer, const int stream_id) {} }; #endif
interaction.c
/* Copyright (C) 2015 Atsushi Togo */ /* All rights reserved. */ /* This file is part of phonopy. */ /* Redistribution and use in source and binary forms, with or without */ /* modification, are permitted provided that the following conditions */ /* are met: */ /* * Redistributions of source code must retain the above copyright */ /* notice, this list of conditions and the following disclaimer. */ /* * 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. */ /* * Neither the name of the phonopy project nor the names of its */ /* contributors may be used to endorse or promote products derived */ /* from this software without specific prior written permission. */ /* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS */ /* "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 */ /* COPYRIGHT HOLDER OR CONTRIBUTORS 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 "interaction.h" #include <stdio.h> #include <stdlib.h> #include "bzgrid.h" #include "imag_self_energy_with_g.h" #include "lapack_wrapper.h" #include "phonoc_array.h" #include "real_to_reciprocal.h" #include "reciprocal_to_normal.h" static const long index_exchange[6][3] = {{0, 1, 2}, {2, 0, 1}, {1, 2, 0}, {2, 1, 0}, {0, 2, 1}, {1, 0, 2}}; static void real_to_normal( double *fc3_normal_squared, const long (*g_pos)[4], const long num_g_pos, const double *freqs0, const double *freqs1, const double *freqs2, const lapack_complex_double *eigvecs0, const lapack_complex_double *eigvecs1, const lapack_complex_double *eigvecs2, const double *fc3, const long is_compact_fc3, const double q_vecs[3][3], /* q0, q1, q2 */ const double (*svecs)[3], const long multi_dims[2], const long (*multiplicity)[2], const double *masses, const long *p2s_map, const long *s2p_map, const long *band_indices, const long num_band, const double cutoff_frequency, const long triplet_index, const long num_triplets, const long openmp_at_bands); static void real_to_normal_sym_q( double *fc3_normal_squared, const long (*g_pos)[4], const long num_g_pos, double *const freqs[3], lapack_complex_double *const eigvecs[3], const double *fc3, const long is_compact_fc3, const double q_vecs[3][3], /* q0, q1, q2 */ const double (*svecs)[3], const long multi_dims[2], const long (*multiplicity)[2], const double *masses, const long *p2s_map, const long *s2p_map, const long *band_indices, const long num_band0, const long num_band, const double cutoff_frequency, const long triplet_index, const long num_triplets, const long openmp_at_bands); /* fc3_normal_squared[num_triplets, num_band0, num_band, num_band] */ void itr_get_interaction(Darray *fc3_normal_squared, const char *g_zero, const Darray *frequencies, const lapack_complex_double *eigenvectors, const long (*triplets)[3], const long num_triplets, const ConstBZGrid *bzgrid, const double *fc3, const long is_compact_fc3, const double (*svecs)[3], const long multi_dims[2], const long (*multiplicity)[2], const double *masses, const long *p2s_map, const long *s2p_map, const long *band_indices, const long symmetrize_fc3_q, const double cutoff_frequency) { long openmp_per_triplets; long(*g_pos)[4]; long i; long num_band, num_band0, num_band_prod, num_g_pos; g_pos = NULL; num_band0 = fc3_normal_squared->dims[1]; num_band = frequencies->dims[1]; num_band_prod = num_band0 * num_band * num_band; if (num_triplets > num_band) { openmp_per_triplets = 1; } else { openmp_per_triplets = 0; } #ifdef _OPENMP #pragma omp parallel for schedule(guided) private( \ num_g_pos, g_pos) if (openmp_per_triplets) #endif for (i = 0; i < num_triplets; i++) { g_pos = (long(*)[4])malloc(sizeof(long[4]) * num_band_prod); num_g_pos = ise_set_g_pos(g_pos, num_band0, num_band, g_zero + i * num_band_prod); itr_get_interaction_at_triplet( fc3_normal_squared->data + i * num_band_prod, num_band0, num_band, g_pos, num_g_pos, frequencies->data, eigenvectors, triplets[i], bzgrid, fc3, is_compact_fc3, svecs, multi_dims, multiplicity, masses, p2s_map, s2p_map, band_indices, symmetrize_fc3_q, cutoff_frequency, i, num_triplets, 1 - openmp_per_triplets); free(g_pos); g_pos = NULL; } } void itr_get_interaction_at_triplet( double *fc3_normal_squared, const long num_band0, const long num_band, const long (*g_pos)[4], const long num_g_pos, const double *frequencies, const lapack_complex_double *eigenvectors, const long triplet[3], const ConstBZGrid *bzgrid, const double *fc3, const long is_compact_fc3, const double (*svecs)[3], const long multi_dims[2], const long (*multiplicity)[2], const double *masses, const long *p2s_map, const long *s2p_map, const long *band_indices, const long symmetrize_fc3_q, const double cutoff_frequency, const long triplet_index, /* only for print */ const long num_triplets, /* only for print */ const long openmp_at_bands) { long j, k; double *freqs[3]; lapack_complex_double *eigvecs[3]; double q_vecs[3][3]; for (j = 0; j < 3; j++) { for (k = 0; k < 3; k++) { q_vecs[j][k] = ((double)bzgrid->addresses[triplet[j]][k]) / bzgrid->D_diag[k]; } bzg_multiply_matrix_vector_ld3(q_vecs[j], bzgrid->Q, q_vecs[j]); } if (symmetrize_fc3_q) { for (j = 0; j < 3; j++) { freqs[j] = (double *)malloc(sizeof(double) * num_band); eigvecs[j] = (lapack_complex_double *)malloc( sizeof(lapack_complex_double) * num_band * num_band); for (k = 0; k < num_band; k++) { freqs[j][k] = frequencies[triplet[j] * num_band + k]; } for (k = 0; k < num_band * num_band; k++) { eigvecs[j][k] = eigenvectors[triplet[j] * num_band * num_band + k]; } } real_to_normal_sym_q( fc3_normal_squared, g_pos, num_g_pos, freqs, eigvecs, fc3, is_compact_fc3, q_vecs, /* q0, q1, q2 */ svecs, multi_dims, multiplicity, masses, p2s_map, s2p_map, band_indices, num_band0, num_band, cutoff_frequency, triplet_index, num_triplets, openmp_at_bands); for (j = 0; j < 3; j++) { free(freqs[j]); freqs[j] = NULL; free(eigvecs[j]); eigvecs[j] = NULL; } } else { real_to_normal(fc3_normal_squared, g_pos, num_g_pos, frequencies + triplet[0] * num_band, frequencies + triplet[1] * num_band, frequencies + triplet[2] * num_band, eigenvectors + triplet[0] * num_band * num_band, eigenvectors + triplet[1] * num_band * num_band, eigenvectors + triplet[2] * num_band * num_band, fc3, is_compact_fc3, q_vecs, /* q0, q1, q2 */ svecs, multi_dims, multiplicity, masses, p2s_map, s2p_map, band_indices, num_band, cutoff_frequency, triplet_index, num_triplets, openmp_at_bands); } } static void real_to_normal( double *fc3_normal_squared, const long (*g_pos)[4], const long num_g_pos, const double *freqs0, const double *freqs1, const double *freqs2, const lapack_complex_double *eigvecs0, const lapack_complex_double *eigvecs1, const lapack_complex_double *eigvecs2, const double *fc3, const long is_compact_fc3, const double q_vecs[3][3], /* q0, q1, q2 */ const double (*svecs)[3], const long multi_dims[2], const long (*multiplicity)[2], const double *masses, const long *p2s_map, const long *s2p_map, const long *band_indices, const long num_band, const double cutoff_frequency, const long triplet_index, const long num_triplets, const long openmp_at_bands) { lapack_complex_double *fc3_reciprocal; fc3_reciprocal = (lapack_complex_double *)malloc( sizeof(lapack_complex_double) * num_band * num_band * num_band); r2r_real_to_reciprocal(fc3_reciprocal, q_vecs, fc3, is_compact_fc3, svecs, multi_dims, multiplicity, p2s_map, s2p_map, openmp_at_bands); #ifdef MEASURE_R2N if (openmp_at_bands && num_triplets > 0) { printf("At triplet %d/%d (# of bands=%d):\n", triplet_index, num_triplets, num_band0); } #endif reciprocal_to_normal_squared( fc3_normal_squared, g_pos, num_g_pos, fc3_reciprocal, freqs0, freqs1, freqs2, eigvecs0, eigvecs1, eigvecs2, masses, band_indices, num_band, cutoff_frequency, openmp_at_bands); free(fc3_reciprocal); fc3_reciprocal = NULL; } static void real_to_normal_sym_q( double *fc3_normal_squared, const long (*g_pos)[4], const long num_g_pos, double *const freqs[3], lapack_complex_double *const eigvecs[3], const double *fc3, const long is_compact_fc3, const double q_vecs[3][3], /* q0, q1, q2 */ const double (*svecs)[3], const long multi_dims[2], const long (*multiplicity)[2], const double *masses, const long *p2s_map, const long *s2p_map, const long *band_indices, const long num_band0, const long num_band, const double cutoff_frequency, const long triplet_index, const long num_triplets, const long openmp_at_bands) { long i, j, k, l; long band_ex[3]; double q_vecs_ex[3][3]; double *fc3_normal_squared_ex; fc3_normal_squared_ex = (double *)malloc(sizeof(double) * num_band * num_band * num_band); for (i = 0; i < num_band0 * num_band * num_band; i++) { fc3_normal_squared[i] = 0; } for (i = 0; i < 6; i++) { for (j = 0; j < 3; j++) { for (k = 0; k < 3; k++) { q_vecs_ex[j][k] = q_vecs[index_exchange[i][j]][k]; } } real_to_normal( fc3_normal_squared_ex, g_pos, num_g_pos, freqs[index_exchange[i][0]], freqs[index_exchange[i][1]], freqs[index_exchange[i][2]], eigvecs[index_exchange[i][0]], eigvecs[index_exchange[i][1]], eigvecs[index_exchange[i][2]], fc3, is_compact_fc3, q_vecs_ex, /* q0, q1, q2 */ svecs, multi_dims, multiplicity, masses, p2s_map, s2p_map, band_indices, num_band, cutoff_frequency, triplet_index, num_triplets, openmp_at_bands); for (j = 0; j < num_band0; j++) { for (k = 0; k < num_band; k++) { for (l = 0; l < num_band; l++) { band_ex[0] = band_indices[j]; band_ex[1] = k; band_ex[2] = l; fc3_normal_squared[j * num_band * num_band + k * num_band + l] += fc3_normal_squared_ex[band_ex[index_exchange[i][0]] * num_band * num_band + band_ex[index_exchange[i][1]] * num_band + band_ex[index_exchange[i][2]]] / 6; } } } } free(fc3_normal_squared_ex); }
GB_binop__isgt_uint8.c
//------------------------------------------------------------------------------ // GB_binop: hard-coded functions for each built-in binary operator //------------------------------------------------------------------------------ // SuiteSparse:GraphBLAS, Timothy A. Davis, (c) 2017-2021, All Rights Reserved. // SPDX-License-Identifier: Apache-2.0 //------------------------------------------------------------------------------ // If this file is in the Generated2/ folder, do not edit it // (it is auto-generated from Generator/*). #include "GB.h" #ifndef GBCOMPACT #include "GB_emult.h" #include "GB_control.h" #include "GB_ek_slice.h" #include "GB_dense.h" #include "GB_atomics.h" #include "GB_bitmap_assign_methods.h" #include "GB_binop__include.h" // C=binop(A,B) is defined by the following types and operators: // A+B function (eWiseAdd): GB (_AaddB__isgt_uint8) // A.*B function (eWiseMult): GB (_AemultB_01__isgt_uint8) // A.*B function (eWiseMult): GB (_AemultB_02__isgt_uint8) // A.*B function (eWiseMult): GB (_AemultB_03__isgt_uint8) // A.*B function (eWiseMult): GB (_AemultB_bitmap__isgt_uint8) // A*D function (colscale): GB (_AxD__isgt_uint8) // D*A function (rowscale): GB (_DxB__isgt_uint8) // C+=B function (dense accum): GB (_Cdense_accumB__isgt_uint8) // C+=b function (dense accum): GB (_Cdense_accumb__isgt_uint8) // C+=A+B function (dense ewise3): GB ((none)) // C=A+B function (dense ewise3): GB (_Cdense_ewise3_noaccum__isgt_uint8) // C=scalar+B GB (_bind1st__isgt_uint8) // C=scalar+B' GB (_bind1st_tran__isgt_uint8) // C=A+scalar GB (_bind2nd__isgt_uint8) // C=A'+scalar GB (_bind2nd_tran__isgt_uint8) // C type: uint8_t // A type: uint8_t // B,b type: uint8_t // BinaryOp: cij = (aij > bij) #define GB_ATYPE \ uint8_t #define GB_BTYPE \ uint8_t #define GB_CTYPE \ uint8_t // true if the types of A and B are identical #define GB_ATYPE_IS_BTYPE \ 1 // true if the types of C and A are identical #define GB_CTYPE_IS_ATYPE \ 1 // true if the types of C and B are identical #define GB_CTYPE_IS_BTYPE \ 1 // aij = Ax [pA] #define GB_GETA(aij,Ax,pA,A_iso) \ uint8_t aij = GBX (Ax, pA, A_iso) // bij = Bx [pB] #define GB_GETB(bij,Bx,pB,B_iso) \ uint8_t bij = GBX (Bx, pB, B_iso) // declare scalar of the same type as C #define GB_CTYPE_SCALAR(t) \ uint8_t t // cij = Ax [pA] #define GB_COPY_A_TO_C(cij,Ax,pA,A_iso) \ cij = GBX (Ax, pA, A_iso) // cij = Bx [pB] #define GB_COPY_B_TO_C(cij,Bx,pB,B_iso) \ cij = GBX (Bx, pB, B_iso) #define GB_CX(p) Cx [p] // binary operator #define GB_BINOP(z,x,y,i,j) \ z = (x > y) ; // true if the binop must be flipped #define GB_BINOP_FLIP \ 0 // op is second #define GB_OP_IS_SECOND \ 0 // do the numerical phases of GB_add and GB_emult #define GB_PHASE_2_OF_2 // hard-coded loops can be vectorized #define GB_PRAGMA_SIMD_VECTORIZE GB_PRAGMA_SIMD // disable this operator and use the generic case if these conditions hold #define GB_DISABLE \ (GxB_NO_ISGT || GxB_NO_UINT8 || GxB_NO_ISGT_UINT8) //------------------------------------------------------------------------------ // C += A+B, all 3 matrices dense //------------------------------------------------------------------------------ #if 0 // The op must be MIN, MAX, PLUS, MINUS, RMINUS, TIMES, DIV, or RDIV. void GB ((none)) ( GrB_Matrix C, const GrB_Matrix A, const GrB_Matrix B, const int nthreads ) { #include "GB_dense_ewise3_accum_template.c" } #endif //------------------------------------------------------------------------------ // C = A+B, all 3 matrices dense //------------------------------------------------------------------------------ GrB_Info GB (_Cdense_ewise3_noaccum__isgt_uint8) ( GrB_Matrix C, const GrB_Matrix A, const GrB_Matrix B, const int nthreads ) { #if GB_DISABLE return (GrB_NO_VALUE) ; #else #include "GB_dense_ewise3_noaccum_template.c" return (GrB_SUCCESS) ; #endif } //------------------------------------------------------------------------------ // C += B, accumulate a sparse matrix into a dense matrix //------------------------------------------------------------------------------ GrB_Info GB (_Cdense_accumB__isgt_uint8) ( GrB_Matrix C, const GrB_Matrix B, const int64_t *B_ek_slicing, const int B_ntasks, const int B_nthreads ) { #if GB_DISABLE return (GrB_NO_VALUE) ; #else { #include "GB_dense_subassign_23_template.c" } return (GrB_SUCCESS) ; #endif } //------------------------------------------------------------------------------ // C += b, accumulate a scalar into a dense matrix //------------------------------------------------------------------------------ GrB_Info GB (_Cdense_accumb__isgt_uint8) ( GrB_Matrix C, const GB_void *p_bwork, const int nthreads ) { #if GB_DISABLE return (GrB_NO_VALUE) ; #else { // get the scalar b for C += b, of type uint8_t uint8_t bwork = (*((uint8_t *) p_bwork)) ; #include "GB_dense_subassign_22_template.c" return (GrB_SUCCESS) ; } return (GrB_SUCCESS) ; #endif } //------------------------------------------------------------------------------ // C = A*D, column scale with diagonal D matrix //------------------------------------------------------------------------------ GrB_Info GB (_AxD__isgt_uint8) ( GrB_Matrix C, const GrB_Matrix A, bool A_is_pattern, const GrB_Matrix D, bool D_is_pattern, const int64_t *A_ek_slicing, const int A_ntasks, const int A_nthreads ) { #if GB_DISABLE return (GrB_NO_VALUE) ; #else uint8_t *restrict Cx = (uint8_t *) C->x ; #include "GB_AxB_colscale_template.c" return (GrB_SUCCESS) ; #endif } //------------------------------------------------------------------------------ // C = D*B, row scale with diagonal D matrix //------------------------------------------------------------------------------ GrB_Info GB (_DxB__isgt_uint8) ( GrB_Matrix C, const GrB_Matrix D, bool D_is_pattern, const GrB_Matrix B, bool B_is_pattern, int nthreads ) { #if GB_DISABLE return (GrB_NO_VALUE) ; #else uint8_t *restrict Cx = (uint8_t *) C->x ; #include "GB_AxB_rowscale_template.c" return (GrB_SUCCESS) ; #endif } //------------------------------------------------------------------------------ // eWiseAdd: C = A+B or C<M> = A+B //------------------------------------------------------------------------------ GrB_Info GB (_AaddB__isgt_uint8) ( GrB_Matrix C, const int C_sparsity, const GrB_Matrix M, const bool Mask_struct, const bool Mask_comp, const GrB_Matrix A, const GrB_Matrix B, const bool Ch_is_Mh, const int64_t *restrict C_to_M, const int64_t *restrict C_to_A, const int64_t *restrict C_to_B, const GB_task_struct *restrict TaskList, const int C_ntasks, const int C_nthreads, GB_Context Context ) { #if GB_DISABLE return (GrB_NO_VALUE) ; #else GB_WERK_DECLARE (M_ek_slicing, int64_t) ; GB_WERK_DECLARE (A_ek_slicing, int64_t) ; GB_WERK_DECLARE (B_ek_slicing, int64_t) ; #include "GB_add_template.c" GB_FREE_WORK ; return (GrB_SUCCESS) ; #endif } //------------------------------------------------------------------------------ // eWiseMult: C = A.*B or C<M> = A.*B //------------------------------------------------------------------------------ GrB_Info GB (_AemultB_01__isgt_uint8) ( GrB_Matrix C, const int C_sparsity, const int ewise_method, const GrB_Matrix M, const bool Mask_struct, const bool Mask_comp, const GrB_Matrix A, const GrB_Matrix B, const int64_t *restrict C_to_M, const int64_t *restrict C_to_A, const int64_t *restrict C_to_B, const GB_task_struct *restrict TaskList, const int C_ntasks, const int C_nthreads, GB_Context Context ) { #if GB_DISABLE return (GrB_NO_VALUE) ; #else #include "GB_emult_01_meta.c" return (GrB_SUCCESS) ; #endif } //------------------------------------------------------------------------------ // eWiseMult: C<#> = A.*B when A is sparse/hyper and B is bitmap/full //------------------------------------------------------------------------------ GrB_Info GB (_AemultB_02__isgt_uint8) ( GrB_Matrix C, const GrB_Matrix M, const bool Mask_struct, const bool Mask_comp, const GrB_Matrix A, const GrB_Matrix B, const bool flipxy, const int64_t *restrict Cp_kfirst, const int64_t *A_ek_slicing, const int A_ntasks, const int A_nthreads ) { #if GB_DISABLE return (GrB_NO_VALUE) ; #else #if GB_BINOP_FLIP // The operator is not commutative, and does not have a flipped // variant. For example z=atan2(y,x). if (flipxy) { // use fmult(y,x) #undef GB_FLIPPED #define GB_FLIPPED 1 #include "GB_emult_02_template.c" } else { // use fmult(x,y) #undef GB_FLIPPED #define GB_FLIPPED 0 #include "GB_emult_02_template.c" } #else // No need to handle the flip: the operator is either commutative, or // has been handled by changing z=div(y,x) to z=rdiv(x,y) for example. #undef GB_FLIPPED #define GB_FLIPPED 0 #include "GB_emult_02_template.c" #endif return (GrB_SUCCESS) ; #endif } //------------------------------------------------------------------------------ // eWiseMult: C<M> = A.*B, M sparse/hyper, A and B bitmap/full //------------------------------------------------------------------------------ GrB_Info GB (_AemultB_03__isgt_uint8) ( GrB_Matrix C, const GrB_Matrix M, const bool Mask_struct, const GrB_Matrix A, const GrB_Matrix B, const int64_t *restrict Cp_kfirst, const int64_t *M_ek_slicing, const int M_ntasks, const int M_nthreads ) { #if GB_DISABLE return (GrB_NO_VALUE) ; #else #include "GB_emult_03_template.c" return (GrB_SUCCESS) ; #endif } //------------------------------------------------------------------------------ // eWiseMult: C=A.*B, C<M>=A.*B, C<!M>=A.*B where C is bitmap //------------------------------------------------------------------------------ GrB_Info GB (_AemultB_bitmap__isgt_uint8) ( GrB_Matrix C, const int ewise_method, const GrB_Matrix M, const bool Mask_struct, const bool Mask_comp, const GrB_Matrix A, const GrB_Matrix B, const int64_t *M_ek_slicing, const int M_ntasks, const int M_nthreads, const int C_nthreads, GB_Context Context ) { #if GB_DISABLE return (GrB_NO_VALUE) ; #else #include "GB_bitmap_emult_template.c" return (GrB_SUCCESS) ; #endif } //------------------------------------------------------------------------------ // Cx = op (x,Bx): apply a binary operator to a matrix with scalar bind1st //------------------------------------------------------------------------------ GrB_Info GB (_bind1st__isgt_uint8) ( GB_void *Cx_output, // Cx and Bx may be aliased const GB_void *x_input, const GB_void *Bx_input, const int8_t *restrict Bb, int64_t bnz, int nthreads ) { #if GB_DISABLE return (GrB_NO_VALUE) ; #else uint8_t *Cx = (uint8_t *) Cx_output ; uint8_t x = (*((uint8_t *) x_input)) ; uint8_t *Bx = (uint8_t *) Bx_input ; int64_t p ; #pragma omp parallel for num_threads(nthreads) schedule(static) for (p = 0 ; p < bnz ; p++) { if (!GBB (Bb, p)) continue ; uint8_t bij = GBX (Bx, p, false) ; Cx [p] = (x > bij) ; } return (GrB_SUCCESS) ; #endif } //------------------------------------------------------------------------------ // Cx = op (Ax,y): apply a binary operator to a matrix with scalar bind2nd //------------------------------------------------------------------------------ GrB_Info GB (_bind2nd__isgt_uint8) ( GB_void *Cx_output, // Cx and Ax may be aliased const GB_void *Ax_input, const GB_void *y_input, const int8_t *restrict Ab, int64_t anz, int nthreads ) { #if GB_DISABLE return (GrB_NO_VALUE) ; #else int64_t p ; uint8_t *Cx = (uint8_t *) Cx_output ; uint8_t *Ax = (uint8_t *) Ax_input ; uint8_t y = (*((uint8_t *) y_input)) ; #pragma omp parallel for num_threads(nthreads) schedule(static) for (p = 0 ; p < anz ; p++) { if (!GBB (Ab, p)) continue ; uint8_t aij = GBX (Ax, p, false) ; Cx [p] = (aij > y) ; } return (GrB_SUCCESS) ; #endif } //------------------------------------------------------------------------------ // C = op (x, A'): transpose and apply a binary operator //------------------------------------------------------------------------------ // cij = op (x, aij), no typecasting (in spite of the macro name) #undef GB_CAST_OP #define GB_CAST_OP(pC,pA) \ { \ uint8_t aij = GBX (Ax, pA, false) ; \ Cx [pC] = (x > aij) ; \ } GrB_Info GB (_bind1st_tran__isgt_uint8) ( GrB_Matrix C, const GB_void *x_input, const GrB_Matrix A, int64_t *restrict *Workspaces, const int64_t *restrict A_slice, int nworkspaces, int nthreads ) { // GB_unop_transpose.c uses GB_ATYPE, but A is // the 2nd input to binary operator z=f(x,y). #undef GB_ATYPE #define GB_ATYPE \ uint8_t #if GB_DISABLE return (GrB_NO_VALUE) ; #else uint8_t x = (*((const uint8_t *) x_input)) ; #include "GB_unop_transpose.c" return (GrB_SUCCESS) ; #endif #undef GB_ATYPE #define GB_ATYPE \ uint8_t } //------------------------------------------------------------------------------ // C = op (A', y): transpose and apply a binary operator //------------------------------------------------------------------------------ // cij = op (aij, y), no typecasting (in spite of the macro name) #undef GB_CAST_OP #define GB_CAST_OP(pC,pA) \ { \ uint8_t aij = GBX (Ax, pA, false) ; \ Cx [pC] = (aij > y) ; \ } GrB_Info GB (_bind2nd_tran__isgt_uint8) ( GrB_Matrix C, const GrB_Matrix A, const GB_void *y_input, int64_t *restrict *Workspaces, const int64_t *restrict A_slice, int nworkspaces, int nthreads ) { #if GB_DISABLE return (GrB_NO_VALUE) ; #else uint8_t y = (*((const uint8_t *) y_input)) ; #include "GB_unop_transpose.c" return (GrB_SUCCESS) ; #endif } #endif
kmp_sch_simd_runtime_static.c
// RUN: %libomp-compile && %libomp-run // RUN: %libomp-run 1 && %libomp-run 2 // The test checks schedule(simd:runtime) // in combination with OMP_SCHEDULE=static[,chunk] #include <stdio.h> #include <stdlib.h> #include <omp.h> #if defined(WIN32) || defined(_WIN32) #include <windows.h> #define delay() Sleep(1); #define seten(a,b,c) _putenv_s((a),(b)) #else #include <unistd.h> #define delay() usleep(10); #define seten(a,b,c) setenv((a),(b),(c)) #endif #define SIMD_LEN 4 int err = 0; // --------------------------------------------------------------------------- // Various definitions copied from OpenMP RTL. enum sched { kmp_sch_static_balanced_chunked = 45, kmp_sch_guided_simd = 46, kmp_sch_runtime_simd = 47, }; typedef unsigned u32; typedef long long i64; typedef unsigned long long u64; typedef struct { int reserved_1; int flags; int reserved_2; int reserved_3; char *psource; } id; #ifdef __cplusplus extern "C" { #endif int __kmpc_global_thread_num(id*); void __kmpc_barrier(id*, int gtid); void __kmpc_dispatch_init_4(id*, int, enum sched, int, int, int, int); void __kmpc_dispatch_init_8(id*, int, enum sched, i64, i64, i64, i64); int __kmpc_dispatch_next_4(id*, int, void*, void*, void*, void*); int __kmpc_dispatch_next_8(id*, int, void*, void*, void*, void*); #ifdef __cplusplus } // extern "C" #endif // End of definitions copied from OpenMP RTL. // --------------------------------------------------------------------------- static id loc = {0, 2, 0, 0, ";file;func;0;0;;"}; // --------------------------------------------------------------------------- void run_loop( int loop_lb, // Loop lower bound. int loop_ub, // Loop upper bound. int loop_st, // Loop stride. int lchunk ) { static int volatile loop_sync = 0; int lb; // Chunk lower bound. int ub; // Chunk upper bound. int st; // Chunk stride. int rc; int tid = omp_get_thread_num(); int gtid = __kmpc_global_thread_num(&loc); int last; int tc = (loop_ub - loop_lb) / loop_st + 1; int ch; int no_chunk = 0; if (lchunk == 0) { no_chunk = 1; lchunk = 1; } ch = lchunk * SIMD_LEN; #if _DEBUG > 1 printf("run_loop gtid %d tid %d (lb=%d, ub=%d, st=%d, ch=%d)\n", gtid, tid, (int)loop_lb, (int)loop_ub, (int)loop_st, lchunk); #endif // Don't test degenerate cases that should have been discovered by codegen. if (loop_st == 0) return; if (loop_st > 0 ? loop_lb > loop_ub : loop_lb < loop_ub) return; __kmpc_dispatch_init_4(&loc, gtid, kmp_sch_runtime_simd, loop_lb, loop_ub, loop_st, SIMD_LEN); { // Let the master thread handle the chunks alone. int chunk; // No of current chunk. int last_ub; // Upper bound of the last processed chunk. u64 cur; // Number of interations in current chunk. u64 max; // Max allowed iterations for current chunk. int undersized = 0; last_ub = loop_ub; chunk = 0; max = (loop_ub - loop_lb) / loop_st + 1; // The first chunk can consume all iterations. while (__kmpc_dispatch_next_4(&loc, gtid, &last, &lb, &ub, &st)) { ++ chunk; #if _DEBUG printf("th %d: chunk=%d, lb=%d, ub=%d ch %d\n", tid, chunk, (int)lb, (int)ub, (int)(ub-lb+1)); #endif // Check if previous chunk (it is not the final chunk) is undersized. if (undersized) printf("Error with chunk %d, th %d, err %d\n", chunk, tid, ++err); if (loop_st > 0) { if (!(ub <= loop_ub)) printf("Error with ub %d, %d, ch %d, err %d\n", (int)ub, (int)loop_ub, chunk, ++err); if (!(lb <= ub)) printf("Error with bounds %d, %d, %d, err %d\n", (int)lb, (int)ub, chunk, ++err); } else { if (!(ub >= loop_ub)) printf("Error with ub %d, %d, %d, err %d\n", (int)ub, (int)loop_ub, chunk, ++err); if (!(lb >= ub)) printf("Error with bounds %d, %d, %d, err %d\n", (int)lb, (int)ub, chunk, ++err); }; // if // Stride should not change. if (!(st == loop_st)) printf("Error with st %d, %d, ch %d, err %d\n", (int)st, (int)loop_st, chunk, ++err); cur = ( ub - lb ) / loop_st + 1; // Guided scheduling uses FP computations, so current chunk may // be a bit bigger (+1) than allowed maximum. if (!( cur <= max + 1)) printf("Error with iter %d, %d, err %d\n", cur, max, ++err); // Update maximum for the next chunk. if (last) { if (!no_chunk && cur > ch) printf("Error: too big last chunk %d (%d), tid %d, err %d\n", (int)cur, ch, tid, ++err); } else { if (cur % ch) printf("Error with chunk %d, %d, ch %d, tid %d, err %d\n", chunk, (int)cur, ch, tid, ++err); } if (cur < max) max = cur; last_ub = ub; undersized = (cur < ch); #if _DEBUG > 1 if (last) printf("under%d cur %d, ch %d, tid %d, ub %d, lb %d, st %d =======\n", undersized,cur,ch,tid,ub,lb,loop_st); #endif } // while // Must have the right last iteration index. if (loop_st > 0) { if (!(last_ub <= loop_ub)) printf("Error with last1 %d, %d, ch %d, err %d\n", (int)last_ub, (int)loop_ub, chunk, ++err); if (last && !(last_ub + loop_st > loop_ub)) printf("Error with last2 %d, %d, %d, ch %d, err %d\n", (int)last_ub, (int)loop_st, (int)loop_ub, chunk, ++err); } else { if (!(last_ub >= loop_ub)) printf("Error with last1 %d, %d, ch %d, err %d\n", (int)last_ub, (int)loop_ub, chunk, ++err); if (last && !(last_ub + loop_st < loop_ub)) printf("Error with last2 %d, %d, %d, ch %d, err %d\n", (int)last_ub, (int)loop_st, (int)loop_ub, chunk, ++err); } // if } __kmpc_barrier(&loc, gtid); } // run_loop int main(int argc, char *argv[]) { int chunk = 0; if (argc > 1) { char *buf = malloc(8 + strlen(argv[1])); // expect chunk size as a parameter chunk = atoi(argv[1]); strcpy(buf,"static,"); strcat(buf,argv[1]); seten("OMP_SCHEDULE",buf,1); printf("Testing schedule(simd:%s)\n", buf); free(buf); } else { seten("OMP_SCHEDULE","static",1); printf("Testing schedule(simd:static)\n"); } #pragma omp parallel// num_threads(num_th) run_loop(0, 26, 1, chunk); if (err) { printf("failed, err = %d\n", err); return 1; } else { printf("passed\n"); return 0; } }
GB_binop__lt_bool.c
//------------------------------------------------------------------------------ // GB_binop: hard-coded functions for each built-in binary operator //------------------------------------------------------------------------------ // SuiteSparse:GraphBLAS, Timothy A. Davis, (c) 2017-2022, All Rights Reserved. // SPDX-License-Identifier: Apache-2.0 //------------------------------------------------------------------------------ // If this file is in the Generated2/ folder, do not edit it // (it is auto-generated from Generator/*). #include "GB.h" #ifndef GBCOMPACT #include "GB_emult.h" #include "GB_control.h" #include "GB_ek_slice.h" #include "GB_dense.h" #include "GB_atomics.h" #include "GB_bitmap_assign_methods.h" #include "GB_binop__include.h" // C=binop(A,B) is defined by the following types and operators: // A+B function (eWiseAdd): GB (_AaddB__lt_bool) // A.*B function (eWiseMult): GB (_AemultB_08__lt_bool) // A.*B function (eWiseMult): GB (_AemultB_02__lt_bool) // A.*B function (eWiseMult): GB (_AemultB_04__lt_bool) // A.*B function (eWiseMult): GB (_AemultB_bitmap__lt_bool) // A*D function (colscale): GB (_AxD__lt_bool) // D*A function (rowscale): GB (_DxB__lt_bool) // C+=B function (dense accum): GB (_Cdense_accumB__lt_bool) // C+=b function (dense accum): GB (_Cdense_accumb__lt_bool) // C+=A+B function (dense ewise3): GB ((none)) // C=A+B function (dense ewise3): GB (_Cdense_ewise3_noaccum__lt_bool) // C=scalar+B GB (_bind1st__lt_bool) // C=scalar+B' GB (_bind1st_tran__lt_bool) // C=A+scalar GB (_bind2nd__lt_bool) // C=A'+scalar GB (_bind2nd_tran__lt_bool) // C type: bool // A type: bool // A pattern? 0 // B type: bool // B pattern? 0 // BinaryOp: cij = (aij < bij) #define GB_ATYPE \ bool #define GB_BTYPE \ bool #define GB_CTYPE \ bool // true if the types of A and B are identical #define GB_ATYPE_IS_BTYPE \ 1 // true if the types of C and A are identical #define GB_CTYPE_IS_ATYPE \ 1 // true if the types of C and B are identical #define GB_CTYPE_IS_BTYPE \ 1 // aij = Ax [pA] #define GB_GETA(aij,Ax,pA,A_iso) \ bool aij = GBX (Ax, pA, A_iso) // true if values of A are not used #define GB_A_IS_PATTERN \ 0 \ // bij = Bx [pB] #define GB_GETB(bij,Bx,pB,B_iso) \ bool bij = GBX (Bx, pB, B_iso) // true if values of B are not used #define GB_B_IS_PATTERN \ 0 \ // declare scalar of the same type as C #define GB_CTYPE_SCALAR(t) \ bool t // cij = Ax [pA] #define GB_COPY_A_TO_C(cij,Ax,pA,A_iso) \ cij = GBX (Ax, pA, A_iso) // cij = Bx [pB] #define GB_COPY_B_TO_C(cij,Bx,pB,B_iso) \ cij = GBX (Bx, pB, B_iso) #define GB_CX(p) Cx [p] // binary operator #define GB_BINOP(z,x,y,i,j) \ z = (x < y) ; // true if the binop must be flipped #define GB_BINOP_FLIP \ 0 // op is second #define GB_OP_IS_SECOND \ 0 // do the numerical phases of GB_add and GB_emult #define GB_PHASE_2_OF_2 // hard-coded loops can be vectorized #define GB_PRAGMA_SIMD_VECTORIZE GB_PRAGMA_SIMD // disable this operator and use the generic case if these conditions hold #define GB_DISABLE \ (GxB_NO_LT || GxB_NO_BOOL || GxB_NO_LT_BOOL) //------------------------------------------------------------------------------ // C += A+B, all 3 matrices dense //------------------------------------------------------------------------------ #if 0 // The op must be MIN, MAX, PLUS, MINUS, RMINUS, TIMES, DIV, or RDIV. void GB ((none)) ( GrB_Matrix C, const GrB_Matrix A, const GrB_Matrix B, const int nthreads ) { #include "GB_dense_ewise3_accum_template.c" } #endif //------------------------------------------------------------------------------ // C = A+B, all 3 matrices dense //------------------------------------------------------------------------------ void GB (_Cdense_ewise3_noaccum__lt_bool) ( GrB_Matrix C, const GrB_Matrix A, const GrB_Matrix B, const int nthreads ) { #include "GB_dense_ewise3_noaccum_template.c" } //------------------------------------------------------------------------------ // C += B, accumulate a sparse matrix into a dense matrix //------------------------------------------------------------------------------ GrB_Info GB (_Cdense_accumB__lt_bool) ( GrB_Matrix C, const GrB_Matrix B, const int64_t *B_ek_slicing, const int B_ntasks, const int B_nthreads ) { #if GB_DISABLE return (GrB_NO_VALUE) ; #else { #include "GB_dense_subassign_23_template.c" } return (GrB_SUCCESS) ; #endif } //------------------------------------------------------------------------------ // C += b, accumulate a scalar into a dense matrix //------------------------------------------------------------------------------ GrB_Info GB (_Cdense_accumb__lt_bool) ( GrB_Matrix C, const GB_void *p_bwork, const int nthreads ) { #if GB_DISABLE return (GrB_NO_VALUE) ; #else { // get the scalar b for C += b, of type bool bool bwork = (*((bool *) p_bwork)) ; #include "GB_dense_subassign_22_template.c" return (GrB_SUCCESS) ; } return (GrB_SUCCESS) ; #endif } //------------------------------------------------------------------------------ // C = A*D, column scale with diagonal D matrix //------------------------------------------------------------------------------ GrB_Info GB (_AxD__lt_bool) ( GrB_Matrix C, const GrB_Matrix A, const GrB_Matrix D, const int64_t *A_ek_slicing, const int A_ntasks, const int A_nthreads ) { #if GB_DISABLE return (GrB_NO_VALUE) ; #else bool *restrict Cx = (bool *) C->x ; #include "GB_AxB_colscale_template.c" return (GrB_SUCCESS) ; #endif } //------------------------------------------------------------------------------ // C = D*B, row scale with diagonal D matrix //------------------------------------------------------------------------------ GrB_Info GB (_DxB__lt_bool) ( GrB_Matrix C, const GrB_Matrix D, const GrB_Matrix B, int nthreads ) { #if GB_DISABLE return (GrB_NO_VALUE) ; #else bool *restrict Cx = (bool *) C->x ; #include "GB_AxB_rowscale_template.c" return (GrB_SUCCESS) ; #endif } //------------------------------------------------------------------------------ // eWiseAdd: C=A+B, C<M>=A+B, C<!M>=A+B //------------------------------------------------------------------------------ GrB_Info GB (_AaddB__lt_bool) ( GrB_Matrix C, const int C_sparsity, const GrB_Matrix M, const bool Mask_struct, const bool Mask_comp, const GrB_Matrix A, const GrB_Matrix B, const bool is_eWiseUnion, const GB_void *alpha_scalar_in, const GB_void *beta_scalar_in, const bool Ch_is_Mh, const int64_t *restrict C_to_M, const int64_t *restrict C_to_A, const int64_t *restrict C_to_B, const GB_task_struct *restrict TaskList, const int C_ntasks, const int C_nthreads, GB_Context Context ) { #if GB_DISABLE return (GrB_NO_VALUE) ; #else GB_WERK_DECLARE (M_ek_slicing, int64_t) ; GB_WERK_DECLARE (A_ek_slicing, int64_t) ; GB_WERK_DECLARE (B_ek_slicing, int64_t) ; bool alpha_scalar ; bool beta_scalar ; if (is_eWiseUnion) { alpha_scalar = (*((bool *) alpha_scalar_in)) ; beta_scalar = (*((bool *) beta_scalar_in )) ; } #include "GB_add_template.c" GB_FREE_WORKSPACE ; return (GrB_SUCCESS) ; #endif } //------------------------------------------------------------------------------ // eWiseMult: C=A.*B, C<M>=A.*B, or C<M!>=A.*B where C is sparse/hyper //------------------------------------------------------------------------------ GrB_Info GB (_AemultB_08__lt_bool) ( GrB_Matrix C, const int C_sparsity, const int ewise_method, const GrB_Matrix M, const bool Mask_struct, const bool Mask_comp, const GrB_Matrix A, const GrB_Matrix B, const int64_t *restrict C_to_M, const int64_t *restrict C_to_A, const int64_t *restrict C_to_B, const GB_task_struct *restrict TaskList, const int C_ntasks, const int C_nthreads, GB_Context Context ) { #if GB_DISABLE return (GrB_NO_VALUE) ; #else #include "GB_emult_08_meta.c" return (GrB_SUCCESS) ; #endif } //------------------------------------------------------------------------------ // eWiseMult: C<#> = A.*B when A is sparse/hyper and B is bitmap/full //------------------------------------------------------------------------------ GrB_Info GB (_AemultB_02__lt_bool) ( GrB_Matrix C, const GrB_Matrix M, const bool Mask_struct, const bool Mask_comp, const GrB_Matrix A, const GrB_Matrix B, const bool flipxy, const int64_t *restrict Cp_kfirst, const int64_t *A_ek_slicing, const int A_ntasks, const int A_nthreads ) { #if GB_DISABLE return (GrB_NO_VALUE) ; #else #if GB_BINOP_FLIP // The operator is not commutative, and does not have a flipped // variant. For example z=atan2(y,x). if (flipxy) { // use fmult(y,x) #undef GB_FLIPPED #define GB_FLIPPED 1 #include "GB_emult_02_template.c" } else { // use fmult(x,y) #undef GB_FLIPPED #define GB_FLIPPED 0 #include "GB_emult_02_template.c" } #else // No need to handle the flip: the operator is either commutative, or // has been handled by changing z=div(y,x) to z=rdiv(x,y) for example. #undef GB_FLIPPED #define GB_FLIPPED 0 #include "GB_emult_02_template.c" #endif return (GrB_SUCCESS) ; #endif } //------------------------------------------------------------------------------ // eWiseMult: C<M> = A.*B, M sparse/hyper, A and B bitmap/full //------------------------------------------------------------------------------ GrB_Info GB (_AemultB_04__lt_bool) ( GrB_Matrix C, const GrB_Matrix M, const bool Mask_struct, const GrB_Matrix A, const GrB_Matrix B, const int64_t *restrict Cp_kfirst, const int64_t *M_ek_slicing, const int M_ntasks, const int M_nthreads ) { #if GB_DISABLE return (GrB_NO_VALUE) ; #else #include "GB_emult_04_template.c" return (GrB_SUCCESS) ; #endif } //------------------------------------------------------------------------------ // eWiseMult: C=A.*B, C<M>=A.*B, C<!M>=A.*B where C is bitmap //------------------------------------------------------------------------------ GrB_Info GB (_AemultB_bitmap__lt_bool) ( GrB_Matrix C, const int ewise_method, const GrB_Matrix M, const bool Mask_struct, const bool Mask_comp, const GrB_Matrix A, const GrB_Matrix B, const int64_t *M_ek_slicing, const int M_ntasks, const int M_nthreads, const int C_nthreads, GB_Context Context ) { #if GB_DISABLE return (GrB_NO_VALUE) ; #else #include "GB_bitmap_emult_template.c" return (GrB_SUCCESS) ; #endif } //------------------------------------------------------------------------------ // Cx = op (x,Bx): apply a binary operator to a matrix with scalar bind1st //------------------------------------------------------------------------------ GrB_Info GB (_bind1st__lt_bool) ( GB_void *Cx_output, // Cx and Bx may be aliased const GB_void *x_input, const GB_void *Bx_input, const int8_t *restrict Bb, int64_t bnz, int nthreads ) { #if GB_DISABLE return (GrB_NO_VALUE) ; #else bool *Cx = (bool *) Cx_output ; bool x = (*((bool *) x_input)) ; bool *Bx = (bool *) Bx_input ; int64_t p ; #pragma omp parallel for num_threads(nthreads) schedule(static) for (p = 0 ; p < bnz ; p++) { if (!GBB (Bb, p)) continue ; bool bij = GBX (Bx, p, false) ; Cx [p] = (x < bij) ; } return (GrB_SUCCESS) ; #endif } //------------------------------------------------------------------------------ // Cx = op (Ax,y): apply a binary operator to a matrix with scalar bind2nd //------------------------------------------------------------------------------ GrB_Info GB (_bind2nd__lt_bool) ( GB_void *Cx_output, // Cx and Ax may be aliased const GB_void *Ax_input, const GB_void *y_input, const int8_t *restrict Ab, int64_t anz, int nthreads ) { #if GB_DISABLE return (GrB_NO_VALUE) ; #else int64_t p ; bool *Cx = (bool *) Cx_output ; bool *Ax = (bool *) Ax_input ; bool y = (*((bool *) y_input)) ; #pragma omp parallel for num_threads(nthreads) schedule(static) for (p = 0 ; p < anz ; p++) { if (!GBB (Ab, p)) continue ; bool aij = GBX (Ax, p, false) ; Cx [p] = (aij < y) ; } return (GrB_SUCCESS) ; #endif } //------------------------------------------------------------------------------ // C = op (x, A'): transpose and apply a binary operator //------------------------------------------------------------------------------ // cij = op (x, aij), no typecasting (in spite of the macro name) #undef GB_CAST_OP #define GB_CAST_OP(pC,pA) \ { \ bool aij = GBX (Ax, pA, false) ; \ Cx [pC] = (x < aij) ; \ } GrB_Info GB (_bind1st_tran__lt_bool) ( GrB_Matrix C, const GB_void *x_input, const GrB_Matrix A, int64_t *restrict *Workspaces, const int64_t *restrict A_slice, int nworkspaces, int nthreads ) { // GB_unop_transpose.c uses GB_ATYPE, but A is // the 2nd input to binary operator z=f(x,y). #undef GB_ATYPE #define GB_ATYPE \ bool #if GB_DISABLE return (GrB_NO_VALUE) ; #else bool x = (*((const bool *) x_input)) ; #include "GB_unop_transpose.c" return (GrB_SUCCESS) ; #endif #undef GB_ATYPE #define GB_ATYPE \ bool } //------------------------------------------------------------------------------ // C = op (A', y): transpose and apply a binary operator //------------------------------------------------------------------------------ // cij = op (aij, y), no typecasting (in spite of the macro name) #undef GB_CAST_OP #define GB_CAST_OP(pC,pA) \ { \ bool aij = GBX (Ax, pA, false) ; \ Cx [pC] = (aij < y) ; \ } GrB_Info GB (_bind2nd_tran__lt_bool) ( GrB_Matrix C, const GrB_Matrix A, const GB_void *y_input, int64_t *restrict *Workspaces, const int64_t *restrict A_slice, int nworkspaces, int nthreads ) { #if GB_DISABLE return (GrB_NO_VALUE) ; #else bool y = (*((const bool *) y_input)) ; #include "GB_unop_transpose.c" return (GrB_SUCCESS) ; #endif } #endif
file_loader.h
#pragma once #include <cmath> #include "util/primitives/primitives.h" #include "util/timer.h" #include "util/util.h" #include "parsing_util.h" template<typename T> T *GetMMAPArr(const char *file_name, int &file_fd, size_t arr_size) { Timer populate_timer; file_fd = open(file_name, O_RDWR | O_CREAT, S_IRUSR | S_IWUSR); size_t file_size = arr_size * sizeof(T); auto ret = ftruncate(file_fd, file_size); auto mmap_arr_ = (T *) mmap(nullptr, file_size, PROT_WRITE, MAP_SHARED, file_fd, 0); // auto mmap_arr_ = (T *) mmap(nullptr, file_size, PROT_WRITE, MAP_SHARED | MAP_POPULATE, file_fd, 0); log_info("Open & MMAP Time: %.6lfs", populate_timer.elapsed()); assert(ret == 0); return mmap_arr_; } template<typename T> T *GetMMAPArrReadOnly(const char *file_name, int &file_fd, size_t arr_size) { Timer populate_timer; file_fd = open(file_name, O_RDONLY, S_IRUSR | S_IWUSR); size_t file_size = arr_size * sizeof(T); assert(file_fd >= 0); auto mmap_arr_ = (T *) mmap(nullptr, file_size, PROT_READ, MAP_PRIVATE, file_fd, 0); log_info("Open & MMAP Time: %.6lfs", populate_timer.elapsed()); return mmap_arr_; } template<typename T> T *GetMallocPReadArrReadOnly(const char *file_name, int &file_fd, size_t arr_size) { Timer populate_timer; file_fd = open(file_name, O_RDONLY, S_IRUSR | S_IWUSR); size_t file_size = arr_size * sizeof(T); log_info("File Size: %zu", file_size); assert(file_fd >= 0); auto arr = (char *) malloc(file_size); #pragma omp parallel for for (size_t i = 0; i < file_size; i += IO_REQ_SIZE) { auto size = min(i + IO_REQ_SIZE, file_size) - i; // assert(size <= IO_REQ_SIZE); auto ret = pread(file_fd, arr + i, size, i); // assert(ret == size); } log_info("Open & Malloc & PRead Time: %.6lfs", populate_timer.elapsed()); return (T *) arr; } /* * Global One. */ class FileLoader { protected: int file_fd{}; Timer timer; public: size_t size{}; FileLoader() = default; explicit FileLoader(const char *file_name) { file_fd = open(file_name, O_RDONLY, S_IRUSR | S_IWUSR); size = file_size(file_name); log_info("Start IO"); } ssize_t ReadToBuf(size_t i, char *tmp) { ssize_t num_reads; if (i != 0) { num_reads = pread(file_fd, tmp, IO_REQ_SIZE, i - EXTRA_IO_SIZE); } else { tmp[EXTRA_IO_SIZE - 1] = LINUX_SPLITTER; num_reads = pread(file_fd, tmp + EXTRA_IO_SIZE, IO_REQ_SIZE - EXTRA_IO_SIZE, i) + EXTRA_IO_SIZE; } return num_reads; } void PrintEndStat() { log_info("Read Time: %.6lfs, QPS: %.3lf GB/s", timer.elapsed(), size / timer.elapsed() / pow(10, 9)); } }; class FileLoaderMMap : public FileLoader { char *mmap_mem; public: explicit FileLoaderMMap(const char *file_name) : FileLoader(file_name) { mmap_mem = (char *) mmap(nullptr, size, PROT_READ, MAP_PRIVATE, file_fd, 0); } ssize_t ReadToBuf(size_t i, char *&tmp, char *first_buf) { ssize_t num_reads; if (i != 0) { num_reads = min<ssize_t>(size - i + EXTRA_IO_SIZE, IO_REQ_SIZE); tmp = mmap_mem + i - EXTRA_IO_SIZE; } else { num_reads = min<ssize_t>(size - i, IO_REQ_SIZE - EXTRA_IO_SIZE); memcpy(first_buf + EXTRA_IO_SIZE, mmap_mem, num_reads); tmp = first_buf; tmp[EXTRA_IO_SIZE - 1] = LINUX_SPLITTER; num_reads += EXTRA_IO_SIZE; } return num_reads; } };
nqueenspre.c
# 1 "nqueens.c" # 1 "<built-in>" 1 # 1 "<built-in>" 3 # 330 "<built-in>" 3 # 1 "<command line>" 1 # 1 "<built-in>" 2 # 1 "nqueens.c" 2 # 28 "nqueens.c" # 1 "/usr/include/stdlib.h" 1 3 4 # 24 "/usr/include/stdlib.h" 3 4 # 1 "/usr/include/features.h" 1 3 4 # 345 "/usr/include/features.h" 3 4 # 1 "/usr/include/stdc-predef.h" 1 3 4 # 346 "/usr/include/features.h" 2 3 4 # 367 "/usr/include/features.h" 3 4 # 1 "/usr/include/x86_64-linux-gnu/sys/cdefs.h" 1 3 4 # 410 "/usr/include/x86_64-linux-gnu/sys/cdefs.h" 3 4 # 1 "/usr/include/x86_64-linux-gnu/bits/wordsize.h" 1 3 4 # 411 "/usr/include/x86_64-linux-gnu/sys/cdefs.h" 2 3 4 # 368 "/usr/include/features.h" 2 3 4 # 391 "/usr/include/features.h" 3 4 # 1 "/usr/include/x86_64-linux-gnu/gnu/stubs.h" 1 3 4 # 10 "/usr/include/x86_64-linux-gnu/gnu/stubs.h" 3 4 # 1 "/usr/include/x86_64-linux-gnu/gnu/stubs-64.h" 1 3 4 # 11 "/usr/include/x86_64-linux-gnu/gnu/stubs.h" 2 3 4 # 392 "/usr/include/features.h" 2 3 4 # 25 "/usr/include/stdlib.h" 2 3 4 # 1 "/home/nader/llvm-omp/lib/clang/5.0.1/include/stddef.h" 1 3 4 # 62 "/home/nader/llvm-omp/lib/clang/5.0.1/include/stddef.h" 3 4 typedef long unsigned int size_t; # 90 "/home/nader/llvm-omp/lib/clang/5.0.1/include/stddef.h" 3 4 typedef int wchar_t; # 33 "/usr/include/stdlib.h" 2 3 4 # 1 "/usr/include/x86_64-linux-gnu/bits/waitflags.h" 1 3 4 # 50 "/usr/include/x86_64-linux-gnu/bits/waitflags.h" 3 4 typedef enum { P_ALL, P_PID, P_PGID } idtype_t; # 42 "/usr/include/stdlib.h" 2 3 4 # 1 "/usr/include/x86_64-linux-gnu/bits/waitstatus.h" 1 3 4 # 64 "/usr/include/x86_64-linux-gnu/bits/waitstatus.h" 3 4 # 1 "/usr/include/endian.h" 1 3 4 # 36 "/usr/include/endian.h" 3 4 # 1 "/usr/include/x86_64-linux-gnu/bits/endian.h" 1 3 4 # 37 "/usr/include/endian.h" 2 3 4 # 60 "/usr/include/endian.h" 3 4 # 1 "/usr/include/x86_64-linux-gnu/bits/byteswap.h" 1 3 4 # 27 "/usr/include/x86_64-linux-gnu/bits/byteswap.h" 3 4 # 1 "/usr/include/x86_64-linux-gnu/bits/types.h" 1 3 4 # 27 "/usr/include/x86_64-linux-gnu/bits/types.h" 3 4 # 1 "/usr/include/x86_64-linux-gnu/bits/wordsize.h" 1 3 4 # 28 "/usr/include/x86_64-linux-gnu/bits/types.h" 2 3 4 typedef unsigned char __u_char; typedef unsigned short int __u_short; typedef unsigned int __u_int; typedef unsigned long int __u_long; typedef signed char __int8_t; typedef unsigned char __uint8_t; typedef signed short int __int16_t; typedef unsigned short int __uint16_t; typedef signed int __int32_t; typedef unsigned int __uint32_t; typedef signed long int __int64_t; typedef unsigned long int __uint64_t; typedef long int __quad_t; typedef unsigned long int __u_quad_t; # 121 "/usr/include/x86_64-linux-gnu/bits/types.h" 3 4 # 1 "/usr/include/x86_64-linux-gnu/bits/typesizes.h" 1 3 4 # 122 "/usr/include/x86_64-linux-gnu/bits/types.h" 2 3 4 typedef unsigned long int __dev_t; typedef unsigned int __uid_t; typedef unsigned int __gid_t; typedef unsigned long int __ino_t; typedef unsigned long int __ino64_t; typedef unsigned int __mode_t; typedef unsigned long int __nlink_t; typedef long int __off_t; typedef long int __off64_t; typedef int __pid_t; typedef struct { int __val[2]; } __fsid_t; typedef long int __clock_t; typedef unsigned long int __rlim_t; typedef unsigned long int __rlim64_t; typedef unsigned int __id_t; typedef long int __time_t; typedef unsigned int __useconds_t; typedef long int __suseconds_t; typedef int __daddr_t; typedef int __key_t; typedef int __clockid_t; typedef void * __timer_t; typedef long int __blksize_t; typedef long int __blkcnt_t; typedef long int __blkcnt64_t; typedef unsigned long int __fsblkcnt_t; typedef unsigned long int __fsblkcnt64_t; typedef unsigned long int __fsfilcnt_t; typedef unsigned long int __fsfilcnt64_t; typedef long int __fsword_t; typedef long int __ssize_t; typedef long int __syscall_slong_t; typedef unsigned long int __syscall_ulong_t; typedef __off64_t __loff_t; typedef __quad_t *__qaddr_t; typedef char *__caddr_t; typedef long int __intptr_t; typedef unsigned int __socklen_t; # 28 "/usr/include/x86_64-linux-gnu/bits/byteswap.h" 2 3 4 # 1 "/usr/include/x86_64-linux-gnu/bits/wordsize.h" 1 3 4 # 29 "/usr/include/x86_64-linux-gnu/bits/byteswap.h" 2 3 4 # 1 "/usr/include/x86_64-linux-gnu/bits/byteswap-16.h" 1 3 4 # 36 "/usr/include/x86_64-linux-gnu/bits/byteswap.h" 2 3 4 # 61 "/usr/include/endian.h" 2 3 4 # 65 "/usr/include/x86_64-linux-gnu/bits/waitstatus.h" 2 3 4 union wait { int w_status; struct { unsigned int __w_termsig:7; unsigned int __w_coredump:1; unsigned int __w_retcode:8; unsigned int:16; } __wait_terminated; struct { unsigned int __w_stopval:8; unsigned int __w_stopsig:8; unsigned int:16; } __wait_stopped; }; # 43 "/usr/include/stdlib.h" 2 3 4 # 67 "/usr/include/stdlib.h" 3 4 typedef union { union wait *__uptr; int *__iptr; } __WAIT_STATUS __attribute__ ((__transparent_union__)); # 97 "/usr/include/stdlib.h" 3 4 typedef struct { int quot; int rem; } div_t; typedef struct { long int quot; long int rem; } ldiv_t; __extension__ typedef struct { long long int quot; long long int rem; } lldiv_t; # 139 "/usr/include/stdlib.h" 3 4 extern size_t __ctype_get_mb_cur_max (void) __attribute__ ((__nothrow__ )) ; extern double atof (const char *__nptr) __attribute__ ((__nothrow__ )) __attribute__ ((__pure__)) __attribute__ ((__nonnull__ (1))) ; extern int atoi (const char *__nptr) __attribute__ ((__nothrow__ )) __attribute__ ((__pure__)) __attribute__ ((__nonnull__ (1))) ; extern long int atol (const char *__nptr) __attribute__ ((__nothrow__ )) __attribute__ ((__pure__)) __attribute__ ((__nonnull__ (1))) ; __extension__ extern long long int atoll (const char *__nptr) __attribute__ ((__nothrow__ )) __attribute__ ((__pure__)) __attribute__ ((__nonnull__ (1))) ; extern double strtod (const char *__restrict __nptr, char **__restrict __endptr) __attribute__ ((__nothrow__ )) __attribute__ ((__nonnull__ (1))); extern float strtof (const char *__restrict __nptr, char **__restrict __endptr) __attribute__ ((__nothrow__ )) __attribute__ ((__nonnull__ (1))); extern long double strtold (const char *__restrict __nptr, char **__restrict __endptr) __attribute__ ((__nothrow__ )) __attribute__ ((__nonnull__ (1))); extern long int strtol (const char *__restrict __nptr, char **__restrict __endptr, int __base) __attribute__ ((__nothrow__ )) __attribute__ ((__nonnull__ (1))); extern unsigned long int strtoul (const char *__restrict __nptr, char **__restrict __endptr, int __base) __attribute__ ((__nothrow__ )) __attribute__ ((__nonnull__ (1))); __extension__ extern long long int strtoq (const char *__restrict __nptr, char **__restrict __endptr, int __base) __attribute__ ((__nothrow__ )) __attribute__ ((__nonnull__ (1))); __extension__ extern unsigned long long int strtouq (const char *__restrict __nptr, char **__restrict __endptr, int __base) __attribute__ ((__nothrow__ )) __attribute__ ((__nonnull__ (1))); __extension__ extern long long int strtoll (const char *__restrict __nptr, char **__restrict __endptr, int __base) __attribute__ ((__nothrow__ )) __attribute__ ((__nonnull__ (1))); __extension__ extern unsigned long long int strtoull (const char *__restrict __nptr, char **__restrict __endptr, int __base) __attribute__ ((__nothrow__ )) __attribute__ ((__nonnull__ (1))); # 277 "/usr/include/stdlib.h" 3 4 extern __inline __attribute__ ((__gnu_inline__)) int __attribute__ ((__nothrow__ )) atoi (const char *__nptr) { return (int) strtol (__nptr, (char **) ((void*)0), 10); } extern __inline __attribute__ ((__gnu_inline__)) long int __attribute__ ((__nothrow__ )) atol (const char *__nptr) { return strtol (__nptr, (char **) ((void*)0), 10); } __extension__ extern __inline __attribute__ ((__gnu_inline__)) long long int __attribute__ ((__nothrow__ )) atoll (const char *__nptr) { return strtoll (__nptr, (char **) ((void*)0), 10); } # 305 "/usr/include/stdlib.h" 3 4 extern char *l64a (long int __n) __attribute__ ((__nothrow__ )) ; extern long int a64l (const char *__s) __attribute__ ((__nothrow__ )) __attribute__ ((__pure__)) __attribute__ ((__nonnull__ (1))) ; # 1 "/usr/include/x86_64-linux-gnu/sys/types.h" 1 3 4 # 33 "/usr/include/x86_64-linux-gnu/sys/types.h" 3 4 typedef __u_char u_char; typedef __u_short u_short; typedef __u_int u_int; typedef __u_long u_long; typedef __quad_t quad_t; typedef __u_quad_t u_quad_t; typedef __fsid_t fsid_t; typedef __loff_t loff_t; typedef __ino_t ino_t; # 60 "/usr/include/x86_64-linux-gnu/sys/types.h" 3 4 typedef __dev_t dev_t; typedef __gid_t gid_t; typedef __mode_t mode_t; typedef __nlink_t nlink_t; typedef __uid_t uid_t; typedef __off_t off_t; # 98 "/usr/include/x86_64-linux-gnu/sys/types.h" 3 4 typedef __pid_t pid_t; typedef __id_t id_t; typedef __ssize_t ssize_t; typedef __daddr_t daddr_t; typedef __caddr_t caddr_t; typedef __key_t key_t; # 132 "/usr/include/x86_64-linux-gnu/sys/types.h" 3 4 # 1 "/usr/include/time.h" 1 3 4 # 59 "/usr/include/time.h" 3 4 typedef __clock_t clock_t; # 75 "/usr/include/time.h" 3 4 typedef __time_t time_t; # 91 "/usr/include/time.h" 3 4 typedef __clockid_t clockid_t; # 103 "/usr/include/time.h" 3 4 typedef __timer_t timer_t; # 133 "/usr/include/x86_64-linux-gnu/sys/types.h" 2 3 4 # 146 "/usr/include/x86_64-linux-gnu/sys/types.h" 3 4 # 1 "/home/nader/llvm-omp/lib/clang/5.0.1/include/stddef.h" 1 3 4 # 147 "/usr/include/x86_64-linux-gnu/sys/types.h" 2 3 4 typedef unsigned long int ulong; typedef unsigned short int ushort; typedef unsigned int uint; # 194 "/usr/include/x86_64-linux-gnu/sys/types.h" 3 4 typedef int int8_t __attribute__ ((__mode__ (__QI__))); typedef int int16_t __attribute__ ((__mode__ (__HI__))); typedef int int32_t __attribute__ ((__mode__ (__SI__))); typedef int int64_t __attribute__ ((__mode__ (__DI__))); typedef unsigned int u_int8_t __attribute__ ((__mode__ (__QI__))); typedef unsigned int u_int16_t __attribute__ ((__mode__ (__HI__))); typedef unsigned int u_int32_t __attribute__ ((__mode__ (__SI__))); typedef unsigned int u_int64_t __attribute__ ((__mode__ (__DI__))); typedef int register_t __attribute__ ((__mode__ (__word__))); # 219 "/usr/include/x86_64-linux-gnu/sys/types.h" 3 4 # 1 "/usr/include/x86_64-linux-gnu/sys/select.h" 1 3 4 # 30 "/usr/include/x86_64-linux-gnu/sys/select.h" 3 4 # 1 "/usr/include/x86_64-linux-gnu/bits/select.h" 1 3 4 # 22 "/usr/include/x86_64-linux-gnu/bits/select.h" 3 4 # 1 "/usr/include/x86_64-linux-gnu/bits/wordsize.h" 1 3 4 # 23 "/usr/include/x86_64-linux-gnu/bits/select.h" 2 3 4 # 31 "/usr/include/x86_64-linux-gnu/sys/select.h" 2 3 4 # 1 "/usr/include/x86_64-linux-gnu/bits/sigset.h" 1 3 4 # 22 "/usr/include/x86_64-linux-gnu/bits/sigset.h" 3 4 typedef int __sig_atomic_t; typedef struct { unsigned long int __val[(1024 / (8 * sizeof (unsigned long int)))]; } __sigset_t; # 34 "/usr/include/x86_64-linux-gnu/sys/select.h" 2 3 4 typedef __sigset_t sigset_t; # 1 "/usr/include/time.h" 1 3 4 # 120 "/usr/include/time.h" 3 4 struct timespec { __time_t tv_sec; __syscall_slong_t tv_nsec; }; # 44 "/usr/include/x86_64-linux-gnu/sys/select.h" 2 3 4 # 1 "/usr/include/x86_64-linux-gnu/bits/time.h" 1 3 4 # 30 "/usr/include/x86_64-linux-gnu/bits/time.h" 3 4 struct timeval { __time_t tv_sec; __suseconds_t tv_usec; }; # 46 "/usr/include/x86_64-linux-gnu/sys/select.h" 2 3 4 typedef __suseconds_t suseconds_t; typedef long int __fd_mask; # 64 "/usr/include/x86_64-linux-gnu/sys/select.h" 3 4 typedef struct { __fd_mask __fds_bits[1024 / (8 * (int) sizeof (__fd_mask))]; } fd_set; typedef __fd_mask fd_mask; # 106 "/usr/include/x86_64-linux-gnu/sys/select.h" 3 4 extern int select (int __nfds, fd_set *__restrict __readfds, fd_set *__restrict __writefds, fd_set *__restrict __exceptfds, struct timeval *__restrict __timeout); # 118 "/usr/include/x86_64-linux-gnu/sys/select.h" 3 4 extern int pselect (int __nfds, fd_set *__restrict __readfds, fd_set *__restrict __writefds, fd_set *__restrict __exceptfds, const struct timespec *__restrict __timeout, const __sigset_t *__restrict __sigmask); # 220 "/usr/include/x86_64-linux-gnu/sys/types.h" 2 3 4 # 1 "/usr/include/x86_64-linux-gnu/sys/sysmacros.h" 1 3 4 # 26 "/usr/include/x86_64-linux-gnu/sys/sysmacros.h" 3 4 __extension__ extern unsigned int gnu_dev_major (unsigned long long int __dev) __attribute__ ((__nothrow__ )) __attribute__ ((__const__)); __extension__ extern unsigned int gnu_dev_minor (unsigned long long int __dev) __attribute__ ((__nothrow__ )) __attribute__ ((__const__)); __extension__ extern unsigned long long int gnu_dev_makedev (unsigned int __major, unsigned int __minor) __attribute__ ((__nothrow__ )) __attribute__ ((__const__)); __extension__ extern __inline __attribute__ ((__gnu_inline__)) __attribute__ ((__const__)) unsigned int __attribute__ ((__nothrow__ )) gnu_dev_major (unsigned long long int __dev) { return ((__dev >> 8) & 0xfff) | ((unsigned int) (__dev >> 32) & ~0xfff); } __extension__ extern __inline __attribute__ ((__gnu_inline__)) __attribute__ ((__const__)) unsigned int __attribute__ ((__nothrow__ )) gnu_dev_minor (unsigned long long int __dev) { return (__dev & 0xff) | ((unsigned int) (__dev >> 12) & ~0xff); } __extension__ extern __inline __attribute__ ((__gnu_inline__)) __attribute__ ((__const__)) unsigned long long int __attribute__ ((__nothrow__ )) gnu_dev_makedev (unsigned int __major, unsigned int __minor) { return ((__minor & 0xff) | ((__major & 0xfff) << 8) | (((unsigned long long int) (__minor & ~0xff)) << 12) | (((unsigned long long int) (__major & ~0xfff)) << 32)); } # 223 "/usr/include/x86_64-linux-gnu/sys/types.h" 2 3 4 typedef __blksize_t blksize_t; typedef __blkcnt_t blkcnt_t; typedef __fsblkcnt_t fsblkcnt_t; typedef __fsfilcnt_t fsfilcnt_t; # 270 "/usr/include/x86_64-linux-gnu/sys/types.h" 3 4 # 1 "/usr/include/x86_64-linux-gnu/bits/pthreadtypes.h" 1 3 4 # 21 "/usr/include/x86_64-linux-gnu/bits/pthreadtypes.h" 3 4 # 1 "/usr/include/x86_64-linux-gnu/bits/wordsize.h" 1 3 4 # 22 "/usr/include/x86_64-linux-gnu/bits/pthreadtypes.h" 2 3 4 # 60 "/usr/include/x86_64-linux-gnu/bits/pthreadtypes.h" 3 4 typedef unsigned long int pthread_t; union pthread_attr_t { char __size[56]; long int __align; }; typedef union pthread_attr_t pthread_attr_t; typedef struct __pthread_internal_list { struct __pthread_internal_list *__prev; struct __pthread_internal_list *__next; } __pthread_list_t; # 90 "/usr/include/x86_64-linux-gnu/bits/pthreadtypes.h" 3 4 typedef union { struct __pthread_mutex_s { int __lock; unsigned int __count; int __owner; unsigned int __nusers; int __kind; short __spins; short __elision; __pthread_list_t __list; # 125 "/usr/include/x86_64-linux-gnu/bits/pthreadtypes.h" 3 4 } __data; char __size[40]; long int __align; } pthread_mutex_t; typedef union { char __size[4]; int __align; } pthread_mutexattr_t; typedef union { struct { int __lock; unsigned int __futex; __extension__ unsigned long long int __total_seq; __extension__ unsigned long long int __wakeup_seq; __extension__ unsigned long long int __woken_seq; void *__mutex; unsigned int __nwaiters; unsigned int __broadcast_seq; } __data; char __size[48]; __extension__ long long int __align; } pthread_cond_t; typedef union { char __size[4]; int __align; } pthread_condattr_t; typedef unsigned int pthread_key_t; typedef int pthread_once_t; typedef union { struct { int __lock; unsigned int __nr_readers; unsigned int __readers_wakeup; unsigned int __writer_wakeup; unsigned int __nr_readers_queued; unsigned int __nr_writers_queued; int __writer; int __shared; signed char __rwelision; unsigned char __pad1[7]; unsigned long int __pad2; unsigned int __flags; } __data; # 220 "/usr/include/x86_64-linux-gnu/bits/pthreadtypes.h" 3 4 char __size[56]; long int __align; } pthread_rwlock_t; typedef union { char __size[8]; long int __align; } pthread_rwlockattr_t; typedef volatile int pthread_spinlock_t; typedef union { char __size[32]; long int __align; } pthread_barrier_t; typedef union { char __size[4]; int __align; } pthread_barrierattr_t; # 271 "/usr/include/x86_64-linux-gnu/sys/types.h" 2 3 4 # 315 "/usr/include/stdlib.h" 2 3 4 extern long int random (void) __attribute__ ((__nothrow__ )); extern void srandom (unsigned int __seed) __attribute__ ((__nothrow__ )); extern char *initstate (unsigned int __seed, char *__statebuf, size_t __statelen) __attribute__ ((__nothrow__ )) __attribute__ ((__nonnull__ (2))); extern char *setstate (char *__statebuf) __attribute__ ((__nothrow__ )) __attribute__ ((__nonnull__ (1))); struct random_data { int32_t *fptr; int32_t *rptr; int32_t *state; int rand_type; int rand_deg; int rand_sep; int32_t *end_ptr; }; extern int random_r (struct random_data *__restrict __buf, int32_t *__restrict __result) __attribute__ ((__nothrow__ )) __attribute__ ((__nonnull__ (1, 2))); extern int srandom_r (unsigned int __seed, struct random_data *__buf) __attribute__ ((__nothrow__ )) __attribute__ ((__nonnull__ (2))); extern int initstate_r (unsigned int __seed, char *__restrict __statebuf, size_t __statelen, struct random_data *__restrict __buf) __attribute__ ((__nothrow__ )) __attribute__ ((__nonnull__ (2, 4))); extern int setstate_r (char *__restrict __statebuf, struct random_data *__restrict __buf) __attribute__ ((__nothrow__ )) __attribute__ ((__nonnull__ (1, 2))); extern int rand (void) __attribute__ ((__nothrow__ )); extern void srand (unsigned int __seed) __attribute__ ((__nothrow__ )); extern int rand_r (unsigned int *__seed) __attribute__ ((__nothrow__ )); extern double drand48 (void) __attribute__ ((__nothrow__ )); extern double erand48 (unsigned short int __xsubi[3]) __attribute__ ((__nothrow__ )) __attribute__ ((__nonnull__ (1))); extern long int lrand48 (void) __attribute__ ((__nothrow__ )); extern long int nrand48 (unsigned short int __xsubi[3]) __attribute__ ((__nothrow__ )) __attribute__ ((__nonnull__ (1))); extern long int mrand48 (void) __attribute__ ((__nothrow__ )); extern long int jrand48 (unsigned short int __xsubi[3]) __attribute__ ((__nothrow__ )) __attribute__ ((__nonnull__ (1))); extern void srand48 (long int __seedval) __attribute__ ((__nothrow__ )); extern unsigned short int *seed48 (unsigned short int __seed16v[3]) __attribute__ ((__nothrow__ )) __attribute__ ((__nonnull__ (1))); extern void lcong48 (unsigned short int __param[7]) __attribute__ ((__nothrow__ )) __attribute__ ((__nonnull__ (1))); struct drand48_data { unsigned short int __x[3]; unsigned short int __old_x[3]; unsigned short int __c; unsigned short int __init; __extension__ unsigned long long int __a; }; extern int drand48_r (struct drand48_data *__restrict __buffer, double *__restrict __result) __attribute__ ((__nothrow__ )) __attribute__ ((__nonnull__ (1, 2))); extern int erand48_r (unsigned short int __xsubi[3], struct drand48_data *__restrict __buffer, double *__restrict __result) __attribute__ ((__nothrow__ )) __attribute__ ((__nonnull__ (1, 2))); extern int lrand48_r (struct drand48_data *__restrict __buffer, long int *__restrict __result) __attribute__ ((__nothrow__ )) __attribute__ ((__nonnull__ (1, 2))); extern int nrand48_r (unsigned short int __xsubi[3], struct drand48_data *__restrict __buffer, long int *__restrict __result) __attribute__ ((__nothrow__ )) __attribute__ ((__nonnull__ (1, 2))); extern int mrand48_r (struct drand48_data *__restrict __buffer, long int *__restrict __result) __attribute__ ((__nothrow__ )) __attribute__ ((__nonnull__ (1, 2))); extern int jrand48_r (unsigned short int __xsubi[3], struct drand48_data *__restrict __buffer, long int *__restrict __result) __attribute__ ((__nothrow__ )) __attribute__ ((__nonnull__ (1, 2))); extern int srand48_r (long int __seedval, struct drand48_data *__buffer) __attribute__ ((__nothrow__ )) __attribute__ ((__nonnull__ (2))); extern int seed48_r (unsigned short int __seed16v[3], struct drand48_data *__buffer) __attribute__ ((__nothrow__ )) __attribute__ ((__nonnull__ (1, 2))); extern int lcong48_r (unsigned short int __param[7], struct drand48_data *__buffer) __attribute__ ((__nothrow__ )) __attribute__ ((__nonnull__ (1, 2))); # 466 "/usr/include/stdlib.h" 3 4 extern void *malloc (size_t __size) __attribute__ ((__nothrow__ )) __attribute__ ((__malloc__)) ; extern void *calloc (size_t __nmemb, size_t __size) __attribute__ ((__nothrow__ )) __attribute__ ((__malloc__)) ; # 480 "/usr/include/stdlib.h" 3 4 extern void *realloc (void *__ptr, size_t __size) __attribute__ ((__nothrow__ )) __attribute__ ((__warn_unused_result__)); extern void free (void *__ptr) __attribute__ ((__nothrow__ )); extern void cfree (void *__ptr) __attribute__ ((__nothrow__ )); # 1 "/usr/include/alloca.h" 1 3 4 # 24 "/usr/include/alloca.h" 3 4 # 1 "/home/nader/llvm-omp/lib/clang/5.0.1/include/stddef.h" 1 3 4 # 25 "/usr/include/alloca.h" 2 3 4 extern void *alloca (size_t __size) __attribute__ ((__nothrow__ )); # 493 "/usr/include/stdlib.h" 2 3 4 extern void *valloc (size_t __size) __attribute__ ((__nothrow__ )) __attribute__ ((__malloc__)) ; extern int posix_memalign (void **__memptr, size_t __alignment, size_t __size) __attribute__ ((__nothrow__ )) __attribute__ ((__nonnull__ (1))) ; extern void *aligned_alloc (size_t __alignment, size_t __size) __attribute__ ((__nothrow__ )) __attribute__ ((__malloc__)) ; extern void abort (void) __attribute__ ((__nothrow__ )) __attribute__ ((__noreturn__)); extern int atexit (void (*__func) (void)) __attribute__ ((__nothrow__ )) __attribute__ ((__nonnull__ (1))); extern int at_quick_exit (void (*__func) (void)) __attribute__ ((__nothrow__ )) __attribute__ ((__nonnull__ (1))); extern int on_exit (void (*__func) (int __status, void *__arg), void *__arg) __attribute__ ((__nothrow__ )) __attribute__ ((__nonnull__ (1))); extern void exit (int __status) __attribute__ ((__nothrow__ )) __attribute__ ((__noreturn__)); extern void quick_exit (int __status) __attribute__ ((__nothrow__ )) __attribute__ ((__noreturn__)); extern void _Exit (int __status) __attribute__ ((__nothrow__ )) __attribute__ ((__noreturn__)); extern char *getenv (const char *__name) __attribute__ ((__nothrow__ )) __attribute__ ((__nonnull__ (1))) ; # 578 "/usr/include/stdlib.h" 3 4 extern int putenv (char *__string) __attribute__ ((__nothrow__ )) __attribute__ ((__nonnull__ (1))); extern int setenv (const char *__name, const char *__value, int __replace) __attribute__ ((__nothrow__ )) __attribute__ ((__nonnull__ (2))); extern int unsetenv (const char *__name) __attribute__ ((__nothrow__ )) __attribute__ ((__nonnull__ (1))); extern int clearenv (void) __attribute__ ((__nothrow__ )); # 606 "/usr/include/stdlib.h" 3 4 extern char *mktemp (char *__template) __attribute__ ((__nothrow__ )) __attribute__ ((__nonnull__ (1))); # 619 "/usr/include/stdlib.h" 3 4 extern int mkstemp (char *__template) __attribute__ ((__nonnull__ (1))) ; # 641 "/usr/include/stdlib.h" 3 4 extern int mkstemps (char *__template, int __suffixlen) __attribute__ ((__nonnull__ (1))) ; # 662 "/usr/include/stdlib.h" 3 4 extern char *mkdtemp (char *__template) __attribute__ ((__nothrow__ )) __attribute__ ((__nonnull__ (1))) ; # 716 "/usr/include/stdlib.h" 3 4 extern int system (const char *__command) ; # 733 "/usr/include/stdlib.h" 3 4 extern char *realpath (const char *__restrict __name, char *__restrict __resolved) __attribute__ ((__nothrow__ )) ; typedef int (*__compar_fn_t) (const void *, const void *); # 754 "/usr/include/stdlib.h" 3 4 extern void *bsearch (const void *__key, const void *__base, size_t __nmemb, size_t __size, __compar_fn_t __compar) __attribute__ ((__nonnull__ (1, 2, 5))) ; # 1 "/usr/include/x86_64-linux-gnu/bits/stdlib-bsearch.h" 1 3 4 # 19 "/usr/include/x86_64-linux-gnu/bits/stdlib-bsearch.h" 3 4 extern __inline __attribute__ ((__gnu_inline__)) void * bsearch (const void *__key, const void *__base, size_t __nmemb, size_t __size, __compar_fn_t __compar) { size_t __l, __u, __idx; const void *__p; int __comparison; __l = 0; __u = __nmemb; while (__l < __u) { __idx = (__l + __u) / 2; __p = (void *) (((const char *) __base) + (__idx * __size)); __comparison = (*__compar) (__key, __p); if (__comparison < 0) __u = __idx; else if (__comparison > 0) __l = __idx + 1; else return (void *) __p; } return ((void*)0); } # 760 "/usr/include/stdlib.h" 2 3 4 extern void qsort (void *__base, size_t __nmemb, size_t __size, __compar_fn_t __compar) __attribute__ ((__nonnull__ (1, 4))); # 774 "/usr/include/stdlib.h" 3 4 extern int abs (int __x) __attribute__ ((__nothrow__ )) __attribute__ ((__const__)) ; extern long int labs (long int __x) __attribute__ ((__nothrow__ )) __attribute__ ((__const__)) ; __extension__ extern long long int llabs (long long int __x) __attribute__ ((__nothrow__ )) __attribute__ ((__const__)) ; extern div_t div (int __numer, int __denom) __attribute__ ((__nothrow__ )) __attribute__ ((__const__)) ; extern ldiv_t ldiv (long int __numer, long int __denom) __attribute__ ((__nothrow__ )) __attribute__ ((__const__)) ; __extension__ extern lldiv_t lldiv (long long int __numer, long long int __denom) __attribute__ ((__nothrow__ )) __attribute__ ((__const__)) ; # 811 "/usr/include/stdlib.h" 3 4 extern char *ecvt (double __value, int __ndigit, int *__restrict __decpt, int *__restrict __sign) __attribute__ ((__nothrow__ )) __attribute__ ((__nonnull__ (3, 4))) ; extern char *fcvt (double __value, int __ndigit, int *__restrict __decpt, int *__restrict __sign) __attribute__ ((__nothrow__ )) __attribute__ ((__nonnull__ (3, 4))) ; extern char *gcvt (double __value, int __ndigit, char *__buf) __attribute__ ((__nothrow__ )) __attribute__ ((__nonnull__ (3))) ; extern char *qecvt (long double __value, int __ndigit, int *__restrict __decpt, int *__restrict __sign) __attribute__ ((__nothrow__ )) __attribute__ ((__nonnull__ (3, 4))) ; extern char *qfcvt (long double __value, int __ndigit, int *__restrict __decpt, int *__restrict __sign) __attribute__ ((__nothrow__ )) __attribute__ ((__nonnull__ (3, 4))) ; extern char *qgcvt (long double __value, int __ndigit, char *__buf) __attribute__ ((__nothrow__ )) __attribute__ ((__nonnull__ (3))) ; extern int ecvt_r (double __value, int __ndigit, int *__restrict __decpt, int *__restrict __sign, char *__restrict __buf, size_t __len) __attribute__ ((__nothrow__ )) __attribute__ ((__nonnull__ (3, 4, 5))); extern int fcvt_r (double __value, int __ndigit, int *__restrict __decpt, int *__restrict __sign, char *__restrict __buf, size_t __len) __attribute__ ((__nothrow__ )) __attribute__ ((__nonnull__ (3, 4, 5))); extern int qecvt_r (long double __value, int __ndigit, int *__restrict __decpt, int *__restrict __sign, char *__restrict __buf, size_t __len) __attribute__ ((__nothrow__ )) __attribute__ ((__nonnull__ (3, 4, 5))); extern int qfcvt_r (long double __value, int __ndigit, int *__restrict __decpt, int *__restrict __sign, char *__restrict __buf, size_t __len) __attribute__ ((__nothrow__ )) __attribute__ ((__nonnull__ (3, 4, 5))); extern int mblen (const char *__s, size_t __n) __attribute__ ((__nothrow__ )); extern int mbtowc (wchar_t *__restrict __pwc, const char *__restrict __s, size_t __n) __attribute__ ((__nothrow__ )); extern int wctomb (char *__s, wchar_t __wchar) __attribute__ ((__nothrow__ )); extern size_t mbstowcs (wchar_t *__restrict __pwcs, const char *__restrict __s, size_t __n) __attribute__ ((__nothrow__ )); extern size_t wcstombs (char *__restrict __s, const wchar_t *__restrict __pwcs, size_t __n) __attribute__ ((__nothrow__ )); # 887 "/usr/include/stdlib.h" 3 4 extern int rpmatch (const char *__response) __attribute__ ((__nothrow__ )) __attribute__ ((__nonnull__ (1))) ; # 898 "/usr/include/stdlib.h" 3 4 extern int getsubopt (char **__restrict __optionp, char *const *__restrict __tokens, char **__restrict __valuep) __attribute__ ((__nothrow__ )) __attribute__ ((__nonnull__ (1, 2, 3))) ; # 950 "/usr/include/stdlib.h" 3 4 extern int getloadavg (double __loadavg[], int __nelem) __attribute__ ((__nothrow__ )) __attribute__ ((__nonnull__ (1))); # 1 "/usr/include/x86_64-linux-gnu/bits/stdlib-float.h" 1 3 4 # 25 "/usr/include/x86_64-linux-gnu/bits/stdlib-float.h" 3 4 extern __inline __attribute__ ((__gnu_inline__)) double __attribute__ ((__nothrow__ )) atof (const char *__nptr) { return strtod (__nptr, (char **) ((void*)0)); } # 955 "/usr/include/stdlib.h" 2 3 4 # 29 "nqueens.c" 2 # 1 "/usr/include/stdio.h" 1 3 4 # 33 "/usr/include/stdio.h" 3 4 # 1 "/home/nader/llvm-omp/lib/clang/5.0.1/include/stddef.h" 1 3 4 # 34 "/usr/include/stdio.h" 2 3 4 # 44 "/usr/include/stdio.h" 3 4 struct _IO_FILE; typedef struct _IO_FILE FILE; # 64 "/usr/include/stdio.h" 3 4 typedef struct _IO_FILE __FILE; # 74 "/usr/include/stdio.h" 3 4 # 1 "/usr/include/libio.h" 1 3 4 # 31 "/usr/include/libio.h" 3 4 # 1 "/usr/include/_G_config.h" 1 3 4 # 15 "/usr/include/_G_config.h" 3 4 # 1 "/home/nader/llvm-omp/lib/clang/5.0.1/include/stddef.h" 1 3 4 # 16 "/usr/include/_G_config.h" 2 3 4 # 1 "/usr/include/wchar.h" 1 3 4 # 82 "/usr/include/wchar.h" 3 4 typedef struct { int __count; union { unsigned int __wch; char __wchb[4]; } __value; } __mbstate_t; # 21 "/usr/include/_G_config.h" 2 3 4 typedef struct { __off_t __pos; __mbstate_t __state; } _G_fpos_t; typedef struct { __off64_t __pos; __mbstate_t __state; } _G_fpos64_t; # 32 "/usr/include/libio.h" 2 3 4 # 49 "/usr/include/libio.h" 3 4 # 1 "/home/nader/llvm-omp/lib/clang/5.0.1/include/stdarg.h" 1 3 4 # 30 "/home/nader/llvm-omp/lib/clang/5.0.1/include/stdarg.h" 3 4 typedef __builtin_va_list va_list; # 48 "/home/nader/llvm-omp/lib/clang/5.0.1/include/stdarg.h" 3 4 typedef __builtin_va_list __gnuc_va_list; # 50 "/usr/include/libio.h" 2 3 4 # 144 "/usr/include/libio.h" 3 4 struct _IO_jump_t; struct _IO_FILE; typedef void _IO_lock_t; struct _IO_marker { struct _IO_marker *_next; struct _IO_FILE *_sbuf; int _pos; # 173 "/usr/include/libio.h" 3 4 }; enum __codecvt_result { __codecvt_ok, __codecvt_partial, __codecvt_error, __codecvt_noconv }; # 241 "/usr/include/libio.h" 3 4 struct _IO_FILE { int _flags; char* _IO_read_ptr; char* _IO_read_end; char* _IO_read_base; char* _IO_write_base; char* _IO_write_ptr; char* _IO_write_end; char* _IO_buf_base; char* _IO_buf_end; char *_IO_save_base; char *_IO_backup_base; char *_IO_save_end; struct _IO_marker *_markers; struct _IO_FILE *_chain; int _fileno; int _flags2; __off_t _old_offset; unsigned short _cur_column; signed char _vtable_offset; char _shortbuf[1]; _IO_lock_t *_lock; # 289 "/usr/include/libio.h" 3 4 __off64_t _offset; void *__pad1; void *__pad2; void *__pad3; void *__pad4; size_t __pad5; int _mode; char _unused2[15 * sizeof (int) - 4 * sizeof (void *) - sizeof (size_t)]; }; typedef struct _IO_FILE _IO_FILE; struct _IO_FILE_plus; extern struct _IO_FILE_plus _IO_2_1_stdin_; extern struct _IO_FILE_plus _IO_2_1_stdout_; extern struct _IO_FILE_plus _IO_2_1_stderr_; # 333 "/usr/include/libio.h" 3 4 typedef __ssize_t __io_read_fn (void *__cookie, char *__buf, size_t __nbytes); typedef __ssize_t __io_write_fn (void *__cookie, const char *__buf, size_t __n); typedef int __io_seek_fn (void *__cookie, __off64_t *__pos, int __w); typedef int __io_close_fn (void *__cookie); # 385 "/usr/include/libio.h" 3 4 extern int __underflow (_IO_FILE *); extern int __uflow (_IO_FILE *); extern int __overflow (_IO_FILE *, int); # 429 "/usr/include/libio.h" 3 4 extern int _IO_getc (_IO_FILE *__fp); extern int _IO_putc (int __c, _IO_FILE *__fp); extern int _IO_feof (_IO_FILE *__fp) __attribute__ ((__nothrow__ )); extern int _IO_ferror (_IO_FILE *__fp) __attribute__ ((__nothrow__ )); extern int _IO_peekc_locked (_IO_FILE *__fp); extern void _IO_flockfile (_IO_FILE *) __attribute__ ((__nothrow__ )); extern void _IO_funlockfile (_IO_FILE *) __attribute__ ((__nothrow__ )); extern int _IO_ftrylockfile (_IO_FILE *) __attribute__ ((__nothrow__ )); # 459 "/usr/include/libio.h" 3 4 extern int _IO_vfscanf (_IO_FILE * __restrict, const char * __restrict, __gnuc_va_list, int *__restrict); extern int _IO_vfprintf (_IO_FILE *__restrict, const char *__restrict, __gnuc_va_list); extern __ssize_t _IO_padn (_IO_FILE *, int, __ssize_t); extern size_t _IO_sgetn (_IO_FILE *, void *, size_t); extern __off64_t _IO_seekoff (_IO_FILE *, __off64_t, int, int); extern __off64_t _IO_seekpos (_IO_FILE *, __off64_t, int); extern void _IO_free_backup_area (_IO_FILE *) __attribute__ ((__nothrow__ )); # 75 "/usr/include/stdio.h" 2 3 4 typedef __gnuc_va_list va_list; # 110 "/usr/include/stdio.h" 3 4 typedef _G_fpos_t fpos_t; # 164 "/usr/include/stdio.h" 3 4 # 1 "/usr/include/x86_64-linux-gnu/bits/stdio_lim.h" 1 3 4 # 165 "/usr/include/stdio.h" 2 3 4 extern struct _IO_FILE *stdin; extern struct _IO_FILE *stdout; extern struct _IO_FILE *stderr; extern int remove (const char *__filename) __attribute__ ((__nothrow__ )); extern int rename (const char *__old, const char *__new) __attribute__ ((__nothrow__ )); extern int renameat (int __oldfd, const char *__old, int __newfd, const char *__new) __attribute__ ((__nothrow__ )); # 195 "/usr/include/stdio.h" 3 4 extern FILE *tmpfile (void) ; # 209 "/usr/include/stdio.h" 3 4 extern char *tmpnam (char *__s) __attribute__ ((__nothrow__ )) ; extern char *tmpnam_r (char *__s) __attribute__ ((__nothrow__ )) ; # 227 "/usr/include/stdio.h" 3 4 extern char *tempnam (const char *__dir, const char *__pfx) __attribute__ ((__nothrow__ )) __attribute__ ((__malloc__)) ; # 237 "/usr/include/stdio.h" 3 4 extern int fclose (FILE *__stream); extern int fflush (FILE *__stream); # 252 "/usr/include/stdio.h" 3 4 extern int fflush_unlocked (FILE *__stream); # 272 "/usr/include/stdio.h" 3 4 extern FILE *fopen (const char *__restrict __filename, const char *__restrict __modes) ; extern FILE *freopen (const char *__restrict __filename, const char *__restrict __modes, FILE *__restrict __stream) ; # 306 "/usr/include/stdio.h" 3 4 extern FILE *fdopen (int __fd, const char *__modes) __attribute__ ((__nothrow__ )) ; # 319 "/usr/include/stdio.h" 3 4 extern FILE *fmemopen (void *__s, size_t __len, const char *__modes) __attribute__ ((__nothrow__ )) ; extern FILE *open_memstream (char **__bufloc, size_t *__sizeloc) __attribute__ ((__nothrow__ )) ; extern void setbuf (FILE *__restrict __stream, char *__restrict __buf) __attribute__ ((__nothrow__ )); extern int setvbuf (FILE *__restrict __stream, char *__restrict __buf, int __modes, size_t __n) __attribute__ ((__nothrow__ )); extern void setbuffer (FILE *__restrict __stream, char *__restrict __buf, size_t __size) __attribute__ ((__nothrow__ )); extern void setlinebuf (FILE *__stream) __attribute__ ((__nothrow__ )); # 356 "/usr/include/stdio.h" 3 4 extern int fprintf (FILE *__restrict __stream, const char *__restrict __format, ...); extern int printf (const char *__restrict __format, ...); extern int sprintf (char *__restrict __s, const char *__restrict __format, ...) __attribute__ ((__nothrow__)); extern int vfprintf (FILE *__restrict __s, const char *__restrict __format, __gnuc_va_list __arg); extern int vprintf (const char *__restrict __format, __gnuc_va_list __arg); extern int vsprintf (char *__restrict __s, const char *__restrict __format, __gnuc_va_list __arg) __attribute__ ((__nothrow__)); extern int snprintf (char *__restrict __s, size_t __maxlen, const char *__restrict __format, ...) __attribute__ ((__nothrow__)) __attribute__ ((__format__ (__printf__, 3, 4))); extern int vsnprintf (char *__restrict __s, size_t __maxlen, const char *__restrict __format, __gnuc_va_list __arg) __attribute__ ((__nothrow__)) __attribute__ ((__format__ (__printf__, 3, 0))); # 412 "/usr/include/stdio.h" 3 4 extern int vdprintf (int __fd, const char *__restrict __fmt, __gnuc_va_list __arg) __attribute__ ((__format__ (__printf__, 2, 0))); extern int dprintf (int __fd, const char *__restrict __fmt, ...) __attribute__ ((__format__ (__printf__, 2, 3))); # 425 "/usr/include/stdio.h" 3 4 extern int fscanf (FILE *__restrict __stream, const char *__restrict __format, ...) ; extern int scanf (const char *__restrict __format, ...) ; extern int sscanf (const char *__restrict __s, const char *__restrict __format, ...) __attribute__ ((__nothrow__ )); # 443 "/usr/include/stdio.h" 3 4 extern int fscanf (FILE *__restrict __stream, const char *__restrict __format, ...) __asm__ ("" "__isoc99_fscanf") ; extern int scanf (const char *__restrict __format, ...) __asm__ ("" "__isoc99_scanf") ; extern int sscanf (const char *__restrict __s, const char *__restrict __format, ...) __asm__ ("" "__isoc99_sscanf") __attribute__ ((__nothrow__ )); # 471 "/usr/include/stdio.h" 3 4 extern int vfscanf (FILE *__restrict __s, const char *__restrict __format, __gnuc_va_list __arg) __attribute__ ((__format__ (__scanf__, 2, 0))) ; extern int vscanf (const char *__restrict __format, __gnuc_va_list __arg) __attribute__ ((__format__ (__scanf__, 1, 0))) ; extern int vsscanf (const char *__restrict __s, const char *__restrict __format, __gnuc_va_list __arg) __attribute__ ((__nothrow__ )) __attribute__ ((__format__ (__scanf__, 2, 0))); # 494 "/usr/include/stdio.h" 3 4 extern int vfscanf (FILE *__restrict __s, const char *__restrict __format, __gnuc_va_list __arg) __asm__ ("" "__isoc99_vfscanf") __attribute__ ((__format__ (__scanf__, 2, 0))) ; extern int vscanf (const char *__restrict __format, __gnuc_va_list __arg) __asm__ ("" "__isoc99_vscanf") __attribute__ ((__format__ (__scanf__, 1, 0))) ; extern int vsscanf (const char *__restrict __s, const char *__restrict __format, __gnuc_va_list __arg) __asm__ ("" "__isoc99_vsscanf") __attribute__ ((__nothrow__ )) __attribute__ ((__format__ (__scanf__, 2, 0))); # 531 "/usr/include/stdio.h" 3 4 extern int fgetc (FILE *__stream); extern int getc (FILE *__stream); extern int getchar (void); # 550 "/usr/include/stdio.h" 3 4 extern int getc_unlocked (FILE *__stream); extern int getchar_unlocked (void); # 561 "/usr/include/stdio.h" 3 4 extern int fgetc_unlocked (FILE *__stream); # 573 "/usr/include/stdio.h" 3 4 extern int fputc (int __c, FILE *__stream); extern int putc (int __c, FILE *__stream); extern int putchar (int __c); # 594 "/usr/include/stdio.h" 3 4 extern int fputc_unlocked (int __c, FILE *__stream); extern int putc_unlocked (int __c, FILE *__stream); extern int putchar_unlocked (int __c); extern int getw (FILE *__stream); extern int putw (int __w, FILE *__stream); # 622 "/usr/include/stdio.h" 3 4 extern char *fgets (char *__restrict __s, int __n, FILE *__restrict __stream) ; # 665 "/usr/include/stdio.h" 3 4 extern __ssize_t __getdelim (char **__restrict __lineptr, size_t *__restrict __n, int __delimiter, FILE *__restrict __stream) ; extern __ssize_t getdelim (char **__restrict __lineptr, size_t *__restrict __n, int __delimiter, FILE *__restrict __stream) ; extern __ssize_t getline (char **__restrict __lineptr, size_t *__restrict __n, FILE *__restrict __stream) ; # 689 "/usr/include/stdio.h" 3 4 extern int fputs (const char *__restrict __s, FILE *__restrict __stream); extern int puts (const char *__s); extern int ungetc (int __c, FILE *__stream); extern size_t fread (void *__restrict __ptr, size_t __size, size_t __n, FILE *__restrict __stream) ; extern size_t fwrite (const void *__restrict __ptr, size_t __size, size_t __n, FILE *__restrict __s); # 737 "/usr/include/stdio.h" 3 4 extern size_t fread_unlocked (void *__restrict __ptr, size_t __size, size_t __n, FILE *__restrict __stream) ; extern size_t fwrite_unlocked (const void *__restrict __ptr, size_t __size, size_t __n, FILE *__restrict __stream); # 749 "/usr/include/stdio.h" 3 4 extern int fseek (FILE *__stream, long int __off, int __whence); extern long int ftell (FILE *__stream) ; extern void rewind (FILE *__stream); # 773 "/usr/include/stdio.h" 3 4 extern int fseeko (FILE *__stream, __off_t __off, int __whence); extern __off_t ftello (FILE *__stream) ; # 798 "/usr/include/stdio.h" 3 4 extern int fgetpos (FILE *__restrict __stream, fpos_t *__restrict __pos); extern int fsetpos (FILE *__stream, const fpos_t *__pos); # 826 "/usr/include/stdio.h" 3 4 extern void clearerr (FILE *__stream) __attribute__ ((__nothrow__ )); extern int feof (FILE *__stream) __attribute__ ((__nothrow__ )) ; extern int ferror (FILE *__stream) __attribute__ ((__nothrow__ )) ; extern void clearerr_unlocked (FILE *__stream) __attribute__ ((__nothrow__ )); extern int feof_unlocked (FILE *__stream) __attribute__ ((__nothrow__ )) ; extern int ferror_unlocked (FILE *__stream) __attribute__ ((__nothrow__ )) ; # 846 "/usr/include/stdio.h" 3 4 extern void perror (const char *__s); # 1 "/usr/include/x86_64-linux-gnu/bits/sys_errlist.h" 1 3 4 # 26 "/usr/include/x86_64-linux-gnu/bits/sys_errlist.h" 3 4 extern int sys_nerr; extern const char *const sys_errlist[]; # 854 "/usr/include/stdio.h" 2 3 4 extern int fileno (FILE *__stream) __attribute__ ((__nothrow__ )) ; extern int fileno_unlocked (FILE *__stream) __attribute__ ((__nothrow__ )) ; # 872 "/usr/include/stdio.h" 3 4 extern FILE *popen (const char *__command, const char *__modes) ; extern int pclose (FILE *__stream); extern char *ctermid (char *__s) __attribute__ ((__nothrow__ )); # 912 "/usr/include/stdio.h" 3 4 extern void flockfile (FILE *__stream) __attribute__ ((__nothrow__ )); extern int ftrylockfile (FILE *__stream) __attribute__ ((__nothrow__ )) ; extern void funlockfile (FILE *__stream) __attribute__ ((__nothrow__ )); # 933 "/usr/include/stdio.h" 3 4 # 1 "/usr/include/x86_64-linux-gnu/bits/stdio.h" 1 3 4 # 35 "/usr/include/x86_64-linux-gnu/bits/stdio.h" 3 4 extern __inline __attribute__ ((__gnu_inline__)) int vprintf (const char *__restrict __fmt, __gnuc_va_list __arg) { return vfprintf (stdout, __fmt, __arg); } extern __inline __attribute__ ((__gnu_inline__)) int getchar (void) { return _IO_getc (stdin); } extern __inline __attribute__ ((__gnu_inline__)) int fgetc_unlocked (FILE *__fp) { return (__builtin_expect (((__fp)->_IO_read_ptr >= (__fp)->_IO_read_end), 0) ? __uflow (__fp) : *(unsigned char *) (__fp)->_IO_read_ptr++); } extern __inline __attribute__ ((__gnu_inline__)) int getc_unlocked (FILE *__fp) { return (__builtin_expect (((__fp)->_IO_read_ptr >= (__fp)->_IO_read_end), 0) ? __uflow (__fp) : *(unsigned char *) (__fp)->_IO_read_ptr++); } extern __inline __attribute__ ((__gnu_inline__)) int getchar_unlocked (void) { return (__builtin_expect (((stdin)->_IO_read_ptr >= (stdin)->_IO_read_end), 0) ? __uflow (stdin) : *(unsigned char *) (stdin)->_IO_read_ptr++); } extern __inline __attribute__ ((__gnu_inline__)) int putchar (int __c) { return _IO_putc (__c, stdout); } extern __inline __attribute__ ((__gnu_inline__)) int fputc_unlocked (int __c, FILE *__stream) { return (__builtin_expect (((__stream)->_IO_write_ptr >= (__stream)->_IO_write_end), 0) ? __overflow (__stream, (unsigned char) (__c)) : (unsigned char) (*(__stream)->_IO_write_ptr++ = (__c))); } extern __inline __attribute__ ((__gnu_inline__)) int putc_unlocked (int __c, FILE *__stream) { return (__builtin_expect (((__stream)->_IO_write_ptr >= (__stream)->_IO_write_end), 0) ? __overflow (__stream, (unsigned char) (__c)) : (unsigned char) (*(__stream)->_IO_write_ptr++ = (__c))); } extern __inline __attribute__ ((__gnu_inline__)) int putchar_unlocked (int __c) { return (__builtin_expect (((stdout)->_IO_write_ptr >= (stdout)->_IO_write_end), 0) ? __overflow (stdout, (unsigned char) (__c)) : (unsigned char) (*(stdout)->_IO_write_ptr++ = (__c))); } # 124 "/usr/include/x86_64-linux-gnu/bits/stdio.h" 3 4 extern __inline __attribute__ ((__gnu_inline__)) int __attribute__ ((__nothrow__ )) feof_unlocked (FILE *__stream) { return (((__stream)->_flags & 0x10) != 0); } extern __inline __attribute__ ((__gnu_inline__)) int __attribute__ ((__nothrow__ )) ferror_unlocked (FILE *__stream) { return (((__stream)->_flags & 0x20) != 0); } # 934 "/usr/include/stdio.h" 2 3 4 # 30 "nqueens.c" 2 # 1 "/usr/include/memory.h" 1 3 4 # 29 "/usr/include/memory.h" 3 4 # 1 "/usr/include/string.h" 1 3 4 # 32 "/usr/include/string.h" 3 4 # 1 "/home/nader/llvm-omp/lib/clang/5.0.1/include/stddef.h" 1 3 4 # 33 "/usr/include/string.h" 2 3 4 # 42 "/usr/include/string.h" 3 4 extern void *memcpy (void *__restrict __dest, const void *__restrict __src, size_t __n) __attribute__ ((__nothrow__ )) __attribute__ ((__nonnull__ (1, 2))); extern void *memmove (void *__dest, const void *__src, size_t __n) __attribute__ ((__nothrow__ )) __attribute__ ((__nonnull__ (1, 2))); extern void *memccpy (void *__restrict __dest, const void *__restrict __src, int __c, size_t __n) __attribute__ ((__nothrow__ )) __attribute__ ((__nonnull__ (1, 2))); extern void *memset (void *__s, int __c, size_t __n) __attribute__ ((__nothrow__ )) __attribute__ ((__nonnull__ (1))); extern int memcmp (const void *__s1, const void *__s2, size_t __n) __attribute__ ((__nothrow__ )) __attribute__ ((__pure__)) __attribute__ ((__nonnull__ (1, 2))); # 92 "/usr/include/string.h" 3 4 extern void *memchr (const void *__s, int __c, size_t __n) __attribute__ ((__nothrow__ )) __attribute__ ((__pure__)) __attribute__ ((__nonnull__ (1))); # 125 "/usr/include/string.h" 3 4 extern char *strcpy (char *__restrict __dest, const char *__restrict __src) __attribute__ ((__nothrow__ )) __attribute__ ((__nonnull__ (1, 2))); extern char *strncpy (char *__restrict __dest, const char *__restrict __src, size_t __n) __attribute__ ((__nothrow__ )) __attribute__ ((__nonnull__ (1, 2))); extern char *strcat (char *__restrict __dest, const char *__restrict __src) __attribute__ ((__nothrow__ )) __attribute__ ((__nonnull__ (1, 2))); extern char *strncat (char *__restrict __dest, const char *__restrict __src, size_t __n) __attribute__ ((__nothrow__ )) __attribute__ ((__nonnull__ (1, 2))); extern int strcmp (const char *__s1, const char *__s2) __attribute__ ((__nothrow__ )) __attribute__ ((__pure__)) __attribute__ ((__nonnull__ (1, 2))); extern int strncmp (const char *__s1, const char *__s2, size_t __n) __attribute__ ((__nothrow__ )) __attribute__ ((__pure__)) __attribute__ ((__nonnull__ (1, 2))); extern int strcoll (const char *__s1, const char *__s2) __attribute__ ((__nothrow__ )) __attribute__ ((__pure__)) __attribute__ ((__nonnull__ (1, 2))); extern size_t strxfrm (char *__restrict __dest, const char *__restrict __src, size_t __n) __attribute__ ((__nothrow__ )) __attribute__ ((__nonnull__ (2))); # 1 "/usr/include/xlocale.h" 1 3 4 # 27 "/usr/include/xlocale.h" 3 4 typedef struct __locale_struct { struct __locale_data *__locales[13]; const unsigned short int *__ctype_b; const int *__ctype_tolower; const int *__ctype_toupper; const char *__names[13]; } *__locale_t; typedef __locale_t locale_t; # 160 "/usr/include/string.h" 2 3 4 extern int strcoll_l (const char *__s1, const char *__s2, __locale_t __l) __attribute__ ((__nothrow__ )) __attribute__ ((__pure__)) __attribute__ ((__nonnull__ (1, 2, 3))); extern size_t strxfrm_l (char *__dest, const char *__src, size_t __n, __locale_t __l) __attribute__ ((__nothrow__ )) __attribute__ ((__nonnull__ (2, 4))); extern char *strdup (const char *__s) __attribute__ ((__nothrow__ )) __attribute__ ((__malloc__)) __attribute__ ((__nonnull__ (1))); extern char *strndup (const char *__string, size_t __n) __attribute__ ((__nothrow__ )) __attribute__ ((__malloc__)) __attribute__ ((__nonnull__ (1))); # 231 "/usr/include/string.h" 3 4 extern char *strchr (const char *__s, int __c) __attribute__ ((__nothrow__ )) __attribute__ ((__pure__)) __attribute__ ((__nonnull__ (1))); # 258 "/usr/include/string.h" 3 4 extern char *strrchr (const char *__s, int __c) __attribute__ ((__nothrow__ )) __attribute__ ((__pure__)) __attribute__ ((__nonnull__ (1))); # 280 "/usr/include/string.h" 3 4 extern size_t strcspn (const char *__s, const char *__reject) __attribute__ ((__nothrow__ )) __attribute__ ((__pure__)) __attribute__ ((__nonnull__ (1, 2))); extern size_t strspn (const char *__s, const char *__accept) __attribute__ ((__nothrow__ )) __attribute__ ((__pure__)) __attribute__ ((__nonnull__ (1, 2))); # 310 "/usr/include/string.h" 3 4 extern char *strpbrk (const char *__s, const char *__accept) __attribute__ ((__nothrow__ )) __attribute__ ((__pure__)) __attribute__ ((__nonnull__ (1, 2))); # 337 "/usr/include/string.h" 3 4 extern char *strstr (const char *__haystack, const char *__needle) __attribute__ ((__nothrow__ )) __attribute__ ((__pure__)) __attribute__ ((__nonnull__ (1, 2))); extern char *strtok (char *__restrict __s, const char *__restrict __delim) __attribute__ ((__nothrow__ )) __attribute__ ((__nonnull__ (2))); extern char *__strtok_r (char *__restrict __s, const char *__restrict __delim, char **__restrict __save_ptr) __attribute__ ((__nothrow__ )) __attribute__ ((__nonnull__ (2, 3))); extern char *strtok_r (char *__restrict __s, const char *__restrict __delim, char **__restrict __save_ptr) __attribute__ ((__nothrow__ )) __attribute__ ((__nonnull__ (2, 3))); # 394 "/usr/include/string.h" 3 4 extern size_t strlen (const char *__s) __attribute__ ((__nothrow__ )) __attribute__ ((__pure__)) __attribute__ ((__nonnull__ (1))); extern size_t strnlen (const char *__string, size_t __maxlen) __attribute__ ((__nothrow__ )) __attribute__ ((__pure__)) __attribute__ ((__nonnull__ (1))); extern char *strerror (int __errnum) __attribute__ ((__nothrow__ )); # 422 "/usr/include/string.h" 3 4 extern int strerror_r (int __errnum, char *__buf, size_t __buflen) __asm__ ("" "__xpg_strerror_r") __attribute__ ((__nothrow__ )) __attribute__ ((__nonnull__ (2))); # 440 "/usr/include/string.h" 3 4 extern char *strerror_l (int __errnum, __locale_t __l) __attribute__ ((__nothrow__ )); extern void __bzero (void *__s, size_t __n) __attribute__ ((__nothrow__ )) __attribute__ ((__nonnull__ (1))); extern void bcopy (const void *__src, void *__dest, size_t __n) __attribute__ ((__nothrow__ )) __attribute__ ((__nonnull__ (1, 2))); extern void bzero (void *__s, size_t __n) __attribute__ ((__nothrow__ )) __attribute__ ((__nonnull__ (1))); extern int bcmp (const void *__s1, const void *__s2, size_t __n) __attribute__ ((__nothrow__ )) __attribute__ ((__pure__)) __attribute__ ((__nonnull__ (1, 2))); # 484 "/usr/include/string.h" 3 4 extern char *index (const char *__s, int __c) __attribute__ ((__nothrow__ )) __attribute__ ((__pure__)) __attribute__ ((__nonnull__ (1))); # 512 "/usr/include/string.h" 3 4 extern char *rindex (const char *__s, int __c) __attribute__ ((__nothrow__ )) __attribute__ ((__pure__)) __attribute__ ((__nonnull__ (1))); extern int ffs (int __i) __attribute__ ((__nothrow__ )) __attribute__ ((__const__)); # 529 "/usr/include/string.h" 3 4 extern int strcasecmp (const char *__s1, const char *__s2) __attribute__ ((__nothrow__ )) __attribute__ ((__pure__)) __attribute__ ((__nonnull__ (1, 2))); extern int strncasecmp (const char *__s1, const char *__s2, size_t __n) __attribute__ ((__nothrow__ )) __attribute__ ((__pure__)) __attribute__ ((__nonnull__ (1, 2))); # 552 "/usr/include/string.h" 3 4 extern char *strsep (char **__restrict __stringp, const char *__restrict __delim) __attribute__ ((__nothrow__ )) __attribute__ ((__nonnull__ (1, 2))); extern char *strsignal (int __sig) __attribute__ ((__nothrow__ )); extern char *__stpcpy (char *__restrict __dest, const char *__restrict __src) __attribute__ ((__nothrow__ )) __attribute__ ((__nonnull__ (1, 2))); extern char *stpcpy (char *__restrict __dest, const char *__restrict __src) __attribute__ ((__nothrow__ )) __attribute__ ((__nonnull__ (1, 2))); extern char *__stpncpy (char *__restrict __dest, const char *__restrict __src, size_t __n) __attribute__ ((__nothrow__ )) __attribute__ ((__nonnull__ (1, 2))); extern char *stpncpy (char *__restrict __dest, const char *__restrict __src, size_t __n) __attribute__ ((__nothrow__ )) __attribute__ ((__nonnull__ (1, 2))); # 627 "/usr/include/string.h" 3 4 # 1 "/usr/include/x86_64-linux-gnu/bits/string.h" 1 3 4 # 628 "/usr/include/string.h" 2 3 4 # 1 "/usr/include/x86_64-linux-gnu/bits/string2.h" 1 3 4 # 393 "/usr/include/x86_64-linux-gnu/bits/string2.h" 3 4 extern void *__rawmemchr (const void *__s, int __c); # 945 "/usr/include/x86_64-linux-gnu/bits/string2.h" 3 4 extern __inline __attribute__ ((__gnu_inline__)) size_t __strcspn_c1 (const char *__s, int __reject); extern __inline __attribute__ ((__gnu_inline__)) size_t __strcspn_c1 (const char *__s, int __reject) { size_t __result = 0; while (__s[__result] != '\0' && __s[__result] != __reject) ++__result; return __result; } extern __inline __attribute__ ((__gnu_inline__)) size_t __strcspn_c2 (const char *__s, int __reject1, int __reject2); extern __inline __attribute__ ((__gnu_inline__)) size_t __strcspn_c2 (const char *__s, int __reject1, int __reject2) { size_t __result = 0; while (__s[__result] != '\0' && __s[__result] != __reject1 && __s[__result] != __reject2) ++__result; return __result; } extern __inline __attribute__ ((__gnu_inline__)) size_t __strcspn_c3 (const char *__s, int __reject1, int __reject2, int __reject3); extern __inline __attribute__ ((__gnu_inline__)) size_t __strcspn_c3 (const char *__s, int __reject1, int __reject2, int __reject3) { size_t __result = 0; while (__s[__result] != '\0' && __s[__result] != __reject1 && __s[__result] != __reject2 && __s[__result] != __reject3) ++__result; return __result; } # 1021 "/usr/include/x86_64-linux-gnu/bits/string2.h" 3 4 extern __inline __attribute__ ((__gnu_inline__)) size_t __strspn_c1 (const char *__s, int __accept); extern __inline __attribute__ ((__gnu_inline__)) size_t __strspn_c1 (const char *__s, int __accept) { size_t __result = 0; while (__s[__result] == __accept) ++__result; return __result; } extern __inline __attribute__ ((__gnu_inline__)) size_t __strspn_c2 (const char *__s, int __accept1, int __accept2); extern __inline __attribute__ ((__gnu_inline__)) size_t __strspn_c2 (const char *__s, int __accept1, int __accept2) { size_t __result = 0; while (__s[__result] == __accept1 || __s[__result] == __accept2) ++__result; return __result; } extern __inline __attribute__ ((__gnu_inline__)) size_t __strspn_c3 (const char *__s, int __accept1, int __accept2, int __accept3); extern __inline __attribute__ ((__gnu_inline__)) size_t __strspn_c3 (const char *__s, int __accept1, int __accept2, int __accept3) { size_t __result = 0; while (__s[__result] == __accept1 || __s[__result] == __accept2 || __s[__result] == __accept3) ++__result; return __result; } # 1097 "/usr/include/x86_64-linux-gnu/bits/string2.h" 3 4 extern __inline __attribute__ ((__gnu_inline__)) char *__strpbrk_c2 (const char *__s, int __accept1, int __accept2); extern __inline __attribute__ ((__gnu_inline__)) char * __strpbrk_c2 (const char *__s, int __accept1, int __accept2) { while (*__s != '\0' && *__s != __accept1 && *__s != __accept2) ++__s; return *__s == '\0' ? ((void*)0) : (char *) (size_t) __s; } extern __inline __attribute__ ((__gnu_inline__)) char *__strpbrk_c3 (const char *__s, int __accept1, int __accept2, int __accept3); extern __inline __attribute__ ((__gnu_inline__)) char * __strpbrk_c3 (const char *__s, int __accept1, int __accept2, int __accept3) { while (*__s != '\0' && *__s != __accept1 && *__s != __accept2 && *__s != __accept3) ++__s; return *__s == '\0' ? ((void*)0) : (char *) (size_t) __s; } # 1147 "/usr/include/x86_64-linux-gnu/bits/string2.h" 3 4 extern __inline __attribute__ ((__gnu_inline__)) char *__strtok_r_1c (char *__s, char __sep, char **__nextp); extern __inline __attribute__ ((__gnu_inline__)) char * __strtok_r_1c (char *__s, char __sep, char **__nextp) { char *__result; if (__s == ((void*)0)) __s = *__nextp; while (*__s == __sep) ++__s; __result = ((void*)0); if (*__s != '\0') { __result = __s++; while (*__s != '\0') if (*__s++ == __sep) { __s[-1] = '\0'; break; } } *__nextp = __s; return __result; } # 1179 "/usr/include/x86_64-linux-gnu/bits/string2.h" 3 4 extern char *__strsep_g (char **__stringp, const char *__delim); # 1197 "/usr/include/x86_64-linux-gnu/bits/string2.h" 3 4 extern __inline __attribute__ ((__gnu_inline__)) char *__strsep_1c (char **__s, char __reject); extern __inline __attribute__ ((__gnu_inline__)) char * __strsep_1c (char **__s, char __reject) { char *__retval = *__s; if (__retval != ((void*)0) && (*__s = (__extension__ (__builtin_constant_p (__reject) && !__builtin_constant_p (__retval) && (__reject) == '\0' ? (char *) __rawmemchr (__retval, __reject) : __builtin_strchr (__retval, __reject)))) != ((void*)0)) *(*__s)++ = '\0'; return __retval; } extern __inline __attribute__ ((__gnu_inline__)) char *__strsep_2c (char **__s, char __reject1, char __reject2); extern __inline __attribute__ ((__gnu_inline__)) char * __strsep_2c (char **__s, char __reject1, char __reject2) { char *__retval = *__s; if (__retval != ((void*)0)) { char *__cp = __retval; while (1) { if (*__cp == '\0') { __cp = ((void*)0); break; } if (*__cp == __reject1 || *__cp == __reject2) { *__cp++ = '\0'; break; } ++__cp; } *__s = __cp; } return __retval; } extern __inline __attribute__ ((__gnu_inline__)) char *__strsep_3c (char **__s, char __reject1, char __reject2, char __reject3); extern __inline __attribute__ ((__gnu_inline__)) char * __strsep_3c (char **__s, char __reject1, char __reject2, char __reject3) { char *__retval = *__s; if (__retval != ((void*)0)) { char *__cp = __retval; while (1) { if (*__cp == '\0') { __cp = ((void*)0); break; } if (*__cp == __reject1 || *__cp == __reject2 || *__cp == __reject3) { *__cp++ = '\0'; break; } ++__cp; } *__s = __cp; } return __retval; } # 1278 "/usr/include/x86_64-linux-gnu/bits/string2.h" 3 4 extern char *__strdup (const char *__string) __attribute__ ((__nothrow__ )) __attribute__ ((__malloc__)); # 1297 "/usr/include/x86_64-linux-gnu/bits/string2.h" 3 4 extern char *__strndup (const char *__string, size_t __n) __attribute__ ((__nothrow__ )) __attribute__ ((__malloc__)); # 631 "/usr/include/string.h" 2 3 4 # 30 "/usr/include/memory.h" 2 3 4 # 31 "nqueens.c" 2 # 1 "./bots.h" 1 # 27 "./bots.h" extern int bots_sequential_flag; extern int bots_benchmark_flag; extern int bots_check_flag; extern int bots_result; extern int bots_output_format; extern int bots_print_header; extern char bots_name[]; extern char bots_parameters[]; extern char bots_model[]; extern char bots_resources[]; extern char bots_exec_date[]; extern char bots_exec_message[]; extern char bots_comp_date[]; extern char bots_comp_message[]; extern char bots_cc[]; extern char bots_cflags[]; extern char bots_ld[]; extern char bots_ldflags[]; extern double bots_time_program; extern double bots_time_sequential; extern unsigned long long bots_number_of_tasks; extern char bots_cutoff[]; extern int bots_cutoff_value; extern int bots_app_cutoff_value; extern int bots_app_cutoff_value_1; extern int bots_app_cutoff_value_2; extern int bots_arg_size; extern int bots_arg_size_1; extern int bots_arg_size_2; long bots_usecs(); void bots_error(int error, char *message); void bots_warning(int warning, char *message); typedef enum { BOTS_VERBOSE_NONE=0, BOTS_VERBOSE_DEFAULT, BOTS_VERBOSE_DEBUG } bots_verbose_mode_t; extern bots_verbose_mode_t bots_verbose_mode; # 33 "nqueens.c" 2 # 1 "./app-desc.h" 1 # 21 "./app-desc.h" # 1 "./omp-tasks-app.h" 1 # 21 "./omp-tasks-app.h" # 1 "/home/nader/llvm-omp/lib/clang/5.0.1/include/omp.h" 1 3 # 35 "/home/nader/llvm-omp/lib/clang/5.0.1/include/omp.h" 3 typedef enum omp_sched_t { omp_sched_static = 1, omp_sched_dynamic = 2, omp_sched_guided = 3, omp_sched_auto = 4 } omp_sched_t; extern void omp_set_num_threads (int); extern void omp_set_dynamic (int); extern void omp_set_nested (int); extern void omp_set_max_active_levels (int); extern void omp_set_schedule (omp_sched_t, int); extern int omp_get_num_threads (void); extern int omp_get_dynamic (void); extern int omp_get_nested (void); extern int omp_get_max_threads (void); extern int omp_get_thread_num (void); extern int omp_get_num_procs (void); extern int omp_in_parallel (void); extern int omp_in_final (void); extern int omp_get_active_level (void); extern int omp_get_level (void); extern int omp_get_ancestor_thread_num (int); extern int omp_get_team_size (int); extern int omp_get_thread_limit (void); extern int omp_get_max_active_levels (void); extern void omp_get_schedule (omp_sched_t *, int *); extern int omp_get_max_task_priority (void); typedef struct omp_lock_t { void * _lk; } omp_lock_t; extern void omp_init_lock (omp_lock_t *); extern void omp_set_lock (omp_lock_t *); extern void omp_unset_lock (omp_lock_t *); extern void omp_destroy_lock (omp_lock_t *); extern int omp_test_lock (omp_lock_t *); typedef struct omp_nest_lock_t { void * _lk; } omp_nest_lock_t; extern void omp_init_nest_lock (omp_nest_lock_t *); extern void omp_set_nest_lock (omp_nest_lock_t *); extern void omp_unset_nest_lock (omp_nest_lock_t *); extern void omp_destroy_nest_lock (omp_nest_lock_t *); extern int omp_test_nest_lock (omp_nest_lock_t *); typedef enum omp_lock_hint_t { omp_lock_hint_none = 0, omp_lock_hint_uncontended = 1, omp_lock_hint_contended = (1<<1 ), omp_lock_hint_nonspeculative = (1<<2 ), omp_lock_hint_speculative = (1<<3 ), kmp_lock_hint_hle = (1<<16), kmp_lock_hint_rtm = (1<<17), kmp_lock_hint_adaptive = (1<<18) } omp_lock_hint_t; extern void omp_init_lock_with_hint(omp_lock_t *, omp_lock_hint_t); extern void omp_init_nest_lock_with_hint(omp_nest_lock_t *, omp_lock_hint_t); extern double omp_get_wtime (void); extern double omp_get_wtick (void); extern int omp_get_default_device (void); extern void omp_set_default_device (int); extern int omp_is_initial_device (void); extern int omp_get_num_devices (void); extern int omp_get_num_teams (void); extern int omp_get_team_num (void); extern int omp_get_cancellation (void); extern int omp_get_initial_device (void); extern void* omp_target_alloc(size_t, int); extern void omp_target_free(void *, int); extern int omp_target_is_present(void *, int); extern int omp_target_memcpy(void *, void *, size_t, size_t, size_t, int, int); extern int omp_target_memcpy_rect(void *, void *, size_t, int, const size_t *, const size_t *, const size_t *, const size_t *, const size_t *, int, int); extern int omp_target_associate_ptr(void *, void *, size_t, size_t, int); extern int omp_target_disassociate_ptr(void *, int); extern int kmp_get_stacksize (void); extern void kmp_set_stacksize (int); extern size_t kmp_get_stacksize_s (void); extern void kmp_set_stacksize_s (size_t); extern int kmp_get_blocktime (void); extern int kmp_get_library (void); extern void kmp_set_blocktime (int); extern void kmp_set_library (int); extern void kmp_set_library_serial (void); extern void kmp_set_library_turnaround (void); extern void kmp_set_library_throughput (void); extern void kmp_set_defaults (char const *); extern void kmp_set_disp_num_buffers (int); typedef void * kmp_affinity_mask_t; extern int kmp_set_affinity (kmp_affinity_mask_t *); extern int kmp_get_affinity (kmp_affinity_mask_t *); extern int kmp_get_affinity_max_proc (void); extern void kmp_create_affinity_mask (kmp_affinity_mask_t *); extern void kmp_destroy_affinity_mask (kmp_affinity_mask_t *); extern int kmp_set_affinity_mask_proc (int, kmp_affinity_mask_t *); extern int kmp_unset_affinity_mask_proc (int, kmp_affinity_mask_t *); extern int kmp_get_affinity_mask_proc (int, kmp_affinity_mask_t *); typedef enum omp_proc_bind_t { omp_proc_bind_false = 0, omp_proc_bind_true = 1, omp_proc_bind_master = 2, omp_proc_bind_close = 3, omp_proc_bind_spread = 4 } omp_proc_bind_t; extern omp_proc_bind_t omp_get_proc_bind (void); extern int omp_get_num_places (void); extern int omp_get_place_num_procs (int); extern void omp_get_place_proc_ids (int, int *); extern int omp_get_place_num (void); extern int omp_get_partition_num_places (void); extern void omp_get_partition_place_nums (int *); extern void * kmp_malloc (size_t); extern void * kmp_aligned_malloc (size_t, size_t); extern void * kmp_calloc (size_t, size_t); extern void * kmp_realloc (void *, size_t); extern void kmp_free (void *); extern void kmp_set_warnings_on(void); extern void kmp_set_warnings_off(void); typedef int omp_int_t; typedef double omp_wtime_t; # 22 "./omp-tasks-app.h" 2 # 22 "./app-desc.h" 2 # 31 "./app-desc.h" int ok(int n, char *a); void nqueens(int n, int j, char *a, int depth); void nqueens_ser (int n, int j, char *a); int verify_queens(int); void find_queens (int); # 34 "nqueens.c" 2 static int solutions[] = { 1, 0, 0, 2, 10, 4, 40, 92, 352, 724, 2680, 14200, 73712, 365596, }; int mycount=0; #pragma omp threadprivate(mycount) int total_count; int ok(int n, char *a) { int i, j; char p, q; for (i = 0; i < n; i++) { p = a[i]; for (j = i + 1; j < n; j++) { q = a[j]; if (q == p || q == p - (j - i) || q == p + (j - i)) return 0; } } return 1; } void nqueens_ser (int n, int j, char *a) { int i; if (n == j) { mycount++; return; } for (i = 0; i < n; i++) { { a[j] = (char) i; if (ok(j + 1, a)) { nqueens_ser(n, j + 1, a); } } } } # 259 "nqueens.c" void nqueens(int n, int j, char *a, int depth) { int i; if (n == j) { mycount++; return; } # 286 "nqueens.c" for (i = 0; i < n; i++) { if ( depth < bots_cutoff_value ) { #pragma omp task { char * b = (char*)__builtin_alloca (n * sizeof(char)); memcpy(b, a, j * sizeof(char)); b[j] = (char) i; if (ok(j + 1, b)) nqueens(n, j + 1, b,depth+1); } } else { a[j] = (char) i; if (ok(j + 1, a)) nqueens_ser(n, j + 1, a); } } #pragma omp taskwait } # 375 "nqueens.c" void find_queens (int size) { total_count=0; { if ( bots_verbose_mode >= BOTS_VERBOSE_DEFAULT ) { fprintf(stdout, "Computing N-Queens algorithm (n=%d) " , size); } }; #pragma omp parallel num_threads(4) { #pragma omp single { char *a; a = (char*)__builtin_alloca (size * sizeof(char)); nqueens(size, 0, a, 0); } #pragma omp atomic total_count += mycount; } { if ( bots_verbose_mode >= BOTS_VERBOSE_DEFAULT ) { fprintf(stdout, " completed!\n"); } }; } int verify_queens (int size) { if ( size > sizeof(solutions)/sizeof(int) ) return 0; if ( total_count == solutions[size-1]) return 1; return 2; }
heap_mult.h
#include "CSC.h" #include "utility.h" #include <omp.h> #include <algorithm> #include <iostream> using namespace std; /** ** Count flop of SpGEMM between A and B in CSC format **/ template <typename IT, typename NT> long long int get_flop(const CSC<IT,NT> & A, const CSC<IT,NT> & B, IT *maxnnzc) { long long int flop = 0; // total flop (multiplication) needed to generate C #pragma omp parallel { long long int tflop=0; //thread private flop #pragma omp for for (IT i=0; i < B.cols; ++i) { // for all columns of B long long int locmax = 0; for (IT j = B.colptr[i]; j < B.colptr[i+1]; ++j) { // For all the nonzeros of the ith column IT inner = B.rowids[j]; // get the row id of B (or column id of A) IT npins = A.colptr[inner+1] - A.colptr[inner]; // get the number of nonzeros in A's corresponding column locmax += npins; } maxnnzc[i] = locmax; tflop += locmax; } #pragma omp critical { flop += tflop; } } return flop * 2; } template <typename IT, typename NT> long long int get_flop(const CSC<IT,NT> & A, const CSC<IT,NT> & B) { IT *dummy = my_malloc<IT>(B.cols); long long int flop = get_flop(A, B, dummy); my_free<IT>(dummy); return flop; } template <typename IT, typename NT, typename MultiplyOperation, typename AddOperation> void HeapSpGEMM(const CSC<IT,NT> & A, const CSC<IT,NT> & B, CSC<IT,NT> & C, MultiplyOperation multop, AddOperation addop) { int numThreads; #pragma omp parallel { numThreads = omp_get_num_threads(); } // *************** Load-balancing Thread Scheduling ********************* IT *maxnnzc = my_malloc<IT>(B.cols); long long int flops = get_flop(A, B, maxnnzc) / 2; IT flopsPerThread = flops/numThreads; // amount of work that will be assigned to each thread IT *colPerThread = my_malloc<IT>(numThreads + 1); //thread i will process columns from colPerThread[i] to colPerThread[i+1]-1 IT *colStart = my_malloc<IT>(B.cols); //start index in the global array for storing ith column of C IT *colEnd = my_malloc<IT>(B.cols); //end index in the global array for storing ith column of C colStart[0] = 0; colEnd[0] = 0; int curThread = 0; colPerThread[curThread++] = 0; IT nextflops = flopsPerThread; /* Parallelized version */ scan(maxnnzc, colStart, B.cols); #pragma omp parallel for for (int i = 1; i < B.cols; ++i) { colEnd[i] = colStart[i]; } #pragma omp parallel { int tid = omp_get_thread_num(); long end_itr = (lower_bound(colStart, colStart + B.cols, flopsPerThread * (tid + 1))) - colStart; colPerThread[tid + 1] = end_itr; } colPerThread[numThreads] = B.cols; // *************** Creating global space to store result, used by all threads ********************* IT size = colEnd[B.cols-1] + maxnnzc[B.cols-1]; IT **LocalRowIdsofC = my_malloc<IT*>(numThreads); NT **LocalValuesofC = my_malloc<NT*>(numThreads); #pragma omp parallel { int tid = omp_get_thread_num(); IT localsum = 0; for (IT i = colPerThread[tid]; i < colPerThread[tid + 1]; ++i) { localsum += maxnnzc[i]; } LocalRowIdsofC[tid] = my_malloc<IT>(localsum); LocalValuesofC[tid] = my_malloc<NT>(localsum); } my_free<IT>(maxnnzc); // *************** Creating LOCAL heap space to be used by all threads ********************* IT *threadHeapSize = my_malloc<IT>(numThreads); #pragma omp parallel { int thisThread = omp_get_thread_num(); // IT localmax = -1; //incorrect IT localmax = 0; for (IT i = colPerThread[thisThread]; i < colPerThread[thisThread + 1]; ++i) { IT colnnz = B.colptr[i + 1] - B.colptr[i]; if (colnnz > localmax) localmax = colnnz; } threadHeapSize[thisThread] = localmax; } // ************************ Numeric Phase ************************************* #pragma omp parallel { int thisThread = omp_get_thread_num(); HeapEntry<IT, NT> *mergeheap = my_malloc<HeapEntry<IT, NT>>(threadHeapSize[thisThread]); for (IT i = colPerThread[thisThread]; i < colPerThread[thisThread + 1]; ++i) { IT k = 0; // Make initial heap for (IT j = B.colptr[i]; j < B.colptr[i + 1]; ++j) { // For all the nonzeros of the ith column IT inner = B.rowids[j]; // get the row id of B (or column id of A) IT npins = A.colptr[inner + 1] - A.colptr[inner]; // get the number of nonzeros in A's corresponding column if (npins > 0) { mergeheap[k].loc = 1; mergeheap[k].runr = j; // the pointer to B.rowid's is the run-rank mergeheap[k].value = multop(A.values[A.colptr[inner]], B.values[j]); mergeheap[k++].key = A.rowids[A.colptr[inner]]; // A's first rowid is the first key } } IT hsize = k; // if any of A's "significant" columns is empty, k will be less than hsize make_heap(mergeheap, mergeheap + hsize); while(hsize > 0) { pop_heap(mergeheap, mergeheap + hsize); // result is stored in mergeheap[hsize-1] HeapEntry<IT,NT> hentry = mergeheap[hsize - 1]; // Use short circuiting if ((colEnd[i] > colStart[i]) && LocalRowIdsofC[thisThread][colEnd[i] - colStart[colPerThread[thisThread]] - 1] == hentry.key) { LocalValuesofC[thisThread][colEnd[i] - colStart[colPerThread[thisThread]] - 1] = addop(hentry.value, LocalValuesofC[thisThread][colEnd[i] - colStart[colPerThread[thisThread]] - 1]); } else { LocalValuesofC[thisThread][colEnd[i] - colStart[colPerThread[thisThread]]]= hentry.value; LocalRowIdsofC[thisThread][colEnd[i] - colStart[colPerThread[thisThread]]]= hentry.key; colEnd[i] ++; } IT inner = B.rowids[hentry.runr]; // If still unused nonzeros exists in A(:,colind), insert the next nonzero to the heap if ((A.colptr[inner + 1] - A.colptr[inner]) > hentry.loc) { IT index = A.colptr[inner] + hentry.loc; mergeheap[hsize-1].loc = hentry.loc + 1; mergeheap[hsize-1].runr = hentry.runr; mergeheap[hsize-1].value = multop(A.values[index], B.values[hentry.runr]); mergeheap[hsize-1].key = A.rowids[index]; push_heap(mergeheap, mergeheap + hsize); } else { --hsize; } } } my_free<HeapEntry<IT, NT>>(mergeheap); } my_free<IT>(threadHeapSize); if (C.isEmpty()) { C.make_empty(); } // ************************ Copy output to C ************************************* C.rows = A.rows; C.cols = B.cols; C.colptr = my_malloc<IT>(C.cols + 1); C.colptr[0] = 0; IT *col_nz = my_malloc<IT>(C.cols); #pragma omp parallel for for (int i = 0; i < C.cols; ++i) { col_nz[i] = colEnd[i] - colStart[i]; } scan(col_nz, C.colptr, C.cols + 1); my_free<IT>(col_nz); C.nnz = C.colptr[C.cols]; C.rowids = my_malloc<IT>(C.nnz); C.values = my_malloc<NT>(C.nnz); #pragma omp parallel { int thisThread = omp_get_thread_num(); for(int i = colPerThread[thisThread]; i< colPerThread[thisThread + 1]; ++i) { // combine step copy(&LocalRowIdsofC[thisThread][colStart[i] - colStart[colPerThread[thisThread]]], &LocalRowIdsofC[thisThread][colEnd[i] - colStart[colPerThread[thisThread]]], C.rowids + C.colptr[i]); copy(&LocalValuesofC[thisThread][colStart[i] - colStart[colPerThread[thisThread]]], &LocalValuesofC[thisThread][colEnd[i] - colStart[colPerThread[thisThread]]], C.values + C.colptr[i]); } } // ************************ Memory deallocation ************************************* #pragma omp parallel { int thisThread = omp_get_thread_num(); my_free<IT>(LocalRowIdsofC[thisThread]); my_free<NT>(LocalValuesofC[thisThread]); } my_free<IT*>(LocalRowIdsofC); my_free<NT*>(LocalValuesofC); my_free<IT>(colPerThread); my_free<IT>(colEnd); my_free<IT>(colStart); }
Jacobi2D-DiamondByHandParam-OMP_static.test.c
/****************************************************************************** * Jacobi2D benchmark * Diamond tiling parameterized by hand. * * Copied Jacobi2D-DiamondSlabISCCParam-OMP-test.c to get similar format * to other drivers and then put in parameterized loop bounds. * * Look for the notes titled "Parameterizing diamond tiling by hand" in * ProjectNotes/chapel-diamond-MMS-log.txt for the details of how this was done. * * Usage: * make omp * export OMP_NUM_THREADS=8 * bin/Jacobi2D-DiamondISCCParam-OMP \ * `cat src/Jacobi2D-DiamondByHandParam-OMP.perfexecopts` * For a run on 8 threads * * Use * bin/Jacobi2D-DiamondByHandParam-OMP -h * to get a list of command-line arguments. It is possible that not all work * for this driver. * ******************************************************************************/ #include <stdio.h> #include <omp.h> #include <time.h> #include <stdlib.h> #include <getopt.h> #include <stdbool.h> #include <ctype.h> #include <math.h> #include <assert.h> #define STENCIL(read,write,x,y) space[write][x][y] = \ ( space[read][x-1][y] +\ space[read][x][y] +\ space[read][x+1][y] +\ space[read][x][y+1] +\ space[read][x][y-1] )/5; #include "util.h" // main // Stages // 1 - command line parsing // 2 - data allocation and initialization // 3 - jacobi 1D timed within an openmp loop // 4 - output and optional verification int main( int argc, char* argv[] ){ // rather than calling fflush setbuf(stdout, NULL); // 1 - command line parsing Params cmdLineArgs; parseCmdLineArgs(&cmdLineArgs,argc,argv); // T is used down it loop code a lot. int T = cmdLineArgs.T; // If tau was not defined at compile time then declare a tau variable // and grab the value set with command-line options. // If it was defined at compile time then all instances of "tau" will be replaced // with that number by the compiler. #if ! defined tau int tau = cmdLineArgs.tau_runtime; #endif // 2 - data allocation and initialization int lowerBound = 1; int upperBound = lowerBound + cmdLineArgs.problemSize - 1; double** space[2]; int i; // allocate x axis space[0] = (double**)malloc((cmdLineArgs.problemSize + 2) * sizeof(double*)); space[1] = (double**)malloc((cmdLineArgs.problemSize + 2) * sizeof(double*)); if( space[0] == NULL || space[1] == NULL ){ printf( "Could not allocate x axis of space array\n" ); exit(0); } // allocate y axis for( i = 0; i < cmdLineArgs.problemSize + 2; ++i ){ space[0][i]=(double*)malloc((cmdLineArgs.problemSize + 2) * sizeof(double)); space[1][i]=(double*)malloc((cmdLineArgs.problemSize + 2) * sizeof(double)); if( space[0][i] == NULL || space[1][i] == NULL ){ printf( "Could not allocate y axis of space array\n" ); exit(0); } } // use global seed to seed the random number gen (will be constant) srand(cmdLineArgs.globalSeed); // first touch for openmp // FIXME: we will have to specialize first touch for diamond tiles int x, y; #pragma omp parallel for private( x, y ) collapse(2) schedule(static) for( x = lowerBound; x <= upperBound; ++x ){ for( y = lowerBound; y <= upperBound; ++y ){ space[0][x][y] = 0; } } // seed the space. for( x = lowerBound; x <= upperBound; ++x ){ for( y = lowerBound; y <= upperBound; ++y ){ space[0][x][y] = rand() / (double)rand(); } } // set halo values (sanity) for( i = 0; i < cmdLineArgs.problemSize + 2; ++i){ space[0][i][0] = 0; space[1][i][0] = 0; space[0][i][cmdLineArgs.problemSize + 1] = 0; space[1][i][cmdLineArgs.problemSize + 1] = 0; space[0][0][i] = 0; space[1][0][i] = 0; space[0][cmdLineArgs.problemSize + 1][i] = 0; space[1][cmdLineArgs.problemSize + 1][i] = 0; } // 3 - jacobi 2D timed within an openmp loop double start_time = omp_get_wtime(); int read=0,write=1; int num_tiles = 0; int tau_times_3 = tau*3; // Set lower and upper bounds for spatial dimensions. int Li=1, Lj=1, Ui=upperBound, Uj=upperBound; int thyme, k1, k2, t, j; // Loop over tile wavefronts. //for (thyme=-2; thyme<=floord(3*T,tau); thyme++) { // rev 298 for (thyme=ceild(3,tau)-3; thyme<=floord(3*T,tau); thyme++){ // from paper // The next two loops iterate within a tile wavefront. //int k1_lb = floord(3*Lj+2+(thyme-2)*tau,tau_times_3); // rev 298 //int k1_ub = floord(3*Uj+(thyme+2)*tau-2,tau_times_3); int k1_lb = ceild(3*Lj+2+(thyme-2)*tau,tau*3); // paper int k1_ub = floord(3*Uj+(thyme+2)*tau,tau*3); // int k2_lb = floord((2*thyme-2)*tau-3*Ui+2,tau_times_3); // int k2_ub = floord((2+2*thyme)*tau-2-3*Li,tau_times_3); #define k2_lb_exp(k1val) floord((2*thyme-2)*tau-3*Ui+2,tau*3)-(k1val) #define k2_ub_exp(k1val) floord((2+2*thyme)*tau-3*Li-2,tau*3)-(k1val) // bounding box for k2 int k2_lb = k2_lb_exp(k1_ub); // min possible value of expression int k2_ub = k2_ub_exp(k1_lb); // max possible value of expression //num_tiles+=(k2_ub-k2_lb+1)*(k1_ub-k1_lb+1); //printf("Number of tiles: %d\n",(k2_ub-k2_lb+1)*(k1_ub-k1_lb+1)); #pragma omp parallel for shared(start_time, Li, Lj, Ui, Uj ) private(read, write,k1,k2,t,i,j) schedule(static) collapse(2) for (k1=k1_lb; k1<=k1_ub; k1++) { for (int x=k2_lb; x<=k2_ub; x++) { k2 = x; // Loop over time within a tile. //for (t=max(1,floord(thyme*tau,3)); // rev 298 // t<= min(T,floord((3+thyme)*tau-3,3)); t++) { for (t = max(1,floord(thyme*tau-1, 3) + 1); // from paper t < min(T+1, tau + floord(thyme*tau, 3)); t+=1) { // if t % 2 is 1, then read=0 and write=1 write = t & 1; read = 1-write; // Loops over spatial dimensions within tile. //for (i=max(Li,max((thyme-k1-k2)*tau-t, 2*t-(2+k1+k2)*tau+2));// rev 298 // i<=min(Ui,min((1+thyme-k1-k2)*tau-t-1, 2*t-(k1+k2)*tau)); i++) { // for (j=max(Lj,max(tau*k1-t,t-i-(1+k2)*tau+1)); // j<=min(Uj,min((1+k1)*tau-t-1,t-i-k2*tau)); j++) { for (i = max(Li, max(-2*tau-k1*tau-k2*tau+2*t+2, // from paper (thyme-k1-k2)*tau-t)); i <= min(Ui, min(tau+(thyme-k1-k2)*tau-t-1, -k1*tau-k2*tau+2*t)); i+=1) { for (j = max(Li,max(k1*tau-t, -tau-k2*tau+t-i+1)); j <= min(Ui,min(tau+k1*tau-t-1, -k2*tau+t-i)); j+=1) { STENCIL( read, write, i, j); } // for j } // for i } // for t } // for k2 } // for k1 } // for thyme double end_time = omp_get_wtime(); double time = (end_time - start_time); // 4 - output and optional verification if( cmdLineArgs.printtime ){ /* printf("Threads: %d, ",cmdLineArgs.cores); printf( "T: %d, ", T ); printf( "N: %d, ", upperBound ); printf( "tau: %d, ", tau ); printf( "num_tiles: %d, ", num_tiles ); */ printf( "Time: %f", time ); } if( cmdLineArgs.verify ){ if(!verifyResultJacobi2D(space[cmdLineArgs.T & 1],cmdLineArgs.problemSize, cmdLineArgs.globalSeed,cmdLineArgs.T )){ fprintf(stderr,"FAILURE\n"); }else{ fprintf(stderr,"SUCCESS\n"); } } }
vbHmm_Common.c
/* * vbHmm_Common.c * Common VB-HMM engine. * Reference: * Christopher M. Bishop, "Pattern Recognition and Machine Learning", Springer, 2006 * * Created by OKAMOTO Kenji, SAKO Yasushi and RIKEN * Copyright 2011-2015 * Cellular Informatics Laboratory, Advance Science Institute, RIKEN, Japan. * All rights reserved. * * Ver. 1.1.0 * Last modified on 2016.11.04 */ #include "vbHmm_Common.h" #include <string.h> #include <float.h> // Pointers of functions to call model-specific functions. new_model_parameters_func newModelParameters = NULL; free_model_parameters_func freeModelParameters = NULL; new_model_stats_func newModelStats = NULL; free_model_stats_func freeModelStats = NULL; initialize_vbHmm_func initializeVbHmm = NULL; pTilde_z1_func pTilde_z1 = NULL; pTilde_zn_zn1_func pTilde_zn_zn1 = NULL; pTilde_xn_zn_func pTilde_xn_zn = NULL; calcStatsVars_func calcStatsVars = NULL; maximization_func maximization = NULL; varLowerBound_func varLowerBound = NULL; reorderParameters_func reorderParameters = NULL; outputResults_func outputResults = NULL; // This function must be called to connect with the model before executing analysis. void setFunctions( funcs ) commonFunctions funcs; { newModelParameters = funcs.newModelParameters; freeModelParameters = funcs.freeModelParameters; newModelStats = funcs.newModelStats; freeModelStats = funcs.freeModelStats; initializeVbHmm = funcs.initializeVbHmm; pTilde_z1 = funcs.pTilde_z1; pTilde_zn_zn1 = funcs.pTilde_zn_zn1; pTilde_xn_zn = funcs.pTilde_xn_zn; calcStatsVars = funcs.calcStatsVars; maximization = funcs.maximization; varLowerBound = funcs.varLowerBound; reorderParameters = funcs.reorderParameters; outputResults = funcs.outputResults; } ////////////////////////////////////////////////////////////////// VB-HMM Execution Functions int modelComparison( xn, sFrom, sTo, trials, maxIteration, threshold, logFP ) xnDataSet *xn; int sFrom, sTo, trials; int maxIteration; double threshold; FILE *logFP; { int s, t; if( logFP != NULL ){ fprintf( logFP, " No. of states from %d to %d, trials = %d, ", sFrom, sTo, trials); fprintf( logFP, " analyze: maxIteration = %d, threshold = %g \n\n", maxIteration, threshold); } double *LqVsK = malloc( trials * (sTo - sFrom + 1) * sizeof(double) ); int maxS = 0; double maxLq = -DBL_MAX; globalVars **gvArray = (globalVars**)malloc( trials * sizeof(globalVars*) ); indVars **ivArray = (indVars**)malloc( trials * sizeof(indVars*) ); for( s = sFrom ; s <= sTo ; s++ ){ #ifdef _OPENMP #pragma omp parallel for private(t) #endif for( t = 0 ; t < trials ; t++ ){ int st = (s - sFrom) * trials + t; gvArray[t] = newGlobalVars( xn, s ); ivArray[t] = newIndVars( xn, gvArray[t] ); LqVsK[st] = vbHmm_Main( xn, gvArray[t], ivArray[t], maxIteration, threshold, logFP ); if( LqVsK[st] > maxLq ){ maxLq = LqVsK[st]; maxS = s; } } double maxLqForS = 0.0; int maxT = 0; for( t = 0 ; t < trials ; t++ ){ int st = (s - sFrom) * trials + t; if( LqVsK[st] > maxLqForS ){ maxLqForS = LqVsK[st]; maxT = t; } } (*outputResults)( xn, gvArray[maxT], ivArray[maxT], logFP ); for( t = 0 ; t < trials ; t++ ){ freeIndVars( xn, gvArray[t], &ivArray[t] ); freeGlobalVars( xn, &gvArray[t] ); } if( s >= (maxS+3) ){ s++; break; } } sTo = s - 1; free( gvArray ); free( ivArray ); char fn[256]; FILE *fp = NULL; strncpy( fn, xn->name, sizeof(fn) ); strncat( fn, ".LqVsK", sizeof(fn) - strlen(fn) - 1 ); if( (fp = fopen( fn, "w" )) != NULL ){ for( s = 0 ; s < trials * (sTo - sFrom + 1) ; s++ ){ fprintf( fp, "%2d, %.20g\n", (s/trials) + sFrom, LqVsK[s] ); } fclose(fp); } free( LqVsK ); return maxS; } globalVars *newGlobalVars( xn, sNo ) xnDataSet *xn; int sNo; { globalVars *gv = (globalVars*)malloc( sizeof(globalVars) ); gv->sNo = sNo; gv->iteration = 0; gv->maxLq = 0.0; gv->LqArr = NULL; gv->params = (*newModelParameters)( xn, sNo ); return gv; } void freeGlobalVars( xn, gv ) xnDataSet *xn; globalVars **gv; { free( (*gv)->LqArr ); (*freeModelParameters)( &(*gv)->params, xn, (*gv)->sNo ); free( *gv ); *gv = NULL; } indVars *newIndVars( xn, gv ) xnDataSet *xn; globalVars *gv; { size_t dLen = xn->N; int sNo = gv->sNo; int i, n; indVars *iv = (indVars*)malloc( sizeof(indVars) ); // gamma iv->gmMat = (double**)malloc( dLen * sizeof(double*) ); double **gmMat = iv->gmMat; for( n = 0 ; n < dLen ; n++ ){ gmMat[n] = (double*)malloc( sNo * sizeof(double) ); memset( gmMat[n], 0, sNo * sizeof(double) ); } // xi iv->xiMat = (double***)malloc( dLen * sizeof(double**) ); double ***xiMat = iv->xiMat; for( n = 0 ; n < dLen ; n++ ){ xiMat[n] = (double**)malloc( sNo * sizeof(double*) ); for( i = 0 ; i < sNo ; i++ ){ xiMat[n][i] = (double*)malloc( sNo * sizeof(double) ); memset( xiMat[n][i], 0, sNo * sizeof(double) ); } } // alpha for E-step iv->aMat = (double**)malloc( dLen * sizeof(double*) ); for( n = 0 ; n < dLen ; n++ ) { iv->aMat[n] = (double*)malloc( sNo * sizeof(double) ); } // beta for E-step iv->bMat = (double**)malloc( dLen * sizeof(double*) ); for( n = 0 ; n < dLen ; n++ ) { iv->bMat[n] = (double*)malloc( sNo * sizeof(double) ); } // scaling factor for E-step iv->cn = (double*)malloc( dLen * sizeof(double) ); // temporary storage of calculation resutls to save time iv->valpZnZn1 = (double**)malloc( sNo * sizeof(double*) ); for( i = 0 ; i < sNo ; i++ ) { iv->valpZnZn1[i] = (double*)malloc( sNo * sizeof(double) ); } iv->valpXnZn = (double**)malloc( dLen * sizeof(double*) ); for( n = 0 ; n < dLen ; n++ ) { iv->valpXnZn[n] = (double*)malloc( sNo * sizeof(double) ); } iv->stats = (*newModelStats)( xn, gv, iv ); #ifdef OUTPUT_MAX_GAMMA iv->gammaTraj = NULL; #endif iv->stateTraj = NULL; return iv; } void freeIndVars( xn, gv, iv ) xnDataSet *xn; globalVars *gv; indVars **iv; { size_t dLen = xn->N; int sNo = gv->sNo; int i, n; // gamma for( n = 0 ; n < dLen ; n++ ) { free( (*iv)->gmMat[n] ); } free( (*iv)->gmMat ); // xi for( n = 0 ; n < dLen ; n++ ){ for( i = 0 ; i < sNo ; i++ ){ free( (*iv)->xiMat[n][i] ); } free( (*iv)->xiMat[n] ); } free( (*iv)->xiMat ); // alpha for( n = 0 ; n < dLen ; n++ ) { free( (*iv)->aMat[n] ); } free( (*iv)->aMat ); // beta for( n = 0 ; n < dLen ; n++ ) { free( (*iv)->bMat[n] ); } free( (*iv)->bMat ); // scaling factor free( (*iv)->cn ); // temporary storage for( i = 0 ; i < sNo ; i++ ) { free( (*iv)->valpZnZn1[i] ); } free( (*iv)->valpZnZn1 ); for( n = 0 ; n < dLen ; n++ ) { free( (*iv)->valpXnZn[n] ); } free( (*iv)->valpXnZn ); #ifdef OUTPUT_MAX_GAMMA free( (*iv)->gammaTraj ); #endif free( (*iv)->stateTraj ); (*freeModelStats)( &(*iv)->stats, xn, gv, (*iv) ); free( *iv ); *iv = NULL; } ////////////////////////////////////////////////////////////////// VB-HMM Common Engine double vbHmm_Main( xn, gv, iv ,maxIteration, threshold, logFP ) xnDataSet *xn; globalVars *gv; indVars *iv; int maxIteration; double threshold; FILE *logFP; { double **LqArr = &gv->LqArr; *LqArr = realloc( *LqArr, maxIteration * sizeof(double) ); (*initializeVbHmm)( xn, gv, iv ); int i; for( i = 0 ; i < maxIteration ; i++ ){ // E-step forwardBackward( xn, gv, iv ); (*calcStatsVars)( xn, gv, iv ); (*LqArr)[i] = (*varLowerBound)( xn, gv, iv ); // End loop if derivative of variational lower bound reaches threshold. if( (i>0) && ( fabs( ((*LqArr)[i] - (*LqArr)[i-1]) / (*LqArr)[i] ) < threshold ) ){ break; } // M-step (*maximization)( xn, gv, iv ); } if( i == maxIteration ){ if( logFP != NULL ){ fprintf(logFP, "MAX iteration (%d) reached.\n", maxIteration); } i--; } (*reorderParameters)( xn, gv, iv ); #ifdef OUTPUT_MAX_GAMMA maxGamma( xn, gv, iv ); #endif maxSum( xn, gv, iv ); gv->iteration = i+1; *LqArr = realloc( *LqArr, (i+1) * sizeof(double) ); gv->maxLq = (*LqArr)[i]; if( logFP != NULL ){ fprintf( logFP, " iteration: %d evidence p(x|K=%d) = %.20g \n", i+1, gv->sNo, gv->maxLq ); } return gv->maxLq; } // Baum-Welch algorithm for E-step calculation void forwardBackward( xn, gv, iv ) xnDataSet *xn; globalVars *gv; indVars *iv; { size_t dLen = xn->N; // number of time stamp data points int sNo = gv->sNo; double **gmMat = iv->gmMat, ***xiMat = iv->xiMat; double **aMat = iv->aMat, **bMat = iv->bMat; double *cn = iv->cn; double **valpZnZn1 = iv->valpZnZn1, **valpXnZn = iv->valpXnZn; size_t n, i, j; // forward cn[0] = 0.0; for( i = 0 ; i < sNo ; i++ ){ valpXnZn[0][i] = (*pTilde_xn_zn)( xn, 0, (int)i, gv->params ); aMat[0][i] = (*pTilde_z1)( (int)i, gv->params ) * valpXnZn[0][i]; cn[0] += aMat[0][i]; for( j = 0 ; j < sNo ; j++ ){ valpZnZn1[i][j] = (*pTilde_zn_zn1)( (int)i, (int)j, gv->params ); } } for( i = 0 ; i < sNo ; i++ ){ aMat[0][i] /= cn[0]; } for( n = 1 ; n < dLen ; n++ ){ cn[n] = 0.0; for( j = 0 ; j < sNo ; j++ ){ aMat[n][j] = 0; for( i = 0 ; i < sNo ; i++ ){ aMat[n][j] += aMat[n-1][i] * valpZnZn1[i][j]; } valpXnZn[n][j] = (*pTilde_xn_zn)( xn, n, (int)j, gv->params ); aMat[n][j] *= valpXnZn[n][j]; cn[n] += aMat[n][j]; } for( j = 0 ; j < sNo ; j++ ){ aMat[n][j] /= cn[n]; } } // backward for( i = 0 ; i < sNo ; i++ ){ bMat[dLen-1][i] = 1; } double betaTerm; for( n = dLen-1 ; n > 0 ; ){ n--; for( i = 0 ; i < sNo ; i++ ){ bMat[n][i] = 0; for( j = 0 ; j < sNo ; j++ ){ betaTerm = bMat[n+1][j]; betaTerm *= valpZnZn1[i][j]; betaTerm *= valpXnZn[n+1][j]; bMat[n][i] += betaTerm; } bMat[n][i] /= cn[n+1]; } } // update gamma for( n = 0 ; n < dLen ; n++ ){ for( i = 0 ; i < sNo ; i++ ){ gmMat[n][i] = aMat[n][i] * bMat[n][i]; } } // update xi double xiTerm; for( i = 0 ; i < sNo ; i++ ){ for( j = 0 ; j < sNo ; j++ ){ xiMat[0][i][j] = 0; } } for( n = 1 ; n < dLen ; n++ ){ for( i = 0 ; i < sNo ; i++ ){ for( j = 0 ; j < sNo ; j++ ){ xiTerm = aMat[n-1][i]; xiTerm *= valpXnZn[n][j]; xiTerm *= valpZnZn1[i][j]; xiTerm *= bMat[n][j]; xiMat[n][i][j] = xiTerm / cn[n]; } } } } // construct most likely trajectory to trace max Gamma #ifdef OUTPUT_MAX_GAMMA int *maxGamma( xn, gv, iv ) xnDataSet *xn; globalVars *gv; indVars *iv; { size_t dLen = xn->N; int sNo = gv->sNo; double **gmMat = iv->gmMat; size_t n; int i, j; iv->gammaTraj = (int*)realloc( iv->gammaTraj, dLen * sizeof(int) ); int maxI; double maxG; for( n = 0 ; n < dLen ; n++ ){ maxG = - 1.0; for( i = 0 ; i < sNo ; i++ ){ if( gmMat[n][i] > maxG ){ maxG = gmMat[n][i]; maxI = i; } } iv->gammaTraj[n] = maxI; } return iv->gammaTraj; } #endif // Viterbi algorithm to construct most likely trajectory int *maxSum( xn, gv, iv ) xnDataSet *xn; globalVars *gv; indVars *iv; { size_t dLen = xn->N; int sNo = gv->sNo; size_t n; int i, j; iv->stateTraj = (int*)realloc( iv->stateTraj, dLen * sizeof(int) ); double **wnMat = (double **)malloc( dLen * sizeof(double*) ); double **phiMat = (double **)malloc( dLen * sizeof(double*) ); for( n = 0 ; n < dLen ; n++ ){ wnMat[n] = (double*)malloc( sNo * sizeof(double) ); phiMat[n] = (double*)malloc( sNo * sizeof(double) ); } int maxI; double wnTest, maxWn; // forward for( n = 0 ; n < dLen ; n++ ){ for( i = 0 ; i < sNo ; i++ ){ wnMat[n][i] = 0.0; phiMat[n][i] = 0.0; } } for( i = 0 ; i < sNo ; i++ ){ wnMat[0][i] = log((*pTilde_z1)(i, gv->params)) + log((*pTilde_xn_zn)(xn, 0, i, gv->params)); } for( n = 1 ; n < dLen ; n++ ){ for( j = 0 ; j < sNo ; j++ ){ maxWn = log( (*pTilde_zn_zn1)(0, j, gv->params) ) + wnMat[n-1][0]; maxI = 0; for( i = 1 ; i < sNo ; i++ ){ wnTest = log( (*pTilde_zn_zn1)(i, j, gv->params) ) + wnMat[n-1][i]; if( wnTest > maxWn ){ maxWn = wnTest; maxI = i; } } phiMat[n][j] = maxI; wnMat[n][j] = log((*pTilde_xn_zn)(xn, n, j, gv->params)) + maxWn; } } // backward maxWn = wnMat[dLen-1][0]; maxI = 0; for( i = 1 ; i < sNo ; i++ ){ if( wnMat[dLen-1][i] > maxWn ){ maxWn = wnMat[dLen-1][i]; maxI = i; } } iv->stateTraj[dLen-1] = maxI; for( n = dLen-1 ; n > 0 ; n-- ){ iv->stateTraj[n-1] = phiMat[n][iv->stateTraj[n]]; } for( n = 0 ; n < dLen ; n++ ){ free( wnMat[n] ); free( phiMat[n] ); } free( wnMat ); free( phiMat ); return iv->stateTraj; } //
targ-273742.c
#include <omp.h> #include <stdio.h> struct simple_dvector { size_t length; double* data; } ; int main (){ omp_set_default_device(0); int Device = 0; //allocate memory on the device size_t N = 1024*1024*10; int use_device = 1; int chunk = 1; struct simple_dvector x_vec, y_vec; x_vec.data = (double*) omp_target_alloc(N*sizeof(double), Device); y_vec.data = (double*) omp_target_alloc(N*sizeof(double), Device); fprintf(stderr, "CPU: x_vec.data = %p\n",x_vec.data); fprintf(stderr, "CPU: y_vec.data = %p\n",y_vec.data); #pragma omp target map(to:x_vec,y_vec) { printf("GPU: x_vec.data = %p\n",x_vec.data); //works printf("GPU: y_vec.data = %p\n",y_vec.data); //works } #pragma omp target teams distribute parallel for num_teams(120*4) thread_limit(512) schedule(static,chunk) map(to:x_vec,y_vec) if(target:use_device) for (size_t i = 0; i < N; ++i){ x_vec.data[i] = 0.0001*i; //fails y_vec.data[i] = 0.00003*i; } omp_target_free( x_vec.data, Device); omp_target_free( y_vec.data, Device); return 0; }
c-parser.c
/* Parser for C and Objective-C. Copyright (C) 1987, 1988, 1989, 1992, 1993, 1994, 1995, 1996, 1997, 1998, 1999, 2000, 2001, 2002, 2003, 2004, 2005, 2007, 2008, 2009 Free Software Foundation, Inc. Parser actions based on the old Bison parser; structure somewhat influenced by and fragments based on the C++ parser. This file is part of GCC. GCC is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 3, or (at your option) any later version. GCC is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with GCC; see the file COPYING3. If not see <http://www.gnu.org/licenses/>. */ /* TODO: Make sure all relevant comments, and all relevant code from all actions, brought over from old parser. Verify exact correspondence of syntax accepted. Add testcases covering every input symbol in every state in old and new parsers. Include full syntax for GNU C, including erroneous cases accepted with error messages, in syntax productions in comments. Make more diagnostics in the front end generally take an explicit location rather than implicitly using input_location. */ #include "config.h" #include "system.h" #include "coretypes.h" #include "tm.h" #include "tree.h" #include "rtl.h" #include "langhooks.h" #include "input.h" #include "cpplib.h" #include "timevar.h" #include "c-pragma.h" #include "c-tree.h" #include "flags.h" #include "output.h" #include "toplev.h" #include "ggc.h" #include "c-common.h" #include "vec.h" #include "target.h" #include "cgraph.h" #include "plugin.h" #include "except.h" /* Initialization routine for this file. */ void c_parse_init (void) { /* The only initialization required is of the reserved word identifiers. */ unsigned int i; tree id; int mask = 0; /* Make sure RID_MAX hasn't grown past the 8 bits used to hold the keyword in the c_token structure. */ gcc_assert (RID_MAX <= 255); mask |= D_CXXONLY; if (!flag_isoc99) mask |= D_C99; if (flag_no_asm) { mask |= D_ASM | D_EXT; if (!flag_isoc99) mask |= D_EXT89; } if (!c_dialect_objc ()) mask |= D_OBJC | D_CXX_OBJC; ridpointers = GGC_CNEWVEC (tree, (int) RID_MAX); for (i = 0; i < num_c_common_reswords; i++) { /* If a keyword is disabled, do not enter it into the table and so create a canonical spelling that isn't a keyword. */ if (c_common_reswords[i].disable & mask) { if (warn_cxx_compat && (c_common_reswords[i].disable & D_CXXWARN)) { id = get_identifier (c_common_reswords[i].word); C_SET_RID_CODE (id, RID_CXX_COMPAT_WARN); C_IS_RESERVED_WORD (id) = 1; } continue; } id = get_identifier (c_common_reswords[i].word); C_SET_RID_CODE (id, c_common_reswords[i].rid); C_IS_RESERVED_WORD (id) = 1; ridpointers [(int) c_common_reswords[i].rid] = id; } } /* The C lexer intermediates between the lexer in cpplib and c-lex.c and the C parser. Unlike the C++ lexer, the parser structure stores the lexer information instead of using a separate structure. Identifiers are separated into ordinary identifiers, type names, keywords and some other Objective-C types of identifiers, and some look-ahead is maintained. ??? It might be a good idea to lex the whole file up front (as for C++). It would then be possible to share more of the C and C++ lexer code, if desired. */ /* The following local token type is used. */ /* A keyword. */ #define CPP_KEYWORD ((enum cpp_ttype) (N_TTYPES + 1)) /* More information about the type of a CPP_NAME token. */ typedef enum c_id_kind { /* An ordinary identifier. */ C_ID_ID, /* An identifier declared as a typedef name. */ C_ID_TYPENAME, /* An identifier declared as an Objective-C class name. */ C_ID_CLASSNAME, /* An address space identifier. */ C_ID_ADDRSPACE, /* Not an identifier. */ C_ID_NONE } c_id_kind; /* A single C token after string literal concatenation and conversion of preprocessing tokens to tokens. */ typedef struct GTY (()) c_token { /* The kind of token. */ ENUM_BITFIELD (cpp_ttype) type : 8; /* If this token is a CPP_NAME, this value indicates whether also declared as some kind of type. Otherwise, it is C_ID_NONE. */ ENUM_BITFIELD (c_id_kind) id_kind : 8; /* If this token is a keyword, this value indicates which keyword. Otherwise, this value is RID_MAX. */ ENUM_BITFIELD (rid) keyword : 8; /* If this token is a CPP_PRAGMA, this indicates the pragma that was seen. Otherwise it is PRAGMA_NONE. */ ENUM_BITFIELD (pragma_kind) pragma_kind : 8; /* The value associated with this token, if any. */ tree value; /* The location at which this token was found. */ location_t location; } c_token; /* A parser structure recording information about the state and context of parsing. Includes lexer information with up to two tokens of look-ahead; more are not needed for C. */ typedef struct GTY(()) c_parser { /* The look-ahead tokens. */ c_token tokens[2]; /* How many look-ahead tokens are available (0, 1 or 2). */ short tokens_avail; /* True if a syntax error is being recovered from; false otherwise. c_parser_error sets this flag. It should clear this flag when enough tokens have been consumed to recover from the error. */ BOOL_BITFIELD error : 1; /* True if we're processing a pragma, and shouldn't automatically consume CPP_PRAGMA_EOL. */ BOOL_BITFIELD in_pragma : 1; /* True if we're parsing the outermost block of an if statement. */ BOOL_BITFIELD in_if_block : 1; /* True if we want to lex an untranslated string. */ BOOL_BITFIELD lex_untranslated_string : 1; /* Objective-C specific parser/lexer information. */ BOOL_BITFIELD objc_pq_context : 1; /* The following flag is needed to contextualize Objective-C lexical analysis. In some cases (e.g., 'int NSObject;'), it is undesirable to bind an identifier to an Objective-C class, even if a class with that name exists. */ BOOL_BITFIELD objc_need_raw_identifier : 1; } c_parser; /* The actual parser and external interface. ??? Does this need to be garbage-collected? */ static GTY (()) c_parser *the_parser; /* Read in and lex a single token, storing it in *TOKEN. */ static void c_lex_one_token (c_parser *parser, c_token *token) { timevar_push (TV_LEX); token->type = c_lex_with_flags (&token->value, &token->location, NULL, (parser->lex_untranslated_string ? C_LEX_STRING_NO_TRANSLATE : 0)); token->id_kind = C_ID_NONE; token->keyword = RID_MAX; token->pragma_kind = PRAGMA_NONE; switch (token->type) { case CPP_NAME: { tree decl; bool objc_force_identifier = parser->objc_need_raw_identifier; if (c_dialect_objc ()) parser->objc_need_raw_identifier = false; if (C_IS_RESERVED_WORD (token->value)) { enum rid rid_code = C_RID_CODE (token->value); if (rid_code == RID_CXX_COMPAT_WARN) { warning_at (token->location, OPT_Wc___compat, "identifier %qE conflicts with C++ keyword", token->value); } else if (rid_code >= RID_FIRST_ADDR_SPACE && rid_code <= RID_LAST_ADDR_SPACE) { token->id_kind = C_ID_ADDRSPACE; token->keyword = rid_code; break; } else if (c_dialect_objc ()) { if (!objc_is_reserved_word (token->value) && (!OBJC_IS_PQ_KEYWORD (rid_code) || parser->objc_pq_context)) { /* Return the canonical spelling for this keyword. */ token->value = ridpointers[(int) rid_code]; token->type = CPP_KEYWORD; token->keyword = rid_code; break; } } else { token->type = CPP_KEYWORD; token->keyword = rid_code; break; } } decl = lookup_name (token->value); if (decl) { if (TREE_CODE (decl) == TYPE_DECL) { token->id_kind = C_ID_TYPENAME; break; } } else if (c_dialect_objc ()) { tree objc_interface_decl = objc_is_class_name (token->value); /* Objective-C class names are in the same namespace as variables and typedefs, and hence are shadowed by local declarations. */ if (objc_interface_decl && (global_bindings_p () || (!objc_force_identifier && !decl))) { token->value = objc_interface_decl; token->id_kind = C_ID_CLASSNAME; break; } } token->id_kind = C_ID_ID; } break; case CPP_AT_NAME: /* This only happens in Objective-C; it must be a keyword. */ token->type = CPP_KEYWORD; token->keyword = C_RID_CODE (token->value); break; case CPP_COLON: case CPP_COMMA: case CPP_CLOSE_PAREN: case CPP_SEMICOLON: /* These tokens may affect the interpretation of any identifiers following, if doing Objective-C. */ if (c_dialect_objc ()) parser->objc_need_raw_identifier = false; break; case CPP_PRAGMA: /* We smuggled the cpp_token->u.pragma value in an INTEGER_CST. */ token->pragma_kind = (enum pragma_kind) TREE_INT_CST_LOW (token->value); token->value = NULL; break; default: break; } timevar_pop (TV_LEX); } /* Return a pointer to the next token from PARSER, reading it in if necessary. */ static inline c_token * c_parser_peek_token (c_parser *parser) { if (parser->tokens_avail == 0) { c_lex_one_token (parser, &parser->tokens[0]); parser->tokens_avail = 1; } return &parser->tokens[0]; } /* Return true if the next token from PARSER has the indicated TYPE. */ static inline bool c_parser_next_token_is (c_parser *parser, enum cpp_ttype type) { return c_parser_peek_token (parser)->type == type; } /* Return true if the next token from PARSER does not have the indicated TYPE. */ static inline bool c_parser_next_token_is_not (c_parser *parser, enum cpp_ttype type) { return !c_parser_next_token_is (parser, type); } /* Return true if the next token from PARSER is the indicated KEYWORD. */ static inline bool c_parser_next_token_is_keyword (c_parser *parser, enum rid keyword) { return c_parser_peek_token (parser)->keyword == keyword; } /* Return true if TOKEN can start a type name, false otherwise. */ static bool c_token_starts_typename (c_token *token) { switch (token->type) { case CPP_NAME: switch (token->id_kind) { case C_ID_ID: return false; case C_ID_ADDRSPACE: return true; case C_ID_TYPENAME: return true; case C_ID_CLASSNAME: gcc_assert (c_dialect_objc ()); return true; default: gcc_unreachable (); } case CPP_KEYWORD: switch (token->keyword) { case RID_UNSIGNED: case RID_LONG: case RID_SHORT: case RID_SIGNED: case RID_COMPLEX: case RID_INT: case RID_CHAR: case RID_FLOAT: case RID_DOUBLE: case RID_VOID: case RID_DFLOAT32: case RID_DFLOAT64: case RID_DFLOAT128: case RID_BOOL: case RID_ENUM: case RID_STRUCT: case RID_UNION: case RID_TYPEOF: case RID_CONST: case RID_VOLATILE: case RID_RESTRICT: case RID_ATTRIBUTE: case RID_FRACT: case RID_ACCUM: case RID_SAT: return true; default: return false; } case CPP_LESS: if (c_dialect_objc ()) return true; return false; default: return false; } } /* Return true if the next token from PARSER can start a type name, false otherwise. */ static inline bool c_parser_next_token_starts_typename (c_parser *parser) { c_token *token = c_parser_peek_token (parser); return c_token_starts_typename (token); } /* Return true if TOKEN can start declaration specifiers, false otherwise. */ static bool c_token_starts_declspecs (c_token *token) { switch (token->type) { case CPP_NAME: switch (token->id_kind) { case C_ID_ID: return false; case C_ID_ADDRSPACE: return true; case C_ID_TYPENAME: return true; case C_ID_CLASSNAME: gcc_assert (c_dialect_objc ()); return true; default: gcc_unreachable (); } case CPP_KEYWORD: switch (token->keyword) { case RID_STATIC: case RID_EXTERN: case RID_REGISTER: case RID_TYPEDEF: case RID_INLINE: case RID_AUTO: case RID_THREAD: case RID_UNSIGNED: case RID_LONG: case RID_SHORT: case RID_SIGNED: case RID_COMPLEX: case RID_INT: case RID_CHAR: case RID_FLOAT: case RID_DOUBLE: case RID_VOID: case RID_DFLOAT32: case RID_DFLOAT64: case RID_DFLOAT128: case RID_BOOL: case RID_ENUM: case RID_STRUCT: case RID_UNION: case RID_TYPEOF: case RID_CONST: case RID_VOLATILE: case RID_RESTRICT: case RID_ATTRIBUTE: case RID_FRACT: case RID_ACCUM: case RID_SAT: return true; default: return false; } case CPP_LESS: if (c_dialect_objc ()) return true; return false; default: return false; } } /* Return true if the next token from PARSER can start declaration specifiers, false otherwise. */ static inline bool c_parser_next_token_starts_declspecs (c_parser *parser) { c_token *token = c_parser_peek_token (parser); return c_token_starts_declspecs (token); } /* Return a pointer to the next-but-one token from PARSER, reading it in if necessary. The next token is already read in. */ static c_token * c_parser_peek_2nd_token (c_parser *parser) { if (parser->tokens_avail >= 2) return &parser->tokens[1]; gcc_assert (parser->tokens_avail == 1); gcc_assert (parser->tokens[0].type != CPP_EOF); gcc_assert (parser->tokens[0].type != CPP_PRAGMA_EOL); c_lex_one_token (parser, &parser->tokens[1]); parser->tokens_avail = 2; return &parser->tokens[1]; } /* Consume the next token from PARSER. */ static void c_parser_consume_token (c_parser *parser) { gcc_assert (parser->tokens_avail >= 1); gcc_assert (parser->tokens[0].type != CPP_EOF); gcc_assert (!parser->in_pragma || parser->tokens[0].type != CPP_PRAGMA_EOL); gcc_assert (parser->error || parser->tokens[0].type != CPP_PRAGMA); if (parser->tokens_avail == 2) parser->tokens[0] = parser->tokens[1]; parser->tokens_avail--; } /* Expect the current token to be a #pragma. Consume it and remember that we've begun parsing a pragma. */ static void c_parser_consume_pragma (c_parser *parser) { gcc_assert (!parser->in_pragma); gcc_assert (parser->tokens_avail >= 1); gcc_assert (parser->tokens[0].type == CPP_PRAGMA); if (parser->tokens_avail == 2) parser->tokens[0] = parser->tokens[1]; parser->tokens_avail--; parser->in_pragma = true; } /* Update the globals input_location and in_system_header from TOKEN. */ static inline void c_parser_set_source_position_from_token (c_token *token) { if (token->type != CPP_EOF) { input_location = token->location; } } /* Issue a diagnostic of the form FILE:LINE: MESSAGE before TOKEN where TOKEN is the next token in the input stream of PARSER. MESSAGE (specified by the caller) is usually of the form "expected OTHER-TOKEN". Do not issue a diagnostic if still recovering from an error. ??? This is taken from the C++ parser, but building up messages in this way is not i18n-friendly and some other approach should be used. */ static void c_parser_error (c_parser *parser, const char *gmsgid) { c_token *token = c_parser_peek_token (parser); if (parser->error) return; parser->error = true; if (!gmsgid) return; /* This diagnostic makes more sense if it is tagged to the line of the token we just peeked at. */ c_parser_set_source_position_from_token (token); c_parse_error (gmsgid, /* Because c_parse_error does not understand CPP_KEYWORD, keywords are treated like identifiers. */ (token->type == CPP_KEYWORD ? CPP_NAME : token->type), /* ??? The C parser does not save the cpp flags of a token, we need to pass 0 here and we will not get the source spelling of some tokens but rather the canonical spelling. */ token->value, /*flags=*/0); } /* If the next token is of the indicated TYPE, consume it. Otherwise, issue the error MSGID. If MSGID is NULL then a message has already been produced and no message will be produced this time. Returns true if found, false otherwise. */ static bool c_parser_require (c_parser *parser, enum cpp_ttype type, const char *msgid) { if (c_parser_next_token_is (parser, type)) { c_parser_consume_token (parser); return true; } else { c_parser_error (parser, msgid); return false; } } /* If the next token is the indicated keyword, consume it. Otherwise, issue the error MSGID. Returns true if found, false otherwise. */ static bool c_parser_require_keyword (c_parser *parser, enum rid keyword, const char *msgid) { if (c_parser_next_token_is_keyword (parser, keyword)) { c_parser_consume_token (parser); return true; } else { c_parser_error (parser, msgid); return false; } } /* Like c_parser_require, except that tokens will be skipped until the desired token is found. An error message is still produced if the next token is not as expected. If MSGID is NULL then a message has already been produced and no message will be produced this time. */ static void c_parser_skip_until_found (c_parser *parser, enum cpp_ttype type, const char *msgid) { unsigned nesting_depth = 0; if (c_parser_require (parser, type, msgid)) return; /* Skip tokens until the desired token is found. */ while (true) { /* Peek at the next token. */ c_token *token = c_parser_peek_token (parser); /* If we've reached the token we want, consume it and stop. */ if (token->type == type && !nesting_depth) { c_parser_consume_token (parser); break; } /* If we've run out of tokens, stop. */ if (token->type == CPP_EOF) return; if (token->type == CPP_PRAGMA_EOL && parser->in_pragma) return; if (token->type == CPP_OPEN_BRACE || token->type == CPP_OPEN_PAREN || token->type == CPP_OPEN_SQUARE) ++nesting_depth; else if (token->type == CPP_CLOSE_BRACE || token->type == CPP_CLOSE_PAREN || token->type == CPP_CLOSE_SQUARE) { if (nesting_depth-- == 0) break; } /* Consume this token. */ c_parser_consume_token (parser); } parser->error = false; } /* Skip tokens until the end of a parameter is found, but do not consume the comma, semicolon or closing delimiter. */ static void c_parser_skip_to_end_of_parameter (c_parser *parser) { unsigned nesting_depth = 0; while (true) { c_token *token = c_parser_peek_token (parser); if ((token->type == CPP_COMMA || token->type == CPP_SEMICOLON) && !nesting_depth) break; /* If we've run out of tokens, stop. */ if (token->type == CPP_EOF) return; if (token->type == CPP_PRAGMA_EOL && parser->in_pragma) return; if (token->type == CPP_OPEN_BRACE || token->type == CPP_OPEN_PAREN || token->type == CPP_OPEN_SQUARE) ++nesting_depth; else if (token->type == CPP_CLOSE_BRACE || token->type == CPP_CLOSE_PAREN || token->type == CPP_CLOSE_SQUARE) { if (nesting_depth-- == 0) break; } /* Consume this token. */ c_parser_consume_token (parser); } parser->error = false; } /* Expect to be at the end of the pragma directive and consume an end of line marker. */ static void c_parser_skip_to_pragma_eol (c_parser *parser) { gcc_assert (parser->in_pragma); parser->in_pragma = false; if (!c_parser_require (parser, CPP_PRAGMA_EOL, "expected end of line")) while (true) { c_token *token = c_parser_peek_token (parser); if (token->type == CPP_EOF) break; if (token->type == CPP_PRAGMA_EOL) { c_parser_consume_token (parser); break; } c_parser_consume_token (parser); } parser->error = false; } /* Skip tokens until we have consumed an entire block, or until we have consumed a non-nested ';'. */ static void c_parser_skip_to_end_of_block_or_statement (c_parser *parser) { unsigned nesting_depth = 0; bool save_error = parser->error; while (true) { c_token *token; /* Peek at the next token. */ token = c_parser_peek_token (parser); switch (token->type) { case CPP_EOF: return; case CPP_PRAGMA_EOL: if (parser->in_pragma) return; break; case CPP_SEMICOLON: /* If the next token is a ';', we have reached the end of the statement. */ if (!nesting_depth) { /* Consume the ';'. */ c_parser_consume_token (parser); goto finished; } break; case CPP_CLOSE_BRACE: /* If the next token is a non-nested '}', then we have reached the end of the current block. */ if (nesting_depth == 0 || --nesting_depth == 0) { c_parser_consume_token (parser); goto finished; } break; case CPP_OPEN_BRACE: /* If it the next token is a '{', then we are entering a new block. Consume the entire block. */ ++nesting_depth; break; case CPP_PRAGMA: /* If we see a pragma, consume the whole thing at once. We have some safeguards against consuming pragmas willy-nilly. Normally, we'd expect to be here with parser->error set, which disables these safeguards. But it's possible to get here for secondary error recovery, after parser->error has been cleared. */ c_parser_consume_pragma (parser); c_parser_skip_to_pragma_eol (parser); parser->error = save_error; continue; default: break; } c_parser_consume_token (parser); } finished: parser->error = false; } /* CPP's options (initialized by c-opts.c). */ extern cpp_options *cpp_opts; /* Save the warning flags which are controlled by __extension__. */ static inline int disable_extension_diagnostics (void) { int ret = (pedantic | (warn_pointer_arith << 1) | (warn_traditional << 2) | (flag_iso << 3) | (warn_long_long << 4) | (warn_cxx_compat << 5)); cpp_opts->pedantic = pedantic = 0; warn_pointer_arith = 0; cpp_opts->warn_traditional = warn_traditional = 0; flag_iso = 0; cpp_opts->warn_long_long = warn_long_long = 0; warn_cxx_compat = 0; return ret; } /* Restore the warning flags which are controlled by __extension__. FLAGS is the return value from disable_extension_diagnostics. */ static inline void restore_extension_diagnostics (int flags) { cpp_opts->pedantic = pedantic = flags & 1; warn_pointer_arith = (flags >> 1) & 1; cpp_opts->warn_traditional = warn_traditional = (flags >> 2) & 1; flag_iso = (flags >> 3) & 1; cpp_opts->warn_long_long = warn_long_long = (flags >> 4) & 1; warn_cxx_compat = (flags >> 5) & 1; } /* Possibly kinds of declarator to parse. */ typedef enum c_dtr_syn { /* A normal declarator with an identifier. */ C_DTR_NORMAL, /* An abstract declarator (maybe empty). */ C_DTR_ABSTRACT, /* A parameter declarator: may be either, but after a type name does not redeclare a typedef name as an identifier if it can alternatively be interpreted as a typedef name; see DR#009, applied in C90 TC1, omitted from C99 and reapplied in C99 TC2 following DR#249. For example, given a typedef T, "int T" and "int *T" are valid parameter declarations redeclaring T, while "int (T)" and "int * (T)" and "int (T[])" and "int (T (int))" are abstract declarators rather than involving redundant parentheses; the same applies with attributes inside the parentheses before "T". */ C_DTR_PARM } c_dtr_syn; static void c_parser_external_declaration (c_parser *); static void c_parser_asm_definition (c_parser *); static void c_parser_declaration_or_fndef (c_parser *, bool, bool, bool, bool); static void c_parser_declspecs (c_parser *, struct c_declspecs *, bool, bool, bool); static struct c_typespec c_parser_enum_specifier (c_parser *); static struct c_typespec c_parser_struct_or_union_specifier (c_parser *); static tree c_parser_struct_declaration (c_parser *); static struct c_typespec c_parser_typeof_specifier (c_parser *); static struct c_declarator *c_parser_declarator (c_parser *, bool, c_dtr_syn, bool *); static struct c_declarator *c_parser_direct_declarator (c_parser *, bool, c_dtr_syn, bool *); static struct c_declarator *c_parser_direct_declarator_inner (c_parser *, bool, struct c_declarator *); static struct c_arg_info *c_parser_parms_declarator (c_parser *, bool, tree); static struct c_arg_info *c_parser_parms_list_declarator (c_parser *, tree); static struct c_parm *c_parser_parameter_declaration (c_parser *, tree); static tree c_parser_simple_asm_expr (c_parser *); static tree c_parser_attributes (c_parser *); static struct c_type_name *c_parser_type_name (c_parser *); static struct c_expr c_parser_initializer (c_parser *); static struct c_expr c_parser_braced_init (c_parser *, tree, bool); static void c_parser_initelt (c_parser *); static void c_parser_initval (c_parser *, struct c_expr *); static tree c_parser_compound_statement (c_parser *); static void c_parser_compound_statement_nostart (c_parser *); static void c_parser_label (c_parser *); static void c_parser_statement (c_parser *); static void c_parser_statement_after_labels (c_parser *); static void c_parser_if_statement (c_parser *); static void c_parser_switch_statement (c_parser *); static void c_parser_while_statement (c_parser *); static void c_parser_do_statement (c_parser *); static void c_parser_for_statement (c_parser *); static tree c_parser_asm_statement (c_parser *); static tree c_parser_asm_operands (c_parser *, bool); static tree c_parser_asm_goto_operands (c_parser *); static tree c_parser_asm_clobbers (c_parser *); static struct c_expr c_parser_expr_no_commas (c_parser *, struct c_expr *); static struct c_expr c_parser_conditional_expression (c_parser *, struct c_expr *); static struct c_expr c_parser_binary_expression (c_parser *, struct c_expr *); static struct c_expr c_parser_cast_expression (c_parser *, struct c_expr *); static struct c_expr c_parser_unary_expression (c_parser *); static struct c_expr c_parser_sizeof_expression (c_parser *); static struct c_expr c_parser_alignof_expression (c_parser *); static struct c_expr c_parser_postfix_expression (c_parser *); static struct c_expr c_parser_postfix_expression_after_paren_type (c_parser *, struct c_type_name *, location_t); static struct c_expr c_parser_postfix_expression_after_primary (c_parser *, location_t loc, struct c_expr); static struct c_expr c_parser_expression (c_parser *); static struct c_expr c_parser_expression_conv (c_parser *); static VEC(tree,gc) *c_parser_expr_list (c_parser *, bool, bool, VEC(tree,gc) **); static void c_parser_omp_construct (c_parser *); static void c_parser_omp_threadprivate (c_parser *); static void c_parser_omp_barrier (c_parser *); static void c_parser_omp_flush (c_parser *); static void c_parser_omp_taskwait (c_parser *); enum pragma_context { pragma_external, pragma_stmt, pragma_compound }; static bool c_parser_pragma (c_parser *, enum pragma_context); /* These Objective-C parser functions are only ever called when compiling Objective-C. */ static void c_parser_objc_class_definition (c_parser *); static void c_parser_objc_class_instance_variables (c_parser *); static void c_parser_objc_class_declaration (c_parser *); static void c_parser_objc_alias_declaration (c_parser *); static void c_parser_objc_protocol_definition (c_parser *); static enum tree_code c_parser_objc_method_type (c_parser *); static void c_parser_objc_method_definition (c_parser *); static void c_parser_objc_methodprotolist (c_parser *); static void c_parser_objc_methodproto (c_parser *); static tree c_parser_objc_method_decl (c_parser *); static tree c_parser_objc_type_name (c_parser *); static tree c_parser_objc_protocol_refs (c_parser *); static void c_parser_objc_try_catch_statement (c_parser *); static void c_parser_objc_synchronized_statement (c_parser *); static tree c_parser_objc_selector (c_parser *); static tree c_parser_objc_selector_arg (c_parser *); static tree c_parser_objc_receiver (c_parser *); static tree c_parser_objc_message_args (c_parser *); static tree c_parser_objc_keywordexpr (c_parser *); /* Parse a translation unit (C90 6.7, C99 6.9). translation-unit: external-declarations external-declarations: external-declaration external-declarations external-declaration GNU extensions: translation-unit: empty */ static void c_parser_translation_unit (c_parser *parser) { if (c_parser_next_token_is (parser, CPP_EOF)) { pedwarn (c_parser_peek_token (parser)->location, OPT_pedantic, "ISO C forbids an empty translation unit"); } else { void *obstack_position = obstack_alloc (&parser_obstack, 0); mark_valid_location_for_stdc_pragma (false); do { ggc_collect (); c_parser_external_declaration (parser); obstack_free (&parser_obstack, obstack_position); } while (c_parser_next_token_is_not (parser, CPP_EOF)); } } /* Parse an external declaration (C90 6.7, C99 6.9). external-declaration: function-definition declaration GNU extensions: external-declaration: asm-definition ; __extension__ external-declaration Objective-C: external-declaration: objc-class-definition objc-class-declaration objc-alias-declaration objc-protocol-definition objc-method-definition @end */ static void c_parser_external_declaration (c_parser *parser) { int ext; switch (c_parser_peek_token (parser)->type) { case CPP_KEYWORD: switch (c_parser_peek_token (parser)->keyword) { case RID_EXTENSION: ext = disable_extension_diagnostics (); c_parser_consume_token (parser); c_parser_external_declaration (parser); restore_extension_diagnostics (ext); break; case RID_ASM: c_parser_asm_definition (parser); break; case RID_AT_INTERFACE: case RID_AT_IMPLEMENTATION: gcc_assert (c_dialect_objc ()); c_parser_objc_class_definition (parser); break; case RID_CLASS: gcc_assert (c_dialect_objc ()); c_parser_objc_class_declaration (parser); break; case RID_AT_ALIAS: gcc_assert (c_dialect_objc ()); c_parser_objc_alias_declaration (parser); break; case RID_AT_PROTOCOL: gcc_assert (c_dialect_objc ()); c_parser_objc_protocol_definition (parser); break; case RID_AT_END: gcc_assert (c_dialect_objc ()); c_parser_consume_token (parser); objc_finish_implementation (); break; default: goto decl_or_fndef; } break; case CPP_SEMICOLON: pedwarn (c_parser_peek_token (parser)->location, OPT_pedantic, "ISO C does not allow extra %<;%> outside of a function"); c_parser_consume_token (parser); break; case CPP_PRAGMA: mark_valid_location_for_stdc_pragma (true); c_parser_pragma (parser, pragma_external); mark_valid_location_for_stdc_pragma (false); break; case CPP_PLUS: case CPP_MINUS: if (c_dialect_objc ()) { c_parser_objc_method_definition (parser); break; } /* Else fall through, and yield a syntax error trying to parse as a declaration or function definition. */ default: decl_or_fndef: /* A declaration or a function definition. We can only tell which after parsing the declaration specifiers, if any, and the first declarator. */ c_parser_declaration_or_fndef (parser, true, true, false, true); break; } } /* Parse a declaration or function definition (C90 6.5, 6.7.1, C99 6.7, 6.9.1). If FNDEF_OK is true, a function definition is accepted; otherwise (old-style parameter declarations) only other declarations are accepted. If NESTED is true, we are inside a function or parsing old-style parameter declarations; any functions encountered are nested functions and declaration specifiers are required; otherwise we are at top level and functions are normal functions and declaration specifiers may be optional. If EMPTY_OK is true, empty declarations are OK (subject to all other constraints); otherwise (old-style parameter declarations) they are diagnosed. If START_ATTR_OK is true, the declaration specifiers may start with attributes; otherwise they may not. declaration: declaration-specifiers init-declarator-list[opt] ; function-definition: declaration-specifiers[opt] declarator declaration-list[opt] compound-statement declaration-list: declaration declaration-list declaration init-declarator-list: init-declarator init-declarator-list , init-declarator init-declarator: declarator simple-asm-expr[opt] attributes[opt] declarator simple-asm-expr[opt] attributes[opt] = initializer GNU extensions: nested-function-definition: declaration-specifiers declarator declaration-list[opt] compound-statement The simple-asm-expr and attributes are GNU extensions. This function does not handle __extension__; that is handled in its callers. ??? Following the old parser, __extension__ may start external declarations, declarations in functions and declarations at the start of "for" loops, but not old-style parameter declarations. C99 requires declaration specifiers in a function definition; the absence is diagnosed through the diagnosis of implicit int. In GNU C we also allow but diagnose declarations without declaration specifiers, but only at top level (elsewhere they conflict with other syntax). OpenMP: declaration: threadprivate-directive */ static void c_parser_declaration_or_fndef (c_parser *parser, bool fndef_ok, bool empty_ok, bool nested, bool start_attr_ok) { struct c_declspecs *specs; tree prefix_attrs; tree all_prefix_attrs; bool diagnosed_no_specs = false; location_t here = c_parser_peek_token (parser)->location; specs = build_null_declspecs (); c_parser_declspecs (parser, specs, true, true, start_attr_ok); if (parser->error) { c_parser_skip_to_end_of_block_or_statement (parser); return; } if (nested && !specs->declspecs_seen_p) { c_parser_error (parser, "expected declaration specifiers"); c_parser_skip_to_end_of_block_or_statement (parser); return; } finish_declspecs (specs); if (c_parser_next_token_is (parser, CPP_SEMICOLON)) { if (empty_ok) shadow_tag (specs); else { shadow_tag_warned (specs, 1); pedwarn (here, 0, "empty declaration"); } c_parser_consume_token (parser); return; } pending_xref_error (); prefix_attrs = specs->attrs; all_prefix_attrs = prefix_attrs; specs->attrs = NULL_TREE; while (true) { struct c_declarator *declarator; bool dummy = false; tree fnbody; /* Declaring either one or more declarators (in which case we should diagnose if there were no declaration specifiers) or a function definition (in which case the diagnostic for implicit int suffices). */ declarator = c_parser_declarator (parser, specs->type_seen_p, C_DTR_NORMAL, &dummy); if (declarator == NULL) { c_parser_skip_to_end_of_block_or_statement (parser); return; } if (c_parser_next_token_is (parser, CPP_EQ) || c_parser_next_token_is (parser, CPP_COMMA) || c_parser_next_token_is (parser, CPP_SEMICOLON) || c_parser_next_token_is_keyword (parser, RID_ASM) || c_parser_next_token_is_keyword (parser, RID_ATTRIBUTE)) { tree asm_name = NULL_TREE; tree postfix_attrs = NULL_TREE; if (!diagnosed_no_specs && !specs->declspecs_seen_p) { diagnosed_no_specs = true; pedwarn (here, 0, "data definition has no type or storage class"); } /* Having seen a data definition, there cannot now be a function definition. */ fndef_ok = false; if (c_parser_next_token_is_keyword (parser, RID_ASM)) asm_name = c_parser_simple_asm_expr (parser); if (c_parser_next_token_is_keyword (parser, RID_ATTRIBUTE)) postfix_attrs = c_parser_attributes (parser); if (c_parser_next_token_is (parser, CPP_EQ)) { tree d; struct c_expr init; location_t init_loc; c_parser_consume_token (parser); /* The declaration of the variable is in effect while its initializer is parsed. */ d = start_decl (declarator, specs, true, chainon (postfix_attrs, all_prefix_attrs)); if (!d) d = error_mark_node; start_init (d, asm_name, global_bindings_p ()); init_loc = c_parser_peek_token (parser)->location; init = c_parser_initializer (parser); finish_init (); if (d != error_mark_node) { maybe_warn_string_init (TREE_TYPE (d), init); finish_decl (d, init_loc, init.value, init.original_type, asm_name); } } else { tree d = start_decl (declarator, specs, false, chainon (postfix_attrs, all_prefix_attrs)); if (d) finish_decl (d, UNKNOWN_LOCATION, NULL_TREE, NULL_TREE, asm_name); } if (c_parser_next_token_is (parser, CPP_COMMA)) { c_parser_consume_token (parser); if (c_parser_next_token_is_keyword (parser, RID_ATTRIBUTE)) all_prefix_attrs = chainon (c_parser_attributes (parser), prefix_attrs); else all_prefix_attrs = prefix_attrs; continue; } else if (c_parser_next_token_is (parser, CPP_SEMICOLON)) { c_parser_consume_token (parser); return; } else { c_parser_error (parser, "expected %<,%> or %<;%>"); c_parser_skip_to_end_of_block_or_statement (parser); return; } } else if (!fndef_ok) { c_parser_error (parser, "expected %<=%>, %<,%>, %<;%>, " "%<asm%> or %<__attribute__%>"); c_parser_skip_to_end_of_block_or_statement (parser); return; } /* Function definition (nested or otherwise). */ if (nested) { pedwarn (here, OPT_pedantic, "ISO C forbids nested functions"); c_push_function_context (); } if (!start_function (specs, declarator, all_prefix_attrs)) { /* This can appear in many cases looking nothing like a function definition, so we don't give a more specific error suggesting there was one. */ c_parser_error (parser, "expected %<=%>, %<,%>, %<;%>, %<asm%> " "or %<__attribute__%>"); if (nested) c_pop_function_context (); break; } /* Parse old-style parameter declarations. ??? Attributes are not allowed to start declaration specifiers here because of a syntax conflict between a function declaration with attribute suffix and a function definition with an attribute prefix on first old-style parameter declaration. Following the old parser, they are not accepted on subsequent old-style parameter declarations either. However, there is no ambiguity after the first declaration, nor indeed on the first as long as we don't allow postfix attributes after a declarator with a nonempty identifier list in a definition; and postfix attributes have never been accepted here in function definitions either. */ while (c_parser_next_token_is_not (parser, CPP_EOF) && c_parser_next_token_is_not (parser, CPP_OPEN_BRACE)) c_parser_declaration_or_fndef (parser, false, false, true, false); store_parm_decls (); DECL_STRUCT_FUNCTION (current_function_decl)->function_start_locus = c_parser_peek_token (parser)->location; fnbody = c_parser_compound_statement (parser); if (nested) { tree decl = current_function_decl; /* Mark nested functions as needing static-chain initially. lower_nested_functions will recompute it but the DECL_STATIC_CHAIN flag is also used before that happens, by initializer_constant_valid_p. See gcc.dg/nested-fn-2.c. */ DECL_STATIC_CHAIN (decl) = 1; add_stmt (fnbody); finish_function (); c_pop_function_context (); add_stmt (build_stmt (DECL_SOURCE_LOCATION (decl), DECL_EXPR, decl)); } else { add_stmt (fnbody); finish_function (); } break; } } /* Parse an asm-definition (asm() outside a function body). This is a GNU extension. asm-definition: simple-asm-expr ; */ static void c_parser_asm_definition (c_parser *parser) { tree asm_str = c_parser_simple_asm_expr (parser); if (asm_str) cgraph_add_asm_node (asm_str); c_parser_skip_until_found (parser, CPP_SEMICOLON, "expected %<;%>"); } /* Parse some declaration specifiers (possibly none) (C90 6.5, C99 6.7), adding them to SPECS (which may already include some). Storage class specifiers are accepted iff SCSPEC_OK; type specifiers are accepted iff TYPESPEC_OK; attributes are accepted at the start iff START_ATTR_OK. declaration-specifiers: storage-class-specifier declaration-specifiers[opt] type-specifier declaration-specifiers[opt] type-qualifier declaration-specifiers[opt] function-specifier declaration-specifiers[opt] Function specifiers (inline) are from C99, and are currently handled as storage class specifiers, as is __thread. C90 6.5.1, C99 6.7.1: storage-class-specifier: typedef extern static auto register C99 6.7.4: function-specifier: inline C90 6.5.2, C99 6.7.2: type-specifier: void char short int long float double signed unsigned _Bool _Complex [_Imaginary removed in C99 TC2] struct-or-union-specifier enum-specifier typedef-name (_Bool and _Complex are new in C99.) C90 6.5.3, C99 6.7.3: type-qualifier: const restrict volatile address-space-qualifier (restrict is new in C99.) GNU extensions: declaration-specifiers: attributes declaration-specifiers[opt] type-qualifier: address-space address-space: identifier recognized by the target storage-class-specifier: __thread type-specifier: typeof-specifier _Decimal32 _Decimal64 _Decimal128 _Fract _Accum _Sat (_Fract, _Accum, and _Sat are new from ISO/IEC DTR 18037: http://www.open-std.org/jtc1/sc22/wg14/www/docs/n1169.pdf) Objective-C: type-specifier: class-name objc-protocol-refs[opt] typedef-name objc-protocol-refs objc-protocol-refs */ static void c_parser_declspecs (c_parser *parser, struct c_declspecs *specs, bool scspec_ok, bool typespec_ok, bool start_attr_ok) { bool attrs_ok = start_attr_ok; bool seen_type = specs->type_seen_p; while (c_parser_next_token_is (parser, CPP_NAME) || c_parser_next_token_is (parser, CPP_KEYWORD) || (c_dialect_objc () && c_parser_next_token_is (parser, CPP_LESS))) { struct c_typespec t; tree attrs; location_t loc = c_parser_peek_token (parser)->location; if (c_parser_next_token_is (parser, CPP_NAME)) { tree value = c_parser_peek_token (parser)->value; c_id_kind kind = c_parser_peek_token (parser)->id_kind; if (kind == C_ID_ADDRSPACE) { addr_space_t as = c_parser_peek_token (parser)->keyword - RID_FIRST_ADDR_SPACE; declspecs_add_addrspace (specs, as); c_parser_consume_token (parser); attrs_ok = true; continue; } /* This finishes the specifiers unless a type name is OK, it is declared as a type name and a type name hasn't yet been seen. */ if (!typespec_ok || seen_type || (kind != C_ID_TYPENAME && kind != C_ID_CLASSNAME)) break; c_parser_consume_token (parser); seen_type = true; attrs_ok = true; if (kind == C_ID_TYPENAME && (!c_dialect_objc () || c_parser_next_token_is_not (parser, CPP_LESS))) { t.kind = ctsk_typedef; /* For a typedef name, record the meaning, not the name. In case of 'foo foo, bar;'. */ t.spec = lookup_name (value); t.expr = NULL_TREE; t.expr_const_operands = true; } else { tree proto = NULL_TREE; gcc_assert (c_dialect_objc ()); t.kind = ctsk_objc; if (c_parser_next_token_is (parser, CPP_LESS)) proto = c_parser_objc_protocol_refs (parser); t.spec = objc_get_protocol_qualified_type (value, proto); t.expr = NULL_TREE; t.expr_const_operands = true; } declspecs_add_type (loc, specs, t); continue; } if (c_parser_next_token_is (parser, CPP_LESS)) { /* Make "<SomeProtocol>" equivalent to "id <SomeProtocol>" - nisse@lysator.liu.se. */ tree proto; gcc_assert (c_dialect_objc ()); if (!typespec_ok || seen_type) break; proto = c_parser_objc_protocol_refs (parser); t.kind = ctsk_objc; t.spec = objc_get_protocol_qualified_type (NULL_TREE, proto); t.expr = NULL_TREE; t.expr_const_operands = true; declspecs_add_type (loc, specs, t); continue; } gcc_assert (c_parser_next_token_is (parser, CPP_KEYWORD)); switch (c_parser_peek_token (parser)->keyword) { case RID_STATIC: case RID_EXTERN: case RID_REGISTER: case RID_TYPEDEF: case RID_INLINE: case RID_AUTO: case RID_THREAD: if (!scspec_ok) goto out; attrs_ok = true; /* TODO: Distinguish between function specifiers (inline) and storage class specifiers, either here or in declspecs_add_scspec. */ declspecs_add_scspec (specs, c_parser_peek_token (parser)->value); c_parser_consume_token (parser); break; case RID_UNSIGNED: case RID_LONG: case RID_SHORT: case RID_SIGNED: case RID_COMPLEX: case RID_INT: case RID_CHAR: case RID_FLOAT: case RID_DOUBLE: case RID_VOID: case RID_DFLOAT32: case RID_DFLOAT64: case RID_DFLOAT128: case RID_BOOL: case RID_FRACT: case RID_ACCUM: case RID_SAT: if (!typespec_ok) goto out; attrs_ok = true; seen_type = true; if (c_dialect_objc ()) parser->objc_need_raw_identifier = true; t.kind = ctsk_resword; t.spec = c_parser_peek_token (parser)->value; t.expr = NULL_TREE; t.expr_const_operands = true; declspecs_add_type (loc, specs, t); c_parser_consume_token (parser); break; case RID_ENUM: if (!typespec_ok) goto out; attrs_ok = true; seen_type = true; t = c_parser_enum_specifier (parser); declspecs_add_type (loc, specs, t); break; case RID_STRUCT: case RID_UNION: if (!typespec_ok) goto out; attrs_ok = true; seen_type = true; t = c_parser_struct_or_union_specifier (parser); invoke_plugin_callbacks (PLUGIN_FINISH_TYPE, t.spec); declspecs_add_type (loc, specs, t); break; case RID_TYPEOF: /* ??? The old parser rejected typeof after other type specifiers, but is a syntax error the best way of handling this? */ if (!typespec_ok || seen_type) goto out; attrs_ok = true; seen_type = true; t = c_parser_typeof_specifier (parser); declspecs_add_type (loc, specs, t); break; case RID_CONST: case RID_VOLATILE: case RID_RESTRICT: attrs_ok = true; declspecs_add_qual (specs, c_parser_peek_token (parser)->value); c_parser_consume_token (parser); break; case RID_ATTRIBUTE: if (!attrs_ok) goto out; attrs = c_parser_attributes (parser); declspecs_add_attrs (specs, attrs); break; default: goto out; } } out: ; } /* Parse an enum specifier (C90 6.5.2.2, C99 6.7.2.2). enum-specifier: enum attributes[opt] identifier[opt] { enumerator-list } attributes[opt] enum attributes[opt] identifier[opt] { enumerator-list , } attributes[opt] enum attributes[opt] identifier The form with trailing comma is new in C99. The forms with attributes are GNU extensions. In GNU C, we accept any expression without commas in the syntax (assignment expressions, not just conditional expressions); assignment expressions will be diagnosed as non-constant. enumerator-list: enumerator enumerator-list , enumerator enumerator: enumeration-constant enumeration-constant = constant-expression */ static struct c_typespec c_parser_enum_specifier (c_parser *parser) { struct c_typespec ret; tree attrs; tree ident = NULL_TREE; location_t enum_loc; location_t ident_loc = UNKNOWN_LOCATION; /* Quiet warning. */ gcc_assert (c_parser_next_token_is_keyword (parser, RID_ENUM)); enum_loc = c_parser_peek_token (parser)->location; c_parser_consume_token (parser); attrs = c_parser_attributes (parser); enum_loc = c_parser_peek_token (parser)->location; /* Set the location in case we create a decl now. */ c_parser_set_source_position_from_token (c_parser_peek_token (parser)); if (c_parser_next_token_is (parser, CPP_NAME)) { ident = c_parser_peek_token (parser)->value; ident_loc = c_parser_peek_token (parser)->location; enum_loc = ident_loc; c_parser_consume_token (parser); } if (c_parser_next_token_is (parser, CPP_OPEN_BRACE)) { /* Parse an enum definition. */ struct c_enum_contents the_enum; tree type = start_enum (enum_loc, &the_enum, ident); tree postfix_attrs; /* We chain the enumerators in reverse order, then put them in forward order at the end. */ tree values = NULL_TREE; c_parser_consume_token (parser); while (true) { tree enum_id; tree enum_value; tree enum_decl; bool seen_comma; c_token *token; location_t comma_loc = UNKNOWN_LOCATION; /* Quiet warning. */ location_t value_loc; if (c_parser_next_token_is_not (parser, CPP_NAME)) { c_parser_error (parser, "expected identifier"); c_parser_skip_until_found (parser, CPP_CLOSE_BRACE, NULL); values = error_mark_node; break; } token = c_parser_peek_token (parser); enum_id = token->value; /* Set the location in case we create a decl now. */ c_parser_set_source_position_from_token (token); value_loc = token->location; c_parser_consume_token (parser); if (c_parser_next_token_is (parser, CPP_EQ)) { c_parser_consume_token (parser); value_loc = c_parser_peek_token (parser)->location; enum_value = c_parser_expr_no_commas (parser, NULL).value; } else enum_value = NULL_TREE; enum_decl = build_enumerator (value_loc, &the_enum, enum_id, enum_value); TREE_CHAIN (enum_decl) = values; values = enum_decl; seen_comma = false; if (c_parser_next_token_is (parser, CPP_COMMA)) { comma_loc = c_parser_peek_token (parser)->location; seen_comma = true; c_parser_consume_token (parser); } if (c_parser_next_token_is (parser, CPP_CLOSE_BRACE)) { if (seen_comma && !flag_isoc99) pedwarn (comma_loc, OPT_pedantic, "comma at end of enumerator list"); c_parser_consume_token (parser); break; } if (!seen_comma) { c_parser_error (parser, "expected %<,%> or %<}%>"); c_parser_skip_until_found (parser, CPP_CLOSE_BRACE, NULL); values = error_mark_node; break; } } postfix_attrs = c_parser_attributes (parser); ret.spec = finish_enum (type, nreverse (values), chainon (attrs, postfix_attrs)); ret.kind = ctsk_tagdef; ret.expr = NULL_TREE; ret.expr_const_operands = true; return ret; } else if (!ident) { c_parser_error (parser, "expected %<{%>"); ret.spec = error_mark_node; ret.kind = ctsk_tagref; ret.expr = NULL_TREE; ret.expr_const_operands = true; return ret; } ret = parser_xref_tag (ident_loc, ENUMERAL_TYPE, ident); /* In ISO C, enumerated types can be referred to only if already defined. */ if (pedantic && !COMPLETE_TYPE_P (ret.spec)) { gcc_assert (ident); pedwarn (enum_loc, OPT_pedantic, "ISO C forbids forward references to %<enum%> types"); } return ret; } /* Parse a struct or union specifier (C90 6.5.2.1, C99 6.7.2.1). struct-or-union-specifier: struct-or-union attributes[opt] identifier[opt] { struct-contents } attributes[opt] struct-or-union attributes[opt] identifier struct-contents: struct-declaration-list struct-declaration-list: struct-declaration ; struct-declaration-list struct-declaration ; GNU extensions: struct-contents: empty struct-declaration struct-declaration-list struct-declaration struct-declaration-list: struct-declaration-list ; ; (Note that in the syntax here, unlike that in ISO C, the semicolons are included here rather than in struct-declaration, in order to describe the syntax with extra semicolons and missing semicolon at end.) Objective-C: struct-declaration-list: @defs ( class-name ) (Note this does not include a trailing semicolon, but can be followed by further declarations, and gets a pedwarn-if-pedantic when followed by a semicolon.) */ static struct c_typespec c_parser_struct_or_union_specifier (c_parser *parser) { struct c_typespec ret; tree attrs; tree ident = NULL_TREE; location_t struct_loc; location_t ident_loc = UNKNOWN_LOCATION; enum tree_code code; switch (c_parser_peek_token (parser)->keyword) { case RID_STRUCT: code = RECORD_TYPE; break; case RID_UNION: code = UNION_TYPE; break; default: gcc_unreachable (); } struct_loc = c_parser_peek_token (parser)->location; c_parser_consume_token (parser); attrs = c_parser_attributes (parser); /* Set the location in case we create a decl now. */ c_parser_set_source_position_from_token (c_parser_peek_token (parser)); if (c_parser_next_token_is (parser, CPP_NAME)) { ident = c_parser_peek_token (parser)->value; ident_loc = c_parser_peek_token (parser)->location; struct_loc = ident_loc; c_parser_consume_token (parser); } if (c_parser_next_token_is (parser, CPP_OPEN_BRACE)) { /* Parse a struct or union definition. Start the scope of the tag before parsing components. */ struct c_struct_parse_info *struct_info; tree type = start_struct (struct_loc, code, ident, &struct_info); tree postfix_attrs; /* We chain the components in reverse order, then put them in forward order at the end. Each struct-declaration may declare multiple components (comma-separated), so we must use chainon to join them, although when parsing each struct-declaration we can use TREE_CHAIN directly. The theory behind all this is that there will be more semicolon separated fields than comma separated fields, and so we'll be minimizing the number of node traversals required by chainon. */ tree contents = NULL_TREE; c_parser_consume_token (parser); /* Handle the Objective-C @defs construct, e.g. foo(sizeof(struct{ @defs(ClassName) }));. */ if (c_parser_next_token_is_keyword (parser, RID_AT_DEFS)) { tree name; gcc_assert (c_dialect_objc ()); c_parser_consume_token (parser); if (!c_parser_require (parser, CPP_OPEN_PAREN, "expected %<(%>")) goto end_at_defs; if (c_parser_next_token_is (parser, CPP_NAME) && c_parser_peek_token (parser)->id_kind == C_ID_CLASSNAME) { name = c_parser_peek_token (parser)->value; c_parser_consume_token (parser); } else { c_parser_error (parser, "expected class name"); c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, NULL); goto end_at_defs; } c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, "expected %<)%>"); contents = nreverse (objc_get_class_ivars (name)); } end_at_defs: /* Parse the struct-declarations and semicolons. Problems with semicolons are diagnosed here; empty structures are diagnosed elsewhere. */ while (true) { tree decls; /* Parse any stray semicolon. */ if (c_parser_next_token_is (parser, CPP_SEMICOLON)) { pedwarn (c_parser_peek_token (parser)->location, OPT_pedantic, "extra semicolon in struct or union specified"); c_parser_consume_token (parser); continue; } /* Stop if at the end of the struct or union contents. */ if (c_parser_next_token_is (parser, CPP_CLOSE_BRACE)) { c_parser_consume_token (parser); break; } /* Accept #pragmas at struct scope. */ if (c_parser_next_token_is (parser, CPP_PRAGMA)) { c_parser_pragma (parser, pragma_external); continue; } /* Parse some comma-separated declarations, but not the trailing semicolon if any. */ decls = c_parser_struct_declaration (parser); contents = chainon (decls, contents); /* If no semicolon follows, either we have a parse error or are at the end of the struct or union and should pedwarn. */ if (c_parser_next_token_is (parser, CPP_SEMICOLON)) c_parser_consume_token (parser); else { if (c_parser_next_token_is (parser, CPP_CLOSE_BRACE)) pedwarn (c_parser_peek_token (parser)->location, 0, "no semicolon at end of struct or union"); else { c_parser_error (parser, "expected %<;%>"); c_parser_skip_until_found (parser, CPP_CLOSE_BRACE, NULL); break; } } } postfix_attrs = c_parser_attributes (parser); ret.spec = finish_struct (struct_loc, type, nreverse (contents), chainon (attrs, postfix_attrs), struct_info); ret.kind = ctsk_tagdef; ret.expr = NULL_TREE; ret.expr_const_operands = true; return ret; } else if (!ident) { c_parser_error (parser, "expected %<{%>"); ret.spec = error_mark_node; ret.kind = ctsk_tagref; ret.expr = NULL_TREE; ret.expr_const_operands = true; return ret; } ret = parser_xref_tag (ident_loc, code, ident); return ret; } /* Parse a struct-declaration (C90 6.5.2.1, C99 6.7.2.1), *without* the trailing semicolon. struct-declaration: specifier-qualifier-list struct-declarator-list specifier-qualifier-list: type-specifier specifier-qualifier-list[opt] type-qualifier specifier-qualifier-list[opt] attributes specifier-qualifier-list[opt] struct-declarator-list: struct-declarator struct-declarator-list , attributes[opt] struct-declarator struct-declarator: declarator attributes[opt] declarator[opt] : constant-expression attributes[opt] GNU extensions: struct-declaration: __extension__ struct-declaration specifier-qualifier-list Unlike the ISO C syntax, semicolons are handled elsewhere. The use of attributes where shown is a GNU extension. In GNU C, we accept any expression without commas in the syntax (assignment expressions, not just conditional expressions); assignment expressions will be diagnosed as non-constant. */ static tree c_parser_struct_declaration (c_parser *parser) { struct c_declspecs *specs; tree prefix_attrs; tree all_prefix_attrs; tree decls; location_t decl_loc; if (c_parser_next_token_is_keyword (parser, RID_EXTENSION)) { int ext; tree decl; ext = disable_extension_diagnostics (); c_parser_consume_token (parser); decl = c_parser_struct_declaration (parser); restore_extension_diagnostics (ext); return decl; } specs = build_null_declspecs (); decl_loc = c_parser_peek_token (parser)->location; c_parser_declspecs (parser, specs, false, true, true); if (parser->error) return NULL_TREE; if (!specs->declspecs_seen_p) { c_parser_error (parser, "expected specifier-qualifier-list"); return NULL_TREE; } finish_declspecs (specs); if (c_parser_next_token_is (parser, CPP_SEMICOLON)) { tree ret; if (!specs->type_seen_p) { pedwarn (decl_loc, OPT_pedantic, "ISO C forbids member declarations with no members"); shadow_tag_warned (specs, pedantic); ret = NULL_TREE; } else { /* Support for unnamed structs or unions as members of structs or unions (which is [a] useful and [b] supports MS P-SDK). */ tree attrs = NULL; ret = grokfield (c_parser_peek_token (parser)->location, build_id_declarator (NULL_TREE), specs, NULL_TREE, &attrs); if (ret) decl_attributes (&ret, attrs, 0); } return ret; } pending_xref_error (); prefix_attrs = specs->attrs; all_prefix_attrs = prefix_attrs; specs->attrs = NULL_TREE; decls = NULL_TREE; while (true) { /* Declaring one or more declarators or un-named bit-fields. */ struct c_declarator *declarator; bool dummy = false; if (c_parser_next_token_is (parser, CPP_COLON)) declarator = build_id_declarator (NULL_TREE); else declarator = c_parser_declarator (parser, specs->type_seen_p, C_DTR_NORMAL, &dummy); if (declarator == NULL) { c_parser_skip_to_end_of_block_or_statement (parser); break; } if (c_parser_next_token_is (parser, CPP_COLON) || c_parser_next_token_is (parser, CPP_COMMA) || c_parser_next_token_is (parser, CPP_SEMICOLON) || c_parser_next_token_is (parser, CPP_CLOSE_BRACE) || c_parser_next_token_is_keyword (parser, RID_ATTRIBUTE)) { tree postfix_attrs = NULL_TREE; tree width = NULL_TREE; tree d; if (c_parser_next_token_is (parser, CPP_COLON)) { c_parser_consume_token (parser); width = c_parser_expr_no_commas (parser, NULL).value; } if (c_parser_next_token_is_keyword (parser, RID_ATTRIBUTE)) postfix_attrs = c_parser_attributes (parser); d = grokfield (c_parser_peek_token (parser)->location, declarator, specs, width, &all_prefix_attrs); decl_attributes (&d, chainon (postfix_attrs, all_prefix_attrs), 0); TREE_CHAIN (d) = decls; decls = d; if (c_parser_next_token_is_keyword (parser, RID_ATTRIBUTE)) all_prefix_attrs = chainon (c_parser_attributes (parser), prefix_attrs); else all_prefix_attrs = prefix_attrs; if (c_parser_next_token_is (parser, CPP_COMMA)) c_parser_consume_token (parser); else if (c_parser_next_token_is (parser, CPP_SEMICOLON) || c_parser_next_token_is (parser, CPP_CLOSE_BRACE)) { /* Semicolon consumed in caller. */ break; } else { c_parser_error (parser, "expected %<,%>, %<;%> or %<}%>"); break; } } else { c_parser_error (parser, "expected %<:%>, %<,%>, %<;%>, %<}%> or " "%<__attribute__%>"); break; } } return decls; } /* Parse a typeof specifier (a GNU extension). typeof-specifier: typeof ( expression ) typeof ( type-name ) */ static struct c_typespec c_parser_typeof_specifier (c_parser *parser) { struct c_typespec ret; ret.kind = ctsk_typeof; ret.spec = error_mark_node; ret.expr = NULL_TREE; ret.expr_const_operands = true; gcc_assert (c_parser_next_token_is_keyword (parser, RID_TYPEOF)); c_parser_consume_token (parser); c_inhibit_evaluation_warnings++; in_typeof++; if (!c_parser_require (parser, CPP_OPEN_PAREN, "expected %<(%>")) { c_inhibit_evaluation_warnings--; in_typeof--; return ret; } if (c_parser_next_token_starts_typename (parser)) { struct c_type_name *type = c_parser_type_name (parser); c_inhibit_evaluation_warnings--; in_typeof--; if (type != NULL) { ret.spec = groktypename (type, &ret.expr, &ret.expr_const_operands); pop_maybe_used (variably_modified_type_p (ret.spec, NULL_TREE)); } } else { bool was_vm; location_t here = c_parser_peek_token (parser)->location; struct c_expr expr = c_parser_expression (parser); c_inhibit_evaluation_warnings--; in_typeof--; if (TREE_CODE (expr.value) == COMPONENT_REF && DECL_C_BIT_FIELD (TREE_OPERAND (expr.value, 1))) error_at (here, "%<typeof%> applied to a bit-field"); ret.spec = TREE_TYPE (expr.value); was_vm = variably_modified_type_p (ret.spec, NULL_TREE); /* This is returned with the type so that when the type is evaluated, this can be evaluated. */ if (was_vm) ret.expr = c_fully_fold (expr.value, false, &ret.expr_const_operands); pop_maybe_used (was_vm); } c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, "expected %<)%>"); return ret; } /* Parse a declarator, possibly an abstract declarator (C90 6.5.4, 6.5.5, C99 6.7.5, 6.7.6). If TYPE_SEEN_P then a typedef name may be redeclared; otherwise it may not. KIND indicates which kind of declarator is wanted. Returns a valid declarator except in the case of a syntax error in which case NULL is returned. *SEEN_ID is set to true if an identifier being declared is seen; this is used to diagnose bad forms of abstract array declarators and to determine whether an identifier list is syntactically permitted. declarator: pointer[opt] direct-declarator direct-declarator: identifier ( attributes[opt] declarator ) direct-declarator array-declarator direct-declarator ( parameter-type-list ) direct-declarator ( identifier-list[opt] ) pointer: * type-qualifier-list[opt] * type-qualifier-list[opt] pointer type-qualifier-list: type-qualifier attributes type-qualifier-list type-qualifier type-qualifier-list attributes parameter-type-list: parameter-list parameter-list , ... parameter-list: parameter-declaration parameter-list , parameter-declaration parameter-declaration: declaration-specifiers declarator attributes[opt] declaration-specifiers abstract-declarator[opt] attributes[opt] identifier-list: identifier identifier-list , identifier abstract-declarator: pointer pointer[opt] direct-abstract-declarator direct-abstract-declarator: ( attributes[opt] abstract-declarator ) direct-abstract-declarator[opt] array-declarator direct-abstract-declarator[opt] ( parameter-type-list[opt] ) GNU extensions: direct-declarator: direct-declarator ( parameter-forward-declarations parameter-type-list[opt] ) direct-abstract-declarator: direct-abstract-declarator[opt] ( parameter-forward-declarations parameter-type-list[opt] ) parameter-forward-declarations: parameter-list ; parameter-forward-declarations parameter-list ; The uses of attributes shown above are GNU extensions. Some forms of array declarator are not included in C99 in the syntax for abstract declarators; these are disallowed elsewhere. This may be a defect (DR#289). This function also accepts an omitted abstract declarator as being an abstract declarator, although not part of the formal syntax. */ static struct c_declarator * c_parser_declarator (c_parser *parser, bool type_seen_p, c_dtr_syn kind, bool *seen_id) { /* Parse any initial pointer part. */ if (c_parser_next_token_is (parser, CPP_MULT)) { struct c_declspecs *quals_attrs = build_null_declspecs (); struct c_declarator *inner; c_parser_consume_token (parser); c_parser_declspecs (parser, quals_attrs, false, false, true); inner = c_parser_declarator (parser, type_seen_p, kind, seen_id); if (inner == NULL) return NULL; else return make_pointer_declarator (quals_attrs, inner); } /* Now we have a direct declarator, direct abstract declarator or nothing (which counts as a direct abstract declarator here). */ return c_parser_direct_declarator (parser, type_seen_p, kind, seen_id); } /* Parse a direct declarator or direct abstract declarator; arguments as c_parser_declarator. */ static struct c_declarator * c_parser_direct_declarator (c_parser *parser, bool type_seen_p, c_dtr_syn kind, bool *seen_id) { /* The direct declarator must start with an identifier (possibly omitted) or a parenthesized declarator (possibly abstract). In an ordinary declarator, initial parentheses must start a parenthesized declarator. In an abstract declarator or parameter declarator, they could start a parenthesized declarator or a parameter list. To tell which, the open parenthesis and any following attributes must be read. If a declaration specifier follows, then it is a parameter list; if the specifier is a typedef name, there might be an ambiguity about redeclaring it, which is resolved in the direction of treating it as a typedef name. If a close parenthesis follows, it is also an empty parameter list, as the syntax does not permit empty abstract declarators. Otherwise, it is a parenthesized declarator (in which case the analysis may be repeated inside it, recursively). ??? There is an ambiguity in a parameter declaration "int (__attribute__((foo)) x)", where x is not a typedef name: it could be an abstract declarator for a function, or declare x with parentheses. The proper resolution of this ambiguity needs documenting. At present we follow an accident of the old parser's implementation, whereby the first parameter must have some declaration specifiers other than just attributes. Thus as a parameter declaration it is treated as a parenthesized parameter named x, and as an abstract declarator it is rejected. ??? Also following the old parser, attributes inside an empty parameter list are ignored, making it a list not yielding a prototype, rather than giving an error or making it have one parameter with implicit type int. ??? Also following the old parser, typedef names may be redeclared in declarators, but not Objective-C class names. */ if (kind != C_DTR_ABSTRACT && c_parser_next_token_is (parser, CPP_NAME) && ((type_seen_p && c_parser_peek_token (parser)->id_kind == C_ID_TYPENAME) || c_parser_peek_token (parser)->id_kind == C_ID_ID)) { struct c_declarator *inner = build_id_declarator (c_parser_peek_token (parser)->value); *seen_id = true; inner->id_loc = c_parser_peek_token (parser)->location; c_parser_consume_token (parser); return c_parser_direct_declarator_inner (parser, *seen_id, inner); } if (kind != C_DTR_NORMAL && c_parser_next_token_is (parser, CPP_OPEN_SQUARE)) { struct c_declarator *inner = build_id_declarator (NULL_TREE); return c_parser_direct_declarator_inner (parser, *seen_id, inner); } /* Either we are at the end of an abstract declarator, or we have parentheses. */ if (c_parser_next_token_is (parser, CPP_OPEN_PAREN)) { tree attrs; struct c_declarator *inner; c_parser_consume_token (parser); attrs = c_parser_attributes (parser); if (kind != C_DTR_NORMAL && (c_parser_next_token_starts_declspecs (parser) || c_parser_next_token_is (parser, CPP_CLOSE_PAREN))) { struct c_arg_info *args = c_parser_parms_declarator (parser, kind == C_DTR_NORMAL, attrs); if (args == NULL) return NULL; else { inner = build_function_declarator (args, build_id_declarator (NULL_TREE)); return c_parser_direct_declarator_inner (parser, *seen_id, inner); } } /* A parenthesized declarator. */ inner = c_parser_declarator (parser, type_seen_p, kind, seen_id); if (inner != NULL && attrs != NULL) inner = build_attrs_declarator (attrs, inner); if (c_parser_next_token_is (parser, CPP_CLOSE_PAREN)) { c_parser_consume_token (parser); if (inner == NULL) return NULL; else return c_parser_direct_declarator_inner (parser, *seen_id, inner); } else { c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, "expected %<)%>"); return NULL; } } else { if (kind == C_DTR_NORMAL) { c_parser_error (parser, "expected identifier or %<(%>"); return NULL; } else return build_id_declarator (NULL_TREE); } } /* Parse part of a direct declarator or direct abstract declarator, given that some (in INNER) has already been parsed; ID_PRESENT is true if an identifier is present, false for an abstract declarator. */ static struct c_declarator * c_parser_direct_declarator_inner (c_parser *parser, bool id_present, struct c_declarator *inner) { /* Parse a sequence of array declarators and parameter lists. */ if (c_parser_next_token_is (parser, CPP_OPEN_SQUARE)) { location_t brace_loc = c_parser_peek_token (parser)->location; struct c_declarator *declarator; struct c_declspecs *quals_attrs = build_null_declspecs (); bool static_seen; bool star_seen; tree dimen; c_parser_consume_token (parser); c_parser_declspecs (parser, quals_attrs, false, false, true); static_seen = c_parser_next_token_is_keyword (parser, RID_STATIC); if (static_seen) c_parser_consume_token (parser); if (static_seen && !quals_attrs->declspecs_seen_p) c_parser_declspecs (parser, quals_attrs, false, false, true); if (!quals_attrs->declspecs_seen_p) quals_attrs = NULL; /* If "static" is present, there must be an array dimension. Otherwise, there may be a dimension, "*", or no dimension. */ if (static_seen) { star_seen = false; dimen = c_parser_expr_no_commas (parser, NULL).value; } else { if (c_parser_next_token_is (parser, CPP_CLOSE_SQUARE)) { dimen = NULL_TREE; star_seen = false; } else if (c_parser_next_token_is (parser, CPP_MULT)) { if (c_parser_peek_2nd_token (parser)->type == CPP_CLOSE_SQUARE) { dimen = NULL_TREE; star_seen = true; c_parser_consume_token (parser); } else { star_seen = false; dimen = c_parser_expr_no_commas (parser, NULL).value; } } else { star_seen = false; dimen = c_parser_expr_no_commas (parser, NULL).value; } } if (c_parser_next_token_is (parser, CPP_CLOSE_SQUARE)) c_parser_consume_token (parser); else { c_parser_skip_until_found (parser, CPP_CLOSE_SQUARE, "expected %<]%>"); return NULL; } declarator = build_array_declarator (brace_loc, dimen, quals_attrs, static_seen, star_seen); if (declarator == NULL) return NULL; inner = set_array_declarator_inner (declarator, inner); return c_parser_direct_declarator_inner (parser, id_present, inner); } else if (c_parser_next_token_is (parser, CPP_OPEN_PAREN)) { tree attrs; struct c_arg_info *args; c_parser_consume_token (parser); attrs = c_parser_attributes (parser); args = c_parser_parms_declarator (parser, id_present, attrs); if (args == NULL) return NULL; else { inner = build_function_declarator (args, inner); return c_parser_direct_declarator_inner (parser, id_present, inner); } } return inner; } /* Parse a parameter list or identifier list, including the closing parenthesis but not the opening one. ATTRS are the attributes at the start of the list. ID_LIST_OK is true if an identifier list is acceptable; such a list must not have attributes at the start. */ static struct c_arg_info * c_parser_parms_declarator (c_parser *parser, bool id_list_ok, tree attrs) { push_scope (); declare_parm_level (); /* If the list starts with an identifier, it is an identifier list. Otherwise, it is either a prototype list or an empty list. */ if (id_list_ok && !attrs && c_parser_next_token_is (parser, CPP_NAME) && c_parser_peek_token (parser)->id_kind == C_ID_ID) { tree list = NULL_TREE, *nextp = &list; while (c_parser_next_token_is (parser, CPP_NAME) && c_parser_peek_token (parser)->id_kind == C_ID_ID) { *nextp = build_tree_list (NULL_TREE, c_parser_peek_token (parser)->value); nextp = & TREE_CHAIN (*nextp); c_parser_consume_token (parser); if (c_parser_next_token_is_not (parser, CPP_COMMA)) break; c_parser_consume_token (parser); if (c_parser_next_token_is (parser, CPP_CLOSE_PAREN)) { c_parser_error (parser, "expected identifier"); break; } } if (c_parser_next_token_is (parser, CPP_CLOSE_PAREN)) { struct c_arg_info *ret = XOBNEW (&parser_obstack, struct c_arg_info); ret->parms = 0; ret->tags = 0; ret->types = list; ret->others = 0; ret->pending_sizes = 0; ret->had_vla_unspec = 0; c_parser_consume_token (parser); pop_scope (); return ret; } else { c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, "expected %<)%>"); pop_scope (); return NULL; } } else { struct c_arg_info *ret = c_parser_parms_list_declarator (parser, attrs); pop_scope (); return ret; } } /* Parse a parameter list (possibly empty), including the closing parenthesis but not the opening one. ATTRS are the attributes at the start of the list. */ static struct c_arg_info * c_parser_parms_list_declarator (c_parser *parser, tree attrs) { bool good_parm = false; /* ??? Following the old parser, forward parameter declarations may use abstract declarators, and if no real parameter declarations follow the forward declarations then this is not diagnosed. Also note as above that attributes are ignored as the only contents of the parentheses, or as the only contents after forward declarations. */ if (c_parser_next_token_is (parser, CPP_CLOSE_PAREN)) { struct c_arg_info *ret = XOBNEW (&parser_obstack, struct c_arg_info); ret->parms = 0; ret->tags = 0; ret->types = 0; ret->others = 0; ret->pending_sizes = 0; ret->had_vla_unspec = 0; c_parser_consume_token (parser); return ret; } if (c_parser_next_token_is (parser, CPP_ELLIPSIS)) { struct c_arg_info *ret = XOBNEW (&parser_obstack, struct c_arg_info); ret->parms = 0; ret->tags = 0; ret->others = 0; ret->pending_sizes = 0; ret->had_vla_unspec = 0; /* Suppress -Wold-style-definition for this case. */ ret->types = error_mark_node; error_at (c_parser_peek_token (parser)->location, "ISO C requires a named argument before %<...%>"); c_parser_consume_token (parser); if (c_parser_next_token_is (parser, CPP_CLOSE_PAREN)) { c_parser_consume_token (parser); return ret; } else { c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, "expected %<)%>"); return NULL; } } /* Nonempty list of parameters, either terminated with semicolon (forward declarations; recurse) or with close parenthesis (normal function) or with ", ... )" (variadic function). */ while (true) { /* Parse a parameter. */ struct c_parm *parm = c_parser_parameter_declaration (parser, attrs); attrs = NULL_TREE; if (parm != NULL) { good_parm = true; push_parm_decl (parm); } if (c_parser_next_token_is (parser, CPP_SEMICOLON)) { tree new_attrs; c_parser_consume_token (parser); mark_forward_parm_decls (); new_attrs = c_parser_attributes (parser); return c_parser_parms_list_declarator (parser, new_attrs); } if (c_parser_next_token_is (parser, CPP_CLOSE_PAREN)) { c_parser_consume_token (parser); if (good_parm) return get_parm_info (false); else { struct c_arg_info *ret = XOBNEW (&parser_obstack, struct c_arg_info); ret->parms = 0; ret->tags = 0; ret->types = 0; ret->others = 0; ret->pending_sizes = 0; ret->had_vla_unspec = 0; return ret; } } if (!c_parser_require (parser, CPP_COMMA, "expected %<;%>, %<,%> or %<)%>")) { c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, NULL); get_pending_sizes (); return NULL; } if (c_parser_next_token_is (parser, CPP_ELLIPSIS)) { c_parser_consume_token (parser); if (c_parser_next_token_is (parser, CPP_CLOSE_PAREN)) { c_parser_consume_token (parser); if (good_parm) return get_parm_info (true); else { struct c_arg_info *ret = XOBNEW (&parser_obstack, struct c_arg_info); ret->parms = 0; ret->tags = 0; ret->types = 0; ret->others = 0; ret->pending_sizes = 0; ret->had_vla_unspec = 0; return ret; } } else { c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, "expected %<)%>"); get_pending_sizes (); return NULL; } } } } /* Parse a parameter declaration. ATTRS are the attributes at the start of the declaration if it is the first parameter. */ static struct c_parm * c_parser_parameter_declaration (c_parser *parser, tree attrs) { struct c_declspecs *specs; struct c_declarator *declarator; tree prefix_attrs; tree postfix_attrs = NULL_TREE; bool dummy = false; if (!c_parser_next_token_starts_declspecs (parser)) { /* ??? In some Objective-C cases '...' isn't applicable so there should be a different message. */ c_parser_error (parser, "expected declaration specifiers or %<...%>"); c_parser_skip_to_end_of_parameter (parser); return NULL; } specs = build_null_declspecs (); if (attrs) { declspecs_add_attrs (specs, attrs); attrs = NULL_TREE; } c_parser_declspecs (parser, specs, true, true, true); finish_declspecs (specs); pending_xref_error (); prefix_attrs = specs->attrs; specs->attrs = NULL_TREE; declarator = c_parser_declarator (parser, specs->type_seen_p, C_DTR_PARM, &dummy); if (declarator == NULL) { c_parser_skip_until_found (parser, CPP_COMMA, NULL); return NULL; } if (c_parser_next_token_is_keyword (parser, RID_ATTRIBUTE)) postfix_attrs = c_parser_attributes (parser); return build_c_parm (specs, chainon (postfix_attrs, prefix_attrs), declarator); } /* Parse a string literal in an asm expression. It should not be translated, and wide string literals are an error although permitted by the syntax. This is a GNU extension. asm-string-literal: string-literal ??? At present, following the old parser, the caller needs to have set lex_untranslated_string to 1. It would be better to follow the C++ parser rather than using this kludge. */ static tree c_parser_asm_string_literal (c_parser *parser) { tree str; if (c_parser_next_token_is (parser, CPP_STRING)) { str = c_parser_peek_token (parser)->value; c_parser_consume_token (parser); } else if (c_parser_next_token_is (parser, CPP_WSTRING)) { error_at (c_parser_peek_token (parser)->location, "wide string literal in %<asm%>"); str = build_string (1, ""); c_parser_consume_token (parser); } else { c_parser_error (parser, "expected string literal"); str = NULL_TREE; } return str; } /* Parse a simple asm expression. This is used in restricted contexts, where a full expression with inputs and outputs does not make sense. This is a GNU extension. simple-asm-expr: asm ( asm-string-literal ) */ static tree c_parser_simple_asm_expr (c_parser *parser) { tree str; gcc_assert (c_parser_next_token_is_keyword (parser, RID_ASM)); /* ??? Follow the C++ parser rather than using the lex_untranslated_string kludge. */ parser->lex_untranslated_string = true; c_parser_consume_token (parser); if (!c_parser_require (parser, CPP_OPEN_PAREN, "expected %<(%>")) { parser->lex_untranslated_string = false; return NULL_TREE; } str = c_parser_asm_string_literal (parser); parser->lex_untranslated_string = false; if (!c_parser_require (parser, CPP_CLOSE_PAREN, "expected %<)%>")) { c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, NULL); return NULL_TREE; } return str; } /* Parse (possibly empty) attributes. This is a GNU extension. attributes: empty attributes attribute attribute: __attribute__ ( ( attribute-list ) ) attribute-list: attrib attribute_list , attrib attrib: empty any-word any-word ( identifier ) any-word ( identifier , nonempty-expr-list ) any-word ( expr-list ) where the "identifier" must not be declared as a type, and "any-word" may be any identifier (including one declared as a type), a reserved word storage class specifier, type specifier or type qualifier. ??? This still leaves out most reserved keywords (following the old parser), shouldn't we include them, and why not allow identifiers declared as types to start the arguments? */ static tree c_parser_attributes (c_parser *parser) { tree attrs = NULL_TREE; while (c_parser_next_token_is_keyword (parser, RID_ATTRIBUTE)) { /* ??? Follow the C++ parser rather than using the lex_untranslated_string kludge. */ parser->lex_untranslated_string = true; c_parser_consume_token (parser); if (!c_parser_require (parser, CPP_OPEN_PAREN, "expected %<(%>")) { parser->lex_untranslated_string = false; return attrs; } if (!c_parser_require (parser, CPP_OPEN_PAREN, "expected %<(%>")) { parser->lex_untranslated_string = false; c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, NULL); return attrs; } /* Parse the attribute list. */ while (c_parser_next_token_is (parser, CPP_COMMA) || c_parser_next_token_is (parser, CPP_NAME) || c_parser_next_token_is (parser, CPP_KEYWORD)) { tree attr, attr_name, attr_args; VEC(tree,gc) *expr_list; if (c_parser_next_token_is (parser, CPP_COMMA)) { c_parser_consume_token (parser); continue; } if (c_parser_next_token_is (parser, CPP_KEYWORD)) { /* ??? See comment above about what keywords are accepted here. */ bool ok; switch (c_parser_peek_token (parser)->keyword) { case RID_STATIC: case RID_UNSIGNED: case RID_LONG: case RID_CONST: case RID_EXTERN: case RID_REGISTER: case RID_TYPEDEF: case RID_SHORT: case RID_INLINE: case RID_VOLATILE: case RID_SIGNED: case RID_AUTO: case RID_RESTRICT: case RID_COMPLEX: case RID_THREAD: case RID_INT: case RID_CHAR: case RID_FLOAT: case RID_DOUBLE: case RID_VOID: case RID_DFLOAT32: case RID_DFLOAT64: case RID_DFLOAT128: case RID_BOOL: case RID_FRACT: case RID_ACCUM: case RID_SAT: ok = true; break; default: ok = false; break; } if (!ok) break; /* Accept __attribute__((__const)) as __attribute__((const)) etc. */ attr_name = ridpointers[(int) c_parser_peek_token (parser)->keyword]; } else attr_name = c_parser_peek_token (parser)->value; c_parser_consume_token (parser); if (c_parser_next_token_is_not (parser, CPP_OPEN_PAREN)) { attr = build_tree_list (attr_name, NULL_TREE); attrs = chainon (attrs, attr); continue; } c_parser_consume_token (parser); /* Parse the attribute contents. If they start with an identifier which is followed by a comma or close parenthesis, then the arguments start with that identifier; otherwise they are an expression list. */ if (c_parser_next_token_is (parser, CPP_NAME) && c_parser_peek_token (parser)->id_kind == C_ID_ID && ((c_parser_peek_2nd_token (parser)->type == CPP_COMMA) || (c_parser_peek_2nd_token (parser)->type == CPP_CLOSE_PAREN))) { tree arg1 = c_parser_peek_token (parser)->value; c_parser_consume_token (parser); if (c_parser_next_token_is (parser, CPP_CLOSE_PAREN)) attr_args = build_tree_list (NULL_TREE, arg1); else { tree tree_list; c_parser_consume_token (parser); expr_list = c_parser_expr_list (parser, false, true, NULL); tree_list = build_tree_list_vec (expr_list); attr_args = tree_cons (NULL_TREE, arg1, tree_list); release_tree_vector (expr_list); } } else { if (c_parser_next_token_is (parser, CPP_CLOSE_PAREN)) attr_args = NULL_TREE; else { expr_list = c_parser_expr_list (parser, false, true, NULL); attr_args = build_tree_list_vec (expr_list); release_tree_vector (expr_list); } } attr = build_tree_list (attr_name, attr_args); if (c_parser_next_token_is (parser, CPP_CLOSE_PAREN)) c_parser_consume_token (parser); else { parser->lex_untranslated_string = false; c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, "expected %<)%>"); return attrs; } attrs = chainon (attrs, attr); } if (c_parser_next_token_is (parser, CPP_CLOSE_PAREN)) c_parser_consume_token (parser); else { parser->lex_untranslated_string = false; c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, "expected %<)%>"); return attrs; } if (c_parser_next_token_is (parser, CPP_CLOSE_PAREN)) c_parser_consume_token (parser); else { parser->lex_untranslated_string = false; c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, "expected %<)%>"); return attrs; } parser->lex_untranslated_string = false; } return attrs; } /* Parse a type name (C90 6.5.5, C99 6.7.6). type-name: specifier-qualifier-list abstract-declarator[opt] */ static struct c_type_name * c_parser_type_name (c_parser *parser) { struct c_declspecs *specs = build_null_declspecs (); struct c_declarator *declarator; struct c_type_name *ret; bool dummy = false; c_parser_declspecs (parser, specs, false, true, true); if (!specs->declspecs_seen_p) { c_parser_error (parser, "expected specifier-qualifier-list"); return NULL; } pending_xref_error (); finish_declspecs (specs); declarator = c_parser_declarator (parser, specs->type_seen_p, C_DTR_ABSTRACT, &dummy); if (declarator == NULL) return NULL; ret = XOBNEW (&parser_obstack, struct c_type_name); ret->specs = specs; ret->declarator = declarator; return ret; } /* Parse an initializer (C90 6.5.7, C99 6.7.8). initializer: assignment-expression { initializer-list } { initializer-list , } initializer-list: designation[opt] initializer initializer-list , designation[opt] initializer designation: designator-list = designator-list: designator designator-list designator designator: array-designator . identifier array-designator: [ constant-expression ] GNU extensions: initializer: { } designation: array-designator identifier : array-designator: [ constant-expression ... constant-expression ] Any expression without commas is accepted in the syntax for the constant-expressions, with non-constant expressions rejected later. This function is only used for top-level initializers; for nested ones, see c_parser_initval. */ static struct c_expr c_parser_initializer (c_parser *parser) { if (c_parser_next_token_is (parser, CPP_OPEN_BRACE)) return c_parser_braced_init (parser, NULL_TREE, false); else { struct c_expr ret; location_t loc = c_parser_peek_token (parser)->location; ret = c_parser_expr_no_commas (parser, NULL); if (TREE_CODE (ret.value) != STRING_CST && TREE_CODE (ret.value) != COMPOUND_LITERAL_EXPR) ret = default_function_array_conversion (loc, ret); return ret; } } /* Parse a braced initializer list. TYPE is the type specified for a compound literal, and NULL_TREE for other initializers and for nested braced lists. NESTED_P is true for nested braced lists, false for the list of a compound literal or the list that is the top-level initializer in a declaration. */ static struct c_expr c_parser_braced_init (c_parser *parser, tree type, bool nested_p) { location_t brace_loc = c_parser_peek_token (parser)->location; gcc_assert (c_parser_next_token_is (parser, CPP_OPEN_BRACE)); c_parser_consume_token (parser); if (nested_p) push_init_level (0); else really_start_incremental_init (type); if (c_parser_next_token_is (parser, CPP_CLOSE_BRACE)) { pedwarn (brace_loc, OPT_pedantic, "ISO C forbids empty initializer braces"); } else { /* Parse a non-empty initializer list, possibly with a trailing comma. */ while (true) { c_parser_initelt (parser); if (parser->error) break; if (c_parser_next_token_is (parser, CPP_COMMA)) c_parser_consume_token (parser); else break; if (c_parser_next_token_is (parser, CPP_CLOSE_BRACE)) break; } } if (c_parser_next_token_is_not (parser, CPP_CLOSE_BRACE)) { struct c_expr ret; ret.value = error_mark_node; ret.original_code = ERROR_MARK; ret.original_type = NULL; c_parser_skip_until_found (parser, CPP_CLOSE_BRACE, "expected %<}%>"); pop_init_level (0); return ret; } c_parser_consume_token (parser); return pop_init_level (0); } /* Parse a nested initializer, including designators. */ static void c_parser_initelt (c_parser *parser) { /* Parse any designator or designator list. A single array designator may have the subsequent "=" omitted in GNU C, but a longer list or a structure member designator may not. */ if (c_parser_next_token_is (parser, CPP_NAME) && c_parser_peek_2nd_token (parser)->type == CPP_COLON) { /* Old-style structure member designator. */ set_init_label (c_parser_peek_token (parser)->value); /* Use the colon as the error location. */ pedwarn (c_parser_peek_2nd_token (parser)->location, OPT_pedantic, "obsolete use of designated initializer with %<:%>"); c_parser_consume_token (parser); c_parser_consume_token (parser); } else { /* des_seen is 0 if there have been no designators, 1 if there has been a single array designator and 2 otherwise. */ int des_seen = 0; /* Location of a designator. */ location_t des_loc = UNKNOWN_LOCATION; /* Quiet warning. */ while (c_parser_next_token_is (parser, CPP_OPEN_SQUARE) || c_parser_next_token_is (parser, CPP_DOT)) { int des_prev = des_seen; if (!des_seen) des_loc = c_parser_peek_token (parser)->location; if (des_seen < 2) des_seen++; if (c_parser_next_token_is (parser, CPP_DOT)) { des_seen = 2; c_parser_consume_token (parser); if (c_parser_next_token_is (parser, CPP_NAME)) { set_init_label (c_parser_peek_token (parser)->value); c_parser_consume_token (parser); } else { struct c_expr init; init.value = error_mark_node; init.original_code = ERROR_MARK; init.original_type = NULL; c_parser_error (parser, "expected identifier"); c_parser_skip_until_found (parser, CPP_COMMA, NULL); process_init_element (init, false); return; } } else { tree first, second; location_t ellipsis_loc = UNKNOWN_LOCATION; /* Quiet warning. */ /* ??? Following the old parser, [ objc-receiver objc-message-args ] is accepted as an initializer, being distinguished from a designator by what follows the first assignment expression inside the square brackets, but after a first array designator a subsequent square bracket is for Objective-C taken to start an expression, using the obsolete form of designated initializer without '=', rather than possibly being a second level of designation: in LALR terms, the '[' is shifted rather than reducing designator to designator-list. */ if (des_prev == 1 && c_dialect_objc ()) { des_seen = des_prev; break; } if (des_prev == 0 && c_dialect_objc ()) { /* This might be an array designator or an Objective-C message expression. If the former, continue parsing here; if the latter, parse the remainder of the initializer given the starting primary-expression. ??? It might make sense to distinguish when des_prev == 1 as well; see previous comment. */ tree rec, args; struct c_expr mexpr; c_parser_consume_token (parser); if (c_parser_peek_token (parser)->type == CPP_NAME && ((c_parser_peek_token (parser)->id_kind == C_ID_TYPENAME) || (c_parser_peek_token (parser)->id_kind == C_ID_CLASSNAME))) { /* Type name receiver. */ tree id = c_parser_peek_token (parser)->value; c_parser_consume_token (parser); rec = objc_get_class_reference (id); goto parse_message_args; } first = c_parser_expr_no_commas (parser, NULL).value; if (c_parser_next_token_is (parser, CPP_ELLIPSIS) || c_parser_next_token_is (parser, CPP_CLOSE_SQUARE)) goto array_desig_after_first; /* Expression receiver. So far only one part without commas has been parsed; there might be more of the expression. */ rec = first; while (c_parser_next_token_is (parser, CPP_COMMA)) { struct c_expr next; location_t comma_loc, exp_loc; comma_loc = c_parser_peek_token (parser)->location; c_parser_consume_token (parser); exp_loc = c_parser_peek_token (parser)->location; next = c_parser_expr_no_commas (parser, NULL); next = default_function_array_conversion (exp_loc, next); rec = build_compound_expr (comma_loc, rec, next.value); } parse_message_args: /* Now parse the objc-message-args. */ args = c_parser_objc_message_args (parser); c_parser_skip_until_found (parser, CPP_CLOSE_SQUARE, "expected %<]%>"); mexpr.value = objc_build_message_expr (build_tree_list (rec, args)); mexpr.original_code = ERROR_MARK; mexpr.original_type = NULL; /* Now parse and process the remainder of the initializer, starting with this message expression as a primary-expression. */ c_parser_initval (parser, &mexpr); return; } c_parser_consume_token (parser); first = c_parser_expr_no_commas (parser, NULL).value; array_desig_after_first: if (c_parser_next_token_is (parser, CPP_ELLIPSIS)) { ellipsis_loc = c_parser_peek_token (parser)->location; c_parser_consume_token (parser); second = c_parser_expr_no_commas (parser, NULL).value; } else second = NULL_TREE; if (c_parser_next_token_is (parser, CPP_CLOSE_SQUARE)) { c_parser_consume_token (parser); set_init_index (first, second); if (second) pedwarn (ellipsis_loc, OPT_pedantic, "ISO C forbids specifying range of elements to initialize"); } else c_parser_skip_until_found (parser, CPP_CLOSE_SQUARE, "expected %<]%>"); } } if (des_seen >= 1) { if (c_parser_next_token_is (parser, CPP_EQ)) { if (!flag_isoc99) pedwarn (des_loc, OPT_pedantic, "ISO C90 forbids specifying subobject to initialize"); c_parser_consume_token (parser); } else { if (des_seen == 1) pedwarn (c_parser_peek_token (parser)->location, OPT_pedantic, "obsolete use of designated initializer without %<=%>"); else { struct c_expr init; init.value = error_mark_node; init.original_code = ERROR_MARK; init.original_type = NULL; c_parser_error (parser, "expected %<=%>"); c_parser_skip_until_found (parser, CPP_COMMA, NULL); process_init_element (init, false); return; } } } } c_parser_initval (parser, NULL); } /* Parse a nested initializer; as c_parser_initializer but parses initializers within braced lists, after any designators have been applied. If AFTER is not NULL then it is an Objective-C message expression which is the primary-expression starting the initializer. */ static void c_parser_initval (c_parser *parser, struct c_expr *after) { struct c_expr init; gcc_assert (!after || c_dialect_objc ()); if (c_parser_next_token_is (parser, CPP_OPEN_BRACE) && !after) init = c_parser_braced_init (parser, NULL_TREE, true); else { location_t loc = c_parser_peek_token (parser)->location; init = c_parser_expr_no_commas (parser, after); if (init.value != NULL_TREE && TREE_CODE (init.value) != STRING_CST && TREE_CODE (init.value) != COMPOUND_LITERAL_EXPR) init = default_function_array_conversion (loc, init); } process_init_element (init, false); } /* Parse a compound statement (possibly a function body) (C90 6.6.2, C99 6.8.2). compound-statement: { block-item-list[opt] } { label-declarations block-item-list } block-item-list: block-item block-item-list block-item block-item: nested-declaration statement nested-declaration: declaration GNU extensions: compound-statement: { label-declarations block-item-list } nested-declaration: __extension__ nested-declaration nested-function-definition label-declarations: label-declaration label-declarations label-declaration label-declaration: __label__ identifier-list ; Allowing the mixing of declarations and code is new in C99. The GNU syntax also permits (not shown above) labels at the end of compound statements, which yield an error. We don't allow labels on declarations; this might seem like a natural extension, but there would be a conflict between attributes on the label and prefix attributes on the declaration. ??? The syntax follows the old parser in requiring something after label declarations. Although they are erroneous if the labels declared aren't defined, is it useful for the syntax to be this way? OpenMP: block-item: openmp-directive openmp-directive: barrier-directive flush-directive */ static tree c_parser_compound_statement (c_parser *parser) { tree stmt; location_t brace_loc; brace_loc = c_parser_peek_token (parser)->location; if (!c_parser_require (parser, CPP_OPEN_BRACE, "expected %<{%>")) { /* Ensure a scope is entered and left anyway to avoid confusion if we have just prepared to enter a function body. */ stmt = c_begin_compound_stmt (true); c_end_compound_stmt (brace_loc, stmt, true); return error_mark_node; } stmt = c_begin_compound_stmt (true); c_parser_compound_statement_nostart (parser); return c_end_compound_stmt (brace_loc, stmt, true); } /* Parse a compound statement except for the opening brace. This is used for parsing both compound statements and statement expressions (which follow different paths to handling the opening). */ static void c_parser_compound_statement_nostart (c_parser *parser) { bool last_stmt = false; bool last_label = false; bool save_valid_for_pragma = valid_location_for_stdc_pragma_p (); location_t label_loc = UNKNOWN_LOCATION; /* Quiet warning. */ if (c_parser_next_token_is (parser, CPP_CLOSE_BRACE)) { c_parser_consume_token (parser); return; } mark_valid_location_for_stdc_pragma (true); if (c_parser_next_token_is_keyword (parser, RID_LABEL)) { /* Read zero or more forward-declarations for labels that nested functions can jump to. */ mark_valid_location_for_stdc_pragma (false); while (c_parser_next_token_is_keyword (parser, RID_LABEL)) { label_loc = c_parser_peek_token (parser)->location; c_parser_consume_token (parser); /* Any identifiers, including those declared as type names, are OK here. */ while (true) { tree label; if (c_parser_next_token_is_not (parser, CPP_NAME)) { c_parser_error (parser, "expected identifier"); break; } label = declare_label (c_parser_peek_token (parser)->value); C_DECLARED_LABEL_FLAG (label) = 1; add_stmt (build_stmt (label_loc, DECL_EXPR, label)); c_parser_consume_token (parser); if (c_parser_next_token_is (parser, CPP_COMMA)) c_parser_consume_token (parser); else break; } c_parser_skip_until_found (parser, CPP_SEMICOLON, "expected %<;%>"); } pedwarn (label_loc, OPT_pedantic, "ISO C forbids label declarations"); } /* We must now have at least one statement, label or declaration. */ if (c_parser_next_token_is (parser, CPP_CLOSE_BRACE)) { mark_valid_location_for_stdc_pragma (save_valid_for_pragma); c_parser_error (parser, "expected declaration or statement"); c_parser_consume_token (parser); return; } while (c_parser_next_token_is_not (parser, CPP_CLOSE_BRACE)) { location_t loc = c_parser_peek_token (parser)->location; if (c_parser_next_token_is_keyword (parser, RID_CASE) || c_parser_next_token_is_keyword (parser, RID_DEFAULT) || (c_parser_next_token_is (parser, CPP_NAME) && c_parser_peek_2nd_token (parser)->type == CPP_COLON)) { if (c_parser_next_token_is_keyword (parser, RID_CASE)) label_loc = c_parser_peek_2nd_token (parser)->location; else label_loc = c_parser_peek_token (parser)->location; last_label = true; last_stmt = false; mark_valid_location_for_stdc_pragma (false); c_parser_label (parser); } else if (!last_label && c_parser_next_token_starts_declspecs (parser)) { last_label = false; mark_valid_location_for_stdc_pragma (false); c_parser_declaration_or_fndef (parser, true, true, true, true); if (last_stmt) pedwarn_c90 (loc, (pedantic && !flag_isoc99) ? OPT_pedantic : OPT_Wdeclaration_after_statement, "ISO C90 forbids mixed declarations and code"); last_stmt = false; } else if (!last_label && c_parser_next_token_is_keyword (parser, RID_EXTENSION)) { /* __extension__ can start a declaration, but is also an unary operator that can start an expression. Consume all but the last of a possible series of __extension__ to determine which. */ while (c_parser_peek_2nd_token (parser)->type == CPP_KEYWORD && (c_parser_peek_2nd_token (parser)->keyword == RID_EXTENSION)) c_parser_consume_token (parser); if (c_token_starts_declspecs (c_parser_peek_2nd_token (parser))) { int ext; ext = disable_extension_diagnostics (); c_parser_consume_token (parser); last_label = false; mark_valid_location_for_stdc_pragma (false); c_parser_declaration_or_fndef (parser, true, true, true, true); /* Following the old parser, __extension__ does not disable this diagnostic. */ restore_extension_diagnostics (ext); if (last_stmt) pedwarn_c90 (loc, (pedantic && !flag_isoc99) ? OPT_pedantic : OPT_Wdeclaration_after_statement, "ISO C90 forbids mixed declarations and code"); last_stmt = false; } else goto statement; } else if (c_parser_next_token_is (parser, CPP_PRAGMA)) { /* External pragmas, and some omp pragmas, are not associated with regular c code, and so are not to be considered statements syntactically. This ensures that the user doesn't put them places that would turn into syntax errors if the directive were ignored. */ if (c_parser_pragma (parser, pragma_compound)) last_label = false, last_stmt = true; } else if (c_parser_next_token_is (parser, CPP_EOF)) { mark_valid_location_for_stdc_pragma (save_valid_for_pragma); c_parser_error (parser, "expected declaration or statement"); return; } else if (c_parser_next_token_is_keyword (parser, RID_ELSE)) { if (parser->in_if_block) { mark_valid_location_for_stdc_pragma (save_valid_for_pragma); error_at (loc, """expected %<}%> before %<else%>"); return; } else { error_at (loc, "%<else%> without a previous %<if%>"); c_parser_consume_token (parser); continue; } } else { statement: last_label = false; last_stmt = true; mark_valid_location_for_stdc_pragma (false); c_parser_statement_after_labels (parser); } parser->error = false; } if (last_label) error_at (label_loc, "label at end of compound statement"); c_parser_consume_token (parser); /* Restore the value we started with. */ mark_valid_location_for_stdc_pragma (save_valid_for_pragma); } /* Parse a label (C90 6.6.1, C99 6.8.1). label: identifier : attributes[opt] case constant-expression : default : GNU extensions: label: case constant-expression ... constant-expression : The use of attributes on labels is a GNU extension. The syntax in GNU C accepts any expressions without commas, non-constant expressions being rejected later. */ static void c_parser_label (c_parser *parser) { location_t loc1 = c_parser_peek_token (parser)->location; tree label = NULL_TREE; if (c_parser_next_token_is_keyword (parser, RID_CASE)) { tree exp1, exp2; c_parser_consume_token (parser); exp1 = c_parser_expr_no_commas (parser, NULL).value; if (c_parser_next_token_is (parser, CPP_COLON)) { c_parser_consume_token (parser); label = do_case (loc1, exp1, NULL_TREE); } else if (c_parser_next_token_is (parser, CPP_ELLIPSIS)) { c_parser_consume_token (parser); exp2 = c_parser_expr_no_commas (parser, NULL).value; if (c_parser_require (parser, CPP_COLON, "expected %<:%>")) label = do_case (loc1, exp1, exp2); } else c_parser_error (parser, "expected %<:%> or %<...%>"); } else if (c_parser_next_token_is_keyword (parser, RID_DEFAULT)) { c_parser_consume_token (parser); if (c_parser_require (parser, CPP_COLON, "expected %<:%>")) label = do_case (loc1, NULL_TREE, NULL_TREE); } else { tree name = c_parser_peek_token (parser)->value; tree tlab; tree attrs; location_t loc2 = c_parser_peek_token (parser)->location; gcc_assert (c_parser_next_token_is (parser, CPP_NAME)); c_parser_consume_token (parser); gcc_assert (c_parser_next_token_is (parser, CPP_COLON)); c_parser_consume_token (parser); attrs = c_parser_attributes (parser); tlab = define_label (loc2, name); if (tlab) { decl_attributes (&tlab, attrs, 0); label = add_stmt (build_stmt (loc1, LABEL_EXPR, tlab)); } } if (label) { if (c_parser_next_token_starts_declspecs (parser) && !(c_parser_next_token_is (parser, CPP_NAME) && c_parser_peek_2nd_token (parser)->type == CPP_COLON)) { error_at (c_parser_peek_token (parser)->location, "a label can only be part of a statement and " "a declaration is not a statement"); c_parser_declaration_or_fndef (parser, /*fndef_ok*/ false, /*nested*/ true, /*empty_ok*/ false, /*start_attr_ok*/ true); } } } /* Parse a statement (C90 6.6, C99 6.8). statement: labeled-statement compound-statement expression-statement selection-statement iteration-statement jump-statement labeled-statement: label statement expression-statement: expression[opt] ; selection-statement: if-statement switch-statement iteration-statement: while-statement do-statement for-statement jump-statement: goto identifier ; continue ; break ; return expression[opt] ; GNU extensions: statement: asm-statement jump-statement: goto * expression ; Objective-C: statement: objc-throw-statement objc-try-catch-statement objc-synchronized-statement objc-throw-statement: @throw expression ; @throw ; OpenMP: statement: openmp-construct openmp-construct: parallel-construct for-construct sections-construct single-construct parallel-for-construct parallel-sections-construct master-construct critical-construct atomic-construct ordered-construct parallel-construct: parallel-directive structured-block for-construct: for-directive iteration-statement sections-construct: sections-directive section-scope single-construct: single-directive structured-block parallel-for-construct: parallel-for-directive iteration-statement parallel-sections-construct: parallel-sections-directive section-scope master-construct: master-directive structured-block critical-construct: critical-directive structured-block atomic-construct: atomic-directive expression-statement ordered-construct: ordered-directive structured-block */ static void c_parser_statement (c_parser *parser) { while (c_parser_next_token_is_keyword (parser, RID_CASE) || c_parser_next_token_is_keyword (parser, RID_DEFAULT) || (c_parser_next_token_is (parser, CPP_NAME) && c_parser_peek_2nd_token (parser)->type == CPP_COLON)) c_parser_label (parser); c_parser_statement_after_labels (parser); } /* Parse a statement, other than a labeled statement. */ static void c_parser_statement_after_labels (c_parser *parser) { location_t loc = c_parser_peek_token (parser)->location; tree stmt = NULL_TREE; bool in_if_block = parser->in_if_block; parser->in_if_block = false; switch (c_parser_peek_token (parser)->type) { case CPP_OPEN_BRACE: add_stmt (c_parser_compound_statement (parser)); break; case CPP_KEYWORD: switch (c_parser_peek_token (parser)->keyword) { case RID_IF: c_parser_if_statement (parser); break; case RID_SWITCH: c_parser_switch_statement (parser); break; case RID_WHILE: c_parser_while_statement (parser); break; case RID_DO: c_parser_do_statement (parser); break; case RID_FOR: c_parser_for_statement (parser); break; case RID_GOTO: c_parser_consume_token (parser); if (c_parser_next_token_is (parser, CPP_NAME)) { stmt = c_finish_goto_label (loc, c_parser_peek_token (parser)->value); c_parser_consume_token (parser); } else if (c_parser_next_token_is (parser, CPP_MULT)) { c_parser_consume_token (parser); stmt = c_finish_goto_ptr (loc, c_parser_expression (parser).value); } else c_parser_error (parser, "expected identifier or %<*%>"); goto expect_semicolon; case RID_CONTINUE: c_parser_consume_token (parser); stmt = c_finish_bc_stmt (loc, &c_cont_label, false); goto expect_semicolon; case RID_BREAK: c_parser_consume_token (parser); stmt = c_finish_bc_stmt (loc, &c_break_label, true); goto expect_semicolon; case RID_RETURN: c_parser_consume_token (parser); if (c_parser_next_token_is (parser, CPP_SEMICOLON)) { stmt = c_finish_return (loc, NULL_TREE, NULL_TREE); c_parser_consume_token (parser); } else { struct c_expr expr = c_parser_expression_conv (parser); stmt = c_finish_return (loc, expr.value, expr.original_type); goto expect_semicolon; } break; case RID_ASM: stmt = c_parser_asm_statement (parser); break; case RID_THROW: gcc_assert (c_dialect_objc ()); c_parser_consume_token (parser); if (c_parser_next_token_is (parser, CPP_SEMICOLON)) { stmt = objc_build_throw_stmt (loc, NULL_TREE); c_parser_consume_token (parser); } else { tree expr = c_parser_expression (parser).value; expr = c_fully_fold (expr, false, NULL); stmt = objc_build_throw_stmt (loc, expr); goto expect_semicolon; } break; case RID_TRY: gcc_assert (c_dialect_objc ()); c_parser_objc_try_catch_statement (parser); break; case RID_AT_SYNCHRONIZED: gcc_assert (c_dialect_objc ()); c_parser_objc_synchronized_statement (parser); break; default: goto expr_stmt; } break; case CPP_SEMICOLON: c_parser_consume_token (parser); break; case CPP_CLOSE_PAREN: case CPP_CLOSE_SQUARE: /* Avoid infinite loop in error recovery: c_parser_skip_until_found stops at a closing nesting delimiter without consuming it, but here we need to consume it to proceed further. */ c_parser_error (parser, "expected statement"); c_parser_consume_token (parser); break; case CPP_PRAGMA: c_parser_pragma (parser, pragma_stmt); break; default: expr_stmt: stmt = c_finish_expr_stmt (loc, c_parser_expression_conv (parser).value); expect_semicolon: c_parser_skip_until_found (parser, CPP_SEMICOLON, "expected %<;%>"); break; } /* Two cases cannot and do not have line numbers associated: If stmt is degenerate, such as "2;", then stmt is an INTEGER_CST, which cannot hold line numbers. But that's OK because the statement will either be changed to a MODIFY_EXPR during gimplification of the statement expr, or discarded. If stmt was compound, but without new variables, we will have skipped the creation of a BIND and will have a bare STATEMENT_LIST. But that's OK because (recursively) all of the component statements should already have line numbers assigned. ??? Can we discard no-op statements earlier? */ if (CAN_HAVE_LOCATION_P (stmt) && EXPR_LOCATION (stmt) == UNKNOWN_LOCATION) SET_EXPR_LOCATION (stmt, loc); parser->in_if_block = in_if_block; } /* Parse the condition from an if, do, while or for statements. */ static tree c_parser_condition (c_parser *parser) { location_t loc = c_parser_peek_token (parser)->location; tree cond; cond = c_parser_expression_conv (parser).value; cond = c_objc_common_truthvalue_conversion (loc, cond); cond = c_fully_fold (cond, false, NULL); if (warn_sequence_point) verify_sequence_points (cond); return cond; } /* Parse a parenthesized condition from an if, do or while statement. condition: ( expression ) */ static tree c_parser_paren_condition (c_parser *parser) { tree cond; if (!c_parser_require (parser, CPP_OPEN_PAREN, "expected %<(%>")) return error_mark_node; cond = c_parser_condition (parser); c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, "expected %<)%>"); return cond; } /* Parse a statement which is a block in C99. */ static tree c_parser_c99_block_statement (c_parser *parser) { tree block = c_begin_compound_stmt (flag_isoc99); location_t loc = c_parser_peek_token (parser)->location; c_parser_statement (parser); return c_end_compound_stmt (loc, block, flag_isoc99); } /* Parse the body of an if statement. This is just parsing a statement but (a) it is a block in C99, (b) we track whether the body is an if statement for the sake of -Wparentheses warnings, (c) we handle an empty body specially for the sake of -Wempty-body warnings, and (d) we call parser_compound_statement directly because c_parser_statement_after_labels resets parser->in_if_block. */ static tree c_parser_if_body (c_parser *parser, bool *if_p) { tree block = c_begin_compound_stmt (flag_isoc99); location_t body_loc = c_parser_peek_token (parser)->location; while (c_parser_next_token_is_keyword (parser, RID_CASE) || c_parser_next_token_is_keyword (parser, RID_DEFAULT) || (c_parser_next_token_is (parser, CPP_NAME) && c_parser_peek_2nd_token (parser)->type == CPP_COLON)) c_parser_label (parser); *if_p = c_parser_next_token_is_keyword (parser, RID_IF); if (c_parser_next_token_is (parser, CPP_SEMICOLON)) { location_t loc = c_parser_peek_token (parser)->location; add_stmt (build_empty_stmt (loc)); c_parser_consume_token (parser); if (!c_parser_next_token_is_keyword (parser, RID_ELSE)) warning_at (loc, OPT_Wempty_body, "suggest braces around empty body in an %<if%> statement"); } else if (c_parser_next_token_is (parser, CPP_OPEN_BRACE)) add_stmt (c_parser_compound_statement (parser)); else c_parser_statement_after_labels (parser); return c_end_compound_stmt (body_loc, block, flag_isoc99); } /* Parse the else body of an if statement. This is just parsing a statement but (a) it is a block in C99, (b) we handle an empty body specially for the sake of -Wempty-body warnings. */ static tree c_parser_else_body (c_parser *parser) { location_t else_loc = c_parser_peek_token (parser)->location; tree block = c_begin_compound_stmt (flag_isoc99); while (c_parser_next_token_is_keyword (parser, RID_CASE) || c_parser_next_token_is_keyword (parser, RID_DEFAULT) || (c_parser_next_token_is (parser, CPP_NAME) && c_parser_peek_2nd_token (parser)->type == CPP_COLON)) c_parser_label (parser); if (c_parser_next_token_is (parser, CPP_SEMICOLON)) { location_t loc = c_parser_peek_token (parser)->location; warning_at (loc, OPT_Wempty_body, "suggest braces around empty body in an %<else%> statement"); add_stmt (build_empty_stmt (loc)); c_parser_consume_token (parser); } else c_parser_statement_after_labels (parser); return c_end_compound_stmt (else_loc, block, flag_isoc99); } /* Parse an if statement (C90 6.6.4, C99 6.8.4). if-statement: if ( expression ) statement if ( expression ) statement else statement */ static void c_parser_if_statement (c_parser *parser) { tree block; location_t loc; tree cond; bool first_if = false; tree first_body, second_body; bool in_if_block; gcc_assert (c_parser_next_token_is_keyword (parser, RID_IF)); c_parser_consume_token (parser); block = c_begin_compound_stmt (flag_isoc99); loc = c_parser_peek_token (parser)->location; cond = c_parser_paren_condition (parser); in_if_block = parser->in_if_block; parser->in_if_block = true; first_body = c_parser_if_body (parser, &first_if); parser->in_if_block = in_if_block; if (c_parser_next_token_is_keyword (parser, RID_ELSE)) { c_parser_consume_token (parser); second_body = c_parser_else_body (parser); } else second_body = NULL_TREE; c_finish_if_stmt (loc, cond, first_body, second_body, first_if); add_stmt (c_end_compound_stmt (loc, block, flag_isoc99)); } /* Parse a switch statement (C90 6.6.4, C99 6.8.4). switch-statement: switch (expression) statement */ static void c_parser_switch_statement (c_parser *parser) { tree block, expr, body, save_break; location_t switch_loc = c_parser_peek_token (parser)->location; location_t switch_cond_loc; gcc_assert (c_parser_next_token_is_keyword (parser, RID_SWITCH)); c_parser_consume_token (parser); block = c_begin_compound_stmt (flag_isoc99); if (c_parser_require (parser, CPP_OPEN_PAREN, "expected %<(%>")) { switch_cond_loc = c_parser_peek_token (parser)->location; expr = c_parser_expression (parser).value; c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, "expected %<)%>"); } else { switch_cond_loc = UNKNOWN_LOCATION; expr = error_mark_node; } c_start_case (switch_loc, switch_cond_loc, expr); save_break = c_break_label; c_break_label = NULL_TREE; body = c_parser_c99_block_statement (parser); c_finish_case (body); if (c_break_label) { location_t here = c_parser_peek_token (parser)->location; tree t = build1 (LABEL_EXPR, void_type_node, c_break_label); SET_EXPR_LOCATION (t, here); add_stmt (t); } c_break_label = save_break; add_stmt (c_end_compound_stmt (switch_loc, block, flag_isoc99)); } /* Parse a while statement (C90 6.6.5, C99 6.8.5). while-statement: while (expression) statement */ static void c_parser_while_statement (c_parser *parser) { tree block, cond, body, save_break, save_cont; location_t loc; gcc_assert (c_parser_next_token_is_keyword (parser, RID_WHILE)); c_parser_consume_token (parser); block = c_begin_compound_stmt (flag_isoc99); loc = c_parser_peek_token (parser)->location; cond = c_parser_paren_condition (parser); save_break = c_break_label; c_break_label = NULL_TREE; save_cont = c_cont_label; c_cont_label = NULL_TREE; body = c_parser_c99_block_statement (parser); c_finish_loop (loc, cond, NULL, body, c_break_label, c_cont_label, true); add_stmt (c_end_compound_stmt (loc, block, flag_isoc99)); c_break_label = save_break; c_cont_label = save_cont; } /* Parse a do statement (C90 6.6.5, C99 6.8.5). do-statement: do statement while ( expression ) ; */ static void c_parser_do_statement (c_parser *parser) { tree block, cond, body, save_break, save_cont, new_break, new_cont; location_t loc; gcc_assert (c_parser_next_token_is_keyword (parser, RID_DO)); c_parser_consume_token (parser); if (c_parser_next_token_is (parser, CPP_SEMICOLON)) warning_at (c_parser_peek_token (parser)->location, OPT_Wempty_body, "suggest braces around empty body in %<do%> statement"); block = c_begin_compound_stmt (flag_isoc99); loc = c_parser_peek_token (parser)->location; save_break = c_break_label; c_break_label = NULL_TREE; save_cont = c_cont_label; c_cont_label = NULL_TREE; body = c_parser_c99_block_statement (parser); c_parser_require_keyword (parser, RID_WHILE, "expected %<while%>"); new_break = c_break_label; c_break_label = save_break; new_cont = c_cont_label; c_cont_label = save_cont; cond = c_parser_paren_condition (parser); if (!c_parser_require (parser, CPP_SEMICOLON, "expected %<;%>")) c_parser_skip_to_end_of_block_or_statement (parser); c_finish_loop (loc, cond, NULL, body, new_break, new_cont, false); add_stmt (c_end_compound_stmt (loc, block, flag_isoc99)); } /* Parse a for statement (C90 6.6.5, C99 6.8.5). for-statement: for ( expression[opt] ; expression[opt] ; expression[opt] ) statement for ( nested-declaration expression[opt] ; expression[opt] ) statement The form with a declaration is new in C99. ??? In accordance with the old parser, the declaration may be a nested function, which is then rejected in check_for_loop_decls, but does it make any sense for this to be included in the grammar? Note in particular that the nested function does not include a trailing ';', whereas the "declaration" production includes one. Also, can we reject bad declarations earlier and cheaper than check_for_loop_decls? */ static void c_parser_for_statement (c_parser *parser) { tree block, cond, incr, save_break, save_cont, body; location_t loc = c_parser_peek_token (parser)->location; location_t for_loc = c_parser_peek_token (parser)->location; gcc_assert (c_parser_next_token_is_keyword (parser, RID_FOR)); c_parser_consume_token (parser); block = c_begin_compound_stmt (flag_isoc99); if (c_parser_require (parser, CPP_OPEN_PAREN, "expected %<(%>")) { /* Parse the initialization declaration or expression. */ if (c_parser_next_token_is (parser, CPP_SEMICOLON)) { c_parser_consume_token (parser); c_finish_expr_stmt (loc, NULL_TREE); } else if (c_parser_next_token_starts_declspecs (parser)) { c_parser_declaration_or_fndef (parser, true, true, true, true); check_for_loop_decls (for_loc); } else if (c_parser_next_token_is_keyword (parser, RID_EXTENSION)) { /* __extension__ can start a declaration, but is also an unary operator that can start an expression. Consume all but the last of a possible series of __extension__ to determine which. */ while (c_parser_peek_2nd_token (parser)->type == CPP_KEYWORD && (c_parser_peek_2nd_token (parser)->keyword == RID_EXTENSION)) c_parser_consume_token (parser); if (c_token_starts_declspecs (c_parser_peek_2nd_token (parser))) { int ext; ext = disable_extension_diagnostics (); c_parser_consume_token (parser); c_parser_declaration_or_fndef (parser, true, true, true, true); restore_extension_diagnostics (ext); check_for_loop_decls (for_loc); } else goto init_expr; } else { init_expr: c_finish_expr_stmt (loc, c_parser_expression (parser).value); c_parser_skip_until_found (parser, CPP_SEMICOLON, "expected %<;%>"); } /* Parse the loop condition. */ if (c_parser_next_token_is (parser, CPP_SEMICOLON)) { c_parser_consume_token (parser); cond = NULL_TREE; } else { cond = c_parser_condition (parser); c_parser_skip_until_found (parser, CPP_SEMICOLON, "expected %<;%>"); } /* Parse the increment expression. */ if (c_parser_next_token_is (parser, CPP_CLOSE_PAREN)) incr = c_process_expr_stmt (loc, NULL_TREE); else incr = c_process_expr_stmt (loc, c_parser_expression (parser).value); c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, "expected %<)%>"); } else { cond = error_mark_node; incr = error_mark_node; } save_break = c_break_label; c_break_label = NULL_TREE; save_cont = c_cont_label; c_cont_label = NULL_TREE; body = c_parser_c99_block_statement (parser); c_finish_loop (loc, cond, incr, body, c_break_label, c_cont_label, true); add_stmt (c_end_compound_stmt (loc, block, flag_isoc99)); c_break_label = save_break; c_cont_label = save_cont; } /* Parse an asm statement, a GNU extension. This is a full-blown asm statement with inputs, outputs, clobbers, and volatile tag allowed. asm-statement: asm type-qualifier[opt] ( asm-argument ) ; asm type-qualifier[opt] goto ( asm-goto-argument ) ; asm-argument: asm-string-literal asm-string-literal : asm-operands[opt] asm-string-literal : asm-operands[opt] : asm-operands[opt] asm-string-literal : asm-operands[opt] : asm-operands[opt] : asm-clobbers[opt] asm-goto-argument: asm-string-literal : : asm-operands[opt] : asm-clobbers[opt] \ : asm-goto-operands Qualifiers other than volatile are accepted in the syntax but warned for. */ static tree c_parser_asm_statement (c_parser *parser) { tree quals, str, outputs, inputs, clobbers, labels, ret; bool simple, is_goto; location_t asm_loc = c_parser_peek_token (parser)->location; int section, nsections; gcc_assert (c_parser_next_token_is_keyword (parser, RID_ASM)); c_parser_consume_token (parser); if (c_parser_next_token_is_keyword (parser, RID_VOLATILE)) { quals = c_parser_peek_token (parser)->value; c_parser_consume_token (parser); } else if (c_parser_next_token_is_keyword (parser, RID_CONST) || c_parser_next_token_is_keyword (parser, RID_RESTRICT)) { warning_at (c_parser_peek_token (parser)->location, 0, "%E qualifier ignored on asm", c_parser_peek_token (parser)->value); quals = NULL_TREE; c_parser_consume_token (parser); } else quals = NULL_TREE; is_goto = false; if (c_parser_next_token_is_keyword (parser, RID_GOTO)) { c_parser_consume_token (parser); is_goto = true; } /* ??? Follow the C++ parser rather than using the lex_untranslated_string kludge. */ parser->lex_untranslated_string = true; ret = NULL; if (!c_parser_require (parser, CPP_OPEN_PAREN, "expected %<(%>")) goto error; str = c_parser_asm_string_literal (parser); if (str == NULL_TREE) goto error_close_paren; simple = true; outputs = NULL_TREE; inputs = NULL_TREE; clobbers = NULL_TREE; labels = NULL_TREE; if (c_parser_next_token_is (parser, CPP_CLOSE_PAREN) && !is_goto) goto done_asm; /* Parse each colon-delimited section of operands. */ nsections = 3 + is_goto; for (section = 0; section < nsections; ++section) { if (!c_parser_require (parser, CPP_COLON, is_goto ? "expected %<:%>" : "expected %<:%> or %<)%>")) goto error_close_paren; /* Once past any colon, we're no longer a simple asm. */ simple = false; if ((!c_parser_next_token_is (parser, CPP_COLON) && !c_parser_next_token_is (parser, CPP_CLOSE_PAREN)) || section == 3) switch (section) { case 0: /* For asm goto, we don't allow output operands, but reserve the slot for a future extension that does allow them. */ if (!is_goto) outputs = c_parser_asm_operands (parser, false); break; case 1: inputs = c_parser_asm_operands (parser, true); break; case 2: clobbers = c_parser_asm_clobbers (parser); break; case 3: labels = c_parser_asm_goto_operands (parser); break; default: gcc_unreachable (); } if (c_parser_next_token_is (parser, CPP_CLOSE_PAREN) && !is_goto) goto done_asm; } done_asm: if (!c_parser_require (parser, CPP_CLOSE_PAREN, "expected %<)%>")) { c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, NULL); goto error; } if (!c_parser_require (parser, CPP_SEMICOLON, "expected %<;%>")) c_parser_skip_to_end_of_block_or_statement (parser); ret = build_asm_stmt (quals, build_asm_expr (asm_loc, str, outputs, inputs, clobbers, labels, simple)); error: parser->lex_untranslated_string = false; return ret; error_close_paren: c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, NULL); goto error; } /* Parse asm operands, a GNU extension. If CONVERT_P (for inputs but not outputs), apply the default conversion of functions and arrays to pointers. asm-operands: asm-operand asm-operands , asm-operand asm-operand: asm-string-literal ( expression ) [ identifier ] asm-string-literal ( expression ) */ static tree c_parser_asm_operands (c_parser *parser, bool convert_p) { tree list = NULL_TREE; location_t loc; while (true) { tree name, str; struct c_expr expr; if (c_parser_next_token_is (parser, CPP_OPEN_SQUARE)) { c_parser_consume_token (parser); if (c_parser_next_token_is (parser, CPP_NAME)) { tree id = c_parser_peek_token (parser)->value; c_parser_consume_token (parser); name = build_string (IDENTIFIER_LENGTH (id), IDENTIFIER_POINTER (id)); } else { c_parser_error (parser, "expected identifier"); c_parser_skip_until_found (parser, CPP_CLOSE_SQUARE, NULL); return NULL_TREE; } c_parser_skip_until_found (parser, CPP_CLOSE_SQUARE, "expected %<]%>"); } else name = NULL_TREE; str = c_parser_asm_string_literal (parser); if (str == NULL_TREE) return NULL_TREE; parser->lex_untranslated_string = false; if (!c_parser_require (parser, CPP_OPEN_PAREN, "expected %<(%>")) { parser->lex_untranslated_string = true; return NULL_TREE; } loc = c_parser_peek_token (parser)->location; expr = c_parser_expression (parser); if (convert_p) expr = default_function_array_conversion (loc, expr); expr.value = c_fully_fold (expr.value, false, NULL); parser->lex_untranslated_string = true; if (!c_parser_require (parser, CPP_CLOSE_PAREN, "expected %<)%>")) { c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, NULL); return NULL_TREE; } list = chainon (list, build_tree_list (build_tree_list (name, str), expr.value)); if (c_parser_next_token_is (parser, CPP_COMMA)) c_parser_consume_token (parser); else break; } return list; } /* Parse asm clobbers, a GNU extension. asm-clobbers: asm-string-literal asm-clobbers , asm-string-literal */ static tree c_parser_asm_clobbers (c_parser *parser) { tree list = NULL_TREE; while (true) { tree str = c_parser_asm_string_literal (parser); if (str) list = tree_cons (NULL_TREE, str, list); else return NULL_TREE; if (c_parser_next_token_is (parser, CPP_COMMA)) c_parser_consume_token (parser); else break; } return list; } /* Parse asm goto labels, a GNU extension. asm-goto-operands: identifier asm-goto-operands , identifier */ static tree c_parser_asm_goto_operands (c_parser *parser) { tree list = NULL_TREE; while (true) { tree name, label; if (c_parser_next_token_is (parser, CPP_NAME)) { c_token *tok = c_parser_peek_token (parser); name = tok->value; label = lookup_label_for_goto (tok->location, name); c_parser_consume_token (parser); TREE_USED (label) = 1; } else { c_parser_error (parser, "expected identifier"); return NULL_TREE; } name = build_string (IDENTIFIER_LENGTH (name), IDENTIFIER_POINTER (name)); list = tree_cons (name, label, list); if (c_parser_next_token_is (parser, CPP_COMMA)) c_parser_consume_token (parser); else return nreverse (list); } } /* Parse an expression other than a compound expression; that is, an assignment expression (C90 6.3.16, C99 6.5.16). If AFTER is not NULL then it is an Objective-C message expression which is the primary-expression starting the expression as an initializer. assignment-expression: conditional-expression unary-expression assignment-operator assignment-expression assignment-operator: one of = *= /= %= += -= <<= >>= &= ^= |= In GNU C we accept any conditional expression on the LHS and diagnose the invalid lvalue rather than producing a syntax error. */ static struct c_expr c_parser_expr_no_commas (c_parser *parser, struct c_expr *after) { struct c_expr lhs, rhs, ret; enum tree_code code; location_t op_location, exp_location; gcc_assert (!after || c_dialect_objc ()); lhs = c_parser_conditional_expression (parser, after); op_location = c_parser_peek_token (parser)->location; switch (c_parser_peek_token (parser)->type) { case CPP_EQ: code = NOP_EXPR; break; case CPP_MULT_EQ: code = MULT_EXPR; break; case CPP_DIV_EQ: code = TRUNC_DIV_EXPR; break; case CPP_MOD_EQ: code = TRUNC_MOD_EXPR; break; case CPP_PLUS_EQ: code = PLUS_EXPR; break; case CPP_MINUS_EQ: code = MINUS_EXPR; break; case CPP_LSHIFT_EQ: code = LSHIFT_EXPR; break; case CPP_RSHIFT_EQ: code = RSHIFT_EXPR; break; case CPP_AND_EQ: code = BIT_AND_EXPR; break; case CPP_XOR_EQ: code = BIT_XOR_EXPR; break; case CPP_OR_EQ: code = BIT_IOR_EXPR; break; default: return lhs; } c_parser_consume_token (parser); exp_location = c_parser_peek_token (parser)->location; rhs = c_parser_expr_no_commas (parser, NULL); rhs = default_function_array_conversion (exp_location, rhs); ret.value = build_modify_expr (op_location, lhs.value, lhs.original_type, code, exp_location, rhs.value, rhs.original_type); if (code == NOP_EXPR) ret.original_code = MODIFY_EXPR; else { TREE_NO_WARNING (ret.value) = 1; ret.original_code = ERROR_MARK; } ret.original_type = NULL; return ret; } /* Parse a conditional expression (C90 6.3.15, C99 6.5.15). If AFTER is not NULL then it is an Objective-C message expression which is the primary-expression starting the expression as an initializer. conditional-expression: logical-OR-expression logical-OR-expression ? expression : conditional-expression GNU extensions: conditional-expression: logical-OR-expression ? : conditional-expression */ static struct c_expr c_parser_conditional_expression (c_parser *parser, struct c_expr *after) { struct c_expr cond, exp1, exp2, ret; location_t cond_loc, colon_loc; gcc_assert (!after || c_dialect_objc ()); cond = c_parser_binary_expression (parser, after); if (c_parser_next_token_is_not (parser, CPP_QUERY)) return cond; cond_loc = c_parser_peek_token (parser)->location; cond = default_function_array_conversion (cond_loc, cond); c_parser_consume_token (parser); if (c_parser_next_token_is (parser, CPP_COLON)) { tree eptype = NULL_TREE; pedwarn (c_parser_peek_token (parser)->location, OPT_pedantic, "ISO C forbids omitting the middle term of a ?: expression"); if (TREE_CODE (cond.value) == EXCESS_PRECISION_EXPR) { eptype = TREE_TYPE (cond.value); cond.value = TREE_OPERAND (cond.value, 0); } /* Make sure first operand is calculated only once. */ exp1.value = c_save_expr (default_conversion (cond.value)); if (eptype) exp1.value = build1 (EXCESS_PRECISION_EXPR, eptype, exp1.value); exp1.original_type = NULL; cond.value = c_objc_common_truthvalue_conversion (cond_loc, exp1.value); c_inhibit_evaluation_warnings += cond.value == truthvalue_true_node; } else { cond.value = c_objc_common_truthvalue_conversion (cond_loc, default_conversion (cond.value)); c_inhibit_evaluation_warnings += cond.value == truthvalue_false_node; exp1 = c_parser_expression_conv (parser); c_inhibit_evaluation_warnings += ((cond.value == truthvalue_true_node) - (cond.value == truthvalue_false_node)); } colon_loc = c_parser_peek_token (parser)->location; if (!c_parser_require (parser, CPP_COLON, "expected %<:%>")) { c_inhibit_evaluation_warnings -= cond.value == truthvalue_true_node; ret.value = error_mark_node; ret.original_code = ERROR_MARK; ret.original_type = NULL; return ret; } { location_t exp2_loc = c_parser_peek_token (parser)->location; exp2 = c_parser_conditional_expression (parser, NULL); exp2 = default_function_array_conversion (exp2_loc, exp2); } c_inhibit_evaluation_warnings -= cond.value == truthvalue_true_node; ret.value = build_conditional_expr (colon_loc, cond.value, cond.original_code == C_MAYBE_CONST_EXPR, exp1.value, exp1.original_type, exp2.value, exp2.original_type); ret.original_code = ERROR_MARK; if (exp1.value == error_mark_node || exp2.value == error_mark_node) ret.original_type = NULL; else { tree t1, t2; /* If both sides are enum type, the default conversion will have made the type of the result be an integer type. We want to remember the enum types we started with. */ t1 = exp1.original_type ? exp1.original_type : TREE_TYPE (exp1.value); t2 = exp2.original_type ? exp2.original_type : TREE_TYPE (exp2.value); ret.original_type = ((t1 != error_mark_node && t2 != error_mark_node && (TYPE_MAIN_VARIANT (t1) == TYPE_MAIN_VARIANT (t2))) ? t1 : NULL); } return ret; } /* Parse a binary expression; that is, a logical-OR-expression (C90 6.3.5-6.3.14, C99 6.5.5-6.5.14). If AFTER is not NULL then it is an Objective-C message expression which is the primary-expression starting the expression as an initializer. multiplicative-expression: cast-expression multiplicative-expression * cast-expression multiplicative-expression / cast-expression multiplicative-expression % cast-expression additive-expression: multiplicative-expression additive-expression + multiplicative-expression additive-expression - multiplicative-expression shift-expression: additive-expression shift-expression << additive-expression shift-expression >> additive-expression relational-expression: shift-expression relational-expression < shift-expression relational-expression > shift-expression relational-expression <= shift-expression relational-expression >= shift-expression equality-expression: relational-expression equality-expression == relational-expression equality-expression != relational-expression AND-expression: equality-expression AND-expression & equality-expression exclusive-OR-expression: AND-expression exclusive-OR-expression ^ AND-expression inclusive-OR-expression: exclusive-OR-expression inclusive-OR-expression | exclusive-OR-expression logical-AND-expression: inclusive-OR-expression logical-AND-expression && inclusive-OR-expression logical-OR-expression: logical-AND-expression logical-OR-expression || logical-AND-expression */ static struct c_expr c_parser_binary_expression (c_parser *parser, struct c_expr *after) { /* A binary expression is parsed using operator-precedence parsing, with the operands being cast expressions. All the binary operators are left-associative. Thus a binary expression is of form: E0 op1 E1 op2 E2 ... which we represent on a stack. On the stack, the precedence levels are strictly increasing. When a new operator is encountered of higher precedence than that at the top of the stack, it is pushed; its LHS is the top expression, and its RHS is everything parsed until it is popped. When a new operator is encountered with precedence less than or equal to that at the top of the stack, triples E[i-1] op[i] E[i] are popped and replaced by the result of the operation until the operator at the top of the stack has lower precedence than the new operator or there is only one element on the stack; then the top expression is the LHS of the new operator. In the case of logical AND and OR expressions, we also need to adjust c_inhibit_evaluation_warnings as appropriate when the operators are pushed and popped. */ /* The precedence levels, where 0 is a dummy lowest level used for the bottom of the stack. */ enum prec { PREC_NONE, PREC_LOGOR, PREC_LOGAND, PREC_BITOR, PREC_BITXOR, PREC_BITAND, PREC_EQ, PREC_REL, PREC_SHIFT, PREC_ADD, PREC_MULT, NUM_PRECS }; struct { /* The expression at this stack level. */ struct c_expr expr; /* The precedence of the operator on its left, PREC_NONE at the bottom of the stack. */ enum prec prec; /* The operation on its left. */ enum tree_code op; /* The source location of this operation. */ location_t loc; } stack[NUM_PRECS]; int sp; /* Location of the binary operator. */ location_t binary_loc = UNKNOWN_LOCATION; /* Quiet warning. */ #define POP \ do { \ switch (stack[sp].op) \ { \ case TRUTH_ANDIF_EXPR: \ c_inhibit_evaluation_warnings -= (stack[sp - 1].expr.value \ == truthvalue_false_node); \ break; \ case TRUTH_ORIF_EXPR: \ c_inhibit_evaluation_warnings -= (stack[sp - 1].expr.value \ == truthvalue_true_node); \ break; \ default: \ break; \ } \ stack[sp - 1].expr \ = default_function_array_conversion (stack[sp - 1].loc, \ stack[sp - 1].expr); \ stack[sp].expr \ = default_function_array_conversion (stack[sp].loc, stack[sp].expr); \ stack[sp - 1].expr = parser_build_binary_op (stack[sp].loc, \ stack[sp].op, \ stack[sp - 1].expr, \ stack[sp].expr); \ sp--; \ } while (0) gcc_assert (!after || c_dialect_objc ()); stack[0].loc = c_parser_peek_token (parser)->location; stack[0].expr = c_parser_cast_expression (parser, after); stack[0].prec = PREC_NONE; sp = 0; while (true) { enum prec oprec; enum tree_code ocode; if (parser->error) goto out; switch (c_parser_peek_token (parser)->type) { case CPP_MULT: oprec = PREC_MULT; ocode = MULT_EXPR; break; case CPP_DIV: oprec = PREC_MULT; ocode = TRUNC_DIV_EXPR; break; case CPP_MOD: oprec = PREC_MULT; ocode = TRUNC_MOD_EXPR; break; case CPP_PLUS: oprec = PREC_ADD; ocode = PLUS_EXPR; break; case CPP_MINUS: oprec = PREC_ADD; ocode = MINUS_EXPR; break; case CPP_LSHIFT: oprec = PREC_SHIFT; ocode = LSHIFT_EXPR; break; case CPP_RSHIFT: oprec = PREC_SHIFT; ocode = RSHIFT_EXPR; break; case CPP_LESS: oprec = PREC_REL; ocode = LT_EXPR; break; case CPP_GREATER: oprec = PREC_REL; ocode = GT_EXPR; break; case CPP_LESS_EQ: oprec = PREC_REL; ocode = LE_EXPR; break; case CPP_GREATER_EQ: oprec = PREC_REL; ocode = GE_EXPR; break; case CPP_EQ_EQ: oprec = PREC_EQ; ocode = EQ_EXPR; break; case CPP_NOT_EQ: oprec = PREC_EQ; ocode = NE_EXPR; break; case CPP_AND: oprec = PREC_BITAND; ocode = BIT_AND_EXPR; break; case CPP_XOR: oprec = PREC_BITXOR; ocode = BIT_XOR_EXPR; break; case CPP_OR: oprec = PREC_BITOR; ocode = BIT_IOR_EXPR; break; case CPP_AND_AND: oprec = PREC_LOGAND; ocode = TRUTH_ANDIF_EXPR; break; case CPP_OR_OR: oprec = PREC_LOGOR; ocode = TRUTH_ORIF_EXPR; break; default: /* Not a binary operator, so end of the binary expression. */ goto out; } binary_loc = c_parser_peek_token (parser)->location; c_parser_consume_token (parser); while (oprec <= stack[sp].prec) POP; switch (ocode) { case TRUTH_ANDIF_EXPR: stack[sp].expr = default_function_array_conversion (stack[sp].loc, stack[sp].expr); stack[sp].expr.value = c_objc_common_truthvalue_conversion (stack[sp].loc, default_conversion (stack[sp].expr.value)); c_inhibit_evaluation_warnings += (stack[sp].expr.value == truthvalue_false_node); break; case TRUTH_ORIF_EXPR: stack[sp].expr = default_function_array_conversion (stack[sp].loc, stack[sp].expr); stack[sp].expr.value = c_objc_common_truthvalue_conversion (stack[sp].loc, default_conversion (stack[sp].expr.value)); c_inhibit_evaluation_warnings += (stack[sp].expr.value == truthvalue_true_node); break; default: break; } sp++; stack[sp].loc = binary_loc; stack[sp].expr = c_parser_cast_expression (parser, NULL); stack[sp].prec = oprec; stack[sp].op = ocode; stack[sp].loc = binary_loc; } out: while (sp > 0) POP; return stack[0].expr; #undef POP } /* Parse a cast expression (C90 6.3.4, C99 6.5.4). If AFTER is not NULL then it is an Objective-C message expression which is the primary-expression starting the expression as an initializer. cast-expression: unary-expression ( type-name ) unary-expression */ static struct c_expr c_parser_cast_expression (c_parser *parser, struct c_expr *after) { location_t cast_loc = c_parser_peek_token (parser)->location; gcc_assert (!after || c_dialect_objc ()); if (after) return c_parser_postfix_expression_after_primary (parser, cast_loc, *after); /* If the expression begins with a parenthesized type name, it may be either a cast or a compound literal; we need to see whether the next character is '{' to tell the difference. If not, it is an unary expression. */ if (c_parser_next_token_is (parser, CPP_OPEN_PAREN) && c_token_starts_typename (c_parser_peek_2nd_token (parser))) { struct c_type_name *type_name; struct c_expr ret; struct c_expr expr; c_parser_consume_token (parser); type_name = c_parser_type_name (parser); c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, "expected %<)%>"); if (type_name == NULL) { ret.value = error_mark_node; ret.original_code = ERROR_MARK; ret.original_type = NULL; return ret; } /* Save casted types in the function's used types hash table. */ used_types_insert (type_name->specs->type); if (c_parser_next_token_is (parser, CPP_OPEN_BRACE)) return c_parser_postfix_expression_after_paren_type (parser, type_name, cast_loc); { location_t expr_loc = c_parser_peek_token (parser)->location; expr = c_parser_cast_expression (parser, NULL); expr = default_function_array_conversion (expr_loc, expr); } ret.value = c_cast_expr (cast_loc, type_name, expr.value); ret.original_code = ERROR_MARK; ret.original_type = NULL; return ret; } else return c_parser_unary_expression (parser); } /* Parse an unary expression (C90 6.3.3, C99 6.5.3). unary-expression: postfix-expression ++ unary-expression -- unary-expression unary-operator cast-expression sizeof unary-expression sizeof ( type-name ) unary-operator: one of & * + - ~ ! GNU extensions: unary-expression: __alignof__ unary-expression __alignof__ ( type-name ) && identifier unary-operator: one of __extension__ __real__ __imag__ In addition, the GNU syntax treats ++ and -- as unary operators, so they may be applied to cast expressions with errors for non-lvalues given later. */ static struct c_expr c_parser_unary_expression (c_parser *parser) { int ext; struct c_expr ret, op; location_t op_loc = c_parser_peek_token (parser)->location; location_t exp_loc; ret.original_code = ERROR_MARK; ret.original_type = NULL; switch (c_parser_peek_token (parser)->type) { case CPP_PLUS_PLUS: c_parser_consume_token (parser); exp_loc = c_parser_peek_token (parser)->location; op = c_parser_cast_expression (parser, NULL); op = default_function_array_conversion (exp_loc, op); return parser_build_unary_op (op_loc, PREINCREMENT_EXPR, op); case CPP_MINUS_MINUS: c_parser_consume_token (parser); exp_loc = c_parser_peek_token (parser)->location; op = c_parser_cast_expression (parser, NULL); op = default_function_array_conversion (exp_loc, op); return parser_build_unary_op (op_loc, PREDECREMENT_EXPR, op); case CPP_AND: c_parser_consume_token (parser); return parser_build_unary_op (op_loc, ADDR_EXPR, c_parser_cast_expression (parser, NULL)); case CPP_MULT: c_parser_consume_token (parser); exp_loc = c_parser_peek_token (parser)->location; op = c_parser_cast_expression (parser, NULL); op = default_function_array_conversion (exp_loc, op); ret.value = build_indirect_ref (op_loc, op.value, RO_UNARY_STAR); return ret; case CPP_PLUS: if (!c_dialect_objc () && !in_system_header) warning_at (op_loc, OPT_Wtraditional, "traditional C rejects the unary plus operator"); c_parser_consume_token (parser); exp_loc = c_parser_peek_token (parser)->location; op = c_parser_cast_expression (parser, NULL); op = default_function_array_conversion (exp_loc, op); return parser_build_unary_op (op_loc, CONVERT_EXPR, op); case CPP_MINUS: c_parser_consume_token (parser); exp_loc = c_parser_peek_token (parser)->location; op = c_parser_cast_expression (parser, NULL); op = default_function_array_conversion (exp_loc, op); return parser_build_unary_op (op_loc, NEGATE_EXPR, op); case CPP_COMPL: c_parser_consume_token (parser); exp_loc = c_parser_peek_token (parser)->location; op = c_parser_cast_expression (parser, NULL); op = default_function_array_conversion (exp_loc, op); return parser_build_unary_op (op_loc, BIT_NOT_EXPR, op); case CPP_NOT: c_parser_consume_token (parser); exp_loc = c_parser_peek_token (parser)->location; op = c_parser_cast_expression (parser, NULL); op = default_function_array_conversion (exp_loc, op); return parser_build_unary_op (op_loc, TRUTH_NOT_EXPR, op); case CPP_AND_AND: /* Refer to the address of a label as a pointer. */ c_parser_consume_token (parser); if (c_parser_next_token_is (parser, CPP_NAME)) { ret.value = finish_label_address_expr (c_parser_peek_token (parser)->value, op_loc); c_parser_consume_token (parser); } else { c_parser_error (parser, "expected identifier"); ret.value = error_mark_node; } return ret; case CPP_KEYWORD: switch (c_parser_peek_token (parser)->keyword) { case RID_SIZEOF: return c_parser_sizeof_expression (parser); case RID_ALIGNOF: return c_parser_alignof_expression (parser); case RID_EXTENSION: c_parser_consume_token (parser); ext = disable_extension_diagnostics (); ret = c_parser_cast_expression (parser, NULL); restore_extension_diagnostics (ext); return ret; case RID_REALPART: c_parser_consume_token (parser); exp_loc = c_parser_peek_token (parser)->location; op = c_parser_cast_expression (parser, NULL); op = default_function_array_conversion (exp_loc, op); return parser_build_unary_op (op_loc, REALPART_EXPR, op); case RID_IMAGPART: c_parser_consume_token (parser); exp_loc = c_parser_peek_token (parser)->location; op = c_parser_cast_expression (parser, NULL); op = default_function_array_conversion (exp_loc, op); return parser_build_unary_op (op_loc, IMAGPART_EXPR, op); default: return c_parser_postfix_expression (parser); } default: return c_parser_postfix_expression (parser); } } /* Parse a sizeof expression. */ static struct c_expr c_parser_sizeof_expression (c_parser *parser) { struct c_expr expr; location_t expr_loc; gcc_assert (c_parser_next_token_is_keyword (parser, RID_SIZEOF)); c_parser_consume_token (parser); c_inhibit_evaluation_warnings++; in_sizeof++; if (c_parser_next_token_is (parser, CPP_OPEN_PAREN) && c_token_starts_typename (c_parser_peek_2nd_token (parser))) { /* Either sizeof ( type-name ) or sizeof unary-expression starting with a compound literal. */ struct c_type_name *type_name; c_parser_consume_token (parser); expr_loc = c_parser_peek_token (parser)->location; type_name = c_parser_type_name (parser); c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, "expected %<)%>"); if (type_name == NULL) { struct c_expr ret; c_inhibit_evaluation_warnings--; in_sizeof--; ret.value = error_mark_node; ret.original_code = ERROR_MARK; ret.original_type = NULL; return ret; } if (c_parser_next_token_is (parser, CPP_OPEN_BRACE)) { expr = c_parser_postfix_expression_after_paren_type (parser, type_name, expr_loc); goto sizeof_expr; } /* sizeof ( type-name ). */ c_inhibit_evaluation_warnings--; in_sizeof--; return c_expr_sizeof_type (expr_loc, type_name); } else { expr_loc = c_parser_peek_token (parser)->location; expr = c_parser_unary_expression (parser); sizeof_expr: c_inhibit_evaluation_warnings--; in_sizeof--; if (TREE_CODE (expr.value) == COMPONENT_REF && DECL_C_BIT_FIELD (TREE_OPERAND (expr.value, 1))) error_at (expr_loc, "%<sizeof%> applied to a bit-field"); return c_expr_sizeof_expr (expr_loc, expr); } } /* Parse an alignof expression. */ static struct c_expr c_parser_alignof_expression (c_parser *parser) { struct c_expr expr; location_t loc = c_parser_peek_token (parser)->location; gcc_assert (c_parser_next_token_is_keyword (parser, RID_ALIGNOF)); c_parser_consume_token (parser); c_inhibit_evaluation_warnings++; in_alignof++; if (c_parser_next_token_is (parser, CPP_OPEN_PAREN) && c_token_starts_typename (c_parser_peek_2nd_token (parser))) { /* Either __alignof__ ( type-name ) or __alignof__ unary-expression starting with a compound literal. */ location_t loc; struct c_type_name *type_name; struct c_expr ret; c_parser_consume_token (parser); loc = c_parser_peek_token (parser)->location; type_name = c_parser_type_name (parser); c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, "expected %<)%>"); if (type_name == NULL) { struct c_expr ret; c_inhibit_evaluation_warnings--; in_alignof--; ret.value = error_mark_node; ret.original_code = ERROR_MARK; ret.original_type = NULL; return ret; } if (c_parser_next_token_is (parser, CPP_OPEN_BRACE)) { expr = c_parser_postfix_expression_after_paren_type (parser, type_name, loc); goto alignof_expr; } /* alignof ( type-name ). */ c_inhibit_evaluation_warnings--; in_alignof--; ret.value = c_alignof (loc, groktypename (type_name, NULL, NULL)); ret.original_code = ERROR_MARK; ret.original_type = NULL; return ret; } else { struct c_expr ret; expr = c_parser_unary_expression (parser); alignof_expr: c_inhibit_evaluation_warnings--; in_alignof--; ret.value = c_alignof_expr (loc, expr.value); ret.original_code = ERROR_MARK; ret.original_type = NULL; return ret; } } /* Parse a postfix expression (C90 6.3.1-6.3.2, C99 6.5.1-6.5.2). postfix-expression: primary-expression postfix-expression [ expression ] postfix-expression ( argument-expression-list[opt] ) postfix-expression . identifier postfix-expression -> identifier postfix-expression ++ postfix-expression -- ( type-name ) { initializer-list } ( type-name ) { initializer-list , } argument-expression-list: argument-expression argument-expression-list , argument-expression primary-expression: identifier constant string-literal ( expression ) GNU extensions: primary-expression: __func__ (treated as a keyword in GNU C) __FUNCTION__ __PRETTY_FUNCTION__ ( compound-statement ) __builtin_va_arg ( assignment-expression , type-name ) __builtin_offsetof ( type-name , offsetof-member-designator ) __builtin_choose_expr ( assignment-expression , assignment-expression , assignment-expression ) __builtin_types_compatible_p ( type-name , type-name ) offsetof-member-designator: identifier offsetof-member-designator . identifier offsetof-member-designator [ expression ] Objective-C: primary-expression: [ objc-receiver objc-message-args ] @selector ( objc-selector-arg ) @protocol ( identifier ) @encode ( type-name ) objc-string-literal */ static struct c_expr c_parser_postfix_expression (c_parser *parser) { struct c_expr expr, e1, e2, e3; struct c_type_name *t1, *t2; location_t loc = c_parser_peek_token (parser)->location;; expr.original_code = ERROR_MARK; expr.original_type = NULL; switch (c_parser_peek_token (parser)->type) { case CPP_NUMBER: expr.value = c_parser_peek_token (parser)->value; loc = c_parser_peek_token (parser)->location; c_parser_consume_token (parser); if (TREE_CODE (expr.value) == FIXED_CST && !targetm.fixed_point_supported_p ()) { error_at (loc, "fixed-point types not supported for this target"); expr.value = error_mark_node; } break; case CPP_CHAR: case CPP_CHAR16: case CPP_CHAR32: case CPP_WCHAR: expr.value = c_parser_peek_token (parser)->value; c_parser_consume_token (parser); break; case CPP_STRING: case CPP_STRING16: case CPP_STRING32: case CPP_WSTRING: case CPP_UTF8STRING: expr.value = c_parser_peek_token (parser)->value; expr.original_code = STRING_CST; c_parser_consume_token (parser); break; case CPP_OBJC_STRING: gcc_assert (c_dialect_objc ()); expr.value = objc_build_string_object (c_parser_peek_token (parser)->value); c_parser_consume_token (parser); break; case CPP_NAME: if (c_parser_peek_token (parser)->id_kind != C_ID_ID) { c_parser_error (parser, "expected expression"); expr.value = error_mark_node; break; } { tree id = c_parser_peek_token (parser)->value; c_parser_consume_token (parser); expr.value = build_external_ref (loc, id, (c_parser_peek_token (parser)->type == CPP_OPEN_PAREN), &expr.original_type); } break; case CPP_OPEN_PAREN: /* A parenthesized expression, statement expression or compound literal. */ if (c_parser_peek_2nd_token (parser)->type == CPP_OPEN_BRACE) { /* A statement expression. */ tree stmt; location_t brace_loc; c_parser_consume_token (parser); brace_loc = c_parser_peek_token (parser)->location; c_parser_consume_token (parser); if (cur_stmt_list == NULL) { error_at (loc, "braced-group within expression allowed " "only inside a function"); parser->error = true; c_parser_skip_until_found (parser, CPP_CLOSE_BRACE, NULL); c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, NULL); expr.value = error_mark_node; break; } stmt = c_begin_stmt_expr (); c_parser_compound_statement_nostart (parser); c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, "expected %<)%>"); pedwarn (loc, OPT_pedantic, "ISO C forbids braced-groups within expressions"); expr.value = c_finish_stmt_expr (brace_loc, stmt); } else if (c_token_starts_typename (c_parser_peek_2nd_token (parser))) { /* A compound literal. ??? Can we actually get here rather than going directly to c_parser_postfix_expression_after_paren_type from elsewhere? */ location_t loc; struct c_type_name *type_name; c_parser_consume_token (parser); loc = c_parser_peek_token (parser)->location; type_name = c_parser_type_name (parser); c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, "expected %<)%>"); if (type_name == NULL) { expr.value = error_mark_node; } else expr = c_parser_postfix_expression_after_paren_type (parser, type_name, loc); } else { /* A parenthesized expression. */ c_parser_consume_token (parser); expr = c_parser_expression (parser); if (TREE_CODE (expr.value) == MODIFY_EXPR) TREE_NO_WARNING (expr.value) = 1; if (expr.original_code != C_MAYBE_CONST_EXPR) expr.original_code = ERROR_MARK; /* Don't change EXPR.ORIGINAL_TYPE. */ c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, "expected %<)%>"); } break; case CPP_KEYWORD: switch (c_parser_peek_token (parser)->keyword) { case RID_FUNCTION_NAME: case RID_PRETTY_FUNCTION_NAME: case RID_C99_FUNCTION_NAME: expr.value = fname_decl (loc, c_parser_peek_token (parser)->keyword, c_parser_peek_token (parser)->value); c_parser_consume_token (parser); break; case RID_VA_ARG: c_parser_consume_token (parser); if (!c_parser_require (parser, CPP_OPEN_PAREN, "expected %<(%>")) { expr.value = error_mark_node; break; } e1 = c_parser_expr_no_commas (parser, NULL); e1.value = c_fully_fold (e1.value, false, NULL); if (!c_parser_require (parser, CPP_COMMA, "expected %<,%>")) { c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, NULL); expr.value = error_mark_node; break; } loc = c_parser_peek_token (parser)->location; t1 = c_parser_type_name (parser); c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, "expected %<)%>"); if (t1 == NULL) { expr.value = error_mark_node; } else { tree type_expr = NULL_TREE; expr.value = c_build_va_arg (loc, e1.value, groktypename (t1, &type_expr, NULL)); if (type_expr) { expr.value = build2 (C_MAYBE_CONST_EXPR, TREE_TYPE (expr.value), type_expr, expr.value); C_MAYBE_CONST_EXPR_NON_CONST (expr.value) = true; } } break; case RID_OFFSETOF: c_parser_consume_token (parser); if (!c_parser_require (parser, CPP_OPEN_PAREN, "expected %<(%>")) { expr.value = error_mark_node; break; } t1 = c_parser_type_name (parser); if (t1 == NULL) { expr.value = error_mark_node; break; } if (!c_parser_require (parser, CPP_COMMA, "expected %<,%>")) { c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, NULL); expr.value = error_mark_node; break; } { tree type = groktypename (t1, NULL, NULL); tree offsetof_ref; if (type == error_mark_node) offsetof_ref = error_mark_node; else { offsetof_ref = build1 (INDIRECT_REF, type, null_pointer_node); SET_EXPR_LOCATION (offsetof_ref, loc); } /* Parse the second argument to __builtin_offsetof. We must have one identifier, and beyond that we want to accept sub structure and sub array references. */ if (c_parser_next_token_is (parser, CPP_NAME)) { offsetof_ref = build_component_ref (loc, offsetof_ref, c_parser_peek_token (parser)->value); c_parser_consume_token (parser); while (c_parser_next_token_is (parser, CPP_DOT) || c_parser_next_token_is (parser, CPP_OPEN_SQUARE) || c_parser_next_token_is (parser, CPP_DEREF)) { if (c_parser_next_token_is (parser, CPP_DEREF)) { loc = c_parser_peek_token (parser)->location; offsetof_ref = build_array_ref (loc, offsetof_ref, integer_zero_node); goto do_dot; } else if (c_parser_next_token_is (parser, CPP_DOT)) { do_dot: c_parser_consume_token (parser); if (c_parser_next_token_is_not (parser, CPP_NAME)) { c_parser_error (parser, "expected identifier"); break; } offsetof_ref = build_component_ref (loc, offsetof_ref, c_parser_peek_token (parser)->value); c_parser_consume_token (parser); } else { tree idx; loc = c_parser_peek_token (parser)->location; c_parser_consume_token (parser); idx = c_parser_expression (parser).value; idx = c_fully_fold (idx, false, NULL); c_parser_skip_until_found (parser, CPP_CLOSE_SQUARE, "expected %<]%>"); offsetof_ref = build_array_ref (loc, offsetof_ref, idx); } } } else c_parser_error (parser, "expected identifier"); c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, "expected %<)%>"); expr.value = fold_offsetof (offsetof_ref, NULL_TREE); } break; case RID_CHOOSE_EXPR: c_parser_consume_token (parser); if (!c_parser_require (parser, CPP_OPEN_PAREN, "expected %<(%>")) { expr.value = error_mark_node; break; } loc = c_parser_peek_token (parser)->location; e1 = c_parser_expr_no_commas (parser, NULL); if (!c_parser_require (parser, CPP_COMMA, "expected %<,%>")) { c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, NULL); expr.value = error_mark_node; break; } e2 = c_parser_expr_no_commas (parser, NULL); if (!c_parser_require (parser, CPP_COMMA, "expected %<,%>")) { c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, NULL); expr.value = error_mark_node; break; } e3 = c_parser_expr_no_commas (parser, NULL); c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, "expected %<)%>"); { tree c; c = e1.value; if (TREE_CODE (c) != INTEGER_CST || !INTEGRAL_TYPE_P (TREE_TYPE (c))) error_at (loc, "first argument to %<__builtin_choose_expr%> not" " a constant"); constant_expression_warning (c); expr = integer_zerop (c) ? e3 : e2; } break; case RID_TYPES_COMPATIBLE_P: c_parser_consume_token (parser); if (!c_parser_require (parser, CPP_OPEN_PAREN, "expected %<(%>")) { expr.value = error_mark_node; break; } t1 = c_parser_type_name (parser); if (t1 == NULL) { expr.value = error_mark_node; break; } if (!c_parser_require (parser, CPP_COMMA, "expected %<,%>")) { c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, NULL); expr.value = error_mark_node; break; } t2 = c_parser_type_name (parser); if (t2 == NULL) { expr.value = error_mark_node; break; } c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, "expected %<)%>"); { tree e1, e2; e1 = TYPE_MAIN_VARIANT (groktypename (t1, NULL, NULL)); e2 = TYPE_MAIN_VARIANT (groktypename (t2, NULL, NULL)); expr.value = comptypes (e1, e2) ? build_int_cst (NULL_TREE, 1) : build_int_cst (NULL_TREE, 0); } break; case RID_AT_SELECTOR: gcc_assert (c_dialect_objc ()); c_parser_consume_token (parser); if (!c_parser_require (parser, CPP_OPEN_PAREN, "expected %<(%>")) { expr.value = error_mark_node; break; } { tree sel = c_parser_objc_selector_arg (parser); c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, "expected %<)%>"); expr.value = objc_build_selector_expr (loc, sel); } break; case RID_AT_PROTOCOL: gcc_assert (c_dialect_objc ()); c_parser_consume_token (parser); if (!c_parser_require (parser, CPP_OPEN_PAREN, "expected %<(%>")) { expr.value = error_mark_node; break; } if (c_parser_next_token_is_not (parser, CPP_NAME)) { c_parser_error (parser, "expected identifier"); c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, NULL); expr.value = error_mark_node; break; } { tree id = c_parser_peek_token (parser)->value; c_parser_consume_token (parser); c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, "expected %<)%>"); expr.value = objc_build_protocol_expr (id); } break; case RID_AT_ENCODE: /* Extension to support C-structures in the archiver. */ gcc_assert (c_dialect_objc ()); c_parser_consume_token (parser); if (!c_parser_require (parser, CPP_OPEN_PAREN, "expected %<(%>")) { expr.value = error_mark_node; break; } t1 = c_parser_type_name (parser); if (t1 == NULL) { expr.value = error_mark_node; c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, NULL); break; } c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, "expected %<)%>"); { tree type = groktypename (t1, NULL, NULL); expr.value = objc_build_encode_expr (type); } break; default: c_parser_error (parser, "expected expression"); expr.value = error_mark_node; break; } break; case CPP_OPEN_SQUARE: if (c_dialect_objc ()) { tree receiver, args; c_parser_consume_token (parser); receiver = c_parser_objc_receiver (parser); args = c_parser_objc_message_args (parser); c_parser_skip_until_found (parser, CPP_CLOSE_SQUARE, "expected %<]%>"); expr.value = objc_build_message_expr (build_tree_list (receiver, args)); break; } /* Else fall through to report error. */ default: c_parser_error (parser, "expected expression"); expr.value = error_mark_node; break; } return c_parser_postfix_expression_after_primary (parser, loc, expr); } /* Parse a postfix expression after a parenthesized type name: the brace-enclosed initializer of a compound literal, possibly followed by some postfix operators. This is separate because it is not possible to tell until after the type name whether a cast expression has a cast or a compound literal, or whether the operand of sizeof is a parenthesized type name or starts with a compound literal. TYPE_LOC is the location where TYPE_NAME starts--the location of the first token after the parentheses around the type name. */ static struct c_expr c_parser_postfix_expression_after_paren_type (c_parser *parser, struct c_type_name *type_name, location_t type_loc) { tree type; struct c_expr init; bool non_const; struct c_expr expr; location_t start_loc; tree type_expr = NULL_TREE; bool type_expr_const = true; check_compound_literal_type (type_loc, type_name); start_init (NULL_TREE, NULL, 0); type = groktypename (type_name, &type_expr, &type_expr_const); start_loc = c_parser_peek_token (parser)->location; if (type != error_mark_node && C_TYPE_VARIABLE_SIZE (type)) { error_at (type_loc, "compound literal has variable size"); type = error_mark_node; } init = c_parser_braced_init (parser, type, false); finish_init (); maybe_warn_string_init (type, init); if (type != error_mark_node && !ADDR_SPACE_GENERIC_P (TYPE_ADDR_SPACE (type)) && current_function_decl) { error ("compound literal qualified by address-space qualifier"); type = error_mark_node; } if (!flag_isoc99) pedwarn (start_loc, OPT_pedantic, "ISO C90 forbids compound literals"); non_const = ((init.value && TREE_CODE (init.value) == CONSTRUCTOR) ? CONSTRUCTOR_NON_CONST (init.value) : init.original_code == C_MAYBE_CONST_EXPR); non_const |= !type_expr_const; expr.value = build_compound_literal (start_loc, type, init.value, non_const); expr.original_code = ERROR_MARK; expr.original_type = NULL; if (type_expr) { if (TREE_CODE (expr.value) == C_MAYBE_CONST_EXPR) { gcc_assert (C_MAYBE_CONST_EXPR_PRE (expr.value) == NULL_TREE); C_MAYBE_CONST_EXPR_PRE (expr.value) = type_expr; } else { gcc_assert (!non_const); expr.value = build2 (C_MAYBE_CONST_EXPR, type, type_expr, expr.value); } } return c_parser_postfix_expression_after_primary (parser, start_loc, expr); } /* Parse a postfix expression after the initial primary or compound literal; that is, parse a series of postfix operators. EXPR_LOC is the location of the primary expression. */ static struct c_expr c_parser_postfix_expression_after_primary (c_parser *parser, location_t expr_loc, struct c_expr expr) { struct c_expr orig_expr; tree ident, idx; VEC(tree,gc) *exprlist; VEC(tree,gc) *origtypes; while (true) { location_t op_loc = c_parser_peek_token (parser)->location; switch (c_parser_peek_token (parser)->type) { case CPP_OPEN_SQUARE: /* Array reference. */ c_parser_consume_token (parser); idx = c_parser_expression (parser).value; c_parser_skip_until_found (parser, CPP_CLOSE_SQUARE, "expected %<]%>"); expr.value = build_array_ref (op_loc, expr.value, idx); expr.original_code = ERROR_MARK; expr.original_type = NULL; break; case CPP_OPEN_PAREN: /* Function call. */ c_parser_consume_token (parser); if (c_parser_next_token_is (parser, CPP_CLOSE_PAREN)) exprlist = NULL; else exprlist = c_parser_expr_list (parser, true, false, &origtypes); c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, "expected %<)%>"); orig_expr = expr; /* FIXME diagnostics: Ideally we want the FUNCNAME, not the "(" after the FUNCNAME, which is what we have now. */ expr.value = build_function_call_vec (op_loc, expr.value, exprlist, origtypes); expr.original_code = ERROR_MARK; if (TREE_CODE (expr.value) == INTEGER_CST && TREE_CODE (orig_expr.value) == FUNCTION_DECL && DECL_BUILT_IN_CLASS (orig_expr.value) == BUILT_IN_NORMAL && DECL_FUNCTION_CODE (orig_expr.value) == BUILT_IN_CONSTANT_P) expr.original_code = C_MAYBE_CONST_EXPR; expr.original_type = NULL; if (exprlist != NULL) { release_tree_vector (exprlist); release_tree_vector (origtypes); } break; case CPP_DOT: /* Structure element reference. */ c_parser_consume_token (parser); expr = default_function_array_conversion (expr_loc, expr); if (c_parser_next_token_is (parser, CPP_NAME)) ident = c_parser_peek_token (parser)->value; else { c_parser_error (parser, "expected identifier"); expr.value = error_mark_node; expr.original_code = ERROR_MARK; expr.original_type = NULL; return expr; } c_parser_consume_token (parser); expr.value = build_component_ref (op_loc, expr.value, ident); expr.original_code = ERROR_MARK; if (TREE_CODE (expr.value) != COMPONENT_REF) expr.original_type = NULL; else { /* Remember the original type of a bitfield. */ tree field = TREE_OPERAND (expr.value, 1); if (TREE_CODE (field) != FIELD_DECL) expr.original_type = NULL; else expr.original_type = DECL_BIT_FIELD_TYPE (field); } break; case CPP_DEREF: /* Structure element reference. */ c_parser_consume_token (parser); expr = default_function_array_conversion (expr_loc, expr); if (c_parser_next_token_is (parser, CPP_NAME)) ident = c_parser_peek_token (parser)->value; else { c_parser_error (parser, "expected identifier"); expr.value = error_mark_node; expr.original_code = ERROR_MARK; expr.original_type = NULL; return expr; } c_parser_consume_token (parser); expr.value = build_component_ref (op_loc, build_indirect_ref (op_loc, expr.value, RO_ARROW), ident); expr.original_code = ERROR_MARK; if (TREE_CODE (expr.value) != COMPONENT_REF) expr.original_type = NULL; else { /* Remember the original type of a bitfield. */ tree field = TREE_OPERAND (expr.value, 1); if (TREE_CODE (field) != FIELD_DECL) expr.original_type = NULL; else expr.original_type = DECL_BIT_FIELD_TYPE (field); } break; case CPP_PLUS_PLUS: /* Postincrement. */ c_parser_consume_token (parser); expr = default_function_array_conversion (expr_loc, expr); expr.value = build_unary_op (op_loc, POSTINCREMENT_EXPR, expr.value, 0); expr.original_code = ERROR_MARK; expr.original_type = NULL; break; case CPP_MINUS_MINUS: /* Postdecrement. */ c_parser_consume_token (parser); expr = default_function_array_conversion (expr_loc, expr); expr.value = build_unary_op (op_loc, POSTDECREMENT_EXPR, expr.value, 0); expr.original_code = ERROR_MARK; expr.original_type = NULL; break; default: return expr; } } } /* Parse an expression (C90 6.3.17, C99 6.5.17). expression: assignment-expression expression , assignment-expression */ static struct c_expr c_parser_expression (c_parser *parser) { struct c_expr expr; expr = c_parser_expr_no_commas (parser, NULL); while (c_parser_next_token_is (parser, CPP_COMMA)) { struct c_expr next; location_t loc = c_parser_peek_token (parser)->location; location_t expr_loc; c_parser_consume_token (parser); expr_loc = c_parser_peek_token (parser)->location; next = c_parser_expr_no_commas (parser, NULL); next = default_function_array_conversion (expr_loc, next); expr.value = build_compound_expr (loc, expr.value, next.value); expr.original_code = COMPOUND_EXPR; expr.original_type = next.original_type; } return expr; } /* Parse an expression and convert functions or arrays to pointers. */ static struct c_expr c_parser_expression_conv (c_parser *parser) { struct c_expr expr; location_t loc = c_parser_peek_token (parser)->location; expr = c_parser_expression (parser); expr = default_function_array_conversion (loc, expr); return expr; } /* Parse a non-empty list of expressions. If CONVERT_P, convert functions and arrays to pointers. If FOLD_P, fold the expressions. nonempty-expr-list: assignment-expression nonempty-expr-list , assignment-expression */ static VEC(tree,gc) * c_parser_expr_list (c_parser *parser, bool convert_p, bool fold_p, VEC(tree,gc) **p_orig_types) { VEC(tree,gc) *ret; VEC(tree,gc) *orig_types; struct c_expr expr; location_t loc = c_parser_peek_token (parser)->location; ret = make_tree_vector (); if (p_orig_types == NULL) orig_types = NULL; else orig_types = make_tree_vector (); expr = c_parser_expr_no_commas (parser, NULL); if (convert_p) expr = default_function_array_conversion (loc, expr); if (fold_p) expr.value = c_fully_fold (expr.value, false, NULL); VEC_quick_push (tree, ret, expr.value); if (orig_types != NULL) VEC_quick_push (tree, orig_types, expr.original_type); while (c_parser_next_token_is (parser, CPP_COMMA)) { c_parser_consume_token (parser); loc = c_parser_peek_token (parser)->location; expr = c_parser_expr_no_commas (parser, NULL); if (convert_p) expr = default_function_array_conversion (loc, expr); if (fold_p) expr.value = c_fully_fold (expr.value, false, NULL); VEC_safe_push (tree, gc, ret, expr.value); if (orig_types != NULL) VEC_safe_push (tree, gc, orig_types, expr.original_type); } if (orig_types != NULL) *p_orig_types = orig_types; return ret; } /* Parse Objective-C-specific constructs. */ /* Parse an objc-class-definition. objc-class-definition: @interface identifier objc-superclass[opt] objc-protocol-refs[opt] objc-class-instance-variables[opt] objc-methodprotolist @end @implementation identifier objc-superclass[opt] objc-class-instance-variables[opt] @interface identifier ( identifier ) objc-protocol-refs[opt] objc-methodprotolist @end @implementation identifier ( identifier ) objc-superclass: : identifier "@interface identifier (" must start "@interface identifier ( identifier ) ...": objc-methodprotolist in the first production may not start with a parenthesized identifier as a declarator of a data definition with no declaration specifiers if the objc-superclass, objc-protocol-refs and objc-class-instance-variables are omitted. */ static void c_parser_objc_class_definition (c_parser *parser) { bool iface_p; tree id1; tree superclass; if (c_parser_next_token_is_keyword (parser, RID_AT_INTERFACE)) iface_p = true; else if (c_parser_next_token_is_keyword (parser, RID_AT_IMPLEMENTATION)) iface_p = false; else gcc_unreachable (); c_parser_consume_token (parser); if (c_parser_next_token_is_not (parser, CPP_NAME)) { c_parser_error (parser, "expected identifier"); return; } id1 = c_parser_peek_token (parser)->value; c_parser_consume_token (parser); if (c_parser_next_token_is (parser, CPP_OPEN_PAREN)) { tree id2; tree proto = NULL_TREE; c_parser_consume_token (parser); if (c_parser_next_token_is_not (parser, CPP_NAME)) { c_parser_error (parser, "expected identifier"); c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, NULL); return; } id2 = c_parser_peek_token (parser)->value; c_parser_consume_token (parser); c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, "expected %<)%>"); if (!iface_p) { objc_start_category_implementation (id1, id2); return; } if (c_parser_next_token_is (parser, CPP_LESS)) proto = c_parser_objc_protocol_refs (parser); objc_start_category_interface (id1, id2, proto); c_parser_objc_methodprotolist (parser); c_parser_require_keyword (parser, RID_AT_END, "expected %<@end%>"); objc_finish_interface (); return; } if (c_parser_next_token_is (parser, CPP_COLON)) { c_parser_consume_token (parser); if (c_parser_next_token_is_not (parser, CPP_NAME)) { c_parser_error (parser, "expected identifier"); return; } superclass = c_parser_peek_token (parser)->value; c_parser_consume_token (parser); } else superclass = NULL_TREE; if (iface_p) { tree proto = NULL_TREE; if (c_parser_next_token_is (parser, CPP_LESS)) proto = c_parser_objc_protocol_refs (parser); objc_start_class_interface (id1, superclass, proto); } else objc_start_class_implementation (id1, superclass); if (c_parser_next_token_is (parser, CPP_OPEN_BRACE)) c_parser_objc_class_instance_variables (parser); if (iface_p) { objc_continue_interface (); c_parser_objc_methodprotolist (parser); c_parser_require_keyword (parser, RID_AT_END, "expected %<@end%>"); objc_finish_interface (); } else { objc_continue_implementation (); return; } } /* Parse objc-class-instance-variables. objc-class-instance-variables: { objc-instance-variable-decl-list[opt] } objc-instance-variable-decl-list: objc-visibility-spec objc-instance-variable-decl ; ; objc-instance-variable-decl-list objc-visibility-spec objc-instance-variable-decl-list objc-instance-variable-decl ; objc-instance-variable-decl-list ; objc-visibility-spec: @private @protected @public objc-instance-variable-decl: struct-declaration */ static void c_parser_objc_class_instance_variables (c_parser *parser) { gcc_assert (c_parser_next_token_is (parser, CPP_OPEN_BRACE)); c_parser_consume_token (parser); while (c_parser_next_token_is_not (parser, CPP_EOF)) { tree decls; /* Parse any stray semicolon. */ if (c_parser_next_token_is (parser, CPP_SEMICOLON)) { pedwarn (c_parser_peek_token (parser)->location, OPT_pedantic, "extra semicolon in struct or union specified"); c_parser_consume_token (parser); continue; } /* Stop if at the end of the instance variables. */ if (c_parser_next_token_is (parser, CPP_CLOSE_BRACE)) { c_parser_consume_token (parser); break; } /* Parse any objc-visibility-spec. */ if (c_parser_next_token_is_keyword (parser, RID_PRIVATE)) { c_parser_consume_token (parser); objc_set_visibility (2); continue; } else if (c_parser_next_token_is_keyword (parser, RID_PROTECTED)) { c_parser_consume_token (parser); objc_set_visibility (0); continue; } else if (c_parser_next_token_is_keyword (parser, RID_PUBLIC)) { c_parser_consume_token (parser); objc_set_visibility (1); continue; } else if (c_parser_next_token_is (parser, CPP_PRAGMA)) { c_parser_pragma (parser, pragma_external); continue; } /* Parse some comma-separated declarations. */ decls = c_parser_struct_declaration (parser); { /* Comma-separated instance variables are chained together in reverse order; add them one by one. */ tree ivar = nreverse (decls); for (; ivar; ivar = TREE_CHAIN (ivar)) objc_add_instance_variable (copy_node (ivar)); } c_parser_skip_until_found (parser, CPP_SEMICOLON, "expected %<;%>"); } } /* Parse an objc-class-declaration. objc-class-declaration: @class identifier-list ; */ static void c_parser_objc_class_declaration (c_parser *parser) { tree list = NULL_TREE; gcc_assert (c_parser_next_token_is_keyword (parser, RID_CLASS)); c_parser_consume_token (parser); /* Any identifiers, including those declared as type names, are OK here. */ while (true) { tree id; if (c_parser_next_token_is_not (parser, CPP_NAME)) { c_parser_error (parser, "expected identifier"); break; } id = c_parser_peek_token (parser)->value; list = chainon (list, build_tree_list (NULL_TREE, id)); c_parser_consume_token (parser); if (c_parser_next_token_is (parser, CPP_COMMA)) c_parser_consume_token (parser); else break; } c_parser_skip_until_found (parser, CPP_SEMICOLON, "expected %<;%>"); objc_declare_class (list); } /* Parse an objc-alias-declaration. objc-alias-declaration: @compatibility_alias identifier identifier ; */ static void c_parser_objc_alias_declaration (c_parser *parser) { tree id1, id2; gcc_assert (c_parser_next_token_is_keyword (parser, RID_AT_ALIAS)); c_parser_consume_token (parser); if (c_parser_next_token_is_not (parser, CPP_NAME)) { c_parser_error (parser, "expected identifier"); c_parser_skip_until_found (parser, CPP_SEMICOLON, NULL); return; } id1 = c_parser_peek_token (parser)->value; c_parser_consume_token (parser); if (c_parser_next_token_is_not (parser, CPP_NAME)) { c_parser_error (parser, "expected identifier"); c_parser_skip_until_found (parser, CPP_SEMICOLON, NULL); return; } id2 = c_parser_peek_token (parser)->value; c_parser_consume_token (parser); c_parser_skip_until_found (parser, CPP_SEMICOLON, "expected %<;%>"); objc_declare_alias (id1, id2); } /* Parse an objc-protocol-definition. objc-protocol-definition: @protocol identifier objc-protocol-refs[opt] objc-methodprotolist @end @protocol identifier-list ; "@protocol identifier ;" should be resolved as "@protocol identifier-list ;": objc-methodprotolist may not start with a semicolon in the first alternative if objc-protocol-refs are omitted. */ static void c_parser_objc_protocol_definition (c_parser *parser) { gcc_assert (c_parser_next_token_is_keyword (parser, RID_AT_PROTOCOL)); c_parser_consume_token (parser); if (c_parser_next_token_is_not (parser, CPP_NAME)) { c_parser_error (parser, "expected identifier"); return; } if (c_parser_peek_2nd_token (parser)->type == CPP_COMMA || c_parser_peek_2nd_token (parser)->type == CPP_SEMICOLON) { tree list = NULL_TREE; /* Any identifiers, including those declared as type names, are OK here. */ while (true) { tree id; if (c_parser_next_token_is_not (parser, CPP_NAME)) { c_parser_error (parser, "expected identifier"); break; } id = c_parser_peek_token (parser)->value; list = chainon (list, build_tree_list (NULL_TREE, id)); c_parser_consume_token (parser); if (c_parser_next_token_is (parser, CPP_COMMA)) c_parser_consume_token (parser); else break; } c_parser_skip_until_found (parser, CPP_SEMICOLON, "expected %<;%>"); objc_declare_protocols (list); } else { tree id = c_parser_peek_token (parser)->value; tree proto = NULL_TREE; c_parser_consume_token (parser); if (c_parser_next_token_is (parser, CPP_LESS)) proto = c_parser_objc_protocol_refs (parser); parser->objc_pq_context = true; objc_start_protocol (id, proto); c_parser_objc_methodprotolist (parser); c_parser_require_keyword (parser, RID_AT_END, "expected %<@end%>"); parser->objc_pq_context = false; objc_finish_interface (); } } /* Parse an objc-method-type. objc-method-type: + - */ static enum tree_code c_parser_objc_method_type (c_parser *parser) { switch (c_parser_peek_token (parser)->type) { case CPP_PLUS: c_parser_consume_token (parser); return PLUS_EXPR; case CPP_MINUS: c_parser_consume_token (parser); return MINUS_EXPR; default: gcc_unreachable (); } } /* Parse an objc-method-definition. objc-method-definition: objc-method-type objc-method-decl ;[opt] compound-statement */ static void c_parser_objc_method_definition (c_parser *parser) { enum tree_code type = c_parser_objc_method_type (parser); tree decl; objc_set_method_type (type); parser->objc_pq_context = true; decl = c_parser_objc_method_decl (parser); if (c_parser_next_token_is (parser, CPP_SEMICOLON)) { c_parser_consume_token (parser); pedwarn (c_parser_peek_token (parser)->location, OPT_pedantic, "extra semicolon in method definition specified"); } if (!c_parser_next_token_is (parser, CPP_OPEN_BRACE)) { c_parser_error (parser, "expected %<{%>"); return; } parser->objc_pq_context = false; objc_start_method_definition (decl); add_stmt (c_parser_compound_statement (parser)); objc_finish_method_definition (current_function_decl); } /* Parse an objc-methodprotolist. objc-methodprotolist: empty objc-methodprotolist objc-methodproto objc-methodprotolist declaration objc-methodprotolist ; The declaration is a data definition, which may be missing declaration specifiers under the same rules and diagnostics as other data definitions outside functions, and the stray semicolon is diagnosed the same way as a stray semicolon outside a function. */ static void c_parser_objc_methodprotolist (c_parser *parser) { while (true) { /* The list is terminated by @end. */ switch (c_parser_peek_token (parser)->type) { case CPP_SEMICOLON: pedwarn (c_parser_peek_token (parser)->location, OPT_pedantic, "ISO C does not allow extra %<;%> outside of a function"); c_parser_consume_token (parser); break; case CPP_PLUS: case CPP_MINUS: c_parser_objc_methodproto (parser); break; case CPP_PRAGMA: c_parser_pragma (parser, pragma_external); break; case CPP_EOF: return; default: if (c_parser_next_token_is_keyword (parser, RID_AT_END)) return; c_parser_declaration_or_fndef (parser, false, true, false, true); break; } } } /* Parse an objc-methodproto. objc-methodproto: objc-method-type objc-method-decl ; */ static void c_parser_objc_methodproto (c_parser *parser) { enum tree_code type = c_parser_objc_method_type (parser); tree decl; objc_set_method_type (type); /* Remember protocol qualifiers in prototypes. */ parser->objc_pq_context = true; decl = c_parser_objc_method_decl (parser); /* Forget protocol qualifiers here. */ parser->objc_pq_context = false; objc_add_method_declaration (decl); c_parser_skip_until_found (parser, CPP_SEMICOLON, "expected %<;%>"); } /* Parse an objc-method-decl. objc-method-decl: ( objc-type-name ) objc-selector objc-selector ( objc-type-name ) objc-keyword-selector objc-optparmlist objc-keyword-selector objc-optparmlist objc-keyword-selector: objc-keyword-decl objc-keyword-selector objc-keyword-decl objc-keyword-decl: objc-selector : ( objc-type-name ) identifier objc-selector : identifier : ( objc-type-name ) identifier : identifier objc-optparmlist: objc-optparms objc-optellipsis objc-optparms: empty objc-opt-parms , parameter-declaration objc-optellipsis: empty , ... */ static tree c_parser_objc_method_decl (c_parser *parser) { tree type = NULL_TREE; tree sel; tree parms = NULL_TREE; bool ellipsis = false; if (c_parser_next_token_is (parser, CPP_OPEN_PAREN)) { c_parser_consume_token (parser); type = c_parser_objc_type_name (parser); c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, "expected %<)%>"); } sel = c_parser_objc_selector (parser); /* If there is no selector, or a colon follows, we have an objc-keyword-selector. If there is a selector, and a colon does not follow, that selector ends the objc-method-decl. */ if (!sel || c_parser_next_token_is (parser, CPP_COLON)) { tree tsel = sel; tree list = NULL_TREE; while (true) { tree atype = NULL_TREE, id, keyworddecl; if (!c_parser_require (parser, CPP_COLON, "expected %<:%>")) break; if (c_parser_next_token_is (parser, CPP_OPEN_PAREN)) { c_parser_consume_token (parser); atype = c_parser_objc_type_name (parser); c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, "expected %<)%>"); } if (c_parser_next_token_is_not (parser, CPP_NAME)) { c_parser_error (parser, "expected identifier"); return error_mark_node; } id = c_parser_peek_token (parser)->value; c_parser_consume_token (parser); keyworddecl = objc_build_keyword_decl (tsel, atype, id); list = chainon (list, keyworddecl); tsel = c_parser_objc_selector (parser); if (!tsel && c_parser_next_token_is_not (parser, CPP_COLON)) break; } /* Parse the optional parameter list. Optional Objective-C method parameters follow the C syntax, and may include '...' to denote a variable number of arguments. */ parms = make_node (TREE_LIST); while (c_parser_next_token_is (parser, CPP_COMMA)) { struct c_parm *parm; c_parser_consume_token (parser); if (c_parser_next_token_is (parser, CPP_ELLIPSIS)) { ellipsis = true; c_parser_consume_token (parser); break; } parm = c_parser_parameter_declaration (parser, NULL_TREE); if (parm == NULL) break; parms = chainon (parms, build_tree_list (NULL_TREE, grokparm (parm))); } sel = list; } return objc_build_method_signature (type, sel, parms, ellipsis); } /* Parse an objc-type-name. objc-type-name: objc-type-qualifiers[opt] type-name objc-type-qualifiers[opt] objc-type-qualifiers: objc-type-qualifier objc-type-qualifiers objc-type-qualifier objc-type-qualifier: one of in out inout bycopy byref oneway */ static tree c_parser_objc_type_name (c_parser *parser) { tree quals = NULL_TREE; struct c_type_name *type_name = NULL; tree type = NULL_TREE; while (true) { c_token *token = c_parser_peek_token (parser); if (token->type == CPP_KEYWORD && (token->keyword == RID_IN || token->keyword == RID_OUT || token->keyword == RID_INOUT || token->keyword == RID_BYCOPY || token->keyword == RID_BYREF || token->keyword == RID_ONEWAY)) { quals = chainon (quals, build_tree_list (NULL_TREE, token->value)); c_parser_consume_token (parser); } else break; } if (c_parser_next_token_starts_typename (parser)) type_name = c_parser_type_name (parser); if (type_name) type = groktypename (type_name, NULL, NULL); return build_tree_list (quals, type); } /* Parse objc-protocol-refs. objc-protocol-refs: < identifier-list > */ static tree c_parser_objc_protocol_refs (c_parser *parser) { tree list = NULL_TREE; gcc_assert (c_parser_next_token_is (parser, CPP_LESS)); c_parser_consume_token (parser); /* Any identifiers, including those declared as type names, are OK here. */ while (true) { tree id; if (c_parser_next_token_is_not (parser, CPP_NAME)) { c_parser_error (parser, "expected identifier"); break; } id = c_parser_peek_token (parser)->value; list = chainon (list, build_tree_list (NULL_TREE, id)); c_parser_consume_token (parser); if (c_parser_next_token_is (parser, CPP_COMMA)) c_parser_consume_token (parser); else break; } c_parser_require (parser, CPP_GREATER, "expected %<>%>"); return list; } /* Parse an objc-try-catch-statement. objc-try-catch-statement: @try compound-statement objc-catch-list[opt] @try compound-statement objc-catch-list[opt] @finally compound-statement objc-catch-list: @catch ( parameter-declaration ) compound-statement objc-catch-list @catch ( parameter-declaration ) compound-statement */ static void c_parser_objc_try_catch_statement (c_parser *parser) { location_t loc; tree stmt; gcc_assert (c_parser_next_token_is_keyword (parser, RID_TRY)); c_parser_consume_token (parser); loc = c_parser_peek_token (parser)->location; stmt = c_parser_compound_statement (parser); objc_begin_try_stmt (loc, stmt); while (c_parser_next_token_is_keyword (parser, RID_CATCH)) { struct c_parm *parm; c_parser_consume_token (parser); if (!c_parser_require (parser, CPP_OPEN_PAREN, "expected %<(%>")) break; parm = c_parser_parameter_declaration (parser, NULL_TREE); if (parm == NULL) { c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, NULL); break; } c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, "expected %<)%>"); objc_begin_catch_clause (grokparm (parm)); if (c_parser_require (parser, CPP_OPEN_BRACE, "expected %<{%>")) c_parser_compound_statement_nostart (parser); objc_finish_catch_clause (); } if (c_parser_next_token_is_keyword (parser, RID_AT_FINALLY)) { location_t finloc; tree finstmt; c_parser_consume_token (parser); finloc = c_parser_peek_token (parser)->location; finstmt = c_parser_compound_statement (parser); objc_build_finally_clause (finloc, finstmt); } objc_finish_try_stmt (); } /* Parse an objc-synchronized-statement. objc-synchronized-statement: @synchronized ( expression ) compound-statement */ static void c_parser_objc_synchronized_statement (c_parser *parser) { location_t loc; tree expr, stmt; gcc_assert (c_parser_next_token_is_keyword (parser, RID_AT_SYNCHRONIZED)); c_parser_consume_token (parser); loc = c_parser_peek_token (parser)->location; if (c_parser_require (parser, CPP_OPEN_PAREN, "expected %<(%>")) { expr = c_parser_expression (parser).value; expr = c_fully_fold (expr, false, NULL); c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, "expected %<)%>"); } else expr = error_mark_node; stmt = c_parser_compound_statement (parser); objc_build_synchronized (loc, expr, stmt); } /* Parse an objc-selector; return NULL_TREE without an error if the next token is not an objc-selector. objc-selector: identifier one of enum struct union if else while do for switch case default break continue return goto asm sizeof typeof __alignof unsigned long const short volatile signed restrict _Complex in out inout bycopy byref oneway int char float double void _Bool ??? Why this selection of keywords but not, for example, storage class specifiers? */ static tree c_parser_objc_selector (c_parser *parser) { c_token *token = c_parser_peek_token (parser); tree value = token->value; if (token->type == CPP_NAME) { c_parser_consume_token (parser); return value; } if (token->type != CPP_KEYWORD) return NULL_TREE; switch (token->keyword) { case RID_ENUM: case RID_STRUCT: case RID_UNION: case RID_IF: case RID_ELSE: case RID_WHILE: case RID_DO: case RID_FOR: case RID_SWITCH: case RID_CASE: case RID_DEFAULT: case RID_BREAK: case RID_CONTINUE: case RID_RETURN: case RID_GOTO: case RID_ASM: case RID_SIZEOF: case RID_TYPEOF: case RID_ALIGNOF: case RID_UNSIGNED: case RID_LONG: case RID_CONST: case RID_SHORT: case RID_VOLATILE: case RID_SIGNED: case RID_RESTRICT: case RID_COMPLEX: case RID_IN: case RID_OUT: case RID_INOUT: case RID_BYCOPY: case RID_BYREF: case RID_ONEWAY: case RID_INT: case RID_CHAR: case RID_FLOAT: case RID_DOUBLE: case RID_VOID: case RID_BOOL: c_parser_consume_token (parser); return value; default: return NULL_TREE; } } /* Parse an objc-selector-arg. objc-selector-arg: objc-selector objc-keywordname-list objc-keywordname-list: objc-keywordname objc-keywordname-list objc-keywordname objc-keywordname: objc-selector : : */ static tree c_parser_objc_selector_arg (c_parser *parser) { tree sel = c_parser_objc_selector (parser); tree list = NULL_TREE; if (sel && c_parser_next_token_is_not (parser, CPP_COLON)) return sel; while (true) { if (!c_parser_require (parser, CPP_COLON, "expected %<:%>")) return list; list = chainon (list, build_tree_list (sel, NULL_TREE)); sel = c_parser_objc_selector (parser); if (!sel && c_parser_next_token_is_not (parser, CPP_COLON)) break; } return list; } /* Parse an objc-receiver. objc-receiver: expression class-name type-name */ static tree c_parser_objc_receiver (c_parser *parser) { if (c_parser_peek_token (parser)->type == CPP_NAME && (c_parser_peek_token (parser)->id_kind == C_ID_TYPENAME || c_parser_peek_token (parser)->id_kind == C_ID_CLASSNAME)) { tree id = c_parser_peek_token (parser)->value; c_parser_consume_token (parser); return objc_get_class_reference (id); } return c_fully_fold (c_parser_expression (parser).value, false, NULL); } /* Parse objc-message-args. objc-message-args: objc-selector objc-keywordarg-list objc-keywordarg-list: objc-keywordarg objc-keywordarg-list objc-keywordarg objc-keywordarg: objc-selector : objc-keywordexpr : objc-keywordexpr */ static tree c_parser_objc_message_args (c_parser *parser) { tree sel = c_parser_objc_selector (parser); tree list = NULL_TREE; if (sel && c_parser_next_token_is_not (parser, CPP_COLON)) return sel; while (true) { tree keywordexpr; if (!c_parser_require (parser, CPP_COLON, "expected %<:%>")) return error_mark_node; keywordexpr = c_parser_objc_keywordexpr (parser); list = chainon (list, build_tree_list (sel, keywordexpr)); sel = c_parser_objc_selector (parser); if (!sel && c_parser_next_token_is_not (parser, CPP_COLON)) break; } return list; } /* Parse an objc-keywordexpr. objc-keywordexpr: nonempty-expr-list */ static tree c_parser_objc_keywordexpr (c_parser *parser) { tree ret; VEC(tree,gc) *expr_list = c_parser_expr_list (parser, true, true, NULL); if (VEC_length (tree, expr_list) == 1) { /* Just return the expression, remove a level of indirection. */ ret = VEC_index (tree, expr_list, 0); } else { /* We have a comma expression, we will collapse later. */ ret = build_tree_list_vec (expr_list); } release_tree_vector (expr_list); return ret; } /* Handle pragmas. Some OpenMP pragmas are associated with, and therefore should be considered, statements. ALLOW_STMT is true if we're within the context of a function and such pragmas are to be allowed. Returns true if we actually parsed such a pragma. */ static bool c_parser_pragma (c_parser *parser, enum pragma_context context) { unsigned int id; id = c_parser_peek_token (parser)->pragma_kind; gcc_assert (id != PRAGMA_NONE); switch (id) { case PRAGMA_OMP_BARRIER: if (context != pragma_compound) { if (context == pragma_stmt) c_parser_error (parser, "%<#pragma omp barrier%> may only be " "used in compound statements"); goto bad_stmt; } c_parser_omp_barrier (parser); return false; case PRAGMA_OMP_FLUSH: if (context != pragma_compound) { if (context == pragma_stmt) c_parser_error (parser, "%<#pragma omp flush%> may only be " "used in compound statements"); goto bad_stmt; } c_parser_omp_flush (parser); return false; case PRAGMA_OMP_TASKWAIT: if (context != pragma_compound) { if (context == pragma_stmt) c_parser_error (parser, "%<#pragma omp taskwait%> may only be " "used in compound statements"); goto bad_stmt; } c_parser_omp_taskwait (parser); return false; case PRAGMA_OMP_THREADPRIVATE: c_parser_omp_threadprivate (parser); return false; case PRAGMA_OMP_SECTION: error_at (c_parser_peek_token (parser)->location, "%<#pragma omp section%> may only be used in " "%<#pragma omp sections%> construct"); c_parser_skip_until_found (parser, CPP_PRAGMA_EOL, NULL); return false; case PRAGMA_GCC_PCH_PREPROCESS: c_parser_error (parser, "%<#pragma GCC pch_preprocess%> must be first"); c_parser_skip_until_found (parser, CPP_PRAGMA_EOL, NULL); return false; default: if (id < PRAGMA_FIRST_EXTERNAL) { if (context == pragma_external) { bad_stmt: c_parser_error (parser, "expected declaration specifiers"); c_parser_skip_until_found (parser, CPP_PRAGMA_EOL, NULL); return false; } c_parser_omp_construct (parser); return true; } break; } c_parser_consume_pragma (parser); c_invoke_pragma_handler (id); /* Skip to EOL, but suppress any error message. Those will have been generated by the handler routine through calling error, as opposed to calling c_parser_error. */ parser->error = true; c_parser_skip_to_pragma_eol (parser); return false; } /* The interface the pragma parsers have to the lexer. */ enum cpp_ttype pragma_lex (tree *value) { c_token *tok = c_parser_peek_token (the_parser); enum cpp_ttype ret = tok->type; *value = tok->value; if (ret == CPP_PRAGMA_EOL || ret == CPP_EOF) ret = CPP_EOF; else { if (ret == CPP_KEYWORD) ret = CPP_NAME; c_parser_consume_token (the_parser); } return ret; } static void c_parser_pragma_pch_preprocess (c_parser *parser) { tree name = NULL; c_parser_consume_pragma (parser); if (c_parser_next_token_is (parser, CPP_STRING)) { name = c_parser_peek_token (parser)->value; c_parser_consume_token (parser); } else c_parser_error (parser, "expected string literal"); c_parser_skip_to_pragma_eol (parser); if (name) c_common_pch_pragma (parse_in, TREE_STRING_POINTER (name)); } /* OpenMP 2.5 parsing routines. */ /* Returns name of the next clause. If the clause is not recognized PRAGMA_OMP_CLAUSE_NONE is returned and the token is not consumed. Otherwise appropriate pragma_omp_clause is returned and the token is consumed. */ static pragma_omp_clause c_parser_omp_clause_name (c_parser *parser) { pragma_omp_clause result = PRAGMA_OMP_CLAUSE_NONE; if (c_parser_next_token_is_keyword (parser, RID_IF)) result = PRAGMA_OMP_CLAUSE_IF; else if (c_parser_next_token_is_keyword (parser, RID_DEFAULT)) result = PRAGMA_OMP_CLAUSE_DEFAULT; else if (c_parser_next_token_is (parser, CPP_NAME)) { const char *p = IDENTIFIER_POINTER (c_parser_peek_token (parser)->value); switch (p[0]) { case 'c': if (!strcmp ("collapse", p)) result = PRAGMA_OMP_CLAUSE_COLLAPSE; else if (!strcmp ("copyin", p)) result = PRAGMA_OMP_CLAUSE_COPYIN; else if (!strcmp ("copyprivate", p)) result = PRAGMA_OMP_CLAUSE_COPYPRIVATE; break; case 'f': if (!strcmp ("firstprivate", p)) result = PRAGMA_OMP_CLAUSE_FIRSTPRIVATE; break; case 'l': if (!strcmp ("lastprivate", p)) result = PRAGMA_OMP_CLAUSE_LASTPRIVATE; break; case 'n': if (!strcmp ("nowait", p)) result = PRAGMA_OMP_CLAUSE_NOWAIT; else if (!strcmp ("num_threads", p)) result = PRAGMA_OMP_CLAUSE_NUM_THREADS; break; case 'o': if (!strcmp ("ordered", p)) result = PRAGMA_OMP_CLAUSE_ORDERED; break; case 'p': if (!strcmp ("private", p)) result = PRAGMA_OMP_CLAUSE_PRIVATE; break; case 'r': if (!strcmp ("reduction", p)) result = PRAGMA_OMP_CLAUSE_REDUCTION; break; case 's': if (!strcmp ("schedule", p)) result = PRAGMA_OMP_CLAUSE_SCHEDULE; else if (!strcmp ("shared", p)) result = PRAGMA_OMP_CLAUSE_SHARED; break; case 'u': if (!strcmp ("untied", p)) result = PRAGMA_OMP_CLAUSE_UNTIED; break; } } if (result != PRAGMA_OMP_CLAUSE_NONE) c_parser_consume_token (parser); return result; } /* Validate that a clause of the given type does not already exist. */ static void check_no_duplicate_clause (tree clauses, enum omp_clause_code code, const char *name) { tree c; for (c = clauses; c ; c = OMP_CLAUSE_CHAIN (c)) if (OMP_CLAUSE_CODE (c) == code) { location_t loc = OMP_CLAUSE_LOCATION (c); error_at (loc, "too many %qs clauses", name); break; } } /* OpenMP 2.5: variable-list: identifier variable-list , identifier If KIND is nonzero, create the appropriate node and install the decl in OMP_CLAUSE_DECL and add the node to the head of the list. If KIND is nonzero, CLAUSE_LOC is the location of the clause. If KIND is zero, create a TREE_LIST with the decl in TREE_PURPOSE; return the list created. */ static tree c_parser_omp_variable_list (c_parser *parser, location_t clause_loc, enum omp_clause_code kind, tree list) { if (c_parser_next_token_is_not (parser, CPP_NAME) || c_parser_peek_token (parser)->id_kind != C_ID_ID) c_parser_error (parser, "expected identifier"); while (c_parser_next_token_is (parser, CPP_NAME) && c_parser_peek_token (parser)->id_kind == C_ID_ID) { tree t = lookup_name (c_parser_peek_token (parser)->value); if (t == NULL_TREE) undeclared_variable (c_parser_peek_token (parser)->location, c_parser_peek_token (parser)->value); else if (t == error_mark_node) ; else if (kind != 0) { tree u = build_omp_clause (clause_loc, kind); OMP_CLAUSE_DECL (u) = t; OMP_CLAUSE_CHAIN (u) = list; list = u; } else list = tree_cons (t, NULL_TREE, list); c_parser_consume_token (parser); if (c_parser_next_token_is_not (parser, CPP_COMMA)) break; c_parser_consume_token (parser); } return list; } /* Similarly, but expect leading and trailing parenthesis. This is a very common case for omp clauses. */ static tree c_parser_omp_var_list_parens (c_parser *parser, enum omp_clause_code kind, tree list) { /* The clauses location. */ location_t loc = c_parser_peek_token (parser)->location; if (c_parser_require (parser, CPP_OPEN_PAREN, "expected %<(%>")) { list = c_parser_omp_variable_list (parser, loc, kind, list); c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, "expected %<)%>"); } return list; } /* OpenMP 3.0: collapse ( constant-expression ) */ static tree c_parser_omp_clause_collapse (c_parser *parser, tree list) { tree c, num = error_mark_node; HOST_WIDE_INT n; location_t loc; check_no_duplicate_clause (list, OMP_CLAUSE_COLLAPSE, "collapse"); loc = c_parser_peek_token (parser)->location; if (c_parser_require (parser, CPP_OPEN_PAREN, "expected %<(%>")) { num = c_parser_expr_no_commas (parser, NULL).value; c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, "expected %<)%>"); } if (num == error_mark_node) return list; if (!INTEGRAL_TYPE_P (TREE_TYPE (num)) || !host_integerp (num, 0) || (n = tree_low_cst (num, 0)) <= 0 || (int) n != n) { error_at (loc, "collapse argument needs positive constant integer expression"); return list; } c = build_omp_clause (loc, OMP_CLAUSE_COLLAPSE); OMP_CLAUSE_COLLAPSE_EXPR (c) = num; OMP_CLAUSE_CHAIN (c) = list; return c; } /* OpenMP 2.5: copyin ( variable-list ) */ static tree c_parser_omp_clause_copyin (c_parser *parser, tree list) { return c_parser_omp_var_list_parens (parser, OMP_CLAUSE_COPYIN, list); } /* OpenMP 2.5: copyprivate ( variable-list ) */ static tree c_parser_omp_clause_copyprivate (c_parser *parser, tree list) { return c_parser_omp_var_list_parens (parser, OMP_CLAUSE_COPYPRIVATE, list); } /* OpenMP 2.5: default ( shared | none ) */ static tree c_parser_omp_clause_default (c_parser *parser, tree list) { enum omp_clause_default_kind kind = OMP_CLAUSE_DEFAULT_UNSPECIFIED; location_t loc = c_parser_peek_token (parser)->location; tree c; if (!c_parser_require (parser, CPP_OPEN_PAREN, "expected %<(%>")) return list; if (c_parser_next_token_is (parser, CPP_NAME)) { const char *p = IDENTIFIER_POINTER (c_parser_peek_token (parser)->value); switch (p[0]) { case 'n': if (strcmp ("none", p) != 0) goto invalid_kind; kind = OMP_CLAUSE_DEFAULT_NONE; break; case 's': if (strcmp ("shared", p) != 0) goto invalid_kind; kind = OMP_CLAUSE_DEFAULT_SHARED; break; default: goto invalid_kind; } c_parser_consume_token (parser); } else { invalid_kind: c_parser_error (parser, "expected %<none%> or %<shared%>"); } c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, "expected %<)%>"); if (kind == OMP_CLAUSE_DEFAULT_UNSPECIFIED) return list; check_no_duplicate_clause (list, OMP_CLAUSE_DEFAULT, "default"); c = build_omp_clause (loc, OMP_CLAUSE_DEFAULT); OMP_CLAUSE_CHAIN (c) = list; OMP_CLAUSE_DEFAULT_KIND (c) = kind; return c; } /* OpenMP 2.5: firstprivate ( variable-list ) */ static tree c_parser_omp_clause_firstprivate (c_parser *parser, tree list) { return c_parser_omp_var_list_parens (parser, OMP_CLAUSE_FIRSTPRIVATE, list); } /* OpenMP 2.5: if ( expression ) */ static tree c_parser_omp_clause_if (c_parser *parser, tree list) { location_t loc = c_parser_peek_token (parser)->location; if (c_parser_next_token_is (parser, CPP_OPEN_PAREN)) { tree t = c_parser_paren_condition (parser); tree c; check_no_duplicate_clause (list, OMP_CLAUSE_IF, "if"); c = build_omp_clause (loc, OMP_CLAUSE_IF); OMP_CLAUSE_IF_EXPR (c) = t; OMP_CLAUSE_CHAIN (c) = list; list = c; } else c_parser_error (parser, "expected %<(%>"); return list; } /* OpenMP 2.5: lastprivate ( variable-list ) */ static tree c_parser_omp_clause_lastprivate (c_parser *parser, tree list) { return c_parser_omp_var_list_parens (parser, OMP_CLAUSE_LASTPRIVATE, list); } /* OpenMP 2.5: nowait */ static tree c_parser_omp_clause_nowait (c_parser *parser ATTRIBUTE_UNUSED, tree list) { tree c; location_t loc = c_parser_peek_token (parser)->location; check_no_duplicate_clause (list, OMP_CLAUSE_NOWAIT, "nowait"); c = build_omp_clause (loc, OMP_CLAUSE_NOWAIT); OMP_CLAUSE_CHAIN (c) = list; return c; } /* OpenMP 2.5: num_threads ( expression ) */ static tree c_parser_omp_clause_num_threads (c_parser *parser, tree list) { location_t num_threads_loc = c_parser_peek_token (parser)->location; if (c_parser_require (parser, CPP_OPEN_PAREN, "expected %<(%>")) { location_t expr_loc = c_parser_peek_token (parser)->location; tree c, t = c_parser_expression (parser).value; t = c_fully_fold (t, false, NULL); c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, "expected %<)%>"); if (!INTEGRAL_TYPE_P (TREE_TYPE (t))) { c_parser_error (parser, "expected integer expression"); return list; } /* Attempt to statically determine when the number isn't positive. */ c = fold_build2_loc (expr_loc, LE_EXPR, boolean_type_node, t, build_int_cst (TREE_TYPE (t), 0)); if (CAN_HAVE_LOCATION_P (c)) SET_EXPR_LOCATION (c, expr_loc); if (c == boolean_true_node) { warning_at (expr_loc, 0, "%<num_threads%> value must be positive"); t = integer_one_node; } check_no_duplicate_clause (list, OMP_CLAUSE_NUM_THREADS, "num_threads"); c = build_omp_clause (num_threads_loc, OMP_CLAUSE_NUM_THREADS); OMP_CLAUSE_NUM_THREADS_EXPR (c) = t; OMP_CLAUSE_CHAIN (c) = list; list = c; } return list; } /* OpenMP 2.5: ordered */ static tree c_parser_omp_clause_ordered (c_parser *parser, tree list) { tree c; check_no_duplicate_clause (list, OMP_CLAUSE_ORDERED, "ordered"); c = build_omp_clause (c_parser_peek_token (parser)->location, OMP_CLAUSE_ORDERED); OMP_CLAUSE_CHAIN (c) = list; return c; } /* OpenMP 2.5: private ( variable-list ) */ static tree c_parser_omp_clause_private (c_parser *parser, tree list) { return c_parser_omp_var_list_parens (parser, OMP_CLAUSE_PRIVATE, list); } /* OpenMP 2.5: reduction ( reduction-operator : variable-list ) reduction-operator: One of: + * - & ^ | && || */ static tree c_parser_omp_clause_reduction (c_parser *parser, tree list) { location_t clause_loc = c_parser_peek_token (parser)->location; if (c_parser_require (parser, CPP_OPEN_PAREN, "expected %<(%>")) { enum tree_code code; switch (c_parser_peek_token (parser)->type) { case CPP_PLUS: code = PLUS_EXPR; break; case CPP_MULT: code = MULT_EXPR; break; case CPP_MINUS: code = MINUS_EXPR; break; case CPP_AND: code = BIT_AND_EXPR; break; case CPP_XOR: code = BIT_XOR_EXPR; break; case CPP_OR: code = BIT_IOR_EXPR; break; case CPP_AND_AND: code = TRUTH_ANDIF_EXPR; break; case CPP_OR_OR: code = TRUTH_ORIF_EXPR; break; default: c_parser_error (parser, "expected %<+%>, %<*%>, %<-%>, %<&%>, " "%<^%>, %<|%>, %<&&%>, or %<||%>"); c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, 0); return list; } c_parser_consume_token (parser); if (c_parser_require (parser, CPP_COLON, "expected %<:%>")) { tree nl, c; nl = c_parser_omp_variable_list (parser, clause_loc, OMP_CLAUSE_REDUCTION, list); for (c = nl; c != list; c = OMP_CLAUSE_CHAIN (c)) OMP_CLAUSE_REDUCTION_CODE (c) = code; list = nl; } c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, "expected %<)%>"); } return list; } /* OpenMP 2.5: schedule ( schedule-kind ) schedule ( schedule-kind , expression ) schedule-kind: static | dynamic | guided | runtime | auto */ static tree c_parser_omp_clause_schedule (c_parser *parser, tree list) { tree c, t; location_t loc = c_parser_peek_token (parser)->location; if (!c_parser_require (parser, CPP_OPEN_PAREN, "expected %<(%>")) return list; c = build_omp_clause (loc, OMP_CLAUSE_SCHEDULE); if (c_parser_next_token_is (parser, CPP_NAME)) { tree kind = c_parser_peek_token (parser)->value; const char *p = IDENTIFIER_POINTER (kind); switch (p[0]) { case 'd': if (strcmp ("dynamic", p) != 0) goto invalid_kind; OMP_CLAUSE_SCHEDULE_KIND (c) = OMP_CLAUSE_SCHEDULE_DYNAMIC; break; case 'g': if (strcmp ("guided", p) != 0) goto invalid_kind; OMP_CLAUSE_SCHEDULE_KIND (c) = OMP_CLAUSE_SCHEDULE_GUIDED; break; case 'r': if (strcmp ("runtime", p) != 0) goto invalid_kind; OMP_CLAUSE_SCHEDULE_KIND (c) = OMP_CLAUSE_SCHEDULE_RUNTIME; break; default: goto invalid_kind; } } else if (c_parser_next_token_is_keyword (parser, RID_STATIC)) OMP_CLAUSE_SCHEDULE_KIND (c) = OMP_CLAUSE_SCHEDULE_STATIC; else if (c_parser_next_token_is_keyword (parser, RID_AUTO)) OMP_CLAUSE_SCHEDULE_KIND (c) = OMP_CLAUSE_SCHEDULE_AUTO; else goto invalid_kind; c_parser_consume_token (parser); if (c_parser_next_token_is (parser, CPP_COMMA)) { location_t here; c_parser_consume_token (parser); here = c_parser_peek_token (parser)->location; t = c_parser_expr_no_commas (parser, NULL).value; t = c_fully_fold (t, false, NULL); if (OMP_CLAUSE_SCHEDULE_KIND (c) == OMP_CLAUSE_SCHEDULE_RUNTIME) error_at (here, "schedule %<runtime%> does not take " "a %<chunk_size%> parameter"); else if (OMP_CLAUSE_SCHEDULE_KIND (c) == OMP_CLAUSE_SCHEDULE_AUTO) error_at (here, "schedule %<auto%> does not take " "a %<chunk_size%> parameter"); else if (TREE_CODE (TREE_TYPE (t)) == INTEGER_TYPE) OMP_CLAUSE_SCHEDULE_CHUNK_EXPR (c) = t; else c_parser_error (parser, "expected integer expression"); c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, "expected %<)%>"); } else c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, "expected %<,%> or %<)%>"); check_no_duplicate_clause (list, OMP_CLAUSE_SCHEDULE, "schedule"); OMP_CLAUSE_CHAIN (c) = list; return c; invalid_kind: c_parser_error (parser, "invalid schedule kind"); c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, 0); return list; } /* OpenMP 2.5: shared ( variable-list ) */ static tree c_parser_omp_clause_shared (c_parser *parser, tree list) { return c_parser_omp_var_list_parens (parser, OMP_CLAUSE_SHARED, list); } /* OpenMP 3.0: untied */ static tree c_parser_omp_clause_untied (c_parser *parser ATTRIBUTE_UNUSED, tree list) { tree c; /* FIXME: Should we allow duplicates? */ check_no_duplicate_clause (list, OMP_CLAUSE_UNTIED, "untied"); c = build_omp_clause (c_parser_peek_token (parser)->location, OMP_CLAUSE_UNTIED); OMP_CLAUSE_CHAIN (c) = list; return c; } /* Parse all OpenMP clauses. The set clauses allowed by the directive is a bitmask in MASK. Return the list of clauses found; the result of clause default goes in *pdefault. */ static tree c_parser_omp_all_clauses (c_parser *parser, unsigned int mask, const char *where) { tree clauses = NULL; bool first = true; while (c_parser_next_token_is_not (parser, CPP_PRAGMA_EOL)) { location_t here; pragma_omp_clause c_kind; const char *c_name; tree prev = clauses; if (!first && c_parser_next_token_is (parser, CPP_COMMA)) c_parser_consume_token (parser); first = false; here = c_parser_peek_token (parser)->location; c_kind = c_parser_omp_clause_name (parser); switch (c_kind) { case PRAGMA_OMP_CLAUSE_COLLAPSE: clauses = c_parser_omp_clause_collapse (parser, clauses); c_name = "collapse"; break; case PRAGMA_OMP_CLAUSE_COPYIN: clauses = c_parser_omp_clause_copyin (parser, clauses); c_name = "copyin"; break; case PRAGMA_OMP_CLAUSE_COPYPRIVATE: clauses = c_parser_omp_clause_copyprivate (parser, clauses); c_name = "copyprivate"; break; case PRAGMA_OMP_CLAUSE_DEFAULT: clauses = c_parser_omp_clause_default (parser, clauses); c_name = "default"; break; case PRAGMA_OMP_CLAUSE_FIRSTPRIVATE: clauses = c_parser_omp_clause_firstprivate (parser, clauses); c_name = "firstprivate"; break; case PRAGMA_OMP_CLAUSE_IF: clauses = c_parser_omp_clause_if (parser, clauses); c_name = "if"; break; case PRAGMA_OMP_CLAUSE_LASTPRIVATE: clauses = c_parser_omp_clause_lastprivate (parser, clauses); c_name = "lastprivate"; break; case PRAGMA_OMP_CLAUSE_NOWAIT: clauses = c_parser_omp_clause_nowait (parser, clauses); c_name = "nowait"; break; case PRAGMA_OMP_CLAUSE_NUM_THREADS: clauses = c_parser_omp_clause_num_threads (parser, clauses); c_name = "num_threads"; break; case PRAGMA_OMP_CLAUSE_ORDERED: clauses = c_parser_omp_clause_ordered (parser, clauses); c_name = "ordered"; break; case PRAGMA_OMP_CLAUSE_PRIVATE: clauses = c_parser_omp_clause_private (parser, clauses); c_name = "private"; break; case PRAGMA_OMP_CLAUSE_REDUCTION: clauses = c_parser_omp_clause_reduction (parser, clauses); c_name = "reduction"; break; case PRAGMA_OMP_CLAUSE_SCHEDULE: clauses = c_parser_omp_clause_schedule (parser, clauses); c_name = "schedule"; break; case PRAGMA_OMP_CLAUSE_SHARED: clauses = c_parser_omp_clause_shared (parser, clauses); c_name = "shared"; break; case PRAGMA_OMP_CLAUSE_UNTIED: clauses = c_parser_omp_clause_untied (parser, clauses); c_name = "untied"; break; default: c_parser_error (parser, "expected %<#pragma omp%> clause"); goto saw_error; } if (((mask >> c_kind) & 1) == 0 && !parser->error) { /* Remove the invalid clause(s) from the list to avoid confusing the rest of the compiler. */ clauses = prev; error_at (here, "%qs is not valid for %qs", c_name, where); } } saw_error: c_parser_skip_to_pragma_eol (parser); return c_finish_omp_clauses (clauses); } /* OpenMP 2.5: structured-block: statement In practice, we're also interested in adding the statement to an outer node. So it is convenient if we work around the fact that c_parser_statement calls add_stmt. */ static tree c_parser_omp_structured_block (c_parser *parser) { tree stmt = push_stmt_list (); c_parser_statement (parser); return pop_stmt_list (stmt); } /* OpenMP 2.5: # pragma omp atomic new-line expression-stmt expression-stmt: x binop= expr | x++ | ++x | x-- | --x binop: +, *, -, /, &, ^, |, <<, >> where x is an lvalue expression with scalar type. LOC is the location of the #pragma token. */ static void c_parser_omp_atomic (location_t loc, c_parser *parser) { tree lhs, rhs; tree stmt; enum tree_code code; struct c_expr rhs_expr; c_parser_skip_to_pragma_eol (parser); lhs = c_parser_unary_expression (parser).value; lhs = c_fully_fold (lhs, false, NULL); switch (TREE_CODE (lhs)) { case ERROR_MARK: saw_error: c_parser_skip_to_end_of_block_or_statement (parser); return; case PREINCREMENT_EXPR: case POSTINCREMENT_EXPR: lhs = TREE_OPERAND (lhs, 0); code = PLUS_EXPR; rhs = integer_one_node; break; case PREDECREMENT_EXPR: case POSTDECREMENT_EXPR: lhs = TREE_OPERAND (lhs, 0); code = MINUS_EXPR; rhs = integer_one_node; break; default: switch (c_parser_peek_token (parser)->type) { case CPP_MULT_EQ: code = MULT_EXPR; break; case CPP_DIV_EQ: code = TRUNC_DIV_EXPR; break; case CPP_PLUS_EQ: code = PLUS_EXPR; break; case CPP_MINUS_EQ: code = MINUS_EXPR; break; case CPP_LSHIFT_EQ: code = LSHIFT_EXPR; break; case CPP_RSHIFT_EQ: code = RSHIFT_EXPR; break; case CPP_AND_EQ: code = BIT_AND_EXPR; break; case CPP_OR_EQ: code = BIT_IOR_EXPR; break; case CPP_XOR_EQ: code = BIT_XOR_EXPR; break; default: c_parser_error (parser, "invalid operator for %<#pragma omp atomic%>"); goto saw_error; } c_parser_consume_token (parser); { location_t rhs_loc = c_parser_peek_token (parser)->location; rhs_expr = c_parser_expression (parser); rhs_expr = default_function_array_conversion (rhs_loc, rhs_expr); } rhs = rhs_expr.value; rhs = c_fully_fold (rhs, false, NULL); break; } stmt = c_finish_omp_atomic (loc, code, lhs, rhs); if (stmt != error_mark_node) add_stmt (stmt); c_parser_skip_until_found (parser, CPP_SEMICOLON, "expected %<;%>"); } /* OpenMP 2.5: # pragma omp barrier new-line */ static void c_parser_omp_barrier (c_parser *parser) { location_t loc = c_parser_peek_token (parser)->location; c_parser_consume_pragma (parser); c_parser_skip_to_pragma_eol (parser); c_finish_omp_barrier (loc); } /* OpenMP 2.5: # pragma omp critical [(name)] new-line structured-block LOC is the location of the #pragma itself. */ static tree c_parser_omp_critical (location_t loc, c_parser *parser) { tree stmt, name = NULL; if (c_parser_next_token_is (parser, CPP_OPEN_PAREN)) { c_parser_consume_token (parser); if (c_parser_next_token_is (parser, CPP_NAME)) { name = c_parser_peek_token (parser)->value; c_parser_consume_token (parser); c_parser_require (parser, CPP_CLOSE_PAREN, "expected %<)%>"); } else c_parser_error (parser, "expected identifier"); } else if (c_parser_next_token_is_not (parser, CPP_PRAGMA_EOL)) c_parser_error (parser, "expected %<(%> or end of line"); c_parser_skip_to_pragma_eol (parser); stmt = c_parser_omp_structured_block (parser); return c_finish_omp_critical (loc, stmt, name); } /* OpenMP 2.5: # pragma omp flush flush-vars[opt] new-line flush-vars: ( variable-list ) */ static void c_parser_omp_flush (c_parser *parser) { location_t loc = c_parser_peek_token (parser)->location; c_parser_consume_pragma (parser); if (c_parser_next_token_is (parser, CPP_OPEN_PAREN)) c_parser_omp_var_list_parens (parser, OMP_CLAUSE_ERROR, NULL); else if (c_parser_next_token_is_not (parser, CPP_PRAGMA_EOL)) c_parser_error (parser, "expected %<(%> or end of line"); c_parser_skip_to_pragma_eol (parser); c_finish_omp_flush (loc); } /* Parse the restricted form of the for statement allowed by OpenMP. The real trick here is to determine the loop control variable early so that we can push a new decl if necessary to make it private. LOC is the location of the OMP in "#pragma omp". */ static tree c_parser_omp_for_loop (location_t loc, c_parser *parser, tree clauses, tree *par_clauses) { tree decl, cond, incr, save_break, save_cont, body, init, stmt, cl; tree declv, condv, incrv, initv, for_block = NULL, ret = NULL; bool fail = false, open_brace_parsed = false; int i, collapse = 1, nbraces = 0; location_t for_loc; for (cl = clauses; cl; cl = OMP_CLAUSE_CHAIN (cl)) if (OMP_CLAUSE_CODE (cl) == OMP_CLAUSE_COLLAPSE) collapse = tree_low_cst (OMP_CLAUSE_COLLAPSE_EXPR (cl), 0); gcc_assert (collapse >= 1); declv = make_tree_vec (collapse); initv = make_tree_vec (collapse); condv = make_tree_vec (collapse); incrv = make_tree_vec (collapse); if (!c_parser_next_token_is_keyword (parser, RID_FOR)) { c_parser_error (parser, "for statement expected"); return NULL; } for_loc = c_parser_peek_token (parser)->location; c_parser_consume_token (parser); for (i = 0; i < collapse; i++) { int bracecount = 0; if (!c_parser_require (parser, CPP_OPEN_PAREN, "expected %<(%>")) goto pop_scopes; /* Parse the initialization declaration or expression. */ if (c_parser_next_token_starts_declspecs (parser)) { if (i > 0) for_block = tree_cons (NULL, c_begin_compound_stmt (true), for_block); c_parser_declaration_or_fndef (parser, true, true, true, true); decl = check_for_loop_decls (for_loc); if (decl == NULL) goto error_init; if (DECL_INITIAL (decl) == error_mark_node) decl = error_mark_node; init = decl; } else if (c_parser_next_token_is (parser, CPP_NAME) && c_parser_peek_2nd_token (parser)->type == CPP_EQ) { struct c_expr decl_exp; struct c_expr init_exp; location_t init_loc; decl_exp = c_parser_postfix_expression (parser); decl = decl_exp.value; c_parser_require (parser, CPP_EQ, "expected %<=%>"); init_loc = c_parser_peek_token (parser)->location; init_exp = c_parser_expr_no_commas (parser, NULL); init_exp = default_function_array_conversion (init_loc, init_exp); init = build_modify_expr (init_loc, decl, decl_exp.original_type, NOP_EXPR, init_loc, init_exp.value, init_exp.original_type); init = c_process_expr_stmt (init_loc, init); c_parser_skip_until_found (parser, CPP_SEMICOLON, "expected %<;%>"); } else { error_init: c_parser_error (parser, "expected iteration declaration or initialization"); c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, "expected %<)%>"); fail = true; goto parse_next; } /* Parse the loop condition. */ cond = NULL_TREE; if (c_parser_next_token_is_not (parser, CPP_SEMICOLON)) { location_t cond_loc = c_parser_peek_token (parser)->location; struct c_expr cond_expr = c_parser_binary_expression (parser, NULL); cond = cond_expr.value; cond = c_objc_common_truthvalue_conversion (cond_loc, cond); cond = c_fully_fold (cond, false, NULL); switch (cond_expr.original_code) { case GT_EXPR: case GE_EXPR: case LT_EXPR: case LE_EXPR: break; default: /* Can't be cond = error_mark_node, because we want to preserve the location until c_finish_omp_for. */ cond = build1 (NOP_EXPR, boolean_type_node, error_mark_node); break; } protected_set_expr_location (cond, cond_loc); } c_parser_skip_until_found (parser, CPP_SEMICOLON, "expected %<;%>"); /* Parse the increment expression. */ incr = NULL_TREE; if (c_parser_next_token_is_not (parser, CPP_CLOSE_PAREN)) { location_t incr_loc = c_parser_peek_token (parser)->location; incr = c_process_expr_stmt (incr_loc, c_parser_expression (parser).value); } c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, "expected %<)%>"); if (decl == NULL || decl == error_mark_node || init == error_mark_node) fail = true; else { TREE_VEC_ELT (declv, i) = decl; TREE_VEC_ELT (initv, i) = init; TREE_VEC_ELT (condv, i) = cond; TREE_VEC_ELT (incrv, i) = incr; } parse_next: if (i == collapse - 1) break; /* FIXME: OpenMP 3.0 draft isn't very clear on what exactly is allowed in between the collapsed for loops to be still considered perfectly nested. Hopefully the final version clarifies this. For now handle (multiple) {'s and empty statements. */ do { if (c_parser_next_token_is_keyword (parser, RID_FOR)) { c_parser_consume_token (parser); break; } else if (c_parser_next_token_is (parser, CPP_OPEN_BRACE)) { c_parser_consume_token (parser); bracecount++; } else if (bracecount && c_parser_next_token_is (parser, CPP_SEMICOLON)) c_parser_consume_token (parser); else { c_parser_error (parser, "not enough perfectly nested loops"); if (bracecount) { open_brace_parsed = true; bracecount--; } fail = true; collapse = 0; break; } } while (1); nbraces += bracecount; } save_break = c_break_label; c_break_label = size_one_node; save_cont = c_cont_label; c_cont_label = NULL_TREE; body = push_stmt_list (); if (open_brace_parsed) { location_t here = c_parser_peek_token (parser)->location; stmt = c_begin_compound_stmt (true); c_parser_compound_statement_nostart (parser); add_stmt (c_end_compound_stmt (here, stmt, true)); } else add_stmt (c_parser_c99_block_statement (parser)); if (c_cont_label) { tree t = build1 (LABEL_EXPR, void_type_node, c_cont_label); SET_EXPR_LOCATION (t, loc); add_stmt (t); } body = pop_stmt_list (body); c_break_label = save_break; c_cont_label = save_cont; while (nbraces) { if (c_parser_next_token_is (parser, CPP_CLOSE_BRACE)) { c_parser_consume_token (parser); nbraces--; } else if (c_parser_next_token_is (parser, CPP_SEMICOLON)) c_parser_consume_token (parser); else { c_parser_error (parser, "collapsed loops not perfectly nested"); while (nbraces) { location_t here = c_parser_peek_token (parser)->location; stmt = c_begin_compound_stmt (true); add_stmt (body); c_parser_compound_statement_nostart (parser); body = c_end_compound_stmt (here, stmt, true); nbraces--; } goto pop_scopes; } } /* Only bother calling c_finish_omp_for if we haven't already generated an error from the initialization parsing. */ if (!fail) { stmt = c_finish_omp_for (loc, declv, initv, condv, incrv, body, NULL); if (stmt) { if (par_clauses != NULL) { tree *c; for (c = par_clauses; *c ; ) if (OMP_CLAUSE_CODE (*c) != OMP_CLAUSE_FIRSTPRIVATE && OMP_CLAUSE_CODE (*c) != OMP_CLAUSE_LASTPRIVATE) c = &OMP_CLAUSE_CHAIN (*c); else { for (i = 0; i < collapse; i++) if (TREE_VEC_ELT (declv, i) == OMP_CLAUSE_DECL (*c)) break; if (i == collapse) c = &OMP_CLAUSE_CHAIN (*c); else if (OMP_CLAUSE_CODE (*c) == OMP_CLAUSE_FIRSTPRIVATE) { error_at (loc, "iteration variable %qD should not be firstprivate", OMP_CLAUSE_DECL (*c)); *c = OMP_CLAUSE_CHAIN (*c); } else { /* Copy lastprivate (decl) clause to OMP_FOR_CLAUSES, change it to shared (decl) in OMP_PARALLEL_CLAUSES. */ tree l = build_omp_clause (OMP_CLAUSE_LOCATION (*c), OMP_CLAUSE_LASTPRIVATE); OMP_CLAUSE_DECL (l) = OMP_CLAUSE_DECL (*c); OMP_CLAUSE_CHAIN (l) = clauses; clauses = l; OMP_CLAUSE_SET_CODE (*c, OMP_CLAUSE_SHARED); } } } OMP_FOR_CLAUSES (stmt) = clauses; } ret = stmt; } pop_scopes: while (for_block) { /* FIXME diagnostics: LOC below should be the actual location of this particular for block. We need to build a list of locations to go along with FOR_BLOCK. */ stmt = c_end_compound_stmt (loc, TREE_VALUE (for_block), true); add_stmt (stmt); for_block = TREE_CHAIN (for_block); } return ret; } /* OpenMP 2.5: #pragma omp for for-clause[optseq] new-line for-loop LOC is the location of the #pragma token. */ #define OMP_FOR_CLAUSE_MASK \ ( (1u << PRAGMA_OMP_CLAUSE_PRIVATE) \ | (1u << PRAGMA_OMP_CLAUSE_FIRSTPRIVATE) \ | (1u << PRAGMA_OMP_CLAUSE_LASTPRIVATE) \ | (1u << PRAGMA_OMP_CLAUSE_REDUCTION) \ | (1u << PRAGMA_OMP_CLAUSE_ORDERED) \ | (1u << PRAGMA_OMP_CLAUSE_SCHEDULE) \ | (1u << PRAGMA_OMP_CLAUSE_COLLAPSE) \ | (1u << PRAGMA_OMP_CLAUSE_NOWAIT)) static tree c_parser_omp_for (location_t loc, c_parser *parser) { tree block, clauses, ret; clauses = c_parser_omp_all_clauses (parser, OMP_FOR_CLAUSE_MASK, "#pragma omp for"); block = c_begin_compound_stmt (true); ret = c_parser_omp_for_loop (loc, parser, clauses, NULL); block = c_end_compound_stmt (loc, block, true); add_stmt (block); return ret; } /* OpenMP 2.5: # pragma omp master new-line structured-block LOC is the location of the #pragma token. */ static tree c_parser_omp_master (location_t loc, c_parser *parser) { c_parser_skip_to_pragma_eol (parser); return c_finish_omp_master (loc, c_parser_omp_structured_block (parser)); } /* OpenMP 2.5: # pragma omp ordered new-line structured-block LOC is the location of the #pragma itself. */ static tree c_parser_omp_ordered (location_t loc, c_parser *parser) { c_parser_skip_to_pragma_eol (parser); return c_finish_omp_ordered (loc, c_parser_omp_structured_block (parser)); } /* OpenMP 2.5: section-scope: { section-sequence } section-sequence: section-directive[opt] structured-block section-sequence section-directive structured-block SECTIONS_LOC is the location of the #pragma omp sections. */ static tree c_parser_omp_sections_scope (location_t sections_loc, c_parser *parser) { tree stmt, substmt; bool error_suppress = false; location_t loc; loc = c_parser_peek_token (parser)->location; if (!c_parser_require (parser, CPP_OPEN_BRACE, "expected %<{%>")) { /* Avoid skipping until the end of the block. */ parser->error = false; return NULL_TREE; } stmt = push_stmt_list (); if (c_parser_peek_token (parser)->pragma_kind != PRAGMA_OMP_SECTION) { substmt = push_stmt_list (); while (1) { c_parser_statement (parser); if (c_parser_peek_token (parser)->pragma_kind == PRAGMA_OMP_SECTION) break; if (c_parser_next_token_is (parser, CPP_CLOSE_BRACE)) break; if (c_parser_next_token_is (parser, CPP_EOF)) break; } substmt = pop_stmt_list (substmt); substmt = build1 (OMP_SECTION, void_type_node, substmt); SET_EXPR_LOCATION (substmt, loc); add_stmt (substmt); } while (1) { if (c_parser_next_token_is (parser, CPP_CLOSE_BRACE)) break; if (c_parser_next_token_is (parser, CPP_EOF)) break; loc = c_parser_peek_token (parser)->location; if (c_parser_peek_token (parser)->pragma_kind == PRAGMA_OMP_SECTION) { c_parser_consume_pragma (parser); c_parser_skip_to_pragma_eol (parser); error_suppress = false; } else if (!error_suppress) { error_at (loc, "expected %<#pragma omp section%> or %<}%>"); error_suppress = true; } substmt = c_parser_omp_structured_block (parser); substmt = build1 (OMP_SECTION, void_type_node, substmt); SET_EXPR_LOCATION (substmt, loc); add_stmt (substmt); } c_parser_skip_until_found (parser, CPP_CLOSE_BRACE, "expected %<#pragma omp section%> or %<}%>"); substmt = pop_stmt_list (stmt); stmt = make_node (OMP_SECTIONS); SET_EXPR_LOCATION (stmt, sections_loc); TREE_TYPE (stmt) = void_type_node; OMP_SECTIONS_BODY (stmt) = substmt; return add_stmt (stmt); } /* OpenMP 2.5: # pragma omp sections sections-clause[optseq] newline sections-scope LOC is the location of the #pragma token. */ #define OMP_SECTIONS_CLAUSE_MASK \ ( (1u << PRAGMA_OMP_CLAUSE_PRIVATE) \ | (1u << PRAGMA_OMP_CLAUSE_FIRSTPRIVATE) \ | (1u << PRAGMA_OMP_CLAUSE_LASTPRIVATE) \ | (1u << PRAGMA_OMP_CLAUSE_REDUCTION) \ | (1u << PRAGMA_OMP_CLAUSE_NOWAIT)) static tree c_parser_omp_sections (location_t loc, c_parser *parser) { tree block, clauses, ret; clauses = c_parser_omp_all_clauses (parser, OMP_SECTIONS_CLAUSE_MASK, "#pragma omp sections"); block = c_begin_compound_stmt (true); ret = c_parser_omp_sections_scope (loc, parser); if (ret) OMP_SECTIONS_CLAUSES (ret) = clauses; block = c_end_compound_stmt (loc, block, true); add_stmt (block); return ret; } /* OpenMP 2.5: # pragma parallel parallel-clause new-line # pragma parallel for parallel-for-clause new-line # pragma parallel sections parallel-sections-clause new-line LOC is the location of the #pragma token. */ #define OMP_PARALLEL_CLAUSE_MASK \ ( (1u << PRAGMA_OMP_CLAUSE_IF) \ | (1u << PRAGMA_OMP_CLAUSE_PRIVATE) \ | (1u << PRAGMA_OMP_CLAUSE_FIRSTPRIVATE) \ | (1u << PRAGMA_OMP_CLAUSE_DEFAULT) \ | (1u << PRAGMA_OMP_CLAUSE_SHARED) \ | (1u << PRAGMA_OMP_CLAUSE_COPYIN) \ | (1u << PRAGMA_OMP_CLAUSE_REDUCTION) \ | (1u << PRAGMA_OMP_CLAUSE_NUM_THREADS)) static tree c_parser_omp_parallel (location_t loc, c_parser *parser) { enum pragma_kind p_kind = PRAGMA_OMP_PARALLEL; const char *p_name = "#pragma omp parallel"; tree stmt, clauses, par_clause, ws_clause, block; unsigned int mask = OMP_PARALLEL_CLAUSE_MASK; if (c_parser_next_token_is_keyword (parser, RID_FOR)) { c_parser_consume_token (parser); p_kind = PRAGMA_OMP_PARALLEL_FOR; p_name = "#pragma omp parallel for"; mask |= OMP_FOR_CLAUSE_MASK; mask &= ~(1u << PRAGMA_OMP_CLAUSE_NOWAIT); } else if (c_parser_next_token_is (parser, CPP_NAME)) { const char *p = IDENTIFIER_POINTER (c_parser_peek_token (parser)->value); if (strcmp (p, "sections") == 0) { c_parser_consume_token (parser); p_kind = PRAGMA_OMP_PARALLEL_SECTIONS; p_name = "#pragma omp parallel sections"; mask |= OMP_SECTIONS_CLAUSE_MASK; mask &= ~(1u << PRAGMA_OMP_CLAUSE_NOWAIT); } } clauses = c_parser_omp_all_clauses (parser, mask, p_name); switch (p_kind) { case PRAGMA_OMP_PARALLEL: block = c_begin_omp_parallel (); c_parser_statement (parser); stmt = c_finish_omp_parallel (loc, clauses, block); break; case PRAGMA_OMP_PARALLEL_FOR: block = c_begin_omp_parallel (); c_split_parallel_clauses (loc, clauses, &par_clause, &ws_clause); c_parser_omp_for_loop (loc, parser, ws_clause, &par_clause); stmt = c_finish_omp_parallel (loc, par_clause, block); OMP_PARALLEL_COMBINED (stmt) = 1; break; case PRAGMA_OMP_PARALLEL_SECTIONS: block = c_begin_omp_parallel (); c_split_parallel_clauses (loc, clauses, &par_clause, &ws_clause); stmt = c_parser_omp_sections_scope (loc, parser); if (stmt) OMP_SECTIONS_CLAUSES (stmt) = ws_clause; stmt = c_finish_omp_parallel (loc, par_clause, block); OMP_PARALLEL_COMBINED (stmt) = 1; break; default: gcc_unreachable (); } return stmt; } /* OpenMP 2.5: # pragma omp single single-clause[optseq] new-line structured-block LOC is the location of the #pragma. */ #define OMP_SINGLE_CLAUSE_MASK \ ( (1u << PRAGMA_OMP_CLAUSE_PRIVATE) \ | (1u << PRAGMA_OMP_CLAUSE_FIRSTPRIVATE) \ | (1u << PRAGMA_OMP_CLAUSE_COPYPRIVATE) \ | (1u << PRAGMA_OMP_CLAUSE_NOWAIT)) static tree c_parser_omp_single (location_t loc, c_parser *parser) { tree stmt = make_node (OMP_SINGLE); SET_EXPR_LOCATION (stmt, loc); TREE_TYPE (stmt) = void_type_node; OMP_SINGLE_CLAUSES (stmt) = c_parser_omp_all_clauses (parser, OMP_SINGLE_CLAUSE_MASK, "#pragma omp single"); OMP_SINGLE_BODY (stmt) = c_parser_omp_structured_block (parser); return add_stmt (stmt); } /* OpenMP 3.0: # pragma omp task task-clause[optseq] new-line LOC is the location of the #pragma. */ #define OMP_TASK_CLAUSE_MASK \ ( (1u << PRAGMA_OMP_CLAUSE_IF) \ | (1u << PRAGMA_OMP_CLAUSE_UNTIED) \ | (1u << PRAGMA_OMP_CLAUSE_DEFAULT) \ | (1u << PRAGMA_OMP_CLAUSE_PRIVATE) \ | (1u << PRAGMA_OMP_CLAUSE_FIRSTPRIVATE) \ | (1u << PRAGMA_OMP_CLAUSE_SHARED)) static tree c_parser_omp_task (location_t loc, c_parser *parser) { tree clauses, block; clauses = c_parser_omp_all_clauses (parser, OMP_TASK_CLAUSE_MASK, "#pragma omp task"); block = c_begin_omp_task (); c_parser_statement (parser); return c_finish_omp_task (loc, clauses, block); } /* OpenMP 3.0: # pragma omp taskwait new-line */ static void c_parser_omp_taskwait (c_parser *parser) { location_t loc = c_parser_peek_token (parser)->location; c_parser_consume_pragma (parser); c_parser_skip_to_pragma_eol (parser); c_finish_omp_taskwait (loc); } /* Main entry point to parsing most OpenMP pragmas. */ static void c_parser_omp_construct (c_parser *parser) { enum pragma_kind p_kind; location_t loc; tree stmt; loc = c_parser_peek_token (parser)->location; p_kind = c_parser_peek_token (parser)->pragma_kind; c_parser_consume_pragma (parser); switch (p_kind) { case PRAGMA_OMP_ATOMIC: c_parser_omp_atomic (loc, parser); return; case PRAGMA_OMP_CRITICAL: stmt = c_parser_omp_critical (loc, parser); break; case PRAGMA_OMP_FOR: stmt = c_parser_omp_for (loc, parser); break; case PRAGMA_OMP_MASTER: stmt = c_parser_omp_master (loc, parser); break; case PRAGMA_OMP_ORDERED: stmt = c_parser_omp_ordered (loc, parser); break; case PRAGMA_OMP_PARALLEL: stmt = c_parser_omp_parallel (loc, parser); break; case PRAGMA_OMP_SECTIONS: stmt = c_parser_omp_sections (loc, parser); break; case PRAGMA_OMP_SINGLE: stmt = c_parser_omp_single (loc, parser); break; case PRAGMA_OMP_TASK: stmt = c_parser_omp_task (loc, parser); break; default: gcc_unreachable (); } if (stmt) gcc_assert (EXPR_LOCATION (stmt) != UNKNOWN_LOCATION); } /* OpenMP 2.5: # pragma omp threadprivate (variable-list) */ static void c_parser_omp_threadprivate (c_parser *parser) { tree vars, t; location_t loc; c_parser_consume_pragma (parser); loc = c_parser_peek_token (parser)->location; vars = c_parser_omp_var_list_parens (parser, OMP_CLAUSE_ERROR, NULL); /* Mark every variable in VARS to be assigned thread local storage. */ for (t = vars; t; t = TREE_CHAIN (t)) { tree v = TREE_PURPOSE (t); /* FIXME diagnostics: Ideally we should keep individual locations for all the variables in the var list to make the following errors more precise. Perhaps c_parser_omp_var_list_parens() should construct a list of locations to go along with the var list. */ /* If V had already been marked threadprivate, it doesn't matter whether it had been used prior to this point. */ if (TREE_CODE (v) != VAR_DECL) error_at (loc, "%qD is not a variable", v); else if (TREE_USED (v) && !C_DECL_THREADPRIVATE_P (v)) error_at (loc, "%qE declared %<threadprivate%> after first use", v); else if (! TREE_STATIC (v) && ! DECL_EXTERNAL (v)) error_at (loc, "automatic variable %qE cannot be %<threadprivate%>", v); else if (TREE_TYPE (v) == error_mark_node) ; else if (! COMPLETE_TYPE_P (TREE_TYPE (v))) error_at (loc, "%<threadprivate%> %qE has incomplete type", v); else { if (! DECL_THREAD_LOCAL_P (v)) { DECL_TLS_MODEL (v) = decl_default_tls_model (v); /* If rtl has been already set for this var, call make_decl_rtl once again, so that encode_section_info has a chance to look at the new decl flags. */ if (DECL_RTL_SET_P (v)) make_decl_rtl (v); } C_DECL_THREADPRIVATE_P (v) = 1; } } c_parser_skip_to_pragma_eol (parser); } /* Parse a single source file. */ void c_parse_file (void) { /* Use local storage to begin. If the first token is a pragma, parse it. If it is #pragma GCC pch_preprocess, then this will load a PCH file which will cause garbage collection. */ c_parser tparser; memset (&tparser, 0, sizeof tparser); the_parser = &tparser; if (c_parser_peek_token (&tparser)->pragma_kind == PRAGMA_GCC_PCH_PREPROCESS) c_parser_pragma_pch_preprocess (&tparser); the_parser = GGC_NEW (c_parser); *the_parser = tparser; /* Initialize EH, if we've been told to do so. */ if (flag_exceptions) using_eh_for_cleanups (); c_parser_translation_unit (the_parser); the_parser = NULL; } #include "gt-c-parser.h"
fc_kernel_fp16_arm82.c
/* * Licensed to the Apache Software Foundation (ASF) under one * or more contributor license agreements. See the NOTICE file * distributed with this work for additional information * regarding copyright ownership. The ASF licenses this file * to you under the Apache License, Version 2.0 (the * License); you may not use this file except in compliance * with the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, * software distributed under the License is distributed on an * AS IS BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY * KIND, either express or implied. See the License for the * specific language governing permissions and limitations * under the License. */ /* * Copyright (c) 2021, OPEN AI LAB * Author: xlchen@openailab.com */ #include "fc_kernel_fp16_arm82.h" #include <stdint.h> #include <stdlib.h> #include <math.h> #include <arm_neon.h> void hgemv_1x8_a55(__fp16* biases, __fp16* input, __fp16* kernel, long kernel_size, __fp16* output); void hgemv_1x2_a55(__fp16* biases, __fp16* input, __fp16* kernel, long kernel_size, __fp16* output); // start and end channel must be 8 aligned void hgemv1x8(const __fp16* input, const __fp16* output, __fp16* weight_interleaved, const __fp16* biases, int kernel_size, int start_channel, int end_channel, int num_thread, int cpu_affinity) { int ch = 0; __fp16 *cur_kernel, *cur_biases, *cur_result; // #pragma omp parallel for num_threads(num_thread) for (ch = start_channel; ch < end_channel; ch += 8) { cur_kernel = (__fp16*)(weight_interleaved + kernel_size * ch); cur_result = (__fp16*)(output + ch); cur_biases = biases ? (__fp16*)(biases + ch) : NULL; hgemv_1x8_a55(cur_biases, (__fp16*)input, cur_kernel, kernel_size, cur_result); // todo implement with A76 } } // start channel must be 2 aligned void hgemv1x2(const __fp16* input, const __fp16* output, __fp16* weight_interleaved, const __fp16* biases, int kernel_size, int start_channel, int end_channel, int num_thread, int cpu_affinity) { __fp16 sum; int ch = 0; __fp16 *cur_kernel, *cur_biases, *cur_result; for (ch = start_channel; ch < (end_channel & -2); ch += 2) { cur_kernel = (__fp16*)(weight_interleaved + kernel_size * ch); cur_result = (__fp16*)(output + ch); cur_biases = biases ? (__fp16*)(biases + ch) : NULL; hgemv_1x2_a55(cur_biases, (__fp16*)input, cur_kernel, kernel_size, cur_result); } if (end_channel & 0x1) { cur_kernel = (__fp16*)(weight_interleaved + kernel_size * ch); cur_result = (__fp16*)(output + ch); sum = biases ? *(biases + ch) : 0.f; for (int j = 0; j < kernel_size; j++) sum = sum + input[j] * cur_kernel[j]; *cur_result = sum; } } static void interleave_kernel(const __fp16* kernel, __fp16* kernel_interleaved, int out_chan, int kernel_size) { int i, j, k; __fp16* cur_kernel[8]; __fp16* cur_kernel_interleaved; // interleave 8 kernel for (i = 0; i < (out_chan & -8); i += 8) { for (j = 0; j < 8; j++) cur_kernel[j] = (__fp16*)kernel + kernel_size * (i + j); cur_kernel_interleaved = (__fp16*)kernel_interleaved + kernel_size * i; for (k = 0; k < kernel_size; k++) for (j = 0; j < 8; j++) cur_kernel_interleaved[8 * k + j] = *(cur_kernel[j] + k); } // interleave 2 kernel for (; i < (out_chan & -2); i += 2) { for (j = 0; j < 2; j++) cur_kernel[j] = (__fp16*)kernel + kernel_size * (i + j); cur_kernel_interleaved = (__fp16*)kernel_interleaved + kernel_size * i; for (k = 0; k < kernel_size; k++) for (j = 0; j < 2; j++) cur_kernel_interleaved[2 * k + j] = *(cur_kernel[j] + k); } // copy last kernel if (out_chan & 0x1) { cur_kernel[0] = (__fp16*)kernel + kernel_size * i; cur_kernel_interleaved = (__fp16*)kernel_interleaved + kernel_size * i; for (k = 0; k < kernel_size; k++) cur_kernel_interleaved[k] = *(cur_kernel[0] + k); } return; } int fp16_fc_kernel_prerun(struct tensor* input_tensor, struct tensor* filter_tensor, struct tensor* output_tensor, struct fc_priv_info* priv_info, struct fc_param* param) { int num_output = param->num_output; int kernel_size = filter_tensor->dims[1]; int kernel_align = ((kernel_size + 1) & -2); if (!priv_info->interleave_buffer) { int mem_size = sizeof(__fp16) * num_output * kernel_align; void* mem = sys_malloc(mem_size); priv_info->interleave_buffer = mem; priv_info->interleave_buffer_size = mem_size; } if (!priv_info->input_buffer) { int mem_size = sizeof(__fp16) * kernel_align; void* mem = sys_malloc(mem_size); priv_info->input_buffer = mem; priv_info->input_buffer_size = mem_size; } __fp16* filter_data = (__fp16*)filter_tensor->data; interleave_kernel(filter_data, (__fp16*)priv_info->interleave_buffer, num_output, kernel_size); return 0; } int fp16_fc_kernel_run(struct tensor* input_tensor, struct tensor* filter_tensor, struct tensor* bias_tensor, struct tensor* output_tensor, struct fc_priv_info* priv_info, struct fc_param* param, int num_thread, int cpu_affinity) { int out_num = param->num_output; int kernel_size = filter_tensor->dims[1]; __fp16* input = (__fp16*)input_tensor->data; __fp16* output = (__fp16*)output_tensor->data; __fp16* weight = (__fp16*)priv_info->interleave_buffer; __fp16* biases = NULL; if (bias_tensor) biases = (__fp16*)bias_tensor->data; int out_num_8 = out_num & ~7; for (int i = 0; i < input_tensor->dims[0]; i++) { __fp16* cur_input = input + i * kernel_size; __fp16* cur_output = output + i * out_num; hgemv1x8(cur_input, cur_output, weight, biases, kernel_size, 0, out_num_8, num_thread, cpu_affinity); if (out_num & 0x7) hgemv1x2(cur_input, cur_output, weight, biases, kernel_size, out_num_8, out_num, num_thread, cpu_affinity); } return 0; }
hypre_merge_sort.c
/****************************************************************************** * Copyright 1998-2019 Lawrence Livermore National Security, LLC and other * HYPRE Project Developers. See the top-level COPYRIGHT file for details. * * SPDX-License-Identifier: (Apache-2.0 OR MIT) ******************************************************************************/ #include "_hypre_utilities.h" #include "hypre_hopscotch_hash.h" #include "../seq_mv/HYPRE_seq_mv.h" //#define DBG_MERGE_SORT #ifdef DBG_MERGE_SORT #include <algorithm> #include <unordered_map> #endif #define SWAP(T, a, b) do { T tmp = a; a = b; b = tmp; } while (0) /* union of two sorted (in ascending order) array arr1 and arr2 into arr3 * Assumption: no duplicates in arr1 and arr2 * arr3 should have enough space on entry * map1 and map2 map arr1 and arr2 to arr3 */ void hypre_union2(HYPRE_Int n1, HYPRE_BigInt *arr1, HYPRE_Int n2, HYPRE_BigInt *arr2, HYPRE_Int *n3, HYPRE_BigInt *arr3, HYPRE_Int *map1, HYPRE_Int *map2) { HYPRE_Int i = 0, j = 0, k = 0; while (i < n1 && j < n2) { if (arr1[i] < arr2[j]) { if (map1) { map1[i] = k; } arr3[k++] = arr1[i++]; } else if (arr1[i] > arr2[j]) { if (map2) { map2[j] = k; } arr3[k++] = arr2[j++]; } else /* == */ { if (map1) { map1[i] = k; } if (map2) { map2[j] = k; } arr3[k++] = arr1[i++]; j++; } } while (i < n1) { if (map1) { map1[i] = k; } arr3[k++] = arr1[i++]; } while (j < n2) { if (map2) { map2[j] = k; } arr3[k++] = arr2[j++]; } *n3 = k; } static void hypre_merge(HYPRE_Int *first1, HYPRE_Int *last1, HYPRE_Int *first2, HYPRE_Int *last2, HYPRE_Int *out) { for ( ; first1 != last1; ++out) { if (first2 == last2) { for ( ; first1 != last1; ++first1, ++out) { *out = *first1; } return; } if (*first2 < *first1) { *out = *first2; ++first2; } else { *out = *first1; ++first1; } } for ( ; first2 != last2; ++first2, ++out) { *out = *first2; } } #ifdef HYPRE_CONCURRENT_HOPSCOTCH static void hypre_big_merge(HYPRE_BigInt *first1, HYPRE_BigInt *last1, HYPRE_BigInt *first2, HYPRE_BigInt *last2, HYPRE_BigInt *out) { for ( ; first1 != last1; ++out) { if (first2 == last2) { for ( ; first1 != last1; ++first1, ++out) { *out = *first1; } return; } if (*first2 < *first1) { *out = *first2; ++first2; } else { *out = *first1; ++first1; } } for ( ; first2 != last2; ++first2, ++out) { *out = *first2; } } #endif static void kth_element_( HYPRE_Int *out1, HYPRE_Int *out2, HYPRE_Int *a1, HYPRE_Int *a2, HYPRE_Int left, HYPRE_Int right, HYPRE_Int n1, HYPRE_Int n2, HYPRE_Int k) { while (1) { HYPRE_Int i = (left + right)/2; // right < k -> i < k HYPRE_Int j = k - i - 1; #ifdef DBG_MERGE_SORT hypre_assert(left <= right && right <= k); hypre_assert(i < k); // i == k implies left == right == k that can never happen hypre_assert(j >= 0 && j < n2); #endif if ((j == -1 || a1[i] >= a2[j]) && (j == n2 - 1 || a1[i] <= a2[j + 1])) { *out1 = i; *out2 = j + 1; return; } else if (j >= 0 && a2[j] >= a1[i] && (i == n1 - 1 || a2[j] <= a1[i + 1])) { *out1 = i + 1; *out2 = j; return; } else if (a1[i] > a2[j] && j != n2 - 1 && a1[i] > a2[j+1]) { // search in left half of a1 right = i - 1; } else { // search in right half of a1 left = i + 1; } } } /** * Partition the input so that * a1[0:*out1) and a2[0:*out2) contain the smallest k elements */ static void kth_element( HYPRE_Int *out1, HYPRE_Int *out2, HYPRE_Int *a1, HYPRE_Int *a2, HYPRE_Int n1, HYPRE_Int n2, HYPRE_Int k) { // either of the inputs is empty if (n1 == 0) { *out1 = 0; *out2 = k; return; } if (n2 == 0) { *out1 = k; *out2 = 0; return; } if (k >= n1 + n2) { *out1 = n1; *out2 = n2; return; } // one is greater than the other if (k < n1 && a1[k] <= a2[0]) { *out1 = k; *out2 = 0; return; } if (k - n1 >= 0 && a2[k - n1] >= a1[n1 - 1]) { *out1 = n1; *out2 = k - n1; return; } if (k < n2 && a2[k] <= a1[0]) { *out1 = 0; *out2 = k; return; } if (k - n2 >= 0 && a1[k - n2] >= a2[n2 - 1]) { *out1 = k - n2; *out2 = n2; return; } // now k > 0 // faster to do binary search on the shorter sequence if (n1 > n2) { SWAP(HYPRE_Int, n1, n2); SWAP(HYPRE_Int *, a1, a2); SWAP(HYPRE_Int *, out1, out2); } if (k < (n1 + n2)/2) { kth_element_(out1, out2, a1, a2, 0, hypre_min(n1 - 1, k), n1, n2, k); } else { // when k is big, faster to find (n1 + n2 - k)th biggest element HYPRE_Int offset1 = hypre_max(k - n2, 0), offset2 = hypre_max(k - n1, 0); HYPRE_Int new_k = k - offset1 - offset2; HYPRE_Int new_n1 = hypre_min(n1 - offset1, new_k + 1); HYPRE_Int new_n2 = hypre_min(n2 - offset2, new_k + 1); kth_element_(out1, out2, a1 + offset1, a2 + offset2, 0, new_n1 - 1, new_n1, new_n2, new_k); *out1 += offset1; *out2 += offset2; } #ifdef DBG_MERGE_SORT hypre_assert(*out1 + *out2 == k); #endif } #ifdef HYPRE_CONCURRENT_HOPSCOTCH static void big_kth_element_( HYPRE_Int *out1, HYPRE_Int *out2, HYPRE_BigInt *a1, HYPRE_BigInt *a2, HYPRE_Int left, HYPRE_Int right, HYPRE_Int n1, HYPRE_Int n2, HYPRE_Int k) { while (1) { HYPRE_Int i = (left + right)/2; // right < k -> i < k HYPRE_Int j = k - i - 1; #ifdef DBG_MERGE_SORT hypre_assert(left <= right && right <= k); hypre_assert(i < k); // i == k implies left == right == k that can never happen hypre_assert(j >= 0 && j < n2); #endif if ((j == -1 || a1[i] >= a2[j]) && (j == n2 - 1 || a1[i] <= a2[j + 1])) { *out1 = i; *out2 = j + 1; return; } else if (j >= 0 && a2[j] >= a1[i] && (i == n1 - 1 || a2[j] <= a1[i + 1])) { *out1 = i + 1; *out2 = j; return; } else if (a1[i] > a2[j] && j != n2 - 1 && a1[i] > a2[j+1]) { // search in left half of a1 right = i - 1; } else { // search in right half of a1 left = i + 1; } } } /** * Partition the input so that * a1[0:*out1) and a2[0:*out2) contain the smallest k elements */ static void big_kth_element( HYPRE_Int *out1, HYPRE_Int *out2, HYPRE_BigInt *a1, HYPRE_BigInt *a2, HYPRE_Int n1, HYPRE_Int n2, HYPRE_Int k) { // either of the inputs is empty if (n1 == 0) { *out1 = 0; *out2 = k; return; } if (n2 == 0) { *out1 = k; *out2 = 0; return; } if (k >= n1 + n2) { *out1 = n1; *out2 = n2; return; } // one is greater than the other if (k < n1 && a1[k] <= a2[0]) { *out1 = k; *out2 = 0; return; } if (k - n1 >= 0 && a2[k - n1] >= a1[n1 - 1]) { *out1 = n1; *out2 = k - n1; return; } if (k < n2 && a2[k] <= a1[0]) { *out1 = 0; *out2 = k; return; } if (k - n2 >= 0 && a1[k - n2] >= a2[n2 - 1]) { *out1 = k - n2; *out2 = n2; return; } // now k > 0 // faster to do binary search on the shorter sequence if (n1 > n2) { SWAP(HYPRE_Int, n1, n2); SWAP(HYPRE_BigInt *, a1, a2); SWAP(HYPRE_Int *, out1, out2); } if (k < (n1 + n2)/2) { big_kth_element_(out1, out2, a1, a2, 0, hypre_min(n1 - 1, k), n1, n2, k); } else { // when k is big, faster to find (n1 + n2 - k)th biggest element HYPRE_Int offset1 = hypre_max(k - n2, 0), offset2 = hypre_max(k - n1, 0); HYPRE_Int new_k = k - offset1 - offset2; HYPRE_Int new_n1 = hypre_min(n1 - offset1, new_k + 1); HYPRE_Int new_n2 = hypre_min(n2 - offset2, new_k + 1); big_kth_element_(out1, out2, a1 + (HYPRE_BigInt)offset1, a2 + (HYPRE_BigInt)offset2, 0, new_n1 - 1, new_n1, new_n2, new_k); *out1 += offset1; *out2 += offset2; } #ifdef DBG_MERGE_SORT hypre_assert(*out1 + *out2 == k); #endif } #endif /** * @param num_threads number of threads that participate in this merge * @param my_thread_num thread id (zeor-based) among the threads that participate in this merge */ static void hypre_parallel_merge( HYPRE_Int *first1, HYPRE_Int *last1, HYPRE_Int *first2, HYPRE_Int *last2, HYPRE_Int *out, HYPRE_Int num_threads, HYPRE_Int my_thread_num) { HYPRE_Int n1 = last1 - first1; HYPRE_Int n2 = last2 - first2; HYPRE_Int n = n1 + n2; HYPRE_Int n_per_thread = (n + num_threads - 1)/num_threads; HYPRE_Int begin_rank = hypre_min(n_per_thread*my_thread_num, n); HYPRE_Int end_rank = hypre_min(begin_rank + n_per_thread, n); #ifdef DBG_MERGE_SORT hypre_assert(std::is_sorted(first1, last1)); hypre_assert(std::is_sorted(first2, last2)); #endif HYPRE_Int begin1, begin2, end1, end2; kth_element(&begin1, &begin2, first1, first2, n1, n2, begin_rank); kth_element(&end1, &end2, first1, first2, n1, n2, end_rank); while (begin1 > end1 && begin1 > 0 && begin2 < n2 && first1[begin1 - 1] == first2[begin2]) { #ifdef DBG_MERGE_SORT printf("%s:%d\n", __FILE__, __LINE__); #endif begin1--; begin2++; } while (begin2 > end2 && end1 > 0 && end2 < n2 && first1[end1 - 1] == first2[end2]) { #ifdef DBG_MERGE_SORT printf("%s:%d\n", __FILE__, __LINE__); #endif end1--; end2++; } #ifdef DBG_MERGE_SORT hypre_assert(begin1 <= end1); hypre_assert(begin2 <= end2); #endif hypre_merge( first1 + begin1, first1 + end1, first2 + begin2, first2 + end2, out + begin1 + begin2); #ifdef DBG_MERGE_SORT hypre_assert(std::is_sorted(out + begin1 + begin2, out + end1 + end2)); #endif } #ifdef HYPRE_CONCURRENT_HOPSCOTCH /** * @param num_threads number of threads that participate in this merge * @param my_thread_num thread id (zeor-based) among the threads that participate in this merge */ static void hypre_big_parallel_merge( HYPRE_BigInt *first1, HYPRE_BigInt *last1, HYPRE_BigInt *first2, HYPRE_BigInt *last2, HYPRE_BigInt *out, HYPRE_Int num_threads, HYPRE_Int my_thread_num) { HYPRE_Int n1 = (HYPRE_Int)(last1 - first1); HYPRE_Int n2 = (HYPRE_Int)(last2 - first2); HYPRE_Int n = n1 + n2; HYPRE_Int n_per_thread = (n + num_threads - 1)/num_threads; HYPRE_Int begin_rank = hypre_min(n_per_thread*my_thread_num, n); HYPRE_Int end_rank = hypre_min(begin_rank + n_per_thread, n); #ifdef DBG_MERGE_SORT hypre_assert(std::is_sorted(first1, last1)); hypre_assert(std::is_sorted(first2, last2)); #endif HYPRE_Int begin1, begin2, end1, end2; big_kth_element(&begin1, &begin2, first1, first2, n1, n2, begin_rank); big_kth_element(&end1, &end2, first1, first2, n1, n2, end_rank); while (begin1 > end1 && begin1 > 0 && begin2 < n2 && first1[begin1 - 1] == first2[begin2]) { #ifdef DBG_MERGE_SORT printf("%s:%d\n", __FILE__, __LINE__); #endif begin1--; begin2++; } while (begin2 > end2 && end1 > 0 && end2 < n2 && first1[end1 - 1] == first2[end2]) { #ifdef DBG_MERGE_SORT printf("%s:%d\n", __FILE__, __LINE__); #endif end1--; end2++; } #ifdef DBG_MERGE_SORT hypre_assert(begin1 <= end1); hypre_assert(begin2 <= end2); #endif hypre_big_merge( first1 + (HYPRE_BigInt)begin1, first1 + (HYPRE_BigInt)end1, first2 + (HYPRE_BigInt)begin2, first2 + (HYPRE_BigInt)end2, out + (HYPRE_BigInt)(begin1 + begin2)); #ifdef DBG_MERGE_SORT hypre_assert(std::is_sorted(out + begin1 + begin2, out + end1 + end2)); #endif } #endif void hypre_merge_sort(HYPRE_Int *in, HYPRE_Int *temp, HYPRE_Int len, HYPRE_Int **out) { if (0 == len) return; #ifdef HYPRE_PROFILE hypre_profile_times[HYPRE_TIMER_ID_MERGE] -= hypre_MPI_Wtime(); #endif #ifdef DBG_MERGE_SORT HYPRE_Int *dbg_buf = new HYPRE_Int[len]; std::copy(in, in + len, dbg_buf); std::sort(dbg_buf, dbg_buf + len); #endif // HYPRE_Int thread_private_len[hypre_NumThreads()]; // HYPRE_Int out_len = 0; #ifdef HYPRE_USING_OPENMP #pragma omp parallel #endif { HYPRE_Int num_threads = hypre_NumActiveThreads(); HYPRE_Int my_thread_num = hypre_GetThreadNum(); // thread-private sort HYPRE_Int i_per_thread = (len + num_threads - 1)/num_threads; HYPRE_Int i_begin = hypre_min(i_per_thread*my_thread_num, len); HYPRE_Int i_end = hypre_min(i_begin + i_per_thread, len); hypre_qsort0(in, i_begin, i_end - 1); // merge sorted sequences HYPRE_Int in_group_size; HYPRE_Int *in_buf = in; HYPRE_Int *out_buf = temp; for (in_group_size = 1; in_group_size < num_threads; in_group_size *= 2) { #ifdef HYPRE_USING_OPENMP #pragma omp barrier #endif // merge 2 in-groups into 1 out-group HYPRE_Int out_group_size = in_group_size*2; HYPRE_Int group_leader = my_thread_num/out_group_size*out_group_size; // HYPRE_Int group_sub_leader = hypre_min(group_leader + in_group_size, num_threads - 1); HYPRE_Int id_in_group = my_thread_num%out_group_size; HYPRE_Int num_threads_in_group = hypre_min(group_leader + out_group_size, num_threads) - group_leader; HYPRE_Int in_group1_begin = hypre_min(i_per_thread*group_leader, len); HYPRE_Int in_group1_end = hypre_min(in_group1_begin + i_per_thread*in_group_size, len); HYPRE_Int in_group2_begin = hypre_min(in_group1_begin + i_per_thread*in_group_size, len); HYPRE_Int in_group2_end = hypre_min(in_group2_begin + i_per_thread*in_group_size, len); hypre_parallel_merge( in_buf + in_group1_begin, in_buf + in_group1_end, in_buf + in_group2_begin, in_buf + in_group2_end, out_buf + in_group1_begin, num_threads_in_group, id_in_group); HYPRE_Int *temp = in_buf; in_buf = out_buf; out_buf = temp; } *out = in_buf; } /* omp parallel */ #ifdef DBG_MERGE_SORT hypre_assert(std::equal(*out, *out + len, dbg_buf)); delete[] dbg_buf; #endif #ifdef HYPRE_PROFILE hypre_profile_times[HYPRE_TIMER_ID_MERGE] += hypre_MPI_Wtime(); #endif } #ifdef HYPRE_CONCURRENT_HOPSCOTCH void hypre_sort_and_create_inverse_map( HYPRE_Int *in, HYPRE_Int len, HYPRE_Int **out, hypre_UnorderedIntMap *inverse_map) { if (len == 0) { return; } #ifdef HYPRE_PROFILE hypre_profile_times[HYPRE_TIMER_ID_MERGE] -= hypre_MPI_Wtime(); #endif HYPRE_Int *temp = hypre_TAlloc(HYPRE_Int, len, HYPRE_MEMORY_HOST); hypre_merge_sort(in, temp, len, out); hypre_UnorderedIntMapCreate(inverse_map, 2*len, 16*hypre_NumThreads()); HYPRE_Int i; #pragma omp parallel for HYPRE_SMP_SCHEDULE for (i = 0; i < len; i++) { HYPRE_Int old = hypre_UnorderedIntMapPutIfAbsent(inverse_map, (*out)[i], i); hypre_assert(old == HYPRE_HOPSCOTCH_HASH_EMPTY); #ifdef DBG_MERGE_SORT if (hypre_UnorderedIntMapGet(inverse_map, (*out)[i]) != i) { fprintf(stderr, "%d %d\n", i, (*out)[i]); hypre_assert(false); } #endif } #ifdef DBG_MERGE_SORT std::unordered_map<HYPRE_Int, HYPRE_Int> inverse_map2(len); for (HYPRE_Int i = 0; i < len; ++i) { inverse_map2[(*out)[i]] = i; if (hypre_UnorderedIntMapGet(inverse_map, (*out)[i]) != i) { fprintf(stderr, "%d %d\n", i, (*out)[i]); hypre_assert(false); } } hypre_assert(hypre_UnorderedIntMapSize(inverse_map) == len); #endif if (*out == in) { hypre_TFree(temp, HYPRE_MEMORY_HOST); } else { hypre_TFree(in, HYPRE_MEMORY_HOST); } #ifdef HYPRE_PROFILE hypre_profile_times[HYPRE_TIMER_ID_MERGE] += hypre_MPI_Wtime(); #endif } #ifdef HYPRE_CONCURRENT_HOPSCOTCH void hypre_big_merge_sort(HYPRE_BigInt *in, HYPRE_BigInt *temp, HYPRE_Int len, HYPRE_BigInt **out) { if (0 == len) return; #ifdef HYPRE_PROFILE hypre_profile_times[HYPRE_TIMER_ID_MERGE] -= hypre_MPI_Wtime(); #endif #ifdef DBG_MERGE_SORT HYPRE_Int *dbg_buf = new HYPRE_Int[len]; std::copy(in, in + len, dbg_buf); std::sort(dbg_buf, dbg_buf + len); #endif // HYPRE_Int thread_private_len[hypre_NumThreads()]; // HYPRE_Int out_len = 0; #ifdef HYPRE_USING_OPENMP #pragma omp parallel #endif { HYPRE_Int num_threads = hypre_NumActiveThreads(); HYPRE_Int my_thread_num = hypre_GetThreadNum(); // thread-private sort HYPRE_Int i_per_thread = (len + num_threads - 1)/num_threads; HYPRE_Int i_begin = hypre_min(i_per_thread*my_thread_num, len); HYPRE_Int i_end = hypre_min(i_begin + i_per_thread, len); hypre_BigQsort0(in, i_begin, i_end - 1); // merge sorted sequences HYPRE_Int in_group_size; HYPRE_BigInt *in_buf = in; HYPRE_BigInt *out_buf = temp; for (in_group_size = 1; in_group_size < num_threads; in_group_size *= 2) { #ifdef HYPRE_USING_OPENMP #pragma omp barrier #endif // merge 2 in-groups into 1 out-group HYPRE_Int out_group_size = in_group_size*2; HYPRE_Int group_leader = my_thread_num/out_group_size*out_group_size; // HYPRE_Int group_sub_leader = hypre_min(group_leader + in_group_size, num_threads - 1); HYPRE_Int id_in_group = my_thread_num%out_group_size; HYPRE_Int num_threads_in_group = hypre_min(group_leader + out_group_size, num_threads) - group_leader; HYPRE_Int in_group1_begin = hypre_min(i_per_thread*group_leader, len); HYPRE_Int in_group1_end = hypre_min(in_group1_begin + i_per_thread*in_group_size, len); HYPRE_Int in_group2_begin = hypre_min(in_group1_begin + i_per_thread*in_group_size, len); HYPRE_Int in_group2_end = hypre_min(in_group2_begin + i_per_thread*in_group_size, len); hypre_big_parallel_merge( in_buf + (HYPRE_BigInt)in_group1_begin, in_buf + (HYPRE_BigInt)in_group1_end, in_buf + (HYPRE_BigInt)in_group2_begin, in_buf + (HYPRE_BigInt)in_group2_end, out_buf + (HYPRE_BigInt)in_group1_begin, num_threads_in_group, id_in_group); HYPRE_BigInt *temp = in_buf; in_buf = out_buf; out_buf = temp; } *out = in_buf; } /* omp parallel */ #ifdef DBG_MERGE_SORT hypre_assert(std::equal(*out, *out + len, dbg_buf)); delete[] dbg_buf; #endif #ifdef HYPRE_PROFILE hypre_profile_times[HYPRE_TIMER_ID_MERGE] += hypre_MPI_Wtime(); #endif } void hypre_big_sort_and_create_inverse_map( HYPRE_BigInt *in, HYPRE_Int len, HYPRE_BigInt **out, hypre_UnorderedBigIntMap *inverse_map) { if (len == 0) { return; } #ifdef HYPRE_PROFILE hypre_profile_times[HYPRE_TIMER_ID_MERGE] -= hypre_MPI_Wtime(); #endif HYPRE_BigInt *temp = hypre_TAlloc(HYPRE_BigInt, len, HYPRE_MEMORY_HOST); hypre_big_merge_sort(in, temp, len, out); hypre_UnorderedBigIntMapCreate(inverse_map, 2*len, 16*hypre_NumThreads()); HYPRE_Int i; #pragma omp parallel for HYPRE_SMP_SCHEDULE for (i = 0; i < len; i++) { HYPRE_Int old = hypre_UnorderedBigIntMapPutIfAbsent(inverse_map, (*out)[i], i); hypre_assert(old == HYPRE_HOPSCOTCH_HASH_EMPTY); #ifdef DBG_MERGE_SORT if (hypre_UnorderedBigIntMapGet(inverse_map, (*out)[i]) != i) { fprintf(stderr, "%d %d\n", i, (*out)[i]); hypre_assert(false); } #endif } #ifdef DBG_MERGE_SORT std::unordered_map<HYPRE_Int, HYPRE_Int> inverse_map2(len); for (HYPRE_Int i = 0; i < len; ++i) { inverse_map2[(*out)[i]] = i; if (hypre_UnorderedBigIntMapGet(inverse_map, (*out)[i]) != i) { fprintf(stderr, "%d %d\n", i, (*out)[i]); hypre_assert(false); } } hypre_assert(hypre_UnorderedBigIntMapSize(inverse_map) == len); #endif if (*out == in) { hypre_TFree(temp, HYPRE_MEMORY_HOST); } else { hypre_TFree(in, HYPRE_MEMORY_HOST); } #ifdef HYPRE_PROFILE hypre_profile_times[HYPRE_TIMER_ID_MERGE] += hypre_MPI_Wtime(); #endif } #endif #endif /* vim: set tabstop=8 softtabstop=3 sw=3 expandtab: */
trmv_x_sky_n_hi_trans.c
#include "alphasparse/kernel.h" #include "alphasparse/opt.h" #include "alphasparse/util.h" #include <string.h> #ifdef _OPENMP #include <omp.h> #endif static alphasparse_status_t ONAME_omp(const ALPHA_Number alpha, const ALPHA_SPMAT_SKY *A, const ALPHA_Number *x, const ALPHA_Number beta, ALPHA_Number *y) { const ALPHA_INT m = A->rows; const ALPHA_INT n = A->cols; if(m != n) return ALPHA_SPARSE_STATUS_INVALID_VALUE; const ALPHA_INT thread_num = alpha_get_thread_num(); #ifdef _OPENMP #pragma omp parallel for num_threads(thread_num) #endif for(ALPHA_INT i = 0; i < m; ++i) { alpha_mul(y[i], beta, y[i]); } #ifdef _OPENMP #pragma omp parallel for num_threads(thread_num) #endif for(ALPHA_INT r = 0; r < m; ++r) { const ALPHA_INT row_start = A->pointers[r]; const ALPHA_INT row_end = A->pointers[r + 1]; ALPHA_INT row_indx = 1; for(ALPHA_INT i = row_start; i < row_end; i++) { ALPHA_INT row_eles = row_end - row_start; ALPHA_INT c = r - row_eles + row_indx; ALPHA_Number t; alpha_mul(t, alpha, A->values[i]); alpha_madde(y[r], t, x[c]); row_indx ++; } } return ALPHA_SPARSE_STATUS_SUCCESS; } alphasparse_status_t ONAME(const ALPHA_Number alpha, const ALPHA_SPMAT_SKY *A, const ALPHA_Number *x, const ALPHA_Number beta, ALPHA_Number *y) { return ONAME_omp(alpha, A, x, beta, y); }
TemporalRowConvolution.c
#ifndef TH_GENERIC_FILE #define TH_GENERIC_FILE "generic/TemporalRowConvolution.c" #else static inline void THNN_(TemporalRowConvolution_shapeCheck)( THNNState *state, THTensor *input, THTensor *gradOutput, THTensor *weight, THTensor *bias, int kW, int dW, int padW) { THArgCheck(kW > 0, 5, "kernel size should be greater than zero, but got kW: %d", kW); THArgCheck(dW > 0, 6, "stride should be greater than zero, but got dW: %d", dW); THNN_ARGCHECK(weight->nDimension == 3, 3, weight, "3D weight tensor expected, but got: %s"); THArgCheck(THTensor_(isContiguous)(weight), 4, "weight must be contiguous"); THArgCheck(!bias || THTensor_(isContiguous)(bias), 5, "bias must be contiguous"); if (bias != NULL) { THNN_CHECK_DIM_SIZE(bias, 1, 0, weight->size[0]); } // we're always looking at (possibly batch) x feats x seq int ndim = input->nDimension; int dimF = 0; int dimS = 1; if (ndim == 3) { ++dimS; ++dimF; } THNN_ARGCHECK(ndim == 2 || ndim == 3, 1, input, "2D or 3D (batch mode) input tensor expected, but got :%s"); long inputFrameSize = weight->size[0]; long nInputFrame = input->size[dimS]; long nOutputFrame = (nInputFrame + 2 * padW - kW) / dW + 1; if (nOutputFrame < 1) { THError("Given input size: (%d x %d). " "Calculated output size: (%d x %d). Output size is too small", inputFrameSize, nInputFrame, inputFrameSize, nOutputFrame); } THNN_CHECK_DIM_SIZE(input, ndim, dimF, inputFrameSize); if (gradOutput != NULL) { THNN_CHECK_DIM_SIZE(gradOutput, ndim, dimF, inputFrameSize); THNN_CHECK_DIM_SIZE(gradOutput, ndim, dimS, nOutputFrame); } } static void THNN_(unfolded_acc_row)( THTensor *finput, THTensor *input, int kW, int dW, int padW, long inputFrameSize, long nInputFrame, long nOutputFrame) { size_t c; real *input_data = THTensor_(data)(input); real *finput_data = THTensor_(data)(finput); // #pragma omp parallel for private(c) for (c = 0; c < inputFrameSize; c++) { size_t kw, x; size_t ix = 0; for (kw = 0; kw < kW; kw++) { real *src = finput_data + c * (kW * nOutputFrame) + kw * (nOutputFrame); real *dst = input_data + c * (nInputFrame); ix = (size_t)(kw); if (dW == 1) { real *dst_slice = dst + (size_t)(ix); THVector_(cadd)(dst_slice, dst_slice, src, 1, nOutputFrame); } else { for (x = 0; x < nOutputFrame; x++) { real *dst_slice = dst + (size_t)(ix + x * dW); THVector_(cadd)(dst_slice, dst_slice, src + (size_t)(x), 1, 1); } } } } } static void THNN_(unfolded_copy_row)( THTensor *finput, THTensor *input, int kW, int dW, int padW, long inputFrameSize, long nInputFrame, long nOutputFrame) { long k; real *input_data = THTensor_(data)(input); real *finput_data = THTensor_(data)(finput); // #pragma omp parallel for private(k) for (k = 0; k < inputFrameSize * kW; k++) { size_t c = k / kW; size_t rest = k % kW; size_t kw = rest % kW; size_t x; size_t ix; real *dst = finput_data + c * (kW * nOutputFrame) + kw * (nOutputFrame); real *src = input_data + c * (nInputFrame); ix = (size_t)(kw); if (dW == 1) { memcpy(dst, src+(size_t)(ix), sizeof(real) * (nOutputFrame)); } else { for (x = 0; x < nOutputFrame; x++) { memcpy(dst + (size_t)(x), src + (size_t)(ix + x * dW), sizeof(real) * 1); } } } } static void THNN_(TemporalRowConvolution_updateOutput_frame)( THTensor *input, THTensor *output, THTensor *weight, THTensor *bias, THTensor *finput, int kW, int dW, int padW, long inputFrameSize, long nInputFrame, long nOutputFrame) { long i; THTensor *output3d = THTensor_(newWithStorage3d)( output->storage, output->storageOffset, inputFrameSize, -1, 1, -1, nOutputFrame, -1); THNN_(unfolded_copy_row)(finput, input, kW, dW, padW, inputFrameSize, nInputFrame, nOutputFrame); THTensor_(zero)(output); if (bias != NULL) { for (i = 0; i < inputFrameSize; i++) THVector_(fill) (output->storage->data + output->storageOffset + output->stride[0] * i, THTensor_(get1d)(bias, i), nOutputFrame); } THTensor_(baddbmm)(output3d, 1, output3d, 1, weight, finput); THTensor_(free)(output3d); } void THNN_(TemporalRowConvolution_updateOutput)( THNNState *state, THTensor *input, THTensor *output, THTensor *weight, THTensor *bias, THTensor *finput, THTensor *fgradInput, // unused here but needed for Cuda int kW, int dW, int padW, bool featFirst) { int ndim = input->nDimension; THTensor *tinput; if (!featFirst) { tinput = THTensor_(newTranspose)(input, ndim - 1, ndim - 2); input = THTensor_(newContiguous)(tinput); } else { input = THTensor_(newContiguous)(input); } THNN_(TemporalRowConvolution_shapeCheck)( state, input, NULL, weight, bias, kW, dW, padW); long inputFrameSize = weight->size[0]; long nInputFrame = input->size[ndim - 1]; long nOutputFrame = (nInputFrame + 2 * padW - kW) / dW + 1; if (ndim == 2) { /* non-batch mode */ THTensor_(resize3d)(finput, inputFrameSize, kW, nOutputFrame); THTensor_(resize2d)(output, inputFrameSize, nOutputFrame); THTensor_(zero)(finput); THTensor_(zero)(output); THNN_(TemporalRowConvolution_updateOutput_frame) (input, output, weight, bias, finput, kW, dW, padW, inputFrameSize, nInputFrame, nOutputFrame); } else { long T = input->size[0]; long t; THTensor_(resize4d)(finput, T, inputFrameSize, kW, nOutputFrame); THTensor_(resize3d)(output, T, inputFrameSize, nOutputFrame); THTensor_(zero)(finput); THTensor_(zero)(output); #pragma omp parallel for private(t) for (t = 0; t < T; t++) { THTensor *input_t = THTensor_(newSelect)(input, 0, t); THTensor *output_t = THTensor_(newSelect)(output, 0, t); THTensor *finput_t = THTensor_(newSelect)(finput, 0, t); THNN_(TemporalRowConvolution_updateOutput_frame) (input_t, output_t, weight, bias, finput_t, kW, dW, padW, inputFrameSize, nInputFrame, nOutputFrame); THTensor_(free)(input_t); THTensor_(free)(output_t); THTensor_(free)(finput_t); } } if (!featFirst) { // NOTE: output will NOT be contiguous in this case THTensor_(transpose)(output, output, ndim - 1, ndim - 2); THTensor_(free)(tinput); } THTensor_(free)(input); } static void THNN_(TemporalRowConvolution_updateGradInput_frame)( THTensor *gradInput, THTensor *gradOutput, THTensor *weight, THTensor *fgradInput, int kW, int dW, int padW, long inputFrameSize, long nInputFrame, long nOutputFrame) { THTensor *gradOutput3d = THTensor_(newWithStorage3d)( gradOutput->storage, gradOutput->storageOffset, inputFrameSize, -1, 1, -1, nOutputFrame, -1); // weight: inputFrameSize x kW x 1 // gradOutput3d: inputFrameSize x 1 x nOutputFrame THTensor_(baddbmm)(fgradInput, 0, fgradInput, 1, weight, gradOutput3d); // fgradInput: inputFrameSize x kW x nOutputFrame THTensor_(free)(gradOutput3d); THTensor_(zero)(gradInput); THNN_(unfolded_acc_row)(fgradInput, gradInput, kW, dW, padW, inputFrameSize, nInputFrame, nOutputFrame); } void THNN_(TemporalRowConvolution_updateGradInput)( THNNState *state, THTensor *input, THTensor *gradOutput, THTensor *gradInput, THTensor *weight, THTensor *finput, THTensor *fgradInput, int kW, int dW, int padW, bool featFirst) { int ndim = input->nDimension; THTensor *tinput, *tgradOutput; if (!featFirst) { tinput = THTensor_(newTranspose)(input, ndim - 1, ndim - 2); tgradOutput = THTensor_(newTranspose)(gradOutput, ndim - 1, ndim - 2); input = THTensor_(newContiguous)(tinput); gradOutput = THTensor_(newContiguous)(tgradOutput); } else { input = THTensor_(newContiguous)(input); gradOutput = THTensor_(newContiguous)(gradOutput); } THNN_(TemporalRowConvolution_shapeCheck)(state, input, gradOutput, weight, NULL, kW, dW, padW); long inputFrameSize = weight->size[0]; long nInputFrame = input->size[ndim - 1]; long nOutputFrame = (nInputFrame + 2 * padW - kW) / dW + 1; THTensor_(resizeAs)(fgradInput, finput); THTensor_(resizeAs)(gradInput, input); THTensor_(zero)(fgradInput); THTensor_(zero)(gradInput); THTensor *tweight = THTensor_(new)(); THTensor_(transpose)(tweight, weight, 1, 2); if (ndim == 2) { THNN_(TemporalRowConvolution_updateGradInput_frame) (gradInput, gradOutput, tweight, fgradInput, kW, dW, padW, inputFrameSize, nInputFrame, nOutputFrame); } else { long T = input->size[0]; long t; #pragma omp parallel for private(t) for (t = 0; t < T; t++) { THTensor *gradInput_t = THTensor_(newSelect)(gradInput, 0, t); THTensor *gradOutput_t = THTensor_(newSelect)(gradOutput, 0, t); THTensor *fgradInput_t = THTensor_(newSelect)(fgradInput, 0, t); THNN_(TemporalRowConvolution_updateGradInput_frame) (gradInput_t, gradOutput_t, tweight, fgradInput_t, kW, dW, padW, inputFrameSize, nInputFrame, nOutputFrame); THTensor_(free)(gradInput_t); THTensor_(free)(gradOutput_t); THTensor_(free)(fgradInput_t); } } THTensor_(free)(tweight); if (!featFirst) { // NOTE: gradInput will NOT be contiguous in this case THTensor_(free)(tinput); THTensor_(free)(tgradOutput); THTensor_(transpose)(gradInput, gradInput, ndim - 1, ndim - 2); } THTensor_(free)(input); THTensor_(free)(gradOutput); } static void THNN_(TemporalRowConvolution_accGradParameters_frame)( THTensor *gradOutput, THTensor *gradWeight, THTensor *gradBias, THTensor *finput, real scale) { long i; THTensor *gradOutput3d = THTensor_(newWithStorage3d)( gradOutput->storage, gradOutput->storageOffset, gradOutput->size[0], -1, 1, -1, gradOutput->size[1], -1); THTensor *tfinput = THTensor_(new)(); THTensor_(transpose)(tfinput, finput, 1, 2); // gradOutput3d: inputFrameSize x 1 x nOutputFrame // finput: inputFrameSize x nOutputFrame x kW THTensor_(baddbmm)(gradWeight, 1, gradWeight, scale, gradOutput3d, tfinput); // gradWeight: inputFrameSize x 1 x kW THTensor_(free)(tfinput); if (gradBias != NULL) { for (i = 0; i < gradBias->size[0]; i++) { long k; real sum = 0; real *data = gradOutput3d->storage->data + gradOutput3d->storageOffset + i * gradOutput3d->stride[0]; for (k = 0; k < gradOutput3d->size[2]; k++) { sum += data[k]; } (gradBias->storage->data + gradBias->storageOffset)[i] += scale * sum; } } THTensor_(free)(gradOutput3d); } void THNN_(TemporalRowConvolution_accGradParameters)( THNNState *state, THTensor *input, THTensor *gradOutput, THTensor *gradWeight, THTensor *gradBias, THTensor *finput, THTensor *fgradInput, int kW, int dW, int padW, bool featFirst, accreal scale_) { real scale = TH_CONVERT_ACCREAL_TO_REAL(scale_); int ndim = input->nDimension; THTensor *tinput, *tgradOutput; if (!featFirst) { tinput = THTensor_(newTranspose)(input, ndim - 1, ndim - 2); tgradOutput = THTensor_(newTranspose)(gradOutput, ndim - 1, ndim - 2); input = THTensor_(newContiguous)(tinput); gradOutput = THTensor_(newContiguous)(tgradOutput); } else { input = THTensor_(newContiguous)(input); gradOutput = THTensor_(newContiguous)(gradOutput); } THNN_(TemporalRowConvolution_shapeCheck) (state, input, gradOutput, gradWeight, gradBias, kW, dW, padW); long inputFrameSize = gradWeight->size[0]; long nInputFrame = input->size[ndim - 1]; long nOutputFrame = (nInputFrame + 2 * padW - kW) / dW + 1; if (ndim == 2) { THNN_(TemporalRowConvolution_accGradParameters_frame)( gradOutput, gradWeight, gradBias, finput, scale); } else { long T = input->size[0]; long t; for (t = 0; t < T; t++) { THTensor *gradOutput_t = THTensor_(newSelect)(gradOutput, 0, t); THTensor *finput_t = THTensor_(newSelect)(finput, 0, t); THNN_(TemporalRowConvolution_accGradParameters_frame)( gradOutput_t, gradWeight, gradBias, finput_t, scale); THTensor_(free)(gradOutput_t); THTensor_(free)(finput_t); } } if (!featFirst) { THTensor_(free)(tinput); THTensor_(free)(tgradOutput); } THTensor_(free)(input); THTensor_(free)(gradOutput); } #endif
3d25pt_var.lbpar.c
#include <omp.h> #include <math.h> #define ceild(n,d) ceil(((double)(n))/((double)(d))) #define floord(n,d) floor(((double)(n))/((double)(d))) #define max(x,y) ((x) > (y)? (x) : (y)) #define min(x,y) ((x) < (y)? (x) : (y)) /* * Order-1, 3D 25 point stencil with axis-symmetric ariable coefficients * Adapted from PLUTO and Pochoir test bench * * Tareq Malas */ #include <stdio.h> #include <stdlib.h> #include <sys/time.h> #ifdef LIKWID_PERFMON #include <likwid.h> #endif #include "print_utils.h" #define TESTS 2 #define MAX(a,b) ((a) > (b) ? a : b) #define MIN(a,b) ((a) < (b) ? a : b) /* Subtract the `struct timeval' values X and Y, * storing the result in RESULT. * * Return 1 if the difference is negative, otherwise 0. */ int timeval_subtract(struct timeval *result, struct timeval *x, struct timeval *y) { /* Perform the carry for the later subtraction by updating y. */ if (x->tv_usec < y->tv_usec) { int nsec = (y->tv_usec - x->tv_usec) / 1000000 + 1; y->tv_usec -= 1000000 * nsec; y->tv_sec += nsec; } if (x->tv_usec - y->tv_usec > 1000000) { int nsec = (x->tv_usec - y->tv_usec) / 1000000; y->tv_usec += 1000000 * nsec; y->tv_sec -= nsec; } /* Compute the time remaining to wait. * tv_usec is certainly positive. */ result->tv_sec = x->tv_sec - y->tv_sec; result->tv_usec = x->tv_usec - y->tv_usec; /* Return 1 if result is negative. */ return x->tv_sec < y->tv_sec; } int main(int argc, char *argv[]) { int t, i, j, k, m, test; int Nx, Ny, Nz, Nt; if (argc > 3) { Nx = atoi(argv[1])+8; Ny = atoi(argv[2])+8; Nz = atoi(argv[3])+8; } if (argc > 4) Nt = atoi(argv[4]); // allocate the arrays double ****A = (double ****) malloc(sizeof(double***)*2); for(m=0; m<2;m++){ A[m] = (double ***) malloc(sizeof(double**)*Nz); for(i=0; i<Nz; i++){ A[m][i] = (double**) malloc(sizeof(double*)*Ny); for(j=0;j<Ny;j++){ A[m][i][j] = (double*) malloc(sizeof(double)*Nx); } } } double ****coef = (double ****) malloc(sizeof(double***)*13); for(m=0; m<13;m++){ coef[m] = (double ***) malloc(sizeof(double**)*Nz); for(i=0; i<Nz; i++){ coef[m][i] = (double**) malloc(sizeof(double*)*Ny); for(j=0;j<Ny;j++){ coef[m][i][j] = (double*) malloc(sizeof(double)*Nx); } } } // tile size information, including extra element to decide the list length int *tile_size = (int*) malloc(sizeof(int)); tile_size[0] = -1; // The list is modified here before source-to-source transformations tile_size = (int*) realloc((void *)tile_size, sizeof(int)*5); tile_size[0] = 24; tile_size[1] = 24; tile_size[2] = 32; tile_size[3] = 32; tile_size[4] = -1; // for timekeeping int ts_return = -1; struct timeval start, end, result; double tdiff = 0.0, min_tdiff=1.e100; const int BASE = 1024; // initialize variables // srand(42); for (i = 1; i < Nz; i++) { for (j = 1; j < Ny; j++) { for (k = 1; k < Nx; k++) { A[0][i][j][k] = 1.0 * (rand() % BASE); } } } for (m=0; m<13; m++) { for (i=1; i<Nz; i++) { for (j=1; j<Ny; j++) { for (k=1; k<Nx; k++) { coef[m][i][j][k] = 1.0 * (rand() % BASE); } } } } #ifdef LIKWID_PERFMON LIKWID_MARKER_INIT; #pragma omp parallel { LIKWID_MARKER_THREADINIT; #pragma omp barrier LIKWID_MARKER_START("calc"); } #endif int num_threads = 1; #if defined(_OPENMP) num_threads = omp_get_max_threads(); #endif for(test=0; test<TESTS; test++){ gettimeofday(&start, 0); // serial execution - Addition: 6 && Multiplication: 2 /* Copyright (C) 1991-2014 Free Software Foundation, Inc. This file is part of the GNU C Library. The GNU C Library is free software; you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by the Free Software Foundation; either version 2.1 of the License, or (at your option) any later version. The GNU C Library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details. You should have received a copy of the GNU Lesser General Public License along with the GNU C Library; if not, see <http://www.gnu.org/licenses/>. */ /* This header is separate from features.h so that the compiler can include it implicitly at the start of every compilation. It must not itself include <features.h> or any other header that includes <features.h> because the implicit include comes before any feature test macros that may be defined in a source file before it first explicitly includes a system header. GCC knows the name of this header in order to preinclude it. */ /* glibc's intent is to support the IEC 559 math functionality, real and complex. If the GCC (4.9 and later) predefined macros specifying compiler intent are available, use them to determine whether the overall intent is to support these features; otherwise, presume an older compiler has intent to support these features and define these macros by default. */ /* wchar_t uses ISO/IEC 10646 (2nd ed., published 2011-03-15) / Unicode 6.0. */ /* We do not support C11 <threads.h>. */ int t1, t2, t3, t4, t5, t6, t7, t8; int lb, ub, lbp, ubp, lb2, ub2; register int lbv, ubv; /* Start of CLooG code */ if ((Nt >= 1) && (Nx >= 9) && (Ny >= 9) && (Nz >= 9)) { for (t1=-1;t1<=floord(Nt-1,3);t1++) { lbp=max(ceild(t1,2),ceild(6*t1-Nt+2,6)); ubp=min(floord(4*Nt+Nz-9,24),floord(12*t1+Nz+6,24)); #pragma omp parallel for private(lbv,ubv,t3,t4,t5,t6,t7,t8) for (t2=lbp;t2<=ubp;t2++) { for (t3=max(max(max(0,ceild(3*t1-3*t2-2,4)),ceild(3*t1-6,8)),ceild(24*t2-Nz-19,32));t3<=min(min(min(floord(4*Nt+Ny-9,32),floord(12*t1+Ny+15,32)),floord(24*t2+Ny+11,32)),floord(24*t1-24*t2+Nz+Ny+13,32));t3++) { for (t4=max(max(max(max(0,ceild(3*t1-3*t2-2,4)),ceild(3*t1-6,8)),ceild(24*t2-Nz-19,32)),ceild(32*t3-Ny-19,32));t4<=min(min(min(min(floord(4*Nt+Nx-9,32),floord(12*t1+Nx+15,32)),floord(24*t2+Nx+11,32)),floord(32*t3+Nx+19,32)),floord(24*t1-24*t2+Nz+Nx+13,32));t4++) { for (t5=max(max(max(max(max(0,ceild(24*t2-Nz+5,4)),ceild(32*t3-Ny+5,4)),ceild(32*t4-Nx+5,4)),3*t1),6*t1-6*t2+1);t5<=min(min(min(min(min(floord(24*t1-24*t2+Nz+18,4),Nt-1),3*t1+5),6*t2+4),8*t3+6),8*t4+6);t5++) { for (t6=max(max(24*t2,4*t5+4),-24*t1+24*t2+8*t5-23);t6<=min(min(24*t2+23,-24*t1+24*t2+8*t5),4*t5+Nz-5);t6++) { for (t7=max(32*t3,4*t5+4);t7<=min(32*t3+31,4*t5+Ny-5);t7++) { lbv=max(32*t4,4*t5+4); ubv=min(32*t4+31,4*t5+Nx-5); #pragma ivdep #pragma vector always for (t8=lbv;t8<=ubv;t8++) { A[( t5 + 1) % 2][ (-4*t5+t6)][ (-4*t5+t7)][ (-4*t5+t8)] = (((((((((((((coef[0][ (-4*t5+t6)][ (-4*t5+t7)][ (-4*t5+t8)] * A[ t5 % 2][ (-4*t5+t6)][ (-4*t5+t7)][ (-4*t5+t8)]) + (coef[1][ (-4*t5+t6)][ (-4*t5+t7)][ (-4*t5+t8)] * (A[ t5 % 2][ (-4*t5+t6) - 1][ (-4*t5+t7)][ (-4*t5+t8)] + A[ t5 % 2][ (-4*t5+t6) + 1][ (-4*t5+t7)][ (-4*t5+t8)]))) + (coef[2][ (-4*t5+t6)][ (-4*t5+t7)][ (-4*t5+t8)] * (A[ t5 % 2][ (-4*t5+t6)][ (-4*t5+t7) - 1][ (-4*t5+t8)] + A[ t5 % 2][ (-4*t5+t6)][ (-4*t5+t7) + 1][ (-4*t5+t8)]))) + (coef[3][ (-4*t5+t6)][ (-4*t5+t7)][ (-4*t5+t8)] * (A[ t5 % 2][ (-4*t5+t6)][ (-4*t5+t7)][ (-4*t5+t8) - 1] + A[ t5 % 2][ (-4*t5+t6)][ (-4*t5+t7)][ (-4*t5+t8) + 1]))) + (coef[4][ (-4*t5+t6)][ (-4*t5+t7)][ (-4*t5+t8)] * (A[ t5 % 2][ (-4*t5+t6) - 2][ (-4*t5+t7)][ (-4*t5+t8)] + A[ t5 % 2][ (-4*t5+t6) + 2][ (-4*t5+t7)][ (-4*t5+t8)]))) + (coef[5][ (-4*t5+t6)][ (-4*t5+t7)][ (-4*t5+t8)] * (A[ t5 % 2][ (-4*t5+t6)][ (-4*t5+t7) - 2][ (-4*t5+t8)] + A[ t5 % 2][ (-4*t5+t6)][ (-4*t5+t7) + 2][ (-4*t5+t8)]))) + (coef[6][ (-4*t5+t6)][ (-4*t5+t7)][ (-4*t5+t8)] * (A[ t5 % 2][ (-4*t5+t6)][ (-4*t5+t7)][ (-4*t5+t8) - 2] + A[ t5 % 2][ (-4*t5+t6)][ (-4*t5+t7)][ (-4*t5+t8) + 2]))) + (coef[7][ (-4*t5+t6)][ (-4*t5+t7)][ (-4*t5+t8)] * (A[ t5 % 2][ (-4*t5+t6) - 3][ (-4*t5+t7)][ (-4*t5+t8)] + A[ t5 % 2][ (-4*t5+t6) + 3][ (-4*t5+t7)][ (-4*t5+t8)]))) + (coef[8][ (-4*t5+t6)][ (-4*t5+t7)][ (-4*t5+t8)] * (A[ t5 % 2][ (-4*t5+t6)][ (-4*t5+t7) - 3][ (-4*t5+t8)] + A[ t5 % 2][ (-4*t5+t6)][ (-4*t5+t7) + 3][ (-4*t5+t8)]))) + (coef[9][ (-4*t5+t6)][ (-4*t5+t7)][ (-4*t5+t8)] * (A[ t5 % 2][ (-4*t5+t6)][ (-4*t5+t7)][ (-4*t5+t8) - 3] + A[ t5 % 2][ (-4*t5+t6)][ (-4*t5+t7)][ (-4*t5+t8) + 3]))) + (coef[10][ (-4*t5+t6)][ (-4*t5+t7)][ (-4*t5+t8)] * (A[ t5 % 2][ (-4*t5+t6) - 4][ (-4*t5+t7)][ (-4*t5+t8)] + A[ t5 % 2][ (-4*t5+t6) + 4][ (-4*t5+t7)][ (-4*t5+t8)]))) + (coef[11][ (-4*t5+t6)][ (-4*t5+t7)][ (-4*t5+t8)] * (A[ t5 % 2][ (-4*t5+t6)][ (-4*t5+t7) - 4][ (-4*t5+t8)] + A[ t5 % 2][ (-4*t5+t6)][ (-4*t5+t7) + 4][ (-4*t5+t8)]))) + (coef[12][ (-4*t5+t6)][ (-4*t5+t7)][ (-4*t5+t8)] * (A[ t5 % 2][ (-4*t5+t6)][ (-4*t5+t7)][ (-4*t5+t8) - 4] + A[ t5 % 2][ (-4*t5+t6)][ (-4*t5+t7)][ (-4*t5+t8) + 4])));; } } } } } } } } } /* End of CLooG code */ gettimeofday(&end, 0); ts_return = timeval_subtract(&result, &end, &start); tdiff = (double) (result.tv_sec + result.tv_usec * 1.0e-6); min_tdiff = min(min_tdiff, tdiff); printf("Rank 0 TEST# %d time: %f\n", test, tdiff); } PRINT_RESULTS(4, "variable axis-symmetric") #ifdef LIKWID_PERFMON #pragma omp parallel { LIKWID_MARKER_STOP("calc"); } LIKWID_MARKER_CLOSE; #endif // Free allocated arrays for(i=0; i<Nz; i++){ for(j=0;j<Ny;j++){ free(A[0][i][j]); free(A[1][i][j]); } free(A[0][i]); free(A[1][i]); } free(A[0]); free(A[1]); for(m=0; m<13;m++){ for(i=0; i<Nz; i++){ for(j=0;j<Ny;j++){ free(coef[m][i][j]); } free(coef[m][i]); } free(coef[m]); } return 0; }
GB_unop__identity_bool_int16.c
//------------------------------------------------------------------------------ // GB_unop: hard-coded functions for each built-in unary operator //------------------------------------------------------------------------------ // SuiteSparse:GraphBLAS, Timothy A. Davis, (c) 2017-2020, All Rights Reserved. // http://suitesparse.com See GraphBLAS/Doc/License.txt for license. //------------------------------------------------------------------------------ // If this file is in the Generated/ folder, do not edit it (auto-generated). #include "GB.h" #ifndef GBCOMPACT #include "GB_control.h" #include "GB_unop__include.h" // C=unop(A) is defined by the following types and operators: // op(A) function: GB_unop_apply__identity_bool_int16 // op(A') function: GB_unop_tran__identity_bool_int16 // C type: bool // A type: int16_t // cast: bool cij = (bool) aij // unaryop: cij = aij #define GB_ATYPE \ int16_t #define GB_CTYPE \ bool // aij = Ax [pA] #define GB_GETA(aij,Ax,pA) \ int16_t aij = Ax [pA] #define GB_CX(p) Cx [p] // unary operator #define GB_OP(z, x) \ z = x ; // casting #define GB_CAST(z, aij) \ bool z = (bool) aij ; // cij = op (aij) #define GB_CAST_OP(pC,pA) \ { \ /* aij = Ax [pA] */ \ int16_t aij = Ax [pA] ; \ /* Cx [pC] = op (cast (aij)) */ \ bool z = (bool) aij ; \ Cx [pC] = z ; \ } // disable this operator and use the generic case if these conditions hold #define GB_DISABLE \ (GxB_NO_IDENTITY || GxB_NO_BOOL || GxB_NO_INT16) //------------------------------------------------------------------------------ // Cx = op (cast (Ax)): apply a unary operator //------------------------------------------------------------------------------ GrB_Info GB_unop_apply__identity_bool_int16 ( bool *Cx, // Cx and Ax may be aliased const int16_t *Ax, int64_t anz, int nthreads ) { #if GB_DISABLE return (GrB_NO_VALUE) ; #else int64_t p ; #pragma omp parallel for num_threads(nthreads) schedule(static) for (p = 0 ; p < anz ; p++) { int16_t aij = Ax [p] ; bool z = (bool) aij ; Cx [p] = z ; } return (GrB_SUCCESS) ; #endif } //------------------------------------------------------------------------------ // C = op (cast (A')): transpose, typecast, and apply a unary operator //------------------------------------------------------------------------------ GrB_Info GB_unop_tran__identity_bool_int16 ( GrB_Matrix C, const GrB_Matrix A, int64_t *GB_RESTRICT *Rowcounts, GBI_single_iterator Iter, const int64_t *GB_RESTRICT A_slice, int naslice ) { #if GB_DISABLE return (GrB_NO_VALUE) ; #else #define GB_PHASE_2_OF_2 #include "GB_unop_transpose.c" return (GrB_SUCCESS) ; #endif } #endif
pi_integration_omp.c
#include <stdio.h> #include <stdlib.h> #include <omp.h> int main (int argc, char *argv[]) { int i,num_steps; double x, sum, step, pi; double t_start, t_end; num_steps=500000000; x=0; sum = 0.0; step = 1.0/(double) num_steps; t_start = omp_get_wtime(); #pragma omp parallel for reduction(+:sum) default(none) private(i,x) firstprivate(step, num_steps) for (i=0; i < num_steps; i++) { x = (i+0.5)*step; sum = sum + 4.0/(1.0+x*x); } pi = step * sum; t_end = omp_get_wtime(); printf("Value of pi = %g\n",pi); printf("Expended wall clock time = %.20f\n", t_end - t_start); printf("num proc = %d\n", omp_get_num_procs()); return EXIT_SUCCESS; }
GB_convert_hyper_to_sparse.c
//------------------------------------------------------------------------------ // GB_convert_hyper_to_sparse: convert a matrix from hypersparse to sparse //------------------------------------------------------------------------------ // SuiteSparse:GraphBLAS, Timothy A. Davis, (c) 2017-2022, All Rights Reserved. // SPDX-License-Identifier: Apache-2.0 //------------------------------------------------------------------------------ // On input, the matrix may have shallow A->p and A->h content; it is safely // removed. On output, the matrix is always non-hypersparse (even if out of // memory). If the input matrix is hypersparse, it is given a new A->p that is // not shallow. If the input matrix is already non-hypersparse, nothing is // changed (and in that case A->p remains shallow on output if shallow on // input). The A->x and A->i content is not changed; it remains in whatever // shallow/non-shallow/iso property that it had on input). // If an out-of-memory condition occurs, all content of the matrix is cleared. // If the input matrix A is sparse, bitmap or full, it is unchanged. #include "GB.h" GB_PUBLIC GrB_Info GB_convert_hyper_to_sparse // convert hypersparse to sparse ( GrB_Matrix A, // matrix to convert to non-hypersparse GB_Context Context ) { //-------------------------------------------------------------------------- // check inputs //-------------------------------------------------------------------------- ASSERT_MATRIX_OK (A, "A being converted from hyper to sparse", GB0) ; ASSERT (GB_ZOMBIES_OK (A)) ; ASSERT (GB_JUMBLED_OK (A)) ; ASSERT (GB_PENDING_OK (A)) ; //-------------------------------------------------------------------------- // convert A from hypersparse to sparse //-------------------------------------------------------------------------- if (GB_IS_HYPERSPARSE (A)) { //---------------------------------------------------------------------- // determine the number of threads to use //---------------------------------------------------------------------- GBURBLE ("(hyper to sparse) ") ; int64_t n = A->vdim ; GB_GET_NTHREADS_MAX (nthreads_max, chunk, Context) ; int nthreads = GB_nthreads (n, chunk, nthreads_max) ; int ntasks = (nthreads == 1) ? 1 : (8 * nthreads) ; ntasks = GB_IMIN (ntasks, n) ; ntasks = GB_IMAX (ntasks, 1) ; //---------------------------------------------------------------------- // allocate the new Ap array, of size n+1 //---------------------------------------------------------------------- int64_t *restrict Ap_new = NULL ; size_t Ap_new_size = 0 ; Ap_new = GB_MALLOC (n+1, int64_t, &Ap_new_size) ; if (Ap_new == NULL) { // out of memory return (GrB_OUT_OF_MEMORY) ; } #ifdef GB_DEBUG // to ensure all values of Ap_new are assigned below. for (int64_t j = 0 ; j <= n ; j++) Ap_new [j] = -99999 ; #endif //---------------------------------------------------------------------- // get the old hyperlist //---------------------------------------------------------------------- int64_t nvec = A->nvec ; // # of vectors in Ah_old int64_t *restrict Ap_old = A->p ; // size nvec+1 int64_t *restrict Ah_old = A->h ; // size nvec int64_t nvec_nonempty = 0 ; // recompute A->nvec_nonempty int64_t anz = GB_nnz (A) ; //---------------------------------------------------------------------- // construct the new vector pointers //---------------------------------------------------------------------- int tid ; #pragma omp parallel for num_threads(nthreads) schedule(dynamic,1) \ reduction(+:nvec_nonempty) for (tid = 0 ; tid < ntasks ; tid++) { int64_t jstart, jend, my_nvec_nonempty = 0 ; GB_PARTITION (jstart, jend, n, tid, ntasks) ; ASSERT (0 <= jstart && jstart <= jend && jend <= n) ; // task tid computes Ap_new [jstart:jend-1] from Ap_old, Ah_old. // GB_SPLIT_BINARY_SEARCH of Ah_old [0..nvec-1] for jstart: // If found is true then Ah_old [k] == jstart. // If found is false, and nvec > 0 then // Ah_old [0 ... k-1] < jstart < Ah_old [k ... nvec-1] // Whether or not i is found, if nvec > 0 // Ah_old [0 ... k-1] < jstart <= Ah_old [k ... nvec-1] // If nvec == 0, then k == 0 and found will be false. In this // case, jstart cannot be compared with any content of Ah_old, // since Ah_old is completely empty (Ah_old [0] is invalid). int64_t k = 0, pright = nvec-1 ; bool found ; GB_SPLIT_BINARY_SEARCH (jstart, Ah_old, k, pright, found) ; ASSERT (k >= 0 && k <= nvec) ; ASSERT (GB_IMPLIES (nvec == 0, !found && k == 0)) ; ASSERT (GB_IMPLIES (found, jstart == Ah_old [k])) ; ASSERT (GB_IMPLIES (!found && k < nvec, jstart < Ah_old [k])) ; // Let jk = Ah_old [k], jlast = Ah_old [k-1], and pk = Ah_old [k]. // Then Ap_new [jlast+1:jk] must be set to pk. This must be done // for all k = 0:nvec-1. In addition, the last vector k=nvec-1 // must be terminated by setting Ap_new [jk+1:n-1] to Ap_old [nvec]. // A task owns the kth vector if jk is in jstart:jend-1, inclusive. // It counts all non-empty vectors that it owns. However, the task // must also set Ap_new [...] = pk for any jlast+1:jk that overlaps // jstart:jend-1, even if it does not own that particular vector k. // This happens only at the tail end of jstart:jend-1. int64_t jlast = (k == 0) ? (-1) : Ah_old [k-1] ; jlast = GB_IMAX (jstart-1, jlast) ; bool done = false ; for ( ; k <= nvec && !done ; k++) { //-------------------------------------------------------------- // get the kth vector in Ah_old, which is vector index jk. //-------------------------------------------------------------- int64_t jk = (k < nvec) ? Ah_old [k] : n ; int64_t pk = (k < nvec) ? Ap_old [k] : anz ; //-------------------------------------------------------------- // determine if this task owns jk //-------------------------------------------------------------- int64_t jfin ; if (jk >= jend) { // This is the last iteration for this task. This task // does not own the kth vector. However, it does own the // vector indices jlast+1:jend-1, and these vectors must // be handled by this task. jfin = jend - 1 ; done = true ; } else { // This task owns the kth vector, which is vector index jk. // Ap must be set to pk for all vector indices jlast+1:jk. jfin = jk ; ASSERT (k >= 0 && k < nvec && nvec > 0) ; if (pk < Ap_old [k+1]) my_nvec_nonempty++ ; } //-------------------------------------------------------------- // set Ap_new for this vector //-------------------------------------------------------------- // Ap_new [jlast+1:jk] must be set to pk. This tasks handles // the intersection of jlast+1:jk with jstart:jend-1. for (int64_t j = jlast+1 ; j <= jfin ; j++) { Ap_new [j] = pk ; } //-------------------------------------------------------------- // keep track of the prior vector index //-------------------------------------------------------------- jlast = jk ; } nvec_nonempty += my_nvec_nonempty ; //------------------------------------------------------------------ // no task owns Ap_new [n] so it is set by the last task //------------------------------------------------------------------ if (tid == ntasks-1) { ASSERT (jend == n) ; Ap_new [n] = anz ; } } // free the old A->p and A->h hyperlist content. // this clears A->nvec_nonempty so it must be restored below. GB_ph_free (A) ; // transplant the new vector pointers; matrix is no longer hypersparse A->p = Ap_new ; A->p_size = Ap_new_size ; A->h = NULL ; A->nvec = n ; A->nvec_nonempty = nvec_nonempty ; A->plen = n ; A->p_shallow = false ; A->h_shallow = false ; A->magic = GB_MAGIC ; ASSERT (anz == GB_nnz (A)) ; //---------------------------------------------------------------------- // A is now sparse //---------------------------------------------------------------------- ASSERT (GB_IS_SPARSE (A)) ; } //-------------------------------------------------------------------------- // A is now in sparse form (or left as full or bitmap) //-------------------------------------------------------------------------- ASSERT_MATRIX_OK (A, "A converted to sparse (or left as-is)", GB0) ; ASSERT (!GB_IS_HYPERSPARSE (A)) ; ASSERT (GB_ZOMBIES_OK (A)) ; ASSERT (GB_JUMBLED_OK (A)) ; ASSERT (GB_PENDING_OK (A)) ; return (GrB_SUCCESS) ; }
i420.c
/* * Colorspace converter (i420 -> RGB) * * Copyright (C) 2019 Hiroshi Kuwagata <kgt9221@gmail.com> */ #include <stdio.h> #include <stdlib.h> #include <stdint.h> #include <string.h> #ifdef _OPENMP #include <omp.h> #endif /* defined(_OPENMP) */ #ifdef ENABLE_NEON #include "neon.h" #endif /* defined(ENABLE_NEON) */ #ifdef ENABLE_AVX #include "avx.h" #endif /* defined(ENABLE_AVX) */ #include "i420.h" #define ALLOC(t) ((t*)malloc(sizeof(t))) #define CLIP(v) (((v) < 0)? 0: ((v) > 255)? 255: (v)) #define DEFAULT_ERROR __LINE__ int i420_new(i420_t** dst) { int ret; i420_t* obj; /* * initialize */ ret = 0; obj = NULL; /* * argument check */ if (dst == NULL) { ret = DEFAULT_ERROR; } /* * alloc memory */ if (!ret) { obj = ALLOC(i420_t); if (obj == NULL) ret = DEFAULT_ERROR; } /* * put return parameter */ if (!ret) { obj->width = -1; obj->height = -1; obj->stride = -1; obj->size = -1; obj->plane = NULL; obj->y_stride = -1; obj->uv_stride = -1; *dst = obj; } /* * post process */ if (ret) { if (obj) free(obj); } return ret; } int i420_destroy(i420_t* ptr) { int ret; /* * initialize */ ret = 0; /* * argument check */ if (ptr == NULL) { ret = DEFAULT_ERROR; } /* * release memory */ if (!ret) { if (ptr->plane) free(ptr->plane); free(ptr); } return ret; } int i420_update(i420_t* ptr, int width, int height, int y_stride, int uv_stride) { int ret; int size; void* plane; /* * initialize */ ret = 0; plane = NULL; /* * argument check */ do { if (ptr == NULL) { ret = DEFAULT_ERROR; break; } if (width <= 0 || width & 1) { ret = DEFAULT_ERROR; break; } if (height <= 0 || height & 1) { ret = DEFAULT_ERROR; break; } if (y_stride < width ) { ret = DEFAULT_ERROR; break; } if (uv_stride < (width / 2)) { ret = DEFAULT_ERROR; break; } } while(0); /* * alloc memory */ if (!ret) { size = width * height * 3; if (ptr->size == size) { plane = ptr->plane; } else { plane = (ptr->plane == NULL)? malloc(size): realloc(ptr->plane, size); if (plane == NULL) ret = DEFAULT_ERROR; } } /* * update context */ if (!ret) { ptr->width = width; ptr->height = height; ptr->stride = width * 3; ptr->size = size; ptr->plane = plane; ptr->y_stride = y_stride; ptr->uv_stride = uv_stride; } /* * post process */ if (ret) { if (plane) free(plane); } return ret; } #if defined(ENABLE_NEON) int i420_conv(i420_t* ptr, uint8_t* src_y, uint8_t* src_u, uint8_t* src_v) { int ret; int i; int j; /* * initialize */ ret = 0; /* * argument check */ do { if (ptr == NULL) { ret = DEFAULT_ERROR; break; } if (src_y == NULL) { ret = DEFAULT_ERROR; break; } if (src_u == NULL) { ret = DEFAULT_ERROR; break; } if (src_v == NULL) { ret = DEFAULT_ERROR; break; } } while (0); /* * do convert * * 2x2ピクセルを1ユニットとして処理。ピクセルに対するレーン配置は以下の通り * * 0 1 * 2 3 * * YUVからRGBへの変換式は以下の通り * * R = (1.164f * (y - 16)) + (1.596f * (v - 128)) * G = (1.164f * (y - 16)) - (0.813f * (v - 128)) - (0.391f * (u - 128)) * B = (1.164f * (y - 16)) + (2.018f * (u - 128)) * * 上記を、整数演算化による高速化を狙って以下の様に実装する。 * * R = ((1192 * (y - 16)) + (1634 * (v - 128))) >> 10 * G = ((1192 * (y - 16)) - ( 833 * (v - 128)) - (400 * (u - 128))) >> 10 * B = ((1192 * (y - 16)) + (2066 * (u - 128))) >> 10 */ if (!ret) { #if defined(_OPENMP) && defined(NUM_THREADS) omp_set_num_threads(NUM_THREADS); #endif /* defined(_OPENMP) && defined(NUM_THREADS) */ #pragma omp parallel private(j) shared(ptr,src_y,src_u,src_v) { int32x4_t c16 = vmovq_n_s32(16); int32x4_t c0 = vmovq_n_s32(0); int32x4_t c255 = vmovq_n_s32(255); uint8_t* d1; uint8_t* d2; uint8_t* yp1; uint8_t* yp2; uint8_t* up; uint8_t* vp; int32x4_t vy; int32x4_t vu; int32x4_t vv; int32x4_t vr; int32x4_t vg; int32x4_t vb; #pragma omp for for (i = 0; i < ptr->height; i += 2) { d1 = (uint8_t*)ptr->plane + (i * ptr->stride); d2 = d1 + ptr->stride; yp1 = src_y + (i * ptr->y_stride); yp2 = yp1 + ptr->y_stride; up = src_u + ((i / 2) * ptr->uv_stride); vp = src_v + ((i / 2) * ptr->uv_stride); for (j = 0; j < ptr->width; j += 2) { /* * Y */ vy = vsetq_lane_s32(yp1[0], vy, 0); vy = vsetq_lane_s32(yp1[1], vy, 1); vy = vsetq_lane_s32(yp2[0], vy, 2); vy = vsetq_lane_s32(yp2[1], vy, 3); vy = vsubq_s32(vy, c16); vy = vmulq_n_s32(vy, 1192); /* * U */ vu = vmovq_n_s32(up[0] - 128); /* * V */ vv = vmovq_n_s32(vp[0] - 128); /* * B */ vb = vmlaq_n_s32(vy, vu, 2066); vb = vshrq_n_s32(vb, 10); vb = vmaxq_s32(vb, c0); vb = vminq_s32(vb, c255); /* * R */ vr = vmlaq_n_s32(vy, vv, 1634); vr = vshrq_n_s32(vr, 10); vr = vmaxq_s32(vr, c0); vr = vminq_s32(vr, c255); /* * G */ vg = vmlsq_n_s32(vg, vv, 833); vg = vmlsq_n_s32(vy, vu, 400); vg = vshrq_n_s32(vg, 10); vg = vmaxq_s32(vg, c0); vg = vminq_s32(vg, c255); /* * store result */ d1[0] = vgetq_lane_s32(vr, 0); d1[1] = vgetq_lane_s32(vg, 0); d1[2] = vgetq_lane_s32(vb, 0); d1[3] = vgetq_lane_s32(vr, 1); d1[4] = vgetq_lane_s32(vg, 1); d1[5] = vgetq_lane_s32(vb, 1); d2[0] = vgetq_lane_s32(vr, 2); d2[1] = vgetq_lane_s32(vg, 2); d2[2] = vgetq_lane_s32(vb, 2); d2[3] = vgetq_lane_s32(vr, 3); d2[4] = vgetq_lane_s32(vg, 3); d2[5] = vgetq_lane_s32(vb, 3); /* * update pointer */ yp1 += 2; yp2 += 2; up += 1; vp += 1; d1 += 6; d2 += 6; } } } } return ret; } #elif defined(ENABLE_AVX) int i420_conv(i420_t* ptr, uint8_t* src_y, uint8_t* src_u, uint8_t* src_v) { int ret; int i; int j; int k; /* * initialize */ ret = 0; /* * argument check */ do { if (ptr == NULL) { ret = DEFAULT_ERROR; break; } if (src_y == NULL) { ret = DEFAULT_ERROR; break; } if (src_u == NULL) { ret = DEFAULT_ERROR; break; } if (src_v == NULL) { ret = DEFAULT_ERROR; break; } } while (0); /* * do convert * * 4x2ピクセルを1ユニットとして処理。ピクセルに対するレーン配置は以下の通り * * 0 1 2 3 * 4 5 6 7 * * YUVからRGBへの変換式は以下の通り * * R = (1.164f * (y - 16)) + (1.596f * (v - 128)) * G = (1.164f * (y - 16)) - (0.813f * (v - 128)) - (0.391f * (u - 128)) * B = (1.164f * (y - 16)) + (2.018f * (u - 128)) * * 上記を、整数演算化による高速化を狙って以下の様に実装する。 * * R = ((1192 * (y - 16)) + (1634 * (v - 128))) >> 10 * G = ((1192 * (y - 16)) - ( 833 * (v - 128)) - (400 * (u - 128))) >> 10 * B = ((1192 * (y - 16)) + (2066 * (u - 128))) >> 10 */ if (!ret) { #if defined(_OPENMP) && defined(NUM_THREADS) omp_set_num_threads(NUM_THREADS); #endif /* defined(_OPENMP) && defined(NUM_THREADS) */ #pragma omp parallel private(j,k) shared(ptr,src_y,src_u,src_v) { __m256i c16 = _mm256_set1_epi32(16); __m256i c128 = _mm256_set1_epi32(128); __m256i c1192 = _mm256_set1_epi32(1192); __m256i c400 = _mm256_set1_epi32(400); __m256i c2066 = _mm256_set1_epi32(2066); __m256i c1634 = _mm256_set1_epi32(1634); __m256i c833 = _mm256_set1_epi32(833); uint8_t* d1; // destination pointer for even line uint8_t* d2; // destination pointer for odd line uint8_t* yp1; // y-plane pointer for even line uint8_t* yp2; // y-plane pointer for odd line uint8_t* up; // u-plane pointer uint8_t* vp; // v-plane pointer __m256i vy; __m256i vu; __m256i vv; __m256i vr; __m256i vg; __m256i vb; #pragma omp for for (i = 0; i < ptr->height; i += 2) { d1 = (uint8_t*)ptr->plane + (i * ptr->stride); d2 = d1 + ptr->stride; yp1 = src_y + (i * ptr->y_stride); yp2 = yp1 + ptr->y_stride; up = src_u + ((i / 2) * ptr->uv_stride); vp = src_v + ((i / 2) * ptr->uv_stride); for (j = 0; j < ptr->width; j += 4) { /* * 飽和演算はストア時のパック処理で併せて行っているので注意。 */ /* * Y */ vy = _mm256_set_epi32(yp2[3], yp2[2], yp2[1], yp2[0], yp1[3], yp1[2], yp1[1], yp1[0]); vy = _mm256_sub_epi32(vy, c16); vy = _mm256_mullo_epi32(vy, c1192); /* * U */ vu = _mm256_set_epi32(up[1], up[1], up[0], up[0], up[1], up[1], up[0], up[0]); vu = _mm256_sub_epi32(vu, c128); /* * V */ vv = _mm256_set_epi32(vp[1], vp[1], vp[0], vp[0], vp[1], vp[1], vp[0], vp[0]); vv = _mm256_sub_epi32(vv, c128); /* * B */ vb = _mm256_mullo_epi32(vu, c2066); vb = _mm256_add_epi32(vy, vb); vb = _mm256_srai_epi32(vb, 10); /* * R */ vr = _mm256_mullo_epi32(vv, c1634); vr = _mm256_add_epi32(vy, vr); vr = _mm256_srai_epi32(vr, 10); /* * G */ vu = _mm256_mullo_epi32(vu, c400); vv = _mm256_mullo_epi32(vv, c833); vg = _mm256_sub_epi32(vy, vv); vg = _mm256_sub_epi32(vg, vu); vg = _mm256_srai_epi32(vg, 10); /* * store result */ { alignas(32) union { __m256i ymm; uint8_t u8[32]; } buf; /* * vr: * 0 16 * +--+--+--+--+--+--+--+--+ * |R7|R6|R5|R4|R3|R2|R1|R0| * +--+--+--+--+--+--+--+--+ * ※1単位 1byte(8bit) * * vg: * 0 16 * +--+--+--+--+--+--+--+--+ * |G7|G6|G5|G4|G3|G2|G1|G0| * +--+--+--+--+--+--+--+--+ * ※1単位 1byte(8bit) * * | * V * * vr: * 0 8 16 24 * +--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+ * |G7|G6|G5|G4|R7|R6|R5|R4|G3|G2|G1|G0|R3|R2|R1|R0| * +--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+ * ※1単位 1byte(8bit) */ vr = _mm256_packs_epi32(vr, vg); /* * vb: * 0 16 * +--+--+--+--+--+--+--+--+ * |B7|B6|B5|B4|B3|B2|B1|B0| * +--+--+--+--+--+--+--+--+ * ※1単位 1byte(8bit) * * vb: * 0 16 * +--+--+--+--+--+--+--+--+ * |B7|B6|B5|B4|B3|B2|B1|B0| * +--+--+--+--+--+--+--+--+ * ※1単位 1byte(8bit) * * | * V * * vb: * 0 8 16 24 * +--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+ * |B7|B6|B5|B4|B7|B6|B5|B4|B3|B2|B1|B0|B3|B2|B1|B0| * +--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+ * ※1単位 1byte(8bit) */ vb = _mm256_packs_epi32(vb, vb); /* * vr: * 0 8 16 24 * +--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+ * |G7|G6|G5|G4|R7|R6|R5|R4|G3|G2|G1|G0|R3|R2|R1|R0| * +--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+ * ※1単位 1byte(8bit) * * vb: * 0 8 16 24 * +--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+ * |B7|B6|B5|B4|B7|B6|B5|B4|B3|B2|B1|B0|B3|B2|B1|B0| * +--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+ * ※1単位 1byte(8bit) * * | * V * * vr: * 0 4 8 12 * +--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+ * |B7|B6|B5|B4|B7|B6|B5|B4|G7|G6|G5|G4|R7|R6|R5|R4| * +--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+ * |B3|B2|B1|B0|B3|B2|B1|B0|G3|G2|G1|G0|R3|R2|R1|R0| * +--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+ * ※1単位 1byte(8bit) */ vr = _mm256_packus_epi16(vr, vb); /* * store * * ymm: * 0 4 8 12 * +--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+ * |B7|B6|B5|B4|B7|B6|B5|B4|G7|G6|G5|G4|R7|R6|R5|R4| * +--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+ * |B3|B2|B1|B0|B3|B2|B1|B0|G3|G2|G1|G0|R3|R2|R1|R0| * +--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+ * ※1単位 1byte(8bit) * * | (64bit単位のリトルエンディアンなので、 * | メモリイメージは64bit単位で反転) * V * * mem: * 0 4 8 12 * +--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+ * |R4|R5|R6|R7|G4|G5|G6|G7|B4|B5|B6|B7|B4|B5|B6|B7| * +--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+ * |R0|R1|R2|R3|G0|G1|G2|G3|B0|B1|B2|B3|B0|B1|B2|B3| * +--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+ * ※1単位 1byte(8bit) */ _mm256_store_si256(&buf.ymm, vr); for (k = 0; k < 4; k++) { d1[0] = buf.u8[k + 0]; d1[1] = buf.u8[k + 4]; d1[2] = buf.u8[k + 8]; d2[0] = buf.u8[k + 16]; d2[1] = buf.u8[k + 20]; d2[2] = buf.u8[k + 24]; d1 += 3; d2 += 3; } } /* * update pointer */ yp1 += 4; yp2 += 4; up += 2; vp += 2; } } } } return ret; } #else /* * */ int i420_conv(i420_t* ptr, uint8_t* src_y, uint8_t* src_u, uint8_t* src_v) { int ret; int i; int j; /* * initialize */ ret = 0; /* * argument check */ do { if (ptr == NULL) { ret = DEFAULT_ERROR; break; } if (src_y == NULL) { ret = DEFAULT_ERROR; break; } if (src_u == NULL) { ret = DEFAULT_ERROR; break; } if (src_v == NULL) { ret = DEFAULT_ERROR; break; } } while (0); /* * do convert */ if (!ret) { #ifdef NUM_THREADS omp_set_num_threads(NUM_THREADS); #endif /* defined(NUM_THREADS) */ #pragma omp parallel for private(j) for (i = 0; i < ptr->height; i += 2) { uint8_t* d1; // destination pointer for even line uint8_t* d2; // destination pointer for odd line uint8_t* yp1; // y-plane pointer for even line uint8_t* yp2; // y-plane pointer for odd line uint8_t* up; // u-plane pointer uint8_t* vp; // v-plane pointer d1 = (uint8_t*)ptr->plane + (i * ptr->stride); d2 = d1 + ptr->stride; yp1 = src_y + (i * ptr->y_stride); yp2 = yp1 + ptr->y_stride; up = src_u + ((i / 2) * ptr->uv_stride); vp = src_v + ((i / 2) * ptr->uv_stride); for (j = 0; j < ptr->width; j += 2) { int y; int u; int v; int r0; int g0; int b0; u = (int)*up - 128; v = (int)*vp - 128; r0 = (v * 1634); g0 = (v * 833) + (u * 400); b0 = (u * 2066); /* [0,0] */ y = ((int)yp1[0] - 16) * 1192; *d1++ = CLIP((y + r0) >> 10); *d1++ = CLIP((y - g0) >> 10); *d1++ = CLIP((y + b0) >> 10); /* [0,1] */ y = ((int)yp2[0] - 16) * 1192; *d2++ = CLIP((y + r0) >> 10); *d2++ = CLIP((y - g0) >> 10); *d2++ = CLIP((y + b0) >> 10); /* [1,0] */ y = ((int)yp1[1] - 16) * 1192; *d1++ = CLIP((y + r0) >> 10); *d1++ = CLIP((y - g0) >> 10); *d1++ = CLIP((y + b0) >> 10); /* [1,1] */ y = ((int)yp2[1] - 16) * 1192; *d2++ = CLIP((y + r0) >> 10); *d2++ = CLIP((y - g0) >> 10); *d2++ = CLIP((y + b0) >> 10); yp1 += 2; yp2 += 2; up++; vp++; } } } return ret; } #endif /* * */
owl_slicing_basic_impl_omp.h
/* * OWL - OCaml Scientific Computing * Copyright (c) 2016-2022 Liang Wang <liang@ocaml.xyz> */ #ifdef OWL_ENABLE_TEMPLATE // Level 1 optimisation void FUNCTION (c, slice_1) (struct slice_pair *p) { TYPE *x = (TYPE *) p->x; TYPE *y = (TYPE *) p->y; int64_t d = p->dim - 1; int64_t n = p->n[d]; int64_t posx = p->posx + p->ofsx[d]; int64_t posy = p->posy + p->ofsy[d]; int64_t incx = p->incx[d]; int64_t incy = p->incy[d]; for (int64_t i = 0; i < n; i++) { MAPFUN (*(x + posx), *(y + posy)); posx += incx; posy += incy; } } // Level 2 optimisation void FUNCTION (c, slice_2) (struct slice_pair *p) { TYPE *x = (TYPE *) p->x; TYPE *y = (TYPE *) p->y; int64_t d0 = p->dim - 2; int64_t d1 = p->dim - 1; int64_t n0 = p->n[d0]; int64_t n1 = p->n[d1]; int64_t ofsx0 = p->ofsx[d0]; int64_t ofsy0 = p->ofsy[d0]; int64_t incx0 = p->incx[d0]; int64_t incy0 = p->incy[d0]; int64_t ofsx1 = p->ofsx[d1]; int64_t ofsy1 = p->ofsy[d1]; int64_t incx1 = p->incx[d1]; int64_t incy1 = p->incy[d1]; int64_t posx0 = p->posx + ofsx0; int64_t posy0 = p->posy + ofsy0; #pragma omp parallel for schedule(static) for (int64_t i0 = 0; i0 < n0; i0++) { int64_t posx1 = posx0 + ofsx1 + i0 * incx0; int64_t posy1 = posy0 + ofsy1 + i0 * incy0; for (int64_t i1 = 0; i1 < n1; i1++) { MAPFUN (*(x + posx1), *(y + posy1)); posx1 += incx1; posy1 += incy1; } } } // Level 3 optimisation void FUNCTION (c, slice_3) (struct slice_pair *p) { TYPE *x = (TYPE *) p->x; TYPE *y = (TYPE *) p->y; int64_t d0 = p->dim - 3; int64_t d1 = p->dim - 2; int64_t d2 = p->dim - 1; int64_t n0 = p->n[d0]; int64_t n1 = p->n[d1]; int64_t n2 = p->n[d2]; int64_t ofsx0 = p->ofsx[d0]; int64_t ofsy0 = p->ofsy[d0]; int64_t incx0 = p->incx[d0]; int64_t incy0 = p->incy[d0]; int64_t ofsx1 = p->ofsx[d1]; int64_t ofsy1 = p->ofsy[d1]; int64_t incx1 = p->incx[d1]; int64_t incy1 = p->incy[d1]; int64_t ofsx2 = p->ofsx[d2]; int64_t ofsy2 = p->ofsy[d2]; int64_t incx2 = p->incx[d2]; int64_t incy2 = p->incy[d2]; int64_t posx0 = p->posx + ofsx0; int64_t posy0 = p->posy + ofsy0; #pragma omp parallel for schedule(static) for (int64_t i0 = 0; i0 < n0; i0++) { int64_t posx1 = posx0 + ofsx1 + i0 * incx0; int64_t posy1 = posy0 + ofsy1 + i0 * incy0; for (int64_t i1 = 0; i1 < n1; i1++) { int64_t posx2 = posx1 + ofsx2; int64_t posy2 = posy1 + ofsy2; for (int64_t i2 = 0; i2 < n2; i2++) { MAPFUN (*(x + posx2), *(y + posy2)); posx2 += incx2; posy2 += incy2; } posx1 += incx1; posy1 += incy1; } } } // Level 4 optimisation void FUNCTION (c, slice_4) (struct slice_pair *p) { TYPE *x = (TYPE *) p->x; TYPE *y = (TYPE *) p->y; int64_t d0 = p->dim - 4; int64_t d1 = p->dim - 3; int64_t d2 = p->dim - 2; int64_t d3 = p->dim - 1; int64_t n0 = p->n[d0]; int64_t n1 = p->n[d1]; int64_t n2 = p->n[d2]; int64_t n3 = p->n[d3]; int64_t ofsx0 = p->ofsx[d0]; int64_t ofsy0 = p->ofsy[d0]; int64_t incx0 = p->incx[d0]; int64_t incy0 = p->incy[d0]; int64_t ofsx1 = p->ofsx[d1]; int64_t ofsy1 = p->ofsy[d1]; int64_t incx1 = p->incx[d1]; int64_t incy1 = p->incy[d1]; int64_t ofsx2 = p->ofsx[d2]; int64_t ofsy2 = p->ofsy[d2]; int64_t incx2 = p->incx[d2]; int64_t incy2 = p->incy[d2]; int64_t ofsx3 = p->ofsx[d3]; int64_t ofsy3 = p->ofsy[d3]; int64_t incx3 = p->incx[d3]; int64_t incy3 = p->incy[d3]; int64_t posx0 = p->posx + ofsx0; int64_t posy0 = p->posy + ofsy0; #pragma omp parallel for schedule(static) for (int64_t i0 = 0; i0 < n0; i0++) { int64_t posx1 = posx0 + ofsx1 + i0 * incx0; int64_t posy1 = posy0 + ofsy1 + i0 * incy0; for (int64_t i1 = 0; i1 < n1; i1++) { int64_t posx2 = posx1 + ofsx2; int64_t posy2 = posy1 + ofsy2; for (int64_t i2 = 0; i2 < n2; i2++) { int64_t posx3 = posx2 + ofsx3; int64_t posy3 = posy2 + ofsy3; for (int64_t i3 = 0; i3 < n3; i3++) { MAPFUN (*(x + posx3), *(y + posy3)); posx3 += incx3; posy3 += incy3; } posx2 += incx2; posy2 += incy2; } posx1 += incx1; posy1 += incy1; } } } // slice x based on the basic slice definition and save to y. void FUNCTION (c, slice) (struct slice_pair *p) { if (p->dep == p->dim - 1) FUNCTION (c, slice_1) (p); else if (p->dep == p->dim - 2) FUNCTION (c, slice_2) (p); else if (p->dep == p->dim - 3) FUNCTION (c, slice_3) (p); else if (p->dep == p->dim - 4) FUNCTION (c, slice_4) (p); else { const int64_t d = p->dep; const int64_t n = p->n[d]; const int64_t incx = p->incx[d]; const int64_t incy = p->incy[d]; const int64_t save_posx = p->posx; const int64_t save_posy = p->posy; p->posx += p->ofsx[d]; p->posy += p->ofsy[d]; for (int64_t i = 0; i < n; i++) { p->dep += 1; FUNCTION (c, slice) (p); p->dep -= 1; p->posx += incx; p->posy += incy; } p->posx = save_posx; p->posy = save_posy; } } // stub function CAMLprim value FUNCTION (stub, slice) (value vX, value vY, value vZ) { struct caml_ba_array *X = Caml_ba_array_val(vX); TYPE *X_data = (TYPE *) X->data; struct caml_ba_array *Y = Caml_ba_array_val(vY); TYPE *Y_data = (TYPE *) Y->data; struct caml_ba_array *Z = Caml_ba_array_val(vZ); int64_t *slice = (int64_t *) Z->data; struct slice_pair * sp = calloc(1, sizeof(struct slice_pair)); sp->dim = X->num_dims; sp->dep = 0; sp->n = Y->dim; sp->x = X_data; sp->y = Y_data; sp->posx = 0; sp->posy = 0; sp->ofsx = calloc(sp->dim, sizeof(int64_t)); sp->ofsy = calloc(sp->dim, sizeof(int64_t)); sp->incx = calloc(sp->dim, sizeof(int64_t)); sp->incy = calloc(sp->dim, sizeof(int64_t)); c_slicing_offset(X, slice, sp->ofsx); c_slicing_stride(X, slice, sp->incx); c_ndarray_stride(Y, sp->incy); FUNCTION (c, slice) (sp); free(sp->ofsx); free(sp->ofsy); free(sp->incx); free(sp->incy); free(sp); return Val_unit; } #endif /* OWL_ENABLE_TEMPLATE */
TGV_core.c
/* * This work is part of the Core Imaging Library developed by * Visual Analytics and Imaging System Group of the Science Technology * Facilities Council, STFC * * Copyright 2019 Daniil Kazantsev * Copyright 2019 Srikanth Nagella, Edoardo Pasca * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * http://www.apache.org/licenses/LICENSE-2.0 * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ #include "TGV_core.h" /* C-OMP implementation of Primal-Dual denoising method for * Total Generilized Variation (TGV)-L2 model [1] (2D/3D case) * * Input Parameters: * 1. Noisy image/volume (2D/3D) * 2. lambda - regularisation parameter * 3. parameter to control the first-order term (alpha1) * 4. parameter to control the second-order term (alpha0) * 5. Number of Chambolle-Pock (Primal-Dual) iterations * 6. Lipshitz constant (default is 12) * 7. eplsilon: tolerance constant * * Output: * [1] Filtered/regularized image/volume * [2] Information vector which contains [iteration no., reached tolerance] * * References: * [1] K. Bredies "Total Generalized Variation" * */ float TGV_main(float *U0, float *U, float *infovector, float lambda, float alpha1, float alpha0, int iter, float L2, float epsil, int dimX, int dimY, int dimZ) { long DimTotal; int ll, j; float re, re1; re = 0.0f; re1 = 0.0f; int count = 0; float *U_old, *P1, *P2, *Q1, *Q2, *Q3, *V1, *V1_old, *V2, *V2_old, tau, sigma; DimTotal = (long)(dimX*dimY*dimZ); copyIm(U0, U, (long)(dimX), (long)(dimY), (long)(dimZ)); /* initialize */ tau = pow(L2,-0.5); sigma = pow(L2,-0.5); /* dual variables */ P1 = calloc(DimTotal, sizeof(float)); P2 = calloc(DimTotal, sizeof(float)); Q1 = calloc(DimTotal, sizeof(float)); Q2 = calloc(DimTotal, sizeof(float)); Q3 = calloc(DimTotal, sizeof(float)); U_old = calloc(DimTotal, sizeof(float)); V1 = calloc(DimTotal, sizeof(float)); V1_old = calloc(DimTotal, sizeof(float)); V2 = calloc(DimTotal, sizeof(float)); V2_old = calloc(DimTotal, sizeof(float)); if (dimZ == 1) { /*2D case*/ /* Primal-dual iterations begin here */ for(ll = 0; ll < iter; ll++) { /* Calculate Dual Variable P */ DualP_2D(U, V1, V2, P1, P2, (long)(dimX), (long)(dimY), sigma); /*Projection onto convex set for P*/ ProjP_2D(P1, P2, (long)(dimX), (long)(dimY), alpha1); /* Calculate Dual Variable Q */ DualQ_2D(V1, V2, Q1, Q2, Q3, (long)(dimX), (long)(dimY), sigma); /*Projection onto convex set for Q*/ ProjQ_2D(Q1, Q2, Q3, (long)(dimX), (long)(dimY), alpha0); /*saving U into U_old*/ copyIm(U, U_old, (long)(dimX), (long)(dimY), 1l); /*adjoint operation -> divergence and projection of P*/ DivProjP_2D(U, U0, P1, P2, (long)(dimX), (long)(dimY), lambda, tau); /*get updated solution U*/ newU(U, U_old, (long)(dimX), (long)(dimY)); /*saving V into V_old*/ copyIm(V1, V1_old, (long)(dimX), (long)(dimY), 1l); copyIm(V2, V2_old, (long)(dimX), (long)(dimY), 1l); /* upd V*/ UpdV_2D(V1, V2, P1, P2, Q1, Q2, Q3, (long)(dimX), (long)(dimY), tau); /*get new V*/ newU(V1, V1_old, (long)(dimX), (long)(dimY)); newU(V2, V2_old, (long)(dimX), (long)(dimY)); /* check early stopping criteria */ if ((epsil != 0.0f) && (ll % 5 == 0)) { re = 0.0f; re1 = 0.0f; for(j=0; j<DimTotal; j++) { re += powf(U[j] - U_old[j],2); re1 += powf(U[j],2); } re = sqrtf(re)/sqrtf(re1); if (re < epsil) count++; if (count > 3) break; } } /*end of iterations*/ } else { /*3D case*/ float *P3, *Q4, *Q5, *Q6, *V3, *V3_old; P3 = calloc(DimTotal, sizeof(float)); Q4 = calloc(DimTotal, sizeof(float)); Q5 = calloc(DimTotal, sizeof(float)); Q6 = calloc(DimTotal, sizeof(float)); V3 = calloc(DimTotal, sizeof(float)); V3_old = calloc(DimTotal, sizeof(float)); /* Primal-dual iterations begin here */ for(ll = 0; ll < iter; ll++) { /* Calculate Dual Variable P */ DualP_3D(U, V1, V2, V3, P1, P2, P3, (long)(dimX), (long)(dimY), (long)(dimZ), sigma); /*Projection onto convex set for P*/ ProjP_3D(P1, P2, P3, (long)(dimX), (long)(dimY), (long)(dimZ), alpha1); /* Calculate Dual Variable Q */ DualQ_3D(V1, V2, V3, Q1, Q2, Q3, Q4, Q5, Q6, (long)(dimX), (long)(dimY), (long)(dimZ), sigma); /*Projection onto convex set for Q*/ ProjQ_3D(Q1, Q2, Q3, Q4, Q5, Q6, (long)(dimX), (long)(dimY), (long)(dimZ), alpha0); /*saving U into U_old*/ copyIm(U, U_old, (long)(dimX), (long)(dimY), (long)(dimZ)); /*adjoint operation -> divergence and projection of P*/ DivProjP_3D(U, U0, P1, P2, P3, (long)(dimX), (long)(dimY), (long)(dimZ), lambda, tau); /*get updated solution U*/ newU3D(U, U_old, (long)(dimX), (long)(dimY), (long)(dimZ)); /*saving V into V_old*/ copyIm_3Ar(V1, V2, V3, V1_old, V2_old, V3_old, (long)(dimX), (long)(dimY), (long)(dimZ)); /* upd V*/ UpdV_3D(V1, V2, V3, P1, P2, P3, Q1, Q2, Q3, Q4, Q5, Q6, (long)(dimX), (long)(dimY), (long)(dimZ), tau); /*get new V*/ newU3D_3Ar(V1, V2, V3, V1_old, V2_old, V3_old, (long)(dimX), (long)(dimY), (long)(dimZ)); /* check early stopping criteria */ if ((epsil != 0.0f) && (ll % 5 == 0)) { re = 0.0f; re1 = 0.0f; for(j=0; j<DimTotal; j++) { re += powf(U[j] - U_old[j],2); re1 += powf(U[j],2); } re = sqrtf(re)/sqrtf(re1); if (re < epsil) count++; if (count > 3) break; } } /*end of iterations*/ free(P3);free(Q4);free(Q5);free(Q6);free(V3);free(V3_old); } /*freeing*/ free(P1);free(P2);free(Q1);free(Q2);free(Q3);free(U_old); free(V1);free(V2);free(V1_old);free(V2_old); /*adding info into info_vector */ infovector[0] = (float)(ll); /*iterations number (if stopped earlier based on tolerance)*/ infovector[1] = re; /* reached tolerance */ return 0; } /********************************************************************/ /***************************2D Functions*****************************/ /********************************************************************/ /*Calculating dual variable P (using forward differences)*/ float DualP_2D(float *U, float *V1, float *V2, float *P1, float *P2, long dimX, long dimY, float sigma) { long i,j, index; #pragma omp parallel for shared(U,V1,V2,P1,P2) private(i,j,index) for(j=0; j<dimY; j++) { for(i=0; i<dimX; i++) { index = j*dimX+i; /* symmetric boundary conditions (Neuman) */ if (i == dimX-1) P1[index] += sigma*(-V1[index]); else P1[index] += sigma*((U[j*dimX+(i+1)] - U[index]) - V1[index]); if (j == dimY-1) P2[index] += sigma*(-V2[index]); else P2[index] += sigma*((U[(j+1)*dimX+i] - U[index]) - V2[index]); }} return 1; } /*Projection onto convex set for P*/ float ProjP_2D(float *P1, float *P2, long dimX, long dimY, float alpha1) { float grad_magn; long i,j,index; #pragma omp parallel for shared(P1,P2) private(i,j,index,grad_magn) for(j=0; j<dimY; j++) { for(i=0; i<dimX; i++) { index = j*dimX+i; grad_magn = (sqrtf(pow(P1[index],2) + pow(P2[index],2)))/alpha1; if (grad_magn > 1.0f) { P1[index] /= grad_magn; P2[index] /= grad_magn; } }} return 1; } /*Calculating dual variable Q (using forward differences)*/ float DualQ_2D(float *V1, float *V2, float *Q1, float *Q2, float *Q3, long dimX, long dimY, float sigma) { long i,j,index; float q1, q2, q11, q22; #pragma omp parallel for shared(Q1,Q2,Q3,V1,V2) private(i,j,index,q1,q2,q11,q22) for(j=0; j<dimY; j++) { for(i=0; i<dimX; i++) { index = j*dimX+i; q1 = 0.0f; q11 = 0.0f; q2 = 0.0f; q22 = 0.0f; /* boundary conditions (Neuman) */ if (i != dimX-1){ q1 = V1[j*dimX+(i+1)] - V1[index]; q11 = V2[j*dimX+(i+1)] - V2[index]; } if (j != dimY-1) { q2 = V2[(j+1)*dimX+i] - V2[index]; q22 = V1[(j+1)*dimX+i] - V1[index]; } Q1[index] += sigma*(q1); Q2[index] += sigma*(q2); Q3[index] += sigma*(0.5f*(q11 + q22)); }} return 1; } float ProjQ_2D(float *Q1, float *Q2, float *Q3, long dimX, long dimY, float alpha0) { float grad_magn; long i,j,index; #pragma omp parallel for shared(Q1,Q2,Q3) private(i,j,index,grad_magn) for(j=0; j<dimY; j++) { for(i=0; i<dimX; i++) { index = j*dimX+i; grad_magn = sqrtf(pow(Q1[index],2) + pow(Q2[index],2) + 2*pow(Q3[index],2)); grad_magn = grad_magn/alpha0; if (grad_magn > 1.0f) { Q1[index] /= grad_magn; Q2[index] /= grad_magn; Q3[index] /= grad_magn; } }} return 1; } /* Divergence and projection for P (backward differences)*/ float DivProjP_2D(float *U, float *U0, float *P1, float *P2, long dimX, long dimY, float lambda, float tau) { long i,j,index; float P_v1, P_v2, div; #pragma omp parallel for shared(U,U0,P1,P2) private(i,j,index,P_v1,P_v2,div) for(j=0; j<dimY; j++) { for(i=0; i<dimX; i++) { index = j*dimX+i; if (i == 0) P_v1 = P1[index]; else if (i == dimX-1) P_v1 = -P1[j*dimX+(i-1)]; else P_v1 = P1[index] - P1[j*dimX+(i-1)]; if (j == 0) P_v2 = P2[index]; else if (j == dimY-1) P_v2 = -P2[(j-1)*dimX+i]; else P_v2 = P2[index] - P2[(j-1)*dimX+i]; div = P_v1 + P_v2; U[index] = (lambda*(U[index] + tau*div) + tau*U0[index])/(lambda + tau); }} return *U; } /*get updated solution U*/ float newU(float *U, float *U_old, long dimX, long dimY) { long i; #pragma omp parallel for shared(U,U_old) private(i) for(i=0; i<dimX*dimY; i++) U[i] = 2*U[i] - U_old[i]; return *U; } /*get update for V (backward differences)*/ float UpdV_2D(float *V1, float *V2, float *P1, float *P2, float *Q1, float *Q2, float *Q3, long dimX, long dimY, float tau) { long i, j, index; float q1, q3_x, q3_y, q2, div1, div2; #pragma omp parallel for shared(V1,V2,P1,P2,Q1,Q2,Q3) private(i, j, index, q1, q3_x, q3_y, q2, div1, div2) for(j=0; j<dimY; j++) { for(i=0; i<dimX; i++) { index = j*dimX+i; /* boundary conditions (Neuman) */ if (i == 0) { q1 = Q1[index]; q3_x = Q3[index]; } else if (i == dimX-1) { q1 = -Q1[j*dimX+(i-1)]; q3_x = -Q3[j*dimX+(i-1)]; } else { q1 = Q1[index] - Q1[j*dimX+(i-1)]; q3_x = Q3[index] - Q3[j*dimX+(i-1)]; } if (j == 0) { q2 = Q2[index]; q3_y = Q3[index]; } else if (j == dimY-1) { q2 = -Q2[(j-1)*dimX+i]; q3_y = -Q3[(j-1)*dimX+i]; } else { q2 = Q2[index] - Q2[(j-1)*dimX+i]; q3_y = Q3[index] - Q3[(j-1)*dimX+i]; } div1 = q1 + q3_y; div2 = q3_x + q2; V1[index] += tau*(P1[index] + div1); V2[index] += tau*(P2[index] + div2); }} return 1; } /********************************************************************/ /***************************3D Functions*****************************/ /********************************************************************/ /*Calculating dual variable P (using forward differences)*/ float DualP_3D(float *U, float *V1, float *V2, float *V3, float *P1, float *P2, float *P3, long dimX, long dimY, long dimZ, float sigma) { long i,j,k, index; #pragma omp parallel for shared(U,V1,V2,V3,P1,P2,P3) private(i,j,k,index) for(k=0; k<dimZ; k++) { for(j=0; j<dimY; j++) { for(i=0; i<dimX; i++) { index = (dimX*dimY)*k + j*dimX+i; /* symmetric boundary conditions (Neuman) */ if (i == dimX-1) P1[index] += sigma*(-V1[index]); else P1[index] += sigma*((U[(dimX*dimY)*k + j*dimX+(i+1)] - U[index]) - V1[index]); if (j == dimY-1) P2[index] += sigma*(-V2[index]); else P2[index] += sigma*((U[(dimX*dimY)*k + (j+1)*dimX+i] - U[index]) - V2[index]); if (k == dimZ-1) P3[index] += sigma*(-V3[index]); else P3[index] += sigma*((U[(dimX*dimY)*(k+1) + j*dimX+i] - U[index]) - V3[index]); }}} return 1; } /*Projection onto convex set for P*/ float ProjP_3D(float *P1, float *P2, float *P3, long dimX, long dimY, long dimZ, float alpha1) { float grad_magn; long i,j,k,index; #pragma omp parallel for shared(P1,P2,P3) private(i,j,k,index,grad_magn) for(k=0; k<dimZ; k++) { for(j=0; j<dimY; j++) { for(i=0; i<dimX; i++) { index = (dimX*dimY)*k + j*dimX+i; grad_magn = (sqrtf(pow(P1[index],2) + pow(P2[index],2) + pow(P3[index],2)))/alpha1; if (grad_magn > 1.0f) { P1[index] /= grad_magn; P2[index] /= grad_magn; P3[index] /= grad_magn; } }}} return 1; } /*Calculating dual variable Q (using forward differences)*/ float DualQ_3D(float *V1, float *V2, float *V3, float *Q1, float *Q2, float *Q3, float *Q4, float *Q5, float *Q6, long dimX, long dimY, long dimZ, float sigma) { long i,j,k,index; float q1, q2, q3, q11, q22, q33, q44, q55, q66; #pragma omp parallel for shared(Q1,Q2,Q3,Q4,Q5,Q6,V1,V2,V3) private(i,j,k,index,q1,q2,q3,q11,q22,q33,q44,q55,q66) for(k=0; k<dimZ; k++) { for(j=0; j<dimY; j++) { for(i=0; i<dimX; i++) { index = (dimX*dimY)*k + j*dimX+i; q1 = 0.0f; q11 = 0.0f; q33 = 0.0f; q2 = 0.0f; q22 = 0.0f; q55 = 0.0f; q3 = 0.0f; q44 = 0.0f; q66 = 0.0f; /* symmetric boundary conditions (Neuman) */ if (i != dimX-1){ q1 = V1[(dimX*dimY)*k + j*dimX+(i+1)] - V1[index]; q11 = V2[(dimX*dimY)*k + j*dimX+(i+1)] - V2[index]; q33 = V3[(dimX*dimY)*k + j*dimX+(i+1)] - V3[index]; } if (j != dimY-1) { q2 = V2[(dimX*dimY)*k + (j+1)*dimX+i] - V2[index]; q22 = V1[(dimX*dimY)*k + (j+1)*dimX+i] - V1[index]; q55 = V3[(dimX*dimY)*k + (j+1)*dimX+i] - V3[index]; } if (k != dimZ-1) { q3 = V3[(dimX*dimY)*(k+1) + j*dimX+i] - V3[index]; q44 = V1[(dimX*dimY)*(k+1) + j*dimX+i] - V1[index]; q66 = V2[(dimX*dimY)*(k+1) + j*dimX+i] - V2[index]; } Q1[index] += sigma*(q1); /*Q11*/ Q2[index] += sigma*(q2); /*Q22*/ Q3[index] += sigma*(q3); /*Q33*/ Q4[index] += sigma*(0.5f*(q11 + q22)); /* Q21 / Q12 */ Q5[index] += sigma*(0.5f*(q33 + q44)); /* Q31 / Q13 */ Q6[index] += sigma*(0.5f*(q55 + q66)); /* Q32 / Q23 */ }}} return 1; } float ProjQ_3D(float *Q1, float *Q2, float *Q3, float *Q4, float *Q5, float *Q6, long dimX, long dimY, long dimZ, float alpha0) { float grad_magn; long i,j,k,index; #pragma omp parallel for shared(Q1,Q2,Q3,Q4,Q5,Q6) private(i,j,k,index,grad_magn) for(k=0; k<dimZ; k++) { for(j=0; j<dimY; j++) { for(i=0; i<dimX; i++) { index = (dimX*dimY)*k + j*dimX+i; grad_magn = sqrtf(pow(Q1[index],2) + pow(Q2[index],2) + pow(Q3[index],2) + 2.0f*pow(Q4[index],2) + 2.0f*pow(Q5[index],2) + 2.0f*pow(Q6[index],2)); grad_magn = grad_magn/alpha0; if (grad_magn > 1.0f) { Q1[index] /= grad_magn; Q2[index] /= grad_magn; Q3[index] /= grad_magn; Q4[index] /= grad_magn; Q5[index] /= grad_magn; Q6[index] /= grad_magn; } }}} return 1; } /* Divergence and projection for P*/ float DivProjP_3D(float *U, float *U0, float *P1, float *P2, float *P3, long dimX, long dimY, long dimZ, float lambda, float tau) { long i,j,k,index; float P_v1, P_v2, P_v3, div; #pragma omp parallel for shared(U,U0,P1,P2,P3) private(i,j,k,index,P_v1,P_v2,P_v3,div) for(k=0; k<dimZ; k++) { for(j=0; j<dimY; j++) { for(i=0; i<dimX; i++) { index = (dimX*dimY)*k + j*dimX+i; if (i == 0) P_v1 = P1[index]; else if (i == dimX-1) P_v1 = -P1[(dimX*dimY)*k + j*dimX+(i-1)]; else P_v1 = P1[index] - P1[(dimX*dimY)*k + j*dimX+(i-1)]; if (j == 0) P_v2 = P2[index]; else if (j == dimY-1) P_v2 = -P2[(dimX*dimY)*k + (j-1)*dimX+i]; else P_v2 = P2[index] - P2[(dimX*dimY)*k + (j-1)*dimX+i]; if (k == 0) P_v3 = P3[index]; else if (k == dimZ-1) P_v3 = -P3[(dimX*dimY)*(k-1) + (j)*dimX+i]; else P_v3 = P3[index] - P3[(dimX*dimY)*(k-1) + (j)*dimX+i]; div = P_v1 + P_v2 + P_v3; U[index] = (lambda*(U[index] + tau*div) + tau*U0[index])/(lambda + tau); }}} return *U; } /*get update for V*/ float UpdV_3D(float *V1, float *V2, float *V3, float *P1, float *P2, float *P3, float *Q1, float *Q2, float *Q3, float *Q4, float *Q5, float *Q6, long dimX, long dimY, long dimZ, float tau) { long i,j,k,index; float q1, q4x, q5x, q2, q4y, q6y, q6z, q5z, q3, div1, div2, div3; #pragma omp parallel for shared(V1,V2,V3,P1,P2,P3,Q1,Q2,Q3,Q4,Q5,Q6) private(i,j,k,index,q1,q4x,q5x,q2,q4y,q6y,q6z,q5z,q3,div1,div2,div3) for(k=0; k<dimZ; k++) { for(j=0; j<dimY; j++) { for(i=0; i<dimX; i++) { index = (dimX*dimY)*k + j*dimX+i; q1 = 0.0f; q4x= 0.0f; q5x= 0.0f; q2= 0.0f; q4y= 0.0f; q6y= 0.0f; q6z= 0.0f; q5z= 0.0f; q3= 0.0f; /* Q1 - Q11, Q2 - Q22, Q3 - Q33, Q4 - Q21/Q12, Q5 - Q31/Q13, Q6 - Q32/Q23*/ /* symmetric boundary conditions (Neuman) */ if (i == 0) { q1 = Q1[index]; q4x = Q4[index]; q5x = Q5[index]; } else if (i == dimX-1) { q1 = -Q1[(dimX*dimY)*k + j*dimX+(i-1)]; q4x = -Q4[(dimX*dimY)*k + j*dimX+(i-1)]; q5x = -Q5[(dimX*dimY)*k + j*dimX+(i-1)]; } else { q1 = Q1[index] - Q1[(dimX*dimY)*k + j*dimX+(i-1)]; q4x = Q4[index] - Q4[(dimX*dimY)*k + j*dimX+(i-1)]; q5x = Q5[index] - Q5[(dimX*dimY)*k + j*dimX+(i-1)]; } if (j == 0) { q2 = Q2[index]; q4y = Q4[index]; q6y = Q6[index]; } else if (j == dimY-1) { q2 = -Q2[(dimX*dimY)*k + (j-1)*dimX+i]; q4y = -Q4[(dimX*dimY)*k + (j-1)*dimX+i]; q6y = -Q6[(dimX*dimY)*k + (j-1)*dimX+i]; } else { q2 = Q2[index] - Q2[(dimX*dimY)*k + (j-1)*dimX+i]; q4y = Q4[index] - Q4[(dimX*dimY)*k + (j-1)*dimX+i]; q6y = Q6[index] - Q6[(dimX*dimY)*k + (j-1)*dimX+i]; } if (k == 0) { q6z = Q6[index]; q5z = Q5[index]; q3 = Q3[index]; } else if (k == dimZ-1) { q6z = -Q6[(dimX*dimY)*(k-1) + (j)*dimX+i]; q5z = -Q5[(dimX*dimY)*(k-1) + (j)*dimX+i]; q3 = -Q3[(dimX*dimY)*(k-1) + (j)*dimX+i]; } else { q6z = Q6[index] - Q6[(dimX*dimY)*(k-1) + (j)*dimX+i]; q5z = Q5[index] - Q5[(dimX*dimY)*(k-1) + (j)*dimX+i]; q3 = Q3[index] - Q3[(dimX*dimY)*(k-1) + (j)*dimX+i]; } div1 = q1 + q4y + q5z; div2 = q4x + q2 + q6z; div3 = q5x + q6y + q3; V1[index] += tau*(P1[index] + div1); V2[index] += tau*(P2[index] + div2); V3[index] += tau*(P3[index] + div3); }}} return 1; } float copyIm_3Ar(float *V1, float *V2, float *V3, float *V1_old, float *V2_old, float *V3_old, long dimX, long dimY, long dimZ) { long j; #pragma omp parallel for shared(V1, V2, V3, V1_old, V2_old, V3_old) private(j) for (j = 0; j<dimX*dimY*dimZ; j++) { V1_old[j] = V1[j]; V2_old[j] = V2[j]; V3_old[j] = V3[j]; } return 1; } /*get updated solution U*/ float newU3D(float *U, float *U_old, long dimX, long dimY, long dimZ) { long i; #pragma omp parallel for shared(U, U_old) private(i) for(i=0; i<dimX*dimY*dimZ; i++) U[i] = 2.0f*U[i] - U_old[i]; return *U; } /*get updated solution U*/ float newU3D_3Ar(float *V1, float *V2, float *V3, float *V1_old, float *V2_old, float *V3_old, long dimX, long dimY, long dimZ) { long i; #pragma omp parallel for shared(V1, V2, V3, V1_old, V2_old, V3_old) private(i) for(i=0; i<dimX*dimY*dimZ; i++) { V1[i] = 2.0f*V1[i] - V1_old[i]; V2[i] = 2.0f*V2[i] - V2_old[i]; V3[i] = 2.0f*V3[i] - V3_old[i]; } return 1; }
box_coder_op.h
/* Copyright (c) 2018 PaddlePaddle Authors. All Rights Reserved. Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. */ #pragma once #include <string> #include <vector> #include "paddle/fluid/framework/op_registry.h" #include "paddle/fluid/operators/math/math_function.h" namespace paddle { namespace operators { enum class BoxCodeType { kEncodeCenterSize = 0, kDecodeCenterSize = 1 }; inline BoxCodeType GetBoxCodeType(const std::string &type) { PADDLE_ENFORCE_EQ( (type == "encode_center_size") || (type == "decode_center_size"), true, platform::errors::InvalidArgument( "The 'code_type' attribute in BoxCoder" " must be 'encode_center_size' or 'decode_center_size'. " "But received 'code_type' is %s", type)); if (type == "encode_center_size") { return BoxCodeType::kEncodeCenterSize; } else { return BoxCodeType::kDecodeCenterSize; } } template <typename DeviceContext, typename T> class BoxCoderKernel : public framework::OpKernel<T> { public: void EncodeCenterSize(const framework::Tensor *target_box, const framework::Tensor *prior_box, const framework::Tensor *prior_box_var, const bool normalized, const std::vector<float> variance, T *output) const { int64_t row = target_box->dims()[0]; int64_t col = prior_box->dims()[0]; int64_t len = prior_box->dims()[1]; #ifdef PADDLE_WITH_MKLML #pragma omp parallel for collapse(2) #endif for (int64_t i = 0; i < row; ++i) { for (int64_t j = 0; j < col; ++j) { auto *target_box_data = target_box->data<T>(); auto *prior_box_data = prior_box->data<T>(); size_t offset = i * col * len + j * len; T prior_box_width = prior_box_data[j * len + 2] - prior_box_data[j * len] + (normalized == false); T prior_box_height = prior_box_data[j * len + 3] - prior_box_data[j * len + 1] + (normalized == false); T prior_box_center_x = prior_box_data[j * len] + prior_box_width / 2; T prior_box_center_y = prior_box_data[j * len + 1] + prior_box_height / 2; T target_box_center_x = (target_box_data[i * len + 2] + target_box_data[i * len]) / 2; T target_box_center_y = (target_box_data[i * len + 3] + target_box_data[i * len + 1]) / 2; T target_box_width = target_box_data[i * len + 2] - target_box_data[i * len] + (normalized == false); T target_box_height = target_box_data[i * len + 3] - target_box_data[i * len + 1] + (normalized == false); output[offset] = (target_box_center_x - prior_box_center_x) / prior_box_width; output[offset + 1] = (target_box_center_y - prior_box_center_y) / prior_box_height; output[offset + 2] = std::log(std::fabs(target_box_width / prior_box_width)); output[offset + 3] = std::log(std::fabs(target_box_height / prior_box_height)); } } if (prior_box_var) { const T *prior_box_var_data = prior_box_var->data<T>(); #ifdef PADDLE_WITH_MKLML #pragma omp parallel for collapse(3) #endif for (int64_t i = 0; i < row; ++i) { for (int64_t j = 0; j < col; ++j) { for (int k = 0; k < 4; ++k) { size_t offset = i * col * len + j * len; int prior_var_offset = j * len; output[offset + k] /= prior_box_var_data[prior_var_offset + k]; } } } } else if (!(variance.empty())) { #ifdef PADDLE_WITH_MKLML #pragma omp parallel for collapse(3) #endif for (int64_t i = 0; i < row; ++i) { for (int64_t j = 0; j < col; ++j) { for (int k = 0; k < 4; ++k) { size_t offset = i * col * len + j * len; output[offset + k] /= static_cast<T>(variance[k]); } } } } } template <int axis, int var_size> void DecodeCenterSize(const framework::Tensor *target_box, const framework::Tensor *prior_box, const framework::Tensor *prior_box_var, const bool normalized, std::vector<float> variance, T *output) const { int64_t row = target_box->dims()[0]; int64_t col = target_box->dims()[1]; int64_t len = target_box->dims()[2]; #ifdef PADDLE_WITH_MKLML #pragma omp parallel for collapse(2) #endif for (int64_t i = 0; i < row; ++i) { for (int64_t j = 0; j < col; ++j) { auto *target_box_data = target_box->data<T>(); auto *prior_box_data = prior_box->data<T>(); T var_data[4] = {1., 1., 1., 1.}; T *var_ptr = var_data; size_t offset = i * col * len + j * len; int prior_box_offset = axis == 0 ? j * len : i * len; T prior_box_width = prior_box_data[prior_box_offset + 2] - prior_box_data[prior_box_offset] + (normalized == false); T prior_box_height = prior_box_data[prior_box_offset + 3] - prior_box_data[prior_box_offset + 1] + (normalized == false); T prior_box_center_x = prior_box_data[prior_box_offset] + prior_box_width / 2; T prior_box_center_y = prior_box_data[prior_box_offset + 1] + prior_box_height / 2; T target_box_center_x = 0, target_box_center_y = 0; T target_box_width = 0, target_box_height = 0; int prior_var_offset = axis == 0 ? j * len : i * len; if (var_size == 2) { std::memcpy(var_ptr, prior_box_var->data<T>() + prior_var_offset, 4 * sizeof(T)); } else if (var_size == 1) { var_ptr = reinterpret_cast<T *>(variance.data()); } T box_var_x = *var_ptr; T box_var_y = *(var_ptr + 1); T box_var_w = *(var_ptr + 2); T box_var_h = *(var_ptr + 3); target_box_center_x = box_var_x * target_box_data[offset] * prior_box_width + prior_box_center_x; target_box_center_y = box_var_y * target_box_data[offset + 1] * prior_box_height + prior_box_center_y; target_box_width = std::exp(box_var_w * target_box_data[offset + 2]) * prior_box_width; target_box_height = std::exp(box_var_h * target_box_data[offset + 3]) * prior_box_height; output[offset] = target_box_center_x - target_box_width / 2; output[offset + 1] = target_box_center_y - target_box_height / 2; output[offset + 2] = target_box_center_x + target_box_width / 2 - (normalized == false); output[offset + 3] = target_box_center_y + target_box_height / 2 - (normalized == false); } } } void Compute(const framework::ExecutionContext &context) const override { auto *prior_box = context.Input<framework::Tensor>("PriorBox"); auto *prior_box_var = context.Input<framework::Tensor>("PriorBoxVar"); auto *target_box = context.Input<framework::LoDTensor>("TargetBox"); auto *output_box = context.Output<framework::Tensor>("OutputBox"); std::vector<float> variance = context.Attr<std::vector<float>>("variance"); const int axis = context.Attr<int>("axis"); if (target_box->lod().size()) { PADDLE_ENFORCE_EQ(target_box->lod().size(), 1UL, platform::errors::InvalidArgument( "Input(TargetBox) of BoxCoder operator " "supports LoD with only one level. But received " "level = %d", target_box->lod().size())); } if (prior_box_var) { PADDLE_ENFORCE_EQ(variance.empty(), true, platform::errors::InvalidArgument( "Input 'PriorBoxVar' and attribute 'variance' " "of BoxCoder operator should not be used at the " "same time.")); } if (!(variance.empty())) { PADDLE_ENFORCE_EQ(static_cast<int>(variance.size()), 4, platform::errors::InvalidArgument( "Size of attribute 'variance' of BoxCoder " "operator should be 4. But received " "size = %d", variance.size())); } auto code_type = GetBoxCodeType(context.Attr<std::string>("code_type")); bool normalized = context.Attr<bool>("box_normalized"); auto row = target_box->dims()[0]; auto col = prior_box->dims()[0]; if (code_type == BoxCodeType::kDecodeCenterSize) { col = target_box->dims()[1]; } auto len = prior_box->dims()[1]; output_box->mutable_data<T>({row, col, len}, context.GetPlace()); T *output = output_box->data<T>(); if (code_type == BoxCodeType::kEncodeCenterSize) { EncodeCenterSize(target_box, prior_box, prior_box_var, normalized, variance, output); } else if (code_type == BoxCodeType::kDecodeCenterSize) { if (prior_box_var) { if (axis == 0) { DecodeCenterSize<0, 2>(target_box, prior_box, prior_box_var, normalized, variance, output); } else { DecodeCenterSize<1, 2>(target_box, prior_box, prior_box_var, normalized, variance, output); } } else if (!(variance.empty())) { if (axis == 0) { DecodeCenterSize<0, 1>(target_box, prior_box, prior_box_var, normalized, variance, output); } else { DecodeCenterSize<1, 1>(target_box, prior_box, prior_box_var, normalized, variance, output); } } else { if (axis == 0) { DecodeCenterSize<0, 0>(target_box, prior_box, prior_box_var, normalized, variance, output); } else { DecodeCenterSize<1, 0>(target_box, prior_box, prior_box_var, normalized, variance, output); } } } } }; } // namespace operators } // namespace paddle
nbody.c
#include <stdio.h> #include <stdlib.h> #include <string.h> #include <math.h> #include <omp.h> #define DIM 2 /* Two-dimensional system */ #define X 0 /* x-coordinate subscript */ #define Y 1 /* y-coordinate subscript */ #define MARGIN 1e-12 const double G = 6.673e-11; double kinetic_energy_seq, potential_energy_seq; double kinetic_energy_par, potential_energy_par; typedef double vect_t[DIM]; /* Vector type for position, etc. */ struct particle_s { double m; /* Mass */ vect_t s; /* Position */ vect_t v; /* Velocity */ }; void Usage(char* prog_name); void Get_args(int part, int steps, double dt, int freq, char * c, int* n_p, int* n_steps_p, double* delta_t_p, int* output_freq_p, char* g_i_p); void Get_init_cond(struct particle_s curr[], int n); void Gen_init_cond(struct particle_s curr[], int n); void Output_state(double time, struct particle_s curr[], int n); void Compute_force_PAR(int part, vect_t forces[], struct particle_s curr[], int n); void Compute_force_SEQ(int part, vect_t forces[], struct particle_s curr[], int n); void Update_part(int part, vect_t forces[], struct particle_s curr[], int n, double delta_t); void Compute_energy_PAR(struct particle_s curr[], int n, double* kin_en_p, double* pot_en_p); void Compute_energy_SEQ(struct particle_s curr[], int n, double* kin_en_p, double* pot_en_p); int main_SEQ(int parts, int steps, double dt, int freq, char* c) { int n; /* Number of particles */ int n_steps; /* Number of timesteps */ int step; /* Current step */ int part; /* Current particle */ int output_freq; /* Frequency of output */ double delta_t; /* Size of timestep */ double t; /* Current Time */ struct particle_s* curr; /* Current state of system */ vect_t* forces; /* Forces on each particle */ char g_i; /*_G_en or _i_nput init conds */ double kinetic_energy, potential_energy; double start, finish; /* For timings */ Get_args(parts, steps, dt, freq, c, &n, &n_steps, &delta_t, &output_freq, &g_i); curr = malloc(n*sizeof(struct particle_s)); forces = malloc(n*sizeof(vect_t)); if (g_i == 'i') Get_init_cond(curr, n); else Gen_init_cond(curr, n); start = omp_get_wtime(); Compute_energy_SEQ(curr, n, &kinetic_energy, &potential_energy); kinetic_energy_seq = kinetic_energy; potential_energy_seq = potential_energy; printf(" PE = %e, KE = %e, Total Energy = %e\n", potential_energy, kinetic_energy, kinetic_energy+potential_energy); //Output_state(0, curr, n); for (step = 1; step <= n_steps; step++) { t = step*delta_t; memset(forces, 0, n*sizeof(vect_t)); for (part = 0; part < n-1; part++) Compute_force_SEQ(part, forces, curr, n); for (part = 0; part < n; part++) Update_part(part, forces, curr, n, delta_t); Compute_energy_SEQ(curr, n, &kinetic_energy, &potential_energy); kinetic_energy_seq = kinetic_energy; potential_energy_seq = potential_energy; } //Output_state(t, curr, n); printf(" PE = %e, KE = %e, Total Energy = %e\n", potential_energy, kinetic_energy, kinetic_energy+potential_energy); finish = omp_get_wtime(); printf("Elapsed time = %e seconds\n", finish-start); free(curr); free(forces); return 0; } /* main */ int main_PAR(int parts, int steps, double dt, int freq, char* c) { int n; /* Number of particles */ int n_steps; /* Number of timesteps */ int step; /* Current step */ int part; /* Current particle */ int output_freq; /* Frequency of output */ double delta_t; /* Size of timestep */ double t; /* Current Time */ struct particle_s* curr; /* Current state of system */ vect_t* forces; /* Forces on each particle */ char g_i; /*_G_en or _i_nput init conds */ double kinetic_energy, potential_energy; double start, finish; /* For timings */ Get_args(parts, steps, dt, freq, c, &n, &n_steps, &delta_t, &output_freq, &g_i); curr = malloc(n*sizeof(struct particle_s)); forces = malloc(n*sizeof(vect_t)); if (g_i == 'i') Get_init_cond(curr, n); else Gen_init_cond(curr, n); start = omp_get_wtime(); Compute_energy_PAR(curr, n, &kinetic_energy, &potential_energy); kinetic_energy_par = kinetic_energy; potential_energy_par = potential_energy; printf(" PE = %e, KE = %e, Total Energy = %e\n", potential_energy, kinetic_energy, kinetic_energy+potential_energy); //Output_state(0, curr, n); for (step = 1; step <= n_steps; step++) { t = step*delta_t; memset(forces, 0, n*sizeof(vect_t)); for (part = 0; part < n-1; part++) Compute_force_PAR(part, forces, curr, n); #pragma omp parallel for private(part) for (part = 0; part < n; part++) Update_part(part, forces, curr, n, delta_t); Compute_energy_PAR(curr, n, &kinetic_energy, &potential_energy); kinetic_energy_par = kinetic_energy; potential_energy_par = potential_energy; } //Output_state(t, curr, n); printf(" PE = %e, KE = %e, Total Energy = %e\n", potential_energy, kinetic_energy, kinetic_energy+potential_energy); finish = omp_get_wtime(); printf("Elapsed time = %e seconds\n", finish-start); free(curr); free(forces); return 0; } /* main */ int main(){ printf("\n\n 100"); printf("\nSEQUENTIAL\n"); main_SEQ( 100, 500, 0.01, 500, "g"); printf("\nPARALLEL\n"); main_PAR( 100, 500, 0.01, 500, "g"); if(abs(kinetic_energy_seq - kinetic_energy_par) <= MARGIN && abs(potential_energy_seq - potential_energy_par) <= MARGIN ) printf("\nTest PASSED \n"); else printf("\nTest FAILED \n"); printf("\n\n 500"); printf("\nSEQUENTIAL\n"); main_SEQ( 500, 500, 0.01, 500, "g"); printf("\nPARALLEL\n"); main_PAR( 500, 500, 0.01, 500, "g"); if(abs(kinetic_energy_seq - kinetic_energy_par) <= MARGIN && abs(potential_energy_seq - potential_energy_par) <= MARGIN ) printf("\nTest PASSED \n"); else printf("\nTest FAILED \n"); printf("\n\n 5000"); printf("\nSEQUENTIAL\n"); main_SEQ( 5000, 500, 0.01, 500, "g"); printf("\nPARELLEL\n"); main_PAR( 5000, 500, 0.01, 500, "g"); if(abs(kinetic_energy_seq - kinetic_energy_par) <= MARGIN && abs(potential_energy_seq - potential_energy_par) <= MARGIN ) printf("\nTest PASSED \n"); else printf("\nTest FAILED \n"); } void Usage(char* prog_name) { fprintf(stderr, "usage: %s <number of particles> <number of timesteps>\n", prog_name); fprintf(stderr, " <size of timestep> <output frequency>\n"); fprintf(stderr, " <g|i>\n"); fprintf(stderr, " 'g': program should generate init conds\n"); fprintf(stderr, " 'i': program should get init conds from stdin\n"); exit(0); } /* Usage */ void Get_args(int part, int steps, double dt, int freq, char* c, int* n_p, int* n_steps_p, double* delta_t_p, int* output_freq_p, char* g_i_p) { *n_p = part; *n_steps_p = steps; *delta_t_p = dt; *output_freq_p = freq; *g_i_p = c; } void Get_init_cond(struct particle_s curr[], int n) { int part; printf("For each particle, enter (in order):\n"); printf(" its mass, its x-coord, its y-coord, "); printf("its x-velocity, its y-velocity\n"); for (part = 0; part < n; part++) { scanf("%lf", &curr[part].m); scanf("%lf", &curr[part].s[X]); scanf("%lf", &curr[part].s[Y]); scanf("%lf", &curr[part].v[X]); scanf("%lf", &curr[part].v[Y]); } } /* Get_init_cond */ void Gen_init_cond(struct particle_s curr[], int n) { int part; double mass = 5.0e24; double gap = 1.0e5; double speed = 3.0e4; srandom(1); for (part = 0; part < n; part++) { curr[part].m = mass; curr[part].s[X] = part*gap; curr[part].s[Y] = 0.0; curr[part].v[X] = 0.0; if (part % 2 == 0) curr[part].v[Y] = speed; else curr[part].v[Y] = -speed; } } /* Gen_init_cond */ void Output_state(double time, struct particle_s curr[], int n) { int part; printf("%.2f\n", time); for (part = 0; part < n; part++) { printf("%3d %10.3e ", part, curr[part].s[X]); printf(" %10.3e ", curr[part].s[Y]); printf(" %10.3e ", curr[part].v[X]); printf(" %10.3e\n", curr[part].v[Y]); } printf("\n"); } /* Output_state */ void Compute_force_SEQ(int part, vect_t forces[], struct particle_s curr[], int n) { int k; double mg; vect_t f_part_k; double len, len_3, fact; for (k = part+1; k < n; k++) { f_part_k[X] = curr[part].s[X] - curr[k].s[X]; f_part_k[Y] = curr[part].s[Y] - curr[k].s[Y]; len = sqrt(f_part_k[X]*f_part_k[X] + f_part_k[Y]*f_part_k[Y]); len_3 = len*len*len; mg = -G*curr[part].m*curr[k].m; fact = mg/len_3; f_part_k[X] *= fact; f_part_k[Y] *= fact; forces[part][X] += f_part_k[X]; forces[part][Y] += f_part_k[Y]; forces[k][X] -= f_part_k[X]; forces[k][Y] -= f_part_k[Y]; } } void Compute_force_PAR(int part, vect_t forces[], struct particle_s curr[], int n) { int k; double mg; vect_t f_part_k; double len, len_3, fact, tempForcesX = 0, tempForcesY = 0; #pragma omp parallel for \ shared(part, curr, n, forces) \ private(k, fact, len, len_3, f_part_k, mg) \ reduction(+:tempForcesX, tempForcesY) for (k = part+1; k < n; k++) { f_part_k[X] = curr[part].s[X] - curr[k].s[X]; f_part_k[Y] = curr[part].s[Y] - curr[k].s[Y]; len = sqrt(f_part_k[X]*f_part_k[X] + f_part_k[Y]*f_part_k[Y]); len_3 = len*len*len; mg = -G*curr[part].m*curr[k].m; fact = mg/len_3; f_part_k[X] *= fact; f_part_k[Y] *= fact; tempForcesX += f_part_k[X]; tempForcesY += f_part_k[Y]; forces[k][X] -= f_part_k[X]; forces[k][Y] -= f_part_k[Y]; } forces[part][X] += tempForcesX; forces[part][Y] += tempForcesY; } /* Compute_force */ void Update_part(int part, vect_t forces[], struct particle_s curr[], int n, double delta_t) { double fact = delta_t/curr[part].m; curr[part].s[X] += delta_t * curr[part].v[X]; curr[part].s[Y] += delta_t * curr[part].v[Y]; curr[part].v[X] += fact * forces[part][X]; curr[part].v[Y] += fact * forces[part][Y]; } void Compute_energy_SEQ(struct particle_s curr[], int n, double* kin_en_p, double* pot_en_p) { int i, j; vect_t diff; double pe = 0.0, ke = 0.0; double dist, speed_sqr; for (i = 0; i < n; i++) { speed_sqr = curr[i].v[X]*curr[i].v[X] + curr[i].v[Y]*curr[i].v[Y]; ke += curr[i].m*speed_sqr; } ke *= 0.5; for (i = 0; i < n-1; i++) { for (j = i+1; j < n; j++) { diff[X] = curr[i].s[X] - curr[j].s[X]; diff[Y] = curr[i].s[Y] - curr[j].s[Y]; dist = sqrt(diff[X]*diff[X] + diff[Y]*diff[Y]); pe += -G*curr[i].m*curr[j].m/dist; } } *kin_en_p = ke; *pot_en_p = pe; } void Compute_energy_PAR(struct particle_s curr[], int n, double* kin_en_p, double* pot_en_p) { int i, j; vect_t diff; double pe = 0.0, ke = 0.0; double dist, speed_sqr; #pragma omp parallel for \ shared(curr, n) \ private(speed_sqr, i) \ reduction(+:ke) for (i = 0; i < n; i++) { speed_sqr = curr[i].v[X]*curr[i].v[X] + curr[i].v[Y]*curr[i].v[Y]; ke += curr[i].m*speed_sqr; } ke *= 0.5; for (i = 0; i < n-1; i++) { #pragma omp parallel for \ private(j, diff, dist) \ shared(i, curr, n) \ reduction(+:pe) for (j = i+1; j < n; j++) { diff[X] = curr[i].s[X] - curr[j].s[X]; diff[Y] = curr[i].s[Y] - curr[j].s[Y]; dist = sqrt(diff[X]*diff[X] + diff[Y]*diff[Y]); pe += -G*curr[i].m*curr[j].m/dist; } } *kin_en_p = ke; *pot_en_p = pe; } /* Compute_energy */
nlk_corpus.c
/****************************************************************************** * NLK - Neural Language Kit * * Copyright (c) 2015 Luis Rei <me@luisrei.com> http://luisrei.com @lmrei * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to * deal in the Software without restriction, including without limitation the * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or * sell copies of the Software, and to permit persons to whom the Software is * furnished to do so, subject to the following conditions: * * The above copyright notice and this permission notice shall be included in * all copies or substantial portions of the Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS * IN THE SOFTWARE. *****************************************************************************/ /** * @file nlk_corpus.c * Create and use corpus structures */ #include <unistd.h> #include <time.h> #include <inttypes.h> #include <omp.h> #include "nlk_text.h" #include "nlk_vocabulary.h" #include "nlk_util.h" #include "nlk_tic.h" #include "nlk.h" #include "nlk_corpus.h" /** * Displays the progress stats while building a corpus from a file * * @param start the clocks used just before starting to read the file */ static void nlk_corpus_display_progress(const size_t line_counter, const size_t total_lines, const clock_t start) { double progress; double speed; char display_str[256]; clock_t now = clock(); progress = (line_counter / (double) total_lines) * 100; speed = line_counter / ((double)(now - start + 1) / (double)CLOCKS_PER_SEC * 1000), snprintf(display_str, 256, "Corpus Progress: %.2f%% Lines/Thread/sec: %.2fK Threads: %d", progress, speed, omp_get_num_threads()); nlk_tic(display_str, false); } /** * Reads a corpus (in id-text line delimited format) * * @param file_path the path to the corpus * @param vocab the vocabulary to use * * @return a corpus structure */ struct nlk_corpus_t * nlk_corpus_read(char *file_path, struct nlk_vocab_t **vocab, const bool verbose) { struct nlk_corpus_t *corpus = NULL; size_t total_lines; const int num_threads = nlk_get_num_threads(); /* count lines */ if(verbose) { nlk_tic("Reading Corpus: ", false); printf("%s\n", file_path); } total_lines = nlk_text_count_lines(file_path); if(verbose) { printf("Lines: %zu\n", total_lines); } /* allocate corpus */ corpus = (struct nlk_corpus_t *) malloc(sizeof(struct nlk_corpus_t)); if(corpus == NULL) { NLK_ERROR_NULL("unable to allocate memory for the vocabularized file", NLK_ENOMEM); } /* allocate memory for the file (the line array) */ corpus->lines = (struct nlk_line_t *) calloc(total_lines, sizeof(struct nlk_line_t)); if(corpus->lines == NULL) { NLK_ERROR_NULL("unable to allocate memory for the vocabularized file", NLK_ENOMEM); /* unreachable */ } corpus->len = total_lines; struct nlk_line_t *lines = corpus->lines; struct nlk_vocab_t *replacement = nlk_vocab_find(vocab, NLK_UNK_SYMBOL); uint64_t word_count = 0; size_t line_counter = 0; size_t updated = 0; clock_t start = clock(); /** * Start of Parallel Region */ #pragma omp parallel reduction(+ : word_count) shared(line_counter, updated) { /* allocate memory for a line of text */ char **text_line = nlk_text_line_create(); char *buffer = malloc(sizeof(char) * NLK_BUFFER_SIZE); if(buffer == NULL) { NLK_ERROR_ABORT("unable to allocate memory for buffering", NLK_ENOMEM); /* unreachable */ } /* memory for vocabularizing */ struct nlk_vocab_t *varray[NLK_MAX_LINE_SIZE]; struct nlk_line_t vline; vline.varray = varray; /* open file */ int fd = nlk_open(file_path); #pragma omp for for(int thread_id = 0; thread_id < num_threads; thread_id++) { /** @subsection File Reading Position * open file and get start and end positions for thread */ const size_t line_start = nlk_text_get_split_start_line(total_lines, num_threads, thread_id); const size_t end_line = nlk_text_get_split_end_line(total_lines, num_threads, thread_id); /* go to start position */ size_t line_cur = line_start; nlk_text_goto_line(fd, line_cur); /** @subsection Read lines */ while(line_cur <= end_line) { /* display */ if(verbose) { if(line_counter - updated > 1000) { updated = line_counter; nlk_corpus_display_progress(line_counter, total_lines, start); } } /* end of display */ /* read */ nlk_vocab_read_vocabularize(fd, true, vocab, replacement, text_line, &vline, buffer); /* check for errors */ if(vline.len == 0) { lines[line_cur].varray = NULL; lines[line_cur].len = 0; lines[line_cur].line_id = (size_t)-1; /* nlk_debug("\nBad line: %zu\n", line_cur); */ line_cur++; line_counter++; continue; } /* create */ lines[line_cur].varray = (struct nlk_vocab_t **) malloc(sizeof(struct nlk_vocab_t *) * vline.len); if(lines[line_cur].varray == NULL) { NLK_ERROR_ABORT("unable to allocate memory for line", NLK_ENOMEM); /* unreachable */ } /* copy */ lines[line_cur].len = vline.len; lines[line_cur].line_id = vline.line_id; for(size_t ii = 0; ii < vline.len; ii++) { lines[line_cur].varray[ii] = varray[ii]; } word_count += vline.len; line_cur++; line_counter++; } /* end of lines for thread */ } /* end of for() threads */ if(verbose) { nlk_corpus_display_progress(line_counter, total_lines, start); } /* free thread memory */ nlk_text_line_free(text_line); free(buffer); buffer = NULL; close(fd); fd = 0; } /* end of parallel region */ corpus->count = word_count; if(verbose) { printf("\n"); nlk_tic("done reading corpus: ", false); printf("%"PRIu64" words\n", word_count); } return corpus; } /** * Free a corpus structure * * @param corpus the corpus structure to free */ void nlk_corpus_free(struct nlk_corpus_t *corpus) { /* free individual lines */ for(size_t ii = 0; ii < corpus->len; ii++) { if(corpus->lines[ii].varray != NULL) { free(corpus->lines[ii].varray); corpus->lines[ii].varray = NULL; } } /* free the lines array */ free(corpus->lines); corpus->lines = NULL; /* free the corpus */ free(corpus); } /** * Counts the number of word occurrences in the subset of a corpus * * @param corpus the corpus * @param ids the ids of the corpus that make up the subset * @param n_ids the size of the ids array * * @return the number of word occurrences in the corpus subset */ uint64_t nlk_corpus_subset_count(const struct nlk_corpus_t *corpus, const size_t *ids, const size_t n_ids) { uint64_t total = 0; for(size_t ii = 0; ii < corpus->len; ii++) { if(nlk_in(corpus->lines[ii].line_id, ids, n_ids)) { total += corpus->lines[ii].len; } } return total; }
GB_binop__lxor_uint64.c
//------------------------------------------------------------------------------ // GB_binop: hard-coded functions for each built-in binary operator //------------------------------------------------------------------------------ // SuiteSparse:GraphBLAS, Timothy A. Davis, (c) 2017-2020, All Rights Reserved. // http://suitesparse.com See GraphBLAS/Doc/License.txt for license. //------------------------------------------------------------------------------ // If this file is in the Generated/ folder, do not edit it (auto-generated). #include "GB.h" #ifndef GBCOMPACT #include "GB_control.h" #include "GB_ek_slice.h" #include "GB_dense.h" #include "GB_mkl.h" #include "GB_binop__include.h" // C=binop(A,B) is defined by the following types and operators: // A+B function (eWiseAdd): GB_AaddB__lxor_uint64 // A.*B function (eWiseMult): GB_AemultB__lxor_uint64 // A*D function (colscale): GB_AxD__lxor_uint64 // D*A function (rowscale): GB_DxB__lxor_uint64 // C+=B function (dense accum): GB_Cdense_accumB__lxor_uint64 // C+=b function (dense accum): GB_Cdense_accumb__lxor_uint64 // C+=A+B function (dense ewise3): (none) // C=A+B function (dense ewise3): GB_Cdense_ewise3_noaccum__lxor_uint64 // C=scalar+B GB_bind1st__lxor_uint64 // C=scalar+B' GB_bind1st_tran__lxor_uint64 // C=A+scalar GB_bind2nd__lxor_uint64 // C=A'+scalar GB_bind2nd_tran__lxor_uint64 // C type: uint64_t // A type: uint64_t // B,b type: uint64_t // BinaryOp: cij = ((aij != 0) != (bij != 0)) #define GB_ATYPE \ uint64_t #define GB_BTYPE \ uint64_t #define GB_CTYPE \ uint64_t // true if the types of A and B are identical #define GB_ATYPE_IS_BTYPE \ 1 // true if the types of C and A are identical #define GB_CTYPE_IS_ATYPE \ 1 // true if the types of C and B are identical #define GB_CTYPE_IS_BTYPE \ 1 // aij = Ax [pA] #define GB_GETA(aij,Ax,pA) \ uint64_t aij = Ax [pA] // bij = Bx [pB] #define GB_GETB(bij,Bx,pB) \ uint64_t bij = Bx [pB] // declare scalar of the same type as C #define GB_CTYPE_SCALAR(t) \ uint64_t t // cij = Ax [pA] #define GB_COPY_A_TO_C(cij,Ax,pA) \ cij = Ax [pA] // cij = Bx [pB] #define GB_COPY_B_TO_C(cij,Bx,pB) \ cij = Bx [pB] #define GB_CX(p) Cx [p] // binary operator #define GB_BINOP(z, x, y) \ z = ((x != 0) != (y != 0)) ; // op is second #define GB_OP_IS_SECOND \ 0 // op is plus_fp32 or plus_fp64 #define GB_OP_IS_PLUS_REAL \ 0 // op is minus_fp32 or minus_fp64 #define GB_OP_IS_MINUS_REAL \ 0 // GB_cblas_*axpy gateway routine, if it exists for this operator and type: #define GB_CBLAS_AXPY \ (none) // do the numerical phases of GB_add and GB_emult #define GB_PHASE_2_OF_2 // hard-coded loops can be vectorized #define GB_PRAGMA_SIMD_VECTORIZE GB_PRAGMA_SIMD // disable this operator and use the generic case if these conditions hold #define GB_DISABLE \ (GxB_NO_LXOR || GxB_NO_UINT64 || GxB_NO_LXOR_UINT64) //------------------------------------------------------------------------------ // C += A+B, all 3 matrices dense //------------------------------------------------------------------------------ #if 0 // The op must be MIN, MAX, PLUS, MINUS, RMINUS, TIMES, DIV, or RDIV. void (none) ( GrB_Matrix C, const GrB_Matrix A, const GrB_Matrix B, const int nthreads ) { #include "GB_dense_ewise3_accum_template.c" } #endif //------------------------------------------------------------------------------ // C = A+B, all 3 matrices dense //------------------------------------------------------------------------------ GrB_Info GB_Cdense_ewise3_noaccum__lxor_uint64 ( GrB_Matrix C, const GrB_Matrix A, const GrB_Matrix B, const int nthreads ) { #if GB_DISABLE return (GrB_NO_VALUE) ; #else #include "GB_dense_ewise3_noaccum_template.c" return (GrB_SUCCESS) ; #endif } //------------------------------------------------------------------------------ // C += B, accumulate a sparse matrix into a dense matrix //------------------------------------------------------------------------------ GrB_Info GB_Cdense_accumB__lxor_uint64 ( GrB_Matrix C, const GrB_Matrix B, const int64_t *GB_RESTRICT kfirst_slice, const int64_t *GB_RESTRICT klast_slice, const int64_t *GB_RESTRICT pstart_slice, const int ntasks, const int nthreads ) { #if GB_DISABLE return (GrB_NO_VALUE) ; #else { #include "GB_dense_subassign_23_template.c" } return (GrB_SUCCESS) ; #endif } //------------------------------------------------------------------------------ // C += b, accumulate a scalar into a dense matrix //------------------------------------------------------------------------------ GrB_Info GB_Cdense_accumb__lxor_uint64 ( GrB_Matrix C, const GB_void *p_bwork, const int nthreads ) { #if GB_DISABLE return (GrB_NO_VALUE) ; #else { // get the scalar b for C += b, of type uint64_t uint64_t bwork = (*((uint64_t *) p_bwork)) ; #include "GB_dense_subassign_22_template.c" return (GrB_SUCCESS) ; } return (GrB_SUCCESS) ; #endif } //------------------------------------------------------------------------------ // C = A*D, column scale with diagonal D matrix //------------------------------------------------------------------------------ GrB_Info GB_AxD__lxor_uint64 ( GrB_Matrix C, const GrB_Matrix A, bool A_is_pattern, const GrB_Matrix D, bool D_is_pattern, const int64_t *GB_RESTRICT kfirst_slice, const int64_t *GB_RESTRICT klast_slice, const int64_t *GB_RESTRICT pstart_slice, const int ntasks, const int nthreads ) { #if GB_DISABLE return (GrB_NO_VALUE) ; #else uint64_t *GB_RESTRICT Cx = (uint64_t *) C->x ; #include "GB_AxB_colscale_meta.c" return (GrB_SUCCESS) ; #endif } //------------------------------------------------------------------------------ // C = D*B, row scale with diagonal D matrix //------------------------------------------------------------------------------ GrB_Info GB_DxB__lxor_uint64 ( GrB_Matrix C, const GrB_Matrix D, bool D_is_pattern, const GrB_Matrix B, bool B_is_pattern, int nthreads ) { #if GB_DISABLE return (GrB_NO_VALUE) ; #else uint64_t *GB_RESTRICT Cx = (uint64_t *) C->x ; #include "GB_AxB_rowscale_meta.c" return (GrB_SUCCESS) ; #endif } //------------------------------------------------------------------------------ // eWiseAdd: C = A+B or C<M> = A+B //------------------------------------------------------------------------------ GrB_Info GB_AaddB__lxor_uint64 ( GrB_Matrix C, const GrB_Matrix M, const bool Mask_struct, const GrB_Matrix A, const GrB_Matrix B, const bool Ch_is_Mh, const int64_t *GB_RESTRICT C_to_M, const int64_t *GB_RESTRICT C_to_A, const int64_t *GB_RESTRICT C_to_B, const GB_task_struct *GB_RESTRICT TaskList, const int ntasks, const int nthreads ) { #if GB_DISABLE return (GrB_NO_VALUE) ; #else #include "GB_add_template.c" return (GrB_SUCCESS) ; #endif } //------------------------------------------------------------------------------ // eWiseMult: C = A.*B or C<M> = A.*B //------------------------------------------------------------------------------ GrB_Info GB_AemultB__lxor_uint64 ( GrB_Matrix C, const GrB_Matrix M, const bool Mask_struct, const GrB_Matrix A, const GrB_Matrix B, const int64_t *GB_RESTRICT C_to_M, const int64_t *GB_RESTRICT C_to_A, const int64_t *GB_RESTRICT C_to_B, const GB_task_struct *GB_RESTRICT TaskList, const int ntasks, const int nthreads ) { #if GB_DISABLE return (GrB_NO_VALUE) ; #else #include "GB_emult_template.c" return (GrB_SUCCESS) ; #endif } //------------------------------------------------------------------------------ // Cx = op (x,Bx): apply a binary operator to a matrix with scalar bind1st //------------------------------------------------------------------------------ GrB_Info GB_bind1st__lxor_uint64 ( GB_void *Cx_output, // Cx and Bx may be aliased const GB_void *x_input, const GB_void *Bx_input, int64_t anz, int nthreads ) { #if GB_DISABLE return (GrB_NO_VALUE) ; #else uint64_t *Cx = (uint64_t *) Cx_output ; uint64_t x = (*((uint64_t *) x_input)) ; uint64_t *Bx = (uint64_t *) Bx_input ; int64_t p ; #pragma omp parallel for num_threads(nthreads) schedule(static) for (p = 0 ; p < anz ; p++) { uint64_t bij = Bx [p] ; Cx [p] = ((x != 0) != (bij != 0)) ; } return (GrB_SUCCESS) ; #endif } //------------------------------------------------------------------------------ // Cx = op (Ax,y): apply a binary operator to a matrix with scalar bind2nd //------------------------------------------------------------------------------ GrB_Info GB_bind2nd__lxor_uint64 ( GB_void *Cx_output, // Cx and Ax may be aliased const GB_void *Ax_input, const GB_void *y_input, int64_t anz, int nthreads ) { #if GB_DISABLE return (GrB_NO_VALUE) ; #else int64_t p ; uint64_t *Cx = (uint64_t *) Cx_output ; uint64_t *Ax = (uint64_t *) Ax_input ; uint64_t y = (*((uint64_t *) y_input)) ; #pragma omp parallel for num_threads(nthreads) schedule(static) for (p = 0 ; p < anz ; p++) { uint64_t aij = Ax [p] ; Cx [p] = ((aij != 0) != (y != 0)) ; } return (GrB_SUCCESS) ; #endif } //------------------------------------------------------------------------------ // C = op (x, A'): transpose and apply a binary operator //------------------------------------------------------------------------------ // cij = op (x, aij), no typcasting (in spite of the macro name) #undef GB_CAST_OP #define GB_CAST_OP(pC,pA) \ { \ uint64_t aij = Ax [pA] ; \ Cx [pC] = ((x != 0) != (aij != 0)) ; \ } GrB_Info GB_bind1st_tran__lxor_uint64 ( GrB_Matrix C, const GB_void *x_input, const GrB_Matrix A, int64_t *GB_RESTRICT *Rowcounts, GBI_single_iterator Iter, const int64_t *GB_RESTRICT A_slice, int naslice ) { // GB_unop_transpose.c uses GB_ATYPE, but A is // the 2nd input to binary operator z=f(x,y). #undef GB_ATYPE #define GB_ATYPE \ uint64_t #if GB_DISABLE return (GrB_NO_VALUE) ; #else uint64_t x = (*((const uint64_t *) x_input)) ; #define GB_PHASE_2_OF_2 #include "GB_unop_transpose.c" return (GrB_SUCCESS) ; #endif #undef GB_ATYPE #define GB_ATYPE \ uint64_t } //------------------------------------------------------------------------------ // C = op (A', y): transpose and apply a binary operator //------------------------------------------------------------------------------ // cij = op (aij, y), no typcasting (in spite of the macro name) #undef GB_CAST_OP #define GB_CAST_OP(pC,pA) \ { \ uint64_t aij = Ax [pA] ; \ Cx [pC] = ((aij != 0) != (y != 0)) ; \ } GrB_Info GB_bind2nd_tran__lxor_uint64 ( GrB_Matrix C, const GrB_Matrix A, const GB_void *y_input, int64_t *GB_RESTRICT *Rowcounts, GBI_single_iterator Iter, const int64_t *GB_RESTRICT A_slice, int naslice ) { #if GB_DISABLE return (GrB_NO_VALUE) ; #else uint64_t y = (*((const uint64_t *) y_input)) ; #define GB_PHASE_2_OF_2 #include "GB_unop_transpose.c" return (GrB_SUCCESS) ; #endif } #endif
pi.c
#ifndef _MONTECARLO_H #define _MONTECARLO_H #include"pi.h" #endif int main(int argc, char *argv[]){ double elapsed_time; double serialPI = 0, parallelPI = 0; if(argc != 3){ printf("Correct way to execute this program is:\n"); printf("./pi stepNum numberOfThreads\n"); return 1; } int num_steps = atoi(argv[1]); int num_thread = atoi(argv[2]); // Sequential histogram set_clock(); // COMPLETE HERE time_t t; srand((unsigned) time(&t)); double x = 0, y = 0; double sum = 0; int count_inside = 0; for(int i = 0; i < num_steps; i++){ x = (double)rand()/RAND_MAX; y = (double)rand()/RAND_MAX; sum = x * x + y * y; if (sum <= 1){ count_inside++; } } serialPI = (count_inside * 4.0) / num_steps; elapsed_time = get_elapsed_time(); printf("Naive PI calculation time: %.4fms\n", elapsed_time / 1000); // Openmp Parallel histogram set_clock(); // COMPLETE HERE omp_set_num_threads(num_thread); int count_inside_shared = 0; #pragma omp parallel { double x = 0, y = 0; double sum = 0; int count_inside = 0; unsigned int seed = 23 * omp_get_thread_num(); #pragma omp for for(int i = 0; i < num_steps; i++){ x = (double)rand_r(&seed)/RAND_MAX; y = (double)rand_r(&seed)/RAND_MAX; sum = x * x + y * y; if (sum <= 1){ count_inside++; } } #pragma omp atomic count_inside_shared += count_inside; } parallelPI = (count_inside_shared * 4.0) / num_steps; elapsed_time = get_elapsed_time(); printf("-> Openmp PI calculation time: %.4fms\n", elapsed_time / 1000); #ifdef TEST validate(&serialPI, &parallelPI, 1); #endif return 0; }
softmax-inl.h
/* * Licensed to the Apache Software Foundation (ASF) under one * or more contributor license agreements. See the NOTICE file * distributed with this work for additional information * regarding copyright ownership. The ASF licenses this file * to you under the Apache License, Version 2.0 (the * "License"); you may not use this file except in compliance * with the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, * software distributed under the License is distributed on an * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY * KIND, either express or implied. See the License for the * specific language governing permissions and limitations * under the License. */ /*! * Copyright (c) 2017 by Contributors * \file softmax-inl.h * \brief */ #ifndef MXNET_OPERATOR_NN_SOFTMAX_INL_H_ #define MXNET_OPERATOR_NN_SOFTMAX_INL_H_ #include <algorithm> #include <string> #include <utility> #include <vector> #include <type_traits> #include "../mxnet_op.h" #include "../operator_common.h" #include "../tensor/broadcast_reduce_op.h" #include "../../common/cuda_utils.h" namespace mxnet { namespace op { namespace mxnet_op { struct softmax_fwd { template<typename AType> MSHADOW_XINLINE static AType Map(float a, AType b) { return AType(expf(a)/b); } template<typename AType> MSHADOW_XINLINE static AType Map(double a, AType b) { return AType(exp(a)/b); } }; struct log_softmax_fwd { template<typename DType> MSHADOW_XINLINE static float Map(DType a, float b) { return a - logf(b); } template<typename DType> MSHADOW_XINLINE static double Map(DType a, double b) { return a - log(b); } }; template<typename OP, bool negate, typename AType, typename DType, typename OType, typename IType, int ndim> inline void Softmax(Stream<cpu> *s, DType *in, OType *out, IType *length, Shape<ndim> shape, int axis, const DType temperature) { index_t M = shape[axis]; if (M == 0) return; index_t N = shape.Size()/M; Shape<ndim> stride = calc_stride(shape); Shape<ndim> sshape = shape; sshape[axis] = 1; index_t sa = stride[axis]; if (length == nullptr) { #pragma omp parallel for for (index_t i = 0; i < N; ++i) { index_t base = unravel_dot(i, sshape, stride); DType mmax = negate ? -in[base] : in[base]; DType val; for (index_t j = 1; j < M; ++j) { val = negate ? -in[base + j*sa] : in[base + j*sa]; if (mmax < val) mmax = val; } AType sum = AType(0); DType in_val; // By default temperature is 1.0. // Adding a branch here to save the CPU 'divide-by-1' computation at runtime if (temperature == 1.0) { for (index_t j = 0; j < M; ++j) { in_val = negate ? -in[base + j*sa] : in[base + j*sa]; sum += std::exp(in_val - mmax); } for (index_t j = 0; j < M; ++j) { in_val = negate ? -in[base + j*sa] : in[base + j*sa]; out[base + j*sa] = OP::Map(in_val - mmax, sum); } } else { for (index_t j = 0; j < M; ++j) { in_val = negate ? -in[base + j*sa] : in[base + j*sa]; sum += std::exp((in_val - mmax)/temperature); } for (index_t j = 0; j < M; ++j) { in_val = negate ? -in[base + j*sa] : in[base + j*sa]; out[base + j*sa] = OP::Map((in_val - mmax)/temperature, sum); } } } } else { #pragma omp parallel for for (index_t i = 0; i < N; ++i) { index_t len = static_cast<index_t>(length[i]); index_t base = unravel_dot(i, sshape, stride); DType mmax = negate ? -in[base] : in[base]; DType val; for (index_t j = 1; j < len; ++j) { val = negate ? -in[base + j*sa] : in[base + j*sa]; if (mmax < val) mmax = val; } for (index_t j = len; j < M; ++j) { out[base + j*sa] = OType(0.0f); } AType sum = AType(0); DType in_val; // By default temperature is 1.0. // Adding a branch here to save the CPU 'divide-by-1' computation at runtime if (temperature == 1.0) { for (index_t j = 0; j < len; ++j) { in_val = negate ? -in[base + j*sa] : in[base + j*sa]; sum += std::exp(in_val - mmax); } for (index_t j = 0; j < len; ++j) { in_val = negate ? -in[base + j*sa] : in[base + j*sa]; out[base + j*sa] = OP::Map(in_val - mmax, sum); } } else { for (index_t j = 0; j < len; ++j) { in_val = negate ? -in[base + j*sa] : in[base + j*sa]; sum += std::exp((in_val - mmax)/temperature); } for (index_t j = 0; j < len; ++j) { in_val = negate ? -in[base + j*sa] : in[base + j*sa]; out[base + j*sa] = OP::Map((in_val - mmax)/temperature, sum); } } } } } struct softmax_bwd { template<typename DType, typename AType> MSHADOW_XINLINE static AType Map(DType ograd, DType out, AType sum) { return AType(out * (ograd - sum)); } }; struct log_softmax_bwd { template<typename AType> MSHADOW_XINLINE static AType Map(float ograd, float out, AType sum) { return AType(ograd - expf(out)*sum); } template<typename AType> MSHADOW_XINLINE static AType Map(double ograd, double out, AType sum) { return AType(ograd - exp(out)*sum); } }; template<typename OP1, typename OP2, int Req, bool negate, typename AType, typename DType, typename OType, typename IType, int ndim> inline void SoftmaxGrad(Stream<cpu> *s, OType *out, OType *ograd, DType *igrad, IType *length, Shape<ndim> shape, int axis, const DType temperature) { index_t M = shape[axis]; if (M == 0) return; index_t N = shape.Size()/M; Shape<ndim> stride = calc_stride(shape); Shape<ndim> sshape = shape; sshape[axis] = 1; index_t sa = stride[axis]; if (length != nullptr) { #pragma omp parallel for for (index_t i = 0; i < N; ++i) { index_t base = unravel_dot(i, sshape, stride); index_t len = static_cast<index_t>(length[i]); AType sum = AType(0); for (index_t j = 0; j < len; ++j) { sum += OP1::Map(ograd[base + j*sa], out[base + j*sa]); } // By default temperature is 1.0. // Adding a branch here to save the CPU 'divide-by-1' computation at runtime DType final_result; if (temperature == 1.0) { for (index_t j = 0; j < M; ++j) { final_result = negate ? -OP2::Map(ograd[base + j*sa], out[base + j*sa], sum) : OP2::Map(ograd[base + j*sa], out[base + j*sa], sum); final_result = (j < len) ? final_result : DType(0.0f); KERNEL_ASSIGN(igrad[base + j*sa], Req, final_result); } } else { for (index_t j = 0; j < M; ++j) { final_result = negate ? -OP2::Map(ograd[base + j*sa], out[base + j*sa], sum) / temperature : OP2::Map(ograd[base + j*sa], out[base + j*sa], sum) / temperature; final_result = (j < len) ? final_result : DType(0.0f); KERNEL_ASSIGN(igrad[base + j*sa], Req, final_result); } } } } else { #pragma omp parallel for for (index_t i = 0; i < N; ++i) { index_t base = unravel_dot(i, sshape, stride); AType sum = AType(0); for (index_t j = 0; j < M; ++j) { sum += OP1::Map(ograd[base + j*sa], out[base + j*sa]); } // By default temperature is 1.0. // Adding a branch here to save the CPU 'divide-by-1' computation at runtime DType final_result; if (temperature == 1.0) { for (index_t j = 0; j < M; ++j) { final_result = negate ? -OP2::Map(ograd[base + j*sa], out[base + j*sa], sum) : OP2::Map(ograd[base + j*sa], out[base + j*sa], sum); KERNEL_ASSIGN(igrad[base + j*sa], Req, final_result); } } else { for (index_t j = 0; j < M; ++j) { final_result = negate ? -OP2::Map(ograd[base + j*sa], out[base + j*sa], sum) / temperature : OP2::Map(ograd[base + j*sa], out[base + j*sa], sum) / temperature; KERNEL_ASSIGN(igrad[base + j*sa], Req, final_result); } } } } } #ifdef __CUDACC__ template<int x_bits, typename OP, bool negate, typename AType, int ndim, typename DType, typename OType, typename IType> __global__ void softmax_compute_kernel(DType *in, OType *out, IType *length, index_t M, int axis, Shape<ndim> sshape, Shape<ndim> stride, const double temperature) { const unsigned x_size = 1 << x_bits; __shared__ AType smem[x_size]; index_t sa = stride[axis]; index_t base = unravel_dot(blockIdx.x, sshape, stride); index_t x = threadIdx.x; const index_t len = length == nullptr ? M : static_cast<index_t>(length[blockIdx.x]); red::maximum::SetInitValue(smem[x]); for (index_t i = x; i < len; i += x_size) { smem[x] = ::max(smem[x], negate ? -in[base + i*sa] : in[base + i*sa]); } __syncthreads(); cuda::Reduce1D<red::maximum, x_bits>(smem); __syncthreads(); DType smax = smem[0]; __syncthreads(); red::sum::SetInitValue(smem[x]); DType val; for (index_t i = x; i < len; i += x_size) { val = negate ? -in[base + i*sa]:in[base + i*sa]; smem[x] += static_cast<AType>(expf((val - smax) / static_cast<AType>(temperature))); } __syncthreads(); cuda::Reduce1D<red::sum, x_bits>(smem); __syncthreads(); AType ssum = smem[0]; __syncthreads(); for (index_t i = x; i < M; i += x_size) { val = negate ? -in[base + i*sa] : in[base + i*sa]; out[base + i*sa] = (i < len) ? OType(OP::Map((val - smax)/static_cast<DType>(temperature), ssum)) : OType(0.0f); } } const int softmax_threads_per_block = 512; template<typename OP, bool negate, typename AType, typename LType, typename DType, typename OType, typename IType> __global__ void softmax_stride1_compute_kernel(const DType *in, OType *out, IType *length, const index_t M, const double temperature, const int rows_per_block, const index_t total_rows) { __shared__ AType scratch[softmax_threads_per_block]; __shared__ LType persistent_storage[20 * 1024 / sizeof(LType)]; const int warp_size = 32; const int threads_per_row = softmax_threads_per_block / rows_per_block; const int my_local_row = threadIdx.x / threads_per_row; const int my_row = blockIdx.x * rows_per_block + my_local_row; if (my_row >= total_rows) return; const int my_id = threadIdx.x % threads_per_row; const int entries_per_load = sizeof(LType)/sizeof(DType); const index_t len = length == nullptr ? M : static_cast<index_t>(length[my_row]); // Due to usage of MSHADOW_TYPE_SWITCH macro we are generating // kernels where sizeof(LType) may be less than sizeof(DType), // resulting in entries_per_load being 0. // This is not a valid combination and is being checked against // in the launcher code. This switch here is just to silence // the division by zero warning generated for such invalid cases. const int row_length = entries_per_load > 0 ? M / entries_per_load : 0; const LType* in_aligned = reinterpret_cast<const LType*>(in); size_t base = my_row * row_length; for (index_t i = my_id; i < row_length; i += threads_per_row) { persistent_storage[my_local_row * row_length + i] = in_aligned[base + i]; } DType * row = reinterpret_cast<DType *>(persistent_storage + my_local_row * row_length); __syncthreads(); DType my_max_value; red::maximum::SetInitValue(my_max_value); for (index_t i = my_id; i < len; i += threads_per_row) { my_max_value = ::max(my_max_value, negate ? -row[i] : row[i]); } scratch[threadIdx.x] = my_max_value; __syncthreads(); for (int size = threads_per_row / 2; size >= warp_size; size /= 2) { if (my_id < size) { scratch[threadIdx.x] = ::max(scratch[threadIdx.x], scratch[threadIdx.x + size]); } __syncthreads(); } if (my_id < warp_size) { AType my_value = common::cuda::warp_reduce(scratch[threadIdx.x], [](AType x, AType y) { return ::max(x, y); }); scratch[threadIdx.x] = my_value; } __syncthreads(); DType smax = scratch[threadIdx.x - threadIdx.x % threads_per_row]; __syncthreads(); AType my_sum; red::sum::SetInitValue(my_sum); for (index_t i = my_id; i < len; i += threads_per_row) { const DType val = negate ? -row[i] : row[i]; my_sum += static_cast<AType>(expf((val - smax) / static_cast<AType>(temperature))); } scratch[threadIdx.x] = my_sum; __syncthreads(); for (int size = threads_per_row / 2; size >= warp_size; size /= 2) { if (my_id < size) { scratch[threadIdx.x] += scratch[threadIdx.x + size]; } __syncthreads(); } if (my_id < warp_size) { AType my_value = common::cuda::warp_reduce(scratch[threadIdx.x], [](AType x, AType y) { return x + y;}); scratch[threadIdx.x] = my_value; } __syncthreads(); AType ssum = scratch[threadIdx.x - threadIdx.x % threads_per_row]; __syncthreads(); for (index_t i = my_id; i < M; i += threads_per_row) { const DType val = negate ? -row[i] : row[i]; row[i] = (i < len) ? DType(OP::Map((val - smax)/static_cast<DType>(temperature), ssum)) : DType(0.0f); } __syncthreads(); LType* out_aligned = reinterpret_cast<LType*>(out); for (index_t i = my_id; i < row_length; i += threads_per_row) { out_aligned[base + i] = persistent_storage[my_local_row * row_length + i]; } } template<typename OP, bool negate, typename AType, typename DType, typename OType, typename IType, int ndim> inline void Softmax(Stream<gpu> *s, DType *in, OType *out, IType *length, Shape<ndim> shape, int axis, const double temperature) { const int x_bits = 7; const int x_size = 1 << x_bits; index_t M = shape[axis]; if (M == 0 || shape.Size() == 0) return; index_t N = shape.Size()/M; Shape<ndim> stride = calc_stride(shape); Shape<ndim> sshape = shape; sshape[axis] = 1; const size_t DSize = sizeof(DType); // Using 20 kB of shared memory for persistent storage in the optimized case const size_t max_opt_M = 20 * 1024 / DSize; if (stride[axis] == 1 && static_cast<size_t>(M) <= max_opt_M && std::is_same<DType, OType>::value) { int ltype = mxnet::common::cuda::get_load_type(M * sizeof(DType)); MXNET_LOAD_TYPE_SWITCH(ltype, LType, { int rows_per_block = mxnet::common::cuda::get_rows_per_block(M * sizeof(DType) / sizeof(LType), softmax_threads_per_block); int nblocks = (N + rows_per_block - 1) / rows_per_block; CHECK_LE(sizeof(DType), sizeof(LType)); softmax_stride1_compute_kernel<OP, negate, AType, LType> <<<nblocks, softmax_threads_per_block, 0, mshadow::Stream<gpu>::GetStream(s)>>>( in, out, length, M, temperature, rows_per_block, N); }); MSHADOW_CUDA_POST_KERNEL_CHECK(softmax_stride1_compute_kernel); } else { softmax_compute_kernel<x_bits, OP, negate, AType, ndim> <<<N, x_size, 0, mshadow::Stream<gpu>::GetStream(s)>>>( in, out, length, M, axis, sshape, stride, temperature); MSHADOW_CUDA_POST_KERNEL_CHECK(softmax_compute_kernel); } } template<typename OP1, typename OP2, int Req, bool negate, typename AType, typename LType, typename DType, typename OType, typename IType> __global__ void softmax_stride1_grad_kernel(const OType *out, const OType *ograd, DType *igrad, const IType *length, const index_t M, const double temperature, const int rows_per_block, const index_t total_rows) { __shared__ AType scratch[softmax_threads_per_block]; __shared__ LType persistent_storage[20 * 1024 / sizeof(LType)]; const int warp_size = 32; const int threads_per_row = softmax_threads_per_block / rows_per_block; const int my_local_row = threadIdx.x / threads_per_row; const int my_row = blockIdx.x * rows_per_block + my_local_row; if (my_row >= total_rows) return; const int my_id = threadIdx.x % threads_per_row; const int entries_per_load = sizeof(LType)/sizeof(DType); const index_t len = length == nullptr ? M : static_cast<index_t>(length[my_row]); // Due to usage of MSHADOW_TYPE_SWITCH macro we are generating // kernels where sizeof(LType) may be less than sizeof(DType), // resulting in entries_per_load being 0. // This is not a valid combination and is being checked against // in the launcher code. This switch here is just to silence // the division by zero warning generated for such invalid cases. const int row_length = entries_per_load > 0 ? M / entries_per_load : 0; const LType* out_aligned = reinterpret_cast<const LType*>(out); const LType* ograd_aligned = reinterpret_cast<const LType*>(ograd); size_t base = my_row * row_length; for (index_t i = my_id; i < row_length; i += threads_per_row) { persistent_storage[my_local_row * row_length * 2 + i] = out_aligned[base + i]; persistent_storage[my_local_row * row_length * 2 + row_length + i] = ograd_aligned[base + i]; } DType * row = reinterpret_cast<DType *>(persistent_storage + my_local_row * row_length * 2); __syncthreads(); AType my_sum_value; red::sum::SetInitValue(my_sum_value); for (index_t i = my_id; i < len; i += threads_per_row) { my_sum_value += OP1::Map(row[i + M], row[i]); } scratch[threadIdx.x] = my_sum_value; __syncthreads(); for (int size = threads_per_row / 2; size >= warp_size; size /= 2) { if (my_id < size) { scratch[threadIdx.x] = scratch[threadIdx.x] + scratch[threadIdx.x + size]; } __syncthreads(); } if (my_id < warp_size) { AType my_value = common::cuda::warp_reduce(scratch[threadIdx.x], [](AType x, AType y) { return x + y; }); scratch[threadIdx.x] = my_value; } __syncthreads(); AType ssum = scratch[threadIdx.x - threadIdx.x % threads_per_row]; __syncthreads(); for (index_t i = my_id; i < M; i += threads_per_row) { const DType val = negate ? -OP2::Map(row[i + M], row[i], ssum) : OP2::Map(row[i + M], row[i], ssum); row[i] = (i < len) ? DType(val / static_cast<DType>(temperature)) : DType(0.0f); if (Req == kAddTo) { row[i] += igrad[my_row * M + i]; } } __syncthreads(); LType* igrad_aligned = reinterpret_cast<LType*>(igrad); for (index_t i = my_id; i < row_length; i += threads_per_row) { igrad_aligned[base + i] = persistent_storage[my_local_row * row_length * 2 + i]; } } template<int x_bits, typename OP1, typename OP2, int Req, bool negate, typename AType, int ndim, typename DType, typename OType, typename IType> __global__ void softmax_grad_kernel(OType *out, OType *ograd, DType *igrad, const IType *length, index_t M, int axis, Shape<ndim> sshape, Shape<ndim> stride, const double temperature) { const unsigned x_size = 1 << x_bits; __shared__ AType smem[x_size]; index_t sa = stride[axis]; index_t base = unravel_dot(blockIdx.x, sshape, stride); index_t x = threadIdx.x; index_t len = length != nullptr ? static_cast<index_t>(length[blockIdx.x]) : M; red::sum::SetInitValue(smem[x]); for (index_t i = x; i < len; i += x_size) { smem[x] += OP1::Map(ograd[base + i*sa], out[base + i*sa]); } __syncthreads(); cuda::Reduce1D<red::sum, x_bits>(smem); __syncthreads(); AType ssum = smem[0]; __syncthreads(); DType final_result; for (index_t i = x; i < M; i += x_size) { final_result = negate ? -OP2::Map(ograd[base + i*sa], out[base + i*sa], ssum) : OP2::Map(ograd[base + i*sa], out[base + i*sa], ssum); final_result = (i < len) ? final_result : DType(0.0f); KERNEL_ASSIGN(igrad[base + i*sa], Req, final_result / static_cast<DType>(temperature)); } } template<typename OP1, typename OP2, int Req, bool negate, typename AType, int ndim, typename DType, typename OType, typename IType> inline void SoftmaxGrad(Stream<gpu> *s, OType *out, OType *ograd, DType *igrad, IType *length, Shape<ndim> shape, int axis, const double temperature) { const int x_bits = 7; const int x_size = 1 << x_bits; index_t M = shape[axis]; if (M == 0 || shape.Size() == 0) return; index_t N = shape.Size()/M; Shape<ndim> stride = calc_stride(shape); Shape<ndim> sshape = shape; sshape[axis] = 1; const size_t DSize = sizeof(DType); // Using 20 kB of shared memory for persistent storage in the optimized case // Need to store both out and ograd, so M can be only half compared to // forward pass. const size_t max_opt_M = 20 * 1024 / DSize / 2; if (stride[axis] == 1 && static_cast<size_t>(M) <= max_opt_M && std::is_same<DType, OType>::value) { int ltype = mxnet::common::cuda::get_load_type(M * sizeof(DType)); MXNET_LOAD_TYPE_SWITCH(ltype, LType, { int rows_per_block = mxnet::common::cuda::get_rows_per_block(M * sizeof(DType) / sizeof(LType), softmax_threads_per_block); int nblocks = (N + rows_per_block - 1) / rows_per_block; CHECK_LE(sizeof(DType), sizeof(LType)); softmax_stride1_grad_kernel<OP1, OP2, Req, negate, AType, LType> <<<nblocks, softmax_threads_per_block, 0, mshadow::Stream<gpu>::GetStream(s)>>>( out, ograd, igrad, length, M, temperature, rows_per_block, N); }); MSHADOW_CUDA_POST_KERNEL_CHECK(softmax_stride1_grad_kernel); } else { softmax_grad_kernel<x_bits, OP1, OP2, Req, negate, AType, ndim> <<<N, x_size, 0, mshadow::Stream<gpu>::GetStream(s)>>>( out, ograd, igrad, length, M, axis, sshape, stride, temperature); MSHADOW_CUDA_POST_KERNEL_CHECK(softmax_grad_kernel); } } #endif } // namespace mxnet_op struct SoftmaxParam : public dmlc::Parameter<SoftmaxParam> { int axis; dmlc::optional<double> temperature; dmlc::optional<int> dtype; dmlc::optional<bool> use_length; DMLC_DECLARE_PARAMETER(SoftmaxParam) { DMLC_DECLARE_FIELD(axis).set_default(-1) .describe("The axis along which to compute softmax."); DMLC_DECLARE_FIELD(temperature).set_default(dmlc::optional<double>()) .describe("Temperature parameter in softmax"); DMLC_DECLARE_FIELD(dtype) .add_enum("float16", mshadow::kFloat16) .add_enum("float32", mshadow::kFloat32) .add_enum("float64", mshadow::kFloat64) .set_default(dmlc::optional<int>()) .describe("DType of the output in case this can't be inferred. " "Defaults to the same as input's dtype if not defined (dtype=None)."); DMLC_DECLARE_FIELD(use_length) .set_default(dmlc::optional<bool>(false)) .describe("Whether to use the length input as a mask over the data input."); } bool operator==(const SoftmaxParam& other) const { return this->axis == other.axis && this->temperature == other.temperature && this->dtype == other.dtype && this->use_length == other.use_length; } }; static inline bool softmax_has_dtype_override(const nnvm::NodeAttrs& attrs) { const SoftmaxParam& param = nnvm::get<SoftmaxParam>(attrs.parsed); return param.dtype.has_value() && param.dtype.value() != -1; } static inline bool softmax_use_length(const nnvm::NodeAttrs& attrs) { const SoftmaxParam& param = nnvm::get<SoftmaxParam>(attrs.parsed); return param.use_length.value(); } static inline bool SoftmaxOpType(const nnvm::NodeAttrs& attrs, std::vector<int>* in_attrs, std::vector<int>* out_attrs) { CHECK_EQ(out_attrs->size(), 1); const SoftmaxParam& param = nnvm::get<SoftmaxParam>(attrs.parsed); CHECK_EQ(in_attrs->size(), softmax_use_length(attrs) ? 2U : 1U); if (softmax_has_dtype_override(attrs)) { TYPE_ASSIGN_CHECK(*out_attrs, 0, param.dtype.value()); type_assign(&(*in_attrs)[0], (*out_attrs)[0]); return true; } else { std::vector<int> tmp = {in_attrs->at(0)}; return ElemwiseType<1, 1>(attrs, &tmp, out_attrs); } } static inline bool SoftmaxOpShape(const nnvm::NodeAttrs& attrs, mxnet::ShapeVector *in_attrs, mxnet::ShapeVector *out_attrs) { CHECK_EQ(out_attrs->size(), 1U); const SoftmaxParam& param = nnvm::get<SoftmaxParam>(attrs.parsed); CHECK_EQ(in_attrs->size(), param.use_length.value() ? 2U : 1U); if (param.use_length.value()) { mxnet::TShape& dshape = in_attrs->at(0); mxnet::TShape tmp_shape((dshape.ndim() == 1) ? 1U : dshape.ndim() - 1, 1); int j = 0; int axis = param.axis != -1 ? param.axis : dshape.ndim() - 1; for (int i = 0; i < dshape.ndim(); ++i) { if (i != axis) { tmp_shape[j++] = dshape[i]; } } SHAPE_ASSIGN_CHECK(*in_attrs, 1, tmp_shape); } mxnet::ShapeVector tmp = {in_attrs->at(0)}; return ElemwiseShape<1, 1>(attrs, &tmp, out_attrs); } static inline bool SoftmaxGradOpShape(const nnvm::NodeAttrs& attrs, mxnet::ShapeVector *in_attrs, mxnet::ShapeVector *out_attrs) { if (softmax_has_dtype_override(attrs) || softmax_use_length(attrs)) { if (softmax_use_length(attrs)) { mxnet::ShapeVector ins = {in_attrs->at(0), in_attrs->at(1), in_attrs->at(3)}; mxnet::ShapeVector dgrad = {out_attrs->at(0)}; bool res = ElemwiseShape<3, 1>(attrs, &ins, &dgrad); SHAPE_ASSIGN_CHECK(*in_attrs, 0, ins[0]); SHAPE_ASSIGN_CHECK(*in_attrs, 1, ins[1]); SHAPE_ASSIGN_CHECK(*in_attrs, 3, ins[2]); SHAPE_ASSIGN_CHECK(*out_attrs, 0, dgrad[0]); mxnet::ShapeVector length = {in_attrs->at(2)}; mxnet::ShapeVector lgrad = {out_attrs->at(1)}; res = (res && ElemwiseShape<1, 1>(attrs, &length, &lgrad)); SHAPE_ASSIGN_CHECK(*in_attrs, 2, length[0]); SHAPE_ASSIGN_CHECK(*out_attrs, 1, lgrad[0]); return res; } else { return ElemwiseShape<3, 1>(attrs, in_attrs, out_attrs); } } else { return ElemwiseShape<2, 1>(attrs, in_attrs, out_attrs); } } static inline bool SoftmaxGradOpType(const nnvm::NodeAttrs& attrs, std::vector<int>* in_attrs, std::vector<int>* out_attrs) { CHECK_EQ(out_attrs->size(), softmax_use_length(attrs) ? 2U : 1U); if (softmax_has_dtype_override(attrs) || softmax_use_length(attrs)) { CHECK_EQ(in_attrs->size(), softmax_use_length(attrs) ? 4U : 3U); int in_dtype = (*in_attrs)[1]; int out_dtype = (*in_attrs)[softmax_use_length(attrs) ? 3 : 2]; TYPE_ASSIGN_CHECK(*in_attrs, 0, out_dtype); TYPE_ASSIGN_CHECK(*out_attrs, 0, in_dtype); if (softmax_use_length(attrs)) { TYPE_ASSIGN_CHECK(*out_attrs, 1, in_attrs->at(2)); } return (*out_attrs)[0] != -1 && (*in_attrs)[0] != -1 && (!softmax_use_length(attrs) || ((*out_attrs)[1] != -1 && (*in_attrs)[1] != -1)); } else { CHECK_EQ(in_attrs->size(), 2U); int out_dtype = (*in_attrs)[1]; TYPE_ASSIGN_CHECK(*out_attrs, 0, out_dtype); TYPE_ASSIGN_CHECK(*in_attrs, 0, out_dtype); return (*out_attrs)[0] != -1 && (*in_attrs)[0] != -1; } } static inline std::vector<std::pair<int, int> > SoftmaxGradOpInplaceOption(const nnvm::NodeAttrs& attrs) { if (softmax_has_dtype_override(attrs) || softmax_use_length(attrs)) { if (softmax_use_length(attrs)) { return std::vector<std::pair<int, int> >{{0, 0}, {1, 0}, {2, 1}, {3, 0}}; } else { return std::vector<std::pair<int, int> >{{0, 0}, {1, 0}, {2, 0}}; } } else { return std::vector<std::pair<int, int> >{{0, 0}, {1, 0}}; } } static inline uint32_t SoftmaxGradOpNumInputs(const nnvm::NodeAttrs& attrs) { if (softmax_has_dtype_override(attrs) || softmax_use_length(attrs)) { return softmax_use_length(attrs) ? 4 : 3; } return 2; } static inline std::vector<std::string> SoftmaxGradOpInputNames(const nnvm::NodeAttrs& attrs) { if (softmax_has_dtype_override(attrs) || softmax_use_length(attrs)) { if (softmax_use_length(attrs)) { return std::vector<std::string>{"ograd", "data", "length", "output"}; } else { return std::vector<std::string>{"ograd", "data", "output"}; } } else { return std::vector<std::string>{"ograd", "output"}; } } struct SoftmaxFGradient { const char *op_name; std::vector<nnvm::NodeEntry> operator()(const nnvm::ObjectPtr& n, const std::vector<nnvm::NodeEntry>& ograds) const { if (softmax_has_dtype_override(n->attrs) || softmax_use_length(n->attrs)) { return ElemwiseGradUseInOut {op_name}(n, ograds); } else { return ElemwiseGradUseOut {op_name}(n, ograds); } } }; template<typename xpu, typename OP, bool negate = false> void SoftmaxCompute(const nnvm::NodeAttrs& attrs, const OpContext& ctx, const std::vector<TBlob>& inputs, const std::vector<OpReqType>& req, const std::vector<TBlob>& outputs) { using namespace mxnet_op; if (req[0] == kNullOp || inputs[0].Size() == 0U) return; CHECK_NE(req[0], kAddTo); const SoftmaxParam& param = nnvm::get<SoftmaxParam>(attrs.parsed); int axis = CheckAxis(param.axis, inputs[0].ndim()); const double temperature = param.temperature.has_value() ? param.temperature.value() : 1.0; mxnet::TShape shape = AxisShapeCompact(inputs[0].shape_, &axis, true); bool safe_acc = dmlc::GetEnv("MXNET_SAFE_ACCUMULATION", false); if (!safe_acc && inputs[0].type_flag_ == mshadow::kFloat16) { common::LogOnce("MXNET_SAFE_ACCUMULATION=1 is recommended for softmax with float16 inputs. " "See https://mxnet.apache.org/api/faq/env_var " "for more details."); } MXNET_REAL_ACC_TYPE_SWITCH(inputs[0].type_flag_, DType, AType, { MSHADOW_REAL_TYPE_SWITCH(outputs[0].type_flag_, OType, { int type = kInt32; if (param.use_length.value()) { CHECK(inputs.size() > 1) << "Mask needs to be provided when using softmax with use_length=True."; type = inputs[1].type_flag_; } MXNET_INT32_INT64_TYPE_SWITCH(type, IType, { IType* mask_ptr = nullptr; if (param.use_length.value()) { mask_ptr = inputs[1].dptr<IType>(); } if (safe_acc) { if (shape.ndim() == 2) { Softmax<OP, negate, AType>( ctx.get_stream<xpu>(), inputs[0].dptr<DType>(), outputs[0].dptr<OType>(), mask_ptr, shape.get<2>(), axis, static_cast<DType>(temperature)); } else { Softmax<OP, negate, AType>( ctx.get_stream<xpu>(), inputs[0].dptr<DType>(), outputs[0].dptr<OType>(), mask_ptr, shape.get<3>(), axis, static_cast<DType>(temperature)); } } else { if (shape.ndim() == 2) { Softmax<OP, negate, DType>( ctx.get_stream<xpu>(), inputs[0].dptr<DType>(), outputs[0].dptr<OType>(), mask_ptr, shape.get<2>(), axis, static_cast<DType>(temperature)); } else { Softmax<OP, negate, DType>( ctx.get_stream<xpu>(), inputs[0].dptr<DType>(), outputs[0].dptr<OType>(), mask_ptr, shape.get<3>(), axis, static_cast<DType>(temperature)); } } }); }); }); } template<typename xpu, typename OP1, typename OP2, bool negate = false> void SoftmaxGradCompute(const nnvm::NodeAttrs& attrs, const OpContext& ctx, const std::vector<TBlob>& inputs, const std::vector<OpReqType>& req, const std::vector<TBlob>& outputs) { using namespace mxnet_op; if (softmax_use_length(attrs)) { MXNET_INT32_INT64_TYPE_SWITCH(inputs[2].type_flag_, IType, { if (req[1] != kNullOp) { mxnet_op::Kernel<mxnet_op::set_zero, xpu>::Launch( ctx.get_stream<xpu>(), outputs[1].Size(), outputs[1].dptr<IType>()); } }); } if (req[0] == kNullOp) return; const int itype = softmax_use_length(attrs) ? inputs[2].type_flag_ : kInt32; const SoftmaxParam& param = nnvm::get<SoftmaxParam>(attrs.parsed); int axis = CheckAxis(param.axis, inputs[0].ndim()); const double temperature = param.temperature.has_value() ? param.temperature.value() : 1.0; mxnet::TShape shape = AxisShapeCompact(inputs[0].shape_, &axis, true); int out_idx = softmax_has_dtype_override(attrs) ? 2 : 1; out_idx = softmax_use_length(attrs) ? 3 : out_idx; bool safe_acc = dmlc::GetEnv("MXNET_SAFE_ACCUMULATION", false); MXNET_REAL_ACC_TYPE_SWITCH(inputs[0].type_flag_, OType, AType, { MSHADOW_REAL_TYPE_SWITCH(outputs[0].type_flag_, DType, { MXNET_ASSIGN_REQ_SWITCH(req[0], Req, { MXNET_INT32_INT64_TYPE_SWITCH(itype, IType, { IType * length_ptr = nullptr; if (softmax_use_length(attrs)) { length_ptr = inputs[2].dptr<IType>(); } if (safe_acc) { if (shape.ndim() == 2) { SoftmaxGrad<OP1, OP2, Req, negate, AType>( ctx.get_stream<xpu>(), inputs[out_idx].dptr<OType>(), inputs[0].dptr<OType>(), outputs[0].dptr<DType>(), length_ptr, shape.get<2>(), axis, static_cast<DType>(temperature)); } else { SoftmaxGrad<OP1, OP2, Req, negate, AType>( ctx.get_stream<xpu>(), inputs[out_idx].dptr<OType>(), inputs[0].dptr<OType>(), outputs[0].dptr<DType>(), length_ptr, shape.get<3>(), axis, static_cast<DType>(temperature)); } } else { if (shape.ndim() == 2) { SoftmaxGrad<OP1, OP2, Req, negate, DType>( ctx.get_stream<xpu>(), inputs[out_idx].dptr<OType>(), inputs[0].dptr<OType>(), outputs[0].dptr<DType>(), length_ptr, shape.get<2>(), axis, static_cast<DType>(temperature)); } else { SoftmaxGrad<OP1, OP2, Req, negate, DType>( ctx.get_stream<xpu>(), inputs[out_idx].dptr<OType>(), inputs[0].dptr<OType>(), outputs[0].dptr<DType>(), length_ptr, shape.get<3>(), axis, static_cast<DType>(temperature)); } } }); }); }); }); } } // namespace op } // namespace mxnet namespace std { template<> struct hash<mxnet::op::SoftmaxParam> { size_t operator()(const mxnet::op::SoftmaxParam& val) { size_t ret = 0; ret = dmlc::HashCombine(ret, val.axis); ret = dmlc::HashCombine(ret, val.temperature); ret = dmlc::HashCombine(ret, val.dtype); ret = dmlc::HashCombine(ret, val.use_length); return ret; } }; } // namespace std #endif // MXNET_OPERATOR_NN_SOFTMAX_INL_H_
GB_unaryop__ainv_int64_int8.c
//------------------------------------------------------------------------------ // GB_unaryop: hard-coded functions for each built-in unary operator //------------------------------------------------------------------------------ // SuiteSparse:GraphBLAS, Timothy A. Davis, (c) 2017-2019, All Rights Reserved. // http://suitesparse.com See GraphBLAS/Doc/License.txt for license. //------------------------------------------------------------------------------ // If this file is in the Generated/ folder, do not edit it (auto-generated). #include "GB.h" #ifndef GBCOMPACT #include "GB_control.h" #include "GB_iterator.h" #include "GB_unaryop__include.h" // C=unop(A) is defined by the following types and operators: // op(A) function: GB_unop__ainv_int64_int8 // op(A') function: GB_tran__ainv_int64_int8 // C type: int64_t // A type: int8_t // cast: int64_t cij = (int64_t) aij // unaryop: cij = -aij #define GB_ATYPE \ int8_t #define GB_CTYPE \ int64_t // aij = Ax [pA] #define GB_GETA(aij,Ax,pA) \ int8_t aij = Ax [pA] #define GB_CX(p) Cx [p] // unary operator #define GB_OP(z, x) \ z = -x ; // casting #define GB_CASTING(z, x) \ int64_t z = (int64_t) x ; // cij = op (cast (aij)) #define GB_CAST_OP(pC,pA) \ { \ /* aij = Ax [pA] */ \ GB_GETA (aij, Ax, pA) ; \ /* Cx [pC] = op (cast (aij)) */ \ GB_CASTING (x, aij) ; \ GB_OP (GB_CX (pC), x) ; \ } // disable this operator and use the generic case if these conditions hold #define GB_DISABLE \ (GxB_NO_AINV || GxB_NO_INT64 || GxB_NO_INT8) //------------------------------------------------------------------------------ // Cx = op (cast (Ax)): apply a unary operator //------------------------------------------------------------------------------ GrB_Info GB_unop__ainv_int64_int8 ( int64_t *restrict Cx, const int8_t *restrict Ax, int64_t anz, int nthreads ) { #if GB_DISABLE return (GrB_NO_VALUE) ; #else #pragma omp parallel for num_threads(nthreads) schedule(static) for (int64_t p = 0 ; p < anz ; p++) { GB_CAST_OP (p, p) ; } return (GrB_SUCCESS) ; #endif } //------------------------------------------------------------------------------ // C = op (cast (A')): transpose, typecast, and apply a unary operator //------------------------------------------------------------------------------ GrB_Info GB_tran__ainv_int64_int8 ( GrB_Matrix C, const GrB_Matrix A, int64_t **Rowcounts, GBI_single_iterator Iter, const int64_t *restrict A_slice, int naslice ) { #if GB_DISABLE return (GrB_NO_VALUE) ; #else #define GB_PHASE_2_OF_2 #include "GB_unaryop_transpose.c" return (GrB_SUCCESS) ; #endif } #endif
bug_set_schedule_0.c
// RUN: %libomp-compile-and-run #include <stdio.h> #include <omp.h> #include "omp_testsuite.h" /* Test that the chunk size is set to default (1) when chunk size <= 0 is specified */ int a = 0; int test_set_schedule_0() { int i; a = 0; omp_set_schedule(omp_sched_dynamic,0); #pragma omp parallel { #pragma omp for schedule(runtime) for(i = 0; i < 10; i++) { #pragma omp atomic a++; if(a > 10) exit(1); } } return a==10; } int main() { int i; int num_failed=0; for(i = 0; i < REPETITIONS; i++) { if(!test_set_schedule_0()) { num_failed++; } } return num_failed; }
omp-single-3.c
extern void abort (void); void single (int a, int b) { #pragma omp single copyprivate(a) copyprivate(b) { a = b = 5; } if (a != b) abort (); } int main() { #pragma omp parallel single (1, 2); return 0; }
_hypre_struct_mv.h
/*** DO NOT EDIT THIS FILE DIRECTLY (use 'headers' to generate) ***/ #ifndef hypre_STRUCT_MV_HEADER #define hypre_STRUCT_MV_HEADER #include <stdlib.h> #include <stdio.h> #include <math.h> #include "HYPRE_struct_mv.h" #include "_hypre_utilities.h" #if defined(HYPRE_USING_RAJA) /****************************************************************************** * Copyright 1998-2019 Lawrence Livermore National Security, LLC and other * HYPRE Project Developers. See the top-level COPYRIGHT file for details. * * SPDX-License-Identifier: (Apache-2.0 OR MIT) ******************************************************************************/ /****************************************************************************** * * Header info for the BoxLoop * *****************************************************************************/ /*-------------------------------------------------------------------------- * BoxLoop macros: *--------------------------------------------------------------------------*/ #ifndef HYPRE_NEWBOXLOOP_HEADER #define HYPRE_NEWBOXLOOP_HEADER extern "C++" { #include <RAJA/RAJA.hpp> } using namespace RAJA; typedef struct hypre_Boxloop_struct { HYPRE_Int lsize0,lsize1,lsize2; HYPRE_Int strides0,strides1,strides2; HYPRE_Int bstart0,bstart1,bstart2; HYPRE_Int bsize0,bsize1,bsize2; } hypre_Boxloop; #if defined(HYPRE_USING_CUDA) /* RAJA with CUDA, running on device */ #define BLOCKSIZE 256 #define hypre_RAJA_DEVICE RAJA_DEVICE #define hypre_raja_exec_policy cuda_exec<BLOCKSIZE> /* #define hypre_raja_reduce_policy cuda_reduce_atomic<BLOCKSIZE> */ #define hypre_raja_reduce_policy cuda_reduce<BLOCKSIZE> #define hypre_fence() /* #define hypre_fence() \ cudaError err = cudaGetLastError();\ if ( cudaSuccess != err ) {\ printf("\n ERROR zypre_newBoxLoop: %s in %s(%d) function %s\n",cudaGetErrorString(err),__FILE__,__LINE__,__FUNCTION__); \ }\ hypre_CheckErrorDevice(cudaDeviceSynchronize()); */ #elif defined(HYPRE_USING_DEVICE_OPENMP) /* RAJA with OpenMP (>4.5), running on device */ //TODO #elif defined(HYPRE_USING_OPENMP) /* RAJA with OpenMP, running on host (CPU) */ #define hypre_RAJA_DEVICE #define hypre_raja_exec_policy omp_for_exec #define hypre_raja_reduce_policy omp_reduce #define hypre_fence() #else /* RAJA, running on host (CPU) */ #define hypre_RAJA_DEVICE #define hypre_raja_exec_policy seq_exec #define hypre_raja_reduce_policy seq_reduce #define hypre_fence() #endif /* #if defined(HYPRE_USING_CUDA) */ #define zypre_BoxLoopIncK(k,box,hypre__i) \ HYPRE_Int hypre_boxD##k = 1; \ HYPRE_Int hypre__i = 0; \ hypre__i += (hypre_IndexD(local_idx, 0)*box.strides0 + box.bstart0) * hypre_boxD##k; \ hypre_boxD##k *= hypre_max(0, box.bsize0 + 1); \ hypre__i += (hypre_IndexD(local_idx, 1)*box.strides1 + box.bstart1) * hypre_boxD##k; \ hypre_boxD##k *= hypre_max(0, box.bsize1 + 1); \ hypre__i += (hypre_IndexD(local_idx, 2)*box.strides2 + box.bstart2) * hypre_boxD##k; \ hypre_boxD##k *= hypre_max(0, box.bsize2 + 1); \ #define zypre_newBoxLoopInit(ndim,loop_size) \ HYPRE_Int hypre__tot = 1; \ for (HYPRE_Int d = 0;d < ndim;d ++) \ hypre__tot *= loop_size[d]; #define zypre_newBoxLoopDeclare(box) \ hypre_Index local_idx; \ HYPRE_Int idx_local = idx; \ hypre_IndexD(local_idx, 0) = idx_local % box.lsize0; \ idx_local = idx_local / box.lsize0; \ hypre_IndexD(local_idx, 1) = idx_local % box.lsize1; \ idx_local = idx_local / box.lsize1; \ hypre_IndexD(local_idx, 2) = idx_local % box.lsize2; #define zypre_BoxLoopDataDeclareK(k,ndim,loop_size,dbox,start,stride) \ hypre_Boxloop databox##k; \ databox##k.lsize0 = loop_size[0]; \ databox##k.strides0 = stride[0]; \ databox##k.bstart0 = start[0] - dbox->imin[0]; \ databox##k.bsize0 = dbox->imax[0]-dbox->imin[0]; \ if (ndim > 1) \ { \ databox##k.lsize1 = loop_size[1]; \ databox##k.strides1 = stride[1]; \ databox##k.bstart1 = start[1] - dbox->imin[1]; \ databox##k.bsize1 = dbox->imax[1]-dbox->imin[1]; \ } \ else \ { \ databox##k.lsize1 = 1; \ databox##k.strides1 = 0; \ databox##k.bstart1 = 0; \ databox##k.bsize1 = 0; \ } \ if (ndim == 3) \ { \ databox##k.lsize2 = loop_size[2]; \ databox##k.strides2 = stride[2]; \ databox##k.bstart2 = start[2] - dbox->imin[2]; \ databox##k.bsize2 = dbox->imax[2]-dbox->imin[2]; \ } \ else \ { \ databox##k.lsize2 = 1; \ databox##k.strides2 = 0; \ databox##k.bstart2 = 0; \ databox##k.bsize2 = 0; \ } #define zypre_newBoxLoop0Begin(ndim, loop_size) \ { \ zypre_newBoxLoopInit(ndim,loop_size); \ forall< hypre_raja_exec_policy >(RangeSegment(0, hypre__tot), [=] hypre_RAJA_DEVICE (HYPRE_Int idx) \ { #define zypre_newBoxLoop0End() \ }); \ hypre_fence(); \ } #define zypre_newBoxLoop1Begin(ndim, loop_size, \ dbox1, start1, stride1, i1) \ { \ zypre_newBoxLoopInit(ndim,loop_size); \ zypre_BoxLoopDataDeclareK(1,ndim,loop_size,dbox1,start1,stride1); \ forall< hypre_raja_exec_policy >(RangeSegment(0, hypre__tot), [=] hypre_RAJA_DEVICE (HYPRE_Int idx) \ { \ zypre_newBoxLoopDeclare(databox1); \ zypre_BoxLoopIncK(1,databox1,i1); #define zypre_newBoxLoop1End(i1) \ }); \ hypre_fence(); \ } #define zypre_newBoxLoop2Begin(ndim, loop_size, \ dbox1, start1, stride1, i1, \ dbox2, start2, stride2, i2) \ { \ zypre_newBoxLoopInit(ndim,loop_size); \ zypre_BoxLoopDataDeclareK(1,ndim,loop_size,dbox1,start1,stride1); \ zypre_BoxLoopDataDeclareK(2,ndim,loop_size,dbox2,start2,stride2); \ forall< hypre_raja_exec_policy >(RangeSegment(0, hypre__tot), [=] hypre_RAJA_DEVICE (HYPRE_Int idx) \ { \ zypre_newBoxLoopDeclare(databox1); \ zypre_BoxLoopIncK(1,databox1,i1); \ zypre_BoxLoopIncK(2,databox2,i2); #define zypre_newBoxLoop2End(i1, i2) \ }); \ hypre_fence(); \ } #define zypre_newBoxLoop3Begin(ndim, loop_size, \ dbox1, start1, stride1, i1, \ dbox2, start2, stride2, i2, \ dbox3, start3, stride3, i3) \ { \ zypre_newBoxLoopInit(ndim,loop_size); \ zypre_BoxLoopDataDeclareK(1,ndim,loop_size,dbox1,start1,stride1); \ zypre_BoxLoopDataDeclareK(2,ndim,loop_size,dbox2,start2,stride2); \ zypre_BoxLoopDataDeclareK(3,ndim,loop_size,dbox3,start3,stride3); \ forall< hypre_raja_exec_policy >(RangeSegment(0, hypre__tot), [=] hypre_RAJA_DEVICE (HYPRE_Int idx) \ { \ zypre_newBoxLoopDeclare(databox1); \ zypre_BoxLoopIncK(1,databox1,i1); \ zypre_BoxLoopIncK(2,databox2,i2); \ zypre_BoxLoopIncK(3,databox3,i3); #define zypre_newBoxLoop3End(i1, i2, i3) \ }); \ hypre_fence(); \ } #define zypre_newBoxLoop4Begin(ndim, loop_size, \ dbox1, start1, stride1, i1, \ dbox2, start2, stride2, i2, \ dbox3, start3, stride3, i3, \ dbox4, start4, stride4, i4) \ { \ zypre_newBoxLoopInit(ndim,loop_size); \ zypre_BoxLoopDataDeclareK(1,ndim,loop_size,dbox1,start1,stride1); \ zypre_BoxLoopDataDeclareK(2,ndim,loop_size,dbox2,start2,stride2); \ zypre_BoxLoopDataDeclareK(3,ndim,loop_size,dbox3,start3,stride3); \ zypre_BoxLoopDataDeclareK(4,ndim,loop_size,dbox4,start4,stride4); \ forall< hypre_raja_exec_policy >(RangeSegment(0, hypre__tot), [=] hypre_RAJA_DEVICE (HYPRE_Int idx) \ { \ zypre_newBoxLoopDeclare(databox1); \ zypre_BoxLoopIncK(1,databox1,i1); \ zypre_BoxLoopIncK(2,databox2,i2); \ zypre_BoxLoopIncK(3,databox3,i3); \ zypre_BoxLoopIncK(4,databox4,i4); #define zypre_newBoxLoop4End(i1, i2, i3, i4) \ }); \ hypre_fence(); \ } #define zypre_BasicBoxLoopDataDeclareK(k,ndim,loop_size,stride) \ hypre_Boxloop databox##k; \ databox##k.lsize0 = loop_size[0]; \ databox##k.strides0 = stride[0]; \ databox##k.bstart0 = 0; \ databox##k.bsize0 = 0; \ if (ndim > 1) \ { \ databox##k.lsize1 = loop_size[1]; \ databox##k.strides1 = stride[1]; \ databox##k.bstart1 = 0; \ databox##k.bsize1 = 0; \ } \ else \ { \ databox##k.lsize1 = 1; \ databox##k.strides1 = 0; \ databox##k.bstart1 = 0; \ databox##k.bsize1 = 0; \ } \ if (ndim == 3) \ { \ databox##k.lsize2 = loop_size[2]; \ databox##k.strides2 = stride[2]; \ databox##k.bstart2 = 0; \ databox##k.bsize2 = 0; \ } \ else \ { \ databox##k.lsize2 = 1; \ databox##k.strides2 = 0; \ databox##k.bstart2 = 0; \ databox##k.bsize2 = 0; \ } #define zypre_newBasicBoxLoop2Begin(ndim, loop_size, \ stride1, i1, \ stride2, i2) \ { \ zypre_newBoxLoopInit(ndim,loop_size); \ zypre_BasicBoxLoopDataDeclareK(1,ndim,loop_size,stride1); \ zypre_BasicBoxLoopDataDeclareK(2,ndim,loop_size,stride2); \ forall< hypre_raja_exec_policy >(RangeSegment(0, hypre__tot), [=] hypre_RAJA_DEVICE (HYPRE_Int idx) \ { \ zypre_newBoxLoopDeclare(databox1); \ zypre_BoxLoopIncK(1,databox1,i1); \ zypre_BoxLoopIncK(2,databox2,i2); \ #define hypre_LoopBegin(size,idx) \ { \ forall< hypre_raja_exec_policy >(RangeSegment(0, size), [=] hypre_RAJA_DEVICE (HYPRE_Int idx) \ { #define hypre_LoopEnd() \ }); \ hypre_fence(); \ } #define zypre_newBoxLoopSetOneBlock() #define hypre_newBoxLoopGetIndex(index) \ index[0] = hypre_IndexD(local_idx, 0); \ index[1] = hypre_IndexD(local_idx, 1); \ index[2] = hypre_IndexD(local_idx, 2); #define hypre_BoxLoopGetIndex zypre_BoxLoopGetIndex #define hypre_BoxLoopSetOneBlock zypre_newBoxLoopSetOneBlock #define hypre_BoxLoopBlock() 0 #define hypre_BoxLoop0Begin zypre_newBoxLoop0Begin #define hypre_BoxLoop0For zypre_newBoxLoop0For #define hypre_BoxLoop0End zypre_newBoxLoop0End #define hypre_BoxLoop1Begin zypre_newBoxLoop1Begin #define hypre_BoxLoop1For zypre_newBoxLoop1For #define hypre_BoxLoop1End zypre_newBoxLoop1End #define hypre_BoxLoop2Begin zypre_newBoxLoop2Begin #define hypre_BoxLoop2For zypre_newBoxLoop2For #define hypre_BoxLoop2End zypre_newBoxLoop2End #define hypre_BoxLoop3Begin zypre_newBoxLoop3Begin #define hypre_BoxLoop3For zypre_newBoxLoop3For #define hypre_BoxLoop3End zypre_newBoxLoop3End #define hypre_BoxLoop4Begin zypre_newBoxLoop4Begin #define hypre_BoxLoop4For zypre_newBoxLoop4For #define hypre_BoxLoop4End zypre_newBoxLoop4End #define hypre_newBoxLoopInit zypre_newBoxLoopInit #define hypre_BasicBoxLoop2Begin zypre_newBasicBoxLoop2Begin /* Reduction */ #define hypre_BoxLoop1ReductionBegin(ndim, loop_size, dbox1, start1, stride1, i1, reducesum) \ hypre_BoxLoop1Begin(ndim, loop_size, dbox1, start1, stride1, i1) #define hypre_BoxLoop1ReductionEnd(i1, reducesum) \ hypre_BoxLoop1End(i1) #define hypre_BoxLoop2ReductionBegin(ndim, loop_size, dbox1, start1, stride1, i1, \ dbox2, start2, stride2, i2, reducesum) \ hypre_BoxLoop2Begin(ndim, loop_size, dbox1, start1, stride1, i1, \ dbox2, start2, stride2, i2) #define hypre_BoxLoop2ReductionEnd(i1, i2, reducesum) \ hypre_BoxLoop2End(i1, i2) #endif #elif defined(HYPRE_USING_KOKKOS) /****************************************************************************** * Copyright 1998-2019 Lawrence Livermore National Security, LLC and other * HYPRE Project Developers. See the top-level COPYRIGHT file for details. * * SPDX-License-Identifier: (Apache-2.0 OR MIT) ******************************************************************************/ /****************************************************************************** * * Header info for the BoxLoop * *****************************************************************************/ /*-------------------------------------------------------------------------- * BoxLoop macros: *--------------------------------------------------------------------------*/ #ifndef HYPRE_NEWBOXLOOP_HEADER #define HYPRE_NEWBOXLOOP_HEADER extern "C++" { #include <Kokkos_Core.hpp> using namespace Kokkos; } #if defined( KOKKOS_HAVE_MPI ) #include <mpi.h> #endif typedef struct hypre_Boxloop_struct { HYPRE_Int lsize0,lsize1,lsize2; HYPRE_Int strides0,strides1,strides2; HYPRE_Int bstart0,bstart1,bstart2; HYPRE_Int bsize0,bsize1,bsize2; } hypre_Boxloop; #define hypre_fence() /* #define hypre_fence() \ cudaError err = cudaGetLastError(); \ if ( cudaSuccess != err ) { \ printf("\n ERROR hypre_newBoxLoop: %s in %s(%d) function %s\n", cudaGetErrorString(err),__FILE__,__LINE__,__FUNCTION__); \ } \ hypre_CheckErrorDevice(cudaDeviceSynchronize()); */ #define hypre_newBoxLoopInit(ndim,loop_size) \ HYPRE_Int hypre__tot = 1; \ for (HYPRE_Int d = 0;d < ndim;d ++) \ hypre__tot *= loop_size[d]; #define hypre_BoxLoopIncK(k,box,hypre__i) \ HYPRE_Int hypre_boxD##k = 1; \ HYPRE_Int hypre__i = 0; \ hypre__i += (hypre_IndexD(local_idx, 0)*box.strides0 + box.bstart0) * hypre_boxD##k; \ hypre_boxD##k *= hypre_max(0, box.bsize0 + 1); \ hypre__i += (hypre_IndexD(local_idx, 1)*box.strides1 + box.bstart1) * hypre_boxD##k; \ hypre_boxD##k *= hypre_max(0, box.bsize1 + 1); \ hypre__i += (hypre_IndexD(local_idx, 2)*box.strides2 + box.bstart2) * hypre_boxD##k; \ hypre_boxD##k *= hypre_max(0, box.bsize2 + 1); \ #define hypre_newBoxLoopDeclare(box) \ hypre_Index local_idx; \ HYPRE_Int idx_local = idx; \ hypre_IndexD(local_idx, 0) = idx_local % box.lsize0; \ idx_local = idx_local / box.lsize0; \ hypre_IndexD(local_idx, 1) = idx_local % box.lsize1; \ idx_local = idx_local / box.lsize1; \ hypre_IndexD(local_idx, 2) = idx_local % box.lsize2; #define hypre_BoxLoopDataDeclareK(k,ndim,loop_size,dbox,start,stride) \ hypre_Boxloop databox##k; \ databox##k.lsize0 = loop_size[0]; \ databox##k.strides0 = stride[0]; \ databox##k.bstart0 = start[0] - dbox->imin[0]; \ databox##k.bsize0 = dbox->imax[0]-dbox->imin[0]; \ if (ndim > 1) \ { \ databox##k.lsize1 = loop_size[1]; \ databox##k.strides1 = stride[1]; \ databox##k.bstart1 = start[1] - dbox->imin[1]; \ databox##k.bsize1 = dbox->imax[1]-dbox->imin[1]; \ } \ else \ { \ databox##k.lsize1 = 1; \ databox##k.strides1 = 0; \ databox##k.bstart1 = 0; \ databox##k.bsize1 = 0; \ } \ if (ndim == 3) \ { \ databox##k.lsize2 = loop_size[2]; \ databox##k.strides2 = stride[2]; \ databox##k.bstart2 = start[2] - dbox->imin[2]; \ databox##k.bsize2 = dbox->imax[2]-dbox->imin[2]; \ } \ else \ { \ databox##k.lsize2 = 1; \ databox##k.strides2 = 0; \ databox##k.bstart2 = 0; \ databox##k.bsize2 = 0; \ } #define hypre_newBoxLoop0Begin(ndim, loop_size) \ { \ hypre_newBoxLoopInit(ndim,loop_size); \ Kokkos::parallel_for (hypre__tot, KOKKOS_LAMBDA (HYPRE_Int idx) \ { #define hypre_newBoxLoop0End(i1) \ }); \ hypre_fence(); \ } #define hypre_newBoxLoop1Begin(ndim, loop_size, \ dbox1, start1, stride1, i1) \ { \ hypre_newBoxLoopInit(ndim,loop_size) \ hypre_BoxLoopDataDeclareK(1,ndim,loop_size,dbox1,start1,stride1); \ Kokkos::parallel_for (hypre__tot, KOKKOS_LAMBDA (HYPRE_Int idx) \ { \ hypre_newBoxLoopDeclare(databox1); \ hypre_BoxLoopIncK(1,databox1,i1); #define hypre_newBoxLoop1End(i1) \ }); \ hypre_fence(); \ } #define hypre_newBoxLoop2Begin(ndim, loop_size, \ dbox1, start1, stride1, i1, \ dbox2, start2, stride2, i2) \ { \ hypre_newBoxLoopInit(ndim,loop_size); \ hypre_BoxLoopDataDeclareK(1,ndim,loop_size,dbox1,start1,stride1); \ hypre_BoxLoopDataDeclareK(2,ndim,loop_size,dbox2,start2,stride2); \ Kokkos::parallel_for (hypre__tot, KOKKOS_LAMBDA (HYPRE_Int idx) \ { \ hypre_newBoxLoopDeclare(databox1) \ hypre_BoxLoopIncK(1,databox1,i1); \ hypre_BoxLoopIncK(2,databox2,i2); #define hypre_newBoxLoop2End(i1, i2) \ }); \ hypre_fence(); \ } #define hypre_newBoxLoop3Begin(ndim, loop_size, \ dbox1, start1, stride1, i1, \ dbox2, start2, stride2, i2, \ dbox3, start3, stride3, i3) \ { \ hypre_newBoxLoopInit(ndim,loop_size); \ hypre_BoxLoopDataDeclareK(1,ndim,loop_size,dbox1,start1,stride1); \ hypre_BoxLoopDataDeclareK(2,ndim,loop_size,dbox2,start2,stride2); \ hypre_BoxLoopDataDeclareK(3,ndim,loop_size,dbox3,start3,stride3); \ Kokkos::parallel_for (hypre__tot, KOKKOS_LAMBDA (HYPRE_Int idx) \ { \ hypre_newBoxLoopDeclare(databox1); \ hypre_BoxLoopIncK(1,databox1,i1); \ hypre_BoxLoopIncK(2,databox2,i2); \ hypre_BoxLoopIncK(3,databox3,i3); #define hypre_newBoxLoop3End(i1, i2, i3) \ }); \ hypre_fence(); \ } #define hypre_newBoxLoop4Begin(ndim, loop_size, \ dbox1, start1, stride1, i1, \ dbox2, start2, stride2, i2, \ dbox3, start3, stride3, i3, \ dbox4, start4, stride4, i4) \ { \ hypre_newBoxLoopInit(ndim,loop_size); \ hypre_BoxLoopDataDeclareK(1,ndim,loop_size,dbox1,start1,stride1); \ hypre_BoxLoopDataDeclareK(2,ndim,loop_size,dbox2,start2,stride2); \ hypre_BoxLoopDataDeclareK(3,ndim,loop_size,dbox3,start3,stride3); \ hypre_BoxLoopDataDeclareK(4,ndim,loop_size,dbox4,start4,stride4); \ Kokkos::parallel_for (hypre__tot, KOKKOS_LAMBDA (HYPRE_Int idx) \ { \ hypre_newBoxLoopDeclare(databox1); \ hypre_BoxLoopIncK(1,databox1,i1); \ hypre_BoxLoopIncK(2,databox2,i2); \ hypre_BoxLoopIncK(3,databox3,i3); \ hypre_BoxLoopIncK(4,databox4,i4); #define hypre_newBoxLoop4End(i1, i2, i3, i4) \ }); \ hypre_fence(); \ } #define hypre_BasicBoxLoopDataDeclareK(k,ndim,loop_size,stride) \ hypre_Boxloop databox##k; \ databox##k.lsize0 = loop_size[0]; \ databox##k.strides0 = stride[0]; \ databox##k.bstart0 = 0; \ databox##k.bsize0 = 0; \ if (ndim > 1) \ { \ databox##k.lsize1 = loop_size[1]; \ databox##k.strides1 = stride[1]; \ databox##k.bstart1 = 0; \ databox##k.bsize1 = 0; \ } \ else \ { \ databox##k.lsize1 = 1; \ databox##k.strides1 = 0; \ databox##k.bstart1 = 0; \ databox##k.bsize1 = 0; \ } \ if (ndim == 3) \ { \ databox##k.lsize2 = loop_size[2]; \ databox##k.strides2 = stride[2]; \ databox##k.bstart2 = 0; \ databox##k.bsize2 = 0; \ } \ else \ { \ databox##k.lsize2 = 1; \ databox##k.strides2 = 0; \ databox##k.bstart2 = 0; \ databox##k.bsize2 = 0; \ } #define hypre_newBasicBoxLoop2Begin(ndim, loop_size, \ stride1, i1, \ stride2, i2) \ { \ hypre_newBoxLoopInit(ndim,loop_size); \ hypre_BasicBoxLoopDataDeclareK(1,ndim,loop_size,stride1); \ hypre_BasicBoxLoopDataDeclareK(2,ndim,loop_size,stride2); \ Kokkos::parallel_for (hypre__tot, KOKKOS_LAMBDA (HYPRE_Int idx) \ { \ hypre_newBoxLoopDeclare(databox1); \ hypre_BoxLoopIncK(1,databox1,i1); \ hypre_BoxLoopIncK(2,databox2,i2); \ #define hypre_BoxLoop1ReductionBegin(ndim, loop_size, \ dbox1, start1, stride1, i1, \ HYPRE_BOX_REDUCTION) \ { \ HYPRE_Real __hypre_sum_tmp = HYPRE_BOX_REDUCTION; \ HYPRE_BOX_REDUCTION = 0.0; \ hypre_newBoxLoopInit(ndim,loop_size); \ hypre_BoxLoopDataDeclareK(1,ndim,loop_size,dbox1,start1,stride1); \ Kokkos::parallel_reduce (hypre__tot, KOKKOS_LAMBDA (HYPRE_Int idx, \ HYPRE_Real &HYPRE_BOX_REDUCTION) \ { \ hypre_newBoxLoopDeclare(databox1); \ hypre_BoxLoopIncK(1,databox1,i1); \ #define hypre_BoxLoop1ReductionEnd(i1, HYPRE_BOX_REDUCTION) \ }, HYPRE_BOX_REDUCTION); \ hypre_fence(); \ HYPRE_BOX_REDUCTION += __hypre_sum_tmp; \ } #define hypre_BoxLoop2ReductionBegin(ndim, loop_size, \ dbox1, start1, stride1, i1, \ dbox2, start2, stride2, i2, \ HYPRE_BOX_REDUCTION) \ { \ HYPRE_Real __hypre_sum_tmp = HYPRE_BOX_REDUCTION; \ HYPRE_BOX_REDUCTION = 0.0; \ hypre_newBoxLoopInit(ndim,loop_size); \ hypre_BoxLoopDataDeclareK(1,ndim,loop_size,dbox1,start1,stride1); \ hypre_BoxLoopDataDeclareK(2,ndim,loop_size,dbox2,start2,stride2); \ Kokkos::parallel_reduce (hypre__tot, KOKKOS_LAMBDA (HYPRE_Int idx, \ HYPRE_Real &HYPRE_BOX_REDUCTION) \ { \ hypre_newBoxLoopDeclare(databox1); \ hypre_BoxLoopIncK(1,databox1,i1); \ hypre_BoxLoopIncK(2,databox2,i2); \ #define hypre_BoxLoop2ReductionEnd(i1, i2, HYPRE_BOX_REDUCTION) \ }, HYPRE_BOX_REDUCTION); \ hypre_fence(); \ HYPRE_BOX_REDUCTION += __hypre_sum_tmp; \ } #define hypre_LoopBegin(size,idx) \ { \ Kokkos::parallel_for(size, KOKKOS_LAMBDA (HYPRE_Int idx) \ { #define hypre_LoopEnd() \ }); \ hypre_fence(); \ } /* extern "C++" { struct ColumnSums { typedef HYPRE_Real value_type[]; typedef View<HYPRE_Real**>::size_type size_type; size_type value_count; View<HYPRE_Real**> X_; ColumnSums(const View<HYPRE_Real**>& X):value_count(X.dimension_1()),X_(X){} KOKKOS_INLINE_FUNCTION void operator()(const size_type i,value_type sum) const { for (size_type j = 0;j < value_count;j++) { sum[j] += X_(i,j); } } KOKKOS_INLINE_FUNCTION void join (volatile value_type dst,volatile value_type src) const { for (size_type j= 0;j < value_count;j++) { dst[j] +=src[j]; } } KOKKOS_INLINE_FUNCTION void init(value_type sum) const { for (size_type j= 0;j < value_count;j++) { sum[j] += 0.0; } } }; } */ #define hypre_newBoxLoopSetOneBlock() #define hypre_newBoxLoopGetIndex(index)\ index[0] = hypre_IndexD(local_idx, 0); index[1] = hypre_IndexD(local_idx, 1); index[2] = hypre_IndexD(local_idx, 2); #define hypre_BoxLoopGetIndex zypre_BoxLoopGetIndex #define hypre_BoxLoopSetOneBlock hypre_newBoxLoopSetOneBlock #define hypre_BoxLoopBlock() 0 #define hypre_BoxLoop0Begin hypre_newBoxLoop0Begin #define hypre_BoxLoop0For hypre_newBoxLoop0For #define hypre_BoxLoop0End hypre_newBoxLoop0End #define hypre_BoxLoop1Begin hypre_newBoxLoop1Begin #define hypre_BoxLoop1For hypre_newBoxLoop1For #define hypre_BoxLoop1End hypre_newBoxLoop1End #define hypre_BoxLoop2Begin hypre_newBoxLoop2Begin #define hypre_BoxLoop2For hypre_newBoxLoop2For #define hypre_BoxLoop2End hypre_newBoxLoop2End #define hypre_BoxLoop3Begin hypre_newBoxLoop3Begin #define hypre_BoxLoop3For hypre_newBoxLoop3For #define hypre_BoxLoop3End hypre_newBoxLoop3End #define hypre_BoxLoop4Begin hypre_newBoxLoop4Begin #define hypre_BoxLoop4For hypre_newBoxLoop4For #define hypre_BoxLoop4End hypre_newBoxLoop4End #define hypre_BasicBoxLoop2Begin hypre_newBasicBoxLoop2Begin #endif #elif defined(HYPRE_USING_CUDA) /****************************************************************************** * Copyright 1998-2019 Lawrence Livermore National Security, LLC and other * HYPRE Project Developers. See the top-level COPYRIGHT file for details. * * SPDX-License-Identifier: (Apache-2.0 OR MIT) ******************************************************************************/ /****************************************************************************** * * Header info for the BoxLoop * *****************************************************************************/ /*-------------------------------------------------------------------------- * BoxLoop macros: *--------------------------------------------------------------------------*/ #ifndef HYPRE_NEWBOXLOOP_HEADER #define HYPRE_NEWBOXLOOP_HEADER #include <cuda.h> #include <cuda_runtime.h> #ifdef HYPRE_USING_OPENMP #include <omp.h> #endif #define HYPRE_LAMBDA [=] __host__ __device__ #define BLOCKSIZE 512 typedef struct hypre_Boxloop_struct { HYPRE_Int lsize0,lsize1,lsize2; HYPRE_Int strides0,strides1,strides2; HYPRE_Int bstart0,bstart1,bstart2; HYPRE_Int bsize0,bsize1,bsize2; } hypre_Boxloop; #if 1 #define hypre_fence() /*printf("\n hypre_newBoxLoop in %s(%d) function %s\n",__FILE__,__LINE__,__FUNCTION__);*/ #else #define hypre_fence() \ { \ cudaError err = cudaGetLastError(); \ if ( cudaSuccess != err ) \ { \ printf("\n ERROR hypre_newBoxLoop: %s in %s(%d) function %s\n",cudaGetErrorString(err),__FILE__,__LINE__,__FUNCTION__); \ /* HYPRE_Int *p = NULL; *p = 1; */ \ } \ hypre_CheckErrorDevice(cudaDeviceSynchronize()); \ } #endif /* #define hypre_reduce_policy cuda_reduce<BLOCKSIZE> */ extern "C++" { template <typename LOOP_BODY> __global__ void forall_kernel(LOOP_BODY loop_body, HYPRE_Int length) { HYPRE_Int idx = blockDim.x * blockIdx.x + threadIdx.x; if (idx < length) { loop_body(idx); } } template<typename LOOP_BODY> void BoxLoopforall(HYPRE_Int policy, HYPRE_Int length, LOOP_BODY loop_body) { if (policy == HYPRE_MEMORY_HOST) { #ifdef HYPRE_USING_OPENMP #pragma omp parallel for HYPRE_SMP_SCHEDULE #endif for (HYPRE_Int idx = 0; idx < length; idx++) { loop_body(idx); } } else if (policy == HYPRE_MEMORY_DEVICE) { HYPRE_Int gridSize = (length + BLOCKSIZE - 1) / BLOCKSIZE; const dim3 gDim(gridSize), bDim(BLOCKSIZE); HYPRE_CUDA_LAUNCH( forall_kernel, gDim, bDim, loop_body, length ); } else if (policy == 2) { } } template <typename LOOP_BODY> __global__ void reductionforall_kernel(LOOP_BODY ReductionLoop, HYPRE_Int length) { ReductionLoop(blockDim.x*blockIdx.x+threadIdx.x, blockDim.x*gridDim.x, length); } template<typename LOOP_BODY> void ReductionBoxLoopforall(HYPRE_Int policy, HYPRE_Int length, LOOP_BODY ReductionLoop) { if (length <= 0) { return; } if (policy == HYPRE_MEMORY_HOST) { } else if (policy == HYPRE_MEMORY_DEVICE) { HYPRE_Int gridSize = (length + BLOCKSIZE - 1) / BLOCKSIZE; gridSize = hypre_min(gridSize, 1024); /* hypre_printf("length= %d, blocksize = %d, gridsize = %d\n", length, BLOCKSIZE, gridSize); */ const dim3 gDim(gridSize), bDim(BLOCKSIZE); HYPRE_CUDA_LAUNCH( reductionforall_kernel, gDim, bDim, ReductionLoop, length ); } } } #define hypre_BoxLoopIncK(k,box,hypre__i) \ HYPRE_Int hypre_boxD##k = 1; \ HYPRE_Int hypre__i = 0; \ hypre__i += (hypre_IndexD(local_idx, 0)*box.strides0 + box.bstart0) * hypre_boxD##k; \ hypre_boxD##k *= hypre_max(0, box.bsize0 + 1); \ hypre__i += (hypre_IndexD(local_idx, 1)*box.strides1 + box.bstart1) * hypre_boxD##k; \ hypre_boxD##k *= hypre_max(0, box.bsize1 + 1); \ hypre__i += (hypre_IndexD(local_idx, 2)*box.strides2 + box.bstart2) * hypre_boxD##k; \ hypre_boxD##k *= hypre_max(0, box.bsize2 + 1); #define hypre_newBoxLoopInit(ndim,loop_size) \ HYPRE_Int hypre__tot = 1; \ for (HYPRE_Int hypre_d = 0;hypre_d < ndim;hypre_d ++) \ hypre__tot *= loop_size[hypre_d]; #define hypre_BasicBoxLoopInit(ndim,loop_size) \ HYPRE_Int hypre__tot = 1; \ for (HYPRE_Int hypre_d = 0;hypre_d < ndim;hypre_d ++) \ hypre__tot *= loop_size[hypre_d]; \ #define hypre_newBoxLoopDeclare(box) \ hypre_Index local_idx; \ HYPRE_Int idx_local = idx; \ hypre_IndexD(local_idx, 0) = idx_local % box.lsize0; \ idx_local = idx_local / box.lsize0; \ hypre_IndexD(local_idx, 1) = idx_local % box.lsize1; \ idx_local = idx_local / box.lsize1; \ hypre_IndexD(local_idx, 2) = idx_local % box.lsize2; \ #define hypre_newBoxLoop0Begin(ndim, loop_size) \ { \ hypre_newBoxLoopInit(ndim,loop_size); \ BoxLoopforall(hypre_exec_policy,hypre__tot,HYPRE_LAMBDA (HYPRE_Int idx) \ { #define hypre_newBoxLoop0End() \ }); \ hypre_fence(); \ } #define hypre_BoxLoopDataDeclareK(k,ndim,loop_size,dbox,start,stride) \ hypre_Boxloop databox##k; \ databox##k.lsize0 = loop_size[0]; \ databox##k.strides0 = stride[0]; \ databox##k.bstart0 = start[0] - dbox->imin[0]; \ databox##k.bsize0 = dbox->imax[0]-dbox->imin[0]; \ if (ndim > 1) \ { \ databox##k.lsize1 = loop_size[1]; \ databox##k.strides1 = stride[1]; \ databox##k.bstart1 = start[1] - dbox->imin[1]; \ databox##k.bsize1 = dbox->imax[1]-dbox->imin[1]; \ } \ else \ { \ databox##k.lsize1 = 1; \ databox##k.strides1 = 0; \ databox##k.bstart1 = 0; \ databox##k.bsize1 = 0; \ } \ if (ndim == 3) \ { \ databox##k.lsize2 = loop_size[2]; \ databox##k.strides2 = stride[2]; \ databox##k.bstart2 = start[2] - dbox->imin[2]; \ databox##k.bsize2 = dbox->imax[2]-dbox->imin[2]; \ } \ else \ { \ databox##k.lsize2 = 1; \ databox##k.strides2 = 0; \ databox##k.bstart2 = 0; \ databox##k.bsize2 = 0; \ } #define hypre_newBoxLoop1Begin(ndim, loop_size, \ dbox1, start1, stride1, i1) \ { \ hypre_newBoxLoopInit(ndim,loop_size); \ hypre_BoxLoopDataDeclareK(1,ndim,loop_size,dbox1,start1,stride1); \ BoxLoopforall(hypre_exec_policy,hypre__tot,HYPRE_LAMBDA (HYPRE_Int idx) \ { \ hypre_newBoxLoopDeclare(databox1); \ hypre_BoxLoopIncK(1,databox1,i1); #define hypre_newBoxLoop1End(i1) \ }); \ hypre_fence(); \ } #define hypre_newBoxLoop2Begin(ndim, loop_size, \ dbox1, start1, stride1, i1, \ dbox2, start2, stride2, i2) \ { \ hypre_newBoxLoopInit(ndim,loop_size); \ hypre_BoxLoopDataDeclareK(1,ndim,loop_size,dbox1,start1,stride1); \ hypre_BoxLoopDataDeclareK(2,ndim,loop_size,dbox2,start2,stride2); \ BoxLoopforall(hypre_exec_policy,hypre__tot,HYPRE_LAMBDA (HYPRE_Int idx) \ { \ hypre_newBoxLoopDeclare(databox1); \ hypre_BoxLoopIncK(1,databox1,i1); \ hypre_BoxLoopIncK(2,databox2,i2); #define hypre_newBoxLoop2End(i1, i2) \ }); \ hypre_fence(); \ } #define hypre_newBoxLoop3Begin(ndim, loop_size, \ dbox1, start1, stride1, i1, \ dbox2, start2, stride2, i2, \ dbox3, start3, stride3, i3) \ { \ hypre_newBoxLoopInit(ndim,loop_size); \ hypre_BoxLoopDataDeclareK(1,ndim,loop_size,dbox1,start1,stride1); \ hypre_BoxLoopDataDeclareK(2,ndim,loop_size,dbox2,start2,stride2); \ hypre_BoxLoopDataDeclareK(3,ndim,loop_size,dbox3,start3,stride3); \ BoxLoopforall(hypre_exec_policy,hypre__tot,HYPRE_LAMBDA (HYPRE_Int idx) \ { \ hypre_newBoxLoopDeclare(databox1); \ hypre_BoxLoopIncK(1,databox1,i1); \ hypre_BoxLoopIncK(2,databox2,i2); \ hypre_BoxLoopIncK(3,databox3,i3); #define hypre_newBoxLoop3End(i1, i2,i3) \ }); \ hypre_fence(); \ } #define hypre_newBoxLoop4Begin(ndim, loop_size, \ dbox1, start1, stride1, i1, \ dbox2, start2, stride2, i2, \ dbox3, start3, stride3, i3, \ dbox4, start4, stride4, i4) \ { \ hypre_newBoxLoopInit(ndim,loop_size); \ hypre_BoxLoopDataDeclareK(1,ndim,loop_size,dbox1,start1,stride1); \ hypre_BoxLoopDataDeclareK(2,ndim,loop_size,dbox2,start2,stride2); \ hypre_BoxLoopDataDeclareK(3,ndim,loop_size,dbox3,start3,stride3); \ hypre_BoxLoopDataDeclareK(4,ndim,loop_size,dbox4,start4,stride4); \ BoxLoopforall(hypre_exec_policy,hypre__tot,HYPRE_LAMBDA (HYPRE_Int idx) \ { \ hypre_newBoxLoopDeclare(databox1); \ hypre_BoxLoopIncK(1,databox1,i1); \ hypre_BoxLoopIncK(2,databox2,i2); \ hypre_BoxLoopIncK(3,databox3,i3); \ hypre_BoxLoopIncK(4,databox4,i4); #define hypre_newBoxLoop4End(i1, i2, i3, i4) \ }); \ hypre_fence(); \ } #define zypre_BasicBoxLoopDataDeclareK(k,ndim,loop_size,stride) \ hypre_Boxloop databox##k; \ databox##k.lsize0 = loop_size[0]; \ databox##k.strides0 = stride[0]; \ databox##k.bstart0 = 0; \ databox##k.bsize0 = 0; \ if (ndim > 1) \ { \ databox##k.lsize1 = loop_size[1]; \ databox##k.strides1 = stride[1]; \ databox##k.bstart1 = 0; \ databox##k.bsize1 = 0; \ } \ else \ { \ databox##k.lsize1 = 1; \ databox##k.strides1 = 0; \ databox##k.bstart1 = 0; \ databox##k.bsize1 = 0; \ } \ if (ndim == 3) \ { \ databox##k.lsize2 = loop_size[2]; \ databox##k.strides2 = stride[2]; \ databox##k.bstart2 = 0; \ databox##k.bsize2 = 0; \ } \ else \ { \ databox##k.lsize2 = 1; \ databox##k.strides2 = 0; \ databox##k.bstart2 = 0; \ databox##k.bsize2 = 0; \ } #define zypre_newBasicBoxLoop1Begin(ndim, loop_size, \ stride1, i1) \ { \ hypre_BasicBoxLoopInit(ndim,loop_size); \ zypre_BasicBoxLoopDataDeclareK(1,ndim,loop_size,stride1); \ BoxLoopforall(hypre_exec_policy,hypre__tot,HYPRE_LAMBDA (HYPRE_Int idx) \ { \ hypre_newBoxLoopDeclare(databox1); \ hypre_BoxLoopIncK(1,databox1,i1); \ #define zypre_newBasicBoxLoop2Begin(ndim, loop_size, \ stride1, i1, \ stride2, i2) \ { \ hypre_BasicBoxLoopInit(ndim,loop_size); \ zypre_BasicBoxLoopDataDeclareK(1,ndim,loop_size,stride1); \ zypre_BasicBoxLoopDataDeclareK(2,ndim,loop_size,stride2); \ BoxLoopforall(hypre_exec_policy,hypre__tot,HYPRE_LAMBDA (HYPRE_Int idx) \ { \ hypre_newBoxLoopDeclare(databox1); \ hypre_BoxLoopIncK(1,databox1,i1); \ hypre_BoxLoopIncK(2,databox2,i2); \ #define hypre_LoopBegin(size,idx) \ { \ BoxLoopforall(hypre_exec_policy,size,HYPRE_LAMBDA (HYPRE_Int idx) \ { #define hypre_LoopEnd() \ }); \ hypre_fence(); \ } #define hypre_newBoxLoopGetIndex(index) \ index[0] = hypre_IndexD(local_idx, 0); index[1] = hypre_IndexD(local_idx, 1); index[2] = hypre_IndexD(local_idx, 2); #define hypre_BoxLoopGetIndex zypre_BoxLoopGetIndex #define hypre_BoxLoopSetOneBlock() ; #define hypre_BoxLoopBlock() 0 #define hypre_BoxLoop0Begin hypre_newBoxLoop0Begin #define hypre_BoxLoop0For hypre_newBoxLoop0For #define hypre_BoxLoop0End hypre_newBoxLoop0End #define hypre_BoxLoop1Begin hypre_newBoxLoop1Begin #define hypre_BoxLoop1For hypre_newBoxLoop1For #define hypre_BoxLoop1End hypre_newBoxLoop1End #define hypre_BoxLoop2Begin hypre_newBoxLoop2Begin #define hypre_BoxLoop2For hypre_newBoxLoop2For #define hypre_BoxLoop2End hypre_newBoxLoop2End #define hypre_BoxLoop3Begin hypre_newBoxLoop3Begin #define hypre_BoxLoop3For hypre_newBoxLoop3For #define hypre_BoxLoop3End hypre_newBoxLoop3End #define hypre_BoxLoop4Begin hypre_newBoxLoop4Begin #define hypre_BoxLoop4For hypre_newBoxLoop4For #define hypre_BoxLoop4End hypre_newBoxLoop4End #define hypre_BasicBoxLoop1Begin zypre_newBasicBoxLoop1Begin #define hypre_BasicBoxLoop2Begin zypre_newBasicBoxLoop2Begin /* Reduction BoxLoop1*/ #define hypre_BoxLoop1ReductionBegin(ndim, loop_size, \ dbox1, start1, stride1, i1, \ reducesum) \ { \ hypre_newBoxLoopInit(ndim,loop_size); \ hypre_BoxLoopDataDeclareK(1,ndim,loop_size,dbox1,start1,stride1); \ reducesum.nblocks = hypre_min( (hypre__tot+BLOCKSIZE-1)/BLOCKSIZE, 1024 ); \ ReductionBoxLoopforall(hypre_exec_policy, hypre__tot, \ HYPRE_LAMBDA (HYPRE_Int tid, HYPRE_Int nthreads, \ HYPRE_Int len) \ { \ for (HYPRE_Int idx = tid; \ idx < len; \ idx += nthreads) \ { \ hypre_newBoxLoopDeclare(databox1); \ hypre_BoxLoopIncK(1,databox1,i1); #define hypre_BoxLoop1ReductionEnd(i1, reducesum) \ } \ reducesum.BlockReduce(); \ }); \ hypre_fence(); \ } /* Reduction BoxLoop2 */ #define hypre_BoxLoop2ReductionBegin(ndim, loop_size, \ dbox1, start1, stride1, i1, \ dbox2, start2, stride2, i2, \ reducesum) \ { \ hypre_newBoxLoopInit(ndim,loop_size); \ hypre_BoxLoopDataDeclareK(1,ndim,loop_size,dbox1,start1,stride1); \ hypre_BoxLoopDataDeclareK(2,ndim,loop_size,dbox2,start2,stride2); \ reducesum.nblocks = hypre_min( (hypre__tot+BLOCKSIZE-1)/BLOCKSIZE, 1024 ); \ ReductionBoxLoopforall(hypre_exec_policy, hypre__tot, \ HYPRE_LAMBDA (HYPRE_Int tid, HYPRE_Int nthreads, \ HYPRE_Int len) \ { \ for (HYPRE_Int idx = tid; \ idx < len; \ idx += nthreads) \ { \ hypre_newBoxLoopDeclare(databox1); \ hypre_BoxLoopIncK(1,databox1,i1); \ hypre_BoxLoopIncK(2,databox2,i2); #define hypre_BoxLoop2ReductionEnd(i1, i2, reducesum) \ } \ reducesum.BlockReduce(); \ }); \ hypre_fence(); \ } #endif #elif defined(HYPRE_USING_DEVICE_OPENMP) /****************************************************************************** * Copyright 1998-2019 Lawrence Livermore National Security, LLC and other * HYPRE Project Developers. See the top-level COPYRIGHT file for details. * * SPDX-License-Identifier: (Apache-2.0 OR MIT) ******************************************************************************/ /****************************************************************************** * * Header info for the BoxLoop * *****************************************************************************/ /*-------------------------------------------------------------------------- * BoxLoop macros: *--------------------------------------------------------------------------*/ #ifndef HYPRE_NEWBOXLOOP_HEADER #define HYPRE_NEWBOXLOOP_HEADER #include "omp.h" /* concatenation: */ #define HYPRE_CONCAT2(x, y) x ## _ ## y #define HYPRE_XCONCAT2(x, y) HYPRE_CONCAT2(x, y) #define HYPRE_CONCAT3(x, y, z) x ## _ ## y ## _ ## z #define HYPRE_XCONCAT3(x, y, z) HYPRE_CONCAT3(x, y, z) /* if use OMP 4.5 default team size and number of teams */ #define AUTO_OMP_TEAM #ifndef AUTO_OMP_TEAM /* omp team size (aka. gpu block size) */ #define hypre_gpu_block_size 512 /* the max number of omp teams */ #define hypre_max_num_blocks 1000000 #endif //#define HYPRE_BOXLOOP_ENTRY_PRINT hypre_printf("%s %s %d\n", __FILE__, __func__, __LINE__); #define HYPRE_BOXLOOP_ENTRY_PRINT /* - - - - - - - - - - - - - - - - - - - - - - - - - - - - BOX LOOPS [TEAM DISTRIBUTE VERSION] !!! NOTE: THIS CODE ONLY WORKS FOR DIM <= 3 !!! * - - - - - - - - - - - - - - - - - - - - - - - - - - - -*/ /* #define hypre_BoxLoop0For() #define hypre_BoxLoop1For(i1) #define hypre_BoxLoop2For(i1, i2) #define hypre_BoxLoop3For(i1, i2, i3) #define hypre_BoxLoop4For(i1, i2, i3, i4) */ #define hypre_BoxLoopGetIndex zypre_BoxLoopGetIndex #define hypre_BoxLoopSetOneBlock() ; #define hypre_BoxLoopBlock() 0 #define hypre_BoxLoop0Begin zypre_omp4_dist_BoxLoop0Begin #define hypre_BoxLoop0End zypre_omp4_dist_BoxLoopEnd #define hypre_BoxLoop1Begin zypre_omp4_dist_BoxLoop1Begin #define hypre_BoxLoop1End zypre_omp4_dist_BoxLoopEnd #define hypre_BasicBoxLoop2Begin zypre_omp4_dist_BoxLoop2_v2_Begin #define hypre_BoxLoop2Begin zypre_omp4_dist_BoxLoop2Begin #define hypre_BoxLoop2End zypre_omp4_dist_BoxLoopEnd #define hypre_BoxLoop3Begin zypre_omp4_dist_BoxLoop3Begin #if 0 #define hypre_BoxLoop3_SAME_STRIDE_Begin zypre_omp4_dist_BoxLoop3_SAME_STRIDE_Begin #endif #define hypre_BoxLoop3End zypre_omp4_dist_BoxLoopEnd #define hypre_BoxLoop4Begin zypre_omp4_dist_BoxLoop4Begin #define hypre_BoxLoop4End zypre_omp4_dist_BoxLoopEnd #define hypre_LoopBegin zypre_LoopBegin #define hypre_LoopEnd zypre_omp4_dist_BoxLoopEnd /* Look for more in struct_ls/red_black_gs.h" */ #define zypre_omp4_dist_BoxLoopEnd(...) \ }\ /*cudaDeviceSynchronize();*/ \ } #define HYPRE_BOX_REDUCTION /* - - - - - - - - - - - - - - - - - - - - - - - - - - - - * host code: declare variables used in the box loop * - - - - - - - - - - - - - - - - - - - - - - - - - - - -*/ #define zypre_omp4_BoxLoopDeclareInit_0(ndim, loop_size) \ HYPRE_Int hypre__ndim = ndim, hypre__tot = 1; \ /* HYPRE_Int hypre__thread; */ \ /* loop size */ \ HYPRE_Int hypre__loop_size_0, hypre__loop_size_1, hypre__loop_size_2; \ if (hypre__ndim > 0) { hypre__loop_size_0 = loop_size[0]; hypre__tot *= hypre__loop_size_0; } \ if (hypre__ndim > 1) { hypre__loop_size_1 = loop_size[1]; hypre__tot *= hypre__loop_size_1; } \ if (hypre__ndim > 2) { hypre__loop_size_2 = loop_size[2]; hypre__tot *= hypre__loop_size_2; } #ifdef AUTO_OMP_TEAM #define TEAM_CLAUSE #define zypre_omp4_BoxLoopDeclareInit(ndim, loop_size) zypre_omp4_BoxLoopDeclareInit_0(ndim, loop_size) #else #define TEAM_CLAUSE num_teams(num_blocks) thread_limit(block_size) #define zypre_omp4_BoxLoopDeclareInit(ndim, loop_size) zypre_omp4_BoxLoopDeclareInit_0(ndim, loop_size) \ /* GPU block numbers and dimensions */ \ HYPRE_Int block_size = hypre_gpu_block_size; \ HYPRE_Int num_blocks = hypre_min(hypre_max_num_blocks, (hypre__tot + hypre_gpu_block_size - 1) / hypre_gpu_block_size); #endif /* - - - - - - - - - - - - - - - - - - - - - - - - - - - - * host code: declare and initialize variables for box k * - - - - - - - - - - - - - - - - - - - - - - - - - - - -*/ #define zypre_omp4_BoxKDeclareInitBody(j, k, startk, dboxk, stridek) \ HYPRE_XCONCAT3(hypre__stride,j,k) = stridek[j]; \ /* precompute some entities used in the parallel for loop */ \ HYPRE_XCONCAT3(hypre__box_start_imin,j,k) = startk[j] - dboxk->imin[j]; \ HYPRE_XCONCAT3(hypre__box_imax_imin,j,k) = dboxk->imax[j] - dboxk->imin[j] + 1; #define zypre_omp4_BoxKDeclareInit(k, startk, dboxk, stridek)\ /* start - imin */ \ HYPRE_Int HYPRE_XCONCAT3(hypre__box_start_imin,0,k), HYPRE_XCONCAT3(hypre__box_start_imin,1,k), HYPRE_XCONCAT3(hypre__box_start_imin,2,k); \ /* imax - imin + 1 */ \ HYPRE_Int HYPRE_XCONCAT3(hypre__box_imax_imin,0,k), HYPRE_XCONCAT3(hypre__box_imax_imin,1,k), HYPRE_XCONCAT3(hypre__box_imax_imin,2,k); \ /* stride */ \ HYPRE_Int HYPRE_XCONCAT3(hypre__stride,0,k), HYPRE_XCONCAT3(hypre__stride,1,k), HYPRE_XCONCAT3(hypre__stride,2,k); \ /*if (hypre__ndim > 0)*/ { zypre_omp4_BoxKDeclareInitBody(0, k, startk, dboxk, stridek) } \ if (hypre__ndim > 1) { zypre_omp4_BoxKDeclareInitBody(1, k, startk, dboxk, stridek) } \ if (hypre__ndim > 2) { zypre_omp4_BoxKDeclareInitBody(2, k, startk, dboxk, stridek) } \ /* - - - - - - - - - - - - - - - - - - - - - - - - - - - - * map clause * - - - - - - - - - - - - - - - - - - - - - - - - - - - -*/ #define MAP_CLAUSE0 #define MAP_CLAUSE1 #define MAP_CLAUSE2 #define MAP_CLAUSE3 #define MAP_CLAUSE4 /* - - - - - - - - - - - - - - - - - - - - - - - - - - - - * if clause * - - - - - - - - - - - - - - - - - - - - - - - - - - - -*/ #define IF_CLAUSE if (hypre__global_offload && hypre__tot > 0) //#define IF_CLAUSE /* - - - - - - - - - - - - - - - - - - - - - - - - - - - - * is_device_ptr clause * - - - - - - - - - - - - - - - - - - - - - - - - - - - -*/ #if defined(HYPRE_DEVICE_OPENMP_ALLOC) #define IS_DEVICE_CLAUSE DEVICE_VAR #else #define IS_DEVICE_CLAUSE #endif /* - - - - - - - - - - - - - - - - - - - - - - - - - - - - * device code for BoxLoop 1, set i1 * - - - - - - - - - - - - - - - - - - - - - - - - - - - -*/ #define zypre_omp4_BoxLoopSet1Body(j, i1) \ /* coord in dimension j */ \ hypre__i = hypre__J % HYPRE_XCONCAT2(hypre__loop_size,j); \ /* once */ \ hypre__i_1 = hypre__i * HYPRE_XCONCAT3(hypre__stride,j,1) + HYPRE_XCONCAT3(hypre__box_start_imin,j,1);\ /* once */ \ i1 += hypre__i_1 * hypre__I_1; \ /* once */ \ hypre__I_1 *= HYPRE_XCONCAT3(hypre__box_imax_imin,j,1); \ /* */ \ hypre__J /= HYPRE_XCONCAT2(hypre__loop_size,j); \ /* !!! special for BoxLoop1: save the 3-D id */ \ /* HYPRE_XCONCAT2(hypre__id,j) = hypre__i; */ #define zypre_omp4_BoxLoopSet1(i1) \ HYPRE_Int hypre__I_1, hypre__i, hypre__i_1, hypre__J, i1, idx; \ /* HYPRE_Int hypre__id_0, hypre__id_1, hypre__id_2; */ \ hypre__I_1 = 1; idx = hypre__J = hypre__thread; i1 = 0; \ /*if (hypre__ndim > 0)*/ { zypre_omp4_BoxLoopSet1Body(0, i1) } \ if (hypre__ndim > 1) { zypre_omp4_BoxLoopSet1Body(1, i1) } \ if (hypre__ndim > 2) { zypre_omp4_BoxLoopSet1Body(2, i1) } /* - - - - - - - - - - - - - - - - - - - - - - - - - - - - * device code for BoxLoop 2, set i1, i2 * - - - - - - - - - - - - - - - - - - - - - - - - - - - -*/ #define zypre_omp4_BoxLoopSet2Body(j, i1, i2) \ /* */ \ hypre__i = hypre__J % HYPRE_XCONCAT2(hypre__loop_size,j); \ /* twice */ \ hypre__i_1 = hypre__i * HYPRE_XCONCAT3(hypre__stride,j,1) + HYPRE_XCONCAT3(hypre__box_start_imin,j,1);\ hypre__i_2 = hypre__i * HYPRE_XCONCAT3(hypre__stride,j,2) + HYPRE_XCONCAT3(hypre__box_start_imin,j,2);\ /* twice */ \ i1 += hypre__i_1 * hypre__I_1; \ i2 += hypre__i_2 * hypre__I_2; \ /* twice */ \ hypre__I_1 *= HYPRE_XCONCAT3(hypre__box_imax_imin,j,1); \ hypre__I_2 *= HYPRE_XCONCAT3(hypre__box_imax_imin,j,2); \ /* */ \ hypre__J /= HYPRE_XCONCAT2(hypre__loop_size,j); #define zypre_omp4_BoxLoopSet2(i1, i2) \ HYPRE_Int hypre__I_1, hypre__I_2, hypre__i, hypre__i_1, hypre__i_2, hypre__J, i1, i2; \ hypre__I_1 = hypre__I_2 = 1; hypre__J = hypre__thread; i1 = i2 = 0; \ /*if (hypre__ndim > 0)*/ { zypre_omp4_BoxLoopSet2Body(0, i1, i2) } \ if (hypre__ndim > 1) { zypre_omp4_BoxLoopSet2Body(1, i1, i2) } \ if (hypre__ndim > 2) { zypre_omp4_BoxLoopSet2Body(2, i1, i2) } /* - - - - - - - - - - - - - - - - - - - - - - - - - - - - * device code for BoxLoop 3, set i1, i2, i3 * - - - - - - - - - - - - - - - - - - - - - - - - - - - -*/ #define zypre_omp4_BoxLoopSet3Body(j, i1, i2, i3) \ /* */ \ hypre__i = hypre__J % HYPRE_XCONCAT2(hypre__loop_size,j); \ /* 3 times */ \ hypre__i_1 = hypre__i * HYPRE_XCONCAT3(hypre__stride,j,1) + HYPRE_XCONCAT3(hypre__box_start_imin,j,1);\ hypre__i_2 = hypre__i * HYPRE_XCONCAT3(hypre__stride,j,2) + HYPRE_XCONCAT3(hypre__box_start_imin,j,2);\ hypre__i_3 = hypre__i * HYPRE_XCONCAT3(hypre__stride,j,3) + HYPRE_XCONCAT3(hypre__box_start_imin,j,3);\ /* 3 times */ \ i1 += hypre__i_1 * hypre__I_1; \ i2 += hypre__i_2 * hypre__I_2; \ i3 += hypre__i_3 * hypre__I_3; \ /* 3 times */ \ hypre__I_1 *= HYPRE_XCONCAT3(hypre__box_imax_imin,j,1); \ hypre__I_2 *= HYPRE_XCONCAT3(hypre__box_imax_imin,j,2); \ hypre__I_3 *= HYPRE_XCONCAT3(hypre__box_imax_imin,j,3); \ /* */ \ hypre__J /= HYPRE_XCONCAT2(hypre__loop_size,j); #define zypre_omp4_BoxLoopSet3(i1, i2, i3) \ HYPRE_Int hypre__I_1, hypre__I_2, hypre__I_3, hypre__i, hypre__i_1, hypre__i_2, hypre__i_3, hypre__J, i1, i2, i3; \ hypre__I_1 = hypre__I_2 = hypre__I_3 = 1; hypre__J = hypre__thread; i1 = i2 = i3 = 0; \ /*if (hypre__ndim > 0)*/ { zypre_omp4_BoxLoopSet3Body(0, i1, i2, i3) } \ if (hypre__ndim > 1) { zypre_omp4_BoxLoopSet3Body(1, i1, i2, i3) } \ if (hypre__ndim > 2) { zypre_omp4_BoxLoopSet3Body(2, i1, i2, i3) } #if 0 /* - - - - - special Box 3: XXX */ #define zypre_omp4_BoxLoopSet3_SAME_STRIDE_Body(j, i1, i2, i3) \ /* */ \ hypre__i = (hypre__J % HYPRE_XCONCAT2(hypre__loop_size,j)) * HYPRE_XCONCAT3(hypre__stride,j,1); \ /* 3 times */ \ hypre__i_1 = hypre__i + HYPRE_XCONCAT3(hypre__box_start_imin,j,1);\ hypre__i_2 = hypre__i + HYPRE_XCONCAT3(hypre__box_start_imin,j,2);\ hypre__i_3 = hypre__i + HYPRE_XCONCAT3(hypre__box_start_imin,j,3);\ /* 3 times */ \ i1 += hypre__i_1 * hypre__I_1; \ i2 += hypre__i_2 * hypre__I_2; \ i3 += hypre__i_3 * hypre__I_3; \ /* 3 times */ \ hypre__I_1 *= HYPRE_XCONCAT3(hypre__box_imax_imin,j,1); \ hypre__I_2 *= HYPRE_XCONCAT3(hypre__box_imax_imin,j,2); \ hypre__I_3 *= HYPRE_XCONCAT3(hypre__box_imax_imin,j,3); \ /* */ \ hypre__J /= HYPRE_XCONCAT2(hypre__loop_size,j); #define zypre_omp4_BoxLoopSet3_SAME_STRIDE(i1, i2, o2, i3) \ HYPRE_Int hypre__I_1, hypre__I_2, hypre__I_3, hypre__i, hypre__i_1, hypre__i_2, hypre__i_3, hypre__J; \ hypre__I_1 = hypre__I_2 = hypre__I_3 = 1; hypre__J = hypre__thread; i1 = i3 = 0; i2 = o2;\ /*if (hypre__ndim > 0)*/ { zypre_omp4_BoxLoopSet3_SAME_STRIDE_Body(0, i1, i2, i3) } \ if (hypre__ndim > 1) { zypre_omp4_BoxLoopSet3_SAME_STRIDE_Body(1, i1, i2, i3) } \ if (hypre__ndim > 2) { zypre_omp4_BoxLoopSet3_SAME_STRIDE_Body(2, i1, i2, i3) } #endif /* - - - - - - - - - - - - - - - - - - - - - - - - - - - - * device code for BoxLoop 4, set i1, i2, i3, i4 * - - - - - - - - - - - - - - - - - - - - - - - - - - - -*/ #define zypre_omp4_BoxLoopSet4Body(j, i1, i2, i3, i4) \ /* */ \ hypre__i = hypre__J % HYPRE_XCONCAT2(hypre__loop_size,j); \ /* 4 times */ \ hypre__i_1 = hypre__i * HYPRE_XCONCAT3(hypre__stride,j,1) + HYPRE_XCONCAT3(hypre__box_start_imin,j,1);\ hypre__i_2 = hypre__i * HYPRE_XCONCAT3(hypre__stride,j,2) + HYPRE_XCONCAT3(hypre__box_start_imin,j,2);\ hypre__i_3 = hypre__i * HYPRE_XCONCAT3(hypre__stride,j,3) + HYPRE_XCONCAT3(hypre__box_start_imin,j,3);\ hypre__i_4 = hypre__i * HYPRE_XCONCAT3(hypre__stride,j,4) + HYPRE_XCONCAT3(hypre__box_start_imin,j,4);\ /* 4 times */ \ i1 += hypre__i_1 * hypre__I_1; \ i2 += hypre__i_2 * hypre__I_2; \ i3 += hypre__i_3 * hypre__I_3; \ i4 += hypre__i_4 * hypre__I_4; \ /* 4 times */ \ hypre__I_1 *= HYPRE_XCONCAT3(hypre__box_imax_imin,j,1); \ hypre__I_2 *= HYPRE_XCONCAT3(hypre__box_imax_imin,j,2); \ hypre__I_3 *= HYPRE_XCONCAT3(hypre__box_imax_imin,j,3); \ hypre__I_4 *= HYPRE_XCONCAT3(hypre__box_imax_imin,j,4); \ /* */ \ hypre__J /= HYPRE_XCONCAT2(hypre__loop_size,j); #define zypre_omp4_BoxLoopSet4(i1, i2, i3, i4) \ HYPRE_Int hypre__I_1, hypre__I_2, hypre__I_3, hypre__I_4, hypre__i, hypre__i_1, hypre__i_2, hypre__i_3, hypre__i_4, hypre__J, i1, i2, i3, i4; \ hypre__I_1 = hypre__I_2 = hypre__I_3 = hypre__I_4 = 1; hypre__J = hypre__thread; i1 = i2 = i3 = i4 = 0; \ /*if (hypre__ndim > 0)*/ { zypre_omp4_BoxLoopSet4Body(0, i1, i2, i3, i4) } \ if (hypre__ndim > 1) { zypre_omp4_BoxLoopSet4Body(1, i1, i2, i3, i4) } \ if (hypre__ndim > 2) { zypre_omp4_BoxLoopSet4Body(2, i1, i2, i3, i4) } /* - - - - - - - - - - - - - - - - - - - - - - - - - - - - * BoxLoop 0 * - - - - - - - - - - - - - - - - - - - - - - - - - - - -*/ #define zypre_omp4_dist_BoxLoop0Begin(ndim, loop_size) \ {\ /* host code: */ \ HYPRE_BOXLOOP_ENTRY_PRINT \ zypre_omp4_BoxLoopDeclareInit(ndim, loop_size) \ /* device code: */ \ _Pragma (HYPRE_XSTR(omp target teams distribute parallel for IF_CLAUSE MAP_CLAUSE0 IS_DEVICE_CLAUSE TEAM_CLAUSE)) \ for (HYPRE_Int hypre__thread = 0; hypre__thread < hypre__tot; hypre__thread++) \ {\ /* - - - - - - - - - - - - - - - - - - - - - - - - - - - - * BoxLoop 1 * - - - - - - - - - - - - - - - - - - - - - - - - - - - -*/ #define zypre_omp4_dist_BoxLoop1Begin(ndim, loop_size, dbox1, start1, stride1, i1) \ {\ /* host code: */ \ HYPRE_BOXLOOP_ENTRY_PRINT \ zypre_omp4_BoxLoopDeclareInit(ndim, loop_size) \ zypre_omp4_BoxKDeclareInit(1, start1, dbox1, stride1) \ /* device code: */ \ _Pragma (HYPRE_XSTR(omp target teams distribute parallel for IF_CLAUSE MAP_CLAUSE1 IS_DEVICE_CLAUSE HYPRE_BOX_REDUCTION TEAM_CLAUSE)) \ for (HYPRE_Int hypre__thread = 0; hypre__thread < hypre__tot; hypre__thread++) \ {\ zypre_omp4_BoxLoopSet1(i1) /* - - - - - - - - - - - - - - - - - - - - - - - - - - - - * BoxLoop 2 * - - - - - - - - - - - - - - - - - - - - - - - - - - - -*/ #define zypre_omp4_dist_BoxLoop2Begin(ndim, loop_size, dbox1, start1, stride1, i1, dbox2, start2, stride2, i2) \ {\ /* host code: */ \ HYPRE_BOXLOOP_ENTRY_PRINT \ zypre_omp4_BoxLoopDeclareInit(ndim, loop_size) \ zypre_omp4_BoxKDeclareInit(1, start1, dbox1, stride1) \ zypre_omp4_BoxKDeclareInit(2, start2, dbox2, stride2) \ /* device code: */ \ _Pragma (HYPRE_XSTR(omp target teams distribute parallel for IF_CLAUSE MAP_CLAUSE2 IS_DEVICE_CLAUSE HYPRE_BOX_REDUCTION TEAM_CLAUSE)) \ for (HYPRE_Int hypre__thread = 0; hypre__thread < hypre__tot; hypre__thread++) \ {\ zypre_omp4_BoxLoopSet2(i1, i2) /* - - - - - - - - - - - - - - - - - - - - - - - - - - - - * BoxLoop 3 * - - - - - - - - - - - - - - - - - - - - - - - - - - - -*/ #define zypre_omp4_dist_BoxLoop3Begin(ndim, loop_size, \ dbox1, start1, stride1, i1, \ dbox2, start2, stride2, i2, \ dbox3, start3, stride3, i3) \ {\ /* host code: */ \ HYPRE_BOXLOOP_ENTRY_PRINT \ zypre_omp4_BoxLoopDeclareInit(ndim, loop_size) \ zypre_omp4_BoxKDeclareInit(1, start1, dbox1, stride1) \ zypre_omp4_BoxKDeclareInit(2, start2, dbox2, stride2) \ zypre_omp4_BoxKDeclareInit(3, start3, dbox3, stride3) \ /* device code: */ \ _Pragma (HYPRE_XSTR(omp target teams distribute parallel for IF_CLAUSE MAP_CLAUSE3 IS_DEVICE_CLAUSE TEAM_CLAUSE)) \ for (HYPRE_Int hypre__thread = 0; hypre__thread < hypre__tot; hypre__thread++) \ {\ zypre_omp4_BoxLoopSet3(i1, i2, i3) #if 0 #define zypre_omp4_dist_BoxLoop3_SAME_STRIDE_Begin(ndim, loop_size, \ dbox1, start1, stride1, i1, \ dbox2, start2, stride2, i2, o2, \ dbox3, start3, stride3, i3) \ {\ /* host code: */ \ zypre_omp4_BoxLoopDeclareInit(ndim, loop_size) \ zypre_omp4_BoxKDeclareInit(1, start1, dbox1, stride1) \ zypre_omp4_BoxKDeclareInit(2, start2, dbox2, stride2) \ zypre_omp4_BoxKDeclareInit(3, start3, dbox3, stride3) \ /* device code: */ \ _Pragma (HYPRE_XSTR(omp target teams distribute parallel for IF_CLAUSE MAP_CLAUSE3 IS_DEVICE_CLAUSE TEAM_CLAUSE)) \ for (HYPRE_Int hypre__thread = 0; hypre__thread < hypre__tot; hypre__thread++) \ {\ zypre_omp4_BoxLoopSet3_SAME_STRIDE(i1, i2, o2, i3) #endif /* - - - - - - - - - - - - - - - - - - - - - - - - - - - - * BoxLoop 4 * - - - - - - - - - - - - - - - - - - - - - - - - - - - -*/ #define zypre_omp4_dist_BoxLoop4Begin(ndim, loop_size, \ dbox1, start1, stride1, i1, \ dbox2, start2, stride2, i2, \ dbox3, start3, stride3, i3, \ dbox4, start4, stride4, i4) \ {\ /* host code: */ \ HYPRE_BOXLOOP_ENTRY_PRINT \ zypre_omp4_BoxLoopDeclareInit(ndim, loop_size) \ zypre_omp4_BoxKDeclareInit(1, start1, dbox1, stride1) \ zypre_omp4_BoxKDeclareInit(2, start2, dbox2, stride2) \ zypre_omp4_BoxKDeclareInit(3, start3, dbox3, stride3) \ zypre_omp4_BoxKDeclareInit(4, start4, dbox4, stride4) \ /* device code: */ \ _Pragma (HYPRE_XSTR(omp target teams distribute parallel for IF_CLAUSE MAP_CLAUSE4 IS_DEVICE_CLAUSE TEAM_CLAUSE)) \ for (HYPRE_Int hypre__thread = 0; hypre__thread < hypre__tot; hypre__thread++) \ {\ zypre_omp4_BoxLoopSet4(i1, i2, i3, i4) #if 0 /* no longer needed, use the above BoxLoop's for reductions */ /* - - - - - - - - - - - - - - - - - - - - - - - - - - - - * BoxLoop 1 reduction * - - - - - - - - - - - - - - - - - - - - - - - - - - - -*/ #define zypre_omp4_dist_Red_BoxLoop1Begin(ndim, loop_size, dbox1, start1, stride1, i1, xsum) \ {\ /* host code: */ \ zypre_omp4_BoxLoopDeclareInit(ndim, loop_size) \ zypre_omp4_BoxKDeclareInit(1, start1, dbox1, stride1) \ /* device code: */ \ _Pragma (HYPRE_XSTR(omp target teams distribute parallel for IF_CLAUSE MAP_CLAUSE1 map(tofrom: xsum) reduction(+:xsum) TEAM_CLAUSE)) \ for (HYPRE_Int hypre__thread = 0; hypre__thread < hypre__tot; hypre__thread++) \ {\ zypre_omp4_BoxLoopSet1(i1) /* - - - - - - - - - - - - - - - - - - - - - - - - - - - - * BoxLoop 2 reduction * - - - - - - - - - - - - - - - - - - - - - - - - - - - -*/ #define zypre_omp4_dist_Red_BoxLoop2Begin(ndim, loop_size, dbox1, start1, stride1, i1, dbox2, start2, stride2, i2, xsum) \ {\ /* host code: */ \ zypre_omp4_BoxLoopDeclareInit(ndim, loop_size) \ zypre_omp4_BoxKDeclareInit(1, start1, dbox1, stride1) \ zypre_omp4_BoxKDeclareInit(2, start2, dbox2, stride2) \ /* device code: */ \ _Pragma (HYPRE_XSTR(omp target teams distribute parallel for IF_CLAUSE MAP_CLAUSE2 map(tofrom: xsum) reduction(+:xsum) TEAM_CLAUSE)) \ for (HYPRE_Int hypre__thread = 0; hypre__thread < hypre__tot; hypre__thread++) \ {\ zypre_omp4_BoxLoopSet2(i1, i2) #endif /* - - - - - - - - - - - - - - - - - - - - - - - - - - - - * v2 * host code: declare and initialize variables for box k * - - - - - - - - - - - - - - - - - - - - - - - - - - - -*/ #define zypre_omp4_BoxKDeclareInit_v2(k, stridek)\ /* stridek[0,1,2] */ \ HYPRE_Int HYPRE_XCONCAT3(hypre__stride,0,k), HYPRE_XCONCAT3(hypre__stride,1,k), HYPRE_XCONCAT3(hypre__stride,2,k); \ /*if (hypre__ndim > 0)*/ { HYPRE_XCONCAT3(hypre__stride,0,k) = stridek[0]; } \ if (hypre__ndim > 1) { HYPRE_XCONCAT3(hypre__stride,1,k) = stridek[1]; } \ if (hypre__ndim > 2) { HYPRE_XCONCAT3(hypre__stride,2,k) = stridek[2]; } \ /* - - - - - - - - - - - - - - - - - - - - - - - - - - - - * v2 * device code for BoxLoop 1, set i1 * - - - - - - - - - - - - - - - - - - - - - - - - - - - -*/ #define zypre_omp4_BoxLoopSet1Body_v2(j, i1) \ i1 += ( hypre__J % HYPRE_XCONCAT2(hypre__loop_size,j) ) * HYPRE_XCONCAT3(hypre__stride,j,1);\ hypre__J /= HYPRE_XCONCAT2(hypre__loop_size,j); #define zypre_omp4_BoxLoopSet1_v2(i1, idx) \ HYPRE_Int hypre__J, i1, idx; \ idx = hypre__J = hypre__thread; i1 = 0; \ /*if (hypre__ndim > 0)*/ { zypre_omp4_BoxLoopSet1Body_v2(0, i1) } \ if (hypre__ndim > 1) { zypre_omp4_BoxLoopSet1Body_v2(1, i1) } \ if (hypre__ndim > 2) { zypre_omp4_BoxLoopSet1Body_v2(2, i1) } /* - - - - - - - - - - - - - - - - - - - - - - - - - - - - * v2: Basic * BoxLoop 1 * - - - - - - - - - - - - - - - - - - - - - - - - - - - -*/ #define zypre_omp4_dist_BoxLoop1_v2_Begin(ndim, loop_size, stride1, i1, idx) \ {\ /* host code: */ \ HYPRE_BOXLOOP_ENTRY_PRINT \ zypre_omp4_BoxLoopDeclareInit(ndim, loop_size) \ zypre_omp4_BoxKDeclareInit_v2(1, stride1) \ /* device code: */ \ _Pragma (HYPRE_XSTR(omp target teams distribute parallel for IF_CLAUSE MAP_CLAUSE1 IS_DEVICE_CLAUSE TEAM_CLAUSE)) \ for (HYPRE_Int hypre__thread = 0; hypre__thread < hypre__tot; hypre__thread++) \ {\ zypre_omp4_BoxLoopSet1_v2(i1, idx) /* - - - - - - - - - - - - - - - - - - - - - - - - - - - - * v2 * device code for BoxLoop 2, set i1, i2 * - - - - - - - - - - - - - - - - - - - - - - - - - - - -*/ #define zypre_omp4_BoxLoopSet2Body_v2(j, i1, i2) \ hypre__i = hypre__J % HYPRE_XCONCAT2(hypre__loop_size,j); \ /* twice */ \ i1 += hypre__i * HYPRE_XCONCAT3(hypre__stride,j,1); \ i2 += hypre__i * HYPRE_XCONCAT3(hypre__stride,j,2); \ hypre__J /= HYPRE_XCONCAT2(hypre__loop_size,j); #define zypre_omp4_BoxLoopSet2_v2(i1, i2) \ HYPRE_Int hypre__i, hypre__J, i1, i2; \ hypre__J = hypre__thread; i1 = i2 = 0; \ /*if (hypre__ndim > 0)*/ { zypre_omp4_BoxLoopSet2Body_v2(0, i1, i2) } \ if (hypre__ndim > 1) { zypre_omp4_BoxLoopSet2Body_v2(1, i1, i2) } \ if (hypre__ndim > 2) { zypre_omp4_BoxLoopSet2Body_v2(2, i1, i2) } /* - - - - - - - - - - - - - - - - - - - - - - - - - - - - * v2: Basic * BoxLoop 2 * - - - - - - - - - - - - - - - - - - - - - - - - - - - -*/ #define zypre_omp4_dist_BoxLoop2_v2_Begin(ndim, loop_size, stride1, i1, stride2, i2) \ { \ /* host code: */ \ HYPRE_BOXLOOP_ENTRY_PRINT \ zypre_omp4_BoxLoopDeclareInit(ndim, loop_size) \ zypre_omp4_BoxKDeclareInit_v2(1, stride1) \ zypre_omp4_BoxKDeclareInit_v2(2, stride2) \ /* device code: */ \ _Pragma (HYPRE_XSTR(omp target teams distribute parallel for IF_CLAUSE MAP_CLAUSE2 IS_DEVICE_CLAUSE TEAM_CLAUSE)) \ for (HYPRE_Int hypre__thread = 0; hypre__thread < hypre__tot; hypre__thread++) \ { \ zypre_omp4_BoxLoopSet2_v2(i1, i2) /* - - - - - - - - - - - - - - - - - - - - - - - - - - - - * Basic Loop * - - - - - - - - - - - - - - - - - - - - - - - - - - - -*/ #define zypre_LoopBegin(size, idx) \ { \ /* host code: */ \ /* HYPRE_Int idx = 0; */\ HYPRE_Int hypre__tot = size; \ HYPRE_BOXLOOP_ENTRY_PRINT \ /* device code: */ \ _Pragma (HYPRE_XSTR(omp target teams distribute parallel for IF_CLAUSE MAP_CLAUSE2 IS_DEVICE_CLAUSE TEAM_CLAUSE)) \ for (HYPRE_Int idx = 0; idx < hypre__tot; idx++) \ { #if 0 #define hypre_LoopBegin0(size, idx) \ { \ HYPRE_Int idx, hypre__size = size; \ for (idx = 0; idx < hypre__size; idx++) \ { #define hypre_newBoxLoopGetIndex(index) \ index[0] = hypre__id_0; \ index[1] = hypre__id_1; \ index[2] = hypre__id_2; #endif /* Reduction */ #define hypre_BoxLoop1ReductionBegin(ndim, loop_size, dbox1, start1, stride1, i1, reducesum) \ hypre_BoxLoop1Begin(ndim, loop_size, dbox1, start1, stride1, i1) #define hypre_BoxLoop1ReductionEnd(i1, reducesum) \ hypre_BoxLoop1End(i1) #define hypre_BoxLoop2ReductionBegin(ndim, loop_size, dbox1, start1, stride1, i1, \ dbox2, start2, stride2, i2, reducesum) \ hypre_BoxLoop2Begin(ndim, loop_size, dbox1, start1, stride1, i1, \ dbox2, start2, stride2, i2) #define hypre_BoxLoop2ReductionEnd(i1, i2, reducesum) \ hypre_BoxLoop2End(i1, i2) #endif #else /****************************************************************************** * Copyright 1998-2019 Lawrence Livermore National Security, LLC and other * HYPRE Project Developers. See the top-level COPYRIGHT file for details. * * SPDX-License-Identifier: (Apache-2.0 OR MIT) ******************************************************************************/ /****************************************************************************** * * Header info for the BoxLoop * *****************************************************************************/ /*-------------------------------------------------------------------------- * BoxLoop macros: *--------------------------------------------------------------------------*/ #ifndef HYPRE_NEWBOXLOOP_HEADER #define HYPRE_NEWBOXLOOP_HEADER #ifdef HYPRE_USING_OPENMP #define HYPRE_BOX_REDUCTION #ifdef WIN32 #define Pragma(x) __pragma(HYPRE_XSTR(x)) #else #define Pragma(x) _Pragma(HYPRE_XSTR(x)) #endif #define OMP1 Pragma(omp parallel for private(HYPRE_BOX_PRIVATE) HYPRE_BOX_REDUCTION HYPRE_SMP_SCHEDULE) #else #define OMP1 #endif typedef struct hypre_Boxloop_struct { HYPRE_Int lsize0,lsize1,lsize2; HYPRE_Int strides0,strides1,strides2; HYPRE_Int bstart0,bstart1,bstart2; HYPRE_Int bsize0,bsize1,bsize2; } hypre_Boxloop; #define zypre_newBoxLoop0Begin(ndim, loop_size) \ { \ zypre_BoxLoopDeclare(); \ zypre_BoxLoopInit(ndim, loop_size); \ OMP1 \ for (hypre__block = 0; hypre__block < hypre__num_blocks; hypre__block++) \ { \ zypre_BoxLoopSet(); \ for (hypre__J = 0; hypre__J < hypre__JN; hypre__J++) \ { \ for (hypre__I = 0; hypre__I < hypre__IN; hypre__I++) \ { #define zypre_newBoxLoop0End() \ } \ zypre_BoxLoopInc1(); \ zypre_BoxLoopInc2(); \ } \ } \ } #define zypre_newBoxLoop1Begin(ndim, loop_size, \ dbox1, start1, stride1, i1) \ { \ HYPRE_Int i1; \ zypre_BoxLoopDeclare(); \ zypre_BoxLoopDeclareK(1); \ zypre_BoxLoopInit(ndim, loop_size); \ zypre_BoxLoopInitK(1, dbox1, start1, stride1, i1); \ OMP1 \ for (hypre__block = 0; hypre__block < hypre__num_blocks; hypre__block++) \ { \ HYPRE_Int i1; \ zypre_BoxLoopSet(); \ zypre_BoxLoopSetK(1, i1); \ for (hypre__J = 0; hypre__J < hypre__JN; hypre__J++) \ { \ for (hypre__I = 0; hypre__I < hypre__IN; hypre__I++) \ { #define zypre_newBoxLoop1End(i1) \ i1 += hypre__i0inc1; \ } \ zypre_BoxLoopInc1(); \ i1 += hypre__ikinc1[hypre__d]; \ zypre_BoxLoopInc2(); \ } \ } \ } #define zypre_newBoxLoop2Begin(ndim, loop_size, \ dbox1, start1, stride1, i1, \ dbox2, start2, stride2, i2) \ { \ HYPRE_Int i1, i2; \ zypre_BoxLoopDeclare(); \ zypre_BoxLoopDeclareK(1); \ zypre_BoxLoopDeclareK(2); \ zypre_BoxLoopInit(ndim, loop_size); \ zypre_BoxLoopInitK(1, dbox1, start1, stride1, i1); \ zypre_BoxLoopInitK(2, dbox2, start2, stride2, i2); \ OMP1 \ for (hypre__block = 0; hypre__block < hypre__num_blocks; hypre__block++) \ { \ HYPRE_Int i1, i2; \ zypre_BoxLoopSet(); \ zypre_BoxLoopSetK(1, i1); \ zypre_BoxLoopSetK(2, i2); \ for (hypre__J = 0; hypre__J < hypre__JN; hypre__J++) \ { \ for (hypre__I = 0; hypre__I < hypre__IN; hypre__I++) \ { #define zypre_newBoxLoop2End(i1, i2) \ i1 += hypre__i0inc1; \ i2 += hypre__i0inc2; \ } \ zypre_BoxLoopInc1(); \ i1 += hypre__ikinc1[hypre__d]; \ i2 += hypre__ikinc2[hypre__d]; \ zypre_BoxLoopInc2(); \ } \ } \ } #define zypre_newBoxLoop3Begin(ndim, loop_size, \ dbox1, start1, stride1, i1, \ dbox2, start2, stride2, i2, \ dbox3, start3, stride3, i3) \ { \ HYPRE_Int i1, i2, i3; \ zypre_BoxLoopDeclare(); \ zypre_BoxLoopDeclareK(1); \ zypre_BoxLoopDeclareK(2); \ zypre_BoxLoopDeclareK(3); \ zypre_BoxLoopInit(ndim, loop_size); \ zypre_BoxLoopInitK(1, dbox1, start1, stride1, i1); \ zypre_BoxLoopInitK(2, dbox2, start2, stride2, i2); \ zypre_BoxLoopInitK(3, dbox3, start3, stride3, i3); \ OMP1 \ for (hypre__block = 0; hypre__block < hypre__num_blocks; hypre__block++) \ { \ HYPRE_Int i1, i2, i3; \ zypre_BoxLoopSet(); \ zypre_BoxLoopSetK(1, i1); \ zypre_BoxLoopSetK(2, i2); \ zypre_BoxLoopSetK(3, i3); \ for (hypre__J = 0; hypre__J < hypre__JN; hypre__J++) \ { \ for (hypre__I = 0; hypre__I < hypre__IN; hypre__I++) \ { #define zypre_newBoxLoop3End(i1, i2, i3) \ i1 += hypre__i0inc1; \ i2 += hypre__i0inc2; \ i3 += hypre__i0inc3; \ } \ zypre_BoxLoopInc1(); \ i1 += hypre__ikinc1[hypre__d]; \ i2 += hypre__ikinc2[hypre__d]; \ i3 += hypre__ikinc3[hypre__d]; \ zypre_BoxLoopInc2(); \ } \ } \ } #define zypre_newBoxLoop4Begin(ndim, loop_size, \ dbox1, start1, stride1, i1, \ dbox2, start2, stride2, i2, \ dbox3, start3, stride3, i3, \ dbox4, start4, stride4, i4) \ { \ HYPRE_Int i1, i2, i3, i4; \ zypre_BoxLoopDeclare(); \ zypre_BoxLoopDeclareK(1); \ zypre_BoxLoopDeclareK(2); \ zypre_BoxLoopDeclareK(3); \ zypre_BoxLoopDeclareK(4); \ zypre_BoxLoopInit(ndim, loop_size); \ zypre_BoxLoopInitK(1, dbox1, start1, stride1, i1); \ zypre_BoxLoopInitK(2, dbox2, start2, stride2, i2); \ zypre_BoxLoopInitK(3, dbox3, start3, stride3, i3); \ zypre_BoxLoopInitK(4, dbox4, start4, stride4, i4); \ OMP1 \ for (hypre__block = 0; hypre__block < hypre__num_blocks; hypre__block++) \ { \ HYPRE_Int i1, i2, i3, i4; \ zypre_BoxLoopSet(); \ zypre_BoxLoopSetK(1, i1); \ zypre_BoxLoopSetK(2, i2); \ zypre_BoxLoopSetK(3, i3); \ zypre_BoxLoopSetK(4, i4); \ for (hypre__J = 0; hypre__J < hypre__JN; hypre__J++) \ { \ for (hypre__I = 0; hypre__I < hypre__IN; hypre__I++) \ { #define zypre_newBoxLoop4End(i1, i2, i3, i4) \ i1 += hypre__i0inc1; \ i2 += hypre__i0inc2; \ i3 += hypre__i0inc3; \ i4 += hypre__i0inc4; \ } \ zypre_BoxLoopInc1(); \ i1 += hypre__ikinc1[hypre__d]; \ i2 += hypre__ikinc2[hypre__d]; \ i3 += hypre__ikinc3[hypre__d]; \ i4 += hypre__ikinc4[hypre__d]; \ zypre_BoxLoopInc2(); \ } \ } \ } #define zypre_newBasicBoxLoop2Begin(ndim, loop_size, \ stride1, i1, \ stride2, i2) \ { \ zypre_BoxLoopDeclare(); \ zypre_BoxLoopDeclareK(1); \ zypre_BoxLoopDeclareK(2); \ zypre_BoxLoopInit(ndim, loop_size); \ zypre_BasicBoxLoopInitK(1, stride1); \ zypre_BasicBoxLoopInitK(2, stride2); \ OMP1 \ for (hypre__block = 0; hypre__block < hypre__num_blocks; hypre__block++) \ { \ HYPRE_Int i1, i2; \ zypre_BoxLoopSet(); \ zypre_BoxLoopSetK(1, i1); \ zypre_BoxLoopSetK(2, i2); \ for (hypre__J = 0; hypre__J < hypre__JN; hypre__J++) \ { \ for (hypre__I = 0; hypre__I < hypre__IN; hypre__I++) \ { #define hypre_LoopBegin(size,idx) \ { \ HYPRE_Int idx; \ for (idx = 0;idx < size;idx ++) \ { #define hypre_LoopEnd() \ } \ } #define hypre_newBoxLoopGetIndex zypre_BoxLoopGetIndex #define hypre_BoxLoopGetIndex zypre_BoxLoopGetIndex #define hypre_BoxLoopSetOneBlock zypre_BoxLoopSetOneBlock #define hypre_BoxLoopBlock zypre_BoxLoopBlock #define hypre_BoxLoop0Begin zypre_newBoxLoop0Begin #define hypre_BoxLoop0End zypre_newBoxLoop0End #define hypre_BoxLoop1Begin zypre_newBoxLoop1Begin #define hypre_BoxLoop1End zypre_newBoxLoop1End #define hypre_BoxLoop2Begin zypre_newBoxLoop2Begin #define hypre_BoxLoop2End zypre_newBoxLoop2End #define hypre_BoxLoop3Begin zypre_newBoxLoop3Begin #define hypre_BoxLoop3End zypre_newBoxLoop3End #define hypre_BoxLoop4Begin zypre_newBoxLoop4Begin #define hypre_BoxLoop4End zypre_newBoxLoop4End #define hypre_BasicBoxLoop2Begin zypre_newBasicBoxLoop2Begin /* Reduction */ #define hypre_BoxLoop1ReductionBegin(ndim, loop_size, dbox1, start1, stride1, i1, reducesum) \ hypre_BoxLoop1Begin(ndim, loop_size, dbox1, start1, stride1, i1) #define hypre_BoxLoop1ReductionEnd(i1, reducesum) \ hypre_BoxLoop1End(i1) #define hypre_BoxLoop2ReductionBegin(ndim, loop_size, dbox1, start1, stride1, i1, \ dbox2, start2, stride2, i2, reducesum) \ hypre_BoxLoop2Begin(ndim, loop_size, dbox1, start1, stride1, i1, \ dbox2, start2, stride2, i2) #define hypre_BoxLoop2ReductionEnd(i1, i2, reducesum) \ hypre_BoxLoop2End(i1, i2) #endif #endif #ifdef __cplusplus extern "C" { #endif /****************************************************************************** * Copyright 1998-2019 Lawrence Livermore National Security, LLC and other * HYPRE Project Developers. See the top-level COPYRIGHT file for details. * * SPDX-License-Identifier: (Apache-2.0 OR MIT) ******************************************************************************/ /****************************************************************************** * * Header info for the Box structures * *****************************************************************************/ #ifndef hypre_BOX_HEADER #define hypre_BOX_HEADER #ifndef HYPRE_MAXDIM #define HYPRE_MAXDIM 3 #endif /*-------------------------------------------------------------------------- * hypre_Index: * This is used to define indices in index space, or dimension * sizes of boxes. * * The spatial dimensions x, y, and z may be specified by the * integers 0, 1, and 2, respectively (see the hypre_IndexD macro below). * This simplifies the code in the hypre_Box class by reducing code * replication. *--------------------------------------------------------------------------*/ typedef HYPRE_Int hypre_Index[HYPRE_MAXDIM]; typedef HYPRE_Int *hypre_IndexRef; /*-------------------------------------------------------------------------- * hypre_Box: *--------------------------------------------------------------------------*/ typedef struct hypre_Box_struct { hypre_Index imin; /* min bounding indices */ hypre_Index imax; /* max bounding indices */ HYPRE_Int ndim; /* number of dimensions */ } hypre_Box; /*-------------------------------------------------------------------------- * hypre_BoxArray: * An array of boxes. * Since size can be zero, need to store ndim separately. *--------------------------------------------------------------------------*/ typedef struct hypre_BoxArray_struct { hypre_Box *boxes; /* Array of boxes */ HYPRE_Int size; /* Size of box array */ HYPRE_Int alloc_size; /* Size of currently alloced space */ HYPRE_Int ndim; /* number of dimensions */ } hypre_BoxArray; #define hypre_BoxArrayExcess 10 /*-------------------------------------------------------------------------- * hypre_BoxArrayArray: * An array of box arrays. * Since size can be zero, need to store ndim separately. *--------------------------------------------------------------------------*/ typedef struct hypre_BoxArrayArray_struct { hypre_BoxArray **box_arrays; /* Array of pointers to box arrays */ HYPRE_Int size; /* Size of box array array */ HYPRE_Int ndim; /* number of dimensions */ } hypre_BoxArrayArray; /*-------------------------------------------------------------------------- * Accessor macros: hypre_Index *--------------------------------------------------------------------------*/ #define hypre_IndexD(index, d) (index[d]) /* Avoid using these macros */ #define hypre_IndexX(index) hypre_IndexD(index, 0) #define hypre_IndexY(index) hypre_IndexD(index, 1) #define hypre_IndexZ(index) hypre_IndexD(index, 2) /*-------------------------------------------------------------------------- * Member functions: hypre_Index *--------------------------------------------------------------------------*/ /*----- Avoid using these Index macros -----*/ #define hypre_SetIndex3(index, ix, iy, iz) \ ( hypre_IndexD(index, 0) = ix,\ hypre_IndexD(index, 1) = iy,\ hypre_IndexD(index, 2) = iz ) #define hypre_ClearIndex(index) hypre_SetIndex(index, 0) /*-------------------------------------------------------------------------- * Accessor macros: hypre_Box *--------------------------------------------------------------------------*/ #define hypre_BoxIMin(box) ((box) -> imin) #define hypre_BoxIMax(box) ((box) -> imax) #define hypre_BoxNDim(box) ((box) -> ndim) #define hypre_BoxIMinD(box, d) (hypre_IndexD(hypre_BoxIMin(box), d)) #define hypre_BoxIMaxD(box, d) (hypre_IndexD(hypre_BoxIMax(box), d)) #define hypre_BoxSizeD(box, d) \ hypre_max(0, (hypre_BoxIMaxD(box, d) - hypre_BoxIMinD(box, d) + 1)) #define hypre_IndexDInBox(index, d, box) \ ( hypre_IndexD(index, d) >= hypre_BoxIMinD(box, d) && \ hypre_IndexD(index, d) <= hypre_BoxIMaxD(box, d) ) /* The first hypre_CCBoxIndexRank is better style because it is similar to hypre_BoxIndexRank. The second one sometimes avoids compiler warnings. */ #define hypre_CCBoxIndexRank(box, index) 0 #define hypre_CCBoxIndexRank_noargs() 0 #define hypre_CCBoxOffsetDistance(box, index) 0 /*----- Avoid using these Box macros -----*/ #define hypre_BoxSizeX(box) hypre_BoxSizeD(box, 0) #define hypre_BoxSizeY(box) hypre_BoxSizeD(box, 1) #define hypre_BoxSizeZ(box) hypre_BoxSizeD(box, 2) /*-------------------------------------------------------------------------- * Accessor macros: hypre_BoxArray *--------------------------------------------------------------------------*/ #define hypre_BoxArrayBoxes(box_array) ((box_array) -> boxes) #define hypre_BoxArrayBox(box_array, i) &((box_array) -> boxes[(i)]) #define hypre_BoxArraySize(box_array) ((box_array) -> size) #define hypre_BoxArrayAllocSize(box_array) ((box_array) -> alloc_size) #define hypre_BoxArrayNDim(box_array) ((box_array) -> ndim) /*-------------------------------------------------------------------------- * Accessor macros: hypre_BoxArrayArray *--------------------------------------------------------------------------*/ #define hypre_BoxArrayArrayBoxArrays(box_array_array) \ ((box_array_array) -> box_arrays) #define hypre_BoxArrayArrayBoxArray(box_array_array, i) \ ((box_array_array) -> box_arrays[(i)]) #define hypre_BoxArrayArraySize(box_array_array) \ ((box_array_array) -> size) #define hypre_BoxArrayArrayNDim(box_array_array) \ ((box_array_array) -> ndim) /*-------------------------------------------------------------------------- * Looping macros: *--------------------------------------------------------------------------*/ #define hypre_ForBoxI(i, box_array) \ for (i = 0; i < hypre_BoxArraySize(box_array); i++) #define hypre_ForBoxArrayI(i, box_array_array) \ for (i = 0; i < hypre_BoxArrayArraySize(box_array_array); i++) /*-------------------------------------------------------------------------- * BoxLoop macros: *--------------------------------------------------------------------------*/ #define hypre_SerialBoxLoop0Begin(ndim, loop_size)\ {\ zypre_BoxLoopDeclare();\ zypre_BoxLoopInit(ndim, loop_size);\ hypre_BoxLoopSetOneBlock();\ for (hypre__block = 0; hypre__block < hypre__num_blocks; hypre__block++)\ {\ zypre_BoxLoopSet();\ for (hypre__J = 0; hypre__J < hypre__JN; hypre__J++)\ {\ for (hypre__I = 0; hypre__I < hypre__IN; hypre__I++)\ { #define hypre_SerialBoxLoop0End()\ }\ zypre_BoxLoopInc1();\ zypre_BoxLoopInc2();\ }\ }\ } #define hypre_SerialBoxLoop1Begin(ndim, loop_size,\ dbox1, start1, stride1, i1)\ {\ HYPRE_Int i1;\ zypre_BoxLoopDeclare();\ zypre_BoxLoopDeclareK(1);\ zypre_BoxLoopInit(ndim, loop_size);\ zypre_BoxLoopInitK(1, dbox1, start1, stride1, i1);\ zypre_BoxLoopSetOneBlock();\ for (hypre__block = 0; hypre__block < hypre__num_blocks; hypre__block++)\ {\ zypre_BoxLoopSet();\ zypre_BoxLoopSetK(1, i1);\ for (hypre__J = 0; hypre__J < hypre__JN; hypre__J++)\ {\ for (hypre__I = 0; hypre__I < hypre__IN; hypre__I++)\ { #define hypre_SerialBoxLoop1End(i1)\ i1 += hypre__i0inc1;\ }\ zypre_BoxLoopInc1();\ i1 += hypre__ikinc1[hypre__d];\ zypre_BoxLoopInc2();\ }\ }\ } #define hypre_SerialBoxLoop2Begin(ndim, loop_size,\ dbox1, start1, stride1, i1,\ dbox2, start2, stride2, i2)\ {\ HYPRE_Int i1,i2;\ zypre_BoxLoopDeclare();\ zypre_BoxLoopDeclareK(1);\ zypre_BoxLoopDeclareK(2);\ zypre_BoxLoopInit(ndim, loop_size);\ zypre_BoxLoopInitK(1, dbox1, start1, stride1, i1);\ zypre_BoxLoopInitK(2, dbox2, start2, stride2, i2);\ zypre_BoxLoopSetOneBlock();\ for (hypre__block = 0; hypre__block < hypre__num_blocks; hypre__block++)\ {\ zypre_BoxLoopSet();\ zypre_BoxLoopSetK(1, i1);\ zypre_BoxLoopSetK(2, i2);\ for (hypre__J = 0; hypre__J < hypre__JN; hypre__J++)\ {\ for (hypre__I = 0; hypre__I < hypre__IN; hypre__I++)\ { #define hypre_SerialBoxLoop2End(i1, i2)\ i1 += hypre__i0inc1;\ i2 += hypre__i0inc2;\ }\ zypre_BoxLoopInc1();\ i1 += hypre__ikinc1[hypre__d];\ i2 += hypre__ikinc2[hypre__d];\ zypre_BoxLoopInc2();\ }\ }\ } #define ZYPRE_BOX_PRIVATE hypre__IN,hypre__JN,hypre__I,hypre__J,hypre__d,hypre__i #define HYPRE_BOX_PRIVATE ZYPRE_BOX_PRIVATE #define zypre_BoxLoopDeclare() \ HYPRE_Int hypre__tot, hypre__div, hypre__mod;\ HYPRE_Int hypre__block, hypre__num_blocks;\ HYPRE_Int hypre__d, hypre__ndim;\ HYPRE_Int hypre__I, hypre__J, hypre__IN, hypre__JN;\ HYPRE_Int hypre__i[HYPRE_MAXDIM+1], hypre__n[HYPRE_MAXDIM+1] #define zypre_BoxLoopDeclareK(k) \ HYPRE_Int hypre__ikstart##k, hypre__i0inc##k;\ HYPRE_Int hypre__sk##k[HYPRE_MAXDIM], hypre__ikinc##k[HYPRE_MAXDIM+1] #define zypre_BoxLoopInit(ndim, loop_size) \ hypre__ndim = ndim;\ hypre__n[0] = loop_size[0];\ hypre__tot = 1;\ for (hypre__d = 1; hypre__d < hypre__ndim; hypre__d++)\ {\ hypre__n[hypre__d] = loop_size[hypre__d];\ hypre__tot *= hypre__n[hypre__d];\ }\ hypre__n[hypre__ndim] = 2;\ hypre__num_blocks = hypre_NumThreads();\ if (hypre__tot < hypre__num_blocks)\ {\ hypre__num_blocks = hypre__tot;\ }\ if (hypre__num_blocks > 0)\ {\ hypre__div = hypre__tot / hypre__num_blocks;\ hypre__mod = hypre__tot % hypre__num_blocks;\ } #define zypre_BoxLoopInitK(k, dboxk, startk, stridek, ik) \ hypre__sk##k[0] = stridek[0];\ hypre__ikinc##k[0] = 0;\ ik = hypre_BoxSizeD(dboxk, 0); /* temporarily use ik */\ for (hypre__d = 1; hypre__d < hypre__ndim; hypre__d++)\ {\ hypre__sk##k[hypre__d] = ik*stridek[hypre__d];\ hypre__ikinc##k[hypre__d] = hypre__ikinc##k[hypre__d-1] +\ hypre__sk##k[hypre__d] - hypre__n[hypre__d-1]*hypre__sk##k[hypre__d-1];\ ik *= hypre_BoxSizeD(dboxk, hypre__d);\ }\ hypre__i0inc##k = hypre__sk##k[0];\ hypre__ikinc##k[hypre__ndim] = 0;\ hypre__ikstart##k = hypre_BoxIndexRank(dboxk, startk) #define zypre_BoxLoopSet() \ hypre__IN = hypre__n[0];\ if (hypre__num_blocks > 1)/* in case user sets num_blocks to 1 */\ {\ hypre__JN = hypre__div + ((hypre__mod > hypre__block) ? 1 : 0);\ hypre__J = hypre__block * hypre__div + hypre_min(hypre__mod, hypre__block);\ for (hypre__d = 1; hypre__d < hypre__ndim; hypre__d++)\ {\ hypre__i[hypre__d] = hypre__J % hypre__n[hypre__d];\ hypre__J /= hypre__n[hypre__d];\ }\ }\ else\ {\ hypre__JN = hypre__tot;\ for (hypre__d = 1; hypre__d < hypre__ndim; hypre__d++)\ {\ hypre__i[hypre__d] = 0;\ }\ }\ hypre__i[hypre__ndim] = 0 #define zypre_BoxLoopSetK(k, ik) \ ik = hypre__ikstart##k;\ for (hypre__d = 1; hypre__d < hypre__ndim; hypre__d++)\ {\ ik += hypre__i[hypre__d]*hypre__sk##k[hypre__d];\ } #define zypre_BoxLoopInc1() \ hypre__d = 1;\ while ((hypre__i[hypre__d]+2) > hypre__n[hypre__d])\ {\ hypre__d++;\ } #define zypre_BoxLoopInc2() \ hypre__i[hypre__d]++;\ while (hypre__d > 1)\ {\ hypre__d--;\ hypre__i[hypre__d] = 0;\ } /* This returns the loop index (of type hypre_Index) for the current iteration, * where the numbering starts at 0. It works even when threading is turned on, * as long as 'index' is declared to be private. */ #define zypre_BoxLoopGetIndex(index) \ index[0] = hypre__I;\ for (hypre__d = 1; hypre__d < hypre__ndim; hypre__d++)\ {\ index[hypre__d] = hypre__i[hypre__d];\ } /* Use this before the For macros below to force only one block */ #define zypre_BoxLoopSetOneBlock() hypre__num_blocks = 1 /* Use this to get the block iteration inside a BoxLoop */ #define zypre_BoxLoopBlock() hypre__block /* FIXME: Remove !!! */ /*-----------------------------------*/ #define zypre_BoxLoop0Begin(ndim, loop_size)\ {\ zypre_BoxLoopDeclare();\ zypre_BoxLoopInit(ndim, loop_size); #define zypre_BoxLoop0For()\ for (hypre__block = 0; hypre__block < hypre__num_blocks; hypre__block++)\ {\ zypre_BoxLoopSet();\ for (hypre__J = 0; hypre__J < hypre__JN; hypre__J++)\ {\ for (hypre__I = 0; hypre__I < hypre__IN; hypre__I++)\ { #define zypre_BoxLoop0End()\ }\ zypre_BoxLoopInc1();\ zypre_BoxLoopInc2();\ }\ }\ } /*-----------------------------------*/ #define zypre_BoxLoop1Begin(ndim, loop_size,\ dbox1, start1, stride1, i1)\ {\ HYPRE_Int i1;\ zypre_BoxLoopDeclare();\ zypre_BoxLoopDeclareK(1);\ zypre_BoxLoopInit(ndim, loop_size);\ zypre_BoxLoopInitK(1, dbox1, start1, stride1, i1); #define zypre_BoxLoop1For(i1)\ for (hypre__block = 0; hypre__block < hypre__num_blocks; hypre__block++)\ {\ HYPRE_Int i1;\ zypre_BoxLoopSet();\ zypre_BoxLoopSetK(1, i1);\ for (hypre__J = 0; hypre__J < hypre__JN; hypre__J++)\ {\ for (hypre__I = 0; hypre__I < hypre__IN; hypre__I++)\ { #define zypre_BoxLoop1End(i1)\ i1 += hypre__i0inc1;\ }\ zypre_BoxLoopInc1();\ i1 += hypre__ikinc1[hypre__d];\ zypre_BoxLoopInc2();\ }\ }\ } /*-----------------------------------*/ #define zypre_BoxLoop2Begin(ndim, loop_size,\ dbox1, start1, stride1, i1,\ dbox2, start2, stride2, i2)\ {\ HYPRE_Int i1,i2;\ zypre_BoxLoopDeclare();\ zypre_BoxLoopDeclareK(1);\ zypre_BoxLoopDeclareK(2);\ zypre_BoxLoopInit(ndim, loop_size);\ zypre_BoxLoopInitK(1, dbox1, start1, stride1, i1);\ zypre_BoxLoopInitK(2, dbox2, start2, stride2, i2); #define zypre_BoxLoop2For(i1, i2)\ for (hypre__block = 0; hypre__block < hypre__num_blocks; hypre__block++)\ {\ HYPRE_Int i1,i2;\ zypre_BoxLoopSet();\ zypre_BoxLoopSetK(1, i1);\ zypre_BoxLoopSetK(2, i2);\ for (hypre__J = 0; hypre__J < hypre__JN; hypre__J++)\ {\ for (hypre__I = 0; hypre__I < hypre__IN; hypre__I++)\ { #define zypre_BoxLoop2End(i1, i2)\ i1 += hypre__i0inc1;\ i2 += hypre__i0inc2;\ }\ zypre_BoxLoopInc1();\ i1 += hypre__ikinc1[hypre__d];\ i2 += hypre__ikinc2[hypre__d];\ zypre_BoxLoopInc2();\ }\ }\ } /*-----------------------------------*/ #define zypre_BoxLoop3Begin(ndim, loop_size,\ dbox1, start1, stride1, i1,\ dbox2, start2, stride2, i2,\ dbox3, start3, stride3, i3)\ {\ HYPRE_Int i1,i2,i3;\ zypre_BoxLoopDeclare();\ zypre_BoxLoopDeclareK(1);\ zypre_BoxLoopDeclareK(2);\ zypre_BoxLoopDeclareK(3);\ zypre_BoxLoopInit(ndim, loop_size);\ zypre_BoxLoopInitK(1, dbox1, start1, stride1, i1);\ zypre_BoxLoopInitK(2, dbox2, start2, stride2, i2);\ zypre_BoxLoopInitK(3, dbox3, start3, stride3, i3); #define zypre_BoxLoop3For(i1, i2, i3)\ for (hypre__block = 0; hypre__block < hypre__num_blocks; hypre__block++)\ {\ HYPRE_Int i1,i2,i3;\ zypre_BoxLoopSet();\ zypre_BoxLoopSetK(1, i1);\ zypre_BoxLoopSetK(2, i2);\ zypre_BoxLoopSetK(3, i3);\ for (hypre__J = 0; hypre__J < hypre__JN; hypre__J++)\ {\ for (hypre__I = 0; hypre__I < hypre__IN; hypre__I++)\ { #define zypre_BoxLoop3End(i1, i2, i3)\ i1 += hypre__i0inc1;\ i2 += hypre__i0inc2;\ i3 += hypre__i0inc3;\ }\ zypre_BoxLoopInc1();\ i1 += hypre__ikinc1[hypre__d];\ i2 += hypre__ikinc2[hypre__d];\ i3 += hypre__ikinc3[hypre__d];\ zypre_BoxLoopInc2();\ }\ }\ } /*-----------------------------------*/ #define zypre_BoxLoop4Begin(ndim, loop_size,\ dbox1, start1, stride1, i1,\ dbox2, start2, stride2, i2,\ dbox3, start3, stride3, i3,\ dbox4, start4, stride4, i4)\ {\ HYPRE_Int i1,i2,i3,i4;\ zypre_BoxLoopDeclare();\ zypre_BoxLoopDeclareK(1);\ zypre_BoxLoopDeclareK(2);\ zypre_BoxLoopDeclareK(3);\ zypre_BoxLoopDeclareK(4);\ zypre_BoxLoopInit(ndim, loop_size);\ zypre_BoxLoopInitK(1, dbox1, start1, stride1, i1);\ zypre_BoxLoopInitK(2, dbox2, start2, stride2, i2);\ zypre_BoxLoopInitK(3, dbox3, start3, stride3, i3);\ zypre_BoxLoopInitK(4, dbox4, start4, stride4, i4); #define zypre_BoxLoop4For(i1, i2, i3, i4)\ for (hypre__block = 0; hypre__block < hypre__num_blocks; hypre__block++)\ {\ HYPRE_Int i1,i2,i3,i4;\ zypre_BoxLoopSet();\ zypre_BoxLoopSetK(1, i1);\ zypre_BoxLoopSetK(2, i2);\ zypre_BoxLoopSetK(3, i3);\ zypre_BoxLoopSetK(4, i4);\ for (hypre__J = 0; hypre__J < hypre__JN; hypre__J++)\ {\ for (hypre__I = 0; hypre__I < hypre__IN; hypre__I++)\ { #define zypre_BoxLoop4End(i1, i2, i3, i4)\ i1 += hypre__i0inc1;\ i2 += hypre__i0inc2;\ i3 += hypre__i0inc3;\ i4 += hypre__i0inc4;\ }\ zypre_BoxLoopInc1();\ i1 += hypre__ikinc1[hypre__d];\ i2 += hypre__ikinc2[hypre__d];\ i3 += hypre__ikinc3[hypre__d];\ i4 += hypre__ikinc4[hypre__d];\ zypre_BoxLoopInc2();\ }\ }\ } /*-----------------------------------*/ #define zypre_BasicBoxLoopInitK(k, stridek) \ hypre__sk##k[0] = stridek[0];\ hypre__ikinc##k[0] = 0;\ for (hypre__d = 1; hypre__d < hypre__ndim; hypre__d++)\ {\ hypre__sk##k[hypre__d] = stridek[hypre__d];\ hypre__ikinc##k[hypre__d] = hypre__ikinc##k[hypre__d-1] +\ hypre__sk##k[hypre__d] - hypre__n[hypre__d-1]*hypre__sk##k[hypre__d-1];\ }\ hypre__i0inc##k = hypre__sk##k[0];\ hypre__ikinc##k[hypre__ndim] = 0;\ hypre__ikstart##k = 0 #define zypre_BasicBoxLoop2Begin(ndim, loop_size,\ stride1, i1,\ stride2, i2)\ {\ zypre_BoxLoopDeclare();\ zypre_BoxLoopDeclareK(1);\ zypre_BoxLoopDeclareK(2);\ zypre_BoxLoopInit(ndim, loop_size);\ zypre_BasicBoxLoopInitK(1, stride1);\ zypre_BasicBoxLoopInitK(2, stride2); /*-----------------------------------*/ #endif /*-------------------------------------------------------------------------- * NOTES - Keep these for reference here and elsewhere in the code *--------------------------------------------------------------------------*/ #if 0 #define hypre_BoxLoop2Begin(loop_size, dbox1, start1, stride1, i1, dbox2, start2, stride2, i2) { /* init hypre__i1start */ HYPRE_Int hypre__i1start = hypre_BoxIndexRank(dbox1, start1); HYPRE_Int hypre__i2start = hypre_BoxIndexRank(dbox2, start2); /* declare and set hypre__s1 */ hypre_BoxLoopDeclareS(dbox1, stride1, hypre__sx1, hypre__sy1, hypre__sz1); hypre_BoxLoopDeclareS(dbox2, stride2, hypre__sx2, hypre__sy2, hypre__sz2); /* declare and set hypre__n, hypre__m, hypre__dir, hypre__max, * hypre__div, hypre__mod, hypre__block, hypre__num_blocks */ hypre_BoxLoopDeclareN(loop_size); #define hypre_BoxLoop2For(i, j, k, i1, i2) for (hypre__block = 0; hypre__block < hypre__num_blocks; hypre__block++) { /* set i and hypre__n */ hypre_BoxLoopSet(i, j, k); /* set i1 */ i1 = hypre__i1start + i*hypre__sx1 + j*hypre__sy1 + k*hypre__sz1; i2 = hypre__i2start + i*hypre__sx2 + j*hypre__sy2 + k*hypre__sz2; for (k = 0; k < hypre__nz; k++) { for (j = 0; j < hypre__ny; j++) { for (i = 0; i < hypre__nx; i++) { #define hypre_BoxLoop2End(i1, i2) i1 += hypre__sx1; i2 += hypre__sx2; } i1 += hypre__sy1 - hypre__nx*hypre__sx1; i2 += hypre__sy2 - hypre__nx*hypre__sx2; } i1 += hypre__sz1 - hypre__ny*hypre__sy1; i2 += hypre__sz2 - hypre__ny*hypre__sy2; } } } /*---------------------------------------- * Idea 2: Simple version of Idea 3 below *----------------------------------------*/ N = 1; for (d = 0; d < ndim; d++) { N *= n[d]; i[d] = 0; n[d] -= 2; /* this produces a simpler comparison below */ } i[ndim] = 0; n[ndim] = 0; for (I = 0; I < N; I++) { /* loop body */ for (d = 0; i[d] > n[d]; d++) { i[d] = 0; } i[d]++; i1 += s1[d]; /* NOTE: These are different from hypre__sx1, etc. above */ i2 += s2[d]; /* The lengths of i, n, and s must be (ndim+1) */ } /*---------------------------------------- * Idea 3: Approach used in the box loops *----------------------------------------*/ N = 1; for (d = 1; d < ndim; d++) { N *= n[d]; i[d] = 0; n[d] -= 2; /* this produces a simpler comparison below */ } i[ndim] = 0; n[ndim] = 0; for (J = 0; J < N; J++) { for (I = 0; I < n[0]; I++) { /* loop body */ i1 += s1[0]; i2 += s2[0]; } for (d = 1; i[d] > n[d]; d++) { i[d] = 0; } i[d]++; i1 += s1[d]; /* NOTE: These are different from hypre__sx1, etc. above */ i2 += s2[d]; /* The lengths of i, n, and s must be (ndim+1) */ } #endif /****************************************************************************** * Copyright 1998-2019 Lawrence Livermore National Security, LLC and other * HYPRE Project Developers. See the top-level COPYRIGHT file for details. * * SPDX-License-Identifier: (Apache-2.0 OR MIT) ******************************************************************************/ /****************************************************************************** * * Header info for the struct assumed partition * *****************************************************************************/ #ifndef hypre_ASSUMED_PART_HEADER #define hypre_ASSUMED_PART_HEADER typedef struct { /* the entries will be the same for all procs */ HYPRE_Int ndim; /* number of dimensions */ hypre_BoxArray *regions; /* areas of the grid with boxes */ HYPRE_Int num_regions; /* how many regions */ HYPRE_Int *proc_partitions; /* proc ids assigned to each region (this is size num_regions +1) */ hypre_Index *divisions; /* number of proc divisions in each direction for each region */ /* these entries are specific to each proc */ hypre_BoxArray *my_partition; /* my portion of grid (at most 2) */ hypre_BoxArray *my_partition_boxes; /* boxes in my portion */ HYPRE_Int *my_partition_proc_ids; HYPRE_Int *my_partition_boxnums; HYPRE_Int my_partition_ids_size; HYPRE_Int my_partition_ids_alloc; HYPRE_Int my_partition_num_distinct_procs; } hypre_StructAssumedPart; /*Accessor macros */ #define hypre_StructAssumedPartNDim(apart) ((apart)->ndim) #define hypre_StructAssumedPartRegions(apart) ((apart)->regions) #define hypre_StructAssumedPartNumRegions(apart) ((apart)->num_regions) #define hypre_StructAssumedPartDivisions(apart) ((apart)->divisions) #define hypre_StructAssumedPartDivision(apart, i) ((apart)->divisions[i]) #define hypre_StructAssumedPartProcPartitions(apart) ((apart)->proc_partitions) #define hypre_StructAssumedPartProcPartition(apart, i) ((apart)->proc_partitions[i]) #define hypre_StructAssumedPartMyPartition(apart) ((apart)->my_partition) #define hypre_StructAssumedPartMyPartitionBoxes(apart) ((apart)->my_partition_boxes) #define hypre_StructAssumedPartMyPartitionProcIds(apart) ((apart)->my_partition_proc_ids) #define hypre_StructAssumedPartMyPartitionIdsSize(apart) ((apart)->my_partition_ids_size) #define hypre_StructAssumedPartMyPartitionIdsAlloc(apart) ((apart)->my_partition_ids_alloc) #define hypre_StructAssumedPartMyPartitionNumDistinctProcs(apart) ((apart)->my_partition_num_distinct_procs) #define hypre_StructAssumedPartMyPartitionBoxnums(apart) ((apart)->my_partition_boxnums) #define hypre_StructAssumedPartMyPartitionProcId(apart, i) ((apart)->my_partition_proc_ids[i]) #define hypre_StructAssumedPartMyPartitionBoxnum(apart, i) ((apart)->my_partition_boxnums[i]) #endif /****************************************************************************** * Copyright 1998-2019 Lawrence Livermore National Security, LLC and other * HYPRE Project Developers. See the top-level COPYRIGHT file for details. * * SPDX-License-Identifier: (Apache-2.0 OR MIT) ******************************************************************************/ #ifndef hypre_BOX_MANAGER_HEADER #define hypre_BOX_MANAGER_HEADER /*-------------------------------------------------------------------------- * BoxManEntry *--------------------------------------------------------------------------*/ typedef struct hypre_BoxManEntry_struct { hypre_Index imin; /* Extents of box */ hypre_Index imax; HYPRE_Int ndim; /* Number of dimensions */ HYPRE_Int proc; /* This is a two-part unique id: (proc, id) */ HYPRE_Int id; HYPRE_Int num_ghost[2*HYPRE_MAXDIM]; HYPRE_Int position; /* This indicates the location of the entry in the the * box manager entries array and is used for pairing with * the info object (populated in addentry) */ void *boxman; /* The owning manager (populated in addentry) */ struct hypre_BoxManEntry_struct *next; } hypre_BoxManEntry; /*--------------------------------------------------------------------------- * Box Manager: organizes arbitrary information in a spatial way *----------------------------------------------------------------------------*/ typedef struct { MPI_Comm comm; HYPRE_Int max_nentries; /* storage allocated for entries */ HYPRE_Int is_gather_called; /* Boolean to indicate whether GatherEntries function has been called (prior to assemble) - may not want this (can tell by the size of gather_regions array) */ hypre_BoxArray *gather_regions; /* This is where we collect boxes input by calls to BoxManGatherEntries - to be gathered in the assemble. These are then deleted after the assemble */ HYPRE_Int all_global_known; /* Boolean to say that every processor already has all of the global data for this manager (this could be accessed by a coarsening routine, for example) */ HYPRE_Int is_entries_sort; /* Boolean to say that entries were added in sorted order (id, proc) (this could be accessed by a coarsening routine, for example) */ HYPRE_Int entry_info_size; /* In bytes, the (max) size of the info object for the entries */ HYPRE_Int is_assembled; /* Flag to indicate if the box manager has been assembled (used to control whether or not functions can be used prior to assemble) */ /* Storing the entries */ HYPRE_Int nentries; /* Number of entries stored */ hypre_BoxManEntry *entries; /* Actual box manager entries - sorted by (proc, id) at the end of the assemble) */ HYPRE_Int *procs_sort; /* The sorted procs corresponding to entries */ HYPRE_Int *ids_sort; /* Sorted ids corresponding to the entries */ HYPRE_Int num_procs_sort; /* Number of distinct procs in entries */ HYPRE_Int *procs_sort_offsets; /* Offsets for procs into the entry_sort array */ HYPRE_Int first_local; /* Position of local infomation in entries */ HYPRE_Int local_proc_offset; /* Position of local information in offsets */ /* Here is the table that organizes the entries spatially (by index) */ hypre_BoxManEntry **index_table; /* This points into 'entries' array and corresponds to the index arays */ HYPRE_Int *indexes[HYPRE_MAXDIM]; /* Indexes (ordered) for imin and imax of each box in the entries array */ HYPRE_Int size[HYPRE_MAXDIM]; /* How many indexes in each direction */ HYPRE_Int last_index[HYPRE_MAXDIM]; /* Last index used in the indexes map */ HYPRE_Int num_my_entries; /* Num entries with proc_id = myid */ HYPRE_Int *my_ids; /* Array of ids corresponding to my entries */ hypre_BoxManEntry **my_entries; /* Points into entries that are mine and corresponds to my_ids array. This is destroyed in the assemble. */ void *info_objects; /* Array of info objects (each of size entry_info_size), managed byte-wise */ hypre_StructAssumedPart *assumed_partition; /* The assumed partition object. For now this is only used during the assemble (where it is created). */ HYPRE_Int ndim; /* Problem dimension (known in the grid) */ hypre_Box *bounding_box; /* Bounding box from associated grid */ HYPRE_Int next_id; /* Counter to indicate the next id that would be unique (regardless of proc id) */ /* Ghost stuff */ HYPRE_Int num_ghost[2*HYPRE_MAXDIM]; } hypre_BoxManager; /*-------------------------------------------------------------------------- * Accessor macros: hypre_BoxMan *--------------------------------------------------------------------------*/ #define hypre_BoxManComm(manager) ((manager) -> comm) #define hypre_BoxManMaxNEntries(manager) ((manager) -> max_nentries) #define hypre_BoxManIsGatherCalled(manager) ((manager) -> is_gather_called) #define hypre_BoxManIsEntriesSort(manager) ((manager) -> is_entries_sort) #define hypre_BoxManGatherRegions(manager) ((manager) -> gather_regions) #define hypre_BoxManAllGlobalKnown(manager) ((manager) -> all_global_known) #define hypre_BoxManEntryInfoSize(manager) ((manager) -> entry_info_size) #define hypre_BoxManNEntries(manager) ((manager) -> nentries) #define hypre_BoxManEntries(manager) ((manager) -> entries) #define hypre_BoxManInfoObjects(manager) ((manager) -> info_objects) #define hypre_BoxManIsAssembled(manager) ((manager) -> is_assembled) #define hypre_BoxManProcsSort(manager) ((manager) -> procs_sort) #define hypre_BoxManIdsSort(manager) ((manager) -> ids_sort) #define hypre_BoxManNumProcsSort(manager) ((manager) -> num_procs_sort) #define hypre_BoxManProcsSortOffsets(manager) ((manager) -> procs_sort_offsets) #define hypre_BoxManLocalProcOffset(manager) ((manager) -> local_proc_offset) #define hypre_BoxManFirstLocal(manager) ((manager) -> first_local) #define hypre_BoxManIndexTable(manager) ((manager) -> index_table) #define hypre_BoxManIndexes(manager) ((manager) -> indexes) #define hypre_BoxManSize(manager) ((manager) -> size) #define hypre_BoxManLastIndex(manager) ((manager) -> last_index) #define hypre_BoxManNumMyEntries(manager) ((manager) -> num_my_entries) #define hypre_BoxManMyIds(manager) ((manager) -> my_ids) #define hypre_BoxManMyEntries(manager) ((manager) -> my_entries) #define hypre_BoxManAssumedPartition(manager) ((manager) -> assumed_partition) #define hypre_BoxManNDim(manager) ((manager) -> ndim) #define hypre_BoxManBoundingBox(manager) ((manager) -> bounding_box) #define hypre_BoxManNextId(manager) ((manager) -> next_id) #define hypre_BoxManNumGhost(manager) ((manager) -> num_ghost) #define hypre_BoxManIndexesD(manager, d) hypre_BoxManIndexes(manager)[d] #define hypre_BoxManSizeD(manager, d) hypre_BoxManSize(manager)[d] #define hypre_BoxManLastIndexD(manager, d) hypre_BoxManLastIndex(manager)[d] #define hypre_BoxManInfoObject(manager, i) \ (void *) ((char *)hypre_BoxManInfoObjects(manager) + i* hypre_BoxManEntryInfoSize(manager)) /*-------------------------------------------------------------------------- * Accessor macros: hypre_BoxManEntry *--------------------------------------------------------------------------*/ #define hypre_BoxManEntryIMin(entry) ((entry) -> imin) #define hypre_BoxManEntryIMax(entry) ((entry) -> imax) #define hypre_BoxManEntryNDim(entry) ((entry) -> ndim) #define hypre_BoxManEntryProc(entry) ((entry) -> proc) #define hypre_BoxManEntryId(entry) ((entry) -> id) #define hypre_BoxManEntryPosition(entry) ((entry) -> position) #define hypre_BoxManEntryNumGhost(entry) ((entry) -> num_ghost) #define hypre_BoxManEntryNext(entry) ((entry) -> next) #define hypre_BoxManEntryBoxMan(entry) ((entry) -> boxman) #endif /****************************************************************************** * Copyright 1998-2019 Lawrence Livermore National Security, LLC and other * HYPRE Project Developers. See the top-level COPYRIGHT file for details. * * SPDX-License-Identifier: (Apache-2.0 OR MIT) ******************************************************************************/ /****************************************************************************** * * Header info for the hypre_StructGrid structures * *****************************************************************************/ #ifndef hypre_STRUCT_GRID_HEADER #define hypre_STRUCT_GRID_HEADER /*-------------------------------------------------------------------------- * hypre_StructGrid: *--------------------------------------------------------------------------*/ typedef struct hypre_StructGrid_struct { MPI_Comm comm; HYPRE_Int ndim; /* Number of grid dimensions */ hypre_BoxArray *boxes; /* Array of boxes in this process */ HYPRE_Int *ids; /* Unique IDs for boxes */ hypre_Index max_distance; /* Neighborhood size - in each dimension*/ hypre_Box *bounding_box; /* Bounding box around grid */ HYPRE_Int local_size; /* Number of grid points locally */ HYPRE_BigInt global_size; /* Total number of grid points */ hypre_Index periodic; /* Indicates if grid is periodic */ HYPRE_Int num_periods; /* number of box set periods */ hypre_Index *pshifts; /* shifts of periodicity */ HYPRE_Int ref_count; HYPRE_Int ghlocal_size; /* Number of vars in box including ghosts */ HYPRE_Int num_ghost[2*HYPRE_MAXDIM]; /* ghost layer size */ hypre_BoxManager *boxman; #if defined(HYPRE_USING_CUDA) HYPRE_Int data_location; #endif } hypre_StructGrid; /*-------------------------------------------------------------------------- * Accessor macros: hypre_StructGrid *--------------------------------------------------------------------------*/ #define hypre_StructGridComm(grid) ((grid) -> comm) #define hypre_StructGridNDim(grid) ((grid) -> ndim) #define hypre_StructGridBoxes(grid) ((grid) -> boxes) #define hypre_StructGridIDs(grid) ((grid) -> ids) #define hypre_StructGridMaxDistance(grid) ((grid) -> max_distance) #define hypre_StructGridBoundingBox(grid) ((grid) -> bounding_box) #define hypre_StructGridLocalSize(grid) ((grid) -> local_size) #define hypre_StructGridGlobalSize(grid) ((grid) -> global_size) #define hypre_StructGridPeriodic(grid) ((grid) -> periodic) #define hypre_StructGridNumPeriods(grid) ((grid) -> num_periods) #define hypre_StructGridPShifts(grid) ((grid) -> pshifts) #define hypre_StructGridPShift(grid, i) ((grid) -> pshifts[i]) #define hypre_StructGridRefCount(grid) ((grid) -> ref_count) #define hypre_StructGridGhlocalSize(grid) ((grid) -> ghlocal_size) #define hypre_StructGridNumGhost(grid) ((grid) -> num_ghost) #define hypre_StructGridBoxMan(grid) ((grid) -> boxman) #define hypre_StructGridBox(grid, i) \ (hypre_BoxArrayBox(hypre_StructGridBoxes(grid), i)) #define hypre_StructGridNumBoxes(grid) \ (hypre_BoxArraySize(hypre_StructGridBoxes(grid))) #define hypre_StructGridIDPeriod(grid) \ hypre_BoxNeighborsIDPeriod(hypre_StructGridNeighbors(grid)) #if defined(HYPRE_USING_CUDA) #define hypre_StructGridDataLocation(grid) ((grid) -> data_location) #endif /*-------------------------------------------------------------------------- * Looping macros: *--------------------------------------------------------------------------*/ #define hypre_ForStructGridBoxI(i, grid) \ hypre_ForBoxI(i, hypre_StructGridBoxes(grid)) #endif /****************************************************************************** * Copyright 1998-2019 Lawrence Livermore National Security, LLC and other * HYPRE Project Developers. See the top-level COPYRIGHT file for details. * * SPDX-License-Identifier: (Apache-2.0 OR MIT) ******************************************************************************/ /****************************************************************************** * * Header info for hypre_StructStencil data structures * *****************************************************************************/ #ifndef hypre_STRUCT_STENCIL_HEADER #define hypre_STRUCT_STENCIL_HEADER /*-------------------------------------------------------------------------- * hypre_StructStencil *--------------------------------------------------------------------------*/ typedef struct hypre_StructStencil_struct { hypre_Index *shape; /* Description of a stencil's shape */ HYPRE_Int size; /* Number of stencil coefficients */ HYPRE_Int ndim; /* Number of dimensions */ HYPRE_Int ref_count; } hypre_StructStencil; /*-------------------------------------------------------------------------- * Accessor functions for the hypre_StructStencil structure *--------------------------------------------------------------------------*/ #define hypre_StructStencilShape(stencil) ((stencil) -> shape) #define hypre_StructStencilSize(stencil) ((stencil) -> size) #define hypre_StructStencilNDim(stencil) ((stencil) -> ndim) #define hypre_StructStencilRefCount(stencil) ((stencil) -> ref_count) #define hypre_StructStencilElement(stencil, i) hypre_StructStencilShape(stencil)[i] #endif /****************************************************************************** * Copyright 1998-2019 Lawrence Livermore National Security, LLC and other * HYPRE Project Developers. See the top-level COPYRIGHT file for details. * * SPDX-License-Identifier: (Apache-2.0 OR MIT) ******************************************************************************/ #ifndef hypre_COMMUNICATION_HEADER #define hypre_COMMUNICATION_HEADER /*-------------------------------------------------------------------------- * hypre_CommInfo: * * For "reverse" communication, the following are not needed (may be NULL) * send_rboxnums, send_rboxes, send_transforms * * For "forward" communication, the following are not needed (may be NULL) * recv_rboxnums, recv_rboxes, recv_transforms * *--------------------------------------------------------------------------*/ typedef struct hypre_CommInfo_struct { HYPRE_Int ndim; hypre_BoxArrayArray *send_boxes; hypre_Index send_stride; HYPRE_Int **send_processes; HYPRE_Int **send_rboxnums; hypre_BoxArrayArray *send_rboxes; /* send_boxes, some with periodic shift */ hypre_BoxArrayArray *recv_boxes; hypre_Index recv_stride; HYPRE_Int **recv_processes; HYPRE_Int **recv_rboxnums; hypre_BoxArrayArray *recv_rboxes; /* recv_boxes, some with periodic shift */ HYPRE_Int num_transforms; /* may be 0 = identity transform */ hypre_Index *coords; /* may be NULL = identity transform */ hypre_Index *dirs; /* may be NULL = identity transform */ HYPRE_Int **send_transforms; /* may be NULL = identity transform */ HYPRE_Int **recv_transforms; /* may be NULL = identity transform */ HYPRE_Int boxes_match; /* true (>0) if each send box has a * matching box on the recv processor */ } hypre_CommInfo; /*-------------------------------------------------------------------------- * hypre_CommEntryType: *--------------------------------------------------------------------------*/ typedef struct hypre_CommEntryType_struct { HYPRE_Int offset; /* offset for the data */ HYPRE_Int dim; /* dimension of the communication */ HYPRE_Int length_array[HYPRE_MAXDIM]; /* last dim has length num_values */ HYPRE_Int stride_array[HYPRE_MAXDIM+1]; HYPRE_Int *order; /* order of last dim values */ } hypre_CommEntryType; /*-------------------------------------------------------------------------- * hypre_CommType: *--------------------------------------------------------------------------*/ typedef struct hypre_CommType_struct { HYPRE_Int proc; HYPRE_Int bufsize; /* message buffer size (in doubles) */ HYPRE_Int num_entries; hypre_CommEntryType *entries; /* this is only needed until first send buffer prefix is packed */ HYPRE_Int *rem_boxnums; /* entry remote box numbers */ hypre_Box *rem_boxes; /* entry remote boxes */ } hypre_CommType; /*-------------------------------------------------------------------------- * hypre_CommPkg: * Structure containing information for doing communications *--------------------------------------------------------------------------*/ typedef struct hypre_CommPkg_struct { MPI_Comm comm; HYPRE_Int first_comm; /* is this the first communication? */ HYPRE_Int ndim; HYPRE_Int num_values; hypre_Index send_stride; hypre_Index recv_stride; HYPRE_Int send_bufsize; /* total send buffer size (in doubles) */ HYPRE_Int recv_bufsize; /* total recv buffer size (in doubles) */ HYPRE_Int num_sends; HYPRE_Int num_recvs; hypre_CommType *send_types; hypre_CommType *recv_types; hypre_CommType *copy_from_type; hypre_CommType *copy_to_type; /* these pointers are just to help free up memory for send/from types */ hypre_CommEntryType *entries; HYPRE_Int *rem_boxnums; hypre_Box *rem_boxes; HYPRE_Int num_orders; HYPRE_Int **orders; /* num_orders x num_values */ HYPRE_Int *recv_data_offsets; /* offsets into recv data (by box) */ hypre_BoxArray *recv_data_space; /* recv data dimensions (by box) */ hypre_Index identity_coord; hypre_Index identity_dir; HYPRE_Int *identity_order; } hypre_CommPkg; /*-------------------------------------------------------------------------- * CommHandle: *--------------------------------------------------------------------------*/ typedef struct hypre_CommHandle_struct { hypre_CommPkg *comm_pkg; HYPRE_Complex *send_data; HYPRE_Complex *recv_data; HYPRE_Int num_requests; hypre_MPI_Request *requests; hypre_MPI_Status *status; HYPRE_Complex **send_buffers; HYPRE_Complex **recv_buffers; HYPRE_Complex **send_buffers_data; HYPRE_Complex **recv_buffers_data; /* set = 0, add = 1 */ HYPRE_Int action; } hypre_CommHandle; /*-------------------------------------------------------------------------- * Accessor macros: hypre_CommInto *--------------------------------------------------------------------------*/ #define hypre_CommInfoNDim(info) (info -> ndim) #define hypre_CommInfoSendBoxes(info) (info -> send_boxes) #define hypre_CommInfoSendStride(info) (info -> send_stride) #define hypre_CommInfoSendProcesses(info) (info -> send_processes) #define hypre_CommInfoSendRBoxnums(info) (info -> send_rboxnums) #define hypre_CommInfoSendRBoxes(info) (info -> send_rboxes) #define hypre_CommInfoRecvBoxes(info) (info -> recv_boxes) #define hypre_CommInfoRecvStride(info) (info -> recv_stride) #define hypre_CommInfoRecvProcesses(info) (info -> recv_processes) #define hypre_CommInfoRecvRBoxnums(info) (info -> recv_rboxnums) #define hypre_CommInfoRecvRBoxes(info) (info -> recv_rboxes) #define hypre_CommInfoNumTransforms(info) (info -> num_transforms) #define hypre_CommInfoCoords(info) (info -> coords) #define hypre_CommInfoDirs(info) (info -> dirs) #define hypre_CommInfoSendTransforms(info) (info -> send_transforms) #define hypre_CommInfoRecvTransforms(info) (info -> recv_transforms) #define hypre_CommInfoBoxesMatch(info) (info -> boxes_match) /*-------------------------------------------------------------------------- * Accessor macros: hypre_CommEntryType *--------------------------------------------------------------------------*/ #define hypre_CommEntryTypeOffset(entry) (entry -> offset) #define hypre_CommEntryTypeDim(entry) (entry -> dim) #define hypre_CommEntryTypeLengthArray(entry) (entry -> length_array) #define hypre_CommEntryTypeStrideArray(entry) (entry -> stride_array) #define hypre_CommEntryTypeOrder(entry) (entry -> order) /*-------------------------------------------------------------------------- * Accessor macros: hypre_CommType *--------------------------------------------------------------------------*/ #define hypre_CommTypeProc(type) (type -> proc) #define hypre_CommTypeBufsize(type) (type -> bufsize) #define hypre_CommTypeNumEntries(type) (type -> num_entries) #define hypre_CommTypeEntries(type) (type -> entries) #define hypre_CommTypeEntry(type, i) &(type -> entries[i]) #define hypre_CommTypeRemBoxnums(type) (type -> rem_boxnums) #define hypre_CommTypeRemBoxnum(type, i) (type -> rem_boxnums[i]) #define hypre_CommTypeRemBoxes(type) (type -> rem_boxes) #define hypre_CommTypeRemBox(type, i) &(type -> rem_boxes[i]) /*-------------------------------------------------------------------------- * Accessor macros: hypre_CommPkg *--------------------------------------------------------------------------*/ #define hypre_CommPkgComm(comm_pkg) (comm_pkg -> comm) #define hypre_CommPkgFirstComm(comm_pkg) (comm_pkg -> first_comm) #define hypre_CommPkgNDim(comm_pkg) (comm_pkg -> ndim) #define hypre_CommPkgNumValues(comm_pkg) (comm_pkg -> num_values) #define hypre_CommPkgSendStride(comm_pkg) (comm_pkg -> send_stride) #define hypre_CommPkgRecvStride(comm_pkg) (comm_pkg -> recv_stride) #define hypre_CommPkgSendBufsize(comm_pkg) (comm_pkg -> send_bufsize) #define hypre_CommPkgRecvBufsize(comm_pkg) (comm_pkg -> recv_bufsize) #define hypre_CommPkgNumSends(comm_pkg) (comm_pkg -> num_sends) #define hypre_CommPkgNumRecvs(comm_pkg) (comm_pkg -> num_recvs) #define hypre_CommPkgSendTypes(comm_pkg) (comm_pkg -> send_types) #define hypre_CommPkgSendType(comm_pkg, i) &(comm_pkg -> send_types[i]) #define hypre_CommPkgRecvTypes(comm_pkg) (comm_pkg -> recv_types) #define hypre_CommPkgRecvType(comm_pkg, i) &(comm_pkg -> recv_types[i]) #define hypre_CommPkgCopyFromType(comm_pkg) (comm_pkg -> copy_from_type) #define hypre_CommPkgCopyToType(comm_pkg) (comm_pkg -> copy_to_type) #define hypre_CommPkgEntries(comm_pkg) (comm_pkg -> entries) #define hypre_CommPkgRemBoxnums(comm_pkg) (comm_pkg -> rem_boxnums) #define hypre_CommPkgRemBoxes(comm_pkg) (comm_pkg -> rem_boxes) #define hypre_CommPkgNumOrders(comm_pkg) (comm_pkg -> num_orders) #define hypre_CommPkgOrders(comm_pkg) (comm_pkg -> orders) #define hypre_CommPkgRecvDataOffsets(comm_pkg) (comm_pkg -> recv_data_offsets) #define hypre_CommPkgRecvDataSpace(comm_pkg) (comm_pkg -> recv_data_space) #define hypre_CommPkgIdentityCoord(comm_pkg) (comm_pkg -> identity_coord) #define hypre_CommPkgIdentityDir(comm_pkg) (comm_pkg -> identity_dir) #define hypre_CommPkgIdentityOrder(comm_pkg) (comm_pkg -> identity_order) /*-------------------------------------------------------------------------- * Accessor macros: hypre_CommHandle *--------------------------------------------------------------------------*/ #define hypre_CommHandleCommPkg(comm_handle) (comm_handle -> comm_pkg) #define hypre_CommHandleSendData(comm_handle) (comm_handle -> send_data) #define hypre_CommHandleRecvData(comm_handle) (comm_handle -> recv_data) #define hypre_CommHandleNumRequests(comm_handle) (comm_handle -> num_requests) #define hypre_CommHandleRequests(comm_handle) (comm_handle -> requests) #define hypre_CommHandleStatus(comm_handle) (comm_handle -> status) #define hypre_CommHandleSendBuffers(comm_handle) (comm_handle -> send_buffers) #define hypre_CommHandleRecvBuffers(comm_handle) (comm_handle -> recv_buffers) #define hypre_CommHandleAction(comm_handle) (comm_handle -> action) #define hypre_CommHandleSendBuffersDevice(comm_handle) (comm_handle -> send_buffers_data) #define hypre_CommHandleRecvBuffersDevice(comm_handle) (comm_handle -> recv_buffers_data) #endif /****************************************************************************** * Copyright 1998-2019 Lawrence Livermore National Security, LLC and other * HYPRE Project Developers. See the top-level COPYRIGHT file for details. * * SPDX-License-Identifier: (Apache-2.0 OR MIT) ******************************************************************************/ /****************************************************************************** * * Header info for computation * *****************************************************************************/ #ifndef hypre_COMPUTATION_HEADER #define hypre_COMPUTATION_HEADER /*-------------------------------------------------------------------------- * hypre_ComputeInfo: *--------------------------------------------------------------------------*/ typedef struct hypre_ComputeInfo_struct { hypre_CommInfo *comm_info; hypre_BoxArrayArray *indt_boxes; hypre_BoxArrayArray *dept_boxes; hypre_Index stride; } hypre_ComputeInfo; /*-------------------------------------------------------------------------- * hypre_ComputePkg: * Structure containing information for doing computations. *--------------------------------------------------------------------------*/ typedef struct hypre_ComputePkg_struct { hypre_CommPkg *comm_pkg; hypre_BoxArrayArray *indt_boxes; hypre_BoxArrayArray *dept_boxes; hypre_Index stride; hypre_StructGrid *grid; hypre_BoxArray *data_space; HYPRE_Int num_values; } hypre_ComputePkg; /*-------------------------------------------------------------------------- * Accessor macros: hypre_ComputeInfo *--------------------------------------------------------------------------*/ #define hypre_ComputeInfoCommInfo(info) (info -> comm_info) #define hypre_ComputeInfoIndtBoxes(info) (info -> indt_boxes) #define hypre_ComputeInfoDeptBoxes(info) (info -> dept_boxes) #define hypre_ComputeInfoStride(info) (info -> stride) /*-------------------------------------------------------------------------- * Accessor macros: hypre_ComputePkg *--------------------------------------------------------------------------*/ #define hypre_ComputePkgCommPkg(compute_pkg) (compute_pkg -> comm_pkg) #define hypre_ComputePkgIndtBoxes(compute_pkg) (compute_pkg -> indt_boxes) #define hypre_ComputePkgDeptBoxes(compute_pkg) (compute_pkg -> dept_boxes) #define hypre_ComputePkgStride(compute_pkg) (compute_pkg -> stride) #define hypre_ComputePkgGrid(compute_pkg) (compute_pkg -> grid) #define hypre_ComputePkgDataSpace(compute_pkg) (compute_pkg -> data_space) #define hypre_ComputePkgNumValues(compute_pkg) (compute_pkg -> num_values) #endif /****************************************************************************** * Copyright 1998-2019 Lawrence Livermore National Security, LLC and other * HYPRE Project Developers. See the top-level COPYRIGHT file for details. * * SPDX-License-Identifier: (Apache-2.0 OR MIT) ******************************************************************************/ /****************************************************************************** * * Header info for the hypre_StructMatrix structures * *****************************************************************************/ #ifndef hypre_STRUCT_MATRIX_HEADER #define hypre_STRUCT_MATRIX_HEADER /*-------------------------------------------------------------------------- * hypre_StructMatrix: *--------------------------------------------------------------------------*/ typedef struct hypre_StructMatrix_struct { MPI_Comm comm; hypre_StructGrid *grid; hypre_StructStencil *user_stencil; hypre_StructStencil *stencil; HYPRE_Int num_values; /* Number of "stored" coefficients */ hypre_BoxArray *data_space; HYPRE_Complex *data; /* Pointer to variable matrix data */ HYPRE_Complex *data_const; /* Pointer to constant matrix data */ HYPRE_Complex **stencil_data; /* Pointer for each stencil */ HYPRE_Int data_alloced; /* Boolean used for freeing data */ HYPRE_Int data_size; /* Size of variable matrix data */ HYPRE_Int data_const_size; /* Size of constant matrix data */ HYPRE_Int **data_indices; /* num-boxes by stencil-size array of indices into the data array. data_indices[b][s] is the starting index of matrix data corresponding to box b and stencil coefficient s */ HYPRE_Int constant_coefficient; /* normally 0; set to 1 for constant coefficient matrices or 2 for constant coefficient with variable diagonal */ HYPRE_Int symmetric; /* Is the matrix symmetric */ HYPRE_Int *symm_elements; /* Which elements are "symmetric" */ HYPRE_Int num_ghost[2*HYPRE_MAXDIM]; /* Num ghost layers in each direction */ HYPRE_BigInt global_size; /* Total number of nonzero coeffs */ hypre_CommPkg *comm_pkg; /* Info on how to update ghost data */ HYPRE_Int ref_count; } hypre_StructMatrix; /*-------------------------------------------------------------------------- * Accessor macros: hypre_StructMatrix *--------------------------------------------------------------------------*/ #define hypre_StructMatrixComm(matrix) ((matrix) -> comm) #define hypre_StructMatrixGrid(matrix) ((matrix) -> grid) #define hypre_StructMatrixUserStencil(matrix) ((matrix) -> user_stencil) #define hypre_StructMatrixStencil(matrix) ((matrix) -> stencil) #define hypre_StructMatrixNumValues(matrix) ((matrix) -> num_values) #define hypre_StructMatrixDataSpace(matrix) ((matrix) -> data_space) #define hypre_StructMatrixData(matrix) ((matrix) -> data) #define hypre_StructMatrixDataConst(matrix) ((matrix) -> data_const) #define hypre_StructMatrixStencilData(matrix) ((matrix) -> stencil_data) #define hypre_StructMatrixDataAlloced(matrix) ((matrix) -> data_alloced) #define hypre_StructMatrixDataSize(matrix) ((matrix) -> data_size) #define hypre_StructMatrixDataConstSize(matrix) ((matrix) -> data_const_size) #define hypre_StructMatrixDataIndices(matrix) ((matrix) -> data_indices) #define hypre_StructMatrixConstantCoefficient(matrix) ((matrix) -> constant_coefficient) #define hypre_StructMatrixSymmetric(matrix) ((matrix) -> symmetric) #define hypre_StructMatrixSymmElements(matrix) ((matrix) -> symm_elements) #define hypre_StructMatrixNumGhost(matrix) ((matrix) -> num_ghost) #define hypre_StructMatrixGlobalSize(matrix) ((matrix) -> global_size) #define hypre_StructMatrixCommPkg(matrix) ((matrix) -> comm_pkg) #define hypre_StructMatrixRefCount(matrix) ((matrix) -> ref_count) #define hypre_StructMatrixNDim(matrix) \ hypre_StructGridNDim(hypre_StructMatrixGrid(matrix)) #define hypre_StructMatrixBox(matrix, b) \ hypre_BoxArrayBox(hypre_StructMatrixDataSpace(matrix), b) #define hypre_StructMatrixBoxData(matrix, b, s) \ (hypre_StructMatrixStencilData(matrix)[s] + hypre_StructMatrixDataIndices(matrix)[b][s]) #define hypre_StructMatrixBoxDataValue(matrix, b, s, index) \ (hypre_StructMatrixBoxData(matrix, b, s) + \ hypre_BoxIndexRank(hypre_StructMatrixBox(matrix, b), index)) #define hypre_CCStructMatrixBoxDataValue(matrix, b, s, index) \ (hypre_StructMatrixBoxData(matrix, b, s) + \ hypre_CCBoxIndexRank(hypre_StructMatrixBox(matrix, b), index)) #endif /****************************************************************************** * Copyright 1998-2019 Lawrence Livermore National Security, LLC and other * HYPRE Project Developers. See the top-level COPYRIGHT file for details. * * SPDX-License-Identifier: (Apache-2.0 OR MIT) ******************************************************************************/ /****************************************************************************** * * Header info for the hypre_StructVector structures * *****************************************************************************/ #ifndef hypre_STRUCT_VECTOR_HEADER #define hypre_STRUCT_VECTOR_HEADER /*-------------------------------------------------------------------------- * hypre_StructVector: *--------------------------------------------------------------------------*/ typedef struct hypre_StructVector_struct { MPI_Comm comm; hypre_StructGrid *grid; hypre_BoxArray *data_space; HYPRE_Complex *data; /* Pointer to vector data on device*/ HYPRE_Int data_alloced; /* Boolean used for freeing data */ HYPRE_Int data_size; /* Size of vector data */ HYPRE_Int *data_indices; /* num-boxes array of indices into the data array. data_indices[b] is the starting index of vector data corresponding to box b. */ HYPRE_Int num_ghost[2*HYPRE_MAXDIM]; /* Num ghost layers in each * direction */ HYPRE_Int bghost_not_clear; /* Are boundary ghosts clear? */ HYPRE_BigInt global_size; /* Total number coefficients */ HYPRE_Int ref_count; } hypre_StructVector; /*-------------------------------------------------------------------------- * Accessor macros: hypre_StructVector *--------------------------------------------------------------------------*/ #define hypre_StructVectorComm(vector) ((vector) -> comm) #define hypre_StructVectorGrid(vector) ((vector) -> grid) #define hypre_StructVectorDataSpace(vector) ((vector) -> data_space) #define hypre_StructVectorData(vector) ((vector) -> data) #define hypre_StructVectorDataAlloced(vector) ((vector) -> data_alloced) #define hypre_StructVectorDataSize(vector) ((vector) -> data_size) #define hypre_StructVectorDataIndices(vector) ((vector) -> data_indices) #define hypre_StructVectorNumGhost(vector) ((vector) -> num_ghost) #define hypre_StructVectorBGhostNotClear(vector)((vector) -> bghost_not_clear) #define hypre_StructVectorGlobalSize(vector) ((vector) -> global_size) #define hypre_StructVectorRefCount(vector) ((vector) -> ref_count) #define hypre_StructVectorNDim(vector) \ hypre_StructGridNDim(hypre_StructVectorGrid(vector)) #define hypre_StructVectorBox(vector, b) \ hypre_BoxArrayBox(hypre_StructVectorDataSpace(vector), b) #define hypre_StructVectorBoxData(vector, b) \ (hypre_StructVectorData(vector) + hypre_StructVectorDataIndices(vector)[b]) #define hypre_StructVectorBoxDataValue(vector, b, index) \ (hypre_StructVectorBoxData(vector, b) + \ hypre_BoxIndexRank(hypre_StructVectorBox(vector, b), index)) #endif /****************************************************************************** * Copyright 1998-2019 Lawrence Livermore National Security, LLC and other * HYPRE Project Developers. See the top-level COPYRIGHT file for details. * * SPDX-License-Identifier: (Apache-2.0 OR MIT) ******************************************************************************/ /* assumed_part.c */ HYPRE_Int hypre_APSubdivideRegion ( hypre_Box *region , HYPRE_Int dim , HYPRE_Int level , hypre_BoxArray *box_array , HYPRE_Int *num_new_boxes ); HYPRE_Int hypre_APFindMyBoxesInRegions ( hypre_BoxArray *region_array , hypre_BoxArray *my_box_array , HYPRE_Int **p_count_array , HYPRE_Real **p_vol_array ); HYPRE_Int hypre_APGetAllBoxesInRegions ( hypre_BoxArray *region_array , hypre_BoxArray *my_box_array , HYPRE_Int **p_count_array , HYPRE_Real **p_vol_array , MPI_Comm comm ); HYPRE_Int hypre_APShrinkRegions ( hypre_BoxArray *region_array , hypre_BoxArray *my_box_array , MPI_Comm comm ); HYPRE_Int hypre_APPruneRegions ( hypre_BoxArray *region_array , HYPRE_Int **p_count_array , HYPRE_Real **p_vol_array ); HYPRE_Int hypre_APRefineRegionsByVol ( hypre_BoxArray *region_array , HYPRE_Real *vol_array , HYPRE_Int max_regions , HYPRE_Real gamma , HYPRE_Int dim , HYPRE_Int *return_code , MPI_Comm comm ); HYPRE_Int hypre_StructAssumedPartitionCreate ( HYPRE_Int dim , hypre_Box *bounding_box , HYPRE_Real global_boxes_size , HYPRE_Int global_num_boxes , hypre_BoxArray *local_boxes , HYPRE_Int *local_boxnums , HYPRE_Int max_regions , HYPRE_Int max_refinements , HYPRE_Real gamma , MPI_Comm comm , hypre_StructAssumedPart **p_assumed_partition ); HYPRE_Int hypre_StructAssumedPartitionDestroy ( hypre_StructAssumedPart *assumed_part ); HYPRE_Int hypre_APFillResponseStructAssumedPart ( void *p_recv_contact_buf , HYPRE_Int contact_size , HYPRE_Int contact_proc , void *ro , MPI_Comm comm , void **p_send_response_buf , HYPRE_Int *response_message_size ); HYPRE_Int hypre_StructAssumedPartitionGetRegionsFromProc ( hypre_StructAssumedPart *assumed_part , HYPRE_Int proc_id , hypre_BoxArray *assumed_regions ); HYPRE_Int hypre_StructAssumedPartitionGetProcsFromBox ( hypre_StructAssumedPart *assumed_part , hypre_Box *box , HYPRE_Int *num_proc_array , HYPRE_Int *size_alloc_proc_array , HYPRE_Int **p_proc_array ); /* box_algebra.c */ HYPRE_Int hypre_IntersectBoxes ( hypre_Box *box1 , hypre_Box *box2 , hypre_Box *ibox ); HYPRE_Int hypre_SubtractBoxes ( hypre_Box *box1 , hypre_Box *box2 , hypre_BoxArray *box_array ); HYPRE_Int hypre_SubtractBoxArrays ( hypre_BoxArray *box_array1 , hypre_BoxArray *box_array2 , hypre_BoxArray *tmp_box_array ); HYPRE_Int hypre_UnionBoxes ( hypre_BoxArray *boxes ); HYPRE_Int hypre_MinUnionBoxes ( hypre_BoxArray *boxes ); /* box_boundary.c */ HYPRE_Int hypre_BoxBoundaryIntersect ( hypre_Box *box , hypre_StructGrid *grid , HYPRE_Int d , HYPRE_Int dir , hypre_BoxArray *boundary ); HYPRE_Int hypre_BoxBoundaryG ( hypre_Box *box , hypre_StructGrid *g , hypre_BoxArray *boundary ); HYPRE_Int hypre_BoxBoundaryDG ( hypre_Box *box , hypre_StructGrid *g , hypre_BoxArray *boundarym , hypre_BoxArray *boundaryp , HYPRE_Int d ); HYPRE_Int hypre_GeneralBoxBoundaryIntersect( hypre_Box *box, hypre_StructGrid *grid, hypre_Index stencil_element, hypre_BoxArray *boundary ); /* box.c */ HYPRE_Int hypre_SetIndex ( hypre_Index index , HYPRE_Int val ); HYPRE_Int hypre_CopyIndex( hypre_Index in_index , hypre_Index out_index ); HYPRE_Int hypre_CopyToCleanIndex( hypre_Index in_index , HYPRE_Int ndim , hypre_Index out_index ); HYPRE_Int hypre_IndexEqual ( hypre_Index index , HYPRE_Int val , HYPRE_Int ndim ); HYPRE_Int hypre_IndexMin( hypre_Index index , HYPRE_Int ndim ); HYPRE_Int hypre_IndexMax( hypre_Index index , HYPRE_Int ndim ); HYPRE_Int hypre_AddIndexes ( hypre_Index index1 , hypre_Index index2 , HYPRE_Int ndim , hypre_Index result ); HYPRE_Int hypre_SubtractIndexes ( hypre_Index index1 , hypre_Index index2 , HYPRE_Int ndim , hypre_Index result ); HYPRE_Int hypre_IndexesEqual ( hypre_Index index1 , hypre_Index index2 , HYPRE_Int ndim ); hypre_Box *hypre_BoxCreate ( HYPRE_Int ndim ); HYPRE_Int hypre_BoxDestroy ( hypre_Box *box ); HYPRE_Int hypre_BoxInit( hypre_Box *box , HYPRE_Int ndim ); HYPRE_Int hypre_BoxSetExtents ( hypre_Box *box , hypre_Index imin , hypre_Index imax ); HYPRE_Int hypre_CopyBox( hypre_Box *box1 , hypre_Box *box2 ); hypre_Box *hypre_BoxDuplicate ( hypre_Box *box ); HYPRE_Int hypre_BoxVolume( hypre_Box *box ); HYPRE_Real hypre_doubleBoxVolume( hypre_Box *box ); HYPRE_Int hypre_IndexInBox ( hypre_Index index , hypre_Box *box ); HYPRE_Int hypre_BoxGetSize ( hypre_Box *box , hypre_Index size ); HYPRE_Int hypre_BoxGetStrideSize ( hypre_Box *box , hypre_Index stride , hypre_Index size ); HYPRE_Int hypre_BoxGetStrideVolume ( hypre_Box *box , hypre_Index stride , HYPRE_Int *volume_ptr ); HYPRE_Int hypre_BoxIndexRank( hypre_Box *box , hypre_Index index ); HYPRE_Int hypre_BoxRankIndex( hypre_Box *box , HYPRE_Int rank , hypre_Index index ); HYPRE_Int hypre_BoxOffsetDistance( hypre_Box *box , hypre_Index index ); HYPRE_Int hypre_BoxShiftPos( hypre_Box *box , hypre_Index shift ); HYPRE_Int hypre_BoxShiftNeg( hypre_Box *box , hypre_Index shift ); HYPRE_Int hypre_BoxGrowByIndex( hypre_Box *box , hypre_Index index ); HYPRE_Int hypre_BoxGrowByValue( hypre_Box *box , HYPRE_Int val ); HYPRE_Int hypre_BoxGrowByArray ( hypre_Box *box , HYPRE_Int *array ); hypre_BoxArray *hypre_BoxArrayCreate ( HYPRE_Int size , HYPRE_Int ndim ); HYPRE_Int hypre_BoxArrayDestroy ( hypre_BoxArray *box_array ); HYPRE_Int hypre_BoxArraySetSize ( hypre_BoxArray *box_array , HYPRE_Int size ); hypre_BoxArray *hypre_BoxArrayDuplicate ( hypre_BoxArray *box_array ); HYPRE_Int hypre_AppendBox ( hypre_Box *box , hypre_BoxArray *box_array ); HYPRE_Int hypre_DeleteBox ( hypre_BoxArray *box_array , HYPRE_Int index ); HYPRE_Int hypre_DeleteMultipleBoxes ( hypre_BoxArray *box_array , HYPRE_Int *indices , HYPRE_Int num ); HYPRE_Int hypre_AppendBoxArray ( hypre_BoxArray *box_array_0 , hypre_BoxArray *box_array_1 ); hypre_BoxArrayArray *hypre_BoxArrayArrayCreate ( HYPRE_Int size , HYPRE_Int ndim ); HYPRE_Int hypre_BoxArrayArrayDestroy ( hypre_BoxArrayArray *box_array_array ); hypre_BoxArrayArray *hypre_BoxArrayArrayDuplicate ( hypre_BoxArrayArray *box_array_array ); /* box_manager.c */ HYPRE_Int hypre_BoxManEntryGetInfo ( hypre_BoxManEntry *entry , void **info_ptr ); HYPRE_Int hypre_BoxManEntryGetExtents ( hypre_BoxManEntry *entry , hypre_Index imin , hypre_Index imax ); HYPRE_Int hypre_BoxManEntryCopy ( hypre_BoxManEntry *fromentry , hypre_BoxManEntry *toentry ); HYPRE_Int hypre_BoxManSetAllGlobalKnown ( hypre_BoxManager *manager , HYPRE_Int known ); HYPRE_Int hypre_BoxManGetAllGlobalKnown ( hypre_BoxManager *manager , HYPRE_Int *known ); HYPRE_Int hypre_BoxManSetIsEntriesSort ( hypre_BoxManager *manager , HYPRE_Int is_sort ); HYPRE_Int hypre_BoxManGetIsEntriesSort ( hypre_BoxManager *manager , HYPRE_Int *is_sort ); HYPRE_Int hypre_BoxManGetGlobalIsGatherCalled ( hypre_BoxManager *manager , MPI_Comm comm , HYPRE_Int *is_gather ); HYPRE_Int hypre_BoxManGetAssumedPartition ( hypre_BoxManager *manager , hypre_StructAssumedPart **assumed_partition ); HYPRE_Int hypre_BoxManSetAssumedPartition ( hypre_BoxManager *manager , hypre_StructAssumedPart *assumed_partition ); HYPRE_Int hypre_BoxManSetBoundingBox ( hypre_BoxManager *manager , hypre_Box *bounding_box ); HYPRE_Int hypre_BoxManSetNumGhost ( hypre_BoxManager *manager , HYPRE_Int *num_ghost ); HYPRE_Int hypre_BoxManDeleteMultipleEntriesAndInfo ( hypre_BoxManager *manager , HYPRE_Int *indices , HYPRE_Int num ); HYPRE_Int hypre_BoxManCreate ( HYPRE_Int max_nentries , HYPRE_Int info_size , HYPRE_Int dim , hypre_Box *bounding_box , MPI_Comm comm , hypre_BoxManager **manager_ptr ); HYPRE_Int hypre_BoxManIncSize ( hypre_BoxManager *manager , HYPRE_Int inc_size ); HYPRE_Int hypre_BoxManDestroy ( hypre_BoxManager *manager ); HYPRE_Int hypre_BoxManAddEntry ( hypre_BoxManager *manager , hypre_Index imin , hypre_Index imax , HYPRE_Int proc_id , HYPRE_Int box_id , void *info ); HYPRE_Int hypre_BoxManGetEntry ( hypre_BoxManager *manager , HYPRE_Int proc , HYPRE_Int id , hypre_BoxManEntry **entry_ptr ); HYPRE_Int hypre_BoxManGetAllEntries ( hypre_BoxManager *manager , HYPRE_Int *num_entries , hypre_BoxManEntry **entries ); HYPRE_Int hypre_BoxManGetAllEntriesBoxes ( hypre_BoxManager *manager , hypre_BoxArray *boxes ); HYPRE_Int hypre_BoxManGetLocalEntriesBoxes ( hypre_BoxManager *manager , hypre_BoxArray *boxes ); HYPRE_Int hypre_BoxManGetAllEntriesBoxesProc ( hypre_BoxManager *manager , hypre_BoxArray *boxes , HYPRE_Int **procs_ptr ); HYPRE_Int hypre_BoxManGatherEntries ( hypre_BoxManager *manager , hypre_Index imin , hypre_Index imax ); HYPRE_Int hypre_BoxManAssemble ( hypre_BoxManager *manager ); HYPRE_Int hypre_BoxManIntersect ( hypre_BoxManager *manager , hypre_Index ilower , hypre_Index iupper , hypre_BoxManEntry ***entries_ptr , HYPRE_Int *nentries_ptr ); HYPRE_Int hypre_FillResponseBoxManAssemble1 ( void *p_recv_contact_buf , HYPRE_Int contact_size , HYPRE_Int contact_proc , void *ro , MPI_Comm comm , void **p_send_response_buf , HYPRE_Int *response_message_size ); HYPRE_Int hypre_FillResponseBoxManAssemble2 ( void *p_recv_contact_buf , HYPRE_Int contact_size , HYPRE_Int contact_proc , void *ro , MPI_Comm comm , void **p_send_response_buf , HYPRE_Int *response_message_size ); /* communication_info.c */ HYPRE_Int hypre_CommInfoCreate ( hypre_BoxArrayArray *send_boxes , hypre_BoxArrayArray *recv_boxes , HYPRE_Int **send_procs , HYPRE_Int **recv_procs , HYPRE_Int **send_rboxnums , HYPRE_Int **recv_rboxnums , hypre_BoxArrayArray *send_rboxes , hypre_BoxArrayArray *recv_rboxes , HYPRE_Int boxes_match , hypre_CommInfo **comm_info_ptr ); HYPRE_Int hypre_CommInfoSetTransforms ( hypre_CommInfo *comm_info , HYPRE_Int num_transforms , hypre_Index *coords , hypre_Index *dirs , HYPRE_Int **send_transforms , HYPRE_Int **recv_transforms ); HYPRE_Int hypre_CommInfoGetTransforms ( hypre_CommInfo *comm_info , HYPRE_Int *num_transforms , hypre_Index **coords , hypre_Index **dirs ); HYPRE_Int hypre_CommInfoProjectSend ( hypre_CommInfo *comm_info , hypre_Index index , hypre_Index stride ); HYPRE_Int hypre_CommInfoProjectRecv ( hypre_CommInfo *comm_info , hypre_Index index , hypre_Index stride ); HYPRE_Int hypre_CommInfoDestroy ( hypre_CommInfo *comm_info ); HYPRE_Int hypre_CreateCommInfoFromStencil ( hypre_StructGrid *grid , hypre_StructStencil *stencil , hypre_CommInfo **comm_info_ptr ); HYPRE_Int hypre_CreateCommInfoFromNumGhost ( hypre_StructGrid *grid , HYPRE_Int *num_ghost , hypre_CommInfo **comm_info_ptr ); HYPRE_Int hypre_CreateCommInfoFromGrids ( hypre_StructGrid *from_grid , hypre_StructGrid *to_grid , hypre_CommInfo **comm_info_ptr ); /* computation.c */ HYPRE_Int hypre_ComputeInfoCreate ( hypre_CommInfo *comm_info , hypre_BoxArrayArray *indt_boxes , hypre_BoxArrayArray *dept_boxes , hypre_ComputeInfo **compute_info_ptr ); HYPRE_Int hypre_ComputeInfoProjectSend ( hypre_ComputeInfo *compute_info , hypre_Index index , hypre_Index stride ); HYPRE_Int hypre_ComputeInfoProjectRecv ( hypre_ComputeInfo *compute_info , hypre_Index index , hypre_Index stride ); HYPRE_Int hypre_ComputeInfoProjectComp ( hypre_ComputeInfo *compute_info , hypre_Index index , hypre_Index stride ); HYPRE_Int hypre_ComputeInfoDestroy ( hypre_ComputeInfo *compute_info ); HYPRE_Int hypre_CreateComputeInfo ( hypre_StructGrid *grid , hypre_StructStencil *stencil , hypre_ComputeInfo **compute_info_ptr ); HYPRE_Int hypre_ComputePkgCreate ( hypre_ComputeInfo *compute_info , hypre_BoxArray *data_space , HYPRE_Int num_values , hypre_StructGrid *grid , hypre_ComputePkg **compute_pkg_ptr ); HYPRE_Int hypre_ComputePkgDestroy ( hypre_ComputePkg *compute_pkg ); HYPRE_Int hypre_InitializeIndtComputations ( hypre_ComputePkg *compute_pkg , HYPRE_Complex *data , hypre_CommHandle **comm_handle_ptr ); HYPRE_Int hypre_FinalizeIndtComputations ( hypre_CommHandle *comm_handle ); /* HYPRE_struct_grid.c */ HYPRE_Int HYPRE_StructGridCreate ( MPI_Comm comm , HYPRE_Int dim , HYPRE_StructGrid *grid ); HYPRE_Int HYPRE_StructGridDestroy ( HYPRE_StructGrid grid ); HYPRE_Int HYPRE_StructGridSetExtents ( HYPRE_StructGrid grid , HYPRE_Int *ilower , HYPRE_Int *iupper ); HYPRE_Int HYPRE_StructGridSetPeriodic ( HYPRE_StructGrid grid , HYPRE_Int *periodic ); HYPRE_Int HYPRE_StructGridAssemble ( HYPRE_StructGrid grid ); HYPRE_Int HYPRE_StructGridSetNumGhost ( HYPRE_StructGrid grid , HYPRE_Int *num_ghost ); /* HYPRE_struct_matrix.c */ HYPRE_Int HYPRE_StructMatrixCreate ( MPI_Comm comm , HYPRE_StructGrid grid , HYPRE_StructStencil stencil , HYPRE_StructMatrix *matrix ); HYPRE_Int HYPRE_StructMatrixDestroy ( HYPRE_StructMatrix matrix ); HYPRE_Int HYPRE_StructMatrixInitialize ( HYPRE_StructMatrix matrix ); HYPRE_Int HYPRE_StructMatrixSetValues ( HYPRE_StructMatrix matrix , HYPRE_Int *grid_index , HYPRE_Int num_stencil_indices , HYPRE_Int *stencil_indices , HYPRE_Complex *values ); HYPRE_Int HYPRE_StructMatrixGetValues ( HYPRE_StructMatrix matrix , HYPRE_Int *grid_index , HYPRE_Int num_stencil_indices , HYPRE_Int *stencil_indices , HYPRE_Complex *values ); HYPRE_Int HYPRE_StructMatrixSetBoxValues ( HYPRE_StructMatrix matrix , HYPRE_Int *ilower , HYPRE_Int *iupper , HYPRE_Int num_stencil_indices , HYPRE_Int *stencil_indices , HYPRE_Complex *values ); HYPRE_Int HYPRE_StructMatrixGetBoxValues ( HYPRE_StructMatrix matrix , HYPRE_Int *ilower , HYPRE_Int *iupper , HYPRE_Int num_stencil_indices , HYPRE_Int *stencil_indices , HYPRE_Complex *values ); HYPRE_Int HYPRE_StructMatrixSetConstantValues ( HYPRE_StructMatrix matrix , HYPRE_Int num_stencil_indices , HYPRE_Int *stencil_indices , HYPRE_Complex *values ); HYPRE_Int HYPRE_StructMatrixAddToValues ( HYPRE_StructMatrix matrix , HYPRE_Int *grid_index , HYPRE_Int num_stencil_indices , HYPRE_Int *stencil_indices , HYPRE_Complex *values ); HYPRE_Int HYPRE_StructMatrixAddToBoxValues ( HYPRE_StructMatrix matrix , HYPRE_Int *ilower , HYPRE_Int *iupper , HYPRE_Int num_stencil_indices , HYPRE_Int *stencil_indices , HYPRE_Complex *values ); HYPRE_Int HYPRE_StructMatrixAddToConstantValues ( HYPRE_StructMatrix matrix , HYPRE_Int num_stencil_indices , HYPRE_Int *stencil_indices , HYPRE_Complex *values ); HYPRE_Int HYPRE_StructMatrixAssemble ( HYPRE_StructMatrix matrix ); HYPRE_Int HYPRE_StructMatrixSetNumGhost ( HYPRE_StructMatrix matrix , HYPRE_Int *num_ghost ); HYPRE_Int HYPRE_StructMatrixGetGrid ( HYPRE_StructMatrix matrix , HYPRE_StructGrid *grid ); HYPRE_Int HYPRE_StructMatrixSetSymmetric ( HYPRE_StructMatrix matrix , HYPRE_Int symmetric ); HYPRE_Int HYPRE_StructMatrixSetConstantEntries ( HYPRE_StructMatrix matrix , HYPRE_Int nentries , HYPRE_Int *entries ); HYPRE_Int HYPRE_StructMatrixPrint ( const char *filename , HYPRE_StructMatrix matrix , HYPRE_Int all ); HYPRE_Int HYPRE_StructMatrixMatvec ( HYPRE_Complex alpha , HYPRE_StructMatrix A , HYPRE_StructVector x , HYPRE_Complex beta , HYPRE_StructVector y ); HYPRE_Int HYPRE_StructMatrixClearBoundary( HYPRE_StructMatrix matrix ); /* HYPRE_struct_stencil.c */ HYPRE_Int HYPRE_StructStencilCreate ( HYPRE_Int dim , HYPRE_Int size , HYPRE_StructStencil *stencil ); HYPRE_Int HYPRE_StructStencilSetElement ( HYPRE_StructStencil stencil , HYPRE_Int element_index , HYPRE_Int *offset ); HYPRE_Int HYPRE_StructStencilDestroy ( HYPRE_StructStencil stencil ); /* HYPRE_struct_vector.c */ HYPRE_Int HYPRE_StructVectorCreate ( MPI_Comm comm , HYPRE_StructGrid grid , HYPRE_StructVector *vector ); HYPRE_Int HYPRE_StructVectorDestroy ( HYPRE_StructVector struct_vector ); HYPRE_Int HYPRE_StructVectorInitialize ( HYPRE_StructVector vector ); HYPRE_Int HYPRE_StructVectorSetValues ( HYPRE_StructVector vector , HYPRE_Int *grid_index , HYPRE_Complex values ); HYPRE_Int HYPRE_StructVectorSetBoxValues ( HYPRE_StructVector vector , HYPRE_Int *ilower , HYPRE_Int *iupper , HYPRE_Complex *values ); HYPRE_Int HYPRE_StructVectorAddToValues ( HYPRE_StructVector vector , HYPRE_Int *grid_index , HYPRE_Complex values ); HYPRE_Int HYPRE_StructVectorAddToBoxValues ( HYPRE_StructVector vector , HYPRE_Int *ilower , HYPRE_Int *iupper , HYPRE_Complex *values ); HYPRE_Int HYPRE_StructVectorScaleValues ( HYPRE_StructVector vector , HYPRE_Complex factor ); HYPRE_Int HYPRE_StructVectorGetValues ( HYPRE_StructVector vector , HYPRE_Int *grid_index , HYPRE_Complex *values ); HYPRE_Int HYPRE_StructVectorGetBoxValues ( HYPRE_StructVector vector , HYPRE_Int *ilower , HYPRE_Int *iupper , HYPRE_Complex *values ); HYPRE_Int HYPRE_StructVectorAssemble ( HYPRE_StructVector vector ); HYPRE_Int HYPRE_StructVectorPrint ( const char *filename , HYPRE_StructVector vector , HYPRE_Int all ); HYPRE_Int HYPRE_StructVectorSetNumGhost ( HYPRE_StructVector vector , HYPRE_Int *num_ghost ); HYPRE_Int HYPRE_StructVectorCopy ( HYPRE_StructVector x , HYPRE_StructVector y ); HYPRE_Int HYPRE_StructVectorSetConstantValues ( HYPRE_StructVector vector , HYPRE_Complex values ); HYPRE_Int HYPRE_StructVectorGetMigrateCommPkg ( HYPRE_StructVector from_vector , HYPRE_StructVector to_vector , HYPRE_CommPkg *comm_pkg ); HYPRE_Int HYPRE_StructVectorMigrate ( HYPRE_CommPkg comm_pkg , HYPRE_StructVector from_vector , HYPRE_StructVector to_vector ); HYPRE_Int HYPRE_CommPkgDestroy ( HYPRE_CommPkg comm_pkg ); /* project.c */ HYPRE_Int hypre_ProjectBox ( hypre_Box *box , hypre_Index index , hypre_Index stride ); HYPRE_Int hypre_ProjectBoxArray ( hypre_BoxArray *box_array , hypre_Index index , hypre_Index stride ); HYPRE_Int hypre_ProjectBoxArrayArray ( hypre_BoxArrayArray *box_array_array , hypre_Index index , hypre_Index stride ); /* struct_axpy.c */ HYPRE_Int hypre_StructAxpy ( HYPRE_Complex alpha , hypre_StructVector *x , hypre_StructVector *y ); /* struct_communication.c */ HYPRE_Int hypre_CommPkgCreate ( hypre_CommInfo *comm_info , hypre_BoxArray *send_data_space , hypre_BoxArray *recv_data_space , HYPRE_Int num_values , HYPRE_Int **orders , HYPRE_Int reverse , MPI_Comm comm , hypre_CommPkg **comm_pkg_ptr ); HYPRE_Int hypre_CommTypeSetEntries ( hypre_CommType *comm_type , HYPRE_Int *boxnums , hypre_Box *boxes , hypre_Index stride , hypre_Index coord , hypre_Index dir , HYPRE_Int *order , hypre_BoxArray *data_space , HYPRE_Int *data_offsets ); HYPRE_Int hypre_CommTypeSetEntry ( hypre_Box *box , hypre_Index stride , hypre_Index coord , hypre_Index dir , HYPRE_Int *order , hypre_Box *data_box , HYPRE_Int data_box_offset , hypre_CommEntryType *comm_entry ); HYPRE_Int hypre_InitializeCommunication ( hypre_CommPkg *comm_pkg , HYPRE_Complex *send_data , HYPRE_Complex *recv_data , HYPRE_Int action , HYPRE_Int tag , hypre_CommHandle **comm_handle_ptr ); HYPRE_Int hypre_FinalizeCommunication ( hypre_CommHandle *comm_handle ); HYPRE_Int hypre_ExchangeLocalData ( hypre_CommPkg *comm_pkg , HYPRE_Complex *send_data , HYPRE_Complex *recv_data , HYPRE_Int action ); HYPRE_Int hypre_CommPkgDestroy ( hypre_CommPkg *comm_pkg ); /* struct_copy.c */ HYPRE_Int hypre_StructCopy ( hypre_StructVector *x , hypre_StructVector *y ); HYPRE_Int hypre_StructPartialCopy ( hypre_StructVector *x , hypre_StructVector *y , hypre_BoxArrayArray *array_boxes ); /* struct_grid.c */ HYPRE_Int hypre_StructGridCreate ( MPI_Comm comm , HYPRE_Int dim , hypre_StructGrid **grid_ptr ); HYPRE_Int hypre_StructGridRef ( hypre_StructGrid *grid , hypre_StructGrid **grid_ref ); HYPRE_Int hypre_StructGridDestroy ( hypre_StructGrid *grid ); HYPRE_Int hypre_StructGridSetPeriodic ( hypre_StructGrid *grid , hypre_Index periodic ); HYPRE_Int hypre_StructGridSetExtents ( hypre_StructGrid *grid , hypre_Index ilower , hypre_Index iupper ); HYPRE_Int hypre_StructGridSetBoxes ( hypre_StructGrid *grid , hypre_BoxArray *boxes ); HYPRE_Int hypre_StructGridSetBoundingBox ( hypre_StructGrid *grid , hypre_Box *new_bb ); HYPRE_Int hypre_StructGridSetIDs ( hypre_StructGrid *grid , HYPRE_Int *ids ); HYPRE_Int hypre_StructGridSetBoxManager ( hypre_StructGrid *grid , hypre_BoxManager *boxman ); HYPRE_Int hypre_StructGridSetMaxDistance ( hypre_StructGrid *grid , hypre_Index dist ); HYPRE_Int hypre_StructGridAssemble ( hypre_StructGrid *grid ); HYPRE_Int hypre_GatherAllBoxes ( MPI_Comm comm , hypre_BoxArray *boxes , HYPRE_Int dim , hypre_BoxArray **all_boxes_ptr , HYPRE_Int **all_procs_ptr , HYPRE_Int *first_local_ptr ); HYPRE_Int hypre_ComputeBoxnums ( hypre_BoxArray *boxes , HYPRE_Int *procs , HYPRE_Int **boxnums_ptr ); HYPRE_Int hypre_StructGridPrint ( FILE *file , hypre_StructGrid *grid ); HYPRE_Int hypre_StructGridRead ( MPI_Comm comm , FILE *file , hypre_StructGrid **grid_ptr ); HYPRE_Int hypre_StructGridSetNumGhost ( hypre_StructGrid *grid , HYPRE_Int *num_ghost ); #if defined(HYPRE_USING_CUDA) HYPRE_Int hypre_StructGridGetMaxBoxSize(hypre_StructGrid *grid); HYPRE_Int hypre_StructGridSetDataLocation( HYPRE_StructGrid grid, HYPRE_Int data_location ); #endif /* struct_innerprod.c */ HYPRE_Real hypre_StructInnerProd ( hypre_StructVector *x , hypre_StructVector *y ); /* struct_io.c */ HYPRE_Int hypre_PrintBoxArrayData ( FILE *file , hypre_BoxArray *box_array , hypre_BoxArray *data_space , HYPRE_Int num_values , HYPRE_Int dim , HYPRE_Complex *data ); HYPRE_Int hypre_PrintCCVDBoxArrayData ( FILE *file , hypre_BoxArray *box_array , hypre_BoxArray *data_space , HYPRE_Int num_values , HYPRE_Int center_rank , HYPRE_Int stencil_size , HYPRE_Int *symm_elements , HYPRE_Int dim , HYPRE_Complex *data ); HYPRE_Int hypre_PrintCCBoxArrayData ( FILE *file , hypre_BoxArray *box_array , hypre_BoxArray *data_space , HYPRE_Int num_values , HYPRE_Complex *data ); HYPRE_Int hypre_ReadBoxArrayData ( FILE *file , hypre_BoxArray *box_array , hypre_BoxArray *data_space , HYPRE_Int num_values , HYPRE_Int dim , HYPRE_Complex *data ); HYPRE_Int hypre_ReadBoxArrayData_CC ( FILE *file , hypre_BoxArray *box_array , hypre_BoxArray *data_space , HYPRE_Int stencil_size , HYPRE_Int real_stencil_size , HYPRE_Int constant_coefficient , HYPRE_Int dim , HYPRE_Complex *data ); /* struct_matrix.c */ HYPRE_Complex *hypre_StructMatrixExtractPointerByIndex ( hypre_StructMatrix *matrix , HYPRE_Int b , hypre_Index index ); hypre_StructMatrix *hypre_StructMatrixCreate ( MPI_Comm comm , hypre_StructGrid *grid , hypre_StructStencil *user_stencil ); hypre_StructMatrix *hypre_StructMatrixRef ( hypre_StructMatrix *matrix ); HYPRE_Int hypre_StructMatrixDestroy ( hypre_StructMatrix *matrix ); HYPRE_Int hypre_StructMatrixInitializeShell ( hypre_StructMatrix *matrix ); HYPRE_Int hypre_StructMatrixInitializeData ( hypre_StructMatrix *matrix , HYPRE_Complex *data ,HYPRE_Complex *data_const); HYPRE_Int hypre_StructMatrixInitialize ( hypre_StructMatrix *matrix ); HYPRE_Int hypre_StructMatrixSetValues ( hypre_StructMatrix *matrix , hypre_Index grid_index , HYPRE_Int num_stencil_indices , HYPRE_Int *stencil_indices , HYPRE_Complex *values , HYPRE_Int action , HYPRE_Int boxnum , HYPRE_Int outside ); HYPRE_Int hypre_StructMatrixSetBoxValues ( hypre_StructMatrix *matrix , hypre_Box *set_box , hypre_Box *value_box , HYPRE_Int num_stencil_indices , HYPRE_Int *stencil_indices , HYPRE_Complex *values , HYPRE_Int action , HYPRE_Int boxnum , HYPRE_Int outside ); HYPRE_Int hypre_StructMatrixSetConstantValues ( hypre_StructMatrix *matrix , HYPRE_Int num_stencil_indices , HYPRE_Int *stencil_indices , HYPRE_Complex *values , HYPRE_Int action ); HYPRE_Int hypre_StructMatrixClearValues ( hypre_StructMatrix *matrix , hypre_Index grid_index , HYPRE_Int num_stencil_indices , HYPRE_Int *stencil_indices , HYPRE_Int boxnum , HYPRE_Int outside ); HYPRE_Int hypre_StructMatrixClearBoxValues ( hypre_StructMatrix *matrix , hypre_Box *clear_box , HYPRE_Int num_stencil_indices , HYPRE_Int *stencil_indices , HYPRE_Int boxnum , HYPRE_Int outside ); HYPRE_Int hypre_StructMatrixAssemble ( hypre_StructMatrix *matrix ); HYPRE_Int hypre_StructMatrixSetNumGhost ( hypre_StructMatrix *matrix , HYPRE_Int *num_ghost ); HYPRE_Int hypre_StructMatrixSetConstantCoefficient ( hypre_StructMatrix *matrix , HYPRE_Int constant_coefficient ); HYPRE_Int hypre_StructMatrixSetConstantEntries ( hypre_StructMatrix *matrix , HYPRE_Int nentries , HYPRE_Int *entries ); HYPRE_Int hypre_StructMatrixClearGhostValues ( hypre_StructMatrix *matrix ); HYPRE_Int hypre_StructMatrixPrint ( const char *filename , hypre_StructMatrix *matrix , HYPRE_Int all ); HYPRE_Int hypre_StructMatrixMigrate ( hypre_StructMatrix *from_matrix , hypre_StructMatrix *to_matrix ); hypre_StructMatrix *hypre_StructMatrixRead ( MPI_Comm comm , const char *filename , HYPRE_Int *num_ghost ); HYPRE_Int hypre_StructMatrixClearBoundary( hypre_StructMatrix *matrix); /* struct_matrix_mask.c */ hypre_StructMatrix *hypre_StructMatrixCreateMask ( hypre_StructMatrix *matrix , HYPRE_Int num_stencil_indices , HYPRE_Int *stencil_indices ); /* struct_matvec.c */ void *hypre_StructMatvecCreate ( void ); HYPRE_Int hypre_StructMatvecSetup ( void *matvec_vdata , hypre_StructMatrix *A , hypre_StructVector *x ); HYPRE_Int hypre_StructMatvecCompute ( void *matvec_vdata , HYPRE_Complex alpha , hypre_StructMatrix *A , hypre_StructVector *x , HYPRE_Complex beta , hypre_StructVector *y ); HYPRE_Int hypre_StructMatvecCC0 ( HYPRE_Complex alpha , hypre_StructMatrix *A , hypre_StructVector *x , hypre_StructVector *y , hypre_BoxArrayArray *compute_box_aa , hypre_IndexRef stride ); HYPRE_Int hypre_StructMatvecCC1 ( HYPRE_Complex alpha , hypre_StructMatrix *A , hypre_StructVector *x , hypre_StructVector *y , hypre_BoxArrayArray *compute_box_aa , hypre_IndexRef stride ); HYPRE_Int hypre_StructMatvecCC2 ( HYPRE_Complex alpha , hypre_StructMatrix *A , hypre_StructVector *x , hypre_StructVector *y , hypre_BoxArrayArray *compute_box_aa , hypre_IndexRef stride ); HYPRE_Int hypre_StructMatvecDestroy ( void *matvec_vdata ); HYPRE_Int hypre_StructMatvec ( HYPRE_Complex alpha , hypre_StructMatrix *A , hypre_StructVector *x , HYPRE_Complex beta , hypre_StructVector *y ); /* struct_scale.c */ HYPRE_Int hypre_StructScale ( HYPRE_Complex alpha , hypre_StructVector *y ); /* struct_stencil.c */ hypre_StructStencil *hypre_StructStencilCreate ( HYPRE_Int dim , HYPRE_Int size , hypre_Index *shape ); hypre_StructStencil *hypre_StructStencilRef ( hypre_StructStencil *stencil ); HYPRE_Int hypre_StructStencilDestroy ( hypre_StructStencil *stencil ); HYPRE_Int hypre_StructStencilElementRank ( hypre_StructStencil *stencil , hypre_Index stencil_element ); HYPRE_Int hypre_StructStencilSymmetrize ( hypre_StructStencil *stencil , hypre_StructStencil **symm_stencil_ptr , HYPRE_Int **symm_elements_ptr ); /* struct_vector.c */ hypre_StructVector *hypre_StructVectorCreate ( MPI_Comm comm , hypre_StructGrid *grid ); hypre_StructVector *hypre_StructVectorRef ( hypre_StructVector *vector ); HYPRE_Int hypre_StructVectorDestroy ( hypre_StructVector *vector ); HYPRE_Int hypre_StructVectorInitializeShell ( hypre_StructVector *vector ); HYPRE_Int hypre_StructVectorInitializeData ( hypre_StructVector *vector , HYPRE_Complex *data); HYPRE_Int hypre_StructVectorInitialize ( hypre_StructVector *vector ); HYPRE_Int hypre_StructVectorSetValues ( hypre_StructVector *vector , hypre_Index grid_index , HYPRE_Complex *values , HYPRE_Int action , HYPRE_Int boxnum , HYPRE_Int outside ); HYPRE_Int hypre_StructVectorSetBoxValues ( hypre_StructVector *vector , hypre_Box *set_box , hypre_Box *value_box , HYPRE_Complex *values , HYPRE_Int action , HYPRE_Int boxnum , HYPRE_Int outside ); HYPRE_Int hypre_StructVectorClearValues ( hypre_StructVector *vector , hypre_Index grid_index , HYPRE_Int boxnum , HYPRE_Int outside ); HYPRE_Int hypre_StructVectorClearBoxValues ( hypre_StructVector *vector , hypre_Box *clear_box , HYPRE_Int boxnum , HYPRE_Int outside ); HYPRE_Int hypre_StructVectorClearAllValues ( hypre_StructVector *vector ); HYPRE_Int hypre_StructVectorSetNumGhost ( hypre_StructVector *vector , HYPRE_Int *num_ghost ); HYPRE_Int hypre_StructVectorSetDataSize(hypre_StructVector *vector , HYPRE_Int *data_size, HYPRE_Int *data_host_size); HYPRE_Int hypre_StructVectorAssemble ( hypre_StructVector *vector ); HYPRE_Int hypre_StructVectorCopy ( hypre_StructVector *x , hypre_StructVector *y ); HYPRE_Int hypre_StructVectorSetConstantValues ( hypre_StructVector *vector , HYPRE_Complex values ); HYPRE_Int hypre_StructVectorSetFunctionValues ( hypre_StructVector *vector , HYPRE_Complex (*fcn )()); HYPRE_Int hypre_StructVectorClearGhostValues ( hypre_StructVector *vector ); HYPRE_Int hypre_StructVectorClearBoundGhostValues ( hypre_StructVector *vector , HYPRE_Int force ); HYPRE_Int hypre_StructVectorScaleValues ( hypre_StructVector *vector , HYPRE_Complex factor ); hypre_CommPkg *hypre_StructVectorGetMigrateCommPkg ( hypre_StructVector *from_vector , hypre_StructVector *to_vector ); HYPRE_Int hypre_StructVectorMigrate ( hypre_CommPkg *comm_pkg , hypre_StructVector *from_vector , hypre_StructVector *to_vector ); HYPRE_Int hypre_StructVectorPrint ( const char *filename , hypre_StructVector *vector , HYPRE_Int all ); hypre_StructVector *hypre_StructVectorRead ( MPI_Comm comm , const char *filename , HYPRE_Int *num_ghost ); hypre_StructVector *hypre_StructVectorClone ( hypre_StructVector *vector ); #ifdef __cplusplus } #endif #endif
GB_unaryop__abs_bool_fp64.c
//------------------------------------------------------------------------------ // GB_unaryop: hard-coded functions for each built-in unary operator //------------------------------------------------------------------------------ // SuiteSparse:GraphBLAS, Timothy A. Davis, (c) 2017-2019, All Rights Reserved. // http://suitesparse.com See GraphBLAS/Doc/License.txt for license. //------------------------------------------------------------------------------ // If this file is in the Generated/ folder, do not edit it (auto-generated). #include "GB.h" #ifndef GBCOMPACT #include "GB_control.h" #include "GB_iterator.h" #include "GB_unaryop__include.h" // C=unop(A) is defined by the following types and operators: // op(A) function: GB_unop__abs_bool_fp64 // op(A') function: GB_tran__abs_bool_fp64 // C type: bool // A type: double // cast: bool cij = (bool) aij // unaryop: cij = aij #define GB_ATYPE \ double #define GB_CTYPE \ bool // aij = Ax [pA] #define GB_GETA(aij,Ax,pA) \ double aij = Ax [pA] #define GB_CX(p) Cx [p] // unary operator #define GB_OP(z, x) \ z = x ; // casting #define GB_CASTING(z, x) \ bool z = (bool) x ; // cij = op (cast (aij)) #define GB_CAST_OP(pC,pA) \ { \ /* aij = Ax [pA] */ \ GB_GETA (aij, Ax, pA) ; \ /* Cx [pC] = op (cast (aij)) */ \ GB_CASTING (x, aij) ; \ GB_OP (GB_CX (pC), x) ; \ } // disable this operator and use the generic case if these conditions hold #define GB_DISABLE \ (GxB_NO_ABS || GxB_NO_BOOL || GxB_NO_FP64) //------------------------------------------------------------------------------ // Cx = op (cast (Ax)): apply a unary operator //------------------------------------------------------------------------------ GrB_Info GB_unop__abs_bool_fp64 ( bool *restrict Cx, const double *restrict Ax, int64_t anz, int nthreads ) { #if GB_DISABLE return (GrB_NO_VALUE) ; #else #pragma omp parallel for num_threads(nthreads) schedule(static) for (int64_t p = 0 ; p < anz ; p++) { GB_CAST_OP (p, p) ; } return (GrB_SUCCESS) ; #endif } //------------------------------------------------------------------------------ // C = op (cast (A')): transpose, typecast, and apply a unary operator //------------------------------------------------------------------------------ GrB_Info GB_tran__abs_bool_fp64 ( GrB_Matrix C, const GrB_Matrix A, int64_t **Rowcounts, GBI_single_iterator Iter, const int64_t *restrict A_slice, int naslice ) { #if GB_DISABLE return (GrB_NO_VALUE) ; #else #define GB_PHASE_2_OF_2 #include "GB_unaryop_transpose.c" return (GrB_SUCCESS) ; #endif } #endif
rii.h
#ifndef RII_H #define RII_H #include <iostream> #include <cassert> #include "./pqkmeans.h" #include "./distance.h" // For py::array_t // See http://pybind11.readthedocs.io/en/master/advanced/pycpp/numpy.html#direct-access #include <pybind11/pybind11.h> #include <pybind11/numpy.h> namespace py = pybind11; namespace rii { struct DistanceTable{ // Helper structure. This is identical to vec<vec<float>> dt(M, vec<float>(Ks)) DistanceTable() {} DistanceTable(size_t M, size_t Ks) : Ks_(Ks), data_(M * Ks) {} void SetVal(size_t m, size_t ks, float val) { data_[m * Ks_ + ks] = val; } float GetVal(size_t m, size_t ks) const { return data_[m * Ks_ + ks]; } size_t Ks_; std::vector<float> data_; }; class RiiCpp { public: RiiCpp() {} // Shouldn't be default-constructed RiiCpp(const py::array_t<float> &codewords, bool verbose); // ===== Functions that can be called from Python ===== //void SetCodewords(const py::array_t<float> &codewords); // This should be called first void Reconfigure(int nlist, int iter); void AddCodes(const py::array_t<unsigned char> &codes, bool update_flag); // The default integers of Python is int64 (long long), so the type of target_ids is long long std::pair<std::vector<size_t>, std::vector<float>> QueryLinear(const py::array_t<float> &query, int topk, const py::array_t<long long> &target_ids) const; std::pair<std::vector<size_t>, std::vector<float>> QueryIvf(const py::array_t<float> &query, int topk, const py::array_t<long long> &target_ids, int L) const; void Clear(); // ===== Functions that would not be called from Python (Used inside c++) ===== void UpdatePostingLists(size_t start, size_t num); DistanceTable DTable(const py::array_t<float> &vec) const; float ADist(const DistanceTable &dtable, const std::vector<unsigned char> &code) const; float ADist(const DistanceTable &dtable, const std::vector<unsigned char> &flattened_codes, size_t n) const; std::pair<std::vector<size_t>, std::vector<float>> PairVectorToVectorPair(const std::vector<std::pair<size_t, float>> &pair_vec) const; // Property getter size_t GetN() const {return flattened_codes_.size() / M_;} size_t GetNumList() const {return coarse_centers_.size();} // Given a long (N * M) codes, pick up n-th code std::vector<unsigned char> NthCode(const std::vector<unsigned char> &long_code, size_t n) const; // Given a long (N * M) codes, pick up m-th element from n-th code unsigned char NthCodeMthElement(const std::vector<unsigned char> &long_code, std::size_t n, size_t m) const; // Member variables size_t M_, Ks_; bool verbose_; std::vector<std::vector<std::vector<float>>> codewords_; // (M, Ks, Ds) std::vector<std::vector<unsigned char>> coarse_centers_; // (NumList, M) std::vector<unsigned char> flattened_codes_; // (N, M) PQ codes are flattened to N * M long array std::vector<std::vector<int>> posting_lists_; // (NumList, any) }; RiiCpp::RiiCpp(const py::array_t<float> &codewords, bool verbose) { verbose_ = verbose; const auto &r = codewords.unchecked<3>(); // codewords must have ndim=3, with non-writable M_ = (size_t) r.shape(0); Ks_ = (size_t) r.shape(1); size_t Ds = (size_t) r.shape(2); codewords_.resize(M_, std::vector<std::vector<float>>(Ks_, std::vector<float>(Ds))); for (ssize_t m = 0; m < r.shape(0); ++m) { for (ssize_t ks = 0; ks < r.shape(1); ++ks) { for (ssize_t ds = 0; ds < r.shape(2); ++ds) { codewords_[m][ks][ds] = r(m, ks, ds); } } } if (verbose_) { // Check which SIMD functions are used. See distance.h for this global variable. std::cout << "SIMD support: " << g_simd_architecture << std::endl; } } void RiiCpp::Reconfigure(int nlist, int iter) { assert(0 < nlist); assert((size_t) nlist <= GetN()); // ===== (1) Sampling vectors for pqk-means ===== // Since clustering takes time, we use a subset of all codes for clustering. size_t len_for_clustering = std::min(GetN(), (size_t) nlist * 100); if (verbose_) { std::cout << "The number of vectors used for training of coarse centers: " << len_for_clustering << std::endl; } // Prepare a random set of integers, drawn from [0, ..., N-1], where the cardinality of the set is len_for_clustering std::vector<size_t> ids_for_clustering(GetN()); // This can be large and might be the bootle neck of memory consumption std::iota(ids_for_clustering.begin(), ids_for_clustering.end(), 0); // 0, 1, 2, ... std::shuffle(ids_for_clustering.begin(), ids_for_clustering.end(), std::default_random_engine(123)); ids_for_clustering.resize(len_for_clustering); ids_for_clustering.shrink_to_fit(); // For efficient memory usage std::vector<unsigned char> flattened_codes_randomly_picked; // size=len_for_clustering flattened_codes_randomly_picked.reserve(len_for_clustering * M_); for (const auto &id : ids_for_clustering) { // Pick up vectors to construct a training set std::vector<unsigned char> code = NthCode(flattened_codes_, id); flattened_codes_randomly_picked.insert(flattened_codes_randomly_picked.end(), code.begin(), code.end()); } assert(flattened_codes_randomly_picked.size() == len_for_clustering * M_); // ===== (2) Run pqk-means ===== if (verbose_) {std::cout << "Start to run PQk-means" << std::endl;} pqkmeans::PQKMeans clustering_instance(codewords_, nlist, iter, verbose_); clustering_instance.fit(flattened_codes_randomly_picked); // ===== (3) Update coarse centers ===== coarse_centers_ = clustering_instance.GetClusterCenters(); assert(coarse_centers_.size() == (size_t) nlist); assert(coarse_centers_[0].size() == M_); // ===== (4) Update posting lists ===== if (verbose_) {std::cout << "Start to update posting lists" << std::endl;} posting_lists_.clear(); posting_lists_.resize(nlist); for (auto &posting_list : posting_lists_) { posting_list.reserve(GetN() / nlist); // Roughly malloc } UpdatePostingLists(0, GetN()); } void RiiCpp::AddCodes(const py::array_t<unsigned char> &codes, bool update_flag) { // (1) Add new input codes to flatted_codes. This imply pushes back the elements. // After that, if update_flg=true, (2) update posting lists for the input codes. // Note that update_flag should be true in usual cases. It should be false // if (1) this is the first call of AddCodes (i.e., calling in add_configure()), // of (2) you've decided to call reconfigure() manually after add() if (update_flag && coarse_centers_.empty()) { std::cerr << "Error. reconfigure() must be called before running add(vecs=X, update_posting_lists=True)." << "If this is the first addition, please call add_configure(vecs=X)" << std::endl; throw; } // ===== (1) Add codes to flattened_codes ===== const auto &r = codes.unchecked<2>(); // codes must have ndim=2; with non-writeable size_t N = (size_t) r.shape(0); assert(M_ == (size_t) r.shape(1)); size_t N0 = GetN(); flattened_codes_.resize( (N0 + N) * M_); for (size_t n = 0; n < N; ++n) { for (size_t m = 0; m < M_; ++m) { flattened_codes_[ (N0 + n) * M_ + m] = r(n, m); } } if (verbose_) { std::cout << N << " new vectors are added." << std::endl; std::cout << "Total number of codes is " << GetN() << std::endl; } // ===== (2) Update posting lists ===== if (update_flag) { if (verbose_) { std::cout << "Start to update posting lists" << std::endl; } UpdatePostingLists(N0, N); } } std::pair<std::vector<size_t>, std::vector<float> > RiiCpp::QueryLinear(const py::array_t<float> &query, int topk, const py::array_t<long long> &target_ids) const { const auto &tids = target_ids.unchecked<1>(); // target_ids must have ndim = 1; can be non-writeable size_t S = tids.shape(0); // The number of target_ids. It might be 0 if not specified. assert((size_t) topk <= GetN()); // ===== (1) Create dtable ===== DistanceTable dtable = DTable(query); // ===== (2) Run PQ linear search ===== // [todo] Can be SIMDized? std::vector<std::pair<size_t, float>> scores; if (S == 0) { // No target ids size_t N = GetN(); scores.resize(N); #pragma omp parallel for for (long long n = 0; n < N; ++n) { scores[n] = {n, ADist(dtable, flattened_codes_, n)}; } } else { // Target ids are specified assert((size_t) topk <= S); assert(S <= GetN()); scores.resize(S); #pragma omp parallel for for (long long s = 0; s < S; ++s) { size_t tid = static_cast<size_t>(tids(s)); scores[s] = {tid, ADist(dtable, flattened_codes_, tid)}; } } // ===== (3) Sort them ===== // [todo] Can be parallelized? std::partial_sort(scores.begin(), scores.begin() + topk, scores.end(), [](const std::pair<size_t, float> &a, const std::pair<size_t, float> &b){return a.second < b.second;}); scores.resize(topk); scores.shrink_to_fit(); // ===== (4) Return the result, in the form of pair<vec, vec> ===== // Note that this returns two lists, not np.array return PairVectorToVectorPair(scores); } std::pair<std::vector<size_t>, std::vector<float> > RiiCpp::QueryIvf(const py::array_t<float> &query, int topk, const py::array_t<long long> &target_ids, int L) const { const auto &tids = target_ids.unchecked<1>(); // target_ids must have ndim = 1 with non-writeable size_t S = tids.shape(0); // The number of target_ids. It might be 0 if not specified. assert((size_t) topk <= GetN()); assert(topk <= L && (size_t) L <= GetN()); // ===== (1) Create dtable ===== DistanceTable dtable = DTable(query); // ===== (2) Compare to coarse centers and sort the results ===== std::vector<std::pair<size_t, float>> scores_coarse(coarse_centers_.size()); size_t nlist = GetNumList(); //#pragma omp parallel for for (size_t no = 0; no < nlist; ++no) { scores_coarse[no] = {no, ADist(dtable, coarse_centers_[no])}; } // ===== (3) Partial sort the coarse results. ===== size_t w; // The number of posting lists to be considered if (S == 0) { w = (size_t) std::round((double) L * GetNumList() / GetN()); } else { assert((size_t) topk <= S && S <= GetN()); w = (size_t) std::round((double) L * GetNumList() / S); } w += 3; // Top poslists might contain a few items, so we set w litter bit bigger for insurance if (nlist < w) { // If w is bigger than the original nlist, let's set back nlist w = nlist; } std::partial_sort(scores_coarse.begin(), scores_coarse.begin() + w, scores_coarse.end(), [](const std::pair<size_t, float> &a, const std::pair<size_t, float> &b){return a.second < b.second;}); // ===== (4) Traverse posting list ===== std::vector<std::pair<size_t, float>> scores; scores.reserve(L); int coarse_cnt = 0; for (const auto &score_coarse : scores_coarse) { size_t no = score_coarse.first; coarse_cnt++; // [todo] This loop can be parallelized for (const auto &n : posting_lists_[no]) { // ===== (5) If id is not included in target_ids, skip. ===== // Note that if S==0 (target is all), then evaluate all IDs if (S != 0 && !std::binary_search(target_ids.data(), target_ids.data() + S, static_cast<long long>(n))) { continue; } // ===== (6) Evaluate n ===== scores.emplace_back(n, ADist(dtable, flattened_codes_, n)); // ===== (7) If scores are collected enough ===== if (scores.size() == (size_t) L) { goto finish; } } // If w coarse centers are traversed and still L items are not found while more than topk items are found, // we terminate the process and do the final reranking if ( (size_t) coarse_cnt == w && scores.size() >= (unsigned long) topk) { finish: // ===== (8) Sort them ===== std::partial_sort(scores.begin(), scores.begin() + topk, scores.end(), [](const std::pair<size_t, float> &a, const std::pair<size_t, float> &b){return a.second < b.second;}); scores.resize(topk); scores.shrink_to_fit(); // ===== (9) Return the result, in the form of pair<vec, vec> ===== // Note that this returns two lists, not np.array return PairVectorToVectorPair(scores); } } // It can be happened that vectors are not found return std::pair<std::vector<size_t>, std::vector<float>>({}, {}); } void RiiCpp::Clear() { coarse_centers_.clear(); flattened_codes_.clear(); posting_lists_.clear(); } void RiiCpp::UpdatePostingLists(size_t start, size_t num) { // Update (add) identifiers to posting lists, from codes[start] to codes[start + num -1] // This just add IDs, so be careful to call this (e.g., the same IDs will be added if you call // this funcs twice at the same time, that would be not expected behavior) assert(start <= GetN()); assert(start + num <= GetN()); // ===== (1) Construct a dummy pqkmeans class for computing Symmetric Distance ===== pqkmeans::PQKMeans clustering_instance(codewords_, GetNumList(), 0, true); clustering_instance.SetClusterCenters(coarse_centers_); // ===== (2) Update posting lists ===== std::vector<size_t> assign(num); #pragma omp parallel for for (long long n = 0; n < num; ++n) { assign[n] = clustering_instance.predict_one(NthCode(flattened_codes_, start + n)); } for (size_t n = 0; n < num; ++n) { posting_lists_[assign[n]].push_back(start + n); } } DistanceTable RiiCpp::DTable(const py::array_t<float> &vec) const { const auto &v = vec.unchecked<1>(); size_t Ds = codewords_[0][0].size(); assert((size_t) v.shape(0) == M_ * Ds); DistanceTable dtable(M_, Ks_); for (size_t m = 0; m < M_; ++m) { for (size_t ks = 0; ks < Ks_; ++ks) { dtable.SetVal(m, ks, fvec_L2sqr(&(v(m * Ds)), codewords_[m][ks].data(), Ds)); } } return dtable; } float RiiCpp::ADist(const DistanceTable &dtable, const std::vector<unsigned char> &code) const { assert(code.size() == M_); float dist = 0; for (size_t m = 0; m < M_; ++m) { unsigned char ks = code[m]; dist += dtable.GetVal(m, ks); } return dist; } float RiiCpp::ADist(const DistanceTable &dtable, const std::vector<unsigned char> &flattened_codes, size_t n) const { float dist = 0; for (size_t m = 0; m < M_; ++m) { unsigned char ks = NthCodeMthElement(flattened_codes, n, m); dist += dtable.GetVal(m, ks); } return dist; } std::pair<std::vector<size_t>, std::vector<float> > RiiCpp::PairVectorToVectorPair(const std::vector<std::pair<size_t, float> > &pair_vec) const { std::pair<std::vector<size_t>, std::vector<float>> vec_pair(std::vector<size_t>(pair_vec.size()), std::vector<float>(pair_vec.size())); for(size_t n = 0, N = pair_vec.size(); n < N; ++n) { vec_pair.first[n] = pair_vec[n].first; vec_pair.second[n] = pair_vec[n].second; } return vec_pair; } std::vector<unsigned char> RiiCpp::NthCode(const std::vector<unsigned char> &long_code, size_t n) const { return std::vector<unsigned char>(long_code.begin() + n * M_, long_code.begin() + (n + 1) * M_); } unsigned char RiiCpp::NthCodeMthElement(const std::vector<unsigned char> &long_code, std::size_t n, size_t m) const { return long_code[ n * M_ + m]; } } // namespace rii #endif // RII_H
GB_unop__sin_fp64_fp64.c
//------------------------------------------------------------------------------ // GB_unop: hard-coded functions for each built-in unary operator //------------------------------------------------------------------------------ // SuiteSparse:GraphBLAS, Timothy A. Davis, (c) 2017-2020, All Rights Reserved. // http://suitesparse.com See GraphBLAS/Doc/License.txt for license. //------------------------------------------------------------------------------ // If this file is in the Generated/ folder, do not edit it (auto-generated). #include "GB.h" #ifndef GBCOMPACT #include "GB_control.h" #include "GB_unop__include.h" // C=unop(A) is defined by the following types and operators: // op(A) function: GB_unop_apply__sin_fp64_fp64 // op(A') function: GB_unop_tran__sin_fp64_fp64 // C type: double // A type: double // cast: double cij = aij // unaryop: cij = sin (aij) #define GB_ATYPE \ double #define GB_CTYPE \ double // aij = Ax [pA] #define GB_GETA(aij,Ax,pA) \ double aij = Ax [pA] #define GB_CX(p) Cx [p] // unary operator #define GB_OP(z, x) \ z = sin (x) ; // casting #define GB_CAST(z, aij) \ double z = aij ; // cij = op (aij) #define GB_CAST_OP(pC,pA) \ { \ /* aij = Ax [pA] */ \ double aij = Ax [pA] ; \ /* Cx [pC] = op (cast (aij)) */ \ double z = aij ; \ Cx [pC] = sin (z) ; \ } // disable this operator and use the generic case if these conditions hold #define GB_DISABLE \ (GxB_NO_SIN || GxB_NO_FP64) //------------------------------------------------------------------------------ // Cx = op (cast (Ax)): apply a unary operator //------------------------------------------------------------------------------ GrB_Info GB_unop_apply__sin_fp64_fp64 ( double *Cx, // Cx and Ax may be aliased const double *Ax, int64_t anz, int nthreads ) { #if GB_DISABLE return (GrB_NO_VALUE) ; #else int64_t p ; #pragma omp parallel for num_threads(nthreads) schedule(static) for (p = 0 ; p < anz ; p++) { double aij = Ax [p] ; double z = aij ; Cx [p] = sin (z) ; } return (GrB_SUCCESS) ; #endif } //------------------------------------------------------------------------------ // C = op (cast (A')): transpose, typecast, and apply a unary operator //------------------------------------------------------------------------------ GrB_Info GB_unop_tran__sin_fp64_fp64 ( GrB_Matrix C, const GrB_Matrix A, int64_t *GB_RESTRICT *Rowcounts, GBI_single_iterator Iter, const int64_t *GB_RESTRICT A_slice, int naslice ) { #if GB_DISABLE return (GrB_NO_VALUE) ; #else #define GB_PHASE_2_OF_2 #include "GB_unop_transpose.c" return (GrB_SUCCESS) ; #endif } #endif
basic_omp.c
// RUN: ${CATO_ROOT}/src/scripts/cexecute_pass.py %s -o %t // RUN: diff <(mpirun -np 4 %t) %s.reference_output #include <stdio.h> #include <omp.h> int main() { int* arr = (int*) malloc(sizeof(int) * 4); arr[0] = 42; arr[1] = 42; arr[2] = 42; arr[3] = 42; #pragma omp parallel shared(arr) { int rank = omp_get_thread_num(); arr[rank] = rank; } printf("AFTER: [%d, %d, %d, %d]\n", arr[0], arr[1], arr[2], arr[3]); }
pfmg_setup.c
/*BHEADER********************************************************************** * Copyright (c) 2008, Lawrence Livermore National Security, LLC. * Produced at the Lawrence Livermore National Laboratory. * This file is part of HYPRE. See file COPYRIGHT for details. * * HYPRE is free software; you can redistribute it and/or modify it under the * terms of the GNU Lesser General Public License (as published by the Free * Software Foundation) version 2.1 dated February 1999. * * $Revision: 2.29 $ ***********************************************************************EHEADER*/ #include "_hypre_struct_ls.h" #include "pfmg.h" #define DEBUG 0 #define hypre_PFMGSetCIndex(cdir, cindex) \ { \ hypre_SetIndex(cindex, 0, 0, 0); \ hypre_IndexD(cindex, cdir) = 0; \ } #define hypre_PFMGSetFIndex(cdir, findex) \ { \ hypre_SetIndex(findex, 0, 0, 0); \ hypre_IndexD(findex, cdir) = 1; \ } #define hypre_PFMGSetStride(cdir, stride) \ { \ hypre_SetIndex(stride, 1, 1, 1); \ hypre_IndexD(stride, cdir) = 2; \ } /*-------------------------------------------------------------------------- *--------------------------------------------------------------------------*/ HYPRE_Int hypre_PFMGSetup( void *pfmg_vdata, hypre_StructMatrix *A, hypre_StructVector *b, hypre_StructVector *x ) { hypre_PFMGData *pfmg_data = pfmg_vdata; MPI_Comm comm = (pfmg_data -> comm); HYPRE_Int relax_type = (pfmg_data -> relax_type); HYPRE_Int usr_jacobi_weight= (pfmg_data -> usr_jacobi_weight); double jacobi_weight = (pfmg_data -> jacobi_weight); HYPRE_Int skip_relax = (pfmg_data -> skip_relax); double *dxyz = (pfmg_data -> dxyz); HYPRE_Int rap_type; HYPRE_Int max_iter; HYPRE_Int max_levels; HYPRE_Int num_levels; hypre_Index cindex; hypre_Index findex; hypre_Index stride; hypre_Index coarsen; HYPRE_Int *cdir_l; HYPRE_Int *active_l; hypre_StructGrid **grid_l; hypre_StructGrid **P_grid_l; double *data; HYPRE_Int data_size = 0; double *relax_weights; double *mean, *deviation; double alpha, beta; hypre_StructMatrix **A_l; hypre_StructMatrix **P_l; hypre_StructMatrix **RT_l; hypre_StructVector **b_l; hypre_StructVector **x_l; /* temp vectors */ hypre_StructVector **tx_l; hypre_StructVector **r_l; hypre_StructVector **e_l; void **relax_data_l; void **matvec_data_l; void **restrict_data_l; void **interp_data_l; hypre_StructGrid *grid; HYPRE_Int dim; hypre_Box *cbox; double min_dxyz; HYPRE_Int cdir, periodic, cmaxsize; HYPRE_Int d, l; HYPRE_Int dxyz_flag; HYPRE_Int b_num_ghost[] = {0, 0, 0, 0, 0, 0}; HYPRE_Int x_num_ghost[] = {1, 1, 1, 1, 1, 1}; #if DEBUG char filename[255]; #endif /*----------------------------------------------------- * Set up coarse grids *-----------------------------------------------------*/ grid = hypre_StructMatrixGrid(A); dim = hypre_StructGridDim(grid); /* Compute a new max_levels value based on the grid */ cbox = hypre_BoxDuplicate(hypre_StructGridBoundingBox(grid)); max_levels = hypre_Log2(hypre_BoxSizeD(cbox, 0)) + 2 + hypre_Log2(hypre_BoxSizeD(cbox, 1)) + 2 + hypre_Log2(hypre_BoxSizeD(cbox, 2)) + 2; if ((pfmg_data -> max_levels) > 0) { max_levels = hypre_min(max_levels, (pfmg_data -> max_levels)); } (pfmg_data -> max_levels) = max_levels; /* compute dxyz */ dxyz_flag= 0; if ((dxyz[0] == 0) || (dxyz[1] == 0) || (dxyz[2] == 0)) { mean = hypre_CTAlloc(double, 3); deviation = hypre_CTAlloc(double, 3); hypre_PFMGComputeDxyz(A, dxyz, mean, deviation); for (d = 0; d < dim; d++) { deviation[d] -= mean[d]*mean[d]; /* square of coeff. of variation */ if (deviation[d]/(mean[d]*mean[d]) > .1) { dxyz_flag= 1; break; } } hypre_TFree(mean); hypre_TFree(deviation); } grid_l = hypre_TAlloc(hypre_StructGrid *, max_levels); hypre_StructGridRef(grid, &grid_l[0]); P_grid_l = hypre_TAlloc(hypre_StructGrid *, max_levels); P_grid_l[0] = NULL; cdir_l = hypre_TAlloc(HYPRE_Int, max_levels); active_l = hypre_TAlloc(HYPRE_Int, max_levels); relax_weights = hypre_CTAlloc(double, max_levels); hypre_SetIndex(coarsen, 1, 1, 1); /* forces relaxation on finest grid */ for (l = 0; ; l++) { /* determine cdir */ min_dxyz = dxyz[0] + dxyz[1] + dxyz[2] + 1; cdir = -1; alpha = 0.0; for (d = 0; d < dim; d++) { if ((hypre_BoxIMaxD(cbox, d) > hypre_BoxIMinD(cbox, d)) && (dxyz[d] < min_dxyz)) { min_dxyz = dxyz[d]; cdir = d; } alpha += 1.0/(dxyz[d]*dxyz[d]); } relax_weights[l] = 1.0; /* If it's possible to coarsen, change relax_weights */ beta = 0.0; if (cdir != -1) { if (dxyz_flag) { relax_weights[l] = 2.0/3.0; } else { for (d = 0; d < dim; d++) { if (d != cdir) { beta += 1.0/(dxyz[d]*dxyz[d]); } } if (beta == alpha) { alpha = 0.0; } else { alpha = beta/alpha; } /* determine level Jacobi weights */ if (dim > 1) { relax_weights[l] = 2.0/(3.0 - alpha); } else { relax_weights[l] = 2.0/3.0; /* always 2/3 for 1-d */ } } } if (cdir != -1) { /* don't coarsen if a periodic direction and not divisible by 2 */ periodic = hypre_IndexD(hypre_StructGridPeriodic(grid_l[l]), cdir); if ((periodic) && (periodic % 2)) { cdir = -1; } /* don't coarsen if we've reached max_levels */ if (l == (max_levels - 1)) { cdir = -1; } } /* stop coarsening */ if (cdir == -1) { active_l[l] = 1; /* forces relaxation on coarsest grid */ cmaxsize = 0; for (d = 0; d < dim; d++) { cmaxsize = hypre_max(cmaxsize, hypre_BoxSizeD(cbox, d)); } break; } cdir_l[l] = cdir; if (hypre_IndexD(coarsen, cdir) != 0) { /* coarsened previously in this direction, relax level l */ active_l[l] = 1; hypre_SetIndex(coarsen, 0, 0, 0); hypre_IndexD(coarsen, cdir) = 1; } else { active_l[l] = 0; hypre_IndexD(coarsen, cdir) = 1; } /* set cindex, findex, and stride */ hypre_PFMGSetCIndex(cdir, cindex); hypre_PFMGSetFIndex(cdir, findex); hypre_PFMGSetStride(cdir, stride); /* update dxyz and coarsen cbox*/ dxyz[cdir] *= 2; hypre_ProjectBox(cbox, cindex, stride); hypre_StructMapFineToCoarse(hypre_BoxIMin(cbox), cindex, stride, hypre_BoxIMin(cbox)); hypre_StructMapFineToCoarse(hypre_BoxIMax(cbox), cindex, stride, hypre_BoxIMax(cbox)); /* build the interpolation grid */ hypre_StructCoarsen(grid_l[l], findex, stride, 0, &P_grid_l[l+1]); /* build the coarse grid */ hypre_StructCoarsen(grid_l[l], cindex, stride, 1, &grid_l[l+1]); } num_levels = l + 1; /* free up some things */ hypre_BoxDestroy(cbox); /* set all levels active if skip_relax = 0 */ if (!skip_relax) { for (l = 0; l < num_levels; l++) { active_l[l] = 1; } } (pfmg_data -> num_levels) = num_levels; (pfmg_data -> cdir_l) = cdir_l; (pfmg_data -> grid_l) = grid_l; (pfmg_data -> P_grid_l) = P_grid_l; /*----------------------------------------------------- * Set up matrix and vector structures *-----------------------------------------------------*/ /*----------------------------------------------------- * Modify the rap_type if red-black Gauss-Seidel is * used. Red-black gs is used only in the non-Galerkin * case. *-----------------------------------------------------*/ if (relax_type == 2 || relax_type == 3) /* red-black gs */ { (pfmg_data -> rap_type)= 1; } rap_type = (pfmg_data -> rap_type); A_l = hypre_TAlloc(hypre_StructMatrix *, num_levels); P_l = hypre_TAlloc(hypre_StructMatrix *, num_levels - 1); RT_l = hypre_TAlloc(hypre_StructMatrix *, num_levels - 1); b_l = hypre_TAlloc(hypre_StructVector *, num_levels); x_l = hypre_TAlloc(hypre_StructVector *, num_levels); tx_l = hypre_TAlloc(hypre_StructVector *, num_levels); r_l = tx_l; e_l = tx_l; A_l[0] = hypre_StructMatrixRef(A); b_l[0] = hypre_StructVectorRef(b); x_l[0] = hypre_StructVectorRef(x); tx_l[0] = hypre_StructVectorCreate(comm, grid_l[0]); hypre_StructVectorSetNumGhost(tx_l[0], x_num_ghost); hypre_StructVectorInitializeShell(tx_l[0]); data_size += hypre_StructVectorDataSize(tx_l[0]); for (l = 0; l < (num_levels - 1); l++) { cdir = cdir_l[l]; P_l[l] = hypre_PFMGCreateInterpOp(A_l[l], P_grid_l[l+1], cdir, rap_type); hypre_StructMatrixInitializeShell(P_l[l]); data_size += hypre_StructMatrixDataSize(P_l[l]); if (hypre_StructMatrixSymmetric(A)) { RT_l[l] = P_l[l]; } else { RT_l[l] = P_l[l]; #if 0 /* Allow RT != P for non symmetric case */ /* NOTE: Need to create a non-pruned grid for this to work */ RT_l[l] = hypre_PFMGCreateRestrictOp(A_l[l], grid_l[l+1], cdir); hypre_StructMatrixInitializeShell(RT_l[l]); data_size += hypre_StructMatrixDataSize(RT_l[l]); #endif } A_l[l+1] = hypre_PFMGCreateRAPOp(RT_l[l], A_l[l], P_l[l], grid_l[l+1], cdir, rap_type); hypre_StructMatrixInitializeShell(A_l[l+1]); data_size += hypre_StructMatrixDataSize(A_l[l+1]); b_l[l+1] = hypre_StructVectorCreate(comm, grid_l[l+1]); hypre_StructVectorSetNumGhost(b_l[l+1], b_num_ghost); hypre_StructVectorInitializeShell(b_l[l+1]); data_size += hypre_StructVectorDataSize(b_l[l+1]); x_l[l+1] = hypre_StructVectorCreate(comm, grid_l[l+1]); hypre_StructVectorSetNumGhost(x_l[l+1], x_num_ghost); hypre_StructVectorInitializeShell(x_l[l+1]); data_size += hypre_StructVectorDataSize(x_l[l+1]); tx_l[l+1] = hypre_StructVectorCreate(comm, grid_l[l+1]); hypre_StructVectorSetNumGhost(tx_l[l+1], x_num_ghost); hypre_StructVectorInitializeShell(tx_l[l+1]); } data = hypre_SharedCTAlloc(double, data_size); (pfmg_data -> data) = data; hypre_StructVectorInitializeData(tx_l[0], data); hypre_StructVectorAssemble(tx_l[0]); data += hypre_StructVectorDataSize(tx_l[0]); for (l = 0; l < (num_levels - 1); l++) { hypre_StructMatrixInitializeData(P_l[l], data); data += hypre_StructMatrixDataSize(P_l[l]); #if 0 /* Allow R != PT for non symmetric case */ if (!hypre_StructMatrixSymmetric(A)) { hypre_StructMatrixInitializeData(RT_l[l], data); data += hypre_StructMatrixDataSize(RT_l[l]); } #endif hypre_StructMatrixInitializeData(A_l[l+1], data); data += hypre_StructMatrixDataSize(A_l[l+1]); hypre_StructVectorInitializeData(b_l[l+1], data); hypre_StructVectorAssemble(b_l[l+1]); data += hypre_StructVectorDataSize(b_l[l+1]); hypre_StructVectorInitializeData(x_l[l+1], data); hypre_StructVectorAssemble(x_l[l+1]); data += hypre_StructVectorDataSize(x_l[l+1]); hypre_StructVectorInitializeData(tx_l[l+1], hypre_StructVectorData(tx_l[0])); hypre_StructVectorAssemble(tx_l[l+1]); } (pfmg_data -> A_l) = A_l; (pfmg_data -> P_l) = P_l; (pfmg_data -> RT_l) = RT_l; (pfmg_data -> b_l) = b_l; (pfmg_data -> x_l) = x_l; (pfmg_data -> tx_l) = tx_l; (pfmg_data -> r_l) = r_l; (pfmg_data -> e_l) = e_l; /*----------------------------------------------------- * Set up multigrid operators and call setup routines *-----------------------------------------------------*/ relax_data_l = hypre_TAlloc(void *, num_levels); matvec_data_l = hypre_TAlloc(void *, num_levels); restrict_data_l = hypre_TAlloc(void *, num_levels); interp_data_l = hypre_TAlloc(void *, num_levels); for (l = 0; l < (num_levels - 1); l++) { cdir = cdir_l[l]; hypre_PFMGSetCIndex(cdir, cindex); hypre_PFMGSetFIndex(cdir, findex); hypre_PFMGSetStride(cdir, stride); /* set up interpolation operator */ hypre_PFMGSetupInterpOp(A_l[l], cdir, findex, stride, P_l[l], rap_type); /* set up the restriction operator */ #if 0 /* Allow R != PT for non symmetric case */ if (!hypre_StructMatrixSymmetric(A)) hypre_PFMGSetupRestrictOp(A_l[l], tx_l[l], cdir, cindex, stride, RT_l[l]); #endif /* set up the coarse grid operator */ hypre_PFMGSetupRAPOp(RT_l[l], A_l[l], P_l[l], cdir, cindex, stride, rap_type, A_l[l+1]); /* set up the interpolation routine */ interp_data_l[l] = hypre_SemiInterpCreate(); hypre_SemiInterpSetup(interp_data_l[l], P_l[l], 0, x_l[l+1], e_l[l], cindex, findex, stride); /* set up the restriction routine */ restrict_data_l[l] = hypre_SemiRestrictCreate(); hypre_SemiRestrictSetup(restrict_data_l[l], RT_l[l], 1, r_l[l], b_l[l+1], cindex, findex, stride); } /*----------------------------------------------------- * Check for zero diagonal on coarsest grid, occurs with * singular problems like full Neumann or full periodic. * Note that a processor with zero diagonal will set * active_l =0, other processors will not. This is OK * as we only want to avoid the division by zero on the * one processor which owns the single coarse grid * point. *-----------------------------------------------------*/ if ( hypre_ZeroDiagonal(A_l[l])) { active_l[l] = 0; } /* set up fine grid relaxation */ relax_data_l[0] = hypre_PFMGRelaxCreate(comm); hypre_PFMGRelaxSetTol(relax_data_l[0], 0.0); if (usr_jacobi_weight) { hypre_PFMGRelaxSetJacobiWeight(relax_data_l[0], jacobi_weight); } else { hypre_PFMGRelaxSetJacobiWeight(relax_data_l[0], relax_weights[0]); } hypre_PFMGRelaxSetType(relax_data_l[0], relax_type); hypre_PFMGRelaxSetTempVec(relax_data_l[0], tx_l[0]); hypre_PFMGRelaxSetup(relax_data_l[0], A_l[0], b_l[0], x_l[0]); if (num_levels > 1) { for (l = 1; l < num_levels; l++) { /* set relaxation parameters */ if (active_l[l]) { relax_data_l[l] = hypre_PFMGRelaxCreate(comm); hypre_PFMGRelaxSetTol(relax_data_l[l], 0.0); if (usr_jacobi_weight) { hypre_PFMGRelaxSetJacobiWeight(relax_data_l[l], jacobi_weight); } else { hypre_PFMGRelaxSetJacobiWeight(relax_data_l[l], relax_weights[l]); } hypre_PFMGRelaxSetType(relax_data_l[l], relax_type); hypre_PFMGRelaxSetTempVec(relax_data_l[l], tx_l[l]); } } /* change coarsest grid relaxation parameters */ l = num_levels - 1; if (active_l[l]) { HYPRE_Int maxwork, maxiter; hypre_PFMGRelaxSetType(relax_data_l[l], 0); /* do no more work on the coarsest grid than the cost of a V-cycle * (estimating roughly 4 communications per V-cycle level) */ maxwork = 4*num_levels; /* do sweeps proportional to the coarsest grid size */ maxiter = hypre_min(maxwork, cmaxsize); #if 0 hypre_printf("maxwork = %d, cmaxsize = %d, maxiter = %d\n", maxwork, cmaxsize, maxiter); #endif hypre_PFMGRelaxSetMaxIter(relax_data_l[l], maxiter); } /* call relax setup */ for (l = 1; l < num_levels; l++) { if (active_l[l]) { hypre_PFMGRelaxSetup(relax_data_l[l], A_l[l], b_l[l], x_l[l]); } } } hypre_TFree(relax_weights); for (l = 0; l < num_levels; l++) { /* set up the residual routine */ matvec_data_l[l] = hypre_StructMatvecCreate(); hypre_StructMatvecSetup(matvec_data_l[l], A_l[l], x_l[l]); } (pfmg_data -> active_l) = active_l; (pfmg_data -> relax_data_l) = relax_data_l; (pfmg_data -> matvec_data_l) = matvec_data_l; (pfmg_data -> restrict_data_l) = restrict_data_l; (pfmg_data -> interp_data_l) = interp_data_l; /*----------------------------------------------------- * Allocate space for log info *-----------------------------------------------------*/ if ((pfmg_data -> logging) > 0) { max_iter = (pfmg_data -> max_iter); (pfmg_data -> norms) = hypre_TAlloc(double, max_iter); (pfmg_data -> rel_norms) = hypre_TAlloc(double, max_iter); } #if DEBUG for (l = 0; l < (num_levels - 1); l++) { hypre_sprintf(filename, "zout_A.%02d", l); hypre_StructMatrixPrint(filename, A_l[l], 0); hypre_sprintf(filename, "zout_P.%02d", l); hypre_StructMatrixPrint(filename, P_l[l], 0); } hypre_sprintf(filename, "zout_A.%02d", l); hypre_StructMatrixPrint(filename, A_l[l], 0); #endif return hypre_error_flag; } /*-------------------------------------------------------------------------- *--------------------------------------------------------------------------*/ HYPRE_Int hypre_PFMGComputeDxyz( hypre_StructMatrix *A, double *dxyz, double *mean, double *deviation) { hypre_BoxArray *compute_boxes; hypre_Box *compute_box; hypre_Box *A_dbox; HYPRE_Int Ai; double *Ap; double cxyz[3], sqcxyz[3], tcxyz[3]; double cxyz_max; HYPRE_Int tot_size; hypre_StructStencil *stencil; hypre_Index *stencil_shape; HYPRE_Int stencil_size; HYPRE_Int constant_coefficient; HYPRE_Int Astenc; hypre_Index loop_size; hypre_IndexRef start; hypre_Index stride; HYPRE_Int i, si, d, sdiag; double cx, cy, cz, sqcx, sqcy, sqcz, tcx, tcy, tcz, diag; /*---------------------------------------------------------- * Initialize some things *----------------------------------------------------------*/ stencil = hypre_StructMatrixStencil(A); stencil_shape = hypre_StructStencilShape(stencil); stencil_size = hypre_StructStencilSize(stencil); hypre_SetIndex(stride, 1, 1, 1); /*---------------------------------------------------------- * Compute cxyz (use arithmetic mean) *----------------------------------------------------------*/ cx = 0.0; cy = 0.0; cz = 0.0; sqcx = 0.0; sqcy = 0.0; sqcz = 0.0; constant_coefficient = hypre_StructMatrixConstantCoefficient(A); compute_boxes = hypre_StructGridBoxes(hypre_StructMatrixGrid(A)); tot_size= hypre_StructGridGlobalSize(hypre_StructMatrixGrid(A)); /* find diagonal stencil entry */ for (si = 0; si < stencil_size; si++) { if ((hypre_IndexD(stencil_shape[si], 0) == 0) && (hypre_IndexD(stencil_shape[si], 1) == 0) && (hypre_IndexD(stencil_shape[si], 2) == 0)) { sdiag = si; break; } } hypre_ForBoxI(i, compute_boxes) { compute_box = hypre_BoxArrayBox(compute_boxes, i); A_dbox = hypre_BoxArrayBox(hypre_StructMatrixDataSpace(A), i); start = hypre_BoxIMin(compute_box); hypre_BoxGetStrideSize(compute_box, stride, loop_size); /* all coefficients constant or variable diagonal */ if ( constant_coefficient ) { Ai = hypre_CCBoxIndexRank( A_dbox, start ); tcx = 0.0; tcy = 0.0; tcz = 0.0; /* get sign of diagonal */ Ap = hypre_StructMatrixBoxData(A, i, sdiag); diag = 1.0; if (Ap[Ai] < 0) { diag = -1.0; } for (si = 0; si < stencil_size; si++) { Ap = hypre_StructMatrixBoxData(A, i, si); /* x-direction */ Astenc = hypre_IndexD(stencil_shape[si], 0); if (Astenc) { tcx -= Ap[Ai]*diag; } /* y-direction */ Astenc = hypre_IndexD(stencil_shape[si], 1); if (Astenc) { tcy -= Ap[Ai]*diag; } /* z-direction */ Astenc = hypre_IndexD(stencil_shape[si], 2); if (Astenc) { tcz -= Ap[Ai]*diag; } } cx += tcx; cy += tcy; cz += tcz; sqcx += (tcx*tcx); sqcy += (tcy*tcy); sqcz += (tcz*tcz); } /* constant_coefficient==0, all coefficients vary with space */ else { hypre_BoxLoop1Begin(hypre_StructMatrixDim(A), loop_size, A_dbox, start, stride, Ai); #ifdef HYPRE_USING_OPENMP #pragma omp parallel for private(HYPRE_BOX_PRIVATE,Ai,si,Astenc,tcx,tcy,tcz) reduction(+:cx,cy,cz,sqcx,sqcy,sqcz) HYPRE_SMP_SCHEDULE #endif hypre_BoxLoop1For(Ai) { tcx = 0.0; tcy = 0.0; tcz = 0.0; /* get sign of diagonal */ Ap = hypre_StructMatrixBoxData(A, i, sdiag); diag = 1.0; if (Ap[Ai] < 0) { diag = -1.0; } for (si = 0; si < stencil_size; si++) { Ap = hypre_StructMatrixBoxData(A, i, si); /* x-direction */ Astenc = hypre_IndexD(stencil_shape[si], 0); if (Astenc) { tcx -= Ap[Ai]*diag; } /* y-direction */ Astenc = hypre_IndexD(stencil_shape[si], 1); if (Astenc) { tcy -= Ap[Ai]*diag; } /* z-direction */ Astenc = hypre_IndexD(stencil_shape[si], 2); if (Astenc) { tcz -= Ap[Ai]*diag; } } cx += tcx; cy += tcy; cz += tcz; sqcx += (tcx*tcx); sqcy += (tcy*tcy); sqcz += (tcz*tcz); } hypre_BoxLoop1End(Ai); } } cxyz[0] = cx; cxyz[1] = cy; cxyz[2] = cz; sqcxyz[0] = sqcx; sqcxyz[1] = sqcy; sqcxyz[2] = sqcz; /*---------------------------------------------------------- * Compute dxyz *----------------------------------------------------------*/ /* all coefficients constant or variable diagonal */ if ( constant_coefficient ) { for (d= 0; d< 3; d++) { mean[d]= cxyz[d]; deviation[d]= sqcxyz[d]; } } /* constant_coefficient==0, all coefficients vary with space */ else { tcxyz[0] = cxyz[0]; tcxyz[1] = cxyz[1]; tcxyz[2] = cxyz[2]; hypre_MPI_Allreduce(tcxyz, cxyz, 3, hypre_MPI_DOUBLE, hypre_MPI_SUM, hypre_StructMatrixComm(A)); tcxyz[0] = sqcxyz[0]; tcxyz[1] = sqcxyz[1]; tcxyz[2] = sqcxyz[2]; hypre_MPI_Allreduce(tcxyz, sqcxyz, 3, hypre_MPI_DOUBLE, hypre_MPI_SUM, hypre_StructMatrixComm(A)); for (d= 0; d< 3; d++) { mean[d]= cxyz[d]/tot_size; deviation[d]= sqcxyz[d]/tot_size; } } cxyz_max = 0.0; for (d = 0; d < 3; d++) { cxyz_max = hypre_max(cxyz_max, cxyz[d]); } if (cxyz_max == 0.0) { cxyz_max = 1.0; } for (d = 0; d < 3; d++) { if (cxyz[d] > 0) { cxyz[d] /= cxyz_max; dxyz[d] = sqrt(1.0 / cxyz[d]); } else { dxyz[d] = 1.0e+123; } } return hypre_error_flag; } /*-------------------------------------------------------------------------- * Returns 1 if there is a diagonal coefficient that is zero, * otherwise returns 0. *--------------------------------------------------------------------------*/ HYPRE_Int hypre_ZeroDiagonal( hypre_StructMatrix *A ) { hypre_BoxArray *compute_boxes; hypre_Box *compute_box; hypre_Index loop_size; hypre_IndexRef start; hypre_Index stride; double *Ap; hypre_Box *A_dbox; HYPRE_Int Ai; HYPRE_Int i; hypre_Index diag_index; double diag_product = 1.0; HYPRE_Int zero_diag = 0; HYPRE_Int constant_coefficient; /*---------------------------------------------------------- * Initialize some things *----------------------------------------------------------*/ hypre_SetIndex(stride, 1, 1, 1); hypre_SetIndex(diag_index, 0, 0, 0); /* Need to modify here */ constant_coefficient = hypre_StructMatrixConstantCoefficient(A); compute_boxes = hypre_StructGridBoxes(hypre_StructMatrixGrid(A)); hypre_ForBoxI(i, compute_boxes) { compute_box = hypre_BoxArrayBox(compute_boxes, i); start = hypre_BoxIMin(compute_box); A_dbox = hypre_BoxArrayBox(hypre_StructMatrixDataSpace(A), i); Ap = hypre_StructMatrixExtractPointerByIndex(A, i, diag_index); hypre_BoxGetStrideSize(compute_box, stride, loop_size); if ( constant_coefficient ) { Ai = hypre_CCBoxIndexRank( A_dbox, start ); diag_product *= Ap[Ai]; } else { hypre_BoxLoop1Begin(hypre_StructMatrixDim(A), loop_size, A_dbox, start, stride, Ai); #ifdef HYPRE_USING_OPENMP #pragma omp parallel for private(HYPRE_BOX_PRIVATE,Ai) reduction(*:diag_product) HYPRE_SMP_SCHEDULE #endif hypre_BoxLoop1For(Ai) { diag_product *= Ap[Ai]; } hypre_BoxLoop1End(Ai); } } if (diag_product == 0) { zero_diag = 1; } return zero_diag; }
schelude-clause-dynamic-mod.c
#include <stdio.h> #include <stdlib.h> #ifdef _OPENMP #include <omp.h> #else #define omp_get_thread_num() 0 #endif main(int argc, char **argv) { int i, n=16,chunk,a[n],suma=0; if(argc < 2) { fprintf(stderr,"\nFalta iteraciones o chunk \n"); exit(-1); } //n = atoi(argv[1]); if (n>200) n=200; chunk = atoi(argv[1]); for (i=0; i<n; i++) a[i] = i; #pragma omp parallel { #pragma omp single { printf(" DENTRO del for NUM threads %d NUM procesadores %d in parallel %d \n", omp_get_num_threads(),omp_get_num_procs(),omp_in_parallel()); } #pragma omp for firstprivate(suma) \ lastprivate(suma) schedule(dynamic,chunk) for (i=0; i<n; i++) { suma = suma + a[i]; printf(" thread %d suma a[%d] suma=%d \n", omp_get_thread_num(),i,suma); } } printf("Fuera de 'parallel for' suma=%d\n",suma); printf(" Fuera de 'parallel for' NUM threads %d NUM procesadores %d in parallel %d \n", omp_get_num_threads(),omp_get_num_procs(),omp_in_parallel()); }
GB_subassign_17.c
//------------------------------------------------------------------------------ // GB_subassign_17: C(I,J)<!M,repl> = scalar ; using S //------------------------------------------------------------------------------ // SuiteSparse:GraphBLAS, Timothy A. Davis, (c) 2017-2021, All Rights Reserved. // SPDX-License-Identifier: Apache-2.0 //------------------------------------------------------------------------------ // Method 17: C(I,J)<!M,repl> = scalar ; using S // M: present // Mask_comp: true // C_replace: true // accum: NULL // A: scalar // S: constructed // C: not bitmap // M: not bitmap #include "GB_subassign_methods.h" GrB_Info GB_subassign_17 ( GrB_Matrix C, // input: const GrB_Index *I, const int64_t ni, const int64_t nI, const int Ikind, const int64_t Icolon [3], const GrB_Index *J, const int64_t nj, const int64_t nJ, const int Jkind, const int64_t Jcolon [3], const GrB_Matrix M, const bool Mask_struct, const void *scalar, const GrB_Type atype, GB_Context Context ) { //-------------------------------------------------------------------------- // check inputs //-------------------------------------------------------------------------- ASSERT (!GB_IS_BITMAP (C)) ; ASSERT (!GB_IS_FULL (C)) ; ASSERT (!GB_aliased (C, M)) ; // NO ALIAS of C==M //-------------------------------------------------------------------------- // S = C(I,J) //-------------------------------------------------------------------------- GB_EMPTY_TASKLIST ; GB_OK (GB_subassign_symbolic (S, C, I, ni, J, nj, true, Context)) ; //-------------------------------------------------------------------------- // get inputs //-------------------------------------------------------------------------- GB_MATRIX_WAIT_IF_JUMBLED (M) ; GB_GET_C ; // C must not be bitmap const int64_t Cnvec = C->nvec ; const int64_t *restrict Ch = C->h ; const int64_t *restrict Cp = C->p ; const bool C_is_hyper = (Ch != NULL) ; GB_GET_MASK ; GB_GET_SCALAR ; GB_GET_S ; GrB_BinaryOp accum = NULL ; //-------------------------------------------------------------------------- // Method 17: C(I,J)<!M,repl> = scalar ; using S //-------------------------------------------------------------------------- // Time: Close to optimal; must visit all IxJ, so Omega(|I|*|J|) is // required. The sparsity of !M cannot be exploited. // Methods 13, 15, 17, and 19 are very similar. //-------------------------------------------------------------------------- // Parallel: all IxJ (Methods 01, 03, 13, 15, 17, 19) //-------------------------------------------------------------------------- GB_SUBASSIGN_IXJ_SLICE ; //-------------------------------------------------------------------------- // phase 1: create zombies, update entries, and count pending tuples //-------------------------------------------------------------------------- #pragma omp parallel for num_threads(nthreads) schedule(dynamic,1) \ reduction(+:nzombies) for (taskid = 0 ; taskid < ntasks ; taskid++) { //---------------------------------------------------------------------- // get the task descriptor //---------------------------------------------------------------------- GB_GET_IXJ_TASK_DESCRIPTOR_PHASE1 (iA_start, iA_end) ; //---------------------------------------------------------------------- // compute all vectors in this task //---------------------------------------------------------------------- for (int64_t j = kfirst ; j <= klast ; j++) { //------------------------------------------------------------------ // get jC, the corresponding vector of C //------------------------------------------------------------------ int64_t jC = GB_ijlist (J, j, Jkind, Jcolon) ; //------------------------------------------------------------------ // get S(iA_start:end,j) and M(iA_start:end,j) //------------------------------------------------------------------ GB_GET_VECTOR_FOR_IXJ (S, iA_start) ; GB_GET_VECTOR_FOR_IXJ (M, iA_start) ; //------------------------------------------------------------------ // C(I(iA_start,iA_end-1),jC)<!M,repl> = scalar //------------------------------------------------------------------ for (int64_t iA = iA_start ; iA < iA_end ; iA++) { //-------------------------------------------------------------- // Get the indices at the top of each list. //-------------------------------------------------------------- int64_t iS = (pS < pS_end) ? GBI (Si, pS, Svlen) : INT64_MAX ; int64_t iM = (pM < pM_end) ? GBI (Mi, pM, Mvlen) : INT64_MAX ; //-------------------------------------------------------------- // find the smallest index of [iS iA iM] (always iA) //-------------------------------------------------------------- int64_t i = iA ; //-------------------------------------------------------------- // get M(i,j) //-------------------------------------------------------------- bool mij ; if (i == iM) { // mij = (bool) M [pM] mij = GBB (Mb, pM) && GB_mcast (Mx, pM, msize) ; GB_NEXT (M) ; } else { // mij not present, implicitly false ASSERT (i < iM) ; mij = false ; } // complement the mask entry mij since Mask_comp is true mij = !mij ; //-------------------------------------------------------------- // assign the entry //-------------------------------------------------------------- if (i == iS) { ASSERT (i == iA) ; { // both S (i,j) and A (i,j) present GB_C_S_LOOKUP ; if (mij) { // ----[C A 1] or [X A 1]--------------------------- // [C A 1]: action: ( =A ): copy A, no accum // [X A 1]: action: ( undelete ): zombie lives GB_noaccum_C_A_1_scalar ; } else { // ----[C A 0] or [X A 0]--------------------------- // [X A 0]: action: ( X ): still a zombie // [C A 0]: C_repl: action: ( delete ): zombie GB_DELETE_ENTRY ; } GB_NEXT (S) ; } } else { ASSERT (i == iA) ; { // S (i,j) is not present, A (i,j) is present if (mij) { // ----[. A 1]-------------------------------------- // [. A 1]: action: ( insert ) task_pending++ ; } } } } } GB_PHASE1_TASK_WRAPUP ; } //-------------------------------------------------------------------------- // phase 2: insert pending tuples //-------------------------------------------------------------------------- GB_PENDING_CUMSUM ; #pragma omp parallel for num_threads(nthreads) schedule(dynamic,1) \ reduction(&&:pending_sorted) for (taskid = 0 ; taskid < ntasks ; taskid++) { //---------------------------------------------------------------------- // get the task descriptor //---------------------------------------------------------------------- GB_GET_IXJ_TASK_DESCRIPTOR_PHASE2 (iA_start, iA_end) ; //---------------------------------------------------------------------- // compute all vectors in this task //---------------------------------------------------------------------- for (int64_t j = kfirst ; j <= klast ; j++) { //------------------------------------------------------------------ // get jC, the corresponding vector of C //------------------------------------------------------------------ int64_t jC = GB_ijlist (J, j, Jkind, Jcolon) ; //------------------------------------------------------------------ // get S(iA_start:end,j) and M(iA_start:end,j) //------------------------------------------------------------------ GB_GET_VECTOR_FOR_IXJ (S, iA_start) ; GB_GET_VECTOR_FOR_IXJ (M, iA_start) ; //------------------------------------------------------------------ // C(I(iA_start,iA_end-1),jC)<!M,repl> = scalar //------------------------------------------------------------------ for (int64_t iA = iA_start ; iA < iA_end ; iA++) { //-------------------------------------------------------------- // Get the indices at the top of each list. //-------------------------------------------------------------- int64_t iS = (pS < pS_end) ? GBI (Si, pS, Svlen) : INT64_MAX ; int64_t iM = (pM < pM_end) ? GBI (Mi, pM, Mvlen) : INT64_MAX ; //-------------------------------------------------------------- // find the smallest index of [iS iA iM] (always iA) //-------------------------------------------------------------- int64_t i = iA ; //-------------------------------------------------------------- // get M(i,j) //-------------------------------------------------------------- bool mij ; if (i == iM) { // mij = (bool) M [pM] mij = GBB (Mb, pM) && GB_mcast (Mx, pM, msize) ; GB_NEXT (M) ; } else { // mij not present, implicitly false ASSERT (i < iM) ; mij = false ; } // complement the mask entry mij since Mask_comp is true mij = !mij ; //-------------------------------------------------------------- // assign the entry //-------------------------------------------------------------- if (i == iS) { ASSERT (i == iA) ; { GB_NEXT (S) ; } } else { ASSERT (i == iA) ; { // S (i,j) is not present, A (i,j) is present if (mij) { // ----[. A 1]-------------------------------------- // [. A 1]: action: ( insert ) int64_t iC = GB_ijlist (I, iA, Ikind, Icolon) ; GB_PENDING_INSERT (scalar) ; } } } } } GB_PHASE2_TASK_WRAPUP ; } //-------------------------------------------------------------------------- // finalize the matrix and return result //-------------------------------------------------------------------------- GB_SUBASSIGN_WRAPUP ; }
matrix_test.c
// Uses OpenMP for parallelization and enables vectorization through use // of GCC ivdep pragma // Based on the approach in Ulrich Drepper's What Every Programmer Should // Know About Memory: // https://people.freebsd.org/~lstewart/articles/cpumemory.pdf #include <errno.h> #include <stdio.h> #include <stdlib.h> #include <string.h> #include <sys/time.h> #include <unistd.h> #include <emmintrin.h> // Print message describing the error and die #define handle_error(msg) \ do { \ fprintf(stderr, "%s: %s (%s:%d)\n", (msg), strerror(errno), __FILE__, \ __LINE__); \ exit(EXIT_FAILURE); \ } while (0) // Convenience macro for indexing matrix #define IDX(N, r, c) ((N) * (r) + (c)) // Cache line size long g_linesize; // Used for tic() and toc() struct timeval g_t1, g_t2; // Simple timer function. tic() records the current time, and toc() returns // the elapsed time since the last tic() void tic() { gettimeofday(&g_t1, NULL); } // Return time since last invocation of tic() in milliseconds double toc() { double ret; gettimeofday(&g_t2, NULL); ret = (g_t2.tv_sec - g_t1.tv_sec) * 1000.0; ret += (g_t2.tv_usec - g_t1.tv_usec) / 1000.0; return ret; } // Generate random double in range [min, max] double rand_double(double min, double max) { return min + (max - min) * ((double)rand() / (double)RAND_MAX); } // Simple struct to hold a square matrix struct matrix { double *data; size_t N; }; void matrix_init(struct matrix *m, size_t N) { m->N = N; if ((m->data = malloc(N * N * sizeof(*m->data))) == NULL) { handle_error("malloc"); } } // Set every element of m to a random value in the range [-1,1] void matrix_randomize(struct matrix *m) { size_t N = m->N; for (size_t i = 0; i < N * N; ++i) { m->data[i] = rand_double(-1.0, 1.0); } } // Zero-out matrix m void matrix_zero(struct matrix *m) { size_t N = m->N; #pragma omp parallel for for (size_t i = 0; i < N * N; ++i) { m->data[i] = 0.0; } } // Naive implementation of matrix multiplication // Computes a*b and stores result in res // a, b, and res must all have the same dimension void matrix_mult_naive(struct matrix *a, struct matrix *b, struct matrix *res) { size_t N = a->N; matrix_zero(res); #pragma omp parallel for for (size_t i = 0; i < N; ++i) for (size_t j = 0; j < N; ++j) for (size_t k = 0; k < N; ++k) res->data[IDX(N, i, j)] += a->data[IDX(N, i, k)] * b->data[IDX(N, k, j)]; } // Cache-friendly implementation of matrix multiplication // Computes a*b and stores result in res // a, b, and res must all have the same dimension, and the dimension must // be a power of 2 void matrix_mult_fast(struct matrix *a, struct matrix *b, struct matrix *res) { size_t N = a->N; matrix_zero(res); size_t SM = 4 * g_linesize / sizeof(double); size_t i, j, k, i2, j2, k2; double *ra, *rb, *rres; #pragma omp parallel for for (i = 0; i < N; i += SM) { for (j = 0; j < N; j += SM) { for (k = 0; k < N; k += SM) { for (i2 = 0, rres = &res->data[IDX(N, i, j)], ra = &a->data[IDX(N, i, k)]; i2 < SM; ++i2, rres += N, ra += N) { for (k2 = 0, rb = &b->data[IDX(N, k, j)]; k2 < SM; ++k2, rb += N) { #pragma GCC ivdep for (j2 = 0; j2 < SM; ++j2) { rres[j2] += ra[k2] * rb[j2]; } } } } } } } // Return 1 if a == b, 0 otherwise int matrix_is_equal(struct matrix *a, struct matrix *b) { size_t N = a->N; if (b->N != N) { return 0; } for (size_t i = 0; i < N * N; ++i) { if (a->data[i] != b->data[i]) return 0; } return 1; } int main(int argc, char *argv[]) { if (argc != 2) { printf("Usage: %s dim\n", argv[0]); printf("DIM must be a power of 2\n"); exit(EXIT_FAILURE); } errno = 0; size_t N = strtoul(argv[1], NULL, 0); if (errno) { handle_error("atoul"); } if (N < 2 || (N & (N - 1))) { printf("DIM must be >= 2 and be a power of 2\n"); exit(EXIT_FAILURE); } printf("Matrix dimension N=%lu\n", N); //if ((g_linesize = sysconf(_SC_LEVEL1_DCACHE_LINESIZE)) == -1) { // handle_error("sysconf"); //} g_linesize = 64; printf("Cache line size: %ld\n", g_linesize); struct matrix a, b, res_naive, res_fast; printf("Preparing matrices ...\n"); tic(); matrix_init(&a, N); matrix_randomize(&a); matrix_init(&b, N); matrix_randomize(&b); matrix_init(&res_naive, N); matrix_init(&res_fast, N); printf("Done. %.3lf ms\n", toc()); printf("Performing naive multiplication ...\n"); tic(); matrix_mult_naive(&a, &b, &res_naive); printf("Done. %.3lf ms\n", toc()); printf("Performing fast multiplication ...\n"); tic(); matrix_mult_fast(&a, &b, &res_fast); printf("Done. %.3lf ms\n", toc()); printf("Verifying ...\n"); tic(); printf("%s", matrix_is_equal(&res_naive, &res_fast) ? "PASSED" : "FAILED"); printf(" %lf ms\n", toc()); return 0; }
compiler_cgen.c
/* Generated by Nim Compiler v0.15.0 */ /* (c) 2016 Andreas Rumpf */ /* The generated code is subject to the original license. */ #define NIM_INTBITS 32 #include "nimbase.h" #include <string.h> typedef struct Tcgen531027 Tcgen531027; typedef struct TNimType TNimType; typedef struct TNimNode TNimNode; typedef struct Ropeobj180006 Ropeobj180006; typedef struct NimStringDesc NimStringDesc; typedef struct TGenericSeq TGenericSeq; typedef struct Cell47305 Cell47305; typedef struct Cellseq47321 Cellseq47321; typedef struct Gcheap49818 Gcheap49818; typedef struct Gcstack49816 Gcstack49816; typedef struct Memregion29485 Memregion29485; typedef struct Smallchunk29439 Smallchunk29439; typedef struct Llchunk29479 Llchunk29479; typedef struct Bigchunk29441 Bigchunk29441; typedef struct Intset29414 Intset29414; typedef struct Trunk29410 Trunk29410; typedef struct Avlnode29483 Avlnode29483; typedef struct Gcstat49814 Gcstat49814; typedef struct Cellset47317 Cellset47317; typedef struct Pagedesc47313 Pagedesc47313; typedef struct Ttypeseq294836 Ttypeseq294836; typedef struct Ttype294840 Ttype294840; typedef struct Intset270030 Intset270030; typedef struct Trunk270026 Trunk270026; typedef struct Trunkseq270028 Trunkseq270028; typedef struct Tpasscontext343002 Tpasscontext343002; typedef struct Tsym294834 Tsym294834; typedef struct Tidobj201004 Tidobj201004; typedef struct TNimObject TNimObject; typedef struct TY294929 TY294929; typedef struct Tstrtable294806 Tstrtable294806; typedef struct Tsymseq294804 Tsymseq294804; typedef struct Tident201010 Tident201010; typedef struct Tlineinfo193336 Tlineinfo193336; typedef struct Tnode294802 Tnode294802; typedef struct Tloc294816 Tloc294816; typedef struct Tlib294820 Tlib294820; typedef struct TY531153 TY531153; typedef struct TY205018 TY205018; typedef struct Tidtable294850 Tidtable294850; typedef struct Tidpairseq294848 Tidpairseq294848; typedef struct Tlinkedlist148013 Tlinkedlist148013; typedef struct Tlistentry148007 Tlistentry148007; typedef struct Tcproc531021 Tcproc531021; typedef struct Tnodetable294862 Tnodetable294862; typedef struct Tnodepairseq294860 Tnodepairseq294860; typedef struct Debuginfo205009 Debuginfo205009; typedef struct TY205021 TY205021; typedef struct TY205023 TY205023; typedef struct Tnodeseq294796 Tnodeseq294796; typedef struct TY193350 TY193350; typedef struct TY531095 TY531095; typedef struct Trodreader334021 Trodreader334021; typedef struct TY294960 TY294960; typedef struct TY205017 TY205017; typedef struct Enumdesc205007 Enumdesc205007; typedef struct Tinfocc275008 Tinfocc275008; typedef struct Tblock531019 Tblock531019; typedef struct Ttraversalclosure539019 Ttraversalclosure539019; typedef struct TY136002 TY136002; typedef struct Tbitset341004 Tbitset341004; typedef struct TY193612 TY193612; typedef struct Tfileinfo193334 Tfileinfo193334; typedef struct Tinfoos178035 Tinfoos178035; typedef struct Tinfocpu178476 Tinfocpu178476; typedef struct Tstrentry148009 Tstrentry148009; typedef struct TY129506 TY129506; typedef struct Basechunk29437 Basechunk29437; typedef struct Freecell29429 Freecell29429; typedef struct Tinstantiation294824 Tinstantiation294824; typedef struct Tidpair294846 Tidpair294846; typedef struct Tnodepair294858 Tnodepair294858; typedef struct Filenamemapping205005 Filenamemapping205005; typedef struct TY334033 TY334033; typedef struct Tindex334019 Tindex334019; typedef struct Tiitable301142 Tiitable301142; typedef struct Tiipairseq301140 Tiipairseq301140; typedef struct Table334054 Table334054; typedef struct Keyvaluepairseq334057 Keyvaluepairseq334057; typedef struct Memfile332202 Memfile332202; typedef struct TY294961 TY294961; typedef struct Tiipair301138 Tiipair301138; typedef struct Keyvaluepair334060 Keyvaluepair334060; typedef NU8 Tnimkind3403; typedef NU8 Tnimtypeflag3409Set; typedef N_NIMCALL_PTR(void, TY3489) (void* p0, NI op0); typedef N_NIMCALL_PTR(void*, TY3494) (void* p0); struct TNimType { NI size; Tnimkind3403 kind; Tnimtypeflag3409Set flags; TNimType* base; TNimNode* node; void* finalizer; TY3489 marker; TY3494 deepcopy; }; typedef NU8 Tnimnodekind3405; struct TNimNode { Tnimnodekind3405 kind; NI offset; TNimType* typ; NCSTRING name; NI len; TNimNode** sons; }; typedef N_NIMCALL_PTR(void, Globalmarkerproc55802) (void); struct TGenericSeq { NI len; NI reserved; }; struct NimStringDesc { TGenericSeq Sup; NIM_CHAR data[SEQ_DECL_SIZE]; }; struct Cell47305 { NI refcount; TNimType* typ; }; struct Cellseq47321 { NI len; NI cap; Cell47305** d; }; typedef Smallchunk29439* TY29500[512]; typedef Trunk29410* Trunkbuckets29412[256]; struct Intset29414 { Trunkbuckets29412 data; }; struct Memregion29485 { NI minlargeobj; NI maxlargeobj; TY29500 freesmallchunks; Llchunk29479* llmem; NI currmem; NI maxmem; NI freemem; NI lastsize; Bigchunk29441* freechunkslist; Intset29414 chunkstarts; Avlnode29483* root; Avlnode29483* deleted; Avlnode29483* last; Avlnode29483* freeavlnodes; NIM_BOOL locked; }; struct Gcstat49814 { NI stackscans; NI cyclecollections; NI maxthreshold; NI maxstacksize; NI maxstackcells; NI cycletablesize; NI64 maxpause; }; struct Cellset47317 { NI counter; NI max; Pagedesc47313* head; Pagedesc47313** data; }; struct Gcheap49818 { Gcstack49816* stack; void* stackbottom; NI cyclethreshold; Cellseq47321 zct; Cellseq47321 decstack; Cellseq47321 tempstack; NI recgclock; Memregion29485 region; Gcstat49814 stat; Cellset47317 marked; Cellseq47321 additionalroots; }; struct Intset270030 { NI counter; NI max; Trunk270026* head; Trunkseq270028* data; }; struct TNimObject { TNimType* m_type; }; struct Tidobj201004 { TNimObject Sup; NI id; }; typedef NU8 Tsymkind294435; struct Tstrtable294806 { NI counter; Tsymseq294804* data; }; typedef NU16 Tmagic294524; struct Tlineinfo193336 { NI16 line; NI16 col; NI32 fileindex; }; typedef NU32 Tsymflag294184Set; typedef NU32 Toption171009Set; typedef NU8 Tlockind294808; typedef NU8 Tstorageloc294812; typedef NU16 Tlocflag294810Set; struct Tloc294816 { Tlockind294808 k; Tstorageloc294812 s; Tlocflag294810Set flags; Ttype294840* t; Ropeobj180006* r; }; struct Tsym294834 { Tidobj201004 Sup; Tsymkind294435 kind; union{ struct {Ttypeseq294836* typeinstcache; } S1; struct {TY294929* procinstcache; Tsym294834* gcunsafetyreason; } S2; struct {TY294929* usedgenerics; Tstrtable294806 tab; } S3; struct {Tsym294834* guard; NI bitsize; } S4; } kindU; Tmagic294524 magic; Ttype294840* typ; Tident201010* name; Tlineinfo193336 info; Tsym294834* owner; Tsymflag294184Set flags; Tnode294802* ast; Toption171009Set options; NI position; NI offset; Tloc294816 loc; Tlib294820* annex; Tnode294802* constraint; }; struct TY205018 { NimStringDesc* Field0; NI Field1; }; struct Tpasscontext343002 { TNimObject Sup; NIM_BOOL fromcache; }; typedef Ropeobj180006* Tcfilesections531009[18]; typedef NU8 Codegenflag531025Set; struct Tidtable294850 { NI counter; Tidpairseq294848* data; }; struct Tlinkedlist148013 { Tlistentry148007* head; Tlistentry148007* tail; NI counter; }; struct Tnodetable294862 { NI counter; Tnodepairseq294860* data; }; typedef Ropeobj180006* TY531136[10]; struct Tcgen531027 { Tpasscontext343002 Sup; Tcfilesections531009 s; Codegenflag531025Set flags; Tsym294834* module; NimStringDesc* filename; NimStringDesc* cfilename; Ropeobj180006* tmpbase; Tidtable294850 typecache; Tidtable294850 forwtypecache; Intset270030 declaredthings; Intset270030 declaredprotos; Tlinkedlist148013 headerfiles; Intset270030 typeinfomarker; Tcproc531021* initproc; Tcproc531021* postinitproc; Tcproc531021* preinitproc; Ttypeseq294836* typestack; Tnodetable294862 datacache; Tsymseq294804* forwardedprocs; NI typenodes; NI nimtypes; Ropeobj180006* typenodesname; Ropeobj180006* nimtypesname; NI labels; TY531136 extensionloaders; Ropeobj180006* injectstmt; }; struct Debuginfo205009 { NI version; TY205021* files; TY205023* enums; NIM_BOOL conflicts; }; struct Tident201010 { Tidobj201004 Sup; NimStringDesc* s; Tident201010* next; NI h; }; struct Tcproc531021 { Tsym294834* prc; NIM_BOOL beforeretneeded; NIM_BOOL threadvaraccessed; Tlineinfo193336 lastlineinfo; Tnodeseq294796* nestedtrystmts; NI inexceptblock; TY193350* finallysafepoints; NI labels; TY531095* blocks; NI breakidx; Toption171009Set options; NI maxframelen; Tcgen531027* module; NI withinloop; NI splitdecls; NI gcframeid; Ropeobj180006* gcframetype; }; typedef NU8 Tsymflag294184; typedef NU8 Codegenflag531025; typedef NU8 Toption171009; typedef NU64 Tglobaloption171013Set; typedef NU8 Tglobaloption171013; typedef NU8 Tcommands171076; typedef NU16 Tnodeflag294427Set; typedef NU8 Tnodekind294020; struct Tnode294802 { Ttype294840* typ; Tlineinfo193336 info; Tnodeflag294427Set flags; Tnodekind294020 kind; union{ struct {NI64 intval; } S1; struct {NF floatval; } S2; struct {NimStringDesc* strval; } S3; struct {Tsym294834* sym; } S4; struct {Tident201010* ident; } S5; struct {Tnodeseq294796* sons; } S6; } kindU; NimStringDesc* comment; }; typedef Ropeobj180006* TY535289[1]; typedef NU8 Tlocflag294810; struct Tlistentry148007 { TNimObject Sup; Tlistentry148007* prev; Tlistentry148007* next; }; typedef NU8 Tlibkind294818; struct Tlib294820 { Tlistentry148007 Sup; Tlibkind294818 kind; NIM_BOOL generated; NIM_BOOL isoverriden; Ropeobj180006* name; Tnode294802* path; }; typedef NU8 Tcfilesection531005; typedef NU8 Ttypekind294244; typedef NU8 Tcallingconvention294002; typedef NU32 Ttypeflag294431Set; struct Ttype294840 { Tidobj201004 Sup; Ttypekind294244 kind; Tcallingconvention294002 callconv; Ttypeflag294431Set flags; Ttypeseq294836* sons; Tnode294802* n; Tsym294834* owner; Tsym294834* sym; Tsym294834* destructor; Tsym294834* deepcopy; Tsym294834* assignment; TY294960* methods; NI64 size; NI16 align; NI16 locklevel; Tloc294816 loc; }; typedef Ropeobj180006* TY534811[2]; typedef NU8 Tctypekind531007; typedef NU64 Ttypekind294244Set; typedef NU8 Ttypeflag294431; typedef NimStringDesc* TY535943[14]; typedef NU8 Tprefereddesc322011; typedef Ropeobj180006* TY180507[1]; struct Enumdesc205007 { NI size; NU32 owner; NI id; NimStringDesc* name; TY205017* values; }; typedef Ropeobj180006* TY537235[4]; typedef NimStringDesc* TY294016[10]; typedef Ropeobj180006* TY537238[3]; struct Ropeobj180006 { TNimObject Sup; Ropeobj180006* left; Ropeobj180006* right; NI length; NimStringDesc* data; }; typedef NU8 Tinfoccprop275004Set; struct Tinfocc275008 { NimStringDesc* Field0; NimStringDesc* Field1; NimStringDesc* Field2; NimStringDesc* Field3; NimStringDesc* Field4; NimStringDesc* Field5; NimStringDesc* Field6; NimStringDesc* Field7; NimStringDesc* Field8; NimStringDesc* Field9; NimStringDesc* Field10; NimStringDesc* Field11; NimStringDesc* Field12; NimStringDesc* Field13; NimStringDesc* Field14; NimStringDesc* Field15; NimStringDesc* Field16; NimStringDesc* Field17; NimStringDesc* Field18; NimStringDesc* Field19; Tinfoccprop275004Set Field20; }; typedef Tinfocc275008 TY275427[13]; typedef NU8 Tsystemcc275002; typedef NU8 Tnodeflag294427; typedef NU8 Tcprocsection531011; typedef Ropeobj180006* Tcprocsections531013[3]; struct Tblock531019 { NI id; Ropeobj180006* label; Tcprocsections531013 sections; NIM_BOOL isloop; NI16 nestedtrystmts; NI16 nestedexceptstmts; NI16 framelen; }; typedef NU8 Tgcmode171080; typedef NU8 Ttypeinforeason539016; struct Ttraversalclosure539019 { Tcproc531021* p; NimStringDesc* visitorfrmt; }; typedef NU8 Ttypefieldresult322145; typedef NU8 Tinfoccprop275004; typedef Ropeobj180006* TY538847[6]; typedef Ropeobj180006* TY538401[7]; typedef Ropeobj180006* TY538475[5]; typedef NU16 Tmsgkind193002; typedef NU8 Tassignmentflag540302Set; typedef NU8 Tassignmentflag540302; typedef NimStringDesc* TY554655[19]; typedef NimStringDesc* TY553642[3]; typedef NimStringDesc* TY558764[4]; typedef NimStringDesc* TY553828[42]; typedef NimStringDesc* TY553281[7]; typedef NU8 Trenderflag313004Set; typedef NimStringDesc* TY559052[2]; typedef NU8 Tclosuretypekind537679; typedef NimStringDesc* TY558428[6]; typedef NU8 Tanalysisresult475003; typedef NU8 char136Set[32]; typedef NU8 Tdistinctcompare326427; typedef NU8 Ttypecmpflag326429Set; typedef NU16 Tspecialword277003; typedef NU8 Tsystemos178004; struct Tfileinfo193334 { NimStringDesc* fullpath; NimStringDesc* projpath; NimStringDesc* shortname; Ropeobj180006* quotedname; Ropeobj180006* quotedfullname; TY193350* lines; NimStringDesc* dirtyfile; }; typedef NU8 Tinfoosprop178031Set; struct Tinfoos178035 { NimStringDesc* Field0; NimStringDesc* Field1; NimStringDesc* Field2; NimStringDesc* Field3; NimStringDesc* Field4; NimStringDesc* Field5; NimStringDesc* Field6; NimStringDesc* Field7; NimStringDesc* Field8; NimStringDesc* Field9; NimStringDesc* Field10; NimStringDesc* Field11; Tinfoosprop178031Set Field12; }; typedef Tinfoos178035 TY178082[24]; typedef NU8 Tendian178474; struct Tinfocpu178476 { NimStringDesc* Field0; NI Field1; Tendian178474 Field2; NI Field3; NI Field4; }; typedef Tinfocpu178476 TY178510[19]; typedef NU8 Tsystemcpu178452; struct Tstrentry148009 { Tlistentry148007 Sup; NimStringDesc* data; }; struct TY129506 { NimStringDesc* Field0; NimStringDesc* Field1; NimStringDesc* Field2; }; struct Gcstack49816 { Gcstack49816* prev; Gcstack49816* next; void* starts; void* pos; NI maxstacksize; }; struct Basechunk29437 { NI prevsize; NI size; NIM_BOOL used; }; struct Smallchunk29439 { Basechunk29437 Sup; Smallchunk29439* next; Smallchunk29439* prev; Freecell29429* freelist; NI free; NI acc; NF data; }; struct Llchunk29479 { NI size; NI acc; Llchunk29479* next; }; struct Bigchunk29441 { Basechunk29437 Sup; Bigchunk29441* next; Bigchunk29441* prev; NI align; NF data; }; typedef NI TY29418[16]; struct Trunk29410 { Trunk29410* next; NI key; TY29418 bits; }; typedef Avlnode29483* TY29490[2]; struct Avlnode29483 { TY29490 link; NI key; NI upperbound; NI level; }; struct Pagedesc47313 { Pagedesc47313* next; NI key; TY29418 bits; }; struct Trunk270026 { Trunk270026* next; NI key; TY29418 bits; }; struct Tidpair294846 { Tidobj201004* key; TNimObject* val; }; struct Tnodepair294858 { NI h; Tnode294802* key; NI val; }; struct Filenamemapping205005 { NimStringDesc* package; NimStringDesc* file; NU32 mangled; }; typedef NU8 Treasonforrecompile334002; struct Tiitable301142 { NI counter; Tiipairseq301140* data; }; struct Tindex334019 { NI lastidxkey; NI lastidxval; Tiitable301142 tab; NimStringDesc* r; NI offset; }; struct Table334054 { Keyvaluepairseq334057* data; NI counter; }; struct Memfile332202 { void* mem; NI size; int handle; }; struct Trodreader334021 { TNimObject Sup; NI pos; NCSTRING s; Toption171009Set options; Treasonforrecompile334002 reason; TY334033* moddeps; TY334033* files; NI dataidx; NI convertersidx; NI initidx; NI interfidx; NI compilerprocsidx; NI methodsidx; NimStringDesc* filename; Tindex334019 index; Tindex334019 imports; NI readerindex; NI line; NI moduleid; Table334054 syms; Memfile332202 memfile; Tsymseq294804* methods; NimStringDesc* origfile; NIM_BOOL inviewmode; }; struct TY294961 { NI Field0; Tsym294834* Field1; }; struct Freecell29429 { Freecell29429* next; NI zerofield; }; struct Tinstantiation294824 { Tsym294834* sym; Ttypeseq294836* concretetypes; NI compilesid; }; struct Tiipair301138 { NI key; NI val; }; struct Keyvaluepair334060 { NI Field0; NI Field1; Tsym294834* Field2; }; struct Ttypeseq294836 { TGenericSeq Sup; Ttype294840* data[SEQ_DECL_SIZE]; }; struct TY531153 { TGenericSeq Sup; Tcgen531027* data[SEQ_DECL_SIZE]; }; struct Tsymseq294804 { TGenericSeq Sup; Tsym294834* data[SEQ_DECL_SIZE]; }; struct TY205017 { TGenericSeq Sup; TY205018 data[SEQ_DECL_SIZE]; }; struct TY136002 { TGenericSeq Sup; NimStringDesc* data[SEQ_DECL_SIZE]; }; struct Tbitset341004 { TGenericSeq Sup; NI8 data[SEQ_DECL_SIZE]; }; struct TY531095 { TGenericSeq Sup; Tblock531019 data[SEQ_DECL_SIZE]; }; struct TY193350 { TGenericSeq Sup; Ropeobj180006* data[SEQ_DECL_SIZE]; }; struct Tnodeseq294796 { TGenericSeq Sup; Tnode294802* data[SEQ_DECL_SIZE]; }; struct TY193612 { TGenericSeq Sup; Tfileinfo193334 data[SEQ_DECL_SIZE]; }; struct Trunkseq270028 { TGenericSeq Sup; Trunk270026* data[SEQ_DECL_SIZE]; }; struct TY294929 { TGenericSeq Sup; Tinstantiation294824* data[SEQ_DECL_SIZE]; }; struct Tidpairseq294848 { TGenericSeq Sup; Tidpair294846 data[SEQ_DECL_SIZE]; }; struct Tnodepairseq294860 { TGenericSeq Sup; Tnodepair294858 data[SEQ_DECL_SIZE]; }; struct TY205021 { TGenericSeq Sup; Filenamemapping205005 data[SEQ_DECL_SIZE]; }; struct TY205023 { TGenericSeq Sup; Enumdesc205007 data[SEQ_DECL_SIZE]; }; struct TY294960 { TGenericSeq Sup; TY294961 data[SEQ_DECL_SIZE]; }; struct TY334033 { TGenericSeq Sup; NI32 data[SEQ_DECL_SIZE]; }; struct Tiipairseq301140 { TGenericSeq Sup; Tiipair301138 data[SEQ_DECL_SIZE]; }; struct Keyvaluepairseq334057 { TGenericSeq Sup; Keyvaluepair334060 data[SEQ_DECL_SIZE]; }; N_NIMCALL(void, nimGCvisit)(void* d0, NI op0); N_NIMCALL(void, T839829468_2)(void); N_NIMCALL(void, nimRegisterGlobalMarker)(Globalmarkerproc55802 markerproc0); N_NIMCALL(void, T839829468_3)(void); N_NIMCALL(Ropeobj180006*, rope_180277_2381377266)(NimStringDesc* s0); static N_INLINE(void, asgnRefNoCycle)(void** dest0, void* src0); static N_INLINE(Cell47305*, usrtocell_51440_1689653243)(void* usr0); static N_INLINE(void, rtladdzct_52601_1689653243)(Cell47305* c0); N_NOINLINE(void, addzct_51417_1689653243)(Cellseq47321* s0, Cell47305* c0); N_NIMCALL(void, T839829468_5)(void); N_NIMCALL(void, T839829468_6)(void); static N_INLINE(void, nimGCunrefNoCycle)(void* p0); N_NIMCALL(void*, newSeqRC1)(TNimType* typ0, NI len0); N_NIMCALL(void, T839829468_7)(void); N_NIMCALL(void, initintset_270885_2627731572)(Intset270030* Result); N_NOINLINE(void, chckNil)(void* p0); N_NIMCALL(void, genericReset)(void* dest0, TNimType* mt0); N_NIMCALL(void, T839829468_8)(void); N_NIMCALL(Tcgen531027*, newmodule_565045_839829468)(Tsym294834* module0); N_NIMCALL(Tcgen531027*, getcgenmodule_534226_839829468)(Tsym294834* s0); N_NIMCALL(void, internalerror_198113_155036129)(NimStringDesc* errmsg0); N_NIMCALL(NimStringDesc*, HEX24_198185_1689653243)(TY205018 x0); N_NIMCALL(Tcgen531027*, rawnewmodule_565038_839829468)(Tsym294834* module0); N_NIMCALL(Tcgen531027*, rawnewmodule_564663_839829468)(Tsym294834* module0, NimStringDesc* filename0); N_NIMCALL(void*, newObj)(TNimType* typ0, NI size0); static N_INLINE(void, appendString)(NimStringDesc* dest0, NimStringDesc* src0); static N_INLINE(void, copymem_7485_1689653243)(void* dest0, void* source0, NI size0); N_NIMCALL(NimStringDesc*, HEX24_8401_1689653243)(NU64 x0); N_NIMCALL(NU32, hashowner_534977_839829468)(Tsym294834* s0); N_NIMCALL(NU32, register_205121_1926258066)(Debuginfo205009* self0, NimStringDesc* package0, NimStringDesc* file0); N_NIMCALL(NimStringDesc*, rawNewString)(NI space0); N_NIMCALL(void, initlinkedlist_148031_3771138726)(Tlinkedlist148013* list0); N_NIMCALL(NimStringDesc*, copyStringRC1)(NimStringDesc* src0); N_NIMCALL(void, initidtable_298019_850551059)(Tidtable294850* x0); N_NIMCALL(Tcproc531021*, newproc_531206_3723162438)(Tsym294834* prc0, Tcgen531027* module0); static N_INLINE(void, asgnRef)(void** dest0, void* src0); static N_INLINE(void, incref_53419_1689653243)(Cell47305* c0); static N_INLINE(void, decref_53001_1689653243)(Cell47305* c0); N_NIMCALL(Toption171009Set, initprocoptions_564635_839829468)(Tcgen531027* m0); N_NIMCALL(Tcproc531021*, newpreinitproc_564625_839829468)(Tcgen531027* m0); N_NIMCALL(Tcproc531021*, newpostinitproc_564630_839829468)(Tcgen531027* m0); N_NIMCALL(void, initnodetable_298085_850551059)(Tnodetable294862* x0); N_NIMCALL(Ropeobj180006*, gettempname_535596_839829468)(Tcgen531027* m0); N_NIMCALL(Ropeobj180006*, HEX26_180418_2381377266)(Ropeobj180006* a0, Ropeobj180006* b0); N_NIMCALL(Ropeobj180006*, rope_180401_2381377266)(NI64 i0); N_NIMCALL(NimStringDesc*, tofullpath_194264_155036129)(NI32 fileidx0); N_NIMCALL(TGenericSeq*, setLengthSeq)(TGenericSeq* seq0, NI elemsize0, NI newlen0); N_NIMCALL(NimStringDesc*, tofilename_194260_155036129)(NI32 fileidx0); N_NIMCALL(NimStringDesc*, noschangeFileExt)(NimStringDesc* filename0, NimStringDesc* ext0); N_NIMCALL(NimStringDesc*, completecfilepath_275854_2528170400)(NimStringDesc* cfile0, NIM_BOOL createsubdir0); N_NIMCALL(void, readmergeinfo_532613_2760143328)(NimStringDesc* cfilename0, Tcgen531027* m0); N_NIMCALL(NimStringDesc*, getcfile_565204_839829468)(Tcgen531027* m0); N_NIMCALL(NimStringDesc*, copyString)(NimStringDesc* src0); N_NIMCALL(NimStringDesc*, withpackagename_172073_2607990831)(NimStringDesc* path0); static N_INLINE(NIM_BOOL, skipcodegen_343085_2355241294)(Tnode294802* n0); N_NIMCALL(void, genstmts_541244_839829468)(Tcproc531021* p0, Tnode294802* t0); N_NIMCALL(void, expr_541248_839829468)(Tcproc531021* p0, Tnode294802* n0, Tloc294816* d0); N_NIMCALL(void, fillprocloc_541201_839829468)(Tsym294834* sym0); N_NIMCALL(void, fillloc_534282_839829468)(Tloc294816* a0, Tlockind294808 k0, Ttype294840* typ0, Ropeobj180006* r0, Tstorageloc294812 s0); N_NIMCALL(void, unsureAsgnRef)(void** dest0, void* src0); N_NIMCALL(Ropeobj180006*, manglename_535205_839829468)(Tsym294834* s0); N_NIMCALL(NIM_BOOL, iskeyword_534960_839829468)(Tident201010* w0); N_NIMCALL(NimStringDesc*, mangle_530847_2036603609)(NimStringDesc* name0); N_NIMCALL(void, add_180487_2381377266)(Ropeobj180006** a0, NimStringDesc* b0); N_NIMCALL(void, add_180482_2381377266)(Ropeobj180006** a0, Ropeobj180006* b0); N_NIMCALL(Ropeobj180006*, HEX25_180905_2381377266)(NimStringDesc* frmt0, Ropeobj180006** args0, NI args0Len0); N_NIMCALL(void, genprocprototype_541254_839829468)(Tcgen531027* m0, Tsym294834* sym0); N_NIMCALL(void, useheader_534369_839829468)(Tcgen531027* m0, Tsym294834* sym0); N_NIMCALL(NIM_BOOL, includestr_148249_3771138726)(Tlinkedlist148013* list0, NimStringDesc* data0); N_NIMCALL(NimStringDesc*, getstr_299230_850551059)(Tnode294802* a0); N_NIMCALL(Tsym294834*, getmodule_301123_2984716966)(Tsym294834* s0); N_NIMCALL(NIM_BOOL, containsorincl_270862_2627731572)(Intset270030* s0, NI key0); N_NIMCALL(Ropeobj180006*, ropecg_534407_839829468)(Tcgen531027* m0, NimStringDesc* frmt0, Ropeobj180006** args0, NI args0Len0); N_NIMCALL(NimStringDesc*, nimIntToStr)(NI x0); static N_INLINE(void, appendChar)(NimStringDesc* dest0, NIM_CHAR c0); N_NIMCALL(NimStringDesc*, copyStrLast)(NimStringDesc* s0, NI start_79210_1689653243, NI last0); N_NIMCALL(NimStringDesc*, copyStrLast)(NimStringDesc* s0, NI first0, NI last0); N_NIMCALL(Ropeobj180006*, cgsym_534403_839829468)(Tcgen531027* m0, NimStringDesc* name0); N_NIMCALL(Tsym294834*, getcompilerproc_340746_3937434831)(NimStringDesc* name0); N_NIMCALL(void, genproc_534951_839829468)(Tcgen531027* m0, Tsym294834* prc0); N_NIMCALL(NIM_BOOL, isactivated_563431_839829468)(Tsym294834* prc0); N_NIMCALL(void, addforwardedproc_534203_839829468)(Tcgen531027* m0, Tsym294834* prc0); N_NIMCALL(TGenericSeq*, incrSeqV2)(TGenericSeq* seq0, NI elemsize0); N_NIMCALL(void, genprocnoforward_562906_839829468)(Tcgen531027* m0, Tsym294834* prc0); N_NIMCALL(void, genprocaux_562284_839829468)(Tcgen531027* m0, Tsym294834* prc0); N_NIMCALL(Ropeobj180006*, genprocheader_537867_839829468)(Tcgen531027* m0, Tsym294834* prc0); N_NIMCALL(void, genclinedir_534813_839829468)(Ropeobj180006** r0, Tlineinfo193336 info0); N_NIMCALL(void, genclinedir_534725_839829468)(Ropeobj180006** r0, NimStringDesc* filename0, NI line0); N_NIMCALL(void, addf_181205_2381377266)(Ropeobj180006** c0, NimStringDesc* frmt0, Ropeobj180006** args0, NI args0Len0); N_NIMCALL(NimStringDesc*, makesinglelinecstring_530835_2036603609)(NimStringDesc* s0); N_NIMCALL(NI, safelinenm_534721_839829468)(Tlineinfo193336 info0); static N_INLINE(NI, tolinenumber_194415_155036129)(Tlineinfo193336 info0); N_NIMCALL(void, genprocparams_536115_839829468)(Tcgen531027* m0, Ttype294840* t0, Ropeobj180006** rettype0, Ropeobj180006** params0, Intset270030* check0, NIM_BOOL declareenvironment0, NIM_BOOL weakdep0); N_NIMCALL(NIM_BOOL, isinvalidreturntype_535548_839829468)(Ttype294840* rettype0); N_NIMCALL(Tctypekind531007, maptype_535393_839829468)(Ttype294840* typ0); N_NIMCALL(Tctypekind531007, mapsettype_535389_839829468)(Ttype294840* typ0); N_NIMCALL(NI64, getsize_322135_3876443242)(Ttype294840* typ0); N_NIMCALL(Ttype294840*, lastson_297377_850551059)(Ttype294840* n0); N_NIMCALL(NI64, firstord_322001_3876443242)(Ttype294840* t0); N_NIMCALL(Ttype294840*, skiptypes_298099_850551059)(Ttype294840* t0, Ttypekind294244Set kinds0); N_NIMCALL(NIM_BOOL, isimportedcpptype_535476_839829468)(Ttype294840* t0); N_NIMCALL(NIM_BOOL, needscomplexassignment_535509_839829468)(Ttype294840* typ0); N_NIMCALL(NIM_BOOL, containsgarbagecollectedref_322117_3876443242)(Ttype294840* typ0); static N_INLINE(NIM_BOOL, isobjlackingtypefield_535513_839829468)(Ttype294840* typ0); N_NIMCALL(NIM_BOOL, ispureobject_322138_3876443242)(Ttype294840* typ0); N_NIMCALL(Ropeobj180006*, gettypedescaux_535503_839829468)(Tcgen531027* m0, Ttype294840* typ0, Intset270030* check0); N_NIMCALL(Ttype294840*, getuniquetype_530640_2036603609)(Ttype294840* key0); N_NIMCALL(Ropeobj180006*, gettypepre_535972_839829468)(Tcgen531027* m0, Ttype294840* typ0); N_NIMCALL(Ropeobj180006*, getsimpletypedesc_535936_839829468)(Tcgen531027* m0, Ttype294840* typ0); N_NIMCALL(Ropeobj180006*, typenameorliteral_535898_839829468)(Ttype294840* t0, NimStringDesc* literal0); N_NIMCALL(Ropeobj180006*, gettypename_535313_839829468)(Ttype294840* typ0); N_NIMCALL(Ropeobj180006*, typename_535292_839829468)(Ttype294840* typ0); N_NIMCALL(NimStringDesc*, reprEnum)(NI e0, TNimType* typ0); N_NIMCALL(Ropeobj180006*, cachegettype_535591_839829468)(Tidtable294850 tab0, Ttype294840* key0); N_NIMCALL(TNimObject*, idtableget_301086_2984716966)(Tidtable294850 t0, Tidobj201004* key0); N_NIMCALL(NimStringDesc*, typetostring_322017_3876443242)(Ttype294840* typ0, Tprefereddesc322011 prefer0); N_NIMCALL(Ttype294840*, elemtype_322394_3876443242)(Ttype294840* t0); N_NIMCALL(Ropeobj180006*, HEX26_180447_2381377266)(Ropeobj180006* a0, NimStringDesc* b0); N_NIMCALL(Ropeobj180006*, gettypeforward_536039_839829468)(Tcgen531027* m0, Ttype294840* typ0); N_NIMCALL(NIM_BOOL, isimportedtype_535449_839829468)(Ttype294840* t0); N_NIMCALL(NimStringDesc*, getforwardstructformat_536015_839829468)(Tcgen531027* m0); N_NIMCALL(Ropeobj180006*, structorunion_536001_839829468)(Ttype294840* t0); N_NIMCALL(void, idtableput_301094_2984716966)(Tidtable294850* t0, Tidobj201004* key0, TNimObject* val0); N_NIMCALL(void, pushtype_535958_839829468)(Tcgen531027* m0, Ttype294840* typ0); N_NIMCALL(Ropeobj180006*, gettypedescweak_536079_839829468)(Tcgen531027* m0, Ttype294840* t0, Intset270030* check0); N_NIMCALL(void, internalerror_198100_155036129)(Tlineinfo193336 info0, NimStringDesc* errmsg0); N_NIMCALL(NIM_BOOL, hasenum_205230_1926258066)(Debuginfo205009 self0, NimStringDesc* ename0, NI id0, NU32 owner0); N_NIMCALL(void*, newSeq)(TNimType* typ0, NI len0); static N_INLINE(NI, len_295081_850551059)(Tnode294802* n0); N_NIMCALL(void, registerenum_205419_1926258066)(Debuginfo205009* self0, Enumdesc205007* ed0); N_NIMCALL(void, genericSeqAssign)(void* dest0, void* src_86404_1689653243, TNimType* mt0); N_NIMCALL(void, appcg_534632_839829468)(Tcgen531027* m0, Ropeobj180006** c0, NimStringDesc* frmt0, Ropeobj180006** args0, NI args0Len0); N_NIMCALL(NI64, lengthord_322007_3876443242)(Ttype294840* t0); N_NIMCALL(NIM_BOOL, scancppgenericslot_536827_839829468)(NimStringDesc* pat0, NI* cursor0, NI* outidx0, NI* outstars0); N_NIMCALL(Ttype294840*, resolvestarsincpptype_536891_839829468)(Ttype294840* typ0, NI idx0, NI stars0); N_NIMCALL(NI, len_297339_850551059)(Ttype294840* n0); N_NIMCALL(NimStringDesc*, copyStr)(NimStringDesc* s0, NI start0); N_NIMCALL(NimStringDesc*, copyStr)(NimStringDesc* s0, NI first0); N_NIMCALL(Ropeobj180006*, getrecorddesc_536643_839829468)(Tcgen531027* m0, Ttype294840* typ0, Ropeobj180006* name0, Intset270030* check0); N_NIMCALL(Ropeobj180006*, getrecordfields_536636_839829468)(Tcgen531027* m0, Ttype294840* typ0, Intset270030* check0); N_NIMCALL(Ropeobj180006*, genrecordfieldsaux_536421_839829468)(Tcgen531027* m0, Tnode294802* n0, Ropeobj180006* accessexpr0, Ttype294840* rectype0, Intset270030* check0); N_NIMCALL(NI, sonslen_297351_850551059)(Tnode294802* n0); N_NIMCALL(Tnode294802*, lastson_297364_850551059)(Tnode294802* n0); N_NIMCALL(Ropeobj180006*, HEX26_180452_2381377266)(NimStringDesc* a0, Ropeobj180006* b0); N_NIMCALL(Ropeobj180006*, manglerecfieldname_536361_839829468)(Tsym294834* field0, Ttype294840* rectype0); N_NIMCALL(NimStringDesc*, manglefield_534973_839829468)(Tident201010* name0); N_NIMCALL(NIM_CHAR, nsuToUpperAsciiChar)(NIM_CHAR c0); N_NIMCALL(Ropeobj180006*, gettupledesc_536777_839829468)(Tcgen531027* m0, Ttype294840* typ0, Ropeobj180006* name0, Intset270030* check0); N_NIMCALL(NI, sonslen_297327_850551059)(Ttype294840* n0); N_NIMCALL(void, excl_270841_2627731572)(Intset270030* s0, NI key0); static N_INLINE(NIM_BOOL, iscompiletimeonly_330706_3876443242)(Ttype294840* t0); N_NIMCALL(Tstorageloc294812, paramstorageloc_536098_839829468)(Tsym294834* param0); N_NIMCALL(NIM_BOOL, ccgintroducedptr_535609_839829468)(Tsym294834* s0); N_NIMCALL(Tctypekind531007, mapreturntype_535445_839829468)(Ttype294840* typ0); N_NIMCALL(Tnode294802*, easyresultasgn_562191_839829468)(Tnode294802* n0); static N_INLINE(Tnode294802*, HEX5BHEX5D_295238_850551059)(Tnode294802* n0, NI i0); N_NIMCALL(Tnode294802*, getbody_337227_1724185294)(Tsym294834* s0); N_NIMCALL(Ropeobj180006*, localvardecl_540532_839829468)(Tcproc531021* p0, Tsym294834* s0); N_NIMCALL(Ropeobj180006*, gettypedesc_537671_839829468)(Tcgen531027* m0, Ttype294840* typ0); N_NIMCALL(void, initlocexprsingleuse_541289_839829468)(Tcproc531021* p0, Tnode294802* e0, Tloc294816* result0); N_NIMCALL(void, initloc_534273_839829468)(Tloc294816* result0, Tlockind294808 k0, Ttype294840* typ0, Tstorageloc294812 s0); N_NIMCALL(void, linefmt_534714_839829468)(Tcproc531021* p0, Tcprocsection531011 s0, NimStringDesc* frmt0, Ropeobj180006** args0, NI args0Len0); static N_INLINE(Ropeobj180006**, s_531179_3723162438)(Tcproc531021* p0, Tcprocsection531011 s0); N_NIMCALL(Ropeobj180006*, indentline_534656_839829468)(Tcproc531021* p0, Ropeobj180006* r0); N_NIMCALL(void, prepend_180893_2381377266)(Ropeobj180006** a0, Ropeobj180006* b0); N_NIMCALL(Ropeobj180006*, rdloc_540188_839829468)(Tloc294816 a0); N_NIMCALL(void, assignlocalvar_540614_839829468)(Tcproc531021* p0, Tsym294834* s0); N_NIMCALL(void, line_534690_839829468)(Tcproc531021* p0, Tcprocsection531011 s0, Ropeobj180006* r0); N_NIMCALL(void, localdebuginfo_540449_839829468)(Tcproc531021* p0, Tsym294834* s0); N_NIMCALL(void, linef_534700_839829468)(Tcproc531021* p0, Tcprocsection531011 s0, NimStringDesc* frmt0, Ropeobj180006** args0, NI args0Len0); N_NIMCALL(Ropeobj180006*, makecstring_193638_155036129)(NimStringDesc* s0); N_NIMCALL(NimStringDesc*, nsuNormalize)(NimStringDesc* s0); N_NIMCALL(Ropeobj180006*, gentypeinfo_537941_839829468)(Tcgen531027* m0, Ttype294840* t_537944_839829468); N_NIMCALL(Tcgen531027*, bmod_531201_3723162438)(Tsym294834* module0); N_NIMCALL(void, gentypeinfoauxbase_537960_839829468)(Tcgen531027* m0, Ttype294840* typ0, Ttype294840* origtype0, Ropeobj180006* name0, Ropeobj180006* base0); N_NIMCALL(NIM_BOOL, canformacycle_322123_3876443242)(Ttype294840* typ0); N_NIMCALL(void, gentupleinfo_538549_839829468)(Tcgen531027* m0, Ttype294840* typ0, Ropeobj180006* name0); N_NIMCALL(Ropeobj180006*, getnimnode_537945_839829468)(Tcgen531027* m0); N_NIMCALL(Ttype294840*, fakeclosuretype_539010_839829468)(Tsym294834* owner0); N_NIMCALL(Ttype294840*, newtype_297107_850551059)(Ttypekind294244 kind0, Tsym294834* owner0); N_NIMCALL(void, rawaddson_298394_850551059)(Ttype294840* father0, Ttype294840* son0); N_NIMCALL(void, gentypeinfoaux_538027_839829468)(Tcgen531027* m0, Ttype294840* typ0, Ttype294840* origtype0, Ropeobj180006* name0); N_NIMCALL(Ropeobj180006*, gentraverseproc_539632_839829468)(Tcgen531027* m0, Ttype294840* typ0, Ttypeinforeason539016 reason0); N_NIMCALL(void, gentraverseprocseq_539399_839829468)(Ttraversalclosure539019* c0, Ropeobj180006* accessor0, Ttype294840* typ0); N_NIMCALL(void, gettemp_539032_839829468)(Tcproc531021* p0, Ttype294840* t0, Tloc294816* result0, NIM_BOOL needsinit0); N_NIMCALL(void, constructloc_540388_839829468)(Tcproc531021* p0, Tloc294816 loc0, NIM_BOOL istemp0); static N_INLINE(NIM_BOOL, iscomplexvaluetype_540317_839829468)(Ttype294840* t0); N_NIMCALL(void, usestringh_534345_839829468)(Tcgen531027* m0); N_NIMCALL(Ropeobj180006*, addrloc_540204_839829468)(Tloc294816 a0); N_NIMCALL(void, genobjectinit_540242_839829468)(Tcproc531021* p0, Tcprocsection531011 section0, Ttype294840* t0, Tloc294816 a0, NIM_BOOL takeaddr0); N_NIMCALL(Ttypefieldresult322145, analyseobjectwithtypefield_322149_3876443242)(Ttype294840* t0); N_NIMCALL(Ttype294840*, getsystype_340150_3937434831)(Ttypekind294244 kind0); N_NIMCALL(void, gentraverseproc_539022_839829468)(Ttraversalclosure539019* c0, Ropeobj180006* accessor0, Ttype294840* typ_539027_839829468); static N_INLINE(Ropeobj180006*, parentobj_539257_839829468)(Ropeobj180006* accessor0, Tcgen531027* m0); N_NIMCALL(void, gentraverseproc_539039_839829468)(Ttraversalclosure539019* c0, Ropeobj180006* accessor0, Tnode294802* n0); N_NIMCALL(void, gencaserange_539028_839829468)(Tcproc531021* p0, Tnode294802* branch0); N_NIMCALL(Ropeobj180006*, genliteral_541273_839829468)(Tcproc531021* p0, Tnode294802* n0); N_NIMCALL(Ropeobj180006*, genliteral_551476_839829468)(Tcproc531021* p0, Tnode294802* n0, Ttype294840* ty0); N_NIMCALL(Ropeobj180006*, intliteral_541270_839829468)(NI64 i0); N_NIMCALL(Ropeobj180006*, int64literal_551430_839829468)(NI64 i0); N_NIMCALL(Ropeobj180006*, uint64literal_551442_839829468)(NU64 i0); N_NIMCALL(NI, nodetabletestorset_344682_1142335848)(Tnodetable294862* t0, Tnode294802* key0, NI val0); N_NIMCALL(Ropeobj180006*, getstrlit_551468_839829468)(Tcgen531027* m0, NimStringDesc* s0); N_NIMCALL(NimStringDesc*, tostrmaxprecision_300007_3471544153)(NF f0); N_NIMCALL(Tnode294802*, copynode_298528_850551059)(Tnode294802* src0); N_NIMCALL(void, linecg_534707_839829468)(Tcproc531021* p0, Tcprocsection531011 s0, NimStringDesc* frmt0, Ropeobj180006** args0, NI args0Len0); N_NIMCALL(void, genarrayinfo_539005_839829468)(Tcgen531027* m0, Ttype294840* typ0, Ropeobj180006* name0); N_NIMCALL(void, gensetinfo_538867_839829468)(Tcgen531027* m0, Ttype294840* typ0, Ropeobj180006* name0); N_NIMCALL(void, genenuminfo_538597_839829468)(Tcgen531027* m0, Ttype294840* typ0, Ropeobj180006* name0); N_NIMCALL(void, genobjectinfo_538506_839829468)(Tcgen531027* m0, Ttype294840* typ0, Ttype294840* origtype0, Ropeobj180006* name0); N_NIMCALL(void, genobjectfields_538104_839829468)(Tcgen531027* m0, Ttype294840* typ0, Tnode294802* n0, Ropeobj180006* expr0); N_NIMCALL(Ropeobj180006*, discriminatortablename_538057_839829468)(Tcgen531027* m0, Ttype294840* objtype_538060_839829468, Tsym294834* d0); N_NIMCALL(Tsym294834*, lookupinrecord_301119_2984716966)(Tnode294802* n0, Tident201010* field0); N_NIMCALL(NI64, getordvalue_322129_3876443242)(Tnode294802* n0); N_NIMCALL(void, gendeepcopyproc_540066_839829468)(Tcgen531027* m0, Tsym294834* s0, Ropeobj180006* result0); N_NIMCALL(void, initlocalvar_540398_839829468)(Tcproc531021* p0, Tsym294834* v0, NIM_BOOL immediateasgn0); N_NIMCALL(void, fillresult_535865_839829468)(Tsym294834* param0); N_NIMCALL(void, assignparam_540994_839829468)(Tcproc531021* p0, Tsym294834* s0); N_NIMCALL(void, closuresetup_562158_839829468)(Tcproc531021* p0, Tsym294834* prc0); N_NIMCALL(Ropeobj180006*, initgcframe_540435_839829468)(Tcproc531021* p0); N_NIMCALL(Ropeobj180006*, initframe_562140_839829468)(Tcproc531021* p0, Ropeobj180006* procname0, Ropeobj180006* filename0); N_NIMCALL(Ropeobj180006*, quotedfilename_198818_155036129)(Tlineinfo193336 i0); N_NIMCALL(void, appcg_534648_839829468)(Tcproc531021* p0, Tcprocsection531011 s0, NimStringDesc* frmt0, Ropeobj180006** args0, NI args0Len0); N_NIMCALL(Ropeobj180006*, deinitgcframe_540441_839829468)(Tcproc531021* p0); N_NIMCALL(Ropeobj180006*, deinitframe_562150_839829468)(Tcproc531021* p0); N_NIMCALL(Tcgen531027*, findpendingmodule_534241_839829468)(Tcgen531027* m0, Tsym294834* s0); N_NIMCALL(void, symindynamiclib_561929_839829468)(Tcgen531027* m0, Tsym294834* sym0); N_NIMCALL(NIM_BOOL, isgetprocaddr_561442_839829468)(Tlib294820* lib0); N_NIMCALL(void, loaddynamiclib_561480_839829468)(Tcgen531027* m0, Tlib294820* lib0); N_NIMCALL(void, libcandidates_172605_2607990831)(NimStringDesc* s0, TY136002** dest0); N_NIMCALL(void, rawmessage_196612_155036129)(Tmsgkind193002 msg0, NimStringDesc* arg0); N_NIMCALL(void, initlocexpr_541283_839829468)(Tcproc531021* p0, Tnode294802* e0, Tloc294816* result0); N_NIMCALL(Ropeobj180006*, mangledynlibproc_540816_839829468)(Tsym294834* sym0); N_NIMCALL(NimStringDesc*, HEX24_180856_2381377266)(Ropeobj180006* r0); N_NIMCALL(void, symindynamiclibpartial_562071_839829468)(Tcgen531027* m0, Tsym294834* sym0); N_NIMCALL(void, genvarprototype_541236_839829468)(Tcgen531027* m0, Tsym294834* sym0); N_NIMCALL(void, genvarprototypeaux_546254_839829468)(Tcgen531027* m0, Tsym294834* sym0); N_NIMCALL(void, declarethreadvar_540676_839829468)(Tcgen531027* m0, Tsym294834* s0, NIM_BOOL isextern0); static N_INLINE(NIM_BOOL, emulatedthreadvars_534949_839829468)(void); static N_INLINE(NIM_BOOL, crossescppboundary_562754_839829468)(Tcgen531027* m0, Tsym294834* sym0); N_NIMCALL(void, putlocintodest_541258_839829468)(Tcproc531021* p0, Tloc294816* d0, Tloc294816 s0); N_NIMCALL(void, genassignment_541264_839829468)(Tcproc531021* p0, Tloc294816 dest0, Tloc294816 src0, Tassignmentflag540302Set flags0); N_NIMCALL(void, genrefassign_540311_839829468)(Tcproc531021* p0, Tloc294816 dest0, Tloc294816 src0, Tassignmentflag540302Set flags0); static N_INLINE(NIM_BOOL, usesnativegc_171177_2607990831)(void); N_NIMCALL(void, optasgnloc_551788_839829468)(Tloc294816 a0, Ttype294840* t0, Ropeobj180006* field0, Tloc294816* Result); N_NIMCALL(void, genoptasgntuple_552001_839829468)(Tcproc531021* p0, Tloc294816 dest0, Tloc294816 src0, Tassignmentflag540302Set flags0); N_NIMCALL(void, gengenericasgn_552167_839829468)(Tcproc531021* p0, Tloc294816 dest0, Tloc294816 src0, Tassignmentflag540302Set flags0); N_NIMCALL(NI, asgncomplexity_551750_839829468)(Tnode294802* n0); N_NIMCALL(void, genoptasgnobject_552084_839829468)(Tcproc531021* p0, Tloc294816 dest0, Tloc294816 src0, Tassignmentflag540302Set flags0, Tnode294802* t0); N_NIMCALL(void, genericAssign)(void* dest0, void* src0, TNimType* mt0); N_NIMCALL(void, localerror_198085_155036129)(Tlineinfo193336 info0, NimStringDesc* arg0); N_NIMCALL(NIM_BOOL, issimpleconst_534311_839829468)(Ttype294840* typ0); N_NIMCALL(void, putintodest_552468_839829468)(Tcproc531021* p0, Tloc294816* d0, Ttype294840* t0, Ropeobj180006* r0, Tstorageloc294812 s0); N_NIMCALL(void, gencomplexconst_560249_839829468)(Tcproc531021* p0, Tsym294834* sym0, Tloc294816* d0); N_NIMCALL(void, requestconstimpl_541240_839829468)(Tcproc531021* p0, Tsym294834* sym0); N_NIMCALL(Ropeobj180006*, genconstexpr_556849_839829468)(Tcproc531021* p0, Tnode294802* n0); N_NIMCALL(void, tobitset_342001_452470228)(Tnode294802* s0, Tbitset341004** b0); N_NIMCALL(Ropeobj180006*, genrawsetdata_551629_839829468)(Tbitset341004* cs0, NI size0); N_NIMCALL(NimStringDesc*, nsuToHex)(NI64 x0, NI len0); N_NIMCALL(NI64, bitsettoword_551578_839829468)(Tbitset341004* s0, NI size0); N_NIMCALL(Ropeobj180006*, genconstseq_561371_839829468)(Tcproc531021* p0, Tnode294802* n0, Ttype294840* t0); N_NIMCALL(void, appcg_534640_839829468)(Tcgen531027* m0, Tcfilesection531005 s0, NimStringDesc* frmt0, Ropeobj180006** args0, NI args0Len0); N_NIMCALL(Ropeobj180006*, genconstsimplelist_561299_839829468)(Tcproc531021* p0, Tnode294802* n0); N_NIMCALL(Ropeobj180006*, gennamedconstexpr_561284_839829468)(Tcproc531021* p0, Tnode294802* n0); N_NIMCALL(void, accessthreadlocalvar_534945_839829468)(Tcproc531021* p0, Tsym294834* s0); static N_INLINE(Ropeobj180006**, procsec_531194_3723162438)(Tcproc531021* p0, Tcprocsection531011 s0); static N_INLINE(NIM_BOOL, isemptytype_299440_850551059)(Ttype294840* t0); N_NIMCALL(void, putdataintodest_552436_839829468)(Tcproc531021* p0, Tloc294816* d0, Ttype294840* t0, Ropeobj180006* r0); N_NIMCALL(void, genlinedir_534823_839829468)(Tcproc531021* p0, Tnode294802* t0); N_NIMCALL(Ropeobj180006*, sourceline_194068_155036129)(Tlineinfo193336 i0); N_NIMCALL(NIM_BOOL, freshlineinfo_534818_839829468)(Tcproc531021* p0, Tlineinfo193336 info0); N_NIMCALL(void, genmagicexpr_559033_839829468)(Tcproc531021* p0, Tnode294802* e0, Tloc294816* d0, Tmagic294524 op0); N_NIMCALL(void, genandor_556311_839829468)(Tcproc531021* p0, Tnode294802* e0, Tloc294816* d0, Tmagic294524 m0); N_NIMCALL(Ropeobj180006*, getlabel_541217_839829468)(Tcproc531021* p0); N_NIMCALL(void, fixlabel_541230_839829468)(Tcproc531021* p0, Ropeobj180006* labl0); N_NIMCALL(void, unaryarith_554646_839829468)(Tcproc531021* p0, Tnode294802* e0, Tloc294816* d0, Tmagic294524 op0); N_NIMCALL(void, unaryarithoverflow_553633_839829468)(Tcproc531021* p0, Tnode294802* e0, Tloc294816* d0, Tmagic294524 m0); N_NIMCALL(void, binaryfloatarith_558728_839829468)(Tcproc531021* p0, Tnode294802* e0, Tloc294816* d0, Tmagic294524 m0); N_NIMCALL(void, binaryarith_553819_839829468)(Tcproc531021* p0, Tnode294802* e0, Tloc294816* d0, Tmagic294524 op0); N_NIMCALL(void, geneqproc_554214_839829468)(Tcproc531021* p0, Tnode294802* e0, Tloc294816* d0); N_NIMCALL(void, binaryarithoverflow_553262_839829468)(Tcproc531021* p0, Tnode294802* e0, Tloc294816* d0, Tmagic294524 m0); N_NIMCALL(Ropeobj180006*, binaryarithoverflowraw_553235_839829468)(Tcproc531021* p0, Ttype294840* t0, Tloc294816 a0, Tloc294816 b0, NimStringDesc* frmt0); N_NIMCALL(Ropeobj180006*, rdcharloc_540227_839829468)(Tloc294816 a0); N_NIMCALL(NI64, lastord_322004_3876443242)(Ttype294840* t0); N_NIMCALL(void, genrepr_557339_839829468)(Tcproc531021* p0, Tnode294802* e0, Tloc294816* d0); N_NIMCALL(Ropeobj180006*, lenfield_541305_839829468)(Tcproc531021* p0); N_NIMCALL(void, gcusage_556439_839829468)(Tnode294802* n0); N_NIMCALL(void, message_198095_155036129)(Tlineinfo193336 info0, Tmsgkind193002 msg0, NimStringDesc* arg0); N_NIMCALL(NimStringDesc*, rendertree_313044_382274130)(Tnode294802* n0, Trenderflag313004Set renderflags0); N_NIMCALL(void, gengettypeinfo_557383_839829468)(Tcproc531021* p0, Tnode294802* e0, Tloc294816* d0); N_NIMCALL(void, genswap_557638_839829468)(Tcproc531021* p0, Tnode294802* e0, Tloc294816* d0); N_NIMCALL(void, unaryexpr_553209_839829468)(Tcproc531021* p0, Tnode294802* e0, Tloc294816* d0, NimStringDesc* frmt0); N_NIMCALL(void, binarystmt_552501_839829468)(Tcproc531021* p0, Tnode294802* e0, Tloc294816* d0, NimStringDesc* frmt0); N_NIMCALL(void, genstrconcat_556452_839829468)(Tcproc531021* p0, Tnode294802* e0, Tloc294816* d0); N_NIMCALL(void, genstrappend_556554_839829468)(Tcproc531021* p0, Tnode294802* e0, Tloc294816* d0); N_NIMCALL(void, genseqelemappend_556683_839829468)(Tcproc531021* p0, Tnode294802* e0, Tloc294816* d0); N_NIMCALL(void, genstrequals_558666_839829468)(Tcproc531021* p0, Tnode294802* e0, Tloc294816* d0); N_NIMCALL(void, binaryexpr_552549_839829468)(Tcproc531021* p0, Tnode294802* e0, Tloc294816* d0, NimStringDesc* frmt0); N_NIMCALL(void, genisnil_554620_839829468)(Tcproc531021* p0, Tnode294802* e0, Tloc294816* d0); N_NIMCALL(void, gendollar_557391_839829468)(Tcproc531021* p0, Tnode294802* n0, Tloc294816* d0, NimStringDesc* frmt0); N_NIMCALL(void, genof_557331_839829468)(Tcproc531021* p0, Tnode294802* n0, Tloc294816* d0); N_NIMCALL(void, genof_557201_839829468)(Tcproc531021* p0, Tnode294802* x0, Ttype294840* typ0, Tloc294816* d0); N_NIMCALL(void, globalerror_198071_155036129)(Tlineinfo193336 info0, Tmsgkind193002 msg0, NimStringDesc* arg0); N_NIMCALL(Ropeobj180006*, genofhelper_557139_839829468)(Tcproc531021* p0, Ttype294840* dest0, Ropeobj180006* a0); N_NIMCALL(void, gennew_556782_839829468)(Tcproc531021* p0, Tnode294802* e0); N_NIMCALL(void, rawgennew_556741_839829468)(Tcproc531021* p0, Tloc294816 a0, Ropeobj180006* sizeexpr_556745_839829468); N_NIMCALL(void, gennewfinalize_557110_839829468)(Tcproc531021* p0, Tnode294802* e0); N_NIMCALL(void, gennewseq_556824_839829468)(Tcproc531021* p0, Tnode294802* e0); N_NIMCALL(void, gennewseqaux_556795_839829468)(Tcproc531021* p0, Tloc294816 dest0, Ropeobj180006* length0); N_NIMCALL(void, gennewseqofcap_556836_839829468)(Tcproc531021* p0, Tnode294802* e0, Tloc294816* d0); N_NIMCALL(void, gensomecast_558480_839829468)(Tcproc531021* p0, Tnode294802* e0, Tloc294816* d0); N_NIMCALL(Ropeobj180006*, getclosuretype_537683_839829468)(Tcgen531027* m0, Ttype294840* t0, Tclosuretypekind537679 kind0); N_NIMCALL(void, genord_558474_839829468)(Tcproc531021* p0, Tnode294802* e0, Tloc294816* d0); N_NIMCALL(void, unaryexprchar_553222_839829468)(Tcproc531021* p0, Tnode294802* e0, Tloc294816* d0, NimStringDesc* frmt0); N_NIMCALL(void, genarraylen_557415_839829468)(Tcproc531021* p0, Tnode294802* e0, Tloc294816* d0, Tmagic294524 op0); N_NIMCALL(void, unarystmt_552527_839829468)(Tcproc531021* p0, Tnode294802* e0, Tloc294816* d0, NimStringDesc* frmt0); N_NIMCALL(void, gensetlengthstr_557632_839829468)(Tcproc531021* p0, Tnode294802* e0, Tloc294816* d0); N_NIMCALL(void, gensetlengthseq_557500_839829468)(Tcproc531021* p0, Tnode294802* e0, Tloc294816* d0); N_NIMCALL(void, gensetop_558419_839829468)(Tcproc531021* p0, Tnode294802* e0, Tloc294816* d0, Tmagic294524 op0); N_NIMCALL(void, binarystmtinexcl_557857_839829468)(Tcproc531021* p0, Tnode294802* e0, Tloc294816* d0, NimStringDesc* frmt0); N_NIMCALL(Ropeobj180006*, rdsetelemloc_557662_839829468)(Tloc294816 a0, Ttype294840* settype0); N_NIMCALL(void, binaryexprchar_552809_839829468)(Tcproc531021* p0, Tnode294802* e0, Tloc294816* d0, NimStringDesc* frmt0); N_NIMCALL(void, geninop_558009_839829468)(Tcproc531021* p0, Tnode294802* e0, Tloc294816* d0); N_NIMCALL(NIM_BOOL, fewcmps_557803_839829468)(Tnode294802* s0); N_NIMCALL(void, geninexpraux_555496_839829468)(Tcproc531021* p0, Tnode294802* e0, Tloc294816* a0, Tloc294816* b0, Tloc294816* d0); N_NIMCALL(void, binaryexprin_557837_839829468)(Tcproc531021* p0, Tnode294802* e0, Tloc294816* a0, Tloc294816* b0, Tloc294816* d0, NimStringDesc* frmt0); N_NIMCALL(void, gencall_545632_839829468)(Tcproc531021* p0, Tnode294802* e0, Tloc294816* d0); N_NIMCALL(void, genclosurecall_542452_839829468)(Tcproc531021* p0, Tnode294802* le0, Tnode294802* ri0, Tloc294816* d0); N_NIMCALL(Ropeobj180006*, genarg_541787_839829468)(Tcproc531021* p0, Tnode294802* n_541790_839829468, Tsym294834* param0, Tnode294802* call0); static N_INLINE(Ropeobj180006*, genargstringtocstring_541776_839829468)(Tcproc531021* p0, Tnode294802* n0); N_NIMCALL(Ropeobj180006*, openarrayloc_541665_839829468)(Tcproc531021* p0, Tnode294802* n0); N_NIMCALL(Tnode294802*, skipconv_330882_3876443242)(Tnode294802* n0); N_NIMCALL(Tmagic294524, getmagic_320502_2616423590)(Tnode294802* op0); N_NIMCALL(Ropeobj180006*, genargnoparam_541938_839829468)(Tcproc531021* p0, Tnode294802* n0); N_NIMCALL(Ropeobj180006*, getrawproctype_542459_839829468)(Tcproc531021* p0, Ttype294840* t0); N_NIMCALL(NIM_BOOL, leftappearsonrightside_541329_839829468)(Tnode294802* le0, Tnode294802* ri0); N_NIMCALL(Tanalysisresult475003, ispartof_475340_788060399)(Tnode294802* a0, Tnode294802* b0); static N_INLINE(NIM_BOOL, hasnoinit_541383_839829468)(Tnode294802* call0); N_NIMCALL(void, resetloc_540350_839829468)(Tcproc531021* p0, Tloc294816* loc0); N_NIMCALL(Ropeobj180006*, addcomma_542464_839829468)(Ropeobj180006* r0); N_NIMCALL(void, geninfixcall_543929_839829468)(Tcproc531021* p0, Tnode294802* le0, Tnode294802* ri0, Tloc294816* d0); N_NIMCALL(NIM_BOOL, contains_110056_4286263276)(NimStringDesc* s0, char136Set chars0); N_NIMCALL(Ropeobj180006*, genpatterncall_543699_839829468)(Tcproc531021* p0, Tnode294802* ri_543702_839829468, NimStringDesc* pat0, Ttype294840* typ_543704_839829468); N_NIMCALL(Ropeobj180006*, genotherarg_541277_839829468)(Tcproc531021* p0, Tnode294802* ri0, NI i0, Ttype294840* typ0); N_NIMCALL(Ropeobj180006*, genthisarg_543475_839829468)(Tcproc531021* p0, Tnode294802* ri_543478_839829468, NI i0, Ttype294840* typ0); N_NIMCALL(Tnode294802*, skipaddrderef_543433_839829468)(Tnode294802* node0); N_NIMCALL(void, fixupcall_541410_839829468)(Tcproc531021* p0, Tnode294802* le0, Tnode294802* ri0, Tloc294816* d0, Ropeobj180006* callee0, Ropeobj180006* params0); N_NIMCALL(void, gennamedparamcall_544616_839829468)(Tcproc531021* p0, Tnode294802* ri0, Tloc294816* d0); N_NIMCALL(NIM_BOOL, contains_110046_4286263276)(NimStringDesc* s0, NIM_CHAR c0); N_NIMCALL(void, genprefixcall_541960_839829468)(Tcproc531021* p0, Tnode294802* le0, Tnode294802* ri0, Tloc294816* d0); static N_INLINE(void, poststmtactions_534942_839829468)(Tcproc531021* p0); N_NIMCALL(void, genreset_556731_839829468)(Tcproc531021* p0, Tnode294802* n0); N_NIMCALL(void, genecho_556369_839829468)(Tcproc531021* p0, Tnode294802* n0); N_NIMCALL(NimStringDesc*, nsuRepeatStr)(NimStringDesc* s0, NI n0); N_NIMCALL(void, genarrtoseq_557046_839829468)(Tcproc531021* p0, Tnode294802* t0, Tloc294816* d0); N_NIMCALL(void, genseqconstr_557004_839829468)(Tcproc531021* p0, Tnode294802* t0, Tloc294816* d0); N_NIMCALL(void, localerror_198080_155036129)(Tlineinfo193336 info0, Tmsgkind193002 msg0, NimStringDesc* arg0); N_NIMCALL(Tnode294802*, wrapprocforspawn_437501_2218250499)(Tsym294834* owner0, Tnode294802* spawnexpr0, Ttype294840* rettype0, Tnode294802* barrier0, Tnode294802* dest0); N_NIMCALL(Tnode294802*, liftparallel_480822_1773027539)(Tsym294834* owner0, Tnode294802* n0); N_NIMCALL(void, gendeepcopy_552374_839829468)(Tcproc531021* p0, Tloc294816 dest0, Tloc294816 src0); N_NIMCALL(NIM_BOOL, isdeepconstexpr_320566_2616423590)(Tnode294802* n0); N_NIMCALL(Ropeobj180006*, gensetnode_551664_839829468)(Tcproc531021* p0, Tnode294802* n0); N_NIMCALL(void, gensetconstr_559496_839829468)(Tcproc531021* p0, Tnode294802* e0, Tloc294816* d0); N_NIMCALL(NimStringDesc*, nimInt64ToStr)(NI64 x0); N_NIMCALL(void, exprcomplexconst_560684_839829468)(Tcproc531021* p0, Tnode294802* n0, Tloc294816* d0); N_NIMCALL(void, genarrayconstr_560207_839829468)(Tcproc531021* p0, Tnode294802* n0, Tloc294816* d0); N_NIMCALL(NIM_BOOL, handleconstexpr_556853_839829468)(Tcproc531021* p0, Tnode294802* n0, Tloc294816* d0); N_NIMCALL(void, gentupleconstr_559618_839829468)(Tcproc531021* p0, Tnode294802* n0, Tloc294816* d0); N_NIMCALL(void, genobjconstr_556903_839829468)(Tcproc531021* p0, Tnode294802* e0, Tloc294816* d0); N_NIMCALL(Tsym294834*, lookupfieldagain_555153_839829468)(Tcproc531021* p0, Ttype294840* ty_555156_839829468, Tsym294834* field0, Ropeobj180006** r0); N_NIMCALL(void, genfieldcheck_555504_839829468)(Tcproc531021* p0, Tnode294802* e0, Ropeobj180006* obj0, Tsym294834* field0, Ttype294840* origty0); N_NIMCALL(Tnode294802*, newstrnode_295678_850551059)(Tnodekind294020 kind0, NimStringDesc* strval0); N_NIMCALL(void, gencast_558537_839829468)(Tcproc531021* p0, Tnode294802* e0, Tloc294816* d0); N_NIMCALL(void, genconv_558632_839829468)(Tcproc531021* p0, Tnode294802* e0, Tloc294816* d0); N_NIMCALL(NIM_BOOL, comparetypes_328214_3876443242)(Ttype294840* x0, Ttype294840* y0, Tdistinctcompare326427 cmp0, Ttypecmpflag326429Set flags0); N_NIMCALL(void, genaddr_555051_839829468)(Tcproc531021* p0, Tnode294802* e0, Tloc294816* d0); static N_INLINE(NIM_BOOL, iscppref_554807_839829468)(Tcproc531021* p0, Ttype294840* typ0); N_NIMCALL(void, genbracketexpr_556277_839829468)(Tcproc531021* p0, Tnode294802* n0, Tloc294816* d0); N_NIMCALL(void, genarrayelem_556093_839829468)(Tcproc531021* p0, Tnode294802* x0, Tnode294802* y0, Tloc294816* d0); N_NIMCALL(NIM_BOOL, isconstexpr_320510_2616423590)(Tnode294802* n0); N_NIMCALL(void, genopenarrayelem_556169_839829468)(Tcproc531021* p0, Tnode294802* x0, Tnode294802* y0, Tloc294816* d0); N_NIMCALL(void, genseqelem_556205_839829468)(Tcproc531021* p0, Tnode294802* x0, Tnode294802* y0, Tloc294816* d0); N_NIMCALL(void, gencstringelem_556144_839829468)(Tcproc531021* p0, Tnode294802* x0, Tnode294802* y0, Tloc294816* d0); N_NIMCALL(void, gentupleelem_555124_839829468)(Tcproc531021* p0, Tnode294802* e0, Tloc294816* d0); N_NIMCALL(void, genderef_545921_839829468)(Tcproc531021* p0, Tnode294802* e0, Tloc294816* d0, NIM_BOOL enforcederef0); N_NIMCALL(void, genrecordfield_555448_839829468)(Tcproc531021* p0, Tnode294802* e0, Tloc294816* d0); N_NIMCALL(Ttype294840*, genrecordfieldaux_555096_839829468)(Tcproc531021* p0, Tnode294802* e0, Tloc294816* d0, Tloc294816* a0); N_NIMCALL(void, gencheckedrecordfield_556046_839829468)(Tcproc531021* p0, Tnode294802* e0, Tloc294816* d0); N_NIMCALL(void, genblock_548083_839829468)(Tcproc531021* p0, Tnode294802* n0, Tloc294816* d0); N_NIMCALL(NI, startblock_545978_839829468)(Tcproc531021* p0, NimStringDesc* start0, Ropeobj180006** args0, NI args0Len0); N_NIMCALL(void, endblock_546060_839829468)(Tcproc531021* p0); N_NIMCALL(void, endblock_546035_839829468)(Tcproc531021* p0, Ropeobj180006* blockend0); N_NIMCALL(Ropeobj180006*, blockbody_546025_839829468)(Tblock531019* b0); N_NIMCALL(void, genstmtlistexpr_560402_839829468)(Tcproc531021* p0, Tnode294802* n0, Tloc294816* d0); N_NIMCALL(void, genif_546982_839829468)(Tcproc531021* p0, Tnode294802* n0, Tloc294816* d0); N_NIMCALL(void, downconv_560581_839829468)(Tcproc531021* p0, Tnode294802* n0, Tloc294816* d0); N_NIMCALL(NI, inheritancediff_328252_3876443242)(Ttype294840* a0, Ttype294840* b0); N_NIMCALL(void, upconv_560431_839829468)(Tcproc531021* p0, Tnode294802* n0, Tloc294816* d0); N_NIMCALL(void, genrangechck_558590_839829468)(Tcproc531021* p0, Tnode294802* n0, Tloc294816* d0, NimStringDesc* magic0); N_NIMCALL(void, convstrtocstr_558642_839829468)(Tcproc531021* p0, Tnode294802* n0, Tloc294816* d0); N_NIMCALL(void, convcstrtostr_558654_839829468)(Tcproc531021* p0, Tnode294802* n0, Tloc294816* d0); N_NIMCALL(void, genclosure_559836_839829468)(Tcproc531021* p0, Tnode294802* n0, Tloc294816* d0); static N_INLINE(NIM_BOOL, isconstclosure_559810_839829468)(Tnode294802* n0); static N_INLINE(NIM_BOOL, isroutine_299323_850551059)(Tsym294834* s0); N_NIMCALL(void, genwhilestmt_547984_839829468)(Tcproc531021* p0, Tnode294802* t0); static N_INLINE(Ropeobj180006*, assignlabel_546020_839829468)(Tblock531019* b0); N_NIMCALL(NIM_BOOL, stmtscontainpragma_530083_2036603609)(Tnode294802* n0, Tspecialword277003 w0); N_NIMCALL(void, gencomputedgoto_547744_839829468)(Tcproc531021* p0, Tnode294802* n0); N_NIMCALL(void, genvarstmt_546854_839829468)(Tcproc531021* p0, Tnode294802* n0); N_NIMCALL(void, gensinglevar_546276_839829468)(Tcproc531021* p0, Tnode294802* a0); N_NIMCALL(void, gengotovar_546258_839829468)(Tcproc531021* p0, Tnode294802* value0); N_NIMCALL(void, assignglobalvar_540819_839829468)(Tcproc531021* p0, Tsym294834* s0); N_NIMCALL(void, varindynamiclib_540812_839829468)(Tcgen531027* m0, Tsym294834* sym0); N_NIMCALL(void, registergcroot_545762_839829468)(Tcproc531021* p0, Tsym294834* v0); N_NIMCALL(Ropeobj180006*, gentraverseprocforglobal_540032_839829468)(Tcgen531027* m0, Tsym294834* s0); static N_INLINE(NIM_BOOL, isassignedimmediately_545781_839829468)(Tnode294802* n0); N_NIMCALL(NIM_BOOL, containshiddenpointer_322120_3876443242)(Ttype294840* typ0); static N_INLINE(void, loadinto_545928_839829468)(Tcproc531021* p0, Tnode294802* le0, Tnode294802* ri0, Tloc294816* a0); N_NIMCALL(void, genasgncall_545695_839829468)(Tcproc531021* p0, Tnode294802* le0, Tnode294802* ri0, Tloc294816* d0); N_NIMCALL(void, genclosurevar_546832_839829468)(Tcproc531021* p0, Tnode294802* a0); N_NIMCALL(void, genvartuple_545794_839829468)(Tcproc531021* p0, Tnode294802* n0); N_NIMCALL(Tnode294802*, lowertupleunpacking_435037_2218250499)(Tnode294802* n0, Tsym294834* owner0); N_NIMCALL(void, genconststmt_546909_839829468)(Tcproc531021* p0, Tnode294802* t0); N_NIMCALL(NIM_BOOL, containscompiletimeonly_330721_3876443242)(Ttype294840* t0); static N_INLINE(NIM_BOOL, emitlazily_534248_839829468)(Tsym294834* s0); N_NIMCALL(void, gencase_549826_839829468)(Tcproc531021* p0, Tnode294802* t0, Tloc294816* d0); N_NIMCALL(void, genstringcase_549416_839829468)(Tcproc531021* p0, Tnode294802* t0, Tloc294816* d0); N_NIMCALL(NI, nextpoweroftwo_101629_1009420244)(NI x0); N_NIMCALL(void, gencasestringbranch_549100_839829468)(Tcproc531021* p0, Tnode294802* b0, Tloc294816 e0, Ropeobj180006* labl0, Ropeobj180006** branches0, NI branches0Len0); N_NIMCALL(NI64, hashstring_530100_2036603609)(NimStringDesc* s0); N_NIMCALL(Ropeobj180006*, gencasesecondpass_548965_839829468)(Tcproc531021* p0, Tnode294802* t0, Tloc294816* d0, NI labid0, NI until0); N_NIMCALL(void, exprblock_546103_839829468)(Tcproc531021* p0, Tnode294802* n0, Tloc294816* d0); N_NIMCALL(void, gencasegeneric_549087_839829468)(Tcproc531021* p0, Tnode294802* t0, Tloc294816* d0, NimStringDesc* rangeformat0, NimStringDesc* eqformat0); N_NIMCALL(Ropeobj180006*, genifforcaseuntil_549021_839829468)(Tcproc531021* p0, Tnode294802* t0, Tloc294816* d0, NimStringDesc* rangeformat0, NimStringDesc* eqformat0, NI until0, Tloc294816 a0); N_NIMCALL(void, gencasegenericbranch_548910_839829468)(Tcproc531021* p0, Tnode294802* b0, Tloc294816 e0, NimStringDesc* rangeformat0, NimStringDesc* eqformat0, Ropeobj180006* labl0); N_NIMCALL(void, gengotoforcase_547673_839829468)(Tcproc531021* p0, Tnode294802* casestmt0); N_NIMCALL(void, genordinalcase_549724_839829468)(Tcproc531021* p0, Tnode294802* n0, Tloc294816* d0); N_NIMCALL(NI, ifswitchsplitpoint_549615_839829468)(Tcproc531021* p0, Tnode294802* n0); N_NIMCALL(NIM_BOOL, branchhastoobigrange_549575_839829468)(Tnode294802* b0); N_NIMCALL(void, genreturnstmt_547617_839829468)(Tcproc531021* p0, Tnode294802* t0); N_NIMCALL(void, blockleaveactions_547442_839829468)(Tcproc531021* p0, NI howmanytrys0, NI howmanyexcepts0); static N_INLINE(Tnode294802*, pop_320246_1689653243)(Tnodeseq294796** s0); N_NIMCALL(void, genbreakstmt_548444_839829468)(Tcproc531021* p0, Tnode294802* t0); N_NIMCALL(void, genasgn_551239_839829468)(Tcproc531021* p0, Tnode294802* e0, NIM_BOOL fastasgn0); N_NIMCALL(NIM_BOOL, fielddiscriminantcheckneeded_551080_839829468)(Tcproc531021* p0, Tnode294802* asgn0); N_NIMCALL(void, asgnfielddiscriminant_551209_839829468)(Tcproc531021* p0, Tnode294802* e0); N_NIMCALL(void, gendiscriminantcheck_551144_839829468)(Tcproc531021* p0, Tloc294816 a0, Tloc294816 tmp0, Ttype294840* objtype0, Tsym294834* field0); N_NIMCALL(Ropeobj180006*, discriminatortabledecl_538094_839829468)(Tcgen531027* m0, Ttype294840* objtype0, Tsym294834* d0); N_NIMCALL(void, genasmstmt_550659_839829468)(Tcproc531021* p0, Tnode294802* t0); N_NIMCALL(Ropeobj180006*, genasmoremitstmt_550529_839829468)(Tcproc531021* p0, Tnode294802* t0, NIM_BOOL isasmstmt0); N_NIMCALL(NimStringDesc*, resizeString)(NimStringDesc* dest0, NI addlen0); N_NIMCALL(void, gentrycpp_549865_839829468)(Tcproc531021* p0, Tnode294802* t0, Tloc294816* d0); static N_INLINE(void, gensimpleblock_546095_839829468)(Tcproc531021* p0, Tnode294802* stmts0); N_NIMCALL(void, gentry_550114_839829468)(Tcproc531021* p0, Tnode294802* t0, Tloc294816* d0); N_NIMCALL(NIM_BOOL, isdefined_202011_1967573533)(NimStringDesc* symbol0); N_NIMCALL(void, line_534695_839829468)(Tcproc531021* p0, Tcprocsection531011 s0, NimStringDesc* r0); static N_INLINE(Ropeobj180006*, pop_180530_1689653243)(TY193350** s0); N_NIMCALL(void, genraisestmt_548828_839829468)(Tcproc531021* p0, Tnode294802* t0); N_NIMCALL(NimStringDesc*, getraisefrmt_548824_839829468)(Tcproc531021* p0); N_NIMCALL(void, gentypesection_540184_839829468)(Tcgen531027* m0, Tnode294802* n0); N_NIMCALL(void, genpragma_551039_839829468)(Tcproc531021* p_551041_839829468, Tnode294802* n0); N_NIMCALL(Tspecialword277003, whichpragma_320911_2616423590)(Tnode294802* n0); N_NIMCALL(void, genemit_550839_839829468)(Tcproc531021* p0, Tnode294802* t0); N_NIMCALL(Tcfilesection531005, determinesection_550819_839829468)(Tnode294802* n0); N_NIMCALL(NIM_BOOL, nsuStartsWith)(NimStringDesc* s0, NimStringDesc* prefix0); N_NIMCALL(void, genbreakpoint_550862_839829468)(Tcproc531021* p0, Tnode294802* t0); N_NIMCALL(void, genwatchpoint_551016_839829468)(Tcproc531021* p0, Tnode294802* n0); N_NIMCALL(Tsym294834*, skipgenericowner_299279_850551059)(Tsym294834* s0); N_NIMCALL(void, genparforstmt_548208_839829468)(Tcproc531021* p0, Tnode294802* t0); N_NIMCALL(void, genstate_546117_839829468)(Tcproc531021* p0, Tnode294802* n0); N_NIMCALL(void, gengotostate_546144_839829468)(Tcproc531021* p0, Tnode294802* n0); N_NIMCALL(void, genbreakstate_546229_839829468)(Tcproc531021* p0, Tnode294802* n0); N_NIMCALL(void, registermoduletomain_564243_839829468)(Tsym294834* m0); N_NIMCALL(Ropeobj180006*, getinitname_564235_839829468)(Tsym294834* m0); N_NIMCALL(Ropeobj180006*, getsomeinitname_563904_839829468)(Tsym294834* m0, NimStringDesc* suffix0); N_NIMCALL(Ropeobj180006*, getdatinitname_564239_839829468)(Tsym294834* m0); N_NIMCALL(Tnode294802*, generatemethoddispatchers_434151_3853300031)(void); N_NIMCALL(void, genmainproc_563729_839829468)(Tcgen531027* m0); N_NIMCALL(Ropeobj180006*, genfilenames_563688_839829468)(Tcgen531027* m0); N_NIMCALL(void, finishmodule_565420_839829468)(Tcgen531027* m0); N_NIMCALL(void, updatecachedmodule_565813_839829468)(Tcgen531027* m0); N_NIMCALL(NIM_BOOL, mergerequired_532832_2760143328)(Tcgen531027* m0); N_NIMCALL(void, mergefiles_533241_2760143328)(NimStringDesc* cfilename0, Tcgen531027* m0); N_NIMCALL(void, geninitcode_564286_839829468)(Tcgen531027* m0); N_NIMCALL(Ropeobj180006*, gensectionstart_532081_2760143328)(Tcprocsection531011 ps0); N_NIMCALL(Ropeobj180006*, gensectionend_532116_2760143328)(Tcprocsection531011 ps0); N_NIMCALL(Ropeobj180006*, gensectionstart_532015_2760143328)(Tcfilesection531005 fs0); N_NIMCALL(Ropeobj180006*, gensectionend_532050_2760143328)(Tcfilesection531005 fs0); N_NIMCALL(void, finishtypedescriptions_537842_839829468)(Tcgen531027* m0); N_NIMCALL(Ropeobj180006*, genmodule_564491_839829468)(Tcgen531027* m0, NimStringDesc* cfile0); N_NIMCALL(Ropeobj180006*, getfileheader_563683_839829468)(NimStringDesc* cfile0); N_NIMCALL(Ropeobj180006*, getcopyright_563665_839829468)(NimStringDesc* cfile0); N_NIMCALL(NimStringDesc*, getcompilecfilecmd_276284_2528170400)(NimStringDesc* cfilename0, NIM_BOOL isexternal0); static N_INLINE(void, addinttypes_563659_839829468)(Ropeobj180006** result0); N_NIMCALL(Ropeobj180006*, genmergeinfo_532203_2760143328)(Tcgen531027* m0); N_NIMCALL(void, generatethreadlocalstorage_540717_839829468)(Tcgen531027* m0); N_NIMCALL(void, generateheaders_562104_839829468)(Tcgen531027* m0); N_NIMCALL(NimStringDesc*, nsuReplaceChar)(NimStringDesc* s0, NIM_CHAR sub0, NIM_CHAR by0); N_NIMCALL(void, writerope_180836_2381377266)(Ropeobj180006* head0, NimStringDesc* filename0, NIM_BOOL usewarning0); N_NIMCALL(void, addfiletocompile_275863_2528170400)(NimStringDesc* filename0); N_NIMCALL(void, addfiletolink_275872_2528170400)(NimStringDesc* filename0); N_NIMCALL(void, writemodule_565637_839829468)(Tcgen531027* m0, NIM_BOOL pending0); N_NIMCALL(void, generatethreadvarssize_540771_839829468)(Tcgen531027* m0); N_NIMCALL(NIM_BOOL, shouldrecompile_565621_839829468)(Ropeobj180006* code0, NimStringDesc* cfile0); N_NIMCALL(NimStringDesc*, toobjfile_275859_2528170400)(NimStringDesc* filename0); N_NIMCALL(NIM_BOOL, writeropeifnotequal_181511_2381377266)(Ropeobj180006* r0, NimStringDesc* filename0); N_NIMCALL(NIM_BOOL, nosexistsFile)(NimStringDesc* filename0); N_NIMCALL(NIM_BOOL, nosfileNewer)(NimStringDesc* a0, NimStringDesc* b0); N_NIMCALL(void, writemapping_276789_2528170400)(Ropeobj180006* gsymbolmapping0); N_NIMCALL(void, writeheader_565152_839829468)(Tcgen531027* m0); N_NIMCALL(void, nossplitFile)(NimStringDesc* path0, TY129506* Result); N_NIMCALL(void, resetmodule_564763_839829468)(Tcgen531027* m0); N_NIMCALL(void, nullify_564833_839829468)(Ropeobj180006** arr0); N_NIMCALL(void, nullify_564858_839829468)(Ropeobj180006** arr0); STRING_LITERAL(T839829468_4, "\011", 1); STRING_LITERAL(T839829468_10, "compiler/cgen.nim", 17); NIM_CONST TY205018 T839829468_9 = {((NimStringDesc*) &T839829468_10), ((NI) 1158)} ; STRING_LITERAL(T839829468_11, "T", 1); STRING_LITERAL(T839829468_12, "_", 1); STRING_LITERAL(T839829468_13, "added pending module twice: ", 28); STRING_LITERAL(T839829468_14, ".h", 2); STRING_LITERAL(T839829468_15, ".cpp", 4); STRING_LITERAL(T839829468_16, ".m", 2); STRING_LITERAL(T839829468_17, ".c", 2); STRING_LITERAL(T839829468_18, "0", 1); STRING_LITERAL(T839829468_19, "$", 1); STRING_LITERAL(T839829468_20, "ropes: invalid format string $", 30); STRING_LITERAL(T839829468_21, "$N#line $2 $1$N", 15); STRING_LITERAL(T839829468_22, "N_LIB_IMPORT ", 13); STRING_LITERAL(T839829468_23, "N_LIB_EXPORT ", 13); STRING_LITERAL(T839829468_24, "static ", 7); STRING_LITERAL(T839829468_25, "mapType", 7); STRING_LITERAL(T839829468_26, "void", 4); STRING_LITERAL(T839829468_27, "getTypeDescAux: t == nil", 24); STRING_LITERAL(T839829468_28, "TY", 2); STRING_LITERAL(T839829468_29, "getTypeName: ", 13); STRING_LITERAL(T839829468_30, "void*", 5); STRING_LITERAL(T839829468_31, "NimStringDesc", 13); STRING_LITERAL(T839829468_32, "NimStringDesc*", 14); STRING_LITERAL(T839829468_33, "NCSTRING", 8); STRING_LITERAL(T839829468_34, "NIM_BOOL", 8); STRING_LITERAL(T839829468_35, "NIM_CHAR", 8); STRING_LITERAL(T839829468_36, "NI", 2); STRING_LITERAL(T839829468_37, "NI8", 3); STRING_LITERAL(T839829468_38, "NI16", 4); STRING_LITERAL(T839829468_39, "NI32", 4); STRING_LITERAL(T839829468_40, "NI64", 4); STRING_LITERAL(T839829468_41, "NF", 2); STRING_LITERAL(T839829468_42, "NF32", 4); STRING_LITERAL(T839829468_43, "NF64", 4); STRING_LITERAL(T839829468_44, "NF128", 5); STRING_LITERAL(T839829468_45, "NU", 2); STRING_LITERAL(T839829468_46, "NU8", 3); STRING_LITERAL(T839829468_47, "NU16", 4); STRING_LITERAL(T839829468_48, "NU32", 4); STRING_LITERAL(T839829468_49, "NU64", 4); NIM_CONST TY535943 Numericaltypetostr_535941_839829468 = {((NimStringDesc*) &T839829468_36), ((NimStringDesc*) &T839829468_37), ((NimStringDesc*) &T839829468_38), ((NimStringDesc*) &T839829468_39), ((NimStringDesc*) &T839829468_40), ((NimStringDesc*) &T839829468_41), ((NimStringDesc*) &T839829468_42), ((NimStringDesc*) &T839829468_43), ((NimStringDesc*) &T839829468_44), ((NimStringDesc*) &T839829468_45), ((NimStringDesc*) &T839829468_46), ((NimStringDesc*) &T839829468_47), ((NimStringDesc*) &T839829468_48), ((NimStringDesc*) &T839829468_49)} ; STRING_LITERAL(T839829468_50, "tyStatic for getSimpleTypeDesc", 30); STRING_LITERAL(T839829468_51, "cannot generate C type for: ", 28); STRING_LITERAL(T839829468_52, "&", 1); STRING_LITERAL(T839829468_53, "*", 1); STRING_LITERAL(T839829468_54, "$1 $2;$n", 8); STRING_LITERAL(T839829468_55, "typedef $1 $2 $2;$n", 19); STRING_LITERAL(T839829468_56, "union", 5); STRING_LITERAL(T839829468_57, "struct", 6); STRING_LITERAL(T839829468_58, "getTypeForward(", 15); STRING_LITERAL(T839829468_59, "typedef NI32 $1;$n", 18); STRING_LITERAL(T839829468_60, "typedef NU8 $1;$n", 17); STRING_LITERAL(T839829468_61, "typedef NU16 $1;$n", 18); STRING_LITERAL(T839829468_62, "typedef NI64 $1;$n", 18); STRING_LITERAL(T839829468_63, "getTypeDescAux: enum", 20); STRING_LITERAL(T839829468_64, "typedef $1_PTR($2, $3) $4;$n", 28); STRING_LITERAL(T839829468_65, "N_NIMCALL", 9); STRING_LITERAL(T839829468_66, "N_STDCALL", 9); STRING_LITERAL(T839829468_67, "N_CDECL", 7); STRING_LITERAL(T839829468_68, "N_SAFECALL", 10); STRING_LITERAL(T839829468_69, "N_SYSCALL", 9); STRING_LITERAL(T839829468_70, "N_INLINE", 8); STRING_LITERAL(T839829468_71, "N_NOINLINE", 10); STRING_LITERAL(T839829468_72, "N_FASTCALL", 10); STRING_LITERAL(T839829468_73, "N_CLOSURE", 9); STRING_LITERAL(T839829468_74, "N_NOCONV", 8); NIM_CONST TY294016 Callingconvtostr_535585_839829468 = {((NimStringDesc*) &T839829468_65), ((NimStringDesc*) &T839829468_66), ((NimStringDesc*) &T839829468_67), ((NimStringDesc*) &T839829468_68), ((NimStringDesc*) &T839829468_69), ((NimStringDesc*) &T839829468_70), ((NimStringDesc*) &T839829468_71), ((NimStringDesc*) &T839829468_72), ((NimStringDesc*) &T839829468_73), ((NimStringDesc*) &T839829468_74)} ; STRING_LITERAL(T839829468_75, "typedef struct {$nN_NIMCALL_PTR($2, ClPrc) $3;$nvoid* ClEnv;$n}" " $1;$n", 69); STRING_LITERAL(T839829468_76, "struct $2 : #TGenericSeq {$n", 28); STRING_LITERAL(T839829468_77, "struct $2 {$n #TGenericSeq Sup;$n", 34); STRING_LITERAL(T839829468_78, " $1 data[SEQ_DECL_SIZE];$n};$n", 31); STRING_LITERAL(T839829468_79, "TGenericSeq", 11); STRING_LITERAL(T839829468_80, "typedef $1 $2[$3];$n", 20); STRING_LITERAL(T839829468_81, "invalid apostrophe type parameter index", 39); STRING_LITERAL(T839829468_82, "<", 1); STRING_LITERAL(T839829468_83, " COMMA ", 7); STRING_LITERAL(T839829468_84, "> ", 2); extern NIM_CONST TY275427 Cc_275413_2528170400; STRING_LITERAL(T839829468_85, " {$n", 4); STRING_LITERAL(T839829468_86, " {$n#TNimType* m_type;$n", 24); STRING_LITERAL(T839829468_87, " : public $1 {$n", 16); STRING_LITERAL(T839829468_88, " {$n $1 Sup;$n", 15); STRING_LITERAL(T839829468_89, "genRecordFieldsAux", 18); STRING_LITERAL(T839829468_90, "$1.$2", 5); STRING_LITERAL(T839829468_91, "S", 1); STRING_LITERAL(T839829468_92, "struct {", 8); STRING_LITERAL(T839829468_93, "} $1;$n", 7); STRING_LITERAL(T839829468_94, "genRecordFieldsAux(record case branch)", 38); STRING_LITERAL(T839829468_95, "union{$n$1} $2;$n", 17); STRING_LITERAL(T839829468_96, "mangleRecFieldName", 18); STRING_LITERAL(T839829468_97, "$1 $2[SEQ_DECL_SIZE];$n", 23); STRING_LITERAL(T839829468_98, "$1 $2:$3;$n", 11); STRING_LITERAL(T839829468_99, "genRecordFieldsAux()", 20); STRING_LITERAL(T839829468_100, "char dummy;$n", 13); STRING_LITERAL(T839829468_101, "};", 2); STRING_LITERAL(T839829468_102, "$1 $2 {$n", 9); STRING_LITERAL(T839829468_103, "$1 Field$2;$n", 13); STRING_LITERAL(T839829468_104, "char dummy;", 11); STRING_LITERAL(T839829468_105, "Set", 3); STRING_LITERAL(T839829468_106, "typedef NU$2 $1;$n", 18); STRING_LITERAL(T839829468_107, "typedef NU8 $1[$2];$n", 21); STRING_LITERAL(T839829468_108, "getTypeDescAux(", 15); STRING_LITERAL(T839829468_109, "genProcParams", 13); STRING_LITERAL(T839829468_110, ", ", 2); STRING_LITERAL(T839829468_111, " ", 1); STRING_LITERAL(T839829468_112, ", NI $1Len$2", 12); STRING_LITERAL(T839829468_113, " Result", 7); STRING_LITERAL(T839829468_114, "void* ClEnv", 11); STRING_LITERAL(T839829468_115, "...", 3); STRING_LITERAL(T839829468_116, "void)", 5); STRING_LITERAL(T839829468_117, ")", 1); STRING_LITERAL(T839829468_118, "(", 1); STRING_LITERAL(T839829468_119, "$1($2, $3)$4", 12); STRING_LITERAL(T839829468_120, "proc has no result symbol", 25); STRING_LITERAL(T839829468_121, " register", 9); STRING_LITERAL(T839829468_122, " volatile", 9); STRING_LITERAL(T839829468_123, "$1 = $2;$n", 10); STRING_LITERAL(T839829468_124, "(*$1)", 5); STRING_LITERAL(T839829468_125, ";", 1); STRING_LITERAL(T839829468_126, "FR.s[$1].address = (void*)$3; FR.s[$1].typ = $4; FR.s[$1].name " "= $2;$n", 70); STRING_LITERAL(T839829468_127, "NTI$1", 5); STRING_LITERAL(T839829468_128, "(&", 2); STRING_LITERAL(T839829468_129, "TNimType", 8); STRING_LITERAL(T839829468_130, "TNimNode", 8); STRING_LITERAL(T839829468_131, "extern TNimType $1; /* $2 */$n", 30); STRING_LITERAL(T839829468_132, "0", 1); STRING_LITERAL(T839829468_133, "void*", 5); STRING_LITERAL(T839829468_134, "$1.size = sizeof($2);$n$1.kind = $3;$n$1.base = $4;$n", 53); STRING_LITERAL(T839829468_135, "$1.flags = $2;$n", 16); STRING_LITERAL(T839829468_136, "TNimType $1; /* $2 */$n", 23); STRING_LITERAL(T839829468_137, "genTypeInfo(", 12); STRING_LITERAL(T839829468_138, "$1[$2]", 6); STRING_LITERAL(T839829468_139, "static TNimNode* $1[$2];$n", 26); STRING_LITERAL(T839829468_140, "$1[$2] = &$3;$n", 15); STRING_LITERAL(T839829468_141, "$1.kind = 1;$n$1.offset = offsetof($2, Field$3);$n$1.typ = $4;$" "n$1.name = \"Field$3\";$n", 86); STRING_LITERAL(T839829468_142, "$1.len = $2; $1.kind = 2; $1.sons = &$3[0];$n", 45); STRING_LITERAL(T839829468_143, "$1.len = $2; $1.kind = 2;$n", 27); STRING_LITERAL(T839829468_144, "$1.node = &$2;$n", 16); STRING_LITERAL(T839829468_145, "#nimGCvisit((void*)$1, op);$n", 29); STRING_LITERAL(T839829468_146, "N_NIMCALL(void, $1)(void* p, NI op)", 35); STRING_LITERAL(T839829468_147, "$1 a;$n", 7); STRING_LITERAL(T839829468_148, "a = ($1)p;$n", 12); STRING_LITERAL(T839829468_149, "LOC", 3); STRING_LITERAL(T839829468_150, "$1 = ($2)0;$n", 13); STRING_LITERAL(T839829468_151, "<string.h>", 10); STRING_LITERAL(T839829468_152, "memset((void*)$1, 0, sizeof($2));$n", 35); STRING_LITERAL(T839829468_153, ".Sup", 4); STRING_LITERAL(T839829468_154, "$1.m_type = $2;$n", 17); STRING_LITERAL(T839829468_155, "#objectInit($1, $2);$n", 22); STRING_LITERAL(T839829468_156, "for ($1 = 0; $1 < $2->$3; $1++) {$n", 35); STRING_LITERAL(T839829468_157, "len", 3); STRING_LITERAL(T839829468_158, "Sup.len", 7); STRING_LITERAL(T839829468_159, "for ($1 = 0; $1 < $2; $1++) {$n", 31); STRING_LITERAL(T839829468_160, "}$n", 3); STRING_LITERAL(T839829468_161, "$1.Sup", 6); STRING_LITERAL(T839829468_162, "genTraverseProc", 15); STRING_LITERAL(T839829468_163, "switch ($1.$2) {$n", 18); STRING_LITERAL(T839829468_164, "case $1 ... $2:$n", 17); STRING_LITERAL(T839829468_165, "genLiteral: ty is nil", 21); STRING_LITERAL(T839829468_166, "(-2147483647 -1)", 16); STRING_LITERAL(T839829468_167, "IL64($1)", 8); STRING_LITERAL(T839829468_168, "(IL64(-9223372036854775807) - IL64(1))", 38); STRING_LITERAL(T839829468_169, "NIM_TRUE", 8); STRING_LITERAL(T839829468_170, "NIM_FALSE", 9); STRING_LITERAL(T839829468_171, "ULL", 3); STRING_LITERAL(T839829468_172, "(($1) $2)", 9); STRING_LITERAL(T839829468_173, "static NIM_CONST $1 $2 = {NIM_NIL,NIM_NIL};$n", 45); STRING_LITERAL(T839829468_174, "NIM_NIL", 7); STRING_LITERAL(T839829468_175, "((#NimStringDesc*) NIM_NIL)", 27); STRING_LITERAL(T839829468_176, "((#NimStringDesc*) &$1)", 23); STRING_LITERAL(T839829468_177, "STRING_LITERAL($1, $2, $3);$n", 29); STRING_LITERAL(T839829468_178, "((#NimStringDesc*) &$1$2)", 25); STRING_LITERAL(T839829468_179, "genLiteral(", 11); STRING_LITERAL(T839829468_180, "case $1:$n", 10); STRING_LITERAL(T839829468_181, "default:$n", 10); STRING_LITERAL(T839829468_182, "break;$n", 8); STRING_LITERAL(T839829468_183, "} $n", 4); STRING_LITERAL(T839829468_184, "genTraverseProc()", 17); STRING_LITERAL(T839829468_185, "$1.Field$2", 10); STRING_LITERAL(T839829468_186, "$1.ClEnv", 8); STRING_LITERAL(T839829468_187, "$1->data[$2]", 12); STRING_LITERAL(T839829468_188, "a", 1); STRING_LITERAL(T839829468_189, "(*a)", 4); STRING_LITERAL(T839829468_190, "$1 {$n$2$3$4}$n", 15); STRING_LITERAL(T839829468_191, "$1;$n", 5); STRING_LITERAL(T839829468_192, "$1.marker = $2;$n", 17); STRING_LITERAL(T839829468_193, "$1.len = $2; $1.kind = 0;$n$3.node = &$1;$n", 43); STRING_LITERAL(T839829468_194, "$1.offset = $2;$n", 17); STRING_LITERAL(T839829468_195, "NI $1;$n", 8); STRING_LITERAL(T839829468_196, "static char* NIM_CONST $1[$2] = {$n$3};$n", 41); STRING_LITERAL(T839829468_197, "for ($1 = 0; $1 < $2; $1++) {$n$3[$1+$4].kind = 1;$n$3[$1+$4].o" "ffset = $1;$n$3[$1+$4].name = $5[$1];$n$6[$1] = &$3[$1+$4];$n}$n", 127); STRING_LITERAL(T839829468_198, "$1.len = $2; $1.kind = 2; $1.sons = &$3[0];$n$4.node = &$1;$n", 61); STRING_LITERAL(T839829468_199, "$1.flags = 1<<2;$n", 18); STRING_LITERAL(T839829468_200, "anonymous obj with discriminator", 32); STRING_LITERAL(T839829468_201, "NimDT_$1_$2", 11); STRING_LITERAL(T839829468_202, "$1.kind = 3;$n$1.offset = offsetof($2, $3);$n$1.typ = $4;$n$1.n" "ame = $5;$n$1.sons = &$6[0];$n$1.len = $7;$n", 107); STRING_LITERAL(T839829468_203, "TNimNode* $1[$2];$n", 19); STRING_LITERAL(T839829468_204, "genObjectFields; nkOfBranch broken", 34); STRING_LITERAL(T839829468_205, "genObjectFields(nkRecCase)", 26); STRING_LITERAL(T839829468_206, "$1.kind = 1;$n$1.offset = offsetof($2, $3);$n$1.typ = $4;$n$1.n" "ame = $5;$n", 74); STRING_LITERAL(T839829468_207, "genObjectFields", 15); STRING_LITERAL(T839829468_208, "$1.deepcopy =(void* (N_RAW_NIMCALL*)(void*))$2;$n", 49); STRING_LITERAL(T839829468_209, "\011return $1;$n", 13); STRING_LITERAL(T839829468_210, "Result", 6); STRING_LITERAL(T839829468_211, "closure generation failed", 25); STRING_LITERAL(T839829468_212, "$1 = ($2) ClEnv;$n", 18); STRING_LITERAL(T839829468_213, "__declspec(noreturn) ", 21); STRING_LITERAL(T839829468_214, "__declspec(naked) ", 18); STRING_LITERAL(T839829468_215, "$N$1 {$n$2$3$4}$N$N", 19); STRING_LITERAL(T839829468_216, "$N$1 {$N", 8); STRING_LITERAL(T839829468_217, "struct {$1} GCFRAME;$n", 22); STRING_LITERAL(T839829468_218, "nimFrame", 8); STRING_LITERAL(T839829468_219, "VarSlot", 7); STRING_LITERAL(T839829468_220, "\011nimfrs($1, $2, $3, $4)$N", 25); STRING_LITERAL(T839829468_221, "\011nimfr($1, $2)$N", 16); STRING_LITERAL(T839829468_222, "\011#nimProfile();$n", 17); STRING_LITERAL(T839829468_223, "{", 1); STRING_LITERAL(T839829468_224, "\011}BeforeRet: ;$n", 16); STRING_LITERAL(T839829468_225, "if (((NU)&GCFRAME) < 4096) #nimGCFrame(&GCFRAME);$n", 51); STRING_LITERAL(T839829468_226, "\011#popFrame();$n", 15); STRING_LITERAL(T839829468_227, "}$N", 3); STRING_LITERAL(T839829468_228, "static void* $1;$n", 18); STRING_LITERAL(T839829468_229, "||", 2); STRING_LITERAL(T839829468_230, "($1 = #nimLoadLibrary((#NimStringDesc*) &$2))$n", 47); STRING_LITERAL(T839829468_231, "if (!($1)) #nimLoadLibraryError((#NimStringDesc*) &$2);$n", 57); STRING_LITERAL(T839829468_232, "if (!($1 = #nimLoadLibrary($2))) #nimLoadLibraryError($2);$n", 60); STRING_LITERAL(T839829468_233, "loadDynamicLib", 14); STRING_LITERAL(T839829468_234, "Dl_$1", 5); STRING_LITERAL(T839829468_235, "\011$1 = ($2) ($3$4));$n", 21); NIM_CONST TY205018 T839829468_236 = {((NimStringDesc*) &T839829468_10), ((NI) 535)} ; STRING_LITERAL(T839829468_237, "wrong index: ", 13); STRING_LITERAL(T839829468_238, "\011$1 = ($2) #nimGetProcAddr($3, $4);$n", 37); STRING_LITERAL(T839829468_239, "$2 $1;$n", 8); STRING_LITERAL(T839829468_240, "extern ", 7); STRING_LITERAL(T839829468_241, "NIM_THREADVAR ", 14); STRING_LITERAL(T839829468_242, " $1;$n", 6); STRING_LITERAL(T839829468_243, "cgsym: ", 7); STRING_LITERAL(T839829468_244, ": ", 2); STRING_LITERAL(T839829468_245, "extern $1 $2;$n", 15); STRING_LITERAL(T839829468_246, "extern \"C\" ", 11); STRING_LITERAL(T839829468_247, " __attribute__((naked))", 23); STRING_LITERAL(T839829468_248, " __attribute__((noreturn))", 26); STRING_LITERAL(T839829468_249, "#asgnRef((void**) $1, $2);$n", 28); STRING_LITERAL(T839829468_250, "#asgnRefNoCycle((void**) $1, $2);$n", 35); STRING_LITERAL(T839829468_251, "#unsureAsgnRef((void**) $1, $2);$n", 34); STRING_LITERAL(T839829468_252, "#genericSeqAssign($1, $2, $3);$n", 32); STRING_LITERAL(T839829468_253, "$1 = #copyString($2);$n", 23); STRING_LITERAL(T839829468_254, "$3 = $1; $1 = #copyStringRC1($2);$n", 35); STRING_LITERAL(T839829468_255, "if ($1) #nimGCunrefNoCycle($1);$n", 33); STRING_LITERAL(T839829468_256, "#unsureAsgnRef((void**) $1, #copyString($2));$n", 47); STRING_LITERAL(T839829468_257, ".", 1); STRING_LITERAL(T839829468_258, "ClEnv", 5); STRING_LITERAL(T839829468_259, "$1.ClPrc = $2.ClPrc;$n", 22); STRING_LITERAL(T839829468_260, "Field$1", 7); STRING_LITERAL(T839829468_261, "memcpy((void*)$1, (NIM_CONST void*)$2, sizeof($3));$n", 53); STRING_LITERAL(T839829468_262, "#genericShallowAssign((void*)$1, (void*)$2, $3);$n", 50); STRING_LITERAL(T839829468_263, "#genericAssign((void*)$1, (void*)$2, $3);$n", 43); STRING_LITERAL(T839829468_265, "compiler/ccgexprs.nim", 21); NIM_CONST TY205018 T839829468_264 = {((NimStringDesc*) &T839829468_265), ((NI) 320)} ; STRING_LITERAL(T839829468_266, "#genericAssignOpenArray((void*)$1, (void*)$2, $1Len0, $3);$n", 60); STRING_LITERAL(T839829468_267, "memcpy((void*)$1, (NIM_CONST void*)$2, sizeof($1[0])*$1Len0);$n", 63); STRING_LITERAL(T839829468_268, "memcpy((void*)$1, (NIM_CONST void*)$2, $3);$n", 45); STRING_LITERAL(T839829468_269, "genAssignment: ", 15); STRING_LITERAL(T839829468_270, "request to generate code for .compileTime proc: ", 48); STRING_LITERAL(T839829468_271, "expr: proc not init ", 20); STRING_LITERAL(T839829468_272, "NIM_CONST $1 $2 = $3;$n", 23); STRING_LITERAL(T839829468_273, "{$n", 3); STRING_LITERAL(T839829468_274, "0x$1,$n", 7); STRING_LITERAL(T839829468_275, "0x$1, ", 6); STRING_LITERAL(T839829468_276, "0x$1}$n", 7); STRING_LITERAL(T839829468_277, "{{$1, $1}", 9); STRING_LITERAL(T839829468_278, ", {", 3); STRING_LITERAL(T839829468_279, ",$n", 3); STRING_LITERAL(T839829468_280, "}", 1); STRING_LITERAL(T839829468_281, "NIM_CONST struct {$n #TGenericSeq Sup;$n $1 data[$2];$n} $3 =" " $4;$n", 69); STRING_LITERAL(T839829468_282, "(($1)&$2)", 9); STRING_LITERAL(T839829468_283, "$1,$n", 5); STRING_LITERAL(T839829468_284, "extern NIM_CONST $1 $2;$n", 25); STRING_LITERAL(T839829468_285, "expr: var not init ", 19); STRING_LITERAL(T839829468_286, "\011NimThreadVars* NimTV;$n", 24); STRING_LITERAL(T839829468_287, "\011NimTV = (NimThreadVars*) #GetThreadLocalVars();$n", 50); STRING_LITERAL(T839829468_288, "NimTV->", 7); STRING_LITERAL(T839829468_289, "expr: temp not init ", 20); STRING_LITERAL(T839829468_290, "expr: param not init ", 21); STRING_LITERAL(T839829468_291, "expr(", 5); STRING_LITERAL(T839829468_292, "); unknown symbol", 17); STRING_LITERAL(T839829468_293, "//", 2); STRING_LITERAL(T839829468_294, "#endb($1, $2);$n", 16); STRING_LITERAL(T839829468_295, "nimln($1, $2);$n", 16); STRING_LITERAL(T839829468_296, "LA", 2); STRING_LITERAL(T839829468_297, "if ($1) goto $2;$n", 18); STRING_LITERAL(T839829468_298, "if (!($1)) goto $2;$n", 21); STRING_LITERAL(T839829468_299, "$1: ;$n", 7); STRING_LITERAL(T839829468_300, "!($1)", 5); STRING_LITERAL(T839829468_301, "$1", 2); STRING_LITERAL(T839829468_302, "($3)((NU$2) ~($1))", 18); STRING_LITERAL(T839829468_303, "-($1)", 5); STRING_LITERAL(T839829468_304, "($1 > 0? ($1) : -($1))", 22); STRING_LITERAL(T839829468_305, "(($3)(NU)(NU8)($1))", 19); STRING_LITERAL(T839829468_306, "(($3)(NU64)(NU8)($1))", 21); STRING_LITERAL(T839829468_307, "(($3)(NU)(NU16)($1))", 20); STRING_LITERAL(T839829468_308, "(($3)(NU64)(NU16)($1))", 22); STRING_LITERAL(T839829468_309, "(($3)(NU64)(NU32)($1))", 22); STRING_LITERAL(T839829468_310, "(($3)(NU64)(NU)($1))", 20); STRING_LITERAL(T839829468_311, "(($3)(NU8)(NU)($1))", 19); STRING_LITERAL(T839829468_312, "(($3)(NU16)(NU)($1))", 20); STRING_LITERAL(T839829468_313, "(($3)(NU32)(NU64)($1))", 22); STRING_LITERAL(T839829468_314, "((double) ($1))", 15); STRING_LITERAL(T839829468_315, "float64ToInt32($1)", 18); STRING_LITERAL(T839829468_316, "float64ToInt64($1)", 18); NIM_CONST TY554655 unarithtab_554653_839829468 = {((NimStringDesc*) &T839829468_300), ((NimStringDesc*) &T839829468_301), ((NimStringDesc*) &T839829468_302), ((NimStringDesc*) &T839829468_301), ((NimStringDesc*) &T839829468_303), ((NimStringDesc*) &T839829468_304), ((NimStringDesc*) &T839829468_305), ((NimStringDesc*) &T839829468_306), ((NimStringDesc*) &T839829468_307), ((NimStringDesc*) &T839829468_308), ((NimStringDesc*) &T839829468_309), ((NimStringDesc*) &T839829468_310), ((NimStringDesc*) &T839829468_311), ((NimStringDesc*) &T839829468_312), ((NimStringDesc*) &T839829468_313), ((NimStringDesc*) &T839829468_314), ((NimStringDesc*) &T839829468_314), ((NimStringDesc*) &T839829468_315), ((NimStringDesc*) &T839829468_316)} ; STRING_LITERAL(T839829468_317, "if ($1 == $2) #raiseOverflow();$n", 33); STRING_LITERAL(T839829468_318, "((NI$2)-($1))", 13); NIM_CONST TY553642 opr_553640_839829468 = {((NimStringDesc*) &T839829468_318), ((NimStringDesc*) &T839829468_303), ((NimStringDesc*) &T839829468_304)} ; STRING_LITERAL(T839829468_319, "(($4)($2) $1 ($4)($3))", 22); STRING_LITERAL(T839829468_320, "+", 1); STRING_LITERAL(T839829468_321, "-", 1); STRING_LITERAL(T839829468_322, "/", 1); NIM_CONST TY558764 opr_558762_839829468 = {((NimStringDesc*) &T839829468_320), ((NimStringDesc*) &T839829468_321), ((NimStringDesc*) &T839829468_53), ((NimStringDesc*) &T839829468_322)} ; STRING_LITERAL(T839829468_323, "#nanCheck($1);$n", 16); STRING_LITERAL(T839829468_324, "#infCheck($1);$n", 16); STRING_LITERAL(T839829468_325, "(($4)($1) + ($4)($2))", 21); STRING_LITERAL(T839829468_326, "(($4)($1) - ($4)($2))", 21); STRING_LITERAL(T839829468_327, "(($4)($1) * ($4)($2))", 21); STRING_LITERAL(T839829468_328, "(($4)($1) / ($4)($2))", 21); STRING_LITERAL(T839829468_329, "($4)((NU$3)($1) >> (NU$3)($2))", 30); STRING_LITERAL(T839829468_330, "($4)((NU$3)($1) << (NU$3)($2))", 30); STRING_LITERAL(T839829468_331, "($4)($1 & $2)", 13); STRING_LITERAL(T839829468_332, "($4)($1 | $2)", 13); STRING_LITERAL(T839829468_333, "($4)($1 ^ $2)", 13); STRING_LITERAL(T839829468_334, "(($1 <= $2) ? $1 : $2)", 22); STRING_LITERAL(T839829468_335, "(($1 >= $2) ? $1 : $2)", 22); STRING_LITERAL(T839829468_336, "($4)((NU$3)($1) + (NU$3)($2))", 29); STRING_LITERAL(T839829468_337, "($4)((NU$3)($1) - (NU$3)($2))", 29); STRING_LITERAL(T839829468_338, "($4)((NU$3)($1) * (NU$3)($2))", 29); STRING_LITERAL(T839829468_339, "($4)((NU$3)($1) / (NU$3)($2))", 29); STRING_LITERAL(T839829468_340, "($4)((NU$3)($1) % (NU$3)($2))", 29); STRING_LITERAL(T839829468_341, "($1 == $2)", 10); STRING_LITERAL(T839829468_342, "($1 <= $2)", 10); STRING_LITERAL(T839829468_343, "($1 < $2)", 9); STRING_LITERAL(T839829468_344, "((NU$3)($1) <= (NU$3)($2))", 26); STRING_LITERAL(T839829468_345, "((NU$3)($1) < (NU$3)($2))", 25); STRING_LITERAL(T839829468_346, "((NU64)($1) <= (NU64)($2))", 26); STRING_LITERAL(T839829468_347, "((NU64)($1) < (NU64)($2))", 25); STRING_LITERAL(T839829468_348, "((NU8)($1) == (NU8)($2))", 24); STRING_LITERAL(T839829468_349, "((NU8)($1) <= (NU8)($2))", 24); STRING_LITERAL(T839829468_350, "((NU8)($1) < (NU8)($2))", 23); STRING_LITERAL(T839829468_351, "($1 != $2)", 10); NIM_CONST TY553828 binarithtab_553826_839829468 = {((NimStringDesc*) &T839829468_325), ((NimStringDesc*) &T839829468_326), ((NimStringDesc*) &T839829468_327), ((NimStringDesc*) &T839829468_328), ((NimStringDesc*) &T839829468_329), ((NimStringDesc*) &T839829468_330), ((NimStringDesc*) &T839829468_331), ((NimStringDesc*) &T839829468_332), ((NimStringDesc*) &T839829468_333), ((NimStringDesc*) &T839829468_334), ((NimStringDesc*) &T839829468_335), ((NimStringDesc*) &T839829468_334), ((NimStringDesc*) &T839829468_335), ((NimStringDesc*) &T839829468_336), ((NimStringDesc*) &T839829468_337), ((NimStringDesc*) &T839829468_338), ((NimStringDesc*) &T839829468_339), ((NimStringDesc*) &T839829468_340), ((NimStringDesc*) &T839829468_341), ((NimStringDesc*) &T839829468_342), ((NimStringDesc*) &T839829468_343), ((NimStringDesc*) &T839829468_341), ((NimStringDesc*) &T839829468_342), ((NimStringDesc*) &T839829468_343), ((NimStringDesc*) &T839829468_344), ((NimStringDesc*) &T839829468_345), ((NimStringDesc*) &T839829468_346), ((NimStringDesc*) &T839829468_347), ((NimStringDesc*) &T839829468_341), ((NimStringDesc*) &T839829468_342), ((NimStringDesc*) &T839829468_343), ((NimStringDesc*) &T839829468_348), ((NimStringDesc*) &T839829468_349), ((NimStringDesc*) &T839829468_350), ((NimStringDesc*) &T839829468_341), ((NimStringDesc*) &T839829468_342), ((NimStringDesc*) &T839829468_343), ((NimStringDesc*) &T839829468_341), ((NimStringDesc*) &T839829468_341), ((NimStringDesc*) &T839829468_342), ((NimStringDesc*) &T839829468_343), ((NimStringDesc*) &T839829468_351)} ; STRING_LITERAL(T839829468_352, "($1.ClPrc == $2.ClPrc && $1.ClEnv == $2.ClEnv)", 46); STRING_LITERAL(T839829468_353, "($#)($# + $#)", 13); STRING_LITERAL(T839829468_354, "($#)($# - $#)", 13); STRING_LITERAL(T839829468_355, "($#)($# * $#)", 13); STRING_LITERAL(T839829468_356, "($#)($# / $#)", 13); STRING_LITERAL(T839829468_357, "($#)($# % $#)", 13); NIM_CONST TY553281 opr_553279_839829468 = {((NimStringDesc*) &T839829468_353), ((NimStringDesc*) &T839829468_354), ((NimStringDesc*) &T839829468_355), ((NimStringDesc*) &T839829468_356), ((NimStringDesc*) &T839829468_357), ((NimStringDesc*) &T839829468_353), ((NimStringDesc*) &T839829468_354)} ; STRING_LITERAL(T839829468_358, "((NU8)($1))", 11); STRING_LITERAL(T839829468_359, "if ($1 < $2 || $1 > $3) #raiseOverflow();$n", 43); STRING_LITERAL(T839829468_360, "$# = #addInt64($#, $#);$n", 25); STRING_LITERAL(T839829468_361, "$# = #subInt64($#, $#);$n", 25); STRING_LITERAL(T839829468_362, "$# = #mulInt64($#, $#);$n", 25); STRING_LITERAL(T839829468_363, "$# = #divInt64($#, $#);$n", 25); STRING_LITERAL(T839829468_364, "$# = #modInt64($#, $#);$n", 25); NIM_CONST TY553281 prc64_553274_839829468 = {((NimStringDesc*) &T839829468_360), ((NimStringDesc*) &T839829468_361), ((NimStringDesc*) &T839829468_362), ((NimStringDesc*) &T839829468_363), ((NimStringDesc*) &T839829468_364), ((NimStringDesc*) &T839829468_360), ((NimStringDesc*) &T839829468_361)} ; STRING_LITERAL(T839829468_365, "$# = #addInt($#, $#);$n", 23); STRING_LITERAL(T839829468_366, "$# = #subInt($#, $#);$n", 23); STRING_LITERAL(T839829468_367, "$# = #mulInt($#, $#);$n", 23); STRING_LITERAL(T839829468_368, "$# = #divInt($#, $#);$n", 23); STRING_LITERAL(T839829468_369, "$# = #modInt($#, $#);$n", 23); NIM_CONST TY553281 prc_553269_839829468 = {((NimStringDesc*) &T839829468_365), ((NimStringDesc*) &T839829468_366), ((NimStringDesc*) &T839829468_367), ((NimStringDesc*) &T839829468_368), ((NimStringDesc*) &T839829468_369), ((NimStringDesc*) &T839829468_365), ((NimStringDesc*) &T839829468_366)} ; STRING_LITERAL(T839829468_370, "($#)($#)", 8); STRING_LITERAL(T839829468_371, "#reprInt((NI64)$1)", 18); STRING_LITERAL(T839829468_372, "#reprFloat($1)", 14); STRING_LITERAL(T839829468_373, "#reprBool($1)", 13); STRING_LITERAL(T839829468_374, "#reprChar($1)", 13); STRING_LITERAL(T839829468_375, "#reprEnum((NI)$1, $2)", 21); STRING_LITERAL(T839829468_376, "#reprStr($1)", 12); STRING_LITERAL(T839829468_377, "#reprSet($1, $2)", 16); STRING_LITERAL(T839829468_378, "$1, $1Len0", 10); STRING_LITERAL(T839829468_379, "$1->data, $1->$2", 16); STRING_LITERAL(T839829468_380, "$1, $2", 6); STRING_LITERAL(T839829468_381, "genRepr()", 9); STRING_LITERAL(T839829468_382, "#reprOpenArray($1, $2)", 22); STRING_LITERAL(T839829468_383, "#reprAny($1, $2)", 16); STRING_LITERAL(T839829468_384, "\'repr\' doesn\'t support \'void\' type", 34); STRING_LITERAL(T839829468_385, "($1 - 1)", 8); STRING_LITERAL(T839829468_386, "#subInt($1, 1)", 14); STRING_LITERAL(T839829468_387, "binaryStmt", 10); STRING_LITERAL(T839829468_388, "$1 += $2;$n", 11); STRING_LITERAL(T839829468_389, "$1 -= $2;$n", 11); NIM_CONST TY559052 opr_559050_839829468 = {((NimStringDesc*) &T839829468_388), ((NimStringDesc*) &T839829468_389)} ; NIM_CONST TY559052 fun64_559055_839829468 = {((NimStringDesc*) &T839829468_360), ((NimStringDesc*) &T839829468_361)} ; NIM_CONST TY559052 fun_559060_839829468 = {((NimStringDesc*) &T839829468_365), ((NimStringDesc*) &T839829468_366)} ; STRING_LITERAL(T839829468_390, "#appendChar($1, $2);$n", 22); STRING_LITERAL(T839829468_391, "$1->$2 + ", 9); STRING_LITERAL(T839829468_392, "#appendString($1, $2);$n", 24); STRING_LITERAL(T839829468_393, "$1 = #rawNewString($2$3);$n", 27); STRING_LITERAL(T839829468_394, "$1 = #addChar($1, $2);$n", 24); STRING_LITERAL(T839829468_395, "$1 = #resizeString($1, $2$3);$n", 31); STRING_LITERAL(T839829468_396, "$1 = ($2) #incrSeqV2(&($1)->Sup, sizeof($3));$n", 47); STRING_LITERAL(T839829468_397, "$1 = ($2) #incrSeqV2($1, sizeof($3));$n", 39); STRING_LITERAL(T839829468_398, "$1->data[$1->$2]", 16); STRING_LITERAL(T839829468_399, "++$1->$2;$n", 11); STRING_LITERAL(T839829468_400, "(($1) && ($1)->$2 == 0)", 23); STRING_LITERAL(T839829468_401, "#eqStrings($1, $2)", 18); STRING_LITERAL(T839829468_402, "(#cmpStrings($1, $2) <= 0)", 26); STRING_LITERAL(T839829468_403, "(#cmpStrings($1, $2) < 0)", 25); STRING_LITERAL(T839829468_404, "$1.ClPrc == 0", 13); STRING_LITERAL(T839829468_405, "$1 == 0", 7); STRING_LITERAL(T839829468_406, "#nimIntToStr($1)", 16); STRING_LITERAL(T839829468_407, "#nimInt64ToStr($1)", 18); STRING_LITERAL(T839829468_408, "#nimBoolToStr($1)", 17); STRING_LITERAL(T839829468_409, "#nimCharToStr($1)", 17); STRING_LITERAL(T839829468_410, "#nimFloatToStr($1)", 18); STRING_LITERAL(T839829468_411, "#cstrToNimstr($1)", 17); STRING_LITERAL(T839829468_412, "no \'of\' operator available for pure objects", 43); STRING_LITERAL(T839829468_413, "(($1) && ($2))", 14); STRING_LITERAL(T839829468_414, "$1.m_type == $2", 15); STRING_LITERAL(T839829468_415, "Nim_OfCheck_CACHE", 17); STRING_LITERAL(T839829468_416, "static TNimType* $#[2];$n", 25); STRING_LITERAL(T839829468_417, "#isObjWithCache($#.m_type, $#, $#)", 34); STRING_LITERAL(T839829468_418, "($1)", 4); STRING_LITERAL(T839829468_419, "sizeof($1)", 10); STRING_LITERAL(T839829468_420, "if ($1) #nimGCunref($1);$n", 26); STRING_LITERAL(T839829468_421, "($1) #newObjRC1($2, $3)", 23); STRING_LITERAL(T839829468_422, "($1) #newObj($2, $3)", 20); STRING_LITERAL(T839829468_423, "$1->finalizer = (void*)$2;$n", 28); STRING_LITERAL(T839829468_424, "($1) #newObj($2, sizeof($3))", 28); STRING_LITERAL(T839829468_425, "($1) #newSeqRC1($2, $3)", 23); STRING_LITERAL(T839829468_426, "($1) #newSeq($2, $3)", 20); STRING_LITERAL(T839829468_427, "($1)#nimNewSeqOfCap($2, $3)", 27); STRING_LITERAL(T839829468_428, "((NI)sizeof($1))", 16); STRING_LITERAL(T839829468_429, "(*($1*) ($2))", 13); STRING_LITERAL(T839829468_430, "(($1) ($2))", 11); STRING_LITERAL(T839829468_431, "($1Len0-1)", 10); STRING_LITERAL(T839829468_432, "$1Len0", 6); STRING_LITERAL(T839829468_433, "($1 ? (strlen($1)-1) : -1)", 26); STRING_LITERAL(T839829468_434, "($1 ? strlen($1) : 0)", 21); STRING_LITERAL(T839829468_435, "($1 ? ($1->Sup.len-1) : -1)", 27); STRING_LITERAL(T839829468_436, "($1 ? $1->Sup.len : 0)", 22); STRING_LITERAL(T839829468_437, "($1 ? ($1->len-1) : -1)", 23); STRING_LITERAL(T839829468_438, "($1 ? $1->len : 0)", 18); STRING_LITERAL(T839829468_439, "genArrayLen()", 13); STRING_LITERAL(T839829468_440, "($1->Sup.len)", 13); STRING_LITERAL(T839829468_441, "$1->len", 7); STRING_LITERAL(T839829468_442, "unaryStmt", 9); STRING_LITERAL(T839829468_443, "#nimGCref($1);$n", 16); STRING_LITERAL(T839829468_444, "#nimGCunref($1);$n", 18); STRING_LITERAL(T839829468_445, "$1 = #setLengthStr($1, $2);$n", 29); STRING_LITERAL(T839829468_446, "$1 = ($3) #setLengthSeq(&($1)->Sup, sizeof($4), $2);$n", 54); STRING_LITERAL(T839829468_447, "$1 = ($3) #setLengthSeq($1, sizeof($4), $2);$n", 46); STRING_LITERAL(T839829468_448, "($1- $2)", 8); STRING_LITERAL(T839829468_449, "$1 |= ((", 8); STRING_LITERAL(T839829468_450, ")1)<<(($2)%(sizeof(", 19); STRING_LITERAL(T839829468_451, ")*8));$n", 8); STRING_LITERAL(T839829468_452, "$1 &= ~(((", 10); STRING_LITERAL(T839829468_453, ")1) << (($2) % (sizeof(", 23); STRING_LITERAL(T839829468_454, ")*8)));$n", 9); STRING_LITERAL(T839829468_455, "#countBits32($1)", 16); STRING_LITERAL(T839829468_456, "#countBits64($1)", 16); STRING_LITERAL(T839829468_457, "(($1 & ~ $2 ==0)&&($1 != $2))", 29); STRING_LITERAL(T839829468_458, "(($1 & ~ $2)==0)", 16); STRING_LITERAL(T839829468_459, "($1 & $2)", 9); STRING_LITERAL(T839829468_460, "($1 | $2)", 9); STRING_LITERAL(T839829468_461, "($1 & ~ $2)", 11); STRING_LITERAL(T839829468_462, "($1 ^ $2)", 9); STRING_LITERAL(T839829468_463, "fewCmps", 7); STRING_LITERAL(T839829468_464, "$1 >= $2 && $1 <= $3", 20); STRING_LITERAL(T839829468_465, "$1 == $2", 8); STRING_LITERAL(T839829468_466, " || ", 4); STRING_LITERAL(T839829468_467, "(($1 &(1U<<((NU)($2)&7U)))!=0)", 30); STRING_LITERAL(T839829468_468, "(($1 &(1U<<((NU)($2)&15U)))!=0)", 31); STRING_LITERAL(T839829468_469, "(($1 &(1U<<((NU)($2)&31U)))!=0)", 31); STRING_LITERAL(T839829468_470, "(($1 &((NU64)1<<((NU)($2)&63U)))!=0)", 36); STRING_LITERAL(T839829468_471, "(($1[(NU)($2)>>3] &(1U<<((NU)($2)&7U)))!=0)", 43); STRING_LITERAL(T839829468_472, "genSetOp()", 10); STRING_LITERAL(T839829468_473, "$1[(NU)($2)>>3] |=(1U<<($2&7U));$n", 34); STRING_LITERAL(T839829468_474, "$1[(NU)($2)>>3] &= ~(1U<<($2&7U));$n", 36); STRING_LITERAL(T839829468_475, "#cardSet($1, ", 13); STRING_LITERAL(T839829468_476, "for ($1 = 0; $1 < $2; $1++) { $n $3 = (($4[$1] & ~ $5[$1]) == " "0);$n if (!$3) break;}$n", 88); STRING_LITERAL(T839829468_477, "for ($1 = 0; $1 < $2; $1++) { $n $3 = (($4[$1] & ~ $5[$1]) == " "0);$n if (!$3) break;}$nif ($3) $3 = (memcmp($4, $5, $2) != 0);" "$n", 129); STRING_LITERAL(T839829468_478, "|", 1); STRING_LITERAL(T839829468_479, "& ~", 3); STRING_LITERAL(T839829468_480, "^", 1); NIM_CONST TY558428 lookupopr_558426_839829468 = {((NimStringDesc*) &T839829468_476), ((NimStringDesc*) &T839829468_477), ((NimStringDesc*) &T839829468_52), ((NimStringDesc*) &T839829468_478), ((NimStringDesc*) &T839829468_479), ((NimStringDesc*) &T839829468_480)} ; STRING_LITERAL(T839829468_481, "(memcmp($1, $2, ", 16); STRING_LITERAL(T839829468_482, ")==0)", 5); STRING_LITERAL(T839829468_483, "for ($1 = 0; $1 < $2; $1++) $n $3[$1] = $4[$1] $6 $5[$1];$n", 60); STRING_LITERAL(T839829468_484, "genSetOp", 8); STRING_LITERAL(T839829468_485, "$1->data", 8); STRING_LITERAL(T839829468_486, "($1)+($2), ($3)-($2)+1", 22); STRING_LITERAL(T839829468_487, "(*$1)->data+($2), ($3)-($2)+1", 29); STRING_LITERAL(T839829468_488, "$1->data+($2), ($3)-($2)+1", 26); STRING_LITERAL(T839829468_489, "openArrayLoc: ", 14); STRING_LITERAL(T839829468_490, "", 0); STRING_LITERAL(T839829468_491, "(*$1)->data, (*$1)->$2", 22); STRING_LITERAL(T839829468_492, "$1.ClPrc($3$1.ClEnv)", 20); STRING_LITERAL(T839829468_493, "$1.ClEnv? $1.ClPrc($3$1.ClEnv):(($4)($1.ClPrc))($2)", 51); STRING_LITERAL(T839829468_494, "$1 = 0;$n", 9); STRING_LITERAL(T839829468_495, "#chckNil((void*)$1);$n", 22); STRING_LITERAL(T839829468_496, "#genericReset((void*)$1, $2);$n", 31); STRING_LITERAL(T839829468_497, ";$n", 3); STRING_LITERAL(T839829468_499, "compiler/ccgcalls.nim", 21); NIM_CONST TY205018 T839829468_498 = {((NimStringDesc*) &T839829468_499), ((NI) 423)} ; static NIM_CONST char136Set T839829468_500 = { 0x00, 0x00, 0x00, 0x00, 0x88, 0x01, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00} ; STRING_LITERAL(T839829468_501, "wrong argument count", 20); STRING_LITERAL(T839829468_502, "call expression expected for C++ pattern", 40); NIM_CONST TY205018 T839829468_503 = {((NimStringDesc*) &T839829468_499), ((NI) 328)} ; STRING_LITERAL(T839829468_504, "->", 2); STRING_LITERAL(T839829468_505, ");$n", 4); STRING_LITERAL(T839829468_506, "[", 1); NIM_CONST TY205018 T839829468_507 = {((NimStringDesc*) &T839829468_499), ((NI) 472)} ; STRING_LITERAL(T839829468_508, "varargs for objective C method?", 31); STRING_LITERAL(T839829468_509, "Result: ", 8); STRING_LITERAL(T839829468_510, "];$n", 4); STRING_LITERAL(T839829468_511, "]", 1); NIM_CONST TY205018 T839829468_512 = {((NimStringDesc*) &T839829468_265), ((NI) 925)} ; STRING_LITERAL(T839829468_513, "<stdio.h>", 9); STRING_LITERAL(T839829468_514, ", \"nil\"", 7); STRING_LITERAL(T839829468_515, ", $1? ($1)->data:\"nil\"", 22); STRING_LITERAL(T839829468_516, "printf($1$2);$n", 15); STRING_LITERAL(T839829468_517, "%s", 2); STRING_LITERAL(T839829468_518, "fflush(stdout);$n", 17); STRING_LITERAL(T839829468_519, "#genericDeepCopy((void*)$1, (void*)$2, $3);$n", 45); STRING_LITERAL(T839829468_520, "#genericSeqDeepCopy($1, $2, $3);$n", 34); STRING_LITERAL(T839829468_521, "#genericDeepCopyOpenArray((void*)$1, (void*)$2, $1Len0, $3);$n", 62); STRING_LITERAL(T839829468_522, "genDeepCopy: ", 13); STRING_LITERAL(T839829468_523, "genMagicExpr: ", 14); STRING_LITERAL(T839829468_524, "static NIM_CONST $1 $2 = $3;$n", 30); STRING_LITERAL(T839829468_525, "memset($1, 0, sizeof($1));$n", 28); STRING_LITERAL(T839829468_526, "for ($1 = $3; $1 <= $4; $1++) $n$2[(NU)($1)>>3] |=(1U<<((NU)($1" ")&7U));$n", 72); STRING_LITERAL(T839829468_527, "$1[(NU)($2)>>3] |=(1U<<((NU)($2)&7U));$n", 40); STRING_LITERAL(T839829468_528, "for ($1 = $3; $1 <= $4; $1++) $n$2 |=((", 39); STRING_LITERAL(T839829468_529, ")(1)<<(($1)%(sizeof(", 20); STRING_LITERAL(T839829468_530, "$1 |=((", 7); STRING_LITERAL(T839829468_531, ")(1)<<(($2)%(sizeof(", 20); STRING_LITERAL(T839829468_532, "genCheckedRecordField", 21); STRING_LITERAL(T839829468_533, "genObjConstr", 12); STRING_LITERAL(T839829468_534, "if ($1) #raiseFieldError(((#NimStringDesc*) &$2));$n", 52); STRING_LITERAL(T839829468_535, "if (!($1)) #raiseFieldError(((#NimStringDesc*) &$2));$n", 55); STRING_LITERAL(T839829468_536, "LOC$1.source", 12); STRING_LITERAL(T839829468_537, "union { $1 source; $2 dest; } LOC$3;$n", 38); STRING_LITERAL(T839829468_538, "LOC$#.dest", 10); STRING_LITERAL(T839829468_539, "if ((NU)($1) > (NU)($2)) #raiseIndexError();$n", 46); STRING_LITERAL(T839829468_540, "if ($1 < $2 || $1 > $3) #raiseIndexError();$n", 45); STRING_LITERAL(T839829468_541, "$1[($2)- $3]", 12); STRING_LITERAL(T839829468_542, "if ((NU)($1) >= (NU)($2Len0)) #raiseIndexError();$n", 51); STRING_LITERAL(T839829468_543, "if ((NU)($1) > (NU)($2->$3)) #raiseIndexError();$n", 50); STRING_LITERAL(T839829468_544, "if ((NU)($1) >= (NU)($2->$3)) #raiseIndexError();$n", 51); STRING_LITERAL(T839829468_545, "genTupleElem", 12); STRING_LITERAL(T839829468_546, ".Field$1", 8); STRING_LITERAL(T839829468_547, "expr(nkBracketExpr, ", 20); STRING_LITERAL(T839829468_548, "genDeref ", 9); STRING_LITERAL(T839829468_549, "genRecordFieldAux", 17); STRING_LITERAL(T839829468_550, "genRecordField 3", 16); STRING_LITERAL(T839829468_551, ".$1", 3); STRING_LITERAL(T839829468_552, "} $1: ;$n", 9); STRING_LITERAL(T839829468_553, "FR.len-=$1;$n", 13); STRING_LITERAL(T839829468_554, "FR.len+=$1;$n", 13); STRING_LITERAL(T839829468_555, "if (!$1) goto $2;$n", 19); STRING_LITERAL(T839829468_556, "goto $1;$n", 10); STRING_LITERAL(T839829468_557, "genIf()", 7); STRING_LITERAL(T839829468_558, "->Sup", 5); STRING_LITERAL(T839829468_559, "$1 = &$2;$n", 11); STRING_LITERAL(T839829468_560, "if ($1) #chckObj($2.m_type, $3);$n", 34); STRING_LITERAL(T839829468_561, "#chckObj($1.m_type, $2);$n", 26); STRING_LITERAL(T839829468_562, "(($1)#$5($2, $3, $4))", 21); STRING_LITERAL(T839829468_563, "chckRangeF", 10); STRING_LITERAL(T839829468_564, "chckRange64", 11); STRING_LITERAL(T839829468_565, "chckRange", 9); STRING_LITERAL(T839829468_566, "CNSTCLOSURE", 11); STRING_LITERAL(T839829468_567, "closure to closure created", 26); STRING_LITERAL(T839829468_568, "$1.ClPrc = $2; $1.ClEnv = $3;$n", 31); STRING_LITERAL(T839829468_569, "while (1) {$n", 13); STRING_LITERAL(T839829468_570, "case statement must be exhaustive for computed goto", 51); STRING_LITERAL(T839829468_571, "case statement has too many cases for computed goto", 51); STRING_LITERAL(T839829468_572, "case statement has to start at 0 for computed goto", 50); STRING_LITERAL(T839829468_573, "no case statement found for computed goto", 41); STRING_LITERAL(T839829468_574, "TMP$1", 5); STRING_LITERAL(T839829468_575, "static void* $#[$#] = {", 23); STRING_LITERAL(T839829468_576, "&&TMP$#, ", 9); STRING_LITERAL(T839829468_577, "&&TMP$#};$n", 11); STRING_LITERAL(T839829468_578, "goto *$#[$#];$n", 15); STRING_LITERAL(T839829468_579, "range notation not available for computed goto", 46); STRING_LITERAL(T839829468_580, "TMP$#:$n", 8); STRING_LITERAL(T839829468_581, "#nimProfile();$n", 16); STRING_LITERAL(T839829468_582, "\'goto\' target must be a literal value", 37); STRING_LITERAL(T839829468_583, "goto NIMSTATE_$#;$n", 19); STRING_LITERAL(T839829468_584, "$1 = ($2*) #nimGetProcAddr($3, $4);$n", 37); STRING_LITERAL(T839829468_585, "$2* $1;$n", 9); STRING_LITERAL(T839829468_586, "#dbgRegisterGlobal($1, &$2, $3);$n", 34); STRING_LITERAL(T839829468_587, "#nimGCvisit((void*)$1, 0);$n", 28); STRING_LITERAL(T839829468_588, "N_NIMCALL(void, $1)(void)", 25); STRING_LITERAL(T839829468_589, "#nimRegisterGlobalMarker($1);$n", 31); STRING_LITERAL(T839829468_590, "$#($#);$n", 9); STRING_LITERAL(T839829468_591, "$# = $#;$n", 10); STRING_LITERAL(T839829468_592, "genVarTuple", 11); STRING_LITERAL(T839829468_593, "genConstStmt", 12); STRING_LITERAL(T839829468_594, "for statement not eliminated", 28); STRING_LITERAL(T839829468_595, "if (#eqStrings($1, $2)) goto $3;$n", 34); STRING_LITERAL(T839829468_596, "switch (#hashString($1) & $2) {$n", 33); STRING_LITERAL(T839829468_597, "case $1: $n$2break;$n", 21); STRING_LITERAL(T839829468_598, "goto LA$1;$n", 12); STRING_LITERAL(T839829468_599, "LA$1: ;$n", 9); STRING_LITERAL(T839829468_600, "if ($1 >= $2 && $1 <= $3) goto $4;$n", 36); STRING_LITERAL(T839829468_601, "if ($1 == $2) goto $3;$n", 24); STRING_LITERAL(T839829468_602, "NIMSTATE_$#:$n", 14); STRING_LITERAL(T839829468_603, "switch ($1) {$n", 15); STRING_LITERAL(T839829468_604, "default: __assume(0);$n", 23); STRING_LITERAL(T839829468_605, "#popSafePoint();$n", 18); STRING_LITERAL(T839829468_606, "#popCurrentException();$n", 25); STRING_LITERAL(T839829468_607, "if ($1.status != 0) #popCurrentException();$n", 45); STRING_LITERAL(T839829468_608, "goto BeforeRet;$n", 17); STRING_LITERAL(T839829468_609, "no loop to break", 16); STRING_LITERAL(T839829468_610, "extern $1", 9); STRING_LITERAL(T839829468_611, "#FieldDiscriminantCheck((NI)(NU)($1), (NI)(NU)($2), $3, $4);$n", 62); STRING_LITERAL(T839829468_612, "genAsmOrEmitStmt()", 18); STRING_LITERAL(T839829468_613, "\"", 1); STRING_LITERAL(T839829468_614, "\\n\"\012", 4); STRING_LITERAL(T839829468_615, "Exception", 9); STRING_LITERAL(T839829468_616, "E_Base", 6); STRING_LITERAL(T839829468_617, "try {$n", 7); STRING_LITERAL(T839829468_618, "} catch (NimException& $1) {$n", 30); STRING_LITERAL(T839829468_619, "#setFrame((TFrame*)&FR);$n", 26); STRING_LITERAL(T839829468_620, "else ", 5); STRING_LITERAL(T839829468_621, "#isObj($1.exp->m_type, $2)", 26); STRING_LITERAL(T839829468_622, "if ($1) ", 8); STRING_LITERAL(T839829468_623, "throw;$n", 8); STRING_LITERAL(T839829468_624, "<setjmp.h>", 10); STRING_LITERAL(T839829468_625, "#TSafePoint $1;$n", 17); STRING_LITERAL(T839829468_626, "#pushSafePoint(&$1);$n", 22); STRING_LITERAL(T839829468_627, "nimStdSetjmp", 12); STRING_LITERAL(T839829468_628, "$1.status = setjmp($1.context);$n", 33); STRING_LITERAL(T839829468_629, "nimSigSetjmp", 12); STRING_LITERAL(T839829468_630, "$1.status = sigsetjmp($1.context, 0);$n", 39); STRING_LITERAL(T839829468_631, "nimRawSetjmp", 12); STRING_LITERAL(T839829468_632, "$1.status = _setjmp($1.context);$n", 34); STRING_LITERAL(T839829468_633, "if ($1.status == 0) {$n", 23); STRING_LITERAL(T839829468_634, "else {$n", 8); STRING_LITERAL(T839829468_635, "else", 4); STRING_LITERAL(T839829468_636, "$1.status = 0;$n", 16); STRING_LITERAL(T839829468_637, "#isObj(#getCurrentException()->Sup.m_type, $1)", 46); STRING_LITERAL(T839829468_638, "#isObj(#getCurrentException()->m_type, $1)", 42); STRING_LITERAL(T839829468_639, "if ($1) {$n", 11); STRING_LITERAL(T839829468_640, "if ($1.status != 0) #reraiseException();$n", 42); STRING_LITERAL(T839829468_641, "#raiseException((#Exception*)$1, $2);$n", 39); STRING_LITERAL(T839829468_642, "#reraiseException();$n", 22); STRING_LITERAL(T839829468_643, "/*TYPESECTION*/", 15); STRING_LITERAL(T839829468_644, "/*VARSECTION*/", 14); STRING_LITERAL(T839829468_645, "/*INCLUDESECTION*/", 18); STRING_LITERAL(T839829468_646, "bp", 2); STRING_LITERAL(T839829468_647, "#dbgRegisterBreakpoint($1, (NCSTRING)$2, (NCSTRING)$3);$n", 57); STRING_LITERAL(T839829468_648, "#dbgRegisterWatchpoint($1, (NCSTRING)$2, $3);$n", 47); STRING_LITERAL(T839829468_649, "#pragma omp parallel for $4$nfor ($1 = $2; $1 <= $3; ++$1)", 58); STRING_LITERAL(T839829468_651, "compiler/ccgstmts.nim", 21); NIM_CONST TY205018 T839829468_650 = {((NimStringDesc*) &T839829468_651), ((NI) 145)} ; STRING_LITERAL(T839829468_652, "STATE$1: ;$n", 12); STRING_LITERAL(T839829468_653, "case -1: goto BeforeRet;$n", 26); STRING_LITERAL(T839829468_654, "case $1: goto STATE$1;$n", 24); STRING_LITERAL(T839829468_655, "if (((NI*) $1)[0] < 0) break;$n", 31); STRING_LITERAL(T839829468_656, "if ((((NI*) $1.ClEnv)[0]) < 0) break;$n", 39); STRING_LITERAL(T839829468_657, "); unknown node kind", 20); NIM_CONST TY205018 T839829468_658 = {((NimStringDesc*) &T839829468_651), ((NI) 1122)} ; STRING_LITERAL(T839829468_659, "Init000", 7); STRING_LITERAL(T839829468_660, "DatInit000", 10); STRING_LITERAL(T839829468_661, "NIM_EXTERNC N_NOINLINE(void, $1)(void);$N", 41); STRING_LITERAL(T839829468_662, "\011$1();$N", 8); STRING_LITERAL(T839829468_663, "N_CDECL(void, NimMainInner)(void) {$N$1}$N$NN_CDECL(void, NimMa" "in)(void) {$N\011void (*volatile inner)();$N\011PreMain();$N\011inner = N" "imMainInner;$N$2\011(*inner)();$N}$N$N", 162); STRING_LITERAL(T839829468_664, "N_STDCALL(int, WinMain)(HINSTANCE hCurInstance, $N " " HINSTANCE hPrevInstance, $N LP" "STR lpCmdLine, int nCmdShow) {$N\011NimMain();$N\011return nim_program" "_result;$N}$N$N", 206); STRING_LITERAL(T839829468_665, "N_LIB_EXPORT N_CDECL(void, NimMainInner)(void) {$N$1}$N$NN_CDEC" "L(void, NimMain)(void) {$N\011void (*volatile inner)();$N\011PreMain()" ";$N\011inner = NimMainInner;$N$2\011(*inner)();$N}$N$N", 175); STRING_LITERAL(T839829468_666, "BOOL WINAPI DllMain(HINSTANCE hinstDLL, DWORD fwdreason, $N " " LPVOID lpvReserved) {$N\011if(fwdreason == DLL_PROC" "ESS_ATTACH) {$N\011NimMain();$N}$N\011return 1;$N}$N$N", 175); STRING_LITERAL(T839829468_667, "<windows.h>", 11); STRING_LITERAL(T839829468_668, "void NIM_POSIX_INIT NimMainInit(void) {$N\011NimMain();$N}$N$N", 59); STRING_LITERAL(T839829468_669, "int cmdCount;$Nchar** cmdLine;$Nchar** gEnv;$NN_CDECL(void, Nim" "MainInner)(void) {$N$1}$N$NN_CDECL(void, NimMain)(void) {$N\011void" " (*volatile inner)();$N\011PreMain();$N\011inner = NimMainInner;$N$2\011(" "*inner)();$N}$N$N", 208); STRING_LITERAL(T839829468_670, "int main(void) {$N\011NimMain();$N\011return 0;$N}$N$N", 48); STRING_LITERAL(T839829468_671, "int main(int argc, char** args, char** env) {$N\011cmdLine = args;" "$N\011cmdCount = argc;$N\011gEnv = env;$N\011NimMain();$N\011return nim_prog" "ram_result;$N}$N$N", 145); STRING_LITERAL(T839829468_672, "dbgRegisterBreakpoint", 21); STRING_LITERAL(T839829468_673, "dbgRegisterFilename", 19); STRING_LITERAL(T839829468_674, "dbgRegisterFilename($1);$N", 26); STRING_LITERAL(T839829468_675, "\011#initStackBottomWith((void *)&inner);$N", 40); STRING_LITERAL(T839829468_676, "void PreMainInner() {$N\011systemInit000();$N$1$2$3}$N$Nvoid PreMa" "in() {$N\011void (*volatile inner)();$N\011systemDatInit000();$N\011inner" " = PreMainInner;$N$4$5\011(*inner)();$N}$N$N", 168); STRING_LITERAL(T839829468_677, "\011#initThreadVarsEmulation();$N", 30); STRING_LITERAL(T839829468_678, "still forwarded: ", 17); STRING_LITERAL(T839829468_679, "NIM_EXTERNC N_NOINLINE(void, $1)(void) {$N", 42); STRING_LITERAL(T839829468_680, "static #TNimNode $1[$2];$n", 26); STRING_LITERAL(T839829468_681, "static #TNimType $1[$2];$n", 26); STRING_LITERAL(T839829468_682, "\011TFrame FR; FR.len = 0;$N", 25); STRING_LITERAL(T839829468_683, "}$N$N", 5); STRING_LITERAL(T839829468_684, "N_NIMCALL(void, nimLoadProcs$1)(void) {$2}$N$N", 46); STRING_LITERAL(T839829468_685, "/* Generated by Nim Compiler v$1 */$N/* (c) 2016 Andreas Rump" "f */$N/* The generated code is subject to the original license. " "*/$N", 131); STRING_LITERAL(T839829468_686, "0.15.0", 6); STRING_LITERAL(T839829468_687, "/* Generated by Nim Compiler v$1 */$N/* (c) 2016 Andreas Rump" "f */$N/* The generated code is subject to the original license. " "*/$N/* Compiled for: $2, $3, $4 */$N/* Command for C compiler:$n" " $5 */$N", 201); extern NIM_CONST TY178082 Os_178068_4151366050; extern NIM_CONST TY178510 Cpu_178496_4151366050; STRING_LITERAL(T839829468_688, "#define NIM_INTBITS $1", 22); STRING_LITERAL(T839829468_689, "typedef struct {$1} NimThreadVars;$n", 36); STRING_LITERAL(T839829468_690, "#include \"nimbase.h\"", 20); STRING_LITERAL(T839829468_691, "#include \"$1\"$N", 15); STRING_LITERAL(T839829468_692, "#include $1$N", 13); STRING_LITERAL(T839829468_693, "extern \"C\"", 10); STRING_LITERAL(T839829468_694, "$#NI NimThreadVarsSize(){return (NI)sizeof(NimThreadVars);}$n", 61); STRING_LITERAL(T839829468_695, "__$1__", 6); STRING_LITERAL(T839829468_696, "#ifndef $1$n#define $1$n", 24); STRING_LITERAL(T839829468_697, "N_CDECL(void, NimMain)(void);$n", 31); STRING_LITERAL(T839829468_698, "#endif /* $1 */$n", 17); Tcgen531027* generatedheader_534201_839829468; extern TNimType NTI531015; /* BModule */ Ropeobj180006* indent_534655_839829468; extern TNimType NTI180004; /* Rope */ extern Gcheap49818 gch_49858_1689653243; Ropeobj180006* nimtv_540656_839829468; Ttypeseq294836* nimtvdeps_540674_839829468; extern TNimType NTI294836; /* TTypeSeq */ Intset270030 nimtvdeclared_540675_839829468; extern TNimType NTI270030; /* IntSet */ NI breakpointid_550860_839829468; Ropeobj180006* gbreakpoints_550861_839829468; extern TY531153* gmodules_531170_3723162438; extern TNimType NTI531027; /* TCGen */ extern Debuginfo205009 gdebuginfo_205470_1926258066; extern Toption171009Set goptions_171128_2607990831; extern TNimType NTI294804; /* TSymSeq */ extern Tglobaloption171013Set gglobaloptions_171130_2607990831; extern NimStringDesc* headerfile_171138_2607990831; extern NimStringDesc* gprojectfull_171211_2607990831; extern Tcommands171076 gcmd_171132_2607990831; extern NI gerrorcounter_194072_155036129; extern Ropeobj180006* rnl_180903_2381377266; extern NI gforwardedprocscounter_531171_3723162438; extern TNimType NTI294244; /* TTypeKind */ extern TNimType NTI205017; /* seq[(string, int)] */ extern Tsystemcc275002 ccompiler_275431_2528170400; extern NimStringDesc* tnl_178644_4151366050; extern NI floatsize_178642_4151366050; extern Tgcmode171080 gselectedgc_171133_2607990831; extern TNimType NTI294020; /* TNodeKind */ extern TNimType NTI136002; /* seq[string] */ extern TNimType NTI294435; /* TSymKind */ extern TNimType NTI294816; /* TLoc */ extern NI intsize_178641_4151366050; extern TNimType NTI294524; /* TMagic */ extern TNimType NTI193350; /* seq[Rope] */ extern TNimType NTI294796; /* TNodeSeq */ extern Ropeobj180006* mainmodprocs_531148_3723162438; extern Ropeobj180006* maindatinit_531151_3723162438; extern Ropeobj180006* mainmodinit_531149_3723162438; extern Ropeobj180006* othermodsinit_531150_3723162438; extern Tsystemos178004 targetos_178629_4151366050; extern TY193612* fileinfos_193629_155036129; extern Tsystemcpu178452 targetcpu_178627_4151366050; extern Ropeobj180006* gmapping_531152_3723162438; N_NIMCALL(void, T839829468_2)(void) { nimGCvisit((void*)generatedheader_534201_839829468, 0); } N_NIMCALL(void, T839829468_3)(void) { nimGCvisit((void*)indent_534655_839829468, 0); } static N_INLINE(Cell47305*, usrtocell_51440_1689653243)(void* usr0) { Cell47305* result0; result0 = (Cell47305*)0; result0 = ((Cell47305*) ((NI)((NU32)(((NI) (usr0))) - (NU32)(((NI)sizeof(Cell47305)))))); return result0; } static N_INLINE(void, rtladdzct_52601_1689653243)(Cell47305* c0) { addzct_51417_1689653243((&gch_49858_1689653243.zct), c0); } static N_INLINE(void, asgnRefNoCycle)(void** dest0, void* src0) { { Cell47305* c0; if (!!((src0 == NIM_NIL))) goto LA3; c0 = usrtocell_51440_1689653243(src0); (*c0).refcount += ((NI) 8); } LA3: ; { Cell47305* c0; if (!!(((*dest0) == NIM_NIL))) goto LA7; c0 = usrtocell_51440_1689653243((*dest0)); { (*c0).refcount -= ((NI) 8); if (!((NU32)((*c0).refcount) < (NU32)(((NI) 8)))) goto LA11; rtladdzct_52601_1689653243(c0); } LA11: ; } LA7: ; (*dest0) = src0; } N_NIMCALL(void, T839829468_5)(void) { nimGCvisit((void*)nimtv_540656_839829468, 0); } N_NIMCALL(void, T839829468_6)(void) { nimGCvisit((void*)nimtvdeps_540674_839829468, 0); } static N_INLINE(void, nimGCunrefNoCycle)(void* p0) { Cell47305* c0; c0 = usrtocell_51440_1689653243(p0); { (*c0).refcount -= ((NI) 8); if (!((NU32)((*c0).refcount) < (NU32)(((NI) 8)))) goto LA3; rtladdzct_52601_1689653243(c0); } LA3: ; } N_NIMCALL(void, T839829468_7)(void) { nimGCvisit((void*)nimtvdeclared_540675_839829468.head, 0); nimGCvisit((void*)nimtvdeclared_540675_839829468.data, 0); } N_NIMCALL(void, T839829468_8)(void) { nimGCvisit((void*)gbreakpoints_550861_839829468, 0); } N_NIMCALL(Tcgen531027*, getcgenmodule_534226_839829468)(Tsym294834* s0) { Tcgen531027* result0; result0 = (Tcgen531027*)0; { NIM_BOOL LOC3; LOC3 = (NIM_BOOL)0; LOC3 = (((NI) 0) <= (*s0).position); if (!(LOC3)) goto LA4; LOC3 = ((*s0).position < (gmodules_531170_3723162438 ? gmodules_531170_3723162438->Sup.len : 0)); LA4: ; if (!LOC3) goto LA5; result0 = gmodules_531170_3723162438->data[(*s0).position]; } goto LA1; LA5: ; { result0 = NIM_NIL; } LA1: ; return result0; } static N_INLINE(void, copymem_7485_1689653243)(void* dest0, void* source0, NI size0) { void* LOC1; LOC1 = (void*)0; LOC1 = memcpy(dest0, source0, ((size_t) (size0))); } static N_INLINE(void, appendString)(NimStringDesc* dest0, NimStringDesc* src0) { copymem_7485_1689653243(((void*) ((&(*dest0).data[((*dest0).Sup.len)- 0]))), ((void*) ((*src0).data)), ((NI) ((NI)((*src0).Sup.len + ((NI) 1))))); (*dest0).Sup.len += (*src0).Sup.len; } N_NIMCALL(NU32, hashowner_534977_839829468)(Tsym294834* s0) { NU32 result0; Tsym294834* m0; Tsym294834* p0; result0 = (NU32)0; m0 = s0; { while (1) { if (!!(((*m0).kind == ((Tsymkind294435) 6)))) goto LA2; m0 = (*m0).owner; } LA2: ; } p0 = (*m0).owner; result0 = register_205121_1926258066((&gdebuginfo_205470_1926258066), (*(*p0).name).s, (*(*m0).name).s); return result0; } static N_INLINE(void, incref_53419_1689653243)(Cell47305* c0) { (*c0).refcount = (NI)((NU32)((*c0).refcount) + (NU32)(((NI) 8))); } static N_INLINE(void, decref_53001_1689653243)(Cell47305* c0) { { (*c0).refcount -= ((NI) 8); if (!((NU32)((*c0).refcount) < (NU32)(((NI) 8)))) goto LA3; rtladdzct_52601_1689653243(c0); } LA3: ; } static N_INLINE(void, asgnRef)(void** dest0, void* src0) { { Cell47305* LOC5; if (!!((src0 == NIM_NIL))) goto LA3; LOC5 = (Cell47305*)0; LOC5 = usrtocell_51440_1689653243(src0); incref_53419_1689653243(LOC5); } LA3: ; { Cell47305* LOC10; if (!!(((*dest0) == NIM_NIL))) goto LA8; LOC10 = (Cell47305*)0; LOC10 = usrtocell_51440_1689653243((*dest0)); decref_53001_1689653243(LOC10); } LA8: ; (*dest0) = src0; } N_NIMCALL(Toption171009Set, initprocoptions_564635_839829468)(Tcgen531027* m0) { Toption171009Set result0; memset((void*)(&result0), 0, sizeof(result0)); { if (!(((*(*m0).module).flags &(1U<<((NU)(((Tsymflag294184) 13))&31U)))!=0)) goto LA3; result0 = (goptions_171128_2607990831 & ~ 32768); } goto LA1; LA3: ; { result0 = goptions_171128_2607990831; } LA1: ; return result0; } N_NIMCALL(Tcproc531021*, newpreinitproc_564625_839829468)(Tcgen531027* m0) { Tcproc531021* result0; result0 = (Tcproc531021*)0; result0 = newproc_531206_3723162438(NIM_NIL, m0); (*result0).labels = ((NI) 100000); return result0; } N_NIMCALL(Tcproc531021*, newpostinitproc_564630_839829468)(Tcgen531027* m0) { Tcproc531021* result0; result0 = (Tcproc531021*)0; result0 = newproc_531206_3723162438(NIM_NIL, m0); (*result0).labels = ((NI) 200000); return result0; } N_NIMCALL(Ropeobj180006*, gettempname_535596_839829468)(Tcgen531027* m0) { Ropeobj180006* result0; Ropeobj180006* LOC1; result0 = (Ropeobj180006*)0; LOC1 = (Ropeobj180006*)0; LOC1 = rope_180401_2381377266(((NI64) ((*m0).labels))); result0 = HEX26_180418_2381377266((*m0).tmpbase, LOC1); (*m0).labels += ((NI) 1); return result0; } N_NIMCALL(Tcgen531027*, rawnewmodule_564663_839829468)(Tsym294834* module0, NimStringDesc* filename0) { Tcgen531027* result0; NimStringDesc* LOC1; NU32 LOC2; NimStringDesc* LOC3; NimStringDesc* LOC4; NimStringDesc* LOC5; result0 = (Tcgen531027*)0; result0 = (Tcgen531027*) newObj((&NTI531015), sizeof(Tcgen531027)); (*result0).Sup.Sup.m_type = (&NTI531027); LOC1 = (NimStringDesc*)0; LOC2 = (NU32)0; LOC2 = hashowner_534977_839829468(module0); LOC3 = (NimStringDesc*)0; LOC3 = HEX24_8401_1689653243(((NU64) (LOC2))); LOC1 = rawNewString(LOC3->Sup.len + 2); appendString(LOC1, ((NimStringDesc*) &T839829468_11)); appendString(LOC1, LOC3); appendString(LOC1, ((NimStringDesc*) &T839829468_12)); asgnRefNoCycle((void**) (&(*result0).tmpbase), rope_180277_2381377266(LOC1)); initlinkedlist_148031_3771138726((&(*result0).headerfiles)); initintset_270885_2627731572((&(*result0).declaredthings)); initintset_270885_2627731572((&(*result0).declaredprotos)); LOC4 = (NimStringDesc*)0; LOC4 = (*result0).cfilename; (*result0).cfilename = copyStringRC1(filename0); if (LOC4) nimGCunrefNoCycle(LOC4); LOC5 = (NimStringDesc*)0; LOC5 = (*result0).filename; (*result0).filename = copyStringRC1(filename0); if (LOC5) nimGCunrefNoCycle(LOC5); initidtable_298019_850551059((&(*result0).typecache)); initidtable_298019_850551059((&(*result0).forwtypecache)); asgnRefNoCycle((void**) (&(*result0).module), module0); initintset_270885_2627731572((&(*result0).typeinfomarker)); asgnRef((void**) (&(*result0).initproc), newproc_531206_3723162438(NIM_NIL, result0)); (*(*result0).initproc).options = initprocoptions_564635_839829468(result0); asgnRef((void**) (&(*result0).preinitproc), newpreinitproc_564625_839829468(result0)); asgnRef((void**) (&(*result0).postinitproc), newpostinitproc_564630_839829468(result0)); initnodetable_298085_850551059((&(*result0).datacache)); if ((*result0).typestack) nimGCunrefNoCycle((*result0).typestack); (*result0).typestack = (Ttypeseq294836*) newSeqRC1((&NTI294836), 0); if ((*result0).forwardedprocs) nimGCunrefNoCycle((*result0).forwardedprocs); (*result0).forwardedprocs = (Tsymseq294804*) newSeqRC1((&NTI294804), 0); asgnRefNoCycle((void**) (&(*result0).typenodesname), gettempname_535596_839829468(result0)); asgnRefNoCycle((void**) (&(*result0).nimtypesname), gettempname_535596_839829468(result0)); { if (!(((*module0).flags &(1U<<((NU)(((Tsymflag294184) 13))&31U)))!=0)) goto LA8; (*result0).flags |= ((NU8)1)<<((((Codegenflag531025) 0))%(sizeof(NU8)*8)); (*(*result0).preinitproc).options &= ~(((NU32)1) << ((((Toption171009) 15)) % (sizeof(NU32)*8))); (*(*result0).postinitproc).options &= ~(((NU32)1) << ((((Toption171009) 15)) % (sizeof(NU32)*8))); } LA8: ; return result0; } N_NIMCALL(Tcgen531027*, rawnewmodule_565038_839829468)(Tsym294834* module0) { Tcgen531027* result0; NimStringDesc* LOC1; result0 = (Tcgen531027*)0; LOC1 = (NimStringDesc*)0; LOC1 = tofullpath_194264_155036129(((NI32) ((*module0).position))); result0 = rawnewmodule_564663_839829468(module0, LOC1); return result0; } N_NIMCALL(Tcgen531027*, newmodule_565045_839829468)(Tsym294834* module0) { Tcgen531027* result0; result0 = (Tcgen531027*)0; { Tcgen531027* LOC3; NimStringDesc* LOC6; LOC3 = (Tcgen531027*)0; LOC3 = getcgenmodule_534226_839829468(module0); if (!!((LOC3 == NIM_NIL))) goto LA4; LOC6 = (NimStringDesc*)0; LOC6 = HEX24_198185_1689653243(T839829468_9); internalerror_198113_155036129(LOC6); } LA4: ; result0 = rawnewmodule_565038_839829468(module0); { if (!((gmodules_531170_3723162438 ? gmodules_531170_3723162438->Sup.len : 0) <= (*module0).position)) goto LA9; gmodules_531170_3723162438 = (TY531153*) setLengthSeq(&(gmodules_531170_3723162438)->Sup, sizeof(Tcgen531027*), ((NI) ((NI)((*module0).position + ((NI) 1))))); } LA9: ; asgnRef((void**) (&gmodules_531170_3723162438->data[(*module0).position]), result0); { if (!((gglobaloptions_171130_2607990831 &((NU64)1<<((NU)(((Tglobaloption171013) 2))&63U)))!=0)) goto LA13; { NimStringDesc* LOC19; NimStringDesc* LOC20; if (!(((*module0).flags &(1U<<((NU)(((Tsymflag294184) 25))&31U)))!=0)) goto LA17; LOC19 = (NimStringDesc*)0; LOC20 = (NimStringDesc*)0; LOC20 = tofilename_194260_155036129(((NI32) ((*module0).position))); LOC19 = rawNewString(LOC20->Sup.len + 28); appendString(LOC19, ((NimStringDesc*) &T839829468_13)); appendString(LOC19, LOC20); internalerror_198113_155036129(LOC19); } LA17: ; } LA13: ; return result0; } N_NIMCALL(Tpasscontext343002*, myopen_565115_839829468)(Tsym294834* module0) { Tpasscontext343002* result0; Tcgen531027* LOC1; result0 = (Tpasscontext343002*)0; LOC1 = (Tcgen531027*)0; LOC1 = newmodule_565045_839829468(module0); result0 = &LOC1->Sup; { NIM_BOOL LOC4; NimStringDesc* f0; NimStringDesc* LOC13; NimStringDesc* LOC14; LOC4 = (NIM_BOOL)0; LOC4 = ((gglobaloptions_171130_2607990831 &((NU64)1<<((NU)(((Tglobaloption171013) 27))&63U)))!=0); if (!(LOC4)) goto LA5; LOC4 = (generatedheader_534201_839829468 == NIM_NIL); LA5: ; if (!LOC4) goto LA6; { if (!(((NI) 0) < (headerfile_171138_2607990831 ? headerfile_171138_2607990831->Sup.len : 0))) goto LA10; f0 = headerfile_171138_2607990831; } goto LA8; LA10: ; { f0 = gprojectfull_171211_2607990831; } LA8: ; LOC13 = (NimStringDesc*)0; LOC13 = completecfilepath_275854_2528170400(f0, NIM_TRUE); LOC14 = (NimStringDesc*)0; LOC14 = noschangeFileExt(LOC13, ((NimStringDesc*) &T839829468_14)); asgnRef((void**) (&generatedheader_534201_839829468), rawnewmodule_564663_839829468(module0, LOC14)); (*generatedheader_534201_839829468).flags |= ((NU8)1)<<((((Codegenflag531025) 3))%(sizeof(NU8)*8)); } LA6: ; return result0; } N_NIMCALL(NimStringDesc*, getcfile_565204_839829468)(Tcgen531027* m0) { NimStringDesc* result0; NimStringDesc* ext0; NimStringDesc* LOC13; NimStringDesc* LOC14; result0 = (NimStringDesc*)0; { NIM_BOOL LOC3; LOC3 = (NIM_BOOL)0; LOC3 = (gcmd_171132_2607990831 == ((Tcommands171076) 2)); if (LOC3) goto LA4; LOC3 = (((*(*m0).module).flags &(1U<<((NU)(((Tsymflag294184) 27))&31U)))!=0); LA4: ; if (!LOC3) goto LA5; ext0 = copyString(((NimStringDesc*) &T839829468_15)); } goto LA1; LA5: ; { NIM_BOOL LOC8; LOC8 = (NIM_BOOL)0; LOC8 = (gcmd_171132_2607990831 == ((Tcommands171076) 3)); if (LOC8) goto LA9; LOC8 = (((*(*m0).module).flags &(1U<<((NU)(((Tsymflag294184) 28))&31U)))!=0); LA9: ; if (!LOC8) goto LA10; ext0 = copyString(((NimStringDesc*) &T839829468_16)); } goto LA1; LA10: ; { ext0 = copyString(((NimStringDesc*) &T839829468_17)); } LA1: ; LOC13 = (NimStringDesc*)0; LOC13 = withpackagename_172073_2607990831((*m0).cfilename); LOC14 = (NimStringDesc*)0; LOC14 = completecfilepath_275854_2528170400(LOC13, NIM_TRUE); result0 = noschangeFileExt(LOC14, ext0); return result0; } N_NIMCALL(Tpasscontext343002*, myopencached_565249_839829468)(Tsym294834* module0, Trodreader334021* rd0) { Tpasscontext343002* result0; Tcgen531027* m0; NimStringDesc* LOC1; result0 = (Tpasscontext343002*)0; m0 = newmodule_565045_839829468(module0); LOC1 = (NimStringDesc*)0; LOC1 = getcfile_565204_839829468(m0); readmergeinfo_532613_2760143328(LOC1, m0); result0 = &m0->Sup; return result0; } static N_INLINE(NIM_BOOL, skipcodegen_343085_2355241294)(Tnode294802* n0) { NIM_BOOL result0; result0 = (NIM_BOOL)0; result0 = (((NI) 0) < gerrorcounter_194072_155036129); return result0; } N_NIMCALL(void, fillloc_534282_839829468)(Tloc294816* a0, Tlockind294808 k0, Ttype294840* typ0, Ropeobj180006* r0, Tstorageloc294812 s0) { { if (!((*a0).k == ((Tlockind294808) 0))) goto LA3; (*a0).k = k0; unsureAsgnRef((void**) (&(*a0).t), typ0); (*a0).s = s0; { if (!((*a0).r == NIM_NIL)) goto LA7; unsureAsgnRef((void**) (&(*a0).r), r0); } LA7: ; } LA3: ; } N_NIMCALL(NIM_BOOL, iskeyword_534960_839829468)(Tident201010* w0) { NIM_BOOL result0; { result0 = (NIM_BOOL)0; switch ((*w0).Sup.id) { case ((NI) 200) ... ((NI) 262): case ((NI) 4) ... ((NI) 70): case ((NI) 138): { result0 = NIM_TRUE; goto BeforeRet; } break; default: { result0 = NIM_FALSE; goto BeforeRet; } break; } }BeforeRet: ; return result0; } N_NIMCALL(Ropeobj180006*, manglename_535205_839829468)(Tsym294834* s0) { Ropeobj180006* result0; result0 = (Ropeobj180006*)0; result0 = (*s0).loc.r; { NIM_BOOL keeporigname0; NIM_BOOL LOC5; NIM_BOOL LOC6; NIM_BOOL LOC9; NimStringDesc* LOC10; if (!(result0 == NIM_NIL)) goto LA3; LOC5 = (NIM_BOOL)0; LOC6 = (NIM_BOOL)0; LOC6 = ((2824 &(1U<<((NU)((*s0).kind)&31U)))!=0); if (!(LOC6)) goto LA7; LOC6 = ((IL64(2149580812) & (*s0).flags) == 0); LA7: ; LOC5 = LOC6; if (!(LOC5)) goto LA8; LOC9 = (NIM_BOOL)0; LOC9 = iskeyword_534960_839829468((*s0).name); LOC5 = !(LOC9); LA8: ; keeporigname0 = LOC5; LOC10 = (NimStringDesc*)0; LOC10 = mangle_530847_2036603609((*(*s0).name).s); result0 = rope_180277_2381377266(LOC10); { if (!keeporigname0) goto LA13; add_180487_2381377266(&result0, ((NimStringDesc*) &T839829468_18)); } goto LA11; LA13: ; { TY535289 LOC16; Ropeobj180006* LOC17; Ropeobj180006* LOC18; TY535289 LOC19; Ropeobj180006* LOC20; NU32 LOC21; Ropeobj180006* LOC22; memset((void*)LOC16, 0, sizeof(LOC16)); LOC17 = (Ropeobj180006*)0; LOC17 = HEX25_180905_2381377266(((NimStringDesc*) &T839829468_12), LOC16, 0); add_180482_2381377266(&result0, LOC17); LOC18 = (Ropeobj180006*)0; LOC18 = rope_180401_2381377266(((NI64) ((*s0).Sup.id))); add_180482_2381377266(&result0, LOC18); memset((void*)LOC19, 0, sizeof(LOC19)); LOC20 = (Ropeobj180006*)0; LOC20 = HEX25_180905_2381377266(((NimStringDesc*) &T839829468_12), LOC19, 0); add_180482_2381377266(&result0, LOC20); LOC21 = (NU32)0; LOC21 = hashowner_534977_839829468(s0); LOC22 = (Ropeobj180006*)0; LOC22 = rope_180401_2381377266(((NI64) (LOC21))); add_180482_2381377266(&result0, LOC22); } LA11: ; asgnRefNoCycle((void**) (&(*s0).loc.r), result0); } LA3: ; return result0; } N_NIMCALL(void, fillprocloc_541201_839829468)(Tsym294834* sym0) { { Ropeobj180006* LOC5; if (!((*sym0).loc.k == ((Tlockind294808) 0))) goto LA3; LOC5 = (Ropeobj180006*)0; LOC5 = manglename_535205_839829468(sym0); fillloc_534282_839829468((&(*sym0).loc), ((Tlockind294808) 7), (*sym0).typ, LOC5, ((Tstorageloc294812) 2)); } LA3: ; } N_NIMCALL(void, useheader_534369_839829468)(Tcgen531027* m0, Tsym294834* sym0) { { NimStringDesc* LOC5; NIM_BOOL LOC6; if (!(((*sym0).loc.flags &(1U<<((NU)(((Tlocflag294810) 6))&15U)))!=0)) goto LA3; LOC5 = (NimStringDesc*)0; LOC5 = getstr_299230_850551059((*(*sym0).annex).path); LOC6 = (NIM_BOOL)0; LOC6 = includestr_148249_3771138726((&(*m0).headerfiles), LOC5); } LA3: ; } static N_INLINE(void, appendChar)(NimStringDesc* dest0, NIM_CHAR c0) { (*dest0).data[((*dest0).Sup.len)- 0] = c0; (*dest0).data[((NI)((*dest0).Sup.len + ((NI) 1)))- 0] = 0; (*dest0).Sup.len += ((NI) 1); } N_NIMCALL(NIM_BOOL, isactivated_563431_839829468)(Tsym294834* prc0) { NIM_BOOL result0; result0 = (NIM_BOOL)0; result0 = !(((*prc0).typ == NIM_NIL)); return result0; } N_NIMCALL(void, addforwardedproc_534203_839829468)(Tcgen531027* m0, Tsym294834* prc0) { (*m0).forwardedprocs = (Tsymseq294804*) incrSeqV2(&((*m0).forwardedprocs)->Sup, sizeof(Tsym294834*)); asgnRefNoCycle((void**) (&(*m0).forwardedprocs->data[(*m0).forwardedprocs->Sup.len]), prc0); ++(*m0).forwardedprocs->Sup.len; gforwardedprocscounter_531171_3723162438 += ((NI) 1); } N_NIMCALL(void, genclinedir_534725_839829468)(Ropeobj180006** r0, NimStringDesc* filename0, NI line0) { { TY534811 LOC5; NimStringDesc* LOC6; if (!((goptions_171128_2607990831 &(1U<<((NU)(((Toption171009) 10))&31U)))!=0)) goto LA3; memset((void*)LOC5, 0, sizeof(LOC5)); LOC6 = (NimStringDesc*)0; LOC6 = makesinglelinecstring_530835_2036603609(filename0); LOC5[0] = rope_180277_2381377266(LOC6); LOC5[1] = rope_180401_2381377266(((NI64) (line0))); addf_181205_2381377266(r0, ((NimStringDesc*) &T839829468_21), LOC5, 2); } LA3: ; } static N_INLINE(NI, tolinenumber_194415_155036129)(Tlineinfo193336 info0) { NI result0; result0 = (NI)0; result0 = ((NI) (info0.line)); return result0; } N_NIMCALL(NI, safelinenm_534721_839829468)(Tlineinfo193336 info0) { NI result0; result0 = (NI)0; result0 = tolinenumber_194415_155036129(info0); { if (!(result0 < ((NI) 0))) goto LA3; result0 = ((NI) 0); } LA3: ; return result0; } N_NIMCALL(void, genclinedir_534813_839829468)(Ropeobj180006** r0, Tlineinfo193336 info0) { NimStringDesc* LOC1; NI LOC2; LOC1 = (NimStringDesc*)0; LOC1 = tofullpath_194264_155036129(info0.fileindex); LOC2 = (NI)0; LOC2 = safelinenm_534721_839829468(info0); genclinedir_534725_839829468(r0, LOC1, LOC2); } N_NIMCALL(Tctypekind531007, mapsettype_535389_839829468)(Ttype294840* typ0) { Tctypekind531007 result0; NI64 LOC1; result0 = (Tctypekind531007)0; LOC1 = (NI64)0; LOC1 = getsize_322135_3876443242(typ0); switch (((NI) (LOC1))) { case ((NI) 1): { result0 = ((Tctypekind531007) 4); } break; case ((NI) 2): { result0 = ((Tctypekind531007) 5); } break; case ((NI) 4): { result0 = ((Tctypekind531007) 6); } break; case ((NI) 8): { result0 = ((Tctypekind531007) 7); } break; default: { result0 = ((Tctypekind531007) 17); } break; } return result0; } N_NIMCALL(Tctypekind531007, maptype_535393_839829468)(Ttype294840* typ0) { Tctypekind531007 result0; result0 = (Tctypekind531007)0; switch ((*typ0).kind) { case ((Ttypekind294244) 0): case ((Ttypekind294244) 7): { result0 = ((Tctypekind531007) 0); } break; case ((Ttypekind294244) 1): { result0 = ((Tctypekind531007) 2); } break; case ((Ttypekind294244) 2): { result0 = ((Tctypekind531007) 1); } break; case ((Ttypekind294244) 19): { result0 = mapsettype_535389_839829468(typ0); } break; case ((Ttypekind294244) 27): case ((Ttypekind294244) 4): case ((Ttypekind294244) 16): case ((Ttypekind294244) 48): { result0 = ((Tctypekind531007) 17); } break; case ((Ttypekind294244) 17): case ((Ttypekind294244) 18): { result0 = ((Tctypekind531007) 19); } break; case ((Ttypekind294244) 10): case ((Ttypekind294244) 11): case ((Ttypekind294244) 12): case ((Ttypekind294244) 13): case ((Ttypekind294244) 15): case ((Ttypekind294244) 46): case ((Ttypekind294244) 47): case ((Ttypekind294244) 49): case ((Ttypekind294244) 8): { Ttype294840* LOC8; LOC8 = (Ttype294840*)0; LOC8 = lastson_297377_850551059(typ0); result0 = maptype_535393_839829468(LOC8); } break; case ((Ttypekind294244) 14): { { NI64 LOC12; LOC12 = (NI64)0; LOC12 = firstord_322001_3876443242(typ0); if (!(LOC12 < IL64(0))) goto LA13; result0 = ((Tctypekind531007) 6); } goto LA10; LA13: ; { NI64 LOC16; LOC16 = (NI64)0; LOC16 = getsize_322135_3876443242(typ0); switch (((NI) (LOC16))) { case ((NI) 1): { result0 = ((Tctypekind531007) 13); } break; case ((NI) 2): { result0 = ((Tctypekind531007) 14); } break; case ((NI) 4): { result0 = ((Tctypekind531007) 6); } break; case ((NI) 8): { result0 = ((Tctypekind531007) 7); } break; default: { internalerror_198113_155036129(((NimStringDesc*) &T839829468_25)); } break; } } LA10: ; } break; case ((Ttypekind294244) 20): { result0 = maptype_535393_839829468((*typ0).sons->data[((NI) 0)]); } break; case ((Ttypekind294244) 21): case ((Ttypekind294244) 23): case ((Ttypekind294244) 22): { Ttype294840* base0; Ttype294840* LOC24; LOC24 = (Ttype294840*)0; LOC24 = lastson_297377_850551059(typ0); base0 = skiptypes_298099_850551059(LOC24, IL64(211106232576256)); switch ((*base0).kind) { case ((Ttypekind294244) 27): case ((Ttypekind294244) 4): case ((Ttypekind294244) 16): case ((Ttypekind294244) 48): { result0 = ((Tctypekind531007) 18); } break; default: { result0 = ((Tctypekind531007) 20); } break; } } break; case ((Ttypekind294244) 26): { result0 = ((Tctypekind531007) 20); } break; case ((Ttypekind294244) 24): { result0 = ((Tctypekind531007) 22); } break; case ((Ttypekind294244) 25): { { if (!!(((*typ0).callconv == ((Tcallingconvention294002) 8)))) goto LA32; result0 = ((Tctypekind531007) 23); } goto LA30; LA32: ; { result0 = ((Tctypekind531007) 19); } LA30: ; } break; case ((Ttypekind294244) 28): { result0 = ((Tctypekind531007) 21); } break; case ((Ttypekind294244) 29): { result0 = ((Tctypekind531007) 24); } break; case ((Ttypekind294244) 31) ... ((Ttypekind294244) 44): { result0 = ((Tctypekind531007) ((NI)(((NI) ((NI)(((NI) ((*typ0).kind)) - ((NI) 31)))) + ((NI) 3)))); } break; case ((Ttypekind294244) 59): { { Ttype294840* LOC43; if (!!(((*typ0).n == NIM_NIL))) goto LA41; LOC43 = (Ttype294840*)0; LOC43 = lastson_297377_850551059(typ0); result0 = maptype_535393_839829468(LOC43); } goto LA39; LA41: ; { internalerror_198113_155036129(((NimStringDesc*) &T839829468_25)); } LA39: ; } break; default: { internalerror_198113_155036129(((NimStringDesc*) &T839829468_25)); } break; } return result0; } N_NIMCALL(NIM_BOOL, isimportedcpptype_535476_839829468)(Ttype294840* t0) { NIM_BOOL result0; NIM_BOOL LOC1; result0 = (NIM_BOOL)0; LOC1 = (NIM_BOOL)0; LOC1 = !(((*t0).sym == NIM_NIL)); if (!(LOC1)) goto LA2; LOC1 = (((*(*t0).sym).flags &(1U<<((NU)(((Tsymflag294184) 27))&31U)))!=0); LA2: ; result0 = LOC1; return result0; } N_NIMCALL(NIM_BOOL, needscomplexassignment_535509_839829468)(Ttype294840* typ0) { NIM_BOOL result0; result0 = (NIM_BOOL)0; result0 = containsgarbagecollectedref_322117_3876443242(typ0); return result0; } static N_INLINE(NIM_BOOL, isobjlackingtypefield_535513_839829468)(Ttype294840* typ0) { NIM_BOOL result0; NIM_BOOL LOC1; NIM_BOOL LOC3; NIM_BOOL LOC4; result0 = (NIM_BOOL)0; LOC1 = (NIM_BOOL)0; LOC1 = ((*typ0).kind == ((Ttypekind294244) 17)); if (!(LOC1)) goto LA2; LOC3 = (NIM_BOOL)0; LOC4 = (NIM_BOOL)0; LOC4 = (((*typ0).flags &(1U<<((NU)(((Ttypeflag294431) 2))&31U)))!=0); if (!(LOC4)) goto LA5; LOC4 = ((*typ0).sons->data[((NI) 0)] == NIM_NIL); LA5: ; LOC3 = LOC4; if (LOC3) goto LA6; LOC3 = ispureobject_322138_3876443242(typ0); LA6: ; LOC1 = LOC3; LA2: ; result0 = LOC1; return result0; } N_NIMCALL(NIM_BOOL, isinvalidreturntype_535548_839829468)(Ttype294840* rettype0) { NIM_BOOL result0; { result0 = (NIM_BOOL)0; { if (!(rettype0 == NIM_NIL)) goto LA3; result0 = NIM_TRUE; } goto LA1; LA3: ; { Tctypekind531007 LOC6; LOC6 = (Tctypekind531007)0; LOC6 = maptype_535393_839829468(rettype0); switch (LOC6) { case ((Tctypekind531007) 17): { Ttype294840* LOC8; LOC8 = (Ttype294840*)0; LOC8 = skiptypes_298099_850551059(rettype0, IL64(211106232576256)); result0 = !(((*LOC8).kind == ((Ttypekind294244) 23) || (*LOC8).kind == ((Ttypekind294244) 22) || (*LOC8).kind == ((Ttypekind294244) 21))); } break; case ((Tctypekind531007) 19): { Ttype294840* t0; NIM_BOOL LOC16; NIM_BOOL LOC18; NIM_BOOL LOC20; t0 = skiptypes_298099_850551059(rettype0, IL64(211106232576256)); { NIM_BOOL LOC12; LOC12 = (NIM_BOOL)0; LOC12 = isimportedcpptype_535476_839829468(rettype0); if (LOC12) goto LA13; LOC12 = isimportedcpptype_535476_839829468(t0); LA13: ; if (!LOC12) goto LA14; result0 = NIM_FALSE; goto BeforeRet; } LA14: ; LOC16 = (NIM_BOOL)0; LOC16 = needscomplexassignment_535509_839829468(t0); if (LOC16) goto LA17; LOC18 = (NIM_BOOL)0; LOC18 = ((*t0).kind == ((Ttypekind294244) 17)); if (!(LOC18)) goto LA19; LOC20 = (NIM_BOOL)0; LOC20 = isobjlackingtypefield_535513_839829468(t0); LOC18 = !(LOC20); LA19: ; LOC16 = LOC18; LA17: ; result0 = LOC16; } break; default: { result0 = NIM_FALSE; } break; } } LA1: ; }BeforeRet: ; return result0; } N_NIMCALL(Ropeobj180006*, typename_535292_839829468)(Ttype294840* typ0) { Ropeobj180006* result0; result0 = (Ropeobj180006*)0; { NimStringDesc* LOC5; if (!!(((*typ0).sym == NIM_NIL))) goto LA3; LOC5 = (NimStringDesc*)0; LOC5 = mangle_530847_2036603609((*(*(*typ0).sym).name).s); result0 = rope_180277_2381377266(LOC5); } goto LA1; LA3: ; { TY535289 LOC7; memset((void*)LOC7, 0, sizeof(LOC7)); result0 = HEX25_180905_2381377266(((NimStringDesc*) &T839829468_28), LOC7, 0); } LA1: ; return result0; } N_NIMCALL(Ropeobj180006*, gettypename_535313_839829468)(Ttype294840* typ0) { Ropeobj180006* result0; result0 = (Ropeobj180006*)0; { NIM_BOOL LOC3; LOC3 = (NIM_BOOL)0; LOC3 = !(((*typ0).sym == NIM_NIL)); if (!(LOC3)) goto LA4; LOC3 = !(((96 & (*(*typ0).sym).flags) == 0)); LA4: ; if (!LOC3) goto LA5; result0 = (*(*typ0).sym).loc.r; } goto LA1; LA5: ; { { Ropeobj180006* LOC12; Ropeobj180006* LOC13; if (!((*typ0).loc.r == NIM_NIL)) goto LA10; LOC12 = (Ropeobj180006*)0; LOC12 = typename_535292_839829468(typ0); LOC13 = (Ropeobj180006*)0; LOC13 = rope_180401_2381377266(((NI64) ((*typ0).Sup.id))); asgnRefNoCycle((void**) (&(*typ0).loc.r), HEX26_180418_2381377266(LOC12, LOC13)); } LA10: ; result0 = (*typ0).loc.r; } LA1: ; { NimStringDesc* LOC18; if (!(result0 == NIM_NIL)) goto LA16; LOC18 = (NimStringDesc*)0; LOC18 = rawNewString(reprEnum((NI)(*typ0).kind, (&NTI294244))->Sup.len + 13); appendString(LOC18, ((NimStringDesc*) &T839829468_29)); appendString(LOC18, reprEnum((NI)(*typ0).kind, (&NTI294244))); internalerror_198113_155036129(LOC18); } LA16: ; return result0; } N_NIMCALL(Ropeobj180006*, typenameorliteral_535898_839829468)(Ttype294840* t0, NimStringDesc* literal0) { Ropeobj180006* result0; result0 = (Ropeobj180006*)0; { NIM_BOOL LOC3; NIM_BOOL LOC4; LOC3 = (NIM_BOOL)0; LOC4 = (NIM_BOOL)0; LOC4 = !(((*t0).sym == NIM_NIL)); if (!(LOC4)) goto LA5; LOC4 = (((*(*t0).sym).flags &(1U<<((NU)(((Tsymflag294184) 5))&31U)))!=0); LA5: ; LOC3 = LOC4; if (!(LOC3)) goto LA6; LOC3 = ((*(*t0).sym).magic == ((Tmagic294524) 0)); LA6: ; if (!LOC3) goto LA7; result0 = gettypename_535313_839829468(t0); } goto LA1; LA7: ; { result0 = rope_180277_2381377266(literal0); } LA1: ; return result0; } N_NIMCALL(Ropeobj180006*, getsimpletypedesc_535936_839829468)(Tcgen531027* m0, Ttype294840* typ0) { Ropeobj180006* result0; result0 = (Ropeobj180006*)0; switch ((*typ0).kind) { case ((Ttypekind294244) 26): { result0 = typenameorliteral_535898_839829468(typ0, ((NimStringDesc*) &T839829468_30)); } break; case ((Ttypekind294244) 28): { Ropeobj180006* LOC3; LOC3 = (Ropeobj180006*)0; LOC3 = cgsym_534403_839829468(m0, ((NimStringDesc*) &T839829468_31)); result0 = typenameorliteral_535898_839829468(typ0, ((NimStringDesc*) &T839829468_32)); } break; case ((Ttypekind294244) 29): { result0 = typenameorliteral_535898_839829468(typ0, ((NimStringDesc*) &T839829468_33)); } break; case ((Ttypekind294244) 1): { result0 = typenameorliteral_535898_839829468(typ0, ((NimStringDesc*) &T839829468_34)); } break; case ((Ttypekind294244) 2): { result0 = typenameorliteral_535898_839829468(typ0, ((NimStringDesc*) &T839829468_35)); } break; case ((Ttypekind294244) 5): { result0 = typenameorliteral_535898_839829468(typ0, ((NimStringDesc*) &T839829468_18)); } break; case ((Ttypekind294244) 31) ... ((Ttypekind294244) 44): { result0 = typenameorliteral_535898_839829468(typ0, Numericaltypetostr_535941_839829468[((*typ0).kind)- 31]); } break; case ((Ttypekind294244) 13): case ((Ttypekind294244) 20): case ((Ttypekind294244) 15): { result0 = getsimpletypedesc_535936_839829468(m0, (*typ0).sons->data[((NI) 0)]); } break; case ((Ttypekind294244) 59): { { Ttype294840* LOC15; if (!!(((*typ0).n == NIM_NIL))) goto LA13; LOC15 = (Ttype294840*)0; LOC15 = lastson_297377_850551059(typ0); result0 = getsimpletypedesc_535936_839829468(m0, LOC15); } goto LA11; LA13: ; { internalerror_198113_155036129(((NimStringDesc*) &T839829468_50)); } LA11: ; } break; case ((Ttypekind294244) 11): { Ttype294840* LOC18; LOC18 = (Ttype294840*)0; LOC18 = lastson_297377_850551059(typ0); result0 = getsimpletypedesc_535936_839829468(m0, LOC18); } break; default: { result0 = NIM_NIL; } break; } return result0; } N_NIMCALL(Ropeobj180006*, cachegettype_535591_839829468)(Tidtable294850 tab0, Ttype294840* key0) { Ropeobj180006* result0; Tidobj201004* LOC1; TNimObject* LOC2; result0 = (Ropeobj180006*)0; LOC1 = (Tidobj201004*)0; LOC1 = &key0->Sup; LOC2 = (TNimObject*)0; LOC2 = idtableget_301086_2984716966(tab0, LOC1); result0 = ((Ropeobj180006*) (LOC2)); return result0; } N_NIMCALL(Ropeobj180006*, gettypepre_535972_839829468)(Tcgen531027* m0, Ttype294840* typ0) { Ropeobj180006* result0; result0 = (Ropeobj180006*)0; { if (!(typ0 == NIM_NIL)) goto LA3; result0 = rope_180277_2381377266(((NimStringDesc*) &T839829468_26)); } goto LA1; LA3: ; { result0 = getsimpletypedesc_535936_839829468(m0, typ0); { if (!(result0 == NIM_NIL)) goto LA8; result0 = cachegettype_535591_839829468((*m0).typecache, typ0); } LA8: ; } LA1: ; return result0; } N_NIMCALL(NIM_BOOL, isimportedtype_535449_839829468)(Ttype294840* t0) { NIM_BOOL result0; NIM_BOOL LOC1; result0 = (NIM_BOOL)0; LOC1 = (NIM_BOOL)0; LOC1 = !(((*t0).sym == NIM_NIL)); if (!(LOC1)) goto LA2; LOC1 = (((*(*t0).sym).flags &(1U<<((NU)(((Tsymflag294184) 5))&31U)))!=0); LA2: ; result0 = LOC1; return result0; } N_NIMCALL(NimStringDesc*, getforwardstructformat_536015_839829468)(Tcgen531027* m0) { NimStringDesc* result0; result0 = (NimStringDesc*)0; { NIM_BOOL LOC3; LOC3 = (NIM_BOOL)0; LOC3 = (gcmd_171132_2607990831 == ((Tcommands171076) 2)); if (LOC3) goto LA4; LOC3 = (((*(*m0).module).flags &(1U<<((NU)(((Tsymflag294184) 27))&31U)))!=0); LA4: ; if (!LOC3) goto LA5; result0 = copyString(((NimStringDesc*) &T839829468_54)); } goto LA1; LA5: ; { result0 = copyString(((NimStringDesc*) &T839829468_55)); } LA1: ; return result0; } N_NIMCALL(Ropeobj180006*, structorunion_536001_839829468)(Ttype294840* t0) { Ropeobj180006* result0; result0 = (Ropeobj180006*)0; { if (!(((*t0).flags &(1U<<((NU)(((Ttypeflag294431) 1))&31U)))!=0)) goto LA3; result0 = rope_180277_2381377266(((NimStringDesc*) &T839829468_56)); } goto LA1; LA3: ; { result0 = rope_180277_2381377266(((NimStringDesc*) &T839829468_57)); } LA1: ; return result0; } N_NIMCALL(Ropeobj180006*, gettypeforward_536039_839829468)(Tcgen531027* m0, Ttype294840* typ0) { Ropeobj180006* result0; { result0 = (Ropeobj180006*)0; result0 = cachegettype_535591_839829468((*m0).forwtypecache, typ0); { if (!!((result0 == NIM_NIL))) goto LA3; goto BeforeRet; } LA3: ; result0 = gettypepre_535972_839829468(m0, typ0); { if (!!((result0 == NIM_NIL))) goto LA7; goto BeforeRet; } LA7: ; switch ((*typ0).kind) { case ((Ttypekind294244) 24): case ((Ttypekind294244) 18): case ((Ttypekind294244) 17): { Tidobj201004* LOC17; TNimObject* LOC18; result0 = gettypename_535313_839829468(typ0); { NIM_BOOL LOC12; NimStringDesc* LOC15; TY534811 LOC16; LOC12 = (NIM_BOOL)0; LOC12 = isimportedtype_535449_839829468(typ0); if (!!(LOC12)) goto LA13; LOC15 = (NimStringDesc*)0; LOC15 = getforwardstructformat_536015_839829468(m0); memset((void*)LOC16, 0, sizeof(LOC16)); LOC16[0] = structorunion_536001_839829468(typ0); LOC16[1] = result0; addf_181205_2381377266(&(*m0).s[(((Tcfilesection531005) 2))- 0], LOC15, LOC16, 2); } LA13: ; LOC17 = (Tidobj201004*)0; LOC17 = &typ0->Sup; LOC18 = (TNimObject*)0; LOC18 = &result0->Sup; idtableput_301094_2984716966((&(*m0).forwtypecache), LOC17, LOC18); } break; default: { NimStringDesc* LOC20; LOC20 = (NimStringDesc*)0; LOC20 = rawNewString(reprEnum((NI)(*typ0).kind, (&NTI294244))->Sup.len + 16); appendString(LOC20, ((NimStringDesc*) &T839829468_58)); appendString(LOC20, reprEnum((NI)(*typ0).kind, (&NTI294244))); appendChar(LOC20, 41); internalerror_198113_155036129(LOC20); } break; } }BeforeRet: ; return result0; } N_NIMCALL(void, pushtype_535958_839829468)(Tcgen531027* m0, Ttype294840* typ0) { (*m0).typestack = (Ttypeseq294836*) incrSeqV2(&((*m0).typestack)->Sup, sizeof(Ttype294840*)); asgnRefNoCycle((void**) (&(*m0).typestack->data[(*m0).typestack->Sup.len]), typ0); ++(*m0).typestack->Sup.len; } N_NIMCALL(Ropeobj180006*, gettypedescweak_536079_839829468)(Tcgen531027* m0, Ttype294840* t0, Intset270030* check0) { Ropeobj180006* result0; Ttype294840* etb0; result0 = (Ropeobj180006*)0; etb0 = skiptypes_298099_850551059(t0, IL64(211106232576256)); switch ((*etb0).kind) { case ((Ttypekind294244) 17): case ((Ttypekind294244) 18): { { NIM_BOOL LOC4; LOC4 = (NIM_BOOL)0; LOC4 = isimportedcpptype_535476_839829468(etb0); if (!(LOC4)) goto LA5; LOC4 = ((*t0).kind == ((Ttypekind294244) 11)); LA5: ; if (!LOC4) goto LA6; result0 = gettypedescaux_535503_839829468(m0, t0, check0); } goto LA2; LA6: ; { Ttype294840* x0; x0 = getuniquetype_530640_2036603609(etb0); result0 = gettypeforward_536039_839829468(m0, x0); pushtype_535958_839829468(m0, x0); } LA2: ; } break; case ((Ttypekind294244) 24): { Ttype294840* x0; Ropeobj180006* LOC10; x0 = getuniquetype_530640_2036603609(etb0); LOC10 = (Ropeobj180006*)0; LOC10 = gettypeforward_536039_839829468(m0, x0); result0 = HEX26_180447_2381377266(LOC10, ((NimStringDesc*) &T839829468_53)); pushtype_535958_839829468(m0, x0); } break; default: { result0 = gettypedescaux_535503_839829468(m0, t0, check0); } break; } return result0; } static N_INLINE(NI, len_295081_850551059)(Tnode294802* n0) { NI result0; result0 = (NI)0; { if (!(*n0).kindU.S6.sons == 0) goto LA3; result0 = ((NI) 0); } goto LA1; LA3: ; { result0 = ((*n0).kindU.S6.sons ? (*n0).kindU.S6.sons->Sup.len : 0); } LA1: ; return result0; } N_NIMCALL(void, appcg_534632_839829468)(Tcgen531027* m0, Ropeobj180006** c0, NimStringDesc* frmt0, Ropeobj180006** args0, NI args0Len0) { Ropeobj180006* LOC1; LOC1 = (Ropeobj180006*)0; LOC1 = ropecg_534407_839829468(m0, frmt0, args0, args0Len0); add_180482_2381377266(c0, LOC1); } N_NIMCALL(NIM_BOOL, scancppgenericslot_536827_839829468)(NimStringDesc* pat0, NI* cursor0, NI* outidx0, NI* outstars0) { NIM_BOOL result0; NI begin0; { result0 = (NIM_BOOL)0; (*cursor0) += ((NI) 1); begin0 = (*cursor0); { while (1) { if (!((NU8)(pat0->data[(*cursor0)]) == (NU8)(42))) goto LA2; (*cursor0) += ((NI) 1); } LA2: ; } { if (!(((NU8)(pat0->data[(*cursor0)])) >= ((NU8)(48)) && ((NU8)(pat0->data[(*cursor0)])) <= ((NU8)(57)))) goto LA5; (*outidx0) = ((NI) ((NI)(((NI) (((NU8)(pat0->data[(*cursor0)])))) - ((NI) 48)))); (*outstars0) = (NI)((*cursor0) - begin0); (*cursor0) += ((NI) 1); result0 = NIM_TRUE; goto BeforeRet; } goto LA3; LA5: ; { result0 = NIM_FALSE; goto BeforeRet; } LA3: ; }BeforeRet: ; return result0; } N_NIMCALL(Ttype294840*, resolvestarsincpptype_536891_839829468)(Ttype294840* typ0, NI idx0, NI stars0) { Ttype294840* result0; result0 = (Ttype294840*)0; { NI LOC3; LOC3 = (NI)0; LOC3 = len_297339_850551059(typ0); if (!(LOC3 <= idx0)) goto LA4; internalerror_198113_155036129(((NimStringDesc*) &T839829468_81)); } LA4: ; result0 = (*typ0).sons->data[idx0]; { NI i_536906_839829468; NI res_536931_839829468; i_536906_839829468 = (NI)0; res_536931_839829468 = ((NI) 1); { while (1) { if (!(res_536931_839829468 <= stars0)) goto LA8; i_536906_839829468 = res_536931_839829468; { NIM_BOOL LOC11; NI LOC13; LOC11 = (NIM_BOOL)0; LOC11 = !((result0 == NIM_NIL)); if (!(LOC11)) goto LA12; LOC13 = (NI)0; LOC13 = len_297339_850551059(result0); LOC11 = (((NI) 0) < LOC13); LA12: ; if (!LOC11) goto LA14; { if (!((*result0).kind == ((Ttypekind294244) 11))) goto LA18; result0 = (*result0).sons->data[((NI) 1)]; } goto LA16; LA18: ; { result0 = elemtype_322394_3876443242(result0); } LA16: ; } LA14: ; res_536931_839829468 += ((NI) 1); } LA8: ; } } return result0; } N_NIMCALL(NimStringDesc*, manglefield_534973_839829468)(Tident201010* name0) { NimStringDesc* result0; result0 = (NimStringDesc*)0; result0 = mangle_530847_2036603609((*name0).s); { NIM_BOOL LOC3; LOC3 = (NIM_BOOL)0; LOC3 = iskeyword_534960_839829468(name0); if (!LOC3) goto LA4; result0->data[((NI) 0)] = nsuToUpperAsciiChar(result0->data[((NI) 0)]); } LA4: ; return result0; } N_NIMCALL(Ropeobj180006*, manglerecfieldname_536361_839829468)(Tsym294834* field0, Ttype294840* rectype0) { Ropeobj180006* result0; result0 = (Ropeobj180006*)0; { NIM_BOOL LOC3; LOC3 = (NIM_BOOL)0; LOC3 = !(((*rectype0).sym == NIM_NIL)); if (!(LOC3)) goto LA4; LOC3 = !(((96 & (*(*rectype0).sym).flags) == 0)); LA4: ; if (!LOC3) goto LA5; result0 = (*field0).loc.r; } goto LA1; LA5: ; { NimStringDesc* LOC8; LOC8 = (NimStringDesc*)0; LOC8 = manglefield_534973_839829468((*field0).name); result0 = rope_180277_2381377266(LOC8); } LA1: ; { if (!(result0 == NIM_NIL)) goto LA11; internalerror_198100_155036129((*field0).info, ((NimStringDesc*) &T839829468_96)); } LA11: ; return result0; } N_NIMCALL(Ropeobj180006*, genrecordfieldsaux_536421_839829468)(Tcgen531027* m0, Tnode294802* n0, Ropeobj180006* accessexpr0, Ttype294840* rectype0, Intset270030* check0) { Ropeobj180006* result0; Ropeobj180006* ae0; Ropeobj180006* uname0; Ropeobj180006* sname0; Ropeobj180006* a0; Tnode294802* k0; Tsym294834* field0; { result0 = (Ropeobj180006*)0; ae0 = (Ropeobj180006*)0; uname0 = (Ropeobj180006*)0; sname0 = (Ropeobj180006*)0; a0 = (Ropeobj180006*)0; k0 = (Tnode294802*)0; field0 = (Tsym294834*)0; result0 = NIM_NIL; switch ((*n0).kind) { case ((Tnodekind294020) 138): { { NI i_536447_839829468; NI HEX3Atmp_536620_839829468; NI LOC3; NI res_536623_839829468; i_536447_839829468 = (NI)0; HEX3Atmp_536620_839829468 = (NI)0; LOC3 = (NI)0; LOC3 = sonslen_297351_850551059(n0); HEX3Atmp_536620_839829468 = (NI)(LOC3 - ((NI) 1)); res_536623_839829468 = ((NI) 0); { while (1) { Ropeobj180006* LOC6; if (!(res_536623_839829468 <= HEX3Atmp_536620_839829468)) goto LA5; i_536447_839829468 = res_536623_839829468; LOC6 = (Ropeobj180006*)0; LOC6 = genrecordfieldsaux_536421_839829468(m0, (*n0).kindU.S6.sons->data[i_536447_839829468], accessexpr0, rectype0, check0); add_180482_2381377266(&result0, LOC6); res_536623_839829468 += ((NI) 1); } LA5: ; } } } break; case ((Tnodekind294020) 139): { Ropeobj180006* LOC12; NimStringDesc* LOC13; NimStringDesc* LOC14; Ropeobj180006* unionbody0; { if (!!(((*(*n0).kindU.S6.sons->data[((NI) 0)]).kind == ((Tnodekind294020) 3)))) goto LA10; internalerror_198100_155036129((*n0).info, ((NimStringDesc*) &T839829468_89)); } LA10: ; LOC12 = (Ropeobj180006*)0; LOC12 = genrecordfieldsaux_536421_839829468(m0, (*n0).kindU.S6.sons->data[((NI) 0)], accessexpr0, rectype0, check0); add_180482_2381377266(&result0, LOC12); LOC13 = (NimStringDesc*)0; LOC14 = (NimStringDesc*)0; LOC14 = mangle_530847_2036603609((*(*(*(*n0).kindU.S6.sons->data[((NI) 0)]).kindU.S4.sym).name).s); LOC13 = rawNewString(LOC14->Sup.len + 1); appendString(LOC13, LOC14); appendChar(LOC13, 85); uname0 = rope_180277_2381377266(LOC13); { TY534811 LOC19; if (!!((accessexpr0 == NIM_NIL))) goto LA17; memset((void*)LOC19, 0, sizeof(LOC19)); LOC19[0] = accessexpr0; LOC19[1] = uname0; ae0 = HEX25_180905_2381377266(((NimStringDesc*) &T839829468_90), LOC19, 2); } goto LA15; LA17: ; { ae0 = uname0; } LA15: ; unionbody0 = NIM_NIL; { NI i_536491_839829468; NI HEX3Atmp_536629_839829468; NI LOC22; NI res_536632_839829468; i_536491_839829468 = (NI)0; HEX3Atmp_536629_839829468 = (NI)0; LOC22 = (NI)0; LOC22 = sonslen_297351_850551059(n0); HEX3Atmp_536629_839829468 = (NI)(LOC22 - ((NI) 1)); res_536632_839829468 = ((NI) 1); { while (1) { if (!(res_536632_839829468 <= HEX3Atmp_536629_839829468)) goto LA24; i_536491_839829468 = res_536632_839829468; switch ((*(*n0).kindU.S6.sons->data[i_536491_839829468]).kind) { case ((Tnodekind294020) 85): case ((Tnodekind294020) 88): { k0 = lastson_297364_850551059((*n0).kindU.S6.sons->data[i_536491_839829468]); { Ropeobj180006* LOC30; TY534811 LOC31; Ropeobj180006* LOC32; if (!!(((*k0).kind == ((Tnodekind294020) 3)))) goto LA28; LOC30 = (Ropeobj180006*)0; LOC30 = rope_180401_2381377266(((NI64) (i_536491_839829468))); sname0 = HEX26_180452_2381377266(((NimStringDesc*) &T839829468_91), LOC30); memset((void*)LOC31, 0, sizeof(LOC31)); LOC31[0] = ae0; LOC31[1] = sname0; LOC32 = (Ropeobj180006*)0; LOC32 = HEX25_180905_2381377266(((NimStringDesc*) &T839829468_90), LOC31, 2); a0 = genrecordfieldsaux_536421_839829468(m0, k0, LOC32, rectype0, check0); { TY180507 LOC37; if (!!((a0 == NIM_NIL))) goto LA35; add_180487_2381377266(&unionbody0, ((NimStringDesc*) &T839829468_92)); add_180482_2381377266(&unionbody0, a0); memset((void*)LOC37, 0, sizeof(LOC37)); LOC37[0] = sname0; addf_181205_2381377266(&unionbody0, ((NimStringDesc*) &T839829468_93), LOC37, 1); } LA35: ; } goto LA26; LA28: ; { Ropeobj180006* LOC39; LOC39 = (Ropeobj180006*)0; LOC39 = genrecordfieldsaux_536421_839829468(m0, k0, ae0, rectype0, check0); add_180482_2381377266(&unionbody0, LOC39); } LA26: ; } break; default: { internalerror_198113_155036129(((NimStringDesc*) &T839829468_94)); } break; } res_536632_839829468 += ((NI) 1); } LA24: ; } } { TY534811 LOC45; if (!!((unionbody0 == NIM_NIL))) goto LA43; memset((void*)LOC45, 0, sizeof(LOC45)); LOC45[0] = unionbody0; LOC45[1] = uname0; addf_181205_2381377266(&result0, ((NimStringDesc*) &T839829468_95), LOC45, 2); } LA43: ; } break; case ((Tnodekind294020) 3): { field0 = (*n0).kindU.S4.sym; { if (!((*(*field0).typ).kind == ((Ttypekind294244) 62))) goto LA49; goto BeforeRet; } LA49: ; sname0 = manglerecfieldname_536361_839829468(field0, rectype0); { TY534811 LOC55; if (!!((accessexpr0 == NIM_NIL))) goto LA53; memset((void*)LOC55, 0, sizeof(LOC55)); LOC55[0] = accessexpr0; LOC55[1] = sname0; ae0 = HEX25_180905_2381377266(((NimStringDesc*) &T839829468_90), LOC55, 2); } goto LA51; LA53: ; { ae0 = sname0; } LA51: ; fillloc_534282_839829468((&(*field0).loc), ((Tlockind294808) 5), (*field0).typ, ae0, ((Tstorageloc294812) 0)); { NIM_BOOL LOC59; Ttype294840* fieldtype0; LOC59 = (NIM_BOOL)0; LOC59 = isimportedcpptype_535476_839829468(rectype0); if (!!(LOC59)) goto LA60; fieldtype0 = skiptypes_298099_850551059((*field0).loc.t, IL64(211106232576256)); { NIM_BOOL LOC64; TY534811 LOC68; Ttype294840* LOC69; LOC64 = (NIM_BOOL)0; LOC64 = ((*fieldtype0).kind == ((Ttypekind294244) 16)); if (!(LOC64)) goto LA65; LOC64 = (((*fieldtype0).flags &(1U<<((NU)(((Ttypeflag294431) 0))&31U)))!=0); LA65: ; if (!LOC64) goto LA66; memset((void*)LOC68, 0, sizeof(LOC68)); LOC69 = (Ttype294840*)0; LOC69 = elemtype_322394_3876443242(fieldtype0); LOC68[0] = gettypedescaux_535503_839829468(m0, LOC69, check0); LOC68[1] = sname0; addf_181205_2381377266(&result0, ((NimStringDesc*) &T839829468_97), LOC68, 2); } goto LA62; LA66: ; { TY534811 LOC73; if (!((*fieldtype0).kind == ((Ttypekind294244) 24))) goto LA71; memset((void*)LOC73, 0, sizeof(LOC73)); LOC73[0] = gettypedescweak_536079_839829468(m0, (*field0).loc.t, check0); LOC73[1] = sname0; addf_181205_2381377266(&result0, ((NimStringDesc*) &T839829468_54), LOC73, 2); } goto LA62; LA71: ; { TY537238 LOC77; NimStringDesc* LOC78; if (!!(((*field0).kindU.S4.bitsize == ((NI) 0)))) goto LA75; memset((void*)LOC77, 0, sizeof(LOC77)); LOC77[0] = gettypedescaux_535503_839829468(m0, (*field0).loc.t, check0); LOC77[1] = sname0; LOC78 = (NimStringDesc*)0; LOC78 = nimIntToStr((*field0).kindU.S4.bitsize); LOC77[2] = rope_180277_2381377266(LOC78); addf_181205_2381377266(&result0, ((NimStringDesc*) &T839829468_98), LOC77, 3); } goto LA62; LA75: ; { TY534811 LOC80; memset((void*)LOC80, 0, sizeof(LOC80)); LOC80[0] = gettypedescaux_535503_839829468(m0, (*field0).loc.t, check0); LOC80[1] = sname0; addf_181205_2381377266(&result0, ((NimStringDesc*) &T839829468_54), LOC80, 2); } LA62: ; } LA60: ; } break; default: { internalerror_198100_155036129((*n0).info, ((NimStringDesc*) &T839829468_99)); } break; } }BeforeRet: ; return result0; } N_NIMCALL(Ropeobj180006*, getrecordfields_536636_839829468)(Tcgen531027* m0, Ttype294840* typ0, Intset270030* check0) { Ropeobj180006* result0; result0 = (Ropeobj180006*)0; result0 = genrecordfieldsaux_536421_839829468(m0, (*typ0).n, NIM_NIL, typ0, check0); return result0; } N_NIMCALL(Ropeobj180006*, getrecorddesc_536643_839829468)(Tcgen531027* m0, Ttype294840* typ0, Ropeobj180006* name0, Intset270030* check0) { Ropeobj180006* result0; NIM_BOOL hasfield0; Ropeobj180006* attribute0; TY537238 LOC6; Ropeobj180006* desc0; NimStringDesc* LOC46; result0 = (Ropeobj180006*)0; hasfield0 = NIM_FALSE; { if (!(((*typ0).flags &(1U<<((NU)(((Ttypeflag294431) 21))&31U)))!=0)) goto LA3; attribute0 = rope_180277_2381377266(Cc_275413_2528170400[(ccompiler_275431_2528170400)- 1].Field19); } goto LA1; LA3: ; { attribute0 = NIM_NIL; } LA1: ; memset((void*)LOC6, 0, sizeof(LOC6)); LOC6[0] = structorunion_536001_839829468(typ0); LOC6[1] = name0; LOC6[2] = attribute0; result0 = ropecg_534407_839829468(m0, Cc_275413_2528170400[(ccompiler_275431_2528170400)- 1].Field18, LOC6, 3); { if (!((*typ0).kind == ((Ttypekind294244) 17))) goto LA9; { if (!((*typ0).sons->data[((NI) 0)] == NIM_NIL)) goto LA13; { NIM_BOOL LOC17; NIM_BOOL LOC18; TY535289 LOC23; LOC17 = (NIM_BOOL)0; LOC18 = (NIM_BOOL)0; LOC18 = !(((*typ0).sym == NIM_NIL)); if (!(LOC18)) goto LA19; LOC18 = (((*(*typ0).sym).flags &(1U<<((NU)(((Tsymflag294184) 9))&31U)))!=0); LA19: ; LOC17 = LOC18; if (LOC17) goto LA20; LOC17 = (((*typ0).flags &(1U<<((NU)(((Ttypeflag294431) 2))&31U)))!=0); LA20: ; if (!LOC17) goto LA21; memset((void*)LOC23, 0, sizeof(LOC23)); appcg_534632_839829468(m0, &result0, ((NimStringDesc*) &T839829468_85), LOC23, 0); } goto LA15; LA21: ; { TY534811 LOC25; memset((void*)LOC25, 0, sizeof(LOC25)); LOC25[0] = name0; LOC25[1] = attribute0; appcg_534632_839829468(m0, &result0, ((NimStringDesc*) &T839829468_86), LOC25, 2); hasfield0 = NIM_TRUE; } LA15: ; } goto LA11; LA13: ; { NIM_BOOL LOC27; TY180507 LOC31; Ttype294840* LOC32; LOC27 = (NIM_BOOL)0; LOC27 = (gcmd_171132_2607990831 == ((Tcommands171076) 2)); if (LOC27) goto LA28; LOC27 = (((*(*m0).module).flags &(1U<<((NU)(((Tsymflag294184) 27))&31U)))!=0); LA28: ; if (!LOC27) goto LA29; memset((void*)LOC31, 0, sizeof(LOC31)); LOC32 = (Ttype294840*)0; LOC32 = skiptypes_298099_850551059((*typ0).sons->data[((NI) 0)], IL64(211106247215360)); LOC31[0] = gettypedescaux_535503_839829468(m0, LOC32, check0); appcg_534632_839829468(m0, &result0, ((NimStringDesc*) &T839829468_87), LOC31, 1); hasfield0 = NIM_TRUE; } goto LA11; LA29: ; { TY180507 LOC34; Ttype294840* LOC35; memset((void*)LOC34, 0, sizeof(LOC34)); LOC35 = (Ttype294840*)0; LOC35 = skiptypes_298099_850551059((*typ0).sons->data[((NI) 0)], IL64(211106247215360)); LOC34[0] = gettypedescaux_535503_839829468(m0, LOC35, check0); appcg_534632_839829468(m0, &result0, ((NimStringDesc*) &T839829468_88), LOC34, 1); hasfield0 = NIM_TRUE; } LA11: ; } goto LA7; LA9: ; { TY180507 LOC37; memset((void*)LOC37, 0, sizeof(LOC37)); LOC37[0] = name0; addf_181205_2381377266(&result0, ((NimStringDesc*) &T839829468_85), LOC37, 1); } LA7: ; desc0 = getrecordfields_536636_839829468(m0, typ0, check0); { NIM_BOOL LOC40; TY535289 LOC44; LOC40 = (NIM_BOOL)0; LOC40 = (desc0 == NIM_NIL); if (!(LOC40)) goto LA41; LOC40 = !(hasfield0); LA41: ; if (!LOC40) goto LA42; memset((void*)LOC44, 0, sizeof(LOC44)); addf_181205_2381377266(&result0, ((NimStringDesc*) &T839829468_100), LOC44, 0); } goto LA38; LA42: ; { add_180482_2381377266(&result0, desc0); } LA38: ; LOC46 = (NimStringDesc*)0; LOC46 = rawNewString(tnl_178644_4151366050->Sup.len + 2); appendString(LOC46, ((NimStringDesc*) &T839829468_101)); appendString(LOC46, tnl_178644_4151366050); add_180487_2381377266(&result0, LOC46); return result0; } N_NIMCALL(Ropeobj180006*, gettupledesc_536777_839829468)(Tcgen531027* m0, Ttype294840* typ0, Ropeobj180006* name0, Intset270030* check0) { Ropeobj180006* result0; TY534811 LOC1; Ropeobj180006* desc0; NimStringDesc* LOC13; result0 = (Ropeobj180006*)0; memset((void*)LOC1, 0, sizeof(LOC1)); LOC1[0] = structorunion_536001_839829468(typ0); LOC1[1] = name0; result0 = HEX25_180905_2381377266(((NimStringDesc*) &T839829468_102), LOC1, 2); desc0 = NIM_NIL; { NI i_536799_839829468; NI HEX3Atmp_536820_839829468; NI LOC3; NI res_536823_839829468; i_536799_839829468 = (NI)0; HEX3Atmp_536820_839829468 = (NI)0; LOC3 = (NI)0; LOC3 = sonslen_297327_850551059(typ0); HEX3Atmp_536820_839829468 = (NI)(LOC3 - ((NI) 1)); res_536823_839829468 = ((NI) 0); { while (1) { TY534811 LOC6; if (!(res_536823_839829468 <= HEX3Atmp_536820_839829468)) goto LA5; i_536799_839829468 = res_536823_839829468; memset((void*)LOC6, 0, sizeof(LOC6)); LOC6[0] = gettypedescaux_535503_839829468(m0, (*typ0).sons->data[i_536799_839829468], check0); LOC6[1] = rope_180401_2381377266(((NI64) (i_536799_839829468))); addf_181205_2381377266(&desc0, ((NimStringDesc*) &T839829468_103), LOC6, 2); res_536823_839829468 += ((NI) 1); } LA5: ; } } { NimStringDesc* LOC11; if (!(desc0 == NIM_NIL)) goto LA9; LOC11 = (NimStringDesc*)0; LOC11 = rawNewString(tnl_178644_4151366050->Sup.len + 11); appendString(LOC11, ((NimStringDesc*) &T839829468_104)); appendString(LOC11, tnl_178644_4151366050); add_180487_2381377266(&result0, LOC11); } goto LA7; LA9: ; { add_180482_2381377266(&result0, desc0); } LA7: ; LOC13 = (NimStringDesc*)0; LOC13 = rawNewString(tnl_178644_4151366050->Sup.len + 2); appendString(LOC13, ((NimStringDesc*) &T839829468_101)); appendString(LOC13, tnl_178644_4151366050); add_180487_2381377266(&result0, LOC13); return result0; } N_NIMCALL(Ropeobj180006*, gettypedescaux_535503_839829468)(Tcgen531027* m0, Ttype294840* typ0, Intset270030* check0) { Ropeobj180006* result0; Ttype294840* t_536942_839829468; { result0 = (Ropeobj180006*)0; t_536942_839829468 = getuniquetype_530640_2036603609(typ0); { if (!(t_536942_839829468 == NIM_NIL)) goto LA3; internalerror_198113_155036129(((NimStringDesc*) &T839829468_27)); } LA3: ; { if (!!(((*t_536942_839829468).sym == NIM_NIL))) goto LA7; useheader_534369_839829468(m0, (*t_536942_839829468).sym); } LA7: ; result0 = gettypepre_535972_839829468(m0, t_536942_839829468); { if (!!((result0 == NIM_NIL))) goto LA11; goto BeforeRet; } LA11: ; { NIM_BOOL LOC15; LOC15 = (NIM_BOOL)0; LOC15 = containsorincl_270862_2627731572(check0, (*t_536942_839829468).Sup.id); if (!LOC15) goto LA16; { NIM_BOOL LOC20; NimStringDesc* LOC24; NimStringDesc* LOC25; LOC20 = (NIM_BOOL)0; LOC20 = isimportedcpptype_535476_839829468(typ0); if (LOC20) goto LA21; LOC20 = isimportedcpptype_535476_839829468(t_536942_839829468); LA21: ; if (!!(LOC20)) goto LA22; LOC24 = (NimStringDesc*)0; LOC25 = (NimStringDesc*)0; LOC25 = typetostring_322017_3876443242(typ0, ((Tprefereddesc322011) 0)); LOC24 = rawNewString(LOC25->Sup.len + 28); appendString(LOC24, ((NimStringDesc*) &T839829468_51)); appendString(LOC24, LOC25); internalerror_198113_155036129(LOC24); } LA22: ; } LA16: ; switch ((*t_536942_839829468).kind) { case ((Ttypekind294244) 22): case ((Ttypekind294244) 21): case ((Ttypekind294244) 23): { NimStringDesc* star0; Ttype294840* et0; Ttype294840* LOC38; Ttype294840* etb0; { NIM_BOOL LOC29; NIM_BOOL LOC30; NIM_BOOL LOC33; LOC29 = (NIM_BOOL)0; LOC30 = (NIM_BOOL)0; LOC30 = ((*t_536942_839829468).kind == ((Ttypekind294244) 23)); if (!(LOC30)) goto LA31; LOC30 = !((((*typ0).flags &(1U<<((NU)(((Ttypeflag294431) 18))&31U)))!=0)); LA31: ; LOC29 = LOC30; if (!(LOC29)) goto LA32; LOC33 = (NIM_BOOL)0; LOC33 = (gcmd_171132_2607990831 == ((Tcommands171076) 2)); if (LOC33) goto LA34; LOC33 = (((*(*m0).module).flags &(1U<<((NU)(((Tsymflag294184) 27))&31U)))!=0); LA34: ; LOC29 = LOC33; LA32: ; if (!LOC29) goto LA35; star0 = copyString(((NimStringDesc*) &T839829468_52)); } goto LA27; LA35: ; { star0 = copyString(((NimStringDesc*) &T839829468_53)); } LA27: ; LOC38 = (Ttype294840*)0; LOC38 = skiptypes_298099_850551059(typ0, IL64(211106232576256)); et0 = lastson_297377_850551059(LOC38); etb0 = skiptypes_298099_850551059(et0, IL64(211106232576256)); { if (!((*etb0).kind == ((Ttypekind294244) 4) || (*etb0).kind == ((Ttypekind294244) 16) || (*etb0).kind == ((Ttypekind294244) 27) || (*etb0).kind == ((Ttypekind294244) 48))) goto LA41; et0 = elemtype_322394_3876443242(etb0); etb0 = skiptypes_298099_850551059(et0, IL64(211106232576256)); star0->data[((NI) 0)] = 42; } LA41: ; switch ((*etb0).kind) { case ((Ttypekind294244) 17): case ((Ttypekind294244) 18): { { NIM_BOOL LOC46; Ropeobj180006* LOC50; LOC46 = (NIM_BOOL)0; LOC46 = isimportedcpptype_535476_839829468(etb0); if (!(LOC46)) goto LA47; LOC46 = ((*et0).kind == ((Ttypekind294244) 11)); LA47: ; if (!LOC46) goto LA48; LOC50 = (Ropeobj180006*)0; LOC50 = gettypedescaux_535503_839829468(m0, et0, check0); result0 = HEX26_180447_2381377266(LOC50, star0); } goto LA44; LA48: ; { Ttype294840* x0; Ropeobj180006* name0; Tidobj201004* LOC52; TNimObject* LOC53; x0 = getuniquetype_530640_2036603609(etb0); name0 = gettypeforward_536039_839829468(m0, x0); result0 = HEX26_180447_2381377266(name0, star0); LOC52 = (Tidobj201004*)0; LOC52 = &t_536942_839829468->Sup; LOC53 = (TNimObject*)0; LOC53 = &result0->Sup; idtableput_301094_2984716966((&(*m0).typecache), LOC52, LOC53); pushtype_535958_839829468(m0, x0); } LA44: ; } break; case ((Ttypekind294244) 24): { Ttype294840* x0; Ropeobj180006* name0; Ropeobj180006* LOC55; Tidobj201004* LOC56; TNimObject* LOC57; x0 = getuniquetype_530640_2036603609(etb0); name0 = gettypeforward_536039_839829468(m0, x0); LOC55 = (Ropeobj180006*)0; LOC55 = HEX26_180447_2381377266(name0, ((NimStringDesc*) &T839829468_53)); result0 = HEX26_180447_2381377266(LOC55, star0); LOC56 = (Tidobj201004*)0; LOC56 = &t_536942_839829468->Sup; LOC57 = (TNimObject*)0; LOC57 = &result0->Sup; idtableput_301094_2984716966((&(*m0).typecache), LOC56, LOC57); pushtype_535958_839829468(m0, x0); } break; default: { Ropeobj180006* LOC59; Tidobj201004* LOC60; TNimObject* LOC61; LOC59 = (Ropeobj180006*)0; LOC59 = gettypedescaux_535503_839829468(m0, et0, check0); result0 = HEX26_180447_2381377266(LOC59, star0); LOC60 = (Tidobj201004*)0; LOC60 = &t_536942_839829468->Sup; LOC61 = (TNimObject*)0; LOC61 = &result0->Sup; idtableput_301094_2984716966((&(*m0).typecache), LOC60, LOC61); } break; } } break; case ((Ttypekind294244) 27): case ((Ttypekind294244) 48): { Ropeobj180006* LOC63; Tidobj201004* LOC64; TNimObject* LOC65; LOC63 = (Ropeobj180006*)0; LOC63 = gettypedescweak_536079_839829468(m0, (*t_536942_839829468).sons->data[((NI) 0)], check0); result0 = HEX26_180447_2381377266(LOC63, ((NimStringDesc*) &T839829468_53)); LOC64 = (Tidobj201004*)0; LOC64 = &t_536942_839829468->Sup; LOC65 = (TNimObject*)0; LOC65 = &result0->Sup; idtableput_301094_2984716966((&(*m0).typecache), LOC64, LOC65); } break; case ((Ttypekind294244) 20): case ((Ttypekind294244) 14): { Ttype294840* t0; { if (!((*t_536942_839829468).kind == ((Ttypekind294244) 20))) goto LA69; t0 = lastson_297377_850551059(t_536942_839829468); } goto LA67; LA69: ; { t0 = t_536942_839829468; } LA67: ; result0 = cachegettype_535591_839829468((*m0).typecache, t0); { if (!(result0 == NIM_NIL)) goto LA74; result0 = gettypename_535313_839829468(t0); { NIM_BOOL LOC78; NIM_BOOL LOC80; Tidobj201004* LOC84; TNimObject* LOC85; NI size0; NU32 owner0; LOC78 = (NIM_BOOL)0; LOC78 = isimportedcpptype_535476_839829468(t0); if (LOC78) goto LA79; LOC80 = (NIM_BOOL)0; LOC80 = (((*(*t0).sym).flags &(1U<<((NU)(((Tsymflag294184) 5))&31U)))!=0); if (!(LOC80)) goto LA81; LOC80 = ((*(*t0).sym).magic == ((Tmagic294524) 0)); LA81: ; LOC78 = LOC80; LA79: ; if (!!(LOC78)) goto LA82; LOC84 = (Tidobj201004*)0; LOC84 = &t0->Sup; LOC85 = (TNimObject*)0; LOC85 = &result0->Sup; idtableput_301094_2984716966((&(*m0).typecache), LOC84, LOC85); size0 = (NI)0; { NI64 LOC88; TY180507 LOC91; LOC88 = (NI64)0; LOC88 = firstord_322001_3876443242(t0); if (!(LOC88 < IL64(0))) goto LA89; memset((void*)LOC91, 0, sizeof(LOC91)); LOC91[0] = result0; addf_181205_2381377266(&(*m0).s[(((Tcfilesection531005) 3))- 0], ((NimStringDesc*) &T839829468_59), LOC91, 1); size0 = ((NI) 4); } goto LA86; LA89: ; { NI64 LOC93; LOC93 = (NI64)0; LOC93 = getsize_322135_3876443242(t0); size0 = ((NI) (LOC93)); switch (size0) { case ((NI) 1): { TY180507 LOC95; memset((void*)LOC95, 0, sizeof(LOC95)); LOC95[0] = result0; addf_181205_2381377266(&(*m0).s[(((Tcfilesection531005) 3))- 0], ((NimStringDesc*) &T839829468_60), LOC95, 1); } break; case ((NI) 2): { TY180507 LOC97; memset((void*)LOC97, 0, sizeof(LOC97)); LOC97[0] = result0; addf_181205_2381377266(&(*m0).s[(((Tcfilesection531005) 3))- 0], ((NimStringDesc*) &T839829468_61), LOC97, 1); } break; case ((NI) 4): { TY180507 LOC99; memset((void*)LOC99, 0, sizeof(LOC99)); LOC99[0] = result0; addf_181205_2381377266(&(*m0).s[(((Tcfilesection531005) 3))- 0], ((NimStringDesc*) &T839829468_59), LOC99, 1); } break; case ((NI) 8): { TY180507 LOC101; memset((void*)LOC101, 0, sizeof(LOC101)); LOC101[0] = result0; addf_181205_2381377266(&(*m0).s[(((Tcfilesection531005) 3))- 0], ((NimStringDesc*) &T839829468_62), LOC101, 1); } break; default: { internalerror_198100_155036129((*(*t0).sym).info, ((NimStringDesc*) &T839829468_63)); } break; } } LA86: ; owner0 = hashowner_534977_839829468((*t0).sym); { NIM_BOOL LOC105; TY205017* vals0; Enumdesc205007 LOC114; LOC105 = (NIM_BOOL)0; LOC105 = hasenum_205230_1926258066(gdebuginfo_205470_1926258066, (*(*(*t0).sym).name).s, ((NI) ((*(*t0).sym).info.line)), owner0); if (!!(LOC105)) goto LA106; vals0 = (TY205017*) newSeq((&NTI205017), 0); { NI i_537144_839829468; NI HEX3Atmp_537648_839829468; NI LOC109; NI res_537651_839829468; i_537144_839829468 = (NI)0; HEX3Atmp_537648_839829468 = (NI)0; LOC109 = (NI)0; LOC109 = len_295081_850551059((*t0).n); HEX3Atmp_537648_839829468 = (NI)(LOC109 - ((NI) 1)); res_537651_839829468 = ((NI) 0); { while (1) { Tsym294834* field0; TY205018 LOC112; NimStringDesc* LOC113; if (!(res_537651_839829468 <= HEX3Atmp_537648_839829468)) goto LA111; i_537144_839829468 = res_537651_839829468; field0 = (*(*(*t0).n).kindU.S6.sons->data[i_537144_839829468]).kindU.S4.sym; memset((void*)(&LOC112), 0, sizeof(LOC112)); LOC112.Field0 = copyString((*(*field0).name).s); LOC112.Field1 = (*field0).position; vals0 = (TY205017*) incrSeqV2(&(vals0)->Sup, sizeof(TY205018)); LOC113 = (NimStringDesc*)0; LOC113 = vals0->data[vals0->Sup.len].Field0; vals0->data[vals0->Sup.len].Field0 = copyStringRC1(LOC112.Field0); if (LOC113) nimGCunrefNoCycle(LOC113); vals0->data[vals0->Sup.len].Field1 = LOC112.Field1; ++vals0->Sup.len; res_537651_839829468 += ((NI) 1); } LA111: ; } } memset((void*)(&LOC114), 0, sizeof(LOC114)); memset((void*)(&LOC114), 0, sizeof(LOC114)); LOC114.size = size0; LOC114.owner = owner0; LOC114.id = (*(*t0).sym).Sup.id; LOC114.name = copyString((*(*(*t0).sym).name).s); genericSeqAssign((&LOC114.values), vals0, (&NTI205017)); registerenum_205419_1926258066((&gdebuginfo_205470_1926258066), (&LOC114)); } LA106: ; } LA82: ; } LA74: ; } break; case ((Ttypekind294244) 25): { Tidobj201004* LOC116; TNimObject* LOC117; Ropeobj180006* rettype0; Ropeobj180006* desc0; result0 = gettypename_535313_839829468(t_536942_839829468); LOC116 = (Tidobj201004*)0; LOC116 = &t_536942_839829468->Sup; LOC117 = (TNimObject*)0; LOC117 = &result0->Sup; idtableput_301094_2984716966((&(*m0).typecache), LOC116, LOC117); rettype0 = (Ropeobj180006*)0; desc0 = (Ropeobj180006*)0; genprocparams_536115_839829468(m0, t_536942_839829468, &rettype0, &desc0, check0, NIM_TRUE, NIM_TRUE); { NIM_BOOL LOC120; LOC120 = (NIM_BOOL)0; LOC120 = isimportedtype_535449_839829468(t_536942_839829468); if (!!(LOC120)) goto LA121; { TY537235 LOC127; if (!!(((*t_536942_839829468).callconv == ((Tcallingconvention294002) 8)))) goto LA125; memset((void*)LOC127, 0, sizeof(LOC127)); LOC127[0] = rope_180277_2381377266(Callingconvtostr_535585_839829468[((*t_536942_839829468).callconv)- 0]); LOC127[1] = rettype0; LOC127[2] = result0; LOC127[3] = desc0; addf_181205_2381377266(&(*m0).s[(((Tcfilesection531005) 3))- 0], ((NimStringDesc*) &T839829468_64), LOC127, 4); } goto LA123; LA125: ; { TY537238 LOC129; memset((void*)LOC129, 0, sizeof(LOC129)); LOC129[0] = result0; LOC129[1] = rettype0; LOC129[2] = desc0; addf_181205_2381377266(&(*m0).s[(((Tcfilesection531005) 3))- 0], ((NimStringDesc*) &T839829468_75), LOC129, 3); } LA123: ; } LA121: ; } break; case ((Ttypekind294244) 24): { Tidobj201004* LOC144; Ropeobj180006* LOC145; TNimObject* LOC146; result0 = cachegettype_535591_839829468((*m0).forwtypecache, t_536942_839829468); { Tidobj201004* LOC142; TNimObject* LOC143; if (!(result0 == NIM_NIL)) goto LA133; result0 = gettypename_535313_839829468(t_536942_839829468); { NIM_BOOL LOC137; NimStringDesc* LOC140; TY534811 LOC141; LOC137 = (NIM_BOOL)0; LOC137 = isimportedtype_535449_839829468(t_536942_839829468); if (!!(LOC137)) goto LA138; LOC140 = (NimStringDesc*)0; LOC140 = getforwardstructformat_536015_839829468(m0); memset((void*)LOC141, 0, sizeof(LOC141)); LOC141[0] = structorunion_536001_839829468(t_536942_839829468); LOC141[1] = result0; addf_181205_2381377266(&(*m0).s[(((Tcfilesection531005) 2))- 0], LOC140, LOC141, 2); } LA138: ; LOC142 = (Tidobj201004*)0; LOC142 = &t_536942_839829468->Sup; LOC143 = (TNimObject*)0; LOC143 = &result0->Sup; idtableput_301094_2984716966((&(*m0).forwtypecache), LOC142, LOC143); } LA133: ; LOC144 = (Tidobj201004*)0; LOC144 = &t_536942_839829468->Sup; LOC145 = (Ropeobj180006*)0; LOC145 = HEX26_180447_2381377266(result0, ((NimStringDesc*) &T839829468_53)); LOC146 = (TNimObject*)0; LOC146 = &LOC145->Sup; idtableput_301094_2984716966((&(*m0).typecache), LOC144, LOC146); { NIM_BOOL LOC149; LOC149 = (NIM_BOOL)0; LOC149 = isimportedtype_535449_839829468(t_536942_839829468); if (!!(LOC149)) goto LA150; { Ttype294840* LOC154; NimStringDesc* LOC157; NimStringDesc* LOC158; TY534811 LOC166; LOC154 = (Ttype294840*)0; LOC154 = skiptypes_298099_850551059((*t_536942_839829468).sons->data[((NI) 0)], IL64(211106232576256)); if (!!(((*LOC154).kind == ((Ttypekind294244) 3)))) goto LA155; LOC157 = (NimStringDesc*)0; LOC158 = (NimStringDesc*)0; { NIM_BOOL LOC161; LOC161 = (NIM_BOOL)0; LOC161 = (gcmd_171132_2607990831 == ((Tcommands171076) 2)); if (LOC161) goto LA162; LOC161 = (((*(*m0).module).flags &(1U<<((NU)(((Tsymflag294184) 27))&31U)))!=0); LA162: ; if (!LOC161) goto LA163; LOC158 = copyString(((NimStringDesc*) &T839829468_76)); } goto LA159; LA163: ; { LOC158 = copyString(((NimStringDesc*) &T839829468_77)); } LA159: ; LOC157 = rawNewString(LOC158->Sup.len + 31); appendString(LOC157, LOC158); appendString(LOC157, ((NimStringDesc*) &T839829468_78)); memset((void*)LOC166, 0, sizeof(LOC166)); LOC166[0] = gettypedescaux_535503_839829468(m0, (*t_536942_839829468).sons->data[((NI) 0)], check0); LOC166[1] = result0; appcg_534632_839829468(m0, &(*m0).s[(((Tcfilesection531005) 4))- 0], LOC157, LOC166, 2); } goto LA152; LA155: ; { result0 = rope_180277_2381377266(((NimStringDesc*) &T839829468_79)); } LA152: ; } LA150: ; add_180487_2381377266(&result0, ((NimStringDesc*) &T839829468_53)); } break; case ((Ttypekind294244) 4): case ((Ttypekind294244) 16): { NI64 n0; Tidobj201004* LOC173; TNimObject* LOC174; n0 = lengthord_322007_3876443242(t_536942_839829468); { if (!(n0 <= IL64(0))) goto LA171; n0 = IL64(1); } LA171: ; result0 = gettypename_535313_839829468(t_536942_839829468); LOC173 = (Tidobj201004*)0; LOC173 = &t_536942_839829468->Sup; LOC174 = (TNimObject*)0; LOC174 = &result0->Sup; idtableput_301094_2984716966((&(*m0).typecache), LOC173, LOC174); { NIM_BOOL LOC177; Ropeobj180006* foo0; TY537238 LOC180; LOC177 = (NIM_BOOL)0; LOC177 = isimportedtype_535449_839829468(t_536942_839829468); if (!!(LOC177)) goto LA178; foo0 = gettypedescaux_535503_839829468(m0, (*t_536942_839829468).sons->data[((NI) 1)], check0); memset((void*)LOC180, 0, sizeof(LOC180)); LOC180[0] = foo0; LOC180[1] = result0; LOC180[2] = rope_180401_2381377266(n0); addf_181205_2381377266(&(*m0).s[(((Tcfilesection531005) 3))- 0], ((NimStringDesc*) &T839829468_80), LOC180, 3); } LA178: ; } break; case ((Ttypekind294244) 17): case ((Ttypekind294244) 18): { { NIM_BOOL LOC184; Ropeobj180006* cppname0; NI i0; NI chunkstart0; Ropeobj180006* LOC226; LOC184 = (NIM_BOOL)0; LOC184 = isimportedcpptype_535476_839829468(t_536942_839829468); if (!(LOC184)) goto LA185; LOC184 = ((*typ0).kind == ((Ttypekind294244) 11)); LA185: ; if (!LOC184) goto LA186; cppname0 = gettypename_535313_839829468(t_536942_839829468); i0 = ((NI) 0); chunkstart0 = ((NI) 0); { while (1) { if (!(i0 < ((*cppname0).data ? (*cppname0).data->Sup.len : 0))) goto LA189; { NI chunkend0; NI idx0; NI stars0; if (!((NU8)((*cppname0).data->data[i0]) == (NU8)(39))) goto LA192; chunkend0 = (i0 - 1); idx0 = (NI)0; stars0 = (NI)0; { NIM_BOOL LOC196; NimStringDesc* LOC199; Ttype294840* typeinslot0; LOC196 = (NIM_BOOL)0; LOC196 = scancppgenericslot_536827_839829468((*cppname0).data, (&i0), (&idx0), (&stars0)); if (!LOC196) goto LA197; LOC199 = (NimStringDesc*)0; LOC199 = copyStrLast((*cppname0).data, chunkstart0, chunkend0); add_180487_2381377266(&result0, LOC199); chunkstart0 = i0; typeinslot0 = resolvestarsincpptype_536891_839829468(typ0, (NI)(idx0 + ((NI) 1)), stars0); { NIM_BOOL LOC202; TY535289 LOC206; Ropeobj180006* LOC207; LOC202 = (NIM_BOOL)0; LOC202 = (typeinslot0 == NIM_NIL); if (LOC202) goto LA203; LOC202 = ((*typeinslot0).kind == ((Ttypekind294244) 62)); LA203: ; if (!LOC202) goto LA204; memset((void*)LOC206, 0, sizeof(LOC206)); LOC207 = (Ropeobj180006*)0; LOC207 = HEX25_180905_2381377266(((NimStringDesc*) &T839829468_26), LOC206, 0); add_180482_2381377266(&result0, LOC207); } goto LA200; LA204: ; { Ropeobj180006* LOC209; LOC209 = (Ropeobj180006*)0; LOC209 = gettypedescaux_535503_839829468(m0, typeinslot0, check0); add_180482_2381377266(&result0, LOC209); } LA200: ; } LA197: ; } goto LA190; LA192: ; { i0 += ((NI) 1); } LA190: ; } LA189: ; } { NimStringDesc* LOC215; if (!!((chunkstart0 == ((NI) 0)))) goto LA213; LOC215 = (NimStringDesc*)0; LOC215 = copyStr((*cppname0).data, chunkstart0); add_180487_2381377266(&result0, LOC215); } goto LA211; LA213: ; { result0 = HEX26_180447_2381377266(cppname0, ((NimStringDesc*) &T839829468_82)); { NI i_537516_839829468; NI HEX3Atmp_537664_839829468; NI LOC218; NI res_537667_839829468; i_537516_839829468 = (NI)0; HEX3Atmp_537664_839829468 = (NI)0; LOC218 = (NI)0; LOC218 = len_297339_850551059(typ0); HEX3Atmp_537664_839829468 = (NI)(LOC218 - ((NI) 2)); res_537667_839829468 = ((NI) 1); { while (1) { Ropeobj180006* LOC225; if (!(res_537667_839829468 <= HEX3Atmp_537664_839829468)) goto LA220; i_537516_839829468 = res_537667_839829468; { if (!(((NI) 1) < i_537516_839829468)) goto LA223; add_180487_2381377266(&result0, ((NimStringDesc*) &T839829468_83)); } LA223: ; LOC225 = (Ropeobj180006*)0; LOC225 = gettypedescaux_535503_839829468(m0, (*typ0).sons->data[i_537516_839829468], check0); add_180482_2381377266(&result0, LOC225); res_537667_839829468 += ((NI) 1); } LA220: ; } } add_180487_2381377266(&result0, ((NimStringDesc*) &T839829468_84)); } LA211: ; LOC226 = (Ropeobj180006*)0; LOC226 = getrecorddesc_536643_839829468(m0, t_536942_839829468, result0, check0); } goto LA182; LA186: ; { Tidobj201004* LOC241; TNimObject* LOC242; Ropeobj180006* recdesc0; result0 = cachegettype_535591_839829468((*m0).forwtypecache, t_536942_839829468); { Tidobj201004* LOC239; TNimObject* LOC240; if (!(result0 == NIM_NIL)) goto LA230; result0 = gettypename_535313_839829468(t_536942_839829468); { NIM_BOOL LOC234; NimStringDesc* LOC237; TY534811 LOC238; LOC234 = (NIM_BOOL)0; LOC234 = isimportedtype_535449_839829468(t_536942_839829468); if (!!(LOC234)) goto LA235; LOC237 = (NimStringDesc*)0; LOC237 = getforwardstructformat_536015_839829468(m0); memset((void*)LOC238, 0, sizeof(LOC238)); LOC238[0] = structorunion_536001_839829468(t_536942_839829468); LOC238[1] = result0; addf_181205_2381377266(&(*m0).s[(((Tcfilesection531005) 2))- 0], LOC237, LOC238, 2); } LA235: ; LOC239 = (Tidobj201004*)0; LOC239 = &t_536942_839829468->Sup; LOC240 = (TNimObject*)0; LOC240 = &result0->Sup; idtableput_301094_2984716966((&(*m0).forwtypecache), LOC239, LOC240); } LA230: ; LOC241 = (Tidobj201004*)0; LOC241 = &t_536942_839829468->Sup; LOC242 = (TNimObject*)0; LOC242 = &result0->Sup; idtableput_301094_2984716966((&(*m0).typecache), LOC241, LOC242); { if (!!(((*t_536942_839829468).kind == ((Ttypekind294244) 18)))) goto LA245; recdesc0 = getrecorddesc_536643_839829468(m0, t_536942_839829468, result0, check0); } goto LA243; LA245: ; { recdesc0 = gettupledesc_536777_839829468(m0, t_536942_839829468, result0, check0); } LA243: ; { NIM_BOOL LOC250; LOC250 = (NIM_BOOL)0; LOC250 = isimportedtype_535449_839829468(t_536942_839829468); if (!!(LOC250)) goto LA251; add_180482_2381377266(&(*m0).s[(((Tcfilesection531005) 3))- 0], recdesc0); } LA251: ; } LA182: ; } break; case ((Ttypekind294244) 19): { Ttype294840* LOC254; Ropeobj180006* LOC255; Tidobj201004* LOC256; TNimObject* LOC257; LOC254 = (Ttype294840*)0; LOC254 = lastson_297377_850551059(t_536942_839829468); LOC255 = (Ropeobj180006*)0; LOC255 = gettypename_535313_839829468(LOC254); result0 = HEX26_180447_2381377266(LOC255, ((NimStringDesc*) &T839829468_105)); LOC256 = (Tidobj201004*)0; LOC256 = &t_536942_839829468->Sup; LOC257 = (TNimObject*)0; LOC257 = &result0->Sup; idtableput_301094_2984716966((&(*m0).typecache), LOC256, LOC257); { NIM_BOOL LOC260; NI s0; NI64 LOC263; LOC260 = (NIM_BOOL)0; LOC260 = isimportedtype_535449_839829468(t_536942_839829468); if (!!(LOC260)) goto LA261; LOC263 = (NI64)0; LOC263 = getsize_322135_3876443242(t_536942_839829468); s0 = ((NI) (LOC263)); switch (s0) { case ((NI) 1): case ((NI) 2): case ((NI) 4): case ((NI) 8): { TY534811 LOC265; memset((void*)LOC265, 0, sizeof(LOC265)); LOC265[0] = result0; LOC265[1] = rope_180401_2381377266(((NI64) ((NI)(s0 * ((NI) 8))))); addf_181205_2381377266(&(*m0).s[(((Tcfilesection531005) 3))- 0], ((NimStringDesc*) &T839829468_106), LOC265, 2); } break; default: { TY534811 LOC267; NI64 LOC268; memset((void*)LOC267, 0, sizeof(LOC267)); LOC267[0] = result0; LOC268 = (NI64)0; LOC268 = getsize_322135_3876443242(t_536942_839829468); LOC267[1] = rope_180401_2381377266(LOC268); addf_181205_2381377266(&(*m0).s[(((Tcfilesection531005) 3))- 0], ((NimStringDesc*) &T839829468_107), LOC267, 2); } break; } } LA261: ; } break; case ((Ttypekind294244) 11): case ((Ttypekind294244) 13): case ((Ttypekind294244) 15): case ((Ttypekind294244) 46): case ((Ttypekind294244) 47): case ((Ttypekind294244) 49): case ((Ttypekind294244) 8): { Ttype294840* LOC270; LOC270 = (Ttype294840*)0; LOC270 = lastson_297377_850551059(t_536942_839829468); result0 = gettypedescaux_535503_839829468(m0, LOC270, check0); } break; default: { NimStringDesc* LOC272; LOC272 = (NimStringDesc*)0; LOC272 = rawNewString(reprEnum((NI)(*t_536942_839829468).kind, (&NTI294244))->Sup.len + 16); appendString(LOC272, ((NimStringDesc*) &T839829468_108)); appendString(LOC272, reprEnum((NI)(*t_536942_839829468).kind, (&NTI294244))); appendChar(LOC272, 41); internalerror_198113_155036129(LOC272); result0 = NIM_NIL; } break; } excl_270841_2627731572(check0, (*t_536942_839829468).Sup.id); }BeforeRet: ; return result0; } static N_INLINE(NIM_BOOL, iscompiletimeonly_330706_3876443242)(Ttype294840* t0) { NIM_BOOL result0; result0 = (NIM_BOOL)0; result0 = ((*t0).kind == ((Ttypekind294244) 8) || (*t0).kind == ((Ttypekind294244) 59)); return result0; } N_NIMCALL(Tstorageloc294812, paramstorageloc_536098_839829468)(Tsym294834* param0) { Tstorageloc294812 result0; result0 = (Tstorageloc294812)0; { Ttype294840* LOC3; LOC3 = (Ttype294840*)0; LOC3 = skiptypes_298099_850551059((*param0).typ, 8388864); if (!!(((*LOC3).kind == ((Ttypekind294244) 16) || (*LOC3).kind == ((Ttypekind294244) 27) || (*LOC3).kind == ((Ttypekind294244) 48) || (*LOC3).kind == ((Ttypekind294244) 4)))) goto LA4; result0 = ((Tstorageloc294812) 2); } goto LA1; LA4: ; { result0 = ((Tstorageloc294812) 0); } LA1: ; return result0; } N_NIMCALL(NIM_BOOL, ccgintroducedptr_535609_839829468)(Tsym294834* s0) { NIM_BOOL result0; Ttype294840* pt0; { result0 = (NIM_BOOL)0; pt0 = skiptypes_298099_850551059((*s0).typ, IL64(211106232576256)); { if (!(((*pt0).flags &(1U<<((NU)(((Ttypeflag294431) 13))&31U)))!=0)) goto LA3; result0 = NIM_TRUE; goto BeforeRet; } goto LA1; LA3: ; { if (!(((*pt0).flags &(1U<<((NU)(((Ttypeflag294431) 12))&31U)))!=0)) goto LA6; result0 = NIM_FALSE; goto BeforeRet; } goto LA1; LA6: ; LA1: ; switch ((*pt0).kind) { case ((Ttypekind294244) 17): { { NIM_BOOL LOC11; NI64 LOC13; LOC11 = (NIM_BOOL)0; LOC11 = (((*s0).options &(1U<<((NU)(((Toption171009) 18))&31U)))!=0); if (LOC11) goto LA12; LOC13 = (NI64)0; LOC13 = getsize_322135_3876443242(pt0); LOC11 = (((NI64) ((NI)(floatsize_178642_4151366050 * ((NI) 2)))) < LOC13); LA12: ; if (!LOC11) goto LA14; result0 = NIM_TRUE; } goto LA9; LA14: ; { NIM_BOOL LOC17; LOC17 = (NIM_BOOL)0; LOC17 = (((*pt0).flags &(1U<<((NU)(((Ttypeflag294431) 2))&31U)))!=0); if (!(LOC17)) goto LA18; LOC17 = ((*pt0).sons->data[((NI) 0)] == NIM_NIL); LA18: ; if (!LOC17) goto LA19; result0 = NIM_FALSE; } goto LA9; LA19: ; { result0 = NIM_TRUE; } LA9: ; } break; case ((Ttypekind294244) 18): { NIM_BOOL LOC23; NI64 LOC24; LOC23 = (NIM_BOOL)0; LOC24 = (NI64)0; LOC24 = getsize_322135_3876443242(pt0); LOC23 = (((NI64) ((NI)(floatsize_178642_4151366050 * ((NI) 2)))) < LOC24); if (LOC23) goto LA25; LOC23 = (((*s0).options &(1U<<((NU)(((Toption171009) 18))&31U)))!=0); LA25: ; result0 = LOC23; } break; default: { result0 = NIM_FALSE; } break; } }BeforeRet: ; return result0; } N_NIMCALL(Tctypekind531007, mapreturntype_535445_839829468)(Ttype294840* typ0) { Tctypekind531007 result0; result0 = (Tctypekind531007)0; result0 = maptype_535393_839829468(typ0); return result0; } N_NIMCALL(void, genprocparams_536115_839829468)(Tcgen531027* m0, Ttype294840* t0, Ropeobj180006** rettype0, Ropeobj180006** params0, Intset270030* check0, NIM_BOOL declareenvironment0, NIM_BOOL weakdep0) { unsureAsgnRef((void**) (&(*params0)), NIM_NIL); { NIM_BOOL LOC3; TY535289 LOC7; LOC3 = (NIM_BOOL)0; LOC3 = ((*t0).sons->data[((NI) 0)] == NIM_NIL); if (LOC3) goto LA4; LOC3 = isinvalidreturntype_535548_839829468((*t0).sons->data[((NI) 0)]); LA4: ; if (!LOC3) goto LA5; memset((void*)LOC7, 0, sizeof(LOC7)); unsureAsgnRef((void**) (&(*rettype0)), HEX25_180905_2381377266(((NimStringDesc*) &T839829468_26), LOC7, 0)); } goto LA1; LA5: ; { unsureAsgnRef((void**) (&(*rettype0)), gettypedescaux_535503_839829468(m0, (*t0).sons->data[((NI) 0)], check0)); } LA1: ; { NI i_536152_839829468; NI HEX3Atmp_536353_839829468; NI LOC10; NI res_536356_839829468; i_536152_839829468 = (NI)0; HEX3Atmp_536353_839829468 = (NI)0; LOC10 = (NI)0; LOC10 = sonslen_297351_850551059((*t0).n); HEX3Atmp_536353_839829468 = (NI)(LOC10 - ((NI) 1)); res_536356_839829468 = ((NI) 1); { while (1) { if (!(res_536356_839829468 <= HEX3Atmp_536353_839829468)) goto LA12; i_536152_839829468 = res_536356_839829468; { Tsym294834* param0; Ropeobj180006* LOC29; Tstorageloc294812 LOC30; TY535289 LOC45; Ropeobj180006* LOC46; Ttype294840* arr0; NI j0; { if (!!(((*(*(*t0).n).kindU.S6.sons->data[i_536152_839829468]).kind == ((Tnodekind294020) 3)))) goto LA16; internalerror_198100_155036129((*(*t0).n).info, ((NimStringDesc*) &T839829468_109)); } LA16: ; param0 = (*(*(*t0).n).kindU.S6.sons->data[i_536152_839829468]).kindU.S4.sym; { NIM_BOOL LOC20; LOC20 = (NIM_BOOL)0; LOC20 = iscompiletimeonly_330706_3876443242((*param0).typ); if (!LOC20) goto LA21; goto LA13; } LA21: ; { TY535289 LOC27; Ropeobj180006* LOC28; if (!!(((*params0) == NIM_NIL))) goto LA25; memset((void*)LOC27, 0, sizeof(LOC27)); LOC28 = (Ropeobj180006*)0; LOC28 = HEX25_180905_2381377266(((NimStringDesc*) &T839829468_110), LOC27, 0); add_180482_2381377266(params0, LOC28); } LA25: ; LOC29 = (Ropeobj180006*)0; LOC29 = manglename_535205_839829468(param0); LOC30 = (Tstorageloc294812)0; LOC30 = paramstorageloc_536098_839829468(param0); fillloc_534282_839829468((&(*param0).loc), ((Tlockind294808) 4), (*param0).typ, LOC29, LOC30); { NIM_BOOL LOC33; Ropeobj180006* LOC36; TY535289 LOC37; Ropeobj180006* LOC38; LOC33 = (NIM_BOOL)0; LOC33 = ccgintroducedptr_535609_839829468(param0); if (!LOC33) goto LA34; LOC36 = (Ropeobj180006*)0; LOC36 = gettypedescweak_536079_839829468(m0, (*param0).typ, check0); add_180482_2381377266(params0, LOC36); memset((void*)LOC37, 0, sizeof(LOC37)); LOC38 = (Ropeobj180006*)0; LOC38 = HEX25_180905_2381377266(((NimStringDesc*) &T839829468_53), LOC37, 0); add_180482_2381377266(params0, LOC38); (*param0).loc.flags |= ((NU16)1)<<((((Tlocflag294810) 0))%(sizeof(NU16)*8)); (*param0).loc.s = ((Tstorageloc294812) 0); } goto LA31; LA34: ; { Ropeobj180006* LOC42; if (!weakdep0) goto LA40; LOC42 = (Ropeobj180006*)0; LOC42 = gettypedescweak_536079_839829468(m0, (*param0).typ, check0); add_180482_2381377266(params0, LOC42); } goto LA31; LA40: ; { Ropeobj180006* LOC44; LOC44 = (Ropeobj180006*)0; LOC44 = gettypedescaux_535503_839829468(m0, (*param0).typ, check0); add_180482_2381377266(params0, LOC44); } LA31: ; memset((void*)LOC45, 0, sizeof(LOC45)); LOC46 = (Ropeobj180006*)0; LOC46 = HEX25_180905_2381377266(((NimStringDesc*) &T839829468_111), LOC45, 0); add_180482_2381377266(params0, LOC46); add_180482_2381377266(params0, (*param0).loc.r); arr0 = (*param0).typ; { if (!((*arr0).kind == ((Ttypekind294244) 23))) goto LA49; arr0 = (*arr0).sons->data[((NI) 0)]; } LA49: ; j0 = ((NI) 0); { while (1) { TY534811 LOC57; if (!((*arr0).kind == ((Ttypekind294244) 27) || (*arr0).kind == ((Ttypekind294244) 48))) goto LA52; { if (!((*(*param0).typ).kind == ((Ttypekind294244) 23))) goto LA55; (*param0).loc.s = ((Tstorageloc294812) 0); } LA55: ; memset((void*)LOC57, 0, sizeof(LOC57)); LOC57[0] = (*param0).loc.r; LOC57[1] = rope_180401_2381377266(((NI64) (j0))); addf_181205_2381377266(params0, ((NimStringDesc*) &T839829468_112), LOC57, 2); j0 += ((NI) 1); arr0 = (*arr0).sons->data[((NI) 0)]; } LA52: ; } } LA13: ; res_536356_839829468 += ((NI) 1); } LA12: ; } } { NIM_BOOL LOC60; Ttype294840* arr0; TY535289 LOC76; LOC60 = (NIM_BOOL)0; LOC60 = !(((*t0).sons->data[((NI) 0)] == NIM_NIL)); if (!(LOC60)) goto LA61; LOC60 = isinvalidreturntype_535548_839829468((*t0).sons->data[((NI) 0)]); LA61: ; if (!LOC60) goto LA62; arr0 = (*t0).sons->data[((NI) 0)]; { if (!!(((*params0) == NIM_NIL))) goto LA66; add_180487_2381377266(params0, ((NimStringDesc*) &T839829468_110)); } LA66: ; { Tctypekind531007 LOC70; Ropeobj180006* LOC73; LOC70 = (Tctypekind531007)0; LOC70 = mapreturntype_535445_839829468((*t0).sons->data[((NI) 0)]); if (!!((LOC70 == ((Tctypekind531007) 17)))) goto LA71; LOC73 = (Ropeobj180006*)0; LOC73 = gettypedescweak_536079_839829468(m0, arr0, check0); add_180482_2381377266(params0, LOC73); add_180487_2381377266(params0, ((NimStringDesc*) &T839829468_53)); } goto LA68; LA71: ; { Ropeobj180006* LOC75; LOC75 = (Ropeobj180006*)0; LOC75 = gettypedescaux_535503_839829468(m0, arr0, check0); add_180482_2381377266(params0, LOC75); } LA68: ; memset((void*)LOC76, 0, sizeof(LOC76)); addf_181205_2381377266(params0, ((NimStringDesc*) &T839829468_113), LOC76, 0); } LA62: ; { NIM_BOOL LOC79; LOC79 = (NIM_BOOL)0; LOC79 = ((*t0).callconv == ((Tcallingconvention294002) 8)); if (!(LOC79)) goto LA80; LOC79 = declareenvironment0; LA80: ; if (!LOC79) goto LA81; { if (!!(((*params0) == NIM_NIL))) goto LA85; add_180487_2381377266(params0, ((NimStringDesc*) &T839829468_110)); } LA85: ; add_180487_2381377266(params0, ((NimStringDesc*) &T839829468_114)); } LA81: ; { if (!(((*t0).flags &(1U<<((NU)(((Ttypeflag294431) 0))&31U)))!=0)) goto LA89; { if (!!(((*params0) == NIM_NIL))) goto LA93; add_180487_2381377266(params0, ((NimStringDesc*) &T839829468_110)); } LA93: ; add_180487_2381377266(params0, ((NimStringDesc*) &T839829468_115)); } LA89: ; { if (!((*params0) == NIM_NIL)) goto LA97; add_180487_2381377266(params0, ((NimStringDesc*) &T839829468_116)); } goto LA95; LA97: ; { add_180487_2381377266(params0, ((NimStringDesc*) &T839829468_117)); } LA95: ; unsureAsgnRef((void**) (&(*params0)), HEX26_180452_2381377266(((NimStringDesc*) &T839829468_118), (*params0))); } N_NIMCALL(Ropeobj180006*, genprocheader_537867_839829468)(Tcgen531027* m0, Tsym294834* prc0) { Ropeobj180006* result0; Ropeobj180006* rettype0; Ropeobj180006* params0; Intset270030 check0; Ropeobj180006* LOC13; result0 = (Ropeobj180006*)0; rettype0 = (Ropeobj180006*)0; params0 = (Ropeobj180006*)0; genclinedir_534813_839829468(&result0, (*prc0).info); { if (!(((*prc0).loc.flags &(1U<<((NU)(((Tlocflag294810) 5))&15U)))!=0)) goto LA3; { if (!(((*m0).flags &(1U<<((NU)(((Codegenflag531025) 3))&7U)))!=0)) goto LA7; add_180487_2381377266(&result0, ((NimStringDesc*) &T839829468_22)); } goto LA5; LA7: ; { add_180487_2381377266(&result0, ((NimStringDesc*) &T839829468_23)); } LA5: ; } goto LA1; LA3: ; { if (!((*(*prc0).typ).callconv == ((Tcallingconvention294002) 5))) goto LA11; add_180487_2381377266(&result0, ((NimStringDesc*) &T839829468_24)); } goto LA1; LA11: ; LA1: ; memset((void*)(&check0), 0, sizeof(check0)); chckNil((void*)(&check0)); memset((void*)(&check0), 0, sizeof(check0)); initintset_270885_2627731572((&check0)); LOC13 = (Ropeobj180006*)0; LOC13 = manglename_535205_839829468(prc0); fillloc_534282_839829468((&(*prc0).loc), ((Tlockind294808) 7), (*prc0).typ, LOC13, ((Tstorageloc294812) 0)); genprocparams_536115_839829468(m0, (*prc0).typ, &rettype0, &params0, (&check0), NIM_TRUE, NIM_FALSE); { TY537235 LOC18; if (!(*prc0).constraint == 0) goto LA16; memset((void*)LOC18, 0, sizeof(LOC18)); LOC18[0] = rope_180277_2381377266(Callingconvtostr_535585_839829468[((*(*prc0).typ).callconv)- 0]); LOC18[1] = rettype0; LOC18[2] = (*prc0).loc.r; LOC18[3] = params0; addf_181205_2381377266(&result0, ((NimStringDesc*) &T839829468_119), LOC18, 4); } goto LA14; LA16: ; { TY537238 LOC20; memset((void*)LOC20, 0, sizeof(LOC20)); LOC20[0] = rettype0; LOC20[1] = (*prc0).loc.r; LOC20[2] = params0; result0 = HEX25_180905_2381377266((*(*prc0).constraint).kindU.S3.strval, LOC20, 3); } LA14: ; return result0; } static N_INLINE(Tnode294802*, HEX5BHEX5D_295238_850551059)(Tnode294802* n0, NI i0) { Tnode294802* result0; result0 = (Tnode294802*)0; result0 = (*n0).kindU.S6.sons->data[i0]; return result0; } N_NIMCALL(Tnode294802*, easyresultasgn_562191_839829468)(Tnode294802* n0) { Tnode294802* result0; { result0 = (Tnode294802*)0; switch ((*n0).kind) { case ((Tnodekind294020) 115): case ((Tnodekind294020) 126): { NI i0; i0 = ((NI) 0); { while (1) { NIM_BOOL LOC4; NI LOC5; Tnode294802* LOC7; LOC4 = (NIM_BOOL)0; LOC5 = (NI)0; LOC5 = len_295081_850551059(n0); LOC4 = (i0 < LOC5); if (!(LOC4)) goto LA6; LOC7 = (Tnode294802*)0; LOC7 = HEX5BHEX5D_295238_850551059(n0, i0); LOC4 = ((*LOC7).kind == ((Tnodekind294020) 1) || (*LOC7).kind >= ((Tnodekind294020) 79) && (*LOC7).kind <= ((Tnodekind294020) 81) || (*LOC7).kind == ((Tnodekind294020) 84) || (*LOC7).kind == ((Tnodekind294020) 98) || (*LOC7).kind == ((Tnodekind294020) 101) || (*LOC7).kind == ((Tnodekind294020) 125)); LA6: ; if (!LOC4) goto LA3; i0 += ((NI) 1); } LA3: ; } { NI LOC10; Tnode294802* LOC13; LOC10 = (NI)0; LOC10 = len_295081_850551059(n0); if (!(i0 < LOC10)) goto LA11; LOC13 = (Tnode294802*)0; LOC13 = HEX5BHEX5D_295238_850551059(n0, i0); result0 = easyresultasgn_562191_839829468(LOC13); } LA11: ; } break; case ((Tnodekind294020) 73): case ((Tnodekind294020) 74): { { NIM_BOOL LOC17; Tnode294802* LOC18; Tnode294802* LOC20; LOC17 = (NIM_BOOL)0; LOC18 = (Tnode294802*)0; LOC18 = HEX5BHEX5D_295238_850551059(n0, ((NI) 0)); LOC17 = ((*LOC18).kind == ((Tnodekind294020) 3)); if (!(LOC17)) goto LA19; LOC20 = (Tnode294802*)0; LOC20 = HEX5BHEX5D_295238_850551059(n0, ((NI) 0)); LOC17 = (((Tsymkind294435) 11) == (*(*LOC20).kindU.S4.sym).kind); LA19: ; if (!LOC17) goto LA21; (*n0).flags |= ((NU16)1)<<((((Tnodeflag294427) 14))%(sizeof(NU16)*8)); result0 = HEX5BHEX5D_295238_850551059(n0, ((NI) 1)); goto BeforeRet; } LA21: ; } break; case ((Tnodekind294020) 109): { { NI LOC26; Tnode294802* LOC29; LOC26 = (NI)0; LOC26 = len_295081_850551059(n0); if (!(((NI) 0) < LOC26)) goto LA27; LOC29 = (Tnode294802*)0; LOC29 = HEX5BHEX5D_295238_850551059(n0, ((NI) 0)); result0 = easyresultasgn_562191_839829468(LOC29); { if (!!((result0 == NIM_NIL))) goto LA32; (*n0).flags |= ((NU16)1)<<((((Tnodeflag294427) 14))%(sizeof(NU16)*8)); } LA32: ; } LA27: ; } break; default: { } break; } }BeforeRet: ; return result0; } N_NIMCALL(Ropeobj180006*, gettypedesc_537671_839829468)(Tcgen531027* m0, Ttype294840* typ0) { Ropeobj180006* result0; Intset270030 check0; result0 = (Ropeobj180006*)0; memset((void*)(&check0), 0, sizeof(check0)); chckNil((void*)(&check0)); memset((void*)(&check0), 0, sizeof(check0)); initintset_270885_2627731572((&check0)); result0 = gettypedescaux_535503_839829468(m0, typ0, (&check0)); return result0; } N_NIMCALL(Ropeobj180006*, localvardecl_540532_839829468)(Tcproc531021* p0, Tsym294834* s0) { Ropeobj180006* result0; result0 = (Ropeobj180006*)0; { Ropeobj180006* LOC5; if (!((*s0).loc.k == ((Tlockind294808) 0))) goto LA3; LOC5 = (Ropeobj180006*)0; LOC5 = manglename_535205_839829468(s0); fillloc_534282_839829468((&(*s0).loc), ((Tlockind294808) 2), (*s0).typ, LOC5, ((Tstorageloc294812) 2)); { if (!((*s0).kind == ((Tsymkind294435) 9))) goto LA8; (*s0).loc.flags |= ((NU16)1)<<((((Tlocflag294810) 2))%(sizeof(NU16)*8)); } LA8: ; } LA3: ; result0 = gettypedesc_537671_839829468((*p0).module, (*s0).loc.t); { if (!(*s0).constraint == 0) goto LA12; { if (!(((*s0).flags &(1U<<((NU)(((Tsymflag294184) 8))&31U)))!=0)) goto LA16; add_180487_2381377266(&result0, ((NimStringDesc*) &T839829468_121)); } LA16: ; { if (!(((*s0).flags &(1U<<((NU)(((Tsymflag294184) 7))&31U)))!=0)) goto LA20; add_180487_2381377266(&result0, ((NimStringDesc*) &T839829468_122)); } LA20: ; add_180487_2381377266(&result0, ((NimStringDesc*) &T839829468_111)); add_180482_2381377266(&result0, (*s0).loc.r); } goto LA10; LA12: ; { TY534811 LOC23; memset((void*)LOC23, 0, sizeof(LOC23)); LOC23[0] = result0; LOC23[1] = (*s0).loc.r; result0 = HEX25_180905_2381377266((*(*s0).constraint).kindU.S3.strval, LOC23, 2); } LA10: ; return result0; } N_NIMCALL(void, initloc_534273_839829468)(Tloc294816* result0, Tlockind294808 k0, Ttype294840* typ0, Tstorageloc294812 s0) { (*result0).k = k0; (*result0).s = s0; unsureAsgnRef((void**) (&(*result0).t), typ0); unsureAsgnRef((void**) (&(*result0).r), NIM_NIL); (*result0).flags = 0; } N_NIMCALL(void, initlocexprsingleuse_541289_839829468)(Tcproc531021* p0, Tnode294802* e0, Tloc294816* result0) { initloc_534273_839829468(result0, ((Tlockind294808) 0), (*e0).typ, ((Tstorageloc294812) 0)); (*result0).flags |= ((NU16)1)<<((((Tlocflag294810) 8))%(sizeof(NU16)*8)); expr_541248_839829468(p0, e0, result0); } static N_INLINE(Ropeobj180006**, s_531179_3723162438)(Tcproc531021* p0, Tcprocsection531011 s0) { Ropeobj180006** result0; result0 = (Ropeobj180006**)0; result0 = &(*p0).blocks->data[(NI)(((*p0).blocks ? (*p0).blocks->Sup.len : 0) - ((NI) 1))].sections[(s0)- 0]; return result0; } N_NIMCALL(Ropeobj180006*, indentline_534656_839829468)(Tcproc531021* p0, Ropeobj180006* r0) { Ropeobj180006* result0; result0 = (Ropeobj180006*)0; result0 = r0; { NI i_534680_839829468; NI HEX3Atmp_534683_839829468; NI res_534686_839829468; i_534680_839829468 = (NI)0; HEX3Atmp_534683_839829468 = (NI)0; HEX3Atmp_534683_839829468 = (NI)(((*p0).blocks ? (*p0).blocks->Sup.len : 0) - ((NI) 1)); res_534686_839829468 = ((NI) 0); { while (1) { if (!(res_534686_839829468 <= HEX3Atmp_534683_839829468)) goto LA3; i_534680_839829468 = res_534686_839829468; prepend_180893_2381377266(&result0, indent_534655_839829468); res_534686_839829468 += ((NI) 1); } LA3: ; } } return result0; } N_NIMCALL(void, linefmt_534714_839829468)(Tcproc531021* p0, Tcprocsection531011 s0, NimStringDesc* frmt0, Ropeobj180006** args0, NI args0Len0) { Ropeobj180006** LOC1; Ropeobj180006* LOC2; Ropeobj180006* LOC3; LOC1 = (Ropeobj180006**)0; LOC1 = s_531179_3723162438(p0, s0); LOC2 = (Ropeobj180006*)0; LOC2 = ropecg_534407_839829468((*p0).module, frmt0, args0, args0Len0); LOC3 = (Ropeobj180006*)0; LOC3 = indentline_534656_839829468(p0, LOC2); add_180482_2381377266(LOC1, LOC3); } N_NIMCALL(Ropeobj180006*, rdloc_540188_839829468)(Tloc294816 a0) { Ropeobj180006* result0; result0 = (Ropeobj180006*)0; result0 = a0.r; { TY180507 LOC5; if (!((a0.flags &(1U<<((NU)(((Tlocflag294810) 0))&15U)))!=0)) goto LA3; memset((void*)LOC5, 0, sizeof(LOC5)); LOC5[0] = result0; result0 = HEX25_180905_2381377266(((NimStringDesc*) &T839829468_124), LOC5, 1); } LA3: ; return result0; } N_NIMCALL(void, line_534690_839829468)(Tcproc531021* p0, Tcprocsection531011 s0, Ropeobj180006* r0) { Ropeobj180006** LOC1; Ropeobj180006* LOC2; LOC1 = (Ropeobj180006**)0; LOC1 = s_531179_3723162438(p0, s0); LOC2 = (Ropeobj180006*)0; LOC2 = indentline_534656_839829468(p0, r0); add_180482_2381377266(LOC1, LOC2); } N_NIMCALL(void, linef_534700_839829468)(Tcproc531021* p0, Tcprocsection531011 s0, NimStringDesc* frmt0, Ropeobj180006** args0, NI args0Len0) { Ropeobj180006** LOC1; Ropeobj180006* LOC2; Ropeobj180006* LOC3; LOC1 = (Ropeobj180006**)0; LOC1 = s_531179_3723162438(p0, s0); LOC2 = (Ropeobj180006*)0; LOC2 = HEX25_180905_2381377266(frmt0, args0, args0Len0); LOC3 = (Ropeobj180006*)0; LOC3 = indentline_534656_839829468(p0, LOC2); add_180482_2381377266(LOC1, LOC3); } N_NIMCALL(void, gentypeinfoauxbase_537960_839829468)(Tcgen531027* m0, Ttype294840* typ0, Ttype294840* origtype0, Ropeobj180006* name0, Ropeobj180006* base0) { NI nimtypekind0; Ropeobj180006* size0; TY537235 LOC17; NI flags0; Ropeobj180006* LOC33; TY534811 LOC34; NimStringDesc* LOC35; nimtypekind0 = (NI)0; { NIM_BOOL LOC3; LOC3 = (NIM_BOOL)0; LOC3 = isobjlackingtypefield_535513_839829468(typ0); if (!LOC3) goto LA4; nimtypekind0 = ((NI) 18); } goto LA1; LA4: ; { nimtypekind0 = ((NI) ((*typ0).kind)); } LA1: ; size0 = (Ropeobj180006*)0; { if (!(((*typ0).flags &(1U<<((NU)(((Ttypeflag294431) 0))&31U)))!=0)) goto LA9; size0 = rope_180277_2381377266(((NimStringDesc*) &T839829468_133)); } goto LA7; LA9: ; { NIM_BOOL LOC12; LOC12 = (NIM_BOOL)0; LOC12 = (gcmd_171132_2607990831 == ((Tcommands171076) 2)); if (LOC12) goto LA13; LOC12 = (((*(*m0).module).flags &(1U<<((NU)(((Tsymflag294184) 27))&31U)))!=0); LA13: ; if (!LOC12) goto LA14; size0 = gettypedesc_537671_839829468(m0, origtype0); } goto LA7; LA14: ; { size0 = gettypedesc_537671_839829468(m0, typ0); } LA7: ; memset((void*)LOC17, 0, sizeof(LOC17)); LOC17[0] = name0; LOC17[1] = size0; LOC17[2] = rope_180401_2381377266(((NI64) (nimtypekind0))); LOC17[3] = base0; addf_181205_2381377266(&(*m0).s[(((Tcfilesection531005) 14))- 0], ((NimStringDesc*) &T839829468_134), LOC17, 4); flags0 = ((NI) 0); { NIM_BOOL LOC20; LOC20 = (NIM_BOOL)0; LOC20 = containsgarbagecollectedref_322117_3876443242(typ0); if (!!(LOC20)) goto LA21; flags0 = (NI)(flags0 | ((NI) 1)); } LA21: ; { NIM_BOOL LOC25; LOC25 = (NIM_BOOL)0; LOC25 = canformacycle_322123_3876443242(typ0); if (!!(LOC25)) goto LA26; flags0 = (NI)(flags0 | ((NI) 2)); } LA26: ; { TY534811 LOC32; if (!!((flags0 == ((NI) 0)))) goto LA30; memset((void*)LOC32, 0, sizeof(LOC32)); LOC32[0] = name0; LOC32[1] = rope_180401_2381377266(((NI64) (flags0))); addf_181205_2381377266(&(*m0).s[(((Tcfilesection531005) 14))- 0], ((NimStringDesc*) &T839829468_135), LOC32, 2); } LA30: ; LOC33 = (Ropeobj180006*)0; LOC33 = cgsym_534403_839829468(m0, ((NimStringDesc*) &T839829468_129)); memset((void*)LOC34, 0, sizeof(LOC34)); LOC34[0] = name0; LOC35 = (NimStringDesc*)0; LOC35 = typetostring_322017_3876443242(typ0, ((Tprefereddesc322011) 0)); LOC34[1] = rope_180277_2381377266(LOC35); addf_181205_2381377266(&(*m0).s[(((Tcfilesection531005) 9))- 0], ((NimStringDesc*) &T839829468_136), LOC34, 2); } N_NIMCALL(Ropeobj180006*, getnimnode_537945_839829468)(Tcgen531027* m0) { Ropeobj180006* result0; TY534811 LOC1; result0 = (Ropeobj180006*)0; memset((void*)LOC1, 0, sizeof(LOC1)); LOC1[0] = (*m0).typenodesname; LOC1[1] = rope_180401_2381377266(((NI64) ((*m0).typenodes))); result0 = HEX25_180905_2381377266(((NimStringDesc*) &T839829468_138), LOC1, 2); (*m0).typenodes += ((NI) 1); return result0; } N_NIMCALL(void, gentupleinfo_538549_839829468)(Tcgen531027* m0, Ttype294840* typ0, Ropeobj180006* name0) { Ropeobj180006* LOC1; Ropeobj180006* expr0; NI length0; TY534811 LOC15; LOC1 = (Ropeobj180006*)0; LOC1 = rope_180277_2381377266(((NimStringDesc*) &T839829468_18)); gentypeinfoauxbase_537960_839829468(m0, typ0, typ0, name0, LOC1); expr0 = getnimnode_537945_839829468(m0); length0 = sonslen_297327_850551059(typ0); { Ropeobj180006* tmp0; TY534811 LOC6; TY537238 LOC12; if (!(((NI) 0) < length0)) goto LA4; tmp0 = gettempname_535596_839829468(m0); memset((void*)LOC6, 0, sizeof(LOC6)); LOC6[0] = tmp0; LOC6[1] = rope_180401_2381377266(((NI64) (length0))); addf_181205_2381377266(&(*m0).s[(((Tcfilesection531005) 12))- 0], ((NimStringDesc*) &T839829468_139), LOC6, 2); { NI i_538571_839829468; NI HEX3Atmp_538590_839829468; NI res_538593_839829468; i_538571_839829468 = (NI)0; HEX3Atmp_538590_839829468 = (NI)0; HEX3Atmp_538590_839829468 = (NI)(length0 - ((NI) 1)); res_538593_839829468 = ((NI) 0); { while (1) { Ttype294840* a0; Ropeobj180006* tmp20; TY537238 LOC10; TY537235 LOC11; if (!(res_538593_839829468 <= HEX3Atmp_538590_839829468)) goto LA9; i_538571_839829468 = res_538593_839829468; a0 = (*typ0).sons->data[i_538571_839829468]; tmp20 = getnimnode_537945_839829468(m0); memset((void*)LOC10, 0, sizeof(LOC10)); LOC10[0] = tmp0; LOC10[1] = rope_180401_2381377266(((NI64) (i_538571_839829468))); LOC10[2] = tmp20; addf_181205_2381377266(&(*m0).s[(((Tcfilesection531005) 14))- 0], ((NimStringDesc*) &T839829468_140), LOC10, 3); memset((void*)LOC11, 0, sizeof(LOC11)); LOC11[0] = tmp20; LOC11[1] = gettypedesc_537671_839829468(m0, typ0); LOC11[2] = rope_180401_2381377266(((NI64) (i_538571_839829468))); LOC11[3] = gentypeinfo_537941_839829468(m0, a0); addf_181205_2381377266(&(*m0).s[(((Tcfilesection531005) 14))- 0], ((NimStringDesc*) &T839829468_141), LOC11, 4); res_538593_839829468 += ((NI) 1); } LA9: ; } } memset((void*)LOC12, 0, sizeof(LOC12)); LOC12[0] = expr0; LOC12[1] = rope_180401_2381377266(((NI64) (length0))); LOC12[2] = tmp0; addf_181205_2381377266(&(*m0).s[(((Tcfilesection531005) 14))- 0], ((NimStringDesc*) &T839829468_142), LOC12, 3); } goto LA2; LA4: ; { TY534811 LOC14; memset((void*)LOC14, 0, sizeof(LOC14)); LOC14[0] = expr0; LOC14[1] = rope_180401_2381377266(((NI64) (length0))); addf_181205_2381377266(&(*m0).s[(((Tcfilesection531005) 14))- 0], ((NimStringDesc*) &T839829468_143), LOC14, 2); } LA2: ; memset((void*)LOC15, 0, sizeof(LOC15)); LOC15[0] = name0; LOC15[1] = expr0; addf_181205_2381377266(&(*m0).s[(((Tcfilesection531005) 14))- 0], ((NimStringDesc*) &T839829468_144), LOC15, 2); } N_NIMCALL(Ttype294840*, fakeclosuretype_539010_839829468)(Tsym294834* owner0) { Ttype294840* result0; Ttype294840* LOC1; Ttype294840* r0; Ttype294840* LOC2; result0 = (Ttype294840*)0; result0 = newtype_297107_850551059(((Ttypekind294244) 18), owner0); LOC1 = (Ttype294840*)0; LOC1 = newtype_297107_850551059(((Ttypekind294244) 26), owner0); rawaddson_298394_850551059(result0, LOC1); r0 = newtype_297107_850551059(((Ttypekind294244) 22), owner0); LOC2 = (Ttype294840*)0; LOC2 = newtype_297107_850551059(((Ttypekind294244) 18), owner0); rawaddson_298394_850551059(r0, LOC2); rawaddson_298394_850551059(result0, r0); return result0; } N_NIMCALL(void, gentypeinfoaux_538027_839829468)(Tcgen531027* m0, Ttype294840* typ0, Ttype294840* origtype0, Ropeobj180006* name0) { Ropeobj180006* base0; base0 = (Ropeobj180006*)0; { NIM_BOOL LOC3; NI LOC4; Ttype294840* x0; LOC3 = (NIM_BOOL)0; LOC4 = (NI)0; LOC4 = sonslen_297327_850551059(typ0); LOC3 = (((NI) 0) < LOC4); if (!(LOC3)) goto LA5; LOC3 = !(((*typ0).sons->data[((NI) 0)] == NIM_NIL)); LA5: ; if (!LOC3) goto LA6; x0 = (*typ0).sons->data[((NI) 0)]; { if (!((*typ0).kind == ((Ttypekind294244) 17))) goto LA10; x0 = skiptypes_298099_850551059(x0, IL64(211106247215360)); } LA10: ; base0 = gentypeinfo_537941_839829468(m0, x0); } goto LA1; LA6: ; { base0 = rope_180277_2381377266(((NimStringDesc*) &T839829468_18)); } LA1: ; gentypeinfoauxbase_537960_839829468(m0, typ0, origtype0, name0, base0); } static N_INLINE(NIM_BOOL, iscomplexvaluetype_540317_839829468)(Ttype294840* t0) { NIM_BOOL result0; NIM_BOOL LOC1; NIM_BOOL LOC3; result0 = (NIM_BOOL)0; LOC1 = (NIM_BOOL)0; LOC1 = ((*t0).kind == ((Ttypekind294244) 16) || (*t0).kind == ((Ttypekind294244) 4) || (*t0).kind == ((Ttypekind294244) 19) || (*t0).kind == ((Ttypekind294244) 18) || (*t0).kind == ((Ttypekind294244) 17)); if (LOC1) goto LA2; LOC3 = (NIM_BOOL)0; LOC3 = ((*t0).kind == ((Ttypekind294244) 25)); if (!(LOC3)) goto LA4; LOC3 = ((*t0).callconv == ((Tcallingconvention294002) 8)); LA4: ; LOC1 = LOC3; LA2: ; result0 = LOC1; return result0; } N_NIMCALL(void, usestringh_534345_839829468)(Tcgen531027* m0) { { NIM_BOOL LOC5; if (!!((((*m0).flags &(1U<<((NU)(((Codegenflag531025) 4))&7U)))!=0))) goto LA3; (*m0).flags |= ((NU8)1)<<((((Codegenflag531025) 4))%(sizeof(NU8)*8)); LOC5 = (NIM_BOOL)0; LOC5 = includestr_148249_3771138726((&(*m0).headerfiles), ((NimStringDesc*) &T839829468_151)); } LA3: ; } N_NIMCALL(Ropeobj180006*, addrloc_540204_839829468)(Tloc294816 a0) { Ropeobj180006* result0; result0 = (Ropeobj180006*)0; result0 = a0.r; { NIM_BOOL LOC3; Tctypekind531007 LOC5; Ropeobj180006* LOC8; LOC3 = (NIM_BOOL)0; LOC3 = !(((a0.flags &(1U<<((NU)(((Tlocflag294810) 0))&15U)))!=0)); if (!(LOC3)) goto LA4; LOC5 = (Tctypekind531007)0; LOC5 = maptype_535393_839829468(a0.t); LOC3 = !((LOC5 == ((Tctypekind531007) 17))); LA4: ; if (!LOC3) goto LA6; LOC8 = (Ropeobj180006*)0; LOC8 = HEX26_180452_2381377266(((NimStringDesc*) &T839829468_128), result0); result0 = HEX26_180447_2381377266(LOC8, ((NimStringDesc*) &T839829468_117)); } LA6: ; return result0; } N_NIMCALL(void, genobjectinit_540242_839829468)(Tcproc531021* p0, Tcprocsection531011 section0, Ttype294840* t0, Tloc294816 a0, NIM_BOOL takeaddr0) { Ttypefieldresult322145 LOC1; LOC1 = (Ttypefieldresult322145)0; LOC1 = analyseobjectwithtypefield_322149_3876443242(t0); switch (LOC1) { case ((Ttypefieldresult322145) 0): { } break; case ((Ttypefieldresult322145) 1): { Ropeobj180006* r0; Ttype294840* s0; TY534811 LOC19; r0 = rdloc_540188_839829468(a0); { TY180507 LOC8; if (!!(takeaddr0)) goto LA6; memset((void*)LOC8, 0, sizeof(LOC8)); LOC8[0] = r0; r0 = HEX25_180905_2381377266(((NimStringDesc*) &T839829468_124), LOC8, 1); } LA6: ; s0 = skiptypes_298099_850551059(t0, IL64(211106232576256)); { NIM_BOOL LOC11; LOC11 = (NIM_BOOL)0; LOC11 = (gcmd_171132_2607990831 == ((Tcommands171076) 2)); if (LOC11) goto LA12; LOC11 = (((*(*(*p0).module).module).flags &(1U<<((NU)(((Tsymflag294184) 27))&31U)))!=0); LA12: ; if (!!(LOC11)) goto LA13; { while (1) { NIM_BOOL LOC17; LOC17 = (NIM_BOOL)0; LOC17 = ((*s0).kind == ((Ttypekind294244) 17)); if (!(LOC17)) goto LA18; LOC17 = !(((*s0).sons->data[((NI) 0)] == NIM_NIL)); LA18: ; if (!LOC17) goto LA16; add_180487_2381377266(&r0, ((NimStringDesc*) &T839829468_153)); s0 = skiptypes_298099_850551059((*s0).sons->data[((NI) 0)], IL64(211106247215360)); } LA16: ; } } LA13: ; memset((void*)LOC19, 0, sizeof(LOC19)); LOC19[0] = r0; LOC19[1] = gentypeinfo_537941_839829468((*p0).module, t0); linefmt_534714_839829468(p0, section0, ((NimStringDesc*) &T839829468_154), LOC19, 2); } break; case ((Ttypefieldresult322145) 2): { Ropeobj180006* r0; TY534811 LOC26; { if (!takeaddr0) goto LA23; r0 = addrloc_540204_839829468(a0); } goto LA21; LA23: ; { r0 = rdloc_540188_839829468(a0); } LA21: ; memset((void*)LOC26, 0, sizeof(LOC26)); LOC26[0] = r0; LOC26[1] = gentypeinfo_537941_839829468((*p0).module, t0); linefmt_534714_839829468(p0, section0, ((NimStringDesc*) &T839829468_155), LOC26, 2); } break; } } N_NIMCALL(void, constructloc_540388_839829468)(Tcproc531021* p0, Tloc294816 loc0, NIM_BOOL istemp0) { Ttype294840* typ0; typ0 = skiptypes_298099_850551059(loc0.t, IL64(211106233624832)); { NIM_BOOL LOC3; TY534811 LOC6; LOC3 = (NIM_BOOL)0; LOC3 = iscomplexvaluetype_540317_839829468(typ0); if (!!(LOC3)) goto LA4; memset((void*)LOC6, 0, sizeof(LOC6)); LOC6[0] = rdloc_540188_839829468(loc0); LOC6[1] = gettypedesc_537671_839829468((*p0).module, typ0); linefmt_534714_839829468(p0, ((Tcprocsection531011) 2), ((NimStringDesc*) &T839829468_150), LOC6, 2); } goto LA1; LA4: ; { { NIM_BOOL LOC10; LOC10 = (NIM_BOOL)0; LOC10 = !(istemp0); if (LOC10) goto LA11; LOC10 = containsgarbagecollectedref_322117_3876443242(loc0.t); LA11: ; if (!LOC10) goto LA12; { NIM_BOOL LOC16; TY534811 LOC19; LOC16 = (NIM_BOOL)0; LOC16 = isimportedcpptype_535476_839829468(typ0); if (!!(LOC16)) goto LA17; usestringh_534345_839829468((*p0).module); memset((void*)LOC19, 0, sizeof(LOC19)); LOC19[0] = addrloc_540204_839829468(loc0); LOC19[1] = rdloc_540188_839829468(loc0); linefmt_534714_839829468(p0, ((Tcprocsection531011) 2), ((NimStringDesc*) &T839829468_152), LOC19, 2); } LA17: ; } LA12: ; genobjectinit_540242_839829468(p0, ((Tcprocsection531011) 2), loc0.t, loc0, NIM_TRUE); } LA1: ; } N_NIMCALL(void, gettemp_539032_839829468)(Tcproc531021* p0, Ttype294840* t0, Tloc294816* result0, NIM_BOOL needsinit0) { Ropeobj180006* LOC1; TY534811 LOC2; (*p0).labels += ((NI) 1); LOC1 = (Ropeobj180006*)0; LOC1 = rope_180401_2381377266(((NI64) ((*p0).labels))); unsureAsgnRef((void**) (&(*result0).r), HEX26_180452_2381377266(((NimStringDesc*) &T839829468_149), LOC1)); memset((void*)LOC2, 0, sizeof(LOC2)); LOC2[0] = gettypedesc_537671_839829468((*p0).module, t0); LOC2[1] = (*result0).r; linefmt_534714_839829468(p0, ((Tcprocsection531011) 0), ((NimStringDesc*) &T839829468_54), LOC2, 2); (*result0).k = ((Tlockind294808) 1); unsureAsgnRef((void**) (&(*result0).t), t0); (*result0).s = ((Tstorageloc294812) 2); (*result0).flags = 0; constructloc_540388_839829468(p0, (*result0), !(needsinit0)); } static N_INLINE(Ropeobj180006*, parentobj_539257_839829468)(Ropeobj180006* accessor0, Tcgen531027* m0) { Ropeobj180006* result0; result0 = (Ropeobj180006*)0; { NIM_BOOL LOC3; TY180507 LOC7; LOC3 = (NIM_BOOL)0; LOC3 = (gcmd_171132_2607990831 == ((Tcommands171076) 2)); if (LOC3) goto LA4; LOC3 = (((*(*m0).module).flags &(1U<<((NU)(((Tsymflag294184) 27))&31U)))!=0); LA4: ; if (!!(LOC3)) goto LA5; memset((void*)LOC7, 0, sizeof(LOC7)); LOC7[0] = accessor0; result0 = HEX25_180905_2381377266(((NimStringDesc*) &T839829468_161), LOC7, 1); } goto LA1; LA5: ; { result0 = accessor0; } LA1: ; return result0; } N_NIMCALL(Ropeobj180006*, intliteral_541270_839829468)(NI64 i0) { Ropeobj180006* result0; result0 = (Ropeobj180006*)0; { NIM_BOOL LOC3; LOC3 = (NIM_BOOL)0; LOC3 = (IL64(-2147483648) < i0); if (!(LOC3)) goto LA4; LOC3 = (i0 <= IL64(2147483647)); LA4: ; if (!LOC3) goto LA5; result0 = rope_180401_2381377266(i0); } goto LA1; LA5: ; { TY535289 LOC10; if (!(i0 == IL64(-2147483648))) goto LA8; memset((void*)LOC10, 0, sizeof(LOC10)); result0 = HEX25_180905_2381377266(((NimStringDesc*) &T839829468_166), LOC10, 0); } goto LA1; LA8: ; { TY180507 LOC14; if (!((IL64(-9223372036854775807) - IL64(1)) < i0)) goto LA12; memset((void*)LOC14, 0, sizeof(LOC14)); LOC14[0] = rope_180401_2381377266(i0); result0 = ropecg_534407_839829468(NIM_NIL, ((NimStringDesc*) &T839829468_167), LOC14, 1); } goto LA1; LA12: ; { TY535289 LOC16; memset((void*)LOC16, 0, sizeof(LOC16)); result0 = HEX25_180905_2381377266(((NimStringDesc*) &T839829468_168), LOC16, 0); } LA1: ; return result0; } N_NIMCALL(Ropeobj180006*, int64literal_551430_839829468)(NI64 i0) { Ropeobj180006* result0; result0 = (Ropeobj180006*)0; { TY180507 LOC5; if (!((IL64(-9223372036854775807) - IL64(1)) < i0)) goto LA3; memset((void*)LOC5, 0, sizeof(LOC5)); LOC5[0] = rope_180401_2381377266(i0); result0 = ropecg_534407_839829468(NIM_NIL, ((NimStringDesc*) &T839829468_167), LOC5, 1); } goto LA1; LA3: ; { TY535289 LOC7; memset((void*)LOC7, 0, sizeof(LOC7)); result0 = HEX25_180905_2381377266(((NimStringDesc*) &T839829468_168), LOC7, 0); } LA1: ; return result0; } N_NIMCALL(Ropeobj180006*, uint64literal_551442_839829468)(NU64 i0) { Ropeobj180006* result0; NimStringDesc* LOC1; NimStringDesc* LOC2; result0 = (Ropeobj180006*)0; LOC1 = (NimStringDesc*)0; LOC2 = (NimStringDesc*)0; LOC2 = HEX24_8401_1689653243(i0); LOC1 = rawNewString(LOC2->Sup.len + 3); appendString(LOC1, LOC2); appendString(LOC1, ((NimStringDesc*) &T839829468_171)); result0 = rope_180277_2381377266(LOC1); return result0; } N_NIMCALL(Ropeobj180006*, getstrlit_551468_839829468)(Tcgen531027* m0, NimStringDesc* s0) { Ropeobj180006* result0; Ropeobj180006* LOC1; TY537238 LOC2; result0 = (Ropeobj180006*)0; LOC1 = (Ropeobj180006*)0; LOC1 = cgsym_534403_839829468(m0, ((NimStringDesc*) &T839829468_79)); result0 = gettempname_535596_839829468(m0); memset((void*)LOC2, 0, sizeof(LOC2)); LOC2[0] = result0; LOC2[1] = makecstring_193638_155036129(s0); LOC2[2] = rope_180401_2381377266(((NI64) ((s0 ? s0->Sup.len : 0)))); addf_181205_2381377266(&(*m0).s[(((Tcfilesection531005) 8))- 0], ((NimStringDesc*) &T839829468_177), LOC2, 3); return result0; } N_NIMCALL(Ropeobj180006*, genliteral_551476_839829468)(Tcproc531021* p0, Tnode294802* n0, Ttype294840* ty0) { Ropeobj180006* result0; result0 = (Ropeobj180006*)0; { if (!(ty0 == NIM_NIL)) goto LA3; internalerror_198100_155036129((*n0).info, ((NimStringDesc*) &T839829468_165)); } LA3: ; switch ((*n0).kind) { case ((Tnodekind294020) 5) ... ((Tnodekind294020) 15): { Ttype294840* LOC6; LOC6 = (Ttype294840*)0; LOC6 = skiptypes_298099_850551059(ty0, IL64(211106242013440)); switch ((*LOC6).kind) { case ((Ttypekind294244) 2): case ((Ttypekind294244) 5): { result0 = intliteral_541270_839829468((*n0).kindU.S1.intval); } break; case ((Ttypekind294244) 1): { { TY535289 LOC13; if (!!(((*n0).kindU.S1.intval == IL64(0)))) goto LA11; memset((void*)LOC13, 0, sizeof(LOC13)); result0 = HEX25_180905_2381377266(((NimStringDesc*) &T839829468_169), LOC13, 0); } goto LA9; LA11: ; { TY535289 LOC15; memset((void*)LOC15, 0, sizeof(LOC15)); result0 = HEX25_180905_2381377266(((NimStringDesc*) &T839829468_170), LOC15, 0); } LA9: ; } break; case ((Ttypekind294244) 35): { result0 = int64literal_551430_839829468((*n0).kindU.S1.intval); } break; case ((Ttypekind294244) 44): { result0 = uint64literal_551442_839829468(((NU64) ((*n0).kindU.S1.intval))); } break; default: { TY534811 LOC19; Ttype294840* LOC20; memset((void*)LOC19, 0, sizeof(LOC19)); LOC20 = (Ttype294840*)0; LOC20 = skiptypes_298099_850551059(ty0, IL64(211106242013440)); LOC19[0] = gettypedesc_537671_839829468((*p0).module, LOC20); LOC19[1] = intliteral_541270_839829468((*n0).kindU.S1.intval); result0 = HEX25_180905_2381377266(((NimStringDesc*) &T839829468_172), LOC19, 2); } break; } } break; case ((Tnodekind294020) 23): { Ttype294840* t0; t0 = skiptypes_298099_850551059(ty0, IL64(211106242013440)); { NIM_BOOL LOC24; NI id0; Ropeobj180006* LOC28; LOC24 = (NIM_BOOL)0; LOC24 = ((*t0).kind == ((Ttypekind294244) 25)); if (!(LOC24)) goto LA25; LOC24 = ((*t0).callconv == ((Tcallingconvention294002) 8)); LA25: ; if (!LOC24) goto LA26; id0 = nodetabletestorset_344682_1142335848((&(*(*p0).module).datacache), n0, ((NI) ((*(*p0).module).labels))); LOC28 = (Ropeobj180006*)0; LOC28 = rope_180401_2381377266(((NI64) (id0))); result0 = HEX26_180418_2381377266((*(*p0).module).tmpbase, LOC28); { TY534811 LOC33; if (!(id0 == ((NI) ((*(*p0).module).labels)))) goto LA31; (*(*p0).module).labels += ((NI) 1); memset((void*)LOC33, 0, sizeof(LOC33)); LOC33[0] = gettypedesc_537671_839829468((*p0).module, t0); LOC33[1] = result0; addf_181205_2381377266(&(*(*p0).module).s[(((Tcfilesection531005) 8))- 0], ((NimStringDesc*) &T839829468_173), LOC33, 2); } LA31: ; } goto LA22; LA26: ; { result0 = rope_180277_2381377266(((NimStringDesc*) &T839829468_174)); } LA22: ; } break; case ((Tnodekind294020) 20) ... ((Tnodekind294020) 22): { { TY535289 LOC40; if (!(*n0).kindU.S3.strval == 0) goto LA38; memset((void*)LOC40, 0, sizeof(LOC40)); result0 = ropecg_534407_839829468((*p0).module, ((NimStringDesc*) &T839829468_175), LOC40, 0); } goto LA36; LA38: ; { Ttype294840* LOC42; NI id0; LOC42 = (Ttype294840*)0; LOC42 = skiptypes_298099_850551059(ty0, IL64(211106242013440)); if (!((*LOC42).kind == ((Ttypekind294244) 28))) goto LA43; id0 = nodetabletestorset_344682_1142335848((&(*(*p0).module).datacache), n0, ((NI) ((*(*p0).module).labels))); { TY180507 LOC49; if (!(id0 == ((NI) ((*(*p0).module).labels)))) goto LA47; memset((void*)LOC49, 0, sizeof(LOC49)); LOC49[0] = getstrlit_551468_839829468((*p0).module, (*n0).kindU.S3.strval); result0 = ropecg_534407_839829468((*p0).module, ((NimStringDesc*) &T839829468_176), LOC49, 1); } goto LA45; LA47: ; { TY534811 LOC51; memset((void*)LOC51, 0, sizeof(LOC51)); LOC51[0] = (*(*p0).module).tmpbase; LOC51[1] = rope_180401_2381377266(((NI64) (id0))); result0 = ropecg_534407_839829468((*p0).module, ((NimStringDesc*) &T839829468_178), LOC51, 2); } LA45: ; } goto LA36; LA43: ; { result0 = makecstring_193638_155036129((*n0).kindU.S3.strval); } LA36: ; } break; case ((Tnodekind294020) 16) ... ((Tnodekind294020) 18): { NimStringDesc* LOC54; LOC54 = (NimStringDesc*)0; LOC54 = tostrmaxprecision_300007_3471544153((*n0).kindU.S2.floatval); result0 = rope_180277_2381377266(LOC54); } break; default: { NimStringDesc* LOC56; LOC56 = (NimStringDesc*)0; LOC56 = rawNewString(reprEnum((NI)(*n0).kind, (&NTI294020))->Sup.len + 12); appendString(LOC56, ((NimStringDesc*) &T839829468_179)); appendString(LOC56, reprEnum((NI)(*n0).kind, (&NTI294020))); appendChar(LOC56, 41); internalerror_198100_155036129((*n0).info, LOC56); result0 = NIM_NIL; } break; } return result0; } N_NIMCALL(Ropeobj180006*, genliteral_541273_839829468)(Tcproc531021* p0, Tnode294802* n0) { Ropeobj180006* result0; result0 = (Ropeobj180006*)0; result0 = genliteral_551476_839829468(p0, n0, (*n0).typ); return result0; } N_NIMCALL(void, gencaserange_539028_839829468)(Tcproc531021* p0, Tnode294802* branch0) { NI length0; length0 = len_295081_850551059(branch0); { NI j_549676_839829468; NI HEX3Atmp_549717_839829468; NI res_549720_839829468; j_549676_839829468 = (NI)0; HEX3Atmp_549717_839829468 = (NI)0; HEX3Atmp_549717_839829468 = (NI)(length0 - ((NI) 2)); res_549720_839829468 = ((NI) 0); { while (1) { if (!(res_549720_839829468 <= HEX3Atmp_549717_839829468)) goto LA3; j_549676_839829468 = res_549720_839829468; { Tnode294802* LOC6; LOC6 = (Tnode294802*)0; LOC6 = HEX5BHEX5D_295238_850551059(branch0, j_549676_839829468); if (!((*LOC6).kind == ((Tnodekind294020) 44))) goto LA7; { TY534811 LOC13; Tnode294802* LOC14; Tnode294802* LOC15; Tnode294802* LOC16; Tnode294802* LOC17; if (!((Cc_275413_2528170400[(ccompiler_275431_2528170400)- 1].Field20 &(1U<<((NU)(((Tinfoccprop275004) 0))&7U)))!=0)) goto LA11; memset((void*)LOC13, 0, sizeof(LOC13)); LOC14 = (Tnode294802*)0; LOC14 = HEX5BHEX5D_295238_850551059(branch0, j_549676_839829468); LOC15 = (Tnode294802*)0; LOC15 = HEX5BHEX5D_295238_850551059(LOC14, ((NI) 0)); LOC13[0] = genliteral_541273_839829468(p0, LOC15); LOC16 = (Tnode294802*)0; LOC16 = HEX5BHEX5D_295238_850551059(branch0, j_549676_839829468); LOC17 = (Tnode294802*)0; LOC17 = HEX5BHEX5D_295238_850551059(LOC16, ((NI) 1)); LOC13[1] = genliteral_541273_839829468(p0, LOC17); linef_534700_839829468(p0, ((Tcprocsection531011) 2), ((NimStringDesc*) &T839829468_164), LOC13, 2); } goto LA9; LA11: ; { Tnode294802* v0; Tnode294802* LOC19; Tnode294802* LOC20; LOC19 = (Tnode294802*)0; LOC19 = HEX5BHEX5D_295238_850551059(branch0, j_549676_839829468); LOC20 = (Tnode294802*)0; LOC20 = HEX5BHEX5D_295238_850551059(LOC19, ((NI) 0)); v0 = copynode_298528_850551059(LOC20); { while (1) { Tnode294802* LOC23; Tnode294802* LOC24; TY180507 LOC25; LOC23 = (Tnode294802*)0; LOC23 = HEX5BHEX5D_295238_850551059(branch0, j_549676_839829468); LOC24 = (Tnode294802*)0; LOC24 = HEX5BHEX5D_295238_850551059(LOC23, ((NI) 1)); if (!((*v0).kindU.S1.intval <= (*LOC24).kindU.S1.intval)) goto LA22; memset((void*)LOC25, 0, sizeof(LOC25)); LOC25[0] = genliteral_541273_839829468(p0, v0); linef_534700_839829468(p0, ((Tcprocsection531011) 2), ((NimStringDesc*) &T839829468_180), LOC25, 1); (*v0).kindU.S1.intval += ((NI) 1); } LA22: ; } } LA9: ; } goto LA4; LA7: ; { TY180507 LOC27; Tnode294802* LOC28; memset((void*)LOC27, 0, sizeof(LOC27)); LOC28 = (Tnode294802*)0; LOC28 = HEX5BHEX5D_295238_850551059(branch0, j_549676_839829468); LOC27[0] = genliteral_541273_839829468(p0, LOC28); linef_534700_839829468(p0, ((Tcprocsection531011) 2), ((NimStringDesc*) &T839829468_180), LOC27, 1); } LA4: ; res_549720_839829468 += ((NI) 1); } LA3: ; } } } N_NIMCALL(void, gentraverseproc_539039_839829468)(Ttraversalclosure539019* c0, Ropeobj180006* accessor0, Tnode294802* n0) { { { if (!(n0 == NIM_NIL)) goto LA3; goto BeforeRet; } LA3: ; switch ((*n0).kind) { case ((Tnodekind294020) 138): { { NI i_539068_839829468; NI HEX3Atmp_539239_839829468; NI LOC7; NI res_539242_839829468; i_539068_839829468 = (NI)0; HEX3Atmp_539239_839829468 = (NI)0; LOC7 = (NI)0; LOC7 = sonslen_297351_850551059(n0); HEX3Atmp_539239_839829468 = (NI)(LOC7 - ((NI) 1)); res_539242_839829468 = ((NI) 0); { while (1) { if (!(res_539242_839829468 <= HEX3Atmp_539239_839829468)) goto LA9; i_539068_839829468 = res_539242_839829468; gentraverseproc_539039_839829468(c0, accessor0, (*n0).kindU.S6.sons->data[i_539068_839829468]); res_539242_839829468 += ((NI) 1); } LA9: ; } } } break; case ((Tnodekind294020) 139): { Tcproc531021* p0; Tsym294834* disc0; TY534811 LOC15; TY535289 LOC28; { if (!!(((*(*n0).kindU.S6.sons->data[((NI) 0)]).kind == ((Tnodekind294020) 3)))) goto LA13; internalerror_198100_155036129((*n0).info, ((NimStringDesc*) &T839829468_162)); } LA13: ; p0 = (*c0).p; disc0 = (*(*n0).kindU.S6.sons->data[((NI) 0)]).kindU.S4.sym; memset((void*)LOC15, 0, sizeof(LOC15)); LOC15[0] = accessor0; LOC15[1] = (*disc0).loc.r; linef_534700_839829468(p0, ((Tcprocsection531011) 2), ((NimStringDesc*) &T839829468_163), LOC15, 2); { NI i_539098_839829468; NI HEX3Atmp_539249_839829468; NI LOC17; NI res_539252_839829468; i_539098_839829468 = (NI)0; HEX3Atmp_539249_839829468 = (NI)0; LOC17 = (NI)0; LOC17 = sonslen_297351_850551059(n0); HEX3Atmp_539249_839829468 = (NI)(LOC17 - ((NI) 1)); res_539252_839829468 = ((NI) 1); { while (1) { Tnode294802* branch0; Tnode294802* LOC26; TY535289 LOC27; if (!(res_539252_839829468 <= HEX3Atmp_539249_839829468)) goto LA19; i_539098_839829468 = res_539252_839829468; branch0 = (*n0).kindU.S6.sons->data[i_539098_839829468]; { if (!((*branch0).kind == ((Tnodekind294020) 85))) goto LA22; gencaserange_539028_839829468((*c0).p, branch0); } goto LA20; LA22: ; { TY535289 LOC25; memset((void*)LOC25, 0, sizeof(LOC25)); linef_534700_839829468(p0, ((Tcprocsection531011) 2), ((NimStringDesc*) &T839829468_181), LOC25, 0); } LA20: ; LOC26 = (Tnode294802*)0; LOC26 = lastson_297364_850551059(branch0); gentraverseproc_539039_839829468(c0, accessor0, LOC26); memset((void*)LOC27, 0, sizeof(LOC27)); linef_534700_839829468(p0, ((Tcprocsection531011) 2), ((NimStringDesc*) &T839829468_182), LOC27, 0); res_539252_839829468 += ((NI) 1); } LA19: ; } } memset((void*)LOC28, 0, sizeof(LOC28)); linef_534700_839829468(p0, ((Tcprocsection531011) 2), ((NimStringDesc*) &T839829468_183), LOC28, 0); } break; case ((Tnodekind294020) 3): { Tsym294834* field0; TY534811 LOC34; Ropeobj180006* LOC35; field0 = (*n0).kindU.S4.sym; { if (!((*field0).loc.t == NIM_NIL)) goto LA32; internalerror_198100_155036129((*n0).info, ((NimStringDesc*) &T839829468_184)); } LA32: ; memset((void*)LOC34, 0, sizeof(LOC34)); LOC34[0] = accessor0; LOC34[1] = (*field0).loc.r; LOC35 = (Ropeobj180006*)0; LOC35 = HEX25_180905_2381377266(((NimStringDesc*) &T839829468_90), LOC34, 2); gentraverseproc_539022_839829468(c0, LOC35, (*field0).loc.t); } break; default: { internalerror_198100_155036129((*n0).info, ((NimStringDesc*) &T839829468_184)); } break; } }BeforeRet: ; } N_NIMCALL(void, linecg_534707_839829468)(Tcproc531021* p0, Tcprocsection531011 s0, NimStringDesc* frmt0, Ropeobj180006** args0, NI args0Len0) { Ropeobj180006** LOC1; Ropeobj180006* LOC2; Ropeobj180006* LOC3; LOC1 = (Ropeobj180006**)0; LOC1 = s_531179_3723162438(p0, s0); LOC2 = (Ropeobj180006*)0; LOC2 = ropecg_534407_839829468((*p0).module, frmt0, args0, args0Len0); LOC3 = (Ropeobj180006*)0; LOC3 = indentline_534656_839829468(p0, LOC2); add_180482_2381377266(LOC1, LOC3); } N_NIMCALL(void, gentraverseproc_539022_839829468)(Ttraversalclosure539019* c0, Ropeobj180006* accessor0, Ttype294840* typ_539027_839829468) { Ttype294840* typ_539302_839829468; Tcproc531021* p0; { { if (!(typ_539027_839829468 == NIM_NIL)) goto LA3; goto BeforeRet; } LA3: ; typ_539302_839829468 = getuniquetype_530640_2036603609(typ_539027_839829468); p0 = (*c0).p; switch ((*typ_539302_839829468).kind) { case ((Ttypekind294244) 11): case ((Ttypekind294244) 10): case ((Ttypekind294244) 8): { Ttype294840* LOC6; LOC6 = (Ttype294840*)0; LOC6 = lastson_297377_850551059(typ_539302_839829468); gentraverseproc_539022_839829468(c0, accessor0, LOC6); } break; case ((Ttypekind294244) 4): case ((Ttypekind294244) 16): { NI64 arraysize0; Tloc294816 i0; Ttype294840* LOC8; TY534811 LOC9; TY534811 LOC10; Ropeobj180006* LOC11; TY535289 LOC12; arraysize0 = lengthord_322007_3876443242((*typ_539302_839829468).sons->data[((NI) 0)]); memset((void*)(&i0), 0, sizeof(i0)); LOC8 = (Ttype294840*)0; LOC8 = getsystype_340150_3937434831(((Ttypekind294244) 31)); gettemp_539032_839829468(p0, LOC8, (&i0), NIM_FALSE); memset((void*)LOC9, 0, sizeof(LOC9)); LOC9[0] = i0.r; LOC9[1] = rope_180401_2381377266(arraysize0); linefmt_534714_839829468(p0, ((Tcprocsection531011) 2), ((NimStringDesc*) &T839829468_159), LOC9, 2); memset((void*)LOC10, 0, sizeof(LOC10)); LOC10[0] = accessor0; LOC10[1] = i0.r; LOC11 = (Ropeobj180006*)0; LOC11 = ropecg_534407_839829468(NIM_NIL, ((NimStringDesc*) &T839829468_138), LOC10, 2); gentraverseproc_539022_839829468(c0, LOC11, (*typ_539302_839829468).sons->data[((NI) 1)]); memset((void*)LOC12, 0, sizeof(LOC12)); linef_534700_839829468(p0, ((Tcprocsection531011) 2), ((NimStringDesc*) &T839829468_160), LOC12, 0); } break; case ((Ttypekind294244) 17): { { NI i_539325_839829468; NI HEX3Atmp_539384_839829468; NI LOC15; NI res_539387_839829468; i_539325_839829468 = (NI)0; HEX3Atmp_539384_839829468 = (NI)0; LOC15 = (NI)0; LOC15 = sonslen_297327_850551059(typ_539302_839829468); HEX3Atmp_539384_839829468 = (NI)(LOC15 - ((NI) 1)); res_539387_839829468 = ((NI) 0); { while (1) { Ttype294840* x0; Ropeobj180006* LOC22; if (!(res_539387_839829468 <= HEX3Atmp_539384_839829468)) goto LA17; i_539325_839829468 = res_539387_839829468; x0 = (*typ_539302_839829468).sons->data[i_539325_839829468]; { if (!!((x0 == NIM_NIL))) goto LA20; x0 = skiptypes_298099_850551059(x0, IL64(211106247215360)); } LA20: ; LOC22 = (Ropeobj180006*)0; LOC22 = parentobj_539257_839829468(accessor0, (*(*c0).p).module); gentraverseproc_539022_839829468(c0, LOC22, x0); res_539387_839829468 += ((NI) 1); } LA17: ; } } { if (!!(((*typ_539302_839829468).n == NIM_NIL))) goto LA25; gentraverseproc_539039_839829468(c0, accessor0, (*typ_539302_839829468).n); } LA25: ; } break; case ((Ttypekind294244) 18): { Ttype294840* typ0; typ0 = getuniquetype_530640_2036603609(typ_539302_839829468); { NI i_539363_839829468; NI HEX3Atmp_539392_839829468; NI LOC29; NI res_539395_839829468; i_539363_839829468 = (NI)0; HEX3Atmp_539392_839829468 = (NI)0; LOC29 = (NI)0; LOC29 = sonslen_297327_850551059(typ0); HEX3Atmp_539392_839829468 = (NI)(LOC29 - ((NI) 1)); res_539395_839829468 = ((NI) 0); { while (1) { TY534811 LOC32; Ropeobj180006* LOC33; if (!(res_539395_839829468 <= HEX3Atmp_539392_839829468)) goto LA31; i_539363_839829468 = res_539395_839829468; memset((void*)LOC32, 0, sizeof(LOC32)); LOC32[0] = accessor0; LOC32[1] = rope_180401_2381377266(((NI64) (i_539363_839829468))); LOC33 = (Ropeobj180006*)0; LOC33 = ropecg_534407_839829468(NIM_NIL, ((NimStringDesc*) &T839829468_185), LOC32, 2); gentraverseproc_539022_839829468(c0, LOC33, (*typ0).sons->data[i_539363_839829468]); res_539395_839829468 += ((NI) 1); } LA31: ; } } } break; case ((Ttypekind294244) 22): case ((Ttypekind294244) 28): case ((Ttypekind294244) 24): { TY180507 LOC35; memset((void*)LOC35, 0, sizeof(LOC35)); LOC35[0] = accessor0; linecg_534707_839829468(p0, ((Tcprocsection531011) 2), (*c0).visitorfrmt, LOC35, 1); } break; case ((Ttypekind294244) 25): { { TY180507 LOC41; TY180507 LOC42; if (!((*typ_539302_839829468).callconv == ((Tcallingconvention294002) 8))) goto LA39; memset((void*)LOC41, 0, sizeof(LOC41)); memset((void*)LOC42, 0, sizeof(LOC42)); LOC42[0] = accessor0; LOC41[0] = ropecg_534407_839829468(NIM_NIL, ((NimStringDesc*) &T839829468_186), LOC42, 1); linecg_534707_839829468(p0, ((Tcprocsection531011) 2), (*c0).visitorfrmt, LOC41, 1); } LA39: ; } break; default: { } break; } }BeforeRet: ; } N_NIMCALL(void, gentraverseprocseq_539399_839829468)(Ttraversalclosure539019* c0, Ropeobj180006* accessor0, Ttype294840* typ0) { Tcproc531021* p0; Tloc294816 i0; Ttype294840* LOC1; TY537238 LOC2; NimStringDesc* LOC3; TY534811 LOC11; Ropeobj180006* LOC12; TY535289 LOC13; p0 = (*c0).p; memset((void*)(&i0), 0, sizeof(i0)); LOC1 = (Ttype294840*)0; LOC1 = getsystype_340150_3937434831(((Ttypekind294244) 31)); gettemp_539032_839829468(p0, LOC1, (&i0), NIM_FALSE); memset((void*)LOC2, 0, sizeof(LOC2)); LOC2[0] = i0.r; LOC2[1] = accessor0; LOC3 = (NimStringDesc*)0; { NIM_BOOL LOC6; LOC6 = (NIM_BOOL)0; LOC6 = (gcmd_171132_2607990831 == ((Tcommands171076) 2)); if (LOC6) goto LA7; LOC6 = (((*(*(*(*c0).p).module).module).flags &(1U<<((NU)(((Tsymflag294184) 27))&31U)))!=0); LA7: ; if (!LOC6) goto LA8; LOC3 = copyString(((NimStringDesc*) &T839829468_157)); } goto LA4; LA8: ; { LOC3 = copyString(((NimStringDesc*) &T839829468_158)); } LA4: ; LOC2[2] = rope_180277_2381377266(LOC3); linef_534700_839829468(p0, ((Tcprocsection531011) 2), ((NimStringDesc*) &T839829468_156), LOC2, 3); memset((void*)LOC11, 0, sizeof(LOC11)); LOC11[0] = accessor0; LOC11[1] = i0.r; LOC12 = (Ropeobj180006*)0; LOC12 = HEX25_180905_2381377266(((NimStringDesc*) &T839829468_187), LOC11, 2); gentraverseproc_539022_839829468(c0, LOC12, (*typ0).sons->data[((NI) 0)]); memset((void*)LOC13, 0, sizeof(LOC13)); linef_534700_839829468(p0, ((Tcprocsection531011) 2), ((NimStringDesc*) &T839829468_160), LOC13, 0); } N_NIMCALL(Ropeobj180006*, gentraverseproc_539632_839829468)(Tcgen531027* m0, Ttype294840* typ0, Ttypeinforeason539016 reason0) { Ropeobj180006* result0; Ttraversalclosure539019 c0; Tcproc531021* p0; Ropeobj180006* header0; TY180507 LOC3; Ropeobj180006* t0; TY180507 LOC4; TY180507 LOC5; Ropeobj180006* generatedproc0; TY537235 LOC20; Ropeobj180006** LOC21; Ropeobj180006** LOC22; Ropeobj180006** LOC23; TY180507 LOC24; result0 = (Ropeobj180006*)0; memset((void*)(&c0), 0, sizeof(c0)); p0 = newproc_531206_3723162438(NIM_NIL, m0); result0 = gettempname_535596_839829468(m0); switch (reason0) { case ((Ttypeinforeason539016) 0): { c0.visitorfrmt = copyString(((NimStringDesc*) &T839829468_145)); } break; default: { } break; } memset((void*)LOC3, 0, sizeof(LOC3)); LOC3[0] = result0; header0 = HEX25_180905_2381377266(((NimStringDesc*) &T839829468_146), LOC3, 1); t0 = gettypedesc_537671_839829468(m0, typ0); memset((void*)LOC4, 0, sizeof(LOC4)); LOC4[0] = t0; linef_534700_839829468(p0, ((Tcprocsection531011) 0), ((NimStringDesc*) &T839829468_147), LOC4, 1); memset((void*)LOC5, 0, sizeof(LOC5)); LOC5[0] = t0; linef_534700_839829468(p0, ((Tcprocsection531011) 1), ((NimStringDesc*) &T839829468_148), LOC5, 1); c0.p = p0; { Ropeobj180006* LOC10; if (!((*typ0).kind == ((Ttypekind294244) 24))) goto LA8; LOC10 = (Ropeobj180006*)0; LOC10 = rope_180277_2381377266(((NimStringDesc*) &T839829468_188)); gentraverseprocseq_539399_839829468((&c0), LOC10, typ0); } goto LA6; LA8: ; { { Ttype294840* LOC14; Ropeobj180006* LOC17; LOC14 = (Ttype294840*)0; LOC14 = skiptypes_298099_850551059((*typ0).sons->data[((NI) 0)], IL64(211106232576256)); if (!((*LOC14).kind == ((Ttypekind294244) 4) || (*LOC14).kind == ((Ttypekind294244) 16))) goto LA15; LOC17 = (Ropeobj180006*)0; LOC17 = rope_180277_2381377266(((NimStringDesc*) &T839829468_188)); gentraverseproc_539022_839829468((&c0), LOC17, (*typ0).sons->data[((NI) 0)]); } goto LA12; LA15: ; { Ropeobj180006* LOC19; LOC19 = (Ropeobj180006*)0; LOC19 = rope_180277_2381377266(((NimStringDesc*) &T839829468_189)); gentraverseproc_539022_839829468((&c0), LOC19, (*typ0).sons->data[((NI) 0)]); } LA12: ; } LA6: ; memset((void*)LOC20, 0, sizeof(LOC20)); LOC20[0] = header0; LOC21 = (Ropeobj180006**)0; LOC21 = s_531179_3723162438(p0, ((Tcprocsection531011) 0)); LOC20[1] = (*LOC21); LOC22 = (Ropeobj180006**)0; LOC22 = s_531179_3723162438(p0, ((Tcprocsection531011) 1)); LOC20[2] = (*LOC22); LOC23 = (Ropeobj180006**)0; LOC23 = s_531179_3723162438(p0, ((Tcprocsection531011) 2)); LOC20[3] = (*LOC23); generatedproc0 = HEX25_180905_2381377266(((NimStringDesc*) &T839829468_190), LOC20, 4); memset((void*)LOC24, 0, sizeof(LOC24)); LOC24[0] = header0; addf_181205_2381377266(&(*m0).s[(((Tcfilesection531005) 7))- 0], ((NimStringDesc*) &T839829468_191), LOC24, 1); add_180482_2381377266(&(*m0).s[(((Tcfilesection531005) 10))- 0], generatedproc0); return result0; } N_NIMCALL(void, genarrayinfo_539005_839829468)(Tcgen531027* m0, Ttype294840* typ0, Ropeobj180006* name0) { Ropeobj180006* LOC1; LOC1 = (Ropeobj180006*)0; LOC1 = gentypeinfo_537941_839829468(m0, (*typ0).sons->data[((NI) 1)]); gentypeinfoauxbase_537960_839829468(m0, typ0, typ0, name0, LOC1); } N_NIMCALL(void, gensetinfo_538867_839829468)(Tcgen531027* m0, Ttype294840* typ0, Ropeobj180006* name0) { Ropeobj180006* tmp0; TY537238 LOC1; NI64 LOC2; gentypeinfoaux_538027_839829468(m0, typ0, typ0, name0); tmp0 = getnimnode_537945_839829468(m0); memset((void*)LOC1, 0, sizeof(LOC1)); LOC1[0] = tmp0; LOC2 = (NI64)0; LOC2 = firstord_322001_3876443242(typ0); LOC1[1] = rope_180401_2381377266(LOC2); LOC1[2] = name0; addf_181205_2381377266(&(*m0).s[(((Tcfilesection531005) 14))- 0], ((NimStringDesc*) &T839829468_193), LOC1, 3); } N_NIMCALL(void, genenuminfo_538597_839829468)(Tcgen531027* m0, Ttype294840* typ0, Ropeobj180006* name0) { Ropeobj180006* nodeptrs0; NI length0; TY534811 LOC1; Ropeobj180006* enumnames0; Ropeobj180006* specialcases0; NI firstnimnode0; NIM_BOOL hasholes0; Ropeobj180006* enumarray0; Ropeobj180006* counter0; TY180507 LOC24; TY537238 LOC25; TY538847 LOC26; TY537235 LOC27; gentypeinfoaux_538027_839829468(m0, typ0, typ0, name0); nodeptrs0 = gettempname_535596_839829468(m0); length0 = sonslen_297351_850551059((*typ0).n); memset((void*)LOC1, 0, sizeof(LOC1)); LOC1[0] = nodeptrs0; LOC1[1] = rope_180401_2381377266(((NI64) (length0))); addf_181205_2381377266(&(*m0).s[(((Tcfilesection531005) 12))- 0], ((NimStringDesc*) &T839829468_139), LOC1, 2); enumnames0 = (Ropeobj180006*)0; specialcases0 = (Ropeobj180006*)0; firstnimnode0 = (*m0).typenodes; hasholes0 = NIM_FALSE; { NI i_538622_839829468; NI HEX3Atmp_538860_839829468; NI res_538863_839829468; i_538622_839829468 = (NI)0; HEX3Atmp_538860_839829468 = (NI)0; HEX3Atmp_538860_839829468 = (NI)(length0 - ((NI) 1)); res_538863_839829468 = ((NI) 0); { while (1) { Tsym294834* field0; Ropeobj180006* elemnode0; if (!(res_538863_839829468 <= HEX3Atmp_538860_839829468)) goto LA4; i_538622_839829468 = res_538863_839829468; field0 = (*(*(*typ0).n).kindU.S6.sons->data[i_538622_839829468]).kindU.S4.sym; elemnode0 = getnimnode_537945_839829468(m0); { Ropeobj180006* LOC9; if (!((*field0).ast == NIM_NIL)) goto LA7; LOC9 = (Ropeobj180006*)0; LOC9 = makecstring_193638_155036129((*(*field0).name).s); add_180482_2381377266(&enumnames0, LOC9); } goto LA5; LA7: ; { Ropeobj180006* LOC11; LOC11 = (Ropeobj180006*)0; LOC11 = makecstring_193638_155036129((*(*field0).ast).kindU.S3.strval); add_180482_2381377266(&enumnames0, LOC11); } LA5: ; { NimStringDesc* LOC16; if (!(i_538622_839829468 < (NI)(length0 - ((NI) 1)))) goto LA14; LOC16 = (NimStringDesc*)0; LOC16 = rawNewString(tnl_178644_4151366050->Sup.len + 2); appendString(LOC16, ((NimStringDesc*) &T839829468_110)); appendString(LOC16, tnl_178644_4151366050); add_180487_2381377266(&enumnames0, LOC16); } LA14: ; { NIM_BOOL LOC19; TY534811 LOC23; LOC19 = (NIM_BOOL)0; LOC19 = !(((*field0).position == i_538622_839829468)); if (LOC19) goto LA20; LOC19 = (((*typ0).flags &(1U<<((NU)(((Ttypeflag294431) 5))&31U)))!=0); LA20: ; if (!LOC19) goto LA21; memset((void*)LOC23, 0, sizeof(LOC23)); LOC23[0] = elemnode0; LOC23[1] = rope_180401_2381377266(((NI64) ((*field0).position))); addf_181205_2381377266(&specialcases0, ((NimStringDesc*) &T839829468_194), LOC23, 2); hasholes0 = NIM_TRUE; } LA21: ; res_538863_839829468 += ((NI) 1); } LA4: ; } } enumarray0 = gettempname_535596_839829468(m0); counter0 = gettempname_535596_839829468(m0); memset((void*)LOC24, 0, sizeof(LOC24)); LOC24[0] = counter0; addf_181205_2381377266(&(*m0).s[(((Tcfilesection531005) 12))- 0], ((NimStringDesc*) &T839829468_195), LOC24, 1); memset((void*)LOC25, 0, sizeof(LOC25)); LOC25[0] = enumarray0; LOC25[1] = rope_180401_2381377266(((NI64) (length0))); LOC25[2] = enumnames0; addf_181205_2381377266(&(*m0).s[(((Tcfilesection531005) 12))- 0], ((NimStringDesc*) &T839829468_196), LOC25, 3); memset((void*)LOC26, 0, sizeof(LOC26)); LOC26[0] = counter0; LOC26[1] = rope_180401_2381377266(((NI64) (length0))); LOC26[2] = (*m0).typenodesname; LOC26[3] = rope_180401_2381377266(((NI64) (firstnimnode0))); LOC26[4] = enumarray0; LOC26[5] = nodeptrs0; addf_181205_2381377266(&(*m0).s[(((Tcfilesection531005) 14))- 0], ((NimStringDesc*) &T839829468_197), LOC26, 6); add_180482_2381377266(&(*m0).s[(((Tcfilesection531005) 14))- 0], specialcases0); memset((void*)LOC27, 0, sizeof(LOC27)); LOC27[0] = getnimnode_537945_839829468(m0); LOC27[1] = rope_180401_2381377266(((NI64) (length0))); LOC27[2] = nodeptrs0; LOC27[3] = name0; addf_181205_2381377266(&(*m0).s[(((Tcfilesection531005) 14))- 0], ((NimStringDesc*) &T839829468_198), LOC27, 4); { TY180507 LOC32; if (!hasholes0) goto LA30; memset((void*)LOC32, 0, sizeof(LOC32)); LOC32[0] = name0; addf_181205_2381377266(&(*m0).s[(((Tcfilesection531005) 14))- 0], ((NimStringDesc*) &T839829468_199), LOC32, 1); } LA30: ; } N_NIMCALL(Ropeobj180006*, discriminatortablename_538057_839829468)(Tcgen531027* m0, Ttype294840* objtype_538060_839829468, Tsym294834* d0) { Ropeobj180006* result0; Ttype294840* objtype0; TY534811 LOC8; NimStringDesc* LOC9; result0 = (Ropeobj180006*)0; objtype0 = objtype_538060_839829468; { while (1) { Tsym294834* LOC3; LOC3 = (Tsym294834*)0; LOC3 = lookupinrecord_301119_2984716966((*objtype0).n, (*d0).name); if (!(LOC3 == NIM_NIL)) goto LA2; objtype0 = (*objtype0).sons->data[((NI) 0)]; } LA2: ; } { if (!((*objtype0).sym == NIM_NIL)) goto LA6; internalerror_198100_155036129((*d0).info, ((NimStringDesc*) &T839829468_200)); } LA6: ; memset((void*)LOC8, 0, sizeof(LOC8)); LOC8[0] = rope_180401_2381377266(((NI64) ((*objtype0).Sup.id))); LOC9 = (NimStringDesc*)0; LOC9 = mangle_530847_2036603609((*(*d0).name).s); LOC8[1] = rope_180277_2381377266(LOC9); result0 = HEX25_180905_2381377266(((NimStringDesc*) &T839829468_201), LOC8, 2); return result0; } N_NIMCALL(void, genobjectfields_538104_839829468)(Tcgen531027* m0, Ttype294840* typ0, Tnode294802* n0, Ropeobj180006* expr0) { switch ((*n0).kind) { case ((Tnodekind294020) 138): { NI L0; L0 = sonslen_297351_850551059(n0); { if (!(L0 == ((NI) 1))) goto LA4; genobjectfields_538104_839829468(m0, typ0, (*n0).kindU.S6.sons->data[((NI) 0)], expr0); } goto LA2; LA4: ; { Ropeobj180006* tmp0; TY534811 LOC9; TY537238 LOC14; if (!(((NI) 0) < L0)) goto LA7; tmp0 = gettempname_535596_839829468(m0); memset((void*)LOC9, 0, sizeof(LOC9)); LOC9[0] = tmp0; LOC9[1] = rope_180401_2381377266(((NI64) (L0))); addf_181205_2381377266(&(*m0).s[(((Tcfilesection531005) 12))- 0], ((NimStringDesc*) &T839829468_139), LOC9, 2); { NI i_538127_839829468; NI HEX3Atmp_538482_839829468; NI res_538485_839829468; i_538127_839829468 = (NI)0; HEX3Atmp_538482_839829468 = (NI)0; HEX3Atmp_538482_839829468 = (NI)(L0 - ((NI) 1)); res_538485_839829468 = ((NI) 0); { while (1) { Ropeobj180006* tmp20; TY537238 LOC13; if (!(res_538485_839829468 <= HEX3Atmp_538482_839829468)) goto LA12; i_538127_839829468 = res_538485_839829468; tmp20 = getnimnode_537945_839829468(m0); memset((void*)LOC13, 0, sizeof(LOC13)); LOC13[0] = tmp0; LOC13[1] = rope_180401_2381377266(((NI64) (i_538127_839829468))); LOC13[2] = tmp20; addf_181205_2381377266(&(*m0).s[(((Tcfilesection531005) 14))- 0], ((NimStringDesc*) &T839829468_140), LOC13, 3); genobjectfields_538104_839829468(m0, typ0, (*n0).kindU.S6.sons->data[i_538127_839829468], tmp20); res_538485_839829468 += ((NI) 1); } LA12: ; } } memset((void*)LOC14, 0, sizeof(LOC14)); LOC14[0] = expr0; LOC14[1] = rope_180401_2381377266(((NI64) (L0))); LOC14[2] = tmp0; addf_181205_2381377266(&(*m0).s[(((Tcfilesection531005) 14))- 0], ((NimStringDesc*) &T839829468_142), LOC14, 3); } goto LA2; LA7: ; { TY534811 LOC16; memset((void*)LOC16, 0, sizeof(LOC16)); LOC16[0] = expr0; LOC16[1] = rope_180401_2381377266(((NI64) (L0))); addf_181205_2381377266(&(*m0).s[(((Tcfilesection531005) 14))- 0], ((NimStringDesc*) &T839829468_143), LOC16, 2); } LA2: ; } break; case ((Tnodekind294020) 139): { Tsym294834* field0; Ropeobj180006* tmp0; NI64 L0; TY538401 LOC18; TY534811 LOC19; field0 = (*(*n0).kindU.S6.sons->data[((NI) 0)]).kindU.S4.sym; tmp0 = discriminatortablename_538057_839829468(m0, typ0, field0); L0 = lengthord_322007_3876443242((*field0).typ); memset((void*)LOC18, 0, sizeof(LOC18)); LOC18[0] = expr0; LOC18[1] = gettypedesc_537671_839829468(m0, typ0); LOC18[2] = (*field0).loc.r; LOC18[3] = gentypeinfo_537941_839829468(m0, (*field0).typ); LOC18[4] = makecstring_193638_155036129((*(*field0).name).s); LOC18[5] = tmp0; LOC18[6] = rope_180401_2381377266(L0); addf_181205_2381377266(&(*m0).s[(((Tcfilesection531005) 14))- 0], ((NimStringDesc*) &T839829468_202), LOC18, 7); memset((void*)LOC19, 0, sizeof(LOC19)); LOC19[0] = tmp0; LOC19[1] = rope_180401_2381377266((NI64)(L0 + IL64(1))); addf_181205_2381377266(&(*m0).s[(((Tcfilesection531005) 8))- 0], ((NimStringDesc*) &T839829468_203), LOC19, 2); { NI i_538421_839829468; NI HEX3Atmp_538499_839829468; NI LOC21; NI res_538502_839829468; i_538421_839829468 = (NI)0; HEX3Atmp_538499_839829468 = (NI)0; LOC21 = (NI)0; LOC21 = sonslen_297351_850551059(n0); HEX3Atmp_538499_839829468 = (NI)(LOC21 - ((NI) 1)); res_538502_839829468 = ((NI) 1); { while (1) { Tnode294802* b0; Ropeobj180006* tmp20; Tnode294802* LOC24; if (!(res_538502_839829468 <= HEX3Atmp_538499_839829468)) goto LA23; i_538421_839829468 = res_538502_839829468; b0 = (*n0).kindU.S6.sons->data[i_538421_839829468]; tmp20 = getnimnode_537945_839829468(m0); LOC24 = (Tnode294802*)0; LOC24 = lastson_297364_850551059(b0); genobjectfields_538104_839829468(m0, typ0, LOC24, tmp20); switch ((*b0).kind) { case ((Tnodekind294020) 85): { { NI LOC28; LOC28 = (NI)0; LOC28 = sonslen_297351_850551059(b0); if (!(LOC28 < ((NI) 2))) goto LA29; internalerror_198100_155036129((*b0).info, ((NimStringDesc*) &T839829468_204)); } LA29: ; { NI j_538436_839829468; NI HEX3Atmp_538492_839829468; NI LOC32; NI res_538495_839829468; j_538436_839829468 = (NI)0; HEX3Atmp_538492_839829468 = (NI)0; LOC32 = (NI)0; LOC32 = sonslen_297351_850551059(b0); HEX3Atmp_538492_839829468 = (NI)(LOC32 - ((NI) 2)); res_538495_839829468 = ((NI) 0); { while (1) { if (!(res_538495_839829468 <= HEX3Atmp_538492_839829468)) goto LA34; j_538436_839829468 = res_538495_839829468; { NI x0; NI64 LOC39; NI y0; NI64 LOC40; if (!((*(*b0).kindU.S6.sons->data[j_538436_839829468]).kind == ((Tnodekind294020) 44))) goto LA37; LOC39 = (NI64)0; LOC39 = getordvalue_322129_3876443242((*(*b0).kindU.S6.sons->data[j_538436_839829468]).kindU.S6.sons->data[((NI) 0)]); x0 = ((NI) (LOC39)); LOC40 = (NI64)0; LOC40 = getordvalue_322129_3876443242((*(*b0).kindU.S6.sons->data[j_538436_839829468]).kindU.S6.sons->data[((NI) 1)]); y0 = ((NI) (LOC40)); { while (1) { TY537238 LOC43; if (!(x0 <= y0)) goto LA42; memset((void*)LOC43, 0, sizeof(LOC43)); LOC43[0] = tmp0; LOC43[1] = rope_180401_2381377266(((NI64) (x0))); LOC43[2] = tmp20; addf_181205_2381377266(&(*m0).s[(((Tcfilesection531005) 14))- 0], ((NimStringDesc*) &T839829468_140), LOC43, 3); x0 += ((NI) 1); } LA42: ; } } goto LA35; LA37: ; { TY537238 LOC45; NI64 LOC46; memset((void*)LOC45, 0, sizeof(LOC45)); LOC45[0] = tmp0; LOC46 = (NI64)0; LOC46 = getordvalue_322129_3876443242((*b0).kindU.S6.sons->data[j_538436_839829468]); LOC45[1] = rope_180401_2381377266(LOC46); LOC45[2] = tmp20; addf_181205_2381377266(&(*m0).s[(((Tcfilesection531005) 14))- 0], ((NimStringDesc*) &T839829468_140), LOC45, 3); } LA35: ; res_538495_839829468 += ((NI) 1); } LA34: ; } } } break; case ((Tnodekind294020) 88): { TY537238 LOC48; memset((void*)LOC48, 0, sizeof(LOC48)); LOC48[0] = tmp0; LOC48[1] = rope_180401_2381377266(L0); LOC48[2] = tmp20; addf_181205_2381377266(&(*m0).s[(((Tcfilesection531005) 14))- 0], ((NimStringDesc*) &T839829468_140), LOC48, 3); } break; default: { internalerror_198100_155036129((*n0).info, ((NimStringDesc*) &T839829468_205)); } break; } res_538502_839829468 += ((NI) 1); } LA23: ; } } } break; case ((Tnodekind294020) 3): { Tsym294834* field0; field0 = (*n0).kindU.S4.sym; { TY538475 LOC55; if (!((*field0).kindU.S4.bitsize == ((NI) 0))) goto LA53; memset((void*)LOC55, 0, sizeof(LOC55)); LOC55[0] = expr0; LOC55[1] = gettypedesc_537671_839829468(m0, typ0); LOC55[2] = (*field0).loc.r; LOC55[3] = gentypeinfo_537941_839829468(m0, (*field0).typ); LOC55[4] = makecstring_193638_155036129((*(*field0).name).s); addf_181205_2381377266(&(*m0).s[(((Tcfilesection531005) 14))- 0], ((NimStringDesc*) &T839829468_206), LOC55, 5); } LA53: ; } break; default: { internalerror_198100_155036129((*n0).info, ((NimStringDesc*) &T839829468_207)); } break; } } N_NIMCALL(void, genobjectinfo_538506_839829468)(Tcgen531027* m0, Ttype294840* typ0, Ttype294840* origtype0, Ropeobj180006* name0) { Ropeobj180006* tmp0; TY534811 LOC12; Ttype294840* t0; { if (!((*typ0).kind == ((Ttypekind294244) 17))) goto LA3; gentypeinfoaux_538027_839829468(m0, typ0, origtype0, name0); } goto LA1; LA3: ; { Ropeobj180006* LOC6; LOC6 = (Ropeobj180006*)0; LOC6 = rope_180277_2381377266(((NimStringDesc*) &T839829468_18)); gentypeinfoauxbase_537960_839829468(m0, typ0, origtype0, name0, LOC6); } LA1: ; tmp0 = getnimnode_537945_839829468(m0); { NIM_BOOL LOC9; LOC9 = (NIM_BOOL)0; LOC9 = isimportedcpptype_535476_839829468(typ0); if (!!(LOC9)) goto LA10; genobjectfields_538104_839829468(m0, typ0, (*typ0).n, tmp0); } LA10: ; memset((void*)LOC12, 0, sizeof(LOC12)); LOC12[0] = name0; LOC12[1] = tmp0; addf_181205_2381377266(&(*m0).s[(((Tcfilesection531005) 14))- 0], ((NimStringDesc*) &T839829468_144), LOC12, 2); t0 = (*typ0).sons->data[((NI) 0)]; { while (1) { if (!!((t0 == NIM_NIL))) goto LA14; t0 = skiptypes_298099_850551059(t0, IL64(211106247215360)); (*t0).flags |= ((NU32)1)<<((((Ttypeflag294431) 5))%(sizeof(NU32)*8)); t0 = (*t0).sons->data[((NI) 0)]; } LA14: ; } } N_NIMCALL(void, gendeepcopyproc_540066_839829468)(Tcgen531027* m0, Tsym294834* s0, Ropeobj180006* result0) { TY534811 LOC1; genproc_534951_839829468(m0, s0); memset((void*)LOC1, 0, sizeof(LOC1)); LOC1[0] = result0; LOC1[1] = (*s0).loc.r; addf_181205_2381377266(&(*m0).s[(((Tcfilesection531005) 14))- 0], ((NimStringDesc*) &T839829468_208), LOC1, 2); } N_NIMCALL(Ropeobj180006*, gentypeinfo_537941_839829468)(Tcgen531027* m0, Ttype294840* t_537944_839829468) { Ropeobj180006* result0; Ttype294840* origtype0; Ttype294840* t0; TY180507 LOC1; Tsym294834* owner0; Ttype294840* LOC12; Ropeobj180006* LOC66; Ropeobj180006* LOC67; Ropeobj180006* LOC68; { result0 = (Ropeobj180006*)0; origtype0 = t_537944_839829468; t0 = getuniquetype_530640_2036603609(t_537944_839829468); memset((void*)LOC1, 0, sizeof(LOC1)); LOC1[0] = rope_180401_2381377266(((NI64) ((*t0).Sup.id))); result0 = HEX25_180905_2381377266(((NimStringDesc*) &T839829468_127), LOC1, 1); { NIM_BOOL LOC4; Ropeobj180006* LOC7; Ropeobj180006* LOC8; Ropeobj180006* LOC9; LOC4 = (NIM_BOOL)0; LOC4 = containsorincl_270862_2627731572((&(*m0).typeinfomarker), (*t0).Sup.id); if (!LOC4) goto LA5; LOC7 = (Ropeobj180006*)0; LOC7 = rope_180277_2381377266(((NimStringDesc*) &T839829468_128)); LOC8 = (Ropeobj180006*)0; LOC8 = HEX26_180418_2381377266(LOC7, result0); LOC9 = (Ropeobj180006*)0; LOC9 = rope_180277_2381377266(((NimStringDesc*) &T839829468_117)); result0 = HEX26_180418_2381377266(LOC8, LOC9); goto BeforeRet; } LA5: ; { while (1) { if (!((*t0).kind == ((Ttypekind294244) 13))) goto LA11; t0 = lastson_297377_850551059(t0); } LA11: ; } LOC12 = (Ttype294840*)0; LOC12 = skiptypes_298099_850551059(t0, IL64(211106247256320)); owner0 = getmodule_301123_2984716966((*LOC12).owner); { Tcgen531027* LOC17; Ropeobj180006* LOC18; Ropeobj180006* LOC19; Ropeobj180006* LOC20; TY534811 LOC21; NimStringDesc* LOC22; Ropeobj180006* LOC23; Ropeobj180006* LOC24; Ropeobj180006* LOC25; if (!!((owner0 == (*m0).module))) goto LA15; LOC17 = (Tcgen531027*)0; LOC17 = bmod_531201_3723162438(owner0); LOC18 = (Ropeobj180006*)0; LOC18 = gentypeinfo_537941_839829468(LOC17, t0); LOC19 = (Ropeobj180006*)0; LOC19 = cgsym_534403_839829468(m0, ((NimStringDesc*) &T839829468_129)); LOC20 = (Ropeobj180006*)0; LOC20 = cgsym_534403_839829468(m0, ((NimStringDesc*) &T839829468_130)); memset((void*)LOC21, 0, sizeof(LOC21)); LOC21[0] = result0; LOC22 = (NimStringDesc*)0; LOC22 = typetostring_322017_3876443242(t0, ((Tprefereddesc322011) 0)); LOC21[1] = rope_180277_2381377266(LOC22); addf_181205_2381377266(&(*m0).s[(((Tcfilesection531005) 9))- 0], ((NimStringDesc*) &T839829468_131), LOC21, 2); LOC23 = (Ropeobj180006*)0; LOC23 = rope_180277_2381377266(((NimStringDesc*) &T839829468_128)); LOC24 = (Ropeobj180006*)0; LOC24 = HEX26_180418_2381377266(LOC23, result0); LOC25 = (Ropeobj180006*)0; LOC25 = rope_180277_2381377266(((NimStringDesc*) &T839829468_117)); result0 = HEX26_180418_2381377266(LOC24, LOC25); goto BeforeRet; } LA15: ; switch ((*t0).kind) { case ((Ttypekind294244) 3): case ((Ttypekind294244) 62): { result0 = rope_180277_2381377266(((NimStringDesc*) &T839829468_132)); } break; case ((Ttypekind294244) 26): case ((Ttypekind294244) 1): case ((Ttypekind294244) 2): case ((Ttypekind294244) 29): case ((Ttypekind294244) 28): case ((Ttypekind294244) 31) ... ((Ttypekind294244) 44): case ((Ttypekind294244) 23): { Ropeobj180006* LOC28; LOC28 = (Ropeobj180006*)0; LOC28 = rope_180277_2381377266(((NimStringDesc*) &T839829468_132)); gentypeinfoauxbase_537960_839829468(m0, t0, t0, result0, LOC28); } break; case ((Ttypekind294244) 59): { { Ttype294840* LOC34; if (!!(((*t0).n == NIM_NIL))) goto LA32; LOC34 = (Ttype294840*)0; LOC34 = lastson_297377_850551059(t0); result0 = gentypeinfo_537941_839829468(m0, LOC34); } goto LA30; LA32: ; { NimStringDesc* LOC36; LOC36 = (NimStringDesc*)0; LOC36 = rawNewString(reprEnum((NI)(*t0).kind, (&NTI294244))->Sup.len + 13); appendString(LOC36, ((NimStringDesc*) &T839829468_137)); appendString(LOC36, reprEnum((NI)(*t0).kind, (&NTI294244))); appendChar(LOC36, 41); internalerror_198113_155036129(LOC36); } LA30: ; } break; case ((Ttypekind294244) 25): { { Ropeobj180006* LOC42; if (!!(((*t0).callconv == ((Tcallingconvention294002) 8)))) goto LA40; LOC42 = (Ropeobj180006*)0; LOC42 = rope_180277_2381377266(((NimStringDesc*) &T839829468_132)); gentypeinfoauxbase_537960_839829468(m0, t0, t0, result0, LOC42); } goto LA38; LA40: ; { Ttype294840* LOC44; LOC44 = (Ttype294840*)0; LOC44 = fakeclosuretype_539010_839829468((*t0).owner); gentupleinfo_538549_839829468(m0, LOC44, result0); } LA38: ; } break; case ((Ttypekind294244) 24): case ((Ttypekind294244) 22): { gentypeinfoaux_538027_839829468(m0, t0, t0, result0); { Ropeobj180006* markerproc0; TY534811 LOC50; if (!(((Tgcmode171080) 4) <= gselectedgc_171133_2607990831)) goto LA48; markerproc0 = gentraverseproc_539632_839829468(m0, t0, ((Ttypeinforeason539016) 0)); memset((void*)LOC50, 0, sizeof(LOC50)); LOC50[0] = result0; LOC50[1] = markerproc0; addf_181205_2381377266(&(*m0).s[(((Tcfilesection531005) 14))- 0], ((NimStringDesc*) &T839829468_192), LOC50, 2); } LA48: ; } break; case ((Ttypekind294244) 21): case ((Ttypekind294244) 20): { gentypeinfoaux_538027_839829468(m0, t0, t0, result0); } break; case ((Ttypekind294244) 4): case ((Ttypekind294244) 16): { genarrayinfo_539005_839829468(m0, t0, result0); } break; case ((Ttypekind294244) 19): { gensetinfo_538867_839829468(m0, t0, result0); } break; case ((Ttypekind294244) 14): { genenuminfo_538597_839829468(m0, t0, result0); } break; case ((Ttypekind294244) 17): { genobjectinfo_538506_839829468(m0, t0, origtype0, result0); } break; case ((Ttypekind294244) 18): { gentupleinfo_538549_839829468(m0, t0, result0); } break; default: { NimStringDesc* LOC58; LOC58 = (NimStringDesc*)0; LOC58 = rawNewString(reprEnum((NI)(*t0).kind, (&NTI294244))->Sup.len + 13); appendString(LOC58, ((NimStringDesc*) &T839829468_137)); appendString(LOC58, reprEnum((NI)(*t0).kind, (&NTI294244))); appendChar(LOC58, 41); internalerror_198113_155036129(LOC58); } break; } { if (!!(((*t0).deepcopy == NIM_NIL))) goto LA61; gendeepcopyproc_540066_839829468(m0, (*t0).deepcopy, result0); } goto LA59; LA61: ; { if (!!(((*origtype0).deepcopy == NIM_NIL))) goto LA64; gendeepcopyproc_540066_839829468(m0, (*origtype0).deepcopy, result0); } goto LA59; LA64: ; LA59: ; LOC66 = (Ropeobj180006*)0; LOC66 = rope_180277_2381377266(((NimStringDesc*) &T839829468_128)); LOC67 = (Ropeobj180006*)0; LOC67 = HEX26_180418_2381377266(LOC66, result0); LOC68 = (Ropeobj180006*)0; LOC68 = rope_180277_2381377266(((NimStringDesc*) &T839829468_117)); result0 = HEX26_180418_2381377266(LOC67, LOC68); }BeforeRet: ; return result0; } N_NIMCALL(void, localdebuginfo_540449_839829468)(Tcproc531021* p0, Tsym294834* s0) { Ropeobj180006* a0; TY537235 LOC16; NimStringDesc* LOC17; { { if (!!(((163840 & (*p0).options) == 163840))) goto LA3; goto BeforeRet; } LA3: ; { Ttype294840* LOC7; LOC7 = (Ttype294840*)0; LOC7 = skiptypes_298099_850551059((*s0).typ, IL64(211106240964864)); if (!((*LOC7).kind == ((Ttypekind294244) 27) || (*LOC7).kind == ((Ttypekind294244) 48))) goto LA8; goto BeforeRet; } LA8: ; a0 = HEX26_180452_2381377266(((NimStringDesc*) &T839829468_52), (*s0).loc.r); { NIM_BOOL LOC12; LOC12 = (NIM_BOOL)0; LOC12 = ((*s0).kind == ((Tsymkind294435) 3)); if (!(LOC12)) goto LA13; LOC12 = ccgintroducedptr_535609_839829468(s0); LA13: ; if (!LOC12) goto LA14; a0 = (*s0).loc.r; } LA14: ; memset((void*)LOC16, 0, sizeof(LOC16)); LOC16[0] = rope_180401_2381377266(((NI64) ((*p0).maxframelen))); LOC17 = (NimStringDesc*)0; LOC17 = nsuNormalize((*(*s0).name).s); LOC16[1] = makecstring_193638_155036129(LOC17); LOC16[2] = a0; LOC16[3] = gentypeinfo_537941_839829468((*p0).module, (*s0).loc.t); linef_534700_839829468(p0, ((Tcprocsection531011) 1), ((NimStringDesc*) &T839829468_126), LOC16, 4); (*p0).maxframelen += ((NI) 1); (*p0).blocks->data[(NI)(((*p0).blocks ? (*p0).blocks->Sup.len : 0) - ((NI) 1))].framelen += ((NI) 1); }BeforeRet: ; } N_NIMCALL(void, assignlocalvar_540614_839829468)(Tcproc531021* p0, Tsym294834* s0) { Ropeobj180006* decl0; Ropeobj180006* LOC1; Ropeobj180006* LOC2; LOC1 = (Ropeobj180006*)0; LOC1 = localvardecl_540532_839829468(p0, s0); LOC2 = (Ropeobj180006*)0; LOC2 = HEX26_180447_2381377266(LOC1, ((NimStringDesc*) &T839829468_125)); decl0 = HEX26_180447_2381377266(LOC2, tnl_178644_4151366050); line_534690_839829468(p0, ((Tcprocsection531011) 0), decl0); localdebuginfo_540449_839829468(p0, s0); } N_NIMCALL(void, initlocalvar_540398_839829468)(Tcproc531021* p0, Tsym294834* v0, NIM_BOOL immediateasgn0) { { if (!!((((*v0).flags &(1U<<((NU)(((Tsymflag294184) 12))&31U)))!=0))) goto LA3; { if (!!(immediateasgn0)) goto LA7; constructloc_540388_839829468(p0, (*v0).loc, NIM_FALSE); } LA7: ; } LA3: ; } N_NIMCALL(void, fillresult_535865_839829468)(Tsym294834* param0) { TY535289 LOC1; Ropeobj180006* LOC2; memset((void*)LOC1, 0, sizeof(LOC1)); LOC2 = (Ropeobj180006*)0; LOC2 = HEX25_180905_2381377266(((NimStringDesc*) &T839829468_210), LOC1, 0); fillloc_534282_839829468((&(*param0).loc), ((Tlockind294808) 4), (*param0).typ, LOC2, ((Tstorageloc294812) 2)); { NIM_BOOL LOC5; Tctypekind531007 LOC6; LOC5 = (NIM_BOOL)0; LOC6 = (Tctypekind531007)0; LOC6 = mapreturntype_535445_839829468((*param0).typ); LOC5 = !((LOC6 == ((Tctypekind531007) 17))); if (!(LOC5)) goto LA7; LOC5 = isinvalidreturntype_535548_839829468((*param0).typ); LA7: ; if (!LOC5) goto LA8; (*param0).loc.flags |= ((NU16)1)<<((((Tlocflag294810) 0))%(sizeof(NU16)*8)); (*param0).loc.s = ((Tstorageloc294812) 0); } LA8: ; } N_NIMCALL(void, assignparam_540994_839829468)(Tcproc531021* p0, Tsym294834* s0) { localdebuginfo_540449_839829468(p0, s0); } N_NIMCALL(void, closuresetup_562158_839829468)(Tcproc531021* p0, Tsym294834* prc0) { Tnode294802* ls0; Tnode294802* LOC5; Tsym294834* env0; TY534811 LOC10; { { if (!!((((*(*prc0).typ).flags &(1U<<((NU)(((Ttypeflag294431) 11))&31U)))!=0))) goto LA3; goto BeforeRet; } LA3: ; LOC5 = (Tnode294802*)0; LOC5 = HEX5BHEX5D_295238_850551059((*prc0).ast, ((NI) 3)); ls0 = lastson_297364_850551059(LOC5); { if (!!(((*ls0).kind == ((Tnodekind294020) 3)))) goto LA8; internalerror_198100_155036129((*prc0).info, ((NimStringDesc*) &T839829468_211)); } LA8: ; env0 = (*ls0).kindU.S4.sym; assignlocalvar_540614_839829468(p0, env0); memset((void*)LOC10, 0, sizeof(LOC10)); LOC10[0] = rdloc_540188_839829468((*env0).loc); LOC10[1] = gettypedesc_537671_839829468((*p0).module, (*env0).typ); linefmt_534714_839829468(p0, ((Tcprocsection531011) 2), ((NimStringDesc*) &T839829468_212), LOC10, 2); }BeforeRet: ; } N_NIMCALL(Ropeobj180006*, initgcframe_540435_839829468)(Tcproc531021* p0) { Ropeobj180006* result0; result0 = (Ropeobj180006*)0; { TY180507 LOC5; if (!(((NI) 0) < ((NI) ((*p0).gcframeid)))) goto LA3; memset((void*)LOC5, 0, sizeof(LOC5)); LOC5[0] = (*p0).gcframetype; result0 = HEX25_180905_2381377266(((NimStringDesc*) &T839829468_217), LOC5, 1); } LA3: ; return result0; } N_NIMCALL(Ropeobj180006*, initframe_562140_839829468)(Tcproc531021* p0, Ropeobj180006* procname0, Ropeobj180006* filename0) { Ropeobj180006* result0; Ropeobj180006* LOC1; result0 = (Ropeobj180006*)0; LOC1 = (Ropeobj180006*)0; LOC1 = cgsym_534403_839829468((*p0).module, ((NimStringDesc*) &T839829468_218)); { Ropeobj180006* LOC6; TY537235 LOC7; if (!(((NI) 0) < (*p0).maxframelen)) goto LA4; LOC6 = (Ropeobj180006*)0; LOC6 = cgsym_534403_839829468((*p0).module, ((NimStringDesc*) &T839829468_219)); memset((void*)LOC7, 0, sizeof(LOC7)); LOC7[0] = procname0; LOC7[1] = filename0; LOC7[2] = rope_180401_2381377266(((NI64) ((*p0).maxframelen))); LOC7[3] = rope_180401_2381377266(((NI64) ((*p0).blocks->data[((NI) 0)].framelen))); result0 = ropecg_534407_839829468(NIM_NIL, ((NimStringDesc*) &T839829468_220), LOC7, 4); } goto LA2; LA4: ; { TY534811 LOC9; memset((void*)LOC9, 0, sizeof(LOC9)); LOC9[0] = procname0; LOC9[1] = filename0; result0 = ropecg_534407_839829468(NIM_NIL, ((NimStringDesc*) &T839829468_221), LOC9, 2); } LA2: ; return result0; } N_NIMCALL(void, appcg_534648_839829468)(Tcproc531021* p0, Tcprocsection531011 s0, NimStringDesc* frmt0, Ropeobj180006** args0, NI args0Len0) { Ropeobj180006** LOC1; Ropeobj180006* LOC2; LOC1 = (Ropeobj180006**)0; LOC1 = s_531179_3723162438(p0, s0); LOC2 = (Ropeobj180006*)0; LOC2 = ropecg_534407_839829468((*p0).module, frmt0, args0, args0Len0); add_180482_2381377266(LOC1, LOC2); } N_NIMCALL(Ropeobj180006*, deinitgcframe_540441_839829468)(Tcproc531021* p0) { Ropeobj180006* result0; result0 = (Ropeobj180006*)0; { TY535289 LOC5; if (!(((NI) 0) < ((NI) ((*p0).gcframeid)))) goto LA3; memset((void*)LOC5, 0, sizeof(LOC5)); result0 = ropecg_534407_839829468((*p0).module, ((NimStringDesc*) &T839829468_225), LOC5, 0); } LA3: ; return result0; } N_NIMCALL(Ropeobj180006*, deinitframe_562150_839829468)(Tcproc531021* p0) { Ropeobj180006* result0; TY535289 LOC1; result0 = (Ropeobj180006*)0; memset((void*)LOC1, 0, sizeof(LOC1)); result0 = ropecg_534407_839829468((*p0).module, ((NimStringDesc*) &T839829468_226), LOC1, 0); return result0; } N_NIMCALL(void, genprocaux_562284_839829468)(Tcgen531027* m0, Tsym294834* prc0) { Tcproc531021* p0; Ropeobj180006* header0; Ropeobj180006* returnstmt0; Tnode294802* LOC51; Ropeobj180006* generatedproc0; p0 = newproc_531206_3723162438(prc0, m0); header0 = genprocheader_537867_839829468(m0, prc0); returnstmt0 = NIM_NIL; { NIM_BOOL LOC3; Tsym294834* res0; LOC3 = (NIM_BOOL)0; LOC3 = !((((*prc0).flags &(1U<<((NU)(((Tsymflag294184) 9))&31U)))!=0)); if (!(LOC3)) goto LA4; LOC3 = !(((*(*prc0).typ).sons->data[((NI) 0)] == NIM_NIL)); LA4: ; if (!LOC3) goto LA5; { NI LOC9; LOC9 = (NI)0; LOC9 = len_295081_850551059((*prc0).ast); if (!(LOC9 <= ((NI) 7))) goto LA10; internalerror_198100_155036129((*prc0).info, ((NimStringDesc*) &T839829468_120)); } LA10: ; res0 = (*(*(*prc0).ast).kindU.S6.sons->data[((NI) 7)]).kindU.S4.sym; { NIM_BOOL LOC14; TY180507 LOC34; LOC14 = (NIM_BOOL)0; LOC14 = isinvalidreturntype_535548_839829468((*(*prc0).typ).sons->data[((NI) 0)]); if (!!(LOC14)) goto LA15; { if (!(((*prc0).flags &(1U<<((NU)(((Tsymflag294184) 12))&31U)))!=0)) goto LA19; (*res0).flags |= ((NU32)1)<<((((Tsymflag294184) 12))%(sizeof(NU32)*8)); } LA19: ; { NIM_BOOL LOC23; NIM_BOOL LOC24; NIM_BOOL LOC26; Tnode294802* val0; Tnode294802* LOC29; Ropeobj180006* decl0; Tloc294816 a0; TY534811 LOC32; LOC23 = (NIM_BOOL)0; LOC24 = (NIM_BOOL)0; LOC24 = (((*prc0).flags &(1U<<((NU)(((Tsymflag294184) 12))&31U)))!=0); if (!(LOC24)) goto LA25; LOC26 = (NIM_BOOL)0; LOC26 = (gcmd_171132_2607990831 == ((Tcommands171076) 2)); if (LOC26) goto LA27; LOC26 = (((*(*(*p0).module).module).flags &(1U<<((NU)(((Tsymflag294184) 27))&31U)))!=0); LA27: ; LOC24 = LOC26; LA25: ; LOC23 = LOC24; if (!(LOC23)) goto LA28; LOC29 = (Tnode294802*)0; LOC29 = getbody_337227_1724185294(prc0); val0 = easyresultasgn_562191_839829468(LOC29); LOC23 = !((val0 == NIM_NIL)); LA28: ; if (!LOC23) goto LA30; decl0 = localvardecl_540532_839829468(p0, res0); memset((void*)(&a0), 0, sizeof(a0)); initlocexprsingleuse_541289_839829468(p0, val0, (&a0)); memset((void*)LOC32, 0, sizeof(LOC32)); LOC32[0] = decl0; LOC32[1] = rdloc_540188_839829468(a0); linefmt_534714_839829468(p0, ((Tcprocsection531011) 2), ((NimStringDesc*) &T839829468_123), LOC32, 2); } goto LA21; LA30: ; { assignlocalvar_540614_839829468(p0, res0); initlocalvar_540398_839829468(p0, res0, NIM_FALSE); } LA21: ; memset((void*)LOC34, 0, sizeof(LOC34)); LOC34[0] = rdloc_540188_839829468((*res0).loc); returnstmt0 = ropecg_534407_839829468(NIM_NIL, ((NimStringDesc*) &T839829468_209), LOC34, 1); } goto LA12; LA15: ; { fillresult_535865_839829468(res0); assignparam_540994_839829468(p0, res0); { Ttype294840* LOC38; LOC38 = (Ttype294840*)0; LOC38 = skiptypes_298099_850551059((*res0).typ, IL64(211106232576256)); if (!((*LOC38).kind == ((Ttypekind294244) 16))) goto LA39; (*res0).loc.s = ((Tstorageloc294812) 0); } LA39: ; } LA12: ; } LA5: ; { NI i_562627_839829468; NI HEX3Atmp_562743_839829468; NI LOC42; NI res_562746_839829468; i_562627_839829468 = (NI)0; HEX3Atmp_562743_839829468 = (NI)0; LOC42 = (NI)0; LOC42 = sonslen_297351_850551059((*(*prc0).typ).n); HEX3Atmp_562743_839829468 = (NI)(LOC42 - ((NI) 1)); res_562746_839829468 = ((NI) 1); { while (1) { if (!(res_562746_839829468 <= HEX3Atmp_562743_839829468)) goto LA44; i_562627_839829468 = res_562746_839829468; { Tsym294834* param0; param0 = (*(*(*(*prc0).typ).n).kindU.S6.sons->data[i_562627_839829468]).kindU.S4.sym; { NIM_BOOL LOC48; LOC48 = (NIM_BOOL)0; LOC48 = iscompiletimeonly_330706_3876443242((*param0).typ); if (!LOC48) goto LA49; goto LA45; } LA49: ; assignparam_540994_839829468(p0, param0); } LA45: ; res_562746_839829468 += ((NI) 1); } LA44: ; } } closuresetup_562158_839829468(p0, prc0); LOC51 = (Tnode294802*)0; LOC51 = getbody_337227_1724185294(prc0); genstmts_541244_839829468(p0, LOC51); generatedproc0 = (Ropeobj180006*)0; { if (!(((*prc0).flags &(1U<<((NU)(((Tsymflag294184) 14))&31U)))!=0)) goto LA54; { if (!((Cc_275413_2528170400[(ccompiler_275431_2528170400)- 1].Field20 &(1U<<((NU)(((Tinfoccprop275004) 6))&7U)))!=0)) goto LA58; header0 = HEX26_180452_2381377266(((NimStringDesc*) &T839829468_213), header0); } LA58: ; } LA54: ; { TY537235 LOC68; Ropeobj180006** LOC69; Ropeobj180006** LOC70; Ropeobj180006** LOC71; if (!(((*prc0).flags &(1U<<((NU)(((Tsymflag294184) 9))&31U)))!=0)) goto LA62; { if (!((Cc_275413_2528170400[(ccompiler_275431_2528170400)- 1].Field20 &(1U<<((NU)(((Tinfoccprop275004) 6))&7U)))!=0)) goto LA66; header0 = HEX26_180452_2381377266(((NimStringDesc*) &T839829468_214), header0); } LA66: ; memset((void*)LOC68, 0, sizeof(LOC68)); LOC68[0] = header0; LOC69 = (Ropeobj180006**)0; LOC69 = s_531179_3723162438(p0, ((Tcprocsection531011) 0)); LOC68[1] = (*LOC69); LOC70 = (Ropeobj180006**)0; LOC70 = s_531179_3723162438(p0, ((Tcprocsection531011) 1)); LOC68[2] = (*LOC70); LOC71 = (Ropeobj180006**)0; LOC71 = s_531179_3723162438(p0, ((Tcprocsection531011) 2)); LOC68[3] = (*LOC71); generatedproc0 = ropecg_534407_839829468(NIM_NIL, ((NimStringDesc*) &T839829468_215), LOC68, 4); } goto LA60; LA62: ; { TY180507 LOC73; Ropeobj180006* LOC74; Ropeobj180006** LOC93; Ropeobj180006** LOC94; Ropeobj180006* LOC101; TY535289 LOC107; Ropeobj180006* LOC108; memset((void*)LOC73, 0, sizeof(LOC73)); LOC73[0] = header0; generatedproc0 = ropecg_534407_839829468(NIM_NIL, ((NimStringDesc*) &T839829468_216), LOC73, 1); LOC74 = (Ropeobj180006*)0; LOC74 = initgcframe_540435_839829468(p0); add_180482_2381377266(&generatedproc0, LOC74); { Ropeobj180006** LOC79; Ropeobj180006* procname0; Ropeobj180006* LOC80; Ropeobj180006* LOC81; if (!(((*prc0).options &(1U<<((NU)(((Toption171009) 15))&31U)))!=0)) goto LA77; LOC79 = (Ropeobj180006**)0; LOC79 = s_531179_3723162438(p0, ((Tcprocsection531011) 0)); add_180482_2381377266(&generatedproc0, (*LOC79)); procname0 = makecstring_193638_155036129((*(*prc0).name).s); LOC80 = (Ropeobj180006*)0; LOC80 = quotedfilename_198818_155036129((*prc0).info); LOC81 = (Ropeobj180006*)0; LOC81 = initframe_562140_839829468(p0, procname0, LOC80); add_180482_2381377266(&generatedproc0, LOC81); } goto LA75; LA77: ; { Ropeobj180006** LOC83; LOC83 = (Ropeobj180006**)0; LOC83 = s_531179_3723162438(p0, ((Tcprocsection531011) 0)); add_180482_2381377266(&generatedproc0, (*LOC83)); } LA75: ; { TY535289 LOC88; if (!(((*prc0).options &(1U<<((NU)(((Toption171009) 19))&31U)))!=0)) goto LA86; memset((void*)LOC88, 0, sizeof(LOC88)); appcg_534648_839829468(p0, ((Tcprocsection531011) 1), ((NimStringDesc*) &T839829468_222), LOC88, 0); } LA86: ; { if (!(*p0).beforeretneeded) goto LA91; add_180487_2381377266(&generatedproc0, ((NimStringDesc*) &T839829468_223)); } LA91: ; LOC93 = (Ropeobj180006**)0; LOC93 = s_531179_3723162438(p0, ((Tcprocsection531011) 1)); add_180482_2381377266(&generatedproc0, (*LOC93)); LOC94 = (Ropeobj180006**)0; LOC94 = s_531179_3723162438(p0, ((Tcprocsection531011) 2)); add_180482_2381377266(&generatedproc0, (*LOC94)); { TY535289 LOC99; Ropeobj180006* LOC100; if (!(*p0).beforeretneeded) goto LA97; memset((void*)LOC99, 0, sizeof(LOC99)); LOC100 = (Ropeobj180006*)0; LOC100 = HEX25_180905_2381377266(((NimStringDesc*) &T839829468_224), LOC99, 0); add_180482_2381377266(&generatedproc0, LOC100); } LA97: ; LOC101 = (Ropeobj180006*)0; LOC101 = deinitgcframe_540441_839829468(p0); add_180482_2381377266(&generatedproc0, LOC101); { Ropeobj180006* LOC106; if (!(((*prc0).options &(1U<<((NU)(((Toption171009) 15))&31U)))!=0)) goto LA104; LOC106 = (Ropeobj180006*)0; LOC106 = deinitframe_562150_839829468(p0); add_180482_2381377266(&generatedproc0, LOC106); } LA104: ; add_180482_2381377266(&generatedproc0, returnstmt0); memset((void*)LOC107, 0, sizeof(LOC107)); LOC108 = (Ropeobj180006*)0; LOC108 = HEX25_180905_2381377266(((NimStringDesc*) &T839829468_227), LOC107, 0); add_180482_2381377266(&generatedproc0, LOC108); } LA60: ; add_180482_2381377266(&(*m0).s[(((Tcfilesection531005) 10))- 0], generatedproc0); } N_NIMCALL(Tcgen531027*, findpendingmodule_534241_839829468)(Tcgen531027* m0, Tsym294834* s0) { Tcgen531027* result0; Tsym294834* ms0; result0 = (Tcgen531027*)0; ms0 = getmodule_301123_2984716966(s0); result0 = gmodules_531170_3723162438->data[(*ms0).position]; return result0; } N_NIMCALL(NIM_BOOL, isgetprocaddr_561442_839829468)(Tlib294820* lib0) { NIM_BOOL result0; Tnode294802* n0; NIM_BOOL LOC1; NIM_BOOL LOC2; result0 = (NIM_BOOL)0; n0 = (*lib0).path; LOC1 = (NIM_BOOL)0; LOC2 = (NIM_BOOL)0; LOC2 = ((*n0).kind == ((Tnodekind294020) 27) || (*n0).kind == ((Tnodekind294020) 29) || (*n0).kind == ((Tnodekind294020) 30) || (*n0).kind == ((Tnodekind294020) 31) || (*n0).kind == ((Tnodekind294020) 26) || (*n0).kind == ((Tnodekind294020) 28) || (*n0).kind == ((Tnodekind294020) 32)); if (!(LOC2)) goto LA3; LOC2 = !(((*n0).typ == NIM_NIL)); LA3: ; LOC1 = LOC2; if (!(LOC1)) goto LA4; LOC1 = ((*(*n0).typ).kind == ((Ttypekind294244) 26) || (*(*n0).typ).kind == ((Ttypekind294244) 25)); LA4: ; result0 = LOC1; return result0; } N_NIMCALL(void, initlocexpr_541283_839829468)(Tcproc531021* p0, Tnode294802* e0, Tloc294816* result0) { initloc_534273_839829468(result0, ((Tlockind294808) 0), (*e0).typ, ((Tstorageloc294812) 0)); expr_541248_839829468(p0, e0, result0); } N_NIMCALL(void, loaddynamiclib_561480_839829468)(Tcgen531027* m0, Tlib294820* lib0) { { Ropeobj180006* tmp0; TY180507 LOC5; if (!!((*lib0).generated)) goto LA3; (*lib0).generated = NIM_TRUE; tmp0 = gettempname_535596_839829468(m0); asgnRefNoCycle((void**) (&(*lib0).name), tmp0); memset((void*)LOC5, 0, sizeof(LOC5)); LOC5[0] = tmp0; addf_181205_2381377266(&(*m0).s[(((Tcfilesection531005) 9))- 0], ((NimStringDesc*) &T839829468_228), LOC5, 1); { TY136002* s0; Ropeobj180006* loadlib0; TY534811 LOC18; if (!((*(*lib0).path).kind >= ((Tnodekind294020) 20) && (*(*lib0).path).kind <= ((Tnodekind294020) 22))) goto LA8; s0 = (TY136002*) newSeq((&NTI136002), 0); libcandidates_172605_2607990831((*(*lib0).path).kindU.S3.strval, (&s0)); rawmessage_196612_155036129(((Tmsgkind193002) 286), (*(*lib0).path).kindU.S3.strval); loadlib0 = NIM_NIL; { NI i_561847_839829468; NI HEX3Atmp_561902_839829468; NI res_561905_839829468; i_561847_839829468 = (NI)0; HEX3Atmp_561902_839829468 = (NI)0; HEX3Atmp_561902_839829468 = (s0 ? (s0->Sup.len-1) : -1); res_561905_839829468 = ((NI) 0); { while (1) { TY534811 LOC17; if (!(res_561905_839829468 <= HEX3Atmp_561902_839829468)) goto LA12; i_561847_839829468 = res_561905_839829468; (*m0).labels += ((NI) 1); { if (!(((NI) 0) < i_561847_839829468)) goto LA15; add_180487_2381377266(&loadlib0, ((NimStringDesc*) &T839829468_229)); } LA15: ; memset((void*)LOC17, 0, sizeof(LOC17)); LOC17[0] = tmp0; LOC17[1] = getstrlit_551468_839829468(m0, s0->data[i_561847_839829468]); appcg_534632_839829468(m0, &loadlib0, ((NimStringDesc*) &T839829468_230), LOC17, 2); res_561905_839829468 += ((NI) 1); } LA12: ; } } memset((void*)LOC18, 0, sizeof(LOC18)); LOC18[0] = loadlib0; LOC18[1] = getstrlit_551468_839829468(m0, (*(*lib0).path).kindU.S3.strval); appcg_534632_839829468(m0, &(*m0).s[(((Tcfilesection531005) 16))- 0], ((NimStringDesc*) &T839829468_231), LOC18, 2); } goto LA6; LA8: ; { Tcproc531021* p0; Tloc294816 dest0; Ropeobj180006** LOC20; Ropeobj180006** LOC21; Ropeobj180006** LOC22; TY534811 LOC23; p0 = newproc_531206_3723162438(NIM_NIL, m0); (*p0).options = ((*p0).options & ~ 163840); memset((void*)(&dest0), 0, sizeof(dest0)); initlocexpr_541283_839829468(p0, (*lib0).path, (&dest0)); LOC20 = (Ropeobj180006**)0; LOC20 = s_531179_3723162438(p0, ((Tcprocsection531011) 0)); add_180482_2381377266(&(*m0).s[(((Tcfilesection531005) 9))- 0], (*LOC20)); LOC21 = (Ropeobj180006**)0; LOC21 = s_531179_3723162438(p0, ((Tcprocsection531011) 1)); add_180482_2381377266(&(*m0).s[(((Tcfilesection531005) 16))- 0], (*LOC21)); LOC22 = (Ropeobj180006**)0; LOC22 = s_531179_3723162438(p0, ((Tcprocsection531011) 2)); add_180482_2381377266(&(*m0).s[(((Tcfilesection531005) 16))- 0], (*LOC22)); memset((void*)LOC23, 0, sizeof(LOC23)); LOC23[0] = tmp0; LOC23[1] = rdloc_540188_839829468(dest0); appcg_534632_839829468(m0, &(*m0).s[(((Tcfilesection531005) 16))- 0], ((NimStringDesc*) &T839829468_232), LOC23, 2); } LA6: ; } LA3: ; { if (!((*lib0).name == NIM_NIL)) goto LA26; internalerror_198113_155036129(((NimStringDesc*) &T839829468_233)); } LA26: ; } N_NIMCALL(Ropeobj180006*, mangledynlibproc_540816_839829468)(Tsym294834* sym0) { Ropeobj180006* result0; result0 = (Ropeobj180006*)0; { if (!(((*sym0).flags &(1U<<((NU)(((Tsymflag294184) 16))&31U)))!=0)) goto LA3; result0 = rope_180277_2381377266((*(*sym0).name).s); } goto LA1; LA3: ; { TY180507 LOC6; memset((void*)LOC6, 0, sizeof(LOC6)); LOC6[0] = rope_180401_2381377266(((NI64) ((*sym0).Sup.id))); result0 = HEX25_180905_2381377266(((NimStringDesc*) &T839829468_234), LOC6, 1); } LA1: ; return result0; } N_NIMCALL(void, symindynamiclib_561929_839829468)(Tcgen531027* m0, Tsym294834* sym0) { Tlib294820* lib0; NIM_BOOL iscall0; Ropeobj180006* extname0; Ropeobj180006* tmp0; TY534811 LOC43; lib0 = (*sym0).annex; iscall0 = isgetprocaddr_561442_839829468(lib0); extname0 = (*sym0).loc.r; { if (!!(iscall0)) goto LA3; loaddynamiclib_561480_839829468(m0, lib0); } LA3: ; tmp0 = mangledynlibproc_540816_839829468(sym0); asgnRefNoCycle((void**) (&(*sym0).loc.r), tmp0); asgnRefNoCycle((void**) (&(*(*sym0).typ).sym), NIM_NIL); (*m0).labels += ((NI) 2); { Tnode294802* n0; Tloc294816 a0; Tnode294802* LOC9; Ropeobj180006* params0; Ropeobj180006* LOC10; Ropeobj180006* load0; TY537235 LOC17; NimStringDesc* LOC18; Tnode294802* last0; NimStringDesc* idx0; if (!iscall0) goto LA7; n0 = (*lib0).path; memset((void*)(&a0), 0, sizeof(a0)); LOC9 = (Tnode294802*)0; LOC9 = HEX5BHEX5D_295238_850551059(n0, ((NI) 0)); initlocexpr_541283_839829468((*m0).initproc, LOC9, (&a0)); LOC10 = (Ropeobj180006*)0; LOC10 = rdloc_540188_839829468(a0); params0 = HEX26_180447_2381377266(LOC10, ((NimStringDesc*) &T839829468_118)); { NI i_561964_839829468; NI HEX3Atmp_562025_839829468; NI LOC12; NI res_562028_839829468; i_561964_839829468 = (NI)0; HEX3Atmp_562025_839829468 = (NI)0; LOC12 = (NI)0; LOC12 = len_295081_850551059(n0); HEX3Atmp_562025_839829468 = (NI)(LOC12 - ((NI) 2)); res_562028_839829468 = ((NI) 1); { while (1) { Tnode294802* LOC15; Ropeobj180006* LOC16; if (!(res_562028_839829468 <= HEX3Atmp_562025_839829468)) goto LA14; i_561964_839829468 = res_562028_839829468; LOC15 = (Tnode294802*)0; LOC15 = HEX5BHEX5D_295238_850551059(n0, i_561964_839829468); initlocexpr_541283_839829468((*m0).initproc, LOC15, (&a0)); LOC16 = (Ropeobj180006*)0; LOC16 = rdloc_540188_839829468(a0); add_180482_2381377266(&params0, LOC16); add_180487_2381377266(&params0, ((NimStringDesc*) &T839829468_110)); res_562028_839829468 += ((NI) 1); } LA14: ; } } memset((void*)LOC17, 0, sizeof(LOC17)); LOC17[0] = tmp0; LOC17[1] = gettypedesc_537671_839829468(m0, (*sym0).typ); LOC17[2] = params0; LOC18 = (NimStringDesc*)0; LOC18 = HEX24_180856_2381377266(extname0); LOC17[3] = makecstring_193638_155036129(LOC18); load0 = HEX25_180905_2381377266(((NimStringDesc*) &T839829468_235), LOC17, 4); last0 = lastson_297364_850551059(n0); { if (!((*last0).kind == ((Tnodekind294020) 58))) goto LA21; last0 = (*last0).kindU.S6.sons->data[((NI) 1)]; } LA21: ; { NimStringDesc* LOC27; if (!!(((*last0).kind == ((Tnodekind294020) 20)))) goto LA25; LOC27 = (NimStringDesc*)0; LOC27 = HEX24_198185_1689653243(T839829468_236); internalerror_198113_155036129(LOC27); } LA25: ; idx0 = (*last0).kindU.S3.strval; { Ropeobj180006** LOC32; if (!((idx0 ? idx0->Sup.len : 0) == ((NI) 0))) goto LA30; LOC32 = (Ropeobj180006**)0; LOC32 = s_531179_3723162438((*m0).initproc, ((Tcprocsection531011) 2)); add_180482_2381377266(LOC32, load0); } goto LA28; LA30: ; { NIM_BOOL LOC34; LOC34 = (NIM_BOOL)0; LOC34 = ((idx0 ? idx0->Sup.len : 0) == ((NI) 1)); if (!(LOC34)) goto LA35; LOC34 = (((NU8)(idx0->data[((NI) 0)])) >= ((NU8)(48)) && ((NU8)(idx0->data[((NI) 0)])) <= ((NU8)(57))); LA35: ; if (!LOC34) goto LA36; add_180482_2381377266(&(*m0).extensionloaders[(((NU8)(idx0->data[((NI) 0)])))- 48], load0); } goto LA28; LA36: ; { NimStringDesc* LOC39; LOC39 = (NimStringDesc*)0; LOC39 = rawNewString(idx0->Sup.len + 13); appendString(LOC39, ((NimStringDesc*) &T839829468_237)); appendString(LOC39, idx0); internalerror_198100_155036129((*sym0).info, LOC39); } LA28: ; } goto LA5; LA7: ; { TY537235 LOC41; NimStringDesc* LOC42; memset((void*)LOC41, 0, sizeof(LOC41)); LOC41[0] = tmp0; LOC41[1] = gettypedesc_537671_839829468(m0, (*sym0).typ); LOC41[2] = (*lib0).name; LOC42 = (NimStringDesc*)0; LOC42 = HEX24_180856_2381377266(extname0); LOC41[3] = makecstring_193638_155036129(LOC42); appcg_534632_839829468(m0, &(*m0).s[(((Tcfilesection531005) 16))- 0], ((NimStringDesc*) &T839829468_238), LOC41, 4); } LA5: ; memset((void*)LOC43, 0, sizeof(LOC43)); LOC43[0] = (*sym0).loc.r; LOC43[1] = gettypedesc_537671_839829468(m0, (*sym0).loc.t); addf_181205_2381377266(&(*m0).s[(((Tcfilesection531005) 9))- 0], ((NimStringDesc*) &T839829468_239), LOC43, 2); } N_NIMCALL(void, symindynamiclibpartial_562071_839829468)(Tcgen531027* m0, Tsym294834* sym0) { asgnRefNoCycle((void**) (&(*sym0).loc.r), mangledynlibproc_540816_839829468(sym0)); asgnRefNoCycle((void**) (&(*(*sym0).typ).sym), NIM_NIL); } N_NIMCALL(void, genprocnoforward_562906_839829468)(Tcgen531027* m0, Tsym294834* prc0) { { fillprocloc_541201_839829468(prc0); useheader_534369_839829468(m0, prc0); { Ropeobj180006* LOC5; if (!(((*prc0).loc.flags &(1U<<((NU)(((Tlocflag294810) 7))&15U)))!=0)) goto LA3; LOC5 = (Ropeobj180006*)0; LOC5 = cgsym_534403_839829468(m0, (*(*prc0).name).s); goto BeforeRet; } LA3: ; genprocprototype_541254_839829468(m0, prc0); { if (!(((*prc0).loc.flags &(1U<<((NU)(((Tlocflag294810) 3))&15U)))!=0)) goto LA8; } goto LA6; LA8: ; { if (!((*(*prc0).typ).callconv == ((Tcallingconvention294002) 5))) goto LA11; { NIM_BOOL LOC15; LOC15 = (NIM_BOOL)0; LOC15 = containsorincl_270862_2627731572((&(*m0).declaredthings), (*prc0).Sup.id); if (!!(LOC15)) goto LA16; genprocaux_562284_839829468(m0, prc0); } LA16: ; } goto LA6; LA11: ; { Tcgen531027* q0; if (!(((*prc0).loc.flags &(1U<<((NU)(((Tlocflag294810) 4))&15U)))!=0)) goto LA19; q0 = findpendingmodule_534241_839829468(m0, prc0); { NIM_BOOL LOC23; NIM_BOOL LOC25; LOC23 = (NIM_BOOL)0; LOC23 = !((q0 == NIM_NIL)); if (!(LOC23)) goto LA24; LOC25 = (NIM_BOOL)0; LOC25 = containsorincl_270862_2627731572((&(*q0).declaredthings), (*prc0).Sup.id); LOC23 = !(LOC25); LA24: ; if (!LOC23) goto LA26; symindynamiclib_561929_839829468(q0, prc0); } goto LA21; LA26: ; { symindynamiclibpartial_562071_839829468(m0, prc0); } LA21: ; } goto LA6; LA19: ; { Tcgen531027* q0; if (!!((((*prc0).flags &(1U<<((NU)(((Tsymflag294184) 5))&31U)))!=0))) goto LA30; q0 = findpendingmodule_534241_839829468(m0, prc0); { NIM_BOOL LOC34; NIM_BOOL LOC36; LOC34 = (NIM_BOOL)0; LOC34 = !((q0 == NIM_NIL)); if (!(LOC34)) goto LA35; LOC36 = (NIM_BOOL)0; LOC36 = containsorincl_270862_2627731572((&(*q0).declaredthings), (*prc0).Sup.id); LOC34 = !(LOC36); LA35: ; if (!LOC34) goto LA37; genprocaux_562284_839829468(q0, prc0); } LA37: ; } goto LA6; LA30: ; LA6: ; }BeforeRet: ; } N_NIMCALL(void, genproc_534951_839829468)(Tcgen531027* m0, Tsym294834* prc0) { { { NIM_BOOL LOC3; NIM_BOOL LOC5; LOC3 = (NIM_BOOL)0; LOC3 = (((*prc0).flags &(1U<<((NU)(((Tsymflag294184) 26))&31U)))!=0); if (LOC3) goto LA4; LOC5 = (NIM_BOOL)0; LOC5 = isactivated_563431_839829468(prc0); LOC3 = !(LOC5); LA4: ; if (!LOC3) goto LA6; goto BeforeRet; } LA6: ; fillprocloc_541201_839829468(prc0); { if (!(((*prc0).flags &(1U<<((NU)(((Tsymflag294184) 4))&31U)))!=0)) goto LA10; addforwardedproc_534203_839829468(m0, prc0); } goto LA8; LA10: ; { genprocnoforward_562906_839829468(m0, prc0); { NIM_BOOL LOC15; NIM_BOOL LOC16; LOC15 = (NIM_BOOL)0; LOC16 = (NIM_BOOL)0; LOC16 = ((65600 & (*prc0).flags) == 64); if (!(LOC16)) goto LA17; LOC16 = !((generatedheader_534201_839829468 == NIM_NIL)); LA17: ; LOC15 = LOC16; if (!(LOC15)) goto LA18; LOC15 = !((((*prc0).loc.flags &(1U<<((NU)(((Tlocflag294810) 3))&15U)))!=0)); LA18: ; if (!LOC15) goto LA19; genprocprototype_541254_839829468(generatedheader_534201_839829468, prc0); { if (!((*(*prc0).typ).callconv == ((Tcallingconvention294002) 5))) goto LA23; { NIM_BOOL LOC27; LOC27 = (NIM_BOOL)0; LOC27 = containsorincl_270862_2627731572((&(*generatedheader_534201_839829468).declaredthings), (*prc0).Sup.id); if (!!(LOC27)) goto LA28; genprocaux_562284_839829468(generatedheader_534201_839829468, prc0); } LA28: ; } LA23: ; } LA19: ; } LA8: ; }BeforeRet: ; } static N_INLINE(NIM_BOOL, emulatedthreadvars_534949_839829468)(void) { NIM_BOOL result0; result0 = (NIM_BOOL)0; result0 = ((71303168 & ~ gglobaloptions_171130_2607990831)==0); return result0; } N_NIMCALL(void, declarethreadvar_540676_839829468)(Tcgen531027* m0, Tsym294834* s0, NIM_BOOL isextern0) { { NIM_BOOL LOC3; LOC3 = (NIM_BOOL)0; LOC3 = emulatedthreadvars_534949_839829468(); if (!LOC3) goto LA4; { NIM_BOOL LOC8; TY534811 LOC11; LOC8 = (NIM_BOOL)0; LOC8 = containsorincl_270862_2627731572((&nimtvdeclared_540675_839829468), (*s0).Sup.id); if (!!(LOC8)) goto LA9; nimtvdeps_540674_839829468 = (Ttypeseq294836*) incrSeqV2(&(nimtvdeps_540674_839829468)->Sup, sizeof(Ttype294840*)); asgnRefNoCycle((void**) (&nimtvdeps_540674_839829468->data[nimtvdeps_540674_839829468->Sup.len]), (*s0).loc.t); ++nimtvdeps_540674_839829468->Sup.len; memset((void*)LOC11, 0, sizeof(LOC11)); LOC11[0] = gettypedesc_537671_839829468(m0, (*s0).loc.t); LOC11[1] = (*s0).loc.r; addf_181205_2381377266(&nimtv_540656_839829468, ((NimStringDesc*) &T839829468_54), LOC11, 2); } LA9: ; } goto LA1; LA4: ; { Ropeobj180006* LOC21; TY180507 LOC22; { if (!isextern0) goto LA15; add_180487_2381377266(&(*m0).s[(((Tcfilesection531005) 9))- 0], ((NimStringDesc*) &T839829468_240)); } LA15: ; { if (!((gglobaloptions_171130_2607990831 &((NU64)1<<((NU)(((Tglobaloption171013) 22))&63U)))!=0)) goto LA19; add_180487_2381377266(&(*m0).s[(((Tcfilesection531005) 9))- 0], ((NimStringDesc*) &T839829468_241)); } LA19: ; LOC21 = (Ropeobj180006*)0; LOC21 = gettypedesc_537671_839829468(m0, (*s0).loc.t); add_180482_2381377266(&(*m0).s[(((Tcfilesection531005) 9))- 0], LOC21); memset((void*)LOC22, 0, sizeof(LOC22)); LOC22[0] = (*s0).loc.r; addf_181205_2381377266(&(*m0).s[(((Tcfilesection531005) 9))- 0], ((NimStringDesc*) &T839829468_242), LOC22, 1); } LA1: ; } N_NIMCALL(void, genvarprototypeaux_546254_839829468)(Tcgen531027* m0, Tsym294834* sym0) { Ropeobj180006* LOC1; { useheader_534369_839829468(m0, sym0); LOC1 = (Ropeobj180006*)0; LOC1 = manglename_535205_839829468(sym0); fillloc_534282_839829468((&(*sym0).loc), ((Tlockind294808) 3), (*sym0).typ, LOC1, ((Tstorageloc294812) 3)); { NIM_BOOL LOC4; LOC4 = (NIM_BOOL)0; LOC4 = (((*sym0).loc.flags &(1U<<((NU)(((Tlocflag294810) 3))&15U)))!=0); if (LOC4) goto LA5; LOC4 = containsorincl_270862_2627731572((&(*m0).declaredthings), (*sym0).Sup.id); LA5: ; if (!LOC4) goto LA6; goto BeforeRet; } LA6: ; { if (!!(((*(*sym0).owner).Sup.id == (*(*m0).module).Sup.id))) goto LA10; { if (!(((*sym0).flags &(1U<<((NU)(((Tsymflag294184) 22))&31U)))!=0)) goto LA14; declarethreadvar_540676_839829468(m0, sym0, NIM_TRUE); } goto LA12; LA14: ; { Ropeobj180006* LOC17; TY180507 LOC30; add_180487_2381377266(&(*m0).s[(((Tcfilesection531005) 9))- 0], ((NimStringDesc*) &T839829468_240)); LOC17 = (Ropeobj180006*)0; LOC17 = gettypedesc_537671_839829468(m0, (*sym0).loc.t); add_180482_2381377266(&(*m0).s[(((Tcfilesection531005) 9))- 0], LOC17); { if (!(((*sym0).loc.flags &(1U<<((NU)(((Tlocflag294810) 4))&15U)))!=0)) goto LA20; add_180487_2381377266(&(*m0).s[(((Tcfilesection531005) 9))- 0], ((NimStringDesc*) &T839829468_53)); } LA20: ; { if (!(((*sym0).flags &(1U<<((NU)(((Tsymflag294184) 8))&31U)))!=0)) goto LA24; add_180487_2381377266(&(*m0).s[(((Tcfilesection531005) 9))- 0], ((NimStringDesc*) &T839829468_121)); } LA24: ; { if (!(((*sym0).flags &(1U<<((NU)(((Tsymflag294184) 7))&31U)))!=0)) goto LA28; add_180487_2381377266(&(*m0).s[(((Tcfilesection531005) 9))- 0], ((NimStringDesc*) &T839829468_122)); } LA28: ; memset((void*)LOC30, 0, sizeof(LOC30)); LOC30[0] = (*sym0).loc.r; addf_181205_2381377266(&(*m0).s[(((Tcfilesection531005) 9))- 0], ((NimStringDesc*) &T839829468_242), LOC30, 1); } LA12: ; } LA10: ; }BeforeRet: ; } N_NIMCALL(void, genvarprototype_541236_839829468)(Tcgen531027* m0, Tsym294834* sym0) { genvarprototypeaux_546254_839829468(m0, sym0); } N_NIMCALL(Ropeobj180006*, cgsym_534403_839829468)(Tcgen531027* m0, NimStringDesc* name0) { Ropeobj180006* result0; Tsym294834* sym0; result0 = (Ropeobj180006*)0; sym0 = getcompilerproc_340746_3937434831(name0); { if (!!((sym0 == NIM_NIL))) goto LA3; switch ((*sym0).kind) { case ((Tsymkind294435) 12): case ((Tsymkind294435) 13): case ((Tsymkind294435) 15): case ((Tsymkind294435) 14): { genproc_534951_839829468(m0, sym0); } break; case ((Tsymkind294435) 8): case ((Tsymkind294435) 11): case ((Tsymkind294435) 9): { genvarprototype_541236_839829468(m0, sym0); } break; case ((Tsymkind294435) 7): { Ropeobj180006* LOC8; LOC8 = (Ropeobj180006*)0; LOC8 = gettypedesc_537671_839829468(m0, (*sym0).typ); } break; default: { NimStringDesc* LOC10; LOC10 = (NimStringDesc*)0; LOC10 = rawNewString(name0->Sup.len + reprEnum((NI)(*sym0).kind, (&NTI294435))->Sup.len + 9); appendString(LOC10, ((NimStringDesc*) &T839829468_243)); appendString(LOC10, name0); appendString(LOC10, ((NimStringDesc*) &T839829468_244)); appendString(LOC10, reprEnum((NI)(*sym0).kind, (&NTI294435))); internalerror_198113_155036129(LOC10); } break; } } goto LA1; LA3: ; { rawmessage_196612_155036129(((Tmsgkind193002) 68), name0); } LA1: ; result0 = (*sym0).loc.r; return result0; } N_NIMCALL(Ropeobj180006*, ropecg_534407_839829468)(Tcgen531027* m0, NimStringDesc* frmt0, Ropeobj180006** args0, NI args0Len0) { Ropeobj180006* result0; NI i0; NI length0; NI num0; result0 = (Ropeobj180006*)0; i0 = ((NI) 0); length0 = (frmt0 ? frmt0->Sup.len : 0); result0 = NIM_NIL; num0 = ((NI) 0); { while (1) { NI start0; if (!(i0 < length0)) goto LA2; { if (!((NU8)(frmt0->data[i0]) == (NU8)(36))) goto LA5; i0 += ((NI) 1); switch (((NU8)(frmt0->data[i0]))) { case 36: { add_180487_2381377266(&result0, ((NimStringDesc*) &T839829468_19)); i0 += ((NI) 1); } break; case 35: { i0 += ((NI) 1); add_180482_2381377266(&result0, args0[num0]); num0 += ((NI) 1); } break; case 48 ... 57: { NI j0; j0 = ((NI) 0); { while (1) { j0 = (NI)((NI)((NI)(j0 * ((NI) 10)) + ((NI) (((NU8)(frmt0->data[i0]))))) - ((NI) 48)); i0 += ((NI) 1); { NIM_BOOL LOC14; LOC14 = (NIM_BOOL)0; LOC14 = (length0 <= i0); if (LOC14) goto LA15; LOC14 = !((((NU8)(frmt0->data[i0])) >= ((NU8)(48)) && ((NU8)(frmt0->data[i0])) <= ((NU8)(57)))); LA15: ; if (!LOC14) goto LA16; goto LA10; } LA16: ; } } LA10: ; num0 = j0; { NimStringDesc* LOC22; NimStringDesc* LOC23; if (!((NI)((args0Len0-1) + ((NI) 1)) < j0)) goto LA20; LOC22 = (NimStringDesc*)0; LOC23 = (NimStringDesc*)0; LOC23 = nimIntToStr(j0); LOC22 = rawNewString(LOC23->Sup.len + 30); appendString(LOC22, ((NimStringDesc*) &T839829468_20)); appendString(LOC22, LOC23); internalerror_198113_155036129(LOC22); } LA20: ; add_180482_2381377266(&result0, args0[(NI)(j0 - ((NI) 1))]); } break; case 110: { { if (!!(((goptions_171128_2607990831 &(1U<<((NU)(((Toption171009) 10))&31U)))!=0))) goto LA27; add_180482_2381377266(&result0, rnl_180903_2381377266); } LA27: ; i0 += ((NI) 1); } break; case 78: { add_180482_2381377266(&result0, rnl_180903_2381377266); i0 += ((NI) 1); } break; default: { NimStringDesc* LOC31; LOC31 = (NimStringDesc*)0; LOC31 = rawNewString(31); appendString(LOC31, ((NimStringDesc*) &T839829468_20)); appendChar(LOC31, frmt0->data[i0]); internalerror_198113_155036129(LOC31); } break; } } goto LA3; LA5: ; { NIM_BOOL LOC33; NI j0; NimStringDesc* ident0; Ropeobj180006* LOC39; LOC33 = (NIM_BOOL)0; LOC33 = ((NU8)(frmt0->data[i0]) == (NU8)(35)); if (!(LOC33)) goto LA34; LOC33 = (((NU8)(frmt0->data[(NI)(i0 + ((NI) 1))])) >= ((NU8)(97)) && ((NU8)(frmt0->data[(NI)(i0 + ((NI) 1))])) <= ((NU8)(122)) || ((NU8)(frmt0->data[(NI)(i0 + ((NI) 1))])) >= ((NU8)(65)) && ((NU8)(frmt0->data[(NI)(i0 + ((NI) 1))])) <= ((NU8)(90)) || ((NU8)(frmt0->data[(NI)(i0 + ((NI) 1))])) == ((NU8)(95))); LA34: ; if (!LOC33) goto LA35; i0 += ((NI) 1); j0 = i0; { while (1) { if (!(((NU8)(frmt0->data[j0])) >= ((NU8)(97)) && ((NU8)(frmt0->data[j0])) <= ((NU8)(122)) || ((NU8)(frmt0->data[j0])) >= ((NU8)(65)) && ((NU8)(frmt0->data[j0])) <= ((NU8)(90)) || ((NU8)(frmt0->data[j0])) >= ((NU8)(48)) && ((NU8)(frmt0->data[j0])) <= ((NU8)(57)) || ((NU8)(frmt0->data[j0])) == ((NU8)(95)))) goto LA38; j0 += ((NI) 1); } LA38: ; } ident0 = copyStrLast(frmt0, i0, (NI)(j0 - ((NI) 1))); i0 = j0; LOC39 = (Ropeobj180006*)0; LOC39 = cgsym_534403_839829468(m0, ident0); add_180482_2381377266(&result0, LOC39); } goto LA3; LA35: ; { NIM_BOOL LOC41; NI j0; NimStringDesc* LOC47; Ropeobj180006* LOC48; LOC41 = (NIM_BOOL)0; LOC41 = ((NU8)(frmt0->data[i0]) == (NU8)(35)); if (!(LOC41)) goto LA42; LOC41 = ((NU8)(frmt0->data[(NI)(i0 + ((NI) 1))]) == (NU8)(36)); LA42: ; if (!LOC41) goto LA43; i0 += ((NI) 2); j0 = ((NI) 0); { while (1) { if (!(((NU8)(frmt0->data[i0])) >= ((NU8)(48)) && ((NU8)(frmt0->data[i0])) <= ((NU8)(57)))) goto LA46; j0 = (NI)((NI)((NI)(j0 * ((NI) 10)) + ((NI) (((NU8)(frmt0->data[i0]))))) - ((NI) 48)); i0 += ((NI) 1); } LA46: ; } LOC47 = (NimStringDesc*)0; LOC47 = HEX24_180856_2381377266(args0[(NI)(j0 - ((NI) 1))]); LOC48 = (Ropeobj180006*)0; LOC48 = cgsym_534403_839829468(m0, LOC47); add_180482_2381377266(&result0, LOC48); } goto LA3; LA43: ; LA3: ; start0 = i0; { while (1) { if (!(i0 < length0)) goto LA50; { NIM_BOOL LOC53; LOC53 = (NIM_BOOL)0; LOC53 = !(((NU8)(frmt0->data[i0]) == (NU8)(36))); if (!(LOC53)) goto LA54; LOC53 = !(((NU8)(frmt0->data[i0]) == (NU8)(35))); LA54: ; if (!LOC53) goto LA55; i0 += ((NI) 1); } goto LA51; LA55: ; { goto LA49; } LA51: ; } LA50: ; } LA49: ; { NimStringDesc* LOC62; if (!(start0 <= (NI)(i0 - ((NI) 1)))) goto LA60; LOC62 = (NimStringDesc*)0; LOC62 = copyStrLast(frmt0, start0, (NI)(i0 - ((NI) 1))); add_180487_2381377266(&result0, LOC62); } LA60: ; } LA2: ; } return result0; } static N_INLINE(NIM_BOOL, crossescppboundary_562754_839829468)(Tcgen531027* m0, Tsym294834* sym0) { NIM_BOOL result0; NIM_BOOL LOC1; NIM_BOOL LOC2; Tsym294834* LOC4; result0 = (NIM_BOOL)0; LOC1 = (NIM_BOOL)0; LOC2 = (NIM_BOOL)0; LOC2 = (((*(*m0).module).flags &(1U<<((NU)(((Tsymflag294184) 27))&31U)))!=0); if (!(LOC2)) goto LA3; LOC4 = (Tsym294834*)0; LOC4 = getmodule_301123_2984716966(sym0); LOC2 = !((((*LOC4).flags &(1U<<((NU)(((Tsymflag294184) 27))&31U)))!=0)); LA3: ; LOC1 = LOC2; if (!(LOC1)) goto LA5; LOC1 = !((gcmd_171132_2607990831 == ((Tcommands171076) 2))); LA5: ; result0 = LOC1; return result0; } N_NIMCALL(void, genprocprototype_541254_839829468)(Tcgen531027* m0, Tsym294834* sym0) { { useheader_534369_839829468(m0, sym0); { if (!(((*sym0).loc.flags &(1U<<((NU)(((Tlocflag294810) 3))&15U)))!=0)) goto LA3; goto BeforeRet; } LA3: ; { if (!(((*sym0).loc.flags &(1U<<((NU)(((Tlocflag294810) 4))&15U)))!=0)) goto LA7; { NIM_BOOL LOC11; Tsym294834* LOC12; NIM_BOOL LOC14; TY534811 LOC17; Ropeobj180006* LOC18; LOC11 = (NIM_BOOL)0; LOC12 = (Tsym294834*)0; LOC12 = getmodule_301123_2984716966(sym0); LOC11 = !(((*LOC12).Sup.id == (*(*m0).module).Sup.id)); if (!(LOC11)) goto LA13; LOC14 = (NIM_BOOL)0; LOC14 = containsorincl_270862_2627731572((&(*m0).declaredthings), (*sym0).Sup.id); LOC11 = !(LOC14); LA13: ; if (!LOC11) goto LA15; memset((void*)LOC17, 0, sizeof(LOC17)); LOC17[0] = gettypedesc_537671_839829468(m0, (*sym0).loc.t); LOC17[1] = mangledynlibproc_540816_839829468(sym0); LOC18 = (Ropeobj180006*)0; LOC18 = ropecg_534407_839829468(NIM_NIL, ((NimStringDesc*) &T839829468_245), LOC17, 2); add_180482_2381377266(&(*m0).s[(((Tcfilesection531005) 9))- 0], LOC18); } LA15: ; } goto LA5; LA7: ; { NIM_BOOL LOC20; Ropeobj180006* header0; TY180507 LOC47; Ropeobj180006* LOC48; LOC20 = (NIM_BOOL)0; LOC20 = containsorincl_270862_2627731572((&(*m0).declaredprotos), (*sym0).Sup.id); if (!!(LOC20)) goto LA21; header0 = genprocheader_537867_839829468(m0, sym0); { NIM_BOOL LOC25; LOC25 = (NIM_BOOL)0; LOC25 = (((*sym0).flags &(1U<<((NU)(((Tsymflag294184) 14))&31U)))!=0); if (!(LOC25)) goto LA26; LOC25 = ((Cc_275413_2528170400[(ccompiler_275431_2528170400)- 1].Field20 &(1U<<((NU)(((Tinfoccprop275004) 6))&7U)))!=0); LA26: ; if (!LOC25) goto LA27; header0 = HEX26_180452_2381377266(((NimStringDesc*) &T839829468_213), header0); } LA27: ; { NIM_BOOL LOC31; LOC31 = (NIM_BOOL)0; LOC31 = !(((*(*sym0).typ).callconv == ((Tcallingconvention294002) 5))); if (!(LOC31)) goto LA32; LOC31 = crossescppboundary_562754_839829468(m0, sym0); LA32: ; if (!LOC31) goto LA33; header0 = HEX26_180452_2381377266(((NimStringDesc*) &T839829468_246), header0); } LA33: ; { NIM_BOOL LOC37; LOC37 = (NIM_BOOL)0; LOC37 = (((*sym0).flags &(1U<<((NU)(((Tsymflag294184) 9))&31U)))!=0); if (!(LOC37)) goto LA38; LOC37 = ((Cc_275413_2528170400[(ccompiler_275431_2528170400)- 1].Field20 &(1U<<((NU)(((Tinfoccprop275004) 7))&7U)))!=0); LA38: ; if (!LOC37) goto LA39; add_180487_2381377266(&header0, ((NimStringDesc*) &T839829468_247)); } LA39: ; { NIM_BOOL LOC43; LOC43 = (NIM_BOOL)0; LOC43 = (((*sym0).flags &(1U<<((NU)(((Tsymflag294184) 14))&31U)))!=0); if (!(LOC43)) goto LA44; LOC43 = ((Cc_275413_2528170400[(ccompiler_275431_2528170400)- 1].Field20 &(1U<<((NU)(((Tinfoccprop275004) 7))&7U)))!=0); LA44: ; if (!LOC43) goto LA45; add_180487_2381377266(&header0, ((NimStringDesc*) &T839829468_248)); } LA45: ; memset((void*)LOC47, 0, sizeof(LOC47)); LOC47[0] = header0; LOC48 = (Ropeobj180006*)0; LOC48 = ropecg_534407_839829468(NIM_NIL, ((NimStringDesc*) &T839829468_191), LOC47, 1); add_180482_2381377266(&(*m0).s[(((Tcfilesection531005) 7))- 0], LOC48); } goto LA5; LA21: ; LA5: ; }BeforeRet: ; } static N_INLINE(NIM_BOOL, usesnativegc_171177_2607990831)(void) { NIM_BOOL result0; result0 = (NIM_BOOL)0; result0 = (((Tgcmode171080) 5) <= gselectedgc_171133_2607990831); return result0; } N_NIMCALL(void, genrefassign_540311_839829468)(Tcproc531021* p0, Tloc294816 dest0, Tloc294816 src0, Tassignmentflag540302Set flags0) { { NIM_BOOL LOC3; NIM_BOOL LOC5; TY534811 LOC8; LOC3 = (NIM_BOOL)0; LOC3 = (dest0.s == ((Tstorageloc294812) 2)); if (LOC3) goto LA4; LOC5 = (NIM_BOOL)0; LOC5 = usesnativegc_171177_2607990831(); LOC3 = !(LOC5); LA4: ; if (!LOC3) goto LA6; memset((void*)LOC8, 0, sizeof(LOC8)); LOC8[0] = rdloc_540188_839829468(dest0); LOC8[1] = rdloc_540188_839829468(src0); linefmt_534714_839829468(p0, ((Tcprocsection531011) 2), ((NimStringDesc*) &T839829468_123), LOC8, 2); } goto LA1; LA6: ; { if (!(dest0.s == ((Tstorageloc294812) 3))) goto LA10; { NIM_BOOL LOC14; TY534811 LOC17; LOC14 = (NIM_BOOL)0; LOC14 = canformacycle_322123_3876443242(dest0.t); if (!LOC14) goto LA15; memset((void*)LOC17, 0, sizeof(LOC17)); LOC17[0] = addrloc_540204_839829468(dest0); LOC17[1] = rdloc_540188_839829468(src0); linefmt_534714_839829468(p0, ((Tcprocsection531011) 2), ((NimStringDesc*) &T839829468_249), LOC17, 2); } goto LA12; LA15: ; { TY534811 LOC19; memset((void*)LOC19, 0, sizeof(LOC19)); LOC19[0] = addrloc_540204_839829468(dest0); LOC19[1] = rdloc_540188_839829468(src0); linefmt_534714_839829468(p0, ((Tcprocsection531011) 2), ((NimStringDesc*) &T839829468_250), LOC19, 2); } LA12: ; } goto LA1; LA10: ; { TY534811 LOC21; memset((void*)LOC21, 0, sizeof(LOC21)); LOC21[0] = addrloc_540204_839829468(dest0); LOC21[1] = rdloc_540188_839829468(src0); linefmt_534714_839829468(p0, ((Tcprocsection531011) 2), ((NimStringDesc*) &T839829468_251), LOC21, 2); } LA1: ; } N_NIMCALL(void, optasgnloc_551788_839829468)(Tloc294816 a0, Ttype294840* t0, Ropeobj180006* field0, Tloc294816* Result) { Ropeobj180006* LOC1; Ropeobj180006* LOC2; (*Result).k = ((Tlockind294808) 5); (*Result).s = a0.s; unsureAsgnRef((void**) (&(*Result).t), t0); LOC1 = (Ropeobj180006*)0; LOC1 = rdloc_540188_839829468(a0); LOC2 = (Ropeobj180006*)0; LOC2 = HEX26_180447_2381377266(LOC1, ((NimStringDesc*) &T839829468_257)); unsureAsgnRef((void**) (&(*Result).r), HEX26_180418_2381377266(LOC2, field0)); } N_NIMCALL(void, genoptasgntuple_552001_839829468)(Tcproc531021* p0, Tloc294816 dest0, Tloc294816 src0, Tassignmentflag540302Set flags0) { Tassignmentflag540302Set newflags0; Ttype294840* t_552053_839829468; Ttype294840* LOC9; { if (!(src0.s == ((Tstorageloc294812) 1))) goto LA3; newflags0 = (flags0 | 1); } goto LA1; LA3: ; { if (!(((*dest0.t).flags &(1U<<((NU)(((Ttypeflag294431) 6))&31U)))!=0)) goto LA6; newflags0 = (flags0 & ~ 1); } goto LA1; LA6: ; { newflags0 = flags0; } LA1: ; LOC9 = (Ttype294840*)0; LOC9 = skiptypes_298099_850551059(dest0.t, IL64(211106232576256)); t_552053_839829468 = getuniquetype_530640_2036603609(LOC9); { NI i_552071_839829468; NI HEX3Atmp_552077_839829468; NI LOC11; NI res_552080_839829468; i_552071_839829468 = (NI)0; HEX3Atmp_552077_839829468 = (NI)0; LOC11 = (NI)0; LOC11 = len_297339_850551059(t_552053_839829468); HEX3Atmp_552077_839829468 = (LOC11 - 1); res_552080_839829468 = ((NI) 0); { while (1) { Ttype294840* t0; Ropeobj180006* field0; TY180507 LOC14; Tloc294816 LOC15; Tloc294816 LOC16; if (!(res_552080_839829468 <= HEX3Atmp_552077_839829468)) goto LA13; i_552071_839829468 = res_552080_839829468; t0 = (*t_552053_839829468).sons->data[i_552071_839829468]; memset((void*)LOC14, 0, sizeof(LOC14)); LOC14[0] = rope_180401_2381377266(((NI64) (i_552071_839829468))); field0 = HEX25_180905_2381377266(((NimStringDesc*) &T839829468_260), LOC14, 1); memset((void*)(&LOC15), 0, sizeof(LOC15)); optasgnloc_551788_839829468(dest0, t0, field0, (&LOC15)); memset((void*)(&LOC16), 0, sizeof(LOC16)); optasgnloc_551788_839829468(src0, t0, field0, (&LOC16)); genassignment_541264_839829468(p0, LOC15, LOC16, newflags0); res_552080_839829468 += ((NI) 1); } LA13: ; } } } N_NIMCALL(void, gengenericasgn_552167_839829468)(Tcproc531021* p0, Tloc294816 dest0, Tloc294816 src0, Tassignmentflag540302Set flags0) { { NIM_BOOL LOC3; Ttype294840* LOC5; LOC3 = (NIM_BOOL)0; LOC3 = !(((flags0 &(1U<<((NU)(((Tassignmentflag540302) 0))&7U)))!=0)); if (LOC3) goto LA4; LOC5 = (Ttype294840*)0; LOC5 = skiptypes_298099_850551059(dest0.t, IL64(211106242013440)); LOC3 = (((*LOC5).flags &(1U<<((NU)(((Ttypeflag294431) 6))&31U)))!=0); LA4: ; if (!LOC3) goto LA6; { NIM_BOOL LOC10; NIM_BOOL LOC12; TY537238 LOC15; LOC10 = (NIM_BOOL)0; LOC10 = (dest0.s == ((Tstorageloc294812) 2)); if (LOC10) goto LA11; LOC12 = (NIM_BOOL)0; LOC12 = usesnativegc_171177_2607990831(); LOC10 = !(LOC12); LA11: ; if (!LOC10) goto LA13; usestringh_534345_839829468((*p0).module); memset((void*)LOC15, 0, sizeof(LOC15)); LOC15[0] = addrloc_540204_839829468(dest0); LOC15[1] = addrloc_540204_839829468(src0); LOC15[2] = rdloc_540188_839829468(dest0); linefmt_534714_839829468(p0, ((Tcprocsection531011) 2), ((NimStringDesc*) &T839829468_261), LOC15, 3); } goto LA8; LA13: ; { TY537238 LOC17; memset((void*)LOC17, 0, sizeof(LOC17)); LOC17[0] = addrloc_540204_839829468(dest0); LOC17[1] = addrloc_540204_839829468(src0); LOC17[2] = gentypeinfo_537941_839829468((*p0).module, dest0.t); linefmt_534714_839829468(p0, ((Tcprocsection531011) 2), ((NimStringDesc*) &T839829468_262), LOC17, 3); } LA8: ; } goto LA1; LA6: ; { TY537238 LOC19; memset((void*)LOC19, 0, sizeof(LOC19)); LOC19[0] = addrloc_540204_839829468(dest0); LOC19[1] = addrloc_540204_839829468(src0); LOC19[2] = gentypeinfo_537941_839829468((*p0).module, dest0.t); linefmt_534714_839829468(p0, ((Tcprocsection531011) 2), ((NimStringDesc*) &T839829468_263), LOC19, 3); } LA1: ; } N_NIMCALL(NI, asgncomplexity_551750_839829468)(Tnode294802* n0) { NI result0; result0 = (NI)0; { if (!!((n0 == NIM_NIL))) goto LA3; switch ((*n0).kind) { case ((Tnodekind294020) 3): { result0 = ((NI) 1); } break; case ((Tnodekind294020) 139): { result0 = ((NI) 100); } break; case ((Tnodekind294020) 138): { { Tnode294802* t_551767_839829468; t_551767_839829468 = (Tnode294802*)0; { NI i_551781_839829468; NI HEX3Atmp_551783_839829468; NI LOC10; NI res_551785_839829468; i_551781_839829468 = (NI)0; HEX3Atmp_551783_839829468 = (NI)0; LOC10 = (NI)0; LOC10 = len_295081_850551059(n0); HEX3Atmp_551783_839829468 = (LOC10 - 1); res_551785_839829468 = ((NI) 0); { while (1) { NI LOC13; if (!(res_551785_839829468 <= HEX3Atmp_551783_839829468)) goto LA12; i_551781_839829468 = res_551785_839829468; t_551767_839829468 = (*n0).kindU.S6.sons->data[i_551781_839829468]; LOC13 = (NI)0; LOC13 = asgncomplexity_551750_839829468(t_551767_839829468); result0 += LOC13; res_551785_839829468 += ((NI) 1); } LA12: ; } } } } break; default: { } break; } } LA3: ; return result0; } N_NIMCALL(void, genoptasgnobject_552084_839829468)(Tcproc531021* p0, Tloc294816 dest0, Tloc294816 src0, Tassignmentflag540302Set flags0, Tnode294802* t0) { Tassignmentflag540302Set newflags0; { { if (!(t0 == NIM_NIL)) goto LA3; goto BeforeRet; } LA3: ; { if (!(src0.s == ((Tstorageloc294812) 1))) goto LA7; newflags0 = (flags0 | 1); } goto LA5; LA7: ; { if (!(((*dest0.t).flags &(1U<<((NU)(((Ttypeflag294431) 6))&31U)))!=0)) goto LA10; newflags0 = (flags0 & ~ 1); } goto LA5; LA10: ; { newflags0 = flags0; } LA5: ; switch ((*t0).kind) { case ((Tnodekind294020) 3): { Tsym294834* field0; Tloc294816 LOC14; Tloc294816 LOC15; field0 = (*t0).kindU.S4.sym; memset((void*)(&LOC14), 0, sizeof(LOC14)); optasgnloc_551788_839829468(dest0, (*field0).typ, (*field0).loc.r, (&LOC14)); memset((void*)(&LOC15), 0, sizeof(LOC15)); optasgnloc_551788_839829468(src0, (*field0).typ, (*field0).loc.r, (&LOC15)); genassignment_541264_839829468(p0, LOC14, LOC15, newflags0); } break; case ((Tnodekind294020) 138): { { Tnode294802* child_552155_839829468; child_552155_839829468 = (Tnode294802*)0; { NI i_552160_839829468; NI HEX3Atmp_552162_839829468; NI LOC19; NI res_552164_839829468; i_552160_839829468 = (NI)0; HEX3Atmp_552162_839829468 = (NI)0; LOC19 = (NI)0; LOC19 = len_295081_850551059(t0); HEX3Atmp_552162_839829468 = (LOC19 - 1); res_552164_839829468 = ((NI) 0); { while (1) { if (!(res_552164_839829468 <= HEX3Atmp_552162_839829468)) goto LA21; i_552160_839829468 = res_552164_839829468; child_552155_839829468 = (*t0).kindU.S6.sons->data[i_552160_839829468]; genoptasgnobject_552084_839829468(p0, dest0, src0, newflags0, child_552155_839829468); res_552164_839829468 += ((NI) 1); } LA21: ; } } } } break; default: { } break; } }BeforeRet: ; } N_NIMCALL(void, genassignment_541264_839829468)(Tcproc531021* p0, Tloc294816 dest0, Tloc294816 src0, Tassignmentflag540302Set flags0) { Ttype294840* ty0; { { NIM_BOOL LOC3; TY534811 LOC7; LOC3 = (NIM_BOOL)0; LOC3 = !((src0.t == NIM_NIL)); if (!(LOC3)) goto LA4; LOC3 = ((*src0.t).kind == ((Ttypekind294244) 21)); LA4: ; if (!LOC3) goto LA5; memset((void*)LOC7, 0, sizeof(LOC7)); LOC7[0] = rdloc_540188_839829468(dest0); LOC7[1] = rdloc_540188_839829468(src0); linefmt_534714_839829468(p0, ((Tcprocsection531011) 2), ((NimStringDesc*) &T839829468_123), LOC7, 2); goto BeforeRet; } LA5: ; ty0 = skiptypes_298099_850551059(dest0.t, IL64(211106233624832)); switch ((*ty0).kind) { case ((Ttypekind294244) 22): { genrefassign_540311_839829468(p0, dest0, src0, flags0); } break; case ((Ttypekind294244) 24): { { NIM_BOOL LOC12; LOC12 = (NIM_BOOL)0; LOC12 = !(((flags0 &(1U<<((NU)(((Tassignmentflag540302) 0))&7U)))!=0)); if (!(LOC12)) goto LA13; LOC12 = !((src0.s == ((Tstorageloc294812) 1))); LA13: ; if (!LOC12) goto LA14; genrefassign_540311_839829468(p0, dest0, src0, flags0); } goto LA10; LA14: ; { TY537238 LOC17; memset((void*)LOC17, 0, sizeof(LOC17)); LOC17[0] = addrloc_540204_839829468(dest0); LOC17[1] = rdloc_540188_839829468(src0); LOC17[2] = gentypeinfo_537941_839829468((*p0).module, dest0.t); linefmt_534714_839829468(p0, ((Tcprocsection531011) 2), ((NimStringDesc*) &T839829468_252), LOC17, 3); } LA10: ; } break; case ((Ttypekind294244) 28): { { NIM_BOOL LOC21; LOC21 = (NIM_BOOL)0; LOC21 = !(((flags0 &(1U<<((NU)(((Tassignmentflag540302) 0))&7U)))!=0)); if (!(LOC21)) goto LA22; LOC21 = !((src0.s == ((Tstorageloc294812) 1))); LA22: ; if (!LOC21) goto LA23; genrefassign_540311_839829468(p0, dest0, src0, flags0); } goto LA19; LA23: ; { { NIM_BOOL LOC28; NIM_BOOL LOC30; TY534811 LOC33; LOC28 = (NIM_BOOL)0; LOC28 = (dest0.s == ((Tstorageloc294812) 2)); if (LOC28) goto LA29; LOC30 = (NIM_BOOL)0; LOC30 = usesnativegc_171177_2607990831(); LOC28 = !(LOC30); LA29: ; if (!LOC28) goto LA31; memset((void*)LOC33, 0, sizeof(LOC33)); LOC33[0] = rdloc_540188_839829468(dest0); LOC33[1] = rdloc_540188_839829468(src0); linefmt_534714_839829468(p0, ((Tcprocsection531011) 2), ((NimStringDesc*) &T839829468_253), LOC33, 2); } goto LA26; LA31: ; { Tloc294816 tmp0; TY537238 LOC37; TY180507 LOC38; if (!(dest0.s == ((Tstorageloc294812) 3))) goto LA35; memset((void*)(&tmp0), 0, sizeof(tmp0)); gettemp_539032_839829468(p0, ty0, (&tmp0), NIM_FALSE); memset((void*)LOC37, 0, sizeof(LOC37)); LOC37[0] = rdloc_540188_839829468(dest0); LOC37[1] = rdloc_540188_839829468(src0); LOC37[2] = rdloc_540188_839829468(tmp0); linefmt_534714_839829468(p0, ((Tcprocsection531011) 2), ((NimStringDesc*) &T839829468_254), LOC37, 3); memset((void*)LOC38, 0, sizeof(LOC38)); LOC38[0] = rdloc_540188_839829468(tmp0); linefmt_534714_839829468(p0, ((Tcprocsection531011) 2), ((NimStringDesc*) &T839829468_255), LOC38, 1); } goto LA26; LA35: ; { TY534811 LOC40; memset((void*)LOC40, 0, sizeof(LOC40)); LOC40[0] = addrloc_540204_839829468(dest0); LOC40[1] = rdloc_540188_839829468(src0); linefmt_534714_839829468(p0, ((Tcprocsection531011) 2), ((NimStringDesc*) &T839829468_256), LOC40, 2); } LA26: ; } LA19: ; } break; case ((Ttypekind294244) 25): { { NIM_BOOL LOC44; Tloc294816 a0; Ropeobj180006* LOC47; Tloc294816 LOC48; Tloc294816 b0; Ropeobj180006* LOC49; Tloc294816 LOC50; TY534811 LOC51; LOC44 = (NIM_BOOL)0; LOC44 = needscomplexassignment_535509_839829468(dest0.t); if (!LOC44) goto LA45; memset((void*)(&a0), 0, sizeof(a0)); LOC47 = (Ropeobj180006*)0; LOC47 = rope_180277_2381377266(((NimStringDesc*) &T839829468_258)); memset((void*)(&LOC48), 0, sizeof(LOC48)); optasgnloc_551788_839829468(dest0, dest0.t, LOC47, (&LOC48)); memcpy((void*)(&a0), (NIM_CONST void*)(&LOC48), sizeof(a0)); memset((void*)(&b0), 0, sizeof(b0)); LOC49 = (Ropeobj180006*)0; LOC49 = rope_180277_2381377266(((NimStringDesc*) &T839829468_258)); memset((void*)(&LOC50), 0, sizeof(LOC50)); optasgnloc_551788_839829468(src0, dest0.t, LOC49, (&LOC50)); memcpy((void*)(&b0), (NIM_CONST void*)(&LOC50), sizeof(b0)); genrefassign_540311_839829468(p0, a0, b0, flags0); memset((void*)LOC51, 0, sizeof(LOC51)); LOC51[0] = rdloc_540188_839829468(dest0); LOC51[1] = rdloc_540188_839829468(src0); linefmt_534714_839829468(p0, ((Tcprocsection531011) 2), ((NimStringDesc*) &T839829468_259), LOC51, 2); } goto LA42; LA45: ; { TY534811 LOC53; memset((void*)LOC53, 0, sizeof(LOC53)); LOC53[0] = rdloc_540188_839829468(dest0); LOC53[1] = rdloc_540188_839829468(src0); linefmt_534714_839829468(p0, ((Tcprocsection531011) 2), ((NimStringDesc*) &T839829468_123), LOC53, 2); } LA42: ; } break; case ((Ttypekind294244) 18): { { NIM_BOOL LOC57; LOC57 = (NIM_BOOL)0; LOC57 = needscomplexassignment_535509_839829468(dest0.t); if (!LOC57) goto LA58; { NI LOC62; LOC62 = (NI)0; LOC62 = len_297339_850551059(dest0.t); if (!(LOC62 <= ((NI) 4))) goto LA63; genoptasgntuple_552001_839829468(p0, dest0, src0, flags0); } goto LA60; LA63: ; { gengenericasgn_552167_839829468(p0, dest0, src0, flags0); } LA60: ; } goto LA55; LA58: ; { TY534811 LOC67; memset((void*)LOC67, 0, sizeof(LOC67)); LOC67[0] = rdloc_540188_839829468(dest0); LOC67[1] = rdloc_540188_839829468(src0); linefmt_534714_839829468(p0, ((Tcprocsection531011) 2), ((NimStringDesc*) &T839829468_123), LOC67, 2); } LA55: ; } break; case ((Ttypekind294244) 17): { { NIM_BOOL LOC71; TY534811 LOC74; LOC71 = (NIM_BOOL)0; LOC71 = isimportedcpptype_535476_839829468(ty0); if (!LOC71) goto LA72; memset((void*)LOC74, 0, sizeof(LOC74)); LOC74[0] = rdloc_540188_839829468(dest0); LOC74[1] = rdloc_540188_839829468(src0); linefmt_534714_839829468(p0, ((Tcprocsection531011) 2), ((NimStringDesc*) &T839829468_123), LOC74, 2); } goto LA69; LA72: ; { NIM_BOOL LOC76; LOC76 = (NIM_BOOL)0; LOC76 = isobjlackingtypefield_535513_839829468(ty0); if (!!(LOC76)) goto LA77; gengenericasgn_552167_839829468(p0, dest0, src0, flags0); } goto LA69; LA77: ; { NIM_BOOL LOC80; LOC80 = (NIM_BOOL)0; LOC80 = needscomplexassignment_535509_839829468(ty0); if (!LOC80) goto LA81; { NIM_BOOL LOC85; NI LOC87; Ropeobj180006* LOC90; LOC85 = (NIM_BOOL)0; LOC85 = (*ty0).sons->data[((NI) 0)] == 0; if (!(LOC85)) goto LA86; LOC87 = (NI)0; LOC87 = asgncomplexity_551750_839829468((*ty0).n); LOC85 = (LOC87 <= ((NI) 4)); LA86: ; if (!LOC85) goto LA88; LOC90 = (Ropeobj180006*)0; LOC90 = gettypedesc_537671_839829468((*p0).module, ty0); ty0 = getuniquetype_530640_2036603609(ty0); { NimStringDesc* LOC95; if (!!(!(((*ty0).n == NIM_NIL)))) goto LA93; LOC95 = (NimStringDesc*)0; LOC95 = HEX24_198185_1689653243(T839829468_264); internalerror_198113_155036129(LOC95); } LA93: ; genoptasgnobject_552084_839829468(p0, dest0, src0, flags0, (*ty0).n); } goto LA83; LA88: ; { gengenericasgn_552167_839829468(p0, dest0, src0, flags0); } LA83: ; } goto LA69; LA81: ; { TY534811 LOC98; memset((void*)LOC98, 0, sizeof(LOC98)); LOC98[0] = rdloc_540188_839829468(dest0); LOC98[1] = rdloc_540188_839829468(src0); linefmt_534714_839829468(p0, ((Tcprocsection531011) 2), ((NimStringDesc*) &T839829468_123), LOC98, 2); } LA69: ; } break; case ((Ttypekind294244) 16): case ((Ttypekind294244) 4): { { NIM_BOOL LOC102; LOC102 = (NIM_BOOL)0; LOC102 = needscomplexassignment_535509_839829468(dest0.t); if (!LOC102) goto LA103; gengenericasgn_552167_839829468(p0, dest0, src0, flags0); } goto LA100; LA103: ; { TY537238 LOC106; usestringh_534345_839829468((*p0).module); memset((void*)LOC106, 0, sizeof(LOC106)); LOC106[0] = rdloc_540188_839829468(dest0); LOC106[1] = rdloc_540188_839829468(src0); LOC106[2] = gettypedesc_537671_839829468((*p0).module, ty0); linefmt_534714_839829468(p0, ((Tcprocsection531011) 2), ((NimStringDesc*) &T839829468_261), LOC106, 3); } LA100: ; } break; case ((Ttypekind294244) 27): case ((Ttypekind294244) 48): { { NIM_BOOL LOC110; TY537238 LOC113; LOC110 = (NIM_BOOL)0; LOC110 = needscomplexassignment_535509_839829468(dest0.t); if (!LOC110) goto LA111; memset((void*)LOC113, 0, sizeof(LOC113)); LOC113[0] = addrloc_540204_839829468(dest0); LOC113[1] = addrloc_540204_839829468(src0); LOC113[2] = gentypeinfo_537941_839829468((*p0).module, dest0.t); linefmt_534714_839829468(p0, ((Tcprocsection531011) 2), ((NimStringDesc*) &T839829468_266), LOC113, 3); } goto LA108; LA111: ; { TY534811 LOC115; usestringh_534345_839829468((*p0).module); memset((void*)LOC115, 0, sizeof(LOC115)); LOC115[0] = rdloc_540188_839829468(dest0); LOC115[1] = rdloc_540188_839829468(src0); linefmt_534714_839829468(p0, ((Tcprocsection531011) 2), ((NimStringDesc*) &T839829468_267), LOC115, 2); } LA108: ; } break; case ((Ttypekind294244) 19): { { Tctypekind531007 LOC119; TY537238 LOC122; NI64 LOC123; LOC119 = (Tctypekind531007)0; LOC119 = maptype_535393_839829468(ty0); if (!(LOC119 == ((Tctypekind531007) 17))) goto LA120; usestringh_534345_839829468((*p0).module); memset((void*)LOC122, 0, sizeof(LOC122)); LOC122[0] = rdloc_540188_839829468(dest0); LOC122[1] = rdloc_540188_839829468(src0); LOC123 = (NI64)0; LOC123 = getsize_322135_3876443242(dest0.t); LOC122[2] = rope_180401_2381377266(LOC123); linefmt_534714_839829468(p0, ((Tcprocsection531011) 2), ((NimStringDesc*) &T839829468_268), LOC122, 3); } goto LA117; LA120: ; { TY534811 LOC125; memset((void*)LOC125, 0, sizeof(LOC125)); LOC125[0] = rdloc_540188_839829468(dest0); LOC125[1] = rdloc_540188_839829468(src0); linefmt_534714_839829468(p0, ((Tcprocsection531011) 2), ((NimStringDesc*) &T839829468_123), LOC125, 2); } LA117: ; } break; case ((Ttypekind294244) 21): case ((Ttypekind294244) 26): case ((Ttypekind294244) 2): case ((Ttypekind294244) 1): case ((Ttypekind294244) 14): case ((Ttypekind294244) 29): case ((Ttypekind294244) 31) ... ((Ttypekind294244) 44): case ((Ttypekind294244) 20): case ((Ttypekind294244) 23): { TY534811 LOC127; memset((void*)LOC127, 0, sizeof(LOC127)); LOC127[0] = rdloc_540188_839829468(dest0); LOC127[1] = rdloc_540188_839829468(src0); linefmt_534714_839829468(p0, ((Tcprocsection531011) 2), ((NimStringDesc*) &T839829468_123), LOC127, 2); } break; default: { NimStringDesc* LOC129; LOC129 = (NimStringDesc*)0; LOC129 = rawNewString(reprEnum((NI)(*ty0).kind, (&NTI294244))->Sup.len + 15); appendString(LOC129, ((NimStringDesc*) &T839829468_269)); appendString(LOC129, reprEnum((NI)(*ty0).kind, (&NTI294244))); internalerror_198113_155036129(LOC129); } break; } }BeforeRet: ; } N_NIMCALL(void, putlocintodest_541258_839829468)(Tcproc531021* p0, Tloc294816* d0, Tloc294816 s0) { { if (!!(((*d0).k == ((Tlockind294808) 0)))) goto LA3; { if (!(((*d0).flags &(1U<<((NU)(((Tlocflag294810) 2))&15U)))!=0)) goto LA7; genassignment_541264_839829468(p0, (*d0), s0, 0); } goto LA5; LA7: ; { genassignment_541264_839829468(p0, (*d0), s0, 1); } LA5: ; } goto LA1; LA3: ; { genericAssign((void*)(&(*d0)), (void*)(&s0), (&NTI294816)); } LA1: ; } N_NIMCALL(NIM_BOOL, issimpleconst_534311_839829468)(Ttype294840* typ0) { NIM_BOOL result0; Ttype294840* t0; NIM_BOOL LOC1; NIM_BOOL LOC3; result0 = (NIM_BOOL)0; t0 = skiptypes_298099_850551059(typ0, IL64(211106240964864)); LOC1 = (NIM_BOOL)0; LOC1 = !(((*t0).kind == ((Ttypekind294244) 18) || (*t0).kind == ((Ttypekind294244) 17) || (*t0).kind == ((Ttypekind294244) 16) || (*t0).kind == ((Ttypekind294244) 4) || (*t0).kind == ((Ttypekind294244) 19) || (*t0).kind == ((Ttypekind294244) 24))); if (!(LOC1)) goto LA2; LOC3 = (NIM_BOOL)0; LOC3 = ((*t0).kind == ((Ttypekind294244) 25)); if (!(LOC3)) goto LA4; LOC3 = ((*t0).callconv == ((Tcallingconvention294002) 8)); LA4: ; LOC1 = !(LOC3); LA2: ; result0 = LOC1; return result0; } N_NIMCALL(void, putintodest_552468_839829468)(Tcproc531021* p0, Tloc294816* d0, Ttype294840* t0, Ropeobj180006* r0, Tstorageloc294812 s0) { Tloc294816 a0; memset((void*)(&a0), 0, sizeof(a0)); { if (!!(((*d0).k == ((Tlockind294808) 0)))) goto LA3; initloc_534273_839829468((&a0), ((Tlockind294808) 6), t0, s0); a0.r = r0; { if (!(((*d0).flags &(1U<<((NU)(((Tlocflag294810) 2))&15U)))!=0)) goto LA7; genassignment_541264_839829468(p0, (*d0), a0, 0); } goto LA5; LA7: ; { genassignment_541264_839829468(p0, (*d0), a0, 1); } LA5: ; } goto LA1; LA3: ; { (*d0).k = ((Tlockind294808) 6); unsureAsgnRef((void**) (&(*d0).t), t0); unsureAsgnRef((void**) (&(*d0).r), r0); } LA1: ; } N_NIMCALL(NI64, bitsettoword_551578_839829468)(Tbitset341004* s0, NI size0) { NI64 result0; result0 = (NI64)0; result0 = IL64(0); { NI j_551612_839829468; NI HEX3Atmp_551622_839829468; NI res_551625_839829468; j_551612_839829468 = (NI)0; HEX3Atmp_551622_839829468 = (NI)0; HEX3Atmp_551622_839829468 = (NI)(size0 - ((NI) 1)); res_551625_839829468 = ((NI) 0); { while (1) { if (!(res_551625_839829468 <= HEX3Atmp_551622_839829468)) goto LA3; j_551612_839829468 = res_551625_839829468; { if (!(j_551612_839829468 < (s0 ? s0->Sup.len : 0))) goto LA6; result0 = (NI64)(result0 | (NI64)((NU64)(((NI64)(NU64)(NU8)(s0->data[j_551612_839829468]))) << (NU64)(((NI64) ((NI)(j_551612_839829468 * ((NI) 8))))))); } LA6: ; res_551625_839829468 += ((NI) 1); } LA3: ; } } return result0; } N_NIMCALL(Ropeobj180006*, genrawsetdata_551629_839829468)(Tbitset341004* cs0, NI size0) { Ropeobj180006* result0; NimStringDesc* frmt0; result0 = (Ropeobj180006*)0; frmt0 = (NimStringDesc*)0; { TY535289 LOC5; if (!(((NI) 8) < size0)) goto LA3; memset((void*)LOC5, 0, sizeof(LOC5)); result0 = HEX25_180905_2381377266(((NimStringDesc*) &T839829468_273), LOC5, 0); { NI i_551649_839829468; NI HEX3Atmp_551657_839829468; NI res_551660_839829468; i_551649_839829468 = (NI)0; HEX3Atmp_551657_839829468 = (NI)0; HEX3Atmp_551657_839829468 = (NI)(size0 - ((NI) 1)); res_551660_839829468 = ((NI) 0); { while (1) { TY180507 LOC19; NimStringDesc* LOC20; if (!(res_551660_839829468 <= HEX3Atmp_551657_839829468)) goto LA8; i_551649_839829468 = res_551660_839829468; { if (!(i_551649_839829468 < (NI)(size0 - ((NI) 1)))) goto LA11; { if (!(((NI) ((NI)((NI)(i_551649_839829468 + ((NI) 1)) % ((NI) 8)))) == ((NI) 0))) goto LA15; frmt0 = copyString(((NimStringDesc*) &T839829468_274)); } goto LA13; LA15: ; { frmt0 = copyString(((NimStringDesc*) &T839829468_275)); } LA13: ; } goto LA9; LA11: ; { frmt0 = copyString(((NimStringDesc*) &T839829468_276)); } LA9: ; memset((void*)LOC19, 0, sizeof(LOC19)); LOC20 = (NimStringDesc*)0; LOC20 = nsuToHex(((NI64)(NU64)(NU8)(cs0->data[i_551649_839829468])), ((NI) 2)); LOC19[0] = rope_180277_2381377266(LOC20); addf_181205_2381377266(&result0, frmt0, LOC19, 1); res_551660_839829468 += ((NI) 1); } LA8: ; } } } goto LA1; LA3: ; { NI64 LOC22; LOC22 = (NI64)0; LOC22 = bitsettoword_551578_839829468(cs0, size0); result0 = intliteral_541270_839829468(LOC22); } LA1: ; return result0; } N_NIMCALL(void, appcg_534640_839829468)(Tcgen531027* m0, Tcfilesection531005 s0, NimStringDesc* frmt0, Ropeobj180006** args0, NI args0Len0) { Ropeobj180006* LOC1; LOC1 = (Ropeobj180006*)0; LOC1 = ropecg_534407_839829468(m0, frmt0, args0, args0Len0); add_180482_2381377266(&(*m0).s[(s0)- 0], LOC1); } N_NIMCALL(Ropeobj180006*, genconstseq_561371_839829468)(Tcproc531021* p0, Tnode294802* n0, Ttype294840* t0) { Ropeobj180006* result0; Ropeobj180006* data0; TY180507 LOC1; NI LOC2; TY537235 LOC18; NI LOC19; TY534811 LOC20; result0 = (Ropeobj180006*)0; memset((void*)LOC1, 0, sizeof(LOC1)); LOC2 = (NI)0; LOC2 = len_295081_850551059(n0); LOC1[0] = rope_180401_2381377266(((NI64) (LOC2))); data0 = HEX25_180905_2381377266(((NimStringDesc*) &T839829468_277), LOC1, 1); { NI LOC5; LOC5 = (NI)0; LOC5 = len_295081_850551059(n0); if (!(((NI) 0) < LOC5)) goto LA6; add_180487_2381377266(&data0, ((NimStringDesc*) &T839829468_278)); { NI i_561395_839829468; NI HEX3Atmp_561411_839829468; NI LOC9; NI res_561414_839829468; i_561395_839829468 = (NI)0; HEX3Atmp_561411_839829468 = (NI)0; LOC9 = (NI)0; LOC9 = len_295081_850551059(n0); HEX3Atmp_561411_839829468 = (NI)(LOC9 - ((NI) 1)); res_561414_839829468 = ((NI) 0); { while (1) { Ropeobj180006* LOC17; if (!(res_561414_839829468 <= HEX3Atmp_561411_839829468)) goto LA11; i_561395_839829468 = res_561414_839829468; { TY535289 LOC16; if (!(((NI) 0) < i_561395_839829468)) goto LA14; memset((void*)LOC16, 0, sizeof(LOC16)); addf_181205_2381377266(&data0, ((NimStringDesc*) &T839829468_279), LOC16, 0); } LA14: ; LOC17 = (Ropeobj180006*)0; LOC17 = genconstexpr_556849_839829468(p0, (*n0).kindU.S6.sons->data[i_561395_839829468]); add_180482_2381377266(&data0, LOC17); res_561414_839829468 += ((NI) 1); } LA11: ; } } add_180487_2381377266(&data0, ((NimStringDesc*) &T839829468_280)); } LA6: ; add_180487_2381377266(&data0, ((NimStringDesc*) &T839829468_280)); result0 = gettempname_535596_839829468((*p0).module); memset((void*)LOC18, 0, sizeof(LOC18)); LOC18[0] = gettypedesc_537671_839829468((*p0).module, (*t0).sons->data[((NI) 0)]); LOC19 = (NI)0; LOC19 = len_295081_850551059(n0); LOC18[1] = rope_180401_2381377266(((NI64) (LOC19))); LOC18[2] = result0; LOC18[3] = data0; appcg_534640_839829468((*p0).module, ((Tcfilesection531005) 8), ((NimStringDesc*) &T839829468_281), LOC18, 4); memset((void*)LOC20, 0, sizeof(LOC20)); LOC20[0] = gettypedesc_537671_839829468((*p0).module, t0); LOC20[1] = result0; result0 = HEX25_180905_2381377266(((NimStringDesc*) &T839829468_282), LOC20, 2); return result0; } N_NIMCALL(Ropeobj180006*, gennamedconstexpr_561284_839829468)(Tcproc531021* p0, Tnode294802* n0) { Ropeobj180006* result0; result0 = (Ropeobj180006*)0; { if (!((*n0).kind == ((Tnodekind294020) 34))) goto LA3; result0 = genconstexpr_556849_839829468(p0, (*n0).kindU.S6.sons->data[((NI) 1)]); } goto LA1; LA3: ; { result0 = genconstexpr_556849_839829468(p0, n0); } LA1: ; return result0; } N_NIMCALL(Ropeobj180006*, genconstsimplelist_561299_839829468)(Tcproc531021* p0, Tnode294802* n0) { Ropeobj180006* result0; NI length0; TY535289 LOC10; result0 = (Ropeobj180006*)0; length0 = sonslen_297351_850551059(n0); result0 = rope_180277_2381377266(((NimStringDesc*) &T839829468_223)); { NI i_561333_839829468; NI HEX3Atmp_561362_839829468; NI HEX3Atmp_561363_839829468; NI res_561366_839829468; i_561333_839829468 = (NI)0; HEX3Atmp_561362_839829468 = (NI)0; HEX3Atmp_561363_839829468 = (NI)0; HEX3Atmp_561362_839829468 = ((*n0).kind == ((Tnodekind294020) 38)); HEX3Atmp_561363_839829468 = (NI)(length0 - ((NI) 2)); res_561366_839829468 = ((NI) (HEX3Atmp_561362_839829468)); { while (1) { TY180507 LOC4; if (!(res_561366_839829468 <= HEX3Atmp_561363_839829468)) goto LA3; i_561333_839829468 = res_561366_839829468; memset((void*)LOC4, 0, sizeof(LOC4)); LOC4[0] = gennamedconstexpr_561284_839829468(p0, (*n0).kindU.S6.sons->data[i_561333_839829468]); addf_181205_2381377266(&result0, ((NimStringDesc*) &T839829468_283), LOC4, 1); res_561366_839829468 += ((NI) 1); } LA3: ; } } { Ropeobj180006* LOC9; if (!(((NI) (((*n0).kind == ((Tnodekind294020) 38)))) < length0)) goto LA7; LOC9 = (Ropeobj180006*)0; LOC9 = gennamedconstexpr_561284_839829468(p0, (*n0).kindU.S6.sons->data[(NI)(length0 - ((NI) 1))]); add_180482_2381377266(&result0, LOC9); } LA7: ; memset((void*)LOC10, 0, sizeof(LOC10)); addf_181205_2381377266(&result0, ((NimStringDesc*) &T839829468_160), LOC10, 0); return result0; } N_NIMCALL(Ropeobj180006*, genconstexpr_556849_839829468)(Tcproc531021* p0, Tnode294802* n0) { Ropeobj180006* result0; result0 = (Ropeobj180006*)0; switch ((*n0).kind) { case ((Tnodekind294020) 58): case ((Tnodekind294020) 59): { result0 = genconstexpr_556849_839829468(p0, (*n0).kindU.S6.sons->data[((NI) 1)]); } break; case ((Tnodekind294020) 39): { Tbitset341004* cs0; NI64 LOC3; cs0 = (Tbitset341004*)0; tobitset_342001_452470228(n0, (&cs0)); LOC3 = (NI64)0; LOC3 = getsize_322135_3876443242((*n0).typ); result0 = genrawsetdata_551629_839829468(cs0, ((NI) (LOC3))); } break; case ((Tnodekind294020) 41): case ((Tnodekind294020) 37): case ((Tnodekind294020) 155): case ((Tnodekind294020) 38): { Ttype294840* t0; t0 = skiptypes_298099_850551059((*n0).typ, IL64(211106232576256)); { if (!((*t0).kind == ((Ttypekind294244) 24))) goto LA7; result0 = genconstseq_561371_839829468(p0, n0, t0); } goto LA5; LA7: ; { result0 = genconstsimplelist_561299_839829468(p0, n0); } LA5: ; } break; default: { Tloc294816 d0; memset((void*)(&d0), 0, sizeof(d0)); initlocexpr_541283_839829468(p0, n0, (&d0)); result0 = rdloc_540188_839829468(d0); } break; } return result0; } N_NIMCALL(void, requestconstimpl_541240_839829468)(Tcproc531021* p0, Tsym294834* sym0) { Tcgen531027* m0; Tcgen531027* q0; { m0 = (*p0).module; useheader_534369_839829468(m0, sym0); { Ropeobj180006* LOC5; if (!((*sym0).loc.k == ((Tlockind294808) 0))) goto LA3; LOC5 = (Ropeobj180006*)0; LOC5 = manglename_535205_839829468(sym0); fillloc_534282_839829468((&(*sym0).loc), ((Tlockind294808) 8), (*sym0).typ, LOC5, ((Tstorageloc294812) 1)); } LA3: ; { if (!(((*sym0).loc.flags &(1U<<((NU)(((Tlocflag294810) 3))&15U)))!=0)) goto LA8; goto BeforeRet; } LA8: ; q0 = findpendingmodule_534241_839829468(m0, sym0); { NIM_BOOL LOC12; NIM_BOOL LOC14; TY537238 LOC17; LOC12 = (NIM_BOOL)0; LOC12 = !((q0 == NIM_NIL)); if (!(LOC12)) goto LA13; LOC14 = (NIM_BOOL)0; LOC14 = containsorincl_270862_2627731572((&(*q0).declaredthings), (*sym0).Sup.id); LOC12 = !(LOC14); LA13: ; if (!LOC12) goto LA15; memset((void*)LOC17, 0, sizeof(LOC17)); LOC17[0] = gettypedesc_537671_839829468(q0, (*sym0).typ); LOC17[1] = (*sym0).loc.r; LOC17[2] = genconstexpr_556849_839829468((*q0).initproc, (*sym0).ast); addf_181205_2381377266(&(*q0).s[(((Tcfilesection531005) 8))- 0], ((NimStringDesc*) &T839829468_272), LOC17, 3); } LA15: ; { NIM_BOOL LOC20; NIM_BOOL LOC22; Ropeobj180006* headerdecl0; TY534811 LOC25; LOC20 = (NIM_BOOL)0; LOC20 = !((q0 == m0)); if (!(LOC20)) goto LA21; LOC22 = (NIM_BOOL)0; LOC22 = containsorincl_270862_2627731572((&(*m0).declaredthings), (*sym0).Sup.id); LOC20 = !(LOC22); LA21: ; if (!LOC20) goto LA23; memset((void*)LOC25, 0, sizeof(LOC25)); LOC25[0] = gettypedesc_537671_839829468(m0, (*sym0).loc.t); LOC25[1] = (*sym0).loc.r; headerdecl0 = HEX25_180905_2381377266(((NimStringDesc*) &T839829468_284), LOC25, 2); add_180482_2381377266(&(*m0).s[(((Tcfilesection531005) 8))- 0], headerdecl0); { NIM_BOOL LOC28; LOC28 = (NIM_BOOL)0; LOC28 = (((*sym0).flags &(1U<<((NU)(((Tsymflag294184) 6))&31U)))!=0); if (!(LOC28)) goto LA29; LOC28 = !((generatedheader_534201_839829468 == NIM_NIL)); LA29: ; if (!LOC28) goto LA30; add_180482_2381377266(&(*generatedheader_534201_839829468).s[(((Tcfilesection531005) 8))- 0], headerdecl0); } LA30: ; } LA23: ; }BeforeRet: ; } N_NIMCALL(void, gencomplexconst_560249_839829468)(Tcproc531021* p0, Tsym294834* sym0, Tloc294816* d0) { requestconstimpl_541240_839829468(p0, sym0); putlocintodest_541258_839829468(p0, d0, (*sym0).loc); } static N_INLINE(Ropeobj180006**, procsec_531194_3723162438)(Tcproc531021* p0, Tcprocsection531011 s0) { Ropeobj180006** result0; result0 = (Ropeobj180006**)0; result0 = &(*p0).blocks->data[((NI) 0)].sections[(s0)- 0]; return result0; } N_NIMCALL(void, accessthreadlocalvar_534945_839829468)(Tcproc531021* p0, Tsym294834* s0) { { NIM_BOOL LOC3; Ropeobj180006** LOC7; TY535289 LOC8; Ropeobj180006** LOC9; TY535289 LOC10; Ropeobj180006* LOC11; LOC3 = (NIM_BOOL)0; LOC3 = emulatedthreadvars_534949_839829468(); if (!(LOC3)) goto LA4; LOC3 = !((*p0).threadvaraccessed); LA4: ; if (!LOC3) goto LA5; (*p0).threadvaraccessed = NIM_TRUE; (*(*p0).module).flags |= ((NU8)1)<<((((Codegenflag531025) 1))%(sizeof(NU8)*8)); LOC7 = (Ropeobj180006**)0; LOC7 = procsec_531194_3723162438(p0, ((Tcprocsection531011) 0)); memset((void*)LOC8, 0, sizeof(LOC8)); addf_181205_2381377266(LOC7, ((NimStringDesc*) &T839829468_286), LOC8, 0); LOC9 = (Ropeobj180006**)0; LOC9 = procsec_531194_3723162438(p0, ((Tcprocsection531011) 1)); memset((void*)LOC10, 0, sizeof(LOC10)); LOC11 = (Ropeobj180006*)0; LOC11 = ropecg_534407_839829468((*p0).module, ((NimStringDesc*) &T839829468_287), LOC10, 0); add_180482_2381377266(LOC9, LOC11); } LA5: ; } static N_INLINE(NIM_BOOL, isemptytype_299440_850551059)(Ttype294840* t0) { NIM_BOOL result0; NIM_BOOL LOC1; result0 = (NIM_BOOL)0; LOC1 = (NIM_BOOL)0; LOC1 = (t0 == NIM_NIL); if (LOC1) goto LA2; LOC1 = ((*t0).kind == ((Ttypekind294244) 62) || (*t0).kind == ((Ttypekind294244) 7)); LA2: ; result0 = LOC1; return result0; } N_NIMCALL(void, putdataintodest_552436_839829468)(Tcproc531021* p0, Tloc294816* d0, Ttype294840* t0, Ropeobj180006* r0) { Tloc294816 a0; memset((void*)(&a0), 0, sizeof(a0)); { if (!!(((*d0).k == ((Tlockind294808) 0)))) goto LA3; initloc_534273_839829468((&a0), ((Tlockind294808) 8), t0, ((Tstorageloc294812) 1)); a0.r = r0; { if (!(((*d0).flags &(1U<<((NU)(((Tlocflag294810) 2))&15U)))!=0)) goto LA7; genassignment_541264_839829468(p0, (*d0), a0, 0); } goto LA5; LA7: ; { genassignment_541264_839829468(p0, (*d0), a0, 1); } LA5: ; } goto LA1; LA3: ; { (*d0).k = ((Tlockind294808) 8); unsureAsgnRef((void**) (&(*d0).t), t0); unsureAsgnRef((void**) (&(*d0).r), r0); } LA1: ; } N_NIMCALL(NIM_BOOL, freshlineinfo_534818_839829468)(Tcproc531021* p0, Tlineinfo193336 info0) { NIM_BOOL result0; result0 = (NIM_BOOL)0; { NIM_BOOL LOC3; LOC3 = (NIM_BOOL)0; LOC3 = !(((*p0).lastlineinfo.line == info0.line)); if (LOC3) goto LA4; LOC3 = !(((*p0).lastlineinfo.fileindex == info0.fileindex)); LA4: ; if (!LOC3) goto LA5; (*p0).lastlineinfo.line = info0.line; (*p0).lastlineinfo.fileindex = info0.fileindex; result0 = NIM_TRUE; } LA5: ; return result0; } N_NIMCALL(void, genlinedir_534823_839829468)(Tcproc531021* p0, Tnode294802* t0) { NI line0; Ropeobj180006** LOC11; NimStringDesc* LOC12; line0 = safelinenm_534721_839829468((*t0).info); { Ropeobj180006** LOC5; TY535289 LOC6; Ropeobj180006* LOC7; Ropeobj180006* LOC8; Ropeobj180006* LOC9; Ropeobj180006* LOC10; if (!((gglobaloptions_171130_2607990831 &((NU64)1<<((NU)(((Tglobaloption171013) 28))&63U)))!=0)) goto LA3; LOC5 = (Ropeobj180006**)0; LOC5 = s_531179_3723162438(p0, ((Tcprocsection531011) 2)); memset((void*)LOC6, 0, sizeof(LOC6)); LOC7 = (Ropeobj180006*)0; LOC7 = HEX25_180905_2381377266(((NimStringDesc*) &T839829468_293), LOC6, 0); LOC8 = (Ropeobj180006*)0; LOC8 = sourceline_194068_155036129((*t0).info); LOC9 = (Ropeobj180006*)0; LOC9 = HEX26_180418_2381377266(LOC7, LOC8); LOC10 = (Ropeobj180006*)0; LOC10 = HEX26_180418_2381377266(LOC9, rnl_180903_2381377266); add_180482_2381377266(LOC5, LOC10); } LA3: ; LOC11 = (Ropeobj180006**)0; LOC11 = s_531179_3723162438(p0, ((Tcprocsection531011) 2)); LOC12 = (NimStringDesc*)0; LOC12 = tofullpath_194264_155036129((*t0).info.fileindex); genclinedir_534725_839829468(LOC11, LOC12, line0); { NIM_BOOL LOC15; NIM_BOOL LOC17; LOC15 = (NIM_BOOL)0; LOC15 = ((163840 & (*p0).options) == 163840); if (!(LOC15)) goto LA16; LOC17 = (NIM_BOOL)0; LOC17 = ((*p0).prc == NIM_NIL); if (LOC17) goto LA18; LOC17 = !((((*(*p0).prc).flags &(1U<<((NU)(((Tsymflag294184) 9))&31U)))!=0)); LA18: ; LOC15 = LOC17; LA16: ; if (!LOC15) goto LA19; { NIM_BOOL LOC23; TY534811 LOC26; NimStringDesc* LOC27; LOC23 = (NIM_BOOL)0; LOC23 = freshlineinfo_534818_839829468(p0, (*t0).info); if (!LOC23) goto LA24; memset((void*)LOC26, 0, sizeof(LOC26)); LOC26[0] = rope_180401_2381377266(((NI64) (line0))); LOC27 = (NimStringDesc*)0; LOC27 = tofilename_194260_155036129((*t0).info.fileindex); LOC26[1] = makecstring_193638_155036129(LOC27); linefmt_534714_839829468(p0, ((Tcprocsection531011) 2), ((NimStringDesc*) &T839829468_294), LOC26, 2); } LA24: ; } goto LA13; LA19: ; { NIM_BOOL LOC29; NIM_BOOL LOC30; NIM_BOOL LOC32; LOC29 = (NIM_BOOL)0; LOC30 = (NIM_BOOL)0; LOC30 = ((98304 & (*p0).options) == 98304); if (!(LOC30)) goto LA31; LOC32 = (NIM_BOOL)0; LOC32 = ((*p0).prc == NIM_NIL); if (LOC32) goto LA33; LOC32 = !((((*(*p0).prc).flags &(1U<<((NU)(((Tsymflag294184) 9))&31U)))!=0)); LA33: ; LOC30 = LOC32; LA31: ; LOC29 = LOC30; if (!(LOC29)) goto LA34; LOC29 = (((NI32) 0) <= (*t0).info.fileindex); LA34: ; if (!LOC29) goto LA35; { NIM_BOOL LOC39; TY534811 LOC42; LOC39 = (NIM_BOOL)0; LOC39 = freshlineinfo_534818_839829468(p0, (*t0).info); if (!LOC39) goto LA40; memset((void*)LOC42, 0, sizeof(LOC42)); LOC42[0] = rope_180401_2381377266(((NI64) (line0))); LOC42[1] = quotedfilename_198818_155036129((*t0).info); linefmt_534714_839829468(p0, ((Tcprocsection531011) 2), ((NimStringDesc*) &T839829468_295), LOC42, 2); } LA40: ; } goto LA13; LA35: ; LA13: ; } N_NIMCALL(Ropeobj180006*, getlabel_541217_839829468)(Tcproc531021* p0) { Ropeobj180006* result0; Ropeobj180006* LOC1; result0 = (Ropeobj180006*)0; (*p0).labels += ((NI) 1); LOC1 = (Ropeobj180006*)0; LOC1 = rope_180401_2381377266(((NI64) ((*p0).labels))); result0 = HEX26_180452_2381377266(((NimStringDesc*) &T839829468_296), LOC1); return result0; } N_NIMCALL(void, fixlabel_541230_839829468)(Tcproc531021* p0, Ropeobj180006* labl0) { TY180507 LOC1; memset((void*)LOC1, 0, sizeof(LOC1)); LOC1[0] = labl0; linef_534700_839829468(p0, ((Tcprocsection531011) 2), ((NimStringDesc*) &T839829468_299), LOC1, 1); } N_NIMCALL(void, genandor_556311_839829468)(Tcproc531021* p0, Tnode294802* e0, Tloc294816* d0, Tmagic294524 m0) { Ropeobj180006* L0; Tloc294816 tmp0; L0 = (Ropeobj180006*)0; memset((void*)(&tmp0), 0, sizeof(tmp0)); gettemp_539032_839829468(p0, (*e0).typ, (&tmp0), NIM_FALSE); (*p0).splitdecls += ((NI) 1); expr_541248_839829468(p0, (*e0).kindU.S6.sons->data[((NI) 1)], (&tmp0)); L0 = getlabel_541217_839829468(p0); { TY534811 LOC5; if (!(m0 == ((Tmagic294524) 127))) goto LA3; memset((void*)LOC5, 0, sizeof(LOC5)); LOC5[0] = rdloc_540188_839829468(tmp0); LOC5[1] = L0; linef_534700_839829468(p0, ((Tcprocsection531011) 2), ((NimStringDesc*) &T839829468_297), LOC5, 2); } goto LA1; LA3: ; { TY534811 LOC7; memset((void*)LOC7, 0, sizeof(LOC7)); LOC7[0] = rdloc_540188_839829468(tmp0); LOC7[1] = L0; linef_534700_839829468(p0, ((Tcprocsection531011) 2), ((NimStringDesc*) &T839829468_298), LOC7, 2); } LA1: ; expr_541248_839829468(p0, (*e0).kindU.S6.sons->data[((NI) 2)], (&tmp0)); fixlabel_541230_839829468(p0, L0); { if (!((*d0).k == ((Tlockind294808) 0))) goto LA10; genericAssign((void*)(&(*d0)), (void*)(&tmp0), (&NTI294816)); } goto LA8; LA10: ; { genassignment_541264_839829468(p0, (*d0), tmp0, 0); } LA8: ; (*p0).splitdecls -= ((NI) 1); } N_NIMCALL(void, unaryarith_554646_839829468)(Tcproc531021* p0, Tnode294802* e0, Tloc294816* d0, Tmagic294524 op0) { Tloc294816 a0; Ttype294840* t0; TY537238 LOC1; NI64 LOC2; Ropeobj180006* LOC3; memset((void*)(&a0), 0, sizeof(a0)); t0 = (Ttype294840*)0; initlocexpr_541283_839829468(p0, (*e0).kindU.S6.sons->data[((NI) 1)], (&a0)); t0 = skiptypes_298099_850551059((*e0).typ, IL64(211106233624832)); memset((void*)LOC1, 0, sizeof(LOC1)); LOC1[0] = rdloc_540188_839829468(a0); LOC2 = (NI64)0; LOC2 = getsize_322135_3876443242(t0); LOC1[1] = rope_180401_2381377266((NI64)(LOC2 * IL64(8))); LOC1[2] = getsimpletypedesc_535936_839829468((*p0).module, (*e0).typ); LOC3 = (Ropeobj180006*)0; LOC3 = HEX25_180905_2381377266(unarithtab_554653_839829468[(op0)- 99], LOC1, 3); putintodest_552468_839829468(p0, d0, (*e0).typ, LOC3, ((Tstorageloc294812) 0)); } N_NIMCALL(void, unaryarithoverflow_553633_839829468)(Tcproc531021* p0, Tnode294802* e0, Tloc294816* d0, Tmagic294524 m0) { Tloc294816 a0; Ttype294840* t0; TY534811 LOC7; NI64 LOC8; Ropeobj180006* LOC9; memset((void*)(&a0), 0, sizeof(a0)); t0 = (Ttype294840*)0; initlocexpr_541283_839829468(p0, (*e0).kindU.S6.sons->data[((NI) 1)], (&a0)); t0 = skiptypes_298099_850551059((*e0).typ, IL64(211106233624832)); { TY534811 LOC5; NI64 LOC6; if (!(((*p0).options &(1U<<((NU)(((Toption171009) 5))&31U)))!=0)) goto LA3; memset((void*)LOC5, 0, sizeof(LOC5)); LOC5[0] = rdloc_540188_839829468(a0); LOC6 = (NI64)0; LOC6 = firstord_322001_3876443242(t0); LOC5[1] = intliteral_541270_839829468(LOC6); linefmt_534714_839829468(p0, ((Tcprocsection531011) 2), ((NimStringDesc*) &T839829468_317), LOC5, 2); } LA3: ; memset((void*)LOC7, 0, sizeof(LOC7)); LOC7[0] = rdloc_540188_839829468(a0); LOC8 = (NI64)0; LOC8 = getsize_322135_3876443242(t0); LOC7[1] = rope_180401_2381377266((NI64)(LOC8 * IL64(8))); LOC9 = (Ropeobj180006*)0; LOC9 = HEX25_180905_2381377266(opr_553640_839829468[(m0)- 96], LOC7, 2); putintodest_552468_839829468(p0, d0, (*e0).typ, LOC9, ((Tstorageloc294812) 0)); } N_NIMCALL(void, binaryarith_553819_839829468)(Tcproc531021* p0, Tnode294802* e0, Tloc294816* d0, Tmagic294524 op0) { Tloc294816 a0; Tloc294816 b0; NI64 s0; NI64 LOC1; NI64 LOC2; TY537235 LOC3; Ropeobj180006* LOC4; memset((void*)(&a0), 0, sizeof(a0)); memset((void*)(&b0), 0, sizeof(b0)); s0 = (NI64)0; initlocexpr_541283_839829468(p0, (*e0).kindU.S6.sons->data[((NI) 1)], (&a0)); initlocexpr_541283_839829468(p0, (*e0).kindU.S6.sons->data[((NI) 2)], (&b0)); LOC1 = (NI64)0; LOC1 = getsize_322135_3876443242(a0.t); LOC2 = (NI64)0; LOC2 = getsize_322135_3876443242(b0.t); s0 = (NI64)(((LOC1 >= LOC2) ? LOC1 : LOC2) * IL64(8)); memset((void*)LOC3, 0, sizeof(LOC3)); LOC3[0] = rdloc_540188_839829468(a0); LOC3[1] = rdloc_540188_839829468(b0); LOC3[2] = rope_180401_2381377266(s0); LOC3[3] = getsimpletypedesc_535936_839829468((*p0).module, (*e0).typ); LOC4 = (Ropeobj180006*)0; LOC4 = HEX25_180905_2381377266(binarithtab_553826_839829468[(op0)- 52], LOC3, 4); putintodest_552468_839829468(p0, d0, (*e0).typ, LOC4, ((Tstorageloc294812) 0)); } N_NIMCALL(void, binaryfloatarith_558728_839829468)(Tcproc531021* p0, Tnode294802* e0, Tloc294816* d0, Tmagic294524 m0) { { Tloc294816 a0; Tloc294816 b0; TY537235 LOC5; Tnode294802* LOC6; Ropeobj180006* LOC7; if (!!(((384 & (*p0).options) == 0))) goto LA3; memset((void*)(&a0), 0, sizeof(a0)); memset((void*)(&b0), 0, sizeof(b0)); initlocexpr_541283_839829468(p0, (*e0).kindU.S6.sons->data[((NI) 1)], (&a0)); initlocexpr_541283_839829468(p0, (*e0).kindU.S6.sons->data[((NI) 2)], (&b0)); memset((void*)LOC5, 0, sizeof(LOC5)); LOC5[0] = rope_180277_2381377266(opr_558762_839829468[(m0)- 52]); LOC5[1] = rdloc_540188_839829468(a0); LOC5[2] = rdloc_540188_839829468(b0); LOC6 = (Tnode294802*)0; LOC6 = HEX5BHEX5D_295238_850551059(e0, ((NI) 1)); LOC5[3] = getsimpletypedesc_535936_839829468((*p0).module, (*LOC6).typ); LOC7 = (Ropeobj180006*)0; LOC7 = ropecg_534407_839829468(NIM_NIL, ((NimStringDesc*) &T839829468_319), LOC5, 4); putintodest_552468_839829468(p0, d0, (*e0).typ, LOC7, ((Tstorageloc294812) 0)); { TY180507 LOC12; if (!(((*p0).options &(1U<<((NU)(((Toption171009) 7))&31U)))!=0)) goto LA10; memset((void*)LOC12, 0, sizeof(LOC12)); LOC12[0] = rdloc_540188_839829468((*d0)); linefmt_534714_839829468(p0, ((Tcprocsection531011) 2), ((NimStringDesc*) &T839829468_323), LOC12, 1); } LA10: ; { TY180507 LOC17; if (!(((*p0).options &(1U<<((NU)(((Toption171009) 8))&31U)))!=0)) goto LA15; memset((void*)LOC17, 0, sizeof(LOC17)); LOC17[0] = rdloc_540188_839829468((*d0)); linefmt_534714_839829468(p0, ((Tcprocsection531011) 2), ((NimStringDesc*) &T839829468_324), LOC17, 1); } LA15: ; } goto LA1; LA3: ; { binaryarith_553819_839829468(p0, e0, d0, m0); } LA1: ; } N_NIMCALL(void, geneqproc_554214_839829468)(Tcproc531021* p0, Tnode294802* e0, Tloc294816* d0) { Tloc294816 a0; Tloc294816 b0; memset((void*)(&a0), 0, sizeof(a0)); memset((void*)(&b0), 0, sizeof(b0)); initlocexpr_541283_839829468(p0, (*e0).kindU.S6.sons->data[((NI) 1)], (&a0)); initlocexpr_541283_839829468(p0, (*e0).kindU.S6.sons->data[((NI) 2)], (&b0)); { Ttype294840* LOC3; TY534811 LOC6; Ropeobj180006* LOC7; LOC3 = (Ttype294840*)0; LOC3 = skiptypes_298099_850551059(a0.t, IL64(211106232576256)); if (!((*LOC3).callconv == ((Tcallingconvention294002) 8))) goto LA4; memset((void*)LOC6, 0, sizeof(LOC6)); LOC6[0] = rdloc_540188_839829468(a0); LOC6[1] = rdloc_540188_839829468(b0); LOC7 = (Ropeobj180006*)0; LOC7 = HEX25_180905_2381377266(((NimStringDesc*) &T839829468_352), LOC6, 2); putintodest_552468_839829468(p0, d0, (*e0).typ, LOC7, ((Tstorageloc294812) 0)); } goto LA1; LA4: ; { TY534811 LOC9; Ropeobj180006* LOC10; memset((void*)LOC9, 0, sizeof(LOC9)); LOC9[0] = rdloc_540188_839829468(a0); LOC9[1] = rdloc_540188_839829468(b0); LOC10 = (Ropeobj180006*)0; LOC10 = HEX25_180905_2381377266(((NimStringDesc*) &T839829468_341), LOC9, 2); putintodest_552468_839829468(p0, d0, (*e0).typ, LOC10, ((Tstorageloc294812) 0)); } LA1: ; } N_NIMCALL(Ropeobj180006*, rdcharloc_540227_839829468)(Tloc294816 a0) { Ropeobj180006* result0; result0 = (Ropeobj180006*)0; result0 = rdloc_540188_839829468(a0); { Ttype294840* LOC3; TY180507 LOC6; LOC3 = (Ttype294840*)0; LOC3 = skiptypes_298099_850551059(a0.t, IL64(211106233624832)); if (!((*LOC3).kind == ((Ttypekind294244) 2))) goto LA4; memset((void*)LOC6, 0, sizeof(LOC6)); LOC6[0] = result0; result0 = HEX25_180905_2381377266(((NimStringDesc*) &T839829468_358), LOC6, 1); } LA4: ; return result0; } N_NIMCALL(Ropeobj180006*, binaryarithoverflowraw_553235_839829468)(Tcproc531021* p0, Ttype294840* t0, Tloc294816 a0, Tloc294816 b0, NimStringDesc* frmt0) { Ropeobj180006* result0; NI64 size0; Ropeobj180006* storage0; TY534811 LOC6; TY537238 LOC7; result0 = (Ropeobj180006*)0; size0 = getsize_322135_3876443242(t0); { if (!(size0 < ((NI64) (intsize_178641_4151366050)))) goto LA3; storage0 = rope_180277_2381377266(((NimStringDesc*) &T839829468_36)); } goto LA1; LA3: ; { storage0 = gettypedesc_537671_839829468((*p0).module, t0); } LA1: ; result0 = gettempname_535596_839829468((*p0).module); memset((void*)LOC6, 0, sizeof(LOC6)); LOC6[0] = storage0; LOC6[1] = result0; linefmt_534714_839829468(p0, ((Tcprocsection531011) 0), ((NimStringDesc*) &T839829468_54), LOC6, 2); memset((void*)LOC7, 0, sizeof(LOC7)); LOC7[0] = result0; LOC7[1] = rdcharloc_540227_839829468(a0); LOC7[2] = rdcharloc_540227_839829468(b0); linecg_534707_839829468(p0, ((Tcprocsection531011) 2), frmt0, LOC7, 3); { NIM_BOOL LOC10; TY537238 LOC14; NI64 LOC15; NI64 LOC16; LOC10 = (NIM_BOOL)0; LOC10 = (size0 < ((NI64) (intsize_178641_4151366050))); if (LOC10) goto LA11; LOC10 = ((*t0).kind == ((Ttypekind294244) 20) || (*t0).kind == ((Ttypekind294244) 14)); LA11: ; if (!LOC10) goto LA12; memset((void*)LOC14, 0, sizeof(LOC14)); LOC14[0] = result0; LOC15 = (NI64)0; LOC15 = firstord_322001_3876443242(t0); LOC14[1] = intliteral_541270_839829468(LOC15); LOC16 = (NI64)0; LOC16 = lastord_322004_3876443242(t0); LOC14[2] = intliteral_541270_839829468(LOC16); linefmt_534714_839829468(p0, ((Tcprocsection531011) 2), ((NimStringDesc*) &T839829468_359), LOC14, 3); } LA12: ; return result0; } N_NIMCALL(void, binaryarithoverflow_553262_839829468)(Tcproc531021* p0, Tnode294802* e0, Tloc294816* d0, Tmagic294524 m0) { Tloc294816 a0; Tloc294816 b0; Ttype294840* t0; memset((void*)(&a0), 0, sizeof(a0)); memset((void*)(&b0), 0, sizeof(b0)); initlocexpr_541283_839829468(p0, (*e0).kindU.S6.sons->data[((NI) 1)], (&a0)); initlocexpr_541283_839829468(p0, (*e0).kindU.S6.sons->data[((NI) 2)], (&b0)); t0 = skiptypes_298099_850551059((*e0).typ, IL64(211106233624832)); { Ropeobj180006* res0; TY537238 LOC5; if (!!((((*p0).options &(1U<<((NU)(((Toption171009) 5))&31U)))!=0))) goto LA3; memset((void*)LOC5, 0, sizeof(LOC5)); LOC5[0] = gettypedesc_537671_839829468((*p0).module, t0); LOC5[1] = rdloc_540188_839829468(a0); LOC5[2] = rdloc_540188_839829468(b0); res0 = HEX25_180905_2381377266(opr_553279_839829468[(m0)- 45], LOC5, 3); putintodest_552468_839829468(p0, d0, (*e0).typ, res0, ((Tstorageloc294812) 0)); } goto LA1; LA3: ; { Ropeobj180006* res0; NimStringDesc* LOC7; TY534811 LOC13; Ropeobj180006* LOC14; LOC7 = (NimStringDesc*)0; { if (!((*t0).kind == ((Ttypekind294244) 35))) goto LA10; LOC7 = copyString(prc64_553274_839829468[(m0)- 45]); } goto LA8; LA10: ; { LOC7 = copyString(prc_553269_839829468[(m0)- 45]); } LA8: ; res0 = binaryarithoverflowraw_553235_839829468(p0, t0, a0, b0, LOC7); memset((void*)LOC13, 0, sizeof(LOC13)); LOC13[0] = gettypedesc_537671_839829468((*p0).module, t0); LOC13[1] = res0; LOC14 = (Ropeobj180006*)0; LOC14 = HEX25_180905_2381377266(((NimStringDesc*) &T839829468_370), LOC13, 2); putintodest_552468_839829468(p0, d0, (*e0).typ, LOC14, ((Tstorageloc294812) 0)); } LA1: ; } N_NIMCALL(Ropeobj180006*, lenfield_541305_839829468)(Tcproc531021* p0) { Ropeobj180006* result0; NimStringDesc* LOC1; result0 = (Ropeobj180006*)0; LOC1 = (NimStringDesc*)0; { NIM_BOOL LOC4; LOC4 = (NIM_BOOL)0; LOC4 = (gcmd_171132_2607990831 == ((Tcommands171076) 2)); if (LOC4) goto LA5; LOC4 = (((*(*(*p0).module).module).flags &(1U<<((NU)(((Tsymflag294184) 27))&31U)))!=0); LA5: ; if (!LOC4) goto LA6; LOC1 = copyString(((NimStringDesc*) &T839829468_157)); } goto LA2; LA6: ; { LOC1 = copyString(((NimStringDesc*) &T839829468_158)); } LA2: ; result0 = rope_180277_2381377266(LOC1); return result0; } N_NIMCALL(void, gcusage_556439_839829468)(Tnode294802* n0) { { NimStringDesc* LOC5; if (!(gselectedgc_171133_2607990831 == ((Tgcmode171080) 0))) goto LA3; LOC5 = (NimStringDesc*)0; LOC5 = rendertree_313044_382274130(n0, 0); message_198095_155036129((*n0).info, ((Tmsgkind193002) 263), LOC5); } LA3: ; } N_NIMCALL(void, genrepr_557339_839829468)(Tcproc531021* p0, Tnode294802* e0, Tloc294816* d0) { Tloc294816 a0; Ttype294840* t0; memset((void*)(&a0), 0, sizeof(a0)); initlocexpr_541283_839829468(p0, (*e0).kindU.S6.sons->data[((NI) 1)], (&a0)); t0 = skiptypes_298099_850551059((*(*e0).kindU.S6.sons->data[((NI) 1)]).typ, IL64(211106242013440)); switch ((*t0).kind) { case ((Ttypekind294244) 31) ... ((Ttypekind294244) 35): case ((Ttypekind294244) 40) ... ((Ttypekind294244) 44): { TY180507 LOC2; Ropeobj180006* LOC3; memset((void*)LOC2, 0, sizeof(LOC2)); LOC2[0] = rdloc_540188_839829468(a0); LOC3 = (Ropeobj180006*)0; LOC3 = ropecg_534407_839829468((*p0).module, ((NimStringDesc*) &T839829468_371), LOC2, 1); putintodest_552468_839829468(p0, d0, (*e0).typ, LOC3, a0.s); } break; case ((Ttypekind294244) 36) ... ((Ttypekind294244) 39): { TY180507 LOC5; Ropeobj180006* LOC6; memset((void*)LOC5, 0, sizeof(LOC5)); LOC5[0] = rdloc_540188_839829468(a0); LOC6 = (Ropeobj180006*)0; LOC6 = ropecg_534407_839829468((*p0).module, ((NimStringDesc*) &T839829468_372), LOC5, 1); putintodest_552468_839829468(p0, d0, (*e0).typ, LOC6, a0.s); } break; case ((Ttypekind294244) 1): { TY180507 LOC8; Ropeobj180006* LOC9; memset((void*)LOC8, 0, sizeof(LOC8)); LOC8[0] = rdloc_540188_839829468(a0); LOC9 = (Ropeobj180006*)0; LOC9 = ropecg_534407_839829468((*p0).module, ((NimStringDesc*) &T839829468_373), LOC8, 1); putintodest_552468_839829468(p0, d0, (*e0).typ, LOC9, a0.s); } break; case ((Ttypekind294244) 2): { TY180507 LOC11; Ropeobj180006* LOC12; memset((void*)LOC11, 0, sizeof(LOC11)); LOC11[0] = rdloc_540188_839829468(a0); LOC12 = (Ropeobj180006*)0; LOC12 = ropecg_534407_839829468((*p0).module, ((NimStringDesc*) &T839829468_374), LOC11, 1); putintodest_552468_839829468(p0, d0, (*e0).typ, LOC12, a0.s); } break; case ((Ttypekind294244) 14): case ((Ttypekind294244) 15): { TY534811 LOC14; Ropeobj180006* LOC15; memset((void*)LOC14, 0, sizeof(LOC14)); LOC14[0] = rdloc_540188_839829468(a0); LOC14[1] = gentypeinfo_537941_839829468((*p0).module, t0); LOC15 = (Ropeobj180006*)0; LOC15 = ropecg_534407_839829468((*p0).module, ((NimStringDesc*) &T839829468_375), LOC14, 2); putintodest_552468_839829468(p0, d0, (*e0).typ, LOC15, a0.s); } break; case ((Ttypekind294244) 28): { TY180507 LOC17; Ropeobj180006* LOC18; memset((void*)LOC17, 0, sizeof(LOC17)); LOC17[0] = rdloc_540188_839829468(a0); LOC18 = (Ropeobj180006*)0; LOC18 = ropecg_534407_839829468((*p0).module, ((NimStringDesc*) &T839829468_376), LOC17, 1); putintodest_552468_839829468(p0, d0, (*e0).typ, LOC18, a0.s); } break; case ((Ttypekind294244) 19): { TY534811 LOC20; Ropeobj180006* LOC21; memset((void*)LOC20, 0, sizeof(LOC20)); LOC20[0] = addrloc_540204_839829468(a0); LOC20[1] = gentypeinfo_537941_839829468((*p0).module, t0); LOC21 = (Ropeobj180006*)0; LOC21 = ropecg_534407_839829468((*p0).module, ((NimStringDesc*) &T839829468_377), LOC20, 2); putintodest_552468_839829468(p0, d0, (*e0).typ, LOC21, a0.s); } break; case ((Ttypekind294244) 27): case ((Ttypekind294244) 48): { Tloc294816 b0; TY534811 LOC34; Ttype294840* LOC35; Ropeobj180006* LOC36; memset((void*)(&b0), 0, sizeof(b0)); switch ((*a0.t).kind) { case ((Ttypekind294244) 27): case ((Ttypekind294244) 48): { TY180507 LOC24; Ropeobj180006* LOC25; memset((void*)LOC24, 0, sizeof(LOC24)); LOC24[0] = rdloc_540188_839829468(a0); LOC25 = (Ropeobj180006*)0; LOC25 = HEX25_180905_2381377266(((NimStringDesc*) &T839829468_378), LOC24, 1); putintodest_552468_839829468(p0, (&b0), (*e0).typ, LOC25, a0.s); } break; case ((Ttypekind294244) 28): case ((Ttypekind294244) 24): { TY534811 LOC27; Ropeobj180006* LOC28; memset((void*)LOC27, 0, sizeof(LOC27)); LOC27[0] = rdloc_540188_839829468(a0); LOC27[1] = lenfield_541305_839829468(p0); LOC28 = (Ropeobj180006*)0; LOC28 = HEX25_180905_2381377266(((NimStringDesc*) &T839829468_379), LOC27, 2); putintodest_552468_839829468(p0, (&b0), (*e0).typ, LOC28, a0.s); } break; case ((Ttypekind294244) 16): case ((Ttypekind294244) 4): { TY534811 LOC30; NI64 LOC31; Ropeobj180006* LOC32; memset((void*)LOC30, 0, sizeof(LOC30)); LOC30[0] = rdloc_540188_839829468(a0); LOC31 = (NI64)0; LOC31 = lengthord_322007_3876443242(a0.t); LOC30[1] = rope_180401_2381377266(LOC31); LOC32 = (Ropeobj180006*)0; LOC32 = HEX25_180905_2381377266(((NimStringDesc*) &T839829468_380), LOC30, 2); putintodest_552468_839829468(p0, (&b0), (*e0).typ, LOC32, a0.s); } break; default: { internalerror_198100_155036129((*(*e0).kindU.S6.sons->data[((NI) 0)]).info, ((NimStringDesc*) &T839829468_381)); } break; } memset((void*)LOC34, 0, sizeof(LOC34)); LOC34[0] = rdloc_540188_839829468(b0); LOC35 = (Ttype294840*)0; LOC35 = elemtype_322394_3876443242(t0); LOC34[1] = gentypeinfo_537941_839829468((*p0).module, LOC35); LOC36 = (Ropeobj180006*)0; LOC36 = ropecg_534407_839829468((*p0).module, ((NimStringDesc*) &T839829468_382), LOC34, 2); putintodest_552468_839829468(p0, d0, (*e0).typ, LOC36, a0.s); } break; case ((Ttypekind294244) 29): case ((Ttypekind294244) 16): case ((Ttypekind294244) 4): case ((Ttypekind294244) 22): case ((Ttypekind294244) 21): case ((Ttypekind294244) 26): case ((Ttypekind294244) 5): case ((Ttypekind294244) 24): { TY534811 LOC38; Ropeobj180006* LOC39; memset((void*)LOC38, 0, sizeof(LOC38)); LOC38[0] = rdloc_540188_839829468(a0); LOC38[1] = gentypeinfo_537941_839829468((*p0).module, t0); LOC39 = (Ropeobj180006*)0; LOC39 = ropecg_534407_839829468((*p0).module, ((NimStringDesc*) &T839829468_383), LOC38, 2); putintodest_552468_839829468(p0, d0, (*e0).typ, LOC39, a0.s); } break; case ((Ttypekind294244) 3): case ((Ttypekind294244) 62): { localerror_198085_155036129((*e0).info, ((NimStringDesc*) &T839829468_384)); } break; default: { TY534811 LOC42; Ropeobj180006* LOC43; memset((void*)LOC42, 0, sizeof(LOC42)); LOC42[0] = addrloc_540204_839829468(a0); LOC42[1] = gentypeinfo_537941_839829468((*p0).module, t0); LOC43 = (Ropeobj180006*)0; LOC43 = ropecg_534407_839829468((*p0).module, ((NimStringDesc*) &T839829468_383), LOC42, 2); putintodest_552468_839829468(p0, d0, (*e0).typ, LOC43, a0.s); } break; } gcusage_556439_839829468(e0); } N_NIMCALL(void, gengettypeinfo_557383_839829468)(Tcproc531021* p0, Tnode294802* e0, Tloc294816* d0) { Ttype294840* t0; Ropeobj180006* LOC1; t0 = skiptypes_298099_850551059((*(*e0).kindU.S6.sons->data[((NI) 1)]).typ, IL64(211106242013440)); LOC1 = (Ropeobj180006*)0; LOC1 = gentypeinfo_537941_839829468((*p0).module, t0); putintodest_552468_839829468(p0, d0, (*e0).typ, LOC1, ((Tstorageloc294812) 0)); } N_NIMCALL(void, genswap_557638_839829468)(Tcproc531021* p0, Tnode294802* e0, Tloc294816* d0) { Tloc294816 a0; Tloc294816 b0; Tloc294816 tmp0; Ttype294840* LOC1; memset((void*)(&a0), 0, sizeof(a0)); memset((void*)(&b0), 0, sizeof(b0)); memset((void*)(&tmp0), 0, sizeof(tmp0)); LOC1 = (Ttype294840*)0; LOC1 = skiptypes_298099_850551059((*(*e0).kindU.S6.sons->data[((NI) 1)]).typ, IL64(211106240964864)); gettemp_539032_839829468(p0, LOC1, (&tmp0), NIM_FALSE); initlocexpr_541283_839829468(p0, (*e0).kindU.S6.sons->data[((NI) 1)], (&a0)); initlocexpr_541283_839829468(p0, (*e0).kindU.S6.sons->data[((NI) 2)], (&b0)); genassignment_541264_839829468(p0, tmp0, a0, 0); genassignment_541264_839829468(p0, a0, b0, 0); genassignment_541264_839829468(p0, b0, tmp0, 0); } N_NIMCALL(void, unaryexpr_553209_839829468)(Tcproc531021* p0, Tnode294802* e0, Tloc294816* d0, NimStringDesc* frmt0) { Tloc294816 a0; TY180507 LOC1; Ropeobj180006* LOC2; memset((void*)(&a0), 0, sizeof(a0)); initlocexpr_541283_839829468(p0, (*e0).kindU.S6.sons->data[((NI) 1)], (&a0)); memset((void*)LOC1, 0, sizeof(LOC1)); LOC1[0] = rdloc_540188_839829468(a0); LOC2 = (Ropeobj180006*)0; LOC2 = ropecg_534407_839829468((*p0).module, frmt0, LOC1, 1); putintodest_552468_839829468(p0, d0, (*e0).typ, LOC2, ((Tstorageloc294812) 0)); } N_NIMCALL(void, binarystmt_552501_839829468)(Tcproc531021* p0, Tnode294802* e0, Tloc294816* d0, NimStringDesc* frmt0) { Tloc294816 a0; Tloc294816 b0; TY534811 LOC5; memset((void*)(&a0), 0, sizeof(a0)); memset((void*)(&b0), 0, sizeof(b0)); { if (!!(((*d0).k == ((Tlockind294808) 0)))) goto LA3; internalerror_198100_155036129((*e0).info, ((NimStringDesc*) &T839829468_387)); } LA3: ; initlocexpr_541283_839829468(p0, (*e0).kindU.S6.sons->data[((NI) 1)], (&a0)); initlocexpr_541283_839829468(p0, (*e0).kindU.S6.sons->data[((NI) 2)], (&b0)); memset((void*)LOC5, 0, sizeof(LOC5)); LOC5[0] = rdloc_540188_839829468(a0); LOC5[1] = rdloc_540188_839829468(b0); linecg_534707_839829468(p0, ((Tcprocsection531011) 2), frmt0, LOC5, 2); } N_NIMCALL(void, genstrconcat_556452_839829468)(Tcproc531021* p0, Tnode294802* e0, Tloc294816* d0) { Tloc294816 a0; Tloc294816 tmp0; NI L0; Ropeobj180006* appends0; Ropeobj180006* lens0; TY537238 LOC21; Ropeobj180006** LOC22; memset((void*)(&a0), 0, sizeof(a0)); memset((void*)(&tmp0), 0, sizeof(tmp0)); gettemp_539032_839829468(p0, (*e0).typ, (&tmp0), NIM_FALSE); L0 = ((NI) 0); appends0 = NIM_NIL; lens0 = NIM_NIL; { NI i_556475_839829468; NI HEX3Atmp_556547_839829468; NI LOC2; NI res_556550_839829468; i_556475_839829468 = (NI)0; HEX3Atmp_556547_839829468 = (NI)0; LOC2 = (NI)0; LOC2 = sonslen_297351_850551059(e0); HEX3Atmp_556547_839829468 = (NI)(LOC2 - ((NI) 2)); res_556550_839829468 = ((NI) 0); { while (1) { if (!(res_556550_839829468 <= HEX3Atmp_556547_839829468)) goto LA4; i_556475_839829468 = res_556550_839829468; initlocexpr_541283_839829468(p0, (*e0).kindU.S6.sons->data[(NI)(i_556475_839829468 + ((NI) 1))], (&a0)); { Ttype294840* LOC7; TY534811 LOC10; Ropeobj180006* LOC11; LOC7 = (Ttype294840*)0; LOC7 = skiptypes_298099_850551059((*(*e0).kindU.S6.sons->data[(NI)(i_556475_839829468 + ((NI) 1))]).typ, IL64(211106242013440)); if (!((*LOC7).kind == ((Ttypekind294244) 2))) goto LA8; L0 += ((NI) 1); memset((void*)LOC10, 0, sizeof(LOC10)); LOC10[0] = tmp0.r; LOC10[1] = rdloc_540188_839829468(a0); LOC11 = (Ropeobj180006*)0; LOC11 = ropecg_534407_839829468((*p0).module, ((NimStringDesc*) &T839829468_390), LOC10, 2); add_180482_2381377266(&appends0, LOC11); } goto LA5; LA8: ; { TY534811 LOC19; Ropeobj180006* LOC20; { if (!((*(*e0).kindU.S6.sons->data[(NI)(i_556475_839829468 + ((NI) 1))]).kind >= ((Tnodekind294020) 20) && (*(*e0).kindU.S6.sons->data[(NI)(i_556475_839829468 + ((NI) 1))]).kind <= ((Tnodekind294020) 22))) goto LA15; L0 += ((*(*e0).kindU.S6.sons->data[(NI)(i_556475_839829468 + ((NI) 1))]).kindU.S3.strval ? (*(*e0).kindU.S6.sons->data[(NI)(i_556475_839829468 + ((NI) 1))]).kindU.S3.strval->Sup.len : 0); } goto LA13; LA15: ; { TY534811 LOC18; memset((void*)LOC18, 0, sizeof(LOC18)); LOC18[0] = rdloc_540188_839829468(a0); LOC18[1] = lenfield_541305_839829468(p0); addf_181205_2381377266(&lens0, ((NimStringDesc*) &T839829468_391), LOC18, 2); } LA13: ; memset((void*)LOC19, 0, sizeof(LOC19)); LOC19[0] = tmp0.r; LOC19[1] = rdloc_540188_839829468(a0); LOC20 = (Ropeobj180006*)0; LOC20 = ropecg_534407_839829468((*p0).module, ((NimStringDesc*) &T839829468_392), LOC19, 2); add_180482_2381377266(&appends0, LOC20); } LA5: ; res_556550_839829468 += ((NI) 1); } LA4: ; } } memset((void*)LOC21, 0, sizeof(LOC21)); LOC21[0] = tmp0.r; LOC21[1] = lens0; LOC21[2] = rope_180401_2381377266(((NI64) (L0))); linefmt_534714_839829468(p0, ((Tcprocsection531011) 2), ((NimStringDesc*) &T839829468_393), LOC21, 3); LOC22 = (Ropeobj180006**)0; LOC22 = s_531179_3723162438(p0, ((Tcprocsection531011) 2)); add_180482_2381377266(LOC22, appends0); { if (!((*d0).k == ((Tlockind294808) 0))) goto LA25; genericAssign((void*)(&(*d0)), (void*)(&tmp0), (&NTI294816)); } goto LA23; LA25: ; { genassignment_541264_839829468(p0, (*d0), tmp0, 0); } LA23: ; gcusage_556439_839829468(e0); } N_NIMCALL(void, genstrappend_556554_839829468)(Tcproc531021* p0, Tnode294802* e0, Tloc294816* d0) { Tloc294816 a0; Tloc294816 dest0; Ropeobj180006* appends0; Ropeobj180006* lens0; NI L0; TY537238 LOC21; Ropeobj180006** LOC22; memset((void*)(&a0), 0, sizeof(a0)); memset((void*)(&dest0), 0, sizeof(dest0)); appends0 = (Ropeobj180006*)0; lens0 = (Ropeobj180006*)0; L0 = ((NI) 0); initlocexpr_541283_839829468(p0, (*e0).kindU.S6.sons->data[((NI) 1)], (&dest0)); { NI i_556615_839829468; NI HEX3Atmp_556676_839829468; NI LOC2; NI res_556679_839829468; i_556615_839829468 = (NI)0; HEX3Atmp_556676_839829468 = (NI)0; LOC2 = (NI)0; LOC2 = sonslen_297351_850551059(e0); HEX3Atmp_556676_839829468 = (NI)(LOC2 - ((NI) 3)); res_556679_839829468 = ((NI) 0); { while (1) { if (!(res_556679_839829468 <= HEX3Atmp_556676_839829468)) goto LA4; i_556615_839829468 = res_556679_839829468; initlocexpr_541283_839829468(p0, (*e0).kindU.S6.sons->data[(NI)(i_556615_839829468 + ((NI) 2))], (&a0)); { Ttype294840* LOC7; TY534811 LOC10; Ropeobj180006* LOC11; LOC7 = (Ttype294840*)0; LOC7 = skiptypes_298099_850551059((*(*e0).kindU.S6.sons->data[(NI)(i_556615_839829468 + ((NI) 2))]).typ, IL64(211106242013440)); if (!((*LOC7).kind == ((Ttypekind294244) 2))) goto LA8; L0 += ((NI) 1); memset((void*)LOC10, 0, sizeof(LOC10)); LOC10[0] = rdloc_540188_839829468(dest0); LOC10[1] = rdloc_540188_839829468(a0); LOC11 = (Ropeobj180006*)0; LOC11 = ropecg_534407_839829468((*p0).module, ((NimStringDesc*) &T839829468_390), LOC10, 2); add_180482_2381377266(&appends0, LOC11); } goto LA5; LA8: ; { TY534811 LOC19; Ropeobj180006* LOC20; { if (!((*(*e0).kindU.S6.sons->data[(NI)(i_556615_839829468 + ((NI) 2))]).kind >= ((Tnodekind294020) 20) && (*(*e0).kindU.S6.sons->data[(NI)(i_556615_839829468 + ((NI) 2))]).kind <= ((Tnodekind294020) 22))) goto LA15; L0 += ((*(*e0).kindU.S6.sons->data[(NI)(i_556615_839829468 + ((NI) 2))]).kindU.S3.strval ? (*(*e0).kindU.S6.sons->data[(NI)(i_556615_839829468 + ((NI) 2))]).kindU.S3.strval->Sup.len : 0); } goto LA13; LA15: ; { TY534811 LOC18; memset((void*)LOC18, 0, sizeof(LOC18)); LOC18[0] = rdloc_540188_839829468(a0); LOC18[1] = lenfield_541305_839829468(p0); addf_181205_2381377266(&lens0, ((NimStringDesc*) &T839829468_391), LOC18, 2); } LA13: ; memset((void*)LOC19, 0, sizeof(LOC19)); LOC19[0] = rdloc_540188_839829468(dest0); LOC19[1] = rdloc_540188_839829468(a0); LOC20 = (Ropeobj180006*)0; LOC20 = ropecg_534407_839829468((*p0).module, ((NimStringDesc*) &T839829468_392), LOC19, 2); add_180482_2381377266(&appends0, LOC20); } LA5: ; res_556679_839829468 += ((NI) 1); } LA4: ; } } memset((void*)LOC21, 0, sizeof(LOC21)); LOC21[0] = rdloc_540188_839829468(dest0); LOC21[1] = lens0; LOC21[2] = rope_180401_2381377266(((NI64) (L0))); linefmt_534714_839829468(p0, ((Tcprocsection531011) 2), ((NimStringDesc*) &T839829468_395), LOC21, 3); LOC22 = (Ropeobj180006**)0; LOC22 = s_531179_3723162438(p0, ((Tcprocsection531011) 2)); add_180482_2381377266(LOC22, appends0); gcusage_556439_839829468(e0); } N_NIMCALL(void, genseqelemappend_556683_839829468)(Tcproc531021* p0, Tnode294802* e0, Tloc294816* d0) { NimStringDesc* seqappendpattern0; Tloc294816 a0; Tloc294816 b0; Tloc294816 dest0; Ttype294840* bt0; TY537238 LOC8; Ttype294840* LOC9; TY534811 LOC10; TY534811 LOC11; { NIM_BOOL LOC3; LOC3 = (NIM_BOOL)0; LOC3 = (gcmd_171132_2607990831 == ((Tcommands171076) 2)); if (LOC3) goto LA4; LOC3 = (((*(*(*p0).module).module).flags &(1U<<((NU)(((Tsymflag294184) 27))&31U)))!=0); LA4: ; if (!!(LOC3)) goto LA5; seqappendpattern0 = copyString(((NimStringDesc*) &T839829468_396)); } goto LA1; LA5: ; { seqappendpattern0 = copyString(((NimStringDesc*) &T839829468_397)); } LA1: ; memset((void*)(&a0), 0, sizeof(a0)); memset((void*)(&b0), 0, sizeof(b0)); memset((void*)(&dest0), 0, sizeof(dest0)); initlocexpr_541283_839829468(p0, (*e0).kindU.S6.sons->data[((NI) 1)], (&a0)); initlocexpr_541283_839829468(p0, (*e0).kindU.S6.sons->data[((NI) 2)], (&b0)); bt0 = skiptypes_298099_850551059((*(*e0).kindU.S6.sons->data[((NI) 2)]).typ, IL64(211106240964864)); memset((void*)LOC8, 0, sizeof(LOC8)); LOC8[0] = rdloc_540188_839829468(a0); LOC9 = (Ttype294840*)0; LOC9 = skiptypes_298099_850551059((*(*e0).kindU.S6.sons->data[((NI) 1)]).typ, IL64(211106240964864)); LOC8[1] = gettypedesc_537671_839829468((*p0).module, LOC9); LOC8[2] = gettypedesc_537671_839829468((*p0).module, bt0); linecg_534707_839829468(p0, ((Tcprocsection531011) 2), seqappendpattern0, LOC8, 3); initloc_534273_839829468((&dest0), ((Tlockind294808) 6), bt0, ((Tstorageloc294812) 3)); memset((void*)LOC10, 0, sizeof(LOC10)); LOC10[0] = rdloc_540188_839829468(a0); LOC10[1] = lenfield_541305_839829468(p0); dest0.r = ropecg_534407_839829468(NIM_NIL, ((NimStringDesc*) &T839829468_398), LOC10, 2); genassignment_541264_839829468(p0, dest0, b0, 3); memset((void*)LOC11, 0, sizeof(LOC11)); LOC11[0] = rdloc_540188_839829468(a0); LOC11[1] = lenfield_541305_839829468(p0); linecg_534707_839829468(p0, ((Tcprocsection531011) 2), ((NimStringDesc*) &T839829468_399), LOC11, 2); gcusage_556439_839829468(e0); } N_NIMCALL(void, binaryexpr_552549_839829468)(Tcproc531021* p0, Tnode294802* e0, Tloc294816* d0, NimStringDesc* frmt0) { Tloc294816 a0; Tloc294816 b0; TY534811 LOC1; Ropeobj180006* LOC2; memset((void*)(&a0), 0, sizeof(a0)); memset((void*)(&b0), 0, sizeof(b0)); initlocexpr_541283_839829468(p0, (*e0).kindU.S6.sons->data[((NI) 1)], (&a0)); initlocexpr_541283_839829468(p0, (*e0).kindU.S6.sons->data[((NI) 2)], (&b0)); memset((void*)LOC1, 0, sizeof(LOC1)); LOC1[0] = rdloc_540188_839829468(a0); LOC1[1] = rdloc_540188_839829468(b0); LOC2 = (Ropeobj180006*)0; LOC2 = ropecg_534407_839829468((*p0).module, frmt0, LOC1, 2); putintodest_552468_839829468(p0, d0, (*e0).typ, LOC2, ((Tstorageloc294812) 0)); } N_NIMCALL(void, genstrequals_558666_839829468)(Tcproc531021* p0, Tnode294802* e0, Tloc294816* d0) { Tloc294816 x0; Tnode294802* a0; Tnode294802* b0; memset((void*)(&x0), 0, sizeof(x0)); a0 = (*e0).kindU.S6.sons->data[((NI) 1)]; b0 = (*e0).kindU.S6.sons->data[((NI) 2)]; { NIM_BOOL LOC3; LOC3 = (NIM_BOOL)0; LOC3 = ((*a0).kind == ((Tnodekind294020) 23)); if (LOC3) goto LA4; LOC3 = ((*b0).kind == ((Tnodekind294020) 23)); LA4: ; if (!LOC3) goto LA5; binaryexpr_552549_839829468(p0, e0, d0, ((NimStringDesc*) &T839829468_341)); } goto LA1; LA5: ; { NIM_BOOL LOC8; TY534811 LOC12; Ropeobj180006* LOC13; LOC8 = (NIM_BOOL)0; LOC8 = ((*a0).kind >= ((Tnodekind294020) 20) && (*a0).kind <= ((Tnodekind294020) 22)); if (!(LOC8)) goto LA9; LOC8 = (((*a0).kindU.S3.strval) && ((*a0).kindU.S3.strval)->Sup.len == 0); LA9: ; if (!LOC8) goto LA10; initlocexpr_541283_839829468(p0, (*e0).kindU.S6.sons->data[((NI) 2)], (&x0)); memset((void*)LOC12, 0, sizeof(LOC12)); LOC12[0] = rdloc_540188_839829468(x0); LOC12[1] = lenfield_541305_839829468(p0); LOC13 = (Ropeobj180006*)0; LOC13 = ropecg_534407_839829468(NIM_NIL, ((NimStringDesc*) &T839829468_400), LOC12, 2); putintodest_552468_839829468(p0, d0, (*e0).typ, LOC13, ((Tstorageloc294812) 0)); } goto LA1; LA10: ; { NIM_BOOL LOC15; TY534811 LOC19; Ropeobj180006* LOC20; LOC15 = (NIM_BOOL)0; LOC15 = ((*b0).kind >= ((Tnodekind294020) 20) && (*b0).kind <= ((Tnodekind294020) 22)); if (!(LOC15)) goto LA16; LOC15 = (((*b0).kindU.S3.strval) && ((*b0).kindU.S3.strval)->Sup.len == 0); LA16: ; if (!LOC15) goto LA17; initlocexpr_541283_839829468(p0, (*e0).kindU.S6.sons->data[((NI) 1)], (&x0)); memset((void*)LOC19, 0, sizeof(LOC19)); LOC19[0] = rdloc_540188_839829468(x0); LOC19[1] = lenfield_541305_839829468(p0); LOC20 = (Ropeobj180006*)0; LOC20 = ropecg_534407_839829468(NIM_NIL, ((NimStringDesc*) &T839829468_400), LOC19, 2); putintodest_552468_839829468(p0, d0, (*e0).typ, LOC20, ((Tstorageloc294812) 0)); } goto LA1; LA17: ; { binaryexpr_552549_839829468(p0, e0, d0, ((NimStringDesc*) &T839829468_401)); } LA1: ; } N_NIMCALL(void, genisnil_554620_839829468)(Tcproc531021* p0, Tnode294802* e0, Tloc294816* d0) { Ttype294840* t0; t0 = skiptypes_298099_850551059((*(*e0).kindU.S6.sons->data[((NI) 1)]).typ, IL64(211106233624832)); { NIM_BOOL LOC3; LOC3 = (NIM_BOOL)0; LOC3 = ((*t0).kind == ((Ttypekind294244) 25)); if (!(LOC3)) goto LA4; LOC3 = ((*t0).callconv == ((Tcallingconvention294002) 8)); LA4: ; if (!LOC3) goto LA5; unaryexpr_553209_839829468(p0, e0, d0, ((NimStringDesc*) &T839829468_404)); } goto LA1; LA5: ; { unaryexpr_553209_839829468(p0, e0, d0, ((NimStringDesc*) &T839829468_405)); } LA1: ; } N_NIMCALL(void, gendollar_557391_839829468)(Tcproc531021* p0, Tnode294802* n0, Tloc294816* d0, NimStringDesc* frmt0) { Tloc294816 a0; TY180507 LOC1; memset((void*)(&a0), 0, sizeof(a0)); initlocexpr_541283_839829468(p0, (*n0).kindU.S6.sons->data[((NI) 1)], (&a0)); memset((void*)LOC1, 0, sizeof(LOC1)); LOC1[0] = rdloc_540188_839829468(a0); a0.r = ropecg_534407_839829468((*p0).module, frmt0, LOC1, 1); { if (!((*d0).k == ((Tlockind294808) 0))) goto LA4; gettemp_539032_839829468(p0, (*n0).typ, d0, NIM_FALSE); } LA4: ; genassignment_541264_839829468(p0, (*d0), a0, 0); gcusage_556439_839829468(n0); } N_NIMCALL(Ropeobj180006*, genofhelper_557139_839829468)(Tcproc531021* p0, Ttype294840* dest0, Ropeobj180006* a0) { Ropeobj180006* result0; Ropeobj180006* ti0; result0 = (Ropeobj180006*)0; ti0 = gentypeinfo_537941_839829468((*p0).module, dest0); { NIM_BOOL LOC3; NIM_BOOL LOC5; TY534811 LOC9; LOC3 = (NIM_BOOL)0; LOC3 = (((*dest0).flags &(1U<<((NU)(((Ttypeflag294431) 2))&31U)))!=0); if (LOC3) goto LA4; LOC5 = (NIM_BOOL)0; LOC5 = (((*(*p0).module).flags &(1U<<((NU)(((Codegenflag531025) 5))&7U)))!=0); if (!(LOC5)) goto LA6; LOC5 = !((((*dest0).flags &(1U<<((NU)(((Ttypeflag294431) 5))&31U)))!=0)); LA6: ; LOC3 = LOC5; LA4: ; if (!LOC3) goto LA7; memset((void*)LOC9, 0, sizeof(LOC9)); LOC9[0] = a0; LOC9[1] = ti0; result0 = HEX25_180905_2381377266(((NimStringDesc*) &T839829468_414), LOC9, 2); } goto LA1; LA7: ; { Ropeobj180006* LOC11; Ropeobj180006* cache0; Ropeobj180006* LOC12; TY180507 LOC13; TY537238 LOC14; LOC11 = (Ropeobj180006*)0; LOC11 = cgsym_534403_839829468((*p0).module, ((NimStringDesc*) &T839829468_129)); (*(*p0).module).labels += ((NI) 1); LOC12 = (Ropeobj180006*)0; LOC12 = rope_180401_2381377266(((NI64) ((*(*p0).module).labels))); cache0 = HEX26_180452_2381377266(((NimStringDesc*) &T839829468_415), LOC12); memset((void*)LOC13, 0, sizeof(LOC13)); LOC13[0] = cache0; addf_181205_2381377266(&(*(*p0).module).s[(((Tcfilesection531005) 9))- 0], ((NimStringDesc*) &T839829468_416), LOC13, 1); memset((void*)LOC14, 0, sizeof(LOC14)); LOC14[0] = a0; LOC14[1] = ti0; LOC14[2] = cache0; result0 = ropecg_534407_839829468((*p0).module, ((NimStringDesc*) &T839829468_417), LOC14, 3); } LA1: ; return result0; } N_NIMCALL(void, genof_557201_839829468)(Tcproc531021* p0, Tnode294802* x0, Ttype294840* typ0, Tloc294816* d0) { Tloc294816 a0; Ttype294840* dest0; Ropeobj180006* r0; Ropeobj180006* nilcheck0; Ttype294840* t0; Ttype294840* LOC41; memset((void*)(&a0), 0, sizeof(a0)); initlocexpr_541283_839829468(p0, x0, (&a0)); dest0 = skiptypes_298099_850551059(typ0, IL64(211106247256320)); r0 = rdloc_540188_839829468(a0); nilcheck0 = NIM_NIL; t0 = skiptypes_298099_850551059(a0.t, IL64(211106232576256)); { while (1) { Ttype294840* LOC16; if (!((*t0).kind == ((Ttypekind294244) 23) || (*t0).kind == ((Ttypekind294244) 21) || (*t0).kind == ((Ttypekind294244) 22))) goto LA2; { if (!!(((*t0).kind == ((Ttypekind294244) 23)))) goto LA5; nilcheck0 = r0; } LA5: ; { NIM_BOOL LOC9; NIM_BOOL LOC11; TY180507 LOC15; LOC9 = (NIM_BOOL)0; LOC9 = !(((*t0).kind == ((Ttypekind294244) 23))); if (LOC9) goto LA10; LOC11 = (NIM_BOOL)0; LOC11 = (gcmd_171132_2607990831 == ((Tcommands171076) 2)); if (LOC11) goto LA12; LOC11 = (((*(*(*p0).module).module).flags &(1U<<((NU)(((Tsymflag294184) 27))&31U)))!=0); LA12: ; LOC9 = !(LOC11); LA10: ; if (!LOC9) goto LA13; memset((void*)LOC15, 0, sizeof(LOC15)); LOC15[0] = r0; r0 = ropecg_534407_839829468(NIM_NIL, ((NimStringDesc*) &T839829468_124), LOC15, 1); } LA13: ; LOC16 = (Ttype294840*)0; LOC16 = lastson_297377_850551059(t0); t0 = skiptypes_298099_850551059(LOC16, IL64(211106232576256)); } LA2: ; } { NIM_BOOL LOC19; LOC19 = (NIM_BOOL)0; LOC19 = (gcmd_171132_2607990831 == ((Tcommands171076) 2)); if (LOC19) goto LA20; LOC19 = (((*(*(*p0).module).module).flags &(1U<<((NU)(((Tsymflag294184) 27))&31U)))!=0); LA20: ; if (!!(LOC19)) goto LA21; { while (1) { NIM_BOOL LOC25; TY535289 LOC27; Ropeobj180006* LOC28; LOC25 = (NIM_BOOL)0; LOC25 = ((*t0).kind == ((Ttypekind294244) 17)); if (!(LOC25)) goto LA26; LOC25 = !(((*t0).sons->data[((NI) 0)] == NIM_NIL)); LA26: ; if (!LOC25) goto LA24; memset((void*)LOC27, 0, sizeof(LOC27)); LOC28 = (Ropeobj180006*)0; LOC28 = HEX25_180905_2381377266(((NimStringDesc*) &T839829468_153), LOC27, 0); add_180482_2381377266(&r0, LOC28); t0 = skiptypes_298099_850551059((*t0).sons->data[((NI) 0)], IL64(211106247215360)); } LA24: ; } } LA21: ; { NIM_BOOL LOC31; LOC31 = (NIM_BOOL)0; LOC31 = isobjlackingtypefield_535513_839829468(t0); if (!LOC31) goto LA32; globalerror_198071_155036129((*x0).info, ((Tmsgkind193002) 4), ((NimStringDesc*) &T839829468_412)); } LA32: ; { TY534811 LOC38; if (!!((nilcheck0 == NIM_NIL))) goto LA36; memset((void*)LOC38, 0, sizeof(LOC38)); LOC38[0] = nilcheck0; LOC38[1] = genofhelper_557139_839829468(p0, dest0, r0); r0 = ropecg_534407_839829468((*p0).module, ((NimStringDesc*) &T839829468_413), LOC38, 2); } goto LA34; LA36: ; { TY180507 LOC40; memset((void*)LOC40, 0, sizeof(LOC40)); LOC40[0] = genofhelper_557139_839829468(p0, dest0, r0); r0 = ropecg_534407_839829468((*p0).module, ((NimStringDesc*) &T839829468_418), LOC40, 1); } LA34: ; LOC41 = (Ttype294840*)0; LOC41 = getsystype_340150_3937434831(((Ttypekind294244) 1)); putintodest_552468_839829468(p0, d0, LOC41, r0, a0.s); } N_NIMCALL(void, genof_557331_839829468)(Tcproc531021* p0, Tnode294802* n0, Tloc294816* d0) { genof_557201_839829468(p0, (*n0).kindU.S6.sons->data[((NI) 1)], (*(*n0).kindU.S6.sons->data[((NI) 2)]).typ, d0); } N_NIMCALL(void, rawgennew_556741_839829468)(Tcproc531021* p0, Tloc294816 a0, Ropeobj180006* sizeexpr_556745_839829468) { Ropeobj180006* sizeexpr0; Ttype294840* reftype0; Tloc294816 b0; TY537238 args0; Ttype294840* bt0; sizeexpr0 = sizeexpr_556745_839829468; reftype0 = skiptypes_298099_850551059(a0.t, IL64(211106242013440)); memset((void*)(&b0), 0, sizeof(b0)); initloc_534273_839829468((&b0), ((Tlockind294808) 6), a0.t, ((Tstorageloc294812) 3)); { TY180507 LOC5; Ttype294840* LOC6; if (!sizeexpr0 == 0) goto LA3; memset((void*)LOC5, 0, sizeof(LOC5)); LOC6 = (Ttype294840*)0; LOC6 = skiptypes_298099_850551059((*reftype0).sons->data[((NI) 0)], IL64(211106233624832)); LOC5[0] = gettypedesc_537671_839829468((*p0).module, LOC6); sizeexpr0 = HEX25_180905_2381377266(((NimStringDesc*) &T839829468_419), LOC5, 1); } LA3: ; memset((void*)args0, 0, sizeof(args0)); args0[0] = gettypedesc_537671_839829468((*p0).module, reftype0); args0[1] = gentypeinfo_537941_839829468((*p0).module, reftype0); args0[2] = sizeexpr0; { NIM_BOOL LOC9; TY534811 LOC21; LOC9 = (NIM_BOOL)0; LOC9 = (a0.s == ((Tstorageloc294812) 3)); if (!(LOC9)) goto LA10; LOC9 = usesnativegc_171177_2607990831(); LA10: ; if (!LOC9) goto LA11; { NIM_BOOL LOC15; TY180507 LOC18; LOC15 = (NIM_BOOL)0; LOC15 = canformacycle_322123_3876443242(a0.t); if (!LOC15) goto LA16; memset((void*)LOC18, 0, sizeof(LOC18)); LOC18[0] = rdloc_540188_839829468(a0); linefmt_534714_839829468(p0, ((Tcprocsection531011) 2), ((NimStringDesc*) &T839829468_420), LOC18, 1); } goto LA13; LA16: ; { TY180507 LOC20; memset((void*)LOC20, 0, sizeof(LOC20)); LOC20[0] = rdloc_540188_839829468(a0); linefmt_534714_839829468(p0, ((Tcprocsection531011) 2), ((NimStringDesc*) &T839829468_255), LOC20, 1); } LA13: ; b0.r = ropecg_534407_839829468((*p0).module, ((NimStringDesc*) &T839829468_421), args0, 3); memset((void*)LOC21, 0, sizeof(LOC21)); LOC21[0] = rdloc_540188_839829468(a0); LOC21[1] = rdloc_540188_839829468(b0); linefmt_534714_839829468(p0, ((Tcprocsection531011) 2), ((NimStringDesc*) &T839829468_123), LOC21, 2); } goto LA7; LA11: ; { b0.r = ropecg_534407_839829468((*p0).module, ((NimStringDesc*) &T839829468_422), args0, 3); genassignment_541264_839829468(p0, a0, b0, 0); } LA7: ; bt0 = skiptypes_298099_850551059((*reftype0).sons->data[((NI) 0)], IL64(211106233624832)); genobjectinit_540242_839829468(p0, ((Tcprocsection531011) 2), bt0, a0, NIM_FALSE); } N_NIMCALL(void, gennew_556782_839829468)(Tcproc531021* p0, Tnode294802* e0) { Tloc294816 a0; memset((void*)(&a0), 0, sizeof(a0)); initlocexpr_541283_839829468(p0, (*e0).kindU.S6.sons->data[((NI) 1)], (&a0)); { NI LOC3; Tloc294816 se0; Ropeobj180006* LOC6; LOC3 = (NI)0; LOC3 = len_295081_850551059(e0); if (!(LOC3 == ((NI) 3))) goto LA4; memset((void*)(&se0), 0, sizeof(se0)); initlocexpr_541283_839829468(p0, (*e0).kindU.S6.sons->data[((NI) 2)], (&se0)); LOC6 = (Ropeobj180006*)0; LOC6 = rdloc_540188_839829468(se0); rawgennew_556741_839829468(p0, a0, LOC6); } goto LA1; LA4: ; { rawgennew_556741_839829468(p0, a0, NIM_NIL); } LA1: ; gcusage_556439_839829468(e0); } N_NIMCALL(void, gennewfinalize_557110_839829468)(Tcproc531021* p0, Tnode294802* e0) { Tloc294816 a0; Tloc294816 b0; Tloc294816 f0; Ttype294840* reftype0; Ttype294840* bt0; Ropeobj180006* ti0; TY534811 LOC1; TY537238 LOC2; Ttype294840* LOC3; Ttype294840* LOC4; Ttype294840* LOC5; memset((void*)(&a0), 0, sizeof(a0)); memset((void*)(&b0), 0, sizeof(b0)); memset((void*)(&f0), 0, sizeof(f0)); reftype0 = (Ttype294840*)0; bt0 = (Ttype294840*)0; ti0 = (Ropeobj180006*)0; reftype0 = skiptypes_298099_850551059((*(*e0).kindU.S6.sons->data[((NI) 1)]).typ, IL64(211106242013440)); initlocexpr_541283_839829468(p0, (*e0).kindU.S6.sons->data[((NI) 1)], (&a0)); initlocexpr_541283_839829468(p0, (*e0).kindU.S6.sons->data[((NI) 2)], (&f0)); initloc_534273_839829468((&b0), ((Tlockind294808) 6), a0.t, ((Tstorageloc294812) 3)); ti0 = gentypeinfo_537941_839829468((*p0).module, reftype0); memset((void*)LOC1, 0, sizeof(LOC1)); LOC1[0] = ti0; LOC1[1] = rdloc_540188_839829468(f0); addf_181205_2381377266(&(*(*p0).module).s[(((Tcfilesection531005) 14))- 0], ((NimStringDesc*) &T839829468_423), LOC1, 2); memset((void*)LOC2, 0, sizeof(LOC2)); LOC2[0] = gettypedesc_537671_839829468((*p0).module, reftype0); LOC2[1] = ti0; LOC3 = (Ttype294840*)0; LOC3 = lastson_297377_850551059(reftype0); LOC4 = (Ttype294840*)0; LOC4 = skiptypes_298099_850551059(LOC3, IL64(211106233624832)); LOC2[2] = gettypedesc_537671_839829468((*p0).module, LOC4); b0.r = ropecg_534407_839829468((*p0).module, ((NimStringDesc*) &T839829468_424), LOC2, 3); genassignment_541264_839829468(p0, a0, b0, 0); LOC5 = (Ttype294840*)0; LOC5 = lastson_297377_850551059(reftype0); bt0 = skiptypes_298099_850551059(LOC5, IL64(211106233624832)); genobjectinit_540242_839829468(p0, ((Tcprocsection531011) 2), bt0, a0, NIM_FALSE); gcusage_556439_839829468(e0); } N_NIMCALL(void, gennewseqaux_556795_839829468)(Tcproc531021* p0, Tloc294816 dest0, Ropeobj180006* length0) { Ttype294840* seqtype0; TY537238 args0; Tloc294816 call0; seqtype0 = skiptypes_298099_850551059(dest0.t, IL64(211106242013440)); memset((void*)args0, 0, sizeof(args0)); args0[0] = gettypedesc_537671_839829468((*p0).module, seqtype0); args0[1] = gentypeinfo_537941_839829468((*p0).module, seqtype0); args0[2] = length0; memset((void*)(&call0), 0, sizeof(call0)); initloc_534273_839829468((&call0), ((Tlockind294808) 6), dest0.t, ((Tstorageloc294812) 3)); { NIM_BOOL LOC3; TY534811 LOC15; LOC3 = (NIM_BOOL)0; LOC3 = (dest0.s == ((Tstorageloc294812) 3)); if (!(LOC3)) goto LA4; LOC3 = usesnativegc_171177_2607990831(); LA4: ; if (!LOC3) goto LA5; { NIM_BOOL LOC9; TY180507 LOC12; LOC9 = (NIM_BOOL)0; LOC9 = canformacycle_322123_3876443242(dest0.t); if (!LOC9) goto LA10; memset((void*)LOC12, 0, sizeof(LOC12)); LOC12[0] = rdloc_540188_839829468(dest0); linefmt_534714_839829468(p0, ((Tcprocsection531011) 2), ((NimStringDesc*) &T839829468_420), LOC12, 1); } goto LA7; LA10: ; { TY180507 LOC14; memset((void*)LOC14, 0, sizeof(LOC14)); LOC14[0] = rdloc_540188_839829468(dest0); linefmt_534714_839829468(p0, ((Tcprocsection531011) 2), ((NimStringDesc*) &T839829468_255), LOC14, 1); } LA7: ; call0.r = ropecg_534407_839829468((*p0).module, ((NimStringDesc*) &T839829468_425), args0, 3); memset((void*)LOC15, 0, sizeof(LOC15)); LOC15[0] = rdloc_540188_839829468(dest0); LOC15[1] = rdloc_540188_839829468(call0); linefmt_534714_839829468(p0, ((Tcprocsection531011) 2), ((NimStringDesc*) &T839829468_123), LOC15, 2); } goto LA1; LA5: ; { call0.r = ropecg_534407_839829468((*p0).module, ((NimStringDesc*) &T839829468_426), args0, 3); genassignment_541264_839829468(p0, dest0, call0, 0); } LA1: ; } N_NIMCALL(void, gennewseq_556824_839829468)(Tcproc531021* p0, Tnode294802* e0) { Tloc294816 a0; Tloc294816 b0; Ropeobj180006* LOC1; memset((void*)(&a0), 0, sizeof(a0)); memset((void*)(&b0), 0, sizeof(b0)); initlocexpr_541283_839829468(p0, (*e0).kindU.S6.sons->data[((NI) 1)], (&a0)); initlocexpr_541283_839829468(p0, (*e0).kindU.S6.sons->data[((NI) 2)], (&b0)); LOC1 = (Ropeobj180006*)0; LOC1 = rdloc_540188_839829468(b0); gennewseqaux_556795_839829468(p0, a0, LOC1); gcusage_556439_839829468(e0); } N_NIMCALL(void, gennewseqofcap_556836_839829468)(Tcproc531021* p0, Tnode294802* e0, Tloc294816* d0) { Ttype294840* seqtype0; Tloc294816 a0; TY537238 LOC1; Ropeobj180006* LOC2; seqtype0 = skiptypes_298099_850551059((*e0).typ, IL64(211106242013440)); memset((void*)(&a0), 0, sizeof(a0)); initlocexpr_541283_839829468(p0, (*e0).kindU.S6.sons->data[((NI) 1)], (&a0)); memset((void*)LOC1, 0, sizeof(LOC1)); LOC1[0] = gettypedesc_537671_839829468((*p0).module, seqtype0); LOC1[1] = gentypeinfo_537941_839829468((*p0).module, seqtype0); LOC1[2] = rdloc_540188_839829468(a0); LOC2 = (Ropeobj180006*)0; LOC2 = ropecg_534407_839829468((*p0).module, ((NimStringDesc*) &T839829468_427), LOC1, 3); putintodest_552468_839829468(p0, d0, (*e0).typ, LOC2, ((Tstorageloc294812) 0)); gcusage_556439_839829468(e0); } N_NIMCALL(Ropeobj180006*, getclosuretype_537683_839829468)(Tcgen531027* m0, Ttype294840* t0, Tclosuretypekind537679 kind0) { Ropeobj180006* result0; Intset270030 check0; Ropeobj180006* rettype0; Ropeobj180006* desc0; result0 = (Ropeobj180006*)0; memset((void*)(&check0), 0, sizeof(check0)); chckNil((void*)(&check0)); memset((void*)(&check0), 0, sizeof(check0)); initintset_270885_2627731572((&check0)); result0 = gettempname_535596_839829468(m0); rettype0 = (Ropeobj180006*)0; desc0 = (Ropeobj180006*)0; genprocparams_536115_839829468(m0, t0, &rettype0, &desc0, (&check0), !((kind0 == ((Tclosuretypekind537679) 0))), NIM_FALSE); { NIM_BOOL LOC3; LOC3 = (NIM_BOOL)0; LOC3 = isimportedtype_535449_839829468(t0); if (!!(LOC3)) goto LA4; { NIM_BOOL LOC8; TY537235 LOC12; LOC8 = (NIM_BOOL)0; LOC8 = !(((*t0).callconv == ((Tcallingconvention294002) 8))); if (LOC8) goto LA9; LOC8 = !((kind0 == ((Tclosuretypekind537679) 2))); LA9: ; if (!LOC8) goto LA10; memset((void*)LOC12, 0, sizeof(LOC12)); LOC12[0] = rope_180277_2381377266(Callingconvtostr_535585_839829468[((*t0).callconv)- 0]); LOC12[1] = rettype0; LOC12[2] = result0; LOC12[3] = desc0; addf_181205_2381377266(&(*m0).s[(((Tcfilesection531005) 3))- 0], ((NimStringDesc*) &T839829468_64), LOC12, 4); } goto LA6; LA10: ; { TY537238 LOC14; memset((void*)LOC14, 0, sizeof(LOC14)); LOC14[0] = result0; LOC14[1] = rettype0; LOC14[2] = desc0; addf_181205_2381377266(&(*m0).s[(((Tcfilesection531005) 3))- 0], ((NimStringDesc*) &T839829468_75), LOC14, 3); } LA6: ; } LA4: ; return result0; } N_NIMCALL(void, gensomecast_558480_839829468)(Tcproc531021* p0, Tnode294802* e0, Tloc294816* d0) { Tloc294816 a0; Ttype294840* etyp0; memset((void*)(&a0), 0, sizeof(a0)); initlocexpr_541283_839829468(p0, (*e0).kindU.S6.sons->data[((NI) 1)], (&a0)); etyp0 = skiptypes_298099_850551059((*e0).typ, IL64(211106233624832)); { NIM_BOOL LOC3; TY534811 LOC7; Ropeobj180006* LOC8; LOC3 = (NIM_BOOL)0; LOC3 = ((*etyp0).kind == ((Ttypekind294244) 18) || (*etyp0).kind == ((Ttypekind294244) 17) || (*etyp0).kind == ((Ttypekind294244) 16) || (*etyp0).kind == ((Ttypekind294244) 27) || (*etyp0).kind == ((Ttypekind294244) 48) || (*etyp0).kind == ((Ttypekind294244) 4)); if (!(LOC3)) goto LA4; LOC3 = !(((a0.flags &(1U<<((NU)(((Tlocflag294810) 0))&15U)))!=0)); LA4: ; if (!LOC3) goto LA5; memset((void*)LOC7, 0, sizeof(LOC7)); LOC7[0] = gettypedesc_537671_839829468((*p0).module, (*e0).typ); LOC7[1] = addrloc_540204_839829468(a0); LOC8 = (Ropeobj180006*)0; LOC8 = HEX25_180905_2381377266(((NimStringDesc*) &T839829468_429), LOC7, 2); putintodest_552468_839829468(p0, d0, (*e0).typ, LOC8, a0.s); } goto LA1; LA5: ; { NIM_BOOL LOC10; TY534811 LOC14; Ropeobj180006* LOC15; LOC10 = (NIM_BOOL)0; LOC10 = ((*etyp0).kind == ((Ttypekind294244) 25)); if (!(LOC10)) goto LA11; LOC10 = ((*etyp0).callconv == ((Tcallingconvention294002) 8)); LA11: ; if (!LOC10) goto LA12; memset((void*)LOC14, 0, sizeof(LOC14)); LOC14[0] = getclosuretype_537683_839829468((*p0).module, etyp0, ((Tclosuretypekind537679) 1)); LOC14[1] = rdcharloc_540227_839829468(a0); LOC15 = (Ropeobj180006*)0; LOC15 = HEX25_180905_2381377266(((NimStringDesc*) &T839829468_430), LOC14, 2); putintodest_552468_839829468(p0, d0, (*e0).typ, LOC15, a0.s); } goto LA1; LA12: ; { TY534811 LOC17; Ropeobj180006* LOC18; memset((void*)LOC17, 0, sizeof(LOC17)); LOC17[0] = gettypedesc_537671_839829468((*p0).module, (*e0).typ); LOC17[1] = rdcharloc_540227_839829468(a0); LOC18 = (Ropeobj180006*)0; LOC18 = HEX25_180905_2381377266(((NimStringDesc*) &T839829468_430), LOC17, 2); putintodest_552468_839829468(p0, d0, (*e0).typ, LOC18, a0.s); } LA1: ; } N_NIMCALL(void, unaryexprchar_553222_839829468)(Tcproc531021* p0, Tnode294802* e0, Tloc294816* d0, NimStringDesc* frmt0) { Tloc294816 a0; TY180507 LOC1; Ropeobj180006* LOC2; memset((void*)(&a0), 0, sizeof(a0)); initlocexpr_541283_839829468(p0, (*e0).kindU.S6.sons->data[((NI) 1)], (&a0)); memset((void*)LOC1, 0, sizeof(LOC1)); LOC1[0] = rdcharloc_540227_839829468(a0); LOC2 = (Ropeobj180006*)0; LOC2 = ropecg_534407_839829468((*p0).module, frmt0, LOC1, 1); putintodest_552468_839829468(p0, d0, (*e0).typ, LOC2, ((Tstorageloc294812) 0)); } N_NIMCALL(void, genord_558474_839829468)(Tcproc531021* p0, Tnode294802* e0, Tloc294816* d0) { unaryexprchar_553222_839829468(p0, e0, d0, ((NimStringDesc*) &T839829468_301)); } N_NIMCALL(void, genarraylen_557415_839829468)(Tcproc531021* p0, Tnode294802* e0, Tloc294816* d0, Tmagic294524 op0) { Tnode294802* a0; Ttype294840* typ0; a0 = (*e0).kindU.S6.sons->data[((NI) 1)]; { if (!((*a0).kind == ((Tnodekind294020) 64))) goto LA3; a0 = (*a0).kindU.S6.sons->data[((NI) 0)]; } LA3: ; typ0 = skiptypes_298099_850551059((*a0).typ, IL64(211106240964864)); switch ((*typ0).kind) { case ((Ttypekind294244) 27): case ((Ttypekind294244) 48): { { if (!(op0 == ((Tmagic294524) 8))) goto LA8; unaryexpr_553209_839829468(p0, e0, d0, ((NimStringDesc*) &T839829468_431)); } goto LA6; LA8: ; { unaryexpr_553209_839829468(p0, e0, d0, ((NimStringDesc*) &T839829468_432)); } LA6: ; } break; case ((Ttypekind294244) 29): { usestringh_534345_839829468((*p0).module); { if (!(op0 == ((Tmagic294524) 8))) goto LA14; unaryexpr_553209_839829468(p0, e0, d0, ((NimStringDesc*) &T839829468_433)); } goto LA12; LA14: ; { unaryexpr_553209_839829468(p0, e0, d0, ((NimStringDesc*) &T839829468_434)); } LA12: ; } break; case ((Ttypekind294244) 28): case ((Ttypekind294244) 24): { { NIM_BOOL LOC20; LOC20 = (NIM_BOOL)0; LOC20 = (gcmd_171132_2607990831 == ((Tcommands171076) 2)); if (LOC20) goto LA21; LOC20 = (((*(*(*p0).module).module).flags &(1U<<((NU)(((Tsymflag294184) 27))&31U)))!=0); LA21: ; if (!!(LOC20)) goto LA22; { if (!(op0 == ((Tmagic294524) 8))) goto LA26; unaryexpr_553209_839829468(p0, e0, d0, ((NimStringDesc*) &T839829468_435)); } goto LA24; LA26: ; { unaryexpr_553209_839829468(p0, e0, d0, ((NimStringDesc*) &T839829468_436)); } LA24: ; } goto LA18; LA22: ; { { if (!(op0 == ((Tmagic294524) 8))) goto LA32; unaryexpr_553209_839829468(p0, e0, d0, ((NimStringDesc*) &T839829468_437)); } goto LA30; LA32: ; { unaryexpr_553209_839829468(p0, e0, d0, ((NimStringDesc*) &T839829468_438)); } LA30: ; } LA18: ; } break; case ((Ttypekind294244) 16): case ((Ttypekind294244) 4): { { NI64 LOC40; Ropeobj180006* LOC41; if (!(op0 == ((Tmagic294524) 8))) goto LA38; LOC40 = (NI64)0; LOC40 = lastord_322004_3876443242(typ0); LOC41 = (Ropeobj180006*)0; LOC41 = rope_180401_2381377266(LOC40); putintodest_552468_839829468(p0, d0, (*e0).typ, LOC41, ((Tstorageloc294812) 0)); } goto LA36; LA38: ; { NI64 LOC43; Ropeobj180006* LOC44; LOC43 = (NI64)0; LOC43 = lengthord_322007_3876443242(typ0); LOC44 = (Ropeobj180006*)0; LOC44 = rope_180401_2381377266(LOC43); putintodest_552468_839829468(p0, d0, (*e0).typ, LOC44, ((Tstorageloc294812) 0)); } LA36: ; } break; default: { internalerror_198100_155036129((*e0).info, ((NimStringDesc*) &T839829468_439)); } break; } } N_NIMCALL(void, unarystmt_552527_839829468)(Tcproc531021* p0, Tnode294802* e0, Tloc294816* d0, NimStringDesc* frmt0) { Tloc294816 a0; TY180507 LOC5; memset((void*)(&a0), 0, sizeof(a0)); { if (!!(((*d0).k == ((Tlockind294808) 0)))) goto LA3; internalerror_198100_155036129((*e0).info, ((NimStringDesc*) &T839829468_442)); } LA3: ; initlocexpr_541283_839829468(p0, (*e0).kindU.S6.sons->data[((NI) 1)], (&a0)); memset((void*)LOC5, 0, sizeof(LOC5)); LOC5[0] = rdloc_540188_839829468(a0); linecg_534707_839829468(p0, ((Tcprocsection531011) 2), frmt0, LOC5, 1); } N_NIMCALL(void, gensetlengthstr_557632_839829468)(Tcproc531021* p0, Tnode294802* e0, Tloc294816* d0) { binarystmt_552501_839829468(p0, e0, d0, ((NimStringDesc*) &T839829468_445)); gcusage_556439_839829468(e0); } N_NIMCALL(void, gensetlengthseq_557500_839829468)(Tcproc531021* p0, Tnode294802* e0, Tloc294816* d0) { Tloc294816 a0; Tloc294816 b0; Ttype294840* t0; NimStringDesc* setlenpattern0; TY537235 LOC8; memset((void*)(&a0), 0, sizeof(a0)); memset((void*)(&b0), 0, sizeof(b0)); initlocexpr_541283_839829468(p0, (*e0).kindU.S6.sons->data[((NI) 1)], (&a0)); initlocexpr_541283_839829468(p0, (*e0).kindU.S6.sons->data[((NI) 2)], (&b0)); t0 = skiptypes_298099_850551059((*(*e0).kindU.S6.sons->data[((NI) 1)]).typ, IL64(211106240964864)); { NIM_BOOL LOC3; LOC3 = (NIM_BOOL)0; LOC3 = (gcmd_171132_2607990831 == ((Tcommands171076) 2)); if (LOC3) goto LA4; LOC3 = (((*(*(*p0).module).module).flags &(1U<<((NU)(((Tsymflag294184) 27))&31U)))!=0); LA4: ; if (!!(LOC3)) goto LA5; setlenpattern0 = copyString(((NimStringDesc*) &T839829468_446)); } goto LA1; LA5: ; { setlenpattern0 = copyString(((NimStringDesc*) &T839829468_447)); } LA1: ; memset((void*)LOC8, 0, sizeof(LOC8)); LOC8[0] = rdloc_540188_839829468(a0); LOC8[1] = rdloc_540188_839829468(b0); LOC8[2] = gettypedesc_537671_839829468((*p0).module, t0); LOC8[3] = gettypedesc_537671_839829468((*p0).module, (*t0).sons->data[((NI) 0)]); linecg_534707_839829468(p0, ((Tcprocsection531011) 2), setlenpattern0, LOC8, 4); gcusage_556439_839829468(e0); } N_NIMCALL(Ropeobj180006*, rdsetelemloc_557662_839829468)(Tloc294816 a0, Ttype294840* settype0) { Ropeobj180006* result0; result0 = (Ropeobj180006*)0; result0 = rdcharloc_540227_839829468(a0); { NI64 LOC3; TY534811 LOC6; NI64 LOC7; LOC3 = (NI64)0; LOC3 = firstord_322001_3876443242(settype0); if (!!((LOC3 == IL64(0)))) goto LA4; memset((void*)LOC6, 0, sizeof(LOC6)); LOC6[0] = result0; LOC7 = (NI64)0; LOC7 = firstord_322001_3876443242(settype0); LOC6[1] = rope_180401_2381377266(LOC7); result0 = HEX25_180905_2381377266(((NimStringDesc*) &T839829468_448), LOC6, 2); } LA4: ; return result0; } N_NIMCALL(void, binarystmtinexcl_557857_839829468)(Tcproc531021* p0, Tnode294802* e0, Tloc294816* d0, NimStringDesc* frmt0) { Tloc294816 a0; Tloc294816 b0; TY534811 LOC1; memset((void*)(&a0), 0, sizeof(a0)); memset((void*)(&b0), 0, sizeof(b0)); initlocexpr_541283_839829468(p0, (*e0).kindU.S6.sons->data[((NI) 1)], (&a0)); initlocexpr_541283_839829468(p0, (*e0).kindU.S6.sons->data[((NI) 2)], (&b0)); memset((void*)LOC1, 0, sizeof(LOC1)); LOC1[0] = rdloc_540188_839829468(a0); LOC1[1] = rdsetelemloc_557662_839829468(b0, a0.t); linef_534700_839829468(p0, ((Tcprocsection531011) 2), frmt0, LOC1, 2); } N_NIMCALL(void, binaryexprchar_552809_839829468)(Tcproc531021* p0, Tnode294802* e0, Tloc294816* d0, NimStringDesc* frmt0) { Tloc294816 a0; Tloc294816 b0; TY534811 LOC1; Ropeobj180006* LOC2; memset((void*)(&a0), 0, sizeof(a0)); memset((void*)(&b0), 0, sizeof(b0)); initlocexpr_541283_839829468(p0, (*e0).kindU.S6.sons->data[((NI) 1)], (&a0)); initlocexpr_541283_839829468(p0, (*e0).kindU.S6.sons->data[((NI) 2)], (&b0)); memset((void*)LOC1, 0, sizeof(LOC1)); LOC1[0] = rdcharloc_540227_839829468(a0); LOC1[1] = rdcharloc_540227_839829468(b0); LOC2 = (Ropeobj180006*)0; LOC2 = ropecg_534407_839829468((*p0).module, frmt0, LOC1, 2); putintodest_552468_839829468(p0, d0, (*e0).typ, LOC2, ((Tstorageloc294812) 0)); } N_NIMCALL(NIM_BOOL, fewcmps_557803_839829468)(Tnode294802* s0) { NIM_BOOL result0; result0 = (NIM_BOOL)0; { if (!!(((*s0).kind == ((Tnodekind294020) 39)))) goto LA3; internalerror_198100_155036129((*s0).info, ((NimStringDesc*) &T839829468_463)); } LA3: ; { NIM_BOOL LOC7; NI64 LOC8; LOC7 = (NIM_BOOL)0; LOC8 = (NI64)0; LOC8 = getsize_322135_3876443242((*s0).typ); LOC7 = (LOC8 <= ((NI64) (intsize_178641_4151366050))); if (!(LOC7)) goto LA9; LOC7 = (((*s0).flags &(1U<<((NU)(((Tnodeflag294427) 4))&15U)))!=0); LA9: ; if (!LOC7) goto LA10; result0 = NIM_FALSE; } goto LA5; LA10: ; { Ttype294840* LOC13; LOC13 = (Ttype294840*)0; LOC13 = elemtype_322394_3876443242((*s0).typ); if (!((*LOC13).kind == ((Ttypekind294244) 31) || (*LOC13).kind >= ((Ttypekind294244) 33) && (*LOC13).kind <= ((Ttypekind294244) 35))) goto LA14; result0 = NIM_TRUE; } goto LA5; LA14: ; { NI LOC17; LOC17 = (NI)0; LOC17 = sonslen_297351_850551059(s0); result0 = (LOC17 <= ((NI) 8)); } LA5: ; return result0; } N_NIMCALL(void, binaryexprin_557837_839829468)(Tcproc531021* p0, Tnode294802* e0, Tloc294816* a0, Tloc294816* b0, Tloc294816* d0, NimStringDesc* frmt0) { TY534811 LOC1; Ropeobj180006* LOC2; memset((void*)LOC1, 0, sizeof(LOC1)); LOC1[0] = rdloc_540188_839829468((*a0)); LOC1[1] = rdsetelemloc_557662_839829468((*b0), (*a0).t); LOC2 = (Ropeobj180006*)0; LOC2 = HEX25_180905_2381377266(frmt0, LOC1, 2); putintodest_552468_839829468(p0, d0, (*e0).typ, LOC2, ((Tstorageloc294812) 0)); } N_NIMCALL(void, geninexpraux_555496_839829468)(Tcproc531021* p0, Tnode294802* e0, Tloc294816* a0, Tloc294816* b0, Tloc294816* d0) { Ttype294840* LOC1; NI64 LOC2; LOC1 = (Ttype294840*)0; LOC1 = skiptypes_298099_850551059((*(*e0).kindU.S6.sons->data[((NI) 1)]).typ, IL64(211106240964864)); LOC2 = (NI64)0; LOC2 = getsize_322135_3876443242(LOC1); switch (((NI) (LOC2))) { case ((NI) 1): { binaryexprin_557837_839829468(p0, e0, a0, b0, d0, ((NimStringDesc*) &T839829468_467)); } break; case ((NI) 2): { binaryexprin_557837_839829468(p0, e0, a0, b0, d0, ((NimStringDesc*) &T839829468_468)); } break; case ((NI) 4): { binaryexprin_557837_839829468(p0, e0, a0, b0, d0, ((NimStringDesc*) &T839829468_469)); } break; case ((NI) 8): { binaryexprin_557837_839829468(p0, e0, a0, b0, d0, ((NimStringDesc*) &T839829468_470)); } break; default: { binaryexprin_557837_839829468(p0, e0, a0, b0, d0, ((NimStringDesc*) &T839829468_471)); } break; } } N_NIMCALL(void, geninop_558009_839829468)(Tcproc531021* p0, Tnode294802* e0, Tloc294816* d0) { Tloc294816 a0; Tloc294816 b0; Tloc294816 x0; Tloc294816 y0; memset((void*)(&a0), 0, sizeof(a0)); memset((void*)(&b0), 0, sizeof(b0)); memset((void*)(&x0), 0, sizeof(x0)); memset((void*)(&y0), 0, sizeof(y0)); { NIM_BOOL LOC3; Tnode294802* ea0; NI length0; LOC3 = (NIM_BOOL)0; LOC3 = ((*(*e0).kindU.S6.sons->data[((NI) 1)]).kind == ((Tnodekind294020) 39)); if (!(LOC3)) goto LA4; LOC3 = fewcmps_557803_839829468((*e0).kindU.S6.sons->data[((NI) 1)]); LA4: ; if (!LOC3) goto LA5; { if (!((*(*e0).kindU.S6.sons->data[((NI) 2)]).kind == ((Tnodekind294020) 70) || (*(*e0).kindU.S6.sons->data[((NI) 2)]).kind == ((Tnodekind294020) 69))) goto LA9; ea0 = (*(*e0).kindU.S6.sons->data[((NI) 2)]).kindU.S6.sons->data[((NI) 0)]; } goto LA7; LA9: ; { ea0 = (*e0).kindU.S6.sons->data[((NI) 2)]; } LA7: ; initlocexpr_541283_839829468(p0, ea0, (&a0)); initloc_534273_839829468((&b0), ((Tlockind294808) 6), (*e0).typ, ((Tstorageloc294812) 0)); b0.r = rope_180277_2381377266(((NimStringDesc*) &T839829468_118)); length0 = sonslen_297351_850551059((*e0).kindU.S6.sons->data[((NI) 1)]); { NI i_558061_839829468; NI HEX3Atmp_558412_839829468; NI res_558415_839829468; i_558061_839829468 = (NI)0; HEX3Atmp_558412_839829468 = (NI)0; HEX3Atmp_558412_839829468 = (NI)(length0 - ((NI) 1)); res_558415_839829468 = ((NI) 0); { while (1) { if (!(res_558415_839829468 <= HEX3Atmp_558412_839829468)) goto LA14; i_558061_839829468 = res_558415_839829468; { TY537238 LOC19; if (!((*(*(*e0).kindU.S6.sons->data[((NI) 1)]).kindU.S6.sons->data[i_558061_839829468]).kind == ((Tnodekind294020) 44))) goto LA17; initlocexpr_541283_839829468(p0, (*(*(*e0).kindU.S6.sons->data[((NI) 1)]).kindU.S6.sons->data[i_558061_839829468]).kindU.S6.sons->data[((NI) 0)], (&x0)); initlocexpr_541283_839829468(p0, (*(*(*e0).kindU.S6.sons->data[((NI) 1)]).kindU.S6.sons->data[i_558061_839829468]).kindU.S6.sons->data[((NI) 1)], (&y0)); memset((void*)LOC19, 0, sizeof(LOC19)); LOC19[0] = rdcharloc_540227_839829468(a0); LOC19[1] = rdcharloc_540227_839829468(x0); LOC19[2] = rdcharloc_540227_839829468(y0); addf_181205_2381377266(&b0.r, ((NimStringDesc*) &T839829468_464), LOC19, 3); } goto LA15; LA17: ; { TY534811 LOC21; initlocexpr_541283_839829468(p0, (*(*e0).kindU.S6.sons->data[((NI) 1)]).kindU.S6.sons->data[i_558061_839829468], (&x0)); memset((void*)LOC21, 0, sizeof(LOC21)); LOC21[0] = rdcharloc_540227_839829468(a0); LOC21[1] = rdcharloc_540227_839829468(x0); addf_181205_2381377266(&b0.r, ((NimStringDesc*) &T839829468_465), LOC21, 2); } LA15: ; { if (!(i_558061_839829468 < (NI)(length0 - ((NI) 1)))) goto LA24; add_180487_2381377266(&b0.r, ((NimStringDesc*) &T839829468_466)); } LA24: ; res_558415_839829468 += ((NI) 1); } LA14: ; } } add_180487_2381377266(&b0.r, ((NimStringDesc*) &T839829468_117)); putintodest_552468_839829468(p0, d0, (*e0).typ, b0.r, ((Tstorageloc294812) 0)); } goto LA1; LA5: ; { initlocexpr_541283_839829468(p0, (*e0).kindU.S6.sons->data[((NI) 1)], (&a0)); initlocexpr_541283_839829468(p0, (*e0).kindU.S6.sons->data[((NI) 2)], (&b0)); geninexpraux_555496_839829468(p0, e0, (&a0), (&b0), d0); } LA1: ; } N_NIMCALL(void, gensetop_558419_839829468)(Tcproc531021* p0, Tnode294802* e0, Tloc294816* d0, Tmagic294524 op0) { Tloc294816 a0; Tloc294816 b0; Tloc294816 i0; Ttype294840* settype0; NI size0; NI64 LOC1; memset((void*)(&a0), 0, sizeof(a0)); memset((void*)(&b0), 0, sizeof(b0)); memset((void*)(&i0), 0, sizeof(i0)); settype0 = skiptypes_298099_850551059((*(*e0).kindU.S6.sons->data[((NI) 1)]).typ, IL64(211106240964864)); LOC1 = (NI64)0; LOC1 = getsize_322135_3876443242(settype0); size0 = ((NI) (LOC1)); switch (size0) { case ((NI) 1): case ((NI) 2): case ((NI) 4): case ((NI) 8): { switch (op0) { case ((Tmagic294524) 39): { NimStringDesc* ts0; NimStringDesc* LOC4; NimStringDesc* LOC5; NimStringDesc* LOC6; LOC4 = (NimStringDesc*)0; LOC5 = (NimStringDesc*)0; LOC5 = nimIntToStr((NI)(size0 * ((NI) 8))); LOC4 = rawNewString(LOC5->Sup.len + 2); appendString(LOC4, ((NimStringDesc*) &T839829468_45)); appendString(LOC4, LOC5); ts0 = LOC4; LOC6 = (NimStringDesc*)0; LOC6 = rawNewString(ts0->Sup.len + ts0->Sup.len + 35); appendString(LOC6, ((NimStringDesc*) &T839829468_449)); appendString(LOC6, ts0); appendString(LOC6, ((NimStringDesc*) &T839829468_450)); appendString(LOC6, ts0); appendString(LOC6, ((NimStringDesc*) &T839829468_451)); binarystmtinexcl_557857_839829468(p0, e0, d0, LOC6); } break; case ((Tmagic294524) 40): { NimStringDesc* ts0; NimStringDesc* LOC8; NimStringDesc* LOC9; NimStringDesc* LOC10; LOC8 = (NimStringDesc*)0; LOC9 = (NimStringDesc*)0; LOC9 = nimIntToStr((NI)(size0 * ((NI) 8))); LOC8 = rawNewString(LOC9->Sup.len + 2); appendString(LOC8, ((NimStringDesc*) &T839829468_45)); appendString(LOC8, LOC9); ts0 = LOC8; LOC10 = (NimStringDesc*)0; LOC10 = rawNewString(ts0->Sup.len + ts0->Sup.len + 42); appendString(LOC10, ((NimStringDesc*) &T839829468_452)); appendString(LOC10, ts0); appendString(LOC10, ((NimStringDesc*) &T839829468_453)); appendString(LOC10, ts0); appendString(LOC10, ((NimStringDesc*) &T839829468_454)); binarystmtinexcl_557857_839829468(p0, e0, d0, LOC10); } break; case ((Tmagic294524) 41): { { if (!(size0 <= ((NI) 4))) goto LA14; unaryexprchar_553222_839829468(p0, e0, d0, ((NimStringDesc*) &T839829468_455)); } goto LA12; LA14: ; { unaryexprchar_553222_839829468(p0, e0, d0, ((NimStringDesc*) &T839829468_456)); } LA12: ; } break; case ((Tmagic294524) 133): { binaryexprchar_552809_839829468(p0, e0, d0, ((NimStringDesc*) &T839829468_457)); } break; case ((Tmagic294524) 132): { binaryexprchar_552809_839829468(p0, e0, d0, ((NimStringDesc*) &T839829468_458)); } break; case ((Tmagic294524) 131): { binaryexpr_552549_839829468(p0, e0, d0, ((NimStringDesc*) &T839829468_341)); } break; case ((Tmagic294524) 134): { binaryexpr_552549_839829468(p0, e0, d0, ((NimStringDesc*) &T839829468_459)); } break; case ((Tmagic294524) 135): { binaryexpr_552549_839829468(p0, e0, d0, ((NimStringDesc*) &T839829468_460)); } break; case ((Tmagic294524) 136): { binaryexpr_552549_839829468(p0, e0, d0, ((NimStringDesc*) &T839829468_461)); } break; case ((Tmagic294524) 137): { binaryexpr_552549_839829468(p0, e0, d0, ((NimStringDesc*) &T839829468_462)); } break; case ((Tmagic294524) 148): { geninop_558009_839829468(p0, e0, d0); } break; default: { internalerror_198100_155036129((*e0).info, ((NimStringDesc*) &T839829468_472)); } break; } } break; default: { switch (op0) { case ((Tmagic294524) 39): { binarystmtinexcl_557857_839829468(p0, e0, d0, ((NimStringDesc*) &T839829468_473)); } break; case ((Tmagic294524) 40): { binarystmtinexcl_557857_839829468(p0, e0, d0, ((NimStringDesc*) &T839829468_474)); } break; case ((Tmagic294524) 41): { NimStringDesc* LOC30; NimStringDesc* LOC31; LOC30 = (NimStringDesc*)0; LOC31 = (NimStringDesc*)0; LOC31 = nimIntToStr(size0); LOC30 = rawNewString(LOC31->Sup.len + 14); appendString(LOC30, ((NimStringDesc*) &T839829468_475)); appendString(LOC30, LOC31); appendChar(LOC30, 41); unaryexprchar_553222_839829468(p0, e0, d0, LOC30); } break; case ((Tmagic294524) 133): case ((Tmagic294524) 132): { Ttype294840* LOC33; TY538475 LOC39; LOC33 = (Ttype294840*)0; LOC33 = getsystype_340150_3937434831(((Ttypekind294244) 31)); gettemp_539032_839829468(p0, LOC33, (&i0), NIM_FALSE); initlocexpr_541283_839829468(p0, (*e0).kindU.S6.sons->data[((NI) 1)], (&a0)); initlocexpr_541283_839829468(p0, (*e0).kindU.S6.sons->data[((NI) 2)], (&b0)); { Ttype294840* LOC38; if (!((*d0).k == ((Tlockind294808) 0))) goto LA36; LOC38 = (Ttype294840*)0; LOC38 = getsystype_340150_3937434831(((Ttypekind294244) 1)); gettemp_539032_839829468(p0, LOC38, d0, NIM_FALSE); } LA36: ; memset((void*)LOC39, 0, sizeof(LOC39)); LOC39[0] = rdloc_540188_839829468(i0); LOC39[1] = rope_180401_2381377266(((NI64) (size0))); LOC39[2] = rdloc_540188_839829468((*d0)); LOC39[3] = rdloc_540188_839829468(a0); LOC39[4] = rdloc_540188_839829468(b0); linef_534700_839829468(p0, ((Tcprocsection531011) 2), lookupopr_558426_839829468[(op0)- 132], LOC39, 5); } break; case ((Tmagic294524) 131): { NimStringDesc* LOC41; NimStringDesc* LOC42; usestringh_534345_839829468((*p0).module); LOC41 = (NimStringDesc*)0; LOC42 = (NimStringDesc*)0; LOC42 = nimIntToStr(size0); LOC41 = rawNewString(LOC42->Sup.len + 21); appendString(LOC41, ((NimStringDesc*) &T839829468_481)); appendString(LOC41, LOC42); appendString(LOC41, ((NimStringDesc*) &T839829468_482)); binaryexprchar_552809_839829468(p0, e0, d0, LOC41); } break; case ((Tmagic294524) 134): case ((Tmagic294524) 135): case ((Tmagic294524) 136): case ((Tmagic294524) 137): { Ttype294840* LOC44; TY538847 LOC49; LOC44 = (Ttype294840*)0; LOC44 = getsystype_340150_3937434831(((Ttypekind294244) 31)); gettemp_539032_839829468(p0, LOC44, (&i0), NIM_FALSE); initlocexpr_541283_839829468(p0, (*e0).kindU.S6.sons->data[((NI) 1)], (&a0)); initlocexpr_541283_839829468(p0, (*e0).kindU.S6.sons->data[((NI) 2)], (&b0)); { if (!((*d0).k == ((Tlockind294808) 0))) goto LA47; gettemp_539032_839829468(p0, a0.t, d0, NIM_FALSE); } LA47: ; memset((void*)LOC49, 0, sizeof(LOC49)); LOC49[0] = rdloc_540188_839829468(i0); LOC49[1] = rope_180401_2381377266(((NI64) (size0))); LOC49[2] = rdloc_540188_839829468((*d0)); LOC49[3] = rdloc_540188_839829468(a0); LOC49[4] = rdloc_540188_839829468(b0); LOC49[5] = rope_180277_2381377266(lookupopr_558426_839829468[(op0)- 132]); linef_534700_839829468(p0, ((Tcprocsection531011) 2), ((NimStringDesc*) &T839829468_483), LOC49, 6); } break; case ((Tmagic294524) 148): { geninop_558009_839829468(p0, e0, d0); } break; default: { internalerror_198100_155036129((*e0).info, ((NimStringDesc*) &T839829468_484)); } break; } } break; } } static N_INLINE(Ropeobj180006*, genargstringtocstring_541776_839829468)(Tcproc531021* p0, Tnode294802* n0) { Ropeobj180006* result0; Tloc294816 a0; TY180507 LOC1; result0 = (Ropeobj180006*)0; memset((void*)(&a0), 0, sizeof(a0)); initlocexpr_541283_839829468(p0, (*n0).kindU.S6.sons->data[((NI) 0)], (&a0)); memset((void*)LOC1, 0, sizeof(LOC1)); LOC1[0] = rdloc_540188_839829468(a0); result0 = HEX25_180905_2381377266(((NimStringDesc*) &T839829468_485), LOC1, 1); return result0; } N_NIMCALL(Ropeobj180006*, openarrayloc_541665_839829468)(Tcproc531021* p0, Tnode294802* n0) { Ropeobj180006* result0; Tloc294816 a0; Tnode294802* q0; result0 = (Ropeobj180006*)0; memset((void*)(&a0), 0, sizeof(a0)); q0 = skipconv_330882_3876443242(n0); { Tmagic294524 LOC3; Tloc294816 b0; Tloc294816 c0; Tnode294802* LOC6; Tnode294802* LOC7; Tnode294802* LOC8; NimStringDesc* fmt0; Ttype294840* LOC9; TY537238 LOC25; LOC3 = (Tmagic294524)0; LOC3 = getmagic_320502_2616423590(q0); if (!(LOC3 == ((Tmagic294524) 139))) goto LA4; memset((void*)(&b0), 0, sizeof(b0)); memset((void*)(&c0), 0, sizeof(c0)); LOC6 = (Tnode294802*)0; LOC6 = HEX5BHEX5D_295238_850551059(q0, ((NI) 1)); initlocexpr_541283_839829468(p0, LOC6, (&a0)); LOC7 = (Tnode294802*)0; LOC7 = HEX5BHEX5D_295238_850551059(q0, ((NI) 2)); initlocexpr_541283_839829468(p0, LOC7, (&b0)); LOC8 = (Tnode294802*)0; LOC8 = HEX5BHEX5D_295238_850551059(q0, ((NI) 3)); initlocexpr_541283_839829468(p0, LOC8, (&c0)); LOC9 = (Ttype294840*)0; LOC9 = skiptypes_298099_850551059(a0.t, IL64(211106243062016)); switch ((*LOC9).kind) { case ((Ttypekind294244) 27): case ((Ttypekind294244) 48): case ((Ttypekind294244) 16): case ((Ttypekind294244) 4): { fmt0 = copyString(((NimStringDesc*) &T839829468_486)); } break; case ((Ttypekind294244) 28): case ((Ttypekind294244) 24): { { NIM_BOOL LOC14; Ttype294840* LOC15; NIM_BOOL LOC17; LOC14 = (NIM_BOOL)0; LOC15 = (Ttype294840*)0; LOC15 = skiptypes_298099_850551059((*n0).typ, IL64(211106232576256)); LOC14 = ((*LOC15).kind == ((Ttypekind294244) 23)); if (!(LOC14)) goto LA16; LOC17 = (NIM_BOOL)0; LOC17 = (gcmd_171132_2607990831 == ((Tcommands171076) 2)); if (LOC17) goto LA18; LOC17 = (((*(*(*p0).module).module).flags &(1U<<((NU)(((Tsymflag294184) 27))&31U)))!=0); LA18: ; LOC14 = !(LOC17); LA16: ; if (!LOC14) goto LA19; fmt0 = copyString(((NimStringDesc*) &T839829468_487)); } goto LA12; LA19: ; { fmt0 = copyString(((NimStringDesc*) &T839829468_488)); } LA12: ; } break; default: { NimStringDesc* LOC23; NimStringDesc* LOC24; LOC23 = (NimStringDesc*)0; LOC24 = (NimStringDesc*)0; LOC24 = typetostring_322017_3876443242(a0.t, ((Tprefereddesc322011) 0)); LOC23 = rawNewString(LOC24->Sup.len + 14); appendString(LOC23, ((NimStringDesc*) &T839829468_489)); appendString(LOC23, LOC24); internalerror_198113_155036129(LOC23); fmt0 = copyString(((NimStringDesc*) &T839829468_490)); } break; } memset((void*)LOC25, 0, sizeof(LOC25)); LOC25[0] = rdloc_540188_839829468(a0); LOC25[1] = rdloc_540188_839829468(b0); LOC25[2] = rdloc_540188_839829468(c0); result0 = HEX25_180905_2381377266(fmt0, LOC25, 3); } goto LA1; LA4: ; { Ttype294840* LOC27; initlocexpr_541283_839829468(p0, n0, (&a0)); LOC27 = (Ttype294840*)0; LOC27 = skiptypes_298099_850551059(a0.t, IL64(211106240964864)); switch ((*LOC27).kind) { case ((Ttypekind294244) 27): case ((Ttypekind294244) 48): { TY180507 LOC29; memset((void*)LOC29, 0, sizeof(LOC29)); LOC29[0] = rdloc_540188_839829468(a0); result0 = HEX25_180905_2381377266(((NimStringDesc*) &T839829468_378), LOC29, 1); } break; case ((Ttypekind294244) 28): case ((Ttypekind294244) 24): { { NIM_BOOL LOC33; Ttype294840* LOC34; NIM_BOOL LOC36; TY534811 LOC40; LOC33 = (NIM_BOOL)0; LOC34 = (Ttype294840*)0; LOC34 = skiptypes_298099_850551059((*n0).typ, IL64(211106232576256)); LOC33 = ((*LOC34).kind == ((Ttypekind294244) 23)); if (!(LOC33)) goto LA35; LOC36 = (NIM_BOOL)0; LOC36 = (gcmd_171132_2607990831 == ((Tcommands171076) 2)); if (LOC36) goto LA37; LOC36 = (((*(*(*p0).module).module).flags &(1U<<((NU)(((Tsymflag294184) 27))&31U)))!=0); LA37: ; LOC33 = !(LOC36); LA35: ; if (!LOC33) goto LA38; memset((void*)LOC40, 0, sizeof(LOC40)); LOC40[0] = rdloc_540188_839829468(a0); LOC40[1] = lenfield_541305_839829468(p0); result0 = HEX25_180905_2381377266(((NimStringDesc*) &T839829468_491), LOC40, 2); } goto LA31; LA38: ; { TY534811 LOC42; memset((void*)LOC42, 0, sizeof(LOC42)); LOC42[0] = rdloc_540188_839829468(a0); LOC42[1] = lenfield_541305_839829468(p0); result0 = HEX25_180905_2381377266(((NimStringDesc*) &T839829468_379), LOC42, 2); } LA31: ; } break; case ((Ttypekind294244) 16): case ((Ttypekind294244) 4): { TY534811 LOC44; NI64 LOC45; memset((void*)LOC44, 0, sizeof(LOC44)); LOC44[0] = rdloc_540188_839829468(a0); LOC45 = (NI64)0; LOC45 = lengthord_322007_3876443242(a0.t); LOC44[1] = rope_180401_2381377266(LOC45); result0 = HEX25_180905_2381377266(((NimStringDesc*) &T839829468_380), LOC44, 2); } break; case ((Ttypekind294244) 21): case ((Ttypekind294244) 22): { Ttype294840* LOC47; LOC47 = (Ttype294840*)0; LOC47 = lastson_297377_850551059(a0.t); switch ((*LOC47).kind) { case ((Ttypekind294244) 28): case ((Ttypekind294244) 24): { TY534811 LOC49; memset((void*)LOC49, 0, sizeof(LOC49)); LOC49[0] = rdloc_540188_839829468(a0); LOC49[1] = lenfield_541305_839829468(p0); result0 = HEX25_180905_2381377266(((NimStringDesc*) &T839829468_491), LOC49, 2); } break; case ((Ttypekind294244) 16): case ((Ttypekind294244) 4): { TY534811 LOC51; Ttype294840* LOC52; NI64 LOC53; memset((void*)LOC51, 0, sizeof(LOC51)); LOC51[0] = rdloc_540188_839829468(a0); LOC52 = (Ttype294840*)0; LOC52 = lastson_297377_850551059(a0.t); LOC53 = (NI64)0; LOC53 = lengthord_322007_3876443242(LOC52); LOC51[1] = rope_180401_2381377266(LOC53); result0 = HEX25_180905_2381377266(((NimStringDesc*) &T839829468_380), LOC51, 2); } break; default: { NimStringDesc* LOC55; NimStringDesc* LOC56; LOC55 = (NimStringDesc*)0; LOC56 = (NimStringDesc*)0; LOC56 = typetostring_322017_3876443242(a0.t, ((Tprefereddesc322011) 0)); LOC55 = rawNewString(LOC56->Sup.len + 14); appendString(LOC55, ((NimStringDesc*) &T839829468_489)); appendString(LOC55, LOC56); internalerror_198113_155036129(LOC55); } break; } } break; default: { NimStringDesc* LOC58; NimStringDesc* LOC59; LOC58 = (NimStringDesc*)0; LOC59 = (NimStringDesc*)0; LOC59 = typetostring_322017_3876443242(a0.t, ((Tprefereddesc322011) 0)); LOC58 = rawNewString(LOC59->Sup.len + 14); appendString(LOC58, ((NimStringDesc*) &T839829468_489)); appendString(LOC58, LOC59); internalerror_198113_155036129(LOC58); } break; } } LA1: ; return result0; } N_NIMCALL(Ropeobj180006*, genarg_541787_839829468)(Tcproc531021* p0, Tnode294802* n_541790_839829468, Tsym294834* param0, Tnode294802* call0) { Ropeobj180006* result0; Tloc294816 a0; result0 = (Ropeobj180006*)0; memset((void*)(&a0), 0, sizeof(a0)); { if (!((*n_541790_839829468).kind == ((Tnodekind294020) 71))) goto LA3; result0 = genargstringtocstring_541776_839829468(p0, n_541790_839829468); } goto LA1; LA3: ; { Ttype294840* LOC6; Tnode294802* n0; LOC6 = (Ttype294840*)0; LOC6 = skiptypes_298099_850551059((*param0).typ, IL64(211106240964864)); if (!((*LOC6).kind == ((Ttypekind294244) 27) || (*LOC6).kind == ((Ttypekind294244) 48))) goto LA7; { if (!!(((*n_541790_839829468).kind == ((Tnodekind294020) 64)))) goto LA11; n0 = n_541790_839829468; } goto LA9; LA11: ; { n0 = (*n_541790_839829468).kindU.S6.sons->data[((NI) 0)]; } LA9: ; result0 = openarrayloc_541665_839829468(p0, n0); } goto LA1; LA7: ; { NIM_BOOL LOC15; LOC15 = (NIM_BOOL)0; LOC15 = ccgintroducedptr_535609_839829468(param0); if (!LOC15) goto LA16; initlocexpr_541283_839829468(p0, n_541790_839829468, (&a0)); result0 = addrloc_540204_839829468(a0); } goto LA1; LA16: ; { NIM_BOOL LOC19; NIM_BOOL LOC20; NIM_BOOL LOC21; Tnode294802* callee0; LOC19 = (NIM_BOOL)0; LOC20 = (NIM_BOOL)0; LOC21 = (NIM_BOOL)0; LOC21 = (gcmd_171132_2607990831 == ((Tcommands171076) 2)); if (LOC21) goto LA22; LOC21 = (((*(*(*p0).module).module).flags &(1U<<((NU)(((Tsymflag294184) 27))&31U)))!=0); LA22: ; LOC20 = LOC21; if (!(LOC20)) goto LA23; LOC20 = ((*(*param0).typ).kind == ((Ttypekind294244) 23)); LA23: ; LOC19 = LOC20; if (!(LOC19)) goto LA24; LOC19 = ((*n_541790_839829468).kind == ((Tnodekind294020) 64)); LA24: ; if (!LOC19) goto LA25; initlocexprsingleuse_541289_839829468(p0, (*n_541790_839829468).kindU.S6.sons->data[((NI) 0)], (&a0)); callee0 = (*call0).kindU.S6.sons->data[((NI) 0)]; { NIM_BOOL LOC29; NIM_BOOL LOC30; LOC29 = (NIM_BOOL)0; LOC30 = (NIM_BOOL)0; LOC30 = ((*callee0).kind == ((Tnodekind294020) 3)); if (!(LOC30)) goto LA31; LOC30 = ((134283296 & (*(*callee0).kindU.S4.sym).flags) == 32); LA31: ; LOC29 = LOC30; if (!(LOC29)) goto LA32; LOC29 = !(((72 & (*(*callee0).kindU.S4.sym).loc.flags) == 0)); LA32: ; if (!LOC29) goto LA33; result0 = addrloc_540204_839829468(a0); } goto LA27; LA33: ; { result0 = rdloc_540188_839829468(a0); } LA27: ; } goto LA1; LA25: ; { initlocexprsingleuse_541289_839829468(p0, n_541790_839829468, (&a0)); result0 = rdloc_540188_839829468(a0); } LA1: ; return result0; } N_NIMCALL(Ropeobj180006*, genargnoparam_541938_839829468)(Tcproc531021* p0, Tnode294802* n0) { Ropeobj180006* result0; Tloc294816 a0; result0 = (Ropeobj180006*)0; memset((void*)(&a0), 0, sizeof(a0)); { if (!((*n0).kind == ((Tnodekind294020) 71))) goto LA3; result0 = genargstringtocstring_541776_839829468(p0, n0); } goto LA1; LA3: ; { initlocexprsingleuse_541289_839829468(p0, n0, (&a0)); result0 = rdloc_540188_839829468(a0); } LA1: ; return result0; } N_NIMCALL(Ropeobj180006*, getrawproctype_542459_839829468)(Tcproc531021* p0, Ttype294840* t0) { Ropeobj180006* result0; result0 = (Ropeobj180006*)0; result0 = getclosuretype_537683_839829468((*p0).module, t0, ((Tclosuretypekind537679) 0)); return result0; } N_NIMCALL(NIM_BOOL, leftappearsonrightside_541329_839829468)(Tnode294802* le0, Tnode294802* ri0) { NIM_BOOL result0; { result0 = (NIM_BOOL)0; { if (!!((le0 == NIM_NIL))) goto LA3; { NI i_541364_839829468; NI HEX3Atmp_541376_839829468; NI LOC6; NI res_541379_839829468; i_541364_839829468 = (NI)0; HEX3Atmp_541376_839829468 = (NI)0; LOC6 = (NI)0; LOC6 = len_295081_850551059(ri0); HEX3Atmp_541376_839829468 = (LOC6 - 1); res_541379_839829468 = ((NI) 1); { while (1) { Tnode294802* r0; if (!(res_541379_839829468 <= HEX3Atmp_541376_839829468)) goto LA8; i_541364_839829468 = res_541379_839829468; r0 = HEX5BHEX5D_295238_850551059(ri0, i_541364_839829468); { Tanalysisresult475003 LOC11; LOC11 = (Tanalysisresult475003)0; LOC11 = ispartof_475340_788060399(le0, r0); if (!!((LOC11 == ((Tanalysisresult475003) 0)))) goto LA12; result0 = NIM_TRUE; goto BeforeRet; } LA12: ; res_541379_839829468 += ((NI) 1); } LA8: ; } } } LA3: ; }BeforeRet: ; return result0; } static N_INLINE(NIM_BOOL, hasnoinit_541383_839829468)(Tnode294802* call0) { NIM_BOOL result0; NIM_BOOL LOC1; result0 = (NIM_BOOL)0; LOC1 = (NIM_BOOL)0; LOC1 = ((*(*call0).kindU.S6.sons->data[((NI) 0)]).kind == ((Tnodekind294020) 3)); if (!(LOC1)) goto LA2; LOC1 = (((*(*(*call0).kindU.S6.sons->data[((NI) 0)]).kindU.S4.sym).flags &(1U<<((NU)(((Tsymflag294184) 12))&31U)))!=0); LA2: ; result0 = LOC1; return result0; } N_NIMCALL(void, resetloc_540350_839829468)(Tcproc531021* p0, Tloc294816* loc0) { NIM_BOOL containsgcref0; Ttype294840* typ0; { containsgcref0 = containsgarbagecollectedref_322117_3876443242((*loc0).t); typ0 = skiptypes_298099_850551059((*loc0).t, IL64(211106242013440)); { NIM_BOOL LOC3; LOC3 = (NIM_BOOL)0; LOC3 = isimportedcpptype_535476_839829468(typ0); if (!LOC3) goto LA4; goto BeforeRet; } LA4: ; { NIM_BOOL LOC8; LOC8 = (NIM_BOOL)0; LOC8 = iscomplexvaluetype_540317_839829468(typ0); if (!!(LOC8)) goto LA9; { Tloc294816 nilloc0; if (!containsgcref0) goto LA13; memset((void*)(&nilloc0), 0, sizeof(nilloc0)); initloc_534273_839829468((&nilloc0), ((Tlockind294808) 1), (*loc0).t, ((Tstorageloc294812) 2)); nilloc0.r = rope_180277_2381377266(((NimStringDesc*) &T839829468_174)); genrefassign_540311_839829468(p0, (*loc0), nilloc0, 8); } goto LA11; LA13: ; { TY180507 LOC16; memset((void*)LOC16, 0, sizeof(LOC16)); LOC16[0] = rdloc_540188_839829468((*loc0)); linefmt_534714_839829468(p0, ((Tcprocsection531011) 2), ((NimStringDesc*) &T839829468_494), LOC16, 1); } LA11: ; } goto LA6; LA9: ; { { TY180507 LOC22; if (!(((*p0).options &(1U<<((NU)(((Toption171009) 6))&31U)))!=0)) goto LA20; memset((void*)LOC22, 0, sizeof(LOC22)); LOC22[0] = addrloc_540204_839829468((*loc0)); linefmt_534714_839829468(p0, ((Tcprocsection531011) 2), ((NimStringDesc*) &T839829468_495), LOC22, 1); } LA20: ; { TY534811 LOC27; if (!!(((*loc0).s == ((Tstorageloc294812) 2)))) goto LA25; memset((void*)LOC27, 0, sizeof(LOC27)); LOC27[0] = addrloc_540204_839829468((*loc0)); LOC27[1] = gentypeinfo_537941_839829468((*p0).module, (*loc0).t); linefmt_534714_839829468(p0, ((Tcprocsection531011) 2), ((NimStringDesc*) &T839829468_496), LOC27, 2); genobjectinit_540242_839829468(p0, ((Tcprocsection531011) 2), (*loc0).t, (*loc0), NIM_TRUE); } goto LA23; LA25: ; { TY534811 LOC29; usestringh_534345_839829468((*p0).module); memset((void*)LOC29, 0, sizeof(LOC29)); LOC29[0] = addrloc_540204_839829468((*loc0)); LOC29[1] = rdloc_540188_839829468((*loc0)); linefmt_534714_839829468(p0, ((Tcprocsection531011) 2), ((NimStringDesc*) &T839829468_152), LOC29, 2); genobjectinit_540242_839829468(p0, ((Tcprocsection531011) 2), (*loc0).t, (*loc0), NIM_TRUE); } LA23: ; } LA6: ; }BeforeRet: ; } N_NIMCALL(Ropeobj180006*, addcomma_542464_839829468)(Ropeobj180006* r0) { Ropeobj180006* result0; result0 = (Ropeobj180006*)0; { if (!(r0 == NIM_NIL)) goto LA3; result0 = r0; } goto LA1; LA3: ; { TY535289 LOC6; Ropeobj180006* LOC7; memset((void*)LOC6, 0, sizeof(LOC6)); LOC7 = (Ropeobj180006*)0; LOC7 = HEX25_180905_2381377266(((NimStringDesc*) &T839829468_110), LOC6, 0); result0 = HEX26_180418_2381377266(r0, LOC7); } LA1: ; return result0; } N_NIMCALL(void, genclosurecall_542452_839829468)(Tcproc531021* p0, Tnode294802* le0, Tnode294802* ri0, Tloc294816* d0) { Tloc294816 op0; Ropeobj180006* pl0; Ttype294840* typ0; NI length0; Ropeobj180006* rawproc0; NimStringDesc* callpattern0; memset((void*)(&op0), 0, sizeof(op0)); initlocexpr_541283_839829468(p0, (*ri0).kindU.S6.sons->data[((NI) 0)], (&op0)); pl0 = (Ropeobj180006*)0; typ0 = skiptypes_298099_850551059((*(*ri0).kindU.S6.sons->data[((NI) 0)]).typ, IL64(211106232576256)); length0 = sonslen_297351_850551059(ri0); { NI i_542613_839829468; NI HEX3Atmp_543214_839829468; NI res_543217_839829468; i_542613_839829468 = (NI)0; HEX3Atmp_543214_839829468 = (NI)0; HEX3Atmp_543214_839829468 = (NI)(length0 - ((NI) 1)); res_543217_839829468 = ((NI) 1); { while (1) { if (!(res_543217_839829468 <= HEX3Atmp_543214_839829468)) goto LA3; i_542613_839829468 = res_543217_839829468; { NI LOC6; Tnode294802* paramtype0; LOC6 = (NI)0; LOC6 = sonslen_297327_850551059(typ0); if (!(i_542613_839829468 < LOC6)) goto LA7; paramtype0 = (*(*typ0).n).kindU.S6.sons->data[i_542613_839829468]; { NIM_BOOL LOC11; Ropeobj180006* LOC20; LOC11 = (NIM_BOOL)0; LOC11 = iscompiletimeonly_330706_3876443242((*paramtype0).typ); if (!!(LOC11)) goto LA12; { TY535289 LOC18; Ropeobj180006* LOC19; if (!!((pl0 == NIM_NIL))) goto LA16; memset((void*)LOC18, 0, sizeof(LOC18)); LOC19 = (Ropeobj180006*)0; LOC19 = HEX25_180905_2381377266(((NimStringDesc*) &T839829468_110), LOC18, 0); add_180482_2381377266(&pl0, LOC19); } LA16: ; LOC20 = (Ropeobj180006*)0; LOC20 = genarg_541787_839829468(p0, (*ri0).kindU.S6.sons->data[i_542613_839829468], (*paramtype0).kindU.S4.sym, ri0); add_180482_2381377266(&pl0, LOC20); } LA12: ; } goto LA4; LA7: ; { Ropeobj180006* LOC28; { TY535289 LOC26; Ropeobj180006* LOC27; if (!!((pl0 == NIM_NIL))) goto LA24; memset((void*)LOC26, 0, sizeof(LOC26)); LOC27 = (Ropeobj180006*)0; LOC27 = HEX25_180905_2381377266(((NimStringDesc*) &T839829468_110), LOC26, 0); add_180482_2381377266(&pl0, LOC27); } LA24: ; LOC28 = (Ropeobj180006*)0; LOC28 = genargnoparam_541938_839829468(p0, (*ri0).kindU.S6.sons->data[i_542613_839829468]); add_180482_2381377266(&pl0, LOC28); } LA4: ; res_543217_839829468 += ((NI) 1); } LA3: ; } } rawproc0 = getrawproctype_542459_839829468(p0, typ0); { if (!(((*typ0).flags &(1U<<((NU)(((Ttypeflag294431) 14))&31U)))!=0)) goto LA31; callpattern0 = copyString(((NimStringDesc*) &T839829468_492)); } goto LA29; LA31: ; { callpattern0 = copyString(((NimStringDesc*) &T839829468_493)); } LA29: ; { if (!!(((*typ0).sons->data[((NI) 0)] == NIM_NIL))) goto LA36; { NIM_BOOL LOC40; LOC40 = (NIM_BOOL)0; LOC40 = isinvalidreturntype_535548_839829468((*typ0).sons->data[((NI) 0)]); if (!LOC40) goto LA41; { NI LOC45; TY535289 LOC48; Ropeobj180006* LOC49; LOC45 = (NI)0; LOC45 = sonslen_297351_850551059(ri0); if (!(((NI) 1) < LOC45)) goto LA46; memset((void*)LOC48, 0, sizeof(LOC48)); LOC49 = (Ropeobj180006*)0; LOC49 = HEX25_180905_2381377266(((NimStringDesc*) &T839829468_110), LOC48, 0); add_180482_2381377266(&pl0, LOC49); } LA46: ; { NIM_BOOL LOC52; NIM_BOOL LOC54; Ropeobj180006* LOC67; NimStringDesc* LOC68; TY537235 LOC69; LOC52 = (NIM_BOOL)0; LOC52 = ((3 &(1U<<((NU)((*d0).k)&15U)))!=0); if (LOC52) goto LA53; LOC54 = (NIM_BOOL)0; LOC54 = leftappearsonrightside_541329_839829468(le0, ri0); LOC52 = !(LOC54); LA53: ; if (!LOC52) goto LA55; { if (!((*d0).k == ((Tlockind294808) 0))) goto LA59; gettemp_539032_839829468(p0, (*typ0).sons->data[((NI) 0)], d0, NIM_TRUE); } goto LA57; LA59: ; { NIM_BOOL LOC62; NIM_BOOL LOC64; LOC62 = (NIM_BOOL)0; LOC62 = !(((66 &(1U<<((NU)((*d0).k)&15U)))!=0)); if (!(LOC62)) goto LA63; LOC64 = (NIM_BOOL)0; LOC64 = hasnoinit_541383_839829468(ri0); LOC62 = !(LOC64); LA63: ; if (!LOC62) goto LA65; resetloc_540350_839829468(p0, d0); } goto LA57; LA65: ; LA57: ; LOC67 = (Ropeobj180006*)0; LOC67 = addrloc_540204_839829468((*d0)); add_180482_2381377266(&pl0, LOC67); LOC68 = (NimStringDesc*)0; LOC68 = rawNewString(callpattern0->Sup.len + 3); appendString(LOC68, callpattern0); appendString(LOC68, ((NimStringDesc*) &T839829468_497)); memset((void*)LOC69, 0, sizeof(LOC69)); LOC69[0] = op0.r; LOC69[1] = pl0; LOC69[2] = addcomma_542464_839829468(pl0); LOC69[3] = rawproc0; linef_534700_839829468(p0, ((Tcprocsection531011) 2), LOC68, LOC69, 4); } goto LA50; LA55: ; { Tloc294816 tmp0; Ropeobj180006* LOC71; NimStringDesc* LOC72; TY537235 LOC73; memset((void*)(&tmp0), 0, sizeof(tmp0)); gettemp_539032_839829468(p0, (*typ0).sons->data[((NI) 0)], (&tmp0), NIM_TRUE); LOC71 = (Ropeobj180006*)0; LOC71 = addrloc_540204_839829468(tmp0); add_180482_2381377266(&pl0, LOC71); LOC72 = (NimStringDesc*)0; LOC72 = rawNewString(callpattern0->Sup.len + 3); appendString(LOC72, callpattern0); appendString(LOC72, ((NimStringDesc*) &T839829468_497)); memset((void*)LOC73, 0, sizeof(LOC73)); LOC73[0] = op0.r; LOC73[1] = pl0; LOC73[2] = addcomma_542464_839829468(pl0); LOC73[3] = rawproc0; linef_534700_839829468(p0, ((Tcprocsection531011) 2), LOC72, LOC73, 4); genassignment_541264_839829468(p0, (*d0), tmp0, 0); } LA50: ; } goto LA38; LA41: ; { Tloc294816 list0; TY537235 LOC79; { if (!((*d0).k == ((Tlockind294808) 0))) goto LA77; gettemp_539032_839829468(p0, (*typ0).sons->data[((NI) 0)], d0, NIM_FALSE); } LA77: ; memset((void*)(&list0), 0, sizeof(list0)); initloc_534273_839829468((&list0), ((Tlockind294808) 9), (*d0).t, ((Tstorageloc294812) 0)); memset((void*)LOC79, 0, sizeof(LOC79)); LOC79[0] = op0.r; LOC79[1] = pl0; LOC79[2] = addcomma_542464_839829468(pl0); LOC79[3] = rawproc0; list0.r = HEX25_180905_2381377266(callpattern0, LOC79, 4); genassignment_541264_839829468(p0, (*d0), list0, 0); } LA38: ; } goto LA34; LA36: ; { NimStringDesc* LOC81; TY537235 LOC82; LOC81 = (NimStringDesc*)0; LOC81 = rawNewString(callpattern0->Sup.len + 3); appendString(LOC81, callpattern0); appendString(LOC81, ((NimStringDesc*) &T839829468_497)); memset((void*)LOC82, 0, sizeof(LOC82)); LOC82[0] = op0.r; LOC82[1] = pl0; LOC82[2] = addcomma_542464_839829468(pl0); LOC82[3] = rawproc0; linef_534700_839829468(p0, ((Tcprocsection531011) 2), LOC81, LOC82, 4); } LA34: ; } N_NIMCALL(Ropeobj180006*, genotherarg_541277_839829468)(Tcproc531021* p0, Tnode294802* ri0, NI i0, Ttype294840* typ0) { Ropeobj180006* result0; result0 = (Ropeobj180006*)0; { NI LOC3; Tnode294802* paramtype0; LOC3 = (NI)0; LOC3 = sonslen_297327_850551059(typ0); if (!(i0 < LOC3)) goto LA4; paramtype0 = (*(*typ0).n).kindU.S6.sons->data[i0]; { NIM_BOOL LOC8; LOC8 = (NIM_BOOL)0; LOC8 = iscompiletimeonly_330706_3876443242((*paramtype0).typ); if (!LOC8) goto LA9; result0 = NIM_NIL; } goto LA6; LA9: ; { NIM_BOOL LOC12; Tnode294802* LOC16; LOC12 = (NIM_BOOL)0; LOC12 = ((*(*typ0).sons->data[i0]).kind == ((Ttypekind294244) 23)); if (!(LOC12)) goto LA13; LOC12 = ((*(*ri0).kindU.S6.sons->data[i0]).kind == ((Tnodekind294020) 64)); LA13: ; if (!LOC12) goto LA14; LOC16 = (Tnode294802*)0; LOC16 = HEX5BHEX5D_295238_850551059((*ri0).kindU.S6.sons->data[i0], ((NI) 0)); result0 = genargnoparam_541938_839829468(p0, LOC16); } goto LA6; LA14: ; { result0 = genargnoparam_541938_839829468(p0, (*ri0).kindU.S6.sons->data[i0]); } LA6: ; } goto LA1; LA4: ; { { if (!!((((*typ0).flags &(1U<<((NU)(((Ttypeflag294431) 0))&31U)))!=0))) goto LA21; localerror_198085_155036129((*ri0).info, ((NimStringDesc*) &T839829468_501)); result0 = NIM_NIL; } goto LA19; LA21: ; { result0 = genargnoparam_541938_839829468(p0, (*ri0).kindU.S6.sons->data[i0]); } LA19: ; } LA1: ; return result0; } N_NIMCALL(Tnode294802*, skipaddrderef_543433_839829468)(Tnode294802* node0) { Tnode294802* result0; Tnode294802* n0; NIM_BOOL isaddr0; { result0 = (Tnode294802*)0; n0 = node0; isaddr0 = NIM_FALSE; switch ((*n0).kind) { case ((Tnodekind294020) 63): case ((Tnodekind294020) 64): { n0 = (*n0).kindU.S6.sons->data[((NI) 0)]; isaddr0 = NIM_TRUE; } break; case ((Tnodekind294020) 47): case ((Tnodekind294020) 65): { n0 = (*n0).kindU.S6.sons->data[((NI) 0)]; } break; default: { result0 = n0; goto BeforeRet; } break; } { if (!((*n0).kind == ((Tnodekind294020) 66))) goto LA6; n0 = (*n0).kindU.S6.sons->data[((NI) 0)]; } LA6: ; { NIM_BOOL LOC10; LOC10 = (NIM_BOOL)0; LOC10 = isaddr0; if (!(LOC10)) goto LA11; LOC10 = ((*n0).kind == ((Tnodekind294020) 47) || (*n0).kind == ((Tnodekind294020) 65)); LA11: ; if (!LOC10) goto LA12; result0 = (*n0).kindU.S6.sons->data[((NI) 0)]; } goto LA8; LA12: ; { if (!((*n0).kind == ((Tnodekind294020) 63) || (*n0).kind == ((Tnodekind294020) 64))) goto LA15; result0 = (*n0).kindU.S6.sons->data[((NI) 0)]; } goto LA8; LA15: ; { result0 = node0; } LA8: ; }BeforeRet: ; return result0; } N_NIMCALL(Ropeobj180006*, genthisarg_543475_839829468)(Tcproc531021* p0, Tnode294802* ri_543478_839829468, NI i0, Ttype294840* typ0) { Ropeobj180006* result0; Tnode294802* ri0; Ttype294840* t0; result0 = (Ropeobj180006*)0; { NI LOC3; NimStringDesc* LOC6; LOC3 = (NI)0; LOC3 = sonslen_297327_850551059(typ0); if (!!((i0 < LOC3))) goto LA4; LOC6 = (NimStringDesc*)0; LOC6 = HEX24_198185_1689653243(T839829468_503); internalerror_198113_155036129(LOC6); } LA4: ; ri0 = HEX5BHEX5D_295238_850551059(ri_543478_839829468, i0); { while (1) { if (!((*ri0).kind == ((Tnodekind294020) 66))) goto LA8; ri0 = HEX5BHEX5D_295238_850551059(ri0, ((NI) 0)); } LA8: ; } t0 = skiptypes_298099_850551059((*typ0).sons->data[i0], 2048); { Tnode294802* x0; if (!((*t0).kind == ((Ttypekind294244) 23))) goto LA11; { if (!((*ri0).kind == ((Tnodekind294020) 64))) goto LA15; x0 = HEX5BHEX5D_295238_850551059(ri0, ((NI) 0)); } goto LA13; LA15: ; { x0 = ri0; } LA13: ; { if (!((*(*x0).typ).kind == ((Ttypekind294244) 21))) goto LA20; result0 = genargnoparam_541938_839829468(p0, x0); add_180487_2381377266(&result0, ((NimStringDesc*) &T839829468_504)); } goto LA18; LA20: ; { NIM_BOOL LOC23; Tnode294802* LOC25; Tnode294802* LOC28; LOC23 = (NIM_BOOL)0; LOC23 = ((*x0).kind == ((Tnodekind294020) 65) || (*x0).kind == ((Tnodekind294020) 47)); if (!(LOC23)) goto LA24; LOC25 = (Tnode294802*)0; LOC25 = HEX5BHEX5D_295238_850551059(x0, ((NI) 0)); LOC23 = ((*(*LOC25).typ).kind == ((Ttypekind294244) 21)); LA24: ; if (!LOC23) goto LA26; LOC28 = (Tnode294802*)0; LOC28 = HEX5BHEX5D_295238_850551059(x0, ((NI) 0)); result0 = genargnoparam_541938_839829468(p0, LOC28); add_180487_2381377266(&result0, ((NimStringDesc*) &T839829468_504)); } goto LA18; LA26: ; { result0 = genargnoparam_541938_839829468(p0, x0); add_180487_2381377266(&result0, ((NimStringDesc*) &T839829468_257)); } LA18: ; } goto LA9; LA11: ; { if (!((*t0).kind == ((Ttypekind294244) 21))) goto LA31; { Tnode294802* LOC37; if (!((*ri0).kind == ((Tnodekind294020) 63) || (*ri0).kind == ((Tnodekind294020) 64))) goto LA35; LOC37 = (Tnode294802*)0; LOC37 = HEX5BHEX5D_295238_850551059(ri0, ((NI) 0)); result0 = genargnoparam_541938_839829468(p0, LOC37); add_180487_2381377266(&result0, ((NimStringDesc*) &T839829468_257)); } goto LA33; LA35: ; { result0 = genargnoparam_541938_839829468(p0, ri0); add_180487_2381377266(&result0, ((NimStringDesc*) &T839829468_504)); } LA33: ; } goto LA9; LA31: ; { ri0 = skipaddrderef_543433_839829468(ri0); { if (!((*ri0).kind == ((Tnodekind294020) 63) || (*ri0).kind == ((Tnodekind294020) 64))) goto LA42; ri0 = HEX5BHEX5D_295238_850551059(ri0, ((NI) 0)); } LA42: ; result0 = genargnoparam_541938_839829468(p0, ri0); add_180487_2381377266(&result0, ((NimStringDesc*) &T839829468_257)); } LA9: ; return result0; } N_NIMCALL(Ropeobj180006*, genpatterncall_543699_839829468)(Tcproc531021* p0, Tnode294802* ri_543702_839829468, NimStringDesc* pat0, Ttype294840* typ_543704_839829468) { Ropeobj180006* result0; NI i0; NI j0; result0 = (Ropeobj180006*)0; i0 = ((NI) 0); j0 = ((NI) 1); { while (1) { if (!(i0 < (pat0 ? pat0->Sup.len : 0))) goto LA2; switch (((NU8)(pat0->data[i0]))) { case 64: { { NI LOC6; Ropeobj180006* LOC9; LOC6 = (NI)0; LOC6 = len_295081_850551059(ri_543702_839829468); if (!(j0 < LOC6)) goto LA7; LOC9 = (Ropeobj180006*)0; LOC9 = genotherarg_541277_839829468(p0, ri_543702_839829468, j0, typ_543704_839829468); add_180482_2381377266(&result0, LOC9); { NI k_543728_839829468; NI HEX3Atmp_543904_839829468; NI HEX3Atmp_543905_839829468; NI LOC11; NI res_543908_839829468; k_543728_839829468 = (NI)0; HEX3Atmp_543904_839829468 = (NI)0; HEX3Atmp_543905_839829468 = (NI)0; HEX3Atmp_543904_839829468 = (NI)(j0 + ((NI) 1)); LOC11 = (NI)0; LOC11 = len_295081_850551059(ri_543702_839829468); HEX3Atmp_543905_839829468 = (LOC11 - 1); res_543908_839829468 = HEX3Atmp_543904_839829468; { while (1) { TY535289 LOC14; Ropeobj180006* LOC15; Ropeobj180006* LOC16; if (!(res_543908_839829468 <= HEX3Atmp_543905_839829468)) goto LA13; k_543728_839829468 = res_543908_839829468; memset((void*)LOC14, 0, sizeof(LOC14)); LOC15 = (Ropeobj180006*)0; LOC15 = HEX25_180905_2381377266(((NimStringDesc*) &T839829468_110), LOC14, 0); add_180482_2381377266(&result0, LOC15); LOC16 = (Ropeobj180006*)0; LOC16 = genotherarg_541277_839829468(p0, ri_543702_839829468, k_543728_839829468, typ_543704_839829468); add_180482_2381377266(&result0, LOC16); res_543908_839829468 += ((NI) 1); } LA13: ; } } } LA7: ; i0 += ((NI) 1); } break; case 35: { { Tnode294802* ri0; if (!(((NU8)(pat0->data[(NI)(i0 + ((NI) 1))])) == ((NU8)(43)) || ((NU8)(pat0->data[(NI)(i0 + ((NI) 1))])) == ((NU8)(64)))) goto LA20; ri0 = HEX5BHEX5D_295238_850551059(ri_543702_839829468, j0); { Ttype294840* typ0; TY535289 LOC31; Ropeobj180006* LOC32; TY535289 LOC46; Ropeobj180006* LOC47; if (!((*ri0).kind == ((Tnodekind294020) 27) || (*ri0).kind == ((Tnodekind294020) 29) || (*ri0).kind == ((Tnodekind294020) 30) || (*ri0).kind == ((Tnodekind294020) 31) || (*ri0).kind == ((Tnodekind294020) 26) || (*ri0).kind == ((Tnodekind294020) 28) || (*ri0).kind == ((Tnodekind294020) 32))) goto LA24; typ0 = skiptypes_298099_850551059((*(*ri0).kindU.S6.sons->data[((NI) 0)]).typ, IL64(211106232576256)); { Ropeobj180006* LOC30; if (!((NU8)(pat0->data[(NI)(i0 + ((NI) 1))]) == (NU8)(43))) goto LA28; LOC30 = (Ropeobj180006*)0; LOC30 = genargnoparam_541938_839829468(p0, (*ri0).kindU.S6.sons->data[((NI) 0)]); add_180482_2381377266(&result0, LOC30); } LA28: ; memset((void*)LOC31, 0, sizeof(LOC31)); LOC32 = (Ropeobj180006*)0; LOC32 = HEX25_180905_2381377266(((NimStringDesc*) &T839829468_118), LOC31, 0); add_180482_2381377266(&result0, LOC32); { NI LOC35; Ropeobj180006* LOC38; LOC35 = (NI)0; LOC35 = len_295081_850551059(ri0); if (!(((NI) 1) < LOC35)) goto LA36; LOC38 = (Ropeobj180006*)0; LOC38 = genotherarg_541277_839829468(p0, ri0, ((NI) 1), typ0); add_180482_2381377266(&result0, LOC38); } LA36: ; { NI k_543793_839829468; NI HEX3Atmp_543915_839829468; NI HEX3Atmp_543916_839829468; NI LOC40; NI res_543919_839829468; k_543793_839829468 = (NI)0; HEX3Atmp_543915_839829468 = (NI)0; HEX3Atmp_543916_839829468 = (NI)0; HEX3Atmp_543915_839829468 = (NI)(j0 + ((NI) 1)); LOC40 = (NI)0; LOC40 = len_295081_850551059(ri0); HEX3Atmp_543916_839829468 = (LOC40 - 1); res_543919_839829468 = HEX3Atmp_543915_839829468; { while (1) { TY535289 LOC43; Ropeobj180006* LOC44; Ropeobj180006* LOC45; if (!(res_543919_839829468 <= HEX3Atmp_543916_839829468)) goto LA42; k_543793_839829468 = res_543919_839829468; memset((void*)LOC43, 0, sizeof(LOC43)); LOC44 = (Ropeobj180006*)0; LOC44 = HEX25_180905_2381377266(((NimStringDesc*) &T839829468_110), LOC43, 0); add_180482_2381377266(&result0, LOC44); LOC45 = (Ropeobj180006*)0; LOC45 = genotherarg_541277_839829468(p0, ri0, k_543793_839829468, typ0); add_180482_2381377266(&result0, LOC45); res_543919_839829468 += ((NI) 1); } LA42: ; } } memset((void*)LOC46, 0, sizeof(LOC46)); LOC47 = (Ropeobj180006*)0; LOC47 = HEX25_180905_2381377266(((NimStringDesc*) &T839829468_117), LOC46, 0); add_180482_2381377266(&result0, LOC47); } goto LA22; LA24: ; { localerror_198085_155036129((*ri0).info, ((NimStringDesc*) &T839829468_502)); } LA22: ; i0 += ((NI) 1); } goto LA18; LA20: ; { Ropeobj180006* LOC52; if (!((NU8)(pat0->data[(NI)(i0 + ((NI) 1))]) == (NU8)(46))) goto LA50; LOC52 = (Ropeobj180006*)0; LOC52 = genthisarg_543475_839829468(p0, ri_543702_839829468, j0, typ_543704_839829468); add_180482_2381377266(&result0, LOC52); i0 += ((NI) 1); } goto LA18; LA50: ; { Tnode294802* arg0; Ropeobj180006* LOC58; if (!((NU8)(pat0->data[(NI)(i0 + ((NI) 1))]) == (NU8)(91))) goto LA54; arg0 = skipaddrderef_543433_839829468((*ri_543702_839829468).kindU.S6.sons->data[j0]); { while (1) { if (!((*arg0).kind == ((Tnodekind294020) 63) || (*arg0).kind == ((Tnodekind294020) 64) || (*arg0).kind == ((Tnodekind294020) 66))) goto LA57; arg0 = HEX5BHEX5D_295238_850551059(arg0, ((NI) 0)); } LA57: ; } LOC58 = (Ropeobj180006*)0; LOC58 = genargnoparam_541938_839829468(p0, arg0); add_180482_2381377266(&result0, LOC58); } goto LA18; LA54: ; { Ropeobj180006* LOC60; LOC60 = (Ropeobj180006*)0; LOC60 = genotherarg_541277_839829468(p0, ri_543702_839829468, j0, typ_543704_839829468); add_180482_2381377266(&result0, LOC60); } LA18: ; j0 += ((NI) 1); i0 += ((NI) 1); } break; case 39: { NI idx0; NI stars0; idx0 = (NI)0; stars0 = (NI)0; { NIM_BOOL LOC64; Ttype294840* t0; LOC64 = (NIM_BOOL)0; LOC64 = scancppgenericslot_536827_839829468(pat0, (&i0), (&idx0), (&stars0)); if (!LOC64) goto LA65; t0 = resolvestarsincpptype_536891_839829468(typ_543704_839829468, idx0, stars0); { TY535289 LOC71; Ropeobj180006* LOC72; if (!(t0 == NIM_NIL)) goto LA69; memset((void*)LOC71, 0, sizeof(LOC71)); LOC72 = (Ropeobj180006*)0; LOC72 = HEX25_180905_2381377266(((NimStringDesc*) &T839829468_26), LOC71, 0); add_180482_2381377266(&result0, LOC72); } goto LA67; LA69: ; { Ropeobj180006* LOC74; LOC74 = (Ropeobj180006*)0; LOC74 = gettypedesc_537671_839829468((*p0).module, t0); add_180482_2381377266(&result0, LOC74); } LA67: ; } LA65: ; } break; default: { NI start0; start0 = i0; { while (1) { if (!(i0 < (pat0 ? pat0->Sup.len : 0))) goto LA77; { if (!!((((NU8)(pat0->data[i0])) == ((NU8)(64)) || ((NU8)(pat0->data[i0])) == ((NU8)(35)) || ((NU8)(pat0->data[i0])) == ((NU8)(39))))) goto LA80; i0 += ((NI) 1); } goto LA78; LA80: ; { goto LA76; } LA78: ; } LA77: ; } LA76: ; { NimStringDesc* LOC87; if (!(start0 <= (NI)(i0 - ((NI) 1)))) goto LA85; LOC87 = (NimStringDesc*)0; LOC87 = copyStrLast(pat0, start0, (NI)(i0 - ((NI) 1))); add_180487_2381377266(&result0, LOC87); } LA85: ; } break; } } LA2: ; } return result0; } N_NIMCALL(void, fixupcall_541410_839829468)(Tcproc531021* p0, Tnode294802* le0, Tnode294802* ri0, Tloc294816* d0, Ropeobj180006* callee0, Ropeobj180006* params0) { Ropeobj180006* pl0; TY535289 LOC1; Ropeobj180006* LOC2; Ropeobj180006* LOC3; Ttype294840* typ0; memset((void*)LOC1, 0, sizeof(LOC1)); LOC2 = (Ropeobj180006*)0; LOC2 = HEX25_180905_2381377266(((NimStringDesc*) &T839829468_118), LOC1, 0); LOC3 = (Ropeobj180006*)0; LOC3 = HEX26_180418_2381377266(callee0, LOC2); pl0 = HEX26_180418_2381377266(LOC3, params0); typ0 = skiptypes_298099_850551059((*(*ri0).kindU.S6.sons->data[((NI) 0)]).typ, IL64(211106232576256)); { if (!!(((*typ0).sons->data[((NI) 0)] == NIM_NIL))) goto LA6; { NIM_BOOL LOC10; LOC10 = (NIM_BOOL)0; LOC10 = isinvalidreturntype_535548_839829468((*typ0).sons->data[((NI) 0)]); if (!LOC10) goto LA11; { TY535289 LOC17; Ropeobj180006* LOC18; if (!!((params0 == NIM_NIL))) goto LA15; memset((void*)LOC17, 0, sizeof(LOC17)); LOC18 = (Ropeobj180006*)0; LOC18 = HEX25_180905_2381377266(((NimStringDesc*) &T839829468_110), LOC17, 0); add_180482_2381377266(&pl0, LOC18); } LA15: ; { NIM_BOOL LOC21; NIM_BOOL LOC23; Ropeobj180006* LOC36; TY535289 LOC37; Ropeobj180006* LOC38; LOC21 = (NIM_BOOL)0; LOC21 = ((3 &(1U<<((NU)((*d0).k)&15U)))!=0); if (LOC21) goto LA22; LOC23 = (NIM_BOOL)0; LOC23 = leftappearsonrightside_541329_839829468(le0, ri0); LOC21 = !(LOC23); LA22: ; if (!LOC21) goto LA24; { if (!((*d0).k == ((Tlockind294808) 0))) goto LA28; gettemp_539032_839829468(p0, (*typ0).sons->data[((NI) 0)], d0, NIM_TRUE); } goto LA26; LA28: ; { NIM_BOOL LOC31; NIM_BOOL LOC33; LOC31 = (NIM_BOOL)0; LOC31 = !(((66 &(1U<<((NU)((*d0).k)&15U)))!=0)); if (!(LOC31)) goto LA32; LOC33 = (NIM_BOOL)0; LOC33 = hasnoinit_541383_839829468(ri0); LOC31 = !(LOC33); LA32: ; if (!LOC31) goto LA34; resetloc_540350_839829468(p0, d0); } goto LA26; LA34: ; LA26: ; LOC36 = (Ropeobj180006*)0; LOC36 = addrloc_540204_839829468((*d0)); add_180482_2381377266(&pl0, LOC36); memset((void*)LOC37, 0, sizeof(LOC37)); LOC38 = (Ropeobj180006*)0; LOC38 = HEX25_180905_2381377266(((NimStringDesc*) &T839829468_505), LOC37, 0); add_180482_2381377266(&pl0, LOC38); line_534690_839829468(p0, ((Tcprocsection531011) 2), pl0); } goto LA19; LA24: ; { Tloc294816 tmp0; Ropeobj180006* LOC40; TY535289 LOC41; Ropeobj180006* LOC42; memset((void*)(&tmp0), 0, sizeof(tmp0)); gettemp_539032_839829468(p0, (*typ0).sons->data[((NI) 0)], (&tmp0), NIM_TRUE); LOC40 = (Ropeobj180006*)0; LOC40 = addrloc_540204_839829468(tmp0); add_180482_2381377266(&pl0, LOC40); memset((void*)LOC41, 0, sizeof(LOC41)); LOC42 = (Ropeobj180006*)0; LOC42 = HEX25_180905_2381377266(((NimStringDesc*) &T839829468_505), LOC41, 0); add_180482_2381377266(&pl0, LOC42); line_534690_839829468(p0, ((Tcprocsection531011) 2), pl0); genassignment_541264_839829468(p0, (*d0), tmp0, 0); } LA19: ; } goto LA8; LA11: ; { TY535289 LOC44; Ropeobj180006* LOC45; memset((void*)LOC44, 0, sizeof(LOC44)); LOC45 = (Ropeobj180006*)0; LOC45 = HEX25_180905_2381377266(((NimStringDesc*) &T839829468_117), LOC44, 0); add_180482_2381377266(&pl0, LOC45); { NIM_BOOL LOC48; NIM_BOOL LOC49; LOC48 = (NIM_BOOL)0; LOC49 = (NIM_BOOL)0; LOC49 = (gcmd_171132_2607990831 == ((Tcommands171076) 2)); if (LOC49) goto LA50; LOC49 = (((*(*(*p0).module).module).flags &(1U<<((NU)(((Tsymflag294184) 27))&31U)))!=0); LA50: ; LOC48 = LOC49; if (!(LOC48)) goto LA51; LOC48 = (((*d0).flags &(1U<<((NU)(((Tlocflag294810) 8))&15U)))!=0); LA51: ; if (!LOC48) goto LA52; (*d0).k = ((Tlockind294808) 9); unsureAsgnRef((void**) (&(*d0).r), pl0); (*d0).flags &= ~(((NU16)1) << ((((Tlocflag294810) 8)) % (sizeof(NU16)*8))); } goto LA46; LA52: ; { Tloc294816 list0; { if (!((*d0).k == ((Tlockind294808) 0))) goto LA57; gettemp_539032_839829468(p0, (*typ0).sons->data[((NI) 0)], d0, NIM_FALSE); } LA57: ; memset((void*)(&list0), 0, sizeof(list0)); initloc_534273_839829468((&list0), ((Tlockind294808) 9), (*d0).t, ((Tstorageloc294812) 0)); list0.r = pl0; genassignment_541264_839829468(p0, (*d0), list0, 0); } LA46: ; } LA8: ; } goto LA4; LA6: ; { TY535289 LOC60; Ropeobj180006* LOC61; memset((void*)LOC60, 0, sizeof(LOC60)); LOC61 = (Ropeobj180006*)0; LOC61 = HEX25_180905_2381377266(((NimStringDesc*) &T839829468_505), LOC60, 0); add_180482_2381377266(&pl0, LOC61); line_534690_839829468(p0, ((Tcprocsection531011) 2), pl0); } LA4: ; } N_NIMCALL(void, geninfixcall_543929_839829468)(Tcproc531021* p0, Tnode294802* le0, Tnode294802* ri0, Tloc294816* d0) { Tloc294816 op0; Ttype294840* typ_543940_839829468; NI length0; NimStringDesc* pat0; memset((void*)(&op0), 0, sizeof(op0)); initlocexpr_541283_839829468(p0, (*ri0).kindU.S6.sons->data[((NI) 0)], (&op0)); typ_543940_839829468 = skiptypes_298099_850551059((*(*ri0).kindU.S6.sons->data[((NI) 0)]).typ, IL64(211106232576256)); length0 = sonslen_297351_850551059(ri0); pat0 = (*(*(*(*ri0).kindU.S6.sons->data[((NI) 0)]).kindU.S4.sym).loc.r).data; { NimStringDesc* LOC5; if (!!(!((pat0 == NIM_NIL)))) goto LA3; LOC5 = (NimStringDesc*)0; LOC5 = HEX24_198185_1689653243(T839829468_498); internalerror_198113_155036129(LOC5); } LA3: ; { NIM_BOOL LOC8; Ropeobj180006* pl0; Ttype294840* typ0; LOC8 = (NIM_BOOL)0; LOC8 = contains_110056_4286263276(pat0, T839829468_500); if (!LOC8) goto LA9; pl0 = genpatterncall_543699_839829468(p0, ri0, pat0, typ_543940_839829468); typ0 = skiptypes_298099_850551059((*(*ri0).kindU.S6.sons->data[((NI) 0)]).typ, IL64(211106232576256)); { if (!!(((*typ0).sons->data[((NI) 0)] == NIM_NIL))) goto LA13; { NIM_BOOL LOC17; NIM_BOOL LOC18; LOC17 = (NIM_BOOL)0; LOC18 = (NIM_BOOL)0; LOC18 = (gcmd_171132_2607990831 == ((Tcommands171076) 2)); if (LOC18) goto LA19; LOC18 = (((*(*(*p0).module).module).flags &(1U<<((NU)(((Tsymflag294184) 27))&31U)))!=0); LA19: ; LOC17 = LOC18; if (!(LOC17)) goto LA20; LOC17 = (((*d0).flags &(1U<<((NU)(((Tlocflag294810) 8))&15U)))!=0); LA20: ; if (!LOC17) goto LA21; (*d0).k = ((Tlockind294808) 9); unsureAsgnRef((void**) (&(*d0).r), pl0); (*d0).flags &= ~(((NU16)1) << ((((Tlocflag294810) 8)) % (sizeof(NU16)*8))); } goto LA15; LA21: ; { Tloc294816 list0; { if (!((*d0).k == ((Tlockind294808) 0))) goto LA26; gettemp_539032_839829468(p0, (*typ0).sons->data[((NI) 0)], d0, NIM_FALSE); } LA26: ; memset((void*)(&list0), 0, sizeof(list0)); initloc_534273_839829468((&list0), ((Tlockind294808) 9), (*d0).t, ((Tstorageloc294812) 0)); list0.r = pl0; genassignment_541264_839829468(p0, (*d0), list0, 0); } LA15: ; } goto LA11; LA13: ; { TY535289 LOC29; Ropeobj180006* LOC30; memset((void*)LOC29, 0, sizeof(LOC29)); LOC30 = (Ropeobj180006*)0; LOC30 = HEX25_180905_2381377266(((NimStringDesc*) &T839829468_497), LOC29, 0); add_180482_2381377266(&pl0, LOC30); line_534690_839829468(p0, ((Tcprocsection531011) 2), pl0); } LA11: ; } goto LA6; LA9: ; { Ropeobj180006* pl0; Ropeobj180006* params0; pl0 = NIM_NIL; { NI LOC34; Ropeobj180006* LOC37; LOC34 = (NI)0; LOC34 = len_295081_850551059(ri0); if (!(((NI) 1) < LOC34)) goto LA35; LOC37 = (Ropeobj180006*)0; LOC37 = genthisarg_543475_839829468(p0, ri0, ((NI) 1), typ_543940_839829468); add_180482_2381377266(&pl0, LOC37); } LA35: ; add_180482_2381377266(&pl0, op0.r); params0 = (Ropeobj180006*)0; { NI i_544425_839829468; NI HEX3Atmp_544609_839829468; NI res_544612_839829468; i_544425_839829468 = (NI)0; HEX3Atmp_544609_839829468 = (NI)0; HEX3Atmp_544609_839829468 = (NI)(length0 - ((NI) 1)); res_544612_839829468 = ((NI) 2); { while (1) { Ropeobj180006* LOC47; if (!(res_544612_839829468 <= HEX3Atmp_544609_839829468)) goto LA40; i_544425_839829468 = res_544612_839829468; { TY535289 LOC45; Ropeobj180006* LOC46; if (!!((params0 == NIM_NIL))) goto LA43; memset((void*)LOC45, 0, sizeof(LOC45)); LOC46 = (Ropeobj180006*)0; LOC46 = HEX25_180905_2381377266(((NimStringDesc*) &T839829468_110), LOC45, 0); add_180482_2381377266(&params0, LOC46); } LA43: ; LOC47 = (Ropeobj180006*)0; LOC47 = genotherarg_541277_839829468(p0, ri0, i_544425_839829468, typ_543940_839829468); add_180482_2381377266(&params0, LOC47); res_544612_839829468 += ((NI) 1); } LA40: ; } } fixupcall_541410_839829468(p0, le0, ri0, d0, pl0, params0); } LA6: ; } N_NIMCALL(void, gennamedparamcall_544616_839829468)(Tcproc531021* p0, Tnode294802* ri0, Tloc294816* d0) { Tloc294816 op0; Ropeobj180006* pl0; TY535289 LOC1; Ttype294840* typ0; NI length0; NimStringDesc* pat0; NI start0; memset((void*)(&op0), 0, sizeof(op0)); initlocexpr_541283_839829468(p0, (*ri0).kindU.S6.sons->data[((NI) 0)], (&op0)); memset((void*)LOC1, 0, sizeof(LOC1)); pl0 = HEX25_180905_2381377266(((NimStringDesc*) &T839829468_506), LOC1, 0); typ0 = skiptypes_298099_850551059((*(*ri0).kindU.S6.sons->data[((NI) 0)]).typ, IL64(211106232576256)); length0 = sonslen_297351_850551059(ri0); pat0 = (*(*(*(*ri0).kindU.S6.sons->data[((NI) 0)]).kindU.S4.sym).loc.r).data; { NimStringDesc* LOC6; if (!!(!((pat0 == NIM_NIL)))) goto LA4; LOC6 = (NimStringDesc*)0; LOC6 = HEX24_198185_1689653243(T839829468_507); internalerror_198113_155036129(LOC6); } LA4: ; start0 = ((NI) 3); { NIM_BOOL LOC9; LOC9 = (NIM_BOOL)0; LOC9 = contains_110046_4286263276(pat0, 32); if (!LOC9) goto LA10; start0 = ((NI) 1); add_180482_2381377266(&pl0, op0.r); { TY535289 LOC16; Ropeobj180006* LOC17; Ropeobj180006* LOC18; if (!(((NI) 1) < length0)) goto LA14; memset((void*)LOC16, 0, sizeof(LOC16)); LOC17 = (Ropeobj180006*)0; LOC17 = HEX25_180905_2381377266(((NimStringDesc*) &T839829468_244), LOC16, 0); add_180482_2381377266(&pl0, LOC17); LOC18 = (Ropeobj180006*)0; LOC18 = genarg_541787_839829468(p0, (*ri0).kindU.S6.sons->data[((NI) 1)], (*(*(*typ0).n).kindU.S6.sons->data[((NI) 1)]).kindU.S4.sym, ri0); add_180482_2381377266(&pl0, LOC18); start0 = ((NI) 2); } LA14: ; } goto LA7; LA10: ; { { Ropeobj180006* LOC24; TY535289 LOC25; Ropeobj180006* LOC26; if (!(((NI) 1) < length0)) goto LA22; LOC24 = (Ropeobj180006*)0; LOC24 = genarg_541787_839829468(p0, (*ri0).kindU.S6.sons->data[((NI) 1)], (*(*(*typ0).n).kindU.S6.sons->data[((NI) 1)]).kindU.S4.sym, ri0); add_180482_2381377266(&pl0, LOC24); memset((void*)LOC25, 0, sizeof(LOC25)); LOC26 = (Ropeobj180006*)0; LOC26 = HEX25_180905_2381377266(((NimStringDesc*) &T839829468_111), LOC25, 0); add_180482_2381377266(&pl0, LOC26); } LA22: ; add_180482_2381377266(&pl0, op0.r); { TY535289 LOC31; Ropeobj180006* LOC32; Ropeobj180006* LOC33; if (!(((NI) 2) < length0)) goto LA29; memset((void*)LOC31, 0, sizeof(LOC31)); LOC32 = (Ropeobj180006*)0; LOC32 = HEX25_180905_2381377266(((NimStringDesc*) &T839829468_244), LOC31, 0); add_180482_2381377266(&pl0, LOC32); LOC33 = (Ropeobj180006*)0; LOC33 = genarg_541787_839829468(p0, (*ri0).kindU.S6.sons->data[((NI) 2)], (*(*(*typ0).n).kindU.S6.sons->data[((NI) 2)]).kindU.S4.sym, ri0); add_180482_2381377266(&pl0, LOC33); } LA29: ; } LA7: ; { NI i_545051_839829468; NI HEX3Atmp_545617_839829468; NI res_545620_839829468; i_545051_839829468 = (NI)0; HEX3Atmp_545617_839829468 = (NI)0; HEX3Atmp_545617_839829468 = (NI)(length0 - ((NI) 1)); res_545620_839829468 = start0; { while (1) { Tsym294834* param0; TY535289 LOC42; Ropeobj180006* LOC43; TY535289 LOC44; Ropeobj180006* LOC45; Ropeobj180006* LOC46; if (!(res_545620_839829468 <= HEX3Atmp_545617_839829468)) goto LA36; i_545051_839829468 = res_545620_839829468; { NI LOC39; LOC39 = (NI)0; LOC39 = sonslen_297327_850551059(typ0); if (!(LOC39 <= i_545051_839829468)) goto LA40; internalerror_198100_155036129((*ri0).info, ((NimStringDesc*) &T839829468_508)); } LA40: ; param0 = (*(*(*typ0).n).kindU.S6.sons->data[i_545051_839829468]).kindU.S4.sym; memset((void*)LOC42, 0, sizeof(LOC42)); LOC43 = (Ropeobj180006*)0; LOC43 = HEX25_180905_2381377266(((NimStringDesc*) &T839829468_111), LOC42, 0); add_180482_2381377266(&pl0, LOC43); add_180487_2381377266(&pl0, (*(*param0).name).s); memset((void*)LOC44, 0, sizeof(LOC44)); LOC45 = (Ropeobj180006*)0; LOC45 = HEX25_180905_2381377266(((NimStringDesc*) &T839829468_244), LOC44, 0); add_180482_2381377266(&pl0, LOC45); LOC46 = (Ropeobj180006*)0; LOC46 = genarg_541787_839829468(p0, (*ri0).kindU.S6.sons->data[i_545051_839829468], param0, ri0); add_180482_2381377266(&pl0, LOC46); res_545620_839829468 += ((NI) 1); } LA36: ; } } { if (!!(((*typ0).sons->data[((NI) 0)] == NIM_NIL))) goto LA49; { NIM_BOOL LOC53; LOC53 = (NIM_BOOL)0; LOC53 = isinvalidreturntype_535548_839829468((*typ0).sons->data[((NI) 0)]); if (!LOC53) goto LA54; { NI LOC58; TY535289 LOC61; Ropeobj180006* LOC62; LOC58 = (NI)0; LOC58 = sonslen_297351_850551059(ri0); if (!(((NI) 1) < LOC58)) goto LA59; memset((void*)LOC61, 0, sizeof(LOC61)); LOC62 = (Ropeobj180006*)0; LOC62 = HEX25_180905_2381377266(((NimStringDesc*) &T839829468_111), LOC61, 0); add_180482_2381377266(&pl0, LOC62); } LA59: ; { TY535289 LOC71; Ropeobj180006* LOC72; Ropeobj180006* LOC73; TY535289 LOC74; Ropeobj180006* LOC75; if (!((3 &(1U<<((NU)((*d0).k)&15U)))!=0)) goto LA65; { if (!((*d0).k == ((Tlockind294808) 0))) goto LA69; gettemp_539032_839829468(p0, (*typ0).sons->data[((NI) 0)], d0, NIM_TRUE); } LA69: ; memset((void*)LOC71, 0, sizeof(LOC71)); LOC72 = (Ropeobj180006*)0; LOC72 = HEX25_180905_2381377266(((NimStringDesc*) &T839829468_509), LOC71, 0); add_180482_2381377266(&pl0, LOC72); LOC73 = (Ropeobj180006*)0; LOC73 = addrloc_540204_839829468((*d0)); add_180482_2381377266(&pl0, LOC73); memset((void*)LOC74, 0, sizeof(LOC74)); LOC75 = (Ropeobj180006*)0; LOC75 = HEX25_180905_2381377266(((NimStringDesc*) &T839829468_510), LOC74, 0); add_180482_2381377266(&pl0, LOC75); line_534690_839829468(p0, ((Tcprocsection531011) 2), pl0); } goto LA63; LA65: ; { Tloc294816 tmp0; Ropeobj180006* LOC77; TY535289 LOC78; Ropeobj180006* LOC79; memset((void*)(&tmp0), 0, sizeof(tmp0)); gettemp_539032_839829468(p0, (*typ0).sons->data[((NI) 0)], (&tmp0), NIM_TRUE); LOC77 = (Ropeobj180006*)0; LOC77 = addrloc_540204_839829468(tmp0); add_180482_2381377266(&pl0, LOC77); memset((void*)LOC78, 0, sizeof(LOC78)); LOC79 = (Ropeobj180006*)0; LOC79 = HEX25_180905_2381377266(((NimStringDesc*) &T839829468_510), LOC78, 0); add_180482_2381377266(&pl0, LOC79); line_534690_839829468(p0, ((Tcprocsection531011) 2), pl0); genassignment_541264_839829468(p0, (*d0), tmp0, 0); } LA63: ; } goto LA51; LA54: ; { TY535289 LOC81; Ropeobj180006* LOC82; Tloc294816 list0; memset((void*)LOC81, 0, sizeof(LOC81)); LOC82 = (Ropeobj180006*)0; LOC82 = HEX25_180905_2381377266(((NimStringDesc*) &T839829468_511), LOC81, 0); add_180482_2381377266(&pl0, LOC82); { if (!((*d0).k == ((Tlockind294808) 0))) goto LA85; gettemp_539032_839829468(p0, (*typ0).sons->data[((NI) 0)], d0, NIM_FALSE); } LA85: ; memset((void*)(&list0), 0, sizeof(list0)); initloc_534273_839829468((&list0), ((Tlockind294808) 9), NIM_NIL, ((Tstorageloc294812) 0)); list0.r = pl0; genassignment_541264_839829468(p0, (*d0), list0, 0); } LA51: ; } goto LA47; LA49: ; { TY535289 LOC88; Ropeobj180006* LOC89; memset((void*)LOC88, 0, sizeof(LOC88)); LOC89 = (Ropeobj180006*)0; LOC89 = HEX25_180905_2381377266(((NimStringDesc*) &T839829468_510), LOC88, 0); add_180482_2381377266(&pl0, LOC89); line_534690_839829468(p0, ((Tcprocsection531011) 2), pl0); } LA47: ; } N_NIMCALL(void, genprefixcall_541960_839829468)(Tcproc531021* p0, Tnode294802* le0, Tnode294802* ri0, Tloc294816* d0) { Tloc294816 op0; Ropeobj180006* params0; Ttype294840* typ0; NI length0; memset((void*)(&op0), 0, sizeof(op0)); initlocexpr_541283_839829468(p0, (*ri0).kindU.S6.sons->data[((NI) 0)], (&op0)); params0 = (Ropeobj180006*)0; typ0 = skiptypes_298099_850551059((*(*ri0).kindU.S6.sons->data[((NI) 0)]).typ, IL64(211106232576256)); length0 = sonslen_297351_850551059(ri0); { NI i_542213_839829468; NI HEX3Atmp_542445_839829468; NI res_542448_839829468; i_542213_839829468 = (NI)0; HEX3Atmp_542445_839829468 = (NI)0; HEX3Atmp_542445_839829468 = (NI)(length0 - ((NI) 1)); res_542448_839829468 = ((NI) 1); { while (1) { if (!(res_542448_839829468 <= HEX3Atmp_542445_839829468)) goto LA3; i_542213_839829468 = res_542448_839829468; { NI LOC6; Tnode294802* paramtype0; LOC6 = (NI)0; LOC6 = sonslen_297327_850551059(typ0); if (!(i_542213_839829468 < LOC6)) goto LA7; paramtype0 = (*(*typ0).n).kindU.S6.sons->data[i_542213_839829468]; { NIM_BOOL LOC11; Ropeobj180006* LOC20; LOC11 = (NIM_BOOL)0; LOC11 = iscompiletimeonly_330706_3876443242((*paramtype0).typ); if (!!(LOC11)) goto LA12; { TY535289 LOC18; Ropeobj180006* LOC19; if (!!((params0 == NIM_NIL))) goto LA16; memset((void*)LOC18, 0, sizeof(LOC18)); LOC19 = (Ropeobj180006*)0; LOC19 = HEX25_180905_2381377266(((NimStringDesc*) &T839829468_110), LOC18, 0); add_180482_2381377266(&params0, LOC19); } LA16: ; LOC20 = (Ropeobj180006*)0; LOC20 = genarg_541787_839829468(p0, (*ri0).kindU.S6.sons->data[i_542213_839829468], (*paramtype0).kindU.S4.sym, ri0); add_180482_2381377266(&params0, LOC20); } LA12: ; } goto LA4; LA7: ; { Ropeobj180006* LOC28; { TY535289 LOC26; Ropeobj180006* LOC27; if (!!((params0 == NIM_NIL))) goto LA24; memset((void*)LOC26, 0, sizeof(LOC26)); LOC27 = (Ropeobj180006*)0; LOC27 = HEX25_180905_2381377266(((NimStringDesc*) &T839829468_110), LOC26, 0); add_180482_2381377266(&params0, LOC27); } LA24: ; LOC28 = (Ropeobj180006*)0; LOC28 = genargnoparam_541938_839829468(p0, (*ri0).kindU.S6.sons->data[i_542213_839829468]); add_180482_2381377266(&params0, LOC28); } LA4: ; res_542448_839829468 += ((NI) 1); } LA3: ; } } fixupcall_541410_839829468(p0, le0, ri0, d0, op0.r, params0); } static N_INLINE(void, poststmtactions_534942_839829468)(Tcproc531021* p0) { Ropeobj180006** LOC1; LOC1 = (Ropeobj180006**)0; LOC1 = s_531179_3723162438(p0, ((Tcprocsection531011) 2)); add_180482_2381377266(LOC1, (*(*p0).module).injectstmt); } N_NIMCALL(void, gencall_545632_839829468)(Tcproc531021* p0, Tnode294802* e0, Tloc294816* d0) { { Ttype294840* LOC3; LOC3 = (Ttype294840*)0; LOC3 = skiptypes_298099_850551059((*(*e0).kindU.S6.sons->data[((NI) 0)]).typ, 2048); if (!((*LOC3).callconv == ((Tcallingconvention294002) 8))) goto LA4; genclosurecall_542452_839829468(p0, NIM_NIL, e0, d0); } goto LA1; LA4: ; { NIM_BOOL LOC7; LOC7 = (NIM_BOOL)0; LOC7 = ((*(*e0).kindU.S6.sons->data[((NI) 0)]).kind == ((Tnodekind294020) 3)); if (!(LOC7)) goto LA8; LOC7 = (((*(*(*e0).kindU.S6.sons->data[((NI) 0)]).kindU.S4.sym).flags &(1U<<((NU)(((Tsymflag294184) 27))&31U)))!=0); LA8: ; if (!LOC7) goto LA9; geninfixcall_543929_839829468(p0, NIM_NIL, e0, d0); } goto LA1; LA9: ; { NIM_BOOL LOC12; LOC12 = (NIM_BOOL)0; LOC12 = ((*(*e0).kindU.S6.sons->data[((NI) 0)]).kind == ((Tnodekind294020) 3)); if (!(LOC12)) goto LA13; LOC12 = (((*(*(*e0).kindU.S6.sons->data[((NI) 0)]).kindU.S4.sym).flags &(1U<<((NU)(((Tsymflag294184) 28))&31U)))!=0); LA13: ; if (!LOC12) goto LA14; gennamedparamcall_544616_839829468(p0, e0, d0); } goto LA1; LA14: ; { genprefixcall_541960_839829468(p0, NIM_NIL, e0, d0); } LA1: ; poststmtactions_534942_839829468(p0); } N_NIMCALL(void, genreset_556731_839829468)(Tcproc531021* p0, Tnode294802* n0) { Tloc294816 a0; TY534811 LOC1; Ttype294840* LOC2; memset((void*)(&a0), 0, sizeof(a0)); initlocexpr_541283_839829468(p0, (*n0).kindU.S6.sons->data[((NI) 1)], (&a0)); memset((void*)LOC1, 0, sizeof(LOC1)); LOC1[0] = addrloc_540204_839829468(a0); LOC2 = (Ttype294840*)0; LOC2 = skiptypes_298099_850551059(a0.t, IL64(211106242013440)); LOC1[1] = gentypeinfo_537941_839829468((*p0).module, LOC2); linefmt_534714_839829468(p0, ((Tcprocsection531011) 2), ((NimStringDesc*) &T839829468_496), LOC1, 2); } N_NIMCALL(void, genecho_556369_839829468)(Tcproc531021* p0, Tnode294802* n0) { NIM_BOOL LOC6; Ropeobj180006* args0; Tloc294816 a0; TY534811 LOC18; NimStringDesc* LOC19; NI LOC20; NimStringDesc* LOC21; TY535289 LOC22; { NimStringDesc* LOC5; if (!!(((*n0).kind == ((Tnodekind294020) 41)))) goto LA3; LOC5 = (NimStringDesc*)0; LOC5 = HEX24_198185_1689653243(T839829468_512); internalerror_198113_155036129(LOC5); } LA3: ; LOC6 = (NIM_BOOL)0; LOC6 = includestr_148249_3771138726((&(*(*p0).module).headerfiles), ((NimStringDesc*) &T839829468_513)); args0 = NIM_NIL; memset((void*)(&a0), 0, sizeof(a0)); { NI i_556404_839829468; NI HEX3Atmp_556431_839829468; NI LOC8; NI res_556434_839829468; i_556404_839829468 = (NI)0; HEX3Atmp_556431_839829468 = (NI)0; LOC8 = (NI)0; LOC8 = len_295081_850551059(n0); HEX3Atmp_556431_839829468 = (NI)(LOC8 - ((NI) 1)); res_556434_839829468 = ((NI) 0); { while (1) { if (!(res_556434_839829468 <= HEX3Atmp_556431_839829468)) goto LA10; i_556404_839829468 = res_556434_839829468; { Tnode294802* LOC13; LOC13 = (Tnode294802*)0; LOC13 = skipconv_330882_3876443242((*n0).kindU.S6.sons->data[i_556404_839829468]); if (!((*LOC13).kind == ((Tnodekind294020) 23))) goto LA14; add_180487_2381377266(&args0, ((NimStringDesc*) &T839829468_514)); } goto LA11; LA14: ; { TY180507 LOC17; initlocexpr_541283_839829468(p0, (*n0).kindU.S6.sons->data[i_556404_839829468], (&a0)); memset((void*)LOC17, 0, sizeof(LOC17)); LOC17[0] = rdloc_540188_839829468(a0); addf_181205_2381377266(&args0, ((NimStringDesc*) &T839829468_515), LOC17, 1); } LA11: ; res_556434_839829468 += ((NI) 1); } LA10: ; } } memset((void*)LOC18, 0, sizeof(LOC18)); LOC19 = (NimStringDesc*)0; LOC20 = (NI)0; LOC20 = len_295081_850551059(n0); LOC21 = (NimStringDesc*)0; LOC21 = nsuRepeatStr(((NimStringDesc*) &T839829468_517), ((NI) (LOC20))); LOC19 = rawNewString(LOC21->Sup.len + tnl_178644_4151366050->Sup.len + 0); appendString(LOC19, LOC21); appendString(LOC19, tnl_178644_4151366050); LOC18[0] = makecstring_193638_155036129(LOC19); LOC18[1] = args0; linefmt_534714_839829468(p0, ((Tcprocsection531011) 2), ((NimStringDesc*) &T839829468_516), LOC18, 2); memset((void*)LOC22, 0, sizeof(LOC22)); linefmt_534714_839829468(p0, ((Tcprocsection531011) 2), ((NimStringDesc*) &T839829468_518), LOC22, 0); } N_NIMCALL(void, genseqconstr_557004_839829468)(Tcproc531021* p0, Tnode294802* t0, Tloc294816* d0) { Tloc294816 arr0; NI LOC5; Ropeobj180006* LOC6; memset((void*)(&arr0), 0, sizeof(arr0)); { if (!((*d0).k == ((Tlockind294808) 0))) goto LA3; gettemp_539032_839829468(p0, (*t0).typ, d0, NIM_FALSE); } LA3: ; LOC5 = (NI)0; LOC5 = sonslen_297351_850551059(t0); LOC6 = (Ropeobj180006*)0; LOC6 = intliteral_541270_839829468(((NI64) (LOC5))); gennewseqaux_556795_839829468(p0, (*d0), LOC6); { NI i_557031_839829468; NI HEX3Atmp_557039_839829468; NI LOC8; NI res_557042_839829468; i_557031_839829468 = (NI)0; HEX3Atmp_557039_839829468 = (NI)0; LOC8 = (NI)0; LOC8 = sonslen_297351_850551059(t0); HEX3Atmp_557039_839829468 = (NI)(LOC8 - ((NI) 1)); res_557042_839829468 = ((NI) 0); { while (1) { Ttype294840* LOC11; Ttype294840* LOC12; TY534811 LOC13; if (!(res_557042_839829468 <= HEX3Atmp_557039_839829468)) goto LA10; i_557031_839829468 = res_557042_839829468; LOC11 = (Ttype294840*)0; LOC11 = skiptypes_298099_850551059((*t0).typ, IL64(211106232576256)); LOC12 = (Ttype294840*)0; LOC12 = elemtype_322394_3876443242(LOC11); initloc_534273_839829468((&arr0), ((Tlockind294808) 6), LOC12, ((Tstorageloc294812) 3)); memset((void*)LOC13, 0, sizeof(LOC13)); LOC13[0] = rdloc_540188_839829468((*d0)); LOC13[1] = intliteral_541270_839829468(((NI64) (i_557031_839829468))); arr0.r = ropecg_534407_839829468(NIM_NIL, ((NimStringDesc*) &T839829468_187), LOC13, 2); arr0.s = ((Tstorageloc294812) 3); expr_541248_839829468(p0, (*t0).kindU.S6.sons->data[i_557031_839829468], (&arr0)); res_557042_839829468 += ((NI) 1); } LA10: ; } } gcusage_556439_839829468(t0); } N_NIMCALL(void, genarrtoseq_557046_839829468)(Tcproc531021* p0, Tnode294802* t0, Tloc294816* d0) { Tloc294816 elem0; Tloc294816 a0; Tloc294816 arr0; NI L0; NI64 LOC9; Ropeobj180006* LOC10; { memset((void*)(&elem0), 0, sizeof(elem0)); memset((void*)(&a0), 0, sizeof(a0)); memset((void*)(&arr0), 0, sizeof(arr0)); { if (!((*t0).kind == ((Tnodekind294020) 41))) goto LA3; asgnRefNoCycle((void**) (&(*(*t0).kindU.S6.sons->data[((NI) 1)]).typ), (*t0).typ); genseqconstr_557004_839829468(p0, (*t0).kindU.S6.sons->data[((NI) 1)], d0); goto BeforeRet; } LA3: ; { if (!((*d0).k == ((Tlockind294808) 0))) goto LA7; gettemp_539032_839829468(p0, (*t0).typ, d0, NIM_FALSE); } LA7: ; LOC9 = (NI64)0; LOC9 = lengthord_322007_3876443242((*(*t0).kindU.S6.sons->data[((NI) 1)]).typ); L0 = ((NI) (LOC9)); LOC10 = (Ropeobj180006*)0; LOC10 = intliteral_541270_839829468(((NI64) (L0))); gennewseqaux_556795_839829468(p0, (*d0), LOC10); initlocexpr_541283_839829468(p0, (*t0).kindU.S6.sons->data[((NI) 1)], (&a0)); { NI i_557090_839829468; NI HEX3Atmp_557103_839829468; NI res_557106_839829468; i_557090_839829468 = (NI)0; HEX3Atmp_557103_839829468 = (NI)0; HEX3Atmp_557103_839829468 = (NI)(L0 - ((NI) 1)); res_557106_839829468 = ((NI) 0); { while (1) { Ttype294840* LOC14; Ttype294840* LOC15; TY534811 LOC16; Ttype294840* LOC17; Ttype294840* LOC18; TY534811 LOC19; if (!(res_557106_839829468 <= HEX3Atmp_557103_839829468)) goto LA13; i_557090_839829468 = res_557106_839829468; LOC14 = (Ttype294840*)0; LOC14 = skiptypes_298099_850551059((*t0).typ, IL64(211106232576256)); LOC15 = (Ttype294840*)0; LOC15 = elemtype_322394_3876443242(LOC14); initloc_534273_839829468((&elem0), ((Tlockind294808) 6), LOC15, ((Tstorageloc294812) 3)); memset((void*)LOC16, 0, sizeof(LOC16)); LOC16[0] = rdloc_540188_839829468((*d0)); LOC16[1] = intliteral_541270_839829468(((NI64) (i_557090_839829468))); elem0.r = ropecg_534407_839829468(NIM_NIL, ((NimStringDesc*) &T839829468_187), LOC16, 2); elem0.s = ((Tstorageloc294812) 3); LOC17 = (Ttype294840*)0; LOC17 = skiptypes_298099_850551059((*(*t0).kindU.S6.sons->data[((NI) 1)]).typ, IL64(211106232576256)); LOC18 = (Ttype294840*)0; LOC18 = elemtype_322394_3876443242(LOC17); initloc_534273_839829468((&arr0), ((Tlockind294808) 6), LOC18, a0.s); memset((void*)LOC19, 0, sizeof(LOC19)); LOC19[0] = rdloc_540188_839829468(a0); LOC19[1] = intliteral_541270_839829468(((NI64) (i_557090_839829468))); arr0.r = ropecg_534407_839829468(NIM_NIL, ((NimStringDesc*) &T839829468_138), LOC19, 2); genassignment_541264_839829468(p0, elem0, arr0, 3); res_557106_839829468 += ((NI) 1); } LA13: ; } } }BeforeRet: ; } N_NIMCALL(void, gendeepcopy_552374_839829468)(Tcproc531021* p0, Tloc294816 dest0, Tloc294816 src0) { Ttype294840* ty0; ty0 = skiptypes_298099_850551059(dest0.t, IL64(211106242013440)); switch ((*ty0).kind) { case ((Ttypekind294244) 21): case ((Ttypekind294244) 22): case ((Ttypekind294244) 25): case ((Ttypekind294244) 18): case ((Ttypekind294244) 17): case ((Ttypekind294244) 16): case ((Ttypekind294244) 4): { TY537238 LOC2; memset((void*)LOC2, 0, sizeof(LOC2)); LOC2[0] = addrloc_540204_839829468(dest0); LOC2[1] = addrloc_540204_839829468(src0); LOC2[2] = gentypeinfo_537941_839829468((*p0).module, dest0.t); linefmt_534714_839829468(p0, ((Tcprocsection531011) 2), ((NimStringDesc*) &T839829468_519), LOC2, 3); } break; case ((Ttypekind294244) 24): case ((Ttypekind294244) 28): { TY537238 LOC4; memset((void*)LOC4, 0, sizeof(LOC4)); LOC4[0] = addrloc_540204_839829468(dest0); LOC4[1] = rdloc_540188_839829468(src0); LOC4[2] = gentypeinfo_537941_839829468((*p0).module, dest0.t); linefmt_534714_839829468(p0, ((Tcprocsection531011) 2), ((NimStringDesc*) &T839829468_520), LOC4, 3); } break; case ((Ttypekind294244) 27): case ((Ttypekind294244) 48): { TY537238 LOC6; memset((void*)LOC6, 0, sizeof(LOC6)); LOC6[0] = addrloc_540204_839829468(dest0); LOC6[1] = addrloc_540204_839829468(src0); LOC6[2] = gentypeinfo_537941_839829468((*p0).module, dest0.t); linefmt_534714_839829468(p0, ((Tcprocsection531011) 2), ((NimStringDesc*) &T839829468_521), LOC6, 3); } break; case ((Ttypekind294244) 19): { { Tctypekind531007 LOC10; TY537238 LOC13; NI64 LOC14; LOC10 = (Tctypekind531007)0; LOC10 = maptype_535393_839829468(ty0); if (!(LOC10 == ((Tctypekind531007) 17))) goto LA11; usestringh_534345_839829468((*p0).module); memset((void*)LOC13, 0, sizeof(LOC13)); LOC13[0] = rdloc_540188_839829468(dest0); LOC13[1] = rdloc_540188_839829468(src0); LOC14 = (NI64)0; LOC14 = getsize_322135_3876443242(dest0.t); LOC13[2] = rope_180401_2381377266(LOC14); linefmt_534714_839829468(p0, ((Tcprocsection531011) 2), ((NimStringDesc*) &T839829468_268), LOC13, 3); } goto LA8; LA11: ; { TY534811 LOC16; memset((void*)LOC16, 0, sizeof(LOC16)); LOC16[0] = rdloc_540188_839829468(dest0); LOC16[1] = rdloc_540188_839829468(src0); linefmt_534714_839829468(p0, ((Tcprocsection531011) 2), ((NimStringDesc*) &T839829468_123), LOC16, 2); } LA8: ; } break; case ((Ttypekind294244) 26): case ((Ttypekind294244) 2): case ((Ttypekind294244) 1): case ((Ttypekind294244) 14): case ((Ttypekind294244) 29): case ((Ttypekind294244) 31) ... ((Ttypekind294244) 44): case ((Ttypekind294244) 20): case ((Ttypekind294244) 23): { TY534811 LOC18; memset((void*)LOC18, 0, sizeof(LOC18)); LOC18[0] = rdloc_540188_839829468(dest0); LOC18[1] = rdloc_540188_839829468(src0); linefmt_534714_839829468(p0, ((Tcprocsection531011) 2), ((NimStringDesc*) &T839829468_123), LOC18, 2); } break; default: { NimStringDesc* LOC20; LOC20 = (NimStringDesc*)0; LOC20 = rawNewString(reprEnum((NI)(*ty0).kind, (&NTI294244))->Sup.len + 13); appendString(LOC20, ((NimStringDesc*) &T839829468_522)); appendString(LOC20, reprEnum((NI)(*ty0).kind, (&NTI294244))); internalerror_198113_155036129(LOC20); } break; } } N_NIMCALL(void, genmagicexpr_559033_839829468)(Tcproc531021* p0, Tnode294802* e0, Tloc294816* d0, Tmagic294524 op0) { switch (op0) { case ((Tmagic294524) 127): case ((Tmagic294524) 126): { genandor_556311_839829468(p0, e0, d0, op0); } break; case ((Tmagic294524) 99) ... ((Tmagic294524) 117): { unaryarith_554646_839829468(p0, e0, d0, op0); } break; case ((Tmagic294524) 96) ... ((Tmagic294524) 98): { unaryarithoverflow_553633_839829468(p0, e0, d0, op0); } break; case ((Tmagic294524) 52) ... ((Tmagic294524) 55): { binaryfloatarith_558728_839829468(p0, e0, d0, op0); } break; case ((Tmagic294524) 56) ... ((Tmagic294524) 93): { binaryarith_553819_839829468(p0, e0, d0, op0); } break; case ((Tmagic294524) 95): { geneqproc_554214_839829468(p0, e0, d0); } break; case ((Tmagic294524) 45) ... ((Tmagic294524) 51): { binaryarithoverflow_553262_839829468(p0, e0, d0, op0); } break; case ((Tmagic294524) 149): { genrepr_557339_839829468(p0, e0, d0); } break; case ((Tmagic294524) 259): { gengettypeinfo_557383_839829468(p0, e0, d0); } break; case ((Tmagic294524) 156): { genswap_557638_839829468(p0, e0, d0); } break; case ((Tmagic294524) 25): { { if (!!((((*p0).options &(1U<<((NU)(((Toption171009) 5))&31U)))!=0))) goto LA14; unaryexpr_553209_839829468(p0, e0, d0, ((NimStringDesc*) &T839829468_385)); } goto LA12; LA14: ; { unaryexpr_553209_839829468(p0, e0, d0, ((NimStringDesc*) &T839829468_386)); } LA12: ; } break; case ((Tmagic294524) 26): case ((Tmagic294524) 27): { Ttype294840* underlying0; underlying0 = skiptypes_298099_850551059((*(*e0).kindU.S6.sons->data[((NI) 1)]).typ, 9439232); { NIM_BOOL LOC20; LOC20 = (NIM_BOOL)0; LOC20 = !((((*p0).options &(1U<<((NU)(((Toption171009) 5))&31U)))!=0)); if (LOC20) goto LA21; LOC20 = ((*underlying0).kind >= ((Ttypekind294244) 40) && (*underlying0).kind <= ((Ttypekind294244) 44)); LA21: ; if (!LOC20) goto LA22; binarystmt_552501_839829468(p0, e0, d0, opr_559050_839829468[(op0)- 26]); } goto LA18; LA22: ; { Tloc294816 a0; Tloc294816 b0; Ttype294840* ranged0; Ropeobj180006* res0; NimStringDesc* LOC25; TY534811 LOC31; Ropeobj180006* LOC32; memset((void*)(&a0), 0, sizeof(a0)); memset((void*)(&b0), 0, sizeof(b0)); initlocexpr_541283_839829468(p0, (*e0).kindU.S6.sons->data[((NI) 1)], (&a0)); initlocexpr_541283_839829468(p0, (*e0).kindU.S6.sons->data[((NI) 2)], (&b0)); ranged0 = skiptypes_298099_850551059((*(*e0).kindU.S6.sons->data[((NI) 1)]).typ, 8390656); LOC25 = (NimStringDesc*)0; { if (!((*underlying0).kind == ((Ttypekind294244) 35))) goto LA28; LOC25 = copyString(fun64_559055_839829468[(op0)- 26]); } goto LA26; LA28: ; { LOC25 = copyString(fun_559060_839829468[(op0)- 26]); } LA26: ; res0 = binaryarithoverflowraw_553235_839829468(p0, ranged0, a0, b0, LOC25); memset((void*)LOC31, 0, sizeof(LOC31)); LOC31[0] = gettypedesc_537671_839829468((*p0).module, ranged0); LOC31[1] = res0; LOC32 = (Ropeobj180006*)0; LOC32 = HEX25_180905_2381377266(((NimStringDesc*) &T839829468_370), LOC31, 2); putintodest_552468_839829468(p0, (&a0), ranged0, LOC32, ((Tstorageloc294812) 0)); } LA18: ; } break; case ((Tmagic294524) 138): { genstrconcat_556452_839829468(p0, e0, d0); } break; case ((Tmagic294524) 144): { binarystmt_552501_839829468(p0, e0, d0, ((NimStringDesc*) &T839829468_394)); } break; case ((Tmagic294524) 145): { genstrappend_556554_839829468(p0, e0, d0); } break; case ((Tmagic294524) 146): { genseqelemappend_556683_839829468(p0, e0, d0); } break; case ((Tmagic294524) 128): { genstrequals_558666_839829468(p0, e0, d0); } break; case ((Tmagic294524) 129): { binaryexpr_552549_839829468(p0, e0, d0, ((NimStringDesc*) &T839829468_402)); } break; case ((Tmagic294524) 130): { binaryexpr_552549_839829468(p0, e0, d0, ((NimStringDesc*) &T839829468_403)); } break; case ((Tmagic294524) 157): { genisnil_554620_839829468(p0, e0, d0); } break; case ((Tmagic294524) 120): { gendollar_557391_839829468(p0, e0, d0, ((NimStringDesc*) &T839829468_406)); } break; case ((Tmagic294524) 121): { gendollar_557391_839829468(p0, e0, d0, ((NimStringDesc*) &T839829468_407)); } break; case ((Tmagic294524) 119): { gendollar_557391_839829468(p0, e0, d0, ((NimStringDesc*) &T839829468_408)); } break; case ((Tmagic294524) 118): { gendollar_557391_839829468(p0, e0, d0, ((NimStringDesc*) &T839829468_409)); } break; case ((Tmagic294524) 122): { gendollar_557391_839829468(p0, e0, d0, ((NimStringDesc*) &T839829468_410)); } break; case ((Tmagic294524) 123): { gendollar_557391_839829468(p0, e0, d0, ((NimStringDesc*) &T839829468_411)); } break; case ((Tmagic294524) 124): { expr_541248_839829468(p0, (*e0).kindU.S6.sons->data[((NI) 1)], d0); } break; case ((Tmagic294524) 125): { genrepr_557339_839829468(p0, e0, d0); } break; case ((Tmagic294524) 12): { genof_557331_839829468(p0, e0, d0); } break; case ((Tmagic294524) 29): { gennew_556782_839829468(p0, e0); } break; case ((Tmagic294524) 30): { gennewfinalize_557110_839829468(p0, e0); } break; case ((Tmagic294524) 31): { gennewseq_556824_839829468(p0, e0); } break; case ((Tmagic294524) 32): { gennewseqofcap_556836_839829468(p0, e0, d0); } break; case ((Tmagic294524) 9): { Ttype294840* t0; TY180507 LOC55; Ropeobj180006* LOC56; t0 = skiptypes_298099_850551059((*(*e0).kindU.S6.sons->data[((NI) 1)]).typ, 256); memset((void*)LOC55, 0, sizeof(LOC55)); LOC55[0] = gettypedesc_537671_839829468((*p0).module, t0); LOC56 = (Ropeobj180006*)0; LOC56 = HEX25_180905_2381377266(((NimStringDesc*) &T839829468_428), LOC55, 1); putintodest_552468_839829468(p0, d0, (*e0).typ, LOC56, ((Tstorageloc294812) 0)); } break; case ((Tmagic294524) 42): { gensomecast_558480_839829468(p0, e0, d0); } break; case ((Tmagic294524) 28): { genord_558474_839829468(p0, e0, d0); } break; case ((Tmagic294524) 35): case ((Tmagic294524) 8): case ((Tmagic294524) 34): case ((Tmagic294524) 36): case ((Tmagic294524) 33): { genarraylen_557415_839829468(p0, e0, d0, op0); } break; case ((Tmagic294524) 37): case ((Tmagic294524) 38): { { NIM_BOOL LOC63; LOC63 = (NIM_BOOL)0; LOC63 = (gcmd_171132_2607990831 == ((Tcommands171076) 2)); if (LOC63) goto LA64; LOC63 = (((*(*(*p0).module).module).flags &(1U<<((NU)(((Tsymflag294184) 27))&31U)))!=0); LA64: ; if (!!(LOC63)) goto LA65; unaryexpr_553209_839829468(p0, e0, d0, ((NimStringDesc*) &T839829468_440)); } goto LA61; LA65: ; { unaryexpr_553209_839829468(p0, e0, d0, ((NimStringDesc*) &T839829468_441)); } LA61: ; } break; case ((Tmagic294524) 43): { unarystmt_552527_839829468(p0, e0, d0, ((NimStringDesc*) &T839829468_443)); } break; case ((Tmagic294524) 44): { unarystmt_552527_839829468(p0, e0, d0, ((NimStringDesc*) &T839829468_444)); } break; case ((Tmagic294524) 151): { gensetlengthstr_557632_839829468(p0, e0, d0); } break; case ((Tmagic294524) 152): { gensetlengthseq_557500_839829468(p0, e0, d0); } break; case ((Tmagic294524) 39): case ((Tmagic294524) 40): case ((Tmagic294524) 41): case ((Tmagic294524) 133): case ((Tmagic294524) 132): case ((Tmagic294524) 131): case ((Tmagic294524) 134): case ((Tmagic294524) 135): case ((Tmagic294524) 136): case ((Tmagic294524) 148): { gensetop_558419_839829468(p0, e0, d0, op0); } break; case ((Tmagic294524) 161): case ((Tmagic294524) 162): case ((Tmagic294524) 159): case ((Tmagic294524) 160): case ((Tmagic294524) 150): case ((Tmagic294524) 163): { Tsym294834* opr0; opr0 = (*(*e0).kindU.S6.sons->data[((NI) 0)]).kindU.S4.sym; { NimStringDesc* LOC78; Ropeobj180006* LOC79; if (!!((((*opr0).loc.flags &(1U<<((NU)(((Tlocflag294810) 3))&15U)))!=0))) goto LA76; LOC78 = (NimStringDesc*)0; LOC78 = HEX24_180856_2381377266((*opr0).loc.r); LOC79 = (Ropeobj180006*)0; LOC79 = cgsym_534403_839829468((*p0).module, LOC78); } LA76: ; gencall_545632_839829468(p0, e0, d0); } break; case ((Tmagic294524) 164): { genreset_556731_839829468(p0, e0); } break; case ((Tmagic294524) 17): { Tnode294802* LOC82; Tnode294802* LOC83; LOC82 = (Tnode294802*)0; LOC82 = HEX5BHEX5D_295238_850551059(e0, ((NI) 1)); LOC83 = (Tnode294802*)0; LOC83 = skipconv_330882_3876443242(LOC82); genecho_556369_839829468(p0, LOC83); } break; case ((Tmagic294524) 158): { genarrtoseq_557046_839829468(p0, e0, d0); } break; case ((Tmagic294524) 223) ... ((Tmagic294524) 257): case ((Tmagic294524) 19) ... ((Tmagic294524) 24): { localerror_198080_155036129((*e0).info, ((Tmsgkind193002) 229), (*(*(*(*e0).kindU.S6.sons->data[((NI) 0)]).kindU.S4.sym).name).s); } break; case ((Tmagic294524) 208): { Tnode294802* n0; n0 = wrapprocforspawn_437501_2218250499((*(*p0).module).module, e0, (*e0).typ, NIM_NIL, NIM_NIL); expr_541248_839829468(p0, n0, d0); } break; case ((Tmagic294524) 155): { Tnode294802* n0; n0 = liftparallel_480822_1773027539((*(*p0).module).module, e0); expr_541248_839829468(p0, n0, d0); } break; case ((Tmagic294524) 209): { Tloc294816 a0; Tloc294816 b0; Tnode294802* x0; memset((void*)(&a0), 0, sizeof(a0)); memset((void*)(&b0), 0, sizeof(b0)); { Tnode294802* LOC91; Tnode294802* LOC94; LOC91 = (Tnode294802*)0; LOC91 = HEX5BHEX5D_295238_850551059(e0, ((NI) 1)); if (!((*LOC91).kind == ((Tnodekind294020) 63) || (*LOC91).kind == ((Tnodekind294020) 64))) goto LA92; LOC94 = (Tnode294802*)0; LOC94 = HEX5BHEX5D_295238_850551059(e0, ((NI) 1)); x0 = HEX5BHEX5D_295238_850551059(LOC94, ((NI) 0)); } goto LA89; LA92: ; { x0 = HEX5BHEX5D_295238_850551059(e0, ((NI) 1)); } LA89: ; initlocexpr_541283_839829468(p0, x0, (&a0)); initlocexpr_541283_839829468(p0, (*e0).kindU.S6.sons->data[((NI) 2)], (&b0)); gendeepcopy_552374_839829468(p0, a0, b0); } break; case ((Tmagic294524) 140): case ((Tmagic294524) 94): { gencall_545632_839829468(p0, e0, d0); } break; default: { NimStringDesc* LOC98; LOC98 = (NimStringDesc*)0; LOC98 = rawNewString(reprEnum((NI)op0, (&NTI294524))->Sup.len + 14); appendString(LOC98, ((NimStringDesc*) &T839829468_523)); appendString(LOC98, reprEnum((NI)op0, (&NTI294524))); internalerror_198100_155036129((*e0).info, LOC98); } break; } } N_NIMCALL(Ropeobj180006*, gensetnode_551664_839829468)(Tcproc531021* p0, Tnode294802* n0) { Ropeobj180006* result0; Tbitset341004* cs0; NI size0; NI64 LOC1; result0 = (Ropeobj180006*)0; cs0 = (Tbitset341004*)0; LOC1 = (NI64)0; LOC1 = getsize_322135_3876443242((*n0).typ); size0 = ((NI) (LOC1)); tobitset_342001_452470228(n0, (&cs0)); { NI id0; Ropeobj180006* LOC6; if (!(((NI) 8) < size0)) goto LA4; id0 = nodetabletestorset_344682_1142335848((&(*(*p0).module).datacache), n0, ((NI) ((*(*p0).module).labels))); LOC6 = (Ropeobj180006*)0; LOC6 = rope_180401_2381377266(((NI64) (id0))); result0 = HEX26_180418_2381377266((*(*p0).module).tmpbase, LOC6); { TY537238 LOC11; if (!(id0 == ((NI) ((*(*p0).module).labels)))) goto LA9; (*(*p0).module).labels += ((NI) 1); memset((void*)LOC11, 0, sizeof(LOC11)); LOC11[0] = gettypedesc_537671_839829468((*p0).module, (*n0).typ); LOC11[1] = result0; LOC11[2] = genrawsetdata_551629_839829468(cs0, size0); addf_181205_2381377266(&(*(*p0).module).s[(((Tcfilesection531005) 8))- 0], ((NimStringDesc*) &T839829468_524), LOC11, 3); } LA9: ; } goto LA2; LA4: ; { result0 = genrawsetdata_551629_839829468(cs0, size0); } LA2: ; return result0; } N_NIMCALL(void, gensetconstr_559496_839829468)(Tcproc531021* p0, Tnode294802* e0, Tloc294816* d0) { Tloc294816 a0; Tloc294816 b0; Tloc294816 idx0; memset((void*)(&a0), 0, sizeof(a0)); memset((void*)(&b0), 0, sizeof(b0)); memset((void*)(&idx0), 0, sizeof(idx0)); { Ropeobj180006* LOC5; if (!(((*e0).flags &(1U<<((NU)(((Tnodeflag294427) 4))&15U)))!=0)) goto LA3; LOC5 = (Ropeobj180006*)0; LOC5 = gensetnode_551664_839829468(p0, e0); putintodest_552468_839829468(p0, d0, (*e0).typ, LOC5, ((Tstorageloc294812) 0)); } goto LA1; LA3: ; { { if (!((*d0).k == ((Tlockind294808) 0))) goto LA9; gettemp_539032_839829468(p0, (*e0).typ, d0, NIM_FALSE); } LA9: ; { NI64 LOC13; TY180507 LOC16; LOC13 = (NI64)0; LOC13 = getsize_322135_3876443242((*e0).typ); if (!(IL64(8) < LOC13)) goto LA14; usestringh_534345_839829468((*p0).module); memset((void*)LOC16, 0, sizeof(LOC16)); LOC16[0] = rdloc_540188_839829468((*d0)); linef_534700_839829468(p0, ((Tcprocsection531011) 2), ((NimStringDesc*) &T839829468_525), LOC16, 1); { NI i_559537_839829468; NI HEX3Atmp_559603_839829468; NI LOC18; NI res_559606_839829468; i_559537_839829468 = (NI)0; HEX3Atmp_559603_839829468 = (NI)0; LOC18 = (NI)0; LOC18 = sonslen_297351_850551059(e0); HEX3Atmp_559603_839829468 = (NI)(LOC18 - ((NI) 1)); res_559606_839829468 = ((NI) 0); { while (1) { if (!(res_559606_839829468 <= HEX3Atmp_559603_839829468)) goto LA20; i_559537_839829468 = res_559606_839829468; { Ttype294840* LOC25; TY537235 LOC26; if (!((*(*e0).kindU.S6.sons->data[i_559537_839829468]).kind == ((Tnodekind294020) 44))) goto LA23; LOC25 = (Ttype294840*)0; LOC25 = getsystype_340150_3937434831(((Ttypekind294244) 31)); gettemp_539032_839829468(p0, LOC25, (&idx0), NIM_FALSE); initlocexpr_541283_839829468(p0, (*(*e0).kindU.S6.sons->data[i_559537_839829468]).kindU.S6.sons->data[((NI) 0)], (&a0)); initlocexpr_541283_839829468(p0, (*(*e0).kindU.S6.sons->data[i_559537_839829468]).kindU.S6.sons->data[((NI) 1)], (&b0)); memset((void*)LOC26, 0, sizeof(LOC26)); LOC26[0] = rdloc_540188_839829468(idx0); LOC26[1] = rdloc_540188_839829468((*d0)); LOC26[2] = rdsetelemloc_557662_839829468(a0, (*e0).typ); LOC26[3] = rdsetelemloc_557662_839829468(b0, (*e0).typ); linef_534700_839829468(p0, ((Tcprocsection531011) 2), ((NimStringDesc*) &T839829468_526), LOC26, 4); } goto LA21; LA23: ; { TY534811 LOC28; initlocexpr_541283_839829468(p0, (*e0).kindU.S6.sons->data[i_559537_839829468], (&a0)); memset((void*)LOC28, 0, sizeof(LOC28)); LOC28[0] = rdloc_540188_839829468((*d0)); LOC28[1] = rdsetelemloc_557662_839829468(a0, (*e0).typ); linef_534700_839829468(p0, ((Tcprocsection531011) 2), ((NimStringDesc*) &T839829468_527), LOC28, 2); } LA21: ; res_559606_839829468 += ((NI) 1); } LA20: ; } } } goto LA11; LA14: ; { NimStringDesc* ts0; NimStringDesc* LOC30; NI64 LOC31; NimStringDesc* LOC32; TY180507 LOC33; LOC30 = (NimStringDesc*)0; LOC31 = (NI64)0; LOC31 = getsize_322135_3876443242((*e0).typ); LOC32 = (NimStringDesc*)0; LOC32 = nimInt64ToStr((NI64)(LOC31 * IL64(8))); LOC30 = rawNewString(LOC32->Sup.len + 2); appendString(LOC30, ((NimStringDesc*) &T839829468_45)); appendString(LOC30, LOC32); ts0 = LOC30; memset((void*)LOC33, 0, sizeof(LOC33)); LOC33[0] = rdloc_540188_839829468((*d0)); linef_534700_839829468(p0, ((Tcprocsection531011) 2), ((NimStringDesc*) &T839829468_494), LOC33, 1); { NI i_559575_839829468; NI HEX3Atmp_559611_839829468; NI LOC35; NI res_559614_839829468; i_559575_839829468 = (NI)0; HEX3Atmp_559611_839829468 = (NI)0; LOC35 = (NI)0; LOC35 = sonslen_297351_850551059(e0); HEX3Atmp_559611_839829468 = (NI)(LOC35 - ((NI) 1)); res_559614_839829468 = ((NI) 0); { while (1) { if (!(res_559614_839829468 <= HEX3Atmp_559611_839829468)) goto LA37; i_559575_839829468 = res_559614_839829468; { Ttype294840* LOC42; NimStringDesc* LOC43; TY537235 LOC44; if (!((*(*e0).kindU.S6.sons->data[i_559575_839829468]).kind == ((Tnodekind294020) 44))) goto LA40; LOC42 = (Ttype294840*)0; LOC42 = getsystype_340150_3937434831(((Ttypekind294244) 31)); gettemp_539032_839829468(p0, LOC42, (&idx0), NIM_FALSE); initlocexpr_541283_839829468(p0, (*(*e0).kindU.S6.sons->data[i_559575_839829468]).kindU.S6.sons->data[((NI) 0)], (&a0)); initlocexpr_541283_839829468(p0, (*(*e0).kindU.S6.sons->data[i_559575_839829468]).kindU.S6.sons->data[((NI) 1)], (&b0)); LOC43 = (NimStringDesc*)0; LOC43 = rawNewString(ts0->Sup.len + ts0->Sup.len + 68); appendString(LOC43, ((NimStringDesc*) &T839829468_528)); appendString(LOC43, ts0); appendString(LOC43, ((NimStringDesc*) &T839829468_529)); appendString(LOC43, ts0); appendString(LOC43, ((NimStringDesc*) &T839829468_454)); memset((void*)LOC44, 0, sizeof(LOC44)); LOC44[0] = rdloc_540188_839829468(idx0); LOC44[1] = rdloc_540188_839829468((*d0)); LOC44[2] = rdsetelemloc_557662_839829468(a0, (*e0).typ); LOC44[3] = rdsetelemloc_557662_839829468(b0, (*e0).typ); linef_534700_839829468(p0, ((Tcprocsection531011) 2), LOC43, LOC44, 4); } goto LA38; LA40: ; { NimStringDesc* LOC46; TY534811 LOC47; initlocexpr_541283_839829468(p0, (*e0).kindU.S6.sons->data[i_559575_839829468], (&a0)); LOC46 = (NimStringDesc*)0; LOC46 = rawNewString(ts0->Sup.len + ts0->Sup.len + 36); appendString(LOC46, ((NimStringDesc*) &T839829468_530)); appendString(LOC46, ts0); appendString(LOC46, ((NimStringDesc*) &T839829468_531)); appendString(LOC46, ts0); appendString(LOC46, ((NimStringDesc*) &T839829468_454)); memset((void*)LOC47, 0, sizeof(LOC47)); LOC47[0] = rdloc_540188_839829468((*d0)); LOC47[1] = rdsetelemloc_557662_839829468(a0, (*e0).typ); linef_534700_839829468(p0, ((Tcprocsection531011) 2), LOC46, LOC47, 2); } LA38: ; res_559614_839829468 += ((NI) 1); } LA37: ; } } } LA11: ; } LA1: ; } N_NIMCALL(void, exprcomplexconst_560684_839829468)(Tcproc531021* p0, Tnode294802* n0, Tloc294816* d0) { Ttype294840* t0; Ropeobj180006* LOC1; NI id0; Ropeobj180006* tmp0; Ropeobj180006* LOC2; t0 = getuniquetype_530640_2036603609((*n0).typ); LOC1 = (Ropeobj180006*)0; LOC1 = gettypedesc_537671_839829468((*p0).module, t0); id0 = nodetabletestorset_344682_1142335848((&(*(*p0).module).datacache), n0, ((NI) ((*(*p0).module).labels))); LOC2 = (Ropeobj180006*)0; LOC2 = rope_180401_2381377266(((NI64) (id0))); tmp0 = HEX26_180418_2381377266((*(*p0).module).tmpbase, LOC2); { TY537238 LOC7; if (!(id0 == ((NI) ((*(*p0).module).labels)))) goto LA5; (*(*p0).module).labels += ((NI) 1); memset((void*)LOC7, 0, sizeof(LOC7)); LOC7[0] = gettypedesc_537671_839829468((*p0).module, t0); LOC7[1] = tmp0; LOC7[2] = genconstexpr_556849_839829468(p0, n0); addf_181205_2381377266(&(*(*p0).module).s[(((Tcfilesection531005) 8))- 0], ((NimStringDesc*) &T839829468_272), LOC7, 3); } LA5: ; { if (!((*d0).k == ((Tlockind294808) 0))) goto LA10; fillloc_534282_839829468(d0, ((Tlockind294808) 8), t0, tmp0, ((Tstorageloc294812) 1)); } goto LA8; LA10: ; { putdataintodest_552436_839829468(p0, d0, t0, tmp0); { if (!!(((*t0).kind == ((Ttypekind294244) 24) || (*t0).kind == ((Ttypekind294244) 28)))) goto LA15; (*d0).s = ((Tstorageloc294812) 1); } LA15: ; } LA8: ; } N_NIMCALL(NIM_BOOL, handleconstexpr_556853_839829468)(Tcproc531021* p0, Tnode294802* n0, Tloc294816* d0) { NIM_BOOL result0; result0 = (NIM_BOOL)0; { NIM_BOOL LOC3; NIM_BOOL LOC4; NI LOC6; Ttype294840* t0; Ropeobj180006* LOC10; NI id0; Ropeobj180006* LOC11; Ropeobj180006* LOC12; LOC3 = (NIM_BOOL)0; LOC4 = (NIM_BOOL)0; LOC4 = ((*d0).k == ((Tlockind294808) 0)); if (!(LOC4)) goto LA5; LOC6 = (NI)0; LOC6 = len_295081_850551059(n0); LOC4 = (((NI) (((*n0).kind == ((Tnodekind294020) 38)))) < LOC6); LA5: ; LOC3 = LOC4; if (!(LOC3)) goto LA7; LOC3 = isdeepconstexpr_320566_2616423590(n0); LA7: ; if (!LOC3) goto LA8; t0 = getuniquetype_530640_2036603609((*n0).typ); LOC10 = (Ropeobj180006*)0; LOC10 = gettypedesc_537671_839829468((*p0).module, t0); id0 = nodetabletestorset_344682_1142335848((&(*(*p0).module).datacache), n0, ((NI) ((*(*p0).module).labels))); LOC11 = (Ropeobj180006*)0; LOC11 = rope_180401_2381377266(((NI64) (id0))); LOC12 = (Ropeobj180006*)0; LOC12 = HEX26_180418_2381377266((*(*p0).module).tmpbase, LOC11); fillloc_534282_839829468(d0, ((Tlockind294808) 8), t0, LOC12, ((Tstorageloc294812) 1)); { TY537238 LOC17; if (!(id0 == ((NI) ((*(*p0).module).labels)))) goto LA15; (*(*p0).module).labels += ((NI) 1); memset((void*)LOC17, 0, sizeof(LOC17)); LOC17[0] = gettypedesc_537671_839829468((*p0).module, t0); LOC17[1] = (*d0).r; LOC17[2] = genconstexpr_556849_839829468(p0, n0); addf_181205_2381377266(&(*(*p0).module).s[(((Tcfilesection531005) 8))- 0], ((NimStringDesc*) &T839829468_272), LOC17, 3); } LA15: ; result0 = NIM_TRUE; } goto LA1; LA8: ; { result0 = NIM_FALSE; } LA1: ; return result0; } N_NIMCALL(void, genarrayconstr_560207_839829468)(Tcproc531021* p0, Tnode294802* n0, Tloc294816* d0) { Tloc294816 arr0; memset((void*)(&arr0), 0, sizeof(arr0)); { NIM_BOOL LOC3; LOC3 = (NIM_BOOL)0; LOC3 = handleconstexpr_556853_839829468(p0, n0, d0); if (!!(LOC3)) goto LA4; { if (!((*d0).k == ((Tlockind294808) 0))) goto LA8; gettemp_539032_839829468(p0, (*n0).typ, d0, NIM_FALSE); } LA8: ; { NI i_560234_839829468; NI HEX3Atmp_560242_839829468; NI LOC11; NI res_560245_839829468; i_560234_839829468 = (NI)0; HEX3Atmp_560242_839829468 = (NI)0; LOC11 = (NI)0; LOC11 = sonslen_297351_850551059(n0); HEX3Atmp_560242_839829468 = (NI)(LOC11 - ((NI) 1)); res_560245_839829468 = ((NI) 0); { while (1) { Ttype294840* LOC14; Ttype294840* LOC15; TY534811 LOC16; if (!(res_560245_839829468 <= HEX3Atmp_560242_839829468)) goto LA13; i_560234_839829468 = res_560245_839829468; LOC14 = (Ttype294840*)0; LOC14 = skiptypes_298099_850551059((*n0).typ, IL64(211106232576256)); LOC15 = (Ttype294840*)0; LOC15 = elemtype_322394_3876443242(LOC14); initloc_534273_839829468((&arr0), ((Tlockind294808) 6), LOC15, (*d0).s); memset((void*)LOC16, 0, sizeof(LOC16)); LOC16[0] = rdloc_540188_839829468((*d0)); LOC16[1] = intliteral_541270_839829468(((NI64) (i_560234_839829468))); arr0.r = HEX25_180905_2381377266(((NimStringDesc*) &T839829468_138), LOC16, 2); expr_541248_839829468(p0, (*n0).kindU.S6.sons->data[i_560234_839829468], (&arr0)); res_560245_839829468 += ((NI) 1); } LA13: ; } } } LA4: ; } N_NIMCALL(void, gentupleconstr_559618_839829468)(Tcproc531021* p0, Tnode294802* n0, Tloc294816* d0) { Tloc294816 rec0; memset((void*)(&rec0), 0, sizeof(rec0)); { NIM_BOOL LOC3; Ttype294840* t0; Ropeobj180006* LOC6; LOC3 = (NIM_BOOL)0; LOC3 = handleconstexpr_556853_839829468(p0, n0, d0); if (!!(LOC3)) goto LA4; t0 = getuniquetype_530640_2036603609((*n0).typ); LOC6 = (Ropeobj180006*)0; LOC6 = gettypedesc_537671_839829468((*p0).module, t0); { if (!((*d0).k == ((Tlockind294808) 0))) goto LA9; gettemp_539032_839829468(p0, t0, d0, NIM_FALSE); } LA9: ; { NI i_559646_839829468; NI HEX3Atmp_559803_839829468; NI LOC12; NI res_559806_839829468; i_559646_839829468 = (NI)0; HEX3Atmp_559803_839829468 = (NI)0; LOC12 = (NI)0; LOC12 = sonslen_297351_850551059(n0); HEX3Atmp_559803_839829468 = (NI)(LOC12 - ((NI) 1)); res_559806_839829468 = ((NI) 0); { while (1) { Tnode294802* it0; TY534811 LOC19; if (!(res_559806_839829468 <= HEX3Atmp_559803_839829468)) goto LA14; i_559646_839829468 = res_559806_839829468; it0 = (*n0).kindU.S6.sons->data[i_559646_839829468]; { if (!((*it0).kind == ((Tnodekind294020) 34))) goto LA17; it0 = (*it0).kindU.S6.sons->data[((NI) 1)]; } LA17: ; initloc_534273_839829468((&rec0), ((Tlockind294808) 6), (*it0).typ, (*d0).s); memset((void*)LOC19, 0, sizeof(LOC19)); LOC19[0] = rdloc_540188_839829468((*d0)); LOC19[1] = rope_180401_2381377266(((NI64) (i_559646_839829468))); rec0.r = HEX25_180905_2381377266(((NimStringDesc*) &T839829468_185), LOC19, 2); expr_541248_839829468(p0, it0, (&rec0)); res_559806_839829468 += ((NI) 1); } LA14: ; } } } LA4: ; } N_NIMCALL(Tsym294834*, lookupfieldagain_555153_839829468)(Tcproc531021* p0, Ttype294840* ty_555156_839829468, Tsym294834* field0, Ropeobj180006** r0) { Tsym294834* result0; Ttype294840* ty0; result0 = (Tsym294834*)0; ty0 = ty_555156_839829468; { while (1) { if (!!((ty0 == NIM_NIL))) goto LA2; ty0 = skiptypes_298099_850551059(ty0, IL64(211106247215360)); result0 = lookupinrecord_301119_2984716966((*ty0).n, (*field0).name); { if (!!((result0 == NIM_NIL))) goto LA5; goto LA1; } LA5: ; { NIM_BOOL LOC9; LOC9 = (NIM_BOOL)0; LOC9 = (gcmd_171132_2607990831 == ((Tcommands171076) 2)); if (LOC9) goto LA10; LOC9 = (((*(*(*p0).module).module).flags &(1U<<((NU)(((Tsymflag294184) 27))&31U)))!=0); LA10: ; if (!!(LOC9)) goto LA11; add_180487_2381377266(r0, ((NimStringDesc*) &T839829468_153)); } LA11: ; ty0 = getuniquetype_530640_2036603609((*ty0).sons->data[((NI) 0)]); } LA2: ; } LA1: ; { if (!(result0 == NIM_NIL)) goto LA15; internalerror_198100_155036129((*field0).info, ((NimStringDesc*) &T839829468_532)); } LA15: ; return result0; } N_NIMCALL(void, genfieldcheck_555504_839829468)(Tcproc531021* p0, Tnode294802* e0, Ropeobj180006* obj0, Tsym294834* field0, Ttype294840* origty0) { Tloc294816 test0; Tloc294816 u0; Tloc294816 v0; memset((void*)(&test0), 0, sizeof(test0)); memset((void*)(&u0), 0, sizeof(u0)); memset((void*)(&v0), 0, sizeof(v0)); { NI i_555525_839829468; NI HEX3Atmp_556039_839829468; NI LOC2; NI res_556042_839829468; i_555525_839829468 = (NI)0; HEX3Atmp_556039_839829468 = (NI)0; LOC2 = (NI)0; LOC2 = sonslen_297351_850551059(e0); HEX3Atmp_556039_839829468 = (NI)(LOC2 - ((NI) 1)); res_556042_839829468 = ((NI) 1); { while (1) { Tnode294802* it0; Tsym294834* op0; Tnode294802* disc0; Ropeobj180006* o0; Tsym294834* d0; NI id0; Tnode294802* LOC9; Ropeobj180006* strlit0; if (!(res_556042_839829468 <= HEX3Atmp_556039_839829468)) goto LA4; i_555525_839829468 = res_556042_839829468; it0 = (*e0).kindU.S6.sons->data[i_555525_839829468]; op0 = (*(*it0).kindU.S6.sons->data[((NI) 0)]).kindU.S4.sym; { if (!((*op0).magic == ((Tmagic294524) 99))) goto LA7; it0 = (*it0).kindU.S6.sons->data[((NI) 1)]; } LA7: ; disc0 = skipconv_330882_3876443242((*it0).kindU.S6.sons->data[((NI) 2)]); initloc_534273_839829468((&test0), ((Tlockind294808) 0), (*it0).typ, ((Tstorageloc294812) 2)); initlocexpr_541283_839829468(p0, (*it0).kindU.S6.sons->data[((NI) 1)], (&u0)); o0 = obj0; d0 = lookupfieldagain_555153_839829468(p0, origty0, (*disc0).kindU.S4.sym, &o0); initloc_534273_839829468((&v0), ((Tlockind294808) 6), (*d0).typ, ((Tstorageloc294812) 0)); v0.r = o0; add_180487_2381377266(&v0.r, ((NimStringDesc*) &T839829468_257)); add_180482_2381377266(&v0.r, (*d0).loc.r); geninexpraux_555496_839829468(p0, it0, (&u0), (&v0), (&test0)); LOC9 = (Tnode294802*)0; LOC9 = newstrnode_295678_850551059(((Tnodekind294020) 20), (*(*field0).name).s); id0 = nodetabletestorset_344682_1142335848((&(*(*p0).module).datacache), LOC9, ((NI) ((*(*p0).module).labels))); { if (!(id0 == ((NI) ((*(*p0).module).labels)))) goto LA12; strlit0 = getstrlit_551468_839829468((*p0).module, (*(*field0).name).s); } goto LA10; LA12: ; { Ropeobj180006* LOC15; LOC15 = (Ropeobj180006*)0; LOC15 = rope_180401_2381377266(((NI64) (id0))); strlit0 = HEX26_180418_2381377266((*(*p0).module).tmpbase, LOC15); } LA10: ; { TY534811 LOC20; if (!((*op0).magic == ((Tmagic294524) 99))) goto LA18; memset((void*)LOC20, 0, sizeof(LOC20)); LOC20[0] = rdloc_540188_839829468(test0); LOC20[1] = strlit0; linefmt_534714_839829468(p0, ((Tcprocsection531011) 2), ((NimStringDesc*) &T839829468_534), LOC20, 2); } goto LA16; LA18: ; { TY534811 LOC22; memset((void*)LOC22, 0, sizeof(LOC22)); LOC22[0] = rdloc_540188_839829468(test0); LOC22[1] = strlit0; linefmt_534714_839829468(p0, ((Tcprocsection531011) 2), ((NimStringDesc*) &T839829468_535), LOC22, 2); } LA16: ; res_556042_839829468 += ((NI) 1); } LA4: ; } } } N_NIMCALL(void, genobjconstr_556903_839829468)(Tcproc531021* p0, Tnode294802* e0, Tloc294816* d0) { Tloc294816 tmp0; Ttype294840* t0; NIM_BOOL isref0; Ropeobj180006* r0; Ropeobj180006* LOC13; Ttype294840* ty0; { { NIM_BOOL LOC3; LOC3 = (NIM_BOOL)0; LOC3 = handleconstexpr_556853_839829468(p0, e0, d0); if (!LOC3) goto LA4; goto BeforeRet; } LA4: ; memset((void*)(&tmp0), 0, sizeof(tmp0)); t0 = skiptypes_298099_850551059((*e0).typ, IL64(211106232576256)); gettemp_539032_839829468(p0, t0, (&tmp0), NIM_FALSE); isref0 = ((*t0).kind == ((Ttypekind294244) 22)); r0 = rdloc_540188_839829468(tmp0); { Ttype294840* LOC10; TY180507 LOC11; if (!isref0) goto LA8; rawgennew_556741_839829468(p0, tmp0, NIM_NIL); LOC10 = (Ttype294840*)0; LOC10 = lastson_297377_850551059(t0); t0 = skiptypes_298099_850551059(LOC10, IL64(211106232576256)); memset((void*)LOC11, 0, sizeof(LOC11)); LOC11[0] = r0; r0 = HEX25_180905_2381377266(((NimStringDesc*) &T839829468_124), LOC11, 1); gcusage_556439_839829468(e0); } goto LA6; LA8: ; { constructloc_540388_839829468(p0, tmp0, NIM_FALSE); } LA6: ; LOC13 = (Ropeobj180006*)0; LOC13 = gettypedesc_537671_839829468((*p0).module, t0); ty0 = getuniquetype_530640_2036603609(t0); { NI i_556944_839829468; NI HEX3Atmp_556997_839829468; NI LOC15; NI res_557000_839829468; i_556944_839829468 = (NI)0; HEX3Atmp_556997_839829468 = (NI)0; LOC15 = (NI)0; LOC15 = len_295081_850551059(e0); HEX3Atmp_556997_839829468 = (LOC15 - 1); res_557000_839829468 = ((NI) 1); { while (1) { Tnode294802* it0; Tloc294816 tmp20; Tsym294834* field0; if (!(res_557000_839829468 <= HEX3Atmp_556997_839829468)) goto LA17; i_556944_839829468 = res_557000_839829468; it0 = (*e0).kindU.S6.sons->data[i_556944_839829468]; memset((void*)(&tmp20), 0, sizeof(tmp20)); tmp20.r = r0; field0 = lookupfieldagain_555153_839829468(p0, ty0, (*(*it0).kindU.S6.sons->data[((NI) 0)]).kindU.S4.sym, &tmp20.r); { if (!((*field0).loc.r == NIM_NIL)) goto LA20; internalerror_198100_155036129((*e0).info, ((NimStringDesc*) &T839829468_533)); } LA20: ; { NIM_BOOL LOC24; NI LOC25; LOC24 = (NIM_BOOL)0; LOC25 = (NI)0; LOC25 = len_295081_850551059(it0); LOC24 = (LOC25 == ((NI) 3)); if (!(LOC24)) goto LA26; LOC24 = (((*p0).options &(1U<<((NU)(((Toption171009) 2))&31U)))!=0); LA26: ; if (!LOC24) goto LA27; genfieldcheck_555504_839829468(p0, (*it0).kindU.S6.sons->data[((NI) 2)], r0, field0, ty0); } LA27: ; add_180487_2381377266(&tmp20.r, ((NimStringDesc*) &T839829468_257)); add_180482_2381377266(&tmp20.r, (*field0).loc.r); tmp20.k = ((Tlockind294808) 1); tmp20.t = (*field0).loc.t; { if (!isref0) goto LA31; tmp20.s = ((Tstorageloc294812) 3); } goto LA29; LA31: ; { tmp20.s = ((Tstorageloc294812) 2); } LA29: ; expr_541248_839829468(p0, (*it0).kindU.S6.sons->data[((NI) 1)], (&tmp20)); res_557000_839829468 += ((NI) 1); } LA17: ; } } { if (!((*d0).k == ((Tlockind294808) 0))) goto LA36; genericAssign((void*)(&(*d0)), (void*)(&tmp0), (&NTI294816)); } goto LA34; LA36: ; { genassignment_541264_839829468(p0, (*d0), tmp0, 0); } LA34: ; }BeforeRet: ; } N_NIMCALL(void, gencast_558537_839829468)(Tcproc531021* p0, Tnode294802* e0, Tloc294816* d0) { Ttype294840* destt0; Ttype294840* srct0; destt0 = skiptypes_298099_850551059((*e0).typ, IL64(211106233624832)); srct0 = skiptypes_298099_850551059((*(*e0).kindU.S6.sons->data[((NI) 1)]).typ, IL64(211106233624832)); { NIM_BOOL LOC3; Ropeobj180006* lbl0; Tloc294816 tmp0; TY180507 LOC7; TY537238 LOC8; TY180507 LOC9; Ropeobj180006* LOC10; LOC3 = (NIM_BOOL)0; LOC3 = ((*destt0).kind >= ((Ttypekind294244) 36) && (*destt0).kind <= ((Ttypekind294244) 39) || (*destt0).kind == ((Ttypekind294244) 18) || (*destt0).kind == ((Ttypekind294244) 17) || (*destt0).kind == ((Ttypekind294244) 16) || (*destt0).kind == ((Ttypekind294244) 4)); if (LOC3) goto LA4; LOC3 = ((*srct0).kind >= ((Ttypekind294244) 36) && (*srct0).kind <= ((Ttypekind294244) 39) || (*srct0).kind == ((Ttypekind294244) 18) || (*srct0).kind == ((Ttypekind294244) 17) || (*srct0).kind == ((Ttypekind294244) 16) || (*srct0).kind == ((Ttypekind294244) 4)); LA4: ; if (!LOC3) goto LA5; (*p0).labels += ((NI) 1); lbl0 = rope_180401_2381377266(((NI64) ((*p0).labels))); memset((void*)(&tmp0), 0, sizeof(tmp0)); memset((void*)LOC7, 0, sizeof(LOC7)); LOC7[0] = lbl0; tmp0.r = HEX25_180905_2381377266(((NimStringDesc*) &T839829468_536), LOC7, 1); memset((void*)LOC8, 0, sizeof(LOC8)); LOC8[0] = gettypedesc_537671_839829468((*p0).module, srct0); LOC8[1] = gettypedesc_537671_839829468((*p0).module, destt0); LOC8[2] = lbl0; linefmt_534714_839829468(p0, ((Tcprocsection531011) 0), ((NimStringDesc*) &T839829468_537), LOC8, 3); tmp0.k = ((Tlockind294808) 6); tmp0.t = srct0; tmp0.s = ((Tstorageloc294812) 2); tmp0.flags = 0; expr_541248_839829468(p0, (*e0).kindU.S6.sons->data[((NI) 1)], (&tmp0)); memset((void*)LOC9, 0, sizeof(LOC9)); LOC9[0] = lbl0; LOC10 = (Ropeobj180006*)0; LOC10 = HEX25_180905_2381377266(((NimStringDesc*) &T839829468_538), LOC9, 1); putintodest_552468_839829468(p0, d0, (*e0).typ, LOC10, tmp0.s); } goto LA1; LA5: ; { gensomecast_558480_839829468(p0, e0, d0); } LA1: ; } N_NIMCALL(void, genconv_558632_839829468)(Tcproc531021* p0, Tnode294802* e0, Tloc294816* d0) { Ttype294840* desttype0; desttype0 = skiptypes_298099_850551059((*e0).typ, 8390656); { NIM_BOOL LOC3; LOC3 = (NIM_BOOL)0; LOC3 = comparetypes_328214_3876443242(desttype0, (*(*e0).kindU.S6.sons->data[((NI) 1)]).typ, ((Tdistinctcompare326427) 1), 0); if (!LOC3) goto LA4; expr_541248_839829468(p0, (*e0).kindU.S6.sons->data[((NI) 1)], d0); } goto LA1; LA4: ; { gensomecast_558480_839829468(p0, e0, d0); } LA1: ; } static N_INLINE(NIM_BOOL, iscppref_554807_839829468)(Tcproc531021* p0, Ttype294840* typ0) { NIM_BOOL result0; NIM_BOOL LOC1; NIM_BOOL LOC2; NIM_BOOL LOC3; Ttype294840* LOC6; Ttype294840* LOC8; result0 = (NIM_BOOL)0; LOC1 = (NIM_BOOL)0; LOC2 = (NIM_BOOL)0; LOC3 = (NIM_BOOL)0; LOC3 = (gcmd_171132_2607990831 == ((Tcommands171076) 2)); if (LOC3) goto LA4; LOC3 = (((*(*(*p0).module).module).flags &(1U<<((NU)(((Tsymflag294184) 27))&31U)))!=0); LA4: ; LOC2 = LOC3; if (!(LOC2)) goto LA5; LOC6 = (Ttype294840*)0; LOC6 = skiptypes_298099_850551059(typ0, IL64(211106232576256)); LOC2 = ((*LOC6).kind == ((Ttypekind294244) 23)); LA5: ; LOC1 = LOC2; if (!(LOC1)) goto LA7; LOC8 = (Ttype294840*)0; LOC8 = skiptypes_298099_850551059(typ0, IL64(211106232576256)); LOC1 = !((((*LOC8).flags &(1U<<((NU)(((Ttypeflag294431) 18))&31U)))!=0)); LA7: ; result0 = LOC1; return result0; } N_NIMCALL(void, genaddr_555051_839829468)(Tcproc531021* p0, Tnode294802* e0, Tloc294816* d0) { { Ttype294840* LOC3; Tloc294816 a0; Ropeobj180006* LOC6; LOC3 = (Ttype294840*)0; LOC3 = skiptypes_298099_850551059((*(*e0).kindU.S6.sons->data[((NI) 0)]).typ, IL64(211106232576256)); if (!((*LOC3).kind == ((Ttypekind294244) 22) || (*LOC3).kind == ((Ttypekind294244) 21))) goto LA4; memset((void*)(&a0), 0, sizeof(a0)); initlocexpr_541283_839829468(p0, (*e0).kindU.S6.sons->data[((NI) 0)], (&a0)); LOC6 = (Ropeobj180006*)0; LOC6 = HEX26_180452_2381377266(((NimStringDesc*) &T839829468_52), a0.r); putintodest_552468_839829468(p0, d0, (*e0).typ, LOC6, a0.s); } goto LA1; LA4: ; { NIM_BOOL LOC8; Tctypekind531007 LOC9; LOC8 = (NIM_BOOL)0; LOC9 = (Tctypekind531007)0; LOC9 = maptype_535393_839829468((*(*e0).kindU.S6.sons->data[((NI) 0)]).typ); LOC8 = (LOC9 == ((Tctypekind531007) 17)); if (LOC8) goto LA10; LOC8 = iscppref_554807_839829468(p0, (*(*e0).kindU.S6.sons->data[((NI) 0)]).typ); LA10: ; if (!LOC8) goto LA11; expr_541248_839829468(p0, (*e0).kindU.S6.sons->data[((NI) 0)], d0); } goto LA1; LA11: ; { Tloc294816 a0; Ropeobj180006* LOC14; memset((void*)(&a0), 0, sizeof(a0)); initlocexpr_541283_839829468(p0, (*e0).kindU.S6.sons->data[((NI) 0)], (&a0)); LOC14 = (Ropeobj180006*)0; LOC14 = addrloc_540204_839829468(a0); putintodest_552468_839829468(p0, d0, (*e0).typ, LOC14, a0.s); } LA1: ; } N_NIMCALL(void, genarrayelem_556093_839829468)(Tcproc531021* p0, Tnode294802* x0, Tnode294802* y0, Tloc294816* d0) { Tloc294816 a0; Tloc294816 b0; Ttype294840* ty0; Ttype294840* LOC1; Ropeobj180006* first0; NI64 LOC2; Ttype294840* LOC47; Ttype294840* LOC48; TY537238 LOC49; Ropeobj180006* LOC50; memset((void*)(&a0), 0, sizeof(a0)); memset((void*)(&b0), 0, sizeof(b0)); initlocexpr_541283_839829468(p0, x0, (&a0)); initlocexpr_541283_839829468(p0, y0, (&b0)); LOC1 = (Ttype294840*)0; LOC1 = skiptypes_298099_850551059(a0.t, IL64(211106242013440)); ty0 = skiptypes_298099_850551059(LOC1, IL64(211106247256320)); LOC2 = (NI64)0; LOC2 = firstord_322001_3876443242(ty0); first0 = intliteral_541270_839829468(LOC2); { NIM_BOOL LOC5; LOC5 = (NIM_BOOL)0; LOC5 = (((*p0).options &(1U<<((NU)(((Toption171009) 4))&31U)))!=0); if (!(LOC5)) goto LA6; LOC5 = !((((*ty0).flags &(1U<<((NU)(((Ttypeflag294431) 0))&31U)))!=0)); LA6: ; if (!LOC5) goto LA7; { NIM_BOOL LOC11; LOC11 = (NIM_BOOL)0; LOC11 = isconstexpr_320510_2616423590(y0); if (!!(LOC11)) goto LA12; { NI64 LOC16; LOC16 = (NI64)0; LOC16 = firstord_322001_3876443242(ty0); if (!(LOC16 == IL64(0))) goto LA17; { NIM_BOOL LOC21; NI64 LOC22; NI64 LOC23; NI64 LOC25; NI64 LOC26; TY534811 LOC29; NI64 LOC30; LOC21 = (NIM_BOOL)0; LOC22 = (NI64)0; LOC22 = firstord_322001_3876443242(b0.t); LOC23 = (NI64)0; LOC23 = firstord_322001_3876443242(ty0); LOC21 = (LOC22 < LOC23); if (LOC21) goto LA24; LOC25 = (NI64)0; LOC25 = lastord_322004_3876443242(ty0); LOC26 = (NI64)0; LOC26 = lastord_322004_3876443242(b0.t); LOC21 = (LOC25 < LOC26); LA24: ; if (!LOC21) goto LA27; memset((void*)LOC29, 0, sizeof(LOC29)); LOC29[0] = rdcharloc_540227_839829468(b0); LOC30 = (NI64)0; LOC30 = lastord_322004_3876443242(ty0); LOC29[1] = intliteral_541270_839829468(LOC30); linefmt_534714_839829468(p0, ((Tcprocsection531011) 2), ((NimStringDesc*) &T839829468_539), LOC29, 2); } LA27: ; } goto LA14; LA17: ; { TY537238 LOC32; NI64 LOC33; memset((void*)LOC32, 0, sizeof(LOC32)); LOC32[0] = rdcharloc_540227_839829468(b0); LOC32[1] = first0; LOC33 = (NI64)0; LOC33 = lastord_322004_3876443242(ty0); LOC32[2] = intliteral_541270_839829468(LOC33); linefmt_534714_839829468(p0, ((Tcprocsection531011) 2), ((NimStringDesc*) &T839829468_540), LOC32, 3); } LA14: ; } goto LA9; LA12: ; { NI64 idx0; idx0 = getordvalue_322129_3876443242(y0); { NIM_BOOL LOC37; NI64 LOC38; NI64 LOC40; LOC37 = (NIM_BOOL)0; LOC38 = (NI64)0; LOC38 = firstord_322001_3876443242(ty0); LOC37 = (idx0 < LOC38); if (LOC37) goto LA39; LOC40 = (NI64)0; LOC40 = lastord_322004_3876443242(ty0); LOC37 = (LOC40 < idx0); LA39: ; if (!LOC37) goto LA41; localerror_198080_155036129((*x0).info, ((Tmsgkind193002) 86), ((NimStringDesc*) &T839829468_490)); } LA41: ; } LA9: ; } LA7: ; { if (!((*d0).k == ((Tlockind294808) 0))) goto LA45; (*d0).s = a0.s; } LA45: ; LOC47 = (Ttype294840*)0; LOC47 = skiptypes_298099_850551059(ty0, IL64(211106240964864)); LOC48 = (Ttype294840*)0; LOC48 = elemtype_322394_3876443242(LOC47); memset((void*)LOC49, 0, sizeof(LOC49)); LOC49[0] = rdloc_540188_839829468(a0); LOC49[1] = rdcharloc_540227_839829468(b0); LOC49[2] = first0; LOC50 = (Ropeobj180006*)0; LOC50 = ropecg_534407_839829468(NIM_NIL, ((NimStringDesc*) &T839829468_541), LOC49, 3); putintodest_552468_839829468(p0, d0, LOC48, LOC50, a0.s); } N_NIMCALL(void, genopenarrayelem_556169_839829468)(Tcproc531021* p0, Tnode294802* x0, Tnode294802* y0, Tloc294816* d0) { Tloc294816 a0; Tloc294816 b0; Ttype294840* LOC10; Ttype294840* LOC11; TY534811 LOC12; Ropeobj180006* LOC13; memset((void*)(&a0), 0, sizeof(a0)); memset((void*)(&b0), 0, sizeof(b0)); initlocexpr_541283_839829468(p0, x0, (&a0)); initlocexpr_541283_839829468(p0, y0, (&b0)); { TY534811 LOC5; if (!(((*p0).options &(1U<<((NU)(((Toption171009) 4))&31U)))!=0)) goto LA3; memset((void*)LOC5, 0, sizeof(LOC5)); LOC5[0] = rdloc_540188_839829468(b0); LOC5[1] = rdloc_540188_839829468(a0); linefmt_534714_839829468(p0, ((Tcprocsection531011) 2), ((NimStringDesc*) &T839829468_542), LOC5, 2); } LA3: ; { if (!((*d0).k == ((Tlockind294808) 0))) goto LA8; (*d0).s = a0.s; } LA8: ; LOC10 = (Ttype294840*)0; LOC10 = skiptypes_298099_850551059(a0.t, IL64(211106240964864)); LOC11 = (Ttype294840*)0; LOC11 = elemtype_322394_3876443242(LOC10); memset((void*)LOC12, 0, sizeof(LOC12)); LOC12[0] = rdloc_540188_839829468(a0); LOC12[1] = rdcharloc_540227_839829468(b0); LOC13 = (Ropeobj180006*)0; LOC13 = ropecg_534407_839829468(NIM_NIL, ((NimStringDesc*) &T839829468_138), LOC12, 2); putintodest_552468_839829468(p0, d0, LOC11, LOC13, a0.s); } N_NIMCALL(void, genseqelem_556205_839829468)(Tcproc531021* p0, Tnode294802* x0, Tnode294802* y0, Tloc294816* d0) { Tloc294816 a0; Tloc294816 b0; Ttype294840* ty0; Ttype294840* LOC27; Ttype294840* LOC28; TY534811 LOC29; Ropeobj180006* LOC30; memset((void*)(&a0), 0, sizeof(a0)); memset((void*)(&b0), 0, sizeof(b0)); initlocexpr_541283_839829468(p0, x0, (&a0)); initlocexpr_541283_839829468(p0, y0, (&b0)); ty0 = skiptypes_298099_850551059(a0.t, IL64(211106242013440)); { Ttype294840* LOC5; if (!((*ty0).kind == ((Ttypekind294244) 22) || (*ty0).kind == ((Ttypekind294244) 21))) goto LA3; LOC5 = (Ttype294840*)0; LOC5 = lastson_297377_850551059(ty0); ty0 = skiptypes_298099_850551059(LOC5, IL64(211106242013440)); } LA3: ; { if (!(((*p0).options &(1U<<((NU)(((Toption171009) 4))&31U)))!=0)) goto LA8; { TY537238 LOC14; if (!((*ty0).kind == ((Ttypekind294244) 28))) goto LA12; memset((void*)LOC14, 0, sizeof(LOC14)); LOC14[0] = rdloc_540188_839829468(b0); LOC14[1] = rdloc_540188_839829468(a0); LOC14[2] = lenfield_541305_839829468(p0); linefmt_534714_839829468(p0, ((Tcprocsection531011) 2), ((NimStringDesc*) &T839829468_543), LOC14, 3); } goto LA10; LA12: ; { TY537238 LOC16; memset((void*)LOC16, 0, sizeof(LOC16)); LOC16[0] = rdloc_540188_839829468(b0); LOC16[1] = rdloc_540188_839829468(a0); LOC16[2] = lenfield_541305_839829468(p0); linefmt_534714_839829468(p0, ((Tcprocsection531011) 2), ((NimStringDesc*) &T839829468_544), LOC16, 3); } LA10: ; } LA8: ; { if (!((*d0).k == ((Tlockind294808) 0))) goto LA19; (*d0).s = ((Tstorageloc294812) 3); } LA19: ; { Ttype294840* LOC23; TY180507 LOC26; LOC23 = (Ttype294840*)0; LOC23 = skiptypes_298099_850551059(a0.t, IL64(211106240964864)); if (!((*LOC23).kind == ((Ttypekind294244) 22) || (*LOC23).kind == ((Ttypekind294244) 21))) goto LA24; memset((void*)LOC26, 0, sizeof(LOC26)); LOC26[0] = a0.r; a0.r = ropecg_534407_839829468(NIM_NIL, ((NimStringDesc*) &T839829468_124), LOC26, 1); } LA24: ; LOC27 = (Ttype294840*)0; LOC27 = skiptypes_298099_850551059(a0.t, IL64(211106240964864)); LOC28 = (Ttype294840*)0; LOC28 = elemtype_322394_3876443242(LOC27); memset((void*)LOC29, 0, sizeof(LOC29)); LOC29[0] = rdloc_540188_839829468(a0); LOC29[1] = rdcharloc_540227_839829468(b0); LOC30 = (Ropeobj180006*)0; LOC30 = ropecg_534407_839829468(NIM_NIL, ((NimStringDesc*) &T839829468_187), LOC29, 2); putintodest_552468_839829468(p0, d0, LOC28, LOC30, a0.s); } N_NIMCALL(void, gencstringelem_556144_839829468)(Tcproc531021* p0, Tnode294802* x0, Tnode294802* y0, Tloc294816* d0) { Tloc294816 a0; Tloc294816 b0; Ttype294840* ty0; Ttype294840* LOC5; Ttype294840* LOC6; TY534811 LOC7; Ropeobj180006* LOC8; memset((void*)(&a0), 0, sizeof(a0)); memset((void*)(&b0), 0, sizeof(b0)); initlocexpr_541283_839829468(p0, x0, (&a0)); initlocexpr_541283_839829468(p0, y0, (&b0)); ty0 = skiptypes_298099_850551059(a0.t, IL64(211106242013440)); { if (!((*d0).k == ((Tlockind294808) 0))) goto LA3; (*d0).s = a0.s; } LA3: ; LOC5 = (Ttype294840*)0; LOC5 = skiptypes_298099_850551059(ty0, IL64(211106240964864)); LOC6 = (Ttype294840*)0; LOC6 = elemtype_322394_3876443242(LOC5); memset((void*)LOC7, 0, sizeof(LOC7)); LOC7[0] = rdloc_540188_839829468(a0); LOC7[1] = rdcharloc_540227_839829468(b0); LOC8 = (Ropeobj180006*)0; LOC8 = ropecg_534407_839829468(NIM_NIL, ((NimStringDesc*) &T839829468_138), LOC7, 2); putintodest_552468_839829468(p0, d0, LOC6, LOC8, a0.s); } N_NIMCALL(void, gentupleelem_555124_839829468)(Tcproc531021* p0, Tnode294802* e0, Tloc294816* d0) { Tloc294816 a0; NI i0; Ropeobj180006* LOC5; Ttype294840* ty0; Ropeobj180006* r0; TY180507 LOC8; memset((void*)(&a0), 0, sizeof(a0)); i0 = (NI)0; initlocexpr_541283_839829468(p0, (*e0).kindU.S6.sons->data[((NI) 0)], (&a0)); { if (!((*d0).k == ((Tlockind294808) 0))) goto LA3; (*d0).s = a0.s; } LA3: ; LOC5 = (Ropeobj180006*)0; LOC5 = gettypedesc_537671_839829468((*p0).module, a0.t); ty0 = getuniquetype_530640_2036603609(a0.t); r0 = rdloc_540188_839829468(a0); switch ((*(*e0).kindU.S6.sons->data[((NI) 1)]).kind) { case ((Tnodekind294020) 6) ... ((Tnodekind294020) 15): { i0 = ((NI) ((*(*e0).kindU.S6.sons->data[((NI) 1)]).kindU.S1.intval)); } break; default: { internalerror_198100_155036129((*e0).info, ((NimStringDesc*) &T839829468_545)); } break; } memset((void*)LOC8, 0, sizeof(LOC8)); LOC8[0] = rope_180401_2381377266(((NI64) (i0))); addf_181205_2381377266(&r0, ((NimStringDesc*) &T839829468_546), LOC8, 1); putintodest_552468_839829468(p0, d0, (*ty0).sons->data[i0], r0, a0.s); } N_NIMCALL(void, genbracketexpr_556277_839829468)(Tcproc531021* p0, Tnode294802* n0, Tloc294816* d0) { Ttype294840* ty0; ty0 = skiptypes_298099_850551059((*(*n0).kindU.S6.sons->data[((NI) 0)]).typ, IL64(211106242013440)); { Ttype294840* LOC5; if (!((*ty0).kind == ((Ttypekind294244) 22) || (*ty0).kind == ((Ttypekind294244) 21))) goto LA3; LOC5 = (Ttype294840*)0; LOC5 = lastson_297377_850551059(ty0); ty0 = skiptypes_298099_850551059(LOC5, IL64(211106242013440)); } LA3: ; switch ((*ty0).kind) { case ((Ttypekind294244) 16): case ((Ttypekind294244) 4): { genarrayelem_556093_839829468(p0, (*n0).kindU.S6.sons->data[((NI) 0)], (*n0).kindU.S6.sons->data[((NI) 1)], d0); } break; case ((Ttypekind294244) 27): case ((Ttypekind294244) 48): { genopenarrayelem_556169_839829468(p0, (*n0).kindU.S6.sons->data[((NI) 0)], (*n0).kindU.S6.sons->data[((NI) 1)], d0); } break; case ((Ttypekind294244) 24): case ((Ttypekind294244) 28): { genseqelem_556205_839829468(p0, (*n0).kindU.S6.sons->data[((NI) 0)], (*n0).kindU.S6.sons->data[((NI) 1)], d0); } break; case ((Ttypekind294244) 29): { gencstringelem_556144_839829468(p0, (*n0).kindU.S6.sons->data[((NI) 0)], (*n0).kindU.S6.sons->data[((NI) 1)], d0); } break; case ((Ttypekind294244) 18): { gentupleelem_555124_839829468(p0, n0, d0); } break; default: { NimStringDesc* LOC12; LOC12 = (NimStringDesc*)0; LOC12 = rawNewString(reprEnum((NI)(*ty0).kind, (&NTI294244))->Sup.len + 21); appendString(LOC12, ((NimStringDesc*) &T839829468_547)); appendString(LOC12, reprEnum((NI)(*ty0).kind, (&NTI294244))); appendChar(LOC12, 41); internalerror_198100_155036129((*n0).info, LOC12); } break; } } N_NIMCALL(void, genderef_545921_839829468)(Tcproc531021* p0, Tnode294802* e0, Tloc294816* d0, NIM_BOOL enforcederef0) { Tctypekind531007 mt0; { mt0 = maptype_535393_839829468((*(*e0).kindU.S6.sons->data[((NI) 0)]).typ); { NIM_BOOL LOC3; LOC3 = (NIM_BOOL)0; LOC3 = ((393216 &(1U<<((NU)(mt0)&31U)))!=0); if (!(LOC3)) goto LA4; LOC3 = !(enforcederef0); LA4: ; if (!LOC3) goto LA5; expr_541248_839829468(p0, (*e0).kindU.S6.sons->data[((NI) 0)], d0); { Ttype294840* LOC9; LOC9 = (Ttype294840*)0; LOC9 = skiptypes_298099_850551059((*(*e0).kindU.S6.sons->data[((NI) 0)]).typ, IL64(211106232576256)); if (!((*LOC9).kind == ((Ttypekind294244) 22))) goto LA10; (*d0).s = ((Tstorageloc294812) 3); } LA10: ; } goto LA1; LA5: ; { Tloc294816 a0; Ttype294840* typ0; memset((void*)(&a0), 0, sizeof(a0)); typ0 = skiptypes_298099_850551059((*(*e0).kindU.S6.sons->data[((NI) 0)]).typ, IL64(211106232576256)); { NIM_BOOL LOC15; NIM_BOOL LOC16; NIM_BOOL LOC17; NIM_BOOL LOC20; Tnode294802* LOC25; Tnode294802* LOC26; LOC15 = (NIM_BOOL)0; LOC16 = (NIM_BOOL)0; LOC17 = (NIM_BOOL)0; LOC17 = ((*typ0).kind == ((Ttypekind294244) 23)); if (!(LOC17)) goto LA18; LOC17 = !((((*typ0).flags &(1U<<((NU)(((Ttypeflag294431) 18))&31U)))!=0)); LA18: ; LOC16 = LOC17; if (!(LOC16)) goto LA19; LOC20 = (NIM_BOOL)0; LOC20 = (gcmd_171132_2607990831 == ((Tcommands171076) 2)); if (LOC20) goto LA21; LOC20 = (((*(*(*p0).module).module).flags &(1U<<((NU)(((Tsymflag294184) 27))&31U)))!=0); LA21: ; LOC16 = LOC20; LA19: ; LOC15 = LOC16; if (!(LOC15)) goto LA22; LOC15 = ((*(*e0).kindU.S6.sons->data[((NI) 0)]).kind == ((Tnodekind294020) 64)); LA22: ; if (!LOC15) goto LA23; LOC25 = (Tnode294802*)0; LOC25 = HEX5BHEX5D_295238_850551059(e0, ((NI) 0)); LOC26 = (Tnode294802*)0; LOC26 = HEX5BHEX5D_295238_850551059(LOC25, ((NI) 0)); initlocexprsingleuse_541289_839829468(p0, LOC26, d0); goto BeforeRet; } goto LA13; LA23: ; { initlocexprsingleuse_541289_839829468(p0, (*e0).kindU.S6.sons->data[((NI) 0)], (&a0)); } LA13: ; { if (!((*d0).k == ((Tlockind294808) 0))) goto LA30; switch ((*typ0).kind) { case ((Ttypekind294244) 22): { (*d0).s = ((Tstorageloc294812) 3); } break; case ((Ttypekind294244) 23): { (*d0).s = ((Tstorageloc294812) 0); { NIM_BOOL LOC36; NIM_BOOL LOC37; NIM_BOOL LOC39; Ropeobj180006* LOC44; LOC36 = (NIM_BOOL)0; LOC37 = (NIM_BOOL)0; LOC37 = !((((*typ0).flags &(1U<<((NU)(((Ttypeflag294431) 18))&31U)))!=0)); if (!(LOC37)) goto LA38; LOC39 = (NIM_BOOL)0; LOC39 = (gcmd_171132_2607990831 == ((Tcommands171076) 2)); if (LOC39) goto LA40; LOC39 = (((*(*(*p0).module).module).flags &(1U<<((NU)(((Tsymflag294184) 27))&31U)))!=0); LA40: ; LOC37 = LOC39; LA38: ; LOC36 = LOC37; if (!(LOC36)) goto LA41; LOC36 = ((*e0).kind == ((Tnodekind294020) 65)); LA41: ; if (!LOC36) goto LA42; LOC44 = (Ropeobj180006*)0; LOC44 = rdloc_540188_839829468(a0); putintodest_552468_839829468(p0, d0, (*e0).typ, LOC44, a0.s); goto BeforeRet; } LA42: ; } break; case ((Ttypekind294244) 21): { (*d0).s = ((Tstorageloc294812) 0); } break; default: { NimStringDesc* LOC47; LOC47 = (NimStringDesc*)0; LOC47 = rawNewString(reprEnum((NI)(*typ0).kind, (&NTI294244))->Sup.len + 9); appendString(LOC47, ((NimStringDesc*) &T839829468_548)); appendString(LOC47, reprEnum((NI)(*typ0).kind, (&NTI294244))); internalerror_198100_155036129((*e0).info, LOC47); } break; } } goto LA28; LA30: ; { NIM_BOOL LOC49; LOC49 = (NIM_BOOL)0; LOC49 = (gcmd_171132_2607990831 == ((Tcommands171076) 2)); if (LOC49) goto LA50; LOC49 = (((*(*(*p0).module).module).flags &(1U<<((NU)(((Tsymflag294184) 27))&31U)))!=0); LA50: ; if (!LOC49) goto LA51; { NIM_BOOL LOC55; NIM_BOOL LOC56; Ropeobj180006* LOC61; LOC55 = (NIM_BOOL)0; LOC56 = (NIM_BOOL)0; LOC56 = ((*typ0).kind == ((Ttypekind294244) 23)); if (!(LOC56)) goto LA57; LOC56 = !((((*typ0).flags &(1U<<((NU)(((Ttypeflag294431) 18))&31U)))!=0)); LA57: ; LOC55 = LOC56; if (!(LOC55)) goto LA58; LOC55 = ((*e0).kind == ((Tnodekind294020) 65)); LA58: ; if (!LOC55) goto LA59; LOC61 = (Ropeobj180006*)0; LOC61 = rdloc_540188_839829468(a0); putintodest_552468_839829468(p0, d0, (*e0).typ, LOC61, a0.s); goto BeforeRet; } LA59: ; } goto LA28; LA51: ; LA28: ; { NIM_BOOL LOC64; Ropeobj180006* LOC68; LOC64 = (NIM_BOOL)0; LOC64 = enforcederef0; if (!(LOC64)) goto LA65; LOC64 = (mt0 == ((Tctypekind531007) 18)); LA65: ; if (!LOC64) goto LA66; LOC68 = (Ropeobj180006*)0; LOC68 = rdloc_540188_839829468(a0); putintodest_552468_839829468(p0, d0, (*a0.t).sons->data[((NI) 0)], LOC68, a0.s); } goto LA62; LA66: ; { TY180507 LOC70; Ropeobj180006* LOC71; memset((void*)LOC70, 0, sizeof(LOC70)); LOC70[0] = rdloc_540188_839829468(a0); LOC71 = (Ropeobj180006*)0; LOC71 = HEX25_180905_2381377266(((NimStringDesc*) &T839829468_124), LOC70, 1); putintodest_552468_839829468(p0, d0, (*e0).typ, LOC71, a0.s); } LA62: ; } LA1: ; }BeforeRet: ; } N_NIMCALL(Ttype294840*, genrecordfieldaux_555096_839829468)(Tcproc531021* p0, Tnode294802* e0, Tloc294816* d0, Tloc294816* a0) { Ttype294840* result0; Ropeobj180006* LOC9; result0 = (Ttype294840*)0; initlocexpr_541283_839829468(p0, (*e0).kindU.S6.sons->data[((NI) 0)], a0); { if (!!(((*(*e0).kindU.S6.sons->data[((NI) 1)]).kind == ((Tnodekind294020) 3)))) goto LA3; internalerror_198100_155036129((*e0).info, ((NimStringDesc*) &T839829468_549)); } LA3: ; { if (!((*d0).k == ((Tlockind294808) 0))) goto LA7; (*d0).s = (*a0).s; } LA7: ; LOC9 = (Ropeobj180006*)0; LOC9 = gettypedesc_537671_839829468((*p0).module, (*a0).t); result0 = getuniquetype_530640_2036603609((*a0).t); return result0; } N_NIMCALL(void, genrecordfield_555448_839829468)(Tcproc531021* p0, Tnode294802* e0, Tloc294816* d0) { Tloc294816 a0; Ttype294840* ty0; Ropeobj180006* r0; Tsym294834* f0; memset((void*)(&a0), 0, sizeof(a0)); ty0 = genrecordfieldaux_555096_839829468(p0, e0, d0, (&a0)); r0 = rdloc_540188_839829468(a0); f0 = (*(*e0).kindU.S6.sons->data[((NI) 1)]).kindU.S4.sym; { TY180507 LOC5; if (!((*ty0).kind == ((Ttypekind294244) 18))) goto LA3; memset((void*)LOC5, 0, sizeof(LOC5)); LOC5[0] = rope_180401_2381377266(((NI64) ((*f0).position))); addf_181205_2381377266(&r0, ((NimStringDesc*) &T839829468_546), LOC5, 1); putintodest_552468_839829468(p0, d0, (*f0).typ, r0, a0.s); } goto LA1; LA3: ; { Tsym294834* field0; TY180507 LOC11; field0 = lookupfieldagain_555153_839829468(p0, ty0, f0, &r0); { if (!((*field0).loc.r == NIM_NIL)) goto LA9; internalerror_198100_155036129((*e0).info, ((NimStringDesc*) &T839829468_550)); } LA9: ; memset((void*)LOC11, 0, sizeof(LOC11)); LOC11[0] = (*field0).loc.r; addf_181205_2381377266(&r0, ((NimStringDesc*) &T839829468_551), LOC11, 1); putintodest_552468_839829468(p0, d0, (*field0).typ, r0, a0.s); } LA1: ; } N_NIMCALL(void, gencheckedrecordfield_556046_839829468)(Tcproc531021* p0, Tnode294802* e0, Tloc294816* d0) { { Tloc294816 a0; Ttype294840* ty0; Ropeobj180006* r0; Tsym294834* f0; Tsym294834* field0; TY180507 LOC9; Ropeobj180006* LOC10; if (!(((*p0).options &(1U<<((NU)(((Toption171009) 2))&31U)))!=0)) goto LA3; memset((void*)(&a0), 0, sizeof(a0)); ty0 = genrecordfieldaux_555096_839829468(p0, (*e0).kindU.S6.sons->data[((NI) 0)], d0, (&a0)); r0 = rdloc_540188_839829468(a0); f0 = (*(*(*e0).kindU.S6.sons->data[((NI) 0)]).kindU.S6.sons->data[((NI) 1)]).kindU.S4.sym; field0 = lookupfieldagain_555153_839829468(p0, ty0, f0, &r0); { if (!((*field0).loc.r == NIM_NIL)) goto LA7; internalerror_198100_155036129((*e0).info, ((NimStringDesc*) &T839829468_532)); } LA7: ; genfieldcheck_555504_839829468(p0, e0, r0, field0, ty0); memset((void*)LOC9, 0, sizeof(LOC9)); LOC9[0] = (*field0).loc.r; LOC10 = (Ropeobj180006*)0; LOC10 = ropecg_534407_839829468(NIM_NIL, ((NimStringDesc*) &T839829468_551), LOC9, 1); add_180482_2381377266(&r0, LOC10); putintodest_552468_839829468(p0, d0, (*field0).typ, r0, a0.s); } goto LA1; LA3: ; { genrecordfield_555448_839829468(p0, (*e0).kindU.S6.sons->data[((NI) 0)], d0); } LA1: ; } N_NIMCALL(NI, startblock_545978_839829468)(Tcproc531021* p0, NimStringDesc* start0, Ropeobj180006** args0, NI args0Len0) { NI result0; result0 = (NI)0; linecg_534707_839829468(p0, ((Tcprocsection531011) 2), start0, args0, args0Len0); (*p0).labels += ((NI) 1); result0 = ((*p0).blocks ? (*p0).blocks->Sup.len : 0); (*p0).blocks = (TY531095*) setLengthSeq(&((*p0).blocks)->Sup, sizeof(Tblock531019), ((NI) ((NI)(result0 + ((NI) 1))))); (*p0).blocks->data[result0].id = ((NI) ((*p0).labels)); (*p0).blocks->data[result0].nestedtrystmts = ((NI16) (((*p0).nestedtrystmts ? (*p0).nestedtrystmts->Sup.len : 0))); (*p0).blocks->data[result0].nestedexceptstmts = ((NI16) ((*p0).inexceptblock)); return result0; } N_NIMCALL(Ropeobj180006*, blockbody_546025_839829468)(Tblock531019* b0) { Ropeobj180006* result0; result0 = (Ropeobj180006*)0; result0 = (*b0).sections[(((Tcprocsection531011) 0))- 0]; { TY180507 LOC5; if (!(((NI16) 0) < (*b0).framelen)) goto LA3; memset((void*)LOC5, 0, sizeof(LOC5)); LOC5[0] = rope_180401_2381377266(((NI64) ((*b0).framelen))); addf_181205_2381377266(&result0, ((NimStringDesc*) &T839829468_554), LOC5, 1); } LA3: ; add_180482_2381377266(&result0, (*b0).sections[(((Tcprocsection531011) 1))- 0]); add_180482_2381377266(&result0, (*b0).sections[(((Tcprocsection531011) 2))- 0]); return result0; } N_NIMCALL(void, endblock_546035_839829468)(Tcproc531021* p0, Ropeobj180006* blockend0) { NI topblock0; Ropeobj180006* LOC1; topblock0 = (NI)(((*p0).blocks ? (*p0).blocks->Sup.len : 0) - ((NI) 1)); LOC1 = (Ropeobj180006*)0; LOC1 = blockbody_546025_839829468((&(*p0).blocks->data[topblock0])); add_180482_2381377266(&(*p0).blocks->data[(NI)(topblock0 - ((NI) 1))].sections[(((Tcprocsection531011) 2))- 0], LOC1); (*p0).blocks = (TY531095*) setLengthSeq(&((*p0).blocks)->Sup, sizeof(Tblock531019), ((NI) (topblock0))); line_534690_839829468(p0, ((Tcprocsection531011) 2), blockend0); } N_NIMCALL(void, endblock_546060_839829468)(Tcproc531021* p0) { NI topblock0; Ropeobj180006* blockend0; NI16 framelen0; topblock0 = (NI)(((*p0).blocks ? (*p0).blocks->Sup.len : 0) - ((NI) 1)); { TY180507 LOC5; if (!!(((*p0).blocks->data[topblock0].label == NIM_NIL))) goto LA3; memset((void*)LOC5, 0, sizeof(LOC5)); LOC5[0] = (*p0).blocks->data[topblock0].label; blockend0 = ropecg_534407_839829468(NIM_NIL, ((NimStringDesc*) &T839829468_552), LOC5, 1); } goto LA1; LA3: ; { TY535289 LOC7; memset((void*)LOC7, 0, sizeof(LOC7)); blockend0 = HEX25_180905_2381377266(((NimStringDesc*) &T839829468_160), LOC7, 0); } LA1: ; framelen0 = (*p0).blocks->data[topblock0].framelen; { TY180507 LOC12; if (!(((NI16) 0) < framelen0)) goto LA10; memset((void*)LOC12, 0, sizeof(LOC12)); LOC12[0] = rope_180401_2381377266(((NI64) (framelen0))); addf_181205_2381377266(&blockend0, ((NimStringDesc*) &T839829468_553), LOC12, 1); } LA10: ; endblock_546035_839829468(p0, blockend0); } N_NIMCALL(void, genblock_548083_839829468)(Tcproc531021* p0, Tnode294802* n0, Tloc294816* d0) { NI oldbreakidx_548099_839829468; TY535289 LOC8; { NIM_BOOL LOC3; NIM_BOOL LOC4; LOC3 = (NIM_BOOL)0; LOC4 = (NIM_BOOL)0; LOC4 = isemptytype_299440_850551059((*n0).typ); LOC3 = !(LOC4); if (!(LOC3)) goto LA5; LOC3 = ((*d0).k == ((Tlockind294808) 0)); LA5: ; if (!LOC3) goto LA6; gettemp_539032_839829468(p0, (*n0).typ, d0, NIM_FALSE); } LA6: ; oldbreakidx_548099_839829468 = (*p0).breakidx; memset((void*)LOC8, 0, sizeof(LOC8)); (*p0).breakidx = startblock_545978_839829468(p0, ((NimStringDesc*) &T839829468_273), LOC8, 0); { Tsym294834* sym0; if (!!(((*(*n0).kindU.S6.sons->data[((NI) 0)]).kind == ((Tnodekind294020) 1)))) goto LA11; sym0 = (*(*n0).kindU.S6.sons->data[((NI) 0)]).kindU.S4.sym; (*sym0).loc.k = ((Tlockind294808) 10); (*sym0).position = (NI)((*p0).breakidx + ((NI) 1)); } LA11: ; expr_541248_839829468(p0, (*n0).kindU.S6.sons->data[((NI) 1)], d0); endblock_546060_839829468(p0); (*p0).breakidx = oldbreakidx_548099_839829468; } N_NIMCALL(void, genstmtlistexpr_560402_839829468)(Tcproc531021* p0, Tnode294802* n0, Tloc294816* d0) { NI length0; length0 = sonslen_297351_850551059(n0); { NI i_560420_839829468; NI HEX3Atmp_560424_839829468; NI res_560427_839829468; i_560420_839829468 = (NI)0; HEX3Atmp_560424_839829468 = (NI)0; HEX3Atmp_560424_839829468 = (NI)(length0 - ((NI) 2)); res_560427_839829468 = ((NI) 0); { while (1) { if (!(res_560427_839829468 <= HEX3Atmp_560424_839829468)) goto LA3; i_560420_839829468 = res_560427_839829468; genstmts_541244_839829468(p0, (*n0).kindU.S6.sons->data[i_560420_839829468]); res_560427_839829468 += ((NI) 1); } LA3: ; } } { if (!(((NI) 0) < length0)) goto LA6; expr_541248_839829468(p0, (*n0).kindU.S6.sons->data[(NI)(length0 - ((NI) 1))], d0); } LA6: ; } N_NIMCALL(void, genif_546982_839829468)(Tcproc531021* p0, Tnode294802* n0, Tloc294816* d0) { Tloc294816 a0; Ropeobj180006* lelse0; Ropeobj180006* lend0; memset((void*)(&a0), 0, sizeof(a0)); lelse0 = (Ropeobj180006*)0; { NIM_BOOL LOC3; NIM_BOOL LOC4; LOC3 = (NIM_BOOL)0; LOC4 = (NIM_BOOL)0; LOC4 = isemptytype_299440_850551059((*n0).typ); LOC3 = !(LOC4); if (!(LOC3)) goto LA5; LOC3 = ((*d0).k == ((Tlockind294808) 0)); LA5: ; if (!LOC3) goto LA6; gettemp_539032_839829468(p0, (*n0).typ, d0, NIM_FALSE); } LA6: ; genlinedir_534823_839829468(p0, n0); lend0 = getlabel_541217_839829468(p0); { NI i_547011_839829468; NI HEX3Atmp_547435_839829468; NI LOC9; NI res_547438_839829468; i_547011_839829468 = (NI)0; HEX3Atmp_547435_839829468 = (NI)0; LOC9 = (NI)0; LOC9 = sonslen_297351_850551059(n0); HEX3Atmp_547435_839829468 = (NI)(LOC9 - ((NI) 1)); res_547438_839829468 = ((NI) 0); { while (1) { Tnode294802* it0; if (!(res_547438_839829468 <= HEX3Atmp_547435_839829468)) goto LA11; i_547011_839829468 = res_547438_839829468; { NIM_BOOL LOC14; LOC14 = (NIM_BOOL)0; LOC14 = ((*d0).k == ((Tlockind294808) 1)); if (!(LOC14)) goto LA15; LOC14 = isemptytype_299440_850551059((*n0).typ); LA15: ; if (!LOC14) goto LA16; (*d0).k = ((Tlockind294808) 0); } LA16: ; it0 = (*n0).kindU.S6.sons->data[i_547011_839829468]; { NI LOC20; TY535289 LOC23; NI LOC24; TY534811 LOC25; LOC20 = (NI)0; LOC20 = len_295081_850551059(it0); if (!(LOC20 == ((NI) 2))) goto LA21; memset((void*)LOC23, 0, sizeof(LOC23)); LOC24 = (NI)0; LOC24 = startblock_545978_839829468(p0, ((NimStringDesc*) &T839829468_273), LOC23, 0); initlocexprsingleuse_541289_839829468(p0, (*it0).kindU.S6.sons->data[((NI) 0)], (&a0)); lelse0 = getlabel_541217_839829468(p0); (*p0).labels += ((NI) 1); memset((void*)LOC25, 0, sizeof(LOC25)); LOC25[0] = rdloc_540188_839829468(a0); LOC25[1] = lelse0; linef_534700_839829468(p0, ((Tcprocsection531011) 2), ((NimStringDesc*) &T839829468_555), LOC25, 2); { NIM_BOOL LOC28; Ropeobj180006** LOC32; Ropeobj180006** LOC33; LOC28 = (NIM_BOOL)0; LOC28 = (gcmd_171132_2607990831 == ((Tcommands171076) 2)); if (LOC28) goto LA29; LOC28 = (((*(*(*p0).module).module).flags &(1U<<((NU)(((Tsymflag294184) 27))&31U)))!=0); LA29: ; if (!LOC28) goto LA30; LOC32 = (Ropeobj180006**)0; LOC32 = s_531179_3723162438(p0, ((Tcprocsection531011) 2)); add_180487_2381377266(LOC32, ((NimStringDesc*) &T839829468_223)); expr_541248_839829468(p0, (*it0).kindU.S6.sons->data[((NI) 1)], d0); LOC33 = (Ropeobj180006**)0; LOC33 = s_531179_3723162438(p0, ((Tcprocsection531011) 2)); add_180487_2381377266(LOC33, ((NimStringDesc*) &T839829468_280)); } goto LA26; LA30: ; { expr_541248_839829468(p0, (*it0).kindU.S6.sons->data[((NI) 1)], d0); } LA26: ; endblock_546060_839829468(p0); { NI LOC37; TY180507 LOC40; LOC37 = (NI)0; LOC37 = sonslen_297351_850551059(n0); if (!(((NI) 1) < LOC37)) goto LA38; memset((void*)LOC40, 0, sizeof(LOC40)); LOC40[0] = lend0; linef_534700_839829468(p0, ((Tcprocsection531011) 2), ((NimStringDesc*) &T839829468_556), LOC40, 1); } LA38: ; fixlabel_541230_839829468(p0, lelse0); } goto LA18; LA21: ; { NI LOC42; TY535289 LOC45; NI LOC46; LOC42 = (NI)0; LOC42 = len_295081_850551059(it0); if (!(LOC42 == ((NI) 1))) goto LA43; memset((void*)LOC45, 0, sizeof(LOC45)); LOC46 = (NI)0; LOC46 = startblock_545978_839829468(p0, ((NimStringDesc*) &T839829468_273), LOC45, 0); expr_541248_839829468(p0, (*it0).kindU.S6.sons->data[((NI) 0)], d0); endblock_546060_839829468(p0); } goto LA18; LA43: ; { internalerror_198100_155036129((*n0).info, ((NimStringDesc*) &T839829468_557)); } LA18: ; res_547438_839829468 += ((NI) 1); } LA11: ; } } { NI LOC50; LOC50 = (NI)0; LOC50 = sonslen_297351_850551059(n0); if (!(((NI) 1) < LOC50)) goto LA51; fixlabel_541230_839829468(p0, lend0); } LA51: ; } N_NIMCALL(void, downconv_560581_839829468)(Tcproc531021* p0, Tnode294802* n0, Tloc294816* d0) { { NIM_BOOL LOC3; LOC3 = (NIM_BOOL)0; LOC3 = (gcmd_171132_2607990831 == ((Tcommands171076) 2)); if (LOC3) goto LA4; LOC3 = (((*(*(*p0).module).module).flags &(1U<<((NU)(((Tsymflag294184) 27))&31U)))!=0); LA4: ; if (!LOC3) goto LA5; expr_541248_839829468(p0, (*n0).kindU.S6.sons->data[((NI) 0)], d0); } goto LA1; LA5: ; { Ttype294840* dest0; Tnode294802* arg0; Ttype294840* src0; Tloc294816 a0; Ropeobj180006* r0; NIM_BOOL isref0; Ttype294840* LOC10; dest0 = skiptypes_298099_850551059((*n0).typ, IL64(211106247256320)); arg0 = (*n0).kindU.S6.sons->data[((NI) 0)]; { while (1) { if (!((*arg0).kind == ((Tnodekind294020) 66))) goto LA9; arg0 = (*arg0).kindU.S6.sons->data[((NI) 0)]; } LA9: ; } src0 = skiptypes_298099_850551059((*arg0).typ, IL64(211106247256320)); memset((void*)(&a0), 0, sizeof(a0)); initlocexpr_541283_839829468(p0, arg0, (&a0)); r0 = rdloc_540188_839829468(a0); LOC10 = (Ttype294840*)0; LOC10 = skiptypes_298099_850551059((*arg0).typ, IL64(211106232576256)); isref0 = ((*LOC10).kind == ((Ttypekind294244) 22) || (*LOC10).kind == ((Ttypekind294244) 21) || (*LOC10).kind == ((Ttypekind294244) 23)); { if (!isref0) goto LA13; add_180487_2381377266(&r0, ((NimStringDesc*) &T839829468_558)); } goto LA11; LA13: ; { add_180487_2381377266(&r0, ((NimStringDesc*) &T839829468_153)); } LA11: ; { NI i_560650_839829468; NI HEX3Atmp_560677_839829468; NI LOC17; NI res_560680_839829468; i_560650_839829468 = (NI)0; HEX3Atmp_560677_839829468 = (NI)0; LOC17 = (NI)0; LOC17 = inheritancediff_328252_3876443242(dest0, src0); HEX3Atmp_560677_839829468 = (LOC17 > 0? (LOC17) : -(LOC17)); res_560680_839829468 = ((NI) 2); { while (1) { if (!(res_560680_839829468 <= HEX3Atmp_560677_839829468)) goto LA19; i_560650_839829468 = res_560680_839829468; add_180487_2381377266(&r0, ((NimStringDesc*) &T839829468_153)); res_560680_839829468 += ((NI) 1); } LA19: ; } } { if (!isref0) goto LA22; { NIM_BOOL LOC26; Ttype294840* LOC28; TY534811 LOC31; LOC26 = (NIM_BOOL)0; LOC26 = ((*d0).k == ((Tlockind294808) 0)); if (!(LOC26)) goto LA27; LOC28 = (Ttype294840*)0; LOC28 = skiptypes_298099_850551059((*n0).typ, IL64(211106232576256)); LOC26 = ((*LOC28).kind == ((Ttypekind294244) 22) || (*LOC28).kind == ((Ttypekind294244) 21) || (*LOC28).kind == ((Ttypekind294244) 23)); LA27: ; if (!LOC26) goto LA29; gettemp_539032_839829468(p0, (*n0).typ, d0, NIM_FALSE); memset((void*)LOC31, 0, sizeof(LOC31)); LOC31[0] = rdloc_540188_839829468((*d0)); LOC31[1] = r0; linefmt_534714_839829468(p0, ((Tcprocsection531011) 2), ((NimStringDesc*) &T839829468_559), LOC31, 2); } goto LA24; LA29: ; { r0 = HEX26_180452_2381377266(((NimStringDesc*) &T839829468_52), r0); putintodest_552468_839829468(p0, d0, (*n0).typ, r0, a0.s); } LA24: ; } goto LA20; LA22: ; { putintodest_552468_839829468(p0, d0, (*n0).typ, r0, a0.s); } LA20: ; } LA1: ; } N_NIMCALL(void, upconv_560431_839829468)(Tcproc531021* p0, Tnode294802* n0, Tloc294816* d0) { Tloc294816 a0; Ttype294840* dest0; memset((void*)(&a0), 0, sizeof(a0)); initlocexpr_541283_839829468(p0, (*n0).kindU.S6.sons->data[((NI) 0)], (&a0)); dest0 = skiptypes_298099_850551059((*n0).typ, IL64(211106247256320)); { NIM_BOOL LOC3; NIM_BOOL LOC5; Ropeobj180006* r0; Ropeobj180006* nilcheck0; Ttype294840* t0; LOC3 = (NIM_BOOL)0; LOC3 = (((*p0).options &(1U<<((NU)(((Toption171009) 1))&31U)))!=0); if (!(LOC3)) goto LA4; LOC5 = (NIM_BOOL)0; LOC5 = isobjlackingtypefield_535513_839829468(dest0); LOC3 = !(LOC5); LA4: ; if (!LOC3) goto LA6; r0 = rdloc_540188_839829468(a0); nilcheck0 = NIM_NIL; t0 = skiptypes_298099_850551059(a0.t, IL64(211106232576256)); { while (1) { Ttype294840* LOC23; if (!((*t0).kind == ((Ttypekind294244) 23) || (*t0).kind == ((Ttypekind294244) 21) || (*t0).kind == ((Ttypekind294244) 22))) goto LA9; { if (!!(((*t0).kind == ((Ttypekind294244) 23)))) goto LA12; nilcheck0 = r0; } LA12: ; { NIM_BOOL LOC16; NIM_BOOL LOC18; TY180507 LOC22; LOC16 = (NIM_BOOL)0; LOC16 = !(((*t0).kind == ((Ttypekind294244) 23))); if (LOC16) goto LA17; LOC18 = (NIM_BOOL)0; LOC18 = (gcmd_171132_2607990831 == ((Tcommands171076) 2)); if (LOC18) goto LA19; LOC18 = (((*(*(*p0).module).module).flags &(1U<<((NU)(((Tsymflag294184) 27))&31U)))!=0); LA19: ; LOC16 = !(LOC18); LA17: ; if (!LOC16) goto LA20; memset((void*)LOC22, 0, sizeof(LOC22)); LOC22[0] = r0; r0 = HEX25_180905_2381377266(((NimStringDesc*) &T839829468_124), LOC22, 1); } LA20: ; LOC23 = (Ttype294840*)0; LOC23 = lastson_297377_850551059(t0); t0 = skiptypes_298099_850551059(LOC23, IL64(211106232576256)); } LA9: ; } { NIM_BOOL LOC26; LOC26 = (NIM_BOOL)0; LOC26 = (gcmd_171132_2607990831 == ((Tcommands171076) 2)); if (LOC26) goto LA27; LOC26 = (((*(*(*p0).module).module).flags &(1U<<((NU)(((Tsymflag294184) 27))&31U)))!=0); LA27: ; if (!!(LOC26)) goto LA28; { while (1) { NIM_BOOL LOC32; LOC32 = (NIM_BOOL)0; LOC32 = ((*t0).kind == ((Ttypekind294244) 17)); if (!(LOC32)) goto LA33; LOC32 = !(((*t0).sons->data[((NI) 0)] == NIM_NIL)); LA33: ; if (!LOC32) goto LA31; add_180487_2381377266(&r0, ((NimStringDesc*) &T839829468_153)); t0 = skiptypes_298099_850551059((*t0).sons->data[((NI) 0)], IL64(211106247215360)); } LA31: ; } } LA28: ; { TY537238 LOC38; if (!!((nilcheck0 == NIM_NIL))) goto LA36; memset((void*)LOC38, 0, sizeof(LOC38)); LOC38[0] = nilcheck0; LOC38[1] = r0; LOC38[2] = gentypeinfo_537941_839829468((*p0).module, dest0); linefmt_534714_839829468(p0, ((Tcprocsection531011) 2), ((NimStringDesc*) &T839829468_560), LOC38, 3); } goto LA34; LA36: ; { TY534811 LOC40; memset((void*)LOC40, 0, sizeof(LOC40)); LOC40[0] = r0; LOC40[1] = gentypeinfo_537941_839829468((*p0).module, dest0); linefmt_534714_839829468(p0, ((Tcprocsection531011) 2), ((NimStringDesc*) &T839829468_561), LOC40, 2); } LA34: ; } LA6: ; { TY534811 LOC45; Ropeobj180006* LOC46; if (!!(((*(*(*n0).kindU.S6.sons->data[((NI) 0)]).typ).kind == ((Ttypekind294244) 17)))) goto LA43; memset((void*)LOC45, 0, sizeof(LOC45)); LOC45[0] = gettypedesc_537671_839829468((*p0).module, (*n0).typ); LOC45[1] = rdloc_540188_839829468(a0); LOC46 = (Ropeobj180006*)0; LOC46 = HEX25_180905_2381377266(((NimStringDesc*) &T839829468_430), LOC45, 2); putintodest_552468_839829468(p0, d0, (*n0).typ, LOC46, a0.s); } goto LA41; LA43: ; { TY534811 LOC48; Ropeobj180006* LOC49; memset((void*)LOC48, 0, sizeof(LOC48)); LOC48[0] = gettypedesc_537671_839829468((*p0).module, dest0); LOC48[1] = addrloc_540204_839829468(a0); LOC49 = (Ropeobj180006*)0; LOC49 = HEX25_180905_2381377266(((NimStringDesc*) &T839829468_429), LOC48, 2); putintodest_552468_839829468(p0, d0, (*n0).typ, LOC49, a0.s); } LA41: ; } N_NIMCALL(void, genrangechck_558590_839829468)(Tcproc531021* p0, Tnode294802* n0, Tloc294816* d0, NimStringDesc* magic0) { Tloc294816 a0; Ttype294840* dest0; memset((void*)(&a0), 0, sizeof(a0)); dest0 = skiptypes_298099_850551059((*n0).typ, IL64(211106240964864)); { NIM_BOOL LOC3; Ttype294840* LOC5; TY534811 LOC8; Ropeobj180006* LOC9; LOC3 = (NIM_BOOL)0; LOC3 = !((((*p0).options &(1U<<((NU)(((Toption171009) 3))&31U)))!=0)); if (LOC3) goto LA4; LOC5 = (Ttype294840*)0; LOC5 = skiptypes_298099_850551059(dest0, 1048576); LOC3 = ((*LOC5).kind >= ((Ttypekind294244) 40) && (*LOC5).kind <= ((Ttypekind294244) 44)); LA4: ; if (!LOC3) goto LA6; initlocexpr_541283_839829468(p0, (*n0).kindU.S6.sons->data[((NI) 0)], (&a0)); memset((void*)LOC8, 0, sizeof(LOC8)); LOC8[0] = gettypedesc_537671_839829468((*p0).module, dest0); LOC8[1] = rdcharloc_540227_839829468(a0); LOC9 = (Ropeobj180006*)0; LOC9 = HEX25_180905_2381377266(((NimStringDesc*) &T839829468_430), LOC8, 2); putintodest_552468_839829468(p0, d0, (*n0).typ, LOC9, a0.s); } goto LA1; LA6: ; { TY538475 LOC11; Ropeobj180006* LOC12; initlocexpr_541283_839829468(p0, (*n0).kindU.S6.sons->data[((NI) 0)], (&a0)); memset((void*)LOC11, 0, sizeof(LOC11)); LOC11[0] = gettypedesc_537671_839829468((*p0).module, dest0); LOC11[1] = rdcharloc_540227_839829468(a0); LOC11[2] = genliteral_551476_839829468(p0, (*n0).kindU.S6.sons->data[((NI) 1)], dest0); LOC11[3] = genliteral_551476_839829468(p0, (*n0).kindU.S6.sons->data[((NI) 2)], dest0); LOC11[4] = rope_180277_2381377266(magic0); LOC12 = (Ropeobj180006*)0; LOC12 = ropecg_534407_839829468((*p0).module, ((NimStringDesc*) &T839829468_562), LOC11, 5); putintodest_552468_839829468(p0, d0, dest0, LOC12, a0.s); } LA1: ; } N_NIMCALL(void, convstrtocstr_558642_839829468)(Tcproc531021* p0, Tnode294802* n0, Tloc294816* d0) { Tloc294816 a0; Ttype294840* LOC1; TY180507 LOC2; Ropeobj180006* LOC3; memset((void*)(&a0), 0, sizeof(a0)); initlocexpr_541283_839829468(p0, (*n0).kindU.S6.sons->data[((NI) 0)], (&a0)); LOC1 = (Ttype294840*)0; LOC1 = skiptypes_298099_850551059((*n0).typ, IL64(211106240964864)); memset((void*)LOC2, 0, sizeof(LOC2)); LOC2[0] = rdloc_540188_839829468(a0); LOC3 = (Ropeobj180006*)0; LOC3 = HEX25_180905_2381377266(((NimStringDesc*) &T839829468_485), LOC2, 1); putintodest_552468_839829468(p0, d0, LOC1, LOC3, a0.s); } N_NIMCALL(void, convcstrtostr_558654_839829468)(Tcproc531021* p0, Tnode294802* n0, Tloc294816* d0) { Tloc294816 a0; Ttype294840* LOC1; TY180507 LOC2; Ropeobj180006* LOC3; memset((void*)(&a0), 0, sizeof(a0)); initlocexpr_541283_839829468(p0, (*n0).kindU.S6.sons->data[((NI) 0)], (&a0)); LOC1 = (Ttype294840*)0; LOC1 = skiptypes_298099_850551059((*n0).typ, IL64(211106240964864)); memset((void*)LOC2, 0, sizeof(LOC2)); LOC2[0] = rdloc_540188_839829468(a0); LOC3 = (Ropeobj180006*)0; LOC3 = ropecg_534407_839829468((*p0).module, ((NimStringDesc*) &T839829468_411), LOC2, 1); putintodest_552468_839829468(p0, d0, LOC1, LOC3, a0.s); gcusage_556439_839829468(n0); } static N_INLINE(NIM_BOOL, isroutine_299323_850551059)(Tsym294834* s0) { NIM_BOOL result0; result0 = (NIM_BOOL)0; result0 = ((258048 &(1U<<((NU)((*s0).kind)&31U)))!=0); return result0; } static N_INLINE(NIM_BOOL, isconstclosure_559810_839829468)(Tnode294802* n0) { NIM_BOOL result0; NIM_BOOL LOC1; NIM_BOOL LOC2; result0 = (NIM_BOOL)0; LOC1 = (NIM_BOOL)0; LOC2 = (NIM_BOOL)0; LOC2 = ((*(*n0).kindU.S6.sons->data[((NI) 0)]).kind == ((Tnodekind294020) 3)); if (!(LOC2)) goto LA3; LOC2 = isroutine_299323_850551059((*(*n0).kindU.S6.sons->data[((NI) 0)]).kindU.S4.sym); LA3: ; LOC1 = LOC2; if (!(LOC1)) goto LA4; LOC1 = ((*(*n0).kindU.S6.sons->data[((NI) 1)]).kind == ((Tnodekind294020) 23)); LA4: ; result0 = LOC1; return result0; } N_NIMCALL(void, genclosure_559836_839829468)(Tcproc531021* p0, Tnode294802* n0, Tloc294816* d0) { { NIM_BOOL LOC3; Ropeobj180006* tmp0; Ropeobj180006* LOC6; TY537238 LOC7; LOC3 = (NIM_BOOL)0; LOC3 = isconstclosure_559810_839829468(n0); if (!LOC3) goto LA4; (*(*p0).module).labels += ((NI) 1); LOC6 = (Ropeobj180006*)0; LOC6 = rope_180401_2381377266(((NI64) ((*(*p0).module).labels))); tmp0 = HEX26_180452_2381377266(((NimStringDesc*) &T839829468_566), LOC6); memset((void*)LOC7, 0, sizeof(LOC7)); LOC7[0] = gettypedesc_537671_839829468((*p0).module, (*n0).typ); LOC7[1] = tmp0; LOC7[2] = genconstexpr_556849_839829468(p0, n0); addf_181205_2381377266(&(*(*p0).module).s[(((Tcfilesection531005) 8))- 0], ((NimStringDesc*) &T839829468_524), LOC7, 3); putintodest_552468_839829468(p0, d0, (*n0).typ, tmp0, ((Tstorageloc294812) 1)); } goto LA1; LA4: ; { Tloc294816 tmp0; Tloc294816 a0; Tloc294816 b0; TY537238 LOC14; memset((void*)(&tmp0), 0, sizeof(tmp0)); memset((void*)(&a0), 0, sizeof(a0)); memset((void*)(&b0), 0, sizeof(b0)); initlocexpr_541283_839829468(p0, (*n0).kindU.S6.sons->data[((NI) 0)], (&a0)); initlocexpr_541283_839829468(p0, (*n0).kindU.S6.sons->data[((NI) 1)], (&b0)); { Tnode294802* LOC11; LOC11 = (Tnode294802*)0; LOC11 = skipconv_330882_3876443242((*n0).kindU.S6.sons->data[((NI) 0)]); if (!((*LOC11).kind == ((Tnodekind294020) 155))) goto LA12; internalerror_198100_155036129((*n0).info, ((NimStringDesc*) &T839829468_567)); } LA12: ; gettemp_539032_839829468(p0, (*n0).typ, (&tmp0), NIM_FALSE); memset((void*)LOC14, 0, sizeof(LOC14)); LOC14[0] = rdloc_540188_839829468(tmp0); LOC14[1] = rdloc_540188_839829468(a0); LOC14[2] = rdloc_540188_839829468(b0); linefmt_534714_839829468(p0, ((Tcprocsection531011) 2), ((NimStringDesc*) &T839829468_568), LOC14, 3); putlocintodest_541258_839829468(p0, d0, tmp0); } LA1: ; } static N_INLINE(Ropeobj180006*, assignlabel_546020_839829468)(Tblock531019* b0) { Ropeobj180006* result0; Ropeobj180006* LOC1; result0 = (Ropeobj180006*)0; LOC1 = (Ropeobj180006*)0; LOC1 = rope_180401_2381377266(((NI64) ((*b0).id))); unsureAsgnRef((void**) (&(*b0).label), HEX26_180452_2381377266(((NimStringDesc*) &T839829468_296), LOC1)); result0 = (*b0).label; return result0; } N_NIMCALL(void, gencomputedgoto_547744_839829468)(Tcproc531021* p0, Tnode294802* n0) { NI casepos0; NI arraysize0; NI id0; Ropeobj180006* tmp0; TY180507 LOC27; Ropeobj180006* gotoarray0; TY534811 LOC28; TY180507 LOC33; NI topblock0; Ropeobj180006* oldbody0; Ropeobj180006* tailb0; Ropeobj180006* taila0; Tnode294802* casestmt0; Tloc294816 a_547871_839829468; TY534811 LOC41; { casepos0 = ((NI) -1); arraysize0 = (NI)0; { NI i_547768_839829468; NI HEX3Atmp_547933_839829468; NI LOC2; NI res_547936_839829468; i_547768_839829468 = (NI)0; HEX3Atmp_547933_839829468 = (NI)0; LOC2 = (NI)0; LOC2 = len_295081_850551059(n0); HEX3Atmp_547933_839829468 = (LOC2 - 1); res_547936_839829468 = ((NI) 0); { while (1) { Tnode294802* it0; if (!(res_547936_839829468 <= HEX3Atmp_547933_839829468)) goto LA4; i_547768_839829468 = res_547936_839829468; it0 = (*n0).kindU.S6.sons->data[i_547768_839829468]; { NI64 asize0; if (!((*it0).kind == ((Tnodekind294020) 97))) goto LA7; { Tnode294802* LOC11; LOC11 = (Tnode294802*)0; LOC11 = lastson_297364_850551059(it0); if (!!(((*LOC11).kind == ((Tnodekind294020) 85)))) goto LA12; localerror_198085_155036129((*it0).info, ((NimStringDesc*) &T839829468_570)); goto BeforeRet; } LA12: ; casepos0 = i_547768_839829468; asize0 = lengthord_322007_3876443242((*(*it0).kindU.S6.sons->data[((NI) 0)]).typ); { if (!(IL64(10000) < asize0)) goto LA16; localerror_198085_155036129((*it0).info, ((NimStringDesc*) &T839829468_571)); goto BeforeRet; } LA16: ; arraysize0 = ((NI) (asize0)); { NI64 LOC20; LOC20 = (NI64)0; LOC20 = firstord_322001_3876443242((*(*it0).kindU.S6.sons->data[((NI) 0)]).typ); if (!!((LOC20 == IL64(0)))) goto LA21; localerror_198085_155036129((*it0).info, ((NimStringDesc*) &T839829468_572)); goto BeforeRet; } LA21: ; } LA7: ; res_547936_839829468 += ((NI) 1); } LA4: ; } } { if (!(casepos0 < ((NI) 0))) goto LA25; localerror_198085_155036129((*n0).info, ((NimStringDesc*) &T839829468_573)); goto BeforeRet; } LA25: ; id0 = (NI)(((NI) ((*p0).labels)) + ((NI) 1)); (*p0).labels += (NI)(arraysize0 + ((NI) 1)); memset((void*)LOC27, 0, sizeof(LOC27)); LOC27[0] = rope_180401_2381377266(((NI64) (id0))); tmp0 = HEX25_180905_2381377266(((NimStringDesc*) &T839829468_574), LOC27, 1); memset((void*)LOC28, 0, sizeof(LOC28)); LOC28[0] = tmp0; LOC28[1] = rope_180401_2381377266(((NI64) (arraysize0))); gotoarray0 = HEX25_180905_2381377266(((NimStringDesc*) &T839829468_575), LOC28, 2); { NI i_547819_839829468; NI HEX3Atmp_547941_839829468; NI res_547944_839829468; i_547819_839829468 = (NI)0; HEX3Atmp_547941_839829468 = (NI)0; HEX3Atmp_547941_839829468 = (NI)(arraysize0 - ((NI) 1)); res_547944_839829468 = ((NI) 1); { while (1) { TY180507 LOC32; if (!(res_547944_839829468 <= HEX3Atmp_547941_839829468)) goto LA31; i_547819_839829468 = res_547944_839829468; memset((void*)LOC32, 0, sizeof(LOC32)); LOC32[0] = rope_180401_2381377266(((NI64) ((NI)(((NI) (id0)) + i_547819_839829468)))); addf_181205_2381377266(&gotoarray0, ((NimStringDesc*) &T839829468_576), LOC32, 1); res_547944_839829468 += ((NI) 1); } LA31: ; } } memset((void*)LOC33, 0, sizeof(LOC33)); LOC33[0] = rope_180401_2381377266(((NI64) ((NI)(((NI) (id0)) + arraysize0)))); addf_181205_2381377266(&gotoarray0, ((NimStringDesc*) &T839829468_577), LOC33, 1); line_534690_839829468(p0, ((Tcprocsection531011) 0), gotoarray0); topblock0 = (NI)(((*p0).blocks ? (*p0).blocks->Sup.len : 0) - ((NI) 1)); oldbody0 = (*p0).blocks->data[topblock0].sections[(((Tcprocsection531011) 2))- 0]; asgnRefNoCycle((void**) (&(*p0).blocks->data[topblock0].sections[(((Tcprocsection531011) 2))- 0]), NIM_NIL); { NI j_547854_839829468; NI HEX3Atmp_547949_839829468; NI HEX3Atmp_547950_839829468; NI LOC35; NI res_547953_839829468; j_547854_839829468 = (NI)0; HEX3Atmp_547949_839829468 = (NI)0; HEX3Atmp_547950_839829468 = (NI)0; HEX3Atmp_547949_839829468 = (NI)(casepos0 + ((NI) 1)); LOC35 = (NI)0; LOC35 = len_295081_850551059(n0); HEX3Atmp_547950_839829468 = (LOC35 - 1); res_547953_839829468 = HEX3Atmp_547949_839829468; { while (1) { if (!(res_547953_839829468 <= HEX3Atmp_547950_839829468)) goto LA37; j_547854_839829468 = res_547953_839829468; genstmts_541244_839829468(p0, (*n0).kindU.S6.sons->data[j_547854_839829468]); res_547953_839829468 += ((NI) 1); } LA37: ; } } tailb0 = (*p0).blocks->data[topblock0].sections[(((Tcprocsection531011) 2))- 0]; asgnRefNoCycle((void**) (&(*p0).blocks->data[topblock0].sections[(((Tcprocsection531011) 2))- 0]), NIM_NIL); { NI j_547866_839829468; NI HEX3Atmp_547958_839829468; NI res_547961_839829468; j_547866_839829468 = (NI)0; HEX3Atmp_547958_839829468 = (NI)0; HEX3Atmp_547958_839829468 = (NI)(casepos0 - ((NI) 1)); res_547961_839829468 = ((NI) 0); { while (1) { if (!(res_547961_839829468 <= HEX3Atmp_547958_839829468)) goto LA40; j_547866_839829468 = res_547961_839829468; genstmts_541244_839829468(p0, (*n0).kindU.S6.sons->data[j_547866_839829468]); res_547961_839829468 += ((NI) 1); } LA40: ; } } taila0 = (*p0).blocks->data[topblock0].sections[(((Tcprocsection531011) 2))- 0]; asgnRefNoCycle((void**) (&(*p0).blocks->data[topblock0].sections[(((Tcprocsection531011) 2))- 0]), HEX26_180418_2381377266(oldbody0, taila0)); casestmt0 = (*n0).kindU.S6.sons->data[casepos0]; memset((void*)(&a_547871_839829468), 0, sizeof(a_547871_839829468)); initlocexpr_541283_839829468(p0, (*casestmt0).kindU.S6.sons->data[((NI) 0)], (&a_547871_839829468)); memset((void*)LOC41, 0, sizeof(LOC41)); LOC41[0] = tmp0; LOC41[1] = rdloc_540188_839829468(a_547871_839829468); linef_534700_839829468(p0, ((Tcprocsection531011) 2), ((NimStringDesc*) &T839829468_578), LOC41, 2); { NI i_547894_839829468; NI HEX3Atmp_547977_839829468; NI LOC43; NI res_547980_839829468; i_547894_839829468 = (NI)0; HEX3Atmp_547977_839829468 = (NI)0; LOC43 = (NI)0; LOC43 = len_295081_850551059(casestmt0); HEX3Atmp_547977_839829468 = (LOC43 - 1); res_547980_839829468 = ((NI) 1); { while (1) { TY535289 LOC46; NI LOC47; Tnode294802* it0; Tnode294802* LOC57; Ropeobj180006** LOC58; Ropeobj180006** LOC59; Tloc294816 a0; TY534811 LOC60; if (!(res_547980_839829468 <= HEX3Atmp_547977_839829468)) goto LA45; i_547894_839829468 = res_547980_839829468; memset((void*)LOC46, 0, sizeof(LOC46)); LOC47 = (NI)0; LOC47 = startblock_545978_839829468(p0, ((NimStringDesc*) &T839829468_273), LOC46, 0); it0 = (*casestmt0).kindU.S6.sons->data[i_547894_839829468]; { NI j_547910_839829468; NI HEX3Atmp_547969_839829468; NI LOC49; NI res_547972_839829468; j_547910_839829468 = (NI)0; HEX3Atmp_547969_839829468 = (NI)0; LOC49 = (NI)0; LOC49 = len_295081_850551059(it0); HEX3Atmp_547969_839829468 = (NI)(LOC49 - ((NI) 2)); res_547972_839829468 = ((NI) 0); { while (1) { NI64 val0; TY180507 LOC56; if (!(res_547972_839829468 <= HEX3Atmp_547969_839829468)) goto LA51; j_547910_839829468 = res_547972_839829468; { if (!((*(*it0).kindU.S6.sons->data[j_547910_839829468]).kind == ((Tnodekind294020) 44))) goto LA54; localerror_198085_155036129((*it0).info, ((NimStringDesc*) &T839829468_579)); goto BeforeRet; } LA54: ; val0 = getordvalue_322129_3876443242((*it0).kindU.S6.sons->data[j_547910_839829468]); memset((void*)LOC56, 0, sizeof(LOC56)); LOC56[0] = intliteral_541270_839829468((NI64)((NI64)(val0 + ((NI64) (id0))) + IL64(1))); linef_534700_839829468(p0, ((Tcprocsection531011) 2), ((NimStringDesc*) &T839829468_580), LOC56, 1); res_547972_839829468 += ((NI) 1); } LA51: ; } } LOC57 = (Tnode294802*)0; LOC57 = lastson_297364_850551059(it0); genstmts_541244_839829468(p0, LOC57); LOC58 = (Ropeobj180006**)0; LOC58 = s_531179_3723162438(p0, ((Tcprocsection531011) 2)); add_180482_2381377266(LOC58, tailb0); LOC59 = (Ropeobj180006**)0; LOC59 = s_531179_3723162438(p0, ((Tcprocsection531011) 2)); add_180482_2381377266(LOC59, taila0); memset((void*)(&a0), 0, sizeof(a0)); initlocexpr_541283_839829468(p0, (*casestmt0).kindU.S6.sons->data[((NI) 0)], (&a0)); memset((void*)LOC60, 0, sizeof(LOC60)); LOC60[0] = tmp0; LOC60[1] = rdloc_540188_839829468(a0); linef_534700_839829468(p0, ((Tcprocsection531011) 2), ((NimStringDesc*) &T839829468_578), LOC60, 2); endblock_546060_839829468(p0); res_547980_839829468 += ((NI) 1); } LA45: ; } } }BeforeRet: ; } N_NIMCALL(void, genwhilestmt_547984_839829468)(Tcproc531021* p0, Tnode294802* t0) { Tloc294816 a0; NI oldbreakidx_548011_839829468; TY535289 LOC1; Tnode294802* loopbody0; memset((void*)(&a0), 0, sizeof(a0)); (*p0).withinloop += ((NI) 1); genlinedir_534823_839829468(p0, t0); oldbreakidx_548011_839829468 = (*p0).breakidx; memset((void*)LOC1, 0, sizeof(LOC1)); (*p0).breakidx = startblock_545978_839829468(p0, ((NimStringDesc*) &T839829468_569), LOC1, 0); (*p0).blocks->data[(*p0).breakidx].isloop = NIM_TRUE; initlocexpr_541283_839829468(p0, (*t0).kindU.S6.sons->data[((NI) 0)], (&a0)); { NIM_BOOL LOC4; Ropeobj180006* label0; TY534811 LOC8; LOC4 = (NIM_BOOL)0; LOC4 = !(((*(*t0).kindU.S6.sons->data[((NI) 0)]).kind == ((Tnodekind294020) 6))); if (LOC4) goto LA5; LOC4 = ((*(*t0).kindU.S6.sons->data[((NI) 0)]).kindU.S1.intval == IL64(0)); LA5: ; if (!LOC4) goto LA6; label0 = assignlabel_546020_839829468((&(*p0).blocks->data[(*p0).breakidx])); memset((void*)LOC8, 0, sizeof(LOC8)); LOC8[0] = rdloc_540188_839829468(a0); LOC8[1] = label0; linef_534700_839829468(p0, ((Tcprocsection531011) 2), ((NimStringDesc*) &T839829468_555), LOC8, 2); } LA6: ; loopbody0 = (*t0).kindU.S6.sons->data[((NI) 1)]; { NIM_BOOL LOC11; LOC11 = (NIM_BOOL)0; LOC11 = stmtscontainpragma_530083_2036603609(loopbody0, ((Tspecialword277003) 182)); if (!(LOC11)) goto LA12; LOC11 = ((Cc_275413_2528170400[(ccompiler_275431_2528170400)- 1].Field20 &(1U<<((NU)(((Tinfoccprop275004) 1))&7U)))!=0); LA12: ; if (!LOC11) goto LA13; { NIM_BOOL LOC17; NI LOC18; LOC17 = (NIM_BOOL)0; LOC18 = (NI)0; LOC18 = len_295081_850551059(loopbody0); LOC17 = (LOC18 == ((NI) 2)); if (!(LOC17)) goto LA19; LOC17 = ((*(*loopbody0).kindU.S6.sons->data[((NI) 0)]).kind == ((Tnodekind294020) 1)); LA19: ; if (!LOC17) goto LA20; loopbody0 = (*loopbody0).kindU.S6.sons->data[((NI) 1)]; } LA20: ; gencomputedgoto_547744_839829468(p0, loopbody0); } goto LA9; LA13: ; { genstmts_541244_839829468(p0, loopbody0); } LA9: ; { TY535289 LOC27; if (!(((*p0).options &(1U<<((NU)(((Toption171009) 19))&31U)))!=0)) goto LA25; memset((void*)LOC27, 0, sizeof(LOC27)); linefmt_534714_839829468(p0, ((Tcprocsection531011) 2), ((NimStringDesc*) &T839829468_581), LOC27, 0); } LA25: ; endblock_546060_839829468(p0); (*p0).breakidx = oldbreakidx_548011_839829468; (*p0).withinloop -= ((NI) 1); } N_NIMCALL(void, gengotovar_546258_839829468)(Tcproc531021* p0, Tnode294802* value0) { { if (!!(((*value0).kind >= ((Tnodekind294020) 5) && (*value0).kind <= ((Tnodekind294020) 15)))) goto LA3; localerror_198085_155036129((*value0).info, ((NimStringDesc*) &T839829468_582)); } goto LA1; LA3: ; { TY180507 LOC6; memset((void*)LOC6, 0, sizeof(LOC6)); LOC6[0] = rope_180401_2381377266((*value0).kindU.S1.intval); linef_534700_839829468(p0, ((Tcprocsection531011) 2), ((NimStringDesc*) &T839829468_583), LOC6, 1); } LA1: ; } N_NIMCALL(void, varindynamiclib_540812_839829468)(Tcgen531027* m0, Tsym294834* sym0) { Tlib294820* lib0; Ropeobj180006* extname0; Ropeobj180006* tmp0; TY537235 LOC1; NimStringDesc* LOC2; TY534811 LOC3; lib0 = (*sym0).annex; extname0 = (*sym0).loc.r; loaddynamiclib_561480_839829468(m0, lib0); (*sym0).loc.flags |= ((NU16)1)<<((((Tlocflag294810) 0))%(sizeof(NU16)*8)); tmp0 = mangledynlibproc_540816_839829468(sym0); asgnRefNoCycle((void**) (&(*sym0).loc.r), tmp0); (*m0).labels += ((NI) 2); memset((void*)LOC1, 0, sizeof(LOC1)); LOC1[0] = tmp0; LOC1[1] = gettypedesc_537671_839829468(m0, (*sym0).typ); LOC1[2] = (*lib0).name; LOC2 = (NimStringDesc*)0; LOC2 = HEX24_180856_2381377266(extname0); LOC1[3] = makecstring_193638_155036129(LOC2); appcg_534632_839829468(m0, &(*m0).s[(((Tcfilesection531005) 16))- 0], ((NimStringDesc*) &T839829468_584), LOC1, 4); memset((void*)LOC3, 0, sizeof(LOC3)); LOC3[0] = (*sym0).loc.r; LOC3[1] = gettypedesc_537671_839829468(m0, (*sym0).loc.t); addf_181205_2381377266(&(*m0).s[(((Tcfilesection531005) 9))- 0], ((NimStringDesc*) &T839829468_585), LOC3, 2); } N_NIMCALL(void, assignglobalvar_540819_839829468)(Tcproc531021* p0, Tsym294834* s0) { { { Ropeobj180006* LOC5; if (!((*s0).loc.k == ((Tlockind294808) 0))) goto LA3; LOC5 = (Ropeobj180006*)0; LOC5 = manglename_535205_839829468(s0); fillloc_534282_839829468((&(*s0).loc), ((Tlockind294808) 3), (*s0).typ, LOC5, ((Tstorageloc294812) 3)); } LA3: ; { Tcgen531027* q0; if (!(((*s0).loc.flags &(1U<<((NU)(((Tlocflag294810) 4))&15U)))!=0)) goto LA8; q0 = findpendingmodule_534241_839829468((*p0).module, s0); { NIM_BOOL LOC12; NIM_BOOL LOC14; LOC12 = (NIM_BOOL)0; LOC12 = !((q0 == NIM_NIL)); if (!(LOC12)) goto LA13; LOC14 = (NIM_BOOL)0; LOC14 = containsorincl_270862_2627731572((&(*q0).declaredthings), (*s0).Sup.id); LOC12 = !(LOC14); LA13: ; if (!LOC12) goto LA15; varindynamiclib_540812_839829468(q0, s0); } goto LA10; LA15: ; { asgnRefNoCycle((void**) (&(*s0).loc.r), mangledynlibproc_540816_839829468(s0)); } LA10: ; goto BeforeRet; } LA8: ; useheader_534369_839829468((*p0).module, s0); { if (!(((*s0).loc.flags &(1U<<((NU)(((Tlocflag294810) 3))&15U)))!=0)) goto LA20; goto BeforeRet; } LA20: ; { if (!(((*s0).flags &(1U<<((NU)(((Tsymflag294184) 22))&31U)))!=0)) goto LA24; declarethreadvar_540676_839829468((*p0).module, s0, (((*s0).flags &(1U<<((NU)(((Tsymflag294184) 5))&31U)))!=0)); } goto LA22; LA24: ; { Ropeobj180006* decl0; Ropeobj180006* td0; decl0 = NIM_NIL; td0 = gettypedesc_537671_839829468((*p0).module, (*s0).loc.t); { TY180507 LOC43; if (!(*s0).constraint == 0) goto LA29; { if (!(((*s0).flags &(1U<<((NU)(((Tsymflag294184) 5))&31U)))!=0)) goto LA33; add_180487_2381377266(&decl0, ((NimStringDesc*) &T839829468_240)); } LA33: ; add_180482_2381377266(&decl0, td0); { if (!(((*s0).flags &(1U<<((NU)(((Tsymflag294184) 8))&31U)))!=0)) goto LA37; add_180487_2381377266(&decl0, ((NimStringDesc*) &T839829468_121)); } LA37: ; { if (!(((*s0).flags &(1U<<((NU)(((Tsymflag294184) 7))&31U)))!=0)) goto LA41; add_180487_2381377266(&decl0, ((NimStringDesc*) &T839829468_122)); } LA41: ; memset((void*)LOC43, 0, sizeof(LOC43)); LOC43[0] = (*s0).loc.r; addf_181205_2381377266(&decl0, ((NimStringDesc*) &T839829468_242), LOC43, 1); } goto LA27; LA29: ; { NimStringDesc* LOC45; TY534811 LOC46; LOC45 = (NimStringDesc*)0; LOC45 = rawNewString((*(*s0).constraint).kindU.S3.strval->Sup.len + 3); appendString(LOC45, (*(*s0).constraint).kindU.S3.strval); appendString(LOC45, ((NimStringDesc*) &T839829468_497)); memset((void*)LOC46, 0, sizeof(LOC46)); LOC46[0] = td0; LOC46[1] = (*s0).loc.r; decl0 = HEX25_180905_2381377266(LOC45, LOC46, 2); } LA27: ; add_180482_2381377266(&(*(*p0).module).s[(((Tcfilesection531005) 9))- 0], decl0); } LA22: ; { if (!(((NI) 0) < (*p0).withinloop)) goto LA49; resetloc_540350_839829468(p0, (&(*s0).loc)); } LA49: ; { TY537238 LOC55; NimStringDesc* LOC56; NimStringDesc* LOC57; if (!(((*(*(*p0).module).module).options & 163840) == 163840)) goto LA53; memset((void*)LOC55, 0, sizeof(LOC55)); LOC56 = (NimStringDesc*)0; LOC56 = rawNewString((*(*(*s0).owner).name).s->Sup.len + (*(*s0).name).s->Sup.len + 1); appendString(LOC56, (*(*(*s0).owner).name).s); appendChar(LOC56, 46); appendString(LOC56, (*(*s0).name).s); LOC57 = (NimStringDesc*)0; LOC57 = nsuNormalize(LOC56); LOC55[0] = makecstring_193638_155036129(LOC57); LOC55[1] = (*s0).loc.r; LOC55[2] = gentypeinfo_537941_839829468((*p0).module, (*s0).typ); appcg_534632_839829468((*p0).module, &(*(*p0).module).s[(((Tcfilesection531005) 15))- 0], ((NimStringDesc*) &T839829468_586), LOC55, 3); } LA53: ; }BeforeRet: ; } N_NIMCALL(Ropeobj180006*, gentraverseprocforglobal_540032_839829468)(Tcgen531027* m0, Tsym294834* s0) { Ropeobj180006* result0; Ropeobj180006* LOC1; Ttraversalclosure539019 c0; Tcproc531021* p0; Ropeobj180006* sloc0; Ropeobj180006* header0; TY180507 LOC8; Ropeobj180006* generatedproc0; TY537235 LOC9; Ropeobj180006** LOC10; Ropeobj180006** LOC11; Ropeobj180006** LOC12; TY180507 LOC13; result0 = (Ropeobj180006*)0; LOC1 = (Ropeobj180006*)0; LOC1 = gentypeinfo_537941_839829468(m0, (*s0).loc.t); memset((void*)(&c0), 0, sizeof(c0)); p0 = newproc_531206_3723162438(NIM_NIL, m0); sloc0 = (*s0).loc.r; result0 = gettempname_535596_839829468(m0); { NIM_BOOL LOC4; LOC4 = (NIM_BOOL)0; LOC4 = (((*s0).flags &(1U<<((NU)(((Tsymflag294184) 22))&31U)))!=0); if (!(LOC4)) goto LA5; LOC4 = emulatedthreadvars_534949_839829468(); LA5: ; if (!LOC4) goto LA6; accessthreadlocalvar_534945_839829468(p0, s0); sloc0 = HEX26_180452_2381377266(((NimStringDesc*) &T839829468_288), sloc0); } LA6: ; c0.visitorfrmt = copyString(((NimStringDesc*) &T839829468_587)); c0.p = p0; memset((void*)LOC8, 0, sizeof(LOC8)); LOC8[0] = result0; header0 = HEX25_180905_2381377266(((NimStringDesc*) &T839829468_588), LOC8, 1); gentraverseproc_539022_839829468((&c0), sloc0, (*s0).loc.t); memset((void*)LOC9, 0, sizeof(LOC9)); LOC9[0] = header0; LOC10 = (Ropeobj180006**)0; LOC10 = s_531179_3723162438(p0, ((Tcprocsection531011) 0)); LOC9[1] = (*LOC10); LOC11 = (Ropeobj180006**)0; LOC11 = s_531179_3723162438(p0, ((Tcprocsection531011) 1)); LOC9[2] = (*LOC11); LOC12 = (Ropeobj180006**)0; LOC12 = s_531179_3723162438(p0, ((Tcprocsection531011) 2)); LOC9[3] = (*LOC12); generatedproc0 = HEX25_180905_2381377266(((NimStringDesc*) &T839829468_190), LOC9, 4); memset((void*)LOC13, 0, sizeof(LOC13)); LOC13[0] = header0; addf_181205_2381377266(&(*m0).s[(((Tcfilesection531005) 7))- 0], ((NimStringDesc*) &T839829468_191), LOC13, 1); add_180482_2381377266(&(*m0).s[(((Tcfilesection531005) 10))- 0], generatedproc0); return result0; } N_NIMCALL(void, registergcroot_545762_839829468)(Tcproc531021* p0, Tsym294834* v0) { { NIM_BOOL LOC3; Ropeobj180006* prc0; Ropeobj180006** LOC7; TY180507 LOC8; LOC3 = (NIM_BOOL)0; LOC3 = ((240 &(1U<<((NU)(gselectedgc_171133_2607990831)&7U)))!=0); if (!(LOC3)) goto LA4; LOC3 = containsgarbagecollectedref_322117_3876443242((*v0).loc.t); LA4: ; if (!LOC3) goto LA5; prc0 = gentraverseprocforglobal_540032_839829468((*p0).module, v0); LOC7 = (Ropeobj180006**)0; LOC7 = procsec_531194_3723162438((*(*p0).module).initproc, ((Tcprocsection531011) 1)); memset((void*)LOC8, 0, sizeof(LOC8)); LOC8[0] = prc0; appcg_534632_839829468((*p0).module, LOC7, ((NimStringDesc*) &T839829468_589), LOC8, 1); } LA5: ; } static N_INLINE(NIM_BOOL, isassignedimmediately_545781_839829468)(Tnode294802* n0) { NIM_BOOL result0; { result0 = (NIM_BOOL)0; { if (!((*n0).kind == ((Tnodekind294020) 1))) goto LA3; result0 = NIM_FALSE; goto BeforeRet; } LA3: ; { NIM_BOOL LOC7; LOC7 = (NIM_BOOL)0; LOC7 = isinvalidreturntype_535548_839829468((*n0).typ); if (!LOC7) goto LA8; result0 = NIM_FALSE; goto BeforeRet; } LA8: ; result0 = NIM_TRUE; }BeforeRet: ; return result0; } N_NIMCALL(void, genasgncall_545695_839829468)(Tcproc531021* p0, Tnode294802* le0, Tnode294802* ri0, Tloc294816* d0) { { Ttype294840* LOC3; LOC3 = (Ttype294840*)0; LOC3 = skiptypes_298099_850551059((*(*ri0).kindU.S6.sons->data[((NI) 0)]).typ, 2048); if (!((*LOC3).callconv == ((Tcallingconvention294002) 8))) goto LA4; genclosurecall_542452_839829468(p0, le0, ri0, d0); } goto LA1; LA4: ; { NIM_BOOL LOC7; LOC7 = (NIM_BOOL)0; LOC7 = ((*(*ri0).kindU.S6.sons->data[((NI) 0)]).kind == ((Tnodekind294020) 3)); if (!(LOC7)) goto LA8; LOC7 = (((*(*(*ri0).kindU.S6.sons->data[((NI) 0)]).kindU.S4.sym).flags &(1U<<((NU)(((Tsymflag294184) 27))&31U)))!=0); LA8: ; if (!LOC7) goto LA9; geninfixcall_543929_839829468(p0, le0, ri0, d0); } goto LA1; LA9: ; { NIM_BOOL LOC12; LOC12 = (NIM_BOOL)0; LOC12 = ((*(*ri0).kindU.S6.sons->data[((NI) 0)]).kind == ((Tnodekind294020) 3)); if (!(LOC12)) goto LA13; LOC12 = (((*(*(*ri0).kindU.S6.sons->data[((NI) 0)]).kindU.S4.sym).flags &(1U<<((NU)(((Tsymflag294184) 28))&31U)))!=0); LA13: ; if (!LOC12) goto LA14; gennamedparamcall_544616_839829468(p0, ri0, d0); } goto LA1; LA14: ; { genprefixcall_541960_839829468(p0, le0, ri0, d0); } LA1: ; poststmtactions_534942_839829468(p0); } static N_INLINE(void, loadinto_545928_839829468)(Tcproc531021* p0, Tnode294802* le0, Tnode294802* ri0, Tloc294816* a0) { { NIM_BOOL LOC3; NIM_BOOL LOC5; LOC3 = (NIM_BOOL)0; LOC3 = ((*ri0).kind == ((Tnodekind294020) 27) || (*ri0).kind == ((Tnodekind294020) 29) || (*ri0).kind == ((Tnodekind294020) 30) || (*ri0).kind == ((Tnodekind294020) 31) || (*ri0).kind == ((Tnodekind294020) 26) || (*ri0).kind == ((Tnodekind294020) 28) || (*ri0).kind == ((Tnodekind294020) 32)); if (!(LOC3)) goto LA4; LOC5 = (NIM_BOOL)0; LOC5 = !(((*(*ri0).kindU.S6.sons->data[((NI) 0)]).kind == ((Tnodekind294020) 3))); if (LOC5) goto LA6; LOC5 = ((*(*(*ri0).kindU.S6.sons->data[((NI) 0)]).kindU.S4.sym).magic == ((Tmagic294524) 0)); LA6: ; LOC3 = LOC5; LA4: ; if (!LOC3) goto LA7; genasgncall_545695_839829468(p0, le0, ri0, a0); } goto LA1; LA7: ; { if (!((*ri0).kind == ((Tnodekind294020) 47) || (*ri0).kind == ((Tnodekind294020) 65))) goto LA10; genderef_545921_839829468(p0, ri0, a0, NIM_TRUE); } goto LA1; LA10: ; { expr_541248_839829468(p0, ri0, a0); } LA1: ; } N_NIMCALL(void, gensinglevar_546276_839829468)(Tcproc531021* p0, Tnode294802* a0) { Tsym294834* v0; Tcproc531021* targetproc0; { v0 = (*(*a0).kindU.S6.sons->data[((NI) 0)]).kindU.S4.sym; { if (!!(((1082130432 & (*v0).flags) == 0))) goto LA3; { if (!(((*v0).flags &(1U<<((NU)(((Tsymflag294184) 30))&31U)))!=0)) goto LA7; gengotovar_546258_839829468(p0, (*a0).kindU.S6.sons->data[((NI) 2)]); } LA7: ; goto BeforeRet; } LA3: ; targetproc0 = p0; { if (!(((*v0).flags &(1U<<((NU)(((Tsymflag294184) 3))&31U)))!=0)) goto LA11; { NIM_BOOL LOC15; NIM_BOOL LOC16; LOC15 = (NIM_BOOL)0; LOC16 = (NIM_BOOL)0; LOC16 = (((*v0).flags & 96) == 32); if (!(LOC16)) goto LA17; LOC16 = ((*(*a0).kindU.S6.sons->data[((NI) 2)]).kind == ((Tnodekind294020) 1)); LA17: ; LOC15 = LOC16; if (!(LOC15)) goto LA18; LOC15 = !((((*v0).loc.flags & 72) == 0)); LA18: ; if (!LOC15) goto LA19; goto BeforeRet; } LA19: ; { if (!(((*v0).flags &(1U<<((NU)(((Tsymflag294184) 9))&31U)))!=0)) goto LA23; targetproc0 = (*(*p0).module).preinitproc; } LA23: ; assignglobalvar_540819_839829468(targetproc0, v0); genobjectinit_540242_839829468((*(*p0).module).preinitproc, ((Tcprocsection531011) 1), (*v0).typ, (*v0).loc, NIM_TRUE); { NIM_BOOL LOC27; LOC27 = (NIM_BOOL)0; LOC27 = (((*v0).flags &(1U<<((NU)(((Tsymflag294184) 6))&31U)))!=0); if (!(LOC27)) goto LA28; LOC27 = !((generatedheader_534201_839829468 == NIM_NIL)); LA28: ; if (!LOC27) goto LA29; genvarprototypeaux_546254_839829468(generatedheader_534201_839829468, v0); } LA29: ; registergcroot_545762_839829468(p0, v0); } goto LA9; LA11: ; { Tnode294802* value0; NIM_BOOL imm0; value0 = (*a0).kindU.S6.sons->data[((NI) 2)]; imm0 = isassignedimmediately_545781_839829468(value0); { NIM_BOOL LOC34; NIM_BOOL LOC35; NIM_BOOL LOC36; NIM_BOOL LOC38; NIM_BOOL LOC42; Ropeobj180006* decl0; Tloc294816 tmp0; LOC34 = (NIM_BOOL)0; LOC35 = (NIM_BOOL)0; LOC36 = (NIM_BOOL)0; LOC36 = imm0; if (!(LOC36)) goto LA37; LOC38 = (NIM_BOOL)0; LOC38 = (gcmd_171132_2607990831 == ((Tcommands171076) 2)); if (LOC38) goto LA39; LOC38 = (((*(*(*p0).module).module).flags &(1U<<((NU)(((Tsymflag294184) 27))&31U)))!=0); LA39: ; LOC36 = LOC38; LA37: ; LOC35 = LOC36; if (!(LOC35)) goto LA40; LOC35 = ((*p0).splitdecls == ((NI) 0)); LA40: ; LOC34 = LOC35; if (!(LOC34)) goto LA41; LOC42 = (NIM_BOOL)0; LOC42 = containshiddenpointer_322120_3876443242((*v0).typ); LOC34 = !(LOC42); LA41: ; if (!LOC34) goto LA43; genlinedir_534823_839829468(p0, a0); decl0 = localvardecl_540532_839829468(p0, v0); memset((void*)(&tmp0), 0, sizeof(tmp0)); { NIM_BOOL LOC47; NIM_BOOL LOC48; Tnode294802* LOC50; Tnode294802* LOC52; Ropeobj180006* params0; Ttype294840* typ0; TY534811 LOC66; LOC47 = (NIM_BOOL)0; LOC48 = (NIM_BOOL)0; LOC48 = ((*value0).kind == ((Tnodekind294020) 27) || (*value0).kind == ((Tnodekind294020) 29) || (*value0).kind == ((Tnodekind294020) 30) || (*value0).kind == ((Tnodekind294020) 31) || (*value0).kind == ((Tnodekind294020) 26) || (*value0).kind == ((Tnodekind294020) 28) || (*value0).kind == ((Tnodekind294020) 32)); if (!(LOC48)) goto LA49; LOC50 = (Tnode294802*)0; LOC50 = HEX5BHEX5D_295238_850551059(value0, ((NI) 0)); LOC48 = ((*LOC50).kind == ((Tnodekind294020) 3)); LA49: ; LOC47 = LOC48; if (!(LOC47)) goto LA51; LOC52 = (Tnode294802*)0; LOC52 = HEX5BHEX5D_295238_850551059(value0, ((NI) 0)); LOC47 = (((*(*LOC52).kindU.S4.sym).flags &(1U<<((NU)(((Tsymflag294184) 24))&31U)))!=0); LA51: ; if (!LOC47) goto LA53; params0 = (Ropeobj180006*)0; typ0 = skiptypes_298099_850551059((*(*value0).kindU.S6.sons->data[((NI) 0)]).typ, IL64(211106232576256)); { NI i_546619_839829468; NI HEX3Atmp_546825_839829468; NI LOC56; NI res_546828_839829468; i_546619_839829468 = (NI)0; HEX3Atmp_546825_839829468 = (NI)0; LOC56 = (NI)0; LOC56 = len_295081_850551059(value0); HEX3Atmp_546825_839829468 = (LOC56 - 1); res_546828_839829468 = ((NI) 1); { while (1) { Ropeobj180006* LOC65; if (!(res_546828_839829468 <= HEX3Atmp_546825_839829468)) goto LA58; i_546619_839829468 = res_546828_839829468; { TY535289 LOC63; Ropeobj180006* LOC64; if (!!((params0 == NIM_NIL))) goto LA61; memset((void*)LOC63, 0, sizeof(LOC63)); LOC64 = (Ropeobj180006*)0; LOC64 = HEX25_180905_2381377266(((NimStringDesc*) &T839829468_110), LOC63, 0); add_180482_2381377266(&params0, LOC64); } LA61: ; LOC65 = (Ropeobj180006*)0; LOC65 = genotherarg_541277_839829468(p0, value0, i_546619_839829468, typ0); add_180482_2381377266(&params0, LOC65); res_546828_839829468 += ((NI) 1); } LA58: ; } } memset((void*)LOC66, 0, sizeof(LOC66)); LOC66[0] = decl0; LOC66[1] = params0; linef_534700_839829468(p0, ((Tcprocsection531011) 2), ((NimStringDesc*) &T839829468_590), LOC66, 2); } goto LA45; LA53: ; { TY534811 LOC68; initlocexprsingleuse_541289_839829468(p0, value0, (&tmp0)); memset((void*)LOC68, 0, sizeof(LOC68)); LOC68[0] = decl0; LOC68[1] = rdloc_540188_839829468(tmp0); linef_534700_839829468(p0, ((Tcprocsection531011) 2), ((NimStringDesc*) &T839829468_591), LOC68, 2); } LA45: ; goto BeforeRet; } LA43: ; assignlocalvar_540614_839829468(p0, v0); initlocalvar_540398_839829468(p0, v0, imm0); } LA9: ; { if (!!(((*(*a0).kindU.S6.sons->data[((NI) 2)]).kind == ((Tnodekind294020) 1)))) goto LA71; genlinedir_534823_839829468(targetproc0, a0); loadinto_545928_839829468(targetproc0, (*a0).kindU.S6.sons->data[((NI) 0)], (*a0).kindU.S6.sons->data[((NI) 2)], (&(*v0).loc)); } LA71: ; }BeforeRet: ; } N_NIMCALL(void, genclosurevar_546832_839829468)(Tcproc531021* p0, Tnode294802* a0) { NIM_BOOL immediateasgn0; immediateasgn0 = !(((*(*a0).kindU.S6.sons->data[((NI) 2)]).kind == ((Tnodekind294020) 1))); { Tloc294816 v0; if (!immediateasgn0) goto LA3; memset((void*)(&v0), 0, sizeof(v0)); initlocexpr_541283_839829468(p0, (*a0).kindU.S6.sons->data[((NI) 0)], (&v0)); genlinedir_534823_839829468(p0, a0); loadinto_545928_839829468(p0, (*a0).kindU.S6.sons->data[((NI) 0)], (*a0).kindU.S6.sons->data[((NI) 2)], (&v0)); } LA3: ; } N_NIMCALL(void, genvartuple_545794_839829468)(Tcproc531021* p0, Tnode294802* n0) { Tloc294816 tup0; Tloc294816 field0; NI L0; NIM_BOOL uselowering0; Ttype294840* t0; { memset((void*)(&tup0), 0, sizeof(tup0)); memset((void*)(&field0), 0, sizeof(field0)); { if (!!(((*n0).kind == ((Tnodekind294020) 36)))) goto LA3; internalerror_198100_155036129((*n0).info, ((NimStringDesc*) &T839829468_592)); } LA3: ; L0 = sonslen_297351_850551059(n0); uselowering0 = NIM_FALSE; { NI i_545822_839829468; NI HEX3Atmp_545905_839829468; NI res_545908_839829468; i_545822_839829468 = (NI)0; HEX3Atmp_545905_839829468 = (NI)0; HEX3Atmp_545905_839829468 = (NI)(L0 - ((NI) 3)); res_545908_839829468 = ((NI) 0); { while (1) { if (!(res_545908_839829468 <= HEX3Atmp_545905_839829468)) goto LA7; i_545822_839829468 = res_545908_839829468; { Tnode294802* LOC10; LOC10 = (Tnode294802*)0; LOC10 = HEX5BHEX5D_295238_850551059(n0, i_545822_839829468); if (!!(((*LOC10).kind == ((Tnodekind294020) 3)))) goto LA11; uselowering0 = NIM_TRUE; goto LA5; } LA11: ; res_545908_839829468 += ((NI) 1); } LA7: ; } } LA5: ; { Tnode294802* LOC17; if (!uselowering0) goto LA15; LOC17 = (Tnode294802*)0; LOC17 = lowertupleunpacking_435037_2218250499(n0, (*p0).prc); genstmts_541244_839829468(p0, LOC17); goto BeforeRet; } LA15: ; genlinedir_534823_839829468(p0, n0); initlocexpr_541283_839829468(p0, (*n0).kindU.S6.sons->data[(NI)(L0 - ((NI) 1))], (&tup0)); t0 = getuniquetype_530640_2036603609(tup0.t); { NI i_545846_839829468; NI HEX3Atmp_545914_839829468; NI res_545917_839829468; i_545846_839829468 = (NI)0; HEX3Atmp_545914_839829468 = (NI)0; HEX3Atmp_545914_839829468 = (NI)(L0 - ((NI) 3)); res_545917_839829468 = ((NI) 0); { while (1) { if (!(res_545917_839829468 <= HEX3Atmp_545914_839829468)) goto LA20; i_545846_839829468 = res_545917_839829468; { Tsym294834* v0; v0 = (*(*n0).kindU.S6.sons->data[i_545846_839829468]).kindU.S4.sym; { if (!(((*v0).flags &(1U<<((NU)(((Tsymflag294184) 23))&31U)))!=0)) goto LA24; goto LA21; } LA24: ; { if (!(((*v0).flags &(1U<<((NU)(((Tsymflag294184) 3))&31U)))!=0)) goto LA28; assignglobalvar_540819_839829468(p0, v0); genobjectinit_540242_839829468(p0, ((Tcprocsection531011) 1), (*v0).typ, (*v0).loc, NIM_TRUE); registergcroot_545762_839829468(p0, v0); } goto LA26; LA28: ; { Tnode294802* LOC31; NIM_BOOL LOC32; assignlocalvar_540614_839829468(p0, v0); LOC31 = (Tnode294802*)0; LOC31 = HEX5BHEX5D_295238_850551059(n0, (NI)(L0 - ((NI) 1))); LOC32 = (NIM_BOOL)0; LOC32 = isassignedimmediately_545781_839829468(LOC31); initlocalvar_540398_839829468(p0, v0, LOC32); } LA26: ; initloc_534273_839829468((&field0), ((Tlockind294808) 6), (*t0).sons->data[i_545846_839829468], tup0.s); { TY534811 LOC37; if (!((*t0).kind == ((Ttypekind294244) 18))) goto LA35; memset((void*)LOC37, 0, sizeof(LOC37)); LOC37[0] = rdloc_540188_839829468(tup0); LOC37[1] = rope_180401_2381377266(((NI64) (i_545846_839829468))); field0.r = HEX25_180905_2381377266(((NimStringDesc*) &T839829468_185), LOC37, 2); } goto LA33; LA35: ; { TY534811 LOC43; { if (!!(((*(*(*t0).n).kindU.S6.sons->data[i_545846_839829468]).kind == ((Tnodekind294020) 3)))) goto LA41; internalerror_198100_155036129((*n0).info, ((NimStringDesc*) &T839829468_592)); } LA41: ; memset((void*)LOC43, 0, sizeof(LOC43)); LOC43[0] = rdloc_540188_839829468(tup0); LOC43[1] = manglerecfieldname_536361_839829468((*(*(*t0).n).kindU.S6.sons->data[i_545846_839829468]).kindU.S4.sym, t0); field0.r = HEX25_180905_2381377266(((NimStringDesc*) &T839829468_90), LOC43, 2); } LA33: ; putlocintodest_541258_839829468(p0, (&(*v0).loc), field0); } LA21: ; res_545917_839829468 += ((NI) 1); } LA20: ; } } }BeforeRet: ; } N_NIMCALL(void, genvarstmt_546854_839829468)(Tcproc531021* p0, Tnode294802* n0) { { NI i_546869_839829468; NI HEX3Atmp_546902_839829468; NI LOC2; NI res_546905_839829468; i_546869_839829468 = (NI)0; HEX3Atmp_546902_839829468 = (NI)0; LOC2 = (NI)0; LOC2 = sonslen_297351_850551059(n0); HEX3Atmp_546902_839829468 = (NI)(LOC2 - ((NI) 1)); res_546905_839829468 = ((NI) 0); { while (1) { if (!(res_546905_839829468 <= HEX3Atmp_546902_839829468)) goto LA4; i_546869_839829468 = res_546905_839829468; { Tnode294802* a0; a0 = (*n0).kindU.S6.sons->data[i_546869_839829468]; { if (!((*a0).kind == ((Tnodekind294020) 125))) goto LA8; goto LA5; } LA8: ; { if (!((*a0).kind == ((Tnodekind294020) 35))) goto LA12; { if (!((*(*a0).kindU.S6.sons->data[((NI) 0)]).kind == ((Tnodekind294020) 3))) goto LA16; gensinglevar_546276_839829468(p0, a0); } goto LA14; LA16: ; { genclosurevar_546832_839829468(p0, a0); } LA14: ; } goto LA10; LA12: ; { genvartuple_545794_839829468(p0, a0); } LA10: ; } LA5: ; res_546905_839829468 += ((NI) 1); } LA4: ; } } } static N_INLINE(NIM_BOOL, emitlazily_534248_839829468)(Tsym294834* s0) { NIM_BOOL result0; NIM_BOOL LOC1; Tsym294834* LOC3; result0 = (NIM_BOOL)0; LOC1 = (NIM_BOOL)0; LOC1 = ((gglobaloptions_171130_2607990831 &((NU64)1<<((NU)(((Tglobaloption171013) 2))&63U)))!=0); if (LOC1) goto LA2; LOC3 = (Tsym294834*)0; LOC3 = getmodule_301123_2984716966(s0); LOC1 = (((*LOC3).flags &(1U<<((NU)(((Tsymflag294184) 25))&31U)))!=0); LA2: ; result0 = LOC1; return result0; } N_NIMCALL(void, genconststmt_546909_839829468)(Tcproc531021* p0, Tnode294802* t0) { { NI i_546924_839829468; NI HEX3Atmp_546975_839829468; NI LOC2; NI res_546978_839829468; i_546924_839829468 = (NI)0; HEX3Atmp_546975_839829468 = (NI)0; LOC2 = (NI)0; LOC2 = sonslen_297351_850551059(t0); HEX3Atmp_546975_839829468 = (NI)(LOC2 - ((NI) 1)); res_546978_839829468 = ((NI) 0); { while (1) { if (!(res_546978_839829468 <= HEX3Atmp_546975_839829468)) goto LA4; i_546924_839829468 = res_546978_839829468; { Tnode294802* it0; Tsym294834* c0; it0 = (*t0).kindU.S6.sons->data[i_546924_839829468]; { if (!((*it0).kind == ((Tnodekind294020) 125))) goto LA8; goto LA5; } LA8: ; { if (!!(((*it0).kind == ((Tnodekind294020) 102)))) goto LA12; internalerror_198100_155036129((*t0).info, ((NimStringDesc*) &T839829468_593)); } LA12: ; c0 = (*(*it0).kindU.S6.sons->data[((NI) 0)]).kindU.S4.sym; { NIM_BOOL LOC16; LOC16 = (NIM_BOOL)0; LOC16 = containscompiletimeonly_330721_3876443242((*c0).typ); if (!LOC16) goto LA17; goto LA5; } goto LA14; LA17: ; { NIM_BOOL LOC20; NIM_BOOL LOC21; NI LOC24; LOC20 = (NIM_BOOL)0; LOC21 = (NIM_BOOL)0; LOC21 = ((*(*c0).typ).kind == ((Ttypekind294244) 4) || (*(*c0).typ).kind == ((Ttypekind294244) 16) || (*(*c0).typ).kind == ((Ttypekind294244) 19) || (*(*c0).typ).kind == ((Ttypekind294244) 18) || (*(*c0).typ).kind == ((Ttypekind294244) 24)); if (!(LOC21)) goto LA22; LOC21 = !((((*c0).loc.flags &(1U<<((NU)(((Tlocflag294810) 3))&15U)))!=0)); LA22: ; LOC20 = LOC21; if (!(LOC20)) goto LA23; LOC24 = (NI)0; LOC24 = len_295081_850551059((*c0).ast); LOC20 = !((LOC24 == ((NI) 0))); LA23: ; if (!LOC20) goto LA25; { NIM_BOOL LOC29; LOC29 = (NIM_BOOL)0; LOC29 = emitlazily_534248_839829468(c0); if (!!(LOC29)) goto LA30; requestconstimpl_541240_839829468(p0, c0); } LA30: ; } goto LA14; LA25: ; LA14: ; } LA5: ; res_546978_839829468 += ((NI) 1); } LA4: ; } } } N_NIMCALL(void, gencasestringbranch_549100_839829468)(Tcproc531021* p0, Tnode294802* b0, Tloc294816 e0, Ropeobj180006* labl0, Ropeobj180006** branches0, NI branches0Len0) { Tloc294816 x0; NI length0; memset((void*)(&x0), 0, sizeof(x0)); length0 = sonslen_297351_850551059(b0); { NI i_549122_839829468; NI HEX3Atmp_549409_839829468; NI res_549412_839829468; i_549122_839829468 = (NI)0; HEX3Atmp_549409_839829468 = (NI)0; HEX3Atmp_549409_839829468 = (NI)(length0 - ((NI) 2)); res_549412_839829468 = ((NI) 0); { while (1) { NI j0; NI64 LOC4; TY537238 LOC5; if (!(res_549412_839829468 <= HEX3Atmp_549409_839829468)) goto LA3; i_549122_839829468 = res_549412_839829468; initlocexpr_541283_839829468(p0, (*b0).kindU.S6.sons->data[i_549122_839829468], (&x0)); LOC4 = (NI64)0; LOC4 = hashstring_530100_2036603609((*(*b0).kindU.S6.sons->data[i_549122_839829468]).kindU.S3.strval); j0 = ((NI) ((NI64)(LOC4 & ((NI64) ((branches0Len0-1)))))); memset((void*)LOC5, 0, sizeof(LOC5)); LOC5[0] = rdloc_540188_839829468(e0); LOC5[1] = rdloc_540188_839829468(x0); LOC5[2] = labl0; appcg_534632_839829468((*p0).module, &branches0[j0], ((NimStringDesc*) &T839829468_595), LOC5, 3); res_549412_839829468 += ((NI) 1); } LA3: ; } } } N_NIMCALL(void, exprblock_546103_839829468)(Tcproc531021* p0, Tnode294802* n0, Tloc294816* d0) { TY535289 LOC1; NI LOC2; memset((void*)LOC1, 0, sizeof(LOC1)); LOC2 = (NI)0; LOC2 = startblock_545978_839829468(p0, ((NimStringDesc*) &T839829468_273), LOC1, 0); expr_541248_839829468(p0, n0, d0); endblock_546060_839829468(p0); } N_NIMCALL(Ropeobj180006*, gencasesecondpass_548965_839829468)(Tcproc531021* p0, Tnode294802* t0, Tloc294816* d0, NI labid0, NI until0) { Ropeobj180006* result0; Ropeobj180006* lend0; result0 = (Ropeobj180006*)0; lend0 = getlabel_541217_839829468(p0); { NI i_548984_839829468; NI res_549017_839829468; i_548984_839829468 = (NI)0; res_549017_839829468 = ((NI) 1); { while (1) { TY180507 LOC10; if (!(res_549017_839829468 <= until0)) goto LA3; i_548984_839829468 = res_549017_839829468; { NIM_BOOL LOC6; LOC6 = (NIM_BOOL)0; LOC6 = ((*d0).k == ((Tlockind294808) 1)); if (!(LOC6)) goto LA7; LOC6 = isemptytype_299440_850551059((*t0).typ); LA7: ; if (!LOC6) goto LA8; (*d0).k = ((Tlockind294808) 0); } LA8: ; memset((void*)LOC10, 0, sizeof(LOC10)); LOC10[0] = rope_180401_2381377266(((NI64) ((NI)(labid0 + i_548984_839829468)))); linef_534700_839829468(p0, ((Tcprocsection531011) 2), ((NimStringDesc*) &T839829468_599), LOC10, 1); { NI length0; TY180507 LOC15; if (!((*(*t0).kindU.S6.sons->data[i_548984_839829468]).kind == ((Tnodekind294020) 85))) goto LA13; length0 = sonslen_297351_850551059((*t0).kindU.S6.sons->data[i_548984_839829468]); exprblock_546103_839829468(p0, (*(*t0).kindU.S6.sons->data[i_548984_839829468]).kindU.S6.sons->data[(NI)(length0 - ((NI) 1))], d0); memset((void*)LOC15, 0, sizeof(LOC15)); LOC15[0] = lend0; linef_534700_839829468(p0, ((Tcprocsection531011) 2), ((NimStringDesc*) &T839829468_556), LOC15, 1); } goto LA11; LA13: ; { exprblock_546103_839829468(p0, (*(*t0).kindU.S6.sons->data[i_548984_839829468]).kindU.S6.sons->data[((NI) 0)], d0); } LA11: ; res_549017_839829468 += ((NI) 1); } LA3: ; } } result0 = lend0; return result0; } N_NIMCALL(void, gencasegenericbranch_548910_839829468)(Tcproc531021* p0, Tnode294802* b0, Tloc294816 e0, NimStringDesc* rangeformat0, NimStringDesc* eqformat0, Ropeobj180006* labl0) { Tloc294816 x0; Tloc294816 y0; NI length0; memset((void*)(&x0), 0, sizeof(x0)); memset((void*)(&y0), 0, sizeof(y0)); length0 = sonslen_297351_850551059(b0); { NI i_548932_839829468; NI HEX3Atmp_548958_839829468; NI res_548961_839829468; i_548932_839829468 = (NI)0; HEX3Atmp_548958_839829468 = (NI)0; HEX3Atmp_548958_839829468 = (NI)(length0 - ((NI) 2)); res_548961_839829468 = ((NI) 0); { while (1) { if (!(res_548961_839829468 <= HEX3Atmp_548958_839829468)) goto LA3; i_548932_839829468 = res_548961_839829468; { TY537235 LOC8; if (!((*(*b0).kindU.S6.sons->data[i_548932_839829468]).kind == ((Tnodekind294020) 44))) goto LA6; initlocexpr_541283_839829468(p0, (*(*b0).kindU.S6.sons->data[i_548932_839829468]).kindU.S6.sons->data[((NI) 0)], (&x0)); initlocexpr_541283_839829468(p0, (*(*b0).kindU.S6.sons->data[i_548932_839829468]).kindU.S6.sons->data[((NI) 1)], (&y0)); memset((void*)LOC8, 0, sizeof(LOC8)); LOC8[0] = rdcharloc_540227_839829468(e0); LOC8[1] = rdcharloc_540227_839829468(x0); LOC8[2] = rdcharloc_540227_839829468(y0); LOC8[3] = labl0; linecg_534707_839829468(p0, ((Tcprocsection531011) 2), rangeformat0, LOC8, 4); } goto LA4; LA6: ; { TY537238 LOC10; initlocexpr_541283_839829468(p0, (*b0).kindU.S6.sons->data[i_548932_839829468], (&x0)); memset((void*)LOC10, 0, sizeof(LOC10)); LOC10[0] = rdcharloc_540227_839829468(e0); LOC10[1] = rdcharloc_540227_839829468(x0); LOC10[2] = labl0; linecg_534707_839829468(p0, ((Tcprocsection531011) 2), eqformat0, LOC10, 3); } LA4: ; res_548961_839829468 += ((NI) 1); } LA3: ; } } } N_NIMCALL(Ropeobj180006*, genifforcaseuntil_549021_839829468)(Tcproc531021* p0, Tnode294802* t0, Tloc294816* d0, NimStringDesc* rangeformat0, NimStringDesc* eqformat0, NI until0, Tloc294816 a0) { Ropeobj180006* result0; NI labid0; result0 = (Ropeobj180006*)0; labid0 = (*p0).labels; { NI i_549042_839829468; NI res_549083_839829468; i_549042_839829468 = (NI)0; res_549083_839829468 = ((NI) 1); { while (1) { if (!(res_549083_839829468 <= until0)) goto LA3; i_549042_839829468 = res_549083_839829468; (*p0).labels += ((NI) 1); { Ropeobj180006* LOC8; Ropeobj180006* LOC9; if (!((*(*t0).kindU.S6.sons->data[i_549042_839829468]).kind == ((Tnodekind294020) 85))) goto LA6; LOC8 = (Ropeobj180006*)0; LOC8 = rope_180401_2381377266(((NI64) ((*p0).labels))); LOC9 = (Ropeobj180006*)0; LOC9 = HEX26_180452_2381377266(((NimStringDesc*) &T839829468_296), LOC8); gencasegenericbranch_548910_839829468(p0, (*t0).kindU.S6.sons->data[i_549042_839829468], a0, rangeformat0, eqformat0, LOC9); } goto LA4; LA6: ; { TY180507 LOC11; memset((void*)LOC11, 0, sizeof(LOC11)); LOC11[0] = rope_180401_2381377266(((NI64) ((*p0).labels))); linef_534700_839829468(p0, ((Tcprocsection531011) 2), ((NimStringDesc*) &T839829468_598), LOC11, 1); } LA4: ; res_549083_839829468 += ((NI) 1); } LA3: ; } } { NI LOC14; NI gototarget0; TY180507 LOC17; TY180507 LOC18; LOC14 = (NI)0; LOC14 = len_295081_850551059(t0); if (!(until0 < (NI)(LOC14 - ((NI) 1)))) goto LA15; (*p0).labels += ((NI) 1); gototarget0 = (*p0).labels; memset((void*)LOC17, 0, sizeof(LOC17)); LOC17[0] = rope_180401_2381377266(((NI64) (gototarget0))); linef_534700_839829468(p0, ((Tcprocsection531011) 2), ((NimStringDesc*) &T839829468_598), LOC17, 1); result0 = gencasesecondpass_548965_839829468(p0, t0, d0, ((NI) (labid0)), until0); memset((void*)LOC18, 0, sizeof(LOC18)); LOC18[0] = rope_180401_2381377266(((NI64) (gototarget0))); linef_534700_839829468(p0, ((Tcprocsection531011) 2), ((NimStringDesc*) &T839829468_599), LOC18, 1); } goto LA12; LA15: ; { result0 = gencasesecondpass_548965_839829468(p0, t0, d0, ((NI) (labid0)), until0); } LA12: ; return result0; } N_NIMCALL(void, gencasegeneric_549087_839829468)(Tcproc531021* p0, Tnode294802* t0, Tloc294816* d0, NimStringDesc* rangeformat0, NimStringDesc* eqformat0) { Tloc294816 a0; Ropeobj180006* lend0; NI LOC1; memset((void*)(&a0), 0, sizeof(a0)); initlocexpr_541283_839829468(p0, (*t0).kindU.S6.sons->data[((NI) 0)], (&a0)); LOC1 = (NI)0; LOC1 = sonslen_297351_850551059(t0); lend0 = genifforcaseuntil_549021_839829468(p0, t0, d0, rangeformat0, eqformat0, (NI)(LOC1 - ((NI) 1)), a0); fixlabel_541230_839829468(p0, lend0); } N_NIMCALL(void, genstringcase_549416_839829468)(Tcproc531021* p0, Tnode294802* t0, Tloc294816* d0) { NI strings0; strings0 = ((NI) 0); { NI i_549434_839829468; NI HEX3Atmp_549549_839829468; NI LOC2; NI res_549552_839829468; i_549434_839829468 = (NI)0; HEX3Atmp_549549_839829468 = (NI)0; LOC2 = (NI)0; LOC2 = sonslen_297351_850551059(t0); HEX3Atmp_549549_839829468 = (NI)(LOC2 - ((NI) 1)); res_549552_839829468 = ((NI) 1); { while (1) { if (!(res_549552_839829468 <= HEX3Atmp_549549_839829468)) goto LA4; i_549434_839829468 = res_549552_839829468; { NI LOC9; if (!((*(*t0).kindU.S6.sons->data[i_549434_839829468]).kind == ((Tnodekind294020) 85))) goto LA7; LOC9 = (NI)0; LOC9 = sonslen_297351_850551059((*t0).kindU.S6.sons->data[i_549434_839829468]); strings0 += (NI)(LOC9 - ((NI) 1)); } LA7: ; res_549552_839829468 += ((NI) 1); } LA4: ; } } { NI bitmask0; NI LOC14; TY193350* branches0; Tloc294816 a0; NI labid0; TY534811 LOC26; TY535289 LOC35; Ropeobj180006* lend0; NI LOC42; if (!(((NI) 8) < strings0)) goto LA12; LOC14 = (NI)0; LOC14 = nextpoweroftwo_101629_1009420244(strings0); bitmask0 = (NI)(LOC14 - ((NI) 1)); branches0 = (TY193350*)0; branches0 = (TY193350*) newSeq((&NTI193350), ((NI) ((NI)(bitmask0 + ((NI) 1))))); memset((void*)(&a0), 0, sizeof(a0)); initlocexpr_541283_839829468(p0, (*t0).kindU.S6.sons->data[((NI) 0)], (&a0)); labid0 = (*p0).labels; { NI i_549483_839829468; NI HEX3Atmp_549559_839829468; NI LOC16; NI res_549562_839829468; i_549483_839829468 = (NI)0; HEX3Atmp_549559_839829468 = (NI)0; LOC16 = (NI)0; LOC16 = sonslen_297351_850551059(t0); HEX3Atmp_549559_839829468 = (NI)(LOC16 - ((NI) 1)); res_549562_839829468 = ((NI) 1); { while (1) { if (!(res_549562_839829468 <= HEX3Atmp_549559_839829468)) goto LA18; i_549483_839829468 = res_549562_839829468; (*p0).labels += ((NI) 1); { Ropeobj180006* LOC23; Ropeobj180006* LOC24; if (!((*(*t0).kindU.S6.sons->data[i_549483_839829468]).kind == ((Tnodekind294020) 85))) goto LA21; LOC23 = (Ropeobj180006*)0; LOC23 = rope_180401_2381377266(((NI64) ((*p0).labels))); LOC24 = (Ropeobj180006*)0; LOC24 = HEX26_180452_2381377266(((NimStringDesc*) &T839829468_296), LOC23); gencasestringbranch_549100_839829468(p0, (*t0).kindU.S6.sons->data[i_549483_839829468], a0, LOC24, branches0->data, branches0->Sup.len); } goto LA19; LA21: ; { } LA19: ; res_549562_839829468 += ((NI) 1); } LA18: ; } } memset((void*)LOC26, 0, sizeof(LOC26)); LOC26[0] = rdloc_540188_839829468(a0); LOC26[1] = rope_180401_2381377266(((NI64) (bitmask0))); linefmt_534714_839829468(p0, ((Tcprocsection531011) 2), ((NimStringDesc*) &T839829468_596), LOC26, 2); { NI j_549517_839829468; NI HEX3Atmp_549567_839829468; NI res_549570_839829468; j_549517_839829468 = (NI)0; HEX3Atmp_549567_839829468 = (NI)0; HEX3Atmp_549567_839829468 = (branches0 ? (branches0->Sup.len-1) : -1); res_549570_839829468 = ((NI) 0); { while (1) { if (!(res_549570_839829468 <= HEX3Atmp_549567_839829468)) goto LA29; j_549517_839829468 = res_549570_839829468; { TY534811 LOC34; if (!!((branches0->data[j_549517_839829468] == NIM_NIL))) goto LA32; memset((void*)LOC34, 0, sizeof(LOC34)); LOC34[0] = intliteral_541270_839829468(((NI64) (j_549517_839829468))); LOC34[1] = branches0->data[j_549517_839829468]; linef_534700_839829468(p0, ((Tcprocsection531011) 2), ((NimStringDesc*) &T839829468_597), LOC34, 2); } LA32: ; res_549570_839829468 += ((NI) 1); } LA29: ; } } memset((void*)LOC35, 0, sizeof(LOC35)); linef_534700_839829468(p0, ((Tcprocsection531011) 2), ((NimStringDesc*) &T839829468_160), LOC35, 0); { NI LOC38; TY180507 LOC41; LOC38 = (NI)0; LOC38 = sonslen_297351_850551059(t0); if (!!(((*(*t0).kindU.S6.sons->data[(NI)(LOC38 - ((NI) 1))]).kind == ((Tnodekind294020) 85)))) goto LA39; memset((void*)LOC41, 0, sizeof(LOC41)); LOC41[0] = rope_180401_2381377266(((NI64) ((*p0).labels))); linef_534700_839829468(p0, ((Tcprocsection531011) 2), ((NimStringDesc*) &T839829468_598), LOC41, 1); } LA39: ; LOC42 = (NI)0; LOC42 = sonslen_297351_850551059(t0); lend0 = gencasesecondpass_548965_839829468(p0, t0, d0, ((NI) (labid0)), (NI)(LOC42 - ((NI) 1))); fixlabel_541230_839829468(p0, lend0); } goto LA10; LA12: ; { gencasegeneric_549087_839829468(p0, t0, d0, ((NimStringDesc*) &T839829468_490), ((NimStringDesc*) &T839829468_595)); } LA10: ; } N_NIMCALL(void, gengotoforcase_547673_839829468)(Tcproc531021* p0, Tnode294802* casestmt0) { { { NI i_547695_839829468; NI HEX3Atmp_547737_839829468; NI LOC2; NI res_547740_839829468; i_547695_839829468 = (NI)0; HEX3Atmp_547737_839829468 = (NI)0; LOC2 = (NI)0; LOC2 = len_295081_850551059(casestmt0); HEX3Atmp_547737_839829468 = (LOC2 - 1); res_547740_839829468 = ((NI) 1); { while (1) { TY535289 LOC5; NI LOC6; Tnode294802* it0; Tnode294802* LOC16; if (!(res_547740_839829468 <= HEX3Atmp_547737_839829468)) goto LA4; i_547695_839829468 = res_547740_839829468; memset((void*)LOC5, 0, sizeof(LOC5)); LOC6 = (NI)0; LOC6 = startblock_545978_839829468(p0, ((NimStringDesc*) &T839829468_273), LOC5, 0); it0 = (*casestmt0).kindU.S6.sons->data[i_547695_839829468]; { NI j_547711_839829468; NI HEX3Atmp_547730_839829468; NI LOC8; NI res_547733_839829468; j_547711_839829468 = (NI)0; HEX3Atmp_547730_839829468 = (NI)0; LOC8 = (NI)0; LOC8 = len_295081_850551059(it0); HEX3Atmp_547730_839829468 = (NI)(LOC8 - ((NI) 2)); res_547733_839829468 = ((NI) 0); { while (1) { NI64 val0; TY180507 LOC15; if (!(res_547733_839829468 <= HEX3Atmp_547730_839829468)) goto LA10; j_547711_839829468 = res_547733_839829468; { if (!((*(*it0).kindU.S6.sons->data[j_547711_839829468]).kind == ((Tnodekind294020) 44))) goto LA13; localerror_198085_155036129((*it0).info, ((NimStringDesc*) &T839829468_579)); goto BeforeRet; } LA13: ; val0 = getordvalue_322129_3876443242((*it0).kindU.S6.sons->data[j_547711_839829468]); memset((void*)LOC15, 0, sizeof(LOC15)); LOC15[0] = rope_180401_2381377266(val0); linef_534700_839829468(p0, ((Tcprocsection531011) 2), ((NimStringDesc*) &T839829468_602), LOC15, 1); res_547733_839829468 += ((NI) 1); } LA10: ; } } LOC16 = (Tnode294802*)0; LOC16 = lastson_297364_850551059(it0); genstmts_541244_839829468(p0, LOC16); endblock_546060_839829468(p0); res_547740_839829468 += ((NI) 1); } LA4: ; } } }BeforeRet: ; } N_NIMCALL(NIM_BOOL, branchhastoobigrange_549575_839829468)(Tnode294802* b0) { NIM_BOOL result0; { result0 = (NIM_BOOL)0; { NI i_549590_839829468; NI HEX3Atmp_549608_839829468; NI LOC2; NI res_549611_839829468; i_549590_839829468 = (NI)0; HEX3Atmp_549608_839829468 = (NI)0; LOC2 = (NI)0; LOC2 = sonslen_297351_850551059(b0); HEX3Atmp_549608_839829468 = (NI)(LOC2 - ((NI) 2)); res_549611_839829468 = ((NI) 0); { while (1) { if (!(res_549611_839829468 <= HEX3Atmp_549608_839829468)) goto LA4; i_549590_839829468 = res_549611_839829468; { NIM_BOOL LOC7; LOC7 = (NIM_BOOL)0; LOC7 = ((*(*b0).kindU.S6.sons->data[i_549590_839829468]).kind == ((Tnodekind294020) 44)); if (!(LOC7)) goto LA8; LOC7 = (IL64(256) < (NI64)((*(*(*b0).kindU.S6.sons->data[i_549590_839829468]).kindU.S6.sons->data[((NI) 1)]).kindU.S1.intval - (*(*(*b0).kindU.S6.sons->data[i_549590_839829468]).kindU.S6.sons->data[((NI) 0)]).kindU.S1.intval)); LA8: ; if (!LOC7) goto LA9; result0 = NIM_TRUE; goto BeforeRet; } LA9: ; res_549611_839829468 += ((NI) 1); } LA4: ; } } }BeforeRet: ; return result0; } N_NIMCALL(NI, ifswitchsplitpoint_549615_839829468)(Tcproc531021* p0, Tnode294802* n0) { NI result0; result0 = (NI)0; { NI i_549630_839829468; NI HEX3Atmp_549654_839829468; NI LOC2; NI res_549657_839829468; i_549630_839829468 = (NI)0; HEX3Atmp_549654_839829468 = (NI)0; LOC2 = (NI)0; LOC2 = len_295081_850551059(n0); HEX3Atmp_549654_839829468 = (NI)(LOC2 - ((NI) 1)); res_549657_839829468 = ((NI) 1); { while (1) { Tnode294802* branch0; Tnode294802* stmtblock0; if (!(res_549657_839829468 <= HEX3Atmp_549654_839829468)) goto LA4; i_549630_839829468 = res_549657_839829468; branch0 = HEX5BHEX5D_295238_850551059(n0, i_549630_839829468); stmtblock0 = lastson_297364_850551059(branch0); { NIM_BOOL LOC7; LOC7 = (NIM_BOOL)0; LOC7 = stmtscontainpragma_530083_2036603609(stmtblock0, ((Tspecialword277003) 181)); if (!LOC7) goto LA8; result0 = i_549630_839829468; } goto LA5; LA8: ; { if (!!(((Cc_275413_2528170400[(ccompiler_275431_2528170400)- 1].Field20 &(1U<<((NU)(((Tinfoccprop275004) 0))&7U)))!=0))) goto LA11; { NIM_BOOL LOC15; LOC15 = (NIM_BOOL)0; LOC15 = ((*branch0).kind == ((Tnodekind294020) 85)); if (!(LOC15)) goto LA16; LOC15 = branchhastoobigrange_549575_839829468(branch0); LA16: ; if (!LOC15) goto LA17; result0 = i_549630_839829468; } LA17: ; } goto LA5; LA11: ; LA5: ; res_549657_839829468 += ((NI) 1); } LA4: ; } } return result0; } N_NIMCALL(void, genordinalcase_549724_839829468)(Tcproc531021* p0, Tnode294802* n0, Tloc294816* d0) { NI splitpoint0; Tloc294816 a0; Ropeobj180006* lend0; splitpoint0 = ifswitchsplitpoint_549615_839829468(p0, n0); memset((void*)(&a0), 0, sizeof(a0)); initlocexpr_541283_839829468(p0, (*n0).kindU.S6.sons->data[((NI) 0)], (&a0)); { if (!(((NI) 0) < splitpoint0)) goto LA3; lend0 = genifforcaseuntil_549021_839829468(p0, n0, d0, ((NimStringDesc*) &T839829468_600), ((NimStringDesc*) &T839829468_601), splitpoint0, a0); } goto LA1; LA3: ; { lend0 = NIM_NIL; } LA1: ; { NI LOC8; TY180507 LOC11; NIM_BOOL hasdefault0; TY535289 LOC37; LOC8 = (NI)0; LOC8 = len_295081_850551059(n0); if (!((NI)(splitpoint0 + ((NI) 1)) < LOC8)) goto LA9; memset((void*)LOC11, 0, sizeof(LOC11)); LOC11[0] = rdcharloc_540227_839829468(a0); linef_534700_839829468(p0, ((Tcprocsection531011) 2), ((NimStringDesc*) &T839829468_603), LOC11, 1); hasdefault0 = NIM_FALSE; { NI i_549757_839829468; NI HEX3Atmp_549816_839829468; NI HEX3Atmp_549817_839829468; NI LOC13; NI res_549820_839829468; i_549757_839829468 = (NI)0; HEX3Atmp_549816_839829468 = (NI)0; HEX3Atmp_549817_839829468 = (NI)0; HEX3Atmp_549816_839829468 = (NI)(splitpoint0 + ((NI) 1)); LOC13 = (NI)0; LOC13 = len_295081_850551059(n0); HEX3Atmp_549817_839829468 = (LOC13 - 1); res_549820_839829468 = HEX3Atmp_549816_839829468; { while (1) { Tnode294802* branch0; Tnode294802* LOC28; TY535289 LOC29; if (!(res_549820_839829468 <= HEX3Atmp_549817_839829468)) goto LA15; i_549757_839829468 = res_549820_839829468; { NIM_BOOL LOC18; LOC18 = (NIM_BOOL)0; LOC18 = ((*d0).k == ((Tlockind294808) 1)); if (!(LOC18)) goto LA19; LOC18 = isemptytype_299440_850551059((*n0).typ); LA19: ; if (!LOC18) goto LA20; (*d0).k = ((Tlockind294808) 0); } LA20: ; branch0 = HEX5BHEX5D_295238_850551059(n0, i_549757_839829468); { if (!((*branch0).kind == ((Tnodekind294020) 85))) goto LA24; gencaserange_539028_839829468(p0, branch0); } goto LA22; LA24: ; { TY535289 LOC27; memset((void*)LOC27, 0, sizeof(LOC27)); linef_534700_839829468(p0, ((Tcprocsection531011) 2), ((NimStringDesc*) &T839829468_181), LOC27, 0); hasdefault0 = NIM_TRUE; } LA22: ; LOC28 = (Tnode294802*)0; LOC28 = lastson_297364_850551059(branch0); exprblock_546103_839829468(p0, LOC28, d0); memset((void*)LOC29, 0, sizeof(LOC29)); linef_534700_839829468(p0, ((Tcprocsection531011) 2), ((NimStringDesc*) &T839829468_182), LOC29, 0); res_549820_839829468 += ((NI) 1); } LA15: ; } } { NIM_BOOL LOC32; TY535289 LOC36; LOC32 = (NIM_BOOL)0; LOC32 = ((Cc_275413_2528170400[(ccompiler_275431_2528170400)- 1].Field20 &(1U<<((NU)(((Tinfoccprop275004) 3))&7U)))!=0); if (!(LOC32)) goto LA33; LOC32 = !(hasdefault0); LA33: ; if (!LOC32) goto LA34; memset((void*)LOC36, 0, sizeof(LOC36)); linef_534700_839829468(p0, ((Tcprocsection531011) 2), ((NimStringDesc*) &T839829468_604), LOC36, 0); } LA34: ; memset((void*)LOC37, 0, sizeof(LOC37)); linef_534700_839829468(p0, ((Tcprocsection531011) 2), ((NimStringDesc*) &T839829468_160), LOC37, 0); } LA9: ; { if (!!((lend0 == NIM_NIL))) goto LA40; fixlabel_541230_839829468(p0, lend0); } LA40: ; } N_NIMCALL(void, gencase_549826_839829468)(Tcproc531021* p0, Tnode294802* t0, Tloc294816* d0) { Ttype294840* LOC8; genlinedir_534823_839829468(p0, t0); { NIM_BOOL LOC3; NIM_BOOL LOC4; LOC3 = (NIM_BOOL)0; LOC4 = (NIM_BOOL)0; LOC4 = isemptytype_299440_850551059((*t0).typ); LOC3 = !(LOC4); if (!(LOC3)) goto LA5; LOC3 = ((*d0).k == ((Tlockind294808) 0)); LA5: ; if (!LOC3) goto LA6; gettemp_539032_839829468(p0, (*t0).typ, d0, NIM_FALSE); } LA6: ; LOC8 = (Ttype294840*)0; LOC8 = skiptypes_298099_850551059((*(*t0).kindU.S6.sons->data[((NI) 0)]).typ, IL64(211106242013440)); switch ((*LOC8).kind) { case ((Ttypekind294244) 28): { genstringcase_549416_839829468(p0, t0, d0); } break; case ((Ttypekind294244) 36) ... ((Ttypekind294244) 39): { gencasegeneric_549087_839829468(p0, t0, d0, ((NimStringDesc*) &T839829468_600), ((NimStringDesc*) &T839829468_601)); } break; default: { { NIM_BOOL LOC14; LOC14 = (NIM_BOOL)0; LOC14 = ((*(*t0).kindU.S6.sons->data[((NI) 0)]).kind == ((Tnodekind294020) 3)); if (!(LOC14)) goto LA15; LOC14 = (((*(*(*t0).kindU.S6.sons->data[((NI) 0)]).kindU.S4.sym).flags &(1U<<((NU)(((Tsymflag294184) 30))&31U)))!=0); LA15: ; if (!LOC14) goto LA16; gengotoforcase_547673_839829468(p0, t0); } goto LA12; LA16: ; { genordinalcase_549724_839829468(p0, t0, d0); } LA12: ; } break; } } static N_INLINE(Tnode294802*, pop_320246_1689653243)(Tnodeseq294796** s0) { Tnode294802* result0; NI L0; result0 = (Tnode294802*)0; L0 = (NI)(((*s0) ? (*s0)->Sup.len : 0) - ((NI) 1)); result0 = (*s0)->data[L0]; (*s0) = (Tnodeseq294796*) setLengthSeq(&((*s0))->Sup, sizeof(Tnode294802*), ((NI) (L0))); return result0; } N_NIMCALL(void, blockleaveactions_547442_839829468)(Tcproc531021* p0, NI howmanytrys0, NI howmanyexcepts0) { Tnodeseq294796* stack0; NI alreadypoppedcnt0; stack0 = (Tnodeseq294796*)0; stack0 = (Tnodeseq294796*) newSeq((&NTI294796), ((NI) 0)); alreadypoppedcnt0 = (*p0).inexceptblock; { NI i_547471_839829468; NI res_547596_839829468; i_547471_839829468 = (NI)0; res_547596_839829468 = ((NI) 1); { while (1) { Tnode294802* trystmt0; Tnode294802* finallystmt0; if (!(res_547596_839829468 <= howmanytrys0)) goto LA3; i_547471_839829468 = res_547596_839829468; { NIM_BOOL LOC6; LOC6 = (NIM_BOOL)0; LOC6 = (gcmd_171132_2607990831 == ((Tcommands171076) 2)); if (LOC6) goto LA7; LOC6 = (((*(*(*p0).module).module).flags &(1U<<((NU)(((Tsymflag294184) 27))&31U)))!=0); LA7: ; if (!!(LOC6)) goto LA8; { if (!(((NI) 0) < alreadypoppedcnt0)) goto LA12; alreadypoppedcnt0 -= ((NI) 1); } goto LA10; LA12: ; { TY535289 LOC15; memset((void*)LOC15, 0, sizeof(LOC15)); linefmt_534714_839829468(p0, ((Tcprocsection531011) 2), ((NimStringDesc*) &T839829468_605), LOC15, 0); } LA10: ; } LA8: ; trystmt0 = pop_320246_1689653243((&(*p0).nestedtrystmts)); stack0 = (Tnodeseq294796*) incrSeqV2(&(stack0)->Sup, sizeof(Tnode294802*)); asgnRefNoCycle((void**) (&stack0->data[stack0->Sup.len]), trystmt0); ++stack0->Sup.len; finallystmt0 = lastson_297364_850551059(trystmt0); { if (!((*finallystmt0).kind == ((Tnodekind294020) 107))) goto LA18; genstmts_541244_839829468(p0, (*finallystmt0).kindU.S6.sons->data[((NI) 0)]); } LA18: ; res_547596_839829468 += ((NI) 1); } LA3: ; } } { NI i_547546_839829468; NI HEX3Atmp_547601_839829468; NI res_547604_839829468; i_547546_839829468 = (NI)0; HEX3Atmp_547601_839829468 = (NI)0; HEX3Atmp_547601_839829468 = (NI)(howmanytrys0 - ((NI) 1)); res_547604_839829468 = HEX3Atmp_547601_839829468; { while (1) { if (!(((NI) 0) <= res_547604_839829468)) goto LA22; i_547546_839829468 = res_547604_839829468; (*p0).nestedtrystmts = (Tnodeseq294796*) incrSeqV2(&((*p0).nestedtrystmts)->Sup, sizeof(Tnode294802*)); asgnRefNoCycle((void**) (&(*p0).nestedtrystmts->data[(*p0).nestedtrystmts->Sup.len]), stack0->data[i_547546_839829468]); ++(*p0).nestedtrystmts->Sup.len; res_547604_839829468 -= ((NI) 1); } LA22: ; } } { NIM_BOOL LOC25; LOC25 = (NIM_BOOL)0; LOC25 = (gcmd_171132_2607990831 == ((Tcommands171076) 2)); if (LOC25) goto LA26; LOC25 = (((*(*(*p0).module).module).flags &(1U<<((NU)(((Tsymflag294184) 27))&31U)))!=0); LA26: ; if (!!(LOC25)) goto LA27; { NI i_547587_839829468; NI HEX3Atmp_547610_839829468; NI res_547613_839829468; i_547587_839829468 = (NI)0; HEX3Atmp_547610_839829468 = (NI)0; HEX3Atmp_547610_839829468 = (NI)(howmanyexcepts0 - ((NI) 1)); res_547613_839829468 = HEX3Atmp_547610_839829468; { while (1) { TY535289 LOC32; if (!(((NI) 0) <= res_547613_839829468)) goto LA31; i_547587_839829468 = res_547613_839829468; memset((void*)LOC32, 0, sizeof(LOC32)); linefmt_534714_839829468(p0, ((Tcprocsection531011) 2), ((NimStringDesc*) &T839829468_606), LOC32, 0); res_547613_839829468 -= ((NI) 1); } LA31: ; } } } LA27: ; } N_NIMCALL(void, genreturnstmt_547617_839829468)(Tcproc531021* p0, Tnode294802* t0) { TY535289 LOC14; { { if (!(((*t0).flags &(1U<<((NU)(((Tnodeflag294427) 14))&15U)))!=0)) goto LA3; goto BeforeRet; } LA3: ; (*p0).beforeretneeded = NIM_TRUE; genlinedir_534823_839829468(p0, t0); { if (!!(((*(*t0).kindU.S6.sons->data[((NI) 0)]).kind == ((Tnodekind294020) 1)))) goto LA7; genstmts_541244_839829468(p0, (*t0).kindU.S6.sons->data[((NI) 0)]); } LA7: ; blockleaveactions_547442_839829468(p0, ((*p0).nestedtrystmts ? (*p0).nestedtrystmts->Sup.len : 0), (*p0).inexceptblock); { Ropeobj180006* safepoint0; TY180507 LOC13; if (!(((NI) 0) < ((*p0).finallysafepoints ? (*p0).finallysafepoints->Sup.len : 0))) goto LA11; safepoint0 = (*p0).finallysafepoints->data[(NI)(((*p0).finallysafepoints ? (*p0).finallysafepoints->Sup.len : 0) - ((NI) 1))]; memset((void*)LOC13, 0, sizeof(LOC13)); LOC13[0] = safepoint0; linefmt_534714_839829468(p0, ((Tcprocsection531011) 2), ((NimStringDesc*) &T839829468_607), LOC13, 1); } LA11: ; memset((void*)LOC14, 0, sizeof(LOC14)); linef_534700_839829468(p0, ((Tcprocsection531011) 2), ((NimStringDesc*) &T839829468_608), LOC14, 0); }BeforeRet: ; } N_NIMCALL(void, genbreakstmt_548444_839829468)(Tcproc531021* p0, Tnode294802* t0) { NI idx0; Ropeobj180006* label0; TY180507 LOC16; idx0 = (*p0).breakidx; { Tsym294834* sym0; if (!!(((*(*t0).kindU.S6.sons->data[((NI) 0)]).kind == ((Tnodekind294020) 1)))) goto LA3; sym0 = (*(*t0).kindU.S6.sons->data[((NI) 0)]).kindU.S4.sym; idx0 = (NI)((*sym0).position - ((NI) 1)); } goto LA1; LA3: ; { { while (1) { NIM_BOOL LOC8; LOC8 = (NIM_BOOL)0; LOC8 = (((NI) 0) <= idx0); if (!(LOC8)) goto LA9; LOC8 = !((*p0).blocks->data[idx0].isloop); LA9: ; if (!LOC8) goto LA7; idx0 -= ((NI) 1); } LA7: ; } { NIM_BOOL LOC12; LOC12 = (NIM_BOOL)0; LOC12 = (idx0 < ((NI) 0)); if (LOC12) goto LA13; LOC12 = !((*p0).blocks->data[idx0].isloop); LA13: ; if (!LOC12) goto LA14; internalerror_198100_155036129((*t0).info, ((NimStringDesc*) &T839829468_609)); } LA14: ; } LA1: ; label0 = assignlabel_546020_839829468((&(*p0).blocks->data[idx0])); blockleaveactions_547442_839829468(p0, (NI)(((*p0).nestedtrystmts ? (*p0).nestedtrystmts->Sup.len : 0) - ((NI) ((*p0).blocks->data[idx0].nestedtrystmts))), (NI)((*p0).inexceptblock - ((NI) ((*p0).blocks->data[idx0].nestedexceptstmts)))); genlinedir_534823_839829468(p0, t0); memset((void*)LOC16, 0, sizeof(LOC16)); LOC16[0] = label0; linef_534700_839829468(p0, ((Tcprocsection531011) 2), ((NimStringDesc*) &T839829468_556), LOC16, 1); } N_NIMCALL(NIM_BOOL, fielddiscriminantcheckneeded_551080_839829468)(Tcproc531021* p0, Tnode294802* asgn0) { NIM_BOOL result0; result0 = (NIM_BOOL)0; { Tnode294802* le0; if (!(((*p0).options &(1U<<((NU)(((Toption171009) 2))&31U)))!=0)) goto LA3; le0 = (*asgn0).kindU.S6.sons->data[((NI) 0)]; { Tsym294834* field0; if (!((*le0).kind == ((Tnodekind294020) 46))) goto LA7; field0 = (*(*(*le0).kindU.S6.sons->data[((NI) 0)]).kindU.S6.sons->data[((NI) 1)]).kindU.S4.sym; result0 = (((*field0).flags &(1U<<((NU)(((Tsymflag294184) 18))&31U)))!=0); } goto LA5; LA7: ; { Tsym294834* field0; if (!((*le0).kind == ((Tnodekind294020) 45))) goto LA10; field0 = (*(*le0).kindU.S6.sons->data[((NI) 1)]).kindU.S4.sym; result0 = (((*field0).flags &(1U<<((NU)(((Tsymflag294184) 18))&31U)))!=0); } goto LA5; LA10: ; LA5: ; } LA3: ; return result0; } N_NIMCALL(Ropeobj180006*, discriminatortabledecl_538094_839829468)(Tcgen531027* m0, Ttype294840* objtype0, Tsym294834* d0) { Ropeobj180006* result0; Ropeobj180006* LOC1; Ropeobj180006* tmp0; TY534811 LOC2; NI64 LOC3; result0 = (Ropeobj180006*)0; LOC1 = (Ropeobj180006*)0; LOC1 = cgsym_534403_839829468(m0, ((NimStringDesc*) &T839829468_130)); tmp0 = discriminatortablename_538057_839829468(m0, objtype0, d0); memset((void*)LOC2, 0, sizeof(LOC2)); LOC2[0] = tmp0; LOC3 = (NI64)0; LOC3 = lengthord_322007_3876443242((*d0).typ); LOC2[1] = rope_180401_2381377266((NI64)(LOC3 + IL64(1))); result0 = HEX25_180905_2381377266(((NimStringDesc*) &T839829468_203), LOC2, 2); return result0; } N_NIMCALL(void, gendiscriminantcheck_551144_839829468)(Tcproc531021* p0, Tloc294816 a0, Tloc294816 tmp0, Ttype294840* objtype0, Tsym294834* field0) { Ttype294840* t0; Ropeobj180006* LOC1; NI64 L0; TY537235 LOC8; t0 = skiptypes_298099_850551059(objtype0, IL64(211106240964864)); LOC1 = (Ropeobj180006*)0; LOC1 = gentypeinfo_537941_839829468((*p0).module, t0); L0 = lengthord_322007_3876443242((*field0).typ); { NIM_BOOL LOC4; TY180507 LOC7; LOC4 = (NIM_BOOL)0; LOC4 = containsorincl_270862_2627731572((&(*(*p0).module).declaredthings), (*field0).Sup.id); if (!!(LOC4)) goto LA5; memset((void*)LOC7, 0, sizeof(LOC7)); LOC7[0] = discriminatortabledecl_538094_839829468((*p0).module, t0, field0); appcg_534640_839829468((*p0).module, ((Tcfilesection531005) 9), ((NimStringDesc*) &T839829468_610), LOC7, 1); } LA5: ; memset((void*)LOC8, 0, sizeof(LOC8)); LOC8[0] = rdloc_540188_839829468(a0); LOC8[1] = rdloc_540188_839829468(tmp0); LOC8[2] = discriminatortablename_538057_839829468((*p0).module, t0, field0); LOC8[3] = intliteral_541270_839829468((NI64)(L0 + IL64(1))); linecg_534707_839829468(p0, ((Tcprocsection531011) 2), ((NimStringDesc*) &T839829468_611), LOC8, 4); } N_NIMCALL(void, asgnfielddiscriminant_551209_839829468)(Tcproc531021* p0, Tnode294802* e0) { Tloc294816 a0; Tloc294816 tmp0; Tnode294802* dotexpr0; memset((void*)(&a0), 0, sizeof(a0)); memset((void*)(&tmp0), 0, sizeof(tmp0)); dotexpr0 = (*e0).kindU.S6.sons->data[((NI) 0)]; { if (!((*dotexpr0).kind == ((Tnodekind294020) 46))) goto LA3; dotexpr0 = (*dotexpr0).kindU.S6.sons->data[((NI) 0)]; } LA3: ; initlocexpr_541283_839829468(p0, (*e0).kindU.S6.sons->data[((NI) 0)], (&a0)); gettemp_539032_839829468(p0, a0.t, (&tmp0), NIM_FALSE); expr_541248_839829468(p0, (*e0).kindU.S6.sons->data[((NI) 1)], (&tmp0)); gendiscriminantcheck_551144_839829468(p0, a0, tmp0, (*(*dotexpr0).kindU.S6.sons->data[((NI) 0)]).typ, (*(*dotexpr0).kindU.S6.sons->data[((NI) 1)]).kindU.S4.sym); genassignment_541264_839829468(p0, a0, tmp0, 0); } N_NIMCALL(void, genasgn_551239_839829468)(Tcproc531021* p0, Tnode294802* e0, NIM_BOOL fastasgn0) { genlinedir_534823_839829468(p0, e0); { NIM_BOOL LOC3; LOC3 = (NIM_BOOL)0; LOC3 = ((*(*e0).kindU.S6.sons->data[((NI) 0)]).kind == ((Tnodekind294020) 3)); if (!(LOC3)) goto LA4; LOC3 = (((*(*(*e0).kindU.S6.sons->data[((NI) 0)]).kindU.S4.sym).flags &(1U<<((NU)(((Tsymflag294184) 30))&31U)))!=0); LA4: ; if (!LOC3) goto LA5; gengotovar_546258_839829468(p0, (*e0).kindU.S6.sons->data[((NI) 1)]); } goto LA1; LA5: ; { NIM_BOOL LOC8; Tloc294816 a0; LOC8 = (NIM_BOOL)0; LOC8 = fielddiscriminantcheckneeded_551080_839829468(p0, e0); if (!!(LOC8)) goto LA9; memset((void*)(&a0), 0, sizeof(a0)); { Tnode294802* LOC13; Tnode294802* LOC16; LOC13 = (Tnode294802*)0; LOC13 = HEX5BHEX5D_295238_850551059(e0, ((NI) 0)); if (!((*LOC13).kind == ((Tnodekind294020) 47) || (*LOC13).kind == ((Tnodekind294020) 65))) goto LA14; LOC16 = (Tnode294802*)0; LOC16 = HEX5BHEX5D_295238_850551059(e0, ((NI) 0)); genderef_545921_839829468(p0, LOC16, (&a0), NIM_TRUE); } goto LA11; LA14: ; { initlocexpr_541283_839829468(p0, (*e0).kindU.S6.sons->data[((NI) 0)], (&a0)); } LA11: ; { if (!fastasgn0) goto LA20; a0.flags |= ((NU16)1)<<((((Tlocflag294810) 2))%(sizeof(NU16)*8)); } LA20: ; loadinto_545928_839829468(p0, (*e0).kindU.S6.sons->data[((NI) 0)], (*e0).kindU.S6.sons->data[((NI) 1)], (&a0)); } goto LA1; LA9: ; { asgnfielddiscriminant_551209_839829468(p0, e0); } LA1: ; } N_NIMCALL(Ropeobj180006*, genasmoremitstmt_550529_839829468)(Tcproc531021* p0, Tnode294802* t0, NIM_BOOL isasmstmt0) { Ropeobj180006* result0; NimStringDesc* res0; result0 = (Ropeobj180006*)0; res0 = copyString(((NimStringDesc*) &T839829468_490)); { NI i_550547_839829468; NI HEX3Atmp_550644_839829468; NI LOC2; NI res_550647_839829468; i_550547_839829468 = (NI)0; HEX3Atmp_550644_839829468 = (NI)0; LOC2 = (NI)0; LOC2 = sonslen_297351_850551059(t0); HEX3Atmp_550644_839829468 = (NI)(LOC2 - ((NI) 1)); res_550647_839829468 = ((NI) 0); { while (1) { if (!(res_550647_839829468 <= HEX3Atmp_550644_839829468)) goto LA4; i_550547_839829468 = res_550647_839829468; switch ((*(*t0).kindU.S6.sons->data[i_550547_839829468]).kind) { case ((Tnodekind294020) 20) ... ((Tnodekind294020) 22): { res0 = resizeString(res0, (*(*t0).kindU.S6.sons->data[i_550547_839829468]).kindU.S3.strval->Sup.len + 0); appendString(res0, (*(*t0).kindU.S6.sons->data[i_550547_839829468]).kindU.S3.strval); } break; case ((Tnodekind294020) 3): { Tsym294834* sym0; sym0 = (*(*t0).kindU.S6.sons->data[i_550547_839829468]).kindU.S4.sym; { Tloc294816 a0; Ropeobj180006* LOC11; NimStringDesc* LOC12; if (!((28672 &(1U<<((NU)((*sym0).kind)&31U)))!=0)) goto LA9; memset((void*)(&a0), 0, sizeof(a0)); initlocexpr_541283_839829468(p0, (*t0).kindU.S6.sons->data[i_550547_839829468], (&a0)); LOC11 = (Ropeobj180006*)0; LOC11 = rdloc_540188_839829468(a0); LOC12 = (NimStringDesc*)0; LOC12 = HEX24_180856_2381377266(LOC11); res0 = resizeString(res0, LOC12->Sup.len + 0); appendString(res0, LOC12); } goto LA7; LA9: ; { Ropeobj180006* LOC16; NimStringDesc* LOC17; if (!((*sym0).kind == ((Tsymkind294435) 7))) goto LA14; LOC16 = (Ropeobj180006*)0; LOC16 = gettypedesc_537671_839829468((*p0).module, (*sym0).typ); LOC17 = (NimStringDesc*)0; LOC17 = HEX24_180856_2381377266(LOC16); res0 = resizeString(res0, LOC17->Sup.len + 0); appendString(res0, LOC17); } goto LA7; LA14: ; { Ropeobj180006* r0; NimStringDesc* LOC23; r0 = (*sym0).loc.r; { if (!(r0 == NIM_NIL)) goto LA21; r0 = manglename_535205_839829468(sym0); asgnRefNoCycle((void**) (&(*sym0).loc.r), r0); } LA21: ; LOC23 = (NimStringDesc*)0; LOC23 = HEX24_180856_2381377266(r0); res0 = resizeString(res0, LOC23->Sup.len + 0); appendString(res0, LOC23); } LA7: ; } break; default: { internalerror_198100_155036129((*(*t0).kindU.S6.sons->data[i_550547_839829468]).info, ((NimStringDesc*) &T839829468_612)); } break; } res_550647_839829468 += ((NI) 1); } LA4: ; } } { NIM_BOOL LOC27; LOC27 = (NIM_BOOL)0; LOC27 = isasmstmt0; if (!(LOC27)) goto LA28; LOC27 = ((Cc_275413_2528170400[(ccompiler_275431_2528170400)- 1].Field20 &(1U<<((NU)(((Tinfoccprop275004) 5))&7U)))!=0); LA28: ; if (!LOC27) goto LA29; { NimStringDesc* x_550604_839829468; NI first_550656_839829468; NI last_550658_839829468; x_550604_839829468 = (NimStringDesc*)0; first_550656_839829468 = ((NI) 0); last_550658_839829468 = ((NI) 0); { while (1) { NI j0; { while (1) { if (!!((((NU8)(res0->data[last_550658_839829468])) == ((NU8)(0)) || ((NU8)(res0->data[last_550658_839829468])) == ((NU8)(13)) || ((NU8)(res0->data[last_550658_839829468])) == ((NU8)(10))))) goto LA35; last_550658_839829468 += ((NI) 1); } LA35: ; } x_550604_839829468 = copyStrLast(res0, first_550656_839829468, (NI)(last_550658_839829468 - ((NI) 1))); j0 = ((NI) 0); { while (1) { if (!(((NU8)(x_550604_839829468->data[j0])) == ((NU8)(32)) || ((NU8)(x_550604_839829468->data[j0])) == ((NU8)(9)))) goto LA37; j0 += ((NI) 1); } LA37: ; } { if (!(((NU8)(x_550604_839829468->data[j0])) == ((NU8)(34)) || ((NU8)(x_550604_839829468->data[j0])) == ((NU8)(58)))) goto LA40; add_180487_2381377266(&result0, x_550604_839829468); add_180487_2381377266(&result0, tnl_178644_4151366050); } goto LA38; LA40: ; { if (!!(((NU8)(x_550604_839829468->data[j0]) == (NU8)(0)))) goto LA43; add_180487_2381377266(&result0, ((NimStringDesc*) &T839829468_613)); add_180487_2381377266(&result0, x_550604_839829468); add_180487_2381377266(&result0, ((NimStringDesc*) &T839829468_614)); } goto LA38; LA43: ; LA38: ; { if (!((NU8)(res0->data[last_550658_839829468]) == (NU8)(10))) goto LA47; last_550658_839829468 += ((NI) 1); } goto LA45; LA47: ; { if (!((NU8)(res0->data[last_550658_839829468]) == (NU8)(13))) goto LA50; last_550658_839829468 += ((NI) 1); { if (!((NU8)(res0->data[last_550658_839829468]) == (NU8)(10))) goto LA54; last_550658_839829468 += ((NI) 1); } LA54: ; } goto LA45; LA50: ; { goto LA32; } LA45: ; first_550656_839829468 = last_550658_839829468; } } LA32: ; } } goto LA25; LA29: ; { res0 = resizeString(res0, tnl_178644_4151366050->Sup.len + 0); appendString(res0, tnl_178644_4151366050); result0 = rope_180277_2381377266(res0); } LA25: ; return result0; } N_NIMCALL(void, genasmstmt_550659_839829468)(Tcproc531021* p0, Tnode294802* t0) { Ropeobj180006* s0; genlinedir_534823_839829468(p0, t0); s0 = genasmoremitstmt_550529_839829468(p0, t0, NIM_TRUE); { TY180507 LOC5; if (!((*p0).prc == NIM_NIL)) goto LA3; memset((void*)LOC5, 0, sizeof(LOC5)); LOC5[0] = s0; addf_181205_2381377266(&(*(*p0).module).s[(((Tcfilesection531005) 7))- 0], Cc_275413_2528170400[(ccompiler_275431_2528170400)- 1].Field17, LOC5, 1); } goto LA1; LA3: ; { TY180507 LOC7; memset((void*)LOC7, 0, sizeof(LOC7)); LOC7[0] = s0; linef_534700_839829468(p0, ((Tcprocsection531011) 2), Cc_275413_2528170400[(ccompiler_275431_2528170400)- 1].Field17, LOC7, 1); } LA1: ; } static N_INLINE(void, gensimpleblock_546095_839829468)(Tcproc531021* p0, Tnode294802* stmts0) { TY535289 LOC1; NI LOC2; memset((void*)LOC1, 0, sizeof(LOC1)); LOC2 = (NI)0; LOC2 = startblock_545978_839829468(p0, ((NimStringDesc*) &T839829468_273), LOC1, 0); genstmts_541244_839829468(p0, stmts0); endblock_546060_839829468(p0); } N_NIMCALL(void, gentrycpp_549865_839829468)(Tcproc531021* p0, Tnode294802* t0, Tloc294816* d0) { Ropeobj180006* exc0; TY535289 LOC16; NI LOC17; NI length0; TY180507 LOC18; Ropeobj180006* LOC19; NI i0; NIM_BOOL catchallpresent0; TY535289 LOC78; Tnode294802* LOC79; { NIM_BOOL LOC3; NIM_BOOL LOC4; LOC3 = (NIM_BOOL)0; LOC4 = (NIM_BOOL)0; LOC4 = isemptytype_299440_850551059((*t0).typ); LOC3 = !(LOC4); if (!(LOC3)) goto LA5; LOC3 = ((*d0).k == ((Tlockind294808) 0)); LA5: ; if (!LOC3) goto LA6; gettemp_539032_839829468(p0, (*t0).typ, d0, NIM_FALSE); } LA6: ; genlinedir_534823_839829468(p0, t0); exc0 = gettempname_535596_839829468((*p0).module); { Tsym294834* LOC10; Ropeobj180006* LOC13; LOC10 = (Tsym294834*)0; LOC10 = getcompilerproc_340746_3937434831(((NimStringDesc*) &T839829468_615)); if (!!((LOC10 == NIM_NIL))) goto LA11; LOC13 = (Ropeobj180006*)0; LOC13 = cgsym_534403_839829468((*p0).module, ((NimStringDesc*) &T839829468_615)); } goto LA8; LA11: ; { Ropeobj180006* LOC15; LOC15 = (Ropeobj180006*)0; LOC15 = cgsym_534403_839829468((*p0).module, ((NimStringDesc*) &T839829468_616)); } LA8: ; (*p0).nestedtrystmts = (Tnodeseq294796*) incrSeqV2(&((*p0).nestedtrystmts)->Sup, sizeof(Tnode294802*)); asgnRefNoCycle((void**) (&(*p0).nestedtrystmts->data[(*p0).nestedtrystmts->Sup.len]), t0); ++(*p0).nestedtrystmts->Sup.len; memset((void*)LOC16, 0, sizeof(LOC16)); LOC17 = (NI)0; LOC17 = startblock_545978_839829468(p0, ((NimStringDesc*) &T839829468_617), LOC16, 0); expr_541248_839829468(p0, (*t0).kindU.S6.sons->data[((NI) 0)], d0); length0 = sonslen_297351_850551059(t0); memset((void*)LOC18, 0, sizeof(LOC18)); LOC18[0] = exc0; LOC19 = (Ropeobj180006*)0; LOC19 = ropecg_534407_839829468((*p0).module, ((NimStringDesc*) &T839829468_618), LOC18, 1); endblock_546035_839829468(p0, LOC19); { TY535289 LOC24; if (!(((*p0).options &(1U<<((NU)(((Toption171009) 15))&31U)))!=0)) goto LA22; memset((void*)LOC24, 0, sizeof(LOC24)); linefmt_534714_839829468(p0, ((Tcprocsection531011) 2), ((NimStringDesc*) &T839829468_619), LOC24, 0); } LA22: ; (*p0).inexceptblock += ((NI) 1); i0 = ((NI) 1); catchallpresent0 = NIM_FALSE; { while (1) { NIM_BOOL LOC27; NI blen0; LOC27 = (NIM_BOOL)0; LOC27 = (i0 < length0); if (!(LOC27)) goto LA28; LOC27 = ((*(*t0).kindU.S6.sons->data[i0]).kind == ((Tnodekind294020) 87)); LA28: ; if (!LOC27) goto LA26; { NIM_BOOL LOC31; LOC31 = (NIM_BOOL)0; LOC31 = ((*d0).k == ((Tlockind294808) 1)); if (!(LOC31)) goto LA32; LOC31 = isemptytype_299440_850551059((*t0).typ); LA32: ; if (!LOC31) goto LA33; (*d0).k = ((Tlockind294808) 0); } LA33: ; blen0 = sonslen_297351_850551059((*t0).kindU.S6.sons->data[i0]); { Ropeobj180006** LOC39; TY535289 LOC40; if (!(((NI) 1) < i0)) goto LA37; LOC39 = (Ropeobj180006**)0; LOC39 = s_531179_3723162438(p0, ((Tcprocsection531011) 2)); memset((void*)LOC40, 0, sizeof(LOC40)); addf_181205_2381377266(LOC39, ((NimStringDesc*) &T839829468_620), LOC40, 0); } LA37: ; { TY535289 LOC45; NI LOC46; TY535289 LOC47; if (!(blen0 == ((NI) 1))) goto LA43; catchallpresent0 = NIM_TRUE; memset((void*)LOC45, 0, sizeof(LOC45)); LOC46 = (NI)0; LOC46 = startblock_545978_839829468(p0, ((NimStringDesc*) &T839829468_273), LOC45, 0); expr_541248_839829468(p0, (*(*t0).kindU.S6.sons->data[i0]).kindU.S6.sons->data[((NI) 0)], d0); memset((void*)LOC47, 0, sizeof(LOC47)); linefmt_534714_839829468(p0, ((Tcprocsection531011) 2), ((NimStringDesc*) &T839829468_606), LOC47, 0); endblock_546060_839829468(p0); } goto LA41; LA43: ; { Ropeobj180006* orexpr0; TY180507 LOC57; TY535289 LOC58; NI LOC59; TY535289 LOC60; orexpr0 = NIM_NIL; { NI j_549978_839829468; NI HEX3Atmp_550101_839829468; NI res_550104_839829468; j_549978_839829468 = (NI)0; HEX3Atmp_550101_839829468 = (NI)0; HEX3Atmp_550101_839829468 = (NI)(blen0 - ((NI) 2)); res_550104_839829468 = ((NI) 0); { while (1) { TY534811 LOC56; if (!(res_550104_839829468 <= HEX3Atmp_550101_839829468)) goto LA51; j_549978_839829468 = res_550104_839829468; { if (!!((orexpr0 == NIM_NIL))) goto LA54; add_180487_2381377266(&orexpr0, ((NimStringDesc*) &T839829468_229)); } LA54: ; memset((void*)LOC56, 0, sizeof(LOC56)); LOC56[0] = exc0; LOC56[1] = gentypeinfo_537941_839829468((*p0).module, (*(*(*t0).kindU.S6.sons->data[i0]).kindU.S6.sons->data[j_549978_839829468]).typ); appcg_534632_839829468((*p0).module, &orexpr0, ((NimStringDesc*) &T839829468_621), LOC56, 2); res_550104_839829468 += ((NI) 1); } LA51: ; } } memset((void*)LOC57, 0, sizeof(LOC57)); LOC57[0] = orexpr0; linef_534700_839829468(p0, ((Tcprocsection531011) 2), ((NimStringDesc*) &T839829468_622), LOC57, 1); memset((void*)LOC58, 0, sizeof(LOC58)); LOC59 = (NI)0; LOC59 = startblock_545978_839829468(p0, ((NimStringDesc*) &T839829468_273), LOC58, 0); expr_541248_839829468(p0, (*(*t0).kindU.S6.sons->data[i0]).kindU.S6.sons->data[(NI)(blen0 - ((NI) 1))], d0); memset((void*)LOC60, 0, sizeof(LOC60)); linefmt_534714_839829468(p0, ((Tcprocsection531011) 2), ((NimStringDesc*) &T839829468_606), LOC60, 0); endblock_546060_839829468(p0); } LA41: ; i0 += ((NI) 1); } LA26: ; } { TY535289 LOC70; NI LOC71; Tnode294802* finallyblock0; TY535289 LOC76; Ropeobj180006* LOC77; if (!!(catchallpresent0)) goto LA63; { TY535289 LOC69; if (!(((NI) 1) < i0)) goto LA67; memset((void*)LOC69, 0, sizeof(LOC69)); linef_534700_839829468(p0, ((Tcprocsection531011) 2), ((NimStringDesc*) &T839829468_620), LOC69, 0); } LA67: ; memset((void*)LOC70, 0, sizeof(LOC70)); LOC71 = (NI)0; LOC71 = startblock_545978_839829468(p0, ((NimStringDesc*) &T839829468_273), LOC70, 0); finallyblock0 = lastson_297364_850551059(t0); { if (!((*finallyblock0).kind == ((Tnodekind294020) 107))) goto LA74; genstmts_541244_839829468(p0, (*finallyblock0).kindU.S6.sons->data[((NI) 0)]); } LA74: ; memset((void*)LOC76, 0, sizeof(LOC76)); LOC77 = (Ropeobj180006*)0; LOC77 = HEX25_180905_2381377266(((NimStringDesc*) &T839829468_623), LOC76, 0); line_534690_839829468(p0, ((Tcprocsection531011) 2), LOC77); endblock_546060_839829468(p0); } LA63: ; memset((void*)LOC78, 0, sizeof(LOC78)); linef_534700_839829468(p0, ((Tcprocsection531011) 2), ((NimStringDesc*) &T839829468_160), LOC78, 0); (*p0).inexceptblock -= ((NI) 1); LOC79 = (Tnode294802*)0; LOC79 = pop_320246_1689653243((&(*p0).nestedtrystmts)); { NIM_BOOL LOC82; LOC82 = (NIM_BOOL)0; LOC82 = (i0 < length0); if (!(LOC82)) goto LA83; LOC82 = ((*(*t0).kindU.S6.sons->data[i0]).kind == ((Tnodekind294020) 107)); LA83: ; if (!LOC82) goto LA84; gensimpleblock_546095_839829468(p0, (*(*t0).kindU.S6.sons->data[i0]).kindU.S6.sons->data[((NI) 0)]); } LA84: ; } N_NIMCALL(void, line_534695_839829468)(Tcproc531021* p0, Tcprocsection531011 s0, NimStringDesc* r0) { Ropeobj180006** LOC1; Ropeobj180006* LOC2; Ropeobj180006* LOC3; LOC1 = (Ropeobj180006**)0; LOC1 = s_531179_3723162438(p0, s0); LOC2 = (Ropeobj180006*)0; LOC2 = rope_180277_2381377266(r0); LOC3 = (Ropeobj180006*)0; LOC3 = indentline_534656_839829468(p0, LOC2); add_180482_2381377266(LOC1, LOC3); } static N_INLINE(Ropeobj180006*, pop_180530_1689653243)(TY193350** s0) { Ropeobj180006* result0; NI L0; result0 = (Ropeobj180006*)0; L0 = (NI)(((*s0) ? (*s0)->Sup.len : 0) - ((NI) 1)); result0 = (*s0)->data[L0]; (*s0) = (TY193350*) setLengthSeq(&((*s0))->Sup, sizeof(Ropeobj180006*), ((NI) (L0))); return result0; } N_NIMCALL(void, gentry_550114_839829468)(Tcproc531021* p0, Tnode294802* t0, Tloc294816* d0) { NIM_BOOL LOC8; Ropeobj180006* safepoint0; TY180507 LOC17; TY180507 LOC18; TY180507 LOC37; NI LOC38; NI length0; TY535289 LOC39; TY535289 LOC40; NI LOC41; TY535289 LOC42; NI i0; Tnode294802* LOC95; TY180507 LOC103; { NIM_BOOL LOC3; NIM_BOOL LOC4; LOC3 = (NIM_BOOL)0; LOC4 = (NIM_BOOL)0; LOC4 = isemptytype_299440_850551059((*t0).typ); LOC3 = !(LOC4); if (!(LOC3)) goto LA5; LOC3 = ((*d0).k == ((Tlockind294808) 0)); LA5: ; if (!LOC3) goto LA6; gettemp_539032_839829468(p0, (*t0).typ, d0, NIM_FALSE); } LA6: ; LOC8 = (NIM_BOOL)0; LOC8 = includestr_148249_3771138726((&(*(*p0).module).headerfiles), ((NimStringDesc*) &T839829468_624)); genlinedir_534823_839829468(p0, t0); safepoint0 = gettempname_535596_839829468((*p0).module); { Tsym294834* LOC11; Ropeobj180006* LOC14; LOC11 = (Tsym294834*)0; LOC11 = getcompilerproc_340746_3937434831(((NimStringDesc*) &T839829468_615)); if (!!((LOC11 == NIM_NIL))) goto LA12; LOC14 = (Ropeobj180006*)0; LOC14 = cgsym_534403_839829468((*p0).module, ((NimStringDesc*) &T839829468_615)); } goto LA9; LA12: ; { Ropeobj180006* LOC16; LOC16 = (Ropeobj180006*)0; LOC16 = cgsym_534403_839829468((*p0).module, ((NimStringDesc*) &T839829468_616)); } LA9: ; memset((void*)LOC17, 0, sizeof(LOC17)); LOC17[0] = safepoint0; linefmt_534714_839829468(p0, ((Tcprocsection531011) 0), ((NimStringDesc*) &T839829468_625), LOC17, 1); memset((void*)LOC18, 0, sizeof(LOC18)); LOC18[0] = safepoint0; linefmt_534714_839829468(p0, ((Tcprocsection531011) 2), ((NimStringDesc*) &T839829468_626), LOC18, 1); { NIM_BOOL LOC21; TY180507 LOC24; LOC21 = (NIM_BOOL)0; LOC21 = isdefined_202011_1967573533(((NimStringDesc*) &T839829468_627)); if (!LOC21) goto LA22; memset((void*)LOC24, 0, sizeof(LOC24)); LOC24[0] = safepoint0; linefmt_534714_839829468(p0, ((Tcprocsection531011) 2), ((NimStringDesc*) &T839829468_628), LOC24, 1); } goto LA19; LA22: ; { NIM_BOOL LOC26; TY180507 LOC29; LOC26 = (NIM_BOOL)0; LOC26 = isdefined_202011_1967573533(((NimStringDesc*) &T839829468_629)); if (!LOC26) goto LA27; memset((void*)LOC29, 0, sizeof(LOC29)); LOC29[0] = safepoint0; linefmt_534714_839829468(p0, ((Tcprocsection531011) 2), ((NimStringDesc*) &T839829468_630), LOC29, 1); } goto LA19; LA27: ; { NIM_BOOL LOC31; TY180507 LOC34; LOC31 = (NIM_BOOL)0; LOC31 = isdefined_202011_1967573533(((NimStringDesc*) &T839829468_631)); if (!LOC31) goto LA32; memset((void*)LOC34, 0, sizeof(LOC34)); LOC34[0] = safepoint0; linefmt_534714_839829468(p0, ((Tcprocsection531011) 2), ((NimStringDesc*) &T839829468_632), LOC34, 1); } goto LA19; LA32: ; { TY180507 LOC36; memset((void*)LOC36, 0, sizeof(LOC36)); LOC36[0] = safepoint0; linefmt_534714_839829468(p0, ((Tcprocsection531011) 2), ((NimStringDesc*) &T839829468_628), LOC36, 1); } LA19: ; memset((void*)LOC37, 0, sizeof(LOC37)); LOC37[0] = safepoint0; LOC38 = (NI)0; LOC38 = startblock_545978_839829468(p0, ((NimStringDesc*) &T839829468_633), LOC37, 1); length0 = sonslen_297351_850551059(t0); (*p0).nestedtrystmts = (Tnodeseq294796*) incrSeqV2(&((*p0).nestedtrystmts)->Sup, sizeof(Tnode294802*)); asgnRefNoCycle((void**) (&(*p0).nestedtrystmts->data[(*p0).nestedtrystmts->Sup.len]), t0); ++(*p0).nestedtrystmts->Sup.len; expr_541248_839829468(p0, (*t0).kindU.S6.sons->data[((NI) 0)], d0); memset((void*)LOC39, 0, sizeof(LOC39)); linefmt_534714_839829468(p0, ((Tcprocsection531011) 2), ((NimStringDesc*) &T839829468_605), LOC39, 0); endblock_546060_839829468(p0); memset((void*)LOC40, 0, sizeof(LOC40)); LOC41 = (NI)0; LOC41 = startblock_545978_839829468(p0, ((NimStringDesc*) &T839829468_634), LOC40, 0); memset((void*)LOC42, 0, sizeof(LOC42)); linefmt_534714_839829468(p0, ((Tcprocsection531011) 2), ((NimStringDesc*) &T839829468_605), LOC42, 0); { TY535289 LOC47; if (!(((*p0).options &(1U<<((NU)(((Toption171009) 15))&31U)))!=0)) goto LA45; memset((void*)LOC47, 0, sizeof(LOC47)); linefmt_534714_839829468(p0, ((Tcprocsection531011) 2), ((NimStringDesc*) &T839829468_619), LOC47, 0); } LA45: ; (*p0).inexceptblock += ((NI) 1); i0 = ((NI) 1); { while (1) { NIM_BOOL LOC50; NI blen0; LOC50 = (NIM_BOOL)0; LOC50 = (i0 < length0); if (!(LOC50)) goto LA51; LOC50 = ((*(*t0).kindU.S6.sons->data[i0]).kind == ((Tnodekind294020) 87)); LA51: ; if (!LOC50) goto LA49; { NIM_BOOL LOC54; LOC54 = (NIM_BOOL)0; LOC54 = ((*d0).k == ((Tlockind294808) 1)); if (!(LOC54)) goto LA55; LOC54 = isemptytype_299440_850551059((*t0).typ); LA55: ; if (!LOC54) goto LA56; (*d0).k = ((Tlockind294808) 0); } LA56: ; blen0 = sonslen_297351_850551059((*t0).kindU.S6.sons->data[i0]); { TY535289 LOC67; NI LOC68; TY180507 LOC69; TY535289 LOC70; if (!(blen0 == ((NI) 1))) goto LA60; { TY535289 LOC66; if (!(((NI) 1) < i0)) goto LA64; memset((void*)LOC66, 0, sizeof(LOC66)); linef_534700_839829468(p0, ((Tcprocsection531011) 2), ((NimStringDesc*) &T839829468_635), LOC66, 0); } LA64: ; memset((void*)LOC67, 0, sizeof(LOC67)); LOC68 = (NI)0; LOC68 = startblock_545978_839829468(p0, ((NimStringDesc*) &T839829468_273), LOC67, 0); memset((void*)LOC69, 0, sizeof(LOC69)); LOC69[0] = safepoint0; linefmt_534714_839829468(p0, ((Tcprocsection531011) 2), ((NimStringDesc*) &T839829468_636), LOC69, 1); expr_541248_839829468(p0, (*(*t0).kindU.S6.sons->data[i0]).kindU.S6.sons->data[((NI) 0)], d0); memset((void*)LOC70, 0, sizeof(LOC70)); linefmt_534714_839829468(p0, ((Tcprocsection531011) 2), ((NimStringDesc*) &T839829468_606), LOC70, 0); endblock_546060_839829468(p0); } goto LA58; LA60: ; { Ropeobj180006* orexpr0; TY180507 LOC91; NI LOC92; TY180507 LOC93; TY535289 LOC94; orexpr0 = NIM_NIL; { NI j_550247_839829468; NI HEX3Atmp_550521_839829468; NI res_550524_839829468; j_550247_839829468 = (NI)0; HEX3Atmp_550521_839829468 = (NI)0; HEX3Atmp_550521_839829468 = (NI)(blen0 - ((NI) 2)); res_550524_839829468 = ((NI) 0); { while (1) { NimStringDesc* isobjformat0; TY180507 LOC86; if (!(res_550524_839829468 <= HEX3Atmp_550521_839829468)) goto LA74; j_550247_839829468 = res_550524_839829468; { if (!!((orexpr0 == NIM_NIL))) goto LA77; add_180487_2381377266(&orexpr0, ((NimStringDesc*) &T839829468_229)); } LA77: ; { NIM_BOOL LOC81; LOC81 = (NIM_BOOL)0; LOC81 = (gcmd_171132_2607990831 == ((Tcommands171076) 2)); if (LOC81) goto LA82; LOC81 = (((*(*(*p0).module).module).flags &(1U<<((NU)(((Tsymflag294184) 27))&31U)))!=0); LA82: ; if (!!(LOC81)) goto LA83; isobjformat0 = copyString(((NimStringDesc*) &T839829468_637)); } goto LA79; LA83: ; { isobjformat0 = copyString(((NimStringDesc*) &T839829468_638)); } LA79: ; memset((void*)LOC86, 0, sizeof(LOC86)); LOC86[0] = gentypeinfo_537941_839829468((*p0).module, (*(*(*t0).kindU.S6.sons->data[i0]).kindU.S6.sons->data[j_550247_839829468]).typ); appcg_534632_839829468((*p0).module, &orexpr0, isobjformat0, LOC86, 1); res_550524_839829468 += ((NI) 1); } LA74: ; } } { if (!(((NI) 1) < i0)) goto LA89; line_534695_839829468(p0, ((Tcprocsection531011) 2), ((NimStringDesc*) &T839829468_620)); } LA89: ; memset((void*)LOC91, 0, sizeof(LOC91)); LOC91[0] = orexpr0; LOC92 = (NI)0; LOC92 = startblock_545978_839829468(p0, ((NimStringDesc*) &T839829468_639), LOC91, 1); memset((void*)LOC93, 0, sizeof(LOC93)); LOC93[0] = safepoint0; linefmt_534714_839829468(p0, ((Tcprocsection531011) 2), ((NimStringDesc*) &T839829468_636), LOC93, 1); expr_541248_839829468(p0, (*(*t0).kindU.S6.sons->data[i0]).kindU.S6.sons->data[(NI)(blen0 - ((NI) 1))], d0); memset((void*)LOC94, 0, sizeof(LOC94)); linefmt_534714_839829468(p0, ((Tcprocsection531011) 2), ((NimStringDesc*) &T839829468_606), LOC94, 0); endblock_546060_839829468(p0); } LA58: ; i0 += ((NI) 1); } LA49: ; } (*p0).inexceptblock -= ((NI) 1); LOC95 = (Tnode294802*)0; LOC95 = pop_320246_1689653243((&(*p0).nestedtrystmts)); endblock_546060_839829468(p0); { NIM_BOOL LOC98; Ropeobj180006* LOC102; LOC98 = (NIM_BOOL)0; LOC98 = (i0 < length0); if (!(LOC98)) goto LA99; LOC98 = ((*(*t0).kindU.S6.sons->data[i0]).kind == ((Tnodekind294020) 107)); LA99: ; if (!LOC98) goto LA100; (*p0).finallysafepoints = (TY193350*) incrSeqV2(&((*p0).finallysafepoints)->Sup, sizeof(Ropeobj180006*)); asgnRefNoCycle((void**) (&(*p0).finallysafepoints->data[(*p0).finallysafepoints->Sup.len]), safepoint0); ++(*p0).finallysafepoints->Sup.len; gensimpleblock_546095_839829468(p0, (*(*t0).kindU.S6.sons->data[i0]).kindU.S6.sons->data[((NI) 0)]); LOC102 = (Ropeobj180006*)0; LOC102 = pop_180530_1689653243((&(*p0).finallysafepoints)); } LA100: ; memset((void*)LOC103, 0, sizeof(LOC103)); LOC103[0] = safepoint0; linefmt_534714_839829468(p0, ((Tcprocsection531011) 2), ((NimStringDesc*) &T839829468_640), LOC103, 1); } N_NIMCALL(NimStringDesc*, getraisefrmt_548824_839829468)(Tcproc531021* p0) { NimStringDesc* result0; result0 = (NimStringDesc*)0; result0 = copyString(((NimStringDesc*) &T839829468_641)); return result0; } N_NIMCALL(void, genraisestmt_548828_839829468)(Tcproc531021* p0, Tnode294802* t0) { { Tnode294802* finallyblock0; if (!(((NI) 0) < (*p0).inexceptblock)) goto LA3; finallyblock0 = lastson_297364_850551059((*p0).nestedtrystmts->data[(NI)(((*p0).nestedtrystmts ? (*p0).nestedtrystmts->Sup.len : 0) - ((NI) 1))]); { if (!((*finallyblock0).kind == ((Tnodekind294020) 107))) goto LA7; gensimpleblock_546095_839829468(p0, (*finallyblock0).kindU.S6.sons->data[((NI) 0)]); } LA7: ; } LA3: ; { Tloc294816 a0; Ropeobj180006* e0; Ttype294840* typ0; NimStringDesc* LOC13; TY534811 LOC14; if (!!(((*(*t0).kindU.S6.sons->data[((NI) 0)]).kind == ((Tnodekind294020) 1)))) goto LA11; memset((void*)(&a0), 0, sizeof(a0)); initlocexpr_541283_839829468(p0, (*t0).kindU.S6.sons->data[((NI) 0)], (&a0)); e0 = rdloc_540188_839829468(a0); typ0 = skiptypes_298099_850551059((*(*t0).kindU.S6.sons->data[((NI) 0)]).typ, IL64(211106247256320)); genlinedir_534823_839829468(p0, t0); LOC13 = (NimStringDesc*)0; LOC13 = getraisefrmt_548824_839829468(p0); memset((void*)LOC14, 0, sizeof(LOC14)); LOC14[0] = e0; LOC14[1] = makecstring_193638_155036129((*(*(*typ0).sym).name).s); linecg_534707_839829468(p0, ((Tcprocsection531011) 2), LOC13, LOC14, 2); } goto LA9; LA11: ; { genlinedir_534823_839829468(p0, t0); { NIM_BOOL LOC18; NIM_BOOL LOC19; TY535289 LOC24; Ropeobj180006* LOC25; LOC18 = (NIM_BOOL)0; LOC19 = (NIM_BOOL)0; LOC19 = (gcmd_171132_2607990831 == ((Tcommands171076) 2)); if (LOC19) goto LA20; LOC19 = (((*(*(*p0).module).module).flags &(1U<<((NU)(((Tsymflag294184) 27))&31U)))!=0); LA20: ; LOC18 = LOC19; if (!(LOC18)) goto LA21; LOC18 = !(((gglobaloptions_171130_2607990831 &((NU64)1<<((NU)(((Tglobaloption171013) 31))&63U)))!=0)); LA21: ; if (!LOC18) goto LA22; memset((void*)LOC24, 0, sizeof(LOC24)); LOC25 = (Ropeobj180006*)0; LOC25 = HEX25_180905_2381377266(((NimStringDesc*) &T839829468_623), LOC24, 0); line_534690_839829468(p0, ((Tcprocsection531011) 2), LOC25); } goto LA16; LA22: ; { TY535289 LOC27; memset((void*)LOC27, 0, sizeof(LOC27)); linefmt_534714_839829468(p0, ((Tcprocsection531011) 2), ((NimStringDesc*) &T839829468_642), LOC27, 0); } LA16: ; } LA9: ; } N_NIMCALL(void, gentypesection_540184_839829468)(Tcgen531027* m0, Tnode294802* n0) { } N_NIMCALL(Tcfilesection531005, determinesection_550819_839829468)(Tnode294802* n0) { Tcfilesection531005 result0; result0 = (Tcfilesection531005)0; result0 = ((Tcfilesection531005) 7); { NIM_BOOL LOC3; NI LOC4; NimStringDesc* sec0; LOC3 = (NIM_BOOL)0; LOC4 = (NI)0; LOC4 = len_295081_850551059(n0); LOC3 = (((NI) 1) <= LOC4); if (!(LOC3)) goto LA5; LOC3 = ((*(*n0).kindU.S6.sons->data[((NI) 0)]).kind >= ((Tnodekind294020) 20) && (*(*n0).kindU.S6.sons->data[((NI) 0)]).kind <= ((Tnodekind294020) 22)); LA5: ; if (!LOC3) goto LA6; sec0 = (*(*n0).kindU.S6.sons->data[((NI) 0)]).kindU.S3.strval; { NIM_BOOL LOC10; LOC10 = (NIM_BOOL)0; LOC10 = nsuStartsWith(sec0, ((NimStringDesc*) &T839829468_643)); if (!LOC10) goto LA11; result0 = ((Tcfilesection531005) 3); } goto LA8; LA11: ; { NIM_BOOL LOC14; LOC14 = (NIM_BOOL)0; LOC14 = nsuStartsWith(sec0, ((NimStringDesc*) &T839829468_644)); if (!LOC14) goto LA15; result0 = ((Tcfilesection531005) 9); } goto LA8; LA15: ; { NIM_BOOL LOC18; LOC18 = (NIM_BOOL)0; LOC18 = nsuStartsWith(sec0, ((NimStringDesc*) &T839829468_645)); if (!LOC18) goto LA19; result0 = ((Tcfilesection531005) 1); } goto LA8; LA19: ; LA8: ; } LA6: ; return result0; } N_NIMCALL(void, genemit_550839_839829468)(Tcproc531021* p0, Tnode294802* t0) { Ropeobj180006* s0; s0 = genasmoremitstmt_550529_839829468(p0, (*t0).kindU.S6.sons->data[((NI) 1)], NIM_FALSE); { Tcfilesection531005 section0; Tnode294802* LOC5; if (!((*p0).prc == NIM_NIL)) goto LA3; LOC5 = (Tnode294802*)0; LOC5 = HEX5BHEX5D_295238_850551059(t0, ((NI) 1)); section0 = determinesection_550819_839829468(LOC5); genclinedir_534813_839829468(&(*(*p0).module).s[(section0)- 0], (*t0).info); add_180482_2381377266(&(*(*p0).module).s[(section0)- 0], s0); } goto LA1; LA3: ; { genlinedir_534823_839829468(p0, t0); line_534690_839829468(p0, ((Tcprocsection531011) 2), s0); } LA1: ; } N_NIMCALL(void, genbreakpoint_550862_839829468)(Tcproc531021* p0, Tnode294802* t0) { NimStringDesc* name0; name0 = (NimStringDesc*)0; { TY537238 LOC12; NI LOC13; NimStringDesc* LOC14; if (!(((*p0).options &(1U<<((NU)(((Toption171009) 17))&31U)))!=0)) goto LA3; { if (!((*t0).kind == ((Tnodekind294020) 34))) goto LA7; name0 = nsuNormalize((*(*t0).kindU.S6.sons->data[((NI) 1)]).kindU.S3.strval); } goto LA5; LA7: ; { NimStringDesc* LOC10; NimStringDesc* LOC11; breakpointid_550860_839829468 += ((NI) 1); LOC10 = (NimStringDesc*)0; LOC11 = (NimStringDesc*)0; LOC11 = nimIntToStr(breakpointid_550860_839829468); LOC10 = rawNewString(LOC11->Sup.len + 2); appendString(LOC10, ((NimStringDesc*) &T839829468_646)); appendString(LOC10, LOC11); name0 = LOC10; } LA5: ; genlinedir_534823_839829468(p0, t0); memset((void*)LOC12, 0, sizeof(LOC12)); LOC13 = (NI)0; LOC13 = tolinenumber_194415_155036129((*t0).info); LOC12[0] = rope_180401_2381377266(((NI64) (LOC13))); LOC14 = (NimStringDesc*)0; LOC14 = tofilename_194260_155036129((*t0).info.fileindex); LOC12[1] = makecstring_193638_155036129(LOC14); LOC12[2] = makecstring_193638_155036129(name0); appcg_534632_839829468((*p0).module, &gbreakpoints_550861_839829468, ((NimStringDesc*) &T839829468_647), LOC12, 3); } LA3: ; } N_NIMCALL(void, genwatchpoint_551016_839829468)(Tcproc531021* p0, Tnode294802* n0) { Tloc294816 a0; Ttype294840* typ0; TY537238 LOC5; NimStringDesc* LOC6; { { if (!!((((*p0).options &(1U<<((NU)(((Toption171009) 17))&31U)))!=0))) goto LA3; goto BeforeRet; } LA3: ; memset((void*)(&a0), 0, sizeof(a0)); initlocexpr_541283_839829468(p0, (*n0).kindU.S6.sons->data[((NI) 1)], (&a0)); typ0 = skiptypes_298099_850551059((*(*n0).kindU.S6.sons->data[((NI) 1)]).typ, IL64(211106242013440)); memset((void*)LOC5, 0, sizeof(LOC5)); LOC5[0] = addrloc_540204_839829468(a0); LOC6 = (NimStringDesc*)0; LOC6 = rendertree_313044_382274130((*n0).kindU.S6.sons->data[((NI) 1)], 0); LOC5[1] = makecstring_193638_155036129(LOC6); LOC5[2] = gentypeinfo_537941_839829468((*p0).module, typ0); linecg_534707_839829468(p0, ((Tcprocsection531011) 2), ((NimStringDesc*) &T839829468_648), LOC5, 3); }BeforeRet: ; } N_NIMCALL(void, genpragma_551039_839829468)(Tcproc531021* p_551041_839829468, Tnode294802* n0) { { NI i_551054_839829468; NI HEX3Atmp_551073_839829468; NI LOC2; NI res_551076_839829468; i_551054_839829468 = (NI)0; HEX3Atmp_551073_839829468 = (NI)0; LOC2 = (NI)0; LOC2 = sonslen_297351_850551059(n0); HEX3Atmp_551073_839829468 = (NI)(LOC2 - ((NI) 1)); res_551076_839829468 = ((NI) 0); { while (1) { Tnode294802* it0; Tspecialword277003 LOC5; if (!(res_551076_839829468 <= HEX3Atmp_551073_839829468)) goto LA4; i_551054_839829468 = res_551076_839829468; it0 = (*n0).kindU.S6.sons->data[i_551054_839829468]; LOC5 = (Tspecialword277003)0; LOC5 = whichpragma_320911_2616423590(it0); switch (LOC5) { case ((Tspecialword277003) 191): { genemit_550839_839829468(p_551041_839829468, it0); } break; case ((Tspecialword277003) 131): { genbreakpoint_550862_839829468(p_551041_839829468, it0); } break; case ((Tspecialword277003) 176): { genwatchpoint_551016_839829468(p_551041_839829468, it0); } break; case ((Tspecialword277003) 183): { Tcproc531021* p0; Ropeobj180006** LOC10; p0 = newproc_531206_3723162438(NIM_NIL, (*p_551041_839829468).module); (*p0).options = ((*p0).options & ~ 98304); genstmts_541244_839829468(p0, (*it0).kindU.S6.sons->data[((NI) 1)]); LOC10 = (Ropeobj180006**)0; LOC10 = s_531179_3723162438(p0, ((Tcprocsection531011) 2)); asgnRefNoCycle((void**) (&(*(*p0).module).injectstmt), (*LOC10)); } break; default: { } break; } res_551076_839829468 += ((NI) 1); } LA4: ; } } } N_NIMCALL(void, genparforstmt_548208_839829468)(Tcproc531021* p0, Tnode294802* t0) { NI oldbreakidx_548411_839829468; Tsym294834* forloopvar0; Tloc294816 rangea0; Tloc294816 rangeb0; Tnode294802* call0; TY537235 LOC1; NimStringDesc* LOC2; TY535289 LOC3; (*p0).withinloop += ((NI) 1); genlinedir_534823_839829468(p0, t0); oldbreakidx_548411_839829468 = (*p0).breakidx; forloopvar0 = (*(*t0).kindU.S6.sons->data[((NI) 0)]).kindU.S4.sym; memset((void*)(&rangea0), 0, sizeof(rangea0)); memset((void*)(&rangeb0), 0, sizeof(rangeb0)); assignlocalvar_540614_839829468(p0, forloopvar0); call0 = (*t0).kindU.S6.sons->data[((NI) 1)]; initlocexpr_541283_839829468(p0, (*call0).kindU.S6.sons->data[((NI) 1)], (&rangea0)); initlocexpr_541283_839829468(p0, (*call0).kindU.S6.sons->data[((NI) 2)], (&rangeb0)); memset((void*)LOC1, 0, sizeof(LOC1)); LOC1[0] = rdloc_540188_839829468((*forloopvar0).loc); LOC1[1] = rdloc_540188_839829468(rangea0); LOC1[2] = rdloc_540188_839829468(rangeb0); LOC2 = (NimStringDesc*)0; LOC2 = getstr_299230_850551059((*call0).kindU.S6.sons->data[((NI) 3)]); LOC1[3] = rope_180277_2381377266(LOC2); linef_534700_839829468(p0, ((Tcprocsection531011) 2), ((NimStringDesc*) &T839829468_649), LOC1, 4); memset((void*)LOC3, 0, sizeof(LOC3)); (*p0).breakidx = startblock_545978_839829468(p0, ((NimStringDesc*) &T839829468_273), LOC3, 0); (*p0).blocks->data[(*p0).breakidx].isloop = NIM_TRUE; genstmts_541244_839829468(p0, (*t0).kindU.S6.sons->data[((NI) 2)]); endblock_546060_839829468(p0); (*p0).breakidx = oldbreakidx_548411_839829468; (*p0).withinloop -= ((NI) 1); } N_NIMCALL(void, genstate_546117_839829468)(Tcproc531021* p0, Tnode294802* n0) { NI64 idx0; TY180507 LOC9; { NIM_BOOL LOC3; NI LOC4; NimStringDesc* LOC8; LOC3 = (NIM_BOOL)0; LOC4 = (NI)0; LOC4 = len_295081_850551059(n0); LOC3 = (LOC4 == ((NI) 1)); if (!(LOC3)) goto LA5; LOC3 = ((*(*n0).kindU.S6.sons->data[((NI) 0)]).kind == ((Tnodekind294020) 6)); LA5: ; if (!!(LOC3)) goto LA6; LOC8 = (NimStringDesc*)0; LOC8 = HEX24_198185_1689653243(T839829468_650); internalerror_198113_155036129(LOC8); } LA6: ; idx0 = (*(*n0).kindU.S6.sons->data[((NI) 0)]).kindU.S1.intval; memset((void*)LOC9, 0, sizeof(LOC9)); LOC9[0] = rope_180401_2381377266(idx0); linefmt_534714_839829468(p0, ((Tcprocsection531011) 2), ((NimStringDesc*) &T839829468_652), LOC9, 1); } N_NIMCALL(void, gengotostate_546144_839829468)(Tcproc531021* p0, Tnode294802* n0) { Tloc294816 a0; TY180507 LOC1; TY535289 LOC2; TY535289 LOC7; memset((void*)(&a0), 0, sizeof(a0)); initlocexpr_541283_839829468(p0, (*n0).kindU.S6.sons->data[((NI) 0)], (&a0)); memset((void*)LOC1, 0, sizeof(LOC1)); LOC1[0] = rdloc_540188_839829468(a0); linef_534700_839829468(p0, ((Tcprocsection531011) 2), ((NimStringDesc*) &T839829468_603), LOC1, 1); (*p0).beforeretneeded = NIM_TRUE; memset((void*)LOC2, 0, sizeof(LOC2)); linef_534700_839829468(p0, ((Tcprocsection531011) 2), ((NimStringDesc*) &T839829468_653), LOC2, 0); { NI64 i_546214_839829468; NI64 HEX3Atmp_546223_839829468; NI64 res_546226_839829468; i_546214_839829468 = (NI64)0; HEX3Atmp_546223_839829468 = (NI64)0; HEX3Atmp_546223_839829468 = lastord_322004_3876443242((*(*n0).kindU.S6.sons->data[((NI) 0)]).typ); res_546226_839829468 = IL64(0); { while (1) { TY180507 LOC6; if (!(res_546226_839829468 <= HEX3Atmp_546223_839829468)) goto LA5; i_546214_839829468 = res_546226_839829468; memset((void*)LOC6, 0, sizeof(LOC6)); LOC6[0] = rope_180401_2381377266(i_546214_839829468); linef_534700_839829468(p0, ((Tcprocsection531011) 2), ((NimStringDesc*) &T839829468_654), LOC6, 1); res_546226_839829468 += ((NI) 1); } LA5: ; } } memset((void*)LOC7, 0, sizeof(LOC7)); linef_534700_839829468(p0, ((Tcprocsection531011) 2), ((NimStringDesc*) &T839829468_160), LOC7, 0); } N_NIMCALL(void, genbreakstate_546229_839829468)(Tcproc531021* p0, Tnode294802* n0) { Tloc294816 a0; memset((void*)(&a0), 0, sizeof(a0)); { TY180507 LOC5; if (!((*(*n0).kindU.S6.sons->data[((NI) 0)]).kind == ((Tnodekind294020) 155))) goto LA3; initlocexpr_541283_839829468(p0, (*(*n0).kindU.S6.sons->data[((NI) 0)]).kindU.S6.sons->data[((NI) 1)], (&a0)); memset((void*)LOC5, 0, sizeof(LOC5)); LOC5[0] = rdloc_540188_839829468(a0); linef_534700_839829468(p0, ((Tcprocsection531011) 2), ((NimStringDesc*) &T839829468_655), LOC5, 1); } goto LA1; LA3: ; { TY180507 LOC7; initlocexpr_541283_839829468(p0, (*n0).kindU.S6.sons->data[((NI) 0)], (&a0)); memset((void*)LOC7, 0, sizeof(LOC7)); LOC7[0] = rdloc_540188_839829468(a0); linef_534700_839829468(p0, ((Tcprocsection531011) 2), ((NimStringDesc*) &T839829468_656), LOC7, 1); } LA1: ; } N_NIMCALL(void, expr_541248_839829468)(Tcproc531021* p0, Tnode294802* n0, Tloc294816* d0) { switch ((*n0).kind) { case ((Tnodekind294020) 3): { Tsym294834* sym0; sym0 = (*n0).kindU.S4.sym; switch ((*sym0).kind) { case ((Tsymkind294435) 13): { { if (!!(((33554448 & (*sym0).flags) == 0))) goto LA5; fillprocloc_541201_839829468(sym0); genprocprototype_541254_839829468((*p0).module, sym0); } goto LA3; LA5: ; { genproc_534951_839829468((*p0).module, sym0); } LA3: ; putlocintodest_541258_839829468(p0, d0, (*sym0).loc); } break; case ((Tsymkind294435) 12): case ((Tsymkind294435) 15): case ((Tsymkind294435) 14): { { NimStringDesc* LOC13; if (!(((*sym0).flags &(1U<<((NU)(((Tsymflag294184) 23))&31U)))!=0)) goto LA11; LOC13 = (NimStringDesc*)0; LOC13 = rawNewString((*(*sym0).name).s->Sup.len + 48); appendString(LOC13, ((NimStringDesc*) &T839829468_270)); appendString(LOC13, (*(*sym0).name).s); localerror_198085_155036129((*n0).info, LOC13); } LA11: ; genproc_534951_839829468((*p0).module, sym0); { NIM_BOOL LOC16; NimStringDesc* LOC20; LOC16 = (NIM_BOOL)0; LOC16 = ((*sym0).loc.r == NIM_NIL); if (LOC16) goto LA17; LOC16 = ((*sym0).loc.t == NIM_NIL); LA17: ; if (!LOC16) goto LA18; LOC20 = (NimStringDesc*)0; LOC20 = rawNewString((*(*sym0).name).s->Sup.len + 20); appendString(LOC20, ((NimStringDesc*) &T839829468_271)); appendString(LOC20, (*(*sym0).name).s); internalerror_198100_155036129((*n0).info, LOC20); } LA18: ; putlocintodest_541258_839829468(p0, d0, (*sym0).loc); } break; case ((Tsymkind294435) 10): { { NIM_BOOL LOC24; Ropeobj180006* LOC27; LOC24 = (NIM_BOOL)0; LOC24 = issimpleconst_534311_839829468((*sym0).typ); if (!LOC24) goto LA25; LOC27 = (Ropeobj180006*)0; LOC27 = genliteral_551476_839829468(p0, (*sym0).ast, (*sym0).typ); putintodest_552468_839829468(p0, d0, (*n0).typ, LOC27, ((Tstorageloc294812) 1)); } goto LA22; LA25: ; { gencomplexconst_560249_839829468(p0, sym0, d0); } LA22: ; } break; case ((Tsymkind294435) 19): { Ropeobj180006* LOC30; LOC30 = (Ropeobj180006*)0; LOC30 = rope_180401_2381377266(((NI64) ((*sym0).position))); putintodest_552468_839829468(p0, d0, (*n0).typ, LOC30, ((Tstorageloc294812) 0)); } break; case ((Tsymkind294435) 8): case ((Tsymkind294435) 20): case ((Tsymkind294435) 11): case ((Tsymkind294435) 9): { { if (!!(((4194312 & (*sym0).flags) == 0))) goto LA34; genvarprototype_541236_839829468((*p0).module, sym0); } LA34: ; { NIM_BOOL LOC38; NimStringDesc* LOC42; NimStringDesc* LOC43; LOC38 = (NIM_BOOL)0; LOC38 = ((*sym0).loc.r == NIM_NIL); if (LOC38) goto LA39; LOC38 = ((*sym0).loc.t == NIM_NIL); LA39: ; if (!LOC38) goto LA40; LOC42 = (NimStringDesc*)0; LOC43 = (NimStringDesc*)0; LOC43 = nimIntToStr((*sym0).Sup.id); LOC42 = rawNewString((*(*sym0).name).s->Sup.len + LOC43->Sup.len + 20); appendString(LOC42, ((NimStringDesc*) &T839829468_285)); appendString(LOC42, (*(*sym0).name).s); appendString(LOC42, ((NimStringDesc*) &T839829468_12)); appendString(LOC42, LOC43); internalerror_198100_155036129((*n0).info, LOC42); } LA40: ; { if (!(((*sym0).flags &(1U<<((NU)(((Tsymflag294184) 22))&31U)))!=0)) goto LA46; accessthreadlocalvar_534945_839829468(p0, sym0); { NIM_BOOL LOC50; Ropeobj180006* LOC53; LOC50 = (NIM_BOOL)0; LOC50 = emulatedthreadvars_534949_839829468(); if (!LOC50) goto LA51; LOC53 = (Ropeobj180006*)0; LOC53 = HEX26_180452_2381377266(((NimStringDesc*) &T839829468_288), (*sym0).loc.r); putintodest_552468_839829468(p0, d0, (*sym0).loc.t, LOC53, ((Tstorageloc294812) 0)); } goto LA48; LA51: ; { putlocintodest_541258_839829468(p0, d0, (*sym0).loc); } LA48: ; } goto LA44; LA46: ; { putlocintodest_541258_839829468(p0, d0, (*sym0).loc); } LA44: ; } break; case ((Tsymkind294435) 5): { { NIM_BOOL LOC59; NimStringDesc* LOC63; NimStringDesc* LOC64; LOC59 = (NIM_BOOL)0; LOC59 = ((*sym0).loc.r == NIM_NIL); if (LOC59) goto LA60; LOC59 = ((*sym0).loc.t == NIM_NIL); LA60: ; if (!LOC59) goto LA61; LOC63 = (NimStringDesc*)0; LOC64 = (NimStringDesc*)0; LOC64 = nimIntToStr((*sym0).Sup.id); LOC63 = rawNewString((*(*sym0).name).s->Sup.len + LOC64->Sup.len + 21); appendString(LOC63, ((NimStringDesc*) &T839829468_289)); appendString(LOC63, (*(*sym0).name).s); appendString(LOC63, ((NimStringDesc*) &T839829468_12)); appendString(LOC63, LOC64); internalerror_198100_155036129((*n0).info, LOC63); } LA61: ; putlocintodest_541258_839829468(p0, d0, (*sym0).loc); } break; case ((Tsymkind294435) 3): { { NIM_BOOL LOC68; NimStringDesc* LOC72; NimStringDesc* LOC73; LOC68 = (NIM_BOOL)0; LOC68 = ((*sym0).loc.r == NIM_NIL); if (LOC68) goto LA69; LOC68 = ((*sym0).loc.t == NIM_NIL); LA69: ; if (!LOC68) goto LA70; LOC72 = (NimStringDesc*)0; LOC73 = (NimStringDesc*)0; LOC73 = nimIntToStr((*sym0).Sup.id); LOC72 = rawNewString((*(*sym0).name).s->Sup.len + LOC73->Sup.len + 22); appendString(LOC72, ((NimStringDesc*) &T839829468_290)); appendString(LOC72, (*(*sym0).name).s); appendString(LOC72, ((NimStringDesc*) &T839829468_12)); appendString(LOC72, LOC73); internalerror_198100_155036129((*n0).info, LOC72); } LA70: ; putlocintodest_541258_839829468(p0, d0, (*sym0).loc); } break; default: { NimStringDesc* LOC75; LOC75 = (NimStringDesc*)0; LOC75 = rawNewString(reprEnum((NI)(*sym0).kind, (&NTI294435))->Sup.len + 22); appendString(LOC75, ((NimStringDesc*) &T839829468_291)); appendString(LOC75, reprEnum((NI)(*sym0).kind, (&NTI294435))); appendString(LOC75, ((NimStringDesc*) &T839829468_292)); internalerror_198100_155036129((*n0).info, LOC75); } break; } } break; case ((Tnodekind294020) 23): { { NIM_BOOL LOC79; Ropeobj180006* LOC82; LOC79 = (NIM_BOOL)0; LOC79 = isemptytype_299440_850551059((*n0).typ); if (!!(LOC79)) goto LA80; LOC82 = (Ropeobj180006*)0; LOC82 = genliteral_541273_839829468(p0, n0); putintodest_552468_839829468(p0, d0, (*n0).typ, LOC82, ((Tstorageloc294812) 0)); } LA80: ; } break; case ((Tnodekind294020) 20) ... ((Tnodekind294020) 22): { Ropeobj180006* LOC84; LOC84 = (Ropeobj180006*)0; LOC84 = genliteral_541273_839829468(p0, n0); putdataintodest_552436_839829468(p0, d0, (*n0).typ, LOC84); } break; case ((Tnodekind294020) 6) ... ((Tnodekind294020) 15): case ((Tnodekind294020) 16) ... ((Tnodekind294020) 19): case ((Tnodekind294020) 5): { Ropeobj180006* LOC86; LOC86 = (Ropeobj180006*)0; LOC86 = genliteral_541273_839829468(p0, n0); putintodest_552468_839829468(p0, d0, (*n0).typ, LOC86, ((Tstorageloc294812) 0)); } break; case ((Tnodekind294020) 27): case ((Tnodekind294020) 32): case ((Tnodekind294020) 29): case ((Tnodekind294020) 30): case ((Tnodekind294020) 31): case ((Tnodekind294020) 26): case ((Tnodekind294020) 28): { Tnode294802* op0; genlinedir_534823_839829468(p0, n0); op0 = (*n0).kindU.S6.sons->data[((NI) 0)]; { Tloc294816 a0; if (!(*n0).typ == 0) goto LA90; memset((void*)(&a0), 0, sizeof(a0)); { NIM_BOOL LOC94; LOC94 = (NIM_BOOL)0; LOC94 = ((*op0).kind == ((Tnodekind294020) 3)); if (!(LOC94)) goto LA95; LOC94 = !(((*(*op0).kindU.S4.sym).magic == ((Tmagic294524) 0))); LA95: ; if (!LOC94) goto LA96; genmagicexpr_559033_839829468(p0, n0, (&a0), (*(*op0).kindU.S4.sym).magic); } goto LA92; LA96: ; { gencall_545632_839829468(p0, n0, (&a0)); } LA92: ; } goto LA88; LA90: ; { { NIM_BOOL LOC102; LOC102 = (NIM_BOOL)0; LOC102 = ((*op0).kind == ((Tnodekind294020) 3)); if (!(LOC102)) goto LA103; LOC102 = !(((*(*op0).kindU.S4.sym).magic == ((Tmagic294524) 0))); LA103: ; if (!LOC102) goto LA104; genmagicexpr_559033_839829468(p0, n0, d0, (*(*op0).kindU.S4.sym).magic); } goto LA100; LA104: ; { gencall_545632_839829468(p0, n0, d0); } LA100: ; } LA88: ; } break; case ((Tnodekind294020) 39): { { NIM_BOOL LOC110; NI LOC112; Ropeobj180006* LOC115; LOC110 = (NIM_BOOL)0; LOC110 = isdeepconstexpr_320566_2616423590(n0); if (!(LOC110)) goto LA111; LOC112 = (NI)0; LOC112 = len_295081_850551059(n0); LOC110 = !((LOC112 == ((NI) 0))); LA111: ; if (!LOC110) goto LA113; LOC115 = (Ropeobj180006*)0; LOC115 = gensetnode_551664_839829468(p0, n0); putintodest_552468_839829468(p0, d0, (*n0).typ, LOC115, ((Tstorageloc294812) 0)); } goto LA108; LA113: ; { gensetconstr_559496_839829468(p0, n0, d0); } LA108: ; } break; case ((Tnodekind294020) 41): { { NIM_BOOL LOC120; NI LOC122; LOC120 = (NIM_BOOL)0; LOC120 = isdeepconstexpr_320566_2616423590(n0); if (!(LOC120)) goto LA121; LOC122 = (NI)0; LOC122 = len_295081_850551059(n0); LOC120 = !((LOC122 == ((NI) 0))); LA121: ; if (!LOC120) goto LA123; exprcomplexconst_560684_839829468(p0, n0, d0); } goto LA118; LA123: ; { Ttype294840* LOC126; LOC126 = (Ttype294840*)0; LOC126 = skiptypes_298099_850551059((*n0).typ, IL64(211106242013440)); if (!((*LOC126).kind == ((Ttypekind294244) 24))) goto LA127; genseqconstr_557004_839829468(p0, n0, d0); } goto LA118; LA127: ; { genarrayconstr_560207_839829468(p0, n0, d0); } LA118: ; } break; case ((Tnodekind294020) 37): { { NIM_BOOL LOC133; NI LOC135; LOC133 = (NIM_BOOL)0; LOC133 = isdeepconstexpr_320566_2616423590(n0); if (!(LOC133)) goto LA134; LOC135 = (NI)0; LOC135 = len_295081_850551059(n0); LOC133 = !((LOC135 == ((NI) 0))); LA134: ; if (!LOC133) goto LA136; exprcomplexconst_560684_839829468(p0, n0, d0); } goto LA131; LA136: ; { gentupleconstr_559618_839829468(p0, n0, d0); } LA131: ; } break; case ((Tnodekind294020) 38): { genobjconstr_556903_839829468(p0, n0, d0); } break; case ((Tnodekind294020) 61): { gencast_558537_839829468(p0, n0, d0); } break; case ((Tnodekind294020) 58): case ((Tnodekind294020) 59): case ((Tnodekind294020) 60): { genconv_558632_839829468(p0, n0, d0); } break; case ((Tnodekind294020) 64): case ((Tnodekind294020) 63): { genaddr_555051_839829468(p0, n0, d0); } break; case ((Tnodekind294020) 42): { genbracketexpr_556277_839829468(p0, n0, d0); } break; case ((Tnodekind294020) 47): case ((Tnodekind294020) 65): { genderef_545921_839829468(p0, n0, d0, NIM_FALSE); } break; case ((Tnodekind294020) 45): { genrecordfield_555448_839829468(p0, n0, d0); } break; case ((Tnodekind294020) 46): { gencheckedrecordfield_556046_839829468(p0, n0, d0); } break; case ((Tnodekind294020) 127): case ((Tnodekind294020) 112): { genblock_548083_839829468(p0, n0, d0); } break; case ((Tnodekind294020) 126): { genstmtlistexpr_560402_839829468(p0, n0, d0); } break; case ((Tnodekind294020) 115): { { NI i_561023_839829468; NI HEX3Atmp_561276_839829468; NI LOC151; NI res_561279_839829468; i_561023_839829468 = (NI)0; HEX3Atmp_561276_839829468 = (NI)0; LOC151 = (NI)0; LOC151 = sonslen_297351_850551059(n0); HEX3Atmp_561276_839829468 = (NI)(LOC151 - ((NI) 1)); res_561279_839829468 = ((NI) 0); { while (1) { if (!(res_561279_839829468 <= HEX3Atmp_561276_839829468)) goto LA153; i_561023_839829468 = res_561279_839829468; genstmts_541244_839829468(p0, (*n0).kindU.S6.sons->data[i_561023_839829468]); res_561279_839829468 += ((NI) 1); } LA153: ; } } } break; case ((Tnodekind294020) 48): case ((Tnodekind294020) 92): { genif_546982_839829468(p0, n0, d0); } break; case ((Tnodekind294020) 93): { expr_541248_839829468(p0, (*(*n0).kindU.S6.sons->data[((NI) 1)]).kindU.S6.sons->data[((NI) 0)], d0); } break; case ((Tnodekind294020) 66): { downconv_560581_839829468(p0, n0, d0); } break; case ((Tnodekind294020) 67): { upconv_560431_839829468(p0, n0, d0); } break; case ((Tnodekind294020) 68): { genrangechck_558590_839829468(p0, n0, d0, ((NimStringDesc*) &T839829468_563)); } break; case ((Tnodekind294020) 69): { genrangechck_558590_839829468(p0, n0, d0, ((NimStringDesc*) &T839829468_564)); } break; case ((Tnodekind294020) 70): { genrangechck_558590_839829468(p0, n0, d0, ((NimStringDesc*) &T839829468_565)); } break; case ((Tnodekind294020) 71): { convstrtocstr_558642_839829468(p0, n0, d0); } break; case ((Tnodekind294020) 72): { convcstrtostr_558654_839829468(p0, n0, d0); } break; case ((Tnodekind294020) 51): case ((Tnodekind294020) 52): { Tsym294834* sym0; sym0 = (*(*n0).kindU.S6.sons->data[((NI) 0)]).kindU.S4.sym; genproc_534951_839829468((*p0).module, sym0); { NIM_BOOL LOC166; NimStringDesc* LOC170; LOC166 = (NIM_BOOL)0; LOC166 = ((*sym0).loc.r == NIM_NIL); if (LOC166) goto LA167; LOC166 = ((*sym0).loc.t == NIM_NIL); LA167: ; if (!LOC166) goto LA168; LOC170 = (NimStringDesc*)0; LOC170 = rawNewString((*(*sym0).name).s->Sup.len + 20); appendString(LOC170, ((NimStringDesc*) &T839829468_271)); appendString(LOC170, (*(*sym0).name).s); internalerror_198100_155036129((*n0).info, LOC170); } LA168: ; putlocintodest_541258_839829468(p0, d0, (*sym0).loc); } break; case ((Tnodekind294020) 155): { genclosure_559836_839829468(p0, n0, d0); } break; case ((Tnodekind294020) 1): { } break; case ((Tnodekind294020) 96): { genwhilestmt_547984_839829468(p0, n0); } break; case ((Tnodekind294020) 99): case ((Tnodekind294020) 100): { genvarstmt_546854_839829468(p0, n0); } break; case ((Tnodekind294020) 101): { genconststmt_546909_839829468(p0, n0); } break; case ((Tnodekind294020) 94): { internalerror_198100_155036129((*n0).info, ((NimStringDesc*) &T839829468_594)); } break; case ((Tnodekind294020) 97): { gencase_549826_839829468(p0, n0, d0); } break; case ((Tnodekind294020) 109): { genreturnstmt_547617_839829468(p0, n0); } break; case ((Tnodekind294020) 110): { genbreakstmt_548444_839829468(p0, n0); } break; case ((Tnodekind294020) 73): { { if (!!((((*n0).flags &(1U<<((NU)(((Tnodeflag294427) 14))&15U)))!=0))) goto LA183; genasgn_551239_839829468(p0, n0, NIM_FALSE); } LA183: ; } break; case ((Tnodekind294020) 74): { { if (!!((((*n0).flags &(1U<<((NU)(((Tnodeflag294427) 14))&15U)))!=0))) goto LA188; genasgn_551239_839829468(p0, n0, !(((*p0).prc == NIM_NIL))); } LA188: ; } break; case ((Tnodekind294020) 114): { { Tloc294816 a0; if (!!(((*(*n0).kindU.S6.sons->data[((NI) 0)]).kind == ((Tnodekind294020) 1)))) goto LA193; genlinedir_534823_839829468(p0, n0); memset((void*)(&a0), 0, sizeof(a0)); initlocexpr_541283_839829468(p0, (*n0).kindU.S6.sons->data[((NI) 0)], (&a0)); } LA193: ; } break; case ((Tnodekind294020) 89): { genasmstmt_550659_839829468(p0, n0); } break; case ((Tnodekind294020) 106): { { NIM_BOOL LOC199; NIM_BOOL LOC200; LOC199 = (NIM_BOOL)0; LOC200 = (NIM_BOOL)0; LOC200 = (gcmd_171132_2607990831 == ((Tcommands171076) 2)); if (LOC200) goto LA201; LOC200 = (((*(*(*p0).module).module).flags &(1U<<((NU)(((Tsymflag294184) 27))&31U)))!=0); LA201: ; LOC199 = LOC200; if (!(LOC199)) goto LA202; LOC199 = !(((gglobaloptions_171130_2607990831 &((NU64)1<<((NU)(((Tglobaloption171013) 31))&63U)))!=0)); LA202: ; if (!LOC199) goto LA203; gentrycpp_549865_839829468(p0, n0, d0); } goto LA197; LA203: ; { gentry_550114_839829468(p0, n0, d0); } LA197: ; } break; case ((Tnodekind294020) 108): { genraisestmt_548828_839829468(p0, n0); } break; case ((Tnodekind294020) 98): { gentypesection_540184_839829468((*p0).module, n0); } break; case ((Tnodekind294020) 125): case ((Tnodekind294020) 84): case ((Tnodekind294020) 121): case ((Tnodekind294020) 116): case ((Tnodekind294020) 117): case ((Tnodekind294020) 118): case ((Tnodekind294020) 119): case ((Tnodekind294020) 120): case ((Tnodekind294020) 83): case ((Tnodekind294020) 82): { } break; case ((Tnodekind294020) 90): { genpragma_551039_839829468(p0, n0); } break; case ((Tnodekind294020) 91): { Tnode294802* LOC211; LOC211 = (Tnode294802*)0; LOC211 = lastson_297364_850551059(n0); expr_541248_839829468(p0, LOC211, d0); } break; case ((Tnodekind294020) 79): case ((Tnodekind294020) 80): case ((Tnodekind294020) 81): { { Tsym294834* prc0; if (!((*(*n0).kindU.S6.sons->data[((NI) 2)]).kind == ((Tnodekind294020) 1))) goto LA215; prc0 = (*(*n0).kindU.S6.sons->data[((NI) 0)]).kindU.S4.sym; { NIM_BOOL LOC219; Tsym294834* LOC220; LOC219 = (NIM_BOOL)0; LOC220 = (Tsym294834*)0; LOC220 = skipgenericowner_299279_850551059(prc0); LOC219 = ((*LOC220).kind == ((Tsymkind294435) 6)); if (!(LOC219)) goto LA221; LOC219 = !((((*prc0).flags &(1U<<((NU)(((Tsymflag294184) 23))&31U)))!=0)); LA221: ; if (!LOC219) goto LA222; { NIM_BOOL LOC226; NIM_BOOL LOC227; NIM_BOOL LOC228; NIM_BOOL LOC229; Tsym294834* LOC231; NIM_BOOL LOC234; LOC226 = (NIM_BOOL)0; LOC227 = (NIM_BOOL)0; LOC228 = (NIM_BOOL)0; LOC229 = (NIM_BOOL)0; LOC229 = !(((gglobaloptions_171130_2607990831 &((NU64)1<<((NU)(((Tglobaloption171013) 2))&63U)))!=0)); if (!(LOC229)) goto LA230; LOC231 = (Tsym294834*)0; LOC231 = getmodule_301123_2984716966(prc0); LOC229 = !((((*LOC231).flags &(1U<<((NU)(((Tsymflag294184) 25))&31U)))!=0)); LA230: ; LOC228 = LOC229; if (LOC228) goto LA232; LOC228 = ((65600 & (*prc0).flags) == 64); LA232: ; LOC227 = LOC228; if (LOC227) goto LA233; LOC234 = (NIM_BOOL)0; LOC234 = (((*prc0).flags &(1U<<((NU)(((Tsymflag294184) 6))&31U)))!=0); if (!(LOC234)) goto LA235; LOC234 = (((*prc0).loc.flags &(1U<<((NU)(((Tlocflag294810) 5))&15U)))!=0); LA235: ; LOC227 = LOC234; LA233: ; LOC226 = LOC227; if (LOC226) goto LA236; LOC226 = ((*prc0).kind == ((Tsymkind294435) 13)); LA236: ; if (!LOC226) goto LA237; { NIM_BOOL LOC241; Tnode294802* LOC242; LOC241 = (NIM_BOOL)0; LOC242 = (Tnode294802*)0; LOC242 = getbody_337227_1724185294(prc0); LOC241 = !(((*LOC242).kind == ((Tnodekind294020) 1))); if (LOC241) goto LA243; LOC241 = (((*prc0).loc.flags &(1U<<((NU)(((Tlocflag294810) 4))&15U)))!=0); LA243: ; if (!LOC241) goto LA244; genproc_534951_839829468((*p0).module, prc0); } LA244: ; } LA237: ; } LA222: ; } LA215: ; } break; case ((Tnodekind294020) 95): { genparforstmt_548208_839829468(p0, n0); } break; case ((Tnodekind294020) 157): { genstate_546117_839829468(p0, n0); } break; case ((Tnodekind294020) 156): { gengotostate_546144_839829468(p0, n0); } break; case ((Tnodekind294020) 158): { genbreakstate_546229_839829468(p0, n0); } break; default: { NimStringDesc* LOC251; LOC251 = (NimStringDesc*)0; LOC251 = rawNewString(reprEnum((NI)(*n0).kind, (&NTI294020))->Sup.len + 25); appendString(LOC251, ((NimStringDesc*) &T839829468_291)); appendString(LOC251, reprEnum((NI)(*n0).kind, (&NTI294020))); appendString(LOC251, ((NimStringDesc*) &T839829468_657)); internalerror_198100_155036129((*n0).info, LOC251); } break; } } N_NIMCALL(void, genstmts_541244_839829468)(Tcproc531021* p0, Tnode294802* t0) { Tloc294816 a0; memset((void*)(&a0), 0, sizeof(a0)); expr_541248_839829468(p0, t0, (&a0)); { NimStringDesc* LOC5; if (!!(((7 &(1U<<((NU)(a0.k)&15U)))!=0))) goto LA3; LOC5 = (NimStringDesc*)0; LOC5 = HEX24_198185_1689653243(T839829468_658); internalerror_198113_155036129(LOC5); } LA3: ; } N_NIMCALL(Tnode294802*, myprocess_565402_839829468)(Tpasscontext343002* b0, Tnode294802* n0) { Tnode294802* result0; Tcgen531027* m0; { result0 = (Tnode294802*)0; result0 = n0; { NIM_BOOL LOC3; LOC3 = (NIM_BOOL)0; LOC3 = (b0 == NIM_NIL); if (LOC3) goto LA4; LOC3 = skipcodegen_343085_2355241294(n0); LA4: ; if (!LOC3) goto LA5; goto BeforeRet; } LA5: ; m0 = ((Tcgen531027*) (b0)); (*(*m0).initproc).options = initprocoptions_564635_839829468(m0); genstmts_541244_839829468((*m0).initproc, n0); }BeforeRet: ; return result0; } N_NIMCALL(Ropeobj180006*, getsomeinitname_563904_839829468)(Tsym294834* m0, NimStringDesc* suffix0) { Ropeobj180006* result0; result0 = (Ropeobj180006*)0; { NimStringDesc* LOC5; if (!((12288 & (*m0).flags) == 0)) goto LA3; LOC5 = (NimStringDesc*)0; LOC5 = mangle_530847_2036603609((*(*(*m0).owner).name).s); result0 = rope_180277_2381377266(LOC5); add_180487_2381377266(&result0, ((NimStringDesc*) &T839829468_12)); } LA3: ; add_180487_2381377266(&result0, (*(*m0).name).s); add_180487_2381377266(&result0, suffix0); return result0; } N_NIMCALL(Ropeobj180006*, getinitname_564235_839829468)(Tsym294834* m0) { Ropeobj180006* result0; result0 = (Ropeobj180006*)0; result0 = getsomeinitname_563904_839829468(m0, ((NimStringDesc*) &T839829468_659)); return result0; } N_NIMCALL(Ropeobj180006*, getdatinitname_564239_839829468)(Tsym294834* m0) { Ropeobj180006* result0; result0 = (Ropeobj180006*)0; result0 = getsomeinitname_563904_839829468(m0, ((NimStringDesc*) &T839829468_660)); return result0; } N_NIMCALL(void, registermoduletomain_564243_839829468)(Tsym294834* m0) { Ropeobj180006* init0; Ropeobj180006* datinit0; TY180507 LOC1; TY180507 LOC2; init0 = getinitname_564235_839829468(m0); datinit0 = getdatinitname_564239_839829468(m0); memset((void*)LOC1, 0, sizeof(LOC1)); LOC1[0] = init0; addf_181205_2381377266(&mainmodprocs_531148_3723162438, ((NimStringDesc*) &T839829468_661), LOC1, 1); memset((void*)LOC2, 0, sizeof(LOC2)); LOC2[0] = datinit0; addf_181205_2381377266(&mainmodprocs_531148_3723162438, ((NimStringDesc*) &T839829468_661), LOC2, 1); { TY180507 LOC7; Ropeobj180006* initcall0; TY180507 LOC8; if (!!((((*m0).flags &(1U<<((NU)(((Tsymflag294184) 13))&31U)))!=0))) goto LA5; memset((void*)LOC7, 0, sizeof(LOC7)); LOC7[0] = datinit0; addf_181205_2381377266(&maindatinit_531151_3723162438, ((NimStringDesc*) &T839829468_662), LOC7, 1); memset((void*)LOC8, 0, sizeof(LOC8)); LOC8[0] = init0; initcall0 = HEX25_180905_2381377266(((NimStringDesc*) &T839829468_662), LOC8, 1); { if (!(((*m0).flags &(1U<<((NU)(((Tsymflag294184) 12))&31U)))!=0)) goto LA11; add_180482_2381377266(&mainmodinit_531149_3723162438, initcall0); } goto LA9; LA11: ; { add_180482_2381377266(&othermodsinit_531150_3723162438, initcall0); } LA9: ; } LA5: ; } N_NIMCALL(Ropeobj180006*, genfilenames_563688_839829468)(Tcgen531027* m0) { Ropeobj180006* result0; Ropeobj180006* LOC1; result0 = (Ropeobj180006*)0; LOC1 = (Ropeobj180006*)0; LOC1 = cgsym_534403_839829468(m0, ((NimStringDesc*) &T839829468_673)); result0 = NIM_NIL; { NI i_563717_839829468; NI HEX3Atmp_563722_839829468; NI res_563725_839829468; i_563717_839829468 = (NI)0; HEX3Atmp_563722_839829468 = (NI)0; HEX3Atmp_563722_839829468 = ((fileinfos_193629_155036129 ? fileinfos_193629_155036129->Sup.len : 0) - 1); res_563725_839829468 = ((NI) 0); { while (1) { TY180507 LOC5; if (!(res_563725_839829468 <= HEX3Atmp_563722_839829468)) goto LA4; i_563717_839829468 = res_563725_839829468; memset((void*)LOC5, 0, sizeof(LOC5)); LOC5[0] = makecstring_193638_155036129(fileinfos_193629_155036129->data[i_563717_839829468].projpath); addf_181205_2381377266(&result0, ((NimStringDesc*) &T839829468_674), LOC5, 1); res_563725_839829468 += ((NI) 1); } LA4: ; } } return result0; } N_NIMCALL(void, genmainproc_563729_839829468)(Tcgen531027* m0) { NimStringDesc* nimmain0; NimStringDesc* othermain0; Ropeobj180006* initstackbottomcall0; TY538475 LOC38; TY537238 LOC47; nimmain0 = (NimStringDesc*)0; othermain0 = (NimStringDesc*)0; { NIM_BOOL LOC3; NIM_BOOL LOC12; LOC3 = (NIM_BOOL)0; LOC3 = (targetos_178629_4151366050 == ((Tsystemos178004) 2)); if (!(LOC3)) goto LA4; LOC3 = !(((gglobaloptions_171130_2607990831 & 1280) == 0)); LA4: ; if (!LOC3) goto LA5; { if (!((gglobaloptions_171130_2607990831 &((NU64)1<<((NU)(((Tglobaloption171013) 10))&63U)))!=0)) goto LA9; nimmain0 = copyString(((NimStringDesc*) &T839829468_663)); othermain0 = copyString(((NimStringDesc*) &T839829468_664)); } goto LA7; LA9: ; { nimmain0 = copyString(((NimStringDesc*) &T839829468_665)); othermain0 = copyString(((NimStringDesc*) &T839829468_666)); } LA7: ; LOC12 = (NIM_BOOL)0; LOC12 = includestr_148249_3771138726((&(*m0).headerfiles), ((NimStringDesc*) &T839829468_667)); } goto LA1; LA5: ; { if (!((gglobaloptions_171130_2607990831 &((NU64)1<<((NU)(((Tglobaloption171013) 8))&63U)))!=0)) goto LA14; nimmain0 = copyString(((NimStringDesc*) &T839829468_665)); othermain0 = copyString(((NimStringDesc*) &T839829468_668)); } goto LA1; LA14: ; { if (!(targetos_178629_4151366050 == ((Tsystemos178004) 24))) goto LA17; nimmain0 = copyString(((NimStringDesc*) &T839829468_669)); othermain0 = copyString(((NimStringDesc*) &T839829468_670)); } goto LA1; LA17: ; { nimmain0 = copyString(((NimStringDesc*) &T839829468_669)); othermain0 = copyString(((NimStringDesc*) &T839829468_671)); } LA1: ; { Ropeobj180006* LOC24; if (!!((gbreakpoints_550861_839829468 == NIM_NIL))) goto LA22; LOC24 = (Ropeobj180006*)0; LOC24 = cgsym_534403_839829468(m0, ((NimStringDesc*) &T839829468_672)); } LA22: ; { Ropeobj180006* LOC29; if (!((goptions_171128_2607990831 &(1U<<((NU)(((Toption171009) 17))&31U)))!=0)) goto LA27; LOC29 = (Ropeobj180006*)0; LOC29 = genfilenames_563688_839829468(m0); add_180482_2381377266(&gbreakpoints_550861_839829468, LOC29); } LA27: ; { NIM_BOOL LOC32; LOC32 = (NIM_BOOL)0; LOC32 = (targetos_178629_4151366050 == ((Tsystemos178004) 24)); if (LOC32) goto LA33; LOC32 = (gselectedgc_171133_2607990831 == ((Tgcmode171080) 0)); LA33: ; if (!LOC32) goto LA34; initstackbottomcall0 = rope_180277_2381377266(((NimStringDesc*) &T839829468_490)); } goto LA30; LA34: ; { TY535289 LOC37; memset((void*)LOC37, 0, sizeof(LOC37)); initstackbottomcall0 = ropecg_534407_839829468(m0, ((NimStringDesc*) &T839829468_675), LOC37, 0); } LA30: ; (*m0).labels += ((NI) 1); memset((void*)LOC38, 0, sizeof(LOC38)); LOC38[0] = maindatinit_531151_3723162438; LOC38[1] = gbreakpoints_550861_839829468; LOC38[2] = othermodsinit_531150_3723162438; { NIM_BOOL LOC41; TY535289 LOC45; LOC41 = (NIM_BOOL)0; LOC41 = emulatedthreadvars_534949_839829468(); if (!(LOC41)) goto LA42; LOC41 = !((targetos_178629_4151366050 == ((Tsystemos178004) 24))); LA42: ; if (!LOC41) goto LA43; memset((void*)LOC45, 0, sizeof(LOC45)); LOC38[3] = ropecg_534407_839829468(m0, ((NimStringDesc*) &T839829468_677), LOC45, 0); } goto LA39; LA43: ; { LOC38[3] = rope_180277_2381377266(((NimStringDesc*) &T839829468_490)); } LA39: ; LOC38[4] = initstackbottomcall0; appcg_534632_839829468(m0, &(*m0).s[(((Tcfilesection531005) 10))- 0], ((NimStringDesc*) &T839829468_676), LOC38, 5); memset((void*)LOC47, 0, sizeof(LOC47)); LOC47[0] = mainmodinit_531149_3723162438; LOC47[1] = initstackbottomcall0; LOC47[2] = rope_180401_2381377266(((NI64) ((*m0).labels))); appcg_534632_839829468(m0, &(*m0).s[(((Tcfilesection531005) 10))- 0], nimmain0, LOC47, 3); { TY535289 LOC52; if (!!(((gglobaloptions_171130_2607990831 &((NU64)1<<((NU)(((Tglobaloption171013) 20))&63U)))!=0))) goto LA50; memset((void*)LOC52, 0, sizeof(LOC52)); appcg_534632_839829468(m0, &(*m0).s[(((Tcfilesection531005) 10))- 0], othermain0, LOC52, 0); } LA50: ; } N_NIMCALL(Tnode294802*, myclose_565830_839829468)(Tpasscontext343002* b0, Tnode294802* n0) { Tnode294802* result0; Tcgen531027* m0; { result0 = (Tnode294802*)0; result0 = n0; { NIM_BOOL LOC3; LOC3 = (NIM_BOOL)0; LOC3 = (b0 == NIM_NIL); if (LOC3) goto LA4; LOC3 = skipcodegen_343085_2355241294(n0); LA4: ; if (!LOC3) goto LA5; goto BeforeRet; } LA5: ; m0 = ((Tcgen531027*) (b0)); { if (!!((n0 == NIM_NIL))) goto LA9; (*(*m0).initproc).options = initprocoptions_564635_839829468(m0); genstmts_541244_839829468((*m0).initproc, n0); } LA9: ; registermoduletomain_564243_839829468((*m0).module); { Tnode294802* disp0; if (!(((*(*m0).module).flags &(1U<<((NU)(((Tsymflag294184) 12))&31U)))!=0)) goto LA13; (*m0).flags |= ((NU8)1)<<((((Codegenflag531025) 5))%(sizeof(NU8)*8)); disp0 = generatemethoddispatchers_434151_3853300031(); { NI i_565891_839829468; NI HEX3Atmp_565895_839829468; NI LOC16; NI res_565898_839829468; i_565891_839829468 = (NI)0; HEX3Atmp_565895_839829468 = (NI)0; LOC16 = (NI)0; LOC16 = sonslen_297351_850551059(disp0); HEX3Atmp_565895_839829468 = (NI)(LOC16 - ((NI) 1)); res_565898_839829468 = ((NI) 0); { while (1) { if (!(res_565898_839829468 <= HEX3Atmp_565895_839829468)) goto LA18; i_565891_839829468 = res_565898_839829468; genprocaux_562284_839829468(m0, (*(*disp0).kindU.S6.sons->data[i_565891_839829468]).kindU.S4.sym); res_565898_839829468 += ((NI) 1); } LA18: ; } } genmainproc_563729_839829468(m0); } LA13: ; }BeforeRet: ; return result0; } N_NIMCALL(void, finishmodule_565420_839829468)(Tcgen531027* m0) { NI i0; i0 = ((NI) 0); { while (1) { Tsym294834* prc0; if (!(i0 <= ((*m0).forwardedprocs ? ((*m0).forwardedprocs->Sup.len-1) : -1))) goto LA2; prc0 = (*m0).forwardedprocs->data[i0]; { NimStringDesc* LOC7; if (!(((*prc0).flags &(1U<<((NU)(((Tsymflag294184) 4))&31U)))!=0)) goto LA5; LOC7 = (NimStringDesc*)0; LOC7 = rawNewString((*(*prc0).name).s->Sup.len + 17); appendString(LOC7, ((NimStringDesc*) &T839829468_678)); appendString(LOC7, (*(*prc0).name).s); internalerror_198100_155036129((*prc0).info, LOC7); } LA5: ; genprocnoforward_562906_839829468(m0, prc0); i0 += ((NI) 1); } LA2: ; } gforwardedprocscounter_531171_3723162438 -= i0; (*m0).forwardedprocs = (Tsymseq294804*) setLengthSeq(&((*m0).forwardedprocs)->Sup, sizeof(Tsym294834*), ((NI) 0)); } N_NIMCALL(void, geninitcode_564286_839829468)(Tcgen531027* m0) { Ropeobj180006* initname0; Ropeobj180006* prc0; TY180507 LOC1; Ropeobj180006* LOC12; Ropeobj180006* LOC13; Ropeobj180006** LOC14; Ropeobj180006** LOC15; Ropeobj180006** LOC16; Ropeobj180006* LOC17; Ropeobj180006* LOC33; Ropeobj180006** LOC34; Ropeobj180006** LOC35; Ropeobj180006** LOC36; Ropeobj180006* LOC37; Ropeobj180006* LOC38; Ropeobj180006** LOC39; Ropeobj180006** LOC40; Ropeobj180006** LOC41; Ropeobj180006* LOC42; Ropeobj180006* LOC50; TY535289 LOC51; TY180507 LOC52; TY535289 LOC58; initname0 = getinitname_564235_839829468((*m0).module); memset((void*)LOC1, 0, sizeof(LOC1)); LOC1[0] = initname0; prc0 = HEX25_180905_2381377266(((NimStringDesc*) &T839829468_679), LOC1, 1); { TY534811 LOC6; if (!(((NI) 0) < (*m0).typenodes)) goto LA4; memset((void*)LOC6, 0, sizeof(LOC6)); LOC6[0] = (*m0).typenodesname; LOC6[1] = rope_180401_2381377266(((NI64) ((*m0).typenodes))); appcg_534632_839829468(m0, &(*m0).s[(((Tcfilesection531005) 12))- 0], ((NimStringDesc*) &T839829468_680), LOC6, 2); } LA4: ; { TY534811 LOC11; if (!(((NI) 0) < (*m0).nimtypes)) goto LA9; memset((void*)LOC11, 0, sizeof(LOC11)); LOC11[0] = (*m0).nimtypesname; LOC11[1] = rope_180401_2381377266(((NI64) ((*m0).nimtypes))); appcg_534632_839829468(m0, &(*m0).s[(((Tcfilesection531005) 12))- 0], ((NimStringDesc*) &T839829468_681), LOC11, 2); } LA9: ; LOC12 = (Ropeobj180006*)0; LOC12 = initgcframe_540435_839829468((*m0).initproc); add_180482_2381377266(&prc0, LOC12); LOC13 = (Ropeobj180006*)0; LOC13 = gensectionstart_532081_2760143328(((Tcprocsection531011) 0)); add_180482_2381377266(&prc0, LOC13); LOC14 = (Ropeobj180006**)0; LOC14 = s_531179_3723162438((*m0).preinitproc, ((Tcprocsection531011) 0)); add_180482_2381377266(&prc0, (*LOC14)); LOC15 = (Ropeobj180006**)0; LOC15 = s_531179_3723162438((*m0).initproc, ((Tcprocsection531011) 0)); add_180482_2381377266(&prc0, (*LOC15)); LOC16 = (Ropeobj180006**)0; LOC16 = s_531179_3723162438((*m0).postinitproc, ((Tcprocsection531011) 0)); add_180482_2381377266(&prc0, (*LOC16)); LOC17 = (Ropeobj180006*)0; LOC17 = gensectionend_532116_2760143328(((Tcprocsection531011) 0)); add_180482_2381377266(&prc0, LOC17); { NIM_BOOL LOC20; LOC20 = (NIM_BOOL)0; LOC20 = (((*(*m0).initproc).options &(1U<<((NU)(((Toption171009) 15))&31U)))!=0); if (!(LOC20)) goto LA21; LOC20 = !((((*m0).flags &(1U<<((NU)(((Codegenflag531025) 2))&7U)))!=0)); LA21: ; if (!LOC20) goto LA22; (*m0).flags |= ((NU8)1)<<((((Codegenflag531025) 2))%(sizeof(NU8)*8)); { Ropeobj180006* procname0; Ropeobj180006* LOC28; Ropeobj180006* LOC29; if (!!((((*m0).flags &(1U<<((NU)(((Codegenflag531025) 0))&7U)))!=0))) goto LA26; procname0 = makecstring_193638_155036129((*(*(*m0).module).name).s); LOC28 = (Ropeobj180006*)0; LOC28 = quotedfilename_198818_155036129((*(*m0).module).info); LOC29 = (Ropeobj180006*)0; LOC29 = initframe_562140_839829468((*m0).initproc, procname0, LOC28); add_180482_2381377266(&prc0, LOC29); } goto LA24; LA26: ; { TY535289 LOC31; Ropeobj180006* LOC32; memset((void*)LOC31, 0, sizeof(LOC31)); LOC32 = (Ropeobj180006*)0; LOC32 = HEX25_180905_2381377266(((NimStringDesc*) &T839829468_682), LOC31, 0); add_180482_2381377266(&prc0, LOC32); } LA24: ; } LA22: ; LOC33 = (Ropeobj180006*)0; LOC33 = gensectionstart_532081_2760143328(((Tcprocsection531011) 1)); add_180482_2381377266(&prc0, LOC33); LOC34 = (Ropeobj180006**)0; LOC34 = s_531179_3723162438((*m0).preinitproc, ((Tcprocsection531011) 1)); add_180482_2381377266(&prc0, (*LOC34)); LOC35 = (Ropeobj180006**)0; LOC35 = s_531179_3723162438((*m0).initproc, ((Tcprocsection531011) 1)); add_180482_2381377266(&prc0, (*LOC35)); LOC36 = (Ropeobj180006**)0; LOC36 = s_531179_3723162438((*m0).postinitproc, ((Tcprocsection531011) 1)); add_180482_2381377266(&prc0, (*LOC36)); LOC37 = (Ropeobj180006*)0; LOC37 = gensectionend_532116_2760143328(((Tcprocsection531011) 1)); add_180482_2381377266(&prc0, LOC37); LOC38 = (Ropeobj180006*)0; LOC38 = gensectionstart_532081_2760143328(((Tcprocsection531011) 2)); add_180482_2381377266(&prc0, LOC38); LOC39 = (Ropeobj180006**)0; LOC39 = s_531179_3723162438((*m0).preinitproc, ((Tcprocsection531011) 2)); add_180482_2381377266(&prc0, (*LOC39)); LOC40 = (Ropeobj180006**)0; LOC40 = s_531179_3723162438((*m0).initproc, ((Tcprocsection531011) 2)); add_180482_2381377266(&prc0, (*LOC40)); LOC41 = (Ropeobj180006**)0; LOC41 = s_531179_3723162438((*m0).postinitproc, ((Tcprocsection531011) 2)); add_180482_2381377266(&prc0, (*LOC41)); LOC42 = (Ropeobj180006*)0; LOC42 = gensectionend_532116_2760143328(((Tcprocsection531011) 2)); add_180482_2381377266(&prc0, LOC42); { NIM_BOOL LOC45; Ropeobj180006* LOC49; LOC45 = (NIM_BOOL)0; LOC45 = (((*(*m0).initproc).options &(1U<<((NU)(((Toption171009) 15))&31U)))!=0); if (!(LOC45)) goto LA46; LOC45 = !((((*m0).flags &(1U<<((NU)(((Codegenflag531025) 0))&7U)))!=0)); LA46: ; if (!LOC45) goto LA47; LOC49 = (Ropeobj180006*)0; LOC49 = deinitframe_562150_839829468((*m0).initproc); add_180482_2381377266(&prc0, LOC49); } LA47: ; LOC50 = (Ropeobj180006*)0; LOC50 = deinitgcframe_540441_839829468((*m0).initproc); add_180482_2381377266(&prc0, LOC50); memset((void*)LOC51, 0, sizeof(LOC51)); addf_181205_2381377266(&prc0, ((NimStringDesc*) &T839829468_683), LOC51, 0); memset((void*)LOC52, 0, sizeof(LOC52)); LOC52[0] = getdatinitname_564239_839829468((*m0).module); addf_181205_2381377266(&prc0, ((NimStringDesc*) &T839829468_679), LOC52, 1); { Tcfilesection531005 i_564401_839829468; NI res_564482_839829468; i_564401_839829468 = (Tcfilesection531005)0; res_564482_839829468 = ((NI) 12); { while (1) { Ropeobj180006* LOC56; Ropeobj180006* LOC57; if (!(res_564482_839829468 <= ((NI) 16))) goto LA55; i_564401_839829468 = ((Tcfilesection531005) (res_564482_839829468)); LOC56 = (Ropeobj180006*)0; LOC56 = gensectionstart_532015_2760143328(i_564401_839829468); add_180482_2381377266(&prc0, LOC56); add_180482_2381377266(&prc0, (*m0).s[(i_564401_839829468)- 0]); LOC57 = (Ropeobj180006*)0; LOC57 = gensectionend_532050_2760143328(i_564401_839829468); add_180482_2381377266(&prc0, LOC57); res_564482_839829468 += ((NI) 1); } LA55: ; } } memset((void*)LOC58, 0, sizeof(LOC58)); addf_181205_2381377266(&prc0, ((NimStringDesc*) &T839829468_683), LOC58, 0); add_180482_2381377266(&(*m0).s[(((Tcfilesection531005) 11))- 0], prc0); { NIM_CHAR i_564442_839829468; Ropeobj180006* el_564443_839829468; TY531136 HEX3Atmp_564487_839829468; NIM_CHAR i_564490_839829468; i_564442_839829468 = (NIM_CHAR)0; el_564443_839829468 = (Ropeobj180006*)0; memset((void*)HEX3Atmp_564487_839829468, 0, sizeof(HEX3Atmp_564487_839829468)); memcpy((void*)HEX3Atmp_564487_839829468, (NIM_CONST void*)(*m0).extensionloaders, sizeof(HEX3Atmp_564487_839829468)); i_564490_839829468 = 48; { if (!((NU8)(((NIM_CHAR) (((NU8)(i_564490_839829468))))) <= (NU8)(57))) goto LA62; { while (1) { i_564442_839829468 = i_564490_839829468; el_564443_839829468 = HEX3Atmp_564487_839829468[(((NU8)(i_564490_839829468)))- 48]; { Ropeobj180006* ex0; TY534811 LOC70; if (!!((el_564443_839829468 == NIM_NIL))) goto LA68; memset((void*)LOC70, 0, sizeof(LOC70)); LOC70[0] = rope_180401_2381377266(((NI64) ((NI)(((NI) (((NU8)(i_564442_839829468)))) - ((NI) 48))))); LOC70[1] = el_564443_839829468; ex0 = HEX25_180905_2381377266(((NimStringDesc*) &T839829468_684), LOC70, 2); add_180482_2381377266(&(*m0).s[(((Tcfilesection531005) 11))- 0], ex0); } LA68: ; { if (!((NU8)(57) <= (NU8)(((NIM_CHAR) (((NU8)(i_564490_839829468))))))) goto LA73; goto LA64; } LA73: ; i_564490_839829468 += ((NI) 1); } } LA64: ; } LA62: ; } } N_NIMCALL(void, finishtypedescriptions_537842_839829468)(Tcgen531027* m0) { NI i0; i0 = ((NI) 0); { while (1) { Ropeobj180006* LOC3; if (!(i0 < ((*m0).typestack ? (*m0).typestack->Sup.len : 0))) goto LA2; LOC3 = (Ropeobj180006*)0; LOC3 = gettypedesc_537671_839829468(m0, (*m0).typestack->data[i0]); i0 += ((NI) 1); } LA2: ; } } N_NIMCALL(Ropeobj180006*, getcopyright_563665_839829468)(NimStringDesc* cfile0) { Ropeobj180006* result0; result0 = (Ropeobj180006*)0; { TY180507 LOC5; if (!((gglobaloptions_171130_2607990831 &((NU64)1<<((NU)(((Tglobaloption171013) 4))&63U)))!=0)) goto LA3; memset((void*)LOC5, 0, sizeof(LOC5)); LOC5[0] = rope_180277_2381377266(((NimStringDesc*) &T839829468_686)); result0 = HEX25_180905_2381377266(((NimStringDesc*) &T839829468_685), LOC5, 1); } goto LA1; LA3: ; { TY538475 LOC7; NimStringDesc* LOC8; memset((void*)LOC7, 0, sizeof(LOC7)); LOC7[0] = rope_180277_2381377266(((NimStringDesc*) &T839829468_686)); LOC7[1] = rope_180277_2381377266(Os_178068_4151366050[(targetos_178629_4151366050)- 1].Field0); LOC7[2] = rope_180277_2381377266(Cpu_178496_4151366050[(targetcpu_178627_4151366050)- 1].Field0); LOC7[3] = rope_180277_2381377266(Cc_275413_2528170400[(ccompiler_275431_2528170400)- 1].Field0); LOC8 = (NimStringDesc*)0; LOC8 = getcompilecfilecmd_276284_2528170400(cfile0, NIM_FALSE); LOC7[4] = rope_180277_2381377266(LOC8); result0 = HEX25_180905_2381377266(((NimStringDesc*) &T839829468_687), LOC7, 5); } LA1: ; return result0; } static N_INLINE(void, addinttypes_563659_839829468)(Ropeobj180006** result0) { NimStringDesc* LOC1; TY180507 LOC2; LOC1 = (NimStringDesc*)0; LOC1 = rawNewString(tnl_178644_4151366050->Sup.len + 22); appendString(LOC1, ((NimStringDesc*) &T839829468_688)); appendString(LOC1, tnl_178644_4151366050); memset((void*)LOC2, 0, sizeof(LOC2)); LOC2[0] = rope_180401_2381377266(((NI64) (Cpu_178496_4151366050[(targetcpu_178627_4151366050)- 1].Field1))); addf_181205_2381377266(result0, LOC1, LOC2, 1); } N_NIMCALL(Ropeobj180006*, getfileheader_563683_839829468)(NimStringDesc* cfile0) { Ropeobj180006* result0; result0 = (Ropeobj180006*)0; result0 = getcopyright_563665_839829468(cfile0); addinttypes_563659_839829468(&result0); return result0; } N_NIMCALL(void, generatethreadlocalstorage_540717_839829468)(Tcgen531027* m0) { { NIM_BOOL LOC3; NIM_BOOL LOC5; TY180507 LOC13; LOC3 = (NIM_BOOL)0; LOC3 = !((nimtv_540656_839829468 == NIM_NIL)); if (!(LOC3)) goto LA4; LOC5 = (NIM_BOOL)0; LOC5 = (((*m0).flags &(1U<<((NU)(((Codegenflag531025) 1))&7U)))!=0); if (LOC5) goto LA6; LOC5 = (((*(*m0).module).flags &(1U<<((NU)(((Tsymflag294184) 12))&31U)))!=0); LA6: ; LOC3 = LOC5; LA4: ; if (!LOC3) goto LA7; { Ttype294840* t_540761_839829468; NI i_540768_839829468; NI L_540770_839829468; t_540761_839829468 = (Ttype294840*)0; i_540768_839829468 = ((NI) 0); L_540770_839829468 = (nimtvdeps_540674_839829468 ? nimtvdeps_540674_839829468->Sup.len : 0); { while (1) { Ropeobj180006* LOC12; if (!(i_540768_839829468 < L_540770_839829468)) goto LA11; t_540761_839829468 = nimtvdeps_540674_839829468->data[i_540768_839829468]; LOC12 = (Ropeobj180006*)0; LOC12 = gettypedesc_537671_839829468(m0, t_540761_839829468); i_540768_839829468 += ((NI) 1); } LA11: ; } } memset((void*)LOC13, 0, sizeof(LOC13)); LOC13[0] = nimtv_540656_839829468; addf_181205_2381377266(&(*m0).s[(((Tcfilesection531005) 4))- 0], ((NimStringDesc*) &T839829468_689), LOC13, 1); } LA7: ; } N_NIMCALL(void, generateheaders_562104_839829468)(Tcgen531027* m0) { NimStringDesc* LOC1; Tstrentry148009* it0; LOC1 = (NimStringDesc*)0; LOC1 = rawNewString(tnl_178644_4151366050->Sup.len + tnl_178644_4151366050->Sup.len + 20); appendString(LOC1, tnl_178644_4151366050); appendString(LOC1, ((NimStringDesc*) &T839829468_690)); appendString(LOC1, tnl_178644_4151366050); add_180487_2381377266(&(*m0).s[(((Tcfilesection531005) 1))- 0], LOC1); it0 = ((Tstrentry148009*) ((*m0).headerfiles.head)); { while (1) { if (!!((it0 == NIM_NIL))) goto LA3; { NimStringDesc* LOC8; NimStringDesc* LOC9; Ropeobj180006* LOC10; if (!((NU8)((*it0).data->data[((NI) 0)]) == (NU8)(35))) goto LA6; LOC8 = (NimStringDesc*)0; LOC9 = (NimStringDesc*)0; LOC9 = nsuReplaceChar((*it0).data, 96, 34); LOC8 = rawNewString(LOC9->Sup.len + tnl_178644_4151366050->Sup.len + 0); appendString(LOC8, LOC9); appendString(LOC8, tnl_178644_4151366050); LOC10 = (Ropeobj180006*)0; LOC10 = rope_180277_2381377266(LOC8); add_180482_2381377266(&(*m0).s[(((Tcfilesection531005) 1))- 0], LOC10); } goto LA4; LA6: ; { TY180507 LOC14; if (!!((((NU8)((*it0).data->data[((NI) 0)])) == ((NU8)(34)) || ((NU8)((*it0).data->data[((NI) 0)])) == ((NU8)(60))))) goto LA12; memset((void*)LOC14, 0, sizeof(LOC14)); LOC14[0] = rope_180277_2381377266((*it0).data); addf_181205_2381377266(&(*m0).s[(((Tcfilesection531005) 1))- 0], ((NimStringDesc*) &T839829468_691), LOC14, 1); } goto LA4; LA12: ; { TY180507 LOC16; memset((void*)LOC16, 0, sizeof(LOC16)); LOC16[0] = rope_180277_2381377266((*it0).data); addf_181205_2381377266(&(*m0).s[(((Tcfilesection531005) 1))- 0], ((NimStringDesc*) &T839829468_692), LOC16, 1); } LA4: ; it0 = ((Tstrentry148009*) ((*it0).Sup.next)); } LA3: ; } } N_NIMCALL(Ropeobj180006*, genmodule_564491_839829468)(Tcgen531027* m0, NimStringDesc* cfile0) { Ropeobj180006* result0; Ropeobj180006* LOC1; result0 = (Ropeobj180006*)0; result0 = getfileheader_563683_839829468(cfile0); LOC1 = (Ropeobj180006*)0; LOC1 = genmergeinfo_532203_2760143328(m0); add_180482_2381377266(&result0, LOC1); generatethreadlocalstorage_540717_839829468(m0); generateheaders_562104_839829468(m0); { Tcfilesection531005 i_564614_839829468; NI res_564622_839829468; i_564614_839829468 = (Tcfilesection531005)0; res_564622_839829468 = ((NI) 1); { while (1) { Ropeobj180006* LOC5; Ropeobj180006* LOC6; if (!(res_564622_839829468 <= ((NI) 10))) goto LA4; i_564614_839829468 = ((Tcfilesection531005) (res_564622_839829468)); LOC5 = (Ropeobj180006*)0; LOC5 = gensectionstart_532015_2760143328(i_564614_839829468); add_180482_2381377266(&result0, LOC5); add_180482_2381377266(&result0, (*m0).s[(i_564614_839829468)- 0]); LOC6 = (Ropeobj180006*)0; LOC6 = gensectionend_532050_2760143328(i_564614_839829468); add_180482_2381377266(&result0, LOC6); res_564622_839829468 += ((NI) 1); } LA4: ; } } add_180482_2381377266(&result0, (*m0).s[(((Tcfilesection531005) 11))- 0]); return result0; } N_NIMCALL(void, updatecachedmodule_565813_839829468)(Tcgen531027* m0) { NimStringDesc* cfile0; NimStringDesc* cfilenoext0; cfile0 = getcfile_565204_839829468(m0); cfilenoext0 = noschangeFileExt(cfile0, ((NimStringDesc*) &T839829468_490)); { NIM_BOOL LOC3; Ropeobj180006* code0; LOC3 = (NIM_BOOL)0; LOC3 = mergerequired_532832_2760143328(m0); if (!(LOC3)) goto LA4; LOC3 = !((((*(*m0).module).flags &(1U<<((NU)(((Tsymflag294184) 12))&31U)))!=0)); LA4: ; if (!LOC3) goto LA5; mergefiles_533241_2760143328(cfile0, m0); geninitcode_564286_839829468(m0); finishtypedescriptions_537842_839829468(m0); code0 = genmodule_564491_839829468(m0, cfile0); writerope_180836_2381377266(code0, cfile0, NIM_FALSE); addfiletocompile_275863_2528170400(cfile0); } LA5: ; addfiletolink_275872_2528170400(cfilenoext0); } N_NIMCALL(void, generatethreadvarssize_540771_839829468)(Tcgen531027* m0) { { NimStringDesc* externc0; TY180507 LOC12; if (!!((nimtv_540656_839829468 == NIM_NIL))) goto LA3; { NIM_BOOL LOC7; LOC7 = (NIM_BOOL)0; LOC7 = !((gcmd_171132_2607990831 == ((Tcommands171076) 2))); if (!(LOC7)) goto LA8; LOC7 = (((*(*m0).module).flags &(1U<<((NU)(((Tsymflag294184) 27))&31U)))!=0); LA8: ; if (!LOC7) goto LA9; externc0 = copyString(((NimStringDesc*) &T839829468_693)); } goto LA5; LA9: ; { externc0 = copyString(((NimStringDesc*) &T839829468_490)); } LA5: ; memset((void*)LOC12, 0, sizeof(LOC12)); LOC12[0] = rope_180277_2381377266(externc0); addf_181205_2381377266(&(*m0).s[(((Tcfilesection531005) 10))- 0], ((NimStringDesc*) &T839829468_694), LOC12, 1); } LA3: ; } N_NIMCALL(NIM_BOOL, shouldrecompile_565621_839829468)(Ropeobj180006* code0, NimStringDesc* cfile0) { NIM_BOOL result0; { result0 = (NIM_BOOL)0; result0 = NIM_TRUE; { NimStringDesc* objfile0; if (!!(((gglobaloptions_171130_2607990831 &((NU64)1<<((NU)(((Tglobaloption171013) 1))&63U)))!=0))) goto LA3; objfile0 = toobjfile_275859_2528170400(cfile0); { NIM_BOOL LOC7; LOC7 = (NIM_BOOL)0; LOC7 = writeropeifnotequal_181511_2381377266(code0, cfile0); if (!LOC7) goto LA8; goto BeforeRet; } LA8: ; { NIM_BOOL LOC12; LOC12 = (NIM_BOOL)0; LOC12 = nosexistsFile(objfile0); if (!(LOC12)) goto LA13; LOC12 = nosfileNewer(objfile0, cfile0); LA13: ; if (!LOC12) goto LA14; result0 = NIM_FALSE; } LA14: ; } goto LA1; LA3: ; { writerope_180836_2381377266(code0, cfile0, NIM_FALSE); } LA1: ; }BeforeRet: ; return result0; } N_NIMCALL(void, writemodule_565637_839829468)(Tcgen531027* m0, NIM_BOOL pending0) { NimStringDesc* cfile0; NimStringDesc* cfilenoext0; cfile0 = getcfile_565204_839829468(m0); cfilenoext0 = noschangeFileExt(cfile0, ((NimStringDesc*) &T839829468_490)); { NIM_BOOL LOC3; Ropeobj180006* code0; LOC3 = (NIM_BOOL)0; LOC3 = !((*m0).Sup.fromcache); if (LOC3) goto LA4; LOC3 = ((gglobaloptions_171130_2607990831 &((NU64)1<<((NU)(((Tglobaloption171013) 1))&63U)))!=0); LA4: ; if (!LOC3) goto LA5; geninitcode_564286_839829468(m0); finishtypedescriptions_537842_839829468(m0); { if (!(((*(*m0).module).flags &(1U<<((NU)(((Tsymflag294184) 12))&31U)))!=0)) goto LA9; add_180482_2381377266(&(*m0).s[(((Tcfilesection531005) 7))- 0], mainmodprocs_531148_3723162438); generatethreadvarssize_540771_839829468(m0); } LA9: ; code0 = genmodule_564491_839829468(m0, cfile0); { NIM_BOOL LOC13; LOC13 = (NIM_BOOL)0; LOC13 = shouldrecompile_565621_839829468(code0, cfile0); if (!LOC13) goto LA14; addfiletocompile_275863_2528170400(cfile0); } LA14: ; } goto LA1; LA5: ; { NIM_BOOL LOC17; NIM_BOOL LOC18; Ropeobj180006* code0; LOC17 = (NIM_BOOL)0; LOC18 = (NIM_BOOL)0; LOC18 = pending0; if (!(LOC18)) goto LA19; LOC18 = mergerequired_532832_2760143328(m0); LA19: ; LOC17 = LOC18; if (!(LOC17)) goto LA20; LOC17 = !((((*(*m0).module).flags &(1U<<((NU)(((Tsymflag294184) 12))&31U)))!=0)); LA20: ; if (!LOC17) goto LA21; mergefiles_533241_2760143328(cfile0, m0); geninitcode_564286_839829468(m0); finishtypedescriptions_537842_839829468(m0); code0 = genmodule_564491_839829468(m0, cfile0); writerope_180836_2381377266(code0, cfile0, NIM_FALSE); addfiletocompile_275863_2528170400(cfile0); } goto LA1; LA21: ; { NimStringDesc* LOC24; NIM_BOOL LOC25; LOC24 = (NimStringDesc*)0; LOC24 = toobjfile_275859_2528170400(cfilenoext0); LOC25 = (NIM_BOOL)0; LOC25 = nosexistsFile(LOC24); if (!!(LOC25)) goto LA26; addfiletocompile_275863_2528170400(cfile0); } goto LA1; LA26: ; LA1: ; addfiletolink_275872_2528170400(cfilenoext0); } N_NIMCALL(void, writeheader_565152_839829468)(Tcgen531027* m0) { Ropeobj180006* result0; Ropeobj180006* guard0; TY180507 LOC1; TY129506 LOC2; TY180507 LOC3; TY535289 LOC13; TY180507 LOC14; result0 = getcopyright_563665_839829468((*m0).filename); memset((void*)LOC1, 0, sizeof(LOC1)); memset((void*)(&LOC2), 0, sizeof(LOC2)); nossplitFile((*m0).filename, (&LOC2)); LOC1[0] = rope_180277_2381377266(LOC2.Field1); guard0 = HEX25_180905_2381377266(((NimStringDesc*) &T839829468_695), LOC1, 1); memset((void*)LOC3, 0, sizeof(LOC3)); LOC3[0] = guard0; addf_181205_2381377266(&result0, ((NimStringDesc*) &T839829468_696), LOC3, 1); addinttypes_563659_839829468(&result0); generateheaders_562104_839829468(m0); generatethreadlocalstorage_540717_839829468(m0); { Tcfilesection531005 i_565174_839829468; NI res_565200_839829468; i_565174_839829468 = (Tcfilesection531005)0; res_565200_839829468 = ((NI) 1); { while (1) { Ropeobj180006* LOC7; Ropeobj180006* LOC8; if (!(res_565200_839829468 <= ((NI) 10))) goto LA6; i_565174_839829468 = ((Tcfilesection531005) (res_565200_839829468)); LOC7 = (Ropeobj180006*)0; LOC7 = gensectionstart_532015_2760143328(i_565174_839829468); add_180482_2381377266(&result0, LOC7); add_180482_2381377266(&result0, (*m0).s[(i_565174_839829468)- 0]); LOC8 = (Ropeobj180006*)0; LOC8 = gensectionend_532050_2760143328(i_565174_839829468); add_180482_2381377266(&result0, LOC8); res_565200_839829468 += ((NI) 1); } LA6: ; } } add_180482_2381377266(&result0, (*m0).s[(((Tcfilesection531005) 11))- 0]); { if (!((gglobaloptions_171130_2607990831 &((NU64)1<<((NU)(((Tglobaloption171013) 8))&63U)))!=0)) goto LA11; add_180487_2381377266(&result0, ((NimStringDesc*) &T839829468_22)); } LA11: ; memset((void*)LOC13, 0, sizeof(LOC13)); addf_181205_2381377266(&result0, ((NimStringDesc*) &T839829468_697), LOC13, 0); memset((void*)LOC14, 0, sizeof(LOC14)); LOC14[0] = guard0; addf_181205_2381377266(&result0, ((NimStringDesc*) &T839829468_698), LOC14, 1); writerope_180836_2381377266(result0, (*m0).filename, NIM_FALSE); } N_NIMCALL(void, cgenwritemodules_565902_839829468)(void) { { if (!!((generatedheader_534201_839829468 == NIM_NIL))) goto LA3; finishmodule_565420_839829468(generatedheader_534201_839829468); } LA3: ; { while (1) { if (!(((NI) 0) < gforwardedprocscounter_531171_3723162438)) goto LA6; { Tcgen531027* m_565916_839829468; m_565916_839829468 = (Tcgen531027*)0; { NI i_565935_839829468; NI HEX3Atmp_565937_839829468; NI res_565939_839829468; i_565935_839829468 = (NI)0; HEX3Atmp_565937_839829468 = (NI)0; HEX3Atmp_565937_839829468 = (gmodules_531170_3723162438 ? (gmodules_531170_3723162438->Sup.len-1) : -1); res_565939_839829468 = ((NI) 0); { while (1) { if (!(res_565939_839829468 <= HEX3Atmp_565937_839829468)) goto LA10; i_565935_839829468 = res_565939_839829468; { if (!!((gmodules_531170_3723162438->data[i_565935_839829468] == NIM_NIL))) goto LA13; m_565916_839829468 = gmodules_531170_3723162438->data[i_565935_839829468]; { if (!!((*m_565916_839829468).Sup.fromcache)) goto LA17; finishmodule_565420_839829468(m_565916_839829468); } LA17: ; } LA13: ; res_565939_839829468 += ((NI) 1); } LA10: ; } } } } LA6: ; } { Tcgen531027* m_565917_839829468; m_565917_839829468 = (Tcgen531027*)0; { NI i_565946_839829468; NI HEX3Atmp_565948_839829468; NI res_565950_839829468; i_565946_839829468 = (NI)0; HEX3Atmp_565948_839829468 = (NI)0; HEX3Atmp_565948_839829468 = (gmodules_531170_3723162438 ? (gmodules_531170_3723162438->Sup.len-1) : -1); res_565950_839829468 = ((NI) 0); { while (1) { if (!(res_565950_839829468 <= HEX3Atmp_565948_839829468)) goto LA22; i_565946_839829468 = res_565950_839829468; { if (!!((gmodules_531170_3723162438->data[i_565946_839829468] == NIM_NIL))) goto LA25; m_565917_839829468 = gmodules_531170_3723162438->data[i_565946_839829468]; { if (!(*m_565917_839829468).Sup.fromcache) goto LA29; updatecachedmodule_565813_839829468(m_565917_839829468); } goto LA27; LA29: ; { writemodule_565637_839829468(m_565917_839829468, NIM_TRUE); } LA27: ; } LA25: ; res_565950_839829468 += ((NI) 1); } LA22: ; } } } writemapping_276789_2528170400(gmapping_531152_3723162438); { if (!!((generatedheader_534201_839829468 == NIM_NIL))) goto LA34; writeheader_565152_839829468(generatedheader_534201_839829468); } LA34: ; } N_NIMCALL(void, nullify_564833_839829468)(Ropeobj180006** arr0) { { Tcfilesection531005 i_564848_839829468; NI res_564853_839829468; i_564848_839829468 = (Tcfilesection531005)0; res_564853_839829468 = ((NI) 0); { while (1) { if (!(res_564853_839829468 <= ((NI) 17))) goto LA3; i_564848_839829468 = ((Tcfilesection531005) (res_564853_839829468)); unsureAsgnRef((void**) (&arr0[(i_564848_839829468)- 0]), NIM_NIL); res_564853_839829468 += ((NI) 1); } LA3: ; } } } N_NIMCALL(void, nullify_564858_839829468)(Ropeobj180006** arr0) { { NIM_CHAR i_565014_839829468; NI res_565019_839829468; i_565014_839829468 = (NIM_CHAR)0; res_565019_839829468 = ((NI) 48); { while (1) { if (!(res_565019_839829468 <= ((NI) 57))) goto LA3; i_565014_839829468 = ((NIM_CHAR) (res_565019_839829468)); unsureAsgnRef((void**) (&arr0[(((NU8)(i_565014_839829468)))- 48]), NIM_NIL); res_565019_839829468 += ((NI) 1); } LA3: ; } } } N_NIMCALL(void, resetmodule_564763_839829468)(Tcgen531027* m0) { initlinkedlist_148031_3771138726((&(*m0).headerfiles)); initintset_270885_2627731572((&(*m0).declaredprotos)); initidtable_298019_850551059((&(*m0).forwtypecache)); asgnRef((void**) (&(*m0).initproc), newproc_531206_3723162438(NIM_NIL, m0)); (*(*m0).initproc).options = initprocoptions_564635_839829468(m0); asgnRef((void**) (&(*m0).preinitproc), newpreinitproc_564625_839829468(m0)); asgnRef((void**) (&(*m0).postinitproc), newpostinitproc_564630_839829468(m0)); initnodetable_298085_850551059((&(*m0).datacache)); if ((*m0).typestack) nimGCunrefNoCycle((*m0).typestack); (*m0).typestack = (Ttypeseq294836*) newSeqRC1((&NTI294836), 0); if ((*m0).forwardedprocs) nimGCunrefNoCycle((*m0).forwardedprocs); (*m0).forwardedprocs = (Tsymseq294804*) newSeqRC1((&NTI294804), 0); asgnRefNoCycle((void**) (&(*m0).typenodesname), gettempname_535596_839829468(m0)); asgnRefNoCycle((void**) (&(*m0).nimtypesname), gettempname_535596_839829468(m0)); { if (!(((*(*m0).module).flags &(1U<<((NU)(((Tsymflag294184) 13))&31U)))!=0)) goto LA3; (*m0).flags |= ((NU8)1)<<((((Codegenflag531025) 0))%(sizeof(NU8)*8)); } goto LA1; LA3: ; { (*m0).flags &= ~(((NU8)1) << ((((Codegenflag531025) 0)) % (sizeof(NU8)*8))); } LA1: ; nullify_564833_839829468((*m0).s); (*m0).typenodes = ((NI) 0); (*m0).nimtypes = ((NI) 0); nullify_564858_839829468((*m0).extensionloaders); (*m0).Sup.fromcache = NIM_TRUE; } N_NIMCALL(void, resetcgenmodules_565024_839829468)(void) { { Tcgen531027* m_565026_839829468; m_565026_839829468 = (Tcgen531027*)0; { NI i_565031_839829468; NI HEX3Atmp_565033_839829468; NI res_565035_839829468; i_565031_839829468 = (NI)0; HEX3Atmp_565033_839829468 = (NI)0; HEX3Atmp_565033_839829468 = (gmodules_531170_3723162438 ? (gmodules_531170_3723162438->Sup.len-1) : -1); res_565035_839829468 = ((NI) 0); { while (1) { if (!(res_565035_839829468 <= HEX3Atmp_565033_839829468)) goto LA4; i_565031_839829468 = res_565035_839829468; { if (!!((gmodules_531170_3723162438->data[i_565031_839829468] == NIM_NIL))) goto LA7; m_565026_839829468 = gmodules_531170_3723162438->data[i_565031_839829468]; resetmodule_564763_839829468(m_565026_839829468); } LA7: ; res_565035_839829468 += ((NI) 1); } LA4: ; } } } } NIM_EXTERNC N_NOINLINE(void, compiler_cgenInit000)(void) { nimRegisterGlobalMarker(T839829468_2); nimRegisterGlobalMarker(T839829468_3); nimRegisterGlobalMarker(T839829468_5); nimRegisterGlobalMarker(T839829468_6); nimRegisterGlobalMarker(T839829468_7); nimRegisterGlobalMarker(T839829468_8); asgnRefNoCycle((void**) (&indent_534655_839829468), rope_180277_2381377266(((NimStringDesc*) &T839829468_4))); if (nimtvdeps_540674_839829468) nimGCunrefNoCycle(nimtvdeps_540674_839829468); nimtvdeps_540674_839829468 = (Ttypeseq294836*) newSeqRC1((&NTI294836), 0); chckNil((void*)(&nimtvdeclared_540675_839829468)); genericReset((void*)(&nimtvdeclared_540675_839829468), (&NTI270030)); initintset_270885_2627731572((&nimtvdeclared_540675_839829468)); breakpointid_550860_839829468 = ((NI) 0); } NIM_EXTERNC N_NOINLINE(void, compiler_cgenDatInit000)(void) { }
ex3.c
#include <stdio.h> #include <omp.h> int main(void) { int threadId, nThreads; #pragma omp parallel private(threadId, nThreads) { threadId = omp_get_thread_num(); printf("\nOi %d\n", threadId); if (threadId == 0) { nThreads = omp_get_num_threads(); printf("QTD threads = %d\n", nThreads); } } return 0; }
polybench.c
#include "polybench.h" #include <stdio.h> #include <string.h> #include <stdlib.h> #include <unistd.h> #include <assert.h> #include <time.h> #include <sys/time.h> #include <sys/resource.h> #include <sched.h> #include <math.h> #ifdef _OPENMP # include <omp.h> #endif /* By default, collect PAPI counters on thread 0. */ #ifndef POLYBENCH_THREAD_MONITOR # define POLYBENCH_THREAD_MONITOR 0 #endif /* Total LLC cache size. By default 32+MB.. */ #ifndef POLYBENCH_CACHE_SIZE_KB # define POLYBENCH_CACHE_SIZE_KB 32770 #endif int polybench_papi_counters_threadid = POLYBENCH_THREAD_MONITOR; double polybench_program_total_flops = 0; #ifdef POLYBENCH_PAPI # include <papi.h> # define POLYBENCH_MAX_NB_PAPI_COUNTERS 96 char* _polybench_papi_eventlist[] = { #include "papi_counters.list" NULL }; int polybench_papi_eventset; int polybench_papi_eventlist[POLYBENCH_MAX_NB_PAPI_COUNTERS]; long_long polybench_papi_values[POLYBENCH_MAX_NB_PAPI_COUNTERS]; #endif /* Timer code (gettimeofday). */ double polybench_t_start, polybench_t_end; /* Timer code (RDTSC). */ unsigned long long int polybench_c_start, polybench_c_end; static double rtclock() { #if defined(POLYBENCH_TIME) || defined(POLYBENCH_GFLOPS) struct timeval Tp; int stat; stat = gettimeofday (&Tp, NULL); if (stat != 0) printf ("Error return from gettimeofday: %d", stat); return (Tp.tv_sec + Tp.tv_usec * 1.0e-6); #else return 0; #endif } #ifdef POLYBENCH_CYCLE_ACCURATE_TIMER static unsigned long long int rdtsc() { unsigned long long int ret = 0; unsigned int cycles_lo; unsigned int cycles_hi; __asm__ volatile ("RDTSC" : "=a" (cycles_lo), "=d" (cycles_hi)); ret = (unsigned long long int)cycles_hi << 32 | cycles_lo; return ret; } #endif void polybench_flush_cache() { int cs = POLYBENCH_CACHE_SIZE_KB * 1024 / sizeof(double); double* flush = (double*) calloc (cs, sizeof(double)); int i; double tmp = 0.0; #ifdef _OPENMP #pragma omp parallel for reduction(+:tmp) private(i) #endif for (i = 0; i < cs; i++) tmp += flush[i]; assert (tmp <= 10.0); free (flush); } #ifdef POLYBENCH_LINUX_FIFO_SCHEDULER void polybench_linux_fifo_scheduler() { /* Use FIFO scheduler to limit OS interference. Program must be run as root, and this works only for Linux kernels. */ struct sched_param schedParam; schedParam.sched_priority = sched_get_priority_max (SCHED_FIFO); sched_setscheduler (0, SCHED_FIFO, &schedParam); } void polybench_linux_standard_scheduler() { /* Restore to standard scheduler policy. */ struct sched_param schedParam; schedParam.sched_priority = sched_get_priority_max (SCHED_OTHER); sched_setscheduler (0, SCHED_OTHER, &schedParam); } #endif #ifdef POLYBENCH_PAPI static void test_fail(char *file, int line, char *call, int retval) { char buf[128]; memset(buf, '\0', sizeof(buf)); if (retval != 0) fprintf (stdout,"%-40s FAILED\nLine # %d\n", file, line); else { fprintf (stdout,"%-40s SKIPPED\n", file); fprintf (stdout,"Line # %d\n", line); } if (retval == PAPI_ESYS) { sprintf (buf, "System error in %s", call); perror (buf); } else if (retval > 0) fprintf (stdout,"Error: %s\n", call); else if (retval == 0) fprintf (stdout,"Error: %s\n", call); else { char errstring[PAPI_MAX_STR_LEN]; PAPI_perror (retval, errstring, PAPI_MAX_STR_LEN); fprintf (stdout,"Error in %s: %s\n", call, errstring); } fprintf (stdout,"\n"); if (PAPI_is_initialized ()) PAPI_shutdown (); exit (1); } void polybench_papi_init() { # ifdef _OPENMP #pragma omp parallel { #pragma omp master { if (omp_get_max_threads () < polybench_papi_counters_threadid) polybench_papi_counters_threadid = omp_get_max_threads () - 1; } #pragma omp barrier if (omp_get_thread_num () == polybench_papi_counters_threadid) { # endif int retval; polybench_papi_eventset = PAPI_NULL; if ((retval = PAPI_library_init (PAPI_VER_CURRENT)) != PAPI_VER_CURRENT) test_fail (__FILE__, __LINE__, "PAPI_library_init", retval); if ((retval = PAPI_create_eventset (&polybench_papi_eventset)) != PAPI_OK) test_fail (__FILE__, __LINE__, "PAPI_create_eventset", retval); int k; for (k = 0; _polybench_papi_eventlist[k]; ++k) { if ((retval = PAPI_event_name_to_code (_polybench_papi_eventlist[k], &(polybench_papi_eventlist[k]))) != PAPI_OK) test_fail (__FILE__, __LINE__, "PAPI_event_name_to_code", retval); } polybench_papi_eventlist[k] = 0; # ifdef _OPENMP } } #pragma omp barrier # endif } void polybench_papi_close() { # ifdef _OPENMP #pragma omp parallel { if (omp_get_thread_num () == polybench_papi_counters_threadid) { # endif int retval; if ((retval = PAPI_destroy_eventset (&polybench_papi_eventset)) != PAPI_OK) test_fail (__FILE__, __LINE__, "PAPI_destroy_eventset", retval); if (PAPI_is_initialized ()) PAPI_shutdown (); # ifdef _OPENMP } } #pragma omp barrier # endif } int polybench_papi_start_counter(int evid) { # ifndef POLYBENCH_NO_FLUSH_CACHE polybench_flush_cache(); # endif # ifdef _OPENMP # pragma omp parallel { if (omp_get_thread_num () == polybench_papi_counters_threadid) { # endif int retval = 1; char descr[PAPI_MAX_STR_LEN]; PAPI_event_info_t evinfo; PAPI_event_code_to_name (polybench_papi_eventlist[evid], descr); if (PAPI_add_event (polybench_papi_eventset, polybench_papi_eventlist[evid]) != PAPI_OK) test_fail (__FILE__, __LINE__, "PAPI_add_event", 1); if (PAPI_get_event_info (polybench_papi_eventlist[evid], &evinfo) != PAPI_OK) test_fail (__FILE__, __LINE__, "PAPI_get_event_info", retval); if ((retval = PAPI_start (polybench_papi_eventset)) != PAPI_OK) test_fail (__FILE__, __LINE__, "PAPI_start", retval); # ifdef _OPENMP } } #pragma omp barrier # endif return 0; } void polybench_papi_stop_counter(int evid) { # ifdef _OPENMP # pragma omp parallel { if (omp_get_thread_num () == polybench_papi_counters_threadid) { # endif int retval; long_long values[1]; values[0] = 0; if ((retval = PAPI_read (polybench_papi_eventset, &values[0])) != PAPI_OK) test_fail (__FILE__, __LINE__, "PAPI_read", retval); if ((retval = PAPI_stop (polybench_papi_eventset, NULL)) != PAPI_OK) test_fail (__FILE__, __LINE__, "PAPI_stop", retval); polybench_papi_values[evid] = values[0]; if ((retval = PAPI_remove_event (polybench_papi_eventset, polybench_papi_eventlist[evid])) != PAPI_OK) test_fail (__FILE__, __LINE__, "PAPI_remove_event", retval); # ifdef _OPENMP } } #pragma omp barrier # endif } void polybench_papi_print() { int verbose = 0; # ifdef _OPENMP # pragma omp parallel { if (omp_get_thread_num() == polybench_papi_counters_threadid) { #ifdef POLYBENCH_PAPI_VERBOSE verbose = 1; #endif if (verbose) printf ("On thread %d:\n", polybench_papi_counters_threadid); #endif int evid; for (evid = 0; polybench_papi_eventlist[evid] != 0; ++evid) { if (verbose) printf ("%s=", _polybench_papi_eventlist[evid]); printf ("%llu ", polybench_papi_values[evid]); if (verbose) printf ("\n"); } printf ("\n"); # ifdef _OPENMP } } #pragma omp barrier # endif } #endif /* ! POLYBENCH_PAPI */ void polybench_prepare_instruments() { #ifndef POLYBENCH_NO_FLUSH_CACHE polybench_flush_cache (); #endif #ifdef POLYBENCH_LINUX_FIFO_SCHEDULER polybench_linux_fifo_scheduler (); #endif } void polybench_timer_start() { polybench_prepare_instruments (); #ifndef POLYBENCH_CYCLE_ACCURATE_TIMER polybench_t_start = rtclock (); #else polybench_c_start = rdtsc (); #endif } void polybench_timer_stop() { #ifndef POLYBENCH_CYCLE_ACCURATE_TIMER polybench_t_end = rtclock (); #else polybench_c_end = rdtsc (); #endif #ifdef POLYBENCH_LINUX_FIFO_SCHEDULER polybench_linux_standard_scheduler (); #endif } void polybench_timer_print() { #ifdef POLYBENCH_GFLOPS if (polybench_program_total_flops == 0) { printf ("[PolyBench][WARNING] Program flops not defined, use polybench_set_program_flops(value)\n"); printf ("%0.6lf\n", polybench_t_end - polybench_t_start); } else printf ("%0.2lf\n", (polybench_program_total_flops / (double)(polybench_t_end - polybench_t_start)) / 1000000000); #else # ifndef POLYBENCH_CYCLE_ACCURATE_TIMER printf ("%0.6f\n", polybench_t_end - polybench_t_start); # else printf ("%Ld\n", polybench_c_end - polybench_c_start); # endif #endif } static void * xmalloc (size_t num) { void* cur = NULL; int ret = posix_memalign (&cur, 32, num); if (! cur || ret) { fprintf (stderr, "[PolyBench] posix_memalign: cannot allocate memory"); exit (1); } return cur; } void* polybench_alloc_data(unsigned long long int n, int elt_size) { /// FIXME: detect overflow! size_t val = n; val *= elt_size; void* ret = xmalloc (val); return ret; }
dyn_sswp.h
#ifndef DYN_SSWP_H_ #define DYN_SSWP_H_ #include <vector> #include <algorithm> #include "traversal.h" #include "sliding_queue_dynamic.h" #include "../common/pvector.h" #include <fstream> extern std::ofstream algF; /* Algorithm: Incremental SSWP and SSWP from scratch. This is the bottleneck shortest path problem. */ template<typename T> void SSWPIter0(T* ds, SlidingQueue<NodeID>& queue){ pvector<bool> visited(ds->num_nodes, false); #pragma omp parallel { QueueBuffer<NodeID> lqueue(queue); #pragma omp for schedule(dynamic, 64) for(NodeID n=0; n < ds->num_nodes; n++){ if(ds->affected[n]){ float old_path = ds->property[n]; std::vector<float> arr; neighborhood<T> neigh = in_neigh(n, ds); float temp; // prepare arr vector for(neighborhood_iter<T> it = neigh.begin(); it != neigh.end(); it++){ temp = std::min(ds->property[*it], static_cast<float>(it.extractWeight())); arr.push_back(temp); } if(!arr.empty()){ // find max in arr vector float new_path = arr[0]; for(std::vector<float>::iterator it = arr.begin(); it!=arr.end(); it++){ new_path = std::max(new_path, *it); } bool trigger = (new_path > old_path); if(trigger){ ds->property[n] = new_path; for(auto v: out_neigh(n, ds)){ bool curr_val = visited[v]; if(!curr_val){ if(compare_and_swap(visited[v], curr_val, true)) lqueue.push_back(v); } } } } } } lqueue.flush(); } } template<typename T> void dynSSWPAlg(T* ds, NodeID source){ std::cout << "Running dynamic SSWP" << std::endl; Timer t; t.Start(); SlidingQueue<NodeID> queue(ds->num_nodes); // set all new vertices' rank to inf, otherwise reuse old values #pragma omp parallel for schedule(dynamic, 64) for(NodeID n = 0; n < ds->num_nodes; n++){ if(ds->property[n] == -1){ if(n == source) ds->property[n] = kDistInf; else ds->property[n] = 0; } } SSWPIter0(ds, queue); queue.slide_window(); while(!queue.empty()){ //std::cout << "Not empty queue, Queue Size:" << queue.size() << std::endl; pvector<bool> visited(ds->num_nodes, false); #pragma omp parallel { QueueBuffer<NodeID> lqueue(queue); #pragma omp for schedule(dynamic, 64) for (auto q_iter = queue.begin(); q_iter < queue.end(); q_iter++){ NodeID n = *q_iter; float old_path = ds->property[n]; std::vector<float> arr; neighborhood<T> neigh = in_neigh(n, ds); float temp; // prepare arr vector for(neighborhood_iter<T> it = neigh.begin(); it != neigh.end(); it++){ temp = std::min(ds->property[*it], static_cast<float>(it.extractWeight())); arr.push_back(temp); } if(!arr.empty()){ // find max in arr vector float new_path = arr[0]; for(std::vector<float>::iterator it = arr.begin(); it!=arr.end(); it++){ new_path = std::max(new_path, *it); } bool trigger = (new_path > old_path); if(trigger){ ds->property[n] = new_path; for(auto v: out_neigh(n, ds)){ bool curr_val = visited[v]; if(!curr_val){ if(compare_and_swap(visited[v], curr_val, true)) lqueue.push_back(v); } } } } } lqueue.flush(); } queue.slide_window(); } // clear affected array to get ready for the next update round #pragma omp parallel for schedule(dynamic, 64) for(NodeID i = 0; i < ds->num_nodes; i++){ ds->affected[i] = false; } t.Stop(); algF << t.Seconds() << std::endl; } template<typename T> void SSWPStartFromScratch(T* ds, NodeID source){ std::cout <<"Running SSWP from scratch" << std::endl; Timer t; t.Start(); #pragma omp parallel for for(NodeID n = 0; n < ds->num_nodes; n++) ds->property[n] = 0; ds->property[source] = kDistInf; SlidingQueue<NodeID> queue(ds->num_nodes); queue.push_back(source); queue.slide_window(); while(!queue.empty()){ //std::cout << "Queue not empty, Queue size: " << queue.size() << std::endl; pvector<bool> visited(ds->num_nodes, false); #pragma omp parallel { QueueBuffer<NodeID> lqueue(queue); #pragma omp for for (auto q_iter = queue.begin(); q_iter < queue.end(); q_iter++){ NodeID u = *q_iter; neighborhood<T> neigh = out_neigh(u, ds); for(neighborhood_iter<T> it = neigh.begin(); it != neigh.end(); it++){ NodeID v = *it; float old_dist = ds->property[v]; float new_dist = std::min(ds->property[u], static_cast<float>(it.extractWeight())); if (new_dist > old_dist){ bool curr_val = visited[v]; if(!curr_val){ if(compare_and_swap(visited[v], curr_val, true)) lqueue.push_back(v); } while (!compare_and_swap(ds->property[v], old_dist, new_dist)){ old_dist = ds->property[v]; if (old_dist >= new_dist) break; } } } } lqueue.flush(); } queue.slide_window(); } t.Stop(); algF << t.Seconds() << std::endl; } #endif // DYN_SSWP_H_ //INITIAL PULL VERSION WHICH ALSO WORKED /*template<typename T> void SSWPStartFromScratch(const string& dataStruc, T* partition, bool directed, NodeID source){ std::cout <<"Running SSWP from scratch" << std::endl; #pragma omp parallel for for(NodeID n = 0; n < partition->num_nodes; n++) partition->property[n] = 0; partition->property[source] = kDistInf; pvector<bool> visited(partition->num_nodes, false); SlidingQueue<NodeID> queue(partition->num_nodes); // this is done by one thread for(auto v:out_neigh(source, dataStruc, partition, directed)){ if(!visited[v]){ queue.push_back(v); visited[v] = true; } } queue.slide_window(); while(!queue.empty()){ std::cout << "Queue not empty, Queue size: " << queue.size() << std::endl; visited.fill(0); #pragma omp parallel { QueueBuffer<NodeID> lqueue(queue); #pragma omp for for (auto q_iter = queue.begin(); q_iter < queue.end(); q_iter++){ NodeID v = *q_iter; float old_dist = partition->property[v]; float maxPath = 0; uint32_t num_in_neigh =0; neighborhood<T> neigh = in_neigh(v, dataStruc, partition, directed); for(typename neighborhood<T>::NeighborIterator it = neigh.begin(); it != neigh.end(); it++){ float p = std::min(partition->property[it.extractNodeID()], static_cast<float>(it.extractWeight())); if(p>maxPath) maxPath = p; num_in_neigh++; } bool gotMaxPath = (num_in_neigh >0); if(gotMaxPath && (maxPath > old_dist)){ partition->property[v] = maxPath; // time to put its out neighbors as active vertices for(auto w: out_neigh(v, dataStruc, partition, directed)){ bool curr_val = visited[w]; if(!curr_val){ if(compare_and_swap(visited[w], curr_val, true)) lqueue.push_back(w); } } } } lqueue.flush(); } queue.slide_window(); } }*/
GB_unaryop__ainv_fp32_int32.c
//------------------------------------------------------------------------------ // GB_unaryop: hard-coded functions for each built-in unary operator //------------------------------------------------------------------------------ // SuiteSparse:GraphBLAS, Timothy A. Davis, (c) 2017-2020, All Rights Reserved. // http://suitesparse.com See GraphBLAS/Doc/License.txt for license. //------------------------------------------------------------------------------ // If this file is in the Generated/ folder, do not edit it (auto-generated). #include "GB.h" #ifndef GBCOMPACT #include "GB_control.h" #include "GB_iterator.h" #include "GB_unaryop__include.h" // C=unop(A) is defined by the following types and operators: // op(A) function: GB_unop__ainv_fp32_int32 // op(A') function: GB_tran__ainv_fp32_int32 // C type: float // A type: int32_t // cast: float cij = (float) aij // unaryop: cij = -aij #define GB_ATYPE \ int32_t #define GB_CTYPE \ float // aij = Ax [pA] #define GB_GETA(aij,Ax,pA) \ int32_t aij = Ax [pA] #define GB_CX(p) Cx [p] // unary operator #define GB_OP(z, x) \ z = -x ; // casting #define GB_CASTING(z, aij) \ float z = (float) aij ; // cij = op (cast (aij)) #define GB_CAST_OP(pC,pA) \ { \ /* aij = Ax [pA] */ \ GB_GETA (aij, Ax, pA) ; \ /* Cx [pC] = op (cast (aij)) */ \ GB_CASTING (z, aij) ; \ GB_OP (GB_CX (pC), z) ; \ } // disable this operator and use the generic case if these conditions hold #define GB_DISABLE \ (GxB_NO_AINV || GxB_NO_FP32 || GxB_NO_INT32) //------------------------------------------------------------------------------ // Cx = op (cast (Ax)): apply a unary operator //------------------------------------------------------------------------------ GrB_Info GB_unop__ainv_fp32_int32 ( float *Cx, // Cx and Ax may be aliased int32_t *Ax, int64_t anz, int nthreads ) { #if GB_DISABLE return (GrB_NO_VALUE) ; #else int64_t p ; #pragma omp parallel for num_threads(nthreads) schedule(static) for (p = 0 ; p < anz ; p++) { GB_CAST_OP (p, p) ; } return (GrB_SUCCESS) ; #endif } //------------------------------------------------------------------------------ // C = op (cast (A')): transpose, typecast, and apply a unary operator //------------------------------------------------------------------------------ GrB_Info GB_tran__ainv_fp32_int32 ( GrB_Matrix C, const GrB_Matrix A, int64_t *GB_RESTRICT *Rowcounts, GBI_single_iterator Iter, const int64_t *GB_RESTRICT A_slice, int naslice ) { #if GB_DISABLE return (GrB_NO_VALUE) ; #else #define GB_PHASE_2_OF_2 #include "GB_unaryop_transpose.c" return (GrB_SUCCESS) ; #endif } #endif
multiway_mergesort.h
/*************************************************************************** * include/stxxl/bits/parallel/multiway_mergesort.h * * Parallel multiway mergesort. * Extracted from MCSTL - http://algo2.iti.uni-karlsruhe.de/singler/mcstl/ * * Part of the STXXL. See http://stxxl.sourceforge.net * * Copyright (C) 2007 Johannes Singler <singler@ira.uka.de> * Copyright (C) 2014 Timo Bingmann <tb@panthema.net> * * Distributed under the Boost Software License, Version 1.0. * (See accompanying file LICENSE_1_0.txt or copy at * http://www.boost.org/LICENSE_1_0.txt) **************************************************************************/ #ifndef STXXL_PARALLEL_MULTIWAY_MERGESORT_HEADER #define STXXL_PARALLEL_MULTIWAY_MERGESORT_HEADER #include <vector> #include <iterator> #include <algorithm> #include <stxxl/bits/config.h> #include <stxxl/bits/parallel/compiletime_settings.h> #include <stxxl/bits/parallel/equally_split.h> #include <stxxl/bits/parallel/multiway_merge.h> #include <stxxl/bits/parallel/multiseq_selection.h> #include <stxxl/bits/parallel/settings.h> #include <stxxl/bits/parallel/timing.h> STXXL_BEGIN_NAMESPACE #if STXXL_PARALLEL namespace parallel { //! Subsequence description. template <typename DiffType> struct PMWMSPiece { //! Begin of subsequence. DiffType begin; //! End of subsequence. DiffType end; }; /*! * Data accessed by all threads. * * PMWMS = parallel multiway mergesort */ template <typename RandomAccessIterator> struct PMWMSSortingData { typedef typename std::iterator_traits<RandomAccessIterator>::value_type ValueType; typedef typename std::iterator_traits<RandomAccessIterator>::difference_type DiffType; //! Input begin. RandomAccessIterator source; //! Start indices, per thread. DiffType* starts; /*! * Temporary arrays for each thread. * * Indirection Allows using the temporary storage in different ways, * without code duplication. \see STXXL_MULTIWAY_MERGESORT_COPY_LAST */ ValueType** temporaries; #if STXXL_MULTIWAY_MERGESORT_COPY_LAST /** Storage in which to sort. */ RandomAccessIterator* sorting_places; /** Storage into which to merge. */ ValueType** merging_places; #else /** Storage in which to sort. */ ValueType** sorting_places; /** Storage into which to merge. */ RandomAccessIterator* merging_places; #endif /** Samples. */ ValueType* samples; /** Offsets to add to the found positions. */ DiffType* offsets; /** PMWMSPieces of data to merge \c [thread][sequence] */ std::vector<PMWMSPiece<DiffType> >* pieces; }; //! Thread local data for PMWMS. template <typename RandomAccessIterator> struct PMWMSSorterPU { /** Total number of thread involved. */ thread_index_t num_threads; /** Number of owning thread. */ thread_index_t iam; /** Pointer to global data. */ PMWMSSortingData<RandomAccessIterator>* sd; }; /*! * Select samples from a sequence. * \param d Pointer to thread-local data. Result will be placed in \c d->ds->samples. * \param num_samples Number of samples to select. */ template <typename RandomAccessIterator, typename DiffType> inline void determine_samples(PMWMSSorterPU<RandomAccessIterator>* d, DiffType& num_samples) { PMWMSSortingData<RandomAccessIterator>* sd = d->sd; num_samples = SETTINGS::sort_mwms_oversampling * d->num_threads - 1; std::vector<DiffType> es(num_samples + 2); equally_split(sd->starts[d->iam + 1] - sd->starts[d->iam], (thread_index_t)(num_samples + 1), es.begin()); for (DiffType i = 0; i < num_samples; i++) sd->samples[d->iam * num_samples + i] = sd->source[sd->starts[d->iam] + es[i + 1]]; } /*! * PMWMS code executed by each thread. * \param d Pointer to thread-local data. * \param comp Comparator. */ template <bool Stable, typename RandomAccessIterator, typename Comparator> inline void parallel_sort_mwms_pu(PMWMSSorterPU<RandomAccessIterator>* d, Comparator& comp) { typedef typename std::iterator_traits<RandomAccessIterator>::value_type ValueType; typedef typename std::iterator_traits<RandomAccessIterator>::difference_type DiffType; Timing<inactive_tag> t; t.tic(); PMWMSSortingData<RandomAccessIterator>* sd = d->sd; thread_index_t iam = d->iam; // length of this thread's chunk, before merging DiffType length_local = sd->starts[iam + 1] - sd->starts[iam]; #if STXXL_MULTIWAY_MERGESORT_COPY_LAST typedef RandomAccessIterator SortingPlacesIterator; // sort in input storage sd->sorting_places[iam] = sd->source + sd->starts[iam]; #else typedef ValueType* SortingPlacesIterator; // sort in temporary storage, leave space for sentinel sd->sorting_places[iam] = sd->temporaries[iam] = static_cast<ValueType*>(::operator new (sizeof(ValueType) * (length_local + 1))); // copy there std::uninitialized_copy(sd->source + sd->starts[iam], sd->source + sd->starts[iam] + length_local, sd->sorting_places[iam]); #endif // sort locally if (Stable) std::stable_sort(sd->sorting_places[iam], sd->sorting_places[iam] + length_local, comp); else std::sort(sd->sorting_places[iam], sd->sorting_places[iam] + length_local, comp); STXXL_DEBUG_ASSERT(stxxl::is_sorted(sd->sorting_places[iam], sd->sorting_places[iam] + length_local, comp)); // invariant: locally sorted subsequence in sd->sorting_places[iam], sd->sorting_places[iam] + length_local t.tic("local sort"); if (SETTINGS::sort_splitting == SETTINGS::SAMPLING) { DiffType num_samples; determine_samples(d, num_samples); #pragma omp barrier t.tic("sample/wait"); #pragma omp single std::sort(sd->samples, sd->samples + (num_samples * d->num_threads), comp); #pragma omp barrier for (int s = 0; s < d->num_threads; s++) { // for each sequence if (num_samples * iam > 0) sd->pieces[iam][s].begin = std::lower_bound(sd->sorting_places[s], sd->sorting_places[s] + sd->starts[s + 1] - sd->starts[s], sd->samples[num_samples * iam], comp) - sd->sorting_places[s]; else // absolute beginning sd->pieces[iam][s].begin = 0; if ((num_samples * (iam + 1)) < (num_samples * d->num_threads)) sd->pieces[iam][s].end = std::lower_bound(sd->sorting_places[s], sd->sorting_places[s] + sd->starts[s + 1] - sd->starts[s], sd->samples[num_samples * (iam + 1)], comp) - sd->sorting_places[s]; else // absolute end sd->pieces[iam][s].end = sd->starts[s + 1] - sd->starts[s]; } } else if (SETTINGS::sort_splitting == SETTINGS::EXACT) { #pragma omp barrier t.tic("wait"); std::vector<std::pair<SortingPlacesIterator, SortingPlacesIterator> > seqs(d->num_threads); for (int s = 0; s < d->num_threads; s++) seqs[s] = std::make_pair(sd->sorting_places[s], sd->sorting_places[s] + sd->starts[s + 1] - sd->starts[s]); std::vector<SortingPlacesIterator> offsets(d->num_threads); // if not last thread if (iam < d->num_threads - 1) multiseq_partition(seqs.begin(), seqs.end(), sd->starts[iam + 1], offsets.begin(), comp); for (int seq = 0; seq < d->num_threads; seq++) { // for each sequence if (iam < (d->num_threads - 1)) sd->pieces[iam][seq].end = offsets[seq] - seqs[seq].first; else // absolute end of this sequence sd->pieces[iam][seq].end = sd->starts[seq + 1] - sd->starts[seq]; } #pragma omp barrier for (int seq = 0; seq < d->num_threads; seq++) { // for each sequence if (iam > 0) sd->pieces[iam][seq].begin = sd->pieces[iam - 1][seq].end; else // absolute beginning sd->pieces[iam][seq].begin = 0; } } t.tic("split"); // offset from target begin, length after merging DiffType offset = 0, length_am = 0; for (int s = 0; s < d->num_threads; s++) { length_am += sd->pieces[iam][s].end - sd->pieces[iam][s].begin; offset += sd->pieces[iam][s].begin; } #if STXXL_MULTIWAY_MERGESORT_COPY_LAST // merge to temporary storage, uninitialized creation not possible since // there is no multiway_merge calling the placement new instead of the // assignment operator sd->merging_places[iam] = sd->temporaries[iam] = new ValueType[length_am]; #else // merge directly to target sd->merging_places[iam] = sd->source + offset; #endif std::vector<std::pair<SortingPlacesIterator, SortingPlacesIterator> > seqs(d->num_threads); for (int s = 0; s < d->num_threads; s++) { seqs[s] = std::make_pair(sd->sorting_places[s] + sd->pieces[iam][s].begin, sd->sorting_places[s] + sd->pieces[iam][s].end); STXXL_DEBUG_ASSERT(stxxl::is_sorted(seqs[s].first, seqs[s].second, comp)); } sequential_multiway_merge<Stable, false>(seqs.begin(), seqs.end(), sd->merging_places[iam], length_am, comp); t.tic("merge"); STXXL_DEBUG_ASSERT(stxxl::is_sorted(sd->merging_places[iam], sd->merging_places[iam] + length_am, comp)); #pragma omp barrier #if STXXL_MULTIWAY_MERGESORT_COPY_LAST // write back std::copy(sd->merging_places[iam], sd->merging_places[iam] + length_am, sd->source + offset); #endif delete sd->temporaries[iam]; t.tic("copy back"); t.print(); } /*! * PMWMS main call. * \param begin Begin iterator of sequence. * \param end End iterator of sequence. * \param comp Comparator. * \param num_threads Number of threads to use. * \tparam Stable Stable sorting. */ template <bool Stable, typename RandomAccessIterator, typename Comparator> inline void parallel_sort_mwms(RandomAccessIterator begin, RandomAccessIterator end, Comparator comp, int num_threads) { STXXL_PARALLEL_PCALL(end - begin) typedef typename std::iterator_traits<RandomAccessIterator>::value_type ValueType; typedef typename std::iterator_traits<RandomAccessIterator>::difference_type DiffType; DiffType n = end - begin; if (n <= 1) return; if (num_threads > n) // at least one element per thread num_threads = static_cast<thread_index_t>(n); PMWMSSortingData<RandomAccessIterator> sd; sd.source = begin; sd.temporaries = new ValueType*[num_threads]; #if STXXL_MULTIWAY_MERGESORT_COPY_LAST sd.sorting_places = new RandomAccessIterator[num_threads]; sd.merging_places = new ValueType*[num_threads]; #else sd.sorting_places = new ValueType*[num_threads]; sd.merging_places = new RandomAccessIterator[num_threads]; #endif if (SETTINGS::sort_splitting == SETTINGS::SAMPLING) sd.samples = new ValueType[num_threads * (SETTINGS::sort_mwms_oversampling * num_threads - 1)]; else sd.samples = NULL; sd.offsets = new DiffType[num_threads - 1]; sd.pieces = new std::vector<PMWMSPiece<DiffType> >[num_threads]; for (int s = 0; s < num_threads; s++) sd.pieces[s].resize(num_threads); PMWMSSorterPU<RandomAccessIterator>* pus = new PMWMSSorterPU<RandomAccessIterator>[num_threads]; DiffType* starts = sd.starts = new DiffType[num_threads + 1]; DiffType chunk_length = n / num_threads, split = n % num_threads, start = 0; for (int i = 0; i < num_threads; i++) { starts[i] = start; start += (i < split) ? (chunk_length + 1) : chunk_length; pus[i].num_threads = num_threads; pus[i].iam = i; pus[i].sd = &sd; } starts[num_threads] = start; //now sort in parallel #pragma omp parallel num_threads(num_threads) parallel_sort_mwms_pu<Stable>(&(pus[omp_get_thread_num()]), comp); delete[] starts; delete[] sd.temporaries; delete[] sd.sorting_places; delete[] sd.merging_places; if (SETTINGS::sort_splitting == SETTINGS::SAMPLING) delete[] sd.samples; delete[] sd.offsets; delete[] sd.pieces; delete[] pus; } } // namespace parallel #endif // STXXL_PARALLEL STXXL_END_NAMESPACE #endif // !STXXL_PARALLEL_MULTIWAY_MERGESORT_HEADER
HelloWorld_2.c
#include <omp.h> #include <stdio.h> int main() { int id_thread, num_threads; /* -id_thread: it must be private, that is, it must take on a different value for each thread that will execute the parallel piece of code. -num_threads: It can be left shared so it is left unique */ #pragma omp parallel private(id_thread), shared(num_threads) { id_thread = omp_get_thread_num(); num_threads = omp_get_num_threads(); printf("Hello from thread %d, nthread %d\n", id_thread, num_threads); } return 0; }
heat_omp.c
#include <stdio.h> #include <stdlib.h> #include <math.h> #include <assert.h> #include <string.h> #include <omp.h> #ifndef M_PI #define M_PI acos(-1.0) #endif double T_x_0_boundaryconditions(int xi, int nx) { /*This is the boundary condition along the "bottom" of the grid, where y=0*/ /*xi is the index of x*/ return cos(((double)xi + 0.5)/((double)nx) * M_PI) * cos(((double)xi + 0.5)/((double)nx) * M_PI); } double T_x_pi_boundaryconditions(int xi, int nx) { /*This is the boundary condition along the "top" of the grid, where y=pi*/ /*xi is the index of x*/ return sin(((double)xi + 0.5)/((double)nx) * M_PI) * sin(((double)xi + 0.5)/((double)nx) * M_PI); } double **grid_creator(const int nx) { //Create a space in the memory to store the temperature as we solve for it double **pointer; pointer = malloc(nx * sizeof(double *)); if(pointer == NULL)//if the memory wasn't allocated { fprintf(stderr, "Malloc did not work. Now exiting...\n"); exit(1); } for(int i = 0; i < nx; i++) { pointer[i] = malloc(nx * sizeof(double)); if(pointer[i] == NULL)//if the memory for a particular row wasn't allocated { fprintf(stderr, "Malloc did not work. Now exiting...\n"); for(int j=0; j < i; j++) { free(pointer[j]);//free all the previous successfully allocated rows } free(pointer[i]);//free the array of pointers exit(1); } } return pointer; } void grid_destroyer(double **pointer, const int nx) { //free memory at the end for(int i=0; i < nx; i ++) { free(pointer[i]); } free(pointer); } int stepper(double **T, double **T2, const int nx, const double dx, const double dt, int nthread) { /*This steps the algorithm forward one step in time*/ omp_set_num_threads(nthread); //Number of threads #pragma omp parallel for for(int i=0; i<nx; i++)//which row, y { for(int j=0; j<nx; j++)//which column, x { double *adjacent = malloc(4 * sizeof(double)); if(adjacent == NULL) { fprintf(stderr, "Malloc did not work. Now exiting...\n"); exit(1); } if(i==0) //corresponds to the top { adjacent[0] = T_x_pi_boundaryconditions(j,nx); //top boundary condition } else { adjacent[0] = T[i-1][j]; } if(j==nx-1) //corresponds to right side { adjacent[1] = T[i][0]; //read from left side, periodic boundary condition } else { adjacent[1] = T[i][j+1]; } if(i==nx-1) //corresponds to the bottom { adjacent[2] = T_x_0_boundaryconditions(j,nx); //bottom boundary condition } else { adjacent[2] = T[i+1][j]; } if(j==0) //corresponds to left side { adjacent[3] = T[i][nx-1]; //read from right side, periodic boundary condition } else { adjacent[3] = T[i][j-1]; } T2[i][j] = T[i][j] + dt / (dx * dx) * (adjacent[0] + adjacent[1] + adjacent[2] + adjacent[3] - 4.*T[i][j]); //calculate new temperature free(adjacent); } } return 0; } void initial_message(char *name) { /*This runs if the incorrect number of command line arguments are given*/ printf("Usage: %s <nx> <nthread>\n",name); printf(" nx: grid size on a side\n final grid will be 2-d sized nx by nx\n nthread: number of threads desired for parallel computing\n"); exit(1); } int main(int argc, char *argv[]) { double start_time = omp_get_wtime(); //let's time how long this run takes if (argc!=3) { initial_message(argv[0]); } const int nx = atoi(argv[1]); //grid size const int nthread = atoi(argv[2]); //number of threads for OMP if(nthread<1) { printf("Make sure you define nthread to be AT LEAST 1\n Now exiting...\n"); exit(0); } int check; /*used for checking outputs to make sure they are good*/ double **T_arr; /*This will be a pointer to an array of pointers which will host the grid itself*/ double **T_arr_2; /*This will be used to calculate the new T values at each time step while keeping the old values in T_arr for calculation purposes*/ double **T_pointer_temp; /*To be used to switch the pointers T_arr and T_arr_2*/ const double fraction_of_maximum_time_step = 0.8;/*This is the fraction of the largest numerically stable timestep, calculated below, that we want our dt to actually be. Keeping it some sane fraction will allow us to get an exact fraction of the maximum time we want. In units of kappa*/ const double dx = M_PI / (double)nx; //physical size of cell const double dt = dx * dx / 4.0 * fraction_of_maximum_time_step; /*This is the time step size, in units of kappa, which later cancel*/ const double tmax = (0.5 * M_PI * M_PI); //maximum time to go const int ntstep = (int) (tmax/dt); //number of time steps T_arr = grid_creator(nx); //allocate memory for the temperature and its companion array T_arr_2 = grid_creator(nx); //Now initialize the array to the initial conditions //Our initial conditions are to have T=0 everywhere for(int i=0; i<nx; i++) { for(int j=0; j<nx; j++) { T_arr[i][j]=0.0; } } printf("%d\n",(int) (tmax/dt)); for(int i=0; i<ntstep; i++)//for each timestep { check = stepper(T_arr,T_arr_2,nx,dx,dt,nthread); //step forward in time assert(check==0); /*The following switches the pointers T_arr and T_arr_2, making T_arr now equal to the newly updated array formerly pointed to by T_arr_2 and giving the T_arr_2 pointer the old array*/ T_pointer_temp = T_arr_2; T_arr_2 = T_arr; T_arr = T_pointer_temp; } FILE *fp; char outputfilename[120] = "heat_omp."; //save file name char stringtemp[120]; sprintf(stringtemp, "%d", nx); strcat(outputfilename,stringtemp); strcat(outputfilename,".output.dat"); if(!(fp=fopen(outputfilename,"w"))) { printf("Output file isn't opening for saving. Now quitting...\n"); grid_destroyer(T_arr,nx); grid_destroyer(T_arr_2,nx); exit(1); } fprintf(fp,"#Final temperature stored in grid format\n"); fprintf(fp,"#Each column in this file corresponds to column of actual grid, as does each row\n"); //print data to the file for(int i=0; i<nx; i++) { for(int j=0; j<nx; j++) { fprintf(fp,"%e ", T_arr[i][j]); } fprintf(fp,"\n"); } fclose(fp); //free memory grid_destroyer(T_arr,nx); grid_destroyer(T_arr_2,nx); //print the time it took to standard output printf("threads: %d, nx: %d, time: %lf\n",nthread,nx,omp_get_wtime()-start_time); return 0; }
AffineParametric_private.h
/* Robust Estimation of Multiple Motions * * This motion estimation based on * M.J.Black and P.Anandan, "The Robust Estimation of Multiple Motions: Parametric and Piecewise-Smooth Flow Fields," Computer Vision and Image Understanding, Vol.63, No.1, 1996, pp.75-104. */ template <class T> std::vector<ImgVector<Vector_ST<double> > > AffineParametric<T>::AffineParametric(const ImgVector<ImgClass::RGB>& current, const ImgVector<ImgClass::RGB>& reference, const double MaxInt, const double sigma, const int IterMax) { std::vector<ImgVector<Vector_ST<double> > > u; // For RETURN value ImgVector<ImgClass::Lab> It_Lab_normalize; ImgVector<ImgClass::Lab> Itp1_Lab_normalize; // M-estimator parameter if (It_color.isNULL()) { throw std::invalid_argument("OpticalFlow_BlockMatching(const ImgVector<double>*, const ImgVector<double>* double, MULTIPLE_MOTION_PARAM, int) : const ImgVector<double>* It"); } else if (Itp1_color.isNULL()) { throw std::invalid_argument("OpticalFlow_BlockMatching(const ImgVector<double>*, const ImgVector<double>* double, MULTIPLE_MOTION_PARAM, int) : const ImgVector<double>* Itp1"); } else if (MaxInt < 0) { throw std::invalid_argument("OpticalFlow_BlockMatching(const ImgVector<double>*, const ImgVector<double>* double, MULTIPLE_MOTION_PARAM, int) : double MaxInt"); } // sRGB image It_sRGB_normalize.copy(It_color); Itp1_sRGB_normalize.copy(Itp1_color); // Grayscale It.cast_copy(It_color); Itp1.cast_copy(Itp1_color); // Image Normalization It_normalize = It; Itp1_normalize = Itp1; for (size_t i = 0; i < It_normalize.size(); i++) { // sRGB It_sRGB_normalize[i] /= MaxInt; Itp1_sRGB_normalize[i] /= MaxInt; // Grayscale It_normalize[i] /= MaxInt; Itp1_normalize[i] /= MaxInt; } // Convert sRGB to CIE Lab It_Lab_normalize.reset(It_sRGB_normalize.width(), It_sRGB_normalize.height()); Itp1_Lab_normalize.reset(It_sRGB_normalize.width(), It_sRGB_normalize.height()); for (size_t i = 0; i < It_sRGB_normalize.size(); i++) { It_Lab_normalize[i].set(It_sRGB_normalize[i]); Itp1_Lab_normalize[i].set(Itp1_sRGB_normalize[i]); } // Shift image sequence by 1 and assign current image if (sequence_sRGB.empty()) { sequence_sRGB.push_front(It_sRGB_normalize); sequence_Grayscale.push_front(It_normalize); sequence_Lab.push_front(It_Lab_normalize); } sequence_sRGB.push_front(Itp1_sRGB_normalize); sequence_Grayscale.push_front(Itp1_normalize); sequence_Lab.push_front(Itp1_Lab_normalize); if (sequence_sRGB.size() >= History_Max) { sequence_sRGB.pop_back(); sequence_Grayscale.pop_back(); sequence_Lab.pop_back(); } // ----- Block Matching ----- #if 0 // Normal Block Matching printf("* * Compute Block Matching\n"); int BlockSize = MotionParam.BlockMatching_BlockSize; domain_map.reset(It.width(), It.height()); for (int y = 0; y < It.height(); y++) { for (int x = 0; x < It.width(); x++) { domain_map.at(x, y) = size_t(BlockSize * floor(y / BlockSize) + floor(x / BlockSize)); } } int BlockMatching_BlockSize = 8; if (sequence_Lab.size() <= 2) { block_matching.reset(It_Lab_normalize, Itp1_Lab_normalize, BlockMatching_BlockSize, Subpixel_Scale); } else { block_matching.reset(sequence_Lab[2], sequence_Lab[1], sequence_Lab[0], BlockMatching_BlockSize, Subpixel_Scale); } block_matching.block_matching(BM_Search_Range, coeff_MAD, coeff_ZNCC); #else { // Segmentation printf("* * Compute Segmentation by Mean Shift\n"); #ifdef MEANSHIFT_KERNEL_SPATIAL double kernel_spatial = MEANSHIFT_KERNEL_SPATIAL, kernel_intensity = 9.0 / 255.0; // for images under about HD resolution #else //double kernel_spatial = 64.0, kernel_intensity = 12.0 / 255.0; // for 4K Film kernel(spatial = 64.0, intensity = 12.0 / 255.0) double kernel_spatial = 10.0, kernel_intensity = 9.0 / 255.0; // for images under about HD resolution #endif if (segmentations.empty()) { segmentations.push_front(Segmentation<ImgClass::Lab>(It_Lab_normalize, kernel_spatial, kernel_intensity)); } segmentations.push_front(Segmentation<ImgClass::Lab>(Itp1_Lab_normalize, kernel_spatial, kernel_intensity)); if (segmentations.size() >= History_Max) { segmentations.pop_back(); } PNM pnm; std::string::size_type found = 1 + ofilename.find_last_not_of("0123456789", ofilename.find_last_of("0123456789")); if (found == std::string::npos) { found = ofilename.find_last_of("."); } std::string ofilename_segmentation = ofilename.substr(0, found) + "segmentation_" + ofilename.substr(found); printf("* Output The Segmentation result to '%s'(binary)\n\n", ofilename_segmentation.c_str()); { ImgVector<int> tmp_vector(segmentations[0].width(), segmentations[0].height()); for (size_t i = 0; i < segmentations[0].size(); i++) { tmp_vector[i] = static_cast<int>(segmentations[0][i]); } pnm.copy(PORTABLE_GRAYMAP_BINARY, segmentations[0].width(), segmentations[0].height(), int(tmp_vector.max()), tmp_vector.data()); pnm.write(ofilename_segmentation.c_str()); pnm.free(); } ImgVector<int> quantized(segmentations[0].width(), segmentations[0].height()); for (size_t i = 0; i < segmentations[0].ref_color_quantized_image().size(); i++) { quantized.at(i) = int(round(double(segmentations[0].ref_color_quantized_image().get(i)) / 100.0)); if (quantized.get(i) < 0) { quantized.at(i) = 0; } } std::string ofilename_quantized = ofilename.substr(0, found) + "color-quantized_" + ofilename.substr(found); printf("* Output The color quantized image '%s'(binary)\n\n", ofilename_quantized.c_str()); pnm.copy(PORTABLE_GRAYMAP_BINARY, segmentations[0].width(), segmentations[0].height(), quantized.max(), quantized.data()); pnm.write(ofilename_quantized.c_str()); pnm.free(); // Output vectors std::string ofilename_vector = ofilename.substr(0, found) + "shift-vector_" + ofilename.substr(found); FILE *fp; fp = fopen(ofilename_vector.c_str(), "w"); fprintf(fp, "%d %d\n", segmentations[0].width(), segmentations[0].height()); for (int y = 0; y < segmentations[0].height(); y++) { for (int x = 0; x < segmentations[0].width(); x++) { VECTOR_2D<double> v; v.x = segmentations[0].ref_shift_vector().get(x, y).x - x; v.y = segmentations[0].ref_shift_vector().get(x, y).y - y; fwrite(&v.x, sizeof(double), 1, fp); fwrite(&v.y, sizeof(double), 1, fp); } } fclose(fp); // Arbitrary shaped Block Matching printf("* * Compute Block Matching\n"); //block_matching.reset(segmentations.begin()->ref_segmentation_map(), It, Itp1); if (sequence_Lab.size() <= 2) { block_matching.reset( It_Lab_normalize, segmentations[1].ref_segmentation_map(), Itp1_Lab_normalize, segmentations[0].ref_segmentation_map(), Subpixel_Scale); } else { block_matching.reset( sequence_Lab[2], segmentations[2].ref_segmentation_map(), sequence_Lab[1], segmentations[1].ref_segmentation_map(), sequence_Lab[0], segmentations[0].ref_segmentation_map(), Subpixel_Scale); } block_matching.block_matching(BM_Search_Range, coeff_MAD, coeff_ZNCC); } #endif // ----- Optical Flow ----- std::vector<std::vector<double> > u_affine; if (MotionParam.Level > 0) { const std::vector<std::vector<VECTOR_2D<int> > >* regions; ImgVector<ImgClass::Lab>* interest = nullptr; std::vector<ImgVector<ImgClass::Lab>*> references; if (sequence_Grayscale.size() <= 2) { regions = &(segmentations[0].ref_regions()); interest = &Itp1_Lab_normalize; references.push_back(&It_Lab_normalize); } else { regions = &(segmentations[1].ref_regions()); interest = &sequence_Lab[1]; references.push_back(&sequence_Lab[2]); references.push_back(&sequence_Lab[0]); } // Gradient ImgVector<VECTOR_2D<double> > grad(It_color.width(), It_color.height()); for (int y = 0; y < It_color.height(); y++) { for (int x = 0; x < It_color.width(); x++) { grad.at(x, y).x = (interest->get_mirror(x + 1, y).L - interest->get(x, y).L + interest->get_mirror(x + 1, y + 1).L - interest->get_mirror(x, y + 1).L) / 2.0; grad.at(x, y).y = (interest->get_mirror(x, y + 1).L - interest->get(x, y).L + interest->get_mirror(x + 1, y + 1).L - interest->get_mirror(x + 1, y).L) / 2.0; } } // Initialize affine coefficient vector u_affine.resize(regions->size()); for (size_t n = 0; n < regions->size(); n++) { u_affine[n].resize(Num_Affine_Parameter); } // Gradient-based estimation for (size_t ref = 0; ref < references.size(); ref++) { ImgVector<double> dt_I(interest->width(), interest->height()); for (int y = 0; y < interest->height(); y++) { for (int x = 0; x < interest->width(); x++) { dt_I.at(x, y) = (references[ref]->get(x, y).L - interest->get(x, y).L + references[ref]->get_mirror(x + 1, y).L - interest->get_mirror(x + 1, y).L + references[ref]->get_mirror(x, y + 1).L - interest->get_mirror(x, y + 1).L + references[ref]->get_mirror(x + 1, y + 1).L - interest->get_mirror(x + 1, y + 1).L) / 4.0; } } // IRLS Optical Flow estimation printf("\n* IRLS\n sigma = %f, iteration = %d\n", sigma, IterMax); #ifdef _OPENMP #pragma omp parallel for schedule(dynamic) #endif for (size_t n = 0; n < regions->size(); n++) { IRLS_AffineParametric_region( &u_affine[n], regions->at(n), &grad, &dt_I, sigma, IterMax, MotionParam.Error_Min_Threshold); } } } // Copy the lowest vector for output if (Bidirectional_with_Time) { u.resize(1); u[0].reset(It.width(), It.height()); for (int y = 0; y < block_matching.height(); y++) { for (int x = 0; x < block_matching.width(); x++) { u[0].at(x, y) = block_matching.get(x, y); } } } else { u.resize(2); u[0].reset(It.width(), It.height()); u[1].reset(It.width(), It.height()); for (int y = 0; y < block_matching.height(); y++) { for (int x = 0; x < block_matching.width(); x++) { u[0].at(x, y) = block_matching.get_prev(x, y); u[0].at(x, y).t = -1; if (u.size() > 1) { // bi-directional u[1].at(x, y) = block_matching.get_next(x, y); u[1].at(x, y).t = 1; } } } } return u; } template <class T> void AffineParametric<T>::IRLS_AffineParametric_region(void) { const double omega = 1.0E-3; // Initialize for (int i = 0; i < Num_Affine_Parameter; i++) { u_affine->at(i) = .0; } // Start IRLS for (int n = 0; n < IterMax; n++) { std::vector<double> u_np1(Num_Affine_Parameter); std::vector<double> dE = Error_a_region(u_affine, region, grad, dt, sigma); std::vector<double> sup = sup_Error_aa_region(region, grad, sigma); double E = 0.0; for (int i = 0; i < Num_Affine_Parameter; i++) { if (fabs(sup[i]) < 1.0E-10) { u_np1[i] = u_affine->at(i) - omega * 1.0E+10 * SIGN_NOZERO(sup[i]) * dE[i]; } else { u_np1[i] = u_affine->at(i) - omega / sup[i] * dE[i]; } } *u_affine = u_np1; E = Error_Affine_region(u_affine, region, grad, dt, sigma); if (E < ErrorMinThreshold) { break; } } } template <class T> std::vector<double> AffineParametric<T>::Error_a_region(const std::vector<double>* u_affine, const std::vector<VECTOR_2D<int> >& region, const ImgVector<VECTOR_2D<double> >* grad, const ImgVector<double>* dt, double sigma) { double (*psiD)(const double&, const double&) = LIB_ImgClass_AffineParametric::Geman_McClure_psi; std::vector<double> E_a(Num_Affine_Parameter); VECTOR_2D<double> u_a; for (size_t i = 0; i < Num_Affine_Parameter; i++) { E_a[i] = .0; } for (const VECTOR_2D<int>& element : region) { int x = element.x; int y = element.y; u_a.x = u_affine->at(0) + u_affine->at(1) * x + u_affine->at(2) * y; u_a.y = u_affine->at(3) + u_affine->at(4) * x + u_affine->at(5) * y; E_a[0] += grad->get(x, y).x * (*psiD)(grad->get(x, y).x * u_a.x + grad->get(x, y).y * u_a.y + dt->get_zeropad(x, y), sigma); E_a[1] += grad->get(x, y).x * x * (*psiD)(grad->get(x, y).x * u_a.x + grad->get(x, y).y * u_a.y + dt->get_zeropad(x, y), sigma); E_a[2] += grad->get(x, y).x * y * (*psiD)(grad->get(x, y).x * u_a.x + grad->get(x, y).y * u_a.y + dt->get_zeropad(x, y), sigma); E_a[3] += grad->get(x, y).y * (*psiD)(grad->get(x, y).x * u_a.x + grad->get(x, y).y * u_a.y + dt->get_zeropad(x, y), sigma); E_a[4] += grad->get(x, y).y * x * (*psiD)(grad->get(x, y).x * u_a.x + grad->get(x, y).y * u_a.y + dt->get_zeropad(x, y), sigma); E_a[5] += grad->get(x, y).y * y * (*psiD)(grad->get(x, y).x * u_a.x + grad->get(x, y).y * u_a.y + dt->get_zeropad(x, y), sigma); } return E_a; } template <class T> std::vector<double> AffineParametric<T>::sup_Error_aa_region(const std::vector<VECTOR_2D<int> >& region, const ImgVector<VECTOR_2D<double> >* grad, double sigma) { ERROR Error("sup_Error_aa_region"); std::vector<double> sup(Num_Affine_Parameter); std::vector<double> u_aa_max(Num_Affine_Parameter); for (size_t i = 0; i < Num_Affine_Parameter; i++) { u_aa_max[i] = .0; } if (grad == nullptr) { Error.Value("grad"); Error.PointerNull(); return u_aa_max; } for (const VECTOR_2D<int>& element : region) { int x = element.x; int y = element.y; // u = a0 + a1 * x + a2 * y if (u_aa_max[0] < POW2(grad->get(x, y).x)) { u_aa_max[0] = POW2(grad->get(x, y).x); } if (u_aa_max[1] < POW2(grad->get(x, y).x * x)) { u_aa_max[1] = POW2(grad->get(x, y).x * x); } if (u_aa_max[2] < POW2(grad->get(x, y).x * y)) { u_aa_max[2] = POW2(grad->get(x, y).x * y); } // v = a3 + a4 * x + a5 * y if (u_aa_max[3] < POW2(grad->get(x, y).y)) { u_aa_max[3] = POW2(grad->get(x, y).y); } if (u_aa_max[4] < POW2(grad->get(x, y).y * x)) { u_aa_max[4] = POW2(grad->get(x, y).y * x); } if (u_aa_max[5] < POW2(grad->get(x, y).y * y)) { u_aa_max[5] = POW2(grad->get(x, y).y * y); } } sup[0] = u_aa_max[0] * 2.0 / POW2(sigma); sup[1] = u_aa_max[1] * 2.0 / POW2(sigma); sup[2] = u_aa_max[2] * 2.0 / POW2(sigma); sup[3] = u_aa_max[3] * 2.0 / POW2(sigma); sup[4] = u_aa_max[4] * 2.0 / POW2(sigma); sup[5] = u_aa_max[5] * 2.0 / POW2(sigma); return sup; } template <class T> double AffineParametric<T>::Error_region(const std::vector<double>* u_affine, const std::vector<VECTOR_2D<int> >& region, const ImgVector<VECTOR_2D<double> >* grad, const ImgVector<double>* dt, double sigma) { double (*rhoD)(const double&, const double&) = LIB_ImgClass_AffineParametric::Geman_McClure_rho; double E = 0.0; VECTOR_2D<double> u_a; for (const VECTOR_2D<int>& element : region) { int x = element.x; int y = element.y; u_a.x = u_affine->at(0) + u_affine->at(1) * x + u_affine->at(2) * y; u_a.y = u_affine->at(3) + u_affine->at(4) * x + u_affine->at(5) * y; E += (*rhoD)(grad->get(x, y).x * u_a.x + grad->get(x, y).y * u_a.y + dt->get(x, y), sigma); } return E; }
BFEgg_fmt_plug.c
/* * This file is part of Eggdrop blowfish patch for John The Ripper. * Copyright (c) 2002 by Sun-Zero <sun-zero at freemail.hu> * This is a free software distributable under terms of the GNU GPL. */ #if FMT_EXTERNS_H extern struct fmt_main fmt_BFEgg; #elif FMT_REGISTERS_H john_register_one(&fmt_BFEgg); #else #include <string.h> #include "misc.h" #include "formats.h" #include "common.h" #include "blowfish.c" #ifdef _OPENMP static int omp_t = 1; #include <omp.h> // Tuning on AMD A8 4500M laptop, cygwin64 with OMP(4x) -test=5 // 4 = 44330 (original) // 16 = 54760 // 24 = 56151 // 32 = 56216 // 64 = 57770 // 96 = 57888 // 128 = 58016 > instant -test=0 // 256 = 58282 // from here on, not enough gain to matter. // 512 = 58573 // 1024= 59464 // 4096= 59244 > 1s -test=0 #define OMP_SCALE 128 #endif #include "memdbg.h" #define FORMAT_LABEL "bfegg" #define FORMAT_NAME "Eggdrop" #define ALGORITHM_NAME "Blowfish 32/" ARCH_BITS_STR #define BENCHMARK_COMMENT "" #define BENCHMARK_LENGTH -1 #define PLAINTEXT_LENGTH 31 #define CIPHERTEXT_LENGTH 13 #define BINARY_SIZE 7 #define BINARY_ALIGN 4 #define SALT_SIZE 0 #define SALT_ALIGN 1 #define MIN_KEYS_PER_CRYPT 1 #define MAX_KEYS_PER_CRYPT 1 static struct fmt_tests tests[] = { {"+9F93o1OxwgK1", "123456"}, {"+C/.8o.Wuph9.", "qwerty"}, {"+EEHgy/MBLDd0", "walkman"}, {"+vPBrs07OTXE/", "tesztuser"}, {"+zIvO/1nDsd9.", "654321"}, {NULL} }; static char (*saved_key)[PLAINTEXT_LENGTH + 1]; static ARCH_WORD_32 (*crypt_out)[(BINARY_SIZE + 1) / sizeof(ARCH_WORD_32)]; #if defined (_MSC_VER) || defined (__MINGW32__) // in VC, _atoi64 is a function. #define _atoi64 JtR_atoi64 #endif static const char _itoa64[] = "./0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ"; static char _atoi64[0x100]; static int valid(char *ciphertext, struct fmt_main *self) { char *pos; if (*ciphertext != '+') return 0; if (strlen(ciphertext) != CIPHERTEXT_LENGTH) return 0; for (pos = &ciphertext[1]; atoi64[ARCH_INDEX(*pos)] != 0x7F; pos++); if (*pos || pos - ciphertext != CIPHERTEXT_LENGTH) return 0; return 1; } void init(struct fmt_main *self) { const char *pos; #ifdef _OPENMP omp_t = omp_get_max_threads(); self->params.min_keys_per_crypt *= omp_t; omp_t *= OMP_SCALE; self->params.max_keys_per_crypt *= omp_t; #endif saved_key = mem_calloc_tiny(sizeof(*saved_key) * self->params.max_keys_per_crypt, MEM_ALIGN_WORD); crypt_out = mem_calloc_tiny(sizeof(*crypt_out) * self->params.max_keys_per_crypt, MEM_ALIGN_WORD); memset(_atoi64, 0x7F, sizeof(_atoi64)); for (pos = _itoa64; pos <= &_itoa64[63]; pos++) _atoi64[ARCH_INDEX(*pos)] = pos - _itoa64; } /* The base64 is flawed - we just mimic flaws from the original code */ static void *binary(char *ciphertext) { static union toalign { unsigned char c[BINARY_SIZE]; ARCH_WORD_32 a[1]; } a; unsigned char *out = a.c; ARCH_WORD_32 value; char *pos; pos = ciphertext + 1; value = (ARCH_WORD_32)_atoi64[ARCH_INDEX(pos[0])] | ((ARCH_WORD_32)_atoi64[ARCH_INDEX(pos[1])] << 6) | ((ARCH_WORD_32)_atoi64[ARCH_INDEX(pos[2])] << 12) | ((ARCH_WORD_32)_atoi64[ARCH_INDEX(pos[3])] << 18); out[0] = value; out[1] = value >> 8; out[2] = value >> 16; out[3] = _atoi64[ARCH_INDEX(pos[4])] | (_atoi64[ARCH_INDEX(pos[5])] << 6); pos += 6; value = (ARCH_WORD_32)_atoi64[ARCH_INDEX(pos[0])] | ((ARCH_WORD_32)_atoi64[ARCH_INDEX(pos[1])] << 6) | ((ARCH_WORD_32)_atoi64[ARCH_INDEX(pos[2])] << 12) | ((ARCH_WORD_32)_atoi64[ARCH_INDEX(pos[3])] << 18); out[4] = value; out[5] = value >> 8; out[6] = value >> 16; return (void *)out; } static void set_key(char *key, int index) { strnzcpy(saved_key[index], key, PLAINTEXT_LENGTH+1); } static char *get_key(int index) { return saved_key[index]; } static int cmp_all(void *binary, int count) { int index = 0; #ifdef _OPENMP for (; index < count; index++) #endif if (!memcmp(binary, crypt_out[index], BINARY_SIZE)) return 1; return 0; } static int cmp_one(void *binary, int index) { return !memcmp(binary, crypt_out[index], BINARY_SIZE); } static int cmp_exact(char *source, int index) { return 1; } static int get_hash_0(int index) { return crypt_out[index][0] & 0xf; } static int get_hash_1(int index) { return crypt_out[index][0] & 0xff; } static int get_hash_2(int index) { return crypt_out[index][0] & 0xfff; } static int get_hash_3(int index) { return crypt_out[index][0] & 0xffff; } static int get_hash_4(int index) { return crypt_out[index][0] & 0xfffff; } static int get_hash_5(int index) { return crypt_out[index][0] & 0xffffff; } static int get_hash_6(int index) { return crypt_out[index][0] & 0x7ffffff; } static int crypt_all(int *pcount, struct db_salt *salt) { int count = *pcount; int index = 0; #ifdef _OPENMP #pragma omp parallel for for (index = 0; index < count; index++) #endif { /*if (saved_key[index][0] == '\0') { zerolengthkey = 1; } else { zerolengthkey = 0; */ if (saved_key[index][0] != 0) blowfish_encrypt_pass(saved_key[index], (char*)crypt_out[index]); } return count; } struct fmt_main fmt_BFEgg = { { FORMAT_LABEL, FORMAT_NAME, ALGORITHM_NAME, BENCHMARK_COMMENT, BENCHMARK_LENGTH, PLAINTEXT_LENGTH, BINARY_SIZE, BINARY_ALIGN, SALT_SIZE, SALT_ALIGN, MIN_KEYS_PER_CRYPT, MAX_KEYS_PER_CRYPT, FMT_CASE | FMT_8_BIT | FMT_OMP, #if FMT_MAIN_VERSION > 11 { NULL }, #endif tests }, { init, fmt_default_done, fmt_default_reset, fmt_default_prepare, valid, fmt_default_split, binary, fmt_default_salt, #if FMT_MAIN_VERSION > 11 { NULL }, #endif fmt_default_source, { fmt_default_binary_hash_0, fmt_default_binary_hash_1, fmt_default_binary_hash_2, fmt_default_binary_hash_3, fmt_default_binary_hash_4, fmt_default_binary_hash_5, fmt_default_binary_hash_6 }, fmt_default_salt_hash, fmt_default_set_salt, set_key, get_key, fmt_default_clear_keys, crypt_all, { get_hash_0, get_hash_1, get_hash_2, get_hash_3, get_hash_4, get_hash_5, get_hash_6 }, cmp_all, cmp_one, cmp_exact } }; #endif /* plugin stanza */
SE3P_direct_self.c
#include <math.h> #include "mex.h" #define IDX prhs[0] #define X prhs[1] // Source locations #define Q prhs[2] // Source strengths #define OPT prhs[3] // Parameters #define PHI plhs[0] // Output #ifndef VERBOSE #define VERBOSE 0 #endif #define PI 3.141592653589793 typedef struct { double box[3]; double xi; int layers; double rc; } ewald_opts; void unpack_opt(ewald_opts* opt, const mxArray* mx_opt) { // mandatory options -- will trigger core dump if missing opt->xi = mxGetScalar(mxGetField(mx_opt,0,"xi")); double* box = mxGetPr(mxGetField(mx_opt,0,"box")); opt->box[0] = box[0]; opt->box[1] = box[1]; opt->box[2] = box[2]; // layers: mandatory for ewald sums that are truncated const mxArray* mx_layers = mxGetField(mx_opt,0,"layers"); if(mx_layers) opt->layers = (int)mxGetScalar(mx_layers); else opt->layers = -1; // rc: mandatory for short-range real sum const mxArray* mx_rc = mxGetField(mx_opt,0,"real_cutoff"); if(mx_rc) opt->rc = mxGetScalar(mx_rc); else opt->rc = -1; } // MATLAB (one-based, doubles) to C (zero-based, integers) index translation void index_translation(int* idx, const double* idx_d, int N) { for(int i=0; i<N; i++) idx[i] = (int)idx_d[i] - 1; } void SE3P_direct_self(double* restrict phi, const int* restrict idx, int nidx, const double* restrict q, int N, const ewald_opts opt) { double c = 2*opt.xi/sqrt(PI); #ifdef _OPENMP #pragma omp parallel for #endif for(int m=0; m<nidx; m++) phi[m] -= c*q[idx[m]]; } /* no input checking is done */ void mexFunction(int nlhs, mxArray *plhs[], int nrhs, const mxArray *prhs[] ) { // input dims const int N = mxGetM(X); const int num_eval = mxGetN(IDX); // FIXME: indices assumed to be row vec const double* idx_d = mxGetPr(IDX); int* idx = mxMalloc(num_eval*sizeof(int)); index_translation(idx, idx_d, num_eval); const double* q = mxGetPr(Q); PHI = mxCreateDoubleMatrix(num_eval, 1, mxREAL); double* restrict phi = mxGetPr(PHI); ewald_opts opt; unpack_opt(&opt, OPT); if(VERBOSE) { mexPrintf("[EWALD (%s)] MEX N=(%d,%d) ","SELF3P",N,num_eval); mexPrintf("xi = %.2f [rc = %.2f, layers=%d]\n", opt.xi,opt.rc,opt.layers); } // call kernel SE3P_direct_self(phi, idx, num_eval, q, N, opt); mxFree(idx); }
IndexedFaceMesh.h
#ifndef __INDEXEDFACEMESH_H__ #define __INDEXEDFACEMESH_H__ #include <vector> #include "Common/Common.h" #include <iterator> namespace Utilities { class IndexedFaceMesh { public: struct Edge { unsigned int m_face[2]; unsigned int m_vert[2]; }; struct Face { unsigned int *m_edges; }; // Stores the indices of each face connected to a specific vertex struct VertexFaces { VertexFaces() { m_fIndices = 0; m_numFaces = 0; } VertexFaces(VertexFaces const& other) { *this = other; } VertexFaces& operator=(VertexFaces const& other) { m_numFaces = other.m_numFaces; m_fIndices = new unsigned int[m_numFaces]; #if defined(_MSC_VER) std::copy(other.m_fIndices, other.m_fIndices + m_numFaces, stdext::unchecked_array_iterator<unsigned int*>(m_fIndices)); #else std::copy(other.m_fIndices, other.m_fIndices + m_numFaces, m_fIndices); #endif return *this; } ~VertexFaces() { delete[] m_fIndices; } unsigned int m_numFaces; unsigned int* m_fIndices; }; // Stores the indices of each edge connected to a specific vertex struct VertexEdges { VertexEdges() { m_eIndices = 0; m_numEdges = 0; } VertexEdges(VertexEdges const& other) { *this = other; } VertexEdges& operator=(VertexEdges const& other) { m_numEdges = other.m_numEdges; m_eIndices = new unsigned int[m_numEdges]; #if defined(_MSC_VER) std::copy(other.m_eIndices, other.m_eIndices + m_numEdges, stdext::unchecked_array_iterator<unsigned int*>(m_eIndices)); #else std::copy(other.m_eIndices, other.m_eIndices + m_numEdges, m_eIndices); #endif return *this; } ~VertexEdges() { delete[] m_eIndices; } unsigned int m_numEdges; unsigned int* m_eIndices; }; public: typedef std::vector<unsigned int> Faces; typedef std::vector<Vector3r> FaceNormals; typedef std::vector<Vector3r> VertexNormals; typedef std::vector<Face> FaceData; typedef std::vector<Edge> Edges; typedef std::vector<VertexFaces> VerticesFaces; typedef std::vector<VertexEdges> VerticesEdges; typedef std::vector<unsigned int> UVIndices; typedef std::vector<Vector2r> UVs; protected: unsigned int m_numPoints; Faces m_indices; Edges m_edges; FaceData m_faces; bool m_closed; UVIndices m_uvIndices; UVs m_uvs; VerticesFaces m_verticesFaces; VerticesEdges m_verticesEdges; unsigned int m_verticesPerFace; FaceNormals m_normals; VertexNormals m_vertexNormals; public: IndexedFaceMesh(const unsigned int verticesPerFace = 3); IndexedFaceMesh(IndexedFaceMesh const& other); IndexedFaceMesh& operator=(IndexedFaceMesh const& other); ~IndexedFaceMesh(); void release(); bool isClosed() const; void initMesh(const unsigned int nPoints, const unsigned int nEdges, const unsigned int nFaces); void addFace(const unsigned int * const indices); void addFace(const int * const indices); void addUV(const Real u, const Real v); void addUVIndex(const unsigned int index); const Faces& getFaces() const { return m_indices; } Faces& getFaces(){ return m_indices; } const FaceNormals& getFaceNormals() const { return m_normals; } FaceNormals& getFaceNormals(){ return m_normals; } const VertexNormals& getVertexNormals() const { return m_vertexNormals; } VertexNormals& getVertexNormals(){ return m_vertexNormals; } Edges& getEdges() { return m_edges; } const Edges& getEdges() const { return m_edges; } const FaceData& getFaceData() const { return m_faces; } const UVIndices& getUVIndices() const { return m_uvIndices; } const UVs& getUVs() const { return m_uvs; } const VerticesFaces& getVertexFaces() const { return m_verticesFaces; } const VerticesEdges& getVertexEdges() const { return m_verticesEdges; } unsigned int numVertices() const { return m_numPoints; } unsigned int numFaces() const { return (unsigned int)m_indices.size() / m_verticesPerFace; } unsigned int numEdges() const { return (unsigned int)m_edges.size(); } unsigned int numUVs() const { return (unsigned int)m_uvs.size(); } void copyUVs(const UVIndices& uvIndices, const UVs& uvs); void buildNeighbors(); template<class PositionData> void updateNormals(const PositionData &pd, const unsigned int offset); template<class PositionData> void updateVertexNormals(const PositionData &pd); unsigned int getVerticesPerFace() const; }; template<class PositionData> void IndexedFaceMesh::updateNormals(const PositionData &pd, const unsigned int offset) { m_normals.resize(numFaces()); #pragma omp parallel default(shared) { #pragma omp for schedule(static) for (int i = 0; i < (int) numFaces(); i++) { // Get first three points of face const Vector3r &a = pd.getPosition(m_indices[m_verticesPerFace*i] + offset); const Vector3r &b = pd.getPosition(m_indices[m_verticesPerFace*i + 1] + offset); const Vector3r &c = pd.getPosition(m_indices[m_verticesPerFace*i + 2] + offset); // Create normal Vector3r v1 = b - a; Vector3r v2 = c - a; m_normals[i] = v1.cross(v2); m_normals[i].normalize(); // fix normals of degenerate triangles that can become zero vectors if (m_normals[i].squaredNorm() < 1e-6f) m_normals[i] = Vector3r::UnitX(); } } } template<class PositionData> void IndexedFaceMesh::updateVertexNormals(const PositionData &pd) { m_vertexNormals.resize(numVertices()); for (unsigned int i = 0; i < numVertices(); i++) { m_vertexNormals[i].setZero(); } for (unsigned int i = 0u; i < numFaces(); i++) { const Vector3r &n = m_normals[i]; m_vertexNormals[m_indices[m_verticesPerFace*i]] += n; m_vertexNormals[m_indices[m_verticesPerFace*i + 1]] += n; m_vertexNormals[m_indices[m_verticesPerFace*i + 2]] += n; } for (unsigned int i = 0; i < numVertices(); i++) { m_vertexNormals[i].normalize(); } } } #endif
wave_generator.h
// // Project Name: Kratos // Last Modified by: $Author: pooyan $ // Date: $Date: 2006-11-27 16:07:33 $ // Revision: $Revision: 1.1.1.1 $ // // #if !defined(KRATOS_WAVEGENERATOR_H_INCLUDED ) #define KRATOS_WAVEGENERATOR_H_INCLUDED // System includes #include <string> #include <iostream> // External includes // Project includes #include "includes/define.h" namespace Kratos { ///@name Kratos Globals ///@{ ///@} ///@name Type Definitions ///@{ ///@} ///@name Enum's ///@{ ///@} ///@name Functions ///@{ ///@} ///@name Kratos Classes ///@{ /// Short class definition. /** Detail class definition. */ class WaveGenerator { public: ///@name Type Definitions ///@{ /// Pointer definition of WaveGenerator KRATOS_CLASS_POINTER_DEFINITION(WaveGenerator); ///@} ///@name Life Cycle ///@{ /// Default constructor. WaveGenerator() {} /// Destructor. virtual ~WaveGenerator() {} void GenerateWaveXYPlane(ModelPart::NodesContainerType& rNodes, const double d, const double H, const double T, const double Z0, const double t, const double g) { double C0=g*T/( 6.2831853071795862 ); double L0=C0*T; double teta = (-6.2831853071795862*t / T) - (3.1415926535897931 / 2.0); double aux = cosh(6.2831853071795862*d/L0); double ux= 0.5 * H * (g * T / L0) * cos(teta) / aux; double uy= 0.5 * H * (g * T / L0) * sin(teta) / aux; double h=0.5 * H * cos(teta); const PointerVector< Node<3> >::iterator it_begin = rNodes.begin(); array_1d<double,3> temp; #pragma omp parallel for private(temp) for(int i=0; i<static_cast<int>(rNodes.size()); i++) { PointerVector< Node<3> >::iterator it = it_begin + i; const double Z = it->Z(); temp[0] = ux * cosh(6.2831853071795862*(Z - Z0 + d)/L0); temp[1] = 0.0; temp[2] = uy * sinh(6.2831853071795862*(Z - Z0 + d)/L0); const double distance = -h+Z - Z0; it->FastGetSolutionStepValue(DISTANCE,1)= distance; if(distance <= 0) // applying velocity only to dense fluid part noalias(it->FastGetSolutionStepValue(VELOCITY))=temp; } } /** * * @param rNodes Nodes of the plane we want to apply the wave * @param d Depth of water * @param H height of wave (2 * a) * @param T Period of wave * @param Z0 Level of natural free surface * @param X0 Plane x * @param t current time * @param g gravity */ void GenerateVolumeWaveXYPlane(ModelPart::NodesContainerType& rNodes, const double d, const double H, const double T, const double Z0, const double X0, const double t, const double g) { double C0=g*T/( 6.2831853071795862 ); double L0=C0*T; const PointerVector< Node<3> >::iterator it_begin = rNodes.begin(); array_1d<double,3> temp; array_1d<double,3> velocity; #pragma omp parallel for private(temp, velocity) for(int i=0; i<static_cast<int>(rNodes.size()); i++) { PointerVector< Node<3> >::iterator it = it_begin + i; const double x = it->X(); const double Z = it->Z(); const double alpha = (x - X0) / L0; double beta = 0.8 + 0.199 * alpha * 2.; if(alpha < 0.01) beta = 0.00; double teta = (-6.2831853071795862*t / T) + (3.1415926535897931 * 2.0 * alpha) + (3.1415926535897931 / 2.0); double aux = cosh(6.2831853071795862*d/L0); double ux= 0.5 * H * (g * T / L0) * cos(teta) / aux; double uy= 0.5 * H * (g * T / L0) * sin(teta) / aux; double h=0.5 * H * cos(teta); temp[0] = ux * cosh(6.2831853071795862*(Z - Z0 + d)/L0); temp[1] = 0.0; temp[2] = uy * sinh(6.2831853071795862*(Z - Z0 + d)/L0); const double node_distance = it->FastGetSolutionStepValue(DISTANCE,1); const double distance = -h+Z - Z0; if((t / T) > alpha ) it->FastGetSolutionStepValue(DISTANCE,1)= node_distance * beta + (1-beta) * distance; // if(distance <= 0) // correcting the pressure only to dense fluid part // it->FastGetSolutionStepValue(PRESSURE)= -distance * 1000; noalias(velocity) = it->FastGetSolutionStepValue(VELOCITY) * beta; if((t / T) > alpha ) if(distance <= 0) // applying velocity only to dense fluid part noalias(it->FastGetSolutionStepValue(VELOCITY))=velocity + (1 - beta) * temp; } } void GenerateComposedVolumeWaveXYPlane(ModelPart::NodesContainerType& rNodes, const double d, const Vector& HVector, const Vector& TVector, const Vector& PhaseVector, const double Z0, const double X0, const double t, const double Length) { unsigned int number_of_waves; if (HVector.size() <= TVector.size()) number_of_waves = HVector.size(); else number_of_waves = TVector.size(); const double g = 9.81; const PointerVector< Node < 3 > >::iterator it_begin = rNodes.begin(); array_1d<double, 3 > wave_velocity; array_1d<double, 3 > velocity; #pragma omp parallel for private(wave_velocity,velocity) for (int i = 0; i<static_cast<int> (rNodes.size()); i++) { PointerVector< Node < 3 > >::iterator it = it_begin + i; const double x = it->X(); const double Z = it->Z(); wave_velocity = ZeroVector(3); double wave_h = 0.00; double beta = (x - X0) / Length; double gamma = 0.8 + 0.199 * beta * 2.0; if (gamma > 1.00) gamma = 1.00; if (beta < 0.1) gamma = 8.00 * beta; bool wave_arrived = false; for (unsigned int i_wave = 0; i_wave < number_of_waves; i_wave++) { const double T = TVector[i_wave]; const double H = HVector[i_wave]; double C0 = g * T / (6.2831853071795862); double L0 = C0*T; const double alpha = (x - X0) / L0; if((t / T) > alpha) wave_arrived = true; double teta = (-6.2831853071795862 * t / T) + (3.1415926535897931 * 2.0 * alpha) + (3.1415926535897931 / 2.0) + PhaseVector[i_wave]; double aux = cosh(6.2831853071795862 * d / L0); double ux = 0.5 * H * (g * T / L0) * cos(teta) / aux; double uy = 0.5 * H * (g * T / L0) * sin(teta) / aux; double h = 0.5 * H * cos(teta); if ((t / T) > alpha) { wave_velocity[0] += ux * cosh(6.2831853071795862 * (Z - Z0 + d) / L0); wave_velocity[1] = 0.0; wave_velocity[2] += uy * sinh(6.2831853071795862 * (Z - Z0 + d) / L0); } if ((t / T) > alpha) wave_h += h; } const double node_distance = it->FastGetSolutionStepValue(DISTANCE, 1); double distance = -wave_h + Z - Z0; if(wave_arrived) it->FastGetSolutionStepValue(DISTANCE, 1) = node_distance * gamma + (1 - gamma) * distance; // if(distance <= 0) // correcting the pressure only to dense fluid part // it->FastGetSolutionStepValue(PRESSURE)= -distance * 1000; noalias(velocity) = it->FastGetSolutionStepValue(VELOCITY) * gamma; if(wave_arrived) if (distance <= 0) // applying velocity only to dense fluid part noalias(it->FastGetSolutionStepValue(VELOCITY)) = velocity + (1 - gamma) * wave_velocity; } } ///@} ///@name Operators ///@{ ///@} ///@name Operations ///@{ ///@} ///@name Access ///@{ ///@} ///@name Inquiry ///@{ ///@} ///@name Input and output ///@{ /// Turn back information as a string. virtual std::string Info() const { std::stringstream buffer; buffer << "WaveGenerator" ; return buffer.str(); } /// Print information about this object. virtual void PrintInfo(std::ostream& rOStream) const { rOStream << "WaveGenerator"; } /// Print object's data. virtual void PrintData(std::ostream& rOStream) const {} ///@} ///@name Friends ///@{ ///@} protected: ///@name Protected static Member Variables ///@{ ///@} ///@name Protected member Variables ///@{ ///@} ///@name Protected Operators ///@{ ///@} ///@name Protected Operations ///@{ ///@} ///@name Protected Access ///@{ ///@} ///@name Protected Inquiry ///@{ ///@} ///@name Protected LifeCycle ///@{ ///@} private: ///@name Static Member Variables ///@{ ///@} ///@name Member Variables ///@{ ///@} ///@name Private Operators ///@{ ///@} ///@name Private Operations ///@{ ///@} ///@name Private Access ///@{ ///@} ///@name Private Inquiry ///@{ ///@} ///@name Un accessible methods ///@{ /// Assignment operator. WaveGenerator& operator=(WaveGenerator const& rOther) { return *this; } /// Copy constructor. WaveGenerator(WaveGenerator const& rOther) {}; ///@} }; // Class WaveGenerator ///@} ///@name Type Definitions ///@{ ///@} ///@name Input and output ///@{ /// input stream function inline std::istream& operator >> (std::istream& rIStream, WaveGenerator& rThis) { return rIStream; } /// output stream function inline std::ostream& operator << (std::ostream& rOStream, const WaveGenerator& rThis) { rThis.PrintInfo(rOStream); rOStream << std::endl; rThis.PrintData(rOStream); return rOStream; } ///@} } // namespace Kratos. #endif // KRATOS_WAVEGENERATOR_H_INCLUDED defined