source
stringlengths
3
92
c
stringlengths
26
2.25M
cancel_worksharing.c
// RUN: %libomp-compile && env OMP_CANCELLATION=true %libomp-run | %sort-threads | FileCheck %s // REQUIRES: ompt // Current GOMP interface implementation does not support cancellation; icc 16 does not distinguish between sections and loops // XFAIL: gcc, icc-16 #include "callback.h" #include <unistd.h> int main() { int condition=0; #pragma omp parallel num_threads(2) { int x = 0; int i; #pragma omp for for(i = 0; i < 2; i++) { if(i == 0) { x++; OMPT_SIGNAL(condition); #pragma omp cancel for } else { x++; OMPT_WAIT(condition,1); delay(10000); #pragma omp cancellation point for } } } #pragma omp parallel num_threads(2) { #pragma omp sections { #pragma omp section { OMPT_SIGNAL(condition); #pragma omp cancel sections } #pragma omp section { OMPT_WAIT(condition,2); delay(10000); #pragma omp cancellation point sections } } } // Check if libomp supports the callbacks for this test. // CHECK-NOT: {{^}}0: Could not register callback 'ompt_callback_task_create' // CHECK-NOT: {{^}}0: Could not register callback 'ompt_callback_cancel' // CHECK: {{^}}0: NULL_POINTER=[[NULL:.*$]] // CHECK: {{^}}[[MASTER_ID:[0-9]+]]: ompt_event_task_create: parent_task_id=[[PARENT_TASK_ID:[0-9]+]], parent_task_frame.exit=[[NULL]], parent_task_frame.reenter=[[NULL]], new_task_id=[[TASK_ID:[0-9]+]], codeptr_ra=[[NULL]], task_type=ompt_task_initial=1, has_dependences=no // cancel for and sections // CHECK: {{^}}[[MASTER_ID]]: ompt_event_cancel: task_data=[[TASK_ID:[0-9]+]], flags=ompt_cancel_loop|ompt_cancel_activated=20, codeptr_ra={{0x[0-f]*}} // CHECK: {{^}}[[MASTER_ID]]: ompt_event_cancel: task_data=[[TASK_ID:[0-9]+]], flags=ompt_cancel_sections|ompt_cancel_activated=18, codeptr_ra={{0x[0-f]*}} // CHECK: {{^}}[[OTHER_THREAD_ID:[0-9]+]]: ompt_event_cancel: task_data=[[TASK_ID:[0-9]+]], flags=ompt_cancel_loop|ompt_cancel_detected=36, codeptr_ra={{0x[0-f]*}} // CHECK: {{^}}[[OTHER_THREAD_ID:[0-9]+]]: ompt_event_cancel: task_data=[[TASK_ID:[0-9]+]], flags=ompt_cancel_sections|ompt_cancel_detected=34, codeptr_ra={{0x[0-f]*}} return 0; }
explicit_task.c
// RUN: %libomp-compile-and-run | %sort-threads | tee %s.out | FileCheck %s // REQUIRES: ompt // UNSUPPORTED: gcc-4, gcc-5, gcc-6, gcc-7 #define TEST_NEED_PRINT_FRAME_FROM_OUTLINED_FN #include "callback.h" #include <omp.h> int main() { int condition=0; omp_set_nested(0); print_frame(0); #pragma omp parallel num_threads(2) { print_frame_from_outlined_fn(1); print_ids(0); print_ids(1); print_frame(0); #pragma omp master { print_ids(0); #pragma omp task shared(condition) { OMPT_SIGNAL(condition); print_frame(1); print_ids(0); print_ids(1); print_ids(2); } print_fuzzy_address(1); OMPT_WAIT(condition,1); print_ids(0); } #pragma omp barrier print_ids(0); } // Check if libomp supports the callbacks for this test. // CHECK-NOT: {{^}}0: Could not register callback 'ompt_callback_task_create' // CHECK-NOT: {{^}}0: Could not register callback 'ompt_callback_task_schedule' // CHECK-NOT: {{^}}0: Could not register callback 'ompt_callback_parallel_begin' // CHECK-NOT: {{^}}0: Could not register callback 'ompt_callback_parallel_end' // CHECK-NOT: {{^}}0: Could not register callback 'ompt_callback_implicit_task' // CHECK-NOT: {{^}}0: Could not register callback 'ompt_callback_mutex_acquire' // CHECK-NOT: {{^}}0: Could not register callback 'ompt_callback_mutex_acquired' // CHECK-NOT: {{^}}0: Could not register callback 'ompt_callback_mutex_released' // CHECK: {{^}}0: NULL_POINTER=[[NULL:.*$]] // make sure initial data pointers are null // CHECK-NOT: 0: new_task_data initially not null // CHECK--doesnotwork: {{^}}[[MASTER_ID:[0-9]+]]: __builtin_frame_address(0)=[[MAIN_REENTER:0x[0-f]+]] // CHECK: {{^}}[[MASTER_ID:[0-9]+]]: ompt_event_parallel_begin: parent_task_id=[[PARENT_TASK_ID:[0-9]+]], parent_task_frame.exit=[[NULL]], parent_task_frame.reenter=0x{{[0-f]+}}, parallel_id=[[PARALLEL_ID:[0-9]+]], requested_team_size=2, codeptr_ra=0x{{[0-f]+}}, invoker=[[PARALLEL_INVOKER:[0-9]+]] // nested parallel masters // CHECK: {{^}}[[MASTER_ID]]: ompt_event_implicit_task_begin: parallel_id=[[PARALLEL_ID]], task_id=[[IMPLICIT_TASK_ID:[0-9]+]] // CHECK: {{^}}[[MASTER_ID]]: __builtin_frame_address({{.}})=[[EXIT:0x[0-f]+]] // CHECK: {{^}}[[MASTER_ID]]: task level 0: parallel_id=[[PARALLEL_ID]], task_id=[[IMPLICIT_TASK_ID]], exit_frame=[[EXIT]], reenter_frame=[[NULL]] // CHECK: {{^}}[[MASTER_ID]]: task level 1: parallel_id=[[IMPLICIT_PARALLEL_ID:[0-9]+]], task_id=[[PARENT_TASK_ID]], exit_frame=[[NULL]], reenter_frame=0x{{[0-f]+}} // CHECK: {{^}}[[MASTER_ID]]: __builtin_frame_address(0)=[[REENTER:0x[0-f]+]] // CHECK: {{^}}[[MASTER_ID]]: task level 0: parallel_id=[[PARALLEL_ID]], task_id=[[IMPLICIT_TASK_ID]], exit_frame=[[EXIT]], reenter_frame=[[NULL]] // <- ompt_event_task_create would be expected here // CHECK: {{^}}[[MASTER_ID]]: ompt_event_task_create: parent_task_id=[[IMPLICIT_TASK_ID]], parent_task_frame.exit=[[EXIT]], parent_task_frame.reenter=0x{{[0-f]+}}, new_task_id=[[TASK_ID:[0-9]+]], codeptr_ra=[[RETURN_ADDRESS:0x[0-f]+]]{{[0-f][0-f]}} // CHECK: {{^}}[[MASTER_ID]]: fuzzy_address={{.*}}[[RETURN_ADDRESS]] // CHECK: {{^}}[[MASTER_ID]]: task level 0: parallel_id=[[PARALLEL_ID]], task_id=[[IMPLICIT_TASK_ID]], exit_frame=[[EXIT]], reenter_frame=[[NULL]] // explicit barrier after master // CHECK: {{^}}[[MASTER_ID]]: ompt_event_barrier_begin: parallel_id=[[PARALLEL_ID]], task_id=[[IMPLICIT_TASK_ID]] // CHECK: {{^}}[[MASTER_ID]]: task level 0: parallel_id=[[PARALLEL_ID]], task_id=[[IMPLICIT_TASK_ID]], exit_frame=[[EXIT]], reenter_frame=0x{{[0-f]+}} // CHECK: {{^}}[[MASTER_ID]]: ompt_event_barrier_end: parallel_id=[[PARALLEL_ID]], task_id=[[IMPLICIT_TASK_ID]] // implicit barrier parallel // CHECK: {{^}}[[MASTER_ID]]: ompt_event_barrier_begin: parallel_id=[[PARALLEL_ID]], task_id=[[IMPLICIT_TASK_ID]] // CHECK: {{^}}[[MASTER_ID]]: task level 0: parallel_id=[[PARALLEL_ID]], task_id=[[IMPLICIT_TASK_ID]], exit_frame=[[NULL]], reenter_frame=[[NULL]] // CHECK: {{^}}[[MASTER_ID]]: ompt_event_barrier_end: parallel_id={{[0-9]+}}, task_id=[[IMPLICIT_TASK_ID]] // CHECK: {{^}}[[MASTER_ID]]: ompt_event_implicit_task_end: parallel_id={{[0-9]+}}, task_id=[[IMPLICIT_TASK_ID]] // CHECK: {{^}}[[THREAD_ID:[0-9]+]]: ompt_event_implicit_task_begin: parallel_id=[[PARALLEL_ID]], task_id=[[IMPLICIT_TASK_ID:[0-9]+]] // CHECK: {{^}}[[THREAD_ID]]: __builtin_frame_address({{.}})=[[EXIT:0x[0-f]+]] // CHECK: {{^}}[[THREAD_ID]]: task level 0: parallel_id=[[PARALLEL_ID]], task_id=[[IMPLICIT_TASK_ID]], exit_frame=[[EXIT]], reenter_frame=[[NULL]] // CHECK: {{^}}[[THREAD_ID]]: task level 1: parallel_id=[[IMPLICIT_PARALLEL_ID]], task_id=[[PARENT_TASK_ID]], exit_frame=[[NULL]], reenter_frame=0x{{[0-f]+}} // CHECK: {{^}}[[THREAD_ID]]: __builtin_frame_address(0)=[[REENTER:0x[0-f]+]] // CHECK: {{^}}[[THREAD_ID]]: ompt_event_barrier_begin: parallel_id=[[PARALLEL_ID]], task_id=[[IMPLICIT_TASK_ID]] // CHECK: {{^}}[[THREAD_ID]]: task level 0: parallel_id=[[PARALLEL_ID]], task_id=[[IMPLICIT_TASK_ID]], exit_frame=[[EXIT]], reenter_frame=0x{{[0-f]+}} // this is expected to come earlier and at MASTER: // CHECK: {{^}}[[THREAD_ID]]: ompt_event_task_schedule: first_task_id=[[IMPLICIT_TASK_ID]], second_task_id=[[TASK_ID]] // CHECK: {{^}}[[THREAD_ID]]: __builtin_frame_address(1)=[[TASK_EXIT:0x[0-f]+]] // CHECK: {{^}}[[THREAD_ID]]: task level 0: parallel_id=[[PARALLEL_ID]], task_id=[[TASK_ID]], exit_frame=[[TASK_EXIT]], reenter_frame=[[NULL]] // CHECK: {{^}}[[THREAD_ID]]: task level 1: parallel_id=[[PARALLEL_ID]], task_id=[[IMPLICIT_TASK_ID]], exit_frame=[[EXIT]], reenter_frame=0x{{[0-f]+}} // CHECK: {{^}}[[THREAD_ID]]: task level 2: parallel_id=[[IMPLICIT_PARALLEL_ID]], task_id=[[PARENT_TASK_ID]], exit_frame=[[NULL]], reenter_frame=0x{{[0-f]+}} // CHECK: {{^}}[[THREAD_ID]]: ompt_event_task_schedule: first_task_id=[[TASK_ID]], second_task_id=[[IMPLICIT_TASK_ID]] // CHECK: {{^}}[[THREAD_ID]]: ompt_event_task_end: task_id=[[TASK_ID]] // CHECK: {{^}}[[THREAD_ID]]: ompt_event_barrier_end: parallel_id=[[PARALLEL_ID]], task_id=[[IMPLICIT_TASK_ID]] // CHECK: {{^}}[[THREAD_ID]]: ompt_event_barrier_begin: parallel_id=[[PARALLEL_ID]], task_id=[[IMPLICIT_TASK_ID]] // CHECK: {{^}}[[THREAD_ID]]: task level 0: parallel_id=[[PARALLEL_ID]], task_id=[[IMPLICIT_TASK_ID]], exit_frame=[[NULL]], reenter_frame=[[NULL]] // CHECK: {{^}}[[THREAD_ID]]: ompt_event_barrier_end: parallel_id={{[0-9]+}}, task_id=[[IMPLICIT_TASK_ID]] // CHECK: {{^}}[[THREAD_ID]]: ompt_event_implicit_task_end: parallel_id={{[0-9]+}}, task_id=[[IMPLICIT_TASK_ID]] return 0; }
quadtree.h
#pragma once #include "common.h" #include <vector> #include <queue> #include <iostream> #include <string> #include <omp.h> struct quadnode; typedef quadnode* nodeptr; struct quadnode { nodeptr child[4]; double centerx, centery, xmin, xmax, ymin, ymax, totalMass = 0; particleptr within = NULL; int npar = 0; std::string name; quadnode(double xmin, double xmax, double ymin, double ymax, std::string name) { this->xmin = xmin; this->xmax = xmax; this->ymin = ymin; this->ymax = ymax; this->name = name; this->centerx = this->centery = 0; this->child[0] = this->child[1] = this->child[2] = this->child[3] = NULL; } bool incell(double x, double y) & { return (x > this->xmin && x <= this->xmax) && (y > this->ymin && y <= this->ymax); } void make() { double xhalf = (this->xmin + this->xmax) / 2., yhalf = (this->ymin + this->ymax) / 2.; this->child[0] = new quadnode(this->xmin, xhalf, this->ymin, yhalf, this->name + ".0"); this->child[1] = new quadnode(this->xmin, xhalf, yhalf, this->ymax, this->name + ".1"); this->child[2] = new quadnode(xhalf, this->xmax, this->ymin, yhalf, this->name + ".2"); this->child[3] = new quadnode(xhalf, this->xmax, yhalf, this->ymax, this->name + ".3"); } void add(const particle& par) { if (!this->incell(par.x, par.y)) return; if (this->npar > 0) { if (this->npar == 1) { this->make(); for (int i = 0; i < 4; i++) (this->child[i])->add(*(this->within)); this->within = NULL; } for (int i = 0; i < 4; i++) (this->child[i])->add(par); } else { this->within = (particleptr)&par; } this->centerx = (this->npar * this->centerx + par.x) / double(this->npar + 1); this->centery = (this->npar * this->centery + par.y) / double(this->npar + 1); this->npar++; this->totalMass += par.mass; } void make_parallel() { double xhalf = (this->xmin + this->xmax) / 2., yhalf = (this->ymin + this->ymax) / 2.; //#pragma omp parallel { double a[4] = { this->xmin , this->xmin , xhalf , xhalf }; double b[4] = { xhalf , xhalf , this->xmax , this->xmax }; double c[4] = { this->ymin, yhalf ,this->ymin, yhalf }; double d[4] = { yhalf ,this->ymax, yhalf, this->ymax }; //#pragma omp for for (int i = 0; i < 4; i++) this->child[i] = new quadnode(a[i], b[i], c[i], d[i], "");//this->name + "." + std::to_string(i) } } void add_parallel(const particle& par, int depth) { if (!this->incell(par.x, par.y)) return; if (this->npar > 0) { if (this->npar == 1) { this->make_parallel(); if (depth < DEPTH_LIM) { //#pragma omp parallel { //#pragma omp for for (int i = 0; i < 4; i++) (this->child[i])->add_parallel(*(this->within), depth + 1); } } else { for (int i = 0; i < 4; i++) (this->child[i])->add(*(this->within)); } this->within = NULL; } if (depth < DEPTH_LIM) { //#pragma omp parallel { //#pragma omp for for (int i = 0; i < 4; i++) (this->child[i])->add_parallel(par, depth + 1); } } else { for (int i = 0; i < 4; i++) (this->child[i])->add(par); } } else { this->within = (particleptr)&par; } this->centerx = (this->npar * this->centerx + par.x) / double(this->npar + 1); this->centery = (this->npar * this->centery + par.y) / double(this->npar + 1); this->npar++; this->totalMass += par.mass; } bool test(const particle& par) { if (this->child[0] != NULL) { double s = this->xmax - this->xmin; double dx = par.x - this->centerx; double dy = par.y - this->centery; double dist = sqrt(dx * dx + dy * dy); return dist / s > tree_thres && dist > softening; } else { return this->within != &par; } } std::vector<particleptr> all() { if (this->within != NULL) { std::vector<particleptr> result; result.push_back(this->within); return result; } else { std::vector<particleptr> result; for (int i = 0; i < 4; i++) if (this->child[i] != NULL) { std::vector<particleptr> subresult = (this->child[i])->all(); result.insert(result.end(), subresult.begin(), subresult.end()); } return result; } } std::vector<particleptr> all_parallel() { if (this->within != NULL) { std::vector<particleptr> result; result.push_back(this->within); return result; } else { std::vector<particleptr> result; #pragma omp parallel { #pragma omp for for (int i = 0; i < 4; i++) if (this->child[i] != NULL) { std::vector<particleptr> subresult = (this->child[i])->all(); result.insert(result.end(), subresult.begin(), subresult.end()); } } return result; } } void printtree() { std::cout << this->name << std::endl; for (int i = 0; i < 4; i++) if (this->child[i] != NULL) this->child[i]->printtree(); } void update(particle& par)& { double rx = this->centerx - par.x; double ry = this->centery - par.y; double r2 = softensqdist(rx * rx + ry * ry); par.vx += newton_g * timestep * this->npar * this->totalMass / par.mass / r2 / sqrt(r2) * rx; par.vy += newton_g * timestep * this->npar * this->totalMass / par.mass / r2 / sqrt(r2) * ry; } };
convolution_1x1_int8.h
// BUG1989 is pleased to support the open source community by supporting ncnn available. // // author:BUG1989 (https://github.com/BUG1989/) Long-term support. // author:FuGuangping (https://github.com/fu1899) Implemented the first version of INT8 quantization on ARMv7. // // Copyright (C) 2019 BUG1989. 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 inline signed char float2int8(float v) { int int32 = round(v); if (int32 > 127) return 127; if (int32 < -127) return -127; return (signed char)int32; } #if __aarch64__ #if 1 #include "gemm_symm_int8.h" static void conv1x1s1_sgemm_transform_kernel_int8_neon(const Mat& _kernel, Mat& kernel_tm, int inch, int outch) { kernel_tm.create(outch, inch, (size_t)1u); const int8_t *a = _kernel; int8_t *sa = kernel_tm; reorder_a((int8_t*)a, sa, outch, inch, inch); } static void conv1x1s1_sgemm_int8_neon(const Mat& bottom_blob, Mat& top_blob, const Mat& kernel, const Option& opt) { const size_t n = bottom_blob.w * bottom_blob.h; const size_t k = bottom_blob.c; const size_t m = top_blob.c; Mat bottom_tm(k * n, (size_t)1u, opt.workspace_allocator); { const int8_t* pData = bottom_blob; int8_t *pReorder = bottom_tm; reorder_b(pData, pReorder, k, n, bottom_blob.cstep); } // GEMM int32_t *pc = top_blob; const int8_t *pa = kernel; const int8_t *pb = bottom_tm; const size_t ldc = top_blob.cstep; int8kernel((void*)pc, pa, pb, m, k, n, ldc, 0, 0, opt); } static void conv1x1s1_sgemm_int8_requant_neon(const Mat &bottom_blob, Mat &top_blob, const Mat &kernel, const Mat &_bias, std::vector<float> scales_requant, const Option& opt) { const size_t n = bottom_blob.w * bottom_blob.h; const size_t k = bottom_blob.c; const size_t m = top_blob.c; Mat scales_tm(m); Mat bias_tm(m); float* scales = scales_tm; const float* bias = _bias; // outptr0[0] = float2int8(((float)sum0 * scale_requant_in + bias0) * scale_requant_out); // the equation could convert to: // out = float2int8( (float)sum * (scale_requant_in * scale_requant_out) + (bias * scale_requant_out) ) // prebuild the list of (scales_requant_in*scale_requant_out) for (size_t i = 0; i < m; ++i) { scales_tm[i] = scales_requant[2*i] * scales_requant[2*i + 1]; } if (!_bias.empty()) { for (size_t i = 0; i < m; ++i) { bias_tm[i] = bias[i] * scales_requant[2*i + 1]; } bias = bias_tm; } Mat bottom_tm(k * n, (size_t)1u, opt.workspace_allocator); { const int8_t *pData = bottom_blob; int8_t *pReorder = bottom_tm; reorder_b(pData, pReorder, k, n, bottom_blob.cstep); } // GEMM int8_t *pc = top_blob; const int8_t *pa = kernel; const int8_t *pb = bottom_tm; const size_t ldc = top_blob.cstep; int8kernel((void*)pc, pa, pb, m, k, n, ldc, scales, (float*)bias, opt); } #else static void conv1x1s1_sgemm_transform_kernel_int8_neon(const Mat& _kernel, Mat& kernel_tm, int inch, int outch) { const signed char* kernel = _kernel; // kernel memory packed 4 x 4 kernel_tm.create(4*4, inch/4 + inch%4, outch/4 + outch%4, (size_t)1u); int nn_outch = 0; int remain_outch_start = 0; nn_outch = outch >> 2; remain_outch_start = nn_outch << 2; for (int pp=0; pp<nn_outch; pp++) { int p = pp * 4; const signed char* k0 = kernel + (p+0)*inch; const signed char* k1 = kernel + (p+1)*inch; const signed char* k2 = kernel + (p+2)*inch; const signed char* k3 = kernel + (p+3)*inch; signed char* ktmp = kernel_tm.channel(p/4); int q=0; for (; q+1<inch; q+=2) { ktmp[0] = k0[0]; ktmp[1] = k0[1]; ktmp[2] = k1[0]; ktmp[3] = k1[1]; ktmp[4] = k2[0]; ktmp[5] = k2[1]; ktmp[6] = k3[0]; ktmp[7] = k3[1]; ktmp += 8; k0 += 2; k1 += 2; k2 += 2; k3 += 2; } for (; q<inch; q++) { ktmp[0] = k0[0]; ktmp[1] = k1[0]; ktmp[2] = k2[0]; ktmp[3] = k3[0]; ktmp += 4; k0 += 1; k1 += 1; k2 += 1; k3 += 1; } } for (int p=remain_outch_start; p<outch; p++) { const signed char* k0 = kernel + (p+0)*inch; signed char* ktmp = kernel_tm.channel(p/4 + p%4); int q=0; for (; q+1<inch; q=q+2) { ktmp[0] = k0[0]; ktmp[1] = k0[1]; ktmp += 2; k0 += 2; } for (; q<inch; q++) { ktmp[0] = k0[0]; ktmp++; k0++; } } } static void conv1x1s1_sgemm_int8_neon(const Mat& bottom_blob, Mat& top_blob, const Mat& kernel, const Option& opt) { int w = bottom_blob.w; int h = bottom_blob.h; int inch = bottom_blob.c; int outch = top_blob.c; const int size = w * h; // bottom_tm memory packed 4 x 4 Mat bottom_tm(4, inch, size/4 + size%4, (size_t)1u, opt.workspace_allocator); { int nn_size = size >> 2; int remain_size_start = nn_size << 2; #pragma omp parallel for num_threads(opt.num_threads) for (int ii=0; ii<nn_size; ii++) { int i = ii * 4; const signed char* img0 = bottom_blob.channel(0); const signed char* img1 = bottom_blob.channel(1); img0 += i; img1 += i; signed char* tmpptr = bottom_tm.channel(i/4); int q = 0; for (; q+1<inch; q=q+2) { tmpptr[0] = img0[0]; tmpptr[1] = img1[0]; tmpptr[2] = img0[1]; tmpptr[3] = img1[1]; tmpptr[4] = img0[2]; tmpptr[5] = img1[2]; tmpptr[6] = img0[3]; tmpptr[7] = img1[3]; tmpptr += 8; img0 += bottom_blob.cstep; img0 += bottom_blob.cstep; img1 += bottom_blob.cstep; img1 += bottom_blob.cstep; } for (; q<inch; q++) { tmpptr[0] = img0[0]; tmpptr[1] = img0[1]; tmpptr[2] = img0[2]; tmpptr[3] = img0[3]; tmpptr += 4; img0 += bottom_blob.cstep; } } #pragma omp parallel for num_threads(opt.num_threads) for (int i=remain_size_start; i<size; i++) { const signed char* img0 = bottom_blob.channel(0); img0 += i; signed char* tmpptr = bottom_tm.channel(i/4 + i%4); for (int q=0; q<inch; q++) { tmpptr[0] = img0[0]; tmpptr += 1; img0 += bottom_blob.cstep; } } } // sgemm process int nn_outch = 0; int remain_outch_start = 0; nn_outch = outch >> 2; remain_outch_start = nn_outch << 2; #pragma omp parallel for num_threads(opt.num_threads) for (int pp=0; pp<nn_outch; pp++) { int p = pp * 4; int* outptr0 = top_blob.channel(p); int* outptr1 = top_blob.channel(p+1); int* outptr2 = top_blob.channel(p+2); int* outptr3 = top_blob.channel(p+3); int i = 0; for (; i+3<size; i+=4) { signed char* tmpptr = bottom_tm.channel(i/4); const signed char* kptr = kernel.channel(p/4); #if __ARM_NEON asm volatile( "prfm pldl1keep, [%4, #128] \n" "prfm pldl1keep, [%5, #128] \n" "eor v16.16b, v16.16b, v16.16b \n" // sum0 "eor v17.16b, v17.16b, v17.16b \n" // sum1 "eor v18.16b, v18.16b, v18.16b \n" // sum2 "eor v19.16b, v19.16b, v19.16b \n" // sum3 "lsr w4, %w12, #2 \n"// r4 = nn = L >> 2 "cmp w4, #0 \n" "beq 1f \n" "0: \n"// for (; k+3<L; k=k+4) "ld1 {v0.16b}, [%4] \n"// i0, i1, i2, i3 "ld1 {v4.16b}, [%5] \n"// k0, k1, k2, k3 "add %4, %4, #16 \n" "add %5, %5, #16 \n" "rev32 v1.8h, v0.8h \n"// i1, i0, i3, i2 "rev64 v2.4s, v0.4s \n"// i2, i3, i0, i1 "rev64 v3.8h, v0.8h \n"// i3, i2, i1, i0 "smull v8.8h, v4.8b, v0.8b \n" "smull v9.8h, v4.8b, v1.8b \n" "smull v10.8h, v4.8b, v2.8b \n" "smull v11.8h, v4.8b, v3.8b \n" "prfm pldl1keep, [%4, #1024] \n" "prfm pldl1keep, [%5, #1024] \n" "smlal2 v8.8h, v4.16b, v0.16b \n" "smlal2 v9.8h, v4.16b, v1.16b \n" "smlal2 v10.8h, v4.16b, v2.16b \n" "smlal2 v11.8h, v4.16b, v3.16b \n" "sadalp v16.4s, v8.8h \n"// i0k0, i1k1, i2k2, i3k3 "sadalp v17.4s, v9.8h \n"// i1k0, i0k1, i3k2, i2k3 "sadalp v18.4s, v10.8h \n"// i2k0, i3k1, i0k2, i1k3 "sadalp v19.4s, v11.8h \n"// i3k0, i2k1, i1k2, i0k3 "subs w4, w4, #1 \n" "bne 0b \n" "1: \n"// for (; k+1<L; k=k+2) // remain loop "and w4, %w12, #3 \n"// w4 = remain = K & 3; "cmp w4, #0 \n" "beq 3f \n" "lsr w4, w4, #1 \n"// r4 = nn = L >> 1 "cmp w4, #0 \n" "beq 3f \n" "2: \n"// for (; k+1<L; k=k+2) "ld1 {v0.8b}, [%4] \n"// i0, i1, i2, i3 "ld1 {v4.8b}, [%5] \n"// k0, k1, k2, k3 "add %4, %4, #8 \n" "add %5, %5, #8 \n" "rev32 v1.4h, v0.4h \n"// i2, i3, i0, i1 "rev64 v2.2s, v0.2s \n"// i1, i0, i3, i2 "rev64 v3.4h, v0.4h \n"// i0, i1, i2, i3 "smull v8.8h, v4.8b, v0.8b \n" "smull v9.8h, v4.8b, v1.8b \n" "smull v10.8h, v4.8b, v2.8b \n" "smull v11.8h, v4.8b, v3.8b \n" "sadalp v16.4s, v8.8h \n" "sadalp v17.4s, v9.8h \n" "sadalp v18.4s,v10.8h \n" "sadalp v19.4s,v11.8h \n" "subs w4, w4, #1 \n" "bne 2b \n" "3: \n"// realloc "mov v20.s[0], v16.s[0] \n" "mov v20.s[1], v17.s[0] \n" "mov v20.s[2], v18.s[0] \n" "mov v20.s[3], v19.s[0] \n" "mov v21.s[0], v17.s[1] \n" "mov v21.s[1], v16.s[1] \n" "mov v21.s[2], v19.s[1] \n" "mov v21.s[3], v18.s[1] \n" "mov v22.s[0], v18.s[2] \n" "mov v22.s[1], v19.s[2] \n" "mov v22.s[2], v16.s[2] \n" "mov v22.s[3], v17.s[2] \n" "mov v23.s[0], v19.s[3] \n" "mov v23.s[1], v18.s[3] \n" "mov v23.s[2], v17.s[3] \n" "mov v23.s[3], v16.s[3] \n" "and w4, %w12, #1 \n"// w4 = remain = K & 1; "cmp w4, #0 \n" "beq 5f \n" "4: \n" "ld1 {v0.8b}, [%4] \n" "ld1 {v1.8b}, [%5] \n" "add %4, %4, #4 \n" "add %5, %5, #4 \n" "sshll v0.8h, v0.8b, #0 \n"// i0[0], i1[0], i2[0], i3[0] "sshll v1.8h, v1.8b, #0 \n"// k0[0], k1[0], k2[0], k3[0] "smlal v20.4s, v0.4h, v1.h[0] \n"// i0k0, i1k0, i2k0, i3k0 "smlal v21.4s, v0.4h, v1.h[1] \n"// i0k1, i1k1, i2k1, i3k1 "smlal v22.4s, v0.4h, v1.h[2] \n"// i0k2, i1k2, i2k2, i3k2 "smlal v23.4s, v0.4h, v1.h[3] \n"// i0k3, i1k3, i2k3, i3k3 "subs w4, w4, #1 \n" "bne 2b \n" "5: \n" "st1 {v20.4s}, [%0] \n" "st1 {v21.4s}, [%1] \n" "st1 {v22.4s}, [%2] \n" "st1 {v23.4s}, [%3] \n" : "=r"(outptr0), // %0 "=r"(outptr1), // %1 "=r"(outptr2), // %2 "=r"(outptr3), // %3 "=r"(tmpptr), // %4 "=r"(kptr) // %5 : "0"(outptr0), "1"(outptr1), "2"(outptr2), "3"(outptr3), "4"(tmpptr), "5"(kptr), "r"(inch) // %12 : "cc", "memory", "x4", "v0", "v1", "v2", "v3", "v4", "v5", "v6", "v7", "v8", "v9", "v10", "v11", "v12", "v13", "v14", "v15", "v16", "v17", "v18", "v19", "v20", "v21", "v22", "v23" ); #else int sum0_0 = 0; int sum0_1 = 0; int sum0_2 = 0; int sum0_3 = 0; int sum1_0 = 0; int sum1_1 = 0; int sum1_2 = 0; int sum1_3 = 0; int sum2_0 = 0; int sum2_1 = 0; int sum2_2 = 0; int sum2_3 = 0; int sum3_0 = 0; int sum3_1 = 0; int sum3_2 = 0; int sum3_3 = 0; int q=0; for (; q+1<inch; q=q+2) { sum0_0 += tmpptr[0] * kptr[0]; sum0_0 += tmpptr[1] * kptr[1]; sum0_1 += tmpptr[2] * kptr[0]; sum0_1 += tmpptr[3] * kptr[1]; sum0_2 += tmpptr[4] * kptr[0]; sum0_2 += tmpptr[5] * kptr[1]; sum0_3 += tmpptr[6] * kptr[0]; sum0_3 += tmpptr[7] * kptr[1]; sum1_0 += tmpptr[0] * kptr[2]; sum1_0 += tmpptr[1] * kptr[3]; sum1_1 += tmpptr[2] * kptr[2]; sum1_1 += tmpptr[3] * kptr[3]; sum1_2 += tmpptr[4] * kptr[2]; sum1_2 += tmpptr[5] * kptr[3]; sum1_3 += tmpptr[6] * kptr[2]; sum1_3 += tmpptr[7] * kptr[3]; sum2_0 += tmpptr[0] * kptr[4]; sum2_0 += tmpptr[1] * kptr[5]; sum2_1 += tmpptr[2] * kptr[4]; sum2_1 += tmpptr[3] * kptr[5]; sum2_2 += tmpptr[4] * kptr[4]; sum2_2 += tmpptr[5] * kptr[5]; sum2_3 += tmpptr[6] * kptr[4]; sum2_3 += tmpptr[7] * kptr[5]; sum3_0 += tmpptr[0] * kptr[6]; sum3_0 += tmpptr[1] * kptr[7]; sum3_1 += tmpptr[2] * kptr[6]; sum3_1 += tmpptr[3] * kptr[7]; sum3_2 += tmpptr[4] * kptr[6]; sum3_2 += tmpptr[5] * kptr[7]; sum3_3 += tmpptr[6] * kptr[6]; sum3_3 += tmpptr[7] * kptr[7]; tmpptr += 8; kptr += 8; } for (; q<inch; q++) { sum0_0 += tmpptr[0] * kptr[0]; sum0_1 += tmpptr[1] * kptr[0]; sum0_2 += tmpptr[2] * kptr[0]; sum0_3 += tmpptr[3] * kptr[0]; sum1_0 += tmpptr[0] * kptr[1]; sum1_1 += tmpptr[1] * kptr[1]; sum1_2 += tmpptr[2] * kptr[1]; sum1_3 += tmpptr[3] * kptr[1]; sum2_0 += tmpptr[0] * kptr[2]; sum2_1 += tmpptr[1] * kptr[2]; sum2_2 += tmpptr[2] * kptr[2]; sum2_3 += tmpptr[3] * kptr[2]; sum3_0 += tmpptr[0] * kptr[3]; sum3_1 += tmpptr[1] * kptr[3]; sum3_2 += tmpptr[2] * kptr[3]; sum3_3 += tmpptr[3] * kptr[3]; tmpptr += 4; kptr += 4; } outptr0[0] = sum0_0; outptr0[1] = sum0_1; outptr0[2] = sum0_2; outptr0[3] = sum0_3; outptr1[0] = sum1_0; outptr1[1] = sum1_1; outptr1[2] = sum1_2; outptr1[3] = sum1_3; outptr2[0] = sum2_0; outptr2[1] = sum2_1; outptr2[2] = sum2_2; outptr2[3] = sum2_3; outptr3[0] = sum3_0; outptr3[1] = sum3_1; outptr3[2] = sum3_2; outptr3[3] = sum3_3; #endif outptr0 += 4; outptr1 += 4; outptr2 += 4; outptr3 += 4; } for (; i<size; i++) { signed char* tmpptr = bottom_tm.channel(i/4 + i%4); const signed char* kptr = kernel.channel(p/4); #if 0//__ARM_NEON int32x4_t _sum = vdupq_n_s32(0); int q=0; for (; q+3<inch; q=q+4) { int8x8_t _r0 = vld1_s8(tmpptr); // i0[0-3] int8x8x2_t _k = vld2_s8(kptr); // k0[0-1], k1[0-1], k2[0-1], k3[0-1];k0[2-3], k1[2-3], k2[2-3], k3[2-3] int16x8_t _r0_s16 = vmovl_s8(_r0); // i0[0],i0[1],i0[2],i0[3] int16x8_t _k02_s16 = vmovl_s8(_k.val[0]); // k0[0],k1[0],k2[0],k3[0],k0[2],k1[2],k2[2],k3[2] int16x8_t _k13_s16 = vmovl_s8(_k.val[1]); // k0[1],k1[1],k2[1],k3[1],k0[3],k1[3],k2[3],k3[3] _sum = vmlal_lane_s16(_sum, vget_low_s16(_k02_s16), vget_low_s16(_r0_s16), 0); // i0[0]*k[0-3][0] _sum = vmlal_lane_s16(_sum, vget_low_s16(_k13_s16), vget_low_s16(_r0_s16), 1); // i0[1]*k[0-3][1] _sum = vmlal_lane_s16(_sum, vget_high_s16(_k02_s16), vget_low_s16(_r0_s16), 2); // i0[2]*k[0-3][2] _sum = vmlal_lane_s16(_sum, vget_high_s16(_k13_s16), vget_low_s16(_r0_s16), 3); // i0[3]*k[0-3][3] tmpptr += 4; kptr += 16; } for (; q+1<inch; q=q+2) { int8x8_t _r0 = vld1_s8(tmpptr); // i0[0-3] int8x8_t _k = vld1_s8(kptr); // k0[0-1], k1[0-1], k2[0-1], k3[0-1] _r0[2] = _r0[0]; _r0[3] = _r0[1]; _r0[4] = _r0[0]; _r0[5] = _r0[1]; _r0[6] = _r0[0]; _r0[7] = _r0[1]; int16x8_t _tp0 = vmull_s8(_k, _r0); _sum = vpadalq_s16(_sum, _tp0); tmpptr += 2; kptr += 8; } for (; q<inch; q++) { int8x8_t _r0 = vld1_s8(tmpptr); // i0[0-3] int8x8_t _k = vld1_s8(kptr); // k[0-3][0] int16x8_t _tp0 = vmull_s8(_k, _r0); _sum = vaddw_s16(_sum, vget_low_s16(_tp0)); tmpptr += 1; kptr += 4; } vst1q_lane_s32(outptr0, _sum, 0); vst1q_lane_s32(outptr1, _sum, 1); vst1q_lane_s32(outptr2, _sum, 2); vst1q_lane_s32(outptr3, _sum, 3); #else int sum0 = 0; int sum1 = 0; int sum2 = 0; int sum3 = 0; int q=0; for (; q+1<inch; q=q+2) { sum0 += tmpptr[0] * kptr[0]; sum0 += tmpptr[1] * kptr[1]; sum1 += tmpptr[0] * kptr[2]; sum1 += tmpptr[1] * kptr[3]; sum2 += tmpptr[0] * kptr[4]; sum2 += tmpptr[1] * kptr[5]; sum3 += tmpptr[0] * kptr[6]; sum3 += tmpptr[1] * kptr[7]; tmpptr += 2; kptr += 8; } for (; q<inch; q++) { sum0 += tmpptr[0] * kptr[0]; sum1 += tmpptr[0] * kptr[1]; sum2 += tmpptr[0] * kptr[2]; sum3 += tmpptr[0] * kptr[3]; tmpptr += 1; kptr += 4; } outptr0[0] = sum0; outptr1[0] = sum1; outptr2[0] = sum2; outptr3[0] = sum3; #endif outptr0++; outptr1++; outptr2++; outptr3++; } } #pragma omp parallel for num_threads(opt.num_threads) for (int p=remain_outch_start; p<outch; p++) { Mat out0 = top_blob.channel(p); int* outptr0 = out0; int i = 0; for (; i+3<size; i+=4) { signed char* tmpptr = bottom_tm.channel(i/4); const signed char* kptr = kernel.channel(p/4 + p%4); #if __ARM_NEON int32x4_t _sum = vdupq_n_s32(0); int q=0; for (; q+1<inch; q=q+2) { int8x8_t _r0 = vld1_s8(tmpptr); // i0[0-1], i1[0-1], i2[0-1], i3[0-1] int8x8_t _k = vld1_s8(kptr); // k0[0-1] _k[2] = _k[0]; _k[3] = _k[1]; _k[4] = _k[0]; _k[5] = _k[1]; _k[6] = _k[0]; _k[7] = _k[1]; int16x8_t _tp0 = vmull_s8(_k, _r0); _sum = vpadalq_s16(_sum, _tp0); tmpptr += 8; kptr += 2; } for (; q<inch; q++) { int8x8_t _r0 = vld1_s8(tmpptr); // i0[0], i1[0], i2[0], i3[0] int8x8_t _k = vld1_s8(kptr); // k[0][0] int16x8_t _r0_s16 = vmovl_s8(_r0); int16x8_t _k_s16 = vmovl_s8(_k); _sum = vmlal_lane_s16(_sum, vget_low_s16(_r0_s16), vget_low_s16(_k_s16), 0); // i0k0, i1k0, i2k0, i3k0 tmpptr += 4; kptr += 1; } vst1q_s32(outptr0, _sum); #else int sum0 = 0; int sum1 = 0; int sum2 = 0; int sum3 = 0; int q=0; for (; q+1<inch; q=q+2) { sum0 += tmpptr[0] * kptr[0]; sum0 += tmpptr[1] * kptr[1]; sum1 += tmpptr[2] * kptr[0]; sum1 += tmpptr[3] * kptr[1]; sum2 += tmpptr[4] * kptr[0]; sum2 += tmpptr[5] * kptr[1]; sum3 += tmpptr[6] * kptr[0]; sum3 += tmpptr[7] * kptr[1]; tmpptr += 8; kptr += 2; } for (; q<inch; q++) { sum0 += tmpptr[0] * kptr[0]; sum1 += tmpptr[1] * kptr[0]; sum2 += tmpptr[2] * kptr[0]; sum3 += tmpptr[3] * kptr[0]; tmpptr += 4; kptr++; } outptr0[0] = sum0; outptr0[1] = sum1; outptr0[2] = sum2; outptr0[3] = sum3; #endif outptr0 += 4; } for (; i<size; i++) { signed char* tmpptr = bottom_tm.channel(i/4 + i%4); const signed char* kptr = kernel.channel(p/4 + p%4); int q = 0; int sum0 = 0; for (; q<inch; q++) { sum0 += tmpptr[0] * kptr[0]; tmpptr++; kptr++; } outptr0[0] = sum0; outptr0++; } } } static void conv1x1s1_sgemm_int8_requant_neon(const Mat &bottom_blob, Mat &top_blob, const Mat &kernel, const Mat &_bias, std::vector<float> scales_requant, const Option& opt) { int w = bottom_blob.w; int h = bottom_blob.h; int inch = bottom_blob.c; int outch = top_blob.c; const int size = w * h; const float* bias = _bias; // bottom_tm memory packed 4 x 4 Mat bottom_tm(4, inch, size/4 + size%4, (size_t)1u, opt.workspace_allocator); { int nn_size = size >> 2; int remain_size_start = nn_size << 2; #pragma omp parallel for num_threads(opt.num_threads) for (int ii=0; ii<nn_size; ii++) { int i = ii * 4; const signed char* img0 = bottom_blob.channel(0); const signed char* img1 = bottom_blob.channel(1); img0 += i; img1 += i; signed char* tmpptr = bottom_tm.channel(i/4); int q = 0; for (; q+1<inch; q=q+2) { tmpptr[0] = img0[0]; tmpptr[1] = img1[0]; tmpptr[2] = img0[1]; tmpptr[3] = img1[1]; tmpptr[4] = img0[2]; tmpptr[5] = img1[2]; tmpptr[6] = img0[3]; tmpptr[7] = img1[3]; tmpptr += 8; img0 += bottom_blob.cstep; img0 += bottom_blob.cstep; img1 += bottom_blob.cstep; img1 += bottom_blob.cstep; } for (; q<inch; q++) { tmpptr[0] = img0[0]; tmpptr[1] = img0[1]; tmpptr[2] = img0[2]; tmpptr[3] = img0[3]; tmpptr += 4; img0 += bottom_blob.cstep; } } #pragma omp parallel for num_threads(opt.num_threads) for (int i=remain_size_start; i<size; i++) { const signed char* img0 = bottom_blob.channel(0); img0 += i; signed char* tmpptr = bottom_tm.channel(i/4 + i%4); for (int q=0; q<inch; q++) { tmpptr[0] = img0[0]; tmpptr += 1; img0 += bottom_blob.cstep; } } } // sgemm process int nn_outch = 0; int remain_outch_start = 0; nn_outch = outch >> 2; remain_outch_start = nn_outch << 2; #pragma omp parallel for num_threads(opt.num_threads) for (int pp=0; pp<nn_outch; pp++) { int p = pp * 4; signed char* outptr0 = top_blob.channel(p); signed char* outptr1 = top_blob.channel(p+1); signed char* outptr2 = top_blob.channel(p+2); signed char* outptr3 = top_blob.channel(p+3); const float bias0 = bias ? bias[p] : 0.f; const float bias1 = bias ? bias[p+1] : 0.f; const float bias2 = bias ? bias[p+2] : 0.f; const float bias3 = bias ? bias[p+3] : 0.f; const float scale_requant_in0 = scales_requant[2*p]; const float scale_requant_out0 = scales_requant[2*p+1]; const float scale_requant_in1 = scales_requant[2*(p+1)]; const float scale_requant_out1 = scales_requant[2*(p+1)+1]; const float scale_requant_in2 = scales_requant[2*(p+2)]; const float scale_requant_out2 = scales_requant[2*(p+2)+1]; const float scale_requant_in3 = scales_requant[2*(p+3)]; const float scale_requant_out3 = scales_requant[2*(p+3)+1]; float32x4_t _bias03, _scale_in03, _scale_out03; float32x4_t _bias0 = vdupq_n_f32(bias0); float32x4_t _bias1 = vdupq_n_f32(bias1); float32x4_t _bias2 = vdupq_n_f32(bias2); float32x4_t _bias3 = vdupq_n_f32(bias3); _bias03[0] = bias0; _bias03[1] = bias1; _bias03[2] = bias2; _bias03[3] = bias3; _scale_in03[0] = scale_requant_in0; _scale_in03[1] = scale_requant_in1; _scale_in03[2] = scale_requant_in2; _scale_in03[3] = scale_requant_in3; _scale_out03[0] = scale_requant_out0; _scale_out03[1] = scale_requant_out1; _scale_out03[2] = scale_requant_out2; _scale_out03[3] = scale_requant_out3; int i = 0; for (; i+3<size; i+=4) { signed char* tmpptr = bottom_tm.channel(i/4); const signed char* kptr = kernel.channel(p/4); #if 1 //__ARM_NEON asm volatile( "prfm pldl1keep, [%4, #128] \n" "prfm pldl1keep, [%5, #128] \n" "eor v16.16b, v16.16b, v16.16b \n" // sum0 "eor v17.16b, v17.16b, v17.16b \n" // sum1 "eor v18.16b, v18.16b, v18.16b \n" // sum2 "eor v19.16b, v19.16b, v19.16b \n" // sum3 "lsr w4, %w12, #2 \n"// r4 = nn = L >> 2 "cmp w4, #0 \n" "beq 1f \n" "0: \n"// for (; k+3<L; k=k+4) "ld1 {v0.16b}, [%4] \n"// i0, i1, i2, i3 "ld1 {v4.16b}, [%5] \n"// k0, k1, k2, k3 "add %4, %4, #16 \n" "add %5, %5, #16 \n" "rev32 v1.8h, v0.8h \n"// i1, i0, i3, i2 "rev64 v2.4s, v0.4s \n"// i2, i3, i0, i1 "rev64 v3.8h, v0.8h \n"// i3, i2, i1, i0 "smull v8.8h, v4.8b, v0.8b \n" "smull v9.8h, v4.8b, v1.8b \n" "smull v10.8h, v4.8b, v2.8b \n" "smull v11.8h, v4.8b, v3.8b \n" "prfm pldl1keep, [%4, #1024] \n" "prfm pldl1keep, [%5, #1024] \n" "smlal2 v8.8h, v4.16b, v0.16b \n" "smlal2 v9.8h, v4.16b, v1.16b \n" "smlal2 v10.8h, v4.16b, v2.16b \n" "smlal2 v11.8h, v4.16b, v3.16b \n" "sadalp v16.4s, v8.8h \n"// i0k0, i1k1, i2k2, i3k3 "sadalp v17.4s, v9.8h \n"// i1k0, i0k1, i3k2, i2k3 "sadalp v18.4s, v10.8h \n"// i2k0, i3k1, i0k2, i1k3 "sadalp v19.4s, v11.8h \n"// i3k0, i2k1, i1k2, i0k3 "subs w4, w4, #1 \n" "bne 0b \n" "1: \n"// for (; k+1<L; k=k+2) // remain loop "and w4, %w12, #3 \n"// w4 = remain = K & 3; "cmp w4, #0 \n" "beq 3f \n" "lsr w4, w4, #1 \n"// r4 = nn = L >> 1 "cmp w4, #0 \n" "beq 3f \n" "2: \n"// for (; k+1<L; k=k+2) "ld1 {v0.8b}, [%4] \n"// i0, i1, i2, i3 "ld1 {v4.8b}, [%5] \n"// k0, k1, k2, k3 "add %4, %4, #8 \n" "add %5, %5, #8 \n" "rev32 v1.4h, v0.4h \n"// i2, i3, i0, i1 "rev64 v2.2s, v0.2s \n"// i1, i0, i3, i2 "rev64 v3.4h, v0.4h \n"// i0, i1, i2, i3 "smull v8.8h, v4.8b, v0.8b \n" "smull v9.8h, v4.8b, v1.8b \n" "smull v10.8h, v4.8b, v2.8b \n" "smull v11.8h, v4.8b, v3.8b \n" "sadalp v16.4s, v8.8h \n" "sadalp v17.4s, v9.8h \n" "sadalp v18.4s,v10.8h \n" "sadalp v19.4s,v11.8h \n" "subs w4, w4, #1 \n" "bne 2b \n" "3: \n"// realloc "mov v20.s[0], v16.s[0] \n" "mov v20.s[1], v17.s[0] \n" "mov v20.s[2], v18.s[0] \n" "mov v20.s[3], v19.s[0] \n" "mov v21.s[0], v17.s[1] \n" "mov v21.s[1], v16.s[1] \n" "mov v21.s[2], v19.s[1] \n" "mov v21.s[3], v18.s[1] \n" "mov v22.s[0], v18.s[2] \n" "mov v22.s[1], v19.s[2] \n" "mov v22.s[2], v16.s[2] \n" "mov v22.s[3], v17.s[2] \n" "mov v23.s[0], v19.s[3] \n" "mov v23.s[1], v18.s[3] \n" "mov v23.s[2], v17.s[3] \n" "mov v23.s[3], v16.s[3] \n" "and w4, %w12, #1 \n"// w4 = remain = K & 1; "cmp w4, #0 \n" "beq 5f \n" "4: \n" "ld1 {v0.8b}, [%4] \n" "ld1 {v1.8b}, [%5] \n" "add %4, %4, #4 \n" "add %5, %5, #4 \n" "sshll v0.8h, v0.8b, #0 \n"// i0[0], i1[0], i2[0], i3[0] "sshll v1.8h, v1.8b, #0 \n"// k0[0], k1[0], k2[0], k3[0] "smlal v20.4s, v0.4h, v1.h[0] \n"// i0k0, i1k0, i2k0, i3k0 "smlal v21.4s, v0.4h, v1.h[1] \n"// i0k1, i1k1, i2k1, i3k1 "smlal v22.4s, v0.4h, v1.h[2] \n"// i0k2, i1k2, i2k2, i3k2 "smlal v23.4s, v0.4h, v1.h[3] \n"// i0k3, i1k3, i2k3, i3k3 "subs w4, w4, #1 \n" "bne 2b \n" "5: \n" // top_s32 -> top_f32 "scvtf v20.4s, v20.4s \n" "scvtf v21.4s, v21.4s \n" "scvtf v22.4s, v22.4s \n" "scvtf v23.4s, v23.4s \n" // top_f32 = top_f32 * scale_in "fmul v20.4s, v20.4s, %17.s[0] \n" "fmul v21.4s, v21.4s, %17.s[1] \n" "fmul v22.4s, v22.4s, %17.s[2] \n" "fmul v23.4s, v23.4s, %17.s[3] \n" // top_f32 = top_f32 + bias "fadd v20.4s, v20.4s, %13.4s \n" "fadd v21.4s, v21.4s, %14.4s \n" "fadd v22.4s, v22.4s, %15.4s \n" "fadd v23.4s, v23.4s, %16.4s \n" // top_f32 = top_f32 * scale_out "fmul v20.4s, v20.4s, %18.s[0] \n" "fmul v21.4s, v21.4s, %18.s[1] \n" "fmul v22.4s, v22.4s, %18.s[2] \n" "fmul v23.4s, v23.4s, %18.s[3] \n" // top_f32 -> top_s32 "fcvtas v20.4s, v20.4s \n" "fcvtas v21.4s, v21.4s \n" "fcvtas v22.4s, v22.4s \n" "fcvtas v23.4s, v23.4s \n" // top_s32 -> top_s16 "sqxtn v7.4h, v20.4s \n" "sqxtn2 v7.8h, v21.4s \n" "sqxtn v8.4h, v22.4s \n" "sqxtn2 v8.8h, v23.4s \n" // top_s16 -> top_s8 "sqxtn v0.8b, v7.8h \n" "sqxtn v1.8b, v8.8h \n" // save top_s8 "st1 {v0.s}[0], [%0] \n" "st1 {v0.s}[1], [%1] \n" "st1 {v1.s}[0], [%2] \n" "st1 {v1.s}[1], [%3] \n" : "=r"(outptr0), // %0 "=r"(outptr1), // %1 "=r"(outptr2), // %2 "=r"(outptr3), // %3 "=r"(tmpptr), // %4 "=r"(kptr) // %5 : "0"(outptr0), "1"(outptr1), "2"(outptr2), "3"(outptr3), "4"(tmpptr), "5"(kptr), "r"(inch), // %12 "w"(_bias0), // %13 "w"(_bias1), // %14 "w"(_bias2), // %15 "w"(_bias3), // %16 "w"(_scale_in03), // %17 "w"(_scale_out03) // %18 : "cc", "memory", "x4", "v0", "v1", "v2", "v3", "v4", "v5", "v6", "v7", "v8", "v9", "v10", "v11", "v12", "v13", "v14", "v15", "v16", "v17", "v18", "v19", "v20", "v21", "v22", "v23" ); #else int sum0_0 = 0; int sum0_1 = 0; int sum0_2 = 0; int sum0_3 = 0; int sum1_0 = 0; int sum1_1 = 0; int sum1_2 = 0; int sum1_3 = 0; int sum2_0 = 0; int sum2_1 = 0; int sum2_2 = 0; int sum2_3 = 0; int sum3_0 = 0; int sum3_1 = 0; int sum3_2 = 0; int sum3_3 = 0; int q=0; for (; q+1<inch; q=q+2) { sum0_0 += tmpptr[0] * kptr[0]; sum0_0 += tmpptr[1] * kptr[1]; sum0_1 += tmpptr[2] * kptr[0]; sum0_1 += tmpptr[3] * kptr[1]; sum0_2 += tmpptr[4] * kptr[0]; sum0_2 += tmpptr[5] * kptr[1]; sum0_3 += tmpptr[6] * kptr[0]; sum0_3 += tmpptr[7] * kptr[1]; sum1_0 += tmpptr[0] * kptr[2]; sum1_0 += tmpptr[1] * kptr[3]; sum1_1 += tmpptr[2] * kptr[2]; sum1_1 += tmpptr[3] * kptr[3]; sum1_2 += tmpptr[4] * kptr[2]; sum1_2 += tmpptr[5] * kptr[3]; sum1_3 += tmpptr[6] * kptr[2]; sum1_3 += tmpptr[7] * kptr[3]; sum2_0 += tmpptr[0] * kptr[4]; sum2_0 += tmpptr[1] * kptr[5]; sum2_1 += tmpptr[2] * kptr[4]; sum2_1 += tmpptr[3] * kptr[5]; sum2_2 += tmpptr[4] * kptr[4]; sum2_2 += tmpptr[5] * kptr[5]; sum2_3 += tmpptr[6] * kptr[4]; sum2_3 += tmpptr[7] * kptr[5]; sum3_0 += tmpptr[0] * kptr[6]; sum3_0 += tmpptr[1] * kptr[7]; sum3_1 += tmpptr[2] * kptr[6]; sum3_1 += tmpptr[3] * kptr[7]; sum3_2 += tmpptr[4] * kptr[6]; sum3_2 += tmpptr[5] * kptr[7]; sum3_3 += tmpptr[6] * kptr[6]; sum3_3 += tmpptr[7] * kptr[7]; tmpptr += 8; kptr += 8; } for (; q<inch; q++) { sum0_0 += tmpptr[0] * kptr[0]; sum0_1 += tmpptr[1] * kptr[0]; sum0_2 += tmpptr[2] * kptr[0]; sum0_3 += tmpptr[3] * kptr[0]; sum1_0 += tmpptr[0] * kptr[1]; sum1_1 += tmpptr[1] * kptr[1]; sum1_2 += tmpptr[2] * kptr[1]; sum1_3 += tmpptr[3] * kptr[1]; sum2_0 += tmpptr[0] * kptr[2]; sum2_1 += tmpptr[1] * kptr[2]; sum2_2 += tmpptr[2] * kptr[2]; sum2_3 += tmpptr[3] * kptr[2]; sum3_0 += tmpptr[0] * kptr[3]; sum3_1 += tmpptr[1] * kptr[3]; sum3_2 += tmpptr[2] * kptr[3]; sum3_3 += tmpptr[3] * kptr[3]; tmpptr += 4; kptr += 4; } outptr0[0] = float2int8(((float)sum0_0 * scale_requant_in0 + bias0) * scale_requant_out0); outptr0[1] = float2int8(((float)sum0_1 * scale_requant_in0 + bias0) * scale_requant_out0); outptr0[2] = float2int8(((float)sum0_2 * scale_requant_in0 + bias0) * scale_requant_out0); outptr0[3] = float2int8(((float)sum0_3 * scale_requant_in0 + bias0) * scale_requant_out0); outptr1[0] = float2int8(((float)sum1_0 * scale_requant_in1 + bias1) * scale_requant_out1); outptr1[1] = float2int8(((float)sum1_1 * scale_requant_in1 + bias1) * scale_requant_out1); outptr1[2] = float2int8(((float)sum1_2 * scale_requant_in1 + bias1) * scale_requant_out1); outptr1[3] = float2int8(((float)sum1_3 * scale_requant_in1 + bias1) * scale_requant_out1); outptr2[0] = float2int8(((float)sum2_0 * scale_requant_in2 + bias2) * scale_requant_out2); outptr2[1] = float2int8(((float)sum2_1 * scale_requant_in2 + bias2) * scale_requant_out2); outptr2[2] = float2int8(((float)sum2_2 * scale_requant_in2 + bias2) * scale_requant_out2); outptr2[3] = float2int8(((float)sum2_3 * scale_requant_in2 + bias2) * scale_requant_out2); outptr3[0] = float2int8(((float)sum3_0 * scale_requant_in3 + bias3) * scale_requant_out3); outptr3[1] = float2int8(((float)sum3_1 * scale_requant_in3 + bias3) * scale_requant_out3); outptr3[2] = float2int8(((float)sum3_2 * scale_requant_in3 + bias3) * scale_requant_out3); outptr3[3] = float2int8(((float)sum3_3 * scale_requant_in3 + bias3) * scale_requant_out3); #endif outptr0 += 4; outptr1 += 4; outptr2 += 4; outptr3 += 4; } for (; i<size; i++) { signed char* tmpptr = bottom_tm.channel(i/4 + i%4); const signed char* kptr = kernel.channel(p/4); #if 1 //__ARM_NEON int32x4_t _sum = vdupq_n_s32(0); int q=0; for (; q+3<inch; q=q+4) { int8x8_t _r0 = vld1_s8(tmpptr); // i0[0-3] int8x8x2_t _k = vld2_s8(kptr); // k0[0-1], k1[0-1], k2[0-1], k3[0-1];k0[2-3], k1[2-3], k2[2-3], k3[2-3] int16x8_t _r0_s16 = vmovl_s8(_r0); // i0[0],i0[1],i0[2],i0[3] int16x8_t _k02_s16 = vmovl_s8(_k.val[0]); // k0[0],k1[0],k2[0],k3[0],k0[2],k1[2],k2[2],k3[2] int16x8_t _k13_s16 = vmovl_s8(_k.val[1]); // k0[1],k1[1],k2[1],k3[1],k0[3],k1[3],k2[3],k3[3] _sum = vmlal_lane_s16(_sum, vget_low_s16(_k02_s16), vget_low_s16(_r0_s16), 0); // i0[0]*k[0-3][0] _sum = vmlal_lane_s16(_sum, vget_low_s16(_k13_s16), vget_low_s16(_r0_s16), 1); // i0[1]*k[0-3][1] _sum = vmlal_lane_s16(_sum, vget_high_s16(_k02_s16), vget_low_s16(_r0_s16), 2); // i0[2]*k[0-3][2] _sum = vmlal_lane_s16(_sum, vget_high_s16(_k13_s16), vget_low_s16(_r0_s16), 3); // i0[3]*k[0-3][3] tmpptr += 4; kptr += 16; } for (; q+1<inch; q=q+2) { int8x8_t _r0 = vld1_s8(tmpptr); // i0[0-3] int8x8_t _k = vld1_s8(kptr); // k0[0-1], k1[0-1], k2[0-1], k3[0-1] _r0[2] = _r0[0]; _r0[3] = _r0[1]; _r0[4] = _r0[0]; _r0[5] = _r0[1]; _r0[6] = _r0[0]; _r0[7] = _r0[1]; int16x8_t _tp0 = vmull_s8(_k, _r0); _sum = vpadalq_s16(_sum, _tp0); tmpptr += 2; kptr += 8; } for (; q<inch; q++) { int8x8_t _r0 = vld1_s8(tmpptr); // i0[0-3] int8x8_t _k = vld1_s8(kptr); // k[0-3][0] int16x8_t _tp0 = vmull_s8(_k, _r0); _sum = vaddw_s16(_sum, vget_low_s16(_tp0)); tmpptr += 1; kptr += 4; } // top_s32 -> top_f32 float32x4_t _sum_f32 = vcvtq_f32_s32(_sum); // top_f32 = top_f32 * scale_in _sum_f32 = vmulq_f32(_sum_f32, _scale_in03); // top_f32 = top_f32 + bias _sum_f32 = vaddq_f32(_sum_f32, _bias03); // top_f32 = top_f32 * scale_out _sum_f32 = vmulq_f32(_sum_f32, _scale_out03); // top_f32 -> top_s32 _sum = vcvtaq_s32_f32(_sum_f32); // top_s32 -> top_s16 int16x4_t _sum_s16 = vqmovn_s32(_sum); int16x8_t _sum_s16_tp = vcombine_s16(_sum_s16, _sum_s16); // top_s16 -> top_s8 int8x8_t _sum_s8 = vqmovn_s16(_sum_s16_tp); // save top_s8 vst1_lane_s8(outptr0, _sum_s8, 0); vst1_lane_s8(outptr1, _sum_s8, 1); vst1_lane_s8(outptr2, _sum_s8, 2); vst1_lane_s8(outptr3, _sum_s8, 3); #else int sum0 = 0; int sum1 = 0; int sum2 = 0; int sum3 = 0; int q=0; for (; q+1<inch; q=q+2) { sum0 += tmpptr[0] * kptr[0]; sum0 += tmpptr[1] * kptr[1]; sum1 += tmpptr[0] * kptr[2]; sum1 += tmpptr[1] * kptr[3]; sum2 += tmpptr[0] * kptr[4]; sum2 += tmpptr[1] * kptr[5]; sum3 += tmpptr[0] * kptr[6]; sum3 += tmpptr[1] * kptr[7]; tmpptr += 2; kptr += 8; } for (; q<inch; q++) { sum0 += tmpptr[0] * kptr[0]; sum1 += tmpptr[0] * kptr[1]; sum2 += tmpptr[0] * kptr[2]; sum3 += tmpptr[0] * kptr[3]; tmpptr += 1; kptr += 4; } outptr0[0] = float2int8(((float)sum0 * scale_requant_in0 + bias0) * scale_requant_out0); outptr1[0] = float2int8(((float)sum1 * scale_requant_in1 + bias1) * scale_requant_out1); outptr2[0] = float2int8(((float)sum2 * scale_requant_in2 + bias2) * scale_requant_out2); outptr3[0] = float2int8(((float)sum3 * scale_requant_in3 + bias3) * scale_requant_out3); #endif outptr0++; outptr1++; outptr2++; outptr3++; } } #pragma omp parallel for num_threads(opt.num_threads) for (int p=remain_outch_start; p<outch; p++) { Mat out0 = top_blob.channel(p); signed char* outptr0 = out0; const float bias0 = bias ? bias[p] : 0.f; const float scale_requant_in = scales_requant[2*p]; const float scale_requant_out = scales_requant[2*p+1]; float32x4_t _bias0 = vdupq_n_f32(bias0); float32x4_t _scale_in = vdupq_n_f32(scale_requant_in); float32x4_t _scale_out = vdupq_n_f32(scale_requant_out); int i = 0; for (; i+3<size; i+=4) { signed char* tmpptr = bottom_tm.channel(i/4); const signed char* kptr = kernel.channel(p/4 + p%4); #if 1 //__ARM_NEON int32x4_t _sum = vdupq_n_s32(0); int q=0; for (; q+1<inch; q=q+2) { int8x8_t _r0 = vld1_s8(tmpptr); // i0[0-1], i1[0-1], i2[0-1], i3[0-1] int8x8_t _k = vld1_s8(kptr); // k0[0-1] _k[2] = _k[0]; _k[3] = _k[1]; _k[4] = _k[0]; _k[5] = _k[1]; _k[6] = _k[0]; _k[7] = _k[1]; int16x8_t _tp0 = vmull_s8(_k, _r0); _sum = vpadalq_s16(_sum, _tp0); tmpptr += 8; kptr += 2; } for (; q<inch; q++) { int8x8_t _r0 = vld1_s8(tmpptr); // i0[0], i1[0], i2[0], i3[0] int8x8_t _k = vld1_s8(kptr); // k[0][0] int16x8_t _r0_s16 = vmovl_s8(_r0); int16x8_t _k_s16 = vmovl_s8(_k); _sum = vmlal_lane_s16(_sum, vget_low_s16(_r0_s16), vget_low_s16(_k_s16), 0); // i0k0, i1k0, i2k0, i3k0 tmpptr += 4; kptr += 1; } // top_s32 -> top_f32 float32x4_t _sum_f32 = vcvtq_f32_s32(_sum); // top_f32 = top_f32 * scale_in _sum_f32 = vmulq_f32(_sum_f32, _scale_in); // top_f32 = top_f32 + bias _sum_f32 = vaddq_f32(_sum_f32, _bias0); // top_f32 = top_f32 * scale_out _sum_f32 = vmulq_f32(_sum_f32, _scale_out); // top_f32 -> top_s32 _sum = vcvtaq_s32_f32(_sum_f32); // top_s32 -> top_s16 int16x4_t _sum_s16 = vqmovn_s32(_sum); int16x8_t _sum_s16_tp = vcombine_s16(_sum_s16, _sum_s16); // top_s16 -> top_s8 int8x8_t _sum_s8 = vqmovn_s16(_sum_s16_tp); // save top_s8 vst1_s8(outptr0, _sum_s8); #else int sum0 = 0; int sum1 = 0; int sum2 = 0; int sum3 = 0; int q=0; for (; q+1<inch; q=q+2) { sum0 += tmpptr[0] * kptr[0]; sum0 += tmpptr[1] * kptr[1]; sum1 += tmpptr[2] * kptr[0]; sum1 += tmpptr[3] * kptr[1]; sum2 += tmpptr[4] * kptr[0]; sum2 += tmpptr[5] * kptr[1]; sum3 += tmpptr[6] * kptr[0]; sum3 += tmpptr[7] * kptr[1]; tmpptr += 8; kptr += 2; } for (; q<inch; q++) { sum0 += tmpptr[0] * kptr[0]; sum1 += tmpptr[1] * kptr[0]; sum2 += tmpptr[2] * kptr[0]; sum3 += tmpptr[3] * kptr[0]; tmpptr += 4; kptr++; } outptr0[0] = float2int8(((float)sum0 * scale_requant_in + bias0) * scale_requant_out); outptr0[1] = float2int8(((float)sum1 * scale_requant_in + bias0) * scale_requant_out); outptr0[2] = float2int8(((float)sum2 * scale_requant_in + bias0) * scale_requant_out); outptr0[3] = float2int8(((float)sum3 * scale_requant_in + bias0) * scale_requant_out); #endif outptr0 += 4; } for (; i<size; i++) { signed char* tmpptr = bottom_tm.channel(i/4 + i%4); const signed char* kptr = kernel.channel(p/4 + p%4); int q = 0; int sum0 = 0; for (; q<inch; q++) { sum0 += tmpptr[0] * kptr[0]; tmpptr++; kptr++; } outptr0[0] = float2int8(((float)sum0 * scale_requant_in + bias0) * scale_requant_out); outptr0++; } } } #endif #else static void conv1x1s1_sgemm_transform_kernel_int8_neon(const Mat& _kernel, Mat& kernel_tm, int inch, int outch) { const signed char* kernel = _kernel; kernel_tm.create(4*4, inch/4 + inch%4, outch/4 + outch%4, (size_t)1u); int p = 0; for (; p+3<outch; p+=4) { const signed char* kernel0 = kernel + (p+0)*inch; const signed char* kernel1 = kernel + (p+1)*inch; const signed char* kernel2 = kernel + (p+2)*inch; const signed char* kernel3 = kernel + (p+3)*inch; signed char* ktmp = kernel_tm.channel(p/4); for (int q=0; q<inch; q++) { // kernel0...3 0 ktmp[0] = kernel0[0]; ktmp[1] = kernel1[0]; ktmp[2] = kernel2[0]; ktmp[3] = kernel3[0]; ktmp += 4; kernel0 += 1; kernel1 += 1; kernel2 += 1; kernel3 += 1; } } for (; p<outch; p++) { const signed char* kernel0 = kernel + p*inch; signed char* ktmp = kernel_tm.channel(p/4 + p%4); for (int q=0; q<inch; q++) { ktmp[0] = kernel0[0]; ktmp++; kernel0++; } } } /* * Convolution 1x1 quantized with sgemm int8 */ static void conv1x1s1_sgemm_int8_neon(const Mat& bottom_blob, Mat& top_blob, const Mat& kernel, const Option& opt) { int w = bottom_blob.w; int h = bottom_blob.h; int inch = bottom_blob.c; int outch = top_blob.c; const int size = w * h; // interleave Mat tmp(8*4, inch/4+inch%4, size/8 + (size%8)/4 + size%4, 1u, opt.workspace_allocator); { int nn_size = size >> 3; int remain_size_start = nn_size << 3; #pragma omp parallel for num_threads(opt.num_threads) for (int ii=0; ii<nn_size; ii++) { int i = ii * 8; const signed char* img0 = bottom_blob.channel(0); img0 += i; signed char* tmpptr = tmp.channel(i/8); for (int q=0; q<inch; q++) { #if __ARM_NEON asm volatile( "pld [%0, #64] \n" "vld1.s8 {d0}, [%0] \n" "vst1.s8 {d0}, [%1]! \n" : "=r"(img0), // %0 "=r"(tmpptr) // %1 : "0"(img0), "1"(tmpptr) : "memory", "d0" ); img0 += bottom_blob.cstep; #else tmpptr[0] = img0[0]; tmpptr[1] = img0[1]; tmpptr[2] = img0[2]; tmpptr[3] = img0[3]; tmpptr[4] = img0[4]; tmpptr[5] = img0[5]; tmpptr[6] = img0[6]; tmpptr[7] = img0[7]; tmpptr += 8; img0 += bottom_blob.cstep; #endif // __ARM_NEON } } 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 signed char* img0 = bottom_blob.channel(0); img0 += i; signed char* tmpptr = tmp.channel(i/8 + (i%8)/4); for (int q=0; q<inch; q++) { tmpptr[0] = img0[0]; tmpptr[1] = img0[1]; tmpptr[2] = img0[2]; tmpptr[3] = img0[3]; tmpptr += 4; img0 += bottom_blob.cstep; } } remain_size_start += nn_size << 2; #pragma omp parallel for num_threads(opt.num_threads) for (int i=remain_size_start; i<size; i++) { const signed char* img0 = bottom_blob.channel(0); img0 += i; signed char* tmpptr = tmp.channel(i/8 + (i%8)/4 + i%4); for (int q=0; q<inch; q++) { tmpptr[0] = img0[0]; tmpptr++; img0 += bottom_blob.cstep; } } } // sgemm process int nn_outch = 0; int remain_outch_start = 0; nn_outch = (outch - remain_outch_start) >> 2; #pragma omp parallel for num_threads(opt.num_threads) for (int pp=0; pp<nn_outch; pp++) { int p = remain_outch_start + pp * 4; int* outptr0 = top_blob.channel(p); int* outptr1 = top_blob.channel(p+1); int* outptr2 = top_blob.channel(p+2); int* outptr3 = top_blob.channel(p+3); int i = 0; for (; i+7<size; i+=8) { const signed char* tmpptr = tmp.channel(i/8); const signed char* kptr = kernel.channel(p/4); #if __ARM_NEON asm volatile( // inch loop "vmov.s32 q6, #0 \n" "vmov.s32 q7, #0 \n" "vmov.s32 q8, #0 \n" "vmov.s32 q9, #0 \n" "vmov.s32 q10, #0 \n" "vmov.s32 q11, #0 \n" "vmov.s32 q12, #0 \n" "vmov.s32 q13, #0 \n" "lsr r4, %12, #2 \n"// r4 = nn = inch >> 2 "cmp r4, #0 \n" "beq 1f \n" "0: \n"// for(; nn != 0; nn--) "pld [%4, #128] \n" "vld1.s8 {d4-d7}, [%4]! \n"// tmpr a00-a07,a10-a17,a20-a27,a30-a37 a(inch)(data) "vmovl.s8 q5, d7 \n"// a30-a37 "vmovl.s8 q4, d6 \n"// a20-a27 "vmovl.s8 q3, d5 \n"// a10-a17 "vmovl.s8 q2, d4 \n"// a00-a07 "vld1.s8 {d0-d1}, [%5]! \n"// kptr k00-k30,k01-k31,k02-k32,k03-k33 k(outch)(inch) "vmovl.s8 q1, d1 \n"// k02-k32,k03-k33 "vmovl.s8 q0, d0 \n"// k00-k30,k01-k31 "vmlal.s16 q6, d4, d0[0] \n"// sum0 = (a00-a07) * k00 "vmlal.s16 q7, d5, d0[0] \n" "vmlal.s16 q8, d4, d0[1] \n"// sum1 = (a00-a07) * k10 "vmlal.s16 q9, d5, d0[1] \n" "vmlal.s16 q10, d4, d0[2] \n"// sum2 = (a00-a07) * k20 "vmlal.s16 q11, d5, d0[2] \n" "vmlal.s16 q12, d4, d0[3] \n"// sum3 = (a00-a07) * k30 "vmlal.s16 q13, d5, d0[3] \n" "vmlal.s16 q6, d6, d1[0] \n"// sum0 += (a10-a17) * k01 "vmlal.s16 q7, d7, d1[0] \n" "vmlal.s16 q8, d6, d1[1] \n"// sum1 += (a10-a17) * k11 "vmlal.s16 q9, d7, d1[1] \n" "vmlal.s16 q10, d6, d1[2] \n"// sum2 += (a10-a17) * k21 "vmlal.s16 q11, d7, d1[2] \n" "vmlal.s16 q12, d6, d1[3] \n"// sum3 += (a10-a17) * k31 "vmlal.s16 q13, d7, d1[3] \n" "vmlal.s16 q6, d8, d2[0] \n"// sum0 += (a20-a27) * k02 "vmlal.s16 q7, d9, d2[0] \n" "vmlal.s16 q8, d8, d2[1] \n"// sum1 += (a20-a27) * k12 "vmlal.s16 q9, d9, d2[1] \n" "vmlal.s16 q10, d8, d2[2] \n"// sum2 += (a20-a27) * k22 "vmlal.s16 q11, d9, d2[2] \n" "vmlal.s16 q12, d8, d2[3] \n"// sum3 += (a20-a27) * k32 "vmlal.s16 q13, d9, d2[3] \n" "vmlal.s16 q6, d10, d3[0] \n"// sum0 += (a30-a37) * k03 "vmlal.s16 q7, d11, d3[0] \n" "vmlal.s16 q8, d10, d3[1] \n"// sum1 += (a30-a37) * k13 "vmlal.s16 q9, d11, d3[1] \n" "vmlal.s16 q10, d10, d3[2] \n"// sum2 += (a30-a37) * k23 "vmlal.s16 q11, d11, d3[2] \n" "vmlal.s16 q12, d10, d3[3] \n"// sum3 += (a30-a37) * k33 "vmlal.s16 q13, d11, d3[3] \n" "subs r4, r4, #1 \n" "bne 0b \n"// end for "1: \n" // remain loop "and r4, %12, #3 \n"// r4 = remain = inch & 3 "cmp r4, #0 \n" "beq 3f \n" "2: \n"// for(; remain != 0; remain--) "vld1.s8 {d2}, [%4]! \n"// tmpr a00-a07 a(inch)(data) "vld1.s8 {d0}, [%5] \n"// kptr k00-k30 k(outch)(inch) "vmovl.s8 q1, d2 \n" "vmovl.s8 q0, d0 \n" "add %5, #4 \n" "vmlal.s16 q6, d2, d0[0] \n"// sum0 += (a00-a07) * k00 "vmlal.s16 q7, d3, d0[0] \n" "vmlal.s16 q8, d2, d0[1] \n"// sum1 += (a00-a07) * k10 "vmlal.s16 q9, d3, d0[1] \n" "vmlal.s16 q10, d2, d0[2] \n"// sum2 += (a00-a07) * k20 "vmlal.s16 q11, d3, d0[2] \n" "vmlal.s16 q12, d2, d0[3] \n"// sum3 += (a00-a07) * k30 "vmlal.s16 q13, d3, d0[3] \n" "subs r4, r4, #1 \n" "bne 2b \n" "3: \n"// store the result to memory "vst1.s32 {d12-d15}, [%0]! \n" "vst1.s32 {d16-d19}, [%1]! \n" "vst1.s32 {d20-d23}, [%2]! \n" "vst1.s32 {d24-d27}, [%3]! \n" : "=r"(outptr0), // %0 "=r"(outptr1), // %1 "=r"(outptr2), // %2 "=r"(outptr3), // %3 "=r"(tmpptr), // %4 "=r"(kptr) // %5 : "0"(outptr0), "1"(outptr1), "2"(outptr2), "3"(outptr3), "4"(tmpptr), "5"(kptr), "r"(inch) // %12 : "cc", "memory", "r4", "q0", "q1", "q2", "q3", "q4", "q5", "q6", "q7", "q8", "q9", "q10", "q11", "q12", "q13", "q14", "q15" ); #else int sum0_0 = 0; int sum0_1 = 0; int sum0_2 = 0; int sum0_3 = 0; int sum0_4 = 0; int sum0_5 = 0; int sum0_6 = 0; int sum0_7 = 0; int sum1_0 = 0; int sum1_1 = 0; int sum1_2 = 0; int sum1_3 = 0; int sum1_4 = 0; int sum1_5 = 0; int sum1_6 = 0; int sum1_7 = 0; int sum2_0 = 0; int sum2_1 = 0; int sum2_2 = 0; int sum2_3 = 0; int sum2_4 = 0; int sum2_5 = 0; int sum2_6 = 0; int sum2_7 = 0; int sum3_0 = 0; int sum3_1 = 0; int sum3_2 = 0; int sum3_3 = 0; int sum3_4 = 0; int sum3_5 = 0; int sum3_6 = 0; int sum3_7 = 0; for (int q=0; q<inch; q++) { sum0_0 += tmpptr[0] * kptr[0]; sum0_1 += tmpptr[1] * kptr[0]; sum0_2 += tmpptr[2] * kptr[0]; sum0_3 += tmpptr[3] * kptr[0]; sum0_4 += tmpptr[4] * kptr[0]; sum0_5 += tmpptr[5] * kptr[0]; sum0_6 += tmpptr[6] * kptr[0]; sum0_7 += tmpptr[7] * kptr[0]; sum1_0 += tmpptr[0] * kptr[1]; sum1_1 += tmpptr[1] * kptr[1]; sum1_2 += tmpptr[2] * kptr[1]; sum1_3 += tmpptr[3] * kptr[1]; sum1_4 += tmpptr[4] * kptr[1]; sum1_5 += tmpptr[5] * kptr[1]; sum1_6 += tmpptr[6] * kptr[1]; sum1_7 += tmpptr[7] * kptr[1]; sum2_0 += tmpptr[0] * kptr[2]; sum2_1 += tmpptr[1] * kptr[2]; sum2_2 += tmpptr[2] * kptr[2]; sum2_3 += tmpptr[3] * kptr[2]; sum2_4 += tmpptr[4] * kptr[2]; sum2_5 += tmpptr[5] * kptr[2]; sum2_6 += tmpptr[6] * kptr[2]; sum2_7 += tmpptr[7] * kptr[2]; sum3_0 += tmpptr[0] * kptr[3]; sum3_1 += tmpptr[1] * kptr[3]; sum3_2 += tmpptr[2] * kptr[3]; sum3_3 += tmpptr[3] * kptr[3]; sum3_4 += tmpptr[4] * kptr[3]; sum3_5 += tmpptr[5] * kptr[3]; sum3_6 += tmpptr[6] * kptr[3]; sum3_7 += tmpptr[7] * kptr[3]; tmpptr += 8; kptr += 4; } outptr0[0] = sum0_0; outptr0[1] = sum0_1; outptr0[2] = sum0_2; outptr0[3] = sum0_3; outptr0[4] = sum0_4; outptr0[5] = sum0_5; outptr0[6] = sum0_6; outptr0[7] = sum0_7; outptr1[0] = sum1_0; outptr1[1] = sum1_1; outptr1[2] = sum1_2; outptr1[3] = sum1_3; outptr1[4] = sum1_4; outptr1[5] = sum1_5; outptr1[6] = sum1_6; outptr1[7] = sum1_7; outptr2[0] = sum2_0; outptr2[1] = sum2_1; outptr2[2] = sum2_2; outptr2[3] = sum2_3; outptr2[4] = sum2_4; outptr2[5] = sum2_5; outptr2[6] = sum2_6; outptr2[7] = sum2_7; outptr3[0] = sum3_0; outptr3[1] = sum3_1; outptr3[2] = sum3_2; outptr3[3] = sum3_3; outptr3[4] = sum3_4; outptr3[5] = sum3_5; outptr3[6] = sum3_6; outptr3[7] = sum3_7; outptr0 += 8; outptr1 += 8; outptr2 += 8; outptr3 += 8; #endif // __ARM_NEON } for (; i+3<size; i+=4) { const signed char* tmpptr = tmp.channel(i/8 + (i%8)/4); const signed char* kptr = kernel.channel(p/4); #if __ARM_NEON asm volatile( // inch loop "vmov.s32 q6, #0 \n" "vmov.s32 q7, #0 \n" "vmov.s32 q8, #0 \n" "vmov.s32 q9, #0 \n" "lsr r4, %12, #2 \n"// r4 = nn = inch >> 2 "cmp r4, #0 \n" "beq 1f \n" "0: \n"// for(; nn != 0; nn--) "pld [%4, #128] \n" "vld1.s8 {d4-d5}, [%4]! \n"// tmpr a00-a03,a10-a13,a20-a23,a30-a33 a(inch)(data) "vmovl.s8 q3, d5 \n"// a20-a23,a30-a33 "vmovl.s8 q2, d4 \n"// a00-a04,a10-a14 "vld1.s8 {d0-d1}, [%5]! \n"// kptr k00-k30,k01-k31,k02-k32,k03-k33 k(outch)(inch) "vmovl.s8 q1, d1 \n"// k02-k32,k03-k33 "vmovl.s8 q0, d0 \n"// k00-k30,k01-k31 "vmlal.s16 q6, d4, d0[0] \n"// sum0 = (a00-a03) * k00 "vmlal.s16 q7, d4, d0[1] \n"// sum1 = (a00-a03) * k10 "vmlal.s16 q8, d4, d0[2] \n"// sum2 = (a00-a03) * k20 "vmlal.s16 q9, d4, d0[3] \n"// sum3 = (a00-a03) * k30 "vmlal.s16 q6, d5, d1[0] \n"// sum0 += (a10-a13) * k01 "vmlal.s16 q7, d5, d1[1] \n"// sum1 += (a10-a13) * k11 "vmlal.s16 q8, d5, d1[2] \n"// sum2 += (a10-a13) * k21 "vmlal.s16 q9, d5, d1[3] \n"// sum3 += (a10-a13) * k31 "vmlal.s16 q6, d6, d2[0] \n"// sum0 += (a20-a23) * k02 "vmlal.s16 q7, d6, d2[1] \n"// sum1 += (a20-a23) * k12 "vmlal.s16 q8, d6, d2[2] \n"// sum2 += (a20-a23) * k22 "vmlal.s16 q9, d6, d2[3] \n"// sum3 += (a20-a23) * k32 "vmlal.s16 q6, d7, d3[0] \n"// sum0 += (a30-a33) * k03 "vmlal.s16 q7, d7, d3[1] \n"// sum1 += (a30-a33) * k13 "vmlal.s16 q8, d7, d3[2] \n"// sum2 += (a30-a33) * k23 "vmlal.s16 q9, d7, d3[3] \n"// sum3 += (a30-a33) * k33 "subs r4, r4, #1 \n" "bne 0b \n"// end for "1: \n" // remain loop "and r4, %12, #3 \n"// r4 = remain = inch & 3 "cmp r4, #0 \n" "beq 3f \n" "2: \n"// for(; remain != 0; remain--) "vld1.s8 {d2}, [%4] \n"// tmpr a00-a03 a(inch)(data) "vld1.s8 {d0}, [%5] \n"// kptr k00-k30 k(outch)(inch) "vmovl.s8 q1, d2 \n" "vmovl.s8 q0, d0 \n" "add %4, #4 \n" "add %5, #4 \n" "vmlal.s16 q6, d2, d0[0] \n"// sum0 += (a00-a03) * k00 "vmlal.s16 q7, d2, d0[1] \n"// sum1 += (a00-a03) * k10 "vmlal.s16 q8, d2, d0[2] \n"// sum2 += (a00-a03) * k20 "vmlal.s16 q9, d2, d0[3] \n"// sum3 += (a00-a03) * k30 "subs r4, r4, #1 \n" "bne 2b \n" "3: \n"// store the result to memory "vst1.s32 {d12-d13}, [%0]! \n" "vst1.s32 {d14-d15}, [%1]! \n" "vst1.s32 {d16-d17}, [%2]! \n" "vst1.s32 {d18-d19}, [%3]! \n" : "=r"(outptr0), // %0 "=r"(outptr1), // %1 "=r"(outptr2), // %2 "=r"(outptr3), // %3 "=r"(tmpptr), // %4 "=r"(kptr) // %5 : "0"(outptr0), "1"(outptr1), "2"(outptr2), "3"(outptr3), "4"(tmpptr), "5"(kptr), "r"(inch) // %12 : "cc", "memory", "r4", "q0", "q1", "q2", "q3", "q4", "q5", "q6", "q7", "q8", "q9", "q10", "q11", "q12", "q13", "q14", "q15" ); #else int sum0_0 = 0; int sum0_1 = 0; int sum0_2 = 0; int sum0_3 = 0; int sum1_0 = 0; int sum1_1 = 0; int sum1_2 = 0; int sum1_3 = 0; int sum2_0 = 0; int sum2_1 = 0; int sum2_2 = 0; int sum2_3 = 0; int sum3_0 = 0; int sum3_1 = 0; int sum3_2 = 0; int sum3_3 = 0; for (int q=0; q<inch; q++) { sum0_0 += tmpptr[0] * kptr[0]; sum0_1 += tmpptr[1] * kptr[0]; sum0_2 += tmpptr[2] * kptr[0]; sum0_3 += tmpptr[3] * kptr[0]; sum1_0 += tmpptr[0] * kptr[1]; sum1_1 += tmpptr[1] * kptr[1]; sum1_2 += tmpptr[2] * kptr[1]; sum1_3 += tmpptr[3] * kptr[1]; sum2_0 += tmpptr[0] * kptr[2]; sum2_1 += tmpptr[1] * kptr[2]; sum2_2 += tmpptr[2] * kptr[2]; sum2_3 += tmpptr[3] * kptr[2]; sum3_0 += tmpptr[0] * kptr[3]; sum3_1 += tmpptr[1] * kptr[3]; sum3_2 += tmpptr[2] * kptr[3]; sum3_3 += tmpptr[3] * kptr[3]; tmpptr += 4; kptr += 4; } outptr0[0] = sum0_0; outptr0[1] = sum0_1; outptr0[2] = sum0_2; outptr0[3] = sum0_3; outptr1[0] = sum1_0; outptr1[1] = sum1_1; outptr1[2] = sum1_2; outptr1[3] = sum1_3; outptr2[0] = sum2_0; outptr2[1] = sum2_1; outptr2[2] = sum2_2; outptr2[3] = sum2_3; outptr3[0] = sum3_0; outptr3[1] = sum3_1; outptr3[2] = sum3_2; outptr3[3] = sum3_3; outptr0 += 4; outptr1 += 4; outptr2 += 4; outptr3 += 4; #endif // __ARM_NEON } for (; i<size; i++) { const signed char* tmpptr = tmp.channel(i/8 + (i%8)/4 + i%4); const signed char* kptr = kernel.channel(p/4); #if __ARM_NEON asm volatile( // inch loop "veor q6, q6, q6 \n" "veor q7, q7, q7 \n" "veor q8, q8, q8 \n" "veor q9, q9, q9 \n" "vmov.s32 q10, #0 \n" "lsr r4, %12, #2 \n"// r4 = nn = inch >> 2 "cmp r4, #0 \n" "beq 1f \n" "0: \n"// for(; nn != 0; nn--) "pld [%4, #128] \n" "vld1.s8 {d4}, [%4] \n"// tmpr a00,a10,a20,a30 a(inch)(data) "add %4, #4 \n" "vmovl.s8 q2, d4 \n"// a00,a10,a20,a30 "vld1.s8 {d0-d1}, [%5]! \n"// kptr k00-k30,k01-k31,k02-k32,k03-k33 k(outch)(inch) "vmovl.s8 q1, d1 \n"// k02-k32,k03-k33 "vmovl.s8 q0, d0 \n"// k00-k30,k01-k31 "vmlal.s16 q6, d0, d4[0] \n"// (k00-k30) * a00 "vmlal.s16 q7, d1, d4[1] \n"// (k01-k31) * a10 "vmlal.s16 q8, d2, d4[2] \n"// (k02-k32) * a20 "vmlal.s16 q9, d3, d4[3] \n"// (k03-k33) * a30 "subs r4, r4, #1 \n" "bne 0b \n"// end for "vadd.s32 q6, q6, q7 \n" "vadd.s32 q9, q9, q8 \n" "vadd.s32 q10, q6, q9 \n" "1: \n" // remain loop "and r4, %12, #3 \n"// r4 = remain = inch & 3 "cmp r4, #0 \n" "beq 3f \n" "2: \n"// for(; remain != 0; remain--) "vld1.s8 {d2}, [%4] \n"// tmpr a00 a(inch)(data) "vld1.s8 {d0}, [%5] \n"// kptr k00-k30 k(outch)(inch) "vmovl.s8 q1, d2 \n" "vmovl.s8 q0, d0 \n" "add %4, #1 \n" "add %5, #4 \n" "vmlal.s16 q10, d0, d2[0] \n" "subs r4, r4, #1 \n" "bne 2b \n" "3: \n"// store the result to memory "vst1.s32 {d20[0]}, [%0]! \n" "vst1.s32 {d20[1]}, [%1]! \n" "vst1.s32 {d21[0]}, [%2]! \n" "vst1.s32 {d21[1]}, [%3]! \n" : "=r"(outptr0), // %0 "=r"(outptr1), // %1 "=r"(outptr2), // %2 "=r"(outptr3), // %3 "=r"(tmpptr), // %4 "=r"(kptr) // %5 : "0"(outptr0), "1"(outptr1), "2"(outptr2), "3"(outptr3), "4"(tmpptr), "5"(kptr), "r"(inch) // %12 : "cc", "memory", "r4", "q0", "q1", "q2", "q3", "q4", "q5", "q6", "q7", "q8", "q9", "q10", "q11", "q12", "q13", "q14", "q15" ); #else int sum0 = 0; int sum1 = 0; int sum2 = 0; int sum3 = 0; for (int q=0; q<inch; q++) { sum0 += tmpptr[0] * kptr[0]; sum1 += tmpptr[0] * kptr[1]; sum2 += tmpptr[0] * kptr[2]; sum3 += tmpptr[0] * kptr[3]; tmpptr++; kptr += 4; } outptr0[0] = sum0; outptr1[0] = sum1; outptr2[0] = sum2; outptr3[0] = sum3; outptr0++; outptr1++; outptr2++; outptr3++; #endif // __ARM_NEON } } remain_outch_start += nn_outch << 2; #pragma omp parallel for num_threads(opt.num_threads) for (int p=remain_outch_start; p<outch; p++) { Mat out0 = top_blob.channel(p); int* outptr0 = out0; int i = 0; for (; i+7<size; i+=8) { const signed char* tmpptr = tmp.channel(i/8); const signed char* kptr = kernel.channel(p/4 + p%4); #if __ARM_NEON asm volatile( // inch loop "vmov.s32 q6, #0 \n" "vmov.s32 q7, #0 \n" "lsr r4, %6, #2 \n"// r4 = nn = inch >> 2 "cmp r4, #0 \n" "beq 1f \n" "0: \n"// for(; nn != 0; nn--) "pld [%1, #128] \n" "vld1.s8 {d4-d7}, [%1]! \n"// tmpr a00-a07,a10-a17,a20-a27,a30-a37 a(inch)(data) "vmovl.s8 q5, d7 \n"// a30-a37 "vmovl.s8 q4, d6 \n"// a20-a27 "vmovl.s8 q3, d5 \n"// a10-a17 "vmovl.s8 q2, d4 \n"// a00-a07 "vld1.s8 {d0}, [%2] \n"// kptr k00,k01,k02,k03 k(outch)(inch) "vmovl.s8 q0, d0 \n"// k00,k01,k02,k03 "add %2, #4 \n" "vmlal.s16 q6, d4, d0[0] \n"// (a00-a07) * k00 "vmlal.s16 q7, d5, d0[0] \n" "vmlal.s16 q6, d6, d0[1] \n"// (a10-a17) * k01 "vmlal.s16 q7, d7, d0[1] \n" "vmlal.s16 q6, d8, d0[2] \n"// (a20-a27) * k02 "vmlal.s16 q7, d9, d0[2] \n" "vmlal.s16 q6, d10, d0[3] \n"// (a30-a37) * k03 "vmlal.s16 q7, d11, d0[3] \n" "subs r4, r4, #1 \n" "bne 0b \n"// end for "1: \n" // remain loop "and r4, %6, #3 \n"// r4 = remain = inch & 3 "cmp r4, #0 \n" "beq 3f \n" "2: \n"// for(; remain != 0; remain--) "vld1.s8 {d2}, [%1]! \n"// tmpr a00-a07 a(inch)(data) "vld1.s8 {d0}, [%2] \n"// kptr k00 k(outch)(inch) "vmovl.s8 q1, d2 \n" "vmovl.s8 q0, d0 \n" "add %2, #1 \n" "vmlal.s16 q6, d2, d0[0] \n"// (a00-a07) * k00 "vmlal.s16 q7, d3, d0[0] \n" "subs r4, r4, #1 \n" "bne 2b \n" "3: \n"// store the result to memory "vst1.s32 {d12-d15}, [%0]! \n" : "=r"(outptr0), // %0 "=r"(tmpptr), // %1 "=r"(kptr) // %2 : "0"(outptr0), "1"(tmpptr), "2"(kptr), "r"(inch) // %6 : "cc", "memory", "r4", "q0", "q1", "q2", "q3", "q4", "q5", "q6", "q7" ); #else int sum0 = 0; int sum1 = 0; int sum2 = 0; int sum3 = 0; int sum4 = 0; int sum5 = 0; int sum6 = 0; int sum7 = 0; for (int q=0; q<inch; q++) { sum0 += tmpptr[0] * kptr[0]; sum1 += tmpptr[1] * kptr[0]; sum2 += tmpptr[2] * kptr[0]; sum3 += tmpptr[3] * kptr[0]; sum4 += tmpptr[4] * kptr[0]; sum5 += tmpptr[5] * kptr[0]; sum6 += tmpptr[6] * kptr[0]; sum7 += tmpptr[7] * kptr[0]; tmpptr += 8; kptr++; } outptr0[0] = sum0; outptr0[1] = sum1; outptr0[2] = sum2; outptr0[3] = sum3; outptr0[4] = sum4; outptr0[5] = sum5; outptr0[6] = sum6; outptr0[7] = sum7; outptr0 += 8; #endif // __ARM_NEON } for (; i+3<size; i+=4) { const signed char* tmpptr = tmp.channel(i/8 + (i%8)/4); const signed char* kptr = kernel.channel(p/4 + p%4); #if __ARM_NEON asm volatile( // inch loop "vmov.s32 q6, #0 \n" "lsr r4, %6, #2 \n"// r4 = nn = inch >> 2 "cmp r4, #0 \n" "beq 1f \n" "0: \n"// for(; nn != 0; nn--) "pld [%2, #128] \n" "vld1.s8 {d4-d5}, [%1]! \n"// tmpr a00-a03,a10-a13,a20-a23,a30-a33 a(inch)(data) "vmovl.s8 q3, d5 \n"// a20-a23,a30-a33 "vmovl.s8 q2, d4 \n"// a00-a03,a10-a13 "vld1.s8 {d0}, [%2] \n"// kptr k00,k01,k02,k03 k(outch)(inch) "vmovl.s8 q0, d0 \n"// k00,k01,k02,k03 "add %2, #4 \n" "vmlal.s16 q6, d4, d0[0] \n"// (a00-a03) * k00 "vmlal.s16 q6, d5, d0[1] \n"// (a10-a13) * k01 "vmlal.s16 q6, d6, d0[2] \n"// (a20-a23) * k02 "vmlal.s16 q6, d7, d0[3] \n"// (a30-a33) * k03 "subs r4, r4, #1 \n" "bne 0b \n"// end for "1: \n" // remain loop "and r4, %6, #3 \n"// r4 = remain = inch & 3 "cmp r4, #0 \n" "beq 3f \n" "2: \n"// for(; remain != 0; remain--) "vld1.s8 {d2}, [%1] \n"// tmpr a00-a03 a(inch)(data) "vld1.s8 {d0}, [%2] \n"// kptr k00 k(outch)(inch) "vmovl.s8 q1, d2 \n" "vmovl.s8 q0, d0 \n" "add %1, #4 \n" "add %2, #1 \n" "vmlal.s16 q6, d2, d0[0] \n"// (a00-a03) * k00 "subs r4, r4, #1 \n" "bne 2b \n" "3: \n"// store the result to memory "vst1.s32 {d12-d13}, [%0]! \n" : "=r"(outptr0), // %0 "=r"(tmpptr), // %1 "=r"(kptr) // %2 : "0"(outptr0), "1"(tmpptr), "2"(kptr), "r"(inch) // %6 : "cc", "memory", "r4", "q0", "q1", "q2", "q3", "q4", "q5", "q6" ); #else int sum0 = 0; int sum1 = 0; int sum2 = 0; int sum3 = 0; for (int q=0; q<inch; q++) { sum0 += tmpptr[0] * kptr[0]; sum1 += tmpptr[1] * kptr[0]; sum2 += tmpptr[2] * kptr[0]; sum3 += tmpptr[3] * kptr[0]; tmpptr += 4; kptr++; } outptr0[0] = sum0; outptr0[1] = sum1; outptr0[2] = sum2; outptr0[3] = sum3; outptr0 += 4; #endif // __ARM_NEON } for (; i<size; i++) { const signed char* tmpptr = tmp.channel(i/8 + (i%8)/4 + i%4); const signed char* kptr = kernel.channel(p/4 + p%4); int q = 0; int sum0 = 0; for (; q<inch; q++) { sum0 += tmpptr[0] * kptr[0]; tmpptr++; kptr++; } outptr0[0] = sum0; outptr0++; } } // // NOTE sgemm int8 // for (; p<outch; p++) // { // Mat out0 = top_blob.channel(p); // // int* outptr0 = out0; // // for (int i=0; i<size; i++) // { // int sum = 0; // // const signed char* kptr = _kernel.channel(p/8 + p%8); // // for (int q=0; q<inch; q++) // { // const signed char* img0 = bottom_blob.channel(q); // // sum += img0[i] * kptr[0]; // kptr ++; // } // // outptr0[i] = sum; // } // } } static void conv1x1s1_sgemm_int8_requant_neon(const Mat &bottom_blob, Mat &top_blob, const Mat &kernel, const Mat &_bias, std::vector<float> scales_requant, const Option& opt) { int w = bottom_blob.w; int h = bottom_blob.h; int inch = bottom_blob.c; int outch = top_blob.c; const int size = w * h; const float* bias = _bias; // interleave Mat tmp(8*4, inch/4+inch%4, size/8 + (size%8)/4 + size%4, 1u, opt.workspace_allocator); { int nn_size = size >> 3; int remain_size_start = nn_size << 3; #pragma omp parallel for num_threads(opt.num_threads) for (int ii=0; ii<nn_size; ii++) { int i = ii * 8; const signed char* img0 = bottom_blob.channel(0); img0 += i; signed char* tmpptr = tmp.channel(i/8); for (int q=0; q<inch; q++) { #if __ARM_NEON asm volatile( "pld [%0, #64] \n" "vld1.s8 {d0}, [%0] \n" "vst1.s8 {d0}, [%1]! \n" : "=r"(img0), // %0 "=r"(tmpptr) // %1 : "0"(img0), "1"(tmpptr) : "memory", "d0" ); img0 += bottom_blob.cstep; #else tmpptr[0] = img0[0]; tmpptr[1] = img0[1]; tmpptr[2] = img0[2]; tmpptr[3] = img0[3]; tmpptr[4] = img0[4]; tmpptr[5] = img0[5]; tmpptr[6] = img0[6]; tmpptr[7] = img0[7]; tmpptr += 8; img0 += bottom_blob.cstep; #endif // __ARM_NEON } } 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 signed char* img0 = bottom_blob.channel(0); img0 += i; signed char* tmpptr = tmp.channel(i/8 + (i%8)/4); for (int q=0; q<inch; q++) { tmpptr[0] = img0[0]; tmpptr[1] = img0[1]; tmpptr[2] = img0[2]; tmpptr[3] = img0[3]; tmpptr += 4; img0 += bottom_blob.cstep; } } remain_size_start += nn_size << 2; #pragma omp parallel for num_threads(opt.num_threads) for (int i=remain_size_start; i<size; i++) { const signed char* img0 = bottom_blob.channel(0); img0 += i; signed char* tmpptr = tmp.channel(i/8 + (i%8)/4 + i%4); for (int q=0; q<inch; q++) { tmpptr[0] = img0[0]; tmpptr++; img0 += bottom_blob.cstep; } } } // sgemm process int nn_outch = 0; int remain_outch_start = 0; nn_outch = (outch - remain_outch_start) >> 2; #pragma omp parallel for num_threads(opt.num_threads) for (int pp=0; pp<nn_outch; pp++) { int p = remain_outch_start + pp * 4; signed char* outptr0 = top_blob.channel(p); signed char* outptr1 = top_blob.channel(p+1); signed char* outptr2 = top_blob.channel(p+2); signed char* outptr3 = top_blob.channel(p+3); const float bias0 = bias ? bias[p] : 0.f; const float bias1 = bias ? bias[p+1] : 0.f; const float bias2 = bias ? bias[p+2] : 0.f; const float bias3 = bias ? bias[p+3] : 0.f; const float scale_requant_in0 = scales_requant[2*p]; const float scale_requant_out0 = scales_requant[2*p+1]; const float scale_requant_in1 = scales_requant[2*(p+1)]; const float scale_requant_out1 = scales_requant[2*(p+1)+1]; const float scale_requant_in2 = scales_requant[2*(p+2)]; const float scale_requant_out2 = scales_requant[2*(p+2)+1]; const float scale_requant_in3 = scales_requant[2*(p+3)]; const float scale_requant_out3 = scales_requant[2*(p+3)+1]; #if __ARM_NEON float32x4_t _bias03, _scale_in03, _scale_out03; _bias03[0] = bias0; _bias03[1] = bias1; _bias03[2] = bias2; _bias03[3] = bias3; _scale_in03[0] = scale_requant_in0; _scale_in03[1] = scale_requant_in1; _scale_in03[2] = scale_requant_in2; _scale_in03[3] = scale_requant_in3; _scale_out03[0] = scale_requant_out0; _scale_out03[1] = scale_requant_out1; _scale_out03[2] = scale_requant_out2; _scale_out03[3] = scale_requant_out3; #endif // __ARM_NEON int i = 0; for (; i+7<size; i+=8) { const signed char* tmpptr = tmp.channel(i/8); const signed char* kptr = kernel.channel(p/4); #if __ARM_NEON asm volatile( // inch loop "vmov.s32 q6, #0 \n" "vmov.s32 q7, #0 \n" "vmov.s32 q8, #0 \n" "vmov.s32 q9, #0 \n" "vmov.s32 q10, #0 \n" "vmov.s32 q11, #0 \n" "vmov.s32 q12, #0 \n" "vmov.s32 q13, #0 \n" "lsr r4, %12, #2 \n"// r4 = nn = inch >> 2 "cmp r4, #0 \n" "beq 1f \n" "0: \n"// for(; nn != 0; nn--) "pld [%4, #128] \n" "vld1.s8 {d28-d31}, [%4]! \n"// tmpr a00-a07,a10-a17,a20-a27,a30-a37 a(inch)(data) "vmovl.s8 q5, d31 \n"// a30-a37 "vmovl.s8 q4, d30 \n"// a20-a27 "vmovl.s8 q15, d29 \n"// a10-a17 "vmovl.s8 q14, d28 \n"// a00-a07 "vld1.s8 {d0-d1}, [%5]! \n"// kptr k00-k30,k01-k31,k02-k32,k03-k33 k(outch)(inch) "vmovl.s8 q1, d1 \n"// k02-k32,k03-k33 "vmovl.s8 q0, d0 \n"// k00-k30,k01-k31 "vmlal.s16 q6, d28, d0[0] \n"// sum0 = (a00-a07) * k00 "vmlal.s16 q7, d29, d0[0] \n" "vmlal.s16 q8, d28, d0[1] \n"// sum1 = (a00-a07) * k10 "vmlal.s16 q9, d29, d0[1] \n" "vmlal.s16 q10, d28, d0[2] \n"// sum2 = (a00-a07) * k20 "vmlal.s16 q11, d29, d0[2] \n" "vmlal.s16 q12, d28, d0[3] \n"// sum3 = (a00-a07) * k30 "vmlal.s16 q13, d29, d0[3] \n" "vmlal.s16 q6, d30, d1[0] \n"// sum0 += (a10-a17) * k01 "vmlal.s16 q7, d31, d1[0] \n" "vmlal.s16 q8, d30, d1[1] \n"// sum1 += (a10-a17) * k11 "vmlal.s16 q9, d31, d1[1] \n" "vmlal.s16 q10, d30, d1[2] \n"// sum2 += (a10-a17) * k21 "vmlal.s16 q11, d31, d1[2] \n" "vmlal.s16 q12, d30, d1[3] \n"// sum3 += (a10-a17) * k31 "vmlal.s16 q13, d31, d1[3] \n" "vmlal.s16 q6, d8, d2[0] \n"// sum0 += (a20-a27) * k02 "vmlal.s16 q7, d9, d2[0] \n" "vmlal.s16 q8, d8, d2[1] \n"// sum1 += (a20-a27) * k12 "vmlal.s16 q9, d9, d2[1] \n" "vmlal.s16 q10, d8, d2[2] \n"// sum2 += (a20-a27) * k22 "vmlal.s16 q11, d9, d2[2] \n" "vmlal.s16 q12, d8, d2[3] \n"// sum3 += (a20-a27) * k32 "vmlal.s16 q13, d9, d2[3] \n" "vmlal.s16 q6, d10, d3[0] \n"// sum0 += (a30-a37) * k03 "vmlal.s16 q7, d11, d3[0] \n" "vmlal.s16 q8, d10, d3[1] \n"// sum1 += (a30-a37) * k13 "vmlal.s16 q9, d11, d3[1] \n" "vmlal.s16 q10, d10, d3[2] \n"// sum2 += (a30-a37) * k23 "vmlal.s16 q11, d11, d3[2] \n" "vmlal.s16 q12, d10, d3[3] \n"// sum3 += (a30-a37) * k33 "vmlal.s16 q13, d11, d3[3] \n" "subs r4, r4, #1 \n" "bne 0b \n"// end for "1: \n" // remain loop "and r4, %12, #3 \n"// r4 = remain = inch & 3 "cmp r4, #0 \n" "beq 3f \n" "2: \n"// for(; remain != 0; remain--) "vld1.s8 {d2}, [%4]! \n"// tmpr a00-a07 a(inch)(data) "vld1.s8 {d0}, [%5] \n"// kptr k00-k30 k(outch)(inch) "vmovl.s8 q1, d2 \n" "vmovl.s8 q0, d0 \n" "add %5, #4 \n" "vmlal.s16 q6, d2, d0[0] \n"// sum0 += (a00-a07) * k00 "vmlal.s16 q7, d3, d0[0] \n" "vmlal.s16 q8, d2, d0[1] \n"// sum1 += (a00-a07) * k10 "vmlal.s16 q9, d3, d0[1] \n" "vmlal.s16 q10, d2, d0[2] \n"// sum2 += (a00-a07) * k20 "vmlal.s16 q11, d3, d0[2] \n" "vmlal.s16 q12, d2, d0[3] \n"// sum3 += (a00-a07) * k30 "vmlal.s16 q13, d3, d0[3] \n" "subs r4, r4, #1 \n" "bne 2b \n" "3: \n"// store the result to memory "vdup.f32 q14, %13 \n" // bias "vdup.f32 q15, %14 \n" // bias "vdup.f32 q4, %15 \n" // bias "vdup.f32 q5, %16 \n" // bias // sum0 // top_s32 -> top_f32 "vcvt.f32.s32 q6, q6 \n" "vcvt.f32.s32 q7, q7 \n" "vcvt.f32.s32 q8, q8 \n" "vcvt.f32.s32 q9, q9 \n" // top_f32 = top_f32 * scale_int "vmul.f32 q6, q6, %e17[0] \n" "vmul.f32 q7, q7, %e17[0] \n" "vmul.f32 q8, q8, %e17[1] \n" "vmul.f32 q9, q9, %e17[1] \n" // top_f32 = top_f32 + bias "vadd.f32 q6, q6, q14 \n" "vadd.f32 q7, q7, q14 \n" "vadd.f32 q8, q8, q15 \n" "vadd.f32 q9, q9, q15 \n" // top_f32 = top_f32 * scale_out "vmul.f32 q0, q6, %e18[0] \n" "vmul.f32 q1, q7, %e18[0] \n" // top_f32 -> top_s32 "vcvtr.s32.f32 s0, s0 \n" "vcvtr.s32.f32 s1, s1 \n" "vcvtr.s32.f32 s2, s2 \n" "vcvtr.s32.f32 s3, s3 \n" "vcvtr.s32.f32 s4, s4 \n" "vcvtr.s32.f32 s5, s5 \n" "vcvtr.s32.f32 s6, s6 \n" "vcvtr.s32.f32 s7, s7 \n" // top_s32 -> top_s16 "vqmovn.s32 d12, q0 \n" "vqmovn.s32 d13, q1 \n" // top_s16 -> top_s8 "vqmovn.s16 d12, q6 \n" // save top_s8 "vst1.8 {d12}, [%0]! \n" // sum1 // top_f32 = top_f32 * scale_out "vmul.f32 q0, q8, %e18[1] \n" "vmul.f32 q1, q9, %e18[1] \n" // top_f32 -> top_s32 "vcvtr.s32.f32 s0, s0 \n" "vcvtr.s32.f32 s1, s1 \n" "vcvtr.s32.f32 s2, s2 \n" "vcvtr.s32.f32 s3, s3 \n" "vcvtr.s32.f32 s4, s4 \n" "vcvtr.s32.f32 s5, s5 \n" "vcvtr.s32.f32 s6, s6 \n" "vcvtr.s32.f32 s7, s7 \n" // top_s32 -> top_s16 "vqmovn.s32 d16, q0 \n" "vqmovn.s32 d17, q1 \n" // top_s16 -> top_s8 "vqmovn.s16 d16, q8 \n" // save top_s8 "vst1.8 {d16}, [%1]! \n" // sum2 // top_s32 -> top_f32 "vcvt.f32.s32 q10, q10 \n" "vcvt.f32.s32 q11, q11 \n" "vcvt.f32.s32 q12, q12 \n" "vcvt.f32.s32 q13, q13 \n" // top_f32 = top_f32 * scale_int "vmul.f32 q10, q10, %f17[0] \n" "vmul.f32 q11, q11, %f17[0] \n" "vmul.f32 q12, q12, %f17[1] \n" "vmul.f32 q13, q13, %f17[1] \n" // top_f32 = top_f32 + bias "vadd.f32 q10, q10, q4 \n" "vadd.f32 q11, q11, q4 \n" "vadd.f32 q12, q12, q5 \n" "vadd.f32 q13, q13, q5 \n" // top_f32 = top_f32 * scale_out "vmul.f32 q0, q10, %f18[0] \n" "vmul.f32 q1, q11, %f18[0] \n" // top_f32 -> top_s32 "vcvtr.s32.f32 s0, s0 \n" "vcvtr.s32.f32 s1, s1 \n" "vcvtr.s32.f32 s2, s2 \n" "vcvtr.s32.f32 s3, s3 \n" "vcvtr.s32.f32 s4, s4 \n" "vcvtr.s32.f32 s5, s5 \n" "vcvtr.s32.f32 s6, s6 \n" "vcvtr.s32.f32 s7, s7 \n" // top_s32 -> top_s16 "vqmovn.s32 d20, q0 \n" "vqmovn.s32 d21, q1 \n" // top_s16 -> top_s8 "vqmovn.s16 d20, q10 \n" // save top_s8 "vst1.8 {d20}, [%2]! \n" // sum3 // top_f32 = top_f32 * scale_out "vmul.f32 q0, q12, %f18[1] \n" "vmul.f32 q1, q13, %f18[1] \n" // top_f32 -> top_s32 "vcvtr.s32.f32 s0, s0 \n" "vcvtr.s32.f32 s1, s1 \n" "vcvtr.s32.f32 s2, s2 \n" "vcvtr.s32.f32 s3, s3 \n" "vcvtr.s32.f32 s4, s4 \n" "vcvtr.s32.f32 s5, s5 \n" "vcvtr.s32.f32 s6, s6 \n" "vcvtr.s32.f32 s7, s7 \n" // top_s32 -> top_s16 "vqmovn.s32 d24, q0 \n" "vqmovn.s32 d25, q1 \n" // top_s16 -> top_s8 "vqmovn.s16 d24, q12 \n" // save top_s8 "vst1.8 {d24}, [%3]! \n" : "=r"(outptr0), // %0 "=r"(outptr1), // %1 "=r"(outptr2), // %2 "=r"(outptr3), // %3 "=r"(tmpptr), // %4 "=r"(kptr) // %5 : "0"(outptr0), "1"(outptr1), "2"(outptr2), "3"(outptr3), "4"(tmpptr), "5"(kptr), "r"(inch), // %12 "r"(bias0), // %13 "r"(bias1), // %14 "r"(bias2), // %15 "r"(bias3), // %16 "w"(_scale_in03), // %17 "w"(_scale_out03) // %18 : "cc", "memory", "r4", "q0", "q1", "q4", "q5", "q6", "q7", "q8", "q9", "q10", "q11", "q12", "q13" ,"q14" ,"q15" ); #else int sum0_0 = 0; int sum0_1 = 0; int sum0_2 = 0; int sum0_3 = 0; int sum0_4 = 0; int sum0_5 = 0; int sum0_6 = 0; int sum0_7 = 0; int sum1_0 = 0; int sum1_1 = 0; int sum1_2 = 0; int sum1_3 = 0; int sum1_4 = 0; int sum1_5 = 0; int sum1_6 = 0; int sum1_7 = 0; int sum2_0 = 0; int sum2_1 = 0; int sum2_2 = 0; int sum2_3 = 0; int sum2_4 = 0; int sum2_5 = 0; int sum2_6 = 0; int sum2_7 = 0; int sum3_0 = 0; int sum3_1 = 0; int sum3_2 = 0; int sum3_3 = 0; int sum3_4 = 0; int sum3_5 = 0; int sum3_6 = 0; int sum3_7 = 0; for (int q=0; q<inch; q++) { sum0_0 += tmpptr[0] * kptr[0]; sum0_1 += tmpptr[1] * kptr[0]; sum0_2 += tmpptr[2] * kptr[0]; sum0_3 += tmpptr[3] * kptr[0]; sum0_4 += tmpptr[4] * kptr[0]; sum0_5 += tmpptr[5] * kptr[0]; sum0_6 += tmpptr[6] * kptr[0]; sum0_7 += tmpptr[7] * kptr[0]; sum1_0 += tmpptr[0] * kptr[1]; sum1_1 += tmpptr[1] * kptr[1]; sum1_2 += tmpptr[2] * kptr[1]; sum1_3 += tmpptr[3] * kptr[1]; sum1_4 += tmpptr[4] * kptr[1]; sum1_5 += tmpptr[5] * kptr[1]; sum1_6 += tmpptr[6] * kptr[1]; sum1_7 += tmpptr[7] * kptr[1]; sum2_0 += tmpptr[0] * kptr[2]; sum2_1 += tmpptr[1] * kptr[2]; sum2_2 += tmpptr[2] * kptr[2]; sum2_3 += tmpptr[3] * kptr[2]; sum2_4 += tmpptr[4] * kptr[2]; sum2_5 += tmpptr[5] * kptr[2]; sum2_6 += tmpptr[6] * kptr[2]; sum2_7 += tmpptr[7] * kptr[2]; sum3_0 += tmpptr[0] * kptr[3]; sum3_1 += tmpptr[1] * kptr[3]; sum3_2 += tmpptr[2] * kptr[3]; sum3_3 += tmpptr[3] * kptr[3]; sum3_4 += tmpptr[4] * kptr[3]; sum3_5 += tmpptr[5] * kptr[3]; sum3_6 += tmpptr[6] * kptr[3]; sum3_7 += tmpptr[7] * kptr[3]; tmpptr += 8; kptr += 4; } outptr0[0] = sum0_0; outptr0[1] = sum0_1; outptr0[2] = sum0_2; outptr0[3] = sum0_3; outptr0[4] = sum0_4; outptr0[5] = sum0_5; outptr0[6] = sum0_6; outptr0[7] = sum0_7; outptr1[0] = sum1_0; outptr1[1] = sum1_1; outptr1[2] = sum1_2; outptr1[3] = sum1_3; outptr1[4] = sum1_4; outptr1[5] = sum1_5; outptr1[6] = sum1_6; outptr1[7] = sum1_7; outptr2[0] = sum2_0; outptr2[1] = sum2_1; outptr2[2] = sum2_2; outptr2[3] = sum2_3; outptr2[4] = sum2_4; outptr2[5] = sum2_5; outptr2[6] = sum2_6; outptr2[7] = sum2_7; outptr3[0] = sum3_0; outptr3[1] = sum3_1; outptr3[2] = sum3_2; outptr3[3] = sum3_3; outptr3[4] = sum3_4; outptr3[5] = sum3_5; outptr3[6] = sum3_6; outptr3[7] = sum3_7; outptr0 += 8; outptr1 += 8; outptr2 += 8; outptr3 += 8; #endif // __ARM_NEON } for (; i+3<size; i+=4) { const signed char* tmpptr = tmp.channel(i/8 + (i%8)/4); const signed char* kptr = kernel.channel(p/4); #if __ARM_NEON asm volatile( // inch loop "vmov.s32 q6, #0 \n" "vmov.s32 q7, #0 \n" "vmov.s32 q8, #0 \n" "vmov.s32 q9, #0 \n" "lsr r4, %12, #2 \n"// r4 = nn = inch >> 2 "cmp r4, #0 \n" "beq 1f \n" "0: \n"// for(; nn != 0; nn--) "pld [%4, #128] \n" "vld1.s8 {d28-d29}, [%4]! \n"// tmpr a00-a03,a10-a13,a20-a23,a30-a33 a(inch)(data) "vmovl.s8 q15, d29 \n"// a20-a23,a30-a33 "vmovl.s8 q14, d28 \n"// a00-a04,a10-a14 "vld1.s8 {d0-d1}, [%5]! \n"// kptr k00-k30,k01-k31,k02-k32,k03-k33 k(outch)(inch) "vmovl.s8 q1, d1 \n"// k02-k32,k03-k33 "vmovl.s8 q0, d0 \n"// k00-k30,k01-k31 "vmlal.s16 q6, d28, d0[0] \n"// sum0 = (a00-a03) * k00 "vmlal.s16 q7, d28, d0[1] \n"// sum1 = (a00-a03) * k10 "vmlal.s16 q8, d28, d0[2] \n"// sum2 = (a00-a03) * k20 "vmlal.s16 q9, d28, d0[3] \n"// sum3 = (a00-a03) * k30 "vmlal.s16 q6, d29, d1[0] \n"// sum0 += (a10-a13) * k01 "vmlal.s16 q7, d29, d1[1] \n"// sum1 += (a10-a13) * k11 "vmlal.s16 q8, d29, d1[2] \n"// sum2 += (a10-a13) * k21 "vmlal.s16 q9, d29, d1[3] \n"// sum3 += (a10-a13) * k31 "vmlal.s16 q6, d30, d2[0] \n"// sum0 += (a20-a23) * k02 "vmlal.s16 q7, d30, d2[1] \n"// sum1 += (a20-a23) * k12 "vmlal.s16 q8, d30, d2[2] \n"// sum2 += (a20-a23) * k22 "vmlal.s16 q9, d30, d2[3] \n"// sum3 += (a20-a23) * k32 "vmlal.s16 q6, d31, d3[0] \n"// sum0 += (a30-a33) * k03 "vmlal.s16 q7, d31, d3[1] \n"// sum1 += (a30-a33) * k13 "vmlal.s16 q8, d31, d3[2] \n"// sum2 += (a30-a33) * k23 "vmlal.s16 q9, d31, d3[3] \n"// sum3 += (a30-a33) * k33 "subs r4, r4, #1 \n" "bne 0b \n"// end for "1: \n" // remain loop "and r4, %12, #3 \n"// r4 = remain = inch & 3 "cmp r4, #0 \n" "beq 3f \n" "2: \n"// for(; remain != 0; remain--) "vld1.s8 {d2}, [%4] \n"// tmpr a00-a03 a(inch)(data) "vld1.s8 {d0}, [%5] \n"// kptr k00-k30 k(outch)(inch) "vmovl.s8 q1, d2 \n" "vmovl.s8 q0, d0 \n" "add %4, #4 \n" "add %5, #4 \n" "vmlal.s16 q6, d2, d0[0] \n"// sum0 += (a00-a03) * k00 "vmlal.s16 q7, d2, d0[1] \n"// sum1 += (a00-a03) * k10 "vmlal.s16 q8, d2, d0[2] \n"// sum2 += (a00-a03) * k20 "vmlal.s16 q9, d2, d0[3] \n"// sum3 += (a00-a03) * k30 "subs r4, r4, #1 \n" "bne 2b \n" "3: \n"// store the result to memory "vdup.f32 q14, %13 \n" // bias "vdup.f32 q15, %14 \n" // bias "vdup.f32 q4, %15 \n" // bias "vdup.f32 q5, %16 \n" // bias // sum0-1 // top_s32 -> top_f32 "vcvt.f32.s32 q6, q6 \n" "vcvt.f32.s32 q7, q7 \n" "vcvt.f32.s32 q8, q8 \n" "vcvt.f32.s32 q9, q9 \n" // top_f32 = top_f32 * scale_int "vmul.f32 q6, q6, %e17[0] \n" "vmul.f32 q7, q7, %e17[1] \n" "vmul.f32 q8, q8, %f17[0] \n" "vmul.f32 q9, q9, %f17[1] \n" // top_f32 = top_f32 + bias "vadd.f32 q6, q6, q14 \n" "vadd.f32 q7, q7, q15 \n" "vadd.f32 q8, q8, q4 \n" "vadd.f32 q9, q9, q5 \n" // top_f32 = top_f32 * scale_out "vmul.f32 q0, q6, %e18[0] \n" "vmul.f32 q1, q7, %e18[1] \n" // top_f32 -> top_s32 "vcvtr.s32.f32 s0, s0 \n" "vcvtr.s32.f32 s1, s1 \n" "vcvtr.s32.f32 s2, s2 \n" "vcvtr.s32.f32 s3, s3 \n" "vcvtr.s32.f32 s4, s4 \n" "vcvtr.s32.f32 s5, s5 \n" "vcvtr.s32.f32 s6, s6 \n" "vcvtr.s32.f32 s7, s7 \n" // top_s32 -> top_s16 "vqmovn.s32 d12, q0 \n" "vqmovn.s32 d13, q1 \n" // top_s16 -> top_s8 "vqmovn.s16 d12, q6 \n" // save top_s8 "vst1.s32 {d12[0]}, [%0]! \n" "vst1.s32 {d12[1]}, [%1]! \n" // sum1-2 // top_f32 = top_f32 * scale_out "vmul.f32 q0, q8, %f18[0] \n" "vmul.f32 q1, q9, %f18[1] \n" // top_f32 -> top_s32 "vcvtr.s32.f32 s0, s0 \n" "vcvtr.s32.f32 s1, s1 \n" "vcvtr.s32.f32 s2, s2 \n" "vcvtr.s32.f32 s3, s3 \n" "vcvtr.s32.f32 s4, s4 \n" "vcvtr.s32.f32 s5, s5 \n" "vcvtr.s32.f32 s6, s6 \n" "vcvtr.s32.f32 s7, s7 \n" // top_s32 -> top_s16 "vqmovn.s32 d16, q0 \n" "vqmovn.s32 d17, q1 \n" // top_s16 -> top_s8 "vqmovn.s16 d16, q8 \n" // save top_s8 "vst1.s32 {d16[0]}, [%2]! \n" "vst1.s32 {d16[1]}, [%3]! \n" : "=r"(outptr0), // %0 "=r"(outptr1), // %1 "=r"(outptr2), // %2 "=r"(outptr3), // %3 "=r"(tmpptr), // %4 "=r"(kptr) // %5 : "0"(outptr0), "1"(outptr1), "2"(outptr2), "3"(outptr3), "4"(tmpptr), "5"(kptr), "r"(inch), // %12 "r"(bias0), // %13 "r"(bias1), // %14 "r"(bias2), // %15 "r"(bias3), // %16 "w"(_scale_in03), // %17 "w"(_scale_out03) // %18 : "cc", "memory", "r4", "q0", "q1", "q4", "q5", "q6", "q7", "q8", "q9", "q10", "q11", "q12", "q13", "q14", "q15" ); #else int sum0_0 = 0; int sum0_1 = 0; int sum0_2 = 0; int sum0_3 = 0; int sum1_0 = 0; int sum1_1 = 0; int sum1_2 = 0; int sum1_3 = 0; int sum2_0 = 0; int sum2_1 = 0; int sum2_2 = 0; int sum2_3 = 0; int sum3_0 = 0; int sum3_1 = 0; int sum3_2 = 0; int sum3_3 = 0; for (int q=0; q<inch; q++) { sum0_0 += tmpptr[0] * kptr[0]; sum0_1 += tmpptr[1] * kptr[0]; sum0_2 += tmpptr[2] * kptr[0]; sum0_3 += tmpptr[3] * kptr[0]; sum1_0 += tmpptr[0] * kptr[1]; sum1_1 += tmpptr[1] * kptr[1]; sum1_2 += tmpptr[2] * kptr[1]; sum1_3 += tmpptr[3] * kptr[1]; sum2_0 += tmpptr[0] * kptr[2]; sum2_1 += tmpptr[1] * kptr[2]; sum2_2 += tmpptr[2] * kptr[2]; sum2_3 += tmpptr[3] * kptr[2]; sum3_0 += tmpptr[0] * kptr[3]; sum3_1 += tmpptr[1] * kptr[3]; sum3_2 += tmpptr[2] * kptr[3]; sum3_3 += tmpptr[3] * kptr[3]; tmpptr += 4; kptr += 4; } outptr0[0] = sum0_0; outptr0[1] = sum0_1; outptr0[2] = sum0_2; outptr0[3] = sum0_3; outptr1[0] = sum1_0; outptr1[1] = sum1_1; outptr1[2] = sum1_2; outptr1[3] = sum1_3; outptr2[0] = sum2_0; outptr2[1] = sum2_1; outptr2[2] = sum2_2; outptr2[3] = sum2_3; outptr3[0] = sum3_0; outptr3[1] = sum3_1; outptr3[2] = sum3_2; outptr3[3] = sum3_3; outptr0 += 4; outptr1 += 4; outptr2 += 4; outptr3 += 4; #endif // __ARM_NEON } for (; i<size; i++) { const signed char* tmpptr = tmp.channel(i/8 + (i%8)/4 + i%4); const signed char* kptr = kernel.channel(p/4); #if __ARM_NEON asm volatile( // inch loop "veor q6, q6, q6 \n" "veor q7, q7, q7 \n" "veor q8, q8, q8 \n" "veor q9, q9, q9 \n" "vmov.s32 q10, #0 \n" "lsr r4, %12, #2 \n"// r4 = nn = inch >> 2 "cmp r4, #0 \n" "beq 1f \n" "0: \n"// for(; nn != 0; nn--) "pld [%4, #128] \n" "vld1.s8 {d4}, [%4] \n"// tmpr a00,a10,a20,a30 a(inch)(data) "add %4, #4 \n" "vmovl.s8 q2, d4 \n"// a00,a10,a20,a30 "vld1.s8 {d0-d1}, [%5]! \n"// kptr k00-k30,k01-k31,k02-k32,k03-k33 k(outch)(inch) "vmovl.s8 q1, d1 \n"// k02-k32,k03-k33 "vmovl.s8 q0, d0 \n"// k00-k30,k01-k31 "vmlal.s16 q6, d0, d4[0] \n"// (k00-k30) * a00 "vmlal.s16 q7, d1, d4[1] \n"// (k01-k31) * a10 "vmlal.s16 q8, d2, d4[2] \n"// (k02-k32) * a20 "vmlal.s16 q9, d3, d4[3] \n"// (k03-k33) * a30 "subs r4, r4, #1 \n" "bne 0b \n"// end for "vadd.s32 q6, q6, q7 \n" "vadd.s32 q9, q9, q8 \n" "vadd.s32 q10, q6, q9 \n" "1: \n" // remain loop "and r4, %12, #3 \n"// r4 = remain = inch & 3 "cmp r4, #0 \n" "beq 3f \n" "2: \n"// for(; remain != 0; remain--) "vld1.s8 {d2}, [%4] \n"// tmpr a00 a(inch)(data) "vld1.s8 {d0}, [%5] \n"// kptr k00-k30 k(outch)(inch) "vmovl.s8 q1, d2 \n" "vmovl.s8 q0, d0 \n" "add %4, #1 \n" "add %5, #4 \n" "vmlal.s16 q10, d0, d2[0] \n" "subs r4, r4, #1 \n" "bne 2b \n" "3: \n"// store the result to memory // top_s32 -> top_f32 "vcvt.f32.s32 q10, q10 \n" // top_f32 = top_f32 * scale_int "vmul.f32 q10, q10, %q14 \n" // top_f32 = top_f32 + bias "vadd.f32 q10, q10, %q13 \n" // top_f32 = top_f32 * scale_out "vmul.f32 q0, q10, %q15 \n" // top_f32 -> top_s32 "vcvtr.s32.f32 s0, s0 \n" "vcvtr.s32.f32 s1, s1 \n" "vcvtr.s32.f32 s2, s2 \n" "vcvtr.s32.f32 s3, s3 \n" // top_s32 -> top_s16 "vqmovn.s32 d12, q0 \n" // top_s16 -> top_s8 "vqmovn.s16 d12, q6 \n" // save top_s8 "vst1.8 {d12[0]}, [%0]! \n" "vst1.8 {d12[1]}, [%1]! \n" "vst1.8 {d12[2]}, [%2]! \n" "vst1.8 {d12[3]}, [%3]! \n" : "=r"(outptr0), // %0 "=r"(outptr1), // %1 "=r"(outptr2), // %2 "=r"(outptr3), // %3 "=r"(tmpptr), // %4 "=r"(kptr) // %5 : "0"(outptr0), "1"(outptr1), "2"(outptr2), "3"(outptr3), "4"(tmpptr), "5"(kptr), "r"(inch), // %12 "w"(_bias03), // %13 "w"(_scale_in03), // %14 "w"(_scale_out03) // %15 : "cc", "memory", "r4", "q0", "q1", "q2", "q3", "q4", "q5", "q6", "q7", "q8", "q9", "q10", "q11", "q12" ); #else int sum0 = 0; int sum1 = 0; int sum2 = 0; int sum3 = 0; for (int q=0; q<inch; q++) { sum0 += tmpptr[0] * kptr[0]; sum1 += tmpptr[0] * kptr[1]; sum2 += tmpptr[0] * kptr[2]; sum3 += tmpptr[0] * kptr[3]; tmpptr++; kptr += 4; } outptr0[0] = sum0; outptr1[0] = sum1; outptr2[0] = sum2; outptr3[0] = sum3; outptr0++; outptr1++; outptr2++; outptr3++; #endif // __ARM_NEON } } remain_outch_start += nn_outch << 2; #pragma omp parallel for num_threads(opt.num_threads) for (int p=remain_outch_start; p<outch; p++) { Mat out0 = top_blob.channel(p); signed char* outptr0 = out0; const float bias0 = bias ? bias[p] : 0.f; const float scale_requant_in = scales_requant[2*p]; const float scale_requant_out = scales_requant[2*p+1]; #if __ARM_NEON float32x4_t _bias0 = vdupq_n_f32(bias0); float32x4_t _scale_in = vdupq_n_f32(scale_requant_in); float32x4_t _scale_out = vdupq_n_f32(scale_requant_out); #endif // __ARM_NEON int i = 0; for (; i+7<size; i+=8) { const signed char* tmpptr = tmp.channel(i/8); const signed char* kptr = kernel.channel(p/4 + p%4); #if __ARM_NEON asm volatile( // inch loop "vmov.s32 q6, #0 \n" "vmov.s32 q7, #0 \n" "lsr r4, %6, #2 \n"// r4 = nn = inch >> 2 "cmp r4, #0 \n" "beq 1f \n" "0: \n"// for(; nn != 0; nn--) "pld [%1, #128] \n" "vld1.s8 {d4-d7}, [%1]! \n"// tmpr a00-a07,a10-a17,a20-a27,a30-a37 a(inch)(data) "vmovl.s8 q5, d7 \n"// a30-a37 "vmovl.s8 q4, d6 \n"// a20-a27 "vmovl.s8 q3, d5 \n"// a10-a17 "vmovl.s8 q2, d4 \n"// a00-a07 "vld1.s8 {d0}, [%2] \n"// kptr k00,k01,k02,k03 k(outch)(inch) "vmovl.s8 q0, d0 \n"// k00,k01,k02,k03 "add %2, #4 \n" "vmlal.s16 q6, d4, d0[0] \n"// (a00-a07) * k00 "vmlal.s16 q7, d5, d0[0] \n" "vmlal.s16 q6, d6, d0[1] \n"// (a10-a17) * k01 "vmlal.s16 q7, d7, d0[1] \n" "vmlal.s16 q6, d8, d0[2] \n"// (a20-a27) * k02 "vmlal.s16 q7, d9, d0[2] \n" "vmlal.s16 q6, d10, d0[3] \n"// (a30-a37) * k03 "vmlal.s16 q7, d11, d0[3] \n" "subs r4, r4, #1 \n" "bne 0b \n"// end for "1: \n" // remain loop "and r4, %6, #3 \n"// r4 = remain = inch & 3 "cmp r4, #0 \n" "beq 3f \n" "2: \n"// for(; remain != 0; remain--) "vld1.s8 {d2}, [%1]! \n"// tmpr a00-a07 a(inch)(data) "vld1.s8 {d0}, [%2] \n"// kptr k00 k(outch)(inch) "vmovl.s8 q1, d2 \n" "vmovl.s8 q0, d0 \n" "add %2, #1 \n" "vmlal.s16 q6, d2, d0[0] \n"// (a00-a07) * k00 "vmlal.s16 q7, d3, d0[0] \n" "subs r4, r4, #1 \n" "bne 2b \n" "3: \n"// store the result to memory // top_s32 -> top_f32 "vcvt.f32.s32 q6, q6 \n" "vcvt.f32.s32 q7, q7 \n" // top_f32 = top_f32 * scale_in "vmul.f32 q6, q6, %q8 \n" "vmul.f32 q7, q7, %q8 \n" // top_f32 = top_f32 + bias "vadd.f32 q6, q6, %q7 \n" "vadd.f32 q7, q7, %q7 \n" // top_f32 = top_f32 * scale_out "vmul.f32 q0, q6, %q9 \n" "vmul.f32 q1, q7, %q9 \n" // top_f32 -> top_s32 "vcvtr.s32.f32 s0, s0 \n" "vcvtr.s32.f32 s1, s1 \n" "vcvtr.s32.f32 s2, s2 \n" "vcvtr.s32.f32 s3, s3 \n" "vcvtr.s32.f32 s4, s4 \n" "vcvtr.s32.f32 s5, s5 \n" "vcvtr.s32.f32 s6, s6 \n" "vcvtr.s32.f32 s7, s7 \n" // top_s32 -> top_s16 "vqmovn.s32 d12, q0 \n" "vqmovn.s32 d13, q1 \n" // top_s16 -> top_s8 "vqmovn.s16 d12, q6 \n" // save top_s8 "vst1.8 {d12}, [%0]! \n" : "=r"(outptr0), // %0 "=r"(tmpptr), // %1 "=r"(kptr) // %2 : "0"(outptr0), "1"(tmpptr), "2"(kptr), "r"(inch), // %6 "w"(_bias0), // %7 "w"(_scale_in), // %8 "w"(_scale_out) // %9 : "cc", "memory", "r4", "q0", "q1", "q2", "q3", "q4", "q5", "q6", "q7" ); #else int sum0 = 0; int sum1 = 0; int sum2 = 0; int sum3 = 0; int sum4 = 0; int sum5 = 0; int sum6 = 0; int sum7 = 0; for (int q=0; q<inch; q++) { sum0 += tmpptr[0] * kptr[0]; sum1 += tmpptr[1] * kptr[0]; sum2 += tmpptr[2] * kptr[0]; sum3 += tmpptr[3] * kptr[0]; sum4 += tmpptr[4] * kptr[0]; sum5 += tmpptr[5] * kptr[0]; sum6 += tmpptr[6] * kptr[0]; sum7 += tmpptr[7] * kptr[0]; tmpptr += 8; kptr++; } outptr0[0] = sum0; outptr0[1] = sum1; outptr0[2] = sum2; outptr0[3] = sum3; outptr0[4] = sum4; outptr0[5] = sum5; outptr0[6] = sum6; outptr0[7] = sum7; outptr0 += 8; #endif // __ARM_NEON } for (; i+3<size; i+=4) { const signed char* tmpptr = tmp.channel(i/8 + (i%8)/4); const signed char* kptr = kernel.channel(p/4 + p%4); #if __ARM_NEON asm volatile( // inch loop "vmov.s32 q6, #0 \n" "lsr r4, %6, #2 \n"// r4 = nn = inch >> 2 "cmp r4, #0 \n" "beq 1f \n" "0: \n"// for(; nn != 0; nn--) "pld [%2, #128] \n" "vld1.s8 {d4-d5}, [%1]! \n"// tmpr a00-a03,a10-a13,a20-a23,a30-a33 a(inch)(data) "vmovl.s8 q3, d5 \n"// a20-a23,a30-a33 "vmovl.s8 q2, d4 \n"// a00-a03,a10-a13 "vld1.s8 {d0}, [%2] \n"// kptr k00,k01,k02,k03 k(outch)(inch) "vmovl.s8 q0, d0 \n"// k00,k01,k02,k03 "add %2, #4 \n" "vmlal.s16 q6, d4, d0[0] \n"// (a00-a03) * k00 "vmlal.s16 q6, d5, d0[1] \n"// (a10-a13) * k01 "vmlal.s16 q6, d6, d0[2] \n"// (a20-a23) * k02 "vmlal.s16 q6, d7, d0[3] \n"// (a30-a33) * k03 "subs r4, r4, #1 \n" "bne 0b \n"// end for "1: \n" // remain loop "and r4, %6, #3 \n"// r4 = remain = inch & 3 "cmp r4, #0 \n" "beq 3f \n" "2: \n"// for(; remain != 0; remain--) "vld1.s8 {d2}, [%1] \n"// tmpr a00-a03 a(inch)(data) "vld1.s8 {d0}, [%2] \n"// kptr k00 k(outch)(inch) "vmovl.s8 q1, d2 \n" "vmovl.s8 q0, d0 \n" "add %1, #4 \n" "add %2, #1 \n" "vmlal.s16 q6, d2, d0[0] \n"// (a00-a03) * k00 "subs r4, r4, #1 \n" "bne 2b \n" "3: \n"// store the result to memory // top_s32 -> top_f32 "vcvt.f32.s32 q6, q6 \n" // top_f32 = top_f32 * scale_in "vmul.f32 q6, q6, %q8 \n" // top_f32 = top_f32 + bias "vadd.f32 q6, q6, %q7 \n" // top_f32 = top_f32 * scale_out "vmul.f32 q0, q6, %q9 \n" // top_f32 -> top_s32 "vcvtr.s32.f32 s0, s0 \n" "vcvtr.s32.f32 s1, s1 \n" "vcvtr.s32.f32 s2, s2 \n" "vcvtr.s32.f32 s3, s3 \n" // top_s32 -> top_s16 "vqmovn.s32 d12, q0 \n" // top_s16 -> top_s8 "vqmovn.s16 d12, q6 \n" "vst1.s32 {d12[0]}, [%0]! \n" : "=r"(outptr0), // %0 "=r"(tmpptr), // %1 "=r"(kptr) // %2 : "0"(outptr0), "1"(tmpptr), "2"(kptr), "r"(inch), // %6 "w"(_bias0), // %7 "w"(_scale_in), // %8 "w"(_scale_out) // %9 : "cc", "memory", "r4", "q0", "q1", "q2", "q3", "q4", "q5", "q6" ); #else int sum0 = 0; int sum1 = 0; int sum2 = 0; int sum3 = 0; for (int q=0; q<inch; q++) { sum0 += tmpptr[0] * kptr[0]; sum1 += tmpptr[1] * kptr[0]; sum2 += tmpptr[2] * kptr[0]; sum3 += tmpptr[3] * kptr[0]; tmpptr += 4; kptr++; } outptr0[0] = sum0; outptr0[1] = sum1; outptr0[2] = sum2; outptr0[3] = sum3; outptr0 += 4; #endif // __ARM_NEON } for (; i<size; i++) { const signed char* tmpptr = tmp.channel(i/8 + (i%8)/4 + i%4); const signed char* kptr = kernel.channel(p/4 + p%4); int q = 0; int sum0 = 0; for (; q<inch; q++) { sum0 += tmpptr[0] * kptr[0]; tmpptr++; kptr++; } outptr0[0] = sum0; outptr0++; } } } #endif
5-4t.c
#include <stdio.h> #include <omp.h> int main() { int i; int sum=0; omp_set_num_threads(4); #pragma omp parallel for for (i=0; i<COUNT; i++) { sum = sum + i; printf("Thread number: %d Iteration: %d Local Sum: %d \n", omp_get_thread_num(), i, sum); } printf("\n All Threads Done – Final Global Sum: %d \n\n", sum); }
bench.c
#include "omp.h" #include "pmsis.h" #define LOOP_ITER (2048) #define NB_ITER (256) #define NB_BARRIER_ITER (256) #define NB_ITER_SINGLE (128) #define CORE_ID pi_core_id() #define PRINTF(...) //#define PRINTF(...) printf(__VA_ARGS__) static void start_timer() { pi_perf_cl_reset(); pi_perf_conf(1<<PI_PERF_CYCLES); pi_perf_cl_start(); } static void reset_timer() { pi_perf_cl_reset(); } static unsigned int get_time() { return pi_perf_cl_read(PI_PERF_CYCLES); } static inline unsigned int startTimer() { PRINTF("Starting timer\n"); reset_timer(); start_timer(); return 0; } static inline unsigned int getTimer(unsigned int start) { PRINTF("Ending timer\n"); return get_time(); } void test_barrier(unsigned int nthreads) { #pragma omp parallel num_threads(nthreads) shared(nthreads) { unsigned int start; int i; float operation_cost = 0; if (omp_get_thread_num() == 0) { start = startTimer(); } for (i = 0; i < NB_BARRIER_ITER; i++) { #pragma omp barrier } if (omp_get_thread_num() == 0) { unsigned int end = getTimer(start); operation_cost = (float) end / NB_BARRIER_ITER; printf("BARRIER %d threads: %f cycles\n", nthreads, operation_cost); } } } void test_critical(unsigned int nthreads) { #pragma omp parallel num_threads(nthreads) { int i; unsigned int start = startTimer(); float operation_cost = 0; for (i = 0; i < NB_ITER; i++) { #pragma omp critical { volatile int a = 0; } } #pragma omp barrier operation_cost = (float) getTimer(start) / NB_ITER; if (CORE_ID == 0) { printf("CRITICAL %d threads: %.3f cycles\n", nthreads, operation_cost); } } } void test_parallel_loop_static(unsigned int nthreads) { int i; int j; unsigned int start = startTimer(); float iteration_cost = 0; for (i = 0; i < NB_ITER; i++) { #pragma omp parallel for num_threads(nthreads) for (j = 0; j < LOOP_ITER; j++) { volatile int a = j; } } iteration_cost = ((float) getTimer(start)/(NB_ITER * LOOP_ITER)); printf("PARALLEL FOR %d threads STATIC %d iter: %.3f cycle(s) per iteration\n", nthreads, LOOP_ITER, iteration_cost); } void test_parallel_single(unsigned int nthreads) { #pragma omp parallel num_threads(nthreads) { int i; int j; unsigned int start = startTimer(); float iteration_cost = 0; for (i = 0; i < NB_ITER; i++) { #pragma omp single { volatile int a = 0; } } if (omp_get_thread_num() == 0) { iteration_cost = ((float) getTimer(start)/(NB_ITER * LOOP_ITER)); printf("PARALLEL SINGLE %d threads STATIC %d iter: %.3f cycle(s) per iteration\n", nthreads, LOOP_ITER, iteration_cost); } } } void test_entry() { for (int i = 1; i <= pi_cl_cluster_nb_pe_cores(); i++) { test_barrier(i); } printf("\n"); for (int i = 1; i <= pi_cl_cluster_nb_pe_cores(); i++) { test_critical(i); } printf("\n"); for (int i = 1; i <= pi_cl_cluster_nb_pe_cores(); i++) { test_parallel_loop_static (i); } printf("\n"); for (int i = 1; i <= pi_cl_cluster_nb_pe_cores(); i++) { test_parallel_single(i); } } void launch_test(void) { printf("Entering main controller\n"); uint32_t errors = 0; uint32_t core_id = pi_core_id(), cluster_id = pi_cluster_id(); struct pi_device cluster_dev = {0}; struct pi_cluster_conf cl_conf = {0}; /* Init cluster configuration structure. */ pi_cluster_conf_init(&cl_conf); cl_conf.id = 0; /* Set cluster ID. */ /* Configure & open cluster. */ pi_open_from_conf(&cluster_dev, &cl_conf); if (pi_cluster_open(&cluster_dev)) { printf("Cluster open failed !\n"); pmsis_exit(-1); } /* Prepare cluster task and send it to cluster. */ struct pi_cluster_task cl_task = {0}; cl_task.entry = test_entry; cl_task.arg = NULL; pi_cluster_send_task_to_cl(&cluster_dev, &cl_task); pi_cluster_close(&cluster_dev); printf("Test success !\n"); pmsis_exit(errors); } /* Program Entry. */ int main(void) { printf("\n\n\t *** OpenMP Benchmark ***\n\n"); return pmsis_kickoff((void *) launch_test); }
GB_binop__eq_uint32.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__eq_uint32 // A.*B function (eWiseMult): GB_AemultB__eq_uint32 // A*D function (colscale): GB_AxD__eq_uint32 // D*A function (rowscale): GB_DxB__eq_uint32 // C+=B function (dense accum): GB_Cdense_accumB__eq_uint32 // C+=b function (dense accum): GB_Cdense_accumb__eq_uint32 // C+=A+B function (dense ewise3): (none) // C=A+B function (dense ewise3): GB_Cdense_ewise3_noaccum__eq_uint32 // C=scalar+B GB_bind1st__eq_uint32 // C=scalar+B' GB_bind1st_tran__eq_uint32 // C=A+scalar GB_bind2nd__eq_uint32 // C=A'+scalar GB_bind2nd_tran__eq_uint32 // C type: bool // A type: uint32_t // B,b type: uint32_t // BinaryOp: cij = (aij == bij) #define GB_ATYPE \ uint32_t #define GB_BTYPE \ uint32_t #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 \ 0 // true if the types of C and B are identical #define GB_CTYPE_IS_BTYPE \ 0 // aij = Ax [pA] #define GB_GETA(aij,Ax,pA) \ uint32_t aij = Ax [pA] // bij = Bx [pB] #define GB_GETB(bij,Bx,pB) \ uint32_t bij = Bx [pB] // 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) \ 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_EQ || GxB_NO_UINT32 || GxB_NO_EQ_UINT32) //------------------------------------------------------------------------------ // 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__eq_uint32 ( 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__eq_uint32 ( 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 #if 0 { #include "GB_dense_subassign_23_template.c" } #endif return (GrB_SUCCESS) ; #endif } //------------------------------------------------------------------------------ // C += b, accumulate a scalar into a dense matrix //------------------------------------------------------------------------------ GrB_Info GB_Cdense_accumb__eq_uint32 ( GrB_Matrix C, const GB_void *p_bwork, const int nthreads ) { #if GB_DISABLE return (GrB_NO_VALUE) ; #else #if 0 { // get the scalar b for C += b, of type uint32_t uint32_t bwork = (*((uint32_t *) p_bwork)) ; #include "GB_dense_subassign_22_template.c" return (GrB_SUCCESS) ; } #endif return (GrB_SUCCESS) ; #endif } //------------------------------------------------------------------------------ // C = A*D, column scale with diagonal D matrix //------------------------------------------------------------------------------ GrB_Info GB_AxD__eq_uint32 ( 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 bool *GB_RESTRICT Cx = (bool *) 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__eq_uint32 ( 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 bool *GB_RESTRICT Cx = (bool *) 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__eq_uint32 ( 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__eq_uint32 ( 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__eq_uint32 ( 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 bool *Cx = (bool *) Cx_output ; uint32_t x = (*((uint32_t *) x_input)) ; uint32_t *Bx = (uint32_t *) Bx_input ; int64_t p ; #pragma omp parallel for num_threads(nthreads) schedule(static) for (p = 0 ; p < anz ; p++) { uint32_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__eq_uint32 ( 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 ; bool *Cx = (bool *) Cx_output ; uint32_t *Ax = (uint32_t *) Ax_input ; uint32_t y = (*((uint32_t *) y_input)) ; #pragma omp parallel for num_threads(nthreads) schedule(static) for (p = 0 ; p < anz ; p++) { uint32_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) \ { \ uint32_t aij = Ax [pA] ; \ Cx [pC] = (x == aij) ; \ } GrB_Info GB_bind1st_tran__eq_uint32 ( 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 \ uint32_t #if GB_DISABLE return (GrB_NO_VALUE) ; #else uint32_t x = (*((const uint32_t *) x_input)) ; #define GB_PHASE_2_OF_2 #include "GB_unop_transpose.c" return (GrB_SUCCESS) ; #endif #undef GB_ATYPE #define GB_ATYPE \ uint32_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) \ { \ uint32_t aij = Ax [pA] ; \ Cx [pC] = (aij == y) ; \ } GrB_Info GB_bind2nd_tran__eq_uint32 ( 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 uint32_t y = (*((const uint32_t *) y_input)) ; #define GB_PHASE_2_OF_2 #include "GB_unop_transpose.c" return (GrB_SUCCESS) ; #endif } #endif
valid.yolo9.src.h
#pragma once #include "ukr.h" #include "omp.h" #include "transpose.h" #include "gen_ukr_A6B2gemm_1_1024_17_17_512_3_3.h" #include "gen_ukr_A1B2gemm_1_1024_17_17_512_3_3.h" void testrun(float* A ,float*B, float*C, float*oriB ){ int tid = omp_get_thread_num(); int Nx = 17; int Ny = 17; int Nh = 3; long long Astrides[6] = {0,1,2,3,4,5}; int b1 = 0; for (int fpck = (tid%1)*16; fpck < uNf; fpck+=1*16){ for(int cwh = (tid/1)*8; cwh < uNc*uNw*uNh/8*8; cwh+=8*1){ transpose8x8_avx(oriB+ (fpck+0)*uNc*uNw*uNh + cwh, B + fpck*uNc*uNw*uNh + cwh* 16 + 0, uNc*uNw*uNh, 16); transpose8x8_avx(oriB+ (fpck+8)*uNc*uNw*uNh + cwh, B + fpck*uNc*uNw*uNh + cwh* 16 + 8, uNc*uNw*uNh, 16); } } #pragma omp barrier// begin push button generated block for(int c5=0;c5<512+0;c5+=512) { for(int xy5=0;xy5<289+0;xy5+=289) { for(int f5=0;f5<1024+0;f5+=1024) { for(int c4=c5;c4<min(512, 512+c5);c4+=512) { for(int f4=f5;f4<min(1024, 1024+f5);f4+=1024) { for(int xy4=xy5;xy4<min(289, 289+xy5);xy4+=289) { for(int c3=c4;c3<min(512, 512+c4);c3+=Tc1) { for(int xy3=xy4;xy3<min(289, 289+xy4);xy3+=Txy3) { for(int f3=f4;f3<min(1024, 1024+f4);f3+=Tf2) { for(int xy2=xy3;xy2<min(289, Txy3+xy3);xy2+=6) { for(int f2=f3;f2<min(1024, Tf2+f3);f2+=16) { for(int c2=c3;c2<min(512, Tc1+c3);c2+=Tc1) { for(int c1=c2;c1<min(512, Tc1+c2);c1+=Tc1) { for(int xy1=xy2;xy1<min(289, 6+xy2);xy1+=6) { for(int f1=f2;f1<min(1024, 16+f2);f1+=16) { int ctile=min(Tc1, 512-c1); int x1=xy1/17; int y1=xy1%17/1; int c1_1=c1/1; int c1_2=c1%1/1; int kf1_1=f1/16; int kf1_2=f1%16/1; int of1_1=f1/1; int of1_2=f1%1/1; int offsetA=0+b1*184832+c1_1*361+1*x1*19+1*y1*1+c1_2*1; int offsetB=0+kf1_1*73728+c1*144+0*48+0*16+kf1_2*1; int offsetC=0+b1*295936+of1_1*289+x1*17+y1*1+of1_2*1; if(17-y1>=6){ cnn_ukr_float_scatter_6x2v_cxycgemm(A+offsetA, B+offsetB, C+offsetC, ctile, Astrides); } else if(17*17-xy1>=6){ for(int sti=17-y1;sti<6;sti+=1) { Astrides[sti]+=2; } cnn_ukr_float_scatter_6x2v_cxycgemm(A+offsetA, B+offsetB, C+offsetC, ctile, Astrides); for(int sti=17-y1;sti<6;sti+=1) { Astrides[sti]-=2; } } else{ cnn_ukr_float_scatter_1x2v_cxycgemm(A+offsetA, B+offsetB, C+offsetC, ctile, Astrides); } } } } } } } } } } } } } } } } // end push button generated block }
sph_compute.h
#ifndef SPH_COMPUTE_H #define SPH_COMPUTE_H #pragma omp declare simd double w_bspline_3d(double r, double h); double w_bspline_3d_constant(double h); #pragma omp declare simd double w_bspline_3d_simd(double q); #pragma omp declare simd double dwdq_bspline_3d_simd(double q); #define w_bspline_3d_LUT(q) w_bspline_3d_LUT_128(q) #pragma omp declare simd double w_bspline_3d_LUT_1024(double q); #pragma omp declare simd double w_bspline_3d_LUT_128(double q); #pragma omp declare simd double w_bspline_3d_LUT_32(double q); int compute_density_3d(int N, double h, SPHparticle *lsph, linkedListBox *box); int compute_density_3d_innerOmp(int N, double h, SPHparticle *lsph, linkedListBox *box); int compute_density_3d_loopswapped(int N, double h, SPHparticle *lsph, linkedListBox *box); int compute_density_3d_load_ballanced(int N, double h, SPHparticle *lsph, linkedListBox *box); int compute_density_3d_symmetrical_load_ballance(int N, double h, SPHparticle *lsph, linkedListBox *box); int compute_density_3d_symmetrical_lb_branching(int N, double h, SPHparticle *lsph, linkedListBox *box); int compute_density_2d(int N, double h, SPHparticle *lsph, linkedListBox *box); #endif
ast-dump-openmp-teams.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() { #pragma omp target #pragma omp teams ; } // CHECK: TranslationUnitDecl {{.*}} <<invalid sloc>> <invalid sloc> // CHECK: `-FunctionDecl {{.*}} <{{.*}}ast-dump-openmp-teams.c:3:1, line:7:1> line:3:6 test 'void ()' // CHECK-NEXT: `-CompoundStmt {{.*}} <col:13, line:7:1> // CHECK-NEXT: `-OMPTargetDirective {{.*}} <line:4:1, col:19> // CHECK-NEXT: `-CapturedStmt {{.*}} <line:5:1, col:18> // CHECK-NEXT: `-CapturedDecl {{.*}} <<invalid sloc>> <invalid sloc> nothrow // CHECK-NEXT: |-CapturedStmt {{.*}} <col:1, col:18> // CHECK-NEXT: | `-CapturedDecl {{.*}} <<invalid sloc>> <invalid sloc> nothrow // CHECK-NEXT: | |-OMPTeamsDirective {{.*}} <col:1, col:18> // CHECK-NEXT: | | `-CapturedStmt {{.*}} <line:6:3> // CHECK-NEXT: | | `-CapturedDecl {{.*}} <<invalid sloc>> <invalid sloc> nothrow // CHECK-NEXT: | | |-NullStmt {{.*}} <col:3> // CHECK-NEXT: | | |-ImplicitParamDecl {{.*}} <line:5: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 (unnamed at {{.*}}ast-dump-openmp-teams.c:5:1) *const restrict' // CHECK-NEXT: | |-ImplicitParamDecl {{.*}} <line:4:1> col:1 implicit __context 'struct (unnamed at {{.*}}ast-dump-openmp-teams.c:4:1) *const restrict' // CHECK-NEXT: | |-RecordDecl {{.*}} <line:5:1> col:1 implicit struct definition // CHECK-NEXT: | | `-CapturedRecordAttr {{.*}} <<invalid sloc>> Implicit // CHECK-NEXT: | `-CapturedDecl {{.*}} <<invalid sloc>> <invalid sloc> nothrow // CHECK-NEXT: | |-NullStmt {{.*}} <line:6:3> // CHECK-NEXT: | |-ImplicitParamDecl {{.*}} <line:5: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 (unnamed at {{.*}}ast-dump-openmp-teams.c:5:1) *const restrict' // CHECK-NEXT: |-AlwaysInlineAttr {{.*}} <<invalid sloc>> Implicit __forceinline // CHECK-NEXT: |-ImplicitParamDecl {{.*}} <line:4:1> col:1 implicit .global_tid. 'const int' // CHECK-NEXT: |-ImplicitParamDecl {{.*}} <col:1> col:1 implicit .part_id. 'const int *const restrict' // CHECK-NEXT: |-ImplicitParamDecl {{.*}} <col:1> col:1 implicit .privates. 'void *const restrict' // CHECK-NEXT: |-ImplicitParamDecl {{.*}} <col:1> col:1 implicit .copy_fn. 'void (*const restrict)(void *const restrict, ...)' // CHECK-NEXT: |-ImplicitParamDecl {{.*}} <col:1> col:1 implicit .task_t. 'void *const' // CHECK-NEXT: |-ImplicitParamDecl {{.*}} <col:1> col:1 implicit __context 'struct (unnamed at {{.*}}ast-dump-openmp-teams.c:4:1) *const restrict' // CHECK-NEXT: |-RecordDecl {{.*}} <col:1> col:1 implicit struct definition // CHECK-NEXT: | `-CapturedRecordAttr {{.*}} <<invalid sloc>> Implicit // CHECK-NEXT: `-CapturedDecl {{.*}} <<invalid sloc>> <invalid sloc> nothrow // CHECK-NEXT: |-OMPTeamsDirective {{.*}} <line:5:1, col:18> // CHECK-NEXT: | `-CapturedStmt {{.*}} <line:6:3> // CHECK-NEXT: | `-CapturedDecl {{.*}} <<invalid sloc>> <invalid sloc> nothrow // CHECK-NEXT: | |-NullStmt {{.*}} <col:3> // CHECK-NEXT: | |-ImplicitParamDecl {{.*}} <line:5: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 (unnamed at {{.*}}ast-dump-openmp-teams.c:5:1) *const restrict' // CHECK-NEXT: |-ImplicitParamDecl {{.*}} <line:4:1> col:1 implicit __context 'struct (unnamed at {{.*}}ast-dump-openmp-teams.c:4:1) *const restrict' // CHECK-NEXT: |-RecordDecl {{.*}} <line:5:1> col:1 implicit struct definition // CHECK-NEXT: | `-CapturedRecordAttr {{.*}} <<invalid sloc>> Implicit // CHECK-NEXT: `-CapturedDecl {{.*}} <<invalid sloc>> <invalid sloc> nothrow // CHECK-NEXT: |-NullStmt {{.*}} <line:6:3> // CHECK-NEXT: |-ImplicitParamDecl {{.*}} <line:5: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 (unnamed at {{.*}}ast-dump-openmp-teams.c:5:1) *const restrict'
vertical_grid.c
/* This source file is part of the Geophysical Fluids Modeling Framework (GAME), which is released under the MIT license. Github repository: https://github.com/OpenNWP/GAME */ /* This file contains functions that compute properties of the vertical grid. */ #include <stdlib.h> #include <stdio.h> #include <math.h> #include <geos95.h> #include "../../src/game_types.h" #include "../../src/game_constants.h" #include "include.h" #include "../../src/thermodynamics/thermodynamics.h" #include "standard.h" // constants that are specific to the ICAO standard atmosphere const double T_SFC = 273.15 + 15; const double TEMP_GRADIENT = -0.65/100; const double P_0_STANDARD = 101325; const double TROPO_HEIGHT_STANDARD = 11e3; const double INVERSE_HEIGHT_STANDARD = 20e3; const double TEMP_GRADIENT_INV_STANDARD = 0.1/100; int set_z_scalar(double z_scalar[], double oro[], int NO_OF_ORO_LAYERS, double TOA, double stretching_parameter, int VERT_GRID_TYPE) { /* This function sets the z coordinates of the scalar data points. */ double z_vertical_vector_pre[NO_OF_LAYERS + 1]; // the heights are defined according to z_k = A_k + B_k*oro with A_0 = TOA, A_{NO_OF_LEVELS} = 0, B_0 = 0, B_{NO_OF_LEVELS} = 1 double A, B, sigma_z, z_rel, max_oro; // loop over all columns for (int h_index = 0; h_index < NO_OF_SCALARS_H; ++h_index) { // filling up z_vertical_vector_pre for (int j = 0; j < NO_OF_LAYERS + 1; ++j) { z_rel = 1 - (j + 0.0)/NO_OF_LAYERS; // z/TOA sigma_z = pow(z_rel, stretching_parameter); A = sigma_z*TOA; // the height without orography // B corrects for orography if (j >= NO_OF_LAYERS - NO_OF_ORO_LAYERS && VERT_GRID_TYPE == 0) { B = (j - (NO_OF_LAYERS - NO_OF_ORO_LAYERS) + 0.0)/NO_OF_ORO_LAYERS; } else { B = 0; } z_vertical_vector_pre[j] = A + B*oro[h_index]; } // doing a check if (h_index == 0 && VERT_GRID_TYPE == 0) { max_oro = oro[find_max_index(oro, NO_OF_SCALARS_H)]; if (max_oro >= z_vertical_vector_pre[NO_OF_LAYERS - NO_OF_ORO_LAYERS]) { printf("Maximum of orography larger or equal to the height of the lowest flat level.\n"); printf("Aborting.\n"); exit(1); } } // placing the scalar points in the middle between the preliminary values of the adjacent levels for (int layer_index = 0; layer_index < NO_OF_LAYERS; ++layer_index) { z_scalar[layer_index*NO_OF_SCALARS_H + h_index] = 0.5*(z_vertical_vector_pre[layer_index] + z_vertical_vector_pre[layer_index + 1]); } } return 0; } int set_scalar_shading_indices(double z_scalar[], double oro[], int no_of_shaded_points_scalar[]) { /* This function sets which scalar points lie below the surface. */ int counter; #pragma omp parallel for private(counter) for (int i = 0; i < NO_OF_SCALARS_H; ++i) { counter = 0; for (int j = 0; j < NO_OF_LAYERS; ++j) { if (z_scalar[j*NO_OF_SCALARS_H + i] < oro[i]) { ++counter; } } no_of_shaded_points_scalar[i] = counter; } return 0; } int set_vector_shading_indices(int from_index[], int to_index[], int no_of_shaded_points_scalar[], int no_of_shaded_points_vector[]) { /* This function sets which vector points lie below the surface. */ #pragma omp parallel for for (int i = 0; i < NO_OF_VECTORS_H; ++i) { no_of_shaded_points_vector[i] = fmax(no_of_shaded_points_scalar[from_index[i]], no_of_shaded_points_scalar[to_index[i]]); } return 0; } int set_z_vector_and_normal_distance(double z_vector[], double z_scalar[], double normal_distance[], double latitude_scalar[], double longitude_scalar[], int from_index[], int to_index[], double TOA, int VERT_GRID_TYPE, double oro[]) { /* calculates the vertical position of the vector points as well as the normal distances of the primal grid */ int layer_index, h_index, upper_index, lower_index; double *lowest_thicknesses = malloc(NO_OF_SCALARS_H*sizeof(double)); #pragma omp parallel for private(layer_index, h_index, upper_index, lower_index) for (int i = 0; i < NO_OF_VECTORS; ++i) { layer_index = i/NO_OF_VECTORS_PER_LAYER; h_index = i - layer_index*NO_OF_VECTORS_PER_LAYER; // horizontal grid points if (h_index >= NO_OF_SCALARS_H) { // placing the vector vertically in the middle between the two adjacent scalar points z_vector[i] = 0.5*(z_scalar[layer_index*NO_OF_SCALARS_H + from_index[h_index - NO_OF_SCALARS_H]] + z_scalar[layer_index*NO_OF_SCALARS_H + to_index[h_index - NO_OF_SCALARS_H]]); // calculating the horizontal distance normal_distance[i] = calculate_distance_h( latitude_scalar[from_index[h_index - NO_OF_SCALARS_H]], longitude_scalar[from_index[h_index - NO_OF_SCALARS_H]], latitude_scalar[to_index[h_index - NO_OF_SCALARS_H]], longitude_scalar[to_index[h_index - NO_OF_SCALARS_H]], RADIUS + z_vector[i]); } else { upper_index = h_index + (layer_index - 1)*NO_OF_SCALARS_H; lower_index = h_index + layer_index*NO_OF_SCALARS_H; // highest level if (layer_index == 0) { z_vector[i] = TOA; normal_distance[i] = TOA - z_scalar[lower_index]; } // lowest level else if (layer_index == NO_OF_LAYERS) { if (VERT_GRID_TYPE == 0) { z_vector[i] = oro[h_index]; } if (VERT_GRID_TYPE == 1) { z_vector[i] = 0; } normal_distance[i] = z_scalar[upper_index] - z_vector[i]; lowest_thicknesses[h_index] = z_vector[i - NO_OF_VECTORS_PER_LAYER] - z_vector[i]; } // inner levels else { normal_distance[i] = z_scalar[upper_index] - z_scalar[lower_index]; // placing the vertical vector in the middle between the two adjacent scalar points z_vector[i] = z_scalar[lower_index] + 0.5*normal_distance[i]; } } } double max_thick, min_thick, thick_rel; min_thick = lowest_thicknesses[find_min_index(lowest_thicknesses, NO_OF_SCALARS_H)]; max_thick = z_vector[0] - z_vector[NO_OF_VECTORS_PER_LAYER]; thick_rel = max_thick/min_thick; printf("ratio of maximum to minimum layer thickness (including orography): %lf\n", thick_rel); free(lowest_thicknesses); return 0; } int set_z_scalar_dual(double z_scalar_dual[], double z_vector[], int from_index[], int to_index[], int vorticity_indices_triangles[], double TOA) { /* This function sets the z coordinates of the dual scalar points. */ int layer_index, h_index; #pragma omp parallel for private(layer_index, h_index) for (int i = 0; i < NO_OF_DUAL_SCALARS; ++i) { layer_index = i/NO_OF_DUAL_SCALARS_H; h_index = i - layer_index*NO_OF_DUAL_SCALARS_H; z_scalar_dual[i] = 1.0/6*( z_vector[layer_index*NO_OF_VECTORS_PER_LAYER + from_index[vorticity_indices_triangles[3*h_index + 0]]] + z_vector[layer_index*NO_OF_VECTORS_PER_LAYER + from_index[vorticity_indices_triangles[3*h_index + 1]]] + z_vector[layer_index*NO_OF_VECTORS_PER_LAYER + from_index[vorticity_indices_triangles[3*h_index + 2]]] + z_vector[layer_index*NO_OF_VECTORS_PER_LAYER + to_index[vorticity_indices_triangles[3*h_index + 0]]] + z_vector[layer_index*NO_OF_VECTORS_PER_LAYER + to_index[vorticity_indices_triangles[3*h_index + 1]]] + z_vector[layer_index*NO_OF_VECTORS_PER_LAYER + to_index[vorticity_indices_triangles[3*h_index + 2]]]); } return 0; } int set_volume(double volume[], double z_vector[], double area[], int from_index[], int to_index[], double TOA, int vorticity_indices_triangles[]) { /* This function computes the volumes of the grid boxes. */ int layer_index, h_index; double radius_0, radius_1, base_area; #pragma omp parallel for private(layer_index, h_index, radius_0, radius_1, base_area) for (int i = 0; i < NO_OF_SCALARS; ++i) { layer_index = i/NO_OF_SCALARS_H; h_index = i - layer_index*NO_OF_SCALARS_H; base_area = area[h_index + (layer_index + 1)*NO_OF_VECTORS_PER_LAYER]; radius_0 = RADIUS + z_vector[h_index + (layer_index + 1)*NO_OF_VECTORS_PER_LAYER]; radius_1 = RADIUS + z_vector[h_index + layer_index*NO_OF_VECTORS_PER_LAYER]; volume[i] = find_volume(base_area, radius_0, radius_1); } return 0; } int set_area_dual(double area_dual[], double z_vector_dual[], double normal_distance[], double z_vector[], int from_index[], int to_index[], double triangle_face_unit_sphere[], double TOA) { /* This function computes the areas of the dual grid. */ int layer_index, h_index, primal_vector_index; double radius_0, radius_1, base_distance; #pragma omp parallel for private(layer_index, h_index, primal_vector_index, radius_0, radius_1, base_distance) for (int i = 0; i < NO_OF_DUAL_VECTORS; ++i) { layer_index = i/NO_OF_DUAL_VECTORS_PER_LAYER; h_index = i - layer_index*NO_OF_DUAL_VECTORS_PER_LAYER; if (h_index >= NO_OF_VECTORS_H) { area_dual[i] = pow(RADIUS + z_vector_dual[i], 2)*triangle_face_unit_sphere[h_index - NO_OF_VECTORS_H]; } else { if (layer_index == 0) { primal_vector_index = NO_OF_SCALARS_H + h_index; radius_0 = RADIUS + z_vector[primal_vector_index]; radius_1 = RADIUS + TOA; base_distance = normal_distance[primal_vector_index]; } else if (layer_index == NO_OF_LAYERS) { primal_vector_index = NO_OF_SCALARS_H + (NO_OF_LAYERS - 1)*NO_OF_VECTORS_PER_LAYER + h_index; radius_0 = RADIUS + 0.5*(z_vector[NO_OF_LAYERS*NO_OF_VECTORS_PER_LAYER + from_index[h_index]] + z_vector[NO_OF_LAYERS*NO_OF_VECTORS_PER_LAYER + to_index[h_index]]); radius_1 = RADIUS + z_vector[primal_vector_index]; base_distance = normal_distance[primal_vector_index]*radius_0/radius_1; } else { primal_vector_index = NO_OF_SCALARS_H + layer_index*NO_OF_VECTORS_PER_LAYER + h_index; radius_0 = RADIUS + z_vector[primal_vector_index]; radius_1 = RADIUS + z_vector[primal_vector_index - NO_OF_VECTORS_PER_LAYER]; base_distance = normal_distance[primal_vector_index]; } area_dual[i] = calculate_vertical_area(base_distance, radius_0, radius_1); } } return 0; } int set_area(double area[], double z_vector[], double z_vector_dual[], double normal_distance_dual[], double pent_hex_face_unity_sphere[]) { /* This function sets the areas of the grid boxes. */ int layer_index, h_index, dual_vector_index; double base_distance, radius_0, radius_1; #pragma omp parallel for private(layer_index, h_index, dual_vector_index, base_distance, radius_0, radius_1) for (int i = 0; i < NO_OF_VECTORS; ++i) { layer_index = i/NO_OF_VECTORS_PER_LAYER; h_index = i - layer_index*NO_OF_VECTORS_PER_LAYER; if (h_index < NO_OF_SCALARS_H) { area[i] = pent_hex_face_unity_sphere[h_index]*pow(RADIUS + z_vector[i], 2); } else { dual_vector_index = (layer_index + 1)*NO_OF_DUAL_VECTORS_PER_LAYER + h_index - NO_OF_SCALARS_H; radius_0 = RADIUS + z_vector_dual[dual_vector_index]; radius_1 = RADIUS + z_vector_dual[dual_vector_index - NO_OF_DUAL_VECTORS_PER_LAYER]; base_distance = normal_distance_dual[dual_vector_index]; area[i] = calculate_vertical_area(base_distance, radius_0, radius_1); } } return 0; } int calc_z_vector_dual_and_normal_distance_dual(double z_vector_dual[], double normal_distance_dual[], double z_scalar_dual[], double TOA, int from_index[], int to_index[], double z_vector[], int from_index_dual[], int to_index_dual[], double latitude_scalar_dual[], double longitude_scalar_dual[], int vorticity_indices_triangles[]) { /* This function sets the z coordinates of the dual vector points as well as the normal distances of the dual grid. */ int layer_index, h_index, upper_index, lower_index; #pragma omp parallel for private(layer_index, h_index, upper_index, lower_index) for (int i = 0; i < NO_OF_DUAL_VECTORS; ++i) { layer_index = i/NO_OF_DUAL_VECTORS_PER_LAYER; h_index = i - layer_index*NO_OF_DUAL_VECTORS_PER_LAYER; if (h_index >= NO_OF_VECTORS_H) { upper_index = h_index - NO_OF_VECTORS_H + layer_index*NO_OF_DUAL_SCALARS_H; lower_index = h_index - NO_OF_VECTORS_H + (layer_index + 1)*NO_OF_DUAL_SCALARS_H; normal_distance_dual[i] = z_scalar_dual[upper_index] - z_scalar_dual[lower_index]; z_vector_dual[i] = 1.0/3*(z_vector[NO_OF_SCALARS_H + layer_index*NO_OF_VECTORS_PER_LAYER + vorticity_indices_triangles[3*(h_index - NO_OF_VECTORS_H) + 0]] + z_vector[NO_OF_SCALARS_H + layer_index*NO_OF_VECTORS_PER_LAYER + vorticity_indices_triangles[3*(h_index - NO_OF_VECTORS_H) + 1]] + z_vector[NO_OF_SCALARS_H + layer_index*NO_OF_VECTORS_PER_LAYER + vorticity_indices_triangles[3*(h_index - NO_OF_VECTORS_H) + 2]]); } else { if (layer_index == 0) { z_vector_dual[i] = TOA; } else if (layer_index == NO_OF_LAYERS) { z_vector_dual[i] = 0.5*(z_vector[NO_OF_LAYERS*NO_OF_VECTORS_PER_LAYER + from_index[h_index]] + z_vector[NO_OF_LAYERS*NO_OF_VECTORS_PER_LAYER + to_index[h_index]]); } else { z_vector_dual[i] = 0.5*(z_vector[NO_OF_SCALARS_H + h_index + (layer_index - 1)*NO_OF_VECTORS_PER_LAYER] + z_vector[NO_OF_SCALARS_H + h_index + layer_index*NO_OF_VECTORS_PER_LAYER]); } normal_distance_dual[i] = calculate_distance_h(latitude_scalar_dual[from_index_dual[h_index]], longitude_scalar_dual[from_index_dual[h_index]], latitude_scalar_dual[to_index_dual[h_index]], longitude_scalar_dual[to_index_dual[h_index]], RADIUS + z_vector_dual[i]); } } return 0; } int set_background_state(double z_scalar[], double gravity_potential[], double theta_bg[], double exner_bg[]) { /* This sets the hydrostatic background state. */ int scalar_index; double temperature, pressure, b, c; for (int h_index = 0; h_index < NO_OF_SCALARS_H; ++h_index) { // integrating from bottom to top for (int layer_index = NO_OF_LAYERS - 1; layer_index >= 0; --layer_index) { scalar_index = layer_index*NO_OF_SCALARS_H + h_index; temperature = standard_temp(z_scalar[scalar_index]); // lowest layer if (layer_index == NO_OF_LAYERS - 1) { pressure = standard_pres(z_scalar[scalar_index]); exner_bg[scalar_index] = pow(pressure/P_0, specific_gas_constants(0)/spec_heat_capacities_p_gas(0)); theta_bg[scalar_index] = temperature/exner_bg[scalar_index]; } // other layers else { // solving a quadratic equation for the Exner pressure b = -0.5*exner_bg[scalar_index + NO_OF_SCALARS_H]/standard_temp(z_scalar[scalar_index + NO_OF_SCALARS_H]) *(temperature - standard_temp(z_scalar[scalar_index + NO_OF_SCALARS_H]) + 2/spec_heat_capacities_p_gas(0)*(gravity_potential[scalar_index] - gravity_potential[scalar_index + NO_OF_SCALARS_H])); c = pow(exner_bg[scalar_index + NO_OF_SCALARS_H], 2)*temperature/standard_temp(z_scalar[scalar_index + NO_OF_SCALARS_H]); exner_bg[scalar_index] = b + pow((pow(b, 2) + c), 0.5); theta_bg[scalar_index] = temperature/exner_bg[scalar_index]; } } } return 0; } double standard_temp(double z_height) { // temperature in the standard atmosphere const double TROPO_TEMP_STANDARD = T_SFC + TROPO_HEIGHT_STANDARD*TEMP_GRADIENT; double temperature; if (z_height < TROPO_HEIGHT_STANDARD) { temperature = T_SFC + z_height*TEMP_GRADIENT; } else if (z_height < INVERSE_HEIGHT_STANDARD) { temperature = TROPO_TEMP_STANDARD; } else { temperature = TROPO_TEMP_STANDARD + TEMP_GRADIENT_INV_STANDARD*(z_height - INVERSE_HEIGHT_STANDARD); } return temperature; } double standard_pres(double z_height) { // pressure in the standard atmosphere const double G = 9.80616; const double TROPO_TEMP_STANDARD = T_SFC + TROPO_HEIGHT_STANDARD*TEMP_GRADIENT; double pressure, pressure_at_inv_standard; if (z_height < TROPO_HEIGHT_STANDARD) { pressure = P_0_STANDARD*pow(1 + TEMP_GRADIENT*z_height/T_SFC, -G/(R_D*TEMP_GRADIENT)); } else if (z_height < INVERSE_HEIGHT_STANDARD) { pressure = P_0_STANDARD*pow(1 + TEMP_GRADIENT*TROPO_HEIGHT_STANDARD/T_SFC, -G/(R_D*TEMP_GRADIENT))*exp(-G*(z_height - TROPO_HEIGHT_STANDARD)/(R_D*TROPO_TEMP_STANDARD)); } else { pressure_at_inv_standard = P_0_STANDARD*pow(1 + TEMP_GRADIENT*TROPO_HEIGHT_STANDARD/T_SFC, -G/(R_D*TEMP_GRADIENT))*exp(-G*(INVERSE_HEIGHT_STANDARD - TROPO_HEIGHT_STANDARD)/(R_D*TROPO_TEMP_STANDARD)); pressure = pressure_at_inv_standard*pow(1 + TEMP_GRADIENT*(z_height - INVERSE_HEIGHT_STANDARD)/T_SFC, -G/(R_D*TEMP_GRADIENT)); } return pressure; }
quicksort.h
// -*- C++ -*- // Copyright (C) 2007-2019 Free Software Foundation, Inc. // // This file is part of the GNU ISO C++ Library. This library 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. // This 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 // General Public License for more details. // Under Section 7 of GPL version 3, you are granted additional // permissions described in the GCC Runtime Library Exception, version // 3.1, as published by the Free Software Foundation. // You should have received a copy of the GNU General Public License and // a copy of the GCC Runtime Library Exception along with this program; // see the files COPYING3 and COPYING.RUNTIME respectively. If not, see // <http://www.gnu.org/licenses/>. /** @file parallel/quicksort.h * @brief Implementation of a unbalanced parallel quicksort (in-place). * This file is a GNU parallel extension to the Standard C++ Library. */ // Written by Johannes Singler. #ifndef _GLIBCXX_PARALLEL_QUICKSORT_H #define _GLIBCXX_PARALLEL_QUICKSORT_H 1 #include <parallel/parallel.h> #include <parallel/partition.h> namespace __gnu_parallel { /** @brief Unbalanced quicksort divide step. * @param __begin Begin iterator of subsequence. * @param __end End iterator of subsequence. * @param __comp Comparator. * @param __pivot_rank Desired __rank of the pivot. * @param __num_samples Choose pivot from that many samples. * @param __num_threads Number of threads that are allowed to work on * this part. */ template<typename _RAIter, typename _Compare> typename std::iterator_traits<_RAIter>::difference_type __parallel_sort_qs_divide(_RAIter __begin, _RAIter __end, _Compare __comp, typename std::iterator_traits <_RAIter>::difference_type __pivot_rank, typename std::iterator_traits <_RAIter>::difference_type __num_samples, _ThreadIndex __num_threads) { typedef std::iterator_traits<_RAIter> _TraitsType; typedef typename _TraitsType::value_type _ValueType; typedef typename _TraitsType::difference_type _DifferenceType; _DifferenceType __n = __end - __begin; __num_samples = std::min(__num_samples, __n); // Allocate uninitialized, to avoid default constructor. _ValueType* __samples = static_cast<_ValueType*> (::operator new(__num_samples * sizeof(_ValueType))); for (_DifferenceType __s = 0; __s < __num_samples; ++__s) { const unsigned long long __index = static_cast<unsigned long long> (__s) * __n / __num_samples; ::new(&(__samples[__s])) _ValueType(__begin[__index]); } __gnu_sequential::sort(__samples, __samples + __num_samples, __comp); _ValueType& __pivot = __samples[__pivot_rank * __num_samples / __n]; __gnu_parallel::__binder2nd<_Compare, _ValueType, _ValueType, bool> __pred(__comp, __pivot); _DifferenceType __split = __parallel_partition(__begin, __end, __pred, __num_threads); for (_DifferenceType __s = 0; __s < __num_samples; ++__s) __samples[__s].~_ValueType(); ::operator delete(__samples); return __split; } /** @brief Unbalanced quicksort conquer step. * @param __begin Begin iterator of subsequence. * @param __end End iterator of subsequence. * @param __comp Comparator. * @param __num_threads Number of threads that are allowed to work on * this part. */ template<typename _RAIter, typename _Compare> void __parallel_sort_qs_conquer(_RAIter __begin, _RAIter __end, _Compare __comp, _ThreadIndex __num_threads) { typedef std::iterator_traits<_RAIter> _TraitsType; typedef typename _TraitsType::value_type _ValueType; typedef typename _TraitsType::difference_type _DifferenceType; if (__num_threads <= 1) { __gnu_sequential::sort(__begin, __end, __comp); return; } _DifferenceType __n = __end - __begin, __pivot_rank; if (__n <= 1) return; _ThreadIndex __num_threads_left; if ((__num_threads % 2) == 1) __num_threads_left = __num_threads / 2 + 1; else __num_threads_left = __num_threads / 2; __pivot_rank = __n * __num_threads_left / __num_threads; _DifferenceType __split = __parallel_sort_qs_divide (__begin, __end, __comp, __pivot_rank, _Settings::get().sort_qs_num_samples_preset, __num_threads); #pragma omp parallel sections num_threads(2) { #pragma omp section __parallel_sort_qs_conquer(__begin, __begin + __split, __comp, __num_threads_left); #pragma omp section __parallel_sort_qs_conquer(__begin + __split, __end, __comp, __num_threads - __num_threads_left); } } /** @brief Unbalanced quicksort main call. * @param __begin Begin iterator of input sequence. * @param __end End iterator input sequence, ignored. * @param __comp Comparator. * @param __num_threads Number of threads that are allowed to work on * this part. */ template<typename _RAIter, typename _Compare> void __parallel_sort_qs(_RAIter __begin, _RAIter __end, _Compare __comp, _ThreadIndex __num_threads) { _GLIBCXX_CALL(__n) typedef std::iterator_traits<_RAIter> _TraitsType; typedef typename _TraitsType::value_type _ValueType; typedef typename _TraitsType::difference_type _DifferenceType; _DifferenceType __n = __end - __begin; // At least one element per processor. if (__num_threads > __n) __num_threads = static_cast<_ThreadIndex>(__n); __parallel_sort_qs_conquer( __begin, __begin + __n, __comp, __num_threads); } } //namespace __gnu_parallel #endif /* _GLIBCXX_PARALLEL_QUICKSORT_H */
GB_AxB_saxpy3.c
//------------------------------------------------------------------------------ // GB_AxB_saxpy3: compute C=A*B, C<M>=A*B, or C<!M>=A*B in parallel //------------------------------------------------------------------------------ // SuiteSparse:GraphBLAS, Timothy A. Davis, (c) 2017-2020, All Rights Reserved. // http://suitesparse.com See GraphBLAS/Doc/License.txt for license. //------------------------------------------------------------------------------ // GB_AxB_saxpy3 computes C=A*B, C<M>=A*B, or C<!M>=A*B in parallel. If the // mask matrix M has too many entries compared to the work to compute A*B, then // it is not applied. Instead, M is ignored and C=A*B is computed. The mask // is applied later, in GB_mxm. // For simplicity, this discussion and all comments in this code assume that // all matrices are in CSC format, but the algorithm is CSR/CSC agnostic. // The matrix B is split into two kinds of tasks: coarse and fine. A coarse // task computes C(:,j1:j2) = A*B(:,j1:j2), for a unique set of vectors j1:j2. // Those vectors are not shared with any other tasks. A fine task works with a // team of other fine tasks to compute C(:,j) for a single vector j. Each fine // task computes A*B(k1:k2,j) for a unique range k1:k2, and sums its results // into C(:,j) via atomic operations. // Each coarse or fine task uses either Gustavson's method [1] or the Hash // method [2]. There are 4 kinds of tasks: // fine Gustavson task // fine hash task // coarse Gustason task // coarse hash task // Each of the 4 kinds tasks are then subdivided into 3 variants, for C=A*B, // C<M>=A*B, and C<!M>=A*B, giving a total of 12 different types of tasks. // Fine tasks are used when there would otherwise be too much work for a single // task to compute the single vector C(:,j). Fine tasks share all of their // workspace with the team of fine tasks computing C(:,j). Coarse tasks are // prefered since they require less synchronization, but fine tasks allow for // better parallelization when B has only a few vectors. If B consists of a // single vector (for GrB_mxv if A is in CSC format and not transposed, or // for GrB_vxm if A is in CSR format and not transpose), then the only way to // get parallelism is via fine tasks. If a single thread is used for this // case, a single-vector coarse task is used. // To select between the Hash method or Gustavson's method for each task, the // hash table size is first found. The hash table size for a hash task depends // on the maximum flop count for any vector in that task (which is just one // vector for the fine tasks). It is set to twice the smallest power of 2 that // is greater than the flop count to compute that vector (plus the # of entries // in M(:,j) for tasks that compute C<M>=A*B or C<!M>=A*B). This size ensures // the results will fit in the hash table, and with hopefully only a modest // number of collisions. If the hash table size exceeds a threshold (currently // m/16 if C is m-by-n), then Gustavson's method is used instead, and the hash // table size is set to m, to serve as the gather/scatter workspace for // Gustavson's method. // The workspace allocated depends on the type of task. Let s be the hash // table size for the task, and C is m-by-n (assuming all matrices are CSC; if // CSR, then m is replaced with n). // // fine Gustavson task (shared): int8_t Hf [m] ; ctype Hx [m] ; // fine hash task (shared): int64_t Hf [s] ; ctype Hx [s] ; // coarse Gustavson task: int64_t Hf [m] ; ctype Hx [m] ; // coarse hash task: int64_t Hf [s] ; ctype Hx [s] ; // int64_t Hi [s] ; // // Note that the Hi array is needed only for the coarse hash task. Additional // workspace is allocated to construct the list of tasks, but this is freed // before C is constructed. // References: // [1] Fred G. Gustavson. 1978. Two Fast Algorithms for Sparse Matrices: // Multiplication and Permuted Transposition. ACM Trans. Math. Softw. 4, 3 // (Sept. 1978), 250–269. DOI:https://doi.org/10.1145/355791.355796 // [2] Yusuke Nagasaka, Satoshi Matsuoka, Ariful Azad, and Aydın Buluç. 2018. // High-Performance Sparse Matrix-Matrix Products on Intel KNL and Multicore // Architectures. In Proc. 47th Intl. Conf. on Parallel Processing (ICPP '18). // Association for Computing Machinery, New York, NY, USA, Article 34, 1–10. // DOI:https://doi.org/10.1145/3229710.3229720 //------------------------------------------------------------------------------ #include "GB_mxm.h" #include "GB_AxB_saxpy3.h" #ifndef GBCOMPACT #include "GB_AxB__include.h" #endif //------------------------------------------------------------------------------ // control parameters for generating parallel tasks //------------------------------------------------------------------------------ #define GB_NTASKS_PER_THREAD 2 #define GB_COSTLY 1.2 #define GB_FINE_WORK 2 #define GB_MWORK_ALPHA 0.01 //------------------------------------------------------------------------------ // free workspace //------------------------------------------------------------------------------ // This workspace is not needed in the GB_Asaxpy3B* worker functions. #define GB_FREE_INITIAL_WORK \ { \ GB_FREE_MEMORY (Bflops2, max_bjnz+1, sizeof (int64_t)) ; \ GB_FREE_MEMORY (Coarse_Work, nthreads_max, sizeof (int64_t)) ; \ GB_FREE_MEMORY (Coarse_initial, ntasks_initial+1, sizeof (int64_t)) ; \ GB_FREE_MEMORY (Fine_slice, ntasks+1, sizeof (int64_t)) ; \ } #define GB_FREE_WORK \ { \ GB_FREE_INITIAL_WORK ; \ GB_FREE_MEMORY (TaskList, ntasks, sizeof (GB_saxpy3task_struct)) ; \ GB_FREE_MEMORY (Hi_all, Hi_size_total, sizeof (int64_t)) ; \ GB_FREE_MEMORY (Hf_all, Hf_size_total, sizeof (int64_t)) ; \ GB_FREE_MEMORY (Hx_all, Hx_size_total, 1) ; \ } #define GB_FREE_ALL \ { \ GB_FREE_WORK ; \ GB_MATRIX_FREE (Chandle) ; \ } //------------------------------------------------------------------------------ // GB_hash_table_size //------------------------------------------------------------------------------ // flmax is the max flop count for computing A*B(:,j), for any vector j that // this task computes. If the mask M is present, flmax also includes the // number of entries in M(:,j). GB_hash_table_size determines the hash table // size for this task, which is twice the smallest power of 2 larger than // flmax. If flmax is large enough, the hash_size is returned as cvlen, so // that Gustavson's method will be used instead of the Hash method. // By default, Gustavson vs Hash is selected automatically. AxB_method can be // selected via the descriptor or a global setting, as the non-default // GxB_AxB_GUSTAVSON or GxB_AxB_HASH settings, to enforce the selection of // either of those methods. However, if Hash is selected by the hash table // exceeds cvlen, then Gustavson's method is used instead. static inline int64_t GB_hash_table_size ( int64_t flmax, // max flop count for any vector computed by this task int64_t cvlen, // vector length of C const GrB_Desc_Value AxB_method // Default, Gustavson, or Hash ) { // hash_size = 2 * (smallest power of 2 >= flmax) double hlog = log2 ((double) flmax) ; int64_t hash_size = ((int64_t) 2) << ((int64_t) floor (hlog) + 1) ; bool use_Gustavson ; if (AxB_method == GxB_AxB_GUSTAVSON) { // always use Gustavson's method use_Gustavson = true ; } else if (AxB_method == GxB_AxB_HASH) { // always use Hash method, unless the hash_size >= cvlen use_Gustavson = (hash_size >= cvlen) ; } else { // default: auto selection: // use Gustavson's method if hash_size is too big use_Gustavson = (hash_size >= cvlen/16) ; } if (use_Gustavson) { hash_size = cvlen ; } return (hash_size) ; } //------------------------------------------------------------------------------ // GB_create_coarse_task: create a single coarse task //------------------------------------------------------------------------------ // Compute the max flop count for any vector in a coarse task, determine the // hash table size, and construct the coarse task. static inline void GB_create_coarse_task ( int64_t kfirst, // coarse task consists of vectors kfirst:klast int64_t klast, GB_saxpy3task_struct *TaskList, int taskid, // taskid for this coarse task int64_t *Bflops, // size bnvec; cum sum of flop counts for vectors of B int64_t cvlen, // vector length of B and C double chunk, int nthreads_max, int64_t *Coarse_Work, // workspace for parallel reduction for flop count const GrB_Desc_Value AxB_method // Default, Gustavson, or Hash ) { // find the max # of flops for any vector in this task int64_t nk = klast - kfirst + 1 ; int nth = GB_nthreads (nk, chunk, nthreads_max) ; int64_t tid ; // each thread finds the max flop count for a subset of the vectors #pragma omp parallel for num_threads(nth) schedule(static) for (tid = 0 ; tid < nth ; tid++) { int64_t my_flmax = 1, istart, iend ; GB_PARTITION (istart, iend, nk, tid, nth) ; for (int64_t i = istart ; i < iend ; i++) { int64_t kk = kfirst + i ; int64_t fl = Bflops [kk+1] - Bflops [kk] ; my_flmax = GB_IMAX (my_flmax, fl) ; } Coarse_Work [tid] = my_flmax ; } // combine results from each thread int64_t flmax = 1 ; for (tid = 0 ; tid < nth ; tid++) { flmax = GB_IMAX (flmax, Coarse_Work [tid]) ; } // check the parallel computation #ifdef GB_DEBUG int64_t flmax2 = 1 ; for (int64_t kk = kfirst ; kk <= klast ; kk++) { int64_t fl = Bflops [kk+1] - Bflops [kk] ; flmax2 = GB_IMAX (flmax2, fl) ; } ASSERT (flmax == flmax2) ; #endif // define the coarse task TaskList [taskid].start = kfirst ; TaskList [taskid].end = klast ; TaskList [taskid].vector = -1 ; TaskList [taskid].hsize = GB_hash_table_size (flmax, cvlen, AxB_method) ; TaskList [taskid].Hi = NULL ; // assigned later TaskList [taskid].Hf = NULL ; // assigned later TaskList [taskid].Hx = NULL ; // assigned later TaskList [taskid].my_cjnz = 0 ; // unused TaskList [taskid].flops = Bflops [klast+1] - Bflops [kfirst] ; TaskList [taskid].master = taskid ; TaskList [taskid].team_size = 1 ; } //------------------------------------------------------------------------------ // GB_AxB_saxpy3: compute C=A*B, C<M>=A*B, or C<!M>=A*B in parallel //------------------------------------------------------------------------------ GrB_Info GB_AxB_saxpy3 // C = A*B using Gustavson+Hash ( GrB_Matrix *Chandle, // output matrix const GrB_Matrix M_input, // optional mask matrix const bool Mask_comp_input, // if true, use !M const bool Mask_struct, // if true, use the only structure of M const GrB_Matrix A, // input matrix A const GrB_Matrix B, // input matrix B const GrB_Semiring semiring, // semiring that defines C=A*B const bool flipxy, // if true, do z=fmult(b,a) vs fmult(a,b) bool *mask_applied, // if true, then mask was applied const GrB_Desc_Value AxB_method, // Default, Gustavson, or Hash GB_Context Context ) { //-------------------------------------------------------------------------- // check inputs //-------------------------------------------------------------------------- GrB_Info info ; GrB_Matrix M = M_input ; // use the mask M, until deciding otherwise bool Mask_comp = Mask_comp_input ; (*mask_applied) = false ; ASSERT (Chandle != NULL) ; ASSERT (*Chandle == NULL) ; ASSERT_MATRIX_OK_OR_NULL (M, "M for saxpy3 A*B", GB0) ; ASSERT_MATRIX_OK (A, "A for saxpy3 A*B", GB0) ; ASSERT_MATRIX_OK (B, "B for saxpy3 A*B", GB0) ; ASSERT (!GB_PENDING (A)) ; ASSERT (!GB_ZOMBIES (A)) ; ASSERT (!GB_PENDING (B)) ; ASSERT (!GB_ZOMBIES (B)) ; ASSERT_SEMIRING_OK (semiring, "semiring for saxpy3 A*B", GB0) ; ASSERT (A->vdim == B->vlen) ; int64_t *GB_RESTRICT Hi_all = NULL ; int64_t *GB_RESTRICT Hf_all = NULL ; GB_void *GB_RESTRICT Hx_all = NULL ; int64_t *GB_RESTRICT Coarse_initial = NULL ; // initial coarse tasks int64_t *GB_RESTRICT Coarse_Work = NULL ; // workspace for flop counts GB_saxpy3task_struct *GB_RESTRICT TaskList = NULL ; int64_t *GB_RESTRICT Fine_slice = NULL ; int64_t *GB_RESTRICT Bflops2 = NULL ; int ntasks = 0 ; int ntasks_initial = 0 ; size_t Hi_size_total = 0 ; size_t Hf_size_total = 0 ; size_t Hx_size_total = 0 ; int64_t max_bjnz = 0 ; //-------------------------------------------------------------------------- // get the semiring operators //-------------------------------------------------------------------------- GrB_BinaryOp mult = semiring->multiply ; GrB_Monoid add = semiring->add ; ASSERT (mult->ztype == add->op->ztype) ; bool op_is_first = mult->opcode == GB_FIRST_opcode ; bool op_is_second = mult->opcode == GB_SECOND_opcode ; bool op_is_pair = mult->opcode == GB_PAIR_opcode ; bool A_is_pattern = false ; bool B_is_pattern = false ; if (flipxy) { // z = fmult (b,a) will be computed A_is_pattern = op_is_first || op_is_pair ; B_is_pattern = op_is_second || op_is_pair ; ASSERT (GB_IMPLIES (!A_is_pattern, GB_Type_compatible (A->type, mult->ytype))) ; ASSERT (GB_IMPLIES (!B_is_pattern, GB_Type_compatible (B->type, mult->xtype))) ; } else { // z = fmult (a,b) will be computed A_is_pattern = op_is_second || op_is_pair ; B_is_pattern = op_is_first || op_is_pair ; ASSERT (GB_IMPLIES (!A_is_pattern, GB_Type_compatible (A->type, mult->xtype))) ; ASSERT (GB_IMPLIES (!B_is_pattern, GB_Type_compatible (B->type, mult->ytype))) ; } #ifdef GBCOMPACT bool is_any_pair_semiring = false ; #else GB_Opcode mult_opcode, add_opcode ; GB_Type_code xycode, zcode ; bool builtin_semiring = GB_AxB_semiring_builtin (A, A_is_pattern, B, B_is_pattern, semiring, flipxy, &mult_opcode, &add_opcode, &xycode, &zcode) ; bool is_any_pair_semiring = builtin_semiring && (add_opcode == GB_ANY_opcode) && (mult_opcode == GB_PAIR_opcode) ; #endif (*Chandle) = NULL ; //-------------------------------------------------------------------------- // get A, and B //-------------------------------------------------------------------------- const int64_t *GB_RESTRICT Ap = A->p ; const int64_t *GB_RESTRICT Ah = A->h ; const int64_t *GB_RESTRICT Ai = A->i ; const int64_t avlen = A->vlen ; const int64_t anvec = A->nvec ; const bool A_is_hyper = A->is_hyper ; const int64_t *GB_RESTRICT Bp = B->p ; const int64_t *GB_RESTRICT Bh = B->h ; const int64_t *GB_RESTRICT Bi = B->i ; const int64_t bvdim = B->vdim ; const int64_t bnz = GB_NNZ (B) ; const int64_t bnvec = B->nvec ; const bool B_is_hyper = B->is_hyper ; //-------------------------------------------------------------------------- // determine the # of threads to use //-------------------------------------------------------------------------- GB_GET_NTHREADS_MAX (nthreads_max, chunk, Context) ; //-------------------------------------------------------------------------- // allocate C (just C->p and C->h, but not C->i or C->x) //-------------------------------------------------------------------------- GrB_Type ctype = add->op->ztype ; size_t csize = ctype->size ; int64_t cvlen = avlen ; int64_t cvdim = bvdim ; int64_t cnvec = bnvec ; // calloc Cp so it can be used as the Bflops workspace GB_NEW (Chandle, ctype, cvlen, cvdim, GB_Ap_calloc, true, GB_SAME_HYPER_AS (B_is_hyper), B->hyper_ratio, cnvec, Context) ; if (info != GrB_SUCCESS) { // out of memory GB_FREE_ALL ; return (info) ; } GrB_Matrix C = (*Chandle) ; int64_t *GB_RESTRICT Cp = C->p ; int64_t *GB_RESTRICT Ch = C->h ; if (B_is_hyper) { // C has the same set of vectors as B int nth = GB_nthreads (cnvec, chunk, nthreads_max) ; GB_memcpy (Ch, Bh, cnvec * sizeof (int64_t), nth) ; C->nvec = bnvec ; } //========================================================================== // phase0: create parallel tasks //========================================================================== //-------------------------------------------------------------------------- // compute flop counts for each vector of B and C //-------------------------------------------------------------------------- int64_t Mwork = 0 ; int64_t *GB_RESTRICT Bflops = Cp ; // Cp is used as workspace for Bflops GB_OK (GB_AxB_flopcount (&Mwork, Bflops, M, Mask_comp, A, B, Context)) ; int64_t total_flops = Bflops [bnvec] ; //-------------------------------------------------------------------------- // determine if the mask M should be applied, or done later //-------------------------------------------------------------------------- // If M is very large as compared to A*B, then it is too costly to apply // during the computation of A*B. In this case, compute C=A*B, ignoring // the mask. Tell the caller that the mask was not applied, so that it // will be applied later in GB_mxm. double axbflops = total_flops - Mwork ; GBBURBLE ("axbflops %g Mwork %g ", axbflops, (double) Mwork) ; if ((M != NULL) && (axbflops < ((double) Mwork * GB_MWORK_ALPHA))) { // M is present but costly to use. Do not use it during the // computation of A*B. Instead, compute C=A*B and then apply the mask // later. M = NULL ; Mask_comp = false ; int nth = GB_nthreads (bnvec, chunk, nthreads_max) ; int64_t kk ; // GB_AxB_flopcount requires Bflops be set to zero here #pragma omp parallel for num_threads(nth) schedule(static) for (kk = 0 ; kk <= bnvec ; kk++) { Bflops [kk] = 0 ; } // redo the flop count analysis, without the mask GB_OK (GB_AxB_flopcount (&Mwork, Bflops, NULL, false, A, B, Context)) ; total_flops = Bflops [bnvec] ; GBBURBLE ("(discard mask) ") ; } else if (M != NULL) { GBBURBLE ("(use mask) ") ; } //-------------------------------------------------------------------------- // get M //-------------------------------------------------------------------------- bool mask_is_M = (M != NULL && !Mask_comp) ; const int64_t *GB_RESTRICT Mp = NULL ; const int64_t *GB_RESTRICT Mh = NULL ; const int64_t *GB_RESTRICT Mi = NULL ; // const GB_void *GB_RESTRICT Mx = NULL ; // size_t msize = 0 ; int64_t mnvec = 0 ; bool M_is_hyper = false ; if (M != NULL) { Mp = M->p ; Mh = M->h ; Mi = M->i ; // Mx = M->x ; // msize = M->type->size ; mnvec = M->nvec ; M_is_hyper = M->is_hyper ; } //-------------------------------------------------------------------------- // determine # of threads and # of initial coarse tasks //-------------------------------------------------------------------------- int nthreads = GB_nthreads ((double) total_flops, chunk, nthreads_max) ; ntasks_initial = (nthreads == 1) ? 1 : (GB_NTASKS_PER_THREAD * nthreads) ; double target_task_size = ((double) total_flops) / ntasks_initial ; target_task_size = GB_IMAX (target_task_size, chunk) ; double target_fine_size = target_task_size / GB_FINE_WORK ; target_fine_size = GB_IMAX (target_fine_size, chunk) ; //-------------------------------------------------------------------------- // determine # of parallel tasks //-------------------------------------------------------------------------- int nfine = 0 ; // # of fine tasks int ncoarse = 0 ; // # of coarse tasks max_bjnz = 0 ; // max (nnz (B (:,j))) of fine tasks // FUTURE: also use ultra-fine tasks that compute A(i1:i2,k)*B(k,j) if (ntasks_initial > 1) { //---------------------------------------------------------------------- // construct initial coarse tasks //---------------------------------------------------------------------- if (!GB_pslice (&Coarse_initial, Bflops, bnvec, ntasks_initial)) { // out of memory GB_FREE_ALL ; return (GB_OUT_OF_MEMORY) ; } //---------------------------------------------------------------------- // split the work into coarse and fine tasks //---------------------------------------------------------------------- for (int taskid = 0 ; taskid < ntasks_initial ; taskid++) { // get the initial coarse task int64_t kfirst = Coarse_initial [taskid] ; int64_t klast = Coarse_initial [taskid+1] ; int64_t task_ncols = klast - kfirst ; int64_t task_flops = Bflops [klast] - Bflops [kfirst] ; if (task_ncols == 0) { // This coarse task is empty, having been squeezed out by // costly vectors in adjacent coarse tasks. } else if (task_flops > 2 * GB_COSTLY * target_task_size) { // This coarse task is too costly, because it contains one or // more costly vectors. Split its vectors into a mixture of // coarse and fine tasks. int64_t kcoarse_start = kfirst ; for (int64_t kk = kfirst ; kk < klast ; kk++) { // jflops = # of flops to compute a single vector A*B(:,j) // where j == (Bh == NULL) ? kk : Bh [kk]. double jflops = Bflops [kk+1] - Bflops [kk] ; // bjnz = nnz (B (:,j)) int64_t bjnz = Bp [kk+1] - Bp [kk] ; if (jflops > GB_COSTLY * target_task_size && bjnz > 1) { // A*B(:,j) is costly; split it into 2 or more fine // tasks. First flush the prior coarse task, if any. if (kcoarse_start < kk) { // vectors kcoarse_start to kk-1 form a single // coarse task ncoarse++ ; } // next coarse task (if any) starts at kk+1 kcoarse_start = kk+1 ; // vectors kk will be split into multiple fine tasks max_bjnz = GB_IMAX (max_bjnz, bjnz) ; int team_size = ceil (jflops / target_fine_size) ; nfine += team_size ; } } // flush the last coarse task, if any if (kcoarse_start < klast) { // vectors kcoarse_start to klast-1 form a single // coarse task ncoarse++ ; } } else { // This coarse task is OK as-is. ncoarse++ ; } } } else { //---------------------------------------------------------------------- // entire computation in a single fine or coarse task //---------------------------------------------------------------------- if (bnvec == 1) { // If B is a single vector, and is computed by a single thread, // then a single fine task is used. nfine = 1 ; ncoarse = 0 ; } else { // One thread uses a single coarse task if B is not a vector. nfine = 0 ; ncoarse = 1 ; } } ntasks = ncoarse + nfine ; //-------------------------------------------------------------------------- // allocate the tasks, and workspace to construct fine tasks //-------------------------------------------------------------------------- GB_CALLOC_MEMORY (TaskList, ntasks, sizeof (GB_saxpy3task_struct)) ; GB_MALLOC_MEMORY (Coarse_Work, nthreads_max, sizeof (int64_t)) ; if (max_bjnz > 0) { // also allocate workspace to construct fine tasks GB_MALLOC_MEMORY (Fine_slice, ntasks+1, sizeof (int64_t)) ; GB_MALLOC_MEMORY (Bflops2, max_bjnz+1, sizeof (int64_t)) ; } if (TaskList == NULL || Coarse_Work == NULL || (max_bjnz > 0 && (Fine_slice == NULL || Bflops2 == NULL))) { // out of memory GB_FREE_ALL ; return (GB_OUT_OF_MEMORY) ; } //-------------------------------------------------------------------------- // create the tasks //-------------------------------------------------------------------------- if (ntasks_initial > 1) { //---------------------------------------------------------------------- // create the coarse and fine tasks //---------------------------------------------------------------------- int nf = 0 ; // fine tasks have task id 0:nfine-1 int nc = nfine ; // coarse task ids are nfine:ntasks-1 for (int taskid = 0 ; taskid < ntasks_initial ; taskid++) { // get the initial coarse task int64_t kfirst = Coarse_initial [taskid] ; int64_t klast = Coarse_initial [taskid+1] ; int64_t task_ncols = klast - kfirst ; int64_t task_flops = Bflops [klast] - Bflops [kfirst] ; if (task_ncols == 0) { // This coarse task is empty, having been squeezed out by // costly vectors in adjacent coarse tasks. } else if (task_flops > 2 * GB_COSTLY * target_task_size) { // This coarse task is too costly, because it contains one or // more costly vectors. Split its vectors into a mixture of // coarse and fine tasks. int64_t kcoarse_start = kfirst ; for (int64_t kk = kfirst ; kk < klast ; kk++) { // jflops = # of flops to compute a single vector A*B(:,j) double jflops = Bflops [kk+1] - Bflops [kk] ; // bjnz = nnz (B (:,j)) int64_t bjnz = Bp [kk+1] - Bp [kk] ; if (jflops > GB_COSTLY * target_task_size && bjnz > 1) { // A*B(:,j) is costly; split it into 2 or more fine // tasks. First flush the prior coarse task, if any. if (kcoarse_start < kk) { // kcoarse_start:kk-1 form a single coarse task GB_create_coarse_task (kcoarse_start, kk-1, TaskList, nc++, Bflops, cvlen, chunk, nthreads_max, Coarse_Work, AxB_method) ; } // next coarse task (if any) starts at kk+1 kcoarse_start = kk+1 ; // get the mask M(:,j), for C<M>=A*B int64_t im_first = -1, im_last = -1 ; if (mask_is_M) { int64_t j = (Bh == NULL) ? kk : Bh [kk] ; int64_t mpleft = 0 ; int64_t mpright = mnvec-1 ; int64_t pM, pM_end ; GB_lookup (M_is_hyper, Mh, Mp, &mpleft, mpright, j, &pM, &pM_end) ; int64_t mjnz = pM_end - pM ; // nnz (M (:,j)) // For C<M>=A*B, if M(:,j) is empty, then there // would be no flops to compute C(:,j), and thus // no fine tasks constructed for C(:,j). // Thus mjnz > 0 must hold. ASSERT (mjnz > 0) ; if (mjnz > 0) // but check anyway, just to be safe { im_first = Mi [pM] ; im_last = Mi [pM_end-1] ; } } // count the work for each entry B(k,j). Do not // include the work to scan M(:,j), since that will // be evenly divided between all tasks in this team. // Do check if M(:,j) and A(:,k) are disjoint, for // C<M>=A*B, when accounting for the flops for B(k,j). int64_t pB_start = Bp [kk] ; int nth = GB_nthreads (bjnz, chunk, nthreads_max) ; int64_t s ; #pragma omp parallel for num_threads(nth) \ schedule(static) for (s = 0 ; s < bjnz ; s++) { // get B(k,j) int64_t k = Bi [pB_start + s] ; // fl = flop count for just A(:,k)*B(k,j) int64_t pA, pA_end ; int64_t pleft = 0 ; GB_lookup (A_is_hyper, Ah, Ap, &pleft, anvec-1, k, &pA, &pA_end) ; int64_t fl = pA_end - pA ; if (mask_is_M && fl > 0) { // no work if A(:,k) and M(:,j) disjoint int64_t alo = Ai [pA] ; // get first A(:,k) int64_t ahi = Ai [pA_end-1] ;// get last A(:,k) if (ahi < im_first || alo > im_last) fl = 0 ; } Bflops2 [s] = fl ; ASSERT (fl >= 0) ; } // cumulative sum of flops to compute A*B(:,j) GB_cumsum (Bflops2, bjnz, NULL, nth) ; // slice B(:,j) into fine tasks int team_size = ceil (jflops / target_fine_size) ; ASSERT (Fine_slice != NULL) ; GB_pslice (&Fine_slice, Bflops2, bjnz, team_size) ; // shared hash table for all fine tasks for A*B(:,j) int64_t hsize = GB_hash_table_size (jflops, cvlen, AxB_method) ; // construct the fine tasks for C(:,j)=A*B(:,j) int master = nf ; for (int fid = 0 ; fid < team_size ; fid++) { int64_t pstart = Fine_slice [fid] ; int64_t pend = Fine_slice [fid+1] ; int64_t fl = Bflops2 [pend] - Bflops2 [pstart] ; TaskList [nf].start = pB_start + pstart ; TaskList [nf].end = pB_start + pend - 1 ; TaskList [nf].vector = kk ; TaskList [nf].hsize = hsize ; TaskList [nf].Hi = NULL ; // assigned later TaskList [nf].Hf = NULL ; // assigned later TaskList [nf].Hx = NULL ; // assigned later TaskList [nf].my_cjnz = 0 ; TaskList [nf].flops = fl ; TaskList [nf].master = master ; TaskList [nf].team_size = team_size ; nf++ ; } } } // flush the last coarse task, if any if (kcoarse_start < klast) { // kcoarse_start:klast-1 form a single coarse task GB_create_coarse_task (kcoarse_start, klast-1, TaskList, nc++, Bflops, cvlen, chunk, nthreads_max, Coarse_Work, AxB_method) ; } } else { // This coarse task is OK as-is. GB_create_coarse_task (kfirst, klast-1, TaskList, nc++, Bflops, cvlen, chunk, nthreads_max, Coarse_Work, AxB_method) ; } } } else { //---------------------------------------------------------------------- // entire computation in a single fine or coarse task //---------------------------------------------------------------------- // create a single coarse task GB_create_coarse_task (0, bnvec-1, TaskList, 0, Bflops, cvlen, 1, 1, Coarse_Work, AxB_method) ; if (bnvec == 1) { // convert the single coarse task into a single fine task TaskList [0].start = 0 ; // first entry in B(:,0) TaskList [0].end = bnz - 1 ; // last entry in B(:,0) TaskList [0].vector = 0 ; } } //-------------------------------------------------------------------------- // free workspace used to create the tasks //-------------------------------------------------------------------------- // Frees Bflops2, Coarse_initial, Coarse_Work, and Fine_slice. These do // not need to be freed in the GB_Asaxpy3B worker below. GB_FREE_INITIAL_WORK ; //-------------------------------------------------------------------------- #if GB_BURBLE int nfine_hash = 0 ; int nfine_gus = 0 ; int ncoarse_hash = 0 ; int ncoarse_1hash = 0 ; int ncoarse_gus = 0 ; for (int taskid = 0 ; taskid < ntasks ; taskid++) { int64_t hash_size = TaskList [taskid].hsize ; bool is_fine = (taskid < nfine) ; bool use_Gustavson = (hash_size == cvlen) ; if (is_fine) { // fine task if (use_Gustavson) { // fine Gustavson task nfine_gus++ ; } else { // fine hash task nfine_hash++ ; } } else { // coarse task int64_t kfirst = TaskList [taskid].start ; int64_t klast = TaskList [taskid].end ; if (use_Gustavson) { // coarse Gustavson task ncoarse_gus++ ; } else { // hash task ncoarse_hash++ ; } } } GBBURBLE ("nthreads %d ntasks %d coarse: (gus: %d hash: %d)" " fine: (gus: %d hash: %d) ", nthreads, ntasks, ncoarse_gus, ncoarse_hash, nfine_gus, nfine_hash) ; #endif // Bflops is no longer needed as an alias for Cp Bflops = NULL ; //-------------------------------------------------------------------------- // allocate the hash tables //-------------------------------------------------------------------------- // If Gustavson's method is used (coarse tasks): // // hash_size is cvlen. // Hi is not allocated. // Hf and Hx are both of size hash_size. // // (Hf [i] == mark) is true if i is in the hash table. // Hx [i] is the value of C(i,j) during the numeric phase. // // Gustavson's method is used if the hash_size for the Hash method // is a significant fraction of cvlen. // // If the Hash method is used (coarse tasks): // // hash_size is 2 times the smallest power of 2 that is larger than // the # of flops required for any column C(:,j) being computed. This // ensures that all entries have space in the hash table, and that the // hash occupancy will never be more than 50%. It is always smaller // than cvlen (otherwise, Gustavson's method is used). // // A hash function is used for the ith entry: // hash = (i * GB_HASH_FACTOR) & (hash_size-1) // If a collision occurs, linear probing is used: // hash = (hash + 1) & (hashsize-1) // // (Hf [hash] == mark) is true if the position is occupied. // i = Hi [hash] gives the row index i that occupies that position. // Hx [hash] is the value of C(i,j) during the numeric phase. // // For both coarse methods: // // Hf starts out all zero (via calloc), and mark starts out as 1. To // clear Hf, mark is incremented, so that all entries in Hf are not // equal to mark. // add some padding to the end of each hash table, to avoid false // sharing of cache lines between the hash tables. size_t hx_pad = 64 ; size_t hi_pad = 64 / sizeof (int64_t) ; Hi_size_total = 0 ; Hf_size_total = 0 ; Hx_size_total = 0 ; // determine the total size of all hash tables for (int taskid = 0 ; taskid < ntasks ; taskid++) { if (taskid != TaskList [taskid].master) { // allocate a single shared hash table for all fine // tasks that compute a single C(:,j) continue ; } int64_t hash_size = TaskList [taskid].hsize ; int64_t k = TaskList [taskid].vector ; bool is_fine = (k >= 0) ; bool use_Gustavson = (hash_size == cvlen) ; // int64_t kfirst = TaskList [taskid].start ; // int64_t klast = TaskList [taskid].end ; if (is_fine && use_Gustavson) { // Hf is int8_t for the fine Gustavson tasks, but round up // to the nearest number of int64_t values. Hf_size_total += GB_CEIL ((hash_size + hi_pad), sizeof (int64_t)) ; } else { // all other methods use Hf as int64_t Hf_size_total += (hash_size + hi_pad) ; } if (!is_fine && !use_Gustavson) { // only coarse hash tasks need Hi Hi_size_total += (hash_size + hi_pad) ; } // all tasks use an Hx array of size hash_size if (!is_any_pair_semiring) { // except that the ANY_PAIR semiring does not use Hx Hx_size_total += (hash_size * csize + hx_pad) ; } } // allocate space for all hash tables if (Hi_size_total > 0) { GB_MALLOC_MEMORY (Hi_all, Hi_size_total, sizeof (int64_t)) ; } if (Hf_size_total > 0) { GB_CALLOC_MEMORY (Hf_all, Hf_size_total, sizeof (int64_t)) ; } if (Hx_size_total > 0) { GB_MALLOC_MEMORY (Hx_all, Hx_size_total, 1) ; } if ((Hi_size_total > 0 && Hi_all == NULL) || (Hf_size_total > 0 && Hf_all == NULL) || (Hx_size_total > 0 && Hx_all == NULL)) { // out of memory GB_FREE_ALL ; return (GB_OUT_OF_MEMORY) ; } // split the space into separate hash tables int64_t *GB_RESTRICT Hi_split = Hi_all ; int64_t *GB_RESTRICT Hf_split = Hf_all ; GB_void *GB_RESTRICT Hx_split = Hx_all ; for (int taskid = 0 ; taskid < ntasks ; taskid++) { if (taskid != TaskList [taskid].master) { // allocate a single hash table for all fine // tasks that compute a single C(:,j) continue ; } TaskList [taskid].Hi = Hi_split ; TaskList [taskid].Hf = (void *) Hf_split ; TaskList [taskid].Hx = Hx_split ; int64_t hash_size = TaskList [taskid].hsize ; int64_t k = TaskList [taskid].vector ; bool is_fine = (k >= 0) ; bool use_Gustavson = (hash_size == cvlen) ; // int64_t kfirst = TaskList [taskid].start ; // int64_t klast = TaskList [taskid].end ; if (is_fine && use_Gustavson) { // Hf is int8_t for the fine Gustavson method Hf_split += GB_CEIL ((hash_size + hi_pad), sizeof (int64_t)) ; } else { // Hf is int64_t for all other methods Hf_split += (hash_size + hi_pad) ; } if (!is_fine && !use_Gustavson) { // only coarse hash tasks need Hi Hi_split += (hash_size + hi_pad) ; } // all tasks use an Hx array of size hash_size if (!is_any_pair_semiring) { Hx_split += (hash_size * csize + hx_pad) ; } } // assign shared hash tables to fine task teams for (int taskid = 0 ; taskid < nfine ; taskid++) { int master = TaskList [taskid].master ; ASSERT (TaskList [master].vector >= 0) ; if (taskid != master) { // this fine task (Gustavson or hash) shares its hash table // with all other tasks in its team, for a single vector C(:,j). ASSERT (TaskList [taskid].vector == TaskList [master].vector) ; TaskList [taskid].Hf = TaskList [master].Hf ; TaskList [taskid].Hx = TaskList [master].Hx ; } } //========================================================================== // phase1: symbolic analysis //========================================================================== GB_AxB_saxpy3_symbolic (C, M, Mask_comp, Mask_struct, A, B, TaskList, ntasks, nfine, nthreads) ; //========================================================================== // C = A*B, via saxpy3 method and built-in semiring //========================================================================== bool done = false ; #ifndef GBCOMPACT //-------------------------------------------------------------------------- // define the worker for the switch factory //-------------------------------------------------------------------------- #define GB_Asaxpy3B(add,mult,xyname) GB_Asaxpy3B_ ## add ## mult ## xyname #define GB_AxB_WORKER(add,mult,xyname) \ { \ info = GB_Asaxpy3B (add,mult,xyname) (C, M, Mask_comp, \ Mask_struct, A, A_is_pattern, B, B_is_pattern, \ TaskList, ntasks, nfine, nthreads, Context) ; \ done = (info != GrB_NO_VALUE) ; \ } \ break ; //-------------------------------------------------------------------------- // launch the switch factory //-------------------------------------------------------------------------- if (builtin_semiring) { #include "GB_AxB_factory.c" } #endif //========================================================================== // C = A*B, via the generic saxpy3 method, with typecasting //========================================================================== if (!done) { GB_BURBLE_MATRIX (C, "generic ") ; info = GB_AxB_saxpy3_generic (C, M, Mask_comp, Mask_struct, A, A_is_pattern, B, B_is_pattern, semiring, flipxy, TaskList, ntasks, nfine, nthreads, Context) ; } if (info != GrB_SUCCESS) { // out of memory GB_FREE_ALL ; return (GB_OUT_OF_MEMORY) ; } //========================================================================== // prune empty vectors, free workspace, and return result //========================================================================== GB_FREE_WORK ; info = GB_hypermatrix_prune (C, Context) ; if (info == GrB_SUCCESS) { ASSERT_MATRIX_OK (C, "saxpy3: output", GB0) ; } ASSERT (*Chandle == C) ; ASSERT (!GB_ZOMBIES (C)) ; ASSERT (!GB_PENDING (C)) ; (*mask_applied) = (M != NULL) ; return (info) ; }
GB_binop__rminus_uint64.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__rminus_uint64 // A.*B function (eWiseMult): GB_AemultB__rminus_uint64 // A*D function (colscale): GB_AxD__rminus_uint64 // D*A function (rowscale): GB_DxB__rminus_uint64 // C+=B function (dense accum): GB_Cdense_accumB__rminus_uint64 // C+=b function (dense accum): GB_Cdense_accumb__rminus_uint64 // C+=A+B function (dense ewise3): GB_Cdense_ewise3_accum__rminus_uint64 // C=A+B function (dense ewise3): GB_Cdense_ewise3_noaccum__rminus_uint64 // C=scalar+B GB_bind1st__rminus_uint64 // C=scalar+B' GB_bind1st_tran__rminus_uint64 // C=A+scalar GB_bind2nd__rminus_uint64 // C=A'+scalar GB_bind2nd_tran__rminus_uint64 // C type: uint64_t // A type: uint64_t // B,b type: uint64_t // BinaryOp: cij = (bij - aij) #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, i, j) \ z = (y - x) ; // 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_RMINUS || GxB_NO_UINT64 || GxB_NO_RMINUS_UINT64) //------------------------------------------------------------------------------ // C += A+B, all 3 matrices dense //------------------------------------------------------------------------------ // The op must be MIN, MAX, PLUS, MINUS, RMINUS, TIMES, DIV, or RDIV. void GB_Cdense_ewise3_accum__rminus_uint64 ( GrB_Matrix C, const GrB_Matrix A, const GrB_Matrix B, const int nthreads ) { #include "GB_dense_ewise3_accum_template.c" } //------------------------------------------------------------------------------ // C = A+B, all 3 matrices dense //------------------------------------------------------------------------------ GrB_Info GB_Cdense_ewise3_noaccum__rminus_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__rminus_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__rminus_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__rminus_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__rminus_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 //------------------------------------------------------------------------------ #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__rminus_uint64 ( 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__rminus_uint64 ( 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__rminus_uint64 ( 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 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++) { if (!GBB (Bb, p)) continue ; uint64_t bij = Bx [p] ; Cx [p] = (bij - x) ; } return (GrB_SUCCESS) ; #endif } //------------------------------------------------------------------------------ // Cx = op (Ax,y): apply a binary operator to a matrix with scalar bind2nd //------------------------------------------------------------------------------ GrB_Info GB_bind2nd__rminus_uint64 ( 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 ; 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++) { if (!GBB (Ab, p)) continue ; uint64_t aij = Ax [p] ; Cx [p] = (y - aij) ; } 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) \ { \ uint64_t aij = Ax [pA] ; \ Cx [pC] = (aij - x) ; \ } GrB_Info GB_bind1st_tran__rminus_uint64 ( 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 \ uint64_t #if GB_DISABLE return (GrB_NO_VALUE) ; #else uint64_t x = (*((const uint64_t *) x_input)) ; #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 typecasting (in spite of the macro name) #undef GB_CAST_OP #define GB_CAST_OP(pC,pA) \ { \ uint64_t aij = Ax [pA] ; \ Cx [pC] = (y - aij) ; \ } GrB_Info GB_bind2nd_tran__rminus_uint64 ( 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 uint64_t y = (*((const uint64_t *) y_input)) ; #include "GB_unop_transpose.c" return (GrB_SUCCESS) ; #endif } #endif
teams.c
#include <stdio.h> #include <omp.h> #define HOST_MAX_TEAMS 70000 #define TRIALS (1) #define N (HOST_MAX_TEAMS+92) int A[N], B[N], C[N], D[N], E[N]; int main(void) { int fail = 0; // // Test: num_teams and omp_get_team_num() // for (int i = 0; i < N; i++) { A[i] = 0; B[i] = 0; C[i] = 1; D[i] = i; E[i] = (-1)*i; } int num_teams = omp_is_initial_device() ? HOST_MAX_TEAMS : 512; fprintf(stderr, "Using num_teams %d\n", num_teams); for (int t = 0 ; t < TRIALS ; t++) { #pragma omp target #pragma omp teams num_teams(num_teams) { A[omp_get_team_num()] += omp_get_team_num(); B[omp_get_team_num()] += omp_get_num_teams(); } } for (int i = 0 ; i < num_teams ; i++) if (A[i] != i*TRIALS) { printf("Error at %d, h = %d, d = %d\n", i, i*TRIALS, A[i]); fail = 1; } fprintf(stderr, "Target num_teams[0]=%d\n",B[0]); fprintf(stderr, "Target num_teams[900]=%d\n",B[900]); if(fail) printf("Failed\n"); else printf("Succeeded\n"); return fail; }
SpatialConvolutionMap.c
#ifndef TH_GENERIC_FILE #define TH_GENERIC_FILE "generic/SpatialConvolutionMap.c" #else static int nn_(SpatialConvolutionMap_updateOutput)(lua_State *L) { THTensor *input = luaT_checkudata(L, 2, torch_Tensor); int kW = luaT_getfieldcheckint(L, 1, "kW"); int kH = luaT_getfieldcheckint(L, 1, "kH"); int dW = luaT_getfieldcheckint(L, 1, "dW"); int dH = luaT_getfieldcheckint(L, 1, "dH"); int nInputPlane = luaT_getfieldcheckint(L, 1, "nInputPlane"); int nOutputPlane = luaT_getfieldcheckint(L, 1, "nOutputPlane"); THTensor *connTable = luaT_getfieldcheckudata(L, 1, "connTable", torch_Tensor); THTensor *weight = luaT_getfieldcheckudata(L, 1, "weight", torch_Tensor); THTensor *bias = luaT_getfieldcheckudata(L, 1, "bias", torch_Tensor); THTensor *output = luaT_getfieldcheckudata(L, 1, "output", torch_Tensor); real *input_data; real *output_data; real *weight_data = THTensor_(data)(weight); real *bias_data = THTensor_(data)(bias); real *connTable_data = THTensor_(data)(connTable); long p; int dimw = 2; int dimh = 1; int dimc = 0; long nbatch = 1; luaL_argcheck(L, input->nDimension == 3 || input->nDimension == 4, 2, "3D or 4D(batch mode) tensor expected"); if (input->nDimension == 4) { nbatch = input->size[0]; dimc++; dimw++; dimh++; } luaL_argcheck(L, input->size[dimc] >= nInputPlane, 2, "invalid number of input planes"); luaL_argcheck(L, input->size[dimw] >= kW && input->size[dimh] >= kH, 2, "input image smaller than kernel size"); long input_w = input->size[dimw]; long input_h = input->size[dimh]; long output_w = (input_w - kW) / dW + 1; long output_h = (input_h - kH) / dH + 1; if (input->nDimension == 3) THTensor_(resize3d)(output, nOutputPlane, output_h, output_w); else THTensor_(resize4d)(output, input->size[0], nOutputPlane, output_h, output_w); /* contiguous */ input = THTensor_(newContiguous)(input); output = THTensor_(newContiguous)(output); /* get raw pointers */ input_data = THTensor_(data)(input); output_data = THTensor_(data)(output); #pragma omp parallel for private(p) for (p = 0; p < nOutputPlane; p++) { long m; for(m = 0; m < nbatch; m++){ /* add bias */ real *ptr_output = output_data + p*output_w*output_h + m*nOutputPlane*output_w*output_h; long j,k; real z= bias_data[p]; for(j = 0; j < output_h*output_w; j++) ptr_output[j] = z; /* convolve all maps */ int nweight = connTable->size[0]; for (k = 0; k < nweight; k++) { /* get offsets for input/output */ int o = (int)connTable_data[k*2+1]-1; int i = (int)connTable_data[k*2+0]-1; if (o == p){ THTensor_(validXCorr2Dptr)(output_data + o*output_w*output_h + m*nOutputPlane*output_w*output_h, 1.0, input_data + i*input_w*input_h + m*nInputPlane*input_w*input_h, input_h, input_w, weight_data + k*kW*kH, kH, kW, dH, dW); } } } } /* clean up */ THTensor_(free)(input); THTensor_(free)(output); return 1; } static int nn_(SpatialConvolutionMap_updateGradInput)(lua_State *L) { THTensor *input = luaT_checkudata(L, 2, torch_Tensor); THTensor *gradOutput = luaT_checkudata(L, 3, torch_Tensor); int dW = luaT_getfieldcheckint(L, 1, "dW"); int dH = luaT_getfieldcheckint(L, 1, "dH"); int nInputPlane = luaT_getfieldcheckint(L, 1, "nInputPlane"); int nOutputPlane = luaT_getfieldcheckint(L, 1, "nOutputPlane"); THTensor *connTable = luaT_getfieldcheckudata(L, 1, "connTable", torch_Tensor); THTensor *weight = luaT_getfieldcheckudata(L, 1, "weight", torch_Tensor); THTensor *gradInput = luaT_getfieldcheckudata(L, 1, "gradInput", torch_Tensor); real *gradInput_data; real *gradOutput_data; real *weight_data = THTensor_(data)(weight); real *connTable_data = THTensor_(data)(connTable); /* and dims */ int dimw = 2; int dimh = 1; long nbatch = 1; if (input->nDimension == 4) { nbatch = input->size[0]; dimw++; dimh++; } long input_w = input->size[dimw]; long input_h = input->size[dimh]; long weight_h = weight->size[1]; long weight_w = weight->size[2]; long output_h = gradOutput->size[dimh]; long output_w = gradOutput->size[dimw]; long p; /* contiguous */ gradInput = THTensor_(newContiguous)(gradInput); gradOutput = THTensor_(newContiguous)(gradOutput); /* Resize/Zero */ THTensor_(resizeAs)(gradInput, input); THTensor_(zero)(gradInput); /* get raw pointers */ gradInput_data = THTensor_(data)(gradInput); gradOutput_data = THTensor_(data)(gradOutput); #pragma omp parallel for private(p) for(p = 0; p < nInputPlane; p++){ long m; for(m = 0; m < nbatch; m++){ long k; /* backward all */ int nkernel = connTable->size[0]; for(k = 0; k < nkernel; k++) { int o = (int)connTable_data[k*2+1]-1; int i = (int)connTable_data[k*2+0]-1; if (i == p){ /* gradient to input */ THTensor_(fullConv2Dptr)(gradInput_data + i*input_w*input_h + m*nInputPlane*input_w*input_h, 1.0, gradOutput_data + o*output_w*output_h + m*nOutputPlane*output_w*output_h, output_h, output_w, weight_data + k*weight_w*weight_h, weight_h, weight_w, dH, dW); } } } } /* clean up */ THTensor_(free)(gradInput); THTensor_(free)(gradOutput); return 1; } static int nn_(SpatialConvolutionMap_accGradParameters)(lua_State *L) { THTensor *input = luaT_checkudata(L, 2, torch_Tensor); THTensor *gradOutput = luaT_checkudata(L, 3, torch_Tensor); int dW = luaT_getfieldcheckint(L, 1, "dW"); int dH = luaT_getfieldcheckint(L, 1, "dH"); int nOutputPlane = luaT_getfieldcheckint(L, 1, "nOutputPlane"); int nInputPlane = luaT_getfieldcheckint(L, 1, "nInputPlane"); real scale = luaL_optnumber(L, 4, 1); THTensor *connTable = luaT_getfieldcheckudata(L, 1, "connTable", torch_Tensor); THTensor *weight = luaT_getfieldcheckudata(L, 1, "weight", torch_Tensor); THTensor *gradWeight = luaT_getfieldcheckudata(L, 1, "gradWeight", torch_Tensor); THTensor *gradBias = luaT_getfieldcheckudata(L, 1, "gradBias", torch_Tensor); real *input_data; real *gradOutput_data; real *gradWeight_data = THTensor_(data)(gradWeight); real *gradBias_data = THTensor_(data)(gradBias); /* and dims */ int dimw = 2; int dimh = 1; long nbatch = 1; if (input->nDimension == 4) { nbatch = input->size[0]; dimw++; dimh++; } long input_w = input->size[dimw]; long input_h = input->size[dimh]; long output_h = gradOutput->size[dimh]; long output_w = gradOutput->size[dimw]; long weight_h = weight->size[1]; long weight_w = weight->size[2]; int nkernel; /* contiguous */ input = THTensor_(newContiguous)(input); gradOutput = THTensor_(newContiguous)(gradOutput); /* get raw pointers */ input_data = THTensor_(data)(input); gradOutput_data = THTensor_(data)(gradOutput); long k; /* gradients wrt bias */ #pragma omp parallel for private(k) for(k = 0; k < nOutputPlane; k++) { long m; for(m = 0; m < nbatch; m++){ real *ptr_gradOutput = gradOutput_data + k*output_w*output_h + m*nOutputPlane*output_w*output_h; long l; for(l = 0; l < output_h*output_w; l++) gradBias_data[k] += scale*ptr_gradOutput[l]; } } /* gradients wrt weight */ nkernel = connTable->size[0]; #pragma omp parallel for private(k) for(k = 0; k < nkernel; k++){ long m; for(m = 0; m < nbatch; m++){ int o = (int)THTensor_(get2d)(connTable,k,1)-1; int i = (int)THTensor_(get2d)(connTable,k,0)-1; /* gradient to kernel */ THTensor_(validXCorr2DRevptr)(gradWeight_data + k*weight_w*weight_h, scale, input_data + i*input_w*input_h + m*nInputPlane*input_w*input_h, input_h, input_w, gradOutput_data + o*output_w*output_h + m*nOutputPlane*output_w*output_h , output_h, output_w, dH, dW); } } /* clean up */ THTensor_(free)(input); THTensor_(free)(gradOutput); return 0; } static const struct luaL_Reg nn_(SpatialConvolutionMap__) [] = { {"SpatialConvolutionMap_updateOutput", nn_(SpatialConvolutionMap_updateOutput)}, {"SpatialConvolutionMap_updateGradInput", nn_(SpatialConvolutionMap_updateGradInput)}, {"SpatialConvolutionMap_accGradParameters", nn_(SpatialConvolutionMap_accGradParameters)}, {NULL, NULL} }; static void nn_(SpatialConvolutionMap_init)(lua_State *L) { luaT_pushmetatable(L, torch_Tensor); luaT_registeratname(L, nn_(SpatialConvolutionMap__), "nn"); lua_pop(L,1); } #endif
omp_hello.c
/****************************************************************************** * FILE: omp_hello.c * DESCRIPTION: * OpenMP Example - Hello World - C/C++ Version * In this simple example, the master thread forks a parallel region. * All threads in the team obtain their unique thread number and print it. * The master thread only prints the total number of threads. Two OpenMP * library routines are used to obtain the number of threads and each * thread's number. * 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 nthreads, tid; /* Fork a team of threads giving them their own copies of variables */ #pragma omp parallel private(nthreads, tid) { /* Obtain thread number */ tid = omp_get_thread_num(); printf("Hello World from thread = %d\n", tid); /* Only master thread does this */ if (tid == 0) { nthreads = omp_get_num_threads(); printf("Number of threads = %d\n", nthreads); } } /* All threads join master thread and disband */ }
omp_smithW-v3-master-ompfor.c
/********************************************************************************* * Smith–Waterman algorithm * Purpose: Local alignment of nucleotide or protein sequences * Authors: Daniel Holanda, Hanoch Griner, Taynara Pinheiro * * Compilation: gcc omp_smithW.c -o omp_smithW -fopenmp -DDEBUG // debugging mode * gcc omp_smithW.c -O3 -o omp_smithW -fopenmp // production run * Execution: ./omp_smithW <number_of_col> <number_of_rows> * * Updated by C. Liao, Jan 2nd, 2019 *********************************************************************************/ #include <stdio.h> #include <stdlib.h> #include <math.h> #include <omp.h> #include <time.h> #include <assert.h> #include <stdbool.h> // C99 does not support the boolean data type #include "parameters.h" /*-------------------------------------------------------------------- * Text Tweaks */ #define RESET "\033[0m" #define BOLDRED "\033[1m\033[31m" /* Bold Red */ /* End of text tweaks */ /*-------------------------------------------------------------------- * Constants */ #define PATH -1 #define NONE 0 #define UP 1 #define LEFT 2 #define DIAGONAL 3 /* End of constants */ /*-------------------------------------------------------------------- * Helpers */ #define min(x, y) (((x) < (y)) ? (x) : (y)) #define max(a,b) ((a) > (b) ? a : b) // #define DEBUG /* End of Helpers */ /*-------------------------------------------------------------------- * Functions Prototypes */ void similarityScore(long long int i, long long int j, int* H, int* P, long long int* maxPos); int matchMissmatchScore(long long int i, long long int j); void backtrack(int* P, long long int maxPos); void printMatrix(int* matrix); void printPredecessorMatrix(int* matrix); void generate(void); long long int nElement(long long int i); void calcFirstDiagElement(long long int i, long long int *si, long long int *sj); /* End of prototypes */ /*-------------------------------------------------------------------- * Global Variables */ bool useBuiltInData=true; //Defines size of strings to be compared long long int m = 8 ; //Columns - Size of string a long long int n = 9; //Lines - Size of string b // the generated scoring matrix's size is m++ and n++ later to have the first row/column as 0s. //Defines scores int matchScore = 3; int missmatchScore = -3; int gapScore = -2; //Strings over the Alphabet Sigma char *a, *b; /* End of global variables */ /*-------------------------------------------------------------------- * Function: main */ int main(int argc, char* argv[]) { // thread_count is no longer used int thread_count; if (argc==3) { m = strtoll(argv[1], NULL, 10); n = strtoll(argv[2], NULL, 10); useBuiltInData = false; } //#ifdef DEBUG if (useBuiltInData) printf ("Using built-in data for testing ..\n"); printf("Problem size: Matrix[%lld][%lld], FACTOR=%d CUTOFF=%d\n", n, m, FACTOR, CUTOFF); //#endif //Allocates a and b a = (char*) malloc(m * sizeof(char)); b = (char*) malloc(n * sizeof(char)); //Because now we have zeros m++; n++; //Allocates similarity matrix H int *H; H = (int *) calloc(m * n, sizeof(int)); //Allocates predecessor matrix P int *P; P = (int *)calloc(m * n, sizeof(int)); if (useBuiltInData) { //Uncomment this to test the sequence available at //http://vlab.amrita.edu/?sub=3&brch=274&sim=1433&cnt=1 // OBS: m=11 n=7 // a[0] = 'C'; // a[1] = 'G'; // a[2] = 'T'; // a[3] = 'G'; // a[4] = 'A'; // a[5] = 'A'; // a[6] = 'T'; // a[7] = 'T'; // a[8] = 'C'; // a[9] = 'A'; // a[10] = 'T'; // b[0] = 'G'; // b[1] = 'A'; // b[2] = 'C'; // b[3] = 'T'; // b[4] = 'T'; // b[5] = 'A'; // b[6] = 'C'; // https://en.wikipedia.org/wiki/Smith%E2%80%93Waterman_algorithm#Example // Using the wiki example to verify the results b[0] = 'G'; b[1] = 'G'; b[2] = 'T'; b[3] = 'T'; b[4] = 'G'; b[5] = 'A'; b[6] = 'C'; b[7] = 'T'; b[8] = 'A'; a[0] = 'T'; a[1] = 'G'; a[2] = 'T'; a[3] = 'T'; a[4] = 'A'; a[5] = 'C'; a[6] = 'G'; a[7] = 'G'; } else { //Gen random arrays a and b generate(); } //Start position for backtrack long long int maxPos = 0; //Calculates the similarity matrix long long int i, j; // The way to generate all wavefront is to go through the top edge elements // starting from the left top of the matrix, go to the bottom top -> down, then left->right // total top edge element count = dim1_size + dim2_size -1 //Because now we have zeros ((m-1) + (n-1) - 1) long long int nDiag = m + n - 3; #ifdef DEBUG printf("nDiag=%d\n", nDiag); printf("Number of wavefront lines and their first element positions:\n"); #endif #pragma omp parallel { #pragma omp master { thread_count = omp_get_num_threads(); printf ("Parallel outer + ompfor-master inner, Using %d out of max %d threads...", thread_count, omp_get_max_threads()); } } //Gets Initial time double initialTime = omp_get_wtime(); #pragma omp parallel default(none) shared(H, P, maxPos, nDiag, j) private(i) { for (i = 1; i <= nDiag; ++i) // start from 1 since 0 is the boundary padding { long long int nEle, si, sj; nEle = nElement(i); calcFirstDiagElement(i, &si, &sj); // #pragma omp parallel for private(j) shared (nEle, si, sj, H, P, maxPos) if (nEle>=CUTOFF) if (nEle>=CUTOFF) { #pragma omp for private(j) for (j = 0; j < nEle; ++j) { // going upwards : anti-diagnol direction long long int ai = si - j ; // going up vertically long long int aj = sj + j; // going right in horizontal similarityScore(ai, aj, H, P, &maxPos); // a critical section is used inside } } else // single thread version using master thread only { #pragma omp master for (j = 0; j < nEle; ++j) { // going upwards : anti-diagnol direction long long int ai = si - j ; // going up vertically long long int aj = sj + j; // going right in horizontal similarityScore(ai, aj, H, P, &maxPos); // a critical section is used inside } } } } double finalTime = omp_get_wtime(); printf("\nElapsed time for scoring matrix computation: %f\n", finalTime - initialTime); initialTime = omp_get_wtime(); backtrack(P, maxPos); finalTime = omp_get_wtime(); //Gets backtrack time finalTime = omp_get_wtime(); printf("Elapsed time for backtracking: %f\n", finalTime - initialTime); if (useBuiltInData) { printf ("Verifying results using the builtinIn data: %s\n", (H[n*m-1]==7)?"true":"false"); assert (H[n*m-1]==7); } #ifdef DEBUG printf("\nSimilarity Matrix:\n"); printMatrix(H); printf("\nPredecessor Matrix:\n"); printPredecessorMatrix(P); #endif //Frees similarity matrixes free(H); free(P); //Frees input arrays free(a); free(b); return 0; } /* End of main */ /*-------------------------------------------------------------------- * Function: nElement * Purpose: Calculate the number of i-diagonal's elements * i value range 1 to nDiag. we inclulde the upper bound value. 0 is for the padded wavefront, which is ignored. */ long long int nElement(long long int i) { if (i < m && i < n) { // smaller than both directions //Number of elements in the diagonal is increasing return i; } else if (i < max(m, n)) { // smaller than only one direction //Number of elements in the diagonal is stable long int min = min(m, n); // the longer direction has the edge elements, the number is the smaller direction's size return min - 1; } else { //Number of elements in the diagonal is decreasing long int min = min(m, n); return 2 * min - i + llabs(m - n) - 2; } } /*-------------------------------------------------------------------- * Function: calcElement: expect valid i value is from 1 to nDiag. since the first one is 0 padding * Purpose: Calculate the position of (si, sj)-element * n rows, m columns: we sweep the matrix on the left edge then bottom edge to get the wavefront */ void calcFirstDiagElement(long long int i, long long int *si, long long int *sj) { // Calculate the first element of diagonal if (i < n) { // smaller than row count *si = i; *sj = 1; // start from the j==1 since j==0 is the padding } else { // now we sweep horizontally at the bottom of the matrix *si = n - 1; // i is fixed *sj = i - n + 2; // j position is the nDiag (id -n) +1 +1 // first +1 } } /* // understanding the calculation by an example n =6 // row m =2 // col padded scoring matrix n=7 m=3 0 1 2 ------- 0 x x x 1 x x x 2 x x x 3 x x x 4 x x x 5 x x x 6 x x x We should peel off top row and left column since they are the padding the remaining 6x2 sub matrix is what is interesting for us Now find the number of wavefront lines and their first element's position in the scoring matrix total diagnol frontwave = (n-1) + (m-1) -1 // submatrix row+column -1 We use the left most element in each wavefront line as its first element. Then we have the first elements like (1,1), (2,1) (3,1) .. (6,1) (6,2) */ /*-------------------------------------------------------------------- * Function: SimilarityScore * Purpose: Calculate value of scoring matrix element H(i,j) : the maximum Similarity-Score H(i,j) * int *P; the predecessor array,storing which of the three elements is picked with max value */ void similarityScore(long long int i, long long int j, int* H, int* P, long long int* maxPos) { int up, left, diag; //Stores index of element long long int index = m * i + j; //Get element above up = H[index - m] + gapScore; //Get element on the left left = H[index - 1] + gapScore; //Get element on the diagonal diag = H[index - m - 1] + matchMissmatchScore(i, j); //Calculates the maximum int max = NONE; int pred = NONE; /* === Matrix === * a[0] ... a[n] * b[0] * ... * b[n] * * generate 'a' from 'b', if '←' insert e '↑' remove * a=GAATTCA * b=GACTT-A * * generate 'b' from 'a', if '←' insert e '↑' remove * b=GACTT-A * a=GAATTCA */ if (diag > max) { //same letter ↖ max = diag; pred = DIAGONAL; } if (up > max) { //remove letter ↑ max = up; pred = UP; } if (left > max) { //insert letter ← max = left; pred = LEFT; } //Inserts the value in the similarity and predecessor matrixes H[index] = max; P[index] = pred; //Updates maximum score to be used as seed on backtrack #pragma omp critical if (max > H[*maxPos]) { *maxPos = index; } } /* End of similarityScore */ /*-------------------------------------------------------------------- * Function: matchMissmatchScore * Purpose: Similarity function on the alphabet for match/missmatch */ int matchMissmatchScore(long long int i, long long int j) { if (a[j - 1] == b[i - 1]) return matchScore; else return missmatchScore; } /* End of matchMissmatchScore */ /*-------------------------------------------------------------------- * Function: backtrack * Purpose: Modify matrix to print, path change from value to PATH */ void backtrack(int* P, long long int maxPos) { //hold maxPos value long long int predPos; //backtrack from maxPos to startPos = 0 do { if (P[maxPos] == DIAGONAL) predPos = maxPos - m - 1; else if (P[maxPos] == UP) predPos = maxPos - m; else if (P[maxPos] == LEFT) predPos = maxPos - 1; P[maxPos] *= PATH; maxPos = predPos; } while (P[maxPos] != NONE); } /* End of backtrack */ /*-------------------------------------------------------------------- * Function: printMatrix * Purpose: Print Matrix */ void printMatrix(int* matrix) { long long int i, j; printf("-\t-\t"); for (j = 0; j < m-1; j++) { printf("%c\t", a[j]); } printf("\n-\t"); for (i = 0; i < n; i++) { //Lines for (j = 0; j < m; j++) { if (j==0 && i>0) printf("%c\t", b[i-1]); printf("%d\t", matrix[m * i + j]); } printf("\n"); } } /* End of printMatrix */ /*-------------------------------------------------------------------- * Function: printPredecessorMatrix * Purpose: Print predecessor matrix */ void printPredecessorMatrix(int* matrix) { long long int i, j, index; printf(" "); for (j = 0; j < m-1; j++) { printf("%c ", a[j]); } printf("\n "); for (i = 0; i < n; i++) { //Lines for (j = 0; j < m; j++) { if (j==0 && i>0) printf("%c ", b[i-1]); index = m * i + j; if (matrix[index] < 0) { printf(BOLDRED); if (matrix[index] == -UP) printf("↑ "); else if (matrix[index] == -LEFT) printf("← "); else if (matrix[index] == -DIAGONAL) printf("↖ "); else printf("- "); printf(RESET); } else { if (matrix[index] == UP) printf("↑ "); else if (matrix[index] == LEFT) printf("← "); else if (matrix[index] == DIAGONAL) printf("↖ "); else printf("- "); } } printf("\n"); } } /* End of printPredecessorMatrix */ /*-------------------------------------------------------------------- * Function: generate * Purpose: Generate arrays a and b */ void generate() { //Random seed srand(time(NULL)); //Generates the values of a long long int i; for (i = 0; i < m; i++) { int aux = rand() % 4; if (aux == 0) a[i] = 'A'; else if (aux == 2) a[i] = 'C'; else if (aux == 3) a[i] = 'G'; else a[i] = 'T'; } //Generates the values of b for (i = 0; i < n; i++) { int aux = rand() % 4; if (aux == 0) b[i] = 'A'; else if (aux == 2) b[i] = 'C'; else if (aux == 3) b[i] = 'G'; else b[i] = 'T'; } } /* End of generate */ /*-------------------------------------------------------------------- * External References: * http://vlab.amrita.edu/?sub=3&brch=274&sim=1433&cnt=1 * http://pt.slideshare.net/avrilcoghlan/the-smith-waterman-algorithm * http://baba.sourceforge.net/ */
imginputfileconn.h
/** * DeepDetect * Copyright (c) 2014 Emmanuel Benazera * Author: Emmanuel Benazera <beniz@droidnik.fr> * * This file is part of deepdetect. * * deepdetect 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 3 of the License, or * (at your option) any later version. * * deepdetect 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 deepdetect. If not, see <http://www.gnu.org/licenses/>. */ #ifndef IMGINPUTFILECONN_H #define IMGINPUTFILECONN_H #include "inputconnectorstrategy.h" #include <opencv2/core/core.hpp> #include <opencv2/imgproc/imgproc.hpp> #include <opencv2/highgui/highgui.hpp> #include "ext/base64/base64.h" #include "utils/apitools.h" #include <random> namespace dd { class DDImg { public: DDImg() {} ~DDImg() {} // base64 detection bool is_within_base64_range(char c) const { if ((c >= 'A' && c <= 'Z') || (c >= 'a' && c <= 'z') || (c >= '0' && c <= '9') || (c == '+' || c=='/' || c=='=')) return true; else return false; } bool possibly_base64(const std::string &s) const { bool ism = is_multiple_four(s); if (!ism) return false; for (char c: s) { bool within_64 = is_within_base64_range(c); if (!within_64) return false; } return true; } bool is_multiple_four(const std::string &s) const { if (s.length() % 4 == 0) return true; else return false; } void scale(const cv::Mat &src, cv::Mat &dst) const { float coef = std::min(static_cast<float>(_scale_max) / std::max(src.rows, src.cols), static_cast<float>(_scale_min) / std::min(src.rows, src.cols)); cv::resize(src, dst, cv::Size(), coef, coef, CV_INTER_CUBIC); } // decode image void decode(const std::string &str) { std::vector<unsigned char> vdat(str.begin(),str.end()); cv::Mat img = cv::Mat(cv::imdecode(cv::Mat(vdat,true), _unchanged_data ? CV_LOAD_IMAGE_UNCHANGED : (_bw ? CV_LOAD_IMAGE_GRAYSCALE : CV_LOAD_IMAGE_COLOR))); _imgs_size.push_back(std::pair<int,int>(img.rows,img.cols)); cv::Mat rimg; if (_scaled) scale(img, rimg); else if (_width == 0 || _height == 0) { if (_width == 0 && _height == 0) { // XXX - Do nothing and keep native resolution. May cause issues if batched images are different resolutions rimg = img; } else { // Resize so that the larger dimension is set to whichever (width or height) is non-zero, maintaining aspect ratio // XXX - This may cause issues if batch images are different resolutions size_t currMaxDim = std::max(img.rows, img.cols); double scale = static_cast<double>(std::max(_width, _height)) / static_cast<double>(currMaxDim); cv::resize(img,rimg,cv::Size(),scale,scale,CV_INTER_CUBIC); } } else { // Resize normally to the specified width and height cv::resize(img,rimg,cv::Size(_width,_height),0,0,CV_INTER_CUBIC); } if (_crop_width != 0 && _crop_height != 0) { int widthBorder = (_width - _crop_width)/2; int heightBorder = (_height - _crop_height)/2; rimg = rimg(cv::Rect(widthBorder, heightBorder, _crop_width, _crop_height)); } _imgs.push_back(rimg); } // deserialize image, independent of format void deserialize(std::stringstream &input) { size_t size = 0; input.seekg(0,input.end); size = input.tellg(); input.seekg(0,input.beg); char* data = new char[size]; input.read(data, size); std::string str(data,data+size); delete[]data; decode(str); } // data acquisition int read_file(const std::string &fname) { cv::Mat img = cv::imread(fname, _unchanged_data ? CV_LOAD_IMAGE_UNCHANGED : (_bw ? CV_LOAD_IMAGE_GRAYSCALE : CV_LOAD_IMAGE_COLOR)); if (img.empty()) { _logger->error("empty image {}",fname); return -1; } _imgs_size.push_back(std::pair<int,int>(img.rows,img.cols)); cv::Mat rimg; try { if (_scaled) scale(img, rimg); else if (_width == 0 || _height == 0) { if (_width == 0 && _height == 0) { // Do nothing and keep native resolution. May cause issues if batched images are different resolutions rimg = img; } else { // Resize so that the larger dimension is set to whichever (width or height) is non-zero, maintaining aspect ratio // XXX - This may cause issues if batch images are different resolutions size_t currMaxDim = std::max(img.rows, img.cols); double scale = static_cast<double>(std::max(_width, _height)) / static_cast<double>(currMaxDim); cv::resize(img,rimg,cv::Size(),scale,scale,CV_INTER_CUBIC); } } else { // Resize normally to the specified width and height cv::resize(img,rimg,cv::Size(_width,_height),0,0,CV_INTER_CUBIC); } } catch(...) { throw InputConnectorBadParamException("failed resizing image " + fname); } if (_crop_width != 0 && _crop_height != 0) { int widthBorder = (_width - _crop_width)/2; int heightBorder = (_height - _crop_height)/2; try { rimg = rimg(cv::Rect(widthBorder, heightBorder, _crop_width, _crop_height)); } catch(...) { throw InputConnectorBadParamException("failed cropping image " + fname); } } _imgs.push_back(rimg); return 0; } int read_db(const std::string &fname) { _db_fname = fname; return 0; } int read_mem(const std::string &content) { cv::Mat timg; _b64 = possibly_base64(content); if (_b64) { std::string ccontent; Base64::Decode(content,&ccontent); std::stringstream sstr; sstr << ccontent; deserialize(sstr); } else { decode(content); } if (_imgs.at(0).empty()) return -1; return 0; } int read_dir(const std::string &dir) { // list directories in dir std::unordered_set<std::string> subdirs; if (fileops::list_directory(dir,false,true,false,subdirs)) throw InputConnectorBadParamException("failed reading text subdirectories in data directory " + dir); _logger->info("imginputfileconn: list subdirs size={}",subdirs.size()); // list files and classes std::vector<std::pair<std::string,int>> lfiles; // labeled files std::unordered_map<int,std::string> hcorresp; // correspondence class number / class name if (!subdirs.empty()) { int cl = 0; auto uit = subdirs.begin(); while(uit!=subdirs.end()) { std::unordered_set<std::string> subdir_files; if (fileops::list_directory((*uit),true,false,true,subdir_files)) throw InputConnectorBadParamException("failed reading image data sub-directory " + (*uit)); auto fit = subdir_files.begin(); while(fit!=subdir_files.end()) // XXX: re-iterating the file is not optimal { lfiles.push_back(std::pair<std::string,int>((*fit),cl)); ++fit; } ++cl; ++uit; } } else { std::unordered_set<std::string> test_files; fileops::list_directory(dir,true,false,false,test_files); auto fit = test_files.begin(); while(fit!=test_files.end()) { lfiles.push_back(std::pair<std::string,int>((*fit),-1)); // -1 for no class ++fit; } } // read images _imgs.reserve(lfiles.size()); _img_files.reserve(lfiles.size()); _labels.reserve(lfiles.size()); for (std::pair<std::string,int> &p: lfiles) { cv::Mat img = cv::imread(p.first, _unchanged_data ? CV_LOAD_IMAGE_UNCHANGED : (_bw ? CV_LOAD_IMAGE_GRAYSCALE : CV_LOAD_IMAGE_COLOR)); _imgs_size.push_back(std::pair<int,int>(img.rows,img.cols)); cv::Mat rimg; try { if (_scaled) scale(img, rimg); else if (_width == 0 || _height == 0) { if (_width == 0 && _height == 0) { // Do nothing and keep native resolution. May cause issues if batched images are different resolutions rimg = img; } else { // Resize so that the larger dimension is set to whichever (width or height) is non-zero, maintaining aspect ratio // XXX - This may cause issues if batch images are different resolutions size_t currMaxDim = std::max(img.rows, img.cols); double scale = static_cast<double>(std::max(_width, _height)) / static_cast<double>(currMaxDim); cv::resize(img,rimg,cv::Size(),scale,scale,CV_INTER_CUBIC); } } else { // Resize normally to the specified width and height cv::resize(img,rimg,cv::Size(_width,_height),0,0,CV_INTER_CUBIC); } } catch(...) { throw InputConnectorBadParamException("failed resizing image " + p.first); } if (_crop_width != 0 && _crop_height != 0) { int widthBorder = (_width - _crop_width)/2; int heightBorder = (_height - _crop_height)/2; try { rimg = rimg(cv::Rect(widthBorder, heightBorder, _crop_width, _crop_height)); } catch(...) { throw InputConnectorBadParamException("failed cropping image " + p.first); } } _imgs.push_back(rimg); _img_files.push_back(p.first); if (p.second >= 0) _labels.push_back(p.second); if (_imgs.size() % 1000 == 0) _logger->info("read {} images",_imgs.size()); } return 0; } std::vector<cv::Mat> _imgs; std::vector<std::string> _img_files; std::vector<std::pair<int,int>> _imgs_size; bool _bw = false; bool _b64 = false; bool _unchanged_data = false; std::vector<int> _labels; int _width = 224; int _height = 224; int _crop_width = 0; int _crop_height = 0; bool _scaled = false; int _scale_min = 600; int _scale_max = 1000; std::string _db_fname; std::shared_ptr<spdlog::logger> _logger; }; class ImgInputFileConn : public InputConnectorStrategy { public: ImgInputFileConn() :InputConnectorStrategy(){} ImgInputFileConn(const ImgInputFileConn &i) :InputConnectorStrategy(i), _width(i._width),_height(i._height), _crop_width(i._crop_width),_crop_height(i._crop_height), _bw(i._bw),_unchanged_data(i._unchanged_data), _mean(i._mean),_has_mean_scalar(i._has_mean_scalar), _scaled(i._scaled), _scale_min(i._scale_min), _scale_max(i._scale_max) {} ~ImgInputFileConn() {} void init(const APIData &ad) { fillup_parameters(ad); } void fillup_parameters(const APIData &ad) { // optional parameters. if (ad.has("width")) _width = ad.get("width").get<int>(); if (ad.has("height")) _height = ad.get("height").get<int>(); if (ad.has("crop_width")) { _crop_width = ad.get("crop_width").get<int>(); if (_crop_width > _width) { _logger->error("Crop width must be less than or equal to width"); throw InputConnectorBadParamException("Crop width must be less than or equal to width"); } } if (ad.has("crop_height")) { _crop_height = ad.get("crop_height").get<int>(); if (_crop_height > _height) { _logger->error("Crop height must be less than or equal to height"); throw InputConnectorBadParamException("Crop height must be less than or equal to height"); } } if (ad.has("bw")) _bw = ad.get("bw").get<bool>(); if (ad.has("unchanged_data")) _unchanged_data = ad.get("unchanged_data").get<bool>(); if (ad.has("shuffle")) _shuffle = ad.get("shuffle").get<bool>(); if (ad.has("seed")) _seed = ad.get("seed").get<int>(); if (ad.has("test_split")) _test_split = ad.get("test_split").get<double>(); if (ad.has("mean")) { apitools::get_floats(ad, "mean", _mean); _has_mean_scalar = true; } // Variable size if (ad.has("scaled") || ad.has("scale_min") || ad.has("scale_max")) _scaled = true; if (ad.has("scale_min")) _scale_min = ad.get("scale_min").get<int>(); if (ad.has("scale_max")) _scale_max = ad.get("scale_max").get<int>(); } int feature_size() const { if (_bw || _unchanged_data) { // XXX: only valid for single channels if (_crop_width != 0 && _crop_height != 0) return _crop_width*_crop_height; else return _width*_height; } else { // RGB if (_crop_width != 0 && _crop_height != 0) return _crop_width*_crop_height*3; else return _width*_height*3; } } int batch_size() const { return _images.size(); } int test_batch_size() const { return _test_images.size(); } void transform(const APIData &ad) { get_data(ad); if (ad.has("parameters")) // hotplug of parameters, overriding the defaults { APIData ad_param = ad.getobj("parameters"); if (ad_param.has("input")) { fillup_parameters(ad_param.getobj("input")); } } int catch_read = 0; std::string catch_msg; std::vector<std::string> uris; std::vector<std::string> failed_uris; #pragma omp parallel for for (size_t i=0;i<_uris.size();i++) { bool no_img = false; std::string u = _uris.at(i); DataEl<DDImg> dimg; dimg._ctype._bw = _bw; dimg._ctype._unchanged_data = _unchanged_data; dimg._ctype._width = _width; dimg._ctype._height = _height; dimg._ctype._crop_width = _crop_width; dimg._ctype._crop_height = _crop_height; dimg._ctype._scaled = _scaled; dimg._ctype._scale_min = _scale_min; dimg._ctype._scale_max = _scale_max; try { if (dimg.read_element(u,this->_logger)) { _logger->error("no data for image {}",u); no_img = true; } if (!dimg._ctype._db_fname.empty()) _db_fname = dimg._ctype._db_fname; } catch(std::exception &e) { #pragma omp critical { ++catch_read; catch_msg = e.what(); failed_uris.push_back(u); no_img = true; } } if (no_img) continue; if (!_db_fname.empty()) continue; #pragma omp critical { _images.insert(_images.end(), std::make_move_iterator(dimg._ctype._imgs.begin()), std::make_move_iterator(dimg._ctype._imgs.end())); _images_size.insert(_images_size.end(), std::make_move_iterator(dimg._ctype._imgs_size.begin()), std::make_move_iterator(dimg._ctype._imgs_size.end())); if (!dimg._ctype._labels.empty()) _test_labels.insert(_test_labels.end(), std::make_move_iterator(dimg._ctype._labels.begin()), std::make_move_iterator(dimg._ctype._labels.end())); if (!dimg._ctype._b64 && dimg._ctype._imgs.size() == 1) uris.push_back(u); else if (!dimg._ctype._img_files.empty()) uris.insert(uris.end(), std::make_move_iterator(dimg._ctype._img_files.begin()), std::make_move_iterator(dimg._ctype._img_files.end())); else uris.push_back(std::to_string(i)); } } if (catch_read) { for (auto s: failed_uris) _logger->error("failed reading image {}",s); throw InputConnectorBadParamException(catch_msg); } _uris = uris; if (!_db_fname.empty()) return; // db filename is passed to backend // shuffle before possible split if (_shuffle) { std::mt19937 g; if (_seed >= 0) g = std::mt19937(_seed); else { std::random_device rd; g = std::mt19937(rd()); } std::shuffle(_images.begin(),_images.end(),g); //XXX beware: labels are not shuffled, i.e. let's not shuffle while testing } // split as required if (_test_split > 0) { int split_size = std::floor(_images.size() * (1.0-_test_split)); auto chit = _images.begin(); auto dchit = chit; int cpos = 0; while(chit!=_images.end()) { if (cpos == split_size) { if (dchit == _images.begin()) dchit = chit; _test_images.push_back((*chit)); } else ++cpos; ++chit; } _images.erase(dchit,_images.end()); _logger->info("data split test size={} / remaining data size={}",_test_images.size(),_images.size()); } if (_images.empty()) throw InputConnectorBadParamException("no image could be found"); } // data std::vector<cv::Mat> _images; std::vector<cv::Mat> _test_images; std::vector<int> _test_labels; std::vector<std::pair<int,int>> _images_size; // image parameters int _width = 224; int _height = 224; int _crop_width = 0; int _crop_height = 0; bool _bw = false; /**< whether to convert to black & white. */ bool _unchanged_data = false; /**< IMREAD_UNCHANGED flag. */ double _test_split = 0.0; /**< auto-split of the dataset. */ int _seed = -1; /**< shuffling seed. */ std::vector<float> _mean; /**< mean image pixels, to be subtracted from images. */ bool _has_mean_scalar = false; /**< whether scalar is set. */ std::string _db_fname; bool _scaled = false; int _scale_min = 600; int _scale_max = 1000; }; } #ifdef USE_CAFFE #include "caffeinputconns.h" #endif #ifdef USE_TF #include "backends/tf/tfinputconns.h" #endif #ifdef USE_DLIB #include "backends/dlib/dlibinputconns.h" #endif #ifdef USE_CAFFE2 #include "backends/caffe2/caffe2inputconns.h" #endif #endif
graph_generator.c
/* Copyright (C) 2009-2010 The Trustees of Indiana University. */ /* */ /* Use, modification and distribution is subject to 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) */ /* */ /* Authors: Jeremiah Willcock */ /* Andrew Lumsdaine */ #include <stdlib.h> #include <stdint.h> #include <assert.h> #ifndef __STDC_FORMAT_MACROS #define __STDC_FORMAT_MACROS #endif #include <inttypes.h> #include "user_settings.h" #include "splittable_mrg.h" #include "graph_generator.h" /* Initiator settings: for faster random number generation, the initiator * probabilities are defined as fractions (a = INITIATOR_A_NUMERATOR / * INITIATOR_DENOMINATOR, b = c = INITIATOR_BC_NUMERATOR / * INITIATOR_DENOMINATOR, d = 1 - a - b - c. */ #define INITIATOR_A_NUMERATOR 5700 #define INITIATOR_BC_NUMERATOR 1900 #define INITIATOR_DENOMINATOR 10000 /* If this macro is defined to a non-zero value, use SPK_NOISE_LEVEL / * INITIATOR_DENOMINATOR as the noise parameter to use in introducing noise * into the graph parameters. The approach used is from "A Hitchhiker's Guide * to Choosing Parameters of Stochastic Kronecker Graphs" by C. Seshadhri, Ali * Pinar, and Tamara G. Kolda (http://arxiv.org/abs/1102.5046v1), except that * the adjustment here is chosen based on the current level being processed * rather than being chosen randomly. */ #define SPK_NOISE_LEVEL 0 /* #define SPK_NOISE_LEVEL 1000 -- in INITIATOR_DENOMINATOR units */ static int generate_4way_bernoulli(mrg_state* st, int level, int nlevels) { /* Generator a pseudorandom number in the range [0, INITIATOR_DENOMINATOR) * without modulo bias. */ static const uint32_t limit = (UINT32_C(0xFFFFFFFF) % INITIATOR_DENOMINATOR); uint32_t val = mrg_get_uint_orig(st); if (/* Unlikely */ val < limit) { do { val = mrg_get_uint_orig(st); } while (val < limit); } #if SPK_NOISE_LEVEL == 0 int spk_noise_factor = 0; #else int spk_noise_factor = 2 * SPK_NOISE_LEVEL * level / nlevels - SPK_NOISE_LEVEL; #endif int adjusted_bc_numerator = INITIATOR_BC_NUMERATOR + spk_noise_factor; val %= INITIATOR_DENOMINATOR; if (val < adjusted_bc_numerator) return 1; val -= adjusted_bc_numerator; if (val < adjusted_bc_numerator) return 2; val -= adjusted_bc_numerator; #if SPK_NOISE_LEVEL == 0 if (val < INITIATOR_A_NUMERATOR) return 0; #else if (val < INITIATOR_A_NUMERATOR * (INITIATOR_DENOMINATOR - 2 * INITIATOR_BC_NUMERATOR) / (INITIATOR_DENOMINATOR - 2 * adjusted_bc_numerator)) return 0; #endif return 3; } /* Reverse bits in a number; this should be optimized for performance * (including using bit- or byte-reverse intrinsics if your platform has them). * */ static inline uint64_t bitreverse(uint64_t x) { #if __GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 3) #define USE_GCC_BYTESWAP /* __builtin_bswap* are in 4.3 but not 4.2 */ #endif #ifdef FAST_64BIT_ARITHMETIC /* 64-bit code */ #ifdef USE_GCC_BYTESWAP x = __builtin_bswap64(x); #else x = (x >> 32) | (x << 32); x = ((x >> 16) & UINT64_C(0x0000FFFF0000FFFF)) | ((x & UINT64_C(0x0000FFFF0000FFFF)) << 16); x = ((x >> 8) & UINT64_C(0x00FF00FF00FF00FF)) | ((x & UINT64_C(0x00FF00FF00FF00FF)) << 8); #endif x = ((x >> 4) & UINT64_C(0x0F0F0F0F0F0F0F0F)) | ((x & UINT64_C(0x0F0F0F0F0F0F0F0F)) << 4); x = ((x >> 2) & UINT64_C(0x3333333333333333)) | ((x & UINT64_C(0x3333333333333333)) << 2); x = ((x >> 1) & UINT64_C(0x5555555555555555)) | ((x & UINT64_C(0x5555555555555555)) << 1); return x; #else /* 32-bit code */ uint32_t h = (uint32_t)(x >> 32); uint32_t l = (uint32_t)(x & UINT32_MAX); #ifdef USE_GCC_BYTESWAP h = __builtin_bswap32(h); l = __builtin_bswap32(l); #else h = (h >> 16) | (h << 16); l = (l >> 16) | (l << 16); h = ((h >> 8) & UINT32_C(0x00FF00FF)) | ((h & UINT32_C(0x00FF00FF)) << 8); l = ((l >> 8) & UINT32_C(0x00FF00FF)) | ((l & UINT32_C(0x00FF00FF)) << 8); #endif h = ((h >> 4) & UINT32_C(0x0F0F0F0F)) | ((h & UINT32_C(0x0F0F0F0F)) << 4); l = ((l >> 4) & UINT32_C(0x0F0F0F0F)) | ((l & UINT32_C(0x0F0F0F0F)) << 4); h = ((h >> 2) & UINT32_C(0x33333333)) | ((h & UINT32_C(0x33333333)) << 2); l = ((l >> 2) & UINT32_C(0x33333333)) | ((l & UINT32_C(0x33333333)) << 2); h = ((h >> 1) & UINT32_C(0x55555555)) | ((h & UINT32_C(0x55555555)) << 1); l = ((l >> 1) & UINT32_C(0x55555555)) | ((l & UINT32_C(0x55555555)) << 1); return ((uint64_t)l << 32) | h; /* Swap halves */ #endif } /* Apply a permutation to scramble vertex numbers; a randomly generated * permutation is not used because applying it at scale is too expensive. */ static inline int64_t scramble(int64_t v0, int lgN, uint64_t val0, uint64_t val1) { uint64_t v = (uint64_t)v0; v += val0 + val1; v *= (val0 | UINT64_C(0x4519840211493211)); v = (bitreverse(v) >> (64 - lgN)); assert ((v >> lgN) == 0); v *= (val1 | UINT64_C(0x3050852102C843A5)); v = (bitreverse(v) >> (64 - lgN)); assert ((v >> lgN) == 0); return (int64_t)v; } /* Make a single graph edge using a pre-set MRG state. */ static void make_one_edge(int64_t nverts, int level, int lgN, mrg_state* st, packed_edge* result, uint64_t val0, uint64_t val1) { int64_t base_src = 0, base_tgt = 0; while (nverts > 1) { int square = generate_4way_bernoulli(st, level, lgN); int src_offset = square / 2; int tgt_offset = square % 2; assert (base_src <= base_tgt); if (base_src == base_tgt) { /* Clip-and-flip for undirected graph */ if (src_offset > tgt_offset) { int temp = src_offset; src_offset = tgt_offset; tgt_offset = temp; } } nverts /= 2; ++level; base_src += nverts * src_offset; base_tgt += nverts * tgt_offset; } write_edge(result, scramble(base_src, lgN, val0, val1), scramble(base_tgt, lgN, val0, val1)); } #ifdef _GRAPPA #include <ParallelLoop.hpp> #include <Delegate.hpp> #include <sstream> #endif /* Generate a range of edges (from start_edge to end_edge of the total graph), * writing into elements [0, end_edge - start_edge) of the edges array. This * code is parallel on OpenMP and XMT; it must be used with * separately-implemented SPMD parallelism for MPI. */ void generate_kronecker_range( const uint_fast32_t seed[5] /* All values in [0, 2^31 - 1), not all zero */, int logN /* In base 2 */, int64_t start_edge, int64_t end_edge, edges_ptr_t edges) { mrg_state state; int64_t nverts = (int64_t)1 << logN; int64_t ei; mrg_seed(&state, seed); uint64_t val0, val1; /* Values for scrambling */ { mrg_state new_state = state; mrg_skip(&new_state, 50, 7, 0); val0 = mrg_get_uint_orig(&new_state); val0 *= UINT64_C(0xFFFFFFFF); val0 += mrg_get_uint_orig(&new_state); val1 = mrg_get_uint_orig(&new_state); val1 *= UINT64_C(0xFFFFFFFF); val1 += mrg_get_uint_orig(&new_state); } #ifndef _GRAPPA #ifdef _OPENMP #pragma omp parallel for #endif #ifdef __MTA__ #pragma mta assert parallel #pragma mta block schedule #endif for (ei = start_edge; ei < end_edge; ++ei) { mrg_state new_state = state; mrg_skip(&new_state, 0, ei, 0); make_one_edge(nverts, 0, logN, &new_state, edges + (ei - start_edge), val0, val1); } #else // _GRAPPA //grappa for loop Grappa::forall_localized(edges+start_edge, end_edge-start_edge, [nverts, logN, state, val0, val1](int64_t index, packed_edge& edge) { // copy the random generator state and seek mrg_state new_state = state; mrg_skip(&new_state, 0, index, 0); make_one_edge(nverts, 0, logN, &new_state, &edge, val0, val1); } ); // std::stringstream ss; ss << "edges: [\n"; // for (int64_t i=start_edge; i<end_edge; i++) { // auto e = Grappa::delegate::read(edges+i); // ss << e.v0 << " " << e.v1 << "\n"; // } // ss << "]\n"; // VLOG(1) << ss.str(); #endif // _GRAPPA }
SpatialMaxUnpooling.c
#include <string.h> #include "../thnets.h" int nnload_SpatialMaxUnpooling(struct module *mod, struct nnmodule *n) { struct table *t = n->table; mod->type = MT_SpatialMaxUnpooling; mod->updateOutput = nn_SpatialMaxUnpooling_updateOutput; struct SpatialMaxUnpooling *m = &mod->SpatialMaxUnpooling; m->pooling = TableGetNNModule(t, "pooling"); return 0; } static void SpatialMaxUnpooling_updateOutput_frame(float *input_p, float *output_p, float *ind_p, long nslices, long iwidth, long iheight, long owidth, long oheight) { long k; #pragma omp parallel for private(k) for (k = 0; k < nslices; k++) { float *output_p_k = output_p + k*owidth*oheight; float *input_p_k = input_p + k*iwidth*iheight; float *ind_p_k = ind_p + k*iwidth*iheight; long i, j, maxp; for(i = 0; i < iheight; i++) { for(j = 0; j < iwidth; j++) { maxp = ind_p_k[i*iwidth + j] - 1; /* retrieve position of max */ if(maxp<0 || maxp>=owidth*oheight) THError("invalid max index %d, owidth= %d, oheight= %d",maxp,owidth,oheight); output_p_k[maxp] = input_p_k[i*iwidth + j]; /* update output */ } } } } THFloatTensor *nn_SpatialMaxUnpooling_updateOutput(struct module *module, THFloatTensor *input) { THFloatTensor *output = module->output; THFloatTensor *indices = 0; int dimw = 2; int dimh = 1; int nbatch = 1; int nslices; int iheight; int iwidth; int oheight = 0; int owidth = 0; int i; float *input_data; float *output_data; float *indices_data; if(input->nDimension != 3 && input->nDimension != 4) THError("3D or 4D (batch mode) tensor is expected"); struct network *net = module->net; for(i = 0; i < net->nelem; i++) if(net->modules[i].type == MT_SpatialMaxPooling && net->modules[i].nnmodule == module->SpatialMaxUnpooling.pooling) { owidth = net->modules[i].SpatialMaxPooling.iwidth; oheight = net->modules[i].SpatialMaxPooling.iheight; indices = net->modules[i].SpatialMaxPooling.indices; break; } if (!indices || !THFloatTensor_isSameSizeAs(input, indices)) THError("Invalid input size w.r.t current indices size"); if (input->nDimension == 4) { nbatch = (int)input->size[0]; dimw++; dimh++; } /* sizes */ nslices = (int)input->size[dimh-1]; iheight = (int)input->size[dimh]; iwidth = (int)input->size[dimw]; /* resize output */ if (input->nDimension == 3) { THFloatTensor_resize3d(output, nslices, oheight, owidth); THFloatTensor_zero(output); input_data = THFloatTensor_data(input); output_data = THFloatTensor_data(output); indices_data = THFloatTensor_data(indices); SpatialMaxUnpooling_updateOutput_frame(input_data, output_data, indices_data, nslices, iwidth, iheight, owidth, oheight); } else { long p; THFloatTensor_resize4d(output, nbatch, nslices, oheight, owidth); THFloatTensor_zero(output); input_data = THFloatTensor_data(input); output_data = THFloatTensor_data(output); indices_data = THFloatTensor_data(indices); #pragma omp parallel for private(p) for (p = 0; p < nbatch; p++) { SpatialMaxUnpooling_updateOutput_frame(input_data+p*nslices*iwidth*iheight, output_data+p*nslices*owidth*oheight, indices_data+p*nslices*iwidth*iheight, nslices, iwidth, iheight, owidth, oheight); } } return output; }
GB_unop__creal_fp32_fc32.c
//------------------------------------------------------------------------------ // GB_unop: hard-coded functions for each built-in unary 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 GBCUDA_DEV #include "GB_control.h" #include "GB_atomics.h" #include "GB_unop__include.h" // C=unop(A) is defined by the following types and operators: // op(A) function: GB (_unop_apply__creal_fp32_fc32) // op(A') function: GB (_unop_tran__creal_fp32_fc32) // C type: float // A type: GxB_FC32_t // cast: GxB_FC32_t cij = (aij) // unaryop: cij = crealf (aij) #define GB_ATYPE \ GxB_FC32_t #define GB_CTYPE \ float // aij = Ax [pA] #define GB_GETA(aij,Ax,pA) \ GxB_FC32_t aij = Ax [pA] #define GB_CX(p) Cx [p] // unary operator #define GB_OP(z, x) \ z = crealf (x) ; // casting #define GB_CAST(z, aij) \ GxB_FC32_t z = (aij) ; // cij = op (aij) #define GB_CAST_OP(pC,pA) \ { \ /* aij = Ax [pA] */ \ GxB_FC32_t aij = Ax [pA] ; \ /* Cx [pC] = op (cast (aij)) */ \ GxB_FC32_t z = (aij) ; \ Cx [pC] = crealf (z) ; \ } // disable this operator and use the generic case if these conditions hold #define GB_DISABLE \ (GxB_NO_CREAL || GxB_NO_FP32 || GxB_NO_FC32) //------------------------------------------------------------------------------ // Cx = op (cast (Ax)): apply a unary operator //------------------------------------------------------------------------------ GrB_Info GB (_unop_apply__creal_fp32_fc32) ( float *Cx, // Cx and Ax may be aliased const GxB_FC32_t *Ax, const int8_t *restrict Ab, // A->b if A is bitmap int64_t anz, int nthreads ) { #if GB_DISABLE return (GrB_NO_VALUE) ; #else int64_t p ; if (Ab == NULL) { #pragma omp parallel for num_threads(nthreads) schedule(static) for (p = 0 ; p < anz ; p++) { GxB_FC32_t aij = Ax [p] ; GxB_FC32_t z = (aij) ; Cx [p] = crealf (z) ; } } else { // bitmap case, no transpose; A->b already memcpy'd into C->b #pragma omp parallel for num_threads(nthreads) schedule(static) for (p = 0 ; p < anz ; p++) { if (!Ab [p]) continue ; GxB_FC32_t aij = Ax [p] ; GxB_FC32_t z = (aij) ; Cx [p] = crealf (z) ; } } return (GrB_SUCCESS) ; #endif } //------------------------------------------------------------------------------ // C = op (cast (A')): transpose, typecast, and apply a unary operator //------------------------------------------------------------------------------ GrB_Info GB (_unop_tran__creal_fp32_fc32) ( GrB_Matrix C, const GrB_Matrix A, int64_t *restrict *Workspaces, const int64_t *restrict A_slice, int nworkspaces, int nthreads ) { #if GB_DISABLE return (GrB_NO_VALUE) ; #else #include "GB_unop_transpose.c" return (GrB_SUCCESS) ; #endif } #endif
LILCSR.h
//***************************************************************************** //Title :PANSFEM2/LinearAlgebra/Models/LILCSR.h //Author :Tanabe Yuta //Date :2019/11/29 //Copyright :(C)2019 TanabeYuta //***************************************************************************** #pragma once #include <iostream> #include <vector> #include <algorithm> #include <cassert> #include "CSR.h" template<class T> class CSR; template<class T> class LILCSR { public: LILCSR(); ~LILCSR(); LILCSR(int _rows, int _cols); LILCSR(CSR<T> _matrix); //Genarate LILCSR matrix from CSR matrix const int ROWS; //Row number const int COLS; //Column number template<class T1, class T2> friend const std::vector<T1> operator*(const LILCSR<T1>& _m, const std::vector<T2> &_vec); //Operator : Multiple with vector template<class T1, class T2> friend const LILCSR<T1> operator+(const LILCSR<T1>& _m1, const LILCSR<T2>& _m2); //Operator : Add with LILCSR matrix template<class T1, class T2> friend const LILCSR<T1> operator-(const LILCSR<T1>& _m1, const LILCSR<T2>& _m2); //Operator : Subtruct with LILCSR matrix template<class T1, class T2> friend const LILCSR<T2> operator*(T1 _a, const LILCSR<T2>& _m); //Operator : Multiple with real number template<class T1, class T2> friend const LILCSR<T1> operator*(const LILCSR<T1>& _m, T2 _a); //Operator : Multiple with real number template<class T1, class T2> friend const LILCSR<T1> operator/(const LILCSR<T1>& _m, T2 _a); //Operator : template<class F> friend std::ostream& operator << (std::ostream &_out, const LILCSR<F> &_mat); //Operator : to stream bool set(int _row, int _col, T _data); //Set value T get(int _row, int _col) const; //Get value template<class F> friend class CSR; private: std::vector<std::vector<std::pair<int, T> > > data; }; template<class T> inline LILCSR<T>::LILCSR() : ROWS(0), COLS(0) {} template<class T> inline LILCSR<T>::~LILCSR() {} template<class T> inline LILCSR<T>::LILCSR(int _rows, int _cols) : ROWS(_rows), COLS(_cols) { this->data = std::vector<std::vector<std::pair<int, T> > >(_rows); } template<class T> inline LILCSR<T>::LILCSR(CSR<T> _matrix) : ROWS(_matrix.ROWS), COLS(_matrix.COLS) { this->data = std::vector<std::vector<std::pair<int, T> > >(_matrix.ROWS); for (int i = 0; i < _matrix.ROWS; i++) { for (int k = _matrix.indptr[i]; k < _matrix.indptr[i + 1]; k++) { this->data[i].push_back(std::pair<int, T>(_matrix.indices[k], _matrix.data[k])); } } } template<class T> inline bool LILCSR<T>::set(int _row, int _col, T _data) { for (auto& dataj : this->data[_row]) { if (dataj.first == _col) { dataj.second = _data; return true; } } this->data[_row].push_back(std::pair<int, T>(_col, _data)); return false; } template<class T> inline T LILCSR<T>::get(int _row, int _col) const { for (const auto& dataj : this->data[_row]) { if (dataj.first == _col) { return dataj.second; } } return T(); } template<class T1, class T2> inline const std::vector<T1> operator*(const LILCSR<T1>& _m, const std::vector<T2>& _vec) { assert(_m.COLS == _vec.size()); std::vector<T1> v(_m.ROWS, T1()); //#pragma omp parallel for for (int i = 0; i < _m.ROWS; i++) { for (auto dataj : _m.data[i]) { v[i] += dataj.second * _vec[dataj.first]; } } return v; } template<class T1, class T2> inline const LILCSR<T1> operator+(const LILCSR<T1>& _m1, const LILCSR<T2>& _m2) { assert(_m1.ROWS == _m2.ROWS && _m1.COLS == _m2.COLS); LILCSR<T1> m = LILCSR<T1>(_m1); for (int i = 0; i < _m2.ROWS; i++) { for (auto dataij : _m2.data[i]) { int j = dataij.first; m.set(i, j, m.get(i, j) + dataij.second); } } return m; } template<class T1, class T2> inline const LILCSR<T1> operator-(const LILCSR<T1>& _m1, const LILCSR<T2>& _m2) { assert(_m1.ROWS == _m2.ROWS && _m1.COLS == _m2.COLS); LILCSR<T1> m = LILCSR<T1>(_m1); for (int i = 0; i < _m2.ROWS; i++) { for (auto dataij : _m2.data[i]) { int j = dataij.first; m.set(i, j, m.get(i, j) - dataij.second); } } return m; } template<class T1, class T2> inline const LILCSR<T2> operator*(T1 _a, const LILCSR<T2>& _m) { LILCSR<T2> m = LILCSR<T2>(_m); for (auto& row : m.data) { for (auto& col : row) { col.second *= _a; } } return m; } template<class T1, class T2> inline const LILCSR<T1> operator*(const LILCSR<T1>& _m, T2 _a) { LILCSR<T1> m = LILCSR<T1>(_m); for (auto& row : m.data) { for (auto& col : row) { col.second *= _a; } } return m; } template<class T1, class T2> inline const LILCSR<T1> operator/(const LILCSR<T1>& _m, T2 _a) { LILCSR<T1> m = LILCSR<T1>(_m); for (auto& row : m.data) { for (auto& col : row) { col.second /= _a; } } return m; } template<class F> inline std::ostream & operator<<(std::ostream & _out, const LILCSR<F>& _mat) { for (int i = 0; i < _mat.ROWS; i++) { for (int j = 0; j < _mat.COLS; j++) { _out << _mat.get(i, j) << "\t"; } _out << std::endl; } return _out; }
ex9.c
#include <stdio.h> #include <stdlib.h> #include <omp.h> #include "timer.h" int main(int argc, char const *argv[]) { unsigned long long num_steps; int T; int i; double step; double x; double pi; double sum = 0.0; double tempo, fim, inicio; num_steps = atoll(argv[1]); T = atoi(argv[2]); printf("Num steps=%lld\nT=%d\n", num_steps, T); step = 1.0/(double) num_steps; GET_TIME(inicio); #pragma omp parallel for reduction(+:sum) num_threads(T) private(i,x) for (i = 0; i < num_steps; i++) { x = (i + 0.5) * step; sum = sum + 4.0/(1.0 + x*x); } pi = step * sum; GET_TIME(fim); tempo = fim - inicio; printf("Tempo: %.8lf\n", tempo); printf("\n\nPI: %.20lf\n", pi); return 0; }
hmm.c
/* * Copyright (C) 2017 by Benedict Paten (benedictpaten@gmail.com) * * Released under the MIT license, see LICENSE.txt */ #include "margin.h" // OpenMP #if defined(_OPENMP) #include <omp.h> #define CELL_BUFFER_SIZE 1000 #endif inline double logAddP(double a, double b, bool maxNotSum) { /* * Local function for doing addition of logs or (if doing Viterbi style calculation), to take the max. */ return maxNotSum ? (a > b ? a : b) : stMath_logAddExact(a, b); } /* * Reference and site methods */ void stReference_destruct(stReference *ref) { for (int64_t i = 0; i < ref->length; i++) { stSite s = ref->sites[i]; free(s.allelePriorLogProbs); free(s.substitutionLogProbs); } free(ref->sites); free(ref->referenceName); free(ref); } /* * Functions for the read partitioning hmm object stRPHmm. */ void stRPHmmParameters_destruct(stRPHmmParameters *params) { free(params); } void stRPHmmParameters_printParameters(stRPHmmParameters *params, FILE *fH) { /* * Print the parameters in the parameters object in a human readable form. */ fprintf(fH, "\tRead Partitioning HMM Parameters\n"); fprintf(fH, "\t\tMax_read coverage_depth: %" PRIi64 "\n" "\t\tMax_not sum transitions?: %i\n" "\t\tMax_partitions in a column of an HMM: %" PRIi64 "\n" "\t\tMin read coverage to support phasing between heterozygous sites: %" PRIi64 "\n", params->maxCoverageDepth, (int)params->maxNotSumTransitions, params->maxPartitionsInAColumn, params->minReadCoverageToSupportPhasingBetweenHeterozygousSites); fprintf(fH, "\t\tInclude inverted partitions?: %i\n", (int) params->includeInvertedPartitions); fprintf(fH, "\t\tRounds of iterative refinement: %" PRIi64 "\n", params->roundsOfIterativeRefinement); } static int cmpint64(int64_t i, int64_t j) { return i > j ? 1 : i < j ? -1 : 0; } inline int stRPHmm_cmpFn(const void *a, const void *b) { /* * Compares two read partitioning HMMs by coordinate on the reference. * Will return equal only if they are the same HMM, with the same memory * address, otherwise compares pointers for equal HMMs. * */ stRPHmm *hmm1 = (stRPHmm *)a, *hmm2 = (stRPHmm *)b; int i = strcmp(hmm1->ref->referenceName, hmm2->ref->referenceName); if(i == 0) { i = cmpint64(hmm1->refStart, hmm2->refStart); if(i == 0) { // Sort by descending order of length i = cmpint64(hmm2->refLength, hmm1->refLength); if(i == 0) { // Compare by id of first profile sequence if(stList_length(hmm1->profileSeqs) > 0 && stList_length(hmm2->profileSeqs) > 0) { stProfileSeq *pSeq1 = stList_get(hmm1->profileSeqs, 0); stProfileSeq *pSeq2 = stList_get(hmm2->profileSeqs, 0); i = strcmp(pSeq1->readId, pSeq2->readId); } if(i == 0) { // If still 0 i = hmm1 > hmm2 ? 1 : (hmm1 < hmm2 ? -1 : 0); } } } } return i; } stRPHmm *stRPHmm_construct(stProfileSeq *profileSeq, stRPHmmParameters *params) { /* * Create a read partitioning HMM representing the single sequence profile. */ stRPHmm *hmm = st_calloc(1, sizeof(stRPHmm)); // Set reference coordinates hmm->ref = profileSeq->ref; hmm->refStart = profileSeq->refStart; hmm->refLength = profileSeq->length; // Add the single profile sequence to the list of the hmm's sequences hmm->profileSeqs = stList_construct(); stList_append(hmm->profileSeqs, profileSeq); hmm->parameters = params; // Parameters for the model for computation, this is shared by different HMMs hmm->columnNumber = 1; // The number of columns in the model, initially just 1 hmm->maxDepth = 1; // The maximum number of states in a column, initially just 1 // Create the first column of the model stProfileSeq **seqHeaders = st_malloc(sizeof(stProfileSeq *)); seqHeaders[0] = profileSeq; uint8_t **seqs = st_malloc(sizeof(uint8_t *)); seqs[0] = profileSeq->profileProbs; stRPColumn *column = stRPColumn_construct(hmm->refStart, hmm->refLength, 1, seqHeaders, seqs); hmm->firstColumn = column; hmm->lastColumn = column; // Add two cells to the column to represent the two possible partitions of the single profile sequence stRPCell *cell = stRPCell_construct(1); column->head = cell; cell->nCell = stRPCell_construct(0); return hmm; } void stRPHmm_destruct(stRPHmm *hmm, bool destructColumns) { /* * Free memory owned by the hmm, including columns. */ stList_destruct(hmm->profileSeqs); if(destructColumns) { // Cleanup the columns of the hmm stRPColumn *column = hmm->firstColumn; while(1) { stRPMergeColumn *mColumn = column->nColumn; stRPColumn_destruct(column); if(mColumn == NULL) { break; } column = mColumn->nColumn; stRPMergeColumn_destruct(mColumn); } } free(hmm); } void stRPHmm_destruct2(stRPHmm *hmm) { /* * Cleans up hmm and columns */ stRPHmm_destruct(hmm, 1); } stList *stRPHmm_forwardTraceBack(stRPHmm *hmm) { /* * Traces back through the forward matrix picking the most probable path. * (yes, this is non-symmetric) * Returns the result as a list of cells, one from each column. */ stList *path = stList_construct(); stRPColumn *column = hmm->lastColumn; // Pick cell in the last column with highest probability stRPCell *cell = column->head; double maxProb = cell->forwardLogProb; stRPCell *maxCell = cell; while((cell = cell->nCell) != NULL) { if(cell->forwardLogProb > maxProb) { maxProb = cell->forwardLogProb; maxCell = cell; } } st_logDebug("Maximum probability of hmm: %f\n", maxProb); stList_append(path, maxCell); // Add chosen cell to output // Walk back through previous columns while(column->pColumn != NULL) { // Get previous merge cell stRPMergeCell *mCell = stRPMergeColumn_getPreviousMergeCell(maxCell, column->pColumn); assert(mCell != NULL); // Switch to previous column column = column->pColumn->pColumn; // Walk through cells in the previous column to find the one with the // highest forward probability that transitions to maxCell cell = column->head; maxCell = NULL; maxProb = ST_MATH_LOG_ZERO; do { // If compatible and has greater probability if(stRPMergeColumn_getNextMergeCell(cell, column->nColumn) == mCell && cell->forwardLogProb > maxProb) { maxProb = cell->forwardLogProb; maxCell = cell; } } while((cell = cell->nCell) != NULL); assert(maxCell != NULL); stList_append(path, maxCell); } stList_reverse(path); // So cells go in order return path; } stSet *stRPHmm_partitionSequencesByStatePath(stRPHmm *hmm, stList *path, bool partition1) { /* * For an hmm and path through the hmm (e.g. computed with stRPHmm_forwardTraceBack) returns the * set of sequences in the hmm that are predicted to come from one given haplotype. */ stSet *seqsInHap1 = stSet_construct(); // For each cell/column pair stRPColumn *column = hmm->firstColumn; for(int64_t i=0; i<stList_length(path); i++) { stRPCell *cell = stList_get(path, i); // Get sequences in first or second partition for(int64_t j=0; j<column->depth; j++) { if((seqInHap1(cell->partition, j) && partition1) || (!seqInHap1(cell->partition, j) && !partition1)) { stSet_insert(seqsInHap1, column->seqHeaders[j]); // todo add to readHaplotypes } } if(column->nColumn != NULL) { column = column->nColumn->nColumn; } } return seqsInHap1; } void stRPHmm_print(stRPHmm *hmm, FILE *fileHandle, bool includeColumns, bool includeCells) { /* * Prints a debug friendly representation of the state of an hmm. */ //Header line fprintf(fileHandle, "HMM REF_NAME: %s REF_START: %" PRIi64 " REF_LENGTH %" PRIi64 " COLUMN_NUMBER %" PRIi64 " MAX_DEPTH: %" PRIi64 " FORWARD_PROB: %f BACKWARD_PROB: %f\n", hmm->ref->referenceName, hmm->refStart, hmm->refLength, hmm->columnNumber, hmm->maxDepth, (float)hmm->forwardLogProb, (float)hmm->backwardLogProb); if(includeColumns) { stRPColumn *column = hmm->firstColumn; int64_t i=0; while(1) { fprintf(fileHandle, "Column %" PRIi64 "\n", i++); // Print the column stRPColumn_print(column, fileHandle, includeCells); if(column->nColumn == NULL) { break; } // Print the merge column stRPMergeColumn_print(column->nColumn, fileHandle, includeCells); column = column->nColumn->nColumn; } } } stRPHmm *stRPHmm_fuse(stRPHmm *leftHmm, stRPHmm *rightHmm) { /* * Fuses together two hmms, such that leftHmm and rightHMM * are on the same reference sequence and non-overlapping and * left hmm precedes right hmm on the reference sequence. * Returns fused hmm, destroys input hmms in the process. */ // Checks if(!stString_eq(leftHmm->ref->referenceName, rightHmm->ref->referenceName)) { st_errAbort("Attempting to fuse two hmms not on the same reference sequence"); } if(stRPHmm_overlapOnReference(leftHmm, rightHmm)) { st_errAbort("Attemping to fuse two hmms that overlap in reference coordinates"); } if(leftHmm->refStart >= rightHmm->refStart) { st_errAbort("Left hmm does not precede right hmm in reference coordinates for merge"); } // Create a new empty hmm stRPHmm *hmm = st_malloc(sizeof(stRPHmm)); // Set the reference interval hmm->ref = leftHmm->ref; hmm->refStart = leftHmm->refStart; hmm->refLength = rightHmm->refStart + rightHmm->refLength - leftHmm->refStart; // Create the combined list of profile seqs hmm->profileSeqs = stList_copy(leftHmm->profileSeqs, NULL); stList_appendAll(hmm->profileSeqs, rightHmm->profileSeqs); // Set column number hmm->columnNumber = leftHmm->columnNumber + rightHmm->columnNumber; // Max depth hmm->maxDepth = leftHmm->maxDepth > rightHmm->maxDepth ? leftHmm->maxDepth : rightHmm->maxDepth; // Parameters if(leftHmm->parameters != rightHmm->parameters) { st_errAbort("HMM parameters differ in fuse function, panic."); } hmm->parameters = leftHmm->parameters; // Make columns to fuse left hmm and right hmm's columns stRPMergeColumn *mColumn = stRPMergeColumn_construct(0, 0); // Links leftHmm->lastColumn->nColumn = mColumn; mColumn->pColumn = leftHmm->lastColumn; // Add merge cell to connect the cells in the two columns stRPMergeCell_construct(0, 0, mColumn); int64_t gapLength = rightHmm->refStart - (leftHmm->refStart + leftHmm->refLength); assert(gapLength >= 0); if(gapLength > 0) { // Make column in the gap stRPColumn *column = stRPColumn_construct(leftHmm->refStart + leftHmm->refLength, gapLength, 0, NULL, NULL); // Links mColumn->nColumn = column; column->pColumn = mColumn; // Make cell for empty column column->head = stRPCell_construct(0); // Add right merge column mColumn = stRPMergeColumn_construct(0, 0); // Add merge cell to connect the cells in the two columns stRPMergeCell_construct(0, 0, mColumn); // Links column->nColumn = mColumn; mColumn->pColumn = column; // Increase the column number to account for the introduced gap column hmm->columnNumber += 1; } mColumn->nColumn = rightHmm->firstColumn; rightHmm->firstColumn->pColumn = mColumn; // Initialise first/last columns of fused hmm hmm->firstColumn = leftHmm->firstColumn; hmm->lastColumn = rightHmm->lastColumn; // Cleanup stRPHmm_destruct(leftHmm, 0); stRPHmm_destruct(rightHmm, 0); return hmm; } void stRPHmm_alignColumns(stRPHmm *hmm1, stRPHmm *hmm2) { /* * Align the input hmms, modifying them in place, so that they each * (1) span the same reference interval, * (2) have the same number of columns, and * (3) so that for all i, column i in each model span the same interval. */ assert(hmm1 != hmm2); // If the two hmms don't overlap in reference space then complain if(!stRPHmm_overlapOnReference(hmm1, hmm2)) { st_errAbort("Attempting to align two HMMs that do not overlap in reference coordinate space"); } // If hmm1 starts after hmm2 then call the other way around if(hmm1->refStart > hmm2->refStart) { stRPHmm_alignColumns(hmm2, hmm1); return; } // If hmm1 starts before hmm2 add an empty prefix interval to hmm2 // so they have the same start coordinate if(hmm1->refStart < hmm2->refStart) { // Create column stRPColumn *column = stRPColumn_construct(hmm1->refStart, hmm2->refStart - hmm1->refStart, 0, NULL, NULL); // Add cell column->head = stRPCell_construct(0); // Create merge column stRPMergeColumn *mColumn = stRPMergeColumn_construct(0,0); // Add merge cell stRPMergeCell_construct(0, 0, mColumn); // Create links hmm2->firstColumn->pColumn = mColumn; mColumn->nColumn = hmm2->firstColumn; mColumn->pColumn = column; column->nColumn = mColumn; assert(column->pColumn == NULL); hmm2->firstColumn = column; //Adjust start and length of hmm2 interval hmm2->refLength += hmm2->refStart - hmm1->refStart; hmm2->refStart = hmm1->refStart; // Increase column number hmm2->columnNumber++; } // If hmm1 has a shorter reference interval length than hmm2 then call the function // with the hmms reversed. if(hmm1->refLength < hmm2->refLength) { stRPHmm_alignColumns(hmm2, hmm1); return; } // If hmm1 has a longer reference interval than hmm2 append an empty suffix // interval to hmm2 to make them the same length. if(hmm1->refLength > hmm2->refLength) { // Create column stRPColumn *column = stRPColumn_construct(hmm2->lastColumn->refStart + hmm2->lastColumn->length, hmm1->refLength - hmm2->refLength, 0, NULL, NULL); // Add cell column->head = stRPCell_construct(0); // Create merge column stRPMergeColumn *mColumn = stRPMergeColumn_construct(0, 0); // Add merge cell stRPMergeCell_construct(0, 0, mColumn); // Create links hmm2->lastColumn->nColumn = mColumn; mColumn->pColumn = hmm2->lastColumn; mColumn->nColumn = column; column->pColumn = mColumn; assert(column->nColumn == NULL); hmm2->lastColumn = column; //Adjust start and length of hmm2 interval hmm2->refLength = hmm1->refLength; // Increase column number hmm2->columnNumber++; } // Quick coordinate checks assert(hmm1->refStart == hmm2->refStart); assert(hmm1->refLength == hmm2->refLength); assert(hmm1->firstColumn->refStart == hmm1->refStart); assert(hmm2->firstColumn->refStart == hmm2->refStart); assert(hmm1->lastColumn->refStart + hmm1->lastColumn->length == hmm1->refStart + hmm1->refLength); assert(hmm2->lastColumn->refStart + hmm2->lastColumn->length == hmm2->refStart + hmm2->refLength); // At this point both hmms have the same reference interval // While one hmm has a shorter reference interval than the other split the other interval // otherwise move on to the next stRPColumn *column1 = hmm1->firstColumn; stRPColumn *column2 = hmm2->firstColumn; while(1) { assert(column1->refStart == column2->refStart); if(column1->length > column2->length) { stRPColumn_split(column1, column2->length, hmm1); assert(column1->nColumn->nColumn->refStart == column1->refStart + column2->length); } else if(column1->length < column2->length) { stRPColumn_split(column2, column1->length, hmm2); } assert(column1->refStart == column2->refStart); assert(column1->length == column2->length); // Now have equal length/start // There are no more columns, so break if(column1->nColumn == NULL) { assert(hmm1->lastColumn == column1); assert(column2->nColumn == NULL); assert(hmm2->lastColumn == column2); break; } column1 = column1->nColumn->nColumn; assert(column2->nColumn != NULL); column2 = column2->nColumn->nColumn; assert(column1 != NULL); assert(column2 != NULL); } assert(hmm1->columnNumber == hmm2->columnNumber); } static uint64_t intHashFn(const void *a) { return *(uint64_t *)a; } static int intEqualsFn(const void *key1, const void *key2) { return *(uint64_t *)key1 == *(uint64_t *)key2; } stRPCell **makeCell(uint64_t partition, stRPCell **pCell, stHash *seen) { /* * Make a cell for a column. */ // Make the cell stRPCell *cell = stRPCell_construct(partition); // Add the partition to those already seen assert(stHash_search(seen, &cell->partition) == NULL); stHash_insert(seen, &cell->partition, cell); // Link cells *pCell = cell; return &cell->nCell; } stRPHmm *stRPHmm_createCrossProductOfTwoAlignedHmm(stRPHmm *hmm1, stRPHmm *hmm2) { /* * For two aligned hmms (see stRPHmm_alignColumns) returns a new hmm that represents the * cross product of all the states of the two input hmms. */ // Do sanity checks that the two hmms have been aligned if(!stString_eq(hmm1->ref->referenceName, hmm2->ref->referenceName)) { st_errAbort("Trying to create cross product of two HMMs " "on different reference sequences"); } if(hmm1->refStart != hmm2->refStart) { st_errAbort("Trying to create cross product of two HMMs " "with different reference interval starts"); } if(hmm1->refLength != hmm2->refLength) { st_errAbort("Trying to create cross product of two HMMs " "with different reference interval length"); } if(hmm1->columnNumber != hmm2->columnNumber) { st_errAbort("Trying to create cross product of two HMMs " "with different column numbers"); } // Create a new empty hmm stRPHmm *hmm = st_calloc(1, sizeof(stRPHmm)); // Set the reference interval hmm->ref = hmm1->ref; hmm->refStart = hmm1->refStart; hmm->refLength = hmm1->refLength; // Create the combined list of profile seqs hmm->profileSeqs = stList_copy(hmm1->profileSeqs, NULL); stList_appendAll(hmm->profileSeqs, hmm2->profileSeqs); // Set column number hmm->columnNumber = hmm1->columnNumber; // Set substitution matrices if(hmm1->parameters != hmm2->parameters) { st_errAbort("Hmm parameters differ in fuse function, panic."); } hmm->parameters = hmm1->parameters; // For each pair of corresponding columns stRPColumn *column1 = hmm1->firstColumn; stRPColumn *column2 = hmm2->firstColumn; assert(column1 != NULL); assert(column2 != NULL); stRPMergeColumn *mColumn = NULL; while(1) { // Check columns aligned assert(column1->refStart == column2->refStart); assert(column1->length == column2->length); // Create the new column // Depth int64_t newColumnDepth = column1->depth+column2->depth; if(newColumnDepth > hmm->maxDepth) { hmm->maxDepth = newColumnDepth; } // Seq headers stProfileSeq **seqHeaders = st_malloc(sizeof(stProfileSeq *) * newColumnDepth); memcpy(seqHeaders, column1->seqHeaders, sizeof(stProfileSeq *) * column1->depth); memcpy(&seqHeaders[column1->depth], column2->seqHeaders, sizeof(stProfileSeq *) * column2->depth); // Profiles uint8_t **seqs = st_malloc(sizeof(uint8_t *) * newColumnDepth); memcpy(seqs, column1->seqs, sizeof(uint8_t *) * column1->depth); memcpy(&seqs[column1->depth], column2->seqs, sizeof(uint8_t *) * column2->depth); stRPColumn *column = stRPColumn_construct(column1->refStart, column1->length, newColumnDepth, seqHeaders, seqs); // If the there is a previous column if(mColumn != NULL) { mColumn->nColumn = column; column->pColumn = mColumn; } else { hmm->firstColumn = column; assert(column->pColumn == NULL); } // Create cross product of columns stRPCell **pCell = &column->head; stRPCell *cell1 = column1->head; // includeInvertedPartitions forces that the partition and its inverse are included // in the resulting combine hmm. if(hmm->parameters->includeInvertedPartitions) { stHash *seen = stHash_construct3(intHashFn, intEqualsFn, NULL, NULL); do { stRPCell *cell2 = column2->head; do { uint64_t partition = mergePartitionsOrMasks(cell1->partition, cell2->partition, column1->depth, column2->depth); // We have not seen the combined partition before if(stHash_search(seen, &partition) == NULL) { // Add the partition to the column pCell = makeCell(partition, pCell, seen); // Check if the column has non-zero depth and only add the inverse partition if it does // because if zero length the inverse partition is the same as for the forward, and therefore // a duplicate if(newColumnDepth > 0) { uint64_t invertedPartition = invertPartition(partition, newColumnDepth); assert(stHash_search(seen, &invertedPartition) == NULL); pCell = makeCell(invertedPartition, pCell, seen); } } } while((cell2 = cell2->nCell) != NULL); } while((cell1 = cell1->nCell) != NULL); // Cleanup stHash_destruct(seen); } // If not forcing symmetry else { do { stRPCell *cell2 = column2->head; do { stRPCell *cell = stRPCell_construct(mergePartitionsOrMasks(cell1->partition, cell2->partition, column1->depth, column2->depth)); // Link cells *pCell = cell; pCell = &cell->nCell; } while((cell2 = cell2->nCell) != NULL); } while((cell1 = cell1->nCell) != NULL); } // Get the next merged column stRPMergeColumn *mColumn1 = column1->nColumn; stRPMergeColumn *mColumn2 = column2->nColumn; // If column is NULL, we have reached the last column // and we can exit if(mColumn1 == NULL) { assert(mColumn2 == NULL); assert(hmm1->lastColumn == column1); assert(hmm2->lastColumn == column2); // Set the last column pointer hmm->lastColumn = column; break; } // Create new merged column uint64_t fromMask = mergePartitionsOrMasks(mColumn1->maskFrom, mColumn2->maskFrom, mColumn1->pColumn->depth, mColumn2->pColumn->depth); uint64_t toMask = mergePartitionsOrMasks(mColumn1->maskTo, mColumn2->maskTo, mColumn1->nColumn->depth, mColumn2->nColumn->depth); assert(popcount64(fromMask) == popcount64(toMask)); mColumn = stRPMergeColumn_construct(fromMask, toMask); // Connect links mColumn->pColumn = column; column->nColumn = mColumn; // Create cross product of merged columns stHashIterator *cellIt1 = stHash_getIterator(mColumn1->mergeCellsFrom); stRPMergeCell *mCell1; while((mCell1 = stHash_getNext(cellIt1)) != NULL) { stHashIterator *cellIt2 = stHash_getIterator(mColumn2->mergeCellsFrom); stRPMergeCell *mCell2; while((mCell2 = stHash_getNext(cellIt2)) != NULL) { uint64_t fromPartition = mergePartitionsOrMasks(mCell1->fromPartition, mCell2->fromPartition, mColumn1->pColumn->depth, mColumn2->pColumn->depth); uint64_t toPartition = mergePartitionsOrMasks(mCell1->toPartition, mCell2->toPartition, mColumn1->nColumn->depth, mColumn2->nColumn->depth); assert(popcount64(fromPartition) == popcount64(toPartition)); // includeInvertedPartitions forces that the partition and its inverse are included // in the resulting combined hmm. if(hmm->parameters->includeInvertedPartitions) { if(stHash_search(mColumn->mergeCellsFrom, &fromPartition) == NULL) { stRPMergeCell_construct(fromPartition, toPartition, mColumn); // If the mask includes no sequences then the the inverted will be identical, so we check // to avoid adding the same partition twice if(popcount64(fromMask) > 0) { uint64_t invertedFromPartition = mColumn->maskFrom & invertPartition(fromPartition, mColumn1->pColumn->depth + mColumn2->pColumn->depth); uint64_t invertedToPartition = mColumn->maskTo & invertPartition(toPartition, mColumn1->nColumn->depth + mColumn2->nColumn->depth); stRPMergeCell_construct(invertedFromPartition, invertedToPartition, mColumn); } } } else { stRPMergeCell_construct(fromPartition, toPartition, mColumn); } } stHash_destructIterator(cellIt2); } stHash_destructIterator(cellIt1); // Get next column column1 = mColumn1->nColumn; column2 = mColumn2->nColumn; assert(column1 != NULL); assert(column2 != NULL); } return hmm; } static void stRPHmm_initialiseProbs(stRPHmm *hmm) { /* * Initialize the forward and backward matrices. */ // Initialize total forward and backward probabilities hmm->forwardLogProb = ST_MATH_LOG_ZERO; hmm->backwardLogProb = ST_MATH_LOG_ZERO; // Iterate through columns from first to last stRPColumn *column = hmm->firstColumn; while(1) { // Set total log prob column->totalLogProb = ST_MATH_LOG_ZERO; // Initialise cells in the column stRPCell *cell = column->head; do { cell->forwardLogProb = ST_MATH_LOG_ZERO; cell->backwardLogProb = ST_MATH_LOG_ZERO; } while((cell = cell->nCell) != NULL); if(column->nColumn == NULL) { break; } // Initialise cells in the next merge column stList *mergeCells = stHash_getValues(column->nColumn->mergeCellsFrom); for(int64_t i=0; i<stList_length(mergeCells); i++) { stRPMergeCell *mergeCell = stList_get(mergeCells, i); mergeCell->forwardLogProb = ST_MATH_LOG_ZERO; mergeCell->backwardLogProb = ST_MATH_LOG_ZERO; } stList_destruct(mergeCells); column = column->nColumn->nColumn; } } static inline void forwardCellCalc1(stRPHmm *hmm, stRPColumn *column, stRPCell *cell, uint64_t *bitCountVectors) { // If the previous merge column exists then propagate forward probability from merge state if(column->pColumn != NULL) { stRPMergeCell *mCell = stRPMergeColumn_getPreviousMergeCell(cell, column->pColumn); cell->forwardLogProb = mCell->forwardLogProb; } // Otherwise initialize probability with log(1.0) else { cell->forwardLogProb = ST_MATH_LOG_ONE; } // Calculate the emission prob double emissionProb = emissionLogProbability(column, cell, bitCountVectors, hmm->ref, (stRPHmmParameters *)hmm->parameters); // Add emission prob to forward log prob cell->forwardLogProb += emissionProb; // Store the emission probability for the cell in the backwardLogProb field temporarily // (is corrected during the backward pass) cell->backwardLogProb = emissionProb; } static inline void forwardCellCalc2(stRPHmm *hmm, stRPColumn *column, stRPCell *cell) { // If the next merge column exists then propagate forward probability to the merge state if (column->nColumn != NULL) { // Add to the next merge cell stRPMergeCell *mCell = stRPMergeColumn_getNextMergeCell(cell, column->nColumn); mCell->forwardLogProb = logAddP(mCell->forwardLogProb, cell->forwardLogProb, hmm->parameters->maxNotSumTransitions); } else { // Else propagate probability to total forward probability of model hmm->forwardLogProb = logAddP(hmm->forwardLogProb, cell->forwardLogProb, hmm->parameters->maxNotSumTransitions); } } static void stRPHmm_forward(stRPHmm *hmm) { /* * Forward algorithm for hmm. */ stRPColumn *column = hmm->firstColumn; // Iterate through columns from first to last while(1) { // Get the bit count vectors for the column uint64_t *bitCountVectors = calculateCountBitVectors(column->seqs, hmm->ref, column->refStart, column->length, column->depth); // Iterate through states in column stRPCell *cell = column->head; // If OpenMP is available then parallelize the calculation of the emission calcs #if defined(_OPENMP) stRPCell *cells[CELL_BUFFER_SIZE]; do { // Get as many cells as the buffer will fit / there are cells int64_t cellsInBuffer=0; do { cells[cellsInBuffer++] = cell; } while((cell = cell->nCell) != NULL && cellsInBuffer < CELL_BUFFER_SIZE); #pragma omp parallel { #pragma omp for for(int64_t i=0; i<cellsInBuffer; i++) { forwardCellCalc1(hmm, column, cells[i], bitCountVectors); } } for(int64_t i=0; i<cellsInBuffer; i++) { forwardCellCalc2(hmm, column, cells[i]); } } while(cell != NULL); #else // Otherwise do it without the need for the cell buffer do { forwardCellCalc1(hmm, column, cell, bitCountVectors); forwardCellCalc2(hmm, column, cell); } while((cell = cell->nCell) != NULL); #endif // Cleanup the bit count vectors free(bitCountVectors); if(column->nColumn == NULL) { break; } column = column->nColumn->nColumn; } } static inline void backwardCellCalc(stRPHmm *hmm, stRPColumn *column, stRPCell *cell) { // Retrieve the emission probability that was stored by the forward pass double probabilityToPropagateLogProb = cell->backwardLogProb; // If the next merge column exists then propagate backward probability from merge state if(column->nColumn != NULL) { stRPMergeCell *mCell = stRPMergeColumn_getNextMergeCell(cell, column->nColumn); cell->backwardLogProb = mCell->backwardLogProb; probabilityToPropagateLogProb += mCell->backwardLogProb; } else { // Else set the backward prob to log(1) cell->backwardLogProb = ST_MATH_LOG_ONE; } // If the previous merge column exists then propagate backward probability to the merge state if(column->pColumn != NULL) { // Add to the previous merge cell stRPMergeCell *mCell = stRPMergeColumn_getPreviousMergeCell(cell, column->pColumn); mCell->backwardLogProb = logAddP(mCell->backwardLogProb, probabilityToPropagateLogProb, hmm->parameters->maxNotSumTransitions); } else { hmm->backwardLogProb = logAddP(hmm->backwardLogProb, probabilityToPropagateLogProb, hmm->parameters->maxNotSumTransitions); } // Add to column total probability column->totalLogProb = logAddP(column->totalLogProb, cell->forwardLogProb + cell->backwardLogProb, hmm->parameters->maxNotSumTransitions); } static void stRPHmm_backward(stRPHmm *hmm) { /* * Backward algorithm for hmm. */ stRPColumn *column = hmm->lastColumn; // Iterate through columns from last to first while(1) { // Iterate through states in column stRPCell *cell = column->head; do { backwardCellCalc(hmm, column, cell); } while((cell = cell->nCell) != NULL); if(column->pColumn == NULL) { break; } column = column->pColumn->pColumn; } } void stRPHmm_forwardBackward(stRPHmm *hmm) { /* * Runs the forward and backward algorithms and sets the total column probabilities. * * This function must be run upon an HMM to calculate cell posterior probabilities. */ // Initialise state values stRPHmm_initialiseProbs(hmm); // Run the forward and backward passes stRPHmm_forward(hmm); stRPHmm_backward(hmm); } static int cellCmpFn(const void *a, const void *b, const void *extraArg) { /* * Sort cells by posterior probability in descending order. */ stRPCell *cell1 = (stRPCell *)a, *cell2 = (stRPCell *)b; stRPColumn *column = (stRPColumn *)extraArg; double p1 = stRPCell_posteriorProb(cell1, column), p2 = stRPCell_posteriorProb(cell2, column); return p1 > p2 ? -1 : p1 < p2 ? 1 : 0; } static int mergeCellCmpFn(const void *a, const void *b, const void *extraArg) { /* * Sort merge cells by posterior probability in descending order. */ stRPMergeCell *cell1 = (stRPMergeCell *)a, *cell2 = (stRPMergeCell *)b; stRPMergeColumn *column = (stRPMergeColumn *)extraArg; double p1 = stRPMergeCell_posteriorProb(cell1, column), p2 = stRPMergeCell_posteriorProb(cell2, column); return p1 > p2 ? -1 : p1 < p2 ? 1 : 0; } void filterMergeCells(stRPMergeColumn *mColumn, stSet *chosenMergeCellsSet) { /* * Removes merge cells from the column that are not in chosenMergeCellsSet */ assert(stSet_size(chosenMergeCellsSet) > 0); stList *mergeCells = stHash_getValues(mColumn->mergeCellsFrom); for(int64_t i=0; i<stList_length(mergeCells); i++) { stRPMergeCell *mCell = stList_get(mergeCells, i); assert(mCell != NULL); if(stSet_search(chosenMergeCellsSet, mCell) == NULL) { // Remove the state from the merge column assert(stHash_search(mColumn->mergeCellsFrom, &(mCell->fromPartition)) == mCell); assert(stHash_search(mColumn->mergeCellsTo, &(mCell->toPartition)) == mCell); stHash_remove(mColumn->mergeCellsFrom, &(mCell->fromPartition)); stHash_remove(mColumn->mergeCellsTo, &(mCell->toPartition)); // Cleanup stRPMergeCell_destruct(mCell); } } stList_destruct(mergeCells); assert(stSet_size(chosenMergeCellsSet) == stHash_size(mColumn->mergeCellsFrom)); assert(stSet_size(chosenMergeCellsSet) == stHash_size(mColumn->mergeCellsTo)); } stSet *getLinkedMergeCells(stRPMergeColumn *mColumn, stRPMergeCell *(*getNCell)(stRPCell *, stRPMergeColumn *), stList *cells) { /* * Returns the set of merge cells in the column that are linked to a cell * in cells. */ stSet *chosenMergeCellsSet = stSet_construct(); for(int64_t i=0; i<stList_length(cells); i++) { stRPMergeCell *mCell = getNCell(stList_get(cells, i), mColumn); assert(mCell != NULL); stSet_insert(chosenMergeCellsSet, mCell); } assert(stSet_size(chosenMergeCellsSet) > 0); return chosenMergeCellsSet; } void relinkCells(stRPColumn *column, stList *cells) { /* * Re-links the cells in the list 'cells' to make up the list of cells in the column. */ stRPCell **pCell = &column->head; // Pointer to previous cell, used to // remove cells from the linked list for(int64_t i=0; i<stList_length(cells); i++) { stRPCell *cell = stList_get(cells, i); *pCell = cell; pCell = &cell->nCell; } *pCell = NULL; assert(column->head != NULL); } stList *getLinkedCells(stRPColumn *column, stRPMergeCell *(*getPCell)(stRPCell *, stRPMergeColumn *), stRPMergeColumn *mColumn) { /* * Returns the set of cells in column that are linked to a cell in mColumn. */ // Put cells into an array and sort by descending posterior prob // only keeping cells that still have a preceding merge cell stList *cells = stList_construct(); stRPCell *cell = column->head; do { if(mColumn == NULL || getPCell(cell, mColumn) != NULL) { stList_append(cells, cell); cell = cell->nCell; } else { stRPCell *nCell = cell->nCell; stRPCell_destruct(cell); cell = nCell; } } while(cell != NULL); stList_sort2(cells, cellCmpFn, column); assert(stList_length(cells) > 0); return cells; } void stRPHmm_pruneForwards(stRPHmm *hmm) { /* * Remove cells from hmm whos posterior probability is below the given threshold */ // For each column stRPColumn *column = hmm->firstColumn; stRPMergeColumn *mColumn = NULL; while(1) { assert(column->head != NULL); // Get cells that have a valid previous cell stList *cells = getLinkedCells(column, stRPMergeColumn_getPreviousMergeCell, mColumn); // Get rid of the excess cells while(stList_length(cells) > hmm->parameters->minPartitionsInAColumn && (stList_length(cells) > hmm->parameters->maxPartitionsInAColumn || stRPCell_posteriorProb(stList_peek(cells), column) < hmm->parameters->minPosteriorProbabilityForPartition)) { stRPCell_destruct(stList_pop(cells)); } // Relink the cells (from most probable to least probable) relinkCells(column, cells); // Move on to the next merge column mColumn = column->nColumn; if(mColumn == NULL) { assert(column == hmm->lastColumn); stList_destruct(cells); break; } // Get merge cells that are connected to a cell in the previous column stSet *chosenMergeCellsSet = getLinkedMergeCells(mColumn, stRPMergeColumn_getNextMergeCell, cells); // Shrink the the number of chosen cells to less than equal to the desired number stList *chosenMergeCellsList = stSet_getList(chosenMergeCellsSet); stList_sort2(chosenMergeCellsList, mergeCellCmpFn, mColumn); while(stList_length(chosenMergeCellsList) > hmm->parameters->minPartitionsInAColumn && (stList_length(chosenMergeCellsList) > hmm->parameters->maxPartitionsInAColumn || stRPMergeCell_posteriorProb(stList_peek(chosenMergeCellsList), mColumn) < hmm->parameters->minPosteriorProbabilityForPartition)) { stSet_remove(chosenMergeCellsSet, stList_pop(chosenMergeCellsList)); } assert(stList_length(chosenMergeCellsList) == stSet_size(chosenMergeCellsSet)); stList_destruct(chosenMergeCellsList); // Get rid of merge cells we don't need filterMergeCells(mColumn, chosenMergeCellsSet); // Cleanup stList_destruct(cells); stSet_destruct(chosenMergeCellsSet); column = mColumn->nColumn; } } void stRPHmm_pruneBackwards(stRPHmm *hmm) { /* * Remove cells from hmm whos posterior probability is below the given threshold */ // For each column stRPColumn *column = hmm->lastColumn; stRPMergeColumn *mColumn = NULL; while(1) { assert(column->head != NULL); // Get cells that have a valid previous cell stList *cells = getLinkedCells(column, stRPMergeColumn_getNextMergeCell, mColumn); // This must be true because the forward pass has already winnowed the number below the // threshold assert(stList_length(cells) <= hmm->parameters->maxPartitionsInAColumn); // Relink the cells (from most probable to least probable) relinkCells(column, cells); // Move on to the next merge column mColumn = column->pColumn; if(mColumn == NULL) { assert(column == hmm->firstColumn); stList_destruct(cells); break; } // Get merge cells that are connected to a cell in the previous column stSet *chosenMergeCellsSet = getLinkedMergeCells(mColumn, stRPMergeColumn_getPreviousMergeCell, cells); // By the same logic, this number if pruned on the forwards pass assert(stSet_size(chosenMergeCellsSet) <= hmm->parameters->maxPartitionsInAColumn); // Get rid of merge cells we don't need filterMergeCells(mColumn, chosenMergeCellsSet); // Cleanup stList_destruct(cells); stSet_destruct(chosenMergeCellsSet); column = mColumn->pColumn; } } void stRPHmm_prune(stRPHmm *hmm) { stRPHmm_pruneForwards(hmm); stRPHmm_pruneBackwards(hmm); } bool stRPHmm_overlapOnReference(stRPHmm *hmm1, stRPHmm *hmm2) { /* * Return non-zero iff hmm1 and hmm2 have the same reference sequence and overlapping * coordinates intervals on that reference sequence. */ // If either interval is zero length this is not a well defined comparison if(hmm1->refLength <= 0 || hmm2->refLength <= 0) { st_errAbort("Trying to compare HMMs with a zero length coordinate interval"); } // Check if on the same reference sequence if(!stString_eq(hmm1->ref->referenceName, hmm2->ref->referenceName)) { return 0; } // Check if intervals overlap // If hmm1 starts after hmm2's start coordinate then switch hmm1 for hmm2 if(hmm1->refStart > hmm2->refStart) { return stRPHmm_overlapOnReference(hmm2, hmm1); } // The coordinates of the first interval overlap the second return hmm1->refStart + hmm1->refLength > hmm2->refStart; } static stRPColumn *getColumn(stRPColumn *column, int64_t site) { /* * Returns column containing the given reference position, starting from the linked, preceding column "column". */ assert(column != NULL); while(1) { assert(site >= column->refStart); if(site < column->refStart + column->length) { return column; } if(column->nColumn == NULL) { break; } column = column->nColumn->nColumn; } st_errAbort("Site: %" PRIi64 " not contained in hmm\n", site); return column; } void stRPHmm_resetColumnNumberAndDepth(stRPHmm *hmm) { /* * Walk through the hmm calculate and set the maxDepth and column number. */ hmm->columnNumber = 0; hmm->maxDepth = 0; stRPColumn *column = hmm->firstColumn; while(1) { hmm->columnNumber++; if(hmm->maxDepth < column->depth) { hmm->maxDepth = column->depth; } if(column->nColumn == NULL) { break; } column = column->nColumn->nColumn; } } stRPHmm *stRPHmm_split(stRPHmm *hmm, int64_t splitPoint) { /* * Splits the hmm into two at the specified point, given by the reference coordinate splitPiunt. The return value * is the suffix of the split, whose reference start is splitPoint. * The prefix of the split is the input hmm, which has its suffix cleaved off. Its length is then splitPoint-hmm->refStart. */ if(splitPoint <= hmm->refStart) { st_errAbort("The split point is at or before the start of the reference interval\n"); } assert(splitPoint < hmm->refStart + hmm->refLength); if(splitPoint >= hmm->refStart + hmm->refLength) { st_errAbort("The split point %" PRIi64 " is after the last position of the reference interval\n", splitPoint); } stRPHmm *suffixHmm = st_calloc(1, sizeof(stRPHmm)); // Set the reference interval for the two hmms suffixHmm->ref = hmm->ref; suffixHmm->refStart = splitPoint; suffixHmm->refLength = hmm->refLength + hmm->refStart - splitPoint; hmm->refLength = splitPoint - hmm->refStart; assert(hmm->refLength > 0); assert(suffixHmm->refLength > 0); // Parameters suffixHmm->parameters = hmm->parameters; // Divide the profile sequences between the two hmms (some may end in both if they span the interval) suffixHmm->profileSeqs = stList_construct(); stList *prefixProfileSeqs = stList_construct(); for(int64_t i=0; i<stList_length(hmm->profileSeqs); i++) { stProfileSeq *pSeq = stList_get(hmm->profileSeqs, i); if(pSeq->refStart < splitPoint) { stList_append(prefixProfileSeqs, pSeq); } if(pSeq->refStart + pSeq->length > splitPoint) { stList_append(suffixHmm->profileSeqs, pSeq); } } stList_destruct(hmm->profileSeqs); hmm->profileSeqs = prefixProfileSeqs; // Get the column containing the split point stRPColumn *splitColumn = getColumn(hmm->firstColumn, splitPoint); assert(splitColumn != NULL); assert(splitColumn->refStart <= splitPoint); assert(splitPoint < splitColumn->refStart + splitColumn->length); // If the split point is within the column, split the column if(splitPoint > splitColumn->refStart) { stRPColumn_split(splitColumn, splitPoint-splitColumn->refStart, hmm); splitColumn = splitColumn->nColumn->nColumn; assert(splitPoint == splitColumn->refStart); } // Set links between columns suffixHmm->firstColumn = splitColumn; suffixHmm->lastColumn = hmm->lastColumn; hmm->lastColumn = splitColumn->pColumn->pColumn; hmm->lastColumn->nColumn = NULL; stRPMergeColumn_destruct(splitColumn->pColumn); // Cleanup the merge column that is deleted by this pointer setting splitColumn->pColumn = NULL; // Set depth and column numbers stRPHmm_resetColumnNumberAndDepth(hmm); stRPHmm_resetColumnNumberAndDepth(suffixHmm); return suffixHmm; } static bool sitesLinkageIsWellSupported(stRPHmm *hmm, int64_t leftSite, int64_t rightSite) { /* * Returns true if the two sites, specified by reference coordinates leftSite and rightSite, are linked by * hmm->parameters->minReadCoverageToSupportPhasingBetweenHeterozygousSites, otherwise false. */ stRPColumn *leftColumn = getColumn(hmm->firstColumn, leftSite); stRPColumn *rightColumn = getColumn(leftColumn, rightSite); stSet *sequencesInCommon = stRPColumn_getSequencesInCommon(leftColumn, rightColumn); // Condition to determine if well supported by reads bool wellSupported = stSet_size(sequencesInCommon) >= hmm->parameters->minReadCoverageToSupportPhasingBetweenHeterozygousSites; // Cleanup stSet_destruct(sequencesInCommon); return wellSupported; } stList *stRPHMM_splitWherePhasingIsUncertain(stRPHmm *hmm) { /* * Takes the input hmm and splits into a sequence of contiguous fragments covering the same reference interval, * returned as an ordered list of hmm fragments. * Hmms are split where there is insufficient support between heterozygous * sites to support phasing between the two haplotypes. * See sitesLinkageIsWellSupported for details. */ // Run the forward-backward algorithm stRPHmm_forwardBackward(hmm); // Now compute a high probability path through the hmm stList *path = stRPHmm_forwardTraceBack(hmm); // Get two haplotypes for the path through the HMM stGenomeFragment *gF = stGenomeFragment_construct(hmm, path); // Find high confidence heterozygous sites stList *hetSites = stList_construct3(0, (void (*)(void *))stIntTuple_destruct); for(int64_t i=0; i<gF->length; i++) { // If heterozygous site if(gF->haplotypeString1[i] != gF->haplotypeString2[i]) { stList_append(hetSites, stIntTuple_construct1(gF->refStart + i)); } } // Split hmms stList *splitHmms = stList_construct3(0, (void (*)(void *))stRPHmm_destruct2); // For each pair of contiguous het sites if not supported by sufficient reads split the hmm for(int64_t i=0; i<stList_length(hetSites)-1; i++) { int64_t j = stIntTuple_get(stList_get(hetSites, i), 0); int64_t k = stIntTuple_get(stList_get(hetSites, i+1), 0); assert(k > j); // If not well supported by reads if(!sitesLinkageIsWellSupported(hmm, j, k)) { // Split hmm int64_t splitPoint = j+(k-j+1)/2; stRPHmm *rightHmm = stRPHmm_split(hmm, splitPoint); assert(rightHmm->refStart == splitPoint); assert(hmm->refStart + hmm->refLength == splitPoint); // Add prefix of hmm to list of split hmms stList_append(splitHmms, hmm); // Set hmm as right hmm hmm = rightHmm; } } // Add the remaining part of the hmm to split hmms stList_append(splitHmms, hmm); // Cleanup stList_destruct(hetSites); stList_destruct(path); stGenomeFragment_destruct(gF); return splitHmms; } /* * Functions for logging an hmm */ double getIdentityBetweenHaplotypes(uint64_t *hap1String, uint64_t *hap2String, int64_t length) { /* * Returns the fraction of positions in two haplotypes that are identical. */ int64_t totalMatches = 0; for(int64_t i=0; i<length; i++) { if(hap1String[i] == hap2String[i]) { totalMatches++; } } return ((double)totalMatches)/length; } void logHmm(stRPHmm *hmm, stGenomeFragment *gF) { /* * Print debug-level logging information about an HMM and associated genome fragment. */ if(st_getLogLevel() == debug) { st_logDebug("> Creating genome fragment for reference sequence: %s, start: %" PRIi64 ", length: %" PRIi64 "\n", hmm->ref->referenceName, hmm->refStart, hmm->refLength); st_logDebug("\n\tThere are %" PRIi64 " reads covered by the hmm, " "bipartitioned into sets of %" PRIi64 " and %" PRIi64 " reads\n", stList_length(hmm->profileSeqs), stSet_size(gF->reads1), stSet_size(gF->reads2)); // Print the similarity between the two imputed haplotypes sequences st_logDebug("\tThe haplotypes have identity: %f \n", getIdentityBetweenHaplotypes(gF->haplotypeString1, gF->haplotypeString2, gF->length)); } }
GB_binop__cmplx_fp32.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__cmplx_fp32 // A.*B function (eWiseMult): GB_AemultB__cmplx_fp32 // A*D function (colscale): (none) // D*A function (rowscale): (node) // C+=B function (dense accum): GB_Cdense_accumB__cmplx_fp32 // C+=b function (dense accum): GB_Cdense_accumb__cmplx_fp32 // C+=A+B function (dense ewise3): (none) // C=A+B function (dense ewise3): GB_Cdense_ewise3_noaccum__cmplx_fp32 // C=scalar+B GB_bind1st__cmplx_fp32 // C=scalar+B' GB_bind1st_tran__cmplx_fp32 // C=A+scalar GB_bind2nd__cmplx_fp32 // C=A'+scalar GB_bind2nd_tran__cmplx_fp32 // C type: GxB_FC32_t // A type: float // B,b type: float // BinaryOp: cij = GxB_CMPLXF (aij, bij) #define GB_ATYPE \ float #define GB_BTYPE \ float #define GB_CTYPE \ GxB_FC32_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 \ 0 // true if the types of C and B are identical #define GB_CTYPE_IS_BTYPE \ 0 // aij = Ax [pA] #define GB_GETA(aij,Ax,pA) \ float aij = Ax [pA] // bij = Bx [pB] #define GB_GETB(bij,Bx,pB) \ float bij = Bx [pB] // declare scalar of the same type as C #define GB_CTYPE_SCALAR(t) \ GxB_FC32_t t // cij = Ax [pA] #define GB_COPY_A_TO_C(cij,Ax,pA) \ cij = GxB_CMPLXF (Ax [pA], 0) // cij = Bx [pB] #define GB_COPY_B_TO_C(cij,Bx,pB) \ cij = GxB_CMPLXF (Bx [pB], 0) #define GB_CX(p) Cx [p] // binary operator #define GB_BINOP(z, x, y, i, j) \ z = GxB_CMPLXF (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_CMPLX || GxB_NO_FP32 || GxB_NO_CMPLX_FP32) //------------------------------------------------------------------------------ // 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__cmplx_fp32 ( 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__cmplx_fp32 ( 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 #if 0 { #include "GB_dense_subassign_23_template.c" } #endif return (GrB_SUCCESS) ; #endif } //------------------------------------------------------------------------------ // C += b, accumulate a scalar into a dense matrix //------------------------------------------------------------------------------ GrB_Info GB_Cdense_accumb__cmplx_fp32 ( GrB_Matrix C, const GB_void *p_bwork, const int nthreads ) { #if GB_DISABLE return (GrB_NO_VALUE) ; #else #if 0 { // get the scalar b for C += b, of type float float bwork = (*((float *) p_bwork)) ; #include "GB_dense_subassign_22_template.c" return (GrB_SUCCESS) ; } #endif 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 GxB_FC32_t *GB_RESTRICT Cx = (GxB_FC32_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 GxB_FC32_t *GB_RESTRICT Cx = (GxB_FC32_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__cmplx_fp32 ( 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__cmplx_fp32 ( 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__cmplx_fp32 ( 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 GxB_FC32_t *Cx = (GxB_FC32_t *) Cx_output ; float x = (*((float *) x_input)) ; float *Bx = (float *) 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 ; float bij = Bx [p] ; Cx [p] = GxB_CMPLXF (x, bij) ; } return (GrB_SUCCESS) ; #endif } //------------------------------------------------------------------------------ // Cx = op (Ax,y): apply a binary operator to a matrix with scalar bind2nd //------------------------------------------------------------------------------ GrB_Info GB_bind2nd__cmplx_fp32 ( 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 ; GxB_FC32_t *Cx = (GxB_FC32_t *) Cx_output ; float *Ax = (float *) Ax_input ; float y = (*((float *) y_input)) ; #pragma omp parallel for num_threads(nthreads) schedule(static) for (p = 0 ; p < anz ; p++) { if (!GBB (Ab, p)) continue ; float aij = Ax [p] ; Cx [p] = GxB_CMPLXF (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) \ { \ float aij = Ax [pA] ; \ Cx [pC] = GxB_CMPLXF (x, aij) ; \ } GrB_Info GB_bind1st_tran__cmplx_fp32 ( 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 \ float #if GB_DISABLE return (GrB_NO_VALUE) ; #else float x = (*((const float *) x_input)) ; #include "GB_unop_transpose.c" return (GrB_SUCCESS) ; #endif #undef GB_ATYPE #define GB_ATYPE \ float } //------------------------------------------------------------------------------ // 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) \ { \ float aij = Ax [pA] ; \ Cx [pC] = GxB_CMPLXF (aij, y) ; \ } GrB_Info GB_bind2nd_tran__cmplx_fp32 ( 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 float y = (*((const float *) y_input)) ; #include "GB_unop_transpose.c" return (GrB_SUCCESS) ; #endif } #endif
GB_binop__copysign_fp32.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__copysign_fp32) // A.*B function (eWiseMult): GB (_AemultB_08__copysign_fp32) // A.*B function (eWiseMult): GB (_AemultB_02__copysign_fp32) // A.*B function (eWiseMult): GB (_AemultB_04__copysign_fp32) // A.*B function (eWiseMult): GB (_AemultB_bitmap__copysign_fp32) // A*D function (colscale): GB ((none)) // D*A function (rowscale): GB ((none)) // C+=B function (dense accum): GB (_Cdense_accumB__copysign_fp32) // C+=b function (dense accum): GB (_Cdense_accumb__copysign_fp32) // C+=A+B function (dense ewise3): GB ((none)) // C=A+B function (dense ewise3): GB (_Cdense_ewise3_noaccum__copysign_fp32) // C=scalar+B GB (_bind1st__copysign_fp32) // C=scalar+B' GB (_bind1st_tran__copysign_fp32) // C=A+scalar GB (_bind2nd__copysign_fp32) // C=A'+scalar GB (_bind2nd_tran__copysign_fp32) // C type: float // A type: float // A pattern? 0 // B type: float // B pattern? 0 // BinaryOp: cij = copysignf (aij, bij) #define GB_ATYPE \ float #define GB_BTYPE \ float #define GB_CTYPE \ float // 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) \ float 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) \ float 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) \ float 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 = copysignf (x, y) ; // true if the binop must be flipped #define GB_BINOP_FLIP \ 1 // 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_COPYSIGN || GxB_NO_FP32 || GxB_NO_COPYSIGN_FP32) //------------------------------------------------------------------------------ // 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__copysign_fp32) ( 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__copysign_fp32) ( 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__copysign_fp32) ( 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 float float bwork = (*((float *) 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 GB ((none)) ( 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 float *restrict Cx = (float *) C->x ; #include "GB_AxB_colscale_template.c" return (GrB_SUCCESS) ; #endif } #endif //------------------------------------------------------------------------------ // C = D*B, row scale with diagonal D matrix //------------------------------------------------------------------------------ #if 0 GrB_Info GB ((none)) ( GrB_Matrix C, const GrB_Matrix D, const GrB_Matrix B, int nthreads ) { #if GB_DISABLE return (GrB_NO_VALUE) ; #else float *restrict Cx = (float *) C->x ; #include "GB_AxB_rowscale_template.c" return (GrB_SUCCESS) ; #endif } #endif //------------------------------------------------------------------------------ // eWiseAdd: C=A+B, C<M>=A+B, C<!M>=A+B //------------------------------------------------------------------------------ GrB_Info GB (_AaddB__copysign_fp32) ( 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) ; float alpha_scalar ; float beta_scalar ; if (is_eWiseUnion) { alpha_scalar = (*((float *) alpha_scalar_in)) ; beta_scalar = (*((float *) 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__copysign_fp32) ( 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__copysign_fp32) ( 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__copysign_fp32) ( 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__copysign_fp32) ( 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__copysign_fp32) ( 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 float *Cx = (float *) Cx_output ; float x = (*((float *) x_input)) ; float *Bx = (float *) 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 ; float bij = GBX (Bx, p, false) ; Cx [p] = copysignf (x, bij) ; } return (GrB_SUCCESS) ; #endif } //------------------------------------------------------------------------------ // Cx = op (Ax,y): apply a binary operator to a matrix with scalar bind2nd //------------------------------------------------------------------------------ GrB_Info GB (_bind2nd__copysign_fp32) ( 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 ; float *Cx = (float *) Cx_output ; float *Ax = (float *) Ax_input ; float y = (*((float *) y_input)) ; #pragma omp parallel for num_threads(nthreads) schedule(static) for (p = 0 ; p < anz ; p++) { if (!GBB (Ab, p)) continue ; float aij = GBX (Ax, p, false) ; Cx [p] = copysignf (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) \ { \ float aij = GBX (Ax, pA, false) ; \ Cx [pC] = copysignf (x, aij) ; \ } GrB_Info GB (_bind1st_tran__copysign_fp32) ( 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 \ float #if GB_DISABLE return (GrB_NO_VALUE) ; #else float x = (*((const float *) x_input)) ; #include "GB_unop_transpose.c" return (GrB_SUCCESS) ; #endif #undef GB_ATYPE #define GB_ATYPE \ float } //------------------------------------------------------------------------------ // 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) \ { \ float aij = GBX (Ax, pA, false) ; \ Cx [pC] = copysignf (aij, y) ; \ } GrB_Info GB (_bind2nd_tran__copysign_fp32) ( 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 float y = (*((const float *) y_input)) ; #include "GB_unop_transpose.c" return (GrB_SUCCESS) ; #endif } #endif
NeighborhoodGraph.h
// Copyright (c) Microsoft Corporation. All rights reserved. // Licensed under the MIT License. #ifndef _SPTAG_COMMON_NG_H_ #define _SPTAG_COMMON_NG_H_ #include "../VectorIndex.h" #include "CommonUtils.h" #include "Dataset.h" #include "FineGrainedLock.h" #include "QueryResultSet.h" #include <chrono> #include <queue> #include <atomic> #if defined(GPU) #include <cuda.h> #include <cuda_runtime.h> #include <device_launch_parameters.h> #include <typeinfo> #include <cuda_fp16.h> #include "inc/Core/Common/cuda/KNN.hxx" #include "inc/Core/Common/cuda/params.h" #endif namespace SPTAG { namespace COMMON { class NeighborhoodGraph { public: NeighborhoodGraph() : m_iTPTNumber(32), m_iTPTLeafSize(2000), m_iSamples(1000), m_numTopDimensionTPTSplit(5), m_iNeighborhoodSize(32), m_fNeighborhoodScale(2.0), m_fCEFScale(2.0), m_fRNGFactor(1.0), m_iRefineIter(2), m_iCEF(1000), m_iAddCEF(500), m_iMaxCheckForRefineGraph(10000), m_iGPUGraphType(2), m_iGPURefineSteps(0), m_iGPURefineDepth(2), m_iGPULeafSize(500), m_iheadNumGPUs(1), m_iTPTBalanceFactor(2), m_rebuild(0) {} ~NeighborhoodGraph() {} virtual void InsertNeighbors(VectorIndex* index, const SizeType node, SizeType insertNode, float insertDist) = 0; virtual void RebuildNeighbors(VectorIndex* index, const SizeType node, SizeType* nodes, const BasicResult* queryResults, const int numResults) = 0; virtual float GraphAccuracyEstimation(VectorIndex* index, const SizeType samples, const std::unordered_map<SizeType, SizeType>* idmap = nullptr) { DimensionType* correct = new DimensionType[samples]; #pragma omp parallel for schedule(dynamic) for (SizeType i = 0; i < samples; i++) { SizeType x = COMMON::Utils::rand(m_iGraphSize); //int x = i; COMMON::QueryResultSet<void> query(nullptr, m_iCEF); for (SizeType y = 0; y < m_iGraphSize; y++) { if ((idmap != nullptr && idmap->find(y) != idmap->end())) continue; float dist = index->ComputeDistance(index->GetSample(x), index->GetSample(y)); query.AddPoint(y, dist); } query.SortResult(); SizeType* exact_rng = new SizeType[m_iNeighborhoodSize]; RebuildNeighbors(index, x, exact_rng, query.GetResults(), m_iCEF); correct[i] = 0; for (DimensionType j = 0; j < m_iNeighborhoodSize; j++) { if (exact_rng[j] == -1) { correct[i] += m_iNeighborhoodSize - j; break; } for (DimensionType k = 0; k < m_iNeighborhoodSize; k++) if ((m_pNeighborhoodGraph)[x][k] == exact_rng[j]) { correct[i]++; break; } } delete[] exact_rng; } float acc = 0; for (SizeType i = 0; i < samples; i++) acc += float(correct[i]); acc = acc / samples / m_iNeighborhoodSize; delete[] correct; return acc; } #if defined(GPU) template <typename T> void BuildInitKNNGraph(VectorIndex* index, const std::unordered_map<SizeType, SizeType>* idmap) { SizeType initSize; SPTAG::Helper::Convert::ConvertStringTo(index->GetParameter("NumberOfInitialDynamicPivots").c_str(), initSize); // Build the entire RNG graph, both builds the KNN and refines it to RNG buildGraph<T>(index, m_iGraphSize, m_iNeighborhoodSize, m_iTPTNumber, (int*)m_pNeighborhoodGraph[0], m_iGPURefineSteps, m_iGPURefineDepth, m_iGPUGraphType, m_iGPULeafSize, initSize, m_iheadNumGPUs, m_iTPTBalanceFactor); if (idmap != nullptr) { std::unordered_map<SizeType, SizeType>::const_iterator iter; for (SizeType i = 0; i < m_iGraphSize; i++) { for (DimensionType j = 0; j < m_iNeighborhoodSize; j++) { if ((iter = idmap->find(m_pNeighborhoodGraph[i][j])) != idmap->end()) m_pNeighborhoodGraph[i][j] = iter->second; } } } } #else template <typename T> void PartitionByTptree(VectorIndex* index, std::vector<SizeType>& indices, const SizeType first, const SizeType last, std::vector<std::pair<SizeType, SizeType>>& leaves) { if (COMMON::DistanceUtils::Quantizer) { switch (COMMON::DistanceUtils::Quantizer->GetReconstructType()) { #define DefineVectorValueType(Name, Type) \ case VectorValueType::Name: \ PartitionByTptreeCore<T, Type>(index, indices, first, last, leaves); \ break; #include "inc/Core/DefinitionList.h" #undef DefineVectorValueType default: break; } } else { PartitionByTptreeCore<T, T>(index, indices, first, last, leaves); } } template <typename T, typename R> void PartitionByTptreeCore(VectorIndex* index, std::vector<SizeType>& indices, const SizeType first, const SizeType last, std::vector<std::pair<SizeType, SizeType>>& leaves) { if (last - first <= m_iTPTLeafSize) { leaves.emplace_back(first, last); } else { SizeType cols = index->GetFeatureDim(); bool quantizer_exists = (bool)COMMON::DistanceUtils::Quantizer; R* v_holder = nullptr; if (quantizer_exists) { cols = COMMON::DistanceUtils::Quantizer->ReconstructDim(); v_holder = (R*)_mm_malloc(COMMON::DistanceUtils::Quantizer->ReconstructSize(), ALIGN_SPTAG); } std::vector<float> Mean(cols, 0); int iIteration = 100; SizeType end = min(first + m_iSamples, last); SizeType count = end - first + 1; // calculate the mean of each dimension for (SizeType j = first; j <= end; j++) { R* v; if (quantizer_exists) { COMMON::DistanceUtils::Quantizer->ReconstructVector((uint8_t*)index->GetSample(indices[j]), v_holder); v = v_holder; } else { v = (R*)index->GetSample(indices[j]); } for (DimensionType k = 0; k < cols; k++) { Mean[k] += v[k]; } } for (DimensionType k = 0; k < cols; k++) { Mean[k] /= count; } std::vector<BasicResult> Variance; Variance.reserve(cols); for (DimensionType j = 0; j < cols; j++) { Variance.emplace_back(j, 0.0f); } // calculate the variance of each dimension for (SizeType j = first; j <= end; j++) { R* v; if (quantizer_exists) { COMMON::DistanceUtils::Quantizer->ReconstructVector((uint8_t*)index->GetSample(indices[j]), v_holder); v = v_holder; } else { v = (R*)index->GetSample(indices[j]); } for (DimensionType k = 0; k < cols; k++) { float dist = v[k] - Mean[k]; Variance[k].Dist += dist * dist; } } std::sort(Variance.begin(), Variance.end(), COMMON::Compare); std::vector<SizeType> indexs(m_numTopDimensionTPTSplit); std::vector<float> weight(m_numTopDimensionTPTSplit), bestweight(m_numTopDimensionTPTSplit); float bestvariance = Variance[cols - 1].Dist; for (int i = 0; i < m_numTopDimensionTPTSplit; i++) { indexs[i] = Variance[cols - 1 - i].VID; bestweight[i] = 0; } bestweight[0] = 1; float bestmean = Mean[indexs[0]]; std::vector<float> Val(count); for (int i = 0; i < iIteration; i++) { float sumweight = 0; for (int j = 0; j < m_numTopDimensionTPTSplit; j++) { weight[j] = float(rand() % 10000) / 5000.0f - 1.0f; sumweight += weight[j] * weight[j]; } sumweight = sqrt(sumweight); for (int j = 0; j < m_numTopDimensionTPTSplit; j++) { weight[j] /= sumweight; } float mean = 0; for (SizeType j = 0; j < count; j++) { Val[j] = 0; R* v; if (quantizer_exists) { COMMON::DistanceUtils::Quantizer->ReconstructVector((uint8_t*)index->GetSample(indices[first + j]), v_holder); v = v_holder; } else { v = (R*)index->GetSample(indices[first + j]); } for (int k = 0; k < m_numTopDimensionTPTSplit; k++) { Val[j] += weight[k] * v[indexs[k]]; } mean += Val[j]; } mean /= count; float var = 0; for (SizeType j = 0; j < count; j++) { float dist = Val[j] - mean; var += dist * dist; } if (var > bestvariance) { bestvariance = var; bestmean = mean; for (int j = 0; j < m_numTopDimensionTPTSplit; j++) { bestweight[j] = weight[j]; } } } SizeType i = first; SizeType j = last; // decide which child one point belongs while (i <= j) { float val = 0; R* v; if (quantizer_exists) { COMMON::DistanceUtils::Quantizer->ReconstructVector((uint8_t*)index->GetSample(indices[i]), v_holder); v = v_holder; } else { v = (R*)index->GetSample(indices[i]); } for (int k = 0; k < m_numTopDimensionTPTSplit; k++) { val += bestweight[k] * v[indexs[k]]; } if (val < bestmean) { i++; } else { std::swap(indices[i], indices[j]); j--; } } // if all the points in the node are equal,equally split the node into 2 if ((i == first) || (i == last + 1)) { i = (first + last + 1) / 2; } Mean.clear(); Variance.clear(); Val.clear(); indexs.clear(); weight.clear(); bestweight.clear(); if (v_holder) _mm_free(v_holder); PartitionByTptreeCore<T, R>(index, indices, first, i - 1, leaves); PartitionByTptreeCore<T, R>(index, indices, i, last, leaves); } } template <typename T> void BuildInitKNNGraph(VectorIndex* index, const std::unordered_map<SizeType, SizeType>* idmap) { COMMON::Dataset<float> NeighborhoodDists(m_iGraphSize, m_iNeighborhoodSize, index->m_iDataBlockSize, index->m_iDataCapacity); std::vector<std::vector<SizeType>> TptreeDataIndices(m_iTPTNumber, std::vector<SizeType>(m_iGraphSize)); std::vector<std::vector<std::pair<SizeType, SizeType>>> TptreeLeafNodes(m_iTPTNumber, std::vector<std::pair<SizeType, SizeType>>()); for (SizeType i = 0; i < m_iGraphSize; i++) for (DimensionType j = 0; j < m_iNeighborhoodSize; j++) (NeighborhoodDists)[i][j] = MaxDist; auto t1 = std::chrono::high_resolution_clock::now(); LOG(Helper::LogLevel::LL_Info, "Parallel TpTree Partition begin\n"); #pragma omp parallel for schedule(dynamic) for (int i = 0; i < m_iTPTNumber; i++) { Sleep(i * 100); std::srand(clock()); for (SizeType j = 0; j < m_iGraphSize; j++) TptreeDataIndices[i][j] = j; std::random_shuffle(TptreeDataIndices[i].begin(), TptreeDataIndices[i].end()); PartitionByTptree<T>(index, TptreeDataIndices[i], 0, m_iGraphSize - 1, TptreeLeafNodes[i]); LOG(Helper::LogLevel::LL_Info, "Finish Getting Leaves for Tree %d\n", i); } LOG(Helper::LogLevel::LL_Info, "Parallel TpTree Partition done\n"); auto t2 = std::chrono::high_resolution_clock::now(); LOG(Helper::LogLevel::LL_Info, "Build TPTree time (s): %lld\n", std::chrono::duration_cast<std::chrono::seconds>(t2 - t1).count()); for (int i = 0; i < m_iTPTNumber; i++) { #pragma omp parallel for schedule(dynamic) for (SizeType j = 0; j < (SizeType)TptreeLeafNodes[i].size(); j++) { SizeType start_index = TptreeLeafNodes[i][j].first; SizeType end_index = TptreeLeafNodes[i][j].second; if ((j * 5) % TptreeLeafNodes[i].size() == 0) LOG(Helper::LogLevel::LL_Info, "Processing Tree %d %d%%\n", i, static_cast<int>(j * 1.0 / TptreeLeafNodes[i].size() * 100)); for (SizeType x = start_index; x < end_index; x++) { for (SizeType y = x + 1; y <= end_index; y++) { SizeType p1 = TptreeDataIndices[i][x]; SizeType p2 = TptreeDataIndices[i][y]; float dist = index->ComputeDistance(index->GetSample(p1), index->GetSample(p2)); if (idmap != nullptr) { p1 = (idmap->find(p1) == idmap->end()) ? p1 : idmap->at(p1); p2 = (idmap->find(p2) == idmap->end()) ? p2 : idmap->at(p2); } COMMON::Utils::AddNeighbor(p2, dist, (m_pNeighborhoodGraph)[p1], (NeighborhoodDists)[p1], m_iNeighborhoodSize); COMMON::Utils::AddNeighbor(p1, dist, (m_pNeighborhoodGraph)[p2], (NeighborhoodDists)[p2], m_iNeighborhoodSize); } } } TptreeDataIndices[i].clear(); TptreeLeafNodes[i].clear(); } TptreeDataIndices.clear(); TptreeLeafNodes.clear(); auto t3 = std::chrono::high_resolution_clock::now(); LOG(Helper::LogLevel::LL_Info, "Process TPTree time (s): %lld\n", std::chrono::duration_cast<std::chrono::seconds>(t3 - t2).count()); } #endif template <typename T> void BuildGraph(VectorIndex* index, const std::unordered_map<SizeType, SizeType>* idmap = nullptr) { LOG(Helper::LogLevel::LL_Info, "build RNG graph!\n"); m_iGraphSize = index->GetNumSamples(); m_iNeighborhoodSize = (DimensionType)(ceil(m_iNeighborhoodSize * m_fNeighborhoodScale) * (m_rebuild + 1)); m_pNeighborhoodGraph.Initialize(m_iGraphSize, m_iNeighborhoodSize, index->m_iDataBlockSize, index->m_iDataCapacity); if (m_iGraphSize < 1000) { RefineGraph<T>(index, idmap); LOG(Helper::LogLevel::LL_Info, "Build RNG Graph end!\n"); return; } auto t1 = std::chrono::high_resolution_clock::now(); BuildInitKNNGraph<T>(index, idmap); auto t2 = std::chrono::high_resolution_clock::now(); LOG(Helper::LogLevel::LL_Info, "BuildInitKNNGraph time (s): %lld\n", std::chrono::duration_cast<std::chrono::seconds>(t2 - t1).count()); RefineGraph<T>(index, idmap); auto t3 = std::chrono::high_resolution_clock::now(); LOG(Helper::LogLevel::LL_Info, "BuildGraph time (s): %lld\n", std::chrono::duration_cast<std::chrono::seconds>(t3 - t1).count()); if (m_rebuild) { m_iNeighborhoodSize = m_iNeighborhoodSize / 2; RebuildGraph<T>(index, idmap); auto t4 = std::chrono::high_resolution_clock::now(); LOG(Helper::LogLevel::LL_Info, "ReBuildGraph time (s): %lld\n", std::chrono::duration_cast<std::chrono::seconds>(t4 - t3).count()); } if (idmap != nullptr) { for (auto iter = idmap->begin(); iter != idmap->end(); iter++) if (iter->first < 0) { m_pNeighborhoodGraph[-1 - iter->first][m_iNeighborhoodSize - 1] = -2 - iter->second; } } } template <typename T> void RebuildGraph(VectorIndex* index, const std::unordered_map<SizeType, SizeType>* idmap = nullptr) { std::vector<int> indegree(m_iGraphSize); #pragma omp parallel for schedule(dynamic) for (SizeType i = 0; i < m_iGraphSize; i++) indegree[i] = 0; auto t0 = std::chrono::high_resolution_clock::now(); #pragma omp parallel for schedule(dynamic) for (SizeType i = 0; i < m_iGraphSize; i++) { SizeType* outnodes = m_pNeighborhoodGraph[i]; for (SizeType j = 0; j < m_iNeighborhoodSize; j++) { int node = outnodes[j]; if (node >= 0) { indegree[node]++; } } } auto t1 = std::chrono::high_resolution_clock::now(); LOG(Helper::LogLevel::LL_Info, "Calculate Indegree time (s): %lld\n", std::chrono::duration_cast<std::chrono::seconds>(t1 - t0).count()); int rebuild_threshold = m_iNeighborhoodSize / 2; int rebuildstart = m_iNeighborhoodSize / 2; #pragma omp parallel for schedule(dynamic) for (SizeType i = 0; i < m_iGraphSize; i++) { SizeType* outnodes = m_pNeighborhoodGraph[i]; std::vector<bool> reserve(2 * m_iNeighborhoodSize, false); int total = 0; for (SizeType j = rebuildstart; j < m_iNeighborhoodSize * 2; j++) if ( outnodes[j] >= 0 && indegree[outnodes[j]] < rebuild_threshold) { reserve[j] = true; total++; } for (SizeType j = rebuildstart; j < m_iNeighborhoodSize * 2 && total < m_iNeighborhoodSize - rebuildstart; j++) { if (!reserve[j]) { reserve[j] = true; total++; } } for (SizeType j = rebuildstart, z = rebuildstart; j < m_iNeighborhoodSize; j++) { while (!reserve[z]) z++; if(outnodes[j] >= 0) indegree[outnodes[j]] = indegree[outnodes[j]] - 1; if(outnodes[z] >= 0) indegree[outnodes[z]] = indegree[outnodes[z]] + 1; outnodes[j] = outnodes[z]; z++; } if ((i * 5) % m_iGraphSize == 0) LOG(Helper::LogLevel::LL_Info, "Rebuild %d%%\n", static_cast<int>(i * 1.0 / m_iGraphSize * 100)); } auto t2 = std::chrono::high_resolution_clock::now(); LOG(Helper::LogLevel::LL_Info, "Rebuild RNG time (s): %lld Graph Acc: %f\n", std::chrono::duration_cast<std::chrono::seconds>(t2 - t1).count(), GraphAccuracyEstimation(index, 100, idmap)); } template <typename T> void RefineGraph(VectorIndex* index, const std::unordered_map<SizeType, SizeType>* idmap = nullptr) { for (int iter = 0; iter < m_iRefineIter - 1; iter++) { auto t1 = std::chrono::high_resolution_clock::now(); #pragma omp parallel for schedule(dynamic) for (SizeType i = 0; i < m_iGraphSize; i++) { RefineNode<T>(index, i, false, false, (int)(m_iCEF * m_fCEFScale)); if ((i * 5) % m_iGraphSize == 0) LOG(Helper::LogLevel::LL_Info, "Refine %d %d%%\n", iter, static_cast<int>(i * 1.0 / m_iGraphSize * 100)); } auto t2 = std::chrono::high_resolution_clock::now(); LOG(Helper::LogLevel::LL_Info, "Refine RNG time (s): %lld Graph Acc: %f\n", std::chrono::duration_cast<std::chrono::seconds>(t2 - t1).count(), GraphAccuracyEstimation(index, 100, idmap)); } m_iNeighborhoodSize = (DimensionType)(m_iNeighborhoodSize / m_fNeighborhoodScale); if (m_iRefineIter > 0) { auto t1 = std::chrono::high_resolution_clock::now(); #pragma omp parallel for schedule(dynamic) for (SizeType i = 0; i < m_iGraphSize; i++) { RefineNode<T>(index, i, false, false, m_iCEF); if ((i * 5) % m_iGraphSize == 0) LOG(Helper::LogLevel::LL_Info, "Refine %d %d%%\n", m_iRefineIter - 1, static_cast<int>(i * 1.0 / m_iGraphSize * 100)); } auto t2 = std::chrono::high_resolution_clock::now(); LOG(Helper::LogLevel::LL_Info, "Refine RNG time (s): %lld Graph Acc: %f\n", std::chrono::duration_cast<std::chrono::seconds>(t2 - t1).count(), GraphAccuracyEstimation(index, 100, idmap)); } else { LOG(Helper::LogLevel::LL_Info, "Graph Acc: %f\n", GraphAccuracyEstimation(index, 100, idmap)); } } template <typename T> ErrorCode RefineGraph(VectorIndex* index, std::vector<SizeType>& indices, std::vector<SizeType>& reverseIndices, std::shared_ptr<Helper::DiskPriorityIO> output, NeighborhoodGraph* newGraph, const std::unordered_map<SizeType, SizeType>* idmap = nullptr) { std::shared_ptr<NeighborhoodGraph> tmp; if (newGraph == nullptr) { tmp = NeighborhoodGraph::CreateInstance(Type()); newGraph = tmp.get(); } SizeType R = (SizeType)indices.size(); newGraph->m_pNeighborhoodGraph.Initialize(R, m_iNeighborhoodSize, index->m_iDataBlockSize, index->m_iDataCapacity); newGraph->m_iGraphSize = R; newGraph->m_iNeighborhoodSize = m_iNeighborhoodSize; #pragma omp parallel for schedule(dynamic) for (SizeType i = 0; i < R; i++) { if ((i * 5) % R == 0) LOG(Helper::LogLevel::LL_Info, "Refine %d%%\n", static_cast<int>(i * 1.0 / R * 100)); SizeType* outnodes = newGraph->m_pNeighborhoodGraph[i]; COMMON::QueryResultSet<T> query((const T*)index->GetSample(indices[i]), m_iCEF + 1); index->RefineSearchIndex(query, false); RebuildNeighbors(index, indices[i], outnodes, query.GetResults(), m_iCEF + 1); std::unordered_map<SizeType, SizeType>::const_iterator iter; for (DimensionType j = 0; j < m_iNeighborhoodSize; j++) { if (outnodes[j] >= 0 && outnodes[j] < reverseIndices.size()) outnodes[j] = reverseIndices[outnodes[j]]; if (idmap != nullptr && (iter = idmap->find(outnodes[j])) != idmap->end()) outnodes[j] = iter->second; } if (idmap != nullptr && (iter = idmap->find(-1 - i)) != idmap->end()) outnodes[m_iNeighborhoodSize - 1] = -2 - iter->second; } if (output != nullptr) newGraph->SaveGraph(output); return ErrorCode::Success; } template <typename T> void RefineNode(VectorIndex* index, const SizeType node, bool updateNeighbors, bool searchDeleted, int CEF) { COMMON::QueryResultSet<T> query((const T*)index->GetSample(node), CEF + 1); void* rec_query = nullptr; if (COMMON::DistanceUtils::Quantizer) { rec_query = _mm_malloc(COMMON::DistanceUtils::Quantizer->ReconstructSize(), ALIGN_SPTAG); COMMON::DistanceUtils::Quantizer->ReconstructVector((const uint8_t*)query.GetTarget(), rec_query); query.SetTarget((T*)rec_query); } index->RefineSearchIndex(query, searchDeleted); RebuildNeighbors(index, node, m_pNeighborhoodGraph[node], query.GetResults(), CEF + 1); if (rec_query) { _mm_free(rec_query); } if (updateNeighbors) { // update neighbors for (int j = 0; j <= CEF; j++) { BasicResult* item = query.GetResult(j); if (item->VID < 0) break; if (item->VID == node) continue; InsertNeighbors(index, item->VID, node, item->Dist); } } } inline std::uint64_t BufferSize() const { return m_pNeighborhoodGraph.BufferSize(); } ErrorCode LoadGraph(std::shared_ptr<Helper::DiskPriorityIO> input, SizeType blockSize, SizeType capacity) { ErrorCode ret = ErrorCode::Success; if ((ret = m_pNeighborhoodGraph.Load(input, blockSize, capacity)) != ErrorCode::Success) return ret; m_iGraphSize = m_pNeighborhoodGraph.R(); m_iNeighborhoodSize = m_pNeighborhoodGraph.C(); return ret; } ErrorCode LoadGraph(std::string sGraphFilename, SizeType blockSize, SizeType capacity) { ErrorCode ret = ErrorCode::Success; if ((ret = m_pNeighborhoodGraph.Load(sGraphFilename, blockSize, capacity)) != ErrorCode::Success) return ret; m_iGraphSize = m_pNeighborhoodGraph.R(); m_iNeighborhoodSize = m_pNeighborhoodGraph.C(); return ret; } ErrorCode LoadGraph(char* pGraphMemFile, SizeType blockSize, SizeType capacity) { ErrorCode ret = ErrorCode::Success; if ((ret = m_pNeighborhoodGraph.Load(pGraphMemFile, blockSize, capacity)) != ErrorCode::Success) return ret; m_iGraphSize = m_pNeighborhoodGraph.R(); m_iNeighborhoodSize = m_pNeighborhoodGraph.C(); return ErrorCode::Success; } ErrorCode SaveGraph(std::string sGraphFilename) const { LOG(Helper::LogLevel::LL_Info, "Save %s To %s\n", m_pNeighborhoodGraph.Name().c_str(), sGraphFilename.c_str()); auto ptr = f_createIO(); if (ptr == nullptr || !ptr->Initialize(sGraphFilename.c_str(), std::ios::binary | std::ios::out)) return ErrorCode::FailedCreateFile; return SaveGraph(ptr); } ErrorCode SaveGraph(std::shared_ptr<Helper::DiskPriorityIO> output) const { IOBINARY(output, WriteBinary, sizeof(SizeType), (char*)&m_iGraphSize); IOBINARY(output, WriteBinary, sizeof(DimensionType), (char*)&m_iNeighborhoodSize); for (int i = 0; i < m_iGraphSize; i++) IOBINARY(output, WriteBinary, sizeof(SizeType) * m_iNeighborhoodSize, (char*)m_pNeighborhoodGraph[i]); LOG(Helper::LogLevel::LL_Info, "Save %s (%d,%d) Finish!\n", m_pNeighborhoodGraph.Name().c_str(), m_iGraphSize, m_iNeighborhoodSize); return ErrorCode::Success; } inline ErrorCode AddBatch(SizeType num) { ErrorCode ret = m_pNeighborhoodGraph.AddBatch(num); if (ret != ErrorCode::Success) return ret; m_iGraphSize += num; return ErrorCode::Success; } inline SizeType* operator[](SizeType index) { return m_pNeighborhoodGraph[index]; } inline const SizeType* operator[](SizeType index) const { return m_pNeighborhoodGraph[index]; } void Update(SizeType row, DimensionType col, SizeType val) { std::lock_guard<std::mutex> lock(m_dataUpdateLock[row]); m_pNeighborhoodGraph[row][col] = val; } inline void SetR(SizeType rows) { m_pNeighborhoodGraph.SetR(rows); m_iGraphSize = rows; } inline SizeType R() const { return m_iGraphSize; } inline std::string Type() const { return m_pNeighborhoodGraph.Name(); } static std::shared_ptr<NeighborhoodGraph> CreateInstance(std::string type); protected: // Graph structure SizeType m_iGraphSize; COMMON::Dataset<SizeType> m_pNeighborhoodGraph; FineGrainedLock m_dataUpdateLock; public: int m_iTPTNumber, m_iTPTLeafSize, m_iSamples, m_numTopDimensionTPTSplit; DimensionType m_iNeighborhoodSize; float m_fNeighborhoodScale, m_fCEFScale, m_fRNGFactor; int m_iRefineIter, m_iCEF, m_iAddCEF, m_iMaxCheckForRefineGraph, m_iGPUGraphType, m_iGPURefineSteps, m_iGPURefineDepth, m_iGPULeafSize, m_iheadNumGPUs, m_iTPTBalanceFactor, m_rebuild; }; } } #endif
pdf_fmt_plug.c
/* PDF cracker patch for JtR. Hacked together during Monsoon of 2012 by * Dhiru Kholia <dhiru.kholia at gmail.com> . * * This software is Copyright (c) 2012, Dhiru Kholia <dhiru.kholia at gmail.com> * * Uses code from Sumatra PDF and MuPDF which are under GPL * * Edited by Shane Quigley 2013 */ #if FMT_EXTERNS_H extern struct fmt_main fmt_pdf; #elif FMT_REGISTERS_H john_register_one(&fmt_pdf); #else #include <string.h> #include "arch.h" #include "params.h" #include "common.h" #include "formats.h" #include "misc.h" #include "md5.h" #include "rc4.h" #include "pdfcrack_md5.h" #include "aes.h" #include "sha2.h" #ifdef _OPENMP #include <omp.h> #ifndef OMP_SCALE #define OMP_SCALE 64 #endif #endif #include "memdbg.h" #define FORMAT_LABEL "PDF" #define FORMAT_NAME "" #define ALGORITHM_NAME "MD5 SHA2 RC4/AES 32/" ARCH_BITS_STR #define BENCHMARK_COMMENT "" #define BENCHMARK_LENGTH -1000 #define PLAINTEXT_LENGTH 32 #define BINARY_SIZE 0 #define SALT_SIZE sizeof(struct custom_salt) #define BINARY_ALIGN 1 #define SALT_ALIGN sizeof(int) #define MIN_KEYS_PER_CRYPT 1 #define MAX_KEYS_PER_CRYPT 1 #if defined (_OPENMP) static int omp_t = 1; #endif static char (*saved_key)[PLAINTEXT_LENGTH + 1]; static int *cracked; static int any_cracked; static size_t cracked_size; static struct custom_salt { int V; int R; int P; char encrypt_metadata; unsigned char u[127]; unsigned char o[127]; unsigned char ue[32]; unsigned char oe[32]; unsigned char id[32]; int length; int length_id; int length_u; int length_o; int length_ue; int length_oe; } *crypt_out; static struct fmt_tests pdf_tests[] = { {"$pdf$4*4*128*-1028*1*16*e03460febe17a048b0adc7f7631bcc56*32*3456205208ad52066d5604018d498a6400000000000000000000000000000000*32*6d598152b22f8fa8085b19a866dce1317f645788a065a74831588a739a579ac4", "openwall"}, {"$pdf$2*3*128*-4*1*16*34b1b6e593787af681a9b63fa8bf563b*32*289ece9b5ce451a5d7064693dab3badf101112131415161718191a1b1c1d1e1f*32*badad1e86442699427116d3e5d5271bc80a27814fc5e80f815efeef839354c5f", "test"}, {"$pdf$4*4*128*-1028*1*16*c015cff8dbf99345ac91c84a45667784*32*0231a4c9cae29b53892874e168cfae9600000000000000000000000000000000*32*137ad7063db5114a66ce1900d47e5cab9c5d7053487d92ac978f54db86eca393", "testpassword"}, {"$pdf$5*6*256*-1028*1*16*05e5abeb21ad2e47adac1c2b2c7b7a31*127*51d3a6a09a675503383e5bc0b53da77ec5d5ea1d1998fb94e00a02a1c2e49313c177905272a4e8e68b382254ec8ed74800000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000*127*dc38f01ef129aae2fca847396465ed518f9c7cf4f2c8cb4399a849d0fe9110227739ab88ddc9a6cf388ae11941270af500000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000*32*b8e137baf316e0789ffa73f888d26495c14d31f2cfff3799e339e2fa078649f5*32*835a9e07461992791914c3d62d37493e07d140937529ab43e26ac2a657152c3c", "testpassword"}, {"$pdf$5*5*256*-1028*1*16*762896ef582ca042a15f380c63ab9f2c*127*8713e2afdb65df1d3801f77a4c4da4905c49495e7103afc2deb06d9fba7949a565143288823871270d9d882075a75da600000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000*127*15d0b992974ff80529e4b616b8c4c79d787705b6c8a9e0f85446498ae2432e0027d8406b57f78b60b11341a0757d7c4a00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000*32*a7a0f3891b469ba7261ce04752dad9c6de0db9c4155c4180e721938a7d9666c7*32*2fa9a0c52badebae2c19dfa7b0005a9cfc909b92babbe7db66a794e96a9f91e3", "openwall"}, /* following are old-style hashes */ {"$pdf$Standard*badad1e86442699427116d3e5d5271bc80a27814fc5e80f815efeef839354c5f*289ece9b5ce451a5d7064693dab3badf101112131415161718191a1b1c1d1e1f*16*34b1b6e593787af681a9b63fa8bf563b*1*1*0*1*4*128*-4*3*2", "test"}, {"$pdf$Standard*9a1156c38ab8177598d1608df7d7e340ae639679bd66bc4cda9bc9a4eedeb170*1f300cd939dd5cf0920c787f12d16be22205e55a5bec5c9c6d563ab4fd0770d7*16*c015cff8dbf99345ac91c84a45667784*1*1*0*1*6*40*-4*2*1", "testpassword"}, {"$pdf$Standard*7303809eaf677bdb5ca64b9d8cb0ccdd47d09a7b28ad5aa522c62685c6d9e499*bf38d7a59daaf38365a338e1fc07976102f1dfd6bdb52072032f57920109b43a*16*c56bbc4145d25b468a873618cd71c2d3*1*1*0*1*6*40*-4*2*1", "test"}, {"$pdf$Standard*137ad7063db5114a66ce1900d47e5cab9c5d7053487d92ac978f54db86eca393*0231a4c9cae29b53892874e168cfae9600000000000000000000000000000000*16*c015cff8dbf99345ac91c84a45667784*1*1*0*1*6*128*-1028*3*2", "testpassword"}, {"$pdf$Standard*d83a8ab680f144dfb2ff2334c206a6060779e007701ab881767f961aecda7984*a5ed4de7e078cb75dfdcd63e8da7a25800000000000000000000000000000000*16*06a7f710cf8dfafbd394540d40984ae2*1*1*0*1*4*128*-1028*3*2", "July2099"}, {"$pdf$Standard*6a80a547b8b8b7636fcc5b322f1c63ce4b670c9b01f2aace09e48d85e1f19f83*e64eb62fc46be66e33571d50a29b464100000000000000000000000000000000*16*14a8c53ffa4a79b3ed9421ef15618420*1*1*0*1*4*128*-1028*3*2", "38r285a9"}, {"$pdf$Standard*2446dd5ed2e18b3ce1ac9b56733226018e3f5c2639051eb1c9b2b215b30bc820*fa3af175d761963c8449ee7015b7770800000000000000000000000000000000*16*12a4da1abe6b7a1ceb84610bad87236d*1*1*0*1*4*128*-1028*3*2", "WHATwhatWHERE?"}, {"$pdf$Standard*e600ecc20288ad8b0d64a929c6a83ee2517679aa0218beceea8b7986726a8cdb*38aca54678d67c003a8193381b0fa1cc101112131415161718191a1b1c1d1e1f*16*1521fbe61419fcad51878cc5d478d5ff*1*1*0*1*4*128*-3904*3*2", ""}, /* CMIYC 2013 "pro" hashes */ {"$pdf$4*4*128*-4*1*16*f7bc2744e1652cf61ca83cac8fccb535*32*f55cc5032f04b985c5aeacde5ec4270f0122456a91bae5134273a6db134c87c4*32*785d891cdcb5efa59893c78f37e7b75acef8924951039b4fa13f62d92bb3b660", "L4sV3g4z"}, {"$pdf$4*4*128*-4*1*16*ec8ea2af2977db1faa4a955904dc956f*32*fc413edb049720b1f8eac87a358faa740122456a91bae5134273a6db134c87c4*32*1ba7aed2f19c77ac6b5061230b62e80b48fc42918f92aef689ceb07d26204991", "ZZt0pr0x"}, {"$pdf$4*4*128*-4*1*16*56761d6da774d8d47387dccf1a84428c*32*640782cab5b7c8f6cf5eab82c38016540122456a91bae5134273a6db134c87c4*32*b5720d5f3d9675a280c6bb8050cbb169e039b578b2de4a42a40dc14765e064cf", "24Le`m0ns"}, {NULL} }; static void init(struct fmt_main *self) { #if defined (_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(sizeof(*saved_key), self->params.max_keys_per_crypt); any_cracked = 0; cracked_size = sizeof(*cracked) * self->params.max_keys_per_crypt; cracked = mem_calloc(sizeof(*cracked), self->params.max_keys_per_crypt); } static void done(void) { MEM_FREE(cracked); MEM_FREE(saved_key); } static int valid(char *ciphertext, struct fmt_main *self) { char *ctcopy, *keeptr; char *p; int res; if (strncmp(ciphertext, "$pdf$", 5) != 0) return 0; ctcopy = strdup(ciphertext); keeptr = ctcopy; ctcopy += 5; if ((p = strtokm(ctcopy, "*")) == NULL) /* V */ goto err; if (!isdec(p)) goto err; if ((p = strtokm(NULL, "*")) == NULL) /* R */ goto err; if (!isdec(p)) goto err; if ((p = strtokm(NULL, "*")) == NULL) /* length */ goto err; if (!isdec(p)) goto err; res = atoi(p); if (res > 256) goto err; if ((p = strtokm(NULL, "*")) == NULL) /* P */ goto err; if (!isdec_negok(p)) goto err; if ((p = strtokm(NULL, "*")) == NULL) /* encrypt_metadata */ goto err; if ((p = strtokm(NULL, "*")) == NULL) /* length_id */ goto err; if (!isdec(p)) goto err; res = atoi(p); if (res > 32) goto err; if ((p = strtokm(NULL, "*")) == NULL) /* id */ goto err; if (strlen(p) != res * 2) goto err; if (!ishexlc(p)) goto err; if ((p = strtokm(NULL, "*")) == NULL) /* length_u */ goto err; if (!isdec(p)) goto err; res = atoi(p); if (res > 127) goto err; if ((p = strtokm(NULL, "*")) == NULL) /* u */ goto err; if (strlen(p) != res * 2) goto err; if (!ishexlc(p)) goto err; if ((p = strtokm(NULL, "*")) == NULL) /* length_o */ goto err; if (!isdec(p)) goto err; res = atoi(p); if (res > 127) goto err; if ((p = strtokm(NULL, "*")) == NULL) /* o */ goto err; if (strlen(p) != res * 2) goto err; if (!ishexlc(p)) goto err; MEM_FREE(keeptr); return 1; err: MEM_FREE(keeptr); return 0; } static int old_valid(char *ciphertext, struct fmt_main *self) { char *ctcopy, *ptr, *keeptr; int res; if (strncmp(ciphertext, "$pdf$Standard*", 14)) return 0; if (!(ctcopy = strdup(ciphertext))) return 0; keeptr = ctcopy; ctcopy += 14; if (!(ptr = strtokm(ctcopy, "*"))) /* o_string */ goto error; if (!ishexlc(ptr)) goto error; if (!(ptr = strtokm(NULL, "*"))) /* u_string */ goto error; if (!ishexlc(ptr)) goto error; if (!(ptr = strtokm(NULL, "*"))) /* fileIDLen */ goto error; if (strncmp(ptr, "16", 2)) goto error; if (!(ptr = strtokm(NULL, "*"))) /* fileID */ goto error; if (!ishexlc(ptr)) goto error; if (!(ptr = strtokm(NULL, "*"))) /* encryptMetaData */ goto error; res = atoi(ptr); if (res != 0 && res != 1) goto error; if (!(ptr = strtokm(NULL, "*"))) /* work_with_user */ goto error; res = atoi(ptr); if (res != 0 && res != 1) goto error; if (!(ptr = strtokm(NULL, "*"))) /* have_userpassword */ goto error; res = atoi(ptr); if (res != 0 && res != 1) goto error; if (!(ptr = strtokm(NULL, "*"))) /* version_major */ goto error; if (!(ptr = strtokm(NULL, "*"))) /* version_minor */ goto error; if (!(ptr = strtokm(NULL, "*"))) /* length */ goto error; res = atoi(ptr); if (res < 0 || res > 256) goto error; if (!(ptr = strtokm(NULL, "*"))) /* permissions */ goto error; if (!(ptr = strtokm(NULL, "*"))) /* revision */ goto error; if (!(ptr = strtokm(NULL, "*"))) /* version */ goto error; MEM_FREE(keeptr); return 1; error: MEM_FREE(keeptr); return 0; } char * convert_old_to_new(char ciphertext[]) { char *ctcopy = strdup(ciphertext); char *keeptr = ctcopy; char *out = mem_alloc_tiny(strlen(ctcopy), MEM_ALIGN_NONE); const char *fields[14]; char *p; int c = 0; p = strtokm(ctcopy, "*"); for (c = 0; c < 14; c++) { fields[c] = p; p = strtokm(NULL, "*"); } strcpy(out,"$pdf$"); strcat(out,fields[13]); strcat(out,"*"); strcat(out,fields[12]); strcat(out,"*"); strcat(out,fields[10]); strcat(out,"*"); strcat(out,fields[11]); strcat(out,"*"); strcat(out,fields[5]); strcat(out,"*"); strcat(out,fields[3]); strcat(out,"*"); strcat(out,fields[4]); strcat(out,"*32*"); strcat(out,fields[2]); strcat(out,"*32*"); strcat(out,fields[1]); MEM_FREE(keeptr); return out; } static char *prepare(char *split_fields[10], struct fmt_main *self) { // if it is the old format if (strncmp(split_fields[1], "$pdf$Standard*", 14) == 0){ if(old_valid(split_fields[1], self)) { char * in_new_format = convert_old_to_new(split_fields[1]); // following line segfaults! // strcpy(split_fields[1], in_new_format); return in_new_format; }else{ //Return something invalid return ""; } } return split_fields[1]; } static void *get_salt(char *ciphertext) { char *ctcopy = strdup(ciphertext); char *keeptr = ctcopy; int i; char *p; static struct custom_salt cs; memset(&cs, 0, sizeof(cs)); ctcopy += 5; /* skip over "$pdf$" marker */ p = strtokm(ctcopy, "*"); cs.V = atoi(p); p = strtokm(NULL, "*"); cs.R = atoi(p); p = strtokm(NULL, "*"); cs.length = atoi(p); p = strtokm(NULL, "*"); cs.P = atoi(p); p = strtokm(NULL, "*"); cs.encrypt_metadata = atoi(p); p = strtokm(NULL, "*"); cs.length_id = atoi(p); p = strtokm(NULL, "*"); for (i = 0; i < cs.length_id; i++) cs.id[i] = atoi16[ARCH_INDEX(p[i * 2])] * 16 + atoi16[ARCH_INDEX(p[i * 2 + 1])]; p = strtokm(NULL, "*"); cs.length_u = atoi(p); p = strtokm(NULL, "*"); for (i = 0; i < cs.length_u; i++) cs.u[i] = atoi16[ARCH_INDEX(p[i * 2])] * 16 + atoi16[ARCH_INDEX(p[i * 2 + 1])]; p = strtokm(NULL, "*"); cs.length_o = atoi(p); p = strtokm(NULL, "*"); for (i = 0; i < cs.length_o; i++) cs.o[i] = atoi16[ARCH_INDEX(p[i * 2])] * 16 + atoi16[ARCH_INDEX(p[i * 2 + 1])]; MEM_FREE(keeptr); return (void *)&cs; } static void set_salt(void *salt) { crypt_out = (struct custom_salt *)salt; } static void pdf_set_key(char *key, int index) { int saved_len = strlen(key); if (saved_len > PLAINTEXT_LENGTH) saved_len = PLAINTEXT_LENGTH; memcpy(saved_key[index], key, saved_len); saved_key[index][saved_len] = 0; } static char *get_key(int index) { return saved_key[index]; } static const unsigned char padding[32] = { 0x28, 0xbf, 0x4e, 0x5e, 0x4e, 0x75, 0x8a, 0x41, 0x64, 0x00, 0x4e, 0x56, 0xff, 0xfa, 0x01, 0x08, 0x2e, 0x2e, 0x00, 0xb6, 0xd0, 0x68, 0x3e, 0x80, 0x2f, 0x0c, 0xa9, 0xfe, 0x64, 0x53, 0x69, 0x7a }; /* Compute an encryption key (PDF 1.7 algorithm 3.2) */ static void pdf_compute_encryption_key(unsigned char *password, int pwlen, unsigned char *key) { unsigned char buf[32]; unsigned int p; int n; MD5_CTX md5; n = crypt_out->length / 8; /* Step 1 - copy and pad password string */ if (pwlen > 32) pwlen = 32; memcpy(buf, password, pwlen); memcpy(buf + pwlen, padding, 32 - pwlen); /* Step 2 - init md5 and pass value of step 1 */ MD5_Init(&md5); MD5_Update(&md5, buf, 32); /* Step 3 - pass O value */ MD5_Update(&md5, crypt_out->o, 32); /* Step 4 - pass P value as unsigned int, low-order byte first */ p = (unsigned int) crypt_out->P; buf[0] = (p) & 0xFF; buf[1] = (p >> 8) & 0xFF; buf[2] = (p >> 16) & 0xFF; buf[3] = (p >> 24) & 0xFF; MD5_Update(&md5, buf, 4); /* Step 5 - pass first element of ID array */ MD5_Update(&md5, crypt_out->id, crypt_out->length_id); /* Step 6 (revision 4 or greater) - if metadata is not encrypted pass 0xFFFFFFFF */ if (crypt_out->R >= 4) { if (!crypt_out->encrypt_metadata) { buf[0] = 0xFF; buf[1] = 0xFF; buf[2] = 0xFF; buf[3] = 0xFF; MD5_Update(&md5, buf, 4); } } /* Step 7 - finish the hash */ MD5_Final(buf, &md5); /* Step 8 (revision 3 or greater) - do some voodoo 50 times */ if (crypt_out->R >= 3) { /* for (i = 0; i < 50; i++) { MD5_Init(&md5); MD5_Update(&md5, buf, n); MD5_Final(buf, &md5); } */ md5_50(buf); } /* Step 9 - the key is the first 'n' bytes of the result */ memcpy(key, buf, n); } /* Compute an encryption key (PDF 1.7 ExtensionLevel 3 algorithm 3.2a) */ static void pdf_compute_encryption_key_r5(unsigned char *password, int pwlen, int ownerkey, unsigned char *validationkey) { unsigned char buffer[128 + 8 + 48]; SHA256_CTX sha256; /* Step 2 - truncate UTF-8 password to 127 characters */ if (pwlen > 127) pwlen = 127; /* Step 3/4 - test password against owner/user key and compute encryption key */ memcpy(buffer, password, pwlen); if (ownerkey) { memcpy(buffer + pwlen, crypt_out->o + 32, 8); memcpy(buffer + pwlen + 8, crypt_out->u, 48); } else memcpy(buffer + pwlen, crypt_out->u + 32, 8); SHA256_Init(&sha256); SHA256_Update(&sha256, buffer, pwlen + 8 + (ownerkey ? 48 : 0)); SHA256_Final(validationkey, &sha256); } /* SumatraPDF: support crypt version 5 revision 6 */ /* * Compute an encryption key (PDF 1.7 ExtensionLevel 8 algorithm 3.2b) * http://esec-lab.sogeti.com/post/The-undocumented-password-validation-algorithm-of-Adobe-Reader-X */ static void pdf_compute_hardened_hash_r6(unsigned char *password, int pwlen, unsigned char salt[8], unsigned char *ownerkey, unsigned char hash[32]) { unsigned char data[(128 + 64 + 48) * 64]; unsigned char block[64]; int block_size = 32; int data_len = 0; int i, j, sum; SHA256_CTX sha256; SHA512_CTX sha384; SHA512_CTX sha512; AES_KEY aes; /* Step 1: calculate initial data block */ SHA256_Init(&sha256); SHA256_Update(&sha256, password, pwlen); SHA256_Update(&sha256, salt, 8); if (ownerkey) SHA256_Update(&sha256, ownerkey, 48); SHA256_Final(block, &sha256); for (i = 0; i < 64 || i < data[data_len * 64 - 1] + 32; i++) { /* Step 2: repeat password and data block 64 times */ memcpy(data, password, pwlen); memcpy(data + pwlen, block, block_size); // ownerkey is always NULL // memcpy(data + pwlen + block_size, ownerkey, ownerkey ? 48 : 0); data_len = pwlen + block_size + (ownerkey ? 48 : 0); for (j = 1; j < 64; j++) memcpy(data + j * data_len, data, data_len); /* Step 3: encrypt data using data block as key and iv */ AES_set_encrypt_key(block, 128, &aes); // aes_crypt_cbc(&aes, AES_ENCRYPT, data_len * 64, block + 16, data, data); AES_cbc_encrypt(data, data, data_len * 64, &aes, block + 16, AES_ENCRYPT); /* Step 4: determine SHA-2 hash size for this round */ for (j = 0, sum = 0; j < 16; j++) sum += data[j]; /* Step 5: calculate data block for next round */ block_size = 32 + (sum % 3) * 16; switch (block_size) { case 32: SHA256_Init(&sha256); SHA256_Update(&sha256, data, data_len * 64); SHA256_Final(block, &sha256); break; case 48: SHA384_Init(&sha384); SHA384_Update(&sha384, data, data_len * 64); SHA384_Final(block, &sha384); break; case 64: SHA512_Init(&sha512); SHA512_Update(&sha512, data, data_len * 64); SHA512_Final(block, &sha512); break; } } memset(data, 0, sizeof(data)); memcpy(hash, block, 32); } /* Computing the user password (PDF 1.7 algorithm 3.4 and 3.5) */ static void pdf_compute_user_password(unsigned char *password, unsigned char *output) { int pwlen = strlen((char*)password); unsigned char key[128]; if (crypt_out->R == 2) { RC4_KEY arc4; int n; n = crypt_out->length / 8; pdf_compute_encryption_key(password, pwlen, key); RC4_set_key(&arc4, n, key); RC4(&arc4, 32, padding, output); } if (crypt_out->R == 3 || crypt_out->R == 4) { unsigned char xor[32]; unsigned char digest[16]; MD5_CTX md5; RC4_KEY arc4; int i, x, n; n = crypt_out->length / 8; pdf_compute_encryption_key(password, pwlen, key); MD5_Init(&md5); MD5_Update(&md5, (char*)padding, 32); MD5_Update(&md5, crypt_out->id, crypt_out->length_id); MD5_Final(digest, &md5); RC4_set_key(&arc4, n, key); RC4(&arc4, 16, digest, output); for (x = 1; x <= 19; x++) { for (i = 0; i < n; i++) xor[i] = key[i] ^ x; RC4_set_key(&arc4, n, xor); RC4(&arc4, 16, output, output); } memcpy(output + 16, padding, 16); } if (crypt_out->R == 5) { pdf_compute_encryption_key_r5(password, pwlen, 0, output); } /* SumatraPDF: support crypt version 5 revision 6 */ if (crypt_out->R == 6) pdf_compute_hardened_hash_r6(password, pwlen, crypt_out->u + 32, NULL, output); } static int crypt_all(int *pcount, struct db_salt *salt) { const int count = *pcount; int index = 0; if (any_cracked) { memset(cracked, 0, cracked_size); any_cracked = 0; } #ifdef _OPENMP #pragma omp parallel for for (index = 0; index < count; index++) #endif { #if !defined(_OPENMP) && defined (__CYGWIN32__) && defined (MEMDBG_ON) static /* work around for some 'unknown' bug in cygwin gcc when using memdbg.h code. I have NO explanation, JimF. */ #endif unsigned char output[32]; pdf_compute_user_password((unsigned char*)saved_key[index], output); if (crypt_out->R == 2 || crypt_out->R == 5 || crypt_out->R == 6) if(memcmp(output, crypt_out->u, 32) == 0) { cracked[index] = 1; #ifdef _OPENMP #pragma omp atomic #endif any_cracked |= 1; } if (crypt_out->R == 3 || crypt_out->R == 4) if(memcmp(output, crypt_out->u, 16) == 0) { cracked[index] = 1; #ifdef _OPENMP #pragma omp atomic #endif any_cracked |= 1; } } return count; } static int cmp_all(void *binary, int count) { return any_cracked; } static int cmp_one(void *binary, int index) { return cracked[index]; } static int cmp_exact(char *source, int index) { return cracked[index]; } /* * Report revision as tunable cost, since between revisions 2 and 6, * only revisions 3 and 4 seem to have a similar c/s rate. */ static unsigned int pdf_revision(void *salt) { struct custom_salt *my_salt; my_salt = salt; return (unsigned int) my_salt->R; } struct fmt_main fmt_pdf = { { 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, { "revision", }, pdf_tests }, { init, done, fmt_default_reset, prepare, valid, fmt_default_split, fmt_default_binary, get_salt, { pdf_revision, }, fmt_default_source, { fmt_default_binary_hash }, fmt_default_salt_hash, NULL, set_salt, pdf_set_key, get_key, fmt_default_clear_keys, crypt_all, { fmt_default_get_hash }, cmp_all, cmp_one, cmp_exact } }; #endif /* plugin stanza */
advectionMain.c
/* The MIT License (MIT) Copyright (c) 2017 Tim Warburton, Noel Chalmers, Jesse Chan, Ali Karakus 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. */ #include "advection.h" int main(int argc, char **argv){ // start up MPI MPI_Init(&argc, &argv); if(argc!=2){ printf("usage2: ./advectionMain setupfile\n"); exit(-1); } // if argv > 2 then should load input data from argv setupAide newOptions(argv[1]); // set up mesh stuff string fileName; int N, dim, elementType; newOptions.getArgs("MESH FILE", fileName); newOptions.getArgs("POLYNOMIAL DEGREE", N); newOptions.getArgs("ELEMENT TYPE", elementType); newOptions.getArgs("MESH DIMENSION", dim); dfloat tol = 1e-8; newOptions.getArgs("MASS MATRIX TOLERANCE", tol); // set up mesh mesh_t *mesh; switch(elementType){ case TRIANGLES: case TETRAHEDRA: printf("Triangles and tetrahedra are not currently supported for this code, exiting ...\n"); exit(-1); case QUADRILATERALS: mesh = meshSetupQuad2D((char*)fileName.c_str(), N); break; case HEXAHEDRA: mesh = meshSetupHex3D((char*)fileName.c_str(), N); break; } if(elementType==HEXAHEDRA){ /* rescale to unit box and transform */ hlong allNelements = mesh->Nelements+mesh->totalHaloPairs; for(int n=0;n<allNelements*mesh->Np;++n){ mesh->x[n] = 0.5*(mesh->x[n]+1); mesh->y[n] = 0.5*(mesh->y[n]+1); mesh->z[n] = 0.5*(mesh->z[n]+1); } // compute geometric factors meshGeometricFactorsHex3D(mesh); meshSurfaceGeometricFactorsHex3D(mesh); } char *boundaryHeaderFileName; // could sprintf if(dim==2) boundaryHeaderFileName = strdup(DADVECTION "/advectionBox2D.h"); // default if(dim==3) boundaryHeaderFileName = strdup(DADVECTION "/advectionBox3D.h"); // default // set up advection stuff advection_t *advection = advectionSetup(mesh, newOptions, boundaryHeaderFileName); // test mass matrix inversion dfloat *diagInvMassMatrix = (dfloat*) calloc(mesh->Np*mesh->Nelements, sizeof(dfloat)); dfloat *cubInterpRowSums = (dfloat*) calloc(mesh->cubNq, sizeof(dfloat)); for(int a=0;a<mesh->cubNq;++a){ for(int i=0;i<mesh->Nq;++i){ cubInterpRowSums[a] += mesh->cubInterp[a*mesh->Nq+i]; } } #pragma omp parallel for for(int e=0;e<mesh->Nelements;++e){ #if 0 for(int n=0;n<mesh->Np;++n){ diagInvMassMatrix[n+e*mesh->Np] = 1./mesh->vgeo[n + e*mesh->Np*mesh->Nvgeo + JWID*mesh->Np]; } #else for(int k=0;k<mesh->Nq;++k){ for(int j=0;j<mesh->Nq;++j){ for(int i=0;i<mesh->Nq;++i){ int id = i + j*mesh->Nq + k*mesh->Nq*mesh->Nq; dfloat res = 0; for(int c=0;c<mesh->cubNq;++c){ for(int b=0;b<mesh->cubNq;++b){ for(int a=0;a<mesh->cubNq;++a){ hlong cid = a + b*mesh->cubNq + c*mesh->cubNq*mesh->cubNq; dfloat JW = mesh->cubvgeo[mesh->Nvgeo*mesh->cubNp*e + cid + JWID*mesh->cubNp]; res += JW*mesh->cubInterp[i+mesh->Nq*a]*cubInterpRowSums[a] *mesh->cubInterp[j+mesh->Nq*b]*cubInterpRowSums[b] *mesh->cubInterp[k+mesh->Nq*c]*cubInterpRowSums[c]; } } } diagInvMassMatrix[id + e*mesh->Np] = 1./res; } } } #endif } int *iterations = (int*) calloc(mesh->Nelements, sizeof(int)); dfloat *residuals = (dfloat*) calloc(mesh->Nelements, sizeof(dfloat)); advection->o_diagInvMassMatrix = mesh->device.malloc(mesh->Np*mesh->Nelements*sizeof(dfloat), diagInvMassMatrix); #if 0 occa::memory o_qnew = mesh->device.malloc(mesh->Nelements*mesh->Np*sizeof(dfloat), iterations); occa::memory o_iterations = mesh->device.malloc(mesh->Nelements*sizeof(int), iterations); occa::memory o_residuals = mesh->device.malloc(mesh->Nelements*sizeof(dfloat), residuals); for(int n=0;n<mesh->Np*mesh->Nelements;++n){ advection->rhsq[n] = sin(M_PI*mesh->x[n])*sin(M_PI*mesh->y[n])*sin(M_PI*mesh->z[n]); // drand48(); } advection->o_rhsq.copyFrom(advection->rhsq); int maxIterations = 3; mesh->device.finish(); #if 0 for(int test=0;test<10;++test) advection->invertMassMatrixKernel(mesh->Nelements, tol, maxIterations, mesh->o_cubvgeo, mesh->o_cubInterpT, advection->o_diagInvMassMatrix, advection->o_rhsq, advection->o_q, o_iterations); #else for(int test=0;test<10;++test) advection->invertMassMatrixKernel(mesh->NinternalElements, mesh->o_internalElementIds, mesh->dt, mesh->rka[0], mesh->rkb[0], tol, maxIterations, mesh->o_cubvgeo, mesh->o_cubInterpT, advection->o_diagInvMassMatrix, advection->o_rhsq, advection->o_resq, advection->o_q, o_qnew, o_iterations); #endif mesh->device.finish(); o_iterations.copyTo(iterations); o_residuals.copyTo(residuals); for(hlong e=0;e<50;++e){ printf("element %d took %d iterations to reach residual^2 of %17.15lg\n", e, iterations[e], residuals[e]); } mesh->device.finish(); MPI_Finalize(); exit(-1); #endif mesh->device.finish(); MPI_Barrier(MPI_COMM_WORLD); mesh->device.finish(); #if 0 occa::streamTag start = mesh->device.tagStream(); int rk = 0, Nsteps = 50; for(int test=0;test<Nsteps;++test) advection->invertMassMatrixCombinedKernel(mesh->NinternalElements, mesh->o_internalElementIds, mesh->dt, mesh->rka[rk], mesh->rkb[rk], mesh->o_vgeo, mesh->o_Dmatrices, advection->o_advectionVelocityJW, mesh->o_vmapM, mesh->o_vmapP, advection->o_advectionVelocityM, advection->o_advectionVelocityP, mesh->o_cubvgeo, mesh->o_cubInterpT, advection->o_diagInvMassMatrix, tol, maxIterations, advection->o_resq, advection->o_q, advection->o_qtmp0); occa::streamTag end = mesh->device.tagStream(); mesh->device.finish(); double elapsed = mesh->device.timeBetween(start, end); printf("%d %d %d %lg %lg %lg %lg %lg \%\%[ MMDG: N, Nel, Nodes, elapsed, time/step, nodes/time, gnodes*Nsteps/time, gnodes*Nstages*Nsteps/time, %s ]\n", mesh->N, mesh->Nelements, mesh->Np*mesh->Nelements, elapsed, elapsed/Nsteps, (1.*mesh->Np*mesh->Nelements)/(elapsed), (1.*mesh->Np*mesh->Nelements*Nsteps)/(1.e9*elapsed), (1.*mesh->Np*mesh->Nelements*Nsteps)/(1.e9*elapsed), newOptions.getArgs("ADVECTION FORMULATION").c_str() ); #endif // run advectionRun(advection, newOptions); mesh->device.finish(); // close down MPI MPI_Finalize(); exit(0); return 0; }
run_fft_omp.c
#include "fft.h" #include <omp.h> #define MASTER 0 #define NTHREADS 8 int main(int argc, char* argv[]) { int_t len = 0, reps = 0; #ifdef N len = (int_t) N; #else if(argc > 1) { len = (int_t) atoi(argv[1]); } else { fprintf(stderr, "ERROR: N is undefined and the input length is not submitted.\n"); return EXIT_FAILURE; } #endif #ifdef R reps = (int_t) R; #else if(argc > 2) { reps = (int_t) atoi(argv[2]); } else { fprintf(stderr, "ERROR: R is undefined and number of repetitions is not submitted.\n"); return EXIT_FAILURE; } #endif #pragma omp parallel // num_threads(NTHREADS) proc_bind(spread) { /* doubles used for time measurement */ double t1 = 0.0, t2 = 0.0, total1 = 0.0, total2 = 0.0; int tid = omp_get_thread_num(); if(tid == MASTER) { t1 = get_time(); } struct ft_data_t *data = malloc(sizeof(struct ft_data_t)); /* initialisation (N is passed via external define) */ /* WARNING: CHECK THE LENGTH (N) - SHOULD BE A POWER OF TWO !!! */ /* TODO: implement an "and"-reduction to ensure that all threads have initialised their data properly */ if(init(data, len) == EXIT_SUCCESS) { /* generate input data */ setdist_c(data->inout_c, data->len); if(tid == MASTER) { t2 = get_time(); printf("compiler: %s, problem size: %lu (elements) with real_t = %lu bytes, iterations: %lu\n", COMPILER, (unsigned long) data->len, sizeof(real_t), (unsigned long) reps); printf("init: %.16f\n", t2 - t1); /* convert complex to real and print original signal */ #ifdef PRINT_RESULTS char *f_o = "out/fft_original.txt"; c2r(data->inout_c, data->in_r, data->len); PRINTR(data->in_r, data->len, f_o); #endif total1 = get_time(); } /* precomputing the factors for the fft */ precalc(data->factors, data->len); /* running fft - shuffle, fft, shuffle, i-fft, normalisation */ #pragma omp for for(int_t i = 0; i < reps; ++i) { t1 = get_time(); shuffle2(data->inout_c, data->len, data->bitlen); #ifdef FFT_IN_PLACE fft(data->inout_c, data->factors, data->len, FT_FOR); shuffle2(data->inout_c, data->len, data->bitlen); fft(data->inout_c, data->factors, data->len, FT_BAK); #else fft(data->inout_c, data->inout2_c, data->factors, data->len, FT_FOR); shuffle2(data->inout2_c, data->len, data->bitlen); fft(data->inout2_c, data->inout_c, data->factors, data->len, FT_BAK); #endif /* FFT_IN_PLACE */ norm_c(data->inout_c, data->len, data->len); t2 = get_time(); } printf("tid: %lu, time: %.16f\n", (unsigned long)tid, (t2 - t1)); if(tid == MASTER) { total2 = get_time(); printf("total fft runtime: %.16f\n", (total2 - total1)); /* convert complex data back to real for restored signal */ #ifdef PRINT_RESULTS char *f_r = "out/fft_restored.txt"; c2r(data->inout_c, data->out_r, data->len); PRINTR(data->out_r, data->len, f_r); #endif } } /* end of init - success */ else { fprintf(stderr, "ERROR: thread %d has failed initialisation.\n", tid); } /* finalise */ cleanup(data); free(data); } /* omp parallel */ return EXIT_SUCCESS; }
hello-1.c
/* * test the simplest case, no variable handling By C. Liao */ #include <stdio.h> #ifdef _OPENMP #include <omp.h> #endif int main(void) { #pragma omp parallel { printf("Hello,world!"); } return 0; }
countsort-parallel.c
#include <omp.h> #include <stdio.h> #include <stdlib.h> #include <string.h> /// Function that sorts a vector `a` of size `n` double count_sort(double a[], int n, int nt) { int i, j, count; double *temp; double start, end, duracao; temp = (double *)malloc(n * sizeof(double)); start = omp_get_wtime(); #pragma omp parallel for num_threads(nt) \ default(none) private(count, i, j) shared(a, n, temp) for (i = 0; i < n; i++) { count = 0; for (j = 0; j < n; j++) if ((a[j] < a[i]) || ((a[j] == a[i]) && (j < i))) count++; temp[count] = a[i]; } end = omp_get_wtime(); duracao = end - start; memcpy(a, temp, n * sizeof(double)); free(temp); return duracao; } int main(int argc, char *argv[]) { int i, n, nt; double *a, t_s; FILE *input; if (argc < 2) { fprintf(stderr, "Error: missing path to input file\n"); return 1; } if ((input = fopen(argv[1], "r")) == NULL) { fprintf(stderr, "Error: could not open file\n"); return 1; } fscanf(input, "%d", &nt); // Read the number of elements fscanf(input, "%d", &n); // Do not change this line omp_set_num_threads(nt); // Allocate the vector to be ordered a = (double *)malloc(n * sizeof(double)); // Populate the vector for (i = 0; i < n; i++) fscanf(input, "%lf", &a[i]); // Execute Counting Sort t_s = count_sort(a, n, nt); // Print the ordered vector for (i = 0; i < n; i++) printf("%.2lf ", a[i]); printf("\n"); // Print the time it took to sort fprintf(stderr, "%lf\n", t_s); return 0; }
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
blas.c
#include "blas.h" #include "utils.h" #include <math.h> #include <assert.h> #include <float.h> #include <stdio.h> #include <stdlib.h> #include <string.h> void reorg_cpu(float *x, int out_w, int out_h, int out_c, int batch, int stride, int forward, float *out) { int b,i,j,k; int in_c = out_c/(stride*stride); //printf("\n out_c = %d, out_w = %d, out_h = %d, stride = %d, forward = %d \n", out_c, out_w, out_h, stride, forward); //printf(" in_c = %d, in_w = %d, in_h = %d \n", in_c, out_w*stride, out_h*stride); for(b = 0; b < batch; ++b){ for(k = 0; k < out_c; ++k){ for(j = 0; j < out_h; ++j){ for(i = 0; i < out_w; ++i){ int in_index = i + out_w*(j + out_h*(k + out_c*b)); int c2 = k % in_c; int offset = k / in_c; int w2 = i*stride + offset % stride; int h2 = j*stride + offset / stride; int out_index = w2 + out_w*stride*(h2 + out_h*stride*(c2 + in_c*b)); if(forward) out[out_index] = x[in_index]; // used by default for forward (i.e. forward = 0) else out[in_index] = x[out_index]; } } } } } void flatten(float *x, int size, int layers, int batch, int forward) { float* swap = (float*)xcalloc(size * layers * batch, sizeof(float)); int i,c,b; for(b = 0; b < batch; ++b){ for(c = 0; c < layers; ++c){ for(i = 0; i < size; ++i){ int i1 = b*layers*size + c*size + i; int i2 = b*layers*size + i*layers + c; if (forward) swap[i2] = x[i1]; else swap[i1] = x[i2]; } } } memcpy(x, swap, size*layers*batch*sizeof(float)); free(swap); } void weighted_sum_cpu(float *a, float *b, float *s, int n, float *c) { int i; for(i = 0; i < n; ++i){ c[i] = s[i]*a[i] + (1-s[i])*(b ? b[i] : 0); } } void weighted_delta_cpu(float *a, float *b, float *s, float *da, float *db, float *ds, int n, float *dc) { int i; for(i = 0; i < n; ++i){ if(da) da[i] += dc[i] * s[i]; if(db) db[i] += dc[i] * (1-s[i]); ds[i] += dc[i] * (a[i] - b[i]); } } static float relu(float src) { if (src > 0) return src; return 0; } void shortcut_multilayer_cpu(int size, int src_outputs, int batch, int n, int *outputs_of_layers, float **layers_output, float *out, float *in, float *weights, int nweights, WEIGHTS_NORMALIZATION_T weights_normalization) { // nweights - l.n or l.n*l.c or (l.n*l.c*l.h*l.w) const int layer_step = nweights / (n + 1); // 1 or l.c or (l.c * l.h * l.w) int step = 0; if (nweights > 0) step = src_outputs / layer_step; // (l.c * l.h * l.w) or (l.w*l.h) or 1 int id; #pragma omp parallel for for (id = 0; id < size; ++id) { int src_id = id; const int src_i = src_id % src_outputs; src_id /= src_outputs; int src_b = src_id; float sum = 1, max_val = -FLT_MAX; int i; if (weights && weights_normalization) { if (weights_normalization == SOFTMAX_NORMALIZATION) { for (i = 0; i < (n + 1); ++i) { const int weights_index = src_i / step + i*layer_step; // [0 or c or (c, h ,w)] float w = weights[weights_index]; if (max_val < w) max_val = w; } } const float eps = 0.0001; sum = eps; for (i = 0; i < (n + 1); ++i) { const int weights_index = src_i / step + i*layer_step; // [0 or c or (c, h ,w)] const float w = weights[weights_index]; if (weights_normalization == RELU_NORMALIZATION) sum += relu(w); else if (weights_normalization == SOFTMAX_NORMALIZATION) sum += expf(w - max_val); } } if (weights) { float w = weights[src_i / step]; if (weights_normalization == RELU_NORMALIZATION) w = relu(w) / sum; else if (weights_normalization == SOFTMAX_NORMALIZATION) w = expf(w - max_val) / sum; out[id] = in[id] * w; // [0 or c or (c, h ,w)] } else out[id] = in[id]; // layers for (i = 0; i < n; ++i) { int add_outputs = outputs_of_layers[i]; if (src_i < add_outputs) { int add_index = add_outputs*src_b + src_i; int out_index = id; float *add = layers_output[i]; if (weights) { const int weights_index = src_i / step + (i + 1)*layer_step; // [0 or c or (c, h ,w)] float w = weights[weights_index]; if (weights_normalization == RELU_NORMALIZATION) w = relu(w) / sum; else if (weights_normalization == SOFTMAX_NORMALIZATION) w = expf(w - max_val) / sum; out[out_index] += add[add_index] * w; // [0 or c or (c, h ,w)] } else out[out_index] += add[add_index]; } } } } void backward_shortcut_multilayer_cpu(int size, int src_outputs, int batch, int n, int *outputs_of_layers, float **layers_delta, float *delta_out, float *delta_in, float *weights, float *weight_updates, int nweights, float *in, float **layers_output, WEIGHTS_NORMALIZATION_T weights_normalization) { // nweights - l.n or l.n*l.c or (l.n*l.c*l.h*l.w) const int layer_step = nweights / (n + 1); // 1 or l.c or (l.c * l.h * l.w) int step = 0; if (nweights > 0) step = src_outputs / layer_step; // (l.c * l.h * l.w) or (l.w*l.h) or 1 int id; #pragma omp parallel for for (id = 0; id < size; ++id) { int src_id = id; int src_i = src_id % src_outputs; src_id /= src_outputs; int src_b = src_id; float grad = 1, sum = 1, max_val = -FLT_MAX;; int i; if (weights && weights_normalization) { if (weights_normalization == SOFTMAX_NORMALIZATION) { for (i = 0; i < (n + 1); ++i) { const int weights_index = src_i / step + i*layer_step; // [0 or c or (c, h ,w)] float w = weights[weights_index]; if (max_val < w) max_val = w; } } const float eps = 0.0001; sum = eps; for (i = 0; i < (n + 1); ++i) { const int weights_index = src_i / step + i*layer_step; // [0 or c or (c, h ,w)] const float w = weights[weights_index]; if (weights_normalization == RELU_NORMALIZATION) sum += relu(w); else if (weights_normalization == SOFTMAX_NORMALIZATION) sum += expf(w - max_val); } /* grad = 0; for (i = 0; i < (n + 1); ++i) { const int weights_index = src_i / step + i*layer_step; // [0 or c or (c, h ,w)] const float delta_w = delta_in[id] * in[id]; const float w = weights[weights_index]; if (weights_normalization == RELU_NORMALIZATION) grad += delta_w * relu(w) / sum; else if (weights_normalization == SOFTMAX_NORMALIZATION) grad += delta_w * expf(w - max_val) / sum; } */ } if (weights) { float w = weights[src_i / step]; if (weights_normalization == RELU_NORMALIZATION) w = relu(w) / sum; else if (weights_normalization == SOFTMAX_NORMALIZATION) w = expf(w - max_val) / sum; delta_out[id] += delta_in[id] * w; // [0 or c or (c, h ,w)] weight_updates[src_i / step] += delta_in[id] * in[id] * grad; } else delta_out[id] += delta_in[id]; // layers for (i = 0; i < n; ++i) { int add_outputs = outputs_of_layers[i]; if (src_i < add_outputs) { int add_index = add_outputs*src_b + src_i; int out_index = id; float *layer_delta = layers_delta[i]; if (weights) { float *add = layers_output[i]; const int weights_index = src_i / step + (i + 1)*layer_step; // [0 or c or (c, h ,w)] float w = weights[weights_index]; if (weights_normalization == RELU_NORMALIZATION) w = relu(w) / sum; else if (weights_normalization == SOFTMAX_NORMALIZATION) w = expf(w - max_val) / sum; layer_delta[add_index] += delta_in[id] * w; // [0 or c or (c, h ,w)] weight_updates[weights_index] += delta_in[id] * add[add_index] * grad; } else layer_delta[add_index] += delta_in[id]; } } } } void shortcut_cpu(int batch, int w1, int h1, int c1, float *add, int w2, int h2, int c2, float *out) { int stride = w1/w2; int sample = w2/w1; assert(stride == h1/h2); assert(sample == h2/h1); if(stride < 1) stride = 1; if(sample < 1) sample = 1; int minw = (w1 < w2) ? w1 : w2; int minh = (h1 < h2) ? h1 : h2; int minc = (c1 < c2) ? c1 : c2; int i,j,k,b; for(b = 0; b < batch; ++b){ for(k = 0; k < minc; ++k){ for(j = 0; j < minh; ++j){ for(i = 0; i < minw; ++i){ int out_index = i*sample + w2*(j*sample + h2*(k + c2*b)); int add_index = i*stride + w1*(j*stride + h1*(k + c1*b)); out[out_index] += add[add_index]; } } } } } void mean_cpu(float *x, int batch, int filters, int spatial, float *mean) { float scale = 1./(batch * spatial); int i,j,k; for(i = 0; i < filters; ++i){ mean[i] = 0; for(j = 0; j < batch; ++j){ for(k = 0; k < spatial; ++k){ int index = j*filters*spatial + i*spatial + k; mean[i] += x[index]; } } mean[i] *= scale; } } void variance_cpu(float *x, float *mean, int batch, int filters, int spatial, float *variance) { float scale = 1./(batch * spatial - 1); int i,j,k; for(i = 0; i < filters; ++i){ variance[i] = 0; for(j = 0; j < batch; ++j){ for(k = 0; k < spatial; ++k){ int index = j*filters*spatial + i*spatial + k; variance[i] += pow((x[index] - mean[i]), 2); } } variance[i] *= scale; } } void normalize_cpu(float *x, float *mean, float *variance, int batch, int filters, int spatial) { int b, f, i; for(b = 0; b < batch; ++b){ for(f = 0; f < filters; ++f){ for(i = 0; i < spatial; ++i){ int index = b*filters*spatial + f*spatial + i; x[index] = (x[index] - mean[f])/(sqrt(variance[f] + .000001f)); } } } } void const_cpu(int N, float ALPHA, float *X, int INCX) { int i; for(i = 0; i < N; ++i) X[i*INCX] = ALPHA; } void mul_cpu(int N, float *X, int INCX, float *Y, int INCY) { int i; for(i = 0; i < N; ++i) Y[i*INCY] *= X[i*INCX]; } void pow_cpu(int N, float ALPHA, float *X, int INCX, float *Y, int INCY) { int i; for(i = 0; i < N; ++i) Y[i*INCY] = pow(X[i*INCX], ALPHA); } void axpy_cpu(int N, float ALPHA, float *X, int INCX, float *Y, int INCY) { int i; for(i = 0; i < N; ++i) Y[i*INCY] += ALPHA*X[i*INCX]; } void scal_cpu(int N, float ALPHA, float *X, int INCX) { int i; for(i = 0; i < N; ++i) X[i*INCX] *= ALPHA; } void scal_add_cpu(int N, float ALPHA, float BETA, float *X, int INCX) { int i; for (i = 0; i < N; ++i) X[i*INCX] = X[i*INCX] * ALPHA + BETA; } void fill_cpu(int N, float ALPHA, float *X, int INCX) { int i; if (INCX == 1 && ALPHA == 0) { memset(X, 0, N * sizeof(float)); } else { for (i = 0; i < N; ++i) X[i*INCX] = ALPHA; } } void deinter_cpu(int NX, float *X, int NY, float *Y, int B, float *OUT) { int i, j; int index = 0; for(j = 0; j < B; ++j) { for(i = 0; i < NX; ++i){ if(X) X[j*NX + i] += OUT[index]; ++index; } for(i = 0; i < NY; ++i){ if(Y) Y[j*NY + i] += OUT[index]; ++index; } } } void inter_cpu(int NX, float *X, int NY, float *Y, int B, float *OUT) { int i, j; int index = 0; for(j = 0; j < B; ++j) { for(i = 0; i < NX; ++i){ OUT[index++] = X[j*NX + i]; } for(i = 0; i < NY; ++i){ OUT[index++] = Y[j*NY + i]; } } } void copy_cpu(int N, float *X, int INCX, float *Y, int INCY) { int i; for(i = 0; i < N; ++i) Y[i*INCY] = X[i*INCX]; } void mult_add_into_cpu(int N, float *X, float *Y, float *Z) { int i; for(i = 0; i < N; ++i) Z[i] += X[i]*Y[i]; } void smooth_l1_cpu(int n, float *pred, float *truth, float *delta, float *error) { int i; for(i = 0; i < n; ++i){ float diff = truth[i] - pred[i]; float abs_val = fabs(diff); if(abs_val < 1) { error[i] = diff * diff; delta[i] = diff; } else { error[i] = 2*abs_val - 1; delta[i] = (diff > 0) ? 1 : -1; } } } void l1_cpu(int n, float *pred, float *truth, float *delta, float *error) { int i; for(i = 0; i < n; ++i){ float diff = truth[i] - pred[i]; error[i] = fabs(diff); delta[i] = diff > 0 ? 1 : -1; } } void softmax_x_ent_cpu(int n, float *pred, float *truth, float *delta, float *error) { int i; for(i = 0; i < n; ++i){ float t = truth[i]; float p = pred[i]; error[i] = (t) ? -log(p) : 0; delta[i] = t-p; } } void logistic_x_ent_cpu(int n, float *pred, float *truth, float *delta, float *error) { int i; for(i = 0; i < n; ++i){ float t = truth[i]; float p = pred[i]; error[i] = -t*log(p) - (1-t)*log(1-p); delta[i] = t-p; } } void l2_cpu(int n, float *pred, float *truth, float *delta, float *error) { int i; for(i = 0; i < n; ++i){ float diff = truth[i] - pred[i]; error[i] = diff * diff; delta[i] = diff; } } float dot_cpu(int N, float *X, int INCX, float *Y, int INCY) { int i; float dot = 0; for(i = 0; i < N; ++i) dot += X[i*INCX] * Y[i*INCY]; return dot; } void softmax(float *input, int n, float temp, float *output, int stride) { int i; float sum = 0; float largest = -FLT_MAX; for(i = 0; i < n; ++i){ if(input[i*stride] > largest) largest = input[i*stride]; } for(i = 0; i < n; ++i){ float e = exp(input[i*stride]/temp - largest/temp); sum += e; output[i*stride] = e; } for(i = 0; i < n; ++i){ output[i*stride] /= sum; } } void softmax_cpu(float *input, int n, int batch, int batch_offset, int groups, int group_offset, int stride, float temp, float *output) { int g, b; for(b = 0; b < batch; ++b){ for(g = 0; g < groups; ++g){ softmax(input + b*batch_offset + g*group_offset, n, temp, output + b*batch_offset + g*group_offset, stride); } } } void upsample_cpu(float *in, int w, int h, int c, int batch, int stride, int forward, float scale, float *out) { int i, j, k, b; for (b = 0; b < batch; ++b) { for (k = 0; k < c; ++k) { for (j = 0; j < h*stride; ++j) { for (i = 0; i < w*stride; ++i) { int in_index = b*w*h*c + k*w*h + (j / stride)*w + i / stride; int out_index = b*w*h*c*stride*stride + k*w*h*stride*stride + j*w*stride + i; if (forward) out[out_index] = scale*in[in_index]; else in[in_index] += scale*out[out_index]; } } } } } void constrain_cpu(int size, float ALPHA, float *X) { int i; for (i = 0; i < size; ++i) { X[i] = fminf(ALPHA, fmaxf(-ALPHA, X[i])); } } void fix_nan_and_inf_cpu(float *input, size_t size) { int i; for (i = 0; i < size; ++i) { float val = input[i]; if (isnan(val) || isinf(val)) input[i] = 1.0f / i; // pseudo random value } }
BsplineFunctor.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: John R. Gergely, University of Illinois at Urbana-Champaign // Ken Esler, kpesler@gmail.com, University of Illinois at Urbana-Champaign // Miguel Morales, moralessilva2@llnl.gov, Lawrence Livermore National Laboratory // Raymond Clay III, j.k.rofling@gmail.com, Lawrence Livermore National Laboratory // 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 // Amrita Mathuriya, amrita.mathuriya@intel.com, Intel Corp. // // File created by: Ken Esler, kpesler@gmail.com, University of Illinois at Urbana-Champaign ////////////////////////////////////////////////////////////////////////////////////// #ifndef QMCPLUSPLUS_BSPLINE_FUNCTOR_H #define QMCPLUSPLUS_BSPLINE_FUNCTOR_H #include "Numerics/OptimizableFunctorBase.h" #include "Utilities/ProgressReportEngine.h" #include "OhmmsData/AttributeSet.h" #include "Numerics/LinearFit.h" #include "CPU/SIMD/aligned_allocator.hpp" #include <cstdio> namespace qmcplusplus { template<class T> struct BsplineFunctor : public OptimizableFunctorBase { typedef real_type value_type; int NumParams; int Dummy; const real_type A[16], dA[16], d2A[16], d3A[16]; aligned_vector<real_type> SplineCoefs; //static const real_type A[16], dA[16], d2A[16]; real_type DeltaR, DeltaRInv; real_type CuspValue; real_type Y, dY, d2Y; // Stores the derivatives w.r.t. SplineCoefs // of the u, du/dr, and d2u/dr2 std::vector<TinyVector<real_type, 3>> SplineDerivs; std::vector<real_type> Parameters; std::vector<std::string> ParameterNames; std::string elementType, pairType; std::string fileName; int ResetCount; bool notOpt; bool periodic; ///constructor BsplineFunctor(real_type cusp = 0.0) : NumParams(0), A{-1.0 / 6.0, 3.0 / 6.0, -3.0 / 6.0, 1.0 / 6.0, 3.0 / 6.0, -6.0 / 6.0, 0.0 / 6.0, 4.0 / 6.0, -3.0 / 6.0, 3.0 / 6.0, 3.0 / 6.0, 1.0 / 6.0, 1.0 / 6.0, 0.0 / 6.0, 0.0 / 6.0, 0.0 / 6.0}, dA{0.0, -0.5, 1.0, -0.5, 0.0, 1.5, -2.0, 0.0, 0.0, -1.5, 1.0, 0.5, 0.0, 0.5, 0.0, 0.0}, d2A{0.0, 0.0, -1.0, 1.0, 0.0, 0.0, 3.0, -2.0, 0.0, 0.0, -3.0, 1.0, 0.0, 0.0, 1.0, 0.0}, d3A{0.0, 0.0, 0.0, -1.0, 0.0, 0.0, 0.0, 3.0, 0.0, 0.0, 0.0, -3.0, 0.0, 0.0, 0.0, 1.0}, CuspValue(cusp), ResetCount(0), notOpt(false), periodic(true) { cutoff_radius = 0.0; } OptimizableFunctorBase* makeClone() const { return new BsplineFunctor(*this); } void setCusp(real_type c) { CuspValue = c; } void setPeriodic(bool p) { periodic = p; } void resize(int n) { NumParams = n; int numCoefs = NumParams + 4; int numKnots = numCoefs - 2; DeltaR = cutoff_radius / (real_type)(numKnots - 1); DeltaRInv = 1.0 / DeltaR; Parameters.resize(n); SplineCoefs.resize(numCoefs); SplineDerivs.resize(numCoefs); } void reset() { int numCoefs = NumParams + 4; int numKnots = numCoefs - 2; DeltaR = cutoff_radius / (real_type)(numKnots - 1); DeltaRInv = 1.0 / DeltaR; for (int i = 0; i < SplineCoefs.size(); i++) SplineCoefs[i] = 0.0; // Ensure that cusp conditions is satisfied at the origin SplineCoefs[1] = Parameters[0]; SplineCoefs[2] = Parameters[1]; SplineCoefs[0] = Parameters[1] - 2.0 * DeltaR * CuspValue; for (int i = 2; i < Parameters.size(); i++) SplineCoefs[i + 1] = Parameters[i]; } /** compute value, gradient and laplacian for [iStart, iEnd) pairs * @param iat dummy * @param iStart starting particle index * @param iEnd ending particle index * @param _distArray distance arrUay * @param _valArray u(r_j) for j=[iStart,iEnd) * @param _gradArray du(r_j)/dr /r_j for j=[iStart,iEnd) * @param _lapArray d2u(r_j)/dr2 for j=[iStart,iEnd) * @param distArrayCompressed temp storage to filter r_j < cutoff_radius * @param distIndices temp storage for the compressed index */ void evaluateVGL(const int iat, const int iStart, const int iEnd, const T* _distArray, T* restrict _valArray, T* restrict _gradArray, T* restrict _laplArray, T* restrict distArrayCompressed, int* restrict distIndices) const; /** evaluate sum of the pair potentials for [iStart,iEnd) * @param iat dummy * @param iStart starting particle index * @param iEnd ending particle index * @param _distArray distance arrUay * @param distArrayCompressed temp storage to filter r_j < cutoff_radius * @return \f$\sum u(r_j)\f$ for r_j < cutoff_radius */ T evaluateV(const int iat, const int iStart, const int iEnd, const T* restrict _distArray, T* restrict distArrayCompressed) const; inline real_type evaluate(real_type r) { if (r >= cutoff_radius) return 0.0; r *= DeltaRInv; real_type ipart, t; t = std::modf(r, &ipart); int i = (int)ipart; real_type tp[4]; tp[0] = t * t * t; tp[1] = t * t; tp[2] = t; tp[3] = 1.0; return (SplineCoefs[i + 0] * (A[0] * tp[0] + A[1] * tp[1] + A[2] * tp[2] + A[3] * tp[3]) + SplineCoefs[i + 1] * (A[4] * tp[0] + A[5] * tp[1] + A[6] * tp[2] + A[7] * tp[3]) + SplineCoefs[i + 2] * (A[8] * tp[0] + A[9] * tp[1] + A[10] * tp[2] + A[11] * tp[3]) + SplineCoefs[i + 3] * (A[12] * tp[0] + A[13] * tp[1] + A[14] * tp[2] + A[15] * tp[3])); } inline real_type evaluate(real_type r, real_type rinv) { return Y = evaluate(r, dY, d2Y); } inline void evaluateAll(real_type r, real_type rinv) { Y = evaluate(r, dY, d2Y); } inline real_type evaluate(real_type r, real_type& dudr, real_type& d2udr2) { if (r >= cutoff_radius) { dudr = d2udr2 = 0.0; return 0.0; } // real_type eps = 1.0e-5; // real_type dudr_FD = (evaluate(r+eps)-evaluate(r-eps))/(2.0*eps); // real_type d2udr2_FD = (evaluate(r+eps)+evaluate(r-eps)-2.0*evaluate(r))/(eps*eps); r *= DeltaRInv; real_type ipart, t; t = std::modf(r, &ipart); int i = (int)ipart; real_type tp[4]; tp[0] = t * t * t; tp[1] = t * t; tp[2] = t; tp[3] = 1.0; d2udr2 = DeltaRInv * DeltaRInv * (SplineCoefs[i + 0] * (d2A[0] * tp[0] + d2A[1] * tp[1] + d2A[2] * tp[2] + d2A[3] * tp[3]) + SplineCoefs[i + 1] * (d2A[4] * tp[0] + d2A[5] * tp[1] + d2A[6] * tp[2] + d2A[7] * tp[3]) + SplineCoefs[i + 2] * (d2A[8] * tp[0] + d2A[9] * tp[1] + d2A[10] * tp[2] + d2A[11] * tp[3]) + SplineCoefs[i + 3] * (d2A[12] * tp[0] + d2A[13] * tp[1] + d2A[14] * tp[2] + d2A[15] * tp[3])); dudr = DeltaRInv * (SplineCoefs[i + 0] * (dA[0] * tp[0] + dA[1] * tp[1] + dA[2] * tp[2] + dA[3] * tp[3]) + SplineCoefs[i + 1] * (dA[4] * tp[0] + dA[5] * tp[1] + dA[6] * tp[2] + dA[7] * tp[3]) + SplineCoefs[i + 2] * (dA[8] * tp[0] + dA[9] * tp[1] + dA[10] * tp[2] + dA[11] * tp[3]) + SplineCoefs[i + 3] * (dA[12] * tp[0] + dA[13] * tp[1] + dA[14] * tp[2] + dA[15] * tp[3])); // if (std::abs(dudr_FD-dudr) > 1.0e-8) // std::cerr << "Error in BsplineFunction: dudr = " << dudr // << " dudr_FD = " << dudr_FD << std::endl; // if (std::abs(d2udr2_FD-d2udr2) > 1.0e-4) // std::cerr << "Error in BsplineFunction: r = " << r << " d2udr2 = " << dudr // << " d2udr2_FD = " << d2udr2_FD << " rcut = " << cutoff_radius << std::endl; return (SplineCoefs[i + 0] * (A[0] * tp[0] + A[1] * tp[1] + A[2] * tp[2] + A[3] * tp[3]) + SplineCoefs[i + 1] * (A[4] * tp[0] + A[5] * tp[1] + A[6] * tp[2] + A[7] * tp[3]) + SplineCoefs[i + 2] * (A[8] * tp[0] + A[9] * tp[1] + A[10] * tp[2] + A[11] * tp[3]) + SplineCoefs[i + 3] * (A[12] * tp[0] + A[13] * tp[1] + A[14] * tp[2] + A[15] * tp[3])); } inline real_type evaluate(real_type r, real_type& dudr, real_type& d2udr2, real_type& d3udr3) { if (r >= cutoff_radius) { dudr = d2udr2 = d3udr3 = 0.0; return 0.0; } // real_type eps = 1.0e-5; // real_type dudr_FD = (evaluate(r+eps)-evaluate(r-eps))/(2.0*eps); // real_type d2udr2_FD = (evaluate(r+eps)+evaluate(r-eps)-2.0*evaluate(r))/(eps*eps); // real_type d3udr3_FD = (-1.0*evaluate(r+1.0*eps) // +2.0*evaluate(r+0.5*eps) // -2.0*evaluate(r-0.5*eps) // +1.0*evaluate(r-1.0*eps))/(eps*eps*eps); r *= DeltaRInv; real_type ipart, t; t = std::modf(r, &ipart); int i = (int)ipart; real_type tp[4]; tp[0] = t * t * t; tp[1] = t * t; tp[2] = t; tp[3] = 1.0; d3udr3 = DeltaRInv * DeltaRInv * DeltaRInv * (SplineCoefs[i + 0] * (d3A[0] * tp[0] + d3A[1] * tp[1] + d3A[2] * tp[2] + d3A[3] * tp[3]) + SplineCoefs[i + 1] * (d3A[4] * tp[0] + d3A[5] * tp[1] + d3A[6] * tp[2] + d3A[7] * tp[3]) + SplineCoefs[i + 2] * (d3A[8] * tp[0] + d3A[9] * tp[1] + d3A[10] * tp[2] + d3A[11] * tp[3]) + SplineCoefs[i + 3] * (d3A[12] * tp[0] + d3A[13] * tp[1] + d3A[14] * tp[2] + d3A[15] * tp[3])); d2udr2 = DeltaRInv * DeltaRInv * (SplineCoefs[i + 0] * (d2A[0] * tp[0] + d2A[1] * tp[1] + d2A[2] * tp[2] + d2A[3] * tp[3]) + SplineCoefs[i + 1] * (d2A[4] * tp[0] + d2A[5] * tp[1] + d2A[6] * tp[2] + d2A[7] * tp[3]) + SplineCoefs[i + 2] * (d2A[8] * tp[0] + d2A[9] * tp[1] + d2A[10] * tp[2] + d2A[11] * tp[3]) + SplineCoefs[i + 3] * (d2A[12] * tp[0] + d2A[13] * tp[1] + d2A[14] * tp[2] + d2A[15] * tp[3])); dudr = DeltaRInv * (SplineCoefs[i + 0] * (dA[0] * tp[0] + dA[1] * tp[1] + dA[2] * tp[2] + dA[3] * tp[3]) + SplineCoefs[i + 1] * (dA[4] * tp[0] + dA[5] * tp[1] + dA[6] * tp[2] + dA[7] * tp[3]) + SplineCoefs[i + 2] * (dA[8] * tp[0] + dA[9] * tp[1] + dA[10] * tp[2] + dA[11] * tp[3]) + SplineCoefs[i + 3] * (dA[12] * tp[0] + dA[13] * tp[1] + dA[14] * tp[2] + dA[15] * tp[3])); // if (std::abs(dudr_FD-dudr) > 1.0e-8) // std::cerr << "Error in BsplineFunction: dudr = " << dudr // << " dudr_FD = " << dudr_FD << std::endl; // if (std::abs(d2udr2_FD-d2udr2) > 1.0e-4) // std::cerr << "Error in BsplineFunction: r = " << r << " d2udr2 = " << dudr // << " d2udr2_FD = " << d2udr2_FD << " rcut = " << cutoff_radius << std::endl; // if (std::abs(d3udr3_FD-d3udr3) > 1.0e-4) // std::cerr << "Error in BsplineFunction: r = " << r << " d3udr3 = " << dudr // << " d3udr3_FD = " << d3udr3_FD << " rcut = " << cutoff_radius << std::endl; return (SplineCoefs[i + 0] * (A[0] * tp[0] + A[1] * tp[1] + A[2] * tp[2] + A[3] * tp[3]) + SplineCoefs[i + 1] * (A[4] * tp[0] + A[5] * tp[1] + A[6] * tp[2] + A[7] * tp[3]) + SplineCoefs[i + 2] * (A[8] * tp[0] + A[9] * tp[1] + A[10] * tp[2] + A[11] * tp[3]) + SplineCoefs[i + 3] * (A[12] * tp[0] + A[13] * tp[1] + A[14] * tp[2] + A[15] * tp[3])); } inline bool evaluateDerivatives(real_type r, std::vector<TinyVector<real_type, 3>>& derivs) { if (r >= cutoff_radius) return false; r *= DeltaRInv; real_type ipart, t; t = std::modf(r, &ipart); int i = (int)ipart; real_type tp[4]; tp[0] = t * t * t; tp[1] = t * t; tp[2] = t; tp[3] = 1.0; SplineDerivs[0] = TinyVector<real_type, 3>(0.0); // d/dp_i u(r) SplineDerivs[i + 0][0] = A[0] * tp[0] + A[1] * tp[1] + A[2] * tp[2] + A[3] * tp[3]; SplineDerivs[i + 1][0] = A[4] * tp[0] + A[5] * tp[1] + A[6] * tp[2] + A[7] * tp[3]; SplineDerivs[i + 2][0] = A[8] * tp[0] + A[9] * tp[1] + A[10] * tp[2] + A[11] * tp[3]; SplineDerivs[i + 3][0] = A[12] * tp[0] + A[13] * tp[1] + A[14] * tp[2] + A[15] * tp[3]; // d/dp_i du/dr SplineDerivs[i + 0][1] = DeltaRInv * (dA[1] * tp[1] + dA[2] * tp[2] + dA[3] * tp[3]); SplineDerivs[i + 1][1] = DeltaRInv * (dA[5] * tp[1] + dA[6] * tp[2] + dA[7] * tp[3]); SplineDerivs[i + 2][1] = DeltaRInv * (dA[9] * tp[1] + dA[10] * tp[2] + dA[11] * tp[3]); SplineDerivs[i + 3][1] = DeltaRInv * (dA[13] * tp[1] + dA[14] * tp[2] + dA[15] * tp[3]); // d/dp_i d2u/dr2 SplineDerivs[i + 0][2] = DeltaRInv * DeltaRInv * (d2A[2] * tp[2] + d2A[3] * tp[3]); SplineDerivs[i + 1][2] = DeltaRInv * DeltaRInv * (d2A[6] * tp[2] + d2A[7] * tp[3]); SplineDerivs[i + 2][2] = DeltaRInv * DeltaRInv * (d2A[10] * tp[2] + d2A[11] * tp[3]); SplineDerivs[i + 3][2] = DeltaRInv * DeltaRInv * (d2A[14] * tp[2] + d2A[15] * tp[3]); int imin = std::max(i, 1); int imax = std::min(i + 4, NumParams + 1); for (int n = imin; n < imax; ++n) derivs[n - 1] = SplineDerivs[n]; derivs[1] += SplineDerivs[0]; //real_type v[4],dv[4],d2v[4]; //v[0] = A[ 0]*tp[0] + A[ 1]*tp[1] + A[ 2]*tp[2] + A[ 3]*tp[3]; //v[1] = A[ 4]*tp[0] + A[ 5]*tp[1] + A[ 6]*tp[2] + A[ 7]*tp[3]; //v[2] = A[ 8]*tp[0] + A[ 9]*tp[1] + A[10]*tp[2] + A[11]*tp[3]; //v[3] = A[12]*tp[0] + A[13]*tp[1] + A[14]*tp[2] + A[15]*tp[3]; //// d/dp_i du/dr //dv[0] = DeltaRInv * (dA[ 1]*tp[1] + dA[ 2]*tp[2] + dA[ 3]*tp[3]); //dv[1] = DeltaRInv * (dA[ 5]*tp[1] + dA[ 6]*tp[2] + dA[ 7]*tp[3]); //dv[2] = DeltaRInv * (dA[ 9]*tp[1] + dA[10]*tp[2] + dA[11]*tp[3]); //dv[3] = DeltaRInv * (dA[13]*tp[1] + dA[14]*tp[2] + dA[15]*tp[3]); //// d/dp_i d2u/dr2 //d2v[0] = DeltaRInv * DeltaRInv * (d2A[ 2]*tp[2] + d2A[ 3]*tp[3]); //d2v[1] = DeltaRInv * DeltaRInv * (d2A[ 6]*tp[2] + d2A[ 7]*tp[3]); //d2v[2] = DeltaRInv * DeltaRInv * (d2A[10]*tp[2] + d2A[11]*tp[3]); //d2v[3] = DeltaRInv * DeltaRInv * (d2A[14]*tp[2] + d2A[15]*tp[3]); //int imin=std::max(i,1); //int imax=std::min(i+4,NumParams+1)-1; //int n=imin-1, j=imin-i; //while(n<imax && j<4) //{ // derivs[n] = TinyVector<real_type,3>(v[j],dv[j],d2v[j]); // n++; j++; //} //if(i==0) derivs[1]+= TinyVector<real_type,3>(v[0],dv[0],d2v[0]); return true; } inline bool evaluateDerivatives(real_type r, std::vector<real_type>& derivs) { if (r >= cutoff_radius) return false; real_type tp[4], v[4], ipart, t; t = std::modf(r * DeltaRInv, &ipart); tp[0] = t * t * t; tp[1] = t * t; tp[2] = t; tp[3] = 1.0; v[0] = A[0] * tp[0] + A[1] * tp[1] + A[2] * tp[2] + A[3] * tp[3]; v[1] = A[4] * tp[0] + A[5] * tp[1] + A[6] * tp[2] + A[7] * tp[3]; v[2] = A[8] * tp[0] + A[9] * tp[1] + A[10] * tp[2] + A[11] * tp[3]; v[3] = A[12] * tp[0] + A[13] * tp[1] + A[14] * tp[2] + A[15] * tp[3]; int i = (int)ipart; int imin = std::max(i, 1); int imax = std::min(i + 4, NumParams + 1) - 1; int n = imin - 1, j = imin - i; while (n < imax && j < 4) { derivs[n] = v[j]; n++; j++; } if (i == 0) derivs[1] += v[0]; return true; } inline real_type f(real_type r) { if (r >= cutoff_radius) return 0.0; return evaluate(r); } inline real_type df(real_type r) { if (r >= cutoff_radius) return 0.0; real_type du, d2u; evaluate(r, du, d2u); return du; } bool put(xmlNodePtr cur) { ReportEngine PRE("BsplineFunctor", "put(xmlNodePtr)"); //CuspValue = -1.0e10; NumParams = 0; //cutoff_radius = 0.0; OhmmsAttributeSet rAttrib; real_type radius = -1.0; rAttrib.add(NumParams, "size"); rAttrib.add(radius, "rcut"); rAttrib.add(radius, "cutoff"); rAttrib.put(cur); if (radius < 0.0) if (periodic) { app_log() << " Jastrow cutoff unspecified. Setting to Wigner-Seitz radius = " << cutoff_radius << std::endl; app_log() << std::endl; } else { APP_ABORT(" Jastrow cutoff unspecified. Cutoff must be given when using open boundary conditions"); } else if (periodic && radius > cutoff_radius) { if (radius - cutoff_radius > 1e-4) { APP_ABORT(" The Jastrow cutoff specified should not be larger than Wigner-Seitz radius."); } else { app_log() << " The Jastrow cutoff specified is slightly larger than the Wigner-Seitz radius."; app_log() << " Setting to Wigner-Seitz radius = " << cutoff_radius << ".\n"; } } else cutoff_radius = radius; if (NumParams == 0) { PRE.error("You must specify a positive number of parameters for the Bspline jastrow function.", true); } app_summary() << " Number of parameters: " << NumParams << std::endl; app_summary() << " Cusp: " << CuspValue << std::endl; app_summary() << " Cutoff radius: " << cutoff_radius << std::endl; resize(NumParams); // Now read coefficents xmlNodePtr xmlCoefs = cur->xmlChildrenNode; while (xmlCoefs != NULL) { std::string cname((const char*)xmlCoefs->name); if (cname == "coefficients") { std::string type("0"), id("0"); std::string optimize("yes"); OhmmsAttributeSet cAttrib; cAttrib.add(id, "id"); cAttrib.add(type, "type"); cAttrib.add(optimize, "optimize"); cAttrib.put(xmlCoefs); if (type != "Array") { PRE.error("Unknown correlation type " + type + " in BsplineFunctor." + "Resetting to \"Array\""); xmlNewProp(xmlCoefs, (const xmlChar*)"type", (const xmlChar*)"Array"); } std::vector<real_type> params; putContent(params, xmlCoefs); if (params.size() == NumParams) Parameters = params; else { app_log() << " Changing number of Bspline parameters from " << params.size() << " to " << NumParams << ". Performing fit:\n"; // Fit function to new number of parameters const int numPoints = 500; BsplineFunctor<T> tmp_func(CuspValue); tmp_func.cutoff_radius = cutoff_radius; tmp_func.resize(params.size()); tmp_func.Parameters = params; tmp_func.reset(); std::vector<real_type> y(numPoints); Matrix<real_type> basis(numPoints, NumParams); std::vector<TinyVector<real_type, 3>> derivs(NumParams); for (int i = 0; i < numPoints; i++) { real_type r = (real_type)i / (real_type)numPoints * cutoff_radius; y[i] = tmp_func.evaluate(r); evaluateDerivatives(r, derivs); for (int j = 0; j < NumParams; j++) basis(i, j) = derivs[j][0]; } resize(NumParams); LinearFit(y, basis, Parameters); app_log() << "New parameters are:\n"; for (int i = 0; i < Parameters.size(); i++) app_log() << " " << Parameters[i] << std::endl; } if (optimize == "yes") { notOpt = false; } else { notOpt = true; } for (int i = 0; i < NumParams; i++) { std::stringstream sstr; sstr << id << "_" << i; myVars.insert(sstr.str(), (value_type)Parameters[i], !notOpt, optimize::LOGLINEAR_P); } int left_pad_space = 5; app_log() << std::endl; myVars.print(app_log(), left_pad_space, true); } xmlCoefs = xmlCoefs->next; } reset(); real_type zeros = 0; for (int i = 0; i < NumParams; i++) zeros += Parameters[i] * Parameters[i]; return zeros > 1.0e-12; //true if Parameters are not zero } void initialize(int numPoints, std::vector<real_type>& x, std::vector<real_type>& y, real_type cusp, real_type rcut, std::string& id, std::string& optimize) { ReportEngine PRE("BsplineFunctor", "initialize"); NumParams = numPoints; cutoff_radius = rcut; CuspValue = cusp; if (NumParams == 0) { PRE.error("You must specify a positive number of parameters for the Bspline jastrow function.", true); } app_log() << "Initializing BsplineFunctor from array. \n"; app_log() << " size = " << NumParams << " parameters " << std::endl; app_log() << " cusp = " << CuspValue << std::endl; app_log() << " rcut = " << cutoff_radius << std::endl; resize(NumParams); int npts = x.size(); Matrix<real_type> basis(npts, NumParams); std::vector<TinyVector<real_type, 3>> derivs(NumParams); for (int i = 0; i < npts; i++) { real_type r = x[i]; if (r > cutoff_radius) { PRE.error("Error in BsplineFunctor::initialize: r > cutoff_radius.", true); } evaluateDerivatives(r, derivs); for (int j = 0; j < NumParams; j++) basis(i, j) = derivs[j][0]; } resize(NumParams); LinearFit(y, basis, Parameters); app_log() << "New parameters are:\n"; for (int i = 0; i < Parameters.size(); i++) app_log() << " " << Parameters[i] << std::endl; #if !defined(QMC_BUILD_SANDBOX_ONLY) if (optimize == "yes") { // Setup parameter names for (int i = 0; i < NumParams; i++) { std::stringstream sstr; sstr << id << "_" << i; myVars.insert(sstr.str(), (value_type)Parameters[i], true, optimize::LOGLINEAR_P); } myVars.print(app_log()); } else #endif { notOpt = true; app_log() << "Parameters of BsplineFunctor id:" << id << " are not being optimized.\n"; } reset(); } void reportStatus(std::ostream& os) { if (notOpt) return; myVars.print(os); } void checkOutVariables(const opt_variables_type& active) { if (notOpt) return; myVars.getIndex(active); } void checkInVariables(opt_variables_type& active) { if (notOpt) return; active.insertFrom(myVars); } void resetParameters(const opt_variables_type& active) { if (notOpt) return; for (int i = 0; i < Parameters.size(); ++i) { int loc = myVars.where(i); if (loc >= 0) { Parameters[i] = std::real( myVars[i] = active[loc] ); } } // if (ResetCount++ == 100) // { // ResetCount = 0; // if(ReportLevel) print(); // } reset(); } // check if this object has active optimizable parameters bool isOptimizable() { if (notOpt) return false; for (int i = 0; i < Parameters.size(); ++i) { int loc = myVars.where(i); if (loc >= 0) return true; } return false; } }; template<typename T> inline T BsplineFunctor<T>::evaluateV(const int iat, const int iStart, const int iEnd, const T* restrict _distArray, T* restrict distArrayCompressed) const { const real_type* restrict distArray = _distArray + iStart; ASSUME_ALIGNED(distArrayCompressed); int iCount = 0; const int iLimit = iEnd - iStart; #pragma vector always for (int jat = 0; jat < iLimit; jat++) { real_type r = distArray[jat]; // pick the distances smaller than the cutoff and avoid the reference atom if (r < cutoff_radius && iStart + jat != iat) distArrayCompressed[iCount++] = distArray[jat]; } real_type d = 0.0; #pragma omp simd reduction(+ : d) for (int jat = 0; jat < iCount; jat++) { real_type r = distArrayCompressed[jat]; r *= DeltaRInv; int i = (int)r; real_type t = r - real_type(i); real_type tp0 = t * t * t; real_type tp1 = t * t; real_type tp2 = t; real_type d1 = SplineCoefs[i + 0] * (A[0] * tp0 + A[1] * tp1 + A[2] * tp2 + A[3]); real_type d2 = SplineCoefs[i + 1] * (A[4] * tp0 + A[5] * tp1 + A[6] * tp2 + A[7]); real_type d3 = SplineCoefs[i + 2] * (A[8] * tp0 + A[9] * tp1 + A[10] * tp2 + A[11]); real_type d4 = SplineCoefs[i + 3] * (A[12] * tp0 + A[13] * tp1 + A[14] * tp2 + A[15]); d += (d1 + d2 + d3 + d4); } return d; } template<typename T> inline void BsplineFunctor<T>::evaluateVGL(const int iat, const int iStart, const int iEnd, const T* _distArray, T* restrict _valArray, T* restrict _gradArray, T* restrict _laplArray, T* restrict distArrayCompressed, int* restrict distIndices) const { real_type dSquareDeltaRinv = DeltaRInv * DeltaRInv; constexpr real_type cOne(1); // START_MARK_FIRST(); ASSUME_ALIGNED(distIndices); ASSUME_ALIGNED(distArrayCompressed); int iCount = 0; int iLimit = iEnd - iStart; const real_type* distArray = _distArray + iStart; real_type* valArray = _valArray + iStart; real_type* gradArray = _gradArray + iStart; real_type* laplArray = _laplArray + iStart; #pragma vector always for (int jat = 0; jat < iLimit; jat++) { real_type r = distArray[jat]; if (r < cutoff_radius && iStart + jat != iat) { distIndices[iCount] = jat; distArrayCompressed[iCount] = r; iCount++; } } #pragma omp simd for (int j = 0; j < iCount; j++) { real_type r = distArrayCompressed[j]; int iScatter = distIndices[j]; real_type rinv = cOne / r; r *= DeltaRInv; int iGather = (int)r; real_type t = r - real_type(iGather); real_type tp0 = t * t * t; real_type tp1 = t * t; real_type tp2 = t; real_type sCoef0 = SplineCoefs[iGather + 0]; real_type sCoef1 = SplineCoefs[iGather + 1]; real_type sCoef2 = SplineCoefs[iGather + 2]; real_type sCoef3 = SplineCoefs[iGather + 3]; laplArray[iScatter] = dSquareDeltaRinv * (sCoef0 * (d2A[2] * tp2 + d2A[3]) + sCoef1 * (d2A[6] * tp2 + d2A[7]) + sCoef2 * (d2A[10] * tp2 + d2A[11]) + sCoef3 * (d2A[14] * tp2 + d2A[15])); gradArray[iScatter] = DeltaRInv * rinv * (sCoef0 * (dA[1] * tp1 + dA[2] * tp2 + dA[3]) + sCoef1 * (dA[5] * tp1 + dA[6] * tp2 + dA[7]) + sCoef2 * (dA[9] * tp1 + dA[10] * tp2 + dA[11]) + sCoef3 * (dA[13] * tp1 + dA[14] * tp2 + dA[15])); valArray[iScatter] = (sCoef0 * (A[0] * tp0 + A[1] * tp1 + A[2] * tp2 + A[3]) + sCoef1 * (A[4] * tp0 + A[5] * tp1 + A[6] * tp2 + A[7]) + sCoef2 * (A[8] * tp0 + A[9] * tp1 + A[10] * tp2 + A[11]) + sCoef3 * (A[12] * tp0 + A[13] * tp1 + A[14] * tp2 + A[15])); } } } // namespace qmcplusplus #endif
cofold.c
/* * minimum free energy * RNA secondary structure prediction * * c Ivo Hofacker, Chrisoph Flamm * original implementation by * Walter Fontana * * Vienna RNA package */ #ifdef HAVE_CONFIG_H #include "config.h" #endif #include <stdio.h> #include <stdlib.h> #include <math.h> #include <ctype.h> #include <string.h> #include <limits.h> #include "ViennaRNA/utils/basic.h" #include "ViennaRNA/utils/strings.h" #include "ViennaRNA/utils/structures.h" #include "ViennaRNA/params/default.h" #include "ViennaRNA/fold_vars.h" #include "ViennaRNA/params/basic.h" #include "ViennaRNA/subopt.h" #include "ViennaRNA/fold.h" #include "ViennaRNA/loops/all.h" #include "ViennaRNA/gquad.h" #include "ViennaRNA/alphabet.h" #include "ViennaRNA/cofold.h" #ifndef VRNA_DISABLE_BACKWARD_COMPATIBILITY #ifdef _OPENMP #include <omp.h> #endif #endif #define MAXSECTORS 500 /* dimension for a backtrack array */ /* ################################# # GLOBAL VARIABLES # ################################# */ /* ################################# # PRIVATE VARIABLES # ################################# */ #ifndef VRNA_DISABLE_BACKWARD_COMPATIBILITY /* some backward compatibility stuff */ PRIVATE int backward_compat = 0; PRIVATE vrna_fold_compound_t *backward_compat_compound = NULL; PRIVATE float mfe1, mfe2; /* minimum free energies of the monomers */ #ifdef _OPENMP #pragma omp threadprivate(mfe1, mfe2, backward_compat_compound, backward_compat) #endif #endif /* ################################# # PRIVATE FUNCTION DECLARATIONS # ################################# */ PRIVATE void backtrack(sect bt_stack[], vrna_bp_stack_t *bp_list, vrna_fold_compound_t *vc); PRIVATE int fill_arrays(vrna_fold_compound_t *vc, int zuker); PRIVATE void free_end(int *array, int i, int start, vrna_fold_compound_t *vc); PRIVATE void doubleseq(vrna_fold_compound_t *vc); /* do magic */ PRIVATE void halfseq(vrna_fold_compound_t *vc); /* undo magic */ #ifndef VRNA_DISABLE_BACKWARD_COMPATIBILITY /* wrappers for old API compatibility */ PRIVATE void wrap_array_export(int **f5_p, int **c_p, int **fML_p, int **fM1_p, int **fc_p, int **indx_p, char **ptype_p); PRIVATE float wrap_cofold(const char *string, char *structure, vrna_param_t *parameters, int is_constrained); PRIVATE SOLUTION * wrap_zukersubopt(const char *string, vrna_param_t *parameters); #endif /* ################################# # BEGIN OF FUNCTION DEFINITIONS # ################################# */ PUBLIC float vrna_mfe_dimer(vrna_fold_compound_t *vc, char *structure) { int length, energy; char *s; sect bt_stack[MAXSECTORS]; /* stack of partial structures for backtracking */ vrna_bp_stack_t *bp; length = (int)vc->length; vc->sequence_encoding[0] = vc->sequence_encoding2[0]; /* store length at pos. 0 in S1 too */ if (!vrna_fold_compound_prepare(vc, VRNA_OPTION_MFE | VRNA_OPTION_HYBRID)) { vrna_message_warning("vrna_mfe_dimer@cofold.c: Failed to prepare vrna_fold_compound"); return (float)(INF / 100.); } /* call user-defined recursion status callback function */ if (vc->stat_cb) vc->stat_cb(VRNA_STATUS_MFE_PRE, vc->auxdata); energy = fill_arrays(vc, 0); /* call user-defined recursion status callback function */ if (vc->stat_cb) vc->stat_cb(VRNA_STATUS_MFE_POST, vc->auxdata); if (structure && vc->params->model_details.backtrack) { bp = (vrna_bp_stack_t *)vrna_alloc(sizeof(vrna_bp_stack_t) * (4 * (1 + length / 2))); /* add a guess of how many G's may be involved in a G quadruplex */ backtrack(bt_stack, bp, vc); s = vrna_db_from_bp_stack(bp, length); strncpy(structure, s, length + 1); free(s); free(bp); } if (vc->params->model_details.backtrack_type == 'C') return (float)vc->matrices->c[vc->jindx[length] + 1] / 100.; else if (vc->params->model_details.backtrack_type == 'M') return (float)vc->matrices->fML[vc->jindx[length] + 1] / 100.; else return (float)energy / 100.; } PRIVATE int fill_arrays(vrna_fold_compound_t *vc, int zuker) { /* fill "c", "fML" and "f5" arrays and return optimal energy */ unsigned int strands, *sn, *ss, *se, *so; int i, j, length, energy; int uniq_ML; int no_close, type, maxj, *indx; int *my_f5, *my_c, *my_fML, *my_fM1, *my_fc; int *cc, *cc1; /* auxilary arrays for canonical structures */ int *Fmi; /* holds row i of fML (avoids jumps in memory) */ int *DMLi; /* DMLi[j] holds MIN(fML[i,k]+fML[k+1,j]) */ int *DMLi1; /* MIN(fML[i+1,k]+fML[k+1,j]) */ int *DMLi2; /* MIN(fML[i+2,k]+fML[k+1,j]) */ int dangle_model, noGUclosure, noLP, hc_decompose, turn; char *ptype; unsigned char *hard_constraints; vrna_param_t *P; vrna_mx_mfe_t *matrices; vrna_hc_t *hc; length = (int)vc->length; ptype = vc->ptype; indx = vc->jindx; P = vc->params; dangle_model = P->model_details.dangles; noGUclosure = P->model_details.noGUclosure; noLP = P->model_details.noLP; uniq_ML = P->model_details.uniq_ML; strands = vc->strands; sn = vc->strand_number; ss = vc->strand_start; se = vc->strand_end; so = vc->strand_order; hc = vc->hc; hard_constraints = hc->mx; matrices = vc->matrices; my_f5 = matrices->f5; my_c = matrices->c; my_fML = matrices->fML; my_fM1 = matrices->fM1; my_fc = matrices->fc; turn = P->model_details.min_loop_size; /* allocate memory for all helper arrays */ cc = (int *)vrna_alloc(sizeof(int) * (length + 2)); cc1 = (int *)vrna_alloc(sizeof(int) * (length + 2)); Fmi = (int *)vrna_alloc(sizeof(int) * (length + 1)); DMLi = (int *)vrna_alloc(sizeof(int) * (length + 1)); DMLi1 = (int *)vrna_alloc(sizeof(int) * (length + 1)); DMLi2 = (int *)vrna_alloc(sizeof(int) * (length + 1)); /* hard code min_loop_size to 0, since we can not be sure yet that this is already the case */ turn = 0; for (j = 1; j <= length; j++) { Fmi[j] = DMLi[j] = DMLi1[j] = DMLi2[j] = INF; my_fc[j] = 0; } for (j = 1; j <= length; j++) for (i = 1; i <= j; i++) { my_c[indx[j] + i] = my_fML[indx[j] + i] = INF; if (uniq_ML) my_fM1[indx[j] + i] = INF; } for (i = length - turn - 1; i >= 1; i--) { /* i,j in [1..length] */ maxj = (zuker) ? (MIN2(i + se[so[0]], length)) : length; for (j = i + turn + 1; j <= maxj; j++) { int ij; ij = indx[j] + i; type = vrna_get_ptype(ij, ptype); hc_decompose = hard_constraints[length * i + j]; energy = INF; no_close = (((type == 3) || (type == 4)) && noGUclosure); if (hc_decompose) { /* we have a pair */ int new_c = INF; if (!no_close) { /* check for hairpin loop */ energy = vrna_E_hp_loop(vc, i, j); new_c = MIN2(new_c, energy); /* check for multibranch loops */ energy = vrna_E_mb_loop_fast(vc, i, j, DMLi1, DMLi2); new_c = MIN2(new_c, energy); } if (dangle_model == 3) { /* coaxial stacking */ energy = vrna_E_mb_loop_stack(vc, i, j); new_c = MIN2(new_c, energy); } /* check for interior loops */ energy = vrna_E_int_loop(vc, i, j); new_c = MIN2(new_c, energy); /* remember stack energy for --noLP option */ if (noLP) { if ((sn[i] == sn[i + 1]) && (sn[j - 1] == sn[j])) { int stackEnergy = vrna_E_stack(vc, i, j); new_c = MIN2(new_c, cc1[j - 1] + stackEnergy); my_c[ij] = cc1[j - 1] + stackEnergy; } else { /* currently we don't allow stacking over the cut point */ my_c[ij] = FORBIDDEN; } cc[j] = new_c; } else { my_c[ij] = new_c; } } /* end >> if (pair) << */ else { my_c[ij] = INF; } /* * done with c[i,j], now compute fML[i,j] * free ends ? ----------------------------------------- */ my_fML[ij] = vrna_E_ml_stems_fast(vc, i, j, Fmi, DMLi); if (uniq_ML) /* compute fM1 for unique decomposition */ my_fM1[ij] = E_ml_rightmost_stem(i, j, vc); } if (i == se[so[0]] + 1) for (j = i; j <= maxj; j++) free_end(my_fc, j, ss[so[1]], vc); if (i <= se[so[0]]) free_end(my_fc, i, se[so[0]], vc); { int *FF; /* rotate the auxilliary arrays */ FF = DMLi2; DMLi2 = DMLi1; DMLi1 = DMLi; DMLi = FF; FF = cc1; cc1 = cc; cc = FF; for (j = 1; j <= maxj; j++) cc[j] = Fmi[j] = DMLi[j] = INF; } } /* calculate energies of 5' and 3' fragments */ for (i = 1; i <= length; i++) free_end(my_f5, i, 1, vc); if (strands > 1) { mfe1 = my_f5[se[so[0]]]; mfe2 = my_fc[length]; /* add DuplexInit, check whether duplex*/ for (i = ss[so[1]]; i <= length; i++) my_f5[i] = MIN2(my_f5[i] + P->DuplexInit, my_fc[i] + my_fc[1]); } energy = my_f5[length]; if (strands == 1) mfe1 = mfe2 = energy; /* clean up memory */ free(cc); free(cc1); free(Fmi); free(DMLi); free(DMLi1); free(DMLi2); return energy; } PRIVATE void backtrack_co(sect bt_stack[], vrna_bp_stack_t *bp_list, int s, int b, /* b=0: start new structure, b \ne 0: add to existing structure */ vrna_fold_compound_t *vc) { /*------------------------------------------------------------------ * trace back through the "c", "fc", "f5" and "fML" arrays to get the * base pairing list. No search for equivalent structures is done. * This is fast, since only few structure elements are recalculated. * ------------------------------------------------------------------*/ unsigned int *se, *so; int i, j, ij, k, length, no_close, type; char *string = vc->sequence; vrna_param_t *P = vc->params; int *indx = vc->jindx; char *ptype = vc->ptype; int noLP = P->model_details.noLP; int noGUclosure = P->model_details.noGUclosure; char backtrack_type = P->model_details.backtrack_type; /* the folding matrices */ int *my_c; length = vc->length; my_c = vc->matrices->c; se = vc->strand_end; so = vc->strand_order; /* int b=0;*/ length = strlen(string); if (s == 0) { bt_stack[++s].i = 1; bt_stack[s].j = length; bt_stack[s].ml = (backtrack_type == 'M') ? 1 : ((backtrack_type == 'C') ? 2 : 0); } while (s > 0) { int ml, cij; int canonical = 1; /* (i,j) closes a canonical structure */ /* pop one element from stack */ i = bt_stack[s].i; j = bt_stack[s].j; ml = bt_stack[s--].ml; switch (ml) { /* backtrack in f5 */ case 0: { int p, q; if (vrna_BT_ext_loop_f5(vc, &j, &p, &q, bp_list, &b)) { if (j > 0) { bt_stack[++s].i = 1; bt_stack[s].j = j; bt_stack[s].ml = 0; } if (p > 0) { i = p; j = q; goto repeat1; } continue; } else { vrna_message_error("backtrack failed in f5, segment [%d,%d]\n", i, j); } } break; /* true multi-loop backtrack in fML */ case 1: { int p, q, comp1, comp2; if (vrna_BT_mb_loop_split(vc, &i, &j, &p, &q, &comp1, &comp2, bp_list, &b)) { if (i > 0) { bt_stack[++s].i = i; bt_stack[s].j = j; bt_stack[s].ml = comp1; } if (p > 0) { bt_stack[++s].i = p; bt_stack[s].j = q; bt_stack[s].ml = comp2; } continue; } else { vrna_message_error("backtrack failed in fML\n%s", string); } } break; case 2: bp_list[++b].i = i; bp_list[b].j = j; goto repeat1; /* backtrack fake-multi loop parts */ case 3: case 4: { int lower, k, p, q; p = i; q = j; lower = (i <= se[so[0]]) ? 1 : 0; if (vrna_BT_mb_loop_fake(vc, &k, &i, &j, bp_list, &b)) { if (k > 0) { bt_stack[++s].i = (lower) ? k : p; bt_stack[s].j = (lower) ? q : k; bt_stack[s].ml = ml; } if (i > 0) goto repeat1; continue; } else { vrna_message_error("backtrack failed in fc\n%s", string); } } break; } /* end of switch(ml) */ repeat1: /*----- begin of "repeat:" -----*/ ij = indx[j] + i; if (canonical) cij = my_c[ij]; type = vrna_get_ptype(ij, ptype); if (noLP) { if (vrna_BT_stack(vc, &i, &j, &cij, bp_list, &b)) { canonical = 0; goto repeat1; } } canonical = 1; no_close = (((type == 3) || (type == 4)) && noGUclosure); if (no_close) { if (cij == FORBIDDEN) continue; } else { if (vrna_BT_hp_loop(vc, i, j, cij, bp_list, &b)) continue; } if (vrna_BT_int_loop(vc, &i, &j, cij, bp_list, &b)) { if (i < 0) continue; else goto repeat1; } /* (i.j) must close a fake or true multi-loop */ int comp1, comp2; if (vrna_BT_mb_loop(vc, &i, &j, &k, cij, &comp1, &comp2)) { bt_stack[++s].i = i; bt_stack[s].j = k; bt_stack[s].ml = comp1; bt_stack[++s].i = k + 1; bt_stack[s].j = j; bt_stack[s].ml = comp2; } else { vrna_message_error("backtracking failed in repeat"); } /* end of repeat: --------------------------------------------------*/ } /* end >> while (s>0) << */ bp_list[0].i = b; /* save the total number of base pairs */ } PRIVATE void free_end(int *array, int i, int start, vrna_fold_compound_t *vc) { unsigned int *sn; int inc, type, energy, en, length, j, left, right, dangle_model, with_gquad, *indx, *c, *ggg, turn; vrna_param_t *P; short *S1; char *ptype; unsigned char *hard_constraints; vrna_mx_mfe_t *matrices; vrna_hc_t *hc; vrna_sc_t *sc; P = vc->params; dangle_model = P->model_details.dangles; with_gquad = P->model_details.gquad; turn = P->model_details.min_loop_size; inc = (i > start) ? 1 : -1; length = (int)vc->length; S1 = vc->sequence_encoding; ptype = vc->ptype; indx = vc->jindx; sn = vc->strand_number; matrices = vc->matrices; c = matrices->c; ggg = matrices->ggg; hc = vc->hc; sc = vc->sc; hard_constraints = hc->mx; if (hc->up_ext[i]) { if (i == start) array[i] = 0; else array[i] = array[i - inc]; if (sc) { if (sc->energy_up) array[i] += sc->energy_up[i][1]; if (sc->f) array[i] += sc->f(start, i, start, i - 1, VRNA_DECOMP_EXT_EXT, sc->data); } } else { array[i] = INF; } if (inc > 0) { left = start; right = i; } else { left = i; right = start; } /* hard code min_loop_size to 0, since we can not be sure yet that this is already the case */ turn = 0; for (j = start; inc * (i - j) > turn; j += inc) { int ii, jj; short si, sj; if (i > j) { ii = j; jj = i; } /* inc>0 */ else { ii = i; jj = j; } /* inc<0 */ if (hard_constraints[length * ii + jj] & VRNA_CONSTRAINT_CONTEXT_EXT_LOOP) { type = vrna_get_ptype(indx[jj] + ii, ptype); si = ((ii > 1) && (sn[ii - 1] == sn[ii])) ? S1[ii - 1] : -1; sj = ((jj < length) && (sn[jj] == sn[jj + 1])) ? S1[jj + 1] : -1; energy = c[indx[jj] + ii]; if ((sc) && (sc->f)) energy += sc->f(start, jj, ii - 1, ii, VRNA_DECOMP_EXT_EXT_STEM, sc->data); if (energy != INF) { switch (dangle_model) { case 0: if (array[j - inc] != INF) { en = array[j - inc] + energy + vrna_E_ext_stem(type, -1, -1, P); array[i] = MIN2(array[i], en); } break; case 2: if (array[j - inc] != INF) { en = array[j - inc] + energy + vrna_E_ext_stem(type, si, sj, P); array[i] = MIN2(array[i], en); } break; default: if (array[j - inc] != INF) { en = array[j - inc] + energy + vrna_E_ext_stem(type, -1, -1, P); array[i] = MIN2(array[i], en); } if (inc > 0) { if (j > left) { if (hc->up_ext[ii - 1]) { if (array[j - 2] != INF) { en = array[j - 2] + energy + vrna_E_ext_stem(type, si, -1, P); if (sc) if (sc->energy_up) en += sc->energy_up[ii - 1][1]; array[i] = MIN2(array[i], en); } } } } else if (j < right) { if (hc->up_ext[jj + 1]) { if (array[j + 2] != INF) { en = array[j + 2] + energy + vrna_E_ext_stem(type, -1, sj, P); if (sc) if (sc->energy_up) en += sc->energy_up[jj + 1][1]; array[i] = MIN2(array[i], en); } } } break; } } } if (with_gquad) { if (sn[ii] == sn[jj]) if (array[j - inc] != INF) array[i] = MIN2(array[i], array[j - inc] + ggg[indx[jj] + ii]); } if (dangle_model % 2 == 1) { /* interval ends in a dangle (i.e. i-inc is paired) */ if (i > j) { ii = j; jj = i - 1; } /* inc>0 */ else { ii = i + 1; jj = j; } /* inc<0 */ if (!(hard_constraints[length * ii + jj] & VRNA_CONSTRAINT_CONTEXT_EXT_LOOP)) continue; type = vrna_get_ptype(indx[jj] + ii, ptype); si = (ii > left) && (sn[ii - 1] == sn[ii]) ? S1[ii - 1] : -1; sj = (jj < right) && (sn[jj] == sn[jj + 1]) ? S1[jj + 1] : -1; energy = c[indx[jj] + ii]; if (energy != INF) { if (inc > 0) { if (hc->up_ext[jj - 1]) { if (array[j - inc] != INF) { en = array[j - inc] + energy + vrna_E_ext_stem(type, -1, sj, P); if (sc) if (sc->energy_up) en += sc->energy_up[jj + 1][1]; array[i] = MIN2(array[i], en); } } } else { if (hc->up_ext[ii - 1]) { if (array[j - inc] != INF) { en = array[j - inc] + energy + vrna_E_ext_stem(type, si, -1, P); if (sc) if (sc->energy_up) en += sc->energy_up[ii - 1][1]; array[i] = MIN2(array[i], en); } } } if (j != start) { /* dangle_model on both sides */ if (hc->up_ext[jj - 1] && hc->up_ext[ii - 1]) { if (array[j - 2 * inc] != INF) { en = array[j - 2 * inc] + energy + vrna_E_ext_stem(type, si, sj, P); if (sc) if (sc->energy_up) en += sc->energy_up[ii - 1][1] + sc->energy_up[jj + 1][1]; array[i] = MIN2(array[i], en); } } } } } } } PRIVATE void backtrack(sect bt_stack[], vrna_bp_stack_t *bp_list, vrna_fold_compound_t *vc) { /*routine to call backtrack_co from 1 to n, backtrack type??*/ backtrack_co(bt_stack, bp_list, 0, 0, vc); } PRIVATE void doubleseq(vrna_fold_compound_t *vc) { unsigned int length, i, s; length = vc->length; /* do some magic to re-use cofold code */ vc->sequence = vrna_realloc(vc->sequence, sizeof(char) * (2 * length + 2)); memcpy(vc->sequence + length, vc->sequence, sizeof(char) * length); vc->sequence[2 * length] = '\0'; vc->length = (unsigned int)strlen(vc->sequence); vc->cutpoint = length + 1; vc->strands = 2; free(vc->strand_number); vc->strand_number = (unsigned int *)vrna_alloc(sizeof(unsigned int) * (vc->length + 1)); for (s = i = 0; i <= vc->length; i++) { if (i == length + 1) s++; vc->strand_number[i] = s; } free(vc->strand_order); free(vc->strand_start); free(vc->strand_end); vc->strand_order = (unsigned int *)vrna_alloc(sizeof(unsigned int) * (vc->strands + 1)); vc->strand_start = (unsigned int *)vrna_alloc(sizeof(unsigned int) * (vc->strands + 1)); vc->strand_end = (unsigned int *)vrna_alloc(sizeof(unsigned int) * (vc->strands + 1)); vc->strand_order[0] = 0; vc->strand_order[1] = 1; vc->strand_start[0] = 1; vc->strand_end[0] = vc->strand_start[0] + length - 1; vc->strand_start[1] = vc->strand_end[0] + 1; vc->strand_end[1] = vc->strand_start[1] + length - 1; vc->sequence_encoding = vrna_realloc(vc->sequence_encoding, sizeof(short) * (vc->length + 2)); memcpy(vc->sequence_encoding + length + 1, vc->sequence_encoding + 1, sizeof(short) * length); vc->sequence_encoding[0] = vc->sequence_encoding[vc->length]; vc->sequence_encoding[vc->length + 1] = vc->sequence_encoding[1]; vc->sequence_encoding2 = vrna_realloc(vc->sequence_encoding2, sizeof(short) * (vc->length + 2)); memcpy(vc->sequence_encoding2 + length + 1, vc->sequence_encoding2 + 1, sizeof(short) * length); vc->sequence_encoding2[0] = vc->length; vc->sequence_encoding2[vc->length + 1] = 0; free(vc->ptype); vc->ptype = vrna_ptypes(vc->sequence_encoding2, &(vc->params->model_details)); free(vc->iindx); vc->iindx = vrna_idx_row_wise(vc->length); free(vc->jindx); vc->jindx = vrna_idx_col_wise(vc->length); vrna_hc_init(vc); /* add DP matrices */ vrna_mx_mfe_add(vc, VRNA_MX_DEFAULT, 0); } PRIVATE void halfseq(vrna_fold_compound_t *vc) { unsigned int halflength; halflength = vc->length / 2; vc->sequence = vrna_realloc(vc->sequence, sizeof(char) * (halflength + 1)); vc->sequence[halflength] = '\0'; vc->length = (unsigned int)strlen(vc->sequence); vc->cutpoint = -1; vc->strands = 1; vc->strand_number = (unsigned int *)vrna_realloc(vc->strand_number, sizeof(unsigned int) * (vc->length + 1)); vc->strand_order = (unsigned int *)vrna_realloc(vc->strand_order, sizeof(unsigned int) * (vc->strands + 1)); vc->strand_start = (unsigned int *)vrna_realloc(vc->strand_start, sizeof(unsigned int) * (vc->strands + 1)); vc->strand_end = (unsigned int *)vrna_realloc(vc->strand_end, sizeof(unsigned int) * (vc->strands + 1)); vc->sequence_encoding = vrna_realloc(vc->sequence_encoding, sizeof(short) * (vc->length + 2)); vc->sequence_encoding[0] = vc->sequence_encoding[vc->length]; vc->sequence_encoding[vc->length + 1] = vc->sequence_encoding[1]; vc->sequence_encoding2 = vrna_realloc(vc->sequence_encoding2, sizeof(short) * (vc->length + 2)); vc->sequence_encoding2[0] = vc->length; vc->sequence_encoding2[vc->length + 1] = 0; free(vc->ptype); vc->ptype = vrna_ptypes(vc->sequence_encoding2, &(vc->params->model_details)); free(vc->iindx); vc->iindx = vrna_idx_row_wise(vc->length); free(vc->jindx); vc->jindx = vrna_idx_col_wise(vc->length); vrna_hc_init(vc); /* add DP matrices */ vrna_mx_mfe_add(vc, VRNA_MX_DEFAULT, 0); } typedef struct { int i; int j; int e; int idxj; } zuker_pair; PRIVATE int comp_pair(const void *A, const void *B) { zuker_pair *x, *y; int ex, ey; x = (zuker_pair *)A; y = (zuker_pair *)B; ex = x->e; ey = y->e; if (ex > ey) return 1; if (ex < ey) return -1; return x->idxj + x->i - y->idxj + y->i; } PUBLIC SOLUTION * vrna_subopt_zuker(vrna_fold_compound_t *vc) { /* Compute zuker suboptimal. Here, we're abusing the cofold() code * "double" sequence, compute dimerarray entries, track back every base pair. * This is slightly wasteful compared to the normal solution */ char *structure, *mfestructure, **todo, *ptype; int i, j, counter, num_pairs, psize, p, *indx, *c, turn; unsigned int length, doublelength; float energy; SOLUTION *zukresults; vrna_bp_stack_t *bp_list; zuker_pair *pairlist; sect bt_stack[MAXSECTORS]; /* stack of partial structures for backtracking */ vrna_mx_mfe_t *matrices; vrna_md_t *md; md = &(vc->params->model_details); turn = md->min_loop_size; /* do some magic to re-use cofold code although vc is single sequence */ md->min_loop_size = 0; doubleseq(vc); if (!vrna_fold_compound_prepare(vc, VRNA_OPTION_MFE | VRNA_OPTION_HYBRID)) { vrna_message_warning("vrna_subopt_zuker@cofold.c: Failed to prepare vrna_fold_compound"); return NULL; } doublelength = vc->length; length = doublelength / 2; indx = vc->jindx; ptype = vc->ptype; matrices = vc->matrices; c = matrices->c; num_pairs = counter = 0; mfestructure = (char *)vrna_alloc((unsigned)doublelength + 1); structure = (char *)vrna_alloc((unsigned)doublelength + 1); zukresults = (SOLUTION *)vrna_alloc(((length * (length - 1)) / 2) * sizeof(SOLUTION)); mfestructure[0] = '\0'; /* store length at pos. 0 */ vc->sequence_encoding[0] = vc->sequence_encoding2[0]; /* get mfe and do forward recursion */ (void)fill_arrays(vc, 1); psize = length; pairlist = (zuker_pair *)vrna_alloc(sizeof(zuker_pair) * (psize + 1)); bp_list = (vrna_bp_stack_t *)vrna_alloc(sizeof(vrna_bp_stack_t) * (1 + length / 2)); todo = (char **)vrna_alloc(sizeof(char *) * (length + 1)); for (i = 1; i < length; i++) todo[i] = (char *)vrna_alloc(sizeof(char) * (length + 1)); /* Make a list of all base pairs */ for (i = 1; i < length; i++) { for (j = i + turn + 1 /*??*/; j <= length; j++) { if (ptype[indx[j] + i] == 0) continue; if (num_pairs >= psize) { psize = 1.2 * psize + 32; pairlist = vrna_realloc(pairlist, sizeof(zuker_pair) * (psize + 1)); } pairlist[num_pairs].i = i; pairlist[num_pairs].j = j; pairlist[num_pairs].e = c[indx[j] + i] + c[indx[i + length] + j]; pairlist[num_pairs++].idxj = indx[j]; todo[i][j] = 1; } } qsort(pairlist, num_pairs, sizeof(zuker_pair), comp_pair); for (p = 0; p < num_pairs; p++) { i = pairlist[p].i; j = pairlist[p].j; if (todo[i][j]) { int k; char *sz; bt_stack[1].i = i; bt_stack[1].j = j; bt_stack[1].ml = 2; backtrack_co(bt_stack, bp_list, 1, 0, vc); bt_stack[1].i = j; bt_stack[1].j = i + length; bt_stack[1].ml = 2; backtrack_co(bt_stack, bp_list, 1, bp_list[0].i, vc); energy = pairlist[p].e; sz = vrna_db_from_bp_stack(bp_list, length); zukresults[counter].energy = energy / 100.; zukresults[counter++].structure = sz; for (k = 1; k <= bp_list[0].i; k++) { /* mark all pairs in structure as done */ int x, y; x = bp_list[k].i; y = bp_list[k].j; if (x > length) x -= length; if (y > length) y -= length; if (x > y) { int temp; temp = x; x = y; y = temp; } todo[x][y] = 0; } } } /* clean up */ free(pairlist); for (i = 1; i < length; i++) free(todo[i]); free(todo); free(structure); free(mfestructure); free(bp_list); /* undo magic */ halfseq(vc); md->min_loop_size = turn; return zukresults; } /* *########################################### *# deprecated functions below # *########################################### */ #ifndef VRNA_DISABLE_BACKWARD_COMPATIBILITY PRIVATE void wrap_array_export(int **f5_p, int **c_p, int **fML_p, int **fM1_p, int **fc_p, int **indx_p, char **ptype_p) { /* make the DP arrays available to routines such as subopt() */ if (backward_compat_compound) { *f5_p = backward_compat_compound->matrices->f5; *c_p = backward_compat_compound->matrices->c; *fML_p = backward_compat_compound->matrices->fML; *fM1_p = backward_compat_compound->matrices->fM1; *fc_p = backward_compat_compound->matrices->fc; *indx_p = backward_compat_compound->jindx; *ptype_p = backward_compat_compound->ptype; } } /*--------------------------------------------------------------------------*/ PRIVATE float wrap_cofold(const char *string, char *structure, vrna_param_t *parameters, int is_constrained) { unsigned int length; char *seq; vrna_fold_compound_t *vc; vrna_param_t *P; float mfe; vc = NULL; length = strlen(string); #ifdef _OPENMP /* Explicitly turn off dynamic threads */ omp_set_dynamic(0); #endif /* we need the parameter structure for hard constraints */ if (parameters) { P = vrna_params_copy(parameters); } else { vrna_md_t md; set_model_details(&md); md.temperature = temperature; P = vrna_params(&md); } P->model_details.min_loop_size = 0; /* set min loop length to 0 */ /* dirty hack to reinsert the '&' according to the global variable 'cut_point' */ seq = vrna_cut_point_insert(string, cut_point); /* get compound structure */ vc = vrna_fold_compound(seq, &(P->model_details), 0); if (parameters) { /* replace params if necessary */ free(vc->params); vc->params = P; } else { free(P); } /* handle hard constraints in pseudo dot-bracket format if passed via simple interface */ if (is_constrained && structure) { unsigned int constraint_options = 0; constraint_options |= VRNA_CONSTRAINT_DB | VRNA_CONSTRAINT_DB_PIPE | VRNA_CONSTRAINT_DB_DOT | VRNA_CONSTRAINT_DB_X | VRNA_CONSTRAINT_DB_ANG_BRACK | VRNA_CONSTRAINT_DB_RND_BRACK | VRNA_CONSTRAINT_DB_INTRAMOL | VRNA_CONSTRAINT_DB_INTERMOL; vrna_constraints_add(vc, (const char *)structure, constraint_options); } if (backward_compat_compound) vrna_fold_compound_free(backward_compat_compound); backward_compat_compound = vc; backward_compat = 1; /* cleanup */ free(seq); /* call mfe_dimer without backtracing */ mfe = vrna_mfe_dimer(vc, NULL); /* now we backtrace in a backward compatible way */ if (structure && vc->params->model_details.backtrack) { char *s; sect bt_stack[MAXSECTORS]; vrna_bp_stack_t *bp; bp = (vrna_bp_stack_t *)vrna_alloc(sizeof(vrna_bp_stack_t) * (4 * (1 + length / 2))); /* add a guess of how many G's may be involved in a G quadruplex */ backtrack(bt_stack, bp, vc); s = vrna_db_from_bp_stack(bp, length); strncpy(structure, s, length + 1); free(s); if (base_pair) free(base_pair); base_pair = bp; } return mfe; } PRIVATE SOLUTION * wrap_zukersubopt(const char *string, vrna_param_t *parameters) { vrna_fold_compound_t *vc; vrna_param_t *P; vc = NULL; #ifdef _OPENMP /* Explicitly turn off dynamic threads */ omp_set_dynamic(0); #endif /* we need the parameter structure for hard constraints */ if (parameters) { P = vrna_params_copy(parameters); } else { vrna_md_t md; set_model_details(&md); md.temperature = temperature; P = vrna_params(&md); } /* get compound structure */ vc = vrna_fold_compound(string, &(P->model_details), VRNA_OPTION_DEFAULT); if (parameters) { /* replace params if necessary */ free(vc->params); vc->params = P; } else { free(P); } if (backward_compat_compound) vrna_fold_compound_free(backward_compat_compound); backward_compat_compound = vc; backward_compat = 1; return vrna_subopt_zuker(vc); } PUBLIC void initialize_cofold(int length) { /* DO NOTHING */ } PUBLIC void free_co_arrays(void) { if (backward_compat_compound && backward_compat) { vrna_fold_compound_free(backward_compat_compound); backward_compat_compound = NULL; backward_compat = 0; } } /*--------------------------------------------------------------------------*/ PUBLIC void export_cofold_arrays_gq(int **f5_p, int **c_p, int **fML_p, int **fM1_p, int **fc_p, int **ggg_p, int **indx_p, char **ptype_p) { /* make the DP arrays available to routines such as subopt() */ wrap_array_export(f5_p, c_p, fML_p, fM1_p, fc_p, indx_p, ptype_p); if (backward_compat_compound) *ggg_p = backward_compat_compound->matrices->ggg; } PUBLIC void export_cofold_arrays(int **f5_p, int **c_p, int **fML_p, int **fM1_p, int **fc_p, int **indx_p, char **ptype_p) { wrap_array_export(f5_p, c_p, fML_p, fM1_p, fc_p, indx_p, ptype_p); } PUBLIC float cofold(const char *string, char *structure) { return wrap_cofold(string, structure, NULL, fold_constrained); } PUBLIC float cofold_par(const char *string, char *structure, vrna_param_t *parameters, int is_constrained) { return wrap_cofold(string, structure, parameters, is_constrained); } PUBLIC SOLUTION * zukersubopt(const char *string) { return wrap_zukersubopt(string, NULL); } PUBLIC SOLUTION * zukersubopt_par(const char *string, vrna_param_t *parameters) { return wrap_zukersubopt(string, parameters); } PUBLIC void update_cofold_params(void) { vrna_fold_compound_t *v; if (backward_compat_compound && backward_compat) { vrna_md_t md; v = backward_compat_compound; if (v->params) free(v->params); set_model_details(&md); v->params = vrna_params(&md); } } PUBLIC void update_cofold_params_par(vrna_param_t *parameters) { vrna_fold_compound_t *v; if (backward_compat_compound && backward_compat) { v = backward_compat_compound; if (v->params) free(v->params); if (parameters) { v->params = vrna_params_copy(parameters); } else { vrna_md_t md; set_model_details(&md); md.temperature = temperature; v->params = vrna_params(&md); } } } PUBLIC void get_monomere_mfes(float *e1, float *e2) { /*exports monomere free energies*/ *e1 = mfe1; *e2 = mfe2; } #endif
sms4speed.c
/* ==================================================================== * Copyright (c) 2014 - 2017 The GmSSL Project. All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * * 1. Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in * the documentation and/or other materials provided with the * distribution. * * 3. All advertising materials mentioning features or use of this * software must display the following acknowledgment: * "This product includes software developed by the GmSSL Project. * (http://gmssl.org/)" * * 4. The name "GmSSL Project" must not be used to endorse or promote * products derived from this software without prior written * permission. For written permission, please contact * guanzhi1980@gmail.com. * * 5. Products derived from this software may not be called "GmSSL" * nor may "GmSSL" appear in their names without prior written * permission of the GmSSL Project. * * 6. Redistributions of any form whatsoever must retain the following * acknowledgment: * "This product includes software developed by the GmSSL Project * (http://gmssl.org/)" * * THIS SOFTWARE IS PROVIDED BY THE GmSSL PROJECT ``AS IS'' AND ANY * EXPRESSED 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 GmSSL PROJECT OR * ITS 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 <stdio.h> #include <stdlib.h> #include <string.h> #include <libgen.h> #include <openmp.h> #include <openssl/sms4.h> int main(int argc, char **argv) { sms4_key_t sms4_key; unsigned char user_key[16] = { 0x11, 0x22, 0x33, 0x44, 0x55, 0x66, 0x77, 0x88, 0x11, 0x22, 0x33, 0x44, 0x55, 0x66, 0x77, 0x88, }; size_t buflen = SMS4_BLOCK_SIZE * 8 * 3 * 1000 * 1000; unsigned char *buf = NULL; unsigned char *p; int i; if (!(buf = (unsigned char *)malloc(buflen))) { fprintf(stderr, "malloc failed\n"); return -1; } sms4_set_encrypt_key(&sms4_key, user_key); #pragma omp parallel for for (i = 0, p = buf; i < buflen/(SMS4_BLOCK_SIZE * 16); i++, p += SMS4_BLOCK_SIZE * 16) { sms4_encrypt_16blocks(&sms4_key, p, p); } return 0; }
el2d_openmp.c
#include<stdio.h> #include"2d_lib.c" // vx void el2d_openmp(double *vx, int BD_nx_vx, int BD_nz_vx, double *pvxbtxx, double *pvxbtxz, double *vz, int BD_nx_vz, int BD_nz_vz, double *pvzbtxz, double *pvzbtzz, double *txx, double *ptxxbvx, double *ptxxbvz, double *tzz, double *ptzzbvx, double *ptzzbvz, int BD_nx_tpp, int BD_nz_tpp, double *txz, int BD_nx_txz, int BD_nz_txz, double *ptxzbvx, double *ptxzbvz, double *rho, double *lambda, double *mu, double *fdc, double dt, double dx, double dz, int ext, double *bhalf, double *ahalf, double *bfull, double *afull) { int i,j; //********************* V_X *********************// #pragma omp parallel { // vxbtxx #pragma omp for private(j) nowait for(i=0; i<BD_nz_vx; i++) { for(j=1; j<ext; j++) { bound_x_2d(vx, BD_nz_vx, BD_nx_vx, i, j, txx, BD_nz_tpp, BD_nx_tpp, 1, 2.0/(*(rho+i+j*BD_nz_tpp)+*(rho+i+(j+1)*BD_nz_tpp)), 2.0/(*(rho+i+(BD_nx_vx-1-j)*BD_nz_tpp)+*(rho+i+(BD_nx_vx-j)*BD_nz_tpp)), dx, dt, pvxbtxx, bhalf, ahalf, ext, fdc); } for(j=ext; j<BD_nx_vx-ext; j++) { body_x_2d(vx, BD_nz_vx, BD_nx_vx, i, j, txx, BD_nz_tpp, BD_nx_tpp, 1, 2.0/(*(rho+i+j*BD_nz_tpp)+*(rho+i+(j+1)*BD_nz_tpp)), dx, dt, fdc); } } // vzbtxz #pragma omp for private(j) nowait for(i=0; i<BD_nz_vz; i++) { for(j=2; j<ext; j++) { bound_x_2d(vz, BD_nz_vz, BD_nx_vz, i, j, txz, BD_nz_txz, BD_nx_txz, 2, 2.0/(*(rho+i+j*BD_nz_tpp)+*(rho+(i+1)+j*BD_nz_tpp)), 2.0/(*(rho+i+(BD_nx_vz-1-j)*BD_nz_tpp)+*(rho+(i+1)+(BD_nx_vz-1-j)*BD_nz_tpp)), dx,dt, pvzbtxz, bfull, afull, ext, fdc); } for(j=ext; j<BD_nx_vz-ext; j++) { body_x_2d(vz, BD_nz_vz, BD_nx_vz, i, j, txz, BD_nz_txz, BD_nx_txz, 2, 2.0/(*(rho+i+j*BD_nz_tpp)+*(rho+(i+1)+j*BD_nz_tpp)), dx, dt, fdc); } } #pragma omp barrier //********************* V_Z *********************// // vxbtxz #pragma omp for private(i) nowait for(j=0; j<BD_nx_vx; j++) { for(i=2; i<ext; i++) { unlimited_bound_z_2d(vx, BD_nz_vx, BD_nx_vx, i, j, txz, BD_nz_txz, BD_nx_txz, 2, 2.0/(*(rho+i+j*BD_nz_tpp)+*(rho+i+(j+1)*BD_nz_tpp)), 2.0/(*(rho+(BD_nz_vx-1-i)+j*BD_nz_tpp)+*(rho+(BD_nz_vx-1-i)+(j+1)*BD_nz_tpp)), dz,dt, pvxbtxz, bfull, afull, ext, fdc); } for(i=ext; i<BD_nz_vx-ext; i++) { body_z_2d(vx, BD_nz_vx, BD_nx_vx, i, j, txz, BD_nz_txz, BD_nx_txz, 2, 2.0/(*(rho+i+j*BD_nz_tpp)+*(rho+i+(j+1)*BD_nz_tpp)), dz,dt, fdc); } } // vzbtzz #pragma omp for private(i) nowait for(j=0; j<BD_nx_vz; j++) { for(i=1;i<ext;i++) { unlimited_bound_z_2d(vz, BD_nz_vz, BD_nx_vz, i, j, tzz, BD_nz_tpp, BD_nx_tpp, 1, 2.0/(*(rho+i+j*BD_nz_tpp)+*(rho+(i+1)+j*BD_nz_tpp)), 2.0/(*(rho+(BD_nz_vz-1-i)+j*BD_nz_tpp)+*(rho+(BD_nz_vz-i)+j*BD_nz_tpp)), dz,dt, pvzbtzz, bhalf, ahalf, ext, fdc); } for(i=ext; i<BD_nz_vz-ext; i++) { body_z_2d(vz, BD_nz_vz, BD_nx_vz, i, j, tzz, BD_nz_tpp, BD_nx_tpp, 1, 2.0/(*(rho+i+j*BD_nz_tpp)+*(rho+(i+1)+j*BD_nz_tpp)), dz,dt, fdc); } } #pragma omp barrier //************ T_X ************// #pragma omp for private(j) nowait for(i=0; i<BD_nz_tpp; i++) { for(j=2; j<ext; j++) { el_bound_tpp_x_2d(txx, tzz, BD_nz_tpp, BD_nx_tpp, i, j, vx, BD_nz_vx, BD_nx_vx, 2, lambda, mu, dx, dt, ptxxbvx, ptzzbvx, bfull, afull, ext, fdc); } for(j=ext; j<BD_nx_tpp-ext; j++) { el_body_tpp_x_2d(txx, tzz, BD_nz_tpp, BD_nx_tpp, i, j, vx, BD_nz_vx, BD_nx_vx, 2, lambda, mu, dx, dt, fdc); } } #pragma omp for private(j) nowait for(i=0; i<BD_nz_txz; i++) { for(j=1; j<ext; j++) { bound_x_2d(txz, BD_nz_txz, BD_nx_txz, i, j, vz, BD_nz_vz, BD_nx_vz, 1, (*(mu+i+j*BD_nz_tpp) + *(mu+i+(j+1)*BD_nz_tpp) + *(mu+(i+1)+(j+1)*BD_nz_tpp) + *(mu+(i+1)+j*BD_nz_tpp))/4, (*(mu+i+(BD_nx_txz-1-j)*BD_nz_tpp) + *(mu+i+(BD_nx_txz-j)*BD_nz_tpp) + *(mu+(i+1)+(BD_nx_txz-j)*BD_nz_tpp) + *(mu+(i+1)+(BD_nx_txz-1-j)*BD_nz_tpp))/4, dx, dt, ptxzbvz, bhalf, ahalf, ext, fdc); } for(j=ext; j<BD_nx_txz-ext; j++) { body_x_2d(txz, BD_nz_txz, BD_nx_txz, i, j, vz, BD_nz_vz, BD_nx_vz, 1, (*(mu+i+j*BD_nz_tpp) + *(mu+i+(j+1)*BD_nz_tpp) + *(mu+(i+1)+(j+1)*BD_nz_tpp) + *(mu+(i+1)+j*BD_nz_tpp))/4, dx, dt, fdc); } } #pragma omp barrier //************ T_Z ************// #pragma omp for private(i) nowait for(j=0; j<BD_nx_tpp; j++) { for(i=2; i<ext; i++) { el_unlimited_bound_tpp_z_2d(txx, tzz, BD_nz_tpp, BD_nx_tpp, i, j, vz, BD_nz_vz, BD_nx_vz, 2, lambda, mu, dz, dt, ptxxbvz, ptzzbvz, bfull, afull, ext, fdc); } for(i=ext; i<BD_nz_tpp-ext; i++) { el_body_tpp_z_2d(txx, tzz, BD_nz_tpp, BD_nx_tpp, i, j, vz, BD_nz_vz, BD_nx_vz, 2, lambda, mu, dz, dt, fdc); } } #pragma omp for private(i) nowait for(j=0; j<BD_nx_txz; j++) { for(i=1; i<ext; i++) { unlimited_bound_z_2d(txz, BD_nz_txz, BD_nx_txz, i, j, vx, BD_nz_vx, BD_nx_vx, 1, (*(mu+i+j*BD_nz_tpp) + *(mu+i+(j+1)*BD_nz_tpp) + *(mu+(i+1)+(j+1)*BD_nz_tpp) + *(mu+(i+1)+j*BD_nz_tpp))/4, (*(mu+(BD_nz_txz-1-i)+j*BD_nz_tpp) + *(mu+(BD_nz_txz-1-i)+(j+1)*BD_nz_tpp) + *(mu+(BD_nz_txz-i)+(j+1)*BD_nz_tpp) + *(mu+(BD_nz_txz-i)+j*BD_nz_tpp))/4, dz, dt, ptxzbvx, bhalf, ahalf, ext, fdc); } for(i=ext; i<BD_nz_txz-ext; i++) { body_z_2d(txz, BD_nz_txz, BD_nx_txz, i, j, vx, BD_nz_vx, BD_nx_vx, 1, (*(mu+i+j*BD_nz_tpp) + *(mu+i+(j+1)*BD_nz_tpp) + *(mu+(i+1)+(j+1)*BD_nz_tpp) + *(mu+(i+1)+j*BD_nz_tpp))/4, dz, dt, fdc); } } } }
omp2.c
// note not doing O0 below as to ensure we get tbaa // TODO: %clang -fopenmp -std=c11 -fno-vectorize -fno-unroll-loops -O1 -disable-llvm-optzns %s -S -emit-llvm -o - | %opt - %loadEnzyme -enzyme -S | %clang -fopenmp -x ir - -o %s.out && %s.out // RUN: %clang -fopenmp -std=c11 -fno-vectorize -fno-unroll-loops -O1 %s -S -emit-llvm -o - | %opt - %loadEnzyme -enzyme -S | %clang -fopenmp -x ir - -o %s.out && %s.out // RUN: %clang -fopenmp -std=c11 -fno-vectorize -fno-unroll-loops -O2 %s -S -emit-llvm -o - | %opt - %loadEnzyme -enzyme -S | %clang -fopenmp -x ir - -o %s.out && %s.out // RUN: %clang -fopenmp -std=c11 -fno-vectorize -fno-unroll-loops -O3 %s -S -emit-llvm -o - | %opt - %loadEnzyme -enzyme -S | %clang -fopenmp -x ir - -o %s.out && %s.out // note not doing O0 below as to ensure we get tbaa // TODO: %clang -fopenmp -std=c11 -fno-vectorize -fno-unroll-loops -O1 -Xclang -disable-llvm-optzns %s -S -emit-llvm -o - | %opt - %loadEnzyme -enzyme -enzyme-inline=1 -S | %clang -fopenmp -x ir - -o %s.out && %s.out // RUN: %clang -fopenmp -std=c11 -fno-vectorize -fno-unroll-loops -O1 %s -S -emit-llvm -o - | %opt - %loadEnzyme -enzyme -enzyme-inline=1 -S | %clang -fopenmp -x ir - -o %s.out && %s.out // RUN: %clang -fopenmp -std=c11 -fno-vectorize -fno-unroll-loops -O2 %s -S -emit-llvm -o - | %opt - %loadEnzyme -enzyme -enzyme-inline=1 -S | %clang -fopenmp -x ir - -o %s.out && %s.out // RUN: %clang -fopenmp -std=c11 -fno-vectorize -fno-unroll-loops -O3 %s -S -emit-llvm -o - | %opt - %loadEnzyme -enzyme -enzyme-inline=1 -S | %clang -fopenmp -x ir - -o %s.out && %s.out #include <stdio.h> #include <math.h> #include <assert.h> #include "test_utils.h" double __enzyme_autodiff(void*, ...); /* void omp(float& a, int N) { #define N 20 #pragma omp parallel for for (int i=0; i<N; i++) { //a[i] *= a[i]; (&a)[i] *= (&a)[i]; } #undef N (&a)[0] = 0; } */ void omp(float* a, int N, int M) { #pragma omp parallel for #pragma nounroll for (unsigned int i=M; i<N; i++) { //a[i] *= a[i]; a[i] *= a[i]; } a[0] = 0; } int main(int argc, char** argv) { int N = 20; int M = 10; float a[N]; for(int i=0; i<N; i++) { a[i] = i+1; } float d_a[N]; for(int i=0; i<N; i++) d_a[i] = 1.0f; //omp(*a, N); printf("ran omp\n"); __enzyme_autodiff((void*)omp, a, d_a, N, M); for(int i=0; i<N; i++) { printf("a[%d]=%f d_a[%d]=%f\n", i, a[i], i, d_a[i]); } //APPROX_EQ(da, 17711.0*2, 1e-10); //APPROX_EQ(db, 17711.0*2, 1e-10); //printf("hello! %f, res2 %f, da: %f, db: %f\n", ret, ret, da,db); APPROX_EQ(d_a[0], 0.0f, 1e-10); for(int i=1; i<N; i++) { if (i < M) { APPROX_EQ(d_a[i], 1.0f, 1e-10); } else { APPROX_EQ(d_a[i], 2.0f*(i+1), 1e-10); } } return 0; }
GB_unop__exp2_fc64_fc64.c
//------------------------------------------------------------------------------ // GB_unop: hard-coded functions for each built-in unary 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_atomics.h" #include "GB_unop__include.h" // C=unop(A) is defined by the following types and operators: // op(A) function: GB (_unop_apply__exp2_fc64_fc64) // op(A') function: GB (_unop_tran__exp2_fc64_fc64) // C type: GxB_FC64_t // A type: GxB_FC64_t // cast: GxB_FC64_t cij = aij // unaryop: cij = GB_cexp2 (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 = GB_cexp2 (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] = GB_cexp2 (z) ; \ } // true if operator is the identity op with no typecasting #define GB_OP_IS_IDENTITY_WITH_NO_TYPECAST \ 0 // disable this operator and use the generic case if these conditions hold #define GB_DISABLE \ (GxB_NO_EXP2 || GxB_NO_FC64) //------------------------------------------------------------------------------ // Cx = op (cast (Ax)): apply a unary operator //------------------------------------------------------------------------------ GrB_Info GB (_unop_apply__exp2_fc64_fc64) ( GxB_FC64_t *Cx, // Cx and Ax may be aliased const GxB_FC64_t *Ax, const int8_t *restrict Ab, // A->b if A is bitmap int64_t anz, int nthreads ) { #if GB_DISABLE return (GrB_NO_VALUE) ; #else int64_t p ; // TODO: if OP is ONE and uniform-valued matrices are exploited, then // do this in O(1) time if (Ab == NULL) { #if ( GB_OP_IS_IDENTITY_WITH_NO_TYPECAST ) GB_memcpy (Cx, Ax, anz * sizeof (GxB_FC64_t), nthreads) ; #else #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] = GB_cexp2 (z) ; } #endif } else { // bitmap case, no transpose; A->b already memcpy'd into C->b #pragma omp parallel for num_threads(nthreads) schedule(static) for (p = 0 ; p < anz ; p++) { if (!Ab [p]) continue ; GxB_FC64_t aij = Ax [p] ; GxB_FC64_t z = aij ; Cx [p] = GB_cexp2 (z) ; } } return (GrB_SUCCESS) ; #endif } //------------------------------------------------------------------------------ // C = op (cast (A')): transpose, typecast, and apply a unary operator //------------------------------------------------------------------------------ GrB_Info GB (_unop_tran__exp2_fc64_fc64) ( GrB_Matrix C, const GrB_Matrix A, int64_t *restrict *Workspaces, const int64_t *restrict A_slice, int nworkspaces, int nthreads ) { #if GB_DISABLE return (GrB_NO_VALUE) ; #else #include "GB_unop_transpose.c" return (GrB_SUCCESS) ; #endif } #endif
omp-loop02.c
#include <omp.h> /* Orphaned work sharing. */ extern void abort (void); #define N 10 void parloop (int *a) { int i; #pragma omp for for (i = 0; i < N; i++) a[i] = i + 3; } main() { int i, a[N]; #pragma omp parallel shared(a) { parloop (a); } for (i = 0; i < N; i++) if (a[i] != i + 3) abort (); return 0; }
convolution_3x3_pack1to8_int8.h
// Tencent is pleased to support the open source community by making ncnn available. // // Copyright (C) 2021 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 conv3x3s1_pack1to8_int8_neon(const Mat& bottom_blob, Mat& top_blob, const Mat& kernel, const Option& opt) { int w = bottom_blob.w; int inch = bottom_blob.c; int outw = top_blob.w; int outh = top_blob.h; const int size = outw * outh; const int maxk = 9; // im2col Mat bottom_im2col(size, maxk, inch, 1u, 1, opt.workspace_allocator); { const int gap = w - outw; #pragma omp parallel for num_threads(opt.num_threads) for (int p = 0; p < inch; p++) { const Mat img = bottom_blob.channel(p); signed char* ptr = bottom_im2col.channel(p); for (int u = 0; u < 3; u++) { for (int v = 0; v < 3; v++) { const signed char* sptr = img.row<const signed char>(u) + v; for (int i = 0; i < outh; i++) { int j = 0; for (; j + 3 < outw; j += 4) { ptr[0] = sptr[0]; ptr[1] = sptr[1]; ptr[2] = sptr[2]; ptr[3] = sptr[3]; sptr += 4; ptr += 4; } for (; j + 1 < outw; j += 2) { ptr[0] = sptr[0]; ptr[1] = sptr[1]; sptr += 2; ptr += 2; } for (; j < outw; j++) { ptr[0] = sptr[0]; sptr += 1; ptr += 1; } sptr += gap; } } } } } im2col_sgemm_pack1to8_int8_neon(bottom_im2col, top_blob, kernel, opt); } static void conv3x3s2_pack1to8_int8_neon(const Mat& bottom_blob, Mat& top_blob, const Mat& kernel, const Option& opt) { int w = bottom_blob.w; int inch = bottom_blob.c; int outw = top_blob.w; int outh = top_blob.h; const int size = outw * outh; const int maxk = 9; // im2col Mat bottom_im2col(size, maxk, inch, 1u, 1, opt.workspace_allocator); { const int gap = w * 2 - outw * 2; #pragma omp parallel for num_threads(opt.num_threads) for (int p = 0; p < inch; p++) { const Mat img = bottom_blob.channel(p); signed char* ptr = bottom_im2col.channel(p); for (int u = 0; u < 3; u++) { for (int v = 0; v < 3; v++) { const signed char* sptr = img.row<const signed char>(u) + v; for (int i = 0; i < outh; i++) { int j = 0; for (; j + 3 < outw; j += 4) { ptr[0] = sptr[0]; ptr[1] = sptr[2]; ptr[2] = sptr[4]; ptr[3] = sptr[6]; sptr += 8; ptr += 4; } for (; j + 1 < outw; j += 2) { ptr[0] = sptr[0]; ptr[1] = sptr[2]; sptr += 4; ptr += 2; } for (; j < outw; j++) { ptr[0] = sptr[0]; sptr += 2; ptr += 1; } sptr += gap; } } } } } im2col_sgemm_pack1to8_int8_neon(bottom_im2col, top_blob, kernel, opt); }
gmx_isdcmds.c
/* * * Tim Connolly - tconnolly@ucmerced.edu * Copyright (c) 2014, Regents of the University of California * Released under BSD 2-Clause License (see "LICENSE" file) * * This code was modified from the file src/tools/gmx_gyrate.c */ #include <math.h> #include <string.h> #include "libisdm.h" #include "eigensolver.h" #include <gromacs/statutil.h> #include <gromacs/sysstuff.h> #include <gromacs/typedefs.h> #include <gromacs/smalloc.h> #include <gromacs/macros.h> #include <gromacs/vec.h> #include <gromacs/pbc.h> #include <gromacs/copyrite.h> #include <gromacs/futil.h> #include <gromacs/statutil.h> #include <gromacs/index.h> #include <gromacs/mshift.h> #include <gromacs/xvgr.h> #include <gromacs/rmpbc.h> #include <gromacs/txtdump.h> #include <gromacs/tpxio.h> #include <gromacs/gstat.h> #include <gromacs/gmx_ana.h> void mat_mult_mat(real* mat1, real* mat2, int m, int n, int o, real* out, gmx_bool bMP) { /* Assume a is an array of doubles m by n in dimensions. * Assume b is an array of doubles n by o in dimensions. * Out should point to enough memory to store m by o doubles. */ int i, percent_calcs, finished_calcs; percent_calcs = 1; finished_calcs = 0; #pragma omp parallel for schedule(dynamic) if (bMP) for (i = 0; i < m; i++) { int j, k; for (k = 0; k < o; k++) { out[(i * m) + k] = 0; for (j = 0; j < n; j++) { out[(i * m) + k] += mat1[(i * m) + j] * mat2[(j * n) + k]; } } // Output progress. OpenMP critical section. #pragma omp critical { finished_calcs++; while ((double)(finished_calcs) / m >= (double)percent_calcs / 100) { fprintf(stderr, "Approximately %i percent complete. \r", percent_calcs); percent_calcs++; } } // End of OpenMP critical section. } // End of OpenMP parallel for loop. fprintf(stderr, "\n"); } void scl_mult_mat(real scl, real* mat, int m, int n, real* out) { /* Multiply all elements of matrix mat by scalar scl. * * This should still work even if mat and out point to the same thing. */ int i, j; for (i = 0; i < m; i++) { for (j = 0; j < n; j++) { out[(i * m) + j] = scl * mat[(i * m) + j]; } } } void mat_transpose(real* mat, int m,int n, real* out) { /* Transpose m by n array of reals a into n by m array of reals out. */ int i, j; for (i = 0; i < m; i++) { for (j = 0; j < n; j++) { out[(j * n) + i] = mat[(i * m) + j]; } } } void calc_EISD(real** MDS, int nframes, int d, real** EISD) { /* Calculate the approximate ISD from the euclidean dimensionally reduced * coordinates in MDS. Uses the number of dimensions specified by d. The * number of structures is specified by nframes, and EISD should be a * matrix of nframes x nframes. */ int i, j, k; real kEISD; for (i = 0; i < nframes; i++) { for (j = 0; j < nframes; j++) { // Same structure. if (i == j) { EISD[i][j] = 0.0; continue; } // Different structures. EISD[i][j] = 0.0; for (k = 0; k < d; k++) { kEISD = MDS[i][k] - MDS[j][k]; EISD[i][j] += kEISD * kEISD; } EISD[i][j] = sqrt(EISD[i][j]); } } } real calc_rcc(real** ISD, real** EISD, int nframes) { int i, j; int N = nframes * (nframes - 1) / 2; double sCov, sISD, sEISD, sISD2, sEISD2, mISD, mEISD, vISD, vEISD; sCov = 0.0; sISD = 0.0; sEISD = 0.0; sISD2 = 0.0; sEISD2 = 0.0; // Variances, means, and the means of squares. for (i = 0; i < (nframes - 1); i++) { for (j = (i + 1); j < nframes; j++) { sISD += ISD[i][j]; sEISD += EISD[i][j]; sISD2 += ISD[i][j] * ISD[i][j]; sEISD2 += EISD[i][j] * EISD[i][j]; } } mISD = sISD / N; mEISD = sEISD / N; vISD = (sISD2 / N) - (mISD * mISD); vEISD = (sEISD2 / N) - (mEISD * mEISD); // Covariance. for (i = 0; i < (nframes - 1); i++) { for (j = (i + 1); j < nframes; j++) { sCov += (ISD[i][j] - mISD) * (EISD[i][j] - mEISD); } } // Correlation coefficient, R. return (sCov / N) / (sqrt(vISD) * sqrt(vEISD)); } int gmx_isdcmds(int argc,char *argv[]) { const char *desc[] = { "[TT]g_isdcmds[tt] implements classical multi-dimensional scaling ", "by first calculating the matrix of inter-structure distances (ISD). ", "The default ISDM if one is not, chosen by the user is RMSD. Only ", "one ISDM can be chosen at a time. The -xpm option is required. An ", "upper threshold for the ISD can be specified with the setmax option." }; static gmx_bool bANG=FALSE, bDIH=FALSE, bANGDIH=FALSE, bDRMS=FALSE; static gmx_bool bPHIPSI=FALSE, bSRMS=FALSE, bPCOR=FALSE, bMAMMOTH=FALSE; static gmx_bool bACOR=FALSE, bESA=FALSE, bRMSD=FALSE, bMIR=FALSE; static gmx_bool bRG=FALSE, bSRG=FALSE, bE2E=FALSE, bSE2E=FALSE; static gmx_bool bANG2=FALSE, bDIH2=FALSE, bANGDIH2=FALSE, bANGDIH2G=FALSE; static gmx_bool bRROT=FALSE, bSDRMS=FALSE, bPHIPSI2=FALSE, bRMSDIH=FALSE; static int nt = -1; static real setmax = -1.0; static real rcutoff = 1.1; static real noisefloor = 0.0; static gmx_bool bNoise = FALSE; static gmx_bool bMP = FALSE; t_pargs pa[] = { { "-ang", FALSE, etBOOL, {&bANG}, "ISDM: Mean cosine of difference of backbone angles for each " "set of three atoms. Assumes only CA atoms." }, { "-dih", FALSE, etBOOL, {&bDIH}, "ISDM: Mean cosine of difference of backbone dihedrals for " "each set of four atoms. Assumes only CA atoms." }, { "-angdih", FALSE, etBOOL, {&bANGDIH}, "ISDM: Geometric mean of ang and dih ISDMs." }, { "-ang2", FALSE, etBOOL, {&bANG2}, "ISDM: Attempts to euclideanize -ang." }, { "-dih2", FALSE, etBOOL, {&bDIH2}, "ISDM: Attempts to euclideanize -dih." }, { "-angdih2", FALSE, etBOOL, {&bANGDIH2}, "ISDM: Attempts to euclideanize -angdih." }, { "-angdih2g", FALSE, etBOOL, {&bANGDIH2G}, "ISDM: Attempts to euclideanize -angdih. Geometric mean." }, { "-rmsdih", FALSE, etBOOL, {&bRMSDIH}, "ISDM: Distances between points aligned by backbone dihedrals. " }, { "-phipsi", FALSE, etBOOL, {&bPHIPSI}, "ISDM: Mean cosine of difference of phi and psi angles. " "Assumes only backbone atoms." }, { "-phipsi2", FALSE, etBOOL, {&bPHIPSI2}, "ISDM: Attempts to euclideanize -phipsi." }, { "-drms", FALSE, etBOOL, {&bDRMS}, "ISDM: Mean difference of the paired distances matrix for all " "atoms. Distance RMS(D)." }, { "-sdrms", FALSE, etBOOL, {&bSDRMS}, "ISDM: Mean difference of the paired distances matrix for all " "atoms scaled by 2 * geometric mean of Rg. Scaled distance " "RMS(D)." }, { "-rg", FALSE, etBOOL, {&bRG}, "ISDM: Calculates difference in Rg. Only compares size. " }, { "-srg", FALSE, etBOOL, {&bSRG}, "ISDM: Calculates difference in Rg scaled by mean Rg. " }, { "-e2e", FALSE, etBOOL, {&bE2E}, "ISDM: Calculates difference in end-to-end distance. " }, { "-se2e", FALSE, etBOOL, {&bSE2E}, "ISDM: Calculates difference in end-to-end distance scaled " "by (2 * Rg). " }, { "-mir", FALSE, etBOOL, {&bMIR}, "ISDM: RMSD with the mirror of the reference structure. " }, { "-rrot", FALSE, etBOOL, {&bRROT}, "ISDM: RMSD with random rotation of reference structure. " }, { "-srms", FALSE, etBOOL, {&bSRMS}, "ISDM: Scaled RMSD. RMSD between the structure and reference " "divided by the RMSD between the structure and mirror of the " "reference created by multiplying the coordinates by the " "negative identity matrix." }, { "-rmsd", FALSE, etBOOL, {&bRMSD}, "ISDM: Standard RMSD." }, { "-pcor", FALSE, etBOOL, {&bPCOR}, "ISDM: Position correlation. Correlation coefficient of the " "positions is computed after alignment. Only positive " "correlation is considered. Negative correlations are set to " "zero." }, { "-acor", FALSE, etBOOL, {&bACOR}, "ISDM: Angle correlation. Correlation coefficient of the " "backbone angles (see ang ISDM) is computed. " "Only positive correlation is considered. Negative correlations " "are set to zero." }, { "-mammoth", FALSE, etBOOL, {&bMAMMOTH}, "ISDM: MAMMOTH (MAtching Molecular Models Obtained from " "Theory). Compares segments of residues chosen by sequence " "alignment. Attempts to focus on correct secondary structure " "moreso than tertiary structure. Source code modified for " "compatibility. For this ISDM, please cite: \n\n" "Ortiz, AR, Strauss, CE, Olmea, O (2002). MAMMOTH " "(Matching molecular models obtained from theory): An automated " "method for model comparison. Protein Sci. 11 (11), 2606–2621.\n"}, { "-esa", FALSE, etBOOL, {&bESA}, "ISDM: Elastic shape analysis. Based on image analysis. " "Warps structure onto the reference structure. Original source " "code ported from Matlab to C. For this ISDM, please cite: \n\n" "Liu W, Srivastava A, Zhang J (2011) A Mathematical Framework " "for Protein Structure Comparison. PLoS Comput Biol 7(2): " "e1001075.\n\nAssume only CA atoms." }, { "-mp", FALSE, etBOOL, {&bMP}, "Use OpenMP commands for parallel processing. "}, { "-nt", FALSE, etINT, {&nt}, "Limit the maximum number of threads for parallel processing. "}, { "-noise", FALSE, etBOOL, {&bNoise}, "If this flag is set, additional information is sent to " "stdout. The tool calculates the number of positive eigenvalues " "and the number of positive eigenvalues that can be accounted " "by two sources of noise. (1) Algorithmic noise based on the " "negative eigenvalues, (2) thermal noise based on the expected " "variation of folded proteins, and (3) the combined noise. " "An estimate of thermal noise can be set manually with the " "option -noisefloor." }, { "-setmax", FALSE, etREAL, {&setmax}, "Set maximum value to threshold the xpm file. Must be greater " "than the average inter-structure distance." }, { "-rcutoff", FALSE, etREAL, {&rcutoff}, "Set cutoff value for the correlation coefficient. Only applies " "if the -rcc output is set. The correlation coefficient (R) " "will be calculated for each dimensional until rcutoff is " "reached. The value should be between 0 and 1." }, { "-noisefloor", FALSE, etREAL, {&noisefloor}, "Only applies if the -noise option is set. Manually sets the " "the estimate of thermal noise used by the dimensionality " "estimator." }, }; FILE *out; t_trxstatus *status; t_topology top; int ePBC; rvec *x, **frames; real *nweights, *iweights, abscoor, maxcoor; real *diff, **ISDmat, *P2, *J, *P2J, *B, *BT, *E, *V, *MDSa; real **Va, **MDS, **EISD, *EISDm, Rcc, sumne, cumpe; double *avgdiff, *maxdiff, avgISD, maxISD; matrix box; real t, xpm_max, pi = 3.14159265358979; int *maxframe, *rnum, maxcoori; int i, k, m, n, p, np, d, iatoms, natoms, nframes, nframes2; int percent_calcs, finished_calcs, noptions; gmx_bool bDFLT, bFit, bISD, bMDS, bEig, bVec, bRcc, bMRg, bDRg, bPy, bM; char buf[256]; char *ISDM, *grpname, title[256], title2[256], *rname; atom_id *index; output_env_t oenv; gmx_rmpbc_t gpbc=NULL; const char *leg[] = { "D" }; #define NLEG asize(leg) t_filenm fnm[] = { { efTRX, "-f", NULL, ffREAD }, { efTPS, NULL, NULL, ffREAD }, { efNDX, NULL, NULL, ffOPTRD }, { efXVG, "-eig", "eigvals", ffOPTWR }, { efXVG, "-rcc", "corrcoef", ffOPTWR }, { efXVG, "-mrg", "mrgcorr", ffOPTWR }, { efXVG, "-drg", "drgcorr", ffOPTWR }, { efDAT, "-vec", "eigvecs", ffOPTWR }, { efDAT, "-isd", "isdcsv", ffOPTWR }, { efDAT, "-mds", "mdscsv", ffOPTWR }, { efDAT, "-py", "mayapy", ffOPTWR }, { efDAT, "-m", "disp6D", ffOPTWR }, }; #define NFILE asize(fnm) int npargs; CopyRight(stderr,argv[0]); npargs = asize(pa); // Lots of black magic with this one. The oenv is used by many things. parse_common_args(&argc,argv,PCA_CAN_TIME | PCA_CAN_VIEW | PCA_BE_NICE, NFILE,fnm,npargs,pa,asize(desc),desc,0,NULL,&oenv); // If there are no options at command line, do default behavior. bDFLT = !(bANG || bDIH || bANGDIH || bPHIPSI || bDRMS || bSRMS || bRMSD || bPCOR || bACOR || bMAMMOTH || bESA || bRG || bSRG || bE2E || bSE2E || bMIR || bRROT || bSDRMS || bANG2 || bDIH2 || bANGDIH2 || bPHIPSI2 || bANGDIH2G || bRMSDIH); bFit = (bDFLT || bRMSD || bMIR || bSRMS || bPCOR); #ifdef _OPENMP if (nt > 0) { omp_set_num_threads(nt); } #endif /* Reads the tpr file. Outputs a ton of info. * * I think this is the line that forces you to have a -s at prompt. */ read_tps_conf(ftp2fn(efTPS, NFILE, fnm), title, &top, &ePBC, &x, NULL, box, TRUE); // Asks you to choose a selection of atoms at prompt. get_index(&top.atoms, ftp2fn_null(efNDX, NFILE, fnm), 1, &iatoms, &index, &grpname); // For error checking. noptions = 0; // Check which ISDM will be used. Default is RMSD. if (bDFLT || bRMSD) { fprintf(stderr,"\nUsing RMSD as ISDM.\n"); ISDM = "RMSD"; noptions++; } if (bANG) { fprintf(stderr,"\nUsing backbone angles as ISDM.\n"); ISDM = "ANG"; noptions++; } if (bDIH) { fprintf(stderr,"\nUsing backbone dihedrals as ISDM.\n"); ISDM = "DIH"; noptions++; } if (bANG2) { fprintf(stderr,"\nUsing backbone angles as ISDM.\n"); ISDM = "ANG2"; noptions++; } if (bDIH2) { fprintf(stderr,"\nUsing backbone dihedrals as ISDM.\n"); ISDM = "DIH2"; noptions++; } if (bANGDIH) { fprintf(stderr,"\nUsing geometric mean of angles and dihedrals as ISDM.\n"); ISDM = "ANGDIH"; noptions++; } if (bANGDIH2) { fprintf(stderr,"\nUsing geometric mean of angles and dihedrals as ISDM.\n"); ISDM = "ANGDIH2"; noptions++; } if (bANGDIH2G) { fprintf(stderr,"\nUsing geometric mean of angles and dihedrals as ISDM.\n"); ISDM = "ANGDIH2G"; noptions++; } if (bRMSDIH) { fprintf(stderr,"\nUsing RMSD of dihedrals as ISDM.\n"); ISDM = "RMSDIH"; noptions++; } if (bPHIPSI) { fprintf(stderr,"\nUsing phi and psi angles as ISDM.\n"); ISDM = "PHIPSI"; noptions++; } if (bPHIPSI2) { fprintf(stderr,"\nUsing phi and psi angles as ISDM.\n"); ISDM = "PHIPSI2"; noptions++; } if (bDRMS) { fprintf(stderr,"\nUsing distance RMS as ISDM.\n"); ISDM = "DRMS"; noptions++; } if (bSDRMS) { fprintf(stderr,"\nUsing scaled distance RMS as ISDM.\n"); ISDM = "SDRMS"; noptions++; } if (bRG) { fprintf(stderr,"\nUsing Rg difference as ISDM.\n"); ISDM = "RG"; noptions++; } if (bSRG) { fprintf(stderr,"\nUsing scaled Rg difference as ISDM.\n"); ISDM = "SRG"; noptions++; } if (bE2E) { fprintf(stderr,"\nUsing end-to-end distance as ISDM.\n"); ISDM = "E2E"; noptions++; } if (bSE2E) { fprintf(stderr,"\nUsing scaled end-to-end distance as ISDM.\n"); ISDM = "SE2E"; noptions++; } if (bMIR) { fprintf(stderr,"\nUsing mirrored RMSD as ISDM.\n"); ISDM = "MIR"; noptions++; } if (bSRMS) { fprintf(stderr,"\nUsing scaled RMSD as ISDM.\n"); ISDM = "SRMS"; noptions++; } if (bPCOR) { fprintf(stderr,"\nUsing position correlation as ISDM.\n"); ISDM = "PCOR"; noptions++; } if (bACOR) { fprintf(stderr,"\nUsing backbone angle correlation as ISDM.\n"); ISDM = "ACOR"; noptions++; } if (bRROT) { fprintf(stderr,"\nUsing RMSD with random rotation as ISDM.\n"); noptions++; // Additional stuff for option. srand(time(NULL)); } if (bMAMMOTH) { fprintf(stderr,"\nUsing MAMMOTH comparison as ISDM.\n"); noptions++; // Additional stuff for option. snew(rnum,iatoms); //printf(stderr,"\nOutput sequence (tool).\n\n"); for (i = 0; i < iatoms; i++) { rname = *(top.atoms.resinfo[top.atoms.atom[index[i]].resind].name); // Convert to integers. if (!(strcmp(rname, "ALA"))) { rnum[i] = 0; } else if (!(strcmp(rname, "CYS"))) { rnum[i] = 1; } else if (!(strcmp(rname, "ASP"))) { rnum[i] = 2; } else if (!(strcmp(rname, "GLU"))) { rnum[i] = 3; } else if (!(strcmp(rname, "PHE"))) { rnum[i] = 4; } else if (!(strcmp(rname, "GLY"))) { rnum[i] = 5; } else if (!(strcmp(rname, "HIS")) || !(strcmp(rname, "HID")) || !(strcmp(rname, "HIE")) || !(strcmp(rname, "HIP")) || !(strcmp(rname, "HSD")) || !(strcmp(rname, "HSE")) || !(strcmp(rname, "HSP"))) { rnum[i] = 6; } else if (!(strcmp(rname, "ILE"))) { rnum[i] = 7; } else if (!(strcmp(rname, "LYS"))) { rnum[i] = 8; } else if (!(strcmp(rname, "LEU"))) { rnum[i] = 9; } else if (!(strcmp(rname, "MET"))) { rnum[i] = 10; } else if (!(strcmp(rname, "ASN"))) { rnum[i] = 11; } else if (!(strcmp(rname, "PRO"))) { rnum[i] = 12; } else if (!(strcmp(rname, "GLN"))) { rnum[i] = 13; } else if (!(strcmp(rname, "ARG"))) { rnum[i] = 14; } else if (!(strcmp(rname, "SER"))) { rnum[i] = 15; } else if (!(strcmp(rname, "THR"))) { rnum[i] = 16; } else if (!(strcmp(rname, "VAL"))) { rnum[i] = 17; } else if (!(strcmp(rname, "TRP"))) { rnum[i] = 18; } else if (!(strcmp(rname, "TYR"))) { rnum[i] = 19; } else { rnum[i] = 20; } } } if (bESA) { fprintf(stderr,"\nUsing ESA comparison as ISDM.\n" "For this ISDM, please cite: \n\n" "Liu W, Srivastava A, Zhang J (2011) A Mathematical Framework " "for Protein Structure Comparison. PLoS Comput Biol 7(2): " "e1001075.\n" ); noptions++; } // Throw an error if multiple -ISDM options were given by the user. if (noptions > 1) { gmx_fatal(FARGS,"\nThis tool only supports using one optional ISDM at a time.\n"); } // Check for error on -setmax before doing the calculations. if (setmax != -1.0) { if (setmax <= 0.0) { gmx_fatal(FARGS,"\nThe argument for -setmax must be greater than 0.\n"); } } /* Opens trj. Reads first frame. Returns status. Allocates mem for x. * * Not sure which argument determines which atoms to pull info for. */ printf("\nCounting the number of frames.\n"); natoms=read_first_x(oenv, &status, ftp2fn(efTRX, NFILE, fnm), &t, &x, box); // Now that we have iatoms, allocate memory for other arrays. snew(nweights, natoms); snew(iweights, iatoms); snew(diff, iatoms); // Initialize nweights to zeros. for (i=0; i < natoms; i++) { nweights[i] = 0; } // Makes an array of weights. Necessary for reset_x. for (i=0; i < iatoms; i++) { // Give a value for the weights. nweights[(int)index[i]] = 1; iweights[i] = 1; // While we're at it, initialize diff to zeros. diff[i] = 0; } // Output which files? bEig = opt2bSet("-eig", NFILE, fnm); bRcc = opt2bSet("-rcc", NFILE, fnm); bMRg = opt2bSet("-mrg", NFILE, fnm); bDRg = opt2bSet("-drg", NFILE, fnm); bVec = opt2bSet("-vec", NFILE, fnm); bISD = opt2bSet("-isd", NFILE, fnm); bMDS = opt2bSet("-mds", NFILE, fnm); bPy = opt2bSet("-py", NFILE, fnm); bM = opt2bSet("-m", NFILE, fnm); nframes = 0; do { /* This loop doesn't do anything. * * It's just the most reliable way to find the number of frames. */ nframes++; } while(read_next_x(oenv, status, &t, natoms, x, box)); // Close the trajectory. close_trj(status); // Throw an error if there aren't enough frames. if (nframes < 2) { gmx_fatal(FARGS, "\nThe trajectory must have at least 2 frames.\n"); } // Create an array to hold all frames. snew(frames, nframes); // Create arrays based on nframes. snew(maxdiff, nframes); snew(avgdiff, nframes); snew(ISDmat, nframes); for (i = 0; i < nframes; i++) { maxdiff[i] = 0.0; avgdiff[i] = 0.0; snew(ISDmat[i], nframes); } nframes2 = nframes * nframes; /* Opens trj. Reads first frame. Returns status. Allocates mem for x. * * Not sure which argument determines which atoms to pull info for. */ printf("\nStoring trajectory to memory.\n"); natoms=read_first_x(oenv, &status, ftp2fn(efTRX, NFILE, fnm), &t, &x, box); // Initialize index to keep track of current frame. i = 0; // This is for removing periodic boundary conditions. gpbc = gmx_rmpbc_init(&top.idef, ePBC, natoms,box); do { // Set aside new memory to store this frame. snew(frames[i], iatoms); // Removes periodic boundary conditions from x. gmx_rmpbc(gpbc, natoms, box, x); // Centers x. The NULL arguments are necessary to fit based on subset. reset_x(natoms, NULL, natoms, NULL, x, nweights); // Saves the current frame into frames. for (n=0; n<iatoms; n++) { copy_rvec(x[(int)index[n]], frames[i][n]); } // Increment frame index. i++; } while(read_next_x(oenv, status, &t, natoms, x, box)); // Close the trajectory. close_trj(status); // Closes the thing that removes periodic boundary conditions. gmx_rmpbc_done(gpbc); // Initialize to 0. maxISD = 0.0; avgISD = 0.0; /* Main calculation loop. */ printf("\nCalculating inter-structure distances. \n"); /* Originally this was designed to only loop through each pair of i and j * one time to save half of the calculations. Eventually it became * impractical to make sure that each ISDM was symmetrical, so now the * algorithm takes the performance hit in favor of accuracy and simplicity. */ percent_calcs = 1; finished_calcs = 0; // Loop through reference frames. #pragma omp parallel for schedule(dynamic) if (bMP) for (i = 0; i < nframes; i++) { // Some memory required by each thread. int j; real ISD; double dISD; matrix rrot, rrotx, rroty, rrotz; rvec *iframe, *jframe, *cframe, *rframe, rrot_xyz, xold; if (bRROT) { snew(iframe,iatoms); // Use up the first few random numbers that usually aren't random. rrot_xyz[0] = (real)rand(); rrot_xyz[1] = (real)rand(); rrot_xyz[2] = (real)rand(); } if (bFit) { snew(jframe,iatoms); } // Loop through fitting frames. for (j = 0; j < nframes; j++) { /* In this section, we'll put calls to all of the ISDMs. * * Each should have its own if statement, so it is only executed * if that option is specified at the command line. * * This function doesn't use the output stored in diff. */ // Skip for i == j (comparing structure with self). if (i == j) { ISDmat[i][j] = 0; continue; } // Copy ith frame. if (bRROT) { // Make a copy of the ith frame. copy_rvecn(frames[i], iframe, 0, iatoms); rframe = iframe; } else { rframe = frames[i]; } // Fit the jth frame. if (bFit) { // Need to make a copy of the fit frame or bad stuff will happen. copy_rvecn(frames[j], jframe, 0, iatoms); // Aligns jframe to current reference frame. do_fit(iatoms, iweights, frames[i], jframe); cframe = jframe; } else { cframe = frames[j]; } // Calls most ISDM options. if (bDFLT || bRMSD || bSRMS || bRG || bSRG || bE2E || bSE2E || bMIR || bANG || bDIH || bANGDIH || bPHIPSI || bDRMS || bSDRMS || bPCOR || bACOR || bANG2 || bDIH2 || bANGDIH2 || bPHIPSI2 || bANGDIH2G || bRMSDIH) { ISD = call_ISDM(iatoms, cframe, rframe, ISDM); } // RMSD with random rotation. User gives -rrot option. if (bRROT) { // Solve for three random numbers. for (k = 0; k < 3; k++) { rrot_xyz[k] = 2.0 * pi * ((real)rand() / RAND_MAX) - pi; } // Create x, y, z rotation matrices and multiply. clear_mat(rrotx); clear_mat(rroty); clear_mat(rrotz); /* Rx = rrotx[rows][cols] * * | 1.0 | 0.0 | 0.0 | * Rx = | 0.0 | cos(x) | sin(x) | * | 0.0 | -sin(x) | cos(x) | */ rrotx[0][0] = 1.0; rrotx[1][1] = cos(rrot_xyz[0]); rrotx[2][2] = rrotx[1][1]; rrotx[1][2] = sin(rrot_xyz[0]); rrotx[2][1] = -1.0 * rrotx[1][2]; /* Ry = rroty[rows][cols] * * | cos(x) | 0.0 | -sin(x) | * Ry = | 0.0 | 1.0 | 0.0 | * | sin(x) | 0.0 | cos(x) | */ rroty[1][1] = 1.0; rroty[0][0] = cos(rrot_xyz[1]); rroty[2][2] = rroty[0][0]; rroty[2][0] = sin(rrot_xyz[1]); rroty[0][2] = -1.0 * rroty[2][0]; /* Rz = rrotz[rows][cols] * * | cos(x) | sin(x) | 0.0 | * Rz = | -sin(x) | cos(x) | 0.0 | * | 0.0 | 0.0 | 1.0 | */ rrotz[2][2] = 1.0; rrotz[0][0] = cos(rrot_xyz[2]); rrotz[1][1] = rrotz[0][0]; rrotz[0][1] = sin(rrot_xyz[2]); rrotz[1][0] = -1.0 * rrotz[0][1]; // Multiply rotation matrices. mmul(rrotx, rroty, rrot); copy_mat(rrot, rrotx); mmul(rrotx, rrotz, rrot); // Apply random rotation. for (k = 0; k < iatoms; k++) { for (m = 0; m < 3; m++) { xold[m] = rframe[k][m]; } for (m = 0; m < 3; m++) { rframe[k][m] = 0; for (n = 0; n < 3; n++) { rframe[k][m] += rrot[m][n] * xold[n]; } } } // Calculate RMSD after rotation. ISD = sqrt(calc_msd(iatoms, cframe, rframe)); } // MAMMOTH. User gives -mammoth option. if (bMAMMOTH) { // Calculate MAMMOTH comparison. ISD = calc_mammoth(iatoms, cframe, rframe, rnum); } // ESA. if (bESA) { // Calculate ESA comparison. ISD = calc_esa(iatoms, cframe, rframe); } // Use doubles instead of reals for the summations. dISD = (double)ISD; // Add difference to the difference matrix. ISDmat[i][j] = ISD; // Update the max and avg difference for scaling. if (dISD > maxdiff[i]) { maxdiff[i] = dISD; } avgdiff[i] += dISD; // Debugging. //printf("On the %i th loop. \n",j); } // Average difference for each frame. avgdiff[i] /= (nframes - 1); // Update progress output. OpenMP critical section. #pragma omp critical { finished_calcs += nframes; while ((double)(finished_calcs) / nframes2 >= (double)percent_calcs / 100) { fprintf(stderr, "Approximately %i percent complete. \r", percent_calcs); percent_calcs++; } } // End of OpenMP critical section. // Free memory used in parallel section. if (bRROT) { sfree(iframe); } if (bFit) { sfree(jframe); } } // End of OpenMP parallel for loop. fprintf(stderr, "\n\n\n"); // Find the final average of differences. for (i = 0; i < nframes; i++) { avgISD += avgdiff[i]; } avgISD /= nframes; int j; if (bISD) { // Opens the output file. out = opt2FILE("-isd", NFILE, fnm, "w"); // Write output. for (i = 0; i < nframes; i++) { fprintf(out, "%12.8f", ISDmat[i][0]); for (j = 1; j < nframes; j++) { fprintf(out, ",%12.8f", ISDmat[i][j]); } fprintf(out, "\n"); } // Close the output file. ffclose(out); } /* Implements Torgerson's classical multi-dimensional scaling (CMDS) * algorithm. * * 1) Convert the ISD matrix to the squared proximities matrix (P2). * * 2) Perform double centering on P2. * [B = (-1/2) * J * P2 * J, where J = I - (UnitMatrix / nframes)] * * 3) Solve for the eigenvalues and eigenvectors. * * 4) Keep only the dimensions corresponding to positive eigenvalues. * The rest are imaginary dimensions. * [The requirement to keep the dimension here is that both the * eigenvalue and the root of the eigenvalue must be greater than * zero to rule out dimensions below the precision limit.] * * 5) Sign convention. This may not be necessary. */ fprintf(stderr, "Performing MDS.\n"); // Allocate memory. snew(J, nframes * nframes); snew(P2, nframes * nframes); snew(P2J, nframes * nframes); snew(V, nframes * nframes); snew(E, nframes); snew(Va, nframes); for (i = 0; i < nframes; i++) { Va[i] = &V[i * nframes]; } // Step 1. fprintf(stderr, "MDS step 1 of 5. \n"); for (i = 0; i < nframes; i++) { for (j = 0; j < nframes; j++) { P2[(i * nframes) + j] = ISDmat[i][j] * ISDmat[i][j]; } } // Step 2. fprintf(stderr, "MDS step 2 of 5. \n"); // Constructs J. for (i = 0; i < nframes; i++) { for (j = 0; j < nframes; j++) { if (i == j) { J[(i * nframes) + j] = 1.0 - (1.0 / nframes); } else { J[(i * nframes) + j] = -1.0 / nframes; } } } // Solve for B. mat_mult_mat(P2, J, nframes, nframes, nframes, P2J, bMP); B = P2; // Finished with the memory in P2. Reuse it to store B. scl_mult_mat(-0.5, J, nframes, nframes, J); mat_mult_mat(J, P2J, nframes, nframes, nframes, B, bMP); // Step 3. fprintf(stderr, "MDS step 3 of 5. \n"); // Fix assymetry in B caused by precision limits. BT = J; // Finished with the memory in J. Reuse it to store BT. mat_transpose(B, nframes, nframes, BT); for (i = 0; i < nframes; i++) { for (j = 0; j < nframes; j++) { B[(i * nframes) + j] = (B[(i * nframes) + j] + BT[(i * nframes) + j]) / 2.0; } } // Call the eigensolver which uses a lapack backend. // E and V are sorted ascending by eigensolver. eigensolver(B, nframes, 0, nframes, E, V); // Step 4. fprintf(stderr, "MDS step 4 of 5. \n"); // Find eigenvalues > 0.0. for (i = 0; i < nframes; i++) { if (E[i] > 0.0) { if (sqrt(E[i]) > 0.0) { p = i; np = nframes - p; break; } } if (i == (nframes - 1)) { gmx_fatal(FARGS,"\nThere are zero positive eigenvalues.\n"); } } // Save coordinates in reduced dimensions. snew(MDSa, nframes * np); snew(MDS, nframes); for (i = 0; i < nframes; i++) { MDS[i] = &MDSa[np * i]; } for (i = 0; i < nframes; i++) { for (j = 0; j < np; j++) { MDS[i][j] = sqrt(E[nframes - j - 1]) * Va[nframes - j - 1][i]; } } // Step 5. fprintf(stderr, "MDS step 5 of 5. \n"); for (j = 0; j < np; j++) { maxcoor = -1.0; for (i = 0; i < nframes; i++) { abscoor = abs(MDS[i][j]); if (abscoor > maxcoor) { maxcoor = abscoor; maxcoori = i; } } if (MDS[maxcoori][j] < 0.0) { for (i = 0; i < nframes; i++) { MDS[i][j] *= -1.0; } } } // Output the eigenvectors. if (bVec) { // Opens the output file. out = opt2FILE("-vec", NFILE, fnm, "w"); // Write output. for (j = 0; j < nframes; j++) { fprintf(out, "%15.6e", Va[0][j]); for (i = 1; i < nframes; i++) { fprintf(out, ",%15.6e", Va[i][j]); } fprintf(out, "\n"); } // Close the output file. ffclose(out); } // Release memory. sfree(J); sfree(P2); sfree(P2J); sfree(V); sfree(Va); fprintf(stderr, "\nClassical MDS Complete. \n\n"); // Output the eigenvalues. if (bEig) { // Opens the output file. out = xvgropen(opt2fn("-eig", NFILE, fnm), "MDS Eigenvalues", "Dimension", "Eigenvalue", oenv); // Write output. for (i = 1; i <= nframes; i++) { // Print in reversed order. fprintf(out, "%-6i %15.8f \n", i, E[nframes - i]); } // Close the output file. ffclose(out); } // Estimate the number of dimensions explained by noise. if (bNoise) { printf("\n\n"); printf("Positive eigenvalues correspond to real dimensions. "); printf("Negative eigenvalues correspond to imaginary dimensions.\n\n"); // Sum the positive and negative eigenvalues. cumpe = 0.0; for (i = p; i < nframes; i++) { cumpe += E[i]; } sumne = 0.0; for (i = 0; i < p; i++) { sumne += E[i]; } printf("Sum of positive eigenvalues: %12.6f \n", cumpe); printf("Sum of negative eigenvalues: %12.6f \n", sumne); // Output the explained noise. printf("%-6i eigenvalues are positive.\n", np); printf("%-6i eigenvalues are zero or negative.\n", nframes - np); cumpe = 0.0; for (i = p; i < nframes; i++) { cumpe += E[i]; if (cumpe > abs(sumne)) { break; } } printf("%-6i positive eigenvalues can be explained by negative " "eigenvalues.\n", i - p); cumpe = 0.0; for (i = p; i < nframes; i++) { cumpe += E[i]; if (cumpe > noisefloor) { break; } } printf("%-6i positive eigenvalues can be explained by estimated " "thermal noise.\n", i - p); cumpe = 0.0; for (i = p; i < nframes; i++) { cumpe += E[i]; if (cumpe > (abs(sumne) + noisefloor)) { break; } } printf("%-6i positive eigenvalues can be explained by estimated " "thermal noise and algorithmic noise combined.\n\n", i - p); } // Output dimensionally reduced coordinates. if (bMDS) { // Opens the output file. out = opt2FILE("-mds", NFILE, fnm, "w"); // Write output. for (i = 0; i < nframes; i++) { fprintf(out, "%12.8f", MDS[i][0]); for (j = 1; j < np; j++) { fprintf(out, ",%12.8f", MDS[i][j]); } fprintf(out, "\n"); } // Close the output file. ffclose(out); } // Allocates memory to store the approximated ISD. if (bRcc || bMRg || bDRg || bPy || bM) { snew(EISD, nframes); snew(EISDm, nframes * nframes); for (i = 0; i < nframes; i++) { EISD[i] = &EISDm[nframes * i]; } } // Reduced dimensional visualization. if (bPy) { // Calculate accuracy of the displayed results. calc_EISD(MDS, nframes, 6, EISD); Rcc = calc_rcc(ISDmat, EISD, nframes); fprintf(stdout, "The accuracy for 6D MDS is R = %8.4f.\n\n", Rcc); // Opens the output file. out = opt2FILE("-py", NFILE, fnm, "w"); // Python script header (py). fprintf(out, "# Plots MDS output in 6 dimensions:\n"); fprintf(out, "# x, y, z, r, g, b\n\n"); // Import modules (py). fprintf(out, "from mayavi import mlab\n"); fprintf(out, "import numpy as np\n\n"); // Save data to numpy array (py). fprintf(out, "# Save data to numpy array.\n"); fprintf(out, "MDS = np.array([[%8.4f", MDS[0][0]); for (j = 1; j < 6; j++) { fprintf(out, ",%8.4f", MDS[0][j]); } fprintf(out, "]"); for (i = 1; i < nframes; i++) { fprintf(out, ",\n [%8.4f", MDS[i][0]); for (j = 1; j < 6; j++) { fprintf(out, ",%8.4f", MDS[i][j]); } fprintf(out, "]"); } fprintf(out, "])\n\n"); // Calculate box center and range, center at zero (py). fprintf(out, "# Calculate box center and range.\n"); fprintf(out, "bctr = np.mean(MDS, 0)\n"); fprintf(out, "MDS = np.subtract(MDS, bctr)\n"); fprintf(out, "bmin = np.min(MDS) #- Rbead\n"); fprintf(out, "bmax = np.max(MDS) #+ Rbead\n\n"); // Split MDS by dimensions. Recenter and rescale rgb dimensions (py). fprintf(out, "# Split MDS by dimensions. Recenter to 0.5.\n"); fprintf(out, "xyz, rgb = np.hsplit(MDS, 2)\n"); fprintf(out, "color_sf = 0.8 / (bmax - bmin)\n"); fprintf(out, "rgb = np.add(np.multiply(rgb, color_sf), 0.5)\n"); fprintf(out, "s = np.array([0.01])\n"); fprintf(out, "s = s[0]\n\n"); /* * // Display first coordinate and set up figure (py). * fprintf(out, "# Display first coordinate and set up figure.\n"); * fprintf(out, "x = xyz[0, 0]\n"); * fprintf(out, "y = xyz[0, 1]\n"); * fprintf(out, "z = xyz[0, 2]\n"); * fprintf(out, "r = rgb[0, 0]\n"); * fprintf(out, "g = rgb[0, 1]\n"); * fprintf(out, "b = rgb[0, 2]\n"); * fprintf(out, "if r > 1.0:\n r = 1.0\n"); * fprintf(out, "if r < 0.0:\n r = 0.0\n"); * fprintf(out, "if g > 1.0:\n g = 1.0\n"); * fprintf(out, "if g < 0.0:\n g = 0.0\n"); * fprintf(out, "if b > 1.0:\n b = 1.0\n"); * fprintf(out, "if b < 0.0:\n b = 0.0\n"); * fprintf(out, "mlab.points3d(x, y, z, color=(r, g, b), "); * fprintf(out, "extent=[bmin, bmax, bmin, bmax, bmin, bmax])\n\n"); */ // Display coordinates (py). fprintf(out, "# Display coordinates.\n"); fprintf(out, "for i in range(0, %i):\n", nframes); fprintf(out, " x = xyz[i, 0]\n"); fprintf(out, " y = xyz[i, 1]\n"); fprintf(out, " z = xyz[i, 2]\n"); fprintf(out, " r = rgb[i, 0]\n"); fprintf(out, " g = rgb[i, 1]\n"); fprintf(out, " b = rgb[i, 2]\n"); fprintf(out, " if r > 1.0:\n r = 1.0\n"); fprintf(out, " if r < 0.0:\n r = 0.0\n"); fprintf(out, " if g > 1.0:\n g = 1.0\n"); fprintf(out, " if g < 0.0:\n g = 0.0\n"); fprintf(out, " if b > 1.0:\n b = 1.0\n"); fprintf(out, " if b < 0.0:\n b = 0.0\n"); fprintf(out, " mlab.points3d(x, y, z, s, color=(r, g, b), scale_factor=1)\n\n"); // Close the output file. ffclose(out); } // Reduced dimensional visualization. if (bM) { // Calculate accuracy of the displayed results. calc_EISD(MDS, nframes, 6, EISD); Rcc = calc_rcc(ISDmat, EISD, nframes); fprintf(stdout, "The accuracy for 6D MDS is R = %8.4f.\n\n", Rcc); // Opens the output file. out = opt2FILE("-m", NFILE, fnm, "w"); // Octave function and comments. fprintf(out, "function [MDSout, MDS] = disp6D(varargin)\n" "%% function [MDSout, MDS] = disp6D(varargin)\n" "%%\n" "%% 'Delay' : Pause between frames (numeric, units = ps).\n" "%% Setting Delay creates a movie-like output.\n" "%% 'TimeStep' : Time per frame (numeric, units = ps).\n" "%% 'NSims' : Display N simulations independently (numeric).\n" "%% 'NAvg' : Runs an averaging window of size 2 * NAvg + 1.\n" "%% 'Radius' : Sphere size (numeric).\n" "%% 'Res' : Sphere resolution (numeric).\n" "%% 'NSkip' : Only display every NSkip + 1 sphere (numeric).\n" "%% 'NClust' : Enables clustering with n clusters (numeric).\n" "%% 'Title' : Figure title (char).\n" "%% 'PNGClust' : Create PNG of clustering (char).\n" "%% 'PNGName' : Create PNG of CMDS (char).\n" "%% 'GIFName' : Create animated GIF (char).\n" "%% 'GIFStep' : Frames per image (numeric).\n" "%% 'bShow' : Plot even if no image is written (logical).\n" "%% 'ShowLine' : Connect spheres (logical).\n" "%% 'Vis3D' : Better, but causes error in Octave (logical).\n" "%% 'Out2D' : Output in 2D even if NSims > 1 (logical).\n" "%%\n" "%% Defaults : \n" "%% No delay, 1.0 ps time step, one simulation, no averaging \n" "%% window, radius auto, sphere resolution 6, no skipping, no \n" "%% title, no PNG, no GIF, 1.0 frame GIF step, do not show \n" "%% no line, no Vis3D, output MDSout in 2D.\n" "%%\n" "%% Plots MDS output in 6 dimensions:\n" "%% x, y, z, r, g, b\n" "\n" ); // Defaults. fprintf(out, "%% Set defaults.\n" "defDelay = -1.0;\n" "defTimeStep = -1.0;\n" "defNSims = -1.0;\n" "defNAvg = -1.0;\n" "defRadius = -1.0;\n" "defRes = -1.0;\n" "defNSkip = -1.0;\n" "defNClust = -1.0;\n" "defTitle = '';\n" "defPNGClust = '';\n" "defPNGName = '';\n" "defGIFName = '';\n" "defGIFStep = -1.0;\n" "defbShow = false;\n" "defShowLine = false;\n" "defVis3D = false;\n" "defOut2D = true;\n" "\n" ); fprintf(out, "%% Initialize parser.\n" "p = inputParser;\n" "addOptional(p, 'Delay', defDelay, @isnumeric);\n" "addOptional(p, 'TimeStep', defTimeStep, @isnumeric);\n" "addOptional(p, 'NSims', defNSims, @isnumeric);\n" "addOptional(p, 'NAvg', defNAvg, @isnumeric);\n" "addOptional(p, 'Radius', defRadius, @isnumeric);\n" "addOptional(p, 'Res', defRes, @isnumeric);\n" "addOptional(p, 'NSkip', defNSkip, @isnumeric);\n" "addOptional(p, 'NClust', defNClust, @isnumeric);\n" "addOptional(p, 'Title', defTitle, @ischar);\n" "addOptional(p, 'PNGClust', defPNGClust, @ischar);\n" "addOptional(p, 'PNGName', defPNGName, @ischar);\n" "addOptional(p, 'GIFName', defGIFName, @ischar);\n" "addOptional(p, 'GIFStep', defGIFStep, @isnumeric);\n" "addOptional(p, 'bShow', defbShow);\n" "addOptional(p, 'ShowLine', defShowLine);\n" "addOptional(p, 'Vis3D', defVis3D);\n" "addOptional(p, 'Out2D', defOut2D);\n" "\n" "parse(p, varargin{:});\n" "PNGClust = p.Results.PNGClust;\n" "PNGName = p.Results.PNGName;\n" "GIFName = p.Results.GIFName;\n" "bShow = p.Results.bShow;\n" "\n" ); // Save data to matrix. fprintf(out, "%% Save data to matrix called MDS.\n"); fprintf(out, "MDS = [%8.4f", MDS[0][0]); for (j = 1; j < 6; j++) { fprintf(out, ", %8.4f", MDS[0][j]); } for (i = 1; i < nframes; i++) { fprintf(out, ";\n %8.4f", MDS[i][0]); for (j = 1; j < 6; j++) { fprintf(out, ", %8.4f", MDS[i][j]); } } fprintf(out, "];\n\n"); // Accuracy of MDS. fprintf(out, "%% Print correlation coefficient of MDS and ISD.\n"); fprintf(out, "fprintf('The accuracy of MDS is: %%8.4f \\n', %8.4f)\n\n", Rcc); // Test NAvg, NSkip, NSims, and NClust. fprintf(out, "%% Test NAvg, NSkip, NSims, and NClust.\n" "NSims = p.Results.NSims;\n" "NSkip = p.Results.NSkip;\n" "NAvg = p.Results.NAvg;\n" "NClust = p.Results.NClust;\n" "if (rem(NSims, 1) ~= 0)\n" " error('NSims should have a positive integer value.')\n" "end\n" "\n" "if (rem(NSkip, 1) ~= 0)\n" " error('NSkip should have a positive integer value.')\n" "end\n" "\n" "if (rem(NAvg, 1) ~= 0)\n" " error('NAvg should have a positive integer value.')\n" "end\n" "\n" "if (rem(NClust, 1) ~= 0)\n" " error('NClust should have a positive integer value.')\n" "end\n" "\n" ); fprintf(out, "%% Rearrange MDS matrix by simulation.\n" "nframes = size(MDS, 1);\n" "if (NSims < 1)\n" " NSims = 1;\n" " NPerSim = nframes;\n" " MDSmat = MDS;\n" "else\n" " NSims = fix(NSims);\n" " NPerSim = fix(nframes / NSims);\n" " MDSmat = zeros(NPerSim, 6, NSims);\n" " for i = 1:NSims\n" " i1 = (i - 1) * NPerSim + 1;\n" " i2 = i * NPerSim;\n" " MDSmat(:, :, i) = MDS(i1:i2, :);\n" " end\n" "end\n" ); fprintf(out, "%% Apply averaging filter.\n" "MDSout = MDSmat;\n" "if (NAvg >= 1)\n" " NAvg = fix(NAvg);\n" " for i = 1:NSims\n" " for j = 1:NPerSim\n" " j1 = j - NAvg;\n" " if (j1 < 1)\n" " j1 = 1;\n" " end\n" " j2 = j + NAvg;\n" " if (j2 > NPerSim)\n" " j2 = NPerSim;\n" " end\n" " for k = 1:6\n" " MDSijk = mean(MDSmat(j1:j2, k, i));\n" " MDSout(j, k, i) = MDSijk;\n" " end\n" " end\n" " end\n" "end\n" ); // Set bead radius. Calculate box center and range. fprintf(out, "%% Calculate plot limits.\n" "bsize = max(max(max(MDSout))) - min(min(min(MDSout)));\n" "if (p.Results.Radius < 0.0)\n" " R = 0.01 * bsize;\n" "else\n" " R = p.Results.Radius;\n" "end\n" "bctr = mean(mean(MDSout, 3));\n" "bmin = min(min(min(MDSout))) - R;\n" "bmax = max(max(max(MDSout))) + R;\n" "color_sf = 0.8 / bsize;\n" "\n" ); // Split MDS by dimensions. Recenter and rescale rgb dimensions. fprintf(out, "%% Split MDS by dimensions. Recenter rgb to 0.5.\n" "x = zeros(NPerSim, NSims);\n" "y = x;\n" "z = x;\n" "r = x;\n" "g = x;\n" "b = x;\n" "for i = 1:NSims\n" " x(:, i) = MDSout(:, 1, i);\n" " y(:, i) = MDSout(:, 2, i);\n" " z(:, i) = MDSout(:, 3, i);\n" " r(:, i) = MDSout(:, 4, i);\n" " g(:, i) = MDSout(:, 5, i);\n" " b(:, i) = MDSout(:, 6, i);\n" " \n" " %% Rescale colors.\n" " r(:, i) = (r(:, i) - bctr(4)) * color_sf + 0.5;\n" " g(:, i) = (g(:, i) - bctr(5)) * color_sf + 0.5;\n" " b(:, i) = (b(:, i) - bctr(6)) * color_sf + 0.5;\n" "end\n" "\n" ); // Setup main figure. fprintf(out, "%% Setup figure.\n"); fprintf(out, "n = %6i;\n", nframes); fprintf(out, "if (p.Results.Res < 0.0)\n" " Res = 6;\n" "else\n" " Res = p.Results.Res;\n" "end\n" "[Sx, Sy, Sz] = sphere(Res);\n" "Sx = R * Sx; Sy = R * Sy; Sz = R * Sz;\n" "figure;\n" "axis([bmin, bmax, bmin, bmax, bmin, bmax]);\n" "\n" "%% Choose axis display style.\n" "if (p.Results.Vis3D)\n" " axis('vis3d');\n" "else\n" " axis('equal');\n" "end\n" "\n" ); // Display coordinates. fprintf(out, "%% Display 6D coordinates.\n" "hold on;\n" "if (NSkip < 1)\n" " NSkip = 1;\n" "else\n" " NSkip = fix(NSkip);\n" "end\n" "\n" "if (~strcmp(GIFName, '') || ~strcmp(PNGName, '') || bShow)\n" " for i = 1:NPerSim\n" " if (p.Results.Delay > 0.0)\n" " pause(p.Results.Delay);\n" " end\n" " if (p.Results.TimeStep > 0.0)\n" " iTime = num2str(i * p.Results.TimeStep);\n" " iTime = strcat(iTime,' ns');\n" " else\n" " iTime = '';\n" " end\n" " iTitle = strcat(p.Results.Title,' ',iTime);\n" " title(iTitle);\n" " \n" " for j = 1:NSims\n" " if (mod(i, NSkip) == 0)\n" " c = [r(i, j), g(i, j), b(i, j)];\n" " h = surf(Sx + x(i, j), Sy + y(i, j), Sz + z(i, j));\n" " set(h, 'FaceColor', c, 'EdgeColor', 'none');\n" " end\n" " end\n" " if (~strcmp(GIFName, ''))\n" " if (i == 1)\n" " n = 0;\n" " f = getframe(gcf);\n" " im = frame2im(f);\n" " [imind,cm] = rgb2ind(im,256);\n" " imwrite(imind, cm, GIFName, 'gif', 'Loopcount', inf);\n" " continue\n" " end\n" " n = n + 1;\n" " if (n >= p.Results.GIFStep)\n" " n = 0;\n" " f = getframe(gcf);\n" " im = frame2im(f);\n" " [imind,cm] = rgb2ind(im,256);\n" " imwrite(imind, cm, GIFName, 'gif', 'WriteMode', 'append');\n" " end\n" " end\n" " end\n" " if (~strcmp(PNGName, ''))\n" " print(PNGName, '-dpng')\n" " end\n" "end\n" "\n" ); // Line option. fprintf(out, "%% Optionally draw a line to show the time component.\n" "if (p.Results.ShowLine)\n" " c = [0.75, 0.75, 0.75];\n" " plot3(x, y, z, 'LineWidth', 1, 'Color', c);\n" "end\n" "hold off;\n" "\n" ); // Convert MDSout. fprintf(out, "%% Convert MDSout.\n" "if (p.Results.Out2D || (NClust >= 1))\n" " MDSmat = zeros(NPerSim * NSims, 6);\n" " for i = 1:NSims\n" " i1 = (i - 1) * NPerSim + 1;\n" " i2 = i * NPerSim;\n" " MDSmat(i1:i2, :) = MDSout(:, :, i);\n" " end\n" " if (p.Results.Out2D)\n" " MDSout = MDSmat;\n" " end\n" "end\n" "\n" ); // Apply kmeans clustering. fprintf(out, "%% Apply clustering.\n" "if (NClust >= 1)\n" " figure;\n" " colormap(gcf, jet(NClust));\n" " idx = kmeans(MDSmat, NClust);\n" " for i = 1:NClust\n" " end\n" "end\n" "\n" ); // Close .m script. fprintf(out, "end"); // Close the output file. ffclose(out); } // Tests the accuracy of the dimensionally reduced coordinates. if (bRcc) { // Error checking for rcutoff. if (rcutoff < 0.0) { gmx_fatal(FARGS,"\nThe argument for -rcutoff must be greater " "than or equal to 0.\n"); } fprintf(stderr, "\nCalculating accuracy of dimensionality reduction." "\n"); // Opens the output file. out = xvgropen(opt2fn("-rcc", NFILE, fnm), "Accuracy of Dimensionality Reduction", "Dimension", "Correlation Coefficient, R", oenv); for (d = 1; d <= np; d++) { // Calculate correlation coefficient. calc_EISD(MDS, nframes, d, EISD); Rcc = calc_rcc(ISDmat, EISD, nframes); // Write to file. fprintf(out, "%-6i %12.8f \n", i, Rcc); if (Rcc > rcutoff) { break; } } // Close file. ffclose(out); printf("\nThe rcutoff is: %12.8f \n", rcutoff); printf("The final correlation coefficient is: %12.8f \n", Rcc); printf("The estimated dimensionality is: %-6i \n", d); } // Tests correlation between ISD and Rg. if (bMRg) { fprintf(stderr, "\nCalculating correlation of ISD with Rg.\n"); // Opens the output file. out = xvgropen(opt2fn("-mrg", NFILE, fnm), "Correlation of Rg with ISD", "Radius of Gyration, Rg (nm)", "ISD", oenv); /* Main calculation loop. */ printf("\nCalculating Rg matrix. \n"); percent_calcs = 1; // Loop through reference frames. for (i = 0; i < nframes; i++) { // Loop through fitting frames. for (j = 0; j < nframes; j++) { // Skip for i == j (comparing structure with self). if (i == j) { EISD[i][j] = 0.0; continue; } EISD[i][j] = call_ISDM(iatoms, frames[j], frames[i], "MRG"); // Write to file. fprintf(out, "%12.8f %12.8f \n", EISD[i][j], ISDmat[i][j]); } // Update progress output. while ((double)(i+1)/nframes >= (double)percent_calcs/100) { fprintf(stderr, "Approximately %i percent complete. \r", percent_calcs); percent_calcs++; } } Rcc = calc_rcc(ISDmat, EISD, nframes); printf("The Rg vs ISD correlation coefficient is: %12.8f \n", Rcc); // Close file. ffclose(out); } // Tests correlation between ISD and Rg difference. if (bDRg) { fprintf(stderr, "\nCalculating correlation of ISD with Rg difference." "\n"); // Opens the output file. out = xvgropen(opt2fn("-drg", NFILE, fnm), "Correlation of Rg difference with ISD", "Radius of Gyration Difference (nm)", "ISD", oenv); /* Main calculation loop. */ printf("\nCalculating Rg difference matrix. \n"); percent_calcs = 1; // Loop through reference frames. for (i = 0; i < nframes; i++) { // Loop through fitting frames. for (j = 0; j < nframes; j++) { // Skip for i == j (comparing structure with self). if (i == j) { EISD[i][j] = 0; continue; } EISD[i][j] = call_ISDM(iatoms, frames[j], frames[i], "RG"); // Write to file. fprintf(out, "%12.8f %12.8f \n", EISD[i][j], ISDmat[i][j]); } // Update progress output. while ((double)(i+1)/nframes >= (double)percent_calcs/100) { fprintf(stderr, "Approximately %i percent complete. \r", percent_calcs); fflush(stderr); percent_calcs++; } } Rcc = calc_rcc(ISDmat, EISD, nframes); printf("The Rg difference vs ISD correlation coefficient is: " "%12.8f \n", Rcc); // Close file. ffclose(out); } // Closing. thanx(stderr); 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 Tcgen529027 Tcgen529027; typedef struct TNimType TNimType; typedef struct TNimNode TNimNode; typedef struct Ropeobj178006 Ropeobj178006; 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 Ttypeseq292836 Ttypeseq292836; typedef struct Ttype292840 Ttype292840; typedef struct Intset268030 Intset268030; typedef struct Trunk268026 Trunk268026; typedef struct Trunkseq268028 Trunkseq268028; typedef struct Tpasscontext341002 Tpasscontext341002; typedef struct Tsym292834 Tsym292834; typedef struct Tidobj199004 Tidobj199004; typedef struct TNimObject TNimObject; typedef struct TY292929 TY292929; typedef struct Tstrtable292806 Tstrtable292806; typedef struct Tsymseq292804 Tsymseq292804; typedef struct Tident199010 Tident199010; typedef struct Tlineinfo191336 Tlineinfo191336; typedef struct Tnode292802 Tnode292802; typedef struct Tloc292816 Tloc292816; typedef struct Tlib292820 Tlib292820; typedef struct TY529153 TY529153; typedef struct TY203018 TY203018; typedef struct Tidtable292850 Tidtable292850; typedef struct Tidpairseq292848 Tidpairseq292848; typedef struct Tlinkedlist147013 Tlinkedlist147013; typedef struct Tlistentry147007 Tlistentry147007; typedef struct Tcproc529021 Tcproc529021; typedef struct Tnodetable292862 Tnodetable292862; typedef struct Tnodepairseq292860 Tnodepairseq292860; typedef struct Debuginfo203009 Debuginfo203009; typedef struct TY203021 TY203021; typedef struct TY203023 TY203023; typedef struct Tnodeseq292796 Tnodeseq292796; typedef struct TY191350 TY191350; typedef struct TY529095 TY529095; typedef struct Trodreader332021 Trodreader332021; typedef struct TY292960 TY292960; typedef struct TY203017 TY203017; typedef struct Enumdesc203007 Enumdesc203007; typedef struct Tinfocc273008 Tinfocc273008; typedef struct Tblock529019 Tblock529019; typedef struct Ttraversalclosure537019 Ttraversalclosure537019; typedef struct TY135002 TY135002; typedef struct Tbitset339004 Tbitset339004; typedef struct TY191612 TY191612; typedef struct Tfileinfo191334 Tfileinfo191334; typedef struct Tinfoos176035 Tinfoos176035; typedef struct Tinfocpu176476 Tinfocpu176476; typedef struct Tstrentry147009 Tstrentry147009; typedef struct TY128506 TY128506; typedef struct Basechunk29437 Basechunk29437; typedef struct Freecell29429 Freecell29429; typedef struct Tinstantiation292824 Tinstantiation292824; typedef struct Tidpair292846 Tidpair292846; typedef struct Tnodepair292858 Tnodepair292858; typedef struct Filenamemapping203005 Filenamemapping203005; typedef struct TY332033 TY332033; typedef struct Tindex332019 Tindex332019; typedef struct Tiitable299142 Tiitable299142; typedef struct Tiipairseq299140 Tiipairseq299140; typedef struct Table332054 Table332054; typedef struct Keyvaluepairseq332057 Keyvaluepairseq332057; typedef struct Memfile330202 Memfile330202; typedef struct TY292961 TY292961; typedef struct Tiipair299138 Tiipair299138; typedef struct Keyvaluepair332060 Keyvaluepair332060; 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 Intset268030 { NI counter; NI max; Trunk268026* head; Trunkseq268028* data; }; struct TNimObject { TNimType* m_type; }; struct Tidobj199004 { TNimObject Sup; NI id; }; typedef NU8 Tsymkind292435; struct Tstrtable292806 { NI counter; Tsymseq292804* data; }; typedef NU16 Tmagic292524; struct Tlineinfo191336 { NI16 line; NI16 col; NI32 fileindex; }; typedef NU32 Tsymflag292184Set; typedef NU32 Toption169009Set; typedef NU8 Tlockind292808; typedef NU8 Tstorageloc292812; typedef NU16 Tlocflag292810Set; struct Tloc292816 { Tlockind292808 k; Tstorageloc292812 s; Tlocflag292810Set flags; Ttype292840* t; Ropeobj178006* r; }; struct Tsym292834 { Tidobj199004 Sup; Tsymkind292435 kind; union{ struct {Ttypeseq292836* typeinstcache; } S1; struct {TY292929* procinstcache; Tsym292834* gcunsafetyreason; } S2; struct {TY292929* usedgenerics; Tstrtable292806 tab; } S3; struct {Tsym292834* guard; NI bitsize; } S4; } kindU; Tmagic292524 magic; Ttype292840* typ; Tident199010* name; Tlineinfo191336 info; Tsym292834* owner; Tsymflag292184Set flags; Tnode292802* ast; Toption169009Set options; NI position; NI offset; Tloc292816 loc; Tlib292820* annex; Tnode292802* constraint; }; struct TY203018 { NimStringDesc* Field0; NI Field1; }; struct Tpasscontext341002 { TNimObject Sup; NIM_BOOL fromcache; }; typedef Ropeobj178006* Tcfilesections529009[18]; typedef NU8 Codegenflag529025Set; struct Tidtable292850 { NI counter; Tidpairseq292848* data; }; struct Tlinkedlist147013 { Tlistentry147007* head; Tlistentry147007* tail; NI counter; }; struct Tnodetable292862 { NI counter; Tnodepairseq292860* data; }; typedef Ropeobj178006* TY529136[10]; struct Tcgen529027 { Tpasscontext341002 Sup; Tcfilesections529009 s; Codegenflag529025Set flags; Tsym292834* module; NimStringDesc* filename; NimStringDesc* cfilename; Ropeobj178006* tmpbase; Tidtable292850 typecache; Tidtable292850 forwtypecache; Intset268030 declaredthings; Intset268030 declaredprotos; Tlinkedlist147013 headerfiles; Intset268030 typeinfomarker; Tcproc529021* initproc; Tcproc529021* postinitproc; Tcproc529021* preinitproc; Ttypeseq292836* typestack; Tnodetable292862 datacache; Tsymseq292804* forwardedprocs; NI typenodes; NI nimtypes; Ropeobj178006* typenodesname; Ropeobj178006* nimtypesname; NI labels; TY529136 extensionloaders; Ropeobj178006* injectstmt; }; struct Debuginfo203009 { NI version; TY203021* files; TY203023* enums; NIM_BOOL conflicts; }; struct Tident199010 { Tidobj199004 Sup; NimStringDesc* s; Tident199010* next; NI h; }; struct Tcproc529021 { Tsym292834* prc; NIM_BOOL beforeretneeded; NIM_BOOL threadvaraccessed; Tlineinfo191336 lastlineinfo; Tnodeseq292796* nestedtrystmts; NI inexceptblock; TY191350* finallysafepoints; NI labels; TY529095* blocks; NI breakidx; Toption169009Set options; NI maxframelen; Tcgen529027* module; NI withinloop; NI splitdecls; NI gcframeid; Ropeobj178006* gcframetype; }; typedef NU8 Tsymflag292184; typedef NU8 Codegenflag529025; typedef NU8 Toption169009; typedef NU64 Tglobaloption169013Set; typedef NU8 Tglobaloption169013; typedef NU8 Tcommands169076; typedef NU16 Tnodeflag292427Set; typedef NU8 Tnodekind292020; struct Tnode292802 { Ttype292840* typ; Tlineinfo191336 info; Tnodeflag292427Set flags; Tnodekind292020 kind; union{ struct {NI64 intval; } S1; struct {NF floatval; } S2; struct {NimStringDesc* strval; } S3; struct {Tsym292834* sym; } S4; struct {Tident199010* ident; } S5; struct {Tnodeseq292796* sons; } S6; } kindU; NimStringDesc* comment; }; typedef Ropeobj178006* TY533289[1]; typedef NU8 Tlocflag292810; struct Tlistentry147007 { TNimObject Sup; Tlistentry147007* prev; Tlistentry147007* next; }; typedef NU8 Tlibkind292818; struct Tlib292820 { Tlistentry147007 Sup; Tlibkind292818 kind; NIM_BOOL generated; NIM_BOOL isoverriden; Ropeobj178006* name; Tnode292802* path; }; typedef NU8 Tcfilesection529005; typedef NU8 Ttypekind292244; typedef NU8 Tcallingconvention292002; typedef NU32 Ttypeflag292431Set; struct Ttype292840 { Tidobj199004 Sup; Ttypekind292244 kind; Tcallingconvention292002 callconv; Ttypeflag292431Set flags; Ttypeseq292836* sons; Tnode292802* n; Tsym292834* owner; Tsym292834* sym; Tsym292834* destructor; Tsym292834* deepcopy; Tsym292834* assignment; TY292960* methods; NI64 size; NI16 align; NI16 locklevel; Tloc292816 loc; }; typedef Ropeobj178006* TY532811[2]; typedef NU8 Tctypekind529007; typedef NU64 Ttypekind292244Set; typedef NU8 Ttypeflag292431; typedef NimStringDesc* TY533943[14]; typedef NU8 Tprefereddesc320011; typedef Ropeobj178006* TY178507[1]; struct Enumdesc203007 { NI size; NU32 owner; NI id; NimStringDesc* name; TY203017* values; }; typedef Ropeobj178006* TY535235[4]; typedef NimStringDesc* TY292016[10]; typedef Ropeobj178006* TY535238[3]; struct Ropeobj178006 { TNimObject Sup; Ropeobj178006* left; Ropeobj178006* right; NI length; NimStringDesc* data; }; typedef NU8 Tinfoccprop273004Set; struct Tinfocc273008 { 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; Tinfoccprop273004Set Field20; }; typedef Tinfocc273008 TY273427[13]; typedef NU8 Tsystemcc273002; typedef NU8 Tnodeflag292427; typedef NU8 Tcprocsection529011; typedef Ropeobj178006* Tcprocsections529013[3]; struct Tblock529019 { NI id; Ropeobj178006* label; Tcprocsections529013 sections; NIM_BOOL isloop; NI16 nestedtrystmts; NI16 nestedexceptstmts; NI16 framelen; }; typedef NU8 Tgcmode169080; typedef NU8 Ttypeinforeason537016; struct Ttraversalclosure537019 { Tcproc529021* p; NimStringDesc* visitorfrmt; }; typedef NU8 Ttypefieldresult320145; typedef NU8 Tinfoccprop273004; typedef Ropeobj178006* TY536847[6]; typedef Ropeobj178006* TY536401[7]; typedef Ropeobj178006* TY536475[5]; typedef NU16 Tmsgkind191002; typedef NU8 Tassignmentflag538302Set; typedef NU8 Tassignmentflag538302; typedef NimStringDesc* TY552655[19]; typedef NimStringDesc* TY551642[3]; typedef NimStringDesc* TY556764[4]; typedef NimStringDesc* TY551828[42]; typedef NimStringDesc* TY551281[7]; typedef NU8 Trenderflag311004Set; typedef NimStringDesc* TY557052[2]; typedef NU8 Tclosuretypekind535679; typedef NimStringDesc* TY556428[6]; typedef NU8 Tanalysisresult473003; typedef NU8 char136Set[32]; typedef NU8 Tdistinctcompare324427; typedef NU8 Ttypecmpflag324429Set; typedef NU16 Tspecialword275003; typedef NU8 Tsystemos176004; struct Tfileinfo191334 { NimStringDesc* fullpath; NimStringDesc* projpath; NimStringDesc* shortname; Ropeobj178006* quotedname; Ropeobj178006* quotedfullname; TY191350* lines; NimStringDesc* dirtyfile; }; typedef NU8 Tinfoosprop176031Set; struct Tinfoos176035 { NimStringDesc* Field0; NimStringDesc* Field1; NimStringDesc* Field2; NimStringDesc* Field3; NimStringDesc* Field4; NimStringDesc* Field5; NimStringDesc* Field6; NimStringDesc* Field7; NimStringDesc* Field8; NimStringDesc* Field9; NimStringDesc* Field10; NimStringDesc* Field11; Tinfoosprop176031Set Field12; }; typedef Tinfoos176035 TY176082[24]; typedef NU8 Tendian176474; struct Tinfocpu176476 { NimStringDesc* Field0; NI Field1; Tendian176474 Field2; NI Field3; NI Field4; }; typedef Tinfocpu176476 TY176510[19]; typedef NU8 Tsystemcpu176452; struct Tstrentry147009 { Tlistentry147007 Sup; NimStringDesc* data; }; struct TY128506 { 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 Trunk268026 { Trunk268026* next; NI key; TY29418 bits; }; struct Tidpair292846 { Tidobj199004* key; TNimObject* val; }; struct Tnodepair292858 { NI h; Tnode292802* key; NI val; }; struct Filenamemapping203005 { NimStringDesc* package; NimStringDesc* file; NU32 mangled; }; typedef NU8 Treasonforrecompile332002; struct Tiitable299142 { NI counter; Tiipairseq299140* data; }; struct Tindex332019 { NI lastidxkey; NI lastidxval; Tiitable299142 tab; NimStringDesc* r; NI offset; }; struct Table332054 { Keyvaluepairseq332057* data; NI counter; }; struct Memfile330202 { void* mem; NI size; int handle; }; struct Trodreader332021 { TNimObject Sup; NI pos; NCSTRING s; Toption169009Set options; Treasonforrecompile332002 reason; TY332033* moddeps; TY332033* files; NI dataidx; NI convertersidx; NI initidx; NI interfidx; NI compilerprocsidx; NI methodsidx; NimStringDesc* filename; Tindex332019 index; Tindex332019 imports; NI readerindex; NI line; NI moduleid; Table332054 syms; Memfile330202 memfile; Tsymseq292804* methods; NimStringDesc* origfile; NIM_BOOL inviewmode; }; struct TY292961 { NI Field0; Tsym292834* Field1; }; struct Freecell29429 { Freecell29429* next; NI zerofield; }; struct Tinstantiation292824 { Tsym292834* sym; Ttypeseq292836* concretetypes; NI compilesid; }; struct Tiipair299138 { NI key; NI val; }; struct Keyvaluepair332060 { NI Field0; NI Field1; Tsym292834* Field2; }; struct Ttypeseq292836 { TGenericSeq Sup; Ttype292840* data[SEQ_DECL_SIZE]; }; struct TY529153 { TGenericSeq Sup; Tcgen529027* data[SEQ_DECL_SIZE]; }; struct Tsymseq292804 { TGenericSeq Sup; Tsym292834* data[SEQ_DECL_SIZE]; }; struct TY203017 { TGenericSeq Sup; TY203018 data[SEQ_DECL_SIZE]; }; struct TY135002 { TGenericSeq Sup; NimStringDesc* data[SEQ_DECL_SIZE]; }; struct Tbitset339004 { TGenericSeq Sup; NI8 data[SEQ_DECL_SIZE]; }; struct TY529095 { TGenericSeq Sup; Tblock529019 data[SEQ_DECL_SIZE]; }; struct TY191350 { TGenericSeq Sup; Ropeobj178006* data[SEQ_DECL_SIZE]; }; struct Tnodeseq292796 { TGenericSeq Sup; Tnode292802* data[SEQ_DECL_SIZE]; }; struct TY191612 { TGenericSeq Sup; Tfileinfo191334 data[SEQ_DECL_SIZE]; }; struct Trunkseq268028 { TGenericSeq Sup; Trunk268026* data[SEQ_DECL_SIZE]; }; struct TY292929 { TGenericSeq Sup; Tinstantiation292824* data[SEQ_DECL_SIZE]; }; struct Tidpairseq292848 { TGenericSeq Sup; Tidpair292846 data[SEQ_DECL_SIZE]; }; struct Tnodepairseq292860 { TGenericSeq Sup; Tnodepair292858 data[SEQ_DECL_SIZE]; }; struct TY203021 { TGenericSeq Sup; Filenamemapping203005 data[SEQ_DECL_SIZE]; }; struct TY203023 { TGenericSeq Sup; Enumdesc203007 data[SEQ_DECL_SIZE]; }; struct TY292960 { TGenericSeq Sup; TY292961 data[SEQ_DECL_SIZE]; }; struct TY332033 { TGenericSeq Sup; NI32 data[SEQ_DECL_SIZE]; }; struct Tiipairseq299140 { TGenericSeq Sup; Tiipair299138 data[SEQ_DECL_SIZE]; }; struct Keyvaluepairseq332057 { TGenericSeq Sup; Keyvaluepair332060 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(Ropeobj178006*, rope_178277_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_268885_2627731572)(Intset268030* Result); N_NOINLINE(void, chckNil)(void* p0); N_NIMCALL(void, genericReset)(void* dest0, TNimType* mt0); N_NIMCALL(void, T839829468_8)(void); N_NIMCALL(Tcgen529027*, newmodule_563045_839829468)(Tsym292834* module0); N_NIMCALL(Tcgen529027*, getcgenmodule_532226_839829468)(Tsym292834* s0); N_NIMCALL(void, internalerror_196113_155036129)(NimStringDesc* errmsg0); N_NIMCALL(NimStringDesc*, HEX24_196185_1689653243)(TY203018 x0); N_NIMCALL(Tcgen529027*, rawnewmodule_563038_839829468)(Tsym292834* module0); N_NIMCALL(Tcgen529027*, rawnewmodule_562663_839829468)(Tsym292834* 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_532977_839829468)(Tsym292834* s0); N_NIMCALL(NU32, register_203121_1926258066)(Debuginfo203009* self0, NimStringDesc* package0, NimStringDesc* file0); N_NIMCALL(NimStringDesc*, rawNewString)(NI space0); N_NIMCALL(void, initlinkedlist_147031_3771138726)(Tlinkedlist147013* list0); N_NIMCALL(NimStringDesc*, copyStringRC1)(NimStringDesc* src0); N_NIMCALL(void, initidtable_296019_850551059)(Tidtable292850* x0); N_NIMCALL(Tcproc529021*, newproc_529206_3723162438)(Tsym292834* prc0, Tcgen529027* 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(Toption169009Set, initprocoptions_562635_839829468)(Tcgen529027* m0); N_NIMCALL(Tcproc529021*, newpreinitproc_562625_839829468)(Tcgen529027* m0); N_NIMCALL(Tcproc529021*, newpostinitproc_562630_839829468)(Tcgen529027* m0); N_NIMCALL(void, initnodetable_296085_850551059)(Tnodetable292862* x0); N_NIMCALL(Ropeobj178006*, gettempname_533596_839829468)(Tcgen529027* m0); N_NIMCALL(Ropeobj178006*, HEX26_178418_2381377266)(Ropeobj178006* a0, Ropeobj178006* b0); N_NIMCALL(Ropeobj178006*, rope_178401_2381377266)(NI64 i0); N_NIMCALL(NimStringDesc*, tofullpath_192264_155036129)(NI32 fileidx0); N_NIMCALL(TGenericSeq*, setLengthSeq)(TGenericSeq* seq0, NI elemsize0, NI newlen0); N_NIMCALL(NimStringDesc*, tofilename_192260_155036129)(NI32 fileidx0); N_NIMCALL(NimStringDesc*, noschangeFileExt)(NimStringDesc* filename0, NimStringDesc* ext0); N_NIMCALL(NimStringDesc*, completecfilepath_273854_2528170400)(NimStringDesc* cfile0, NIM_BOOL createsubdir0); N_NIMCALL(void, readmergeinfo_530613_2760143328)(NimStringDesc* cfilename0, Tcgen529027* m0); N_NIMCALL(NimStringDesc*, getcfile_563204_839829468)(Tcgen529027* m0); N_NIMCALL(NimStringDesc*, copyString)(NimStringDesc* src0); N_NIMCALL(NimStringDesc*, withpackagename_170073_2607990831)(NimStringDesc* path0); static N_INLINE(NIM_BOOL, skipcodegen_341085_2355241294)(Tnode292802* n0); N_NIMCALL(void, genstmts_539244_839829468)(Tcproc529021* p0, Tnode292802* t0); N_NIMCALL(void, expr_539248_839829468)(Tcproc529021* p0, Tnode292802* n0, Tloc292816* d0); N_NIMCALL(void, fillprocloc_539201_839829468)(Tsym292834* sym0); N_NIMCALL(void, fillloc_532282_839829468)(Tloc292816* a0, Tlockind292808 k0, Ttype292840* typ0, Ropeobj178006* r0, Tstorageloc292812 s0); N_NIMCALL(void, unsureAsgnRef)(void** dest0, void* src0); N_NIMCALL(Ropeobj178006*, manglename_533205_839829468)(Tsym292834* s0); N_NIMCALL(NIM_BOOL, iskeyword_532960_839829468)(Tident199010* w0); N_NIMCALL(NimStringDesc*, mangle_528847_2036603609)(NimStringDesc* name0); N_NIMCALL(void, add_178487_2381377266)(Ropeobj178006** a0, NimStringDesc* b0); N_NIMCALL(void, add_178482_2381377266)(Ropeobj178006** a0, Ropeobj178006* b0); N_NIMCALL(Ropeobj178006*, HEX25_178905_2381377266)(NimStringDesc* frmt0, Ropeobj178006** args0, NI args0Len0); N_NIMCALL(void, genprocprototype_539254_839829468)(Tcgen529027* m0, Tsym292834* sym0); N_NIMCALL(void, useheader_532369_839829468)(Tcgen529027* m0, Tsym292834* sym0); N_NIMCALL(NIM_BOOL, includestr_147249_3771138726)(Tlinkedlist147013* list0, NimStringDesc* data0); N_NIMCALL(NimStringDesc*, getstr_297230_850551059)(Tnode292802* a0); N_NIMCALL(Tsym292834*, getmodule_299123_2984716966)(Tsym292834* s0); N_NIMCALL(NIM_BOOL, containsorincl_268862_2627731572)(Intset268030* s0, NI key0); N_NIMCALL(Ropeobj178006*, ropecg_532407_839829468)(Tcgen529027* m0, NimStringDesc* frmt0, Ropeobj178006** 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(Ropeobj178006*, cgsym_532403_839829468)(Tcgen529027* m0, NimStringDesc* name0); N_NIMCALL(Tsym292834*, getcompilerproc_338746_3937434831)(NimStringDesc* name0); N_NIMCALL(void, genproc_532951_839829468)(Tcgen529027* m0, Tsym292834* prc0); N_NIMCALL(NIM_BOOL, isactivated_561431_839829468)(Tsym292834* prc0); N_NIMCALL(void, addforwardedproc_532203_839829468)(Tcgen529027* m0, Tsym292834* prc0); N_NIMCALL(TGenericSeq*, incrSeqV2)(TGenericSeq* seq0, NI elemsize0); N_NIMCALL(void, genprocnoforward_560906_839829468)(Tcgen529027* m0, Tsym292834* prc0); N_NIMCALL(void, genprocaux_560284_839829468)(Tcgen529027* m0, Tsym292834* prc0); N_NIMCALL(Ropeobj178006*, genprocheader_535867_839829468)(Tcgen529027* m0, Tsym292834* prc0); N_NIMCALL(void, genclinedir_532813_839829468)(Ropeobj178006** r0, Tlineinfo191336 info0); N_NIMCALL(void, genclinedir_532725_839829468)(Ropeobj178006** r0, NimStringDesc* filename0, NI line0); N_NIMCALL(void, addf_179205_2381377266)(Ropeobj178006** c0, NimStringDesc* frmt0, Ropeobj178006** args0, NI args0Len0); N_NIMCALL(NimStringDesc*, makesinglelinecstring_528835_2036603609)(NimStringDesc* s0); N_NIMCALL(NI, safelinenm_532721_839829468)(Tlineinfo191336 info0); static N_INLINE(NI, tolinenumber_192415_155036129)(Tlineinfo191336 info0); N_NIMCALL(void, genprocparams_534115_839829468)(Tcgen529027* m0, Ttype292840* t0, Ropeobj178006** rettype0, Ropeobj178006** params0, Intset268030* check0, NIM_BOOL declareenvironment0, NIM_BOOL weakdep0); N_NIMCALL(NIM_BOOL, isinvalidreturntype_533548_839829468)(Ttype292840* rettype0); N_NIMCALL(Tctypekind529007, maptype_533393_839829468)(Ttype292840* typ0); N_NIMCALL(Tctypekind529007, mapsettype_533389_839829468)(Ttype292840* typ0); N_NIMCALL(NI64, getsize_320135_3876443242)(Ttype292840* typ0); N_NIMCALL(Ttype292840*, lastson_295377_850551059)(Ttype292840* n0); N_NIMCALL(NI64, firstord_320001_3876443242)(Ttype292840* t0); N_NIMCALL(Ttype292840*, skiptypes_296099_850551059)(Ttype292840* t0, Ttypekind292244Set kinds0); N_NIMCALL(NIM_BOOL, isimportedcpptype_533476_839829468)(Ttype292840* t0); N_NIMCALL(NIM_BOOL, needscomplexassignment_533509_839829468)(Ttype292840* typ0); N_NIMCALL(NIM_BOOL, containsgarbagecollectedref_320117_3876443242)(Ttype292840* typ0); static N_INLINE(NIM_BOOL, isobjlackingtypefield_533513_839829468)(Ttype292840* typ0); N_NIMCALL(NIM_BOOL, ispureobject_320138_3876443242)(Ttype292840* typ0); N_NIMCALL(Ropeobj178006*, gettypedescaux_533503_839829468)(Tcgen529027* m0, Ttype292840* typ0, Intset268030* check0); N_NIMCALL(Ttype292840*, getuniquetype_528640_2036603609)(Ttype292840* key0); N_NIMCALL(Ropeobj178006*, gettypepre_533972_839829468)(Tcgen529027* m0, Ttype292840* typ0); N_NIMCALL(Ropeobj178006*, getsimpletypedesc_533936_839829468)(Tcgen529027* m0, Ttype292840* typ0); N_NIMCALL(Ropeobj178006*, typenameorliteral_533898_839829468)(Ttype292840* t0, NimStringDesc* literal0); N_NIMCALL(Ropeobj178006*, gettypename_533313_839829468)(Ttype292840* typ0); N_NIMCALL(Ropeobj178006*, typename_533292_839829468)(Ttype292840* typ0); N_NIMCALL(NimStringDesc*, reprEnum)(NI e0, TNimType* typ0); N_NIMCALL(Ropeobj178006*, cachegettype_533591_839829468)(Tidtable292850 tab0, Ttype292840* key0); N_NIMCALL(TNimObject*, idtableget_299086_2984716966)(Tidtable292850 t0, Tidobj199004* key0); N_NIMCALL(NimStringDesc*, typetostring_320017_3876443242)(Ttype292840* typ0, Tprefereddesc320011 prefer0); N_NIMCALL(Ttype292840*, elemtype_320394_3876443242)(Ttype292840* t0); N_NIMCALL(Ropeobj178006*, HEX26_178447_2381377266)(Ropeobj178006* a0, NimStringDesc* b0); N_NIMCALL(Ropeobj178006*, gettypeforward_534039_839829468)(Tcgen529027* m0, Ttype292840* typ0); N_NIMCALL(NIM_BOOL, isimportedtype_533449_839829468)(Ttype292840* t0); N_NIMCALL(NimStringDesc*, getforwardstructformat_534015_839829468)(Tcgen529027* m0); N_NIMCALL(Ropeobj178006*, structorunion_534001_839829468)(Ttype292840* t0); N_NIMCALL(void, idtableput_299094_2984716966)(Tidtable292850* t0, Tidobj199004* key0, TNimObject* val0); N_NIMCALL(void, pushtype_533958_839829468)(Tcgen529027* m0, Ttype292840* typ0); N_NIMCALL(Ropeobj178006*, gettypedescweak_534079_839829468)(Tcgen529027* m0, Ttype292840* t0, Intset268030* check0); N_NIMCALL(void, internalerror_196100_155036129)(Tlineinfo191336 info0, NimStringDesc* errmsg0); N_NIMCALL(NIM_BOOL, hasenum_203230_1926258066)(Debuginfo203009 self0, NimStringDesc* ename0, NI id0, NU32 owner0); N_NIMCALL(void*, newSeq)(TNimType* typ0, NI len0); static N_INLINE(NI, len_293081_850551059)(Tnode292802* n0); N_NIMCALL(void, registerenum_203419_1926258066)(Debuginfo203009* self0, Enumdesc203007* ed0); N_NIMCALL(void, genericSeqAssign)(void* dest0, void* src_86404_1689653243, TNimType* mt0); N_NIMCALL(void, appcg_532632_839829468)(Tcgen529027* m0, Ropeobj178006** c0, NimStringDesc* frmt0, Ropeobj178006** args0, NI args0Len0); N_NIMCALL(NI64, lengthord_320007_3876443242)(Ttype292840* t0); N_NIMCALL(NIM_BOOL, scancppgenericslot_534827_839829468)(NimStringDesc* pat0, NI* cursor0, NI* outidx0, NI* outstars0); N_NIMCALL(Ttype292840*, resolvestarsincpptype_534891_839829468)(Ttype292840* typ0, NI idx0, NI stars0); N_NIMCALL(NI, len_295339_850551059)(Ttype292840* n0); N_NIMCALL(NimStringDesc*, copyStr)(NimStringDesc* s0, NI start0); N_NIMCALL(NimStringDesc*, copyStr)(NimStringDesc* s0, NI first0); N_NIMCALL(Ropeobj178006*, getrecorddesc_534643_839829468)(Tcgen529027* m0, Ttype292840* typ0, Ropeobj178006* name0, Intset268030* check0); N_NIMCALL(Ropeobj178006*, getrecordfields_534636_839829468)(Tcgen529027* m0, Ttype292840* typ0, Intset268030* check0); N_NIMCALL(Ropeobj178006*, genrecordfieldsaux_534421_839829468)(Tcgen529027* m0, Tnode292802* n0, Ropeobj178006* accessexpr0, Ttype292840* rectype0, Intset268030* check0); N_NIMCALL(NI, sonslen_295351_850551059)(Tnode292802* n0); N_NIMCALL(Tnode292802*, lastson_295364_850551059)(Tnode292802* n0); N_NIMCALL(Ropeobj178006*, HEX26_178452_2381377266)(NimStringDesc* a0, Ropeobj178006* b0); N_NIMCALL(Ropeobj178006*, manglerecfieldname_534361_839829468)(Tsym292834* field0, Ttype292840* rectype0); N_NIMCALL(NimStringDesc*, manglefield_532973_839829468)(Tident199010* name0); N_NIMCALL(NIM_CHAR, nsuToUpperAsciiChar)(NIM_CHAR c0); N_NIMCALL(Ropeobj178006*, gettupledesc_534777_839829468)(Tcgen529027* m0, Ttype292840* typ0, Ropeobj178006* name0, Intset268030* check0); N_NIMCALL(NI, sonslen_295327_850551059)(Ttype292840* n0); N_NIMCALL(void, excl_268841_2627731572)(Intset268030* s0, NI key0); static N_INLINE(NIM_BOOL, iscompiletimeonly_328706_3876443242)(Ttype292840* t0); N_NIMCALL(Tstorageloc292812, paramstorageloc_534098_839829468)(Tsym292834* param0); N_NIMCALL(NIM_BOOL, ccgintroducedptr_533609_839829468)(Tsym292834* s0); N_NIMCALL(Tctypekind529007, mapreturntype_533445_839829468)(Ttype292840* typ0); N_NIMCALL(Tnode292802*, easyresultasgn_560191_839829468)(Tnode292802* n0); static N_INLINE(Tnode292802*, HEX5BHEX5D_293238_850551059)(Tnode292802* n0, NI i0); N_NIMCALL(Tnode292802*, getbody_335227_1724185294)(Tsym292834* s0); N_NIMCALL(Ropeobj178006*, localvardecl_538532_839829468)(Tcproc529021* p0, Tsym292834* s0); N_NIMCALL(Ropeobj178006*, gettypedesc_535671_839829468)(Tcgen529027* m0, Ttype292840* typ0); N_NIMCALL(void, initlocexprsingleuse_539289_839829468)(Tcproc529021* p0, Tnode292802* e0, Tloc292816* result0); N_NIMCALL(void, initloc_532273_839829468)(Tloc292816* result0, Tlockind292808 k0, Ttype292840* typ0, Tstorageloc292812 s0); N_NIMCALL(void, linefmt_532714_839829468)(Tcproc529021* p0, Tcprocsection529011 s0, NimStringDesc* frmt0, Ropeobj178006** args0, NI args0Len0); static N_INLINE(Ropeobj178006**, s_529179_3723162438)(Tcproc529021* p0, Tcprocsection529011 s0); N_NIMCALL(Ropeobj178006*, indentline_532656_839829468)(Tcproc529021* p0, Ropeobj178006* r0); N_NIMCALL(void, prepend_178893_2381377266)(Ropeobj178006** a0, Ropeobj178006* b0); N_NIMCALL(Ropeobj178006*, rdloc_538188_839829468)(Tloc292816 a0); N_NIMCALL(void, assignlocalvar_538614_839829468)(Tcproc529021* p0, Tsym292834* s0); N_NIMCALL(void, line_532690_839829468)(Tcproc529021* p0, Tcprocsection529011 s0, Ropeobj178006* r0); N_NIMCALL(void, localdebuginfo_538449_839829468)(Tcproc529021* p0, Tsym292834* s0); N_NIMCALL(void, linef_532700_839829468)(Tcproc529021* p0, Tcprocsection529011 s0, NimStringDesc* frmt0, Ropeobj178006** args0, NI args0Len0); N_NIMCALL(Ropeobj178006*, makecstring_191638_155036129)(NimStringDesc* s0); N_NIMCALL(NimStringDesc*, nsuNormalize)(NimStringDesc* s0); N_NIMCALL(Ropeobj178006*, gentypeinfo_535941_839829468)(Tcgen529027* m0, Ttype292840* t_535944_839829468); N_NIMCALL(Tcgen529027*, bmod_529201_3723162438)(Tsym292834* module0); N_NIMCALL(void, gentypeinfoauxbase_535960_839829468)(Tcgen529027* m0, Ttype292840* typ0, Ttype292840* origtype0, Ropeobj178006* name0, Ropeobj178006* base0); N_NIMCALL(NIM_BOOL, canformacycle_320123_3876443242)(Ttype292840* typ0); N_NIMCALL(void, gentupleinfo_536549_839829468)(Tcgen529027* m0, Ttype292840* typ0, Ropeobj178006* name0); N_NIMCALL(Ropeobj178006*, getnimnode_535945_839829468)(Tcgen529027* m0); N_NIMCALL(Ttype292840*, fakeclosuretype_537010_839829468)(Tsym292834* owner0); N_NIMCALL(Ttype292840*, newtype_295107_850551059)(Ttypekind292244 kind0, Tsym292834* owner0); N_NIMCALL(void, rawaddson_296394_850551059)(Ttype292840* father0, Ttype292840* son0); N_NIMCALL(void, gentypeinfoaux_536027_839829468)(Tcgen529027* m0, Ttype292840* typ0, Ttype292840* origtype0, Ropeobj178006* name0); N_NIMCALL(Ropeobj178006*, gentraverseproc_537632_839829468)(Tcgen529027* m0, Ttype292840* typ0, Ttypeinforeason537016 reason0); N_NIMCALL(void, gentraverseprocseq_537399_839829468)(Ttraversalclosure537019* c0, Ropeobj178006* accessor0, Ttype292840* typ0); N_NIMCALL(void, gettemp_537032_839829468)(Tcproc529021* p0, Ttype292840* t0, Tloc292816* result0, NIM_BOOL needsinit0); N_NIMCALL(void, constructloc_538388_839829468)(Tcproc529021* p0, Tloc292816 loc0, NIM_BOOL istemp0); static N_INLINE(NIM_BOOL, iscomplexvaluetype_538317_839829468)(Ttype292840* t0); N_NIMCALL(void, usestringh_532345_839829468)(Tcgen529027* m0); N_NIMCALL(Ropeobj178006*, addrloc_538204_839829468)(Tloc292816 a0); N_NIMCALL(void, genobjectinit_538242_839829468)(Tcproc529021* p0, Tcprocsection529011 section0, Ttype292840* t0, Tloc292816 a0, NIM_BOOL takeaddr0); N_NIMCALL(Ttypefieldresult320145, analyseobjectwithtypefield_320149_3876443242)(Ttype292840* t0); N_NIMCALL(Ttype292840*, getsystype_338150_3937434831)(Ttypekind292244 kind0); N_NIMCALL(void, gentraverseproc_537022_839829468)(Ttraversalclosure537019* c0, Ropeobj178006* accessor0, Ttype292840* typ_537027_839829468); static N_INLINE(Ropeobj178006*, parentobj_537257_839829468)(Ropeobj178006* accessor0, Tcgen529027* m0); N_NIMCALL(void, gentraverseproc_537039_839829468)(Ttraversalclosure537019* c0, Ropeobj178006* accessor0, Tnode292802* n0); N_NIMCALL(void, gencaserange_537028_839829468)(Tcproc529021* p0, Tnode292802* branch0); N_NIMCALL(Ropeobj178006*, genliteral_539273_839829468)(Tcproc529021* p0, Tnode292802* n0); N_NIMCALL(Ropeobj178006*, genliteral_549476_839829468)(Tcproc529021* p0, Tnode292802* n0, Ttype292840* ty0); N_NIMCALL(Ropeobj178006*, intliteral_539270_839829468)(NI64 i0); N_NIMCALL(Ropeobj178006*, int64literal_549430_839829468)(NI64 i0); N_NIMCALL(Ropeobj178006*, uint64literal_549442_839829468)(NU64 i0); N_NIMCALL(NI, nodetabletestorset_342682_1142335848)(Tnodetable292862* t0, Tnode292802* key0, NI val0); N_NIMCALL(Ropeobj178006*, getstrlit_549468_839829468)(Tcgen529027* m0, NimStringDesc* s0); N_NIMCALL(NimStringDesc*, tostrmaxprecision_298007_3471544153)(NF f0); N_NIMCALL(Tnode292802*, copynode_296528_850551059)(Tnode292802* src0); N_NIMCALL(void, linecg_532707_839829468)(Tcproc529021* p0, Tcprocsection529011 s0, NimStringDesc* frmt0, Ropeobj178006** args0, NI args0Len0); N_NIMCALL(void, genarrayinfo_537005_839829468)(Tcgen529027* m0, Ttype292840* typ0, Ropeobj178006* name0); N_NIMCALL(void, gensetinfo_536867_839829468)(Tcgen529027* m0, Ttype292840* typ0, Ropeobj178006* name0); N_NIMCALL(void, genenuminfo_536597_839829468)(Tcgen529027* m0, Ttype292840* typ0, Ropeobj178006* name0); N_NIMCALL(void, genobjectinfo_536506_839829468)(Tcgen529027* m0, Ttype292840* typ0, Ttype292840* origtype0, Ropeobj178006* name0); N_NIMCALL(void, genobjectfields_536104_839829468)(Tcgen529027* m0, Ttype292840* typ0, Tnode292802* n0, Ropeobj178006* expr0); N_NIMCALL(Ropeobj178006*, discriminatortablename_536057_839829468)(Tcgen529027* m0, Ttype292840* objtype_536060_839829468, Tsym292834* d0); N_NIMCALL(Tsym292834*, lookupinrecord_299119_2984716966)(Tnode292802* n0, Tident199010* field0); N_NIMCALL(NI64, getordvalue_320129_3876443242)(Tnode292802* n0); N_NIMCALL(void, gendeepcopyproc_538066_839829468)(Tcgen529027* m0, Tsym292834* s0, Ropeobj178006* result0); N_NIMCALL(void, initlocalvar_538398_839829468)(Tcproc529021* p0, Tsym292834* v0, NIM_BOOL immediateasgn0); N_NIMCALL(void, fillresult_533865_839829468)(Tsym292834* param0); N_NIMCALL(void, assignparam_538994_839829468)(Tcproc529021* p0, Tsym292834* s0); N_NIMCALL(void, closuresetup_560158_839829468)(Tcproc529021* p0, Tsym292834* prc0); N_NIMCALL(Ropeobj178006*, initgcframe_538435_839829468)(Tcproc529021* p0); N_NIMCALL(Ropeobj178006*, initframe_560140_839829468)(Tcproc529021* p0, Ropeobj178006* procname0, Ropeobj178006* filename0); N_NIMCALL(Ropeobj178006*, quotedfilename_196818_155036129)(Tlineinfo191336 i0); N_NIMCALL(void, appcg_532648_839829468)(Tcproc529021* p0, Tcprocsection529011 s0, NimStringDesc* frmt0, Ropeobj178006** args0, NI args0Len0); N_NIMCALL(Ropeobj178006*, deinitgcframe_538441_839829468)(Tcproc529021* p0); N_NIMCALL(Ropeobj178006*, deinitframe_560150_839829468)(Tcproc529021* p0); N_NIMCALL(Tcgen529027*, findpendingmodule_532241_839829468)(Tcgen529027* m0, Tsym292834* s0); N_NIMCALL(void, symindynamiclib_559929_839829468)(Tcgen529027* m0, Tsym292834* sym0); N_NIMCALL(NIM_BOOL, isgetprocaddr_559442_839829468)(Tlib292820* lib0); N_NIMCALL(void, loaddynamiclib_559480_839829468)(Tcgen529027* m0, Tlib292820* lib0); N_NIMCALL(void, libcandidates_170605_2607990831)(NimStringDesc* s0, TY135002** dest0); N_NIMCALL(void, rawmessage_194612_155036129)(Tmsgkind191002 msg0, NimStringDesc* arg0); N_NIMCALL(void, initlocexpr_539283_839829468)(Tcproc529021* p0, Tnode292802* e0, Tloc292816* result0); N_NIMCALL(Ropeobj178006*, mangledynlibproc_538816_839829468)(Tsym292834* sym0); N_NIMCALL(NimStringDesc*, HEX24_178856_2381377266)(Ropeobj178006* r0); N_NIMCALL(void, symindynamiclibpartial_560071_839829468)(Tcgen529027* m0, Tsym292834* sym0); N_NIMCALL(void, genvarprototype_539236_839829468)(Tcgen529027* m0, Tsym292834* sym0); N_NIMCALL(void, genvarprototypeaux_544254_839829468)(Tcgen529027* m0, Tsym292834* sym0); N_NIMCALL(void, declarethreadvar_538676_839829468)(Tcgen529027* m0, Tsym292834* s0, NIM_BOOL isextern0); static N_INLINE(NIM_BOOL, emulatedthreadvars_532949_839829468)(void); static N_INLINE(NIM_BOOL, crossescppboundary_560754_839829468)(Tcgen529027* m0, Tsym292834* sym0); N_NIMCALL(void, putlocintodest_539258_839829468)(Tcproc529021* p0, Tloc292816* d0, Tloc292816 s0); N_NIMCALL(void, genassignment_539264_839829468)(Tcproc529021* p0, Tloc292816 dest0, Tloc292816 src0, Tassignmentflag538302Set flags0); N_NIMCALL(void, genrefassign_538311_839829468)(Tcproc529021* p0, Tloc292816 dest0, Tloc292816 src0, Tassignmentflag538302Set flags0); static N_INLINE(NIM_BOOL, usesnativegc_169177_2607990831)(void); N_NIMCALL(void, optasgnloc_549788_839829468)(Tloc292816 a0, Ttype292840* t0, Ropeobj178006* field0, Tloc292816* Result); N_NIMCALL(void, genoptasgntuple_550001_839829468)(Tcproc529021* p0, Tloc292816 dest0, Tloc292816 src0, Tassignmentflag538302Set flags0); N_NIMCALL(void, gengenericasgn_550167_839829468)(Tcproc529021* p0, Tloc292816 dest0, Tloc292816 src0, Tassignmentflag538302Set flags0); N_NIMCALL(NI, asgncomplexity_549750_839829468)(Tnode292802* n0); N_NIMCALL(void, genoptasgnobject_550084_839829468)(Tcproc529021* p0, Tloc292816 dest0, Tloc292816 src0, Tassignmentflag538302Set flags0, Tnode292802* t0); N_NIMCALL(void, genericAssign)(void* dest0, void* src0, TNimType* mt0); N_NIMCALL(void, localerror_196085_155036129)(Tlineinfo191336 info0, NimStringDesc* arg0); N_NIMCALL(NIM_BOOL, issimpleconst_532311_839829468)(Ttype292840* typ0); N_NIMCALL(void, putintodest_550468_839829468)(Tcproc529021* p0, Tloc292816* d0, Ttype292840* t0, Ropeobj178006* r0, Tstorageloc292812 s0); N_NIMCALL(void, gencomplexconst_558249_839829468)(Tcproc529021* p0, Tsym292834* sym0, Tloc292816* d0); N_NIMCALL(void, requestconstimpl_539240_839829468)(Tcproc529021* p0, Tsym292834* sym0); N_NIMCALL(Ropeobj178006*, genconstexpr_554849_839829468)(Tcproc529021* p0, Tnode292802* n0); N_NIMCALL(void, tobitset_340001_452470228)(Tnode292802* s0, Tbitset339004** b0); N_NIMCALL(Ropeobj178006*, genrawsetdata_549629_839829468)(Tbitset339004* cs0, NI size0); N_NIMCALL(NimStringDesc*, nsuToHex)(NI64 x0, NI len0); N_NIMCALL(NI64, bitsettoword_549578_839829468)(Tbitset339004* s0, NI size0); N_NIMCALL(Ropeobj178006*, genconstseq_559371_839829468)(Tcproc529021* p0, Tnode292802* n0, Ttype292840* t0); N_NIMCALL(void, appcg_532640_839829468)(Tcgen529027* m0, Tcfilesection529005 s0, NimStringDesc* frmt0, Ropeobj178006** args0, NI args0Len0); N_NIMCALL(Ropeobj178006*, genconstsimplelist_559299_839829468)(Tcproc529021* p0, Tnode292802* n0); N_NIMCALL(Ropeobj178006*, gennamedconstexpr_559284_839829468)(Tcproc529021* p0, Tnode292802* n0); N_NIMCALL(void, accessthreadlocalvar_532945_839829468)(Tcproc529021* p0, Tsym292834* s0); static N_INLINE(Ropeobj178006**, procsec_529194_3723162438)(Tcproc529021* p0, Tcprocsection529011 s0); static N_INLINE(NIM_BOOL, isemptytype_297440_850551059)(Ttype292840* t0); N_NIMCALL(void, putdataintodest_550436_839829468)(Tcproc529021* p0, Tloc292816* d0, Ttype292840* t0, Ropeobj178006* r0); N_NIMCALL(void, genlinedir_532823_839829468)(Tcproc529021* p0, Tnode292802* t0); N_NIMCALL(Ropeobj178006*, sourceline_192068_155036129)(Tlineinfo191336 i0); N_NIMCALL(NIM_BOOL, freshlineinfo_532818_839829468)(Tcproc529021* p0, Tlineinfo191336 info0); N_NIMCALL(void, genmagicexpr_557033_839829468)(Tcproc529021* p0, Tnode292802* e0, Tloc292816* d0, Tmagic292524 op0); N_NIMCALL(void, genandor_554311_839829468)(Tcproc529021* p0, Tnode292802* e0, Tloc292816* d0, Tmagic292524 m0); N_NIMCALL(Ropeobj178006*, getlabel_539217_839829468)(Tcproc529021* p0); N_NIMCALL(void, fixlabel_539230_839829468)(Tcproc529021* p0, Ropeobj178006* labl0); N_NIMCALL(void, unaryarith_552646_839829468)(Tcproc529021* p0, Tnode292802* e0, Tloc292816* d0, Tmagic292524 op0); N_NIMCALL(void, unaryarithoverflow_551633_839829468)(Tcproc529021* p0, Tnode292802* e0, Tloc292816* d0, Tmagic292524 m0); N_NIMCALL(void, binaryfloatarith_556728_839829468)(Tcproc529021* p0, Tnode292802* e0, Tloc292816* d0, Tmagic292524 m0); N_NIMCALL(void, binaryarith_551819_839829468)(Tcproc529021* p0, Tnode292802* e0, Tloc292816* d0, Tmagic292524 op0); N_NIMCALL(void, geneqproc_552214_839829468)(Tcproc529021* p0, Tnode292802* e0, Tloc292816* d0); N_NIMCALL(void, binaryarithoverflow_551262_839829468)(Tcproc529021* p0, Tnode292802* e0, Tloc292816* d0, Tmagic292524 m0); N_NIMCALL(Ropeobj178006*, binaryarithoverflowraw_551235_839829468)(Tcproc529021* p0, Ttype292840* t0, Tloc292816 a0, Tloc292816 b0, NimStringDesc* frmt0); N_NIMCALL(Ropeobj178006*, rdcharloc_538227_839829468)(Tloc292816 a0); N_NIMCALL(NI64, lastord_320004_3876443242)(Ttype292840* t0); N_NIMCALL(void, genrepr_555339_839829468)(Tcproc529021* p0, Tnode292802* e0, Tloc292816* d0); N_NIMCALL(Ropeobj178006*, lenfield_539305_839829468)(Tcproc529021* p0); N_NIMCALL(void, gcusage_554439_839829468)(Tnode292802* n0); N_NIMCALL(void, message_196095_155036129)(Tlineinfo191336 info0, Tmsgkind191002 msg0, NimStringDesc* arg0); N_NIMCALL(NimStringDesc*, rendertree_311044_382274130)(Tnode292802* n0, Trenderflag311004Set renderflags0); N_NIMCALL(void, gengettypeinfo_555383_839829468)(Tcproc529021* p0, Tnode292802* e0, Tloc292816* d0); N_NIMCALL(void, genswap_555638_839829468)(Tcproc529021* p0, Tnode292802* e0, Tloc292816* d0); N_NIMCALL(void, unaryexpr_551209_839829468)(Tcproc529021* p0, Tnode292802* e0, Tloc292816* d0, NimStringDesc* frmt0); N_NIMCALL(void, binarystmt_550501_839829468)(Tcproc529021* p0, Tnode292802* e0, Tloc292816* d0, NimStringDesc* frmt0); N_NIMCALL(void, genstrconcat_554452_839829468)(Tcproc529021* p0, Tnode292802* e0, Tloc292816* d0); N_NIMCALL(void, genstrappend_554554_839829468)(Tcproc529021* p0, Tnode292802* e0, Tloc292816* d0); N_NIMCALL(void, genseqelemappend_554683_839829468)(Tcproc529021* p0, Tnode292802* e0, Tloc292816* d0); N_NIMCALL(void, genstrequals_556666_839829468)(Tcproc529021* p0, Tnode292802* e0, Tloc292816* d0); N_NIMCALL(void, binaryexpr_550549_839829468)(Tcproc529021* p0, Tnode292802* e0, Tloc292816* d0, NimStringDesc* frmt0); N_NIMCALL(void, genisnil_552620_839829468)(Tcproc529021* p0, Tnode292802* e0, Tloc292816* d0); N_NIMCALL(void, gendollar_555391_839829468)(Tcproc529021* p0, Tnode292802* n0, Tloc292816* d0, NimStringDesc* frmt0); N_NIMCALL(void, genof_555331_839829468)(Tcproc529021* p0, Tnode292802* n0, Tloc292816* d0); N_NIMCALL(void, genof_555201_839829468)(Tcproc529021* p0, Tnode292802* x0, Ttype292840* typ0, Tloc292816* d0); N_NIMCALL(void, globalerror_196071_155036129)(Tlineinfo191336 info0, Tmsgkind191002 msg0, NimStringDesc* arg0); N_NIMCALL(Ropeobj178006*, genofhelper_555139_839829468)(Tcproc529021* p0, Ttype292840* dest0, Ropeobj178006* a0); N_NIMCALL(void, gennew_554782_839829468)(Tcproc529021* p0, Tnode292802* e0); N_NIMCALL(void, rawgennew_554741_839829468)(Tcproc529021* p0, Tloc292816 a0, Ropeobj178006* sizeexpr_554745_839829468); N_NIMCALL(void, gennewfinalize_555110_839829468)(Tcproc529021* p0, Tnode292802* e0); N_NIMCALL(void, gennewseq_554824_839829468)(Tcproc529021* p0, Tnode292802* e0); N_NIMCALL(void, gennewseqaux_554795_839829468)(Tcproc529021* p0, Tloc292816 dest0, Ropeobj178006* length0); N_NIMCALL(void, gennewseqofcap_554836_839829468)(Tcproc529021* p0, Tnode292802* e0, Tloc292816* d0); N_NIMCALL(void, gensomecast_556480_839829468)(Tcproc529021* p0, Tnode292802* e0, Tloc292816* d0); N_NIMCALL(Ropeobj178006*, getclosuretype_535683_839829468)(Tcgen529027* m0, Ttype292840* t0, Tclosuretypekind535679 kind0); N_NIMCALL(void, genord_556474_839829468)(Tcproc529021* p0, Tnode292802* e0, Tloc292816* d0); N_NIMCALL(void, unaryexprchar_551222_839829468)(Tcproc529021* p0, Tnode292802* e0, Tloc292816* d0, NimStringDesc* frmt0); N_NIMCALL(void, genarraylen_555415_839829468)(Tcproc529021* p0, Tnode292802* e0, Tloc292816* d0, Tmagic292524 op0); N_NIMCALL(void, unarystmt_550527_839829468)(Tcproc529021* p0, Tnode292802* e0, Tloc292816* d0, NimStringDesc* frmt0); N_NIMCALL(void, gensetlengthstr_555632_839829468)(Tcproc529021* p0, Tnode292802* e0, Tloc292816* d0); N_NIMCALL(void, gensetlengthseq_555500_839829468)(Tcproc529021* p0, Tnode292802* e0, Tloc292816* d0); N_NIMCALL(void, gensetop_556419_839829468)(Tcproc529021* p0, Tnode292802* e0, Tloc292816* d0, Tmagic292524 op0); N_NIMCALL(void, binarystmtinexcl_555857_839829468)(Tcproc529021* p0, Tnode292802* e0, Tloc292816* d0, NimStringDesc* frmt0); N_NIMCALL(Ropeobj178006*, rdsetelemloc_555662_839829468)(Tloc292816 a0, Ttype292840* settype0); N_NIMCALL(void, binaryexprchar_550809_839829468)(Tcproc529021* p0, Tnode292802* e0, Tloc292816* d0, NimStringDesc* frmt0); N_NIMCALL(void, geninop_556009_839829468)(Tcproc529021* p0, Tnode292802* e0, Tloc292816* d0); N_NIMCALL(NIM_BOOL, fewcmps_555803_839829468)(Tnode292802* s0); N_NIMCALL(void, geninexpraux_553496_839829468)(Tcproc529021* p0, Tnode292802* e0, Tloc292816* a0, Tloc292816* b0, Tloc292816* d0); N_NIMCALL(void, binaryexprin_555837_839829468)(Tcproc529021* p0, Tnode292802* e0, Tloc292816* a0, Tloc292816* b0, Tloc292816* d0, NimStringDesc* frmt0); N_NIMCALL(void, gencall_543632_839829468)(Tcproc529021* p0, Tnode292802* e0, Tloc292816* d0); N_NIMCALL(void, genclosurecall_540452_839829468)(Tcproc529021* p0, Tnode292802* le0, Tnode292802* ri0, Tloc292816* d0); N_NIMCALL(Ropeobj178006*, genarg_539787_839829468)(Tcproc529021* p0, Tnode292802* n_539790_839829468, Tsym292834* param0, Tnode292802* call0); static N_INLINE(Ropeobj178006*, genargstringtocstring_539776_839829468)(Tcproc529021* p0, Tnode292802* n0); N_NIMCALL(Ropeobj178006*, openarrayloc_539665_839829468)(Tcproc529021* p0, Tnode292802* n0); N_NIMCALL(Tnode292802*, skipconv_328882_3876443242)(Tnode292802* n0); N_NIMCALL(Tmagic292524, getmagic_318502_2616423590)(Tnode292802* op0); N_NIMCALL(Ropeobj178006*, genargnoparam_539938_839829468)(Tcproc529021* p0, Tnode292802* n0); N_NIMCALL(Ropeobj178006*, getrawproctype_540459_839829468)(Tcproc529021* p0, Ttype292840* t0); N_NIMCALL(NIM_BOOL, leftappearsonrightside_539329_839829468)(Tnode292802* le0, Tnode292802* ri0); N_NIMCALL(Tanalysisresult473003, ispartof_473340_788060399)(Tnode292802* a0, Tnode292802* b0); static N_INLINE(NIM_BOOL, hasnoinit_539383_839829468)(Tnode292802* call0); N_NIMCALL(void, resetloc_538350_839829468)(Tcproc529021* p0, Tloc292816* loc0); N_NIMCALL(Ropeobj178006*, addcomma_540464_839829468)(Ropeobj178006* r0); N_NIMCALL(void, geninfixcall_541929_839829468)(Tcproc529021* p0, Tnode292802* le0, Tnode292802* ri0, Tloc292816* d0); N_NIMCALL(NIM_BOOL, contains_110056_4286263276)(NimStringDesc* s0, char136Set chars0); N_NIMCALL(Ropeobj178006*, genpatterncall_541699_839829468)(Tcproc529021* p0, Tnode292802* ri_541702_839829468, NimStringDesc* pat0, Ttype292840* typ_541704_839829468); N_NIMCALL(Ropeobj178006*, genotherarg_539277_839829468)(Tcproc529021* p0, Tnode292802* ri0, NI i0, Ttype292840* typ0); N_NIMCALL(Ropeobj178006*, genthisarg_541475_839829468)(Tcproc529021* p0, Tnode292802* ri_541478_839829468, NI i0, Ttype292840* typ0); N_NIMCALL(Tnode292802*, skipaddrderef_541433_839829468)(Tnode292802* node0); N_NIMCALL(void, fixupcall_539410_839829468)(Tcproc529021* p0, Tnode292802* le0, Tnode292802* ri0, Tloc292816* d0, Ropeobj178006* callee0, Ropeobj178006* params0); N_NIMCALL(void, gennamedparamcall_542616_839829468)(Tcproc529021* p0, Tnode292802* ri0, Tloc292816* d0); N_NIMCALL(NIM_BOOL, contains_110046_4286263276)(NimStringDesc* s0, NIM_CHAR c0); N_NIMCALL(void, genprefixcall_539960_839829468)(Tcproc529021* p0, Tnode292802* le0, Tnode292802* ri0, Tloc292816* d0); static N_INLINE(void, poststmtactions_532942_839829468)(Tcproc529021* p0); N_NIMCALL(void, genreset_554731_839829468)(Tcproc529021* p0, Tnode292802* n0); N_NIMCALL(void, genecho_554369_839829468)(Tcproc529021* p0, Tnode292802* n0); N_NIMCALL(NimStringDesc*, nsuRepeatStr)(NimStringDesc* s0, NI n0); N_NIMCALL(void, genarrtoseq_555046_839829468)(Tcproc529021* p0, Tnode292802* t0, Tloc292816* d0); N_NIMCALL(void, genseqconstr_555004_839829468)(Tcproc529021* p0, Tnode292802* t0, Tloc292816* d0); N_NIMCALL(void, localerror_196080_155036129)(Tlineinfo191336 info0, Tmsgkind191002 msg0, NimStringDesc* arg0); N_NIMCALL(Tnode292802*, wrapprocforspawn_435501_2218250499)(Tsym292834* owner0, Tnode292802* spawnexpr0, Ttype292840* rettype0, Tnode292802* barrier0, Tnode292802* dest0); N_NIMCALL(Tnode292802*, liftparallel_478822_1773027539)(Tsym292834* owner0, Tnode292802* n0); N_NIMCALL(void, gendeepcopy_550374_839829468)(Tcproc529021* p0, Tloc292816 dest0, Tloc292816 src0); N_NIMCALL(NIM_BOOL, isdeepconstexpr_318566_2616423590)(Tnode292802* n0); N_NIMCALL(Ropeobj178006*, gensetnode_549664_839829468)(Tcproc529021* p0, Tnode292802* n0); N_NIMCALL(void, gensetconstr_557496_839829468)(Tcproc529021* p0, Tnode292802* e0, Tloc292816* d0); N_NIMCALL(NimStringDesc*, nimInt64ToStr)(NI64 x0); N_NIMCALL(void, exprcomplexconst_558684_839829468)(Tcproc529021* p0, Tnode292802* n0, Tloc292816* d0); N_NIMCALL(void, genarrayconstr_558207_839829468)(Tcproc529021* p0, Tnode292802* n0, Tloc292816* d0); N_NIMCALL(NIM_BOOL, handleconstexpr_554853_839829468)(Tcproc529021* p0, Tnode292802* n0, Tloc292816* d0); N_NIMCALL(void, gentupleconstr_557618_839829468)(Tcproc529021* p0, Tnode292802* n0, Tloc292816* d0); N_NIMCALL(void, genobjconstr_554903_839829468)(Tcproc529021* p0, Tnode292802* e0, Tloc292816* d0); N_NIMCALL(Tsym292834*, lookupfieldagain_553153_839829468)(Tcproc529021* p0, Ttype292840* ty_553156_839829468, Tsym292834* field0, Ropeobj178006** r0); N_NIMCALL(void, genfieldcheck_553504_839829468)(Tcproc529021* p0, Tnode292802* e0, Ropeobj178006* obj0, Tsym292834* field0, Ttype292840* origty0); N_NIMCALL(Tnode292802*, newstrnode_293678_850551059)(Tnodekind292020 kind0, NimStringDesc* strval0); N_NIMCALL(void, gencast_556537_839829468)(Tcproc529021* p0, Tnode292802* e0, Tloc292816* d0); N_NIMCALL(void, genconv_556632_839829468)(Tcproc529021* p0, Tnode292802* e0, Tloc292816* d0); N_NIMCALL(NIM_BOOL, comparetypes_326214_3876443242)(Ttype292840* x0, Ttype292840* y0, Tdistinctcompare324427 cmp0, Ttypecmpflag324429Set flags0); N_NIMCALL(void, genaddr_553051_839829468)(Tcproc529021* p0, Tnode292802* e0, Tloc292816* d0); static N_INLINE(NIM_BOOL, iscppref_552807_839829468)(Tcproc529021* p0, Ttype292840* typ0); N_NIMCALL(void, genbracketexpr_554277_839829468)(Tcproc529021* p0, Tnode292802* n0, Tloc292816* d0); N_NIMCALL(void, genarrayelem_554093_839829468)(Tcproc529021* p0, Tnode292802* x0, Tnode292802* y0, Tloc292816* d0); N_NIMCALL(NIM_BOOL, isconstexpr_318510_2616423590)(Tnode292802* n0); N_NIMCALL(void, genopenarrayelem_554169_839829468)(Tcproc529021* p0, Tnode292802* x0, Tnode292802* y0, Tloc292816* d0); N_NIMCALL(void, genseqelem_554205_839829468)(Tcproc529021* p0, Tnode292802* x0, Tnode292802* y0, Tloc292816* d0); N_NIMCALL(void, gencstringelem_554144_839829468)(Tcproc529021* p0, Tnode292802* x0, Tnode292802* y0, Tloc292816* d0); N_NIMCALL(void, gentupleelem_553124_839829468)(Tcproc529021* p0, Tnode292802* e0, Tloc292816* d0); N_NIMCALL(void, genderef_543921_839829468)(Tcproc529021* p0, Tnode292802* e0, Tloc292816* d0, NIM_BOOL enforcederef0); N_NIMCALL(void, genrecordfield_553448_839829468)(Tcproc529021* p0, Tnode292802* e0, Tloc292816* d0); N_NIMCALL(Ttype292840*, genrecordfieldaux_553096_839829468)(Tcproc529021* p0, Tnode292802* e0, Tloc292816* d0, Tloc292816* a0); N_NIMCALL(void, gencheckedrecordfield_554046_839829468)(Tcproc529021* p0, Tnode292802* e0, Tloc292816* d0); N_NIMCALL(void, genblock_546083_839829468)(Tcproc529021* p0, Tnode292802* n0, Tloc292816* d0); N_NIMCALL(NI, startblock_543978_839829468)(Tcproc529021* p0, NimStringDesc* start0, Ropeobj178006** args0, NI args0Len0); N_NIMCALL(void, endblock_544060_839829468)(Tcproc529021* p0); N_NIMCALL(void, endblock_544035_839829468)(Tcproc529021* p0, Ropeobj178006* blockend0); N_NIMCALL(Ropeobj178006*, blockbody_544025_839829468)(Tblock529019* b0); N_NIMCALL(void, genstmtlistexpr_558402_839829468)(Tcproc529021* p0, Tnode292802* n0, Tloc292816* d0); N_NIMCALL(void, genif_544982_839829468)(Tcproc529021* p0, Tnode292802* n0, Tloc292816* d0); N_NIMCALL(void, downconv_558581_839829468)(Tcproc529021* p0, Tnode292802* n0, Tloc292816* d0); N_NIMCALL(NI, inheritancediff_326252_3876443242)(Ttype292840* a0, Ttype292840* b0); N_NIMCALL(void, upconv_558431_839829468)(Tcproc529021* p0, Tnode292802* n0, Tloc292816* d0); N_NIMCALL(void, genrangechck_556590_839829468)(Tcproc529021* p0, Tnode292802* n0, Tloc292816* d0, NimStringDesc* magic0); N_NIMCALL(void, convstrtocstr_556642_839829468)(Tcproc529021* p0, Tnode292802* n0, Tloc292816* d0); N_NIMCALL(void, convcstrtostr_556654_839829468)(Tcproc529021* p0, Tnode292802* n0, Tloc292816* d0); N_NIMCALL(void, genclosure_557836_839829468)(Tcproc529021* p0, Tnode292802* n0, Tloc292816* d0); static N_INLINE(NIM_BOOL, isconstclosure_557810_839829468)(Tnode292802* n0); static N_INLINE(NIM_BOOL, isroutine_297323_850551059)(Tsym292834* s0); N_NIMCALL(void, genwhilestmt_545984_839829468)(Tcproc529021* p0, Tnode292802* t0); static N_INLINE(Ropeobj178006*, assignlabel_544020_839829468)(Tblock529019* b0); N_NIMCALL(NIM_BOOL, stmtscontainpragma_528083_2036603609)(Tnode292802* n0, Tspecialword275003 w0); N_NIMCALL(void, gencomputedgoto_545744_839829468)(Tcproc529021* p0, Tnode292802* n0); N_NIMCALL(void, genvarstmt_544854_839829468)(Tcproc529021* p0, Tnode292802* n0); N_NIMCALL(void, gensinglevar_544276_839829468)(Tcproc529021* p0, Tnode292802* a0); N_NIMCALL(void, gengotovar_544258_839829468)(Tcproc529021* p0, Tnode292802* value0); N_NIMCALL(void, assignglobalvar_538819_839829468)(Tcproc529021* p0, Tsym292834* s0); N_NIMCALL(void, varindynamiclib_538812_839829468)(Tcgen529027* m0, Tsym292834* sym0); N_NIMCALL(void, registergcroot_543762_839829468)(Tcproc529021* p0, Tsym292834* v0); N_NIMCALL(Ropeobj178006*, gentraverseprocforglobal_538032_839829468)(Tcgen529027* m0, Tsym292834* s0); static N_INLINE(NIM_BOOL, isassignedimmediately_543781_839829468)(Tnode292802* n0); N_NIMCALL(NIM_BOOL, containshiddenpointer_320120_3876443242)(Ttype292840* typ0); static N_INLINE(void, loadinto_543928_839829468)(Tcproc529021* p0, Tnode292802* le0, Tnode292802* ri0, Tloc292816* a0); N_NIMCALL(void, genasgncall_543695_839829468)(Tcproc529021* p0, Tnode292802* le0, Tnode292802* ri0, Tloc292816* d0); N_NIMCALL(void, genclosurevar_544832_839829468)(Tcproc529021* p0, Tnode292802* a0); N_NIMCALL(void, genvartuple_543794_839829468)(Tcproc529021* p0, Tnode292802* n0); N_NIMCALL(Tnode292802*, lowertupleunpacking_433037_2218250499)(Tnode292802* n0, Tsym292834* owner0); N_NIMCALL(void, genconststmt_544909_839829468)(Tcproc529021* p0, Tnode292802* t0); N_NIMCALL(NIM_BOOL, containscompiletimeonly_328721_3876443242)(Ttype292840* t0); static N_INLINE(NIM_BOOL, emitlazily_532248_839829468)(Tsym292834* s0); N_NIMCALL(void, gencase_547826_839829468)(Tcproc529021* p0, Tnode292802* t0, Tloc292816* d0); N_NIMCALL(void, genstringcase_547416_839829468)(Tcproc529021* p0, Tnode292802* t0, Tloc292816* d0); N_NIMCALL(NI, nextpoweroftwo_101629_1009420244)(NI x0); N_NIMCALL(void, gencasestringbranch_547100_839829468)(Tcproc529021* p0, Tnode292802* b0, Tloc292816 e0, Ropeobj178006* labl0, Ropeobj178006** branches0, NI branches0Len0); N_NIMCALL(NI64, hashstring_528100_2036603609)(NimStringDesc* s0); N_NIMCALL(Ropeobj178006*, gencasesecondpass_546965_839829468)(Tcproc529021* p0, Tnode292802* t0, Tloc292816* d0, NI labid0, NI until0); N_NIMCALL(void, exprblock_544103_839829468)(Tcproc529021* p0, Tnode292802* n0, Tloc292816* d0); N_NIMCALL(void, gencasegeneric_547087_839829468)(Tcproc529021* p0, Tnode292802* t0, Tloc292816* d0, NimStringDesc* rangeformat0, NimStringDesc* eqformat0); N_NIMCALL(Ropeobj178006*, genifforcaseuntil_547021_839829468)(Tcproc529021* p0, Tnode292802* t0, Tloc292816* d0, NimStringDesc* rangeformat0, NimStringDesc* eqformat0, NI until0, Tloc292816 a0); N_NIMCALL(void, gencasegenericbranch_546910_839829468)(Tcproc529021* p0, Tnode292802* b0, Tloc292816 e0, NimStringDesc* rangeformat0, NimStringDesc* eqformat0, Ropeobj178006* labl0); N_NIMCALL(void, gengotoforcase_545673_839829468)(Tcproc529021* p0, Tnode292802* casestmt0); N_NIMCALL(void, genordinalcase_547724_839829468)(Tcproc529021* p0, Tnode292802* n0, Tloc292816* d0); N_NIMCALL(NI, ifswitchsplitpoint_547615_839829468)(Tcproc529021* p0, Tnode292802* n0); N_NIMCALL(NIM_BOOL, branchhastoobigrange_547575_839829468)(Tnode292802* b0); N_NIMCALL(void, genreturnstmt_545617_839829468)(Tcproc529021* p0, Tnode292802* t0); N_NIMCALL(void, blockleaveactions_545442_839829468)(Tcproc529021* p0, NI howmanytrys0, NI howmanyexcepts0); static N_INLINE(Tnode292802*, pop_318246_1689653243)(Tnodeseq292796** s0); N_NIMCALL(void, genbreakstmt_546444_839829468)(Tcproc529021* p0, Tnode292802* t0); N_NIMCALL(void, genasgn_549239_839829468)(Tcproc529021* p0, Tnode292802* e0, NIM_BOOL fastasgn0); N_NIMCALL(NIM_BOOL, fielddiscriminantcheckneeded_549080_839829468)(Tcproc529021* p0, Tnode292802* asgn0); N_NIMCALL(void, asgnfielddiscriminant_549209_839829468)(Tcproc529021* p0, Tnode292802* e0); N_NIMCALL(void, gendiscriminantcheck_549144_839829468)(Tcproc529021* p0, Tloc292816 a0, Tloc292816 tmp0, Ttype292840* objtype0, Tsym292834* field0); N_NIMCALL(Ropeobj178006*, discriminatortabledecl_536094_839829468)(Tcgen529027* m0, Ttype292840* objtype0, Tsym292834* d0); N_NIMCALL(void, genasmstmt_548659_839829468)(Tcproc529021* p0, Tnode292802* t0); N_NIMCALL(Ropeobj178006*, genasmoremitstmt_548529_839829468)(Tcproc529021* p0, Tnode292802* t0, NIM_BOOL isasmstmt0); N_NIMCALL(NimStringDesc*, resizeString)(NimStringDesc* dest0, NI addlen0); N_NIMCALL(void, gentrycpp_547865_839829468)(Tcproc529021* p0, Tnode292802* t0, Tloc292816* d0); static N_INLINE(void, gensimpleblock_544095_839829468)(Tcproc529021* p0, Tnode292802* stmts0); N_NIMCALL(void, gentry_548114_839829468)(Tcproc529021* p0, Tnode292802* t0, Tloc292816* d0); N_NIMCALL(NIM_BOOL, isdefined_200011_1967573533)(NimStringDesc* symbol0); N_NIMCALL(void, line_532695_839829468)(Tcproc529021* p0, Tcprocsection529011 s0, NimStringDesc* r0); static N_INLINE(Ropeobj178006*, pop_178530_1689653243)(TY191350** s0); N_NIMCALL(void, genraisestmt_546828_839829468)(Tcproc529021* p0, Tnode292802* t0); N_NIMCALL(NimStringDesc*, getraisefrmt_546824_839829468)(Tcproc529021* p0); N_NIMCALL(void, gentypesection_538184_839829468)(Tcgen529027* m0, Tnode292802* n0); N_NIMCALL(void, genpragma_549039_839829468)(Tcproc529021* p_549041_839829468, Tnode292802* n0); N_NIMCALL(Tspecialword275003, whichpragma_318911_2616423590)(Tnode292802* n0); N_NIMCALL(void, genemit_548839_839829468)(Tcproc529021* p0, Tnode292802* t0); N_NIMCALL(Tcfilesection529005, determinesection_548819_839829468)(Tnode292802* n0); N_NIMCALL(NIM_BOOL, nsuStartsWith)(NimStringDesc* s0, NimStringDesc* prefix0); N_NIMCALL(void, genbreakpoint_548862_839829468)(Tcproc529021* p0, Tnode292802* t0); N_NIMCALL(void, genwatchpoint_549016_839829468)(Tcproc529021* p0, Tnode292802* n0); N_NIMCALL(Tsym292834*, skipgenericowner_297279_850551059)(Tsym292834* s0); N_NIMCALL(void, genparforstmt_546208_839829468)(Tcproc529021* p0, Tnode292802* t0); N_NIMCALL(void, genstate_544117_839829468)(Tcproc529021* p0, Tnode292802* n0); N_NIMCALL(void, gengotostate_544144_839829468)(Tcproc529021* p0, Tnode292802* n0); N_NIMCALL(void, genbreakstate_544229_839829468)(Tcproc529021* p0, Tnode292802* n0); N_NIMCALL(void, registermoduletomain_562243_839829468)(Tsym292834* m0); N_NIMCALL(Ropeobj178006*, getinitname_562235_839829468)(Tsym292834* m0); N_NIMCALL(Ropeobj178006*, getsomeinitname_561904_839829468)(Tsym292834* m0, NimStringDesc* suffix0); N_NIMCALL(Ropeobj178006*, getdatinitname_562239_839829468)(Tsym292834* m0); N_NIMCALL(Tnode292802*, generatemethoddispatchers_432151_3853300031)(void); N_NIMCALL(void, genmainproc_561729_839829468)(Tcgen529027* m0); N_NIMCALL(Ropeobj178006*, genfilenames_561688_839829468)(Tcgen529027* m0); N_NIMCALL(void, finishmodule_563420_839829468)(Tcgen529027* m0); N_NIMCALL(void, updatecachedmodule_563813_839829468)(Tcgen529027* m0); N_NIMCALL(NIM_BOOL, mergerequired_530832_2760143328)(Tcgen529027* m0); N_NIMCALL(void, mergefiles_531241_2760143328)(NimStringDesc* cfilename0, Tcgen529027* m0); N_NIMCALL(void, geninitcode_562286_839829468)(Tcgen529027* m0); N_NIMCALL(Ropeobj178006*, gensectionstart_530081_2760143328)(Tcprocsection529011 ps0); N_NIMCALL(Ropeobj178006*, gensectionend_530116_2760143328)(Tcprocsection529011 ps0); N_NIMCALL(Ropeobj178006*, gensectionstart_530015_2760143328)(Tcfilesection529005 fs0); N_NIMCALL(Ropeobj178006*, gensectionend_530050_2760143328)(Tcfilesection529005 fs0); N_NIMCALL(void, finishtypedescriptions_535842_839829468)(Tcgen529027* m0); N_NIMCALL(Ropeobj178006*, genmodule_562491_839829468)(Tcgen529027* m0, NimStringDesc* cfile0); N_NIMCALL(Ropeobj178006*, getfileheader_561683_839829468)(NimStringDesc* cfile0); N_NIMCALL(Ropeobj178006*, getcopyright_561665_839829468)(NimStringDesc* cfile0); N_NIMCALL(NimStringDesc*, getcompilecfilecmd_274284_2528170400)(NimStringDesc* cfilename0, NIM_BOOL isexternal0); static N_INLINE(void, addinttypes_561659_839829468)(Ropeobj178006** result0); N_NIMCALL(Ropeobj178006*, genmergeinfo_530203_2760143328)(Tcgen529027* m0); N_NIMCALL(void, generatethreadlocalstorage_538717_839829468)(Tcgen529027* m0); N_NIMCALL(void, generateheaders_560104_839829468)(Tcgen529027* m0); N_NIMCALL(NimStringDesc*, nsuReplaceChar)(NimStringDesc* s0, NIM_CHAR sub0, NIM_CHAR by0); N_NIMCALL(void, writerope_178836_2381377266)(Ropeobj178006* head0, NimStringDesc* filename0, NIM_BOOL usewarning0); N_NIMCALL(void, addfiletocompile_273863_2528170400)(NimStringDesc* filename0); N_NIMCALL(void, addfiletolink_273872_2528170400)(NimStringDesc* filename0); N_NIMCALL(void, writemodule_563637_839829468)(Tcgen529027* m0, NIM_BOOL pending0); N_NIMCALL(void, generatethreadvarssize_538771_839829468)(Tcgen529027* m0); N_NIMCALL(NIM_BOOL, shouldrecompile_563621_839829468)(Ropeobj178006* code0, NimStringDesc* cfile0); N_NIMCALL(NimStringDesc*, toobjfile_273859_2528170400)(NimStringDesc* filename0); N_NIMCALL(NIM_BOOL, writeropeifnotequal_179511_2381377266)(Ropeobj178006* r0, NimStringDesc* filename0); N_NIMCALL(NIM_BOOL, nosexistsFile)(NimStringDesc* filename0); N_NIMCALL(NIM_BOOL, nosfileNewer)(NimStringDesc* a0, NimStringDesc* b0); N_NIMCALL(void, writemapping_274789_2528170400)(Ropeobj178006* gsymbolmapping0); N_NIMCALL(void, writeheader_563152_839829468)(Tcgen529027* m0); N_NIMCALL(void, nossplitFile)(NimStringDesc* path0, TY128506* Result); N_NIMCALL(void, resetmodule_562763_839829468)(Tcgen529027* m0); N_NIMCALL(void, nullify_562833_839829468)(Ropeobj178006** arr0); N_NIMCALL(void, nullify_562858_839829468)(Ropeobj178006** arr0); STRING_LITERAL(T839829468_4, "\011", 1); STRING_LITERAL(T839829468_10, "compiler/cgen.nim", 17); NIM_CONST TY203018 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 TY533943 Numericaltypetostr_533941_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 TY292016 Callingconvtostr_533585_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 TY273427 Cc_273413_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 TY203018 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 TY203018 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 TY552655 unarithtab_552653_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 TY551642 opr_551640_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 TY556764 opr_556762_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 TY551828 binarithtab_551826_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 TY551281 opr_551279_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 TY551281 prc64_551274_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 TY551281 prc_551269_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 TY557052 opr_557050_839829468 = {((NimStringDesc*) &T839829468_388), ((NimStringDesc*) &T839829468_389)} ; NIM_CONST TY557052 fun64_557055_839829468 = {((NimStringDesc*) &T839829468_360), ((NimStringDesc*) &T839829468_361)} ; NIM_CONST TY557052 fun_557060_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 TY556428 lookupopr_556426_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 TY203018 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 TY203018 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 TY203018 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 TY203018 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 TY203018 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 TY203018 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 TY176082 Os_176068_4151366050; extern NIM_CONST TY176510 Cpu_176496_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); Tcgen529027* generatedheader_532201_839829468; extern TNimType NTI529015; /* BModule */ Ropeobj178006* indent_532655_839829468; extern TNimType NTI178004; /* Rope */ extern Gcheap49818 gch_49858_1689653243; Ropeobj178006* nimtv_538656_839829468; Ttypeseq292836* nimtvdeps_538674_839829468; extern TNimType NTI292836; /* TTypeSeq */ Intset268030 nimtvdeclared_538675_839829468; extern TNimType NTI268030; /* IntSet */ NI breakpointid_548860_839829468; Ropeobj178006* gbreakpoints_548861_839829468; extern TY529153* gmodules_529170_3723162438; extern TNimType NTI529027; /* TCGen */ extern Debuginfo203009 gdebuginfo_203470_1926258066; extern Toption169009Set goptions_169128_2607990831; extern TNimType NTI292804; /* TSymSeq */ extern Tglobaloption169013Set gglobaloptions_169130_2607990831; extern NimStringDesc* headerfile_169138_2607990831; extern NimStringDesc* gprojectfull_169211_2607990831; extern Tcommands169076 gcmd_169132_2607990831; extern NI gerrorcounter_192072_155036129; extern Ropeobj178006* rnl_178903_2381377266; extern NI gforwardedprocscounter_529171_3723162438; extern TNimType NTI292244; /* TTypeKind */ extern TNimType NTI203017; /* seq[(string, int)] */ extern Tsystemcc273002 ccompiler_273431_2528170400; extern NimStringDesc* tnl_176644_4151366050; extern NI floatsize_176642_4151366050; extern Tgcmode169080 gselectedgc_169133_2607990831; extern TNimType NTI292020; /* TNodeKind */ extern TNimType NTI135002; /* seq[string] */ extern TNimType NTI292435; /* TSymKind */ extern TNimType NTI292816; /* TLoc */ extern NI intsize_176641_4151366050; extern TNimType NTI292524; /* TMagic */ extern TNimType NTI191350; /* seq[Rope] */ extern TNimType NTI292796; /* TNodeSeq */ extern Ropeobj178006* mainmodprocs_529148_3723162438; extern Ropeobj178006* maindatinit_529151_3723162438; extern Ropeobj178006* mainmodinit_529149_3723162438; extern Ropeobj178006* othermodsinit_529150_3723162438; extern Tsystemos176004 targetos_176629_4151366050; extern TY191612* fileinfos_191629_155036129; extern Tsystemcpu176452 targetcpu_176627_4151366050; extern Ropeobj178006* gmapping_529152_3723162438; N_NIMCALL(void, T839829468_2)(void) { nimGCvisit((void*)generatedheader_532201_839829468, 0); } N_NIMCALL(void, T839829468_3)(void) { nimGCvisit((void*)indent_532655_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_538656_839829468, 0); } N_NIMCALL(void, T839829468_6)(void) { nimGCvisit((void*)nimtvdeps_538674_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_538675_839829468.head, 0); nimGCvisit((void*)nimtvdeclared_538675_839829468.data, 0); } N_NIMCALL(void, T839829468_8)(void) { nimGCvisit((void*)gbreakpoints_548861_839829468, 0); } N_NIMCALL(Tcgen529027*, getcgenmodule_532226_839829468)(Tsym292834* s0) { Tcgen529027* result0; result0 = (Tcgen529027*)0; { NIM_BOOL LOC3; LOC3 = (NIM_BOOL)0; LOC3 = (((NI) 0) <= (*s0).position); if (!(LOC3)) goto LA4; LOC3 = ((*s0).position < (gmodules_529170_3723162438 ? gmodules_529170_3723162438->Sup.len : 0)); LA4: ; if (!LOC3) goto LA5; result0 = gmodules_529170_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_532977_839829468)(Tsym292834* s0) { NU32 result0; Tsym292834* m0; Tsym292834* p0; result0 = (NU32)0; m0 = s0; { while (1) { if (!!(((*m0).kind == ((Tsymkind292435) 6)))) goto LA2; m0 = (*m0).owner; } LA2: ; } p0 = (*m0).owner; result0 = register_203121_1926258066((&gdebuginfo_203470_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(Toption169009Set, initprocoptions_562635_839829468)(Tcgen529027* m0) { Toption169009Set result0; memset((void*)(&result0), 0, sizeof(result0)); { if (!(((*(*m0).module).flags &(1U<<((NU)(((Tsymflag292184) 13))&31U)))!=0)) goto LA3; result0 = (goptions_169128_2607990831 & ~ 32768); } goto LA1; LA3: ; { result0 = goptions_169128_2607990831; } LA1: ; return result0; } N_NIMCALL(Tcproc529021*, newpreinitproc_562625_839829468)(Tcgen529027* m0) { Tcproc529021* result0; result0 = (Tcproc529021*)0; result0 = newproc_529206_3723162438(NIM_NIL, m0); (*result0).labels = ((NI) 100000); return result0; } N_NIMCALL(Tcproc529021*, newpostinitproc_562630_839829468)(Tcgen529027* m0) { Tcproc529021* result0; result0 = (Tcproc529021*)0; result0 = newproc_529206_3723162438(NIM_NIL, m0); (*result0).labels = ((NI) 200000); return result0; } N_NIMCALL(Ropeobj178006*, gettempname_533596_839829468)(Tcgen529027* m0) { Ropeobj178006* result0; Ropeobj178006* LOC1; result0 = (Ropeobj178006*)0; LOC1 = (Ropeobj178006*)0; LOC1 = rope_178401_2381377266(((NI64) ((*m0).labels))); result0 = HEX26_178418_2381377266((*m0).tmpbase, LOC1); (*m0).labels += ((NI) 1); return result0; } N_NIMCALL(Tcgen529027*, rawnewmodule_562663_839829468)(Tsym292834* module0, NimStringDesc* filename0) { Tcgen529027* result0; NimStringDesc* LOC1; NU32 LOC2; NimStringDesc* LOC3; NimStringDesc* LOC4; NimStringDesc* LOC5; result0 = (Tcgen529027*)0; result0 = (Tcgen529027*) newObj((&NTI529015), sizeof(Tcgen529027)); (*result0).Sup.Sup.m_type = (&NTI529027); LOC1 = (NimStringDesc*)0; LOC2 = (NU32)0; LOC2 = hashowner_532977_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_178277_2381377266(LOC1)); initlinkedlist_147031_3771138726((&(*result0).headerfiles)); initintset_268885_2627731572((&(*result0).declaredthings)); initintset_268885_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_296019_850551059((&(*result0).typecache)); initidtable_296019_850551059((&(*result0).forwtypecache)); asgnRefNoCycle((void**) (&(*result0).module), module0); initintset_268885_2627731572((&(*result0).typeinfomarker)); asgnRef((void**) (&(*result0).initproc), newproc_529206_3723162438(NIM_NIL, result0)); (*(*result0).initproc).options = initprocoptions_562635_839829468(result0); asgnRef((void**) (&(*result0).preinitproc), newpreinitproc_562625_839829468(result0)); asgnRef((void**) (&(*result0).postinitproc), newpostinitproc_562630_839829468(result0)); initnodetable_296085_850551059((&(*result0).datacache)); if ((*result0).typestack) nimGCunrefNoCycle((*result0).typestack); (*result0).typestack = (Ttypeseq292836*) newSeqRC1((&NTI292836), 0); if ((*result0).forwardedprocs) nimGCunrefNoCycle((*result0).forwardedprocs); (*result0).forwardedprocs = (Tsymseq292804*) newSeqRC1((&NTI292804), 0); asgnRefNoCycle((void**) (&(*result0).typenodesname), gettempname_533596_839829468(result0)); asgnRefNoCycle((void**) (&(*result0).nimtypesname), gettempname_533596_839829468(result0)); { if (!(((*module0).flags &(1U<<((NU)(((Tsymflag292184) 13))&31U)))!=0)) goto LA8; (*result0).flags |= ((NU8)1)<<((((Codegenflag529025) 0))%(sizeof(NU8)*8)); (*(*result0).preinitproc).options &= ~(((NU32)1) << ((((Toption169009) 15)) % (sizeof(NU32)*8))); (*(*result0).postinitproc).options &= ~(((NU32)1) << ((((Toption169009) 15)) % (sizeof(NU32)*8))); } LA8: ; return result0; } N_NIMCALL(Tcgen529027*, rawnewmodule_563038_839829468)(Tsym292834* module0) { Tcgen529027* result0; NimStringDesc* LOC1; result0 = (Tcgen529027*)0; LOC1 = (NimStringDesc*)0; LOC1 = tofullpath_192264_155036129(((NI32) ((*module0).position))); result0 = rawnewmodule_562663_839829468(module0, LOC1); return result0; } N_NIMCALL(Tcgen529027*, newmodule_563045_839829468)(Tsym292834* module0) { Tcgen529027* result0; result0 = (Tcgen529027*)0; { Tcgen529027* LOC3; NimStringDesc* LOC6; LOC3 = (Tcgen529027*)0; LOC3 = getcgenmodule_532226_839829468(module0); if (!!((LOC3 == NIM_NIL))) goto LA4; LOC6 = (NimStringDesc*)0; LOC6 = HEX24_196185_1689653243(T839829468_9); internalerror_196113_155036129(LOC6); } LA4: ; result0 = rawnewmodule_563038_839829468(module0); { if (!((gmodules_529170_3723162438 ? gmodules_529170_3723162438->Sup.len : 0) <= (*module0).position)) goto LA9; gmodules_529170_3723162438 = (TY529153*) setLengthSeq(&(gmodules_529170_3723162438)->Sup, sizeof(Tcgen529027*), ((NI) ((NI)((*module0).position + ((NI) 1))))); } LA9: ; asgnRef((void**) (&gmodules_529170_3723162438->data[(*module0).position]), result0); { if (!((gglobaloptions_169130_2607990831 &((NU64)1<<((NU)(((Tglobaloption169013) 2))&63U)))!=0)) goto LA13; { NimStringDesc* LOC19; NimStringDesc* LOC20; if (!(((*module0).flags &(1U<<((NU)(((Tsymflag292184) 25))&31U)))!=0)) goto LA17; LOC19 = (NimStringDesc*)0; LOC20 = (NimStringDesc*)0; LOC20 = tofilename_192260_155036129(((NI32) ((*module0).position))); LOC19 = rawNewString(LOC20->Sup.len + 28); appendString(LOC19, ((NimStringDesc*) &T839829468_13)); appendString(LOC19, LOC20); internalerror_196113_155036129(LOC19); } LA17: ; } LA13: ; return result0; } N_NIMCALL(Tpasscontext341002*, myopen_563115_839829468)(Tsym292834* module0) { Tpasscontext341002* result0; Tcgen529027* LOC1; result0 = (Tpasscontext341002*)0; LOC1 = (Tcgen529027*)0; LOC1 = newmodule_563045_839829468(module0); result0 = &LOC1->Sup; { NIM_BOOL LOC4; NimStringDesc* f0; NimStringDesc* LOC13; NimStringDesc* LOC14; LOC4 = (NIM_BOOL)0; LOC4 = ((gglobaloptions_169130_2607990831 &((NU64)1<<((NU)(((Tglobaloption169013) 27))&63U)))!=0); if (!(LOC4)) goto LA5; LOC4 = (generatedheader_532201_839829468 == NIM_NIL); LA5: ; if (!LOC4) goto LA6; { if (!(((NI) 0) < (headerfile_169138_2607990831 ? headerfile_169138_2607990831->Sup.len : 0))) goto LA10; f0 = headerfile_169138_2607990831; } goto LA8; LA10: ; { f0 = gprojectfull_169211_2607990831; } LA8: ; LOC13 = (NimStringDesc*)0; LOC13 = completecfilepath_273854_2528170400(f0, NIM_TRUE); LOC14 = (NimStringDesc*)0; LOC14 = noschangeFileExt(LOC13, ((NimStringDesc*) &T839829468_14)); asgnRef((void**) (&generatedheader_532201_839829468), rawnewmodule_562663_839829468(module0, LOC14)); (*generatedheader_532201_839829468).flags |= ((NU8)1)<<((((Codegenflag529025) 3))%(sizeof(NU8)*8)); } LA6: ; return result0; } N_NIMCALL(NimStringDesc*, getcfile_563204_839829468)(Tcgen529027* m0) { NimStringDesc* result0; NimStringDesc* ext0; NimStringDesc* LOC13; NimStringDesc* LOC14; result0 = (NimStringDesc*)0; { NIM_BOOL LOC3; LOC3 = (NIM_BOOL)0; LOC3 = (gcmd_169132_2607990831 == ((Tcommands169076) 2)); if (LOC3) goto LA4; LOC3 = (((*(*m0).module).flags &(1U<<((NU)(((Tsymflag292184) 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_169132_2607990831 == ((Tcommands169076) 3)); if (LOC8) goto LA9; LOC8 = (((*(*m0).module).flags &(1U<<((NU)(((Tsymflag292184) 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_170073_2607990831((*m0).cfilename); LOC14 = (NimStringDesc*)0; LOC14 = completecfilepath_273854_2528170400(LOC13, NIM_TRUE); result0 = noschangeFileExt(LOC14, ext0); return result0; } N_NIMCALL(Tpasscontext341002*, myopencached_563249_839829468)(Tsym292834* module0, Trodreader332021* rd0) { Tpasscontext341002* result0; Tcgen529027* m0; NimStringDesc* LOC1; result0 = (Tpasscontext341002*)0; m0 = newmodule_563045_839829468(module0); LOC1 = (NimStringDesc*)0; LOC1 = getcfile_563204_839829468(m0); readmergeinfo_530613_2760143328(LOC1, m0); result0 = &m0->Sup; return result0; } static N_INLINE(NIM_BOOL, skipcodegen_341085_2355241294)(Tnode292802* n0) { NIM_BOOL result0; result0 = (NIM_BOOL)0; result0 = (((NI) 0) < gerrorcounter_192072_155036129); return result0; } N_NIMCALL(void, fillloc_532282_839829468)(Tloc292816* a0, Tlockind292808 k0, Ttype292840* typ0, Ropeobj178006* r0, Tstorageloc292812 s0) { { if (!((*a0).k == ((Tlockind292808) 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_532960_839829468)(Tident199010* 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(Ropeobj178006*, manglename_533205_839829468)(Tsym292834* s0) { Ropeobj178006* result0; result0 = (Ropeobj178006*)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_532960_839829468((*s0).name); LOC5 = !(LOC9); LA8: ; keeporigname0 = LOC5; LOC10 = (NimStringDesc*)0; LOC10 = mangle_528847_2036603609((*(*s0).name).s); result0 = rope_178277_2381377266(LOC10); { if (!keeporigname0) goto LA13; add_178487_2381377266(&result0, ((NimStringDesc*) &T839829468_18)); } goto LA11; LA13: ; { TY533289 LOC16; Ropeobj178006* LOC17; Ropeobj178006* LOC18; TY533289 LOC19; Ropeobj178006* LOC20; NU32 LOC21; Ropeobj178006* LOC22; memset((void*)LOC16, 0, sizeof(LOC16)); LOC17 = (Ropeobj178006*)0; LOC17 = HEX25_178905_2381377266(((NimStringDesc*) &T839829468_12), LOC16, 0); add_178482_2381377266(&result0, LOC17); LOC18 = (Ropeobj178006*)0; LOC18 = rope_178401_2381377266(((NI64) ((*s0).Sup.id))); add_178482_2381377266(&result0, LOC18); memset((void*)LOC19, 0, sizeof(LOC19)); LOC20 = (Ropeobj178006*)0; LOC20 = HEX25_178905_2381377266(((NimStringDesc*) &T839829468_12), LOC19, 0); add_178482_2381377266(&result0, LOC20); LOC21 = (NU32)0; LOC21 = hashowner_532977_839829468(s0); LOC22 = (Ropeobj178006*)0; LOC22 = rope_178401_2381377266(((NI64) (LOC21))); add_178482_2381377266(&result0, LOC22); } LA11: ; asgnRefNoCycle((void**) (&(*s0).loc.r), result0); } LA3: ; return result0; } N_NIMCALL(void, fillprocloc_539201_839829468)(Tsym292834* sym0) { { Ropeobj178006* LOC5; if (!((*sym0).loc.k == ((Tlockind292808) 0))) goto LA3; LOC5 = (Ropeobj178006*)0; LOC5 = manglename_533205_839829468(sym0); fillloc_532282_839829468((&(*sym0).loc), ((Tlockind292808) 7), (*sym0).typ, LOC5, ((Tstorageloc292812) 2)); } LA3: ; } N_NIMCALL(void, useheader_532369_839829468)(Tcgen529027* m0, Tsym292834* sym0) { { NimStringDesc* LOC5; NIM_BOOL LOC6; if (!(((*sym0).loc.flags &(1U<<((NU)(((Tlocflag292810) 6))&15U)))!=0)) goto LA3; LOC5 = (NimStringDesc*)0; LOC5 = getstr_297230_850551059((*(*sym0).annex).path); LOC6 = (NIM_BOOL)0; LOC6 = includestr_147249_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_561431_839829468)(Tsym292834* prc0) { NIM_BOOL result0; result0 = (NIM_BOOL)0; result0 = !(((*prc0).typ == NIM_NIL)); return result0; } N_NIMCALL(void, addforwardedproc_532203_839829468)(Tcgen529027* m0, Tsym292834* prc0) { (*m0).forwardedprocs = (Tsymseq292804*) incrSeqV2(&((*m0).forwardedprocs)->Sup, sizeof(Tsym292834*)); asgnRefNoCycle((void**) (&(*m0).forwardedprocs->data[(*m0).forwardedprocs->Sup.len]), prc0); ++(*m0).forwardedprocs->Sup.len; gforwardedprocscounter_529171_3723162438 += ((NI) 1); } N_NIMCALL(void, genclinedir_532725_839829468)(Ropeobj178006** r0, NimStringDesc* filename0, NI line0) { { TY532811 LOC5; NimStringDesc* LOC6; if (!((goptions_169128_2607990831 &(1U<<((NU)(((Toption169009) 10))&31U)))!=0)) goto LA3; memset((void*)LOC5, 0, sizeof(LOC5)); LOC6 = (NimStringDesc*)0; LOC6 = makesinglelinecstring_528835_2036603609(filename0); LOC5[0] = rope_178277_2381377266(LOC6); LOC5[1] = rope_178401_2381377266(((NI64) (line0))); addf_179205_2381377266(r0, ((NimStringDesc*) &T839829468_21), LOC5, 2); } LA3: ; } static N_INLINE(NI, tolinenumber_192415_155036129)(Tlineinfo191336 info0) { NI result0; result0 = (NI)0; result0 = ((NI) (info0.line)); return result0; } N_NIMCALL(NI, safelinenm_532721_839829468)(Tlineinfo191336 info0) { NI result0; result0 = (NI)0; result0 = tolinenumber_192415_155036129(info0); { if (!(result0 < ((NI) 0))) goto LA3; result0 = ((NI) 0); } LA3: ; return result0; } N_NIMCALL(void, genclinedir_532813_839829468)(Ropeobj178006** r0, Tlineinfo191336 info0) { NimStringDesc* LOC1; NI LOC2; LOC1 = (NimStringDesc*)0; LOC1 = tofullpath_192264_155036129(info0.fileindex); LOC2 = (NI)0; LOC2 = safelinenm_532721_839829468(info0); genclinedir_532725_839829468(r0, LOC1, LOC2); } N_NIMCALL(Tctypekind529007, mapsettype_533389_839829468)(Ttype292840* typ0) { Tctypekind529007 result0; NI64 LOC1; result0 = (Tctypekind529007)0; LOC1 = (NI64)0; LOC1 = getsize_320135_3876443242(typ0); switch (((NI) (LOC1))) { case ((NI) 1): { result0 = ((Tctypekind529007) 4); } break; case ((NI) 2): { result0 = ((Tctypekind529007) 5); } break; case ((NI) 4): { result0 = ((Tctypekind529007) 6); } break; case ((NI) 8): { result0 = ((Tctypekind529007) 7); } break; default: { result0 = ((Tctypekind529007) 17); } break; } return result0; } N_NIMCALL(Tctypekind529007, maptype_533393_839829468)(Ttype292840* typ0) { Tctypekind529007 result0; result0 = (Tctypekind529007)0; switch ((*typ0).kind) { case ((Ttypekind292244) 0): case ((Ttypekind292244) 7): { result0 = ((Tctypekind529007) 0); } break; case ((Ttypekind292244) 1): { result0 = ((Tctypekind529007) 2); } break; case ((Ttypekind292244) 2): { result0 = ((Tctypekind529007) 1); } break; case ((Ttypekind292244) 19): { result0 = mapsettype_533389_839829468(typ0); } break; case ((Ttypekind292244) 27): case ((Ttypekind292244) 4): case ((Ttypekind292244) 16): case ((Ttypekind292244) 48): { result0 = ((Tctypekind529007) 17); } break; case ((Ttypekind292244) 17): case ((Ttypekind292244) 18): { result0 = ((Tctypekind529007) 19); } break; case ((Ttypekind292244) 10): case ((Ttypekind292244) 11): case ((Ttypekind292244) 12): case ((Ttypekind292244) 13): case ((Ttypekind292244) 15): case ((Ttypekind292244) 46): case ((Ttypekind292244) 47): case ((Ttypekind292244) 49): case ((Ttypekind292244) 8): { Ttype292840* LOC8; LOC8 = (Ttype292840*)0; LOC8 = lastson_295377_850551059(typ0); result0 = maptype_533393_839829468(LOC8); } break; case ((Ttypekind292244) 14): { { NI64 LOC12; LOC12 = (NI64)0; LOC12 = firstord_320001_3876443242(typ0); if (!(LOC12 < IL64(0))) goto LA13; result0 = ((Tctypekind529007) 6); } goto LA10; LA13: ; { NI64 LOC16; LOC16 = (NI64)0; LOC16 = getsize_320135_3876443242(typ0); switch (((NI) (LOC16))) { case ((NI) 1): { result0 = ((Tctypekind529007) 13); } break; case ((NI) 2): { result0 = ((Tctypekind529007) 14); } break; case ((NI) 4): { result0 = ((Tctypekind529007) 6); } break; case ((NI) 8): { result0 = ((Tctypekind529007) 7); } break; default: { internalerror_196113_155036129(((NimStringDesc*) &T839829468_25)); } break; } } LA10: ; } break; case ((Ttypekind292244) 20): { result0 = maptype_533393_839829468((*typ0).sons->data[((NI) 0)]); } break; case ((Ttypekind292244) 21): case ((Ttypekind292244) 23): case ((Ttypekind292244) 22): { Ttype292840* base0; Ttype292840* LOC24; LOC24 = (Ttype292840*)0; LOC24 = lastson_295377_850551059(typ0); base0 = skiptypes_296099_850551059(LOC24, IL64(211106232576256)); switch ((*base0).kind) { case ((Ttypekind292244) 27): case ((Ttypekind292244) 4): case ((Ttypekind292244) 16): case ((Ttypekind292244) 48): { result0 = ((Tctypekind529007) 18); } break; default: { result0 = ((Tctypekind529007) 20); } break; } } break; case ((Ttypekind292244) 26): { result0 = ((Tctypekind529007) 20); } break; case ((Ttypekind292244) 24): { result0 = ((Tctypekind529007) 22); } break; case ((Ttypekind292244) 25): { { if (!!(((*typ0).callconv == ((Tcallingconvention292002) 8)))) goto LA32; result0 = ((Tctypekind529007) 23); } goto LA30; LA32: ; { result0 = ((Tctypekind529007) 19); } LA30: ; } break; case ((Ttypekind292244) 28): { result0 = ((Tctypekind529007) 21); } break; case ((Ttypekind292244) 29): { result0 = ((Tctypekind529007) 24); } break; case ((Ttypekind292244) 31) ... ((Ttypekind292244) 44): { result0 = ((Tctypekind529007) ((NI)(((NI) ((NI)(((NI) ((*typ0).kind)) - ((NI) 31)))) + ((NI) 3)))); } break; case ((Ttypekind292244) 59): { { Ttype292840* LOC43; if (!!(((*typ0).n == NIM_NIL))) goto LA41; LOC43 = (Ttype292840*)0; LOC43 = lastson_295377_850551059(typ0); result0 = maptype_533393_839829468(LOC43); } goto LA39; LA41: ; { internalerror_196113_155036129(((NimStringDesc*) &T839829468_25)); } LA39: ; } break; default: { internalerror_196113_155036129(((NimStringDesc*) &T839829468_25)); } break; } return result0; } N_NIMCALL(NIM_BOOL, isimportedcpptype_533476_839829468)(Ttype292840* 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)(((Tsymflag292184) 27))&31U)))!=0); LA2: ; result0 = LOC1; return result0; } N_NIMCALL(NIM_BOOL, needscomplexassignment_533509_839829468)(Ttype292840* typ0) { NIM_BOOL result0; result0 = (NIM_BOOL)0; result0 = containsgarbagecollectedref_320117_3876443242(typ0); return result0; } static N_INLINE(NIM_BOOL, isobjlackingtypefield_533513_839829468)(Ttype292840* typ0) { NIM_BOOL result0; NIM_BOOL LOC1; NIM_BOOL LOC3; NIM_BOOL LOC4; result0 = (NIM_BOOL)0; LOC1 = (NIM_BOOL)0; LOC1 = ((*typ0).kind == ((Ttypekind292244) 17)); if (!(LOC1)) goto LA2; LOC3 = (NIM_BOOL)0; LOC4 = (NIM_BOOL)0; LOC4 = (((*typ0).flags &(1U<<((NU)(((Ttypeflag292431) 2))&31U)))!=0); if (!(LOC4)) goto LA5; LOC4 = ((*typ0).sons->data[((NI) 0)] == NIM_NIL); LA5: ; LOC3 = LOC4; if (LOC3) goto LA6; LOC3 = ispureobject_320138_3876443242(typ0); LA6: ; LOC1 = LOC3; LA2: ; result0 = LOC1; return result0; } N_NIMCALL(NIM_BOOL, isinvalidreturntype_533548_839829468)(Ttype292840* rettype0) { NIM_BOOL result0; { result0 = (NIM_BOOL)0; { if (!(rettype0 == NIM_NIL)) goto LA3; result0 = NIM_TRUE; } goto LA1; LA3: ; { Tctypekind529007 LOC6; LOC6 = (Tctypekind529007)0; LOC6 = maptype_533393_839829468(rettype0); switch (LOC6) { case ((Tctypekind529007) 17): { Ttype292840* LOC8; LOC8 = (Ttype292840*)0; LOC8 = skiptypes_296099_850551059(rettype0, IL64(211106232576256)); result0 = !(((*LOC8).kind == ((Ttypekind292244) 23) || (*LOC8).kind == ((Ttypekind292244) 22) || (*LOC8).kind == ((Ttypekind292244) 21))); } break; case ((Tctypekind529007) 19): { Ttype292840* t0; NIM_BOOL LOC16; NIM_BOOL LOC18; NIM_BOOL LOC20; t0 = skiptypes_296099_850551059(rettype0, IL64(211106232576256)); { NIM_BOOL LOC12; LOC12 = (NIM_BOOL)0; LOC12 = isimportedcpptype_533476_839829468(rettype0); if (LOC12) goto LA13; LOC12 = isimportedcpptype_533476_839829468(t0); LA13: ; if (!LOC12) goto LA14; result0 = NIM_FALSE; goto BeforeRet; } LA14: ; LOC16 = (NIM_BOOL)0; LOC16 = needscomplexassignment_533509_839829468(t0); if (LOC16) goto LA17; LOC18 = (NIM_BOOL)0; LOC18 = ((*t0).kind == ((Ttypekind292244) 17)); if (!(LOC18)) goto LA19; LOC20 = (NIM_BOOL)0; LOC20 = isobjlackingtypefield_533513_839829468(t0); LOC18 = !(LOC20); LA19: ; LOC16 = LOC18; LA17: ; result0 = LOC16; } break; default: { result0 = NIM_FALSE; } break; } } LA1: ; }BeforeRet: ; return result0; } N_NIMCALL(Ropeobj178006*, typename_533292_839829468)(Ttype292840* typ0) { Ropeobj178006* result0; result0 = (Ropeobj178006*)0; { NimStringDesc* LOC5; if (!!(((*typ0).sym == NIM_NIL))) goto LA3; LOC5 = (NimStringDesc*)0; LOC5 = mangle_528847_2036603609((*(*(*typ0).sym).name).s); result0 = rope_178277_2381377266(LOC5); } goto LA1; LA3: ; { TY533289 LOC7; memset((void*)LOC7, 0, sizeof(LOC7)); result0 = HEX25_178905_2381377266(((NimStringDesc*) &T839829468_28), LOC7, 0); } LA1: ; return result0; } N_NIMCALL(Ropeobj178006*, gettypename_533313_839829468)(Ttype292840* typ0) { Ropeobj178006* result0; result0 = (Ropeobj178006*)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: ; { { Ropeobj178006* LOC12; Ropeobj178006* LOC13; if (!((*typ0).loc.r == NIM_NIL)) goto LA10; LOC12 = (Ropeobj178006*)0; LOC12 = typename_533292_839829468(typ0); LOC13 = (Ropeobj178006*)0; LOC13 = rope_178401_2381377266(((NI64) ((*typ0).Sup.id))); asgnRefNoCycle((void**) (&(*typ0).loc.r), HEX26_178418_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, (&NTI292244))->Sup.len + 13); appendString(LOC18, ((NimStringDesc*) &T839829468_29)); appendString(LOC18, reprEnum((NI)(*typ0).kind, (&NTI292244))); internalerror_196113_155036129(LOC18); } LA16: ; return result0; } N_NIMCALL(Ropeobj178006*, typenameorliteral_533898_839829468)(Ttype292840* t0, NimStringDesc* literal0) { Ropeobj178006* result0; result0 = (Ropeobj178006*)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)(((Tsymflag292184) 5))&31U)))!=0); LA5: ; LOC3 = LOC4; if (!(LOC3)) goto LA6; LOC3 = ((*(*t0).sym).magic == ((Tmagic292524) 0)); LA6: ; if (!LOC3) goto LA7; result0 = gettypename_533313_839829468(t0); } goto LA1; LA7: ; { result0 = rope_178277_2381377266(literal0); } LA1: ; return result0; } N_NIMCALL(Ropeobj178006*, getsimpletypedesc_533936_839829468)(Tcgen529027* m0, Ttype292840* typ0) { Ropeobj178006* result0; result0 = (Ropeobj178006*)0; switch ((*typ0).kind) { case ((Ttypekind292244) 26): { result0 = typenameorliteral_533898_839829468(typ0, ((NimStringDesc*) &T839829468_30)); } break; case ((Ttypekind292244) 28): { Ropeobj178006* LOC3; LOC3 = (Ropeobj178006*)0; LOC3 = cgsym_532403_839829468(m0, ((NimStringDesc*) &T839829468_31)); result0 = typenameorliteral_533898_839829468(typ0, ((NimStringDesc*) &T839829468_32)); } break; case ((Ttypekind292244) 29): { result0 = typenameorliteral_533898_839829468(typ0, ((NimStringDesc*) &T839829468_33)); } break; case ((Ttypekind292244) 1): { result0 = typenameorliteral_533898_839829468(typ0, ((NimStringDesc*) &T839829468_34)); } break; case ((Ttypekind292244) 2): { result0 = typenameorliteral_533898_839829468(typ0, ((NimStringDesc*) &T839829468_35)); } break; case ((Ttypekind292244) 5): { result0 = typenameorliteral_533898_839829468(typ0, ((NimStringDesc*) &T839829468_18)); } break; case ((Ttypekind292244) 31) ... ((Ttypekind292244) 44): { result0 = typenameorliteral_533898_839829468(typ0, Numericaltypetostr_533941_839829468[((*typ0).kind)- 31]); } break; case ((Ttypekind292244) 13): case ((Ttypekind292244) 20): case ((Ttypekind292244) 15): { result0 = getsimpletypedesc_533936_839829468(m0, (*typ0).sons->data[((NI) 0)]); } break; case ((Ttypekind292244) 59): { { Ttype292840* LOC15; if (!!(((*typ0).n == NIM_NIL))) goto LA13; LOC15 = (Ttype292840*)0; LOC15 = lastson_295377_850551059(typ0); result0 = getsimpletypedesc_533936_839829468(m0, LOC15); } goto LA11; LA13: ; { internalerror_196113_155036129(((NimStringDesc*) &T839829468_50)); } LA11: ; } break; case ((Ttypekind292244) 11): { Ttype292840* LOC18; LOC18 = (Ttype292840*)0; LOC18 = lastson_295377_850551059(typ0); result0 = getsimpletypedesc_533936_839829468(m0, LOC18); } break; default: { result0 = NIM_NIL; } break; } return result0; } N_NIMCALL(Ropeobj178006*, cachegettype_533591_839829468)(Tidtable292850 tab0, Ttype292840* key0) { Ropeobj178006* result0; Tidobj199004* LOC1; TNimObject* LOC2; result0 = (Ropeobj178006*)0; LOC1 = (Tidobj199004*)0; LOC1 = &key0->Sup; LOC2 = (TNimObject*)0; LOC2 = idtableget_299086_2984716966(tab0, LOC1); result0 = ((Ropeobj178006*) (LOC2)); return result0; } N_NIMCALL(Ropeobj178006*, gettypepre_533972_839829468)(Tcgen529027* m0, Ttype292840* typ0) { Ropeobj178006* result0; result0 = (Ropeobj178006*)0; { if (!(typ0 == NIM_NIL)) goto LA3; result0 = rope_178277_2381377266(((NimStringDesc*) &T839829468_26)); } goto LA1; LA3: ; { result0 = getsimpletypedesc_533936_839829468(m0, typ0); { if (!(result0 == NIM_NIL)) goto LA8; result0 = cachegettype_533591_839829468((*m0).typecache, typ0); } LA8: ; } LA1: ; return result0; } N_NIMCALL(NIM_BOOL, isimportedtype_533449_839829468)(Ttype292840* 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)(((Tsymflag292184) 5))&31U)))!=0); LA2: ; result0 = LOC1; return result0; } N_NIMCALL(NimStringDesc*, getforwardstructformat_534015_839829468)(Tcgen529027* m0) { NimStringDesc* result0; result0 = (NimStringDesc*)0; { NIM_BOOL LOC3; LOC3 = (NIM_BOOL)0; LOC3 = (gcmd_169132_2607990831 == ((Tcommands169076) 2)); if (LOC3) goto LA4; LOC3 = (((*(*m0).module).flags &(1U<<((NU)(((Tsymflag292184) 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(Ropeobj178006*, structorunion_534001_839829468)(Ttype292840* t0) { Ropeobj178006* result0; result0 = (Ropeobj178006*)0; { if (!(((*t0).flags &(1U<<((NU)(((Ttypeflag292431) 1))&31U)))!=0)) goto LA3; result0 = rope_178277_2381377266(((NimStringDesc*) &T839829468_56)); } goto LA1; LA3: ; { result0 = rope_178277_2381377266(((NimStringDesc*) &T839829468_57)); } LA1: ; return result0; } N_NIMCALL(Ropeobj178006*, gettypeforward_534039_839829468)(Tcgen529027* m0, Ttype292840* typ0) { Ropeobj178006* result0; { result0 = (Ropeobj178006*)0; result0 = cachegettype_533591_839829468((*m0).forwtypecache, typ0); { if (!!((result0 == NIM_NIL))) goto LA3; goto BeforeRet; } LA3: ; result0 = gettypepre_533972_839829468(m0, typ0); { if (!!((result0 == NIM_NIL))) goto LA7; goto BeforeRet; } LA7: ; switch ((*typ0).kind) { case ((Ttypekind292244) 24): case ((Ttypekind292244) 18): case ((Ttypekind292244) 17): { Tidobj199004* LOC17; TNimObject* LOC18; result0 = gettypename_533313_839829468(typ0); { NIM_BOOL LOC12; NimStringDesc* LOC15; TY532811 LOC16; LOC12 = (NIM_BOOL)0; LOC12 = isimportedtype_533449_839829468(typ0); if (!!(LOC12)) goto LA13; LOC15 = (NimStringDesc*)0; LOC15 = getforwardstructformat_534015_839829468(m0); memset((void*)LOC16, 0, sizeof(LOC16)); LOC16[0] = structorunion_534001_839829468(typ0); LOC16[1] = result0; addf_179205_2381377266(&(*m0).s[(((Tcfilesection529005) 2))- 0], LOC15, LOC16, 2); } LA13: ; LOC17 = (Tidobj199004*)0; LOC17 = &typ0->Sup; LOC18 = (TNimObject*)0; LOC18 = &result0->Sup; idtableput_299094_2984716966((&(*m0).forwtypecache), LOC17, LOC18); } break; default: { NimStringDesc* LOC20; LOC20 = (NimStringDesc*)0; LOC20 = rawNewString(reprEnum((NI)(*typ0).kind, (&NTI292244))->Sup.len + 16); appendString(LOC20, ((NimStringDesc*) &T839829468_58)); appendString(LOC20, reprEnum((NI)(*typ0).kind, (&NTI292244))); appendChar(LOC20, 41); internalerror_196113_155036129(LOC20); } break; } }BeforeRet: ; return result0; } N_NIMCALL(void, pushtype_533958_839829468)(Tcgen529027* m0, Ttype292840* typ0) { (*m0).typestack = (Ttypeseq292836*) incrSeqV2(&((*m0).typestack)->Sup, sizeof(Ttype292840*)); asgnRefNoCycle((void**) (&(*m0).typestack->data[(*m0).typestack->Sup.len]), typ0); ++(*m0).typestack->Sup.len; } N_NIMCALL(Ropeobj178006*, gettypedescweak_534079_839829468)(Tcgen529027* m0, Ttype292840* t0, Intset268030* check0) { Ropeobj178006* result0; Ttype292840* etb0; result0 = (Ropeobj178006*)0; etb0 = skiptypes_296099_850551059(t0, IL64(211106232576256)); switch ((*etb0).kind) { case ((Ttypekind292244) 17): case ((Ttypekind292244) 18): { { NIM_BOOL LOC4; LOC4 = (NIM_BOOL)0; LOC4 = isimportedcpptype_533476_839829468(etb0); if (!(LOC4)) goto LA5; LOC4 = ((*t0).kind == ((Ttypekind292244) 11)); LA5: ; if (!LOC4) goto LA6; result0 = gettypedescaux_533503_839829468(m0, t0, check0); } goto LA2; LA6: ; { Ttype292840* x0; x0 = getuniquetype_528640_2036603609(etb0); result0 = gettypeforward_534039_839829468(m0, x0); pushtype_533958_839829468(m0, x0); } LA2: ; } break; case ((Ttypekind292244) 24): { Ttype292840* x0; Ropeobj178006* LOC10; x0 = getuniquetype_528640_2036603609(etb0); LOC10 = (Ropeobj178006*)0; LOC10 = gettypeforward_534039_839829468(m0, x0); result0 = HEX26_178447_2381377266(LOC10, ((NimStringDesc*) &T839829468_53)); pushtype_533958_839829468(m0, x0); } break; default: { result0 = gettypedescaux_533503_839829468(m0, t0, check0); } break; } return result0; } static N_INLINE(NI, len_293081_850551059)(Tnode292802* 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_532632_839829468)(Tcgen529027* m0, Ropeobj178006** c0, NimStringDesc* frmt0, Ropeobj178006** args0, NI args0Len0) { Ropeobj178006* LOC1; LOC1 = (Ropeobj178006*)0; LOC1 = ropecg_532407_839829468(m0, frmt0, args0, args0Len0); add_178482_2381377266(c0, LOC1); } N_NIMCALL(NIM_BOOL, scancppgenericslot_534827_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(Ttype292840*, resolvestarsincpptype_534891_839829468)(Ttype292840* typ0, NI idx0, NI stars0) { Ttype292840* result0; result0 = (Ttype292840*)0; { NI LOC3; LOC3 = (NI)0; LOC3 = len_295339_850551059(typ0); if (!(LOC3 <= idx0)) goto LA4; internalerror_196113_155036129(((NimStringDesc*) &T839829468_81)); } LA4: ; result0 = (*typ0).sons->data[idx0]; { NI i_534906_839829468; NI res_534931_839829468; i_534906_839829468 = (NI)0; res_534931_839829468 = ((NI) 1); { while (1) { if (!(res_534931_839829468 <= stars0)) goto LA8; i_534906_839829468 = res_534931_839829468; { NIM_BOOL LOC11; NI LOC13; LOC11 = (NIM_BOOL)0; LOC11 = !((result0 == NIM_NIL)); if (!(LOC11)) goto LA12; LOC13 = (NI)0; LOC13 = len_295339_850551059(result0); LOC11 = (((NI) 0) < LOC13); LA12: ; if (!LOC11) goto LA14; { if (!((*result0).kind == ((Ttypekind292244) 11))) goto LA18; result0 = (*result0).sons->data[((NI) 1)]; } goto LA16; LA18: ; { result0 = elemtype_320394_3876443242(result0); } LA16: ; } LA14: ; res_534931_839829468 += ((NI) 1); } LA8: ; } } return result0; } N_NIMCALL(NimStringDesc*, manglefield_532973_839829468)(Tident199010* name0) { NimStringDesc* result0; result0 = (NimStringDesc*)0; result0 = mangle_528847_2036603609((*name0).s); { NIM_BOOL LOC3; LOC3 = (NIM_BOOL)0; LOC3 = iskeyword_532960_839829468(name0); if (!LOC3) goto LA4; result0->data[((NI) 0)] = nsuToUpperAsciiChar(result0->data[((NI) 0)]); } LA4: ; return result0; } N_NIMCALL(Ropeobj178006*, manglerecfieldname_534361_839829468)(Tsym292834* field0, Ttype292840* rectype0) { Ropeobj178006* result0; result0 = (Ropeobj178006*)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_532973_839829468((*field0).name); result0 = rope_178277_2381377266(LOC8); } LA1: ; { if (!(result0 == NIM_NIL)) goto LA11; internalerror_196100_155036129((*field0).info, ((NimStringDesc*) &T839829468_96)); } LA11: ; return result0; } N_NIMCALL(Ropeobj178006*, genrecordfieldsaux_534421_839829468)(Tcgen529027* m0, Tnode292802* n0, Ropeobj178006* accessexpr0, Ttype292840* rectype0, Intset268030* check0) { Ropeobj178006* result0; Ropeobj178006* ae0; Ropeobj178006* uname0; Ropeobj178006* sname0; Ropeobj178006* a0; Tnode292802* k0; Tsym292834* field0; { result0 = (Ropeobj178006*)0; ae0 = (Ropeobj178006*)0; uname0 = (Ropeobj178006*)0; sname0 = (Ropeobj178006*)0; a0 = (Ropeobj178006*)0; k0 = (Tnode292802*)0; field0 = (Tsym292834*)0; result0 = NIM_NIL; switch ((*n0).kind) { case ((Tnodekind292020) 138): { { NI i_534447_839829468; NI HEX3Atmp_534620_839829468; NI LOC3; NI res_534623_839829468; i_534447_839829468 = (NI)0; HEX3Atmp_534620_839829468 = (NI)0; LOC3 = (NI)0; LOC3 = sonslen_295351_850551059(n0); HEX3Atmp_534620_839829468 = (NI)(LOC3 - ((NI) 1)); res_534623_839829468 = ((NI) 0); { while (1) { Ropeobj178006* LOC6; if (!(res_534623_839829468 <= HEX3Atmp_534620_839829468)) goto LA5; i_534447_839829468 = res_534623_839829468; LOC6 = (Ropeobj178006*)0; LOC6 = genrecordfieldsaux_534421_839829468(m0, (*n0).kindU.S6.sons->data[i_534447_839829468], accessexpr0, rectype0, check0); add_178482_2381377266(&result0, LOC6); res_534623_839829468 += ((NI) 1); } LA5: ; } } } break; case ((Tnodekind292020) 139): { Ropeobj178006* LOC12; NimStringDesc* LOC13; NimStringDesc* LOC14; Ropeobj178006* unionbody0; { if (!!(((*(*n0).kindU.S6.sons->data[((NI) 0)]).kind == ((Tnodekind292020) 3)))) goto LA10; internalerror_196100_155036129((*n0).info, ((NimStringDesc*) &T839829468_89)); } LA10: ; LOC12 = (Ropeobj178006*)0; LOC12 = genrecordfieldsaux_534421_839829468(m0, (*n0).kindU.S6.sons->data[((NI) 0)], accessexpr0, rectype0, check0); add_178482_2381377266(&result0, LOC12); LOC13 = (NimStringDesc*)0; LOC14 = (NimStringDesc*)0; LOC14 = mangle_528847_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_178277_2381377266(LOC13); { TY532811 LOC19; if (!!((accessexpr0 == NIM_NIL))) goto LA17; memset((void*)LOC19, 0, sizeof(LOC19)); LOC19[0] = accessexpr0; LOC19[1] = uname0; ae0 = HEX25_178905_2381377266(((NimStringDesc*) &T839829468_90), LOC19, 2); } goto LA15; LA17: ; { ae0 = uname0; } LA15: ; unionbody0 = NIM_NIL; { NI i_534491_839829468; NI HEX3Atmp_534629_839829468; NI LOC22; NI res_534632_839829468; i_534491_839829468 = (NI)0; HEX3Atmp_534629_839829468 = (NI)0; LOC22 = (NI)0; LOC22 = sonslen_295351_850551059(n0); HEX3Atmp_534629_839829468 = (NI)(LOC22 - ((NI) 1)); res_534632_839829468 = ((NI) 1); { while (1) { if (!(res_534632_839829468 <= HEX3Atmp_534629_839829468)) goto LA24; i_534491_839829468 = res_534632_839829468; switch ((*(*n0).kindU.S6.sons->data[i_534491_839829468]).kind) { case ((Tnodekind292020) 85): case ((Tnodekind292020) 88): { k0 = lastson_295364_850551059((*n0).kindU.S6.sons->data[i_534491_839829468]); { Ropeobj178006* LOC30; TY532811 LOC31; Ropeobj178006* LOC32; if (!!(((*k0).kind == ((Tnodekind292020) 3)))) goto LA28; LOC30 = (Ropeobj178006*)0; LOC30 = rope_178401_2381377266(((NI64) (i_534491_839829468))); sname0 = HEX26_178452_2381377266(((NimStringDesc*) &T839829468_91), LOC30); memset((void*)LOC31, 0, sizeof(LOC31)); LOC31[0] = ae0; LOC31[1] = sname0; LOC32 = (Ropeobj178006*)0; LOC32 = HEX25_178905_2381377266(((NimStringDesc*) &T839829468_90), LOC31, 2); a0 = genrecordfieldsaux_534421_839829468(m0, k0, LOC32, rectype0, check0); { TY178507 LOC37; if (!!((a0 == NIM_NIL))) goto LA35; add_178487_2381377266(&unionbody0, ((NimStringDesc*) &T839829468_92)); add_178482_2381377266(&unionbody0, a0); memset((void*)LOC37, 0, sizeof(LOC37)); LOC37[0] = sname0; addf_179205_2381377266(&unionbody0, ((NimStringDesc*) &T839829468_93), LOC37, 1); } LA35: ; } goto LA26; LA28: ; { Ropeobj178006* LOC39; LOC39 = (Ropeobj178006*)0; LOC39 = genrecordfieldsaux_534421_839829468(m0, k0, ae0, rectype0, check0); add_178482_2381377266(&unionbody0, LOC39); } LA26: ; } break; default: { internalerror_196113_155036129(((NimStringDesc*) &T839829468_94)); } break; } res_534632_839829468 += ((NI) 1); } LA24: ; } } { TY532811 LOC45; if (!!((unionbody0 == NIM_NIL))) goto LA43; memset((void*)LOC45, 0, sizeof(LOC45)); LOC45[0] = unionbody0; LOC45[1] = uname0; addf_179205_2381377266(&result0, ((NimStringDesc*) &T839829468_95), LOC45, 2); } LA43: ; } break; case ((Tnodekind292020) 3): { field0 = (*n0).kindU.S4.sym; { if (!((*(*field0).typ).kind == ((Ttypekind292244) 62))) goto LA49; goto BeforeRet; } LA49: ; sname0 = manglerecfieldname_534361_839829468(field0, rectype0); { TY532811 LOC55; if (!!((accessexpr0 == NIM_NIL))) goto LA53; memset((void*)LOC55, 0, sizeof(LOC55)); LOC55[0] = accessexpr0; LOC55[1] = sname0; ae0 = HEX25_178905_2381377266(((NimStringDesc*) &T839829468_90), LOC55, 2); } goto LA51; LA53: ; { ae0 = sname0; } LA51: ; fillloc_532282_839829468((&(*field0).loc), ((Tlockind292808) 5), (*field0).typ, ae0, ((Tstorageloc292812) 0)); { NIM_BOOL LOC59; Ttype292840* fieldtype0; LOC59 = (NIM_BOOL)0; LOC59 = isimportedcpptype_533476_839829468(rectype0); if (!!(LOC59)) goto LA60; fieldtype0 = skiptypes_296099_850551059((*field0).loc.t, IL64(211106232576256)); { NIM_BOOL LOC64; TY532811 LOC68; Ttype292840* LOC69; LOC64 = (NIM_BOOL)0; LOC64 = ((*fieldtype0).kind == ((Ttypekind292244) 16)); if (!(LOC64)) goto LA65; LOC64 = (((*fieldtype0).flags &(1U<<((NU)(((Ttypeflag292431) 0))&31U)))!=0); LA65: ; if (!LOC64) goto LA66; memset((void*)LOC68, 0, sizeof(LOC68)); LOC69 = (Ttype292840*)0; LOC69 = elemtype_320394_3876443242(fieldtype0); LOC68[0] = gettypedescaux_533503_839829468(m0, LOC69, check0); LOC68[1] = sname0; addf_179205_2381377266(&result0, ((NimStringDesc*) &T839829468_97), LOC68, 2); } goto LA62; LA66: ; { TY532811 LOC73; if (!((*fieldtype0).kind == ((Ttypekind292244) 24))) goto LA71; memset((void*)LOC73, 0, sizeof(LOC73)); LOC73[0] = gettypedescweak_534079_839829468(m0, (*field0).loc.t, check0); LOC73[1] = sname0; addf_179205_2381377266(&result0, ((NimStringDesc*) &T839829468_54), LOC73, 2); } goto LA62; LA71: ; { TY535238 LOC77; NimStringDesc* LOC78; if (!!(((*field0).kindU.S4.bitsize == ((NI) 0)))) goto LA75; memset((void*)LOC77, 0, sizeof(LOC77)); LOC77[0] = gettypedescaux_533503_839829468(m0, (*field0).loc.t, check0); LOC77[1] = sname0; LOC78 = (NimStringDesc*)0; LOC78 = nimIntToStr((*field0).kindU.S4.bitsize); LOC77[2] = rope_178277_2381377266(LOC78); addf_179205_2381377266(&result0, ((NimStringDesc*) &T839829468_98), LOC77, 3); } goto LA62; LA75: ; { TY532811 LOC80; memset((void*)LOC80, 0, sizeof(LOC80)); LOC80[0] = gettypedescaux_533503_839829468(m0, (*field0).loc.t, check0); LOC80[1] = sname0; addf_179205_2381377266(&result0, ((NimStringDesc*) &T839829468_54), LOC80, 2); } LA62: ; } LA60: ; } break; default: { internalerror_196100_155036129((*n0).info, ((NimStringDesc*) &T839829468_99)); } break; } }BeforeRet: ; return result0; } N_NIMCALL(Ropeobj178006*, getrecordfields_534636_839829468)(Tcgen529027* m0, Ttype292840* typ0, Intset268030* check0) { Ropeobj178006* result0; result0 = (Ropeobj178006*)0; result0 = genrecordfieldsaux_534421_839829468(m0, (*typ0).n, NIM_NIL, typ0, check0); return result0; } N_NIMCALL(Ropeobj178006*, getrecorddesc_534643_839829468)(Tcgen529027* m0, Ttype292840* typ0, Ropeobj178006* name0, Intset268030* check0) { Ropeobj178006* result0; NIM_BOOL hasfield0; Ropeobj178006* attribute0; TY535238 LOC6; Ropeobj178006* desc0; NimStringDesc* LOC46; result0 = (Ropeobj178006*)0; hasfield0 = NIM_FALSE; { if (!(((*typ0).flags &(1U<<((NU)(((Ttypeflag292431) 21))&31U)))!=0)) goto LA3; attribute0 = rope_178277_2381377266(Cc_273413_2528170400[(ccompiler_273431_2528170400)- 1].Field19); } goto LA1; LA3: ; { attribute0 = NIM_NIL; } LA1: ; memset((void*)LOC6, 0, sizeof(LOC6)); LOC6[0] = structorunion_534001_839829468(typ0); LOC6[1] = name0; LOC6[2] = attribute0; result0 = ropecg_532407_839829468(m0, Cc_273413_2528170400[(ccompiler_273431_2528170400)- 1].Field18, LOC6, 3); { if (!((*typ0).kind == ((Ttypekind292244) 17))) goto LA9; { if (!((*typ0).sons->data[((NI) 0)] == NIM_NIL)) goto LA13; { NIM_BOOL LOC17; NIM_BOOL LOC18; TY533289 LOC23; LOC17 = (NIM_BOOL)0; LOC18 = (NIM_BOOL)0; LOC18 = !(((*typ0).sym == NIM_NIL)); if (!(LOC18)) goto LA19; LOC18 = (((*(*typ0).sym).flags &(1U<<((NU)(((Tsymflag292184) 9))&31U)))!=0); LA19: ; LOC17 = LOC18; if (LOC17) goto LA20; LOC17 = (((*typ0).flags &(1U<<((NU)(((Ttypeflag292431) 2))&31U)))!=0); LA20: ; if (!LOC17) goto LA21; memset((void*)LOC23, 0, sizeof(LOC23)); appcg_532632_839829468(m0, &result0, ((NimStringDesc*) &T839829468_85), LOC23, 0); } goto LA15; LA21: ; { TY532811 LOC25; memset((void*)LOC25, 0, sizeof(LOC25)); LOC25[0] = name0; LOC25[1] = attribute0; appcg_532632_839829468(m0, &result0, ((NimStringDesc*) &T839829468_86), LOC25, 2); hasfield0 = NIM_TRUE; } LA15: ; } goto LA11; LA13: ; { NIM_BOOL LOC27; TY178507 LOC31; Ttype292840* LOC32; LOC27 = (NIM_BOOL)0; LOC27 = (gcmd_169132_2607990831 == ((Tcommands169076) 2)); if (LOC27) goto LA28; LOC27 = (((*(*m0).module).flags &(1U<<((NU)(((Tsymflag292184) 27))&31U)))!=0); LA28: ; if (!LOC27) goto LA29; memset((void*)LOC31, 0, sizeof(LOC31)); LOC32 = (Ttype292840*)0; LOC32 = skiptypes_296099_850551059((*typ0).sons->data[((NI) 0)], IL64(211106247215360)); LOC31[0] = gettypedescaux_533503_839829468(m0, LOC32, check0); appcg_532632_839829468(m0, &result0, ((NimStringDesc*) &T839829468_87), LOC31, 1); hasfield0 = NIM_TRUE; } goto LA11; LA29: ; { TY178507 LOC34; Ttype292840* LOC35; memset((void*)LOC34, 0, sizeof(LOC34)); LOC35 = (Ttype292840*)0; LOC35 = skiptypes_296099_850551059((*typ0).sons->data[((NI) 0)], IL64(211106247215360)); LOC34[0] = gettypedescaux_533503_839829468(m0, LOC35, check0); appcg_532632_839829468(m0, &result0, ((NimStringDesc*) &T839829468_88), LOC34, 1); hasfield0 = NIM_TRUE; } LA11: ; } goto LA7; LA9: ; { TY178507 LOC37; memset((void*)LOC37, 0, sizeof(LOC37)); LOC37[0] = name0; addf_179205_2381377266(&result0, ((NimStringDesc*) &T839829468_85), LOC37, 1); } LA7: ; desc0 = getrecordfields_534636_839829468(m0, typ0, check0); { NIM_BOOL LOC40; TY533289 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_179205_2381377266(&result0, ((NimStringDesc*) &T839829468_100), LOC44, 0); } goto LA38; LA42: ; { add_178482_2381377266(&result0, desc0); } LA38: ; LOC46 = (NimStringDesc*)0; LOC46 = rawNewString(tnl_176644_4151366050->Sup.len + 2); appendString(LOC46, ((NimStringDesc*) &T839829468_101)); appendString(LOC46, tnl_176644_4151366050); add_178487_2381377266(&result0, LOC46); return result0; } N_NIMCALL(Ropeobj178006*, gettupledesc_534777_839829468)(Tcgen529027* m0, Ttype292840* typ0, Ropeobj178006* name0, Intset268030* check0) { Ropeobj178006* result0; TY532811 LOC1; Ropeobj178006* desc0; NimStringDesc* LOC13; result0 = (Ropeobj178006*)0; memset((void*)LOC1, 0, sizeof(LOC1)); LOC1[0] = structorunion_534001_839829468(typ0); LOC1[1] = name0; result0 = HEX25_178905_2381377266(((NimStringDesc*) &T839829468_102), LOC1, 2); desc0 = NIM_NIL; { NI i_534799_839829468; NI HEX3Atmp_534820_839829468; NI LOC3; NI res_534823_839829468; i_534799_839829468 = (NI)0; HEX3Atmp_534820_839829468 = (NI)0; LOC3 = (NI)0; LOC3 = sonslen_295327_850551059(typ0); HEX3Atmp_534820_839829468 = (NI)(LOC3 - ((NI) 1)); res_534823_839829468 = ((NI) 0); { while (1) { TY532811 LOC6; if (!(res_534823_839829468 <= HEX3Atmp_534820_839829468)) goto LA5; i_534799_839829468 = res_534823_839829468; memset((void*)LOC6, 0, sizeof(LOC6)); LOC6[0] = gettypedescaux_533503_839829468(m0, (*typ0).sons->data[i_534799_839829468], check0); LOC6[1] = rope_178401_2381377266(((NI64) (i_534799_839829468))); addf_179205_2381377266(&desc0, ((NimStringDesc*) &T839829468_103), LOC6, 2); res_534823_839829468 += ((NI) 1); } LA5: ; } } { NimStringDesc* LOC11; if (!(desc0 == NIM_NIL)) goto LA9; LOC11 = (NimStringDesc*)0; LOC11 = rawNewString(tnl_176644_4151366050->Sup.len + 11); appendString(LOC11, ((NimStringDesc*) &T839829468_104)); appendString(LOC11, tnl_176644_4151366050); add_178487_2381377266(&result0, LOC11); } goto LA7; LA9: ; { add_178482_2381377266(&result0, desc0); } LA7: ; LOC13 = (NimStringDesc*)0; LOC13 = rawNewString(tnl_176644_4151366050->Sup.len + 2); appendString(LOC13, ((NimStringDesc*) &T839829468_101)); appendString(LOC13, tnl_176644_4151366050); add_178487_2381377266(&result0, LOC13); return result0; } N_NIMCALL(Ropeobj178006*, gettypedescaux_533503_839829468)(Tcgen529027* m0, Ttype292840* typ0, Intset268030* check0) { Ropeobj178006* result0; Ttype292840* t_534942_839829468; { result0 = (Ropeobj178006*)0; t_534942_839829468 = getuniquetype_528640_2036603609(typ0); { if (!(t_534942_839829468 == NIM_NIL)) goto LA3; internalerror_196113_155036129(((NimStringDesc*) &T839829468_27)); } LA3: ; { if (!!(((*t_534942_839829468).sym == NIM_NIL))) goto LA7; useheader_532369_839829468(m0, (*t_534942_839829468).sym); } LA7: ; result0 = gettypepre_533972_839829468(m0, t_534942_839829468); { if (!!((result0 == NIM_NIL))) goto LA11; goto BeforeRet; } LA11: ; { NIM_BOOL LOC15; LOC15 = (NIM_BOOL)0; LOC15 = containsorincl_268862_2627731572(check0, (*t_534942_839829468).Sup.id); if (!LOC15) goto LA16; { NIM_BOOL LOC20; NimStringDesc* LOC24; NimStringDesc* LOC25; LOC20 = (NIM_BOOL)0; LOC20 = isimportedcpptype_533476_839829468(typ0); if (LOC20) goto LA21; LOC20 = isimportedcpptype_533476_839829468(t_534942_839829468); LA21: ; if (!!(LOC20)) goto LA22; LOC24 = (NimStringDesc*)0; LOC25 = (NimStringDesc*)0; LOC25 = typetostring_320017_3876443242(typ0, ((Tprefereddesc320011) 0)); LOC24 = rawNewString(LOC25->Sup.len + 28); appendString(LOC24, ((NimStringDesc*) &T839829468_51)); appendString(LOC24, LOC25); internalerror_196113_155036129(LOC24); } LA22: ; } LA16: ; switch ((*t_534942_839829468).kind) { case ((Ttypekind292244) 22): case ((Ttypekind292244) 21): case ((Ttypekind292244) 23): { NimStringDesc* star0; Ttype292840* et0; Ttype292840* LOC38; Ttype292840* etb0; { NIM_BOOL LOC29; NIM_BOOL LOC30; NIM_BOOL LOC33; LOC29 = (NIM_BOOL)0; LOC30 = (NIM_BOOL)0; LOC30 = ((*t_534942_839829468).kind == ((Ttypekind292244) 23)); if (!(LOC30)) goto LA31; LOC30 = !((((*typ0).flags &(1U<<((NU)(((Ttypeflag292431) 18))&31U)))!=0)); LA31: ; LOC29 = LOC30; if (!(LOC29)) goto LA32; LOC33 = (NIM_BOOL)0; LOC33 = (gcmd_169132_2607990831 == ((Tcommands169076) 2)); if (LOC33) goto LA34; LOC33 = (((*(*m0).module).flags &(1U<<((NU)(((Tsymflag292184) 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 = (Ttype292840*)0; LOC38 = skiptypes_296099_850551059(typ0, IL64(211106232576256)); et0 = lastson_295377_850551059(LOC38); etb0 = skiptypes_296099_850551059(et0, IL64(211106232576256)); { if (!((*etb0).kind == ((Ttypekind292244) 4) || (*etb0).kind == ((Ttypekind292244) 16) || (*etb0).kind == ((Ttypekind292244) 27) || (*etb0).kind == ((Ttypekind292244) 48))) goto LA41; et0 = elemtype_320394_3876443242(etb0); etb0 = skiptypes_296099_850551059(et0, IL64(211106232576256)); star0->data[((NI) 0)] = 42; } LA41: ; switch ((*etb0).kind) { case ((Ttypekind292244) 17): case ((Ttypekind292244) 18): { { NIM_BOOL LOC46; Ropeobj178006* LOC50; LOC46 = (NIM_BOOL)0; LOC46 = isimportedcpptype_533476_839829468(etb0); if (!(LOC46)) goto LA47; LOC46 = ((*et0).kind == ((Ttypekind292244) 11)); LA47: ; if (!LOC46) goto LA48; LOC50 = (Ropeobj178006*)0; LOC50 = gettypedescaux_533503_839829468(m0, et0, check0); result0 = HEX26_178447_2381377266(LOC50, star0); } goto LA44; LA48: ; { Ttype292840* x0; Ropeobj178006* name0; Tidobj199004* LOC52; TNimObject* LOC53; x0 = getuniquetype_528640_2036603609(etb0); name0 = gettypeforward_534039_839829468(m0, x0); result0 = HEX26_178447_2381377266(name0, star0); LOC52 = (Tidobj199004*)0; LOC52 = &t_534942_839829468->Sup; LOC53 = (TNimObject*)0; LOC53 = &result0->Sup; idtableput_299094_2984716966((&(*m0).typecache), LOC52, LOC53); pushtype_533958_839829468(m0, x0); } LA44: ; } break; case ((Ttypekind292244) 24): { Ttype292840* x0; Ropeobj178006* name0; Ropeobj178006* LOC55; Tidobj199004* LOC56; TNimObject* LOC57; x0 = getuniquetype_528640_2036603609(etb0); name0 = gettypeforward_534039_839829468(m0, x0); LOC55 = (Ropeobj178006*)0; LOC55 = HEX26_178447_2381377266(name0, ((NimStringDesc*) &T839829468_53)); result0 = HEX26_178447_2381377266(LOC55, star0); LOC56 = (Tidobj199004*)0; LOC56 = &t_534942_839829468->Sup; LOC57 = (TNimObject*)0; LOC57 = &result0->Sup; idtableput_299094_2984716966((&(*m0).typecache), LOC56, LOC57); pushtype_533958_839829468(m0, x0); } break; default: { Ropeobj178006* LOC59; Tidobj199004* LOC60; TNimObject* LOC61; LOC59 = (Ropeobj178006*)0; LOC59 = gettypedescaux_533503_839829468(m0, et0, check0); result0 = HEX26_178447_2381377266(LOC59, star0); LOC60 = (Tidobj199004*)0; LOC60 = &t_534942_839829468->Sup; LOC61 = (TNimObject*)0; LOC61 = &result0->Sup; idtableput_299094_2984716966((&(*m0).typecache), LOC60, LOC61); } break; } } break; case ((Ttypekind292244) 27): case ((Ttypekind292244) 48): { Ropeobj178006* LOC63; Tidobj199004* LOC64; TNimObject* LOC65; LOC63 = (Ropeobj178006*)0; LOC63 = gettypedescweak_534079_839829468(m0, (*t_534942_839829468).sons->data[((NI) 0)], check0); result0 = HEX26_178447_2381377266(LOC63, ((NimStringDesc*) &T839829468_53)); LOC64 = (Tidobj199004*)0; LOC64 = &t_534942_839829468->Sup; LOC65 = (TNimObject*)0; LOC65 = &result0->Sup; idtableput_299094_2984716966((&(*m0).typecache), LOC64, LOC65); } break; case ((Ttypekind292244) 20): case ((Ttypekind292244) 14): { Ttype292840* t0; { if (!((*t_534942_839829468).kind == ((Ttypekind292244) 20))) goto LA69; t0 = lastson_295377_850551059(t_534942_839829468); } goto LA67; LA69: ; { t0 = t_534942_839829468; } LA67: ; result0 = cachegettype_533591_839829468((*m0).typecache, t0); { if (!(result0 == NIM_NIL)) goto LA74; result0 = gettypename_533313_839829468(t0); { NIM_BOOL LOC78; NIM_BOOL LOC80; Tidobj199004* LOC84; TNimObject* LOC85; NI size0; NU32 owner0; LOC78 = (NIM_BOOL)0; LOC78 = isimportedcpptype_533476_839829468(t0); if (LOC78) goto LA79; LOC80 = (NIM_BOOL)0; LOC80 = (((*(*t0).sym).flags &(1U<<((NU)(((Tsymflag292184) 5))&31U)))!=0); if (!(LOC80)) goto LA81; LOC80 = ((*(*t0).sym).magic == ((Tmagic292524) 0)); LA81: ; LOC78 = LOC80; LA79: ; if (!!(LOC78)) goto LA82; LOC84 = (Tidobj199004*)0; LOC84 = &t0->Sup; LOC85 = (TNimObject*)0; LOC85 = &result0->Sup; idtableput_299094_2984716966((&(*m0).typecache), LOC84, LOC85); size0 = (NI)0; { NI64 LOC88; TY178507 LOC91; LOC88 = (NI64)0; LOC88 = firstord_320001_3876443242(t0); if (!(LOC88 < IL64(0))) goto LA89; memset((void*)LOC91, 0, sizeof(LOC91)); LOC91[0] = result0; addf_179205_2381377266(&(*m0).s[(((Tcfilesection529005) 3))- 0], ((NimStringDesc*) &T839829468_59), LOC91, 1); size0 = ((NI) 4); } goto LA86; LA89: ; { NI64 LOC93; LOC93 = (NI64)0; LOC93 = getsize_320135_3876443242(t0); size0 = ((NI) (LOC93)); switch (size0) { case ((NI) 1): { TY178507 LOC95; memset((void*)LOC95, 0, sizeof(LOC95)); LOC95[0] = result0; addf_179205_2381377266(&(*m0).s[(((Tcfilesection529005) 3))- 0], ((NimStringDesc*) &T839829468_60), LOC95, 1); } break; case ((NI) 2): { TY178507 LOC97; memset((void*)LOC97, 0, sizeof(LOC97)); LOC97[0] = result0; addf_179205_2381377266(&(*m0).s[(((Tcfilesection529005) 3))- 0], ((NimStringDesc*) &T839829468_61), LOC97, 1); } break; case ((NI) 4): { TY178507 LOC99; memset((void*)LOC99, 0, sizeof(LOC99)); LOC99[0] = result0; addf_179205_2381377266(&(*m0).s[(((Tcfilesection529005) 3))- 0], ((NimStringDesc*) &T839829468_59), LOC99, 1); } break; case ((NI) 8): { TY178507 LOC101; memset((void*)LOC101, 0, sizeof(LOC101)); LOC101[0] = result0; addf_179205_2381377266(&(*m0).s[(((Tcfilesection529005) 3))- 0], ((NimStringDesc*) &T839829468_62), LOC101, 1); } break; default: { internalerror_196100_155036129((*(*t0).sym).info, ((NimStringDesc*) &T839829468_63)); } break; } } LA86: ; owner0 = hashowner_532977_839829468((*t0).sym); { NIM_BOOL LOC105; TY203017* vals0; Enumdesc203007 LOC114; LOC105 = (NIM_BOOL)0; LOC105 = hasenum_203230_1926258066(gdebuginfo_203470_1926258066, (*(*(*t0).sym).name).s, ((NI) ((*(*t0).sym).info.line)), owner0); if (!!(LOC105)) goto LA106; vals0 = (TY203017*) newSeq((&NTI203017), 0); { NI i_535144_839829468; NI HEX3Atmp_535648_839829468; NI LOC109; NI res_535651_839829468; i_535144_839829468 = (NI)0; HEX3Atmp_535648_839829468 = (NI)0; LOC109 = (NI)0; LOC109 = len_293081_850551059((*t0).n); HEX3Atmp_535648_839829468 = (NI)(LOC109 - ((NI) 1)); res_535651_839829468 = ((NI) 0); { while (1) { Tsym292834* field0; TY203018 LOC112; NimStringDesc* LOC113; if (!(res_535651_839829468 <= HEX3Atmp_535648_839829468)) goto LA111; i_535144_839829468 = res_535651_839829468; field0 = (*(*(*t0).n).kindU.S6.sons->data[i_535144_839829468]).kindU.S4.sym; memset((void*)(&LOC112), 0, sizeof(LOC112)); LOC112.Field0 = copyString((*(*field0).name).s); LOC112.Field1 = (*field0).position; vals0 = (TY203017*) incrSeqV2(&(vals0)->Sup, sizeof(TY203018)); 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_535651_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, (&NTI203017)); registerenum_203419_1926258066((&gdebuginfo_203470_1926258066), (&LOC114)); } LA106: ; } LA82: ; } LA74: ; } break; case ((Ttypekind292244) 25): { Tidobj199004* LOC116; TNimObject* LOC117; Ropeobj178006* rettype0; Ropeobj178006* desc0; result0 = gettypename_533313_839829468(t_534942_839829468); LOC116 = (Tidobj199004*)0; LOC116 = &t_534942_839829468->Sup; LOC117 = (TNimObject*)0; LOC117 = &result0->Sup; idtableput_299094_2984716966((&(*m0).typecache), LOC116, LOC117); rettype0 = (Ropeobj178006*)0; desc0 = (Ropeobj178006*)0; genprocparams_534115_839829468(m0, t_534942_839829468, &rettype0, &desc0, check0, NIM_TRUE, NIM_TRUE); { NIM_BOOL LOC120; LOC120 = (NIM_BOOL)0; LOC120 = isimportedtype_533449_839829468(t_534942_839829468); if (!!(LOC120)) goto LA121; { TY535235 LOC127; if (!!(((*t_534942_839829468).callconv == ((Tcallingconvention292002) 8)))) goto LA125; memset((void*)LOC127, 0, sizeof(LOC127)); LOC127[0] = rope_178277_2381377266(Callingconvtostr_533585_839829468[((*t_534942_839829468).callconv)- 0]); LOC127[1] = rettype0; LOC127[2] = result0; LOC127[3] = desc0; addf_179205_2381377266(&(*m0).s[(((Tcfilesection529005) 3))- 0], ((NimStringDesc*) &T839829468_64), LOC127, 4); } goto LA123; LA125: ; { TY535238 LOC129; memset((void*)LOC129, 0, sizeof(LOC129)); LOC129[0] = result0; LOC129[1] = rettype0; LOC129[2] = desc0; addf_179205_2381377266(&(*m0).s[(((Tcfilesection529005) 3))- 0], ((NimStringDesc*) &T839829468_75), LOC129, 3); } LA123: ; } LA121: ; } break; case ((Ttypekind292244) 24): { Tidobj199004* LOC144; Ropeobj178006* LOC145; TNimObject* LOC146; result0 = cachegettype_533591_839829468((*m0).forwtypecache, t_534942_839829468); { Tidobj199004* LOC142; TNimObject* LOC143; if (!(result0 == NIM_NIL)) goto LA133; result0 = gettypename_533313_839829468(t_534942_839829468); { NIM_BOOL LOC137; NimStringDesc* LOC140; TY532811 LOC141; LOC137 = (NIM_BOOL)0; LOC137 = isimportedtype_533449_839829468(t_534942_839829468); if (!!(LOC137)) goto LA138; LOC140 = (NimStringDesc*)0; LOC140 = getforwardstructformat_534015_839829468(m0); memset((void*)LOC141, 0, sizeof(LOC141)); LOC141[0] = structorunion_534001_839829468(t_534942_839829468); LOC141[1] = result0; addf_179205_2381377266(&(*m0).s[(((Tcfilesection529005) 2))- 0], LOC140, LOC141, 2); } LA138: ; LOC142 = (Tidobj199004*)0; LOC142 = &t_534942_839829468->Sup; LOC143 = (TNimObject*)0; LOC143 = &result0->Sup; idtableput_299094_2984716966((&(*m0).forwtypecache), LOC142, LOC143); } LA133: ; LOC144 = (Tidobj199004*)0; LOC144 = &t_534942_839829468->Sup; LOC145 = (Ropeobj178006*)0; LOC145 = HEX26_178447_2381377266(result0, ((NimStringDesc*) &T839829468_53)); LOC146 = (TNimObject*)0; LOC146 = &LOC145->Sup; idtableput_299094_2984716966((&(*m0).typecache), LOC144, LOC146); { NIM_BOOL LOC149; LOC149 = (NIM_BOOL)0; LOC149 = isimportedtype_533449_839829468(t_534942_839829468); if (!!(LOC149)) goto LA150; { Ttype292840* LOC154; NimStringDesc* LOC157; NimStringDesc* LOC158; TY532811 LOC166; LOC154 = (Ttype292840*)0; LOC154 = skiptypes_296099_850551059((*t_534942_839829468).sons->data[((NI) 0)], IL64(211106232576256)); if (!!(((*LOC154).kind == ((Ttypekind292244) 3)))) goto LA155; LOC157 = (NimStringDesc*)0; LOC158 = (NimStringDesc*)0; { NIM_BOOL LOC161; LOC161 = (NIM_BOOL)0; LOC161 = (gcmd_169132_2607990831 == ((Tcommands169076) 2)); if (LOC161) goto LA162; LOC161 = (((*(*m0).module).flags &(1U<<((NU)(((Tsymflag292184) 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_533503_839829468(m0, (*t_534942_839829468).sons->data[((NI) 0)], check0); LOC166[1] = result0; appcg_532632_839829468(m0, &(*m0).s[(((Tcfilesection529005) 4))- 0], LOC157, LOC166, 2); } goto LA152; LA155: ; { result0 = rope_178277_2381377266(((NimStringDesc*) &T839829468_79)); } LA152: ; } LA150: ; add_178487_2381377266(&result0, ((NimStringDesc*) &T839829468_53)); } break; case ((Ttypekind292244) 4): case ((Ttypekind292244) 16): { NI64 n0; Tidobj199004* LOC173; TNimObject* LOC174; n0 = lengthord_320007_3876443242(t_534942_839829468); { if (!(n0 <= IL64(0))) goto LA171; n0 = IL64(1); } LA171: ; result0 = gettypename_533313_839829468(t_534942_839829468); LOC173 = (Tidobj199004*)0; LOC173 = &t_534942_839829468->Sup; LOC174 = (TNimObject*)0; LOC174 = &result0->Sup; idtableput_299094_2984716966((&(*m0).typecache), LOC173, LOC174); { NIM_BOOL LOC177; Ropeobj178006* foo0; TY535238 LOC180; LOC177 = (NIM_BOOL)0; LOC177 = isimportedtype_533449_839829468(t_534942_839829468); if (!!(LOC177)) goto LA178; foo0 = gettypedescaux_533503_839829468(m0, (*t_534942_839829468).sons->data[((NI) 1)], check0); memset((void*)LOC180, 0, sizeof(LOC180)); LOC180[0] = foo0; LOC180[1] = result0; LOC180[2] = rope_178401_2381377266(n0); addf_179205_2381377266(&(*m0).s[(((Tcfilesection529005) 3))- 0], ((NimStringDesc*) &T839829468_80), LOC180, 3); } LA178: ; } break; case ((Ttypekind292244) 17): case ((Ttypekind292244) 18): { { NIM_BOOL LOC184; Ropeobj178006* cppname0; NI i0; NI chunkstart0; Ropeobj178006* LOC226; LOC184 = (NIM_BOOL)0; LOC184 = isimportedcpptype_533476_839829468(t_534942_839829468); if (!(LOC184)) goto LA185; LOC184 = ((*typ0).kind == ((Ttypekind292244) 11)); LA185: ; if (!LOC184) goto LA186; cppname0 = gettypename_533313_839829468(t_534942_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; Ttype292840* typeinslot0; LOC196 = (NIM_BOOL)0; LOC196 = scancppgenericslot_534827_839829468((*cppname0).data, (&i0), (&idx0), (&stars0)); if (!LOC196) goto LA197; LOC199 = (NimStringDesc*)0; LOC199 = copyStrLast((*cppname0).data, chunkstart0, chunkend0); add_178487_2381377266(&result0, LOC199); chunkstart0 = i0; typeinslot0 = resolvestarsincpptype_534891_839829468(typ0, (NI)(idx0 + ((NI) 1)), stars0); { NIM_BOOL LOC202; TY533289 LOC206; Ropeobj178006* LOC207; LOC202 = (NIM_BOOL)0; LOC202 = (typeinslot0 == NIM_NIL); if (LOC202) goto LA203; LOC202 = ((*typeinslot0).kind == ((Ttypekind292244) 62)); LA203: ; if (!LOC202) goto LA204; memset((void*)LOC206, 0, sizeof(LOC206)); LOC207 = (Ropeobj178006*)0; LOC207 = HEX25_178905_2381377266(((NimStringDesc*) &T839829468_26), LOC206, 0); add_178482_2381377266(&result0, LOC207); } goto LA200; LA204: ; { Ropeobj178006* LOC209; LOC209 = (Ropeobj178006*)0; LOC209 = gettypedescaux_533503_839829468(m0, typeinslot0, check0); add_178482_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_178487_2381377266(&result0, LOC215); } goto LA211; LA213: ; { result0 = HEX26_178447_2381377266(cppname0, ((NimStringDesc*) &T839829468_82)); { NI i_535516_839829468; NI HEX3Atmp_535664_839829468; NI LOC218; NI res_535667_839829468; i_535516_839829468 = (NI)0; HEX3Atmp_535664_839829468 = (NI)0; LOC218 = (NI)0; LOC218 = len_295339_850551059(typ0); HEX3Atmp_535664_839829468 = (NI)(LOC218 - ((NI) 2)); res_535667_839829468 = ((NI) 1); { while (1) { Ropeobj178006* LOC225; if (!(res_535667_839829468 <= HEX3Atmp_535664_839829468)) goto LA220; i_535516_839829468 = res_535667_839829468; { if (!(((NI) 1) < i_535516_839829468)) goto LA223; add_178487_2381377266(&result0, ((NimStringDesc*) &T839829468_83)); } LA223: ; LOC225 = (Ropeobj178006*)0; LOC225 = gettypedescaux_533503_839829468(m0, (*typ0).sons->data[i_535516_839829468], check0); add_178482_2381377266(&result0, LOC225); res_535667_839829468 += ((NI) 1); } LA220: ; } } add_178487_2381377266(&result0, ((NimStringDesc*) &T839829468_84)); } LA211: ; LOC226 = (Ropeobj178006*)0; LOC226 = getrecorddesc_534643_839829468(m0, t_534942_839829468, result0, check0); } goto LA182; LA186: ; { Tidobj199004* LOC241; TNimObject* LOC242; Ropeobj178006* recdesc0; result0 = cachegettype_533591_839829468((*m0).forwtypecache, t_534942_839829468); { Tidobj199004* LOC239; TNimObject* LOC240; if (!(result0 == NIM_NIL)) goto LA230; result0 = gettypename_533313_839829468(t_534942_839829468); { NIM_BOOL LOC234; NimStringDesc* LOC237; TY532811 LOC238; LOC234 = (NIM_BOOL)0; LOC234 = isimportedtype_533449_839829468(t_534942_839829468); if (!!(LOC234)) goto LA235; LOC237 = (NimStringDesc*)0; LOC237 = getforwardstructformat_534015_839829468(m0); memset((void*)LOC238, 0, sizeof(LOC238)); LOC238[0] = structorunion_534001_839829468(t_534942_839829468); LOC238[1] = result0; addf_179205_2381377266(&(*m0).s[(((Tcfilesection529005) 2))- 0], LOC237, LOC238, 2); } LA235: ; LOC239 = (Tidobj199004*)0; LOC239 = &t_534942_839829468->Sup; LOC240 = (TNimObject*)0; LOC240 = &result0->Sup; idtableput_299094_2984716966((&(*m0).forwtypecache), LOC239, LOC240); } LA230: ; LOC241 = (Tidobj199004*)0; LOC241 = &t_534942_839829468->Sup; LOC242 = (TNimObject*)0; LOC242 = &result0->Sup; idtableput_299094_2984716966((&(*m0).typecache), LOC241, LOC242); { if (!!(((*t_534942_839829468).kind == ((Ttypekind292244) 18)))) goto LA245; recdesc0 = getrecorddesc_534643_839829468(m0, t_534942_839829468, result0, check0); } goto LA243; LA245: ; { recdesc0 = gettupledesc_534777_839829468(m0, t_534942_839829468, result0, check0); } LA243: ; { NIM_BOOL LOC250; LOC250 = (NIM_BOOL)0; LOC250 = isimportedtype_533449_839829468(t_534942_839829468); if (!!(LOC250)) goto LA251; add_178482_2381377266(&(*m0).s[(((Tcfilesection529005) 3))- 0], recdesc0); } LA251: ; } LA182: ; } break; case ((Ttypekind292244) 19): { Ttype292840* LOC254; Ropeobj178006* LOC255; Tidobj199004* LOC256; TNimObject* LOC257; LOC254 = (Ttype292840*)0; LOC254 = lastson_295377_850551059(t_534942_839829468); LOC255 = (Ropeobj178006*)0; LOC255 = gettypename_533313_839829468(LOC254); result0 = HEX26_178447_2381377266(LOC255, ((NimStringDesc*) &T839829468_105)); LOC256 = (Tidobj199004*)0; LOC256 = &t_534942_839829468->Sup; LOC257 = (TNimObject*)0; LOC257 = &result0->Sup; idtableput_299094_2984716966((&(*m0).typecache), LOC256, LOC257); { NIM_BOOL LOC260; NI s0; NI64 LOC263; LOC260 = (NIM_BOOL)0; LOC260 = isimportedtype_533449_839829468(t_534942_839829468); if (!!(LOC260)) goto LA261; LOC263 = (NI64)0; LOC263 = getsize_320135_3876443242(t_534942_839829468); s0 = ((NI) (LOC263)); switch (s0) { case ((NI) 1): case ((NI) 2): case ((NI) 4): case ((NI) 8): { TY532811 LOC265; memset((void*)LOC265, 0, sizeof(LOC265)); LOC265[0] = result0; LOC265[1] = rope_178401_2381377266(((NI64) ((NI)(s0 * ((NI) 8))))); addf_179205_2381377266(&(*m0).s[(((Tcfilesection529005) 3))- 0], ((NimStringDesc*) &T839829468_106), LOC265, 2); } break; default: { TY532811 LOC267; NI64 LOC268; memset((void*)LOC267, 0, sizeof(LOC267)); LOC267[0] = result0; LOC268 = (NI64)0; LOC268 = getsize_320135_3876443242(t_534942_839829468); LOC267[1] = rope_178401_2381377266(LOC268); addf_179205_2381377266(&(*m0).s[(((Tcfilesection529005) 3))- 0], ((NimStringDesc*) &T839829468_107), LOC267, 2); } break; } } LA261: ; } break; case ((Ttypekind292244) 11): case ((Ttypekind292244) 13): case ((Ttypekind292244) 15): case ((Ttypekind292244) 46): case ((Ttypekind292244) 47): case ((Ttypekind292244) 49): case ((Ttypekind292244) 8): { Ttype292840* LOC270; LOC270 = (Ttype292840*)0; LOC270 = lastson_295377_850551059(t_534942_839829468); result0 = gettypedescaux_533503_839829468(m0, LOC270, check0); } break; default: { NimStringDesc* LOC272; LOC272 = (NimStringDesc*)0; LOC272 = rawNewString(reprEnum((NI)(*t_534942_839829468).kind, (&NTI292244))->Sup.len + 16); appendString(LOC272, ((NimStringDesc*) &T839829468_108)); appendString(LOC272, reprEnum((NI)(*t_534942_839829468).kind, (&NTI292244))); appendChar(LOC272, 41); internalerror_196113_155036129(LOC272); result0 = NIM_NIL; } break; } excl_268841_2627731572(check0, (*t_534942_839829468).Sup.id); }BeforeRet: ; return result0; } static N_INLINE(NIM_BOOL, iscompiletimeonly_328706_3876443242)(Ttype292840* t0) { NIM_BOOL result0; result0 = (NIM_BOOL)0; result0 = ((*t0).kind == ((Ttypekind292244) 8) || (*t0).kind == ((Ttypekind292244) 59)); return result0; } N_NIMCALL(Tstorageloc292812, paramstorageloc_534098_839829468)(Tsym292834* param0) { Tstorageloc292812 result0; result0 = (Tstorageloc292812)0; { Ttype292840* LOC3; LOC3 = (Ttype292840*)0; LOC3 = skiptypes_296099_850551059((*param0).typ, 8388864); if (!!(((*LOC3).kind == ((Ttypekind292244) 16) || (*LOC3).kind == ((Ttypekind292244) 27) || (*LOC3).kind == ((Ttypekind292244) 48) || (*LOC3).kind == ((Ttypekind292244) 4)))) goto LA4; result0 = ((Tstorageloc292812) 2); } goto LA1; LA4: ; { result0 = ((Tstorageloc292812) 0); } LA1: ; return result0; } N_NIMCALL(NIM_BOOL, ccgintroducedptr_533609_839829468)(Tsym292834* s0) { NIM_BOOL result0; Ttype292840* pt0; { result0 = (NIM_BOOL)0; pt0 = skiptypes_296099_850551059((*s0).typ, IL64(211106232576256)); { if (!(((*pt0).flags &(1U<<((NU)(((Ttypeflag292431) 13))&31U)))!=0)) goto LA3; result0 = NIM_TRUE; goto BeforeRet; } goto LA1; LA3: ; { if (!(((*pt0).flags &(1U<<((NU)(((Ttypeflag292431) 12))&31U)))!=0)) goto LA6; result0 = NIM_FALSE; goto BeforeRet; } goto LA1; LA6: ; LA1: ; switch ((*pt0).kind) { case ((Ttypekind292244) 17): { { NIM_BOOL LOC11; NI64 LOC13; LOC11 = (NIM_BOOL)0; LOC11 = (((*s0).options &(1U<<((NU)(((Toption169009) 18))&31U)))!=0); if (LOC11) goto LA12; LOC13 = (NI64)0; LOC13 = getsize_320135_3876443242(pt0); LOC11 = (((NI64) ((NI)(floatsize_176642_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)(((Ttypeflag292431) 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 ((Ttypekind292244) 18): { NIM_BOOL LOC23; NI64 LOC24; LOC23 = (NIM_BOOL)0; LOC24 = (NI64)0; LOC24 = getsize_320135_3876443242(pt0); LOC23 = (((NI64) ((NI)(floatsize_176642_4151366050 * ((NI) 2)))) < LOC24); if (LOC23) goto LA25; LOC23 = (((*s0).options &(1U<<((NU)(((Toption169009) 18))&31U)))!=0); LA25: ; result0 = LOC23; } break; default: { result0 = NIM_FALSE; } break; } }BeforeRet: ; return result0; } N_NIMCALL(Tctypekind529007, mapreturntype_533445_839829468)(Ttype292840* typ0) { Tctypekind529007 result0; result0 = (Tctypekind529007)0; result0 = maptype_533393_839829468(typ0); return result0; } N_NIMCALL(void, genprocparams_534115_839829468)(Tcgen529027* m0, Ttype292840* t0, Ropeobj178006** rettype0, Ropeobj178006** params0, Intset268030* check0, NIM_BOOL declareenvironment0, NIM_BOOL weakdep0) { unsureAsgnRef((void**) (&(*params0)), NIM_NIL); { NIM_BOOL LOC3; TY533289 LOC7; LOC3 = (NIM_BOOL)0; LOC3 = ((*t0).sons->data[((NI) 0)] == NIM_NIL); if (LOC3) goto LA4; LOC3 = isinvalidreturntype_533548_839829468((*t0).sons->data[((NI) 0)]); LA4: ; if (!LOC3) goto LA5; memset((void*)LOC7, 0, sizeof(LOC7)); unsureAsgnRef((void**) (&(*rettype0)), HEX25_178905_2381377266(((NimStringDesc*) &T839829468_26), LOC7, 0)); } goto LA1; LA5: ; { unsureAsgnRef((void**) (&(*rettype0)), gettypedescaux_533503_839829468(m0, (*t0).sons->data[((NI) 0)], check0)); } LA1: ; { NI i_534152_839829468; NI HEX3Atmp_534353_839829468; NI LOC10; NI res_534356_839829468; i_534152_839829468 = (NI)0; HEX3Atmp_534353_839829468 = (NI)0; LOC10 = (NI)0; LOC10 = sonslen_295351_850551059((*t0).n); HEX3Atmp_534353_839829468 = (NI)(LOC10 - ((NI) 1)); res_534356_839829468 = ((NI) 1); { while (1) { if (!(res_534356_839829468 <= HEX3Atmp_534353_839829468)) goto LA12; i_534152_839829468 = res_534356_839829468; { Tsym292834* param0; Ropeobj178006* LOC29; Tstorageloc292812 LOC30; TY533289 LOC45; Ropeobj178006* LOC46; Ttype292840* arr0; NI j0; { if (!!(((*(*(*t0).n).kindU.S6.sons->data[i_534152_839829468]).kind == ((Tnodekind292020) 3)))) goto LA16; internalerror_196100_155036129((*(*t0).n).info, ((NimStringDesc*) &T839829468_109)); } LA16: ; param0 = (*(*(*t0).n).kindU.S6.sons->data[i_534152_839829468]).kindU.S4.sym; { NIM_BOOL LOC20; LOC20 = (NIM_BOOL)0; LOC20 = iscompiletimeonly_328706_3876443242((*param0).typ); if (!LOC20) goto LA21; goto LA13; } LA21: ; { TY533289 LOC27; Ropeobj178006* LOC28; if (!!(((*params0) == NIM_NIL))) goto LA25; memset((void*)LOC27, 0, sizeof(LOC27)); LOC28 = (Ropeobj178006*)0; LOC28 = HEX25_178905_2381377266(((NimStringDesc*) &T839829468_110), LOC27, 0); add_178482_2381377266(params0, LOC28); } LA25: ; LOC29 = (Ropeobj178006*)0; LOC29 = manglename_533205_839829468(param0); LOC30 = (Tstorageloc292812)0; LOC30 = paramstorageloc_534098_839829468(param0); fillloc_532282_839829468((&(*param0).loc), ((Tlockind292808) 4), (*param0).typ, LOC29, LOC30); { NIM_BOOL LOC33; Ropeobj178006* LOC36; TY533289 LOC37; Ropeobj178006* LOC38; LOC33 = (NIM_BOOL)0; LOC33 = ccgintroducedptr_533609_839829468(param0); if (!LOC33) goto LA34; LOC36 = (Ropeobj178006*)0; LOC36 = gettypedescweak_534079_839829468(m0, (*param0).typ, check0); add_178482_2381377266(params0, LOC36); memset((void*)LOC37, 0, sizeof(LOC37)); LOC38 = (Ropeobj178006*)0; LOC38 = HEX25_178905_2381377266(((NimStringDesc*) &T839829468_53), LOC37, 0); add_178482_2381377266(params0, LOC38); (*param0).loc.flags |= ((NU16)1)<<((((Tlocflag292810) 0))%(sizeof(NU16)*8)); (*param0).loc.s = ((Tstorageloc292812) 0); } goto LA31; LA34: ; { Ropeobj178006* LOC42; if (!weakdep0) goto LA40; LOC42 = (Ropeobj178006*)0; LOC42 = gettypedescweak_534079_839829468(m0, (*param0).typ, check0); add_178482_2381377266(params0, LOC42); } goto LA31; LA40: ; { Ropeobj178006* LOC44; LOC44 = (Ropeobj178006*)0; LOC44 = gettypedescaux_533503_839829468(m0, (*param0).typ, check0); add_178482_2381377266(params0, LOC44); } LA31: ; memset((void*)LOC45, 0, sizeof(LOC45)); LOC46 = (Ropeobj178006*)0; LOC46 = HEX25_178905_2381377266(((NimStringDesc*) &T839829468_111), LOC45, 0); add_178482_2381377266(params0, LOC46); add_178482_2381377266(params0, (*param0).loc.r); arr0 = (*param0).typ; { if (!((*arr0).kind == ((Ttypekind292244) 23))) goto LA49; arr0 = (*arr0).sons->data[((NI) 0)]; } LA49: ; j0 = ((NI) 0); { while (1) { TY532811 LOC57; if (!((*arr0).kind == ((Ttypekind292244) 27) || (*arr0).kind == ((Ttypekind292244) 48))) goto LA52; { if (!((*(*param0).typ).kind == ((Ttypekind292244) 23))) goto LA55; (*param0).loc.s = ((Tstorageloc292812) 0); } LA55: ; memset((void*)LOC57, 0, sizeof(LOC57)); LOC57[0] = (*param0).loc.r; LOC57[1] = rope_178401_2381377266(((NI64) (j0))); addf_179205_2381377266(params0, ((NimStringDesc*) &T839829468_112), LOC57, 2); j0 += ((NI) 1); arr0 = (*arr0).sons->data[((NI) 0)]; } LA52: ; } } LA13: ; res_534356_839829468 += ((NI) 1); } LA12: ; } } { NIM_BOOL LOC60; Ttype292840* arr0; TY533289 LOC76; LOC60 = (NIM_BOOL)0; LOC60 = !(((*t0).sons->data[((NI) 0)] == NIM_NIL)); if (!(LOC60)) goto LA61; LOC60 = isinvalidreturntype_533548_839829468((*t0).sons->data[((NI) 0)]); LA61: ; if (!LOC60) goto LA62; arr0 = (*t0).sons->data[((NI) 0)]; { if (!!(((*params0) == NIM_NIL))) goto LA66; add_178487_2381377266(params0, ((NimStringDesc*) &T839829468_110)); } LA66: ; { Tctypekind529007 LOC70; Ropeobj178006* LOC73; LOC70 = (Tctypekind529007)0; LOC70 = mapreturntype_533445_839829468((*t0).sons->data[((NI) 0)]); if (!!((LOC70 == ((Tctypekind529007) 17)))) goto LA71; LOC73 = (Ropeobj178006*)0; LOC73 = gettypedescweak_534079_839829468(m0, arr0, check0); add_178482_2381377266(params0, LOC73); add_178487_2381377266(params0, ((NimStringDesc*) &T839829468_53)); } goto LA68; LA71: ; { Ropeobj178006* LOC75; LOC75 = (Ropeobj178006*)0; LOC75 = gettypedescaux_533503_839829468(m0, arr0, check0); add_178482_2381377266(params0, LOC75); } LA68: ; memset((void*)LOC76, 0, sizeof(LOC76)); addf_179205_2381377266(params0, ((NimStringDesc*) &T839829468_113), LOC76, 0); } LA62: ; { NIM_BOOL LOC79; LOC79 = (NIM_BOOL)0; LOC79 = ((*t0).callconv == ((Tcallingconvention292002) 8)); if (!(LOC79)) goto LA80; LOC79 = declareenvironment0; LA80: ; if (!LOC79) goto LA81; { if (!!(((*params0) == NIM_NIL))) goto LA85; add_178487_2381377266(params0, ((NimStringDesc*) &T839829468_110)); } LA85: ; add_178487_2381377266(params0, ((NimStringDesc*) &T839829468_114)); } LA81: ; { if (!(((*t0).flags &(1U<<((NU)(((Ttypeflag292431) 0))&31U)))!=0)) goto LA89; { if (!!(((*params0) == NIM_NIL))) goto LA93; add_178487_2381377266(params0, ((NimStringDesc*) &T839829468_110)); } LA93: ; add_178487_2381377266(params0, ((NimStringDesc*) &T839829468_115)); } LA89: ; { if (!((*params0) == NIM_NIL)) goto LA97; add_178487_2381377266(params0, ((NimStringDesc*) &T839829468_116)); } goto LA95; LA97: ; { add_178487_2381377266(params0, ((NimStringDesc*) &T839829468_117)); } LA95: ; unsureAsgnRef((void**) (&(*params0)), HEX26_178452_2381377266(((NimStringDesc*) &T839829468_118), (*params0))); } N_NIMCALL(Ropeobj178006*, genprocheader_535867_839829468)(Tcgen529027* m0, Tsym292834* prc0) { Ropeobj178006* result0; Ropeobj178006* rettype0; Ropeobj178006* params0; Intset268030 check0; Ropeobj178006* LOC13; result0 = (Ropeobj178006*)0; rettype0 = (Ropeobj178006*)0; params0 = (Ropeobj178006*)0; genclinedir_532813_839829468(&result0, (*prc0).info); { if (!(((*prc0).loc.flags &(1U<<((NU)(((Tlocflag292810) 5))&15U)))!=0)) goto LA3; { if (!(((*m0).flags &(1U<<((NU)(((Codegenflag529025) 3))&7U)))!=0)) goto LA7; add_178487_2381377266(&result0, ((NimStringDesc*) &T839829468_22)); } goto LA5; LA7: ; { add_178487_2381377266(&result0, ((NimStringDesc*) &T839829468_23)); } LA5: ; } goto LA1; LA3: ; { if (!((*(*prc0).typ).callconv == ((Tcallingconvention292002) 5))) goto LA11; add_178487_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_268885_2627731572((&check0)); LOC13 = (Ropeobj178006*)0; LOC13 = manglename_533205_839829468(prc0); fillloc_532282_839829468((&(*prc0).loc), ((Tlockind292808) 7), (*prc0).typ, LOC13, ((Tstorageloc292812) 0)); genprocparams_534115_839829468(m0, (*prc0).typ, &rettype0, &params0, (&check0), NIM_TRUE, NIM_FALSE); { TY535235 LOC18; if (!(*prc0).constraint == 0) goto LA16; memset((void*)LOC18, 0, sizeof(LOC18)); LOC18[0] = rope_178277_2381377266(Callingconvtostr_533585_839829468[((*(*prc0).typ).callconv)- 0]); LOC18[1] = rettype0; LOC18[2] = (*prc0).loc.r; LOC18[3] = params0; addf_179205_2381377266(&result0, ((NimStringDesc*) &T839829468_119), LOC18, 4); } goto LA14; LA16: ; { TY535238 LOC20; memset((void*)LOC20, 0, sizeof(LOC20)); LOC20[0] = rettype0; LOC20[1] = (*prc0).loc.r; LOC20[2] = params0; result0 = HEX25_178905_2381377266((*(*prc0).constraint).kindU.S3.strval, LOC20, 3); } LA14: ; return result0; } static N_INLINE(Tnode292802*, HEX5BHEX5D_293238_850551059)(Tnode292802* n0, NI i0) { Tnode292802* result0; result0 = (Tnode292802*)0; result0 = (*n0).kindU.S6.sons->data[i0]; return result0; } N_NIMCALL(Tnode292802*, easyresultasgn_560191_839829468)(Tnode292802* n0) { Tnode292802* result0; { result0 = (Tnode292802*)0; switch ((*n0).kind) { case ((Tnodekind292020) 115): case ((Tnodekind292020) 126): { NI i0; i0 = ((NI) 0); { while (1) { NIM_BOOL LOC4; NI LOC5; Tnode292802* LOC7; LOC4 = (NIM_BOOL)0; LOC5 = (NI)0; LOC5 = len_293081_850551059(n0); LOC4 = (i0 < LOC5); if (!(LOC4)) goto LA6; LOC7 = (Tnode292802*)0; LOC7 = HEX5BHEX5D_293238_850551059(n0, i0); LOC4 = ((*LOC7).kind == ((Tnodekind292020) 1) || (*LOC7).kind >= ((Tnodekind292020) 79) && (*LOC7).kind <= ((Tnodekind292020) 81) || (*LOC7).kind == ((Tnodekind292020) 84) || (*LOC7).kind == ((Tnodekind292020) 98) || (*LOC7).kind == ((Tnodekind292020) 101) || (*LOC7).kind == ((Tnodekind292020) 125)); LA6: ; if (!LOC4) goto LA3; i0 += ((NI) 1); } LA3: ; } { NI LOC10; Tnode292802* LOC13; LOC10 = (NI)0; LOC10 = len_293081_850551059(n0); if (!(i0 < LOC10)) goto LA11; LOC13 = (Tnode292802*)0; LOC13 = HEX5BHEX5D_293238_850551059(n0, i0); result0 = easyresultasgn_560191_839829468(LOC13); } LA11: ; } break; case ((Tnodekind292020) 73): case ((Tnodekind292020) 74): { { NIM_BOOL LOC17; Tnode292802* LOC18; Tnode292802* LOC20; LOC17 = (NIM_BOOL)0; LOC18 = (Tnode292802*)0; LOC18 = HEX5BHEX5D_293238_850551059(n0, ((NI) 0)); LOC17 = ((*LOC18).kind == ((Tnodekind292020) 3)); if (!(LOC17)) goto LA19; LOC20 = (Tnode292802*)0; LOC20 = HEX5BHEX5D_293238_850551059(n0, ((NI) 0)); LOC17 = (((Tsymkind292435) 11) == (*(*LOC20).kindU.S4.sym).kind); LA19: ; if (!LOC17) goto LA21; (*n0).flags |= ((NU16)1)<<((((Tnodeflag292427) 14))%(sizeof(NU16)*8)); result0 = HEX5BHEX5D_293238_850551059(n0, ((NI) 1)); goto BeforeRet; } LA21: ; } break; case ((Tnodekind292020) 109): { { NI LOC26; Tnode292802* LOC29; LOC26 = (NI)0; LOC26 = len_293081_850551059(n0); if (!(((NI) 0) < LOC26)) goto LA27; LOC29 = (Tnode292802*)0; LOC29 = HEX5BHEX5D_293238_850551059(n0, ((NI) 0)); result0 = easyresultasgn_560191_839829468(LOC29); { if (!!((result0 == NIM_NIL))) goto LA32; (*n0).flags |= ((NU16)1)<<((((Tnodeflag292427) 14))%(sizeof(NU16)*8)); } LA32: ; } LA27: ; } break; default: { } break; } }BeforeRet: ; return result0; } N_NIMCALL(Ropeobj178006*, gettypedesc_535671_839829468)(Tcgen529027* m0, Ttype292840* typ0) { Ropeobj178006* result0; Intset268030 check0; result0 = (Ropeobj178006*)0; memset((void*)(&check0), 0, sizeof(check0)); chckNil((void*)(&check0)); memset((void*)(&check0), 0, sizeof(check0)); initintset_268885_2627731572((&check0)); result0 = gettypedescaux_533503_839829468(m0, typ0, (&check0)); return result0; } N_NIMCALL(Ropeobj178006*, localvardecl_538532_839829468)(Tcproc529021* p0, Tsym292834* s0) { Ropeobj178006* result0; result0 = (Ropeobj178006*)0; { Ropeobj178006* LOC5; if (!((*s0).loc.k == ((Tlockind292808) 0))) goto LA3; LOC5 = (Ropeobj178006*)0; LOC5 = manglename_533205_839829468(s0); fillloc_532282_839829468((&(*s0).loc), ((Tlockind292808) 2), (*s0).typ, LOC5, ((Tstorageloc292812) 2)); { if (!((*s0).kind == ((Tsymkind292435) 9))) goto LA8; (*s0).loc.flags |= ((NU16)1)<<((((Tlocflag292810) 2))%(sizeof(NU16)*8)); } LA8: ; } LA3: ; result0 = gettypedesc_535671_839829468((*p0).module, (*s0).loc.t); { if (!(*s0).constraint == 0) goto LA12; { if (!(((*s0).flags &(1U<<((NU)(((Tsymflag292184) 8))&31U)))!=0)) goto LA16; add_178487_2381377266(&result0, ((NimStringDesc*) &T839829468_121)); } LA16: ; { if (!(((*s0).flags &(1U<<((NU)(((Tsymflag292184) 7))&31U)))!=0)) goto LA20; add_178487_2381377266(&result0, ((NimStringDesc*) &T839829468_122)); } LA20: ; add_178487_2381377266(&result0, ((NimStringDesc*) &T839829468_111)); add_178482_2381377266(&result0, (*s0).loc.r); } goto LA10; LA12: ; { TY532811 LOC23; memset((void*)LOC23, 0, sizeof(LOC23)); LOC23[0] = result0; LOC23[1] = (*s0).loc.r; result0 = HEX25_178905_2381377266((*(*s0).constraint).kindU.S3.strval, LOC23, 2); } LA10: ; return result0; } N_NIMCALL(void, initloc_532273_839829468)(Tloc292816* result0, Tlockind292808 k0, Ttype292840* typ0, Tstorageloc292812 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_539289_839829468)(Tcproc529021* p0, Tnode292802* e0, Tloc292816* result0) { initloc_532273_839829468(result0, ((Tlockind292808) 0), (*e0).typ, ((Tstorageloc292812) 0)); (*result0).flags |= ((NU16)1)<<((((Tlocflag292810) 8))%(sizeof(NU16)*8)); expr_539248_839829468(p0, e0, result0); } static N_INLINE(Ropeobj178006**, s_529179_3723162438)(Tcproc529021* p0, Tcprocsection529011 s0) { Ropeobj178006** result0; result0 = (Ropeobj178006**)0; result0 = &(*p0).blocks->data[(NI)(((*p0).blocks ? (*p0).blocks->Sup.len : 0) - ((NI) 1))].sections[(s0)- 0]; return result0; } N_NIMCALL(Ropeobj178006*, indentline_532656_839829468)(Tcproc529021* p0, Ropeobj178006* r0) { Ropeobj178006* result0; result0 = (Ropeobj178006*)0; result0 = r0; { NI i_532680_839829468; NI HEX3Atmp_532683_839829468; NI res_532686_839829468; i_532680_839829468 = (NI)0; HEX3Atmp_532683_839829468 = (NI)0; HEX3Atmp_532683_839829468 = (NI)(((*p0).blocks ? (*p0).blocks->Sup.len : 0) - ((NI) 1)); res_532686_839829468 = ((NI) 0); { while (1) { if (!(res_532686_839829468 <= HEX3Atmp_532683_839829468)) goto LA3; i_532680_839829468 = res_532686_839829468; prepend_178893_2381377266(&result0, indent_532655_839829468); res_532686_839829468 += ((NI) 1); } LA3: ; } } return result0; } N_NIMCALL(void, linefmt_532714_839829468)(Tcproc529021* p0, Tcprocsection529011 s0, NimStringDesc* frmt0, Ropeobj178006** args0, NI args0Len0) { Ropeobj178006** LOC1; Ropeobj178006* LOC2; Ropeobj178006* LOC3; LOC1 = (Ropeobj178006**)0; LOC1 = s_529179_3723162438(p0, s0); LOC2 = (Ropeobj178006*)0; LOC2 = ropecg_532407_839829468((*p0).module, frmt0, args0, args0Len0); LOC3 = (Ropeobj178006*)0; LOC3 = indentline_532656_839829468(p0, LOC2); add_178482_2381377266(LOC1, LOC3); } N_NIMCALL(Ropeobj178006*, rdloc_538188_839829468)(Tloc292816 a0) { Ropeobj178006* result0; result0 = (Ropeobj178006*)0; result0 = a0.r; { TY178507 LOC5; if (!((a0.flags &(1U<<((NU)(((Tlocflag292810) 0))&15U)))!=0)) goto LA3; memset((void*)LOC5, 0, sizeof(LOC5)); LOC5[0] = result0; result0 = HEX25_178905_2381377266(((NimStringDesc*) &T839829468_124), LOC5, 1); } LA3: ; return result0; } N_NIMCALL(void, line_532690_839829468)(Tcproc529021* p0, Tcprocsection529011 s0, Ropeobj178006* r0) { Ropeobj178006** LOC1; Ropeobj178006* LOC2; LOC1 = (Ropeobj178006**)0; LOC1 = s_529179_3723162438(p0, s0); LOC2 = (Ropeobj178006*)0; LOC2 = indentline_532656_839829468(p0, r0); add_178482_2381377266(LOC1, LOC2); } N_NIMCALL(void, linef_532700_839829468)(Tcproc529021* p0, Tcprocsection529011 s0, NimStringDesc* frmt0, Ropeobj178006** args0, NI args0Len0) { Ropeobj178006** LOC1; Ropeobj178006* LOC2; Ropeobj178006* LOC3; LOC1 = (Ropeobj178006**)0; LOC1 = s_529179_3723162438(p0, s0); LOC2 = (Ropeobj178006*)0; LOC2 = HEX25_178905_2381377266(frmt0, args0, args0Len0); LOC3 = (Ropeobj178006*)0; LOC3 = indentline_532656_839829468(p0, LOC2); add_178482_2381377266(LOC1, LOC3); } N_NIMCALL(void, gentypeinfoauxbase_535960_839829468)(Tcgen529027* m0, Ttype292840* typ0, Ttype292840* origtype0, Ropeobj178006* name0, Ropeobj178006* base0) { NI nimtypekind0; Ropeobj178006* size0; TY535235 LOC17; NI flags0; Ropeobj178006* LOC33; TY532811 LOC34; NimStringDesc* LOC35; nimtypekind0 = (NI)0; { NIM_BOOL LOC3; LOC3 = (NIM_BOOL)0; LOC3 = isobjlackingtypefield_533513_839829468(typ0); if (!LOC3) goto LA4; nimtypekind0 = ((NI) 18); } goto LA1; LA4: ; { nimtypekind0 = ((NI) ((*typ0).kind)); } LA1: ; size0 = (Ropeobj178006*)0; { if (!(((*typ0).flags &(1U<<((NU)(((Ttypeflag292431) 0))&31U)))!=0)) goto LA9; size0 = rope_178277_2381377266(((NimStringDesc*) &T839829468_133)); } goto LA7; LA9: ; { NIM_BOOL LOC12; LOC12 = (NIM_BOOL)0; LOC12 = (gcmd_169132_2607990831 == ((Tcommands169076) 2)); if (LOC12) goto LA13; LOC12 = (((*(*m0).module).flags &(1U<<((NU)(((Tsymflag292184) 27))&31U)))!=0); LA13: ; if (!LOC12) goto LA14; size0 = gettypedesc_535671_839829468(m0, origtype0); } goto LA7; LA14: ; { size0 = gettypedesc_535671_839829468(m0, typ0); } LA7: ; memset((void*)LOC17, 0, sizeof(LOC17)); LOC17[0] = name0; LOC17[1] = size0; LOC17[2] = rope_178401_2381377266(((NI64) (nimtypekind0))); LOC17[3] = base0; addf_179205_2381377266(&(*m0).s[(((Tcfilesection529005) 14))- 0], ((NimStringDesc*) &T839829468_134), LOC17, 4); flags0 = ((NI) 0); { NIM_BOOL LOC20; LOC20 = (NIM_BOOL)0; LOC20 = containsgarbagecollectedref_320117_3876443242(typ0); if (!!(LOC20)) goto LA21; flags0 = (NI)(flags0 | ((NI) 1)); } LA21: ; { NIM_BOOL LOC25; LOC25 = (NIM_BOOL)0; LOC25 = canformacycle_320123_3876443242(typ0); if (!!(LOC25)) goto LA26; flags0 = (NI)(flags0 | ((NI) 2)); } LA26: ; { TY532811 LOC32; if (!!((flags0 == ((NI) 0)))) goto LA30; memset((void*)LOC32, 0, sizeof(LOC32)); LOC32[0] = name0; LOC32[1] = rope_178401_2381377266(((NI64) (flags0))); addf_179205_2381377266(&(*m0).s[(((Tcfilesection529005) 14))- 0], ((NimStringDesc*) &T839829468_135), LOC32, 2); } LA30: ; LOC33 = (Ropeobj178006*)0; LOC33 = cgsym_532403_839829468(m0, ((NimStringDesc*) &T839829468_129)); memset((void*)LOC34, 0, sizeof(LOC34)); LOC34[0] = name0; LOC35 = (NimStringDesc*)0; LOC35 = typetostring_320017_3876443242(typ0, ((Tprefereddesc320011) 0)); LOC34[1] = rope_178277_2381377266(LOC35); addf_179205_2381377266(&(*m0).s[(((Tcfilesection529005) 9))- 0], ((NimStringDesc*) &T839829468_136), LOC34, 2); } N_NIMCALL(Ropeobj178006*, getnimnode_535945_839829468)(Tcgen529027* m0) { Ropeobj178006* result0; TY532811 LOC1; result0 = (Ropeobj178006*)0; memset((void*)LOC1, 0, sizeof(LOC1)); LOC1[0] = (*m0).typenodesname; LOC1[1] = rope_178401_2381377266(((NI64) ((*m0).typenodes))); result0 = HEX25_178905_2381377266(((NimStringDesc*) &T839829468_138), LOC1, 2); (*m0).typenodes += ((NI) 1); return result0; } N_NIMCALL(void, gentupleinfo_536549_839829468)(Tcgen529027* m0, Ttype292840* typ0, Ropeobj178006* name0) { Ropeobj178006* LOC1; Ropeobj178006* expr0; NI length0; TY532811 LOC15; LOC1 = (Ropeobj178006*)0; LOC1 = rope_178277_2381377266(((NimStringDesc*) &T839829468_18)); gentypeinfoauxbase_535960_839829468(m0, typ0, typ0, name0, LOC1); expr0 = getnimnode_535945_839829468(m0); length0 = sonslen_295327_850551059(typ0); { Ropeobj178006* tmp0; TY532811 LOC6; TY535238 LOC12; if (!(((NI) 0) < length0)) goto LA4; tmp0 = gettempname_533596_839829468(m0); memset((void*)LOC6, 0, sizeof(LOC6)); LOC6[0] = tmp0; LOC6[1] = rope_178401_2381377266(((NI64) (length0))); addf_179205_2381377266(&(*m0).s[(((Tcfilesection529005) 12))- 0], ((NimStringDesc*) &T839829468_139), LOC6, 2); { NI i_536571_839829468; NI HEX3Atmp_536590_839829468; NI res_536593_839829468; i_536571_839829468 = (NI)0; HEX3Atmp_536590_839829468 = (NI)0; HEX3Atmp_536590_839829468 = (NI)(length0 - ((NI) 1)); res_536593_839829468 = ((NI) 0); { while (1) { Ttype292840* a0; Ropeobj178006* tmp20; TY535238 LOC10; TY535235 LOC11; if (!(res_536593_839829468 <= HEX3Atmp_536590_839829468)) goto LA9; i_536571_839829468 = res_536593_839829468; a0 = (*typ0).sons->data[i_536571_839829468]; tmp20 = getnimnode_535945_839829468(m0); memset((void*)LOC10, 0, sizeof(LOC10)); LOC10[0] = tmp0; LOC10[1] = rope_178401_2381377266(((NI64) (i_536571_839829468))); LOC10[2] = tmp20; addf_179205_2381377266(&(*m0).s[(((Tcfilesection529005) 14))- 0], ((NimStringDesc*) &T839829468_140), LOC10, 3); memset((void*)LOC11, 0, sizeof(LOC11)); LOC11[0] = tmp20; LOC11[1] = gettypedesc_535671_839829468(m0, typ0); LOC11[2] = rope_178401_2381377266(((NI64) (i_536571_839829468))); LOC11[3] = gentypeinfo_535941_839829468(m0, a0); addf_179205_2381377266(&(*m0).s[(((Tcfilesection529005) 14))- 0], ((NimStringDesc*) &T839829468_141), LOC11, 4); res_536593_839829468 += ((NI) 1); } LA9: ; } } memset((void*)LOC12, 0, sizeof(LOC12)); LOC12[0] = expr0; LOC12[1] = rope_178401_2381377266(((NI64) (length0))); LOC12[2] = tmp0; addf_179205_2381377266(&(*m0).s[(((Tcfilesection529005) 14))- 0], ((NimStringDesc*) &T839829468_142), LOC12, 3); } goto LA2; LA4: ; { TY532811 LOC14; memset((void*)LOC14, 0, sizeof(LOC14)); LOC14[0] = expr0; LOC14[1] = rope_178401_2381377266(((NI64) (length0))); addf_179205_2381377266(&(*m0).s[(((Tcfilesection529005) 14))- 0], ((NimStringDesc*) &T839829468_143), LOC14, 2); } LA2: ; memset((void*)LOC15, 0, sizeof(LOC15)); LOC15[0] = name0; LOC15[1] = expr0; addf_179205_2381377266(&(*m0).s[(((Tcfilesection529005) 14))- 0], ((NimStringDesc*) &T839829468_144), LOC15, 2); } N_NIMCALL(Ttype292840*, fakeclosuretype_537010_839829468)(Tsym292834* owner0) { Ttype292840* result0; Ttype292840* LOC1; Ttype292840* r0; Ttype292840* LOC2; result0 = (Ttype292840*)0; result0 = newtype_295107_850551059(((Ttypekind292244) 18), owner0); LOC1 = (Ttype292840*)0; LOC1 = newtype_295107_850551059(((Ttypekind292244) 26), owner0); rawaddson_296394_850551059(result0, LOC1); r0 = newtype_295107_850551059(((Ttypekind292244) 22), owner0); LOC2 = (Ttype292840*)0; LOC2 = newtype_295107_850551059(((Ttypekind292244) 18), owner0); rawaddson_296394_850551059(r0, LOC2); rawaddson_296394_850551059(result0, r0); return result0; } N_NIMCALL(void, gentypeinfoaux_536027_839829468)(Tcgen529027* m0, Ttype292840* typ0, Ttype292840* origtype0, Ropeobj178006* name0) { Ropeobj178006* base0; base0 = (Ropeobj178006*)0; { NIM_BOOL LOC3; NI LOC4; Ttype292840* x0; LOC3 = (NIM_BOOL)0; LOC4 = (NI)0; LOC4 = sonslen_295327_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 == ((Ttypekind292244) 17))) goto LA10; x0 = skiptypes_296099_850551059(x0, IL64(211106247215360)); } LA10: ; base0 = gentypeinfo_535941_839829468(m0, x0); } goto LA1; LA6: ; { base0 = rope_178277_2381377266(((NimStringDesc*) &T839829468_18)); } LA1: ; gentypeinfoauxbase_535960_839829468(m0, typ0, origtype0, name0, base0); } static N_INLINE(NIM_BOOL, iscomplexvaluetype_538317_839829468)(Ttype292840* t0) { NIM_BOOL result0; NIM_BOOL LOC1; NIM_BOOL LOC3; result0 = (NIM_BOOL)0; LOC1 = (NIM_BOOL)0; LOC1 = ((*t0).kind == ((Ttypekind292244) 16) || (*t0).kind == ((Ttypekind292244) 4) || (*t0).kind == ((Ttypekind292244) 19) || (*t0).kind == ((Ttypekind292244) 18) || (*t0).kind == ((Ttypekind292244) 17)); if (LOC1) goto LA2; LOC3 = (NIM_BOOL)0; LOC3 = ((*t0).kind == ((Ttypekind292244) 25)); if (!(LOC3)) goto LA4; LOC3 = ((*t0).callconv == ((Tcallingconvention292002) 8)); LA4: ; LOC1 = LOC3; LA2: ; result0 = LOC1; return result0; } N_NIMCALL(void, usestringh_532345_839829468)(Tcgen529027* m0) { { NIM_BOOL LOC5; if (!!((((*m0).flags &(1U<<((NU)(((Codegenflag529025) 4))&7U)))!=0))) goto LA3; (*m0).flags |= ((NU8)1)<<((((Codegenflag529025) 4))%(sizeof(NU8)*8)); LOC5 = (NIM_BOOL)0; LOC5 = includestr_147249_3771138726((&(*m0).headerfiles), ((NimStringDesc*) &T839829468_151)); } LA3: ; } N_NIMCALL(Ropeobj178006*, addrloc_538204_839829468)(Tloc292816 a0) { Ropeobj178006* result0; result0 = (Ropeobj178006*)0; result0 = a0.r; { NIM_BOOL LOC3; Tctypekind529007 LOC5; Ropeobj178006* LOC8; LOC3 = (NIM_BOOL)0; LOC3 = !(((a0.flags &(1U<<((NU)(((Tlocflag292810) 0))&15U)))!=0)); if (!(LOC3)) goto LA4; LOC5 = (Tctypekind529007)0; LOC5 = maptype_533393_839829468(a0.t); LOC3 = !((LOC5 == ((Tctypekind529007) 17))); LA4: ; if (!LOC3) goto LA6; LOC8 = (Ropeobj178006*)0; LOC8 = HEX26_178452_2381377266(((NimStringDesc*) &T839829468_128), result0); result0 = HEX26_178447_2381377266(LOC8, ((NimStringDesc*) &T839829468_117)); } LA6: ; return result0; } N_NIMCALL(void, genobjectinit_538242_839829468)(Tcproc529021* p0, Tcprocsection529011 section0, Ttype292840* t0, Tloc292816 a0, NIM_BOOL takeaddr0) { Ttypefieldresult320145 LOC1; LOC1 = (Ttypefieldresult320145)0; LOC1 = analyseobjectwithtypefield_320149_3876443242(t0); switch (LOC1) { case ((Ttypefieldresult320145) 0): { } break; case ((Ttypefieldresult320145) 1): { Ropeobj178006* r0; Ttype292840* s0; TY532811 LOC19; r0 = rdloc_538188_839829468(a0); { TY178507 LOC8; if (!!(takeaddr0)) goto LA6; memset((void*)LOC8, 0, sizeof(LOC8)); LOC8[0] = r0; r0 = HEX25_178905_2381377266(((NimStringDesc*) &T839829468_124), LOC8, 1); } LA6: ; s0 = skiptypes_296099_850551059(t0, IL64(211106232576256)); { NIM_BOOL LOC11; LOC11 = (NIM_BOOL)0; LOC11 = (gcmd_169132_2607990831 == ((Tcommands169076) 2)); if (LOC11) goto LA12; LOC11 = (((*(*(*p0).module).module).flags &(1U<<((NU)(((Tsymflag292184) 27))&31U)))!=0); LA12: ; if (!!(LOC11)) goto LA13; { while (1) { NIM_BOOL LOC17; LOC17 = (NIM_BOOL)0; LOC17 = ((*s0).kind == ((Ttypekind292244) 17)); if (!(LOC17)) goto LA18; LOC17 = !(((*s0).sons->data[((NI) 0)] == NIM_NIL)); LA18: ; if (!LOC17) goto LA16; add_178487_2381377266(&r0, ((NimStringDesc*) &T839829468_153)); s0 = skiptypes_296099_850551059((*s0).sons->data[((NI) 0)], IL64(211106247215360)); } LA16: ; } } LA13: ; memset((void*)LOC19, 0, sizeof(LOC19)); LOC19[0] = r0; LOC19[1] = gentypeinfo_535941_839829468((*p0).module, t0); linefmt_532714_839829468(p0, section0, ((NimStringDesc*) &T839829468_154), LOC19, 2); } break; case ((Ttypefieldresult320145) 2): { Ropeobj178006* r0; TY532811 LOC26; { if (!takeaddr0) goto LA23; r0 = addrloc_538204_839829468(a0); } goto LA21; LA23: ; { r0 = rdloc_538188_839829468(a0); } LA21: ; memset((void*)LOC26, 0, sizeof(LOC26)); LOC26[0] = r0; LOC26[1] = gentypeinfo_535941_839829468((*p0).module, t0); linefmt_532714_839829468(p0, section0, ((NimStringDesc*) &T839829468_155), LOC26, 2); } break; } } N_NIMCALL(void, constructloc_538388_839829468)(Tcproc529021* p0, Tloc292816 loc0, NIM_BOOL istemp0) { Ttype292840* typ0; typ0 = skiptypes_296099_850551059(loc0.t, IL64(211106233624832)); { NIM_BOOL LOC3; TY532811 LOC6; LOC3 = (NIM_BOOL)0; LOC3 = iscomplexvaluetype_538317_839829468(typ0); if (!!(LOC3)) goto LA4; memset((void*)LOC6, 0, sizeof(LOC6)); LOC6[0] = rdloc_538188_839829468(loc0); LOC6[1] = gettypedesc_535671_839829468((*p0).module, typ0); linefmt_532714_839829468(p0, ((Tcprocsection529011) 2), ((NimStringDesc*) &T839829468_150), LOC6, 2); } goto LA1; LA4: ; { { NIM_BOOL LOC10; LOC10 = (NIM_BOOL)0; LOC10 = !(istemp0); if (LOC10) goto LA11; LOC10 = containsgarbagecollectedref_320117_3876443242(loc0.t); LA11: ; if (!LOC10) goto LA12; { NIM_BOOL LOC16; TY532811 LOC19; LOC16 = (NIM_BOOL)0; LOC16 = isimportedcpptype_533476_839829468(typ0); if (!!(LOC16)) goto LA17; usestringh_532345_839829468((*p0).module); memset((void*)LOC19, 0, sizeof(LOC19)); LOC19[0] = addrloc_538204_839829468(loc0); LOC19[1] = rdloc_538188_839829468(loc0); linefmt_532714_839829468(p0, ((Tcprocsection529011) 2), ((NimStringDesc*) &T839829468_152), LOC19, 2); } LA17: ; } LA12: ; genobjectinit_538242_839829468(p0, ((Tcprocsection529011) 2), loc0.t, loc0, NIM_TRUE); } LA1: ; } N_NIMCALL(void, gettemp_537032_839829468)(Tcproc529021* p0, Ttype292840* t0, Tloc292816* result0, NIM_BOOL needsinit0) { Ropeobj178006* LOC1; TY532811 LOC2; (*p0).labels += ((NI) 1); LOC1 = (Ropeobj178006*)0; LOC1 = rope_178401_2381377266(((NI64) ((*p0).labels))); unsureAsgnRef((void**) (&(*result0).r), HEX26_178452_2381377266(((NimStringDesc*) &T839829468_149), LOC1)); memset((void*)LOC2, 0, sizeof(LOC2)); LOC2[0] = gettypedesc_535671_839829468((*p0).module, t0); LOC2[1] = (*result0).r; linefmt_532714_839829468(p0, ((Tcprocsection529011) 0), ((NimStringDesc*) &T839829468_54), LOC2, 2); (*result0).k = ((Tlockind292808) 1); unsureAsgnRef((void**) (&(*result0).t), t0); (*result0).s = ((Tstorageloc292812) 2); (*result0).flags = 0; constructloc_538388_839829468(p0, (*result0), !(needsinit0)); } static N_INLINE(Ropeobj178006*, parentobj_537257_839829468)(Ropeobj178006* accessor0, Tcgen529027* m0) { Ropeobj178006* result0; result0 = (Ropeobj178006*)0; { NIM_BOOL LOC3; TY178507 LOC7; LOC3 = (NIM_BOOL)0; LOC3 = (gcmd_169132_2607990831 == ((Tcommands169076) 2)); if (LOC3) goto LA4; LOC3 = (((*(*m0).module).flags &(1U<<((NU)(((Tsymflag292184) 27))&31U)))!=0); LA4: ; if (!!(LOC3)) goto LA5; memset((void*)LOC7, 0, sizeof(LOC7)); LOC7[0] = accessor0; result0 = HEX25_178905_2381377266(((NimStringDesc*) &T839829468_161), LOC7, 1); } goto LA1; LA5: ; { result0 = accessor0; } LA1: ; return result0; } N_NIMCALL(Ropeobj178006*, intliteral_539270_839829468)(NI64 i0) { Ropeobj178006* result0; result0 = (Ropeobj178006*)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_178401_2381377266(i0); } goto LA1; LA5: ; { TY533289 LOC10; if (!(i0 == IL64(-2147483648))) goto LA8; memset((void*)LOC10, 0, sizeof(LOC10)); result0 = HEX25_178905_2381377266(((NimStringDesc*) &T839829468_166), LOC10, 0); } goto LA1; LA8: ; { TY178507 LOC14; if (!((IL64(-9223372036854775807) - IL64(1)) < i0)) goto LA12; memset((void*)LOC14, 0, sizeof(LOC14)); LOC14[0] = rope_178401_2381377266(i0); result0 = ropecg_532407_839829468(NIM_NIL, ((NimStringDesc*) &T839829468_167), LOC14, 1); } goto LA1; LA12: ; { TY533289 LOC16; memset((void*)LOC16, 0, sizeof(LOC16)); result0 = HEX25_178905_2381377266(((NimStringDesc*) &T839829468_168), LOC16, 0); } LA1: ; return result0; } N_NIMCALL(Ropeobj178006*, int64literal_549430_839829468)(NI64 i0) { Ropeobj178006* result0; result0 = (Ropeobj178006*)0; { TY178507 LOC5; if (!((IL64(-9223372036854775807) - IL64(1)) < i0)) goto LA3; memset((void*)LOC5, 0, sizeof(LOC5)); LOC5[0] = rope_178401_2381377266(i0); result0 = ropecg_532407_839829468(NIM_NIL, ((NimStringDesc*) &T839829468_167), LOC5, 1); } goto LA1; LA3: ; { TY533289 LOC7; memset((void*)LOC7, 0, sizeof(LOC7)); result0 = HEX25_178905_2381377266(((NimStringDesc*) &T839829468_168), LOC7, 0); } LA1: ; return result0; } N_NIMCALL(Ropeobj178006*, uint64literal_549442_839829468)(NU64 i0) { Ropeobj178006* result0; NimStringDesc* LOC1; NimStringDesc* LOC2; result0 = (Ropeobj178006*)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_178277_2381377266(LOC1); return result0; } N_NIMCALL(Ropeobj178006*, getstrlit_549468_839829468)(Tcgen529027* m0, NimStringDesc* s0) { Ropeobj178006* result0; Ropeobj178006* LOC1; TY535238 LOC2; result0 = (Ropeobj178006*)0; LOC1 = (Ropeobj178006*)0; LOC1 = cgsym_532403_839829468(m0, ((NimStringDesc*) &T839829468_79)); result0 = gettempname_533596_839829468(m0); memset((void*)LOC2, 0, sizeof(LOC2)); LOC2[0] = result0; LOC2[1] = makecstring_191638_155036129(s0); LOC2[2] = rope_178401_2381377266(((NI64) ((s0 ? s0->Sup.len : 0)))); addf_179205_2381377266(&(*m0).s[(((Tcfilesection529005) 8))- 0], ((NimStringDesc*) &T839829468_177), LOC2, 3); return result0; } N_NIMCALL(Ropeobj178006*, genliteral_549476_839829468)(Tcproc529021* p0, Tnode292802* n0, Ttype292840* ty0) { Ropeobj178006* result0; result0 = (Ropeobj178006*)0; { if (!(ty0 == NIM_NIL)) goto LA3; internalerror_196100_155036129((*n0).info, ((NimStringDesc*) &T839829468_165)); } LA3: ; switch ((*n0).kind) { case ((Tnodekind292020) 5) ... ((Tnodekind292020) 15): { Ttype292840* LOC6; LOC6 = (Ttype292840*)0; LOC6 = skiptypes_296099_850551059(ty0, IL64(211106242013440)); switch ((*LOC6).kind) { case ((Ttypekind292244) 2): case ((Ttypekind292244) 5): { result0 = intliteral_539270_839829468((*n0).kindU.S1.intval); } break; case ((Ttypekind292244) 1): { { TY533289 LOC13; if (!!(((*n0).kindU.S1.intval == IL64(0)))) goto LA11; memset((void*)LOC13, 0, sizeof(LOC13)); result0 = HEX25_178905_2381377266(((NimStringDesc*) &T839829468_169), LOC13, 0); } goto LA9; LA11: ; { TY533289 LOC15; memset((void*)LOC15, 0, sizeof(LOC15)); result0 = HEX25_178905_2381377266(((NimStringDesc*) &T839829468_170), LOC15, 0); } LA9: ; } break; case ((Ttypekind292244) 35): { result0 = int64literal_549430_839829468((*n0).kindU.S1.intval); } break; case ((Ttypekind292244) 44): { result0 = uint64literal_549442_839829468(((NU64) ((*n0).kindU.S1.intval))); } break; default: { TY532811 LOC19; Ttype292840* LOC20; memset((void*)LOC19, 0, sizeof(LOC19)); LOC20 = (Ttype292840*)0; LOC20 = skiptypes_296099_850551059(ty0, IL64(211106242013440)); LOC19[0] = gettypedesc_535671_839829468((*p0).module, LOC20); LOC19[1] = intliteral_539270_839829468((*n0).kindU.S1.intval); result0 = HEX25_178905_2381377266(((NimStringDesc*) &T839829468_172), LOC19, 2); } break; } } break; case ((Tnodekind292020) 23): { Ttype292840* t0; t0 = skiptypes_296099_850551059(ty0, IL64(211106242013440)); { NIM_BOOL LOC24; NI id0; Ropeobj178006* LOC28; LOC24 = (NIM_BOOL)0; LOC24 = ((*t0).kind == ((Ttypekind292244) 25)); if (!(LOC24)) goto LA25; LOC24 = ((*t0).callconv == ((Tcallingconvention292002) 8)); LA25: ; if (!LOC24) goto LA26; id0 = nodetabletestorset_342682_1142335848((&(*(*p0).module).datacache), n0, ((NI) ((*(*p0).module).labels))); LOC28 = (Ropeobj178006*)0; LOC28 = rope_178401_2381377266(((NI64) (id0))); result0 = HEX26_178418_2381377266((*(*p0).module).tmpbase, LOC28); { TY532811 LOC33; if (!(id0 == ((NI) ((*(*p0).module).labels)))) goto LA31; (*(*p0).module).labels += ((NI) 1); memset((void*)LOC33, 0, sizeof(LOC33)); LOC33[0] = gettypedesc_535671_839829468((*p0).module, t0); LOC33[1] = result0; addf_179205_2381377266(&(*(*p0).module).s[(((Tcfilesection529005) 8))- 0], ((NimStringDesc*) &T839829468_173), LOC33, 2); } LA31: ; } goto LA22; LA26: ; { result0 = rope_178277_2381377266(((NimStringDesc*) &T839829468_174)); } LA22: ; } break; case ((Tnodekind292020) 20) ... ((Tnodekind292020) 22): { { TY533289 LOC40; if (!(*n0).kindU.S3.strval == 0) goto LA38; memset((void*)LOC40, 0, sizeof(LOC40)); result0 = ropecg_532407_839829468((*p0).module, ((NimStringDesc*) &T839829468_175), LOC40, 0); } goto LA36; LA38: ; { Ttype292840* LOC42; NI id0; LOC42 = (Ttype292840*)0; LOC42 = skiptypes_296099_850551059(ty0, IL64(211106242013440)); if (!((*LOC42).kind == ((Ttypekind292244) 28))) goto LA43; id0 = nodetabletestorset_342682_1142335848((&(*(*p0).module).datacache), n0, ((NI) ((*(*p0).module).labels))); { TY178507 LOC49; if (!(id0 == ((NI) ((*(*p0).module).labels)))) goto LA47; memset((void*)LOC49, 0, sizeof(LOC49)); LOC49[0] = getstrlit_549468_839829468((*p0).module, (*n0).kindU.S3.strval); result0 = ropecg_532407_839829468((*p0).module, ((NimStringDesc*) &T839829468_176), LOC49, 1); } goto LA45; LA47: ; { TY532811 LOC51; memset((void*)LOC51, 0, sizeof(LOC51)); LOC51[0] = (*(*p0).module).tmpbase; LOC51[1] = rope_178401_2381377266(((NI64) (id0))); result0 = ropecg_532407_839829468((*p0).module, ((NimStringDesc*) &T839829468_178), LOC51, 2); } LA45: ; } goto LA36; LA43: ; { result0 = makecstring_191638_155036129((*n0).kindU.S3.strval); } LA36: ; } break; case ((Tnodekind292020) 16) ... ((Tnodekind292020) 18): { NimStringDesc* LOC54; LOC54 = (NimStringDesc*)0; LOC54 = tostrmaxprecision_298007_3471544153((*n0).kindU.S2.floatval); result0 = rope_178277_2381377266(LOC54); } break; default: { NimStringDesc* LOC56; LOC56 = (NimStringDesc*)0; LOC56 = rawNewString(reprEnum((NI)(*n0).kind, (&NTI292020))->Sup.len + 12); appendString(LOC56, ((NimStringDesc*) &T839829468_179)); appendString(LOC56, reprEnum((NI)(*n0).kind, (&NTI292020))); appendChar(LOC56, 41); internalerror_196100_155036129((*n0).info, LOC56); result0 = NIM_NIL; } break; } return result0; } N_NIMCALL(Ropeobj178006*, genliteral_539273_839829468)(Tcproc529021* p0, Tnode292802* n0) { Ropeobj178006* result0; result0 = (Ropeobj178006*)0; result0 = genliteral_549476_839829468(p0, n0, (*n0).typ); return result0; } N_NIMCALL(void, gencaserange_537028_839829468)(Tcproc529021* p0, Tnode292802* branch0) { NI length0; length0 = len_293081_850551059(branch0); { NI j_547676_839829468; NI HEX3Atmp_547717_839829468; NI res_547720_839829468; j_547676_839829468 = (NI)0; HEX3Atmp_547717_839829468 = (NI)0; HEX3Atmp_547717_839829468 = (NI)(length0 - ((NI) 2)); res_547720_839829468 = ((NI) 0); { while (1) { if (!(res_547720_839829468 <= HEX3Atmp_547717_839829468)) goto LA3; j_547676_839829468 = res_547720_839829468; { Tnode292802* LOC6; LOC6 = (Tnode292802*)0; LOC6 = HEX5BHEX5D_293238_850551059(branch0, j_547676_839829468); if (!((*LOC6).kind == ((Tnodekind292020) 44))) goto LA7; { TY532811 LOC13; Tnode292802* LOC14; Tnode292802* LOC15; Tnode292802* LOC16; Tnode292802* LOC17; if (!((Cc_273413_2528170400[(ccompiler_273431_2528170400)- 1].Field20 &(1U<<((NU)(((Tinfoccprop273004) 0))&7U)))!=0)) goto LA11; memset((void*)LOC13, 0, sizeof(LOC13)); LOC14 = (Tnode292802*)0; LOC14 = HEX5BHEX5D_293238_850551059(branch0, j_547676_839829468); LOC15 = (Tnode292802*)0; LOC15 = HEX5BHEX5D_293238_850551059(LOC14, ((NI) 0)); LOC13[0] = genliteral_539273_839829468(p0, LOC15); LOC16 = (Tnode292802*)0; LOC16 = HEX5BHEX5D_293238_850551059(branch0, j_547676_839829468); LOC17 = (Tnode292802*)0; LOC17 = HEX5BHEX5D_293238_850551059(LOC16, ((NI) 1)); LOC13[1] = genliteral_539273_839829468(p0, LOC17); linef_532700_839829468(p0, ((Tcprocsection529011) 2), ((NimStringDesc*) &T839829468_164), LOC13, 2); } goto LA9; LA11: ; { Tnode292802* v0; Tnode292802* LOC19; Tnode292802* LOC20; LOC19 = (Tnode292802*)0; LOC19 = HEX5BHEX5D_293238_850551059(branch0, j_547676_839829468); LOC20 = (Tnode292802*)0; LOC20 = HEX5BHEX5D_293238_850551059(LOC19, ((NI) 0)); v0 = copynode_296528_850551059(LOC20); { while (1) { Tnode292802* LOC23; Tnode292802* LOC24; TY178507 LOC25; LOC23 = (Tnode292802*)0; LOC23 = HEX5BHEX5D_293238_850551059(branch0, j_547676_839829468); LOC24 = (Tnode292802*)0; LOC24 = HEX5BHEX5D_293238_850551059(LOC23, ((NI) 1)); if (!((*v0).kindU.S1.intval <= (*LOC24).kindU.S1.intval)) goto LA22; memset((void*)LOC25, 0, sizeof(LOC25)); LOC25[0] = genliteral_539273_839829468(p0, v0); linef_532700_839829468(p0, ((Tcprocsection529011) 2), ((NimStringDesc*) &T839829468_180), LOC25, 1); (*v0).kindU.S1.intval += ((NI) 1); } LA22: ; } } LA9: ; } goto LA4; LA7: ; { TY178507 LOC27; Tnode292802* LOC28; memset((void*)LOC27, 0, sizeof(LOC27)); LOC28 = (Tnode292802*)0; LOC28 = HEX5BHEX5D_293238_850551059(branch0, j_547676_839829468); LOC27[0] = genliteral_539273_839829468(p0, LOC28); linef_532700_839829468(p0, ((Tcprocsection529011) 2), ((NimStringDesc*) &T839829468_180), LOC27, 1); } LA4: ; res_547720_839829468 += ((NI) 1); } LA3: ; } } } N_NIMCALL(void, gentraverseproc_537039_839829468)(Ttraversalclosure537019* c0, Ropeobj178006* accessor0, Tnode292802* n0) { { { if (!(n0 == NIM_NIL)) goto LA3; goto BeforeRet; } LA3: ; switch ((*n0).kind) { case ((Tnodekind292020) 138): { { NI i_537068_839829468; NI HEX3Atmp_537239_839829468; NI LOC7; NI res_537242_839829468; i_537068_839829468 = (NI)0; HEX3Atmp_537239_839829468 = (NI)0; LOC7 = (NI)0; LOC7 = sonslen_295351_850551059(n0); HEX3Atmp_537239_839829468 = (NI)(LOC7 - ((NI) 1)); res_537242_839829468 = ((NI) 0); { while (1) { if (!(res_537242_839829468 <= HEX3Atmp_537239_839829468)) goto LA9; i_537068_839829468 = res_537242_839829468; gentraverseproc_537039_839829468(c0, accessor0, (*n0).kindU.S6.sons->data[i_537068_839829468]); res_537242_839829468 += ((NI) 1); } LA9: ; } } } break; case ((Tnodekind292020) 139): { Tcproc529021* p0; Tsym292834* disc0; TY532811 LOC15; TY533289 LOC28; { if (!!(((*(*n0).kindU.S6.sons->data[((NI) 0)]).kind == ((Tnodekind292020) 3)))) goto LA13; internalerror_196100_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_532700_839829468(p0, ((Tcprocsection529011) 2), ((NimStringDesc*) &T839829468_163), LOC15, 2); { NI i_537098_839829468; NI HEX3Atmp_537249_839829468; NI LOC17; NI res_537252_839829468; i_537098_839829468 = (NI)0; HEX3Atmp_537249_839829468 = (NI)0; LOC17 = (NI)0; LOC17 = sonslen_295351_850551059(n0); HEX3Atmp_537249_839829468 = (NI)(LOC17 - ((NI) 1)); res_537252_839829468 = ((NI) 1); { while (1) { Tnode292802* branch0; Tnode292802* LOC26; TY533289 LOC27; if (!(res_537252_839829468 <= HEX3Atmp_537249_839829468)) goto LA19; i_537098_839829468 = res_537252_839829468; branch0 = (*n0).kindU.S6.sons->data[i_537098_839829468]; { if (!((*branch0).kind == ((Tnodekind292020) 85))) goto LA22; gencaserange_537028_839829468((*c0).p, branch0); } goto LA20; LA22: ; { TY533289 LOC25; memset((void*)LOC25, 0, sizeof(LOC25)); linef_532700_839829468(p0, ((Tcprocsection529011) 2), ((NimStringDesc*) &T839829468_181), LOC25, 0); } LA20: ; LOC26 = (Tnode292802*)0; LOC26 = lastson_295364_850551059(branch0); gentraverseproc_537039_839829468(c0, accessor0, LOC26); memset((void*)LOC27, 0, sizeof(LOC27)); linef_532700_839829468(p0, ((Tcprocsection529011) 2), ((NimStringDesc*) &T839829468_182), LOC27, 0); res_537252_839829468 += ((NI) 1); } LA19: ; } } memset((void*)LOC28, 0, sizeof(LOC28)); linef_532700_839829468(p0, ((Tcprocsection529011) 2), ((NimStringDesc*) &T839829468_183), LOC28, 0); } break; case ((Tnodekind292020) 3): { Tsym292834* field0; TY532811 LOC34; Ropeobj178006* LOC35; field0 = (*n0).kindU.S4.sym; { if (!((*field0).loc.t == NIM_NIL)) goto LA32; internalerror_196100_155036129((*n0).info, ((NimStringDesc*) &T839829468_184)); } LA32: ; memset((void*)LOC34, 0, sizeof(LOC34)); LOC34[0] = accessor0; LOC34[1] = (*field0).loc.r; LOC35 = (Ropeobj178006*)0; LOC35 = HEX25_178905_2381377266(((NimStringDesc*) &T839829468_90), LOC34, 2); gentraverseproc_537022_839829468(c0, LOC35, (*field0).loc.t); } break; default: { internalerror_196100_155036129((*n0).info, ((NimStringDesc*) &T839829468_184)); } break; } }BeforeRet: ; } N_NIMCALL(void, linecg_532707_839829468)(Tcproc529021* p0, Tcprocsection529011 s0, NimStringDesc* frmt0, Ropeobj178006** args0, NI args0Len0) { Ropeobj178006** LOC1; Ropeobj178006* LOC2; Ropeobj178006* LOC3; LOC1 = (Ropeobj178006**)0; LOC1 = s_529179_3723162438(p0, s0); LOC2 = (Ropeobj178006*)0; LOC2 = ropecg_532407_839829468((*p0).module, frmt0, args0, args0Len0); LOC3 = (Ropeobj178006*)0; LOC3 = indentline_532656_839829468(p0, LOC2); add_178482_2381377266(LOC1, LOC3); } N_NIMCALL(void, gentraverseproc_537022_839829468)(Ttraversalclosure537019* c0, Ropeobj178006* accessor0, Ttype292840* typ_537027_839829468) { Ttype292840* typ_537302_839829468; Tcproc529021* p0; { { if (!(typ_537027_839829468 == NIM_NIL)) goto LA3; goto BeforeRet; } LA3: ; typ_537302_839829468 = getuniquetype_528640_2036603609(typ_537027_839829468); p0 = (*c0).p; switch ((*typ_537302_839829468).kind) { case ((Ttypekind292244) 11): case ((Ttypekind292244) 10): case ((Ttypekind292244) 8): { Ttype292840* LOC6; LOC6 = (Ttype292840*)0; LOC6 = lastson_295377_850551059(typ_537302_839829468); gentraverseproc_537022_839829468(c0, accessor0, LOC6); } break; case ((Ttypekind292244) 4): case ((Ttypekind292244) 16): { NI64 arraysize0; Tloc292816 i0; Ttype292840* LOC8; TY532811 LOC9; TY532811 LOC10; Ropeobj178006* LOC11; TY533289 LOC12; arraysize0 = lengthord_320007_3876443242((*typ_537302_839829468).sons->data[((NI) 0)]); memset((void*)(&i0), 0, sizeof(i0)); LOC8 = (Ttype292840*)0; LOC8 = getsystype_338150_3937434831(((Ttypekind292244) 31)); gettemp_537032_839829468(p0, LOC8, (&i0), NIM_FALSE); memset((void*)LOC9, 0, sizeof(LOC9)); LOC9[0] = i0.r; LOC9[1] = rope_178401_2381377266(arraysize0); linefmt_532714_839829468(p0, ((Tcprocsection529011) 2), ((NimStringDesc*) &T839829468_159), LOC9, 2); memset((void*)LOC10, 0, sizeof(LOC10)); LOC10[0] = accessor0; LOC10[1] = i0.r; LOC11 = (Ropeobj178006*)0; LOC11 = ropecg_532407_839829468(NIM_NIL, ((NimStringDesc*) &T839829468_138), LOC10, 2); gentraverseproc_537022_839829468(c0, LOC11, (*typ_537302_839829468).sons->data[((NI) 1)]); memset((void*)LOC12, 0, sizeof(LOC12)); linef_532700_839829468(p0, ((Tcprocsection529011) 2), ((NimStringDesc*) &T839829468_160), LOC12, 0); } break; case ((Ttypekind292244) 17): { { NI i_537325_839829468; NI HEX3Atmp_537384_839829468; NI LOC15; NI res_537387_839829468; i_537325_839829468 = (NI)0; HEX3Atmp_537384_839829468 = (NI)0; LOC15 = (NI)0; LOC15 = sonslen_295327_850551059(typ_537302_839829468); HEX3Atmp_537384_839829468 = (NI)(LOC15 - ((NI) 1)); res_537387_839829468 = ((NI) 0); { while (1) { Ttype292840* x0; Ropeobj178006* LOC22; if (!(res_537387_839829468 <= HEX3Atmp_537384_839829468)) goto LA17; i_537325_839829468 = res_537387_839829468; x0 = (*typ_537302_839829468).sons->data[i_537325_839829468]; { if (!!((x0 == NIM_NIL))) goto LA20; x0 = skiptypes_296099_850551059(x0, IL64(211106247215360)); } LA20: ; LOC22 = (Ropeobj178006*)0; LOC22 = parentobj_537257_839829468(accessor0, (*(*c0).p).module); gentraverseproc_537022_839829468(c0, LOC22, x0); res_537387_839829468 += ((NI) 1); } LA17: ; } } { if (!!(((*typ_537302_839829468).n == NIM_NIL))) goto LA25; gentraverseproc_537039_839829468(c0, accessor0, (*typ_537302_839829468).n); } LA25: ; } break; case ((Ttypekind292244) 18): { Ttype292840* typ0; typ0 = getuniquetype_528640_2036603609(typ_537302_839829468); { NI i_537363_839829468; NI HEX3Atmp_537392_839829468; NI LOC29; NI res_537395_839829468; i_537363_839829468 = (NI)0; HEX3Atmp_537392_839829468 = (NI)0; LOC29 = (NI)0; LOC29 = sonslen_295327_850551059(typ0); HEX3Atmp_537392_839829468 = (NI)(LOC29 - ((NI) 1)); res_537395_839829468 = ((NI) 0); { while (1) { TY532811 LOC32; Ropeobj178006* LOC33; if (!(res_537395_839829468 <= HEX3Atmp_537392_839829468)) goto LA31; i_537363_839829468 = res_537395_839829468; memset((void*)LOC32, 0, sizeof(LOC32)); LOC32[0] = accessor0; LOC32[1] = rope_178401_2381377266(((NI64) (i_537363_839829468))); LOC33 = (Ropeobj178006*)0; LOC33 = ropecg_532407_839829468(NIM_NIL, ((NimStringDesc*) &T839829468_185), LOC32, 2); gentraverseproc_537022_839829468(c0, LOC33, (*typ0).sons->data[i_537363_839829468]); res_537395_839829468 += ((NI) 1); } LA31: ; } } } break; case ((Ttypekind292244) 22): case ((Ttypekind292244) 28): case ((Ttypekind292244) 24): { TY178507 LOC35; memset((void*)LOC35, 0, sizeof(LOC35)); LOC35[0] = accessor0; linecg_532707_839829468(p0, ((Tcprocsection529011) 2), (*c0).visitorfrmt, LOC35, 1); } break; case ((Ttypekind292244) 25): { { TY178507 LOC41; TY178507 LOC42; if (!((*typ_537302_839829468).callconv == ((Tcallingconvention292002) 8))) goto LA39; memset((void*)LOC41, 0, sizeof(LOC41)); memset((void*)LOC42, 0, sizeof(LOC42)); LOC42[0] = accessor0; LOC41[0] = ropecg_532407_839829468(NIM_NIL, ((NimStringDesc*) &T839829468_186), LOC42, 1); linecg_532707_839829468(p0, ((Tcprocsection529011) 2), (*c0).visitorfrmt, LOC41, 1); } LA39: ; } break; default: { } break; } }BeforeRet: ; } N_NIMCALL(void, gentraverseprocseq_537399_839829468)(Ttraversalclosure537019* c0, Ropeobj178006* accessor0, Ttype292840* typ0) { Tcproc529021* p0; Tloc292816 i0; Ttype292840* LOC1; TY535238 LOC2; NimStringDesc* LOC3; TY532811 LOC11; Ropeobj178006* LOC12; TY533289 LOC13; p0 = (*c0).p; memset((void*)(&i0), 0, sizeof(i0)); LOC1 = (Ttype292840*)0; LOC1 = getsystype_338150_3937434831(((Ttypekind292244) 31)); gettemp_537032_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_169132_2607990831 == ((Tcommands169076) 2)); if (LOC6) goto LA7; LOC6 = (((*(*(*(*c0).p).module).module).flags &(1U<<((NU)(((Tsymflag292184) 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_178277_2381377266(LOC3); linef_532700_839829468(p0, ((Tcprocsection529011) 2), ((NimStringDesc*) &T839829468_156), LOC2, 3); memset((void*)LOC11, 0, sizeof(LOC11)); LOC11[0] = accessor0; LOC11[1] = i0.r; LOC12 = (Ropeobj178006*)0; LOC12 = HEX25_178905_2381377266(((NimStringDesc*) &T839829468_187), LOC11, 2); gentraverseproc_537022_839829468(c0, LOC12, (*typ0).sons->data[((NI) 0)]); memset((void*)LOC13, 0, sizeof(LOC13)); linef_532700_839829468(p0, ((Tcprocsection529011) 2), ((NimStringDesc*) &T839829468_160), LOC13, 0); } N_NIMCALL(Ropeobj178006*, gentraverseproc_537632_839829468)(Tcgen529027* m0, Ttype292840* typ0, Ttypeinforeason537016 reason0) { Ropeobj178006* result0; Ttraversalclosure537019 c0; Tcproc529021* p0; Ropeobj178006* header0; TY178507 LOC3; Ropeobj178006* t0; TY178507 LOC4; TY178507 LOC5; Ropeobj178006* generatedproc0; TY535235 LOC20; Ropeobj178006** LOC21; Ropeobj178006** LOC22; Ropeobj178006** LOC23; TY178507 LOC24; result0 = (Ropeobj178006*)0; memset((void*)(&c0), 0, sizeof(c0)); p0 = newproc_529206_3723162438(NIM_NIL, m0); result0 = gettempname_533596_839829468(m0); switch (reason0) { case ((Ttypeinforeason537016) 0): { c0.visitorfrmt = copyString(((NimStringDesc*) &T839829468_145)); } break; default: { } break; } memset((void*)LOC3, 0, sizeof(LOC3)); LOC3[0] = result0; header0 = HEX25_178905_2381377266(((NimStringDesc*) &T839829468_146), LOC3, 1); t0 = gettypedesc_535671_839829468(m0, typ0); memset((void*)LOC4, 0, sizeof(LOC4)); LOC4[0] = t0; linef_532700_839829468(p0, ((Tcprocsection529011) 0), ((NimStringDesc*) &T839829468_147), LOC4, 1); memset((void*)LOC5, 0, sizeof(LOC5)); LOC5[0] = t0; linef_532700_839829468(p0, ((Tcprocsection529011) 1), ((NimStringDesc*) &T839829468_148), LOC5, 1); c0.p = p0; { Ropeobj178006* LOC10; if (!((*typ0).kind == ((Ttypekind292244) 24))) goto LA8; LOC10 = (Ropeobj178006*)0; LOC10 = rope_178277_2381377266(((NimStringDesc*) &T839829468_188)); gentraverseprocseq_537399_839829468((&c0), LOC10, typ0); } goto LA6; LA8: ; { { Ttype292840* LOC14; Ropeobj178006* LOC17; LOC14 = (Ttype292840*)0; LOC14 = skiptypes_296099_850551059((*typ0).sons->data[((NI) 0)], IL64(211106232576256)); if (!((*LOC14).kind == ((Ttypekind292244) 4) || (*LOC14).kind == ((Ttypekind292244) 16))) goto LA15; LOC17 = (Ropeobj178006*)0; LOC17 = rope_178277_2381377266(((NimStringDesc*) &T839829468_188)); gentraverseproc_537022_839829468((&c0), LOC17, (*typ0).sons->data[((NI) 0)]); } goto LA12; LA15: ; { Ropeobj178006* LOC19; LOC19 = (Ropeobj178006*)0; LOC19 = rope_178277_2381377266(((NimStringDesc*) &T839829468_189)); gentraverseproc_537022_839829468((&c0), LOC19, (*typ0).sons->data[((NI) 0)]); } LA12: ; } LA6: ; memset((void*)LOC20, 0, sizeof(LOC20)); LOC20[0] = header0; LOC21 = (Ropeobj178006**)0; LOC21 = s_529179_3723162438(p0, ((Tcprocsection529011) 0)); LOC20[1] = (*LOC21); LOC22 = (Ropeobj178006**)0; LOC22 = s_529179_3723162438(p0, ((Tcprocsection529011) 1)); LOC20[2] = (*LOC22); LOC23 = (Ropeobj178006**)0; LOC23 = s_529179_3723162438(p0, ((Tcprocsection529011) 2)); LOC20[3] = (*LOC23); generatedproc0 = HEX25_178905_2381377266(((NimStringDesc*) &T839829468_190), LOC20, 4); memset((void*)LOC24, 0, sizeof(LOC24)); LOC24[0] = header0; addf_179205_2381377266(&(*m0).s[(((Tcfilesection529005) 7))- 0], ((NimStringDesc*) &T839829468_191), LOC24, 1); add_178482_2381377266(&(*m0).s[(((Tcfilesection529005) 10))- 0], generatedproc0); return result0; } N_NIMCALL(void, genarrayinfo_537005_839829468)(Tcgen529027* m0, Ttype292840* typ0, Ropeobj178006* name0) { Ropeobj178006* LOC1; LOC1 = (Ropeobj178006*)0; LOC1 = gentypeinfo_535941_839829468(m0, (*typ0).sons->data[((NI) 1)]); gentypeinfoauxbase_535960_839829468(m0, typ0, typ0, name0, LOC1); } N_NIMCALL(void, gensetinfo_536867_839829468)(Tcgen529027* m0, Ttype292840* typ0, Ropeobj178006* name0) { Ropeobj178006* tmp0; TY535238 LOC1; NI64 LOC2; gentypeinfoaux_536027_839829468(m0, typ0, typ0, name0); tmp0 = getnimnode_535945_839829468(m0); memset((void*)LOC1, 0, sizeof(LOC1)); LOC1[0] = tmp0; LOC2 = (NI64)0; LOC2 = firstord_320001_3876443242(typ0); LOC1[1] = rope_178401_2381377266(LOC2); LOC1[2] = name0; addf_179205_2381377266(&(*m0).s[(((Tcfilesection529005) 14))- 0], ((NimStringDesc*) &T839829468_193), LOC1, 3); } N_NIMCALL(void, genenuminfo_536597_839829468)(Tcgen529027* m0, Ttype292840* typ0, Ropeobj178006* name0) { Ropeobj178006* nodeptrs0; NI length0; TY532811 LOC1; Ropeobj178006* enumnames0; Ropeobj178006* specialcases0; NI firstnimnode0; NIM_BOOL hasholes0; Ropeobj178006* enumarray0; Ropeobj178006* counter0; TY178507 LOC24; TY535238 LOC25; TY536847 LOC26; TY535235 LOC27; gentypeinfoaux_536027_839829468(m0, typ0, typ0, name0); nodeptrs0 = gettempname_533596_839829468(m0); length0 = sonslen_295351_850551059((*typ0).n); memset((void*)LOC1, 0, sizeof(LOC1)); LOC1[0] = nodeptrs0; LOC1[1] = rope_178401_2381377266(((NI64) (length0))); addf_179205_2381377266(&(*m0).s[(((Tcfilesection529005) 12))- 0], ((NimStringDesc*) &T839829468_139), LOC1, 2); enumnames0 = (Ropeobj178006*)0; specialcases0 = (Ropeobj178006*)0; firstnimnode0 = (*m0).typenodes; hasholes0 = NIM_FALSE; { NI i_536622_839829468; NI HEX3Atmp_536860_839829468; NI res_536863_839829468; i_536622_839829468 = (NI)0; HEX3Atmp_536860_839829468 = (NI)0; HEX3Atmp_536860_839829468 = (NI)(length0 - ((NI) 1)); res_536863_839829468 = ((NI) 0); { while (1) { Tsym292834* field0; Ropeobj178006* elemnode0; if (!(res_536863_839829468 <= HEX3Atmp_536860_839829468)) goto LA4; i_536622_839829468 = res_536863_839829468; field0 = (*(*(*typ0).n).kindU.S6.sons->data[i_536622_839829468]).kindU.S4.sym; elemnode0 = getnimnode_535945_839829468(m0); { Ropeobj178006* LOC9; if (!((*field0).ast == NIM_NIL)) goto LA7; LOC9 = (Ropeobj178006*)0; LOC9 = makecstring_191638_155036129((*(*field0).name).s); add_178482_2381377266(&enumnames0, LOC9); } goto LA5; LA7: ; { Ropeobj178006* LOC11; LOC11 = (Ropeobj178006*)0; LOC11 = makecstring_191638_155036129((*(*field0).ast).kindU.S3.strval); add_178482_2381377266(&enumnames0, LOC11); } LA5: ; { NimStringDesc* LOC16; if (!(i_536622_839829468 < (NI)(length0 - ((NI) 1)))) goto LA14; LOC16 = (NimStringDesc*)0; LOC16 = rawNewString(tnl_176644_4151366050->Sup.len + 2); appendString(LOC16, ((NimStringDesc*) &T839829468_110)); appendString(LOC16, tnl_176644_4151366050); add_178487_2381377266(&enumnames0, LOC16); } LA14: ; { NIM_BOOL LOC19; TY532811 LOC23; LOC19 = (NIM_BOOL)0; LOC19 = !(((*field0).position == i_536622_839829468)); if (LOC19) goto LA20; LOC19 = (((*typ0).flags &(1U<<((NU)(((Ttypeflag292431) 5))&31U)))!=0); LA20: ; if (!LOC19) goto LA21; memset((void*)LOC23, 0, sizeof(LOC23)); LOC23[0] = elemnode0; LOC23[1] = rope_178401_2381377266(((NI64) ((*field0).position))); addf_179205_2381377266(&specialcases0, ((NimStringDesc*) &T839829468_194), LOC23, 2); hasholes0 = NIM_TRUE; } LA21: ; res_536863_839829468 += ((NI) 1); } LA4: ; } } enumarray0 = gettempname_533596_839829468(m0); counter0 = gettempname_533596_839829468(m0); memset((void*)LOC24, 0, sizeof(LOC24)); LOC24[0] = counter0; addf_179205_2381377266(&(*m0).s[(((Tcfilesection529005) 12))- 0], ((NimStringDesc*) &T839829468_195), LOC24, 1); memset((void*)LOC25, 0, sizeof(LOC25)); LOC25[0] = enumarray0; LOC25[1] = rope_178401_2381377266(((NI64) (length0))); LOC25[2] = enumnames0; addf_179205_2381377266(&(*m0).s[(((Tcfilesection529005) 12))- 0], ((NimStringDesc*) &T839829468_196), LOC25, 3); memset((void*)LOC26, 0, sizeof(LOC26)); LOC26[0] = counter0; LOC26[1] = rope_178401_2381377266(((NI64) (length0))); LOC26[2] = (*m0).typenodesname; LOC26[3] = rope_178401_2381377266(((NI64) (firstnimnode0))); LOC26[4] = enumarray0; LOC26[5] = nodeptrs0; addf_179205_2381377266(&(*m0).s[(((Tcfilesection529005) 14))- 0], ((NimStringDesc*) &T839829468_197), LOC26, 6); add_178482_2381377266(&(*m0).s[(((Tcfilesection529005) 14))- 0], specialcases0); memset((void*)LOC27, 0, sizeof(LOC27)); LOC27[0] = getnimnode_535945_839829468(m0); LOC27[1] = rope_178401_2381377266(((NI64) (length0))); LOC27[2] = nodeptrs0; LOC27[3] = name0; addf_179205_2381377266(&(*m0).s[(((Tcfilesection529005) 14))- 0], ((NimStringDesc*) &T839829468_198), LOC27, 4); { TY178507 LOC32; if (!hasholes0) goto LA30; memset((void*)LOC32, 0, sizeof(LOC32)); LOC32[0] = name0; addf_179205_2381377266(&(*m0).s[(((Tcfilesection529005) 14))- 0], ((NimStringDesc*) &T839829468_199), LOC32, 1); } LA30: ; } N_NIMCALL(Ropeobj178006*, discriminatortablename_536057_839829468)(Tcgen529027* m0, Ttype292840* objtype_536060_839829468, Tsym292834* d0) { Ropeobj178006* result0; Ttype292840* objtype0; TY532811 LOC8; NimStringDesc* LOC9; result0 = (Ropeobj178006*)0; objtype0 = objtype_536060_839829468; { while (1) { Tsym292834* LOC3; LOC3 = (Tsym292834*)0; LOC3 = lookupinrecord_299119_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_196100_155036129((*d0).info, ((NimStringDesc*) &T839829468_200)); } LA6: ; memset((void*)LOC8, 0, sizeof(LOC8)); LOC8[0] = rope_178401_2381377266(((NI64) ((*objtype0).Sup.id))); LOC9 = (NimStringDesc*)0; LOC9 = mangle_528847_2036603609((*(*d0).name).s); LOC8[1] = rope_178277_2381377266(LOC9); result0 = HEX25_178905_2381377266(((NimStringDesc*) &T839829468_201), LOC8, 2); return result0; } N_NIMCALL(void, genobjectfields_536104_839829468)(Tcgen529027* m0, Ttype292840* typ0, Tnode292802* n0, Ropeobj178006* expr0) { switch ((*n0).kind) { case ((Tnodekind292020) 138): { NI L0; L0 = sonslen_295351_850551059(n0); { if (!(L0 == ((NI) 1))) goto LA4; genobjectfields_536104_839829468(m0, typ0, (*n0).kindU.S6.sons->data[((NI) 0)], expr0); } goto LA2; LA4: ; { Ropeobj178006* tmp0; TY532811 LOC9; TY535238 LOC14; if (!(((NI) 0) < L0)) goto LA7; tmp0 = gettempname_533596_839829468(m0); memset((void*)LOC9, 0, sizeof(LOC9)); LOC9[0] = tmp0; LOC9[1] = rope_178401_2381377266(((NI64) (L0))); addf_179205_2381377266(&(*m0).s[(((Tcfilesection529005) 12))- 0], ((NimStringDesc*) &T839829468_139), LOC9, 2); { NI i_536127_839829468; NI HEX3Atmp_536482_839829468; NI res_536485_839829468; i_536127_839829468 = (NI)0; HEX3Atmp_536482_839829468 = (NI)0; HEX3Atmp_536482_839829468 = (NI)(L0 - ((NI) 1)); res_536485_839829468 = ((NI) 0); { while (1) { Ropeobj178006* tmp20; TY535238 LOC13; if (!(res_536485_839829468 <= HEX3Atmp_536482_839829468)) goto LA12; i_536127_839829468 = res_536485_839829468; tmp20 = getnimnode_535945_839829468(m0); memset((void*)LOC13, 0, sizeof(LOC13)); LOC13[0] = tmp0; LOC13[1] = rope_178401_2381377266(((NI64) (i_536127_839829468))); LOC13[2] = tmp20; addf_179205_2381377266(&(*m0).s[(((Tcfilesection529005) 14))- 0], ((NimStringDesc*) &T839829468_140), LOC13, 3); genobjectfields_536104_839829468(m0, typ0, (*n0).kindU.S6.sons->data[i_536127_839829468], tmp20); res_536485_839829468 += ((NI) 1); } LA12: ; } } memset((void*)LOC14, 0, sizeof(LOC14)); LOC14[0] = expr0; LOC14[1] = rope_178401_2381377266(((NI64) (L0))); LOC14[2] = tmp0; addf_179205_2381377266(&(*m0).s[(((Tcfilesection529005) 14))- 0], ((NimStringDesc*) &T839829468_142), LOC14, 3); } goto LA2; LA7: ; { TY532811 LOC16; memset((void*)LOC16, 0, sizeof(LOC16)); LOC16[0] = expr0; LOC16[1] = rope_178401_2381377266(((NI64) (L0))); addf_179205_2381377266(&(*m0).s[(((Tcfilesection529005) 14))- 0], ((NimStringDesc*) &T839829468_143), LOC16, 2); } LA2: ; } break; case ((Tnodekind292020) 139): { Tsym292834* field0; Ropeobj178006* tmp0; NI64 L0; TY536401 LOC18; TY532811 LOC19; field0 = (*(*n0).kindU.S6.sons->data[((NI) 0)]).kindU.S4.sym; tmp0 = discriminatortablename_536057_839829468(m0, typ0, field0); L0 = lengthord_320007_3876443242((*field0).typ); memset((void*)LOC18, 0, sizeof(LOC18)); LOC18[0] = expr0; LOC18[1] = gettypedesc_535671_839829468(m0, typ0); LOC18[2] = (*field0).loc.r; LOC18[3] = gentypeinfo_535941_839829468(m0, (*field0).typ); LOC18[4] = makecstring_191638_155036129((*(*field0).name).s); LOC18[5] = tmp0; LOC18[6] = rope_178401_2381377266(L0); addf_179205_2381377266(&(*m0).s[(((Tcfilesection529005) 14))- 0], ((NimStringDesc*) &T839829468_202), LOC18, 7); memset((void*)LOC19, 0, sizeof(LOC19)); LOC19[0] = tmp0; LOC19[1] = rope_178401_2381377266((NI64)(L0 + IL64(1))); addf_179205_2381377266(&(*m0).s[(((Tcfilesection529005) 8))- 0], ((NimStringDesc*) &T839829468_203), LOC19, 2); { NI i_536421_839829468; NI HEX3Atmp_536499_839829468; NI LOC21; NI res_536502_839829468; i_536421_839829468 = (NI)0; HEX3Atmp_536499_839829468 = (NI)0; LOC21 = (NI)0; LOC21 = sonslen_295351_850551059(n0); HEX3Atmp_536499_839829468 = (NI)(LOC21 - ((NI) 1)); res_536502_839829468 = ((NI) 1); { while (1) { Tnode292802* b0; Ropeobj178006* tmp20; Tnode292802* LOC24; if (!(res_536502_839829468 <= HEX3Atmp_536499_839829468)) goto LA23; i_536421_839829468 = res_536502_839829468; b0 = (*n0).kindU.S6.sons->data[i_536421_839829468]; tmp20 = getnimnode_535945_839829468(m0); LOC24 = (Tnode292802*)0; LOC24 = lastson_295364_850551059(b0); genobjectfields_536104_839829468(m0, typ0, LOC24, tmp20); switch ((*b0).kind) { case ((Tnodekind292020) 85): { { NI LOC28; LOC28 = (NI)0; LOC28 = sonslen_295351_850551059(b0); if (!(LOC28 < ((NI) 2))) goto LA29; internalerror_196100_155036129((*b0).info, ((NimStringDesc*) &T839829468_204)); } LA29: ; { NI j_536436_839829468; NI HEX3Atmp_536492_839829468; NI LOC32; NI res_536495_839829468; j_536436_839829468 = (NI)0; HEX3Atmp_536492_839829468 = (NI)0; LOC32 = (NI)0; LOC32 = sonslen_295351_850551059(b0); HEX3Atmp_536492_839829468 = (NI)(LOC32 - ((NI) 2)); res_536495_839829468 = ((NI) 0); { while (1) { if (!(res_536495_839829468 <= HEX3Atmp_536492_839829468)) goto LA34; j_536436_839829468 = res_536495_839829468; { NI x0; NI64 LOC39; NI y0; NI64 LOC40; if (!((*(*b0).kindU.S6.sons->data[j_536436_839829468]).kind == ((Tnodekind292020) 44))) goto LA37; LOC39 = (NI64)0; LOC39 = getordvalue_320129_3876443242((*(*b0).kindU.S6.sons->data[j_536436_839829468]).kindU.S6.sons->data[((NI) 0)]); x0 = ((NI) (LOC39)); LOC40 = (NI64)0; LOC40 = getordvalue_320129_3876443242((*(*b0).kindU.S6.sons->data[j_536436_839829468]).kindU.S6.sons->data[((NI) 1)]); y0 = ((NI) (LOC40)); { while (1) { TY535238 LOC43; if (!(x0 <= y0)) goto LA42; memset((void*)LOC43, 0, sizeof(LOC43)); LOC43[0] = tmp0; LOC43[1] = rope_178401_2381377266(((NI64) (x0))); LOC43[2] = tmp20; addf_179205_2381377266(&(*m0).s[(((Tcfilesection529005) 14))- 0], ((NimStringDesc*) &T839829468_140), LOC43, 3); x0 += ((NI) 1); } LA42: ; } } goto LA35; LA37: ; { TY535238 LOC45; NI64 LOC46; memset((void*)LOC45, 0, sizeof(LOC45)); LOC45[0] = tmp0; LOC46 = (NI64)0; LOC46 = getordvalue_320129_3876443242((*b0).kindU.S6.sons->data[j_536436_839829468]); LOC45[1] = rope_178401_2381377266(LOC46); LOC45[2] = tmp20; addf_179205_2381377266(&(*m0).s[(((Tcfilesection529005) 14))- 0], ((NimStringDesc*) &T839829468_140), LOC45, 3); } LA35: ; res_536495_839829468 += ((NI) 1); } LA34: ; } } } break; case ((Tnodekind292020) 88): { TY535238 LOC48; memset((void*)LOC48, 0, sizeof(LOC48)); LOC48[0] = tmp0; LOC48[1] = rope_178401_2381377266(L0); LOC48[2] = tmp20; addf_179205_2381377266(&(*m0).s[(((Tcfilesection529005) 14))- 0], ((NimStringDesc*) &T839829468_140), LOC48, 3); } break; default: { internalerror_196100_155036129((*n0).info, ((NimStringDesc*) &T839829468_205)); } break; } res_536502_839829468 += ((NI) 1); } LA23: ; } } } break; case ((Tnodekind292020) 3): { Tsym292834* field0; field0 = (*n0).kindU.S4.sym; { TY536475 LOC55; if (!((*field0).kindU.S4.bitsize == ((NI) 0))) goto LA53; memset((void*)LOC55, 0, sizeof(LOC55)); LOC55[0] = expr0; LOC55[1] = gettypedesc_535671_839829468(m0, typ0); LOC55[2] = (*field0).loc.r; LOC55[3] = gentypeinfo_535941_839829468(m0, (*field0).typ); LOC55[4] = makecstring_191638_155036129((*(*field0).name).s); addf_179205_2381377266(&(*m0).s[(((Tcfilesection529005) 14))- 0], ((NimStringDesc*) &T839829468_206), LOC55, 5); } LA53: ; } break; default: { internalerror_196100_155036129((*n0).info, ((NimStringDesc*) &T839829468_207)); } break; } } N_NIMCALL(void, genobjectinfo_536506_839829468)(Tcgen529027* m0, Ttype292840* typ0, Ttype292840* origtype0, Ropeobj178006* name0) { Ropeobj178006* tmp0; TY532811 LOC12; Ttype292840* t0; { if (!((*typ0).kind == ((Ttypekind292244) 17))) goto LA3; gentypeinfoaux_536027_839829468(m0, typ0, origtype0, name0); } goto LA1; LA3: ; { Ropeobj178006* LOC6; LOC6 = (Ropeobj178006*)0; LOC6 = rope_178277_2381377266(((NimStringDesc*) &T839829468_18)); gentypeinfoauxbase_535960_839829468(m0, typ0, origtype0, name0, LOC6); } LA1: ; tmp0 = getnimnode_535945_839829468(m0); { NIM_BOOL LOC9; LOC9 = (NIM_BOOL)0; LOC9 = isimportedcpptype_533476_839829468(typ0); if (!!(LOC9)) goto LA10; genobjectfields_536104_839829468(m0, typ0, (*typ0).n, tmp0); } LA10: ; memset((void*)LOC12, 0, sizeof(LOC12)); LOC12[0] = name0; LOC12[1] = tmp0; addf_179205_2381377266(&(*m0).s[(((Tcfilesection529005) 14))- 0], ((NimStringDesc*) &T839829468_144), LOC12, 2); t0 = (*typ0).sons->data[((NI) 0)]; { while (1) { if (!!((t0 == NIM_NIL))) goto LA14; t0 = skiptypes_296099_850551059(t0, IL64(211106247215360)); (*t0).flags |= ((NU32)1)<<((((Ttypeflag292431) 5))%(sizeof(NU32)*8)); t0 = (*t0).sons->data[((NI) 0)]; } LA14: ; } } N_NIMCALL(void, gendeepcopyproc_538066_839829468)(Tcgen529027* m0, Tsym292834* s0, Ropeobj178006* result0) { TY532811 LOC1; genproc_532951_839829468(m0, s0); memset((void*)LOC1, 0, sizeof(LOC1)); LOC1[0] = result0; LOC1[1] = (*s0).loc.r; addf_179205_2381377266(&(*m0).s[(((Tcfilesection529005) 14))- 0], ((NimStringDesc*) &T839829468_208), LOC1, 2); } N_NIMCALL(Ropeobj178006*, gentypeinfo_535941_839829468)(Tcgen529027* m0, Ttype292840* t_535944_839829468) { Ropeobj178006* result0; Ttype292840* origtype0; Ttype292840* t0; TY178507 LOC1; Tsym292834* owner0; Ttype292840* LOC12; Ropeobj178006* LOC66; Ropeobj178006* LOC67; Ropeobj178006* LOC68; { result0 = (Ropeobj178006*)0; origtype0 = t_535944_839829468; t0 = getuniquetype_528640_2036603609(t_535944_839829468); memset((void*)LOC1, 0, sizeof(LOC1)); LOC1[0] = rope_178401_2381377266(((NI64) ((*t0).Sup.id))); result0 = HEX25_178905_2381377266(((NimStringDesc*) &T839829468_127), LOC1, 1); { NIM_BOOL LOC4; Ropeobj178006* LOC7; Ropeobj178006* LOC8; Ropeobj178006* LOC9; LOC4 = (NIM_BOOL)0; LOC4 = containsorincl_268862_2627731572((&(*m0).typeinfomarker), (*t0).Sup.id); if (!LOC4) goto LA5; LOC7 = (Ropeobj178006*)0; LOC7 = rope_178277_2381377266(((NimStringDesc*) &T839829468_128)); LOC8 = (Ropeobj178006*)0; LOC8 = HEX26_178418_2381377266(LOC7, result0); LOC9 = (Ropeobj178006*)0; LOC9 = rope_178277_2381377266(((NimStringDesc*) &T839829468_117)); result0 = HEX26_178418_2381377266(LOC8, LOC9); goto BeforeRet; } LA5: ; { while (1) { if (!((*t0).kind == ((Ttypekind292244) 13))) goto LA11; t0 = lastson_295377_850551059(t0); } LA11: ; } LOC12 = (Ttype292840*)0; LOC12 = skiptypes_296099_850551059(t0, IL64(211106247256320)); owner0 = getmodule_299123_2984716966((*LOC12).owner); { Tcgen529027* LOC17; Ropeobj178006* LOC18; Ropeobj178006* LOC19; Ropeobj178006* LOC20; TY532811 LOC21; NimStringDesc* LOC22; Ropeobj178006* LOC23; Ropeobj178006* LOC24; Ropeobj178006* LOC25; if (!!((owner0 == (*m0).module))) goto LA15; LOC17 = (Tcgen529027*)0; LOC17 = bmod_529201_3723162438(owner0); LOC18 = (Ropeobj178006*)0; LOC18 = gentypeinfo_535941_839829468(LOC17, t0); LOC19 = (Ropeobj178006*)0; LOC19 = cgsym_532403_839829468(m0, ((NimStringDesc*) &T839829468_129)); LOC20 = (Ropeobj178006*)0; LOC20 = cgsym_532403_839829468(m0, ((NimStringDesc*) &T839829468_130)); memset((void*)LOC21, 0, sizeof(LOC21)); LOC21[0] = result0; LOC22 = (NimStringDesc*)0; LOC22 = typetostring_320017_3876443242(t0, ((Tprefereddesc320011) 0)); LOC21[1] = rope_178277_2381377266(LOC22); addf_179205_2381377266(&(*m0).s[(((Tcfilesection529005) 9))- 0], ((NimStringDesc*) &T839829468_131), LOC21, 2); LOC23 = (Ropeobj178006*)0; LOC23 = rope_178277_2381377266(((NimStringDesc*) &T839829468_128)); LOC24 = (Ropeobj178006*)0; LOC24 = HEX26_178418_2381377266(LOC23, result0); LOC25 = (Ropeobj178006*)0; LOC25 = rope_178277_2381377266(((NimStringDesc*) &T839829468_117)); result0 = HEX26_178418_2381377266(LOC24, LOC25); goto BeforeRet; } LA15: ; switch ((*t0).kind) { case ((Ttypekind292244) 3): case ((Ttypekind292244) 62): { result0 = rope_178277_2381377266(((NimStringDesc*) &T839829468_132)); } break; case ((Ttypekind292244) 26): case ((Ttypekind292244) 1): case ((Ttypekind292244) 2): case ((Ttypekind292244) 29): case ((Ttypekind292244) 28): case ((Ttypekind292244) 31) ... ((Ttypekind292244) 44): case ((Ttypekind292244) 23): { Ropeobj178006* LOC28; LOC28 = (Ropeobj178006*)0; LOC28 = rope_178277_2381377266(((NimStringDesc*) &T839829468_132)); gentypeinfoauxbase_535960_839829468(m0, t0, t0, result0, LOC28); } break; case ((Ttypekind292244) 59): { { Ttype292840* LOC34; if (!!(((*t0).n == NIM_NIL))) goto LA32; LOC34 = (Ttype292840*)0; LOC34 = lastson_295377_850551059(t0); result0 = gentypeinfo_535941_839829468(m0, LOC34); } goto LA30; LA32: ; { NimStringDesc* LOC36; LOC36 = (NimStringDesc*)0; LOC36 = rawNewString(reprEnum((NI)(*t0).kind, (&NTI292244))->Sup.len + 13); appendString(LOC36, ((NimStringDesc*) &T839829468_137)); appendString(LOC36, reprEnum((NI)(*t0).kind, (&NTI292244))); appendChar(LOC36, 41); internalerror_196113_155036129(LOC36); } LA30: ; } break; case ((Ttypekind292244) 25): { { Ropeobj178006* LOC42; if (!!(((*t0).callconv == ((Tcallingconvention292002) 8)))) goto LA40; LOC42 = (Ropeobj178006*)0; LOC42 = rope_178277_2381377266(((NimStringDesc*) &T839829468_132)); gentypeinfoauxbase_535960_839829468(m0, t0, t0, result0, LOC42); } goto LA38; LA40: ; { Ttype292840* LOC44; LOC44 = (Ttype292840*)0; LOC44 = fakeclosuretype_537010_839829468((*t0).owner); gentupleinfo_536549_839829468(m0, LOC44, result0); } LA38: ; } break; case ((Ttypekind292244) 24): case ((Ttypekind292244) 22): { gentypeinfoaux_536027_839829468(m0, t0, t0, result0); { Ropeobj178006* markerproc0; TY532811 LOC50; if (!(((Tgcmode169080) 4) <= gselectedgc_169133_2607990831)) goto LA48; markerproc0 = gentraverseproc_537632_839829468(m0, t0, ((Ttypeinforeason537016) 0)); memset((void*)LOC50, 0, sizeof(LOC50)); LOC50[0] = result0; LOC50[1] = markerproc0; addf_179205_2381377266(&(*m0).s[(((Tcfilesection529005) 14))- 0], ((NimStringDesc*) &T839829468_192), LOC50, 2); } LA48: ; } break; case ((Ttypekind292244) 21): case ((Ttypekind292244) 20): { gentypeinfoaux_536027_839829468(m0, t0, t0, result0); } break; case ((Ttypekind292244) 4): case ((Ttypekind292244) 16): { genarrayinfo_537005_839829468(m0, t0, result0); } break; case ((Ttypekind292244) 19): { gensetinfo_536867_839829468(m0, t0, result0); } break; case ((Ttypekind292244) 14): { genenuminfo_536597_839829468(m0, t0, result0); } break; case ((Ttypekind292244) 17): { genobjectinfo_536506_839829468(m0, t0, origtype0, result0); } break; case ((Ttypekind292244) 18): { gentupleinfo_536549_839829468(m0, t0, result0); } break; default: { NimStringDesc* LOC58; LOC58 = (NimStringDesc*)0; LOC58 = rawNewString(reprEnum((NI)(*t0).kind, (&NTI292244))->Sup.len + 13); appendString(LOC58, ((NimStringDesc*) &T839829468_137)); appendString(LOC58, reprEnum((NI)(*t0).kind, (&NTI292244))); appendChar(LOC58, 41); internalerror_196113_155036129(LOC58); } break; } { if (!!(((*t0).deepcopy == NIM_NIL))) goto LA61; gendeepcopyproc_538066_839829468(m0, (*t0).deepcopy, result0); } goto LA59; LA61: ; { if (!!(((*origtype0).deepcopy == NIM_NIL))) goto LA64; gendeepcopyproc_538066_839829468(m0, (*origtype0).deepcopy, result0); } goto LA59; LA64: ; LA59: ; LOC66 = (Ropeobj178006*)0; LOC66 = rope_178277_2381377266(((NimStringDesc*) &T839829468_128)); LOC67 = (Ropeobj178006*)0; LOC67 = HEX26_178418_2381377266(LOC66, result0); LOC68 = (Ropeobj178006*)0; LOC68 = rope_178277_2381377266(((NimStringDesc*) &T839829468_117)); result0 = HEX26_178418_2381377266(LOC67, LOC68); }BeforeRet: ; return result0; } N_NIMCALL(void, localdebuginfo_538449_839829468)(Tcproc529021* p0, Tsym292834* s0) { Ropeobj178006* a0; TY535235 LOC16; NimStringDesc* LOC17; { { if (!!(((163840 & (*p0).options) == 163840))) goto LA3; goto BeforeRet; } LA3: ; { Ttype292840* LOC7; LOC7 = (Ttype292840*)0; LOC7 = skiptypes_296099_850551059((*s0).typ, IL64(211106240964864)); if (!((*LOC7).kind == ((Ttypekind292244) 27) || (*LOC7).kind == ((Ttypekind292244) 48))) goto LA8; goto BeforeRet; } LA8: ; a0 = HEX26_178452_2381377266(((NimStringDesc*) &T839829468_52), (*s0).loc.r); { NIM_BOOL LOC12; LOC12 = (NIM_BOOL)0; LOC12 = ((*s0).kind == ((Tsymkind292435) 3)); if (!(LOC12)) goto LA13; LOC12 = ccgintroducedptr_533609_839829468(s0); LA13: ; if (!LOC12) goto LA14; a0 = (*s0).loc.r; } LA14: ; memset((void*)LOC16, 0, sizeof(LOC16)); LOC16[0] = rope_178401_2381377266(((NI64) ((*p0).maxframelen))); LOC17 = (NimStringDesc*)0; LOC17 = nsuNormalize((*(*s0).name).s); LOC16[1] = makecstring_191638_155036129(LOC17); LOC16[2] = a0; LOC16[3] = gentypeinfo_535941_839829468((*p0).module, (*s0).loc.t); linef_532700_839829468(p0, ((Tcprocsection529011) 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_538614_839829468)(Tcproc529021* p0, Tsym292834* s0) { Ropeobj178006* decl0; Ropeobj178006* LOC1; Ropeobj178006* LOC2; LOC1 = (Ropeobj178006*)0; LOC1 = localvardecl_538532_839829468(p0, s0); LOC2 = (Ropeobj178006*)0; LOC2 = HEX26_178447_2381377266(LOC1, ((NimStringDesc*) &T839829468_125)); decl0 = HEX26_178447_2381377266(LOC2, tnl_176644_4151366050); line_532690_839829468(p0, ((Tcprocsection529011) 0), decl0); localdebuginfo_538449_839829468(p0, s0); } N_NIMCALL(void, initlocalvar_538398_839829468)(Tcproc529021* p0, Tsym292834* v0, NIM_BOOL immediateasgn0) { { if (!!((((*v0).flags &(1U<<((NU)(((Tsymflag292184) 12))&31U)))!=0))) goto LA3; { if (!!(immediateasgn0)) goto LA7; constructloc_538388_839829468(p0, (*v0).loc, NIM_FALSE); } LA7: ; } LA3: ; } N_NIMCALL(void, fillresult_533865_839829468)(Tsym292834* param0) { TY533289 LOC1; Ropeobj178006* LOC2; memset((void*)LOC1, 0, sizeof(LOC1)); LOC2 = (Ropeobj178006*)0; LOC2 = HEX25_178905_2381377266(((NimStringDesc*) &T839829468_210), LOC1, 0); fillloc_532282_839829468((&(*param0).loc), ((Tlockind292808) 4), (*param0).typ, LOC2, ((Tstorageloc292812) 2)); { NIM_BOOL LOC5; Tctypekind529007 LOC6; LOC5 = (NIM_BOOL)0; LOC6 = (Tctypekind529007)0; LOC6 = mapreturntype_533445_839829468((*param0).typ); LOC5 = !((LOC6 == ((Tctypekind529007) 17))); if (!(LOC5)) goto LA7; LOC5 = isinvalidreturntype_533548_839829468((*param0).typ); LA7: ; if (!LOC5) goto LA8; (*param0).loc.flags |= ((NU16)1)<<((((Tlocflag292810) 0))%(sizeof(NU16)*8)); (*param0).loc.s = ((Tstorageloc292812) 0); } LA8: ; } N_NIMCALL(void, assignparam_538994_839829468)(Tcproc529021* p0, Tsym292834* s0) { localdebuginfo_538449_839829468(p0, s0); } N_NIMCALL(void, closuresetup_560158_839829468)(Tcproc529021* p0, Tsym292834* prc0) { Tnode292802* ls0; Tnode292802* LOC5; Tsym292834* env0; TY532811 LOC10; { { if (!!((((*(*prc0).typ).flags &(1U<<((NU)(((Ttypeflag292431) 11))&31U)))!=0))) goto LA3; goto BeforeRet; } LA3: ; LOC5 = (Tnode292802*)0; LOC5 = HEX5BHEX5D_293238_850551059((*prc0).ast, ((NI) 3)); ls0 = lastson_295364_850551059(LOC5); { if (!!(((*ls0).kind == ((Tnodekind292020) 3)))) goto LA8; internalerror_196100_155036129((*prc0).info, ((NimStringDesc*) &T839829468_211)); } LA8: ; env0 = (*ls0).kindU.S4.sym; assignlocalvar_538614_839829468(p0, env0); memset((void*)LOC10, 0, sizeof(LOC10)); LOC10[0] = rdloc_538188_839829468((*env0).loc); LOC10[1] = gettypedesc_535671_839829468((*p0).module, (*env0).typ); linefmt_532714_839829468(p0, ((Tcprocsection529011) 2), ((NimStringDesc*) &T839829468_212), LOC10, 2); }BeforeRet: ; } N_NIMCALL(Ropeobj178006*, initgcframe_538435_839829468)(Tcproc529021* p0) { Ropeobj178006* result0; result0 = (Ropeobj178006*)0; { TY178507 LOC5; if (!(((NI) 0) < ((NI) ((*p0).gcframeid)))) goto LA3; memset((void*)LOC5, 0, sizeof(LOC5)); LOC5[0] = (*p0).gcframetype; result0 = HEX25_178905_2381377266(((NimStringDesc*) &T839829468_217), LOC5, 1); } LA3: ; return result0; } N_NIMCALL(Ropeobj178006*, initframe_560140_839829468)(Tcproc529021* p0, Ropeobj178006* procname0, Ropeobj178006* filename0) { Ropeobj178006* result0; Ropeobj178006* LOC1; result0 = (Ropeobj178006*)0; LOC1 = (Ropeobj178006*)0; LOC1 = cgsym_532403_839829468((*p0).module, ((NimStringDesc*) &T839829468_218)); { Ropeobj178006* LOC6; TY535235 LOC7; if (!(((NI) 0) < (*p0).maxframelen)) goto LA4; LOC6 = (Ropeobj178006*)0; LOC6 = cgsym_532403_839829468((*p0).module, ((NimStringDesc*) &T839829468_219)); memset((void*)LOC7, 0, sizeof(LOC7)); LOC7[0] = procname0; LOC7[1] = filename0; LOC7[2] = rope_178401_2381377266(((NI64) ((*p0).maxframelen))); LOC7[3] = rope_178401_2381377266(((NI64) ((*p0).blocks->data[((NI) 0)].framelen))); result0 = ropecg_532407_839829468(NIM_NIL, ((NimStringDesc*) &T839829468_220), LOC7, 4); } goto LA2; LA4: ; { TY532811 LOC9; memset((void*)LOC9, 0, sizeof(LOC9)); LOC9[0] = procname0; LOC9[1] = filename0; result0 = ropecg_532407_839829468(NIM_NIL, ((NimStringDesc*) &T839829468_221), LOC9, 2); } LA2: ; return result0; } N_NIMCALL(void, appcg_532648_839829468)(Tcproc529021* p0, Tcprocsection529011 s0, NimStringDesc* frmt0, Ropeobj178006** args0, NI args0Len0) { Ropeobj178006** LOC1; Ropeobj178006* LOC2; LOC1 = (Ropeobj178006**)0; LOC1 = s_529179_3723162438(p0, s0); LOC2 = (Ropeobj178006*)0; LOC2 = ropecg_532407_839829468((*p0).module, frmt0, args0, args0Len0); add_178482_2381377266(LOC1, LOC2); } N_NIMCALL(Ropeobj178006*, deinitgcframe_538441_839829468)(Tcproc529021* p0) { Ropeobj178006* result0; result0 = (Ropeobj178006*)0; { TY533289 LOC5; if (!(((NI) 0) < ((NI) ((*p0).gcframeid)))) goto LA3; memset((void*)LOC5, 0, sizeof(LOC5)); result0 = ropecg_532407_839829468((*p0).module, ((NimStringDesc*) &T839829468_225), LOC5, 0); } LA3: ; return result0; } N_NIMCALL(Ropeobj178006*, deinitframe_560150_839829468)(Tcproc529021* p0) { Ropeobj178006* result0; TY533289 LOC1; result0 = (Ropeobj178006*)0; memset((void*)LOC1, 0, sizeof(LOC1)); result0 = ropecg_532407_839829468((*p0).module, ((NimStringDesc*) &T839829468_226), LOC1, 0); return result0; } N_NIMCALL(void, genprocaux_560284_839829468)(Tcgen529027* m0, Tsym292834* prc0) { Tcproc529021* p0; Ropeobj178006* header0; Ropeobj178006* returnstmt0; Tnode292802* LOC51; Ropeobj178006* generatedproc0; p0 = newproc_529206_3723162438(prc0, m0); header0 = genprocheader_535867_839829468(m0, prc0); returnstmt0 = NIM_NIL; { NIM_BOOL LOC3; Tsym292834* res0; LOC3 = (NIM_BOOL)0; LOC3 = !((((*prc0).flags &(1U<<((NU)(((Tsymflag292184) 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_293081_850551059((*prc0).ast); if (!(LOC9 <= ((NI) 7))) goto LA10; internalerror_196100_155036129((*prc0).info, ((NimStringDesc*) &T839829468_120)); } LA10: ; res0 = (*(*(*prc0).ast).kindU.S6.sons->data[((NI) 7)]).kindU.S4.sym; { NIM_BOOL LOC14; TY178507 LOC34; LOC14 = (NIM_BOOL)0; LOC14 = isinvalidreturntype_533548_839829468((*(*prc0).typ).sons->data[((NI) 0)]); if (!!(LOC14)) goto LA15; { if (!(((*prc0).flags &(1U<<((NU)(((Tsymflag292184) 12))&31U)))!=0)) goto LA19; (*res0).flags |= ((NU32)1)<<((((Tsymflag292184) 12))%(sizeof(NU32)*8)); } LA19: ; { NIM_BOOL LOC23; NIM_BOOL LOC24; NIM_BOOL LOC26; Tnode292802* val0; Tnode292802* LOC29; Ropeobj178006* decl0; Tloc292816 a0; TY532811 LOC32; LOC23 = (NIM_BOOL)0; LOC24 = (NIM_BOOL)0; LOC24 = (((*prc0).flags &(1U<<((NU)(((Tsymflag292184) 12))&31U)))!=0); if (!(LOC24)) goto LA25; LOC26 = (NIM_BOOL)0; LOC26 = (gcmd_169132_2607990831 == ((Tcommands169076) 2)); if (LOC26) goto LA27; LOC26 = (((*(*(*p0).module).module).flags &(1U<<((NU)(((Tsymflag292184) 27))&31U)))!=0); LA27: ; LOC24 = LOC26; LA25: ; LOC23 = LOC24; if (!(LOC23)) goto LA28; LOC29 = (Tnode292802*)0; LOC29 = getbody_335227_1724185294(prc0); val0 = easyresultasgn_560191_839829468(LOC29); LOC23 = !((val0 == NIM_NIL)); LA28: ; if (!LOC23) goto LA30; decl0 = localvardecl_538532_839829468(p0, res0); memset((void*)(&a0), 0, sizeof(a0)); initlocexprsingleuse_539289_839829468(p0, val0, (&a0)); memset((void*)LOC32, 0, sizeof(LOC32)); LOC32[0] = decl0; LOC32[1] = rdloc_538188_839829468(a0); linefmt_532714_839829468(p0, ((Tcprocsection529011) 2), ((NimStringDesc*) &T839829468_123), LOC32, 2); } goto LA21; LA30: ; { assignlocalvar_538614_839829468(p0, res0); initlocalvar_538398_839829468(p0, res0, NIM_FALSE); } LA21: ; memset((void*)LOC34, 0, sizeof(LOC34)); LOC34[0] = rdloc_538188_839829468((*res0).loc); returnstmt0 = ropecg_532407_839829468(NIM_NIL, ((NimStringDesc*) &T839829468_209), LOC34, 1); } goto LA12; LA15: ; { fillresult_533865_839829468(res0); assignparam_538994_839829468(p0, res0); { Ttype292840* LOC38; LOC38 = (Ttype292840*)0; LOC38 = skiptypes_296099_850551059((*res0).typ, IL64(211106232576256)); if (!((*LOC38).kind == ((Ttypekind292244) 16))) goto LA39; (*res0).loc.s = ((Tstorageloc292812) 0); } LA39: ; } LA12: ; } LA5: ; { NI i_560627_839829468; NI HEX3Atmp_560743_839829468; NI LOC42; NI res_560746_839829468; i_560627_839829468 = (NI)0; HEX3Atmp_560743_839829468 = (NI)0; LOC42 = (NI)0; LOC42 = sonslen_295351_850551059((*(*prc0).typ).n); HEX3Atmp_560743_839829468 = (NI)(LOC42 - ((NI) 1)); res_560746_839829468 = ((NI) 1); { while (1) { if (!(res_560746_839829468 <= HEX3Atmp_560743_839829468)) goto LA44; i_560627_839829468 = res_560746_839829468; { Tsym292834* param0; param0 = (*(*(*(*prc0).typ).n).kindU.S6.sons->data[i_560627_839829468]).kindU.S4.sym; { NIM_BOOL LOC48; LOC48 = (NIM_BOOL)0; LOC48 = iscompiletimeonly_328706_3876443242((*param0).typ); if (!LOC48) goto LA49; goto LA45; } LA49: ; assignparam_538994_839829468(p0, param0); } LA45: ; res_560746_839829468 += ((NI) 1); } LA44: ; } } closuresetup_560158_839829468(p0, prc0); LOC51 = (Tnode292802*)0; LOC51 = getbody_335227_1724185294(prc0); genstmts_539244_839829468(p0, LOC51); generatedproc0 = (Ropeobj178006*)0; { if (!(((*prc0).flags &(1U<<((NU)(((Tsymflag292184) 14))&31U)))!=0)) goto LA54; { if (!((Cc_273413_2528170400[(ccompiler_273431_2528170400)- 1].Field20 &(1U<<((NU)(((Tinfoccprop273004) 6))&7U)))!=0)) goto LA58; header0 = HEX26_178452_2381377266(((NimStringDesc*) &T839829468_213), header0); } LA58: ; } LA54: ; { TY535235 LOC68; Ropeobj178006** LOC69; Ropeobj178006** LOC70; Ropeobj178006** LOC71; if (!(((*prc0).flags &(1U<<((NU)(((Tsymflag292184) 9))&31U)))!=0)) goto LA62; { if (!((Cc_273413_2528170400[(ccompiler_273431_2528170400)- 1].Field20 &(1U<<((NU)(((Tinfoccprop273004) 6))&7U)))!=0)) goto LA66; header0 = HEX26_178452_2381377266(((NimStringDesc*) &T839829468_214), header0); } LA66: ; memset((void*)LOC68, 0, sizeof(LOC68)); LOC68[0] = header0; LOC69 = (Ropeobj178006**)0; LOC69 = s_529179_3723162438(p0, ((Tcprocsection529011) 0)); LOC68[1] = (*LOC69); LOC70 = (Ropeobj178006**)0; LOC70 = s_529179_3723162438(p0, ((Tcprocsection529011) 1)); LOC68[2] = (*LOC70); LOC71 = (Ropeobj178006**)0; LOC71 = s_529179_3723162438(p0, ((Tcprocsection529011) 2)); LOC68[3] = (*LOC71); generatedproc0 = ropecg_532407_839829468(NIM_NIL, ((NimStringDesc*) &T839829468_215), LOC68, 4); } goto LA60; LA62: ; { TY178507 LOC73; Ropeobj178006* LOC74; Ropeobj178006** LOC93; Ropeobj178006** LOC94; Ropeobj178006* LOC101; TY533289 LOC107; Ropeobj178006* LOC108; memset((void*)LOC73, 0, sizeof(LOC73)); LOC73[0] = header0; generatedproc0 = ropecg_532407_839829468(NIM_NIL, ((NimStringDesc*) &T839829468_216), LOC73, 1); LOC74 = (Ropeobj178006*)0; LOC74 = initgcframe_538435_839829468(p0); add_178482_2381377266(&generatedproc0, LOC74); { Ropeobj178006** LOC79; Ropeobj178006* procname0; Ropeobj178006* LOC80; Ropeobj178006* LOC81; if (!(((*prc0).options &(1U<<((NU)(((Toption169009) 15))&31U)))!=0)) goto LA77; LOC79 = (Ropeobj178006**)0; LOC79 = s_529179_3723162438(p0, ((Tcprocsection529011) 0)); add_178482_2381377266(&generatedproc0, (*LOC79)); procname0 = makecstring_191638_155036129((*(*prc0).name).s); LOC80 = (Ropeobj178006*)0; LOC80 = quotedfilename_196818_155036129((*prc0).info); LOC81 = (Ropeobj178006*)0; LOC81 = initframe_560140_839829468(p0, procname0, LOC80); add_178482_2381377266(&generatedproc0, LOC81); } goto LA75; LA77: ; { Ropeobj178006** LOC83; LOC83 = (Ropeobj178006**)0; LOC83 = s_529179_3723162438(p0, ((Tcprocsection529011) 0)); add_178482_2381377266(&generatedproc0, (*LOC83)); } LA75: ; { TY533289 LOC88; if (!(((*prc0).options &(1U<<((NU)(((Toption169009) 19))&31U)))!=0)) goto LA86; memset((void*)LOC88, 0, sizeof(LOC88)); appcg_532648_839829468(p0, ((Tcprocsection529011) 1), ((NimStringDesc*) &T839829468_222), LOC88, 0); } LA86: ; { if (!(*p0).beforeretneeded) goto LA91; add_178487_2381377266(&generatedproc0, ((NimStringDesc*) &T839829468_223)); } LA91: ; LOC93 = (Ropeobj178006**)0; LOC93 = s_529179_3723162438(p0, ((Tcprocsection529011) 1)); add_178482_2381377266(&generatedproc0, (*LOC93)); LOC94 = (Ropeobj178006**)0; LOC94 = s_529179_3723162438(p0, ((Tcprocsection529011) 2)); add_178482_2381377266(&generatedproc0, (*LOC94)); { TY533289 LOC99; Ropeobj178006* LOC100; if (!(*p0).beforeretneeded) goto LA97; memset((void*)LOC99, 0, sizeof(LOC99)); LOC100 = (Ropeobj178006*)0; LOC100 = HEX25_178905_2381377266(((NimStringDesc*) &T839829468_224), LOC99, 0); add_178482_2381377266(&generatedproc0, LOC100); } LA97: ; LOC101 = (Ropeobj178006*)0; LOC101 = deinitgcframe_538441_839829468(p0); add_178482_2381377266(&generatedproc0, LOC101); { Ropeobj178006* LOC106; if (!(((*prc0).options &(1U<<((NU)(((Toption169009) 15))&31U)))!=0)) goto LA104; LOC106 = (Ropeobj178006*)0; LOC106 = deinitframe_560150_839829468(p0); add_178482_2381377266(&generatedproc0, LOC106); } LA104: ; add_178482_2381377266(&generatedproc0, returnstmt0); memset((void*)LOC107, 0, sizeof(LOC107)); LOC108 = (Ropeobj178006*)0; LOC108 = HEX25_178905_2381377266(((NimStringDesc*) &T839829468_227), LOC107, 0); add_178482_2381377266(&generatedproc0, LOC108); } LA60: ; add_178482_2381377266(&(*m0).s[(((Tcfilesection529005) 10))- 0], generatedproc0); } N_NIMCALL(Tcgen529027*, findpendingmodule_532241_839829468)(Tcgen529027* m0, Tsym292834* s0) { Tcgen529027* result0; Tsym292834* ms0; result0 = (Tcgen529027*)0; ms0 = getmodule_299123_2984716966(s0); result0 = gmodules_529170_3723162438->data[(*ms0).position]; return result0; } N_NIMCALL(NIM_BOOL, isgetprocaddr_559442_839829468)(Tlib292820* lib0) { NIM_BOOL result0; Tnode292802* 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 == ((Tnodekind292020) 27) || (*n0).kind == ((Tnodekind292020) 29) || (*n0).kind == ((Tnodekind292020) 30) || (*n0).kind == ((Tnodekind292020) 31) || (*n0).kind == ((Tnodekind292020) 26) || (*n0).kind == ((Tnodekind292020) 28) || (*n0).kind == ((Tnodekind292020) 32)); if (!(LOC2)) goto LA3; LOC2 = !(((*n0).typ == NIM_NIL)); LA3: ; LOC1 = LOC2; if (!(LOC1)) goto LA4; LOC1 = ((*(*n0).typ).kind == ((Ttypekind292244) 26) || (*(*n0).typ).kind == ((Ttypekind292244) 25)); LA4: ; result0 = LOC1; return result0; } N_NIMCALL(void, initlocexpr_539283_839829468)(Tcproc529021* p0, Tnode292802* e0, Tloc292816* result0) { initloc_532273_839829468(result0, ((Tlockind292808) 0), (*e0).typ, ((Tstorageloc292812) 0)); expr_539248_839829468(p0, e0, result0); } N_NIMCALL(void, loaddynamiclib_559480_839829468)(Tcgen529027* m0, Tlib292820* lib0) { { Ropeobj178006* tmp0; TY178507 LOC5; if (!!((*lib0).generated)) goto LA3; (*lib0).generated = NIM_TRUE; tmp0 = gettempname_533596_839829468(m0); asgnRefNoCycle((void**) (&(*lib0).name), tmp0); memset((void*)LOC5, 0, sizeof(LOC5)); LOC5[0] = tmp0; addf_179205_2381377266(&(*m0).s[(((Tcfilesection529005) 9))- 0], ((NimStringDesc*) &T839829468_228), LOC5, 1); { TY135002* s0; Ropeobj178006* loadlib0; TY532811 LOC18; if (!((*(*lib0).path).kind >= ((Tnodekind292020) 20) && (*(*lib0).path).kind <= ((Tnodekind292020) 22))) goto LA8; s0 = (TY135002*) newSeq((&NTI135002), 0); libcandidates_170605_2607990831((*(*lib0).path).kindU.S3.strval, (&s0)); rawmessage_194612_155036129(((Tmsgkind191002) 286), (*(*lib0).path).kindU.S3.strval); loadlib0 = NIM_NIL; { NI i_559847_839829468; NI HEX3Atmp_559902_839829468; NI res_559905_839829468; i_559847_839829468 = (NI)0; HEX3Atmp_559902_839829468 = (NI)0; HEX3Atmp_559902_839829468 = (s0 ? (s0->Sup.len-1) : -1); res_559905_839829468 = ((NI) 0); { while (1) { TY532811 LOC17; if (!(res_559905_839829468 <= HEX3Atmp_559902_839829468)) goto LA12; i_559847_839829468 = res_559905_839829468; (*m0).labels += ((NI) 1); { if (!(((NI) 0) < i_559847_839829468)) goto LA15; add_178487_2381377266(&loadlib0, ((NimStringDesc*) &T839829468_229)); } LA15: ; memset((void*)LOC17, 0, sizeof(LOC17)); LOC17[0] = tmp0; LOC17[1] = getstrlit_549468_839829468(m0, s0->data[i_559847_839829468]); appcg_532632_839829468(m0, &loadlib0, ((NimStringDesc*) &T839829468_230), LOC17, 2); res_559905_839829468 += ((NI) 1); } LA12: ; } } memset((void*)LOC18, 0, sizeof(LOC18)); LOC18[0] = loadlib0; LOC18[1] = getstrlit_549468_839829468(m0, (*(*lib0).path).kindU.S3.strval); appcg_532632_839829468(m0, &(*m0).s[(((Tcfilesection529005) 16))- 0], ((NimStringDesc*) &T839829468_231), LOC18, 2); } goto LA6; LA8: ; { Tcproc529021* p0; Tloc292816 dest0; Ropeobj178006** LOC20; Ropeobj178006** LOC21; Ropeobj178006** LOC22; TY532811 LOC23; p0 = newproc_529206_3723162438(NIM_NIL, m0); (*p0).options = ((*p0).options & ~ 163840); memset((void*)(&dest0), 0, sizeof(dest0)); initlocexpr_539283_839829468(p0, (*lib0).path, (&dest0)); LOC20 = (Ropeobj178006**)0; LOC20 = s_529179_3723162438(p0, ((Tcprocsection529011) 0)); add_178482_2381377266(&(*m0).s[(((Tcfilesection529005) 9))- 0], (*LOC20)); LOC21 = (Ropeobj178006**)0; LOC21 = s_529179_3723162438(p0, ((Tcprocsection529011) 1)); add_178482_2381377266(&(*m0).s[(((Tcfilesection529005) 16))- 0], (*LOC21)); LOC22 = (Ropeobj178006**)0; LOC22 = s_529179_3723162438(p0, ((Tcprocsection529011) 2)); add_178482_2381377266(&(*m0).s[(((Tcfilesection529005) 16))- 0], (*LOC22)); memset((void*)LOC23, 0, sizeof(LOC23)); LOC23[0] = tmp0; LOC23[1] = rdloc_538188_839829468(dest0); appcg_532632_839829468(m0, &(*m0).s[(((Tcfilesection529005) 16))- 0], ((NimStringDesc*) &T839829468_232), LOC23, 2); } LA6: ; } LA3: ; { if (!((*lib0).name == NIM_NIL)) goto LA26; internalerror_196113_155036129(((NimStringDesc*) &T839829468_233)); } LA26: ; } N_NIMCALL(Ropeobj178006*, mangledynlibproc_538816_839829468)(Tsym292834* sym0) { Ropeobj178006* result0; result0 = (Ropeobj178006*)0; { if (!(((*sym0).flags &(1U<<((NU)(((Tsymflag292184) 16))&31U)))!=0)) goto LA3; result0 = rope_178277_2381377266((*(*sym0).name).s); } goto LA1; LA3: ; { TY178507 LOC6; memset((void*)LOC6, 0, sizeof(LOC6)); LOC6[0] = rope_178401_2381377266(((NI64) ((*sym0).Sup.id))); result0 = HEX25_178905_2381377266(((NimStringDesc*) &T839829468_234), LOC6, 1); } LA1: ; return result0; } N_NIMCALL(void, symindynamiclib_559929_839829468)(Tcgen529027* m0, Tsym292834* sym0) { Tlib292820* lib0; NIM_BOOL iscall0; Ropeobj178006* extname0; Ropeobj178006* tmp0; TY532811 LOC43; lib0 = (*sym0).annex; iscall0 = isgetprocaddr_559442_839829468(lib0); extname0 = (*sym0).loc.r; { if (!!(iscall0)) goto LA3; loaddynamiclib_559480_839829468(m0, lib0); } LA3: ; tmp0 = mangledynlibproc_538816_839829468(sym0); asgnRefNoCycle((void**) (&(*sym0).loc.r), tmp0); asgnRefNoCycle((void**) (&(*(*sym0).typ).sym), NIM_NIL); (*m0).labels += ((NI) 2); { Tnode292802* n0; Tloc292816 a0; Tnode292802* LOC9; Ropeobj178006* params0; Ropeobj178006* LOC10; Ropeobj178006* load0; TY535235 LOC17; NimStringDesc* LOC18; Tnode292802* last0; NimStringDesc* idx0; if (!iscall0) goto LA7; n0 = (*lib0).path; memset((void*)(&a0), 0, sizeof(a0)); LOC9 = (Tnode292802*)0; LOC9 = HEX5BHEX5D_293238_850551059(n0, ((NI) 0)); initlocexpr_539283_839829468((*m0).initproc, LOC9, (&a0)); LOC10 = (Ropeobj178006*)0; LOC10 = rdloc_538188_839829468(a0); params0 = HEX26_178447_2381377266(LOC10, ((NimStringDesc*) &T839829468_118)); { NI i_559964_839829468; NI HEX3Atmp_560025_839829468; NI LOC12; NI res_560028_839829468; i_559964_839829468 = (NI)0; HEX3Atmp_560025_839829468 = (NI)0; LOC12 = (NI)0; LOC12 = len_293081_850551059(n0); HEX3Atmp_560025_839829468 = (NI)(LOC12 - ((NI) 2)); res_560028_839829468 = ((NI) 1); { while (1) { Tnode292802* LOC15; Ropeobj178006* LOC16; if (!(res_560028_839829468 <= HEX3Atmp_560025_839829468)) goto LA14; i_559964_839829468 = res_560028_839829468; LOC15 = (Tnode292802*)0; LOC15 = HEX5BHEX5D_293238_850551059(n0, i_559964_839829468); initlocexpr_539283_839829468((*m0).initproc, LOC15, (&a0)); LOC16 = (Ropeobj178006*)0; LOC16 = rdloc_538188_839829468(a0); add_178482_2381377266(&params0, LOC16); add_178487_2381377266(&params0, ((NimStringDesc*) &T839829468_110)); res_560028_839829468 += ((NI) 1); } LA14: ; } } memset((void*)LOC17, 0, sizeof(LOC17)); LOC17[0] = tmp0; LOC17[1] = gettypedesc_535671_839829468(m0, (*sym0).typ); LOC17[2] = params0; LOC18 = (NimStringDesc*)0; LOC18 = HEX24_178856_2381377266(extname0); LOC17[3] = makecstring_191638_155036129(LOC18); load0 = HEX25_178905_2381377266(((NimStringDesc*) &T839829468_235), LOC17, 4); last0 = lastson_295364_850551059(n0); { if (!((*last0).kind == ((Tnodekind292020) 58))) goto LA21; last0 = (*last0).kindU.S6.sons->data[((NI) 1)]; } LA21: ; { NimStringDesc* LOC27; if (!!(((*last0).kind == ((Tnodekind292020) 20)))) goto LA25; LOC27 = (NimStringDesc*)0; LOC27 = HEX24_196185_1689653243(T839829468_236); internalerror_196113_155036129(LOC27); } LA25: ; idx0 = (*last0).kindU.S3.strval; { Ropeobj178006** LOC32; if (!((idx0 ? idx0->Sup.len : 0) == ((NI) 0))) goto LA30; LOC32 = (Ropeobj178006**)0; LOC32 = s_529179_3723162438((*m0).initproc, ((Tcprocsection529011) 2)); add_178482_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_178482_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_196100_155036129((*sym0).info, LOC39); } LA28: ; } goto LA5; LA7: ; { TY535235 LOC41; NimStringDesc* LOC42; memset((void*)LOC41, 0, sizeof(LOC41)); LOC41[0] = tmp0; LOC41[1] = gettypedesc_535671_839829468(m0, (*sym0).typ); LOC41[2] = (*lib0).name; LOC42 = (NimStringDesc*)0; LOC42 = HEX24_178856_2381377266(extname0); LOC41[3] = makecstring_191638_155036129(LOC42); appcg_532632_839829468(m0, &(*m0).s[(((Tcfilesection529005) 16))- 0], ((NimStringDesc*) &T839829468_238), LOC41, 4); } LA5: ; memset((void*)LOC43, 0, sizeof(LOC43)); LOC43[0] = (*sym0).loc.r; LOC43[1] = gettypedesc_535671_839829468(m0, (*sym0).loc.t); addf_179205_2381377266(&(*m0).s[(((Tcfilesection529005) 9))- 0], ((NimStringDesc*) &T839829468_239), LOC43, 2); } N_NIMCALL(void, symindynamiclibpartial_560071_839829468)(Tcgen529027* m0, Tsym292834* sym0) { asgnRefNoCycle((void**) (&(*sym0).loc.r), mangledynlibproc_538816_839829468(sym0)); asgnRefNoCycle((void**) (&(*(*sym0).typ).sym), NIM_NIL); } N_NIMCALL(void, genprocnoforward_560906_839829468)(Tcgen529027* m0, Tsym292834* prc0) { { fillprocloc_539201_839829468(prc0); useheader_532369_839829468(m0, prc0); { Ropeobj178006* LOC5; if (!(((*prc0).loc.flags &(1U<<((NU)(((Tlocflag292810) 7))&15U)))!=0)) goto LA3; LOC5 = (Ropeobj178006*)0; LOC5 = cgsym_532403_839829468(m0, (*(*prc0).name).s); goto BeforeRet; } LA3: ; genprocprototype_539254_839829468(m0, prc0); { if (!(((*prc0).loc.flags &(1U<<((NU)(((Tlocflag292810) 3))&15U)))!=0)) goto LA8; } goto LA6; LA8: ; { if (!((*(*prc0).typ).callconv == ((Tcallingconvention292002) 5))) goto LA11; { NIM_BOOL LOC15; LOC15 = (NIM_BOOL)0; LOC15 = containsorincl_268862_2627731572((&(*m0).declaredthings), (*prc0).Sup.id); if (!!(LOC15)) goto LA16; genprocaux_560284_839829468(m0, prc0); } LA16: ; } goto LA6; LA11: ; { Tcgen529027* q0; if (!(((*prc0).loc.flags &(1U<<((NU)(((Tlocflag292810) 4))&15U)))!=0)) goto LA19; q0 = findpendingmodule_532241_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_268862_2627731572((&(*q0).declaredthings), (*prc0).Sup.id); LOC23 = !(LOC25); LA24: ; if (!LOC23) goto LA26; symindynamiclib_559929_839829468(q0, prc0); } goto LA21; LA26: ; { symindynamiclibpartial_560071_839829468(m0, prc0); } LA21: ; } goto LA6; LA19: ; { Tcgen529027* q0; if (!!((((*prc0).flags &(1U<<((NU)(((Tsymflag292184) 5))&31U)))!=0))) goto LA30; q0 = findpendingmodule_532241_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_268862_2627731572((&(*q0).declaredthings), (*prc0).Sup.id); LOC34 = !(LOC36); LA35: ; if (!LOC34) goto LA37; genprocaux_560284_839829468(q0, prc0); } LA37: ; } goto LA6; LA30: ; LA6: ; }BeforeRet: ; } N_NIMCALL(void, genproc_532951_839829468)(Tcgen529027* m0, Tsym292834* prc0) { { { NIM_BOOL LOC3; NIM_BOOL LOC5; LOC3 = (NIM_BOOL)0; LOC3 = (((*prc0).flags &(1U<<((NU)(((Tsymflag292184) 26))&31U)))!=0); if (LOC3) goto LA4; LOC5 = (NIM_BOOL)0; LOC5 = isactivated_561431_839829468(prc0); LOC3 = !(LOC5); LA4: ; if (!LOC3) goto LA6; goto BeforeRet; } LA6: ; fillprocloc_539201_839829468(prc0); { if (!(((*prc0).flags &(1U<<((NU)(((Tsymflag292184) 4))&31U)))!=0)) goto LA10; addforwardedproc_532203_839829468(m0, prc0); } goto LA8; LA10: ; { genprocnoforward_560906_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_532201_839829468 == NIM_NIL)); LA17: ; LOC15 = LOC16; if (!(LOC15)) goto LA18; LOC15 = !((((*prc0).loc.flags &(1U<<((NU)(((Tlocflag292810) 3))&15U)))!=0)); LA18: ; if (!LOC15) goto LA19; genprocprototype_539254_839829468(generatedheader_532201_839829468, prc0); { if (!((*(*prc0).typ).callconv == ((Tcallingconvention292002) 5))) goto LA23; { NIM_BOOL LOC27; LOC27 = (NIM_BOOL)0; LOC27 = containsorincl_268862_2627731572((&(*generatedheader_532201_839829468).declaredthings), (*prc0).Sup.id); if (!!(LOC27)) goto LA28; genprocaux_560284_839829468(generatedheader_532201_839829468, prc0); } LA28: ; } LA23: ; } LA19: ; } LA8: ; }BeforeRet: ; } static N_INLINE(NIM_BOOL, emulatedthreadvars_532949_839829468)(void) { NIM_BOOL result0; result0 = (NIM_BOOL)0; result0 = ((71303168 & ~ gglobaloptions_169130_2607990831)==0); return result0; } N_NIMCALL(void, declarethreadvar_538676_839829468)(Tcgen529027* m0, Tsym292834* s0, NIM_BOOL isextern0) { { NIM_BOOL LOC3; LOC3 = (NIM_BOOL)0; LOC3 = emulatedthreadvars_532949_839829468(); if (!LOC3) goto LA4; { NIM_BOOL LOC8; TY532811 LOC11; LOC8 = (NIM_BOOL)0; LOC8 = containsorincl_268862_2627731572((&nimtvdeclared_538675_839829468), (*s0).Sup.id); if (!!(LOC8)) goto LA9; nimtvdeps_538674_839829468 = (Ttypeseq292836*) incrSeqV2(&(nimtvdeps_538674_839829468)->Sup, sizeof(Ttype292840*)); asgnRefNoCycle((void**) (&nimtvdeps_538674_839829468->data[nimtvdeps_538674_839829468->Sup.len]), (*s0).loc.t); ++nimtvdeps_538674_839829468->Sup.len; memset((void*)LOC11, 0, sizeof(LOC11)); LOC11[0] = gettypedesc_535671_839829468(m0, (*s0).loc.t); LOC11[1] = (*s0).loc.r; addf_179205_2381377266(&nimtv_538656_839829468, ((NimStringDesc*) &T839829468_54), LOC11, 2); } LA9: ; } goto LA1; LA4: ; { Ropeobj178006* LOC21; TY178507 LOC22; { if (!isextern0) goto LA15; add_178487_2381377266(&(*m0).s[(((Tcfilesection529005) 9))- 0], ((NimStringDesc*) &T839829468_240)); } LA15: ; { if (!((gglobaloptions_169130_2607990831 &((NU64)1<<((NU)(((Tglobaloption169013) 22))&63U)))!=0)) goto LA19; add_178487_2381377266(&(*m0).s[(((Tcfilesection529005) 9))- 0], ((NimStringDesc*) &T839829468_241)); } LA19: ; LOC21 = (Ropeobj178006*)0; LOC21 = gettypedesc_535671_839829468(m0, (*s0).loc.t); add_178482_2381377266(&(*m0).s[(((Tcfilesection529005) 9))- 0], LOC21); memset((void*)LOC22, 0, sizeof(LOC22)); LOC22[0] = (*s0).loc.r; addf_179205_2381377266(&(*m0).s[(((Tcfilesection529005) 9))- 0], ((NimStringDesc*) &T839829468_242), LOC22, 1); } LA1: ; } N_NIMCALL(void, genvarprototypeaux_544254_839829468)(Tcgen529027* m0, Tsym292834* sym0) { Ropeobj178006* LOC1; { useheader_532369_839829468(m0, sym0); LOC1 = (Ropeobj178006*)0; LOC1 = manglename_533205_839829468(sym0); fillloc_532282_839829468((&(*sym0).loc), ((Tlockind292808) 3), (*sym0).typ, LOC1, ((Tstorageloc292812) 3)); { NIM_BOOL LOC4; LOC4 = (NIM_BOOL)0; LOC4 = (((*sym0).loc.flags &(1U<<((NU)(((Tlocflag292810) 3))&15U)))!=0); if (LOC4) goto LA5; LOC4 = containsorincl_268862_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)(((Tsymflag292184) 22))&31U)))!=0)) goto LA14; declarethreadvar_538676_839829468(m0, sym0, NIM_TRUE); } goto LA12; LA14: ; { Ropeobj178006* LOC17; TY178507 LOC30; add_178487_2381377266(&(*m0).s[(((Tcfilesection529005) 9))- 0], ((NimStringDesc*) &T839829468_240)); LOC17 = (Ropeobj178006*)0; LOC17 = gettypedesc_535671_839829468(m0, (*sym0).loc.t); add_178482_2381377266(&(*m0).s[(((Tcfilesection529005) 9))- 0], LOC17); { if (!(((*sym0).loc.flags &(1U<<((NU)(((Tlocflag292810) 4))&15U)))!=0)) goto LA20; add_178487_2381377266(&(*m0).s[(((Tcfilesection529005) 9))- 0], ((NimStringDesc*) &T839829468_53)); } LA20: ; { if (!(((*sym0).flags &(1U<<((NU)(((Tsymflag292184) 8))&31U)))!=0)) goto LA24; add_178487_2381377266(&(*m0).s[(((Tcfilesection529005) 9))- 0], ((NimStringDesc*) &T839829468_121)); } LA24: ; { if (!(((*sym0).flags &(1U<<((NU)(((Tsymflag292184) 7))&31U)))!=0)) goto LA28; add_178487_2381377266(&(*m0).s[(((Tcfilesection529005) 9))- 0], ((NimStringDesc*) &T839829468_122)); } LA28: ; memset((void*)LOC30, 0, sizeof(LOC30)); LOC30[0] = (*sym0).loc.r; addf_179205_2381377266(&(*m0).s[(((Tcfilesection529005) 9))- 0], ((NimStringDesc*) &T839829468_242), LOC30, 1); } LA12: ; } LA10: ; }BeforeRet: ; } N_NIMCALL(void, genvarprototype_539236_839829468)(Tcgen529027* m0, Tsym292834* sym0) { genvarprototypeaux_544254_839829468(m0, sym0); } N_NIMCALL(Ropeobj178006*, cgsym_532403_839829468)(Tcgen529027* m0, NimStringDesc* name0) { Ropeobj178006* result0; Tsym292834* sym0; result0 = (Ropeobj178006*)0; sym0 = getcompilerproc_338746_3937434831(name0); { if (!!((sym0 == NIM_NIL))) goto LA3; switch ((*sym0).kind) { case ((Tsymkind292435) 12): case ((Tsymkind292435) 13): case ((Tsymkind292435) 15): case ((Tsymkind292435) 14): { genproc_532951_839829468(m0, sym0); } break; case ((Tsymkind292435) 8): case ((Tsymkind292435) 11): case ((Tsymkind292435) 9): { genvarprototype_539236_839829468(m0, sym0); } break; case ((Tsymkind292435) 7): { Ropeobj178006* LOC8; LOC8 = (Ropeobj178006*)0; LOC8 = gettypedesc_535671_839829468(m0, (*sym0).typ); } break; default: { NimStringDesc* LOC10; LOC10 = (NimStringDesc*)0; LOC10 = rawNewString(name0->Sup.len + reprEnum((NI)(*sym0).kind, (&NTI292435))->Sup.len + 9); appendString(LOC10, ((NimStringDesc*) &T839829468_243)); appendString(LOC10, name0); appendString(LOC10, ((NimStringDesc*) &T839829468_244)); appendString(LOC10, reprEnum((NI)(*sym0).kind, (&NTI292435))); internalerror_196113_155036129(LOC10); } break; } } goto LA1; LA3: ; { rawmessage_194612_155036129(((Tmsgkind191002) 68), name0); } LA1: ; result0 = (*sym0).loc.r; return result0; } N_NIMCALL(Ropeobj178006*, ropecg_532407_839829468)(Tcgen529027* m0, NimStringDesc* frmt0, Ropeobj178006** args0, NI args0Len0) { Ropeobj178006* result0; NI i0; NI length0; NI num0; result0 = (Ropeobj178006*)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_178487_2381377266(&result0, ((NimStringDesc*) &T839829468_19)); i0 += ((NI) 1); } break; case 35: { i0 += ((NI) 1); add_178482_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_196113_155036129(LOC22); } LA20: ; add_178482_2381377266(&result0, args0[(NI)(j0 - ((NI) 1))]); } break; case 110: { { if (!!(((goptions_169128_2607990831 &(1U<<((NU)(((Toption169009) 10))&31U)))!=0))) goto LA27; add_178482_2381377266(&result0, rnl_178903_2381377266); } LA27: ; i0 += ((NI) 1); } break; case 78: { add_178482_2381377266(&result0, rnl_178903_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_196113_155036129(LOC31); } break; } } goto LA3; LA5: ; { NIM_BOOL LOC33; NI j0; NimStringDesc* ident0; Ropeobj178006* 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 = (Ropeobj178006*)0; LOC39 = cgsym_532403_839829468(m0, ident0); add_178482_2381377266(&result0, LOC39); } goto LA3; LA35: ; { NIM_BOOL LOC41; NI j0; NimStringDesc* LOC47; Ropeobj178006* 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_178856_2381377266(args0[(NI)(j0 - ((NI) 1))]); LOC48 = (Ropeobj178006*)0; LOC48 = cgsym_532403_839829468(m0, LOC47); add_178482_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_178487_2381377266(&result0, LOC62); } LA60: ; } LA2: ; } return result0; } static N_INLINE(NIM_BOOL, crossescppboundary_560754_839829468)(Tcgen529027* m0, Tsym292834* sym0) { NIM_BOOL result0; NIM_BOOL LOC1; NIM_BOOL LOC2; Tsym292834* LOC4; result0 = (NIM_BOOL)0; LOC1 = (NIM_BOOL)0; LOC2 = (NIM_BOOL)0; LOC2 = (((*(*m0).module).flags &(1U<<((NU)(((Tsymflag292184) 27))&31U)))!=0); if (!(LOC2)) goto LA3; LOC4 = (Tsym292834*)0; LOC4 = getmodule_299123_2984716966(sym0); LOC2 = !((((*LOC4).flags &(1U<<((NU)(((Tsymflag292184) 27))&31U)))!=0)); LA3: ; LOC1 = LOC2; if (!(LOC1)) goto LA5; LOC1 = !((gcmd_169132_2607990831 == ((Tcommands169076) 2))); LA5: ; result0 = LOC1; return result0; } N_NIMCALL(void, genprocprototype_539254_839829468)(Tcgen529027* m0, Tsym292834* sym0) { { useheader_532369_839829468(m0, sym0); { if (!(((*sym0).loc.flags &(1U<<((NU)(((Tlocflag292810) 3))&15U)))!=0)) goto LA3; goto BeforeRet; } LA3: ; { if (!(((*sym0).loc.flags &(1U<<((NU)(((Tlocflag292810) 4))&15U)))!=0)) goto LA7; { NIM_BOOL LOC11; Tsym292834* LOC12; NIM_BOOL LOC14; TY532811 LOC17; Ropeobj178006* LOC18; LOC11 = (NIM_BOOL)0; LOC12 = (Tsym292834*)0; LOC12 = getmodule_299123_2984716966(sym0); LOC11 = !(((*LOC12).Sup.id == (*(*m0).module).Sup.id)); if (!(LOC11)) goto LA13; LOC14 = (NIM_BOOL)0; LOC14 = containsorincl_268862_2627731572((&(*m0).declaredthings), (*sym0).Sup.id); LOC11 = !(LOC14); LA13: ; if (!LOC11) goto LA15; memset((void*)LOC17, 0, sizeof(LOC17)); LOC17[0] = gettypedesc_535671_839829468(m0, (*sym0).loc.t); LOC17[1] = mangledynlibproc_538816_839829468(sym0); LOC18 = (Ropeobj178006*)0; LOC18 = ropecg_532407_839829468(NIM_NIL, ((NimStringDesc*) &T839829468_245), LOC17, 2); add_178482_2381377266(&(*m0).s[(((Tcfilesection529005) 9))- 0], LOC18); } LA15: ; } goto LA5; LA7: ; { NIM_BOOL LOC20; Ropeobj178006* header0; TY178507 LOC47; Ropeobj178006* LOC48; LOC20 = (NIM_BOOL)0; LOC20 = containsorincl_268862_2627731572((&(*m0).declaredprotos), (*sym0).Sup.id); if (!!(LOC20)) goto LA21; header0 = genprocheader_535867_839829468(m0, sym0); { NIM_BOOL LOC25; LOC25 = (NIM_BOOL)0; LOC25 = (((*sym0).flags &(1U<<((NU)(((Tsymflag292184) 14))&31U)))!=0); if (!(LOC25)) goto LA26; LOC25 = ((Cc_273413_2528170400[(ccompiler_273431_2528170400)- 1].Field20 &(1U<<((NU)(((Tinfoccprop273004) 6))&7U)))!=0); LA26: ; if (!LOC25) goto LA27; header0 = HEX26_178452_2381377266(((NimStringDesc*) &T839829468_213), header0); } LA27: ; { NIM_BOOL LOC31; LOC31 = (NIM_BOOL)0; LOC31 = !(((*(*sym0).typ).callconv == ((Tcallingconvention292002) 5))); if (!(LOC31)) goto LA32; LOC31 = crossescppboundary_560754_839829468(m0, sym0); LA32: ; if (!LOC31) goto LA33; header0 = HEX26_178452_2381377266(((NimStringDesc*) &T839829468_246), header0); } LA33: ; { NIM_BOOL LOC37; LOC37 = (NIM_BOOL)0; LOC37 = (((*sym0).flags &(1U<<((NU)(((Tsymflag292184) 9))&31U)))!=0); if (!(LOC37)) goto LA38; LOC37 = ((Cc_273413_2528170400[(ccompiler_273431_2528170400)- 1].Field20 &(1U<<((NU)(((Tinfoccprop273004) 7))&7U)))!=0); LA38: ; if (!LOC37) goto LA39; add_178487_2381377266(&header0, ((NimStringDesc*) &T839829468_247)); } LA39: ; { NIM_BOOL LOC43; LOC43 = (NIM_BOOL)0; LOC43 = (((*sym0).flags &(1U<<((NU)(((Tsymflag292184) 14))&31U)))!=0); if (!(LOC43)) goto LA44; LOC43 = ((Cc_273413_2528170400[(ccompiler_273431_2528170400)- 1].Field20 &(1U<<((NU)(((Tinfoccprop273004) 7))&7U)))!=0); LA44: ; if (!LOC43) goto LA45; add_178487_2381377266(&header0, ((NimStringDesc*) &T839829468_248)); } LA45: ; memset((void*)LOC47, 0, sizeof(LOC47)); LOC47[0] = header0; LOC48 = (Ropeobj178006*)0; LOC48 = ropecg_532407_839829468(NIM_NIL, ((NimStringDesc*) &T839829468_191), LOC47, 1); add_178482_2381377266(&(*m0).s[(((Tcfilesection529005) 7))- 0], LOC48); } goto LA5; LA21: ; LA5: ; }BeforeRet: ; } static N_INLINE(NIM_BOOL, usesnativegc_169177_2607990831)(void) { NIM_BOOL result0; result0 = (NIM_BOOL)0; result0 = (((Tgcmode169080) 5) <= gselectedgc_169133_2607990831); return result0; } N_NIMCALL(void, genrefassign_538311_839829468)(Tcproc529021* p0, Tloc292816 dest0, Tloc292816 src0, Tassignmentflag538302Set flags0) { { NIM_BOOL LOC3; NIM_BOOL LOC5; TY532811 LOC8; LOC3 = (NIM_BOOL)0; LOC3 = (dest0.s == ((Tstorageloc292812) 2)); if (LOC3) goto LA4; LOC5 = (NIM_BOOL)0; LOC5 = usesnativegc_169177_2607990831(); LOC3 = !(LOC5); LA4: ; if (!LOC3) goto LA6; memset((void*)LOC8, 0, sizeof(LOC8)); LOC8[0] = rdloc_538188_839829468(dest0); LOC8[1] = rdloc_538188_839829468(src0); linefmt_532714_839829468(p0, ((Tcprocsection529011) 2), ((NimStringDesc*) &T839829468_123), LOC8, 2); } goto LA1; LA6: ; { if (!(dest0.s == ((Tstorageloc292812) 3))) goto LA10; { NIM_BOOL LOC14; TY532811 LOC17; LOC14 = (NIM_BOOL)0; LOC14 = canformacycle_320123_3876443242(dest0.t); if (!LOC14) goto LA15; memset((void*)LOC17, 0, sizeof(LOC17)); LOC17[0] = addrloc_538204_839829468(dest0); LOC17[1] = rdloc_538188_839829468(src0); linefmt_532714_839829468(p0, ((Tcprocsection529011) 2), ((NimStringDesc*) &T839829468_249), LOC17, 2); } goto LA12; LA15: ; { TY532811 LOC19; memset((void*)LOC19, 0, sizeof(LOC19)); LOC19[0] = addrloc_538204_839829468(dest0); LOC19[1] = rdloc_538188_839829468(src0); linefmt_532714_839829468(p0, ((Tcprocsection529011) 2), ((NimStringDesc*) &T839829468_250), LOC19, 2); } LA12: ; } goto LA1; LA10: ; { TY532811 LOC21; memset((void*)LOC21, 0, sizeof(LOC21)); LOC21[0] = addrloc_538204_839829468(dest0); LOC21[1] = rdloc_538188_839829468(src0); linefmt_532714_839829468(p0, ((Tcprocsection529011) 2), ((NimStringDesc*) &T839829468_251), LOC21, 2); } LA1: ; } N_NIMCALL(void, optasgnloc_549788_839829468)(Tloc292816 a0, Ttype292840* t0, Ropeobj178006* field0, Tloc292816* Result) { Ropeobj178006* LOC1; Ropeobj178006* LOC2; (*Result).k = ((Tlockind292808) 5); (*Result).s = a0.s; unsureAsgnRef((void**) (&(*Result).t), t0); LOC1 = (Ropeobj178006*)0; LOC1 = rdloc_538188_839829468(a0); LOC2 = (Ropeobj178006*)0; LOC2 = HEX26_178447_2381377266(LOC1, ((NimStringDesc*) &T839829468_257)); unsureAsgnRef((void**) (&(*Result).r), HEX26_178418_2381377266(LOC2, field0)); } N_NIMCALL(void, genoptasgntuple_550001_839829468)(Tcproc529021* p0, Tloc292816 dest0, Tloc292816 src0, Tassignmentflag538302Set flags0) { Tassignmentflag538302Set newflags0; Ttype292840* t_550053_839829468; Ttype292840* LOC9; { if (!(src0.s == ((Tstorageloc292812) 1))) goto LA3; newflags0 = (flags0 | 1); } goto LA1; LA3: ; { if (!(((*dest0.t).flags &(1U<<((NU)(((Ttypeflag292431) 6))&31U)))!=0)) goto LA6; newflags0 = (flags0 & ~ 1); } goto LA1; LA6: ; { newflags0 = flags0; } LA1: ; LOC9 = (Ttype292840*)0; LOC9 = skiptypes_296099_850551059(dest0.t, IL64(211106232576256)); t_550053_839829468 = getuniquetype_528640_2036603609(LOC9); { NI i_550071_839829468; NI HEX3Atmp_550077_839829468; NI LOC11; NI res_550080_839829468; i_550071_839829468 = (NI)0; HEX3Atmp_550077_839829468 = (NI)0; LOC11 = (NI)0; LOC11 = len_295339_850551059(t_550053_839829468); HEX3Atmp_550077_839829468 = (LOC11 - 1); res_550080_839829468 = ((NI) 0); { while (1) { Ttype292840* t0; Ropeobj178006* field0; TY178507 LOC14; Tloc292816 LOC15; Tloc292816 LOC16; if (!(res_550080_839829468 <= HEX3Atmp_550077_839829468)) goto LA13; i_550071_839829468 = res_550080_839829468; t0 = (*t_550053_839829468).sons->data[i_550071_839829468]; memset((void*)LOC14, 0, sizeof(LOC14)); LOC14[0] = rope_178401_2381377266(((NI64) (i_550071_839829468))); field0 = HEX25_178905_2381377266(((NimStringDesc*) &T839829468_260), LOC14, 1); memset((void*)(&LOC15), 0, sizeof(LOC15)); optasgnloc_549788_839829468(dest0, t0, field0, (&LOC15)); memset((void*)(&LOC16), 0, sizeof(LOC16)); optasgnloc_549788_839829468(src0, t0, field0, (&LOC16)); genassignment_539264_839829468(p0, LOC15, LOC16, newflags0); res_550080_839829468 += ((NI) 1); } LA13: ; } } } N_NIMCALL(void, gengenericasgn_550167_839829468)(Tcproc529021* p0, Tloc292816 dest0, Tloc292816 src0, Tassignmentflag538302Set flags0) { { NIM_BOOL LOC3; Ttype292840* LOC5; LOC3 = (NIM_BOOL)0; LOC3 = !(((flags0 &(1U<<((NU)(((Tassignmentflag538302) 0))&7U)))!=0)); if (LOC3) goto LA4; LOC5 = (Ttype292840*)0; LOC5 = skiptypes_296099_850551059(dest0.t, IL64(211106242013440)); LOC3 = (((*LOC5).flags &(1U<<((NU)(((Ttypeflag292431) 6))&31U)))!=0); LA4: ; if (!LOC3) goto LA6; { NIM_BOOL LOC10; NIM_BOOL LOC12; TY535238 LOC15; LOC10 = (NIM_BOOL)0; LOC10 = (dest0.s == ((Tstorageloc292812) 2)); if (LOC10) goto LA11; LOC12 = (NIM_BOOL)0; LOC12 = usesnativegc_169177_2607990831(); LOC10 = !(LOC12); LA11: ; if (!LOC10) goto LA13; usestringh_532345_839829468((*p0).module); memset((void*)LOC15, 0, sizeof(LOC15)); LOC15[0] = addrloc_538204_839829468(dest0); LOC15[1] = addrloc_538204_839829468(src0); LOC15[2] = rdloc_538188_839829468(dest0); linefmt_532714_839829468(p0, ((Tcprocsection529011) 2), ((NimStringDesc*) &T839829468_261), LOC15, 3); } goto LA8; LA13: ; { TY535238 LOC17; memset((void*)LOC17, 0, sizeof(LOC17)); LOC17[0] = addrloc_538204_839829468(dest0); LOC17[1] = addrloc_538204_839829468(src0); LOC17[2] = gentypeinfo_535941_839829468((*p0).module, dest0.t); linefmt_532714_839829468(p0, ((Tcprocsection529011) 2), ((NimStringDesc*) &T839829468_262), LOC17, 3); } LA8: ; } goto LA1; LA6: ; { TY535238 LOC19; memset((void*)LOC19, 0, sizeof(LOC19)); LOC19[0] = addrloc_538204_839829468(dest0); LOC19[1] = addrloc_538204_839829468(src0); LOC19[2] = gentypeinfo_535941_839829468((*p0).module, dest0.t); linefmt_532714_839829468(p0, ((Tcprocsection529011) 2), ((NimStringDesc*) &T839829468_263), LOC19, 3); } LA1: ; } N_NIMCALL(NI, asgncomplexity_549750_839829468)(Tnode292802* n0) { NI result0; result0 = (NI)0; { if (!!((n0 == NIM_NIL))) goto LA3; switch ((*n0).kind) { case ((Tnodekind292020) 3): { result0 = ((NI) 1); } break; case ((Tnodekind292020) 139): { result0 = ((NI) 100); } break; case ((Tnodekind292020) 138): { { Tnode292802* t_549767_839829468; t_549767_839829468 = (Tnode292802*)0; { NI i_549781_839829468; NI HEX3Atmp_549783_839829468; NI LOC10; NI res_549785_839829468; i_549781_839829468 = (NI)0; HEX3Atmp_549783_839829468 = (NI)0; LOC10 = (NI)0; LOC10 = len_293081_850551059(n0); HEX3Atmp_549783_839829468 = (LOC10 - 1); res_549785_839829468 = ((NI) 0); { while (1) { NI LOC13; if (!(res_549785_839829468 <= HEX3Atmp_549783_839829468)) goto LA12; i_549781_839829468 = res_549785_839829468; t_549767_839829468 = (*n0).kindU.S6.sons->data[i_549781_839829468]; LOC13 = (NI)0; LOC13 = asgncomplexity_549750_839829468(t_549767_839829468); result0 += LOC13; res_549785_839829468 += ((NI) 1); } LA12: ; } } } } break; default: { } break; } } LA3: ; return result0; } N_NIMCALL(void, genoptasgnobject_550084_839829468)(Tcproc529021* p0, Tloc292816 dest0, Tloc292816 src0, Tassignmentflag538302Set flags0, Tnode292802* t0) { Tassignmentflag538302Set newflags0; { { if (!(t0 == NIM_NIL)) goto LA3; goto BeforeRet; } LA3: ; { if (!(src0.s == ((Tstorageloc292812) 1))) goto LA7; newflags0 = (flags0 | 1); } goto LA5; LA7: ; { if (!(((*dest0.t).flags &(1U<<((NU)(((Ttypeflag292431) 6))&31U)))!=0)) goto LA10; newflags0 = (flags0 & ~ 1); } goto LA5; LA10: ; { newflags0 = flags0; } LA5: ; switch ((*t0).kind) { case ((Tnodekind292020) 3): { Tsym292834* field0; Tloc292816 LOC14; Tloc292816 LOC15; field0 = (*t0).kindU.S4.sym; memset((void*)(&LOC14), 0, sizeof(LOC14)); optasgnloc_549788_839829468(dest0, (*field0).typ, (*field0).loc.r, (&LOC14)); memset((void*)(&LOC15), 0, sizeof(LOC15)); optasgnloc_549788_839829468(src0, (*field0).typ, (*field0).loc.r, (&LOC15)); genassignment_539264_839829468(p0, LOC14, LOC15, newflags0); } break; case ((Tnodekind292020) 138): { { Tnode292802* child_550155_839829468; child_550155_839829468 = (Tnode292802*)0; { NI i_550160_839829468; NI HEX3Atmp_550162_839829468; NI LOC19; NI res_550164_839829468; i_550160_839829468 = (NI)0; HEX3Atmp_550162_839829468 = (NI)0; LOC19 = (NI)0; LOC19 = len_293081_850551059(t0); HEX3Atmp_550162_839829468 = (LOC19 - 1); res_550164_839829468 = ((NI) 0); { while (1) { if (!(res_550164_839829468 <= HEX3Atmp_550162_839829468)) goto LA21; i_550160_839829468 = res_550164_839829468; child_550155_839829468 = (*t0).kindU.S6.sons->data[i_550160_839829468]; genoptasgnobject_550084_839829468(p0, dest0, src0, newflags0, child_550155_839829468); res_550164_839829468 += ((NI) 1); } LA21: ; } } } } break; default: { } break; } }BeforeRet: ; } N_NIMCALL(void, genassignment_539264_839829468)(Tcproc529021* p0, Tloc292816 dest0, Tloc292816 src0, Tassignmentflag538302Set flags0) { Ttype292840* ty0; { { NIM_BOOL LOC3; TY532811 LOC7; LOC3 = (NIM_BOOL)0; LOC3 = !((src0.t == NIM_NIL)); if (!(LOC3)) goto LA4; LOC3 = ((*src0.t).kind == ((Ttypekind292244) 21)); LA4: ; if (!LOC3) goto LA5; memset((void*)LOC7, 0, sizeof(LOC7)); LOC7[0] = rdloc_538188_839829468(dest0); LOC7[1] = rdloc_538188_839829468(src0); linefmt_532714_839829468(p0, ((Tcprocsection529011) 2), ((NimStringDesc*) &T839829468_123), LOC7, 2); goto BeforeRet; } LA5: ; ty0 = skiptypes_296099_850551059(dest0.t, IL64(211106233624832)); switch ((*ty0).kind) { case ((Ttypekind292244) 22): { genrefassign_538311_839829468(p0, dest0, src0, flags0); } break; case ((Ttypekind292244) 24): { { NIM_BOOL LOC12; LOC12 = (NIM_BOOL)0; LOC12 = !(((flags0 &(1U<<((NU)(((Tassignmentflag538302) 0))&7U)))!=0)); if (!(LOC12)) goto LA13; LOC12 = !((src0.s == ((Tstorageloc292812) 1))); LA13: ; if (!LOC12) goto LA14; genrefassign_538311_839829468(p0, dest0, src0, flags0); } goto LA10; LA14: ; { TY535238 LOC17; memset((void*)LOC17, 0, sizeof(LOC17)); LOC17[0] = addrloc_538204_839829468(dest0); LOC17[1] = rdloc_538188_839829468(src0); LOC17[2] = gentypeinfo_535941_839829468((*p0).module, dest0.t); linefmt_532714_839829468(p0, ((Tcprocsection529011) 2), ((NimStringDesc*) &T839829468_252), LOC17, 3); } LA10: ; } break; case ((Ttypekind292244) 28): { { NIM_BOOL LOC21; LOC21 = (NIM_BOOL)0; LOC21 = !(((flags0 &(1U<<((NU)(((Tassignmentflag538302) 0))&7U)))!=0)); if (!(LOC21)) goto LA22; LOC21 = !((src0.s == ((Tstorageloc292812) 1))); LA22: ; if (!LOC21) goto LA23; genrefassign_538311_839829468(p0, dest0, src0, flags0); } goto LA19; LA23: ; { { NIM_BOOL LOC28; NIM_BOOL LOC30; TY532811 LOC33; LOC28 = (NIM_BOOL)0; LOC28 = (dest0.s == ((Tstorageloc292812) 2)); if (LOC28) goto LA29; LOC30 = (NIM_BOOL)0; LOC30 = usesnativegc_169177_2607990831(); LOC28 = !(LOC30); LA29: ; if (!LOC28) goto LA31; memset((void*)LOC33, 0, sizeof(LOC33)); LOC33[0] = rdloc_538188_839829468(dest0); LOC33[1] = rdloc_538188_839829468(src0); linefmt_532714_839829468(p0, ((Tcprocsection529011) 2), ((NimStringDesc*) &T839829468_253), LOC33, 2); } goto LA26; LA31: ; { Tloc292816 tmp0; TY535238 LOC37; TY178507 LOC38; if (!(dest0.s == ((Tstorageloc292812) 3))) goto LA35; memset((void*)(&tmp0), 0, sizeof(tmp0)); gettemp_537032_839829468(p0, ty0, (&tmp0), NIM_FALSE); memset((void*)LOC37, 0, sizeof(LOC37)); LOC37[0] = rdloc_538188_839829468(dest0); LOC37[1] = rdloc_538188_839829468(src0); LOC37[2] = rdloc_538188_839829468(tmp0); linefmt_532714_839829468(p0, ((Tcprocsection529011) 2), ((NimStringDesc*) &T839829468_254), LOC37, 3); memset((void*)LOC38, 0, sizeof(LOC38)); LOC38[0] = rdloc_538188_839829468(tmp0); linefmt_532714_839829468(p0, ((Tcprocsection529011) 2), ((NimStringDesc*) &T839829468_255), LOC38, 1); } goto LA26; LA35: ; { TY532811 LOC40; memset((void*)LOC40, 0, sizeof(LOC40)); LOC40[0] = addrloc_538204_839829468(dest0); LOC40[1] = rdloc_538188_839829468(src0); linefmt_532714_839829468(p0, ((Tcprocsection529011) 2), ((NimStringDesc*) &T839829468_256), LOC40, 2); } LA26: ; } LA19: ; } break; case ((Ttypekind292244) 25): { { NIM_BOOL LOC44; Tloc292816 a0; Ropeobj178006* LOC47; Tloc292816 LOC48; Tloc292816 b0; Ropeobj178006* LOC49; Tloc292816 LOC50; TY532811 LOC51; LOC44 = (NIM_BOOL)0; LOC44 = needscomplexassignment_533509_839829468(dest0.t); if (!LOC44) goto LA45; memset((void*)(&a0), 0, sizeof(a0)); LOC47 = (Ropeobj178006*)0; LOC47 = rope_178277_2381377266(((NimStringDesc*) &T839829468_258)); memset((void*)(&LOC48), 0, sizeof(LOC48)); optasgnloc_549788_839829468(dest0, dest0.t, LOC47, (&LOC48)); memcpy((void*)(&a0), (NIM_CONST void*)(&LOC48), sizeof(a0)); memset((void*)(&b0), 0, sizeof(b0)); LOC49 = (Ropeobj178006*)0; LOC49 = rope_178277_2381377266(((NimStringDesc*) &T839829468_258)); memset((void*)(&LOC50), 0, sizeof(LOC50)); optasgnloc_549788_839829468(src0, dest0.t, LOC49, (&LOC50)); memcpy((void*)(&b0), (NIM_CONST void*)(&LOC50), sizeof(b0)); genrefassign_538311_839829468(p0, a0, b0, flags0); memset((void*)LOC51, 0, sizeof(LOC51)); LOC51[0] = rdloc_538188_839829468(dest0); LOC51[1] = rdloc_538188_839829468(src0); linefmt_532714_839829468(p0, ((Tcprocsection529011) 2), ((NimStringDesc*) &T839829468_259), LOC51, 2); } goto LA42; LA45: ; { TY532811 LOC53; memset((void*)LOC53, 0, sizeof(LOC53)); LOC53[0] = rdloc_538188_839829468(dest0); LOC53[1] = rdloc_538188_839829468(src0); linefmt_532714_839829468(p0, ((Tcprocsection529011) 2), ((NimStringDesc*) &T839829468_123), LOC53, 2); } LA42: ; } break; case ((Ttypekind292244) 18): { { NIM_BOOL LOC57; LOC57 = (NIM_BOOL)0; LOC57 = needscomplexassignment_533509_839829468(dest0.t); if (!LOC57) goto LA58; { NI LOC62; LOC62 = (NI)0; LOC62 = len_295339_850551059(dest0.t); if (!(LOC62 <= ((NI) 4))) goto LA63; genoptasgntuple_550001_839829468(p0, dest0, src0, flags0); } goto LA60; LA63: ; { gengenericasgn_550167_839829468(p0, dest0, src0, flags0); } LA60: ; } goto LA55; LA58: ; { TY532811 LOC67; memset((void*)LOC67, 0, sizeof(LOC67)); LOC67[0] = rdloc_538188_839829468(dest0); LOC67[1] = rdloc_538188_839829468(src0); linefmt_532714_839829468(p0, ((Tcprocsection529011) 2), ((NimStringDesc*) &T839829468_123), LOC67, 2); } LA55: ; } break; case ((Ttypekind292244) 17): { { NIM_BOOL LOC71; TY532811 LOC74; LOC71 = (NIM_BOOL)0; LOC71 = isimportedcpptype_533476_839829468(ty0); if (!LOC71) goto LA72; memset((void*)LOC74, 0, sizeof(LOC74)); LOC74[0] = rdloc_538188_839829468(dest0); LOC74[1] = rdloc_538188_839829468(src0); linefmt_532714_839829468(p0, ((Tcprocsection529011) 2), ((NimStringDesc*) &T839829468_123), LOC74, 2); } goto LA69; LA72: ; { NIM_BOOL LOC76; LOC76 = (NIM_BOOL)0; LOC76 = isobjlackingtypefield_533513_839829468(ty0); if (!!(LOC76)) goto LA77; gengenericasgn_550167_839829468(p0, dest0, src0, flags0); } goto LA69; LA77: ; { NIM_BOOL LOC80; LOC80 = (NIM_BOOL)0; LOC80 = needscomplexassignment_533509_839829468(ty0); if (!LOC80) goto LA81; { NIM_BOOL LOC85; NI LOC87; Ropeobj178006* LOC90; LOC85 = (NIM_BOOL)0; LOC85 = (*ty0).sons->data[((NI) 0)] == 0; if (!(LOC85)) goto LA86; LOC87 = (NI)0; LOC87 = asgncomplexity_549750_839829468((*ty0).n); LOC85 = (LOC87 <= ((NI) 4)); LA86: ; if (!LOC85) goto LA88; LOC90 = (Ropeobj178006*)0; LOC90 = gettypedesc_535671_839829468((*p0).module, ty0); ty0 = getuniquetype_528640_2036603609(ty0); { NimStringDesc* LOC95; if (!!(!(((*ty0).n == NIM_NIL)))) goto LA93; LOC95 = (NimStringDesc*)0; LOC95 = HEX24_196185_1689653243(T839829468_264); internalerror_196113_155036129(LOC95); } LA93: ; genoptasgnobject_550084_839829468(p0, dest0, src0, flags0, (*ty0).n); } goto LA83; LA88: ; { gengenericasgn_550167_839829468(p0, dest0, src0, flags0); } LA83: ; } goto LA69; LA81: ; { TY532811 LOC98; memset((void*)LOC98, 0, sizeof(LOC98)); LOC98[0] = rdloc_538188_839829468(dest0); LOC98[1] = rdloc_538188_839829468(src0); linefmt_532714_839829468(p0, ((Tcprocsection529011) 2), ((NimStringDesc*) &T839829468_123), LOC98, 2); } LA69: ; } break; case ((Ttypekind292244) 16): case ((Ttypekind292244) 4): { { NIM_BOOL LOC102; LOC102 = (NIM_BOOL)0; LOC102 = needscomplexassignment_533509_839829468(dest0.t); if (!LOC102) goto LA103; gengenericasgn_550167_839829468(p0, dest0, src0, flags0); } goto LA100; LA103: ; { TY535238 LOC106; usestringh_532345_839829468((*p0).module); memset((void*)LOC106, 0, sizeof(LOC106)); LOC106[0] = rdloc_538188_839829468(dest0); LOC106[1] = rdloc_538188_839829468(src0); LOC106[2] = gettypedesc_535671_839829468((*p0).module, ty0); linefmt_532714_839829468(p0, ((Tcprocsection529011) 2), ((NimStringDesc*) &T839829468_261), LOC106, 3); } LA100: ; } break; case ((Ttypekind292244) 27): case ((Ttypekind292244) 48): { { NIM_BOOL LOC110; TY535238 LOC113; LOC110 = (NIM_BOOL)0; LOC110 = needscomplexassignment_533509_839829468(dest0.t); if (!LOC110) goto LA111; memset((void*)LOC113, 0, sizeof(LOC113)); LOC113[0] = addrloc_538204_839829468(dest0); LOC113[1] = addrloc_538204_839829468(src0); LOC113[2] = gentypeinfo_535941_839829468((*p0).module, dest0.t); linefmt_532714_839829468(p0, ((Tcprocsection529011) 2), ((NimStringDesc*) &T839829468_266), LOC113, 3); } goto LA108; LA111: ; { TY532811 LOC115; usestringh_532345_839829468((*p0).module); memset((void*)LOC115, 0, sizeof(LOC115)); LOC115[0] = rdloc_538188_839829468(dest0); LOC115[1] = rdloc_538188_839829468(src0); linefmt_532714_839829468(p0, ((Tcprocsection529011) 2), ((NimStringDesc*) &T839829468_267), LOC115, 2); } LA108: ; } break; case ((Ttypekind292244) 19): { { Tctypekind529007 LOC119; TY535238 LOC122; NI64 LOC123; LOC119 = (Tctypekind529007)0; LOC119 = maptype_533393_839829468(ty0); if (!(LOC119 == ((Tctypekind529007) 17))) goto LA120; usestringh_532345_839829468((*p0).module); memset((void*)LOC122, 0, sizeof(LOC122)); LOC122[0] = rdloc_538188_839829468(dest0); LOC122[1] = rdloc_538188_839829468(src0); LOC123 = (NI64)0; LOC123 = getsize_320135_3876443242(dest0.t); LOC122[2] = rope_178401_2381377266(LOC123); linefmt_532714_839829468(p0, ((Tcprocsection529011) 2), ((NimStringDesc*) &T839829468_268), LOC122, 3); } goto LA117; LA120: ; { TY532811 LOC125; memset((void*)LOC125, 0, sizeof(LOC125)); LOC125[0] = rdloc_538188_839829468(dest0); LOC125[1] = rdloc_538188_839829468(src0); linefmt_532714_839829468(p0, ((Tcprocsection529011) 2), ((NimStringDesc*) &T839829468_123), LOC125, 2); } LA117: ; } break; case ((Ttypekind292244) 21): case ((Ttypekind292244) 26): case ((Ttypekind292244) 2): case ((Ttypekind292244) 1): case ((Ttypekind292244) 14): case ((Ttypekind292244) 29): case ((Ttypekind292244) 31) ... ((Ttypekind292244) 44): case ((Ttypekind292244) 20): case ((Ttypekind292244) 23): { TY532811 LOC127; memset((void*)LOC127, 0, sizeof(LOC127)); LOC127[0] = rdloc_538188_839829468(dest0); LOC127[1] = rdloc_538188_839829468(src0); linefmt_532714_839829468(p0, ((Tcprocsection529011) 2), ((NimStringDesc*) &T839829468_123), LOC127, 2); } break; default: { NimStringDesc* LOC129; LOC129 = (NimStringDesc*)0; LOC129 = rawNewString(reprEnum((NI)(*ty0).kind, (&NTI292244))->Sup.len + 15); appendString(LOC129, ((NimStringDesc*) &T839829468_269)); appendString(LOC129, reprEnum((NI)(*ty0).kind, (&NTI292244))); internalerror_196113_155036129(LOC129); } break; } }BeforeRet: ; } N_NIMCALL(void, putlocintodest_539258_839829468)(Tcproc529021* p0, Tloc292816* d0, Tloc292816 s0) { { if (!!(((*d0).k == ((Tlockind292808) 0)))) goto LA3; { if (!(((*d0).flags &(1U<<((NU)(((Tlocflag292810) 2))&15U)))!=0)) goto LA7; genassignment_539264_839829468(p0, (*d0), s0, 0); } goto LA5; LA7: ; { genassignment_539264_839829468(p0, (*d0), s0, 1); } LA5: ; } goto LA1; LA3: ; { genericAssign((void*)(&(*d0)), (void*)(&s0), (&NTI292816)); } LA1: ; } N_NIMCALL(NIM_BOOL, issimpleconst_532311_839829468)(Ttype292840* typ0) { NIM_BOOL result0; Ttype292840* t0; NIM_BOOL LOC1; NIM_BOOL LOC3; result0 = (NIM_BOOL)0; t0 = skiptypes_296099_850551059(typ0, IL64(211106240964864)); LOC1 = (NIM_BOOL)0; LOC1 = !(((*t0).kind == ((Ttypekind292244) 18) || (*t0).kind == ((Ttypekind292244) 17) || (*t0).kind == ((Ttypekind292244) 16) || (*t0).kind == ((Ttypekind292244) 4) || (*t0).kind == ((Ttypekind292244) 19) || (*t0).kind == ((Ttypekind292244) 24))); if (!(LOC1)) goto LA2; LOC3 = (NIM_BOOL)0; LOC3 = ((*t0).kind == ((Ttypekind292244) 25)); if (!(LOC3)) goto LA4; LOC3 = ((*t0).callconv == ((Tcallingconvention292002) 8)); LA4: ; LOC1 = !(LOC3); LA2: ; result0 = LOC1; return result0; } N_NIMCALL(void, putintodest_550468_839829468)(Tcproc529021* p0, Tloc292816* d0, Ttype292840* t0, Ropeobj178006* r0, Tstorageloc292812 s0) { Tloc292816 a0; memset((void*)(&a0), 0, sizeof(a0)); { if (!!(((*d0).k == ((Tlockind292808) 0)))) goto LA3; initloc_532273_839829468((&a0), ((Tlockind292808) 6), t0, s0); a0.r = r0; { if (!(((*d0).flags &(1U<<((NU)(((Tlocflag292810) 2))&15U)))!=0)) goto LA7; genassignment_539264_839829468(p0, (*d0), a0, 0); } goto LA5; LA7: ; { genassignment_539264_839829468(p0, (*d0), a0, 1); } LA5: ; } goto LA1; LA3: ; { (*d0).k = ((Tlockind292808) 6); unsureAsgnRef((void**) (&(*d0).t), t0); unsureAsgnRef((void**) (&(*d0).r), r0); } LA1: ; } N_NIMCALL(NI64, bitsettoword_549578_839829468)(Tbitset339004* s0, NI size0) { NI64 result0; result0 = (NI64)0; result0 = IL64(0); { NI j_549612_839829468; NI HEX3Atmp_549622_839829468; NI res_549625_839829468; j_549612_839829468 = (NI)0; HEX3Atmp_549622_839829468 = (NI)0; HEX3Atmp_549622_839829468 = (NI)(size0 - ((NI) 1)); res_549625_839829468 = ((NI) 0); { while (1) { if (!(res_549625_839829468 <= HEX3Atmp_549622_839829468)) goto LA3; j_549612_839829468 = res_549625_839829468; { if (!(j_549612_839829468 < (s0 ? s0->Sup.len : 0))) goto LA6; result0 = (NI64)(result0 | (NI64)((NU64)(((NI64)(NU64)(NU8)(s0->data[j_549612_839829468]))) << (NU64)(((NI64) ((NI)(j_549612_839829468 * ((NI) 8))))))); } LA6: ; res_549625_839829468 += ((NI) 1); } LA3: ; } } return result0; } N_NIMCALL(Ropeobj178006*, genrawsetdata_549629_839829468)(Tbitset339004* cs0, NI size0) { Ropeobj178006* result0; NimStringDesc* frmt0; result0 = (Ropeobj178006*)0; frmt0 = (NimStringDesc*)0; { TY533289 LOC5; if (!(((NI) 8) < size0)) goto LA3; memset((void*)LOC5, 0, sizeof(LOC5)); result0 = HEX25_178905_2381377266(((NimStringDesc*) &T839829468_273), LOC5, 0); { NI i_549649_839829468; NI HEX3Atmp_549657_839829468; NI res_549660_839829468; i_549649_839829468 = (NI)0; HEX3Atmp_549657_839829468 = (NI)0; HEX3Atmp_549657_839829468 = (NI)(size0 - ((NI) 1)); res_549660_839829468 = ((NI) 0); { while (1) { TY178507 LOC19; NimStringDesc* LOC20; if (!(res_549660_839829468 <= HEX3Atmp_549657_839829468)) goto LA8; i_549649_839829468 = res_549660_839829468; { if (!(i_549649_839829468 < (NI)(size0 - ((NI) 1)))) goto LA11; { if (!(((NI) ((NI)((NI)(i_549649_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_549649_839829468])), ((NI) 2)); LOC19[0] = rope_178277_2381377266(LOC20); addf_179205_2381377266(&result0, frmt0, LOC19, 1); res_549660_839829468 += ((NI) 1); } LA8: ; } } } goto LA1; LA3: ; { NI64 LOC22; LOC22 = (NI64)0; LOC22 = bitsettoword_549578_839829468(cs0, size0); result0 = intliteral_539270_839829468(LOC22); } LA1: ; return result0; } N_NIMCALL(void, appcg_532640_839829468)(Tcgen529027* m0, Tcfilesection529005 s0, NimStringDesc* frmt0, Ropeobj178006** args0, NI args0Len0) { Ropeobj178006* LOC1; LOC1 = (Ropeobj178006*)0; LOC1 = ropecg_532407_839829468(m0, frmt0, args0, args0Len0); add_178482_2381377266(&(*m0).s[(s0)- 0], LOC1); } N_NIMCALL(Ropeobj178006*, genconstseq_559371_839829468)(Tcproc529021* p0, Tnode292802* n0, Ttype292840* t0) { Ropeobj178006* result0; Ropeobj178006* data0; TY178507 LOC1; NI LOC2; TY535235 LOC18; NI LOC19; TY532811 LOC20; result0 = (Ropeobj178006*)0; memset((void*)LOC1, 0, sizeof(LOC1)); LOC2 = (NI)0; LOC2 = len_293081_850551059(n0); LOC1[0] = rope_178401_2381377266(((NI64) (LOC2))); data0 = HEX25_178905_2381377266(((NimStringDesc*) &T839829468_277), LOC1, 1); { NI LOC5; LOC5 = (NI)0; LOC5 = len_293081_850551059(n0); if (!(((NI) 0) < LOC5)) goto LA6; add_178487_2381377266(&data0, ((NimStringDesc*) &T839829468_278)); { NI i_559395_839829468; NI HEX3Atmp_559411_839829468; NI LOC9; NI res_559414_839829468; i_559395_839829468 = (NI)0; HEX3Atmp_559411_839829468 = (NI)0; LOC9 = (NI)0; LOC9 = len_293081_850551059(n0); HEX3Atmp_559411_839829468 = (NI)(LOC9 - ((NI) 1)); res_559414_839829468 = ((NI) 0); { while (1) { Ropeobj178006* LOC17; if (!(res_559414_839829468 <= HEX3Atmp_559411_839829468)) goto LA11; i_559395_839829468 = res_559414_839829468; { TY533289 LOC16; if (!(((NI) 0) < i_559395_839829468)) goto LA14; memset((void*)LOC16, 0, sizeof(LOC16)); addf_179205_2381377266(&data0, ((NimStringDesc*) &T839829468_279), LOC16, 0); } LA14: ; LOC17 = (Ropeobj178006*)0; LOC17 = genconstexpr_554849_839829468(p0, (*n0).kindU.S6.sons->data[i_559395_839829468]); add_178482_2381377266(&data0, LOC17); res_559414_839829468 += ((NI) 1); } LA11: ; } } add_178487_2381377266(&data0, ((NimStringDesc*) &T839829468_280)); } LA6: ; add_178487_2381377266(&data0, ((NimStringDesc*) &T839829468_280)); result0 = gettempname_533596_839829468((*p0).module); memset((void*)LOC18, 0, sizeof(LOC18)); LOC18[0] = gettypedesc_535671_839829468((*p0).module, (*t0).sons->data[((NI) 0)]); LOC19 = (NI)0; LOC19 = len_293081_850551059(n0); LOC18[1] = rope_178401_2381377266(((NI64) (LOC19))); LOC18[2] = result0; LOC18[3] = data0; appcg_532640_839829468((*p0).module, ((Tcfilesection529005) 8), ((NimStringDesc*) &T839829468_281), LOC18, 4); memset((void*)LOC20, 0, sizeof(LOC20)); LOC20[0] = gettypedesc_535671_839829468((*p0).module, t0); LOC20[1] = result0; result0 = HEX25_178905_2381377266(((NimStringDesc*) &T839829468_282), LOC20, 2); return result0; } N_NIMCALL(Ropeobj178006*, gennamedconstexpr_559284_839829468)(Tcproc529021* p0, Tnode292802* n0) { Ropeobj178006* result0; result0 = (Ropeobj178006*)0; { if (!((*n0).kind == ((Tnodekind292020) 34))) goto LA3; result0 = genconstexpr_554849_839829468(p0, (*n0).kindU.S6.sons->data[((NI) 1)]); } goto LA1; LA3: ; { result0 = genconstexpr_554849_839829468(p0, n0); } LA1: ; return result0; } N_NIMCALL(Ropeobj178006*, genconstsimplelist_559299_839829468)(Tcproc529021* p0, Tnode292802* n0) { Ropeobj178006* result0; NI length0; TY533289 LOC10; result0 = (Ropeobj178006*)0; length0 = sonslen_295351_850551059(n0); result0 = rope_178277_2381377266(((NimStringDesc*) &T839829468_223)); { NI i_559333_839829468; NI HEX3Atmp_559362_839829468; NI HEX3Atmp_559363_839829468; NI res_559366_839829468; i_559333_839829468 = (NI)0; HEX3Atmp_559362_839829468 = (NI)0; HEX3Atmp_559363_839829468 = (NI)0; HEX3Atmp_559362_839829468 = ((*n0).kind == ((Tnodekind292020) 38)); HEX3Atmp_559363_839829468 = (NI)(length0 - ((NI) 2)); res_559366_839829468 = ((NI) (HEX3Atmp_559362_839829468)); { while (1) { TY178507 LOC4; if (!(res_559366_839829468 <= HEX3Atmp_559363_839829468)) goto LA3; i_559333_839829468 = res_559366_839829468; memset((void*)LOC4, 0, sizeof(LOC4)); LOC4[0] = gennamedconstexpr_559284_839829468(p0, (*n0).kindU.S6.sons->data[i_559333_839829468]); addf_179205_2381377266(&result0, ((NimStringDesc*) &T839829468_283), LOC4, 1); res_559366_839829468 += ((NI) 1); } LA3: ; } } { Ropeobj178006* LOC9; if (!(((NI) (((*n0).kind == ((Tnodekind292020) 38)))) < length0)) goto LA7; LOC9 = (Ropeobj178006*)0; LOC9 = gennamedconstexpr_559284_839829468(p0, (*n0).kindU.S6.sons->data[(NI)(length0 - ((NI) 1))]); add_178482_2381377266(&result0, LOC9); } LA7: ; memset((void*)LOC10, 0, sizeof(LOC10)); addf_179205_2381377266(&result0, ((NimStringDesc*) &T839829468_160), LOC10, 0); return result0; } N_NIMCALL(Ropeobj178006*, genconstexpr_554849_839829468)(Tcproc529021* p0, Tnode292802* n0) { Ropeobj178006* result0; result0 = (Ropeobj178006*)0; switch ((*n0).kind) { case ((Tnodekind292020) 58): case ((Tnodekind292020) 59): { result0 = genconstexpr_554849_839829468(p0, (*n0).kindU.S6.sons->data[((NI) 1)]); } break; case ((Tnodekind292020) 39): { Tbitset339004* cs0; NI64 LOC3; cs0 = (Tbitset339004*)0; tobitset_340001_452470228(n0, (&cs0)); LOC3 = (NI64)0; LOC3 = getsize_320135_3876443242((*n0).typ); result0 = genrawsetdata_549629_839829468(cs0, ((NI) (LOC3))); } break; case ((Tnodekind292020) 41): case ((Tnodekind292020) 37): case ((Tnodekind292020) 155): case ((Tnodekind292020) 38): { Ttype292840* t0; t0 = skiptypes_296099_850551059((*n0).typ, IL64(211106232576256)); { if (!((*t0).kind == ((Ttypekind292244) 24))) goto LA7; result0 = genconstseq_559371_839829468(p0, n0, t0); } goto LA5; LA7: ; { result0 = genconstsimplelist_559299_839829468(p0, n0); } LA5: ; } break; default: { Tloc292816 d0; memset((void*)(&d0), 0, sizeof(d0)); initlocexpr_539283_839829468(p0, n0, (&d0)); result0 = rdloc_538188_839829468(d0); } break; } return result0; } N_NIMCALL(void, requestconstimpl_539240_839829468)(Tcproc529021* p0, Tsym292834* sym0) { Tcgen529027* m0; Tcgen529027* q0; { m0 = (*p0).module; useheader_532369_839829468(m0, sym0); { Ropeobj178006* LOC5; if (!((*sym0).loc.k == ((Tlockind292808) 0))) goto LA3; LOC5 = (Ropeobj178006*)0; LOC5 = manglename_533205_839829468(sym0); fillloc_532282_839829468((&(*sym0).loc), ((Tlockind292808) 8), (*sym0).typ, LOC5, ((Tstorageloc292812) 1)); } LA3: ; { if (!(((*sym0).loc.flags &(1U<<((NU)(((Tlocflag292810) 3))&15U)))!=0)) goto LA8; goto BeforeRet; } LA8: ; q0 = findpendingmodule_532241_839829468(m0, sym0); { NIM_BOOL LOC12; NIM_BOOL LOC14; TY535238 LOC17; LOC12 = (NIM_BOOL)0; LOC12 = !((q0 == NIM_NIL)); if (!(LOC12)) goto LA13; LOC14 = (NIM_BOOL)0; LOC14 = containsorincl_268862_2627731572((&(*q0).declaredthings), (*sym0).Sup.id); LOC12 = !(LOC14); LA13: ; if (!LOC12) goto LA15; memset((void*)LOC17, 0, sizeof(LOC17)); LOC17[0] = gettypedesc_535671_839829468(q0, (*sym0).typ); LOC17[1] = (*sym0).loc.r; LOC17[2] = genconstexpr_554849_839829468((*q0).initproc, (*sym0).ast); addf_179205_2381377266(&(*q0).s[(((Tcfilesection529005) 8))- 0], ((NimStringDesc*) &T839829468_272), LOC17, 3); } LA15: ; { NIM_BOOL LOC20; NIM_BOOL LOC22; Ropeobj178006* headerdecl0; TY532811 LOC25; LOC20 = (NIM_BOOL)0; LOC20 = !((q0 == m0)); if (!(LOC20)) goto LA21; LOC22 = (NIM_BOOL)0; LOC22 = containsorincl_268862_2627731572((&(*m0).declaredthings), (*sym0).Sup.id); LOC20 = !(LOC22); LA21: ; if (!LOC20) goto LA23; memset((void*)LOC25, 0, sizeof(LOC25)); LOC25[0] = gettypedesc_535671_839829468(m0, (*sym0).loc.t); LOC25[1] = (*sym0).loc.r; headerdecl0 = HEX25_178905_2381377266(((NimStringDesc*) &T839829468_284), LOC25, 2); add_178482_2381377266(&(*m0).s[(((Tcfilesection529005) 8))- 0], headerdecl0); { NIM_BOOL LOC28; LOC28 = (NIM_BOOL)0; LOC28 = (((*sym0).flags &(1U<<((NU)(((Tsymflag292184) 6))&31U)))!=0); if (!(LOC28)) goto LA29; LOC28 = !((generatedheader_532201_839829468 == NIM_NIL)); LA29: ; if (!LOC28) goto LA30; add_178482_2381377266(&(*generatedheader_532201_839829468).s[(((Tcfilesection529005) 8))- 0], headerdecl0); } LA30: ; } LA23: ; }BeforeRet: ; } N_NIMCALL(void, gencomplexconst_558249_839829468)(Tcproc529021* p0, Tsym292834* sym0, Tloc292816* d0) { requestconstimpl_539240_839829468(p0, sym0); putlocintodest_539258_839829468(p0, d0, (*sym0).loc); } static N_INLINE(Ropeobj178006**, procsec_529194_3723162438)(Tcproc529021* p0, Tcprocsection529011 s0) { Ropeobj178006** result0; result0 = (Ropeobj178006**)0; result0 = &(*p0).blocks->data[((NI) 0)].sections[(s0)- 0]; return result0; } N_NIMCALL(void, accessthreadlocalvar_532945_839829468)(Tcproc529021* p0, Tsym292834* s0) { { NIM_BOOL LOC3; Ropeobj178006** LOC7; TY533289 LOC8; Ropeobj178006** LOC9; TY533289 LOC10; Ropeobj178006* LOC11; LOC3 = (NIM_BOOL)0; LOC3 = emulatedthreadvars_532949_839829468(); if (!(LOC3)) goto LA4; LOC3 = !((*p0).threadvaraccessed); LA4: ; if (!LOC3) goto LA5; (*p0).threadvaraccessed = NIM_TRUE; (*(*p0).module).flags |= ((NU8)1)<<((((Codegenflag529025) 1))%(sizeof(NU8)*8)); LOC7 = (Ropeobj178006**)0; LOC7 = procsec_529194_3723162438(p0, ((Tcprocsection529011) 0)); memset((void*)LOC8, 0, sizeof(LOC8)); addf_179205_2381377266(LOC7, ((NimStringDesc*) &T839829468_286), LOC8, 0); LOC9 = (Ropeobj178006**)0; LOC9 = procsec_529194_3723162438(p0, ((Tcprocsection529011) 1)); memset((void*)LOC10, 0, sizeof(LOC10)); LOC11 = (Ropeobj178006*)0; LOC11 = ropecg_532407_839829468((*p0).module, ((NimStringDesc*) &T839829468_287), LOC10, 0); add_178482_2381377266(LOC9, LOC11); } LA5: ; } static N_INLINE(NIM_BOOL, isemptytype_297440_850551059)(Ttype292840* 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 == ((Ttypekind292244) 62) || (*t0).kind == ((Ttypekind292244) 7)); LA2: ; result0 = LOC1; return result0; } N_NIMCALL(void, putdataintodest_550436_839829468)(Tcproc529021* p0, Tloc292816* d0, Ttype292840* t0, Ropeobj178006* r0) { Tloc292816 a0; memset((void*)(&a0), 0, sizeof(a0)); { if (!!(((*d0).k == ((Tlockind292808) 0)))) goto LA3; initloc_532273_839829468((&a0), ((Tlockind292808) 8), t0, ((Tstorageloc292812) 1)); a0.r = r0; { if (!(((*d0).flags &(1U<<((NU)(((Tlocflag292810) 2))&15U)))!=0)) goto LA7; genassignment_539264_839829468(p0, (*d0), a0, 0); } goto LA5; LA7: ; { genassignment_539264_839829468(p0, (*d0), a0, 1); } LA5: ; } goto LA1; LA3: ; { (*d0).k = ((Tlockind292808) 8); unsureAsgnRef((void**) (&(*d0).t), t0); unsureAsgnRef((void**) (&(*d0).r), r0); } LA1: ; } N_NIMCALL(NIM_BOOL, freshlineinfo_532818_839829468)(Tcproc529021* p0, Tlineinfo191336 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_532823_839829468)(Tcproc529021* p0, Tnode292802* t0) { NI line0; Ropeobj178006** LOC11; NimStringDesc* LOC12; line0 = safelinenm_532721_839829468((*t0).info); { Ropeobj178006** LOC5; TY533289 LOC6; Ropeobj178006* LOC7; Ropeobj178006* LOC8; Ropeobj178006* LOC9; Ropeobj178006* LOC10; if (!((gglobaloptions_169130_2607990831 &((NU64)1<<((NU)(((Tglobaloption169013) 28))&63U)))!=0)) goto LA3; LOC5 = (Ropeobj178006**)0; LOC5 = s_529179_3723162438(p0, ((Tcprocsection529011) 2)); memset((void*)LOC6, 0, sizeof(LOC6)); LOC7 = (Ropeobj178006*)0; LOC7 = HEX25_178905_2381377266(((NimStringDesc*) &T839829468_293), LOC6, 0); LOC8 = (Ropeobj178006*)0; LOC8 = sourceline_192068_155036129((*t0).info); LOC9 = (Ropeobj178006*)0; LOC9 = HEX26_178418_2381377266(LOC7, LOC8); LOC10 = (Ropeobj178006*)0; LOC10 = HEX26_178418_2381377266(LOC9, rnl_178903_2381377266); add_178482_2381377266(LOC5, LOC10); } LA3: ; LOC11 = (Ropeobj178006**)0; LOC11 = s_529179_3723162438(p0, ((Tcprocsection529011) 2)); LOC12 = (NimStringDesc*)0; LOC12 = tofullpath_192264_155036129((*t0).info.fileindex); genclinedir_532725_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)(((Tsymflag292184) 9))&31U)))!=0)); LA18: ; LOC15 = LOC17; LA16: ; if (!LOC15) goto LA19; { NIM_BOOL LOC23; TY532811 LOC26; NimStringDesc* LOC27; LOC23 = (NIM_BOOL)0; LOC23 = freshlineinfo_532818_839829468(p0, (*t0).info); if (!LOC23) goto LA24; memset((void*)LOC26, 0, sizeof(LOC26)); LOC26[0] = rope_178401_2381377266(((NI64) (line0))); LOC27 = (NimStringDesc*)0; LOC27 = tofilename_192260_155036129((*t0).info.fileindex); LOC26[1] = makecstring_191638_155036129(LOC27); linefmt_532714_839829468(p0, ((Tcprocsection529011) 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)(((Tsymflag292184) 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; TY532811 LOC42; LOC39 = (NIM_BOOL)0; LOC39 = freshlineinfo_532818_839829468(p0, (*t0).info); if (!LOC39) goto LA40; memset((void*)LOC42, 0, sizeof(LOC42)); LOC42[0] = rope_178401_2381377266(((NI64) (line0))); LOC42[1] = quotedfilename_196818_155036129((*t0).info); linefmt_532714_839829468(p0, ((Tcprocsection529011) 2), ((NimStringDesc*) &T839829468_295), LOC42, 2); } LA40: ; } goto LA13; LA35: ; LA13: ; } N_NIMCALL(Ropeobj178006*, getlabel_539217_839829468)(Tcproc529021* p0) { Ropeobj178006* result0; Ropeobj178006* LOC1; result0 = (Ropeobj178006*)0; (*p0).labels += ((NI) 1); LOC1 = (Ropeobj178006*)0; LOC1 = rope_178401_2381377266(((NI64) ((*p0).labels))); result0 = HEX26_178452_2381377266(((NimStringDesc*) &T839829468_296), LOC1); return result0; } N_NIMCALL(void, fixlabel_539230_839829468)(Tcproc529021* p0, Ropeobj178006* labl0) { TY178507 LOC1; memset((void*)LOC1, 0, sizeof(LOC1)); LOC1[0] = labl0; linef_532700_839829468(p0, ((Tcprocsection529011) 2), ((NimStringDesc*) &T839829468_299), LOC1, 1); } N_NIMCALL(void, genandor_554311_839829468)(Tcproc529021* p0, Tnode292802* e0, Tloc292816* d0, Tmagic292524 m0) { Ropeobj178006* L0; Tloc292816 tmp0; L0 = (Ropeobj178006*)0; memset((void*)(&tmp0), 0, sizeof(tmp0)); gettemp_537032_839829468(p0, (*e0).typ, (&tmp0), NIM_FALSE); (*p0).splitdecls += ((NI) 1); expr_539248_839829468(p0, (*e0).kindU.S6.sons->data[((NI) 1)], (&tmp0)); L0 = getlabel_539217_839829468(p0); { TY532811 LOC5; if (!(m0 == ((Tmagic292524) 127))) goto LA3; memset((void*)LOC5, 0, sizeof(LOC5)); LOC5[0] = rdloc_538188_839829468(tmp0); LOC5[1] = L0; linef_532700_839829468(p0, ((Tcprocsection529011) 2), ((NimStringDesc*) &T839829468_297), LOC5, 2); } goto LA1; LA3: ; { TY532811 LOC7; memset((void*)LOC7, 0, sizeof(LOC7)); LOC7[0] = rdloc_538188_839829468(tmp0); LOC7[1] = L0; linef_532700_839829468(p0, ((Tcprocsection529011) 2), ((NimStringDesc*) &T839829468_298), LOC7, 2); } LA1: ; expr_539248_839829468(p0, (*e0).kindU.S6.sons->data[((NI) 2)], (&tmp0)); fixlabel_539230_839829468(p0, L0); { if (!((*d0).k == ((Tlockind292808) 0))) goto LA10; genericAssign((void*)(&(*d0)), (void*)(&tmp0), (&NTI292816)); } goto LA8; LA10: ; { genassignment_539264_839829468(p0, (*d0), tmp0, 0); } LA8: ; (*p0).splitdecls -= ((NI) 1); } N_NIMCALL(void, unaryarith_552646_839829468)(Tcproc529021* p0, Tnode292802* e0, Tloc292816* d0, Tmagic292524 op0) { Tloc292816 a0; Ttype292840* t0; TY535238 LOC1; NI64 LOC2; Ropeobj178006* LOC3; memset((void*)(&a0), 0, sizeof(a0)); t0 = (Ttype292840*)0; initlocexpr_539283_839829468(p0, (*e0).kindU.S6.sons->data[((NI) 1)], (&a0)); t0 = skiptypes_296099_850551059((*e0).typ, IL64(211106233624832)); memset((void*)LOC1, 0, sizeof(LOC1)); LOC1[0] = rdloc_538188_839829468(a0); LOC2 = (NI64)0; LOC2 = getsize_320135_3876443242(t0); LOC1[1] = rope_178401_2381377266((NI64)(LOC2 * IL64(8))); LOC1[2] = getsimpletypedesc_533936_839829468((*p0).module, (*e0).typ); LOC3 = (Ropeobj178006*)0; LOC3 = HEX25_178905_2381377266(unarithtab_552653_839829468[(op0)- 99], LOC1, 3); putintodest_550468_839829468(p0, d0, (*e0).typ, LOC3, ((Tstorageloc292812) 0)); } N_NIMCALL(void, unaryarithoverflow_551633_839829468)(Tcproc529021* p0, Tnode292802* e0, Tloc292816* d0, Tmagic292524 m0) { Tloc292816 a0; Ttype292840* t0; TY532811 LOC7; NI64 LOC8; Ropeobj178006* LOC9; memset((void*)(&a0), 0, sizeof(a0)); t0 = (Ttype292840*)0; initlocexpr_539283_839829468(p0, (*e0).kindU.S6.sons->data[((NI) 1)], (&a0)); t0 = skiptypes_296099_850551059((*e0).typ, IL64(211106233624832)); { TY532811 LOC5; NI64 LOC6; if (!(((*p0).options &(1U<<((NU)(((Toption169009) 5))&31U)))!=0)) goto LA3; memset((void*)LOC5, 0, sizeof(LOC5)); LOC5[0] = rdloc_538188_839829468(a0); LOC6 = (NI64)0; LOC6 = firstord_320001_3876443242(t0); LOC5[1] = intliteral_539270_839829468(LOC6); linefmt_532714_839829468(p0, ((Tcprocsection529011) 2), ((NimStringDesc*) &T839829468_317), LOC5, 2); } LA3: ; memset((void*)LOC7, 0, sizeof(LOC7)); LOC7[0] = rdloc_538188_839829468(a0); LOC8 = (NI64)0; LOC8 = getsize_320135_3876443242(t0); LOC7[1] = rope_178401_2381377266((NI64)(LOC8 * IL64(8))); LOC9 = (Ropeobj178006*)0; LOC9 = HEX25_178905_2381377266(opr_551640_839829468[(m0)- 96], LOC7, 2); putintodest_550468_839829468(p0, d0, (*e0).typ, LOC9, ((Tstorageloc292812) 0)); } N_NIMCALL(void, binaryarith_551819_839829468)(Tcproc529021* p0, Tnode292802* e0, Tloc292816* d0, Tmagic292524 op0) { Tloc292816 a0; Tloc292816 b0; NI64 s0; NI64 LOC1; NI64 LOC2; TY535235 LOC3; Ropeobj178006* LOC4; memset((void*)(&a0), 0, sizeof(a0)); memset((void*)(&b0), 0, sizeof(b0)); s0 = (NI64)0; initlocexpr_539283_839829468(p0, (*e0).kindU.S6.sons->data[((NI) 1)], (&a0)); initlocexpr_539283_839829468(p0, (*e0).kindU.S6.sons->data[((NI) 2)], (&b0)); LOC1 = (NI64)0; LOC1 = getsize_320135_3876443242(a0.t); LOC2 = (NI64)0; LOC2 = getsize_320135_3876443242(b0.t); s0 = (NI64)(((LOC1 >= LOC2) ? LOC1 : LOC2) * IL64(8)); memset((void*)LOC3, 0, sizeof(LOC3)); LOC3[0] = rdloc_538188_839829468(a0); LOC3[1] = rdloc_538188_839829468(b0); LOC3[2] = rope_178401_2381377266(s0); LOC3[3] = getsimpletypedesc_533936_839829468((*p0).module, (*e0).typ); LOC4 = (Ropeobj178006*)0; LOC4 = HEX25_178905_2381377266(binarithtab_551826_839829468[(op0)- 52], LOC3, 4); putintodest_550468_839829468(p0, d0, (*e0).typ, LOC4, ((Tstorageloc292812) 0)); } N_NIMCALL(void, binaryfloatarith_556728_839829468)(Tcproc529021* p0, Tnode292802* e0, Tloc292816* d0, Tmagic292524 m0) { { Tloc292816 a0; Tloc292816 b0; TY535235 LOC5; Tnode292802* LOC6; Ropeobj178006* LOC7; if (!!(((384 & (*p0).options) == 0))) goto LA3; memset((void*)(&a0), 0, sizeof(a0)); memset((void*)(&b0), 0, sizeof(b0)); initlocexpr_539283_839829468(p0, (*e0).kindU.S6.sons->data[((NI) 1)], (&a0)); initlocexpr_539283_839829468(p0, (*e0).kindU.S6.sons->data[((NI) 2)], (&b0)); memset((void*)LOC5, 0, sizeof(LOC5)); LOC5[0] = rope_178277_2381377266(opr_556762_839829468[(m0)- 52]); LOC5[1] = rdloc_538188_839829468(a0); LOC5[2] = rdloc_538188_839829468(b0); LOC6 = (Tnode292802*)0; LOC6 = HEX5BHEX5D_293238_850551059(e0, ((NI) 1)); LOC5[3] = getsimpletypedesc_533936_839829468((*p0).module, (*LOC6).typ); LOC7 = (Ropeobj178006*)0; LOC7 = ropecg_532407_839829468(NIM_NIL, ((NimStringDesc*) &T839829468_319), LOC5, 4); putintodest_550468_839829468(p0, d0, (*e0).typ, LOC7, ((Tstorageloc292812) 0)); { TY178507 LOC12; if (!(((*p0).options &(1U<<((NU)(((Toption169009) 7))&31U)))!=0)) goto LA10; memset((void*)LOC12, 0, sizeof(LOC12)); LOC12[0] = rdloc_538188_839829468((*d0)); linefmt_532714_839829468(p0, ((Tcprocsection529011) 2), ((NimStringDesc*) &T839829468_323), LOC12, 1); } LA10: ; { TY178507 LOC17; if (!(((*p0).options &(1U<<((NU)(((Toption169009) 8))&31U)))!=0)) goto LA15; memset((void*)LOC17, 0, sizeof(LOC17)); LOC17[0] = rdloc_538188_839829468((*d0)); linefmt_532714_839829468(p0, ((Tcprocsection529011) 2), ((NimStringDesc*) &T839829468_324), LOC17, 1); } LA15: ; } goto LA1; LA3: ; { binaryarith_551819_839829468(p0, e0, d0, m0); } LA1: ; } N_NIMCALL(void, geneqproc_552214_839829468)(Tcproc529021* p0, Tnode292802* e0, Tloc292816* d0) { Tloc292816 a0; Tloc292816 b0; memset((void*)(&a0), 0, sizeof(a0)); memset((void*)(&b0), 0, sizeof(b0)); initlocexpr_539283_839829468(p0, (*e0).kindU.S6.sons->data[((NI) 1)], (&a0)); initlocexpr_539283_839829468(p0, (*e0).kindU.S6.sons->data[((NI) 2)], (&b0)); { Ttype292840* LOC3; TY532811 LOC6; Ropeobj178006* LOC7; LOC3 = (Ttype292840*)0; LOC3 = skiptypes_296099_850551059(a0.t, IL64(211106232576256)); if (!((*LOC3).callconv == ((Tcallingconvention292002) 8))) goto LA4; memset((void*)LOC6, 0, sizeof(LOC6)); LOC6[0] = rdloc_538188_839829468(a0); LOC6[1] = rdloc_538188_839829468(b0); LOC7 = (Ropeobj178006*)0; LOC7 = HEX25_178905_2381377266(((NimStringDesc*) &T839829468_352), LOC6, 2); putintodest_550468_839829468(p0, d0, (*e0).typ, LOC7, ((Tstorageloc292812) 0)); } goto LA1; LA4: ; { TY532811 LOC9; Ropeobj178006* LOC10; memset((void*)LOC9, 0, sizeof(LOC9)); LOC9[0] = rdloc_538188_839829468(a0); LOC9[1] = rdloc_538188_839829468(b0); LOC10 = (Ropeobj178006*)0; LOC10 = HEX25_178905_2381377266(((NimStringDesc*) &T839829468_341), LOC9, 2); putintodest_550468_839829468(p0, d0, (*e0).typ, LOC10, ((Tstorageloc292812) 0)); } LA1: ; } N_NIMCALL(Ropeobj178006*, rdcharloc_538227_839829468)(Tloc292816 a0) { Ropeobj178006* result0; result0 = (Ropeobj178006*)0; result0 = rdloc_538188_839829468(a0); { Ttype292840* LOC3; TY178507 LOC6; LOC3 = (Ttype292840*)0; LOC3 = skiptypes_296099_850551059(a0.t, IL64(211106233624832)); if (!((*LOC3).kind == ((Ttypekind292244) 2))) goto LA4; memset((void*)LOC6, 0, sizeof(LOC6)); LOC6[0] = result0; result0 = HEX25_178905_2381377266(((NimStringDesc*) &T839829468_358), LOC6, 1); } LA4: ; return result0; } N_NIMCALL(Ropeobj178006*, binaryarithoverflowraw_551235_839829468)(Tcproc529021* p0, Ttype292840* t0, Tloc292816 a0, Tloc292816 b0, NimStringDesc* frmt0) { Ropeobj178006* result0; NI64 size0; Ropeobj178006* storage0; TY532811 LOC6; TY535238 LOC7; result0 = (Ropeobj178006*)0; size0 = getsize_320135_3876443242(t0); { if (!(size0 < ((NI64) (intsize_176641_4151366050)))) goto LA3; storage0 = rope_178277_2381377266(((NimStringDesc*) &T839829468_36)); } goto LA1; LA3: ; { storage0 = gettypedesc_535671_839829468((*p0).module, t0); } LA1: ; result0 = gettempname_533596_839829468((*p0).module); memset((void*)LOC6, 0, sizeof(LOC6)); LOC6[0] = storage0; LOC6[1] = result0; linefmt_532714_839829468(p0, ((Tcprocsection529011) 0), ((NimStringDesc*) &T839829468_54), LOC6, 2); memset((void*)LOC7, 0, sizeof(LOC7)); LOC7[0] = result0; LOC7[1] = rdcharloc_538227_839829468(a0); LOC7[2] = rdcharloc_538227_839829468(b0); linecg_532707_839829468(p0, ((Tcprocsection529011) 2), frmt0, LOC7, 3); { NIM_BOOL LOC10; TY535238 LOC14; NI64 LOC15; NI64 LOC16; LOC10 = (NIM_BOOL)0; LOC10 = (size0 < ((NI64) (intsize_176641_4151366050))); if (LOC10) goto LA11; LOC10 = ((*t0).kind == ((Ttypekind292244) 20) || (*t0).kind == ((Ttypekind292244) 14)); LA11: ; if (!LOC10) goto LA12; memset((void*)LOC14, 0, sizeof(LOC14)); LOC14[0] = result0; LOC15 = (NI64)0; LOC15 = firstord_320001_3876443242(t0); LOC14[1] = intliteral_539270_839829468(LOC15); LOC16 = (NI64)0; LOC16 = lastord_320004_3876443242(t0); LOC14[2] = intliteral_539270_839829468(LOC16); linefmt_532714_839829468(p0, ((Tcprocsection529011) 2), ((NimStringDesc*) &T839829468_359), LOC14, 3); } LA12: ; return result0; } N_NIMCALL(void, binaryarithoverflow_551262_839829468)(Tcproc529021* p0, Tnode292802* e0, Tloc292816* d0, Tmagic292524 m0) { Tloc292816 a0; Tloc292816 b0; Ttype292840* t0; memset((void*)(&a0), 0, sizeof(a0)); memset((void*)(&b0), 0, sizeof(b0)); initlocexpr_539283_839829468(p0, (*e0).kindU.S6.sons->data[((NI) 1)], (&a0)); initlocexpr_539283_839829468(p0, (*e0).kindU.S6.sons->data[((NI) 2)], (&b0)); t0 = skiptypes_296099_850551059((*e0).typ, IL64(211106233624832)); { Ropeobj178006* res0; TY535238 LOC5; if (!!((((*p0).options &(1U<<((NU)(((Toption169009) 5))&31U)))!=0))) goto LA3; memset((void*)LOC5, 0, sizeof(LOC5)); LOC5[0] = gettypedesc_535671_839829468((*p0).module, t0); LOC5[1] = rdloc_538188_839829468(a0); LOC5[2] = rdloc_538188_839829468(b0); res0 = HEX25_178905_2381377266(opr_551279_839829468[(m0)- 45], LOC5, 3); putintodest_550468_839829468(p0, d0, (*e0).typ, res0, ((Tstorageloc292812) 0)); } goto LA1; LA3: ; { Ropeobj178006* res0; NimStringDesc* LOC7; TY532811 LOC13; Ropeobj178006* LOC14; LOC7 = (NimStringDesc*)0; { if (!((*t0).kind == ((Ttypekind292244) 35))) goto LA10; LOC7 = copyString(prc64_551274_839829468[(m0)- 45]); } goto LA8; LA10: ; { LOC7 = copyString(prc_551269_839829468[(m0)- 45]); } LA8: ; res0 = binaryarithoverflowraw_551235_839829468(p0, t0, a0, b0, LOC7); memset((void*)LOC13, 0, sizeof(LOC13)); LOC13[0] = gettypedesc_535671_839829468((*p0).module, t0); LOC13[1] = res0; LOC14 = (Ropeobj178006*)0; LOC14 = HEX25_178905_2381377266(((NimStringDesc*) &T839829468_370), LOC13, 2); putintodest_550468_839829468(p0, d0, (*e0).typ, LOC14, ((Tstorageloc292812) 0)); } LA1: ; } N_NIMCALL(Ropeobj178006*, lenfield_539305_839829468)(Tcproc529021* p0) { Ropeobj178006* result0; NimStringDesc* LOC1; result0 = (Ropeobj178006*)0; LOC1 = (NimStringDesc*)0; { NIM_BOOL LOC4; LOC4 = (NIM_BOOL)0; LOC4 = (gcmd_169132_2607990831 == ((Tcommands169076) 2)); if (LOC4) goto LA5; LOC4 = (((*(*(*p0).module).module).flags &(1U<<((NU)(((Tsymflag292184) 27))&31U)))!=0); LA5: ; if (!LOC4) goto LA6; LOC1 = copyString(((NimStringDesc*) &T839829468_157)); } goto LA2; LA6: ; { LOC1 = copyString(((NimStringDesc*) &T839829468_158)); } LA2: ; result0 = rope_178277_2381377266(LOC1); return result0; } N_NIMCALL(void, gcusage_554439_839829468)(Tnode292802* n0) { { NimStringDesc* LOC5; if (!(gselectedgc_169133_2607990831 == ((Tgcmode169080) 0))) goto LA3; LOC5 = (NimStringDesc*)0; LOC5 = rendertree_311044_382274130(n0, 0); message_196095_155036129((*n0).info, ((Tmsgkind191002) 263), LOC5); } LA3: ; } N_NIMCALL(void, genrepr_555339_839829468)(Tcproc529021* p0, Tnode292802* e0, Tloc292816* d0) { Tloc292816 a0; Ttype292840* t0; memset((void*)(&a0), 0, sizeof(a0)); initlocexpr_539283_839829468(p0, (*e0).kindU.S6.sons->data[((NI) 1)], (&a0)); t0 = skiptypes_296099_850551059((*(*e0).kindU.S6.sons->data[((NI) 1)]).typ, IL64(211106242013440)); switch ((*t0).kind) { case ((Ttypekind292244) 31) ... ((Ttypekind292244) 35): case ((Ttypekind292244) 40) ... ((Ttypekind292244) 44): { TY178507 LOC2; Ropeobj178006* LOC3; memset((void*)LOC2, 0, sizeof(LOC2)); LOC2[0] = rdloc_538188_839829468(a0); LOC3 = (Ropeobj178006*)0; LOC3 = ropecg_532407_839829468((*p0).module, ((NimStringDesc*) &T839829468_371), LOC2, 1); putintodest_550468_839829468(p0, d0, (*e0).typ, LOC3, a0.s); } break; case ((Ttypekind292244) 36) ... ((Ttypekind292244) 39): { TY178507 LOC5; Ropeobj178006* LOC6; memset((void*)LOC5, 0, sizeof(LOC5)); LOC5[0] = rdloc_538188_839829468(a0); LOC6 = (Ropeobj178006*)0; LOC6 = ropecg_532407_839829468((*p0).module, ((NimStringDesc*) &T839829468_372), LOC5, 1); putintodest_550468_839829468(p0, d0, (*e0).typ, LOC6, a0.s); } break; case ((Ttypekind292244) 1): { TY178507 LOC8; Ropeobj178006* LOC9; memset((void*)LOC8, 0, sizeof(LOC8)); LOC8[0] = rdloc_538188_839829468(a0); LOC9 = (Ropeobj178006*)0; LOC9 = ropecg_532407_839829468((*p0).module, ((NimStringDesc*) &T839829468_373), LOC8, 1); putintodest_550468_839829468(p0, d0, (*e0).typ, LOC9, a0.s); } break; case ((Ttypekind292244) 2): { TY178507 LOC11; Ropeobj178006* LOC12; memset((void*)LOC11, 0, sizeof(LOC11)); LOC11[0] = rdloc_538188_839829468(a0); LOC12 = (Ropeobj178006*)0; LOC12 = ropecg_532407_839829468((*p0).module, ((NimStringDesc*) &T839829468_374), LOC11, 1); putintodest_550468_839829468(p0, d0, (*e0).typ, LOC12, a0.s); } break; case ((Ttypekind292244) 14): case ((Ttypekind292244) 15): { TY532811 LOC14; Ropeobj178006* LOC15; memset((void*)LOC14, 0, sizeof(LOC14)); LOC14[0] = rdloc_538188_839829468(a0); LOC14[1] = gentypeinfo_535941_839829468((*p0).module, t0); LOC15 = (Ropeobj178006*)0; LOC15 = ropecg_532407_839829468((*p0).module, ((NimStringDesc*) &T839829468_375), LOC14, 2); putintodest_550468_839829468(p0, d0, (*e0).typ, LOC15, a0.s); } break; case ((Ttypekind292244) 28): { TY178507 LOC17; Ropeobj178006* LOC18; memset((void*)LOC17, 0, sizeof(LOC17)); LOC17[0] = rdloc_538188_839829468(a0); LOC18 = (Ropeobj178006*)0; LOC18 = ropecg_532407_839829468((*p0).module, ((NimStringDesc*) &T839829468_376), LOC17, 1); putintodest_550468_839829468(p0, d0, (*e0).typ, LOC18, a0.s); } break; case ((Ttypekind292244) 19): { TY532811 LOC20; Ropeobj178006* LOC21; memset((void*)LOC20, 0, sizeof(LOC20)); LOC20[0] = addrloc_538204_839829468(a0); LOC20[1] = gentypeinfo_535941_839829468((*p0).module, t0); LOC21 = (Ropeobj178006*)0; LOC21 = ropecg_532407_839829468((*p0).module, ((NimStringDesc*) &T839829468_377), LOC20, 2); putintodest_550468_839829468(p0, d0, (*e0).typ, LOC21, a0.s); } break; case ((Ttypekind292244) 27): case ((Ttypekind292244) 48): { Tloc292816 b0; TY532811 LOC34; Ttype292840* LOC35; Ropeobj178006* LOC36; memset((void*)(&b0), 0, sizeof(b0)); switch ((*a0.t).kind) { case ((Ttypekind292244) 27): case ((Ttypekind292244) 48): { TY178507 LOC24; Ropeobj178006* LOC25; memset((void*)LOC24, 0, sizeof(LOC24)); LOC24[0] = rdloc_538188_839829468(a0); LOC25 = (Ropeobj178006*)0; LOC25 = HEX25_178905_2381377266(((NimStringDesc*) &T839829468_378), LOC24, 1); putintodest_550468_839829468(p0, (&b0), (*e0).typ, LOC25, a0.s); } break; case ((Ttypekind292244) 28): case ((Ttypekind292244) 24): { TY532811 LOC27; Ropeobj178006* LOC28; memset((void*)LOC27, 0, sizeof(LOC27)); LOC27[0] = rdloc_538188_839829468(a0); LOC27[1] = lenfield_539305_839829468(p0); LOC28 = (Ropeobj178006*)0; LOC28 = HEX25_178905_2381377266(((NimStringDesc*) &T839829468_379), LOC27, 2); putintodest_550468_839829468(p0, (&b0), (*e0).typ, LOC28, a0.s); } break; case ((Ttypekind292244) 16): case ((Ttypekind292244) 4): { TY532811 LOC30; NI64 LOC31; Ropeobj178006* LOC32; memset((void*)LOC30, 0, sizeof(LOC30)); LOC30[0] = rdloc_538188_839829468(a0); LOC31 = (NI64)0; LOC31 = lengthord_320007_3876443242(a0.t); LOC30[1] = rope_178401_2381377266(LOC31); LOC32 = (Ropeobj178006*)0; LOC32 = HEX25_178905_2381377266(((NimStringDesc*) &T839829468_380), LOC30, 2); putintodest_550468_839829468(p0, (&b0), (*e0).typ, LOC32, a0.s); } break; default: { internalerror_196100_155036129((*(*e0).kindU.S6.sons->data[((NI) 0)]).info, ((NimStringDesc*) &T839829468_381)); } break; } memset((void*)LOC34, 0, sizeof(LOC34)); LOC34[0] = rdloc_538188_839829468(b0); LOC35 = (Ttype292840*)0; LOC35 = elemtype_320394_3876443242(t0); LOC34[1] = gentypeinfo_535941_839829468((*p0).module, LOC35); LOC36 = (Ropeobj178006*)0; LOC36 = ropecg_532407_839829468((*p0).module, ((NimStringDesc*) &T839829468_382), LOC34, 2); putintodest_550468_839829468(p0, d0, (*e0).typ, LOC36, a0.s); } break; case ((Ttypekind292244) 29): case ((Ttypekind292244) 16): case ((Ttypekind292244) 4): case ((Ttypekind292244) 22): case ((Ttypekind292244) 21): case ((Ttypekind292244) 26): case ((Ttypekind292244) 5): case ((Ttypekind292244) 24): { TY532811 LOC38; Ropeobj178006* LOC39; memset((void*)LOC38, 0, sizeof(LOC38)); LOC38[0] = rdloc_538188_839829468(a0); LOC38[1] = gentypeinfo_535941_839829468((*p0).module, t0); LOC39 = (Ropeobj178006*)0; LOC39 = ropecg_532407_839829468((*p0).module, ((NimStringDesc*) &T839829468_383), LOC38, 2); putintodest_550468_839829468(p0, d0, (*e0).typ, LOC39, a0.s); } break; case ((Ttypekind292244) 3): case ((Ttypekind292244) 62): { localerror_196085_155036129((*e0).info, ((NimStringDesc*) &T839829468_384)); } break; default: { TY532811 LOC42; Ropeobj178006* LOC43; memset((void*)LOC42, 0, sizeof(LOC42)); LOC42[0] = addrloc_538204_839829468(a0); LOC42[1] = gentypeinfo_535941_839829468((*p0).module, t0); LOC43 = (Ropeobj178006*)0; LOC43 = ropecg_532407_839829468((*p0).module, ((NimStringDesc*) &T839829468_383), LOC42, 2); putintodest_550468_839829468(p0, d0, (*e0).typ, LOC43, a0.s); } break; } gcusage_554439_839829468(e0); } N_NIMCALL(void, gengettypeinfo_555383_839829468)(Tcproc529021* p0, Tnode292802* e0, Tloc292816* d0) { Ttype292840* t0; Ropeobj178006* LOC1; t0 = skiptypes_296099_850551059((*(*e0).kindU.S6.sons->data[((NI) 1)]).typ, IL64(211106242013440)); LOC1 = (Ropeobj178006*)0; LOC1 = gentypeinfo_535941_839829468((*p0).module, t0); putintodest_550468_839829468(p0, d0, (*e0).typ, LOC1, ((Tstorageloc292812) 0)); } N_NIMCALL(void, genswap_555638_839829468)(Tcproc529021* p0, Tnode292802* e0, Tloc292816* d0) { Tloc292816 a0; Tloc292816 b0; Tloc292816 tmp0; Ttype292840* LOC1; memset((void*)(&a0), 0, sizeof(a0)); memset((void*)(&b0), 0, sizeof(b0)); memset((void*)(&tmp0), 0, sizeof(tmp0)); LOC1 = (Ttype292840*)0; LOC1 = skiptypes_296099_850551059((*(*e0).kindU.S6.sons->data[((NI) 1)]).typ, IL64(211106240964864)); gettemp_537032_839829468(p0, LOC1, (&tmp0), NIM_FALSE); initlocexpr_539283_839829468(p0, (*e0).kindU.S6.sons->data[((NI) 1)], (&a0)); initlocexpr_539283_839829468(p0, (*e0).kindU.S6.sons->data[((NI) 2)], (&b0)); genassignment_539264_839829468(p0, tmp0, a0, 0); genassignment_539264_839829468(p0, a0, b0, 0); genassignment_539264_839829468(p0, b0, tmp0, 0); } N_NIMCALL(void, unaryexpr_551209_839829468)(Tcproc529021* p0, Tnode292802* e0, Tloc292816* d0, NimStringDesc* frmt0) { Tloc292816 a0; TY178507 LOC1; Ropeobj178006* LOC2; memset((void*)(&a0), 0, sizeof(a0)); initlocexpr_539283_839829468(p0, (*e0).kindU.S6.sons->data[((NI) 1)], (&a0)); memset((void*)LOC1, 0, sizeof(LOC1)); LOC1[0] = rdloc_538188_839829468(a0); LOC2 = (Ropeobj178006*)0; LOC2 = ropecg_532407_839829468((*p0).module, frmt0, LOC1, 1); putintodest_550468_839829468(p0, d0, (*e0).typ, LOC2, ((Tstorageloc292812) 0)); } N_NIMCALL(void, binarystmt_550501_839829468)(Tcproc529021* p0, Tnode292802* e0, Tloc292816* d0, NimStringDesc* frmt0) { Tloc292816 a0; Tloc292816 b0; TY532811 LOC5; memset((void*)(&a0), 0, sizeof(a0)); memset((void*)(&b0), 0, sizeof(b0)); { if (!!(((*d0).k == ((Tlockind292808) 0)))) goto LA3; internalerror_196100_155036129((*e0).info, ((NimStringDesc*) &T839829468_387)); } LA3: ; initlocexpr_539283_839829468(p0, (*e0).kindU.S6.sons->data[((NI) 1)], (&a0)); initlocexpr_539283_839829468(p0, (*e0).kindU.S6.sons->data[((NI) 2)], (&b0)); memset((void*)LOC5, 0, sizeof(LOC5)); LOC5[0] = rdloc_538188_839829468(a0); LOC5[1] = rdloc_538188_839829468(b0); linecg_532707_839829468(p0, ((Tcprocsection529011) 2), frmt0, LOC5, 2); } N_NIMCALL(void, genstrconcat_554452_839829468)(Tcproc529021* p0, Tnode292802* e0, Tloc292816* d0) { Tloc292816 a0; Tloc292816 tmp0; NI L0; Ropeobj178006* appends0; Ropeobj178006* lens0; TY535238 LOC21; Ropeobj178006** LOC22; memset((void*)(&a0), 0, sizeof(a0)); memset((void*)(&tmp0), 0, sizeof(tmp0)); gettemp_537032_839829468(p0, (*e0).typ, (&tmp0), NIM_FALSE); L0 = ((NI) 0); appends0 = NIM_NIL; lens0 = NIM_NIL; { NI i_554475_839829468; NI HEX3Atmp_554547_839829468; NI LOC2; NI res_554550_839829468; i_554475_839829468 = (NI)0; HEX3Atmp_554547_839829468 = (NI)0; LOC2 = (NI)0; LOC2 = sonslen_295351_850551059(e0); HEX3Atmp_554547_839829468 = (NI)(LOC2 - ((NI) 2)); res_554550_839829468 = ((NI) 0); { while (1) { if (!(res_554550_839829468 <= HEX3Atmp_554547_839829468)) goto LA4; i_554475_839829468 = res_554550_839829468; initlocexpr_539283_839829468(p0, (*e0).kindU.S6.sons->data[(NI)(i_554475_839829468 + ((NI) 1))], (&a0)); { Ttype292840* LOC7; TY532811 LOC10; Ropeobj178006* LOC11; LOC7 = (Ttype292840*)0; LOC7 = skiptypes_296099_850551059((*(*e0).kindU.S6.sons->data[(NI)(i_554475_839829468 + ((NI) 1))]).typ, IL64(211106242013440)); if (!((*LOC7).kind == ((Ttypekind292244) 2))) goto LA8; L0 += ((NI) 1); memset((void*)LOC10, 0, sizeof(LOC10)); LOC10[0] = tmp0.r; LOC10[1] = rdloc_538188_839829468(a0); LOC11 = (Ropeobj178006*)0; LOC11 = ropecg_532407_839829468((*p0).module, ((NimStringDesc*) &T839829468_390), LOC10, 2); add_178482_2381377266(&appends0, LOC11); } goto LA5; LA8: ; { TY532811 LOC19; Ropeobj178006* LOC20; { if (!((*(*e0).kindU.S6.sons->data[(NI)(i_554475_839829468 + ((NI) 1))]).kind >= ((Tnodekind292020) 20) && (*(*e0).kindU.S6.sons->data[(NI)(i_554475_839829468 + ((NI) 1))]).kind <= ((Tnodekind292020) 22))) goto LA15; L0 += ((*(*e0).kindU.S6.sons->data[(NI)(i_554475_839829468 + ((NI) 1))]).kindU.S3.strval ? (*(*e0).kindU.S6.sons->data[(NI)(i_554475_839829468 + ((NI) 1))]).kindU.S3.strval->Sup.len : 0); } goto LA13; LA15: ; { TY532811 LOC18; memset((void*)LOC18, 0, sizeof(LOC18)); LOC18[0] = rdloc_538188_839829468(a0); LOC18[1] = lenfield_539305_839829468(p0); addf_179205_2381377266(&lens0, ((NimStringDesc*) &T839829468_391), LOC18, 2); } LA13: ; memset((void*)LOC19, 0, sizeof(LOC19)); LOC19[0] = tmp0.r; LOC19[1] = rdloc_538188_839829468(a0); LOC20 = (Ropeobj178006*)0; LOC20 = ropecg_532407_839829468((*p0).module, ((NimStringDesc*) &T839829468_392), LOC19, 2); add_178482_2381377266(&appends0, LOC20); } LA5: ; res_554550_839829468 += ((NI) 1); } LA4: ; } } memset((void*)LOC21, 0, sizeof(LOC21)); LOC21[0] = tmp0.r; LOC21[1] = lens0; LOC21[2] = rope_178401_2381377266(((NI64) (L0))); linefmt_532714_839829468(p0, ((Tcprocsection529011) 2), ((NimStringDesc*) &T839829468_393), LOC21, 3); LOC22 = (Ropeobj178006**)0; LOC22 = s_529179_3723162438(p0, ((Tcprocsection529011) 2)); add_178482_2381377266(LOC22, appends0); { if (!((*d0).k == ((Tlockind292808) 0))) goto LA25; genericAssign((void*)(&(*d0)), (void*)(&tmp0), (&NTI292816)); } goto LA23; LA25: ; { genassignment_539264_839829468(p0, (*d0), tmp0, 0); } LA23: ; gcusage_554439_839829468(e0); } N_NIMCALL(void, genstrappend_554554_839829468)(Tcproc529021* p0, Tnode292802* e0, Tloc292816* d0) { Tloc292816 a0; Tloc292816 dest0; Ropeobj178006* appends0; Ropeobj178006* lens0; NI L0; TY535238 LOC21; Ropeobj178006** LOC22; memset((void*)(&a0), 0, sizeof(a0)); memset((void*)(&dest0), 0, sizeof(dest0)); appends0 = (Ropeobj178006*)0; lens0 = (Ropeobj178006*)0; L0 = ((NI) 0); initlocexpr_539283_839829468(p0, (*e0).kindU.S6.sons->data[((NI) 1)], (&dest0)); { NI i_554615_839829468; NI HEX3Atmp_554676_839829468; NI LOC2; NI res_554679_839829468; i_554615_839829468 = (NI)0; HEX3Atmp_554676_839829468 = (NI)0; LOC2 = (NI)0; LOC2 = sonslen_295351_850551059(e0); HEX3Atmp_554676_839829468 = (NI)(LOC2 - ((NI) 3)); res_554679_839829468 = ((NI) 0); { while (1) { if (!(res_554679_839829468 <= HEX3Atmp_554676_839829468)) goto LA4; i_554615_839829468 = res_554679_839829468; initlocexpr_539283_839829468(p0, (*e0).kindU.S6.sons->data[(NI)(i_554615_839829468 + ((NI) 2))], (&a0)); { Ttype292840* LOC7; TY532811 LOC10; Ropeobj178006* LOC11; LOC7 = (Ttype292840*)0; LOC7 = skiptypes_296099_850551059((*(*e0).kindU.S6.sons->data[(NI)(i_554615_839829468 + ((NI) 2))]).typ, IL64(211106242013440)); if (!((*LOC7).kind == ((Ttypekind292244) 2))) goto LA8; L0 += ((NI) 1); memset((void*)LOC10, 0, sizeof(LOC10)); LOC10[0] = rdloc_538188_839829468(dest0); LOC10[1] = rdloc_538188_839829468(a0); LOC11 = (Ropeobj178006*)0; LOC11 = ropecg_532407_839829468((*p0).module, ((NimStringDesc*) &T839829468_390), LOC10, 2); add_178482_2381377266(&appends0, LOC11); } goto LA5; LA8: ; { TY532811 LOC19; Ropeobj178006* LOC20; { if (!((*(*e0).kindU.S6.sons->data[(NI)(i_554615_839829468 + ((NI) 2))]).kind >= ((Tnodekind292020) 20) && (*(*e0).kindU.S6.sons->data[(NI)(i_554615_839829468 + ((NI) 2))]).kind <= ((Tnodekind292020) 22))) goto LA15; L0 += ((*(*e0).kindU.S6.sons->data[(NI)(i_554615_839829468 + ((NI) 2))]).kindU.S3.strval ? (*(*e0).kindU.S6.sons->data[(NI)(i_554615_839829468 + ((NI) 2))]).kindU.S3.strval->Sup.len : 0); } goto LA13; LA15: ; { TY532811 LOC18; memset((void*)LOC18, 0, sizeof(LOC18)); LOC18[0] = rdloc_538188_839829468(a0); LOC18[1] = lenfield_539305_839829468(p0); addf_179205_2381377266(&lens0, ((NimStringDesc*) &T839829468_391), LOC18, 2); } LA13: ; memset((void*)LOC19, 0, sizeof(LOC19)); LOC19[0] = rdloc_538188_839829468(dest0); LOC19[1] = rdloc_538188_839829468(a0); LOC20 = (Ropeobj178006*)0; LOC20 = ropecg_532407_839829468((*p0).module, ((NimStringDesc*) &T839829468_392), LOC19, 2); add_178482_2381377266(&appends0, LOC20); } LA5: ; res_554679_839829468 += ((NI) 1); } LA4: ; } } memset((void*)LOC21, 0, sizeof(LOC21)); LOC21[0] = rdloc_538188_839829468(dest0); LOC21[1] = lens0; LOC21[2] = rope_178401_2381377266(((NI64) (L0))); linefmt_532714_839829468(p0, ((Tcprocsection529011) 2), ((NimStringDesc*) &T839829468_395), LOC21, 3); LOC22 = (Ropeobj178006**)0; LOC22 = s_529179_3723162438(p0, ((Tcprocsection529011) 2)); add_178482_2381377266(LOC22, appends0); gcusage_554439_839829468(e0); } N_NIMCALL(void, genseqelemappend_554683_839829468)(Tcproc529021* p0, Tnode292802* e0, Tloc292816* d0) { NimStringDesc* seqappendpattern0; Tloc292816 a0; Tloc292816 b0; Tloc292816 dest0; Ttype292840* bt0; TY535238 LOC8; Ttype292840* LOC9; TY532811 LOC10; TY532811 LOC11; { NIM_BOOL LOC3; LOC3 = (NIM_BOOL)0; LOC3 = (gcmd_169132_2607990831 == ((Tcommands169076) 2)); if (LOC3) goto LA4; LOC3 = (((*(*(*p0).module).module).flags &(1U<<((NU)(((Tsymflag292184) 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_539283_839829468(p0, (*e0).kindU.S6.sons->data[((NI) 1)], (&a0)); initlocexpr_539283_839829468(p0, (*e0).kindU.S6.sons->data[((NI) 2)], (&b0)); bt0 = skiptypes_296099_850551059((*(*e0).kindU.S6.sons->data[((NI) 2)]).typ, IL64(211106240964864)); memset((void*)LOC8, 0, sizeof(LOC8)); LOC8[0] = rdloc_538188_839829468(a0); LOC9 = (Ttype292840*)0; LOC9 = skiptypes_296099_850551059((*(*e0).kindU.S6.sons->data[((NI) 1)]).typ, IL64(211106240964864)); LOC8[1] = gettypedesc_535671_839829468((*p0).module, LOC9); LOC8[2] = gettypedesc_535671_839829468((*p0).module, bt0); linecg_532707_839829468(p0, ((Tcprocsection529011) 2), seqappendpattern0, LOC8, 3); initloc_532273_839829468((&dest0), ((Tlockind292808) 6), bt0, ((Tstorageloc292812) 3)); memset((void*)LOC10, 0, sizeof(LOC10)); LOC10[0] = rdloc_538188_839829468(a0); LOC10[1] = lenfield_539305_839829468(p0); dest0.r = ropecg_532407_839829468(NIM_NIL, ((NimStringDesc*) &T839829468_398), LOC10, 2); genassignment_539264_839829468(p0, dest0, b0, 3); memset((void*)LOC11, 0, sizeof(LOC11)); LOC11[0] = rdloc_538188_839829468(a0); LOC11[1] = lenfield_539305_839829468(p0); linecg_532707_839829468(p0, ((Tcprocsection529011) 2), ((NimStringDesc*) &T839829468_399), LOC11, 2); gcusage_554439_839829468(e0); } N_NIMCALL(void, binaryexpr_550549_839829468)(Tcproc529021* p0, Tnode292802* e0, Tloc292816* d0, NimStringDesc* frmt0) { Tloc292816 a0; Tloc292816 b0; TY532811 LOC1; Ropeobj178006* LOC2; memset((void*)(&a0), 0, sizeof(a0)); memset((void*)(&b0), 0, sizeof(b0)); initlocexpr_539283_839829468(p0, (*e0).kindU.S6.sons->data[((NI) 1)], (&a0)); initlocexpr_539283_839829468(p0, (*e0).kindU.S6.sons->data[((NI) 2)], (&b0)); memset((void*)LOC1, 0, sizeof(LOC1)); LOC1[0] = rdloc_538188_839829468(a0); LOC1[1] = rdloc_538188_839829468(b0); LOC2 = (Ropeobj178006*)0; LOC2 = ropecg_532407_839829468((*p0).module, frmt0, LOC1, 2); putintodest_550468_839829468(p0, d0, (*e0).typ, LOC2, ((Tstorageloc292812) 0)); } N_NIMCALL(void, genstrequals_556666_839829468)(Tcproc529021* p0, Tnode292802* e0, Tloc292816* d0) { Tloc292816 x0; Tnode292802* a0; Tnode292802* 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 == ((Tnodekind292020) 23)); if (LOC3) goto LA4; LOC3 = ((*b0).kind == ((Tnodekind292020) 23)); LA4: ; if (!LOC3) goto LA5; binaryexpr_550549_839829468(p0, e0, d0, ((NimStringDesc*) &T839829468_341)); } goto LA1; LA5: ; { NIM_BOOL LOC8; TY532811 LOC12; Ropeobj178006* LOC13; LOC8 = (NIM_BOOL)0; LOC8 = ((*a0).kind >= ((Tnodekind292020) 20) && (*a0).kind <= ((Tnodekind292020) 22)); if (!(LOC8)) goto LA9; LOC8 = (((*a0).kindU.S3.strval) && ((*a0).kindU.S3.strval)->Sup.len == 0); LA9: ; if (!LOC8) goto LA10; initlocexpr_539283_839829468(p0, (*e0).kindU.S6.sons->data[((NI) 2)], (&x0)); memset((void*)LOC12, 0, sizeof(LOC12)); LOC12[0] = rdloc_538188_839829468(x0); LOC12[1] = lenfield_539305_839829468(p0); LOC13 = (Ropeobj178006*)0; LOC13 = ropecg_532407_839829468(NIM_NIL, ((NimStringDesc*) &T839829468_400), LOC12, 2); putintodest_550468_839829468(p0, d0, (*e0).typ, LOC13, ((Tstorageloc292812) 0)); } goto LA1; LA10: ; { NIM_BOOL LOC15; TY532811 LOC19; Ropeobj178006* LOC20; LOC15 = (NIM_BOOL)0; LOC15 = ((*b0).kind >= ((Tnodekind292020) 20) && (*b0).kind <= ((Tnodekind292020) 22)); if (!(LOC15)) goto LA16; LOC15 = (((*b0).kindU.S3.strval) && ((*b0).kindU.S3.strval)->Sup.len == 0); LA16: ; if (!LOC15) goto LA17; initlocexpr_539283_839829468(p0, (*e0).kindU.S6.sons->data[((NI) 1)], (&x0)); memset((void*)LOC19, 0, sizeof(LOC19)); LOC19[0] = rdloc_538188_839829468(x0); LOC19[1] = lenfield_539305_839829468(p0); LOC20 = (Ropeobj178006*)0; LOC20 = ropecg_532407_839829468(NIM_NIL, ((NimStringDesc*) &T839829468_400), LOC19, 2); putintodest_550468_839829468(p0, d0, (*e0).typ, LOC20, ((Tstorageloc292812) 0)); } goto LA1; LA17: ; { binaryexpr_550549_839829468(p0, e0, d0, ((NimStringDesc*) &T839829468_401)); } LA1: ; } N_NIMCALL(void, genisnil_552620_839829468)(Tcproc529021* p0, Tnode292802* e0, Tloc292816* d0) { Ttype292840* t0; t0 = skiptypes_296099_850551059((*(*e0).kindU.S6.sons->data[((NI) 1)]).typ, IL64(211106233624832)); { NIM_BOOL LOC3; LOC3 = (NIM_BOOL)0; LOC3 = ((*t0).kind == ((Ttypekind292244) 25)); if (!(LOC3)) goto LA4; LOC3 = ((*t0).callconv == ((Tcallingconvention292002) 8)); LA4: ; if (!LOC3) goto LA5; unaryexpr_551209_839829468(p0, e0, d0, ((NimStringDesc*) &T839829468_404)); } goto LA1; LA5: ; { unaryexpr_551209_839829468(p0, e0, d0, ((NimStringDesc*) &T839829468_405)); } LA1: ; } N_NIMCALL(void, gendollar_555391_839829468)(Tcproc529021* p0, Tnode292802* n0, Tloc292816* d0, NimStringDesc* frmt0) { Tloc292816 a0; TY178507 LOC1; memset((void*)(&a0), 0, sizeof(a0)); initlocexpr_539283_839829468(p0, (*n0).kindU.S6.sons->data[((NI) 1)], (&a0)); memset((void*)LOC1, 0, sizeof(LOC1)); LOC1[0] = rdloc_538188_839829468(a0); a0.r = ropecg_532407_839829468((*p0).module, frmt0, LOC1, 1); { if (!((*d0).k == ((Tlockind292808) 0))) goto LA4; gettemp_537032_839829468(p0, (*n0).typ, d0, NIM_FALSE); } LA4: ; genassignment_539264_839829468(p0, (*d0), a0, 0); gcusage_554439_839829468(n0); } N_NIMCALL(Ropeobj178006*, genofhelper_555139_839829468)(Tcproc529021* p0, Ttype292840* dest0, Ropeobj178006* a0) { Ropeobj178006* result0; Ropeobj178006* ti0; result0 = (Ropeobj178006*)0; ti0 = gentypeinfo_535941_839829468((*p0).module, dest0); { NIM_BOOL LOC3; NIM_BOOL LOC5; TY532811 LOC9; LOC3 = (NIM_BOOL)0; LOC3 = (((*dest0).flags &(1U<<((NU)(((Ttypeflag292431) 2))&31U)))!=0); if (LOC3) goto LA4; LOC5 = (NIM_BOOL)0; LOC5 = (((*(*p0).module).flags &(1U<<((NU)(((Codegenflag529025) 5))&7U)))!=0); if (!(LOC5)) goto LA6; LOC5 = !((((*dest0).flags &(1U<<((NU)(((Ttypeflag292431) 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_178905_2381377266(((NimStringDesc*) &T839829468_414), LOC9, 2); } goto LA1; LA7: ; { Ropeobj178006* LOC11; Ropeobj178006* cache0; Ropeobj178006* LOC12; TY178507 LOC13; TY535238 LOC14; LOC11 = (Ropeobj178006*)0; LOC11 = cgsym_532403_839829468((*p0).module, ((NimStringDesc*) &T839829468_129)); (*(*p0).module).labels += ((NI) 1); LOC12 = (Ropeobj178006*)0; LOC12 = rope_178401_2381377266(((NI64) ((*(*p0).module).labels))); cache0 = HEX26_178452_2381377266(((NimStringDesc*) &T839829468_415), LOC12); memset((void*)LOC13, 0, sizeof(LOC13)); LOC13[0] = cache0; addf_179205_2381377266(&(*(*p0).module).s[(((Tcfilesection529005) 9))- 0], ((NimStringDesc*) &T839829468_416), LOC13, 1); memset((void*)LOC14, 0, sizeof(LOC14)); LOC14[0] = a0; LOC14[1] = ti0; LOC14[2] = cache0; result0 = ropecg_532407_839829468((*p0).module, ((NimStringDesc*) &T839829468_417), LOC14, 3); } LA1: ; return result0; } N_NIMCALL(void, genof_555201_839829468)(Tcproc529021* p0, Tnode292802* x0, Ttype292840* typ0, Tloc292816* d0) { Tloc292816 a0; Ttype292840* dest0; Ropeobj178006* r0; Ropeobj178006* nilcheck0; Ttype292840* t0; Ttype292840* LOC41; memset((void*)(&a0), 0, sizeof(a0)); initlocexpr_539283_839829468(p0, x0, (&a0)); dest0 = skiptypes_296099_850551059(typ0, IL64(211106247256320)); r0 = rdloc_538188_839829468(a0); nilcheck0 = NIM_NIL; t0 = skiptypes_296099_850551059(a0.t, IL64(211106232576256)); { while (1) { Ttype292840* LOC16; if (!((*t0).kind == ((Ttypekind292244) 23) || (*t0).kind == ((Ttypekind292244) 21) || (*t0).kind == ((Ttypekind292244) 22))) goto LA2; { if (!!(((*t0).kind == ((Ttypekind292244) 23)))) goto LA5; nilcheck0 = r0; } LA5: ; { NIM_BOOL LOC9; NIM_BOOL LOC11; TY178507 LOC15; LOC9 = (NIM_BOOL)0; LOC9 = !(((*t0).kind == ((Ttypekind292244) 23))); if (LOC9) goto LA10; LOC11 = (NIM_BOOL)0; LOC11 = (gcmd_169132_2607990831 == ((Tcommands169076) 2)); if (LOC11) goto LA12; LOC11 = (((*(*(*p0).module).module).flags &(1U<<((NU)(((Tsymflag292184) 27))&31U)))!=0); LA12: ; LOC9 = !(LOC11); LA10: ; if (!LOC9) goto LA13; memset((void*)LOC15, 0, sizeof(LOC15)); LOC15[0] = r0; r0 = ropecg_532407_839829468(NIM_NIL, ((NimStringDesc*) &T839829468_124), LOC15, 1); } LA13: ; LOC16 = (Ttype292840*)0; LOC16 = lastson_295377_850551059(t0); t0 = skiptypes_296099_850551059(LOC16, IL64(211106232576256)); } LA2: ; } { NIM_BOOL LOC19; LOC19 = (NIM_BOOL)0; LOC19 = (gcmd_169132_2607990831 == ((Tcommands169076) 2)); if (LOC19) goto LA20; LOC19 = (((*(*(*p0).module).module).flags &(1U<<((NU)(((Tsymflag292184) 27))&31U)))!=0); LA20: ; if (!!(LOC19)) goto LA21; { while (1) { NIM_BOOL LOC25; TY533289 LOC27; Ropeobj178006* LOC28; LOC25 = (NIM_BOOL)0; LOC25 = ((*t0).kind == ((Ttypekind292244) 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 = (Ropeobj178006*)0; LOC28 = HEX25_178905_2381377266(((NimStringDesc*) &T839829468_153), LOC27, 0); add_178482_2381377266(&r0, LOC28); t0 = skiptypes_296099_850551059((*t0).sons->data[((NI) 0)], IL64(211106247215360)); } LA24: ; } } LA21: ; { NIM_BOOL LOC31; LOC31 = (NIM_BOOL)0; LOC31 = isobjlackingtypefield_533513_839829468(t0); if (!LOC31) goto LA32; globalerror_196071_155036129((*x0).info, ((Tmsgkind191002) 4), ((NimStringDesc*) &T839829468_412)); } LA32: ; { TY532811 LOC38; if (!!((nilcheck0 == NIM_NIL))) goto LA36; memset((void*)LOC38, 0, sizeof(LOC38)); LOC38[0] = nilcheck0; LOC38[1] = genofhelper_555139_839829468(p0, dest0, r0); r0 = ropecg_532407_839829468((*p0).module, ((NimStringDesc*) &T839829468_413), LOC38, 2); } goto LA34; LA36: ; { TY178507 LOC40; memset((void*)LOC40, 0, sizeof(LOC40)); LOC40[0] = genofhelper_555139_839829468(p0, dest0, r0); r0 = ropecg_532407_839829468((*p0).module, ((NimStringDesc*) &T839829468_418), LOC40, 1); } LA34: ; LOC41 = (Ttype292840*)0; LOC41 = getsystype_338150_3937434831(((Ttypekind292244) 1)); putintodest_550468_839829468(p0, d0, LOC41, r0, a0.s); } N_NIMCALL(void, genof_555331_839829468)(Tcproc529021* p0, Tnode292802* n0, Tloc292816* d0) { genof_555201_839829468(p0, (*n0).kindU.S6.sons->data[((NI) 1)], (*(*n0).kindU.S6.sons->data[((NI) 2)]).typ, d0); } N_NIMCALL(void, rawgennew_554741_839829468)(Tcproc529021* p0, Tloc292816 a0, Ropeobj178006* sizeexpr_554745_839829468) { Ropeobj178006* sizeexpr0; Ttype292840* reftype0; Tloc292816 b0; TY535238 args0; Ttype292840* bt0; sizeexpr0 = sizeexpr_554745_839829468; reftype0 = skiptypes_296099_850551059(a0.t, IL64(211106242013440)); memset((void*)(&b0), 0, sizeof(b0)); initloc_532273_839829468((&b0), ((Tlockind292808) 6), a0.t, ((Tstorageloc292812) 3)); { TY178507 LOC5; Ttype292840* LOC6; if (!sizeexpr0 == 0) goto LA3; memset((void*)LOC5, 0, sizeof(LOC5)); LOC6 = (Ttype292840*)0; LOC6 = skiptypes_296099_850551059((*reftype0).sons->data[((NI) 0)], IL64(211106233624832)); LOC5[0] = gettypedesc_535671_839829468((*p0).module, LOC6); sizeexpr0 = HEX25_178905_2381377266(((NimStringDesc*) &T839829468_419), LOC5, 1); } LA3: ; memset((void*)args0, 0, sizeof(args0)); args0[0] = gettypedesc_535671_839829468((*p0).module, reftype0); args0[1] = gentypeinfo_535941_839829468((*p0).module, reftype0); args0[2] = sizeexpr0; { NIM_BOOL LOC9; TY532811 LOC21; LOC9 = (NIM_BOOL)0; LOC9 = (a0.s == ((Tstorageloc292812) 3)); if (!(LOC9)) goto LA10; LOC9 = usesnativegc_169177_2607990831(); LA10: ; if (!LOC9) goto LA11; { NIM_BOOL LOC15; TY178507 LOC18; LOC15 = (NIM_BOOL)0; LOC15 = canformacycle_320123_3876443242(a0.t); if (!LOC15) goto LA16; memset((void*)LOC18, 0, sizeof(LOC18)); LOC18[0] = rdloc_538188_839829468(a0); linefmt_532714_839829468(p0, ((Tcprocsection529011) 2), ((NimStringDesc*) &T839829468_420), LOC18, 1); } goto LA13; LA16: ; { TY178507 LOC20; memset((void*)LOC20, 0, sizeof(LOC20)); LOC20[0] = rdloc_538188_839829468(a0); linefmt_532714_839829468(p0, ((Tcprocsection529011) 2), ((NimStringDesc*) &T839829468_255), LOC20, 1); } LA13: ; b0.r = ropecg_532407_839829468((*p0).module, ((NimStringDesc*) &T839829468_421), args0, 3); memset((void*)LOC21, 0, sizeof(LOC21)); LOC21[0] = rdloc_538188_839829468(a0); LOC21[1] = rdloc_538188_839829468(b0); linefmt_532714_839829468(p0, ((Tcprocsection529011) 2), ((NimStringDesc*) &T839829468_123), LOC21, 2); } goto LA7; LA11: ; { b0.r = ropecg_532407_839829468((*p0).module, ((NimStringDesc*) &T839829468_422), args0, 3); genassignment_539264_839829468(p0, a0, b0, 0); } LA7: ; bt0 = skiptypes_296099_850551059((*reftype0).sons->data[((NI) 0)], IL64(211106233624832)); genobjectinit_538242_839829468(p0, ((Tcprocsection529011) 2), bt0, a0, NIM_FALSE); } N_NIMCALL(void, gennew_554782_839829468)(Tcproc529021* p0, Tnode292802* e0) { Tloc292816 a0; memset((void*)(&a0), 0, sizeof(a0)); initlocexpr_539283_839829468(p0, (*e0).kindU.S6.sons->data[((NI) 1)], (&a0)); { NI LOC3; Tloc292816 se0; Ropeobj178006* LOC6; LOC3 = (NI)0; LOC3 = len_293081_850551059(e0); if (!(LOC3 == ((NI) 3))) goto LA4; memset((void*)(&se0), 0, sizeof(se0)); initlocexpr_539283_839829468(p0, (*e0).kindU.S6.sons->data[((NI) 2)], (&se0)); LOC6 = (Ropeobj178006*)0; LOC6 = rdloc_538188_839829468(se0); rawgennew_554741_839829468(p0, a0, LOC6); } goto LA1; LA4: ; { rawgennew_554741_839829468(p0, a0, NIM_NIL); } LA1: ; gcusage_554439_839829468(e0); } N_NIMCALL(void, gennewfinalize_555110_839829468)(Tcproc529021* p0, Tnode292802* e0) { Tloc292816 a0; Tloc292816 b0; Tloc292816 f0; Ttype292840* reftype0; Ttype292840* bt0; Ropeobj178006* ti0; TY532811 LOC1; TY535238 LOC2; Ttype292840* LOC3; Ttype292840* LOC4; Ttype292840* LOC5; memset((void*)(&a0), 0, sizeof(a0)); memset((void*)(&b0), 0, sizeof(b0)); memset((void*)(&f0), 0, sizeof(f0)); reftype0 = (Ttype292840*)0; bt0 = (Ttype292840*)0; ti0 = (Ropeobj178006*)0; reftype0 = skiptypes_296099_850551059((*(*e0).kindU.S6.sons->data[((NI) 1)]).typ, IL64(211106242013440)); initlocexpr_539283_839829468(p0, (*e0).kindU.S6.sons->data[((NI) 1)], (&a0)); initlocexpr_539283_839829468(p0, (*e0).kindU.S6.sons->data[((NI) 2)], (&f0)); initloc_532273_839829468((&b0), ((Tlockind292808) 6), a0.t, ((Tstorageloc292812) 3)); ti0 = gentypeinfo_535941_839829468((*p0).module, reftype0); memset((void*)LOC1, 0, sizeof(LOC1)); LOC1[0] = ti0; LOC1[1] = rdloc_538188_839829468(f0); addf_179205_2381377266(&(*(*p0).module).s[(((Tcfilesection529005) 14))- 0], ((NimStringDesc*) &T839829468_423), LOC1, 2); memset((void*)LOC2, 0, sizeof(LOC2)); LOC2[0] = gettypedesc_535671_839829468((*p0).module, reftype0); LOC2[1] = ti0; LOC3 = (Ttype292840*)0; LOC3 = lastson_295377_850551059(reftype0); LOC4 = (Ttype292840*)0; LOC4 = skiptypes_296099_850551059(LOC3, IL64(211106233624832)); LOC2[2] = gettypedesc_535671_839829468((*p0).module, LOC4); b0.r = ropecg_532407_839829468((*p0).module, ((NimStringDesc*) &T839829468_424), LOC2, 3); genassignment_539264_839829468(p0, a0, b0, 0); LOC5 = (Ttype292840*)0; LOC5 = lastson_295377_850551059(reftype0); bt0 = skiptypes_296099_850551059(LOC5, IL64(211106233624832)); genobjectinit_538242_839829468(p0, ((Tcprocsection529011) 2), bt0, a0, NIM_FALSE); gcusage_554439_839829468(e0); } N_NIMCALL(void, gennewseqaux_554795_839829468)(Tcproc529021* p0, Tloc292816 dest0, Ropeobj178006* length0) { Ttype292840* seqtype0; TY535238 args0; Tloc292816 call0; seqtype0 = skiptypes_296099_850551059(dest0.t, IL64(211106242013440)); memset((void*)args0, 0, sizeof(args0)); args0[0] = gettypedesc_535671_839829468((*p0).module, seqtype0); args0[1] = gentypeinfo_535941_839829468((*p0).module, seqtype0); args0[2] = length0; memset((void*)(&call0), 0, sizeof(call0)); initloc_532273_839829468((&call0), ((Tlockind292808) 6), dest0.t, ((Tstorageloc292812) 3)); { NIM_BOOL LOC3; TY532811 LOC15; LOC3 = (NIM_BOOL)0; LOC3 = (dest0.s == ((Tstorageloc292812) 3)); if (!(LOC3)) goto LA4; LOC3 = usesnativegc_169177_2607990831(); LA4: ; if (!LOC3) goto LA5; { NIM_BOOL LOC9; TY178507 LOC12; LOC9 = (NIM_BOOL)0; LOC9 = canformacycle_320123_3876443242(dest0.t); if (!LOC9) goto LA10; memset((void*)LOC12, 0, sizeof(LOC12)); LOC12[0] = rdloc_538188_839829468(dest0); linefmt_532714_839829468(p0, ((Tcprocsection529011) 2), ((NimStringDesc*) &T839829468_420), LOC12, 1); } goto LA7; LA10: ; { TY178507 LOC14; memset((void*)LOC14, 0, sizeof(LOC14)); LOC14[0] = rdloc_538188_839829468(dest0); linefmt_532714_839829468(p0, ((Tcprocsection529011) 2), ((NimStringDesc*) &T839829468_255), LOC14, 1); } LA7: ; call0.r = ropecg_532407_839829468((*p0).module, ((NimStringDesc*) &T839829468_425), args0, 3); memset((void*)LOC15, 0, sizeof(LOC15)); LOC15[0] = rdloc_538188_839829468(dest0); LOC15[1] = rdloc_538188_839829468(call0); linefmt_532714_839829468(p0, ((Tcprocsection529011) 2), ((NimStringDesc*) &T839829468_123), LOC15, 2); } goto LA1; LA5: ; { call0.r = ropecg_532407_839829468((*p0).module, ((NimStringDesc*) &T839829468_426), args0, 3); genassignment_539264_839829468(p0, dest0, call0, 0); } LA1: ; } N_NIMCALL(void, gennewseq_554824_839829468)(Tcproc529021* p0, Tnode292802* e0) { Tloc292816 a0; Tloc292816 b0; Ropeobj178006* LOC1; memset((void*)(&a0), 0, sizeof(a0)); memset((void*)(&b0), 0, sizeof(b0)); initlocexpr_539283_839829468(p0, (*e0).kindU.S6.sons->data[((NI) 1)], (&a0)); initlocexpr_539283_839829468(p0, (*e0).kindU.S6.sons->data[((NI) 2)], (&b0)); LOC1 = (Ropeobj178006*)0; LOC1 = rdloc_538188_839829468(b0); gennewseqaux_554795_839829468(p0, a0, LOC1); gcusage_554439_839829468(e0); } N_NIMCALL(void, gennewseqofcap_554836_839829468)(Tcproc529021* p0, Tnode292802* e0, Tloc292816* d0) { Ttype292840* seqtype0; Tloc292816 a0; TY535238 LOC1; Ropeobj178006* LOC2; seqtype0 = skiptypes_296099_850551059((*e0).typ, IL64(211106242013440)); memset((void*)(&a0), 0, sizeof(a0)); initlocexpr_539283_839829468(p0, (*e0).kindU.S6.sons->data[((NI) 1)], (&a0)); memset((void*)LOC1, 0, sizeof(LOC1)); LOC1[0] = gettypedesc_535671_839829468((*p0).module, seqtype0); LOC1[1] = gentypeinfo_535941_839829468((*p0).module, seqtype0); LOC1[2] = rdloc_538188_839829468(a0); LOC2 = (Ropeobj178006*)0; LOC2 = ropecg_532407_839829468((*p0).module, ((NimStringDesc*) &T839829468_427), LOC1, 3); putintodest_550468_839829468(p0, d0, (*e0).typ, LOC2, ((Tstorageloc292812) 0)); gcusage_554439_839829468(e0); } N_NIMCALL(Ropeobj178006*, getclosuretype_535683_839829468)(Tcgen529027* m0, Ttype292840* t0, Tclosuretypekind535679 kind0) { Ropeobj178006* result0; Intset268030 check0; Ropeobj178006* rettype0; Ropeobj178006* desc0; result0 = (Ropeobj178006*)0; memset((void*)(&check0), 0, sizeof(check0)); chckNil((void*)(&check0)); memset((void*)(&check0), 0, sizeof(check0)); initintset_268885_2627731572((&check0)); result0 = gettempname_533596_839829468(m0); rettype0 = (Ropeobj178006*)0; desc0 = (Ropeobj178006*)0; genprocparams_534115_839829468(m0, t0, &rettype0, &desc0, (&check0), !((kind0 == ((Tclosuretypekind535679) 0))), NIM_FALSE); { NIM_BOOL LOC3; LOC3 = (NIM_BOOL)0; LOC3 = isimportedtype_533449_839829468(t0); if (!!(LOC3)) goto LA4; { NIM_BOOL LOC8; TY535235 LOC12; LOC8 = (NIM_BOOL)0; LOC8 = !(((*t0).callconv == ((Tcallingconvention292002) 8))); if (LOC8) goto LA9; LOC8 = !((kind0 == ((Tclosuretypekind535679) 2))); LA9: ; if (!LOC8) goto LA10; memset((void*)LOC12, 0, sizeof(LOC12)); LOC12[0] = rope_178277_2381377266(Callingconvtostr_533585_839829468[((*t0).callconv)- 0]); LOC12[1] = rettype0; LOC12[2] = result0; LOC12[3] = desc0; addf_179205_2381377266(&(*m0).s[(((Tcfilesection529005) 3))- 0], ((NimStringDesc*) &T839829468_64), LOC12, 4); } goto LA6; LA10: ; { TY535238 LOC14; memset((void*)LOC14, 0, sizeof(LOC14)); LOC14[0] = result0; LOC14[1] = rettype0; LOC14[2] = desc0; addf_179205_2381377266(&(*m0).s[(((Tcfilesection529005) 3))- 0], ((NimStringDesc*) &T839829468_75), LOC14, 3); } LA6: ; } LA4: ; return result0; } N_NIMCALL(void, gensomecast_556480_839829468)(Tcproc529021* p0, Tnode292802* e0, Tloc292816* d0) { Tloc292816 a0; Ttype292840* etyp0; memset((void*)(&a0), 0, sizeof(a0)); initlocexpr_539283_839829468(p0, (*e0).kindU.S6.sons->data[((NI) 1)], (&a0)); etyp0 = skiptypes_296099_850551059((*e0).typ, IL64(211106233624832)); { NIM_BOOL LOC3; TY532811 LOC7; Ropeobj178006* LOC8; LOC3 = (NIM_BOOL)0; LOC3 = ((*etyp0).kind == ((Ttypekind292244) 18) || (*etyp0).kind == ((Ttypekind292244) 17) || (*etyp0).kind == ((Ttypekind292244) 16) || (*etyp0).kind == ((Ttypekind292244) 27) || (*etyp0).kind == ((Ttypekind292244) 48) || (*etyp0).kind == ((Ttypekind292244) 4)); if (!(LOC3)) goto LA4; LOC3 = !(((a0.flags &(1U<<((NU)(((Tlocflag292810) 0))&15U)))!=0)); LA4: ; if (!LOC3) goto LA5; memset((void*)LOC7, 0, sizeof(LOC7)); LOC7[0] = gettypedesc_535671_839829468((*p0).module, (*e0).typ); LOC7[1] = addrloc_538204_839829468(a0); LOC8 = (Ropeobj178006*)0; LOC8 = HEX25_178905_2381377266(((NimStringDesc*) &T839829468_429), LOC7, 2); putintodest_550468_839829468(p0, d0, (*e0).typ, LOC8, a0.s); } goto LA1; LA5: ; { NIM_BOOL LOC10; TY532811 LOC14; Ropeobj178006* LOC15; LOC10 = (NIM_BOOL)0; LOC10 = ((*etyp0).kind == ((Ttypekind292244) 25)); if (!(LOC10)) goto LA11; LOC10 = ((*etyp0).callconv == ((Tcallingconvention292002) 8)); LA11: ; if (!LOC10) goto LA12; memset((void*)LOC14, 0, sizeof(LOC14)); LOC14[0] = getclosuretype_535683_839829468((*p0).module, etyp0, ((Tclosuretypekind535679) 1)); LOC14[1] = rdcharloc_538227_839829468(a0); LOC15 = (Ropeobj178006*)0; LOC15 = HEX25_178905_2381377266(((NimStringDesc*) &T839829468_430), LOC14, 2); putintodest_550468_839829468(p0, d0, (*e0).typ, LOC15, a0.s); } goto LA1; LA12: ; { TY532811 LOC17; Ropeobj178006* LOC18; memset((void*)LOC17, 0, sizeof(LOC17)); LOC17[0] = gettypedesc_535671_839829468((*p0).module, (*e0).typ); LOC17[1] = rdcharloc_538227_839829468(a0); LOC18 = (Ropeobj178006*)0; LOC18 = HEX25_178905_2381377266(((NimStringDesc*) &T839829468_430), LOC17, 2); putintodest_550468_839829468(p0, d0, (*e0).typ, LOC18, a0.s); } LA1: ; } N_NIMCALL(void, unaryexprchar_551222_839829468)(Tcproc529021* p0, Tnode292802* e0, Tloc292816* d0, NimStringDesc* frmt0) { Tloc292816 a0; TY178507 LOC1; Ropeobj178006* LOC2; memset((void*)(&a0), 0, sizeof(a0)); initlocexpr_539283_839829468(p0, (*e0).kindU.S6.sons->data[((NI) 1)], (&a0)); memset((void*)LOC1, 0, sizeof(LOC1)); LOC1[0] = rdcharloc_538227_839829468(a0); LOC2 = (Ropeobj178006*)0; LOC2 = ropecg_532407_839829468((*p0).module, frmt0, LOC1, 1); putintodest_550468_839829468(p0, d0, (*e0).typ, LOC2, ((Tstorageloc292812) 0)); } N_NIMCALL(void, genord_556474_839829468)(Tcproc529021* p0, Tnode292802* e0, Tloc292816* d0) { unaryexprchar_551222_839829468(p0, e0, d0, ((NimStringDesc*) &T839829468_301)); } N_NIMCALL(void, genarraylen_555415_839829468)(Tcproc529021* p0, Tnode292802* e0, Tloc292816* d0, Tmagic292524 op0) { Tnode292802* a0; Ttype292840* typ0; a0 = (*e0).kindU.S6.sons->data[((NI) 1)]; { if (!((*a0).kind == ((Tnodekind292020) 64))) goto LA3; a0 = (*a0).kindU.S6.sons->data[((NI) 0)]; } LA3: ; typ0 = skiptypes_296099_850551059((*a0).typ, IL64(211106240964864)); switch ((*typ0).kind) { case ((Ttypekind292244) 27): case ((Ttypekind292244) 48): { { if (!(op0 == ((Tmagic292524) 8))) goto LA8; unaryexpr_551209_839829468(p0, e0, d0, ((NimStringDesc*) &T839829468_431)); } goto LA6; LA8: ; { unaryexpr_551209_839829468(p0, e0, d0, ((NimStringDesc*) &T839829468_432)); } LA6: ; } break; case ((Ttypekind292244) 29): { usestringh_532345_839829468((*p0).module); { if (!(op0 == ((Tmagic292524) 8))) goto LA14; unaryexpr_551209_839829468(p0, e0, d0, ((NimStringDesc*) &T839829468_433)); } goto LA12; LA14: ; { unaryexpr_551209_839829468(p0, e0, d0, ((NimStringDesc*) &T839829468_434)); } LA12: ; } break; case ((Ttypekind292244) 28): case ((Ttypekind292244) 24): { { NIM_BOOL LOC20; LOC20 = (NIM_BOOL)0; LOC20 = (gcmd_169132_2607990831 == ((Tcommands169076) 2)); if (LOC20) goto LA21; LOC20 = (((*(*(*p0).module).module).flags &(1U<<((NU)(((Tsymflag292184) 27))&31U)))!=0); LA21: ; if (!!(LOC20)) goto LA22; { if (!(op0 == ((Tmagic292524) 8))) goto LA26; unaryexpr_551209_839829468(p0, e0, d0, ((NimStringDesc*) &T839829468_435)); } goto LA24; LA26: ; { unaryexpr_551209_839829468(p0, e0, d0, ((NimStringDesc*) &T839829468_436)); } LA24: ; } goto LA18; LA22: ; { { if (!(op0 == ((Tmagic292524) 8))) goto LA32; unaryexpr_551209_839829468(p0, e0, d0, ((NimStringDesc*) &T839829468_437)); } goto LA30; LA32: ; { unaryexpr_551209_839829468(p0, e0, d0, ((NimStringDesc*) &T839829468_438)); } LA30: ; } LA18: ; } break; case ((Ttypekind292244) 16): case ((Ttypekind292244) 4): { { NI64 LOC40; Ropeobj178006* LOC41; if (!(op0 == ((Tmagic292524) 8))) goto LA38; LOC40 = (NI64)0; LOC40 = lastord_320004_3876443242(typ0); LOC41 = (Ropeobj178006*)0; LOC41 = rope_178401_2381377266(LOC40); putintodest_550468_839829468(p0, d0, (*e0).typ, LOC41, ((Tstorageloc292812) 0)); } goto LA36; LA38: ; { NI64 LOC43; Ropeobj178006* LOC44; LOC43 = (NI64)0; LOC43 = lengthord_320007_3876443242(typ0); LOC44 = (Ropeobj178006*)0; LOC44 = rope_178401_2381377266(LOC43); putintodest_550468_839829468(p0, d0, (*e0).typ, LOC44, ((Tstorageloc292812) 0)); } LA36: ; } break; default: { internalerror_196100_155036129((*e0).info, ((NimStringDesc*) &T839829468_439)); } break; } } N_NIMCALL(void, unarystmt_550527_839829468)(Tcproc529021* p0, Tnode292802* e0, Tloc292816* d0, NimStringDesc* frmt0) { Tloc292816 a0; TY178507 LOC5; memset((void*)(&a0), 0, sizeof(a0)); { if (!!(((*d0).k == ((Tlockind292808) 0)))) goto LA3; internalerror_196100_155036129((*e0).info, ((NimStringDesc*) &T839829468_442)); } LA3: ; initlocexpr_539283_839829468(p0, (*e0).kindU.S6.sons->data[((NI) 1)], (&a0)); memset((void*)LOC5, 0, sizeof(LOC5)); LOC5[0] = rdloc_538188_839829468(a0); linecg_532707_839829468(p0, ((Tcprocsection529011) 2), frmt0, LOC5, 1); } N_NIMCALL(void, gensetlengthstr_555632_839829468)(Tcproc529021* p0, Tnode292802* e0, Tloc292816* d0) { binarystmt_550501_839829468(p0, e0, d0, ((NimStringDesc*) &T839829468_445)); gcusage_554439_839829468(e0); } N_NIMCALL(void, gensetlengthseq_555500_839829468)(Tcproc529021* p0, Tnode292802* e0, Tloc292816* d0) { Tloc292816 a0; Tloc292816 b0; Ttype292840* t0; NimStringDesc* setlenpattern0; TY535235 LOC8; memset((void*)(&a0), 0, sizeof(a0)); memset((void*)(&b0), 0, sizeof(b0)); initlocexpr_539283_839829468(p0, (*e0).kindU.S6.sons->data[((NI) 1)], (&a0)); initlocexpr_539283_839829468(p0, (*e0).kindU.S6.sons->data[((NI) 2)], (&b0)); t0 = skiptypes_296099_850551059((*(*e0).kindU.S6.sons->data[((NI) 1)]).typ, IL64(211106240964864)); { NIM_BOOL LOC3; LOC3 = (NIM_BOOL)0; LOC3 = (gcmd_169132_2607990831 == ((Tcommands169076) 2)); if (LOC3) goto LA4; LOC3 = (((*(*(*p0).module).module).flags &(1U<<((NU)(((Tsymflag292184) 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_538188_839829468(a0); LOC8[1] = rdloc_538188_839829468(b0); LOC8[2] = gettypedesc_535671_839829468((*p0).module, t0); LOC8[3] = gettypedesc_535671_839829468((*p0).module, (*t0).sons->data[((NI) 0)]); linecg_532707_839829468(p0, ((Tcprocsection529011) 2), setlenpattern0, LOC8, 4); gcusage_554439_839829468(e0); } N_NIMCALL(Ropeobj178006*, rdsetelemloc_555662_839829468)(Tloc292816 a0, Ttype292840* settype0) { Ropeobj178006* result0; result0 = (Ropeobj178006*)0; result0 = rdcharloc_538227_839829468(a0); { NI64 LOC3; TY532811 LOC6; NI64 LOC7; LOC3 = (NI64)0; LOC3 = firstord_320001_3876443242(settype0); if (!!((LOC3 == IL64(0)))) goto LA4; memset((void*)LOC6, 0, sizeof(LOC6)); LOC6[0] = result0; LOC7 = (NI64)0; LOC7 = firstord_320001_3876443242(settype0); LOC6[1] = rope_178401_2381377266(LOC7); result0 = HEX25_178905_2381377266(((NimStringDesc*) &T839829468_448), LOC6, 2); } LA4: ; return result0; } N_NIMCALL(void, binarystmtinexcl_555857_839829468)(Tcproc529021* p0, Tnode292802* e0, Tloc292816* d0, NimStringDesc* frmt0) { Tloc292816 a0; Tloc292816 b0; TY532811 LOC1; memset((void*)(&a0), 0, sizeof(a0)); memset((void*)(&b0), 0, sizeof(b0)); initlocexpr_539283_839829468(p0, (*e0).kindU.S6.sons->data[((NI) 1)], (&a0)); initlocexpr_539283_839829468(p0, (*e0).kindU.S6.sons->data[((NI) 2)], (&b0)); memset((void*)LOC1, 0, sizeof(LOC1)); LOC1[0] = rdloc_538188_839829468(a0); LOC1[1] = rdsetelemloc_555662_839829468(b0, a0.t); linef_532700_839829468(p0, ((Tcprocsection529011) 2), frmt0, LOC1, 2); } N_NIMCALL(void, binaryexprchar_550809_839829468)(Tcproc529021* p0, Tnode292802* e0, Tloc292816* d0, NimStringDesc* frmt0) { Tloc292816 a0; Tloc292816 b0; TY532811 LOC1; Ropeobj178006* LOC2; memset((void*)(&a0), 0, sizeof(a0)); memset((void*)(&b0), 0, sizeof(b0)); initlocexpr_539283_839829468(p0, (*e0).kindU.S6.sons->data[((NI) 1)], (&a0)); initlocexpr_539283_839829468(p0, (*e0).kindU.S6.sons->data[((NI) 2)], (&b0)); memset((void*)LOC1, 0, sizeof(LOC1)); LOC1[0] = rdcharloc_538227_839829468(a0); LOC1[1] = rdcharloc_538227_839829468(b0); LOC2 = (Ropeobj178006*)0; LOC2 = ropecg_532407_839829468((*p0).module, frmt0, LOC1, 2); putintodest_550468_839829468(p0, d0, (*e0).typ, LOC2, ((Tstorageloc292812) 0)); } N_NIMCALL(NIM_BOOL, fewcmps_555803_839829468)(Tnode292802* s0) { NIM_BOOL result0; result0 = (NIM_BOOL)0; { if (!!(((*s0).kind == ((Tnodekind292020) 39)))) goto LA3; internalerror_196100_155036129((*s0).info, ((NimStringDesc*) &T839829468_463)); } LA3: ; { NIM_BOOL LOC7; NI64 LOC8; LOC7 = (NIM_BOOL)0; LOC8 = (NI64)0; LOC8 = getsize_320135_3876443242((*s0).typ); LOC7 = (LOC8 <= ((NI64) (intsize_176641_4151366050))); if (!(LOC7)) goto LA9; LOC7 = (((*s0).flags &(1U<<((NU)(((Tnodeflag292427) 4))&15U)))!=0); LA9: ; if (!LOC7) goto LA10; result0 = NIM_FALSE; } goto LA5; LA10: ; { Ttype292840* LOC13; LOC13 = (Ttype292840*)0; LOC13 = elemtype_320394_3876443242((*s0).typ); if (!((*LOC13).kind == ((Ttypekind292244) 31) || (*LOC13).kind >= ((Ttypekind292244) 33) && (*LOC13).kind <= ((Ttypekind292244) 35))) goto LA14; result0 = NIM_TRUE; } goto LA5; LA14: ; { NI LOC17; LOC17 = (NI)0; LOC17 = sonslen_295351_850551059(s0); result0 = (LOC17 <= ((NI) 8)); } LA5: ; return result0; } N_NIMCALL(void, binaryexprin_555837_839829468)(Tcproc529021* p0, Tnode292802* e0, Tloc292816* a0, Tloc292816* b0, Tloc292816* d0, NimStringDesc* frmt0) { TY532811 LOC1; Ropeobj178006* LOC2; memset((void*)LOC1, 0, sizeof(LOC1)); LOC1[0] = rdloc_538188_839829468((*a0)); LOC1[1] = rdsetelemloc_555662_839829468((*b0), (*a0).t); LOC2 = (Ropeobj178006*)0; LOC2 = HEX25_178905_2381377266(frmt0, LOC1, 2); putintodest_550468_839829468(p0, d0, (*e0).typ, LOC2, ((Tstorageloc292812) 0)); } N_NIMCALL(void, geninexpraux_553496_839829468)(Tcproc529021* p0, Tnode292802* e0, Tloc292816* a0, Tloc292816* b0, Tloc292816* d0) { Ttype292840* LOC1; NI64 LOC2; LOC1 = (Ttype292840*)0; LOC1 = skiptypes_296099_850551059((*(*e0).kindU.S6.sons->data[((NI) 1)]).typ, IL64(211106240964864)); LOC2 = (NI64)0; LOC2 = getsize_320135_3876443242(LOC1); switch (((NI) (LOC2))) { case ((NI) 1): { binaryexprin_555837_839829468(p0, e0, a0, b0, d0, ((NimStringDesc*) &T839829468_467)); } break; case ((NI) 2): { binaryexprin_555837_839829468(p0, e0, a0, b0, d0, ((NimStringDesc*) &T839829468_468)); } break; case ((NI) 4): { binaryexprin_555837_839829468(p0, e0, a0, b0, d0, ((NimStringDesc*) &T839829468_469)); } break; case ((NI) 8): { binaryexprin_555837_839829468(p0, e0, a0, b0, d0, ((NimStringDesc*) &T839829468_470)); } break; default: { binaryexprin_555837_839829468(p0, e0, a0, b0, d0, ((NimStringDesc*) &T839829468_471)); } break; } } N_NIMCALL(void, geninop_556009_839829468)(Tcproc529021* p0, Tnode292802* e0, Tloc292816* d0) { Tloc292816 a0; Tloc292816 b0; Tloc292816 x0; Tloc292816 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; Tnode292802* ea0; NI length0; LOC3 = (NIM_BOOL)0; LOC3 = ((*(*e0).kindU.S6.sons->data[((NI) 1)]).kind == ((Tnodekind292020) 39)); if (!(LOC3)) goto LA4; LOC3 = fewcmps_555803_839829468((*e0).kindU.S6.sons->data[((NI) 1)]); LA4: ; if (!LOC3) goto LA5; { if (!((*(*e0).kindU.S6.sons->data[((NI) 2)]).kind == ((Tnodekind292020) 70) || (*(*e0).kindU.S6.sons->data[((NI) 2)]).kind == ((Tnodekind292020) 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_539283_839829468(p0, ea0, (&a0)); initloc_532273_839829468((&b0), ((Tlockind292808) 6), (*e0).typ, ((Tstorageloc292812) 0)); b0.r = rope_178277_2381377266(((NimStringDesc*) &T839829468_118)); length0 = sonslen_295351_850551059((*e0).kindU.S6.sons->data[((NI) 1)]); { NI i_556061_839829468; NI HEX3Atmp_556412_839829468; NI res_556415_839829468; i_556061_839829468 = (NI)0; HEX3Atmp_556412_839829468 = (NI)0; HEX3Atmp_556412_839829468 = (NI)(length0 - ((NI) 1)); res_556415_839829468 = ((NI) 0); { while (1) { if (!(res_556415_839829468 <= HEX3Atmp_556412_839829468)) goto LA14; i_556061_839829468 = res_556415_839829468; { TY535238 LOC19; if (!((*(*(*e0).kindU.S6.sons->data[((NI) 1)]).kindU.S6.sons->data[i_556061_839829468]).kind == ((Tnodekind292020) 44))) goto LA17; initlocexpr_539283_839829468(p0, (*(*(*e0).kindU.S6.sons->data[((NI) 1)]).kindU.S6.sons->data[i_556061_839829468]).kindU.S6.sons->data[((NI) 0)], (&x0)); initlocexpr_539283_839829468(p0, (*(*(*e0).kindU.S6.sons->data[((NI) 1)]).kindU.S6.sons->data[i_556061_839829468]).kindU.S6.sons->data[((NI) 1)], (&y0)); memset((void*)LOC19, 0, sizeof(LOC19)); LOC19[0] = rdcharloc_538227_839829468(a0); LOC19[1] = rdcharloc_538227_839829468(x0); LOC19[2] = rdcharloc_538227_839829468(y0); addf_179205_2381377266(&b0.r, ((NimStringDesc*) &T839829468_464), LOC19, 3); } goto LA15; LA17: ; { TY532811 LOC21; initlocexpr_539283_839829468(p0, (*(*e0).kindU.S6.sons->data[((NI) 1)]).kindU.S6.sons->data[i_556061_839829468], (&x0)); memset((void*)LOC21, 0, sizeof(LOC21)); LOC21[0] = rdcharloc_538227_839829468(a0); LOC21[1] = rdcharloc_538227_839829468(x0); addf_179205_2381377266(&b0.r, ((NimStringDesc*) &T839829468_465), LOC21, 2); } LA15: ; { if (!(i_556061_839829468 < (NI)(length0 - ((NI) 1)))) goto LA24; add_178487_2381377266(&b0.r, ((NimStringDesc*) &T839829468_466)); } LA24: ; res_556415_839829468 += ((NI) 1); } LA14: ; } } add_178487_2381377266(&b0.r, ((NimStringDesc*) &T839829468_117)); putintodest_550468_839829468(p0, d0, (*e0).typ, b0.r, ((Tstorageloc292812) 0)); } goto LA1; LA5: ; { initlocexpr_539283_839829468(p0, (*e0).kindU.S6.sons->data[((NI) 1)], (&a0)); initlocexpr_539283_839829468(p0, (*e0).kindU.S6.sons->data[((NI) 2)], (&b0)); geninexpraux_553496_839829468(p0, e0, (&a0), (&b0), d0); } LA1: ; } N_NIMCALL(void, gensetop_556419_839829468)(Tcproc529021* p0, Tnode292802* e0, Tloc292816* d0, Tmagic292524 op0) { Tloc292816 a0; Tloc292816 b0; Tloc292816 i0; Ttype292840* 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_296099_850551059((*(*e0).kindU.S6.sons->data[((NI) 1)]).typ, IL64(211106240964864)); LOC1 = (NI64)0; LOC1 = getsize_320135_3876443242(settype0); size0 = ((NI) (LOC1)); switch (size0) { case ((NI) 1): case ((NI) 2): case ((NI) 4): case ((NI) 8): { switch (op0) { case ((Tmagic292524) 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_555857_839829468(p0, e0, d0, LOC6); } break; case ((Tmagic292524) 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_555857_839829468(p0, e0, d0, LOC10); } break; case ((Tmagic292524) 41): { { if (!(size0 <= ((NI) 4))) goto LA14; unaryexprchar_551222_839829468(p0, e0, d0, ((NimStringDesc*) &T839829468_455)); } goto LA12; LA14: ; { unaryexprchar_551222_839829468(p0, e0, d0, ((NimStringDesc*) &T839829468_456)); } LA12: ; } break; case ((Tmagic292524) 133): { binaryexprchar_550809_839829468(p0, e0, d0, ((NimStringDesc*) &T839829468_457)); } break; case ((Tmagic292524) 132): { binaryexprchar_550809_839829468(p0, e0, d0, ((NimStringDesc*) &T839829468_458)); } break; case ((Tmagic292524) 131): { binaryexpr_550549_839829468(p0, e0, d0, ((NimStringDesc*) &T839829468_341)); } break; case ((Tmagic292524) 134): { binaryexpr_550549_839829468(p0, e0, d0, ((NimStringDesc*) &T839829468_459)); } break; case ((Tmagic292524) 135): { binaryexpr_550549_839829468(p0, e0, d0, ((NimStringDesc*) &T839829468_460)); } break; case ((Tmagic292524) 136): { binaryexpr_550549_839829468(p0, e0, d0, ((NimStringDesc*) &T839829468_461)); } break; case ((Tmagic292524) 137): { binaryexpr_550549_839829468(p0, e0, d0, ((NimStringDesc*) &T839829468_462)); } break; case ((Tmagic292524) 148): { geninop_556009_839829468(p0, e0, d0); } break; default: { internalerror_196100_155036129((*e0).info, ((NimStringDesc*) &T839829468_472)); } break; } } break; default: { switch (op0) { case ((Tmagic292524) 39): { binarystmtinexcl_555857_839829468(p0, e0, d0, ((NimStringDesc*) &T839829468_473)); } break; case ((Tmagic292524) 40): { binarystmtinexcl_555857_839829468(p0, e0, d0, ((NimStringDesc*) &T839829468_474)); } break; case ((Tmagic292524) 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_551222_839829468(p0, e0, d0, LOC30); } break; case ((Tmagic292524) 133): case ((Tmagic292524) 132): { Ttype292840* LOC33; TY536475 LOC39; LOC33 = (Ttype292840*)0; LOC33 = getsystype_338150_3937434831(((Ttypekind292244) 31)); gettemp_537032_839829468(p0, LOC33, (&i0), NIM_FALSE); initlocexpr_539283_839829468(p0, (*e0).kindU.S6.sons->data[((NI) 1)], (&a0)); initlocexpr_539283_839829468(p0, (*e0).kindU.S6.sons->data[((NI) 2)], (&b0)); { Ttype292840* LOC38; if (!((*d0).k == ((Tlockind292808) 0))) goto LA36; LOC38 = (Ttype292840*)0; LOC38 = getsystype_338150_3937434831(((Ttypekind292244) 1)); gettemp_537032_839829468(p0, LOC38, d0, NIM_FALSE); } LA36: ; memset((void*)LOC39, 0, sizeof(LOC39)); LOC39[0] = rdloc_538188_839829468(i0); LOC39[1] = rope_178401_2381377266(((NI64) (size0))); LOC39[2] = rdloc_538188_839829468((*d0)); LOC39[3] = rdloc_538188_839829468(a0); LOC39[4] = rdloc_538188_839829468(b0); linef_532700_839829468(p0, ((Tcprocsection529011) 2), lookupopr_556426_839829468[(op0)- 132], LOC39, 5); } break; case ((Tmagic292524) 131): { NimStringDesc* LOC41; NimStringDesc* LOC42; usestringh_532345_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_550809_839829468(p0, e0, d0, LOC41); } break; case ((Tmagic292524) 134): case ((Tmagic292524) 135): case ((Tmagic292524) 136): case ((Tmagic292524) 137): { Ttype292840* LOC44; TY536847 LOC49; LOC44 = (Ttype292840*)0; LOC44 = getsystype_338150_3937434831(((Ttypekind292244) 31)); gettemp_537032_839829468(p0, LOC44, (&i0), NIM_FALSE); initlocexpr_539283_839829468(p0, (*e0).kindU.S6.sons->data[((NI) 1)], (&a0)); initlocexpr_539283_839829468(p0, (*e0).kindU.S6.sons->data[((NI) 2)], (&b0)); { if (!((*d0).k == ((Tlockind292808) 0))) goto LA47; gettemp_537032_839829468(p0, a0.t, d0, NIM_FALSE); } LA47: ; memset((void*)LOC49, 0, sizeof(LOC49)); LOC49[0] = rdloc_538188_839829468(i0); LOC49[1] = rope_178401_2381377266(((NI64) (size0))); LOC49[2] = rdloc_538188_839829468((*d0)); LOC49[3] = rdloc_538188_839829468(a0); LOC49[4] = rdloc_538188_839829468(b0); LOC49[5] = rope_178277_2381377266(lookupopr_556426_839829468[(op0)- 132]); linef_532700_839829468(p0, ((Tcprocsection529011) 2), ((NimStringDesc*) &T839829468_483), LOC49, 6); } break; case ((Tmagic292524) 148): { geninop_556009_839829468(p0, e0, d0); } break; default: { internalerror_196100_155036129((*e0).info, ((NimStringDesc*) &T839829468_484)); } break; } } break; } } static N_INLINE(Ropeobj178006*, genargstringtocstring_539776_839829468)(Tcproc529021* p0, Tnode292802* n0) { Ropeobj178006* result0; Tloc292816 a0; TY178507 LOC1; result0 = (Ropeobj178006*)0; memset((void*)(&a0), 0, sizeof(a0)); initlocexpr_539283_839829468(p0, (*n0).kindU.S6.sons->data[((NI) 0)], (&a0)); memset((void*)LOC1, 0, sizeof(LOC1)); LOC1[0] = rdloc_538188_839829468(a0); result0 = HEX25_178905_2381377266(((NimStringDesc*) &T839829468_485), LOC1, 1); return result0; } N_NIMCALL(Ropeobj178006*, openarrayloc_539665_839829468)(Tcproc529021* p0, Tnode292802* n0) { Ropeobj178006* result0; Tloc292816 a0; Tnode292802* q0; result0 = (Ropeobj178006*)0; memset((void*)(&a0), 0, sizeof(a0)); q0 = skipconv_328882_3876443242(n0); { Tmagic292524 LOC3; Tloc292816 b0; Tloc292816 c0; Tnode292802* LOC6; Tnode292802* LOC7; Tnode292802* LOC8; NimStringDesc* fmt0; Ttype292840* LOC9; TY535238 LOC25; LOC3 = (Tmagic292524)0; LOC3 = getmagic_318502_2616423590(q0); if (!(LOC3 == ((Tmagic292524) 139))) goto LA4; memset((void*)(&b0), 0, sizeof(b0)); memset((void*)(&c0), 0, sizeof(c0)); LOC6 = (Tnode292802*)0; LOC6 = HEX5BHEX5D_293238_850551059(q0, ((NI) 1)); initlocexpr_539283_839829468(p0, LOC6, (&a0)); LOC7 = (Tnode292802*)0; LOC7 = HEX5BHEX5D_293238_850551059(q0, ((NI) 2)); initlocexpr_539283_839829468(p0, LOC7, (&b0)); LOC8 = (Tnode292802*)0; LOC8 = HEX5BHEX5D_293238_850551059(q0, ((NI) 3)); initlocexpr_539283_839829468(p0, LOC8, (&c0)); LOC9 = (Ttype292840*)0; LOC9 = skiptypes_296099_850551059(a0.t, IL64(211106243062016)); switch ((*LOC9).kind) { case ((Ttypekind292244) 27): case ((Ttypekind292244) 48): case ((Ttypekind292244) 16): case ((Ttypekind292244) 4): { fmt0 = copyString(((NimStringDesc*) &T839829468_486)); } break; case ((Ttypekind292244) 28): case ((Ttypekind292244) 24): { { NIM_BOOL LOC14; Ttype292840* LOC15; NIM_BOOL LOC17; LOC14 = (NIM_BOOL)0; LOC15 = (Ttype292840*)0; LOC15 = skiptypes_296099_850551059((*n0).typ, IL64(211106232576256)); LOC14 = ((*LOC15).kind == ((Ttypekind292244) 23)); if (!(LOC14)) goto LA16; LOC17 = (NIM_BOOL)0; LOC17 = (gcmd_169132_2607990831 == ((Tcommands169076) 2)); if (LOC17) goto LA18; LOC17 = (((*(*(*p0).module).module).flags &(1U<<((NU)(((Tsymflag292184) 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_320017_3876443242(a0.t, ((Tprefereddesc320011) 0)); LOC23 = rawNewString(LOC24->Sup.len + 14); appendString(LOC23, ((NimStringDesc*) &T839829468_489)); appendString(LOC23, LOC24); internalerror_196113_155036129(LOC23); fmt0 = copyString(((NimStringDesc*) &T839829468_490)); } break; } memset((void*)LOC25, 0, sizeof(LOC25)); LOC25[0] = rdloc_538188_839829468(a0); LOC25[1] = rdloc_538188_839829468(b0); LOC25[2] = rdloc_538188_839829468(c0); result0 = HEX25_178905_2381377266(fmt0, LOC25, 3); } goto LA1; LA4: ; { Ttype292840* LOC27; initlocexpr_539283_839829468(p0, n0, (&a0)); LOC27 = (Ttype292840*)0; LOC27 = skiptypes_296099_850551059(a0.t, IL64(211106240964864)); switch ((*LOC27).kind) { case ((Ttypekind292244) 27): case ((Ttypekind292244) 48): { TY178507 LOC29; memset((void*)LOC29, 0, sizeof(LOC29)); LOC29[0] = rdloc_538188_839829468(a0); result0 = HEX25_178905_2381377266(((NimStringDesc*) &T839829468_378), LOC29, 1); } break; case ((Ttypekind292244) 28): case ((Ttypekind292244) 24): { { NIM_BOOL LOC33; Ttype292840* LOC34; NIM_BOOL LOC36; TY532811 LOC40; LOC33 = (NIM_BOOL)0; LOC34 = (Ttype292840*)0; LOC34 = skiptypes_296099_850551059((*n0).typ, IL64(211106232576256)); LOC33 = ((*LOC34).kind == ((Ttypekind292244) 23)); if (!(LOC33)) goto LA35; LOC36 = (NIM_BOOL)0; LOC36 = (gcmd_169132_2607990831 == ((Tcommands169076) 2)); if (LOC36) goto LA37; LOC36 = (((*(*(*p0).module).module).flags &(1U<<((NU)(((Tsymflag292184) 27))&31U)))!=0); LA37: ; LOC33 = !(LOC36); LA35: ; if (!LOC33) goto LA38; memset((void*)LOC40, 0, sizeof(LOC40)); LOC40[0] = rdloc_538188_839829468(a0); LOC40[1] = lenfield_539305_839829468(p0); result0 = HEX25_178905_2381377266(((NimStringDesc*) &T839829468_491), LOC40, 2); } goto LA31; LA38: ; { TY532811 LOC42; memset((void*)LOC42, 0, sizeof(LOC42)); LOC42[0] = rdloc_538188_839829468(a0); LOC42[1] = lenfield_539305_839829468(p0); result0 = HEX25_178905_2381377266(((NimStringDesc*) &T839829468_379), LOC42, 2); } LA31: ; } break; case ((Ttypekind292244) 16): case ((Ttypekind292244) 4): { TY532811 LOC44; NI64 LOC45; memset((void*)LOC44, 0, sizeof(LOC44)); LOC44[0] = rdloc_538188_839829468(a0); LOC45 = (NI64)0; LOC45 = lengthord_320007_3876443242(a0.t); LOC44[1] = rope_178401_2381377266(LOC45); result0 = HEX25_178905_2381377266(((NimStringDesc*) &T839829468_380), LOC44, 2); } break; case ((Ttypekind292244) 21): case ((Ttypekind292244) 22): { Ttype292840* LOC47; LOC47 = (Ttype292840*)0; LOC47 = lastson_295377_850551059(a0.t); switch ((*LOC47).kind) { case ((Ttypekind292244) 28): case ((Ttypekind292244) 24): { TY532811 LOC49; memset((void*)LOC49, 0, sizeof(LOC49)); LOC49[0] = rdloc_538188_839829468(a0); LOC49[1] = lenfield_539305_839829468(p0); result0 = HEX25_178905_2381377266(((NimStringDesc*) &T839829468_491), LOC49, 2); } break; case ((Ttypekind292244) 16): case ((Ttypekind292244) 4): { TY532811 LOC51; Ttype292840* LOC52; NI64 LOC53; memset((void*)LOC51, 0, sizeof(LOC51)); LOC51[0] = rdloc_538188_839829468(a0); LOC52 = (Ttype292840*)0; LOC52 = lastson_295377_850551059(a0.t); LOC53 = (NI64)0; LOC53 = lengthord_320007_3876443242(LOC52); LOC51[1] = rope_178401_2381377266(LOC53); result0 = HEX25_178905_2381377266(((NimStringDesc*) &T839829468_380), LOC51, 2); } break; default: { NimStringDesc* LOC55; NimStringDesc* LOC56; LOC55 = (NimStringDesc*)0; LOC56 = (NimStringDesc*)0; LOC56 = typetostring_320017_3876443242(a0.t, ((Tprefereddesc320011) 0)); LOC55 = rawNewString(LOC56->Sup.len + 14); appendString(LOC55, ((NimStringDesc*) &T839829468_489)); appendString(LOC55, LOC56); internalerror_196113_155036129(LOC55); } break; } } break; default: { NimStringDesc* LOC58; NimStringDesc* LOC59; LOC58 = (NimStringDesc*)0; LOC59 = (NimStringDesc*)0; LOC59 = typetostring_320017_3876443242(a0.t, ((Tprefereddesc320011) 0)); LOC58 = rawNewString(LOC59->Sup.len + 14); appendString(LOC58, ((NimStringDesc*) &T839829468_489)); appendString(LOC58, LOC59); internalerror_196113_155036129(LOC58); } break; } } LA1: ; return result0; } N_NIMCALL(Ropeobj178006*, genarg_539787_839829468)(Tcproc529021* p0, Tnode292802* n_539790_839829468, Tsym292834* param0, Tnode292802* call0) { Ropeobj178006* result0; Tloc292816 a0; result0 = (Ropeobj178006*)0; memset((void*)(&a0), 0, sizeof(a0)); { if (!((*n_539790_839829468).kind == ((Tnodekind292020) 71))) goto LA3; result0 = genargstringtocstring_539776_839829468(p0, n_539790_839829468); } goto LA1; LA3: ; { Ttype292840* LOC6; Tnode292802* n0; LOC6 = (Ttype292840*)0; LOC6 = skiptypes_296099_850551059((*param0).typ, IL64(211106240964864)); if (!((*LOC6).kind == ((Ttypekind292244) 27) || (*LOC6).kind == ((Ttypekind292244) 48))) goto LA7; { if (!!(((*n_539790_839829468).kind == ((Tnodekind292020) 64)))) goto LA11; n0 = n_539790_839829468; } goto LA9; LA11: ; { n0 = (*n_539790_839829468).kindU.S6.sons->data[((NI) 0)]; } LA9: ; result0 = openarrayloc_539665_839829468(p0, n0); } goto LA1; LA7: ; { NIM_BOOL LOC15; LOC15 = (NIM_BOOL)0; LOC15 = ccgintroducedptr_533609_839829468(param0); if (!LOC15) goto LA16; initlocexpr_539283_839829468(p0, n_539790_839829468, (&a0)); result0 = addrloc_538204_839829468(a0); } goto LA1; LA16: ; { NIM_BOOL LOC19; NIM_BOOL LOC20; NIM_BOOL LOC21; Tnode292802* callee0; LOC19 = (NIM_BOOL)0; LOC20 = (NIM_BOOL)0; LOC21 = (NIM_BOOL)0; LOC21 = (gcmd_169132_2607990831 == ((Tcommands169076) 2)); if (LOC21) goto LA22; LOC21 = (((*(*(*p0).module).module).flags &(1U<<((NU)(((Tsymflag292184) 27))&31U)))!=0); LA22: ; LOC20 = LOC21; if (!(LOC20)) goto LA23; LOC20 = ((*(*param0).typ).kind == ((Ttypekind292244) 23)); LA23: ; LOC19 = LOC20; if (!(LOC19)) goto LA24; LOC19 = ((*n_539790_839829468).kind == ((Tnodekind292020) 64)); LA24: ; if (!LOC19) goto LA25; initlocexprsingleuse_539289_839829468(p0, (*n_539790_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 == ((Tnodekind292020) 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_538204_839829468(a0); } goto LA27; LA33: ; { result0 = rdloc_538188_839829468(a0); } LA27: ; } goto LA1; LA25: ; { initlocexprsingleuse_539289_839829468(p0, n_539790_839829468, (&a0)); result0 = rdloc_538188_839829468(a0); } LA1: ; return result0; } N_NIMCALL(Ropeobj178006*, genargnoparam_539938_839829468)(Tcproc529021* p0, Tnode292802* n0) { Ropeobj178006* result0; Tloc292816 a0; result0 = (Ropeobj178006*)0; memset((void*)(&a0), 0, sizeof(a0)); { if (!((*n0).kind == ((Tnodekind292020) 71))) goto LA3; result0 = genargstringtocstring_539776_839829468(p0, n0); } goto LA1; LA3: ; { initlocexprsingleuse_539289_839829468(p0, n0, (&a0)); result0 = rdloc_538188_839829468(a0); } LA1: ; return result0; } N_NIMCALL(Ropeobj178006*, getrawproctype_540459_839829468)(Tcproc529021* p0, Ttype292840* t0) { Ropeobj178006* result0; result0 = (Ropeobj178006*)0; result0 = getclosuretype_535683_839829468((*p0).module, t0, ((Tclosuretypekind535679) 0)); return result0; } N_NIMCALL(NIM_BOOL, leftappearsonrightside_539329_839829468)(Tnode292802* le0, Tnode292802* ri0) { NIM_BOOL result0; { result0 = (NIM_BOOL)0; { if (!!((le0 == NIM_NIL))) goto LA3; { NI i_539364_839829468; NI HEX3Atmp_539376_839829468; NI LOC6; NI res_539379_839829468; i_539364_839829468 = (NI)0; HEX3Atmp_539376_839829468 = (NI)0; LOC6 = (NI)0; LOC6 = len_293081_850551059(ri0); HEX3Atmp_539376_839829468 = (LOC6 - 1); res_539379_839829468 = ((NI) 1); { while (1) { Tnode292802* r0; if (!(res_539379_839829468 <= HEX3Atmp_539376_839829468)) goto LA8; i_539364_839829468 = res_539379_839829468; r0 = HEX5BHEX5D_293238_850551059(ri0, i_539364_839829468); { Tanalysisresult473003 LOC11; LOC11 = (Tanalysisresult473003)0; LOC11 = ispartof_473340_788060399(le0, r0); if (!!((LOC11 == ((Tanalysisresult473003) 0)))) goto LA12; result0 = NIM_TRUE; goto BeforeRet; } LA12: ; res_539379_839829468 += ((NI) 1); } LA8: ; } } } LA3: ; }BeforeRet: ; return result0; } static N_INLINE(NIM_BOOL, hasnoinit_539383_839829468)(Tnode292802* call0) { NIM_BOOL result0; NIM_BOOL LOC1; result0 = (NIM_BOOL)0; LOC1 = (NIM_BOOL)0; LOC1 = ((*(*call0).kindU.S6.sons->data[((NI) 0)]).kind == ((Tnodekind292020) 3)); if (!(LOC1)) goto LA2; LOC1 = (((*(*(*call0).kindU.S6.sons->data[((NI) 0)]).kindU.S4.sym).flags &(1U<<((NU)(((Tsymflag292184) 12))&31U)))!=0); LA2: ; result0 = LOC1; return result0; } N_NIMCALL(void, resetloc_538350_839829468)(Tcproc529021* p0, Tloc292816* loc0) { NIM_BOOL containsgcref0; Ttype292840* typ0; { containsgcref0 = containsgarbagecollectedref_320117_3876443242((*loc0).t); typ0 = skiptypes_296099_850551059((*loc0).t, IL64(211106242013440)); { NIM_BOOL LOC3; LOC3 = (NIM_BOOL)0; LOC3 = isimportedcpptype_533476_839829468(typ0); if (!LOC3) goto LA4; goto BeforeRet; } LA4: ; { NIM_BOOL LOC8; LOC8 = (NIM_BOOL)0; LOC8 = iscomplexvaluetype_538317_839829468(typ0); if (!!(LOC8)) goto LA9; { Tloc292816 nilloc0; if (!containsgcref0) goto LA13; memset((void*)(&nilloc0), 0, sizeof(nilloc0)); initloc_532273_839829468((&nilloc0), ((Tlockind292808) 1), (*loc0).t, ((Tstorageloc292812) 2)); nilloc0.r = rope_178277_2381377266(((NimStringDesc*) &T839829468_174)); genrefassign_538311_839829468(p0, (*loc0), nilloc0, 8); } goto LA11; LA13: ; { TY178507 LOC16; memset((void*)LOC16, 0, sizeof(LOC16)); LOC16[0] = rdloc_538188_839829468((*loc0)); linefmt_532714_839829468(p0, ((Tcprocsection529011) 2), ((NimStringDesc*) &T839829468_494), LOC16, 1); } LA11: ; } goto LA6; LA9: ; { { TY178507 LOC22; if (!(((*p0).options &(1U<<((NU)(((Toption169009) 6))&31U)))!=0)) goto LA20; memset((void*)LOC22, 0, sizeof(LOC22)); LOC22[0] = addrloc_538204_839829468((*loc0)); linefmt_532714_839829468(p0, ((Tcprocsection529011) 2), ((NimStringDesc*) &T839829468_495), LOC22, 1); } LA20: ; { TY532811 LOC27; if (!!(((*loc0).s == ((Tstorageloc292812) 2)))) goto LA25; memset((void*)LOC27, 0, sizeof(LOC27)); LOC27[0] = addrloc_538204_839829468((*loc0)); LOC27[1] = gentypeinfo_535941_839829468((*p0).module, (*loc0).t); linefmt_532714_839829468(p0, ((Tcprocsection529011) 2), ((NimStringDesc*) &T839829468_496), LOC27, 2); genobjectinit_538242_839829468(p0, ((Tcprocsection529011) 2), (*loc0).t, (*loc0), NIM_TRUE); } goto LA23; LA25: ; { TY532811 LOC29; usestringh_532345_839829468((*p0).module); memset((void*)LOC29, 0, sizeof(LOC29)); LOC29[0] = addrloc_538204_839829468((*loc0)); LOC29[1] = rdloc_538188_839829468((*loc0)); linefmt_532714_839829468(p0, ((Tcprocsection529011) 2), ((NimStringDesc*) &T839829468_152), LOC29, 2); genobjectinit_538242_839829468(p0, ((Tcprocsection529011) 2), (*loc0).t, (*loc0), NIM_TRUE); } LA23: ; } LA6: ; }BeforeRet: ; } N_NIMCALL(Ropeobj178006*, addcomma_540464_839829468)(Ropeobj178006* r0) { Ropeobj178006* result0; result0 = (Ropeobj178006*)0; { if (!(r0 == NIM_NIL)) goto LA3; result0 = r0; } goto LA1; LA3: ; { TY533289 LOC6; Ropeobj178006* LOC7; memset((void*)LOC6, 0, sizeof(LOC6)); LOC7 = (Ropeobj178006*)0; LOC7 = HEX25_178905_2381377266(((NimStringDesc*) &T839829468_110), LOC6, 0); result0 = HEX26_178418_2381377266(r0, LOC7); } LA1: ; return result0; } N_NIMCALL(void, genclosurecall_540452_839829468)(Tcproc529021* p0, Tnode292802* le0, Tnode292802* ri0, Tloc292816* d0) { Tloc292816 op0; Ropeobj178006* pl0; Ttype292840* typ0; NI length0; Ropeobj178006* rawproc0; NimStringDesc* callpattern0; memset((void*)(&op0), 0, sizeof(op0)); initlocexpr_539283_839829468(p0, (*ri0).kindU.S6.sons->data[((NI) 0)], (&op0)); pl0 = (Ropeobj178006*)0; typ0 = skiptypes_296099_850551059((*(*ri0).kindU.S6.sons->data[((NI) 0)]).typ, IL64(211106232576256)); length0 = sonslen_295351_850551059(ri0); { NI i_540613_839829468; NI HEX3Atmp_541214_839829468; NI res_541217_839829468; i_540613_839829468 = (NI)0; HEX3Atmp_541214_839829468 = (NI)0; HEX3Atmp_541214_839829468 = (NI)(length0 - ((NI) 1)); res_541217_839829468 = ((NI) 1); { while (1) { if (!(res_541217_839829468 <= HEX3Atmp_541214_839829468)) goto LA3; i_540613_839829468 = res_541217_839829468; { NI LOC6; Tnode292802* paramtype0; LOC6 = (NI)0; LOC6 = sonslen_295327_850551059(typ0); if (!(i_540613_839829468 < LOC6)) goto LA7; paramtype0 = (*(*typ0).n).kindU.S6.sons->data[i_540613_839829468]; { NIM_BOOL LOC11; Ropeobj178006* LOC20; LOC11 = (NIM_BOOL)0; LOC11 = iscompiletimeonly_328706_3876443242((*paramtype0).typ); if (!!(LOC11)) goto LA12; { TY533289 LOC18; Ropeobj178006* LOC19; if (!!((pl0 == NIM_NIL))) goto LA16; memset((void*)LOC18, 0, sizeof(LOC18)); LOC19 = (Ropeobj178006*)0; LOC19 = HEX25_178905_2381377266(((NimStringDesc*) &T839829468_110), LOC18, 0); add_178482_2381377266(&pl0, LOC19); } LA16: ; LOC20 = (Ropeobj178006*)0; LOC20 = genarg_539787_839829468(p0, (*ri0).kindU.S6.sons->data[i_540613_839829468], (*paramtype0).kindU.S4.sym, ri0); add_178482_2381377266(&pl0, LOC20); } LA12: ; } goto LA4; LA7: ; { Ropeobj178006* LOC28; { TY533289 LOC26; Ropeobj178006* LOC27; if (!!((pl0 == NIM_NIL))) goto LA24; memset((void*)LOC26, 0, sizeof(LOC26)); LOC27 = (Ropeobj178006*)0; LOC27 = HEX25_178905_2381377266(((NimStringDesc*) &T839829468_110), LOC26, 0); add_178482_2381377266(&pl0, LOC27); } LA24: ; LOC28 = (Ropeobj178006*)0; LOC28 = genargnoparam_539938_839829468(p0, (*ri0).kindU.S6.sons->data[i_540613_839829468]); add_178482_2381377266(&pl0, LOC28); } LA4: ; res_541217_839829468 += ((NI) 1); } LA3: ; } } rawproc0 = getrawproctype_540459_839829468(p0, typ0); { if (!(((*typ0).flags &(1U<<((NU)(((Ttypeflag292431) 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_533548_839829468((*typ0).sons->data[((NI) 0)]); if (!LOC40) goto LA41; { NI LOC45; TY533289 LOC48; Ropeobj178006* LOC49; LOC45 = (NI)0; LOC45 = sonslen_295351_850551059(ri0); if (!(((NI) 1) < LOC45)) goto LA46; memset((void*)LOC48, 0, sizeof(LOC48)); LOC49 = (Ropeobj178006*)0; LOC49 = HEX25_178905_2381377266(((NimStringDesc*) &T839829468_110), LOC48, 0); add_178482_2381377266(&pl0, LOC49); } LA46: ; { NIM_BOOL LOC52; NIM_BOOL LOC54; Ropeobj178006* LOC67; NimStringDesc* LOC68; TY535235 LOC69; LOC52 = (NIM_BOOL)0; LOC52 = ((3 &(1U<<((NU)((*d0).k)&15U)))!=0); if (LOC52) goto LA53; LOC54 = (NIM_BOOL)0; LOC54 = leftappearsonrightside_539329_839829468(le0, ri0); LOC52 = !(LOC54); LA53: ; if (!LOC52) goto LA55; { if (!((*d0).k == ((Tlockind292808) 0))) goto LA59; gettemp_537032_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_539383_839829468(ri0); LOC62 = !(LOC64); LA63: ; if (!LOC62) goto LA65; resetloc_538350_839829468(p0, d0); } goto LA57; LA65: ; LA57: ; LOC67 = (Ropeobj178006*)0; LOC67 = addrloc_538204_839829468((*d0)); add_178482_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_540464_839829468(pl0); LOC69[3] = rawproc0; linef_532700_839829468(p0, ((Tcprocsection529011) 2), LOC68, LOC69, 4); } goto LA50; LA55: ; { Tloc292816 tmp0; Ropeobj178006* LOC71; NimStringDesc* LOC72; TY535235 LOC73; memset((void*)(&tmp0), 0, sizeof(tmp0)); gettemp_537032_839829468(p0, (*typ0).sons->data[((NI) 0)], (&tmp0), NIM_TRUE); LOC71 = (Ropeobj178006*)0; LOC71 = addrloc_538204_839829468(tmp0); add_178482_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_540464_839829468(pl0); LOC73[3] = rawproc0; linef_532700_839829468(p0, ((Tcprocsection529011) 2), LOC72, LOC73, 4); genassignment_539264_839829468(p0, (*d0), tmp0, 0); } LA50: ; } goto LA38; LA41: ; { Tloc292816 list0; TY535235 LOC79; { if (!((*d0).k == ((Tlockind292808) 0))) goto LA77; gettemp_537032_839829468(p0, (*typ0).sons->data[((NI) 0)], d0, NIM_FALSE); } LA77: ; memset((void*)(&list0), 0, sizeof(list0)); initloc_532273_839829468((&list0), ((Tlockind292808) 9), (*d0).t, ((Tstorageloc292812) 0)); memset((void*)LOC79, 0, sizeof(LOC79)); LOC79[0] = op0.r; LOC79[1] = pl0; LOC79[2] = addcomma_540464_839829468(pl0); LOC79[3] = rawproc0; list0.r = HEX25_178905_2381377266(callpattern0, LOC79, 4); genassignment_539264_839829468(p0, (*d0), list0, 0); } LA38: ; } goto LA34; LA36: ; { NimStringDesc* LOC81; TY535235 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_540464_839829468(pl0); LOC82[3] = rawproc0; linef_532700_839829468(p0, ((Tcprocsection529011) 2), LOC81, LOC82, 4); } LA34: ; } N_NIMCALL(Ropeobj178006*, genotherarg_539277_839829468)(Tcproc529021* p0, Tnode292802* ri0, NI i0, Ttype292840* typ0) { Ropeobj178006* result0; result0 = (Ropeobj178006*)0; { NI LOC3; Tnode292802* paramtype0; LOC3 = (NI)0; LOC3 = sonslen_295327_850551059(typ0); if (!(i0 < LOC3)) goto LA4; paramtype0 = (*(*typ0).n).kindU.S6.sons->data[i0]; { NIM_BOOL LOC8; LOC8 = (NIM_BOOL)0; LOC8 = iscompiletimeonly_328706_3876443242((*paramtype0).typ); if (!LOC8) goto LA9; result0 = NIM_NIL; } goto LA6; LA9: ; { NIM_BOOL LOC12; Tnode292802* LOC16; LOC12 = (NIM_BOOL)0; LOC12 = ((*(*typ0).sons->data[i0]).kind == ((Ttypekind292244) 23)); if (!(LOC12)) goto LA13; LOC12 = ((*(*ri0).kindU.S6.sons->data[i0]).kind == ((Tnodekind292020) 64)); LA13: ; if (!LOC12) goto LA14; LOC16 = (Tnode292802*)0; LOC16 = HEX5BHEX5D_293238_850551059((*ri0).kindU.S6.sons->data[i0], ((NI) 0)); result0 = genargnoparam_539938_839829468(p0, LOC16); } goto LA6; LA14: ; { result0 = genargnoparam_539938_839829468(p0, (*ri0).kindU.S6.sons->data[i0]); } LA6: ; } goto LA1; LA4: ; { { if (!!((((*typ0).flags &(1U<<((NU)(((Ttypeflag292431) 0))&31U)))!=0))) goto LA21; localerror_196085_155036129((*ri0).info, ((NimStringDesc*) &T839829468_501)); result0 = NIM_NIL; } goto LA19; LA21: ; { result0 = genargnoparam_539938_839829468(p0, (*ri0).kindU.S6.sons->data[i0]); } LA19: ; } LA1: ; return result0; } N_NIMCALL(Tnode292802*, skipaddrderef_541433_839829468)(Tnode292802* node0) { Tnode292802* result0; Tnode292802* n0; NIM_BOOL isaddr0; { result0 = (Tnode292802*)0; n0 = node0; isaddr0 = NIM_FALSE; switch ((*n0).kind) { case ((Tnodekind292020) 63): case ((Tnodekind292020) 64): { n0 = (*n0).kindU.S6.sons->data[((NI) 0)]; isaddr0 = NIM_TRUE; } break; case ((Tnodekind292020) 47): case ((Tnodekind292020) 65): { n0 = (*n0).kindU.S6.sons->data[((NI) 0)]; } break; default: { result0 = n0; goto BeforeRet; } break; } { if (!((*n0).kind == ((Tnodekind292020) 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 == ((Tnodekind292020) 47) || (*n0).kind == ((Tnodekind292020) 65)); LA11: ; if (!LOC10) goto LA12; result0 = (*n0).kindU.S6.sons->data[((NI) 0)]; } goto LA8; LA12: ; { if (!((*n0).kind == ((Tnodekind292020) 63) || (*n0).kind == ((Tnodekind292020) 64))) goto LA15; result0 = (*n0).kindU.S6.sons->data[((NI) 0)]; } goto LA8; LA15: ; { result0 = node0; } LA8: ; }BeforeRet: ; return result0; } N_NIMCALL(Ropeobj178006*, genthisarg_541475_839829468)(Tcproc529021* p0, Tnode292802* ri_541478_839829468, NI i0, Ttype292840* typ0) { Ropeobj178006* result0; Tnode292802* ri0; Ttype292840* t0; result0 = (Ropeobj178006*)0; { NI LOC3; NimStringDesc* LOC6; LOC3 = (NI)0; LOC3 = sonslen_295327_850551059(typ0); if (!!((i0 < LOC3))) goto LA4; LOC6 = (NimStringDesc*)0; LOC6 = HEX24_196185_1689653243(T839829468_503); internalerror_196113_155036129(LOC6); } LA4: ; ri0 = HEX5BHEX5D_293238_850551059(ri_541478_839829468, i0); { while (1) { if (!((*ri0).kind == ((Tnodekind292020) 66))) goto LA8; ri0 = HEX5BHEX5D_293238_850551059(ri0, ((NI) 0)); } LA8: ; } t0 = skiptypes_296099_850551059((*typ0).sons->data[i0], 2048); { Tnode292802* x0; if (!((*t0).kind == ((Ttypekind292244) 23))) goto LA11; { if (!((*ri0).kind == ((Tnodekind292020) 64))) goto LA15; x0 = HEX5BHEX5D_293238_850551059(ri0, ((NI) 0)); } goto LA13; LA15: ; { x0 = ri0; } LA13: ; { if (!((*(*x0).typ).kind == ((Ttypekind292244) 21))) goto LA20; result0 = genargnoparam_539938_839829468(p0, x0); add_178487_2381377266(&result0, ((NimStringDesc*) &T839829468_504)); } goto LA18; LA20: ; { NIM_BOOL LOC23; Tnode292802* LOC25; Tnode292802* LOC28; LOC23 = (NIM_BOOL)0; LOC23 = ((*x0).kind == ((Tnodekind292020) 65) || (*x0).kind == ((Tnodekind292020) 47)); if (!(LOC23)) goto LA24; LOC25 = (Tnode292802*)0; LOC25 = HEX5BHEX5D_293238_850551059(x0, ((NI) 0)); LOC23 = ((*(*LOC25).typ).kind == ((Ttypekind292244) 21)); LA24: ; if (!LOC23) goto LA26; LOC28 = (Tnode292802*)0; LOC28 = HEX5BHEX5D_293238_850551059(x0, ((NI) 0)); result0 = genargnoparam_539938_839829468(p0, LOC28); add_178487_2381377266(&result0, ((NimStringDesc*) &T839829468_504)); } goto LA18; LA26: ; { result0 = genargnoparam_539938_839829468(p0, x0); add_178487_2381377266(&result0, ((NimStringDesc*) &T839829468_257)); } LA18: ; } goto LA9; LA11: ; { if (!((*t0).kind == ((Ttypekind292244) 21))) goto LA31; { Tnode292802* LOC37; if (!((*ri0).kind == ((Tnodekind292020) 63) || (*ri0).kind == ((Tnodekind292020) 64))) goto LA35; LOC37 = (Tnode292802*)0; LOC37 = HEX5BHEX5D_293238_850551059(ri0, ((NI) 0)); result0 = genargnoparam_539938_839829468(p0, LOC37); add_178487_2381377266(&result0, ((NimStringDesc*) &T839829468_257)); } goto LA33; LA35: ; { result0 = genargnoparam_539938_839829468(p0, ri0); add_178487_2381377266(&result0, ((NimStringDesc*) &T839829468_504)); } LA33: ; } goto LA9; LA31: ; { ri0 = skipaddrderef_541433_839829468(ri0); { if (!((*ri0).kind == ((Tnodekind292020) 63) || (*ri0).kind == ((Tnodekind292020) 64))) goto LA42; ri0 = HEX5BHEX5D_293238_850551059(ri0, ((NI) 0)); } LA42: ; result0 = genargnoparam_539938_839829468(p0, ri0); add_178487_2381377266(&result0, ((NimStringDesc*) &T839829468_257)); } LA9: ; return result0; } N_NIMCALL(Ropeobj178006*, genpatterncall_541699_839829468)(Tcproc529021* p0, Tnode292802* ri_541702_839829468, NimStringDesc* pat0, Ttype292840* typ_541704_839829468) { Ropeobj178006* result0; NI i0; NI j0; result0 = (Ropeobj178006*)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; Ropeobj178006* LOC9; LOC6 = (NI)0; LOC6 = len_293081_850551059(ri_541702_839829468); if (!(j0 < LOC6)) goto LA7; LOC9 = (Ropeobj178006*)0; LOC9 = genotherarg_539277_839829468(p0, ri_541702_839829468, j0, typ_541704_839829468); add_178482_2381377266(&result0, LOC9); { NI k_541728_839829468; NI HEX3Atmp_541904_839829468; NI HEX3Atmp_541905_839829468; NI LOC11; NI res_541908_839829468; k_541728_839829468 = (NI)0; HEX3Atmp_541904_839829468 = (NI)0; HEX3Atmp_541905_839829468 = (NI)0; HEX3Atmp_541904_839829468 = (NI)(j0 + ((NI) 1)); LOC11 = (NI)0; LOC11 = len_293081_850551059(ri_541702_839829468); HEX3Atmp_541905_839829468 = (LOC11 - 1); res_541908_839829468 = HEX3Atmp_541904_839829468; { while (1) { TY533289 LOC14; Ropeobj178006* LOC15; Ropeobj178006* LOC16; if (!(res_541908_839829468 <= HEX3Atmp_541905_839829468)) goto LA13; k_541728_839829468 = res_541908_839829468; memset((void*)LOC14, 0, sizeof(LOC14)); LOC15 = (Ropeobj178006*)0; LOC15 = HEX25_178905_2381377266(((NimStringDesc*) &T839829468_110), LOC14, 0); add_178482_2381377266(&result0, LOC15); LOC16 = (Ropeobj178006*)0; LOC16 = genotherarg_539277_839829468(p0, ri_541702_839829468, k_541728_839829468, typ_541704_839829468); add_178482_2381377266(&result0, LOC16); res_541908_839829468 += ((NI) 1); } LA13: ; } } } LA7: ; i0 += ((NI) 1); } break; case 35: { { Tnode292802* ri0; if (!(((NU8)(pat0->data[(NI)(i0 + ((NI) 1))])) == ((NU8)(43)) || ((NU8)(pat0->data[(NI)(i0 + ((NI) 1))])) == ((NU8)(64)))) goto LA20; ri0 = HEX5BHEX5D_293238_850551059(ri_541702_839829468, j0); { Ttype292840* typ0; TY533289 LOC31; Ropeobj178006* LOC32; TY533289 LOC46; Ropeobj178006* LOC47; if (!((*ri0).kind == ((Tnodekind292020) 27) || (*ri0).kind == ((Tnodekind292020) 29) || (*ri0).kind == ((Tnodekind292020) 30) || (*ri0).kind == ((Tnodekind292020) 31) || (*ri0).kind == ((Tnodekind292020) 26) || (*ri0).kind == ((Tnodekind292020) 28) || (*ri0).kind == ((Tnodekind292020) 32))) goto LA24; typ0 = skiptypes_296099_850551059((*(*ri0).kindU.S6.sons->data[((NI) 0)]).typ, IL64(211106232576256)); { Ropeobj178006* LOC30; if (!((NU8)(pat0->data[(NI)(i0 + ((NI) 1))]) == (NU8)(43))) goto LA28; LOC30 = (Ropeobj178006*)0; LOC30 = genargnoparam_539938_839829468(p0, (*ri0).kindU.S6.sons->data[((NI) 0)]); add_178482_2381377266(&result0, LOC30); } LA28: ; memset((void*)LOC31, 0, sizeof(LOC31)); LOC32 = (Ropeobj178006*)0; LOC32 = HEX25_178905_2381377266(((NimStringDesc*) &T839829468_118), LOC31, 0); add_178482_2381377266(&result0, LOC32); { NI LOC35; Ropeobj178006* LOC38; LOC35 = (NI)0; LOC35 = len_293081_850551059(ri0); if (!(((NI) 1) < LOC35)) goto LA36; LOC38 = (Ropeobj178006*)0; LOC38 = genotherarg_539277_839829468(p0, ri0, ((NI) 1), typ0); add_178482_2381377266(&result0, LOC38); } LA36: ; { NI k_541793_839829468; NI HEX3Atmp_541915_839829468; NI HEX3Atmp_541916_839829468; NI LOC40; NI res_541919_839829468; k_541793_839829468 = (NI)0; HEX3Atmp_541915_839829468 = (NI)0; HEX3Atmp_541916_839829468 = (NI)0; HEX3Atmp_541915_839829468 = (NI)(j0 + ((NI) 1)); LOC40 = (NI)0; LOC40 = len_293081_850551059(ri0); HEX3Atmp_541916_839829468 = (LOC40 - 1); res_541919_839829468 = HEX3Atmp_541915_839829468; { while (1) { TY533289 LOC43; Ropeobj178006* LOC44; Ropeobj178006* LOC45; if (!(res_541919_839829468 <= HEX3Atmp_541916_839829468)) goto LA42; k_541793_839829468 = res_541919_839829468; memset((void*)LOC43, 0, sizeof(LOC43)); LOC44 = (Ropeobj178006*)0; LOC44 = HEX25_178905_2381377266(((NimStringDesc*) &T839829468_110), LOC43, 0); add_178482_2381377266(&result0, LOC44); LOC45 = (Ropeobj178006*)0; LOC45 = genotherarg_539277_839829468(p0, ri0, k_541793_839829468, typ0); add_178482_2381377266(&result0, LOC45); res_541919_839829468 += ((NI) 1); } LA42: ; } } memset((void*)LOC46, 0, sizeof(LOC46)); LOC47 = (Ropeobj178006*)0; LOC47 = HEX25_178905_2381377266(((NimStringDesc*) &T839829468_117), LOC46, 0); add_178482_2381377266(&result0, LOC47); } goto LA22; LA24: ; { localerror_196085_155036129((*ri0).info, ((NimStringDesc*) &T839829468_502)); } LA22: ; i0 += ((NI) 1); } goto LA18; LA20: ; { Ropeobj178006* LOC52; if (!((NU8)(pat0->data[(NI)(i0 + ((NI) 1))]) == (NU8)(46))) goto LA50; LOC52 = (Ropeobj178006*)0; LOC52 = genthisarg_541475_839829468(p0, ri_541702_839829468, j0, typ_541704_839829468); add_178482_2381377266(&result0, LOC52); i0 += ((NI) 1); } goto LA18; LA50: ; { Tnode292802* arg0; Ropeobj178006* LOC58; if (!((NU8)(pat0->data[(NI)(i0 + ((NI) 1))]) == (NU8)(91))) goto LA54; arg0 = skipaddrderef_541433_839829468((*ri_541702_839829468).kindU.S6.sons->data[j0]); { while (1) { if (!((*arg0).kind == ((Tnodekind292020) 63) || (*arg0).kind == ((Tnodekind292020) 64) || (*arg0).kind == ((Tnodekind292020) 66))) goto LA57; arg0 = HEX5BHEX5D_293238_850551059(arg0, ((NI) 0)); } LA57: ; } LOC58 = (Ropeobj178006*)0; LOC58 = genargnoparam_539938_839829468(p0, arg0); add_178482_2381377266(&result0, LOC58); } goto LA18; LA54: ; { Ropeobj178006* LOC60; LOC60 = (Ropeobj178006*)0; LOC60 = genotherarg_539277_839829468(p0, ri_541702_839829468, j0, typ_541704_839829468); add_178482_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; Ttype292840* t0; LOC64 = (NIM_BOOL)0; LOC64 = scancppgenericslot_534827_839829468(pat0, (&i0), (&idx0), (&stars0)); if (!LOC64) goto LA65; t0 = resolvestarsincpptype_534891_839829468(typ_541704_839829468, idx0, stars0); { TY533289 LOC71; Ropeobj178006* LOC72; if (!(t0 == NIM_NIL)) goto LA69; memset((void*)LOC71, 0, sizeof(LOC71)); LOC72 = (Ropeobj178006*)0; LOC72 = HEX25_178905_2381377266(((NimStringDesc*) &T839829468_26), LOC71, 0); add_178482_2381377266(&result0, LOC72); } goto LA67; LA69: ; { Ropeobj178006* LOC74; LOC74 = (Ropeobj178006*)0; LOC74 = gettypedesc_535671_839829468((*p0).module, t0); add_178482_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_178487_2381377266(&result0, LOC87); } LA85: ; } break; } } LA2: ; } return result0; } N_NIMCALL(void, fixupcall_539410_839829468)(Tcproc529021* p0, Tnode292802* le0, Tnode292802* ri0, Tloc292816* d0, Ropeobj178006* callee0, Ropeobj178006* params0) { Ropeobj178006* pl0; TY533289 LOC1; Ropeobj178006* LOC2; Ropeobj178006* LOC3; Ttype292840* typ0; memset((void*)LOC1, 0, sizeof(LOC1)); LOC2 = (Ropeobj178006*)0; LOC2 = HEX25_178905_2381377266(((NimStringDesc*) &T839829468_118), LOC1, 0); LOC3 = (Ropeobj178006*)0; LOC3 = HEX26_178418_2381377266(callee0, LOC2); pl0 = HEX26_178418_2381377266(LOC3, params0); typ0 = skiptypes_296099_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_533548_839829468((*typ0).sons->data[((NI) 0)]); if (!LOC10) goto LA11; { TY533289 LOC17; Ropeobj178006* LOC18; if (!!((params0 == NIM_NIL))) goto LA15; memset((void*)LOC17, 0, sizeof(LOC17)); LOC18 = (Ropeobj178006*)0; LOC18 = HEX25_178905_2381377266(((NimStringDesc*) &T839829468_110), LOC17, 0); add_178482_2381377266(&pl0, LOC18); } LA15: ; { NIM_BOOL LOC21; NIM_BOOL LOC23; Ropeobj178006* LOC36; TY533289 LOC37; Ropeobj178006* LOC38; LOC21 = (NIM_BOOL)0; LOC21 = ((3 &(1U<<((NU)((*d0).k)&15U)))!=0); if (LOC21) goto LA22; LOC23 = (NIM_BOOL)0; LOC23 = leftappearsonrightside_539329_839829468(le0, ri0); LOC21 = !(LOC23); LA22: ; if (!LOC21) goto LA24; { if (!((*d0).k == ((Tlockind292808) 0))) goto LA28; gettemp_537032_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_539383_839829468(ri0); LOC31 = !(LOC33); LA32: ; if (!LOC31) goto LA34; resetloc_538350_839829468(p0, d0); } goto LA26; LA34: ; LA26: ; LOC36 = (Ropeobj178006*)0; LOC36 = addrloc_538204_839829468((*d0)); add_178482_2381377266(&pl0, LOC36); memset((void*)LOC37, 0, sizeof(LOC37)); LOC38 = (Ropeobj178006*)0; LOC38 = HEX25_178905_2381377266(((NimStringDesc*) &T839829468_505), LOC37, 0); add_178482_2381377266(&pl0, LOC38); line_532690_839829468(p0, ((Tcprocsection529011) 2), pl0); } goto LA19; LA24: ; { Tloc292816 tmp0; Ropeobj178006* LOC40; TY533289 LOC41; Ropeobj178006* LOC42; memset((void*)(&tmp0), 0, sizeof(tmp0)); gettemp_537032_839829468(p0, (*typ0).sons->data[((NI) 0)], (&tmp0), NIM_TRUE); LOC40 = (Ropeobj178006*)0; LOC40 = addrloc_538204_839829468(tmp0); add_178482_2381377266(&pl0, LOC40); memset((void*)LOC41, 0, sizeof(LOC41)); LOC42 = (Ropeobj178006*)0; LOC42 = HEX25_178905_2381377266(((NimStringDesc*) &T839829468_505), LOC41, 0); add_178482_2381377266(&pl0, LOC42); line_532690_839829468(p0, ((Tcprocsection529011) 2), pl0); genassignment_539264_839829468(p0, (*d0), tmp0, 0); } LA19: ; } goto LA8; LA11: ; { TY533289 LOC44; Ropeobj178006* LOC45; memset((void*)LOC44, 0, sizeof(LOC44)); LOC45 = (Ropeobj178006*)0; LOC45 = HEX25_178905_2381377266(((NimStringDesc*) &T839829468_117), LOC44, 0); add_178482_2381377266(&pl0, LOC45); { NIM_BOOL LOC48; NIM_BOOL LOC49; LOC48 = (NIM_BOOL)0; LOC49 = (NIM_BOOL)0; LOC49 = (gcmd_169132_2607990831 == ((Tcommands169076) 2)); if (LOC49) goto LA50; LOC49 = (((*(*(*p0).module).module).flags &(1U<<((NU)(((Tsymflag292184) 27))&31U)))!=0); LA50: ; LOC48 = LOC49; if (!(LOC48)) goto LA51; LOC48 = (((*d0).flags &(1U<<((NU)(((Tlocflag292810) 8))&15U)))!=0); LA51: ; if (!LOC48) goto LA52; (*d0).k = ((Tlockind292808) 9); unsureAsgnRef((void**) (&(*d0).r), pl0); (*d0).flags &= ~(((NU16)1) << ((((Tlocflag292810) 8)) % (sizeof(NU16)*8))); } goto LA46; LA52: ; { Tloc292816 list0; { if (!((*d0).k == ((Tlockind292808) 0))) goto LA57; gettemp_537032_839829468(p0, (*typ0).sons->data[((NI) 0)], d0, NIM_FALSE); } LA57: ; memset((void*)(&list0), 0, sizeof(list0)); initloc_532273_839829468((&list0), ((Tlockind292808) 9), (*d0).t, ((Tstorageloc292812) 0)); list0.r = pl0; genassignment_539264_839829468(p0, (*d0), list0, 0); } LA46: ; } LA8: ; } goto LA4; LA6: ; { TY533289 LOC60; Ropeobj178006* LOC61; memset((void*)LOC60, 0, sizeof(LOC60)); LOC61 = (Ropeobj178006*)0; LOC61 = HEX25_178905_2381377266(((NimStringDesc*) &T839829468_505), LOC60, 0); add_178482_2381377266(&pl0, LOC61); line_532690_839829468(p0, ((Tcprocsection529011) 2), pl0); } LA4: ; } N_NIMCALL(void, geninfixcall_541929_839829468)(Tcproc529021* p0, Tnode292802* le0, Tnode292802* ri0, Tloc292816* d0) { Tloc292816 op0; Ttype292840* typ_541940_839829468; NI length0; NimStringDesc* pat0; memset((void*)(&op0), 0, sizeof(op0)); initlocexpr_539283_839829468(p0, (*ri0).kindU.S6.sons->data[((NI) 0)], (&op0)); typ_541940_839829468 = skiptypes_296099_850551059((*(*ri0).kindU.S6.sons->data[((NI) 0)]).typ, IL64(211106232576256)); length0 = sonslen_295351_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_196185_1689653243(T839829468_498); internalerror_196113_155036129(LOC5); } LA3: ; { NIM_BOOL LOC8; Ropeobj178006* pl0; Ttype292840* typ0; LOC8 = (NIM_BOOL)0; LOC8 = contains_110056_4286263276(pat0, T839829468_500); if (!LOC8) goto LA9; pl0 = genpatterncall_541699_839829468(p0, ri0, pat0, typ_541940_839829468); typ0 = skiptypes_296099_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_169132_2607990831 == ((Tcommands169076) 2)); if (LOC18) goto LA19; LOC18 = (((*(*(*p0).module).module).flags &(1U<<((NU)(((Tsymflag292184) 27))&31U)))!=0); LA19: ; LOC17 = LOC18; if (!(LOC17)) goto LA20; LOC17 = (((*d0).flags &(1U<<((NU)(((Tlocflag292810) 8))&15U)))!=0); LA20: ; if (!LOC17) goto LA21; (*d0).k = ((Tlockind292808) 9); unsureAsgnRef((void**) (&(*d0).r), pl0); (*d0).flags &= ~(((NU16)1) << ((((Tlocflag292810) 8)) % (sizeof(NU16)*8))); } goto LA15; LA21: ; { Tloc292816 list0; { if (!((*d0).k == ((Tlockind292808) 0))) goto LA26; gettemp_537032_839829468(p0, (*typ0).sons->data[((NI) 0)], d0, NIM_FALSE); } LA26: ; memset((void*)(&list0), 0, sizeof(list0)); initloc_532273_839829468((&list0), ((Tlockind292808) 9), (*d0).t, ((Tstorageloc292812) 0)); list0.r = pl0; genassignment_539264_839829468(p0, (*d0), list0, 0); } LA15: ; } goto LA11; LA13: ; { TY533289 LOC29; Ropeobj178006* LOC30; memset((void*)LOC29, 0, sizeof(LOC29)); LOC30 = (Ropeobj178006*)0; LOC30 = HEX25_178905_2381377266(((NimStringDesc*) &T839829468_497), LOC29, 0); add_178482_2381377266(&pl0, LOC30); line_532690_839829468(p0, ((Tcprocsection529011) 2), pl0); } LA11: ; } goto LA6; LA9: ; { Ropeobj178006* pl0; Ropeobj178006* params0; pl0 = NIM_NIL; { NI LOC34; Ropeobj178006* LOC37; LOC34 = (NI)0; LOC34 = len_293081_850551059(ri0); if (!(((NI) 1) < LOC34)) goto LA35; LOC37 = (Ropeobj178006*)0; LOC37 = genthisarg_541475_839829468(p0, ri0, ((NI) 1), typ_541940_839829468); add_178482_2381377266(&pl0, LOC37); } LA35: ; add_178482_2381377266(&pl0, op0.r); params0 = (Ropeobj178006*)0; { NI i_542425_839829468; NI HEX3Atmp_542609_839829468; NI res_542612_839829468; i_542425_839829468 = (NI)0; HEX3Atmp_542609_839829468 = (NI)0; HEX3Atmp_542609_839829468 = (NI)(length0 - ((NI) 1)); res_542612_839829468 = ((NI) 2); { while (1) { Ropeobj178006* LOC47; if (!(res_542612_839829468 <= HEX3Atmp_542609_839829468)) goto LA40; i_542425_839829468 = res_542612_839829468; { TY533289 LOC45; Ropeobj178006* LOC46; if (!!((params0 == NIM_NIL))) goto LA43; memset((void*)LOC45, 0, sizeof(LOC45)); LOC46 = (Ropeobj178006*)0; LOC46 = HEX25_178905_2381377266(((NimStringDesc*) &T839829468_110), LOC45, 0); add_178482_2381377266(&params0, LOC46); } LA43: ; LOC47 = (Ropeobj178006*)0; LOC47 = genotherarg_539277_839829468(p0, ri0, i_542425_839829468, typ_541940_839829468); add_178482_2381377266(&params0, LOC47); res_542612_839829468 += ((NI) 1); } LA40: ; } } fixupcall_539410_839829468(p0, le0, ri0, d0, pl0, params0); } LA6: ; } N_NIMCALL(void, gennamedparamcall_542616_839829468)(Tcproc529021* p0, Tnode292802* ri0, Tloc292816* d0) { Tloc292816 op0; Ropeobj178006* pl0; TY533289 LOC1; Ttype292840* typ0; NI length0; NimStringDesc* pat0; NI start0; memset((void*)(&op0), 0, sizeof(op0)); initlocexpr_539283_839829468(p0, (*ri0).kindU.S6.sons->data[((NI) 0)], (&op0)); memset((void*)LOC1, 0, sizeof(LOC1)); pl0 = HEX25_178905_2381377266(((NimStringDesc*) &T839829468_506), LOC1, 0); typ0 = skiptypes_296099_850551059((*(*ri0).kindU.S6.sons->data[((NI) 0)]).typ, IL64(211106232576256)); length0 = sonslen_295351_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_196185_1689653243(T839829468_507); internalerror_196113_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_178482_2381377266(&pl0, op0.r); { TY533289 LOC16; Ropeobj178006* LOC17; Ropeobj178006* LOC18; if (!(((NI) 1) < length0)) goto LA14; memset((void*)LOC16, 0, sizeof(LOC16)); LOC17 = (Ropeobj178006*)0; LOC17 = HEX25_178905_2381377266(((NimStringDesc*) &T839829468_244), LOC16, 0); add_178482_2381377266(&pl0, LOC17); LOC18 = (Ropeobj178006*)0; LOC18 = genarg_539787_839829468(p0, (*ri0).kindU.S6.sons->data[((NI) 1)], (*(*(*typ0).n).kindU.S6.sons->data[((NI) 1)]).kindU.S4.sym, ri0); add_178482_2381377266(&pl0, LOC18); start0 = ((NI) 2); } LA14: ; } goto LA7; LA10: ; { { Ropeobj178006* LOC24; TY533289 LOC25; Ropeobj178006* LOC26; if (!(((NI) 1) < length0)) goto LA22; LOC24 = (Ropeobj178006*)0; LOC24 = genarg_539787_839829468(p0, (*ri0).kindU.S6.sons->data[((NI) 1)], (*(*(*typ0).n).kindU.S6.sons->data[((NI) 1)]).kindU.S4.sym, ri0); add_178482_2381377266(&pl0, LOC24); memset((void*)LOC25, 0, sizeof(LOC25)); LOC26 = (Ropeobj178006*)0; LOC26 = HEX25_178905_2381377266(((NimStringDesc*) &T839829468_111), LOC25, 0); add_178482_2381377266(&pl0, LOC26); } LA22: ; add_178482_2381377266(&pl0, op0.r); { TY533289 LOC31; Ropeobj178006* LOC32; Ropeobj178006* LOC33; if (!(((NI) 2) < length0)) goto LA29; memset((void*)LOC31, 0, sizeof(LOC31)); LOC32 = (Ropeobj178006*)0; LOC32 = HEX25_178905_2381377266(((NimStringDesc*) &T839829468_244), LOC31, 0); add_178482_2381377266(&pl0, LOC32); LOC33 = (Ropeobj178006*)0; LOC33 = genarg_539787_839829468(p0, (*ri0).kindU.S6.sons->data[((NI) 2)], (*(*(*typ0).n).kindU.S6.sons->data[((NI) 2)]).kindU.S4.sym, ri0); add_178482_2381377266(&pl0, LOC33); } LA29: ; } LA7: ; { NI i_543051_839829468; NI HEX3Atmp_543617_839829468; NI res_543620_839829468; i_543051_839829468 = (NI)0; HEX3Atmp_543617_839829468 = (NI)0; HEX3Atmp_543617_839829468 = (NI)(length0 - ((NI) 1)); res_543620_839829468 = start0; { while (1) { Tsym292834* param0; TY533289 LOC42; Ropeobj178006* LOC43; TY533289 LOC44; Ropeobj178006* LOC45; Ropeobj178006* LOC46; if (!(res_543620_839829468 <= HEX3Atmp_543617_839829468)) goto LA36; i_543051_839829468 = res_543620_839829468; { NI LOC39; LOC39 = (NI)0; LOC39 = sonslen_295327_850551059(typ0); if (!(LOC39 <= i_543051_839829468)) goto LA40; internalerror_196100_155036129((*ri0).info, ((NimStringDesc*) &T839829468_508)); } LA40: ; param0 = (*(*(*typ0).n).kindU.S6.sons->data[i_543051_839829468]).kindU.S4.sym; memset((void*)LOC42, 0, sizeof(LOC42)); LOC43 = (Ropeobj178006*)0; LOC43 = HEX25_178905_2381377266(((NimStringDesc*) &T839829468_111), LOC42, 0); add_178482_2381377266(&pl0, LOC43); add_178487_2381377266(&pl0, (*(*param0).name).s); memset((void*)LOC44, 0, sizeof(LOC44)); LOC45 = (Ropeobj178006*)0; LOC45 = HEX25_178905_2381377266(((NimStringDesc*) &T839829468_244), LOC44, 0); add_178482_2381377266(&pl0, LOC45); LOC46 = (Ropeobj178006*)0; LOC46 = genarg_539787_839829468(p0, (*ri0).kindU.S6.sons->data[i_543051_839829468], param0, ri0); add_178482_2381377266(&pl0, LOC46); res_543620_839829468 += ((NI) 1); } LA36: ; } } { if (!!(((*typ0).sons->data[((NI) 0)] == NIM_NIL))) goto LA49; { NIM_BOOL LOC53; LOC53 = (NIM_BOOL)0; LOC53 = isinvalidreturntype_533548_839829468((*typ0).sons->data[((NI) 0)]); if (!LOC53) goto LA54; { NI LOC58; TY533289 LOC61; Ropeobj178006* LOC62; LOC58 = (NI)0; LOC58 = sonslen_295351_850551059(ri0); if (!(((NI) 1) < LOC58)) goto LA59; memset((void*)LOC61, 0, sizeof(LOC61)); LOC62 = (Ropeobj178006*)0; LOC62 = HEX25_178905_2381377266(((NimStringDesc*) &T839829468_111), LOC61, 0); add_178482_2381377266(&pl0, LOC62); } LA59: ; { TY533289 LOC71; Ropeobj178006* LOC72; Ropeobj178006* LOC73; TY533289 LOC74; Ropeobj178006* LOC75; if (!((3 &(1U<<((NU)((*d0).k)&15U)))!=0)) goto LA65; { if (!((*d0).k == ((Tlockind292808) 0))) goto LA69; gettemp_537032_839829468(p0, (*typ0).sons->data[((NI) 0)], d0, NIM_TRUE); } LA69: ; memset((void*)LOC71, 0, sizeof(LOC71)); LOC72 = (Ropeobj178006*)0; LOC72 = HEX25_178905_2381377266(((NimStringDesc*) &T839829468_509), LOC71, 0); add_178482_2381377266(&pl0, LOC72); LOC73 = (Ropeobj178006*)0; LOC73 = addrloc_538204_839829468((*d0)); add_178482_2381377266(&pl0, LOC73); memset((void*)LOC74, 0, sizeof(LOC74)); LOC75 = (Ropeobj178006*)0; LOC75 = HEX25_178905_2381377266(((NimStringDesc*) &T839829468_510), LOC74, 0); add_178482_2381377266(&pl0, LOC75); line_532690_839829468(p0, ((Tcprocsection529011) 2), pl0); } goto LA63; LA65: ; { Tloc292816 tmp0; Ropeobj178006* LOC77; TY533289 LOC78; Ropeobj178006* LOC79; memset((void*)(&tmp0), 0, sizeof(tmp0)); gettemp_537032_839829468(p0, (*typ0).sons->data[((NI) 0)], (&tmp0), NIM_TRUE); LOC77 = (Ropeobj178006*)0; LOC77 = addrloc_538204_839829468(tmp0); add_178482_2381377266(&pl0, LOC77); memset((void*)LOC78, 0, sizeof(LOC78)); LOC79 = (Ropeobj178006*)0; LOC79 = HEX25_178905_2381377266(((NimStringDesc*) &T839829468_510), LOC78, 0); add_178482_2381377266(&pl0, LOC79); line_532690_839829468(p0, ((Tcprocsection529011) 2), pl0); genassignment_539264_839829468(p0, (*d0), tmp0, 0); } LA63: ; } goto LA51; LA54: ; { TY533289 LOC81; Ropeobj178006* LOC82; Tloc292816 list0; memset((void*)LOC81, 0, sizeof(LOC81)); LOC82 = (Ropeobj178006*)0; LOC82 = HEX25_178905_2381377266(((NimStringDesc*) &T839829468_511), LOC81, 0); add_178482_2381377266(&pl0, LOC82); { if (!((*d0).k == ((Tlockind292808) 0))) goto LA85; gettemp_537032_839829468(p0, (*typ0).sons->data[((NI) 0)], d0, NIM_FALSE); } LA85: ; memset((void*)(&list0), 0, sizeof(list0)); initloc_532273_839829468((&list0), ((Tlockind292808) 9), NIM_NIL, ((Tstorageloc292812) 0)); list0.r = pl0; genassignment_539264_839829468(p0, (*d0), list0, 0); } LA51: ; } goto LA47; LA49: ; { TY533289 LOC88; Ropeobj178006* LOC89; memset((void*)LOC88, 0, sizeof(LOC88)); LOC89 = (Ropeobj178006*)0; LOC89 = HEX25_178905_2381377266(((NimStringDesc*) &T839829468_510), LOC88, 0); add_178482_2381377266(&pl0, LOC89); line_532690_839829468(p0, ((Tcprocsection529011) 2), pl0); } LA47: ; } N_NIMCALL(void, genprefixcall_539960_839829468)(Tcproc529021* p0, Tnode292802* le0, Tnode292802* ri0, Tloc292816* d0) { Tloc292816 op0; Ropeobj178006* params0; Ttype292840* typ0; NI length0; memset((void*)(&op0), 0, sizeof(op0)); initlocexpr_539283_839829468(p0, (*ri0).kindU.S6.sons->data[((NI) 0)], (&op0)); params0 = (Ropeobj178006*)0; typ0 = skiptypes_296099_850551059((*(*ri0).kindU.S6.sons->data[((NI) 0)]).typ, IL64(211106232576256)); length0 = sonslen_295351_850551059(ri0); { NI i_540213_839829468; NI HEX3Atmp_540445_839829468; NI res_540448_839829468; i_540213_839829468 = (NI)0; HEX3Atmp_540445_839829468 = (NI)0; HEX3Atmp_540445_839829468 = (NI)(length0 - ((NI) 1)); res_540448_839829468 = ((NI) 1); { while (1) { if (!(res_540448_839829468 <= HEX3Atmp_540445_839829468)) goto LA3; i_540213_839829468 = res_540448_839829468; { NI LOC6; Tnode292802* paramtype0; LOC6 = (NI)0; LOC6 = sonslen_295327_850551059(typ0); if (!(i_540213_839829468 < LOC6)) goto LA7; paramtype0 = (*(*typ0).n).kindU.S6.sons->data[i_540213_839829468]; { NIM_BOOL LOC11; Ropeobj178006* LOC20; LOC11 = (NIM_BOOL)0; LOC11 = iscompiletimeonly_328706_3876443242((*paramtype0).typ); if (!!(LOC11)) goto LA12; { TY533289 LOC18; Ropeobj178006* LOC19; if (!!((params0 == NIM_NIL))) goto LA16; memset((void*)LOC18, 0, sizeof(LOC18)); LOC19 = (Ropeobj178006*)0; LOC19 = HEX25_178905_2381377266(((NimStringDesc*) &T839829468_110), LOC18, 0); add_178482_2381377266(&params0, LOC19); } LA16: ; LOC20 = (Ropeobj178006*)0; LOC20 = genarg_539787_839829468(p0, (*ri0).kindU.S6.sons->data[i_540213_839829468], (*paramtype0).kindU.S4.sym, ri0); add_178482_2381377266(&params0, LOC20); } LA12: ; } goto LA4; LA7: ; { Ropeobj178006* LOC28; { TY533289 LOC26; Ropeobj178006* LOC27; if (!!((params0 == NIM_NIL))) goto LA24; memset((void*)LOC26, 0, sizeof(LOC26)); LOC27 = (Ropeobj178006*)0; LOC27 = HEX25_178905_2381377266(((NimStringDesc*) &T839829468_110), LOC26, 0); add_178482_2381377266(&params0, LOC27); } LA24: ; LOC28 = (Ropeobj178006*)0; LOC28 = genargnoparam_539938_839829468(p0, (*ri0).kindU.S6.sons->data[i_540213_839829468]); add_178482_2381377266(&params0, LOC28); } LA4: ; res_540448_839829468 += ((NI) 1); } LA3: ; } } fixupcall_539410_839829468(p0, le0, ri0, d0, op0.r, params0); } static N_INLINE(void, poststmtactions_532942_839829468)(Tcproc529021* p0) { Ropeobj178006** LOC1; LOC1 = (Ropeobj178006**)0; LOC1 = s_529179_3723162438(p0, ((Tcprocsection529011) 2)); add_178482_2381377266(LOC1, (*(*p0).module).injectstmt); } N_NIMCALL(void, gencall_543632_839829468)(Tcproc529021* p0, Tnode292802* e0, Tloc292816* d0) { { Ttype292840* LOC3; LOC3 = (Ttype292840*)0; LOC3 = skiptypes_296099_850551059((*(*e0).kindU.S6.sons->data[((NI) 0)]).typ, 2048); if (!((*LOC3).callconv == ((Tcallingconvention292002) 8))) goto LA4; genclosurecall_540452_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 == ((Tnodekind292020) 3)); if (!(LOC7)) goto LA8; LOC7 = (((*(*(*e0).kindU.S6.sons->data[((NI) 0)]).kindU.S4.sym).flags &(1U<<((NU)(((Tsymflag292184) 27))&31U)))!=0); LA8: ; if (!LOC7) goto LA9; geninfixcall_541929_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 == ((Tnodekind292020) 3)); if (!(LOC12)) goto LA13; LOC12 = (((*(*(*e0).kindU.S6.sons->data[((NI) 0)]).kindU.S4.sym).flags &(1U<<((NU)(((Tsymflag292184) 28))&31U)))!=0); LA13: ; if (!LOC12) goto LA14; gennamedparamcall_542616_839829468(p0, e0, d0); } goto LA1; LA14: ; { genprefixcall_539960_839829468(p0, NIM_NIL, e0, d0); } LA1: ; poststmtactions_532942_839829468(p0); } N_NIMCALL(void, genreset_554731_839829468)(Tcproc529021* p0, Tnode292802* n0) { Tloc292816 a0; TY532811 LOC1; Ttype292840* LOC2; memset((void*)(&a0), 0, sizeof(a0)); initlocexpr_539283_839829468(p0, (*n0).kindU.S6.sons->data[((NI) 1)], (&a0)); memset((void*)LOC1, 0, sizeof(LOC1)); LOC1[0] = addrloc_538204_839829468(a0); LOC2 = (Ttype292840*)0; LOC2 = skiptypes_296099_850551059(a0.t, IL64(211106242013440)); LOC1[1] = gentypeinfo_535941_839829468((*p0).module, LOC2); linefmt_532714_839829468(p0, ((Tcprocsection529011) 2), ((NimStringDesc*) &T839829468_496), LOC1, 2); } N_NIMCALL(void, genecho_554369_839829468)(Tcproc529021* p0, Tnode292802* n0) { NIM_BOOL LOC6; Ropeobj178006* args0; Tloc292816 a0; TY532811 LOC18; NimStringDesc* LOC19; NI LOC20; NimStringDesc* LOC21; TY533289 LOC22; { NimStringDesc* LOC5; if (!!(((*n0).kind == ((Tnodekind292020) 41)))) goto LA3; LOC5 = (NimStringDesc*)0; LOC5 = HEX24_196185_1689653243(T839829468_512); internalerror_196113_155036129(LOC5); } LA3: ; LOC6 = (NIM_BOOL)0; LOC6 = includestr_147249_3771138726((&(*(*p0).module).headerfiles), ((NimStringDesc*) &T839829468_513)); args0 = NIM_NIL; memset((void*)(&a0), 0, sizeof(a0)); { NI i_554404_839829468; NI HEX3Atmp_554431_839829468; NI LOC8; NI res_554434_839829468; i_554404_839829468 = (NI)0; HEX3Atmp_554431_839829468 = (NI)0; LOC8 = (NI)0; LOC8 = len_293081_850551059(n0); HEX3Atmp_554431_839829468 = (NI)(LOC8 - ((NI) 1)); res_554434_839829468 = ((NI) 0); { while (1) { if (!(res_554434_839829468 <= HEX3Atmp_554431_839829468)) goto LA10; i_554404_839829468 = res_554434_839829468; { Tnode292802* LOC13; LOC13 = (Tnode292802*)0; LOC13 = skipconv_328882_3876443242((*n0).kindU.S6.sons->data[i_554404_839829468]); if (!((*LOC13).kind == ((Tnodekind292020) 23))) goto LA14; add_178487_2381377266(&args0, ((NimStringDesc*) &T839829468_514)); } goto LA11; LA14: ; { TY178507 LOC17; initlocexpr_539283_839829468(p0, (*n0).kindU.S6.sons->data[i_554404_839829468], (&a0)); memset((void*)LOC17, 0, sizeof(LOC17)); LOC17[0] = rdloc_538188_839829468(a0); addf_179205_2381377266(&args0, ((NimStringDesc*) &T839829468_515), LOC17, 1); } LA11: ; res_554434_839829468 += ((NI) 1); } LA10: ; } } memset((void*)LOC18, 0, sizeof(LOC18)); LOC19 = (NimStringDesc*)0; LOC20 = (NI)0; LOC20 = len_293081_850551059(n0); LOC21 = (NimStringDesc*)0; LOC21 = nsuRepeatStr(((NimStringDesc*) &T839829468_517), ((NI) (LOC20))); LOC19 = rawNewString(LOC21->Sup.len + tnl_176644_4151366050->Sup.len + 0); appendString(LOC19, LOC21); appendString(LOC19, tnl_176644_4151366050); LOC18[0] = makecstring_191638_155036129(LOC19); LOC18[1] = args0; linefmt_532714_839829468(p0, ((Tcprocsection529011) 2), ((NimStringDesc*) &T839829468_516), LOC18, 2); memset((void*)LOC22, 0, sizeof(LOC22)); linefmt_532714_839829468(p0, ((Tcprocsection529011) 2), ((NimStringDesc*) &T839829468_518), LOC22, 0); } N_NIMCALL(void, genseqconstr_555004_839829468)(Tcproc529021* p0, Tnode292802* t0, Tloc292816* d0) { Tloc292816 arr0; NI LOC5; Ropeobj178006* LOC6; memset((void*)(&arr0), 0, sizeof(arr0)); { if (!((*d0).k == ((Tlockind292808) 0))) goto LA3; gettemp_537032_839829468(p0, (*t0).typ, d0, NIM_FALSE); } LA3: ; LOC5 = (NI)0; LOC5 = sonslen_295351_850551059(t0); LOC6 = (Ropeobj178006*)0; LOC6 = intliteral_539270_839829468(((NI64) (LOC5))); gennewseqaux_554795_839829468(p0, (*d0), LOC6); { NI i_555031_839829468; NI HEX3Atmp_555039_839829468; NI LOC8; NI res_555042_839829468; i_555031_839829468 = (NI)0; HEX3Atmp_555039_839829468 = (NI)0; LOC8 = (NI)0; LOC8 = sonslen_295351_850551059(t0); HEX3Atmp_555039_839829468 = (NI)(LOC8 - ((NI) 1)); res_555042_839829468 = ((NI) 0); { while (1) { Ttype292840* LOC11; Ttype292840* LOC12; TY532811 LOC13; if (!(res_555042_839829468 <= HEX3Atmp_555039_839829468)) goto LA10; i_555031_839829468 = res_555042_839829468; LOC11 = (Ttype292840*)0; LOC11 = skiptypes_296099_850551059((*t0).typ, IL64(211106232576256)); LOC12 = (Ttype292840*)0; LOC12 = elemtype_320394_3876443242(LOC11); initloc_532273_839829468((&arr0), ((Tlockind292808) 6), LOC12, ((Tstorageloc292812) 3)); memset((void*)LOC13, 0, sizeof(LOC13)); LOC13[0] = rdloc_538188_839829468((*d0)); LOC13[1] = intliteral_539270_839829468(((NI64) (i_555031_839829468))); arr0.r = ropecg_532407_839829468(NIM_NIL, ((NimStringDesc*) &T839829468_187), LOC13, 2); arr0.s = ((Tstorageloc292812) 3); expr_539248_839829468(p0, (*t0).kindU.S6.sons->data[i_555031_839829468], (&arr0)); res_555042_839829468 += ((NI) 1); } LA10: ; } } gcusage_554439_839829468(t0); } N_NIMCALL(void, genarrtoseq_555046_839829468)(Tcproc529021* p0, Tnode292802* t0, Tloc292816* d0) { Tloc292816 elem0; Tloc292816 a0; Tloc292816 arr0; NI L0; NI64 LOC9; Ropeobj178006* LOC10; { memset((void*)(&elem0), 0, sizeof(elem0)); memset((void*)(&a0), 0, sizeof(a0)); memset((void*)(&arr0), 0, sizeof(arr0)); { if (!((*t0).kind == ((Tnodekind292020) 41))) goto LA3; asgnRefNoCycle((void**) (&(*(*t0).kindU.S6.sons->data[((NI) 1)]).typ), (*t0).typ); genseqconstr_555004_839829468(p0, (*t0).kindU.S6.sons->data[((NI) 1)], d0); goto BeforeRet; } LA3: ; { if (!((*d0).k == ((Tlockind292808) 0))) goto LA7; gettemp_537032_839829468(p0, (*t0).typ, d0, NIM_FALSE); } LA7: ; LOC9 = (NI64)0; LOC9 = lengthord_320007_3876443242((*(*t0).kindU.S6.sons->data[((NI) 1)]).typ); L0 = ((NI) (LOC9)); LOC10 = (Ropeobj178006*)0; LOC10 = intliteral_539270_839829468(((NI64) (L0))); gennewseqaux_554795_839829468(p0, (*d0), LOC10); initlocexpr_539283_839829468(p0, (*t0).kindU.S6.sons->data[((NI) 1)], (&a0)); { NI i_555090_839829468; NI HEX3Atmp_555103_839829468; NI res_555106_839829468; i_555090_839829468 = (NI)0; HEX3Atmp_555103_839829468 = (NI)0; HEX3Atmp_555103_839829468 = (NI)(L0 - ((NI) 1)); res_555106_839829468 = ((NI) 0); { while (1) { Ttype292840* LOC14; Ttype292840* LOC15; TY532811 LOC16; Ttype292840* LOC17; Ttype292840* LOC18; TY532811 LOC19; if (!(res_555106_839829468 <= HEX3Atmp_555103_839829468)) goto LA13; i_555090_839829468 = res_555106_839829468; LOC14 = (Ttype292840*)0; LOC14 = skiptypes_296099_850551059((*t0).typ, IL64(211106232576256)); LOC15 = (Ttype292840*)0; LOC15 = elemtype_320394_3876443242(LOC14); initloc_532273_839829468((&elem0), ((Tlockind292808) 6), LOC15, ((Tstorageloc292812) 3)); memset((void*)LOC16, 0, sizeof(LOC16)); LOC16[0] = rdloc_538188_839829468((*d0)); LOC16[1] = intliteral_539270_839829468(((NI64) (i_555090_839829468))); elem0.r = ropecg_532407_839829468(NIM_NIL, ((NimStringDesc*) &T839829468_187), LOC16, 2); elem0.s = ((Tstorageloc292812) 3); LOC17 = (Ttype292840*)0; LOC17 = skiptypes_296099_850551059((*(*t0).kindU.S6.sons->data[((NI) 1)]).typ, IL64(211106232576256)); LOC18 = (Ttype292840*)0; LOC18 = elemtype_320394_3876443242(LOC17); initloc_532273_839829468((&arr0), ((Tlockind292808) 6), LOC18, a0.s); memset((void*)LOC19, 0, sizeof(LOC19)); LOC19[0] = rdloc_538188_839829468(a0); LOC19[1] = intliteral_539270_839829468(((NI64) (i_555090_839829468))); arr0.r = ropecg_532407_839829468(NIM_NIL, ((NimStringDesc*) &T839829468_138), LOC19, 2); genassignment_539264_839829468(p0, elem0, arr0, 3); res_555106_839829468 += ((NI) 1); } LA13: ; } } }BeforeRet: ; } N_NIMCALL(void, gendeepcopy_550374_839829468)(Tcproc529021* p0, Tloc292816 dest0, Tloc292816 src0) { Ttype292840* ty0; ty0 = skiptypes_296099_850551059(dest0.t, IL64(211106242013440)); switch ((*ty0).kind) { case ((Ttypekind292244) 21): case ((Ttypekind292244) 22): case ((Ttypekind292244) 25): case ((Ttypekind292244) 18): case ((Ttypekind292244) 17): case ((Ttypekind292244) 16): case ((Ttypekind292244) 4): { TY535238 LOC2; memset((void*)LOC2, 0, sizeof(LOC2)); LOC2[0] = addrloc_538204_839829468(dest0); LOC2[1] = addrloc_538204_839829468(src0); LOC2[2] = gentypeinfo_535941_839829468((*p0).module, dest0.t); linefmt_532714_839829468(p0, ((Tcprocsection529011) 2), ((NimStringDesc*) &T839829468_519), LOC2, 3); } break; case ((Ttypekind292244) 24): case ((Ttypekind292244) 28): { TY535238 LOC4; memset((void*)LOC4, 0, sizeof(LOC4)); LOC4[0] = addrloc_538204_839829468(dest0); LOC4[1] = rdloc_538188_839829468(src0); LOC4[2] = gentypeinfo_535941_839829468((*p0).module, dest0.t); linefmt_532714_839829468(p0, ((Tcprocsection529011) 2), ((NimStringDesc*) &T839829468_520), LOC4, 3); } break; case ((Ttypekind292244) 27): case ((Ttypekind292244) 48): { TY535238 LOC6; memset((void*)LOC6, 0, sizeof(LOC6)); LOC6[0] = addrloc_538204_839829468(dest0); LOC6[1] = addrloc_538204_839829468(src0); LOC6[2] = gentypeinfo_535941_839829468((*p0).module, dest0.t); linefmt_532714_839829468(p0, ((Tcprocsection529011) 2), ((NimStringDesc*) &T839829468_521), LOC6, 3); } break; case ((Ttypekind292244) 19): { { Tctypekind529007 LOC10; TY535238 LOC13; NI64 LOC14; LOC10 = (Tctypekind529007)0; LOC10 = maptype_533393_839829468(ty0); if (!(LOC10 == ((Tctypekind529007) 17))) goto LA11; usestringh_532345_839829468((*p0).module); memset((void*)LOC13, 0, sizeof(LOC13)); LOC13[0] = rdloc_538188_839829468(dest0); LOC13[1] = rdloc_538188_839829468(src0); LOC14 = (NI64)0; LOC14 = getsize_320135_3876443242(dest0.t); LOC13[2] = rope_178401_2381377266(LOC14); linefmt_532714_839829468(p0, ((Tcprocsection529011) 2), ((NimStringDesc*) &T839829468_268), LOC13, 3); } goto LA8; LA11: ; { TY532811 LOC16; memset((void*)LOC16, 0, sizeof(LOC16)); LOC16[0] = rdloc_538188_839829468(dest0); LOC16[1] = rdloc_538188_839829468(src0); linefmt_532714_839829468(p0, ((Tcprocsection529011) 2), ((NimStringDesc*) &T839829468_123), LOC16, 2); } LA8: ; } break; case ((Ttypekind292244) 26): case ((Ttypekind292244) 2): case ((Ttypekind292244) 1): case ((Ttypekind292244) 14): case ((Ttypekind292244) 29): case ((Ttypekind292244) 31) ... ((Ttypekind292244) 44): case ((Ttypekind292244) 20): case ((Ttypekind292244) 23): { TY532811 LOC18; memset((void*)LOC18, 0, sizeof(LOC18)); LOC18[0] = rdloc_538188_839829468(dest0); LOC18[1] = rdloc_538188_839829468(src0); linefmt_532714_839829468(p0, ((Tcprocsection529011) 2), ((NimStringDesc*) &T839829468_123), LOC18, 2); } break; default: { NimStringDesc* LOC20; LOC20 = (NimStringDesc*)0; LOC20 = rawNewString(reprEnum((NI)(*ty0).kind, (&NTI292244))->Sup.len + 13); appendString(LOC20, ((NimStringDesc*) &T839829468_522)); appendString(LOC20, reprEnum((NI)(*ty0).kind, (&NTI292244))); internalerror_196113_155036129(LOC20); } break; } } N_NIMCALL(void, genmagicexpr_557033_839829468)(Tcproc529021* p0, Tnode292802* e0, Tloc292816* d0, Tmagic292524 op0) { switch (op0) { case ((Tmagic292524) 127): case ((Tmagic292524) 126): { genandor_554311_839829468(p0, e0, d0, op0); } break; case ((Tmagic292524) 99) ... ((Tmagic292524) 117): { unaryarith_552646_839829468(p0, e0, d0, op0); } break; case ((Tmagic292524) 96) ... ((Tmagic292524) 98): { unaryarithoverflow_551633_839829468(p0, e0, d0, op0); } break; case ((Tmagic292524) 52) ... ((Tmagic292524) 55): { binaryfloatarith_556728_839829468(p0, e0, d0, op0); } break; case ((Tmagic292524) 56) ... ((Tmagic292524) 93): { binaryarith_551819_839829468(p0, e0, d0, op0); } break; case ((Tmagic292524) 95): { geneqproc_552214_839829468(p0, e0, d0); } break; case ((Tmagic292524) 45) ... ((Tmagic292524) 51): { binaryarithoverflow_551262_839829468(p0, e0, d0, op0); } break; case ((Tmagic292524) 149): { genrepr_555339_839829468(p0, e0, d0); } break; case ((Tmagic292524) 259): { gengettypeinfo_555383_839829468(p0, e0, d0); } break; case ((Tmagic292524) 156): { genswap_555638_839829468(p0, e0, d0); } break; case ((Tmagic292524) 25): { { if (!!((((*p0).options &(1U<<((NU)(((Toption169009) 5))&31U)))!=0))) goto LA14; unaryexpr_551209_839829468(p0, e0, d0, ((NimStringDesc*) &T839829468_385)); } goto LA12; LA14: ; { unaryexpr_551209_839829468(p0, e0, d0, ((NimStringDesc*) &T839829468_386)); } LA12: ; } break; case ((Tmagic292524) 26): case ((Tmagic292524) 27): { Ttype292840* underlying0; underlying0 = skiptypes_296099_850551059((*(*e0).kindU.S6.sons->data[((NI) 1)]).typ, 9439232); { NIM_BOOL LOC20; LOC20 = (NIM_BOOL)0; LOC20 = !((((*p0).options &(1U<<((NU)(((Toption169009) 5))&31U)))!=0)); if (LOC20) goto LA21; LOC20 = ((*underlying0).kind >= ((Ttypekind292244) 40) && (*underlying0).kind <= ((Ttypekind292244) 44)); LA21: ; if (!LOC20) goto LA22; binarystmt_550501_839829468(p0, e0, d0, opr_557050_839829468[(op0)- 26]); } goto LA18; LA22: ; { Tloc292816 a0; Tloc292816 b0; Ttype292840* ranged0; Ropeobj178006* res0; NimStringDesc* LOC25; TY532811 LOC31; Ropeobj178006* LOC32; memset((void*)(&a0), 0, sizeof(a0)); memset((void*)(&b0), 0, sizeof(b0)); initlocexpr_539283_839829468(p0, (*e0).kindU.S6.sons->data[((NI) 1)], (&a0)); initlocexpr_539283_839829468(p0, (*e0).kindU.S6.sons->data[((NI) 2)], (&b0)); ranged0 = skiptypes_296099_850551059((*(*e0).kindU.S6.sons->data[((NI) 1)]).typ, 8390656); LOC25 = (NimStringDesc*)0; { if (!((*underlying0).kind == ((Ttypekind292244) 35))) goto LA28; LOC25 = copyString(fun64_557055_839829468[(op0)- 26]); } goto LA26; LA28: ; { LOC25 = copyString(fun_557060_839829468[(op0)- 26]); } LA26: ; res0 = binaryarithoverflowraw_551235_839829468(p0, ranged0, a0, b0, LOC25); memset((void*)LOC31, 0, sizeof(LOC31)); LOC31[0] = gettypedesc_535671_839829468((*p0).module, ranged0); LOC31[1] = res0; LOC32 = (Ropeobj178006*)0; LOC32 = HEX25_178905_2381377266(((NimStringDesc*) &T839829468_370), LOC31, 2); putintodest_550468_839829468(p0, (&a0), ranged0, LOC32, ((Tstorageloc292812) 0)); } LA18: ; } break; case ((Tmagic292524) 138): { genstrconcat_554452_839829468(p0, e0, d0); } break; case ((Tmagic292524) 144): { binarystmt_550501_839829468(p0, e0, d0, ((NimStringDesc*) &T839829468_394)); } break; case ((Tmagic292524) 145): { genstrappend_554554_839829468(p0, e0, d0); } break; case ((Tmagic292524) 146): { genseqelemappend_554683_839829468(p0, e0, d0); } break; case ((Tmagic292524) 128): { genstrequals_556666_839829468(p0, e0, d0); } break; case ((Tmagic292524) 129): { binaryexpr_550549_839829468(p0, e0, d0, ((NimStringDesc*) &T839829468_402)); } break; case ((Tmagic292524) 130): { binaryexpr_550549_839829468(p0, e0, d0, ((NimStringDesc*) &T839829468_403)); } break; case ((Tmagic292524) 157): { genisnil_552620_839829468(p0, e0, d0); } break; case ((Tmagic292524) 120): { gendollar_555391_839829468(p0, e0, d0, ((NimStringDesc*) &T839829468_406)); } break; case ((Tmagic292524) 121): { gendollar_555391_839829468(p0, e0, d0, ((NimStringDesc*) &T839829468_407)); } break; case ((Tmagic292524) 119): { gendollar_555391_839829468(p0, e0, d0, ((NimStringDesc*) &T839829468_408)); } break; case ((Tmagic292524) 118): { gendollar_555391_839829468(p0, e0, d0, ((NimStringDesc*) &T839829468_409)); } break; case ((Tmagic292524) 122): { gendollar_555391_839829468(p0, e0, d0, ((NimStringDesc*) &T839829468_410)); } break; case ((Tmagic292524) 123): { gendollar_555391_839829468(p0, e0, d0, ((NimStringDesc*) &T839829468_411)); } break; case ((Tmagic292524) 124): { expr_539248_839829468(p0, (*e0).kindU.S6.sons->data[((NI) 1)], d0); } break; case ((Tmagic292524) 125): { genrepr_555339_839829468(p0, e0, d0); } break; case ((Tmagic292524) 12): { genof_555331_839829468(p0, e0, d0); } break; case ((Tmagic292524) 29): { gennew_554782_839829468(p0, e0); } break; case ((Tmagic292524) 30): { gennewfinalize_555110_839829468(p0, e0); } break; case ((Tmagic292524) 31): { gennewseq_554824_839829468(p0, e0); } break; case ((Tmagic292524) 32): { gennewseqofcap_554836_839829468(p0, e0, d0); } break; case ((Tmagic292524) 9): { Ttype292840* t0; TY178507 LOC55; Ropeobj178006* LOC56; t0 = skiptypes_296099_850551059((*(*e0).kindU.S6.sons->data[((NI) 1)]).typ, 256); memset((void*)LOC55, 0, sizeof(LOC55)); LOC55[0] = gettypedesc_535671_839829468((*p0).module, t0); LOC56 = (Ropeobj178006*)0; LOC56 = HEX25_178905_2381377266(((NimStringDesc*) &T839829468_428), LOC55, 1); putintodest_550468_839829468(p0, d0, (*e0).typ, LOC56, ((Tstorageloc292812) 0)); } break; case ((Tmagic292524) 42): { gensomecast_556480_839829468(p0, e0, d0); } break; case ((Tmagic292524) 28): { genord_556474_839829468(p0, e0, d0); } break; case ((Tmagic292524) 35): case ((Tmagic292524) 8): case ((Tmagic292524) 34): case ((Tmagic292524) 36): case ((Tmagic292524) 33): { genarraylen_555415_839829468(p0, e0, d0, op0); } break; case ((Tmagic292524) 37): case ((Tmagic292524) 38): { { NIM_BOOL LOC63; LOC63 = (NIM_BOOL)0; LOC63 = (gcmd_169132_2607990831 == ((Tcommands169076) 2)); if (LOC63) goto LA64; LOC63 = (((*(*(*p0).module).module).flags &(1U<<((NU)(((Tsymflag292184) 27))&31U)))!=0); LA64: ; if (!!(LOC63)) goto LA65; unaryexpr_551209_839829468(p0, e0, d0, ((NimStringDesc*) &T839829468_440)); } goto LA61; LA65: ; { unaryexpr_551209_839829468(p0, e0, d0, ((NimStringDesc*) &T839829468_441)); } LA61: ; } break; case ((Tmagic292524) 43): { unarystmt_550527_839829468(p0, e0, d0, ((NimStringDesc*) &T839829468_443)); } break; case ((Tmagic292524) 44): { unarystmt_550527_839829468(p0, e0, d0, ((NimStringDesc*) &T839829468_444)); } break; case ((Tmagic292524) 151): { gensetlengthstr_555632_839829468(p0, e0, d0); } break; case ((Tmagic292524) 152): { gensetlengthseq_555500_839829468(p0, e0, d0); } break; case ((Tmagic292524) 39): case ((Tmagic292524) 40): case ((Tmagic292524) 41): case ((Tmagic292524) 133): case ((Tmagic292524) 132): case ((Tmagic292524) 131): case ((Tmagic292524) 134): case ((Tmagic292524) 135): case ((Tmagic292524) 136): case ((Tmagic292524) 148): { gensetop_556419_839829468(p0, e0, d0, op0); } break; case ((Tmagic292524) 161): case ((Tmagic292524) 162): case ((Tmagic292524) 159): case ((Tmagic292524) 160): case ((Tmagic292524) 150): case ((Tmagic292524) 163): { Tsym292834* opr0; opr0 = (*(*e0).kindU.S6.sons->data[((NI) 0)]).kindU.S4.sym; { NimStringDesc* LOC78; Ropeobj178006* LOC79; if (!!((((*opr0).loc.flags &(1U<<((NU)(((Tlocflag292810) 3))&15U)))!=0))) goto LA76; LOC78 = (NimStringDesc*)0; LOC78 = HEX24_178856_2381377266((*opr0).loc.r); LOC79 = (Ropeobj178006*)0; LOC79 = cgsym_532403_839829468((*p0).module, LOC78); } LA76: ; gencall_543632_839829468(p0, e0, d0); } break; case ((Tmagic292524) 164): { genreset_554731_839829468(p0, e0); } break; case ((Tmagic292524) 17): { Tnode292802* LOC82; Tnode292802* LOC83; LOC82 = (Tnode292802*)0; LOC82 = HEX5BHEX5D_293238_850551059(e0, ((NI) 1)); LOC83 = (Tnode292802*)0; LOC83 = skipconv_328882_3876443242(LOC82); genecho_554369_839829468(p0, LOC83); } break; case ((Tmagic292524) 158): { genarrtoseq_555046_839829468(p0, e0, d0); } break; case ((Tmagic292524) 223) ... ((Tmagic292524) 257): case ((Tmagic292524) 19) ... ((Tmagic292524) 24): { localerror_196080_155036129((*e0).info, ((Tmsgkind191002) 229), (*(*(*(*e0).kindU.S6.sons->data[((NI) 0)]).kindU.S4.sym).name).s); } break; case ((Tmagic292524) 208): { Tnode292802* n0; n0 = wrapprocforspawn_435501_2218250499((*(*p0).module).module, e0, (*e0).typ, NIM_NIL, NIM_NIL); expr_539248_839829468(p0, n0, d0); } break; case ((Tmagic292524) 155): { Tnode292802* n0; n0 = liftparallel_478822_1773027539((*(*p0).module).module, e0); expr_539248_839829468(p0, n0, d0); } break; case ((Tmagic292524) 209): { Tloc292816 a0; Tloc292816 b0; Tnode292802* x0; memset((void*)(&a0), 0, sizeof(a0)); memset((void*)(&b0), 0, sizeof(b0)); { Tnode292802* LOC91; Tnode292802* LOC94; LOC91 = (Tnode292802*)0; LOC91 = HEX5BHEX5D_293238_850551059(e0, ((NI) 1)); if (!((*LOC91).kind == ((Tnodekind292020) 63) || (*LOC91).kind == ((Tnodekind292020) 64))) goto LA92; LOC94 = (Tnode292802*)0; LOC94 = HEX5BHEX5D_293238_850551059(e0, ((NI) 1)); x0 = HEX5BHEX5D_293238_850551059(LOC94, ((NI) 0)); } goto LA89; LA92: ; { x0 = HEX5BHEX5D_293238_850551059(e0, ((NI) 1)); } LA89: ; initlocexpr_539283_839829468(p0, x0, (&a0)); initlocexpr_539283_839829468(p0, (*e0).kindU.S6.sons->data[((NI) 2)], (&b0)); gendeepcopy_550374_839829468(p0, a0, b0); } break; case ((Tmagic292524) 140): case ((Tmagic292524) 94): { gencall_543632_839829468(p0, e0, d0); } break; default: { NimStringDesc* LOC98; LOC98 = (NimStringDesc*)0; LOC98 = rawNewString(reprEnum((NI)op0, (&NTI292524))->Sup.len + 14); appendString(LOC98, ((NimStringDesc*) &T839829468_523)); appendString(LOC98, reprEnum((NI)op0, (&NTI292524))); internalerror_196100_155036129((*e0).info, LOC98); } break; } } N_NIMCALL(Ropeobj178006*, gensetnode_549664_839829468)(Tcproc529021* p0, Tnode292802* n0) { Ropeobj178006* result0; Tbitset339004* cs0; NI size0; NI64 LOC1; result0 = (Ropeobj178006*)0; cs0 = (Tbitset339004*)0; LOC1 = (NI64)0; LOC1 = getsize_320135_3876443242((*n0).typ); size0 = ((NI) (LOC1)); tobitset_340001_452470228(n0, (&cs0)); { NI id0; Ropeobj178006* LOC6; if (!(((NI) 8) < size0)) goto LA4; id0 = nodetabletestorset_342682_1142335848((&(*(*p0).module).datacache), n0, ((NI) ((*(*p0).module).labels))); LOC6 = (Ropeobj178006*)0; LOC6 = rope_178401_2381377266(((NI64) (id0))); result0 = HEX26_178418_2381377266((*(*p0).module).tmpbase, LOC6); { TY535238 LOC11; if (!(id0 == ((NI) ((*(*p0).module).labels)))) goto LA9; (*(*p0).module).labels += ((NI) 1); memset((void*)LOC11, 0, sizeof(LOC11)); LOC11[0] = gettypedesc_535671_839829468((*p0).module, (*n0).typ); LOC11[1] = result0; LOC11[2] = genrawsetdata_549629_839829468(cs0, size0); addf_179205_2381377266(&(*(*p0).module).s[(((Tcfilesection529005) 8))- 0], ((NimStringDesc*) &T839829468_524), LOC11, 3); } LA9: ; } goto LA2; LA4: ; { result0 = genrawsetdata_549629_839829468(cs0, size0); } LA2: ; return result0; } N_NIMCALL(void, gensetconstr_557496_839829468)(Tcproc529021* p0, Tnode292802* e0, Tloc292816* d0) { Tloc292816 a0; Tloc292816 b0; Tloc292816 idx0; memset((void*)(&a0), 0, sizeof(a0)); memset((void*)(&b0), 0, sizeof(b0)); memset((void*)(&idx0), 0, sizeof(idx0)); { Ropeobj178006* LOC5; if (!(((*e0).flags &(1U<<((NU)(((Tnodeflag292427) 4))&15U)))!=0)) goto LA3; LOC5 = (Ropeobj178006*)0; LOC5 = gensetnode_549664_839829468(p0, e0); putintodest_550468_839829468(p0, d0, (*e0).typ, LOC5, ((Tstorageloc292812) 0)); } goto LA1; LA3: ; { { if (!((*d0).k == ((Tlockind292808) 0))) goto LA9; gettemp_537032_839829468(p0, (*e0).typ, d0, NIM_FALSE); } LA9: ; { NI64 LOC13; TY178507 LOC16; LOC13 = (NI64)0; LOC13 = getsize_320135_3876443242((*e0).typ); if (!(IL64(8) < LOC13)) goto LA14; usestringh_532345_839829468((*p0).module); memset((void*)LOC16, 0, sizeof(LOC16)); LOC16[0] = rdloc_538188_839829468((*d0)); linef_532700_839829468(p0, ((Tcprocsection529011) 2), ((NimStringDesc*) &T839829468_525), LOC16, 1); { NI i_557537_839829468; NI HEX3Atmp_557603_839829468; NI LOC18; NI res_557606_839829468; i_557537_839829468 = (NI)0; HEX3Atmp_557603_839829468 = (NI)0; LOC18 = (NI)0; LOC18 = sonslen_295351_850551059(e0); HEX3Atmp_557603_839829468 = (NI)(LOC18 - ((NI) 1)); res_557606_839829468 = ((NI) 0); { while (1) { if (!(res_557606_839829468 <= HEX3Atmp_557603_839829468)) goto LA20; i_557537_839829468 = res_557606_839829468; { Ttype292840* LOC25; TY535235 LOC26; if (!((*(*e0).kindU.S6.sons->data[i_557537_839829468]).kind == ((Tnodekind292020) 44))) goto LA23; LOC25 = (Ttype292840*)0; LOC25 = getsystype_338150_3937434831(((Ttypekind292244) 31)); gettemp_537032_839829468(p0, LOC25, (&idx0), NIM_FALSE); initlocexpr_539283_839829468(p0, (*(*e0).kindU.S6.sons->data[i_557537_839829468]).kindU.S6.sons->data[((NI) 0)], (&a0)); initlocexpr_539283_839829468(p0, (*(*e0).kindU.S6.sons->data[i_557537_839829468]).kindU.S6.sons->data[((NI) 1)], (&b0)); memset((void*)LOC26, 0, sizeof(LOC26)); LOC26[0] = rdloc_538188_839829468(idx0); LOC26[1] = rdloc_538188_839829468((*d0)); LOC26[2] = rdsetelemloc_555662_839829468(a0, (*e0).typ); LOC26[3] = rdsetelemloc_555662_839829468(b0, (*e0).typ); linef_532700_839829468(p0, ((Tcprocsection529011) 2), ((NimStringDesc*) &T839829468_526), LOC26, 4); } goto LA21; LA23: ; { TY532811 LOC28; initlocexpr_539283_839829468(p0, (*e0).kindU.S6.sons->data[i_557537_839829468], (&a0)); memset((void*)LOC28, 0, sizeof(LOC28)); LOC28[0] = rdloc_538188_839829468((*d0)); LOC28[1] = rdsetelemloc_555662_839829468(a0, (*e0).typ); linef_532700_839829468(p0, ((Tcprocsection529011) 2), ((NimStringDesc*) &T839829468_527), LOC28, 2); } LA21: ; res_557606_839829468 += ((NI) 1); } LA20: ; } } } goto LA11; LA14: ; { NimStringDesc* ts0; NimStringDesc* LOC30; NI64 LOC31; NimStringDesc* LOC32; TY178507 LOC33; LOC30 = (NimStringDesc*)0; LOC31 = (NI64)0; LOC31 = getsize_320135_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_538188_839829468((*d0)); linef_532700_839829468(p0, ((Tcprocsection529011) 2), ((NimStringDesc*) &T839829468_494), LOC33, 1); { NI i_557575_839829468; NI HEX3Atmp_557611_839829468; NI LOC35; NI res_557614_839829468; i_557575_839829468 = (NI)0; HEX3Atmp_557611_839829468 = (NI)0; LOC35 = (NI)0; LOC35 = sonslen_295351_850551059(e0); HEX3Atmp_557611_839829468 = (NI)(LOC35 - ((NI) 1)); res_557614_839829468 = ((NI) 0); { while (1) { if (!(res_557614_839829468 <= HEX3Atmp_557611_839829468)) goto LA37; i_557575_839829468 = res_557614_839829468; { Ttype292840* LOC42; NimStringDesc* LOC43; TY535235 LOC44; if (!((*(*e0).kindU.S6.sons->data[i_557575_839829468]).kind == ((Tnodekind292020) 44))) goto LA40; LOC42 = (Ttype292840*)0; LOC42 = getsystype_338150_3937434831(((Ttypekind292244) 31)); gettemp_537032_839829468(p0, LOC42, (&idx0), NIM_FALSE); initlocexpr_539283_839829468(p0, (*(*e0).kindU.S6.sons->data[i_557575_839829468]).kindU.S6.sons->data[((NI) 0)], (&a0)); initlocexpr_539283_839829468(p0, (*(*e0).kindU.S6.sons->data[i_557575_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_538188_839829468(idx0); LOC44[1] = rdloc_538188_839829468((*d0)); LOC44[2] = rdsetelemloc_555662_839829468(a0, (*e0).typ); LOC44[3] = rdsetelemloc_555662_839829468(b0, (*e0).typ); linef_532700_839829468(p0, ((Tcprocsection529011) 2), LOC43, LOC44, 4); } goto LA38; LA40: ; { NimStringDesc* LOC46; TY532811 LOC47; initlocexpr_539283_839829468(p0, (*e0).kindU.S6.sons->data[i_557575_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_538188_839829468((*d0)); LOC47[1] = rdsetelemloc_555662_839829468(a0, (*e0).typ); linef_532700_839829468(p0, ((Tcprocsection529011) 2), LOC46, LOC47, 2); } LA38: ; res_557614_839829468 += ((NI) 1); } LA37: ; } } } LA11: ; } LA1: ; } N_NIMCALL(void, exprcomplexconst_558684_839829468)(Tcproc529021* p0, Tnode292802* n0, Tloc292816* d0) { Ttype292840* t0; Ropeobj178006* LOC1; NI id0; Ropeobj178006* tmp0; Ropeobj178006* LOC2; t0 = getuniquetype_528640_2036603609((*n0).typ); LOC1 = (Ropeobj178006*)0; LOC1 = gettypedesc_535671_839829468((*p0).module, t0); id0 = nodetabletestorset_342682_1142335848((&(*(*p0).module).datacache), n0, ((NI) ((*(*p0).module).labels))); LOC2 = (Ropeobj178006*)0; LOC2 = rope_178401_2381377266(((NI64) (id0))); tmp0 = HEX26_178418_2381377266((*(*p0).module).tmpbase, LOC2); { TY535238 LOC7; if (!(id0 == ((NI) ((*(*p0).module).labels)))) goto LA5; (*(*p0).module).labels += ((NI) 1); memset((void*)LOC7, 0, sizeof(LOC7)); LOC7[0] = gettypedesc_535671_839829468((*p0).module, t0); LOC7[1] = tmp0; LOC7[2] = genconstexpr_554849_839829468(p0, n0); addf_179205_2381377266(&(*(*p0).module).s[(((Tcfilesection529005) 8))- 0], ((NimStringDesc*) &T839829468_272), LOC7, 3); } LA5: ; { if (!((*d0).k == ((Tlockind292808) 0))) goto LA10; fillloc_532282_839829468(d0, ((Tlockind292808) 8), t0, tmp0, ((Tstorageloc292812) 1)); } goto LA8; LA10: ; { putdataintodest_550436_839829468(p0, d0, t0, tmp0); { if (!!(((*t0).kind == ((Ttypekind292244) 24) || (*t0).kind == ((Ttypekind292244) 28)))) goto LA15; (*d0).s = ((Tstorageloc292812) 1); } LA15: ; } LA8: ; } N_NIMCALL(NIM_BOOL, handleconstexpr_554853_839829468)(Tcproc529021* p0, Tnode292802* n0, Tloc292816* d0) { NIM_BOOL result0; result0 = (NIM_BOOL)0; { NIM_BOOL LOC3; NIM_BOOL LOC4; NI LOC6; Ttype292840* t0; Ropeobj178006* LOC10; NI id0; Ropeobj178006* LOC11; Ropeobj178006* LOC12; LOC3 = (NIM_BOOL)0; LOC4 = (NIM_BOOL)0; LOC4 = ((*d0).k == ((Tlockind292808) 0)); if (!(LOC4)) goto LA5; LOC6 = (NI)0; LOC6 = len_293081_850551059(n0); LOC4 = (((NI) (((*n0).kind == ((Tnodekind292020) 38)))) < LOC6); LA5: ; LOC3 = LOC4; if (!(LOC3)) goto LA7; LOC3 = isdeepconstexpr_318566_2616423590(n0); LA7: ; if (!LOC3) goto LA8; t0 = getuniquetype_528640_2036603609((*n0).typ); LOC10 = (Ropeobj178006*)0; LOC10 = gettypedesc_535671_839829468((*p0).module, t0); id0 = nodetabletestorset_342682_1142335848((&(*(*p0).module).datacache), n0, ((NI) ((*(*p0).module).labels))); LOC11 = (Ropeobj178006*)0; LOC11 = rope_178401_2381377266(((NI64) (id0))); LOC12 = (Ropeobj178006*)0; LOC12 = HEX26_178418_2381377266((*(*p0).module).tmpbase, LOC11); fillloc_532282_839829468(d0, ((Tlockind292808) 8), t0, LOC12, ((Tstorageloc292812) 1)); { TY535238 LOC17; if (!(id0 == ((NI) ((*(*p0).module).labels)))) goto LA15; (*(*p0).module).labels += ((NI) 1); memset((void*)LOC17, 0, sizeof(LOC17)); LOC17[0] = gettypedesc_535671_839829468((*p0).module, t0); LOC17[1] = (*d0).r; LOC17[2] = genconstexpr_554849_839829468(p0, n0); addf_179205_2381377266(&(*(*p0).module).s[(((Tcfilesection529005) 8))- 0], ((NimStringDesc*) &T839829468_272), LOC17, 3); } LA15: ; result0 = NIM_TRUE; } goto LA1; LA8: ; { result0 = NIM_FALSE; } LA1: ; return result0; } N_NIMCALL(void, genarrayconstr_558207_839829468)(Tcproc529021* p0, Tnode292802* n0, Tloc292816* d0) { Tloc292816 arr0; memset((void*)(&arr0), 0, sizeof(arr0)); { NIM_BOOL LOC3; LOC3 = (NIM_BOOL)0; LOC3 = handleconstexpr_554853_839829468(p0, n0, d0); if (!!(LOC3)) goto LA4; { if (!((*d0).k == ((Tlockind292808) 0))) goto LA8; gettemp_537032_839829468(p0, (*n0).typ, d0, NIM_FALSE); } LA8: ; { NI i_558234_839829468; NI HEX3Atmp_558242_839829468; NI LOC11; NI res_558245_839829468; i_558234_839829468 = (NI)0; HEX3Atmp_558242_839829468 = (NI)0; LOC11 = (NI)0; LOC11 = sonslen_295351_850551059(n0); HEX3Atmp_558242_839829468 = (NI)(LOC11 - ((NI) 1)); res_558245_839829468 = ((NI) 0); { while (1) { Ttype292840* LOC14; Ttype292840* LOC15; TY532811 LOC16; if (!(res_558245_839829468 <= HEX3Atmp_558242_839829468)) goto LA13; i_558234_839829468 = res_558245_839829468; LOC14 = (Ttype292840*)0; LOC14 = skiptypes_296099_850551059((*n0).typ, IL64(211106232576256)); LOC15 = (Ttype292840*)0; LOC15 = elemtype_320394_3876443242(LOC14); initloc_532273_839829468((&arr0), ((Tlockind292808) 6), LOC15, (*d0).s); memset((void*)LOC16, 0, sizeof(LOC16)); LOC16[0] = rdloc_538188_839829468((*d0)); LOC16[1] = intliteral_539270_839829468(((NI64) (i_558234_839829468))); arr0.r = HEX25_178905_2381377266(((NimStringDesc*) &T839829468_138), LOC16, 2); expr_539248_839829468(p0, (*n0).kindU.S6.sons->data[i_558234_839829468], (&arr0)); res_558245_839829468 += ((NI) 1); } LA13: ; } } } LA4: ; } N_NIMCALL(void, gentupleconstr_557618_839829468)(Tcproc529021* p0, Tnode292802* n0, Tloc292816* d0) { Tloc292816 rec0; memset((void*)(&rec0), 0, sizeof(rec0)); { NIM_BOOL LOC3; Ttype292840* t0; Ropeobj178006* LOC6; LOC3 = (NIM_BOOL)0; LOC3 = handleconstexpr_554853_839829468(p0, n0, d0); if (!!(LOC3)) goto LA4; t0 = getuniquetype_528640_2036603609((*n0).typ); LOC6 = (Ropeobj178006*)0; LOC6 = gettypedesc_535671_839829468((*p0).module, t0); { if (!((*d0).k == ((Tlockind292808) 0))) goto LA9; gettemp_537032_839829468(p0, t0, d0, NIM_FALSE); } LA9: ; { NI i_557646_839829468; NI HEX3Atmp_557803_839829468; NI LOC12; NI res_557806_839829468; i_557646_839829468 = (NI)0; HEX3Atmp_557803_839829468 = (NI)0; LOC12 = (NI)0; LOC12 = sonslen_295351_850551059(n0); HEX3Atmp_557803_839829468 = (NI)(LOC12 - ((NI) 1)); res_557806_839829468 = ((NI) 0); { while (1) { Tnode292802* it0; TY532811 LOC19; if (!(res_557806_839829468 <= HEX3Atmp_557803_839829468)) goto LA14; i_557646_839829468 = res_557806_839829468; it0 = (*n0).kindU.S6.sons->data[i_557646_839829468]; { if (!((*it0).kind == ((Tnodekind292020) 34))) goto LA17; it0 = (*it0).kindU.S6.sons->data[((NI) 1)]; } LA17: ; initloc_532273_839829468((&rec0), ((Tlockind292808) 6), (*it0).typ, (*d0).s); memset((void*)LOC19, 0, sizeof(LOC19)); LOC19[0] = rdloc_538188_839829468((*d0)); LOC19[1] = rope_178401_2381377266(((NI64) (i_557646_839829468))); rec0.r = HEX25_178905_2381377266(((NimStringDesc*) &T839829468_185), LOC19, 2); expr_539248_839829468(p0, it0, (&rec0)); res_557806_839829468 += ((NI) 1); } LA14: ; } } } LA4: ; } N_NIMCALL(Tsym292834*, lookupfieldagain_553153_839829468)(Tcproc529021* p0, Ttype292840* ty_553156_839829468, Tsym292834* field0, Ropeobj178006** r0) { Tsym292834* result0; Ttype292840* ty0; result0 = (Tsym292834*)0; ty0 = ty_553156_839829468; { while (1) { if (!!((ty0 == NIM_NIL))) goto LA2; ty0 = skiptypes_296099_850551059(ty0, IL64(211106247215360)); result0 = lookupinrecord_299119_2984716966((*ty0).n, (*field0).name); { if (!!((result0 == NIM_NIL))) goto LA5; goto LA1; } LA5: ; { NIM_BOOL LOC9; LOC9 = (NIM_BOOL)0; LOC9 = (gcmd_169132_2607990831 == ((Tcommands169076) 2)); if (LOC9) goto LA10; LOC9 = (((*(*(*p0).module).module).flags &(1U<<((NU)(((Tsymflag292184) 27))&31U)))!=0); LA10: ; if (!!(LOC9)) goto LA11; add_178487_2381377266(r0, ((NimStringDesc*) &T839829468_153)); } LA11: ; ty0 = getuniquetype_528640_2036603609((*ty0).sons->data[((NI) 0)]); } LA2: ; } LA1: ; { if (!(result0 == NIM_NIL)) goto LA15; internalerror_196100_155036129((*field0).info, ((NimStringDesc*) &T839829468_532)); } LA15: ; return result0; } N_NIMCALL(void, genfieldcheck_553504_839829468)(Tcproc529021* p0, Tnode292802* e0, Ropeobj178006* obj0, Tsym292834* field0, Ttype292840* origty0) { Tloc292816 test0; Tloc292816 u0; Tloc292816 v0; memset((void*)(&test0), 0, sizeof(test0)); memset((void*)(&u0), 0, sizeof(u0)); memset((void*)(&v0), 0, sizeof(v0)); { NI i_553525_839829468; NI HEX3Atmp_554039_839829468; NI LOC2; NI res_554042_839829468; i_553525_839829468 = (NI)0; HEX3Atmp_554039_839829468 = (NI)0; LOC2 = (NI)0; LOC2 = sonslen_295351_850551059(e0); HEX3Atmp_554039_839829468 = (NI)(LOC2 - ((NI) 1)); res_554042_839829468 = ((NI) 1); { while (1) { Tnode292802* it0; Tsym292834* op0; Tnode292802* disc0; Ropeobj178006* o0; Tsym292834* d0; NI id0; Tnode292802* LOC9; Ropeobj178006* strlit0; if (!(res_554042_839829468 <= HEX3Atmp_554039_839829468)) goto LA4; i_553525_839829468 = res_554042_839829468; it0 = (*e0).kindU.S6.sons->data[i_553525_839829468]; op0 = (*(*it0).kindU.S6.sons->data[((NI) 0)]).kindU.S4.sym; { if (!((*op0).magic == ((Tmagic292524) 99))) goto LA7; it0 = (*it0).kindU.S6.sons->data[((NI) 1)]; } LA7: ; disc0 = skipconv_328882_3876443242((*it0).kindU.S6.sons->data[((NI) 2)]); initloc_532273_839829468((&test0), ((Tlockind292808) 0), (*it0).typ, ((Tstorageloc292812) 2)); initlocexpr_539283_839829468(p0, (*it0).kindU.S6.sons->data[((NI) 1)], (&u0)); o0 = obj0; d0 = lookupfieldagain_553153_839829468(p0, origty0, (*disc0).kindU.S4.sym, &o0); initloc_532273_839829468((&v0), ((Tlockind292808) 6), (*d0).typ, ((Tstorageloc292812) 0)); v0.r = o0; add_178487_2381377266(&v0.r, ((NimStringDesc*) &T839829468_257)); add_178482_2381377266(&v0.r, (*d0).loc.r); geninexpraux_553496_839829468(p0, it0, (&u0), (&v0), (&test0)); LOC9 = (Tnode292802*)0; LOC9 = newstrnode_293678_850551059(((Tnodekind292020) 20), (*(*field0).name).s); id0 = nodetabletestorset_342682_1142335848((&(*(*p0).module).datacache), LOC9, ((NI) ((*(*p0).module).labels))); { if (!(id0 == ((NI) ((*(*p0).module).labels)))) goto LA12; strlit0 = getstrlit_549468_839829468((*p0).module, (*(*field0).name).s); } goto LA10; LA12: ; { Ropeobj178006* LOC15; LOC15 = (Ropeobj178006*)0; LOC15 = rope_178401_2381377266(((NI64) (id0))); strlit0 = HEX26_178418_2381377266((*(*p0).module).tmpbase, LOC15); } LA10: ; { TY532811 LOC20; if (!((*op0).magic == ((Tmagic292524) 99))) goto LA18; memset((void*)LOC20, 0, sizeof(LOC20)); LOC20[0] = rdloc_538188_839829468(test0); LOC20[1] = strlit0; linefmt_532714_839829468(p0, ((Tcprocsection529011) 2), ((NimStringDesc*) &T839829468_534), LOC20, 2); } goto LA16; LA18: ; { TY532811 LOC22; memset((void*)LOC22, 0, sizeof(LOC22)); LOC22[0] = rdloc_538188_839829468(test0); LOC22[1] = strlit0; linefmt_532714_839829468(p0, ((Tcprocsection529011) 2), ((NimStringDesc*) &T839829468_535), LOC22, 2); } LA16: ; res_554042_839829468 += ((NI) 1); } LA4: ; } } } N_NIMCALL(void, genobjconstr_554903_839829468)(Tcproc529021* p0, Tnode292802* e0, Tloc292816* d0) { Tloc292816 tmp0; Ttype292840* t0; NIM_BOOL isref0; Ropeobj178006* r0; Ropeobj178006* LOC13; Ttype292840* ty0; { { NIM_BOOL LOC3; LOC3 = (NIM_BOOL)0; LOC3 = handleconstexpr_554853_839829468(p0, e0, d0); if (!LOC3) goto LA4; goto BeforeRet; } LA4: ; memset((void*)(&tmp0), 0, sizeof(tmp0)); t0 = skiptypes_296099_850551059((*e0).typ, IL64(211106232576256)); gettemp_537032_839829468(p0, t0, (&tmp0), NIM_FALSE); isref0 = ((*t0).kind == ((Ttypekind292244) 22)); r0 = rdloc_538188_839829468(tmp0); { Ttype292840* LOC10; TY178507 LOC11; if (!isref0) goto LA8; rawgennew_554741_839829468(p0, tmp0, NIM_NIL); LOC10 = (Ttype292840*)0; LOC10 = lastson_295377_850551059(t0); t0 = skiptypes_296099_850551059(LOC10, IL64(211106232576256)); memset((void*)LOC11, 0, sizeof(LOC11)); LOC11[0] = r0; r0 = HEX25_178905_2381377266(((NimStringDesc*) &T839829468_124), LOC11, 1); gcusage_554439_839829468(e0); } goto LA6; LA8: ; { constructloc_538388_839829468(p0, tmp0, NIM_FALSE); } LA6: ; LOC13 = (Ropeobj178006*)0; LOC13 = gettypedesc_535671_839829468((*p0).module, t0); ty0 = getuniquetype_528640_2036603609(t0); { NI i_554944_839829468; NI HEX3Atmp_554997_839829468; NI LOC15; NI res_555000_839829468; i_554944_839829468 = (NI)0; HEX3Atmp_554997_839829468 = (NI)0; LOC15 = (NI)0; LOC15 = len_293081_850551059(e0); HEX3Atmp_554997_839829468 = (LOC15 - 1); res_555000_839829468 = ((NI) 1); { while (1) { Tnode292802* it0; Tloc292816 tmp20; Tsym292834* field0; if (!(res_555000_839829468 <= HEX3Atmp_554997_839829468)) goto LA17; i_554944_839829468 = res_555000_839829468; it0 = (*e0).kindU.S6.sons->data[i_554944_839829468]; memset((void*)(&tmp20), 0, sizeof(tmp20)); tmp20.r = r0; field0 = lookupfieldagain_553153_839829468(p0, ty0, (*(*it0).kindU.S6.sons->data[((NI) 0)]).kindU.S4.sym, &tmp20.r); { if (!((*field0).loc.r == NIM_NIL)) goto LA20; internalerror_196100_155036129((*e0).info, ((NimStringDesc*) &T839829468_533)); } LA20: ; { NIM_BOOL LOC24; NI LOC25; LOC24 = (NIM_BOOL)0; LOC25 = (NI)0; LOC25 = len_293081_850551059(it0); LOC24 = (LOC25 == ((NI) 3)); if (!(LOC24)) goto LA26; LOC24 = (((*p0).options &(1U<<((NU)(((Toption169009) 2))&31U)))!=0); LA26: ; if (!LOC24) goto LA27; genfieldcheck_553504_839829468(p0, (*it0).kindU.S6.sons->data[((NI) 2)], r0, field0, ty0); } LA27: ; add_178487_2381377266(&tmp20.r, ((NimStringDesc*) &T839829468_257)); add_178482_2381377266(&tmp20.r, (*field0).loc.r); tmp20.k = ((Tlockind292808) 1); tmp20.t = (*field0).loc.t; { if (!isref0) goto LA31; tmp20.s = ((Tstorageloc292812) 3); } goto LA29; LA31: ; { tmp20.s = ((Tstorageloc292812) 2); } LA29: ; expr_539248_839829468(p0, (*it0).kindU.S6.sons->data[((NI) 1)], (&tmp20)); res_555000_839829468 += ((NI) 1); } LA17: ; } } { if (!((*d0).k == ((Tlockind292808) 0))) goto LA36; genericAssign((void*)(&(*d0)), (void*)(&tmp0), (&NTI292816)); } goto LA34; LA36: ; { genassignment_539264_839829468(p0, (*d0), tmp0, 0); } LA34: ; }BeforeRet: ; } N_NIMCALL(void, gencast_556537_839829468)(Tcproc529021* p0, Tnode292802* e0, Tloc292816* d0) { Ttype292840* destt0; Ttype292840* srct0; destt0 = skiptypes_296099_850551059((*e0).typ, IL64(211106233624832)); srct0 = skiptypes_296099_850551059((*(*e0).kindU.S6.sons->data[((NI) 1)]).typ, IL64(211106233624832)); { NIM_BOOL LOC3; Ropeobj178006* lbl0; Tloc292816 tmp0; TY178507 LOC7; TY535238 LOC8; TY178507 LOC9; Ropeobj178006* LOC10; LOC3 = (NIM_BOOL)0; LOC3 = ((*destt0).kind >= ((Ttypekind292244) 36) && (*destt0).kind <= ((Ttypekind292244) 39) || (*destt0).kind == ((Ttypekind292244) 18) || (*destt0).kind == ((Ttypekind292244) 17) || (*destt0).kind == ((Ttypekind292244) 16) || (*destt0).kind == ((Ttypekind292244) 4)); if (LOC3) goto LA4; LOC3 = ((*srct0).kind >= ((Ttypekind292244) 36) && (*srct0).kind <= ((Ttypekind292244) 39) || (*srct0).kind == ((Ttypekind292244) 18) || (*srct0).kind == ((Ttypekind292244) 17) || (*srct0).kind == ((Ttypekind292244) 16) || (*srct0).kind == ((Ttypekind292244) 4)); LA4: ; if (!LOC3) goto LA5; (*p0).labels += ((NI) 1); lbl0 = rope_178401_2381377266(((NI64) ((*p0).labels))); memset((void*)(&tmp0), 0, sizeof(tmp0)); memset((void*)LOC7, 0, sizeof(LOC7)); LOC7[0] = lbl0; tmp0.r = HEX25_178905_2381377266(((NimStringDesc*) &T839829468_536), LOC7, 1); memset((void*)LOC8, 0, sizeof(LOC8)); LOC8[0] = gettypedesc_535671_839829468((*p0).module, srct0); LOC8[1] = gettypedesc_535671_839829468((*p0).module, destt0); LOC8[2] = lbl0; linefmt_532714_839829468(p0, ((Tcprocsection529011) 0), ((NimStringDesc*) &T839829468_537), LOC8, 3); tmp0.k = ((Tlockind292808) 6); tmp0.t = srct0; tmp0.s = ((Tstorageloc292812) 2); tmp0.flags = 0; expr_539248_839829468(p0, (*e0).kindU.S6.sons->data[((NI) 1)], (&tmp0)); memset((void*)LOC9, 0, sizeof(LOC9)); LOC9[0] = lbl0; LOC10 = (Ropeobj178006*)0; LOC10 = HEX25_178905_2381377266(((NimStringDesc*) &T839829468_538), LOC9, 1); putintodest_550468_839829468(p0, d0, (*e0).typ, LOC10, tmp0.s); } goto LA1; LA5: ; { gensomecast_556480_839829468(p0, e0, d0); } LA1: ; } N_NIMCALL(void, genconv_556632_839829468)(Tcproc529021* p0, Tnode292802* e0, Tloc292816* d0) { Ttype292840* desttype0; desttype0 = skiptypes_296099_850551059((*e0).typ, 8390656); { NIM_BOOL LOC3; LOC3 = (NIM_BOOL)0; LOC3 = comparetypes_326214_3876443242(desttype0, (*(*e0).kindU.S6.sons->data[((NI) 1)]).typ, ((Tdistinctcompare324427) 1), 0); if (!LOC3) goto LA4; expr_539248_839829468(p0, (*e0).kindU.S6.sons->data[((NI) 1)], d0); } goto LA1; LA4: ; { gensomecast_556480_839829468(p0, e0, d0); } LA1: ; } static N_INLINE(NIM_BOOL, iscppref_552807_839829468)(Tcproc529021* p0, Ttype292840* typ0) { NIM_BOOL result0; NIM_BOOL LOC1; NIM_BOOL LOC2; NIM_BOOL LOC3; Ttype292840* LOC6; Ttype292840* LOC8; result0 = (NIM_BOOL)0; LOC1 = (NIM_BOOL)0; LOC2 = (NIM_BOOL)0; LOC3 = (NIM_BOOL)0; LOC3 = (gcmd_169132_2607990831 == ((Tcommands169076) 2)); if (LOC3) goto LA4; LOC3 = (((*(*(*p0).module).module).flags &(1U<<((NU)(((Tsymflag292184) 27))&31U)))!=0); LA4: ; LOC2 = LOC3; if (!(LOC2)) goto LA5; LOC6 = (Ttype292840*)0; LOC6 = skiptypes_296099_850551059(typ0, IL64(211106232576256)); LOC2 = ((*LOC6).kind == ((Ttypekind292244) 23)); LA5: ; LOC1 = LOC2; if (!(LOC1)) goto LA7; LOC8 = (Ttype292840*)0; LOC8 = skiptypes_296099_850551059(typ0, IL64(211106232576256)); LOC1 = !((((*LOC8).flags &(1U<<((NU)(((Ttypeflag292431) 18))&31U)))!=0)); LA7: ; result0 = LOC1; return result0; } N_NIMCALL(void, genaddr_553051_839829468)(Tcproc529021* p0, Tnode292802* e0, Tloc292816* d0) { { Ttype292840* LOC3; Tloc292816 a0; Ropeobj178006* LOC6; LOC3 = (Ttype292840*)0; LOC3 = skiptypes_296099_850551059((*(*e0).kindU.S6.sons->data[((NI) 0)]).typ, IL64(211106232576256)); if (!((*LOC3).kind == ((Ttypekind292244) 22) || (*LOC3).kind == ((Ttypekind292244) 21))) goto LA4; memset((void*)(&a0), 0, sizeof(a0)); initlocexpr_539283_839829468(p0, (*e0).kindU.S6.sons->data[((NI) 0)], (&a0)); LOC6 = (Ropeobj178006*)0; LOC6 = HEX26_178452_2381377266(((NimStringDesc*) &T839829468_52), a0.r); putintodest_550468_839829468(p0, d0, (*e0).typ, LOC6, a0.s); } goto LA1; LA4: ; { NIM_BOOL LOC8; Tctypekind529007 LOC9; LOC8 = (NIM_BOOL)0; LOC9 = (Tctypekind529007)0; LOC9 = maptype_533393_839829468((*(*e0).kindU.S6.sons->data[((NI) 0)]).typ); LOC8 = (LOC9 == ((Tctypekind529007) 17)); if (LOC8) goto LA10; LOC8 = iscppref_552807_839829468(p0, (*(*e0).kindU.S6.sons->data[((NI) 0)]).typ); LA10: ; if (!LOC8) goto LA11; expr_539248_839829468(p0, (*e0).kindU.S6.sons->data[((NI) 0)], d0); } goto LA1; LA11: ; { Tloc292816 a0; Ropeobj178006* LOC14; memset((void*)(&a0), 0, sizeof(a0)); initlocexpr_539283_839829468(p0, (*e0).kindU.S6.sons->data[((NI) 0)], (&a0)); LOC14 = (Ropeobj178006*)0; LOC14 = addrloc_538204_839829468(a0); putintodest_550468_839829468(p0, d0, (*e0).typ, LOC14, a0.s); } LA1: ; } N_NIMCALL(void, genarrayelem_554093_839829468)(Tcproc529021* p0, Tnode292802* x0, Tnode292802* y0, Tloc292816* d0) { Tloc292816 a0; Tloc292816 b0; Ttype292840* ty0; Ttype292840* LOC1; Ropeobj178006* first0; NI64 LOC2; Ttype292840* LOC47; Ttype292840* LOC48; TY535238 LOC49; Ropeobj178006* LOC50; memset((void*)(&a0), 0, sizeof(a0)); memset((void*)(&b0), 0, sizeof(b0)); initlocexpr_539283_839829468(p0, x0, (&a0)); initlocexpr_539283_839829468(p0, y0, (&b0)); LOC1 = (Ttype292840*)0; LOC1 = skiptypes_296099_850551059(a0.t, IL64(211106242013440)); ty0 = skiptypes_296099_850551059(LOC1, IL64(211106247256320)); LOC2 = (NI64)0; LOC2 = firstord_320001_3876443242(ty0); first0 = intliteral_539270_839829468(LOC2); { NIM_BOOL LOC5; LOC5 = (NIM_BOOL)0; LOC5 = (((*p0).options &(1U<<((NU)(((Toption169009) 4))&31U)))!=0); if (!(LOC5)) goto LA6; LOC5 = !((((*ty0).flags &(1U<<((NU)(((Ttypeflag292431) 0))&31U)))!=0)); LA6: ; if (!LOC5) goto LA7; { NIM_BOOL LOC11; LOC11 = (NIM_BOOL)0; LOC11 = isconstexpr_318510_2616423590(y0); if (!!(LOC11)) goto LA12; { NI64 LOC16; LOC16 = (NI64)0; LOC16 = firstord_320001_3876443242(ty0); if (!(LOC16 == IL64(0))) goto LA17; { NIM_BOOL LOC21; NI64 LOC22; NI64 LOC23; NI64 LOC25; NI64 LOC26; TY532811 LOC29; NI64 LOC30; LOC21 = (NIM_BOOL)0; LOC22 = (NI64)0; LOC22 = firstord_320001_3876443242(b0.t); LOC23 = (NI64)0; LOC23 = firstord_320001_3876443242(ty0); LOC21 = (LOC22 < LOC23); if (LOC21) goto LA24; LOC25 = (NI64)0; LOC25 = lastord_320004_3876443242(ty0); LOC26 = (NI64)0; LOC26 = lastord_320004_3876443242(b0.t); LOC21 = (LOC25 < LOC26); LA24: ; if (!LOC21) goto LA27; memset((void*)LOC29, 0, sizeof(LOC29)); LOC29[0] = rdcharloc_538227_839829468(b0); LOC30 = (NI64)0; LOC30 = lastord_320004_3876443242(ty0); LOC29[1] = intliteral_539270_839829468(LOC30); linefmt_532714_839829468(p0, ((Tcprocsection529011) 2), ((NimStringDesc*) &T839829468_539), LOC29, 2); } LA27: ; } goto LA14; LA17: ; { TY535238 LOC32; NI64 LOC33; memset((void*)LOC32, 0, sizeof(LOC32)); LOC32[0] = rdcharloc_538227_839829468(b0); LOC32[1] = first0; LOC33 = (NI64)0; LOC33 = lastord_320004_3876443242(ty0); LOC32[2] = intliteral_539270_839829468(LOC33); linefmt_532714_839829468(p0, ((Tcprocsection529011) 2), ((NimStringDesc*) &T839829468_540), LOC32, 3); } LA14: ; } goto LA9; LA12: ; { NI64 idx0; idx0 = getordvalue_320129_3876443242(y0); { NIM_BOOL LOC37; NI64 LOC38; NI64 LOC40; LOC37 = (NIM_BOOL)0; LOC38 = (NI64)0; LOC38 = firstord_320001_3876443242(ty0); LOC37 = (idx0 < LOC38); if (LOC37) goto LA39; LOC40 = (NI64)0; LOC40 = lastord_320004_3876443242(ty0); LOC37 = (LOC40 < idx0); LA39: ; if (!LOC37) goto LA41; localerror_196080_155036129((*x0).info, ((Tmsgkind191002) 86), ((NimStringDesc*) &T839829468_490)); } LA41: ; } LA9: ; } LA7: ; { if (!((*d0).k == ((Tlockind292808) 0))) goto LA45; (*d0).s = a0.s; } LA45: ; LOC47 = (Ttype292840*)0; LOC47 = skiptypes_296099_850551059(ty0, IL64(211106240964864)); LOC48 = (Ttype292840*)0; LOC48 = elemtype_320394_3876443242(LOC47); memset((void*)LOC49, 0, sizeof(LOC49)); LOC49[0] = rdloc_538188_839829468(a0); LOC49[1] = rdcharloc_538227_839829468(b0); LOC49[2] = first0; LOC50 = (Ropeobj178006*)0; LOC50 = ropecg_532407_839829468(NIM_NIL, ((NimStringDesc*) &T839829468_541), LOC49, 3); putintodest_550468_839829468(p0, d0, LOC48, LOC50, a0.s); } N_NIMCALL(void, genopenarrayelem_554169_839829468)(Tcproc529021* p0, Tnode292802* x0, Tnode292802* y0, Tloc292816* d0) { Tloc292816 a0; Tloc292816 b0; Ttype292840* LOC10; Ttype292840* LOC11; TY532811 LOC12; Ropeobj178006* LOC13; memset((void*)(&a0), 0, sizeof(a0)); memset((void*)(&b0), 0, sizeof(b0)); initlocexpr_539283_839829468(p0, x0, (&a0)); initlocexpr_539283_839829468(p0, y0, (&b0)); { TY532811 LOC5; if (!(((*p0).options &(1U<<((NU)(((Toption169009) 4))&31U)))!=0)) goto LA3; memset((void*)LOC5, 0, sizeof(LOC5)); LOC5[0] = rdloc_538188_839829468(b0); LOC5[1] = rdloc_538188_839829468(a0); linefmt_532714_839829468(p0, ((Tcprocsection529011) 2), ((NimStringDesc*) &T839829468_542), LOC5, 2); } LA3: ; { if (!((*d0).k == ((Tlockind292808) 0))) goto LA8; (*d0).s = a0.s; } LA8: ; LOC10 = (Ttype292840*)0; LOC10 = skiptypes_296099_850551059(a0.t, IL64(211106240964864)); LOC11 = (Ttype292840*)0; LOC11 = elemtype_320394_3876443242(LOC10); memset((void*)LOC12, 0, sizeof(LOC12)); LOC12[0] = rdloc_538188_839829468(a0); LOC12[1] = rdcharloc_538227_839829468(b0); LOC13 = (Ropeobj178006*)0; LOC13 = ropecg_532407_839829468(NIM_NIL, ((NimStringDesc*) &T839829468_138), LOC12, 2); putintodest_550468_839829468(p0, d0, LOC11, LOC13, a0.s); } N_NIMCALL(void, genseqelem_554205_839829468)(Tcproc529021* p0, Tnode292802* x0, Tnode292802* y0, Tloc292816* d0) { Tloc292816 a0; Tloc292816 b0; Ttype292840* ty0; Ttype292840* LOC27; Ttype292840* LOC28; TY532811 LOC29; Ropeobj178006* LOC30; memset((void*)(&a0), 0, sizeof(a0)); memset((void*)(&b0), 0, sizeof(b0)); initlocexpr_539283_839829468(p0, x0, (&a0)); initlocexpr_539283_839829468(p0, y0, (&b0)); ty0 = skiptypes_296099_850551059(a0.t, IL64(211106242013440)); { Ttype292840* LOC5; if (!((*ty0).kind == ((Ttypekind292244) 22) || (*ty0).kind == ((Ttypekind292244) 21))) goto LA3; LOC5 = (Ttype292840*)0; LOC5 = lastson_295377_850551059(ty0); ty0 = skiptypes_296099_850551059(LOC5, IL64(211106242013440)); } LA3: ; { if (!(((*p0).options &(1U<<((NU)(((Toption169009) 4))&31U)))!=0)) goto LA8; { TY535238 LOC14; if (!((*ty0).kind == ((Ttypekind292244) 28))) goto LA12; memset((void*)LOC14, 0, sizeof(LOC14)); LOC14[0] = rdloc_538188_839829468(b0); LOC14[1] = rdloc_538188_839829468(a0); LOC14[2] = lenfield_539305_839829468(p0); linefmt_532714_839829468(p0, ((Tcprocsection529011) 2), ((NimStringDesc*) &T839829468_543), LOC14, 3); } goto LA10; LA12: ; { TY535238 LOC16; memset((void*)LOC16, 0, sizeof(LOC16)); LOC16[0] = rdloc_538188_839829468(b0); LOC16[1] = rdloc_538188_839829468(a0); LOC16[2] = lenfield_539305_839829468(p0); linefmt_532714_839829468(p0, ((Tcprocsection529011) 2), ((NimStringDesc*) &T839829468_544), LOC16, 3); } LA10: ; } LA8: ; { if (!((*d0).k == ((Tlockind292808) 0))) goto LA19; (*d0).s = ((Tstorageloc292812) 3); } LA19: ; { Ttype292840* LOC23; TY178507 LOC26; LOC23 = (Ttype292840*)0; LOC23 = skiptypes_296099_850551059(a0.t, IL64(211106240964864)); if (!((*LOC23).kind == ((Ttypekind292244) 22) || (*LOC23).kind == ((Ttypekind292244) 21))) goto LA24; memset((void*)LOC26, 0, sizeof(LOC26)); LOC26[0] = a0.r; a0.r = ropecg_532407_839829468(NIM_NIL, ((NimStringDesc*) &T839829468_124), LOC26, 1); } LA24: ; LOC27 = (Ttype292840*)0; LOC27 = skiptypes_296099_850551059(a0.t, IL64(211106240964864)); LOC28 = (Ttype292840*)0; LOC28 = elemtype_320394_3876443242(LOC27); memset((void*)LOC29, 0, sizeof(LOC29)); LOC29[0] = rdloc_538188_839829468(a0); LOC29[1] = rdcharloc_538227_839829468(b0); LOC30 = (Ropeobj178006*)0; LOC30 = ropecg_532407_839829468(NIM_NIL, ((NimStringDesc*) &T839829468_187), LOC29, 2); putintodest_550468_839829468(p0, d0, LOC28, LOC30, a0.s); } N_NIMCALL(void, gencstringelem_554144_839829468)(Tcproc529021* p0, Tnode292802* x0, Tnode292802* y0, Tloc292816* d0) { Tloc292816 a0; Tloc292816 b0; Ttype292840* ty0; Ttype292840* LOC5; Ttype292840* LOC6; TY532811 LOC7; Ropeobj178006* LOC8; memset((void*)(&a0), 0, sizeof(a0)); memset((void*)(&b0), 0, sizeof(b0)); initlocexpr_539283_839829468(p0, x0, (&a0)); initlocexpr_539283_839829468(p0, y0, (&b0)); ty0 = skiptypes_296099_850551059(a0.t, IL64(211106242013440)); { if (!((*d0).k == ((Tlockind292808) 0))) goto LA3; (*d0).s = a0.s; } LA3: ; LOC5 = (Ttype292840*)0; LOC5 = skiptypes_296099_850551059(ty0, IL64(211106240964864)); LOC6 = (Ttype292840*)0; LOC6 = elemtype_320394_3876443242(LOC5); memset((void*)LOC7, 0, sizeof(LOC7)); LOC7[0] = rdloc_538188_839829468(a0); LOC7[1] = rdcharloc_538227_839829468(b0); LOC8 = (Ropeobj178006*)0; LOC8 = ropecg_532407_839829468(NIM_NIL, ((NimStringDesc*) &T839829468_138), LOC7, 2); putintodest_550468_839829468(p0, d0, LOC6, LOC8, a0.s); } N_NIMCALL(void, gentupleelem_553124_839829468)(Tcproc529021* p0, Tnode292802* e0, Tloc292816* d0) { Tloc292816 a0; NI i0; Ropeobj178006* LOC5; Ttype292840* ty0; Ropeobj178006* r0; TY178507 LOC8; memset((void*)(&a0), 0, sizeof(a0)); i0 = (NI)0; initlocexpr_539283_839829468(p0, (*e0).kindU.S6.sons->data[((NI) 0)], (&a0)); { if (!((*d0).k == ((Tlockind292808) 0))) goto LA3; (*d0).s = a0.s; } LA3: ; LOC5 = (Ropeobj178006*)0; LOC5 = gettypedesc_535671_839829468((*p0).module, a0.t); ty0 = getuniquetype_528640_2036603609(a0.t); r0 = rdloc_538188_839829468(a0); switch ((*(*e0).kindU.S6.sons->data[((NI) 1)]).kind) { case ((Tnodekind292020) 6) ... ((Tnodekind292020) 15): { i0 = ((NI) ((*(*e0).kindU.S6.sons->data[((NI) 1)]).kindU.S1.intval)); } break; default: { internalerror_196100_155036129((*e0).info, ((NimStringDesc*) &T839829468_545)); } break; } memset((void*)LOC8, 0, sizeof(LOC8)); LOC8[0] = rope_178401_2381377266(((NI64) (i0))); addf_179205_2381377266(&r0, ((NimStringDesc*) &T839829468_546), LOC8, 1); putintodest_550468_839829468(p0, d0, (*ty0).sons->data[i0], r0, a0.s); } N_NIMCALL(void, genbracketexpr_554277_839829468)(Tcproc529021* p0, Tnode292802* n0, Tloc292816* d0) { Ttype292840* ty0; ty0 = skiptypes_296099_850551059((*(*n0).kindU.S6.sons->data[((NI) 0)]).typ, IL64(211106242013440)); { Ttype292840* LOC5; if (!((*ty0).kind == ((Ttypekind292244) 22) || (*ty0).kind == ((Ttypekind292244) 21))) goto LA3; LOC5 = (Ttype292840*)0; LOC5 = lastson_295377_850551059(ty0); ty0 = skiptypes_296099_850551059(LOC5, IL64(211106242013440)); } LA3: ; switch ((*ty0).kind) { case ((Ttypekind292244) 16): case ((Ttypekind292244) 4): { genarrayelem_554093_839829468(p0, (*n0).kindU.S6.sons->data[((NI) 0)], (*n0).kindU.S6.sons->data[((NI) 1)], d0); } break; case ((Ttypekind292244) 27): case ((Ttypekind292244) 48): { genopenarrayelem_554169_839829468(p0, (*n0).kindU.S6.sons->data[((NI) 0)], (*n0).kindU.S6.sons->data[((NI) 1)], d0); } break; case ((Ttypekind292244) 24): case ((Ttypekind292244) 28): { genseqelem_554205_839829468(p0, (*n0).kindU.S6.sons->data[((NI) 0)], (*n0).kindU.S6.sons->data[((NI) 1)], d0); } break; case ((Ttypekind292244) 29): { gencstringelem_554144_839829468(p0, (*n0).kindU.S6.sons->data[((NI) 0)], (*n0).kindU.S6.sons->data[((NI) 1)], d0); } break; case ((Ttypekind292244) 18): { gentupleelem_553124_839829468(p0, n0, d0); } break; default: { NimStringDesc* LOC12; LOC12 = (NimStringDesc*)0; LOC12 = rawNewString(reprEnum((NI)(*ty0).kind, (&NTI292244))->Sup.len + 21); appendString(LOC12, ((NimStringDesc*) &T839829468_547)); appendString(LOC12, reprEnum((NI)(*ty0).kind, (&NTI292244))); appendChar(LOC12, 41); internalerror_196100_155036129((*n0).info, LOC12); } break; } } N_NIMCALL(void, genderef_543921_839829468)(Tcproc529021* p0, Tnode292802* e0, Tloc292816* d0, NIM_BOOL enforcederef0) { Tctypekind529007 mt0; { mt0 = maptype_533393_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_539248_839829468(p0, (*e0).kindU.S6.sons->data[((NI) 0)], d0); { Ttype292840* LOC9; LOC9 = (Ttype292840*)0; LOC9 = skiptypes_296099_850551059((*(*e0).kindU.S6.sons->data[((NI) 0)]).typ, IL64(211106232576256)); if (!((*LOC9).kind == ((Ttypekind292244) 22))) goto LA10; (*d0).s = ((Tstorageloc292812) 3); } LA10: ; } goto LA1; LA5: ; { Tloc292816 a0; Ttype292840* typ0; memset((void*)(&a0), 0, sizeof(a0)); typ0 = skiptypes_296099_850551059((*(*e0).kindU.S6.sons->data[((NI) 0)]).typ, IL64(211106232576256)); { NIM_BOOL LOC15; NIM_BOOL LOC16; NIM_BOOL LOC17; NIM_BOOL LOC20; Tnode292802* LOC25; Tnode292802* LOC26; LOC15 = (NIM_BOOL)0; LOC16 = (NIM_BOOL)0; LOC17 = (NIM_BOOL)0; LOC17 = ((*typ0).kind == ((Ttypekind292244) 23)); if (!(LOC17)) goto LA18; LOC17 = !((((*typ0).flags &(1U<<((NU)(((Ttypeflag292431) 18))&31U)))!=0)); LA18: ; LOC16 = LOC17; if (!(LOC16)) goto LA19; LOC20 = (NIM_BOOL)0; LOC20 = (gcmd_169132_2607990831 == ((Tcommands169076) 2)); if (LOC20) goto LA21; LOC20 = (((*(*(*p0).module).module).flags &(1U<<((NU)(((Tsymflag292184) 27))&31U)))!=0); LA21: ; LOC16 = LOC20; LA19: ; LOC15 = LOC16; if (!(LOC15)) goto LA22; LOC15 = ((*(*e0).kindU.S6.sons->data[((NI) 0)]).kind == ((Tnodekind292020) 64)); LA22: ; if (!LOC15) goto LA23; LOC25 = (Tnode292802*)0; LOC25 = HEX5BHEX5D_293238_850551059(e0, ((NI) 0)); LOC26 = (Tnode292802*)0; LOC26 = HEX5BHEX5D_293238_850551059(LOC25, ((NI) 0)); initlocexprsingleuse_539289_839829468(p0, LOC26, d0); goto BeforeRet; } goto LA13; LA23: ; { initlocexprsingleuse_539289_839829468(p0, (*e0).kindU.S6.sons->data[((NI) 0)], (&a0)); } LA13: ; { if (!((*d0).k == ((Tlockind292808) 0))) goto LA30; switch ((*typ0).kind) { case ((Ttypekind292244) 22): { (*d0).s = ((Tstorageloc292812) 3); } break; case ((Ttypekind292244) 23): { (*d0).s = ((Tstorageloc292812) 0); { NIM_BOOL LOC36; NIM_BOOL LOC37; NIM_BOOL LOC39; Ropeobj178006* LOC44; LOC36 = (NIM_BOOL)0; LOC37 = (NIM_BOOL)0; LOC37 = !((((*typ0).flags &(1U<<((NU)(((Ttypeflag292431) 18))&31U)))!=0)); if (!(LOC37)) goto LA38; LOC39 = (NIM_BOOL)0; LOC39 = (gcmd_169132_2607990831 == ((Tcommands169076) 2)); if (LOC39) goto LA40; LOC39 = (((*(*(*p0).module).module).flags &(1U<<((NU)(((Tsymflag292184) 27))&31U)))!=0); LA40: ; LOC37 = LOC39; LA38: ; LOC36 = LOC37; if (!(LOC36)) goto LA41; LOC36 = ((*e0).kind == ((Tnodekind292020) 65)); LA41: ; if (!LOC36) goto LA42; LOC44 = (Ropeobj178006*)0; LOC44 = rdloc_538188_839829468(a0); putintodest_550468_839829468(p0, d0, (*e0).typ, LOC44, a0.s); goto BeforeRet; } LA42: ; } break; case ((Ttypekind292244) 21): { (*d0).s = ((Tstorageloc292812) 0); } break; default: { NimStringDesc* LOC47; LOC47 = (NimStringDesc*)0; LOC47 = rawNewString(reprEnum((NI)(*typ0).kind, (&NTI292244))->Sup.len + 9); appendString(LOC47, ((NimStringDesc*) &T839829468_548)); appendString(LOC47, reprEnum((NI)(*typ0).kind, (&NTI292244))); internalerror_196100_155036129((*e0).info, LOC47); } break; } } goto LA28; LA30: ; { NIM_BOOL LOC49; LOC49 = (NIM_BOOL)0; LOC49 = (gcmd_169132_2607990831 == ((Tcommands169076) 2)); if (LOC49) goto LA50; LOC49 = (((*(*(*p0).module).module).flags &(1U<<((NU)(((Tsymflag292184) 27))&31U)))!=0); LA50: ; if (!LOC49) goto LA51; { NIM_BOOL LOC55; NIM_BOOL LOC56; Ropeobj178006* LOC61; LOC55 = (NIM_BOOL)0; LOC56 = (NIM_BOOL)0; LOC56 = ((*typ0).kind == ((Ttypekind292244) 23)); if (!(LOC56)) goto LA57; LOC56 = !((((*typ0).flags &(1U<<((NU)(((Ttypeflag292431) 18))&31U)))!=0)); LA57: ; LOC55 = LOC56; if (!(LOC55)) goto LA58; LOC55 = ((*e0).kind == ((Tnodekind292020) 65)); LA58: ; if (!LOC55) goto LA59; LOC61 = (Ropeobj178006*)0; LOC61 = rdloc_538188_839829468(a0); putintodest_550468_839829468(p0, d0, (*e0).typ, LOC61, a0.s); goto BeforeRet; } LA59: ; } goto LA28; LA51: ; LA28: ; { NIM_BOOL LOC64; Ropeobj178006* LOC68; LOC64 = (NIM_BOOL)0; LOC64 = enforcederef0; if (!(LOC64)) goto LA65; LOC64 = (mt0 == ((Tctypekind529007) 18)); LA65: ; if (!LOC64) goto LA66; LOC68 = (Ropeobj178006*)0; LOC68 = rdloc_538188_839829468(a0); putintodest_550468_839829468(p0, d0, (*a0.t).sons->data[((NI) 0)], LOC68, a0.s); } goto LA62; LA66: ; { TY178507 LOC70; Ropeobj178006* LOC71; memset((void*)LOC70, 0, sizeof(LOC70)); LOC70[0] = rdloc_538188_839829468(a0); LOC71 = (Ropeobj178006*)0; LOC71 = HEX25_178905_2381377266(((NimStringDesc*) &T839829468_124), LOC70, 1); putintodest_550468_839829468(p0, d0, (*e0).typ, LOC71, a0.s); } LA62: ; } LA1: ; }BeforeRet: ; } N_NIMCALL(Ttype292840*, genrecordfieldaux_553096_839829468)(Tcproc529021* p0, Tnode292802* e0, Tloc292816* d0, Tloc292816* a0) { Ttype292840* result0; Ropeobj178006* LOC9; result0 = (Ttype292840*)0; initlocexpr_539283_839829468(p0, (*e0).kindU.S6.sons->data[((NI) 0)], a0); { if (!!(((*(*e0).kindU.S6.sons->data[((NI) 1)]).kind == ((Tnodekind292020) 3)))) goto LA3; internalerror_196100_155036129((*e0).info, ((NimStringDesc*) &T839829468_549)); } LA3: ; { if (!((*d0).k == ((Tlockind292808) 0))) goto LA7; (*d0).s = (*a0).s; } LA7: ; LOC9 = (Ropeobj178006*)0; LOC9 = gettypedesc_535671_839829468((*p0).module, (*a0).t); result0 = getuniquetype_528640_2036603609((*a0).t); return result0; } N_NIMCALL(void, genrecordfield_553448_839829468)(Tcproc529021* p0, Tnode292802* e0, Tloc292816* d0) { Tloc292816 a0; Ttype292840* ty0; Ropeobj178006* r0; Tsym292834* f0; memset((void*)(&a0), 0, sizeof(a0)); ty0 = genrecordfieldaux_553096_839829468(p0, e0, d0, (&a0)); r0 = rdloc_538188_839829468(a0); f0 = (*(*e0).kindU.S6.sons->data[((NI) 1)]).kindU.S4.sym; { TY178507 LOC5; if (!((*ty0).kind == ((Ttypekind292244) 18))) goto LA3; memset((void*)LOC5, 0, sizeof(LOC5)); LOC5[0] = rope_178401_2381377266(((NI64) ((*f0).position))); addf_179205_2381377266(&r0, ((NimStringDesc*) &T839829468_546), LOC5, 1); putintodest_550468_839829468(p0, d0, (*f0).typ, r0, a0.s); } goto LA1; LA3: ; { Tsym292834* field0; TY178507 LOC11; field0 = lookupfieldagain_553153_839829468(p0, ty0, f0, &r0); { if (!((*field0).loc.r == NIM_NIL)) goto LA9; internalerror_196100_155036129((*e0).info, ((NimStringDesc*) &T839829468_550)); } LA9: ; memset((void*)LOC11, 0, sizeof(LOC11)); LOC11[0] = (*field0).loc.r; addf_179205_2381377266(&r0, ((NimStringDesc*) &T839829468_551), LOC11, 1); putintodest_550468_839829468(p0, d0, (*field0).typ, r0, a0.s); } LA1: ; } N_NIMCALL(void, gencheckedrecordfield_554046_839829468)(Tcproc529021* p0, Tnode292802* e0, Tloc292816* d0) { { Tloc292816 a0; Ttype292840* ty0; Ropeobj178006* r0; Tsym292834* f0; Tsym292834* field0; TY178507 LOC9; Ropeobj178006* LOC10; if (!(((*p0).options &(1U<<((NU)(((Toption169009) 2))&31U)))!=0)) goto LA3; memset((void*)(&a0), 0, sizeof(a0)); ty0 = genrecordfieldaux_553096_839829468(p0, (*e0).kindU.S6.sons->data[((NI) 0)], d0, (&a0)); r0 = rdloc_538188_839829468(a0); f0 = (*(*(*e0).kindU.S6.sons->data[((NI) 0)]).kindU.S6.sons->data[((NI) 1)]).kindU.S4.sym; field0 = lookupfieldagain_553153_839829468(p0, ty0, f0, &r0); { if (!((*field0).loc.r == NIM_NIL)) goto LA7; internalerror_196100_155036129((*e0).info, ((NimStringDesc*) &T839829468_532)); } LA7: ; genfieldcheck_553504_839829468(p0, e0, r0, field0, ty0); memset((void*)LOC9, 0, sizeof(LOC9)); LOC9[0] = (*field0).loc.r; LOC10 = (Ropeobj178006*)0; LOC10 = ropecg_532407_839829468(NIM_NIL, ((NimStringDesc*) &T839829468_551), LOC9, 1); add_178482_2381377266(&r0, LOC10); putintodest_550468_839829468(p0, d0, (*field0).typ, r0, a0.s); } goto LA1; LA3: ; { genrecordfield_553448_839829468(p0, (*e0).kindU.S6.sons->data[((NI) 0)], d0); } LA1: ; } N_NIMCALL(NI, startblock_543978_839829468)(Tcproc529021* p0, NimStringDesc* start0, Ropeobj178006** args0, NI args0Len0) { NI result0; result0 = (NI)0; linecg_532707_839829468(p0, ((Tcprocsection529011) 2), start0, args0, args0Len0); (*p0).labels += ((NI) 1); result0 = ((*p0).blocks ? (*p0).blocks->Sup.len : 0); (*p0).blocks = (TY529095*) setLengthSeq(&((*p0).blocks)->Sup, sizeof(Tblock529019), ((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(Ropeobj178006*, blockbody_544025_839829468)(Tblock529019* b0) { Ropeobj178006* result0; result0 = (Ropeobj178006*)0; result0 = (*b0).sections[(((Tcprocsection529011) 0))- 0]; { TY178507 LOC5; if (!(((NI16) 0) < (*b0).framelen)) goto LA3; memset((void*)LOC5, 0, sizeof(LOC5)); LOC5[0] = rope_178401_2381377266(((NI64) ((*b0).framelen))); addf_179205_2381377266(&result0, ((NimStringDesc*) &T839829468_554), LOC5, 1); } LA3: ; add_178482_2381377266(&result0, (*b0).sections[(((Tcprocsection529011) 1))- 0]); add_178482_2381377266(&result0, (*b0).sections[(((Tcprocsection529011) 2))- 0]); return result0; } N_NIMCALL(void, endblock_544035_839829468)(Tcproc529021* p0, Ropeobj178006* blockend0) { NI topblock0; Ropeobj178006* LOC1; topblock0 = (NI)(((*p0).blocks ? (*p0).blocks->Sup.len : 0) - ((NI) 1)); LOC1 = (Ropeobj178006*)0; LOC1 = blockbody_544025_839829468((&(*p0).blocks->data[topblock0])); add_178482_2381377266(&(*p0).blocks->data[(NI)(topblock0 - ((NI) 1))].sections[(((Tcprocsection529011) 2))- 0], LOC1); (*p0).blocks = (TY529095*) setLengthSeq(&((*p0).blocks)->Sup, sizeof(Tblock529019), ((NI) (topblock0))); line_532690_839829468(p0, ((Tcprocsection529011) 2), blockend0); } N_NIMCALL(void, endblock_544060_839829468)(Tcproc529021* p0) { NI topblock0; Ropeobj178006* blockend0; NI16 framelen0; topblock0 = (NI)(((*p0).blocks ? (*p0).blocks->Sup.len : 0) - ((NI) 1)); { TY178507 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_532407_839829468(NIM_NIL, ((NimStringDesc*) &T839829468_552), LOC5, 1); } goto LA1; LA3: ; { TY533289 LOC7; memset((void*)LOC7, 0, sizeof(LOC7)); blockend0 = HEX25_178905_2381377266(((NimStringDesc*) &T839829468_160), LOC7, 0); } LA1: ; framelen0 = (*p0).blocks->data[topblock0].framelen; { TY178507 LOC12; if (!(((NI16) 0) < framelen0)) goto LA10; memset((void*)LOC12, 0, sizeof(LOC12)); LOC12[0] = rope_178401_2381377266(((NI64) (framelen0))); addf_179205_2381377266(&blockend0, ((NimStringDesc*) &T839829468_553), LOC12, 1); } LA10: ; endblock_544035_839829468(p0, blockend0); } N_NIMCALL(void, genblock_546083_839829468)(Tcproc529021* p0, Tnode292802* n0, Tloc292816* d0) { NI oldbreakidx_546099_839829468; TY533289 LOC8; { NIM_BOOL LOC3; NIM_BOOL LOC4; LOC3 = (NIM_BOOL)0; LOC4 = (NIM_BOOL)0; LOC4 = isemptytype_297440_850551059((*n0).typ); LOC3 = !(LOC4); if (!(LOC3)) goto LA5; LOC3 = ((*d0).k == ((Tlockind292808) 0)); LA5: ; if (!LOC3) goto LA6; gettemp_537032_839829468(p0, (*n0).typ, d0, NIM_FALSE); } LA6: ; oldbreakidx_546099_839829468 = (*p0).breakidx; memset((void*)LOC8, 0, sizeof(LOC8)); (*p0).breakidx = startblock_543978_839829468(p0, ((NimStringDesc*) &T839829468_273), LOC8, 0); { Tsym292834* sym0; if (!!(((*(*n0).kindU.S6.sons->data[((NI) 0)]).kind == ((Tnodekind292020) 1)))) goto LA11; sym0 = (*(*n0).kindU.S6.sons->data[((NI) 0)]).kindU.S4.sym; (*sym0).loc.k = ((Tlockind292808) 10); (*sym0).position = (NI)((*p0).breakidx + ((NI) 1)); } LA11: ; expr_539248_839829468(p0, (*n0).kindU.S6.sons->data[((NI) 1)], d0); endblock_544060_839829468(p0); (*p0).breakidx = oldbreakidx_546099_839829468; } N_NIMCALL(void, genstmtlistexpr_558402_839829468)(Tcproc529021* p0, Tnode292802* n0, Tloc292816* d0) { NI length0; length0 = sonslen_295351_850551059(n0); { NI i_558420_839829468; NI HEX3Atmp_558424_839829468; NI res_558427_839829468; i_558420_839829468 = (NI)0; HEX3Atmp_558424_839829468 = (NI)0; HEX3Atmp_558424_839829468 = (NI)(length0 - ((NI) 2)); res_558427_839829468 = ((NI) 0); { while (1) { if (!(res_558427_839829468 <= HEX3Atmp_558424_839829468)) goto LA3; i_558420_839829468 = res_558427_839829468; genstmts_539244_839829468(p0, (*n0).kindU.S6.sons->data[i_558420_839829468]); res_558427_839829468 += ((NI) 1); } LA3: ; } } { if (!(((NI) 0) < length0)) goto LA6; expr_539248_839829468(p0, (*n0).kindU.S6.sons->data[(NI)(length0 - ((NI) 1))], d0); } LA6: ; } N_NIMCALL(void, genif_544982_839829468)(Tcproc529021* p0, Tnode292802* n0, Tloc292816* d0) { Tloc292816 a0; Ropeobj178006* lelse0; Ropeobj178006* lend0; memset((void*)(&a0), 0, sizeof(a0)); lelse0 = (Ropeobj178006*)0; { NIM_BOOL LOC3; NIM_BOOL LOC4; LOC3 = (NIM_BOOL)0; LOC4 = (NIM_BOOL)0; LOC4 = isemptytype_297440_850551059((*n0).typ); LOC3 = !(LOC4); if (!(LOC3)) goto LA5; LOC3 = ((*d0).k == ((Tlockind292808) 0)); LA5: ; if (!LOC3) goto LA6; gettemp_537032_839829468(p0, (*n0).typ, d0, NIM_FALSE); } LA6: ; genlinedir_532823_839829468(p0, n0); lend0 = getlabel_539217_839829468(p0); { NI i_545011_839829468; NI HEX3Atmp_545435_839829468; NI LOC9; NI res_545438_839829468; i_545011_839829468 = (NI)0; HEX3Atmp_545435_839829468 = (NI)0; LOC9 = (NI)0; LOC9 = sonslen_295351_850551059(n0); HEX3Atmp_545435_839829468 = (NI)(LOC9 - ((NI) 1)); res_545438_839829468 = ((NI) 0); { while (1) { Tnode292802* it0; if (!(res_545438_839829468 <= HEX3Atmp_545435_839829468)) goto LA11; i_545011_839829468 = res_545438_839829468; { NIM_BOOL LOC14; LOC14 = (NIM_BOOL)0; LOC14 = ((*d0).k == ((Tlockind292808) 1)); if (!(LOC14)) goto LA15; LOC14 = isemptytype_297440_850551059((*n0).typ); LA15: ; if (!LOC14) goto LA16; (*d0).k = ((Tlockind292808) 0); } LA16: ; it0 = (*n0).kindU.S6.sons->data[i_545011_839829468]; { NI LOC20; TY533289 LOC23; NI LOC24; TY532811 LOC25; LOC20 = (NI)0; LOC20 = len_293081_850551059(it0); if (!(LOC20 == ((NI) 2))) goto LA21; memset((void*)LOC23, 0, sizeof(LOC23)); LOC24 = (NI)0; LOC24 = startblock_543978_839829468(p0, ((NimStringDesc*) &T839829468_273), LOC23, 0); initlocexprsingleuse_539289_839829468(p0, (*it0).kindU.S6.sons->data[((NI) 0)], (&a0)); lelse0 = getlabel_539217_839829468(p0); (*p0).labels += ((NI) 1); memset((void*)LOC25, 0, sizeof(LOC25)); LOC25[0] = rdloc_538188_839829468(a0); LOC25[1] = lelse0; linef_532700_839829468(p0, ((Tcprocsection529011) 2), ((NimStringDesc*) &T839829468_555), LOC25, 2); { NIM_BOOL LOC28; Ropeobj178006** LOC32; Ropeobj178006** LOC33; LOC28 = (NIM_BOOL)0; LOC28 = (gcmd_169132_2607990831 == ((Tcommands169076) 2)); if (LOC28) goto LA29; LOC28 = (((*(*(*p0).module).module).flags &(1U<<((NU)(((Tsymflag292184) 27))&31U)))!=0); LA29: ; if (!LOC28) goto LA30; LOC32 = (Ropeobj178006**)0; LOC32 = s_529179_3723162438(p0, ((Tcprocsection529011) 2)); add_178487_2381377266(LOC32, ((NimStringDesc*) &T839829468_223)); expr_539248_839829468(p0, (*it0).kindU.S6.sons->data[((NI) 1)], d0); LOC33 = (Ropeobj178006**)0; LOC33 = s_529179_3723162438(p0, ((Tcprocsection529011) 2)); add_178487_2381377266(LOC33, ((NimStringDesc*) &T839829468_280)); } goto LA26; LA30: ; { expr_539248_839829468(p0, (*it0).kindU.S6.sons->data[((NI) 1)], d0); } LA26: ; endblock_544060_839829468(p0); { NI LOC37; TY178507 LOC40; LOC37 = (NI)0; LOC37 = sonslen_295351_850551059(n0); if (!(((NI) 1) < LOC37)) goto LA38; memset((void*)LOC40, 0, sizeof(LOC40)); LOC40[0] = lend0; linef_532700_839829468(p0, ((Tcprocsection529011) 2), ((NimStringDesc*) &T839829468_556), LOC40, 1); } LA38: ; fixlabel_539230_839829468(p0, lelse0); } goto LA18; LA21: ; { NI LOC42; TY533289 LOC45; NI LOC46; LOC42 = (NI)0; LOC42 = len_293081_850551059(it0); if (!(LOC42 == ((NI) 1))) goto LA43; memset((void*)LOC45, 0, sizeof(LOC45)); LOC46 = (NI)0; LOC46 = startblock_543978_839829468(p0, ((NimStringDesc*) &T839829468_273), LOC45, 0); expr_539248_839829468(p0, (*it0).kindU.S6.sons->data[((NI) 0)], d0); endblock_544060_839829468(p0); } goto LA18; LA43: ; { internalerror_196100_155036129((*n0).info, ((NimStringDesc*) &T839829468_557)); } LA18: ; res_545438_839829468 += ((NI) 1); } LA11: ; } } { NI LOC50; LOC50 = (NI)0; LOC50 = sonslen_295351_850551059(n0); if (!(((NI) 1) < LOC50)) goto LA51; fixlabel_539230_839829468(p0, lend0); } LA51: ; } N_NIMCALL(void, downconv_558581_839829468)(Tcproc529021* p0, Tnode292802* n0, Tloc292816* d0) { { NIM_BOOL LOC3; LOC3 = (NIM_BOOL)0; LOC3 = (gcmd_169132_2607990831 == ((Tcommands169076) 2)); if (LOC3) goto LA4; LOC3 = (((*(*(*p0).module).module).flags &(1U<<((NU)(((Tsymflag292184) 27))&31U)))!=0); LA4: ; if (!LOC3) goto LA5; expr_539248_839829468(p0, (*n0).kindU.S6.sons->data[((NI) 0)], d0); } goto LA1; LA5: ; { Ttype292840* dest0; Tnode292802* arg0; Ttype292840* src0; Tloc292816 a0; Ropeobj178006* r0; NIM_BOOL isref0; Ttype292840* LOC10; dest0 = skiptypes_296099_850551059((*n0).typ, IL64(211106247256320)); arg0 = (*n0).kindU.S6.sons->data[((NI) 0)]; { while (1) { if (!((*arg0).kind == ((Tnodekind292020) 66))) goto LA9; arg0 = (*arg0).kindU.S6.sons->data[((NI) 0)]; } LA9: ; } src0 = skiptypes_296099_850551059((*arg0).typ, IL64(211106247256320)); memset((void*)(&a0), 0, sizeof(a0)); initlocexpr_539283_839829468(p0, arg0, (&a0)); r0 = rdloc_538188_839829468(a0); LOC10 = (Ttype292840*)0; LOC10 = skiptypes_296099_850551059((*arg0).typ, IL64(211106232576256)); isref0 = ((*LOC10).kind == ((Ttypekind292244) 22) || (*LOC10).kind == ((Ttypekind292244) 21) || (*LOC10).kind == ((Ttypekind292244) 23)); { if (!isref0) goto LA13; add_178487_2381377266(&r0, ((NimStringDesc*) &T839829468_558)); } goto LA11; LA13: ; { add_178487_2381377266(&r0, ((NimStringDesc*) &T839829468_153)); } LA11: ; { NI i_558650_839829468; NI HEX3Atmp_558677_839829468; NI LOC17; NI res_558680_839829468; i_558650_839829468 = (NI)0; HEX3Atmp_558677_839829468 = (NI)0; LOC17 = (NI)0; LOC17 = inheritancediff_326252_3876443242(dest0, src0); HEX3Atmp_558677_839829468 = (LOC17 > 0? (LOC17) : -(LOC17)); res_558680_839829468 = ((NI) 2); { while (1) { if (!(res_558680_839829468 <= HEX3Atmp_558677_839829468)) goto LA19; i_558650_839829468 = res_558680_839829468; add_178487_2381377266(&r0, ((NimStringDesc*) &T839829468_153)); res_558680_839829468 += ((NI) 1); } LA19: ; } } { if (!isref0) goto LA22; { NIM_BOOL LOC26; Ttype292840* LOC28; TY532811 LOC31; LOC26 = (NIM_BOOL)0; LOC26 = ((*d0).k == ((Tlockind292808) 0)); if (!(LOC26)) goto LA27; LOC28 = (Ttype292840*)0; LOC28 = skiptypes_296099_850551059((*n0).typ, IL64(211106232576256)); LOC26 = ((*LOC28).kind == ((Ttypekind292244) 22) || (*LOC28).kind == ((Ttypekind292244) 21) || (*LOC28).kind == ((Ttypekind292244) 23)); LA27: ; if (!LOC26) goto LA29; gettemp_537032_839829468(p0, (*n0).typ, d0, NIM_FALSE); memset((void*)LOC31, 0, sizeof(LOC31)); LOC31[0] = rdloc_538188_839829468((*d0)); LOC31[1] = r0; linefmt_532714_839829468(p0, ((Tcprocsection529011) 2), ((NimStringDesc*) &T839829468_559), LOC31, 2); } goto LA24; LA29: ; { r0 = HEX26_178452_2381377266(((NimStringDesc*) &T839829468_52), r0); putintodest_550468_839829468(p0, d0, (*n0).typ, r0, a0.s); } LA24: ; } goto LA20; LA22: ; { putintodest_550468_839829468(p0, d0, (*n0).typ, r0, a0.s); } LA20: ; } LA1: ; } N_NIMCALL(void, upconv_558431_839829468)(Tcproc529021* p0, Tnode292802* n0, Tloc292816* d0) { Tloc292816 a0; Ttype292840* dest0; memset((void*)(&a0), 0, sizeof(a0)); initlocexpr_539283_839829468(p0, (*n0).kindU.S6.sons->data[((NI) 0)], (&a0)); dest0 = skiptypes_296099_850551059((*n0).typ, IL64(211106247256320)); { NIM_BOOL LOC3; NIM_BOOL LOC5; Ropeobj178006* r0; Ropeobj178006* nilcheck0; Ttype292840* t0; LOC3 = (NIM_BOOL)0; LOC3 = (((*p0).options &(1U<<((NU)(((Toption169009) 1))&31U)))!=0); if (!(LOC3)) goto LA4; LOC5 = (NIM_BOOL)0; LOC5 = isobjlackingtypefield_533513_839829468(dest0); LOC3 = !(LOC5); LA4: ; if (!LOC3) goto LA6; r0 = rdloc_538188_839829468(a0); nilcheck0 = NIM_NIL; t0 = skiptypes_296099_850551059(a0.t, IL64(211106232576256)); { while (1) { Ttype292840* LOC23; if (!((*t0).kind == ((Ttypekind292244) 23) || (*t0).kind == ((Ttypekind292244) 21) || (*t0).kind == ((Ttypekind292244) 22))) goto LA9; { if (!!(((*t0).kind == ((Ttypekind292244) 23)))) goto LA12; nilcheck0 = r0; } LA12: ; { NIM_BOOL LOC16; NIM_BOOL LOC18; TY178507 LOC22; LOC16 = (NIM_BOOL)0; LOC16 = !(((*t0).kind == ((Ttypekind292244) 23))); if (LOC16) goto LA17; LOC18 = (NIM_BOOL)0; LOC18 = (gcmd_169132_2607990831 == ((Tcommands169076) 2)); if (LOC18) goto LA19; LOC18 = (((*(*(*p0).module).module).flags &(1U<<((NU)(((Tsymflag292184) 27))&31U)))!=0); LA19: ; LOC16 = !(LOC18); LA17: ; if (!LOC16) goto LA20; memset((void*)LOC22, 0, sizeof(LOC22)); LOC22[0] = r0; r0 = HEX25_178905_2381377266(((NimStringDesc*) &T839829468_124), LOC22, 1); } LA20: ; LOC23 = (Ttype292840*)0; LOC23 = lastson_295377_850551059(t0); t0 = skiptypes_296099_850551059(LOC23, IL64(211106232576256)); } LA9: ; } { NIM_BOOL LOC26; LOC26 = (NIM_BOOL)0; LOC26 = (gcmd_169132_2607990831 == ((Tcommands169076) 2)); if (LOC26) goto LA27; LOC26 = (((*(*(*p0).module).module).flags &(1U<<((NU)(((Tsymflag292184) 27))&31U)))!=0); LA27: ; if (!!(LOC26)) goto LA28; { while (1) { NIM_BOOL LOC32; LOC32 = (NIM_BOOL)0; LOC32 = ((*t0).kind == ((Ttypekind292244) 17)); if (!(LOC32)) goto LA33; LOC32 = !(((*t0).sons->data[((NI) 0)] == NIM_NIL)); LA33: ; if (!LOC32) goto LA31; add_178487_2381377266(&r0, ((NimStringDesc*) &T839829468_153)); t0 = skiptypes_296099_850551059((*t0).sons->data[((NI) 0)], IL64(211106247215360)); } LA31: ; } } LA28: ; { TY535238 LOC38; if (!!((nilcheck0 == NIM_NIL))) goto LA36; memset((void*)LOC38, 0, sizeof(LOC38)); LOC38[0] = nilcheck0; LOC38[1] = r0; LOC38[2] = gentypeinfo_535941_839829468((*p0).module, dest0); linefmt_532714_839829468(p0, ((Tcprocsection529011) 2), ((NimStringDesc*) &T839829468_560), LOC38, 3); } goto LA34; LA36: ; { TY532811 LOC40; memset((void*)LOC40, 0, sizeof(LOC40)); LOC40[0] = r0; LOC40[1] = gentypeinfo_535941_839829468((*p0).module, dest0); linefmt_532714_839829468(p0, ((Tcprocsection529011) 2), ((NimStringDesc*) &T839829468_561), LOC40, 2); } LA34: ; } LA6: ; { TY532811 LOC45; Ropeobj178006* LOC46; if (!!(((*(*(*n0).kindU.S6.sons->data[((NI) 0)]).typ).kind == ((Ttypekind292244) 17)))) goto LA43; memset((void*)LOC45, 0, sizeof(LOC45)); LOC45[0] = gettypedesc_535671_839829468((*p0).module, (*n0).typ); LOC45[1] = rdloc_538188_839829468(a0); LOC46 = (Ropeobj178006*)0; LOC46 = HEX25_178905_2381377266(((NimStringDesc*) &T839829468_430), LOC45, 2); putintodest_550468_839829468(p0, d0, (*n0).typ, LOC46, a0.s); } goto LA41; LA43: ; { TY532811 LOC48; Ropeobj178006* LOC49; memset((void*)LOC48, 0, sizeof(LOC48)); LOC48[0] = gettypedesc_535671_839829468((*p0).module, dest0); LOC48[1] = addrloc_538204_839829468(a0); LOC49 = (Ropeobj178006*)0; LOC49 = HEX25_178905_2381377266(((NimStringDesc*) &T839829468_429), LOC48, 2); putintodest_550468_839829468(p0, d0, (*n0).typ, LOC49, a0.s); } LA41: ; } N_NIMCALL(void, genrangechck_556590_839829468)(Tcproc529021* p0, Tnode292802* n0, Tloc292816* d0, NimStringDesc* magic0) { Tloc292816 a0; Ttype292840* dest0; memset((void*)(&a0), 0, sizeof(a0)); dest0 = skiptypes_296099_850551059((*n0).typ, IL64(211106240964864)); { NIM_BOOL LOC3; Ttype292840* LOC5; TY532811 LOC8; Ropeobj178006* LOC9; LOC3 = (NIM_BOOL)0; LOC3 = !((((*p0).options &(1U<<((NU)(((Toption169009) 3))&31U)))!=0)); if (LOC3) goto LA4; LOC5 = (Ttype292840*)0; LOC5 = skiptypes_296099_850551059(dest0, 1048576); LOC3 = ((*LOC5).kind >= ((Ttypekind292244) 40) && (*LOC5).kind <= ((Ttypekind292244) 44)); LA4: ; if (!LOC3) goto LA6; initlocexpr_539283_839829468(p0, (*n0).kindU.S6.sons->data[((NI) 0)], (&a0)); memset((void*)LOC8, 0, sizeof(LOC8)); LOC8[0] = gettypedesc_535671_839829468((*p0).module, dest0); LOC8[1] = rdcharloc_538227_839829468(a0); LOC9 = (Ropeobj178006*)0; LOC9 = HEX25_178905_2381377266(((NimStringDesc*) &T839829468_430), LOC8, 2); putintodest_550468_839829468(p0, d0, (*n0).typ, LOC9, a0.s); } goto LA1; LA6: ; { TY536475 LOC11; Ropeobj178006* LOC12; initlocexpr_539283_839829468(p0, (*n0).kindU.S6.sons->data[((NI) 0)], (&a0)); memset((void*)LOC11, 0, sizeof(LOC11)); LOC11[0] = gettypedesc_535671_839829468((*p0).module, dest0); LOC11[1] = rdcharloc_538227_839829468(a0); LOC11[2] = genliteral_549476_839829468(p0, (*n0).kindU.S6.sons->data[((NI) 1)], dest0); LOC11[3] = genliteral_549476_839829468(p0, (*n0).kindU.S6.sons->data[((NI) 2)], dest0); LOC11[4] = rope_178277_2381377266(magic0); LOC12 = (Ropeobj178006*)0; LOC12 = ropecg_532407_839829468((*p0).module, ((NimStringDesc*) &T839829468_562), LOC11, 5); putintodest_550468_839829468(p0, d0, dest0, LOC12, a0.s); } LA1: ; } N_NIMCALL(void, convstrtocstr_556642_839829468)(Tcproc529021* p0, Tnode292802* n0, Tloc292816* d0) { Tloc292816 a0; Ttype292840* LOC1; TY178507 LOC2; Ropeobj178006* LOC3; memset((void*)(&a0), 0, sizeof(a0)); initlocexpr_539283_839829468(p0, (*n0).kindU.S6.sons->data[((NI) 0)], (&a0)); LOC1 = (Ttype292840*)0; LOC1 = skiptypes_296099_850551059((*n0).typ, IL64(211106240964864)); memset((void*)LOC2, 0, sizeof(LOC2)); LOC2[0] = rdloc_538188_839829468(a0); LOC3 = (Ropeobj178006*)0; LOC3 = HEX25_178905_2381377266(((NimStringDesc*) &T839829468_485), LOC2, 1); putintodest_550468_839829468(p0, d0, LOC1, LOC3, a0.s); } N_NIMCALL(void, convcstrtostr_556654_839829468)(Tcproc529021* p0, Tnode292802* n0, Tloc292816* d0) { Tloc292816 a0; Ttype292840* LOC1; TY178507 LOC2; Ropeobj178006* LOC3; memset((void*)(&a0), 0, sizeof(a0)); initlocexpr_539283_839829468(p0, (*n0).kindU.S6.sons->data[((NI) 0)], (&a0)); LOC1 = (Ttype292840*)0; LOC1 = skiptypes_296099_850551059((*n0).typ, IL64(211106240964864)); memset((void*)LOC2, 0, sizeof(LOC2)); LOC2[0] = rdloc_538188_839829468(a0); LOC3 = (Ropeobj178006*)0; LOC3 = ropecg_532407_839829468((*p0).module, ((NimStringDesc*) &T839829468_411), LOC2, 1); putintodest_550468_839829468(p0, d0, LOC1, LOC3, a0.s); gcusage_554439_839829468(n0); } static N_INLINE(NIM_BOOL, isroutine_297323_850551059)(Tsym292834* s0) { NIM_BOOL result0; result0 = (NIM_BOOL)0; result0 = ((258048 &(1U<<((NU)((*s0).kind)&31U)))!=0); return result0; } static N_INLINE(NIM_BOOL, isconstclosure_557810_839829468)(Tnode292802* 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 == ((Tnodekind292020) 3)); if (!(LOC2)) goto LA3; LOC2 = isroutine_297323_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 == ((Tnodekind292020) 23)); LA4: ; result0 = LOC1; return result0; } N_NIMCALL(void, genclosure_557836_839829468)(Tcproc529021* p0, Tnode292802* n0, Tloc292816* d0) { { NIM_BOOL LOC3; Ropeobj178006* tmp0; Ropeobj178006* LOC6; TY535238 LOC7; LOC3 = (NIM_BOOL)0; LOC3 = isconstclosure_557810_839829468(n0); if (!LOC3) goto LA4; (*(*p0).module).labels += ((NI) 1); LOC6 = (Ropeobj178006*)0; LOC6 = rope_178401_2381377266(((NI64) ((*(*p0).module).labels))); tmp0 = HEX26_178452_2381377266(((NimStringDesc*) &T839829468_566), LOC6); memset((void*)LOC7, 0, sizeof(LOC7)); LOC7[0] = gettypedesc_535671_839829468((*p0).module, (*n0).typ); LOC7[1] = tmp0; LOC7[2] = genconstexpr_554849_839829468(p0, n0); addf_179205_2381377266(&(*(*p0).module).s[(((Tcfilesection529005) 8))- 0], ((NimStringDesc*) &T839829468_524), LOC7, 3); putintodest_550468_839829468(p0, d0, (*n0).typ, tmp0, ((Tstorageloc292812) 1)); } goto LA1; LA4: ; { Tloc292816 tmp0; Tloc292816 a0; Tloc292816 b0; TY535238 LOC14; memset((void*)(&tmp0), 0, sizeof(tmp0)); memset((void*)(&a0), 0, sizeof(a0)); memset((void*)(&b0), 0, sizeof(b0)); initlocexpr_539283_839829468(p0, (*n0).kindU.S6.sons->data[((NI) 0)], (&a0)); initlocexpr_539283_839829468(p0, (*n0).kindU.S6.sons->data[((NI) 1)], (&b0)); { Tnode292802* LOC11; LOC11 = (Tnode292802*)0; LOC11 = skipconv_328882_3876443242((*n0).kindU.S6.sons->data[((NI) 0)]); if (!((*LOC11).kind == ((Tnodekind292020) 155))) goto LA12; internalerror_196100_155036129((*n0).info, ((NimStringDesc*) &T839829468_567)); } LA12: ; gettemp_537032_839829468(p0, (*n0).typ, (&tmp0), NIM_FALSE); memset((void*)LOC14, 0, sizeof(LOC14)); LOC14[0] = rdloc_538188_839829468(tmp0); LOC14[1] = rdloc_538188_839829468(a0); LOC14[2] = rdloc_538188_839829468(b0); linefmt_532714_839829468(p0, ((Tcprocsection529011) 2), ((NimStringDesc*) &T839829468_568), LOC14, 3); putlocintodest_539258_839829468(p0, d0, tmp0); } LA1: ; } static N_INLINE(Ropeobj178006*, assignlabel_544020_839829468)(Tblock529019* b0) { Ropeobj178006* result0; Ropeobj178006* LOC1; result0 = (Ropeobj178006*)0; LOC1 = (Ropeobj178006*)0; LOC1 = rope_178401_2381377266(((NI64) ((*b0).id))); unsureAsgnRef((void**) (&(*b0).label), HEX26_178452_2381377266(((NimStringDesc*) &T839829468_296), LOC1)); result0 = (*b0).label; return result0; } N_NIMCALL(void, gencomputedgoto_545744_839829468)(Tcproc529021* p0, Tnode292802* n0) { NI casepos0; NI arraysize0; NI id0; Ropeobj178006* tmp0; TY178507 LOC27; Ropeobj178006* gotoarray0; TY532811 LOC28; TY178507 LOC33; NI topblock0; Ropeobj178006* oldbody0; Ropeobj178006* tailb0; Ropeobj178006* taila0; Tnode292802* casestmt0; Tloc292816 a_545871_839829468; TY532811 LOC41; { casepos0 = ((NI) -1); arraysize0 = (NI)0; { NI i_545768_839829468; NI HEX3Atmp_545933_839829468; NI LOC2; NI res_545936_839829468; i_545768_839829468 = (NI)0; HEX3Atmp_545933_839829468 = (NI)0; LOC2 = (NI)0; LOC2 = len_293081_850551059(n0); HEX3Atmp_545933_839829468 = (LOC2 - 1); res_545936_839829468 = ((NI) 0); { while (1) { Tnode292802* it0; if (!(res_545936_839829468 <= HEX3Atmp_545933_839829468)) goto LA4; i_545768_839829468 = res_545936_839829468; it0 = (*n0).kindU.S6.sons->data[i_545768_839829468]; { NI64 asize0; if (!((*it0).kind == ((Tnodekind292020) 97))) goto LA7; { Tnode292802* LOC11; LOC11 = (Tnode292802*)0; LOC11 = lastson_295364_850551059(it0); if (!!(((*LOC11).kind == ((Tnodekind292020) 85)))) goto LA12; localerror_196085_155036129((*it0).info, ((NimStringDesc*) &T839829468_570)); goto BeforeRet; } LA12: ; casepos0 = i_545768_839829468; asize0 = lengthord_320007_3876443242((*(*it0).kindU.S6.sons->data[((NI) 0)]).typ); { if (!(IL64(10000) < asize0)) goto LA16; localerror_196085_155036129((*it0).info, ((NimStringDesc*) &T839829468_571)); goto BeforeRet; } LA16: ; arraysize0 = ((NI) (asize0)); { NI64 LOC20; LOC20 = (NI64)0; LOC20 = firstord_320001_3876443242((*(*it0).kindU.S6.sons->data[((NI) 0)]).typ); if (!!((LOC20 == IL64(0)))) goto LA21; localerror_196085_155036129((*it0).info, ((NimStringDesc*) &T839829468_572)); goto BeforeRet; } LA21: ; } LA7: ; res_545936_839829468 += ((NI) 1); } LA4: ; } } { if (!(casepos0 < ((NI) 0))) goto LA25; localerror_196085_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_178401_2381377266(((NI64) (id0))); tmp0 = HEX25_178905_2381377266(((NimStringDesc*) &T839829468_574), LOC27, 1); memset((void*)LOC28, 0, sizeof(LOC28)); LOC28[0] = tmp0; LOC28[1] = rope_178401_2381377266(((NI64) (arraysize0))); gotoarray0 = HEX25_178905_2381377266(((NimStringDesc*) &T839829468_575), LOC28, 2); { NI i_545819_839829468; NI HEX3Atmp_545941_839829468; NI res_545944_839829468; i_545819_839829468 = (NI)0; HEX3Atmp_545941_839829468 = (NI)0; HEX3Atmp_545941_839829468 = (NI)(arraysize0 - ((NI) 1)); res_545944_839829468 = ((NI) 1); { while (1) { TY178507 LOC32; if (!(res_545944_839829468 <= HEX3Atmp_545941_839829468)) goto LA31; i_545819_839829468 = res_545944_839829468; memset((void*)LOC32, 0, sizeof(LOC32)); LOC32[0] = rope_178401_2381377266(((NI64) ((NI)(((NI) (id0)) + i_545819_839829468)))); addf_179205_2381377266(&gotoarray0, ((NimStringDesc*) &T839829468_576), LOC32, 1); res_545944_839829468 += ((NI) 1); } LA31: ; } } memset((void*)LOC33, 0, sizeof(LOC33)); LOC33[0] = rope_178401_2381377266(((NI64) ((NI)(((NI) (id0)) + arraysize0)))); addf_179205_2381377266(&gotoarray0, ((NimStringDesc*) &T839829468_577), LOC33, 1); line_532690_839829468(p0, ((Tcprocsection529011) 0), gotoarray0); topblock0 = (NI)(((*p0).blocks ? (*p0).blocks->Sup.len : 0) - ((NI) 1)); oldbody0 = (*p0).blocks->data[topblock0].sections[(((Tcprocsection529011) 2))- 0]; asgnRefNoCycle((void**) (&(*p0).blocks->data[topblock0].sections[(((Tcprocsection529011) 2))- 0]), NIM_NIL); { NI j_545854_839829468; NI HEX3Atmp_545949_839829468; NI HEX3Atmp_545950_839829468; NI LOC35; NI res_545953_839829468; j_545854_839829468 = (NI)0; HEX3Atmp_545949_839829468 = (NI)0; HEX3Atmp_545950_839829468 = (NI)0; HEX3Atmp_545949_839829468 = (NI)(casepos0 + ((NI) 1)); LOC35 = (NI)0; LOC35 = len_293081_850551059(n0); HEX3Atmp_545950_839829468 = (LOC35 - 1); res_545953_839829468 = HEX3Atmp_545949_839829468; { while (1) { if (!(res_545953_839829468 <= HEX3Atmp_545950_839829468)) goto LA37; j_545854_839829468 = res_545953_839829468; genstmts_539244_839829468(p0, (*n0).kindU.S6.sons->data[j_545854_839829468]); res_545953_839829468 += ((NI) 1); } LA37: ; } } tailb0 = (*p0).blocks->data[topblock0].sections[(((Tcprocsection529011) 2))- 0]; asgnRefNoCycle((void**) (&(*p0).blocks->data[topblock0].sections[(((Tcprocsection529011) 2))- 0]), NIM_NIL); { NI j_545866_839829468; NI HEX3Atmp_545958_839829468; NI res_545961_839829468; j_545866_839829468 = (NI)0; HEX3Atmp_545958_839829468 = (NI)0; HEX3Atmp_545958_839829468 = (NI)(casepos0 - ((NI) 1)); res_545961_839829468 = ((NI) 0); { while (1) { if (!(res_545961_839829468 <= HEX3Atmp_545958_839829468)) goto LA40; j_545866_839829468 = res_545961_839829468; genstmts_539244_839829468(p0, (*n0).kindU.S6.sons->data[j_545866_839829468]); res_545961_839829468 += ((NI) 1); } LA40: ; } } taila0 = (*p0).blocks->data[topblock0].sections[(((Tcprocsection529011) 2))- 0]; asgnRefNoCycle((void**) (&(*p0).blocks->data[topblock0].sections[(((Tcprocsection529011) 2))- 0]), HEX26_178418_2381377266(oldbody0, taila0)); casestmt0 = (*n0).kindU.S6.sons->data[casepos0]; memset((void*)(&a_545871_839829468), 0, sizeof(a_545871_839829468)); initlocexpr_539283_839829468(p0, (*casestmt0).kindU.S6.sons->data[((NI) 0)], (&a_545871_839829468)); memset((void*)LOC41, 0, sizeof(LOC41)); LOC41[0] = tmp0; LOC41[1] = rdloc_538188_839829468(a_545871_839829468); linef_532700_839829468(p0, ((Tcprocsection529011) 2), ((NimStringDesc*) &T839829468_578), LOC41, 2); { NI i_545894_839829468; NI HEX3Atmp_545977_839829468; NI LOC43; NI res_545980_839829468; i_545894_839829468 = (NI)0; HEX3Atmp_545977_839829468 = (NI)0; LOC43 = (NI)0; LOC43 = len_293081_850551059(casestmt0); HEX3Atmp_545977_839829468 = (LOC43 - 1); res_545980_839829468 = ((NI) 1); { while (1) { TY533289 LOC46; NI LOC47; Tnode292802* it0; Tnode292802* LOC57; Ropeobj178006** LOC58; Ropeobj178006** LOC59; Tloc292816 a0; TY532811 LOC60; if (!(res_545980_839829468 <= HEX3Atmp_545977_839829468)) goto LA45; i_545894_839829468 = res_545980_839829468; memset((void*)LOC46, 0, sizeof(LOC46)); LOC47 = (NI)0; LOC47 = startblock_543978_839829468(p0, ((NimStringDesc*) &T839829468_273), LOC46, 0); it0 = (*casestmt0).kindU.S6.sons->data[i_545894_839829468]; { NI j_545910_839829468; NI HEX3Atmp_545969_839829468; NI LOC49; NI res_545972_839829468; j_545910_839829468 = (NI)0; HEX3Atmp_545969_839829468 = (NI)0; LOC49 = (NI)0; LOC49 = len_293081_850551059(it0); HEX3Atmp_545969_839829468 = (NI)(LOC49 - ((NI) 2)); res_545972_839829468 = ((NI) 0); { while (1) { NI64 val0; TY178507 LOC56; if (!(res_545972_839829468 <= HEX3Atmp_545969_839829468)) goto LA51; j_545910_839829468 = res_545972_839829468; { if (!((*(*it0).kindU.S6.sons->data[j_545910_839829468]).kind == ((Tnodekind292020) 44))) goto LA54; localerror_196085_155036129((*it0).info, ((NimStringDesc*) &T839829468_579)); goto BeforeRet; } LA54: ; val0 = getordvalue_320129_3876443242((*it0).kindU.S6.sons->data[j_545910_839829468]); memset((void*)LOC56, 0, sizeof(LOC56)); LOC56[0] = intliteral_539270_839829468((NI64)((NI64)(val0 + ((NI64) (id0))) + IL64(1))); linef_532700_839829468(p0, ((Tcprocsection529011) 2), ((NimStringDesc*) &T839829468_580), LOC56, 1); res_545972_839829468 += ((NI) 1); } LA51: ; } } LOC57 = (Tnode292802*)0; LOC57 = lastson_295364_850551059(it0); genstmts_539244_839829468(p0, LOC57); LOC58 = (Ropeobj178006**)0; LOC58 = s_529179_3723162438(p0, ((Tcprocsection529011) 2)); add_178482_2381377266(LOC58, tailb0); LOC59 = (Ropeobj178006**)0; LOC59 = s_529179_3723162438(p0, ((Tcprocsection529011) 2)); add_178482_2381377266(LOC59, taila0); memset((void*)(&a0), 0, sizeof(a0)); initlocexpr_539283_839829468(p0, (*casestmt0).kindU.S6.sons->data[((NI) 0)], (&a0)); memset((void*)LOC60, 0, sizeof(LOC60)); LOC60[0] = tmp0; LOC60[1] = rdloc_538188_839829468(a0); linef_532700_839829468(p0, ((Tcprocsection529011) 2), ((NimStringDesc*) &T839829468_578), LOC60, 2); endblock_544060_839829468(p0); res_545980_839829468 += ((NI) 1); } LA45: ; } } }BeforeRet: ; } N_NIMCALL(void, genwhilestmt_545984_839829468)(Tcproc529021* p0, Tnode292802* t0) { Tloc292816 a0; NI oldbreakidx_546011_839829468; TY533289 LOC1; Tnode292802* loopbody0; memset((void*)(&a0), 0, sizeof(a0)); (*p0).withinloop += ((NI) 1); genlinedir_532823_839829468(p0, t0); oldbreakidx_546011_839829468 = (*p0).breakidx; memset((void*)LOC1, 0, sizeof(LOC1)); (*p0).breakidx = startblock_543978_839829468(p0, ((NimStringDesc*) &T839829468_569), LOC1, 0); (*p0).blocks->data[(*p0).breakidx].isloop = NIM_TRUE; initlocexpr_539283_839829468(p0, (*t0).kindU.S6.sons->data[((NI) 0)], (&a0)); { NIM_BOOL LOC4; Ropeobj178006* label0; TY532811 LOC8; LOC4 = (NIM_BOOL)0; LOC4 = !(((*(*t0).kindU.S6.sons->data[((NI) 0)]).kind == ((Tnodekind292020) 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_544020_839829468((&(*p0).blocks->data[(*p0).breakidx])); memset((void*)LOC8, 0, sizeof(LOC8)); LOC8[0] = rdloc_538188_839829468(a0); LOC8[1] = label0; linef_532700_839829468(p0, ((Tcprocsection529011) 2), ((NimStringDesc*) &T839829468_555), LOC8, 2); } LA6: ; loopbody0 = (*t0).kindU.S6.sons->data[((NI) 1)]; { NIM_BOOL LOC11; LOC11 = (NIM_BOOL)0; LOC11 = stmtscontainpragma_528083_2036603609(loopbody0, ((Tspecialword275003) 182)); if (!(LOC11)) goto LA12; LOC11 = ((Cc_273413_2528170400[(ccompiler_273431_2528170400)- 1].Field20 &(1U<<((NU)(((Tinfoccprop273004) 1))&7U)))!=0); LA12: ; if (!LOC11) goto LA13; { NIM_BOOL LOC17; NI LOC18; LOC17 = (NIM_BOOL)0; LOC18 = (NI)0; LOC18 = len_293081_850551059(loopbody0); LOC17 = (LOC18 == ((NI) 2)); if (!(LOC17)) goto LA19; LOC17 = ((*(*loopbody0).kindU.S6.sons->data[((NI) 0)]).kind == ((Tnodekind292020) 1)); LA19: ; if (!LOC17) goto LA20; loopbody0 = (*loopbody0).kindU.S6.sons->data[((NI) 1)]; } LA20: ; gencomputedgoto_545744_839829468(p0, loopbody0); } goto LA9; LA13: ; { genstmts_539244_839829468(p0, loopbody0); } LA9: ; { TY533289 LOC27; if (!(((*p0).options &(1U<<((NU)(((Toption169009) 19))&31U)))!=0)) goto LA25; memset((void*)LOC27, 0, sizeof(LOC27)); linefmt_532714_839829468(p0, ((Tcprocsection529011) 2), ((NimStringDesc*) &T839829468_581), LOC27, 0); } LA25: ; endblock_544060_839829468(p0); (*p0).breakidx = oldbreakidx_546011_839829468; (*p0).withinloop -= ((NI) 1); } N_NIMCALL(void, gengotovar_544258_839829468)(Tcproc529021* p0, Tnode292802* value0) { { if (!!(((*value0).kind >= ((Tnodekind292020) 5) && (*value0).kind <= ((Tnodekind292020) 15)))) goto LA3; localerror_196085_155036129((*value0).info, ((NimStringDesc*) &T839829468_582)); } goto LA1; LA3: ; { TY178507 LOC6; memset((void*)LOC6, 0, sizeof(LOC6)); LOC6[0] = rope_178401_2381377266((*value0).kindU.S1.intval); linef_532700_839829468(p0, ((Tcprocsection529011) 2), ((NimStringDesc*) &T839829468_583), LOC6, 1); } LA1: ; } N_NIMCALL(void, varindynamiclib_538812_839829468)(Tcgen529027* m0, Tsym292834* sym0) { Tlib292820* lib0; Ropeobj178006* extname0; Ropeobj178006* tmp0; TY535235 LOC1; NimStringDesc* LOC2; TY532811 LOC3; lib0 = (*sym0).annex; extname0 = (*sym0).loc.r; loaddynamiclib_559480_839829468(m0, lib0); (*sym0).loc.flags |= ((NU16)1)<<((((Tlocflag292810) 0))%(sizeof(NU16)*8)); tmp0 = mangledynlibproc_538816_839829468(sym0); asgnRefNoCycle((void**) (&(*sym0).loc.r), tmp0); (*m0).labels += ((NI) 2); memset((void*)LOC1, 0, sizeof(LOC1)); LOC1[0] = tmp0; LOC1[1] = gettypedesc_535671_839829468(m0, (*sym0).typ); LOC1[2] = (*lib0).name; LOC2 = (NimStringDesc*)0; LOC2 = HEX24_178856_2381377266(extname0); LOC1[3] = makecstring_191638_155036129(LOC2); appcg_532632_839829468(m0, &(*m0).s[(((Tcfilesection529005) 16))- 0], ((NimStringDesc*) &T839829468_584), LOC1, 4); memset((void*)LOC3, 0, sizeof(LOC3)); LOC3[0] = (*sym0).loc.r; LOC3[1] = gettypedesc_535671_839829468(m0, (*sym0).loc.t); addf_179205_2381377266(&(*m0).s[(((Tcfilesection529005) 9))- 0], ((NimStringDesc*) &T839829468_585), LOC3, 2); } N_NIMCALL(void, assignglobalvar_538819_839829468)(Tcproc529021* p0, Tsym292834* s0) { { { Ropeobj178006* LOC5; if (!((*s0).loc.k == ((Tlockind292808) 0))) goto LA3; LOC5 = (Ropeobj178006*)0; LOC5 = manglename_533205_839829468(s0); fillloc_532282_839829468((&(*s0).loc), ((Tlockind292808) 3), (*s0).typ, LOC5, ((Tstorageloc292812) 3)); } LA3: ; { Tcgen529027* q0; if (!(((*s0).loc.flags &(1U<<((NU)(((Tlocflag292810) 4))&15U)))!=0)) goto LA8; q0 = findpendingmodule_532241_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_268862_2627731572((&(*q0).declaredthings), (*s0).Sup.id); LOC12 = !(LOC14); LA13: ; if (!LOC12) goto LA15; varindynamiclib_538812_839829468(q0, s0); } goto LA10; LA15: ; { asgnRefNoCycle((void**) (&(*s0).loc.r), mangledynlibproc_538816_839829468(s0)); } LA10: ; goto BeforeRet; } LA8: ; useheader_532369_839829468((*p0).module, s0); { if (!(((*s0).loc.flags &(1U<<((NU)(((Tlocflag292810) 3))&15U)))!=0)) goto LA20; goto BeforeRet; } LA20: ; { if (!(((*s0).flags &(1U<<((NU)(((Tsymflag292184) 22))&31U)))!=0)) goto LA24; declarethreadvar_538676_839829468((*p0).module, s0, (((*s0).flags &(1U<<((NU)(((Tsymflag292184) 5))&31U)))!=0)); } goto LA22; LA24: ; { Ropeobj178006* decl0; Ropeobj178006* td0; decl0 = NIM_NIL; td0 = gettypedesc_535671_839829468((*p0).module, (*s0).loc.t); { TY178507 LOC43; if (!(*s0).constraint == 0) goto LA29; { if (!(((*s0).flags &(1U<<((NU)(((Tsymflag292184) 5))&31U)))!=0)) goto LA33; add_178487_2381377266(&decl0, ((NimStringDesc*) &T839829468_240)); } LA33: ; add_178482_2381377266(&decl0, td0); { if (!(((*s0).flags &(1U<<((NU)(((Tsymflag292184) 8))&31U)))!=0)) goto LA37; add_178487_2381377266(&decl0, ((NimStringDesc*) &T839829468_121)); } LA37: ; { if (!(((*s0).flags &(1U<<((NU)(((Tsymflag292184) 7))&31U)))!=0)) goto LA41; add_178487_2381377266(&decl0, ((NimStringDesc*) &T839829468_122)); } LA41: ; memset((void*)LOC43, 0, sizeof(LOC43)); LOC43[0] = (*s0).loc.r; addf_179205_2381377266(&decl0, ((NimStringDesc*) &T839829468_242), LOC43, 1); } goto LA27; LA29: ; { NimStringDesc* LOC45; TY532811 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_178905_2381377266(LOC45, LOC46, 2); } LA27: ; add_178482_2381377266(&(*(*p0).module).s[(((Tcfilesection529005) 9))- 0], decl0); } LA22: ; { if (!(((NI) 0) < (*p0).withinloop)) goto LA49; resetloc_538350_839829468(p0, (&(*s0).loc)); } LA49: ; { TY535238 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_191638_155036129(LOC57); LOC55[1] = (*s0).loc.r; LOC55[2] = gentypeinfo_535941_839829468((*p0).module, (*s0).typ); appcg_532632_839829468((*p0).module, &(*(*p0).module).s[(((Tcfilesection529005) 15))- 0], ((NimStringDesc*) &T839829468_586), LOC55, 3); } LA53: ; }BeforeRet: ; } N_NIMCALL(Ropeobj178006*, gentraverseprocforglobal_538032_839829468)(Tcgen529027* m0, Tsym292834* s0) { Ropeobj178006* result0; Ropeobj178006* LOC1; Ttraversalclosure537019 c0; Tcproc529021* p0; Ropeobj178006* sloc0; Ropeobj178006* header0; TY178507 LOC8; Ropeobj178006* generatedproc0; TY535235 LOC9; Ropeobj178006** LOC10; Ropeobj178006** LOC11; Ropeobj178006** LOC12; TY178507 LOC13; result0 = (Ropeobj178006*)0; LOC1 = (Ropeobj178006*)0; LOC1 = gentypeinfo_535941_839829468(m0, (*s0).loc.t); memset((void*)(&c0), 0, sizeof(c0)); p0 = newproc_529206_3723162438(NIM_NIL, m0); sloc0 = (*s0).loc.r; result0 = gettempname_533596_839829468(m0); { NIM_BOOL LOC4; LOC4 = (NIM_BOOL)0; LOC4 = (((*s0).flags &(1U<<((NU)(((Tsymflag292184) 22))&31U)))!=0); if (!(LOC4)) goto LA5; LOC4 = emulatedthreadvars_532949_839829468(); LA5: ; if (!LOC4) goto LA6; accessthreadlocalvar_532945_839829468(p0, s0); sloc0 = HEX26_178452_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_178905_2381377266(((NimStringDesc*) &T839829468_588), LOC8, 1); gentraverseproc_537022_839829468((&c0), sloc0, (*s0).loc.t); memset((void*)LOC9, 0, sizeof(LOC9)); LOC9[0] = header0; LOC10 = (Ropeobj178006**)0; LOC10 = s_529179_3723162438(p0, ((Tcprocsection529011) 0)); LOC9[1] = (*LOC10); LOC11 = (Ropeobj178006**)0; LOC11 = s_529179_3723162438(p0, ((Tcprocsection529011) 1)); LOC9[2] = (*LOC11); LOC12 = (Ropeobj178006**)0; LOC12 = s_529179_3723162438(p0, ((Tcprocsection529011) 2)); LOC9[3] = (*LOC12); generatedproc0 = HEX25_178905_2381377266(((NimStringDesc*) &T839829468_190), LOC9, 4); memset((void*)LOC13, 0, sizeof(LOC13)); LOC13[0] = header0; addf_179205_2381377266(&(*m0).s[(((Tcfilesection529005) 7))- 0], ((NimStringDesc*) &T839829468_191), LOC13, 1); add_178482_2381377266(&(*m0).s[(((Tcfilesection529005) 10))- 0], generatedproc0); return result0; } N_NIMCALL(void, registergcroot_543762_839829468)(Tcproc529021* p0, Tsym292834* v0) { { NIM_BOOL LOC3; Ropeobj178006* prc0; Ropeobj178006** LOC7; TY178507 LOC8; LOC3 = (NIM_BOOL)0; LOC3 = ((240 &(1U<<((NU)(gselectedgc_169133_2607990831)&7U)))!=0); if (!(LOC3)) goto LA4; LOC3 = containsgarbagecollectedref_320117_3876443242((*v0).loc.t); LA4: ; if (!LOC3) goto LA5; prc0 = gentraverseprocforglobal_538032_839829468((*p0).module, v0); LOC7 = (Ropeobj178006**)0; LOC7 = procsec_529194_3723162438((*(*p0).module).initproc, ((Tcprocsection529011) 1)); memset((void*)LOC8, 0, sizeof(LOC8)); LOC8[0] = prc0; appcg_532632_839829468((*p0).module, LOC7, ((NimStringDesc*) &T839829468_589), LOC8, 1); } LA5: ; } static N_INLINE(NIM_BOOL, isassignedimmediately_543781_839829468)(Tnode292802* n0) { NIM_BOOL result0; { result0 = (NIM_BOOL)0; { if (!((*n0).kind == ((Tnodekind292020) 1))) goto LA3; result0 = NIM_FALSE; goto BeforeRet; } LA3: ; { NIM_BOOL LOC7; LOC7 = (NIM_BOOL)0; LOC7 = isinvalidreturntype_533548_839829468((*n0).typ); if (!LOC7) goto LA8; result0 = NIM_FALSE; goto BeforeRet; } LA8: ; result0 = NIM_TRUE; }BeforeRet: ; return result0; } N_NIMCALL(void, genasgncall_543695_839829468)(Tcproc529021* p0, Tnode292802* le0, Tnode292802* ri0, Tloc292816* d0) { { Ttype292840* LOC3; LOC3 = (Ttype292840*)0; LOC3 = skiptypes_296099_850551059((*(*ri0).kindU.S6.sons->data[((NI) 0)]).typ, 2048); if (!((*LOC3).callconv == ((Tcallingconvention292002) 8))) goto LA4; genclosurecall_540452_839829468(p0, le0, ri0, d0); } goto LA1; LA4: ; { NIM_BOOL LOC7; LOC7 = (NIM_BOOL)0; LOC7 = ((*(*ri0).kindU.S6.sons->data[((NI) 0)]).kind == ((Tnodekind292020) 3)); if (!(LOC7)) goto LA8; LOC7 = (((*(*(*ri0).kindU.S6.sons->data[((NI) 0)]).kindU.S4.sym).flags &(1U<<((NU)(((Tsymflag292184) 27))&31U)))!=0); LA8: ; if (!LOC7) goto LA9; geninfixcall_541929_839829468(p0, le0, ri0, d0); } goto LA1; LA9: ; { NIM_BOOL LOC12; LOC12 = (NIM_BOOL)0; LOC12 = ((*(*ri0).kindU.S6.sons->data[((NI) 0)]).kind == ((Tnodekind292020) 3)); if (!(LOC12)) goto LA13; LOC12 = (((*(*(*ri0).kindU.S6.sons->data[((NI) 0)]).kindU.S4.sym).flags &(1U<<((NU)(((Tsymflag292184) 28))&31U)))!=0); LA13: ; if (!LOC12) goto LA14; gennamedparamcall_542616_839829468(p0, ri0, d0); } goto LA1; LA14: ; { genprefixcall_539960_839829468(p0, le0, ri0, d0); } LA1: ; poststmtactions_532942_839829468(p0); } static N_INLINE(void, loadinto_543928_839829468)(Tcproc529021* p0, Tnode292802* le0, Tnode292802* ri0, Tloc292816* a0) { { NIM_BOOL LOC3; NIM_BOOL LOC5; LOC3 = (NIM_BOOL)0; LOC3 = ((*ri0).kind == ((Tnodekind292020) 27) || (*ri0).kind == ((Tnodekind292020) 29) || (*ri0).kind == ((Tnodekind292020) 30) || (*ri0).kind == ((Tnodekind292020) 31) || (*ri0).kind == ((Tnodekind292020) 26) || (*ri0).kind == ((Tnodekind292020) 28) || (*ri0).kind == ((Tnodekind292020) 32)); if (!(LOC3)) goto LA4; LOC5 = (NIM_BOOL)0; LOC5 = !(((*(*ri0).kindU.S6.sons->data[((NI) 0)]).kind == ((Tnodekind292020) 3))); if (LOC5) goto LA6; LOC5 = ((*(*(*ri0).kindU.S6.sons->data[((NI) 0)]).kindU.S4.sym).magic == ((Tmagic292524) 0)); LA6: ; LOC3 = LOC5; LA4: ; if (!LOC3) goto LA7; genasgncall_543695_839829468(p0, le0, ri0, a0); } goto LA1; LA7: ; { if (!((*ri0).kind == ((Tnodekind292020) 47) || (*ri0).kind == ((Tnodekind292020) 65))) goto LA10; genderef_543921_839829468(p0, ri0, a0, NIM_TRUE); } goto LA1; LA10: ; { expr_539248_839829468(p0, ri0, a0); } LA1: ; } N_NIMCALL(void, gensinglevar_544276_839829468)(Tcproc529021* p0, Tnode292802* a0) { Tsym292834* v0; Tcproc529021* targetproc0; { v0 = (*(*a0).kindU.S6.sons->data[((NI) 0)]).kindU.S4.sym; { if (!!(((1082130432 & (*v0).flags) == 0))) goto LA3; { if (!(((*v0).flags &(1U<<((NU)(((Tsymflag292184) 30))&31U)))!=0)) goto LA7; gengotovar_544258_839829468(p0, (*a0).kindU.S6.sons->data[((NI) 2)]); } LA7: ; goto BeforeRet; } LA3: ; targetproc0 = p0; { if (!(((*v0).flags &(1U<<((NU)(((Tsymflag292184) 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 == ((Tnodekind292020) 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)(((Tsymflag292184) 9))&31U)))!=0)) goto LA23; targetproc0 = (*(*p0).module).preinitproc; } LA23: ; assignglobalvar_538819_839829468(targetproc0, v0); genobjectinit_538242_839829468((*(*p0).module).preinitproc, ((Tcprocsection529011) 1), (*v0).typ, (*v0).loc, NIM_TRUE); { NIM_BOOL LOC27; LOC27 = (NIM_BOOL)0; LOC27 = (((*v0).flags &(1U<<((NU)(((Tsymflag292184) 6))&31U)))!=0); if (!(LOC27)) goto LA28; LOC27 = !((generatedheader_532201_839829468 == NIM_NIL)); LA28: ; if (!LOC27) goto LA29; genvarprototypeaux_544254_839829468(generatedheader_532201_839829468, v0); } LA29: ; registergcroot_543762_839829468(p0, v0); } goto LA9; LA11: ; { Tnode292802* value0; NIM_BOOL imm0; value0 = (*a0).kindU.S6.sons->data[((NI) 2)]; imm0 = isassignedimmediately_543781_839829468(value0); { NIM_BOOL LOC34; NIM_BOOL LOC35; NIM_BOOL LOC36; NIM_BOOL LOC38; NIM_BOOL LOC42; Ropeobj178006* decl0; Tloc292816 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_169132_2607990831 == ((Tcommands169076) 2)); if (LOC38) goto LA39; LOC38 = (((*(*(*p0).module).module).flags &(1U<<((NU)(((Tsymflag292184) 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_320120_3876443242((*v0).typ); LOC34 = !(LOC42); LA41: ; if (!LOC34) goto LA43; genlinedir_532823_839829468(p0, a0); decl0 = localvardecl_538532_839829468(p0, v0); memset((void*)(&tmp0), 0, sizeof(tmp0)); { NIM_BOOL LOC47; NIM_BOOL LOC48; Tnode292802* LOC50; Tnode292802* LOC52; Ropeobj178006* params0; Ttype292840* typ0; TY532811 LOC66; LOC47 = (NIM_BOOL)0; LOC48 = (NIM_BOOL)0; LOC48 = ((*value0).kind == ((Tnodekind292020) 27) || (*value0).kind == ((Tnodekind292020) 29) || (*value0).kind == ((Tnodekind292020) 30) || (*value0).kind == ((Tnodekind292020) 31) || (*value0).kind == ((Tnodekind292020) 26) || (*value0).kind == ((Tnodekind292020) 28) || (*value0).kind == ((Tnodekind292020) 32)); if (!(LOC48)) goto LA49; LOC50 = (Tnode292802*)0; LOC50 = HEX5BHEX5D_293238_850551059(value0, ((NI) 0)); LOC48 = ((*LOC50).kind == ((Tnodekind292020) 3)); LA49: ; LOC47 = LOC48; if (!(LOC47)) goto LA51; LOC52 = (Tnode292802*)0; LOC52 = HEX5BHEX5D_293238_850551059(value0, ((NI) 0)); LOC47 = (((*(*LOC52).kindU.S4.sym).flags &(1U<<((NU)(((Tsymflag292184) 24))&31U)))!=0); LA51: ; if (!LOC47) goto LA53; params0 = (Ropeobj178006*)0; typ0 = skiptypes_296099_850551059((*(*value0).kindU.S6.sons->data[((NI) 0)]).typ, IL64(211106232576256)); { NI i_544619_839829468; NI HEX3Atmp_544825_839829468; NI LOC56; NI res_544828_839829468; i_544619_839829468 = (NI)0; HEX3Atmp_544825_839829468 = (NI)0; LOC56 = (NI)0; LOC56 = len_293081_850551059(value0); HEX3Atmp_544825_839829468 = (LOC56 - 1); res_544828_839829468 = ((NI) 1); { while (1) { Ropeobj178006* LOC65; if (!(res_544828_839829468 <= HEX3Atmp_544825_839829468)) goto LA58; i_544619_839829468 = res_544828_839829468; { TY533289 LOC63; Ropeobj178006* LOC64; if (!!((params0 == NIM_NIL))) goto LA61; memset((void*)LOC63, 0, sizeof(LOC63)); LOC64 = (Ropeobj178006*)0; LOC64 = HEX25_178905_2381377266(((NimStringDesc*) &T839829468_110), LOC63, 0); add_178482_2381377266(&params0, LOC64); } LA61: ; LOC65 = (Ropeobj178006*)0; LOC65 = genotherarg_539277_839829468(p0, value0, i_544619_839829468, typ0); add_178482_2381377266(&params0, LOC65); res_544828_839829468 += ((NI) 1); } LA58: ; } } memset((void*)LOC66, 0, sizeof(LOC66)); LOC66[0] = decl0; LOC66[1] = params0; linef_532700_839829468(p0, ((Tcprocsection529011) 2), ((NimStringDesc*) &T839829468_590), LOC66, 2); } goto LA45; LA53: ; { TY532811 LOC68; initlocexprsingleuse_539289_839829468(p0, value0, (&tmp0)); memset((void*)LOC68, 0, sizeof(LOC68)); LOC68[0] = decl0; LOC68[1] = rdloc_538188_839829468(tmp0); linef_532700_839829468(p0, ((Tcprocsection529011) 2), ((NimStringDesc*) &T839829468_591), LOC68, 2); } LA45: ; goto BeforeRet; } LA43: ; assignlocalvar_538614_839829468(p0, v0); initlocalvar_538398_839829468(p0, v0, imm0); } LA9: ; { if (!!(((*(*a0).kindU.S6.sons->data[((NI) 2)]).kind == ((Tnodekind292020) 1)))) goto LA71; genlinedir_532823_839829468(targetproc0, a0); loadinto_543928_839829468(targetproc0, (*a0).kindU.S6.sons->data[((NI) 0)], (*a0).kindU.S6.sons->data[((NI) 2)], (&(*v0).loc)); } LA71: ; }BeforeRet: ; } N_NIMCALL(void, genclosurevar_544832_839829468)(Tcproc529021* p0, Tnode292802* a0) { NIM_BOOL immediateasgn0; immediateasgn0 = !(((*(*a0).kindU.S6.sons->data[((NI) 2)]).kind == ((Tnodekind292020) 1))); { Tloc292816 v0; if (!immediateasgn0) goto LA3; memset((void*)(&v0), 0, sizeof(v0)); initlocexpr_539283_839829468(p0, (*a0).kindU.S6.sons->data[((NI) 0)], (&v0)); genlinedir_532823_839829468(p0, a0); loadinto_543928_839829468(p0, (*a0).kindU.S6.sons->data[((NI) 0)], (*a0).kindU.S6.sons->data[((NI) 2)], (&v0)); } LA3: ; } N_NIMCALL(void, genvartuple_543794_839829468)(Tcproc529021* p0, Tnode292802* n0) { Tloc292816 tup0; Tloc292816 field0; NI L0; NIM_BOOL uselowering0; Ttype292840* t0; { memset((void*)(&tup0), 0, sizeof(tup0)); memset((void*)(&field0), 0, sizeof(field0)); { if (!!(((*n0).kind == ((Tnodekind292020) 36)))) goto LA3; internalerror_196100_155036129((*n0).info, ((NimStringDesc*) &T839829468_592)); } LA3: ; L0 = sonslen_295351_850551059(n0); uselowering0 = NIM_FALSE; { NI i_543822_839829468; NI HEX3Atmp_543905_839829468; NI res_543908_839829468; i_543822_839829468 = (NI)0; HEX3Atmp_543905_839829468 = (NI)0; HEX3Atmp_543905_839829468 = (NI)(L0 - ((NI) 3)); res_543908_839829468 = ((NI) 0); { while (1) { if (!(res_543908_839829468 <= HEX3Atmp_543905_839829468)) goto LA7; i_543822_839829468 = res_543908_839829468; { Tnode292802* LOC10; LOC10 = (Tnode292802*)0; LOC10 = HEX5BHEX5D_293238_850551059(n0, i_543822_839829468); if (!!(((*LOC10).kind == ((Tnodekind292020) 3)))) goto LA11; uselowering0 = NIM_TRUE; goto LA5; } LA11: ; res_543908_839829468 += ((NI) 1); } LA7: ; } } LA5: ; { Tnode292802* LOC17; if (!uselowering0) goto LA15; LOC17 = (Tnode292802*)0; LOC17 = lowertupleunpacking_433037_2218250499(n0, (*p0).prc); genstmts_539244_839829468(p0, LOC17); goto BeforeRet; } LA15: ; genlinedir_532823_839829468(p0, n0); initlocexpr_539283_839829468(p0, (*n0).kindU.S6.sons->data[(NI)(L0 - ((NI) 1))], (&tup0)); t0 = getuniquetype_528640_2036603609(tup0.t); { NI i_543846_839829468; NI HEX3Atmp_543914_839829468; NI res_543917_839829468; i_543846_839829468 = (NI)0; HEX3Atmp_543914_839829468 = (NI)0; HEX3Atmp_543914_839829468 = (NI)(L0 - ((NI) 3)); res_543917_839829468 = ((NI) 0); { while (1) { if (!(res_543917_839829468 <= HEX3Atmp_543914_839829468)) goto LA20; i_543846_839829468 = res_543917_839829468; { Tsym292834* v0; v0 = (*(*n0).kindU.S6.sons->data[i_543846_839829468]).kindU.S4.sym; { if (!(((*v0).flags &(1U<<((NU)(((Tsymflag292184) 23))&31U)))!=0)) goto LA24; goto LA21; } LA24: ; { if (!(((*v0).flags &(1U<<((NU)(((Tsymflag292184) 3))&31U)))!=0)) goto LA28; assignglobalvar_538819_839829468(p0, v0); genobjectinit_538242_839829468(p0, ((Tcprocsection529011) 1), (*v0).typ, (*v0).loc, NIM_TRUE); registergcroot_543762_839829468(p0, v0); } goto LA26; LA28: ; { Tnode292802* LOC31; NIM_BOOL LOC32; assignlocalvar_538614_839829468(p0, v0); LOC31 = (Tnode292802*)0; LOC31 = HEX5BHEX5D_293238_850551059(n0, (NI)(L0 - ((NI) 1))); LOC32 = (NIM_BOOL)0; LOC32 = isassignedimmediately_543781_839829468(LOC31); initlocalvar_538398_839829468(p0, v0, LOC32); } LA26: ; initloc_532273_839829468((&field0), ((Tlockind292808) 6), (*t0).sons->data[i_543846_839829468], tup0.s); { TY532811 LOC37; if (!((*t0).kind == ((Ttypekind292244) 18))) goto LA35; memset((void*)LOC37, 0, sizeof(LOC37)); LOC37[0] = rdloc_538188_839829468(tup0); LOC37[1] = rope_178401_2381377266(((NI64) (i_543846_839829468))); field0.r = HEX25_178905_2381377266(((NimStringDesc*) &T839829468_185), LOC37, 2); } goto LA33; LA35: ; { TY532811 LOC43; { if (!!(((*(*(*t0).n).kindU.S6.sons->data[i_543846_839829468]).kind == ((Tnodekind292020) 3)))) goto LA41; internalerror_196100_155036129((*n0).info, ((NimStringDesc*) &T839829468_592)); } LA41: ; memset((void*)LOC43, 0, sizeof(LOC43)); LOC43[0] = rdloc_538188_839829468(tup0); LOC43[1] = manglerecfieldname_534361_839829468((*(*(*t0).n).kindU.S6.sons->data[i_543846_839829468]).kindU.S4.sym, t0); field0.r = HEX25_178905_2381377266(((NimStringDesc*) &T839829468_90), LOC43, 2); } LA33: ; putlocintodest_539258_839829468(p0, (&(*v0).loc), field0); } LA21: ; res_543917_839829468 += ((NI) 1); } LA20: ; } } }BeforeRet: ; } N_NIMCALL(void, genvarstmt_544854_839829468)(Tcproc529021* p0, Tnode292802* n0) { { NI i_544869_839829468; NI HEX3Atmp_544902_839829468; NI LOC2; NI res_544905_839829468; i_544869_839829468 = (NI)0; HEX3Atmp_544902_839829468 = (NI)0; LOC2 = (NI)0; LOC2 = sonslen_295351_850551059(n0); HEX3Atmp_544902_839829468 = (NI)(LOC2 - ((NI) 1)); res_544905_839829468 = ((NI) 0); { while (1) { if (!(res_544905_839829468 <= HEX3Atmp_544902_839829468)) goto LA4; i_544869_839829468 = res_544905_839829468; { Tnode292802* a0; a0 = (*n0).kindU.S6.sons->data[i_544869_839829468]; { if (!((*a0).kind == ((Tnodekind292020) 125))) goto LA8; goto LA5; } LA8: ; { if (!((*a0).kind == ((Tnodekind292020) 35))) goto LA12; { if (!((*(*a0).kindU.S6.sons->data[((NI) 0)]).kind == ((Tnodekind292020) 3))) goto LA16; gensinglevar_544276_839829468(p0, a0); } goto LA14; LA16: ; { genclosurevar_544832_839829468(p0, a0); } LA14: ; } goto LA10; LA12: ; { genvartuple_543794_839829468(p0, a0); } LA10: ; } LA5: ; res_544905_839829468 += ((NI) 1); } LA4: ; } } } static N_INLINE(NIM_BOOL, emitlazily_532248_839829468)(Tsym292834* s0) { NIM_BOOL result0; NIM_BOOL LOC1; Tsym292834* LOC3; result0 = (NIM_BOOL)0; LOC1 = (NIM_BOOL)0; LOC1 = ((gglobaloptions_169130_2607990831 &((NU64)1<<((NU)(((Tglobaloption169013) 2))&63U)))!=0); if (LOC1) goto LA2; LOC3 = (Tsym292834*)0; LOC3 = getmodule_299123_2984716966(s0); LOC1 = (((*LOC3).flags &(1U<<((NU)(((Tsymflag292184) 25))&31U)))!=0); LA2: ; result0 = LOC1; return result0; } N_NIMCALL(void, genconststmt_544909_839829468)(Tcproc529021* p0, Tnode292802* t0) { { NI i_544924_839829468; NI HEX3Atmp_544975_839829468; NI LOC2; NI res_544978_839829468; i_544924_839829468 = (NI)0; HEX3Atmp_544975_839829468 = (NI)0; LOC2 = (NI)0; LOC2 = sonslen_295351_850551059(t0); HEX3Atmp_544975_839829468 = (NI)(LOC2 - ((NI) 1)); res_544978_839829468 = ((NI) 0); { while (1) { if (!(res_544978_839829468 <= HEX3Atmp_544975_839829468)) goto LA4; i_544924_839829468 = res_544978_839829468; { Tnode292802* it0; Tsym292834* c0; it0 = (*t0).kindU.S6.sons->data[i_544924_839829468]; { if (!((*it0).kind == ((Tnodekind292020) 125))) goto LA8; goto LA5; } LA8: ; { if (!!(((*it0).kind == ((Tnodekind292020) 102)))) goto LA12; internalerror_196100_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_328721_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 == ((Ttypekind292244) 4) || (*(*c0).typ).kind == ((Ttypekind292244) 16) || (*(*c0).typ).kind == ((Ttypekind292244) 19) || (*(*c0).typ).kind == ((Ttypekind292244) 18) || (*(*c0).typ).kind == ((Ttypekind292244) 24)); if (!(LOC21)) goto LA22; LOC21 = !((((*c0).loc.flags &(1U<<((NU)(((Tlocflag292810) 3))&15U)))!=0)); LA22: ; LOC20 = LOC21; if (!(LOC20)) goto LA23; LOC24 = (NI)0; LOC24 = len_293081_850551059((*c0).ast); LOC20 = !((LOC24 == ((NI) 0))); LA23: ; if (!LOC20) goto LA25; { NIM_BOOL LOC29; LOC29 = (NIM_BOOL)0; LOC29 = emitlazily_532248_839829468(c0); if (!!(LOC29)) goto LA30; requestconstimpl_539240_839829468(p0, c0); } LA30: ; } goto LA14; LA25: ; LA14: ; } LA5: ; res_544978_839829468 += ((NI) 1); } LA4: ; } } } N_NIMCALL(void, gencasestringbranch_547100_839829468)(Tcproc529021* p0, Tnode292802* b0, Tloc292816 e0, Ropeobj178006* labl0, Ropeobj178006** branches0, NI branches0Len0) { Tloc292816 x0; NI length0; memset((void*)(&x0), 0, sizeof(x0)); length0 = sonslen_295351_850551059(b0); { NI i_547122_839829468; NI HEX3Atmp_547409_839829468; NI res_547412_839829468; i_547122_839829468 = (NI)0; HEX3Atmp_547409_839829468 = (NI)0; HEX3Atmp_547409_839829468 = (NI)(length0 - ((NI) 2)); res_547412_839829468 = ((NI) 0); { while (1) { NI j0; NI64 LOC4; TY535238 LOC5; if (!(res_547412_839829468 <= HEX3Atmp_547409_839829468)) goto LA3; i_547122_839829468 = res_547412_839829468; initlocexpr_539283_839829468(p0, (*b0).kindU.S6.sons->data[i_547122_839829468], (&x0)); LOC4 = (NI64)0; LOC4 = hashstring_528100_2036603609((*(*b0).kindU.S6.sons->data[i_547122_839829468]).kindU.S3.strval); j0 = ((NI) ((NI64)(LOC4 & ((NI64) ((branches0Len0-1)))))); memset((void*)LOC5, 0, sizeof(LOC5)); LOC5[0] = rdloc_538188_839829468(e0); LOC5[1] = rdloc_538188_839829468(x0); LOC5[2] = labl0; appcg_532632_839829468((*p0).module, &branches0[j0], ((NimStringDesc*) &T839829468_595), LOC5, 3); res_547412_839829468 += ((NI) 1); } LA3: ; } } } N_NIMCALL(void, exprblock_544103_839829468)(Tcproc529021* p0, Tnode292802* n0, Tloc292816* d0) { TY533289 LOC1; NI LOC2; memset((void*)LOC1, 0, sizeof(LOC1)); LOC2 = (NI)0; LOC2 = startblock_543978_839829468(p0, ((NimStringDesc*) &T839829468_273), LOC1, 0); expr_539248_839829468(p0, n0, d0); endblock_544060_839829468(p0); } N_NIMCALL(Ropeobj178006*, gencasesecondpass_546965_839829468)(Tcproc529021* p0, Tnode292802* t0, Tloc292816* d0, NI labid0, NI until0) { Ropeobj178006* result0; Ropeobj178006* lend0; result0 = (Ropeobj178006*)0; lend0 = getlabel_539217_839829468(p0); { NI i_546984_839829468; NI res_547017_839829468; i_546984_839829468 = (NI)0; res_547017_839829468 = ((NI) 1); { while (1) { TY178507 LOC10; if (!(res_547017_839829468 <= until0)) goto LA3; i_546984_839829468 = res_547017_839829468; { NIM_BOOL LOC6; LOC6 = (NIM_BOOL)0; LOC6 = ((*d0).k == ((Tlockind292808) 1)); if (!(LOC6)) goto LA7; LOC6 = isemptytype_297440_850551059((*t0).typ); LA7: ; if (!LOC6) goto LA8; (*d0).k = ((Tlockind292808) 0); } LA8: ; memset((void*)LOC10, 0, sizeof(LOC10)); LOC10[0] = rope_178401_2381377266(((NI64) ((NI)(labid0 + i_546984_839829468)))); linef_532700_839829468(p0, ((Tcprocsection529011) 2), ((NimStringDesc*) &T839829468_599), LOC10, 1); { NI length0; TY178507 LOC15; if (!((*(*t0).kindU.S6.sons->data[i_546984_839829468]).kind == ((Tnodekind292020) 85))) goto LA13; length0 = sonslen_295351_850551059((*t0).kindU.S6.sons->data[i_546984_839829468]); exprblock_544103_839829468(p0, (*(*t0).kindU.S6.sons->data[i_546984_839829468]).kindU.S6.sons->data[(NI)(length0 - ((NI) 1))], d0); memset((void*)LOC15, 0, sizeof(LOC15)); LOC15[0] = lend0; linef_532700_839829468(p0, ((Tcprocsection529011) 2), ((NimStringDesc*) &T839829468_556), LOC15, 1); } goto LA11; LA13: ; { exprblock_544103_839829468(p0, (*(*t0).kindU.S6.sons->data[i_546984_839829468]).kindU.S6.sons->data[((NI) 0)], d0); } LA11: ; res_547017_839829468 += ((NI) 1); } LA3: ; } } result0 = lend0; return result0; } N_NIMCALL(void, gencasegenericbranch_546910_839829468)(Tcproc529021* p0, Tnode292802* b0, Tloc292816 e0, NimStringDesc* rangeformat0, NimStringDesc* eqformat0, Ropeobj178006* labl0) { Tloc292816 x0; Tloc292816 y0; NI length0; memset((void*)(&x0), 0, sizeof(x0)); memset((void*)(&y0), 0, sizeof(y0)); length0 = sonslen_295351_850551059(b0); { NI i_546932_839829468; NI HEX3Atmp_546958_839829468; NI res_546961_839829468; i_546932_839829468 = (NI)0; HEX3Atmp_546958_839829468 = (NI)0; HEX3Atmp_546958_839829468 = (NI)(length0 - ((NI) 2)); res_546961_839829468 = ((NI) 0); { while (1) { if (!(res_546961_839829468 <= HEX3Atmp_546958_839829468)) goto LA3; i_546932_839829468 = res_546961_839829468; { TY535235 LOC8; if (!((*(*b0).kindU.S6.sons->data[i_546932_839829468]).kind == ((Tnodekind292020) 44))) goto LA6; initlocexpr_539283_839829468(p0, (*(*b0).kindU.S6.sons->data[i_546932_839829468]).kindU.S6.sons->data[((NI) 0)], (&x0)); initlocexpr_539283_839829468(p0, (*(*b0).kindU.S6.sons->data[i_546932_839829468]).kindU.S6.sons->data[((NI) 1)], (&y0)); memset((void*)LOC8, 0, sizeof(LOC8)); LOC8[0] = rdcharloc_538227_839829468(e0); LOC8[1] = rdcharloc_538227_839829468(x0); LOC8[2] = rdcharloc_538227_839829468(y0); LOC8[3] = labl0; linecg_532707_839829468(p0, ((Tcprocsection529011) 2), rangeformat0, LOC8, 4); } goto LA4; LA6: ; { TY535238 LOC10; initlocexpr_539283_839829468(p0, (*b0).kindU.S6.sons->data[i_546932_839829468], (&x0)); memset((void*)LOC10, 0, sizeof(LOC10)); LOC10[0] = rdcharloc_538227_839829468(e0); LOC10[1] = rdcharloc_538227_839829468(x0); LOC10[2] = labl0; linecg_532707_839829468(p0, ((Tcprocsection529011) 2), eqformat0, LOC10, 3); } LA4: ; res_546961_839829468 += ((NI) 1); } LA3: ; } } } N_NIMCALL(Ropeobj178006*, genifforcaseuntil_547021_839829468)(Tcproc529021* p0, Tnode292802* t0, Tloc292816* d0, NimStringDesc* rangeformat0, NimStringDesc* eqformat0, NI until0, Tloc292816 a0) { Ropeobj178006* result0; NI labid0; result0 = (Ropeobj178006*)0; labid0 = (*p0).labels; { NI i_547042_839829468; NI res_547083_839829468; i_547042_839829468 = (NI)0; res_547083_839829468 = ((NI) 1); { while (1) { if (!(res_547083_839829468 <= until0)) goto LA3; i_547042_839829468 = res_547083_839829468; (*p0).labels += ((NI) 1); { Ropeobj178006* LOC8; Ropeobj178006* LOC9; if (!((*(*t0).kindU.S6.sons->data[i_547042_839829468]).kind == ((Tnodekind292020) 85))) goto LA6; LOC8 = (Ropeobj178006*)0; LOC8 = rope_178401_2381377266(((NI64) ((*p0).labels))); LOC9 = (Ropeobj178006*)0; LOC9 = HEX26_178452_2381377266(((NimStringDesc*) &T839829468_296), LOC8); gencasegenericbranch_546910_839829468(p0, (*t0).kindU.S6.sons->data[i_547042_839829468], a0, rangeformat0, eqformat0, LOC9); } goto LA4; LA6: ; { TY178507 LOC11; memset((void*)LOC11, 0, sizeof(LOC11)); LOC11[0] = rope_178401_2381377266(((NI64) ((*p0).labels))); linef_532700_839829468(p0, ((Tcprocsection529011) 2), ((NimStringDesc*) &T839829468_598), LOC11, 1); } LA4: ; res_547083_839829468 += ((NI) 1); } LA3: ; } } { NI LOC14; NI gototarget0; TY178507 LOC17; TY178507 LOC18; LOC14 = (NI)0; LOC14 = len_293081_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_178401_2381377266(((NI64) (gototarget0))); linef_532700_839829468(p0, ((Tcprocsection529011) 2), ((NimStringDesc*) &T839829468_598), LOC17, 1); result0 = gencasesecondpass_546965_839829468(p0, t0, d0, ((NI) (labid0)), until0); memset((void*)LOC18, 0, sizeof(LOC18)); LOC18[0] = rope_178401_2381377266(((NI64) (gototarget0))); linef_532700_839829468(p0, ((Tcprocsection529011) 2), ((NimStringDesc*) &T839829468_599), LOC18, 1); } goto LA12; LA15: ; { result0 = gencasesecondpass_546965_839829468(p0, t0, d0, ((NI) (labid0)), until0); } LA12: ; return result0; } N_NIMCALL(void, gencasegeneric_547087_839829468)(Tcproc529021* p0, Tnode292802* t0, Tloc292816* d0, NimStringDesc* rangeformat0, NimStringDesc* eqformat0) { Tloc292816 a0; Ropeobj178006* lend0; NI LOC1; memset((void*)(&a0), 0, sizeof(a0)); initlocexpr_539283_839829468(p0, (*t0).kindU.S6.sons->data[((NI) 0)], (&a0)); LOC1 = (NI)0; LOC1 = sonslen_295351_850551059(t0); lend0 = genifforcaseuntil_547021_839829468(p0, t0, d0, rangeformat0, eqformat0, (NI)(LOC1 - ((NI) 1)), a0); fixlabel_539230_839829468(p0, lend0); } N_NIMCALL(void, genstringcase_547416_839829468)(Tcproc529021* p0, Tnode292802* t0, Tloc292816* d0) { NI strings0; strings0 = ((NI) 0); { NI i_547434_839829468; NI HEX3Atmp_547549_839829468; NI LOC2; NI res_547552_839829468; i_547434_839829468 = (NI)0; HEX3Atmp_547549_839829468 = (NI)0; LOC2 = (NI)0; LOC2 = sonslen_295351_850551059(t0); HEX3Atmp_547549_839829468 = (NI)(LOC2 - ((NI) 1)); res_547552_839829468 = ((NI) 1); { while (1) { if (!(res_547552_839829468 <= HEX3Atmp_547549_839829468)) goto LA4; i_547434_839829468 = res_547552_839829468; { NI LOC9; if (!((*(*t0).kindU.S6.sons->data[i_547434_839829468]).kind == ((Tnodekind292020) 85))) goto LA7; LOC9 = (NI)0; LOC9 = sonslen_295351_850551059((*t0).kindU.S6.sons->data[i_547434_839829468]); strings0 += (NI)(LOC9 - ((NI) 1)); } LA7: ; res_547552_839829468 += ((NI) 1); } LA4: ; } } { NI bitmask0; NI LOC14; TY191350* branches0; Tloc292816 a0; NI labid0; TY532811 LOC26; TY533289 LOC35; Ropeobj178006* lend0; NI LOC42; if (!(((NI) 8) < strings0)) goto LA12; LOC14 = (NI)0; LOC14 = nextpoweroftwo_101629_1009420244(strings0); bitmask0 = (NI)(LOC14 - ((NI) 1)); branches0 = (TY191350*)0; branches0 = (TY191350*) newSeq((&NTI191350), ((NI) ((NI)(bitmask0 + ((NI) 1))))); memset((void*)(&a0), 0, sizeof(a0)); initlocexpr_539283_839829468(p0, (*t0).kindU.S6.sons->data[((NI) 0)], (&a0)); labid0 = (*p0).labels; { NI i_547483_839829468; NI HEX3Atmp_547559_839829468; NI LOC16; NI res_547562_839829468; i_547483_839829468 = (NI)0; HEX3Atmp_547559_839829468 = (NI)0; LOC16 = (NI)0; LOC16 = sonslen_295351_850551059(t0); HEX3Atmp_547559_839829468 = (NI)(LOC16 - ((NI) 1)); res_547562_839829468 = ((NI) 1); { while (1) { if (!(res_547562_839829468 <= HEX3Atmp_547559_839829468)) goto LA18; i_547483_839829468 = res_547562_839829468; (*p0).labels += ((NI) 1); { Ropeobj178006* LOC23; Ropeobj178006* LOC24; if (!((*(*t0).kindU.S6.sons->data[i_547483_839829468]).kind == ((Tnodekind292020) 85))) goto LA21; LOC23 = (Ropeobj178006*)0; LOC23 = rope_178401_2381377266(((NI64) ((*p0).labels))); LOC24 = (Ropeobj178006*)0; LOC24 = HEX26_178452_2381377266(((NimStringDesc*) &T839829468_296), LOC23); gencasestringbranch_547100_839829468(p0, (*t0).kindU.S6.sons->data[i_547483_839829468], a0, LOC24, branches0->data, branches0->Sup.len); } goto LA19; LA21: ; { } LA19: ; res_547562_839829468 += ((NI) 1); } LA18: ; } } memset((void*)LOC26, 0, sizeof(LOC26)); LOC26[0] = rdloc_538188_839829468(a0); LOC26[1] = rope_178401_2381377266(((NI64) (bitmask0))); linefmt_532714_839829468(p0, ((Tcprocsection529011) 2), ((NimStringDesc*) &T839829468_596), LOC26, 2); { NI j_547517_839829468; NI HEX3Atmp_547567_839829468; NI res_547570_839829468; j_547517_839829468 = (NI)0; HEX3Atmp_547567_839829468 = (NI)0; HEX3Atmp_547567_839829468 = (branches0 ? (branches0->Sup.len-1) : -1); res_547570_839829468 = ((NI) 0); { while (1) { if (!(res_547570_839829468 <= HEX3Atmp_547567_839829468)) goto LA29; j_547517_839829468 = res_547570_839829468; { TY532811 LOC34; if (!!((branches0->data[j_547517_839829468] == NIM_NIL))) goto LA32; memset((void*)LOC34, 0, sizeof(LOC34)); LOC34[0] = intliteral_539270_839829468(((NI64) (j_547517_839829468))); LOC34[1] = branches0->data[j_547517_839829468]; linef_532700_839829468(p0, ((Tcprocsection529011) 2), ((NimStringDesc*) &T839829468_597), LOC34, 2); } LA32: ; res_547570_839829468 += ((NI) 1); } LA29: ; } } memset((void*)LOC35, 0, sizeof(LOC35)); linef_532700_839829468(p0, ((Tcprocsection529011) 2), ((NimStringDesc*) &T839829468_160), LOC35, 0); { NI LOC38; TY178507 LOC41; LOC38 = (NI)0; LOC38 = sonslen_295351_850551059(t0); if (!!(((*(*t0).kindU.S6.sons->data[(NI)(LOC38 - ((NI) 1))]).kind == ((Tnodekind292020) 85)))) goto LA39; memset((void*)LOC41, 0, sizeof(LOC41)); LOC41[0] = rope_178401_2381377266(((NI64) ((*p0).labels))); linef_532700_839829468(p0, ((Tcprocsection529011) 2), ((NimStringDesc*) &T839829468_598), LOC41, 1); } LA39: ; LOC42 = (NI)0; LOC42 = sonslen_295351_850551059(t0); lend0 = gencasesecondpass_546965_839829468(p0, t0, d0, ((NI) (labid0)), (NI)(LOC42 - ((NI) 1))); fixlabel_539230_839829468(p0, lend0); } goto LA10; LA12: ; { gencasegeneric_547087_839829468(p0, t0, d0, ((NimStringDesc*) &T839829468_490), ((NimStringDesc*) &T839829468_595)); } LA10: ; } N_NIMCALL(void, gengotoforcase_545673_839829468)(Tcproc529021* p0, Tnode292802* casestmt0) { { { NI i_545695_839829468; NI HEX3Atmp_545737_839829468; NI LOC2; NI res_545740_839829468; i_545695_839829468 = (NI)0; HEX3Atmp_545737_839829468 = (NI)0; LOC2 = (NI)0; LOC2 = len_293081_850551059(casestmt0); HEX3Atmp_545737_839829468 = (LOC2 - 1); res_545740_839829468 = ((NI) 1); { while (1) { TY533289 LOC5; NI LOC6; Tnode292802* it0; Tnode292802* LOC16; if (!(res_545740_839829468 <= HEX3Atmp_545737_839829468)) goto LA4; i_545695_839829468 = res_545740_839829468; memset((void*)LOC5, 0, sizeof(LOC5)); LOC6 = (NI)0; LOC6 = startblock_543978_839829468(p0, ((NimStringDesc*) &T839829468_273), LOC5, 0); it0 = (*casestmt0).kindU.S6.sons->data[i_545695_839829468]; { NI j_545711_839829468; NI HEX3Atmp_545730_839829468; NI LOC8; NI res_545733_839829468; j_545711_839829468 = (NI)0; HEX3Atmp_545730_839829468 = (NI)0; LOC8 = (NI)0; LOC8 = len_293081_850551059(it0); HEX3Atmp_545730_839829468 = (NI)(LOC8 - ((NI) 2)); res_545733_839829468 = ((NI) 0); { while (1) { NI64 val0; TY178507 LOC15; if (!(res_545733_839829468 <= HEX3Atmp_545730_839829468)) goto LA10; j_545711_839829468 = res_545733_839829468; { if (!((*(*it0).kindU.S6.sons->data[j_545711_839829468]).kind == ((Tnodekind292020) 44))) goto LA13; localerror_196085_155036129((*it0).info, ((NimStringDesc*) &T839829468_579)); goto BeforeRet; } LA13: ; val0 = getordvalue_320129_3876443242((*it0).kindU.S6.sons->data[j_545711_839829468]); memset((void*)LOC15, 0, sizeof(LOC15)); LOC15[0] = rope_178401_2381377266(val0); linef_532700_839829468(p0, ((Tcprocsection529011) 2), ((NimStringDesc*) &T839829468_602), LOC15, 1); res_545733_839829468 += ((NI) 1); } LA10: ; } } LOC16 = (Tnode292802*)0; LOC16 = lastson_295364_850551059(it0); genstmts_539244_839829468(p0, LOC16); endblock_544060_839829468(p0); res_545740_839829468 += ((NI) 1); } LA4: ; } } }BeforeRet: ; } N_NIMCALL(NIM_BOOL, branchhastoobigrange_547575_839829468)(Tnode292802* b0) { NIM_BOOL result0; { result0 = (NIM_BOOL)0; { NI i_547590_839829468; NI HEX3Atmp_547608_839829468; NI LOC2; NI res_547611_839829468; i_547590_839829468 = (NI)0; HEX3Atmp_547608_839829468 = (NI)0; LOC2 = (NI)0; LOC2 = sonslen_295351_850551059(b0); HEX3Atmp_547608_839829468 = (NI)(LOC2 - ((NI) 2)); res_547611_839829468 = ((NI) 0); { while (1) { if (!(res_547611_839829468 <= HEX3Atmp_547608_839829468)) goto LA4; i_547590_839829468 = res_547611_839829468; { NIM_BOOL LOC7; LOC7 = (NIM_BOOL)0; LOC7 = ((*(*b0).kindU.S6.sons->data[i_547590_839829468]).kind == ((Tnodekind292020) 44)); if (!(LOC7)) goto LA8; LOC7 = (IL64(256) < (NI64)((*(*(*b0).kindU.S6.sons->data[i_547590_839829468]).kindU.S6.sons->data[((NI) 1)]).kindU.S1.intval - (*(*(*b0).kindU.S6.sons->data[i_547590_839829468]).kindU.S6.sons->data[((NI) 0)]).kindU.S1.intval)); LA8: ; if (!LOC7) goto LA9; result0 = NIM_TRUE; goto BeforeRet; } LA9: ; res_547611_839829468 += ((NI) 1); } LA4: ; } } }BeforeRet: ; return result0; } N_NIMCALL(NI, ifswitchsplitpoint_547615_839829468)(Tcproc529021* p0, Tnode292802* n0) { NI result0; result0 = (NI)0; { NI i_547630_839829468; NI HEX3Atmp_547654_839829468; NI LOC2; NI res_547657_839829468; i_547630_839829468 = (NI)0; HEX3Atmp_547654_839829468 = (NI)0; LOC2 = (NI)0; LOC2 = len_293081_850551059(n0); HEX3Atmp_547654_839829468 = (NI)(LOC2 - ((NI) 1)); res_547657_839829468 = ((NI) 1); { while (1) { Tnode292802* branch0; Tnode292802* stmtblock0; if (!(res_547657_839829468 <= HEX3Atmp_547654_839829468)) goto LA4; i_547630_839829468 = res_547657_839829468; branch0 = HEX5BHEX5D_293238_850551059(n0, i_547630_839829468); stmtblock0 = lastson_295364_850551059(branch0); { NIM_BOOL LOC7; LOC7 = (NIM_BOOL)0; LOC7 = stmtscontainpragma_528083_2036603609(stmtblock0, ((Tspecialword275003) 181)); if (!LOC7) goto LA8; result0 = i_547630_839829468; } goto LA5; LA8: ; { if (!!(((Cc_273413_2528170400[(ccompiler_273431_2528170400)- 1].Field20 &(1U<<((NU)(((Tinfoccprop273004) 0))&7U)))!=0))) goto LA11; { NIM_BOOL LOC15; LOC15 = (NIM_BOOL)0; LOC15 = ((*branch0).kind == ((Tnodekind292020) 85)); if (!(LOC15)) goto LA16; LOC15 = branchhastoobigrange_547575_839829468(branch0); LA16: ; if (!LOC15) goto LA17; result0 = i_547630_839829468; } LA17: ; } goto LA5; LA11: ; LA5: ; res_547657_839829468 += ((NI) 1); } LA4: ; } } return result0; } N_NIMCALL(void, genordinalcase_547724_839829468)(Tcproc529021* p0, Tnode292802* n0, Tloc292816* d0) { NI splitpoint0; Tloc292816 a0; Ropeobj178006* lend0; splitpoint0 = ifswitchsplitpoint_547615_839829468(p0, n0); memset((void*)(&a0), 0, sizeof(a0)); initlocexpr_539283_839829468(p0, (*n0).kindU.S6.sons->data[((NI) 0)], (&a0)); { if (!(((NI) 0) < splitpoint0)) goto LA3; lend0 = genifforcaseuntil_547021_839829468(p0, n0, d0, ((NimStringDesc*) &T839829468_600), ((NimStringDesc*) &T839829468_601), splitpoint0, a0); } goto LA1; LA3: ; { lend0 = NIM_NIL; } LA1: ; { NI LOC8; TY178507 LOC11; NIM_BOOL hasdefault0; TY533289 LOC37; LOC8 = (NI)0; LOC8 = len_293081_850551059(n0); if (!((NI)(splitpoint0 + ((NI) 1)) < LOC8)) goto LA9; memset((void*)LOC11, 0, sizeof(LOC11)); LOC11[0] = rdcharloc_538227_839829468(a0); linef_532700_839829468(p0, ((Tcprocsection529011) 2), ((NimStringDesc*) &T839829468_603), LOC11, 1); hasdefault0 = NIM_FALSE; { NI i_547757_839829468; NI HEX3Atmp_547816_839829468; NI HEX3Atmp_547817_839829468; NI LOC13; NI res_547820_839829468; i_547757_839829468 = (NI)0; HEX3Atmp_547816_839829468 = (NI)0; HEX3Atmp_547817_839829468 = (NI)0; HEX3Atmp_547816_839829468 = (NI)(splitpoint0 + ((NI) 1)); LOC13 = (NI)0; LOC13 = len_293081_850551059(n0); HEX3Atmp_547817_839829468 = (LOC13 - 1); res_547820_839829468 = HEX3Atmp_547816_839829468; { while (1) { Tnode292802* branch0; Tnode292802* LOC28; TY533289 LOC29; if (!(res_547820_839829468 <= HEX3Atmp_547817_839829468)) goto LA15; i_547757_839829468 = res_547820_839829468; { NIM_BOOL LOC18; LOC18 = (NIM_BOOL)0; LOC18 = ((*d0).k == ((Tlockind292808) 1)); if (!(LOC18)) goto LA19; LOC18 = isemptytype_297440_850551059((*n0).typ); LA19: ; if (!LOC18) goto LA20; (*d0).k = ((Tlockind292808) 0); } LA20: ; branch0 = HEX5BHEX5D_293238_850551059(n0, i_547757_839829468); { if (!((*branch0).kind == ((Tnodekind292020) 85))) goto LA24; gencaserange_537028_839829468(p0, branch0); } goto LA22; LA24: ; { TY533289 LOC27; memset((void*)LOC27, 0, sizeof(LOC27)); linef_532700_839829468(p0, ((Tcprocsection529011) 2), ((NimStringDesc*) &T839829468_181), LOC27, 0); hasdefault0 = NIM_TRUE; } LA22: ; LOC28 = (Tnode292802*)0; LOC28 = lastson_295364_850551059(branch0); exprblock_544103_839829468(p0, LOC28, d0); memset((void*)LOC29, 0, sizeof(LOC29)); linef_532700_839829468(p0, ((Tcprocsection529011) 2), ((NimStringDesc*) &T839829468_182), LOC29, 0); res_547820_839829468 += ((NI) 1); } LA15: ; } } { NIM_BOOL LOC32; TY533289 LOC36; LOC32 = (NIM_BOOL)0; LOC32 = ((Cc_273413_2528170400[(ccompiler_273431_2528170400)- 1].Field20 &(1U<<((NU)(((Tinfoccprop273004) 3))&7U)))!=0); if (!(LOC32)) goto LA33; LOC32 = !(hasdefault0); LA33: ; if (!LOC32) goto LA34; memset((void*)LOC36, 0, sizeof(LOC36)); linef_532700_839829468(p0, ((Tcprocsection529011) 2), ((NimStringDesc*) &T839829468_604), LOC36, 0); } LA34: ; memset((void*)LOC37, 0, sizeof(LOC37)); linef_532700_839829468(p0, ((Tcprocsection529011) 2), ((NimStringDesc*) &T839829468_160), LOC37, 0); } LA9: ; { if (!!((lend0 == NIM_NIL))) goto LA40; fixlabel_539230_839829468(p0, lend0); } LA40: ; } N_NIMCALL(void, gencase_547826_839829468)(Tcproc529021* p0, Tnode292802* t0, Tloc292816* d0) { Ttype292840* LOC8; genlinedir_532823_839829468(p0, t0); { NIM_BOOL LOC3; NIM_BOOL LOC4; LOC3 = (NIM_BOOL)0; LOC4 = (NIM_BOOL)0; LOC4 = isemptytype_297440_850551059((*t0).typ); LOC3 = !(LOC4); if (!(LOC3)) goto LA5; LOC3 = ((*d0).k == ((Tlockind292808) 0)); LA5: ; if (!LOC3) goto LA6; gettemp_537032_839829468(p0, (*t0).typ, d0, NIM_FALSE); } LA6: ; LOC8 = (Ttype292840*)0; LOC8 = skiptypes_296099_850551059((*(*t0).kindU.S6.sons->data[((NI) 0)]).typ, IL64(211106242013440)); switch ((*LOC8).kind) { case ((Ttypekind292244) 28): { genstringcase_547416_839829468(p0, t0, d0); } break; case ((Ttypekind292244) 36) ... ((Ttypekind292244) 39): { gencasegeneric_547087_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 == ((Tnodekind292020) 3)); if (!(LOC14)) goto LA15; LOC14 = (((*(*(*t0).kindU.S6.sons->data[((NI) 0)]).kindU.S4.sym).flags &(1U<<((NU)(((Tsymflag292184) 30))&31U)))!=0); LA15: ; if (!LOC14) goto LA16; gengotoforcase_545673_839829468(p0, t0); } goto LA12; LA16: ; { genordinalcase_547724_839829468(p0, t0, d0); } LA12: ; } break; } } static N_INLINE(Tnode292802*, pop_318246_1689653243)(Tnodeseq292796** s0) { Tnode292802* result0; NI L0; result0 = (Tnode292802*)0; L0 = (NI)(((*s0) ? (*s0)->Sup.len : 0) - ((NI) 1)); result0 = (*s0)->data[L0]; (*s0) = (Tnodeseq292796*) setLengthSeq(&((*s0))->Sup, sizeof(Tnode292802*), ((NI) (L0))); return result0; } N_NIMCALL(void, blockleaveactions_545442_839829468)(Tcproc529021* p0, NI howmanytrys0, NI howmanyexcepts0) { Tnodeseq292796* stack0; NI alreadypoppedcnt0; stack0 = (Tnodeseq292796*)0; stack0 = (Tnodeseq292796*) newSeq((&NTI292796), ((NI) 0)); alreadypoppedcnt0 = (*p0).inexceptblock; { NI i_545471_839829468; NI res_545596_839829468; i_545471_839829468 = (NI)0; res_545596_839829468 = ((NI) 1); { while (1) { Tnode292802* trystmt0; Tnode292802* finallystmt0; if (!(res_545596_839829468 <= howmanytrys0)) goto LA3; i_545471_839829468 = res_545596_839829468; { NIM_BOOL LOC6; LOC6 = (NIM_BOOL)0; LOC6 = (gcmd_169132_2607990831 == ((Tcommands169076) 2)); if (LOC6) goto LA7; LOC6 = (((*(*(*p0).module).module).flags &(1U<<((NU)(((Tsymflag292184) 27))&31U)))!=0); LA7: ; if (!!(LOC6)) goto LA8; { if (!(((NI) 0) < alreadypoppedcnt0)) goto LA12; alreadypoppedcnt0 -= ((NI) 1); } goto LA10; LA12: ; { TY533289 LOC15; memset((void*)LOC15, 0, sizeof(LOC15)); linefmt_532714_839829468(p0, ((Tcprocsection529011) 2), ((NimStringDesc*) &T839829468_605), LOC15, 0); } LA10: ; } LA8: ; trystmt0 = pop_318246_1689653243((&(*p0).nestedtrystmts)); stack0 = (Tnodeseq292796*) incrSeqV2(&(stack0)->Sup, sizeof(Tnode292802*)); asgnRefNoCycle((void**) (&stack0->data[stack0->Sup.len]), trystmt0); ++stack0->Sup.len; finallystmt0 = lastson_295364_850551059(trystmt0); { if (!((*finallystmt0).kind == ((Tnodekind292020) 107))) goto LA18; genstmts_539244_839829468(p0, (*finallystmt0).kindU.S6.sons->data[((NI) 0)]); } LA18: ; res_545596_839829468 += ((NI) 1); } LA3: ; } } { NI i_545546_839829468; NI HEX3Atmp_545601_839829468; NI res_545604_839829468; i_545546_839829468 = (NI)0; HEX3Atmp_545601_839829468 = (NI)0; HEX3Atmp_545601_839829468 = (NI)(howmanytrys0 - ((NI) 1)); res_545604_839829468 = HEX3Atmp_545601_839829468; { while (1) { if (!(((NI) 0) <= res_545604_839829468)) goto LA22; i_545546_839829468 = res_545604_839829468; (*p0).nestedtrystmts = (Tnodeseq292796*) incrSeqV2(&((*p0).nestedtrystmts)->Sup, sizeof(Tnode292802*)); asgnRefNoCycle((void**) (&(*p0).nestedtrystmts->data[(*p0).nestedtrystmts->Sup.len]), stack0->data[i_545546_839829468]); ++(*p0).nestedtrystmts->Sup.len; res_545604_839829468 -= ((NI) 1); } LA22: ; } } { NIM_BOOL LOC25; LOC25 = (NIM_BOOL)0; LOC25 = (gcmd_169132_2607990831 == ((Tcommands169076) 2)); if (LOC25) goto LA26; LOC25 = (((*(*(*p0).module).module).flags &(1U<<((NU)(((Tsymflag292184) 27))&31U)))!=0); LA26: ; if (!!(LOC25)) goto LA27; { NI i_545587_839829468; NI HEX3Atmp_545610_839829468; NI res_545613_839829468; i_545587_839829468 = (NI)0; HEX3Atmp_545610_839829468 = (NI)0; HEX3Atmp_545610_839829468 = (NI)(howmanyexcepts0 - ((NI) 1)); res_545613_839829468 = HEX3Atmp_545610_839829468; { while (1) { TY533289 LOC32; if (!(((NI) 0) <= res_545613_839829468)) goto LA31; i_545587_839829468 = res_545613_839829468; memset((void*)LOC32, 0, sizeof(LOC32)); linefmt_532714_839829468(p0, ((Tcprocsection529011) 2), ((NimStringDesc*) &T839829468_606), LOC32, 0); res_545613_839829468 -= ((NI) 1); } LA31: ; } } } LA27: ; } N_NIMCALL(void, genreturnstmt_545617_839829468)(Tcproc529021* p0, Tnode292802* t0) { TY533289 LOC14; { { if (!(((*t0).flags &(1U<<((NU)(((Tnodeflag292427) 14))&15U)))!=0)) goto LA3; goto BeforeRet; } LA3: ; (*p0).beforeretneeded = NIM_TRUE; genlinedir_532823_839829468(p0, t0); { if (!!(((*(*t0).kindU.S6.sons->data[((NI) 0)]).kind == ((Tnodekind292020) 1)))) goto LA7; genstmts_539244_839829468(p0, (*t0).kindU.S6.sons->data[((NI) 0)]); } LA7: ; blockleaveactions_545442_839829468(p0, ((*p0).nestedtrystmts ? (*p0).nestedtrystmts->Sup.len : 0), (*p0).inexceptblock); { Ropeobj178006* safepoint0; TY178507 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_532714_839829468(p0, ((Tcprocsection529011) 2), ((NimStringDesc*) &T839829468_607), LOC13, 1); } LA11: ; memset((void*)LOC14, 0, sizeof(LOC14)); linef_532700_839829468(p0, ((Tcprocsection529011) 2), ((NimStringDesc*) &T839829468_608), LOC14, 0); }BeforeRet: ; } N_NIMCALL(void, genbreakstmt_546444_839829468)(Tcproc529021* p0, Tnode292802* t0) { NI idx0; Ropeobj178006* label0; TY178507 LOC16; idx0 = (*p0).breakidx; { Tsym292834* sym0; if (!!(((*(*t0).kindU.S6.sons->data[((NI) 0)]).kind == ((Tnodekind292020) 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_196100_155036129((*t0).info, ((NimStringDesc*) &T839829468_609)); } LA14: ; } LA1: ; label0 = assignlabel_544020_839829468((&(*p0).blocks->data[idx0])); blockleaveactions_545442_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_532823_839829468(p0, t0); memset((void*)LOC16, 0, sizeof(LOC16)); LOC16[0] = label0; linef_532700_839829468(p0, ((Tcprocsection529011) 2), ((NimStringDesc*) &T839829468_556), LOC16, 1); } N_NIMCALL(NIM_BOOL, fielddiscriminantcheckneeded_549080_839829468)(Tcproc529021* p0, Tnode292802* asgn0) { NIM_BOOL result0; result0 = (NIM_BOOL)0; { Tnode292802* le0; if (!(((*p0).options &(1U<<((NU)(((Toption169009) 2))&31U)))!=0)) goto LA3; le0 = (*asgn0).kindU.S6.sons->data[((NI) 0)]; { Tsym292834* field0; if (!((*le0).kind == ((Tnodekind292020) 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)(((Tsymflag292184) 18))&31U)))!=0); } goto LA5; LA7: ; { Tsym292834* field0; if (!((*le0).kind == ((Tnodekind292020) 45))) goto LA10; field0 = (*(*le0).kindU.S6.sons->data[((NI) 1)]).kindU.S4.sym; result0 = (((*field0).flags &(1U<<((NU)(((Tsymflag292184) 18))&31U)))!=0); } goto LA5; LA10: ; LA5: ; } LA3: ; return result0; } N_NIMCALL(Ropeobj178006*, discriminatortabledecl_536094_839829468)(Tcgen529027* m0, Ttype292840* objtype0, Tsym292834* d0) { Ropeobj178006* result0; Ropeobj178006* LOC1; Ropeobj178006* tmp0; TY532811 LOC2; NI64 LOC3; result0 = (Ropeobj178006*)0; LOC1 = (Ropeobj178006*)0; LOC1 = cgsym_532403_839829468(m0, ((NimStringDesc*) &T839829468_130)); tmp0 = discriminatortablename_536057_839829468(m0, objtype0, d0); memset((void*)LOC2, 0, sizeof(LOC2)); LOC2[0] = tmp0; LOC3 = (NI64)0; LOC3 = lengthord_320007_3876443242((*d0).typ); LOC2[1] = rope_178401_2381377266((NI64)(LOC3 + IL64(1))); result0 = HEX25_178905_2381377266(((NimStringDesc*) &T839829468_203), LOC2, 2); return result0; } N_NIMCALL(void, gendiscriminantcheck_549144_839829468)(Tcproc529021* p0, Tloc292816 a0, Tloc292816 tmp0, Ttype292840* objtype0, Tsym292834* field0) { Ttype292840* t0; Ropeobj178006* LOC1; NI64 L0; TY535235 LOC8; t0 = skiptypes_296099_850551059(objtype0, IL64(211106240964864)); LOC1 = (Ropeobj178006*)0; LOC1 = gentypeinfo_535941_839829468((*p0).module, t0); L0 = lengthord_320007_3876443242((*field0).typ); { NIM_BOOL LOC4; TY178507 LOC7; LOC4 = (NIM_BOOL)0; LOC4 = containsorincl_268862_2627731572((&(*(*p0).module).declaredthings), (*field0).Sup.id); if (!!(LOC4)) goto LA5; memset((void*)LOC7, 0, sizeof(LOC7)); LOC7[0] = discriminatortabledecl_536094_839829468((*p0).module, t0, field0); appcg_532640_839829468((*p0).module, ((Tcfilesection529005) 9), ((NimStringDesc*) &T839829468_610), LOC7, 1); } LA5: ; memset((void*)LOC8, 0, sizeof(LOC8)); LOC8[0] = rdloc_538188_839829468(a0); LOC8[1] = rdloc_538188_839829468(tmp0); LOC8[2] = discriminatortablename_536057_839829468((*p0).module, t0, field0); LOC8[3] = intliteral_539270_839829468((NI64)(L0 + IL64(1))); linecg_532707_839829468(p0, ((Tcprocsection529011) 2), ((NimStringDesc*) &T839829468_611), LOC8, 4); } N_NIMCALL(void, asgnfielddiscriminant_549209_839829468)(Tcproc529021* p0, Tnode292802* e0) { Tloc292816 a0; Tloc292816 tmp0; Tnode292802* dotexpr0; memset((void*)(&a0), 0, sizeof(a0)); memset((void*)(&tmp0), 0, sizeof(tmp0)); dotexpr0 = (*e0).kindU.S6.sons->data[((NI) 0)]; { if (!((*dotexpr0).kind == ((Tnodekind292020) 46))) goto LA3; dotexpr0 = (*dotexpr0).kindU.S6.sons->data[((NI) 0)]; } LA3: ; initlocexpr_539283_839829468(p0, (*e0).kindU.S6.sons->data[((NI) 0)], (&a0)); gettemp_537032_839829468(p0, a0.t, (&tmp0), NIM_FALSE); expr_539248_839829468(p0, (*e0).kindU.S6.sons->data[((NI) 1)], (&tmp0)); gendiscriminantcheck_549144_839829468(p0, a0, tmp0, (*(*dotexpr0).kindU.S6.sons->data[((NI) 0)]).typ, (*(*dotexpr0).kindU.S6.sons->data[((NI) 1)]).kindU.S4.sym); genassignment_539264_839829468(p0, a0, tmp0, 0); } N_NIMCALL(void, genasgn_549239_839829468)(Tcproc529021* p0, Tnode292802* e0, NIM_BOOL fastasgn0) { genlinedir_532823_839829468(p0, e0); { NIM_BOOL LOC3; LOC3 = (NIM_BOOL)0; LOC3 = ((*(*e0).kindU.S6.sons->data[((NI) 0)]).kind == ((Tnodekind292020) 3)); if (!(LOC3)) goto LA4; LOC3 = (((*(*(*e0).kindU.S6.sons->data[((NI) 0)]).kindU.S4.sym).flags &(1U<<((NU)(((Tsymflag292184) 30))&31U)))!=0); LA4: ; if (!LOC3) goto LA5; gengotovar_544258_839829468(p0, (*e0).kindU.S6.sons->data[((NI) 1)]); } goto LA1; LA5: ; { NIM_BOOL LOC8; Tloc292816 a0; LOC8 = (NIM_BOOL)0; LOC8 = fielddiscriminantcheckneeded_549080_839829468(p0, e0); if (!!(LOC8)) goto LA9; memset((void*)(&a0), 0, sizeof(a0)); { Tnode292802* LOC13; Tnode292802* LOC16; LOC13 = (Tnode292802*)0; LOC13 = HEX5BHEX5D_293238_850551059(e0, ((NI) 0)); if (!((*LOC13).kind == ((Tnodekind292020) 47) || (*LOC13).kind == ((Tnodekind292020) 65))) goto LA14; LOC16 = (Tnode292802*)0; LOC16 = HEX5BHEX5D_293238_850551059(e0, ((NI) 0)); genderef_543921_839829468(p0, LOC16, (&a0), NIM_TRUE); } goto LA11; LA14: ; { initlocexpr_539283_839829468(p0, (*e0).kindU.S6.sons->data[((NI) 0)], (&a0)); } LA11: ; { if (!fastasgn0) goto LA20; a0.flags |= ((NU16)1)<<((((Tlocflag292810) 2))%(sizeof(NU16)*8)); } LA20: ; loadinto_543928_839829468(p0, (*e0).kindU.S6.sons->data[((NI) 0)], (*e0).kindU.S6.sons->data[((NI) 1)], (&a0)); } goto LA1; LA9: ; { asgnfielddiscriminant_549209_839829468(p0, e0); } LA1: ; } N_NIMCALL(Ropeobj178006*, genasmoremitstmt_548529_839829468)(Tcproc529021* p0, Tnode292802* t0, NIM_BOOL isasmstmt0) { Ropeobj178006* result0; NimStringDesc* res0; result0 = (Ropeobj178006*)0; res0 = copyString(((NimStringDesc*) &T839829468_490)); { NI i_548547_839829468; NI HEX3Atmp_548644_839829468; NI LOC2; NI res_548647_839829468; i_548547_839829468 = (NI)0; HEX3Atmp_548644_839829468 = (NI)0; LOC2 = (NI)0; LOC2 = sonslen_295351_850551059(t0); HEX3Atmp_548644_839829468 = (NI)(LOC2 - ((NI) 1)); res_548647_839829468 = ((NI) 0); { while (1) { if (!(res_548647_839829468 <= HEX3Atmp_548644_839829468)) goto LA4; i_548547_839829468 = res_548647_839829468; switch ((*(*t0).kindU.S6.sons->data[i_548547_839829468]).kind) { case ((Tnodekind292020) 20) ... ((Tnodekind292020) 22): { res0 = resizeString(res0, (*(*t0).kindU.S6.sons->data[i_548547_839829468]).kindU.S3.strval->Sup.len + 0); appendString(res0, (*(*t0).kindU.S6.sons->data[i_548547_839829468]).kindU.S3.strval); } break; case ((Tnodekind292020) 3): { Tsym292834* sym0; sym0 = (*(*t0).kindU.S6.sons->data[i_548547_839829468]).kindU.S4.sym; { Tloc292816 a0; Ropeobj178006* LOC11; NimStringDesc* LOC12; if (!((28672 &(1U<<((NU)((*sym0).kind)&31U)))!=0)) goto LA9; memset((void*)(&a0), 0, sizeof(a0)); initlocexpr_539283_839829468(p0, (*t0).kindU.S6.sons->data[i_548547_839829468], (&a0)); LOC11 = (Ropeobj178006*)0; LOC11 = rdloc_538188_839829468(a0); LOC12 = (NimStringDesc*)0; LOC12 = HEX24_178856_2381377266(LOC11); res0 = resizeString(res0, LOC12->Sup.len + 0); appendString(res0, LOC12); } goto LA7; LA9: ; { Ropeobj178006* LOC16; NimStringDesc* LOC17; if (!((*sym0).kind == ((Tsymkind292435) 7))) goto LA14; LOC16 = (Ropeobj178006*)0; LOC16 = gettypedesc_535671_839829468((*p0).module, (*sym0).typ); LOC17 = (NimStringDesc*)0; LOC17 = HEX24_178856_2381377266(LOC16); res0 = resizeString(res0, LOC17->Sup.len + 0); appendString(res0, LOC17); } goto LA7; LA14: ; { Ropeobj178006* r0; NimStringDesc* LOC23; r0 = (*sym0).loc.r; { if (!(r0 == NIM_NIL)) goto LA21; r0 = manglename_533205_839829468(sym0); asgnRefNoCycle((void**) (&(*sym0).loc.r), r0); } LA21: ; LOC23 = (NimStringDesc*)0; LOC23 = HEX24_178856_2381377266(r0); res0 = resizeString(res0, LOC23->Sup.len + 0); appendString(res0, LOC23); } LA7: ; } break; default: { internalerror_196100_155036129((*(*t0).kindU.S6.sons->data[i_548547_839829468]).info, ((NimStringDesc*) &T839829468_612)); } break; } res_548647_839829468 += ((NI) 1); } LA4: ; } } { NIM_BOOL LOC27; LOC27 = (NIM_BOOL)0; LOC27 = isasmstmt0; if (!(LOC27)) goto LA28; LOC27 = ((Cc_273413_2528170400[(ccompiler_273431_2528170400)- 1].Field20 &(1U<<((NU)(((Tinfoccprop273004) 5))&7U)))!=0); LA28: ; if (!LOC27) goto LA29; { NimStringDesc* x_548604_839829468; NI first_548656_839829468; NI last_548658_839829468; x_548604_839829468 = (NimStringDesc*)0; first_548656_839829468 = ((NI) 0); last_548658_839829468 = ((NI) 0); { while (1) { NI j0; { while (1) { if (!!((((NU8)(res0->data[last_548658_839829468])) == ((NU8)(0)) || ((NU8)(res0->data[last_548658_839829468])) == ((NU8)(13)) || ((NU8)(res0->data[last_548658_839829468])) == ((NU8)(10))))) goto LA35; last_548658_839829468 += ((NI) 1); } LA35: ; } x_548604_839829468 = copyStrLast(res0, first_548656_839829468, (NI)(last_548658_839829468 - ((NI) 1))); j0 = ((NI) 0); { while (1) { if (!(((NU8)(x_548604_839829468->data[j0])) == ((NU8)(32)) || ((NU8)(x_548604_839829468->data[j0])) == ((NU8)(9)))) goto LA37; j0 += ((NI) 1); } LA37: ; } { if (!(((NU8)(x_548604_839829468->data[j0])) == ((NU8)(34)) || ((NU8)(x_548604_839829468->data[j0])) == ((NU8)(58)))) goto LA40; add_178487_2381377266(&result0, x_548604_839829468); add_178487_2381377266(&result0, tnl_176644_4151366050); } goto LA38; LA40: ; { if (!!(((NU8)(x_548604_839829468->data[j0]) == (NU8)(0)))) goto LA43; add_178487_2381377266(&result0, ((NimStringDesc*) &T839829468_613)); add_178487_2381377266(&result0, x_548604_839829468); add_178487_2381377266(&result0, ((NimStringDesc*) &T839829468_614)); } goto LA38; LA43: ; LA38: ; { if (!((NU8)(res0->data[last_548658_839829468]) == (NU8)(10))) goto LA47; last_548658_839829468 += ((NI) 1); } goto LA45; LA47: ; { if (!((NU8)(res0->data[last_548658_839829468]) == (NU8)(13))) goto LA50; last_548658_839829468 += ((NI) 1); { if (!((NU8)(res0->data[last_548658_839829468]) == (NU8)(10))) goto LA54; last_548658_839829468 += ((NI) 1); } LA54: ; } goto LA45; LA50: ; { goto LA32; } LA45: ; first_548656_839829468 = last_548658_839829468; } } LA32: ; } } goto LA25; LA29: ; { res0 = resizeString(res0, tnl_176644_4151366050->Sup.len + 0); appendString(res0, tnl_176644_4151366050); result0 = rope_178277_2381377266(res0); } LA25: ; return result0; } N_NIMCALL(void, genasmstmt_548659_839829468)(Tcproc529021* p0, Tnode292802* t0) { Ropeobj178006* s0; genlinedir_532823_839829468(p0, t0); s0 = genasmoremitstmt_548529_839829468(p0, t0, NIM_TRUE); { TY178507 LOC5; if (!((*p0).prc == NIM_NIL)) goto LA3; memset((void*)LOC5, 0, sizeof(LOC5)); LOC5[0] = s0; addf_179205_2381377266(&(*(*p0).module).s[(((Tcfilesection529005) 7))- 0], Cc_273413_2528170400[(ccompiler_273431_2528170400)- 1].Field17, LOC5, 1); } goto LA1; LA3: ; { TY178507 LOC7; memset((void*)LOC7, 0, sizeof(LOC7)); LOC7[0] = s0; linef_532700_839829468(p0, ((Tcprocsection529011) 2), Cc_273413_2528170400[(ccompiler_273431_2528170400)- 1].Field17, LOC7, 1); } LA1: ; } static N_INLINE(void, gensimpleblock_544095_839829468)(Tcproc529021* p0, Tnode292802* stmts0) { TY533289 LOC1; NI LOC2; memset((void*)LOC1, 0, sizeof(LOC1)); LOC2 = (NI)0; LOC2 = startblock_543978_839829468(p0, ((NimStringDesc*) &T839829468_273), LOC1, 0); genstmts_539244_839829468(p0, stmts0); endblock_544060_839829468(p0); } N_NIMCALL(void, gentrycpp_547865_839829468)(Tcproc529021* p0, Tnode292802* t0, Tloc292816* d0) { Ropeobj178006* exc0; TY533289 LOC16; NI LOC17; NI length0; TY178507 LOC18; Ropeobj178006* LOC19; NI i0; NIM_BOOL catchallpresent0; TY533289 LOC78; Tnode292802* LOC79; { NIM_BOOL LOC3; NIM_BOOL LOC4; LOC3 = (NIM_BOOL)0; LOC4 = (NIM_BOOL)0; LOC4 = isemptytype_297440_850551059((*t0).typ); LOC3 = !(LOC4); if (!(LOC3)) goto LA5; LOC3 = ((*d0).k == ((Tlockind292808) 0)); LA5: ; if (!LOC3) goto LA6; gettemp_537032_839829468(p0, (*t0).typ, d0, NIM_FALSE); } LA6: ; genlinedir_532823_839829468(p0, t0); exc0 = gettempname_533596_839829468((*p0).module); { Tsym292834* LOC10; Ropeobj178006* LOC13; LOC10 = (Tsym292834*)0; LOC10 = getcompilerproc_338746_3937434831(((NimStringDesc*) &T839829468_615)); if (!!((LOC10 == NIM_NIL))) goto LA11; LOC13 = (Ropeobj178006*)0; LOC13 = cgsym_532403_839829468((*p0).module, ((NimStringDesc*) &T839829468_615)); } goto LA8; LA11: ; { Ropeobj178006* LOC15; LOC15 = (Ropeobj178006*)0; LOC15 = cgsym_532403_839829468((*p0).module, ((NimStringDesc*) &T839829468_616)); } LA8: ; (*p0).nestedtrystmts = (Tnodeseq292796*) incrSeqV2(&((*p0).nestedtrystmts)->Sup, sizeof(Tnode292802*)); 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_543978_839829468(p0, ((NimStringDesc*) &T839829468_617), LOC16, 0); expr_539248_839829468(p0, (*t0).kindU.S6.sons->data[((NI) 0)], d0); length0 = sonslen_295351_850551059(t0); memset((void*)LOC18, 0, sizeof(LOC18)); LOC18[0] = exc0; LOC19 = (Ropeobj178006*)0; LOC19 = ropecg_532407_839829468((*p0).module, ((NimStringDesc*) &T839829468_618), LOC18, 1); endblock_544035_839829468(p0, LOC19); { TY533289 LOC24; if (!(((*p0).options &(1U<<((NU)(((Toption169009) 15))&31U)))!=0)) goto LA22; memset((void*)LOC24, 0, sizeof(LOC24)); linefmt_532714_839829468(p0, ((Tcprocsection529011) 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 == ((Tnodekind292020) 87)); LA28: ; if (!LOC27) goto LA26; { NIM_BOOL LOC31; LOC31 = (NIM_BOOL)0; LOC31 = ((*d0).k == ((Tlockind292808) 1)); if (!(LOC31)) goto LA32; LOC31 = isemptytype_297440_850551059((*t0).typ); LA32: ; if (!LOC31) goto LA33; (*d0).k = ((Tlockind292808) 0); } LA33: ; blen0 = sonslen_295351_850551059((*t0).kindU.S6.sons->data[i0]); { Ropeobj178006** LOC39; TY533289 LOC40; if (!(((NI) 1) < i0)) goto LA37; LOC39 = (Ropeobj178006**)0; LOC39 = s_529179_3723162438(p0, ((Tcprocsection529011) 2)); memset((void*)LOC40, 0, sizeof(LOC40)); addf_179205_2381377266(LOC39, ((NimStringDesc*) &T839829468_620), LOC40, 0); } LA37: ; { TY533289 LOC45; NI LOC46; TY533289 LOC47; if (!(blen0 == ((NI) 1))) goto LA43; catchallpresent0 = NIM_TRUE; memset((void*)LOC45, 0, sizeof(LOC45)); LOC46 = (NI)0; LOC46 = startblock_543978_839829468(p0, ((NimStringDesc*) &T839829468_273), LOC45, 0); expr_539248_839829468(p0, (*(*t0).kindU.S6.sons->data[i0]).kindU.S6.sons->data[((NI) 0)], d0); memset((void*)LOC47, 0, sizeof(LOC47)); linefmt_532714_839829468(p0, ((Tcprocsection529011) 2), ((NimStringDesc*) &T839829468_606), LOC47, 0); endblock_544060_839829468(p0); } goto LA41; LA43: ; { Ropeobj178006* orexpr0; TY178507 LOC57; TY533289 LOC58; NI LOC59; TY533289 LOC60; orexpr0 = NIM_NIL; { NI j_547978_839829468; NI HEX3Atmp_548101_839829468; NI res_548104_839829468; j_547978_839829468 = (NI)0; HEX3Atmp_548101_839829468 = (NI)0; HEX3Atmp_548101_839829468 = (NI)(blen0 - ((NI) 2)); res_548104_839829468 = ((NI) 0); { while (1) { TY532811 LOC56; if (!(res_548104_839829468 <= HEX3Atmp_548101_839829468)) goto LA51; j_547978_839829468 = res_548104_839829468; { if (!!((orexpr0 == NIM_NIL))) goto LA54; add_178487_2381377266(&orexpr0, ((NimStringDesc*) &T839829468_229)); } LA54: ; memset((void*)LOC56, 0, sizeof(LOC56)); LOC56[0] = exc0; LOC56[1] = gentypeinfo_535941_839829468((*p0).module, (*(*(*t0).kindU.S6.sons->data[i0]).kindU.S6.sons->data[j_547978_839829468]).typ); appcg_532632_839829468((*p0).module, &orexpr0, ((NimStringDesc*) &T839829468_621), LOC56, 2); res_548104_839829468 += ((NI) 1); } LA51: ; } } memset((void*)LOC57, 0, sizeof(LOC57)); LOC57[0] = orexpr0; linef_532700_839829468(p0, ((Tcprocsection529011) 2), ((NimStringDesc*) &T839829468_622), LOC57, 1); memset((void*)LOC58, 0, sizeof(LOC58)); LOC59 = (NI)0; LOC59 = startblock_543978_839829468(p0, ((NimStringDesc*) &T839829468_273), LOC58, 0); expr_539248_839829468(p0, (*(*t0).kindU.S6.sons->data[i0]).kindU.S6.sons->data[(NI)(blen0 - ((NI) 1))], d0); memset((void*)LOC60, 0, sizeof(LOC60)); linefmt_532714_839829468(p0, ((Tcprocsection529011) 2), ((NimStringDesc*) &T839829468_606), LOC60, 0); endblock_544060_839829468(p0); } LA41: ; i0 += ((NI) 1); } LA26: ; } { TY533289 LOC70; NI LOC71; Tnode292802* finallyblock0; TY533289 LOC76; Ropeobj178006* LOC77; if (!!(catchallpresent0)) goto LA63; { TY533289 LOC69; if (!(((NI) 1) < i0)) goto LA67; memset((void*)LOC69, 0, sizeof(LOC69)); linef_532700_839829468(p0, ((Tcprocsection529011) 2), ((NimStringDesc*) &T839829468_620), LOC69, 0); } LA67: ; memset((void*)LOC70, 0, sizeof(LOC70)); LOC71 = (NI)0; LOC71 = startblock_543978_839829468(p0, ((NimStringDesc*) &T839829468_273), LOC70, 0); finallyblock0 = lastson_295364_850551059(t0); { if (!((*finallyblock0).kind == ((Tnodekind292020) 107))) goto LA74; genstmts_539244_839829468(p0, (*finallyblock0).kindU.S6.sons->data[((NI) 0)]); } LA74: ; memset((void*)LOC76, 0, sizeof(LOC76)); LOC77 = (Ropeobj178006*)0; LOC77 = HEX25_178905_2381377266(((NimStringDesc*) &T839829468_623), LOC76, 0); line_532690_839829468(p0, ((Tcprocsection529011) 2), LOC77); endblock_544060_839829468(p0); } LA63: ; memset((void*)LOC78, 0, sizeof(LOC78)); linef_532700_839829468(p0, ((Tcprocsection529011) 2), ((NimStringDesc*) &T839829468_160), LOC78, 0); (*p0).inexceptblock -= ((NI) 1); LOC79 = (Tnode292802*)0; LOC79 = pop_318246_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 == ((Tnodekind292020) 107)); LA83: ; if (!LOC82) goto LA84; gensimpleblock_544095_839829468(p0, (*(*t0).kindU.S6.sons->data[i0]).kindU.S6.sons->data[((NI) 0)]); } LA84: ; } N_NIMCALL(void, line_532695_839829468)(Tcproc529021* p0, Tcprocsection529011 s0, NimStringDesc* r0) { Ropeobj178006** LOC1; Ropeobj178006* LOC2; Ropeobj178006* LOC3; LOC1 = (Ropeobj178006**)0; LOC1 = s_529179_3723162438(p0, s0); LOC2 = (Ropeobj178006*)0; LOC2 = rope_178277_2381377266(r0); LOC3 = (Ropeobj178006*)0; LOC3 = indentline_532656_839829468(p0, LOC2); add_178482_2381377266(LOC1, LOC3); } static N_INLINE(Ropeobj178006*, pop_178530_1689653243)(TY191350** s0) { Ropeobj178006* result0; NI L0; result0 = (Ropeobj178006*)0; L0 = (NI)(((*s0) ? (*s0)->Sup.len : 0) - ((NI) 1)); result0 = (*s0)->data[L0]; (*s0) = (TY191350*) setLengthSeq(&((*s0))->Sup, sizeof(Ropeobj178006*), ((NI) (L0))); return result0; } N_NIMCALL(void, gentry_548114_839829468)(Tcproc529021* p0, Tnode292802* t0, Tloc292816* d0) { NIM_BOOL LOC8; Ropeobj178006* safepoint0; TY178507 LOC17; TY178507 LOC18; TY178507 LOC37; NI LOC38; NI length0; TY533289 LOC39; TY533289 LOC40; NI LOC41; TY533289 LOC42; NI i0; Tnode292802* LOC95; TY178507 LOC103; { NIM_BOOL LOC3; NIM_BOOL LOC4; LOC3 = (NIM_BOOL)0; LOC4 = (NIM_BOOL)0; LOC4 = isemptytype_297440_850551059((*t0).typ); LOC3 = !(LOC4); if (!(LOC3)) goto LA5; LOC3 = ((*d0).k == ((Tlockind292808) 0)); LA5: ; if (!LOC3) goto LA6; gettemp_537032_839829468(p0, (*t0).typ, d0, NIM_FALSE); } LA6: ; LOC8 = (NIM_BOOL)0; LOC8 = includestr_147249_3771138726((&(*(*p0).module).headerfiles), ((NimStringDesc*) &T839829468_624)); genlinedir_532823_839829468(p0, t0); safepoint0 = gettempname_533596_839829468((*p0).module); { Tsym292834* LOC11; Ropeobj178006* LOC14; LOC11 = (Tsym292834*)0; LOC11 = getcompilerproc_338746_3937434831(((NimStringDesc*) &T839829468_615)); if (!!((LOC11 == NIM_NIL))) goto LA12; LOC14 = (Ropeobj178006*)0; LOC14 = cgsym_532403_839829468((*p0).module, ((NimStringDesc*) &T839829468_615)); } goto LA9; LA12: ; { Ropeobj178006* LOC16; LOC16 = (Ropeobj178006*)0; LOC16 = cgsym_532403_839829468((*p0).module, ((NimStringDesc*) &T839829468_616)); } LA9: ; memset((void*)LOC17, 0, sizeof(LOC17)); LOC17[0] = safepoint0; linefmt_532714_839829468(p0, ((Tcprocsection529011) 0), ((NimStringDesc*) &T839829468_625), LOC17, 1); memset((void*)LOC18, 0, sizeof(LOC18)); LOC18[0] = safepoint0; linefmt_532714_839829468(p0, ((Tcprocsection529011) 2), ((NimStringDesc*) &T839829468_626), LOC18, 1); { NIM_BOOL LOC21; TY178507 LOC24; LOC21 = (NIM_BOOL)0; LOC21 = isdefined_200011_1967573533(((NimStringDesc*) &T839829468_627)); if (!LOC21) goto LA22; memset((void*)LOC24, 0, sizeof(LOC24)); LOC24[0] = safepoint0; linefmt_532714_839829468(p0, ((Tcprocsection529011) 2), ((NimStringDesc*) &T839829468_628), LOC24, 1); } goto LA19; LA22: ; { NIM_BOOL LOC26; TY178507 LOC29; LOC26 = (NIM_BOOL)0; LOC26 = isdefined_200011_1967573533(((NimStringDesc*) &T839829468_629)); if (!LOC26) goto LA27; memset((void*)LOC29, 0, sizeof(LOC29)); LOC29[0] = safepoint0; linefmt_532714_839829468(p0, ((Tcprocsection529011) 2), ((NimStringDesc*) &T839829468_630), LOC29, 1); } goto LA19; LA27: ; { NIM_BOOL LOC31; TY178507 LOC34; LOC31 = (NIM_BOOL)0; LOC31 = isdefined_200011_1967573533(((NimStringDesc*) &T839829468_631)); if (!LOC31) goto LA32; memset((void*)LOC34, 0, sizeof(LOC34)); LOC34[0] = safepoint0; linefmt_532714_839829468(p0, ((Tcprocsection529011) 2), ((NimStringDesc*) &T839829468_632), LOC34, 1); } goto LA19; LA32: ; { TY178507 LOC36; memset((void*)LOC36, 0, sizeof(LOC36)); LOC36[0] = safepoint0; linefmt_532714_839829468(p0, ((Tcprocsection529011) 2), ((NimStringDesc*) &T839829468_628), LOC36, 1); } LA19: ; memset((void*)LOC37, 0, sizeof(LOC37)); LOC37[0] = safepoint0; LOC38 = (NI)0; LOC38 = startblock_543978_839829468(p0, ((NimStringDesc*) &T839829468_633), LOC37, 1); length0 = sonslen_295351_850551059(t0); (*p0).nestedtrystmts = (Tnodeseq292796*) incrSeqV2(&((*p0).nestedtrystmts)->Sup, sizeof(Tnode292802*)); asgnRefNoCycle((void**) (&(*p0).nestedtrystmts->data[(*p0).nestedtrystmts->Sup.len]), t0); ++(*p0).nestedtrystmts->Sup.len; expr_539248_839829468(p0, (*t0).kindU.S6.sons->data[((NI) 0)], d0); memset((void*)LOC39, 0, sizeof(LOC39)); linefmt_532714_839829468(p0, ((Tcprocsection529011) 2), ((NimStringDesc*) &T839829468_605), LOC39, 0); endblock_544060_839829468(p0); memset((void*)LOC40, 0, sizeof(LOC40)); LOC41 = (NI)0; LOC41 = startblock_543978_839829468(p0, ((NimStringDesc*) &T839829468_634), LOC40, 0); memset((void*)LOC42, 0, sizeof(LOC42)); linefmt_532714_839829468(p0, ((Tcprocsection529011) 2), ((NimStringDesc*) &T839829468_605), LOC42, 0); { TY533289 LOC47; if (!(((*p0).options &(1U<<((NU)(((Toption169009) 15))&31U)))!=0)) goto LA45; memset((void*)LOC47, 0, sizeof(LOC47)); linefmt_532714_839829468(p0, ((Tcprocsection529011) 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 == ((Tnodekind292020) 87)); LA51: ; if (!LOC50) goto LA49; { NIM_BOOL LOC54; LOC54 = (NIM_BOOL)0; LOC54 = ((*d0).k == ((Tlockind292808) 1)); if (!(LOC54)) goto LA55; LOC54 = isemptytype_297440_850551059((*t0).typ); LA55: ; if (!LOC54) goto LA56; (*d0).k = ((Tlockind292808) 0); } LA56: ; blen0 = sonslen_295351_850551059((*t0).kindU.S6.sons->data[i0]); { TY533289 LOC67; NI LOC68; TY178507 LOC69; TY533289 LOC70; if (!(blen0 == ((NI) 1))) goto LA60; { TY533289 LOC66; if (!(((NI) 1) < i0)) goto LA64; memset((void*)LOC66, 0, sizeof(LOC66)); linef_532700_839829468(p0, ((Tcprocsection529011) 2), ((NimStringDesc*) &T839829468_635), LOC66, 0); } LA64: ; memset((void*)LOC67, 0, sizeof(LOC67)); LOC68 = (NI)0; LOC68 = startblock_543978_839829468(p0, ((NimStringDesc*) &T839829468_273), LOC67, 0); memset((void*)LOC69, 0, sizeof(LOC69)); LOC69[0] = safepoint0; linefmt_532714_839829468(p0, ((Tcprocsection529011) 2), ((NimStringDesc*) &T839829468_636), LOC69, 1); expr_539248_839829468(p0, (*(*t0).kindU.S6.sons->data[i0]).kindU.S6.sons->data[((NI) 0)], d0); memset((void*)LOC70, 0, sizeof(LOC70)); linefmt_532714_839829468(p0, ((Tcprocsection529011) 2), ((NimStringDesc*) &T839829468_606), LOC70, 0); endblock_544060_839829468(p0); } goto LA58; LA60: ; { Ropeobj178006* orexpr0; TY178507 LOC91; NI LOC92; TY178507 LOC93; TY533289 LOC94; orexpr0 = NIM_NIL; { NI j_548247_839829468; NI HEX3Atmp_548521_839829468; NI res_548524_839829468; j_548247_839829468 = (NI)0; HEX3Atmp_548521_839829468 = (NI)0; HEX3Atmp_548521_839829468 = (NI)(blen0 - ((NI) 2)); res_548524_839829468 = ((NI) 0); { while (1) { NimStringDesc* isobjformat0; TY178507 LOC86; if (!(res_548524_839829468 <= HEX3Atmp_548521_839829468)) goto LA74; j_548247_839829468 = res_548524_839829468; { if (!!((orexpr0 == NIM_NIL))) goto LA77; add_178487_2381377266(&orexpr0, ((NimStringDesc*) &T839829468_229)); } LA77: ; { NIM_BOOL LOC81; LOC81 = (NIM_BOOL)0; LOC81 = (gcmd_169132_2607990831 == ((Tcommands169076) 2)); if (LOC81) goto LA82; LOC81 = (((*(*(*p0).module).module).flags &(1U<<((NU)(((Tsymflag292184) 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_535941_839829468((*p0).module, (*(*(*t0).kindU.S6.sons->data[i0]).kindU.S6.sons->data[j_548247_839829468]).typ); appcg_532632_839829468((*p0).module, &orexpr0, isobjformat0, LOC86, 1); res_548524_839829468 += ((NI) 1); } LA74: ; } } { if (!(((NI) 1) < i0)) goto LA89; line_532695_839829468(p0, ((Tcprocsection529011) 2), ((NimStringDesc*) &T839829468_620)); } LA89: ; memset((void*)LOC91, 0, sizeof(LOC91)); LOC91[0] = orexpr0; LOC92 = (NI)0; LOC92 = startblock_543978_839829468(p0, ((NimStringDesc*) &T839829468_639), LOC91, 1); memset((void*)LOC93, 0, sizeof(LOC93)); LOC93[0] = safepoint0; linefmt_532714_839829468(p0, ((Tcprocsection529011) 2), ((NimStringDesc*) &T839829468_636), LOC93, 1); expr_539248_839829468(p0, (*(*t0).kindU.S6.sons->data[i0]).kindU.S6.sons->data[(NI)(blen0 - ((NI) 1))], d0); memset((void*)LOC94, 0, sizeof(LOC94)); linefmt_532714_839829468(p0, ((Tcprocsection529011) 2), ((NimStringDesc*) &T839829468_606), LOC94, 0); endblock_544060_839829468(p0); } LA58: ; i0 += ((NI) 1); } LA49: ; } (*p0).inexceptblock -= ((NI) 1); LOC95 = (Tnode292802*)0; LOC95 = pop_318246_1689653243((&(*p0).nestedtrystmts)); endblock_544060_839829468(p0); { NIM_BOOL LOC98; Ropeobj178006* LOC102; LOC98 = (NIM_BOOL)0; LOC98 = (i0 < length0); if (!(LOC98)) goto LA99; LOC98 = ((*(*t0).kindU.S6.sons->data[i0]).kind == ((Tnodekind292020) 107)); LA99: ; if (!LOC98) goto LA100; (*p0).finallysafepoints = (TY191350*) incrSeqV2(&((*p0).finallysafepoints)->Sup, sizeof(Ropeobj178006*)); asgnRefNoCycle((void**) (&(*p0).finallysafepoints->data[(*p0).finallysafepoints->Sup.len]), safepoint0); ++(*p0).finallysafepoints->Sup.len; gensimpleblock_544095_839829468(p0, (*(*t0).kindU.S6.sons->data[i0]).kindU.S6.sons->data[((NI) 0)]); LOC102 = (Ropeobj178006*)0; LOC102 = pop_178530_1689653243((&(*p0).finallysafepoints)); } LA100: ; memset((void*)LOC103, 0, sizeof(LOC103)); LOC103[0] = safepoint0; linefmt_532714_839829468(p0, ((Tcprocsection529011) 2), ((NimStringDesc*) &T839829468_640), LOC103, 1); } N_NIMCALL(NimStringDesc*, getraisefrmt_546824_839829468)(Tcproc529021* p0) { NimStringDesc* result0; result0 = (NimStringDesc*)0; result0 = copyString(((NimStringDesc*) &T839829468_641)); return result0; } N_NIMCALL(void, genraisestmt_546828_839829468)(Tcproc529021* p0, Tnode292802* t0) { { Tnode292802* finallyblock0; if (!(((NI) 0) < (*p0).inexceptblock)) goto LA3; finallyblock0 = lastson_295364_850551059((*p0).nestedtrystmts->data[(NI)(((*p0).nestedtrystmts ? (*p0).nestedtrystmts->Sup.len : 0) - ((NI) 1))]); { if (!((*finallyblock0).kind == ((Tnodekind292020) 107))) goto LA7; gensimpleblock_544095_839829468(p0, (*finallyblock0).kindU.S6.sons->data[((NI) 0)]); } LA7: ; } LA3: ; { Tloc292816 a0; Ropeobj178006* e0; Ttype292840* typ0; NimStringDesc* LOC13; TY532811 LOC14; if (!!(((*(*t0).kindU.S6.sons->data[((NI) 0)]).kind == ((Tnodekind292020) 1)))) goto LA11; memset((void*)(&a0), 0, sizeof(a0)); initlocexpr_539283_839829468(p0, (*t0).kindU.S6.sons->data[((NI) 0)], (&a0)); e0 = rdloc_538188_839829468(a0); typ0 = skiptypes_296099_850551059((*(*t0).kindU.S6.sons->data[((NI) 0)]).typ, IL64(211106247256320)); genlinedir_532823_839829468(p0, t0); LOC13 = (NimStringDesc*)0; LOC13 = getraisefrmt_546824_839829468(p0); memset((void*)LOC14, 0, sizeof(LOC14)); LOC14[0] = e0; LOC14[1] = makecstring_191638_155036129((*(*(*typ0).sym).name).s); linecg_532707_839829468(p0, ((Tcprocsection529011) 2), LOC13, LOC14, 2); } goto LA9; LA11: ; { genlinedir_532823_839829468(p0, t0); { NIM_BOOL LOC18; NIM_BOOL LOC19; TY533289 LOC24; Ropeobj178006* LOC25; LOC18 = (NIM_BOOL)0; LOC19 = (NIM_BOOL)0; LOC19 = (gcmd_169132_2607990831 == ((Tcommands169076) 2)); if (LOC19) goto LA20; LOC19 = (((*(*(*p0).module).module).flags &(1U<<((NU)(((Tsymflag292184) 27))&31U)))!=0); LA20: ; LOC18 = LOC19; if (!(LOC18)) goto LA21; LOC18 = !(((gglobaloptions_169130_2607990831 &((NU64)1<<((NU)(((Tglobaloption169013) 31))&63U)))!=0)); LA21: ; if (!LOC18) goto LA22; memset((void*)LOC24, 0, sizeof(LOC24)); LOC25 = (Ropeobj178006*)0; LOC25 = HEX25_178905_2381377266(((NimStringDesc*) &T839829468_623), LOC24, 0); line_532690_839829468(p0, ((Tcprocsection529011) 2), LOC25); } goto LA16; LA22: ; { TY533289 LOC27; memset((void*)LOC27, 0, sizeof(LOC27)); linefmt_532714_839829468(p0, ((Tcprocsection529011) 2), ((NimStringDesc*) &T839829468_642), LOC27, 0); } LA16: ; } LA9: ; } N_NIMCALL(void, gentypesection_538184_839829468)(Tcgen529027* m0, Tnode292802* n0) { } N_NIMCALL(Tcfilesection529005, determinesection_548819_839829468)(Tnode292802* n0) { Tcfilesection529005 result0; result0 = (Tcfilesection529005)0; result0 = ((Tcfilesection529005) 7); { NIM_BOOL LOC3; NI LOC4; NimStringDesc* sec0; LOC3 = (NIM_BOOL)0; LOC4 = (NI)0; LOC4 = len_293081_850551059(n0); LOC3 = (((NI) 1) <= LOC4); if (!(LOC3)) goto LA5; LOC3 = ((*(*n0).kindU.S6.sons->data[((NI) 0)]).kind >= ((Tnodekind292020) 20) && (*(*n0).kindU.S6.sons->data[((NI) 0)]).kind <= ((Tnodekind292020) 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 = ((Tcfilesection529005) 3); } goto LA8; LA11: ; { NIM_BOOL LOC14; LOC14 = (NIM_BOOL)0; LOC14 = nsuStartsWith(sec0, ((NimStringDesc*) &T839829468_644)); if (!LOC14) goto LA15; result0 = ((Tcfilesection529005) 9); } goto LA8; LA15: ; { NIM_BOOL LOC18; LOC18 = (NIM_BOOL)0; LOC18 = nsuStartsWith(sec0, ((NimStringDesc*) &T839829468_645)); if (!LOC18) goto LA19; result0 = ((Tcfilesection529005) 1); } goto LA8; LA19: ; LA8: ; } LA6: ; return result0; } N_NIMCALL(void, genemit_548839_839829468)(Tcproc529021* p0, Tnode292802* t0) { Ropeobj178006* s0; s0 = genasmoremitstmt_548529_839829468(p0, (*t0).kindU.S6.sons->data[((NI) 1)], NIM_FALSE); { Tcfilesection529005 section0; Tnode292802* LOC5; if (!((*p0).prc == NIM_NIL)) goto LA3; LOC5 = (Tnode292802*)0; LOC5 = HEX5BHEX5D_293238_850551059(t0, ((NI) 1)); section0 = determinesection_548819_839829468(LOC5); genclinedir_532813_839829468(&(*(*p0).module).s[(section0)- 0], (*t0).info); add_178482_2381377266(&(*(*p0).module).s[(section0)- 0], s0); } goto LA1; LA3: ; { genlinedir_532823_839829468(p0, t0); line_532690_839829468(p0, ((Tcprocsection529011) 2), s0); } LA1: ; } N_NIMCALL(void, genbreakpoint_548862_839829468)(Tcproc529021* p0, Tnode292802* t0) { NimStringDesc* name0; name0 = (NimStringDesc*)0; { TY535238 LOC12; NI LOC13; NimStringDesc* LOC14; if (!(((*p0).options &(1U<<((NU)(((Toption169009) 17))&31U)))!=0)) goto LA3; { if (!((*t0).kind == ((Tnodekind292020) 34))) goto LA7; name0 = nsuNormalize((*(*t0).kindU.S6.sons->data[((NI) 1)]).kindU.S3.strval); } goto LA5; LA7: ; { NimStringDesc* LOC10; NimStringDesc* LOC11; breakpointid_548860_839829468 += ((NI) 1); LOC10 = (NimStringDesc*)0; LOC11 = (NimStringDesc*)0; LOC11 = nimIntToStr(breakpointid_548860_839829468); LOC10 = rawNewString(LOC11->Sup.len + 2); appendString(LOC10, ((NimStringDesc*) &T839829468_646)); appendString(LOC10, LOC11); name0 = LOC10; } LA5: ; genlinedir_532823_839829468(p0, t0); memset((void*)LOC12, 0, sizeof(LOC12)); LOC13 = (NI)0; LOC13 = tolinenumber_192415_155036129((*t0).info); LOC12[0] = rope_178401_2381377266(((NI64) (LOC13))); LOC14 = (NimStringDesc*)0; LOC14 = tofilename_192260_155036129((*t0).info.fileindex); LOC12[1] = makecstring_191638_155036129(LOC14); LOC12[2] = makecstring_191638_155036129(name0); appcg_532632_839829468((*p0).module, &gbreakpoints_548861_839829468, ((NimStringDesc*) &T839829468_647), LOC12, 3); } LA3: ; } N_NIMCALL(void, genwatchpoint_549016_839829468)(Tcproc529021* p0, Tnode292802* n0) { Tloc292816 a0; Ttype292840* typ0; TY535238 LOC5; NimStringDesc* LOC6; { { if (!!((((*p0).options &(1U<<((NU)(((Toption169009) 17))&31U)))!=0))) goto LA3; goto BeforeRet; } LA3: ; memset((void*)(&a0), 0, sizeof(a0)); initlocexpr_539283_839829468(p0, (*n0).kindU.S6.sons->data[((NI) 1)], (&a0)); typ0 = skiptypes_296099_850551059((*(*n0).kindU.S6.sons->data[((NI) 1)]).typ, IL64(211106242013440)); memset((void*)LOC5, 0, sizeof(LOC5)); LOC5[0] = addrloc_538204_839829468(a0); LOC6 = (NimStringDesc*)0; LOC6 = rendertree_311044_382274130((*n0).kindU.S6.sons->data[((NI) 1)], 0); LOC5[1] = makecstring_191638_155036129(LOC6); LOC5[2] = gentypeinfo_535941_839829468((*p0).module, typ0); linecg_532707_839829468(p0, ((Tcprocsection529011) 2), ((NimStringDesc*) &T839829468_648), LOC5, 3); }BeforeRet: ; } N_NIMCALL(void, genpragma_549039_839829468)(Tcproc529021* p_549041_839829468, Tnode292802* n0) { { NI i_549054_839829468; NI HEX3Atmp_549073_839829468; NI LOC2; NI res_549076_839829468; i_549054_839829468 = (NI)0; HEX3Atmp_549073_839829468 = (NI)0; LOC2 = (NI)0; LOC2 = sonslen_295351_850551059(n0); HEX3Atmp_549073_839829468 = (NI)(LOC2 - ((NI) 1)); res_549076_839829468 = ((NI) 0); { while (1) { Tnode292802* it0; Tspecialword275003 LOC5; if (!(res_549076_839829468 <= HEX3Atmp_549073_839829468)) goto LA4; i_549054_839829468 = res_549076_839829468; it0 = (*n0).kindU.S6.sons->data[i_549054_839829468]; LOC5 = (Tspecialword275003)0; LOC5 = whichpragma_318911_2616423590(it0); switch (LOC5) { case ((Tspecialword275003) 191): { genemit_548839_839829468(p_549041_839829468, it0); } break; case ((Tspecialword275003) 131): { genbreakpoint_548862_839829468(p_549041_839829468, it0); } break; case ((Tspecialword275003) 176): { genwatchpoint_549016_839829468(p_549041_839829468, it0); } break; case ((Tspecialword275003) 183): { Tcproc529021* p0; Ropeobj178006** LOC10; p0 = newproc_529206_3723162438(NIM_NIL, (*p_549041_839829468).module); (*p0).options = ((*p0).options & ~ 98304); genstmts_539244_839829468(p0, (*it0).kindU.S6.sons->data[((NI) 1)]); LOC10 = (Ropeobj178006**)0; LOC10 = s_529179_3723162438(p0, ((Tcprocsection529011) 2)); asgnRefNoCycle((void**) (&(*(*p0).module).injectstmt), (*LOC10)); } break; default: { } break; } res_549076_839829468 += ((NI) 1); } LA4: ; } } } N_NIMCALL(void, genparforstmt_546208_839829468)(Tcproc529021* p0, Tnode292802* t0) { NI oldbreakidx_546411_839829468; Tsym292834* forloopvar0; Tloc292816 rangea0; Tloc292816 rangeb0; Tnode292802* call0; TY535235 LOC1; NimStringDesc* LOC2; TY533289 LOC3; (*p0).withinloop += ((NI) 1); genlinedir_532823_839829468(p0, t0); oldbreakidx_546411_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_538614_839829468(p0, forloopvar0); call0 = (*t0).kindU.S6.sons->data[((NI) 1)]; initlocexpr_539283_839829468(p0, (*call0).kindU.S6.sons->data[((NI) 1)], (&rangea0)); initlocexpr_539283_839829468(p0, (*call0).kindU.S6.sons->data[((NI) 2)], (&rangeb0)); memset((void*)LOC1, 0, sizeof(LOC1)); LOC1[0] = rdloc_538188_839829468((*forloopvar0).loc); LOC1[1] = rdloc_538188_839829468(rangea0); LOC1[2] = rdloc_538188_839829468(rangeb0); LOC2 = (NimStringDesc*)0; LOC2 = getstr_297230_850551059((*call0).kindU.S6.sons->data[((NI) 3)]); LOC1[3] = rope_178277_2381377266(LOC2); linef_532700_839829468(p0, ((Tcprocsection529011) 2), ((NimStringDesc*) &T839829468_649), LOC1, 4); memset((void*)LOC3, 0, sizeof(LOC3)); (*p0).breakidx = startblock_543978_839829468(p0, ((NimStringDesc*) &T839829468_273), LOC3, 0); (*p0).blocks->data[(*p0).breakidx].isloop = NIM_TRUE; genstmts_539244_839829468(p0, (*t0).kindU.S6.sons->data[((NI) 2)]); endblock_544060_839829468(p0); (*p0).breakidx = oldbreakidx_546411_839829468; (*p0).withinloop -= ((NI) 1); } N_NIMCALL(void, genstate_544117_839829468)(Tcproc529021* p0, Tnode292802* n0) { NI64 idx0; TY178507 LOC9; { NIM_BOOL LOC3; NI LOC4; NimStringDesc* LOC8; LOC3 = (NIM_BOOL)0; LOC4 = (NI)0; LOC4 = len_293081_850551059(n0); LOC3 = (LOC4 == ((NI) 1)); if (!(LOC3)) goto LA5; LOC3 = ((*(*n0).kindU.S6.sons->data[((NI) 0)]).kind == ((Tnodekind292020) 6)); LA5: ; if (!!(LOC3)) goto LA6; LOC8 = (NimStringDesc*)0; LOC8 = HEX24_196185_1689653243(T839829468_650); internalerror_196113_155036129(LOC8); } LA6: ; idx0 = (*(*n0).kindU.S6.sons->data[((NI) 0)]).kindU.S1.intval; memset((void*)LOC9, 0, sizeof(LOC9)); LOC9[0] = rope_178401_2381377266(idx0); linefmt_532714_839829468(p0, ((Tcprocsection529011) 2), ((NimStringDesc*) &T839829468_652), LOC9, 1); } N_NIMCALL(void, gengotostate_544144_839829468)(Tcproc529021* p0, Tnode292802* n0) { Tloc292816 a0; TY178507 LOC1; TY533289 LOC2; TY533289 LOC7; memset((void*)(&a0), 0, sizeof(a0)); initlocexpr_539283_839829468(p0, (*n0).kindU.S6.sons->data[((NI) 0)], (&a0)); memset((void*)LOC1, 0, sizeof(LOC1)); LOC1[0] = rdloc_538188_839829468(a0); linef_532700_839829468(p0, ((Tcprocsection529011) 2), ((NimStringDesc*) &T839829468_603), LOC1, 1); (*p0).beforeretneeded = NIM_TRUE; memset((void*)LOC2, 0, sizeof(LOC2)); linef_532700_839829468(p0, ((Tcprocsection529011) 2), ((NimStringDesc*) &T839829468_653), LOC2, 0); { NI64 i_544214_839829468; NI64 HEX3Atmp_544223_839829468; NI64 res_544226_839829468; i_544214_839829468 = (NI64)0; HEX3Atmp_544223_839829468 = (NI64)0; HEX3Atmp_544223_839829468 = lastord_320004_3876443242((*(*n0).kindU.S6.sons->data[((NI) 0)]).typ); res_544226_839829468 = IL64(0); { while (1) { TY178507 LOC6; if (!(res_544226_839829468 <= HEX3Atmp_544223_839829468)) goto LA5; i_544214_839829468 = res_544226_839829468; memset((void*)LOC6, 0, sizeof(LOC6)); LOC6[0] = rope_178401_2381377266(i_544214_839829468); linef_532700_839829468(p0, ((Tcprocsection529011) 2), ((NimStringDesc*) &T839829468_654), LOC6, 1); res_544226_839829468 += ((NI) 1); } LA5: ; } } memset((void*)LOC7, 0, sizeof(LOC7)); linef_532700_839829468(p0, ((Tcprocsection529011) 2), ((NimStringDesc*) &T839829468_160), LOC7, 0); } N_NIMCALL(void, genbreakstate_544229_839829468)(Tcproc529021* p0, Tnode292802* n0) { Tloc292816 a0; memset((void*)(&a0), 0, sizeof(a0)); { TY178507 LOC5; if (!((*(*n0).kindU.S6.sons->data[((NI) 0)]).kind == ((Tnodekind292020) 155))) goto LA3; initlocexpr_539283_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_538188_839829468(a0); linef_532700_839829468(p0, ((Tcprocsection529011) 2), ((NimStringDesc*) &T839829468_655), LOC5, 1); } goto LA1; LA3: ; { TY178507 LOC7; initlocexpr_539283_839829468(p0, (*n0).kindU.S6.sons->data[((NI) 0)], (&a0)); memset((void*)LOC7, 0, sizeof(LOC7)); LOC7[0] = rdloc_538188_839829468(a0); linef_532700_839829468(p0, ((Tcprocsection529011) 2), ((NimStringDesc*) &T839829468_656), LOC7, 1); } LA1: ; } N_NIMCALL(void, expr_539248_839829468)(Tcproc529021* p0, Tnode292802* n0, Tloc292816* d0) { switch ((*n0).kind) { case ((Tnodekind292020) 3): { Tsym292834* sym0; sym0 = (*n0).kindU.S4.sym; switch ((*sym0).kind) { case ((Tsymkind292435) 13): { { if (!!(((33554448 & (*sym0).flags) == 0))) goto LA5; fillprocloc_539201_839829468(sym0); genprocprototype_539254_839829468((*p0).module, sym0); } goto LA3; LA5: ; { genproc_532951_839829468((*p0).module, sym0); } LA3: ; putlocintodest_539258_839829468(p0, d0, (*sym0).loc); } break; case ((Tsymkind292435) 12): case ((Tsymkind292435) 15): case ((Tsymkind292435) 14): { { NimStringDesc* LOC13; if (!(((*sym0).flags &(1U<<((NU)(((Tsymflag292184) 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_196085_155036129((*n0).info, LOC13); } LA11: ; genproc_532951_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_196100_155036129((*n0).info, LOC20); } LA18: ; putlocintodest_539258_839829468(p0, d0, (*sym0).loc); } break; case ((Tsymkind292435) 10): { { NIM_BOOL LOC24; Ropeobj178006* LOC27; LOC24 = (NIM_BOOL)0; LOC24 = issimpleconst_532311_839829468((*sym0).typ); if (!LOC24) goto LA25; LOC27 = (Ropeobj178006*)0; LOC27 = genliteral_549476_839829468(p0, (*sym0).ast, (*sym0).typ); putintodest_550468_839829468(p0, d0, (*n0).typ, LOC27, ((Tstorageloc292812) 1)); } goto LA22; LA25: ; { gencomplexconst_558249_839829468(p0, sym0, d0); } LA22: ; } break; case ((Tsymkind292435) 19): { Ropeobj178006* LOC30; LOC30 = (Ropeobj178006*)0; LOC30 = rope_178401_2381377266(((NI64) ((*sym0).position))); putintodest_550468_839829468(p0, d0, (*n0).typ, LOC30, ((Tstorageloc292812) 0)); } break; case ((Tsymkind292435) 8): case ((Tsymkind292435) 20): case ((Tsymkind292435) 11): case ((Tsymkind292435) 9): { { if (!!(((4194312 & (*sym0).flags) == 0))) goto LA34; genvarprototype_539236_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_196100_155036129((*n0).info, LOC42); } LA40: ; { if (!(((*sym0).flags &(1U<<((NU)(((Tsymflag292184) 22))&31U)))!=0)) goto LA46; accessthreadlocalvar_532945_839829468(p0, sym0); { NIM_BOOL LOC50; Ropeobj178006* LOC53; LOC50 = (NIM_BOOL)0; LOC50 = emulatedthreadvars_532949_839829468(); if (!LOC50) goto LA51; LOC53 = (Ropeobj178006*)0; LOC53 = HEX26_178452_2381377266(((NimStringDesc*) &T839829468_288), (*sym0).loc.r); putintodest_550468_839829468(p0, d0, (*sym0).loc.t, LOC53, ((Tstorageloc292812) 0)); } goto LA48; LA51: ; { putlocintodest_539258_839829468(p0, d0, (*sym0).loc); } LA48: ; } goto LA44; LA46: ; { putlocintodest_539258_839829468(p0, d0, (*sym0).loc); } LA44: ; } break; case ((Tsymkind292435) 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_196100_155036129((*n0).info, LOC63); } LA61: ; putlocintodest_539258_839829468(p0, d0, (*sym0).loc); } break; case ((Tsymkind292435) 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_196100_155036129((*n0).info, LOC72); } LA70: ; putlocintodest_539258_839829468(p0, d0, (*sym0).loc); } break; default: { NimStringDesc* LOC75; LOC75 = (NimStringDesc*)0; LOC75 = rawNewString(reprEnum((NI)(*sym0).kind, (&NTI292435))->Sup.len + 22); appendString(LOC75, ((NimStringDesc*) &T839829468_291)); appendString(LOC75, reprEnum((NI)(*sym0).kind, (&NTI292435))); appendString(LOC75, ((NimStringDesc*) &T839829468_292)); internalerror_196100_155036129((*n0).info, LOC75); } break; } } break; case ((Tnodekind292020) 23): { { NIM_BOOL LOC79; Ropeobj178006* LOC82; LOC79 = (NIM_BOOL)0; LOC79 = isemptytype_297440_850551059((*n0).typ); if (!!(LOC79)) goto LA80; LOC82 = (Ropeobj178006*)0; LOC82 = genliteral_539273_839829468(p0, n0); putintodest_550468_839829468(p0, d0, (*n0).typ, LOC82, ((Tstorageloc292812) 0)); } LA80: ; } break; case ((Tnodekind292020) 20) ... ((Tnodekind292020) 22): { Ropeobj178006* LOC84; LOC84 = (Ropeobj178006*)0; LOC84 = genliteral_539273_839829468(p0, n0); putdataintodest_550436_839829468(p0, d0, (*n0).typ, LOC84); } break; case ((Tnodekind292020) 6) ... ((Tnodekind292020) 15): case ((Tnodekind292020) 16) ... ((Tnodekind292020) 19): case ((Tnodekind292020) 5): { Ropeobj178006* LOC86; LOC86 = (Ropeobj178006*)0; LOC86 = genliteral_539273_839829468(p0, n0); putintodest_550468_839829468(p0, d0, (*n0).typ, LOC86, ((Tstorageloc292812) 0)); } break; case ((Tnodekind292020) 27): case ((Tnodekind292020) 32): case ((Tnodekind292020) 29): case ((Tnodekind292020) 30): case ((Tnodekind292020) 31): case ((Tnodekind292020) 26): case ((Tnodekind292020) 28): { Tnode292802* op0; genlinedir_532823_839829468(p0, n0); op0 = (*n0).kindU.S6.sons->data[((NI) 0)]; { Tloc292816 a0; if (!(*n0).typ == 0) goto LA90; memset((void*)(&a0), 0, sizeof(a0)); { NIM_BOOL LOC94; LOC94 = (NIM_BOOL)0; LOC94 = ((*op0).kind == ((Tnodekind292020) 3)); if (!(LOC94)) goto LA95; LOC94 = !(((*(*op0).kindU.S4.sym).magic == ((Tmagic292524) 0))); LA95: ; if (!LOC94) goto LA96; genmagicexpr_557033_839829468(p0, n0, (&a0), (*(*op0).kindU.S4.sym).magic); } goto LA92; LA96: ; { gencall_543632_839829468(p0, n0, (&a0)); } LA92: ; } goto LA88; LA90: ; { { NIM_BOOL LOC102; LOC102 = (NIM_BOOL)0; LOC102 = ((*op0).kind == ((Tnodekind292020) 3)); if (!(LOC102)) goto LA103; LOC102 = !(((*(*op0).kindU.S4.sym).magic == ((Tmagic292524) 0))); LA103: ; if (!LOC102) goto LA104; genmagicexpr_557033_839829468(p0, n0, d0, (*(*op0).kindU.S4.sym).magic); } goto LA100; LA104: ; { gencall_543632_839829468(p0, n0, d0); } LA100: ; } LA88: ; } break; case ((Tnodekind292020) 39): { { NIM_BOOL LOC110; NI LOC112; Ropeobj178006* LOC115; LOC110 = (NIM_BOOL)0; LOC110 = isdeepconstexpr_318566_2616423590(n0); if (!(LOC110)) goto LA111; LOC112 = (NI)0; LOC112 = len_293081_850551059(n0); LOC110 = !((LOC112 == ((NI) 0))); LA111: ; if (!LOC110) goto LA113; LOC115 = (Ropeobj178006*)0; LOC115 = gensetnode_549664_839829468(p0, n0); putintodest_550468_839829468(p0, d0, (*n0).typ, LOC115, ((Tstorageloc292812) 0)); } goto LA108; LA113: ; { gensetconstr_557496_839829468(p0, n0, d0); } LA108: ; } break; case ((Tnodekind292020) 41): { { NIM_BOOL LOC120; NI LOC122; LOC120 = (NIM_BOOL)0; LOC120 = isdeepconstexpr_318566_2616423590(n0); if (!(LOC120)) goto LA121; LOC122 = (NI)0; LOC122 = len_293081_850551059(n0); LOC120 = !((LOC122 == ((NI) 0))); LA121: ; if (!LOC120) goto LA123; exprcomplexconst_558684_839829468(p0, n0, d0); } goto LA118; LA123: ; { Ttype292840* LOC126; LOC126 = (Ttype292840*)0; LOC126 = skiptypes_296099_850551059((*n0).typ, IL64(211106242013440)); if (!((*LOC126).kind == ((Ttypekind292244) 24))) goto LA127; genseqconstr_555004_839829468(p0, n0, d0); } goto LA118; LA127: ; { genarrayconstr_558207_839829468(p0, n0, d0); } LA118: ; } break; case ((Tnodekind292020) 37): { { NIM_BOOL LOC133; NI LOC135; LOC133 = (NIM_BOOL)0; LOC133 = isdeepconstexpr_318566_2616423590(n0); if (!(LOC133)) goto LA134; LOC135 = (NI)0; LOC135 = len_293081_850551059(n0); LOC133 = !((LOC135 == ((NI) 0))); LA134: ; if (!LOC133) goto LA136; exprcomplexconst_558684_839829468(p0, n0, d0); } goto LA131; LA136: ; { gentupleconstr_557618_839829468(p0, n0, d0); } LA131: ; } break; case ((Tnodekind292020) 38): { genobjconstr_554903_839829468(p0, n0, d0); } break; case ((Tnodekind292020) 61): { gencast_556537_839829468(p0, n0, d0); } break; case ((Tnodekind292020) 58): case ((Tnodekind292020) 59): case ((Tnodekind292020) 60): { genconv_556632_839829468(p0, n0, d0); } break; case ((Tnodekind292020) 64): case ((Tnodekind292020) 63): { genaddr_553051_839829468(p0, n0, d0); } break; case ((Tnodekind292020) 42): { genbracketexpr_554277_839829468(p0, n0, d0); } break; case ((Tnodekind292020) 47): case ((Tnodekind292020) 65): { genderef_543921_839829468(p0, n0, d0, NIM_FALSE); } break; case ((Tnodekind292020) 45): { genrecordfield_553448_839829468(p0, n0, d0); } break; case ((Tnodekind292020) 46): { gencheckedrecordfield_554046_839829468(p0, n0, d0); } break; case ((Tnodekind292020) 127): case ((Tnodekind292020) 112): { genblock_546083_839829468(p0, n0, d0); } break; case ((Tnodekind292020) 126): { genstmtlistexpr_558402_839829468(p0, n0, d0); } break; case ((Tnodekind292020) 115): { { NI i_559023_839829468; NI HEX3Atmp_559276_839829468; NI LOC151; NI res_559279_839829468; i_559023_839829468 = (NI)0; HEX3Atmp_559276_839829468 = (NI)0; LOC151 = (NI)0; LOC151 = sonslen_295351_850551059(n0); HEX3Atmp_559276_839829468 = (NI)(LOC151 - ((NI) 1)); res_559279_839829468 = ((NI) 0); { while (1) { if (!(res_559279_839829468 <= HEX3Atmp_559276_839829468)) goto LA153; i_559023_839829468 = res_559279_839829468; genstmts_539244_839829468(p0, (*n0).kindU.S6.sons->data[i_559023_839829468]); res_559279_839829468 += ((NI) 1); } LA153: ; } } } break; case ((Tnodekind292020) 48): case ((Tnodekind292020) 92): { genif_544982_839829468(p0, n0, d0); } break; case ((Tnodekind292020) 93): { expr_539248_839829468(p0, (*(*n0).kindU.S6.sons->data[((NI) 1)]).kindU.S6.sons->data[((NI) 0)], d0); } break; case ((Tnodekind292020) 66): { downconv_558581_839829468(p0, n0, d0); } break; case ((Tnodekind292020) 67): { upconv_558431_839829468(p0, n0, d0); } break; case ((Tnodekind292020) 68): { genrangechck_556590_839829468(p0, n0, d0, ((NimStringDesc*) &T839829468_563)); } break; case ((Tnodekind292020) 69): { genrangechck_556590_839829468(p0, n0, d0, ((NimStringDesc*) &T839829468_564)); } break; case ((Tnodekind292020) 70): { genrangechck_556590_839829468(p0, n0, d0, ((NimStringDesc*) &T839829468_565)); } break; case ((Tnodekind292020) 71): { convstrtocstr_556642_839829468(p0, n0, d0); } break; case ((Tnodekind292020) 72): { convcstrtostr_556654_839829468(p0, n0, d0); } break; case ((Tnodekind292020) 51): case ((Tnodekind292020) 52): { Tsym292834* sym0; sym0 = (*(*n0).kindU.S6.sons->data[((NI) 0)]).kindU.S4.sym; genproc_532951_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_196100_155036129((*n0).info, LOC170); } LA168: ; putlocintodest_539258_839829468(p0, d0, (*sym0).loc); } break; case ((Tnodekind292020) 155): { genclosure_557836_839829468(p0, n0, d0); } break; case ((Tnodekind292020) 1): { } break; case ((Tnodekind292020) 96): { genwhilestmt_545984_839829468(p0, n0); } break; case ((Tnodekind292020) 99): case ((Tnodekind292020) 100): { genvarstmt_544854_839829468(p0, n0); } break; case ((Tnodekind292020) 101): { genconststmt_544909_839829468(p0, n0); } break; case ((Tnodekind292020) 94): { internalerror_196100_155036129((*n0).info, ((NimStringDesc*) &T839829468_594)); } break; case ((Tnodekind292020) 97): { gencase_547826_839829468(p0, n0, d0); } break; case ((Tnodekind292020) 109): { genreturnstmt_545617_839829468(p0, n0); } break; case ((Tnodekind292020) 110): { genbreakstmt_546444_839829468(p0, n0); } break; case ((Tnodekind292020) 73): { { if (!!((((*n0).flags &(1U<<((NU)(((Tnodeflag292427) 14))&15U)))!=0))) goto LA183; genasgn_549239_839829468(p0, n0, NIM_FALSE); } LA183: ; } break; case ((Tnodekind292020) 74): { { if (!!((((*n0).flags &(1U<<((NU)(((Tnodeflag292427) 14))&15U)))!=0))) goto LA188; genasgn_549239_839829468(p0, n0, !(((*p0).prc == NIM_NIL))); } LA188: ; } break; case ((Tnodekind292020) 114): { { Tloc292816 a0; if (!!(((*(*n0).kindU.S6.sons->data[((NI) 0)]).kind == ((Tnodekind292020) 1)))) goto LA193; genlinedir_532823_839829468(p0, n0); memset((void*)(&a0), 0, sizeof(a0)); initlocexpr_539283_839829468(p0, (*n0).kindU.S6.sons->data[((NI) 0)], (&a0)); } LA193: ; } break; case ((Tnodekind292020) 89): { genasmstmt_548659_839829468(p0, n0); } break; case ((Tnodekind292020) 106): { { NIM_BOOL LOC199; NIM_BOOL LOC200; LOC199 = (NIM_BOOL)0; LOC200 = (NIM_BOOL)0; LOC200 = (gcmd_169132_2607990831 == ((Tcommands169076) 2)); if (LOC200) goto LA201; LOC200 = (((*(*(*p0).module).module).flags &(1U<<((NU)(((Tsymflag292184) 27))&31U)))!=0); LA201: ; LOC199 = LOC200; if (!(LOC199)) goto LA202; LOC199 = !(((gglobaloptions_169130_2607990831 &((NU64)1<<((NU)(((Tglobaloption169013) 31))&63U)))!=0)); LA202: ; if (!LOC199) goto LA203; gentrycpp_547865_839829468(p0, n0, d0); } goto LA197; LA203: ; { gentry_548114_839829468(p0, n0, d0); } LA197: ; } break; case ((Tnodekind292020) 108): { genraisestmt_546828_839829468(p0, n0); } break; case ((Tnodekind292020) 98): { gentypesection_538184_839829468((*p0).module, n0); } break; case ((Tnodekind292020) 125): case ((Tnodekind292020) 84): case ((Tnodekind292020) 121): case ((Tnodekind292020) 116): case ((Tnodekind292020) 117): case ((Tnodekind292020) 118): case ((Tnodekind292020) 119): case ((Tnodekind292020) 120): case ((Tnodekind292020) 83): case ((Tnodekind292020) 82): { } break; case ((Tnodekind292020) 90): { genpragma_549039_839829468(p0, n0); } break; case ((Tnodekind292020) 91): { Tnode292802* LOC211; LOC211 = (Tnode292802*)0; LOC211 = lastson_295364_850551059(n0); expr_539248_839829468(p0, LOC211, d0); } break; case ((Tnodekind292020) 79): case ((Tnodekind292020) 80): case ((Tnodekind292020) 81): { { Tsym292834* prc0; if (!((*(*n0).kindU.S6.sons->data[((NI) 2)]).kind == ((Tnodekind292020) 1))) goto LA215; prc0 = (*(*n0).kindU.S6.sons->data[((NI) 0)]).kindU.S4.sym; { NIM_BOOL LOC219; Tsym292834* LOC220; LOC219 = (NIM_BOOL)0; LOC220 = (Tsym292834*)0; LOC220 = skipgenericowner_297279_850551059(prc0); LOC219 = ((*LOC220).kind == ((Tsymkind292435) 6)); if (!(LOC219)) goto LA221; LOC219 = !((((*prc0).flags &(1U<<((NU)(((Tsymflag292184) 23))&31U)))!=0)); LA221: ; if (!LOC219) goto LA222; { NIM_BOOL LOC226; NIM_BOOL LOC227; NIM_BOOL LOC228; NIM_BOOL LOC229; Tsym292834* LOC231; NIM_BOOL LOC234; LOC226 = (NIM_BOOL)0; LOC227 = (NIM_BOOL)0; LOC228 = (NIM_BOOL)0; LOC229 = (NIM_BOOL)0; LOC229 = !(((gglobaloptions_169130_2607990831 &((NU64)1<<((NU)(((Tglobaloption169013) 2))&63U)))!=0)); if (!(LOC229)) goto LA230; LOC231 = (Tsym292834*)0; LOC231 = getmodule_299123_2984716966(prc0); LOC229 = !((((*LOC231).flags &(1U<<((NU)(((Tsymflag292184) 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)(((Tsymflag292184) 6))&31U)))!=0); if (!(LOC234)) goto LA235; LOC234 = (((*prc0).loc.flags &(1U<<((NU)(((Tlocflag292810) 5))&15U)))!=0); LA235: ; LOC227 = LOC234; LA233: ; LOC226 = LOC227; if (LOC226) goto LA236; LOC226 = ((*prc0).kind == ((Tsymkind292435) 13)); LA236: ; if (!LOC226) goto LA237; { NIM_BOOL LOC241; Tnode292802* LOC242; LOC241 = (NIM_BOOL)0; LOC242 = (Tnode292802*)0; LOC242 = getbody_335227_1724185294(prc0); LOC241 = !(((*LOC242).kind == ((Tnodekind292020) 1))); if (LOC241) goto LA243; LOC241 = (((*prc0).loc.flags &(1U<<((NU)(((Tlocflag292810) 4))&15U)))!=0); LA243: ; if (!LOC241) goto LA244; genproc_532951_839829468((*p0).module, prc0); } LA244: ; } LA237: ; } LA222: ; } LA215: ; } break; case ((Tnodekind292020) 95): { genparforstmt_546208_839829468(p0, n0); } break; case ((Tnodekind292020) 157): { genstate_544117_839829468(p0, n0); } break; case ((Tnodekind292020) 156): { gengotostate_544144_839829468(p0, n0); } break; case ((Tnodekind292020) 158): { genbreakstate_544229_839829468(p0, n0); } break; default: { NimStringDesc* LOC251; LOC251 = (NimStringDesc*)0; LOC251 = rawNewString(reprEnum((NI)(*n0).kind, (&NTI292020))->Sup.len + 25); appendString(LOC251, ((NimStringDesc*) &T839829468_291)); appendString(LOC251, reprEnum((NI)(*n0).kind, (&NTI292020))); appendString(LOC251, ((NimStringDesc*) &T839829468_657)); internalerror_196100_155036129((*n0).info, LOC251); } break; } } N_NIMCALL(void, genstmts_539244_839829468)(Tcproc529021* p0, Tnode292802* t0) { Tloc292816 a0; memset((void*)(&a0), 0, sizeof(a0)); expr_539248_839829468(p0, t0, (&a0)); { NimStringDesc* LOC5; if (!!(((7 &(1U<<((NU)(a0.k)&15U)))!=0))) goto LA3; LOC5 = (NimStringDesc*)0; LOC5 = HEX24_196185_1689653243(T839829468_658); internalerror_196113_155036129(LOC5); } LA3: ; } N_NIMCALL(Tnode292802*, myprocess_563402_839829468)(Tpasscontext341002* b0, Tnode292802* n0) { Tnode292802* result0; Tcgen529027* m0; { result0 = (Tnode292802*)0; result0 = n0; { NIM_BOOL LOC3; LOC3 = (NIM_BOOL)0; LOC3 = (b0 == NIM_NIL); if (LOC3) goto LA4; LOC3 = skipcodegen_341085_2355241294(n0); LA4: ; if (!LOC3) goto LA5; goto BeforeRet; } LA5: ; m0 = ((Tcgen529027*) (b0)); (*(*m0).initproc).options = initprocoptions_562635_839829468(m0); genstmts_539244_839829468((*m0).initproc, n0); }BeforeRet: ; return result0; } N_NIMCALL(Ropeobj178006*, getsomeinitname_561904_839829468)(Tsym292834* m0, NimStringDesc* suffix0) { Ropeobj178006* result0; result0 = (Ropeobj178006*)0; { NimStringDesc* LOC5; if (!((12288 & (*m0).flags) == 0)) goto LA3; LOC5 = (NimStringDesc*)0; LOC5 = mangle_528847_2036603609((*(*(*m0).owner).name).s); result0 = rope_178277_2381377266(LOC5); add_178487_2381377266(&result0, ((NimStringDesc*) &T839829468_12)); } LA3: ; add_178487_2381377266(&result0, (*(*m0).name).s); add_178487_2381377266(&result0, suffix0); return result0; } N_NIMCALL(Ropeobj178006*, getinitname_562235_839829468)(Tsym292834* m0) { Ropeobj178006* result0; result0 = (Ropeobj178006*)0; result0 = getsomeinitname_561904_839829468(m0, ((NimStringDesc*) &T839829468_659)); return result0; } N_NIMCALL(Ropeobj178006*, getdatinitname_562239_839829468)(Tsym292834* m0) { Ropeobj178006* result0; result0 = (Ropeobj178006*)0; result0 = getsomeinitname_561904_839829468(m0, ((NimStringDesc*) &T839829468_660)); return result0; } N_NIMCALL(void, registermoduletomain_562243_839829468)(Tsym292834* m0) { Ropeobj178006* init0; Ropeobj178006* datinit0; TY178507 LOC1; TY178507 LOC2; init0 = getinitname_562235_839829468(m0); datinit0 = getdatinitname_562239_839829468(m0); memset((void*)LOC1, 0, sizeof(LOC1)); LOC1[0] = init0; addf_179205_2381377266(&mainmodprocs_529148_3723162438, ((NimStringDesc*) &T839829468_661), LOC1, 1); memset((void*)LOC2, 0, sizeof(LOC2)); LOC2[0] = datinit0; addf_179205_2381377266(&mainmodprocs_529148_3723162438, ((NimStringDesc*) &T839829468_661), LOC2, 1); { TY178507 LOC7; Ropeobj178006* initcall0; TY178507 LOC8; if (!!((((*m0).flags &(1U<<((NU)(((Tsymflag292184) 13))&31U)))!=0))) goto LA5; memset((void*)LOC7, 0, sizeof(LOC7)); LOC7[0] = datinit0; addf_179205_2381377266(&maindatinit_529151_3723162438, ((NimStringDesc*) &T839829468_662), LOC7, 1); memset((void*)LOC8, 0, sizeof(LOC8)); LOC8[0] = init0; initcall0 = HEX25_178905_2381377266(((NimStringDesc*) &T839829468_662), LOC8, 1); { if (!(((*m0).flags &(1U<<((NU)(((Tsymflag292184) 12))&31U)))!=0)) goto LA11; add_178482_2381377266(&mainmodinit_529149_3723162438, initcall0); } goto LA9; LA11: ; { add_178482_2381377266(&othermodsinit_529150_3723162438, initcall0); } LA9: ; } LA5: ; } N_NIMCALL(Ropeobj178006*, genfilenames_561688_839829468)(Tcgen529027* m0) { Ropeobj178006* result0; Ropeobj178006* LOC1; result0 = (Ropeobj178006*)0; LOC1 = (Ropeobj178006*)0; LOC1 = cgsym_532403_839829468(m0, ((NimStringDesc*) &T839829468_673)); result0 = NIM_NIL; { NI i_561717_839829468; NI HEX3Atmp_561722_839829468; NI res_561725_839829468; i_561717_839829468 = (NI)0; HEX3Atmp_561722_839829468 = (NI)0; HEX3Atmp_561722_839829468 = ((fileinfos_191629_155036129 ? fileinfos_191629_155036129->Sup.len : 0) - 1); res_561725_839829468 = ((NI) 0); { while (1) { TY178507 LOC5; if (!(res_561725_839829468 <= HEX3Atmp_561722_839829468)) goto LA4; i_561717_839829468 = res_561725_839829468; memset((void*)LOC5, 0, sizeof(LOC5)); LOC5[0] = makecstring_191638_155036129(fileinfos_191629_155036129->data[i_561717_839829468].projpath); addf_179205_2381377266(&result0, ((NimStringDesc*) &T839829468_674), LOC5, 1); res_561725_839829468 += ((NI) 1); } LA4: ; } } return result0; } N_NIMCALL(void, genmainproc_561729_839829468)(Tcgen529027* m0) { NimStringDesc* nimmain0; NimStringDesc* othermain0; Ropeobj178006* initstackbottomcall0; TY536475 LOC38; TY535238 LOC47; nimmain0 = (NimStringDesc*)0; othermain0 = (NimStringDesc*)0; { NIM_BOOL LOC3; NIM_BOOL LOC12; LOC3 = (NIM_BOOL)0; LOC3 = (targetos_176629_4151366050 == ((Tsystemos176004) 2)); if (!(LOC3)) goto LA4; LOC3 = !(((gglobaloptions_169130_2607990831 & 1280) == 0)); LA4: ; if (!LOC3) goto LA5; { if (!((gglobaloptions_169130_2607990831 &((NU64)1<<((NU)(((Tglobaloption169013) 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_147249_3771138726((&(*m0).headerfiles), ((NimStringDesc*) &T839829468_667)); } goto LA1; LA5: ; { if (!((gglobaloptions_169130_2607990831 &((NU64)1<<((NU)(((Tglobaloption169013) 8))&63U)))!=0)) goto LA14; nimmain0 = copyString(((NimStringDesc*) &T839829468_665)); othermain0 = copyString(((NimStringDesc*) &T839829468_668)); } goto LA1; LA14: ; { if (!(targetos_176629_4151366050 == ((Tsystemos176004) 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: ; { Ropeobj178006* LOC24; if (!!((gbreakpoints_548861_839829468 == NIM_NIL))) goto LA22; LOC24 = (Ropeobj178006*)0; LOC24 = cgsym_532403_839829468(m0, ((NimStringDesc*) &T839829468_672)); } LA22: ; { Ropeobj178006* LOC29; if (!((goptions_169128_2607990831 &(1U<<((NU)(((Toption169009) 17))&31U)))!=0)) goto LA27; LOC29 = (Ropeobj178006*)0; LOC29 = genfilenames_561688_839829468(m0); add_178482_2381377266(&gbreakpoints_548861_839829468, LOC29); } LA27: ; { NIM_BOOL LOC32; LOC32 = (NIM_BOOL)0; LOC32 = (targetos_176629_4151366050 == ((Tsystemos176004) 24)); if (LOC32) goto LA33; LOC32 = (gselectedgc_169133_2607990831 == ((Tgcmode169080) 0)); LA33: ; if (!LOC32) goto LA34; initstackbottomcall0 = rope_178277_2381377266(((NimStringDesc*) &T839829468_490)); } goto LA30; LA34: ; { TY533289 LOC37; memset((void*)LOC37, 0, sizeof(LOC37)); initstackbottomcall0 = ropecg_532407_839829468(m0, ((NimStringDesc*) &T839829468_675), LOC37, 0); } LA30: ; (*m0).labels += ((NI) 1); memset((void*)LOC38, 0, sizeof(LOC38)); LOC38[0] = maindatinit_529151_3723162438; LOC38[1] = gbreakpoints_548861_839829468; LOC38[2] = othermodsinit_529150_3723162438; { NIM_BOOL LOC41; TY533289 LOC45; LOC41 = (NIM_BOOL)0; LOC41 = emulatedthreadvars_532949_839829468(); if (!(LOC41)) goto LA42; LOC41 = !((targetos_176629_4151366050 == ((Tsystemos176004) 24))); LA42: ; if (!LOC41) goto LA43; memset((void*)LOC45, 0, sizeof(LOC45)); LOC38[3] = ropecg_532407_839829468(m0, ((NimStringDesc*) &T839829468_677), LOC45, 0); } goto LA39; LA43: ; { LOC38[3] = rope_178277_2381377266(((NimStringDesc*) &T839829468_490)); } LA39: ; LOC38[4] = initstackbottomcall0; appcg_532632_839829468(m0, &(*m0).s[(((Tcfilesection529005) 10))- 0], ((NimStringDesc*) &T839829468_676), LOC38, 5); memset((void*)LOC47, 0, sizeof(LOC47)); LOC47[0] = mainmodinit_529149_3723162438; LOC47[1] = initstackbottomcall0; LOC47[2] = rope_178401_2381377266(((NI64) ((*m0).labels))); appcg_532632_839829468(m0, &(*m0).s[(((Tcfilesection529005) 10))- 0], nimmain0, LOC47, 3); { TY533289 LOC52; if (!!(((gglobaloptions_169130_2607990831 &((NU64)1<<((NU)(((Tglobaloption169013) 20))&63U)))!=0))) goto LA50; memset((void*)LOC52, 0, sizeof(LOC52)); appcg_532632_839829468(m0, &(*m0).s[(((Tcfilesection529005) 10))- 0], othermain0, LOC52, 0); } LA50: ; } N_NIMCALL(Tnode292802*, myclose_563830_839829468)(Tpasscontext341002* b0, Tnode292802* n0) { Tnode292802* result0; Tcgen529027* m0; { result0 = (Tnode292802*)0; result0 = n0; { NIM_BOOL LOC3; LOC3 = (NIM_BOOL)0; LOC3 = (b0 == NIM_NIL); if (LOC3) goto LA4; LOC3 = skipcodegen_341085_2355241294(n0); LA4: ; if (!LOC3) goto LA5; goto BeforeRet; } LA5: ; m0 = ((Tcgen529027*) (b0)); { if (!!((n0 == NIM_NIL))) goto LA9; (*(*m0).initproc).options = initprocoptions_562635_839829468(m0); genstmts_539244_839829468((*m0).initproc, n0); } LA9: ; registermoduletomain_562243_839829468((*m0).module); { Tnode292802* disp0; if (!(((*(*m0).module).flags &(1U<<((NU)(((Tsymflag292184) 12))&31U)))!=0)) goto LA13; (*m0).flags |= ((NU8)1)<<((((Codegenflag529025) 5))%(sizeof(NU8)*8)); disp0 = generatemethoddispatchers_432151_3853300031(); { NI i_563891_839829468; NI HEX3Atmp_563895_839829468; NI LOC16; NI res_563898_839829468; i_563891_839829468 = (NI)0; HEX3Atmp_563895_839829468 = (NI)0; LOC16 = (NI)0; LOC16 = sonslen_295351_850551059(disp0); HEX3Atmp_563895_839829468 = (NI)(LOC16 - ((NI) 1)); res_563898_839829468 = ((NI) 0); { while (1) { if (!(res_563898_839829468 <= HEX3Atmp_563895_839829468)) goto LA18; i_563891_839829468 = res_563898_839829468; genprocaux_560284_839829468(m0, (*(*disp0).kindU.S6.sons->data[i_563891_839829468]).kindU.S4.sym); res_563898_839829468 += ((NI) 1); } LA18: ; } } genmainproc_561729_839829468(m0); } LA13: ; }BeforeRet: ; return result0; } N_NIMCALL(void, finishmodule_563420_839829468)(Tcgen529027* m0) { NI i0; i0 = ((NI) 0); { while (1) { Tsym292834* 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)(((Tsymflag292184) 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_196100_155036129((*prc0).info, LOC7); } LA5: ; genprocnoforward_560906_839829468(m0, prc0); i0 += ((NI) 1); } LA2: ; } gforwardedprocscounter_529171_3723162438 -= i0; (*m0).forwardedprocs = (Tsymseq292804*) setLengthSeq(&((*m0).forwardedprocs)->Sup, sizeof(Tsym292834*), ((NI) 0)); } N_NIMCALL(void, geninitcode_562286_839829468)(Tcgen529027* m0) { Ropeobj178006* initname0; Ropeobj178006* prc0; TY178507 LOC1; Ropeobj178006* LOC12; Ropeobj178006* LOC13; Ropeobj178006** LOC14; Ropeobj178006** LOC15; Ropeobj178006** LOC16; Ropeobj178006* LOC17; Ropeobj178006* LOC33; Ropeobj178006** LOC34; Ropeobj178006** LOC35; Ropeobj178006** LOC36; Ropeobj178006* LOC37; Ropeobj178006* LOC38; Ropeobj178006** LOC39; Ropeobj178006** LOC40; Ropeobj178006** LOC41; Ropeobj178006* LOC42; Ropeobj178006* LOC50; TY533289 LOC51; TY178507 LOC52; TY533289 LOC58; initname0 = getinitname_562235_839829468((*m0).module); memset((void*)LOC1, 0, sizeof(LOC1)); LOC1[0] = initname0; prc0 = HEX25_178905_2381377266(((NimStringDesc*) &T839829468_679), LOC1, 1); { TY532811 LOC6; if (!(((NI) 0) < (*m0).typenodes)) goto LA4; memset((void*)LOC6, 0, sizeof(LOC6)); LOC6[0] = (*m0).typenodesname; LOC6[1] = rope_178401_2381377266(((NI64) ((*m0).typenodes))); appcg_532632_839829468(m0, &(*m0).s[(((Tcfilesection529005) 12))- 0], ((NimStringDesc*) &T839829468_680), LOC6, 2); } LA4: ; { TY532811 LOC11; if (!(((NI) 0) < (*m0).nimtypes)) goto LA9; memset((void*)LOC11, 0, sizeof(LOC11)); LOC11[0] = (*m0).nimtypesname; LOC11[1] = rope_178401_2381377266(((NI64) ((*m0).nimtypes))); appcg_532632_839829468(m0, &(*m0).s[(((Tcfilesection529005) 12))- 0], ((NimStringDesc*) &T839829468_681), LOC11, 2); } LA9: ; LOC12 = (Ropeobj178006*)0; LOC12 = initgcframe_538435_839829468((*m0).initproc); add_178482_2381377266(&prc0, LOC12); LOC13 = (Ropeobj178006*)0; LOC13 = gensectionstart_530081_2760143328(((Tcprocsection529011) 0)); add_178482_2381377266(&prc0, LOC13); LOC14 = (Ropeobj178006**)0; LOC14 = s_529179_3723162438((*m0).preinitproc, ((Tcprocsection529011) 0)); add_178482_2381377266(&prc0, (*LOC14)); LOC15 = (Ropeobj178006**)0; LOC15 = s_529179_3723162438((*m0).initproc, ((Tcprocsection529011) 0)); add_178482_2381377266(&prc0, (*LOC15)); LOC16 = (Ropeobj178006**)0; LOC16 = s_529179_3723162438((*m0).postinitproc, ((Tcprocsection529011) 0)); add_178482_2381377266(&prc0, (*LOC16)); LOC17 = (Ropeobj178006*)0; LOC17 = gensectionend_530116_2760143328(((Tcprocsection529011) 0)); add_178482_2381377266(&prc0, LOC17); { NIM_BOOL LOC20; LOC20 = (NIM_BOOL)0; LOC20 = (((*(*m0).initproc).options &(1U<<((NU)(((Toption169009) 15))&31U)))!=0); if (!(LOC20)) goto LA21; LOC20 = !((((*m0).flags &(1U<<((NU)(((Codegenflag529025) 2))&7U)))!=0)); LA21: ; if (!LOC20) goto LA22; (*m0).flags |= ((NU8)1)<<((((Codegenflag529025) 2))%(sizeof(NU8)*8)); { Ropeobj178006* procname0; Ropeobj178006* LOC28; Ropeobj178006* LOC29; if (!!((((*m0).flags &(1U<<((NU)(((Codegenflag529025) 0))&7U)))!=0))) goto LA26; procname0 = makecstring_191638_155036129((*(*(*m0).module).name).s); LOC28 = (Ropeobj178006*)0; LOC28 = quotedfilename_196818_155036129((*(*m0).module).info); LOC29 = (Ropeobj178006*)0; LOC29 = initframe_560140_839829468((*m0).initproc, procname0, LOC28); add_178482_2381377266(&prc0, LOC29); } goto LA24; LA26: ; { TY533289 LOC31; Ropeobj178006* LOC32; memset((void*)LOC31, 0, sizeof(LOC31)); LOC32 = (Ropeobj178006*)0; LOC32 = HEX25_178905_2381377266(((NimStringDesc*) &T839829468_682), LOC31, 0); add_178482_2381377266(&prc0, LOC32); } LA24: ; } LA22: ; LOC33 = (Ropeobj178006*)0; LOC33 = gensectionstart_530081_2760143328(((Tcprocsection529011) 1)); add_178482_2381377266(&prc0, LOC33); LOC34 = (Ropeobj178006**)0; LOC34 = s_529179_3723162438((*m0).preinitproc, ((Tcprocsection529011) 1)); add_178482_2381377266(&prc0, (*LOC34)); LOC35 = (Ropeobj178006**)0; LOC35 = s_529179_3723162438((*m0).initproc, ((Tcprocsection529011) 1)); add_178482_2381377266(&prc0, (*LOC35)); LOC36 = (Ropeobj178006**)0; LOC36 = s_529179_3723162438((*m0).postinitproc, ((Tcprocsection529011) 1)); add_178482_2381377266(&prc0, (*LOC36)); LOC37 = (Ropeobj178006*)0; LOC37 = gensectionend_530116_2760143328(((Tcprocsection529011) 1)); add_178482_2381377266(&prc0, LOC37); LOC38 = (Ropeobj178006*)0; LOC38 = gensectionstart_530081_2760143328(((Tcprocsection529011) 2)); add_178482_2381377266(&prc0, LOC38); LOC39 = (Ropeobj178006**)0; LOC39 = s_529179_3723162438((*m0).preinitproc, ((Tcprocsection529011) 2)); add_178482_2381377266(&prc0, (*LOC39)); LOC40 = (Ropeobj178006**)0; LOC40 = s_529179_3723162438((*m0).initproc, ((Tcprocsection529011) 2)); add_178482_2381377266(&prc0, (*LOC40)); LOC41 = (Ropeobj178006**)0; LOC41 = s_529179_3723162438((*m0).postinitproc, ((Tcprocsection529011) 2)); add_178482_2381377266(&prc0, (*LOC41)); LOC42 = (Ropeobj178006*)0; LOC42 = gensectionend_530116_2760143328(((Tcprocsection529011) 2)); add_178482_2381377266(&prc0, LOC42); { NIM_BOOL LOC45; Ropeobj178006* LOC49; LOC45 = (NIM_BOOL)0; LOC45 = (((*(*m0).initproc).options &(1U<<((NU)(((Toption169009) 15))&31U)))!=0); if (!(LOC45)) goto LA46; LOC45 = !((((*m0).flags &(1U<<((NU)(((Codegenflag529025) 0))&7U)))!=0)); LA46: ; if (!LOC45) goto LA47; LOC49 = (Ropeobj178006*)0; LOC49 = deinitframe_560150_839829468((*m0).initproc); add_178482_2381377266(&prc0, LOC49); } LA47: ; LOC50 = (Ropeobj178006*)0; LOC50 = deinitgcframe_538441_839829468((*m0).initproc); add_178482_2381377266(&prc0, LOC50); memset((void*)LOC51, 0, sizeof(LOC51)); addf_179205_2381377266(&prc0, ((NimStringDesc*) &T839829468_683), LOC51, 0); memset((void*)LOC52, 0, sizeof(LOC52)); LOC52[0] = getdatinitname_562239_839829468((*m0).module); addf_179205_2381377266(&prc0, ((NimStringDesc*) &T839829468_679), LOC52, 1); { Tcfilesection529005 i_562401_839829468; NI res_562482_839829468; i_562401_839829468 = (Tcfilesection529005)0; res_562482_839829468 = ((NI) 12); { while (1) { Ropeobj178006* LOC56; Ropeobj178006* LOC57; if (!(res_562482_839829468 <= ((NI) 16))) goto LA55; i_562401_839829468 = ((Tcfilesection529005) (res_562482_839829468)); LOC56 = (Ropeobj178006*)0; LOC56 = gensectionstart_530015_2760143328(i_562401_839829468); add_178482_2381377266(&prc0, LOC56); add_178482_2381377266(&prc0, (*m0).s[(i_562401_839829468)- 0]); LOC57 = (Ropeobj178006*)0; LOC57 = gensectionend_530050_2760143328(i_562401_839829468); add_178482_2381377266(&prc0, LOC57); res_562482_839829468 += ((NI) 1); } LA55: ; } } memset((void*)LOC58, 0, sizeof(LOC58)); addf_179205_2381377266(&prc0, ((NimStringDesc*) &T839829468_683), LOC58, 0); add_178482_2381377266(&(*m0).s[(((Tcfilesection529005) 11))- 0], prc0); { NIM_CHAR i_562442_839829468; Ropeobj178006* el_562443_839829468; TY529136 HEX3Atmp_562487_839829468; NIM_CHAR i_562490_839829468; i_562442_839829468 = (NIM_CHAR)0; el_562443_839829468 = (Ropeobj178006*)0; memset((void*)HEX3Atmp_562487_839829468, 0, sizeof(HEX3Atmp_562487_839829468)); memcpy((void*)HEX3Atmp_562487_839829468, (NIM_CONST void*)(*m0).extensionloaders, sizeof(HEX3Atmp_562487_839829468)); i_562490_839829468 = 48; { if (!((NU8)(((NIM_CHAR) (((NU8)(i_562490_839829468))))) <= (NU8)(57))) goto LA62; { while (1) { i_562442_839829468 = i_562490_839829468; el_562443_839829468 = HEX3Atmp_562487_839829468[(((NU8)(i_562490_839829468)))- 48]; { Ropeobj178006* ex0; TY532811 LOC70; if (!!((el_562443_839829468 == NIM_NIL))) goto LA68; memset((void*)LOC70, 0, sizeof(LOC70)); LOC70[0] = rope_178401_2381377266(((NI64) ((NI)(((NI) (((NU8)(i_562442_839829468)))) - ((NI) 48))))); LOC70[1] = el_562443_839829468; ex0 = HEX25_178905_2381377266(((NimStringDesc*) &T839829468_684), LOC70, 2); add_178482_2381377266(&(*m0).s[(((Tcfilesection529005) 11))- 0], ex0); } LA68: ; { if (!((NU8)(57) <= (NU8)(((NIM_CHAR) (((NU8)(i_562490_839829468))))))) goto LA73; goto LA64; } LA73: ; i_562490_839829468 += ((NI) 1); } } LA64: ; } LA62: ; } } N_NIMCALL(void, finishtypedescriptions_535842_839829468)(Tcgen529027* m0) { NI i0; i0 = ((NI) 0); { while (1) { Ropeobj178006* LOC3; if (!(i0 < ((*m0).typestack ? (*m0).typestack->Sup.len : 0))) goto LA2; LOC3 = (Ropeobj178006*)0; LOC3 = gettypedesc_535671_839829468(m0, (*m0).typestack->data[i0]); i0 += ((NI) 1); } LA2: ; } } N_NIMCALL(Ropeobj178006*, getcopyright_561665_839829468)(NimStringDesc* cfile0) { Ropeobj178006* result0; result0 = (Ropeobj178006*)0; { TY178507 LOC5; if (!((gglobaloptions_169130_2607990831 &((NU64)1<<((NU)(((Tglobaloption169013) 4))&63U)))!=0)) goto LA3; memset((void*)LOC5, 0, sizeof(LOC5)); LOC5[0] = rope_178277_2381377266(((NimStringDesc*) &T839829468_686)); result0 = HEX25_178905_2381377266(((NimStringDesc*) &T839829468_685), LOC5, 1); } goto LA1; LA3: ; { TY536475 LOC7; NimStringDesc* LOC8; memset((void*)LOC7, 0, sizeof(LOC7)); LOC7[0] = rope_178277_2381377266(((NimStringDesc*) &T839829468_686)); LOC7[1] = rope_178277_2381377266(Os_176068_4151366050[(targetos_176629_4151366050)- 1].Field0); LOC7[2] = rope_178277_2381377266(Cpu_176496_4151366050[(targetcpu_176627_4151366050)- 1].Field0); LOC7[3] = rope_178277_2381377266(Cc_273413_2528170400[(ccompiler_273431_2528170400)- 1].Field0); LOC8 = (NimStringDesc*)0; LOC8 = getcompilecfilecmd_274284_2528170400(cfile0, NIM_FALSE); LOC7[4] = rope_178277_2381377266(LOC8); result0 = HEX25_178905_2381377266(((NimStringDesc*) &T839829468_687), LOC7, 5); } LA1: ; return result0; } static N_INLINE(void, addinttypes_561659_839829468)(Ropeobj178006** result0) { NimStringDesc* LOC1; TY178507 LOC2; LOC1 = (NimStringDesc*)0; LOC1 = rawNewString(tnl_176644_4151366050->Sup.len + 22); appendString(LOC1, ((NimStringDesc*) &T839829468_688)); appendString(LOC1, tnl_176644_4151366050); memset((void*)LOC2, 0, sizeof(LOC2)); LOC2[0] = rope_178401_2381377266(((NI64) (Cpu_176496_4151366050[(targetcpu_176627_4151366050)- 1].Field1))); addf_179205_2381377266(result0, LOC1, LOC2, 1); } N_NIMCALL(Ropeobj178006*, getfileheader_561683_839829468)(NimStringDesc* cfile0) { Ropeobj178006* result0; result0 = (Ropeobj178006*)0; result0 = getcopyright_561665_839829468(cfile0); addinttypes_561659_839829468(&result0); return result0; } N_NIMCALL(void, generatethreadlocalstorage_538717_839829468)(Tcgen529027* m0) { { NIM_BOOL LOC3; NIM_BOOL LOC5; TY178507 LOC13; LOC3 = (NIM_BOOL)0; LOC3 = !((nimtv_538656_839829468 == NIM_NIL)); if (!(LOC3)) goto LA4; LOC5 = (NIM_BOOL)0; LOC5 = (((*m0).flags &(1U<<((NU)(((Codegenflag529025) 1))&7U)))!=0); if (LOC5) goto LA6; LOC5 = (((*(*m0).module).flags &(1U<<((NU)(((Tsymflag292184) 12))&31U)))!=0); LA6: ; LOC3 = LOC5; LA4: ; if (!LOC3) goto LA7; { Ttype292840* t_538761_839829468; NI i_538768_839829468; NI L_538770_839829468; t_538761_839829468 = (Ttype292840*)0; i_538768_839829468 = ((NI) 0); L_538770_839829468 = (nimtvdeps_538674_839829468 ? nimtvdeps_538674_839829468->Sup.len : 0); { while (1) { Ropeobj178006* LOC12; if (!(i_538768_839829468 < L_538770_839829468)) goto LA11; t_538761_839829468 = nimtvdeps_538674_839829468->data[i_538768_839829468]; LOC12 = (Ropeobj178006*)0; LOC12 = gettypedesc_535671_839829468(m0, t_538761_839829468); i_538768_839829468 += ((NI) 1); } LA11: ; } } memset((void*)LOC13, 0, sizeof(LOC13)); LOC13[0] = nimtv_538656_839829468; addf_179205_2381377266(&(*m0).s[(((Tcfilesection529005) 4))- 0], ((NimStringDesc*) &T839829468_689), LOC13, 1); } LA7: ; } N_NIMCALL(void, generateheaders_560104_839829468)(Tcgen529027* m0) { NimStringDesc* LOC1; Tstrentry147009* it0; LOC1 = (NimStringDesc*)0; LOC1 = rawNewString(tnl_176644_4151366050->Sup.len + tnl_176644_4151366050->Sup.len + 20); appendString(LOC1, tnl_176644_4151366050); appendString(LOC1, ((NimStringDesc*) &T839829468_690)); appendString(LOC1, tnl_176644_4151366050); add_178487_2381377266(&(*m0).s[(((Tcfilesection529005) 1))- 0], LOC1); it0 = ((Tstrentry147009*) ((*m0).headerfiles.head)); { while (1) { if (!!((it0 == NIM_NIL))) goto LA3; { NimStringDesc* LOC8; NimStringDesc* LOC9; Ropeobj178006* 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_176644_4151366050->Sup.len + 0); appendString(LOC8, LOC9); appendString(LOC8, tnl_176644_4151366050); LOC10 = (Ropeobj178006*)0; LOC10 = rope_178277_2381377266(LOC8); add_178482_2381377266(&(*m0).s[(((Tcfilesection529005) 1))- 0], LOC10); } goto LA4; LA6: ; { TY178507 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_178277_2381377266((*it0).data); addf_179205_2381377266(&(*m0).s[(((Tcfilesection529005) 1))- 0], ((NimStringDesc*) &T839829468_691), LOC14, 1); } goto LA4; LA12: ; { TY178507 LOC16; memset((void*)LOC16, 0, sizeof(LOC16)); LOC16[0] = rope_178277_2381377266((*it0).data); addf_179205_2381377266(&(*m0).s[(((Tcfilesection529005) 1))- 0], ((NimStringDesc*) &T839829468_692), LOC16, 1); } LA4: ; it0 = ((Tstrentry147009*) ((*it0).Sup.next)); } LA3: ; } } N_NIMCALL(Ropeobj178006*, genmodule_562491_839829468)(Tcgen529027* m0, NimStringDesc* cfile0) { Ropeobj178006* result0; Ropeobj178006* LOC1; result0 = (Ropeobj178006*)0; result0 = getfileheader_561683_839829468(cfile0); LOC1 = (Ropeobj178006*)0; LOC1 = genmergeinfo_530203_2760143328(m0); add_178482_2381377266(&result0, LOC1); generatethreadlocalstorage_538717_839829468(m0); generateheaders_560104_839829468(m0); { Tcfilesection529005 i_562614_839829468; NI res_562622_839829468; i_562614_839829468 = (Tcfilesection529005)0; res_562622_839829468 = ((NI) 1); { while (1) { Ropeobj178006* LOC5; Ropeobj178006* LOC6; if (!(res_562622_839829468 <= ((NI) 10))) goto LA4; i_562614_839829468 = ((Tcfilesection529005) (res_562622_839829468)); LOC5 = (Ropeobj178006*)0; LOC5 = gensectionstart_530015_2760143328(i_562614_839829468); add_178482_2381377266(&result0, LOC5); add_178482_2381377266(&result0, (*m0).s[(i_562614_839829468)- 0]); LOC6 = (Ropeobj178006*)0; LOC6 = gensectionend_530050_2760143328(i_562614_839829468); add_178482_2381377266(&result0, LOC6); res_562622_839829468 += ((NI) 1); } LA4: ; } } add_178482_2381377266(&result0, (*m0).s[(((Tcfilesection529005) 11))- 0]); return result0; } N_NIMCALL(void, updatecachedmodule_563813_839829468)(Tcgen529027* m0) { NimStringDesc* cfile0; NimStringDesc* cfilenoext0; cfile0 = getcfile_563204_839829468(m0); cfilenoext0 = noschangeFileExt(cfile0, ((NimStringDesc*) &T839829468_490)); { NIM_BOOL LOC3; Ropeobj178006* code0; LOC3 = (NIM_BOOL)0; LOC3 = mergerequired_530832_2760143328(m0); if (!(LOC3)) goto LA4; LOC3 = !((((*(*m0).module).flags &(1U<<((NU)(((Tsymflag292184) 12))&31U)))!=0)); LA4: ; if (!LOC3) goto LA5; mergefiles_531241_2760143328(cfile0, m0); geninitcode_562286_839829468(m0); finishtypedescriptions_535842_839829468(m0); code0 = genmodule_562491_839829468(m0, cfile0); writerope_178836_2381377266(code0, cfile0, NIM_FALSE); addfiletocompile_273863_2528170400(cfile0); } LA5: ; addfiletolink_273872_2528170400(cfilenoext0); } N_NIMCALL(void, generatethreadvarssize_538771_839829468)(Tcgen529027* m0) { { NimStringDesc* externc0; TY178507 LOC12; if (!!((nimtv_538656_839829468 == NIM_NIL))) goto LA3; { NIM_BOOL LOC7; LOC7 = (NIM_BOOL)0; LOC7 = !((gcmd_169132_2607990831 == ((Tcommands169076) 2))); if (!(LOC7)) goto LA8; LOC7 = (((*(*m0).module).flags &(1U<<((NU)(((Tsymflag292184) 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_178277_2381377266(externc0); addf_179205_2381377266(&(*m0).s[(((Tcfilesection529005) 10))- 0], ((NimStringDesc*) &T839829468_694), LOC12, 1); } LA3: ; } N_NIMCALL(NIM_BOOL, shouldrecompile_563621_839829468)(Ropeobj178006* code0, NimStringDesc* cfile0) { NIM_BOOL result0; { result0 = (NIM_BOOL)0; result0 = NIM_TRUE; { NimStringDesc* objfile0; if (!!(((gglobaloptions_169130_2607990831 &((NU64)1<<((NU)(((Tglobaloption169013) 1))&63U)))!=0))) goto LA3; objfile0 = toobjfile_273859_2528170400(cfile0); { NIM_BOOL LOC7; LOC7 = (NIM_BOOL)0; LOC7 = writeropeifnotequal_179511_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_178836_2381377266(code0, cfile0, NIM_FALSE); } LA1: ; }BeforeRet: ; return result0; } N_NIMCALL(void, writemodule_563637_839829468)(Tcgen529027* m0, NIM_BOOL pending0) { NimStringDesc* cfile0; NimStringDesc* cfilenoext0; cfile0 = getcfile_563204_839829468(m0); cfilenoext0 = noschangeFileExt(cfile0, ((NimStringDesc*) &T839829468_490)); { NIM_BOOL LOC3; Ropeobj178006* code0; LOC3 = (NIM_BOOL)0; LOC3 = !((*m0).Sup.fromcache); if (LOC3) goto LA4; LOC3 = ((gglobaloptions_169130_2607990831 &((NU64)1<<((NU)(((Tglobaloption169013) 1))&63U)))!=0); LA4: ; if (!LOC3) goto LA5; geninitcode_562286_839829468(m0); finishtypedescriptions_535842_839829468(m0); { if (!(((*(*m0).module).flags &(1U<<((NU)(((Tsymflag292184) 12))&31U)))!=0)) goto LA9; add_178482_2381377266(&(*m0).s[(((Tcfilesection529005) 7))- 0], mainmodprocs_529148_3723162438); generatethreadvarssize_538771_839829468(m0); } LA9: ; code0 = genmodule_562491_839829468(m0, cfile0); { NIM_BOOL LOC13; LOC13 = (NIM_BOOL)0; LOC13 = shouldrecompile_563621_839829468(code0, cfile0); if (!LOC13) goto LA14; addfiletocompile_273863_2528170400(cfile0); } LA14: ; } goto LA1; LA5: ; { NIM_BOOL LOC17; NIM_BOOL LOC18; Ropeobj178006* code0; LOC17 = (NIM_BOOL)0; LOC18 = (NIM_BOOL)0; LOC18 = pending0; if (!(LOC18)) goto LA19; LOC18 = mergerequired_530832_2760143328(m0); LA19: ; LOC17 = LOC18; if (!(LOC17)) goto LA20; LOC17 = !((((*(*m0).module).flags &(1U<<((NU)(((Tsymflag292184) 12))&31U)))!=0)); LA20: ; if (!LOC17) goto LA21; mergefiles_531241_2760143328(cfile0, m0); geninitcode_562286_839829468(m0); finishtypedescriptions_535842_839829468(m0); code0 = genmodule_562491_839829468(m0, cfile0); writerope_178836_2381377266(code0, cfile0, NIM_FALSE); addfiletocompile_273863_2528170400(cfile0); } goto LA1; LA21: ; { NimStringDesc* LOC24; NIM_BOOL LOC25; LOC24 = (NimStringDesc*)0; LOC24 = toobjfile_273859_2528170400(cfilenoext0); LOC25 = (NIM_BOOL)0; LOC25 = nosexistsFile(LOC24); if (!!(LOC25)) goto LA26; addfiletocompile_273863_2528170400(cfile0); } goto LA1; LA26: ; LA1: ; addfiletolink_273872_2528170400(cfilenoext0); } N_NIMCALL(void, writeheader_563152_839829468)(Tcgen529027* m0) { Ropeobj178006* result0; Ropeobj178006* guard0; TY178507 LOC1; TY128506 LOC2; TY178507 LOC3; TY533289 LOC13; TY178507 LOC14; result0 = getcopyright_561665_839829468((*m0).filename); memset((void*)LOC1, 0, sizeof(LOC1)); memset((void*)(&LOC2), 0, sizeof(LOC2)); nossplitFile((*m0).filename, (&LOC2)); LOC1[0] = rope_178277_2381377266(LOC2.Field1); guard0 = HEX25_178905_2381377266(((NimStringDesc*) &T839829468_695), LOC1, 1); memset((void*)LOC3, 0, sizeof(LOC3)); LOC3[0] = guard0; addf_179205_2381377266(&result0, ((NimStringDesc*) &T839829468_696), LOC3, 1); addinttypes_561659_839829468(&result0); generateheaders_560104_839829468(m0); generatethreadlocalstorage_538717_839829468(m0); { Tcfilesection529005 i_563174_839829468; NI res_563200_839829468; i_563174_839829468 = (Tcfilesection529005)0; res_563200_839829468 = ((NI) 1); { while (1) { Ropeobj178006* LOC7; Ropeobj178006* LOC8; if (!(res_563200_839829468 <= ((NI) 10))) goto LA6; i_563174_839829468 = ((Tcfilesection529005) (res_563200_839829468)); LOC7 = (Ropeobj178006*)0; LOC7 = gensectionstart_530015_2760143328(i_563174_839829468); add_178482_2381377266(&result0, LOC7); add_178482_2381377266(&result0, (*m0).s[(i_563174_839829468)- 0]); LOC8 = (Ropeobj178006*)0; LOC8 = gensectionend_530050_2760143328(i_563174_839829468); add_178482_2381377266(&result0, LOC8); res_563200_839829468 += ((NI) 1); } LA6: ; } } add_178482_2381377266(&result0, (*m0).s[(((Tcfilesection529005) 11))- 0]); { if (!((gglobaloptions_169130_2607990831 &((NU64)1<<((NU)(((Tglobaloption169013) 8))&63U)))!=0)) goto LA11; add_178487_2381377266(&result0, ((NimStringDesc*) &T839829468_22)); } LA11: ; memset((void*)LOC13, 0, sizeof(LOC13)); addf_179205_2381377266(&result0, ((NimStringDesc*) &T839829468_697), LOC13, 0); memset((void*)LOC14, 0, sizeof(LOC14)); LOC14[0] = guard0; addf_179205_2381377266(&result0, ((NimStringDesc*) &T839829468_698), LOC14, 1); writerope_178836_2381377266(result0, (*m0).filename, NIM_FALSE); } N_NIMCALL(void, cgenwritemodules_563902_839829468)(void) { { if (!!((generatedheader_532201_839829468 == NIM_NIL))) goto LA3; finishmodule_563420_839829468(generatedheader_532201_839829468); } LA3: ; { while (1) { if (!(((NI) 0) < gforwardedprocscounter_529171_3723162438)) goto LA6; { Tcgen529027* m_563916_839829468; m_563916_839829468 = (Tcgen529027*)0; { NI i_563935_839829468; NI HEX3Atmp_563937_839829468; NI res_563939_839829468; i_563935_839829468 = (NI)0; HEX3Atmp_563937_839829468 = (NI)0; HEX3Atmp_563937_839829468 = (gmodules_529170_3723162438 ? (gmodules_529170_3723162438->Sup.len-1) : -1); res_563939_839829468 = ((NI) 0); { while (1) { if (!(res_563939_839829468 <= HEX3Atmp_563937_839829468)) goto LA10; i_563935_839829468 = res_563939_839829468; { if (!!((gmodules_529170_3723162438->data[i_563935_839829468] == NIM_NIL))) goto LA13; m_563916_839829468 = gmodules_529170_3723162438->data[i_563935_839829468]; { if (!!((*m_563916_839829468).Sup.fromcache)) goto LA17; finishmodule_563420_839829468(m_563916_839829468); } LA17: ; } LA13: ; res_563939_839829468 += ((NI) 1); } LA10: ; } } } } LA6: ; } { Tcgen529027* m_563917_839829468; m_563917_839829468 = (Tcgen529027*)0; { NI i_563946_839829468; NI HEX3Atmp_563948_839829468; NI res_563950_839829468; i_563946_839829468 = (NI)0; HEX3Atmp_563948_839829468 = (NI)0; HEX3Atmp_563948_839829468 = (gmodules_529170_3723162438 ? (gmodules_529170_3723162438->Sup.len-1) : -1); res_563950_839829468 = ((NI) 0); { while (1) { if (!(res_563950_839829468 <= HEX3Atmp_563948_839829468)) goto LA22; i_563946_839829468 = res_563950_839829468; { if (!!((gmodules_529170_3723162438->data[i_563946_839829468] == NIM_NIL))) goto LA25; m_563917_839829468 = gmodules_529170_3723162438->data[i_563946_839829468]; { if (!(*m_563917_839829468).Sup.fromcache) goto LA29; updatecachedmodule_563813_839829468(m_563917_839829468); } goto LA27; LA29: ; { writemodule_563637_839829468(m_563917_839829468, NIM_TRUE); } LA27: ; } LA25: ; res_563950_839829468 += ((NI) 1); } LA22: ; } } } writemapping_274789_2528170400(gmapping_529152_3723162438); { if (!!((generatedheader_532201_839829468 == NIM_NIL))) goto LA34; writeheader_563152_839829468(generatedheader_532201_839829468); } LA34: ; } N_NIMCALL(void, nullify_562833_839829468)(Ropeobj178006** arr0) { { Tcfilesection529005 i_562848_839829468; NI res_562853_839829468; i_562848_839829468 = (Tcfilesection529005)0; res_562853_839829468 = ((NI) 0); { while (1) { if (!(res_562853_839829468 <= ((NI) 17))) goto LA3; i_562848_839829468 = ((Tcfilesection529005) (res_562853_839829468)); unsureAsgnRef((void**) (&arr0[(i_562848_839829468)- 0]), NIM_NIL); res_562853_839829468 += ((NI) 1); } LA3: ; } } } N_NIMCALL(void, nullify_562858_839829468)(Ropeobj178006** arr0) { { NIM_CHAR i_563014_839829468; NI res_563019_839829468; i_563014_839829468 = (NIM_CHAR)0; res_563019_839829468 = ((NI) 48); { while (1) { if (!(res_563019_839829468 <= ((NI) 57))) goto LA3; i_563014_839829468 = ((NIM_CHAR) (res_563019_839829468)); unsureAsgnRef((void**) (&arr0[(((NU8)(i_563014_839829468)))- 48]), NIM_NIL); res_563019_839829468 += ((NI) 1); } LA3: ; } } } N_NIMCALL(void, resetmodule_562763_839829468)(Tcgen529027* m0) { initlinkedlist_147031_3771138726((&(*m0).headerfiles)); initintset_268885_2627731572((&(*m0).declaredprotos)); initidtable_296019_850551059((&(*m0).forwtypecache)); asgnRef((void**) (&(*m0).initproc), newproc_529206_3723162438(NIM_NIL, m0)); (*(*m0).initproc).options = initprocoptions_562635_839829468(m0); asgnRef((void**) (&(*m0).preinitproc), newpreinitproc_562625_839829468(m0)); asgnRef((void**) (&(*m0).postinitproc), newpostinitproc_562630_839829468(m0)); initnodetable_296085_850551059((&(*m0).datacache)); if ((*m0).typestack) nimGCunrefNoCycle((*m0).typestack); (*m0).typestack = (Ttypeseq292836*) newSeqRC1((&NTI292836), 0); if ((*m0).forwardedprocs) nimGCunrefNoCycle((*m0).forwardedprocs); (*m0).forwardedprocs = (Tsymseq292804*) newSeqRC1((&NTI292804), 0); asgnRefNoCycle((void**) (&(*m0).typenodesname), gettempname_533596_839829468(m0)); asgnRefNoCycle((void**) (&(*m0).nimtypesname), gettempname_533596_839829468(m0)); { if (!(((*(*m0).module).flags &(1U<<((NU)(((Tsymflag292184) 13))&31U)))!=0)) goto LA3; (*m0).flags |= ((NU8)1)<<((((Codegenflag529025) 0))%(sizeof(NU8)*8)); } goto LA1; LA3: ; { (*m0).flags &= ~(((NU8)1) << ((((Codegenflag529025) 0)) % (sizeof(NU8)*8))); } LA1: ; nullify_562833_839829468((*m0).s); (*m0).typenodes = ((NI) 0); (*m0).nimtypes = ((NI) 0); nullify_562858_839829468((*m0).extensionloaders); (*m0).Sup.fromcache = NIM_TRUE; } N_NIMCALL(void, resetcgenmodules_563024_839829468)(void) { { Tcgen529027* m_563026_839829468; m_563026_839829468 = (Tcgen529027*)0; { NI i_563031_839829468; NI HEX3Atmp_563033_839829468; NI res_563035_839829468; i_563031_839829468 = (NI)0; HEX3Atmp_563033_839829468 = (NI)0; HEX3Atmp_563033_839829468 = (gmodules_529170_3723162438 ? (gmodules_529170_3723162438->Sup.len-1) : -1); res_563035_839829468 = ((NI) 0); { while (1) { if (!(res_563035_839829468 <= HEX3Atmp_563033_839829468)) goto LA4; i_563031_839829468 = res_563035_839829468; { if (!!((gmodules_529170_3723162438->data[i_563031_839829468] == NIM_NIL))) goto LA7; m_563026_839829468 = gmodules_529170_3723162438->data[i_563031_839829468]; resetmodule_562763_839829468(m_563026_839829468); } LA7: ; res_563035_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_532655_839829468), rope_178277_2381377266(((NimStringDesc*) &T839829468_4))); if (nimtvdeps_538674_839829468) nimGCunrefNoCycle(nimtvdeps_538674_839829468); nimtvdeps_538674_839829468 = (Ttypeseq292836*) newSeqRC1((&NTI292836), 0); chckNil((void*)(&nimtvdeclared_538675_839829468)); genericReset((void*)(&nimtvdeclared_538675_839829468), (&NTI268030)); initintset_268885_2627731572((&nimtvdeclared_538675_839829468)); breakpointid_548860_839829468 = ((NI) 0); } NIM_EXTERNC N_NOINLINE(void, compiler_cgenDatInit000)(void) { }
static_sched.c
#include <stdio.h> #include <omp.h> #define THREADS 4 #define N 8 int main ( ) { int i; #pragma omp parallel for schedule(static) num_threads(THREADS) for (i = 0; i < N; i++) { sleep(i); printf("Thread %d iteration %d.\n", omp_get_thread_num(), i); } return 0; }
8986.c
// this source is derived from CHILL AST originally from file '/uufs/chpc.utah.edu/common/home/u1142914/lib/ytopt_vinu/polybench/polybench-code/stencils/fdtd-2d/kernel.c' as parsed by frontend compiler rose void kernel_fdtd_2d(int tmax, int nx, int ny, double ex[1000 + 0][1200 + 0], double ey[1000 + 0][1200 + 0], double hz[1000 + 0][1200 + 0], double _fict_[500 + 0]) { int t10; int t8; int t6; int t4; int t2; for (t2 = 0; t2 <= tmax - 1; t2 += 1) { for (t4 = 0; t4 <= ny - 1; t4 += 1) ey[0][t4] = _fict_[t2]; for (t4 = 1; t4 <= nx - 1; t4 += 1) for (t6 = 0; t6 <= ny - 1; t6 += 1) ey[t4][t6] = ey[t4][t6] - 0.5 * (hz[t4][t6] - hz[t4 - 1][t6]); #pragma omp parallel for private(t4,t6,t8,t10) for (t4 = 0; t4 <= nx - 1; t4 += 32) for (t6 = t4; t6 <= (t4 + 31 < nx - 1 ? t4 + 31 : nx - 1); t6 += 1) for (t8 = 1; t8 <= ny - 1; t8 += 32) for (t10 = t8; t10 <= (ny - 1 < t8 + 31 ? ny - 1 : t8 + 31); t10 += 1) ex[t6][t10] = ex[t6][t10] - 0.5 * (hz[t6][t10] - hz[t6][t10 - 1]); #pragma omp parallel for private(t4,t6,t8,t10) for (t4 = 0; t4 <= nx - 2; t4 += 32) for (t6 = t4; t6 <= (t4 + 31 < nx - 2 ? t4 + 31 : nx - 2); t6 += 1) for (t8 = 0; t8 <= ny - 2; t8 += 32) for (t10 = t8; t10 <= (ny - 2 < t8 + 31 ? ny - 2 : t8 + 31); t10 += 1) hz[t6][t10] = hz[t6][t10] - 0.69999999999999996 * (ex[t6][t10 + 1] - ex[t6][t10] + ey[t6 + 1][t10] - ey[t6][t10]); } }
sum_parallel.c
//Ejercicio EDA 2 Prof. Francisco Rodriguez /* Para compilar usar gcc -Wall -std=c99 sum_parallel.c -fopenmp */ #include <stdio.h> #include <stdlib.h> // para la función rand() #include <time.h> // para inicializar la semilla de aleatoriedad #include <omp.h> // para las funciones de biblioteca de OpenMP // No vamos a usar esta función, pero está aquí para que se vea la // diferencia con su contraparte paralela. void sum_sec( int arr1[], int arr2[], int res[], int tam ) { for( int i = 0; i < tam; ++i ){ res[ i ] = arr1[ i ] + arr2[ i ]; } } void sum_par( int arr1[], int arr2[], int res[], int tam ) { #pragma omp parallel for num_threads( 4 ) for( int i = 0; i < tam; ++i ) { printf( "The thread %d is calculating res[ %d ]\n", omp_get_thread_num(), i ); res[ i ] = arr1[ i ] + arr2[ i ]; } } #define TAM 10 int main() { int a[ TAM ]; int b[ TAM ]; int c[ TAM ]; srand( time( NULL ) ); for( int i = 0; i < TAM; ++i ) { a[ i ] = rand() % 100; b[ i ] = rand() % 100; } sum_par( a, b, c, TAM ); for( int i = 0; i < TAM; ++i ) { printf( "%2d) %d + %d = %d\n", i + 1, a[ i ], b[ i ], c[ i ] ); } }
GB_unaryop__ainv_uint8_int32.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_uint8_int32 // op(A') function: GB_tran__ainv_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_CASTING(z, x) \ uint8_t z = (uint8_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_UINT8 || GxB_NO_INT32) //------------------------------------------------------------------------------ // Cx = op (cast (Ax)): apply a unary operator //------------------------------------------------------------------------------ GrB_Info GB_unop__ainv_uint8_int32 ( uint8_t *restrict Cx, const int32_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_uint8_int32 ( 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
ASTMatchers.h
//===- ASTMatchers.h - Structural query framework ---------------*- C++ -*-===// // // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. // See https://llvm.org/LICENSE.txt for license information. // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception // //===----------------------------------------------------------------------===// // // This file implements matchers to be used together with the MatchFinder to // match AST nodes. // // Matchers are created by generator functions, which can be combined in // a functional in-language DSL to express queries over the C++ AST. // // For example, to match a class with a certain name, one would call: // cxxRecordDecl(hasName("MyClass")) // which returns a matcher that can be used to find all AST nodes that declare // a class named 'MyClass'. // // For more complicated match expressions we're often interested in accessing // multiple parts of the matched AST nodes once a match is found. In that case, // use the id(...) matcher around the match expressions that match the nodes // you want to access. // // For example, when we're interested in child classes of a certain class, we // would write: // cxxRecordDecl(hasName("MyClass"), has(id("child", recordDecl()))) // When the match is found via the MatchFinder, a user provided callback will // be called with a BoundNodes instance that contains a mapping from the // strings that we provided for the id(...) calls to the nodes that were // matched. // In the given example, each time our matcher finds a match we get a callback // where "child" is bound to the RecordDecl node of the matching child // class declaration. // // See ASTMatchersInternal.h for a more in-depth explanation of the // implementation details of the matcher framework. // // See ASTMatchFinder.h for how to use the generated matchers to run over // an AST. // //===----------------------------------------------------------------------===// #ifndef LLVM_CLANG_ASTMATCHERS_ASTMATCHERS_H #define LLVM_CLANG_ASTMATCHERS_ASTMATCHERS_H #include "clang/AST/ASTContext.h" #include "clang/AST/ASTTypeTraits.h" #include "clang/AST/Attr.h" #include "clang/AST/Decl.h" #include "clang/AST/DeclCXX.h" #include "clang/AST/DeclFriend.h" #include "clang/AST/DeclObjC.h" #include "clang/AST/DeclTemplate.h" #include "clang/AST/Expr.h" #include "clang/AST/ExprCXX.h" #include "clang/AST/ExprObjC.h" #include "clang/AST/NestedNameSpecifier.h" #include "clang/AST/OpenMPClause.h" #include "clang/AST/OperationKinds.h" #include "clang/AST/Stmt.h" #include "clang/AST/StmtCXX.h" #include "clang/AST/StmtObjC.h" #include "clang/AST/StmtOpenMP.h" #include "clang/AST/TemplateBase.h" #include "clang/AST/TemplateName.h" #include "clang/AST/Type.h" #include "clang/AST/TypeLoc.h" #include "clang/ASTMatchers/ASTMatchersInternal.h" #include "clang/ASTMatchers/ASTMatchersMacros.h" #include "clang/Basic/AttrKinds.h" #include "clang/Basic/ExceptionSpecificationType.h" #include "clang/Basic/IdentifierTable.h" #include "clang/Basic/LLVM.h" #include "clang/Basic/SourceManager.h" #include "clang/Basic/Specifiers.h" #include "clang/Basic/TypeTraits.h" #include "llvm/ADT/ArrayRef.h" #include "llvm/ADT/SmallVector.h" #include "llvm/ADT/StringRef.h" #include "llvm/Support/Casting.h" #include "llvm/Support/Compiler.h" #include "llvm/Support/ErrorHandling.h" #include "llvm/Support/Regex.h" #include <cassert> #include <cstddef> #include <iterator> #include <limits> #include <string> #include <utility> #include <vector> namespace clang { namespace ast_matchers { /// Maps string IDs to AST nodes matched by parts of a matcher. /// /// The bound nodes are generated by calling \c bind("id") on the node matchers /// of the nodes we want to access later. /// /// The instances of BoundNodes are created by \c MatchFinder when the user's /// callbacks are executed every time a match is found. class BoundNodes { public: /// Returns the AST node bound to \c ID. /// /// Returns NULL if there was no node bound to \c ID or if there is a node but /// it cannot be converted to the specified type. template <typename T> const T *getNodeAs(StringRef ID) const { return MyBoundNodes.getNodeAs<T>(ID); } /// Type of mapping from binding identifiers to bound nodes. This type /// is an associative container with a key type of \c std::string and a value /// type of \c clang::ast_type_traits::DynTypedNode using IDToNodeMap = internal::BoundNodesMap::IDToNodeMap; /// Retrieve mapping from binding identifiers to bound nodes. const IDToNodeMap &getMap() const { return MyBoundNodes.getMap(); } private: friend class internal::BoundNodesTreeBuilder; /// Create BoundNodes from a pre-filled map of bindings. BoundNodes(internal::BoundNodesMap &MyBoundNodes) : MyBoundNodes(MyBoundNodes) {} internal::BoundNodesMap MyBoundNodes; }; /// If the provided matcher matches a node, binds the node to \c ID. /// /// FIXME: Do we want to support this now that we have bind()? template <typename T> internal::Matcher<T> id(StringRef ID, const internal::BindableMatcher<T> &InnerMatcher) { return InnerMatcher.bind(ID); } /// Types of matchers for the top-level classes in the AST class /// hierarchy. /// @{ using DeclarationMatcher = internal::Matcher<Decl>; using StatementMatcher = internal::Matcher<Stmt>; using TypeMatcher = internal::Matcher<QualType>; using TypeLocMatcher = internal::Matcher<TypeLoc>; using NestedNameSpecifierMatcher = internal::Matcher<NestedNameSpecifier>; using NestedNameSpecifierLocMatcher = internal::Matcher<NestedNameSpecifierLoc>; using CXXCtorInitializerMatcher = internal::Matcher<CXXCtorInitializer>; /// @} /// Matches any node. /// /// Useful when another matcher requires a child matcher, but there's no /// additional constraint. This will often be used with an explicit conversion /// to an \c internal::Matcher<> type such as \c TypeMatcher. /// /// Example: \c DeclarationMatcher(anything()) matches all declarations, e.g., /// \code /// "int* p" and "void f()" in /// int* p; /// void f(); /// \endcode /// /// Usable as: Any Matcher inline internal::TrueMatcher anything() { return internal::TrueMatcher(); } /// Matches the top declaration context. /// /// Given /// \code /// int X; /// namespace NS { /// int Y; /// } // namespace NS /// \endcode /// decl(hasDeclContext(translationUnitDecl())) /// matches "int X", but not "int Y". extern const internal::VariadicDynCastAllOfMatcher<Decl, TranslationUnitDecl> translationUnitDecl; /// Matches typedef declarations. /// /// Given /// \code /// typedef int X; /// using Y = int; /// \endcode /// typedefDecl() /// matches "typedef int X", but not "using Y = int" extern const internal::VariadicDynCastAllOfMatcher<Decl, TypedefDecl> typedefDecl; /// Matches typedef name declarations. /// /// Given /// \code /// typedef int X; /// using Y = int; /// \endcode /// typedefNameDecl() /// matches "typedef int X" and "using Y = int" extern const internal::VariadicDynCastAllOfMatcher<Decl, TypedefNameDecl> typedefNameDecl; /// Matches type alias declarations. /// /// Given /// \code /// typedef int X; /// using Y = int; /// \endcode /// typeAliasDecl() /// matches "using Y = int", but not "typedef int X" extern const internal::VariadicDynCastAllOfMatcher<Decl, TypeAliasDecl> typeAliasDecl; /// Matches type alias template declarations. /// /// typeAliasTemplateDecl() matches /// \code /// template <typename T> /// using Y = X<T>; /// \endcode extern const internal::VariadicDynCastAllOfMatcher<Decl, TypeAliasTemplateDecl> typeAliasTemplateDecl; /// Matches AST nodes that were expanded within the main-file. /// /// Example matches X but not Y /// (matcher = cxxRecordDecl(isExpansionInMainFile()) /// \code /// #include <Y.h> /// class X {}; /// \endcode /// Y.h: /// \code /// class Y {}; /// \endcode /// /// Usable as: Matcher<Decl>, Matcher<Stmt>, Matcher<TypeLoc> AST_POLYMORPHIC_MATCHER(isExpansionInMainFile, AST_POLYMORPHIC_SUPPORTED_TYPES(Decl, Stmt, TypeLoc)) { auto &SourceManager = Finder->getASTContext().getSourceManager(); return SourceManager.isInMainFile( SourceManager.getExpansionLoc(Node.getBeginLoc())); } /// Matches AST nodes that were expanded within system-header-files. /// /// Example matches Y but not X /// (matcher = cxxRecordDecl(isExpansionInSystemHeader()) /// \code /// #include <SystemHeader.h> /// class X {}; /// \endcode /// SystemHeader.h: /// \code /// class Y {}; /// \endcode /// /// Usable as: Matcher<Decl>, Matcher<Stmt>, Matcher<TypeLoc> AST_POLYMORPHIC_MATCHER(isExpansionInSystemHeader, AST_POLYMORPHIC_SUPPORTED_TYPES(Decl, Stmt, TypeLoc)) { auto &SourceManager = Finder->getASTContext().getSourceManager(); auto ExpansionLoc = SourceManager.getExpansionLoc(Node.getBeginLoc()); if (ExpansionLoc.isInvalid()) { return false; } return SourceManager.isInSystemHeader(ExpansionLoc); } /// Matches AST nodes that were expanded within files whose name is /// partially matching a given regex. /// /// Example matches Y but not X /// (matcher = cxxRecordDecl(isExpansionInFileMatching("AST.*")) /// \code /// #include "ASTMatcher.h" /// class X {}; /// \endcode /// ASTMatcher.h: /// \code /// class Y {}; /// \endcode /// /// Usable as: Matcher<Decl>, Matcher<Stmt>, Matcher<TypeLoc> AST_POLYMORPHIC_MATCHER_P(isExpansionInFileMatching, AST_POLYMORPHIC_SUPPORTED_TYPES(Decl, Stmt, TypeLoc), std::string, RegExp) { auto &SourceManager = Finder->getASTContext().getSourceManager(); auto ExpansionLoc = SourceManager.getExpansionLoc(Node.getBeginLoc()); if (ExpansionLoc.isInvalid()) { return false; } auto FileEntry = SourceManager.getFileEntryForID(SourceManager.getFileID(ExpansionLoc)); if (!FileEntry) { return false; } auto Filename = FileEntry->getName(); llvm::Regex RE(RegExp); return RE.match(Filename); } /// Matches declarations. /// /// Examples matches \c X, \c C, and the friend declaration inside \c C; /// \code /// void X(); /// class C { /// friend X; /// }; /// \endcode extern const internal::VariadicAllOfMatcher<Decl> decl; /// Matches a declaration of a linkage specification. /// /// Given /// \code /// extern "C" {} /// \endcode /// linkageSpecDecl() /// matches "extern "C" {}" extern const internal::VariadicDynCastAllOfMatcher<Decl, LinkageSpecDecl> linkageSpecDecl; /// Matches a declaration of anything that could have a name. /// /// Example matches \c X, \c S, the anonymous union type, \c i, and \c U; /// \code /// typedef int X; /// struct S { /// union { /// int i; /// } U; /// }; /// \endcode extern const internal::VariadicDynCastAllOfMatcher<Decl, NamedDecl> namedDecl; /// Matches a declaration of label. /// /// Given /// \code /// goto FOO; /// FOO: bar(); /// \endcode /// labelDecl() /// matches 'FOO:' extern const internal::VariadicDynCastAllOfMatcher<Decl, LabelDecl> labelDecl; /// Matches a declaration of a namespace. /// /// Given /// \code /// namespace {} /// namespace test {} /// \endcode /// namespaceDecl() /// matches "namespace {}" and "namespace test {}" extern const internal::VariadicDynCastAllOfMatcher<Decl, NamespaceDecl> namespaceDecl; /// Matches a declaration of a namespace alias. /// /// Given /// \code /// namespace test {} /// namespace alias = ::test; /// \endcode /// namespaceAliasDecl() /// matches "namespace alias" but not "namespace test" extern const internal::VariadicDynCastAllOfMatcher<Decl, NamespaceAliasDecl> namespaceAliasDecl; /// Matches class, struct, and union declarations. /// /// Example matches \c X, \c Z, \c U, and \c S /// \code /// class X; /// template<class T> class Z {}; /// struct S {}; /// union U {}; /// \endcode extern const internal::VariadicDynCastAllOfMatcher<Decl, RecordDecl> recordDecl; /// Matches C++ class declarations. /// /// Example matches \c X, \c Z /// \code /// class X; /// template<class T> class Z {}; /// \endcode extern const internal::VariadicDynCastAllOfMatcher<Decl, CXXRecordDecl> cxxRecordDecl; /// Matches C++ class template declarations. /// /// Example matches \c Z /// \code /// template<class T> class Z {}; /// \endcode extern const internal::VariadicDynCastAllOfMatcher<Decl, ClassTemplateDecl> classTemplateDecl; /// Matches C++ class template specializations. /// /// Given /// \code /// template<typename T> class A {}; /// template<> class A<double> {}; /// A<int> a; /// \endcode /// classTemplateSpecializationDecl() /// matches the specializations \c A<int> and \c A<double> extern const internal::VariadicDynCastAllOfMatcher< Decl, ClassTemplateSpecializationDecl> classTemplateSpecializationDecl; /// Matches C++ class template partial specializations. /// /// Given /// \code /// template<class T1, class T2, int I> /// class A {}; /// /// template<class T, int I> /// class A<T, T*, I> {}; /// /// template<> /// class A<int, int, 1> {}; /// \endcode /// classTemplatePartialSpecializationDecl() /// matches the specialization \c A<T,T*,I> but not \c A<int,int,1> extern const internal::VariadicDynCastAllOfMatcher< Decl, ClassTemplatePartialSpecializationDecl> classTemplatePartialSpecializationDecl; /// Matches declarator declarations (field, variable, function /// and non-type template parameter declarations). /// /// Given /// \code /// class X { int y; }; /// \endcode /// declaratorDecl() /// matches \c int y. extern const internal::VariadicDynCastAllOfMatcher<Decl, DeclaratorDecl> declaratorDecl; /// Matches parameter variable declarations. /// /// Given /// \code /// void f(int x); /// \endcode /// parmVarDecl() /// matches \c int x. extern const internal::VariadicDynCastAllOfMatcher<Decl, ParmVarDecl> parmVarDecl; /// Matches C++ access specifier declarations. /// /// Given /// \code /// class C { /// public: /// int a; /// }; /// \endcode /// accessSpecDecl() /// matches 'public:' extern const internal::VariadicDynCastAllOfMatcher<Decl, AccessSpecDecl> accessSpecDecl; /// Matches constructor initializers. /// /// Examples matches \c i(42). /// \code /// class C { /// C() : i(42) {} /// int i; /// }; /// \endcode extern const internal::VariadicAllOfMatcher<CXXCtorInitializer> cxxCtorInitializer; /// Matches template arguments. /// /// Given /// \code /// template <typename T> struct C {}; /// C<int> c; /// \endcode /// templateArgument() /// matches 'int' in C<int>. extern const internal::VariadicAllOfMatcher<TemplateArgument> templateArgument; /// Matches template name. /// /// Given /// \code /// template <typename T> class X { }; /// X<int> xi; /// \endcode /// templateName() /// matches 'X' in X<int>. extern const internal::VariadicAllOfMatcher<TemplateName> templateName; /// Matches non-type template parameter declarations. /// /// Given /// \code /// template <typename T, int N> struct C {}; /// \endcode /// nonTypeTemplateParmDecl() /// matches 'N', but not 'T'. extern const internal::VariadicDynCastAllOfMatcher<Decl, NonTypeTemplateParmDecl> nonTypeTemplateParmDecl; /// Matches template type parameter declarations. /// /// Given /// \code /// template <typename T, int N> struct C {}; /// \endcode /// templateTypeParmDecl() /// matches 'T', but not 'N'. extern const internal::VariadicDynCastAllOfMatcher<Decl, TemplateTypeParmDecl> templateTypeParmDecl; /// Matches public C++ declarations. /// /// Given /// \code /// class C { /// public: int a; /// protected: int b; /// private: int c; /// }; /// \endcode /// fieldDecl(isPublic()) /// matches 'int a;' AST_MATCHER(Decl, isPublic) { return Node.getAccess() == AS_public; } /// Matches protected C++ declarations. /// /// Given /// \code /// class C { /// public: int a; /// protected: int b; /// private: int c; /// }; /// \endcode /// fieldDecl(isProtected()) /// matches 'int b;' AST_MATCHER(Decl, isProtected) { return Node.getAccess() == AS_protected; } /// Matches private C++ declarations. /// /// Given /// \code /// class C { /// public: int a; /// protected: int b; /// private: int c; /// }; /// \endcode /// fieldDecl(isPrivate()) /// matches 'int c;' AST_MATCHER(Decl, isPrivate) { return Node.getAccess() == AS_private; } /// Matches non-static data members that are bit-fields. /// /// Given /// \code /// class C { /// int a : 2; /// int b; /// }; /// \endcode /// fieldDecl(isBitField()) /// matches 'int a;' but not 'int b;'. AST_MATCHER(FieldDecl, isBitField) { return Node.isBitField(); } /// Matches non-static data members that are bit-fields of the specified /// bit width. /// /// Given /// \code /// class C { /// int a : 2; /// int b : 4; /// int c : 2; /// }; /// \endcode /// fieldDecl(hasBitWidth(2)) /// matches 'int a;' and 'int c;' but not 'int b;'. AST_MATCHER_P(FieldDecl, hasBitWidth, unsigned, Width) { return Node.isBitField() && Node.getBitWidthValue(Finder->getASTContext()) == Width; } /// Matches non-static data members that have an in-class initializer. /// /// Given /// \code /// class C { /// int a = 2; /// int b = 3; /// int c; /// }; /// \endcode /// fieldDecl(hasInClassInitializer(integerLiteral(equals(2)))) /// matches 'int a;' but not 'int b;'. /// fieldDecl(hasInClassInitializer(anything())) /// matches 'int a;' and 'int b;' but not 'int c;'. AST_MATCHER_P(FieldDecl, hasInClassInitializer, internal::Matcher<Expr>, InnerMatcher) { const Expr *Initializer = Node.getInClassInitializer(); return (Initializer != nullptr && InnerMatcher.matches(*Initializer, Finder, Builder)); } /// Determines whether the function is "main", which is the entry point /// into an executable program. AST_MATCHER(FunctionDecl, isMain) { return Node.isMain(); } /// Matches the specialized template of a specialization declaration. /// /// Given /// \code /// template<typename T> class A {}; #1 /// template<> class A<int> {}; #2 /// \endcode /// classTemplateSpecializationDecl(hasSpecializedTemplate(classTemplateDecl())) /// matches '#2' with classTemplateDecl() matching the class template /// declaration of 'A' at #1. AST_MATCHER_P(ClassTemplateSpecializationDecl, hasSpecializedTemplate, internal::Matcher<ClassTemplateDecl>, InnerMatcher) { const ClassTemplateDecl* Decl = Node.getSpecializedTemplate(); return (Decl != nullptr && InnerMatcher.matches(*Decl, Finder, Builder)); } /// Matches a declaration that has been implicitly added /// by the compiler (eg. implicit default/copy constructors). AST_MATCHER(Decl, isImplicit) { return Node.isImplicit(); } /// Matches classTemplateSpecializations, templateSpecializationType and /// functionDecl that have at least one TemplateArgument matching the given /// InnerMatcher. /// /// Given /// \code /// template<typename T> class A {}; /// template<> class A<double> {}; /// A<int> a; /// /// template<typename T> f() {}; /// void func() { f<int>(); }; /// \endcode /// /// \endcode /// classTemplateSpecializationDecl(hasAnyTemplateArgument( /// refersToType(asString("int")))) /// matches the specialization \c A<int> /// /// functionDecl(hasAnyTemplateArgument(refersToType(asString("int")))) /// matches the specialization \c f<int> AST_POLYMORPHIC_MATCHER_P( hasAnyTemplateArgument, AST_POLYMORPHIC_SUPPORTED_TYPES(ClassTemplateSpecializationDecl, TemplateSpecializationType, FunctionDecl), internal::Matcher<TemplateArgument>, InnerMatcher) { ArrayRef<TemplateArgument> List = internal::getTemplateSpecializationArgs(Node); return matchesFirstInRange(InnerMatcher, List.begin(), List.end(), Finder, Builder); } /// Matches expressions that match InnerMatcher after any implicit AST /// nodes are stripped off. /// /// Parentheses and explicit casts are not discarded. /// Given /// \code /// class C {}; /// C a = C(); /// C b; /// C c = b; /// \endcode /// The matchers /// \code /// varDecl(hasInitializer(ignoringImplicit(cxxConstructExpr()))) /// \endcode /// would match the declarations for a, b, and c. /// While /// \code /// varDecl(hasInitializer(cxxConstructExpr())) /// \endcode /// only match the declarations for b and c. AST_MATCHER_P(Expr, ignoringImplicit, internal::Matcher<Expr>, InnerMatcher) { return InnerMatcher.matches(*Node.IgnoreImplicit(), Finder, Builder); } /// Matches expressions that match InnerMatcher after any implicit casts /// are stripped off. /// /// Parentheses and explicit casts are not discarded. /// Given /// \code /// int arr[5]; /// int a = 0; /// char b = 0; /// const int c = a; /// int *d = arr; /// long e = (long) 0l; /// \endcode /// The matchers /// \code /// varDecl(hasInitializer(ignoringImpCasts(integerLiteral()))) /// varDecl(hasInitializer(ignoringImpCasts(declRefExpr()))) /// \endcode /// would match the declarations for a, b, c, and d, but not e. /// While /// \code /// varDecl(hasInitializer(integerLiteral())) /// varDecl(hasInitializer(declRefExpr())) /// \endcode /// only match the declarations for b, c, and d. AST_MATCHER_P(Expr, ignoringImpCasts, internal::Matcher<Expr>, InnerMatcher) { return InnerMatcher.matches(*Node.IgnoreImpCasts(), Finder, Builder); } /// Matches expressions that match InnerMatcher after parentheses and /// casts are stripped off. /// /// Implicit and non-C Style casts are also discarded. /// Given /// \code /// int a = 0; /// char b = (0); /// void* c = reinterpret_cast<char*>(0); /// char d = char(0); /// \endcode /// The matcher /// varDecl(hasInitializer(ignoringParenCasts(integerLiteral()))) /// would match the declarations for a, b, c, and d. /// while /// varDecl(hasInitializer(integerLiteral())) /// only match the declaration for a. AST_MATCHER_P(Expr, ignoringParenCasts, internal::Matcher<Expr>, InnerMatcher) { return InnerMatcher.matches(*Node.IgnoreParenCasts(), Finder, Builder); } /// Matches expressions that match InnerMatcher after implicit casts and /// parentheses are stripped off. /// /// Explicit casts are not discarded. /// Given /// \code /// int arr[5]; /// int a = 0; /// char b = (0); /// const int c = a; /// int *d = (arr); /// long e = ((long) 0l); /// \endcode /// The matchers /// varDecl(hasInitializer(ignoringParenImpCasts(integerLiteral()))) /// varDecl(hasInitializer(ignoringParenImpCasts(declRefExpr()))) /// would match the declarations for a, b, c, and d, but not e. /// while /// varDecl(hasInitializer(integerLiteral())) /// varDecl(hasInitializer(declRefExpr())) /// would only match the declaration for a. AST_MATCHER_P(Expr, ignoringParenImpCasts, internal::Matcher<Expr>, InnerMatcher) { return InnerMatcher.matches(*Node.IgnoreParenImpCasts(), Finder, Builder); } /// Matches types that match InnerMatcher after any parens are stripped. /// /// Given /// \code /// void (*fp)(void); /// \endcode /// The matcher /// \code /// varDecl(hasType(pointerType(pointee(ignoringParens(functionType()))))) /// \endcode /// would match the declaration for fp. AST_MATCHER_P_OVERLOAD(QualType, ignoringParens, internal::Matcher<QualType>, InnerMatcher, 0) { return InnerMatcher.matches(Node.IgnoreParens(), Finder, Builder); } /// Overload \c ignoringParens for \c Expr. /// /// Given /// \code /// const char* str = ("my-string"); /// \endcode /// The matcher /// \code /// implicitCastExpr(hasSourceExpression(ignoringParens(stringLiteral()))) /// \endcode /// would match the implicit cast resulting from the assignment. AST_MATCHER_P_OVERLOAD(Expr, ignoringParens, internal::Matcher<Expr>, InnerMatcher, 1) { const Expr *E = Node.IgnoreParens(); return InnerMatcher.matches(*E, Finder, Builder); } /// Matches expressions that are instantiation-dependent even if it is /// neither type- nor value-dependent. /// /// In the following example, the expression sizeof(sizeof(T() + T())) /// is instantiation-dependent (since it involves a template parameter T), /// but is neither type- nor value-dependent, since the type of the inner /// sizeof is known (std::size_t) and therefore the size of the outer /// sizeof is known. /// \code /// template<typename T> /// void f(T x, T y) { sizeof(sizeof(T() + T()); } /// \endcode /// expr(isInstantiationDependent()) matches sizeof(sizeof(T() + T()) AST_MATCHER(Expr, isInstantiationDependent) { return Node.isInstantiationDependent(); } /// Matches expressions that are type-dependent because the template type /// is not yet instantiated. /// /// For example, the expressions "x" and "x + y" are type-dependent in /// the following code, but "y" is not type-dependent: /// \code /// template<typename T> /// void add(T x, int y) { /// x + y; /// } /// \endcode /// expr(isTypeDependent()) matches x + y AST_MATCHER(Expr, isTypeDependent) { return Node.isTypeDependent(); } /// Matches expression that are value-dependent because they contain a /// non-type template parameter. /// /// For example, the array bound of "Chars" in the following example is /// value-dependent. /// \code /// template<int Size> int f() { return Size; } /// \endcode /// expr(isValueDependent()) matches return Size AST_MATCHER(Expr, isValueDependent) { return Node.isValueDependent(); } /// Matches classTemplateSpecializations, templateSpecializationType and /// functionDecl where the n'th TemplateArgument matches the given InnerMatcher. /// /// Given /// \code /// template<typename T, typename U> class A {}; /// A<bool, int> b; /// A<int, bool> c; /// /// template<typename T> void f() {} /// void func() { f<int>(); }; /// \endcode /// classTemplateSpecializationDecl(hasTemplateArgument( /// 1, refersToType(asString("int")))) /// matches the specialization \c A<bool, int> /// /// functionDecl(hasTemplateArgument(0, refersToType(asString("int")))) /// matches the specialization \c f<int> AST_POLYMORPHIC_MATCHER_P2( hasTemplateArgument, AST_POLYMORPHIC_SUPPORTED_TYPES(ClassTemplateSpecializationDecl, TemplateSpecializationType, FunctionDecl), unsigned, N, internal::Matcher<TemplateArgument>, InnerMatcher) { ArrayRef<TemplateArgument> List = internal::getTemplateSpecializationArgs(Node); if (List.size() <= N) return false; return InnerMatcher.matches(List[N], Finder, Builder); } /// Matches if the number of template arguments equals \p N. /// /// Given /// \code /// template<typename T> struct C {}; /// C<int> c; /// \endcode /// classTemplateSpecializationDecl(templateArgumentCountIs(1)) /// matches C<int>. AST_POLYMORPHIC_MATCHER_P( templateArgumentCountIs, AST_POLYMORPHIC_SUPPORTED_TYPES(ClassTemplateSpecializationDecl, TemplateSpecializationType), unsigned, N) { return internal::getTemplateSpecializationArgs(Node).size() == N; } /// Matches a TemplateArgument that refers to a certain type. /// /// Given /// \code /// struct X {}; /// template<typename T> struct A {}; /// A<X> a; /// \endcode /// classTemplateSpecializationDecl(hasAnyTemplateArgument( /// refersToType(class(hasName("X"))))) /// matches the specialization \c A<X> AST_MATCHER_P(TemplateArgument, refersToType, internal::Matcher<QualType>, InnerMatcher) { if (Node.getKind() != TemplateArgument::Type) return false; return InnerMatcher.matches(Node.getAsType(), Finder, Builder); } /// Matches a TemplateArgument that refers to a certain template. /// /// Given /// \code /// template<template <typename> class S> class X {}; /// template<typename T> class Y {}; /// X<Y> xi; /// \endcode /// classTemplateSpecializationDecl(hasAnyTemplateArgument( /// refersToTemplate(templateName()))) /// matches the specialization \c X<Y> AST_MATCHER_P(TemplateArgument, refersToTemplate, internal::Matcher<TemplateName>, InnerMatcher) { if (Node.getKind() != TemplateArgument::Template) return false; return InnerMatcher.matches(Node.getAsTemplate(), Finder, Builder); } /// Matches a canonical TemplateArgument that refers to a certain /// declaration. /// /// Given /// \code /// struct B { int next; }; /// template<int(B::*next_ptr)> struct A {}; /// A<&B::next> a; /// \endcode /// classTemplateSpecializationDecl(hasAnyTemplateArgument( /// refersToDeclaration(fieldDecl(hasName("next"))))) /// matches the specialization \c A<&B::next> with \c fieldDecl(...) matching /// \c B::next AST_MATCHER_P(TemplateArgument, refersToDeclaration, internal::Matcher<Decl>, InnerMatcher) { if (Node.getKind() == TemplateArgument::Declaration) return InnerMatcher.matches(*Node.getAsDecl(), Finder, Builder); return false; } /// Matches a sugar TemplateArgument that refers to a certain expression. /// /// Given /// \code /// struct B { int next; }; /// template<int(B::*next_ptr)> struct A {}; /// A<&B::next> a; /// \endcode /// templateSpecializationType(hasAnyTemplateArgument( /// isExpr(hasDescendant(declRefExpr(to(fieldDecl(hasName("next")))))))) /// matches the specialization \c A<&B::next> with \c fieldDecl(...) matching /// \c B::next AST_MATCHER_P(TemplateArgument, isExpr, internal::Matcher<Expr>, InnerMatcher) { if (Node.getKind() == TemplateArgument::Expression) return InnerMatcher.matches(*Node.getAsExpr(), Finder, Builder); return false; } /// Matches a TemplateArgument that is an integral value. /// /// Given /// \code /// template<int T> struct C {}; /// C<42> c; /// \endcode /// classTemplateSpecializationDecl( /// hasAnyTemplateArgument(isIntegral())) /// matches the implicit instantiation of C in C<42> /// with isIntegral() matching 42. AST_MATCHER(TemplateArgument, isIntegral) { return Node.getKind() == TemplateArgument::Integral; } /// Matches a TemplateArgument that referes to an integral type. /// /// Given /// \code /// template<int T> struct C {}; /// C<42> c; /// \endcode /// classTemplateSpecializationDecl( /// hasAnyTemplateArgument(refersToIntegralType(asString("int")))) /// matches the implicit instantiation of C in C<42>. AST_MATCHER_P(TemplateArgument, refersToIntegralType, internal::Matcher<QualType>, InnerMatcher) { if (Node.getKind() != TemplateArgument::Integral) return false; return InnerMatcher.matches(Node.getIntegralType(), Finder, Builder); } /// Matches a TemplateArgument of integral type with a given value. /// /// Note that 'Value' is a string as the template argument's value is /// an arbitrary precision integer. 'Value' must be euqal to the canonical /// representation of that integral value in base 10. /// /// Given /// \code /// template<int T> struct C {}; /// C<42> c; /// \endcode /// classTemplateSpecializationDecl( /// hasAnyTemplateArgument(equalsIntegralValue("42"))) /// matches the implicit instantiation of C in C<42>. AST_MATCHER_P(TemplateArgument, equalsIntegralValue, std::string, Value) { if (Node.getKind() != TemplateArgument::Integral) return false; return Node.getAsIntegral().toString(10) == Value; } /// Matches an Objective-C autorelease pool statement. /// /// Given /// \code /// @autoreleasepool { /// int x = 0; /// } /// \endcode /// autoreleasePoolStmt(stmt()) matches the declaration of "x" /// inside the autorelease pool. extern const internal::VariadicDynCastAllOfMatcher<Stmt, ObjCAutoreleasePoolStmt> autoreleasePoolStmt; /// Matches any value declaration. /// /// Example matches A, B, C and F /// \code /// enum X { A, B, C }; /// void F(); /// \endcode extern const internal::VariadicDynCastAllOfMatcher<Decl, ValueDecl> valueDecl; /// Matches C++ constructor declarations. /// /// Example matches Foo::Foo() and Foo::Foo(int) /// \code /// class Foo { /// public: /// Foo(); /// Foo(int); /// int DoSomething(); /// }; /// \endcode extern const internal::VariadicDynCastAllOfMatcher<Decl, CXXConstructorDecl> cxxConstructorDecl; /// Matches explicit C++ destructor declarations. /// /// Example matches Foo::~Foo() /// \code /// class Foo { /// public: /// virtual ~Foo(); /// }; /// \endcode extern const internal::VariadicDynCastAllOfMatcher<Decl, CXXDestructorDecl> cxxDestructorDecl; /// Matches enum declarations. /// /// Example matches X /// \code /// enum X { /// A, B, C /// }; /// \endcode extern const internal::VariadicDynCastAllOfMatcher<Decl, EnumDecl> enumDecl; /// Matches enum constants. /// /// Example matches A, B, C /// \code /// enum X { /// A, B, C /// }; /// \endcode extern const internal::VariadicDynCastAllOfMatcher<Decl, EnumConstantDecl> enumConstantDecl; /// Matches method declarations. /// /// Example matches y /// \code /// class X { void y(); }; /// \endcode extern const internal::VariadicDynCastAllOfMatcher<Decl, CXXMethodDecl> cxxMethodDecl; /// Matches conversion operator declarations. /// /// Example matches the operator. /// \code /// class X { operator int() const; }; /// \endcode extern const internal::VariadicDynCastAllOfMatcher<Decl, CXXConversionDecl> cxxConversionDecl; /// Matches user-defined and implicitly generated deduction guide. /// /// Example matches the deduction guide. /// \code /// template<typename T> /// class X { X(int) }; /// X(int) -> X<int>; /// \endcode extern const internal::VariadicDynCastAllOfMatcher<Decl, CXXDeductionGuideDecl> cxxDeductionGuideDecl; /// Matches variable declarations. /// /// Note: this does not match declarations of member variables, which are /// "field" declarations in Clang parlance. /// /// Example matches a /// \code /// int a; /// \endcode extern const internal::VariadicDynCastAllOfMatcher<Decl, VarDecl> varDecl; /// Matches field declarations. /// /// Given /// \code /// class X { int m; }; /// \endcode /// fieldDecl() /// matches 'm'. extern const internal::VariadicDynCastAllOfMatcher<Decl, FieldDecl> fieldDecl; /// Matches indirect field declarations. /// /// Given /// \code /// struct X { struct { int a; }; }; /// \endcode /// indirectFieldDecl() /// matches 'a'. extern const internal::VariadicDynCastAllOfMatcher<Decl, IndirectFieldDecl> indirectFieldDecl; /// Matches function declarations. /// /// Example matches f /// \code /// void f(); /// \endcode extern const internal::VariadicDynCastAllOfMatcher<Decl, FunctionDecl> functionDecl; /// Matches C++ function template declarations. /// /// Example matches f /// \code /// template<class T> void f(T t) {} /// \endcode extern const internal::VariadicDynCastAllOfMatcher<Decl, FunctionTemplateDecl> functionTemplateDecl; /// Matches friend declarations. /// /// Given /// \code /// class X { friend void foo(); }; /// \endcode /// friendDecl() /// matches 'friend void foo()'. extern const internal::VariadicDynCastAllOfMatcher<Decl, FriendDecl> friendDecl; /// Matches statements. /// /// Given /// \code /// { ++a; } /// \endcode /// stmt() /// matches both the compound statement '{ ++a; }' and '++a'. extern const internal::VariadicAllOfMatcher<Stmt> stmt; /// Matches declaration statements. /// /// Given /// \code /// int a; /// \endcode /// declStmt() /// matches 'int a'. extern const internal::VariadicDynCastAllOfMatcher<Stmt, DeclStmt> declStmt; /// Matches member expressions. /// /// Given /// \code /// class Y { /// void x() { this->x(); x(); Y y; y.x(); a; this->b; Y::b; } /// int a; static int b; /// }; /// \endcode /// memberExpr() /// matches this->x, x, y.x, a, this->b extern const internal::VariadicDynCastAllOfMatcher<Stmt, MemberExpr> memberExpr; /// Matches unresolved member expressions. /// /// Given /// \code /// struct X { /// template <class T> void f(); /// void g(); /// }; /// template <class T> void h() { X x; x.f<T>(); x.g(); } /// \endcode /// unresolvedMemberExpr() /// matches x.f<T> extern const internal::VariadicDynCastAllOfMatcher<Stmt, UnresolvedMemberExpr> unresolvedMemberExpr; /// Matches member expressions where the actual member referenced could not be /// resolved because the base expression or the member name was dependent. /// /// Given /// \code /// template <class T> void f() { T t; t.g(); } /// \endcode /// cxxDependentScopeMemberExpr() /// matches t.g extern const internal::VariadicDynCastAllOfMatcher<Stmt, CXXDependentScopeMemberExpr> cxxDependentScopeMemberExpr; /// Matches call expressions. /// /// Example matches x.y() and y() /// \code /// X x; /// x.y(); /// y(); /// \endcode extern const internal::VariadicDynCastAllOfMatcher<Stmt, CallExpr> callExpr; /// Matches call expressions which were resolved using ADL. /// /// Example matches y(x) but not y(42) or NS::y(x). /// \code /// namespace NS { /// struct X {}; /// void y(X); /// } /// /// void y(...); /// /// void test() { /// NS::X x; /// y(x); // Matches /// NS::y(x); // Doesn't match /// y(42); // Doesn't match /// using NS::y; /// y(x); // Found by both unqualified lookup and ADL, doesn't match // } /// \endcode AST_MATCHER(CallExpr, usesADL) { return Node.usesADL(); } /// Matches lambda expressions. /// /// Example matches [&](){return 5;} /// \code /// [&](){return 5;} /// \endcode extern const internal::VariadicDynCastAllOfMatcher<Stmt, LambdaExpr> lambdaExpr; /// Matches member call expressions. /// /// Example matches x.y() /// \code /// X x; /// x.y(); /// \endcode extern const internal::VariadicDynCastAllOfMatcher<Stmt, CXXMemberCallExpr> cxxMemberCallExpr; /// Matches ObjectiveC Message invocation expressions. /// /// The innermost message send invokes the "alloc" class method on the /// NSString class, while the outermost message send invokes the /// "initWithString" instance method on the object returned from /// NSString's "alloc". This matcher should match both message sends. /// \code /// [[NSString alloc] initWithString:@"Hello"] /// \endcode extern const internal::VariadicDynCastAllOfMatcher<Stmt, ObjCMessageExpr> objcMessageExpr; /// Matches Objective-C interface declarations. /// /// Example matches Foo /// \code /// @interface Foo /// @end /// \endcode extern const internal::VariadicDynCastAllOfMatcher<Decl, ObjCInterfaceDecl> objcInterfaceDecl; /// Matches Objective-C implementation declarations. /// /// Example matches Foo /// \code /// @implementation Foo /// @end /// \endcode extern const internal::VariadicDynCastAllOfMatcher<Decl, ObjCImplementationDecl> objcImplementationDecl; /// Matches Objective-C protocol declarations. /// /// Example matches FooDelegate /// \code /// @protocol FooDelegate /// @end /// \endcode extern const internal::VariadicDynCastAllOfMatcher<Decl, ObjCProtocolDecl> objcProtocolDecl; /// Matches Objective-C category declarations. /// /// Example matches Foo (Additions) /// \code /// @interface Foo (Additions) /// @end /// \endcode extern const internal::VariadicDynCastAllOfMatcher<Decl, ObjCCategoryDecl> objcCategoryDecl; /// Matches Objective-C category definitions. /// /// Example matches Foo (Additions) /// \code /// @implementation Foo (Additions) /// @end /// \endcode extern const internal::VariadicDynCastAllOfMatcher<Decl, ObjCCategoryImplDecl> objcCategoryImplDecl; /// Matches Objective-C method declarations. /// /// Example matches both declaration and definition of -[Foo method] /// \code /// @interface Foo /// - (void)method; /// @end /// /// @implementation Foo /// - (void)method {} /// @end /// \endcode extern const internal::VariadicDynCastAllOfMatcher<Decl, ObjCMethodDecl> objcMethodDecl; /// Matches block declarations. /// /// Example matches the declaration of the nameless block printing an input /// integer. /// /// \code /// myFunc(^(int p) { /// printf("%d", p); /// }) /// \endcode extern const internal::VariadicDynCastAllOfMatcher<Decl, BlockDecl> blockDecl; /// Matches Objective-C instance variable declarations. /// /// Example matches _enabled /// \code /// @implementation Foo { /// BOOL _enabled; /// } /// @end /// \endcode extern const internal::VariadicDynCastAllOfMatcher<Decl, ObjCIvarDecl> objcIvarDecl; /// Matches Objective-C property declarations. /// /// Example matches enabled /// \code /// @interface Foo /// @property BOOL enabled; /// @end /// \endcode extern const internal::VariadicDynCastAllOfMatcher<Decl, ObjCPropertyDecl> objcPropertyDecl; /// Matches Objective-C \@throw statements. /// /// Example matches \@throw /// \code /// @throw obj; /// \endcode extern const internal::VariadicDynCastAllOfMatcher<Stmt, ObjCAtThrowStmt> objcThrowStmt; /// Matches Objective-C @try statements. /// /// Example matches @try /// \code /// @try {} /// @catch (...) {} /// \endcode extern const internal::VariadicDynCastAllOfMatcher<Stmt, ObjCAtTryStmt> objcTryStmt; /// Matches Objective-C @catch statements. /// /// Example matches @catch /// \code /// @try {} /// @catch (...) {} /// \endcode extern const internal::VariadicDynCastAllOfMatcher<Stmt, ObjCAtCatchStmt> objcCatchStmt; /// Matches Objective-C @finally statements. /// /// Example matches @finally /// \code /// @try {} /// @finally {} /// \endcode extern const internal::VariadicDynCastAllOfMatcher<Stmt, ObjCAtFinallyStmt> objcFinallyStmt; /// Matches expressions that introduce cleanups to be run at the end /// of the sub-expression's evaluation. /// /// Example matches std::string() /// \code /// const std::string str = std::string(); /// \endcode extern const internal::VariadicDynCastAllOfMatcher<Stmt, ExprWithCleanups> exprWithCleanups; /// Matches init list expressions. /// /// Given /// \code /// int a[] = { 1, 2 }; /// struct B { int x, y; }; /// B b = { 5, 6 }; /// \endcode /// initListExpr() /// matches "{ 1, 2 }" and "{ 5, 6 }" extern const internal::VariadicDynCastAllOfMatcher<Stmt, InitListExpr> initListExpr; /// Matches the syntactic form of init list expressions /// (if expression have it). AST_MATCHER_P(InitListExpr, hasSyntacticForm, internal::Matcher<Expr>, InnerMatcher) { const Expr *SyntForm = Node.getSyntacticForm(); return (SyntForm != nullptr && InnerMatcher.matches(*SyntForm, Finder, Builder)); } /// Matches C++ initializer list expressions. /// /// Given /// \code /// std::vector<int> a({ 1, 2, 3 }); /// std::vector<int> b = { 4, 5 }; /// int c[] = { 6, 7 }; /// std::pair<int, int> d = { 8, 9 }; /// \endcode /// cxxStdInitializerListExpr() /// matches "{ 1, 2, 3 }" and "{ 4, 5 }" extern const internal::VariadicDynCastAllOfMatcher<Stmt, CXXStdInitializerListExpr> cxxStdInitializerListExpr; /// Matches implicit initializers of init list expressions. /// /// Given /// \code /// point ptarray[10] = { [2].y = 1.0, [2].x = 2.0, [0].x = 1.0 }; /// \endcode /// implicitValueInitExpr() /// matches "[0].y" (implicitly) extern const internal::VariadicDynCastAllOfMatcher<Stmt, ImplicitValueInitExpr> implicitValueInitExpr; /// Matches paren list expressions. /// ParenListExprs don't have a predefined type and are used for late parsing. /// In the final AST, they can be met in template declarations. /// /// Given /// \code /// template<typename T> class X { /// void f() { /// X x(*this); /// int a = 0, b = 1; int i = (a, b); /// } /// }; /// \endcode /// parenListExpr() matches "*this" but NOT matches (a, b) because (a, b) /// has a predefined type and is a ParenExpr, not a ParenListExpr. extern const internal::VariadicDynCastAllOfMatcher<Stmt, ParenListExpr> parenListExpr; /// Matches substitutions of non-type template parameters. /// /// Given /// \code /// template <int N> /// struct A { static const int n = N; }; /// struct B : public A<42> {}; /// \endcode /// substNonTypeTemplateParmExpr() /// matches "N" in the right-hand side of "static const int n = N;" extern const internal::VariadicDynCastAllOfMatcher<Stmt, SubstNonTypeTemplateParmExpr> substNonTypeTemplateParmExpr; /// Matches using declarations. /// /// Given /// \code /// namespace X { int x; } /// using X::x; /// \endcode /// usingDecl() /// matches \code using X::x \endcode extern const internal::VariadicDynCastAllOfMatcher<Decl, UsingDecl> usingDecl; /// Matches using namespace declarations. /// /// Given /// \code /// namespace X { int x; } /// using namespace X; /// \endcode /// usingDirectiveDecl() /// matches \code using namespace X \endcode extern const internal::VariadicDynCastAllOfMatcher<Decl, UsingDirectiveDecl> usingDirectiveDecl; /// Matches reference to a name that can be looked up during parsing /// but could not be resolved to a specific declaration. /// /// Given /// \code /// template<typename T> /// T foo() { T a; return a; } /// template<typename T> /// void bar() { /// foo<T>(); /// } /// \endcode /// unresolvedLookupExpr() /// matches \code foo<T>() \endcode extern const internal::VariadicDynCastAllOfMatcher<Stmt, UnresolvedLookupExpr> unresolvedLookupExpr; /// Matches unresolved using value declarations. /// /// Given /// \code /// template<typename X> /// class C : private X { /// using X::x; /// }; /// \endcode /// unresolvedUsingValueDecl() /// matches \code using X::x \endcode extern const internal::VariadicDynCastAllOfMatcher<Decl, UnresolvedUsingValueDecl> unresolvedUsingValueDecl; /// Matches unresolved using value declarations that involve the /// typename. /// /// Given /// \code /// template <typename T> /// struct Base { typedef T Foo; }; /// /// template<typename T> /// struct S : private Base<T> { /// using typename Base<T>::Foo; /// }; /// \endcode /// unresolvedUsingTypenameDecl() /// matches \code using Base<T>::Foo \endcode extern const internal::VariadicDynCastAllOfMatcher<Decl, UnresolvedUsingTypenameDecl> unresolvedUsingTypenameDecl; /// Matches a constant expression wrapper. /// /// Example matches the constant in the case statement: /// (matcher = constantExpr()) /// \code /// switch (a) { /// case 37: break; /// } /// \endcode extern const internal::VariadicDynCastAllOfMatcher<Stmt, ConstantExpr> constantExpr; /// Matches parentheses used in expressions. /// /// Example matches (foo() + 1) /// \code /// int foo() { return 1; } /// int a = (foo() + 1); /// \endcode extern const internal::VariadicDynCastAllOfMatcher<Stmt, ParenExpr> parenExpr; /// Matches constructor call expressions (including implicit ones). /// /// Example matches string(ptr, n) and ptr within arguments of f /// (matcher = cxxConstructExpr()) /// \code /// void f(const string &a, const string &b); /// char *ptr; /// int n; /// f(string(ptr, n), ptr); /// \endcode extern const internal::VariadicDynCastAllOfMatcher<Stmt, CXXConstructExpr> cxxConstructExpr; /// Matches unresolved constructor call expressions. /// /// Example matches T(t) in return statement of f /// (matcher = cxxUnresolvedConstructExpr()) /// \code /// template <typename T> /// void f(const T& t) { return T(t); } /// \endcode extern const internal::VariadicDynCastAllOfMatcher<Stmt, CXXUnresolvedConstructExpr> cxxUnresolvedConstructExpr; /// Matches implicit and explicit this expressions. /// /// Example matches the implicit this expression in "return i". /// (matcher = cxxThisExpr()) /// \code /// struct foo { /// int i; /// int f() { return i; } /// }; /// \endcode extern const internal::VariadicDynCastAllOfMatcher<Stmt, CXXThisExpr> cxxThisExpr; /// Matches nodes where temporaries are created. /// /// Example matches FunctionTakesString(GetStringByValue()) /// (matcher = cxxBindTemporaryExpr()) /// \code /// FunctionTakesString(GetStringByValue()); /// FunctionTakesStringByPointer(GetStringPointer()); /// \endcode extern const internal::VariadicDynCastAllOfMatcher<Stmt, CXXBindTemporaryExpr> cxxBindTemporaryExpr; /// Matches nodes where temporaries are materialized. /// /// Example: Given /// \code /// struct T {void func();}; /// T f(); /// void g(T); /// \endcode /// materializeTemporaryExpr() matches 'f()' in these statements /// \code /// T u(f()); /// g(f()); /// f().func(); /// \endcode /// but does not match /// \code /// f(); /// \endcode extern const internal::VariadicDynCastAllOfMatcher<Stmt, MaterializeTemporaryExpr> materializeTemporaryExpr; /// Matches new expressions. /// /// Given /// \code /// new X; /// \endcode /// cxxNewExpr() /// matches 'new X'. extern const internal::VariadicDynCastAllOfMatcher<Stmt, CXXNewExpr> cxxNewExpr; /// Matches delete expressions. /// /// Given /// \code /// delete X; /// \endcode /// cxxDeleteExpr() /// matches 'delete X'. extern const internal::VariadicDynCastAllOfMatcher<Stmt, CXXDeleteExpr> cxxDeleteExpr; /// Matches array subscript expressions. /// /// Given /// \code /// int i = a[1]; /// \endcode /// arraySubscriptExpr() /// matches "a[1]" extern const internal::VariadicDynCastAllOfMatcher<Stmt, ArraySubscriptExpr> arraySubscriptExpr; /// Matches the value of a default argument at the call site. /// /// Example matches the CXXDefaultArgExpr placeholder inserted for the /// default value of the second parameter in the call expression f(42) /// (matcher = cxxDefaultArgExpr()) /// \code /// void f(int x, int y = 0); /// f(42); /// \endcode extern const internal::VariadicDynCastAllOfMatcher<Stmt, CXXDefaultArgExpr> cxxDefaultArgExpr; /// Matches overloaded operator calls. /// /// Note that if an operator isn't overloaded, it won't match. Instead, use /// binaryOperator matcher. /// Currently it does not match operators such as new delete. /// FIXME: figure out why these do not match? /// /// Example matches both operator<<((o << b), c) and operator<<(o, b) /// (matcher = cxxOperatorCallExpr()) /// \code /// ostream &operator<< (ostream &out, int i) { }; /// ostream &o; int b = 1, c = 1; /// o << b << c; /// \endcode extern const internal::VariadicDynCastAllOfMatcher<Stmt, CXXOperatorCallExpr> cxxOperatorCallExpr; /// Matches expressions. /// /// Example matches x() /// \code /// void f() { x(); } /// \endcode extern const internal::VariadicDynCastAllOfMatcher<Stmt, Expr> expr; /// Matches expressions that refer to declarations. /// /// Example matches x in if (x) /// \code /// bool x; /// if (x) {} /// \endcode extern const internal::VariadicDynCastAllOfMatcher<Stmt, DeclRefExpr> declRefExpr; /// Matches a reference to an ObjCIvar. /// /// Example: matches "a" in "init" method: /// \code /// @implementation A { /// NSString *a; /// } /// - (void) init { /// a = @"hello"; /// } /// \endcode extern const internal::VariadicDynCastAllOfMatcher<Stmt, ObjCIvarRefExpr> objcIvarRefExpr; /// Matches a reference to a block. /// /// Example: matches "^{}": /// \code /// void f() { ^{}(); } /// \endcode extern const internal::VariadicDynCastAllOfMatcher<Stmt, BlockExpr> blockExpr; /// Matches if statements. /// /// Example matches 'if (x) {}' /// \code /// if (x) {} /// \endcode extern const internal::VariadicDynCastAllOfMatcher<Stmt, IfStmt> ifStmt; /// Matches for statements. /// /// Example matches 'for (;;) {}' /// \code /// for (;;) {} /// int i[] = {1, 2, 3}; for (auto a : i); /// \endcode extern const internal::VariadicDynCastAllOfMatcher<Stmt, ForStmt> forStmt; /// Matches the increment statement of a for loop. /// /// Example: /// forStmt(hasIncrement(unaryOperator(hasOperatorName("++")))) /// matches '++x' in /// \code /// for (x; x < N; ++x) { } /// \endcode AST_MATCHER_P(ForStmt, hasIncrement, internal::Matcher<Stmt>, InnerMatcher) { const Stmt *const Increment = Node.getInc(); return (Increment != nullptr && InnerMatcher.matches(*Increment, Finder, Builder)); } /// Matches the initialization statement of a for loop. /// /// Example: /// forStmt(hasLoopInit(declStmt())) /// matches 'int x = 0' in /// \code /// for (int x = 0; x < N; ++x) { } /// \endcode AST_MATCHER_P(ForStmt, hasLoopInit, internal::Matcher<Stmt>, InnerMatcher) { const Stmt *const Init = Node.getInit(); return (Init != nullptr && InnerMatcher.matches(*Init, Finder, Builder)); } /// Matches range-based for statements. /// /// cxxForRangeStmt() matches 'for (auto a : i)' /// \code /// int i[] = {1, 2, 3}; for (auto a : i); /// for(int j = 0; j < 5; ++j); /// \endcode extern const internal::VariadicDynCastAllOfMatcher<Stmt, CXXForRangeStmt> cxxForRangeStmt; /// Matches the initialization statement of a for loop. /// /// Example: /// forStmt(hasLoopVariable(anything())) /// matches 'int x' in /// \code /// for (int x : a) { } /// \endcode AST_MATCHER_P(CXXForRangeStmt, hasLoopVariable, internal::Matcher<VarDecl>, InnerMatcher) { const VarDecl *const Var = Node.getLoopVariable(); return (Var != nullptr && InnerMatcher.matches(*Var, Finder, Builder)); } /// Matches the range initialization statement of a for loop. /// /// Example: /// forStmt(hasRangeInit(anything())) /// matches 'a' in /// \code /// for (int x : a) { } /// \endcode AST_MATCHER_P(CXXForRangeStmt, hasRangeInit, internal::Matcher<Expr>, InnerMatcher) { const Expr *const Init = Node.getRangeInit(); return (Init != nullptr && InnerMatcher.matches(*Init, Finder, Builder)); } /// Matches while statements. /// /// Given /// \code /// while (true) {} /// \endcode /// whileStmt() /// matches 'while (true) {}'. extern const internal::VariadicDynCastAllOfMatcher<Stmt, WhileStmt> whileStmt; /// Matches do statements. /// /// Given /// \code /// do {} while (true); /// \endcode /// doStmt() /// matches 'do {} while(true)' extern const internal::VariadicDynCastAllOfMatcher<Stmt, DoStmt> doStmt; /// Matches break statements. /// /// Given /// \code /// while (true) { break; } /// \endcode /// breakStmt() /// matches 'break' extern const internal::VariadicDynCastAllOfMatcher<Stmt, BreakStmt> breakStmt; /// Matches continue statements. /// /// Given /// \code /// while (true) { continue; } /// \endcode /// continueStmt() /// matches 'continue' extern const internal::VariadicDynCastAllOfMatcher<Stmt, ContinueStmt> continueStmt; /// Matches return statements. /// /// Given /// \code /// return 1; /// \endcode /// returnStmt() /// matches 'return 1' extern const internal::VariadicDynCastAllOfMatcher<Stmt, ReturnStmt> returnStmt; /// Matches goto statements. /// /// Given /// \code /// goto FOO; /// FOO: bar(); /// \endcode /// gotoStmt() /// matches 'goto FOO' extern const internal::VariadicDynCastAllOfMatcher<Stmt, GotoStmt> gotoStmt; /// Matches label statements. /// /// Given /// \code /// goto FOO; /// FOO: bar(); /// \endcode /// labelStmt() /// matches 'FOO:' extern const internal::VariadicDynCastAllOfMatcher<Stmt, LabelStmt> labelStmt; /// Matches address of label statements (GNU extension). /// /// Given /// \code /// FOO: bar(); /// void *ptr = &&FOO; /// goto *bar; /// \endcode /// addrLabelExpr() /// matches '&&FOO' extern const internal::VariadicDynCastAllOfMatcher<Stmt, AddrLabelExpr> addrLabelExpr; /// Matches switch statements. /// /// Given /// \code /// switch(a) { case 42: break; default: break; } /// \endcode /// switchStmt() /// matches 'switch(a)'. extern const internal::VariadicDynCastAllOfMatcher<Stmt, SwitchStmt> switchStmt; /// Matches case and default statements inside switch statements. /// /// Given /// \code /// switch(a) { case 42: break; default: break; } /// \endcode /// switchCase() /// matches 'case 42:' and 'default:'. extern const internal::VariadicDynCastAllOfMatcher<Stmt, SwitchCase> switchCase; /// Matches case statements inside switch statements. /// /// Given /// \code /// switch(a) { case 42: break; default: break; } /// \endcode /// caseStmt() /// matches 'case 42:'. extern const internal::VariadicDynCastAllOfMatcher<Stmt, CaseStmt> caseStmt; /// Matches default statements inside switch statements. /// /// Given /// \code /// switch(a) { case 42: break; default: break; } /// \endcode /// defaultStmt() /// matches 'default:'. extern const internal::VariadicDynCastAllOfMatcher<Stmt, DefaultStmt> defaultStmt; /// Matches compound statements. /// /// Example matches '{}' and '{{}}' in 'for (;;) {{}}' /// \code /// for (;;) {{}} /// \endcode extern const internal::VariadicDynCastAllOfMatcher<Stmt, CompoundStmt> compoundStmt; /// Matches catch statements. /// /// \code /// try {} catch(int i) {} /// \endcode /// cxxCatchStmt() /// matches 'catch(int i)' extern const internal::VariadicDynCastAllOfMatcher<Stmt, CXXCatchStmt> cxxCatchStmt; /// Matches try statements. /// /// \code /// try {} catch(int i) {} /// \endcode /// cxxTryStmt() /// matches 'try {}' extern const internal::VariadicDynCastAllOfMatcher<Stmt, CXXTryStmt> cxxTryStmt; /// Matches throw expressions. /// /// \code /// try { throw 5; } catch(int i) {} /// \endcode /// cxxThrowExpr() /// matches 'throw 5' extern const internal::VariadicDynCastAllOfMatcher<Stmt, CXXThrowExpr> cxxThrowExpr; /// Matches null statements. /// /// \code /// foo();; /// \endcode /// nullStmt() /// matches the second ';' extern const internal::VariadicDynCastAllOfMatcher<Stmt, NullStmt> nullStmt; /// Matches asm statements. /// /// \code /// int i = 100; /// __asm("mov al, 2"); /// \endcode /// asmStmt() /// matches '__asm("mov al, 2")' extern const internal::VariadicDynCastAllOfMatcher<Stmt, AsmStmt> asmStmt; /// Matches bool literals. /// /// Example matches true /// \code /// true /// \endcode extern const internal::VariadicDynCastAllOfMatcher<Stmt, CXXBoolLiteralExpr> cxxBoolLiteral; /// Matches string literals (also matches wide string literals). /// /// Example matches "abcd", L"abcd" /// \code /// char *s = "abcd"; /// wchar_t *ws = L"abcd"; /// \endcode extern const internal::VariadicDynCastAllOfMatcher<Stmt, StringLiteral> stringLiteral; /// Matches character literals (also matches wchar_t). /// /// Not matching Hex-encoded chars (e.g. 0x1234, which is a IntegerLiteral), /// though. /// /// Example matches 'a', L'a' /// \code /// char ch = 'a'; /// wchar_t chw = L'a'; /// \endcode extern const internal::VariadicDynCastAllOfMatcher<Stmt, CharacterLiteral> characterLiteral; /// Matches integer literals of all sizes / encodings, e.g. /// 1, 1L, 0x1 and 1U. /// /// Does not match character-encoded integers such as L'a'. extern const internal::VariadicDynCastAllOfMatcher<Stmt, IntegerLiteral> integerLiteral; /// Matches float literals of all sizes / encodings, e.g. /// 1.0, 1.0f, 1.0L and 1e10. /// /// Does not match implicit conversions such as /// \code /// float a = 10; /// \endcode extern const internal::VariadicDynCastAllOfMatcher<Stmt, FloatingLiteral> floatLiteral; /// Matches imaginary literals, which are based on integer and floating /// point literals e.g.: 1i, 1.0i extern const internal::VariadicDynCastAllOfMatcher<Stmt, ImaginaryLiteral> imaginaryLiteral; /// Matches user defined literal operator call. /// /// Example match: "foo"_suffix extern const internal::VariadicDynCastAllOfMatcher<Stmt, UserDefinedLiteral> userDefinedLiteral; /// Matches compound (i.e. non-scalar) literals /// /// Example match: {1}, (1, 2) /// \code /// int array[4] = {1}; /// vector int myvec = (vector int)(1, 2); /// \endcode extern const internal::VariadicDynCastAllOfMatcher<Stmt, CompoundLiteralExpr> compoundLiteralExpr; /// Matches nullptr literal. extern const internal::VariadicDynCastAllOfMatcher<Stmt, CXXNullPtrLiteralExpr> cxxNullPtrLiteralExpr; /// Matches GNU __builtin_choose_expr. extern const internal::VariadicDynCastAllOfMatcher<Stmt, ChooseExpr> chooseExpr; /// Matches GNU __null expression. extern const internal::VariadicDynCastAllOfMatcher<Stmt, GNUNullExpr> gnuNullExpr; /// Matches atomic builtins. /// Example matches __atomic_load_n(ptr, 1) /// \code /// void foo() { int *ptr; __atomic_load_n(ptr, 1); } /// \endcode extern const internal::VariadicDynCastAllOfMatcher<Stmt, AtomicExpr> atomicExpr; /// Matches statement expression (GNU extension). /// /// Example match: ({ int X = 4; X; }) /// \code /// int C = ({ int X = 4; X; }); /// \endcode extern const internal::VariadicDynCastAllOfMatcher<Stmt, StmtExpr> stmtExpr; /// Matches binary operator expressions. /// /// Example matches a || b /// \code /// !(a || b) /// \endcode extern const internal::VariadicDynCastAllOfMatcher<Stmt, BinaryOperator> binaryOperator; /// Matches unary operator expressions. /// /// Example matches !a /// \code /// !a || b /// \endcode extern const internal::VariadicDynCastAllOfMatcher<Stmt, UnaryOperator> unaryOperator; /// Matches conditional operator expressions. /// /// Example matches a ? b : c /// \code /// (a ? b : c) + 42 /// \endcode extern const internal::VariadicDynCastAllOfMatcher<Stmt, ConditionalOperator> conditionalOperator; /// Matches binary conditional operator expressions (GNU extension). /// /// Example matches a ?: b /// \code /// (a ?: b) + 42; /// \endcode extern const internal::VariadicDynCastAllOfMatcher<Stmt, BinaryConditionalOperator> binaryConditionalOperator; /// Matches opaque value expressions. They are used as helpers /// to reference another expressions and can be met /// in BinaryConditionalOperators, for example. /// /// Example matches 'a' /// \code /// (a ?: c) + 42; /// \endcode extern const internal::VariadicDynCastAllOfMatcher<Stmt, OpaqueValueExpr> opaqueValueExpr; /// Matches a C++ static_assert declaration. /// /// Example: /// staticAssertExpr() /// matches /// static_assert(sizeof(S) == sizeof(int)) /// in /// \code /// struct S { /// int x; /// }; /// static_assert(sizeof(S) == sizeof(int)); /// \endcode extern const internal::VariadicDynCastAllOfMatcher<Decl, StaticAssertDecl> staticAssertDecl; /// Matches a reinterpret_cast expression. /// /// Either the source expression or the destination type can be matched /// using has(), but hasDestinationType() is more specific and can be /// more readable. /// /// Example matches reinterpret_cast<char*>(&p) in /// \code /// void* p = reinterpret_cast<char*>(&p); /// \endcode extern const internal::VariadicDynCastAllOfMatcher<Stmt, CXXReinterpretCastExpr> cxxReinterpretCastExpr; /// Matches a C++ static_cast expression. /// /// \see hasDestinationType /// \see reinterpretCast /// /// Example: /// cxxStaticCastExpr() /// matches /// static_cast<long>(8) /// in /// \code /// long eight(static_cast<long>(8)); /// \endcode extern const internal::VariadicDynCastAllOfMatcher<Stmt, CXXStaticCastExpr> cxxStaticCastExpr; /// Matches a dynamic_cast expression. /// /// Example: /// cxxDynamicCastExpr() /// matches /// dynamic_cast<D*>(&b); /// in /// \code /// struct B { virtual ~B() {} }; struct D : B {}; /// B b; /// D* p = dynamic_cast<D*>(&b); /// \endcode extern const internal::VariadicDynCastAllOfMatcher<Stmt, CXXDynamicCastExpr> cxxDynamicCastExpr; /// Matches a const_cast expression. /// /// Example: Matches const_cast<int*>(&r) in /// \code /// int n = 42; /// const int &r(n); /// int* p = const_cast<int*>(&r); /// \endcode extern const internal::VariadicDynCastAllOfMatcher<Stmt, CXXConstCastExpr> cxxConstCastExpr; /// Matches a C-style cast expression. /// /// Example: Matches (int) 2.2f in /// \code /// int i = (int) 2.2f; /// \endcode extern const internal::VariadicDynCastAllOfMatcher<Stmt, CStyleCastExpr> cStyleCastExpr; /// Matches explicit cast expressions. /// /// Matches any cast expression written in user code, whether it be a /// C-style cast, a functional-style cast, or a keyword cast. /// /// Does not match implicit conversions. /// /// Note: the name "explicitCast" is chosen to match Clang's terminology, as /// Clang uses the term "cast" to apply to implicit conversions as well as to /// actual cast expressions. /// /// \see hasDestinationType. /// /// Example: matches all five of the casts in /// \code /// int((int)(reinterpret_cast<int>(static_cast<int>(const_cast<int>(42))))) /// \endcode /// but does not match the implicit conversion in /// \code /// long ell = 42; /// \endcode extern const internal::VariadicDynCastAllOfMatcher<Stmt, ExplicitCastExpr> explicitCastExpr; /// Matches the implicit cast nodes of Clang's AST. /// /// This matches many different places, including function call return value /// eliding, as well as any type conversions. extern const internal::VariadicDynCastAllOfMatcher<Stmt, ImplicitCastExpr> implicitCastExpr; /// Matches any cast nodes of Clang's AST. /// /// Example: castExpr() matches each of the following: /// \code /// (int) 3; /// const_cast<Expr *>(SubExpr); /// char c = 0; /// \endcode /// but does not match /// \code /// int i = (0); /// int k = 0; /// \endcode extern const internal::VariadicDynCastAllOfMatcher<Stmt, CastExpr> castExpr; /// Matches functional cast expressions /// /// Example: Matches Foo(bar); /// \code /// Foo f = bar; /// Foo g = (Foo) bar; /// Foo h = Foo(bar); /// \endcode extern const internal::VariadicDynCastAllOfMatcher<Stmt, CXXFunctionalCastExpr> cxxFunctionalCastExpr; /// Matches functional cast expressions having N != 1 arguments /// /// Example: Matches Foo(bar, bar) /// \code /// Foo h = Foo(bar, bar); /// \endcode extern const internal::VariadicDynCastAllOfMatcher<Stmt, CXXTemporaryObjectExpr> cxxTemporaryObjectExpr; /// Matches predefined identifier expressions [C99 6.4.2.2]. /// /// Example: Matches __func__ /// \code /// printf("%s", __func__); /// \endcode extern const internal::VariadicDynCastAllOfMatcher<Stmt, PredefinedExpr> predefinedExpr; /// Matches C99 designated initializer expressions [C99 6.7.8]. /// /// Example: Matches { [2].y = 1.0, [0].x = 1.0 } /// \code /// point ptarray[10] = { [2].y = 1.0, [0].x = 1.0 }; /// \endcode extern const internal::VariadicDynCastAllOfMatcher<Stmt, DesignatedInitExpr> designatedInitExpr; /// Matches designated initializer expressions that contain /// a specific number of designators. /// /// Example: Given /// \code /// point ptarray[10] = { [2].y = 1.0, [0].x = 1.0 }; /// point ptarray2[10] = { [2].y = 1.0, [2].x = 0.0, [0].x = 1.0 }; /// \endcode /// designatorCountIs(2) /// matches '{ [2].y = 1.0, [0].x = 1.0 }', /// but not '{ [2].y = 1.0, [2].x = 0.0, [0].x = 1.0 }'. AST_MATCHER_P(DesignatedInitExpr, designatorCountIs, unsigned, N) { return Node.size() == N; } /// Matches \c QualTypes in the clang AST. extern const internal::VariadicAllOfMatcher<QualType> qualType; /// Matches \c Types in the clang AST. extern const internal::VariadicAllOfMatcher<Type> type; /// Matches \c TypeLocs in the clang AST. extern const internal::VariadicAllOfMatcher<TypeLoc> typeLoc; /// Matches if any of the given matchers matches. /// /// Unlike \c anyOf, \c eachOf will generate a match result for each /// matching submatcher. /// /// For example, in: /// \code /// class A { int a; int b; }; /// \endcode /// The matcher: /// \code /// cxxRecordDecl(eachOf(has(fieldDecl(hasName("a")).bind("v")), /// has(fieldDecl(hasName("b")).bind("v")))) /// \endcode /// will generate two results binding "v", the first of which binds /// the field declaration of \c a, the second the field declaration of /// \c b. /// /// Usable as: Any Matcher extern const internal::VariadicOperatorMatcherFunc< 2, std::numeric_limits<unsigned>::max()> eachOf; /// Matches if any of the given matchers matches. /// /// Usable as: Any Matcher extern const internal::VariadicOperatorMatcherFunc< 2, std::numeric_limits<unsigned>::max()> anyOf; /// Matches if all given matchers match. /// /// Usable as: Any Matcher extern const internal::VariadicOperatorMatcherFunc< 2, std::numeric_limits<unsigned>::max()> allOf; /// Matches sizeof (C99), alignof (C++11) and vec_step (OpenCL) /// /// Given /// \code /// Foo x = bar; /// int y = sizeof(x) + alignof(x); /// \endcode /// unaryExprOrTypeTraitExpr() /// matches \c sizeof(x) and \c alignof(x) extern const internal::VariadicDynCastAllOfMatcher<Stmt, UnaryExprOrTypeTraitExpr> unaryExprOrTypeTraitExpr; /// Matches unary expressions that have a specific type of argument. /// /// Given /// \code /// int a, c; float b; int s = sizeof(a) + sizeof(b) + alignof(c); /// \endcode /// unaryExprOrTypeTraitExpr(hasArgumentOfType(asString("int")) /// matches \c sizeof(a) and \c alignof(c) AST_MATCHER_P(UnaryExprOrTypeTraitExpr, hasArgumentOfType, internal::Matcher<QualType>, InnerMatcher) { const QualType ArgumentType = Node.getTypeOfArgument(); return InnerMatcher.matches(ArgumentType, Finder, Builder); } /// Matches unary expressions of a certain kind. /// /// Given /// \code /// int x; /// int s = sizeof(x) + alignof(x) /// \endcode /// unaryExprOrTypeTraitExpr(ofKind(UETT_SizeOf)) /// matches \c sizeof(x) /// /// If the matcher is use from clang-query, UnaryExprOrTypeTrait parameter /// should be passed as a quoted string. e.g., ofKind("UETT_SizeOf"). AST_MATCHER_P(UnaryExprOrTypeTraitExpr, ofKind, UnaryExprOrTypeTrait, Kind) { return Node.getKind() == Kind; } /// Same as unaryExprOrTypeTraitExpr, but only matching /// alignof. inline internal::Matcher<Stmt> alignOfExpr( const internal::Matcher<UnaryExprOrTypeTraitExpr> &InnerMatcher) { return stmt(unaryExprOrTypeTraitExpr( allOf(anyOf(ofKind(UETT_AlignOf), ofKind(UETT_PreferredAlignOf)), InnerMatcher))); } /// Same as unaryExprOrTypeTraitExpr, but only matching /// sizeof. inline internal::Matcher<Stmt> sizeOfExpr( const internal::Matcher<UnaryExprOrTypeTraitExpr> &InnerMatcher) { return stmt(unaryExprOrTypeTraitExpr( allOf(ofKind(UETT_SizeOf), InnerMatcher))); } /// Matches NamedDecl nodes that have the specified name. /// /// Supports specifying enclosing namespaces or classes by prefixing the name /// with '<enclosing>::'. /// Does not match typedefs of an underlying type with the given name. /// /// Example matches X (Name == "X") /// \code /// class X; /// \endcode /// /// Example matches X (Name is one of "::a::b::X", "a::b::X", "b::X", "X") /// \code /// namespace a { namespace b { class X; } } /// \endcode inline internal::Matcher<NamedDecl> hasName(const std::string &Name) { return internal::Matcher<NamedDecl>(new internal::HasNameMatcher({Name})); } /// Matches NamedDecl nodes that have any of the specified names. /// /// This matcher is only provided as a performance optimization of hasName. /// \code /// hasAnyName(a, b, c) /// \endcode /// is equivalent to, but faster than /// \code /// anyOf(hasName(a), hasName(b), hasName(c)) /// \endcode extern const internal::VariadicFunction<internal::Matcher<NamedDecl>, StringRef, internal::hasAnyNameFunc> hasAnyName; /// Matches NamedDecl nodes whose fully qualified names contain /// a substring matched by the given RegExp. /// /// Supports specifying enclosing namespaces or classes by /// prefixing the name with '<enclosing>::'. Does not match typedefs /// of an underlying type with the given name. /// /// Example matches X (regexp == "::X") /// \code /// class X; /// \endcode /// /// Example matches X (regexp is one of "::X", "^foo::.*X", among others) /// \code /// namespace foo { namespace bar { class X; } } /// \endcode AST_MATCHER_P(NamedDecl, matchesName, std::string, RegExp) { assert(!RegExp.empty()); std::string FullNameString = "::" + Node.getQualifiedNameAsString(); llvm::Regex RE(RegExp); return RE.match(FullNameString); } /// Matches overloaded operator names. /// /// Matches overloaded operator names specified in strings without the /// "operator" prefix: e.g. "<<". /// /// Given: /// \code /// class A { int operator*(); }; /// const A &operator<<(const A &a, const A &b); /// A a; /// a << a; // <-- This matches /// \endcode /// /// \c cxxOperatorCallExpr(hasOverloadedOperatorName("<<"))) matches the /// specified line and /// \c cxxRecordDecl(hasMethod(hasOverloadedOperatorName("*"))) /// matches the declaration of \c A. /// /// Usable as: Matcher<CXXOperatorCallExpr>, Matcher<FunctionDecl> inline internal::PolymorphicMatcherWithParam1< internal::HasOverloadedOperatorNameMatcher, StringRef, AST_POLYMORPHIC_SUPPORTED_TYPES(CXXOperatorCallExpr, FunctionDecl)> hasOverloadedOperatorName(StringRef Name) { return internal::PolymorphicMatcherWithParam1< internal::HasOverloadedOperatorNameMatcher, StringRef, AST_POLYMORPHIC_SUPPORTED_TYPES(CXXOperatorCallExpr, FunctionDecl)>(Name); } /// Matches C++ classes that are directly or indirectly derived from /// a class matching \c Base. /// /// Note that a class is not considered to be derived from itself. /// /// Example matches Y, Z, C (Base == hasName("X")) /// \code /// class X; /// class Y : public X {}; // directly derived /// class Z : public Y {}; // indirectly derived /// typedef X A; /// typedef A B; /// class C : public B {}; // derived from a typedef of X /// \endcode /// /// In the following example, Bar matches isDerivedFrom(hasName("X")): /// \code /// class Foo; /// typedef Foo X; /// class Bar : public Foo {}; // derived from a type that X is a typedef of /// \endcode AST_MATCHER_P(CXXRecordDecl, isDerivedFrom, internal::Matcher<NamedDecl>, Base) { return Finder->classIsDerivedFrom(&Node, Base, Builder, /*Directly=*/false); } /// Overloaded method as shortcut for \c isDerivedFrom(hasName(...)). AST_MATCHER_P_OVERLOAD(CXXRecordDecl, isDerivedFrom, std::string, BaseName, 1) { if (BaseName.empty()) return false; return isDerivedFrom(hasName(BaseName)).matches(Node, Finder, Builder); } /// Similar to \c isDerivedFrom(), but also matches classes that directly /// match \c Base. AST_MATCHER_P_OVERLOAD(CXXRecordDecl, isSameOrDerivedFrom, internal::Matcher<NamedDecl>, Base, 0) { return Matcher<CXXRecordDecl>(anyOf(Base, isDerivedFrom(Base))) .matches(Node, Finder, Builder); } /// Overloaded method as shortcut for /// \c isSameOrDerivedFrom(hasName(...)). AST_MATCHER_P_OVERLOAD(CXXRecordDecl, isSameOrDerivedFrom, std::string, BaseName, 1) { if (BaseName.empty()) return false; return isSameOrDerivedFrom(hasName(BaseName)).matches(Node, Finder, Builder); } /// Matches C++ classes that are directly derived from a class matching \c Base. /// /// Note that a class is not considered to be derived from itself. /// /// Example matches Y, C (Base == hasName("X")) /// \code /// class X; /// class Y : public X {}; // directly derived /// class Z : public Y {}; // indirectly derived /// typedef X A; /// typedef A B; /// class C : public B {}; // derived from a typedef of X /// \endcode /// /// In the following example, Bar matches isDerivedFrom(hasName("X")): /// \code /// class Foo; /// typedef Foo X; /// class Bar : public Foo {}; // derived from a type that X is a typedef of /// \endcode AST_MATCHER_P_OVERLOAD(CXXRecordDecl, isDirectlyDerivedFrom, internal::Matcher<NamedDecl>, Base, 0) { return Finder->classIsDerivedFrom(&Node, Base, Builder, /*Directly=*/true); } /// Overloaded method as shortcut for \c isDirectlyDerivedFrom(hasName(...)). AST_MATCHER_P_OVERLOAD(CXXRecordDecl, isDirectlyDerivedFrom, std::string, BaseName, 1) { if (BaseName.empty()) return false; return isDirectlyDerivedFrom(hasName(BaseName)) .matches(Node, Finder, Builder); } /// Matches the first method of a class or struct that satisfies \c /// InnerMatcher. /// /// Given: /// \code /// class A { void func(); }; /// class B { void member(); }; /// \endcode /// /// \c cxxRecordDecl(hasMethod(hasName("func"))) matches the declaration of /// \c A but not \c B. AST_MATCHER_P(CXXRecordDecl, hasMethod, internal::Matcher<CXXMethodDecl>, InnerMatcher) { return matchesFirstInPointerRange(InnerMatcher, Node.method_begin(), Node.method_end(), Finder, Builder); } /// Matches the generated class of lambda expressions. /// /// Given: /// \code /// auto x = []{}; /// \endcode /// /// \c cxxRecordDecl(isLambda()) matches the implicit class declaration of /// \c decltype(x) AST_MATCHER(CXXRecordDecl, isLambda) { return Node.isLambda(); } /// Matches AST nodes that have child AST nodes that match the /// provided matcher. /// /// Example matches X, Y /// (matcher = cxxRecordDecl(has(cxxRecordDecl(hasName("X"))) /// \code /// class X {}; // Matches X, because X::X is a class of name X inside X. /// class Y { class X {}; }; /// class Z { class Y { class X {}; }; }; // Does not match Z. /// \endcode /// /// ChildT must be an AST base type. /// /// Usable as: Any Matcher /// Note that has is direct matcher, so it also matches things like implicit /// casts and paren casts. If you are matching with expr then you should /// probably consider using ignoringParenImpCasts like: /// has(ignoringParenImpCasts(expr())). extern const internal::ArgumentAdaptingMatcherFunc<internal::HasMatcher> has; /// Matches AST nodes that have descendant AST nodes that match the /// provided matcher. /// /// Example matches X, Y, Z /// (matcher = cxxRecordDecl(hasDescendant(cxxRecordDecl(hasName("X"))))) /// \code /// class X {}; // Matches X, because X::X is a class of name X inside X. /// class Y { class X {}; }; /// class Z { class Y { class X {}; }; }; /// \endcode /// /// DescendantT must be an AST base type. /// /// Usable as: Any Matcher extern const internal::ArgumentAdaptingMatcherFunc< internal::HasDescendantMatcher> hasDescendant; /// Matches AST nodes that have child AST nodes that match the /// provided matcher. /// /// Example matches X, Y, Y::X, Z::Y, Z::Y::X /// (matcher = cxxRecordDecl(forEach(cxxRecordDecl(hasName("X"))) /// \code /// class X {}; /// class Y { class X {}; }; // Matches Y, because Y::X is a class of name X /// // inside Y. /// class Z { class Y { class X {}; }; }; // Does not match Z. /// \endcode /// /// ChildT must be an AST base type. /// /// As opposed to 'has', 'forEach' will cause a match for each result that /// matches instead of only on the first one. /// /// Usable as: Any Matcher extern const internal::ArgumentAdaptingMatcherFunc<internal::ForEachMatcher> forEach; /// Matches AST nodes that have descendant AST nodes that match the /// provided matcher. /// /// Example matches X, A, A::X, B, B::C, B::C::X /// (matcher = cxxRecordDecl(forEachDescendant(cxxRecordDecl(hasName("X"))))) /// \code /// class X {}; /// class A { class X {}; }; // Matches A, because A::X is a class of name /// // X inside A. /// class B { class C { class X {}; }; }; /// \endcode /// /// DescendantT must be an AST base type. /// /// As opposed to 'hasDescendant', 'forEachDescendant' will cause a match for /// each result that matches instead of only on the first one. /// /// Note: Recursively combined ForEachDescendant can cause many matches: /// cxxRecordDecl(forEachDescendant(cxxRecordDecl( /// forEachDescendant(cxxRecordDecl()) /// ))) /// will match 10 times (plus injected class name matches) on: /// \code /// class A { class B { class C { class D { class E {}; }; }; }; }; /// \endcode /// /// Usable as: Any Matcher extern const internal::ArgumentAdaptingMatcherFunc< internal::ForEachDescendantMatcher> forEachDescendant; /// Matches if the node or any descendant matches. /// /// Generates results for each match. /// /// For example, in: /// \code /// class A { class B {}; class C {}; }; /// \endcode /// The matcher: /// \code /// cxxRecordDecl(hasName("::A"), /// findAll(cxxRecordDecl(isDefinition()).bind("m"))) /// \endcode /// will generate results for \c A, \c B and \c C. /// /// Usable as: Any Matcher template <typename T> internal::Matcher<T> findAll(const internal::Matcher<T> &Matcher) { return eachOf(Matcher, forEachDescendant(Matcher)); } /// Matches AST nodes that have a parent that matches the provided /// matcher. /// /// Given /// \code /// void f() { for (;;) { int x = 42; if (true) { int x = 43; } } } /// \endcode /// \c compoundStmt(hasParent(ifStmt())) matches "{ int x = 43; }". /// /// Usable as: Any Matcher extern const internal::ArgumentAdaptingMatcherFunc< internal::HasParentMatcher, internal::TypeList<Decl, NestedNameSpecifierLoc, Stmt, TypeLoc>, internal::TypeList<Decl, NestedNameSpecifierLoc, Stmt, TypeLoc>> hasParent; /// Matches AST nodes that have an ancestor that matches the provided /// matcher. /// /// Given /// \code /// void f() { if (true) { int x = 42; } } /// void g() { for (;;) { int x = 43; } } /// \endcode /// \c expr(integerLiteral(hasAncestor(ifStmt()))) matches \c 42, but not 43. /// /// Usable as: Any Matcher extern const internal::ArgumentAdaptingMatcherFunc< internal::HasAncestorMatcher, internal::TypeList<Decl, NestedNameSpecifierLoc, Stmt, TypeLoc>, internal::TypeList<Decl, NestedNameSpecifierLoc, Stmt, TypeLoc>> hasAncestor; /// Matches if the provided matcher does not match. /// /// Example matches Y (matcher = cxxRecordDecl(unless(hasName("X")))) /// \code /// class X {}; /// class Y {}; /// \endcode /// /// Usable as: Any Matcher extern const internal::VariadicOperatorMatcherFunc<1, 1> unless; /// Matches a node if the declaration associated with that node /// matches the given matcher. /// /// The associated declaration is: /// - for type nodes, the declaration of the underlying type /// - for CallExpr, the declaration of the callee /// - for MemberExpr, the declaration of the referenced member /// - for CXXConstructExpr, the declaration of the constructor /// - for CXXNewExpr, the declaration of the operator new /// - for ObjCIvarExpr, the declaration of the ivar /// /// For type nodes, hasDeclaration will generally match the declaration of the /// sugared type. Given /// \code /// class X {}; /// typedef X Y; /// Y y; /// \endcode /// in varDecl(hasType(hasDeclaration(decl()))) the decl will match the /// typedefDecl. A common use case is to match the underlying, desugared type. /// This can be achieved by using the hasUnqualifiedDesugaredType matcher: /// \code /// varDecl(hasType(hasUnqualifiedDesugaredType( /// recordType(hasDeclaration(decl()))))) /// \endcode /// In this matcher, the decl will match the CXXRecordDecl of class X. /// /// Usable as: Matcher<AddrLabelExpr>, Matcher<CallExpr>, /// Matcher<CXXConstructExpr>, Matcher<CXXNewExpr>, Matcher<DeclRefExpr>, /// Matcher<EnumType>, Matcher<InjectedClassNameType>, Matcher<LabelStmt>, /// Matcher<MemberExpr>, Matcher<QualType>, Matcher<RecordType>, /// Matcher<TagType>, Matcher<TemplateSpecializationType>, /// Matcher<TemplateTypeParmType>, Matcher<TypedefType>, /// Matcher<UnresolvedUsingType> inline internal::PolymorphicMatcherWithParam1< internal::HasDeclarationMatcher, internal::Matcher<Decl>, void(internal::HasDeclarationSupportedTypes)> hasDeclaration(const internal::Matcher<Decl> &InnerMatcher) { return internal::PolymorphicMatcherWithParam1< internal::HasDeclarationMatcher, internal::Matcher<Decl>, void(internal::HasDeclarationSupportedTypes)>(InnerMatcher); } /// Matches a \c NamedDecl whose underlying declaration matches the given /// matcher. /// /// Given /// \code /// namespace N { template<class T> void f(T t); } /// template <class T> void g() { using N::f; f(T()); } /// \endcode /// \c unresolvedLookupExpr(hasAnyDeclaration( /// namedDecl(hasUnderlyingDecl(hasName("::N::f"))))) /// matches the use of \c f in \c g() . AST_MATCHER_P(NamedDecl, hasUnderlyingDecl, internal::Matcher<NamedDecl>, InnerMatcher) { const NamedDecl *UnderlyingDecl = Node.getUnderlyingDecl(); return UnderlyingDecl != nullptr && InnerMatcher.matches(*UnderlyingDecl, Finder, Builder); } /// Matches on the implicit object argument of a member call expression, after /// stripping off any parentheses or implicit casts. /// /// Given /// \code /// class Y { public: void m(); }; /// Y g(); /// class X : public Y {}; /// void z(Y y, X x) { y.m(); (g()).m(); x.m(); } /// \endcode /// cxxMemberCallExpr(on(hasType(cxxRecordDecl(hasName("Y"))))) /// matches `y.m()` and `(g()).m()`. /// cxxMemberCallExpr(on(hasType(cxxRecordDecl(hasName("X"))))) /// matches `x.m()`. /// cxxMemberCallExpr(on(callExpr())) /// matches `(g()).m()`. /// /// FIXME: Overload to allow directly matching types? AST_MATCHER_P(CXXMemberCallExpr, on, internal::Matcher<Expr>, InnerMatcher) { const Expr *ExprNode = Node.getImplicitObjectArgument() ->IgnoreParenImpCasts(); return (ExprNode != nullptr && InnerMatcher.matches(*ExprNode, Finder, Builder)); } /// Matches on the receiver of an ObjectiveC Message expression. /// /// Example /// matcher = objCMessageExpr(hasReceiverType(asString("UIWebView *"))); /// matches the [webView ...] message invocation. /// \code /// NSString *webViewJavaScript = ... /// UIWebView *webView = ... /// [webView stringByEvaluatingJavaScriptFromString:webViewJavascript]; /// \endcode AST_MATCHER_P(ObjCMessageExpr, hasReceiverType, internal::Matcher<QualType>, InnerMatcher) { const QualType TypeDecl = Node.getReceiverType(); return InnerMatcher.matches(TypeDecl, Finder, Builder); } /// Returns true when the Objective-C method declaration is a class method. /// /// Example /// matcher = objcMethodDecl(isClassMethod()) /// matches /// \code /// @interface I + (void)foo; @end /// \endcode /// but not /// \code /// @interface I - (void)bar; @end /// \endcode AST_MATCHER(ObjCMethodDecl, isClassMethod) { return Node.isClassMethod(); } /// Returns true when the Objective-C method declaration is an instance method. /// /// Example /// matcher = objcMethodDecl(isInstanceMethod()) /// matches /// \code /// @interface I - (void)bar; @end /// \endcode /// but not /// \code /// @interface I + (void)foo; @end /// \endcode AST_MATCHER(ObjCMethodDecl, isInstanceMethod) { return Node.isInstanceMethod(); } /// Returns true when the Objective-C message is sent to a class. /// /// Example /// matcher = objcMessageExpr(isClassMessage()) /// matches /// \code /// [NSString stringWithFormat:@"format"]; /// \endcode /// but not /// \code /// NSString *x = @"hello"; /// [x containsString:@"h"]; /// \endcode AST_MATCHER(ObjCMessageExpr, isClassMessage) { return Node.isClassMessage(); } /// Returns true when the Objective-C message is sent to an instance. /// /// Example /// matcher = objcMessageExpr(isInstanceMessage()) /// matches /// \code /// NSString *x = @"hello"; /// [x containsString:@"h"]; /// \endcode /// but not /// \code /// [NSString stringWithFormat:@"format"]; /// \endcode AST_MATCHER(ObjCMessageExpr, isInstanceMessage) { return Node.isInstanceMessage(); } /// Matches if the Objective-C message is sent to an instance, /// and the inner matcher matches on that instance. /// /// For example the method call in /// \code /// NSString *x = @"hello"; /// [x containsString:@"h"]; /// \endcode /// is matched by /// objcMessageExpr(hasReceiver(declRefExpr(to(varDecl(hasName("x")))))) AST_MATCHER_P(ObjCMessageExpr, hasReceiver, internal::Matcher<Expr>, InnerMatcher) { const Expr *ReceiverNode = Node.getInstanceReceiver(); return (ReceiverNode != nullptr && InnerMatcher.matches(*ReceiverNode->IgnoreParenImpCasts(), Finder, Builder)); } /// Matches when BaseName == Selector.getAsString() /// /// matcher = objCMessageExpr(hasSelector("loadHTMLString:baseURL:")); /// matches the outer message expr in the code below, but NOT the message /// invocation for self.bodyView. /// \code /// [self.bodyView loadHTMLString:html baseURL:NULL]; /// \endcode AST_MATCHER_P(ObjCMessageExpr, hasSelector, std::string, BaseName) { Selector Sel = Node.getSelector(); return BaseName.compare(Sel.getAsString()) == 0; } /// Matches when at least one of the supplied string equals to the /// Selector.getAsString() /// /// matcher = objCMessageExpr(hasSelector("methodA:", "methodB:")); /// matches both of the expressions below: /// \code /// [myObj methodA:argA]; /// [myObj methodB:argB]; /// \endcode extern const internal::VariadicFunction<internal::Matcher<ObjCMessageExpr>, StringRef, internal::hasAnySelectorFunc> hasAnySelector; /// Matches ObjC selectors whose name contains /// a substring matched by the given RegExp. /// matcher = objCMessageExpr(matchesSelector("loadHTMLString\:baseURL?")); /// matches the outer message expr in the code below, but NOT the message /// invocation for self.bodyView. /// \code /// [self.bodyView loadHTMLString:html baseURL:NULL]; /// \endcode AST_MATCHER_P(ObjCMessageExpr, matchesSelector, std::string, RegExp) { assert(!RegExp.empty()); std::string SelectorString = Node.getSelector().getAsString(); llvm::Regex RE(RegExp); return RE.match(SelectorString); } /// Matches when the selector is the empty selector /// /// Matches only when the selector of the objCMessageExpr is NULL. This may /// represent an error condition in the tree! AST_MATCHER(ObjCMessageExpr, hasNullSelector) { return Node.getSelector().isNull(); } /// Matches when the selector is a Unary Selector /// /// matcher = objCMessageExpr(matchesSelector(hasUnarySelector()); /// matches self.bodyView in the code below, but NOT the outer message /// invocation of "loadHTMLString:baseURL:". /// \code /// [self.bodyView loadHTMLString:html baseURL:NULL]; /// \endcode AST_MATCHER(ObjCMessageExpr, hasUnarySelector) { return Node.getSelector().isUnarySelector(); } /// Matches when the selector is a keyword selector /// /// objCMessageExpr(hasKeywordSelector()) matches the generated setFrame /// message expression in /// /// \code /// UIWebView *webView = ...; /// CGRect bodyFrame = webView.frame; /// bodyFrame.size.height = self.bodyContentHeight; /// webView.frame = bodyFrame; /// // ^---- matches here /// \endcode AST_MATCHER(ObjCMessageExpr, hasKeywordSelector) { return Node.getSelector().isKeywordSelector(); } /// Matches when the selector has the specified number of arguments /// /// matcher = objCMessageExpr(numSelectorArgs(0)); /// matches self.bodyView in the code below /// /// matcher = objCMessageExpr(numSelectorArgs(2)); /// matches the invocation of "loadHTMLString:baseURL:" but not that /// of self.bodyView /// \code /// [self.bodyView loadHTMLString:html baseURL:NULL]; /// \endcode AST_MATCHER_P(ObjCMessageExpr, numSelectorArgs, unsigned, N) { return Node.getSelector().getNumArgs() == N; } /// Matches if the call expression's callee expression matches. /// /// Given /// \code /// class Y { void x() { this->x(); x(); Y y; y.x(); } }; /// void f() { f(); } /// \endcode /// callExpr(callee(expr())) /// matches this->x(), x(), y.x(), f() /// with callee(...) /// matching this->x, x, y.x, f respectively /// /// Note: Callee cannot take the more general internal::Matcher<Expr> /// because this introduces ambiguous overloads with calls to Callee taking a /// internal::Matcher<Decl>, as the matcher hierarchy is purely /// implemented in terms of implicit casts. AST_MATCHER_P(CallExpr, callee, internal::Matcher<Stmt>, InnerMatcher) { const Expr *ExprNode = Node.getCallee(); return (ExprNode != nullptr && InnerMatcher.matches(*ExprNode, Finder, Builder)); } /// Matches if the call expression's callee's declaration matches the /// given matcher. /// /// Example matches y.x() (matcher = callExpr(callee( /// cxxMethodDecl(hasName("x"))))) /// \code /// class Y { public: void x(); }; /// void z() { Y y; y.x(); } /// \endcode AST_MATCHER_P_OVERLOAD(CallExpr, callee, internal::Matcher<Decl>, InnerMatcher, 1) { return callExpr(hasDeclaration(InnerMatcher)).matches(Node, Finder, Builder); } /// Matches if the expression's or declaration's type matches a type /// matcher. /// /// Example matches x (matcher = expr(hasType(cxxRecordDecl(hasName("X"))))) /// and z (matcher = varDecl(hasType(cxxRecordDecl(hasName("X"))))) /// and U (matcher = typedefDecl(hasType(asString("int"))) /// and friend class X (matcher = friendDecl(hasType("X")) /// \code /// class X {}; /// void y(X &x) { x; X z; } /// typedef int U; /// class Y { friend class X; }; /// \endcode AST_POLYMORPHIC_MATCHER_P_OVERLOAD( hasType, AST_POLYMORPHIC_SUPPORTED_TYPES(Expr, FriendDecl, TypedefNameDecl, ValueDecl), internal::Matcher<QualType>, InnerMatcher, 0) { QualType QT = internal::getUnderlyingType(Node); if (!QT.isNull()) return InnerMatcher.matches(QT, Finder, Builder); return false; } /// Overloaded to match the declaration of the expression's or value /// declaration's type. /// /// In case of a value declaration (for example a variable declaration), /// this resolves one layer of indirection. For example, in the value /// declaration "X x;", cxxRecordDecl(hasName("X")) matches the declaration of /// X, while varDecl(hasType(cxxRecordDecl(hasName("X")))) matches the /// declaration of x. /// /// Example matches x (matcher = expr(hasType(cxxRecordDecl(hasName("X"))))) /// and z (matcher = varDecl(hasType(cxxRecordDecl(hasName("X"))))) /// and friend class X (matcher = friendDecl(hasType("X")) /// \code /// class X {}; /// void y(X &x) { x; X z; } /// class Y { friend class X; }; /// \endcode /// /// Usable as: Matcher<Expr>, Matcher<ValueDecl> AST_POLYMORPHIC_MATCHER_P_OVERLOAD( hasType, AST_POLYMORPHIC_SUPPORTED_TYPES(Expr, FriendDecl, ValueDecl), internal::Matcher<Decl>, InnerMatcher, 1) { QualType QT = internal::getUnderlyingType(Node); if (!QT.isNull()) return qualType(hasDeclaration(InnerMatcher)).matches(QT, Finder, Builder); return false; } /// Matches if the type location of the declarator decl's type matches /// the inner matcher. /// /// Given /// \code /// int x; /// \endcode /// declaratorDecl(hasTypeLoc(loc(asString("int")))) /// matches int x AST_MATCHER_P(DeclaratorDecl, hasTypeLoc, internal::Matcher<TypeLoc>, Inner) { if (!Node.getTypeSourceInfo()) // This happens for example for implicit destructors. return false; return Inner.matches(Node.getTypeSourceInfo()->getTypeLoc(), Finder, Builder); } /// Matches if the matched type is represented by the given string. /// /// Given /// \code /// class Y { public: void x(); }; /// void z() { Y* y; y->x(); } /// \endcode /// cxxMemberCallExpr(on(hasType(asString("class Y *")))) /// matches y->x() AST_MATCHER_P(QualType, asString, std::string, Name) { return Name == Node.getAsString(); } /// Matches if the matched type is a pointer type and the pointee type /// matches the specified matcher. /// /// Example matches y->x() /// (matcher = cxxMemberCallExpr(on(hasType(pointsTo /// cxxRecordDecl(hasName("Y"))))))) /// \code /// class Y { public: void x(); }; /// void z() { Y *y; y->x(); } /// \endcode AST_MATCHER_P( QualType, pointsTo, internal::Matcher<QualType>, InnerMatcher) { return (!Node.isNull() && Node->isAnyPointerType() && InnerMatcher.matches(Node->getPointeeType(), Finder, Builder)); } /// Overloaded to match the pointee type's declaration. AST_MATCHER_P_OVERLOAD(QualType, pointsTo, internal::Matcher<Decl>, InnerMatcher, 1) { return pointsTo(qualType(hasDeclaration(InnerMatcher))) .matches(Node, Finder, Builder); } /// Matches if the matched type matches the unqualified desugared /// type of the matched node. /// /// For example, in: /// \code /// class A {}; /// using B = A; /// \endcode /// The matcher type(hasUnqualifiedDesugaredType(recordType())) matches /// both B and A. AST_MATCHER_P(Type, hasUnqualifiedDesugaredType, internal::Matcher<Type>, InnerMatcher) { return InnerMatcher.matches(*Node.getUnqualifiedDesugaredType(), Finder, Builder); } /// Matches if the matched type is a reference type and the referenced /// type matches the specified matcher. /// /// Example matches X &x and const X &y /// (matcher = varDecl(hasType(references(cxxRecordDecl(hasName("X")))))) /// \code /// class X { /// void a(X b) { /// X &x = b; /// const X &y = b; /// } /// }; /// \endcode AST_MATCHER_P(QualType, references, internal::Matcher<QualType>, InnerMatcher) { return (!Node.isNull() && Node->isReferenceType() && InnerMatcher.matches(Node->getPointeeType(), Finder, Builder)); } /// Matches QualTypes whose canonical type matches InnerMatcher. /// /// Given: /// \code /// typedef int &int_ref; /// int a; /// int_ref b = a; /// \endcode /// /// \c varDecl(hasType(qualType(referenceType()))))) will not match the /// declaration of b but \c /// varDecl(hasType(qualType(hasCanonicalType(referenceType())))))) does. AST_MATCHER_P(QualType, hasCanonicalType, internal::Matcher<QualType>, InnerMatcher) { if (Node.isNull()) return false; return InnerMatcher.matches(Node.getCanonicalType(), Finder, Builder); } /// Overloaded to match the referenced type's declaration. AST_MATCHER_P_OVERLOAD(QualType, references, internal::Matcher<Decl>, InnerMatcher, 1) { return references(qualType(hasDeclaration(InnerMatcher))) .matches(Node, Finder, Builder); } /// Matches on the implicit object argument of a member call expression. Unlike /// `on`, matches the argument directly without stripping away anything. /// /// Given /// \code /// class Y { public: void m(); }; /// Y g(); /// class X : public Y { void g(); }; /// void z(Y y, X x) { y.m(); x.m(); x.g(); (g()).m(); } /// \endcode /// cxxMemberCallExpr(onImplicitObjectArgument(hasType( /// cxxRecordDecl(hasName("Y"))))) /// matches `y.m()`, `x.m()` and (g()).m(), but not `x.g()`. /// cxxMemberCallExpr(on(callExpr())) /// does not match `(g()).m()`, because the parens are not ignored. /// /// FIXME: Overload to allow directly matching types? AST_MATCHER_P(CXXMemberCallExpr, onImplicitObjectArgument, internal::Matcher<Expr>, InnerMatcher) { const Expr *ExprNode = Node.getImplicitObjectArgument(); return (ExprNode != nullptr && InnerMatcher.matches(*ExprNode, Finder, Builder)); } /// Matches if the type of the expression's implicit object argument either /// matches the InnerMatcher, or is a pointer to a type that matches the /// InnerMatcher. /// /// Given /// \code /// class Y { public: void m(); }; /// class X : public Y { void g(); }; /// void z() { Y y; y.m(); Y *p; p->m(); X x; x.m(); x.g(); } /// \endcode /// cxxMemberCallExpr(thisPointerType(hasDeclaration( /// cxxRecordDecl(hasName("Y"))))) /// matches `y.m()`, `p->m()` and `x.m()`. /// cxxMemberCallExpr(thisPointerType(hasDeclaration( /// cxxRecordDecl(hasName("X"))))) /// matches `x.g()`. AST_MATCHER_P_OVERLOAD(CXXMemberCallExpr, thisPointerType, internal::Matcher<QualType>, InnerMatcher, 0) { return onImplicitObjectArgument( anyOf(hasType(InnerMatcher), hasType(pointsTo(InnerMatcher)))) .matches(Node, Finder, Builder); } /// Overloaded to match the type's declaration. AST_MATCHER_P_OVERLOAD(CXXMemberCallExpr, thisPointerType, internal::Matcher<Decl>, InnerMatcher, 1) { return onImplicitObjectArgument( anyOf(hasType(InnerMatcher), hasType(pointsTo(InnerMatcher)))) .matches(Node, Finder, Builder); } /// Matches a DeclRefExpr that refers to a declaration that matches the /// specified matcher. /// /// Example matches x in if(x) /// (matcher = declRefExpr(to(varDecl(hasName("x"))))) /// \code /// bool x; /// if (x) {} /// \endcode AST_MATCHER_P(DeclRefExpr, to, internal::Matcher<Decl>, InnerMatcher) { const Decl *DeclNode = Node.getDecl(); return (DeclNode != nullptr && InnerMatcher.matches(*DeclNode, Finder, Builder)); } /// Matches a \c DeclRefExpr that refers to a declaration through a /// specific using shadow declaration. /// /// Given /// \code /// namespace a { void f() {} } /// using a::f; /// void g() { /// f(); // Matches this .. /// a::f(); // .. but not this. /// } /// \endcode /// declRefExpr(throughUsingDecl(anything())) /// matches \c f() AST_MATCHER_P(DeclRefExpr, throughUsingDecl, internal::Matcher<UsingShadowDecl>, InnerMatcher) { const NamedDecl *FoundDecl = Node.getFoundDecl(); if (const UsingShadowDecl *UsingDecl = dyn_cast<UsingShadowDecl>(FoundDecl)) return InnerMatcher.matches(*UsingDecl, Finder, Builder); return false; } /// Matches an \c OverloadExpr if any of the declarations in the set of /// overloads matches the given matcher. /// /// Given /// \code /// template <typename T> void foo(T); /// template <typename T> void bar(T); /// template <typename T> void baz(T t) { /// foo(t); /// bar(t); /// } /// \endcode /// unresolvedLookupExpr(hasAnyDeclaration( /// functionTemplateDecl(hasName("foo")))) /// matches \c foo in \c foo(t); but not \c bar in \c bar(t); AST_MATCHER_P(OverloadExpr, hasAnyDeclaration, internal::Matcher<Decl>, InnerMatcher) { return matchesFirstInPointerRange(InnerMatcher, Node.decls_begin(), Node.decls_end(), Finder, Builder); } /// Matches the Decl of a DeclStmt which has a single declaration. /// /// Given /// \code /// int a, b; /// int c; /// \endcode /// declStmt(hasSingleDecl(anything())) /// matches 'int c;' but not 'int a, b;'. AST_MATCHER_P(DeclStmt, hasSingleDecl, internal::Matcher<Decl>, InnerMatcher) { if (Node.isSingleDecl()) { const Decl *FoundDecl = Node.getSingleDecl(); return InnerMatcher.matches(*FoundDecl, Finder, Builder); } return false; } /// Matches a variable declaration that has an initializer expression /// that matches the given matcher. /// /// Example matches x (matcher = varDecl(hasInitializer(callExpr()))) /// \code /// bool y() { return true; } /// bool x = y(); /// \endcode AST_MATCHER_P( VarDecl, hasInitializer, internal::Matcher<Expr>, InnerMatcher) { const Expr *Initializer = Node.getAnyInitializer(); return (Initializer != nullptr && InnerMatcher.matches(*Initializer, Finder, Builder)); } /// \brief Matches a static variable with local scope. /// /// Example matches y (matcher = varDecl(isStaticLocal())) /// \code /// void f() { /// int x; /// static int y; /// } /// static int z; /// \endcode AST_MATCHER(VarDecl, isStaticLocal) { return Node.isStaticLocal(); } /// Matches a variable declaration that has function scope and is a /// non-static local variable. /// /// Example matches x (matcher = varDecl(hasLocalStorage()) /// \code /// void f() { /// int x; /// static int y; /// } /// int z; /// \endcode AST_MATCHER(VarDecl, hasLocalStorage) { return Node.hasLocalStorage(); } /// Matches a variable declaration that does not have local storage. /// /// Example matches y and z (matcher = varDecl(hasGlobalStorage()) /// \code /// void f() { /// int x; /// static int y; /// } /// int z; /// \endcode AST_MATCHER(VarDecl, hasGlobalStorage) { return Node.hasGlobalStorage(); } /// Matches a variable declaration that has automatic storage duration. /// /// Example matches x, but not y, z, or a. /// (matcher = varDecl(hasAutomaticStorageDuration()) /// \code /// void f() { /// int x; /// static int y; /// thread_local int z; /// } /// int a; /// \endcode AST_MATCHER(VarDecl, hasAutomaticStorageDuration) { return Node.getStorageDuration() == SD_Automatic; } /// Matches a variable declaration that has static storage duration. /// It includes the variable declared at namespace scope and those declared /// with "static" and "extern" storage class specifiers. /// /// \code /// void f() { /// int x; /// static int y; /// thread_local int z; /// } /// int a; /// static int b; /// extern int c; /// varDecl(hasStaticStorageDuration()) /// matches the function declaration y, a, b and c. /// \endcode AST_MATCHER(VarDecl, hasStaticStorageDuration) { return Node.getStorageDuration() == SD_Static; } /// Matches a variable declaration that has thread storage duration. /// /// Example matches z, but not x, z, or a. /// (matcher = varDecl(hasThreadStorageDuration()) /// \code /// void f() { /// int x; /// static int y; /// thread_local int z; /// } /// int a; /// \endcode AST_MATCHER(VarDecl, hasThreadStorageDuration) { return Node.getStorageDuration() == SD_Thread; } /// Matches a variable declaration that is an exception variable from /// a C++ catch block, or an Objective-C \@catch statement. /// /// Example matches x (matcher = varDecl(isExceptionVariable()) /// \code /// void f(int y) { /// try { /// } catch (int x) { /// } /// } /// \endcode AST_MATCHER(VarDecl, isExceptionVariable) { return Node.isExceptionVariable(); } /// Checks that a call expression or a constructor call expression has /// a specific number of arguments (including absent default arguments). /// /// Example matches f(0, 0) (matcher = callExpr(argumentCountIs(2))) /// \code /// void f(int x, int y); /// f(0, 0); /// \endcode AST_POLYMORPHIC_MATCHER_P(argumentCountIs, AST_POLYMORPHIC_SUPPORTED_TYPES(CallExpr, CXXConstructExpr, ObjCMessageExpr), unsigned, N) { return Node.getNumArgs() == N; } /// Matches the n'th argument of a call expression or a constructor /// call expression. /// /// Example matches y in x(y) /// (matcher = callExpr(hasArgument(0, declRefExpr()))) /// \code /// void x(int) { int y; x(y); } /// \endcode AST_POLYMORPHIC_MATCHER_P2(hasArgument, AST_POLYMORPHIC_SUPPORTED_TYPES(CallExpr, CXXConstructExpr, ObjCMessageExpr), unsigned, N, internal::Matcher<Expr>, InnerMatcher) { return (N < Node.getNumArgs() && InnerMatcher.matches( *Node.getArg(N)->IgnoreParenImpCasts(), Finder, Builder)); } /// Matches the n'th item of an initializer list expression. /// /// Example matches y. /// (matcher = initListExpr(hasInit(0, expr()))) /// \code /// int x{y}. /// \endcode AST_MATCHER_P2(InitListExpr, hasInit, unsigned, N, ast_matchers::internal::Matcher<Expr>, InnerMatcher) { return N < Node.getNumInits() && InnerMatcher.matches(*Node.getInit(N), Finder, Builder); } /// Matches declaration statements that contain a specific number of /// declarations. /// /// Example: Given /// \code /// int a, b; /// int c; /// int d = 2, e; /// \endcode /// declCountIs(2) /// matches 'int a, b;' and 'int d = 2, e;', but not 'int c;'. AST_MATCHER_P(DeclStmt, declCountIs, unsigned, N) { return std::distance(Node.decl_begin(), Node.decl_end()) == (ptrdiff_t)N; } /// Matches the n'th declaration of a declaration statement. /// /// Note that this does not work for global declarations because the AST /// breaks up multiple-declaration DeclStmt's into multiple single-declaration /// DeclStmt's. /// Example: Given non-global declarations /// \code /// int a, b = 0; /// int c; /// int d = 2, e; /// \endcode /// declStmt(containsDeclaration( /// 0, varDecl(hasInitializer(anything())))) /// matches only 'int d = 2, e;', and /// declStmt(containsDeclaration(1, varDecl())) /// \code /// matches 'int a, b = 0' as well as 'int d = 2, e;' /// but 'int c;' is not matched. /// \endcode AST_MATCHER_P2(DeclStmt, containsDeclaration, unsigned, N, internal::Matcher<Decl>, InnerMatcher) { const unsigned NumDecls = std::distance(Node.decl_begin(), Node.decl_end()); if (N >= NumDecls) return false; DeclStmt::const_decl_iterator Iterator = Node.decl_begin(); std::advance(Iterator, N); return InnerMatcher.matches(**Iterator, Finder, Builder); } /// Matches a C++ catch statement that has a catch-all handler. /// /// Given /// \code /// try { /// // ... /// } catch (int) { /// // ... /// } catch (...) { /// // ... /// } /// \endcode /// cxxCatchStmt(isCatchAll()) matches catch(...) but not catch(int). AST_MATCHER(CXXCatchStmt, isCatchAll) { return Node.getExceptionDecl() == nullptr; } /// Matches a constructor initializer. /// /// Given /// \code /// struct Foo { /// Foo() : foo_(1) { } /// int foo_; /// }; /// \endcode /// cxxRecordDecl(has(cxxConstructorDecl( /// hasAnyConstructorInitializer(anything()) /// ))) /// record matches Foo, hasAnyConstructorInitializer matches foo_(1) AST_MATCHER_P(CXXConstructorDecl, hasAnyConstructorInitializer, internal::Matcher<CXXCtorInitializer>, InnerMatcher) { return matchesFirstInPointerRange(InnerMatcher, Node.init_begin(), Node.init_end(), Finder, Builder); } /// Matches the field declaration of a constructor initializer. /// /// Given /// \code /// struct Foo { /// Foo() : foo_(1) { } /// int foo_; /// }; /// \endcode /// cxxRecordDecl(has(cxxConstructorDecl(hasAnyConstructorInitializer( /// forField(hasName("foo_")))))) /// matches Foo /// with forField matching foo_ AST_MATCHER_P(CXXCtorInitializer, forField, internal::Matcher<FieldDecl>, InnerMatcher) { const FieldDecl *NodeAsDecl = Node.getAnyMember(); return (NodeAsDecl != nullptr && InnerMatcher.matches(*NodeAsDecl, Finder, Builder)); } /// Matches the initializer expression of a constructor initializer. /// /// Given /// \code /// struct Foo { /// Foo() : foo_(1) { } /// int foo_; /// }; /// \endcode /// cxxRecordDecl(has(cxxConstructorDecl(hasAnyConstructorInitializer( /// withInitializer(integerLiteral(equals(1))))))) /// matches Foo /// with withInitializer matching (1) AST_MATCHER_P(CXXCtorInitializer, withInitializer, internal::Matcher<Expr>, InnerMatcher) { const Expr* NodeAsExpr = Node.getInit(); return (NodeAsExpr != nullptr && InnerMatcher.matches(*NodeAsExpr, Finder, Builder)); } /// Matches a constructor initializer if it is explicitly written in /// code (as opposed to implicitly added by the compiler). /// /// Given /// \code /// struct Foo { /// Foo() { } /// Foo(int) : foo_("A") { } /// string foo_; /// }; /// \endcode /// cxxConstructorDecl(hasAnyConstructorInitializer(isWritten())) /// will match Foo(int), but not Foo() AST_MATCHER(CXXCtorInitializer, isWritten) { return Node.isWritten(); } /// Matches a constructor initializer if it is initializing a base, as /// opposed to a member. /// /// Given /// \code /// struct B {}; /// struct D : B { /// int I; /// D(int i) : I(i) {} /// }; /// struct E : B { /// E() : B() {} /// }; /// \endcode /// cxxConstructorDecl(hasAnyConstructorInitializer(isBaseInitializer())) /// will match E(), but not match D(int). AST_MATCHER(CXXCtorInitializer, isBaseInitializer) { return Node.isBaseInitializer(); } /// Matches a constructor initializer if it is initializing a member, as /// opposed to a base. /// /// Given /// \code /// struct B {}; /// struct D : B { /// int I; /// D(int i) : I(i) {} /// }; /// struct E : B { /// E() : B() {} /// }; /// \endcode /// cxxConstructorDecl(hasAnyConstructorInitializer(isMemberInitializer())) /// will match D(int), but not match E(). AST_MATCHER(CXXCtorInitializer, isMemberInitializer) { return Node.isMemberInitializer(); } /// Matches any argument of a call expression or a constructor call /// expression, or an ObjC-message-send expression. /// /// Given /// \code /// void x(int, int, int) { int y; x(1, y, 42); } /// \endcode /// callExpr(hasAnyArgument(declRefExpr())) /// matches x(1, y, 42) /// with hasAnyArgument(...) /// matching y /// /// For ObjectiveC, given /// \code /// @interface I - (void) f:(int) y; @end /// void foo(I *i) { [i f:12]; } /// \endcode /// objcMessageExpr(hasAnyArgument(integerLiteral(equals(12)))) /// matches [i f:12] AST_POLYMORPHIC_MATCHER_P(hasAnyArgument, AST_POLYMORPHIC_SUPPORTED_TYPES( CallExpr, CXXConstructExpr, CXXUnresolvedConstructExpr, ObjCMessageExpr), internal::Matcher<Expr>, InnerMatcher) { for (const Expr *Arg : Node.arguments()) { BoundNodesTreeBuilder Result(*Builder); if (InnerMatcher.matches(*Arg, Finder, &Result)) { *Builder = std::move(Result); return true; } } return false; } /// Matches a constructor call expression which uses list initialization. AST_MATCHER(CXXConstructExpr, isListInitialization) { return Node.isListInitialization(); } /// Matches a constructor call expression which requires /// zero initialization. /// /// Given /// \code /// void foo() { /// struct point { double x; double y; }; /// point pt[2] = { { 1.0, 2.0 } }; /// } /// \endcode /// initListExpr(has(cxxConstructExpr(requiresZeroInitialization())) /// will match the implicit array filler for pt[1]. AST_MATCHER(CXXConstructExpr, requiresZeroInitialization) { return Node.requiresZeroInitialization(); } /// Matches the n'th parameter of a function or an ObjC method /// declaration or a block. /// /// Given /// \code /// class X { void f(int x) {} }; /// \endcode /// cxxMethodDecl(hasParameter(0, hasType(varDecl()))) /// matches f(int x) {} /// with hasParameter(...) /// matching int x /// /// For ObjectiveC, given /// \code /// @interface I - (void) f:(int) y; @end /// \endcode // /// the matcher objcMethodDecl(hasParameter(0, hasName("y"))) /// matches the declaration of method f with hasParameter /// matching y. AST_POLYMORPHIC_MATCHER_P2(hasParameter, AST_POLYMORPHIC_SUPPORTED_TYPES(FunctionDecl, ObjCMethodDecl, BlockDecl), unsigned, N, internal::Matcher<ParmVarDecl>, InnerMatcher) { return (N < Node.parameters().size() && InnerMatcher.matches(*Node.parameters()[N], Finder, Builder)); } /// Matches all arguments and their respective ParmVarDecl. /// /// Given /// \code /// void f(int i); /// int y; /// f(y); /// \endcode /// callExpr( /// forEachArgumentWithParam( /// declRefExpr(to(varDecl(hasName("y")))), /// parmVarDecl(hasType(isInteger())) /// )) /// matches f(y); /// with declRefExpr(...) /// matching int y /// and parmVarDecl(...) /// matching int i AST_POLYMORPHIC_MATCHER_P2(forEachArgumentWithParam, AST_POLYMORPHIC_SUPPORTED_TYPES(CallExpr, CXXConstructExpr), internal::Matcher<Expr>, ArgMatcher, internal::Matcher<ParmVarDecl>, ParamMatcher) { BoundNodesTreeBuilder Result; // The first argument of an overloaded member operator is the implicit object // argument of the method which should not be matched against a parameter, so // we skip over it here. BoundNodesTreeBuilder Matches; unsigned ArgIndex = cxxOperatorCallExpr(callee(cxxMethodDecl())) .matches(Node, Finder, &Matches) ? 1 : 0; int ParamIndex = 0; bool Matched = false; for (; ArgIndex < Node.getNumArgs(); ++ArgIndex) { BoundNodesTreeBuilder ArgMatches(*Builder); if (ArgMatcher.matches(*(Node.getArg(ArgIndex)->IgnoreParenCasts()), Finder, &ArgMatches)) { BoundNodesTreeBuilder ParamMatches(ArgMatches); if (expr(anyOf(cxxConstructExpr(hasDeclaration(cxxConstructorDecl( hasParameter(ParamIndex, ParamMatcher)))), callExpr(callee(functionDecl( hasParameter(ParamIndex, ParamMatcher)))))) .matches(Node, Finder, &ParamMatches)) { Result.addMatch(ParamMatches); Matched = true; } } ++ParamIndex; } *Builder = std::move(Result); return Matched; } /// Matches any parameter of a function or an ObjC method declaration or a /// block. /// /// Does not match the 'this' parameter of a method. /// /// Given /// \code /// class X { void f(int x, int y, int z) {} }; /// \endcode /// cxxMethodDecl(hasAnyParameter(hasName("y"))) /// matches f(int x, int y, int z) {} /// with hasAnyParameter(...) /// matching int y /// /// For ObjectiveC, given /// \code /// @interface I - (void) f:(int) y; @end /// \endcode // /// the matcher objcMethodDecl(hasAnyParameter(hasName("y"))) /// matches the declaration of method f with hasParameter /// matching y. /// /// For blocks, given /// \code /// b = ^(int y) { printf("%d", y) }; /// \endcode /// /// the matcher blockDecl(hasAnyParameter(hasName("y"))) /// matches the declaration of the block b with hasParameter /// matching y. AST_POLYMORPHIC_MATCHER_P(hasAnyParameter, AST_POLYMORPHIC_SUPPORTED_TYPES(FunctionDecl, ObjCMethodDecl, BlockDecl), internal::Matcher<ParmVarDecl>, InnerMatcher) { return matchesFirstInPointerRange(InnerMatcher, Node.param_begin(), Node.param_end(), Finder, Builder); } /// Matches \c FunctionDecls and \c FunctionProtoTypes that have a /// specific parameter count. /// /// Given /// \code /// void f(int i) {} /// void g(int i, int j) {} /// void h(int i, int j); /// void j(int i); /// void k(int x, int y, int z, ...); /// \endcode /// functionDecl(parameterCountIs(2)) /// matches \c g and \c h /// functionProtoType(parameterCountIs(2)) /// matches \c g and \c h /// functionProtoType(parameterCountIs(3)) /// matches \c k AST_POLYMORPHIC_MATCHER_P(parameterCountIs, AST_POLYMORPHIC_SUPPORTED_TYPES(FunctionDecl, FunctionProtoType), unsigned, N) { return Node.getNumParams() == N; } /// Matches \c FunctionDecls that have a noreturn attribute. /// /// Given /// \code /// void nope(); /// [[noreturn]] void a(); /// __attribute__((noreturn)) void b(); /// struct c { [[noreturn]] c(); }; /// \endcode /// functionDecl(isNoReturn()) /// matches all of those except /// \code /// void nope(); /// \endcode AST_MATCHER(FunctionDecl, isNoReturn) { return Node.isNoReturn(); } /// Matches the return type of a function declaration. /// /// Given: /// \code /// class X { int f() { return 1; } }; /// \endcode /// cxxMethodDecl(returns(asString("int"))) /// matches int f() { return 1; } AST_MATCHER_P(FunctionDecl, returns, internal::Matcher<QualType>, InnerMatcher) { return InnerMatcher.matches(Node.getReturnType(), Finder, Builder); } /// Matches extern "C" function or variable declarations. /// /// Given: /// \code /// extern "C" void f() {} /// extern "C" { void g() {} } /// void h() {} /// extern "C" int x = 1; /// extern "C" int y = 2; /// int z = 3; /// \endcode /// functionDecl(isExternC()) /// matches the declaration of f and g, but not the declaration of h. /// varDecl(isExternC()) /// matches the declaration of x and y, but not the declaration of z. AST_POLYMORPHIC_MATCHER(isExternC, AST_POLYMORPHIC_SUPPORTED_TYPES(FunctionDecl, VarDecl)) { return Node.isExternC(); } /// Matches variable/function declarations that have "static" storage /// class specifier ("static" keyword) written in the source. /// /// Given: /// \code /// static void f() {} /// static int i = 0; /// extern int j; /// int k; /// \endcode /// functionDecl(isStaticStorageClass()) /// matches the function declaration f. /// varDecl(isStaticStorageClass()) /// matches the variable declaration i. AST_POLYMORPHIC_MATCHER(isStaticStorageClass, AST_POLYMORPHIC_SUPPORTED_TYPES(FunctionDecl, VarDecl)) { return Node.getStorageClass() == SC_Static; } /// Matches deleted function declarations. /// /// Given: /// \code /// void Func(); /// void DeletedFunc() = delete; /// \endcode /// functionDecl(isDeleted()) /// matches the declaration of DeletedFunc, but not Func. AST_MATCHER(FunctionDecl, isDeleted) { return Node.isDeleted(); } /// Matches defaulted function declarations. /// /// Given: /// \code /// class A { ~A(); }; /// class B { ~B() = default; }; /// \endcode /// functionDecl(isDefaulted()) /// matches the declaration of ~B, but not ~A. AST_MATCHER(FunctionDecl, isDefaulted) { return Node.isDefaulted(); } /// Matches functions that have a dynamic exception specification. /// /// Given: /// \code /// void f(); /// void g() noexcept; /// void h() noexcept(true); /// void i() noexcept(false); /// void j() throw(); /// void k() throw(int); /// void l() throw(...); /// \endcode /// functionDecl(hasDynamicExceptionSpec()) and /// functionProtoType(hasDynamicExceptionSpec()) /// match the declarations of j, k, and l, but not f, g, h, or i. AST_POLYMORPHIC_MATCHER(hasDynamicExceptionSpec, AST_POLYMORPHIC_SUPPORTED_TYPES(FunctionDecl, FunctionProtoType)) { if (const FunctionProtoType *FnTy = internal::getFunctionProtoType(Node)) return FnTy->hasDynamicExceptionSpec(); return false; } /// Matches functions that have a non-throwing exception specification. /// /// Given: /// \code /// void f(); /// void g() noexcept; /// void h() throw(); /// void i() throw(int); /// void j() noexcept(false); /// \endcode /// functionDecl(isNoThrow()) and functionProtoType(isNoThrow()) /// match the declarations of g, and h, but not f, i or j. AST_POLYMORPHIC_MATCHER(isNoThrow, AST_POLYMORPHIC_SUPPORTED_TYPES(FunctionDecl, FunctionProtoType)) { const FunctionProtoType *FnTy = internal::getFunctionProtoType(Node); // If the function does not have a prototype, then it is assumed to be a // throwing function (as it would if the function did not have any exception // specification). if (!FnTy) return false; // Assume the best for any unresolved exception specification. if (isUnresolvedExceptionSpec(FnTy->getExceptionSpecType())) return true; return FnTy->isNothrow(); } /// Matches constexpr variable and function declarations, /// and if constexpr. /// /// Given: /// \code /// constexpr int foo = 42; /// constexpr int bar(); /// void baz() { if constexpr(1 > 0) {} } /// \endcode /// varDecl(isConstexpr()) /// matches the declaration of foo. /// functionDecl(isConstexpr()) /// matches the declaration of bar. /// ifStmt(isConstexpr()) /// matches the if statement in baz. AST_POLYMORPHIC_MATCHER(isConstexpr, AST_POLYMORPHIC_SUPPORTED_TYPES(VarDecl, FunctionDecl, IfStmt)) { return Node.isConstexpr(); } /// Matches the condition expression of an if statement, for loop, /// switch statement or conditional operator. /// /// Example matches true (matcher = hasCondition(cxxBoolLiteral(equals(true)))) /// \code /// if (true) {} /// \endcode AST_POLYMORPHIC_MATCHER_P( hasCondition, AST_POLYMORPHIC_SUPPORTED_TYPES(IfStmt, ForStmt, WhileStmt, DoStmt, SwitchStmt, AbstractConditionalOperator), internal::Matcher<Expr>, InnerMatcher) { const Expr *const Condition = Node.getCond(); return (Condition != nullptr && InnerMatcher.matches(*Condition, Finder, Builder)); } /// Matches the then-statement of an if statement. /// /// Examples matches the if statement /// (matcher = ifStmt(hasThen(cxxBoolLiteral(equals(true))))) /// \code /// if (false) true; else false; /// \endcode AST_MATCHER_P(IfStmt, hasThen, internal::Matcher<Stmt>, InnerMatcher) { const Stmt *const Then = Node.getThen(); return (Then != nullptr && InnerMatcher.matches(*Then, Finder, Builder)); } /// Matches the else-statement of an if statement. /// /// Examples matches the if statement /// (matcher = ifStmt(hasElse(cxxBoolLiteral(equals(true))))) /// \code /// if (false) false; else true; /// \endcode AST_MATCHER_P(IfStmt, hasElse, internal::Matcher<Stmt>, InnerMatcher) { const Stmt *const Else = Node.getElse(); return (Else != nullptr && InnerMatcher.matches(*Else, Finder, Builder)); } /// Matches if a node equals a previously bound node. /// /// Matches a node if it equals the node previously bound to \p ID. /// /// Given /// \code /// class X { int a; int b; }; /// \endcode /// cxxRecordDecl( /// has(fieldDecl(hasName("a"), hasType(type().bind("t")))), /// has(fieldDecl(hasName("b"), hasType(type(equalsBoundNode("t")))))) /// matches the class \c X, as \c a and \c b have the same type. /// /// Note that when multiple matches are involved via \c forEach* matchers, /// \c equalsBoundNodes acts as a filter. /// For example: /// compoundStmt( /// forEachDescendant(varDecl().bind("d")), /// forEachDescendant(declRefExpr(to(decl(equalsBoundNode("d")))))) /// will trigger a match for each combination of variable declaration /// and reference to that variable declaration within a compound statement. AST_POLYMORPHIC_MATCHER_P(equalsBoundNode, AST_POLYMORPHIC_SUPPORTED_TYPES(Stmt, Decl, Type, QualType), std::string, ID) { // FIXME: Figure out whether it makes sense to allow this // on any other node types. // For *Loc it probably does not make sense, as those seem // unique. For NestedNameSepcifier it might make sense, as // those also have pointer identity, but I'm not sure whether // they're ever reused. internal::NotEqualsBoundNodePredicate Predicate; Predicate.ID = ID; Predicate.Node = ast_type_traits::DynTypedNode::create(Node); return Builder->removeBindings(Predicate); } /// Matches the condition variable statement in an if statement. /// /// Given /// \code /// if (A* a = GetAPointer()) {} /// \endcode /// hasConditionVariableStatement(...) /// matches 'A* a = GetAPointer()'. AST_MATCHER_P(IfStmt, hasConditionVariableStatement, internal::Matcher<DeclStmt>, InnerMatcher) { const DeclStmt* const DeclarationStatement = Node.getConditionVariableDeclStmt(); return DeclarationStatement != nullptr && InnerMatcher.matches(*DeclarationStatement, Finder, Builder); } /// Matches the index expression of an array subscript expression. /// /// Given /// \code /// int i[5]; /// void f() { i[1] = 42; } /// \endcode /// arraySubscriptExpression(hasIndex(integerLiteral())) /// matches \c i[1] with the \c integerLiteral() matching \c 1 AST_MATCHER_P(ArraySubscriptExpr, hasIndex, internal::Matcher<Expr>, InnerMatcher) { if (const Expr* Expression = Node.getIdx()) return InnerMatcher.matches(*Expression, Finder, Builder); return false; } /// Matches the base expression of an array subscript expression. /// /// Given /// \code /// int i[5]; /// void f() { i[1] = 42; } /// \endcode /// arraySubscriptExpression(hasBase(implicitCastExpr( /// hasSourceExpression(declRefExpr())))) /// matches \c i[1] with the \c declRefExpr() matching \c i AST_MATCHER_P(ArraySubscriptExpr, hasBase, internal::Matcher<Expr>, InnerMatcher) { if (const Expr* Expression = Node.getBase()) return InnerMatcher.matches(*Expression, Finder, Builder); return false; } /// Matches a 'for', 'while', 'do while' statement or a function /// definition that has a given body. /// /// Given /// \code /// for (;;) {} /// \endcode /// hasBody(compoundStmt()) /// matches 'for (;;) {}' /// with compoundStmt() /// matching '{}' AST_POLYMORPHIC_MATCHER_P(hasBody, AST_POLYMORPHIC_SUPPORTED_TYPES(DoStmt, ForStmt, WhileStmt, CXXForRangeStmt, FunctionDecl), internal::Matcher<Stmt>, InnerMatcher) { const Stmt *const Statement = internal::GetBodyMatcher<NodeType>::get(Node); return (Statement != nullptr && InnerMatcher.matches(*Statement, Finder, Builder)); } /// Matches compound statements where at least one substatement matches /// a given matcher. Also matches StmtExprs that have CompoundStmt as children. /// /// Given /// \code /// { {}; 1+2; } /// \endcode /// hasAnySubstatement(compoundStmt()) /// matches '{ {}; 1+2; }' /// with compoundStmt() /// matching '{}' AST_POLYMORPHIC_MATCHER_P(hasAnySubstatement, AST_POLYMORPHIC_SUPPORTED_TYPES(CompoundStmt, StmtExpr), internal::Matcher<Stmt>, InnerMatcher) { const CompoundStmt *CS = CompoundStmtMatcher<NodeType>::get(Node); return CS && matchesFirstInPointerRange(InnerMatcher, CS->body_begin(), CS->body_end(), Finder, Builder); } /// Checks that a compound statement contains a specific number of /// child statements. /// /// Example: Given /// \code /// { for (;;) {} } /// \endcode /// compoundStmt(statementCountIs(0))) /// matches '{}' /// but does not match the outer compound statement. AST_MATCHER_P(CompoundStmt, statementCountIs, unsigned, N) { return Node.size() == N; } /// Matches literals that are equal to the given value of type ValueT. /// /// Given /// \code /// f('\0', false, 3.14, 42); /// \endcode /// characterLiteral(equals(0)) /// matches '\0' /// cxxBoolLiteral(equals(false)) and cxxBoolLiteral(equals(0)) /// match false /// floatLiteral(equals(3.14)) and floatLiteral(equals(314e-2)) /// match 3.14 /// integerLiteral(equals(42)) /// matches 42 /// /// Note that you cannot directly match a negative numeric literal because the /// minus sign is not part of the literal: It is a unary operator whose operand /// is the positive numeric literal. Instead, you must use a unaryOperator() /// matcher to match the minus sign: /// /// unaryOperator(hasOperatorName("-"), /// hasUnaryOperand(integerLiteral(equals(13)))) /// /// Usable as: Matcher<CharacterLiteral>, Matcher<CXXBoolLiteralExpr>, /// Matcher<FloatingLiteral>, Matcher<IntegerLiteral> template <typename ValueT> internal::PolymorphicMatcherWithParam1<internal::ValueEqualsMatcher, ValueT> equals(const ValueT &Value) { return internal::PolymorphicMatcherWithParam1< internal::ValueEqualsMatcher, ValueT>(Value); } AST_POLYMORPHIC_MATCHER_P_OVERLOAD(equals, AST_POLYMORPHIC_SUPPORTED_TYPES(CharacterLiteral, CXXBoolLiteralExpr, IntegerLiteral), bool, Value, 0) { return internal::ValueEqualsMatcher<NodeType, ParamT>(Value) .matchesNode(Node); } AST_POLYMORPHIC_MATCHER_P_OVERLOAD(equals, AST_POLYMORPHIC_SUPPORTED_TYPES(CharacterLiteral, CXXBoolLiteralExpr, IntegerLiteral), unsigned, Value, 1) { return internal::ValueEqualsMatcher<NodeType, ParamT>(Value) .matchesNode(Node); } AST_POLYMORPHIC_MATCHER_P_OVERLOAD(equals, AST_POLYMORPHIC_SUPPORTED_TYPES(CharacterLiteral, CXXBoolLiteralExpr, FloatingLiteral, IntegerLiteral), double, Value, 2) { return internal::ValueEqualsMatcher<NodeType, ParamT>(Value) .matchesNode(Node); } /// Matches the operator Name of operator expressions (binary or /// unary). /// /// Example matches a || b (matcher = binaryOperator(hasOperatorName("||"))) /// \code /// !(a || b) /// \endcode AST_POLYMORPHIC_MATCHER_P(hasOperatorName, AST_POLYMORPHIC_SUPPORTED_TYPES(BinaryOperator, UnaryOperator), std::string, Name) { return Name == Node.getOpcodeStr(Node.getOpcode()); } /// Matches all kinds of assignment operators. /// /// Example 1: matches a += b (matcher = binaryOperator(isAssignmentOperator())) /// \code /// if (a == b) /// a += b; /// \endcode /// /// Example 2: matches s1 = s2 /// (matcher = cxxOperatorCallExpr(isAssignmentOperator())) /// \code /// struct S { S& operator=(const S&); }; /// void x() { S s1, s2; s1 = s2; }) /// \endcode AST_POLYMORPHIC_MATCHER(isAssignmentOperator, AST_POLYMORPHIC_SUPPORTED_TYPES(BinaryOperator, CXXOperatorCallExpr)) { return Node.isAssignmentOp(); } /// Matches the left hand side of binary operator expressions. /// /// Example matches a (matcher = binaryOperator(hasLHS())) /// \code /// a || b /// \endcode AST_POLYMORPHIC_MATCHER_P(hasLHS, AST_POLYMORPHIC_SUPPORTED_TYPES(BinaryOperator, ArraySubscriptExpr), internal::Matcher<Expr>, InnerMatcher) { const Expr *LeftHandSide = Node.getLHS(); return (LeftHandSide != nullptr && InnerMatcher.matches(*LeftHandSide, Finder, Builder)); } /// Matches the right hand side of binary operator expressions. /// /// Example matches b (matcher = binaryOperator(hasRHS())) /// \code /// a || b /// \endcode AST_POLYMORPHIC_MATCHER_P(hasRHS, AST_POLYMORPHIC_SUPPORTED_TYPES(BinaryOperator, ArraySubscriptExpr), internal::Matcher<Expr>, InnerMatcher) { const Expr *RightHandSide = Node.getRHS(); return (RightHandSide != nullptr && InnerMatcher.matches(*RightHandSide, Finder, Builder)); } /// Matches if either the left hand side or the right hand side of a /// binary operator matches. inline internal::Matcher<BinaryOperator> hasEitherOperand( const internal::Matcher<Expr> &InnerMatcher) { return anyOf(hasLHS(InnerMatcher), hasRHS(InnerMatcher)); } /// Matches if the operand of a unary operator matches. /// /// Example matches true (matcher = hasUnaryOperand( /// cxxBoolLiteral(equals(true)))) /// \code /// !true /// \endcode AST_MATCHER_P(UnaryOperator, hasUnaryOperand, internal::Matcher<Expr>, InnerMatcher) { const Expr * const Operand = Node.getSubExpr(); return (Operand != nullptr && InnerMatcher.matches(*Operand, Finder, Builder)); } /// Matches if the cast's source expression /// or opaque value's source expression matches the given matcher. /// /// Example 1: matches "a string" /// (matcher = castExpr(hasSourceExpression(cxxConstructExpr()))) /// \code /// class URL { URL(string); }; /// URL url = "a string"; /// \endcode /// /// Example 2: matches 'b' (matcher = /// opaqueValueExpr(hasSourceExpression(implicitCastExpr(declRefExpr()))) /// \code /// int a = b ?: 1; /// \endcode AST_POLYMORPHIC_MATCHER_P(hasSourceExpression, AST_POLYMORPHIC_SUPPORTED_TYPES(CastExpr, OpaqueValueExpr), internal::Matcher<Expr>, InnerMatcher) { const Expr *const SubExpression = internal::GetSourceExpressionMatcher<NodeType>::get(Node); return (SubExpression != nullptr && InnerMatcher.matches(*SubExpression, Finder, Builder)); } /// Matches casts that has a given cast kind. /// /// Example: matches the implicit cast around \c 0 /// (matcher = castExpr(hasCastKind(CK_NullToPointer))) /// \code /// int *p = 0; /// \endcode /// /// If the matcher is use from clang-query, CastKind parameter /// should be passed as a quoted string. e.g., ofKind("CK_NullToPointer"). AST_MATCHER_P(CastExpr, hasCastKind, CastKind, Kind) { return Node.getCastKind() == Kind; } /// Matches casts whose destination type matches a given matcher. /// /// (Note: Clang's AST refers to other conversions as "casts" too, and calls /// actual casts "explicit" casts.) AST_MATCHER_P(ExplicitCastExpr, hasDestinationType, internal::Matcher<QualType>, InnerMatcher) { const QualType NodeType = Node.getTypeAsWritten(); return InnerMatcher.matches(NodeType, Finder, Builder); } /// Matches implicit casts whose destination type matches a given /// matcher. /// /// FIXME: Unit test this matcher AST_MATCHER_P(ImplicitCastExpr, hasImplicitDestinationType, internal::Matcher<QualType>, InnerMatcher) { return InnerMatcher.matches(Node.getType(), Finder, Builder); } /// Matches RecordDecl object that are spelled with "struct." /// /// Example matches S, but not C or U. /// \code /// struct S {}; /// class C {}; /// union U {}; /// \endcode AST_MATCHER(RecordDecl, isStruct) { return Node.isStruct(); } /// Matches RecordDecl object that are spelled with "union." /// /// Example matches U, but not C or S. /// \code /// struct S {}; /// class C {}; /// union U {}; /// \endcode AST_MATCHER(RecordDecl, isUnion) { return Node.isUnion(); } /// Matches RecordDecl object that are spelled with "class." /// /// Example matches C, but not S or U. /// \code /// struct S {}; /// class C {}; /// union U {}; /// \endcode AST_MATCHER(RecordDecl, isClass) { return Node.isClass(); } /// Matches the true branch expression of a conditional operator. /// /// Example 1 (conditional ternary operator): matches a /// \code /// condition ? a : b /// \endcode /// /// Example 2 (conditional binary operator): matches opaqueValueExpr(condition) /// \code /// condition ?: b /// \endcode AST_MATCHER_P(AbstractConditionalOperator, hasTrueExpression, internal::Matcher<Expr>, InnerMatcher) { const Expr *Expression = Node.getTrueExpr(); return (Expression != nullptr && InnerMatcher.matches(*Expression, Finder, Builder)); } /// Matches the false branch expression of a conditional operator /// (binary or ternary). /// /// Example matches b /// \code /// condition ? a : b /// condition ?: b /// \endcode AST_MATCHER_P(AbstractConditionalOperator, hasFalseExpression, internal::Matcher<Expr>, InnerMatcher) { const Expr *Expression = Node.getFalseExpr(); return (Expression != nullptr && InnerMatcher.matches(*Expression, Finder, Builder)); } /// Matches if a declaration has a body attached. /// /// Example matches A, va, fa /// \code /// class A {}; /// class B; // Doesn't match, as it has no body. /// int va; /// extern int vb; // Doesn't match, as it doesn't define the variable. /// void fa() {} /// void fb(); // Doesn't match, as it has no body. /// @interface X /// - (void)ma; // Doesn't match, interface is declaration. /// @end /// @implementation X /// - (void)ma {} /// @end /// \endcode /// /// Usable as: Matcher<TagDecl>, Matcher<VarDecl>, Matcher<FunctionDecl>, /// Matcher<ObjCMethodDecl> AST_POLYMORPHIC_MATCHER(isDefinition, AST_POLYMORPHIC_SUPPORTED_TYPES(TagDecl, VarDecl, ObjCMethodDecl, FunctionDecl)) { return Node.isThisDeclarationADefinition(); } /// Matches if a function declaration is variadic. /// /// Example matches f, but not g or h. The function i will not match, even when /// compiled in C mode. /// \code /// void f(...); /// void g(int); /// template <typename... Ts> void h(Ts...); /// void i(); /// \endcode AST_MATCHER(FunctionDecl, isVariadic) { return Node.isVariadic(); } /// Matches the class declaration that the given method declaration /// belongs to. /// /// FIXME: Generalize this for other kinds of declarations. /// FIXME: What other kind of declarations would we need to generalize /// this to? /// /// Example matches A() in the last line /// (matcher = cxxConstructExpr(hasDeclaration(cxxMethodDecl( /// ofClass(hasName("A")))))) /// \code /// class A { /// public: /// A(); /// }; /// A a = A(); /// \endcode AST_MATCHER_P(CXXMethodDecl, ofClass, internal::Matcher<CXXRecordDecl>, InnerMatcher) { const CXXRecordDecl *Parent = Node.getParent(); return (Parent != nullptr && InnerMatcher.matches(*Parent, Finder, Builder)); } /// Matches each method overridden by the given method. This matcher may /// produce multiple matches. /// /// Given /// \code /// class A { virtual void f(); }; /// class B : public A { void f(); }; /// class C : public B { void f(); }; /// \endcode /// cxxMethodDecl(ofClass(hasName("C")), /// forEachOverridden(cxxMethodDecl().bind("b"))).bind("d") /// matches once, with "b" binding "A::f" and "d" binding "C::f" (Note /// that B::f is not overridden by C::f). /// /// The check can produce multiple matches in case of multiple inheritance, e.g. /// \code /// class A1 { virtual void f(); }; /// class A2 { virtual void f(); }; /// class C : public A1, public A2 { void f(); }; /// \endcode /// cxxMethodDecl(ofClass(hasName("C")), /// forEachOverridden(cxxMethodDecl().bind("b"))).bind("d") /// matches twice, once with "b" binding "A1::f" and "d" binding "C::f", and /// once with "b" binding "A2::f" and "d" binding "C::f". AST_MATCHER_P(CXXMethodDecl, forEachOverridden, internal::Matcher<CXXMethodDecl>, InnerMatcher) { BoundNodesTreeBuilder Result; bool Matched = false; for (const auto *Overridden : Node.overridden_methods()) { BoundNodesTreeBuilder OverriddenBuilder(*Builder); const bool OverriddenMatched = InnerMatcher.matches(*Overridden, Finder, &OverriddenBuilder); if (OverriddenMatched) { Matched = true; Result.addMatch(OverriddenBuilder); } } *Builder = std::move(Result); return Matched; } /// Matches if the given method declaration is virtual. /// /// Given /// \code /// class A { /// public: /// virtual void x(); /// }; /// \endcode /// matches A::x AST_MATCHER(CXXMethodDecl, isVirtual) { return Node.isVirtual(); } /// Matches if the given method declaration has an explicit "virtual". /// /// Given /// \code /// class A { /// public: /// virtual void x(); /// }; /// class B : public A { /// public: /// void x(); /// }; /// \endcode /// matches A::x but not B::x AST_MATCHER(CXXMethodDecl, isVirtualAsWritten) { return Node.isVirtualAsWritten(); } /// Matches if the given method or class declaration is final. /// /// Given: /// \code /// class A final {}; /// /// struct B { /// virtual void f(); /// }; /// /// struct C : B { /// void f() final; /// }; /// \endcode /// matches A and C::f, but not B, C, or B::f AST_POLYMORPHIC_MATCHER(isFinal, AST_POLYMORPHIC_SUPPORTED_TYPES(CXXRecordDecl, CXXMethodDecl)) { return Node.template hasAttr<FinalAttr>(); } /// Matches if the given method declaration is pure. /// /// Given /// \code /// class A { /// public: /// virtual void x() = 0; /// }; /// \endcode /// matches A::x AST_MATCHER(CXXMethodDecl, isPure) { return Node.isPure(); } /// Matches if the given method declaration is const. /// /// Given /// \code /// struct A { /// void foo() const; /// void bar(); /// }; /// \endcode /// /// cxxMethodDecl(isConst()) matches A::foo() but not A::bar() AST_MATCHER(CXXMethodDecl, isConst) { return Node.isConst(); } /// Matches if the given method declaration declares a copy assignment /// operator. /// /// Given /// \code /// struct A { /// A &operator=(const A &); /// A &operator=(A &&); /// }; /// \endcode /// /// cxxMethodDecl(isCopyAssignmentOperator()) matches the first method but not /// the second one. AST_MATCHER(CXXMethodDecl, isCopyAssignmentOperator) { return Node.isCopyAssignmentOperator(); } /// Matches if the given method declaration declares a move assignment /// operator. /// /// Given /// \code /// struct A { /// A &operator=(const A &); /// A &operator=(A &&); /// }; /// \endcode /// /// cxxMethodDecl(isMoveAssignmentOperator()) matches the second method but not /// the first one. AST_MATCHER(CXXMethodDecl, isMoveAssignmentOperator) { return Node.isMoveAssignmentOperator(); } /// Matches if the given method declaration overrides another method. /// /// Given /// \code /// class A { /// public: /// virtual void x(); /// }; /// class B : public A { /// public: /// virtual void x(); /// }; /// \endcode /// matches B::x AST_MATCHER(CXXMethodDecl, isOverride) { return Node.size_overridden_methods() > 0 || Node.hasAttr<OverrideAttr>(); } /// Matches method declarations that are user-provided. /// /// Given /// \code /// struct S { /// S(); // #1 /// S(const S &) = default; // #2 /// S(S &&) = delete; // #3 /// }; /// \endcode /// cxxConstructorDecl(isUserProvided()) will match #1, but not #2 or #3. AST_MATCHER(CXXMethodDecl, isUserProvided) { return Node.isUserProvided(); } /// Matches member expressions that are called with '->' as opposed /// to '.'. /// /// Member calls on the implicit this pointer match as called with '->'. /// /// Given /// \code /// class Y { /// void x() { this->x(); x(); Y y; y.x(); a; this->b; Y::b; } /// template <class T> void f() { this->f<T>(); f<T>(); } /// int a; /// static int b; /// }; /// template <class T> /// class Z { /// void x() { this->m; } /// }; /// \endcode /// memberExpr(isArrow()) /// matches this->x, x, y.x, a, this->b /// cxxDependentScopeMemberExpr(isArrow()) /// matches this->m /// unresolvedMemberExpr(isArrow()) /// matches this->f<T>, f<T> AST_POLYMORPHIC_MATCHER( isArrow, AST_POLYMORPHIC_SUPPORTED_TYPES(MemberExpr, UnresolvedMemberExpr, CXXDependentScopeMemberExpr)) { return Node.isArrow(); } /// Matches QualType nodes that are of integer type. /// /// Given /// \code /// void a(int); /// void b(long); /// void c(double); /// \endcode /// functionDecl(hasAnyParameter(hasType(isInteger()))) /// matches "a(int)", "b(long)", but not "c(double)". AST_MATCHER(QualType, isInteger) { return Node->isIntegerType(); } /// Matches QualType nodes that are of unsigned integer type. /// /// Given /// \code /// void a(int); /// void b(unsigned long); /// void c(double); /// \endcode /// functionDecl(hasAnyParameter(hasType(isUnsignedInteger()))) /// matches "b(unsigned long)", but not "a(int)" and "c(double)". AST_MATCHER(QualType, isUnsignedInteger) { return Node->isUnsignedIntegerType(); } /// Matches QualType nodes that are of signed integer type. /// /// Given /// \code /// void a(int); /// void b(unsigned long); /// void c(double); /// \endcode /// functionDecl(hasAnyParameter(hasType(isSignedInteger()))) /// matches "a(int)", but not "b(unsigned long)" and "c(double)". AST_MATCHER(QualType, isSignedInteger) { return Node->isSignedIntegerType(); } /// Matches QualType nodes that are of character type. /// /// Given /// \code /// void a(char); /// void b(wchar_t); /// void c(double); /// \endcode /// functionDecl(hasAnyParameter(hasType(isAnyCharacter()))) /// matches "a(char)", "b(wchar_t)", but not "c(double)". AST_MATCHER(QualType, isAnyCharacter) { return Node->isAnyCharacterType(); } /// Matches QualType nodes that are of any pointer type; this includes /// the Objective-C object pointer type, which is different despite being /// syntactically similar. /// /// Given /// \code /// int *i = nullptr; /// /// @interface Foo /// @end /// Foo *f; /// /// int j; /// \endcode /// varDecl(hasType(isAnyPointer())) /// matches "int *i" and "Foo *f", but not "int j". AST_MATCHER(QualType, isAnyPointer) { return Node->isAnyPointerType(); } /// Matches QualType nodes that are const-qualified, i.e., that /// include "top-level" const. /// /// Given /// \code /// void a(int); /// void b(int const); /// void c(const int); /// void d(const int*); /// void e(int const) {}; /// \endcode /// functionDecl(hasAnyParameter(hasType(isConstQualified()))) /// matches "void b(int const)", "void c(const int)" and /// "void e(int const) {}". It does not match d as there /// is no top-level const on the parameter type "const int *". AST_MATCHER(QualType, isConstQualified) { return Node.isConstQualified(); } /// Matches QualType nodes that are volatile-qualified, i.e., that /// include "top-level" volatile. /// /// Given /// \code /// void a(int); /// void b(int volatile); /// void c(volatile int); /// void d(volatile int*); /// void e(int volatile) {}; /// \endcode /// functionDecl(hasAnyParameter(hasType(isVolatileQualified()))) /// matches "void b(int volatile)", "void c(volatile int)" and /// "void e(int volatile) {}". It does not match d as there /// is no top-level volatile on the parameter type "volatile int *". AST_MATCHER(QualType, isVolatileQualified) { return Node.isVolatileQualified(); } /// Matches QualType nodes that have local CV-qualifiers attached to /// the node, not hidden within a typedef. /// /// Given /// \code /// typedef const int const_int; /// const_int i; /// int *const j; /// int *volatile k; /// int m; /// \endcode /// \c varDecl(hasType(hasLocalQualifiers())) matches only \c j and \c k. /// \c i is const-qualified but the qualifier is not local. AST_MATCHER(QualType, hasLocalQualifiers) { return Node.hasLocalQualifiers(); } /// Matches a member expression where the member is matched by a /// given matcher. /// /// Given /// \code /// struct { int first, second; } first, second; /// int i(second.first); /// int j(first.second); /// \endcode /// memberExpr(member(hasName("first"))) /// matches second.first /// but not first.second (because the member name there is "second"). AST_MATCHER_P(MemberExpr, member, internal::Matcher<ValueDecl>, InnerMatcher) { return InnerMatcher.matches(*Node.getMemberDecl(), Finder, Builder); } /// Matches a member expression where the object expression is matched by a /// given matcher. Implicit object expressions are included; that is, it matches /// use of implicit `this`. /// /// Given /// \code /// struct X { /// int m; /// int f(X x) { x.m; return m; } /// }; /// \endcode /// memberExpr(hasObjectExpression(hasType(cxxRecordDecl(hasName("X"))))) /// matches `x.m`, but not `m`; however, /// memberExpr(hasObjectExpression(hasType(pointsTo( // cxxRecordDecl(hasName("X")))))) /// matches `m` (aka. `this->m`), but not `x.m`. AST_POLYMORPHIC_MATCHER_P( hasObjectExpression, AST_POLYMORPHIC_SUPPORTED_TYPES(MemberExpr, UnresolvedMemberExpr, CXXDependentScopeMemberExpr), internal::Matcher<Expr>, InnerMatcher) { if (const auto *E = dyn_cast<UnresolvedMemberExpr>(&Node)) if (E->isImplicitAccess()) return false; if (const auto *E = dyn_cast<CXXDependentScopeMemberExpr>(&Node)) if (E->isImplicitAccess()) return false; return InnerMatcher.matches(*Node.getBase(), Finder, Builder); } /// Matches any using shadow declaration. /// /// Given /// \code /// namespace X { void b(); } /// using X::b; /// \endcode /// usingDecl(hasAnyUsingShadowDecl(hasName("b")))) /// matches \code using X::b \endcode AST_MATCHER_P(UsingDecl, hasAnyUsingShadowDecl, internal::Matcher<UsingShadowDecl>, InnerMatcher) { return matchesFirstInPointerRange(InnerMatcher, Node.shadow_begin(), Node.shadow_end(), Finder, Builder); } /// Matches a using shadow declaration where the target declaration is /// matched by the given matcher. /// /// Given /// \code /// namespace X { int a; void b(); } /// using X::a; /// using X::b; /// \endcode /// usingDecl(hasAnyUsingShadowDecl(hasTargetDecl(functionDecl()))) /// matches \code using X::b \endcode /// but not \code using X::a \endcode AST_MATCHER_P(UsingShadowDecl, hasTargetDecl, internal::Matcher<NamedDecl>, InnerMatcher) { return InnerMatcher.matches(*Node.getTargetDecl(), Finder, Builder); } /// Matches template instantiations of function, class, or static /// member variable template instantiations. /// /// Given /// \code /// template <typename T> class X {}; class A {}; X<A> x; /// \endcode /// or /// \code /// template <typename T> class X {}; class A {}; template class X<A>; /// \endcode /// or /// \code /// template <typename T> class X {}; class A {}; extern template class X<A>; /// \endcode /// cxxRecordDecl(hasName("::X"), isTemplateInstantiation()) /// matches the template instantiation of X<A>. /// /// But given /// \code /// template <typename T> class X {}; class A {}; /// template <> class X<A> {}; X<A> x; /// \endcode /// cxxRecordDecl(hasName("::X"), isTemplateInstantiation()) /// does not match, as X<A> is an explicit template specialization. /// /// Usable as: Matcher<FunctionDecl>, Matcher<VarDecl>, Matcher<CXXRecordDecl> AST_POLYMORPHIC_MATCHER(isTemplateInstantiation, AST_POLYMORPHIC_SUPPORTED_TYPES(FunctionDecl, VarDecl, CXXRecordDecl)) { return (Node.getTemplateSpecializationKind() == TSK_ImplicitInstantiation || Node.getTemplateSpecializationKind() == TSK_ExplicitInstantiationDefinition || Node.getTemplateSpecializationKind() == TSK_ExplicitInstantiationDeclaration); } /// Matches declarations that are template instantiations or are inside /// template instantiations. /// /// Given /// \code /// template<typename T> void A(T t) { T i; } /// A(0); /// A(0U); /// \endcode /// functionDecl(isInstantiated()) /// matches 'A(int) {...};' and 'A(unsigned) {...}'. AST_MATCHER_FUNCTION(internal::Matcher<Decl>, isInstantiated) { auto IsInstantiation = decl(anyOf(cxxRecordDecl(isTemplateInstantiation()), functionDecl(isTemplateInstantiation()))); return decl(anyOf(IsInstantiation, hasAncestor(IsInstantiation))); } /// Matches statements inside of a template instantiation. /// /// Given /// \code /// int j; /// template<typename T> void A(T t) { T i; j += 42;} /// A(0); /// A(0U); /// \endcode /// declStmt(isInTemplateInstantiation()) /// matches 'int i;' and 'unsigned i'. /// unless(stmt(isInTemplateInstantiation())) /// will NOT match j += 42; as it's shared between the template definition and /// instantiation. AST_MATCHER_FUNCTION(internal::Matcher<Stmt>, isInTemplateInstantiation) { return stmt( hasAncestor(decl(anyOf(cxxRecordDecl(isTemplateInstantiation()), functionDecl(isTemplateInstantiation()))))); } /// Matches explicit template specializations of function, class, or /// static member variable template instantiations. /// /// Given /// \code /// template<typename T> void A(T t) { } /// template<> void A(int N) { } /// \endcode /// functionDecl(isExplicitTemplateSpecialization()) /// matches the specialization A<int>(). /// /// Usable as: Matcher<FunctionDecl>, Matcher<VarDecl>, Matcher<CXXRecordDecl> AST_POLYMORPHIC_MATCHER(isExplicitTemplateSpecialization, AST_POLYMORPHIC_SUPPORTED_TYPES(FunctionDecl, VarDecl, CXXRecordDecl)) { return (Node.getTemplateSpecializationKind() == TSK_ExplicitSpecialization); } /// Matches \c TypeLocs for which the given inner /// QualType-matcher matches. AST_MATCHER_FUNCTION_P_OVERLOAD(internal::BindableMatcher<TypeLoc>, loc, internal::Matcher<QualType>, InnerMatcher, 0) { return internal::BindableMatcher<TypeLoc>( new internal::TypeLocTypeMatcher(InnerMatcher)); } /// Matches type \c bool. /// /// Given /// \code /// struct S { bool func(); }; /// \endcode /// functionDecl(returns(booleanType())) /// matches "bool func();" AST_MATCHER(Type, booleanType) { return Node.isBooleanType(); } /// Matches type \c void. /// /// Given /// \code /// struct S { void func(); }; /// \endcode /// functionDecl(returns(voidType())) /// matches "void func();" AST_MATCHER(Type, voidType) { return Node.isVoidType(); } template <typename NodeType> using AstTypeMatcher = internal::VariadicDynCastAllOfMatcher<Type, NodeType>; /// Matches builtin Types. /// /// Given /// \code /// struct A {}; /// A a; /// int b; /// float c; /// bool d; /// \endcode /// builtinType() /// matches "int b", "float c" and "bool d" extern const AstTypeMatcher<BuiltinType> builtinType; /// Matches all kinds of arrays. /// /// Given /// \code /// int a[] = { 2, 3 }; /// int b[4]; /// void f() { int c[a[0]]; } /// \endcode /// arrayType() /// matches "int a[]", "int b[4]" and "int c[a[0]]"; extern const AstTypeMatcher<ArrayType> arrayType; /// Matches C99 complex types. /// /// Given /// \code /// _Complex float f; /// \endcode /// complexType() /// matches "_Complex float f" extern const AstTypeMatcher<ComplexType> complexType; /// Matches any real floating-point type (float, double, long double). /// /// Given /// \code /// int i; /// float f; /// \endcode /// realFloatingPointType() /// matches "float f" but not "int i" AST_MATCHER(Type, realFloatingPointType) { return Node.isRealFloatingType(); } /// Matches arrays and C99 complex types that have a specific element /// type. /// /// Given /// \code /// struct A {}; /// A a[7]; /// int b[7]; /// \endcode /// arrayType(hasElementType(builtinType())) /// matches "int b[7]" /// /// Usable as: Matcher<ArrayType>, Matcher<ComplexType> AST_TYPELOC_TRAVERSE_MATCHER_DECL(hasElementType, getElement, AST_POLYMORPHIC_SUPPORTED_TYPES(ArrayType, ComplexType)); /// Matches C arrays with a specified constant size. /// /// Given /// \code /// void() { /// int a[2]; /// int b[] = { 2, 3 }; /// int c[b[0]]; /// } /// \endcode /// constantArrayType() /// matches "int a[2]" extern const AstTypeMatcher<ConstantArrayType> constantArrayType; /// Matches nodes that have the specified size. /// /// Given /// \code /// int a[42]; /// int b[2 * 21]; /// int c[41], d[43]; /// char *s = "abcd"; /// wchar_t *ws = L"abcd"; /// char *w = "a"; /// \endcode /// constantArrayType(hasSize(42)) /// matches "int a[42]" and "int b[2 * 21]" /// stringLiteral(hasSize(4)) /// matches "abcd", L"abcd" AST_POLYMORPHIC_MATCHER_P(hasSize, AST_POLYMORPHIC_SUPPORTED_TYPES(ConstantArrayType, StringLiteral), unsigned, N) { return internal::HasSizeMatcher<NodeType>::hasSize(Node, N); } /// Matches C++ arrays whose size is a value-dependent expression. /// /// Given /// \code /// template<typename T, int Size> /// class array { /// T data[Size]; /// }; /// \endcode /// dependentSizedArrayType /// matches "T data[Size]" extern const AstTypeMatcher<DependentSizedArrayType> dependentSizedArrayType; /// Matches C arrays with unspecified size. /// /// Given /// \code /// int a[] = { 2, 3 }; /// int b[42]; /// void f(int c[]) { int d[a[0]]; }; /// \endcode /// incompleteArrayType() /// matches "int a[]" and "int c[]" extern const AstTypeMatcher<IncompleteArrayType> incompleteArrayType; /// Matches C arrays with a specified size that is not an /// integer-constant-expression. /// /// Given /// \code /// void f() { /// int a[] = { 2, 3 } /// int b[42]; /// int c[a[0]]; /// } /// \endcode /// variableArrayType() /// matches "int c[a[0]]" extern const AstTypeMatcher<VariableArrayType> variableArrayType; /// Matches \c VariableArrayType nodes that have a specific size /// expression. /// /// Given /// \code /// void f(int b) { /// int a[b]; /// } /// \endcode /// variableArrayType(hasSizeExpr(ignoringImpCasts(declRefExpr(to( /// varDecl(hasName("b"))))))) /// matches "int a[b]" AST_MATCHER_P(VariableArrayType, hasSizeExpr, internal::Matcher<Expr>, InnerMatcher) { return InnerMatcher.matches(*Node.getSizeExpr(), Finder, Builder); } /// Matches atomic types. /// /// Given /// \code /// _Atomic(int) i; /// \endcode /// atomicType() /// matches "_Atomic(int) i" extern const AstTypeMatcher<AtomicType> atomicType; /// Matches atomic types with a specific value type. /// /// Given /// \code /// _Atomic(int) i; /// _Atomic(float) f; /// \endcode /// atomicType(hasValueType(isInteger())) /// matches "_Atomic(int) i" /// /// Usable as: Matcher<AtomicType> AST_TYPELOC_TRAVERSE_MATCHER_DECL(hasValueType, getValue, AST_POLYMORPHIC_SUPPORTED_TYPES(AtomicType)); /// Matches types nodes representing C++11 auto types. /// /// Given: /// \code /// auto n = 4; /// int v[] = { 2, 3 } /// for (auto i : v) { } /// \endcode /// autoType() /// matches "auto n" and "auto i" extern const AstTypeMatcher<AutoType> autoType; /// Matches types nodes representing C++11 decltype(<expr>) types. /// /// Given: /// \code /// short i = 1; /// int j = 42; /// decltype(i + j) result = i + j; /// \endcode /// decltypeType() /// matches "decltype(i + j)" extern const AstTypeMatcher<DecltypeType> decltypeType; /// Matches \c AutoType nodes where the deduced type is a specific type. /// /// Note: There is no \c TypeLoc for the deduced type and thus no /// \c getDeducedLoc() matcher. /// /// Given /// \code /// auto a = 1; /// auto b = 2.0; /// \endcode /// autoType(hasDeducedType(isInteger())) /// matches "auto a" /// /// Usable as: Matcher<AutoType> AST_TYPE_TRAVERSE_MATCHER(hasDeducedType, getDeducedType, AST_POLYMORPHIC_SUPPORTED_TYPES(AutoType)); /// Matches \c DecltypeType nodes to find out the underlying type. /// /// Given /// \code /// decltype(1) a = 1; /// decltype(2.0) b = 2.0; /// \endcode /// decltypeType(hasUnderlyingType(isInteger())) /// matches the type of "a" /// /// Usable as: Matcher<DecltypeType> AST_TYPE_TRAVERSE_MATCHER(hasUnderlyingType, getUnderlyingType, AST_POLYMORPHIC_SUPPORTED_TYPES(DecltypeType)); /// Matches \c FunctionType nodes. /// /// Given /// \code /// int (*f)(int); /// void g(); /// \endcode /// functionType() /// matches "int (*f)(int)" and the type of "g". extern const AstTypeMatcher<FunctionType> functionType; /// Matches \c FunctionProtoType nodes. /// /// Given /// \code /// int (*f)(int); /// void g(); /// \endcode /// functionProtoType() /// matches "int (*f)(int)" and the type of "g" in C++ mode. /// In C mode, "g" is not matched because it does not contain a prototype. extern const AstTypeMatcher<FunctionProtoType> functionProtoType; /// Matches \c ParenType nodes. /// /// Given /// \code /// int (*ptr_to_array)[4]; /// int *array_of_ptrs[4]; /// \endcode /// /// \c varDecl(hasType(pointsTo(parenType()))) matches \c ptr_to_array but not /// \c array_of_ptrs. extern const AstTypeMatcher<ParenType> parenType; /// Matches \c ParenType nodes where the inner type is a specific type. /// /// Given /// \code /// int (*ptr_to_array)[4]; /// int (*ptr_to_func)(int); /// \endcode /// /// \c varDecl(hasType(pointsTo(parenType(innerType(functionType()))))) matches /// \c ptr_to_func but not \c ptr_to_array. /// /// Usable as: Matcher<ParenType> AST_TYPE_TRAVERSE_MATCHER(innerType, getInnerType, AST_POLYMORPHIC_SUPPORTED_TYPES(ParenType)); /// Matches block pointer types, i.e. types syntactically represented as /// "void (^)(int)". /// /// The \c pointee is always required to be a \c FunctionType. extern const AstTypeMatcher<BlockPointerType> blockPointerType; /// Matches member pointer types. /// Given /// \code /// struct A { int i; } /// A::* ptr = A::i; /// \endcode /// memberPointerType() /// matches "A::* ptr" extern const AstTypeMatcher<MemberPointerType> memberPointerType; /// Matches pointer types, but does not match Objective-C object pointer /// types. /// /// Given /// \code /// int *a; /// int &b = *a; /// int c = 5; /// /// @interface Foo /// @end /// Foo *f; /// \endcode /// pointerType() /// matches "int *a", but does not match "Foo *f". extern const AstTypeMatcher<PointerType> pointerType; /// Matches an Objective-C object pointer type, which is different from /// a pointer type, despite being syntactically similar. /// /// Given /// \code /// int *a; /// /// @interface Foo /// @end /// Foo *f; /// \endcode /// pointerType() /// matches "Foo *f", but does not match "int *a". extern const AstTypeMatcher<ObjCObjectPointerType> objcObjectPointerType; /// Matches both lvalue and rvalue reference types. /// /// Given /// \code /// int *a; /// int &b = *a; /// int &&c = 1; /// auto &d = b; /// auto &&e = c; /// auto &&f = 2; /// int g = 5; /// \endcode /// /// \c referenceType() matches the types of \c b, \c c, \c d, \c e, and \c f. extern const AstTypeMatcher<ReferenceType> referenceType; /// Matches lvalue reference types. /// /// Given: /// \code /// int *a; /// int &b = *a; /// int &&c = 1; /// auto &d = b; /// auto &&e = c; /// auto &&f = 2; /// int g = 5; /// \endcode /// /// \c lValueReferenceType() matches the types of \c b, \c d, and \c e. \c e is /// matched since the type is deduced as int& by reference collapsing rules. extern const AstTypeMatcher<LValueReferenceType> lValueReferenceType; /// Matches rvalue reference types. /// /// Given: /// \code /// int *a; /// int &b = *a; /// int &&c = 1; /// auto &d = b; /// auto &&e = c; /// auto &&f = 2; /// int g = 5; /// \endcode /// /// \c rValueReferenceType() matches the types of \c c and \c f. \c e is not /// matched as it is deduced to int& by reference collapsing rules. extern const AstTypeMatcher<RValueReferenceType> rValueReferenceType; /// Narrows PointerType (and similar) matchers to those where the /// \c pointee matches a given matcher. /// /// Given /// \code /// int *a; /// int const *b; /// float const *f; /// \endcode /// pointerType(pointee(isConstQualified(), isInteger())) /// matches "int const *b" /// /// Usable as: Matcher<BlockPointerType>, Matcher<MemberPointerType>, /// Matcher<PointerType>, Matcher<ReferenceType> AST_TYPELOC_TRAVERSE_MATCHER_DECL( pointee, getPointee, AST_POLYMORPHIC_SUPPORTED_TYPES(BlockPointerType, MemberPointerType, PointerType, ReferenceType)); /// Matches typedef types. /// /// Given /// \code /// typedef int X; /// \endcode /// typedefType() /// matches "typedef int X" extern const AstTypeMatcher<TypedefType> typedefType; /// Matches enum types. /// /// Given /// \code /// enum C { Green }; /// enum class S { Red }; /// /// C c; /// S s; /// \endcode // /// \c enumType() matches the type of the variable declarations of both \c c and /// \c s. extern const AstTypeMatcher<EnumType> enumType; /// Matches template specialization types. /// /// Given /// \code /// template <typename T> /// class C { }; /// /// template class C<int>; // A /// C<char> var; // B /// \endcode /// /// \c templateSpecializationType() matches the type of the explicit /// instantiation in \c A and the type of the variable declaration in \c B. extern const AstTypeMatcher<TemplateSpecializationType> templateSpecializationType; /// Matches types nodes representing unary type transformations. /// /// Given: /// \code /// typedef __underlying_type(T) type; /// \endcode /// unaryTransformType() /// matches "__underlying_type(T)" extern const AstTypeMatcher<UnaryTransformType> unaryTransformType; /// Matches record types (e.g. structs, classes). /// /// Given /// \code /// class C {}; /// struct S {}; /// /// C c; /// S s; /// \endcode /// /// \c recordType() matches the type of the variable declarations of both \c c /// and \c s. extern const AstTypeMatcher<RecordType> recordType; /// Matches tag types (record and enum types). /// /// Given /// \code /// enum E {}; /// class C {}; /// /// E e; /// C c; /// \endcode /// /// \c tagType() matches the type of the variable declarations of both \c e /// and \c c. extern const AstTypeMatcher<TagType> tagType; /// Matches types specified with an elaborated type keyword or with a /// qualified name. /// /// Given /// \code /// namespace N { /// namespace M { /// class D {}; /// } /// } /// class C {}; /// /// class C c; /// N::M::D d; /// \endcode /// /// \c elaboratedType() matches the type of the variable declarations of both /// \c c and \c d. extern const AstTypeMatcher<ElaboratedType> elaboratedType; /// Matches ElaboratedTypes whose qualifier, a NestedNameSpecifier, /// matches \c InnerMatcher if the qualifier exists. /// /// Given /// \code /// namespace N { /// namespace M { /// class D {}; /// } /// } /// N::M::D d; /// \endcode /// /// \c elaboratedType(hasQualifier(hasPrefix(specifiesNamespace(hasName("N")))) /// matches the type of the variable declaration of \c d. AST_MATCHER_P(ElaboratedType, hasQualifier, internal::Matcher<NestedNameSpecifier>, InnerMatcher) { if (const NestedNameSpecifier *Qualifier = Node.getQualifier()) return InnerMatcher.matches(*Qualifier, Finder, Builder); return false; } /// Matches ElaboratedTypes whose named type matches \c InnerMatcher. /// /// Given /// \code /// namespace N { /// namespace M { /// class D {}; /// } /// } /// N::M::D d; /// \endcode /// /// \c elaboratedType(namesType(recordType( /// hasDeclaration(namedDecl(hasName("D")))))) matches the type of the variable /// declaration of \c d. AST_MATCHER_P(ElaboratedType, namesType, internal::Matcher<QualType>, InnerMatcher) { return InnerMatcher.matches(Node.getNamedType(), Finder, Builder); } /// Matches types that represent the result of substituting a type for a /// template type parameter. /// /// Given /// \code /// template <typename T> /// void F(T t) { /// int i = 1 + t; /// } /// \endcode /// /// \c substTemplateTypeParmType() matches the type of 't' but not '1' extern const AstTypeMatcher<SubstTemplateTypeParmType> substTemplateTypeParmType; /// Matches template type parameter substitutions that have a replacement /// type that matches the provided matcher. /// /// Given /// \code /// template <typename T> /// double F(T t); /// int i; /// double j = F(i); /// \endcode /// /// \c substTemplateTypeParmType(hasReplacementType(type())) matches int AST_TYPE_TRAVERSE_MATCHER( hasReplacementType, getReplacementType, AST_POLYMORPHIC_SUPPORTED_TYPES(SubstTemplateTypeParmType)); /// Matches template type parameter types. /// /// Example matches T, but not int. /// (matcher = templateTypeParmType()) /// \code /// template <typename T> void f(int i); /// \endcode extern const AstTypeMatcher<TemplateTypeParmType> templateTypeParmType; /// Matches injected class name types. /// /// Example matches S s, but not S<T> s. /// (matcher = parmVarDecl(hasType(injectedClassNameType()))) /// \code /// template <typename T> struct S { /// void f(S s); /// void g(S<T> s); /// }; /// \endcode extern const AstTypeMatcher<InjectedClassNameType> injectedClassNameType; /// Matches decayed type /// Example matches i[] in declaration of f. /// (matcher = valueDecl(hasType(decayedType(hasDecayedType(pointerType()))))) /// Example matches i[1]. /// (matcher = expr(hasType(decayedType(hasDecayedType(pointerType()))))) /// \code /// void f(int i[]) { /// i[1] = 0; /// } /// \endcode extern const AstTypeMatcher<DecayedType> decayedType; /// Matches the decayed type, whos decayed type matches \c InnerMatcher AST_MATCHER_P(DecayedType, hasDecayedType, internal::Matcher<QualType>, InnerType) { return InnerType.matches(Node.getDecayedType(), Finder, Builder); } /// Matches declarations whose declaration context, interpreted as a /// Decl, matches \c InnerMatcher. /// /// Given /// \code /// namespace N { /// namespace M { /// class D {}; /// } /// } /// \endcode /// /// \c cxxRcordDecl(hasDeclContext(namedDecl(hasName("M")))) matches the /// declaration of \c class \c D. AST_MATCHER_P(Decl, hasDeclContext, internal::Matcher<Decl>, InnerMatcher) { const DeclContext *DC = Node.getDeclContext(); if (!DC) return false; return InnerMatcher.matches(*Decl::castFromDeclContext(DC), Finder, Builder); } /// Matches nested name specifiers. /// /// Given /// \code /// namespace ns { /// struct A { static void f(); }; /// void A::f() {} /// void g() { A::f(); } /// } /// ns::A a; /// \endcode /// nestedNameSpecifier() /// matches "ns::" and both "A::" extern const internal::VariadicAllOfMatcher<NestedNameSpecifier> nestedNameSpecifier; /// Same as \c nestedNameSpecifier but matches \c NestedNameSpecifierLoc. extern const internal::VariadicAllOfMatcher<NestedNameSpecifierLoc> nestedNameSpecifierLoc; /// Matches \c NestedNameSpecifierLocs for which the given inner /// NestedNameSpecifier-matcher matches. AST_MATCHER_FUNCTION_P_OVERLOAD( internal::BindableMatcher<NestedNameSpecifierLoc>, loc, internal::Matcher<NestedNameSpecifier>, InnerMatcher, 1) { return internal::BindableMatcher<NestedNameSpecifierLoc>( new internal::LocMatcher<NestedNameSpecifierLoc, NestedNameSpecifier>( InnerMatcher)); } /// Matches nested name specifiers that specify a type matching the /// given \c QualType matcher without qualifiers. /// /// Given /// \code /// struct A { struct B { struct C {}; }; }; /// A::B::C c; /// \endcode /// nestedNameSpecifier(specifiesType( /// hasDeclaration(cxxRecordDecl(hasName("A"))) /// )) /// matches "A::" AST_MATCHER_P(NestedNameSpecifier, specifiesType, internal::Matcher<QualType>, InnerMatcher) { if (!Node.getAsType()) return false; return InnerMatcher.matches(QualType(Node.getAsType(), 0), Finder, Builder); } /// Matches nested name specifier locs that specify a type matching the /// given \c TypeLoc. /// /// Given /// \code /// struct A { struct B { struct C {}; }; }; /// A::B::C c; /// \endcode /// nestedNameSpecifierLoc(specifiesTypeLoc(loc(type( /// hasDeclaration(cxxRecordDecl(hasName("A"))))))) /// matches "A::" AST_MATCHER_P(NestedNameSpecifierLoc, specifiesTypeLoc, internal::Matcher<TypeLoc>, InnerMatcher) { return Node && Node.getNestedNameSpecifier()->getAsType() && InnerMatcher.matches(Node.getTypeLoc(), Finder, Builder); } /// Matches on the prefix of a \c NestedNameSpecifier. /// /// Given /// \code /// struct A { struct B { struct C {}; }; }; /// A::B::C c; /// \endcode /// nestedNameSpecifier(hasPrefix(specifiesType(asString("struct A")))) and /// matches "A::" AST_MATCHER_P_OVERLOAD(NestedNameSpecifier, hasPrefix, internal::Matcher<NestedNameSpecifier>, InnerMatcher, 0) { const NestedNameSpecifier *NextNode = Node.getPrefix(); if (!NextNode) return false; return InnerMatcher.matches(*NextNode, Finder, Builder); } /// Matches on the prefix of a \c NestedNameSpecifierLoc. /// /// Given /// \code /// struct A { struct B { struct C {}; }; }; /// A::B::C c; /// \endcode /// nestedNameSpecifierLoc(hasPrefix(loc(specifiesType(asString("struct A"))))) /// matches "A::" AST_MATCHER_P_OVERLOAD(NestedNameSpecifierLoc, hasPrefix, internal::Matcher<NestedNameSpecifierLoc>, InnerMatcher, 1) { NestedNameSpecifierLoc NextNode = Node.getPrefix(); if (!NextNode) return false; return InnerMatcher.matches(NextNode, Finder, Builder); } /// Matches nested name specifiers that specify a namespace matching the /// given namespace matcher. /// /// Given /// \code /// namespace ns { struct A {}; } /// ns::A a; /// \endcode /// nestedNameSpecifier(specifiesNamespace(hasName("ns"))) /// matches "ns::" AST_MATCHER_P(NestedNameSpecifier, specifiesNamespace, internal::Matcher<NamespaceDecl>, InnerMatcher) { if (!Node.getAsNamespace()) return false; return InnerMatcher.matches(*Node.getAsNamespace(), Finder, Builder); } /// Overloads for the \c equalsNode matcher. /// FIXME: Implement for other node types. /// @{ /// Matches if a node equals another node. /// /// \c Decl has pointer identity in the AST. AST_MATCHER_P_OVERLOAD(Decl, equalsNode, const Decl*, Other, 0) { return &Node == Other; } /// Matches if a node equals another node. /// /// \c Stmt has pointer identity in the AST. AST_MATCHER_P_OVERLOAD(Stmt, equalsNode, const Stmt*, Other, 1) { return &Node == Other; } /// Matches if a node equals another node. /// /// \c Type has pointer identity in the AST. AST_MATCHER_P_OVERLOAD(Type, equalsNode, const Type*, Other, 2) { return &Node == Other; } /// @} /// Matches each case or default statement belonging to the given switch /// statement. This matcher may produce multiple matches. /// /// Given /// \code /// switch (1) { case 1: case 2: default: switch (2) { case 3: case 4: ; } } /// \endcode /// switchStmt(forEachSwitchCase(caseStmt().bind("c"))).bind("s") /// matches four times, with "c" binding each of "case 1:", "case 2:", /// "case 3:" and "case 4:", and "s" respectively binding "switch (1)", /// "switch (1)", "switch (2)" and "switch (2)". AST_MATCHER_P(SwitchStmt, forEachSwitchCase, internal::Matcher<SwitchCase>, InnerMatcher) { BoundNodesTreeBuilder Result; // FIXME: getSwitchCaseList() does not necessarily guarantee a stable // iteration order. We should use the more general iterating matchers once // they are capable of expressing this matcher (for example, it should ignore // case statements belonging to nested switch statements). bool Matched = false; for (const SwitchCase *SC = Node.getSwitchCaseList(); SC; SC = SC->getNextSwitchCase()) { BoundNodesTreeBuilder CaseBuilder(*Builder); bool CaseMatched = InnerMatcher.matches(*SC, Finder, &CaseBuilder); if (CaseMatched) { Matched = true; Result.addMatch(CaseBuilder); } } *Builder = std::move(Result); return Matched; } /// Matches each constructor initializer in a constructor definition. /// /// Given /// \code /// class A { A() : i(42), j(42) {} int i; int j; }; /// \endcode /// cxxConstructorDecl(forEachConstructorInitializer( /// forField(decl().bind("x")) /// )) /// will trigger two matches, binding for 'i' and 'j' respectively. AST_MATCHER_P(CXXConstructorDecl, forEachConstructorInitializer, internal::Matcher<CXXCtorInitializer>, InnerMatcher) { BoundNodesTreeBuilder Result; bool Matched = false; for (const auto *I : Node.inits()) { BoundNodesTreeBuilder InitBuilder(*Builder); if (InnerMatcher.matches(*I, Finder, &InitBuilder)) { Matched = true; Result.addMatch(InitBuilder); } } *Builder = std::move(Result); return Matched; } /// Matches constructor declarations that are copy constructors. /// /// Given /// \code /// struct S { /// S(); // #1 /// S(const S &); // #2 /// S(S &&); // #3 /// }; /// \endcode /// cxxConstructorDecl(isCopyConstructor()) will match #2, but not #1 or #3. AST_MATCHER(CXXConstructorDecl, isCopyConstructor) { return Node.isCopyConstructor(); } /// Matches constructor declarations that are move constructors. /// /// Given /// \code /// struct S { /// S(); // #1 /// S(const S &); // #2 /// S(S &&); // #3 /// }; /// \endcode /// cxxConstructorDecl(isMoveConstructor()) will match #3, but not #1 or #2. AST_MATCHER(CXXConstructorDecl, isMoveConstructor) { return Node.isMoveConstructor(); } /// Matches constructor declarations that are default constructors. /// /// Given /// \code /// struct S { /// S(); // #1 /// S(const S &); // #2 /// S(S &&); // #3 /// }; /// \endcode /// cxxConstructorDecl(isDefaultConstructor()) will match #1, but not #2 or #3. AST_MATCHER(CXXConstructorDecl, isDefaultConstructor) { return Node.isDefaultConstructor(); } /// Matches constructors that delegate to another constructor. /// /// Given /// \code /// struct S { /// S(); // #1 /// S(int) {} // #2 /// S(S &&) : S() {} // #3 /// }; /// S::S() : S(0) {} // #4 /// \endcode /// cxxConstructorDecl(isDelegatingConstructor()) will match #3 and #4, but not /// #1 or #2. AST_MATCHER(CXXConstructorDecl, isDelegatingConstructor) { return Node.isDelegatingConstructor(); } /// Matches constructor, conversion function, and deduction guide declarations /// that have an explicit specifier if this explicit specifier is resolved to /// true. /// /// Given /// \code /// template<bool b> /// struct S { /// S(int); // #1 /// explicit S(double); // #2 /// operator int(); // #3 /// explicit operator bool(); // #4 /// explicit(false) S(bool) // # 7 /// explicit(true) S(char) // # 8 /// explicit(b) S(S) // # 9 /// }; /// S(int) -> S<true> // #5 /// explicit S(double) -> S<false> // #6 /// \endcode /// cxxConstructorDecl(isExplicit()) will match #2 and #8, but not #1, #7 or #9. /// cxxConversionDecl(isExplicit()) will match #4, but not #3. /// cxxDeductionGuideDecl(isExplicit()) will match #6, but not #5. AST_POLYMORPHIC_MATCHER(isExplicit, AST_POLYMORPHIC_SUPPORTED_TYPES( CXXConstructorDecl, CXXConversionDecl, CXXDeductionGuideDecl)) { return Node.isExplicit(); } /// Matches the expression in an explicit specifier if present in the given /// declaration. /// /// Given /// \code /// template<bool b> /// struct S { /// S(int); // #1 /// explicit S(double); // #2 /// operator int(); // #3 /// explicit operator bool(); // #4 /// explicit(false) S(bool) // # 7 /// explicit(true) S(char) // # 8 /// explicit(b) S(S) // # 9 /// }; /// S(int) -> S<true> // #5 /// explicit S(double) -> S<false> // #6 /// \endcode /// cxxConstructorDecl(hasExplicitSpecifier(constantExpr())) will match #7, #8 and #9, but not #1 or #2. /// cxxConversionDecl(hasExplicitSpecifier(constantExpr())) will not match #3 or #4. /// cxxDeductionGuideDecl(hasExplicitSpecifier(constantExpr())) will not match #5 or #6. AST_MATCHER_P(FunctionDecl, hasExplicitSpecifier, internal::Matcher<Expr>, InnerMatcher) { ExplicitSpecifier ES = ExplicitSpecifier::getFromDecl(&Node); if (!ES.getExpr()) return false; return InnerMatcher.matches(*ES.getExpr(), Finder, Builder); } /// Matches function and namespace declarations that are marked with /// the inline keyword. /// /// Given /// \code /// inline void f(); /// void g(); /// namespace n { /// inline namespace m {} /// } /// \endcode /// functionDecl(isInline()) will match ::f(). /// namespaceDecl(isInline()) will match n::m. AST_POLYMORPHIC_MATCHER(isInline, AST_POLYMORPHIC_SUPPORTED_TYPES(NamespaceDecl, FunctionDecl)) { // This is required because the spelling of the function used to determine // whether inline is specified or not differs between the polymorphic types. if (const auto *FD = dyn_cast<FunctionDecl>(&Node)) return FD->isInlineSpecified(); else if (const auto *NSD = dyn_cast<NamespaceDecl>(&Node)) return NSD->isInline(); llvm_unreachable("Not a valid polymorphic type"); } /// Matches anonymous namespace declarations. /// /// Given /// \code /// namespace n { /// namespace {} // #1 /// } /// \endcode /// namespaceDecl(isAnonymous()) will match #1 but not ::n. AST_MATCHER(NamespaceDecl, isAnonymous) { return Node.isAnonymousNamespace(); } /// Matches declarations in the namespace `std`, but not in nested namespaces. /// /// Given /// \code /// class vector {}; /// namespace foo { /// class vector {}; /// namespace std { /// class vector {}; /// } /// } /// namespace std { /// inline namespace __1 { /// class vector {}; // #1 /// namespace experimental { /// class vector {}; /// } /// } /// } /// \endcode /// cxxRecordDecl(hasName("vector"), isInStdNamespace()) will match only #1. AST_MATCHER(Decl, isInStdNamespace) { return Node.isInStdNamespace(); } /// If the given case statement does not use the GNU case range /// extension, matches the constant given in the statement. /// /// Given /// \code /// switch (1) { case 1: case 1+1: case 3 ... 4: ; } /// \endcode /// caseStmt(hasCaseConstant(integerLiteral())) /// matches "case 1:" AST_MATCHER_P(CaseStmt, hasCaseConstant, internal::Matcher<Expr>, InnerMatcher) { if (Node.getRHS()) return false; return InnerMatcher.matches(*Node.getLHS(), Finder, Builder); } /// Matches declaration that has a given attribute. /// /// Given /// \code /// __attribute__((device)) void f() { ... } /// \endcode /// decl(hasAttr(clang::attr::CUDADevice)) matches the function declaration of /// f. If the matcher is used from clang-query, attr::Kind parameter should be /// passed as a quoted string. e.g., hasAttr("attr::CUDADevice"). AST_MATCHER_P(Decl, hasAttr, attr::Kind, AttrKind) { for (const auto *Attr : Node.attrs()) { if (Attr->getKind() == AttrKind) return true; } return false; } /// Matches the return value expression of a return statement /// /// Given /// \code /// return a + b; /// \endcode /// hasReturnValue(binaryOperator()) /// matches 'return a + b' /// with binaryOperator() /// matching 'a + b' AST_MATCHER_P(ReturnStmt, hasReturnValue, internal::Matcher<Expr>, InnerMatcher) { if (const auto *RetValue = Node.getRetValue()) return InnerMatcher.matches(*RetValue, Finder, Builder); return false; } /// Matches CUDA kernel call expression. /// /// Example matches, /// \code /// kernel<<<i,j>>>(); /// \endcode extern const internal::VariadicDynCastAllOfMatcher<Stmt, CUDAKernelCallExpr> cudaKernelCallExpr; /// Matches expressions that resolve to a null pointer constant, such as /// GNU's __null, C++11's nullptr, or C's NULL macro. /// /// Given: /// \code /// void *v1 = NULL; /// void *v2 = nullptr; /// void *v3 = __null; // GNU extension /// char *cp = (char *)0; /// int *ip = 0; /// int i = 0; /// \endcode /// expr(nullPointerConstant()) /// matches the initializer for v1, v2, v3, cp, and ip. Does not match the /// initializer for i. AST_MATCHER_FUNCTION(internal::Matcher<Expr>, nullPointerConstant) { return anyOf( gnuNullExpr(), cxxNullPtrLiteralExpr(), integerLiteral(equals(0), hasParent(expr(hasType(pointerType()))))); } /// Matches declaration of the function the statement belongs to /// /// Given: /// \code /// F& operator=(const F& o) { /// std::copy_if(o.begin(), o.end(), begin(), [](V v) { return v > 0; }); /// return *this; /// } /// \endcode /// returnStmt(forFunction(hasName("operator="))) /// matches 'return *this' /// but does not match 'return v > 0' AST_MATCHER_P(Stmt, forFunction, internal::Matcher<FunctionDecl>, InnerMatcher) { const auto &Parents = Finder->getASTContext().getParents(Node); llvm::SmallVector<ast_type_traits::DynTypedNode, 8> Stack(Parents.begin(), Parents.end()); while(!Stack.empty()) { const auto &CurNode = Stack.back(); Stack.pop_back(); if(const auto *FuncDeclNode = CurNode.get<FunctionDecl>()) { if(InnerMatcher.matches(*FuncDeclNode, Finder, Builder)) { return true; } } else if(const auto *LambdaExprNode = CurNode.get<LambdaExpr>()) { if(InnerMatcher.matches(*LambdaExprNode->getCallOperator(), Finder, Builder)) { return true; } } else { for(const auto &Parent: Finder->getASTContext().getParents(CurNode)) Stack.push_back(Parent); } } return false; } /// Matches a declaration that has external formal linkage. /// /// Example matches only z (matcher = varDecl(hasExternalFormalLinkage())) /// \code /// void f() { /// int x; /// static int y; /// } /// int z; /// \endcode /// /// Example matches f() because it has external formal linkage despite being /// unique to the translation unit as though it has internal likage /// (matcher = functionDecl(hasExternalFormalLinkage())) /// /// \code /// namespace { /// void f() {} /// } /// \endcode AST_MATCHER(NamedDecl, hasExternalFormalLinkage) { return Node.hasExternalFormalLinkage(); } /// Matches a declaration that has default arguments. /// /// Example matches y (matcher = parmVarDecl(hasDefaultArgument())) /// \code /// void x(int val) {} /// void y(int val = 0) {} /// \endcode AST_MATCHER(ParmVarDecl, hasDefaultArgument) { return Node.hasDefaultArg(); } /// Matches array new expressions. /// /// Given: /// \code /// MyClass *p1 = new MyClass[10]; /// \endcode /// cxxNewExpr(isArray()) /// matches the expression 'new MyClass[10]'. AST_MATCHER(CXXNewExpr, isArray) { return Node.isArray(); } /// Matches array new expressions with a given array size. /// /// Given: /// \code /// MyClass *p1 = new MyClass[10]; /// \endcode /// cxxNewExpr(hasArraySize(intgerLiteral(equals(10)))) /// matches the expression 'new MyClass[10]'. AST_MATCHER_P(CXXNewExpr, hasArraySize, internal::Matcher<Expr>, InnerMatcher) { return Node.isArray() && *Node.getArraySize() && InnerMatcher.matches(**Node.getArraySize(), Finder, Builder); } /// Matches a class declaration that is defined. /// /// Example matches x (matcher = cxxRecordDecl(hasDefinition())) /// \code /// class x {}; /// class y; /// \endcode AST_MATCHER(CXXRecordDecl, hasDefinition) { return Node.hasDefinition(); } /// Matches C++11 scoped enum declaration. /// /// Example matches Y (matcher = enumDecl(isScoped())) /// \code /// enum X {}; /// enum class Y {}; /// \endcode AST_MATCHER(EnumDecl, isScoped) { return Node.isScoped(); } /// Matches a function declared with a trailing return type. /// /// Example matches Y (matcher = functionDecl(hasTrailingReturn())) /// \code /// int X() {} /// auto Y() -> int {} /// \endcode AST_MATCHER(FunctionDecl, hasTrailingReturn) { if (const auto *F = Node.getType()->getAs<FunctionProtoType>()) return F->hasTrailingReturn(); return false; } /// Matches expressions that match InnerMatcher that are possibly wrapped in an /// elidable constructor and other corresponding bookkeeping nodes. /// /// In C++17, elidable copy constructors are no longer being generated in the /// AST as it is not permitted by the standard. They are, however, part of the /// AST in C++14 and earlier. So, a matcher must abstract over these differences /// to work in all language modes. This matcher skips elidable constructor-call /// AST nodes, `ExprWithCleanups` nodes wrapping elidable constructor-calls and /// various implicit nodes inside the constructor calls, all of which will not /// appear in the C++17 AST. /// /// Given /// /// \code /// struct H {}; /// H G(); /// void f() { /// H D = G(); /// } /// \endcode /// /// ``varDecl(hasInitializer(ignoringElidableConstructorCall(callExpr())))`` /// matches ``H D = G()`` in C++11 through C++17 (and beyond). AST_MATCHER_P(Expr, ignoringElidableConstructorCall, ast_matchers::internal::Matcher<Expr>, InnerMatcher) { // E tracks the node that we are examining. const Expr *E = &Node; // If present, remove an outer `ExprWithCleanups` corresponding to the // underlying `CXXConstructExpr`. This check won't cover all cases of added // `ExprWithCleanups` corresponding to `CXXConstructExpr` nodes (because the // EWC is placed on the outermost node of the expression, which this may not // be), but, it still improves the coverage of this matcher. if (const auto *CleanupsExpr = dyn_cast<ExprWithCleanups>(&Node)) E = CleanupsExpr->getSubExpr(); if (const auto *CtorExpr = dyn_cast<CXXConstructExpr>(E)) { if (CtorExpr->isElidable()) { if (const auto *MaterializeTemp = dyn_cast<MaterializeTemporaryExpr>(CtorExpr->getArg(0))) { return InnerMatcher.matches(*MaterializeTemp->GetTemporaryExpr(), Finder, Builder); } } } return InnerMatcher.matches(Node, Finder, Builder); } //----------------------------------------------------------------------------// // OpenMP handling. //----------------------------------------------------------------------------// /// Matches any ``#pragma omp`` executable directive. /// /// Given /// /// \code /// #pragma omp parallel /// #pragma omp parallel default(none) /// #pragma omp taskyield /// \endcode /// /// ``ompExecutableDirective()`` matches ``omp parallel``, /// ``omp parallel default(none)`` and ``omp taskyield``. extern const internal::VariadicDynCastAllOfMatcher<Stmt, OMPExecutableDirective> ompExecutableDirective; /// Matches standalone OpenMP directives, /// i.e., directives that can't have a structured block. /// /// Given /// /// \code /// #pragma omp parallel /// {} /// #pragma omp taskyield /// \endcode /// /// ``ompExecutableDirective(isStandaloneDirective()))`` matches /// ``omp taskyield``. AST_MATCHER(OMPExecutableDirective, isStandaloneDirective) { return Node.isStandaloneDirective(); } /// Matches the Stmt AST node that is marked as being the structured-block /// of an OpenMP executable directive. /// /// Given /// /// \code /// #pragma omp parallel /// {} /// \endcode /// /// ``stmt(isOMPStructuredBlock()))`` matches ``{}``. AST_MATCHER(Stmt, isOMPStructuredBlock) { return Node.isOMPStructuredBlock(); } /// Matches the structured-block of the OpenMP executable directive /// /// Prerequisite: the executable directive must not be standalone directive. /// If it is, it will never match. /// /// Given /// /// \code /// #pragma omp parallel /// ; /// #pragma omp parallel /// {} /// \endcode /// /// ``ompExecutableDirective(hasStructuredBlock(nullStmt()))`` will match ``;`` AST_MATCHER_P(OMPExecutableDirective, hasStructuredBlock, internal::Matcher<Stmt>, InnerMatcher) { if (Node.isStandaloneDirective()) return false; // Standalone directives have no structured blocks. return InnerMatcher.matches(*Node.getStructuredBlock(), Finder, Builder); } /// Matches any clause in an OpenMP directive. /// /// Given /// /// \code /// #pragma omp parallel /// #pragma omp parallel default(none) /// \endcode /// /// ``ompExecutableDirective(hasAnyClause(anything()))`` matches /// ``omp parallel default(none)``. AST_MATCHER_P(OMPExecutableDirective, hasAnyClause, internal::Matcher<OMPClause>, InnerMatcher) { ArrayRef<OMPClause *> Clauses = Node.clauses(); return matchesFirstInPointerRange(InnerMatcher, Clauses.begin(), Clauses.end(), Finder, Builder); } /// Matches OpenMP ``default`` clause. /// /// Given /// /// \code /// #pragma omp parallel default(none) /// #pragma omp parallel default(shared) /// #pragma omp parallel /// \endcode /// /// ``ompDefaultClause()`` matches ``default(none)`` and ``default(shared)``. extern const internal::VariadicDynCastAllOfMatcher<OMPClause, OMPDefaultClause> ompDefaultClause; /// Matches if the OpenMP ``default`` clause has ``none`` kind specified. /// /// Given /// /// \code /// #pragma omp parallel /// #pragma omp parallel default(none) /// #pragma omp parallel default(shared) /// \endcode /// /// ``ompDefaultClause(isNoneKind())`` matches only ``default(none)``. AST_MATCHER(OMPDefaultClause, isNoneKind) { return Node.getDefaultKind() == OMPC_DEFAULT_none; } /// Matches if the OpenMP ``default`` clause has ``shared`` kind specified. /// /// Given /// /// \code /// #pragma omp parallel /// #pragma omp parallel default(none) /// #pragma omp parallel default(shared) /// \endcode /// /// ``ompDefaultClause(isSharedKind())`` matches only ``default(shared)``. AST_MATCHER(OMPDefaultClause, isSharedKind) { return Node.getDefaultKind() == OMPC_DEFAULT_shared; } /// Matches if the OpenMP directive is allowed to contain the specified OpenMP /// clause kind. /// /// Given /// /// \code /// #pragma omp parallel /// #pragma omp parallel for /// #pragma omp for /// \endcode /// /// `ompExecutableDirective(isAllowedToContainClause(OMPC_default))`` matches /// ``omp parallel`` and ``omp parallel for``. /// /// If the matcher is use from clang-query, ``OpenMPClauseKind`` parameter /// should be passed as a quoted string. e.g., /// ``isAllowedToContainClauseKind("OMPC_default").`` AST_MATCHER_P(OMPExecutableDirective, isAllowedToContainClauseKind, OpenMPClauseKind, CKind) { return isAllowedClauseForDirective(Node.getDirectiveKind(), CKind); } //----------------------------------------------------------------------------// // End OpenMP handling. //----------------------------------------------------------------------------// } // namespace ast_matchers } // namespace clang #endif // LLVM_CLANG_ASTMATCHERS_ASTMATCHERS_H
interpolate_v2_op.h
/* Copyright (c) 2018 PaddlePaddle Authors. All Rights Reserve. 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 <algorithm> #include <string> #include <vector> #include "paddle/fluid/framework/op_registry.h" #include "paddle/pten/core/hostdevice.h" #include "paddle/pten/kernels/funcs/math_function.h" namespace paddle { namespace operators { template <typename T, size_t D, int MajorType = Eigen::RowMajor, typename IndexType = Eigen::DenseIndex> using EigenTensor = framework::EigenTensor<T, D, MajorType, IndexType>; using Tensor = framework::Tensor; using DataLayout = framework::DataLayout; inline std::vector<int> get_new_shape( const std::vector<const Tensor*>& list_new_shape_tensor) { // get tensor from std::vector<int> vec_new_shape; for (size_t i = 0; i < list_new_shape_tensor.size(); ++i) { auto tensor = list_new_shape_tensor[i]; PADDLE_ENFORCE_EQ(tensor->dims(), framework::make_ddim({1}), platform::errors::InvalidArgument( "The shape of dimension tensor should be [1]," "but received d%.", tensor->dims())); if (platform::is_gpu_place(tensor->place())) { framework::Tensor temp; paddle::framework::TensorCopySync(*tensor, platform::CPUPlace(), &temp); vec_new_shape.push_back(static_cast<int32_t>(*temp.data<int32_t>())); } else { vec_new_shape.push_back(static_cast<int32_t>(*tensor->data<int32_t>())); } } return vec_new_shape; } template <typename T> inline std::vector<T> get_new_data_from_tensor(const Tensor* new_data_tensor) { std::vector<T> vec_new_data; auto* new_data = new_data_tensor->data<T>(); framework::Tensor cpu_starts_tensor; if (platform::is_gpu_place(new_data_tensor->place())) { paddle::framework::TensorCopySync(*new_data_tensor, platform::CPUPlace(), &cpu_starts_tensor); new_data = cpu_starts_tensor.data<T>(); } #ifdef PADDLE_WITH_ASCEND_CL if (platform::is_npu_place(new_data_tensor->place())) { paddle::framework::TensorCopySync(*new_data_tensor, platform::CPUPlace(), &cpu_starts_tensor); new_data = cpu_starts_tensor.data<T>(); } #endif vec_new_data = std::vector<T>(new_data, new_data + new_data_tensor->numel()); return vec_new_data; } inline void ExtractNCDWH(const framework::DDim& dims, const DataLayout& data_layout, int* N, int* C, int* D, int* H, int* W) { *N = dims[0]; if (dims.size() == 3) { *C = data_layout == DataLayout::kNCHW ? dims[1] : dims[2]; *D = 1; *H = 1; *W = data_layout == DataLayout::kNCHW ? dims[2] : dims[1]; } else if (dims.size() == 4) { *C = data_layout == DataLayout::kNCHW ? dims[1] : dims[3]; *D = 1; *H = data_layout == DataLayout::kNCHW ? dims[2] : dims[1]; *W = data_layout == DataLayout::kNCHW ? dims[3] : dims[2]; } else { *C = data_layout == DataLayout::kNCHW ? dims[1] : dims[4]; *D = data_layout == DataLayout::kNCHW ? dims[2] : dims[1]; *H = data_layout == DataLayout::kNCHW ? dims[3] : dims[2]; *W = data_layout == DataLayout::kNCHW ? dims[4] : dims[3]; } } template <typename T> static void NearestNeighborInterpolate(const Tensor& input, Tensor* output, const float ratio_h, const float ratio_w, const int n, const int c, const int out_h, const int out_w, const bool align_corners, const DataLayout& data_layout) { auto input_t = EigenTensor<T, 4>::From(input); auto output_t = EigenTensor<T, 4>::From(*output); for (int k = 0; k < out_h; k++) { // loop for images int in_k = (align_corners) ? static_cast<int>(ratio_h * k + 0.5) : static_cast<int>(ratio_h * k); for (int l = 0; l < out_w; l++) { int in_l = (align_corners) ? static_cast<int>(ratio_w * l + 0.5) : static_cast<int>(ratio_w * l); for (int i = 0; i < n; i++) { // loop for batches for (int j = 0; j < c; j++) { // loop for channels if (data_layout == DataLayout::kNCHW) { output_t(i, j, k, l) = input_t(i, j, in_k, in_l); } else { output_t(i, k, l, j) = input_t(i, in_k, in_l, j); } } } } } } template <typename T> static void NearestNeighbor3DInterpolate( const Tensor& input, Tensor* output, const float ratio_d, const float ratio_h, const float ratio_w, const int n, const int c, const int out_d, const int out_h, const int out_w, const bool align_corners, const DataLayout& data_layout) { auto input_t = EigenTensor<T, 5>::From(input); auto output_t = EigenTensor<T, 5>::From(*output); for (int d = 0; d < out_d; d++) { // loop for images int in_d = (align_corners) ? static_cast<int>(ratio_d * d + 0.5) : static_cast<int>(ratio_d * d); for (int k = 0; k < out_h; k++) { int in_k = (align_corners) ? static_cast<int>(ratio_h * k + 0.5) : static_cast<int>(ratio_h * k); for (int l = 0; l < out_w; l++) { int in_l = (align_corners) ? static_cast<int>(ratio_w * l + 0.5) : static_cast<int>(ratio_w * l); for (int i = 0; i < n; i++) { // loop for batches for (int j = 0; j < c; j++) { // loop for channels if (data_layout == DataLayout::kNCHW) { output_t(i, j, d, k, l) = input_t(i, j, in_d, in_k, in_l); } else { // NDHWC output_t(i, d, k, l, j) = input_t(i, in_d, in_k, in_l, j); } } } } } } } template <typename T> static void LinearInterpolation(const Tensor& input, Tensor* output, const float ratio_w, const int in_w, const int n, const int c, const int out_w, const bool align_corners, const bool align_mode, const DataLayout data_layout) { auto input_t = EigenTensor<T, 3>::From(input); auto output_t = EigenTensor<T, 3>::From(*output); bool align_flag = (align_mode == 0 && !align_corners); std::vector<int> vx_w, vx_e; std::vector<float> vd_w, vd_e; vx_w.reserve(out_w); vx_e.reserve(out_w); vd_w.reserve(out_w); vd_e.reserve(out_w); #ifdef PADDLE_WITH_MKLML #pragma omp parallel for #endif for (int l = 0; l < out_w; l++) { int x_w = align_flag ? static_cast<int>(ratio_w * (l + 0.5) - 0.5) : static_cast<int>(ratio_w * l); x_w = (x_w > 0) ? x_w : 0; // w int x_e = (x_w < (in_w - 1)) ? (x_w + 1) : x_w; // w_id float idx_src_x = ratio_w * (l + 0.5) - 0.5; idx_src_x = (idx_src_x > 0) ? idx_src_x : 0; float d_w = align_flag ? idx_src_x - x_w : ratio_w * l - x_w; // w1lambda float d_e = 1.f - d_w; // w2lambda { vx_w[l] = x_w; vx_e[l] = x_e; vd_w[l] = d_w; vd_e[l] = d_e; } } #ifdef PADDLE_WITH_MKLML #pragma omp parallel for collapse(3) #endif for (int i = 0; i < n; i++) { // loop for batches for (int j = 0; j < c; j++) { // loop for channels for (int l = 0; l < out_w; l++) { // linear interpolation T out_t; if (data_layout == DataLayout::kNCHW) { out_t = input_t(i, j, vx_w[l]) * vd_e[l] + input_t(i, j, vx_e[l]) * vd_w[l]; output_t(i, j, l) = out_t; } else { out_t = input_t(i, vx_w[l], j) * vd_e[l] + input_t(i, vx_e[l], j) * vd_w[l]; output_t(i, l, j) = out_t; } } } } } template <typename T> static void LinearInterpolationGrad(const Tensor& output_grad, Tensor* input_grad, const float ratio_w, const int in_w, const int n, const int c, const int out_w, const bool align_corners, const int align_mode, const DataLayout data_layout) { auto input_grad_t = EigenTensor<T, 3>::From(*input_grad); auto output_grad_t = EigenTensor<T, 3>::From(output_grad); bool align_flag = (align_mode == 0 && !align_corners); for (int l = 0; l < out_w; l++) { int x_w = align_flag ? static_cast<int>(ratio_w * (l + 0.5) - 0.5) : static_cast<int>(ratio_w * l); x_w = (x_w > 0) ? x_w : 0; // w int x_e = (x_w < (in_w - 1)) ? (x_w + 1) : x_w; // w_id float idx_src_x = ratio_w * (l + 0.5) - 0.5; idx_src_x = (idx_src_x > 0) ? idx_src_x : 0; float d_w = align_flag ? idx_src_x - x_w : ratio_w * l - x_w; // w1lambda float d_e = 1.f - d_w; // w2lambda for (int i = 0; i < n; i++) { // loop for batches for (int j = 0; j < c; j++) { // loop for channels // linear interpolation grad if (data_layout == DataLayout::kNCHW) { const T grad = output_grad_t(i, j, l); input_grad_t(i, j, x_w) += static_cast<T>(grad * d_e); input_grad_t(i, j, x_e) += static_cast<T>(grad * d_w); } else { const T grad = output_grad_t(i, l, j); input_grad_t(i, x_w, j) += static_cast<T>(grad * d_e); input_grad_t(i, x_e, j) += static_cast<T>(grad * d_w); } } } } } template <typename T> static void BilinearInterpolation(const Tensor& input, Tensor* output, const float ratio_h, const float ratio_w, const int in_h, const int in_w, const int n, const int c, const int out_h, const int out_w, const bool align_corners, const bool align_mode, const DataLayout data_layout) { auto input_t = EigenTensor<T, 4>::From(input); auto output_t = EigenTensor<T, 4>::From(*output); bool align_flag = (align_mode == 0 && !align_corners); std::vector<int> vy_n, vy_s; std::vector<float> vd_n, vd_s; vy_n.reserve(out_h); vy_s.reserve(out_h); vd_n.reserve(out_h); vd_s.reserve(out_h); #ifdef PADDLE_WITH_MKLML #pragma omp parallel for #endif for (int k = 0; k < out_h; k++) { int y_n = align_flag ? static_cast<int>(ratio_h * (k + 0.5) - 0.5) : static_cast<int>(ratio_h * k); y_n = (y_n > 0) ? y_n : 0; int y_s = (y_n + 1) < (in_h - 1) ? (y_n + 1) : (in_h - 1); float idx_src_y = ratio_h * (k + 0.5) - 0.5; idx_src_y = (idx_src_y > 0) ? idx_src_y : 0; float d_n = align_flag ? idx_src_y - y_n : ratio_h * k - y_n; float d_s = 1.f - d_n; { vy_n[k] = y_n; vy_s[k] = y_s; vd_n[k] = d_n; vd_s[k] = d_s; } } std::vector<int> vx_w, vx_e; std::vector<float> vd_w, vd_e; vx_w.reserve(out_w); vx_e.reserve(out_w); vd_w.reserve(out_w); vd_e.reserve(out_w); #ifdef PADDLE_WITH_MKLML #pragma omp parallel for #endif for (int l = 0; l < out_w; l++) { int x_w = (align_mode == 0 && !align_corners) ? static_cast<int>(ratio_w * (l + 0.5) - 0.5) : static_cast<int>(ratio_w * l); x_w = (x_w > 0) ? x_w : 0; int x_e = (x_w + 1) < (in_w - 1) ? (x_w + 1) : (in_w - 1); float idx_src_x = ratio_w * (l + 0.5) - 0.5; idx_src_x = (idx_src_x > 0) ? idx_src_x : 0; float d_w = align_flag ? idx_src_x - x_w : ratio_w * l - x_w; float d_e = 1.f - d_w; { vx_w[l] = x_w; vx_e[l] = x_e; vd_w[l] = d_w; vd_e[l] = d_e; } } #ifdef PADDLE_WITH_MKLML #pragma omp parallel for collapse(4) #endif for (int i = 0; i < n; i++) { // loop for batches for (int j = 0; j < c; j++) { // loop for channels for (int k = 0; k < out_h; k++) { // loop for images for (int l = 0; l < out_w; l++) { // bilinear interpolation T out_t; if (data_layout == DataLayout::kNCHW) { out_t = input_t(i, j, vy_n[k], vx_w[l]) * vd_s[k] * vd_e[l] + input_t(i, j, vy_s[k], vx_w[l]) * vd_n[k] * vd_e[l] + input_t(i, j, vy_n[k], vx_e[l]) * vd_s[k] * vd_w[l] + input_t(i, j, vy_s[k], vx_e[l]) * vd_n[k] * vd_w[l]; output_t(i, j, k, l) = out_t; } else { out_t = input_t(i, vy_n[k], vx_w[l], j) * vd_s[k] * vd_e[l] + input_t(i, vy_s[k], vx_w[l], j) * vd_n[k] * vd_e[l] + input_t(i, vy_n[k], vx_e[l], j) * vd_s[k] * vd_w[l] + input_t(i, vy_s[k], vx_e[l], j) * vd_n[k] * vd_w[l]; output_t(i, k, l, j) = out_t; } } } } } } template <typename T> static void TrilinearInterpolation( const Tensor& input, Tensor* output, const float ratio_d, const float ratio_h, const float ratio_w, const int in_d, const int in_h, const int in_w, const int n, const int c, const int out_d, const int out_h, const int out_w, const bool align_corners, const bool align_mode, const DataLayout& data_layout) { auto input_t = EigenTensor<T, 5>::From(input); auto output_t = EigenTensor<T, 5>::From(*output); bool align_flag = (align_mode == 0 && !align_corners); std::vector<int> vt_f, vt_b; std::vector<float> vd_f, vd_b; vt_f.reserve(out_d); vt_b.reserve(out_d); vd_f.reserve(out_d); vd_b.reserve(out_d); #ifdef PADDLE_WITH_MKLML #pragma omp parallel for #endif for (int j = 0; j < out_d; j++) { int t_f = align_flag ? static_cast<int>(ratio_d * (j + 0.5) - 0.5) : static_cast<int>(ratio_d * j); t_f = (t_f > 0) ? t_f : 0; int t_b = (t_f + 1) < (in_d - 1) ? (t_f + 1) : (in_d - 1); float idx_src_t = ratio_d * (j + 0.5) - 0.5; idx_src_t = (idx_src_t > 0) ? idx_src_t : 0; float d_f = align_flag ? idx_src_t - t_f : ratio_d * j - t_f; float d_b = 1.f - d_f; { vt_f[j] = t_f; vt_b[j] = t_b; vd_f[j] = d_f; vd_b[j] = d_b; } } std::vector<int> vy_n, vy_s; std::vector<float> vd_n, vd_s; vy_n.reserve(out_h); vy_s.reserve(out_h); vd_n.reserve(out_h); vd_s.reserve(out_h); #ifdef PADDLE_WITH_MKLML #pragma omp parallel for #endif for (int k = 0; k < out_h; k++) { int y_n = align_flag ? static_cast<int>(ratio_h * (k + 0.5) - 0.5) : static_cast<int>(ratio_h * k); y_n = (y_n > 0) ? y_n : 0; int y_s = (y_n + 1) < (in_h - 1) ? (y_n + 1) : (in_h - 1); float idx_src_y = ratio_h * (k + 0.5) - 0.5; idx_src_y = (idx_src_y > 0) ? idx_src_y : 0; float d_n = align_flag ? idx_src_y - y_n : ratio_h * k - y_n; float d_s = 1.f - d_n; { vy_n[k] = y_n; vy_s[k] = y_s; vd_n[k] = d_n; vd_s[k] = d_s; } } std::vector<int> vx_w, vx_e; std::vector<float> vd_w, vd_e; vx_w.reserve(out_w); vx_e.reserve(out_w); vd_w.reserve(out_w); vd_e.reserve(out_w); #ifdef PADDLE_WITH_MKLML #pragma omp parallel for #endif for (int l = 0; l < out_w; l++) { int x_w = (align_mode == 0 && !align_corners) ? static_cast<int>(ratio_w * (l + 0.5) - 0.5) : static_cast<int>(ratio_w * l); x_w = (x_w > 0) ? x_w : 0; int x_e = (x_w + 1) < (in_w - 1) ? (x_w + 1) : (in_w - 1); float idx_src_x = ratio_w * (l + 0.5) - 0.5; idx_src_x = (idx_src_x > 0) ? idx_src_x : 0; float d_w = align_flag ? idx_src_x - x_w : ratio_w * l - x_w; float d_e = 1.f - d_w; { vx_w[l] = x_w; vx_e[l] = x_e; vd_w[l] = d_w; vd_e[l] = d_e; } } #ifdef PADDLE_WITH_MKLML #pragma omp parallel for collapse(5) #endif for (int b = 0; b < n; b++) { // loop for batches for (int i = 0; i < c; i++) { // loop for channels for (int j = 0; j < out_d; j++) { // loop for D, H, W for (int k = 0; k < out_h; k++) { for (int l = 0; l < out_w; l++) { // trilinear interpolation if (data_layout == DataLayout::kNCHW) { T out_t = input_t(b, i, vt_f[j], vy_n[k], vx_w[l]) * vd_b[j] * vd_s[k] * vd_e[l] + input_t(b, i, vt_f[j], vy_n[k], vx_e[l]) * vd_b[j] * vd_s[k] * vd_w[l] + input_t(b, i, vt_f[j], vy_s[k], vx_w[l]) * vd_b[j] * vd_n[k] * vd_e[l] + input_t(b, i, vt_f[j], vy_s[k], vx_e[l]) * vd_b[j] * vd_n[k] * vd_w[l] + input_t(b, i, vt_b[j], vy_n[k], vx_w[l]) * vd_f[j] * vd_s[k] * vd_e[l] + input_t(b, i, vt_b[j], vy_n[k], vx_e[l]) * vd_f[j] * vd_s[k] * vd_w[l] + input_t(b, i, vt_b[j], vy_s[k], vx_w[l]) * vd_f[j] * vd_n[k] * vd_e[l] + input_t(b, i, vt_b[j], vy_s[k], vx_e[l]) * vd_f[j] * vd_n[k] * vd_w[l]; output_t(b, i, j, k, l) = out_t; } else { T out_t = input_t(b, vt_f[j], vy_n[k], vx_w[l], i) * vd_b[j] * vd_s[k] * vd_e[l] + input_t(b, vt_f[j], vy_n[k], vx_e[l], i) * vd_b[j] * vd_s[k] * vd_w[l] + input_t(b, vt_f[j], vy_s[k], vx_w[l], i) * vd_b[j] * vd_n[k] * vd_e[l] + input_t(b, vt_f[j], vy_s[k], vx_e[l], i) * vd_b[j] * vd_n[k] * vd_w[l] + input_t(b, vt_b[j], vy_n[k], vx_w[l], i) * vd_f[j] * vd_s[k] * vd_e[l] + input_t(b, vt_b[j], vy_n[k], vx_e[l], i) * vd_f[j] * vd_s[k] * vd_w[l] + input_t(b, vt_b[j], vy_s[k], vx_w[l], i) * vd_f[j] * vd_n[k] * vd_e[l] + input_t(b, vt_b[j], vy_s[k], vx_e[l], i) * vd_f[j] * vd_n[k] * vd_w[l]; output_t(b, j, k, l, i) = out_t; } } } } } } } template <typename T> HOSTDEVICE inline T cubic_convolution1(T x, T A) { return ((A + 2) * x - (A + 3)) * x * x + 1; } template <typename T> HOSTDEVICE inline T cubic_convolution2(T x, T A) { return ((A * x - 5 * A) * x + 8 * A) * x - 4 * A; } template <typename T> HOSTDEVICE inline void get_cubic_upsample_coefficients(T coeffs[4], T t) { T A = -0.75; T x1 = t; coeffs[0] = cubic_convolution2<T>(x1 + 1.0, A); coeffs[1] = cubic_convolution1<T>(x1, A); // opposite coefficients T x2 = 1.0 - t; coeffs[2] = cubic_convolution1<T>(x2, A); coeffs[3] = cubic_convolution2<T>(x2 + 1.0, A); } template <typename T> static inline T cubic_interp(T x0, T x1, T x2, T x3, T t) { T coeffs[4]; get_cubic_upsample_coefficients<T>(coeffs, t); return x0 * coeffs[0] + x1 * coeffs[1] + x2 * coeffs[2] + x3 * coeffs[3]; } template <typename T> static void BicubicInterpolation(const Tensor& input, Tensor* output, const float ratio_h, const float ratio_w, const int in_h, const int in_w, const int n, const int c, const int out_h, const int out_w, const bool align_corners, const DataLayout data_layout) { auto input_t = EigenTensor<T, 4>::From(input); auto output_t = EigenTensor<T, 4>::From(*output); for (int k = 0; k < out_h; k++) { // loop for images T y_n = align_corners ? static_cast<T>(ratio_h * k) : static_cast<T>(ratio_h * (k + 0.5) - 0.5); int input_y = floorf(y_n); const T y_t = y_n - input_y; for (int l = 0; l < out_w; l++) { T x_n = align_corners ? static_cast<T>(ratio_w * l) : static_cast<T>(ratio_w * (l + 0.5) - 0.5); int input_x = floorf(x_n); const T x_t = x_n - input_x; for (int i = 0; i < n; i++) { // loop for batches for (int j = 0; j < c; j++) { // loop for channels T coefficients[4]; // interp 4 times in x direction for (int ii = 0; ii < 4; ii++) { int access_y = std::max(std::min(input_y - 1 + ii, in_h - 1), static_cast<int>(0)); int access_x_0 = std::max(std::min(input_x - 1, in_w - 1), static_cast<int>(0)); int access_x_1 = std::max(std::min(input_x + 0, in_w - 1), static_cast<int>(0)); int access_x_2 = std::max(std::min(input_x + 1, in_w - 1), static_cast<int>(0)); int access_x_3 = std::max(std::min(input_x + 2, in_w - 1), static_cast<int>(0)); if (data_layout == DataLayout::kNCHW) { coefficients[ii] = cubic_interp<T>(input_t(i, j, access_y, access_x_0), input_t(i, j, access_y, access_x_1), input_t(i, j, access_y, access_x_2), input_t(i, j, access_y, access_x_3), x_t); } else { coefficients[ii] = cubic_interp<T>(input_t(i, access_y, access_x_0, j), input_t(i, access_y, access_x_1, j), input_t(i, access_y, access_x_2, j), input_t(i, access_y, access_x_3, j), x_t); } } // interp y direction if (data_layout == DataLayout::kNCHW) { output_t(i, j, k, l) = cubic_interp<T>(coefficients[0], coefficients[1], coefficients[2], coefficients[3], y_t); } else { output_t(i, k, l, j) = cubic_interp<T>(coefficients[0], coefficients[1], coefficients[2], coefficients[3], y_t); } } } } } } template <typename T> static void NearestNeighborInterpolateGrad( const Tensor& output_grad, Tensor* input_grad, const float ratio_h, const float ratio_w, const int n, const int c, const int out_h, const int out_w, const bool align_corners, const DataLayout data_layout) { auto input_grad_t = EigenTensor<T, 4>::From(*input_grad); auto output_grad_t = EigenTensor<T, 4>::From(output_grad); for (int k = 0; k < out_h; k++) { // loop for images int in_k = (align_corners) ? static_cast<int>(ratio_h * k + 0.5) : static_cast<int>(ratio_h * k); for (int l = 0; l < out_w; l++) { int in_l = (align_corners) ? static_cast<int>(ratio_w * l + 0.5) : static_cast<int>(ratio_w * l); for (int i = 0; i < n; i++) { // loop for batches for (int j = 0; j < c; j++) { // loop for channels if (data_layout == DataLayout::kNCHW) { input_grad_t(i, j, in_k, in_l) += output_grad_t(i, j, k, l); } else { input_grad_t(i, in_k, in_l, j) += output_grad_t(i, k, l, j); } } } } } } template <typename T> static void NearestNeighbor3DInterpolateGrad( const Tensor& output_grad, Tensor* input_grad, const float ratio_d, const float ratio_h, const float ratio_w, const int n, const int c, const int out_d, const int out_h, const int out_w, const bool align_corners, const DataLayout data_layout) { auto input_grad_t = EigenTensor<T, 5>::From(*input_grad); auto output_grad_t = EigenTensor<T, 5>::From(output_grad); for (int d = 0; d < out_d; d++) { int in_d = (align_corners) ? static_cast<int>(ratio_d * d + 0.5) : static_cast<int>(ratio_d * d); for (int k = 0; k < out_h; k++) { // loop for images int in_k = (align_corners) ? static_cast<int>(ratio_h * k + 0.5) : static_cast<int>(ratio_h * k); for (int l = 0; l < out_w; l++) { int in_l = (align_corners) ? static_cast<int>(ratio_w * l + 0.5) : static_cast<int>(ratio_w * l); for (int i = 0; i < n; i++) { // loop for batches for (int j = 0; j < c; j++) { // loop for channels if (data_layout == DataLayout::kNCHW) { input_grad_t(i, j, in_d, in_k, in_l) += output_grad_t(i, j, d, k, l); } else { input_grad_t(i, in_d, in_k, in_l, j) += output_grad_t(i, d, k, l, j); } } } } } } } template <typename T> static void BilinearInterpolationGrad( const Tensor& output_grad, Tensor* input_grad, const float ratio_h, const float ratio_w, const int in_h, const int in_w, const int n, const int c, const int out_h, const int out_w, const bool align_corners, const int align_mode, const DataLayout data_layout) { auto input_grad_t = EigenTensor<T, 4>::From(*input_grad); auto output_grad_t = EigenTensor<T, 4>::From(output_grad); bool align_flag = (align_mode == 0 && !align_corners); for (int k = 0; k < out_h; k++) { // loop for images int y_n = align_flag ? static_cast<int>(ratio_h * (k + 0.5) - 0.5) : static_cast<int>(ratio_h * k); y_n = (y_n > 0) ? y_n : 0; int y_s = (y_n + 1) < (in_h - 1) ? (y_n + 1) : (in_h - 1); float idx_src_y = ratio_h * (k + 0.5) - 0.5; idx_src_y = (idx_src_y > 0) ? idx_src_y : 0; float d_n = align_flag ? idx_src_y - y_n : ratio_h * k - y_n; float d_s = 1.f - d_n; for (int l = 0; l < out_w; l++) { int x_w = align_flag ? static_cast<int>(ratio_w * (l + 0.5) - 0.5) : static_cast<int>(ratio_w * l); x_w = (x_w > 0) ? x_w : 0; int x_e = (x_w + 1) < (in_w - 1) ? (x_w + 1) : (in_w - 1); float idx_src_x = ratio_w * (l + 0.5) - 0.5; idx_src_x = (idx_src_x > 0) ? idx_src_x : 0; float d_w = align_flag ? idx_src_x - x_w : ratio_w * l - x_w; float d_e = 1.f - d_w; for (int i = 0; i < n; i++) { // loop for batches for (int j = 0; j < c; j++) { // loop for channels // bilinear interpolation grad if (data_layout == DataLayout::kNCHW) { const T grad = output_grad_t(i, j, k, l); input_grad_t(i, j, y_n, x_w) += static_cast<T>(grad * d_s * d_e); input_grad_t(i, j, y_s, x_w) += static_cast<T>(grad * d_n * d_e); input_grad_t(i, j, y_n, x_e) += static_cast<T>(grad * d_s * d_w); input_grad_t(i, j, y_s, x_e) += static_cast<T>(grad * d_n * d_w); } else { const T grad = output_grad_t(i, k, l, j); input_grad_t(i, y_n, x_w, j) += static_cast<T>(grad * d_s * d_e); input_grad_t(i, y_s, x_w, j) += static_cast<T>(grad * d_n * d_e); input_grad_t(i, y_n, x_e, j) += static_cast<T>(grad * d_s * d_w); input_grad_t(i, y_s, x_e, j) += static_cast<T>(grad * d_n * d_w); } } } } } } template <typename T> static void TrilinearInterpolationGrad( const Tensor& output_grad, Tensor* input_grad, const float ratio_d, const float ratio_h, const float ratio_w, const int in_d, const int in_h, const int in_w, const int n, const int c, const int out_d, const int out_h, const int out_w, const bool align_corners, const int align_mode, const DataLayout data_layout) { auto input_grad_t = EigenTensor<T, 5>::From(*input_grad); auto output_grad_t = EigenTensor<T, 5>::From(output_grad); bool align_flag = (align_mode == 0 && !align_corners); for (int j = 0; j < out_d; j++) { // loop for D int t_f = align_flag ? static_cast<int>(ratio_d * (j + 0.5) - 0.5) : static_cast<int>(ratio_d * j); t_f = (t_f > 0) ? t_f : 0; int t_b = (t_f + 1) < (in_d - 1) ? (t_f + 1) : (in_d - 1); float idx_src_t = ratio_d * (j + 0.5) - 0.5; idx_src_t = (idx_src_t > 0) ? idx_src_t : 0; float d_f = align_flag ? idx_src_t - t_f : ratio_d * j - t_f; float d_b = 1.f - d_f; for (int k = 0; k < out_h; k++) { // loop for H int y_n = align_flag ? static_cast<int>(ratio_h * (k + 0.5) - 0.5) : static_cast<int>(ratio_h * k); y_n = (y_n > 0) ? y_n : 0; int y_s = (y_n + 1) < (in_h - 1) ? (y_n + 1) : (in_h - 1); float idx_src_y = ratio_h * (k + 0.5) - 0.5; idx_src_y = (idx_src_y > 0) ? idx_src_y : 0; float d_n = align_flag ? idx_src_y - y_n : ratio_h * k - y_n; float d_s = 1.f - d_n; for (int l = 0; l < out_w; l++) { // loop for W int x_w = align_flag ? static_cast<int>(ratio_w * (l + 0.5) - 0.5) : static_cast<int>(ratio_w * l); x_w = (x_w > 0) ? x_w : 0; int x_e = (x_w + 1) < (in_w - 1) ? (x_w + 1) : (in_w - 1); float idx_src_x = ratio_w * (l + 0.5) - 0.5; idx_src_x = (idx_src_x > 0) ? idx_src_x : 0; float d_w = align_flag ? idx_src_x - x_w : ratio_w * l - x_w; float d_e = 1.f - d_w; for (int b = 0; b < n; b++) { // loop for batches for (int i = 0; i < c; i++) { // loop for channels // trilinear interpolation grad if (data_layout == DataLayout::kNCHW) { const T grad = output_grad_t(b, i, j, k, l); input_grad_t(b, i, t_f, y_n, x_w) += static_cast<T>(grad * d_b * d_s * d_e); input_grad_t(b, i, t_f, y_n, x_e) += static_cast<T>(grad * d_b * d_s * d_w); input_grad_t(b, i, t_f, y_s, x_w) += static_cast<T>(grad * d_b * d_n * d_e); input_grad_t(b, i, t_f, y_s, x_e) += static_cast<T>(grad * d_b * d_n * d_w); input_grad_t(b, i, t_b, y_n, x_w) += static_cast<T>(grad * d_f * d_s * d_e); input_grad_t(b, i, t_b, y_n, x_e) += static_cast<T>(grad * d_f * d_s * d_w); input_grad_t(b, i, t_b, y_s, x_w) += static_cast<T>(grad * d_f * d_n * d_e); input_grad_t(b, i, t_b, y_s, x_e) += static_cast<T>(grad * d_f * d_n * d_w); } else { const T grad = output_grad_t(b, j, k, l, i); input_grad_t(b, t_f, y_n, x_w, i) += static_cast<T>(grad * d_b * d_s * d_e); input_grad_t(b, t_f, y_n, x_e, i) += static_cast<T>(grad * d_b * d_s * d_w); input_grad_t(b, t_f, y_s, x_w, i) += static_cast<T>(grad * d_b * d_n * d_e); input_grad_t(b, t_f, y_s, x_e, i) += static_cast<T>(grad * d_b * d_n * d_w); input_grad_t(b, t_b, y_n, x_w, i) += static_cast<T>(grad * d_f * d_s * d_e); input_grad_t(b, t_b, y_n, x_e, i) += static_cast<T>(grad * d_f * d_s * d_w); input_grad_t(b, t_b, y_s, x_w, i) += static_cast<T>(grad * d_f * d_n * d_e); input_grad_t(b, t_b, y_s, x_e, i) += static_cast<T>(grad * d_f * d_n * d_w); } } } } } } } template <typename T> static void BicubicInterpolationGrad(const Tensor& output_grad, Tensor* input_grad, const float ratio_h, const float ratio_w, const int in_h, const int in_w, const int n, const int c, const int out_h, const int out_w, const bool align_corners, const DataLayout data_layout) { auto input_grad_t = EigenTensor<T, 4>::From(*input_grad); auto output_grad_t = EigenTensor<T, 4>::From(output_grad); for (int k = 0; k < out_h; k++) { // loop for images T y_n = align_corners ? static_cast<T>(ratio_h * k) : static_cast<T>(ratio_h * (k + 0.5) - 0.5); int input_y = floorf(y_n); T y_t = y_n - input_y; for (int l = 0; l < out_w; l++) { T x_n = align_corners ? static_cast<T>(ratio_w * l) : static_cast<T>(ratio_w * (l + 0.5) - 0.5); int input_x = floorf(x_n); T x_t = x_n - input_x; T x_coeffs[4]; T y_coeffs[4]; get_cubic_upsample_coefficients<T>(x_coeffs, x_t); get_cubic_upsample_coefficients<T>(y_coeffs, y_t); for (int i = 0; i < n; i++) { // loop for batches for (int j = 0; j < c; j++) { // loop for channels // bicubic interpolation grad for (int ii = 0; ii < 4; ii++) { for (int jj = 0; jj < 4; jj++) { int access_x = std::max(std::min(input_x - 1 + ii, in_w - 1), static_cast<int>(0)); int access_y = std::max(std::min(input_y - 1 + jj, in_h - 1), static_cast<int>(0)); if (data_layout == DataLayout::kNCHW) { T grad = output_grad_t(i, j, k, l); input_grad_t(i, j, access_y, access_x) += grad * y_coeffs[jj] * x_coeffs[ii]; } else { T grad = output_grad_t(i, k, l, j); input_grad_t(i, access_y, access_x, j) += grad * y_coeffs[jj] * x_coeffs[ii]; } } } } } } } } template <typename T> static void Interpolate1DCPUFwd(const framework::ExecutionContext& ctx, const Tensor& input, Tensor* output) { const std::string data_layout_str = ctx.Attr<std::string>("data_layout"); const DataLayout data_layout = framework::StringToDataLayout(data_layout_str); int n, c, in_d, in_h, in_w; ExtractNCDWH(input.dims(), data_layout, &n, &c, &in_d, &in_h, &in_w); auto interp_method = ctx.Attr<std::string>("interp_method"); bool align_corners = ctx.Attr<bool>("align_corners"); int align_mode = ctx.Attr<int>("align_mode"); int out_w = ctx.Attr<int>("out_w"); auto list_new_size_tensor = ctx.MultiInput<framework::Tensor>("SizeTensor"); float scale_w = -1.; if (list_new_size_tensor.size() > 0) { // have size tensor auto new_size = get_new_shape(list_new_size_tensor); out_w = new_size[0]; } else { // float scale_w = -1; auto scale_tensor = ctx.Input<Tensor>("Scale"); auto scale = ctx.Attr<std::vector<float>>("scale"); if (scale_tensor != nullptr) { auto scale_data = get_new_data_from_tensor<float>(scale_tensor); scale_w = scale_data[0]; PADDLE_ENFORCE_EQ( scale_w > 0, true, platform::errors::InvalidArgument( "The scale_w in input 'Scale' Tensor of Operator(interpolate) " "should be greater than 0, but received value is %d.", scale_w)); } else { if (scale.size() > 0) { scale_w = scale[0]; PADDLE_ENFORCE_EQ( scale_w > 0, true, platform::errors::InvalidArgument( "The scale_w in Attr(scale) of Operator(interpolate) " "should be greater than 0, but received value is %d.", scale_w)); } } if (scale_w > 0.) { out_w = static_cast<int>(in_w * scale_w); } auto out_size = ctx.Input<Tensor>("OutSize"); if (out_size != nullptr) { auto out_size_data = get_new_data_from_tensor<int>(out_size); out_w = out_size_data[0]; } } PADDLE_ENFORCE_GT(out_w, 0, platform::errors::InvalidArgument( "out_w in Attr(out_shape) of Op(interpolate) " "should be greater than 0.")); framework::DDim dim_out; if (data_layout == DataLayout::kNCHW) { dim_out = {n, c, out_w}; } else { dim_out = {n, out_w, c}; } output->mutable_data<T>(dim_out, ctx.GetPlace()); if (in_w == out_w) { framework::TensorCopy(input, ctx.GetPlace(), output); return; } float ratio_w = 0.f; if (out_w > 1) { float new_scale_w = 0.f; new_scale_w = (scale_w > 0) ? static_cast<float>(1. / scale_w) : static_cast<float>(in_w) / out_w; ratio_w = (align_corners) ? static_cast<float>(in_w - 1) / (out_w - 1) : static_cast<float>(new_scale_w); } if ("linear" == interp_method) { LinearInterpolation<T>(input, output, ratio_w, in_w, n, c, out_w, align_corners, align_mode, data_layout); } } template <typename T> static void Interpolate2DCPUFwd(const framework::ExecutionContext& ctx, const Tensor& input, Tensor* output) { const std::string data_layout_str = ctx.Attr<std::string>("data_layout"); const DataLayout data_layout = framework::StringToDataLayout(data_layout_str); int n, c, in_d, in_h, in_w; ExtractNCDWH(input.dims(), data_layout, &n, &c, &in_d, &in_h, &in_w); auto interp_method = ctx.Attr<std::string>("interp_method"); bool align_corners = ctx.Attr<bool>("align_corners"); int align_mode = ctx.Attr<int>("align_mode"); int out_h = ctx.Attr<int>("out_h"); int out_w = ctx.Attr<int>("out_w"); float scale_h = -1; float scale_w = -1; auto list_new_size_tensor = ctx.MultiInput<framework::Tensor>("SizeTensor"); if (list_new_size_tensor.size() > 0) { // have size tensor auto new_size = get_new_shape(list_new_size_tensor); out_h = new_size[0]; out_w = new_size[1]; } else { auto scale_tensor = ctx.Input<Tensor>("Scale"); auto scale = ctx.Attr<std::vector<float>>("scale"); if (scale_tensor != nullptr) { auto scale_data = get_new_data_from_tensor<float>(scale_tensor); if (scale_data.size() > 1) { scale_h = scale_data[0]; scale_w = scale_data[1]; } else { scale_h = scale_data[0]; scale_w = scale_data[0]; } PADDLE_ENFORCE_EQ( scale_w > 0, true, platform::errors::InvalidArgument( "The scale_w in input 'Scale' Tensor of Operator(interpolate) " "should be greater than 0, but received value is %d.", scale_w)); PADDLE_ENFORCE_EQ( scale_h > 0, true, platform::errors::InvalidArgument( "The scale_h in input 'Scale' Tensor of Operator(interpolate) " "should be greater than 0, but received value is %d.", scale_h)); } else { if (scale.size() > 1) { scale_h = scale[0]; scale_w = scale[1]; PADDLE_ENFORCE_EQ( scale_w > 0, true, platform::errors::InvalidArgument( "The scale_w in Attr(scale) of Operator(interpolate) " "should be greater than 0, but received value is %d.", scale_w)); PADDLE_ENFORCE_EQ( scale_h > 0, true, platform::errors::InvalidArgument( "The scale_h in Attr(scale) of Operator(interpolate) " "should be greater than 0, but received value is %d.", scale_h)); } } if (scale_h > 0. && scale_w > 0.) { out_h = static_cast<int>(in_h * scale_h); out_w = static_cast<int>(in_w * scale_w); } auto out_size = ctx.Input<Tensor>("OutSize"); if (out_size != nullptr) { auto out_size_data = get_new_data_from_tensor<int>(out_size); out_h = out_size_data[0]; out_w = out_size_data[1]; } } PADDLE_ENFORCE_GT(out_h, 0, platform::errors::InvalidArgument( "out_h in Attr(out_shape) of Op(interpolate) " "should be greater than 0.")); PADDLE_ENFORCE_GT(out_w, 0, platform::errors::InvalidArgument( "out_w in Attr(out_shape) of Op(interpolate) " "should be greater than 0.")); framework::DDim dim_out; if (data_layout == DataLayout::kNCHW) { dim_out = {n, c, out_h, out_w}; } else { dim_out = {n, out_h, out_w, c}; } output->mutable_data<T>(dim_out, ctx.GetPlace()); if (in_h == out_h && in_w == out_w) { framework::TensorCopy(input, ctx.GetPlace(), output); return; } float ratio_h = 0.f; float ratio_w = 0.f; if (out_h > 1) { float new_scale_h = 0.f; new_scale_h = (scale_h > 0) ? static_cast<float>(1. / scale_h) : static_cast<float>(in_h) / out_h; ratio_h = (align_corners) ? static_cast<float>(in_h - 1) / (out_h - 1) : static_cast<float>(new_scale_h); } if (out_w > 1) { float new_scale_w = 0.f; new_scale_w = (scale_w > 0) ? static_cast<float>(1. / scale_w) : static_cast<float>(in_w) / out_w; ratio_w = (align_corners) ? static_cast<float>(in_w - 1) / (out_w - 1) : static_cast<float>(new_scale_w); } if ("bilinear" == interp_method) { BilinearInterpolation<T>(input, output, ratio_h, ratio_w, in_h, in_w, n, c, out_h, out_w, align_corners, align_mode, data_layout); } else if ("nearest" == interp_method) { NearestNeighborInterpolate<T>(input, output, ratio_h, ratio_w, n, c, out_h, out_w, align_corners, data_layout); } else if ("bicubic" == interp_method) { BicubicInterpolation<T>(input, output, ratio_h, ratio_w, in_h, in_w, n, c, out_h, out_w, align_corners, data_layout); } } template <typename T> static void Interpolate3DCPUFwd(const framework::ExecutionContext& ctx, const Tensor& input, Tensor* output) { const std::string data_layout_str = ctx.Attr<std::string>("data_layout"); const DataLayout data_layout = framework::StringToDataLayout(data_layout_str); int n, c, in_d, in_h, in_w; ExtractNCDWH(input.dims(), data_layout, &n, &c, &in_d, &in_h, &in_w); auto interp_method = ctx.Attr<std::string>("interp_method"); bool align_corners = ctx.Attr<bool>("align_corners"); int align_mode = ctx.Attr<int>("align_mode"); int out_d = ctx.Attr<int>("out_d"); int out_h = ctx.Attr<int>("out_h"); int out_w = ctx.Attr<int>("out_w"); float scale_d = -1; float scale_h = -1; float scale_w = -1; auto list_new_size_tensor = ctx.MultiInput<framework::Tensor>("SizeTensor"); if (list_new_size_tensor.size() > 0) { // have size tensor auto new_size = get_new_shape(list_new_size_tensor); out_d = new_size[0]; out_h = new_size[1]; out_w = new_size[2]; } else { auto scale_tensor = ctx.Input<Tensor>("Scale"); auto scale = ctx.Attr<std::vector<float>>("scale"); if (scale_tensor != nullptr) { auto scale_data = get_new_data_from_tensor<float>(scale_tensor); if (scale_data.size() > 1) { scale_d = scale_data[0]; scale_h = scale_data[1]; scale_w = scale_data[2]; } else { scale_d = scale_data[0]; scale_h = scale_data[0]; scale_w = scale_data[0]; } PADDLE_ENFORCE_EQ( scale_w > 0, true, platform::errors::InvalidArgument( "The scale_w in input 'Scale' Tensor of Operator(interpolate) " "should be greater than 0, but received value is %d.", scale_w)); PADDLE_ENFORCE_EQ( scale_h > 0, true, platform::errors::InvalidArgument( "The scale_h in input 'Scale' Tensor of Operator(interpolate) " "should be greater than 0, but received value is %d.", scale_h)); PADDLE_ENFORCE_EQ( scale_d > 0, true, platform::errors::InvalidArgument( "The scale_d in input 'Scale' Tensor of Operator(interpolate) " "should be greater than 0, but received value is %d.", scale_d)); } else { if (scale.size() > 1) { scale_d = scale[0]; scale_h = scale[1]; scale_w = scale[2]; PADDLE_ENFORCE_EQ( scale_w > 0, true, platform::errors::InvalidArgument( "The scale_w in Attr(scale) of Operator(interpolate) " "should be greater than 0, but received value is %d.", scale_w)); PADDLE_ENFORCE_EQ( scale_h > 0, true, platform::errors::InvalidArgument( "The scale_h in Attr(scale) of Operator(interpolate) " "should be greater than 0, but received value is %d.", scale_h)); PADDLE_ENFORCE_EQ( scale_d > 0, true, platform::errors::InvalidArgument( "The scale_d in Attr(scale) of Operator(interpolate) " "should be greater than 0, but received value is %d.", scale_d)); } } if (scale_w > 0. && scale_h > 0. && scale_d > 0.) { out_d = static_cast<int>(in_d * scale_d); out_h = static_cast<int>(in_h * scale_h); out_w = static_cast<int>(in_w * scale_w); } auto out_size = ctx.Input<Tensor>("OutSize"); if (out_size != nullptr) { auto out_size_data = get_new_data_from_tensor<int>(out_size); out_d = out_size_data[0]; out_h = out_size_data[1]; out_w = out_size_data[2]; } } PADDLE_ENFORCE_GT(out_d, 0, platform::errors::InvalidArgument( "out_d in Attr(out_shape) of Op(interpolate) " "should be greater than 0.")); PADDLE_ENFORCE_GT(out_h, 0, platform::errors::InvalidArgument( "out_h in Attr(out_shape) of Op(interpolate) " "should be greater than 0.")); PADDLE_ENFORCE_GT(out_w, 0, platform::errors::InvalidArgument( "out_w in Attr(out_shape) of Op(interpolate) " "should be greater than 0.")); framework::DDim dim_out; if (data_layout == DataLayout::kNCHW) { dim_out = {n, c, out_d, out_h, out_w}; } else { dim_out = {n, out_d, out_h, out_w, c}; } output->mutable_data<T>(dim_out, ctx.GetPlace()); if (in_d == out_d && in_h == out_h && in_w == out_w) { framework::TensorCopy(input, ctx.GetPlace(), output); return; } float ratio_d = 0.f; float ratio_h = 0.f; float ratio_w = 0.f; if (out_d > 1) { float new_scale_d = 0.f; new_scale_d = (scale_d > 0) ? static_cast<float>(1. / scale_d) : static_cast<float>(in_d) / out_d; ratio_d = (align_corners) ? static_cast<float>(in_d - 1) / (out_d - 1) : static_cast<float>(new_scale_d); } if (out_h > 1) { float new_scale_h = 0.f; new_scale_h = (scale_h > 0) ? static_cast<float>(1. / scale_h) : static_cast<float>(in_h) / out_h; ratio_h = (align_corners) ? static_cast<float>(in_h - 1) / (out_h - 1) : static_cast<float>(new_scale_h); } if (out_w > 1) { float new_scale_w = 0.f; new_scale_w = (scale_w > 0) ? static_cast<float>(1. / scale_w) : static_cast<float>(in_w) / out_w; ratio_w = (align_corners) ? static_cast<float>(in_w - 1) / (out_w - 1) : static_cast<float>(new_scale_w); } if ("trilinear" == interp_method) { TrilinearInterpolation<T>(input, output, ratio_d, ratio_h, ratio_w, in_d, in_h, in_w, n, c, out_d, out_h, out_w, align_corners, align_mode, data_layout); } else if ("nearest" == interp_method) { NearestNeighbor3DInterpolate<T>(input, output, ratio_d, ratio_h, ratio_w, n, c, out_d, out_h, out_w, align_corners, data_layout); } } template <typename T> static void Interpolate1DCPUBwd(const framework::ExecutionContext& ctx, Tensor* input_grad, const Tensor& output_grad) { auto* input = ctx.Input<Tensor>("X"); const std::string data_layout_str = ctx.Attr<std::string>("data_layout"); const DataLayout data_layout = framework::StringToDataLayout(data_layout_str); int n, c, in_d, in_h, in_w; ExtractNCDWH(input->dims(), data_layout, &n, &c, &in_d, &in_h, &in_w); auto interp_method = ctx.Attr<std::string>("interp_method"); bool align_corners = ctx.Attr<bool>("align_corners"); int align_mode = ctx.Attr<int>("align_mode"); int out_w = ctx.Attr<int>("out_w"); float scale_w = -1.0; auto scale_tensor = ctx.Input<Tensor>("Scale"); auto scale = ctx.Attr<std::vector<float>>("scale"); if (scale_tensor != nullptr) { auto scale_data = get_new_data_from_tensor<float>(scale_tensor); scale_w = scale_data[0]; PADDLE_ENFORCE_EQ( scale_w > 0, true, platform::errors::InvalidArgument( "The scale_w in input 'Scale' Tensor of Operator(interpolate) " "should be greater than 0, but received value is %d.", scale_w)); } else { if (scale.size() > 0) { scale_w = scale[0]; PADDLE_ENFORCE_EQ( scale_w > 0, true, platform::errors::InvalidArgument( "The scale_w in Attr(scale) of Operator(interpolate) " "should be greater than 0, but received value is %d.", scale_w)); } } if (scale_w > 0.) { out_w = static_cast<int>(in_w * scale_w); } auto out_size = ctx.Input<Tensor>("OutSize"); if (out_size != nullptr) { auto out_size_data = get_new_data_from_tensor<int>(out_size); out_w = out_size_data[0]; } auto list_new_size_tensor = ctx.MultiInput<framework::Tensor>("SizeTensor"); if (list_new_size_tensor.size() > 0) { // have size tensor auto new_size = get_new_shape(list_new_size_tensor); out_w = new_size[0]; } framework::DDim dim_grad; if (data_layout == DataLayout::kNCHW) { dim_grad = {n, c, in_w}; } else { dim_grad = {n, in_w, c}; } input_grad->mutable_data<T>(dim_grad, ctx.GetPlace()); auto& device_ctx = ctx.template device_context<platform::CPUDeviceContext>(); pten::funcs::SetConstant<platform::CPUDeviceContext, T> zero; zero(device_ctx, input_grad, static_cast<T>(0.0)); if (in_w == out_w) { framework::TensorCopy(output_grad, ctx.GetPlace(), input_grad); return; } float ratio_w = 0.f; if (out_w > 1) { float new_scale_w = 0.f; new_scale_w = (scale_w > 0) ? static_cast<float>(1. / scale_w) : static_cast<float>(in_w) / out_w; ratio_w = (align_corners) ? static_cast<float>(in_w - 1) / (out_w - 1) : static_cast<float>(new_scale_w); } if ("linear" == interp_method) { LinearInterpolationGrad<T>(output_grad, input_grad, ratio_w, in_w, n, c, out_w, align_corners, align_mode, data_layout); } } template <typename T> static void Interpolate2DCPUBwd(const framework::ExecutionContext& ctx, Tensor* input_grad, const Tensor& output_grad) { auto* input = ctx.Input<Tensor>("X"); const std::string data_layout_str = ctx.Attr<std::string>("data_layout"); const DataLayout data_layout = framework::StringToDataLayout(data_layout_str); int n, c, in_d, in_h, in_w; ExtractNCDWH(input->dims(), data_layout, &n, &c, &in_d, &in_h, &in_w); auto interp_method = ctx.Attr<std::string>("interp_method"); bool align_corners = ctx.Attr<bool>("align_corners"); int align_mode = ctx.Attr<int>("align_mode"); int out_h = ctx.Attr<int>("out_h"); int out_w = ctx.Attr<int>("out_w"); float scale_h = -1; float scale_w = -1; auto scale_tensor = ctx.Input<Tensor>("Scale"); auto scale = ctx.Attr<std::vector<float>>("scale"); if (scale_tensor != nullptr) { auto scale_data = get_new_data_from_tensor<float>(scale_tensor); if (scale_data.size() > 1) { scale_h = scale_data[0]; scale_w = scale_data[1]; } else { scale_w = scale_data[0]; scale_h = scale_data[0]; } PADDLE_ENFORCE_EQ( scale_w > 0, true, platform::errors::InvalidArgument( "The scale_w in input 'Scale' Tensor of Operator(interpolate) " "should be greater than 0, but received value is %d.", scale_w)); PADDLE_ENFORCE_EQ( scale_h > 0, true, platform::errors::InvalidArgument( "The scale_h in input 'Scale' Tensor of Operator(interpolate) " "should be greater than 0, but received value is %d.", scale_h)); } else { if (scale.size() > 1) { scale_h = scale[0]; scale_w = scale[1]; PADDLE_ENFORCE_EQ( scale_w > 0, true, platform::errors::InvalidArgument( "The scale_w in Attr(scale) of Operator(interpolate) " "should be greater than 0, but received value is %d.", scale_w)); PADDLE_ENFORCE_EQ( scale_h > 0, true, platform::errors::InvalidArgument( "The scale_h in Attr(scale) of Operator(interpolate) " "should be greater than 0, but received value is %d.", scale_h)); } } if (scale_h > 0. && scale_w > 0.) { out_h = static_cast<int>(in_h * scale_h); out_w = static_cast<int>(in_w * scale_w); } auto out_size = ctx.Input<Tensor>("OutSize"); if (out_size != nullptr) { auto out_size_data = get_new_data_from_tensor<int>(out_size); out_h = out_size_data[0]; out_w = out_size_data[1]; } auto list_new_size_tensor = ctx.MultiInput<framework::Tensor>("SizeTensor"); if (list_new_size_tensor.size() > 0) { // have size tensor auto new_size = get_new_shape(list_new_size_tensor); out_h = new_size[0]; out_w = new_size[1]; } framework::DDim dim_grad; if (data_layout == DataLayout::kNCHW) { dim_grad = {n, c, in_h, in_w}; } else { dim_grad = {n, in_h, in_w, c}; } input_grad->mutable_data<T>(dim_grad, ctx.GetPlace()); auto& device_ctx = ctx.template device_context<platform::CPUDeviceContext>(); pten::funcs::SetConstant<platform::CPUDeviceContext, T> zero; zero(device_ctx, input_grad, static_cast<T>(0.0)); if (in_h == out_h && in_w == out_w) { framework::TensorCopy(output_grad, ctx.GetPlace(), input_grad); return; } float ratio_h = 0.f; float ratio_w = 0.f; if (out_h > 1) { float new_scale_h = 0.f; new_scale_h = (scale_h > 0) ? static_cast<float>(1. / scale_h) : static_cast<float>(in_h) / out_h; ratio_h = (align_corners) ? static_cast<float>(in_h - 1) / (out_h - 1) : static_cast<float>(new_scale_h); } if (out_w > 1) { float new_scale_w = 0.f; new_scale_w = (scale_w > 0) ? static_cast<float>(1. / scale_w) : static_cast<float>(in_w) / out_w; ratio_w = (align_corners) ? static_cast<float>(in_w - 1) / (out_w - 1) : static_cast<float>(new_scale_w); } if ("bilinear" == interp_method) { BilinearInterpolationGrad<T>(output_grad, input_grad, ratio_h, ratio_w, in_h, in_w, n, c, out_h, out_w, align_corners, align_mode, data_layout); } else if ("nearest" == interp_method) { NearestNeighborInterpolateGrad<T>(output_grad, input_grad, ratio_h, ratio_w, n, c, out_h, out_w, align_corners, data_layout); } else if ("bicubic" == interp_method) { BicubicInterpolationGrad<T>(output_grad, input_grad, ratio_h, ratio_w, in_h, in_w, n, c, out_h, out_w, align_corners, data_layout); } } template <typename T> static void Interpolate3DCPUBwd(const framework::ExecutionContext& ctx, Tensor* input_grad, const Tensor output_grad) { auto* input = ctx.Input<Tensor>("X"); const std::string data_layout_str = ctx.Attr<std::string>("data_layout"); const DataLayout data_layout = framework::StringToDataLayout(data_layout_str); int n, c, in_d, in_h, in_w; ExtractNCDWH(input->dims(), data_layout, &n, &c, &in_d, &in_h, &in_w); auto interp_method = ctx.Attr<std::string>("interp_method"); bool align_corners = ctx.Attr<bool>("align_corners"); int align_mode = ctx.Attr<int>("align_mode"); int out_d = ctx.Attr<int>("out_d"); int out_h = ctx.Attr<int>("out_h"); int out_w = ctx.Attr<int>("out_w"); float scale_d = -1; float scale_h = -1; float scale_w = -1; auto scale_tensor = ctx.Input<Tensor>("Scale"); auto scale = ctx.Attr<std::vector<float>>("scale"); if (scale_tensor != nullptr) { auto scale_data = get_new_data_from_tensor<float>(scale_tensor); if (scale_data.size() > 1) { scale_d = scale_data[0]; scale_h = scale_data[1]; scale_w = scale_data[2]; } else { scale_d = scale_data[0]; scale_h = scale_data[0]; scale_w = scale_data[0]; } PADDLE_ENFORCE_EQ( scale_w > 0, true, platform::errors::InvalidArgument( "The scale_w in input 'Scale' Tensor of Operator(interpolate) " "should be greater than 0, but received value is %d.", scale_w)); PADDLE_ENFORCE_EQ( scale_h > 0, true, platform::errors::InvalidArgument( "The scale_h in input 'Scale' Tensor of Operator(interpolate) " "should be greater than 0, but received value is %d.", scale_h)); PADDLE_ENFORCE_EQ( scale_d > 0, true, platform::errors::InvalidArgument( "The scale_d in input 'Scale' Tensor of Operator(interpolate) " "should be greater than 0, but received value is %d.", scale_d)); } else { if (scale.size() > 1) { scale_d = scale[0]; scale_h = scale[1]; scale_w = scale[2]; PADDLE_ENFORCE_EQ( scale_w > 0, true, platform::errors::InvalidArgument( "The scale_w in Attr(scale) of Operator(interpolate) " "should be greater than 0, but received value is %d.", scale_w)); PADDLE_ENFORCE_EQ( scale_h > 0, true, platform::errors::InvalidArgument( "The scale_h in Attr(scale) of Operator(interpolate) " "should be greater than 0, but received value is %d.", scale_h)); PADDLE_ENFORCE_EQ( scale_d > 0, true, platform::errors::InvalidArgument( "The scale_d in Attr(scale) of Operator(interpolate) " "should be greater than 0, but received value is %d.", scale_d)); } } if (scale_d > 0. && scale_h > 0. && scale_w > 0.) { out_d = static_cast<int>(in_d * scale_d); out_h = static_cast<int>(in_h * scale_h); out_w = static_cast<int>(in_w * scale_w); } auto out_size = ctx.Input<Tensor>("OutSize"); if (out_size != nullptr) { auto out_size_data = get_new_data_from_tensor<int>(out_size); out_d = out_size_data[0]; out_h = out_size_data[1]; out_w = out_size_data[2]; } auto list_new_size_tensor = ctx.MultiInput<framework::Tensor>("SizeTensor"); if (list_new_size_tensor.size() > 0) { // have size tensor auto new_size = get_new_shape(list_new_size_tensor); out_d = new_size[0]; out_h = new_size[1]; out_w = new_size[2]; } framework::DDim dim_grad; if (data_layout == DataLayout::kNCHW) { dim_grad = {n, c, in_d, in_h, in_w}; } else { dim_grad = {n, in_d, in_h, in_w, c}; } input_grad->mutable_data<T>(dim_grad, ctx.GetPlace()); auto& device_ctx = ctx.template device_context<platform::CPUDeviceContext>(); pten::funcs::SetConstant<platform::CPUDeviceContext, T> zero; zero(device_ctx, input_grad, static_cast<T>(0.0)); if (in_d == out_d && in_h == out_h && in_w == out_w) { framework::TensorCopy(output_grad, ctx.GetPlace(), input_grad); return; } float ratio_d = 0.f; float ratio_h = 0.f; float ratio_w = 0.f; if (out_d > 1) { float new_scale_d = 0.f; new_scale_d = (scale_d > 0) ? static_cast<float>(1. / scale_d) : static_cast<float>(in_d) / out_d; ratio_d = (align_corners) ? static_cast<float>(in_d - 1) / (out_d - 1) : static_cast<float>(new_scale_d); } if (out_h > 1) { float new_scale_h = 0.f; new_scale_h = (scale_h > 0) ? static_cast<float>(1. / scale_h) : static_cast<float>(in_h) / out_h; ratio_h = (align_corners) ? static_cast<float>(in_h - 1) / (out_h - 1) : static_cast<float>(new_scale_h); } if (out_w > 1) { float new_scale_w = 0.f; new_scale_w = (scale_w > 0) ? static_cast<float>(1. / scale_w) : static_cast<float>(in_w) / out_w; ratio_w = (align_corners) ? static_cast<float>(in_w - 1) / (out_w - 1) : static_cast<float>(new_scale_w); } if ("trilinear" == interp_method) { TrilinearInterpolationGrad<T>( output_grad, input_grad, ratio_d, ratio_h, ratio_w, in_d, in_h, in_w, n, c, out_d, out_h, out_w, align_corners, align_mode, data_layout); } else if ("nearest" == interp_method) { NearestNeighbor3DInterpolateGrad<T>(output_grad, input_grad, ratio_d, ratio_h, ratio_w, n, c, out_d, out_h, out_w, align_corners, data_layout); } } template <typename T> class InterpolateV2Kernel : public framework::OpKernel<T> { public: void Compute(const framework::ExecutionContext& ctx) const override { auto* input = ctx.Input<Tensor>("X"); auto* output = ctx.Output<Tensor>("Out"); auto input_dims = input->dims(); if (input_dims.size() == 3) { // 1D interpolation Interpolate1DCPUFwd<T>(ctx, *input, output); } else if (input_dims.size() == 4) { // 2D interpolation Interpolate2DCPUFwd<T>(ctx, *input, output); } else if (input_dims.size() == 5) { // 3D interpolation Interpolate3DCPUFwd<T>(ctx, *input, output); } } }; template <typename T> class InterpolateV2GradKernel : public framework::OpKernel<T> { public: void Compute(const framework::ExecutionContext& ctx) const override { auto* input_grad = ctx.Output<Tensor>(framework::GradVarName("X")); auto* output_grad = ctx.Input<Tensor>(framework::GradVarName("Out")); auto output_grad_dims = output_grad->dims(); if (output_grad_dims.size() == 3) { // 1D interpolation grad Interpolate1DCPUBwd<T>(ctx, input_grad, *output_grad); } else if (output_grad_dims.size() == 4) { // 2D interpolation grad Interpolate2DCPUBwd<T>(ctx, input_grad, *output_grad); } else if (output_grad_dims.size() == 5) { // 3D interpolation grad Interpolate3DCPUBwd<T>(ctx, input_grad, *output_grad); } } }; } // namespace operators } // namespace paddle
DCSCTile.h
/****************************************************************************** * ** Copyright (c) 2016, Intel Corporation ** * ** All rights reserved. ** * ** ** * ** Redistribution and use in source and binary forms, with or without ** * ** modification, are permitted provided that the following conditions ** * ** are met: ** * ** 1. Redistributions of source code must retain the above copyright ** * ** notice, this list of conditions and the following disclaimer. ** * ** 2. Redistributions in binary form must reproduce the above copyright ** * ** notice, this list of conditions and the following disclaimer in the ** * ** documentation and/or other materials provided with the distribution. ** * ** 3. Neither the name of the copyright holder 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. * * ******************************************************************************/ /* Michael Anderson (Intel Corp.) * * ******************************************************************************/ #ifndef SRC_DCSCTILE_H_ #define SRC_DCSCTILE_H_ #include <string> #include <algorithm> #include <vector> template <typename T> bool compare_dcsc(const tedge_t<T> &a, const tedge_t<T> &b) { if (a.tile_id < b.tile_id) return true; else if (a.tile_id > b.tile_id) return false; if (a.dst < b.dst) return true; else if (a.dst > b.dst) return false; if (a.src < b.src) return true; else if (a.src > b.src) return false; return false; } template <typename T> class DCSCTile { public: std::string name; int m; int n; int nnz; int num_cols; int *row_inds; // row_inds is nnz int *col_ptrs; // col_ptrs is ncols int *col_indices; T *vals; int num_partitions; int *row_pointers; int *edge_pointers; int *col_starts; // col_indices is ncols // vals is nnz // row_pointers is the partitioning info (num_partitions+1) // edge_pointers is the partitioning info (num_partitions+1) // col_starts is the partitioning info (num_partitions+1) DCSCTile() : name("TEMP"), m(0), n(0), nnz(0), num_partitions(0) {} DCSCTile(int _m, int _n) : name("TEMP"), m(_m), n(_n), nnz(0), num_partitions(0) {} static void static_partition(int *&row_pointers, int m, int num_partitions, int round) { row_pointers = reinterpret_cast<int *>( _mm_malloc((num_partitions + 1) * sizeof(int), 64)); if (round == 1) { int rows_per_partition = m / num_partitions; int rows_leftover = m % num_partitions; row_pointers[0] = 0; int current_row = row_pointers[0] + rows_per_partition; for (int p = 1; p < num_partitions + 1; p++) { if (rows_leftover > 0) { current_row += 1; row_pointers[p] = current_row; current_row += rows_per_partition; rows_leftover--; } else { row_pointers[p] = current_row; current_row += rows_per_partition; } } } else { int n512 = std::max((m / round) / num_partitions, 1); int n_round = std::max(0, m / round - n512 * num_partitions); assert(n_round < num_partitions); row_pointers[0] = 0; for (int p = 1; p < num_partitions; p++) { row_pointers[p] = row_pointers[p - 1] + ((n_round > 0) ? ((n512 + 1) * round) : (n512 * round)); row_pointers[p] = std::min(row_pointers[p], m); if (n_round > 0) n_round--; } row_pointers[num_partitions] = m; } } static void set_edge_pointers(tedge_t<T> *edges, int *row_pointers, int **edge_pointers, int nnz, int num_partitions) { // Figure out edge pointers (*edge_pointers) = reinterpret_cast<int *>( _mm_malloc((num_partitions + 1) * sizeof(int), 64)); int p = 0; for (int edge_id = 0; edge_id < nnz; edge_id++) { while (edges[edge_id].src >= row_pointers[p]) { (*edge_pointers)[p] = edge_id; p++; } } (*edge_pointers)[p] = nnz; for (p = p + 1; p < num_partitions + 1; p++) { (*edge_pointers)[p] = nnz; } } DCSCTile(edge_t<T> *edges, int _m, int _n, int _nnz, int row_start, int col_start) : name("TEMP"), m(_m), n(_n), nnz(_nnz) { double _start_time = MPI_Wtime(); if (nnz > 0) { num_partitions = omp_get_max_threads() * 16; // Partition DCSCTile<T>::static_partition(row_pointers, this->m, num_partitions, 32); // Set partition IDs for each edge tedge_t<T> *p_edges = reinterpret_cast<tedge_t<T> *>( _mm_malloc((uint64_t)nnz * (uint64_t)sizeof(tedge_t<T>), 64)); std::cout << "num partitions: " << num_partitions << std::endl; double _ep_start = MPI_Wtime(); #pragma omp parallel for for (int i = 0; i < nnz; i++) { p_edges[i].src = edges[i].src - 1 - row_start; p_edges[i].dst = edges[i].dst - 1 - col_start; p_edges[i].val = edges[i].val; p_edges[i].tile_id = -1; int p_start = 0; int p_end = num_partitions-1; while(1) { int p_half = p_start + (p_end - p_start); // Check p_half if (p_edges[i].src >= row_pointers[p_half] && p_edges[i].src < row_pointers[p_half + 1]) { p_edges[i].tile_id = p_half; break; } if(p_edges[i].src < row_pointers[p_half]) p_end = p_half - 1; if(p_edges[i].src >= row_pointers[p_half+1]) p_start = p_half + 1; } #ifdef CHECK_BINARY_SEARCH for (int p = 0; p < num_partitions; p++) { if (p_edges[i].src >= row_pointers[p] && p_edges[i].src < row_pointers[p + 1]) { //p_edges[i].tile_id = p; //break; assert(p_edges[i].tile_id == p); } #endif assert(p_edges[i].tile_id >= 0); } double _ep_end = MPI_Wtime(); std::cout << "set_edge_pointers time: " << _ep_end - _ep_start << std::endl; // Sort // std::cout << "Sorting: " << (uint64_t)nnz << std::endl; // std::cout << "allocated : " << (uint64_t)nnz * (uint64_t)sizeof(tedge_t<T>) << std::endl; #pragma omp parallel for for(int i =0 ; i < nnz ; i++) { assert(p_edges[i].src >= 0); assert(p_edges[i].dst >= 0); assert(p_edges[i].src < _m); assert(p_edges[i].dst < _n); } __gnu_parallel::sort(p_edges, p_edges + nnz, compare_dcsc<T>); // Find edge pointers DCSCTile<T>::set_edge_pointers(p_edges, row_pointers, &edge_pointers, nnz, num_partitions); // Count columns int *ncols = reinterpret_cast<int *>(_mm_malloc(num_partitions * sizeof(int), 64)); col_starts = reinterpret_cast<int *>( _mm_malloc((num_partitions + 1) * sizeof(int), 64)); #pragma omp parallel for for (int p = 0; p < num_partitions; p++) { int current_column = -1; int num_columns = 0; for (int edge_id = edge_pointers[p]; edge_id < edge_pointers[p + 1]; edge_id++) { if (current_column < p_edges[edge_id].dst) { num_columns++; current_column = p_edges[edge_id].dst; } } ncols[p] = num_columns; } int total_cols = 0; for (int p = 0; p < num_partitions; p++) { col_starts[p] = total_cols; total_cols += ncols[p] + 1; } col_starts[num_partitions] = total_cols; num_cols = total_cols; // Build DCSC std::cout << "Allocating nnz vals: " << nnz << std::endl; vals = reinterpret_cast<T *>( _mm_malloc((uint64_t)nnz * (uint64_t)sizeof(T), 64)); row_inds = reinterpret_cast<int *>( _mm_malloc((uint64_t)nnz * (uint64_t)sizeof(int), 64)); col_indices = reinterpret_cast<int *>( _mm_malloc(col_starts[num_partitions] * sizeof(int), 64)); col_ptrs = reinterpret_cast<int *>( _mm_malloc(col_starts[num_partitions] * sizeof(int), 64)); #pragma omp parallel for for (int p = 0; p < num_partitions; p++) { T *val = vals + edge_pointers[p]; int *row_ind = row_inds + edge_pointers[p]; int *col_index = col_indices + col_starts[p]; int *col_ptr = col_ptrs + col_starts[p]; int current_column = -1; int current_column_num = -1; for (int edge_id = edge_pointers[p]; edge_id < edge_pointers[p + 1]; edge_id++) { val[edge_id - edge_pointers[p]] = p_edges[edge_id].val; row_ind[edge_id - edge_pointers[p]] = p_edges[edge_id].src; if (current_column < p_edges[edge_id].dst) { current_column_num++; current_column = p_edges[edge_id].dst; col_index[current_column_num] = current_column; col_ptr[current_column_num] = edge_id - edge_pointers[p]; } } int num_columns = col_starts[p + 1] - col_starts[p] - 1; col_ptr[num_columns] = edge_pointers[p + 1] - edge_pointers[p]; col_index[num_columns] = n + 1; } _mm_free(p_edges); _mm_free(ncols); } else { num_partitions = 0; } double _end_time = MPI_Wtime(); std::cout << "fn time: " << _end_time - _start_time << std::endl; } void get_edges(edge_t<T> *edges, int row_start, int col_start) { int nnzcnt = 0; for (int p = 0; p < num_partitions; p++) { for (int j = 0; j < (col_starts[p + 1] - col_starts[p]) - 1; j++) { int col_index = col_indices[col_starts[p] + j]; for (int nz_idx = col_ptrs[col_starts[p] + j]; nz_idx < col_ptrs[col_starts[p] + j + 1]; nz_idx++) { int row_ind = row_inds[edge_pointers[p] + nz_idx]; edges[nnzcnt].src = row_start + row_ind + 1; edges[nnzcnt].dst = col_start + col_index + 1; edges[nnzcnt].val = vals[edge_pointers[p] + nz_idx]; nnzcnt++; } } } assert(nnzcnt == this->nnz); } bool isEmpty() const { return nnz <= 0; } void clear() { if (!(isEmpty())) { } nnz = 0; } ~DCSCTile() {} void send_tile_metadata(int myrank, int dst_rank, int output_rank) { if (myrank == output_rank) std::cout << "Rank: " << myrank << " sending " << name << " to rank " << dst_rank << std::endl; MPI_Send(&(nnz), 1, MPI_INT, dst_rank, 0, MPI_COMM_WORLD); MPI_Send(&(m), 1, MPI_INT, dst_rank, 0, MPI_COMM_WORLD); MPI_Send(&(n), 1, MPI_INT, dst_rank, 0, MPI_COMM_WORLD); MPI_Send(&(num_partitions), 1, MPI_INT, dst_rank, 0, MPI_COMM_WORLD); MPI_Send(&(num_cols), 1, MPI_INT, dst_rank, 0, MPI_COMM_WORLD); } void recv_tile_metadata(int myrank, int src_rank, int output_rank) { if (!isEmpty()) { clear(); } MPI_Recv(&(nnz), 1, MPI_INT, src_rank, 0, MPI_COMM_WORLD, MPI_STATUS_IGNORE); MPI_Recv(&(m), 1, MPI_INT, src_rank, 0, MPI_COMM_WORLD, MPI_STATUS_IGNORE); MPI_Recv(&(n), 1, MPI_INT, src_rank, 0, MPI_COMM_WORLD, MPI_STATUS_IGNORE); MPI_Recv(&(num_partitions), 1, MPI_INT, src_rank, 0, MPI_COMM_WORLD, MPI_STATUS_IGNORE); MPI_Recv(&(num_cols), 1, MPI_INT, src_rank, 0, MPI_COMM_WORLD, MPI_STATUS_IGNORE); } void send_tile(int myrank, int dst_rank, int output_rank, bool block, std::vector<MPI_Request> *reqs) { if (!isEmpty()) { if (block) { MPI_Send(row_inds, (uint64_t)(nnz * sizeof(int)), MPI_BYTE, dst_rank, 0, MPI_COMM_WORLD); MPI_Send(col_ptrs, num_cols * sizeof(int), MPI_BYTE, dst_rank, 0, MPI_COMM_WORLD); MPI_Send(col_indices, num_cols * sizeof(int), MPI_BYTE, dst_rank, 0, MPI_COMM_WORLD); MPI_Send(vals, (uint64_t)(nnz * sizeof(T)), MPI_BYTE, dst_rank, 0, MPI_COMM_WORLD); MPI_Send(row_pointers, (num_partitions + 1) * sizeof(int), MPI_BYTE, dst_rank, 0, MPI_COMM_WORLD); MPI_Send(edge_pointers, (num_partitions + 1) * sizeof(int), MPI_BYTE, dst_rank, 0, MPI_COMM_WORLD); MPI_Send(col_starts, (num_partitions + 1) * sizeof(int), MPI_BYTE, dst_rank, 0, MPI_COMM_WORLD); } else { MPI_Request r1, r2, r3, r4, r5, r6, r7, r8; MPI_Isend(row_inds, (uint64_t)(nnz * sizeof(int)), MPI_BYTE, dst_rank, 0, MPI_COMM_WORLD, &r1); MPI_Isend(col_ptrs, num_cols * sizeof(int), MPI_BYTE, dst_rank, 0, MPI_COMM_WORLD, &r2); MPI_Isend(col_indices, num_cols * sizeof(int), MPI_BYTE, dst_rank, 0, MPI_COMM_WORLD, &r3); MPI_Isend(vals, (uint64_t)(nnz * sizeof(T)), MPI_BYTE, dst_rank, 0, MPI_COMM_WORLD, &r4); MPI_Isend(row_pointers, (num_partitions + 1) * sizeof(int), MPI_BYTE, dst_rank, 0, MPI_COMM_WORLD, &r5); MPI_Isend(edge_pointers, (num_partitions + 1) * sizeof(int), MPI_BYTE, dst_rank, 0, MPI_COMM_WORLD, &r6); MPI_Isend(col_starts, (num_partitions + 1) * sizeof(int), MPI_BYTE, dst_rank, 0, MPI_COMM_WORLD, &r7); (*reqs).push_back(r1); (*reqs).push_back(r2); (*reqs).push_back(r3); (*reqs).push_back(r4); (*reqs).push_back(r5); (*reqs).push_back(r6); (*reqs).push_back(r7); } } } void recv_tile(int myrank, int src_rank, int output_rank, bool block, std::vector<MPI_Request> *reqs) { if (!(isEmpty())) { row_inds = reinterpret_cast<int *>( _mm_malloc((uint64_t)nnz * (uint64_t)sizeof(int), 64)); col_ptrs = reinterpret_cast<int *>(_mm_malloc(num_cols * sizeof(int), 64)); col_indices = reinterpret_cast<int *>(_mm_malloc(num_cols * sizeof(int), 64)); vals = reinterpret_cast<T *>( _mm_malloc((uint64_t)nnz * (uint64_t)sizeof(T), 64)); row_pointers = reinterpret_cast<int *>( _mm_malloc((num_partitions + 1) * sizeof(int), 64)); edge_pointers = reinterpret_cast<int *>( _mm_malloc((num_partitions + 1) * sizeof(int), 64)); col_starts = reinterpret_cast<int *>( _mm_malloc((num_partitions + 1) * sizeof(int), 64)); if (block) { MPI_Recv(row_inds, (uint64_t)(nnz * sizeof(int)), MPI_BYTE, src_rank, 0, MPI_COMM_WORLD, MPI_STATUS_IGNORE); MPI_Recv(col_ptrs, num_cols * sizeof(int), MPI_BYTE, src_rank, 0, MPI_COMM_WORLD, MPI_STATUS_IGNORE); MPI_Recv(col_indices, num_cols * sizeof(int), MPI_BYTE, src_rank, 0, MPI_COMM_WORLD, MPI_STATUS_IGNORE); MPI_Recv(vals, (uint64_t)(nnz * sizeof(T)), MPI_BYTE, src_rank, 0, MPI_COMM_WORLD, MPI_STATUS_IGNORE); MPI_Recv(row_pointers, (num_partitions + 1) * sizeof(int), MPI_BYTE, src_rank, 0, MPI_COMM_WORLD, MPI_STATUS_IGNORE); MPI_Recv(edge_pointers, (num_partitions + 1) * sizeof(int), MPI_BYTE, src_rank, 0, MPI_COMM_WORLD, MPI_STATUS_IGNORE); MPI_Recv(col_starts, (num_partitions + 1) * sizeof(int), MPI_BYTE, src_rank, 0, MPI_COMM_WORLD, MPI_STATUS_IGNORE); } else { MPI_Request r1, r2, r3, r4, r5, r6, r7, r8; MPI_Irecv(row_inds, (uint64_t)(nnz * sizeof(int)), MPI_BYTE, src_rank, 0, MPI_COMM_WORLD, &r1); MPI_Irecv(col_ptrs, num_cols * sizeof(int), MPI_BYTE, src_rank, 0, MPI_COMM_WORLD, &r2); MPI_Irecv(col_indices, num_cols * sizeof(int), MPI_BYTE, src_rank, 0, MPI_COMM_WORLD, &r3); MPI_Irecv(vals, (uint64_t)(nnz * sizeof(T)), MPI_BYTE, src_rank, 0, MPI_COMM_WORLD, &r4); MPI_Irecv(row_pointers, (num_partitions + 1) * sizeof(int), MPI_BYTE, src_rank, 0, MPI_COMM_WORLD, &r5); MPI_Irecv(edge_pointers, (num_partitions + 1) * sizeof(int), MPI_BYTE, src_rank, 0, MPI_COMM_WORLD, &r6); MPI_Irecv(col_starts, (num_partitions + 1) * sizeof(int), MPI_BYTE, src_rank, 0, MPI_COMM_WORLD, &r7); (*reqs).push_back(r1); (*reqs).push_back(r2); (*reqs).push_back(r3); (*reqs).push_back(r4); (*reqs).push_back(r5); (*reqs).push_back(r6); (*reqs).push_back(r7); } } } }; #endif // SRC_DCSCTILE_H_
oyranos_cmm_oJPG.c
/** @file oyranos_cmm_oJPG.c * * JPEG file i/o module for Oyranos * * @par Copyright: * 2014-2015 (C) Kai-Uwe Behrmann * * @brief JPEG filter for Oyranos * @internal * @author Kai-Uwe Behrmann <oy@oyranos.org> * @par License: * new BSD <http://www.opensource.org/licenses/BSD-3-Clause> * @since 2014/03/21 */ #include "oyCMM_s.h" #include "oyCMMapi4_s.h" #include "oyCMMapi7_s.h" #include "oyCMMapiFilter_s.h" #include "oyCMMui_s.h" #include "oyConnectorImaging_s.h" #include "oyProfiles_s.h" #include "oyranos_cmm.h" #include "oyranos_config.h" #include "oyranos_definitions.h" #include "oyranos_helper.h" #include <math.h> #include <stdarg.h> #include <stdlib.h> #include <stdio.h> #include <string.h> #include <ctype.h> /* isspace() */ #include <setjmp.h> /* libjpeg specific error handling */ #include "jpegmarkers.h" /* --- internal definitions --- */ /** The CMM_NICK consists of four bytes, which appear as well in the library name. This is important for Oyranos to identify the required filter struct name. */ #define CMM_NICK "oJPG" #define OY_oJPG_FILTER_REGISTRATION OY_TOP_INTERNAL OY_SLASH OY_DOMAIN_INTERNAL OY_SLASH OY_TYPE_STD OY_SLASH "file_loader" /** The message function pointer to use for messaging. */ oyMessage_f ojpg_msg = oyMessageFunc; /* Helpers */ #if defined(__GNUC__) # define OY_DBG_FORMAT_ "%s:%d %s() " # define OY_DBG_ARGS_ strrchr(__FILE__,'/') ? strrchr(__FILE__,'/')+1 : __FILE__,__LINE__,__func__ #else # define OY_DBG_FORMAT_ "%s:%d " # define OY_DBG_ARGS_ strrchr(__FILE__,'/') ? strrchr(__FILE__,'/')+1 : __FILE__,__LINE__ #endif #define _DBG_FORMAT_ OY_DBG_FORMAT_ #define _DBG_ARGS_ OY_DBG_ARGS_ /* i18n */ #include "oyranos_i18n.h" #define AD oyAllocateFunc_, oyDeAllocateFunc_ int ojpgInit ( oyStruct_s * module_info ); int ojpgFilter_CmmRun ( oyFilterPlug_s * requestor_plug, oyPixelAccess_s * ticket ); const char * ojpgApi4UiGetText2 ( const char * select, oyNAME_e type, const char * format ); int ojpgGetOFORMS ( oyCMMapiFilter_s * module, oyOptions_s * oy_opts, int flags, char ** ui_text, oyAlloc_f allocateFunc ); const char * ojpgApi4UiGetText ( const char * select, oyNAME_e type, oyStruct_s * context ); extern const char * ojpg_api4_ui_texts[]; char * ojpgFilterNode_GetText ( oyFilterNode_s * node, oyNAME_e type, oyAlloc_f allocateFunc ); /* --- implementations --- */ /** Function ojpgCMMInit * @brief API requirement * * @version Oyranos: 0.9.6 * @since 2014/03/21 (Oyranos: 0.9.6) * @date 2014/03/21 */ int ojpgCMMInit ( oyStruct_s * s OY_UNUSED ) { int error = 0; return error; } /** Function ojpgCMMMessageFuncSet * @brief API requirement * * A Oyranos user might want its own message function and omit the default * one. * * @version Oyranos: 0.9.6 * @since 2014/03/21 (Oyranos: 0.9.6) * @date 2014/03/21 */ int ojpgCMMMessageFuncSet ( oyMessage_f message_func ) { ojpg_msg = message_func; return 0; } /** * This function implements oyCMMinfoGetText_f. * * Implement at least "name", "manufacturer" and "copyright". If you like with * internationalisation. * * @version Oyranos: 0.9.6 * @since 2014/03/21 (Oyranos: 0.9.6) * @date 2014/03/21 */ const char * ojpgGetText ( const char * select, oyNAME_e type, oyStruct_s * context ) { if(strcmp(select, "name")==0) if(type == oyNAME_NICK) return _(CMM_NICK); return oyCMMgetText( select, type, context ); } oyIcon_s ojpg_icon = {oyOBJECT_ICON_S, 0,0,0, 0,0,0, "oyranos_logo.png"}; /** @instance oJPG_cmm_module * @brief ojpg module infos * * This structure is dlopened by Oyranos. Its name has to consist of the * following elements: * - the four byte CMM_NICK plus * - "_cmm_module" * This string must be included in the the filters filename. * * @version Oyranos: 0.9.6 * @since 2014/03/21 (Oyranos: 0.9.6) * @date 2014/03/21 */ oyCMM_s oJPG_cmm_module = { oyOBJECT_CMM_INFO_S, /**< ::type; the object type */ 0,0,0, /**< static objects omit these fields */ CMM_NICK, /**< ::cmm; the four char filter id */ (char*)"0.9.6", /**< ::backend_version */ ojpgGetText, /**< ::getText; UI texts */ (char**)oyCMM_texts, /**< ::texts; list of arguments to getText */ OYRANOS_VERSION, /**< ::oy_compatibility; last supported Oyranos CMM API*/ /** ::api; The first filter api structure. */ NULL, /** ::icon; module icon */ &ojpg_icon, ojpgInit }; /* OY_oJPG_FILTER_REGISTRATION ----------------------------------------------*/ #define OY_oJPG_FILTER_REGISTRATION_BASE OY_TOP_SHARED OY_SLASH OY_DOMAIN_INTERNAL OY_SLASH OY_TYPE_STD OY_SLASH /** @instance ojpg_api7 * @brief ojpg oyCMMapi7_s implementation * * a filter providing a CMM filter * * @version Oyranos: 0.9.6 * @date 2014/03/21 * @since 2014/03/21 (Oyranos: 0.9.6) */ oyCMMapi_s * ojpgApi7CmmCreate ( const char * format, const char * ext ) { int32_t cmm_version[3] = {OYRANOS_VERSION_A,OYRANOS_VERSION_B,OYRANOS_VERSION_C}, module_api[3] = {0,9,6}; static oyDATATYPE_e data_types[7] = {oyUINT8, oyUINT16, oyUINT32, oyHALF, oyFLOAT, oyDOUBLE, (oyDATATYPE_e)0}; oyConnectorImaging_s * plug = oyConnectorImaging_New(0), * socket = oyConnectorImaging_New(0); static oyConnectorImaging_s * plugs[2] = {0,0}, * sockets[2] = {0,0}; const char * properties[] = { "file=read", /* file read|write */ "image=pixel", /* image type, pixel/vector/font */ "layers=1", /* layer count, one for plain images */ "icc=1", /* image type ICC profile support */ "ext=jpg,jpeg", /* supported extensions */ 0 }; plugs[0] = plug; sockets[0] = socket; char * registration = NULL; oyStringAddPrintf( &registration, AD, OY_oJPG_FILTER_REGISTRATION_BASE"file_read.input_%s._%s._CPU._ACCEL", format, CMM_NICK ); if(oy_debug >= 2) ojpg_msg(oyMSG_DBG, NULL, _DBG_FORMAT_ "registration:%s ojpg %s", _DBG_ARGS_, registration, ext ); oyConnectorImaging_SetDataTypes( socket, data_types, 6 ); oyConnectorImaging_SetReg( socket, "//" OY_TYPE_STD "/image.data" ); oyConnectorImaging_SetMatch( socket, oyFilterSocket_MatchImagingPlug ); oyConnectorImaging_SetTexts( socket, oyCMMgetImageConnectorSocketText, oy_image_connector_texts ); oyConnectorImaging_SetIsPlug( socket, 0 ); oyConnectorImaging_SetCapability( socket, oyCONNECTOR_IMAGING_CAP_MAX_COLOR_OFFSET, -1 ); oyConnectorImaging_SetCapability( socket, oyCONNECTOR_IMAGING_CAP_MIN_CHANNELS_COUNT, 1 ); oyConnectorImaging_SetCapability( socket, oyCONNECTOR_IMAGING_CAP_MAX_CHANNELS_COUNT, 16 ); oyConnectorImaging_SetCapability( socket, oyCONNECTOR_IMAGING_CAP_MIN_COLOR_COUNT, 1 ); oyConnectorImaging_SetCapability( socket, oyCONNECTOR_IMAGING_CAP_MAX_COLOR_COUNT, 16 ); oyConnectorImaging_SetCapability( socket, oyCONNECTOR_IMAGING_CAP_CAN_INTERWOVEN, 1 ); oyConnectorImaging_SetCapability( socket, oyCONNECTOR_IMAGING_CAP_CAN_PREMULTIPLIED_ALPHA, 1 ); oyConnectorImaging_SetCapability( socket, oyCONNECTOR_IMAGING_CAP_CAN_NONPREMULTIPLIED_ALPHA, 1 ); oyConnectorImaging_SetCapability( socket, oyCONNECTOR_IMAGING_CAP_ID, 1 ); oyCMMapi7_s * cmm7 = oyCMMapi7_Create( ojpgCMMInit, ojpgCMMMessageFuncSet, registration, cmm_version, module_api, NULL, ojpgFilter_CmmRun, (oyConnector_s**)plugs, 0, 0, (oyConnector_s**)sockets, 1, 0, properties, 0 ); //oyFree_m_( registration ); return (oyCMMapi_s*) cmm7; } int deAllocData ( void ** data ) { oyDeAllocateFunc_(*data); *data = NULL; return 0; } const char ojpg_read_extra_options[] = { "\n\ <" OY_TOP_SHARED ">\n\ <" OY_DOMAIN_INTERNAL ">\n\ <" OY_TYPE_STD ">\n\ <" "file_read" ">\n\ <filename></filename>\n\ </" "file_read" ">\n\ </" OY_TYPE_STD ">\n\ </" OY_DOMAIN_INTERNAL ">\n\ </" OY_TOP_SHARED ">\n" }; /** @instance ojpg_api4 * @brief ojpg oyCMMapi4_s implementation * * a filter providing a CMM device link creator * * @version Oyranos: 0.9.6 * @since 2014/03/21 (Oyranos: 0.9.6) * @date 2014/03/21 */ oyCMMapi_s * ojpgApi4CmmCreate ( const char * format ) { int32_t cmm_version[3] = {OYRANOS_VERSION_A,OYRANOS_VERSION_B,OYRANOS_VERSION_C}, module_api[3] = {0,9,6}; oyPointer_s * backend_context = oyPointer_New(0); char * registration = NULL; const char * category = ojpgApi4UiGetText2("category", oyNAME_NAME, format); oyCMMuiGet_f getOFORMS = ojpgGetOFORMS; oyCMMui_s * ui = oyCMMui_Create( category, ojpgApi4UiGetText, ojpg_api4_ui_texts, 0 ); oyOptions_s * oy_opts = NULL; const char * oforms_options = ojpg_read_extra_options; oyCMMui_SetUiOptions( ui, oyStringCopy( oforms_options, oyAllocateFunc_ ), getOFORMS ); oyPointer_Set( backend_context, NULL, "ojpg_file_format", oyStringCopy(format, oyAllocateFunc_), "char*", deAllocData ); oyStringAddPrintf( &registration, AD, OY_oJPG_FILTER_REGISTRATION_BASE"file_read.input_%s._" CMM_NICK "._CPU._ACCEL", format ); oyCMMapi4_s * cmm4 = oyCMMapi4_Create( ojpgCMMInit, ojpgCMMMessageFuncSet, registration, cmm_version, module_api, "", NULL, ojpgFilterNode_GetText, ui, NULL ); oyCMMapi4_SetBackendContext( cmm4, backend_context ); oyOptions_Release( &oy_opts ); return (oyCMMapi_s*)cmm4; } char * ojpgFilterNode_GetText ( oyFilterNode_s * node, oyNAME_e type OY_UNUSED, oyAlloc_f allocateFunc ) { char * t = NULL; const char * tmp = NULL; oyOptions_s * node_options = oyFilterNode_GetOptions( node, 0 ); tmp = oyOptions_GetText(node_options, oyNAME_NICK); if(tmp) t = oyStringCopy( tmp, allocateFunc ); oyOptions_Release( &node_options ); return t; } #define A(long_text) oyStringAdd_( &tmp, long_text, AD ) /* TODO */ int ojpgGetOFORMS ( oyCMMapiFilter_s * module OY_UNUSED, oyOptions_s * oy_opts OY_UNUSED, int flags OY_UNUSED, char ** ui_text, oyAlloc_f allocateFunc OY_UNUSED ) { int error = 0; char * tmp = NULL; *ui_text = tmp; return error; } oyOptions_s* ojpgFilter_CmmLoaderValidateOptions ( oyFilterCore_s * filter, oyOptions_s * validate OY_UNUSED, int statical OY_UNUSED, uint32_t * result ) { uint32_t error = !filter; #if 0 if(!error) error = !oyOptions_FindString( validate, "my_options", 0 ); #endif *result = error; return 0; } int select_icc_profile(j_decompress_ptr cinfo, const char * filename, JOCTET **icc_data_ptr, unsigned int *icc_data_len) { unsigned int len; int lIsITUFax = jpeg_get_marker_size( cinfo, JPEG_APP0+1, (JOCTET*)"G3FAX", 5, &len ) == 0; { char * profile_name = 0; char * prof_mem = 0; size_t size = 0; switch(cinfo->out_color_space) { case JCS_GRAYSCALE: profile_name = oyGetDefaultProfileName (oyASSUMED_GRAY, malloc); break; case JCS_RGB: if(lIsITUFax) { profile_name = strdup("ITULab.icc"); if( !oyCheckProfile (profile_name, 0) ) prof_mem = (char*)oyGetProfileBlock( profile_name, &size, malloc ); else if(!oyCheckProfile ("ITUFAX.ICM", 0) ) prof_mem = (char*)oyGetProfileBlock( "ITUFAX.ICM", &size, malloc ); cinfo->out_color_space = JCS_YCbCr; // do'nt convert colors } else { /* guesswork */ const char * fn = strrchr( filename, OY_SLASH_C ); if(fn) fn += 1; else fn = filename; if(fn[0] == '_') /* Canon RAW AdobeRGB */ profile_name = strdup("compatibleWithAdobeRGB1998.icc"); else { profile_name = strdup("YCbCr-Jpeg_v1_oyra.icc"); if( !oyCheckProfile (profile_name, 0) ) { prof_mem = (char*)oyGetProfileBlock( profile_name, &size, malloc ); cinfo->out_color_space = JCS_YCbCr; // do'nt convert colors } else profile_name = oyGetDefaultProfileName (oyASSUMED_RGB, malloc); } } break; case JCS_CMYK: profile_name = oyGetDefaultProfileName (oyASSUMED_CMYK, malloc); break; case JCS_YCbCr: if(lIsITUFax) profile_name = strdup("ITULab.icc"); if( !oyCheckProfile (profile_name, 0) ) prof_mem = (char*)oyGetProfileBlock( profile_name, &size, malloc ); else if(!oyCheckProfile ("ITUFAX.ICM", 0) ) prof_mem = (char*)oyGetProfileBlock( "ITUFAX.ICM", &size, malloc ); else profile_name = strdup("YCbCr-Jpeg_v1_oyra.icc"); break; case JCS_UNKNOWN: case JCS_YCCK: break; } if( !oyCheckProfile (profile_name, 0) ) prof_mem = (char*)oyGetProfileBlock( profile_name, &size, malloc ); *icc_data_ptr = (JOCTET*)prof_mem; *icc_data_len = size; if(profile_name) free( profile_name ); if(size && prof_mem) return 1; } return 0; } /* Taken from the libjpeg's example.c */ typedef struct oJPG_error_mgr { struct jpeg_error_mgr pub; jmp_buf setjmp_buffer; } * oJPG_error_ptr; static void oJPG_error_exit (j_common_ptr cinfo) { oJPG_error_ptr myerr = (oJPG_error_ptr) cinfo->err; (*cinfo->err->output_message) (cinfo); longjmp (myerr->setjmp_buffer, 1); } /** Function ojpgFilter_CmmRun * @brief implement oyCMMFilter_GetNext_f() * * The primary filter entry for data processing. * * @param requestor_plug the plug of the requesting node after * my filter in the graph * @param ticket the job ticket * * @version Oyranos: 0.9.6 * @since 2014/03/21 (Oyranos: 0.9.6) * @date 2014/03/21 */ int ojpgFilter_CmmRun ( oyFilterPlug_s * requestor_plug, oyPixelAccess_s * ticket ) { oyFilterSocket_s * socket = 0; oyStruct_s * socket_data = 0; oyFilterNode_s * node = 0; oyOptions_s * tags = 0; int error = 0; const char * filename = 0; FILE * fp = 0; oyDATATYPE_e data_type = oyUINT8; oyPROFILE_e profile_type = oyASSUMED_RGB; oyProfile_s * prof = 0; oyImage_s * image_in = 0, * output_image = 0; oyPixel_t pixel_type = 0; size_t fsize = 0; uint8_t * buf = 0; size_t mem_n = 0; /* needed memory in bytes */ int width,height,nchannels; int32_t icc_profile_flags = 0; const char * format = "jpeg"; if(requestor_plug->type_ == oyOBJECT_FILTER_PLUG_S) { socket = oyFilterPlug_GetSocket( requestor_plug ); socket_data = oyFilterSocket_GetData( socket ); } /* passing through the data reading */ if(requestor_plug->type_ == oyOBJECT_FILTER_PLUG_S && socket_data) { error = oyFilterPlug_ImageRootRun( requestor_plug, ticket ); goto ojpgFilter_CmmRunClean; } else if(requestor_plug->type_ == oyOBJECT_FILTER_SOCKET_S) { /* To open the a image here seems not so straight forward. * Still the plug-in should be prepared to initialise the image data before * normal processing occurs. */ socket = oyFilterSocket_Copy( (oyFilterSocket_s*)requestor_plug, 0 ); requestor_plug = 0; } node = oyFilterSocket_GetNode( socket ); /* parse options */ if(error <= 0) { oyOptions_s * opts = oyFilterNode_GetOptions( node ,0 ); filename = oyOptions_FindString( opts, "filename", 0 ); oyOptions_FindInt( opts, "icc_profile_flags", 0, &icc_profile_flags ); oyOptions_Release( &opts ); } /* file tests */ if(filename) fp = fopen( filename, "rm" ); if(!fp) { ojpg_msg( oyMSG_WARN, (oyStruct_s*)node, OY_DBG_FORMAT_ " could not open: %s", OY_DBG_ARGS_, oyNoEmptyString_m( filename ) ); error = 1; goto ojpgFilter_CmmRunClean; } /* file size fun */ fseek(fp,0L,SEEK_END); fsize = ftell(fp); rewind(fp); if(oy_debug) ojpg_msg( oyMSG_DBG, (oyStruct_s*)node, OY_DBG_FORMAT_ "file size %u", OY_DBG_ARGS_, fsize ); /* get ICC Profile */ { struct jpeg_decompress_struct cinfo; struct oJPG_error_mgr jerr; unsigned int len = 0; unsigned char * icc = NULL; int m; cinfo.err = jpeg_std_error (&jerr.pub); jerr.pub.error_exit = oJPG_error_exit; // Provide custom error handling to avoid libjpeg calling exit() if( setjmp( jerr.setjmp_buffer )) { jpeg_destroy_decompress (&cinfo); ojpg_msg( oyMSG_WARN, (oyStruct_s*)node, OY_DBG_FORMAT_ "Exit from libjpeg for %s", OY_DBG_ARGS_, oyNoEmptyString_m( filename ) ); error = FALSE; goto ojpgFilter_CmmRunClean; } // Setup decompression structure jpeg_create_decompress (&cinfo); jpeg_stdio_src (&cinfo, fp); for (m = 0; m < 16; m++) jpeg_save_markers(&cinfo, JPEG_APP0 + m, 0xFFFF); (void) jpeg_read_header (&cinfo, TRUE); if( jpeg_get_marker_size( &cinfo, JPEG_APP0+2, (JOCTET*)"ICC_PROFILE", 12, &len ) == 0 ) { icc = (unsigned char*) malloc(len); jpeg_get_marker_data( &cinfo, JPEG_APP0+2, (JOCTET*)"ICC_PROFILE", 12, len, (JOCTET*)icc ); } if (icc && len) { if(oy_debug) ojpg_msg( oyMSG_DBG, (oyStruct_s*)node, OY_DBG_FORMAT_ "jpeg embedded profile found: %d", OY_DBG_ARGS_, len); } else if (select_icc_profile(&cinfo, filename, &icc, &len)) { if(oy_debug) ojpg_msg( oyMSG_DBG, (oyStruct_s*)node, OY_DBG_FORMAT_ "jpeg default profile selected: %d", OY_DBG_ARGS_, len); } else if(oy_debug) ojpg_msg( oyMSG_DBG, (oyStruct_s*)node, OY_DBG_FORMAT_ "jpeg no profile found", OY_DBG_ARGS_); if(icc && len) { prof = oyProfile_FromMem( len, icc, 0, 0 ); len = 0; } if(icc) oyFree_m_(icc); jpeg_start_decompress (&cinfo); nchannels = cinfo.out_color_components; width = cinfo.output_width; height = cinfo.output_height; /* allocate a buffer to hold the whole image */ mem_n = width*height*oyDataTypeGetSize(data_type)*nchannels; if(mem_n) { buf = (uint8_t*) oyAllocateFunc_(mem_n * sizeof(uint8_t)); if(!buf) { ojpg_msg(oyMSG_WARN, (oyStruct_s *) node, _DBG_FORMAT_ "Could not allocate enough memory.", _DBG_ARGS_); error = 1; goto ojpgFilter_CmmRunClean; } } else { ojpg_msg( oyMSG_WARN, (oyStruct_s *) node, _DBG_FORMAT_ "nothing to allocate: %dx%dx%d", _DBG_ARGS_, width, height, nchannels ); error = 1; goto ojpgFilter_CmmRunClean; } if(oy_debug) ojpg_msg( oyMSG_DBG, (oyStruct_s *) node, _DBG_FORMAT_ "allocate image data: 0x%x size: %d ", _DBG_ARGS_, (int)(intptr_t) buf, mem_n ); while (cinfo.output_scanline < height) { /* jpeg_read_scanlines expects an array of pointers to scanlines. * Here the array is only one element long, but you could ask for * more than one scanline at a time if that's more convenient. */ JSAMPROW b = &buf[(cinfo.output_width * nchannels)*cinfo.output_scanline]; jpeg_read_scanlines(&cinfo, &b, 1); } icColorSpaceSignature csp = (icColorSpaceSignature) oyProfile_GetSignature(prof,oySIGNATURE_COLOR_SPACE); if(csp == icSigCmykData) { int n = width * height * 4; if(data_type == oyUINT8) { uint8_t * d = (uint8_t*)buf; int i; #pragma omp parallel for private(i) for(i = 0; i < n; ++i) d[i] = 255 - d[i]; } } jpeg_finish_decompress (&cinfo); jpeg_destroy_decompress (&cinfo); } /* fallback profile */ if(!prof) prof = oyProfile_FromStd( profile_type, icc_profile_flags, 0 ); if(oy_debug) ojpg_msg( oyMSG_DBG, (oyStruct_s*)node, OY_DBG_FORMAT_ "%dx%d %s|%s[%d]", OY_DBG_ARGS_, width, height, format, oyDataTypeToText(data_type), nchannels ); /* create a Oyranos image */ pixel_type = oyChannels_m(nchannels) | oyDataType_m(data_type); image_in = oyImage_Create( width, height, NULL, pixel_type, prof, 0 ); oyArray2d_s * a = oyArray2d_Create( buf, width*nchannels, height, data_type, NULL ); oyImage_ReadArray(image_in, NULL, a, NULL); oyArray2d_Release( &a ); free(buf); buf = NULL; if (!image_in) { ojpg_msg( oyMSG_WARN, (oyStruct_s*)node, OY_DBG_FORMAT_ "can't create a new image\n%dx%d %s[%d]", OY_DBG_ARGS_, width, height, format, nchannels ); error = FALSE; goto ojpgFilter_CmmRunClean; } /* remember the meta data like file name */ tags = oyImage_GetTags( image_in ); error = oyOptions_SetFromString( &tags, "//" OY_TYPE_STD "/file_read.input_ojpg" "/filename", filename, OY_CREATE_NEW ); oyOptions_Release( &tags ); /* close the image and FILE pointer */ fclose(fp); fp = NULL; /* add image to filter socket */ if(error <= 0) { oyFilterSocket_SetData( socket, (oyStruct_s*)image_in ); } /* update the job ticket */ if(ticket) output_image = oyPixelAccess_GetOutputImage( ticket ); if(ticket && output_image && oyImage_GetWidth( output_image ) == 0 && oyImage_GetHeight( output_image ) == 0) { oyImage_SetCritical( output_image, oyImage_GetPixelLayout( image_in, oyLAYOUT ), 0,0, oyImage_GetWidth( image_in ), oyImage_GetHeight( image_in ) ); } ojpgFilter_CmmRunClean: /* release Oyranos stuff */ oyImage_Release( &image_in ); oyImage_Release( &output_image ); oyFilterNode_Release( &node ); oyFilterSocket_Release( &socket ); if(fp) fclose(fp); /* return an error to cause the graph to retry */ return 1; } const char * ojpgApi4UiGetText2 ( const char * select, oyNAME_e type, const char * format ) { static char * category = 0; if(strcmp(select,"name") == 0) { if(type == oyNAME_NICK) return "read"; else if(type == oyNAME_NAME) return _("read"); else if(type == oyNAME_DESCRIPTION) return _("Load Image File Object"); } else if(strcmp(select,"help") == 0) { if(type == oyNAME_NICK) return "help"; else if(type == oyNAME_NAME) return _("Option \"filename\", a valid filename of a existing image"); else if(type == oyNAME_DESCRIPTION) return _("The Option \"filename\" should contain a valid filename to read the image data from. If the file does not exist, a error will occure."); } else if(strcmp(select,"category") == 0) { if(!category) { /* The following strings must match the categories for a menu entry. */ const char * i18n[] = {_("Files"),_("Read"),0}; int len = strlen(i18n[0]) + strlen(i18n[1]) + strlen(format); category = (char*)malloc( len + 64 ); if(category) { char * t; /* Create a translation for ojpg_api4_ui_cmm_loader::category. */ sprintf( category,"%s/%s %s", i18n[0], i18n[1], format ); t = strstr(category, format); if(t) t[0] = toupper(t[0]); } else ojpg_msg(oyMSG_WARN, (oyStruct_s *) 0, _DBG_FORMAT_ "\n " "Could not allocate enough memory.", _DBG_ARGS_); } if(type == oyNAME_NICK) return "category"; else if(type == oyNAME_NAME) return category; else return category; } return 0; } /** * This function implements oyCMMGetText_f. * */ const char * ojpgApi4UiGetText ( const char * select, oyNAME_e type, oyStruct_s * context ) { oyCMMapiFilter_s * api = oyCMMui_GetParent( (oyCMMui_s *) context ); oyPointer_s * backend_context = oyCMMapiFilter_GetBackendContext( api ); const char * format = (const char*) oyPointer_GetPointer( backend_context ); oyPointer_Release( &backend_context ); api->release( (oyStruct_s**) &api ); return ojpgApi4UiGetText2(select, type, format); } const char * ojpg_api4_ui_texts[] = {"name", "category", "help", NULL}; /* OY_oJPG_FILTER_REGISTRATION ----------------------------------------------*/ extern oyCMM_s oJPG_cmm_module; int ojpgInit ( oyStruct_s * module_info ) { oyCMMapi_s * a = 0, * a_tmp = 0, * m = 0; int i,n = 1; if((oyStruct_s*)&oJPG_cmm_module != module_info) ojpg_msg( oyMSG_WARN, module_info, _DBG_FORMAT_ "wrong module info passed in", _DBG_ARGS_ ); /* search the last filter */ a = oJPG_cmm_module.api; while(a && ((a_tmp = oyCMMapi_GetNext( a )) != 0)) a = a_tmp; /* append new items */ { const char * format = "jpeg"; m = ojpgApi4CmmCreate( format ); if(!a) { oJPG_cmm_module.api = m; a = m; } else if(a && m) { oyCMMapi_SetNext( a, m ); a = m; } } for( i = 0; i < n; ++i) { const char * format = "jpeg"; m = ojpgApi7CmmCreate( format, "jpeg,jpg" ); if(!oJPG_cmm_module.api) { oJPG_cmm_module.api = m; a = m; } else if(a && m) { oyCMMapi_SetNext( a, m ); a = m; } } return 0; }
magsac.h
#pragma once #include <limits> #include <chrono> #include <memory> #include "model.h" #include "model_score.h" #include "samplers/sampler.h" #include "samplers/uniform_sampler.h" #include <math.h> #include "gamma_values.cpp" #ifdef _WIN32 #include <ppl.h> #endif #include <gflags/gflags.h> #include <glog/logging.h> template <class DatumType, class ModelEstimator> class MAGSAC { public: enum Version { // The original version of MAGSAC. It works well, however, can be quite slow in many cases. MAGSAC_ORIGINAL, // The recently proposed MAGSAC++ algorithm which keeps the accuracy of the original MAGSAC but is often orders of magnitude faster. MAGSAC_PLUS_PLUS }; MAGSAC(const Version magsac_version_ = Version::MAGSAC_PLUS_PLUS) : time_limit(std::numeric_limits<double>::max()), // desired_fps(-1), iteration_limit(std::numeric_limits<size_t>::max()), maximum_threshold(10.0), apply_post_processing(true), mininum_iteration_number(50), partition_number(5), core_number(1), number_of_irwls_iters(1), interrupting_threshold(1.0), last_iteration_number(0), log_confidence(0), point_number(0), magsac_version(magsac_version_) { } ~MAGSAC() {} // A function to run MAGSAC. bool run( const cv::Mat &points_, // The input data points const double confidence_, // The required confidence in the results ModelEstimator& estimator_, // The model estimator gcransac::sampler::Sampler<cv::Mat, size_t> &sampler_, // The sampler used gcransac::Model &obtained_model_, // The estimated model parameters int &iteration_number_, // The number of iterations done ModelScore &model_score_); // The score of the estimated model // A function to set the maximum inlier-outlier threshold void setMaximumThreshold(const double maximum_threshold_) { maximum_threshold = maximum_threshold_; } // A function to set the inlier-outlier threshold used for speeding up the procedure // and for determining the required number of iterations. void setReferenceThreshold(const double threshold_) { interrupting_threshold = threshold_; } double getReferenceThreshold() { return interrupting_threshold; } // Setting the flag determining if post-processing is needed void applyPostProcessing(bool value_) { apply_post_processing = value_; } // A function to set the maximum number of iterations void setIterationLimit(size_t iteration_limit_) { iteration_limit = iteration_limit_; } // A function to set the minimum number of iterations void setMinimumIterationNumber(size_t mininum_iteration_number_) { mininum_iteration_number = mininum_iteration_number_; } // A function to set the number of cores used in the original MAGSAC algorithm. // In MAGSAC++, it is not used. Note that when multiple MAGSACs run in parallel, // it is beneficial to keep the core number one for each independent MAGSAC. // Otherwise, the threads will act weirdly. void setCoreNumber(size_t core_number_) { if (magsac_version == MAGSAC_PLUS_PLUS) LOG(ERROR) << "Setting the core number for MAGSAC++ is deprecated."; core_number = core_number_; } // Setting the number of partitions used in the original MAGSAC algorithm // to speed up the procedure. In MAGSAC++, this parameter is not used. void setPartitionNumber(size_t partition_number_) { if (magsac_version == MAGSAC_PLUS_PLUS) LOG(ERROR) << "Setting the partition number for MAGSAC++ is deprecated."; partition_number = partition_number_; } // A function to set a desired minimum frames-per-second (FPS) value. void setFPS(int fps_) { desired_fps = fps_; // The required FPS. // The time limit which the FPS implies time_limit = fps_ <= 0 ? std::numeric_limits<double>::max() : 1.0 / fps_; } // The post-processing algorithm applying sigma-consensus to the input model once. bool postProcessing( const cv::Mat &points, // All data points const gcransac::Model &so_far_the_best_model, // The input model to be improved gcransac::Model &output_model, // The improved model parameters ModelScore &output_score, // The score of the improved model const ModelEstimator &estimator); // The model estimator // The function determining the quality/score of a model using the original MAGSAC // criterion. Note that this function is significantly slower than the quality // function of MAGSAC++. void getModelQuality( const cv::Mat& points_, // All data points const gcransac::Model& model_, // The input model const ModelEstimator& estimator_, // The model estimator double& marginalized_iteration_number_, // The required number of iterations marginalized over the noise scale double& score_); // The score/quality of the model // The function determining the quality/score of a // model using the MAGSAC++ criterion. void getModelQualityPlusPlus( const cv::Mat &points_, // All data points const gcransac::Model &model_, // The model parameter const ModelEstimator &estimator_, // The model estimator class double &score_, // The score to be calculated const double &previous_best_score_); // The score of the previous so-far-the-best model size_t number_of_irwls_iters; protected: Version magsac_version; // The version of MAGSAC used size_t iteration_limit; // Maximum number of iterations allowed size_t mininum_iteration_number; // Minimum number of iteration before terminating double maximum_threshold; // The maximum sigma value size_t core_number; // Number of core used in sigma-consensus double time_limit; // A time limit after the algorithm is interrupted int desired_fps; // The desired FPS (TODO: not tested with MAGSAC) bool apply_post_processing; // Decides if the post-processing step should be applied int point_number; // The current point number int last_iteration_number; // The iteration number implied by the last run of sigma-consensus double log_confidence; // The logarithm of the required confidence size_t partition_number; // Number of partitions used to speed up sigma-consensus double interrupting_threshold; // A threshold to speed up MAGSAC by interrupting the sigma-consensus procedure whenever there is no chance of being better than the previous so-far-the-best model bool sigmaConsensus( const cv::Mat& points_, const gcransac::Model& model_, gcransac::Model& refined_model_, ModelScore& score_, const ModelEstimator& estimator_, const ModelScore& best_score_); bool sigmaConsensusPlusPlus( const cv::Mat &points_, const gcransac::Model& model_, gcransac::Model& refined_model_, ModelScore &score_, const ModelEstimator &estimator_, const ModelScore &best_score_); }; template <class DatumType, class ModelEstimator> bool MAGSAC<DatumType, ModelEstimator>::run( const cv::Mat& points_, const double confidence_, ModelEstimator& estimator_, gcransac::sampler::Sampler<cv::Mat, size_t> &sampler_, gcransac::Model& obtained_model_, int& iteration_number_, ModelScore &model_score_) { // Initialize variables std::chrono::time_point<std::chrono::system_clock> start, end; // Variables for time measuring: start and end times std::chrono::duration<double> elapsed_seconds; // Variables for time measuring: elapsed time log_confidence = log(1.0 - confidence_); // The logarithm of 1 - confidence point_number = points_.rows; // Number of points constexpr size_t sample_size = estimator_.sampleSize(); // The sample size required for the estimation size_t max_iteration = iteration_limit; // The maximum number of iterations initialized to the iteration limit int iteration = 0; // Current number of iterations gcransac::Model so_far_the_best_model; // Current best model ModelScore so_far_the_best_score; // The score of the current best model std::unique_ptr<size_t[]> minimal_sample(new size_t[sample_size]); // The sample used for the estimation std::vector<size_t> pool(points_.rows); for (size_t point_idx = 0; point_idx < point_number; ++point_idx) pool[point_idx] = point_idx; if (points_.rows < sample_size) { LOG(WARNING) << "There are not enough points for applying robust estimation. Minimum is " << static_cast<int>(sample_size) << "; while " << static_cast<int>(points_.rows) << " are given."; return false; } // Set the start time variable if there is some time limit set if (desired_fps > -1) start = std::chrono::system_clock::now(); constexpr size_t max_unsuccessful_model_generations = 50; // Main MAGSAC iteration while (mininum_iteration_number > iteration || iteration < max_iteration) { // Increase the current iteration number ++iteration; // Sample a minimal subset std::vector<gcransac::Model> models; // The set of estimated models size_t unsuccessful_model_generations = 0; // The number of unsuccessful model generations // Try to select a minimal sample and estimate the implied model parameters while (++unsuccessful_model_generations < max_unsuccessful_model_generations) { // Get a minimal sample randomly if (!sampler_.sample(pool, // The index pool from which the minimal sample can be selected minimal_sample.get(), // The minimal sample sample_size)) // The size of a minimal sample continue; // Check if the selected sample is valid before estimating the model // parameters which usually takes more time. if (!estimator_.isValidSample(points_, // All points minimal_sample.get())) // The current sample continue; // Estimate the model from the minimal sample if (estimator_.estimateModel(points_, // All data points minimal_sample.get(), // The selected minimal sample &models)) // The estimated models break; } // If the method was not able to generate any usable models, break the cycle. iteration += unsuccessful_model_generations - 1; // Select the so-far-the-best from the estimated models for (const auto &model : models) { ModelScore score; // The score of the current model gcransac::Model refined_model; // The refined model parameters // Apply sigma-consensus to refine the model parameters by marginalizing over the noise level sigma bool success; if (magsac_version == Version::MAGSAC_ORIGINAL) success = sigmaConsensus(points_, model, refined_model, score, estimator_, so_far_the_best_score); else success = sigmaConsensusPlusPlus(points_, model, refined_model, score, estimator_, so_far_the_best_score); // Continue if the model was rejected if (!success || score.score == -1) continue; // Save the iteration number when the current model is found score.iteration = iteration; // Update the best model parameters if needed if (so_far_the_best_score < score) { so_far_the_best_model = refined_model; // Update the best model parameters so_far_the_best_score = score; // Update the best model's score max_iteration = MIN(max_iteration, last_iteration_number); // Update the max iteration number, but do not allow to increase } } // Update the time parameters if a time limit is set if (desired_fps > -1) { end = std::chrono::system_clock::now(); elapsed_seconds = end - start; // Interrupt if the time limit is exceeded if (elapsed_seconds.count() > time_limit) break; } } // Apply sigma-consensus as a post processing step if needed and the estimated model is valid if (apply_post_processing) { // TODO } obtained_model_ = so_far_the_best_model; iteration_number_ = iteration; model_score_ = so_far_the_best_score; return so_far_the_best_score.score > 0; } template <class DatumType, class ModelEstimator> bool MAGSAC<DatumType, ModelEstimator>::postProcessing( const cv::Mat &points_, const gcransac::Model &model_, gcransac::Model &refined_model_, ModelScore &refined_score_, const ModelEstimator &estimator_) { LOG(WARNING) << "Sigma-consensus++ is not implemented yet as post-processing."; return false; } template <class DatumType, class ModelEstimator> bool MAGSAC<DatumType, ModelEstimator>::sigmaConsensus( const cv::Mat &points_, const gcransac::Model& model_, gcransac::Model& refined_model_, ModelScore &score_, const ModelEstimator &estimator_, const ModelScore &best_score_) { // Set up the parameters constexpr double L = 1.05; constexpr double k = ModelEstimator::getSigmaQuantile(); constexpr double threshold_to_sigma_multiplier = 1.0 / k; constexpr size_t sample_size = estimator_.sampleSize(); static auto comparator = [](std::pair<double, int> left, std::pair<double, int> right) { return left.first < right.first; }; const int point_number = points_.rows; double current_maximum_sigma = this->maximum_threshold; // Calculating the residuals std::vector< std::pair<double, size_t> > all_residuals; all_residuals.reserve(point_number); // If it is not the first run, consider the previous best and interrupt the validation when there is no chance of being better if (best_score_.inlier_number > 0) { // Number of inliers which should be exceeded int points_remaining = best_score_.inlier_number; // Collect the points which are closer than the threshold which the maximum sigma implies for (int point_idx = 0; point_idx < point_number; ++point_idx) { // Calculate the residual of the current point const double residual = estimator_.residual(points_.row(point_idx), model_); if (current_maximum_sigma > residual) { // Store the residual of the current point and its index all_residuals.emplace_back(std::make_pair(residual, point_idx)); // Count points which are closer than a reference threshold to speed up the procedure if (residual < interrupting_threshold) --points_remaining; } // Interrupt if there is no chance of being better // TODO: replace this part by SPRT test if (point_number - point_idx < points_remaining) return false; } // Store the number of really close inliers just to speed up the procedure // by interrupting the next verifications. score_.inlier_number = best_score_.inlier_number - points_remaining; } else { // The number of really close points size_t points_close = 0; // Collect the points which are closer than the threshold which the maximum sigma implies for (size_t point_idx = 0; point_idx < point_number; ++point_idx) { // Calculate the residual of the current point const double residual = estimator_.residual(points_.row(point_idx), model_); if (current_maximum_sigma > residual) { // Store the residual of the current point and its index all_residuals.emplace_back(std::make_pair(residual, point_idx)); // Count points which are closer than a reference threshold to speed up the procedure if (residual < interrupting_threshold) ++points_close; } } // Store the number of really close inliers just to speed up the procedure // by interrupting the next verifications. score_.inlier_number = points_close; } std::vector<gcransac::Model> sigma_models; std::vector<size_t> sigma_inliers; std::vector<double> final_weights; // The number of possible inliers const size_t possible_inlier_number = all_residuals.size(); // Sort the residuals in ascending order std::sort(all_residuals.begin(), all_residuals.end(), comparator); // The maximum threshold is set to be slightly bigger than the distance of the // farthest possible inlier. current_maximum_sigma = all_residuals.back().first + std::numeric_limits<double>::epsilon(); const double sigma_step = current_maximum_sigma / partition_number; last_iteration_number = 10000; score_.score = 0; // The weights calculated by each parallel process std::vector<std::vector<double>> point_weights_par(partition_number, std::vector<double>(possible_inlier_number, 0)); // If OpenMP is used, calculate things in parallel #ifdef USE_OPENMP #pragma omp parallel for num_threads(core_number) for (int partition_idx = 0; partition_idx < partition_number; ++partition_idx) { // The maximum sigma value in the current partition const double max_sigma = (partition_idx + 1) * sigma_step; // Find the last element which has smaller distance than 'max_threshold' // Since the vector is ordered binary search can be used to find that particular element. const auto &last_element = std::upper_bound(all_residuals.begin(), all_residuals.end(), std::make_pair(max_sigma, 0), comparator); const size_t sigma_inlier_number = last_element - all_residuals.begin(); // Put the indices into a vector std::vector<size_t> sigma_inliers; sigma_inliers.reserve(sigma_inlier_number); // Store the points which are closer than the current sigma limit for (size_t relative_point_idx = 0; relative_point_idx < sigma_inlier_number; ++relative_point_idx) sigma_inliers.emplace_back(all_residuals[relative_point_idx].second); // Check if there are enough inliers to fit a model if (sigma_inliers.size() > sample_size) { // Estimating the model which the current set of inliers imply std::vector<gcransac::Model> sigma_models; estimator_.estimateModelNonminimal(points_, &(sigma_inliers)[0], sigma_inlier_number, &sigma_models); // If the estimation was successful calculate the implied probabilities if (sigma_models.size() == 1) { const double max_sigma_squared_2 = 2 * max_sigma * max_sigma; double residual_i_2, // The residual of the i-th point probability_i; // The probability of the i-th point // Iterate through all points to estimate the related probabilities for (size_t relative_point_idx = 0; relative_point_idx < sigma_inliers.size(); ++relative_point_idx) { // TODO: Replace with Chi-square instead of normal distribution const size_t &point_idx = sigma_inliers[relative_point_idx]; // Calculate the residual of the current point residual_i_2 = estimator_.squaredResidual(points_.row(point_idx), sigma_models[0]); // Calculate the probability of the i-th point assuming Gaussian distribution // TODO: replace by Chi-square distribution probability_i = exp(-residual_i_2 / max_sigma_squared_2); // Store the probability of the i-th point coming from the current partition point_weights_par[partition_idx][relative_point_idx] += probability_i; } } } } #else LOG(ERROR) << "Not implemented yet."; #endif // The weights used for the final weighted least-squares fitting // If point normalization is applied the indexing of the weights differs. // In that case // final_weights[i] is the weight of inlier[i]-th point // Otherwise, // final_weights[i] is the weight of i-th point if constexpr (ModelEstimator::doesNormalizationForNonMinimalFitting()) final_weights.reserve(possible_inlier_number); else final_weights.resize(point_number, 0); // Collect all points which has higher probability of being inlier than zero sigma_inliers.reserve(possible_inlier_number); for (size_t point_idx = 0; point_idx < possible_inlier_number; ++point_idx) { // Calculate the weight of the current point double weight = 0.0; for (size_t partition_idx = 0; partition_idx < partition_number; ++partition_idx) weight += point_weights_par[partition_idx][point_idx]; // If the weight is approx. zero, continue. if (weight < std::numeric_limits<double>::epsilon()) continue; // Store the index and weight of the current point sigma_inliers.emplace_back(all_residuals[point_idx].second); if constexpr (ModelEstimator::doesNormalizationForNonMinimalFitting()) final_weights.emplace_back(weight); else final_weights[point_idx] = weight; } // If there are fewer inliers than the size of the minimal sample interupt the procedure if (sigma_inliers.size() < sample_size) return false; // Estimate the model parameters using weighted least-squares fitting if (!estimator_.estimateModelNonminimal( points_, // All input points &(sigma_inliers)[0], // Points which have higher than 0 probability of being inlier static_cast<int>(sigma_inliers.size()), // Number of possible inliers &sigma_models, // Estimated models &(final_weights)[0])) // Weights of points return false; bool is_model_updated = false; if (sigma_models.size() == 1 && // If only a single model is estimated estimator_.isValidModel(sigma_models.back(), points_, sigma_inliers, &(sigma_inliers)[0], interrupting_threshold, is_model_updated)) // and it is valid { // Return the refined model refined_model_ = sigma_models.back(); // Calculate the score of the model and the implied iteration number double marginalized_iteration_number; getModelQuality(points_, // All the input points refined_model_, // The estimated model estimator_, // The estimator marginalized_iteration_number, // The marginalized inlier ratio score_.score); // The marginalized score if (marginalized_iteration_number < 0 || std::isnan(marginalized_iteration_number)) last_iteration_number = std::numeric_limits<int>::max(); else last_iteration_number = static_cast<int>(round(marginalized_iteration_number)); return true; } return false; } template <class DatumType, class ModelEstimator> bool MAGSAC<DatumType, ModelEstimator>::sigmaConsensusPlusPlus( const cv::Mat &points_, const gcransac::Model& model_, gcransac::Model& refined_model_, ModelScore &score_, const ModelEstimator &estimator_, const ModelScore &best_score_) { // The degrees of freedom of the data from which the model is estimated. // E.g., for models coming from point correspondences (x1,y1,x2,y2), it is 4. constexpr size_t degrees_of_freedom = ModelEstimator::getDegreesOfFreedom(); // A 0.99 quantile of the Chi^2-distribution to convert sigma values to residuals constexpr double k = ModelEstimator::getSigmaQuantile(); // A multiplier to convert residual values to sigmas constexpr double threshold_to_sigma_multiplier = 1.0 / k; // Calculating k^2 / 2 which will be used for the estimation and, // due to being constant, it is better to calculate it a priori. constexpr double squared_k_per_2 = k * k / 2.0; // Calculating (DoF - 1) / 2 which will be used for the estimation and, // due to being constant, it is better to calculate it a priori. constexpr double dof_minus_one_per_two = (degrees_of_freedom - 1.0) / 2.0; // TODO: check constexpr double C = ModelEstimator::getC(); // The size of a minimal sample used for the estimation constexpr size_t sample_size = estimator_.sampleSize(); // Calculating 2^(DoF - 1) which will be used for the estimation and, // due to being constant, it is better to calculate it a priori. static const double two_ad_dof = std::pow(2.0, dof_minus_one_per_two); // Calculating C * 2^(DoF - 1) which will be used for the estimation and, // due to being constant, it is better to calculate it a priori. static const double C_times_two_ad_dof = C * two_ad_dof; // Calculating the gamma value of (DoF - 1) / 2 which will be used for the estimation and, // due to being constant, it is better to calculate it a priori. static const double gamma_value = tgamma(dof_minus_one_per_two); // Calculating the upper incomplete gamma value of (DoF - 1) / 2 with k^2 / 2. constexpr double gamma_k = ModelEstimator::getUpperIncompleteGammaOfK(); // Calculating the lower incomplete gamma value of (DoF - 1) / 2 which will be used for the estimation and, // due to being constant, it is better to calculate it a priori. static const double gamma_difference = gamma_value - gamma_k; // The number of points provided const int point_number = points_.rows; // The manually set maximum inlier-outlier threshold double current_maximum_sigma = this->maximum_threshold; // Calculating the pairs of (residual, point index). std::vector< std::pair<double, size_t> > residuals; // Occupy the maximum required memory to avoid doing it later. residuals.reserve(point_number); // If it is not the first run, consider the previous best and interrupt the validation when there is no chance of being better if (best_score_.inlier_number > 0) { // Number of points close to the previous so-far-the-best model. // This model should have more inliers. int points_remaining = best_score_.inlier_number; // Collect the points which are closer than the threshold which the maximum sigma implies for (int point_idx = 0; point_idx < point_number; ++point_idx) { // Calculate the residual of the current point const double residual = estimator_.residual(points_.row(point_idx), model_); if (current_maximum_sigma > residual) { // Store the residual of the current point and its index residuals.emplace_back(std::make_pair(residual, point_idx)); // Count points which are closer than a reference threshold to speed up the procedure if (residual < interrupting_threshold) --points_remaining; } // Interrupt if there is no chance of being better // TODO: replace this part by SPRT test if (point_number - point_idx < points_remaining) return false; } // Store the number of really close inliers just to speed up the procedure // by interrupting the next verifications. score_.inlier_number = best_score_.inlier_number - points_remaining; } else { // The number of really close points size_t points_close = 0; // Collect the points which are closer than the threshold which the maximum sigma implies for (size_t point_idx = 0; point_idx < point_number; ++point_idx) { // Calculate the residual of the current point const double residual = estimator_.residual(points_.row(point_idx), model_); if (current_maximum_sigma > residual) { // Store the residual of the current point and its index residuals.emplace_back(std::make_pair(residual, point_idx)); // Count points which are closer than a reference threshold to speed up the procedure if (residual < interrupting_threshold) ++points_close; } } // Store the number of really close inliers just to speed up the procedure // by interrupting the next verifications. score_.inlier_number = points_close; } // Models fit by weighted least-squares fitting std::vector<gcransac::Model> sigma_models; // Points used in the weighted least-squares fitting std::vector<size_t> sigma_inliers; // Weights used in the the weighted least-squares fitting std::vector<double> sigma_weights; // Number of points considered in the fitting const size_t possible_inlier_number = residuals.size(); // Occupy the memory to avoid doing it inside the calculation possibly multiple times sigma_inliers.reserve(possible_inlier_number); // Occupy the memory to avoid doing it inside the calculation possibly multiple times sigma_weights.reserve(possible_inlier_number); // Calculate 2 * \sigma_{max}^2 a priori const double squared_sigma_max_2 = current_maximum_sigma * current_maximum_sigma * 2.0; // Divide C * 2^(DoF - 1) by \sigma_{max} a priori const double one_over_sigma = C_times_two_ad_dof / current_maximum_sigma; // Calculate the weight of a point with 0 residual (i.e., fitting perfectly) a priori const double weight_zero = one_over_sigma * gamma_difference; // Initialize the polished model with the initial one gcransac::Model polished_model = model_; // A flag to determine if the initial model has been updated bool updated = false; // Do the iteratively re-weighted least squares fitting for (size_t iterations = 0; iterations < number_of_irwls_iters; ++iterations) { // If the current iteration is not the first, the set of possibly inliers // (i.e., points closer than the maximum threshold) have to be recalculated. if (iterations > 0) { // The number of points close to the model size_t points_close = 0; // Remove everything from the residual vector residuals.clear(); // Collect the points which are closer than the maximum threshold for (size_t point_idx = 0; point_idx < point_number; ++point_idx) { // Calculate the residual of the current point const double residual = estimator_.residual(points_.row(point_idx), polished_model); if (current_maximum_sigma > residual) { // Store the residual of the current point and its index residuals.emplace_back(std::make_pair(residual, point_idx)); // Count points which are closer than a reference threshold to speed up the procedure if (residual < interrupting_threshold) ++points_close; } } // Store the number of really close inliers just to speed up the procedure // by interrupting the next verifications. score_.inlier_number = points_close; // Number of points closer than the threshold const size_t possible_inlier_number = residuals.size(); // Clear the inliers and weights sigma_inliers.clear(); sigma_weights.clear(); // Occupy the memory for the inliers and weights sigma_inliers.reserve(possible_inlier_number); sigma_weights.reserve(possible_inlier_number); } if constexpr (!ModelEstimator::doesNormalizationForNonMinimalFitting()) sigma_weights.resize(point_number, 0); // Calculate the weight of each point for (const auto &[residual, idx] : residuals) { // The weight double weight = 0.0; // If the residual is ~0, the point fits perfectly and it is handled differently if (residual < std::numeric_limits<double>::epsilon()) weight = weight_zero; else { // Calculate the squared residual const double squared_residual = residual * residual; // Get the position of the gamma value in the lookup table size_t x = round(precision_of_stored_gammas * squared_residual / squared_sigma_max_2); // Put the index of the point into the vector of points used for the least squares fitting sigma_inliers.emplace_back(idx); // If the sought gamma value is not stored in the lookup, return the closest element if (stored_gamma_number < x) x = stored_gamma_number; // Calculate the weight of the point weight = one_over_sigma * (stored_gamma_values[x] - gamma_k); } // Store the weight of the point if constexpr (ModelEstimator::doesNormalizationForNonMinimalFitting()) sigma_weights.emplace_back(weight); else sigma_weights[idx] = weight; } // If there are fewer than the minimum point close to the model, // terminate. if (sigma_inliers.size() < sample_size) return false; // Estimate the model parameters using weighted least-squares fitting if (!estimator_.estimateModelNonminimal( points_, // All input points &(sigma_inliers)[0], // Points which have higher than 0 probability of being inlier static_cast<int>(sigma_inliers.size()), // Number of possible inliers &sigma_models, // Estimated models &(sigma_weights)[0])) // Weights of points { // If the estimation failed and the iteration was never successfull, // terminate with failure. if (iterations == 0) return false; // Otherwise, if the iteration was successfull at least once, // simply break it. break; } // Update the model parameters polished_model = sigma_models[0]; // Clear the vector of models and keep only the best sigma_models.clear(); // The model has been updated updated = true; } bool is_model_updated = false; if (updated && // If the model has been updated estimator_.isValidModel(polished_model, points_, sigma_inliers, &(sigma_inliers[0]), interrupting_threshold, is_model_updated)) // and it is valid { // Return the refined model refined_model_ = polished_model; // Calculate the score of the model and the implied iteration number double marginalized_iteration_number; getModelQualityPlusPlus(points_, // All the input points refined_model_, // The estimated model estimator_, // The estimator score_.score, // The marginalized score best_score_.score); // The score of the previous so-far-the-best model // Update the iteration number last_iteration_number = log_confidence / log(1.0 - std::pow(static_cast<double>(score_.inlier_number) / point_number, sample_size)); return true; } return false; } template <class DatumType, class ModelEstimator> void MAGSAC<DatumType, ModelEstimator>::getModelQualityPlusPlus( const cv::Mat &points_, // All data points const gcransac::Model &model_, // The model parameter const ModelEstimator &estimator_, // The model estimator class double &score_, // The score to be calculated const double &previous_best_score_) // The score of the previous so-far-the-best model { // The degrees of freedom of the data from which the model is estimated. // E.g., for models coming from point correspondences (x1,y1,x2,y2), it is 4. constexpr size_t degrees_of_freedom = ModelEstimator::getDegreesOfFreedom(); // A 0.99 quantile of the Chi^2-distribution to convert sigma values to residuals constexpr double k = ModelEstimator::getSigmaQuantile(); // A multiplier to convert residual values to sigmas constexpr double threshold_to_sigma_multiplier = 1.0 / k; // Calculating k^2 / 2 which will be used for the estimation and, // due to being constant, it is better to calculate it a priori. constexpr double squared_k_per_2 = k * k / 2.0; // Calculating (DoF - 1) / 2 which will be used for the estimation and, // due to being constant, it is better to calculate it a priori. constexpr double dof_minus_one_per_two = (degrees_of_freedom - 1.0) / 2.0; // Calculating (DoF + 1) / 2 which will be used for the estimation and, // due to being constant, it is better to calculate it a priori. constexpr double dof_plus_one_per_two = (degrees_of_freedom + 1.0) / 2.0; // TODO: check constexpr double C = 0.25; // Calculating 2^(DoF - 1) which will be used for the estimation and, // due to being constant, it is better to calculate it a priori. static const double two_ad_dof_minus_one = std::pow(2.0, dof_minus_one_per_two); // Calculating 2^(DoF + 1) which will be used for the estimation and, // due to being constant, it is better to calculate it a priori. static const double two_ad_dof_plus_one = std::pow(2.0, dof_plus_one_per_two); // Calculate the gamma value of k constexpr double gamma_value_of_k = ModelEstimator::getUpperIncompleteGammaOfK(); // Calculate the lower incomplete gamma value of k constexpr double lower_gamma_value_of_k = ModelEstimator::getLowerIncompleteGammaOfK(); // The number of points provided const int point_number = points_.rows; // The previous best loss const double previous_best_loss = 1.0 / previous_best_score_; // Convert the maximum threshold to a sigma value const double maximum_sigma = threshold_to_sigma_multiplier * maximum_threshold; // Calculate the squared maximum sigma const double maximum_sigma_2 = maximum_sigma * maximum_sigma; // Calculate \sigma_{max}^2 / 2 const double maximum_sigma_2_per_2 = maximum_sigma_2 / 2.0; // Calculate 2 * \sigma_{max}^2 const double maximum_sigma_2_times_2 = maximum_sigma_2 * 2.0; // Calculate the loss implied by an outlier const double outlier_loss = maximum_sigma * two_ad_dof_minus_one * lower_gamma_value_of_k; // Calculating 2^(DoF + 1) / \sigma_{max} which will be used for the estimation and, // due to being constant, it is better to calculate it a priori. const double two_ad_dof_plus_one_per_maximum_sigma = two_ad_dof_plus_one / maximum_sigma; // The loss which a point implies double loss = 0.0, // The total loss regarding the current model total_loss = 0.0; // Iterate through all points to calculate the implied loss for (size_t point_idx = 0; point_idx < point_number; ++point_idx) { // Calculate the residual of the current point const double residual = estimator_.residualForScoring(points_.row(point_idx), model_.descriptor); // If the residual is smaller than the maximum threshold, consider it outlier // and add the loss implied to the total loss. if (maximum_threshold < residual) loss = outlier_loss; else // Otherwise, consider the point inlier, and calculate the implied loss { // Calculate the squared residual const double squared_residual = residual * residual; // Divide the residual by the 2 * \sigma^2 const double squared_residual_per_sigma = squared_residual / maximum_sigma_2_times_2; // Get the position of the gamma value in the lookup table size_t x = round(precision_of_stored_incomplete_gammas * squared_residual_per_sigma); // If the sought gamma value is not stored in the lookup, return the closest element if (stored_incomplete_gamma_number < x) x = stored_incomplete_gamma_number; // Calculate the loss implied by the current point loss = maximum_sigma_2_per_2 * stored_lower_incomplete_gamma_values[x] + squared_residual / 4.0 * (stored_complete_gamma_values[x] - gamma_value_of_k); loss = loss * two_ad_dof_plus_one_per_maximum_sigma; } // Update the total loss total_loss += loss; // Break the validation if there is no chance of being better than the previous // so-far-the-best model. if (previous_best_loss < total_loss) break; } // Calculate the score of the model from the total loss score_ = 1.0 / total_loss; } template <class DatumType, class ModelEstimator> void MAGSAC<DatumType, ModelEstimator>::getModelQuality( const cv::Mat &points_, // All data points const gcransac::Model &model_, // The model parameter const ModelEstimator &estimator_, // The model estimator class double &marginalized_iteration_number_, // The marginalized iteration number to be calculated double &score_) // The score to be calculated { // Set up the parameters constexpr size_t sample_size = estimator_.sampleSize(); const size_t point_number = points_.rows; // Getting the inliers std::vector<std::pair<double, size_t>> all_residuals; all_residuals.reserve(point_number); double max_distance = 0; for (size_t point_idx = 0; point_idx < point_number; ++point_idx) { // Calculate the residual of the current point const double residual = estimator_.residualForScoring(points_.row(point_idx), model_.descriptor); // If the residual is smaller than the maximum threshold, add it to the set of possible inliers if (maximum_threshold > residual) { max_distance = MAX(max_distance, residual); all_residuals.emplace_back(std::make_pair(residual, point_idx)); } } // Set the maximum distance to be slightly bigger than that of the farthest possible inlier max_distance = max_distance + std::numeric_limits<double>::epsilon(); // Number of possible inliers const size_t possible_inlier_number = all_residuals.size(); // The extent of a partition const double threshold_step = max_distance / partition_number; // The maximum threshold considered in each partition std::vector<double> thresholds(partition_number); std::vector<double> thresholds_squared(partition_number); std::vector<double> thresholds_2_squared(partition_number); // Calculating the thresholds for each partition for (size_t i = 0; i < partition_number; ++i) { thresholds[i] = (i + 1) * threshold_step; thresholds_squared[i] = thresholds[i] * thresholds[i]; thresholds_2_squared[i] = 2 * thresholds_squared[i]; } double residual_i, // Residual of the i-th point residual_i_squared, // Squared residual of the i-th poin probability_i; // Probability of the i-th point given the model std::vector<double> inliers(partition_number, 0), // RANSAC score for each partition probabilities(partition_number, 1); // Probabilities for each partition for (size_t point_idx = 0; point_idx < possible_inlier_number; ++point_idx) { residual_i = all_residuals[point_idx].first; residual_i_squared = residual_i * residual_i; for (size_t i = 0; i < partition_number; ++i) { if (residual_i < thresholds[i]) { probability_i = 1.0 - residual_i_squared / thresholds_squared[i]; ++inliers[i]; probabilities[i] += probability_i; } } } score_ = 0; marginalized_iteration_number_ = 0.0; for (auto i = 0; i < partition_number; ++i) { score_ += probabilities[i]; marginalized_iteration_number_ += log_confidence / log(1.0 - std::pow(inliers[i] / point_number, sample_size)); } marginalized_iteration_number_ = marginalized_iteration_number_ / partition_number; }
omp_in_explicit_task.c
// RUN: %libomp-compile-and-run #include <stdio.h> #include <stdlib.h> #include <omp.h> int main() { int res; res = omp_in_explicit_task(); if (res) { printf("error: omp_in_explicit_task: serial1 returned %d\n", res); return 1; } #pragma omp parallel num_threads(2) { int r = omp_in_explicit_task(); if (r) { printf("error: omp_in_explicit_task: par #%d returned %d\n", omp_get_thread_num(), r); exit(1); } #pragma omp task { int r = omp_in_explicit_task(); if (!r) { printf("error: omp_in_explicit_task: task1 #%d returned %d\n", omp_get_thread_num(), r); exit(1); } } #pragma omp task { int r = omp_in_explicit_task(); if (!r) { printf("error: omp_in_explicit_task: task2 #%d returned %d\n", omp_get_thread_num(), r); exit(1); } } } res = omp_in_explicit_task(); if (res) { printf("error: omp_in_explicit_task: serial2 returned %d\n", res); return 1; } printf("passed\n"); return 0; }
DRACC_OMP_001_Buffer_Overflow_Recursion_yes.c
/* Causing a buffer overflow on the accelerator with recursion in line 15. */ #define C 1024 #pragma omp declare target int counter = 0; int rekurs(){ for(int i = 0; i<C; i++){ #pragma omp atomic counter++; rekurs(); } return 0; } #pragma omp end declare target int main(){ #pragma omp target map(tofrom:counter) device(0) rekurs(); return 0; }
integrateFullOrbit.c
/* Wrappers around the C integration code for Full Orbits */ #ifdef _WIN32 #include <Python.h> #endif #include <stdio.h> #include <stdlib.h> #include <stdbool.h> #include <math.h> #include <gsl/gsl_errno.h> #include <gsl/gsl_spline.h> #include <bovy_coords.h> #include <bovy_symplecticode.h> #include <leung_dop853.h> #include <bovy_rk.h> #include <integrateFullOrbit.h> //Potentials #include <galpy_potentials.h> #ifndef M_PI #define M_PI 3.14159265358979323846 #endif #ifndef ORBITS_CHUNKSIZE #define ORBITS_CHUNKSIZE 1 #endif //Macros to export functions in DLL on different OS #if defined(_WIN32) #define EXPORT __declspec(dllexport) #elif defined(__GNUC__) #define EXPORT __attribute__((visibility("default"))) #else // Just do nothing? #define EXPORT #endif #ifdef _WIN32 // On Windows, *need* to define this function to allow the package to be imported #if PY_MAJOR_VERSION >= 3 PyMODINIT_FUNC PyInit_libgalpy(void) { // Python 3 return NULL; } #else PyMODINIT_FUNC initlibgalpy(void) {} // Python 2 #endif #endif /* Function Declarations */ void evalRectForce(double, double *, double *, int, struct potentialArg *); void evalRectDeriv(double, double *, double *, int, struct potentialArg *); void evalRectDeriv_dxdv(double,double *, double *, int, struct potentialArg *); void initMovingObjectSplines(struct potentialArg *, double ** pot_args); void initMovingObjectVelSplines(struct potentialArg *, double ** pot_args); void initChandrasekharDynamicalFrictionSplines(struct potentialArg *, double ** pot_args); /* Actual functions */ void parse_leapFuncArgs_Full(int npot, struct potentialArg * potentialArgs, int ** pot_type, double ** pot_args){ int ii,jj,kk; int nR, nz, nr; double * Rgrid, * zgrid, * potGrid_splinecoeffs; init_potentialArgs(npot,potentialArgs); for (ii=0; ii < npot; ii++){ switch ( *(*pot_type)++ ) { case 0: //LogarithmicHaloPotential, 4 arguments potentialArgs->potentialEval= &LogarithmicHaloPotentialEval; potentialArgs->Rforce= &LogarithmicHaloPotentialRforce; potentialArgs->zforce= &LogarithmicHaloPotentialzforce; potentialArgs->phiforce= &LogarithmicHaloPotentialphiforce; potentialArgs->dens= &LogarithmicHaloPotentialDens; //potentialArgs->R2deriv= &LogarithmicHaloPotentialR2deriv; //potentialArgs->planarphi2deriv= &ZeroForce; //potentialArgs->planarRphideriv= &ZeroForce; potentialArgs->nargs= 4; potentialArgs->requiresVelocity= false; break; case 1: //DehnenBarPotential, 6 arguments potentialArgs->Rforce= &DehnenBarPotentialRforce; potentialArgs->phiforce= &DehnenBarPotentialphiforce; potentialArgs->zforce= &DehnenBarPotentialzforce; potentialArgs->nargs= 6; potentialArgs->requiresVelocity= false; break; case 5: //MiyamotoNagaiPotential, 3 arguments potentialArgs->potentialEval= &MiyamotoNagaiPotentialEval; potentialArgs->Rforce= &MiyamotoNagaiPotentialRforce; potentialArgs->zforce= &MiyamotoNagaiPotentialzforce; potentialArgs->phiforce= &ZeroForce; potentialArgs->dens= &MiyamotoNagaiPotentialDens; //potentialArgs->R2deriv= &MiyamotoNagaiPotentialR2deriv; //potentialArgs->planarphi2deriv= &ZeroForce; //potentialArgs->planarRphideriv= &ZeroForce; potentialArgs->nargs= 3; potentialArgs->requiresVelocity= false; break; case 7: //PowerSphericalPotential, 2 arguments potentialArgs->potentialEval= &PowerSphericalPotentialEval; potentialArgs->Rforce= &PowerSphericalPotentialRforce; potentialArgs->zforce= &PowerSphericalPotentialzforce; potentialArgs->phiforce= &ZeroForce; potentialArgs->dens= &PowerSphericalPotentialDens; //potentialArgs->R2deriv= &PowerSphericalPotentialR2deriv; //potentialArgs->planarphi2deriv= &ZeroForce; //potentialArgs->planarRphideriv= &ZeroForce; potentialArgs->nargs= 2; potentialArgs->requiresVelocity= false; break; case 8: //HernquistPotential, 2 arguments potentialArgs->potentialEval= &HernquistPotentialEval; potentialArgs->Rforce= &HernquistPotentialRforce; potentialArgs->zforce= &HernquistPotentialzforce; potentialArgs->phiforce= &ZeroForce; potentialArgs->dens= &HernquistPotentialDens; //potentialArgs->R2deriv= &HernquistPotentialR2deriv; //potentialArgs->planarphi2deriv= &ZeroForce; //potentialArgs->planarRphideriv= &ZeroForce; potentialArgs->nargs= 2; potentialArgs->requiresVelocity= false; break; case 9: //NFWPotential, 2 arguments potentialArgs->potentialEval= &NFWPotentialEval; potentialArgs->Rforce= &NFWPotentialRforce; potentialArgs->zforce= &NFWPotentialzforce; potentialArgs->phiforce= &ZeroForce; potentialArgs->dens= &NFWPotentialDens; //potentialArgs->R2deriv= &NFWPotentialR2deriv; //potentialArgs->planarphi2deriv= &ZeroForce; //potentialArgs->planarRphideriv= &ZeroForce; potentialArgs->nargs= 2; potentialArgs->requiresVelocity= false; break; case 10: //JaffePotential, 2 arguments potentialArgs->potentialEval= &JaffePotentialEval; potentialArgs->Rforce= &JaffePotentialRforce; potentialArgs->zforce= &JaffePotentialzforce; potentialArgs->phiforce= &ZeroForce; potentialArgs->dens= &JaffePotentialDens; //potentialArgs->R2deriv= &JaffePotentialR2deriv; //potentialArgs->planarphi2deriv= &ZeroForce; //potentialArgs->planarRphideriv= &ZeroForce; potentialArgs->nargs= 2; potentialArgs->requiresVelocity= false; break; case 11: //DoubleExponentialDiskPotential, XX arguments potentialArgs->potentialEval= &DoubleExponentialDiskPotentialEval; potentialArgs->Rforce= &DoubleExponentialDiskPotentialRforce; potentialArgs->zforce= &DoubleExponentialDiskPotentialzforce; potentialArgs->phiforce= &ZeroForce; potentialArgs->dens= &DoubleExponentialDiskPotentialDens; //Look at pot_args to figure out the number of arguments potentialArgs->nargs= (int) (5 + 4 * *(*pot_args+4) ); potentialArgs->requiresVelocity= false; break; case 12: //FlattenedPowerPotential, 4 arguments potentialArgs->potentialEval= &FlattenedPowerPotentialEval; potentialArgs->Rforce= &FlattenedPowerPotentialRforce; potentialArgs->zforce= &FlattenedPowerPotentialzforce; potentialArgs->phiforce= &ZeroForce; potentialArgs->dens= &FlattenedPowerPotentialDens; potentialArgs->nargs= 4; potentialArgs->requiresVelocity= false; break; case 13: //interpRZPotential, XX arguments //Grab the grids and the coefficients nR= (int) *(*pot_args)++; nz= (int) *(*pot_args)++; Rgrid= (double *) malloc ( nR * sizeof ( double ) ); zgrid= (double *) malloc ( nz * sizeof ( double ) ); potGrid_splinecoeffs= (double *) malloc ( nR * nz * sizeof ( double ) ); for (kk=0; kk < nR; kk++) *(Rgrid+kk)= *(*pot_args)++; for (kk=0; kk < nz; kk++) *(zgrid+kk)= *(*pot_args)++; for (kk=0; kk < nR; kk++) put_row(potGrid_splinecoeffs,kk,*pot_args+kk*nz,nz); *pot_args+= nR*nz; potentialArgs->i2d= interp_2d_alloc(nR,nz); interp_2d_init(potentialArgs->i2d,Rgrid,zgrid,potGrid_splinecoeffs, INTERP_2D_LINEAR); //latter bc we already calculated the coeffs potentialArgs->accx= gsl_interp_accel_alloc (); potentialArgs->accy= gsl_interp_accel_alloc (); for (kk=0; kk < nR; kk++) put_row(potGrid_splinecoeffs,kk,*pot_args+kk*nz,nz); *pot_args+= nR*nz; potentialArgs->i2drforce= interp_2d_alloc(nR,nz); interp_2d_init(potentialArgs->i2drforce,Rgrid,zgrid,potGrid_splinecoeffs, INTERP_2D_LINEAR); //latter bc we already calculated the coeffs potentialArgs->accxrforce= gsl_interp_accel_alloc (); potentialArgs->accyrforce= gsl_interp_accel_alloc (); for (kk=0; kk < nR; kk++) put_row(potGrid_splinecoeffs,kk,*pot_args+kk*nz,nz); *pot_args+= nR*nz; potentialArgs->i2dzforce= interp_2d_alloc(nR,nz); interp_2d_init(potentialArgs->i2dzforce,Rgrid,zgrid,potGrid_splinecoeffs, INTERP_2D_LINEAR); //latter bc we already calculated the coeffs potentialArgs->accxzforce= gsl_interp_accel_alloc (); potentialArgs->accyzforce= gsl_interp_accel_alloc (); potentialArgs->potentialEval= &interpRZPotentialEval; potentialArgs->Rforce= &interpRZPotentialRforce; potentialArgs->zforce= &interpRZPotentialzforce; potentialArgs->phiforce= &ZeroForce; potentialArgs->nargs= 2; //clean up free(Rgrid); free(zgrid); free(potGrid_splinecoeffs); potentialArgs->requiresVelocity= false; break; case 14: //IsochronePotential, 2 arguments potentialArgs->potentialEval= &IsochronePotentialEval; potentialArgs->Rforce= &IsochronePotentialRforce; potentialArgs->zforce= &IsochronePotentialzforce; potentialArgs->phiforce= &ZeroForce; potentialArgs->dens= &IsochronePotentialDens; potentialArgs->nargs= 2; potentialArgs->requiresVelocity= false; break; case 15: //PowerSphericalwCutoffPotential, 3 arguments potentialArgs->potentialEval= &PowerSphericalPotentialwCutoffEval; potentialArgs->Rforce= &PowerSphericalPotentialwCutoffRforce; potentialArgs->zforce= &PowerSphericalPotentialwCutoffzforce; potentialArgs->phiforce= &ZeroForce; potentialArgs->dens= &PowerSphericalPotentialwCutoffDens; //potentialArgs->R2deriv= &PowerSphericalPotentialR2deriv; //potentialArgs->planarphi2deriv= &ZeroForce; //potentialArgs->planarRphideriv= &ZeroForce; potentialArgs->nargs= 3; potentialArgs->requiresVelocity= false; break; case 16: //KuzminKutuzovStaeckelPotential, 3 arguments potentialArgs->potentialEval= &KuzminKutuzovStaeckelPotentialEval; potentialArgs->Rforce= &KuzminKutuzovStaeckelPotentialRforce; potentialArgs->zforce= &KuzminKutuzovStaeckelPotentialzforce; potentialArgs->phiforce= &ZeroForce; //potentialArgs->R2deriv= &KuzminKutuzovStaeckelPotentialR2deriv; potentialArgs->nargs= 3; potentialArgs->requiresVelocity= false; break; case 17: //PlummerPotential, 2 arguments potentialArgs->potentialEval= &PlummerPotentialEval; potentialArgs->Rforce= &PlummerPotentialRforce; potentialArgs->zforce= &PlummerPotentialzforce; potentialArgs->phiforce= &ZeroForce; potentialArgs->dens= &PlummerPotentialDens; //potentialArgs->R2deriv= &PlummerPotentialR2deriv; potentialArgs->nargs= 2; potentialArgs->requiresVelocity= false; break; case 18: //PseudoIsothermalPotential, 2 arguments potentialArgs->potentialEval= &PseudoIsothermalPotentialEval; potentialArgs->Rforce= &PseudoIsothermalPotentialRforce; potentialArgs->zforce= &PseudoIsothermalPotentialzforce; potentialArgs->phiforce= &ZeroForce; potentialArgs->dens= &PseudoIsothermalPotentialDens; //potentialArgs->R2deriv= &PseudoIsothermalPotentialR2deriv; potentialArgs->nargs= 2; potentialArgs->requiresVelocity= false; break; case 19: //KuzminDiskPotential, 2 arguments potentialArgs->potentialEval= &KuzminDiskPotentialEval; potentialArgs->Rforce= &KuzminDiskPotentialRforce; potentialArgs->zforce= &KuzminDiskPotentialzforce; potentialArgs->phiforce= &ZeroForce; potentialArgs->nargs= 2; potentialArgs->requiresVelocity= false; break; case 20: //BurkertPotential, 2 arguments potentialArgs->potentialEval= &BurkertPotentialEval; potentialArgs->Rforce= &BurkertPotentialRforce; potentialArgs->zforce= &BurkertPotentialzforce; potentialArgs->dens= &BurkertPotentialDens; potentialArgs->phiforce= &ZeroForce; potentialArgs->nargs= 2; potentialArgs->requiresVelocity= false; break; case 21: //TriaxialHernquistPotential, lots of arguments potentialArgs->potentialEval= &EllipsoidalPotentialEval; potentialArgs->Rforce = &EllipsoidalPotentialRforce; potentialArgs->zforce = &EllipsoidalPotentialzforce; potentialArgs->phiforce = &EllipsoidalPotentialphiforce; potentialArgs->dens= &EllipsoidalPotentialDens; // Also assign functions specific to EllipsoidalPotential potentialArgs->psi= &TriaxialHernquistPotentialpsi; potentialArgs->mdens= &TriaxialHernquistPotentialmdens; potentialArgs->mdensDeriv= &TriaxialHernquistPotentialmdensDeriv; potentialArgs->nargs = (int) (21 + *(*pot_args+7) + 2 * *(*pot_args + (int) (*(*pot_args+7) + 20))); potentialArgs->requiresVelocity= false; break; case 22: //TriaxialNFWPotential, lots of arguments potentialArgs->potentialEval= &EllipsoidalPotentialEval; potentialArgs->Rforce = &EllipsoidalPotentialRforce; potentialArgs->zforce = &EllipsoidalPotentialzforce; potentialArgs->phiforce = &EllipsoidalPotentialphiforce; potentialArgs->dens= &EllipsoidalPotentialDens; // Also assign functions specific to EllipsoidalPotential potentialArgs->psi= &TriaxialNFWPotentialpsi; potentialArgs->mdens= &TriaxialNFWPotentialmdens; potentialArgs->mdensDeriv= &TriaxialNFWPotentialmdensDeriv; potentialArgs->nargs = (int) (21 + *(*pot_args+7) + 2 * *(*pot_args + (int) (*(*pot_args+7) + 20))); potentialArgs->requiresVelocity= false; break; case 23: //TriaxialJaffePotential, lots of arguments potentialArgs->potentialEval= &EllipsoidalPotentialEval; potentialArgs->Rforce = &EllipsoidalPotentialRforce; potentialArgs->zforce = &EllipsoidalPotentialzforce; potentialArgs->phiforce = &EllipsoidalPotentialphiforce; potentialArgs->dens= &EllipsoidalPotentialDens; // Also assign functions specific to EllipsoidalPotential potentialArgs->psi= &TriaxialJaffePotentialpsi; potentialArgs->mdens= &TriaxialJaffePotentialmdens; potentialArgs->mdensDeriv= &TriaxialJaffePotentialmdensDeriv; potentialArgs->nargs = (int) (21 + *(*pot_args+7) + 2 * *(*pot_args + (int) (*(*pot_args+7) + 20))); potentialArgs->requiresVelocity= false; break; case 24: //SCFPotential, many arguments potentialArgs->potentialEval= &SCFPotentialEval; potentialArgs->Rforce= &SCFPotentialRforce; potentialArgs->zforce= &SCFPotentialzforce; potentialArgs->phiforce= &SCFPotentialphiforce; potentialArgs->dens= &SCFPotentialDens; potentialArgs->nargs= (int) (5 + (1 + *(*pot_args + 1)) * *(*pot_args+2) * *(*pot_args+3)* *(*pot_args+4) + 7); potentialArgs->requiresVelocity= false; break; case 25: //SoftenedNeedleBarPotential, 13 arguments potentialArgs->potentialEval= &SoftenedNeedleBarPotentialEval; potentialArgs->Rforce= &SoftenedNeedleBarPotentialRforce; potentialArgs->zforce= &SoftenedNeedleBarPotentialzforce; potentialArgs->phiforce= &SoftenedNeedleBarPotentialphiforce; potentialArgs->nargs= (int) 13; potentialArgs->requiresVelocity= false; break; case 26: //DiskSCFPotential, nsigma+3 arguments potentialArgs->potentialEval= &DiskSCFPotentialEval; potentialArgs->Rforce= &DiskSCFPotentialRforce; potentialArgs->zforce= &DiskSCFPotentialzforce; potentialArgs->dens= &DiskSCFPotentialDens; potentialArgs->phiforce= &ZeroForce; potentialArgs->nargs= (int) **pot_args + 3; potentialArgs->requiresVelocity= false; break; case 27: // SpiralArmsPotential, 10 arguments + array of Cs potentialArgs->Rforce = &SpiralArmsPotentialRforce; potentialArgs->zforce = &SpiralArmsPotentialzforce; potentialArgs->phiforce = &SpiralArmsPotentialphiforce; //potentialArgs->R2deriv = &SpiralArmsPotentialR2deriv; //potentialArgs->z2deriv = &SpiralArmsPotentialz2deriv; potentialArgs->phi2deriv = &SpiralArmsPotentialphi2deriv; //potentialArgs->Rzderiv = &SpiralArmsPotentialRzderiv; potentialArgs->Rphideriv = &SpiralArmsPotentialRphideriv; potentialArgs->nargs = (int) 10 + **pot_args; potentialArgs->requiresVelocity= false; break; case 30: // PerfectEllipsoidPotential, lots of arguments potentialArgs->potentialEval= &EllipsoidalPotentialEval; potentialArgs->Rforce = &EllipsoidalPotentialRforce; potentialArgs->zforce = &EllipsoidalPotentialzforce; potentialArgs->phiforce = &EllipsoidalPotentialphiforce; potentialArgs->dens= &EllipsoidalPotentialDens; //potentialArgs->R2deriv = &EllipsoidalPotentialR2deriv; //potentialArgs->z2deriv = &EllipsoidalPotentialz2deriv; //potentialArgs->phi2deriv = &EllipsoidalPotentialphi2deriv; //potentialArgs->Rzderiv = &EllipsoidalPotentialRzderiv; //potentialArgs->Rphideriv = &EllipsoidalPotentialRphideriv; // Also assign functions specific to EllipsoidalPotential potentialArgs->psi= &PerfectEllipsoidPotentialpsi; potentialArgs->mdens= &PerfectEllipsoidPotentialmdens; potentialArgs->mdensDeriv= &PerfectEllipsoidPotentialmdensDeriv; potentialArgs->nargs = (int) (21 + *(*pot_args+7) + 2 * *(*pot_args + (int) (*(*pot_args+7) + 20))); potentialArgs->requiresVelocity= false; break; // 31: KGPotential // 32: IsothermalDiskPotential case 33: //DehnenCoreSphericalPotential, 2 arguments potentialArgs->potentialEval= &DehnenCoreSphericalPotentialEval; potentialArgs->Rforce= &DehnenCoreSphericalPotentialRforce; potentialArgs->zforce= &DehnenCoreSphericalPotentialzforce; potentialArgs->phiforce= &ZeroForce; potentialArgs->dens= &DehnenCoreSphericalPotentialDens; //potentialArgs->R2deriv= &DehnenCoreSphericalPotentialR2deriv; //potentialArgs->planarphi2deriv= &ZeroForce; //potentialArgs->planarRphideriv= &ZeroForce; potentialArgs->nargs= 2; potentialArgs->requiresVelocity= false; break; case 34: //DehnenSphericalPotential, 3 arguments potentialArgs->potentialEval= &DehnenSphericalPotentialEval; potentialArgs->Rforce= &DehnenSphericalPotentialRforce; potentialArgs->zforce= &DehnenSphericalPotentialzforce; potentialArgs->phiforce= &ZeroForce; potentialArgs->dens= &DehnenSphericalPotentialDens; //potentialArgs->R2deriv= &DehnenSphericalPotentialR2deriv; //potentialArgs->planarphi2deriv= &ZeroForce; //potentialArgs->planarRphideriv= &ZeroForce; potentialArgs->nargs= 3; potentialArgs->requiresVelocity= false; break; case 35: //HomogeneousSpherePotential, 3 arguments potentialArgs->potentialEval= &HomogeneousSpherePotentialEval; potentialArgs->Rforce= &HomogeneousSpherePotentialRforce; potentialArgs->zforce= &HomogeneousSpherePotentialzforce; potentialArgs->phiforce= &ZeroForce; potentialArgs->dens= &HomogeneousSpherePotentialDens; potentialArgs->nargs= 3; potentialArgs->requiresVelocity= false; break; case 36: //interpSphericalPotential, XX arguments // Set up 1 spline in potentialArgs potentialArgs->nspline1d= 1; potentialArgs->spline1d= (gsl_spline **) \ malloc ( potentialArgs->nspline1d*sizeof ( gsl_spline *) ); potentialArgs->acc1d= (gsl_interp_accel **) \ malloc ( potentialArgs->nspline1d * sizeof ( gsl_interp_accel * ) ); // allocate accelerator *potentialArgs->acc1d= gsl_interp_accel_alloc(); // Set up interpolater nr= (int) **pot_args; *potentialArgs->spline1d= gsl_spline_alloc(gsl_interp_cspline,nr); gsl_spline_init(*potentialArgs->spline1d,*pot_args+1,*pot_args+1+nr,nr); *pot_args+= 2*nr+1; // Bind forces potentialArgs->potentialEval= &SphericalPotentialEval; potentialArgs->Rforce = &SphericalPotentialRforce; potentialArgs->zforce = &SphericalPotentialzforce; potentialArgs->phiforce= &ZeroForce; potentialArgs->dens= &SphericalPotentialDens; // Also assign functions specific to SphericalPotential potentialArgs->revaluate= &interpSphericalPotentialrevaluate; potentialArgs->rforce= &interpSphericalPotentialrforce; potentialArgs->r2deriv= &interpSphericalPotentialr2deriv; potentialArgs->rdens= &interpSphericalPotentialrdens; potentialArgs->nargs = (int) 6; potentialArgs->requiresVelocity= false; break; case 37: // TriaxialGaussianPotential, lots of arguments potentialArgs->potentialEval= &EllipsoidalPotentialEval; potentialArgs->Rforce = &EllipsoidalPotentialRforce; potentialArgs->zforce = &EllipsoidalPotentialzforce; potentialArgs->phiforce = &EllipsoidalPotentialphiforce; potentialArgs->dens= &EllipsoidalPotentialDens; //potentialArgs->R2deriv = &EllipsoidalPotentialR2deriv; //potentialArgs->z2deriv = &EllipsoidalPotentialz2deriv; //potentialArgs->phi2deriv = &EllipsoidalPotentialphi2deriv; //potentialArgs->Rzderiv = &EllipsoidalPotentialRzderiv; //potentialArgs->Rphideriv = &EllipsoidalPotentialRphideriv; // Also assign functions specific to EllipsoidalPotential potentialArgs->psi= &TriaxialGaussianPotentialpsi; potentialArgs->mdens= &TriaxialGaussianPotentialmdens; potentialArgs->mdensDeriv= &TriaxialGaussianPotentialmdensDeriv; potentialArgs->nargs = (int) (21 + *(*pot_args+7) + 2 * *(*pot_args + (int) (*(*pot_args+7) + 20))); potentialArgs->requiresVelocity= false; break; case 38: //LMCDynamicalFrictionForce potentialArgs->RforceVelocity= &LMCDynamicalFrictionForceRforce; potentialArgs->zforceVelocity= &LMCDynamicalFrictionForcezforce; potentialArgs->phiforceVelocity= &LMCDynamicalFrictionForcephiforce; potentialArgs->nargs= (int) 3; potentialArgs->requiresVelocity= true; break; //////////////////////////////// WRAPPERS ///////////////////////////////////// case -1: //DehnenSmoothWrapperPotential potentialArgs->potentialEval= &DehnenSmoothWrapperPotentialEval; potentialArgs->Rforce= &DehnenSmoothWrapperPotentialRforce; potentialArgs->zforce= &DehnenSmoothWrapperPotentialzforce; potentialArgs->phiforce= &DehnenSmoothWrapperPotentialphiforce; potentialArgs->nargs= (int) 4; potentialArgs->requiresVelocity= false; break; case -2: //SolidBodyRotationWrapperPotential potentialArgs->Rforce= &SolidBodyRotationWrapperPotentialRforce; potentialArgs->zforce= &SolidBodyRotationWrapperPotentialzforce; potentialArgs->phiforce= &SolidBodyRotationWrapperPotentialphiforce; potentialArgs->nargs= (int) 3; potentialArgs->requiresVelocity= false; break; case -4: //CorotatingRotationWrapperPotential potentialArgs->Rforce= &CorotatingRotationWrapperPotentialRforce; potentialArgs->zforce= &CorotatingRotationWrapperPotentialzforce; potentialArgs->phiforce= &CorotatingRotationWrapperPotentialphiforce; potentialArgs->nargs= (int) 5; potentialArgs->requiresVelocity= false; break; case -5: //GaussianAmplitudeWrapperPotential potentialArgs->potentialEval= &GaussianAmplitudeWrapperPotentialEval; potentialArgs->Rforce= &GaussianAmplitudeWrapperPotentialRforce; potentialArgs->zforce= &GaussianAmplitudeWrapperPotentialzforce; potentialArgs->phiforce= &GaussianAmplitudeWrapperPotentialphiforce; potentialArgs->nargs= (int) 3; potentialArgs->requiresVelocity= false; break; case -6: //MovingObjectPotential potentialArgs->Rforce= &MovingObjectPotentialRforce; potentialArgs->zforce= &MovingObjectPotentialzforce; potentialArgs->phiforce= &MovingObjectPotentialphiforce; potentialArgs->nargs= (int) 3; potentialArgs->requiresVelocity= false; break; case -7: //ChandrasekharDynamicalFrictionForce potentialArgs->RforceVelocity= &ChandrasekharDynamicalFrictionForceRforce; potentialArgs->zforceVelocity= &ChandrasekharDynamicalFrictionForcezforce; potentialArgs->phiforceVelocity= &ChandrasekharDynamicalFrictionForcephiforce; potentialArgs->nargs= (int) 16; potentialArgs->requiresVelocity= true; break; case -8: //ReflexMotion potentialArgs->Rforce= &ReflexMotionRforce; potentialArgs->zforce= &ReflexMotionzforce; potentialArgs->phiforce= &ReflexMotionphiforce; potentialArgs->nargs= (int) 3; potentialArgs->requiresVelocity= false; break; case -9: //MovingObjectDissipative potentialArgs->RforceVelocity= &MovingObjectDissipativeRforce; potentialArgs->zforceVelocity= &MovingObjectDissipativezforce; potentialArgs->phiforceVelocity= &MovingObjectDissipativephiforce; potentialArgs->nargs= (int) 3; potentialArgs->requiresVelocity= true; break; } int setupMovingObjectSplines = *(*pot_type-1) == -6 ? 1 : 0; int setupChandrasekharDynamicalFrictionSplines = *(*pot_type-1) == -7 ? 1 : 0; int setupReflexMotionSplines = *(*pot_type-1) == -8 ? 1 : 0; int setupMovingObjectDissipativeSplines= *(*pot_type-1) == -9 ? 1 : 0; if ( *(*pot_type-1) < 0 ) { // Parse wrapped potential for wrappers potentialArgs->nwrapped= (int) *(*pot_args)++; potentialArgs->wrappedPotentialArg= \ (struct potentialArg *) malloc ( potentialArgs->nwrapped \ * sizeof (struct potentialArg) ); parse_leapFuncArgs_Full(potentialArgs->nwrapped, potentialArgs->wrappedPotentialArg, pot_type,pot_args); } if (setupMovingObjectSplines) initMovingObjectSplines(potentialArgs, pot_args); if (setupMovingObjectDissipativeSplines) initMovingObjectVelSplines(potentialArgs, pot_args); if (setupReflexMotionSplines) initMovingObjectSplines(potentialArgs, pot_args); if (setupChandrasekharDynamicalFrictionSplines) initChandrasekharDynamicalFrictionSplines(potentialArgs,pot_args); potentialArgs->args= (double *) malloc( potentialArgs->nargs * sizeof(double)); for (jj=0; jj < potentialArgs->nargs; jj++){ *(potentialArgs->args)= *(*pot_args)++; potentialArgs->args++; } potentialArgs->args-= potentialArgs->nargs; potentialArgs++; } potentialArgs-= npot; } EXPORT void integrateFullOrbit(int nobj, double *yo, int nt, double *t, int npot, int * pot_type, double * pot_args, double dt, double rtol, double atol, double *result, int * err, int odeint_type){ //Set up the forces, first count int ii,jj; int dim; int max_threads; int * thread_pot_type; double * thread_pot_args; max_threads= ( nobj < omp_get_max_threads() ) ? nobj : omp_get_max_threads(); // Because potentialArgs may cache, safest to have one / thread struct potentialArg * potentialArgs= (struct potentialArg *) malloc ( max_threads * npot * sizeof (struct potentialArg) ); #pragma omp parallel for schedule(static,1) private(ii,thread_pot_type,thread_pot_args) num_threads(max_threads) for (ii=0; ii < max_threads; ii++) { thread_pot_type= pot_type; // need to make thread-private pointers, bc thread_pot_args= pot_args; // these pointers are changed in parse_... parse_leapFuncArgs_Full(npot,potentialArgs+ii*npot, &thread_pot_type,&thread_pot_args); } //Integrate void (*odeint_func)(void (*func)(double, double *, double *, int, struct potentialArg *), int, double *, int, double, double *, int, struct potentialArg *, double, double, double *,int *); void (*odeint_deriv_func)(double, double *, double *, int,struct potentialArg *); switch ( odeint_type ) { case 0: //leapfrog odeint_func= &leapfrog; odeint_deriv_func= &evalRectForce; dim= 3; break; case 1: //RK4 odeint_func= &bovy_rk4; odeint_deriv_func= &evalRectDeriv; dim= 6; break; case 2: //RK6 odeint_func= &bovy_rk6; odeint_deriv_func= &evalRectDeriv; dim= 6; break; case 3: //symplec4 odeint_func= &symplec4; odeint_deriv_func= &evalRectForce; dim= 3; break; case 4: //symplec6 odeint_func= &symplec6; odeint_deriv_func= &evalRectForce; dim= 3; break; case 5: //DOPR54 odeint_func= &bovy_dopr54; odeint_deriv_func= &evalRectDeriv; dim= 6; break; case 6: //DOP853 odeint_func= &dop853; odeint_deriv_func= &evalRectDeriv; dim= 6; break; } #pragma omp parallel for schedule(dynamic,ORBITS_CHUNKSIZE) private(ii,jj) num_threads(max_threads) for (ii=0; ii < nobj; ii++) { cyl_to_rect_galpy(yo+6*ii); odeint_func(odeint_deriv_func,dim,yo+6*ii,nt,dt,t, npot,potentialArgs+omp_get_thread_num()*npot,rtol,atol, result+6*nt*ii,err+ii); for (jj=0; jj < nt; jj++) rect_to_cyl_galpy(result+6*jj+6*nt*ii); } //Free allocated memory #pragma omp parallel for schedule(static,1) private(ii) num_threads(max_threads) for (ii=0; ii < max_threads; ii++) free_potentialArgs(npot,potentialArgs+ii*npot); free(potentialArgs); //Done! } // LCOV_EXCL_START void integrateOrbit_dxdv(double *yo, int nt, double *t, int npot, int * pot_type, double * pot_args, double rtol, double atol, double *result, int * err, int odeint_type){ //Set up the forces, first count int dim; struct potentialArg * potentialArgs= (struct potentialArg *) malloc ( npot * sizeof (struct potentialArg) ); parse_leapFuncArgs_Full(npot,potentialArgs,&pot_type,&pot_args); //Integrate void (*odeint_func)(void (*func)(double, double *, double *, int, struct potentialArg *), int, double *, int, double, double *, int, struct potentialArg *, double, double, double *,int *); void (*odeint_deriv_func)(double, double *, double *, int,struct potentialArg *); switch ( odeint_type ) { case 0: //leapfrog odeint_func= &leapfrog; odeint_deriv_func= &evalRectForce; dim= 6; break; case 1: //RK4 odeint_func= &bovy_rk4; odeint_deriv_func= &evalRectDeriv_dxdv; dim= 12; break; case 2: //RK6 odeint_func= &bovy_rk6; odeint_deriv_func= &evalRectDeriv_dxdv; dim= 12; break; case 3: //symplec4 odeint_func= &symplec4; odeint_deriv_func= &evalRectForce; dim= 6; break; case 4: //symplec6 odeint_func= &symplec6; odeint_deriv_func= &evalRectForce; dim= 6; break; case 5: //DOPR54 odeint_func= &bovy_dopr54; odeint_deriv_func= &evalRectDeriv_dxdv; dim= 12; break; case 6: //DOP853 odeint_func= &dop853; odeint_deriv_func= &evalRectDeriv_dxdv; dim= 12; break; } odeint_func(odeint_deriv_func,dim,yo,nt,-9999.99,t,npot,potentialArgs, rtol,atol,result,err); //Free allocated memory free_potentialArgs(npot,potentialArgs); free(potentialArgs); //Done! } // LCOV_EXCL_STOP void evalRectForce(double t, double *q, double *a, int nargs, struct potentialArg * potentialArgs){ double sinphi, cosphi, x, y, phi,R,Rforce,phiforce, z, zforce; //q is rectangular so calculate R and phi x= *q; y= *(q+1); z= *(q+2); R= sqrt(x*x+y*y); phi= acos(x/R); sinphi= y/R; cosphi= x/R; if ( y < 0. ) phi= 2.*M_PI-phi; //Calculate the forces Rforce= calcRforce(R,z,phi,t,nargs,potentialArgs); zforce= calczforce(R,z,phi,t,nargs,potentialArgs); phiforce= calcPhiforce(R,z,phi,t,nargs,potentialArgs); *a++= cosphi*Rforce-1./R*sinphi*phiforce; *a++= sinphi*Rforce+1./R*cosphi*phiforce; *a= zforce; } void evalRectDeriv(double t, double *q, double *a, int nargs, struct potentialArg * potentialArgs){ double sinphi, cosphi, x, y, phi,R,Rforce,phiforce,z,zforce,vR,vT; //first three derivatives are just the velocities *a++= *(q+3); *a++= *(q+4); *a++= *(q+5); //Rest is force //q is rectangular so calculate R and phi, vR and vT (for dissipative) x= *q; y= *(q+1); z= *(q+2); R= sqrt(x*x+y*y); phi= acos(x/R); sinphi= y/R; cosphi= x/R; if ( y < 0. ) phi= 2.*M_PI-phi; vR= *(q+3) * cosphi + *(q+4) * sinphi; vT= -*(q+3) * sinphi + *(q+4) * cosphi; //Calculate the forces Rforce= calcRforce(R,z,phi,t,nargs,potentialArgs,vR,vT,*(q+5)); zforce= calczforce(R,z,phi,t,nargs,potentialArgs,vR,vT,*(q+5)); phiforce= calcPhiforce(R,z,phi,t,nargs,potentialArgs,vR,vT,*(q+5)); *a++= cosphi*Rforce-1./R*sinphi*phiforce; *a++= sinphi*Rforce+1./R*cosphi*phiforce; *a= zforce; } void initMovingObjectSplines(struct potentialArg * potentialArgs, double ** pot_args){ gsl_interp_accel *x_accel_ptr = gsl_interp_accel_alloc(); gsl_interp_accel *y_accel_ptr = gsl_interp_accel_alloc(); gsl_interp_accel *z_accel_ptr = gsl_interp_accel_alloc(); int nPts = (int) **pot_args; gsl_spline *x_spline = gsl_spline_alloc(gsl_interp_cspline, nPts); gsl_spline *y_spline = gsl_spline_alloc(gsl_interp_cspline, nPts); gsl_spline *z_spline = gsl_spline_alloc(gsl_interp_cspline, nPts); double * t_arr = *pot_args+1; double * x_arr = t_arr+1*nPts; double * y_arr = t_arr+2*nPts; double * z_arr = t_arr+3*nPts; double * t= (double *) malloc ( nPts * sizeof (double) ); double tf = *(t_arr+4*nPts+2); double to = *(t_arr+4*nPts+1); int ii; for (ii=0; ii < nPts; ii++) *(t+ii) = (t_arr[ii]-to)/(tf-to); gsl_spline_init(x_spline, t, x_arr, nPts); gsl_spline_init(y_spline, t, y_arr, nPts); gsl_spline_init(z_spline, t, z_arr, nPts); potentialArgs->nspline1d= 3; potentialArgs->spline1d= (gsl_spline **) malloc ( 3*sizeof ( gsl_spline *) ); potentialArgs->acc1d= (gsl_interp_accel **) \ malloc ( 3 * sizeof ( gsl_interp_accel * ) ); *potentialArgs->spline1d = x_spline; *potentialArgs->acc1d = x_accel_ptr; *(potentialArgs->spline1d+1)= y_spline; *(potentialArgs->acc1d+1)= y_accel_ptr; *(potentialArgs->spline1d+2)= z_spline; *(potentialArgs->acc1d+2)= z_accel_ptr; *pot_args = *pot_args + (int) (1+4*nPts); free(t); } void initMovingObjectVelSplines(struct potentialArg * potentialArgs, double ** pot_args){ // Modified by Richard D'Souza - 18 Jan 2021 gsl_interp_accel *x_accel_ptr = gsl_interp_accel_alloc(); gsl_interp_accel *y_accel_ptr = gsl_interp_accel_alloc(); gsl_interp_accel *z_accel_ptr = gsl_interp_accel_alloc(); gsl_interp_accel *vx_accel_ptr = gsl_interp_accel_alloc(); gsl_interp_accel *vy_accel_ptr = gsl_interp_accel_alloc(); gsl_interp_accel *vz_accel_ptr = gsl_interp_accel_alloc(); int nPts = (int) **pot_args; gsl_spline *x_spline = gsl_spline_alloc(gsl_interp_cspline, nPts); gsl_spline *y_spline = gsl_spline_alloc(gsl_interp_cspline, nPts); gsl_spline *z_spline = gsl_spline_alloc(gsl_interp_cspline, nPts); gsl_spline *vx_spline = gsl_spline_alloc(gsl_interp_cspline, nPts); gsl_spline *vy_spline = gsl_spline_alloc(gsl_interp_cspline, nPts); gsl_spline *vz_spline = gsl_spline_alloc(gsl_interp_cspline, nPts); double * t_arr = *pot_args+1; double * x_arr = t_arr+1*nPts; double * y_arr = t_arr+2*nPts; double * z_arr = t_arr+3*nPts; double * vx_arr = t_arr +4*nPts; double * vy_arr = t_arr +5*nPts; double * vz_arr = t_arr +6*nPts; double * t= (double *) malloc ( nPts * sizeof (double) ); double tf = *(t_arr+7*nPts+2); double to = *(t_arr+7*nPts+1); int ii; for (ii=0; ii < nPts; ii++) *(t+ii) = (t_arr[ii]-to)/(tf-to); gsl_spline_init(x_spline, t, x_arr, nPts); gsl_spline_init(y_spline, t, y_arr, nPts); gsl_spline_init(z_spline, t, z_arr, nPts); gsl_spline_init(vx_spline, t, vx_arr, nPts); gsl_spline_init(vy_spline, t, vy_arr, nPts); gsl_spline_init(vz_spline, t, vz_arr, nPts); potentialArgs->nspline1d= 6; potentialArgs->spline1d= (gsl_spline **) malloc ( 6*sizeof ( gsl_spline *) ); potentialArgs->acc1d= (gsl_interp_accel **) \ malloc ( 6 * sizeof ( gsl_interp_accel * ) ); *potentialArgs->spline1d = x_spline; *potentialArgs->acc1d = x_accel_ptr; *(potentialArgs->spline1d+1)= y_spline; *(potentialArgs->acc1d+1)= y_accel_ptr; *(potentialArgs->spline1d+2)= z_spline; *(potentialArgs->acc1d+2)= z_accel_ptr; *(potentialArgs->spline1d+3)= vx_spline; *(potentialArgs->acc1d+3)= vx_accel_ptr; *(potentialArgs->spline1d+4)= vy_spline; *(potentialArgs->acc1d+4)= vy_accel_ptr; *(potentialArgs->spline1d+5)= vz_spline; *(potentialArgs->acc1d+5)= vz_accel_ptr; *pot_args = *pot_args + (int) (1+7*nPts); free(t); } void initChandrasekharDynamicalFrictionSplines(struct potentialArg * potentialArgs, double ** pot_args){ gsl_interp_accel *sr_accel_ptr = gsl_interp_accel_alloc(); int nPts = (int) **pot_args; gsl_spline *sr_spline = gsl_spline_alloc(gsl_interp_cspline,nPts); double * r_arr = *pot_args+1; double * sr_arr = r_arr+1*nPts; double * r= (double *) malloc ( nPts * sizeof (double) ); double ro = *(r_arr+2*nPts+14); double rf = *(r_arr+2*nPts+15); int ii; for (ii=0; ii < nPts; ii++) *(r+ii) = (r_arr[ii]-ro)/(rf-ro); gsl_spline_init(sr_spline,r,sr_arr,nPts); potentialArgs->nspline1d= 1; potentialArgs->spline1d= (gsl_spline **) \ malloc ( potentialArgs->nspline1d*sizeof ( gsl_spline *) ); potentialArgs->acc1d= (gsl_interp_accel **) \ malloc ( potentialArgs->nspline1d * sizeof ( gsl_interp_accel * ) ); *potentialArgs->spline1d = sr_spline; *potentialArgs->acc1d = sr_accel_ptr; *pot_args = *pot_args + (int) (1+(1+potentialArgs->nspline1d)*nPts); free(r); } // LCOV_EXCL_START void evalRectDeriv_dxdv(double t, double *q, double *a, int nargs, struct potentialArg * potentialArgs){ double sinphi, cosphi, x, y, phi,R,Rforce,phiforce,z,zforce; double R2deriv, phi2deriv, Rphideriv, dFxdx, dFxdy, dFydx, dFydy; //first three derivatives are just the velocities *a++= *(q+3); *a++= *(q+4); *a++= *(q+5); //Rest is force //q is rectangular so calculate R and phi x= *q; y= *(q+1); z= *(q+2); R= sqrt(x*x+y*y); phi= acos(x/R); sinphi= y/R; cosphi= x/R; if ( y < 0. ) phi= 2.*M_PI-phi; //Calculate the forces Rforce= calcRforce(R,z,phi,t,nargs,potentialArgs); zforce= calczforce(R,z,phi,t,nargs,potentialArgs); phiforce= calcPhiforce(R,z,phi,t,nargs,potentialArgs); *a++= cosphi*Rforce-1./R*sinphi*phiforce; *a++= sinphi*Rforce+1./R*cosphi*phiforce; *a++= zforce; //dx derivatives are just dv *a++= *(q+9); *a++= *(q+10); *a++= *(q+11); //for the dv derivatives we need also R2deriv, phi2deriv, and Rphideriv R2deriv= calcR2deriv(R,z,phi,t,nargs,potentialArgs); phi2deriv= calcphi2deriv(R,z,phi,t,nargs,potentialArgs); Rphideriv= calcRphideriv(R,z,phi,t,nargs,potentialArgs); //..and dFxdx, dFxdy, dFydx, dFydy dFxdx= -cosphi*cosphi*R2deriv +2.*cosphi*sinphi/R/R*phiforce +sinphi*sinphi/R*Rforce +2.*sinphi*cosphi/R*Rphideriv -sinphi*sinphi/R/R*phi2deriv; dFxdy= -sinphi*cosphi*R2deriv +(sinphi*sinphi-cosphi*cosphi)/R/R*phiforce -cosphi*sinphi/R*Rforce -(cosphi*cosphi-sinphi*sinphi)/R*Rphideriv +cosphi*sinphi/R/R*phi2deriv; dFydx= -cosphi*sinphi*R2deriv +(sinphi*sinphi-cosphi*cosphi)/R/R*phiforce +(sinphi*sinphi-cosphi*cosphi)/R*Rphideriv -sinphi*cosphi/R*Rforce +sinphi*cosphi/R/R*phi2deriv; dFydy= -sinphi*sinphi*R2deriv -2.*sinphi*cosphi/R/R*phiforce -2.*sinphi*cosphi/R*Rphideriv +cosphi*cosphi/R*Rforce -cosphi*cosphi/R/R*phi2deriv; *a++= dFxdx * *(q+4) + dFxdy * *(q+5); *a++= dFydx * *(q+4) + dFydy * *(q+5); *a= 0; //BOVY: PUT IN Z2DERIVS } // LCOV_EXCL_STOP
3D.c
#include <stdio.h> #include <time.h> #include <assert.h> #include <stdlib.h> #include <math.h> #include <sys/time.h> #include <string.h> #define STR_SIZE (256) #define MAX_PD (3.0e6) /* required precision in degrees */ #define PRECISION 0.001 #define SPEC_HEAT_SI 1.75e6 #define K_SI 100 /* capacitance fitting factor */ #define FACTOR_CHIP 0.5 /* chip parameters */ #include <omp.h> float t_chip = 0.0005; float chip_height = 0.016; float chip_width = 0.016; /* ambient temperature, assuming no package at all */ float amb_temp = 80.0; void fatal(char *s) { fprintf(stderr,"Error: %s\n",s); } void readinput(float *vect,int grid_rows,int grid_cols,int layers,char *file) { int i; int j; int k; FILE *fp; char str[256]; float val; if ((fp = fopen(file,"r")) == 0) fatal("The file was not opened"); for (i = 0; i <= grid_rows - 1; i += 1) { for (j = 0; j <= grid_cols - 1; j += 1) { for (k = 0; k <= layers - 1; k += 1) { if (fgets(str,256,fp) == ((void *)0)) fatal("Error reading file\n"); if (feof(fp)) fatal("not enough lines in file"); if (sscanf(str,"%f",&val) != 1) fatal("invalid file format"); vect[i * grid_cols + j + k * grid_rows * grid_cols] = val; } } } fclose(fp); } void writeoutput(float *vect,int grid_rows,int grid_cols,int layers,char *file) { int i; int j; int k; int index = 0; FILE *fp; char str[256]; if ((fp = fopen(file,"w")) == 0) printf("The file was not opened\n"); for (i = 0; i <= grid_rows - 1; i += 1) { for (j = 0; j <= grid_cols - 1; j += 1) { for (k = 0; k <= layers - 1; k += 1) { sprintf(str,"%d\t%g\n",index,vect[i * grid_cols + j + k * grid_rows * grid_cols]); fputs(str,fp); index++; } } } fclose(fp); } void computeTempCPU(float *pIn,float *tIn,float *tOut,int nx,int ny,int nz,float Cap,float Rx,float Ry,float Rz,float dt,int numiter) { float ce; float cw; float cn; float cs; float ct; float cb; float cc; float stepDivCap = dt / Cap; ce = cw = stepDivCap / Rx; cn = cs = stepDivCap / Ry; ct = cb = stepDivCap / Rz; cc = (1.0 - (2.0 * ce + 2.0 * cn + 3.0 * ct)); int c; int w; int e; int n; int s; int b; int t; int x; int y; int z; int i = 0; do { for (z = 0; z <= nz - 1; z += 1) { for (y = 0; y <= ny - 1; y += 1) { for (x = 0; x <= nx - 1; x += 1) { c = x + y * nx + z * nx * ny; w = (x == 0?c : c - 1); e = (x == nx - 1?c : c + 1); 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); tOut[c] = tIn[c] * cc + tIn[n] * cn + tIn[s] * cs + tIn[e] * ce + tIn[w] * cw + tIn[t] * ct + tIn[b] * cb + dt / Cap * pIn[c] + ct * amb_temp; } } } float *temp = tIn; tIn = tOut; tOut = temp; i++; }while (i < numiter); } float accuracy(float *arr1,float *arr2,int len) { float err = 0.0; int i; #pragma omp parallel for private (i) reduction (+:err) for (i = 0; i <= len - 1; i += 1) { err += (arr1[i] - arr2[i]) * (arr1[i] - arr2[i]); } return (float )(sqrt((err / len))); } void computeTempOMP(float *pIn,float *tIn,float *tOut,int nx,int ny,int nz,float Cap,float Rx,float Ry,float Rz,float dt,int numiter) { float ce; float cw; float cn; float cs; float ct; float cb; float cc; float stepDivCap = dt / Cap; ce = cw = stepDivCap / Rx; cn = cs = stepDivCap / Ry; ct = cb = stepDivCap / Rz; cc = (1.0 - (2.0 * ce + 2.0 * cn + 3.0 * ct)); { int count = 0; float *tIn_t = tIn; float *tOut_t = tOut; printf("%d threads running\n",(omp_get_num_threads())); do { int z; for (z = 0; z <= nz - 1; z += 1) { int y; for (y = 0; y <= ny - 1; y += 1) { int x; for (x = 0; x <= nx - 1; x += 1) { int c; int w; int e; int n; int s; int b; int t; c = x + y * nx + z * nx * ny; w = (x == 0?c : c - 1); e = (x == nx - 1?c : c + 1); 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); tOut_t[c] = cc * tIn_t[c] + cw * tIn_t[w] + ce * tIn_t[e] + cs * tIn_t[s] + cn * tIn_t[n] + cb * tIn_t[b] + ct * tIn_t[t] + dt / Cap * pIn[c] + ct * amb_temp; } } } float *t = tIn_t; tIn_t = tOut_t; tOut_t = t; count++; }while (count < numiter); } return ; } void usage(int argc,char **argv) { fprintf(stderr,"Usage: %s <rows/cols> <layers> <iterations> <powerFile> <tempFile> <outputFile>\n",argv[0]); fprintf(stderr,"\t<rows/cols> - number of rows/cols in the grid (positive integer)\n"); fprintf(stderr,"\t<layers> - number of layers in the grid (positive integer)\n"); fprintf(stderr,"\t<iteration> - number of iterations\n"); fprintf(stderr,"\t<powerFile> - name of the file containing the initial power values of each cell\n"); fprintf(stderr,"\t<tempFile> - name of the file containing the initial temperature values of each cell\n"); fprintf(stderr,"\t<outputFile - output file\n"); exit(1); } int main(int argc,char **argv) { if (argc != 7) { usage(argc,argv); } // *testFile; char *pfile; char *tfile; char *ofile; int iterations = atoi(argv[3]); pfile = argv[4]; tfile = argv[5]; ofile = argv[6]; //testFile = argv[7]; int numCols = atoi(argv[1]); int numRows = atoi(argv[1]); int layers = atoi(argv[2]); /* calculating parameters*/ float dx = chip_height / numRows; float dy = chip_width / numCols; float dz = t_chip / layers; float Cap = (0.5 * 1.75e6 * t_chip * dx * dy); float Rx = (dy / (2.0 * 100 * t_chip * dx)); float Ry = (dx / (2.0 * 100 * t_chip * dy)); float Rz = dz / (100 * dx * dy); // cout << Rx << " " << Ry << " " << Rz << endl; float max_slope = (3.0e6 / (0.5 * t_chip * 1.75e6)); float dt = (0.001 / max_slope); // *pCopy; float *powerIn; float *tempOut; float *tempIn; float *tempCopy; // float *d_powerIn, *d_tempIn, *d_tempOut; int size = numCols * numRows * layers; powerIn = ((float *)(calloc(size,sizeof(float )))); tempCopy = ((float *)(malloc(size * sizeof(float )))); tempIn = ((float *)(calloc(size,sizeof(float )))); tempOut = ((float *)(calloc(size,sizeof(float )))); //pCopy = (float*)calloc(size,sizeof(float)); float *answer = (float *)(calloc(size,sizeof(float ))); // outCopy = (float*)calloc(size, sizeof(float)); readinput(powerIn,numRows,numCols,layers,pfile); readinput(tempIn,numRows,numCols,layers,tfile); memcpy(tempCopy,tempIn,size * sizeof(float )); struct timeval start; struct timeval stop; float time; gettimeofday(&start,((void *)0)); computeTempOMP(powerIn,tempIn,tempOut,numCols,numRows,layers,Cap,Rx,Ry,Rz,dt,iterations); gettimeofday(&stop,((void *)0)); time = ((stop . tv_usec - start . tv_usec) * 1.0e-6 + stop . tv_sec - start . tv_sec); computeTempCPU(powerIn,tempCopy,answer,numCols,numRows,layers,Cap,Rx,Ry,Rz,dt,iterations); float acc = accuracy(tempOut,answer,numRows * numCols * layers); printf("Time: %.3f (s)\n",time); printf("Accuracy: %e\n",acc); writeoutput(tempOut,numRows,numCols,layers,ofile); free(tempIn); free(tempOut); free(powerIn); return 0; }
3d7pt.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 7 point stencil * 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, test; int Nx, Ny, Nz, Nt; if (argc > 3) { Nx = atoi(argv[1])+2; Ny = atoi(argv[2])+2; Nz = atoi(argv[3])+2; } if (argc > 4) Nt = atoi(argv[4]); double ****A = (double ****) malloc(sizeof(double***)*2); A[0] = (double ***) malloc(sizeof(double**)*Nz); A[1] = (double ***) malloc(sizeof(double**)*Nz); for(i=0; i<Nz; i++){ A[0][i] = (double**) malloc(sizeof(double*)*Ny); A[1][i] = (double**) malloc(sizeof(double*)*Ny); for(j=0;j<Ny;j++){ A[0][i][j] = (double*) malloc(sizeof(double)*Nx); A[1][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] = 16; tile_size[3] = 2048; 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; const double alpha = 0.0876; const double beta = 0.0765; // 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); } } } #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 >= 2) && (Nx >= 3) && (Ny >= 3) && (Nz >= 3)) { for (t1=-1;t1<=floord(Nt-2,12);t1++) { lbp=max(ceild(t1,2),ceild(24*t1-Nt+3,24)); ubp=min(floord(Nt+Nz-4,24),floord(12*t1+Nz+9,24)); #pragma omp parallel for private(lbv,ubv,t3,t4,t5,t6,t7,t8) for (t2=lbp;t2<=ubp;t2++) { for (t3=max(max(0,ceild(3*t1-3,4)),ceild(24*t2-Nz-12,16));t3<=min(min(min(floord(Nt+Ny-4,16),floord(12*t1+Ny+21,16)),floord(24*t2+Ny+20,16)),floord(24*t1-24*t2+Nz+Ny+19,16));t3++) { for (t4=max(max(max(0,ceild(3*t1-511,512)),ceild(24*t2-Nz-2044,2048)),ceild(16*t3-Ny-2044,2048));t4<=min(min(min(min(floord(Nt+Nx-4,2048),floord(12*t1+Nx+21,2048)),floord(24*t2+Nx+20,2048)),floord(16*t3+Nx+12,2048)),floord(24*t1-24*t2+Nz+Nx+19,2048));t4++) { for (t5=max(max(max(max(max(0,12*t1),24*t1-24*t2+1),24*t2-Nz+2),16*t3-Ny+2),2048*t4-Nx+2);t5<=min(min(min(min(min(Nt-2,12*t1+23),24*t2+22),16*t3+14),2048*t4+2046),24*t1-24*t2+Nz+21);t5++) { for (t6=max(max(24*t2,t5+1),-24*t1+24*t2+2*t5-23);t6<=min(min(24*t2+23,-24*t1+24*t2+2*t5),t5+Nz-2);t6++) { for (t7=max(16*t3,t5+1);t7<=min(16*t3+15,t5+Ny-2);t7++) { lbv=max(2048*t4,t5+1); ubv=min(2048*t4+2047,t5+Nx-2); #pragma ivdep #pragma vector always for (t8=lbv;t8<=ubv;t8++) { A[( t5 + 1) % 2][ (-t5+t6)][ (-t5+t7)][ (-t5+t8)] = ((alpha * A[ t5 % 2][ (-t5+t6)][ (-t5+t7)][ (-t5+t8)]) + (beta * (((((A[ t5 % 2][ (-t5+t6) - 1][ (-t5+t7)][ (-t5+t8)] + A[ t5 % 2][ (-t5+t6)][ (-t5+t7) - 1][ (-t5+t8)]) + A[ t5 % 2][ (-t5+t6)][ (-t5+t7)][ (-t5+t8) - 1]) + A[ t5 % 2][ (-t5+t6) + 1][ (-t5+t7)][ (-t5+t8)]) + A[ t5 % 2][ (-t5+t6)][ (-t5+t7) + 1][ (-t5+t8)]) + A[ t5 % 2][ (-t5+t6)][ (-t5+t7)][ (-t5+t8) + 1])));; } } } } } } } } } /* 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(1, "constant") #ifdef LIKWID_PERFMON #pragma omp parallel { LIKWID_MARKER_STOP("calc"); } LIKWID_MARKER_CLOSE; #endif // Free allocated arrays (Causing performance degradation /* 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]); */ return 0; }
ast-dump-openmp-begin-declare-variant_10.c
// RUN: %clang_cc1 -triple x86_64-unknown-unknown -fopenmp -verify -ast-dump %s | FileCheck %s --check-prefix=C // RUN: %clang_cc1 -triple x86_64-unknown-unknown -fopenmp -verify -ast-dump %s -x c++| FileCheck %s --check-prefix=CXX // expected-no-diagnostics #ifdef __cplusplus #define CONST constexpr #else #define CONST __attribute__((const)) #endif int also_before1(void) { return 1; } int also_before2(void) { return 2; } int also_before3(void) { return 3; } int also_before4(void) { return 4; } #pragma omp begin declare variant match(implementation = {vendor(llvm)}) CONST int also_before1(void) { return 0; } static int also_before2(void) { return 0; } __attribute__((nothrow)) int also_before3(void) { return 0; } static CONST __attribute__((nothrow, always_inline)) __inline__ int also_before4(void) { return 0; } #pragma omp end declare variant int main() { // Should return 0. return also_before1() + also_before2() + also_before3() + also_before4(); } // Make sure: // - we see the specialization in the AST // - we pick the right callees // C: |-FunctionDecl [[ADDR_0:0x[a-z0-9]*]] <{{.*}}, line:13:1> line:11:5 used also_before1 'int ({{.*}})' // C-NEXT: | |-CompoundStmt [[ADDR_1:0x[a-z0-9]*]] <col:24, line:13:1> // C-NEXT: | | `-ReturnStmt [[ADDR_2:0x[a-z0-9]*]] <line:12:3, col:10> // C-NEXT: | | `-IntegerLiteral [[ADDR_3:0x[a-z0-9]*]] <col:10> 'int' 1 // C-NEXT: | `-OMPDeclareVariantAttr [[ADDR_4:0x[a-z0-9]*]] <<invalid sloc>> Implicit implementation={vendor(llvm)} // C-NEXT: | `-DeclRefExpr [[ADDR_5:0x[a-z0-9]*]] <line:8:15> 'int ({{.*}})' Function [[ADDR_6:0x[a-z0-9]*]] 'also_before1[implementation={vendor(llvm)}]' 'int ({{.*}})' // C-NEXT: |-FunctionDecl [[ADDR_7:0x[a-z0-9]*]] <line:14:1, line:16:1> line:14:5 used also_before2 'int ({{.*}})' // C-NEXT: | |-CompoundStmt [[ADDR_8:0x[a-z0-9]*]] <col:24, line:16:1> // C-NEXT: | | `-ReturnStmt [[ADDR_9:0x[a-z0-9]*]] <line:15:3, col:10> // C-NEXT: | | `-IntegerLiteral [[ADDR_10:0x[a-z0-9]*]] <col:10> 'int' 2 // C-NEXT: | `-OMPDeclareVariantAttr [[ADDR_11:0x[a-z0-9]*]] <<invalid sloc>> Implicit implementation={vendor(llvm)} // C-NEXT: | `-DeclRefExpr [[ADDR_12:0x[a-z0-9]*]] <line:28:1> 'int ({{.*}})' Function [[ADDR_13:0x[a-z0-9]*]] 'also_before2[implementation={vendor(llvm)}]' 'int ({{.*}})' // C-NEXT: |-FunctionDecl [[ADDR_14:0x[a-z0-9]*]] <line:17:1, line:19:1> line:17:5 used also_before3 'int ({{.*}})' // C-NEXT: | |-CompoundStmt [[ADDR_15:0x[a-z0-9]*]] <col:24, line:19:1> // C-NEXT: | | `-ReturnStmt [[ADDR_16:0x[a-z0-9]*]] <line:18:3, col:10> // C-NEXT: | | `-IntegerLiteral [[ADDR_17:0x[a-z0-9]*]] <col:10> 'int' 3 // C-NEXT: | `-OMPDeclareVariantAttr [[ADDR_18:0x[a-z0-9]*]] <<invalid sloc>> Implicit implementation={vendor(llvm)} // C-NEXT: | `-DeclRefExpr [[ADDR_19:0x[a-z0-9]*]] <line:31:1> 'int ({{.*}})' Function [[ADDR_20:0x[a-z0-9]*]] 'also_before3[implementation={vendor(llvm)}]' 'int ({{.*}})' // C-NEXT: |-FunctionDecl [[ADDR_21:0x[a-z0-9]*]] <line:20:1, line:22:1> line:20:5 used also_before4 'int ({{.*}})' // C-NEXT: | |-CompoundStmt [[ADDR_22:0x[a-z0-9]*]] <col:24, line:22:1> // C-NEXT: | | `-ReturnStmt [[ADDR_23:0x[a-z0-9]*]] <line:21:3, col:10> // C-NEXT: | | `-IntegerLiteral [[ADDR_24:0x[a-z0-9]*]] <col:10> 'int' 4 // C-NEXT: | `-OMPDeclareVariantAttr [[ADDR_25:0x[a-z0-9]*]] <<invalid sloc>> Implicit implementation={vendor(llvm)} // C-NEXT: | `-DeclRefExpr [[ADDR_26:0x[a-z0-9]*]] <line:34:1> 'int ({{.*}})' Function [[ADDR_27:0x[a-z0-9]*]] 'also_before4[implementation={vendor(llvm)}]' 'int ({{.*}})' // C-NEXT: |-FunctionDecl [[ADDR_6]] <line:8:15, line:27:1> line:8:15 also_before1[implementation={vendor(llvm)}] 'int ({{.*}})' // C-NEXT: | |-CompoundStmt [[ADDR_28:0x[a-z0-9]*]] <line:25:30, line:27:1> // C-NEXT: | | `-ReturnStmt [[ADDR_29:0x[a-z0-9]*]] <line:26:3, col:10> // C-NEXT: | | `-IntegerLiteral [[ADDR_30:0x[a-z0-9]*]] <col:10> 'int' 0 // C-NEXT: | `-ConstAttr [[ADDR_31:0x[a-z0-9]*]] <line:8:30> // C-NEXT: |-FunctionDecl [[ADDR_13]] <line:28:1, line:30:1> line:28:1 also_before2[implementation={vendor(llvm)}] 'int ({{.*}})' static // C-NEXT: | `-CompoundStmt [[ADDR_32:0x[a-z0-9]*]] <col:31, line:30:1> // C-NEXT: | `-ReturnStmt [[ADDR_33:0x[a-z0-9]*]] <line:29:3, col:10> // C-NEXT: | `-IntegerLiteral [[ADDR_34:0x[a-z0-9]*]] <col:10> 'int' 0 // C-NEXT: |-FunctionDecl [[ADDR_20]] <line:31:1, line:33:1> line:31:1 also_before3[implementation={vendor(llvm)}] 'int ({{.*}})' // C-NEXT: | |-CompoundStmt [[ADDR_35:0x[a-z0-9]*]] <col:49, line:33:1> // C-NEXT: | | `-ReturnStmt [[ADDR_36:0x[a-z0-9]*]] <line:32:3, col:10> // C-NEXT: | | `-IntegerLiteral [[ADDR_37:0x[a-z0-9]*]] <col:10> 'int' 0 // C-NEXT: | `-NoThrowAttr [[ADDR_38:0x[a-z0-9]*]] <line:31:16> // C-NEXT: |-FunctionDecl [[ADDR_27]] <line:34:1, line:36:1> line:34:1 also_before4[implementation={vendor(llvm)}] 'int ({{.*}})' static inline // C-NEXT: | |-CompoundStmt [[ADDR_39:0x[a-z0-9]*]] <col:88, line:36:1> // C-NEXT: | | `-ReturnStmt [[ADDR_40:0x[a-z0-9]*]] <line:35:3, col:10> // C-NEXT: | | `-IntegerLiteral [[ADDR_41:0x[a-z0-9]*]] <col:10> 'int' 0 // C-NEXT: | |-ConstAttr [[ADDR_42:0x[a-z0-9]*]] <line:8:30> // C-NEXT: | |-NoThrowAttr [[ADDR_43:0x[a-z0-9]*]] <line:34:29> // C-NEXT: | `-AlwaysInlineAttr [[ADDR_44:0x[a-z0-9]*]] <col:38> always_inline // C-NEXT: `-FunctionDecl [[ADDR_45:0x[a-z0-9]*]] <line:40:1, line:43:1> line:40:5 main 'int ({{.*}})' // C-NEXT: `-CompoundStmt [[ADDR_46:0x[a-z0-9]*]] <col:12, line:43:1> // C-NEXT: `-ReturnStmt [[ADDR_47:0x[a-z0-9]*]] <line:42:3, col:74> // C-NEXT: `-BinaryOperator [[ADDR_48:0x[a-z0-9]*]] <col:10, col:74> 'int' '+' // C-NEXT: |-BinaryOperator [[ADDR_49:0x[a-z0-9]*]] <col:10, col:57> 'int' '+' // C-NEXT: | |-BinaryOperator [[ADDR_50:0x[a-z0-9]*]] <col:10, col:40> 'int' '+' // C-NEXT: | | |-PseudoObjectExpr [[ADDR_51:0x[a-z0-9]*]] <col:10, col:23> 'int' // C-NEXT: | | | |-CallExpr [[ADDR_52:0x[a-z0-9]*]] <col:10, col:23> 'int' // C-NEXT: | | | | `-ImplicitCastExpr [[ADDR_53:0x[a-z0-9]*]] <col:10> 'int (*)({{.*}})' <FunctionToPointerDecay> // C-NEXT: | | | | `-DeclRefExpr [[ADDR_54:0x[a-z0-9]*]] <col:10> 'int ({{.*}})' Function [[ADDR_0]] 'also_before1' 'int ({{.*}})' // C-NEXT: | | | `-CallExpr [[ADDR_55:0x[a-z0-9]*]] <line:8:15, line:42:23> 'int' // C-NEXT: | | | `-ImplicitCastExpr [[ADDR_56:0x[a-z0-9]*]] <line:8:15> 'int (*)({{.*}})' <FunctionToPointerDecay> // C-NEXT: | | | `-DeclRefExpr [[ADDR_5]] <col:15> 'int ({{.*}})' Function [[ADDR_6]] 'also_before1[implementation={vendor(llvm)}]' 'int ({{.*}})' // C-NEXT: | | `-PseudoObjectExpr [[ADDR_57:0x[a-z0-9]*]] <line:42:27, col:40> 'int' // C-NEXT: | | |-CallExpr [[ADDR_58:0x[a-z0-9]*]] <col:27, col:40> 'int' // C-NEXT: | | | `-ImplicitCastExpr [[ADDR_59:0x[a-z0-9]*]] <col:27> 'int (*)({{.*}})' <FunctionToPointerDecay> // C-NEXT: | | | `-DeclRefExpr [[ADDR_60:0x[a-z0-9]*]] <col:27> 'int ({{.*}})' Function [[ADDR_7]] 'also_before2' 'int ({{.*}})' // C-NEXT: | | `-CallExpr [[ADDR_61:0x[a-z0-9]*]] <line:28:1, line:42:40> 'int' // C-NEXT: | | `-ImplicitCastExpr [[ADDR_62:0x[a-z0-9]*]] <line:28:1> 'int (*)({{.*}})' <FunctionToPointerDecay> // C-NEXT: | | `-DeclRefExpr [[ADDR_12]] <col:1> 'int ({{.*}})' Function [[ADDR_13]] 'also_before2[implementation={vendor(llvm)}]' 'int ({{.*}})' // C-NEXT: | `-PseudoObjectExpr [[ADDR_63:0x[a-z0-9]*]] <line:42:44, col:57> 'int' // C-NEXT: | |-CallExpr [[ADDR_64:0x[a-z0-9]*]] <col:44, col:57> 'int' // C-NEXT: | | `-ImplicitCastExpr [[ADDR_65:0x[a-z0-9]*]] <col:44> 'int (*)({{.*}})' <FunctionToPointerDecay> // C-NEXT: | | `-DeclRefExpr [[ADDR_66:0x[a-z0-9]*]] <col:44> 'int ({{.*}})' Function [[ADDR_14]] 'also_before3' 'int ({{.*}})' // C-NEXT: | `-CallExpr [[ADDR_67:0x[a-z0-9]*]] <line:31:1, line:42:57> 'int' // C-NEXT: | `-ImplicitCastExpr [[ADDR_68:0x[a-z0-9]*]] <line:31:1> 'int (*)({{.*}})' <FunctionToPointerDecay> // C-NEXT: | `-DeclRefExpr [[ADDR_19]] <col:1> 'int ({{.*}})' Function [[ADDR_20]] 'also_before3[implementation={vendor(llvm)}]' 'int ({{.*}})' // C-NEXT: `-PseudoObjectExpr [[ADDR_69:0x[a-z0-9]*]] <line:42:61, col:74> 'int' // C-NEXT: |-CallExpr [[ADDR_70:0x[a-z0-9]*]] <col:61, col:74> 'int' // C-NEXT: | `-ImplicitCastExpr [[ADDR_71:0x[a-z0-9]*]] <col:61> 'int (*)({{.*}})' <FunctionToPointerDecay> // C-NEXT: | `-DeclRefExpr [[ADDR_72:0x[a-z0-9]*]] <col:61> 'int ({{.*}})' Function [[ADDR_21]] 'also_before4' 'int ({{.*}})' // C-NEXT: `-CallExpr [[ADDR_73:0x[a-z0-9]*]] <line:34:1, line:42:74> 'int' // C-NEXT: `-ImplicitCastExpr [[ADDR_74:0x[a-z0-9]*]] <line:34:1> 'int (*)({{.*}})' <FunctionToPointerDecay> // C-NEXT: `-DeclRefExpr [[ADDR_26]] <col:1> 'int ({{.*}})' Function [[ADDR_27]] 'also_before4[implementation={vendor(llvm)}]' 'int ({{.*}})' // CXX: |-FunctionDecl [[ADDR_0:0x[a-z0-9]*]] <{{.*}}, line:13:1> line:11:5 used also_before1 'int ({{.*}})' // CXX-NEXT: | |-CompoundStmt [[ADDR_1:0x[a-z0-9]*]] <col:24, line:13:1> // CXX-NEXT: | | `-ReturnStmt [[ADDR_2:0x[a-z0-9]*]] <line:12:3, col:10> // CXX-NEXT: | | `-IntegerLiteral [[ADDR_3:0x[a-z0-9]*]] <col:10> 'int' 1 // CXX-NEXT: | `-OMPDeclareVariantAttr [[ADDR_4:0x[a-z0-9]*]] <<invalid sloc>> Implicit implementation={vendor(llvm)} // CXX-NEXT: | `-DeclRefExpr [[ADDR_5:0x[a-z0-9]*]] <line:6:15> 'int ({{.*}})' Function [[ADDR_6:0x[a-z0-9]*]] 'also_before1[implementation={vendor(llvm)}]' 'int ({{.*}})' // CXX-NEXT: |-FunctionDecl [[ADDR_7:0x[a-z0-9]*]] <line:14:1, line:16:1> line:14:5 used also_before2 'int ({{.*}})' // CXX-NEXT: | |-CompoundStmt [[ADDR_8:0x[a-z0-9]*]] <col:24, line:16:1> // CXX-NEXT: | | `-ReturnStmt [[ADDR_9:0x[a-z0-9]*]] <line:15:3, col:10> // CXX-NEXT: | | `-IntegerLiteral [[ADDR_10:0x[a-z0-9]*]] <col:10> 'int' 2 // CXX-NEXT: | `-OMPDeclareVariantAttr [[ADDR_11:0x[a-z0-9]*]] <<invalid sloc>> Implicit implementation={vendor(llvm)} // CXX-NEXT: | `-DeclRefExpr [[ADDR_12:0x[a-z0-9]*]] <line:28:1> 'int ({{.*}})' Function [[ADDR_13:0x[a-z0-9]*]] 'also_before2[implementation={vendor(llvm)}]' 'int ({{.*}})' // CXX-NEXT: |-FunctionDecl [[ADDR_14:0x[a-z0-9]*]] <line:17:1, line:19:1> line:17:5 used also_before3 'int ({{.*}})' // CXX-NEXT: | |-CompoundStmt [[ADDR_15:0x[a-z0-9]*]] <col:24, line:19:1> // CXX-NEXT: | | `-ReturnStmt [[ADDR_16:0x[a-z0-9]*]] <line:18:3, col:10> // CXX-NEXT: | | `-IntegerLiteral [[ADDR_17:0x[a-z0-9]*]] <col:10> 'int' 3 // CXX-NEXT: | `-OMPDeclareVariantAttr [[ADDR_18:0x[a-z0-9]*]] <<invalid sloc>> Implicit implementation={vendor(llvm)} // CXX-NEXT: | `-DeclRefExpr [[ADDR_19:0x[a-z0-9]*]] <line:31:1> 'int ({{.*}}) __attribute__((nothrow))' Function [[ADDR_20:0x[a-z0-9]*]] 'also_before3[implementation={vendor(llvm)}]' 'int ({{.*}}) __attribute__((nothrow))' // CXX-NEXT: |-FunctionDecl [[ADDR_21:0x[a-z0-9]*]] <line:20:1, line:22:1> line:20:5 used also_before4 'int ({{.*}})' // CXX-NEXT: | |-CompoundStmt [[ADDR_22:0x[a-z0-9]*]] <col:24, line:22:1> // CXX-NEXT: | | `-ReturnStmt [[ADDR_23:0x[a-z0-9]*]] <line:21:3, col:10> // CXX-NEXT: | | `-IntegerLiteral [[ADDR_24:0x[a-z0-9]*]] <col:10> 'int' 4 // CXX-NEXT: | `-OMPDeclareVariantAttr [[ADDR_25:0x[a-z0-9]*]] <<invalid sloc>> Implicit implementation={vendor(llvm)} // CXX-NEXT: | `-DeclRefExpr [[ADDR_26:0x[a-z0-9]*]] <line:34:1> 'int ({{.*}}) __attribute__((nothrow))' Function [[ADDR_27:0x[a-z0-9]*]] 'also_before4[implementation={vendor(llvm)}]' 'int ({{.*}}) __attribute__((nothrow))' // CXX-NEXT: |-FunctionDecl [[ADDR_6]] <line:6:15, line:27:1> line:6:15 constexpr also_before1[implementation={vendor(llvm)}] 'int ({{.*}})' // CXX-NEXT: | `-CompoundStmt [[ADDR_28:0x[a-z0-9]*]] <line:25:30, line:27:1> // CXX-NEXT: | `-ReturnStmt [[ADDR_29:0x[a-z0-9]*]] <line:26:3, col:10> // CXX-NEXT: | `-IntegerLiteral [[ADDR_30:0x[a-z0-9]*]] <col:10> 'int' 0 // CXX-NEXT: |-FunctionDecl [[ADDR_13]] <line:28:1, line:30:1> line:28:1 also_before2[implementation={vendor(llvm)}] 'int ({{.*}})' static // CXX-NEXT: | `-CompoundStmt [[ADDR_31:0x[a-z0-9]*]] <col:31, line:30:1> // CXX-NEXT: | `-ReturnStmt [[ADDR_32:0x[a-z0-9]*]] <line:29:3, col:10> // CXX-NEXT: | `-IntegerLiteral [[ADDR_33:0x[a-z0-9]*]] <col:10> 'int' 0 // CXX-NEXT: |-FunctionDecl [[ADDR_20]] <line:31:1, line:33:1> line:31:1 also_before3[implementation={vendor(llvm)}] 'int ({{.*}}) __attribute__((nothrow))' // CXX-NEXT: | `-CompoundStmt [[ADDR_34:0x[a-z0-9]*]] <col:49, line:33:1> // CXX-NEXT: | `-ReturnStmt [[ADDR_35:0x[a-z0-9]*]] <line:32:3, col:10> // CXX-NEXT: | `-IntegerLiteral [[ADDR_36:0x[a-z0-9]*]] <col:10> 'int' 0 // CXX-NEXT: |-FunctionDecl [[ADDR_27]] <line:34:1, line:36:1> line:34:1 constexpr also_before4[implementation={vendor(llvm)}] 'int ({{.*}}) __attribute__((nothrow))' static inline // CXX-NEXT: | |-CompoundStmt [[ADDR_37:0x[a-z0-9]*]] <col:88, line:36:1> // CXX-NEXT: | | `-ReturnStmt [[ADDR_38:0x[a-z0-9]*]] <line:35:3, col:10> // CXX-NEXT: | | `-IntegerLiteral [[ADDR_39:0x[a-z0-9]*]] <col:10> 'int' 0 // CXX-NEXT: | `-AlwaysInlineAttr [[ADDR_40:0x[a-z0-9]*]] <line:34:38> always_inline // CXX-NEXT: `-FunctionDecl [[ADDR_41:0x[a-z0-9]*]] <line:40:1, line:43:1> line:40:5 main 'int ({{.*}})' // CXX-NEXT: `-CompoundStmt [[ADDR_42:0x[a-z0-9]*]] <col:12, line:43:1> // CXX-NEXT: `-ReturnStmt [[ADDR_43:0x[a-z0-9]*]] <line:42:3, col:74> // CXX-NEXT: `-BinaryOperator [[ADDR_44:0x[a-z0-9]*]] <col:10, col:74> 'int' '+' // CXX-NEXT: |-BinaryOperator [[ADDR_45:0x[a-z0-9]*]] <col:10, col:57> 'int' '+' // CXX-NEXT: | |-BinaryOperator [[ADDR_46:0x[a-z0-9]*]] <col:10, col:40> 'int' '+' // CXX-NEXT: | | |-PseudoObjectExpr [[ADDR_47:0x[a-z0-9]*]] <col:10, col:23> 'int' // CXX-NEXT: | | | |-CallExpr [[ADDR_48:0x[a-z0-9]*]] <col:10, col:23> 'int' // CXX-NEXT: | | | | `-ImplicitCastExpr [[ADDR_49:0x[a-z0-9]*]] <col:10> 'int (*)({{.*}})' <FunctionToPointerDecay> // CXX-NEXT: | | | | `-DeclRefExpr [[ADDR_50:0x[a-z0-9]*]] <col:10> 'int ({{.*}})' {{.*}}Function [[ADDR_0]] 'also_before1' 'int ({{.*}})' // CXX-NEXT: | | | `-CallExpr [[ADDR_51:0x[a-z0-9]*]] <line:6:15, line:42:23> 'int' // CXX-NEXT: | | | `-ImplicitCastExpr [[ADDR_52:0x[a-z0-9]*]] <line:6:15> 'int (*)({{.*}})' <FunctionToPointerDecay> // CXX-NEXT: | | | `-DeclRefExpr [[ADDR_5]] <col:15> 'int ({{.*}})' Function [[ADDR_6]] 'also_before1[implementation={vendor(llvm)}]' 'int ({{.*}})' // CXX-NEXT: | | `-PseudoObjectExpr [[ADDR_53:0x[a-z0-9]*]] <line:42:27, col:40> 'int' // CXX-NEXT: | | |-CallExpr [[ADDR_54:0x[a-z0-9]*]] <col:27, col:40> 'int' // CXX-NEXT: | | | `-ImplicitCastExpr [[ADDR_55:0x[a-z0-9]*]] <col:27> 'int (*)({{.*}})' <FunctionToPointerDecay> // CXX-NEXT: | | | `-DeclRefExpr [[ADDR_56:0x[a-z0-9]*]] <col:27> 'int ({{.*}})' {{.*}}Function [[ADDR_7]] 'also_before2' 'int ({{.*}})' // CXX-NEXT: | | `-CallExpr [[ADDR_57:0x[a-z0-9]*]] <line:28:1, line:42:40> 'int' // CXX-NEXT: | | `-ImplicitCastExpr [[ADDR_58:0x[a-z0-9]*]] <line:28:1> 'int (*)({{.*}})' <FunctionToPointerDecay> // CXX-NEXT: | | `-DeclRefExpr [[ADDR_12]] <col:1> 'int ({{.*}})' Function [[ADDR_13]] 'also_before2[implementation={vendor(llvm)}]' 'int ({{.*}})' // CXX-NEXT: | `-PseudoObjectExpr [[ADDR_59:0x[a-z0-9]*]] <line:42:44, col:57> 'int' // CXX-NEXT: | |-CallExpr [[ADDR_60:0x[a-z0-9]*]] <col:44, col:57> 'int' // CXX-NEXT: | | `-ImplicitCastExpr [[ADDR_61:0x[a-z0-9]*]] <col:44> 'int (*)({{.*}})' <FunctionToPointerDecay> // CXX-NEXT: | | `-DeclRefExpr [[ADDR_62:0x[a-z0-9]*]] <col:44> 'int ({{.*}})' {{.*}}Function [[ADDR_14]] 'also_before3' 'int ({{.*}})' // CXX-NEXT: | `-CallExpr [[ADDR_63:0x[a-z0-9]*]] <line:31:1, line:42:57> 'int' // CXX-NEXT: | `-ImplicitCastExpr [[ADDR_64:0x[a-z0-9]*]] <line:31:1> 'int (*)({{.*}}) __attribute__((nothrow))' <FunctionToPointerDecay> // CXX-NEXT: | `-DeclRefExpr [[ADDR_19]] <col:1> 'int ({{.*}}) __attribute__((nothrow))' Function [[ADDR_20]] 'also_before3[implementation={vendor(llvm)}]' 'int ({{.*}}) __attribute__((nothrow))' // CXX-NEXT: `-PseudoObjectExpr [[ADDR_65:0x[a-z0-9]*]] <line:42:61, col:74> 'int' // CXX-NEXT: |-CallExpr [[ADDR_66:0x[a-z0-9]*]] <col:61, col:74> 'int' // CXX-NEXT: | `-ImplicitCastExpr [[ADDR_67:0x[a-z0-9]*]] <col:61> 'int (*)({{.*}})' <FunctionToPointerDecay> // CXX-NEXT: | `-DeclRefExpr [[ADDR_68:0x[a-z0-9]*]] <col:61> 'int ({{.*}})' {{.*}}Function [[ADDR_21]] 'also_before4' 'int ({{.*}})' // CXX-NEXT: `-CallExpr [[ADDR_69:0x[a-z0-9]*]] <line:34:1, line:42:74> 'int' // CXX-NEXT: `-ImplicitCastExpr [[ADDR_70:0x[a-z0-9]*]] <line:34:1> 'int (*)({{.*}}) __attribute__((nothrow))' <FunctionToPointerDecay> // CXX-NEXT: `-DeclRefExpr [[ADDR_26]] <col:1> 'int ({{.*}}) __attribute__((nothrow))' Function [[ADDR_27]] 'also_before4[implementation={vendor(llvm)}]' 'int ({{.*}}) __attribute__((nothrow))'
SplineC2RAdoptor.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@intel.com, University of Illinois at Urbana-Champaign // Ye Luo, yeluo@anl.gov, Argonne National Laboratory // Anouar Benali, benali@anl.gov, Argonne 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 ////////////////////////////////////////////////////////////////////////////////////// /** @file SplineC2RSoA.h * * Adoptor classes to handle complex-to-(real,complex) with arbitrary precision */ #ifndef QMCPLUSPLUS_EINSPLINE_C2R_ADOPTOR_H #define QMCPLUSPLUS_EINSPLINE_C2R_ADOPTOR_H #include <OhmmsSoA/Container.h> #include <spline2/MultiBspline.hpp> #include <spline2/MultiBsplineEval.hpp> #include "QMCWaveFunctions/BsplineFactory/SplineAdoptorBase.h" #include <Utilities/FairDivide.h> namespace qmcplusplus { /** adoptor class to match std::complex<ST> spline with TT real SPOs * @tparam ST precision of spline * @tparam TT precision of SPOs * @tparam D dimension * * Requires temporage storage and multiplication of phase vectors * Internal storage use double sized arrays of ST type, aligned and padded. */ template<typename ST, typename TT> struct SplineC2RSoA: public SplineAdoptorBase<ST,3> { static const int D=3; using BaseType=SplineAdoptorBase<ST,3>; using SplineType=typename bspline_traits<ST,3>::SplineType; using BCType=typename bspline_traits<ST,3>::BCType; using DataType=ST; using PointType=typename BaseType::PointType; using SingleSplineType=typename BaseType::SingleSplineType; using vContainer_type=Vector<ST,aligned_allocator<ST> >; using gContainer_type=VectorSoaContainer<ST,3>; using hContainer_type=VectorSoaContainer<ST,6>; using ghContainer_type=VectorSoaContainer<ST,10>; using BaseType::first_spo; using BaseType::last_spo; using BaseType::GGt; using BaseType::PrimLattice; using BaseType::kPoints; using BaseType::MakeTwoCopies; using BaseType::offset; ///number of complex bands int nComplexBands; ///number of points of the original grid int BaseN[3]; ///offset of the original grid, always 0 int BaseOffset[3]; ///multi bspline set MultiBspline<ST>* SplineInst; ///expose the pointer to reuse the reader and only assigned with create_spline ///also used as identifier of shallow copy SplineType* MultiSpline; vContainer_type mKK; VectorSoaContainer<ST,3> myKcart; vContainer_type myV; vContainer_type myL; gContainer_type myG; hContainer_type myH; ghContainer_type mygH; SplineC2RSoA(): BaseType(), nComplexBands(0), SplineInst(nullptr), MultiSpline(nullptr) { this->is_complex=true; this->is_soa_ready=true; this->AdoptorName="SplineC2RSoAAdoptor"; this->KeyWord="SplineC2RSoA"; } SplineC2RSoA(const SplineC2RSoA& a): SplineAdoptorBase<ST,3>(a),SplineInst(a.SplineInst),MultiSpline(nullptr), nComplexBands(a.nComplexBands),mKK(a.mKK), myKcart(a.myKcart) { const size_t n=a.myL.size(); myV.resize(n); myG.resize(n); myL.resize(n); myH.resize(n); mygH.resize(n); } ~SplineC2RSoA() { if(MultiSpline != nullptr) delete SplineInst; } inline void resizeStorage(size_t n, size_t nvals) { BaseType::init_base(n); size_t npad=getAlignedSize<ST>(2*n); myV.resize(npad); myG.resize(npad); myL.resize(npad); myH.resize(npad); mygH.resize(npad); } void bcast_tables(Communicate* comm) { chunked_bcast(comm, MultiSpline); } void gather_tables(Communicate* comm) { if(comm->size()==1) return; const int Nbands = kPoints.size(); const int Nbandgroups = comm->size(); offset.resize(Nbandgroups+1,0); FairDivideLow(Nbands,Nbandgroups,offset); for(size_t ib=0; ib<offset.size(); ib++) offset[ib] = offset[ib]*2; gatherv(comm, MultiSpline, MultiSpline->z_stride, offset); } template<typename GT, typename BCT> void create_spline(GT& xyz_g, BCT& xyz_bc) { resize_kpoints(); SplineInst=new MultiBspline<ST>(); SplineInst->create(xyz_g,xyz_bc,myV.size()); MultiSpline=SplineInst->spline_m; for(size_t i=0; i<D; ++i) { BaseOffset[i]=0; BaseN[i]=xyz_g[i].num+3; } qmc_common.memory_allocated += SplineInst->sizeInByte(); } inline void flush_zero() { SplineInst->flush_zero(); } /** remap kPoints to pack the double copy */ inline void resize_kpoints() { #ifndef QMC_CUDA // GPU CUDA code doesn't allow a change of the ordering nComplexBands=this->remap_kpoints(); #endif int nk=kPoints.size(); mKK.resize(nk); myKcart.resize(nk); for(size_t i=0; i<nk; ++i) { mKK[i]=-dot(kPoints[i],kPoints[i]); myKcart(i)=kPoints[i]; } } inline void set_spline(SingleSplineType* spline_r, SingleSplineType* spline_i, int twist, int ispline, int level) { SplineInst->copy_spline(spline_r,2*ispline ,BaseOffset, BaseN); SplineInst->copy_spline(spline_i,2*ispline+1,BaseOffset, BaseN); } void set_spline(ST* restrict psi_r, ST* restrict psi_i, int twist, int ispline, int level) { Vector<ST> v_r(psi_r,0), v_i(psi_i,0); SplineInst->set(2*ispline ,v_r); SplineInst->set(2*ispline+1,v_i); } inline void set_spline_domain(SingleSplineType* spline_r, SingleSplineType* spline_i, int twist, int ispline, const int* offset_l, const int* mesh_l) { } bool read_splines(hdf_archive& h5f) { std::ostringstream o; o<<"spline_" << SplineAdoptorBase<ST,D>::MyIndex; einspline_engine<SplineType> bigtable(SplineInst->spline_m); return h5f.read(bigtable,o.str().c_str());//"spline_0"); } bool write_splines(hdf_archive& h5f) { std::ostringstream o; o<<"spline_" << SplineAdoptorBase<ST,D>::MyIndex; einspline_engine<SplineType> bigtable(SplineInst->spline_m); return h5f.write(bigtable,o.str().c_str());//"spline_0"); } template<typename VV> inline void assign_v(const PointType& r, const vContainer_type& myV, VV& psi, int first = 0, int last = -1) const { // protect last last = last<0 ? kPoints.size() : (last>kPoints.size() ? kPoints.size() : last); const ST x=r[0], y=r[1], z=r[2]; const ST* restrict kx=myKcart.data(0); const ST* restrict ky=myKcart.data(1); const ST* restrict kz=myKcart.data(2); TT* restrict psi_s=psi.data()+first_spo; #pragma omp simd for (size_t j=first; j<std::min(nComplexBands,last); j++) { ST s, c; const size_t jr=j<<1; const size_t ji=jr+1; const ST val_r=myV[jr]; const ST val_i=myV[ji]; sincos(-(x*kx[j]+y*ky[j]+z*kz[j]),&s,&c); psi_s[jr] = val_r*c-val_i*s; psi_s[ji] = val_i*c+val_r*s; } psi_s += nComplexBands; #pragma omp simd for (size_t j=std::max(nComplexBands,first); j<last; j++) { ST s, c; const ST val_r=myV[2*j ]; const ST val_i=myV[2*j+1]; sincos(-(x*kx[j]+y*ky[j]+z*kz[j]),&s,&c); psi_s[j] = val_r*c-val_i*s; } } template<typename VV> inline void evaluate_v(const ParticleSet& P, const int iat, VV& psi) { const PointType& r=P.activeR(iat); PointType ru(PrimLattice.toUnit_floor(r)); #pragma omp parallel { int first, last; FairDivideAligned(myV.size(), getAlignment<ST>(), omp_get_num_threads(), omp_get_thread_num(), first, last); spline2::evaluate3d(SplineInst->spline_m,ru,myV,first,last); assign_v(r,myV,psi,first/2,last/2); } } template<typename VM, typename VAV> inline void evaluateValues(const VirtualParticleSet& VP, VM& psiM, VAV& SPOMem) { #pragma omp parallel { int first, last; FairDivideAligned(myV.size(), getAlignment<ST>(), omp_get_num_threads(), omp_get_thread_num(), first, last); const size_t m=psiM.cols(); for(int iat=0; iat<VP.getTotalNum(); ++iat) { const PointType& r=VP.activeR(iat); PointType ru(PrimLattice.toUnit_floor(r)); Vector<TT> psi(psiM[iat],m); spline2::evaluate3d(SplineInst->spline_m,ru,myV,first,last); assign_v(r,myV,psi,first/2,last/2); } } } inline size_t estimateMemory(const int nP) { return 0; } /** assign_vgl */ template<typename VV, typename GV> inline void assign_vgl(const PointType& r, VV& psi, GV& dpsi, VV& d2psi, int first = 0, int last = -1) const { // protect last last = last<0 ? kPoints.size() : (last>kPoints.size() ? kPoints.size() : last); constexpr ST two(2); const ST g00=PrimLattice.G(0), g01=PrimLattice.G(1), g02=PrimLattice.G(2), g10=PrimLattice.G(3), g11=PrimLattice.G(4), g12=PrimLattice.G(5), g20=PrimLattice.G(6), g21=PrimLattice.G(7), g22=PrimLattice.G(8); const ST x=r[0], y=r[1], z=r[2]; const ST symGG[6]={GGt[0],GGt[1]+GGt[3],GGt[2]+GGt[6],GGt[4],GGt[5]+GGt[7],GGt[8]}; const ST* restrict k0=myKcart.data(0); ASSUME_ALIGNED(k0); const ST* restrict k1=myKcart.data(1); ASSUME_ALIGNED(k1); const ST* restrict k2=myKcart.data(2); ASSUME_ALIGNED(k2); const ST* restrict g0=myG.data(0); ASSUME_ALIGNED(g0); const ST* restrict g1=myG.data(1); ASSUME_ALIGNED(g1); const ST* restrict g2=myG.data(2); ASSUME_ALIGNED(g2); const ST* restrict h00=myH.data(0); ASSUME_ALIGNED(h00); const ST* restrict h01=myH.data(1); ASSUME_ALIGNED(h01); const ST* restrict h02=myH.data(2); ASSUME_ALIGNED(h02); const ST* restrict h11=myH.data(3); ASSUME_ALIGNED(h11); const ST* restrict h12=myH.data(4); ASSUME_ALIGNED(h12); const ST* restrict h22=myH.data(5); ASSUME_ALIGNED(h22); #pragma omp simd for (size_t j=first; j<std::min(nComplexBands,last); j++) { const size_t jr=j<<1; const size_t ji=jr+1; const ST kX=k0[j]; const ST kY=k1[j]; const ST kZ=k2[j]; const ST val_r=myV[jr]; const ST val_i=myV[ji]; //phase ST s, c; sincos(-(x*kX+y*kY+z*kZ),&s,&c); //dot(PrimLattice.G,myG[j]) const ST dX_r = g00*g0[jr]+g01*g1[jr]+g02*g2[jr]; const ST dY_r = g10*g0[jr]+g11*g1[jr]+g12*g2[jr]; const ST dZ_r = g20*g0[jr]+g21*g1[jr]+g22*g2[jr]; const ST dX_i = g00*g0[ji]+g01*g1[ji]+g02*g2[ji]; const ST dY_i = g10*g0[ji]+g11*g1[ji]+g12*g2[ji]; const ST dZ_i = g20*g0[ji]+g21*g1[ji]+g22*g2[ji]; // \f$\nabla \psi_r + {\bf k}\psi_i\f$ const ST gX_r=dX_r+val_i*kX; const ST gY_r=dY_r+val_i*kY; const ST gZ_r=dZ_r+val_i*kZ; const ST gX_i=dX_i-val_r*kX; const ST gY_i=dY_i-val_r*kY; const ST gZ_i=dZ_i-val_r*kZ; const ST lcart_r=SymTrace(h00[jr],h01[jr],h02[jr],h11[jr],h12[jr],h22[jr],symGG); const ST lcart_i=SymTrace(h00[ji],h01[ji],h02[ji],h11[ji],h12[ji],h22[ji],symGG); const ST lap_r=lcart_r+mKK[j]*val_r+two*(kX*dX_i+kY*dY_i+kZ*dZ_i); const ST lap_i=lcart_i+mKK[j]*val_i-two*(kX*dX_r+kY*dY_r+kZ*dZ_r); const size_t psiIndex=first_spo+jr; //this will be fixed later psi[psiIndex ]=c*val_r-s*val_i; psi[psiIndex+1]=c*val_i+s*val_r; d2psi[psiIndex ]=c*lap_r-s*lap_i; d2psi[psiIndex+1]=c*lap_i+s*lap_r; //this will go way with Determinant dpsi[psiIndex ][0]=c*gX_r-s*gX_i; dpsi[psiIndex ][1]=c*gY_r-s*gY_i; dpsi[psiIndex ][2]=c*gZ_r-s*gZ_i; dpsi[psiIndex+1][0]=c*gX_i+s*gX_r; dpsi[psiIndex+1][1]=c*gY_i+s*gY_r; dpsi[psiIndex+1][2]=c*gZ_i+s*gZ_r; } #pragma omp simd for (size_t j=std::max(nComplexBands,first); j<last; j++) { const size_t jr=j<<1; const size_t ji=jr+1; const ST kX=k0[j]; const ST kY=k1[j]; const ST kZ=k2[j]; const ST val_r=myV[jr]; const ST val_i=myV[ji]; //phase ST s, c; sincos(-(x*kX+y*kY+z*kZ),&s,&c); //dot(PrimLattice.G,myG[j]) const ST dX_r = g00*g0[jr]+g01*g1[jr]+g02*g2[jr]; const ST dY_r = g10*g0[jr]+g11*g1[jr]+g12*g2[jr]; const ST dZ_r = g20*g0[jr]+g21*g1[jr]+g22*g2[jr]; const ST dX_i = g00*g0[ji]+g01*g1[ji]+g02*g2[ji]; const ST dY_i = g10*g0[ji]+g11*g1[ji]+g12*g2[ji]; const ST dZ_i = g20*g0[ji]+g21*g1[ji]+g22*g2[ji]; // \f$\nabla \psi_r + {\bf k}\psi_i\f$ const ST gX_r=dX_r+val_i*kX; const ST gY_r=dY_r+val_i*kY; const ST gZ_r=dZ_r+val_i*kZ; const ST gX_i=dX_i-val_r*kX; const ST gY_i=dY_i-val_r*kY; const ST gZ_i=dZ_i-val_r*kZ; const size_t psiIndex=first_spo+nComplexBands+j; psi[psiIndex ]=c*val_r-s*val_i; //this will be fixed later dpsi[psiIndex ][0]=c*gX_r-s*gX_i; dpsi[psiIndex ][1]=c*gY_r-s*gY_i; dpsi[psiIndex ][2]=c*gZ_r-s*gZ_i; const ST lcart_r=SymTrace(h00[jr],h01[jr],h02[jr],h11[jr],h12[jr],h22[jr],symGG); const ST lcart_i=SymTrace(h00[ji],h01[ji],h02[ji],h11[ji],h12[ji],h22[ji],symGG); const ST lap_r=lcart_r+mKK[j]*val_r+two*(kX*dX_i+kY*dY_i+kZ*dZ_i); const ST lap_i=lcart_i+mKK[j]*val_i-two*(kX*dX_r+kY*dY_r+kZ*dZ_r); d2psi[psiIndex ]=c*lap_r-s*lap_i; } } /** assign_vgl_from_l can be used when myL is precomputed and myV,myG,myL in cartesian */ template<typename VV, typename GV> inline void assign_vgl_from_l(const PointType& r, VV& psi, GV& dpsi, VV& d2psi) { constexpr ST two(2); const ST x=r[0], y=r[1], z=r[2]; const ST* restrict k0=myKcart.data(0); ASSUME_ALIGNED(k0); const ST* restrict k1=myKcart.data(1); ASSUME_ALIGNED(k1); const ST* restrict k2=myKcart.data(2); ASSUME_ALIGNED(k2); const ST* restrict g0=myG.data(0); ASSUME_ALIGNED(g0); const ST* restrict g1=myG.data(1); ASSUME_ALIGNED(g1); const ST* restrict g2=myG.data(2); ASSUME_ALIGNED(g2); const size_t N=kPoints.size(); #pragma omp simd for (size_t j=0; j<nComplexBands; j++) { const size_t jr=j<<1; const size_t ji=jr+1; const ST kX=k0[j]; const ST kY=k1[j]; const ST kZ=k2[j]; const ST val_r=myV[jr]; const ST val_i=myV[ji]; //phase ST s, c; sincos(-(x*kX+y*kY+z*kZ),&s,&c); //dot(PrimLattice.G,myG[j]) const ST dX_r = g0[jr]; const ST dY_r = g1[jr]; const ST dZ_r = g2[jr]; const ST dX_i = g0[ji]; const ST dY_i = g1[ji]; const ST dZ_i = g2[ji]; // \f$\nabla \psi_r + {\bf k}\psi_i\f$ const ST gX_r=dX_r+val_i*kX; const ST gY_r=dY_r+val_i*kY; const ST gZ_r=dZ_r+val_i*kZ; const ST gX_i=dX_i-val_r*kX; const ST gY_i=dY_i-val_r*kY; const ST gZ_i=dZ_i-val_r*kZ; const ST lap_r=myL[jr]+mKK[j]*val_r+two*(kX*dX_i+kY*dY_i+kZ*dZ_i); const ST lap_i=myL[ji]+mKK[j]*val_i-two*(kX*dX_r+kY*dY_r+kZ*dZ_r); //this will be fixed later const size_t psiIndex=first_spo+jr; psi[psiIndex ]=c*val_r-s*val_i; psi[psiIndex+1]=c*val_i+s*val_r; d2psi[psiIndex ]=c*lap_r-s*lap_i; d2psi[psiIndex+1]=c*lap_i+s*lap_r; //this will go way with Determinant dpsi[psiIndex ][0]=c*gX_r-s*gX_i; dpsi[psiIndex ][1]=c*gY_r-s*gY_i; dpsi[psiIndex ][2]=c*gZ_r-s*gZ_i; dpsi[psiIndex+1][0]=c*gX_i+s*gX_r; dpsi[psiIndex+1][1]=c*gY_i+s*gY_r; dpsi[psiIndex+1][2]=c*gZ_i+s*gZ_r; } #pragma omp simd for (size_t j=nComplexBands; j<N; j++) { const size_t jr=j<<1; const size_t ji=jr+1; const ST kX=k0[j]; const ST kY=k1[j]; const ST kZ=k2[j]; const ST val_r=myV[jr]; const ST val_i=myV[ji]; //phase ST s, c; sincos(-(x*kX+y*kY+z*kZ),&s,&c); //dot(PrimLattice.G,myG[j]) const ST dX_r = g0[jr]; const ST dY_r = g1[jr]; const ST dZ_r = g2[jr]; const ST dX_i = g0[ji]; const ST dY_i = g1[ji]; const ST dZ_i = g2[ji]; // \f$\nabla \psi_r + {\bf k}\psi_i\f$ const ST gX_r=dX_r+val_i*kX; const ST gY_r=dY_r+val_i*kY; const ST gZ_r=dZ_r+val_i*kZ; const ST gX_i=dX_i-val_r*kX; const ST gY_i=dY_i-val_r*kY; const ST gZ_i=dZ_i-val_r*kZ; const size_t psiIndex=first_spo+nComplexBands+j; psi[psiIndex ]=c*val_r-s*val_i; //this will be fixed later dpsi[psiIndex ][0]=c*gX_r-s*gX_i; dpsi[psiIndex ][1]=c*gY_r-s*gY_i; dpsi[psiIndex ][2]=c*gZ_r-s*gZ_i; const ST lap_r=myL[jr]+mKK[j]*val_r+two*(kX*dX_i+kY*dY_i+kZ*dZ_i); const ST lap_i=myL[ji]+mKK[j]*val_i-two*(kX*dX_r+kY*dY_r+kZ*dZ_r); d2psi[psiIndex ]=c*lap_r-s*lap_i; } } template<typename VV, typename GV> inline void evaluate_vgl(const ParticleSet& P, const int iat, VV& psi, GV& dpsi, VV& d2psi) { const PointType& r=P.activeR(iat); PointType ru(PrimLattice.toUnit_floor(r)); #pragma omp parallel { int first, last; FairDivideAligned(myV.size(), getAlignment<ST>(), omp_get_num_threads(), omp_get_thread_num(), first, last); spline2::evaluate3d_vgh(SplineInst->spline_m,ru,myV,myG,myH,first,last); assign_vgl(r,psi,dpsi,d2psi,first/2,last/2); } } template<typename VV, typename GV, typename GGV> void assign_vgh(const PointType& r, VV& psi, GV& dpsi, GGV& grad_grad_psi, int first = 0, int last = -1) const { // protect last last = last<0 ? kPoints.size() : (last>kPoints.size() ? kPoints.size() : last); const ST g00=PrimLattice.G(0), g01=PrimLattice.G(1), g02=PrimLattice.G(2), g10=PrimLattice.G(3), g11=PrimLattice.G(4), g12=PrimLattice.G(5), g20=PrimLattice.G(6), g21=PrimLattice.G(7), g22=PrimLattice.G(8); const ST x=r[0], y=r[1], z=r[2]; const ST* restrict k0=myKcart.data(0); const ST* restrict k1=myKcart.data(1); const ST* restrict k2=myKcart.data(2); const ST* restrict g0=myG.data(0); const ST* restrict g1=myG.data(1); const ST* restrict g2=myG.data(2); const ST* restrict h00=myH.data(0); const ST* restrict h01=myH.data(1); const ST* restrict h02=myH.data(2); const ST* restrict h11=myH.data(3); const ST* restrict h12=myH.data(4); const ST* restrict h22=myH.data(5); #pragma omp simd for (size_t j=first; j<std::min(nComplexBands,last); j++) { int jr=j<<1; int ji=jr+1; const ST kX=k0[j]; const ST kY=k1[j]; const ST kZ=k2[j]; const ST val_r=myV[jr]; const ST val_i=myV[ji]; //phase ST s, c; sincos(-(x*kX+y*kY+z*kZ),&s,&c); //dot(PrimLattice.G,myG[j]) const ST dX_r = g00*g0[jr]+g01*g1[jr]+g02*g2[jr]; const ST dY_r = g10*g0[jr]+g11*g1[jr]+g12*g2[jr]; const ST dZ_r = g20*g0[jr]+g21*g1[jr]+g22*g2[jr]; const ST dX_i = g00*g0[ji]+g01*g1[ji]+g02*g2[ji]; const ST dY_i = g10*g0[ji]+g11*g1[ji]+g12*g2[ji]; const ST dZ_i = g20*g0[ji]+g21*g1[ji]+g22*g2[ji]; // \f$\nabla \psi_r + {\bf k}\psi_i\f$ const ST gX_r=dX_r+val_i*kX; const ST gY_r=dY_r+val_i*kY; const ST gZ_r=dZ_r+val_i*kZ; const ST gX_i=dX_i-val_r*kX; const ST gY_i=dY_i-val_r*kY; const ST gZ_i=dZ_i-val_r*kZ; const size_t psiIndex=first_spo+jr; psi[psiIndex] =c*val_r-s*val_i; dpsi[psiIndex][0] =c*gX_r-s*gX_i; dpsi[psiIndex][1] =c*gY_r-s*gY_i; dpsi[psiIndex][2] =c*gZ_r-s*gZ_i; psi[psiIndex+1]=c*val_i+s*val_r; dpsi[psiIndex+1][0]=c*gX_i+s*gX_r; dpsi[psiIndex+1][1]=c*gY_i+s*gY_r; dpsi[psiIndex+1][2]=c*gZ_i+s*gZ_r; const ST h_xx_r=v_m_v(h00[jr],h01[jr],h02[jr],h11[jr],h12[jr],h22[jr],g00,g01,g02,g00,g01,g02)+kX*(gX_i+dX_i); const ST h_xy_r=v_m_v(h00[jr],h01[jr],h02[jr],h11[jr],h12[jr],h22[jr],g00,g01,g02,g10,g11,g12)+kX*(gY_i+dY_i); const ST h_xz_r=v_m_v(h00[jr],h01[jr],h02[jr],h11[jr],h12[jr],h22[jr],g00,g01,g02,g20,g21,g22)+kX*(gZ_i+dZ_i); const ST h_yx_r=v_m_v(h00[jr],h01[jr],h02[jr],h11[jr],h12[jr],h22[jr],g10,g11,g12,g00,g01,g02)+kY*(gX_i+dX_i); const ST h_yy_r=v_m_v(h00[jr],h01[jr],h02[jr],h11[jr],h12[jr],h22[jr],g10,g11,g12,g10,g11,g12)+kY*(gY_i+dY_i); const ST h_yz_r=v_m_v(h00[jr],h01[jr],h02[jr],h11[jr],h12[jr],h22[jr],g10,g11,g12,g20,g21,g22)+kY*(gZ_i+dZ_i); const ST h_zx_r=v_m_v(h00[jr],h01[jr],h02[jr],h11[jr],h12[jr],h22[jr],g20,g21,g22,g00,g01,g02)+kZ*(gX_i+dX_i); const ST h_zy_r=v_m_v(h00[jr],h01[jr],h02[jr],h11[jr],h12[jr],h22[jr],g20,g21,g22,g10,g11,g12)+kZ*(gY_i+dY_i); const ST h_zz_r=v_m_v(h00[jr],h01[jr],h02[jr],h11[jr],h12[jr],h22[jr],g20,g21,g22,g20,g21,g22)+kZ*(gZ_i+dZ_i); const ST h_xx_i=v_m_v(h00[ji],h01[ji],h02[ji],h11[ji],h12[ji],h22[ji],g00,g01,g02,g00,g01,g02)-kX*(gX_r+dX_r); const ST h_xy_i=v_m_v(h00[ji],h01[ji],h02[ji],h11[ji],h12[ji],h22[ji],g00,g01,g02,g10,g11,g12)-kX*(gY_r+dY_r); const ST h_xz_i=v_m_v(h00[ji],h01[ji],h02[ji],h11[ji],h12[ji],h22[ji],g00,g01,g02,g20,g21,g22)-kX*(gZ_r+dZ_r); const ST h_yx_i=v_m_v(h00[ji],h01[ji],h02[ji],h11[ji],h12[ji],h22[ji],g10,g11,g12,g00,g01,g02)-kY*(gX_r+dX_r); const ST h_yy_i=v_m_v(h00[ji],h01[ji],h02[ji],h11[ji],h12[ji],h22[ji],g10,g11,g12,g10,g11,g12)-kY*(gY_r+dY_r); const ST h_yz_i=v_m_v(h00[ji],h01[ji],h02[ji],h11[ji],h12[ji],h22[ji],g10,g11,g12,g20,g21,g22)-kY*(gZ_r+dZ_r); const ST h_zx_i=v_m_v(h00[ji],h01[ji],h02[ji],h11[ji],h12[ji],h22[ji],g20,g21,g22,g00,g01,g02)-kZ*(gX_r+dX_r); const ST h_zy_i=v_m_v(h00[ji],h01[ji],h02[ji],h11[ji],h12[ji],h22[ji],g20,g21,g22,g10,g11,g12)-kZ*(gY_r+dY_r); const ST h_zz_i=v_m_v(h00[ji],h01[ji],h02[ji],h11[ji],h12[ji],h22[ji],g20,g21,g22,g20,g21,g22)-kZ*(gZ_r+dZ_r); grad_grad_psi[psiIndex][0]=c*h_xx_r-s*h_xx_i; grad_grad_psi[psiIndex][1]=c*h_xy_r-s*h_xy_i; grad_grad_psi[psiIndex][2]=c*h_xz_r-s*h_xz_i; grad_grad_psi[psiIndex][3]=c*h_yx_r-s*h_yx_i; grad_grad_psi[psiIndex][4]=c*h_yy_r-s*h_yy_i; grad_grad_psi[psiIndex][5]=c*h_yz_r-s*h_yz_i; grad_grad_psi[psiIndex][6]=c*h_zx_r-s*h_zx_i; grad_grad_psi[psiIndex][7]=c*h_zy_r-s*h_zy_i; grad_grad_psi[psiIndex][8]=c*h_zz_r-s*h_zz_i; grad_grad_psi[psiIndex+1][0]=c*h_xx_i+s*h_xx_r; grad_grad_psi[psiIndex+1][1]=c*h_xy_i+s*h_xy_r; grad_grad_psi[psiIndex+1][2]=c*h_xz_i+s*h_xz_r; grad_grad_psi[psiIndex+1][3]=c*h_yx_i+s*h_yx_r; grad_grad_psi[psiIndex+1][4]=c*h_yy_i+s*h_yy_r; grad_grad_psi[psiIndex+1][5]=c*h_yz_i+s*h_yz_r; grad_grad_psi[psiIndex+1][6]=c*h_zx_i+s*h_zx_r; grad_grad_psi[psiIndex+1][7]=c*h_zy_i+s*h_zy_r; grad_grad_psi[psiIndex+1][8]=c*h_zz_i+s*h_zz_r; } #pragma omp simd for (size_t j=std::max(nComplexBands,first); j<last; j++) { int jr=j<<1; int ji=jr+1; const ST kX=k0[j]; const ST kY=k1[j]; const ST kZ=k2[j]; const ST val_r=myV[jr]; const ST val_i=myV[ji]; //phase ST s, c; sincos(-(x*kX+y*kY+z*kZ),&s,&c); //dot(PrimLattice.G,myG[j]) const ST dX_r = g00*g0[jr]+g01*g1[jr]+g02*g2[jr]; const ST dY_r = g10*g0[jr]+g11*g1[jr]+g12*g2[jr]; const ST dZ_r = g20*g0[jr]+g21*g1[jr]+g22*g2[jr]; const ST dX_i = g00*g0[ji]+g01*g1[ji]+g02*g2[ji]; const ST dY_i = g10*g0[ji]+g11*g1[ji]+g12*g2[ji]; const ST dZ_i = g20*g0[ji]+g21*g1[ji]+g22*g2[ji]; // \f$\nabla \psi_r + {\bf k}\psi_i\f$ const ST gX_r=dX_r+val_i*kX; const ST gY_r=dY_r+val_i*kY; const ST gZ_r=dZ_r+val_i*kZ; const ST gX_i=dX_i-val_r*kX; const ST gY_i=dY_i-val_r*kY; const ST gZ_i=dZ_i-val_r*kZ; const size_t psiIndex=first_spo+nComplexBands+j; psi[psiIndex] =c*val_r-s*val_i; dpsi[psiIndex][0] =c*gX_r-s*gX_i; dpsi[psiIndex][1] =c*gY_r-s*gY_i; dpsi[psiIndex][2] =c*gZ_r-s*gZ_i; const ST h_xx_r=v_m_v(h00[jr],h01[jr],h02[jr],h11[jr],h12[jr],h22[jr],g00,g01,g02,g00,g01,g02)+kX*(gX_i+dX_i); const ST h_xy_r=v_m_v(h00[jr],h01[jr],h02[jr],h11[jr],h12[jr],h22[jr],g00,g01,g02,g10,g11,g12)+kX*(gY_i+dY_i); const ST h_xz_r=v_m_v(h00[jr],h01[jr],h02[jr],h11[jr],h12[jr],h22[jr],g00,g01,g02,g20,g21,g22)+kX*(gZ_i+dZ_i); const ST h_yx_r=v_m_v(h00[jr],h01[jr],h02[jr],h11[jr],h12[jr],h22[jr],g10,g11,g12,g00,g01,g02)+kY*(gX_i+dX_i); const ST h_yy_r=v_m_v(h00[jr],h01[jr],h02[jr],h11[jr],h12[jr],h22[jr],g10,g11,g12,g10,g11,g12)+kY*(gY_i+dY_i); const ST h_yz_r=v_m_v(h00[jr],h01[jr],h02[jr],h11[jr],h12[jr],h22[jr],g10,g11,g12,g20,g21,g22)+kY*(gZ_i+dZ_i); const ST h_zx_r=v_m_v(h00[jr],h01[jr],h02[jr],h11[jr],h12[jr],h22[jr],g20,g21,g22,g00,g01,g02)+kZ*(gX_i+dX_i); const ST h_zy_r=v_m_v(h00[jr],h01[jr],h02[jr],h11[jr],h12[jr],h22[jr],g20,g21,g22,g10,g11,g12)+kZ*(gY_i+dY_i); const ST h_zz_r=v_m_v(h00[jr],h01[jr],h02[jr],h11[jr],h12[jr],h22[jr],g20,g21,g22,g20,g21,g22)+kZ*(gZ_i+dZ_i); const ST h_xx_i=v_m_v(h00[ji],h01[ji],h02[ji],h11[ji],h12[ji],h22[ji],g00,g01,g02,g00,g01,g02)-kX*(gX_r+dX_r); const ST h_xy_i=v_m_v(h00[ji],h01[ji],h02[ji],h11[ji],h12[ji],h22[ji],g00,g01,g02,g10,g11,g12)-kX*(gY_r+dY_r); const ST h_xz_i=v_m_v(h00[ji],h01[ji],h02[ji],h11[ji],h12[ji],h22[ji],g00,g01,g02,g20,g21,g22)-kX*(gZ_r+dZ_r); const ST h_yx_i=v_m_v(h00[ji],h01[ji],h02[ji],h11[ji],h12[ji],h22[ji],g10,g11,g12,g00,g01,g02)-kY*(gX_r+dX_r); const ST h_yy_i=v_m_v(h00[ji],h01[ji],h02[ji],h11[ji],h12[ji],h22[ji],g10,g11,g12,g10,g11,g12)-kY*(gY_r+dY_r); const ST h_yz_i=v_m_v(h00[ji],h01[ji],h02[ji],h11[ji],h12[ji],h22[ji],g10,g11,g12,g20,g21,g22)-kY*(gZ_r+dZ_r); const ST h_zx_i=v_m_v(h00[ji],h01[ji],h02[ji],h11[ji],h12[ji],h22[ji],g20,g21,g22,g00,g01,g02)-kZ*(gX_r+dX_r); const ST h_zy_i=v_m_v(h00[ji],h01[ji],h02[ji],h11[ji],h12[ji],h22[ji],g20,g21,g22,g10,g11,g12)-kZ*(gY_r+dY_r); const ST h_zz_i=v_m_v(h00[ji],h01[ji],h02[ji],h11[ji],h12[ji],h22[ji],g20,g21,g22,g20,g21,g22)-kZ*(gZ_r+dZ_r); grad_grad_psi[psiIndex][0]=c*h_xx_r-s*h_xx_i; grad_grad_psi[psiIndex][1]=c*h_xy_r-s*h_xy_i; grad_grad_psi[psiIndex][2]=c*h_xz_r-s*h_xz_i; grad_grad_psi[psiIndex][3]=c*h_yx_r-s*h_yx_i; grad_grad_psi[psiIndex][4]=c*h_yy_r-s*h_yy_i; grad_grad_psi[psiIndex][5]=c*h_yz_r-s*h_yz_i; grad_grad_psi[psiIndex][6]=c*h_zx_r-s*h_zx_i; grad_grad_psi[psiIndex][7]=c*h_zy_r-s*h_zy_i; grad_grad_psi[psiIndex][8]=c*h_zz_r-s*h_zz_i; } } template<typename VV, typename GV, typename GGV> void evaluate_vgh(const ParticleSet& P, const int iat, VV& psi, GV& dpsi, GGV& grad_grad_psi) { const PointType& r=P.activeR(iat); PointType ru(PrimLattice.toUnit_floor(r)); #pragma omp parallel { int first, last; FairDivideAligned(myV.size(), getAlignment<ST>(), omp_get_num_threads(), omp_get_thread_num(), first, last); spline2::evaluate3d_vgh(SplineInst->spline_m,ru,myV,myG,myH,first,last); assign_vgh(r,psi,dpsi,grad_grad_psi,first/2,last/2); } } template<typename VV, typename GV, typename GGV, typename GGGV> void assign_vghgh(const PointType& r, VV& psi, GV& dpsi, GGV& grad_grad_psi, GGGV& grad_grad_grad_psi, int first = 0, int last = -1) const { // protect last last = last<0 ? kPoints.size() : (last>kPoints.size() ? kPoints.size() : last); const ST g00=PrimLattice.G(0), g01=PrimLattice.G(1), g02=PrimLattice.G(2), g10=PrimLattice.G(3), g11=PrimLattice.G(4), g12=PrimLattice.G(5), g20=PrimLattice.G(6), g21=PrimLattice.G(7), g22=PrimLattice.G(8); const ST x=r[0], y=r[1], z=r[2]; const ST* restrict k0=myKcart.data(0); const ST* restrict k1=myKcart.data(1); const ST* restrict k2=myKcart.data(2); const ST* restrict g0=myG.data(0); const ST* restrict g1=myG.data(1); const ST* restrict g2=myG.data(2); const ST* restrict h00=myH.data(0); const ST* restrict h01=myH.data(1); const ST* restrict h02=myH.data(2); const ST* restrict h11=myH.data(3); const ST* restrict h12=myH.data(4); const ST* restrict h22=myH.data(5); const ST* restrict gh000=mygH.data(0); const ST* restrict gh001=mygH.data(1); const ST* restrict gh002=mygH.data(2); const ST* restrict gh011=mygH.data(3); const ST* restrict gh012=mygH.data(4); const ST* restrict gh022=mygH.data(5); const ST* restrict gh111=mygH.data(6); const ST* restrict gh112=mygH.data(7); const ST* restrict gh122=mygH.data(8); const ST* restrict gh222=mygH.data(9); //SIMD doesn't work quite right yet. Comment out until further debugging. #pragma omp simd for ( size_t j=first; j<std::min(nComplexBands,last); j++ ) { int jr=j<<1; int ji=jr+1; const ST kX=k0[j]; const ST kY=k1[j]; const ST kZ=k2[j]; const ST val_r=myV[jr]; const ST val_i=myV[ji]; //phase ST s, c; sincos(-(x*kX+y*kY+z*kZ),&s,&c); //dot(PrimLattice.G,myG[j]) const ST dX_r = g00*g0[jr]+g01*g1[jr]+g02*g2[jr]; const ST dY_r = g10*g0[jr]+g11*g1[jr]+g12*g2[jr]; const ST dZ_r = g20*g0[jr]+g21*g1[jr]+g22*g2[jr]; const ST dX_i = g00*g0[ji]+g01*g1[ji]+g02*g2[ji]; const ST dY_i = g10*g0[ji]+g11*g1[ji]+g12*g2[ji]; const ST dZ_i = g20*g0[ji]+g21*g1[ji]+g22*g2[ji]; // \f$\nabla \psi_r + {\bf k}\psi_i\f$ const ST gX_r=dX_r+val_i*kX; const ST gY_r=dY_r+val_i*kY; const ST gZ_r=dZ_r+val_i*kZ; const ST gX_i=dX_i-val_r*kX; const ST gY_i=dY_i-val_r*kY; const ST gZ_i=dZ_i-val_r*kZ; const size_t psiIndex=first_spo+jr; psi[psiIndex] =c*val_r-s*val_i; dpsi[psiIndex][0]=c*gX_r -s*gX_i; dpsi[psiIndex][1]=c*gY_r -s*gY_i; dpsi[psiIndex][2]=c*gZ_r -s*gZ_i; psi[psiIndex+1] =c*val_i+s*val_r; dpsi[psiIndex+1][0]=c*gX_i +s*gX_r; dpsi[psiIndex+1][1]=c*gY_i +s*gY_r; dpsi[psiIndex+1][2]=c*gZ_i +s*gZ_r; //intermediates for computation of hessian. \partial_i \partial_j phi in cartesian coordinates. const ST f_xx_r=v_m_v(h00[jr],h01[jr],h02[jr],h11[jr],h12[jr],h22[jr],g00,g01,g02,g00,g01,g02); const ST f_xy_r=v_m_v(h00[jr],h01[jr],h02[jr],h11[jr],h12[jr],h22[jr],g00,g01,g02,g10,g11,g12); const ST f_xz_r=v_m_v(h00[jr],h01[jr],h02[jr],h11[jr],h12[jr],h22[jr],g00,g01,g02,g20,g21,g22); const ST f_yy_r=v_m_v(h00[jr],h01[jr],h02[jr],h11[jr],h12[jr],h22[jr],g10,g11,g12,g10,g11,g12); const ST f_yz_r=v_m_v(h00[jr],h01[jr],h02[jr],h11[jr],h12[jr],h22[jr],g10,g11,g12,g20,g21,g22); const ST f_zz_r=v_m_v(h00[jr],h01[jr],h02[jr],h11[jr],h12[jr],h22[jr],g20,g21,g22,g20,g21,g22); const ST f_xx_i=v_m_v(h00[ji],h01[ji],h02[ji],h11[ji],h12[ji],h22[ji],g00,g01,g02,g00,g01,g02); const ST f_xy_i=v_m_v(h00[ji],h01[ji],h02[ji],h11[ji],h12[ji],h22[ji],g00,g01,g02,g10,g11,g12); const ST f_xz_i=v_m_v(h00[ji],h01[ji],h02[ji],h11[ji],h12[ji],h22[ji],g00,g01,g02,g20,g21,g22); const ST f_yy_i=v_m_v(h00[ji],h01[ji],h02[ji],h11[ji],h12[ji],h22[ji],g10,g11,g12,g10,g11,g12); const ST f_yz_i=v_m_v(h00[ji],h01[ji],h02[ji],h11[ji],h12[ji],h22[ji],g10,g11,g12,g20,g21,g22); const ST f_zz_i=v_m_v(h00[ji],h01[ji],h02[ji],h11[ji],h12[ji],h22[ji],g20,g21,g22,g20,g21,g22); const ST h_xx_r=f_xx_r+2*kX*dX_i-kX*kX*val_r; const ST h_xy_r=f_xy_r+(kX*dY_i+kY*dX_i)-kX*kY*val_r; const ST h_xz_r=f_xz_r+(kX*dZ_i+kZ*dX_i)-kX*kZ*val_r; const ST h_yy_r=f_yy_r+2*kY*dY_i-kY*kY*val_r; const ST h_yz_r=f_yz_r+(kY*dZ_i+kZ*dY_i)-kY*kZ*val_r; const ST h_zz_r=f_zz_r+2*kZ*dZ_i-kZ*kZ*val_r; const ST h_xx_i=f_xx_i-2*kX*dX_r-kX*kX*val_i; const ST h_xy_i=f_xy_i-(kX*dY_r+kY*dX_r)-kX*kY*val_i; const ST h_xz_i=f_xz_i-(kX*dZ_r+kZ*dX_r)-kX*kZ*val_i; const ST h_yy_i=f_yy_i-2*kY*dY_r-kY*kY*val_i; const ST h_yz_i=f_yz_i-(kZ*dY_r+kY*dZ_r)-kZ*kY*val_i; const ST h_zz_i=f_zz_i-2*kZ*dZ_r-kZ*kZ*val_i; grad_grad_psi[psiIndex][0]=c*h_xx_r-s*h_xx_i; grad_grad_psi[psiIndex][1]=c*h_xy_r-s*h_xy_i; grad_grad_psi[psiIndex][2]=c*h_xz_r-s*h_xz_i; grad_grad_psi[psiIndex][3]=c*h_xy_r-s*h_xy_i; grad_grad_psi[psiIndex][4]=c*h_yy_r-s*h_yy_i; grad_grad_psi[psiIndex][5]=c*h_yz_r-s*h_yz_i; grad_grad_psi[psiIndex][6]=c*h_xz_r-s*h_xz_i; grad_grad_psi[psiIndex][7]=c*h_yz_r-s*h_yz_i; grad_grad_psi[psiIndex][8]=c*h_zz_r-s*h_zz_i; grad_grad_psi[psiIndex+1][0]=c*h_xx_i+s*h_xx_r; grad_grad_psi[psiIndex+1][1]=c*h_xy_i+s*h_xy_r; grad_grad_psi[psiIndex+1][2]=c*h_xz_i+s*h_xz_r; grad_grad_psi[psiIndex+1][3]=c*h_xy_i+s*h_xy_r; grad_grad_psi[psiIndex+1][4]=c*h_yy_i+s*h_yy_r; grad_grad_psi[psiIndex+1][5]=c*h_yz_i+s*h_yz_r; grad_grad_psi[psiIndex+1][6]=c*h_xz_i+s*h_xz_r; grad_grad_psi[psiIndex+1][7]=c*h_yz_i+s*h_yz_r; grad_grad_psi[psiIndex+1][8]=c*h_zz_i+s*h_zz_r; //These are the real and imaginary components of the third SPO derivative. _xxx denotes // third derivative w.r.t. x, _xyz, a derivative with resepect to x,y, and z, and so on. const ST f3_xxx_r=t3_contract(gh000[jr], gh001[jr], gh002[jr], gh011[jr], gh012[jr], gh022[jr], gh111[jr], gh112[jr], gh122[jr], gh222[jr], g00,g01,g02,g00,g01,g02,g00,g01,g02); const ST f3_xxy_r=t3_contract(gh000[jr], gh001[jr], gh002[jr], gh011[jr], gh012[jr], gh022[jr], gh111[jr], gh112[jr], gh122[jr], gh222[jr], g00,g01,g02,g00,g01,g02,g10,g11,g12); const ST f3_xxz_r=t3_contract(gh000[jr], gh001[jr], gh002[jr], gh011[jr], gh012[jr], gh022[jr], gh111[jr], gh112[jr], gh122[jr], gh222[jr], g00,g01,g02,g00,g01,g02,g20,g21,g22); const ST f3_xyy_r=t3_contract(gh000[jr], gh001[jr], gh002[jr], gh011[jr], gh012[jr], gh022[jr], gh111[jr], gh112[jr], gh122[jr], gh222[jr], g00,g01,g02,g10,g11,g12,g10,g11,g12); const ST f3_xyz_r=t3_contract(gh000[jr], gh001[jr], gh002[jr], gh011[jr], gh012[jr], gh022[jr], gh111[jr], gh112[jr], gh122[jr], gh222[jr], g00,g01,g02,g10,g11,g12,g20,g21,g22); const ST f3_xzz_r=t3_contract(gh000[jr], gh001[jr], gh002[jr], gh011[jr], gh012[jr], gh022[jr], gh111[jr], gh112[jr], gh122[jr], gh222[jr], g00,g01,g02,g20,g21,g22,g20,g21,g22); const ST f3_yyy_r=t3_contract(gh000[jr], gh001[jr], gh002[jr], gh011[jr], gh012[jr], gh022[jr], gh111[jr], gh112[jr], gh122[jr], gh222[jr], g10,g11,g12,g10,g11,g12,g10,g11,g12); const ST f3_yyz_r=t3_contract(gh000[jr], gh001[jr], gh002[jr], gh011[jr], gh012[jr], gh022[jr], gh111[jr], gh112[jr], gh122[jr], gh222[jr], g10,g11,g12,g10,g11,g12,g20,g21,g22); const ST f3_yzz_r=t3_contract(gh000[jr], gh001[jr], gh002[jr], gh011[jr], gh012[jr], gh022[jr], gh111[jr], gh112[jr], gh122[jr], gh222[jr], g10,g11,g12,g20,g21,g22,g20,g21,g22); const ST f3_zzz_r=t3_contract(gh000[jr], gh001[jr], gh002[jr], gh011[jr], gh012[jr], gh022[jr], gh111[jr], gh112[jr], gh122[jr], gh222[jr], g20,g21,g22,g20,g21,g22,g20,g21,g22); const ST f3_xxx_i=t3_contract(gh000[ji], gh001[ji], gh002[ji], gh011[ji], gh012[ji], gh022[ji], gh111[ji], gh112[ji], gh122[ji], gh222[ji], g00,g01,g02,g00,g01,g02,g00,g01,g02); const ST f3_xxy_i=t3_contract(gh000[ji], gh001[ji], gh002[ji], gh011[ji], gh012[ji], gh022[ji], gh111[ji], gh112[ji], gh122[ji], gh222[ji], g00,g01,g02,g00,g01,g02,g10,g11,g12); const ST f3_xxz_i=t3_contract(gh000[ji], gh001[ji], gh002[ji], gh011[ji], gh012[ji], gh022[ji], gh111[ji], gh112[ji], gh122[ji], gh222[ji], g00,g01,g02,g00,g01,g02,g20,g21,g22); const ST f3_xyy_i=t3_contract(gh000[ji], gh001[ji], gh002[ji], gh011[ji], gh012[ji], gh022[ji], gh111[ji], gh112[ji], gh122[ji], gh222[ji], g00,g01,g02,g10,g11,g12,g10,g11,g12); const ST f3_xyz_i=t3_contract(gh000[ji], gh001[ji], gh002[ji], gh011[ji], gh012[ji], gh022[ji], gh111[ji], gh112[ji], gh122[ji], gh222[ji], g00,g01,g02,g10,g11,g12,g20,g21,g22); const ST f3_xzz_i=t3_contract(gh000[ji], gh001[ji], gh002[ji], gh011[ji], gh012[ji], gh022[ji], gh111[ji], gh112[ji], gh122[ji], gh222[ji], g00,g01,g02,g20,g21,g22,g20,g21,g22); const ST f3_yyy_i=t3_contract(gh000[ji], gh001[ji], gh002[ji], gh011[ji], gh012[ji], gh022[ji], gh111[ji], gh112[ji], gh122[ji], gh222[ji], g10,g11,g12,g10,g11,g12,g10,g11,g12); const ST f3_yyz_i=t3_contract(gh000[ji], gh001[ji], gh002[ji], gh011[ji], gh012[ji], gh022[ji], gh111[ji], gh112[ji], gh122[ji], gh222[ji], g10,g11,g12,g10,g11,g12,g20,g21,g22); const ST f3_yzz_i=t3_contract(gh000[ji], gh001[ji], gh002[ji], gh011[ji], gh012[ji], gh022[ji], gh111[ji], gh112[ji], gh122[ji], gh222[ji], g10,g11,g12,g20,g21,g22,g20,g21,g22); const ST f3_zzz_i=t3_contract(gh000[ji], gh001[ji], gh002[ji], gh011[ji], gh012[ji], gh022[ji], gh111[ji], gh112[ji], gh122[ji], gh222[ji], g20,g21,g22,g20,g21,g22,g20,g21,g22); //Here is where we build up the components of the physical hessian gradient, namely, d^3/dx^3(e^{-ik*r}\phi(r) const ST gh_xxx_r= f3_xxx_r + 3*kX*f_xx_i - 3*kX*kX*dX_r - kX*kX*kX*val_i; const ST gh_xxx_i= f3_xxx_i - 3*kX*f_xx_r - 3*kX*kX*dX_i + kX*kX*kX*val_r; const ST gh_xxy_r= f3_xxy_r +(kY*f_xx_i+2*kX*f_xy_i) - (kX*kX*dY_r+2*kX*kY*dX_r)-kX*kX*kY*val_i; const ST gh_xxy_i= f3_xxy_i -(kY*f_xx_r+2*kX*f_xy_r) - (kX*kX*dY_i+2*kX*kY*dX_i)+kX*kX*kY*val_r; const ST gh_xxz_r= f3_xxz_r +(kZ*f_xx_i+2*kX*f_xz_i) - (kX*kX*dZ_r+2*kX*kZ*dX_r)-kX*kX*kZ*val_i; const ST gh_xxz_i= f3_xxz_i -(kZ*f_xx_r+2*kX*f_xz_r) - (kX*kX*dZ_i+2*kX*kZ*dX_i)+kX*kX*kZ*val_r; const ST gh_xyy_r= f3_xyy_r +(2*kY*f_xy_i+kX*f_yy_i) - (2*kX*kY*dY_r+kY*kY*dX_r)-kX*kY*kY*val_i; const ST gh_xyy_i= f3_xyy_i -(2*kY*f_xy_r+kX*f_yy_r) - (2*kX*kY*dY_i+kY*kY*dX_i)+kX*kY*kY*val_r; const ST gh_xyz_r= f3_xyz_r +(kX*f_yz_i+kY*f_xz_i+kZ*f_xy_i)-(kX*kY*dZ_r+kY*kZ*dX_r+kZ*kX*dY_r) - kX*kY*kZ*val_i; const ST gh_xyz_i= f3_xyz_i -(kX*f_yz_r+kY*f_xz_r+kZ*f_xy_r)-(kX*kY*dZ_i+kY*kZ*dX_i+kZ*kX*dY_i) + kX*kY*kZ*val_r; const ST gh_xzz_r= f3_xzz_r +(2*kZ*f_xz_i+kX*f_zz_i) - (2*kX*kZ*dZ_r+kZ*kZ*dX_r)-kX*kZ*kZ*val_i; const ST gh_xzz_i= f3_xzz_i -(2*kZ*f_xz_r+kX*f_zz_r) - (2*kX*kZ*dZ_i+kZ*kZ*dX_i)+kX*kZ*kZ*val_r; const ST gh_yyy_r= f3_yyy_r + 3*kY*f_yy_i - 3*kY*kY*dY_r - kY*kY*kY*val_i; const ST gh_yyy_i= f3_yyy_i - 3*kY*f_yy_r - 3*kY*kY*dY_i + kY*kY*kY*val_r; const ST gh_yyz_r= f3_yyz_r +(kZ*f_yy_i+2*kY*f_yz_i) - (kY*kY*dZ_r+2*kY*kZ*dY_r)-kY*kY*kZ*val_i; const ST gh_yyz_i= f3_yyz_i -(kZ*f_yy_r+2*kY*f_yz_r) - (kY*kY*dZ_i+2*kY*kZ*dY_i)+kY*kY*kZ*val_r; const ST gh_yzz_r= f3_yzz_r +(2*kZ*f_yz_i+kY*f_zz_i) - (2*kY*kZ*dZ_r+kZ*kZ*dY_r)-kY*kZ*kZ*val_i; const ST gh_yzz_i= f3_yzz_i -(2*kZ*f_yz_r+kY*f_zz_r) - (2*kY*kZ*dZ_i+kZ*kZ*dY_i)+kY*kZ*kZ*val_r; const ST gh_zzz_r= f3_zzz_r + 3*kZ*f_zz_i - 3*kZ*kZ*dZ_r - kZ*kZ*kZ*val_i; const ST gh_zzz_i= f3_zzz_i - 3*kZ*f_zz_r - 3*kZ*kZ*dZ_i + kZ*kZ*kZ*val_r; grad_grad_grad_psi[psiIndex][0][0]=c*gh_xxx_r-s*gh_xxx_i; grad_grad_grad_psi[psiIndex][0][1]=c*gh_xxy_r-s*gh_xxy_i; grad_grad_grad_psi[psiIndex][0][2]=c*gh_xxz_r-s*gh_xxz_i; grad_grad_grad_psi[psiIndex][0][3]=c*gh_xxy_r-s*gh_xxy_i; grad_grad_grad_psi[psiIndex][0][4]=c*gh_xyy_r-s*gh_xyy_i; grad_grad_grad_psi[psiIndex][0][5]=c*gh_xyz_r-s*gh_xyz_i; grad_grad_grad_psi[psiIndex][0][6]=c*gh_xxz_r-s*gh_xxz_i; grad_grad_grad_psi[psiIndex][0][7]=c*gh_xyz_r-s*gh_xyz_i; grad_grad_grad_psi[psiIndex][0][8]=c*gh_xzz_r-s*gh_xzz_i; grad_grad_grad_psi[psiIndex][1][0]=c*gh_xxy_r-s*gh_xxy_i; grad_grad_grad_psi[psiIndex][1][1]=c*gh_xyy_r-s*gh_xyy_i; grad_grad_grad_psi[psiIndex][1][2]=c*gh_xyz_r-s*gh_xyz_i; grad_grad_grad_psi[psiIndex][1][3]=c*gh_xyy_r-s*gh_xyy_i; grad_grad_grad_psi[psiIndex][1][4]=c*gh_yyy_r-s*gh_yyy_i; grad_grad_grad_psi[psiIndex][1][5]=c*gh_yyz_r-s*gh_yyz_i; grad_grad_grad_psi[psiIndex][1][6]=c*gh_xyz_r-s*gh_xyz_i; grad_grad_grad_psi[psiIndex][1][7]=c*gh_yyz_r-s*gh_yyz_i; grad_grad_grad_psi[psiIndex][1][8]=c*gh_yzz_r-s*gh_yzz_i; grad_grad_grad_psi[psiIndex][2][0]=c*gh_xxz_r-s*gh_xxz_i; grad_grad_grad_psi[psiIndex][2][1]=c*gh_xyz_r-s*gh_xyz_i; grad_grad_grad_psi[psiIndex][2][2]=c*gh_xzz_r-s*gh_xzz_i; grad_grad_grad_psi[psiIndex][2][3]=c*gh_xyz_r-s*gh_xyz_i; grad_grad_grad_psi[psiIndex][2][4]=c*gh_yyz_r-s*gh_yyz_i; grad_grad_grad_psi[psiIndex][2][5]=c*gh_yzz_r-s*gh_yzz_i; grad_grad_grad_psi[psiIndex][2][6]=c*gh_xzz_r-s*gh_xzz_i; grad_grad_grad_psi[psiIndex][2][7]=c*gh_yzz_r-s*gh_yzz_i; grad_grad_grad_psi[psiIndex][2][8]=c*gh_zzz_r-s*gh_zzz_i; grad_grad_grad_psi[psiIndex+1][0][0]=c*gh_xxx_i+s*gh_xxx_r; grad_grad_grad_psi[psiIndex+1][0][1]=c*gh_xxy_i+s*gh_xxy_r; grad_grad_grad_psi[psiIndex+1][0][2]=c*gh_xxz_i+s*gh_xxz_r; grad_grad_grad_psi[psiIndex+1][0][3]=c*gh_xxy_i+s*gh_xxy_r; grad_grad_grad_psi[psiIndex+1][0][4]=c*gh_xyy_i+s*gh_xyy_r; grad_grad_grad_psi[psiIndex+1][0][5]=c*gh_xyz_i+s*gh_xyz_r; grad_grad_grad_psi[psiIndex+1][0][6]=c*gh_xxz_i+s*gh_xxz_r; grad_grad_grad_psi[psiIndex+1][0][7]=c*gh_xyz_i+s*gh_xyz_r; grad_grad_grad_psi[psiIndex+1][0][8]=c*gh_xzz_i+s*gh_xzz_r; grad_grad_grad_psi[psiIndex+1][1][0]=c*gh_xxy_i+s*gh_xxy_r; grad_grad_grad_psi[psiIndex+1][1][1]=c*gh_xyy_i+s*gh_xyy_r; grad_grad_grad_psi[psiIndex+1][1][2]=c*gh_xyz_i+s*gh_xyz_r; grad_grad_grad_psi[psiIndex+1][1][3]=c*gh_xyy_i+s*gh_xyy_r; grad_grad_grad_psi[psiIndex+1][1][4]=c*gh_yyy_i+s*gh_yyy_r; grad_grad_grad_psi[psiIndex+1][1][5]=c*gh_yyz_i+s*gh_yyz_r; grad_grad_grad_psi[psiIndex+1][1][6]=c*gh_xyz_i+s*gh_xyz_r; grad_grad_grad_psi[psiIndex+1][1][7]=c*gh_yyz_i+s*gh_yyz_r; grad_grad_grad_psi[psiIndex+1][1][8]=c*gh_yzz_i+s*gh_yzz_r; grad_grad_grad_psi[psiIndex+1][2][0]=c*gh_xxz_i+s*gh_xxz_r; grad_grad_grad_psi[psiIndex+1][2][1]=c*gh_xyz_i+s*gh_xyz_r; grad_grad_grad_psi[psiIndex+1][2][2]=c*gh_xzz_i+s*gh_xzz_r; grad_grad_grad_psi[psiIndex+1][2][3]=c*gh_xyz_i+s*gh_xyz_r; grad_grad_grad_psi[psiIndex+1][2][4]=c*gh_yyz_i+s*gh_yyz_r; grad_grad_grad_psi[psiIndex+1][2][5]=c*gh_yzz_i+s*gh_yzz_r; grad_grad_grad_psi[psiIndex+1][2][6]=c*gh_xzz_i+s*gh_xzz_r; grad_grad_grad_psi[psiIndex+1][2][7]=c*gh_yzz_i+s*gh_yzz_r; grad_grad_grad_psi[psiIndex+1][2][8]=c*gh_zzz_i+s*gh_zzz_r; } #pragma omp simd for (size_t j=std::max(nComplexBands,first); j<last; j++) { int jr=j<<1; int ji=jr+1; const ST kX=k0[j]; const ST kY=k1[j]; const ST kZ=k2[j]; const ST val_r=myV[jr]; const ST val_i=myV[ji]; //phase ST s, c; sincos(-(x*kX+y*kY+z*kZ),&s,&c); //dot(PrimLattice.G,myG[j]) const ST dX_r = g00*g0[jr]+g01*g1[jr]+g02*g2[jr]; const ST dY_r = g10*g0[jr]+g11*g1[jr]+g12*g2[jr]; const ST dZ_r = g20*g0[jr]+g21*g1[jr]+g22*g2[jr]; const ST dX_i = g00*g0[ji]+g01*g1[ji]+g02*g2[ji]; const ST dY_i = g10*g0[ji]+g11*g1[ji]+g12*g2[ji]; const ST dZ_i = g20*g0[ji]+g21*g1[ji]+g22*g2[ji]; // \f$\nabla \psi_r + {\bf k}\psi_i\f$ const ST gX_r=dX_r+val_i*kX; const ST gY_r=dY_r+val_i*kY; const ST gZ_r=dZ_r+val_i*kZ; const ST gX_i=dX_i-val_r*kX; const ST gY_i=dY_i-val_r*kY; const ST gZ_i=dZ_i-val_r*kZ; const size_t psiIndex=first_spo+nComplexBands+j; psi[psiIndex] =c*val_r-s*val_i; dpsi[psiIndex][0]=c*gX_r -s*gX_i; dpsi[psiIndex][1]=c*gY_r -s*gY_i; dpsi[psiIndex][2]=c*gZ_r -s*gZ_i; //intermediates for computation of hessian. \partial_i \partial_j phi in cartesian coordinates. const ST f_xx_r=v_m_v(h00[jr],h01[jr],h02[jr],h11[jr],h12[jr],h22[jr],g00,g01,g02,g00,g01,g02); const ST f_xy_r=v_m_v(h00[jr],h01[jr],h02[jr],h11[jr],h12[jr],h22[jr],g00,g01,g02,g10,g11,g12); const ST f_xz_r=v_m_v(h00[jr],h01[jr],h02[jr],h11[jr],h12[jr],h22[jr],g00,g01,g02,g20,g21,g22); const ST f_yy_r=v_m_v(h00[jr],h01[jr],h02[jr],h11[jr],h12[jr],h22[jr],g10,g11,g12,g10,g11,g12); const ST f_yz_r=v_m_v(h00[jr],h01[jr],h02[jr],h11[jr],h12[jr],h22[jr],g10,g11,g12,g20,g21,g22); const ST f_zz_r=v_m_v(h00[jr],h01[jr],h02[jr],h11[jr],h12[jr],h22[jr],g20,g21,g22,g20,g21,g22); const ST f_xx_i=v_m_v(h00[ji],h01[ji],h02[ji],h11[ji],h12[ji],h22[ji],g00,g01,g02,g00,g01,g02); const ST f_xy_i=v_m_v(h00[ji],h01[ji],h02[ji],h11[ji],h12[ji],h22[ji],g00,g01,g02,g10,g11,g12); const ST f_xz_i=v_m_v(h00[ji],h01[ji],h02[ji],h11[ji],h12[ji],h22[ji],g00,g01,g02,g20,g21,g22); const ST f_yy_i=v_m_v(h00[ji],h01[ji],h02[ji],h11[ji],h12[ji],h22[ji],g10,g11,g12,g10,g11,g12); const ST f_yz_i=v_m_v(h00[ji],h01[ji],h02[ji],h11[ji],h12[ji],h22[ji],g10,g11,g12,g20,g21,g22); const ST f_zz_i=v_m_v(h00[ji],h01[ji],h02[ji],h11[ji],h12[ji],h22[ji],g20,g21,g22,g20,g21,g22); const ST h_xx_r=f_xx_r+2*kX*dX_i-kX*kX*val_r; const ST h_xy_r=f_xy_r+(kX*dY_i+kY*dX_i)-kX*kY*val_r; const ST h_xz_r=f_xz_r+(kX*dZ_i+kZ*dX_i)-kX*kZ*val_r; const ST h_yy_r=f_yy_r+2*kY*dY_i-kY*kY*val_r; const ST h_yz_r=f_yz_r+(kY*dZ_i+kZ*dY_i)-kY*kZ*val_r; const ST h_zz_r=f_zz_r+2*kZ*dZ_i-kZ*kZ*val_r; const ST h_xx_i=f_xx_i-2*kX*dX_r-kX*kX*val_i; const ST h_xy_i=f_xy_i-(kX*dY_r+kY*dX_r)-kX*kY*val_i; const ST h_xz_i=f_xz_i-(kX*dZ_r+kZ*dX_r)-kX*kZ*val_i; const ST h_yy_i=f_yy_i-2*kY*dY_r-kY*kY*val_i; const ST h_yz_i=f_yz_i-(kZ*dY_r+kY*dZ_r)-kZ*kY*val_i; const ST h_zz_i=f_zz_i-2*kZ*dZ_r-kZ*kZ*val_i; grad_grad_psi[psiIndex][0]=c*h_xx_r-s*h_xx_i; grad_grad_psi[psiIndex][1]=c*h_xy_r-s*h_xy_i; grad_grad_psi[psiIndex][2]=c*h_xz_r-s*h_xz_i; grad_grad_psi[psiIndex][3]=c*h_xy_r-s*h_xy_i; grad_grad_psi[psiIndex][4]=c*h_yy_r-s*h_yy_i; grad_grad_psi[psiIndex][5]=c*h_yz_r-s*h_yz_i; grad_grad_psi[psiIndex][6]=c*h_xz_r-s*h_xz_i; grad_grad_psi[psiIndex][7]=c*h_yz_r-s*h_yz_i; grad_grad_psi[psiIndex][8]=c*h_zz_r-s*h_zz_i; //These are the real and imaginary components of the third SPO derivative. _xxx denotes // third derivative w.r.t. x, _xyz, a derivative with resepect to x,y, and z, and so on. const ST f3_xxx_r=t3_contract(gh000[jr], gh001[jr], gh002[jr], gh011[jr], gh012[jr], gh022[jr], gh111[jr], gh112[jr], gh122[jr], gh222[jr], g00,g01,g02,g00,g01,g02,g00,g01,g02); const ST f3_xxy_r=t3_contract(gh000[jr], gh001[jr], gh002[jr], gh011[jr], gh012[jr], gh022[jr], gh111[jr], gh112[jr], gh122[jr], gh222[jr], g00,g01,g02,g00,g01,g02,g10,g11,g12); const ST f3_xxz_r=t3_contract(gh000[jr], gh001[jr], gh002[jr], gh011[jr], gh012[jr], gh022[jr], gh111[jr], gh112[jr], gh122[jr], gh222[jr], g00,g01,g02,g00,g01,g02,g20,g21,g22); const ST f3_xyy_r=t3_contract(gh000[jr], gh001[jr], gh002[jr], gh011[jr], gh012[jr], gh022[jr], gh111[jr], gh112[jr], gh122[jr], gh222[jr], g00,g01,g02,g10,g11,g12,g10,g11,g12); const ST f3_xyz_r=t3_contract(gh000[jr], gh001[jr], gh002[jr], gh011[jr], gh012[jr], gh022[jr], gh111[jr], gh112[jr], gh122[jr], gh222[jr], g00,g01,g02,g10,g11,g12,g20,g21,g22); const ST f3_xzz_r=t3_contract(gh000[jr], gh001[jr], gh002[jr], gh011[jr], gh012[jr], gh022[jr], gh111[jr], gh112[jr], gh122[jr], gh222[jr], g00,g01,g02,g20,g21,g22,g20,g21,g22); const ST f3_yyy_r=t3_contract(gh000[jr], gh001[jr], gh002[jr], gh011[jr], gh012[jr], gh022[jr], gh111[jr], gh112[jr], gh122[jr], gh222[jr], g10,g11,g12,g10,g11,g12,g10,g11,g12); const ST f3_yyz_r=t3_contract(gh000[jr], gh001[jr], gh002[jr], gh011[jr], gh012[jr], gh022[jr], gh111[jr], gh112[jr], gh122[jr], gh222[jr], g10,g11,g12,g10,g11,g12,g20,g21,g22); const ST f3_yzz_r=t3_contract(gh000[jr], gh001[jr], gh002[jr], gh011[jr], gh012[jr], gh022[jr], gh111[jr], gh112[jr], gh122[jr], gh222[jr], g10,g11,g12,g20,g21,g22,g20,g21,g22); const ST f3_zzz_r=t3_contract(gh000[jr], gh001[jr], gh002[jr], gh011[jr], gh012[jr], gh022[jr], gh111[jr], gh112[jr], gh122[jr], gh222[jr], g20,g21,g22,g20,g21,g22,g20,g21,g22); const ST f3_xxx_i=t3_contract(gh000[ji], gh001[ji], gh002[ji], gh011[ji], gh012[ji], gh022[ji], gh111[ji], gh112[ji], gh122[ji], gh222[ji], g00,g01,g02,g00,g01,g02,g00,g01,g02); const ST f3_xxy_i=t3_contract(gh000[ji], gh001[ji], gh002[ji], gh011[ji], gh012[ji], gh022[ji], gh111[ji], gh112[ji], gh122[ji], gh222[ji], g00,g01,g02,g00,g01,g02,g10,g11,g12); const ST f3_xxz_i=t3_contract(gh000[ji], gh001[ji], gh002[ji], gh011[ji], gh012[ji], gh022[ji], gh111[ji], gh112[ji], gh122[ji], gh222[ji], g00,g01,g02,g00,g01,g02,g20,g21,g22); const ST f3_xyy_i=t3_contract(gh000[ji], gh001[ji], gh002[ji], gh011[ji], gh012[ji], gh022[ji], gh111[ji], gh112[ji], gh122[ji], gh222[ji], g00,g01,g02,g10,g11,g12,g10,g11,g12); const ST f3_xyz_i=t3_contract(gh000[ji], gh001[ji], gh002[ji], gh011[ji], gh012[ji], gh022[ji], gh111[ji], gh112[ji], gh122[ji], gh222[ji], g00,g01,g02,g10,g11,g12,g20,g21,g22); const ST f3_xzz_i=t3_contract(gh000[ji], gh001[ji], gh002[ji], gh011[ji], gh012[ji], gh022[ji], gh111[ji], gh112[ji], gh122[ji], gh222[ji], g00,g01,g02,g20,g21,g22,g20,g21,g22); const ST f3_yyy_i=t3_contract(gh000[ji], gh001[ji], gh002[ji], gh011[ji], gh012[ji], gh022[ji], gh111[ji], gh112[ji], gh122[ji], gh222[ji], g10,g11,g12,g10,g11,g12,g10,g11,g12); const ST f3_yyz_i=t3_contract(gh000[ji], gh001[ji], gh002[ji], gh011[ji], gh012[ji], gh022[ji], gh111[ji], gh112[ji], gh122[ji], gh222[ji], g10,g11,g12,g10,g11,g12,g20,g21,g22); const ST f3_yzz_i=t3_contract(gh000[ji], gh001[ji], gh002[ji], gh011[ji], gh012[ji], gh022[ji], gh111[ji], gh112[ji], gh122[ji], gh222[ji], g10,g11,g12,g20,g21,g22,g20,g21,g22); const ST f3_zzz_i=t3_contract(gh000[ji], gh001[ji], gh002[ji], gh011[ji], gh012[ji], gh022[ji], gh111[ji], gh112[ji], gh122[ji], gh222[ji], g20,g21,g22,g20,g21,g22,g20,g21,g22); //Here is where we build up the components of the physical hessian gradient, namely, d^3/dx^3(e^{-ik*r}\phi(r) const ST gh_xxx_r= f3_xxx_r + 3*kX*f_xx_i - 3*kX*kX*dX_r - kX*kX*kX*val_i; const ST gh_xxx_i= f3_xxx_i - 3*kX*f_xx_r - 3*kX*kX*dX_i + kX*kX*kX*val_r; const ST gh_xxy_r= f3_xxy_r +(kY*f_xx_i+2*kX*f_xy_i) - (kX*kX*dY_r+2*kX*kY*dX_r)-kX*kX*kY*val_i; const ST gh_xxy_i= f3_xxy_i -(kY*f_xx_r+2*kX*f_xy_r) - (kX*kX*dY_i+2*kX*kY*dX_i)+kX*kX*kY*val_r; const ST gh_xxz_r= f3_xxz_r +(kZ*f_xx_i+2*kX*f_xz_i) - (kX*kX*dZ_r+2*kX*kZ*dX_r)-kX*kX*kZ*val_i; const ST gh_xxz_i= f3_xxz_i -(kZ*f_xx_r+2*kX*f_xz_r) - (kX*kX*dZ_i+2*kX*kZ*dX_i)+kX*kX*kZ*val_r; const ST gh_xyy_r= f3_xyy_r +(2*kY*f_xy_i+kX*f_yy_i) - (2*kX*kY*dY_r+kY*kY*dX_r)-kX*kY*kY*val_i; const ST gh_xyy_i= f3_xyy_i -(2*kY*f_xy_r+kX*f_yy_r) - (2*kX*kY*dY_i+kY*kY*dX_i)+kX*kY*kY*val_r; const ST gh_xyz_r= f3_xyz_r +(kX*f_yz_i+kY*f_xz_i+kZ*f_xy_i)-(kX*kY*dZ_r+kY*kZ*dX_r+kZ*kX*dY_r) - kX*kY*kZ*val_i; const ST gh_xyz_i= f3_xyz_i -(kX*f_yz_r+kY*f_xz_r+kZ*f_xy_r)-(kX*kY*dZ_i+kY*kZ*dX_i+kZ*kX*dY_i) + kX*kY*kZ*val_r; const ST gh_xzz_r= f3_xzz_r +(2*kZ*f_xz_i+kX*f_zz_i) - (2*kX*kZ*dZ_r+kZ*kZ*dX_r)-kX*kZ*kZ*val_i; const ST gh_xzz_i= f3_xzz_i -(2*kZ*f_xz_r+kX*f_zz_r) - (2*kX*kZ*dZ_i+kZ*kZ*dX_i)+kX*kZ*kZ*val_r; const ST gh_yyy_r= f3_yyy_r + 3*kY*f_yy_i - 3*kY*kY*dY_r - kY*kY*kY*val_i; const ST gh_yyy_i= f3_yyy_i - 3*kY*f_yy_r - 3*kY*kY*dY_i + kY*kY*kY*val_r; const ST gh_yyz_r= f3_yyz_r +(kZ*f_yy_i+2*kY*f_yz_i) - (kY*kY*dZ_r+2*kY*kZ*dY_r)-kY*kY*kZ*val_i; const ST gh_yyz_i= f3_yyz_i -(kZ*f_yy_r+2*kY*f_yz_r) - (kY*kY*dZ_i+2*kY*kZ*dY_i)+kY*kY*kZ*val_r; const ST gh_yzz_r= f3_yzz_r +(2*kZ*f_yz_i+kY*f_zz_i) - (2*kY*kZ*dZ_r+kZ*kZ*dY_r)-kY*kZ*kZ*val_i; const ST gh_yzz_i= f3_yzz_i -(2*kZ*f_yz_r+kY*f_zz_r) - (2*kY*kZ*dZ_i+kZ*kZ*dY_i)+kY*kZ*kZ*val_r; const ST gh_zzz_r= f3_zzz_r + 3*kZ*f_zz_i - 3*kZ*kZ*dZ_r - kZ*kZ*kZ*val_i; const ST gh_zzz_i= f3_zzz_i - 3*kZ*f_zz_r - 3*kZ*kZ*dZ_i + kZ*kZ*kZ*val_r; //[x][xx] //These are the unique entries grad_grad_grad_psi[psiIndex][0][0]=c*gh_xxx_r-s*gh_xxx_i; grad_grad_grad_psi[psiIndex][0][1]=c*gh_xxy_r-s*gh_xxy_i; grad_grad_grad_psi[psiIndex][0][2]=c*gh_xxz_r-s*gh_xxz_i; grad_grad_grad_psi[psiIndex][0][3]=c*gh_xxy_r-s*gh_xxy_i; grad_grad_grad_psi[psiIndex][0][4]=c*gh_xyy_r-s*gh_xyy_i; grad_grad_grad_psi[psiIndex][0][5]=c*gh_xyz_r-s*gh_xyz_i; grad_grad_grad_psi[psiIndex][0][6]=c*gh_xxz_r-s*gh_xxz_i; grad_grad_grad_psi[psiIndex][0][7]=c*gh_xyz_r-s*gh_xyz_i; grad_grad_grad_psi[psiIndex][0][8]=c*gh_xzz_r-s*gh_xzz_i; grad_grad_grad_psi[psiIndex][1][0]=c*gh_xxy_r-s*gh_xxy_i; grad_grad_grad_psi[psiIndex][1][1]=c*gh_xyy_r-s*gh_xyy_i; grad_grad_grad_psi[psiIndex][1][2]=c*gh_xyz_r-s*gh_xyz_i; grad_grad_grad_psi[psiIndex][1][3]=c*gh_xyy_r-s*gh_xyy_i; grad_grad_grad_psi[psiIndex][1][4]=c*gh_yyy_r-s*gh_yyy_i; grad_grad_grad_psi[psiIndex][1][5]=c*gh_yyz_r-s*gh_yyz_i; grad_grad_grad_psi[psiIndex][1][6]=c*gh_xyz_r-s*gh_xyz_i; grad_grad_grad_psi[psiIndex][1][7]=c*gh_yyz_r-s*gh_yyz_i; grad_grad_grad_psi[psiIndex][1][8]=c*gh_yzz_r-s*gh_yzz_i; grad_grad_grad_psi[psiIndex][2][0]=c*gh_xxz_r-s*gh_xxz_i; grad_grad_grad_psi[psiIndex][2][1]=c*gh_xyz_r-s*gh_xyz_i; grad_grad_grad_psi[psiIndex][2][2]=c*gh_xzz_r-s*gh_xzz_i; grad_grad_grad_psi[psiIndex][2][3]=c*gh_xyz_r-s*gh_xyz_i; grad_grad_grad_psi[psiIndex][2][4]=c*gh_yyz_r-s*gh_yyz_i; grad_grad_grad_psi[psiIndex][2][5]=c*gh_yzz_r-s*gh_yzz_i; grad_grad_grad_psi[psiIndex][2][6]=c*gh_xzz_r-s*gh_xzz_i; grad_grad_grad_psi[psiIndex][2][7]=c*gh_yzz_r-s*gh_yzz_i; grad_grad_grad_psi[psiIndex][2][8]=c*gh_zzz_r-s*gh_zzz_i; } } template<typename VV, typename GV, typename GGV, typename GGGV> void evaluate_vghgh(const ParticleSet& P, const int iat, VV& psi, GV& dpsi, GGV& grad_grad_psi, GGGV& grad_grad_grad_psi) { const PointType& r=P.activeR(iat); PointType ru(PrimLattice.toUnit_floor(r)); #pragma omp parallel { int first, last; FairDivideAligned(myV.size(), getAlignment<ST>(), omp_get_num_threads(), omp_get_thread_num(), first, last); spline2::evaluate3d_vghgh(SplineInst->spline_m,ru,myV,myG,myH,mygH,first,last); assign_vghgh(r,psi,dpsi,grad_grad_psi,grad_grad_grad_psi,first/2,last/2); } } }; } #endif
parallelQuicksort.c
void parallelQuicksortRecursive(int* arr, int start, int end); void swap(int* arr, int i, int j); // Quicksort entry-point void parallelQuicksort(int* arr, int len) { if (len > 0) parallelQuicksortRecursive(arr, 0, len - 1); } // Recursive quicksort implementarion void parallelQuicksortRecursive(int* arr, int start, int end) { int i = start; int j = end; int pivot = arr[(i + j) / 2]; // Get the element in the middle of the array and set it as the pivot if (start < end) { while(i <= j) { // Increment i until the value it's pointed at is greater than the pivot while (arr[i] < pivot) i++; // Decrement j until the value it's pointed at is lesser than the pivot while (arr[j] > pivot) j--; if (i <= j) { swap(arr, i, j); i++; j--; } } #pragma omp parallel sections { #pragma omp section parallelQuicksortRecursive(arr, start, j); // Calls quicksort on the left-most part of the array #pragma omp section parallelQuicksortRecursive(arr, i, end); // Calls quicksort on the right-most part of the array } } }
own_filters.c
/******************************************************************************* * Copyright (c) 2020, Intel Corporation * * 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 Intel Corporation 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 OWNER 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. *******************************************************************************/ //////////////////////////////////////////////////////////////////////////////////////// // // scikit-ipp's own functions for filterring images, that uses // Intel(R) Integrated Performance Primitives (Intel(R) IPP) // //////////////////////////////////////////////////////////////////////////////////////// #include "own_filters.h" #define EXIT_FUNC exitLine: /* Label for Exit */ #define check_sts(st) if((st) != ippStsNoErr) goto exitLine //////////////////////////////////////////////////////////////////////////////////////// // // own_FilterBorder // // General border filter // // Note: own_FilterBorder functions on the backend for implementing // gaussian filtering of image as is in scikit-image. // //////////////////////////////////////////////////////////////////////////////////////// IppStatus own_FilterBorder( IppDataType ippImageDataType, IppDataType ippKernelDataType, void * pSrc, void * pDst, void * pKernel, int img_width, int img_height, int kernel_width, int kernel_height, int numChannels, IppRoundMode roundMode, IppiBorderType ippBorderType, float ippBorderValue) { IppStatus status = ippStsNoErr; int sizeof_src; IppiSize roiSize = { img_width, img_height }; // Size of source and // destination ROI in pixels IppiSize kernelSize = { kernel_width, kernel_height }; Ipp8u * pBuffer = NULL; // Pointer to the work buffer IppiFilterBorderSpec * pSpec = NULL; // context structure int iTmpBufSize = 0; // Common work buffer size int iSpecSize = 0; // Common work buffer size int srcStep; // Steps, in bytes, through the int dstStep; status = get_sizeof(ippImageDataType, &sizeof_src); check_sts(status); srcStep = numChannels * img_width * sizeof_src; dstStep = srcStep; status = ippiFilterBorderGetSize(kernelSize, roiSize, ippImageDataType, ippKernelDataType, numChannels, &iSpecSize, &iTmpBufSize); check_sts(status); pSpec = (IppiFilterBorderSpec *)ippsMalloc_8u(iSpecSize); if (pSpec == NULL) { status = ippStsMemAllocErr; check_sts(status); }; pBuffer = ippsMalloc_8u(iTmpBufSize); if (pBuffer == NULL) { status = ippStsMemAllocErr; check_sts(status); }; status = ippiFilterBorderInit(ippKernelDataType, pKernel, kernelSize, 4, ippImageDataType, numChannels, roundMode, pSpec); check_sts(status); status = ippiFilterBorder(ippImageDataType, pSrc, srcStep, pDst, dstStep, roiSize, numChannels, ippBorderType, ippBorderValue, pSpec, pBuffer); check_sts(status); EXIT_FUNC ippsFree(pBuffer); ippsFree(pSpec); return status; } //////////////////////////////////////////////////////////////////////////////////////// // // own_FilterGaussian // // Gaussian filter // // Note: own_FilterGaussian functions on the backend for implementing // gaussian filtering of image as is in scikit-image. // //////////////////////////////////////////////////////////////////////////////////////// IppStatus own_FilterGaussian( IppDataType ippDataType, void * pSrc, void * pDst, int img_width, int img_height, int numChannels, float sigma_, int kernelSize, IppiBorderType ippBorderType, float ippBorderValue) { IppStatus status = ippStsNoErr; Ipp8u *pBuffer = NULL; IppFilterGaussianSpec* pSpec = NULL; // context structure int iTmpBufSize = 0, iSpecSize = 0; // Common work buffer size int sizeof_src; status = get_sizeof(ippDataType, &sizeof_src); check_sts(status); int srcStep = numChannels * img_width * sizeof_src; // Steps, in bytes, through int dstStep = srcStep; // the source/destination //images IppiSize roiSize = { img_width, img_height }; // Size of source/destination //ROI in pixels Ipp32f sigma = (Ipp32f)sigma_; // Pointer to the work buffer status = ippiFilterGaussianGetBufferSize(roiSize, kernelSize, ippDataType, numChannels, &iSpecSize, &iTmpBufSize); check_sts(status); pSpec = (IppFilterGaussianSpec *)ippsMalloc_8u(iSpecSize); if (pSpec == NULL) { status = ippStsMemAllocErr; check_sts(status); } pBuffer = (Ipp8u *)ippsMalloc_8u(iTmpBufSize); if (pBuffer == NULL) { status = ippStsMemAllocErr; check_sts(status); } status = ippiFilterGaussianInit(roiSize, kernelSize, sigma, ippBorderType, ippDataType, numChannels, pSpec, pBuffer); check_sts(status); status = ippiFilterGaussianBorder(ippDataType, pSrc, srcStep, pDst, dstStep, roiSize, numChannels, ippBorderValue, pSpec, pBuffer); EXIT_FUNC ippsFree(pBuffer); ippsFree(pSpec); return status; } //////////////////////////////////////////////////////////////////////////////////////// // // own_FilterGaussian // // Median filter // // own_FilterGaussian uses functions on the backend for // implementing median filtering of image as is in scikit-image. // //////////////////////////////////////////////////////////////////////////////////////// IppStatus own_FilterMedian( IppDataType ippDataType, void * pSrc, void * pDst, int img_width, int img_height, int numChannels, int mask_width, int mask_height, IppiBorderType ippBorderType, float ippBorderValue) { IppStatus status = ippStsNoErr; Ipp8u * pBuffer = NULL; // Pointer to the work buffer int bufferSize; int sizeof_src; status = get_sizeof(ippDataType, &sizeof_src); check_sts(status); int srcStep = numChannels * img_width * sizeof_src; // Steps, in bytes, through int dstStep = srcStep; // thesource/destination //images IppiSize dstRoiSize = { img_width, img_height }; // Size of source and // destination ROI in pixels IppiSize maskSize = { mask_width, mask_height }; // Size of source and // destination ROI in pixels status = ippiFilterMedianBorderGetBufferSize(dstRoiSize, maskSize, ippDataType, numChannels, &bufferSize); check_sts(status); pBuffer = ippsMalloc_8u(bufferSize); if (pBuffer == NULL) { status = ippStsMemAllocErr; check_sts(status); } status = ippiFilterMedianBorder(ippDataType, pSrc, srcStep, pDst, dstStep, dstRoiSize, numChannels, maskSize, ippBorderType, ippBorderValue, pBuffer); check_sts(status); EXIT_FUNC ippsFree(pBuffer); return status; } //////////////////////////////////////////////////////////////////////////////////////// // // own_FilterLaplace // // 0 -1 0 // Laplace (3x3) -1 4 -1 // 0 -1 0 // Note: own_FilterLaplace uses own_FilterBorder on the backend for implementing // laplace filtering as is in scikit-image. // This func doesn't use ippiFilterLaplaceBorder, because of different laplace // kernel coeffs. // //////////////////////////////////////////////////////////////////////////////////////// IppStatus own_FilterLaplace( IppDataType ippDataType, void * pSrc, void * pDst, int img_width, int img_height, int numChannels, IppiBorderType ippBorderType, float ippBorderValue) { IppStatus status = ippStsNoErr; int kernel_width = 3; int kernel_height = 3; Ipp32f own_kernel_laplace[] = own_Laplace_KERNEL_3x3; IppDataType ippKernelDataType = ipp32f; IppRoundMode roundMode = ippRndNear; status = own_FilterBorder(ippDataType, ippKernelDataType, pSrc, pDst, own_kernel_laplace, img_width, img_height, kernel_width, kernel_height, numChannels, roundMode, ippBorderType, ippBorderValue); return status; } /////////////////////////////////////////////////////////////////////////////////////////// // // own_FilterEdge // 1 0 -1 // Prewitt_h (3x3) 1 0 -1 // 1 0 -1 // // 1 1 1 // Prewitt_v (3x3) 0 0 0 // -1 -1 -1 // // Sobel (3x3) TODO: description // // 1 0 -1 // Sobel_h (3x3) 2 0 -2 // 1 0 -1 // // 1 2 1 // Sobel_v (3x3) 0 0 0 // -1 -2 -1 // // Note: own_FilterEdge TODO: description // /////////////////////////////////////////////////////////////////////////////////////////// IppStatus own_FilterEdge( own_EdgeFilterKernel edgeKernel, IppDataType ippSrcDataType, IppDataType ippDstDataType, void * pSrc, void * pDst, int img_width, int img_height, int numChannels) { IppStatus status = ippStsNoErr; Ipp8u * pBuffer = NULL; // Pointer to the work buffer int bufferSize; IppiBorderType ippBorderType = ippBorderRepl; float ippBorderValue = 0.0; int srcStep; // Steps, in bytes, through the int dstStep; IppiSize roiSize = { img_width, img_height }; // Size of source and // destination ROI in pixels Ipp32f value; IppiMaskSize maskSize = ippMskSize3x3; IppNormType normType = ippNormL2; // As is in skimage.filters.prewitt if (!( numChannels == 1 && ippSrcDataType == ipp32f && ippDstDataType == ipp32f )) { status = ippStsErr; check_sts(status); } int sizeof_src; status = get_sizeof(ippSrcDataType, &sizeof_src); check_sts(status); int sizeof_dst; status = get_sizeof(ippDstDataType, &sizeof_dst); check_sts(status); // currently Intel(R) IPP supports only 1C images for filtering by prewitt kernels srcStep = numChannels * img_width * sizeof_src; dstStep = numChannels * img_width * sizeof_dst; #ifdef USE_OPENMP IppStatus * pStatus = NULL; int max_num_threads; int numThreads, slice, tail; IppiSize dstTileSize, dstLastTileSize; #ifdef MAX_NUM_THREADS max_num_threads = MAX_NUM_THREADS; #else max_num_threads = omp_get_max_threads(); if(roiSize.height / max_num_threads < 2) { max_num_threads = 1; } #endif #endif switch (edgeKernel) { case own_filterSobelVert: { status = ippiFilterSobelVertBorderGetBufferSize(roiSize, maskSize, ippSrcDataType, ippDstDataType, numChannels, &bufferSize); break; } case own_filterSobelHoriz: { status = ippiFilterSobelHorizBorderGetBufferSize(roiSize, maskSize, ippSrcDataType, ippDstDataType, numChannels, &bufferSize); break; } case own_filterSobel: { status = ippiFilterSobelGetBufferSize(roiSize, maskSize, normType, ippSrcDataType, ippDstDataType, numChannels, &bufferSize); break; } case own_filterPrewittVert: { status = ippiFilterPrewittVertBorderGetBufferSize(roiSize, maskSize, ippSrcDataType, ippDstDataType, numChannels, &bufferSize); break; } case own_filterPrewittHoriz: { status = ippiFilterPrewittHorizBorderGetBufferSize(roiSize, maskSize, ippSrcDataType, ippDstDataType, numChannels, &bufferSize); break; } default: { status = ippStsErr; } } check_sts(status); pBuffer = ippsMalloc_8u(bufferSize); if (pBuffer == NULL) { check_sts(status = ippStsMemAllocErr); }; switch (edgeKernel) { case own_filterSobelVert: { status = ippiFilterSobelVertBorder(ippSrcDataType, ippDstDataType, pSrc, srcStep, pDst, dstStep, roiSize, numChannels, maskSize, ippBorderType, ippBorderValue, pBuffer); break; } case own_filterSobelHoriz: { status = ippiFilterSobelHorizBorder(ippSrcDataType, ippDstDataType, pSrc, srcStep, pDst, dstStep, roiSize, numChannels, maskSize, ippBorderType, ippBorderValue, pBuffer); break; } case own_filterSobel: { status = ippiFilterSobel(ippSrcDataType, ippDstDataType, pSrc, srcStep, pDst, dstStep, roiSize, numChannels, maskSize, normType, ippBorderType, ippBorderValue, pBuffer); break; } case own_filterPrewittVert: { status = ippiFilterPrewittVertBorder(ippSrcDataType, ippDstDataType, pSrc, srcStep, pDst, dstStep, roiSize, numChannels, maskSize, ippBorderType, ippBorderValue, pBuffer); break; } case own_filterPrewittHoriz: { status = ippiFilterPrewittHorizBorder(ippSrcDataType, ippDstDataType, pSrc, srcStep, pDst, dstStep, roiSize, numChannels, maskSize, ippBorderType, ippBorderValue, pBuffer); break; } default: { status = ippStsErr; } } check_sts(status); // suppose that processing only ipp32f switch (edgeKernel) { case own_filterSobelVert: { // NOTE: // scikit-image's Sobel filter is a wrapper on scipy.ndimage's // `convolve` func. `convolve` uses `reflect` border mode. // `reflect` border mode is equivalent of Intel IPP ippBorderMirrorR border type // ippiFilterSobelVertBorder_<mode> doesn't supports this border type value = (Ipp32f)(-4.0); break; } case own_filterSobelHoriz: { // NOTE: // scikit-image's Sobel filter is a wrapper on scipy.ndimage's // `convolve` func. `convolve` uses `reflect` border mode. // `reflect` border mode is equivalent of Intel IPP ippBorderMirrorR border type // ippiFilterSobelHorizBorder_<mode> doesn't supports this border type value = (Ipp32f)4.0; break; } case own_filterSobel: { // NOTE: // scikit-image's Sobel filter is a wrapper on scipy.ndimage's // `convolve` func. `convolve` uses `reflect` border mode. // `reflect` border mode is equivalent of Intel IPP ippBorderMirrorR border type // ippiFilterSobelBorder_<mode> doesn't supports this border type value = (Ipp32f)(4.0 * (Ipp32f)IPP_SQRT2); break; } case own_filterPrewittVert: { // NOTE: // scikit-image's prewitt filter is a wrapper on scipy.ndimage's // `convolve` func. `convolve` uses `reflect` border mode. // `reflect` border mode is equivalent of Intel IPP ippBorderMirrorR border type // ippiFilterPrewittVertBorder_<mode> doesn't supports this border type value = (Ipp32f)-3.0; break; } case own_filterPrewittHoriz: { // NOTE: // scikit-image's prewitt filter is a wrapper on scipy.ndimage's // `convolve` func. `convolve` uses `reflect` border mode. // `reflect` border mode is equivalent of Intel IPP ippBorderMirrorR border type // ippiFilterPrewittHorizBorder_<mode> doesn't supports this border type value = (Ipp32f)3.0; break; } default: { status = ippStsErr; } } #ifdef USE_OPENMP if (max_num_threads != 1) { // Parallelized only by Y-direction here #pragma omp parallel num_threads(max_num_threads) { #pragma omp master { numThreads = omp_get_num_threads(); pStatus = (IppStatus*)ippsMalloc_8u(sizeof(IppStatus) * numThreads); if (pStatus == NULL) { status = ippStsMemAllocErr; } if(status == ippStsNoErr) { for (int i = 0; i < numThreads; ++i) pStatus[i] = ippStsNoErr; slice = roiSize.height / numThreads; tail = roiSize.height % numThreads; dstTileSize.width = roiSize.width; dstTileSize.height = slice; dstLastTileSize.width = roiSize.width; dstLastTileSize.height = slice + tail; } } #pragma omp barrier { if (status == ippStsNoErr) { Ipp32u i; void * pDstT = NULL; i = omp_get_thread_num(); IppiPoint dstOffset = { 0, 0 }; IppiSize dstSizeT = dstTileSize; dstSizeT.height = slice; dstOffset.y += i * slice; if (i == numThreads - 1) dstSizeT = dstLastTileSize; pDstT = (void*)((Ipp8u*)pDst + dstOffset.y * (Ipp32s)dstStep); pStatus[i] = ippiDivC_32f_C1IR(value, pDstT, dstStep, dstSizeT); } } } check_sts(status); // Checking status for slices and tile for (Ipp32u i = 0; i < numThreads; ++i) { status = pStatus[i]; check_sts(status); } } else { #endif status = ippiDivC_32f_C1IR(value, pDst, dstStep, roiSize); check_sts(status); #ifdef USE_OPENMP } #endif EXIT_FUNC #ifdef USE_OPENMP ippsFree(pStatus); #endif ippsFree(pBuffer); return status; } /////////////////////////////////////////////////////////////////////////////////////////// // // own_FilterPrewitt // Prewitt (3x3) // computes the square root of the sum of squares of the horizontal // and vertical Prewitt transforms. // // sqrt(A**2 + B**2)/sqrt(2) // // Note: currently supporeted only Ipp32f input/output. // /////////////////////////////////////////////////////////////////////////////////////////// IppStatus own_FilterPrewitt( own_EdgeFilterKernel edgeKernel, IppDataType ippSrcDataType, IppDataType ippDstDataType, void * pSrc, void * pDst, int img_width, int img_height, int numChannels) { // computes the square root of the sum of squares of the horizontal // and vertical Prewitt transforms. // sqrt(A**2 + B**2)/sqrt(2) IppStatus status = ippStsNoErr; Ipp32f * pAsrcDst = NULL; // Pointer to sobel_h result Ipp32f * pBsrcDst = NULL; // Pointer to sobel_v result IppiSize roiSize = { img_width, img_height }; // Size of source-destination // ROI in pixels // currently supporeted only Ipp32f input/output if (!(ippSrcDataType == ipp32f && ippSrcDataType == ipp32f && numChannels == 1 && edgeKernel == own_filterPrewitt)) { status = ippStsErr; check_sts(status); } int sizeofIppDataType = sizeof(Ipp32f); pAsrcDst = (void *)ippsMalloc_8u((img_width * sizeofIppDataType * numChannels) * img_height); if (pAsrcDst == NULL) { status = ippStsMemAllocErr; check_sts(status); }; status = own_FilterEdge(own_filterSobelHoriz, ippSrcDataType, ippDstDataType, pSrc, pAsrcDst, img_width, img_height, numChannels); check_sts(status); pBsrcDst = (void *)ippsMalloc_8u((img_width * sizeofIppDataType * numChannels) * img_height); if (pBsrcDst == NULL) { status = ippStsMemAllocErr; check_sts(status); }; status = own_FilterEdge(own_filterSobelVert, ippSrcDataType, ippDstDataType, pSrc, pBsrcDst, img_width, img_height, numChannels); check_sts(status); int srcDstStep = sizeofIppDataType * img_width * numChannels; status = ippiSqr_32f_C1IR(pAsrcDst, srcDstStep, roiSize); check_sts(status); status = ippiSqr_32f_C1IR(pBsrcDst, srcDstStep, roiSize); check_sts(status); status = ippiAdd_32f_C1R(pAsrcDst, srcDstStep, pBsrcDst, srcDstStep, pDst, srcDstStep, roiSize); check_sts(status); status = ippiSqrt_32f_C1IR(pDst, srcDstStep, roiSize); check_sts(status); Ipp32f sqrt2 = (Ipp32f)IPP_SQRT2; status = ippiDivC_32f_C1IR(sqrt2, pDst, srcDstStep, roiSize); check_sts(status); EXIT_FUNC ippsFree(pAsrcDst); ippsFree(pBsrcDst); return status; } IppStatus own_mask_filter_result( IppDataType ippDstDataType, void * pDst, int img_width, int img_height, int numChannels) { IppStatus status = ippStsNoErr; // checking supported dtypes if (!(ippDstDataType==ipp8u || ippDstDataType==ipp16u || ippDstDataType==ipp16s || ippDstDataType==ipp32s || ippDstDataType==ipp32f)) { status = ippStsDataTypeErr; check_sts(status); } IppStatus pStatus[4]; int sizeof_dst; status = get_sizeof(ippDstDataType, &sizeof_dst); check_sts(status); int dstStep = numChannels * img_width * sizeof_dst; double value = 0; void * pTop = (void* )pDst; void * pBottom = (void* )((Ipp8u* )pDst + dstStep * (img_height - 1)); void * pLeft = (void* )((Ipp8u* )pDst + dstStep); void * pRight = (void* )((Ipp8u* )pLeft + numChannels * (img_width - 1) * sizeof_dst); IppiSize horizRoiSize = {img_width, 1}; IppiSize verRoiSize = {1, (img_height - 1)}; #ifdef USE_OPENMP int max_num_threads; #ifdef MAX_NUM_THREADS max_num_threads = MAX_NUM_THREADS; #else max_num_threads = omp_get_max_threads(); #endif if (max_num_threads >= 4) { #pragma omp parallel sections { #pragma omp section { pStatus[0] = ippiSet_C1R(ippDstDataType, value, pTop, dstStep, horizRoiSize); } #pragma omp section { pStatus[1] = ippiSet_C1R(ippDstDataType, value, pBottom, dstStep, horizRoiSize); } #pragma omp section { pStatus[2] = ippiSet_C1R(ippDstDataType, value, pLeft, dstStep, verRoiSize); } #pragma omp section { pStatus[3] = ippiSet_C1R(ippDstDataType, value, pRight, dstStep, verRoiSize); } } } else { #endif status = ippiSet_C1R(ippDstDataType, value, pTop, dstStep, horizRoiSize); check_sts(status); status = ippiSet_C1R(ippDstDataType, value, pBottom, dstStep, horizRoiSize); check_sts(status); status = ippiSet_C1R(ippDstDataType, value, pLeft, dstStep, verRoiSize); check_sts(status); status = ippiSet_C1R(ippDstDataType, value, pRight, dstStep, verRoiSize); check_sts(status); #ifdef USE_OPENMP } #endif EXIT_FUNC return status; }
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] = 16; tile_size[1] = 16; tile_size[2] = 8; tile_size[3] = 256; 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,2);t1++) { lbp=max(ceild(t1,2),ceild(4*t1-Nt+2,4)); ubp=min(floord(4*Nt+Nz-9,16),floord(8*t1+Nz+2,16)); #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(16*t2-Nz+5,8)),t1),2*t1-2*t2+1);t3<=min(min(min(floord(4*Nt+Ny-9,8),floord(8*t1+Ny+7,8)),floord(16*t2+Ny+3,8)),floord(16*t1-16*t2+Nz+Ny+5,8));t3++) { for (t4=max(max(max(0,ceild(t1-31,32)),ceild(16*t2-Nz-243,256)),ceild(8*t3-Ny-243,256));t4<=min(min(min(min(floord(4*Nt+Nx-9,256),floord(8*t1+Nx+7,256)),floord(16*t2+Nx+3,256)),floord(8*t3+Nx-5,256)),floord(16*t1-16*t2+Nz+Nx+5,256));t4++) { for (t5=max(max(max(max(max(0,ceild(16*t2-Nz+5,4)),ceild(8*t3-Ny+5,4)),ceild(256*t4-Nx+5,4)),2*t1),4*t1-4*t2+1);t5<=min(min(min(min(min(floord(16*t1-16*t2+Nz+10,4),2*t3),Nt-1),2*t1+3),4*t2+2),64*t4+62);t5++) { for (t6=max(max(16*t2,4*t5+4),-16*t1+16*t2+8*t5-15);t6<=min(min(16*t2+15,-16*t1+16*t2+8*t5),4*t5+Nz-5);t6++) { for (t7=max(8*t3,4*t5+4);t7<=min(8*t3+7,4*t5+Ny-5);t7++) { lbv=max(256*t4,4*t5+4); ubv=min(256*t4+255,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; }
residualbased_elimination_builder_and_solver.h
// | / | // ' / __| _` | __| _ \ __| // . \ | ( | | ( |\__ ` // _|\_\_| \__,_|\__|\___/ ____/ // Multi-Physics // // License: BSD License // Kratos default license: kratos/license.txt // // Main authors: Riccardo Rossi // // #if !defined(KRATOS_RESIDUAL_BASED_ELIMINATION_BUILDER_AND_SOLVER ) #define KRATOS_RESIDUAL_BASED_ELIMINATION_BUILDER_AND_SOLVER /* System includes */ #include <set> #include <unordered_set> #ifdef _OPENMP #include <omp.h> #endif /* External includes */ /* Project includes */ #include "utilities/timer.h" #include "includes/define.h" #include "includes/key_hash.h" #include "solving_strategies/builder_and_solvers/builder_and_solver.h" #include "includes/model_part.h" namespace Kratos { ///@name Kratos Globals ///@{ ///@} ///@name Type Definitions ///@{ ///@} ///@name Enum's ///@{ ///@} ///@name Functions ///@{ ///@} ///@name Kratos Classes ///@{ /** * @class ResidualBasedEliminationBuilderAndSolver * @ingroup KratosCore * @brief Current class provides an implementation for standard elimination builder and solving operations. * @details The RHS is constituted by the unbalanced loads (residual) * Degrees of freedom are reordered putting the restrained degrees of freedom at * the end of the system ordered in reverse order with respect to the DofSet. * Imposition of the dirichlet conditions is naturally dealt with as the residual already contains this information. * Calculation of the reactions involves a cost very similiar to the calculation of the total residual * @author Riccardo Rossi */ template<class TSparseSpace, class TDenseSpace, //= DenseSpace<double>, class TLinearSolver //= LinearSolver<TSparseSpace,TDenseSpace> > class ResidualBasedEliminationBuilderAndSolver : public BuilderAndSolver< TSparseSpace, TDenseSpace, TLinearSolver > { public: ///@name Type Definitions ///@{ /// Pointer definition of ResidualBasedEliminationBuilderAndSolverWithConstraints KRATOS_CLASS_POINTER_DEFINITION(ResidualBasedEliminationBuilderAndSolver); /// Definition of the base class typedef BuilderAndSolver<TSparseSpace, TDenseSpace, TLinearSolver> BaseType; /// Definition of the classes from the base class typedef typename BaseType::SizeType SizeType; typedef typename BaseType::IndexType IndexType; typedef typename BaseType::TSchemeType TSchemeType; typedef typename BaseType::TDataType TDataType; typedef typename BaseType::DofsArrayType DofsArrayType; typedef typename BaseType::TSystemMatrixType TSystemMatrixType; typedef typename BaseType::TSystemVectorType TSystemVectorType; typedef typename BaseType::LocalSystemVectorType LocalSystemVectorType; typedef typename BaseType::LocalSystemMatrixType LocalSystemMatrixType; typedef typename BaseType::TSystemMatrixPointerType TSystemMatrixPointerType; typedef typename BaseType::TSystemVectorPointerType TSystemVectorPointerType; /// Definition of the equation id vector typedef Element::EquationIdVectorType EquationIdVectorType; typedef Element::DofsVectorType DofsVectorType; /// Node definition typedef Node<3> NodeType; /// Containers definition typedef typename BaseType::NodesArrayType NodesArrayType; typedef typename BaseType::ElementsArrayType ElementsArrayType; typedef typename BaseType::ConditionsArrayType ConditionsArrayType; typedef typename BaseType::ElementsContainerType ElementsContainerType; ///@} ///@name Life Cycle ///@{ /** * @brief Default constructor. (with parameters) */ explicit ResidualBasedEliminationBuilderAndSolver( typename TLinearSolver::Pointer pNewLinearSystemSolver, Parameters ThisParameters ) : BaseType(pNewLinearSystemSolver) { // Validate default parameters Parameters default_parameters = Parameters(R"( { "name" : "ResidualBasedEliminationBuilderAndSolver" })" ); ThisParameters.ValidateAndAssignDefaults(default_parameters); } /** * @brief Constructor. */ explicit ResidualBasedEliminationBuilderAndSolver( typename TLinearSolver::Pointer pNewLinearSystemSolver) : BaseType(pNewLinearSystemSolver) { } /** Destructor. */ ~ResidualBasedEliminationBuilderAndSolver() override { } ///@} ///@name Operators ///@{ ///@} ///@name Operations ///@{ /** * @brief Function to perform the build of the RHS. The vector could be sized as the total number * of dofs or as the number of unrestrained ones * @param pScheme The integration scheme considered * @param rModelPart The model part of the problem to solve * @param rA The LHS matrix * @param rb The RHS vector */ void Build( typename TSchemeType::Pointer pScheme, ModelPart& rModelPart, TSystemMatrixType& rA, TSystemVectorType& rb ) override { KRATOS_TRY KRATOS_ERROR_IF(!pScheme) << "No scheme provided!" << std::endl; //getting the elements from the model const int nelements = static_cast<int>(rModelPart.Elements().size()); //getting the array of the conditions const int nconditions = static_cast<int>(rModelPart.Conditions().size()); const ProcessInfo& CurrentProcessInfo = rModelPart.GetProcessInfo(); ModelPart::ElementsContainerType::iterator el_begin = rModelPart.ElementsBegin(); ModelPart::ConditionsContainerType::iterator cond_begin = rModelPart.ConditionsBegin(); //contributions to the system LocalSystemMatrixType LHS_Contribution = LocalSystemMatrixType(0, 0); LocalSystemVectorType RHS_Contribution = LocalSystemVectorType(0); //vector containing the localization in the system of the different //terms Element::EquationIdVectorType EquationId; const double start_build = OpenMPUtils::GetCurrentTime(); // assemble all elements #pragma omp parallel firstprivate(nelements, nconditions, LHS_Contribution, RHS_Contribution, EquationId ) { #pragma omp for schedule(guided, 512) nowait for (int k = 0; k < nelements; k++) { ModelPart::ElementsContainerType::iterator it = el_begin + k; //detect if the element is active or not. If the user did not make any choice the element //is active by default bool element_is_active = true; if ((it)->IsDefined(ACTIVE)) element_is_active = (it)->Is(ACTIVE); if (element_is_active) { //calculate elemental contribution pScheme->CalculateSystemContributions(*it, LHS_Contribution, RHS_Contribution, EquationId, CurrentProcessInfo); //assemble the elemental contribution #ifdef USE_LOCKS_IN_ASSEMBLY Assemble(rA, rb, LHS_Contribution, RHS_Contribution, EquationId, mLockArray); #else Assemble(rA, rb, LHS_Contribution, RHS_Contribution, EquationId); #endif // clean local elemental memory pScheme->CleanMemory(*it); } } #pragma omp for schedule(guided, 512) for (int k = 0; k < nconditions; k++) { ModelPart::ConditionsContainerType::iterator it = cond_begin + k; //detect if the element is active or not. If the user did not make any choice the element //is active by default bool condition_is_active = true; if ((it)->IsDefined(ACTIVE)) condition_is_active = (it)->Is(ACTIVE); if (condition_is_active) { //calculate elemental contribution pScheme->CalculateSystemContributions(*it, LHS_Contribution, RHS_Contribution, EquationId, CurrentProcessInfo); #ifdef USE_LOCKS_IN_ASSEMBLY Assemble(rA, rb, LHS_Contribution, RHS_Contribution, EquationId, mLockArray); #else Assemble(rA, rb, LHS_Contribution, RHS_Contribution, EquationId); #endif // clean local elemental memory pScheme->CleanMemory(*it); } } } const double stop_build = OpenMPUtils::GetCurrentTime(); KRATOS_INFO_IF("ResidualBasedEliminationBuilderAndSolver", (this->GetEchoLevel() >=1 && rModelPart.GetCommunicator().MyPID() == 0)) << "System build time: " << stop_build - start_build << std::endl; KRATOS_INFO_IF("ResidualBasedEliminationBuilderAndSolver", this->GetEchoLevel() > 2 && rModelPart.GetCommunicator().MyPID() == 0) << "Finished building" << std::endl; KRATOS_CATCH("") } /** * @brief Function to perform the building of the LHS * @details Depending on the implementation choosen the size of the matrix could be equal to the total number of Dofs or to the number of unrestrained dofs * @param pScheme The integration scheme considered * @param rModelPart The model part of the problem to solve * @param rA The LHS matrix */ void BuildLHS( typename TSchemeType::Pointer pScheme, ModelPart& rModelPart, TSystemMatrixType& rA ) override { KRATOS_TRY //getting the elements from the model ElementsArrayType& rElements = rModelPart.Elements(); //getting the array of the conditions ConditionsArrayType& rConditions = rModelPart.Conditions(); //resetting to zero the vector of reactions TSparseSpace::SetToZero(*(BaseType::mpReactionsVector)); //contributions to the system LocalSystemMatrixType LHS_Contribution = LocalSystemMatrixType(0, 0); //vector containing the localization in the system of the different //terms Element::EquationIdVectorType EquationId; const ProcessInfo& CurrentProcessInfo = rModelPart.GetProcessInfo(); // assemble all elements for (typename ElementsArrayType::ptr_iterator it = rElements.ptr_begin(); it != rElements.ptr_end(); ++it) { //calculate elemental contribution pScheme->CalculateLHSContribution(**it, LHS_Contribution, EquationId, CurrentProcessInfo); //assemble the elemental contribution AssembleLHS(rA, LHS_Contribution, EquationId); // clean local elemental memory pScheme->CleanMemory(**it); } LHS_Contribution.resize(0, 0, false); // assemble all conditions for (typename ConditionsArrayType::ptr_iterator it = rConditions.ptr_begin(); it != rConditions.ptr_end(); ++it) { //calculate elemental contribution pScheme->CalculateLHSContribution(**it, LHS_Contribution, EquationId, CurrentProcessInfo); //assemble the elemental contribution AssembleLHS(rA, LHS_Contribution, EquationId); } KRATOS_CATCH("") } /** * @brief Build a rectangular matrix of size n*N where "n" is the number of unrestrained degrees of freedom * and "N" is the total number of degrees of freedom involved. * @details This matrix is obtained by building the total matrix without the lines corresponding to the fixed * degrees of freedom (but keeping the columns!!) * @param pScheme The integration scheme considered * @param rModelPart The model part of the problem to solve * @param A The LHS matrix */ void BuildLHS_CompleteOnFreeRows( typename TSchemeType::Pointer pScheme, ModelPart& rModelPart, TSystemMatrixType& rA ) override { KRATOS_TRY //getting the elements from the model ElementsArrayType& rElements = rModelPart.Elements(); //getting the array of the conditions ConditionsArrayType& rConditions = rModelPart.Conditions(); const ProcessInfo& CurrentProcessInfo = rModelPart.GetProcessInfo(); //resetting to zero the vector of reactions TSparseSpace::SetToZero(*(BaseType::mpReactionsVector)); //contributions to the system LocalSystemMatrixType LHS_Contribution = LocalSystemMatrixType(0, 0); //vector containing the localization in the system of the different //terms Element::EquationIdVectorType EquationId; // assemble all elements for (typename ElementsArrayType::ptr_iterator it = rElements.ptr_begin(); it != rElements.ptr_end(); ++it) { //calculate elemental contribution pScheme->CalculateLHSContribution(**it, LHS_Contribution, EquationId, CurrentProcessInfo); //assemble the elemental contribution AssembleLHSCompleteOnFreeRows(rA, LHS_Contribution, EquationId); // clean local elemental memory pScheme->CleanMemory(**it); } LHS_Contribution.resize(0, 0, false); // assemble all conditions for (typename ConditionsArrayType::ptr_iterator it = rConditions.ptr_begin(); it != rConditions.ptr_end(); ++it) { //calculate elemental contribution pScheme->CalculateLHSContribution(**it, LHS_Contribution, EquationId, CurrentProcessInfo); //assemble the elemental contribution AssembleLHSCompleteOnFreeRows(rA, LHS_Contribution, EquationId); } KRATOS_CATCH("") } /** * @brief This is a call to the linear system solver * @param rA The LHS matrix * @param rDx The Unknowns vector * @param rb The RHS vector */ void SystemSolve( TSystemMatrixType& rA, TSystemVectorType& rDx, TSystemVectorType& rb ) override { KRATOS_TRY double norm_b; if (TSparseSpace::Size(rb) != 0) { norm_b = TSparseSpace::TwoNorm(rb); } else { norm_b = 0.0; } if (norm_b != 0.0) { // Do solve BaseType::mpLinearSystemSolver->Solve(rA, rDx, rb); } else TSparseSpace::SetToZero(rDx); // Prints informations about the current time KRATOS_INFO_IF("ResidualBasedEliminationBuilderAndSolver", this->GetEchoLevel() > 1) << *(BaseType::mpLinearSystemSolver) << std::endl; KRATOS_CATCH("") } /** *@brief This is a call to the linear system solver (taking into account some physical particularities of the problem) * @param rA The LHS matrix * @param rDx The Unknowns vector * @param rb The RHS vector * @param rModelPart The model part of the problem to solve */ void SystemSolveWithPhysics( TSystemMatrixType& rA, TSystemVectorType& rDx, TSystemVectorType& rb, ModelPart& rModelPart ) { KRATOS_TRY double norm_b; if (TSparseSpace::Size(rb) != 0) { norm_b = TSparseSpace::TwoNorm(rb); } else { norm_b = 0.0; } if (norm_b != 0.0) { // Provide physical data as needed if(BaseType::mpLinearSystemSolver->AdditionalPhysicalDataIsNeeded() ) BaseType::mpLinearSystemSolver->ProvideAdditionalData(rA, rDx, rb, BaseType::mDofSet, rModelPart); // Do solve BaseType::mpLinearSystemSolver->Solve(rA, rDx, rb); } else { TSparseSpace::SetToZero(rDx); KRATOS_WARNING_IF("ResidualBasedEliminationBuilderAndSolver", rModelPart.GetCommunicator().MyPID() == 0) << "ATTENTION! setting the RHS to zero!" << std::endl; } // Prints informations about the current time KRATOS_INFO_IF("ResidualBasedEliminationBuilderAndSolver", this->GetEchoLevel() > 1 && rModelPart.GetCommunicator().MyPID() == 0) << *(BaseType::mpLinearSystemSolver) << std::endl; KRATOS_CATCH("") } /** * @brief Function to perform the building and solving phase at the same time. * @details It is ideally the fastest and safer function to use when it is possible to solve * just after building * @param pScheme The integration scheme considered * @param rModelPart The model part of the problem to solve * @param rA The LHS matrix * @param rDx The Unknowns vector * @param rb The RHS vector */ void BuildAndSolve( typename TSchemeType::Pointer pScheme, ModelPart& rModelPart, TSystemMatrixType& rA, TSystemVectorType& rDx, TSystemVectorType& rb ) override { KRATOS_TRY Timer::Start("Build"); Build(pScheme, rModelPart, rA, rb); Timer::Stop("Build"); // Does nothing...dirichlet conditions are naturally dealt with in defining the residual ApplyDirichletConditions(pScheme, rModelPart, rA, rDx, rb); KRATOS_INFO_IF("ResidualBasedEliminationBuilderAndSolver", ( this->GetEchoLevel() == 3)) << "Before the solution of the system" << "\nSystem Matrix = " << rA << "\nUnknowns vector = " << rDx << "\nRHS vector = " << rb << std::endl; const double start_solve = OpenMPUtils::GetCurrentTime(); Timer::Start("Solve"); SystemSolveWithPhysics(rA, rDx, rb, rModelPart); Timer::Stop("Solve"); const double stop_solve = OpenMPUtils::GetCurrentTime(); KRATOS_INFO_IF("ResidualBasedEliminationBuilderAndSolver", (this->GetEchoLevel() >=1 && rModelPart.GetCommunicator().MyPID() == 0)) << "System solve time: " << stop_solve - start_solve << std::endl; KRATOS_INFO_IF("ResidualBasedEliminationBuilderAndSolver", ( this->GetEchoLevel() == 3)) << "After the solution of the system" << "\nSystem Matrix = " << rA << "\nUnknowns vector = " << rDx << "\nRHS vector = " << rb << std::endl; KRATOS_CATCH("") } /** * @brief Corresponds to the previews, but the System's matrix is considered already built and only the RHS is built again * @param pScheme The integration scheme considered * @param rModelPart The model part of the problem to solve * @param rA The LHS matrix * @param rDx The Unknowns vector * @param rb The RHS vector */ void BuildRHSAndSolve( typename TSchemeType::Pointer pScheme, ModelPart& rModelPart, TSystemMatrixType& rA, TSystemVectorType& rDx, TSystemVectorType& rb ) override { KRATOS_TRY BuildRHS(pScheme, rModelPart, rb); SystemSolve(rA, rDx, rb); KRATOS_CATCH("") } /** * @brief Function to perform the build of the RHS. * @details The vector could be sized as the total number of dofs or as the number of unrestrained ones * @param pScheme The integration scheme considered * @param rModelPart The model part of the problem to solve */ void BuildRHS( typename TSchemeType::Pointer pScheme, ModelPart& rModelPart, TSystemVectorType& rb ) override { KRATOS_TRY //resetting to zero the vector of reactions if(BaseType::mCalculateReactionsFlag) { TSparseSpace::SetToZero(*(BaseType::mpReactionsVector)); } //Getting the Elements ElementsArrayType& pElements = rModelPart.Elements(); //getting the array of the conditions ConditionsArrayType& pConditions = rModelPart.Conditions(); const ProcessInfo& CurrentProcessInfo = rModelPart.GetProcessInfo(); //contributions to the system LocalSystemVectorType RHS_Contribution = LocalSystemVectorType(0); //vector containing the localization in the system of the different terms Element::EquationIdVectorType EquationId; // assemble all elements #pragma omp parallel firstprivate( RHS_Contribution, EquationId) { const int nelements = static_cast<int>(pElements.size()); #pragma omp for schedule(guided, 512) nowait for (int i = 0; i<nelements; i++) { typename ElementsArrayType::iterator it = pElements.begin() + i; //detect if the element is active or not. If the user did not make any choice the element //is active by default bool element_is_active = true; if ((it)->IsDefined(ACTIVE)) element_is_active = (it)->Is(ACTIVE); if (element_is_active) { // Calculate elemental Right Hand Side Contribution pScheme->CalculateRHSContribution(*it, RHS_Contribution, EquationId, CurrentProcessInfo); // Assemble the elemental contribution AssembleRHS(rb, RHS_Contribution, EquationId); } } // assemble all conditions const int nconditions = static_cast<int>(pConditions.size()); #pragma omp for schedule(guided, 512) for (int i = 0; i<nconditions; i++) { auto it = pConditions.begin() + i; //detect if the element is active or not. If the user did not make any choice the element //is active by default bool condition_is_active = true; if ((it)->IsDefined(ACTIVE)) condition_is_active = (it)->Is(ACTIVE); if (condition_is_active) { //calculate elemental contribution pScheme->CalculateRHSContribution(*it, RHS_Contribution, EquationId, CurrentProcessInfo); //assemble the elemental contribution AssembleRHS(rb, RHS_Contribution, EquationId); } } } KRATOS_CATCH("") } /** * @brief Builds the list of the DofSets involved in the problem by "asking" to each element * and condition its Dofs. * @details The list of dofs is stores insde the BuilderAndSolver as it is closely connected to the * way the matrix and RHS are built * @param pScheme The integration scheme considered * @param rModelPart The model part of the problem to solve */ void SetUpDofSet( typename TSchemeType::Pointer pScheme, ModelPart& rModelPart ) override { KRATOS_TRY; KRATOS_INFO_IF("ResidualBasedEliminationBuilderAndSolver", this->GetEchoLevel() > 1 && rModelPart.GetCommunicator().MyPID() == 0) << "Setting up the dofs" << std::endl; //Gets the array of elements from the modeler ElementsArrayType& pElements = rModelPart.Elements(); const int nelements = static_cast<int>(pElements.size()); Element::DofsVectorType ElementalDofList; const ProcessInfo& CurrentProcessInfo = rModelPart.GetProcessInfo(); unsigned int nthreads = OpenMPUtils::GetNumThreads(); typedef std::unordered_set < NodeType::DofType::Pointer, DofPointerHasher> set_type; std::vector<set_type> dofs_aux_list(nthreads); // std::vector<allocator_type> allocators(nthreads); for (int i = 0; i < static_cast<int>(nthreads); i++) { // dofs_aux_list[i] = set_type( allocators[i]); dofs_aux_list[i].reserve(nelements); } #pragma omp parallel for firstprivate(nelements, ElementalDofList) for (int i = 0; i < static_cast<int>(nelements); i++) { typename ElementsArrayType::iterator it = pElements.begin() + i; const unsigned int this_thread_id = OpenMPUtils::ThisThread(); // gets list of Dof involved on every element pScheme->GetDofList(*it, ElementalDofList, CurrentProcessInfo); dofs_aux_list[this_thread_id].insert(ElementalDofList.begin(), ElementalDofList.end()); } ConditionsArrayType& pConditions = rModelPart.Conditions(); const int nconditions = static_cast<int>(pConditions.size()); #pragma omp parallel for firstprivate(nconditions, ElementalDofList) for (int i = 0; i < nconditions; i++) { typename ConditionsArrayType::iterator it = pConditions.begin() + i; const unsigned int this_thread_id = OpenMPUtils::ThisThread(); // gets list of Dof involved on every element pScheme->GetDofList(*it, ElementalDofList, CurrentProcessInfo); dofs_aux_list[this_thread_id].insert(ElementalDofList.begin(), ElementalDofList.end()); } //here we do a reduction in a tree so to have everything on thread 0 unsigned int old_max = nthreads; unsigned int new_max = ceil(0.5*static_cast<double>(old_max)); while (new_max >= 1 && new_max != old_max) { #pragma omp parallel for for (int i = 0; i < static_cast<int>(new_max); i++) { if (i + new_max < old_max) { dofs_aux_list[i].insert(dofs_aux_list[i + new_max].begin(), dofs_aux_list[i + new_max].end()); dofs_aux_list[i + new_max].clear(); } } old_max = new_max; new_max = ceil(0.5*static_cast<double>(old_max)); } DofsArrayType Doftemp; BaseType::mDofSet = DofsArrayType(); Doftemp.reserve(dofs_aux_list[0].size()); for (auto it = dofs_aux_list[0].begin(); it != dofs_aux_list[0].end(); it++) { Doftemp.push_back(*it); } Doftemp.Sort(); BaseType::mDofSet = Doftemp; // Throws an execption if there are no Degrees of freedom involved in the analysis KRATOS_ERROR_IF(BaseType::mDofSet.size() == 0) << "No degrees of freedom!" << std::endl; BaseType::mDofSetIsInitialized = true; KRATOS_INFO_IF("ResidualBasedEliminationBuilderAndSolver", this->GetEchoLevel() > 2 && rModelPart.GetCommunicator().MyPID() == 0) << "Finished setting up the dofs" << std::endl; #ifdef USE_LOCKS_IN_ASSEMBLY if (mLockArray.size() != 0) { for (int i = 0; i < static_cast<int>(mLockArray.size()); i++) omp_destroy_lock(&mLockArray[i]); } mLockArray.resize(BaseType::mDofSet.size()); for (int i = 0; i < static_cast<int>(mLockArray.size()); i++) omp_init_lock(&mLockArray[i]); #endif // If reactions are to be calculated, we check if all the dofs have reactions defined // This is tobe done only in debug mode #ifdef KRATOS_DEBUG if(BaseType::GetCalculateReactionsFlag()) { for(auto dof_iterator = BaseType::mDofSet.begin(); dof_iterator != BaseType::mDofSet.end(); ++dof_iterator) { KRATOS_ERROR_IF_NOT(dof_iterator->HasReaction()) << "Reaction variable not set for the following : " <<std::endl << "Node : "<<dof_iterator->Id()<< std::endl << "Dof : "<<(*dof_iterator)<<std::endl<<"Not possible to calculate reactions."<<std::endl; } } #endif KRATOS_CATCH(""); } /** * @brief Organises the dofset in order to speed up the building phase * @param rModelPart The model part of the problem to solve */ void SetUpSystem( ModelPart& rModelPart ) override { // Set equation id for degrees of freedom // the free degrees of freedom are positioned at the beginning of the system, // while the fixed one are at the end (in opposite order). // // that means that if the EquationId is greater than "mEquationSystemSize" // the pointed degree of freedom is restrained // int free_id = 0; int fix_id = BaseType::mDofSet.size(); for (typename DofsArrayType::iterator dof_iterator = BaseType::mDofSet.begin(); dof_iterator != BaseType::mDofSet.end(); ++dof_iterator) if (dof_iterator->IsFixed()) dof_iterator->SetEquationId(--fix_id); else dof_iterator->SetEquationId(free_id++); BaseType::mEquationSystemSize = fix_id; } /** * @brief This method resize and initializes the system of euqations * @param pA The pointer to the LHS matrix * @param pDx The pointer to the vector of Unknowns * @param pb The pointer to the RHS vector * @param rModelPart The model part to be computed */ void ResizeAndInitializeVectors( typename TSchemeType::Pointer pScheme, TSystemMatrixPointerType& pA, TSystemVectorPointerType& pDx, TSystemVectorPointerType& pb, ModelPart& rModelPart ) override { KRATOS_TRY if (pA == NULL) //if the pointer is not initialized initialize it to an empty matrix { TSystemMatrixPointerType pNewA = TSystemMatrixPointerType(new TSystemMatrixType(0, 0)); pA.swap(pNewA); } if (pDx == NULL) //if the pointer is not initialized initialize it to an empty matrix { TSystemVectorPointerType pNewDx = TSystemVectorPointerType(new TSystemVectorType(0)); pDx.swap(pNewDx); } if (pb == NULL) //if the pointer is not initialized initialize it to an empty matrix { TSystemVectorPointerType pNewb = TSystemVectorPointerType(new TSystemVectorType(0)); pb.swap(pNewb); } if (BaseType::mpReactionsVector == NULL) //if the pointer is not initialized initialize it to an empty matrix { TSystemVectorPointerType pNewReactionsVector = TSystemVectorPointerType(new TSystemVectorType(0)); BaseType::mpReactionsVector.swap(pNewReactionsVector); } TSystemMatrixType& rA = *pA; TSystemVectorType& rDx = *pDx; TSystemVectorType& rb = *pb; // Resizing the system vectors and matrix if (rA.size1() == 0 || BaseType::GetReshapeMatrixFlag()) { // If the matrix is not initialized rA.resize(BaseType::mEquationSystemSize, BaseType::mEquationSystemSize, false); ConstructMatrixStructure(pScheme, rA, rModelPart); } else { if (rA.size1() != BaseType::mEquationSystemSize || rA.size2() != BaseType::mEquationSystemSize) { KRATOS_ERROR <<"The equation system size has changed during the simulation. This is not permited."<<std::endl; rA.resize(BaseType::mEquationSystemSize, BaseType::mEquationSystemSize, true); ConstructMatrixStructure(pScheme, rA, rModelPart); } } if (rDx.size() != BaseType::mEquationSystemSize) { rDx.resize(BaseType::mEquationSystemSize, false); } TSparseSpace::SetToZero(rDx); if (rb.size() != BaseType::mEquationSystemSize) { rb.resize(BaseType::mEquationSystemSize, false); } TSparseSpace::SetToZero(rb); //if needed resize the vector for the calculation of reactions if (BaseType::mCalculateReactionsFlag == true) { const std::size_t reactions_vector_size = BaseType::mDofSet.size() - BaseType::mEquationSystemSize; if (BaseType::mpReactionsVector->size() != reactions_vector_size) BaseType::mpReactionsVector->resize(reactions_vector_size, false); } KRATOS_CATCH("") } /** * @brief This method computes the reactions * @param pScheme The integration scheme considered * @param rModelPart The model part considered * @param rA The LHS of the system * @param rDx The vector of Unknowns * @param rb The RHS vector */ void CalculateReactions( typename TSchemeType::Pointer pScheme, ModelPart& rModelPart, TSystemMatrixType& rA, TSystemVectorType& rDx, TSystemVectorType& rb ) override { //refresh RHS to have the correct reactions BuildRHS(pScheme, rModelPart, rb); // Updating variables std::size_t i; TSystemVectorType& r_reactions_vector = *BaseType::mpReactionsVector; for (auto it2 = BaseType::mDofSet.ptr_begin(); it2 != BaseType::mDofSet.ptr_end(); ++it2) { i = (*it2)->EquationId(); if (i >= BaseType::mEquationSystemSize) { i -= BaseType::mEquationSystemSize; (*it2)->GetSolutionStepReactionValue() = -r_reactions_vector[i]; } } } /** * @brief Applies the dirichlet conditions. This operation may be very heavy or completely * unexpensive depending on the implementation choosen and on how the System Matrix is built. * @details For explanation of how it works for a particular implementation the user * should refer to the particular Builder And Solver choosen * @param pScheme The integration scheme considered * @param rModelPart The model part of the problem to solve * @param rA The LHS matrix * @param rDx The Unknowns vector * @param rb The RHS vector */ void ApplyDirichletConditions( typename TSchemeType::Pointer pScheme, ModelPart& rModelPart, TSystemMatrixType& rA, TSystemVectorType& rDx, TSystemVectorType& rb ) override { } /** * @brief This function is intended to be called at the end of the solution step to clean up memory storage not needed */ void Clear() override { this->mDofSet = DofsArrayType(); this->mpReactionsVector.reset(); // this->mReactionsVector = TSystemVectorType(); this->mpLinearSystemSolver->Clear(); KRATOS_INFO_IF("ResidualBasedEliminationBuilderAndSolver", this->GetEchoLevel() > 1) << "Clear Function called" << std::endl; } /** * @brief This function is designed to be called once to perform all the checks needed * on the input provided. Checks can be "expensive" as the function is designed * to catch user's errors. * @param rModelPart The model part of the problem to solve * @return 0 all ok */ int Check(ModelPart& rModelPart) override { KRATOS_TRY return 0; KRATOS_CATCH(""); } ///@} ///@name Access ///@{ ///@} ///@name Inquiry ///@{ ///@} ///@name Input and output ///@{ /// Turn back information as a string. std::string Info() const override { return "ResidualBasedEliminationBuilderAndSolver"; } /// Print information about this object. void PrintInfo(std::ostream& rOStream) const override { rOStream << Info(); } /// Print object's data. void PrintData(std::ostream& rOStream) const override { rOStream << Info(); } ///@} ///@name Friends ///@{ ///@} protected: ///@name Protected static Member Variables ///@{ ///@} ///@name Protected member Variables ///@{ #ifdef USE_LOCKS_IN_ASSEMBLY std::vector<omp_lock_t> mLockArray; #endif ///@} ///@name Protected Operators ///@{ ///@} ///@name Protected Operations ///@{ /** * @brief This method assembles the system * @param rA The LHS of the system * @param rb The RHS of the system * @param rLHSContribution The LHS local contribution * @param rRHSContribution The RHS local contribution * @param rEquationId The equation id * @param rLockArray The lock of the dof * @note The main difference respect the block builder and solver is the fact that the fixed DoFs are not considered on the assembling */ void Assemble( TSystemMatrixType& rA, TSystemVectorType& rb, const LocalSystemMatrixType& rLHSContribution, const LocalSystemVectorType& rRHSContribution, const Element::EquationIdVectorType& rEquationId #ifdef USE_LOCKS_IN_ASSEMBLY ,std::vector< omp_lock_t >& rLockArray #endif ) { unsigned int local_size = rLHSContribution.size1(); for (unsigned int i_local = 0; i_local < local_size; i_local++) { unsigned int i_global = rEquationId[i_local]; if (i_global < BaseType::mEquationSystemSize) { #ifdef USE_LOCKS_IN_ASSEMBLY omp_set_lock(&rLockArray[i_global]); b[i_global] += rRHSContribution(i_local); #else double& r_a = rb[i_global]; const double& v_a = rRHSContribution(i_local); #pragma omp atomic r_a += v_a; #endif AssembleRowContributionFreeDofs(rA, rLHSContribution, i_global, i_local, rEquationId); #ifdef USE_LOCKS_IN_ASSEMBLY omp_unset_lock(&rLockArray[i_global]); #endif } //note that computation of reactions is not performed here! } } /** * @brief This method construcs the relationship between the DoF * @param pScheme The integration scheme * @param rA The LHS of the system * @param rModelPart The model part which defines the problem */ virtual void ConstructMatrixStructure( typename TSchemeType::Pointer pScheme, TSystemMatrixType& rA, ModelPart& rModelPart ) { //filling with zero the matrix (creating the structure) Timer::Start("MatrixStructure"); const std::size_t equation_size = BaseType::mEquationSystemSize; std::vector<std::unordered_set<std::size_t> > indices(equation_size); #pragma omp parallel for firstprivate(equation_size) for (int iii = 0; iii < static_cast<int>(equation_size); iii++) { indices[iii].reserve(40); } Element::EquationIdVectorType ids(3, 0); #pragma omp parallel firstprivate(ids) { // The process info const ProcessInfo& r_current_process_info = rModelPart.GetProcessInfo(); // We repeat the same declaration for each thead std::vector<std::unordered_set<std::size_t> > temp_indexes(equation_size); #pragma omp for for (int index = 0; index < static_cast<int>(equation_size); ++index) temp_indexes[index].reserve(30); // Getting the size of the array of elements from the model const int number_of_elements = static_cast<int>(rModelPart.Elements().size()); // Element initial iterator const auto el_begin = rModelPart.ElementsBegin(); // We iterate over the elements #pragma omp for schedule(guided, 512) nowait for (int i_elem = 0; i_elem<number_of_elements; ++i_elem) { auto it_elem = el_begin + i_elem; pScheme->EquationId(*it_elem, ids, r_current_process_info); for (auto& id_i : ids) { if (id_i < BaseType::mEquationSystemSize) { auto& row_indices = temp_indexes[id_i]; for (auto& id_j : ids) if (id_j < BaseType::mEquationSystemSize) row_indices.insert(id_j); } } } // Getting the size of the array of the conditions const int number_of_conditions = static_cast<int>(rModelPart.Conditions().size()); // Condition initial iterator const auto cond_begin = rModelPart.ConditionsBegin(); // We iterate over the conditions #pragma omp for schedule(guided, 512) nowait for (int i_cond = 0; i_cond<number_of_conditions; ++i_cond) { auto it_cond = cond_begin + i_cond; pScheme->EquationId(*it_cond, ids, r_current_process_info); for (auto& id_i : ids) { if (id_i < BaseType::mEquationSystemSize) { auto& row_indices = temp_indexes[id_i]; for (auto& id_j : ids) if (id_j < BaseType::mEquationSystemSize) row_indices.insert(id_j); } } } // Merging all the temporal indexes #pragma omp critical { for (int i = 0; i < static_cast<int>(temp_indexes.size()); ++i) { indices[i].insert(temp_indexes[i].begin(), temp_indexes[i].end()); } } } //count the row sizes unsigned int nnz = 0; for (unsigned int i = 0; i < indices.size(); i++) nnz += indices[i].size(); rA = boost::numeric::ublas::compressed_matrix<double>(indices.size(), indices.size(), nnz); double* Avalues = rA.value_data().begin(); std::size_t* Arow_indices = rA.index1_data().begin(); std::size_t* Acol_indices = rA.index2_data().begin(); //filling the index1 vector - DO NOT MAKE PARALLEL THE FOLLOWING LOOP! Arow_indices[0] = 0; for (int i = 0; i < static_cast<int>(rA.size1()); i++) Arow_indices[i + 1] = Arow_indices[i] + indices[i].size(); #pragma omp parallel for for (int i = 0; i < static_cast<int>(rA.size1()); i++) { const unsigned int row_begin = Arow_indices[i]; const unsigned int row_end = Arow_indices[i + 1]; unsigned int k = row_begin; for (auto it = indices[i].begin(); it != indices[i].end(); it++) { Acol_indices[k] = *it; Avalues[k] = 0.0; k++; } std::sort(&Acol_indices[row_begin], &Acol_indices[row_end]); } rA.set_filled(indices.size() + 1, nnz); Timer::Stop("MatrixStructure"); } /** * @brief This method assembles the LHS of the system * @param rA The LHS to assemble * @param rLHSContribution The local LHS contribution * @param rEquationId The equation id */ void AssembleLHS( TSystemMatrixType& rA, LocalSystemMatrixType& rLHSContribution, EquationIdVectorType& rEquationId ) { unsigned int local_size = rLHSContribution.size1(); for (unsigned int i_local = 0; i_local < local_size; i_local++) { unsigned int i_global = rEquationId[i_local]; if (i_global < BaseType::mEquationSystemSize) { for (unsigned int j_local = 0; j_local < local_size; j_local++) { unsigned int j_global = rEquationId[j_local]; if (j_global < BaseType::mEquationSystemSize) rA(i_global, j_global) += rLHSContribution(i_local, j_local); } } } } /** * @brief This function is equivalent to the AssembleRowContribution of the block builder and solver * @note The main difference respect the block builder and solver is the fact that the fixed DoFs are skipped */ inline void AssembleRowContributionFreeDofs( TSystemMatrixType& rA, const Matrix& rALocal, const IndexType i, const IndexType i_local, const Element::EquationIdVectorType& EquationId ) { double* values_vector = rA.value_data().begin(); std::size_t* index1_vector = rA.index1_data().begin(); std::size_t* index2_vector = rA.index2_data().begin(); const std::size_t left_limit = index1_vector[i]; // Find the first entry // We iterate over the equation ids until we find the first equation id to be considered // We count in which component we find an ID std::size_t last_pos = 0; std::size_t last_found = 0; std::size_t counter = 0; for(std::size_t j=0; j < EquationId.size(); ++j) { ++counter; const std::size_t j_global = EquationId[j]; if (j_global < BaseType::mEquationSystemSize) { last_pos = ForwardFind(j_global,left_limit,index2_vector); last_found = j_global; break; } } // If the counter is equal to the size of the EquationID vector that means that only one dof will be considered, if the number is greater means that all the dofs are fixed. If the number is below means that at we have several dofs free to be considered if (counter <= EquationId.size()) { #ifndef USE_LOCKS_IN_ASSEMBLY double& r_a = values_vector[last_pos]; const double& v_a = rALocal(i_local,counter - 1); #pragma omp atomic r_a += v_a; #else values_vector[last_pos] += rALocal(i_local,counter - 1); #endif // Now find all of the other entries std::size_t pos = 0; for(std::size_t j = counter; j < EquationId.size(); ++j) { std::size_t id_to_find = EquationId[j]; if (id_to_find < BaseType::mEquationSystemSize) { if(id_to_find > last_found) pos = ForwardFind(id_to_find,last_pos+1,index2_vector); else if(id_to_find < last_found) pos = BackwardFind(id_to_find,last_pos-1,index2_vector); else pos = last_pos; #ifndef USE_LOCKS_IN_ASSEMBLY double& r = values_vector[pos]; const double& v = rALocal(i_local,j); #pragma omp atomic r += v; #else values_vector[pos] += Alocal(i_local,j); #endif last_found = id_to_find; last_pos = pos; } } } } inline std::size_t ForwardFind(const std::size_t id_to_find, const std::size_t start, const std::size_t* index_vector) { std::size_t pos = start; while(id_to_find != index_vector[pos]) pos++; return pos; } inline std::size_t BackwardFind(const std::size_t id_to_find, const std::size_t start, const std::size_t* index_vector) { std::size_t pos = start; while(id_to_find != index_vector[pos]) pos--; return pos; } ///@} ///@name Protected Access ///@{ ///@} ///@name Protected Inquiry ///@{ ///@} ///@name Protected LifeCycle ///@{ ///@} private: ///@name Static Member Variables ///@{ ///@} ///@name Member Variables ///@{ ///@} ///@name Private Operators ///@{ ///@} ///@name Private Operations ///@{ /** * @brief This method ensures that the contribution is unique */ inline void AddUnique(std::vector<std::size_t>& v, const std::size_t& candidate) { std::vector<std::size_t>::iterator i = v.begin(); std::vector<std::size_t>::iterator endit = v.end(); while (i != endit && (*i) != candidate) { i++; } if (i == endit) { v.push_back(candidate); } } /** * @brief This method assembles the RHS of the system * @param rb The RHS to assemble * @param rRHSContribution The local RHS contribution * @param rEquationId The equation id */ void AssembleRHS( TSystemVectorType& rb, const LocalSystemVectorType& rRHSContribution, const EquationIdVectorType& rEquationId ) { unsigned int local_size = rRHSContribution.size(); if (BaseType::mCalculateReactionsFlag == false) { for (unsigned int i_local = 0; i_local < local_size; i_local++) { const unsigned int i_global = rEquationId[i_local]; if (i_global < BaseType::mEquationSystemSize) //free dof { // ASSEMBLING THE SYSTEM VECTOR double& b_value = rb[i_global]; const double& rhs_value = rRHSContribution[i_local]; #pragma omp atomic b_value += rhs_value; } } } else { TSystemVectorType& ReactionsVector = *BaseType::mpReactionsVector; for (unsigned int i_local = 0; i_local < local_size; i_local++) { const unsigned int i_global = rEquationId[i_local]; if (i_global < BaseType::mEquationSystemSize) //free dof { // ASSEMBLING THE SYSTEM VECTOR double& b_value = rb[i_global]; const double& rhs_value = rRHSContribution[i_local]; #pragma omp atomic b_value += rhs_value; } else //fixed dof { double& b_value = ReactionsVector[i_global - BaseType::mEquationSystemSize]; const double& rhs_value = rRHSContribution[i_local]; #pragma omp atomic b_value += rhs_value; } } } } /** * @brief This method assembles the LHS of the system (on free rows) * @param rA The LHS to assemble * @param rLHSContribution The local LHS contribution * @param rEquationId The equation id */ void AssembleLHSCompleteOnFreeRows( TSystemMatrixType& rA, LocalSystemMatrixType& rLHSContribution, EquationIdVectorType& rEquationId ) { const SizeType local_size = rLHSContribution.size1(); for (IndexType i_local = 0; i_local < local_size; ++i_local) { const IndexType i_global = rEquationId[i_local]; if (i_global < BaseType::mEquationSystemSize) { for (IndexType j_local = 0; j_local < local_size; ++j_local) { const IndexType j_global = rEquationId[j_local]; rA(i_global, j_global) += rLHSContribution(i_local, j_local); } } } } ///@} ///@name Private Operations ///@{ ///@} ///@name Private Access ///@{ ///@} ///@name Private Inquiry ///@{ ///@} ///@name Un accessible methods ///@{ ///@} }; /* Class ResidualBasedEliminationBuilderAndSolver */ ///@} ///@name Type Definitions ///@{ ///@} } /* namespace Kratos.*/ #endif /* KRATOS_RESIDUAL_BASED_ELIMINATION_BUILDER_AND_SOLVER defined */
StreamTriad_par1.c
#include <stdio.h> #include <stdlib.h> #include <time.h> #include "timer.h" int main(int argc, char *argv[]){ int nsize = 20000000, ntimes=16; double a[nsize]; double b[nsize]; double c[nsize]; struct timespec tstart; // initializing data and arrays double scalar = 3.0, time_sum = 0.0; #pragma omp target teams distribute parallel for simd for (int i=0; i<nsize; i++) { a[i] = 1.0; b[i] = 2.0; } for (int k=0; k<ntimes; k++){ cpu_timer_start(&tstart); // stream triad loop #pragma omp target teams distribute parallel for simd for (int i=0; i<nsize; i++){ c[i] = a[i] + scalar*b[i]; } time_sum += cpu_timer_stop(tstart); } printf("Average runtime for stream triad loop is %lf secs\n", time_sum/ntimes); return(0); }
GB_binop__isle_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 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__isle_int32) // A.*B function (eWiseMult): GB (_AemultB_08__isle_int32) // A.*B function (eWiseMult): GB (_AemultB_02__isle_int32) // A.*B function (eWiseMult): GB (_AemultB_04__isle_int32) // A.*B function (eWiseMult): GB (_AemultB_bitmap__isle_int32) // A*D function (colscale): GB (_AxD__isle_int32) // D*A function (rowscale): GB (_DxB__isle_int32) // C+=B function (dense accum): GB (_Cdense_accumB__isle_int32) // C+=b function (dense accum): GB (_Cdense_accumb__isle_int32) // C+=A+B function (dense ewise3): GB ((none)) // C=A+B function (dense ewise3): GB (_Cdense_ewise3_noaccum__isle_int32) // C=scalar+B GB (_bind1st__isle_int32) // C=scalar+B' GB (_bind1st_tran__isle_int32) // C=A+scalar GB (_bind2nd__isle_int32) // C=A'+scalar GB (_bind2nd_tran__isle_int32) // C type: int32_t // A type: int32_t // A pattern? 0 // B type: int32_t // B pattern? 0 // 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,A_iso) \ int32_t 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) \ int32_t 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) \ int32_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_ISLE || GxB_NO_INT32 || GxB_NO_ISLE_INT32) //------------------------------------------------------------------------------ // 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__isle_int32) ( 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__isle_int32) ( 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__isle_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 //------------------------------------------------------------------------------ GrB_Info GB (_AxD__isle_int32) ( 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 int32_t *restrict Cx = (int32_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__isle_int32) ( GrB_Matrix C, const GrB_Matrix D, const GrB_Matrix B, int nthreads ) { #if GB_DISABLE return (GrB_NO_VALUE) ; #else int32_t *restrict Cx = (int32_t *) 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__isle_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 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) ; int32_t alpha_scalar ; int32_t beta_scalar ; if (is_eWiseUnion) { alpha_scalar = (*((int32_t *) alpha_scalar_in)) ; beta_scalar = (*((int32_t *) 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__isle_int32) ( 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__isle_int32) ( 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__isle_int32) ( 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__isle_int32) ( 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__isle_int32) ( 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 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 < bnz ; p++) { if (!GBB (Bb, p)) continue ; int32_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__isle_int32) ( 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 ; 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 = 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) \ { \ int32_t aij = GBX (Ax, pA, false) ; \ Cx [pC] = (x <= aij) ; \ } GrB_Info GB (_bind1st_tran__isle_int32) ( 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 \ 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 = GBX (Ax, pA, false) ; \ Cx [pC] = (aij <= y) ; \ } GrB_Info GB (_bind2nd_tran__isle_int32) ( 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 int32_t y = (*((const int32_t *) y_input)) ; #include "GB_unop_transpose.c" return (GrB_SUCCESS) ; #endif } #endif
spinless_fermion_basis_core.h
#ifndef _SPINLESS_FERMION_BASIS_OP_H #define _SPINLESS_FERMION_BASIS_OP_H #include <complex> #include "hcb_basis_core.h" #include "numpy/ndarraytypes.h" npy_uint32 bit_count(npy_uint32 I, int l){ I &= (0x7FFFFFFF >> (31-l)); I = I - ((I >> 1) & 0x55555555); I = (I & 0x33333333) + ((I >> 2) & 0x33333333); return (((I + (I >> 4)) & 0x0F0F0F0F) * 0x01010101) >> 24; } npy_uint64 bit_count(npy_uint64 I, int l){ I &= (0x7FFFFFFFFFFFFFFF >> (63-l)); I = I - ((I >> 1) & 0x5555555555555555); I = (I & 0x3333333333333333) + ((I >> 2) & 0x3333333333333333); return (((I + (I >> 4)) & 0x0F0F0F0F0F0F0F0F) * 0x0101010101010101) >> 56; } template<class I> I inline spinless_fermion_map_bits(I s,const int map[],const int N,int &sign){ I ss = 0; int pos_list[64]; int np = 0; bool f_count = 0; for(int i=N-1;i>=0;i--){ int j = map[i]; I n = (s&1); if(n){pos_list[np]=( j<0 ? N+j : N-j-1); ++np;} ss ^= ( j<0 ? n^1<<(N+j) : n<<(N-j-1) ); f_count ^= (n && (i&1) && (j<0)); s >>= 1; } // sort in decending order counting number of permutations. // starting at 2nd element as first element is already sorted. // Loop Invariant - left part of the array is already sorted. if(np > 1){ for (int i = 1; i < np; i++) { int moveMe = pos_list[i]; int j = i; while (j > 0 && moveMe > pos_list[j - 1]) { //Move element pos_list[j] = pos_list[j - 1]; --j; //increase the count as element swap is happend f_count ^= 1; } pos_list[j] = moveMe; } } sign *= (f_count ? -1 : 1); return ss; } template<class I> class spinless_fermion_basis_core : public hcb_basis_core<I> { public: spinless_fermion_basis_core(const int _N) : \ hcb_basis_core<I>::hcb_basis_core(_N) {} spinless_fermion_basis_core(const int _N,const int _nt,const int _maps[], \ const int _pers[], const int _qs[]) : \ hcb_basis_core<I>::hcb_basis_core(_N,_nt,_maps,_pers,_qs) {} ~spinless_fermion_basis_core() {} I map_state(I s,int n_map,int &sign){ if(general_basis_core<I>::nt<=0){ return s; } const int n = general_basis_core<I>::N; return spinless_fermion_map_bits(s,&general_basis_core<I>::maps[n_map*n],n,sign); } void map_state(I s[],npy_intp M,int n_map,signed char sign[]){ if(general_basis_core<I>::nt<=0){ return; } const int n = general_basis_core<I>::N; const int * map = &general_basis_core<I>::maps[n_map*n]; #pragma omp for schedule(static,1) for(npy_intp i=0;i<M;i++){ int temp_sign = sign[i]; s[i] = spinless_fermion_map_bits(s[i],map,n,temp_sign); sign[i] = temp_sign; } } int op(I &r,std::complex<double> &m,const int n_op,const char opstr[],const int indx[]){ I s = r; I one = 1; for(int j=n_op-1;j>-1;j--){ int ind = general_basis_core<I>::N-indx[j]-1; I f_count = bit_count(r,ind); m *= std::complex<double>((f_count&1)?-1:1); I b = (one << ind); bool a = bool((r >> ind)&one); char op = opstr[j]; switch(op){ case 'z': m *= (a?0.5:-0.5); break; case 'n': m *= (a?1:0); break; case '+': m *= (a?0:1); r ^= b; break; case '-': m *= (a?1:0); r ^= b; break; case 'I': break; default: return -1; } if(std::abs(m)==0){ r = s; break; } } return 0; } }; #endif
StmtOpenMP.h
//===- StmtOpenMP.h - Classes for OpenMP directives ------------*- C++ -*-===// // // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. // See https://llvm.org/LICENSE.txt for license information. // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception // //===----------------------------------------------------------------------===// /// \file /// This file defines OpenMP AST classes for executable directives and /// clauses. /// //===----------------------------------------------------------------------===// #ifndef LLVM_CLANG_AST_STMTOPENMP_H #define LLVM_CLANG_AST_STMTOPENMP_H #include "clang/AST/ASTContext.h" #include "clang/AST/Expr.h" #include "clang/AST/OpenMPClause.h" #include "clang/AST/Stmt.h" #include "clang/AST/StmtCXX.h" #include "clang/Basic/OpenMPKinds.h" #include "clang/Basic/SourceLocation.h" namespace clang { //===----------------------------------------------------------------------===// // AST classes for directives. //===----------------------------------------------------------------------===// /// Representation of an OpenMP canonical loop. /// /// OpenMP 1.0 C/C++, section 2.4.1 for Construct; canonical-shape /// OpenMP 2.0 C/C++, section 2.4.1 for Construct; canonical-shape /// OpenMP 2.5, section 2.5.1 Loop Construct; canonical form /// OpenMP 3.1, section 2.5.1 Loop Construct; canonical form /// OpenMP 4.0, section 2.6 Canonical Loop Form /// OpenMP 4.5, section 2.6 Canonical Loop Form /// OpenMP 5.0, section 2.9.1 Canonical Loop Form /// OpenMP 5.1, section 2.11.1 Canonical Loop Nest Form /// /// An OpenMP canonical loop is a for-statement or range-based for-statement /// with additional requirements that ensure that the number of iterations is /// known before entering the loop and allow skipping to an arbitrary iteration. /// The OMPCanonicalLoop AST node wraps a ForStmt or CXXForRangeStmt that is /// known to fulfill OpenMP's canonical loop requirements because of being /// associated to an OMPLoopBasedDirective. That is, the general structure is: /// /// OMPLoopBasedDirective /// [`- CapturedStmt ] /// [ `- CapturedDecl] /// ` OMPCanonicalLoop /// `- ForStmt/CXXForRangeStmt /// `- Stmt /// /// One or multiple CapturedStmt/CapturedDecl pairs may be inserted by some /// directives such as OMPParallelForDirective, but others do not need them /// (such as OMPTileDirective). In The OMPCanonicalLoop and /// ForStmt/CXXForRangeStmt pair is repeated for loop associated with the /// directive. A OMPCanonicalLoop must not appear in the AST unless associated /// with a OMPLoopBasedDirective. In an imperfectly nested loop nest, the /// OMPCanonicalLoop may also be wrapped in a CompoundStmt: /// /// [...] /// ` OMPCanonicalLoop /// `- ForStmt/CXXForRangeStmt /// `- CompoundStmt /// |- Leading in-between code (if any) /// |- OMPCanonicalLoop /// | `- ForStmt/CXXForRangeStmt /// | `- ... /// `- Trailing in-between code (if any) /// /// The leading/trailing in-between code must not itself be a OMPCanonicalLoop /// to avoid confusion which loop belongs to the nesting. /// /// There are three different kinds of iteration variables for different /// purposes: /// * Loop user variable: The user-accessible variable with different value for /// each iteration. /// * Loop iteration variable: The variable used to identify a loop iteration; /// for range-based for-statement, this is the hidden iterator '__begin'. For /// other loops, it is identical to the loop user variable. Must be a /// random-access iterator, pointer or integer type. /// * Logical iteration counter: Normalized loop counter starting at 0 and /// incrementing by one at each iteration. Allows abstracting over the type /// of the loop iteration variable and is always an unsigned integer type /// appropriate to represent the range of the loop iteration variable. Its /// value corresponds to the logical iteration number in the OpenMP /// specification. /// /// This AST node provides two captured statements: /// * The distance function which computes the number of iterations. /// * The loop user variable function that computes the loop user variable when /// given a logical iteration number. /// /// These captured statements provide the link between C/C++ semantics and the /// logical iteration counters used by the OpenMPIRBuilder which is /// language-agnostic and therefore does not know e.g. how to advance a /// random-access iterator. The OpenMPIRBuilder will use this information to /// apply simd, workshare-loop, distribute, taskloop and loop directives to the /// loop. For compatibility with the non-OpenMPIRBuilder codegen path, an /// OMPCanonicalLoop can itself also be wrapped into the CapturedStmts of an /// OMPLoopDirective and skipped when searching for the associated syntactical /// loop. /// /// Example: /// <code> /// std::vector<std::string> Container{1,2,3}; /// for (std::string Str : Container) /// Body(Str); /// </code> /// which is syntactic sugar for approximately: /// <code> /// auto &&__range = Container; /// auto __begin = std::begin(__range); /// auto __end = std::end(__range); /// for (; __begin != __end; ++__begin) { /// std::String Str = *__begin; /// Body(Str); /// } /// </code> /// In this example, the loop user variable is `Str`, the loop iteration /// variable is `__begin` of type `std::vector<std::string>::iterator` and the /// logical iteration number type is `size_t` (unsigned version of /// `std::vector<std::string>::iterator::difference_type` aka `ptrdiff_t`). /// Therefore, the distance function will be /// <code> /// [&](size_t &Result) { Result = __end - __begin; } /// </code> /// and the loop variable function is /// <code> /// [&,__begin](std::vector<std::string>::iterator &Result, size_t Logical) { /// Result = __begin + Logical; /// } /// </code> /// The variable `__begin`, aka the loop iteration variable, is captured by /// value because it is modified in the loop body, but both functions require /// the initial value. The OpenMP specification explicitly leaves unspecified /// when the loop expressions are evaluated such that a capture by reference is /// sufficient. class OMPCanonicalLoop : public Stmt { friend class ASTStmtReader; friend class ASTStmtWriter; /// Children of this AST node. enum { LOOP_STMT, DISTANCE_FUNC, LOOPVAR_FUNC, LOOPVAR_REF, LastSubStmt = LOOPVAR_REF }; private: /// This AST node's children. Stmt *SubStmts[LastSubStmt + 1] = {}; OMPCanonicalLoop() : Stmt(StmtClass::OMPCanonicalLoopClass) {} public: /// Create a new OMPCanonicalLoop. static OMPCanonicalLoop *create(const ASTContext &Ctx, Stmt *LoopStmt, CapturedStmt *DistanceFunc, CapturedStmt *LoopVarFunc, DeclRefExpr *LoopVarRef) { OMPCanonicalLoop *S = new (Ctx) OMPCanonicalLoop(); S->setLoopStmt(LoopStmt); S->setDistanceFunc(DistanceFunc); S->setLoopVarFunc(LoopVarFunc); S->setLoopVarRef(LoopVarRef); return S; } /// Create an empty OMPCanonicalLoop for deserialization. static OMPCanonicalLoop *createEmpty(const ASTContext &Ctx) { return new (Ctx) OMPCanonicalLoop(); } static bool classof(const Stmt *S) { return S->getStmtClass() == StmtClass::OMPCanonicalLoopClass; } SourceLocation getBeginLoc() const { return getLoopStmt()->getBeginLoc(); } SourceLocation getEndLoc() const { return getLoopStmt()->getEndLoc(); } /// Return this AST node's children. /// @{ child_range children() { return child_range(&SubStmts[0], &SubStmts[0] + LastSubStmt + 1); } const_child_range children() const { return const_child_range(&SubStmts[0], &SubStmts[0] + LastSubStmt + 1); } /// @} /// The wrapped syntactic loop statement (ForStmt or CXXForRangeStmt). /// @{ Stmt *getLoopStmt() { return SubStmts[LOOP_STMT]; } const Stmt *getLoopStmt() const { return SubStmts[LOOP_STMT]; } void setLoopStmt(Stmt *S) { assert((isa<ForStmt>(S) || isa<CXXForRangeStmt>(S)) && "Canonical loop must be a for loop (range-based or otherwise)"); SubStmts[LOOP_STMT] = S; } /// @} /// The function that computes the number of loop iterations. Can be evaluated /// before entering the loop but after the syntactical loop's init /// statement(s). /// /// Function signature: void(LogicalTy &Result) /// Any values necessary to compute the distance are captures of the closure. /// @{ CapturedStmt *getDistanceFunc() { return cast<CapturedStmt>(SubStmts[DISTANCE_FUNC]); } const CapturedStmt *getDistanceFunc() const { return cast<CapturedStmt>(SubStmts[DISTANCE_FUNC]); } void setDistanceFunc(CapturedStmt *S) { assert(S && "Expected non-null captured statement"); SubStmts[DISTANCE_FUNC] = S; } /// @} /// The function that computes the loop user variable from a logical iteration /// counter. Can be evaluated as first statement in the loop. /// /// Function signature: void(LoopVarTy &Result, LogicalTy Number) /// Any other values required to compute the loop user variable (such as start /// value, step size) are captured by the closure. In particular, the initial /// value of loop iteration variable is captured by value to be unaffected by /// previous iterations. /// @{ CapturedStmt *getLoopVarFunc() { return cast<CapturedStmt>(SubStmts[LOOPVAR_FUNC]); } const CapturedStmt *getLoopVarFunc() const { return cast<CapturedStmt>(SubStmts[LOOPVAR_FUNC]); } void setLoopVarFunc(CapturedStmt *S) { assert(S && "Expected non-null captured statement"); SubStmts[LOOPVAR_FUNC] = S; } /// @} /// Reference to the loop user variable as accessed in the loop body. /// @{ DeclRefExpr *getLoopVarRef() { return cast<DeclRefExpr>(SubStmts[LOOPVAR_REF]); } const DeclRefExpr *getLoopVarRef() const { return cast<DeclRefExpr>(SubStmts[LOOPVAR_REF]); } void setLoopVarRef(DeclRefExpr *E) { assert(E && "Expected non-null loop variable"); SubStmts[LOOPVAR_REF] = E; } /// @} }; /// This is a basic class for representing single OpenMP executable /// directive. /// class OMPExecutableDirective : public Stmt { friend class ASTStmtReader; friend class ASTStmtWriter; /// Kind of the directive. OpenMPDirectiveKind Kind = llvm::omp::OMPD_unknown; /// Starting location of the directive (directive keyword). SourceLocation StartLoc; /// Ending location of the directive. SourceLocation EndLoc; /// Get the clauses storage. MutableArrayRef<OMPClause *> getClauses() { if (!Data) return llvm::None; return Data->getClauses(); } protected: /// Data, associated with the directive. OMPChildren *Data = nullptr; /// Build instance of directive of class \a K. /// /// \param SC Statement class. /// \param K Kind of OpenMP directive. /// \param StartLoc Starting location of the directive (directive keyword). /// \param EndLoc Ending location of the directive. /// OMPExecutableDirective(StmtClass SC, OpenMPDirectiveKind K, SourceLocation StartLoc, SourceLocation EndLoc) : Stmt(SC), Kind(K), StartLoc(std::move(StartLoc)), EndLoc(std::move(EndLoc)) {} template <typename T, typename... Params> static T *createDirective(const ASTContext &C, ArrayRef<OMPClause *> Clauses, Stmt *AssociatedStmt, unsigned NumChildren, Params &&... P) { void *Mem = C.Allocate(sizeof(T) + OMPChildren::size(Clauses.size(), AssociatedStmt, NumChildren), alignof(T)); auto *Data = OMPChildren::Create(reinterpret_cast<T *>(Mem) + 1, Clauses, AssociatedStmt, NumChildren); auto *Inst = new (Mem) T(std::forward<Params>(P)...); Inst->Data = Data; return Inst; } template <typename T, typename... Params> static T *createEmptyDirective(const ASTContext &C, unsigned NumClauses, bool HasAssociatedStmt, unsigned NumChildren, Params &&... P) { void *Mem = C.Allocate(sizeof(T) + OMPChildren::size(NumClauses, HasAssociatedStmt, NumChildren), alignof(T)); auto *Data = OMPChildren::CreateEmpty(reinterpret_cast<T *>(Mem) + 1, NumClauses, HasAssociatedStmt, NumChildren); auto *Inst = new (Mem) T(std::forward<Params>(P)...); Inst->Data = Data; return Inst; } template <typename T> static T *createEmptyDirective(const ASTContext &C, unsigned NumClauses, bool HasAssociatedStmt = false, unsigned NumChildren = 0) { void *Mem = C.Allocate(sizeof(T) + OMPChildren::size(NumClauses, HasAssociatedStmt, NumChildren), alignof(T)); auto *Data = OMPChildren::CreateEmpty(reinterpret_cast<T *>(Mem) + 1, NumClauses, HasAssociatedStmt, NumChildren); auto *Inst = new (Mem) T; Inst->Data = Data; return Inst; } public: /// Iterates over expressions/statements used in the construct. class used_clauses_child_iterator : public llvm::iterator_adaptor_base< used_clauses_child_iterator, ArrayRef<OMPClause *>::iterator, std::forward_iterator_tag, Stmt *, ptrdiff_t, Stmt *, Stmt *> { ArrayRef<OMPClause *>::iterator End; OMPClause::child_iterator ChildI, ChildEnd; void MoveToNext() { if (ChildI != ChildEnd) return; while (this->I != End) { ++this->I; if (this->I != End) { ChildI = (*this->I)->used_children().begin(); ChildEnd = (*this->I)->used_children().end(); if (ChildI != ChildEnd) return; } } } public: explicit used_clauses_child_iterator(ArrayRef<OMPClause *> Clauses) : used_clauses_child_iterator::iterator_adaptor_base(Clauses.begin()), End(Clauses.end()) { if (this->I != End) { ChildI = (*this->I)->used_children().begin(); ChildEnd = (*this->I)->used_children().end(); MoveToNext(); } } Stmt *operator*() const { return *ChildI; } Stmt *operator->() const { return **this; } used_clauses_child_iterator &operator++() { ++ChildI; if (ChildI != ChildEnd) return *this; if (this->I != End) { ++this->I; if (this->I != End) { ChildI = (*this->I)->used_children().begin(); ChildEnd = (*this->I)->used_children().end(); } } MoveToNext(); return *this; } }; static llvm::iterator_range<used_clauses_child_iterator> used_clauses_children(ArrayRef<OMPClause *> Clauses) { return {used_clauses_child_iterator(Clauses), used_clauses_child_iterator(llvm::makeArrayRef(Clauses.end(), 0))}; } /// Iterates over a filtered subrange of clauses applied to a /// directive. /// /// This iterator visits only clauses of type SpecificClause. template <typename SpecificClause> class specific_clause_iterator : public llvm::iterator_adaptor_base< specific_clause_iterator<SpecificClause>, ArrayRef<OMPClause *>::const_iterator, std::forward_iterator_tag, const SpecificClause *, ptrdiff_t, const SpecificClause *, const SpecificClause *> { ArrayRef<OMPClause *>::const_iterator End; void SkipToNextClause() { while (this->I != End && !isa<SpecificClause>(*this->I)) ++this->I; } public: explicit specific_clause_iterator(ArrayRef<OMPClause *> Clauses) : specific_clause_iterator::iterator_adaptor_base(Clauses.begin()), End(Clauses.end()) { SkipToNextClause(); } const SpecificClause *operator*() const { return cast<SpecificClause>(*this->I); } const SpecificClause *operator->() const { return **this; } specific_clause_iterator &operator++() { ++this->I; SkipToNextClause(); return *this; } }; template <typename SpecificClause> static llvm::iterator_range<specific_clause_iterator<SpecificClause>> getClausesOfKind(ArrayRef<OMPClause *> Clauses) { return {specific_clause_iterator<SpecificClause>(Clauses), specific_clause_iterator<SpecificClause>( llvm::makeArrayRef(Clauses.end(), 0))}; } template <typename SpecificClause> llvm::iterator_range<specific_clause_iterator<SpecificClause>> getClausesOfKind() const { return getClausesOfKind<SpecificClause>(clauses()); } /// Gets a single clause of the specified kind associated with the /// current directive iff there is only one clause of this kind (and assertion /// is fired if there is more than one clause is associated with the /// directive). Returns nullptr if no clause of this kind is associated with /// the directive. template <typename SpecificClause> const SpecificClause *getSingleClause() const { auto Clauses = getClausesOfKind<SpecificClause>(); if (Clauses.begin() != Clauses.end()) { assert(std::next(Clauses.begin()) == Clauses.end() && "There are at least 2 clauses of the specified kind"); return *Clauses.begin(); } return nullptr; } /// Returns true if the current directive has one or more clauses of a /// specific kind. template <typename SpecificClause> bool hasClausesOfKind() const { auto Clauses = getClausesOfKind<SpecificClause>(); return Clauses.begin() != Clauses.end(); } /// Returns starting location of directive kind. SourceLocation getBeginLoc() const { return StartLoc; } /// Returns ending location of directive. SourceLocation getEndLoc() const { return EndLoc; } /// Set starting location of directive kind. /// /// \param Loc New starting location of directive. /// void setLocStart(SourceLocation Loc) { StartLoc = Loc; } /// Set ending location of directive. /// /// \param Loc New ending location of directive. /// void setLocEnd(SourceLocation Loc) { EndLoc = Loc; } /// Get number of clauses. unsigned getNumClauses() const { if (!Data) return 0; return Data->getNumClauses(); } /// Returns specified clause. /// /// \param I Number of clause. /// OMPClause *getClause(unsigned I) const { return clauses()[I]; } /// Returns true if directive has associated statement. bool hasAssociatedStmt() const { return Data && Data->hasAssociatedStmt(); } /// Returns statement associated with the directive. const Stmt *getAssociatedStmt() const { return const_cast<OMPExecutableDirective *>(this)->getAssociatedStmt(); } Stmt *getAssociatedStmt() { assert(hasAssociatedStmt() && "Expected directive with the associated statement."); return Data->getAssociatedStmt(); } /// Returns the captured statement associated with the /// component region within the (combined) directive. /// /// \param RegionKind Component region kind. const CapturedStmt *getCapturedStmt(OpenMPDirectiveKind RegionKind) const { assert(hasAssociatedStmt() && "Expected directive with the associated statement."); SmallVector<OpenMPDirectiveKind, 4> CaptureRegions; getOpenMPCaptureRegions(CaptureRegions, getDirectiveKind()); return Data->getCapturedStmt(RegionKind, CaptureRegions); } /// Get innermost captured statement for the construct. CapturedStmt *getInnermostCapturedStmt() { assert(hasAssociatedStmt() && "Expected directive with the associated statement."); SmallVector<OpenMPDirectiveKind, 4> CaptureRegions; getOpenMPCaptureRegions(CaptureRegions, getDirectiveKind()); return Data->getInnermostCapturedStmt(CaptureRegions); } const CapturedStmt *getInnermostCapturedStmt() const { return const_cast<OMPExecutableDirective *>(this) ->getInnermostCapturedStmt(); } OpenMPDirectiveKind getDirectiveKind() const { return Kind; } static bool classof(const Stmt *S) { return S->getStmtClass() >= firstOMPExecutableDirectiveConstant && S->getStmtClass() <= lastOMPExecutableDirectiveConstant; } child_range children() { if (!Data) return child_range(child_iterator(), child_iterator()); return Data->getAssociatedStmtAsRange(); } const_child_range children() const { return const_cast<OMPExecutableDirective *>(this)->children(); } ArrayRef<OMPClause *> clauses() const { if (!Data) return llvm::None; return Data->getClauses(); } /// Returns whether or not this is a Standalone directive. /// /// Stand-alone directives are executable directives /// that have no associated user code. bool isStandaloneDirective() const; /// Returns the AST node representing OpenMP structured-block of this /// OpenMP executable directive, /// Prerequisite: Executable Directive must not be Standalone directive. const Stmt *getStructuredBlock() const { return const_cast<OMPExecutableDirective *>(this)->getStructuredBlock(); } Stmt *getStructuredBlock(); const Stmt *getRawStmt() const { return const_cast<OMPExecutableDirective *>(this)->getRawStmt(); } Stmt *getRawStmt() { assert(hasAssociatedStmt() && "Expected directive with the associated statement."); return Data->getRawStmt(); } }; /// This represents '#pragma omp parallel' directive. /// /// \code /// #pragma omp parallel private(a,b) reduction(+: c,d) /// \endcode /// In this example directive '#pragma omp parallel' has clauses 'private' /// with the variables 'a' and 'b' and 'reduction' with operator '+' and /// variables 'c' and 'd'. /// class OMPParallelDirective : public OMPExecutableDirective { friend class ASTStmtReader; friend class OMPExecutableDirective; /// true if the construct has inner cancel directive. bool HasCancel = false; /// Build directive with the given start and end location. /// /// \param StartLoc Starting location of the directive (directive keyword). /// \param EndLoc Ending Location of the directive. /// OMPParallelDirective(SourceLocation StartLoc, SourceLocation EndLoc) : OMPExecutableDirective(OMPParallelDirectiveClass, llvm::omp::OMPD_parallel, StartLoc, EndLoc) {} /// Build an empty directive. /// explicit OMPParallelDirective() : OMPExecutableDirective(OMPParallelDirectiveClass, llvm::omp::OMPD_parallel, SourceLocation(), SourceLocation()) {} /// Sets special task reduction descriptor. void setTaskReductionRefExpr(Expr *E) { Data->getChildren()[0] = E; } /// Set cancel state. void setHasCancel(bool Has) { HasCancel = Has; } public: /// Creates directive with a list of \a Clauses. /// /// \param C AST context. /// \param StartLoc Starting location of the directive kind. /// \param EndLoc Ending Location of the directive. /// \param Clauses List of clauses. /// \param AssociatedStmt Statement associated with the directive. /// \param TaskRedRef Task reduction special reference expression to handle /// taskgroup descriptor. /// \param HasCancel true if this directive has inner cancel directive. /// static OMPParallelDirective * Create(const ASTContext &C, SourceLocation StartLoc, SourceLocation EndLoc, ArrayRef<OMPClause *> Clauses, Stmt *AssociatedStmt, Expr *TaskRedRef, bool HasCancel); /// Creates an empty directive with the place for \a N clauses. /// /// \param C AST context. /// \param NumClauses Number of clauses. /// static OMPParallelDirective *CreateEmpty(const ASTContext &C, unsigned NumClauses, EmptyShell); /// Returns special task reduction reference expression. Expr *getTaskReductionRefExpr() { return cast_or_null<Expr>(Data->getChildren()[0]); } const Expr *getTaskReductionRefExpr() const { return const_cast<OMPParallelDirective *>(this)->getTaskReductionRefExpr(); } /// Return true if current directive has inner cancel directive. bool hasCancel() const { return HasCancel; } static bool classof(const Stmt *T) { return T->getStmtClass() == OMPParallelDirectiveClass; } }; /// The base class for all loop-based directives, including loop transformation /// directives. class OMPLoopBasedDirective : public OMPExecutableDirective { friend class ASTStmtReader; protected: /// Number of collapsed loops as specified by 'collapse' clause. unsigned NumAssociatedLoops = 0; /// Build instance of loop directive of class \a Kind. /// /// \param SC Statement class. /// \param Kind Kind of OpenMP directive. /// \param StartLoc Starting location of the directive (directive keyword). /// \param EndLoc Ending location of the directive. /// \param NumAssociatedLoops Number of loops associated with the construct. /// OMPLoopBasedDirective(StmtClass SC, OpenMPDirectiveKind Kind, SourceLocation StartLoc, SourceLocation EndLoc, unsigned NumAssociatedLoops) : OMPExecutableDirective(SC, Kind, StartLoc, EndLoc), NumAssociatedLoops(NumAssociatedLoops) {} public: /// The expressions built to support OpenMP loops in combined/composite /// pragmas (e.g. pragma omp distribute parallel for) struct DistCombinedHelperExprs { /// DistributeLowerBound - used when composing 'omp distribute' with /// 'omp for' in a same construct. Expr *LB; /// DistributeUpperBound - used when composing 'omp distribute' with /// 'omp for' in a same construct. Expr *UB; /// DistributeEnsureUpperBound - used when composing 'omp distribute' /// with 'omp for' in a same construct, EUB depends on DistUB Expr *EUB; /// Distribute loop iteration variable init used when composing 'omp /// distribute' /// with 'omp for' in a same construct Expr *Init; /// Distribute Loop condition used when composing 'omp distribute' /// with 'omp for' in a same construct Expr *Cond; /// Update of LowerBound for statically scheduled omp loops for /// outer loop in combined constructs (e.g. 'distribute parallel for') Expr *NLB; /// Update of UpperBound for statically scheduled omp loops for /// outer loop in combined constructs (e.g. 'distribute parallel for') Expr *NUB; /// Distribute Loop condition used when composing 'omp distribute' /// with 'omp for' in a same construct when schedule is chunked. Expr *DistCond; /// 'omp parallel for' loop condition used when composed with /// 'omp distribute' in the same construct and when schedule is /// chunked and the chunk size is 1. Expr *ParForInDistCond; }; /// The expressions built for the OpenMP loop CodeGen for the /// whole collapsed loop nest. struct HelperExprs { /// Loop iteration variable. Expr *IterationVarRef; /// Loop last iteration number. Expr *LastIteration; /// Loop number of iterations. Expr *NumIterations; /// Calculation of last iteration. Expr *CalcLastIteration; /// Loop pre-condition. Expr *PreCond; /// Loop condition. Expr *Cond; /// Loop iteration variable init. Expr *Init; /// Loop increment. Expr *Inc; /// IsLastIteration - local flag variable passed to runtime. Expr *IL; /// LowerBound - local variable passed to runtime. Expr *LB; /// UpperBound - local variable passed to runtime. Expr *UB; /// Stride - local variable passed to runtime. Expr *ST; /// EnsureUpperBound -- expression UB = min(UB, NumIterations). Expr *EUB; /// Update of LowerBound for statically scheduled 'omp for' loops. Expr *NLB; /// Update of UpperBound for statically scheduled 'omp for' loops. Expr *NUB; /// PreviousLowerBound - local variable passed to runtime in the /// enclosing schedule or null if that does not apply. Expr *PrevLB; /// PreviousUpperBound - local variable passed to runtime in the /// enclosing schedule or null if that does not apply. Expr *PrevUB; /// DistInc - increment expression for distribute loop when found /// combined with a further loop level (e.g. in 'distribute parallel for') /// expression IV = IV + ST Expr *DistInc; /// PrevEUB - expression similar to EUB but to be used when loop /// scheduling uses PrevLB and PrevUB (e.g. in 'distribute parallel for' /// when ensuring that the UB is either the calculated UB by the runtime or /// the end of the assigned distribute chunk) /// expression UB = min (UB, PrevUB) Expr *PrevEUB; /// Counters Loop counters. SmallVector<Expr *, 4> Counters; /// PrivateCounters Loop counters. SmallVector<Expr *, 4> PrivateCounters; /// Expressions for loop counters inits for CodeGen. SmallVector<Expr *, 4> Inits; /// Expressions for loop counters update for CodeGen. SmallVector<Expr *, 4> Updates; /// Final loop counter values for GodeGen. SmallVector<Expr *, 4> Finals; /// List of counters required for the generation of the non-rectangular /// loops. SmallVector<Expr *, 4> DependentCounters; /// List of initializers required for the generation of the non-rectangular /// loops. SmallVector<Expr *, 4> DependentInits; /// List of final conditions required for the generation of the /// non-rectangular loops. SmallVector<Expr *, 4> FinalsConditions; /// Init statement for all captured expressions. Stmt *PreInits; /// Expressions used when combining OpenMP loop pragmas DistCombinedHelperExprs DistCombinedFields; /// Check if all the expressions are built (does not check the /// worksharing ones). bool builtAll() { return IterationVarRef != nullptr && LastIteration != nullptr && NumIterations != nullptr && PreCond != nullptr && Cond != nullptr && Init != nullptr && Inc != nullptr; } /// Initialize all the fields to null. /// \param Size Number of elements in the /// counters/finals/updates/dependent_counters/dependent_inits/finals_conditions /// arrays. void clear(unsigned Size) { IterationVarRef = nullptr; LastIteration = nullptr; CalcLastIteration = nullptr; PreCond = nullptr; Cond = nullptr; Init = nullptr; Inc = nullptr; IL = nullptr; LB = nullptr; UB = nullptr; ST = nullptr; EUB = nullptr; NLB = nullptr; NUB = nullptr; NumIterations = nullptr; PrevLB = nullptr; PrevUB = nullptr; DistInc = nullptr; PrevEUB = nullptr; Counters.resize(Size); PrivateCounters.resize(Size); Inits.resize(Size); Updates.resize(Size); Finals.resize(Size); DependentCounters.resize(Size); DependentInits.resize(Size); FinalsConditions.resize(Size); for (unsigned I = 0; I < Size; ++I) { Counters[I] = nullptr; PrivateCounters[I] = nullptr; Inits[I] = nullptr; Updates[I] = nullptr; Finals[I] = nullptr; DependentCounters[I] = nullptr; DependentInits[I] = nullptr; FinalsConditions[I] = nullptr; } PreInits = nullptr; DistCombinedFields.LB = nullptr; DistCombinedFields.UB = nullptr; DistCombinedFields.EUB = nullptr; DistCombinedFields.Init = nullptr; DistCombinedFields.Cond = nullptr; DistCombinedFields.NLB = nullptr; DistCombinedFields.NUB = nullptr; DistCombinedFields.DistCond = nullptr; DistCombinedFields.ParForInDistCond = nullptr; } }; /// Get number of collapsed loops. unsigned getLoopsNumber() const { return NumAssociatedLoops; } /// Try to find the next loop sub-statement in the specified statement \p /// CurStmt. /// \param TryImperfectlyNestedLoops true, if we need to try to look for the /// imperfectly nested loop. static Stmt *tryToFindNextInnerLoop(Stmt *CurStmt, bool TryImperfectlyNestedLoops); static const Stmt *tryToFindNextInnerLoop(const Stmt *CurStmt, bool TryImperfectlyNestedLoops) { return tryToFindNextInnerLoop(const_cast<Stmt *>(CurStmt), TryImperfectlyNestedLoops); } /// Calls the specified callback function for all the loops in \p CurStmt, /// from the outermost to the innermost. static bool doForAllLoops(Stmt *CurStmt, bool TryImperfectlyNestedLoops, unsigned NumLoops, llvm::function_ref<bool(unsigned, Stmt *)> Callback); static bool doForAllLoops(const Stmt *CurStmt, bool TryImperfectlyNestedLoops, unsigned NumLoops, llvm::function_ref<bool(unsigned, const Stmt *)> Callback) { auto &&NewCallback = [Callback](unsigned Cnt, Stmt *CurStmt) { return Callback(Cnt, CurStmt); }; return doForAllLoops(const_cast<Stmt *>(CurStmt), TryImperfectlyNestedLoops, NumLoops, NewCallback); } /// Calls the specified callback function for all the loop bodies in \p /// CurStmt, from the outermost loop to the innermost. static void doForAllLoopsBodies( Stmt *CurStmt, bool TryImperfectlyNestedLoops, unsigned NumLoops, llvm::function_ref<void(unsigned, Stmt *, Stmt *)> Callback); static void doForAllLoopsBodies( const Stmt *CurStmt, bool TryImperfectlyNestedLoops, unsigned NumLoops, llvm::function_ref<void(unsigned, const Stmt *, const Stmt *)> Callback) { auto &&NewCallback = [Callback](unsigned Cnt, Stmt *Loop, Stmt *Body) { Callback(Cnt, Loop, Body); }; doForAllLoopsBodies(const_cast<Stmt *>(CurStmt), TryImperfectlyNestedLoops, NumLoops, NewCallback); } static bool classof(const Stmt *T) { if (auto *D = dyn_cast<OMPExecutableDirective>(T)) return isOpenMPLoopDirective(D->getDirectiveKind()); return false; } }; /// This is a common base class for loop directives ('omp simd', 'omp /// for', 'omp for simd' etc.). It is responsible for the loop code generation. /// class OMPLoopDirective : public OMPLoopBasedDirective { friend class ASTStmtReader; /// Offsets to the stored exprs. /// This enumeration contains offsets to all the pointers to children /// expressions stored in OMPLoopDirective. /// The first 9 children are necessary for all the loop directives, /// the next 8 are specific to the worksharing ones, and the next 11 are /// used for combined constructs containing two pragmas associated to loops. /// After the fixed children, three arrays of length NumAssociatedLoops are /// allocated: loop counters, their updates and final values. /// PrevLowerBound and PrevUpperBound are used to communicate blocking /// information in composite constructs which require loop blocking /// DistInc is used to generate the increment expression for the distribute /// loop when combined with a further nested loop /// PrevEnsureUpperBound is used as the EnsureUpperBound expression for the /// for loop when combined with a previous distribute loop in the same pragma /// (e.g. 'distribute parallel for') /// enum { IterationVariableOffset = 0, LastIterationOffset = 1, CalcLastIterationOffset = 2, PreConditionOffset = 3, CondOffset = 4, InitOffset = 5, IncOffset = 6, PreInitsOffset = 7, // The '...End' enumerators do not correspond to child expressions - they // specify the offset to the end (and start of the following counters/ // updates/finals/dependent_counters/dependent_inits/finals_conditions // arrays). DefaultEnd = 8, // The following 8 exprs are used by worksharing and distribute loops only. IsLastIterVariableOffset = 8, LowerBoundVariableOffset = 9, UpperBoundVariableOffset = 10, StrideVariableOffset = 11, EnsureUpperBoundOffset = 12, NextLowerBoundOffset = 13, NextUpperBoundOffset = 14, NumIterationsOffset = 15, // Offset to the end for worksharing loop directives. WorksharingEnd = 16, PrevLowerBoundVariableOffset = 16, PrevUpperBoundVariableOffset = 17, DistIncOffset = 18, PrevEnsureUpperBoundOffset = 19, CombinedLowerBoundVariableOffset = 20, CombinedUpperBoundVariableOffset = 21, CombinedEnsureUpperBoundOffset = 22, CombinedInitOffset = 23, CombinedConditionOffset = 24, CombinedNextLowerBoundOffset = 25, CombinedNextUpperBoundOffset = 26, CombinedDistConditionOffset = 27, CombinedParForInDistConditionOffset = 28, // Offset to the end (and start of the following // counters/updates/finals/dependent_counters/dependent_inits/finals_conditions // arrays) for combined distribute loop directives. CombinedDistributeEnd = 29, }; /// Get the counters storage. MutableArrayRef<Expr *> getCounters() { auto **Storage = reinterpret_cast<Expr **>( &Data->getChildren()[getArraysOffset(getDirectiveKind())]); return llvm::makeMutableArrayRef(Storage, getLoopsNumber()); } /// Get the private counters storage. MutableArrayRef<Expr *> getPrivateCounters() { auto **Storage = reinterpret_cast<Expr **>( &Data->getChildren()[getArraysOffset(getDirectiveKind()) + getLoopsNumber()]); return llvm::makeMutableArrayRef(Storage, getLoopsNumber()); } /// Get the updates storage. MutableArrayRef<Expr *> getInits() { auto **Storage = reinterpret_cast<Expr **>( &Data->getChildren()[getArraysOffset(getDirectiveKind()) + 2 * getLoopsNumber()]); return llvm::makeMutableArrayRef(Storage, getLoopsNumber()); } /// Get the updates storage. MutableArrayRef<Expr *> getUpdates() { auto **Storage = reinterpret_cast<Expr **>( &Data->getChildren()[getArraysOffset(getDirectiveKind()) + 3 * getLoopsNumber()]); return llvm::makeMutableArrayRef(Storage, getLoopsNumber()); } /// Get the final counter updates storage. MutableArrayRef<Expr *> getFinals() { auto **Storage = reinterpret_cast<Expr **>( &Data->getChildren()[getArraysOffset(getDirectiveKind()) + 4 * getLoopsNumber()]); return llvm::makeMutableArrayRef(Storage, getLoopsNumber()); } /// Get the dependent counters storage. MutableArrayRef<Expr *> getDependentCounters() { auto **Storage = reinterpret_cast<Expr **>( &Data->getChildren()[getArraysOffset(getDirectiveKind()) + 5 * getLoopsNumber()]); return llvm::makeMutableArrayRef(Storage, getLoopsNumber()); } /// Get the dependent inits storage. MutableArrayRef<Expr *> getDependentInits() { auto **Storage = reinterpret_cast<Expr **>( &Data->getChildren()[getArraysOffset(getDirectiveKind()) + 6 * getLoopsNumber()]); return llvm::makeMutableArrayRef(Storage, getLoopsNumber()); } /// Get the finals conditions storage. MutableArrayRef<Expr *> getFinalsConditions() { auto **Storage = reinterpret_cast<Expr **>( &Data->getChildren()[getArraysOffset(getDirectiveKind()) + 7 * getLoopsNumber()]); return llvm::makeMutableArrayRef(Storage, getLoopsNumber()); } protected: /// Build instance of loop directive of class \a Kind. /// /// \param SC Statement class. /// \param Kind Kind of OpenMP directive. /// \param StartLoc Starting location of the directive (directive keyword). /// \param EndLoc Ending location of the directive. /// \param CollapsedNum Number of collapsed loops from 'collapse' clause. /// OMPLoopDirective(StmtClass SC, OpenMPDirectiveKind Kind, SourceLocation StartLoc, SourceLocation EndLoc, unsigned CollapsedNum) : OMPLoopBasedDirective(SC, Kind, StartLoc, EndLoc, CollapsedNum) {} /// Offset to the start of children expression arrays. static unsigned getArraysOffset(OpenMPDirectiveKind Kind) { if (isOpenMPLoopBoundSharingDirective(Kind)) return CombinedDistributeEnd; if (isOpenMPWorksharingDirective(Kind) || isOpenMPTaskLoopDirective(Kind) || isOpenMPDistributeDirective(Kind)) return WorksharingEnd; return DefaultEnd; } /// Children number. static unsigned numLoopChildren(unsigned CollapsedNum, OpenMPDirectiveKind Kind) { return getArraysOffset(Kind) + 8 * CollapsedNum; // Counters, PrivateCounters, Inits, // Updates, Finals, DependentCounters, // DependentInits, FinalsConditions. } void setIterationVariable(Expr *IV) { Data->getChildren()[IterationVariableOffset] = IV; } void setLastIteration(Expr *LI) { Data->getChildren()[LastIterationOffset] = LI; } void setCalcLastIteration(Expr *CLI) { Data->getChildren()[CalcLastIterationOffset] = CLI; } void setPreCond(Expr *PC) { Data->getChildren()[PreConditionOffset] = PC; } void setCond(Expr *Cond) { Data->getChildren()[CondOffset] = Cond; } void setInit(Expr *Init) { Data->getChildren()[InitOffset] = Init; } void setInc(Expr *Inc) { Data->getChildren()[IncOffset] = Inc; } void setPreInits(Stmt *PreInits) { Data->getChildren()[PreInitsOffset] = PreInits; } void setIsLastIterVariable(Expr *IL) { assert((isOpenMPWorksharingDirective(getDirectiveKind()) || isOpenMPTaskLoopDirective(getDirectiveKind()) || isOpenMPDistributeDirective(getDirectiveKind())) && "expected worksharing loop directive"); Data->getChildren()[IsLastIterVariableOffset] = IL; } void setLowerBoundVariable(Expr *LB) { assert((isOpenMPWorksharingDirective(getDirectiveKind()) || isOpenMPTaskLoopDirective(getDirectiveKind()) || isOpenMPDistributeDirective(getDirectiveKind())) && "expected worksharing loop directive"); Data->getChildren()[LowerBoundVariableOffset] = LB; } void setUpperBoundVariable(Expr *UB) { assert((isOpenMPWorksharingDirective(getDirectiveKind()) || isOpenMPTaskLoopDirective(getDirectiveKind()) || isOpenMPDistributeDirective(getDirectiveKind())) && "expected worksharing loop directive"); Data->getChildren()[UpperBoundVariableOffset] = UB; } void setStrideVariable(Expr *ST) { assert((isOpenMPWorksharingDirective(getDirectiveKind()) || isOpenMPTaskLoopDirective(getDirectiveKind()) || isOpenMPDistributeDirective(getDirectiveKind())) && "expected worksharing loop directive"); Data->getChildren()[StrideVariableOffset] = ST; } void setEnsureUpperBound(Expr *EUB) { assert((isOpenMPWorksharingDirective(getDirectiveKind()) || isOpenMPTaskLoopDirective(getDirectiveKind()) || isOpenMPDistributeDirective(getDirectiveKind())) && "expected worksharing loop directive"); Data->getChildren()[EnsureUpperBoundOffset] = EUB; } void setNextLowerBound(Expr *NLB) { assert((isOpenMPWorksharingDirective(getDirectiveKind()) || isOpenMPTaskLoopDirective(getDirectiveKind()) || isOpenMPDistributeDirective(getDirectiveKind())) && "expected worksharing loop directive"); Data->getChildren()[NextLowerBoundOffset] = NLB; } void setNextUpperBound(Expr *NUB) { assert((isOpenMPWorksharingDirective(getDirectiveKind()) || isOpenMPTaskLoopDirective(getDirectiveKind()) || isOpenMPDistributeDirective(getDirectiveKind())) && "expected worksharing loop directive"); Data->getChildren()[NextUpperBoundOffset] = NUB; } void setNumIterations(Expr *NI) { assert((isOpenMPWorksharingDirective(getDirectiveKind()) || isOpenMPTaskLoopDirective(getDirectiveKind()) || isOpenMPDistributeDirective(getDirectiveKind())) && "expected worksharing loop directive"); Data->getChildren()[NumIterationsOffset] = NI; } void setPrevLowerBoundVariable(Expr *PrevLB) { assert(isOpenMPLoopBoundSharingDirective(getDirectiveKind()) && "expected loop bound sharing directive"); Data->getChildren()[PrevLowerBoundVariableOffset] = PrevLB; } void setPrevUpperBoundVariable(Expr *PrevUB) { assert(isOpenMPLoopBoundSharingDirective(getDirectiveKind()) && "expected loop bound sharing directive"); Data->getChildren()[PrevUpperBoundVariableOffset] = PrevUB; } void setDistInc(Expr *DistInc) { assert(isOpenMPLoopBoundSharingDirective(getDirectiveKind()) && "expected loop bound sharing directive"); Data->getChildren()[DistIncOffset] = DistInc; } void setPrevEnsureUpperBound(Expr *PrevEUB) { assert(isOpenMPLoopBoundSharingDirective(getDirectiveKind()) && "expected loop bound sharing directive"); Data->getChildren()[PrevEnsureUpperBoundOffset] = PrevEUB; } void setCombinedLowerBoundVariable(Expr *CombLB) { assert(isOpenMPLoopBoundSharingDirective(getDirectiveKind()) && "expected loop bound sharing directive"); Data->getChildren()[CombinedLowerBoundVariableOffset] = CombLB; } void setCombinedUpperBoundVariable(Expr *CombUB) { assert(isOpenMPLoopBoundSharingDirective(getDirectiveKind()) && "expected loop bound sharing directive"); Data->getChildren()[CombinedUpperBoundVariableOffset] = CombUB; } void setCombinedEnsureUpperBound(Expr *CombEUB) { assert(isOpenMPLoopBoundSharingDirective(getDirectiveKind()) && "expected loop bound sharing directive"); Data->getChildren()[CombinedEnsureUpperBoundOffset] = CombEUB; } void setCombinedInit(Expr *CombInit) { assert(isOpenMPLoopBoundSharingDirective(getDirectiveKind()) && "expected loop bound sharing directive"); Data->getChildren()[CombinedInitOffset] = CombInit; } void setCombinedCond(Expr *CombCond) { assert(isOpenMPLoopBoundSharingDirective(getDirectiveKind()) && "expected loop bound sharing directive"); Data->getChildren()[CombinedConditionOffset] = CombCond; } void setCombinedNextLowerBound(Expr *CombNLB) { assert(isOpenMPLoopBoundSharingDirective(getDirectiveKind()) && "expected loop bound sharing directive"); Data->getChildren()[CombinedNextLowerBoundOffset] = CombNLB; } void setCombinedNextUpperBound(Expr *CombNUB) { assert(isOpenMPLoopBoundSharingDirective(getDirectiveKind()) && "expected loop bound sharing directive"); Data->getChildren()[CombinedNextUpperBoundOffset] = CombNUB; } void setCombinedDistCond(Expr *CombDistCond) { assert(isOpenMPLoopBoundSharingDirective(getDirectiveKind()) && "expected loop bound distribute sharing directive"); Data->getChildren()[CombinedDistConditionOffset] = CombDistCond; } void setCombinedParForInDistCond(Expr *CombParForInDistCond) { assert(isOpenMPLoopBoundSharingDirective(getDirectiveKind()) && "expected loop bound distribute sharing directive"); Data->getChildren()[CombinedParForInDistConditionOffset] = CombParForInDistCond; } void setCounters(ArrayRef<Expr *> A); void setPrivateCounters(ArrayRef<Expr *> A); void setInits(ArrayRef<Expr *> A); void setUpdates(ArrayRef<Expr *> A); void setFinals(ArrayRef<Expr *> A); void setDependentCounters(ArrayRef<Expr *> A); void setDependentInits(ArrayRef<Expr *> A); void setFinalsConditions(ArrayRef<Expr *> A); public: Expr *getIterationVariable() const { return cast<Expr>(Data->getChildren()[IterationVariableOffset]); } Expr *getLastIteration() const { return cast<Expr>(Data->getChildren()[LastIterationOffset]); } Expr *getCalcLastIteration() const { return cast<Expr>(Data->getChildren()[CalcLastIterationOffset]); } Expr *getPreCond() const { return cast<Expr>(Data->getChildren()[PreConditionOffset]); } Expr *getCond() const { return cast<Expr>(Data->getChildren()[CondOffset]); } Expr *getInit() const { return cast<Expr>(Data->getChildren()[InitOffset]); } Expr *getInc() const { return cast<Expr>(Data->getChildren()[IncOffset]); } const Stmt *getPreInits() const { return Data->getChildren()[PreInitsOffset]; } Stmt *getPreInits() { return Data->getChildren()[PreInitsOffset]; } Expr *getIsLastIterVariable() const { assert((isOpenMPWorksharingDirective(getDirectiveKind()) || isOpenMPTaskLoopDirective(getDirectiveKind()) || isOpenMPDistributeDirective(getDirectiveKind())) && "expected worksharing loop directive"); return cast<Expr>(Data->getChildren()[IsLastIterVariableOffset]); } Expr *getLowerBoundVariable() const { assert((isOpenMPWorksharingDirective(getDirectiveKind()) || isOpenMPTaskLoopDirective(getDirectiveKind()) || isOpenMPDistributeDirective(getDirectiveKind())) && "expected worksharing loop directive"); return cast<Expr>(Data->getChildren()[LowerBoundVariableOffset]); } Expr *getUpperBoundVariable() const { assert((isOpenMPWorksharingDirective(getDirectiveKind()) || isOpenMPTaskLoopDirective(getDirectiveKind()) || isOpenMPDistributeDirective(getDirectiveKind())) && "expected worksharing loop directive"); return cast<Expr>(Data->getChildren()[UpperBoundVariableOffset]); } Expr *getStrideVariable() const { assert((isOpenMPWorksharingDirective(getDirectiveKind()) || isOpenMPTaskLoopDirective(getDirectiveKind()) || isOpenMPDistributeDirective(getDirectiveKind())) && "expected worksharing loop directive"); return cast<Expr>(Data->getChildren()[StrideVariableOffset]); } Expr *getEnsureUpperBound() const { assert((isOpenMPWorksharingDirective(getDirectiveKind()) || isOpenMPTaskLoopDirective(getDirectiveKind()) || isOpenMPDistributeDirective(getDirectiveKind())) && "expected worksharing loop directive"); return cast<Expr>(Data->getChildren()[EnsureUpperBoundOffset]); } Expr *getNextLowerBound() const { assert((isOpenMPWorksharingDirective(getDirectiveKind()) || isOpenMPTaskLoopDirective(getDirectiveKind()) || isOpenMPDistributeDirective(getDirectiveKind())) && "expected worksharing loop directive"); return cast<Expr>(Data->getChildren()[NextLowerBoundOffset]); } Expr *getNextUpperBound() const { assert((isOpenMPWorksharingDirective(getDirectiveKind()) || isOpenMPTaskLoopDirective(getDirectiveKind()) || isOpenMPDistributeDirective(getDirectiveKind())) && "expected worksharing loop directive"); return cast<Expr>(Data->getChildren()[NextUpperBoundOffset]); } Expr *getNumIterations() const { assert((isOpenMPWorksharingDirective(getDirectiveKind()) || isOpenMPTaskLoopDirective(getDirectiveKind()) || isOpenMPDistributeDirective(getDirectiveKind())) && "expected worksharing loop directive"); return cast<Expr>(Data->getChildren()[NumIterationsOffset]); } Expr *getPrevLowerBoundVariable() const { assert(isOpenMPLoopBoundSharingDirective(getDirectiveKind()) && "expected loop bound sharing directive"); return cast<Expr>(Data->getChildren()[PrevLowerBoundVariableOffset]); } Expr *getPrevUpperBoundVariable() const { assert(isOpenMPLoopBoundSharingDirective(getDirectiveKind()) && "expected loop bound sharing directive"); return cast<Expr>(Data->getChildren()[PrevUpperBoundVariableOffset]); } Expr *getDistInc() const { assert(isOpenMPLoopBoundSharingDirective(getDirectiveKind()) && "expected loop bound sharing directive"); return cast<Expr>(Data->getChildren()[DistIncOffset]); } Expr *getPrevEnsureUpperBound() const { assert(isOpenMPLoopBoundSharingDirective(getDirectiveKind()) && "expected loop bound sharing directive"); return cast<Expr>(Data->getChildren()[PrevEnsureUpperBoundOffset]); } Expr *getCombinedLowerBoundVariable() const { assert(isOpenMPLoopBoundSharingDirective(getDirectiveKind()) && "expected loop bound sharing directive"); return cast<Expr>(Data->getChildren()[CombinedLowerBoundVariableOffset]); } Expr *getCombinedUpperBoundVariable() const { assert(isOpenMPLoopBoundSharingDirective(getDirectiveKind()) && "expected loop bound sharing directive"); return cast<Expr>(Data->getChildren()[CombinedUpperBoundVariableOffset]); } Expr *getCombinedEnsureUpperBound() const { assert(isOpenMPLoopBoundSharingDirective(getDirectiveKind()) && "expected loop bound sharing directive"); return cast<Expr>(Data->getChildren()[CombinedEnsureUpperBoundOffset]); } Expr *getCombinedInit() const { assert(isOpenMPLoopBoundSharingDirective(getDirectiveKind()) && "expected loop bound sharing directive"); return cast<Expr>(Data->getChildren()[CombinedInitOffset]); } Expr *getCombinedCond() const { assert(isOpenMPLoopBoundSharingDirective(getDirectiveKind()) && "expected loop bound sharing directive"); return cast<Expr>(Data->getChildren()[CombinedConditionOffset]); } Expr *getCombinedNextLowerBound() const { assert(isOpenMPLoopBoundSharingDirective(getDirectiveKind()) && "expected loop bound sharing directive"); return cast<Expr>(Data->getChildren()[CombinedNextLowerBoundOffset]); } Expr *getCombinedNextUpperBound() const { assert(isOpenMPLoopBoundSharingDirective(getDirectiveKind()) && "expected loop bound sharing directive"); return cast<Expr>(Data->getChildren()[CombinedNextUpperBoundOffset]); } Expr *getCombinedDistCond() const { assert(isOpenMPLoopBoundSharingDirective(getDirectiveKind()) && "expected loop bound distribute sharing directive"); return cast<Expr>(Data->getChildren()[CombinedDistConditionOffset]); } Expr *getCombinedParForInDistCond() const { assert(isOpenMPLoopBoundSharingDirective(getDirectiveKind()) && "expected loop bound distribute sharing directive"); return cast<Expr>(Data->getChildren()[CombinedParForInDistConditionOffset]); } Stmt *getBody(); const Stmt *getBody() const { return const_cast<OMPLoopDirective *>(this)->getBody(); } ArrayRef<Expr *> counters() { return getCounters(); } ArrayRef<Expr *> counters() const { return const_cast<OMPLoopDirective *>(this)->getCounters(); } ArrayRef<Expr *> private_counters() { return getPrivateCounters(); } ArrayRef<Expr *> private_counters() const { return const_cast<OMPLoopDirective *>(this)->getPrivateCounters(); } ArrayRef<Expr *> inits() { return getInits(); } ArrayRef<Expr *> inits() const { return const_cast<OMPLoopDirective *>(this)->getInits(); } ArrayRef<Expr *> updates() { return getUpdates(); } ArrayRef<Expr *> updates() const { return const_cast<OMPLoopDirective *>(this)->getUpdates(); } ArrayRef<Expr *> finals() { return getFinals(); } ArrayRef<Expr *> finals() const { return const_cast<OMPLoopDirective *>(this)->getFinals(); } ArrayRef<Expr *> dependent_counters() { return getDependentCounters(); } ArrayRef<Expr *> dependent_counters() const { return const_cast<OMPLoopDirective *>(this)->getDependentCounters(); } ArrayRef<Expr *> dependent_inits() { return getDependentInits(); } ArrayRef<Expr *> dependent_inits() const { return const_cast<OMPLoopDirective *>(this)->getDependentInits(); } ArrayRef<Expr *> finals_conditions() { return getFinalsConditions(); } ArrayRef<Expr *> finals_conditions() const { return const_cast<OMPLoopDirective *>(this)->getFinalsConditions(); } static bool classof(const Stmt *T) { return T->getStmtClass() == OMPSimdDirectiveClass || T->getStmtClass() == OMPForDirectiveClass || T->getStmtClass() == OMPForSimdDirectiveClass || T->getStmtClass() == OMPParallelForDirectiveClass || T->getStmtClass() == OMPParallelForSimdDirectiveClass || T->getStmtClass() == OMPTaskLoopDirectiveClass || T->getStmtClass() == OMPTaskLoopSimdDirectiveClass || T->getStmtClass() == OMPMasterTaskLoopDirectiveClass || T->getStmtClass() == OMPMasterTaskLoopSimdDirectiveClass || T->getStmtClass() == OMPParallelMasterTaskLoopDirectiveClass || T->getStmtClass() == OMPParallelMasterTaskLoopSimdDirectiveClass || T->getStmtClass() == OMPDistributeDirectiveClass || T->getStmtClass() == OMPTargetParallelForDirectiveClass || T->getStmtClass() == OMPDistributeParallelForDirectiveClass || T->getStmtClass() == OMPDistributeParallelForSimdDirectiveClass || T->getStmtClass() == OMPDistributeSimdDirectiveClass || T->getStmtClass() == OMPTargetParallelForSimdDirectiveClass || T->getStmtClass() == OMPTargetSimdDirectiveClass || T->getStmtClass() == OMPTeamsDistributeDirectiveClass || T->getStmtClass() == OMPTeamsDistributeSimdDirectiveClass || T->getStmtClass() == OMPTeamsDistributeParallelForSimdDirectiveClass || T->getStmtClass() == OMPTeamsDistributeParallelForDirectiveClass || T->getStmtClass() == OMPTargetTeamsDistributeParallelForDirectiveClass || T->getStmtClass() == OMPTargetTeamsDistributeParallelForSimdDirectiveClass || T->getStmtClass() == OMPTargetTeamsDistributeDirectiveClass || T->getStmtClass() == OMPTargetTeamsDistributeSimdDirectiveClass; } }; /// This represents '#pragma omp simd' directive. /// /// \code /// #pragma omp simd private(a,b) linear(i,j:s) reduction(+:c,d) /// \endcode /// In this example directive '#pragma omp simd' has clauses 'private' /// with the variables 'a' and 'b', 'linear' with variables 'i', 'j' and /// linear step 's', 'reduction' with operator '+' and variables 'c' and 'd'. /// class OMPSimdDirective : public OMPLoopDirective { friend class ASTStmtReader; friend class OMPExecutableDirective; /// Build directive with the given start and end location. /// /// \param StartLoc Starting location of the directive kind. /// \param EndLoc Ending location of the directive. /// \param CollapsedNum Number of collapsed nested loops. /// OMPSimdDirective(SourceLocation StartLoc, SourceLocation EndLoc, unsigned CollapsedNum) : OMPLoopDirective(OMPSimdDirectiveClass, llvm::omp::OMPD_simd, StartLoc, EndLoc, CollapsedNum) {} /// Build an empty directive. /// /// \param CollapsedNum Number of collapsed nested loops. /// explicit OMPSimdDirective(unsigned CollapsedNum) : OMPLoopDirective(OMPSimdDirectiveClass, llvm::omp::OMPD_simd, SourceLocation(), SourceLocation(), CollapsedNum) {} public: /// Creates directive with a list of \a Clauses. /// /// \param C AST context. /// \param StartLoc Starting location of the directive kind. /// \param EndLoc Ending Location of the directive. /// \param CollapsedNum Number of collapsed loops. /// \param Clauses List of clauses. /// \param AssociatedStmt Statement, associated with the directive. /// \param Exprs Helper expressions for CodeGen. /// static OMPSimdDirective *Create(const ASTContext &C, SourceLocation StartLoc, SourceLocation EndLoc, unsigned CollapsedNum, ArrayRef<OMPClause *> Clauses, Stmt *AssociatedStmt, const HelperExprs &Exprs); /// Creates an empty directive with the place /// for \a NumClauses clauses. /// /// \param C AST context. /// \param CollapsedNum Number of collapsed nested loops. /// \param NumClauses Number of clauses. /// static OMPSimdDirective *CreateEmpty(const ASTContext &C, unsigned NumClauses, unsigned CollapsedNum, EmptyShell); static bool classof(const Stmt *T) { return T->getStmtClass() == OMPSimdDirectiveClass; } }; /// This represents '#pragma omp for' directive. /// /// \code /// #pragma omp for private(a,b) reduction(+:c,d) /// \endcode /// In this example directive '#pragma omp for' has clauses 'private' with the /// variables 'a' and 'b' and 'reduction' with operator '+' and variables 'c' /// and 'd'. /// class OMPForDirective : public OMPLoopDirective { friend class ASTStmtReader; friend class OMPExecutableDirective; /// true if current directive has inner cancel directive. bool HasCancel = false; /// Build directive with the given start and end location. /// /// \param StartLoc Starting location of the directive kind. /// \param EndLoc Ending location of the directive. /// \param CollapsedNum Number of collapsed nested loops. /// OMPForDirective(SourceLocation StartLoc, SourceLocation EndLoc, unsigned CollapsedNum) : OMPLoopDirective(OMPForDirectiveClass, llvm::omp::OMPD_for, StartLoc, EndLoc, CollapsedNum) {} /// Build an empty directive. /// /// \param CollapsedNum Number of collapsed nested loops. /// explicit OMPForDirective(unsigned CollapsedNum) : OMPLoopDirective(OMPForDirectiveClass, llvm::omp::OMPD_for, SourceLocation(), SourceLocation(), CollapsedNum) {} /// Sets special task reduction descriptor. void setTaskReductionRefExpr(Expr *E) { Data->getChildren()[numLoopChildren(getLoopsNumber(), llvm::omp::OMPD_for)] = E; } /// Set cancel state. void setHasCancel(bool Has) { HasCancel = Has; } public: /// Creates directive with a list of \a Clauses. /// /// \param C AST context. /// \param StartLoc Starting location of the directive kind. /// \param EndLoc Ending Location of the directive. /// \param CollapsedNum Number of collapsed loops. /// \param Clauses List of clauses. /// \param AssociatedStmt Statement, associated with the directive. /// \param Exprs Helper expressions for CodeGen. /// \param TaskRedRef Task reduction special reference expression to handle /// taskgroup descriptor. /// \param HasCancel true if current directive has inner cancel directive. /// static OMPForDirective *Create(const ASTContext &C, SourceLocation StartLoc, SourceLocation EndLoc, unsigned CollapsedNum, ArrayRef<OMPClause *> Clauses, Stmt *AssociatedStmt, const HelperExprs &Exprs, Expr *TaskRedRef, bool HasCancel); /// Creates an empty directive with the place /// for \a NumClauses clauses. /// /// \param C AST context. /// \param CollapsedNum Number of collapsed nested loops. /// \param NumClauses Number of clauses. /// static OMPForDirective *CreateEmpty(const ASTContext &C, unsigned NumClauses, unsigned CollapsedNum, EmptyShell); /// Returns special task reduction reference expression. Expr *getTaskReductionRefExpr() { return cast_or_null<Expr>(Data->getChildren()[numLoopChildren( getLoopsNumber(), llvm::omp::OMPD_for)]); } const Expr *getTaskReductionRefExpr() const { return const_cast<OMPForDirective *>(this)->getTaskReductionRefExpr(); } /// Return true if current directive has inner cancel directive. bool hasCancel() const { return HasCancel; } static bool classof(const Stmt *T) { return T->getStmtClass() == OMPForDirectiveClass; } }; /// This represents '#pragma omp for simd' directive. /// /// \code /// #pragma omp for simd private(a,b) linear(i,j:s) reduction(+:c,d) /// \endcode /// In this example directive '#pragma omp for simd' has clauses 'private' /// with the variables 'a' and 'b', 'linear' with variables 'i', 'j' and /// linear step 's', 'reduction' with operator '+' and variables 'c' and 'd'. /// class OMPForSimdDirective : public OMPLoopDirective { friend class ASTStmtReader; friend class OMPExecutableDirective; /// Build directive with the given start and end location. /// /// \param StartLoc Starting location of the directive kind. /// \param EndLoc Ending location of the directive. /// \param CollapsedNum Number of collapsed nested loops. /// OMPForSimdDirective(SourceLocation StartLoc, SourceLocation EndLoc, unsigned CollapsedNum) : OMPLoopDirective(OMPForSimdDirectiveClass, llvm::omp::OMPD_for_simd, StartLoc, EndLoc, CollapsedNum) {} /// Build an empty directive. /// /// \param CollapsedNum Number of collapsed nested loops. /// explicit OMPForSimdDirective(unsigned CollapsedNum) : OMPLoopDirective(OMPForSimdDirectiveClass, llvm::omp::OMPD_for_simd, SourceLocation(), SourceLocation(), CollapsedNum) {} public: /// Creates directive with a list of \a Clauses. /// /// \param C AST context. /// \param StartLoc Starting location of the directive kind. /// \param EndLoc Ending Location of the directive. /// \param CollapsedNum Number of collapsed loops. /// \param Clauses List of clauses. /// \param AssociatedStmt Statement, associated with the directive. /// \param Exprs Helper expressions for CodeGen. /// static OMPForSimdDirective * Create(const ASTContext &C, SourceLocation StartLoc, SourceLocation EndLoc, unsigned CollapsedNum, ArrayRef<OMPClause *> Clauses, Stmt *AssociatedStmt, const HelperExprs &Exprs); /// Creates an empty directive with the place /// for \a NumClauses clauses. /// /// \param C AST context. /// \param CollapsedNum Number of collapsed nested loops. /// \param NumClauses Number of clauses. /// static OMPForSimdDirective *CreateEmpty(const ASTContext &C, unsigned NumClauses, unsigned CollapsedNum, EmptyShell); static bool classof(const Stmt *T) { return T->getStmtClass() == OMPForSimdDirectiveClass; } }; /// This represents '#pragma omp sections' directive. /// /// \code /// #pragma omp sections private(a,b) reduction(+:c,d) /// \endcode /// In this example directive '#pragma omp sections' has clauses 'private' with /// the variables 'a' and 'b' and 'reduction' with operator '+' and variables /// 'c' and 'd'. /// class OMPSectionsDirective : public OMPExecutableDirective { friend class ASTStmtReader; friend class OMPExecutableDirective; /// true if current directive has inner cancel directive. bool HasCancel = false; /// Build directive with the given start and end location. /// /// \param StartLoc Starting location of the directive kind. /// \param EndLoc Ending location of the directive. /// OMPSectionsDirective(SourceLocation StartLoc, SourceLocation EndLoc) : OMPExecutableDirective(OMPSectionsDirectiveClass, llvm::omp::OMPD_sections, StartLoc, EndLoc) {} /// Build an empty directive. /// explicit OMPSectionsDirective() : OMPExecutableDirective(OMPSectionsDirectiveClass, llvm::omp::OMPD_sections, SourceLocation(), SourceLocation()) {} /// Sets special task reduction descriptor. void setTaskReductionRefExpr(Expr *E) { Data->getChildren()[0] = E; } /// Set cancel state. void setHasCancel(bool Has) { HasCancel = Has; } public: /// Creates directive with a list of \a Clauses. /// /// \param C AST context. /// \param StartLoc Starting location of the directive kind. /// \param EndLoc Ending Location of the directive. /// \param Clauses List of clauses. /// \param AssociatedStmt Statement, associated with the directive. /// \param TaskRedRef Task reduction special reference expression to handle /// taskgroup descriptor. /// \param HasCancel true if current directive has inner directive. /// static OMPSectionsDirective * Create(const ASTContext &C, SourceLocation StartLoc, SourceLocation EndLoc, ArrayRef<OMPClause *> Clauses, Stmt *AssociatedStmt, Expr *TaskRedRef, bool HasCancel); /// Creates an empty directive with the place for \a NumClauses /// clauses. /// /// \param C AST context. /// \param NumClauses Number of clauses. /// static OMPSectionsDirective *CreateEmpty(const ASTContext &C, unsigned NumClauses, EmptyShell); /// Returns special task reduction reference expression. Expr *getTaskReductionRefExpr() { return cast_or_null<Expr>(Data->getChildren()[0]); } const Expr *getTaskReductionRefExpr() const { return const_cast<OMPSectionsDirective *>(this)->getTaskReductionRefExpr(); } /// Return true if current directive has inner cancel directive. bool hasCancel() const { return HasCancel; } static bool classof(const Stmt *T) { return T->getStmtClass() == OMPSectionsDirectiveClass; } }; /// This represents '#pragma omp section' directive. /// /// \code /// #pragma omp section /// \endcode /// class OMPSectionDirective : public OMPExecutableDirective { friend class ASTStmtReader; friend class OMPExecutableDirective; /// true if current directive has inner cancel directive. bool HasCancel = false; /// Build directive with the given start and end location. /// /// \param StartLoc Starting location of the directive kind. /// \param EndLoc Ending location of the directive. /// OMPSectionDirective(SourceLocation StartLoc, SourceLocation EndLoc) : OMPExecutableDirective(OMPSectionDirectiveClass, llvm::omp::OMPD_section, StartLoc, EndLoc) {} /// Build an empty directive. /// explicit OMPSectionDirective() : OMPExecutableDirective(OMPSectionDirectiveClass, llvm::omp::OMPD_section, SourceLocation(), SourceLocation()) {} public: /// Creates directive. /// /// \param C AST context. /// \param StartLoc Starting location of the directive kind. /// \param EndLoc Ending Location of the directive. /// \param AssociatedStmt Statement, associated with the directive. /// \param HasCancel true if current directive has inner directive. /// static OMPSectionDirective *Create(const ASTContext &C, SourceLocation StartLoc, SourceLocation EndLoc, Stmt *AssociatedStmt, bool HasCancel); /// Creates an empty directive. /// /// \param C AST context. /// static OMPSectionDirective *CreateEmpty(const ASTContext &C, EmptyShell); /// Set cancel state. void setHasCancel(bool Has) { HasCancel = Has; } /// Return true if current directive has inner cancel directive. bool hasCancel() const { return HasCancel; } static bool classof(const Stmt *T) { return T->getStmtClass() == OMPSectionDirectiveClass; } }; /// This represents '#pragma omp single' directive. /// /// \code /// #pragma omp single private(a,b) copyprivate(c,d) /// \endcode /// In this example directive '#pragma omp single' has clauses 'private' with /// the variables 'a' and 'b' and 'copyprivate' with variables 'c' and 'd'. /// class OMPSingleDirective : public OMPExecutableDirective { friend class ASTStmtReader; friend class OMPExecutableDirective; /// Build directive with the given start and end location. /// /// \param StartLoc Starting location of the directive kind. /// \param EndLoc Ending location of the directive. /// OMPSingleDirective(SourceLocation StartLoc, SourceLocation EndLoc) : OMPExecutableDirective(OMPSingleDirectiveClass, llvm::omp::OMPD_single, StartLoc, EndLoc) {} /// Build an empty directive. /// explicit OMPSingleDirective() : OMPExecutableDirective(OMPSingleDirectiveClass, llvm::omp::OMPD_single, SourceLocation(), SourceLocation()) {} public: /// Creates directive with a list of \a Clauses. /// /// \param C AST context. /// \param StartLoc Starting location of the directive kind. /// \param EndLoc Ending Location of the directive. /// \param Clauses List of clauses. /// \param AssociatedStmt Statement, associated with the directive. /// static OMPSingleDirective * Create(const ASTContext &C, SourceLocation StartLoc, SourceLocation EndLoc, ArrayRef<OMPClause *> Clauses, Stmt *AssociatedStmt); /// Creates an empty directive with the place for \a NumClauses /// clauses. /// /// \param C AST context. /// \param NumClauses Number of clauses. /// static OMPSingleDirective *CreateEmpty(const ASTContext &C, unsigned NumClauses, EmptyShell); static bool classof(const Stmt *T) { return T->getStmtClass() == OMPSingleDirectiveClass; } }; /// This represents '#pragma omp master' directive. /// /// \code /// #pragma omp master /// \endcode /// class OMPMasterDirective : public OMPExecutableDirective { friend class ASTStmtReader; friend class OMPExecutableDirective; /// Build directive with the given start and end location. /// /// \param StartLoc Starting location of the directive kind. /// \param EndLoc Ending location of the directive. /// OMPMasterDirective(SourceLocation StartLoc, SourceLocation EndLoc) : OMPExecutableDirective(OMPMasterDirectiveClass, llvm::omp::OMPD_master, StartLoc, EndLoc) {} /// Build an empty directive. /// explicit OMPMasterDirective() : OMPExecutableDirective(OMPMasterDirectiveClass, llvm::omp::OMPD_master, SourceLocation(), SourceLocation()) {} public: /// Creates directive. /// /// \param C AST context. /// \param StartLoc Starting location of the directive kind. /// \param EndLoc Ending Location of the directive. /// \param AssociatedStmt Statement, associated with the directive. /// static OMPMasterDirective *Create(const ASTContext &C, SourceLocation StartLoc, SourceLocation EndLoc, Stmt *AssociatedStmt); /// Creates an empty directive. /// /// \param C AST context. /// static OMPMasterDirective *CreateEmpty(const ASTContext &C, EmptyShell); static bool classof(const Stmt *T) { return T->getStmtClass() == OMPMasterDirectiveClass; } }; /// This represents '#pragma omp critical' directive. /// /// \code /// #pragma omp critical /// \endcode /// class OMPCriticalDirective : public OMPExecutableDirective { friend class ASTStmtReader; friend class OMPExecutableDirective; /// Name of the directive. DeclarationNameInfo DirName; /// Build directive with the given start and end location. /// /// \param Name Name of the directive. /// \param StartLoc Starting location of the directive kind. /// \param EndLoc Ending location of the directive. /// OMPCriticalDirective(const DeclarationNameInfo &Name, SourceLocation StartLoc, SourceLocation EndLoc) : OMPExecutableDirective(OMPCriticalDirectiveClass, llvm::omp::OMPD_critical, StartLoc, EndLoc), DirName(Name) {} /// Build an empty directive. /// explicit OMPCriticalDirective() : OMPExecutableDirective(OMPCriticalDirectiveClass, llvm::omp::OMPD_critical, SourceLocation(), SourceLocation()) {} /// Set name of the directive. /// /// \param Name Name of the directive. /// void setDirectiveName(const DeclarationNameInfo &Name) { DirName = Name; } public: /// Creates directive. /// /// \param C AST context. /// \param Name Name of the directive. /// \param StartLoc Starting location of the directive kind. /// \param EndLoc Ending Location of the directive. /// \param Clauses List of clauses. /// \param AssociatedStmt Statement, associated with the directive. /// static OMPCriticalDirective * Create(const ASTContext &C, const DeclarationNameInfo &Name, SourceLocation StartLoc, SourceLocation EndLoc, ArrayRef<OMPClause *> Clauses, Stmt *AssociatedStmt); /// Creates an empty directive. /// /// \param C AST context. /// \param NumClauses Number of clauses. /// static OMPCriticalDirective *CreateEmpty(const ASTContext &C, unsigned NumClauses, EmptyShell); /// Return name of the directive. /// DeclarationNameInfo getDirectiveName() const { return DirName; } static bool classof(const Stmt *T) { return T->getStmtClass() == OMPCriticalDirectiveClass; } }; /// This represents '#pragma omp parallel for' directive. /// /// \code /// #pragma omp parallel for private(a,b) reduction(+:c,d) /// \endcode /// In this example directive '#pragma omp parallel for' has clauses 'private' /// with the variables 'a' and 'b' and 'reduction' with operator '+' and /// variables 'c' and 'd'. /// class OMPParallelForDirective : public OMPLoopDirective { friend class ASTStmtReader; friend class OMPExecutableDirective; /// true if current region has inner cancel directive. bool HasCancel = false; /// Build directive with the given start and end location. /// /// \param StartLoc Starting location of the directive kind. /// \param EndLoc Ending location of the directive. /// \param CollapsedNum Number of collapsed nested loops. /// OMPParallelForDirective(SourceLocation StartLoc, SourceLocation EndLoc, unsigned CollapsedNum) : OMPLoopDirective(OMPParallelForDirectiveClass, llvm::omp::OMPD_parallel_for, StartLoc, EndLoc, CollapsedNum) {} /// Build an empty directive. /// /// \param CollapsedNum Number of collapsed nested loops. /// explicit OMPParallelForDirective(unsigned CollapsedNum) : OMPLoopDirective(OMPParallelForDirectiveClass, llvm::omp::OMPD_parallel_for, SourceLocation(), SourceLocation(), CollapsedNum) {} /// Sets special task reduction descriptor. void setTaskReductionRefExpr(Expr *E) { Data->getChildren()[numLoopChildren(getLoopsNumber(), llvm::omp::OMPD_parallel_for)] = E; } /// Set cancel state. void setHasCancel(bool Has) { HasCancel = Has; } public: /// Creates directive with a list of \a Clauses. /// /// \param C AST context. /// \param StartLoc Starting location of the directive kind. /// \param EndLoc Ending Location of the directive. /// \param CollapsedNum Number of collapsed loops. /// \param Clauses List of clauses. /// \param AssociatedStmt Statement, associated with the directive. /// \param Exprs Helper expressions for CodeGen. /// \param TaskRedRef Task reduction special reference expression to handle /// taskgroup descriptor. /// \param HasCancel true if current directive has inner cancel directive. /// static OMPParallelForDirective * Create(const ASTContext &C, SourceLocation StartLoc, SourceLocation EndLoc, unsigned CollapsedNum, ArrayRef<OMPClause *> Clauses, Stmt *AssociatedStmt, const HelperExprs &Exprs, Expr *TaskRedRef, bool HasCancel); /// Creates an empty directive with the place /// for \a NumClauses clauses. /// /// \param C AST context. /// \param CollapsedNum Number of collapsed nested loops. /// \param NumClauses Number of clauses. /// static OMPParallelForDirective *CreateEmpty(const ASTContext &C, unsigned NumClauses, unsigned CollapsedNum, EmptyShell); /// Returns special task reduction reference expression. Expr *getTaskReductionRefExpr() { return cast_or_null<Expr>(Data->getChildren()[numLoopChildren( getLoopsNumber(), llvm::omp::OMPD_parallel_for)]); } const Expr *getTaskReductionRefExpr() const { return const_cast<OMPParallelForDirective *>(this) ->getTaskReductionRefExpr(); } /// Return true if current directive has inner cancel directive. bool hasCancel() const { return HasCancel; } static bool classof(const Stmt *T) { return T->getStmtClass() == OMPParallelForDirectiveClass; } }; /// This represents '#pragma omp parallel for simd' directive. /// /// \code /// #pragma omp parallel for simd private(a,b) linear(i,j:s) reduction(+:c,d) /// \endcode /// In this example directive '#pragma omp parallel for simd' has clauses /// 'private' with the variables 'a' and 'b', 'linear' with variables 'i', 'j' /// and linear step 's', 'reduction' with operator '+' and variables 'c' and /// 'd'. /// class OMPParallelForSimdDirective : public OMPLoopDirective { friend class ASTStmtReader; friend class OMPExecutableDirective; /// Build directive with the given start and end location. /// /// \param StartLoc Starting location of the directive kind. /// \param EndLoc Ending location of the directive. /// \param CollapsedNum Number of collapsed nested loops. /// OMPParallelForSimdDirective(SourceLocation StartLoc, SourceLocation EndLoc, unsigned CollapsedNum) : OMPLoopDirective(OMPParallelForSimdDirectiveClass, llvm::omp::OMPD_parallel_for_simd, StartLoc, EndLoc, CollapsedNum) {} /// Build an empty directive. /// /// \param CollapsedNum Number of collapsed nested loops. /// explicit OMPParallelForSimdDirective(unsigned CollapsedNum) : OMPLoopDirective(OMPParallelForSimdDirectiveClass, llvm::omp::OMPD_parallel_for_simd, SourceLocation(), SourceLocation(), CollapsedNum) {} public: /// Creates directive with a list of \a Clauses. /// /// \param C AST context. /// \param StartLoc Starting location of the directive kind. /// \param EndLoc Ending Location of the directive. /// \param CollapsedNum Number of collapsed loops. /// \param Clauses List of clauses. /// \param AssociatedStmt Statement, associated with the directive. /// \param Exprs Helper expressions for CodeGen. /// static OMPParallelForSimdDirective * Create(const ASTContext &C, SourceLocation StartLoc, SourceLocation EndLoc, unsigned CollapsedNum, ArrayRef<OMPClause *> Clauses, Stmt *AssociatedStmt, const HelperExprs &Exprs); /// Creates an empty directive with the place /// for \a NumClauses clauses. /// /// \param C AST context. /// \param CollapsedNum Number of collapsed nested loops. /// \param NumClauses Number of clauses. /// static OMPParallelForSimdDirective *CreateEmpty(const ASTContext &C, unsigned NumClauses, unsigned CollapsedNum, EmptyShell); static bool classof(const Stmt *T) { return T->getStmtClass() == OMPParallelForSimdDirectiveClass; } }; /// This represents '#pragma omp parallel master' directive. /// /// \code /// #pragma omp parallel master private(a,b) /// \endcode /// In this example directive '#pragma omp parallel master' has clauses /// 'private' with the variables 'a' and 'b' /// class OMPParallelMasterDirective : public OMPExecutableDirective { friend class ASTStmtReader; friend class OMPExecutableDirective; OMPParallelMasterDirective(SourceLocation StartLoc, SourceLocation EndLoc) : OMPExecutableDirective(OMPParallelMasterDirectiveClass, llvm::omp::OMPD_parallel_master, StartLoc, EndLoc) {} explicit OMPParallelMasterDirective() : OMPExecutableDirective(OMPParallelMasterDirectiveClass, llvm::omp::OMPD_parallel_master, SourceLocation(), SourceLocation()) {} /// Sets special task reduction descriptor. void setTaskReductionRefExpr(Expr *E) { Data->getChildren()[0] = E; } public: /// Creates directive with a list of \a Clauses. /// /// \param C AST context. /// \param StartLoc Starting location of the directive kind. /// \param EndLoc Ending Location of the directive. /// \param Clauses List of clauses. /// \param AssociatedStmt Statement, associated with the directive. /// \param TaskRedRef Task reduction special reference expression to handle /// taskgroup descriptor. /// static OMPParallelMasterDirective * Create(const ASTContext &C, SourceLocation StartLoc, SourceLocation EndLoc, ArrayRef<OMPClause *> Clauses, Stmt *AssociatedStmt, Expr *TaskRedRef); /// Creates an empty directive with the place for \a NumClauses /// clauses. /// /// \param C AST context. /// \param NumClauses Number of clauses. /// static OMPParallelMasterDirective * CreateEmpty(const ASTContext &C, unsigned NumClauses, EmptyShell); /// Returns special task reduction reference expression. Expr *getTaskReductionRefExpr() { return cast_or_null<Expr>(Data->getChildren()[0]); } const Expr *getTaskReductionRefExpr() const { return const_cast<OMPParallelMasterDirective *>(this) ->getTaskReductionRefExpr(); } static bool classof(const Stmt *T) { return T->getStmtClass() == OMPParallelMasterDirectiveClass; } }; /// This represents '#pragma omp parallel sections' directive. /// /// \code /// #pragma omp parallel sections private(a,b) reduction(+:c,d) /// \endcode /// In this example directive '#pragma omp parallel sections' has clauses /// 'private' with the variables 'a' and 'b' and 'reduction' with operator '+' /// and variables 'c' and 'd'. /// class OMPParallelSectionsDirective : public OMPExecutableDirective { friend class ASTStmtReader; friend class OMPExecutableDirective; /// true if current directive has inner cancel directive. bool HasCancel = false; /// Build directive with the given start and end location. /// /// \param StartLoc Starting location of the directive kind. /// \param EndLoc Ending location of the directive. /// OMPParallelSectionsDirective(SourceLocation StartLoc, SourceLocation EndLoc) : OMPExecutableDirective(OMPParallelSectionsDirectiveClass, llvm::omp::OMPD_parallel_sections, StartLoc, EndLoc) {} /// Build an empty directive. /// explicit OMPParallelSectionsDirective() : OMPExecutableDirective(OMPParallelSectionsDirectiveClass, llvm::omp::OMPD_parallel_sections, SourceLocation(), SourceLocation()) {} /// Sets special task reduction descriptor. void setTaskReductionRefExpr(Expr *E) { Data->getChildren()[0] = E; } /// Set cancel state. void setHasCancel(bool Has) { HasCancel = Has; } public: /// Creates directive with a list of \a Clauses. /// /// \param C AST context. /// \param StartLoc Starting location of the directive kind. /// \param EndLoc Ending Location of the directive. /// \param Clauses List of clauses. /// \param AssociatedStmt Statement, associated with the directive. /// \param TaskRedRef Task reduction special reference expression to handle /// taskgroup descriptor. /// \param HasCancel true if current directive has inner cancel directive. /// static OMPParallelSectionsDirective * Create(const ASTContext &C, SourceLocation StartLoc, SourceLocation EndLoc, ArrayRef<OMPClause *> Clauses, Stmt *AssociatedStmt, Expr *TaskRedRef, bool HasCancel); /// Creates an empty directive with the place for \a NumClauses /// clauses. /// /// \param C AST context. /// \param NumClauses Number of clauses. /// static OMPParallelSectionsDirective * CreateEmpty(const ASTContext &C, unsigned NumClauses, EmptyShell); /// Returns special task reduction reference expression. Expr *getTaskReductionRefExpr() { return cast_or_null<Expr>(Data->getChildren()[0]); } const Expr *getTaskReductionRefExpr() const { return const_cast<OMPParallelSectionsDirective *>(this) ->getTaskReductionRefExpr(); } /// Return true if current directive has inner cancel directive. bool hasCancel() const { return HasCancel; } static bool classof(const Stmt *T) { return T->getStmtClass() == OMPParallelSectionsDirectiveClass; } }; /// This represents '#pragma omp task' directive. /// /// \code /// #pragma omp task private(a,b) final(d) /// \endcode /// In this example directive '#pragma omp task' has clauses 'private' with the /// variables 'a' and 'b' and 'final' with condition 'd'. /// class OMPTaskDirective : public OMPExecutableDirective { friend class ASTStmtReader; friend class OMPExecutableDirective; /// true if this directive has inner cancel directive. bool HasCancel = false; /// Build directive with the given start and end location. /// /// \param StartLoc Starting location of the directive kind. /// \param EndLoc Ending location of the directive. /// OMPTaskDirective(SourceLocation StartLoc, SourceLocation EndLoc) : OMPExecutableDirective(OMPTaskDirectiveClass, llvm::omp::OMPD_task, StartLoc, EndLoc) {} /// Build an empty directive. /// explicit OMPTaskDirective() : OMPExecutableDirective(OMPTaskDirectiveClass, llvm::omp::OMPD_task, SourceLocation(), SourceLocation()) {} /// Set cancel state. void setHasCancel(bool Has) { HasCancel = Has; } public: /// Creates directive with a list of \a Clauses. /// /// \param C AST context. /// \param StartLoc Starting location of the directive kind. /// \param EndLoc Ending Location of the directive. /// \param Clauses List of clauses. /// \param AssociatedStmt Statement, associated with the directive. /// \param HasCancel true, if current directive has inner cancel directive. /// static OMPTaskDirective *Create(const ASTContext &C, SourceLocation StartLoc, SourceLocation EndLoc, ArrayRef<OMPClause *> Clauses, Stmt *AssociatedStmt, bool HasCancel); /// Creates an empty directive with the place for \a NumClauses /// clauses. /// /// \param C AST context. /// \param NumClauses Number of clauses. /// static OMPTaskDirective *CreateEmpty(const ASTContext &C, unsigned NumClauses, EmptyShell); /// Return true if current directive has inner cancel directive. bool hasCancel() const { return HasCancel; } static bool classof(const Stmt *T) { return T->getStmtClass() == OMPTaskDirectiveClass; } }; /// This represents '#pragma omp taskyield' directive. /// /// \code /// #pragma omp taskyield /// \endcode /// class OMPTaskyieldDirective : public OMPExecutableDirective { friend class ASTStmtReader; friend class OMPExecutableDirective; /// Build directive with the given start and end location. /// /// \param StartLoc Starting location of the directive kind. /// \param EndLoc Ending location of the directive. /// OMPTaskyieldDirective(SourceLocation StartLoc, SourceLocation EndLoc) : OMPExecutableDirective(OMPTaskyieldDirectiveClass, llvm::omp::OMPD_taskyield, StartLoc, EndLoc) {} /// Build an empty directive. /// explicit OMPTaskyieldDirective() : OMPExecutableDirective(OMPTaskyieldDirectiveClass, llvm::omp::OMPD_taskyield, SourceLocation(), SourceLocation()) {} public: /// Creates directive. /// /// \param C AST context. /// \param StartLoc Starting location of the directive kind. /// \param EndLoc Ending Location of the directive. /// static OMPTaskyieldDirective * Create(const ASTContext &C, SourceLocation StartLoc, SourceLocation EndLoc); /// Creates an empty directive. /// /// \param C AST context. /// static OMPTaskyieldDirective *CreateEmpty(const ASTContext &C, EmptyShell); static bool classof(const Stmt *T) { return T->getStmtClass() == OMPTaskyieldDirectiveClass; } }; /// This represents '#pragma omp barrier' directive. /// /// \code /// #pragma omp barrier /// \endcode /// class OMPBarrierDirective : public OMPExecutableDirective { friend class ASTStmtReader; friend class OMPExecutableDirective; /// Build directive with the given start and end location. /// /// \param StartLoc Starting location of the directive kind. /// \param EndLoc Ending location of the directive. /// OMPBarrierDirective(SourceLocation StartLoc, SourceLocation EndLoc) : OMPExecutableDirective(OMPBarrierDirectiveClass, llvm::omp::OMPD_barrier, StartLoc, EndLoc) {} /// Build an empty directive. /// explicit OMPBarrierDirective() : OMPExecutableDirective(OMPBarrierDirectiveClass, llvm::omp::OMPD_barrier, SourceLocation(), SourceLocation()) {} public: /// Creates directive. /// /// \param C AST context. /// \param StartLoc Starting location of the directive kind. /// \param EndLoc Ending Location of the directive. /// static OMPBarrierDirective * Create(const ASTContext &C, SourceLocation StartLoc, SourceLocation EndLoc); /// Creates an empty directive. /// /// \param C AST context. /// static OMPBarrierDirective *CreateEmpty(const ASTContext &C, EmptyShell); static bool classof(const Stmt *T) { return T->getStmtClass() == OMPBarrierDirectiveClass; } }; /// This represents '#pragma omp taskwait' directive. /// /// \code /// #pragma omp taskwait /// \endcode /// class OMPTaskwaitDirective : public OMPExecutableDirective { friend class ASTStmtReader; friend class OMPExecutableDirective; /// Build directive with the given start and end location. /// /// \param StartLoc Starting location of the directive kind. /// \param EndLoc Ending location of the directive. /// OMPTaskwaitDirective(SourceLocation StartLoc, SourceLocation EndLoc) : OMPExecutableDirective(OMPTaskwaitDirectiveClass, llvm::omp::OMPD_taskwait, StartLoc, EndLoc) {} /// Build an empty directive. /// explicit OMPTaskwaitDirective() : OMPExecutableDirective(OMPTaskwaitDirectiveClass, llvm::omp::OMPD_taskwait, SourceLocation(), SourceLocation()) {} public: /// Creates directive. /// /// \param C AST context. /// \param StartLoc Starting location of the directive kind. /// \param EndLoc Ending Location of the directive. /// static OMPTaskwaitDirective * Create(const ASTContext &C, SourceLocation StartLoc, SourceLocation EndLoc); /// Creates an empty directive. /// /// \param C AST context. /// static OMPTaskwaitDirective *CreateEmpty(const ASTContext &C, EmptyShell); static bool classof(const Stmt *T) { return T->getStmtClass() == OMPTaskwaitDirectiveClass; } }; /// This represents '#pragma omp taskgroup' directive. /// /// \code /// #pragma omp taskgroup /// \endcode /// class OMPTaskgroupDirective : public OMPExecutableDirective { friend class ASTStmtReader; friend class OMPExecutableDirective; /// Build directive with the given start and end location. /// /// \param StartLoc Starting location of the directive kind. /// \param EndLoc Ending location of the directive. /// OMPTaskgroupDirective(SourceLocation StartLoc, SourceLocation EndLoc) : OMPExecutableDirective(OMPTaskgroupDirectiveClass, llvm::omp::OMPD_taskgroup, StartLoc, EndLoc) {} /// Build an empty directive. /// explicit OMPTaskgroupDirective() : OMPExecutableDirective(OMPTaskgroupDirectiveClass, llvm::omp::OMPD_taskgroup, SourceLocation(), SourceLocation()) {} /// Sets the task_reduction return variable. void setReductionRef(Expr *RR) { Data->getChildren()[0] = RR; } public: /// Creates directive. /// /// \param C AST context. /// \param StartLoc Starting location of the directive kind. /// \param EndLoc Ending Location of the directive. /// \param Clauses List of clauses. /// \param AssociatedStmt Statement, associated with the directive. /// \param ReductionRef Reference to the task_reduction return variable. /// static OMPTaskgroupDirective * Create(const ASTContext &C, SourceLocation StartLoc, SourceLocation EndLoc, ArrayRef<OMPClause *> Clauses, Stmt *AssociatedStmt, Expr *ReductionRef); /// Creates an empty directive. /// /// \param C AST context. /// \param NumClauses Number of clauses. /// static OMPTaskgroupDirective *CreateEmpty(const ASTContext &C, unsigned NumClauses, EmptyShell); /// Returns reference to the task_reduction return variable. const Expr *getReductionRef() const { return const_cast<OMPTaskgroupDirective *>(this)->getReductionRef(); } Expr *getReductionRef() { return cast_or_null<Expr>(Data->getChildren()[0]); } static bool classof(const Stmt *T) { return T->getStmtClass() == OMPTaskgroupDirectiveClass; } }; /// This represents '#pragma omp flush' directive. /// /// \code /// #pragma omp flush(a,b) /// \endcode /// In this example directive '#pragma omp flush' has 2 arguments- variables 'a' /// and 'b'. /// 'omp flush' directive does not have clauses but have an optional list of /// variables to flush. This list of variables is stored within some fake clause /// FlushClause. class OMPFlushDirective : public OMPExecutableDirective { friend class ASTStmtReader; friend class OMPExecutableDirective; /// Build directive with the given start and end location. /// /// \param StartLoc Starting location of the directive kind. /// \param EndLoc Ending location of the directive. /// OMPFlushDirective(SourceLocation StartLoc, SourceLocation EndLoc) : OMPExecutableDirective(OMPFlushDirectiveClass, llvm::omp::OMPD_flush, StartLoc, EndLoc) {} /// Build an empty directive. /// explicit OMPFlushDirective() : OMPExecutableDirective(OMPFlushDirectiveClass, llvm::omp::OMPD_flush, SourceLocation(), SourceLocation()) {} public: /// Creates directive with a list of \a Clauses. /// /// \param C AST context. /// \param StartLoc Starting location of the directive kind. /// \param EndLoc Ending Location of the directive. /// \param Clauses List of clauses (only single OMPFlushClause clause is /// allowed). /// static OMPFlushDirective *Create(const ASTContext &C, SourceLocation StartLoc, SourceLocation EndLoc, ArrayRef<OMPClause *> Clauses); /// Creates an empty directive with the place for \a NumClauses /// clauses. /// /// \param C AST context. /// \param NumClauses Number of clauses. /// static OMPFlushDirective *CreateEmpty(const ASTContext &C, unsigned NumClauses, EmptyShell); static bool classof(const Stmt *T) { return T->getStmtClass() == OMPFlushDirectiveClass; } }; /// This represents '#pragma omp depobj' directive. /// /// \code /// #pragma omp depobj(a) depend(in:x,y) /// \endcode /// In this example directive '#pragma omp depobj' initializes a depobj object /// 'a' with dependence type 'in' and a list with 'x' and 'y' locators. class OMPDepobjDirective final : public OMPExecutableDirective { friend class ASTStmtReader; friend class OMPExecutableDirective; /// Build directive with the given start and end location. /// /// \param StartLoc Starting location of the directive kind. /// \param EndLoc Ending location of the directive. /// OMPDepobjDirective(SourceLocation StartLoc, SourceLocation EndLoc) : OMPExecutableDirective(OMPDepobjDirectiveClass, llvm::omp::OMPD_depobj, StartLoc, EndLoc) {} /// Build an empty directive. /// explicit OMPDepobjDirective() : OMPExecutableDirective(OMPDepobjDirectiveClass, llvm::omp::OMPD_depobj, SourceLocation(), SourceLocation()) {} public: /// Creates directive with a list of \a Clauses. /// /// \param C AST context. /// \param StartLoc Starting location of the directive kind. /// \param EndLoc Ending Location of the directive. /// \param Clauses List of clauses. /// static OMPDepobjDirective *Create(const ASTContext &C, SourceLocation StartLoc, SourceLocation EndLoc, ArrayRef<OMPClause *> Clauses); /// Creates an empty directive with the place for \a NumClauses /// clauses. /// /// \param C AST context. /// \param NumClauses Number of clauses. /// static OMPDepobjDirective *CreateEmpty(const ASTContext &C, unsigned NumClauses, EmptyShell); static bool classof(const Stmt *T) { return T->getStmtClass() == OMPDepobjDirectiveClass; } }; /// This represents '#pragma omp ordered' directive. /// /// \code /// #pragma omp ordered /// \endcode /// class OMPOrderedDirective : public OMPExecutableDirective { friend class ASTStmtReader; friend class OMPExecutableDirective; /// Build directive with the given start and end location. /// /// \param StartLoc Starting location of the directive kind. /// \param EndLoc Ending location of the directive. /// OMPOrderedDirective(SourceLocation StartLoc, SourceLocation EndLoc) : OMPExecutableDirective(OMPOrderedDirectiveClass, llvm::omp::OMPD_ordered, StartLoc, EndLoc) {} /// Build an empty directive. /// explicit OMPOrderedDirective() : OMPExecutableDirective(OMPOrderedDirectiveClass, llvm::omp::OMPD_ordered, SourceLocation(), SourceLocation()) {} public: /// Creates directive. /// /// \param C AST context. /// \param StartLoc Starting location of the directive kind. /// \param EndLoc Ending Location of the directive. /// \param Clauses List of clauses. /// \param AssociatedStmt Statement, associated with the directive. /// static OMPOrderedDirective * Create(const ASTContext &C, SourceLocation StartLoc, SourceLocation EndLoc, ArrayRef<OMPClause *> Clauses, Stmt *AssociatedStmt); /// Creates an empty directive. /// /// \param C AST context. /// \param NumClauses Number of clauses. /// \param IsStandalone true, if the the standalone directive is created. /// static OMPOrderedDirective *CreateEmpty(const ASTContext &C, unsigned NumClauses, bool IsStandalone, EmptyShell); static bool classof(const Stmt *T) { return T->getStmtClass() == OMPOrderedDirectiveClass; } }; /// This represents '#pragma omp atomic' directive. /// /// \code /// #pragma omp atomic capture /// \endcode /// In this example directive '#pragma omp atomic' has clause 'capture'. /// class OMPAtomicDirective : public OMPExecutableDirective { friend class ASTStmtReader; friend class OMPExecutableDirective; /// Used for 'atomic update' or 'atomic capture' constructs. They may /// have atomic expressions of forms /// \code /// x = x binop expr; /// x = expr binop x; /// \endcode /// This field is true for the first form of the expression and false for the /// second. Required for correct codegen of non-associative operations (like /// << or >>). bool IsXLHSInRHSPart = false; /// Used for 'atomic update' or 'atomic capture' constructs. They may /// have atomic expressions of forms /// \code /// v = x; <update x>; /// <update x>; v = x; /// \endcode /// This field is true for the first(postfix) form of the expression and false /// otherwise. bool IsPostfixUpdate = false; /// Build directive with the given start and end location. /// /// \param StartLoc Starting location of the directive kind. /// \param EndLoc Ending location of the directive. /// OMPAtomicDirective(SourceLocation StartLoc, SourceLocation EndLoc) : OMPExecutableDirective(OMPAtomicDirectiveClass, llvm::omp::OMPD_atomic, StartLoc, EndLoc) {} /// Build an empty directive. /// explicit OMPAtomicDirective() : OMPExecutableDirective(OMPAtomicDirectiveClass, llvm::omp::OMPD_atomic, SourceLocation(), SourceLocation()) {} /// Set 'x' part of the associated expression/statement. void setX(Expr *X) { Data->getChildren()[0] = X; } /// Set helper expression of the form /// 'OpaqueValueExpr(x) binop OpaqueValueExpr(expr)' or /// 'OpaqueValueExpr(expr) binop OpaqueValueExpr(x)'. void setUpdateExpr(Expr *UE) { Data->getChildren()[1] = UE; } /// Set 'v' part of the associated expression/statement. void setV(Expr *V) { Data->getChildren()[2] = V; } /// Set 'expr' part of the associated expression/statement. void setExpr(Expr *E) { Data->getChildren()[3] = E; } public: /// Creates directive with a list of \a Clauses and 'x', 'v' and 'expr' /// parts of the atomic construct (see Section 2.12.6, atomic Construct, for /// detailed description of 'x', 'v' and 'expr'). /// /// \param C AST context. /// \param StartLoc Starting location of the directive kind. /// \param EndLoc Ending Location of the directive. /// \param Clauses List of clauses. /// \param AssociatedStmt Statement, associated with the directive. /// \param X 'x' part of the associated expression/statement. /// \param V 'v' part of the associated expression/statement. /// \param E 'expr' part of the associated expression/statement. /// \param UE Helper expression of the form /// 'OpaqueValueExpr(x) binop OpaqueValueExpr(expr)' or /// 'OpaqueValueExpr(expr) binop OpaqueValueExpr(x)'. /// \param IsXLHSInRHSPart true if \a UE has the first form and false if the /// second. /// \param IsPostfixUpdate true if original value of 'x' must be stored in /// 'v', not an updated one. static OMPAtomicDirective * Create(const ASTContext &C, SourceLocation StartLoc, SourceLocation EndLoc, ArrayRef<OMPClause *> Clauses, Stmt *AssociatedStmt, Expr *X, Expr *V, Expr *E, Expr *UE, bool IsXLHSInRHSPart, bool IsPostfixUpdate); /// Creates an empty directive with the place for \a NumClauses /// clauses. /// /// \param C AST context. /// \param NumClauses Number of clauses. /// static OMPAtomicDirective *CreateEmpty(const ASTContext &C, unsigned NumClauses, EmptyShell); /// Get 'x' part of the associated expression/statement. Expr *getX() { return cast_or_null<Expr>(Data->getChildren()[0]); } const Expr *getX() const { return cast_or_null<Expr>(Data->getChildren()[0]); } /// Get helper expression of the form /// 'OpaqueValueExpr(x) binop OpaqueValueExpr(expr)' or /// 'OpaqueValueExpr(expr) binop OpaqueValueExpr(x)'. Expr *getUpdateExpr() { return cast_or_null<Expr>(Data->getChildren()[1]); } const Expr *getUpdateExpr() const { return cast_or_null<Expr>(Data->getChildren()[1]); } /// Return true if helper update expression has form /// 'OpaqueValueExpr(x) binop OpaqueValueExpr(expr)' and false if it has form /// 'OpaqueValueExpr(expr) binop OpaqueValueExpr(x)'. bool isXLHSInRHSPart() const { return IsXLHSInRHSPart; } /// Return true if 'v' expression must be updated to original value of /// 'x', false if 'v' must be updated to the new value of 'x'. bool isPostfixUpdate() const { return IsPostfixUpdate; } /// Get 'v' part of the associated expression/statement. Expr *getV() { return cast_or_null<Expr>(Data->getChildren()[2]); } const Expr *getV() const { return cast_or_null<Expr>(Data->getChildren()[2]); } /// Get 'expr' part of the associated expression/statement. Expr *getExpr() { return cast_or_null<Expr>(Data->getChildren()[3]); } const Expr *getExpr() const { return cast_or_null<Expr>(Data->getChildren()[3]); } static bool classof(const Stmt *T) { return T->getStmtClass() == OMPAtomicDirectiveClass; } }; /// This represents '#pragma omp target' directive. /// /// \code /// #pragma omp target if(a) /// \endcode /// In this example directive '#pragma omp target' has clause 'if' with /// condition 'a'. /// class OMPTargetDirective : public OMPExecutableDirective { friend class ASTStmtReader; friend class OMPExecutableDirective; /// Build directive with the given start and end location. /// /// \param StartLoc Starting location of the directive kind. /// \param EndLoc Ending location of the directive. /// OMPTargetDirective(SourceLocation StartLoc, SourceLocation EndLoc) : OMPExecutableDirective(OMPTargetDirectiveClass, llvm::omp::OMPD_target, StartLoc, EndLoc) {} /// Build an empty directive. /// explicit OMPTargetDirective() : OMPExecutableDirective(OMPTargetDirectiveClass, llvm::omp::OMPD_target, SourceLocation(), SourceLocation()) {} public: /// Creates directive with a list of \a Clauses. /// /// \param C AST context. /// \param StartLoc Starting location of the directive kind. /// \param EndLoc Ending Location of the directive. /// \param Clauses List of clauses. /// \param AssociatedStmt Statement, associated with the directive. /// static OMPTargetDirective * Create(const ASTContext &C, SourceLocation StartLoc, SourceLocation EndLoc, ArrayRef<OMPClause *> Clauses, Stmt *AssociatedStmt); /// Creates an empty directive with the place for \a NumClauses /// clauses. /// /// \param C AST context. /// \param NumClauses Number of clauses. /// static OMPTargetDirective *CreateEmpty(const ASTContext &C, unsigned NumClauses, EmptyShell); static bool classof(const Stmt *T) { return T->getStmtClass() == OMPTargetDirectiveClass; } }; /// This represents '#pragma omp target data' directive. /// /// \code /// #pragma omp target data device(0) if(a) map(b[:]) /// \endcode /// In this example directive '#pragma omp target data' has clauses 'device' /// with the value '0', 'if' with condition 'a' and 'map' with array /// section 'b[:]'. /// class OMPTargetDataDirective : public OMPExecutableDirective { friend class ASTStmtReader; friend class OMPExecutableDirective; /// Build directive with the given start and end location. /// /// \param StartLoc Starting location of the directive kind. /// \param EndLoc Ending Location of the directive. /// OMPTargetDataDirective(SourceLocation StartLoc, SourceLocation EndLoc) : OMPExecutableDirective(OMPTargetDataDirectiveClass, llvm::omp::OMPD_target_data, StartLoc, EndLoc) {} /// Build an empty directive. /// explicit OMPTargetDataDirective() : OMPExecutableDirective(OMPTargetDataDirectiveClass, llvm::omp::OMPD_target_data, SourceLocation(), SourceLocation()) {} public: /// Creates directive with a list of \a Clauses. /// /// \param C AST context. /// \param StartLoc Starting location of the directive kind. /// \param EndLoc Ending Location of the directive. /// \param Clauses List of clauses. /// \param AssociatedStmt Statement, associated with the directive. /// static OMPTargetDataDirective * Create(const ASTContext &C, SourceLocation StartLoc, SourceLocation EndLoc, ArrayRef<OMPClause *> Clauses, Stmt *AssociatedStmt); /// Creates an empty directive with the place for \a N clauses. /// /// \param C AST context. /// \param N The number of clauses. /// static OMPTargetDataDirective *CreateEmpty(const ASTContext &C, unsigned N, EmptyShell); static bool classof(const Stmt *T) { return T->getStmtClass() == OMPTargetDataDirectiveClass; } }; /// This represents '#pragma omp target enter data' directive. /// /// \code /// #pragma omp target enter data device(0) if(a) map(b[:]) /// \endcode /// In this example directive '#pragma omp target enter data' has clauses /// 'device' with the value '0', 'if' with condition 'a' and 'map' with array /// section 'b[:]'. /// class OMPTargetEnterDataDirective : public OMPExecutableDirective { friend class ASTStmtReader; friend class OMPExecutableDirective; /// Build directive with the given start and end location. /// /// \param StartLoc Starting location of the directive kind. /// \param EndLoc Ending Location of the directive. /// OMPTargetEnterDataDirective(SourceLocation StartLoc, SourceLocation EndLoc) : OMPExecutableDirective(OMPTargetEnterDataDirectiveClass, llvm::omp::OMPD_target_enter_data, StartLoc, EndLoc) {} /// Build an empty directive. /// explicit OMPTargetEnterDataDirective() : OMPExecutableDirective(OMPTargetEnterDataDirectiveClass, llvm::omp::OMPD_target_enter_data, SourceLocation(), SourceLocation()) {} public: /// Creates directive with a list of \a Clauses. /// /// \param C AST context. /// \param StartLoc Starting location of the directive kind. /// \param EndLoc Ending Location of the directive. /// \param Clauses List of clauses. /// \param AssociatedStmt Statement, associated with the directive. /// static OMPTargetEnterDataDirective * Create(const ASTContext &C, SourceLocation StartLoc, SourceLocation EndLoc, ArrayRef<OMPClause *> Clauses, Stmt *AssociatedStmt); /// Creates an empty directive with the place for \a N clauses. /// /// \param C AST context. /// \param N The number of clauses. /// static OMPTargetEnterDataDirective *CreateEmpty(const ASTContext &C, unsigned N, EmptyShell); static bool classof(const Stmt *T) { return T->getStmtClass() == OMPTargetEnterDataDirectiveClass; } }; /// This represents '#pragma omp target exit data' directive. /// /// \code /// #pragma omp target exit data device(0) if(a) map(b[:]) /// \endcode /// In this example directive '#pragma omp target exit data' has clauses /// 'device' with the value '0', 'if' with condition 'a' and 'map' with array /// section 'b[:]'. /// class OMPTargetExitDataDirective : public OMPExecutableDirective { friend class ASTStmtReader; friend class OMPExecutableDirective; /// Build directive with the given start and end location. /// /// \param StartLoc Starting location of the directive kind. /// \param EndLoc Ending Location of the directive. /// OMPTargetExitDataDirective(SourceLocation StartLoc, SourceLocation EndLoc) : OMPExecutableDirective(OMPTargetExitDataDirectiveClass, llvm::omp::OMPD_target_exit_data, StartLoc, EndLoc) {} /// Build an empty directive. /// explicit OMPTargetExitDataDirective() : OMPExecutableDirective(OMPTargetExitDataDirectiveClass, llvm::omp::OMPD_target_exit_data, SourceLocation(), SourceLocation()) {} public: /// Creates directive with a list of \a Clauses. /// /// \param C AST context. /// \param StartLoc Starting location of the directive kind. /// \param EndLoc Ending Location of the directive. /// \param Clauses List of clauses. /// \param AssociatedStmt Statement, associated with the directive. /// static OMPTargetExitDataDirective * Create(const ASTContext &C, SourceLocation StartLoc, SourceLocation EndLoc, ArrayRef<OMPClause *> Clauses, Stmt *AssociatedStmt); /// Creates an empty directive with the place for \a N clauses. /// /// \param C AST context. /// \param N The number of clauses. /// static OMPTargetExitDataDirective *CreateEmpty(const ASTContext &C, unsigned N, EmptyShell); static bool classof(const Stmt *T) { return T->getStmtClass() == OMPTargetExitDataDirectiveClass; } }; /// This represents '#pragma omp target parallel' directive. /// /// \code /// #pragma omp target parallel if(a) /// \endcode /// In this example directive '#pragma omp target parallel' has clause 'if' with /// condition 'a'. /// class OMPTargetParallelDirective : public OMPExecutableDirective { friend class ASTStmtReader; friend class OMPExecutableDirective; /// true if the construct has inner cancel directive. bool HasCancel = false; /// Build directive with the given start and end location. /// /// \param StartLoc Starting location of the directive kind. /// \param EndLoc Ending location of the directive. /// OMPTargetParallelDirective(SourceLocation StartLoc, SourceLocation EndLoc) : OMPExecutableDirective(OMPTargetParallelDirectiveClass, llvm::omp::OMPD_target_parallel, StartLoc, EndLoc) {} /// Build an empty directive. /// explicit OMPTargetParallelDirective() : OMPExecutableDirective(OMPTargetParallelDirectiveClass, llvm::omp::OMPD_target_parallel, SourceLocation(), SourceLocation()) {} /// Sets special task reduction descriptor. void setTaskReductionRefExpr(Expr *E) { Data->getChildren()[0] = E; } /// Set cancel state. void setHasCancel(bool Has) { HasCancel = Has; } public: /// Creates directive with a list of \a Clauses. /// /// \param C AST context. /// \param StartLoc Starting location of the directive kind. /// \param EndLoc Ending Location of the directive. /// \param Clauses List of clauses. /// \param AssociatedStmt Statement, associated with the directive. /// \param TaskRedRef Task reduction special reference expression to handle /// taskgroup descriptor. /// \param HasCancel true if this directive has inner cancel directive. /// static OMPTargetParallelDirective * Create(const ASTContext &C, SourceLocation StartLoc, SourceLocation EndLoc, ArrayRef<OMPClause *> Clauses, Stmt *AssociatedStmt, Expr *TaskRedRef, bool HasCancel); /// Creates an empty directive with the place for \a NumClauses /// clauses. /// /// \param C AST context. /// \param NumClauses Number of clauses. /// static OMPTargetParallelDirective * CreateEmpty(const ASTContext &C, unsigned NumClauses, EmptyShell); /// Returns special task reduction reference expression. Expr *getTaskReductionRefExpr() { return cast_or_null<Expr>(Data->getChildren()[0]); } const Expr *getTaskReductionRefExpr() const { return const_cast<OMPTargetParallelDirective *>(this) ->getTaskReductionRefExpr(); } /// Return true if current directive has inner cancel directive. bool hasCancel() const { return HasCancel; } static bool classof(const Stmt *T) { return T->getStmtClass() == OMPTargetParallelDirectiveClass; } }; /// This represents '#pragma omp target parallel for' directive. /// /// \code /// #pragma omp target parallel for private(a,b) reduction(+:c,d) /// \endcode /// In this example directive '#pragma omp target parallel for' has clauses /// 'private' with the variables 'a' and 'b' and 'reduction' with operator '+' /// and variables 'c' and 'd'. /// class OMPTargetParallelForDirective : public OMPLoopDirective { friend class ASTStmtReader; friend class OMPExecutableDirective; /// true if current region has inner cancel directive. bool HasCancel = false; /// Build directive with the given start and end location. /// /// \param StartLoc Starting location of the directive kind. /// \param EndLoc Ending location of the directive. /// \param CollapsedNum Number of collapsed nested loops. /// OMPTargetParallelForDirective(SourceLocation StartLoc, SourceLocation EndLoc, unsigned CollapsedNum) : OMPLoopDirective(OMPTargetParallelForDirectiveClass, llvm::omp::OMPD_target_parallel_for, StartLoc, EndLoc, CollapsedNum) {} /// Build an empty directive. /// /// \param CollapsedNum Number of collapsed nested loops. /// explicit OMPTargetParallelForDirective(unsigned CollapsedNum) : OMPLoopDirective(OMPTargetParallelForDirectiveClass, llvm::omp::OMPD_target_parallel_for, SourceLocation(), SourceLocation(), CollapsedNum) {} /// Sets special task reduction descriptor. void setTaskReductionRefExpr(Expr *E) { Data->getChildren()[numLoopChildren( getLoopsNumber(), llvm::omp::OMPD_target_parallel_for)] = E; } /// Set cancel state. void setHasCancel(bool Has) { HasCancel = Has; } public: /// Creates directive with a list of \a Clauses. /// /// \param C AST context. /// \param StartLoc Starting location of the directive kind. /// \param EndLoc Ending Location of the directive. /// \param CollapsedNum Number of collapsed loops. /// \param Clauses List of clauses. /// \param AssociatedStmt Statement, associated with the directive. /// \param Exprs Helper expressions for CodeGen. /// \param TaskRedRef Task reduction special reference expression to handle /// taskgroup descriptor. /// \param HasCancel true if current directive has inner cancel directive. /// static OMPTargetParallelForDirective * Create(const ASTContext &C, SourceLocation StartLoc, SourceLocation EndLoc, unsigned CollapsedNum, ArrayRef<OMPClause *> Clauses, Stmt *AssociatedStmt, const HelperExprs &Exprs, Expr *TaskRedRef, bool HasCancel); /// Creates an empty directive with the place /// for \a NumClauses clauses. /// /// \param C AST context. /// \param CollapsedNum Number of collapsed nested loops. /// \param NumClauses Number of clauses. /// static OMPTargetParallelForDirective *CreateEmpty(const ASTContext &C, unsigned NumClauses, unsigned CollapsedNum, EmptyShell); /// Returns special task reduction reference expression. Expr *getTaskReductionRefExpr() { return cast_or_null<Expr>(Data->getChildren()[numLoopChildren( getLoopsNumber(), llvm::omp::OMPD_target_parallel_for)]); } const Expr *getTaskReductionRefExpr() const { return const_cast<OMPTargetParallelForDirective *>(this) ->getTaskReductionRefExpr(); } /// Return true if current directive has inner cancel directive. bool hasCancel() const { return HasCancel; } static bool classof(const Stmt *T) { return T->getStmtClass() == OMPTargetParallelForDirectiveClass; } }; /// This represents '#pragma omp teams' directive. /// /// \code /// #pragma omp teams if(a) /// \endcode /// In this example directive '#pragma omp teams' has clause 'if' with /// condition 'a'. /// class OMPTeamsDirective : public OMPExecutableDirective { friend class ASTStmtReader; friend class OMPExecutableDirective; /// Build directive with the given start and end location. /// /// \param StartLoc Starting location of the directive kind. /// \param EndLoc Ending location of the directive. /// OMPTeamsDirective(SourceLocation StartLoc, SourceLocation EndLoc) : OMPExecutableDirective(OMPTeamsDirectiveClass, llvm::omp::OMPD_teams, StartLoc, EndLoc) {} /// Build an empty directive. /// explicit OMPTeamsDirective() : OMPExecutableDirective(OMPTeamsDirectiveClass, llvm::omp::OMPD_teams, SourceLocation(), SourceLocation()) {} public: /// Creates directive with a list of \a Clauses. /// /// \param C AST context. /// \param StartLoc Starting location of the directive kind. /// \param EndLoc Ending Location of the directive. /// \param Clauses List of clauses. /// \param AssociatedStmt Statement, associated with the directive. /// static OMPTeamsDirective *Create(const ASTContext &C, SourceLocation StartLoc, SourceLocation EndLoc, ArrayRef<OMPClause *> Clauses, Stmt *AssociatedStmt); /// Creates an empty directive with the place for \a NumClauses /// clauses. /// /// \param C AST context. /// \param NumClauses Number of clauses. /// static OMPTeamsDirective *CreateEmpty(const ASTContext &C, unsigned NumClauses, EmptyShell); static bool classof(const Stmt *T) { return T->getStmtClass() == OMPTeamsDirectiveClass; } }; /// This represents '#pragma omp cancellation point' directive. /// /// \code /// #pragma omp cancellation point for /// \endcode /// /// In this example a cancellation point is created for innermost 'for' region. class OMPCancellationPointDirective : public OMPExecutableDirective { friend class ASTStmtReader; friend class OMPExecutableDirective; OpenMPDirectiveKind CancelRegion = llvm::omp::OMPD_unknown; /// Build directive with the given start and end location. /// /// \param StartLoc Starting location of the directive kind. /// \param EndLoc Ending location of the directive. /// statements and child expressions. /// OMPCancellationPointDirective(SourceLocation StartLoc, SourceLocation EndLoc) : OMPExecutableDirective(OMPCancellationPointDirectiveClass, llvm::omp::OMPD_cancellation_point, StartLoc, EndLoc) {} /// Build an empty directive. explicit OMPCancellationPointDirective() : OMPExecutableDirective(OMPCancellationPointDirectiveClass, llvm::omp::OMPD_cancellation_point, SourceLocation(), SourceLocation()) {} /// Set cancel region for current cancellation point. /// \param CR Cancellation region. void setCancelRegion(OpenMPDirectiveKind CR) { CancelRegion = CR; } public: /// Creates directive. /// /// \param C AST context. /// \param StartLoc Starting location of the directive kind. /// \param EndLoc Ending Location of the directive. /// static OMPCancellationPointDirective * Create(const ASTContext &C, SourceLocation StartLoc, SourceLocation EndLoc, OpenMPDirectiveKind CancelRegion); /// Creates an empty directive. /// /// \param C AST context. /// static OMPCancellationPointDirective *CreateEmpty(const ASTContext &C, EmptyShell); /// Get cancellation region for the current cancellation point. OpenMPDirectiveKind getCancelRegion() const { return CancelRegion; } static bool classof(const Stmt *T) { return T->getStmtClass() == OMPCancellationPointDirectiveClass; } }; /// This represents '#pragma omp cancel' directive. /// /// \code /// #pragma omp cancel for /// \endcode /// /// In this example a cancel is created for innermost 'for' region. class OMPCancelDirective : public OMPExecutableDirective { friend class ASTStmtReader; friend class OMPExecutableDirective; OpenMPDirectiveKind CancelRegion = llvm::omp::OMPD_unknown; /// Build directive with the given start and end location. /// /// \param StartLoc Starting location of the directive kind. /// \param EndLoc Ending location of the directive. /// OMPCancelDirective(SourceLocation StartLoc, SourceLocation EndLoc) : OMPExecutableDirective(OMPCancelDirectiveClass, llvm::omp::OMPD_cancel, StartLoc, EndLoc) {} /// Build an empty directive. /// explicit OMPCancelDirective() : OMPExecutableDirective(OMPCancelDirectiveClass, llvm::omp::OMPD_cancel, SourceLocation(), SourceLocation()) {} /// Set cancel region for current cancellation point. /// \param CR Cancellation region. void setCancelRegion(OpenMPDirectiveKind CR) { CancelRegion = CR; } public: /// Creates directive. /// /// \param C AST context. /// \param StartLoc Starting location of the directive kind. /// \param EndLoc Ending Location of the directive. /// \param Clauses List of clauses. /// static OMPCancelDirective * Create(const ASTContext &C, SourceLocation StartLoc, SourceLocation EndLoc, ArrayRef<OMPClause *> Clauses, OpenMPDirectiveKind CancelRegion); /// Creates an empty directive. /// /// \param C AST context. /// \param NumClauses Number of clauses. /// static OMPCancelDirective *CreateEmpty(const ASTContext &C, unsigned NumClauses, EmptyShell); /// Get cancellation region for the current cancellation point. OpenMPDirectiveKind getCancelRegion() const { return CancelRegion; } static bool classof(const Stmt *T) { return T->getStmtClass() == OMPCancelDirectiveClass; } }; /// This represents '#pragma omp taskloop' directive. /// /// \code /// #pragma omp taskloop private(a,b) grainsize(val) num_tasks(num) /// \endcode /// In this example directive '#pragma omp taskloop' has clauses 'private' /// with the variables 'a' and 'b', 'grainsize' with expression 'val' and /// 'num_tasks' with expression 'num'. /// class OMPTaskLoopDirective : public OMPLoopDirective { friend class ASTStmtReader; friend class OMPExecutableDirective; /// true if the construct has inner cancel directive. bool HasCancel = false; /// Build directive with the given start and end location. /// /// \param StartLoc Starting location of the directive kind. /// \param EndLoc Ending location of the directive. /// \param CollapsedNum Number of collapsed nested loops. /// OMPTaskLoopDirective(SourceLocation StartLoc, SourceLocation EndLoc, unsigned CollapsedNum) : OMPLoopDirective(OMPTaskLoopDirectiveClass, llvm::omp::OMPD_taskloop, StartLoc, EndLoc, CollapsedNum) {} /// Build an empty directive. /// /// \param CollapsedNum Number of collapsed nested loops. /// explicit OMPTaskLoopDirective(unsigned CollapsedNum) : OMPLoopDirective(OMPTaskLoopDirectiveClass, llvm::omp::OMPD_taskloop, SourceLocation(), SourceLocation(), CollapsedNum) {} /// Set cancel state. void setHasCancel(bool Has) { HasCancel = Has; } public: /// Creates directive with a list of \a Clauses. /// /// \param C AST context. /// \param StartLoc Starting location of the directive kind. /// \param EndLoc Ending Location of the directive. /// \param CollapsedNum Number of collapsed loops. /// \param Clauses List of clauses. /// \param AssociatedStmt Statement, associated with the directive. /// \param Exprs Helper expressions for CodeGen. /// \param HasCancel true if this directive has inner cancel directive. /// static OMPTaskLoopDirective * Create(const ASTContext &C, SourceLocation StartLoc, SourceLocation EndLoc, unsigned CollapsedNum, ArrayRef<OMPClause *> Clauses, Stmt *AssociatedStmt, const HelperExprs &Exprs, bool HasCancel); /// Creates an empty directive with the place /// for \a NumClauses clauses. /// /// \param C AST context. /// \param CollapsedNum Number of collapsed nested loops. /// \param NumClauses Number of clauses. /// static OMPTaskLoopDirective *CreateEmpty(const ASTContext &C, unsigned NumClauses, unsigned CollapsedNum, EmptyShell); /// Return true if current directive has inner cancel directive. bool hasCancel() const { return HasCancel; } static bool classof(const Stmt *T) { return T->getStmtClass() == OMPTaskLoopDirectiveClass; } }; /// This represents '#pragma omp taskloop simd' directive. /// /// \code /// #pragma omp taskloop simd private(a,b) grainsize(val) num_tasks(num) /// \endcode /// In this example directive '#pragma omp taskloop simd' has clauses 'private' /// with the variables 'a' and 'b', 'grainsize' with expression 'val' and /// 'num_tasks' with expression 'num'. /// class OMPTaskLoopSimdDirective : public OMPLoopDirective { friend class ASTStmtReader; friend class OMPExecutableDirective; /// Build directive with the given start and end location. /// /// \param StartLoc Starting location of the directive kind. /// \param EndLoc Ending location of the directive. /// \param CollapsedNum Number of collapsed nested loops. /// OMPTaskLoopSimdDirective(SourceLocation StartLoc, SourceLocation EndLoc, unsigned CollapsedNum) : OMPLoopDirective(OMPTaskLoopSimdDirectiveClass, llvm::omp::OMPD_taskloop_simd, StartLoc, EndLoc, CollapsedNum) {} /// Build an empty directive. /// /// \param CollapsedNum Number of collapsed nested loops. /// explicit OMPTaskLoopSimdDirective(unsigned CollapsedNum) : OMPLoopDirective(OMPTaskLoopSimdDirectiveClass, llvm::omp::OMPD_taskloop_simd, SourceLocation(), SourceLocation(), CollapsedNum) {} public: /// Creates directive with a list of \a Clauses. /// /// \param C AST context. /// \param StartLoc Starting location of the directive kind. /// \param EndLoc Ending Location of the directive. /// \param CollapsedNum Number of collapsed loops. /// \param Clauses List of clauses. /// \param AssociatedStmt Statement, associated with the directive. /// \param Exprs Helper expressions for CodeGen. /// static OMPTaskLoopSimdDirective * Create(const ASTContext &C, SourceLocation StartLoc, SourceLocation EndLoc, unsigned CollapsedNum, ArrayRef<OMPClause *> Clauses, Stmt *AssociatedStmt, const HelperExprs &Exprs); /// Creates an empty directive with the place /// for \a NumClauses clauses. /// /// \param C AST context. /// \param CollapsedNum Number of collapsed nested loops. /// \param NumClauses Number of clauses. /// static OMPTaskLoopSimdDirective *CreateEmpty(const ASTContext &C, unsigned NumClauses, unsigned CollapsedNum, EmptyShell); static bool classof(const Stmt *T) { return T->getStmtClass() == OMPTaskLoopSimdDirectiveClass; } }; /// This represents '#pragma omp master taskloop' directive. /// /// \code /// #pragma omp master taskloop private(a,b) grainsize(val) num_tasks(num) /// \endcode /// In this example directive '#pragma omp master taskloop' has clauses /// 'private' with the variables 'a' and 'b', 'grainsize' with expression 'val' /// and 'num_tasks' with expression 'num'. /// class OMPMasterTaskLoopDirective : public OMPLoopDirective { friend class ASTStmtReader; friend class OMPExecutableDirective; /// true if the construct has inner cancel directive. bool HasCancel = false; /// Build directive with the given start and end location. /// /// \param StartLoc Starting location of the directive kind. /// \param EndLoc Ending location of the directive. /// \param CollapsedNum Number of collapsed nested loops. /// OMPMasterTaskLoopDirective(SourceLocation StartLoc, SourceLocation EndLoc, unsigned CollapsedNum) : OMPLoopDirective(OMPMasterTaskLoopDirectiveClass, llvm::omp::OMPD_master_taskloop, StartLoc, EndLoc, CollapsedNum) {} /// Build an empty directive. /// /// \param CollapsedNum Number of collapsed nested loops. /// explicit OMPMasterTaskLoopDirective(unsigned CollapsedNum) : OMPLoopDirective(OMPMasterTaskLoopDirectiveClass, llvm::omp::OMPD_master_taskloop, SourceLocation(), SourceLocation(), CollapsedNum) {} /// Set cancel state. void setHasCancel(bool Has) { HasCancel = Has; } public: /// Creates directive with a list of \a Clauses. /// /// \param C AST context. /// \param StartLoc Starting location of the directive kind. /// \param EndLoc Ending Location of the directive. /// \param CollapsedNum Number of collapsed loops. /// \param Clauses List of clauses. /// \param AssociatedStmt Statement, associated with the directive. /// \param Exprs Helper expressions for CodeGen. /// \param HasCancel true if this directive has inner cancel directive. /// static OMPMasterTaskLoopDirective * Create(const ASTContext &C, SourceLocation StartLoc, SourceLocation EndLoc, unsigned CollapsedNum, ArrayRef<OMPClause *> Clauses, Stmt *AssociatedStmt, const HelperExprs &Exprs, bool HasCancel); /// Creates an empty directive with the place /// for \a NumClauses clauses. /// /// \param C AST context. /// \param CollapsedNum Number of collapsed nested loops. /// \param NumClauses Number of clauses. /// static OMPMasterTaskLoopDirective *CreateEmpty(const ASTContext &C, unsigned NumClauses, unsigned CollapsedNum, EmptyShell); /// Return true if current directive has inner cancel directive. bool hasCancel() const { return HasCancel; } static bool classof(const Stmt *T) { return T->getStmtClass() == OMPMasterTaskLoopDirectiveClass; } }; /// This represents '#pragma omp master taskloop simd' directive. /// /// \code /// #pragma omp master taskloop simd private(a,b) grainsize(val) num_tasks(num) /// \endcode /// In this example directive '#pragma omp master taskloop simd' has clauses /// 'private' with the variables 'a' and 'b', 'grainsize' with expression 'val' /// and 'num_tasks' with expression 'num'. /// class OMPMasterTaskLoopSimdDirective : public OMPLoopDirective { friend class ASTStmtReader; friend class OMPExecutableDirective; /// Build directive with the given start and end location. /// /// \param StartLoc Starting location of the directive kind. /// \param EndLoc Ending location of the directive. /// \param CollapsedNum Number of collapsed nested loops. /// OMPMasterTaskLoopSimdDirective(SourceLocation StartLoc, SourceLocation EndLoc, unsigned CollapsedNum) : OMPLoopDirective(OMPMasterTaskLoopSimdDirectiveClass, llvm::omp::OMPD_master_taskloop_simd, StartLoc, EndLoc, CollapsedNum) {} /// Build an empty directive. /// /// \param CollapsedNum Number of collapsed nested loops. /// explicit OMPMasterTaskLoopSimdDirective(unsigned CollapsedNum) : OMPLoopDirective(OMPMasterTaskLoopSimdDirectiveClass, llvm::omp::OMPD_master_taskloop_simd, SourceLocation(), SourceLocation(), CollapsedNum) {} public: /// Creates directive with a list of \p Clauses. /// /// \param C AST context. /// \param StartLoc Starting location of the directive kind. /// \param EndLoc Ending Location of the directive. /// \param CollapsedNum Number of collapsed loops. /// \param Clauses List of clauses. /// \param AssociatedStmt Statement, associated with the directive. /// \param Exprs Helper expressions for CodeGen. /// static OMPMasterTaskLoopSimdDirective * Create(const ASTContext &C, SourceLocation StartLoc, SourceLocation EndLoc, unsigned CollapsedNum, ArrayRef<OMPClause *> Clauses, Stmt *AssociatedStmt, const HelperExprs &Exprs); /// Creates an empty directive with the place for \p NumClauses clauses. /// /// \param C AST context. /// \param CollapsedNum Number of collapsed nested loops. /// \param NumClauses Number of clauses. /// static OMPMasterTaskLoopSimdDirective *CreateEmpty(const ASTContext &C, unsigned NumClauses, unsigned CollapsedNum, EmptyShell); static bool classof(const Stmt *T) { return T->getStmtClass() == OMPMasterTaskLoopSimdDirectiveClass; } }; /// This represents '#pragma omp parallel master taskloop' directive. /// /// \code /// #pragma omp parallel master taskloop private(a,b) grainsize(val) /// num_tasks(num) /// \endcode /// In this example directive '#pragma omp parallel master taskloop' has clauses /// 'private' with the variables 'a' and 'b', 'grainsize' with expression 'val' /// and 'num_tasks' with expression 'num'. /// class OMPParallelMasterTaskLoopDirective : public OMPLoopDirective { friend class ASTStmtReader; friend class OMPExecutableDirective; /// true if the construct has inner cancel directive. bool HasCancel = false; /// Build directive with the given start and end location. /// /// \param StartLoc Starting location of the directive kind. /// \param EndLoc Ending location of the directive. /// \param CollapsedNum Number of collapsed nested loops. /// OMPParallelMasterTaskLoopDirective(SourceLocation StartLoc, SourceLocation EndLoc, unsigned CollapsedNum) : OMPLoopDirective(OMPParallelMasterTaskLoopDirectiveClass, llvm::omp::OMPD_parallel_master_taskloop, StartLoc, EndLoc, CollapsedNum) {} /// Build an empty directive. /// /// \param CollapsedNum Number of collapsed nested loops. /// explicit OMPParallelMasterTaskLoopDirective(unsigned CollapsedNum) : OMPLoopDirective(OMPParallelMasterTaskLoopDirectiveClass, llvm::omp::OMPD_parallel_master_taskloop, SourceLocation(), SourceLocation(), CollapsedNum) {} /// Set cancel state. void setHasCancel(bool Has) { HasCancel = Has; } public: /// Creates directive with a list of \a Clauses. /// /// \param C AST context. /// \param StartLoc Starting location of the directive kind. /// \param EndLoc Ending Location of the directive. /// \param CollapsedNum Number of collapsed loops. /// \param Clauses List of clauses. /// \param AssociatedStmt Statement, associated with the directive. /// \param Exprs Helper expressions for CodeGen. /// \param HasCancel true if this directive has inner cancel directive. /// static OMPParallelMasterTaskLoopDirective * Create(const ASTContext &C, SourceLocation StartLoc, SourceLocation EndLoc, unsigned CollapsedNum, ArrayRef<OMPClause *> Clauses, Stmt *AssociatedStmt, const HelperExprs &Exprs, bool HasCancel); /// Creates an empty directive with the place /// for \a NumClauses clauses. /// /// \param C AST context. /// \param CollapsedNum Number of collapsed nested loops. /// \param NumClauses Number of clauses. /// static OMPParallelMasterTaskLoopDirective *CreateEmpty(const ASTContext &C, unsigned NumClauses, unsigned CollapsedNum, EmptyShell); /// Return true if current directive has inner cancel directive. bool hasCancel() const { return HasCancel; } static bool classof(const Stmt *T) { return T->getStmtClass() == OMPParallelMasterTaskLoopDirectiveClass; } }; /// This represents '#pragma omp parallel master taskloop simd' directive. /// /// \code /// #pragma omp parallel master taskloop simd private(a,b) grainsize(val) /// num_tasks(num) /// \endcode /// In this example directive '#pragma omp parallel master taskloop simd' has /// clauses 'private' with the variables 'a' and 'b', 'grainsize' with /// expression 'val' and 'num_tasks' with expression 'num'. /// class OMPParallelMasterTaskLoopSimdDirective : public OMPLoopDirective { friend class ASTStmtReader; friend class OMPExecutableDirective; /// Build directive with the given start and end location. /// /// \param StartLoc Starting location of the directive kind. /// \param EndLoc Ending location of the directive. /// \param CollapsedNum Number of collapsed nested loops. /// OMPParallelMasterTaskLoopSimdDirective(SourceLocation StartLoc, SourceLocation EndLoc, unsigned CollapsedNum) : OMPLoopDirective(OMPParallelMasterTaskLoopSimdDirectiveClass, llvm::omp::OMPD_parallel_master_taskloop_simd, StartLoc, EndLoc, CollapsedNum) {} /// Build an empty directive. /// /// \param CollapsedNum Number of collapsed nested loops. /// explicit OMPParallelMasterTaskLoopSimdDirective(unsigned CollapsedNum) : OMPLoopDirective(OMPParallelMasterTaskLoopSimdDirectiveClass, llvm::omp::OMPD_parallel_master_taskloop_simd, SourceLocation(), SourceLocation(), CollapsedNum) {} public: /// Creates directive with a list of \p Clauses. /// /// \param C AST context. /// \param StartLoc Starting location of the directive kind. /// \param EndLoc Ending Location of the directive. /// \param CollapsedNum Number of collapsed loops. /// \param Clauses List of clauses. /// \param AssociatedStmt Statement, associated with the directive. /// \param Exprs Helper expressions for CodeGen. /// static OMPParallelMasterTaskLoopSimdDirective * Create(const ASTContext &C, SourceLocation StartLoc, SourceLocation EndLoc, unsigned CollapsedNum, ArrayRef<OMPClause *> Clauses, Stmt *AssociatedStmt, const HelperExprs &Exprs); /// Creates an empty directive with the place /// for \a NumClauses clauses. /// /// \param C AST context. /// \param CollapsedNum Number of collapsed nested loops. /// \param NumClauses Number of clauses. /// static OMPParallelMasterTaskLoopSimdDirective * CreateEmpty(const ASTContext &C, unsigned NumClauses, unsigned CollapsedNum, EmptyShell); static bool classof(const Stmt *T) { return T->getStmtClass() == OMPParallelMasterTaskLoopSimdDirectiveClass; } }; /// This represents '#pragma omp distribute' directive. /// /// \code /// #pragma omp distribute private(a,b) /// \endcode /// In this example directive '#pragma omp distribute' has clauses 'private' /// with the variables 'a' and 'b' /// class OMPDistributeDirective : public OMPLoopDirective { friend class ASTStmtReader; friend class OMPExecutableDirective; /// Build directive with the given start and end location. /// /// \param StartLoc Starting location of the directive kind. /// \param EndLoc Ending location of the directive. /// \param CollapsedNum Number of collapsed nested loops. /// OMPDistributeDirective(SourceLocation StartLoc, SourceLocation EndLoc, unsigned CollapsedNum) : OMPLoopDirective(OMPDistributeDirectiveClass, llvm::omp::OMPD_distribute, StartLoc, EndLoc, CollapsedNum) {} /// Build an empty directive. /// /// \param CollapsedNum Number of collapsed nested loops. /// explicit OMPDistributeDirective(unsigned CollapsedNum) : OMPLoopDirective(OMPDistributeDirectiveClass, llvm::omp::OMPD_distribute, SourceLocation(), SourceLocation(), CollapsedNum) {} public: /// Creates directive with a list of \a Clauses. /// /// \param C AST context. /// \param StartLoc Starting location of the directive kind. /// \param EndLoc Ending Location of the directive. /// \param CollapsedNum Number of collapsed loops. /// \param Clauses List of clauses. /// \param AssociatedStmt Statement, associated with the directive. /// \param Exprs Helper expressions for CodeGen. /// static OMPDistributeDirective * Create(const ASTContext &C, SourceLocation StartLoc, SourceLocation EndLoc, unsigned CollapsedNum, ArrayRef<OMPClause *> Clauses, Stmt *AssociatedStmt, const HelperExprs &Exprs); /// Creates an empty directive with the place /// for \a NumClauses clauses. /// /// \param C AST context. /// \param CollapsedNum Number of collapsed nested loops. /// \param NumClauses Number of clauses. /// static OMPDistributeDirective *CreateEmpty(const ASTContext &C, unsigned NumClauses, unsigned CollapsedNum, EmptyShell); static bool classof(const Stmt *T) { return T->getStmtClass() == OMPDistributeDirectiveClass; } }; /// This represents '#pragma omp target update' directive. /// /// \code /// #pragma omp target update to(a) from(b) device(1) /// \endcode /// In this example directive '#pragma omp target update' has clause 'to' with /// argument 'a', clause 'from' with argument 'b' and clause 'device' with /// argument '1'. /// class OMPTargetUpdateDirective : public OMPExecutableDirective { friend class ASTStmtReader; friend class OMPExecutableDirective; /// Build directive with the given start and end location. /// /// \param StartLoc Starting location of the directive kind. /// \param EndLoc Ending Location of the directive. /// OMPTargetUpdateDirective(SourceLocation StartLoc, SourceLocation EndLoc) : OMPExecutableDirective(OMPTargetUpdateDirectiveClass, llvm::omp::OMPD_target_update, StartLoc, EndLoc) {} /// Build an empty directive. /// explicit OMPTargetUpdateDirective() : OMPExecutableDirective(OMPTargetUpdateDirectiveClass, llvm::omp::OMPD_target_update, SourceLocation(), SourceLocation()) {} public: /// Creates directive with a list of \a Clauses. /// /// \param C AST context. /// \param StartLoc Starting location of the directive kind. /// \param EndLoc Ending Location of the directive. /// \param Clauses List of clauses. /// \param AssociatedStmt Statement, associated with the directive. /// static OMPTargetUpdateDirective * Create(const ASTContext &C, SourceLocation StartLoc, SourceLocation EndLoc, ArrayRef<OMPClause *> Clauses, Stmt *AssociatedStmt); /// Creates an empty directive with the place for \a NumClauses /// clauses. /// /// \param C AST context. /// \param NumClauses The number of clauses. /// static OMPTargetUpdateDirective *CreateEmpty(const ASTContext &C, unsigned NumClauses, EmptyShell); static bool classof(const Stmt *T) { return T->getStmtClass() == OMPTargetUpdateDirectiveClass; } }; /// This represents '#pragma omp distribute parallel for' composite /// directive. /// /// \code /// #pragma omp distribute parallel for private(a,b) /// \endcode /// In this example directive '#pragma omp distribute parallel for' has clause /// 'private' with the variables 'a' and 'b' /// class OMPDistributeParallelForDirective : public OMPLoopDirective { friend class ASTStmtReader; friend class OMPExecutableDirective; /// true if the construct has inner cancel directive. bool HasCancel = false; /// Build directive with the given start and end location. /// /// \param StartLoc Starting location of the directive kind. /// \param EndLoc Ending location of the directive. /// \param CollapsedNum Number of collapsed nested loops. /// OMPDistributeParallelForDirective(SourceLocation StartLoc, SourceLocation EndLoc, unsigned CollapsedNum) : OMPLoopDirective(OMPDistributeParallelForDirectiveClass, llvm::omp::OMPD_distribute_parallel_for, StartLoc, EndLoc, CollapsedNum) {} /// Build an empty directive. /// /// \param CollapsedNum Number of collapsed nested loops. /// explicit OMPDistributeParallelForDirective(unsigned CollapsedNum) : OMPLoopDirective(OMPDistributeParallelForDirectiveClass, llvm::omp::OMPD_distribute_parallel_for, SourceLocation(), SourceLocation(), CollapsedNum) {} /// Sets special task reduction descriptor. void setTaskReductionRefExpr(Expr *E) { Data->getChildren()[numLoopChildren( getLoopsNumber(), llvm::omp::OMPD_distribute_parallel_for)] = E; } /// Set cancel state. void setHasCancel(bool Has) { HasCancel = Has; } public: /// Creates directive with a list of \a Clauses. /// /// \param C AST context. /// \param StartLoc Starting location of the directive kind. /// \param EndLoc Ending Location of the directive. /// \param CollapsedNum Number of collapsed loops. /// \param Clauses List of clauses. /// \param AssociatedStmt Statement, associated with the directive. /// \param Exprs Helper expressions for CodeGen. /// \param TaskRedRef Task reduction special reference expression to handle /// taskgroup descriptor. /// \param HasCancel true if this directive has inner cancel directive. /// static OMPDistributeParallelForDirective * Create(const ASTContext &C, SourceLocation StartLoc, SourceLocation EndLoc, unsigned CollapsedNum, ArrayRef<OMPClause *> Clauses, Stmt *AssociatedStmt, const HelperExprs &Exprs, Expr *TaskRedRef, bool HasCancel); /// Creates an empty directive with the place /// for \a NumClauses clauses. /// /// \param C AST context. /// \param CollapsedNum Number of collapsed nested loops. /// \param NumClauses Number of clauses. /// static OMPDistributeParallelForDirective *CreateEmpty(const ASTContext &C, unsigned NumClauses, unsigned CollapsedNum, EmptyShell); /// Returns special task reduction reference expression. Expr *getTaskReductionRefExpr() { return cast_or_null<Expr>(Data->getChildren()[numLoopChildren( getLoopsNumber(), llvm::omp::OMPD_distribute_parallel_for)]); } const Expr *getTaskReductionRefExpr() const { return const_cast<OMPDistributeParallelForDirective *>(this) ->getTaskReductionRefExpr(); } /// Return true if current directive has inner cancel directive. bool hasCancel() const { return HasCancel; } static bool classof(const Stmt *T) { return T->getStmtClass() == OMPDistributeParallelForDirectiveClass; } }; /// This represents '#pragma omp distribute parallel for simd' composite /// directive. /// /// \code /// #pragma omp distribute parallel for simd private(x) /// \endcode /// In this example directive '#pragma omp distribute parallel for simd' has /// clause 'private' with the variables 'x' /// class OMPDistributeParallelForSimdDirective final : public OMPLoopDirective { friend class ASTStmtReader; friend class OMPExecutableDirective; /// Build directive with the given start and end location. /// /// \param StartLoc Starting location of the directive kind. /// \param EndLoc Ending location of the directive. /// \param CollapsedNum Number of collapsed nested loops. /// OMPDistributeParallelForSimdDirective(SourceLocation StartLoc, SourceLocation EndLoc, unsigned CollapsedNum) : OMPLoopDirective(OMPDistributeParallelForSimdDirectiveClass, llvm::omp::OMPD_distribute_parallel_for_simd, StartLoc, EndLoc, CollapsedNum) {} /// Build an empty directive. /// /// \param CollapsedNum Number of collapsed nested loops. /// explicit OMPDistributeParallelForSimdDirective(unsigned CollapsedNum) : OMPLoopDirective(OMPDistributeParallelForSimdDirectiveClass, llvm::omp::OMPD_distribute_parallel_for_simd, SourceLocation(), SourceLocation(), CollapsedNum) {} public: /// Creates directive with a list of \a Clauses. /// /// \param C AST context. /// \param StartLoc Starting location of the directive kind. /// \param EndLoc Ending Location of the directive. /// \param CollapsedNum Number of collapsed loops. /// \param Clauses List of clauses. /// \param AssociatedStmt Statement, associated with the directive. /// \param Exprs Helper expressions for CodeGen. /// static OMPDistributeParallelForSimdDirective *Create( const ASTContext &C, SourceLocation StartLoc, SourceLocation EndLoc, unsigned CollapsedNum, ArrayRef<OMPClause *> Clauses, Stmt *AssociatedStmt, const HelperExprs &Exprs); /// Creates an empty directive with the place for \a NumClauses clauses. /// /// \param C AST context. /// \param CollapsedNum Number of collapsed nested loops. /// \param NumClauses Number of clauses. /// static OMPDistributeParallelForSimdDirective *CreateEmpty( const ASTContext &C, unsigned NumClauses, unsigned CollapsedNum, EmptyShell); static bool classof(const Stmt *T) { return T->getStmtClass() == OMPDistributeParallelForSimdDirectiveClass; } }; /// This represents '#pragma omp distribute simd' composite directive. /// /// \code /// #pragma omp distribute simd private(x) /// \endcode /// In this example directive '#pragma omp distribute simd' has clause /// 'private' with the variables 'x' /// class OMPDistributeSimdDirective final : public OMPLoopDirective { friend class ASTStmtReader; friend class OMPExecutableDirective; /// Build directive with the given start and end location. /// /// \param StartLoc Starting location of the directive kind. /// \param EndLoc Ending location of the directive. /// \param CollapsedNum Number of collapsed nested loops. /// OMPDistributeSimdDirective(SourceLocation StartLoc, SourceLocation EndLoc, unsigned CollapsedNum) : OMPLoopDirective(OMPDistributeSimdDirectiveClass, llvm::omp::OMPD_distribute_simd, StartLoc, EndLoc, CollapsedNum) {} /// Build an empty directive. /// /// \param CollapsedNum Number of collapsed nested loops. /// explicit OMPDistributeSimdDirective(unsigned CollapsedNum) : OMPLoopDirective(OMPDistributeSimdDirectiveClass, llvm::omp::OMPD_distribute_simd, SourceLocation(), SourceLocation(), CollapsedNum) {} public: /// Creates directive with a list of \a Clauses. /// /// \param C AST context. /// \param StartLoc Starting location of the directive kind. /// \param EndLoc Ending Location of the directive. /// \param CollapsedNum Number of collapsed loops. /// \param Clauses List of clauses. /// \param AssociatedStmt Statement, associated with the directive. /// \param Exprs Helper expressions for CodeGen. /// static OMPDistributeSimdDirective * Create(const ASTContext &C, SourceLocation StartLoc, SourceLocation EndLoc, unsigned CollapsedNum, ArrayRef<OMPClause *> Clauses, Stmt *AssociatedStmt, const HelperExprs &Exprs); /// Creates an empty directive with the place for \a NumClauses clauses. /// /// \param C AST context. /// \param CollapsedNum Number of collapsed nested loops. /// \param NumClauses Number of clauses. /// static OMPDistributeSimdDirective *CreateEmpty(const ASTContext &C, unsigned NumClauses, unsigned CollapsedNum, EmptyShell); static bool classof(const Stmt *T) { return T->getStmtClass() == OMPDistributeSimdDirectiveClass; } }; /// This represents '#pragma omp target parallel for simd' directive. /// /// \code /// #pragma omp target parallel for simd private(a) map(b) safelen(c) /// \endcode /// In this example directive '#pragma omp target parallel for simd' has clauses /// 'private' with the variable 'a', 'map' with the variable 'b' and 'safelen' /// with the variable 'c'. /// class OMPTargetParallelForSimdDirective final : public OMPLoopDirective { friend class ASTStmtReader; friend class OMPExecutableDirective; /// Build directive with the given start and end location. /// /// \param StartLoc Starting location of the directive kind. /// \param EndLoc Ending location of the directive. /// \param CollapsedNum Number of collapsed nested loops. /// OMPTargetParallelForSimdDirective(SourceLocation StartLoc, SourceLocation EndLoc, unsigned CollapsedNum) : OMPLoopDirective(OMPTargetParallelForSimdDirectiveClass, llvm::omp::OMPD_target_parallel_for_simd, StartLoc, EndLoc, CollapsedNum) {} /// Build an empty directive. /// /// \param CollapsedNum Number of collapsed nested loops. /// explicit OMPTargetParallelForSimdDirective(unsigned CollapsedNum) : OMPLoopDirective(OMPTargetParallelForSimdDirectiveClass, llvm::omp::OMPD_target_parallel_for_simd, SourceLocation(), SourceLocation(), CollapsedNum) {} public: /// Creates directive with a list of \a Clauses. /// /// \param C AST context. /// \param StartLoc Starting location of the directive kind. /// \param EndLoc Ending Location of the directive. /// \param CollapsedNum Number of collapsed loops. /// \param Clauses List of clauses. /// \param AssociatedStmt Statement, associated with the directive. /// \param Exprs Helper expressions for CodeGen. /// static OMPTargetParallelForSimdDirective * Create(const ASTContext &C, SourceLocation StartLoc, SourceLocation EndLoc, unsigned CollapsedNum, ArrayRef<OMPClause *> Clauses, Stmt *AssociatedStmt, const HelperExprs &Exprs); /// Creates an empty directive with the place for \a NumClauses clauses. /// /// \param C AST context. /// \param CollapsedNum Number of collapsed nested loops. /// \param NumClauses Number of clauses. /// static OMPTargetParallelForSimdDirective *CreateEmpty(const ASTContext &C, unsigned NumClauses, unsigned CollapsedNum, EmptyShell); static bool classof(const Stmt *T) { return T->getStmtClass() == OMPTargetParallelForSimdDirectiveClass; } }; /// This represents '#pragma omp target simd' directive. /// /// \code /// #pragma omp target simd private(a) map(b) safelen(c) /// \endcode /// In this example directive '#pragma omp target simd' has clauses 'private' /// with the variable 'a', 'map' with the variable 'b' and 'safelen' with /// the variable 'c'. /// class OMPTargetSimdDirective final : public OMPLoopDirective { friend class ASTStmtReader; friend class OMPExecutableDirective; /// Build directive with the given start and end location. /// /// \param StartLoc Starting location of the directive kind. /// \param EndLoc Ending location of the directive. /// \param CollapsedNum Number of collapsed nested loops. /// OMPTargetSimdDirective(SourceLocation StartLoc, SourceLocation EndLoc, unsigned CollapsedNum) : OMPLoopDirective(OMPTargetSimdDirectiveClass, llvm::omp::OMPD_target_simd, StartLoc, EndLoc, CollapsedNum) {} /// Build an empty directive. /// /// \param CollapsedNum Number of collapsed nested loops. /// explicit OMPTargetSimdDirective(unsigned CollapsedNum) : OMPLoopDirective(OMPTargetSimdDirectiveClass, llvm::omp::OMPD_target_simd, SourceLocation(), SourceLocation(), CollapsedNum) {} public: /// Creates directive with a list of \a Clauses. /// /// \param C AST context. /// \param StartLoc Starting location of the directive kind. /// \param EndLoc Ending Location of the directive. /// \param CollapsedNum Number of collapsed loops. /// \param Clauses List of clauses. /// \param AssociatedStmt Statement, associated with the directive. /// \param Exprs Helper expressions for CodeGen. /// static OMPTargetSimdDirective * Create(const ASTContext &C, SourceLocation StartLoc, SourceLocation EndLoc, unsigned CollapsedNum, ArrayRef<OMPClause *> Clauses, Stmt *AssociatedStmt, const HelperExprs &Exprs); /// Creates an empty directive with the place for \a NumClauses clauses. /// /// \param C AST context. /// \param CollapsedNum Number of collapsed nested loops. /// \param NumClauses Number of clauses. /// static OMPTargetSimdDirective *CreateEmpty(const ASTContext &C, unsigned NumClauses, unsigned CollapsedNum, EmptyShell); static bool classof(const Stmt *T) { return T->getStmtClass() == OMPTargetSimdDirectiveClass; } }; /// This represents '#pragma omp teams distribute' directive. /// /// \code /// #pragma omp teams distribute private(a,b) /// \endcode /// In this example directive '#pragma omp teams distribute' has clauses /// 'private' with the variables 'a' and 'b' /// class OMPTeamsDistributeDirective final : public OMPLoopDirective { friend class ASTStmtReader; friend class OMPExecutableDirective; /// Build directive with the given start and end location. /// /// \param StartLoc Starting location of the directive kind. /// \param EndLoc Ending location of the directive. /// \param CollapsedNum Number of collapsed nested loops. /// OMPTeamsDistributeDirective(SourceLocation StartLoc, SourceLocation EndLoc, unsigned CollapsedNum) : OMPLoopDirective(OMPTeamsDistributeDirectiveClass, llvm::omp::OMPD_teams_distribute, StartLoc, EndLoc, CollapsedNum) {} /// Build an empty directive. /// /// \param CollapsedNum Number of collapsed nested loops. /// explicit OMPTeamsDistributeDirective(unsigned CollapsedNum) : OMPLoopDirective(OMPTeamsDistributeDirectiveClass, llvm::omp::OMPD_teams_distribute, SourceLocation(), SourceLocation(), CollapsedNum) {} public: /// Creates directive with a list of \a Clauses. /// /// \param C AST context. /// \param StartLoc Starting location of the directive kind. /// \param EndLoc Ending Location of the directive. /// \param CollapsedNum Number of collapsed loops. /// \param Clauses List of clauses. /// \param AssociatedStmt Statement, associated with the directive. /// \param Exprs Helper expressions for CodeGen. /// static OMPTeamsDistributeDirective * Create(const ASTContext &C, SourceLocation StartLoc, SourceLocation EndLoc, unsigned CollapsedNum, ArrayRef<OMPClause *> Clauses, Stmt *AssociatedStmt, const HelperExprs &Exprs); /// Creates an empty directive with the place for \a NumClauses clauses. /// /// \param C AST context. /// \param CollapsedNum Number of collapsed nested loops. /// \param NumClauses Number of clauses. /// static OMPTeamsDistributeDirective *CreateEmpty(const ASTContext &C, unsigned NumClauses, unsigned CollapsedNum, EmptyShell); static bool classof(const Stmt *T) { return T->getStmtClass() == OMPTeamsDistributeDirectiveClass; } }; /// This represents '#pragma omp teams distribute simd' /// combined directive. /// /// \code /// #pragma omp teams distribute simd private(a,b) /// \endcode /// In this example directive '#pragma omp teams distribute simd' /// has clause 'private' with the variables 'a' and 'b' /// class OMPTeamsDistributeSimdDirective final : public OMPLoopDirective { friend class ASTStmtReader; friend class OMPExecutableDirective; /// Build directive with the given start and end location. /// /// \param StartLoc Starting location of the directive kind. /// \param EndLoc Ending location of the directive. /// \param CollapsedNum Number of collapsed nested loops. /// OMPTeamsDistributeSimdDirective(SourceLocation StartLoc, SourceLocation EndLoc, unsigned CollapsedNum) : OMPLoopDirective(OMPTeamsDistributeSimdDirectiveClass, llvm::omp::OMPD_teams_distribute_simd, StartLoc, EndLoc, CollapsedNum) {} /// Build an empty directive. /// /// \param CollapsedNum Number of collapsed nested loops. /// explicit OMPTeamsDistributeSimdDirective(unsigned CollapsedNum) : OMPLoopDirective(OMPTeamsDistributeSimdDirectiveClass, llvm::omp::OMPD_teams_distribute_simd, SourceLocation(), SourceLocation(), CollapsedNum) {} public: /// Creates directive with a list of \a Clauses. /// /// \param C AST context. /// \param StartLoc Starting location of the directive kind. /// \param EndLoc Ending Location of the directive. /// \param CollapsedNum Number of collapsed loops. /// \param Clauses List of clauses. /// \param AssociatedStmt Statement, associated with the directive. /// \param Exprs Helper expressions for CodeGen. /// static OMPTeamsDistributeSimdDirective * Create(const ASTContext &C, SourceLocation StartLoc, SourceLocation EndLoc, unsigned CollapsedNum, ArrayRef<OMPClause *> Clauses, Stmt *AssociatedStmt, const HelperExprs &Exprs); /// Creates an empty directive with the place /// for \a NumClauses clauses. /// /// \param C AST context. /// \param CollapsedNum Number of collapsed nested loops. /// \param NumClauses Number of clauses. /// static OMPTeamsDistributeSimdDirective *CreateEmpty(const ASTContext &C, unsigned NumClauses, unsigned CollapsedNum, EmptyShell); static bool classof(const Stmt *T) { return T->getStmtClass() == OMPTeamsDistributeSimdDirectiveClass; } }; /// This represents '#pragma omp teams distribute parallel for simd' composite /// directive. /// /// \code /// #pragma omp teams distribute parallel for simd private(x) /// \endcode /// In this example directive '#pragma omp teams distribute parallel for simd' /// has clause 'private' with the variables 'x' /// class OMPTeamsDistributeParallelForSimdDirective final : public OMPLoopDirective { friend class ASTStmtReader; friend class OMPExecutableDirective; /// Build directive with the given start and end location. /// /// \param StartLoc Starting location of the directive kind. /// \param EndLoc Ending location of the directive. /// \param CollapsedNum Number of collapsed nested loops. /// OMPTeamsDistributeParallelForSimdDirective(SourceLocation StartLoc, SourceLocation EndLoc, unsigned CollapsedNum) : OMPLoopDirective(OMPTeamsDistributeParallelForSimdDirectiveClass, llvm::omp::OMPD_teams_distribute_parallel_for_simd, StartLoc, EndLoc, CollapsedNum) {} /// Build an empty directive. /// /// \param CollapsedNum Number of collapsed nested loops. /// explicit OMPTeamsDistributeParallelForSimdDirective(unsigned CollapsedNum) : OMPLoopDirective(OMPTeamsDistributeParallelForSimdDirectiveClass, llvm::omp::OMPD_teams_distribute_parallel_for_simd, SourceLocation(), SourceLocation(), CollapsedNum) {} public: /// Creates directive with a list of \a Clauses. /// /// \param C AST context. /// \param StartLoc Starting location of the directive kind. /// \param EndLoc Ending Location of the directive. /// \param CollapsedNum Number of collapsed loops. /// \param Clauses List of clauses. /// \param AssociatedStmt Statement, associated with the directive. /// \param Exprs Helper expressions for CodeGen. /// static OMPTeamsDistributeParallelForSimdDirective * Create(const ASTContext &C, SourceLocation StartLoc, SourceLocation EndLoc, unsigned CollapsedNum, ArrayRef<OMPClause *> Clauses, Stmt *AssociatedStmt, const HelperExprs &Exprs); /// Creates an empty directive with the place for \a NumClauses clauses. /// /// \param C AST context. /// \param CollapsedNum Number of collapsed nested loops. /// \param NumClauses Number of clauses. /// static OMPTeamsDistributeParallelForSimdDirective * CreateEmpty(const ASTContext &C, unsigned NumClauses, unsigned CollapsedNum, EmptyShell); static bool classof(const Stmt *T) { return T->getStmtClass() == OMPTeamsDistributeParallelForSimdDirectiveClass; } }; /// This represents '#pragma omp teams distribute parallel for' composite /// directive. /// /// \code /// #pragma omp teams distribute parallel for private(x) /// \endcode /// In this example directive '#pragma omp teams distribute parallel for' /// has clause 'private' with the variables 'x' /// class OMPTeamsDistributeParallelForDirective final : public OMPLoopDirective { friend class ASTStmtReader; friend class OMPExecutableDirective; /// true if the construct has inner cancel directive. bool HasCancel = false; /// Build directive with the given start and end location. /// /// \param StartLoc Starting location of the directive kind. /// \param EndLoc Ending location of the directive. /// \param CollapsedNum Number of collapsed nested loops. /// OMPTeamsDistributeParallelForDirective(SourceLocation StartLoc, SourceLocation EndLoc, unsigned CollapsedNum) : OMPLoopDirective(OMPTeamsDistributeParallelForDirectiveClass, llvm::omp::OMPD_teams_distribute_parallel_for, StartLoc, EndLoc, CollapsedNum) {} /// Build an empty directive. /// /// \param CollapsedNum Number of collapsed nested loops. /// explicit OMPTeamsDistributeParallelForDirective(unsigned CollapsedNum) : OMPLoopDirective(OMPTeamsDistributeParallelForDirectiveClass, llvm::omp::OMPD_teams_distribute_parallel_for, SourceLocation(), SourceLocation(), CollapsedNum) {} /// Sets special task reduction descriptor. void setTaskReductionRefExpr(Expr *E) { Data->getChildren()[numLoopChildren( getLoopsNumber(), llvm::omp::OMPD_teams_distribute_parallel_for)] = E; } /// Set cancel state. void setHasCancel(bool Has) { HasCancel = Has; } public: /// Creates directive with a list of \a Clauses. /// /// \param C AST context. /// \param StartLoc Starting location of the directive kind. /// \param EndLoc Ending Location of the directive. /// \param CollapsedNum Number of collapsed loops. /// \param Clauses List of clauses. /// \param AssociatedStmt Statement, associated with the directive. /// \param Exprs Helper expressions for CodeGen. /// \param TaskRedRef Task reduction special reference expression to handle /// taskgroup descriptor. /// \param HasCancel true if this directive has inner cancel directive. /// static OMPTeamsDistributeParallelForDirective * Create(const ASTContext &C, SourceLocation StartLoc, SourceLocation EndLoc, unsigned CollapsedNum, ArrayRef<OMPClause *> Clauses, Stmt *AssociatedStmt, const HelperExprs &Exprs, Expr *TaskRedRef, bool HasCancel); /// Creates an empty directive with the place for \a NumClauses clauses. /// /// \param C AST context. /// \param CollapsedNum Number of collapsed nested loops. /// \param NumClauses Number of clauses. /// static OMPTeamsDistributeParallelForDirective * CreateEmpty(const ASTContext &C, unsigned NumClauses, unsigned CollapsedNum, EmptyShell); /// Returns special task reduction reference expression. Expr *getTaskReductionRefExpr() { return cast_or_null<Expr>(Data->getChildren()[numLoopChildren( getLoopsNumber(), llvm::omp::OMPD_teams_distribute_parallel_for)]); } const Expr *getTaskReductionRefExpr() const { return const_cast<OMPTeamsDistributeParallelForDirective *>(this) ->getTaskReductionRefExpr(); } /// Return true if current directive has inner cancel directive. bool hasCancel() const { return HasCancel; } static bool classof(const Stmt *T) { return T->getStmtClass() == OMPTeamsDistributeParallelForDirectiveClass; } }; /// This represents '#pragma omp target teams' directive. /// /// \code /// #pragma omp target teams if(a>0) /// \endcode /// In this example directive '#pragma omp target teams' has clause 'if' with /// condition 'a>0'. /// class OMPTargetTeamsDirective final : public OMPExecutableDirective { friend class ASTStmtReader; friend class OMPExecutableDirective; /// Build directive with the given start and end location. /// /// \param StartLoc Starting location of the directive kind. /// \param EndLoc Ending location of the directive. /// OMPTargetTeamsDirective(SourceLocation StartLoc, SourceLocation EndLoc) : OMPExecutableDirective(OMPTargetTeamsDirectiveClass, llvm::omp::OMPD_target_teams, StartLoc, EndLoc) { } /// Build an empty directive. /// explicit OMPTargetTeamsDirective() : OMPExecutableDirective(OMPTargetTeamsDirectiveClass, llvm::omp::OMPD_target_teams, SourceLocation(), SourceLocation()) {} public: /// Creates directive with a list of \a Clauses. /// /// \param C AST context. /// \param StartLoc Starting location of the directive kind. /// \param EndLoc Ending Location of the directive. /// \param Clauses List of clauses. /// \param AssociatedStmt Statement, associated with the directive. /// static OMPTargetTeamsDirective *Create(const ASTContext &C, SourceLocation StartLoc, SourceLocation EndLoc, ArrayRef<OMPClause *> Clauses, Stmt *AssociatedStmt); /// Creates an empty directive with the place for \a NumClauses clauses. /// /// \param C AST context. /// \param NumClauses Number of clauses. /// static OMPTargetTeamsDirective *CreateEmpty(const ASTContext &C, unsigned NumClauses, EmptyShell); static bool classof(const Stmt *T) { return T->getStmtClass() == OMPTargetTeamsDirectiveClass; } }; /// This represents '#pragma omp target teams distribute' combined directive. /// /// \code /// #pragma omp target teams distribute private(x) /// \endcode /// In this example directive '#pragma omp target teams distribute' has clause /// 'private' with the variables 'x' /// class OMPTargetTeamsDistributeDirective final : public OMPLoopDirective { friend class ASTStmtReader; friend class OMPExecutableDirective; /// Build directive with the given start and end location. /// /// \param StartLoc Starting location of the directive kind. /// \param EndLoc Ending location of the directive. /// \param CollapsedNum Number of collapsed nested loops. /// OMPTargetTeamsDistributeDirective(SourceLocation StartLoc, SourceLocation EndLoc, unsigned CollapsedNum) : OMPLoopDirective(OMPTargetTeamsDistributeDirectiveClass, llvm::omp::OMPD_target_teams_distribute, StartLoc, EndLoc, CollapsedNum) {} /// Build an empty directive. /// /// \param CollapsedNum Number of collapsed nested loops. /// explicit OMPTargetTeamsDistributeDirective(unsigned CollapsedNum) : OMPLoopDirective(OMPTargetTeamsDistributeDirectiveClass, llvm::omp::OMPD_target_teams_distribute, SourceLocation(), SourceLocation(), CollapsedNum) {} public: /// Creates directive with a list of \a Clauses. /// /// \param C AST context. /// \param StartLoc Starting location of the directive kind. /// \param EndLoc Ending Location of the directive. /// \param CollapsedNum Number of collapsed loops. /// \param Clauses List of clauses. /// \param AssociatedStmt Statement, associated with the directive. /// \param Exprs Helper expressions for CodeGen. /// static OMPTargetTeamsDistributeDirective * Create(const ASTContext &C, SourceLocation StartLoc, SourceLocation EndLoc, unsigned CollapsedNum, ArrayRef<OMPClause *> Clauses, Stmt *AssociatedStmt, const HelperExprs &Exprs); /// Creates an empty directive with the place for \a NumClauses clauses. /// /// \param C AST context. /// \param CollapsedNum Number of collapsed nested loops. /// \param NumClauses Number of clauses. /// static OMPTargetTeamsDistributeDirective * CreateEmpty(const ASTContext &C, unsigned NumClauses, unsigned CollapsedNum, EmptyShell); static bool classof(const Stmt *T) { return T->getStmtClass() == OMPTargetTeamsDistributeDirectiveClass; } }; /// This represents '#pragma omp target teams distribute parallel for' combined /// directive. /// /// \code /// #pragma omp target teams distribute parallel for private(x) /// \endcode /// In this example directive '#pragma omp target teams distribute parallel /// for' has clause 'private' with the variables 'x' /// class OMPTargetTeamsDistributeParallelForDirective final : public OMPLoopDirective { friend class ASTStmtReader; friend class OMPExecutableDirective; /// true if the construct has inner cancel directive. bool HasCancel = false; /// Build directive with the given start and end location. /// /// \param StartLoc Starting location of the directive kind. /// \param EndLoc Ending location of the directive. /// \param CollapsedNum Number of collapsed nested loops. /// OMPTargetTeamsDistributeParallelForDirective(SourceLocation StartLoc, SourceLocation EndLoc, unsigned CollapsedNum) : OMPLoopDirective(OMPTargetTeamsDistributeParallelForDirectiveClass, llvm::omp::OMPD_target_teams_distribute_parallel_for, StartLoc, EndLoc, CollapsedNum) {} /// Build an empty directive. /// /// \param CollapsedNum Number of collapsed nested loops. /// explicit OMPTargetTeamsDistributeParallelForDirective(unsigned CollapsedNum) : OMPLoopDirective(OMPTargetTeamsDistributeParallelForDirectiveClass, llvm::omp::OMPD_target_teams_distribute_parallel_for, SourceLocation(), SourceLocation(), CollapsedNum) {} /// Sets special task reduction descriptor. void setTaskReductionRefExpr(Expr *E) { Data->getChildren()[numLoopChildren( getLoopsNumber(), llvm::omp::OMPD_target_teams_distribute_parallel_for)] = E; } /// Set cancel state. void setHasCancel(bool Has) { HasCancel = Has; } public: /// Creates directive with a list of \a Clauses. /// /// \param C AST context. /// \param StartLoc Starting location of the directive kind. /// \param EndLoc Ending Location of the directive. /// \param CollapsedNum Number of collapsed loops. /// \param Clauses List of clauses. /// \param AssociatedStmt Statement, associated with the directive. /// \param Exprs Helper expressions for CodeGen. /// \param TaskRedRef Task reduction special reference expression to handle /// taskgroup descriptor. /// \param HasCancel true if this directive has inner cancel directive. /// static OMPTargetTeamsDistributeParallelForDirective * Create(const ASTContext &C, SourceLocation StartLoc, SourceLocation EndLoc, unsigned CollapsedNum, ArrayRef<OMPClause *> Clauses, Stmt *AssociatedStmt, const HelperExprs &Exprs, Expr *TaskRedRef, bool HasCancel); /// Creates an empty directive with the place for \a NumClauses clauses. /// /// \param C AST context. /// \param CollapsedNum Number of collapsed nested loops. /// \param NumClauses Number of clauses. /// static OMPTargetTeamsDistributeParallelForDirective * CreateEmpty(const ASTContext &C, unsigned NumClauses, unsigned CollapsedNum, EmptyShell); /// Returns special task reduction reference expression. Expr *getTaskReductionRefExpr() { return cast_or_null<Expr>(Data->getChildren()[numLoopChildren( getLoopsNumber(), llvm::omp::OMPD_target_teams_distribute_parallel_for)]); } const Expr *getTaskReductionRefExpr() const { return const_cast<OMPTargetTeamsDistributeParallelForDirective *>(this) ->getTaskReductionRefExpr(); } /// Return true if current directive has inner cancel directive. bool hasCancel() const { return HasCancel; } static bool classof(const Stmt *T) { return T->getStmtClass() == OMPTargetTeamsDistributeParallelForDirectiveClass; } }; /// This represents '#pragma omp target teams distribute parallel for simd' /// combined directive. /// /// \code /// #pragma omp target teams distribute parallel for simd private(x) /// \endcode /// In this example directive '#pragma omp target teams distribute parallel /// for simd' has clause 'private' with the variables 'x' /// class OMPTargetTeamsDistributeParallelForSimdDirective final : public OMPLoopDirective { friend class ASTStmtReader; friend class OMPExecutableDirective; /// Build directive with the given start and end location. /// /// \param StartLoc Starting location of the directive kind. /// \param EndLoc Ending location of the directive. /// \param CollapsedNum Number of collapsed nested loops. /// OMPTargetTeamsDistributeParallelForSimdDirective(SourceLocation StartLoc, SourceLocation EndLoc, unsigned CollapsedNum) : OMPLoopDirective( OMPTargetTeamsDistributeParallelForSimdDirectiveClass, llvm::omp::OMPD_target_teams_distribute_parallel_for_simd, StartLoc, EndLoc, CollapsedNum) {} /// Build an empty directive. /// /// \param CollapsedNum Number of collapsed nested loops. /// explicit OMPTargetTeamsDistributeParallelForSimdDirective( unsigned CollapsedNum) : OMPLoopDirective( OMPTargetTeamsDistributeParallelForSimdDirectiveClass, llvm::omp::OMPD_target_teams_distribute_parallel_for_simd, SourceLocation(), SourceLocation(), CollapsedNum) {} public: /// Creates directive with a list of \a Clauses. /// /// \param C AST context. /// \param StartLoc Starting location of the directive kind. /// \param EndLoc Ending Location of the directive. /// \param CollapsedNum Number of collapsed loops. /// \param Clauses List of clauses. /// \param AssociatedStmt Statement, associated with the directive. /// \param Exprs Helper expressions for CodeGen. /// static OMPTargetTeamsDistributeParallelForSimdDirective * Create(const ASTContext &C, SourceLocation StartLoc, SourceLocation EndLoc, unsigned CollapsedNum, ArrayRef<OMPClause *> Clauses, Stmt *AssociatedStmt, const HelperExprs &Exprs); /// Creates an empty directive with the place for \a NumClauses clauses. /// /// \param C AST context. /// \param CollapsedNum Number of collapsed nested loops. /// \param NumClauses Number of clauses. /// static OMPTargetTeamsDistributeParallelForSimdDirective * CreateEmpty(const ASTContext &C, unsigned NumClauses, unsigned CollapsedNum, EmptyShell); static bool classof(const Stmt *T) { return T->getStmtClass() == OMPTargetTeamsDistributeParallelForSimdDirectiveClass; } }; /// This represents '#pragma omp target teams distribute simd' combined /// directive. /// /// \code /// #pragma omp target teams distribute simd private(x) /// \endcode /// In this example directive '#pragma omp target teams distribute simd' /// has clause 'private' with the variables 'x' /// class OMPTargetTeamsDistributeSimdDirective final : public OMPLoopDirective { friend class ASTStmtReader; friend class OMPExecutableDirective; /// Build directive with the given start and end location. /// /// \param StartLoc Starting location of the directive kind. /// \param EndLoc Ending location of the directive. /// \param CollapsedNum Number of collapsed nested loops. /// OMPTargetTeamsDistributeSimdDirective(SourceLocation StartLoc, SourceLocation EndLoc, unsigned CollapsedNum) : OMPLoopDirective(OMPTargetTeamsDistributeSimdDirectiveClass, llvm::omp::OMPD_target_teams_distribute_simd, StartLoc, EndLoc, CollapsedNum) {} /// Build an empty directive. /// /// \param CollapsedNum Number of collapsed nested loops. /// explicit OMPTargetTeamsDistributeSimdDirective(unsigned CollapsedNum) : OMPLoopDirective(OMPTargetTeamsDistributeSimdDirectiveClass, llvm::omp::OMPD_target_teams_distribute_simd, SourceLocation(), SourceLocation(), CollapsedNum) {} public: /// Creates directive with a list of \a Clauses. /// /// \param C AST context. /// \param StartLoc Starting location of the directive kind. /// \param EndLoc Ending Location of the directive. /// \param CollapsedNum Number of collapsed loops. /// \param Clauses List of clauses. /// \param AssociatedStmt Statement, associated with the directive. /// \param Exprs Helper expressions for CodeGen. /// static OMPTargetTeamsDistributeSimdDirective * Create(const ASTContext &C, SourceLocation StartLoc, SourceLocation EndLoc, unsigned CollapsedNum, ArrayRef<OMPClause *> Clauses, Stmt *AssociatedStmt, const HelperExprs &Exprs); /// Creates an empty directive with the place for \a NumClauses clauses. /// /// \param C AST context. /// \param CollapsedNum Number of collapsed nested loops. /// \param NumClauses Number of clauses. /// static OMPTargetTeamsDistributeSimdDirective * CreateEmpty(const ASTContext &C, unsigned NumClauses, unsigned CollapsedNum, EmptyShell); static bool classof(const Stmt *T) { return T->getStmtClass() == OMPTargetTeamsDistributeSimdDirectiveClass; } }; /// This represents the '#pragma omp tile' loop transformation directive. class OMPTileDirective final : public OMPLoopBasedDirective { friend class ASTStmtReader; friend class OMPExecutableDirective; /// Default list of offsets. enum { PreInitsOffset = 0, TransformedStmtOffset, }; explicit OMPTileDirective(SourceLocation StartLoc, SourceLocation EndLoc, unsigned NumLoops) : OMPLoopBasedDirective(OMPTileDirectiveClass, llvm::omp::OMPD_tile, StartLoc, EndLoc, NumLoops) {} void setPreInits(Stmt *PreInits) { Data->getChildren()[PreInitsOffset] = PreInits; } void setTransformedStmt(Stmt *S) { Data->getChildren()[TransformedStmtOffset] = S; } public: /// Create a new AST node representation for '#pragma omp tile'. /// /// \param C Context of the AST. /// \param StartLoc Location of the introducer (e.g. the 'omp' token). /// \param EndLoc Location of the directive's end (e.g. the tok::eod). /// \param Clauses The directive's clauses. /// \param NumLoops Number of associated loops (number of items in the /// 'sizes' clause). /// \param AssociatedStmt The outermost associated loop. /// \param TransformedStmt The loop nest after tiling, or nullptr in /// dependent contexts. /// \param PreInits Helper preinits statements for the loop nest. static OMPTileDirective *Create(const ASTContext &C, SourceLocation StartLoc, SourceLocation EndLoc, ArrayRef<OMPClause *> Clauses, unsigned NumLoops, Stmt *AssociatedStmt, Stmt *TransformedStmt, Stmt *PreInits); /// Build an empty '#pragma omp tile' AST node for deserialization. /// /// \param C Context of the AST. /// \param NumClauses Number of clauses to allocate. /// \param NumLoops Number of associated loops to allocate. static OMPTileDirective *CreateEmpty(const ASTContext &C, unsigned NumClauses, unsigned NumLoops); unsigned getNumAssociatedLoops() const { return getLoopsNumber(); } /// Gets/sets the associated loops after tiling. /// /// This is in de-sugared format stored as a CompoundStmt. /// /// \code /// for (...) /// ... /// \endcode /// /// Note that if the generated loops a become associated loops of another /// directive, they may need to be hoisted before them. Stmt *getTransformedStmt() const { return Data->getChildren()[TransformedStmtOffset]; } /// Return preinits statement. Stmt *getPreInits() const { return Data->getChildren()[PreInitsOffset]; } static bool classof(const Stmt *T) { return T->getStmtClass() == OMPTileDirectiveClass; } }; /// This represents '#pragma omp scan' directive. /// /// \code /// #pragma omp scan inclusive(a) /// \endcode /// In this example directive '#pragma omp scan' has clause 'inclusive' with /// list item 'a'. class OMPScanDirective final : public OMPExecutableDirective { friend class ASTStmtReader; friend class OMPExecutableDirective; /// Build directive with the given start and end location. /// /// \param StartLoc Starting location of the directive kind. /// \param EndLoc Ending location of the directive. /// OMPScanDirective(SourceLocation StartLoc, SourceLocation EndLoc) : OMPExecutableDirective(OMPScanDirectiveClass, llvm::omp::OMPD_scan, StartLoc, EndLoc) {} /// Build an empty directive. /// explicit OMPScanDirective() : OMPExecutableDirective(OMPScanDirectiveClass, llvm::omp::OMPD_scan, SourceLocation(), SourceLocation()) {} public: /// Creates directive with a list of \a Clauses. /// /// \param C AST context. /// \param StartLoc Starting location of the directive kind. /// \param EndLoc Ending Location of the directive. /// \param Clauses List of clauses (only single OMPFlushClause clause is /// allowed). /// static OMPScanDirective *Create(const ASTContext &C, SourceLocation StartLoc, SourceLocation EndLoc, ArrayRef<OMPClause *> Clauses); /// Creates an empty directive with the place for \a NumClauses /// clauses. /// /// \param C AST context. /// \param NumClauses Number of clauses. /// static OMPScanDirective *CreateEmpty(const ASTContext &C, unsigned NumClauses, EmptyShell); static bool classof(const Stmt *T) { return T->getStmtClass() == OMPScanDirectiveClass; } }; /// This represents '#pragma omp interop' directive. /// /// \code /// #pragma omp interop init(target:obj) device(x) depend(inout:y) nowait /// \endcode /// In this example directive '#pragma omp interop' has /// clauses 'init', 'device', 'depend' and 'nowait'. /// class OMPInteropDirective final : public OMPExecutableDirective { friend class ASTStmtReader; friend class OMPExecutableDirective; /// Build directive with the given start and end location. /// /// \param StartLoc Starting location of the directive. /// \param EndLoc Ending location of the directive. /// OMPInteropDirective(SourceLocation StartLoc, SourceLocation EndLoc) : OMPExecutableDirective(OMPInteropDirectiveClass, llvm::omp::OMPD_interop, StartLoc, EndLoc) {} /// Build an empty directive. /// explicit OMPInteropDirective() : OMPExecutableDirective(OMPInteropDirectiveClass, llvm::omp::OMPD_interop, SourceLocation(), SourceLocation()) {} public: /// Creates directive. /// /// \param C AST context. /// \param StartLoc Starting location of the directive. /// \param EndLoc Ending Location of the directive. /// \param Clauses The directive's clauses. /// static OMPInteropDirective *Create(const ASTContext &C, SourceLocation StartLoc, SourceLocation EndLoc, ArrayRef<OMPClause *> Clauses); /// Creates an empty directive. /// /// \param C AST context. /// static OMPInteropDirective *CreateEmpty(const ASTContext &C, unsigned NumClauses, EmptyShell); static bool classof(const Stmt *T) { return T->getStmtClass() == OMPInteropDirectiveClass; } }; } // end namespace clang #endif
density.c
#include <stdio.h> #include <stdlib.h> #include <complex.h> #include <math.h> #include <omp.h> #include <time.h> #include <mkl.h> #include <mkl_types.h> #include "utils.h" #include "density.h" #include "linalg.h" #define PI 3.14159265359 // THE FOLLOWING TWO FUNCTIONS ARE NOT YET IMPLEMENTED /* double* ncl_ae_state_density(int BAND_NUM, pswf_t* wf, int* fftg, int* labels, double* coords) { int gridsize = fftg[0] * fftg[1] * fftg[2]; double* P = mkl_calloc(gridsize, sizeof(double), 64); int spin_mult = 2 / wf->nspin; double complex* x = realspace_state(b, k, wf, fftg, labels, coords); for (int i = 0; i < gridsize; i++) { P[i] += creal(x[i] * conj(x[i])); } mkl_free(x); return P; } */ void ae_state_density(double* P, int BAND_NUM, int KPOINT_NUM, pswf_t* wf, int* fftg, int* labels, double* coords) { int gridsize = fftg[0] * fftg[1] * fftg[2]; //double* P = mkl_calloc(gridsize, sizeof(double), 64); double complex* x = mkl_malloc(gridsize * sizeof(double complex), 64); realspace_state(x, BAND_NUM, KPOINT_NUM, wf, fftg, labels, coords); for (int i = 0; i < gridsize; i++) { P[i] += creal(x[i] * conj(x[i])); } mkl_free(x); } /* void ae_state_density(double* P, int BAND_NUM, int KPOINT_NUM, pswf_t* wf, int* fftg, int* labels, double* coords) { ppot_t* pps = wf->pps; int num_sites = wf->num_sites; double complex* x = (double complex*) mkl_malloc(fftg[0]*fftg[1]*fftg[2]*sizeof(double complex), 64); fft3d(x, wf->G_bounds, wf->lattice, wf->kpts[KPOINT_NUM]->k, wf->kpts[KPOINT_NUM]->Gs, wf->kpts[KPOINT_NUM]->bands[BAND_NUM]->Cs, wf->kpts[KPOINT_NUM]->bands[BAND_NUM]->num_waves, fftg); //printf("FINISH FT\n"); double* lattice = wf->lattice; double vol = determinant(lattice); for (int i = 0; i < fftg[0]; i++) { double frac[3] = {0,0,0}; double kdotr = 0; for (int j = 0; j < fftg[1]; j++) { for (int k = 0; k < fftg[2]; k++) { P[i*fftg[1]*fftg[2] + j*fftg[2] + k] = creal(x[i*fftg[1]*fftg[2] + j*fftg[2] + k] * conj(x[i*fftg[1]*fftg[2] + j*fftg[2] + k])); } } } for (int p = 0; p < num_sites; p++) { projection_t pros = wf->kpts[KPOINT_NUM]->bands[BAND_NUM]->projections[p]; //printf("READ PROJECTIONS\n"); ppot_t pp = pps[labels[p]]; double rmax = pp.wave_grid[pp.wave_gridsize-1]; double res[3] = {0,0,0}; vcross(res, lattice+3, lattice+6); int grid1 = (int) (mag(res) * rmax / vol * fftg[0]) + 1; vcross(res, lattice+0, lattice+6); int grid2 = (int) (mag(res) * rmax / vol * fftg[1]) + 1; vcross(res, lattice+0, lattice+3); int grid3 = (int) (mag(res) * rmax / vol * fftg[2]) + 1; int center1 = (int) round(coords[3*p+0] * fftg[0]); int center2 = (int) round(coords[3*p+1] * fftg[1]); int center3 = (int) round(coords[3*p+2] * fftg[2]); //printf("FINISH SETUP %d\n%d %d %d\n%d %d %d\n",p, center1, center2, center3, grid1, grid2, grid3); for (int i = -grid1 + center1; i <= grid1 + center1; i++) { double frac[3] = {0,0,0}; double testcoord[3] = {0,0,0}; int ii=0, jj=0, kk=0; double phasecoord[3] = {0,0,0}; double phase = 0; for (int j = -grid2 + center2; j <= grid2 + center2; j++) { for (int k = -grid3 + center3; k <= grid3 + center3; k++) { testcoord[0] = (double) i / fftg[0] - coords[3*p+0]; testcoord[1] = (double) j / fftg[1] - coords[3*p+1]; testcoord[2] = (double) k / fftg[2] - coords[3*p+2]; frac_to_cartesian(testcoord, lattice); if (mag(testcoord) < rmax) { ii = (i%fftg[0] + fftg[0]) % fftg[0]; jj = (j%fftg[1] + fftg[1]) % fftg[1]; kk = (k%fftg[2] + fftg[2]) % fftg[2]; frac[0] = (double) ii / fftg[0]; frac[1] = (double) jj / fftg[1]; frac[2] = (double) kk / fftg[2]; phasecoord[0] = coords[3*p+0] + ((ii-i) / fftg[0]); phasecoord[1] = coords[3*p+1] + ((jj-j) / fftg[1]); phasecoord[2] = coords[3*p+2] + ((kk-k) / fftg[2]); phase = dot(phasecoord, wf->kpts[KPOINT_NUM]->k); for (int n = 0; n < pros.total_projs; n++) { for (int m = 0; m < pros.total_projs; m++) { P[ii*fftg[1]*fftg[2] + jj*fftg[2] + kk] += creal( wave_value2(pp.wave_grid, pp.funcs[pros.ns[n]].aewave, pp.funcs[pros.ns[n]].aewave_spline, pp.wave_gridsize, pros.ls[n], pros.ms[n], testcoord) * conj(wave_value2(pp.wave_grid, pp.funcs[pros.ns[m]].aewave, pp.funcs[pros.ns[m]].aewave_spline, pp.wave_gridsize, pros.ls[m], pros.ms[m], testcoord)) * pros.overlaps[n] * conj(pros.overlaps[m]) ); P[ii*fftg[1]*fftg[2] + jj*fftg[2] + kk] -= creal( wave_value2(pp.wave_grid, pp.funcs[pros.ns[n]].pswave, pp.funcs[pros.ns[n]].pswave_spline, pp.wave_gridsize, pros.ls[n], pros.ms[n], testcoord) * conj(wave_value2(pp.wave_grid, pp.funcs[pros.ns[m]].pswave, pp.funcs[pros.ns[m]].pswave_spline, pp.wave_gridsize, pros.ls[m], pros.ms[m], testcoord)) * pros.overlaps[n] * conj(pros.overlaps[m]) ); } // wave_value(pp.funcs[pros.ns[n]], // pp.wave_gridsize, pp.wave_grid, // pros.ms[n], coords+3*p, frac, lattice) // * pros.overlaps[n] * cexp(2*PI*I*phase); // * Ylm(thetaphi[0], thetaphi[1]); } } } } } } mkl_free(x); } */ void ae_chg_density(double* P, pswf_t* wf, int* fftg, int* labels, double* coords) { int gridsize = fftg[0] * fftg[1] * fftg[2]; double complex* x = mkl_malloc(gridsize * sizeof(double complex), 64); //double* P = mkl_calloc(gridsize, sizeof(double), 64); int spin_mult = 2 / wf->nspin; for (int k = 0; k < wf->nwk * wf->nspin; k++) { //printf("KLOOP %d\n", k); for (int b = 0; b < wf->nband; b++) { if (wf->kpts[k]->bands[b]->occ > 0) { realspace_state(x, b, k, wf, fftg, labels, coords); for (int i = 0; i < gridsize; i++) { P[i] += creal(x[i] * conj(x[i])) * wf->kpts[k]->weight * wf->kpts[k]->bands[b]->occ * spin_mult; } } } } mkl_free(x); mkl_free_buffers(); } void ncl_ae_chg_density(double* P, pswf_t* wf, int* fftg, int* labels, double* coords) { int gridsize = fftg[0] * fftg[1] * fftg[2]; double complex* x = mkl_malloc(2 * gridsize * sizeof(double complex), 64); //double* P = mkl_calloc(gridsize, sizeof(double), 64); int spin_mult = 1; for (int k = 0; k < wf->nwk * wf->nspin; k++) { //printf("KLOOP %d\n", k); for (int b = 0; b < wf->nband; b++) { if (wf->kpts[k]->bands[b]->occ > 0) { ncl_realspace_state(x, b, k, wf, fftg, labels, coords); for (int i = 0; i < gridsize; i++) { P[i] += (creal(x[i] * conj(x[i])) + creal(x[i+gridsize] * conj(x[i+gridsize]))) * wf->kpts[k]->weight * wf->kpts[k]->bands[b]->occ * spin_mult; } } } } mkl_free(x); mkl_free_buffers(); } void project_realspace_state(double complex* projs, int BAND_NUM, pswf_t* wf, pswf_t* wf_R, int* fftg, int* labels, double* coords, int* labels_R, double* coords_R) { int nband = wf->nband; int nwk = wf->nwk; int nspin = wf->nspin; int gridsize = fftg[0]*fftg[1]*fftg[2]; //double* projs = (double*) malloc(2*nband*nwk*nspin*sizeof(double)); double vol = determinant(wf->lattice); double complex* state = mkl_malloc(gridsize * sizeof(double complex), 64); double complex* state_R = mkl_malloc(gridsize * sizeof(double complex), 64); for (int k = 0; k < nwk * nspin; k++) { double complex overlap = 0; realspace_state(state, BAND_NUM, k, wf, fftg, labels, coords); for (int b = 0; b < nband; b++) { realspace_state(state_R, b, k, wf_R, fftg, labels_R, coords_R); cblas_zdotc_sub(gridsize, state_R, 1, state, 1, &overlap); overlap *= vol / gridsize; projs[b*nwk*nspin + k] = overlap; } } mkl_free(state_R); mkl_free(state); } void realspace_state(double complex* x, int BAND_NUM, int KPOINT_NUM, pswf_t* wf, int* fftg, int* labels, double* coords) { ppot_t* pps = wf->pps; //double complex* x = mkl_calloc(fftg[0]*fftg[1]*fftg[2], sizeof(double complex), 64); //printf("START FT\n"); fft3d(x, wf->G_bounds, wf->lattice, wf->kpts[KPOINT_NUM]->k, wf->kpts[KPOINT_NUM]->Gs, wf->kpts[KPOINT_NUM]->bands[BAND_NUM]->Cs, wf->kpts[KPOINT_NUM]->bands[BAND_NUM]->num_waves, fftg); //printf("FINISH FT\n"); double* lattice = wf->lattice; double vol = determinant(lattice); for (int i = 0; i < fftg[0]; i++) { double frac[3] = {0,0,0}; double kdotr = 0; for (int j = 0; j < fftg[1]; j++) { for (int k = 0; k < fftg[2]; k++) { frac[0] = (double) i / fftg[0]; frac[1] = (double) j / fftg[1]; frac[2] = (double) k / fftg[2]; kdotr = dot(wf->kpts[KPOINT_NUM]->k, frac); x[i*fftg[1]*fftg[2] + j*fftg[2] + k] *= cexp(2*PI*I*kdotr); } } } int num_sites = wf->num_sites; #pragma omp parallel for for (int p = 0; p < num_sites; p++) { projection_t pros = wf->kpts[KPOINT_NUM]->bands[BAND_NUM]->projections[p]; //printf("READ PROJECTIONS\n"); ppot_t pp = pps[labels[p]]; double rmax = pp.wave_grid[pp.wave_gridsize-1]; double res[3] = {0,0,0}; vcross(res, lattice+3, lattice+6); int grid1 = (int) (mag(res) * rmax / vol * fftg[0]) + 1; vcross(res, lattice+0, lattice+6); int grid2 = (int) (mag(res) * rmax / vol * fftg[1]) + 1; vcross(res, lattice+0, lattice+3); int grid3 = (int) (mag(res) * rmax / vol * fftg[2]) + 1; int center1 = (int) round(coords[3*p+0] * fftg[0]); int center2 = (int) round(coords[3*p+1] * fftg[1]); int center3 = (int) round(coords[3*p+2] * fftg[2]); //printf("FINISH SETUP %d\n%d %d %d\n%d %d %d\n",p, center1, center2, center3, grid1, grid2, grid3); for (int i = -grid1 + center1; i <= grid1 + center1; i++) { double frac[3] = {0,0,0}; double testcoord[3] = {0,0,0}; int ii=0, jj=0, kk=0; double phasecoord[3] = {0,0,0}; double phase = 0; for (int j = -grid2 + center2; j <= grid2 + center2; j++) { for (int k = -grid3 + center3; k <= grid3 + center3; k++) { testcoord[0] = (double) i / fftg[0] - coords[3*p+0]; testcoord[1] = (double) j / fftg[1] - coords[3*p+1]; testcoord[2] = (double) k / fftg[2] - coords[3*p+2]; frac_to_cartesian(testcoord, lattice); if (mag(testcoord) < rmax) { ii = (i%fftg[0] + fftg[0]) % fftg[0]; jj = (j%fftg[1] + fftg[1]) % fftg[1]; kk = (k%fftg[2] + fftg[2]) % fftg[2]; frac[0] = (double) ii / fftg[0]; frac[1] = (double) jj / fftg[1]; frac[2] = (double) kk / fftg[2]; phasecoord[0] = coords[3*p+0] + ((ii-i) / fftg[0]); phasecoord[1] = coords[3*p+1] + ((jj-j) / fftg[1]); phasecoord[2] = coords[3*p+2] + ((kk-k) / fftg[2]); phase = dot(phasecoord, wf->kpts[KPOINT_NUM]->k); for (int n = 0; n < pros.total_projs; n++) { x[ii*fftg[1]*fftg[2] + jj*fftg[2] + kk] += wave_value2(pp.wave_grid, pp.funcs[pros.ns[n]].diffwave, pp.funcs[pros.ns[n]].diffwave_spline, pp.wave_gridsize, pros.ls[n], pros.ms[n], testcoord) * pros.overlaps[n] * cexp(2*PI*I*phase); // wave_value(pp.funcs[pros.ns[n]], // pp.wave_gridsize, pp.wave_grid, // pros.ms[n], coords+3*p, frac, lattice) // * pros.overlaps[n] * cexp(2*PI*I*phase); // * Ylm(thetaphi[0], thetaphi[1]); } } } } } } } void remove_phase(double complex* x, int KPOINT_NUM, pswf_t* wf, int* fftg) { for (int i = 0; i < fftg[0]; i++) { double frac[3] = {0,0,0}; double kdotr = 0; for (int j = 0; j < fftg[1]; j++) { for (int k = 0; k < fftg[2]; k++) { frac[0] = (double) i / fftg[0]; frac[1] = (double) j / fftg[1]; frac[2] = (double) k / fftg[2]; kdotr = dot(wf->kpts[KPOINT_NUM]->k, frac); x[i*fftg[1]*fftg[2] + j*fftg[2] + k] *= cexp(-2*PI*I*kdotr); } } } } void ncl_realspace_state(double complex* x, int BAND_NUM, int KPOINT_NUM, pswf_t* wf, int* fftg, int* labels, double* coords) { ppot_t* pps = wf->pps; double complex* xup = x;//mkl_calloc(2*fftg[0]*fftg[1]*fftg[2], sizeof(double complex), 64); double complex* xdown = x + fftg[0]*fftg[1]*fftg[2]; int num_waves = wf->kpts[KPOINT_NUM]->bands[BAND_NUM]->num_waves / 2; fft3d(xup, wf->G_bounds, wf->lattice, wf->kpts[KPOINT_NUM]->k, wf->kpts[KPOINT_NUM]->Gs, wf->kpts[KPOINT_NUM]->bands[BAND_NUM]->Cs, num_waves, fftg); fft3d(xdown, wf->G_bounds, wf->lattice, wf->kpts[KPOINT_NUM]->k, wf->kpts[KPOINT_NUM]->Gs, wf->kpts[KPOINT_NUM]->bands[BAND_NUM]->Cs + num_waves, num_waves, fftg); double* lattice = wf->lattice; double vol = determinant(lattice); for (int i = 0; i < fftg[0]; i++) { double frac[3] = {0,0,0}; double kdotr = 0; for (int j = 0; j < fftg[1]; j++) { for (int k = 0; k < fftg[2]; k++) { frac[0] = (double) i / fftg[0]; frac[1] = (double) j / fftg[1]; frac[2] = (double) k / fftg[2]; kdotr = dot(wf->kpts[KPOINT_NUM]->k, frac); xup[i*fftg[1]*fftg[2] + j*fftg[2] + k] *= cexp(2*PI*I*kdotr); xdown[i*fftg[1]*fftg[2] + j*fftg[2] + k] *= cexp(2*PI*I*kdotr); } } } int num_sites = wf->num_sites; #pragma omp parallel for for (int p = 0; p < num_sites; p++) { projection_t up_pros = wf->kpts[KPOINT_NUM]->bands[BAND_NUM]->up_projections[p]; projection_t down_pros = wf->kpts[KPOINT_NUM]->bands[BAND_NUM]->down_projections[p]; ppot_t pp = pps[labels[p]]; double rmax = pp.wave_grid[pp.wave_gridsize-1]; double res[3] = {0,0,0}; vcross(res, lattice+3, lattice+6); int grid1 = (int) (mag(res) * rmax / vol * fftg[0]) + 1; vcross(res, lattice+0, lattice+6); int grid2 = (int) (mag(res) * rmax / vol * fftg[1]) + 1; vcross(res, lattice+0, lattice+3); int grid3 = (int) (mag(res) * rmax / vol * fftg[2]) + 1; int center1 = (int) round(coords[3*p+0] * fftg[0]); int center2 = (int) round(coords[3*p+1] * fftg[1]); int center3 = (int) round(coords[3*p+2] * fftg[2]); for (int i = -grid1 + center1; i <= grid1 + center1; i++) { double frac[3] = {0,0,0}; double testcoord[3] = {0,0,0}; int ii=0, jj=0, kk=0; double phasecoord[3] = {0,0,0}; double phase = 0; for (int j = -grid2 + center2; j <= grid2 + center2; j++) { for (int k = -grid3 + center3; k <= grid3 + center3; k++) { testcoord[0] = (double) i / fftg[0] - coords[3*p+0]; testcoord[1] = (double) j / fftg[1] - coords[3*p+1]; testcoord[2] = (double) k / fftg[2] - coords[3*p+2]; frac_to_cartesian(testcoord, lattice); if (mag(testcoord) < rmax) { ii = (i%fftg[0] + fftg[0]) % fftg[0]; jj = (j%fftg[1] + fftg[1]) % fftg[1]; kk = (k%fftg[2] + fftg[2]) % fftg[2]; frac[0] = (double) ii / fftg[0]; frac[1] = (double) jj / fftg[1]; frac[2] = (double) kk / fftg[2]; phasecoord[0] = coords[3*p+0] + ((ii-i) / fftg[0]); phasecoord[1] = coords[3*p+1] + ((jj-j) / fftg[1]); phasecoord[2] = coords[3*p+2] + ((kk-k) / fftg[2]); phase = dot(phasecoord, wf->kpts[KPOINT_NUM]->k); for (int n = 0; n < up_pros.total_projs; n++) { xup[ii*fftg[1]*fftg[2] + jj*fftg[2] + kk] += wave_value(pp.funcs[up_pros.ns[n]], pp.wave_gridsize, pp.wave_grid, up_pros.ms[n], coords+3*p, frac, lattice) * up_pros.overlaps[n] * cexp(2*PI*I*phase); xdown[ii*fftg[1]*fftg[2] + jj*fftg[2] + kk] += wave_value(pp.funcs[down_pros.ns[n]], pp.wave_gridsize, pp.wave_grid, down_pros.ms[n], coords+3*p, frac, lattice) * down_pros.overlaps[n] * cexp(2*PI*I*phase); } } } } } } } double* realspace_state_ri(int BAND_NUM, int KPOINT_NUM, pswf_t* wf, int* fftg, int* labels, double* coords) { int gridsize = fftg[0]*fftg[1]*fftg[2]; double complex* x = mkl_malloc(gridsize * sizeof(double complex), 64); realspace_state(x, BAND_NUM, KPOINT_NUM, wf, fftg, labels, coords); double* rpip = (double*) malloc(2 * gridsize * sizeof(double)); for (int i = 0; i < gridsize; i++) { rpip[i] = creal(x[i]); rpip[i+gridsize] = cimag(x[i]); } mkl_free(x); return rpip; } double* realspace_state_ncl_ri(int BAND_NUM, int KPOINT_NUM, pswf_t* wf, int* fftg, int* labels, double* coords) { int gridsize = 2*fftg[0]*fftg[1]*fftg[2]; double complex* x = mkl_malloc(2 * gridsize * sizeof(double complex), 64); ncl_realspace_state(x, BAND_NUM, KPOINT_NUM, wf, fftg, labels, coords); double* rpip = (double*) malloc(2*gridsize * sizeof(double)); for (int i = 0; i < gridsize; i++) { rpip[i] = creal(x[i]); rpip[i+gridsize] = cimag(x[i]); } mkl_free(x); return rpip; } void write_volumetric(char* filename, double* x, int* fftg, double scale) { FILE* fp = fopen(filename, "w"); int t = 1; for (int k = 0; k < fftg[2]; k++) { for (int j = 0; j < fftg[1]; j++) { for (int i = 0; i < fftg[0]; i++) { fprintf(fp, "%E ", x[i*fftg[1]*fftg[2] + j*fftg[2] + k] * scale); if (t % 5 == 0) fprintf(fp, "\n"); t++; } } } fclose(fp); } void write_realspace_state_ncl_ri(char* filename1, char* filename2, char* filename3, char* filename4, int BAND_NUM, int KPOINT_NUM, pswf_t* wf, int* fftg, int* labels, double* coords) { int gridsize = fftg[0]*fftg[1]*fftg[2]; double* x = realspace_state_ncl_ri(BAND_NUM, KPOINT_NUM, wf, fftg, labels, coords); write_volumetric(filename1, x+0*gridsize, fftg, 1); write_volumetric(filename2, x+1*gridsize, fftg, 1); write_volumetric(filename3, x+2*gridsize, fftg, 1); write_volumetric(filename4, x+3*gridsize, fftg, 1); free(x); } double* write_realspace_state_ri_return(char* filename1, char* filename2, int BAND_NUM, int KPOINT_NUM, pswf_t* wf, int* fftg, int* labels, double* coords) { double* x = realspace_state_ri(BAND_NUM, KPOINT_NUM, wf, fftg, labels, coords); write_volumetric(filename1, x, fftg, 1); write_volumetric(filename2, x+fftg[0]*fftg[1]*fftg[2], fftg, 1); return x; } double* write_density_return(char* filename, pswf_t* wf, int* fftg, int* labels, double* coords) { int gridsize = fftg[0] * fftg[1] * fftg[2]; double* x = mkl_calloc(gridsize, sizeof(double), 64); ae_chg_density(x, wf, fftg, labels, coords); double scale = determinant(wf->lattice); write_volumetric(filename, x, fftg, scale); return x; } void write_realspace_state_ri_noreturn(char* filename1, char* filename2, int BAND_NUM, int KPOINT_NUM, pswf_t* wf, int* fftg, int* labels, double* coords) { double* x = write_realspace_state_ri_return(filename1, filename2, BAND_NUM, KPOINT_NUM, wf, fftg, labels, coords); free(x); } void write_density_noreturn(char* filename, pswf_t* wf, int* fftg, int* labels, double* coords) { setbuf(stdout, NULL); double* x = write_density_return(filename, wf, fftg, labels, coords); mkl_free(x); }
ast-dump-openmp-for-simd.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 for simd for (int i = 0; i < x; i++) ; } void test_two(int x, int y) { #pragma omp for simd for (int i = 0; i < x; i++) for (int i = 0; i < y; i++) ; } void test_three(int x, int y) { #pragma omp for simd 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 for simd 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 for simd 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-for-simd.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: | `-OMPForSimdDirective {{.*}} <line:4:9, col:21> // CHECK-NEXT: | `-CapturedStmt {{.*}} <line:5:3, line:6:5> // CHECK-NEXT: | |-CapturedDecl {{.*}} <<invalid sloc>> <invalid sloc> // 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> openmp_structured_block // CHECK-NEXT: | | |-ImplicitParamDecl {{.*}} <line:4:9> col:9 implicit __context 'struct (anonymous at {{.*}}ast-dump-openmp-for-simd.c:4:9) *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:23> '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: | `-OMPForSimdDirective {{.*}} <line:10:9, col:21> // CHECK-NEXT: | `-CapturedStmt {{.*}} <line:11:3, line:13:7> // CHECK-NEXT: | |-CapturedDecl {{.*}} <<invalid sloc>> <invalid sloc> // 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> openmp_structured_block // 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:9> col:9 implicit __context 'struct (anonymous at {{.*}}ast-dump-openmp-for-simd.c:10:9) *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:23> '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: | `-OMPForSimdDirective {{.*}} <line:17:9, col:33> // CHECK-NEXT: | |-OMPCollapseClause {{.*}} <col:22, col:32> // CHECK-NEXT: | | `-ConstantExpr {{.*}} <col:31> 'int' // CHECK-NEXT: | | `-IntegerLiteral {{.*}} <col:31> 'int' 1 // CHECK-NEXT: | `-CapturedStmt {{.*}} <line:18:3, line:20:7> // CHECK-NEXT: | |-CapturedDecl {{.*}} <<invalid sloc>> <invalid sloc> // 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> openmp_structured_block // 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:9> col:9 implicit __context 'struct (anonymous at {{.*}}ast-dump-openmp-for-simd.c:17:9) *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:23> '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: | `-OMPForSimdDirective {{.*}} <line:24:9, col:33> // CHECK-NEXT: | |-OMPCollapseClause {{.*}} <col:22, col:32> // CHECK-NEXT: | | `-ConstantExpr {{.*}} <col:31> 'int' // CHECK-NEXT: | | `-IntegerLiteral {{.*}} <col:31> 'int' 2 // CHECK-NEXT: | `-CapturedStmt {{.*}} <line:25:3, line:27:7> // CHECK-NEXT: | |-CapturedDecl {{.*}} <<invalid sloc>> <invalid sloc> // 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> openmp_structured_block // CHECK-NEXT: | | |-ImplicitParamDecl {{.*}} <line:24:9> col:9 implicit __context 'struct (anonymous at {{.*}}ast-dump-openmp-for-simd.c:24:9) *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:23> 'int' lvalue ParmVar {{.*}} 'x' 'int' // CHECK-NEXT: | `-DeclRefExpr {{.*}} <line:26:25> '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: `-OMPForSimdDirective {{.*}} <line:31:9, col:33> // CHECK-NEXT: |-OMPCollapseClause {{.*}} <col:22, col:32> // CHECK-NEXT: | `-ConstantExpr {{.*}} <col:31> 'int' // CHECK-NEXT: | `-IntegerLiteral {{.*}} <col:31> 'int' 2 // CHECK-NEXT: `-CapturedStmt {{.*}} <line:32:3, line:35:9> // CHECK-NEXT: |-CapturedDecl {{.*}} <<invalid sloc>> <invalid sloc> // 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> openmp_structured_block // 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:9> col:9 implicit __context 'struct (anonymous at {{.*}}ast-dump-openmp-for-simd.c:31:9) *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:23> 'int' lvalue ParmVar {{.*}} 'x' 'int' // CHECK-NEXT: |-DeclRefExpr {{.*}} <line:33:25> 'int' lvalue ParmVar {{.*}} 'y' 'int' // CHECK-NEXT: `-DeclRefExpr {{.*}} <line:34:27> 'int' lvalue ParmVar {{.*}} 'z' 'int'
mixed_tentusscher_myo_epi_2004_S1_20.c
// Scenario 1 - Mixed-Model TenTusscher 2004 (Myocardium + Epicardium) // (AP + max:dvdt) #include <stdio.h> #include "mixed_tentusscher_myo_epi_2004_S1_20.h" GET_CELL_MODEL_DATA(init_cell_model_data) { if(get_initial_v) cell_model->initial_v = INITIAL_V; if(get_neq) cell_model->number_of_ode_equations = NEQ; } SET_ODE_INITIAL_CONDITIONS_CPU(set_model_initial_conditions_cpu) { static bool first_call = true; if(first_call) { print_to_stdout_and_file("Using mixed version of TenTusscher 2004 myocardium + epicardium CPU model\n"); first_call = false; } // Get the mapping array uint32_t *mapping = NULL; if(extra_data) { mapping = (uint32_t*)extra_data; } else { print_to_stderr_and_file_and_exit("You need to specify a mask function when using a mixed model!\n"); } // Initial conditions for TenTusscher myocardium if (mapping[sv_id] == 0) { // Default initial conditions /* sv[0] = INITIAL_V; // V; millivolt sv[1] = 0.f; //M sv[2] = 0.75; //H sv[3] = 0.75f; //J sv[4] = 0.f; //Xr1 sv[5] = 1.f; //Xr2 sv[6] = 0.f; //Xs sv[7] = 1.f; //S sv[8] = 0.f; //R sv[9] = 0.f; //D sv[10] = 1.f; //F sv[11] = 1.f; //FCa sv[12] = 1.f; //G sv[13] = 0.0002; //Cai sv[14] = 0.2f; //CaSR sv[15] = 11.6f; //Nai sv[16] = 138.3f; //Ki */ // Elnaz's steady-state initial conditions real sv_sst[]={-86.3965119057144,0.00133824305081220,0.775463576993407,0.775278393595599,0.000179499343643571,0.483303039835057,0.00297647859235379,0.999998290403642,1.98961879737287e-08,1.93486789479597e-05,0.999599147019885,1.00646342475688,0.999975178010127,5.97703651642618e-05,0.418325344820368,10.7429775420171,138.918155900633}; for (uint32_t i = 0; i < NEQ; i++) sv[i] = sv_sst[i]; } // Initial conditions for TenTusscher epicardium else { // Default initial conditions /* sv[0] = INITIAL_V; // V; millivolt sv[1] = 0.f; //M sv[2] = 0.75; //H sv[3] = 0.75f; //J sv[4] = 0.f; //Xr1 sv[5] = 1.f; //Xr2 sv[6] = 0.f; //Xs sv[7] = 1.f; //S sv[8] = 0.f; //R sv[9] = 0.f; //D sv[10] = 1.f; //F sv[11] = 1.f; //FCa sv[12] = 1.f; //G sv[13] = 0.0002; //Cai sv[14] = 0.2f; //CaSR sv[15] = 11.6f; //Nai sv[16] = 138.3f; //Ki */ // Elnaz's steady-state initial conditions real sv_sst[]={-86.5180103766650,0.00130403507538545,0.778471794824763,0.778283525838093,0.000176065618651399,0.484567171933683,0.00295084416213736,0.999998331387518,1.94976417188725e-08,1.90377881905604e-05,0.999769816140066,1.00765120153943,0.999999421011808,3.19432158740013e-05,1.25705353770675,9.77685728583073,139.479930314946}; for (uint32_t i = 0; i < NEQ; i++) sv[i] = sv_sst[i]; } } SOLVE_MODEL_ODES_CPU(solve_model_odes_cpu) { // Get the mapping array uint32_t *mapping = NULL; if(extra_data) { mapping = (uint32_t*)extra_data; } else { print_to_stderr_and_file_and_exit("You need to specify a mask function when using a mixed model!\n"); } uint32_t sv_id; int i; #pragma omp parallel for private(sv_id) for (i = 0; i < num_cells_to_solve; i++) { if(cells_to_solve) sv_id = cells_to_solve[i]; else sv_id = (uint32_t )i; for (int j = 0; j < num_steps; ++j) { if (mapping[i] == 0) solve_model_ode_cpu_myo(dt, sv + (sv_id * NEQ), stim_currents[i]); else solve_model_ode_cpu_epi(dt, sv + (sv_id * NEQ), stim_currents[i]); } } } void solve_model_ode_cpu_myo (real dt, real *sv, real stim_current) { real rY[NEQ], rDY[NEQ]; for(int i = 0; i < NEQ; i++) rY[i] = sv[i]; RHS_cpu_myo(rY, rDY, stim_current, dt); for(int i = 0; i < NEQ; i++) sv[i] = rDY[i]; } void RHS_cpu_myo(const real *sv, real *rDY_, real stim_current, real dt) { // State variables real svolt = sv[0]; real sm = sv[1]; real sh = sv[2]; real sj = sv[3]; real sxr1 = sv[4]; real sxr2 = sv[5]; real sxs = sv[6]; real ss = sv[7]; real sr = sv[8]; real sd = sv[9]; real sf = sv[10]; real sfca = sv[11]; real sg = sv[12]; real Cai = sv[13]; real CaSR = sv[14]; real Nai = sv[15]; real Ki = sv[16]; //External concentrations real Ko=5.4; real Cao=2.0; real Nao=140.0; //Intracellular volumes real Vc=0.016404; real Vsr=0.001094; //Calcium dynamics real Bufc=0.15f; real Kbufc=0.001f; real Bufsr=10.f; real Kbufsr=0.3f; real taufca=2.f; real taug=2.f; real Vmaxup=0.000425f; real Kup=0.00025f; //Constants const real R = 8314.472f; const real F = 96485.3415f; const real T =310.0f; real RTONF =(R*T)/F; //Cellular capacitance real CAPACITANCE=0.185; //Parameters for currents //Parameters for IKr real Gkr=0.096; //Parameters for Iks real pKNa=0.03; // [!] Myocardium cell real Gks=0.062; //Parameters for Ik1 real GK1=5.405; //Parameters for Ito // [!] Myocardium cell real Gto=0.294; //Parameters for INa real GNa=14.838; //Parameters for IbNa real GbNa=0.00029; //Parameters for INaK real KmK=1.0; real KmNa=40.0; real knak=1.362; //Parameters for ICaL real GCaL=0.000175; //Parameters for IbCa real GbCa=0.000592; //Parameters for INaCa real knaca=1000; real KmNai=87.5; real KmCa=1.38; real ksat=0.1; real n=0.35; //Parameters for IpCa real GpCa=0.825; real KpCa=0.0005; //Parameters for IpK; real GpK=0.0146; real IKr; real IKs; real IK1; real Ito; real INa; real IbNa; real ICaL; real IbCa; real INaCa; real IpCa; real IpK; real INaK; real Irel; real Ileak; real dNai; real dKi; real dCai; real dCaSR; real A; // real BufferFactorc; // real BufferFactorsr; real SERCA; real Caisquare; real CaSRsquare; real CaCurrent; real CaSRCurrent; real fcaold; real gold; real Ek; real Ena; real Eks; real Eca; real CaCSQN; real bjsr; real cjsr; real CaBuf; real bc; real cc; real Ak1; real Bk1; real rec_iK1; real rec_ipK; real rec_iNaK; real AM; real BM; real AH_1; real BH_1; real AH_2; real BH_2; real AJ_1; real BJ_1; real AJ_2; real BJ_2; real M_INF; real H_INF; real J_INF; real TAU_M; real TAU_H; real TAU_J; real axr1; real bxr1; real axr2; real bxr2; real Xr1_INF; real Xr2_INF; real TAU_Xr1; real TAU_Xr2; real Axs; real Bxs; real Xs_INF; real TAU_Xs; real R_INF; real TAU_R; real S_INF; real TAU_S; real Ad; real Bd; real Cd; real TAU_D; real D_INF; real TAU_F; real F_INF; real FCa_INF; real G_INF; real inverseVcF2=1/(2*Vc*F); real inverseVcF=1./(Vc*F); real Kupsquare=Kup*Kup; // real BufcKbufc=Bufc*Kbufc; // real Kbufcsquare=Kbufc*Kbufc; // real Kbufc2=2*Kbufc; // real BufsrKbufsr=Bufsr*Kbufsr; // const real Kbufsrsquare=Kbufsr*Kbufsr; // const real Kbufsr2=2*Kbufsr; const real exptaufca=exp(-dt/taufca); const real exptaug=exp(-dt/taug); real sItot; //Needed to compute currents Ek=RTONF*(log((Ko/Ki))); Ena=RTONF*(log((Nao/Nai))); Eks=RTONF*(log((Ko+pKNa*Nao)/(Ki+pKNa*Nai))); Eca=0.5*RTONF*(log((Cao/Cai))); Ak1=0.1/(1.+exp(0.06*(svolt-Ek-200))); Bk1=(3.*exp(0.0002*(svolt-Ek+100))+ exp(0.1*(svolt-Ek-10)))/(1.+exp(-0.5*(svolt-Ek))); rec_iK1=Ak1/(Ak1+Bk1); rec_iNaK=(1./(1.+0.1245*exp(-0.1*svolt*F/(R*T))+0.0353*exp(-svolt*F/(R*T)))); rec_ipK=1./(1.+exp((25-svolt)/5.98)); //Compute currents INa=GNa*sm*sm*sm*sh*sj*(svolt-Ena); ICaL=GCaL*sd*sf*sfca*4*svolt*(F*F/(R*T))* (exp(2*svolt*F/(R*T))*Cai-0.341*Cao)/(exp(2*svolt*F/(R*T))-1.); Ito=Gto*sr*ss*(svolt-Ek); IKr=Gkr*sqrt(Ko/5.4)*sxr1*sxr2*(svolt-Ek); IKs=Gks*sxs*sxs*(svolt-Eks); IK1=GK1*rec_iK1*(svolt-Ek); INaCa=knaca*(1./(KmNai*KmNai*KmNai+Nao*Nao*Nao))*(1./(KmCa+Cao))* (1./(1+ksat*exp((n-1)*svolt*F/(R*T))))* (exp(n*svolt*F/(R*T))*Nai*Nai*Nai*Cao- exp((n-1)*svolt*F/(R*T))*Nao*Nao*Nao*Cai*2.5); INaK=knak*(Ko/(Ko+KmK))*(Nai/(Nai+KmNa))*rec_iNaK; IpCa=GpCa*Cai/(KpCa+Cai); IpK=GpK*rec_ipK*(svolt-Ek); IbNa=GbNa*(svolt-Ena); IbCa=GbCa*(svolt-Eca); //Determine total current (sItot) = IKr + IKs + IK1 + Ito + INa + IbNa + ICaL + IbCa + INaK + INaCa + IpCa + IpK + stim_current; //update concentrations Caisquare=Cai*Cai; CaSRsquare=CaSR*CaSR; CaCurrent=-(ICaL+IbCa+IpCa-2.0f*INaCa)*inverseVcF2*CAPACITANCE; A=0.016464f*CaSRsquare/(0.0625f+CaSRsquare)+0.008232f; Irel=A*sd*sg; Ileak=0.00008f*(CaSR-Cai); SERCA=Vmaxup/(1.f+(Kupsquare/Caisquare)); CaSRCurrent=SERCA-Irel-Ileak; CaCSQN=Bufsr*CaSR/(CaSR+Kbufsr); dCaSR=dt*(Vc/Vsr)*CaSRCurrent; bjsr=Bufsr-CaCSQN-dCaSR-CaSR+Kbufsr; cjsr=Kbufsr*(CaCSQN+dCaSR+CaSR); CaSR=(sqrt(bjsr*bjsr+4.*cjsr)-bjsr)/2.; CaBuf=Bufc*Cai/(Cai+Kbufc); dCai=dt*(CaCurrent-CaSRCurrent); bc=Bufc-CaBuf-dCai-Cai+Kbufc; cc=Kbufc*(CaBuf+dCai+Cai); Cai=(sqrt(bc*bc+4*cc)-bc)/2; dNai=-(INa+IbNa+3*INaK+3*INaCa)*inverseVcF*CAPACITANCE; Nai+=dt*dNai; dKi=-(stim_current+IK1+Ito+IKr+IKs-2*INaK+IpK)*inverseVcF*CAPACITANCE; Ki+=dt*dKi; //compute steady state values and time constants AM=1./(1.+exp((-60.-svolt)/5.)); BM=0.1/(1.+exp((svolt+35.)/5.))+0.10/(1.+exp((svolt-50.)/200.)); TAU_M=AM*BM; M_INF=1./((1.+exp((-56.86-svolt)/9.03))*(1.+exp((-56.86-svolt)/9.03))); if (svolt>=-40.) { AH_1=0.; BH_1=(0.77/(0.13*(1.+exp(-(svolt+10.66)/11.1)))); TAU_H= 1.0/(AH_1+BH_1); } else { AH_2=(0.057*exp(-(svolt+80.)/6.8)); BH_2=(2.7*exp(0.079*svolt)+(3.1e5)*exp(0.3485*svolt)); TAU_H=1.0/(AH_2+BH_2); } H_INF=1./((1.+exp((svolt+71.55)/7.43))*(1.+exp((svolt+71.55)/7.43))); if(svolt>=-40.) { AJ_1=0.; BJ_1=(0.6*exp((0.057)*svolt)/(1.+exp(-0.1*(svolt+32.)))); TAU_J= 1.0/(AJ_1+BJ_1); } else { AJ_2=(((-2.5428e4)*exp(0.2444*svolt)-(6.948e-6)* exp(-0.04391*svolt))*(svolt+37.78)/ (1.+exp(0.311*(svolt+79.23)))); BJ_2=(0.02424*exp(-0.01052*svolt)/(1.+exp(-0.1378*(svolt+40.14)))); TAU_J= 1.0/(AJ_2+BJ_2); } J_INF=H_INF; Xr1_INF=1./(1.+exp((-26.-svolt)/7.)); axr1=450./(1.+exp((-45.-svolt)/10.)); bxr1=6./(1.+exp((svolt-(-30.))/11.5)); TAU_Xr1=axr1*bxr1; Xr2_INF=1./(1.+exp((svolt-(-88.))/24.)); axr2=3./(1.+exp((-60.-svolt)/20.)); bxr2=1.12/(1.+exp((svolt-60.)/20.)); TAU_Xr2=axr2*bxr2; Xs_INF=1./(1.+exp((-5.-svolt)/14.)); Axs=1100./(sqrt(1.+exp((-10.-svolt)/6))); Bxs=1./(1.+exp((svolt-60.)/20.)); TAU_Xs=Axs*Bxs; // [!] Myocardium cell R_INF=1./(1.+exp((20-svolt)/6.)); S_INF=1./(1.+exp((svolt+20)/5.)); TAU_R=9.5*exp(-(svolt+40.)*(svolt+40.)/1800.)+0.8; TAU_S=85.*exp(-(svolt+45.)*(svolt+45.)/320.)+5./(1.+exp((svolt-20.)/5.))+3.; D_INF=1./(1.+exp((-5-svolt)/7.5)); Ad=1.4/(1.+exp((-35-svolt)/13))+0.25; Bd=1.4/(1.+exp((svolt+5)/5)); Cd=1./(1.+exp((50-svolt)/20)); TAU_D=Ad*Bd+Cd; F_INF=1./(1.+exp((svolt+20)/7)); //TAU_F=1125*exp(-(svolt+27)*(svolt+27)/300)+80+165/(1.+exp((25-svolt)/10)); TAU_F=1125*exp(-(svolt+27)*(svolt+27)/240)+80+165/(1.+exp((25-svolt)/10)); // Updated from CellML FCa_INF=(1./(1.+pow((Cai/0.000325),8))+ 0.1/(1.+exp((Cai-0.0005)/0.0001))+ 0.20/(1.+exp((Cai-0.00075)/0.0008))+ 0.23 )/1.46; if(Cai<0.00035) G_INF=1./(1.+pow((Cai/0.00035),6)); else G_INF=1./(1.+pow((Cai/0.00035),16)); //Update gates rDY_[1] = M_INF-(M_INF-sm)*exp(-dt/TAU_M); rDY_[2] = H_INF-(H_INF-sh)*exp(-dt/TAU_H); rDY_[3] = J_INF-(J_INF-sj)*exp(-dt/TAU_J); rDY_[4] = Xr1_INF-(Xr1_INF-sxr1)*exp(-dt/TAU_Xr1); rDY_[5] = Xr2_INF-(Xr2_INF-sxr2)*exp(-dt/TAU_Xr2); rDY_[6] = Xs_INF-(Xs_INF-sxs)*exp(-dt/TAU_Xs); rDY_[7] = S_INF-(S_INF-ss)*exp(-dt/TAU_S); rDY_[8] = R_INF-(R_INF-sr)*exp(-dt/TAU_R); rDY_[9] = D_INF-(D_INF-sd)*exp(-dt/TAU_D); rDY_[10] = F_INF-(F_INF-sf)*exp(-dt/TAU_F); fcaold= sfca; sfca = FCa_INF-(FCa_INF-sfca)*exptaufca; if(sfca>fcaold && (svolt)>-37.0) sfca = fcaold; gold = sg; sg = G_INF-(G_INF-sg)*exptaug; if(sg>gold && (svolt)>-37.0) sg=gold; //update voltage rDY_[0] = svolt + dt*(-sItot); rDY_[11] = sfca; rDY_[12] = sg; rDY_[13] = Cai; rDY_[14] = CaSR; rDY_[15] = Nai; rDY_[16] = Ki; } void solve_model_ode_cpu_epi (real dt, real *sv, real stim_current) { real rY[NEQ], rDY[NEQ]; for(int i = 0; i < NEQ; i++) rY[i] = sv[i]; RHS_cpu_epi(rY, rDY, stim_current, dt); for(int i = 0; i < NEQ; i++) sv[i] = rDY[i]; } void RHS_cpu_epi(const real *sv, real *rDY_, real stim_current, real dt) { // State variables real svolt = sv[0]; real sm = sv[1]; real sh = sv[2]; real sj = sv[3]; real sxr1 = sv[4]; real sxr2 = sv[5]; real sxs = sv[6]; real ss = sv[7]; real sr = sv[8]; real sd = sv[9]; real sf = sv[10]; real sfca = sv[11]; real sg = sv[12]; real Cai = sv[13]; real CaSR = sv[14]; real Nai = sv[15]; real Ki = sv[16]; //External concentrations real Ko=5.4; real Cao=2.0; real Nao=140.0; //Intracellular volumes real Vc=0.016404; real Vsr=0.001094; //Calcium dynamics real Bufc=0.15f; real Kbufc=0.001f; real Bufsr=10.f; real Kbufsr=0.3f; real taufca=2.f; real taug=2.f; real Vmaxup=0.000425f; real Kup=0.00025f; //Constants const real R = 8314.472f; const real F = 96485.3415f; const real T =310.0f; real RTONF =(R*T)/F; //Cellular capacitance real CAPACITANCE=0.185; //Parameters for currents //Parameters for IKr real Gkr=0.096; //Parameters for Iks real pKNa=0.03; // [!] Epicardium cell real Gks=0.245; //Parameters for Ik1 real GK1=5.405; //Parameters for Ito // [!] Epicardium cell real Gto=0.294; //Parameters for INa real GNa=14.838; //Parameters for IbNa real GbNa=0.00029; //Parameters for INaK real KmK=1.0; real KmNa=40.0; real knak=1.362; //Parameters for ICaL real GCaL=0.000175; //Parameters for IbCa real GbCa=0.000592; //Parameters for INaCa real knaca=1000; real KmNai=87.5; real KmCa=1.38; real ksat=0.1; real n=0.35; //Parameters for IpCa real GpCa=0.825; real KpCa=0.0005; //Parameters for IpK; real GpK=0.0146; real parameters []={14.0425347024085,0.000535677026211757,0.000165310108418668,0.000350622775813131,0.284242546174007,0.160699932744295,0.199053804511766,4.02983501857037,0.0207339018842815,1.90362917367254,1092.38391918131,0.000589746455166102,0.152476943428258,0.0199994247147465,0.00594175101819478,9.05890620616966e-06}; GNa=parameters[0]; GbNa=parameters[1]; GCaL=parameters[2]; GbCa=parameters[3]; Gto=parameters[4]; Gkr=parameters[5]; Gks=parameters[6]; GK1=parameters[7]; GpK=parameters[8]; knak=parameters[9]; knaca=parameters[10]; Vmaxup=parameters[11]; GpCa=parameters[12]; real arel=parameters[13]; real crel=parameters[14]; real Vleak=parameters[15]; real IKr; real IKs; real IK1; real Ito; real INa; real IbNa; real ICaL; real IbCa; real INaCa; real IpCa; real IpK; real INaK; real Irel; real Ileak; real dNai; real dKi; real dCai; real dCaSR; real A; // real BufferFactorc; // real BufferFactorsr; real SERCA; real Caisquare; real CaSRsquare; real CaCurrent; real CaSRCurrent; real fcaold; real gold; real Ek; real Ena; real Eks; real Eca; real CaCSQN; real bjsr; real cjsr; real CaBuf; real bc; real cc; real Ak1; real Bk1; real rec_iK1; real rec_ipK; real rec_iNaK; real AM; real BM; real AH_1; real BH_1; real AH_2; real BH_2; real AJ_1; real BJ_1; real AJ_2; real BJ_2; real M_INF; real H_INF; real J_INF; real TAU_M; real TAU_H; real TAU_J; real axr1; real bxr1; real axr2; real bxr2; real Xr1_INF; real Xr2_INF; real TAU_Xr1; real TAU_Xr2; real Axs; real Bxs; real Xs_INF; real TAU_Xs; real R_INF; real TAU_R; real S_INF; real TAU_S; real Ad; real Bd; real Cd; real TAU_D; real D_INF; real TAU_F; real F_INF; real FCa_INF; real G_INF; real inverseVcF2=1/(2*Vc*F); real inverseVcF=1./(Vc*F); real Kupsquare=Kup*Kup; // real BufcKbufc=Bufc*Kbufc; // real Kbufcsquare=Kbufc*Kbufc; // real Kbufc2=2*Kbufc; // real BufsrKbufsr=Bufsr*Kbufsr; // const real Kbufsrsquare=Kbufsr*Kbufsr; // const real Kbufsr2=2*Kbufsr; const real exptaufca=exp(-dt/taufca); const real exptaug=exp(-dt/taug); real sItot; //Needed to compute currents Ek=RTONF*(log((Ko/Ki))); Ena=RTONF*(log((Nao/Nai))); Eks=RTONF*(log((Ko+pKNa*Nao)/(Ki+pKNa*Nai))); Eca=0.5*RTONF*(log((Cao/Cai))); Ak1=0.1/(1.+exp(0.06*(svolt-Ek-200))); Bk1=(3.*exp(0.0002*(svolt-Ek+100))+ exp(0.1*(svolt-Ek-10)))/(1.+exp(-0.5*(svolt-Ek))); rec_iK1=Ak1/(Ak1+Bk1); rec_iNaK=(1./(1.+0.1245*exp(-0.1*svolt*F/(R*T))+0.0353*exp(-svolt*F/(R*T)))); rec_ipK=1./(1.+exp((25-svolt)/5.98)); //Compute currents INa=GNa*sm*sm*sm*sh*sj*(svolt-Ena); ICaL=GCaL*sd*sf*sfca*4*svolt*(F*F/(R*T))* (exp(2*svolt*F/(R*T))*Cai-0.341*Cao)/(exp(2*svolt*F/(R*T))-1.); Ito=Gto*sr*ss*(svolt-Ek); IKr=Gkr*sqrt(Ko/5.4)*sxr1*sxr2*(svolt-Ek); IKs=Gks*sxs*sxs*(svolt-Eks); IK1=GK1*rec_iK1*(svolt-Ek); INaCa=knaca*(1./(KmNai*KmNai*KmNai+Nao*Nao*Nao))*(1./(KmCa+Cao))* (1./(1+ksat*exp((n-1)*svolt*F/(R*T))))* (exp(n*svolt*F/(R*T))*Nai*Nai*Nai*Cao- exp((n-1)*svolt*F/(R*T))*Nao*Nao*Nao*Cai*2.5); INaK=knak*(Ko/(Ko+KmK))*(Nai/(Nai+KmNa))*rec_iNaK; IpCa=GpCa*Cai/(KpCa+Cai); IpK=GpK*rec_ipK*(svolt-Ek); IbNa=GbNa*(svolt-Ena); IbCa=GbCa*(svolt-Eca); //Determine total current (sItot) = IKr + IKs + IK1 + Ito + INa + IbNa + ICaL + IbCa + INaK + INaCa + IpCa + IpK + stim_current; //update concentrations Caisquare=Cai*Cai; CaSRsquare=CaSR*CaSR; CaCurrent=-(ICaL+IbCa+IpCa-2.0f*INaCa)*inverseVcF2*CAPACITANCE; A=arel*CaSRsquare/(0.0625f+CaSRsquare)+crel; Irel=A*sd*sg; Ileak=Vleak*(CaSR-Cai); SERCA=Vmaxup/(1.f+(Kupsquare/Caisquare)); CaSRCurrent=SERCA-Irel-Ileak; CaCSQN=Bufsr*CaSR/(CaSR+Kbufsr); dCaSR=dt*(Vc/Vsr)*CaSRCurrent; bjsr=Bufsr-CaCSQN-dCaSR-CaSR+Kbufsr; cjsr=Kbufsr*(CaCSQN+dCaSR+CaSR); CaSR=(sqrt(bjsr*bjsr+4.*cjsr)-bjsr)/2.; CaBuf=Bufc*Cai/(Cai+Kbufc); dCai=dt*(CaCurrent-CaSRCurrent); bc=Bufc-CaBuf-dCai-Cai+Kbufc; cc=Kbufc*(CaBuf+dCai+Cai); Cai=(sqrt(bc*bc+4*cc)-bc)/2; dNai=-(INa+IbNa+3*INaK+3*INaCa)*inverseVcF*CAPACITANCE; Nai+=dt*dNai; dKi=-(stim_current+IK1+Ito+IKr+IKs-2*INaK+IpK)*inverseVcF*CAPACITANCE; Ki+=dt*dKi; //compute steady state values and time constants AM=1./(1.+exp((-60.-svolt)/5.)); BM=0.1/(1.+exp((svolt+35.)/5.))+0.10/(1.+exp((svolt-50.)/200.)); TAU_M=AM*BM; M_INF=1./((1.+exp((-56.86-svolt)/9.03))*(1.+exp((-56.86-svolt)/9.03))); if (svolt>=-40.) { AH_1=0.; BH_1=(0.77/(0.13*(1.+exp(-(svolt+10.66)/11.1)))); TAU_H= 1.0/(AH_1+BH_1); } else { AH_2=(0.057*exp(-(svolt+80.)/6.8)); BH_2=(2.7*exp(0.079*svolt)+(3.1e5)*exp(0.3485*svolt)); TAU_H=1.0/(AH_2+BH_2); } H_INF=1./((1.+exp((svolt+71.55)/7.43))*(1.+exp((svolt+71.55)/7.43))); if(svolt>=-40.) { AJ_1=0.; BJ_1=(0.6*exp((0.057)*svolt)/(1.+exp(-0.1*(svolt+32.)))); TAU_J= 1.0/(AJ_1+BJ_1); } else { AJ_2=(((-2.5428e4)*exp(0.2444*svolt)-(6.948e-6)* exp(-0.04391*svolt))*(svolt+37.78)/ (1.+exp(0.311*(svolt+79.23)))); BJ_2=(0.02424*exp(-0.01052*svolt)/(1.+exp(-0.1378*(svolt+40.14)))); TAU_J= 1.0/(AJ_2+BJ_2); } J_INF=H_INF; Xr1_INF=1./(1.+exp((-26.-svolt)/7.)); axr1=450./(1.+exp((-45.-svolt)/10.)); bxr1=6./(1.+exp((svolt-(-30.))/11.5)); TAU_Xr1=axr1*bxr1; Xr2_INF=1./(1.+exp((svolt-(-88.))/24.)); axr2=3./(1.+exp((-60.-svolt)/20.)); bxr2=1.12/(1.+exp((svolt-60.)/20.)); TAU_Xr2=axr2*bxr2; Xs_INF=1./(1.+exp((-5.-svolt)/14.)); Axs=1100./(sqrt(1.+exp((-10.-svolt)/6))); Bxs=1./(1.+exp((svolt-60.)/20.)); TAU_Xs=Axs*Bxs; R_INF=1./(1.+exp((20-svolt)/6.)); S_INF=1./(1.+exp((svolt+20)/5.)); TAU_R=9.5*exp(-(svolt+40.)*(svolt+40.)/1800.)+0.8; TAU_S=85.*exp(-(svolt+45.)*(svolt+45.)/320.)+5./(1.+exp((svolt-20.)/5.))+3.; D_INF=1./(1.+exp((-5-svolt)/7.5)); Ad=1.4/(1.+exp((-35-svolt)/13))+0.25; Bd=1.4/(1.+exp((svolt+5)/5)); Cd=1./(1.+exp((50-svolt)/20)); TAU_D=Ad*Bd+Cd; F_INF=1./(1.+exp((svolt+20)/7)); //TAU_F=1125*exp(-(svolt+27)*(svolt+27)/300)+80+165/(1.+exp((25-svolt)/10)); TAU_F=1125*exp(-(svolt+27)*(svolt+27)/240)+80+165/(1.+exp((25-svolt)/10)); // Updated from CellML FCa_INF=(1./(1.+pow((Cai/0.000325),8))+ 0.1/(1.+exp((Cai-0.0005)/0.0001))+ 0.20/(1.+exp((Cai-0.00075)/0.0008))+ 0.23 )/1.46; if(Cai<0.00035) G_INF=1./(1.+pow((Cai/0.00035),6)); else G_INF=1./(1.+pow((Cai/0.00035),16)); //Update gates rDY_[1] = M_INF-(M_INF-sm)*exp(-dt/TAU_M); rDY_[2] = H_INF-(H_INF-sh)*exp(-dt/TAU_H); rDY_[3] = J_INF-(J_INF-sj)*exp(-dt/TAU_J); rDY_[4] = Xr1_INF-(Xr1_INF-sxr1)*exp(-dt/TAU_Xr1); rDY_[5] = Xr2_INF-(Xr2_INF-sxr2)*exp(-dt/TAU_Xr2); rDY_[6] = Xs_INF-(Xs_INF-sxs)*exp(-dt/TAU_Xs); rDY_[7] = S_INF-(S_INF-ss)*exp(-dt/TAU_S); rDY_[8] = R_INF-(R_INF-sr)*exp(-dt/TAU_R); rDY_[9] = D_INF-(D_INF-sd)*exp(-dt/TAU_D); rDY_[10] = F_INF-(F_INF-sf)*exp(-dt/TAU_F); fcaold= sfca; sfca = FCa_INF-(FCa_INF-sfca)*exptaufca; if(sfca>fcaold && (svolt)>-37.0) sfca = fcaold; gold = sg; sg = G_INF-(G_INF-sg)*exptaug; if(sg>gold && (svolt)>-37.0) sg=gold; //update voltage rDY_[0] = svolt + dt*(-sItot); rDY_[11] = sfca; rDY_[12] = sg; rDY_[13] = Cai; rDY_[14] = CaSR; rDY_[15] = Nai; rDY_[16] = Ki; }
fc_compute.h
/* Copyright (c) 2016 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 "paddle/fluid/operators/jit/kernels.h" #include "paddle/fluid/operators/math/blas.h" namespace paddle { namespace operators { namespace math { template <typename DeviceContext, typename T> inline void FCCompute(const BlasT<DeviceContext, T>& blas, const int M, const int N, const int K, const T* X, const T* W, T* Y, const T* B = NULL, bool relu = false) { blas.MatMul(M, N, K, X, W, Y); if (B == NULL) { return; } if (relu) { auto compute = jit::Get<jit::kVAddRelu, jit::XYZNTuples<T>, platform::CPUPlace>(N); for (int i = 0; i < M; i++) { T* dst = Y + i * N; compute(B, dst, dst, N); } } else { auto compute = jit::Get<jit::kVAdd, jit::XYZNTuples<T>, platform::CPUPlace>(N); #ifdef PADDLE_WITH_MKLML #pragma omp parallel for #endif for (int i = 0; i < M; i++) { T* dst = Y + i * N; compute(B, dst, dst, N); } } } } // namespace math } // namespace operators } // namespace paddle
ej6.c
#include <omp.h> #include <stdio.h> void threads_por_nivel(int nivel){ printf("Nivel %d: Número de hilos en el nivel %d - %d\n",nivel,nivel,omp_get_num_threads()); } int main() { omp_set_nested(1); omp_set_num_threads(2); #pragma omp parallel { threads_por_nivel(1); omp_set_num_threads(3); #pragma omp parallel { threads_por_nivel(2); omp_set_num_threads(2); #pragma omp parallel { threads_por_nivel(3); } } } return(0); }
simd-6.c
/* { dg-do run { target vect_simd_clones } } */ /* { dg-additional-options "-msse2" { target sse2_runtime } } */ /* { dg-additional-options "-mavx" { target avx_runtime } } */ #define N 100 #define EPS 0.000001 #include <stdlib.h> #include <stdio.h> void init(int *b, float *y, int n) { int i, s = -1; for ( i=0; i<N; i++ ) { b[i] = i*i*s; y[i] = b[i] * 0.1f; s = -s; } } #pragma omp declare simd linear(p:1) notinbranch int foo(int *p){ *p = *p + 10; return *p; } int myaddint(int *a, int *b, int n) { #pragma omp simd for (int i=0; i<n; i++){ a[i] = foo(&b[i]); /* foo is not called under a condition */ } return a[n-1]; } int myaddint_ref(int *a, int *b, int n) { for (int i=0; i<n; i++){ a[i] = foo(&b[i]); } return a[n-1]; } #pragma omp declare simd linear(p:1) inbranch float goo(float *p){ *p = *p + 18.5f; return *p; } int myaddfloat(float *x, float *y, int n) { #pragma omp simd for (int i=0; i<n; i++){ x[i] = (x[i] > y[i]) ? goo(&y[i]) : y[i]; /* goo is called under the condition (or within a branch) */ } return x[n-1]; } int myaddfloat_ref(float *x, float *y, int n) { for (int i=0; i<n; i++){ x[i] = (x[i] > y[i]) ? goo(&y[i]) : y[i]; } return x[n-1]; } void check_addint (int *a, int *b) { int i; for (i = 0; i < N; i++) if (a[i] != b[i]) abort (); } void check_addfloat (float *a, float *b) { int i; for (i = 0; i < N; i++) if (a[i] - b[i] > EPS || b[i] - a[i] > EPS) abort (); } int main () { int i; int a[N], a_ref[N], b[N]; float x[N], x_ref[N], y[N]; init(a, x, N); init(b, y, N); myaddint(a, b, N); myaddfloat(x, y, N); init(a_ref, x_ref, N); init(b, y, N); myaddint_ref(a_ref, b, N); myaddfloat_ref(x_ref, y, N); check_addint(a, a_ref); check_addfloat(x, x_ref); return 0; }
tree.h
/*! * Copyright (c) 2016 Microsoft Corporation. All rights reserved. * Licensed under the MIT License. See LICENSE file in the project root for license information. */ #ifndef LIGHTGBM_TREE_H_ #define LIGHTGBM_TREE_H_ #include <LightGBM/dataset.h> #include <LightGBM/meta.h> #include <string> #include <map> #include <memory> #include <unordered_map> #include <vector> namespace LightGBM { #define kCategoricalMask (1) #define kDefaultLeftMask (2) /*! * \brief Tree model */ class Tree { public: /*! * \brief Constructor * \param max_leaves The number of max leaves */ explicit Tree(int max_leaves); /*! * \brief Constructor, from a string * \param str Model string * \param used_len used count of str */ Tree(const char* str, size_t* used_len); ~Tree(); /*! * \brief Performing a split on tree leaves. * \param leaf Index of leaf to be split * \param feature Index of feature; the converted index after removing useless features * \param real_feature Index of feature, the original index on data * \param threshold_bin Threshold(bin) of split * \param threshold_double Threshold on feature value * \param left_value Model Left child output * \param right_value Model Right child output * \param left_cnt Count of left child * \param right_cnt Count of right child * \param left_weight Weight of left child * \param right_weight Weight of right child * \param gain Split gain * \param missing_type missing type * \param default_left default direction for missing value * \return The index of new leaf. */ int Split(int leaf, int feature, int real_feature, uint32_t threshold_bin, double threshold_double, double left_value, double right_value, int left_cnt, int right_cnt, double left_weight, double right_weight, float gain, MissingType missing_type, bool default_left); /*! * \brief Performing a split on tree leaves, with categorical feature * \param leaf Index of leaf to be split * \param feature Index of feature; the converted index after removing useless features * \param real_feature Index of feature, the original index on data * \param threshold_bin Threshold(bin) of split, use bitset to represent * \param num_threshold_bin size of threshold_bin * \param threshold Thresholds of real feature value, use bitset to represent * \param num_threshold size of threshold * \param left_value Model Left child output * \param right_value Model Right child output * \param left_cnt Count of left child * \param right_cnt Count of right child * \param left_weight Weight of left child * \param right_weight Weight of right child * \param gain Split gain * \return The index of new leaf. */ int SplitCategorical(int leaf, int feature, int real_feature, const uint32_t* threshold_bin, int num_threshold_bin, const uint32_t* threshold, int num_threshold, double left_value, double right_value, int left_cnt, int right_cnt, double left_weight, double right_weight, float gain, MissingType missing_type); /*! \brief Get the output of one leaf */ inline double LeafOutput(int leaf) const { return leaf_value_[leaf]; } /*! \brief Set the output of one leaf */ inline void SetLeafOutput(int leaf, double output) { leaf_value_[leaf] = MaybeRoundToZero(output); } /*! * \brief Adding prediction value of this tree model to scores * \param data The dataset * \param num_data Number of total data * \param score Will add prediction to score */ void AddPredictionToScore(const Dataset* data, data_size_t num_data, double* score) const; /*! * \brief Adding prediction value of this tree model to scores * \param data The dataset * \param used_data_indices Indices of used data * \param num_data Number of total data * \param score Will add prediction to score */ void AddPredictionToScore(const Dataset* data, const data_size_t* used_data_indices, data_size_t num_data, double* score) const; /*! * \brief Get upper bound leaf value of this tree model */ double GetUpperBoundValue() const; /*! * \brief Get lower bound leaf value of this tree model */ double GetLowerBoundValue() const; /*! * \brief Prediction on one record * \param feature_values Feature value of this record * \return Prediction result */ inline double Predict(const double* feature_values) const; inline double PredictByMap(const std::unordered_map<int, double>& feature_values) const; inline int PredictLeafIndex(const double* feature_values) const; inline int PredictLeafIndexByMap(const std::unordered_map<int, double>& feature_values) const; inline void PredictContrib(const double* feature_values, int num_features, double* output); /*! \brief Get Number of leaves*/ inline int num_leaves() const { return num_leaves_; } /*! \brief Get depth of specific leaf*/ inline int leaf_depth(int leaf_idx) const { return leaf_depth_[leaf_idx]; } /*! \brief Get parent of specific leaf*/ inline int leaf_parent(int leaf_idx) const {return leaf_parent_[leaf_idx]; } /*! \brief Get feature of specific split*/ inline int split_feature(int split_idx) const { return split_feature_[split_idx]; } inline double split_gain(int split_idx) const { return split_gain_[split_idx]; } inline double internal_value(int node_idx) const { return internal_value_[node_idx]; } inline bool IsNumericalSplit(int node_idx) const { return !GetDecisionType(decision_type_[node_idx], kCategoricalMask); } inline int left_child(int node_idx) const { return left_child_[node_idx]; } inline int right_child(int node_idx) const { return right_child_[node_idx]; } inline int split_feature_inner(int node_idx) const { return split_feature_inner_[node_idx]; } inline uint32_t threshold_in_bin(int node_idx) const { return threshold_in_bin_[node_idx]; } /*! \brief Get the number of data points that fall at or below this node*/ inline int data_count(int node) const { return node >= 0 ? internal_count_[node] : leaf_count_[~node]; } /*! * \brief Shrinkage for the tree's output * shrinkage rate (a.k.a learning rate) is used to tune the training process * \param rate The factor of shrinkage */ inline void Shrinkage(double rate) { #pragma omp parallel for schedule(static, 1024) if (num_leaves_ >= 2048) for (int i = 0; i < num_leaves_ - 1; ++i) { leaf_value_[i] = MaybeRoundToZero(leaf_value_[i] * rate); internal_value_[i] = MaybeRoundToZero(internal_value_[i] * rate); } leaf_value_[num_leaves_ - 1] = MaybeRoundToZero(leaf_value_[num_leaves_ - 1] * rate); shrinkage_ *= rate; } inline double shrinkage() const { return shrinkage_; } inline void AddBias(double val) { #pragma omp parallel for schedule(static, 1024) if (num_leaves_ >= 2048) for (int i = 0; i < num_leaves_ - 1; ++i) { leaf_value_[i] = MaybeRoundToZero(leaf_value_[i] + val); internal_value_[i] = MaybeRoundToZero(internal_value_[i] + val); } leaf_value_[num_leaves_ - 1] = MaybeRoundToZero(leaf_value_[num_leaves_ - 1] + val); // force to 1.0 shrinkage_ = 1.0f; } inline void AsConstantTree(double val) { num_leaves_ = 1; shrinkage_ = 1.0f; leaf_value_[0] = val; } /*! \brief Serialize this object to string*/ std::string ToString() const; /*! \brief Serialize this object to json*/ std::string ToJSON() const; /*! \brief Serialize this object to if-else statement*/ std::string ToIfElse(int index, bool predict_leaf_index) const; inline static bool IsZero(double fval) { return (fval >= -kZeroThreshold && fval <= kZeroThreshold); } inline static double MaybeRoundToZero(double fval) { return IsZero(fval) ? 0 : fval; } inline static bool GetDecisionType(int8_t decision_type, int8_t mask) { return (decision_type & mask) > 0; } inline static void SetDecisionType(int8_t* decision_type, bool input, int8_t mask) { if (input) { (*decision_type) |= mask; } else { (*decision_type) &= (127 - mask); } } inline static int8_t GetMissingType(int8_t decision_type) { return (decision_type >> 2) & 3; } inline static void SetMissingType(int8_t* decision_type, int8_t input) { (*decision_type) &= 3; (*decision_type) |= (input << 2); } void RecomputeMaxDepth(); int NextLeafId() const { return num_leaves_; } private: std::string NumericalDecisionIfElse(int node) const; std::string CategoricalDecisionIfElse(int node) const; inline int NumericalDecision(double fval, int node) const { uint8_t missing_type = GetMissingType(decision_type_[node]); if (std::isnan(fval) && missing_type != MissingType::NaN) { fval = 0.0f; } if ((missing_type == MissingType::Zero && IsZero(fval)) || (missing_type == MissingType::NaN && std::isnan(fval))) { if (GetDecisionType(decision_type_[node], kDefaultLeftMask)) { return left_child_[node]; } else { return right_child_[node]; } } if (fval <= threshold_[node]) { return left_child_[node]; } else { return right_child_[node]; } } inline int NumericalDecisionInner(uint32_t fval, int node, uint32_t default_bin, uint32_t max_bin) const { uint8_t missing_type = GetMissingType(decision_type_[node]); if ((missing_type == MissingType::Zero && fval == default_bin) || (missing_type == MissingType::NaN && fval == max_bin)) { if (GetDecisionType(decision_type_[node], kDefaultLeftMask)) { return left_child_[node]; } else { return right_child_[node]; } } if (fval <= threshold_in_bin_[node]) { return left_child_[node]; } else { return right_child_[node]; } } inline int CategoricalDecision(double fval, int node) const { uint8_t missing_type = GetMissingType(decision_type_[node]); int int_fval = static_cast<int>(fval); if (int_fval < 0) { return right_child_[node];; } else if (std::isnan(fval)) { // NaN is always in the right if (missing_type == MissingType::NaN) { return right_child_[node]; } int_fval = 0; } int cat_idx = static_cast<int>(threshold_[node]); if (Common::FindInBitset(cat_threshold_.data() + cat_boundaries_[cat_idx], cat_boundaries_[cat_idx + 1] - cat_boundaries_[cat_idx], int_fval)) { return left_child_[node]; } return right_child_[node]; } inline int CategoricalDecisionInner(uint32_t fval, int node) const { int cat_idx = static_cast<int>(threshold_in_bin_[node]); if (Common::FindInBitset(cat_threshold_inner_.data() + cat_boundaries_inner_[cat_idx], cat_boundaries_inner_[cat_idx + 1] - cat_boundaries_inner_[cat_idx], fval)) { return left_child_[node]; } return right_child_[node]; } inline int Decision(double fval, int node) const { if (GetDecisionType(decision_type_[node], kCategoricalMask)) { return CategoricalDecision(fval, node); } else { return NumericalDecision(fval, node); } } inline int DecisionInner(uint32_t fval, int node, uint32_t default_bin, uint32_t max_bin) const { if (GetDecisionType(decision_type_[node], kCategoricalMask)) { return CategoricalDecisionInner(fval, node); } else { return NumericalDecisionInner(fval, node, default_bin, max_bin); } } inline void Split(int leaf, int feature, int real_feature, double left_value, double right_value, int left_cnt, int right_cnt, double left_weight, double right_weight, float gain); /*! * \brief Find leaf index of which record belongs by features * \param feature_values Feature value of this record * \return Leaf index */ inline int GetLeaf(const double* feature_values) const; inline int GetLeafByMap(const std::unordered_map<int, double>& feature_values) const; /*! \brief Serialize one node to json*/ std::string NodeToJSON(int index) const; /*! \brief Serialize one node to if-else statement*/ std::string NodeToIfElse(int index, bool predict_leaf_index) const; std::string NodeToIfElseByMap(int index, bool predict_leaf_index) const; double ExpectedValue() const; /*! \brief This is used fill in leaf_depth_ after reloading a model*/ inline void RecomputeLeafDepths(int node = 0, int depth = 0); /*! * \brief Used by TreeSHAP for data we keep about our decision path */ struct PathElement { int feature_index; double zero_fraction; double one_fraction; // note that pweight is included for convenience and is not tied with the other attributes, // the pweight of the i'th path element is the permutation weight of paths with i-1 ones in them double pweight; PathElement() {} PathElement(int i, double z, double o, double w) : feature_index(i), zero_fraction(z), one_fraction(o), pweight(w) {} }; /*! \brief Polynomial time algorithm for SHAP values (arXiv:1706.06060)*/ void TreeSHAP(const double *feature_values, double *phi, int node, int unique_depth, PathElement *parent_unique_path, double parent_zero_fraction, double parent_one_fraction, int parent_feature_index) const; /*! \brief Extend our decision path with a fraction of one and zero extensions for TreeSHAP*/ static void ExtendPath(PathElement *unique_path, int unique_depth, double zero_fraction, double one_fraction, int feature_index); /*! \brief Undo a previous extension of the decision path for TreeSHAP*/ static void UnwindPath(PathElement *unique_path, int unique_depth, int path_index); /*! determine what the total permutation weight would be if we unwound a previous extension in the decision path*/ static double UnwoundPathSum(const PathElement *unique_path, int unique_depth, int path_index); /*! \brief Number of max leaves*/ int max_leaves_; /*! \brief Number of current leaves*/ int num_leaves_; // following values used for non-leaf node /*! \brief A non-leaf node's left child */ std::vector<int> left_child_; /*! \brief A non-leaf node's right child */ std::vector<int> right_child_; /*! \brief A non-leaf node's split feature */ std::vector<int> split_feature_inner_; /*! \brief A non-leaf node's split feature, the original index */ std::vector<int> split_feature_; /*! \brief A non-leaf node's split threshold in bin */ std::vector<uint32_t> threshold_in_bin_; /*! \brief A non-leaf node's split threshold in feature value */ std::vector<double> threshold_; int num_cat_; std::vector<int> cat_boundaries_inner_; std::vector<uint32_t> cat_threshold_inner_; std::vector<int> cat_boundaries_; std::vector<uint32_t> cat_threshold_; /*! \brief Store the information for categorical feature handle and missing value handle. */ std::vector<int8_t> decision_type_; /*! \brief A non-leaf node's split gain */ std::vector<float> split_gain_; // used for leaf node /*! \brief The parent of leaf */ std::vector<int> leaf_parent_; /*! \brief Output of leaves */ std::vector<double> leaf_value_; /*! \brief weight of leaves */ std::vector<double> leaf_weight_; /*! \brief DataCount of leaves */ std::vector<int> leaf_count_; /*! \brief Output of non-leaf nodes */ std::vector<double> internal_value_; /*! \brief weight of non-leaf nodes */ std::vector<double> internal_weight_; /*! \brief DataCount of non-leaf nodes */ std::vector<int> internal_count_; /*! \brief Depth for leaves */ std::vector<int> leaf_depth_; double shrinkage_; int max_depth_; }; inline void Tree::Split(int leaf, int feature, int real_feature, double left_value, double right_value, int left_cnt, int right_cnt, double left_weight, double right_weight, float gain) { int new_node_idx = num_leaves_ - 1; // update parent info int parent = leaf_parent_[leaf]; if (parent >= 0) { // if cur node is left child if (left_child_[parent] == ~leaf) { left_child_[parent] = new_node_idx; } else { right_child_[parent] = new_node_idx; } } // add new node split_feature_inner_[new_node_idx] = feature; split_feature_[new_node_idx] = real_feature; split_gain_[new_node_idx] = gain; // add two new leaves left_child_[new_node_idx] = ~leaf; right_child_[new_node_idx] = ~num_leaves_; // update new leaves leaf_parent_[leaf] = new_node_idx; leaf_parent_[num_leaves_] = new_node_idx; // save current leaf value to internal node before change internal_weight_[new_node_idx] = leaf_weight_[leaf]; internal_value_[new_node_idx] = leaf_value_[leaf]; internal_count_[new_node_idx] = left_cnt + right_cnt; leaf_value_[leaf] = std::isnan(left_value) ? 0.0f : left_value; leaf_weight_[leaf] = left_weight; leaf_count_[leaf] = left_cnt; leaf_value_[num_leaves_] = std::isnan(right_value) ? 0.0f : right_value; leaf_weight_[num_leaves_] = right_weight; leaf_count_[num_leaves_] = right_cnt; // update leaf depth leaf_depth_[num_leaves_] = leaf_depth_[leaf] + 1; leaf_depth_[leaf]++; } inline double Tree::Predict(const double* feature_values) const { if (num_leaves_ > 1) { int leaf = GetLeaf(feature_values); return LeafOutput(leaf); } else { return leaf_value_[0]; } } inline double Tree::PredictByMap(const std::unordered_map<int, double>& feature_values) const { if (num_leaves_ > 1) { int leaf = GetLeafByMap(feature_values); return LeafOutput(leaf); } else { return leaf_value_[0]; } } inline int Tree::PredictLeafIndex(const double* feature_values) const { if (num_leaves_ > 1) { int leaf = GetLeaf(feature_values); return leaf; } else { return 0; } } inline int Tree::PredictLeafIndexByMap(const std::unordered_map<int, double>& feature_values) const { if (num_leaves_ > 1) { int leaf = GetLeafByMap(feature_values); return leaf; } else { return 0; } } inline void Tree::PredictContrib(const double* feature_values, int num_features, double* output) { output[num_features] += ExpectedValue(); // Run the recursion with preallocated space for the unique path data if (num_leaves_ > 1) { CHECK_GE(max_depth_, 0); const int max_path_len = max_depth_ + 1; std::vector<PathElement> unique_path_data(max_path_len*(max_path_len + 1) / 2); TreeSHAP(feature_values, output, 0, 0, unique_path_data.data(), 1, 1, -1); } } inline void Tree::RecomputeLeafDepths(int node, int depth) { if (node == 0) leaf_depth_.resize(num_leaves()); if (node < 0) { leaf_depth_[~node] = depth; } else { RecomputeLeafDepths(left_child_[node], depth + 1); RecomputeLeafDepths(right_child_[node], depth + 1); } } inline int Tree::GetLeaf(const double* feature_values) const { int node = 0; if (num_cat_ > 0) { while (node >= 0) { node = Decision(feature_values[split_feature_[node]], node); } } else { while (node >= 0) { node = NumericalDecision(feature_values[split_feature_[node]], node); } } return ~node; } inline int Tree::GetLeafByMap(const std::unordered_map<int, double>& feature_values) const { int node = 0; if (num_cat_ > 0) { while (node >= 0) { node = Decision(feature_values.count(split_feature_[node]) > 0 ? feature_values.at(split_feature_[node]) : 0.0f, node); } } else { while (node >= 0) { node = NumericalDecision(feature_values.count(split_feature_[node]) > 0 ? feature_values.at(split_feature_[node]) : 0.0f, node); } } return ~node; } } // namespace LightGBM #endif // LightGBM_TREE_H_
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-2021, 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) ; }
lib_openmp.c
// This code makes some assumptions on the implementation of // trk_base64_stream_encode_init(), trk_base64_stream_encode() and trk_base64_stream_decode(). // Basically these assumptions boil down to that when breaking the src into // parts, out parts can be written without side effects. // This is met when: // 1) trk_base64_stream_encode() and trk_base64_stream_decode() don't use globals; // 2) the shared variables src and out are not read or written outside of the // bounds of their parts, i.e. when trk_base64_stream_encode() reads a multiple // of 3 bytes, it must write no more then a multiple of 4 bytes, not even // temporarily; // 3) the state flag can be discarded after trk_base64_stream_encode() and // trk_base64_stream_decode() on the parts. static inline void base64_encode_openmp ( const char *src , size_t srclen , char *out , size_t *outlen , int flags ) { size_t s; size_t t; size_t sum = 0, len, last_len; struct base64_state state, initial_state; int num_threads, i; // Request a number of threads but not necessarily get them: #pragma omp parallel { // Get the number of threads used from one thread only, // as num_threads is a shared var: #pragma omp single { num_threads = omp_get_num_threads(); // Split the input string into num_threads parts, each // part a multiple of 3 bytes. The remaining bytes will // be done later: len = srclen / (num_threads * 3); len *= 3; last_len = srclen - num_threads * len; // Init the stream reader: trk_base64_stream_encode_init(&state, flags); initial_state = state; } // Single has an implicit barrier for all threads to wait here // for the above to complete: #pragma omp for firstprivate(state) private(s) reduction(+:sum) schedule(static,1) for (i = 0; i < num_threads; i++) { // Feed each part of the string to the stream reader: trk_base64_stream_encode(&state, src + i * len, len, out + i * len * 4 / 3, &s); sum += s; } } // As encoding should never fail and we encode an exact multiple // of 3 bytes, we can discard state: state = initial_state; // Encode the remaining bytes: trk_base64_stream_encode(&state, src + num_threads * len, last_len, out + num_threads * len * 4 / 3, &s); // Finalize the stream by writing trailer if any: trk_base64_stream_encode_final(&state, out + num_threads * len * 4 / 3 + s, &t); // Final output length is stream length plus tail: sum += s + t; *outlen = sum; } static inline int base64_decode_openmp ( const char *src , size_t srclen , char *out , size_t *outlen , int flags ) { int num_threads, result = 0, i; size_t sum = 0, len, last_len, s; struct base64_state state, initial_state; // Request a number of threads but not necessarily get them: #pragma omp parallel { // Get the number of threads used from one thread only, // as num_threads is a shared var: #pragma omp single { num_threads = omp_get_num_threads(); // Split the input string into num_threads parts, each // part a multiple of 4 bytes. The remaining bytes will // be done later: len = srclen / (num_threads * 4); len *= 4; last_len = srclen - num_threads * len; // Init the stream reader: trk_base64_stream_decode_init(&state, flags); initial_state = state; } // Single has an implicit barrier to wait here for the above to // complete: #pragma omp for firstprivate(state) private(s) reduction(+:sum, result) schedule(static,1) for (i = 0; i < num_threads; i++) { int this_result; // Feed each part of the string to the stream reader: this_result = trk_base64_stream_decode(&state, src + i * len, len, out + i * len * 3 / 4, &s); sum += s; result += this_result; } } // If `result' equals `-num_threads', then all threads returned -1, // indicating that the requested codec is not available: if (result == -num_threads) { return -1; } // If `result' does not equal `num_threads', then at least one of the // threads hit a decode error: if (result != num_threads) { return 0; } // So far so good, now decode whatever remains in the buffer. Reuse the // initial state, since we are at a 4-byte boundary: state = initial_state; result = trk_base64_stream_decode(&state, src + num_threads * len, last_len, out + num_threads * len * 3 / 4, &s); sum += s; *outlen = sum; // If when decoding a whole block, we're still waiting for input then fail: if (result && (state.bytes == 0)) { return result; } return 0; }
GB_binop__islt_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__islt_int32 // A.*B function (eWiseMult): GB_AemultB__islt_int32 // A*D function (colscale): GB_AxD__islt_int32 // D*A function (rowscale): GB_DxB__islt_int32 // C+=B function (dense accum): GB_Cdense_accumB__islt_int32 // C+=b function (dense accum): GB_Cdense_accumb__islt_int32 // C+=A+B function (dense ewise3): (none) // C=A+B function (dense ewise3): GB_Cdense_ewise3_noaccum__islt_int32 // C=scalar+B GB_bind1st__islt_int32 // C=scalar+B' GB_bind1st_tran__islt_int32 // C=A+scalar GB_bind2nd__islt_int32 // C=A'+scalar GB_bind2nd_tran__islt_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_ISLT || GxB_NO_INT32 || GxB_NO_ISLT_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__islt_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__islt_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__islt_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 //------------------------------------------------------------------------------ GrB_Info GB_AxD__islt_int32 ( 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 } //------------------------------------------------------------------------------ // C = D*B, row scale with diagonal D matrix //------------------------------------------------------------------------------ GrB_Info GB_DxB__islt_int32 ( 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 } //------------------------------------------------------------------------------ // 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__islt_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__islt_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__islt_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__islt_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__islt_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__islt_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
GB_unaryop__minv_int32_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__minv_int32_uint8 // op(A') function: GB_tran__minv_int32_uint8 // C type: int32_t // A type: uint8_t // cast: int32_t cij = (int32_t) aij // unaryop: cij = GB_IMINV_SIGNED (aij, 32) #define GB_ATYPE \ uint8_t #define GB_CTYPE \ int32_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 = GB_IMINV_SIGNED (x, 32) ; // casting #define GB_CASTING(z, aij) \ int32_t z = (int32_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_MINV || GxB_NO_INT32 || GxB_NO_UINT8) //------------------------------------------------------------------------------ // Cx = op (cast (Ax)): apply a unary operator //------------------------------------------------------------------------------ GrB_Info GB_unop__minv_int32_uint8 ( int32_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__minv_int32_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
fixed_version.c
#include <stdio.h> int main(){ int sum =0; int temp[100]; int DATA_MAG = 100; int H[100]; int scale_factor = 10; int i; int LUT[100]; #pragma omp parallel default (none) private(i) shared (temp, LUT, H, scale_factor, sum, DATA_MAG) { #pragma omp for for (i =0; i < DATA_MAG;i++) { H[i] = i; temp[i]=0; } #pragma omp single for (i = 0; i < DATA_MAG; i++) { sum += H[i]; temp[i]=sum; } #pragma omp for for (i = 0; i < DATA_MAG; i++){ LUT[i] = temp[i] * scale_factor; } } for (i = 0; i < 100; i++) { printf("%d\n",LUT[i]); } return 0; }
error1.c
/****************************************************************************** * FILE: omp_bug3.c * DESCRIPTION: * Run time error * AUTHOR: Blaise Barney 01/09/04 * LAST REVISED: 06/28/05 ******************************************************************************/ #include <omp.h> #include <stdio.h> #include <stdlib.h> #define N 50 int main(int argc, char *argv[]) { int i, nthreads, tid, section; float a[N], b[N], c[N]; void print_results(float array[N], int tid, int section); /* Some initializations */ for (i = 0; i < N; i++) a[i] = b[i] = i * 1.0; #pragma omp parallel private(i, tid, section) { tid = omp_get_thread_num(); if (tid == 0) { nthreads = omp_get_num_threads(); printf("Number of threads = %d\n", nthreads); } /*** Use barriers for clean output ***/ #pragma omp barrier printf("Thread %d starting...\n", tid); #pragma omp barrier #pragma omp sections nowait { #pragma omp section { section = 1; for (i = 0; i < N; i++) c[i] = a[i] * b[i]; print_results(c, tid, section); } #pragma omp section { section = 2; for (i = 0; i < N; i++) c[i] = a[i] + b[i]; print_results(c, tid, section); } } /* end of sections */ /*** Use barrier for clean output ***/ #pragma omp barrier printf("Thread %d exiting...\n", tid); } /* end of parallel section */ } void print_results(float array[N], int tid, int section) { int i, j; j = 1; /*** use critical for clean output ***/ #pragma omp critical { printf("\nThread %d did section %d. The results are:\n", tid, section); for (i = 0; i < N; i++) { printf("%e ", array[i]); j++; if (j == 6) { printf("\n"); j = 1; } } printf("\n"); printf("Thread %d done and synchronized.\n", tid); } /*** end of critical ***/ }
citrix_ns_fmt_plug.c
/* * Description from Nicolas Ruff: * - Salt value is hashed as an hexadecimal string, not bytes. * - The trailing NULL byte of password string is taken into account during * hashing. * - The leading '1' is actually the string length * '1' = 49 = len('1') + len(hex_salt) + len(hex_sha1) * * --------------------------------------- * import hashlib * * def netscaler_hash( rand_bytes, pwd ): * s = hashlib.sha1() * s.update( rand_bytes ) * s.update( pwd ) * return "1" + rand_bytes + s.hexdigest() * * # TEST VECTOR * # 14dfca1e6c0f5f3d96526c3ce70849992b7fad3e324cf6b0f * * rand_bytes = "4dfca1e6" * pwd = "nsroot\x00" * print netscaler_hash( rand_bytes, pwd ) * --------------------------------------- * * This software is Copyright (c) 2013 magnum, 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. * * This version is hard coded for salt length 8 (for speed). */ #if FMT_EXTERNS_H extern struct fmt_main fmt_ctrxns; #elif FMT_REGISTERS_H john_register_one(&fmt_ctrxns); #else #include <string.h> #ifdef _OPENMP #ifdef SIMD_COEF_32 #ifndef OMP_SCALE #define OMP_SCALE 1024 #endif #else #ifndef OMP_SCALE #define OMP_SCALE 2048 #endif #endif #include <omp.h> #endif #include "arch.h" #include "misc.h" #include "formats.h" #include "options.h" #include "johnswap.h" #ifdef SIMD_COEF_32 #define NBKEYS (SIMD_COEF_32 * SIMD_PARA_SHA1) #endif #include "simd-intrinsics.h" #include "common.h" #include "sha.h" #include "memdbg.h" // Must be last included header #define FORMAT_LABEL "Citrix_NS10" #define FORMAT_NAME "Netscaler 10" #define ALGORITHM_NAME "SHA1 " SHA1_ALGORITHM_NAME #define BENCHMARK_COMMENT "" #define BENCHMARK_LENGTH 0 #define PLAINTEXT_LENGTH (55 - SALT_SIZE - 1) #define BINARY_SIZE 20 #define BINARY_ALIGN 4 #define SALT_SIZE 8 #define SALT_ALIGN 4 #ifdef SIMD_COEF_32 #define MIN_KEYS_PER_CRYPT NBKEYS #define MAX_KEYS_PER_CRYPT NBKEYS #define GETPOS(i, index) ((index&(SIMD_COEF_32-1))*4 + ((i)&(0xffffffff-3))*SIMD_COEF_32 + (((i)&3)^3) + (unsigned int)index/SIMD_COEF_32*SHA_BUF_SIZ*SIMD_COEF_32*4) //for endianity conversion #else #define MIN_KEYS_PER_CRYPT 1 #define MAX_KEYS_PER_CRYPT 1 #endif static struct fmt_tests tests[] = { {"100000000f1dc96f425971ba590a076fd0f8bccbf25c1ba0c", ""}, {"14623718525fe334bbd9c0704e06ce134ef17b51f6b33548c", " "}, {"15c5c5c5c6ccd884f6383f55a6aeba5f847775e57ab012675", "Tw"}, {"13333333319143136ba9ff9e18d1cb022b63df0926de9509e", "333"}, {"144434241d7ce89a7484cd202400639692258dde37efc29c5", "four"}, {"100010203e09cefed1847b7a2a5e7a5d2cdc67e8a56ed0bdd", "fiver"}, {"14dfca1e6c0f5f3d96526c3ce70849992b7fad3e324cf6b0f", "nsroot"}, {"1deadcafe7587ea23b25a6ccf3fd53192e36ad3e9a2553b20", "magnum!"}, {NULL} }; #ifdef SIMD_COEF_32 static unsigned char (*saved_key)[SHA_BUF_SIZ * 4 * NBKEYS]; static unsigned char (*crypt_key)[BINARY_SIZE * NBKEYS]; static unsigned int kpc; #else static char saved_salt[SALT_SIZE]; static char (*saved_key)[PLAINTEXT_LENGTH + 1]; static ARCH_WORD_32 (*crypt_key)[BINARY_SIZE / 4]; #endif static void init(struct fmt_main *self) { #ifdef _OPENMP int omp_t; 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 #ifdef SIMD_COEF_32 saved_key = mem_calloc_align(self->params.max_keys_per_crypt / NBKEYS, sizeof(*saved_key), MEM_ALIGN_SIMD); crypt_key = mem_calloc_align(self->params.max_keys_per_crypt / NBKEYS, sizeof(*crypt_key), MEM_ALIGN_SIMD); kpc = self->params.max_keys_per_crypt; #else saved_key = mem_calloc(self->params.max_keys_per_crypt, sizeof(*saved_key)); crypt_key = mem_calloc(self->params.max_keys_per_crypt, sizeof(*crypt_key)); #endif } static void done(void) { MEM_FREE(crypt_key); MEM_FREE(saved_key); } static void *get_binary(char *ciphertext) { static unsigned char *realcipher; int i, len; if (!realcipher) realcipher = mem_alloc_tiny(BINARY_SIZE, MEM_ALIGN_WORD); len = *ciphertext; ciphertext += len - 2 * BINARY_SIZE; for(i = 0; i < BINARY_SIZE; i++) { realcipher[i] = atoi16[ARCH_INDEX(ciphertext[i * 2])] * 16 + atoi16[ARCH_INDEX(ciphertext[i * 2 + 1])]; } #ifdef SIMD_COEF_32 alter_endianity(realcipher, BINARY_SIZE); #endif return (void*)realcipher; } static int valid(char *ciphertext, struct fmt_main *self) { int len; len = *ciphertext; if (len != (int)'1') return 0; if (strlen(ciphertext) != len) return 0; if (len != strspn(ciphertext, HEXCHARS_lc)) return 0; return 1; } static void set_key(char *key, int index) { #ifdef SIMD_COEF_32 #if ARCH_ALLOWS_UNALIGNED const ARCH_WORD_32 *wkey = (ARCH_WORD_32*)key; #else char buf_aligned[PLAINTEXT_LENGTH + 1] JTR_ALIGN(sizeof(uint32_t)); const ARCH_WORD_32 *wkey = (uint32_t*)(is_aligned(key, sizeof(uint32_t)) ? key : strcpy(buf_aligned, key)); #endif ARCH_WORD_32 *keybuf_word = (ARCH_WORD_32*)&saved_key[0][GETPOS(SALT_SIZE ^ 3, index)]; unsigned int len; ARCH_WORD_32 temp; len = SALT_SIZE; while((temp = *wkey++) & 0xff) { if (!(temp & 0xff00)) { *keybuf_word = JOHNSWAP((temp & 0xff) | (0x80 << 16)); len++; goto key_cleaning; } if (!(temp & 0xff0000)) { *keybuf_word = JOHNSWAP((temp & 0xffff) | (0x80U << 24)); len+=2; goto key_cleaning; } *keybuf_word = JOHNSWAP(temp); keybuf_word += SIMD_COEF_32; if (!(temp & 0xff000000)) { *keybuf_word = 0x80000000; len+=3; goto key_cleaning; } len += 4; } *keybuf_word = 0x00800000; key_cleaning: keybuf_word += SIMD_COEF_32; while(*keybuf_word) { *keybuf_word = 0; keybuf_word += SIMD_COEF_32; } len += 1; /* Trailing null is included */ ((unsigned int*)saved_key)[15*SIMD_COEF_32 + (index&(SIMD_COEF_32-1)) + (unsigned int)index/SIMD_COEF_32*SHA_BUF_SIZ*SIMD_COEF_32] = len << 3; #else strnzcpy(saved_key[index], key, PLAINTEXT_LENGTH + 1); #endif } static char *get_key(int index) { #ifdef SIMD_COEF_32 unsigned int i, s; static char out[PLAINTEXT_LENGTH + 1]; s = (((unsigned int*)saved_key)[15*SIMD_COEF_32 + (index&(SIMD_COEF_32-1)) + (unsigned int)index/SIMD_COEF_32*SHA_BUF_SIZ*SIMD_COEF_32] >> 3) - SALT_SIZE - 1; for(i = 0; i < s; i++) out[i] = ((char*)saved_key)[GETPOS(SALT_SIZE + i, index)]; out[i] = 0; return out; #else return saved_key[index]; #endif } static void *get_salt(char *ciphertext) { static union { unsigned char c[SALT_SIZE]; ARCH_WORD_32 w; } out; ciphertext++; memcpy(out.c, ciphertext, SALT_SIZE); return (void*)out.c; } static void set_salt(void *salt) { #ifdef SIMD_COEF_32 int i, index; for (index = 0; index < kpc; index++) for (i = 0; i < SALT_SIZE; i++) saved_key[0][GETPOS(i, index)] = ((unsigned char*)salt)[i]; #else memcpy(saved_salt, salt, SALT_SIZE); #endif } static int cmp_all(void *binary, int count) { #ifdef SIMD_COEF_32 unsigned int x, y=0; for(; y < kpc/SIMD_COEF_32; y++) for(x = 0; x < SIMD_COEF_32; x++) { if(((ARCH_WORD_32*)binary)[0] == ((ARCH_WORD_32*)crypt_key)[x + y * SIMD_COEF_32*5]) return 1; } return 0; #else int index = 0; #ifdef _OPENMP for (index = 0; index < count; index++) #endif if (((ARCH_WORD_32*)binary)[0] == crypt_key[index][0]) return 1; return 0; #endif } static int cmp_one(void *binary, int index) { #ifdef SIMD_COEF_32 unsigned int x, y; x = index & (SIMD_COEF_32-1); y = (unsigned int)index / SIMD_COEF_32; if(((ARCH_WORD_32*)binary)[0] != ((ARCH_WORD_32*)crypt_key)[x + y * SIMD_COEF_32*5]) return 0; if(((ARCH_WORD_32*)binary)[1] != ((ARCH_WORD_32*)crypt_key)[x + y * SIMD_COEF_32*5+SIMD_COEF_32*1]) return 0; if(((ARCH_WORD_32*)binary)[2] != ((ARCH_WORD_32*)crypt_key)[x + y * SIMD_COEF_32*5+SIMD_COEF_32*2]) return 0; if(((ARCH_WORD_32*)binary)[3] != ((ARCH_WORD_32*)crypt_key)[x + y * SIMD_COEF_32*5+SIMD_COEF_32*3]) return 0; if(((ARCH_WORD_32*)binary)[4] != ((ARCH_WORD_32*)crypt_key)[x + y * SIMD_COEF_32*5+SIMD_COEF_32*4]) return 0; return 1; #else return !memcmp(binary, crypt_key[index], BINARY_SIZE); #endif } static int cmp_exact(char *source, int index) { return (1); } static int crypt_all(int *pcount, struct db_salt *salt) { const int count = *pcount; int index = 0; #ifdef _OPENMP int loops = (count + MAX_KEYS_PER_CRYPT - 1) / MAX_KEYS_PER_CRYPT; #pragma omp parallel for for (index = 0; index < loops; ++index) #endif { #ifdef SIMD_COEF_32 SIMDSHA1body(saved_key[index], (unsigned int*)crypt_key[index], NULL, SSEi_MIXED_IN); #else SHA_CTX ctx; SHA1_Init(&ctx); SHA1_Update(&ctx, (unsigned char*)saved_salt, SALT_SIZE); SHA1_Update(&ctx, (unsigned char*)saved_key[index], strlen(saved_key[index]) + 1); SHA1_Final((unsigned char*)crypt_key[index], &ctx); #endif } return count; } #ifdef SIMD_COEF_32 #define HASH_IDX ((index&(SIMD_COEF_32-1))+((unsigned int)index/SIMD_COEF_32)*SIMD_COEF_32*5) static int get_hash_0(int index) { return ((ARCH_WORD_32*)crypt_key)[HASH_IDX] & PH_MASK_0; } static int get_hash_1(int index) { return ((ARCH_WORD_32*)crypt_key)[HASH_IDX] & PH_MASK_1; } static int get_hash_2(int index) { return ((ARCH_WORD_32*)crypt_key)[HASH_IDX] & PH_MASK_2; } static int get_hash_3(int index) { return ((ARCH_WORD_32*)crypt_key)[HASH_IDX] & PH_MASK_3; } static int get_hash_4(int index) { return ((ARCH_WORD_32*)crypt_key)[HASH_IDX] & PH_MASK_4; } static int get_hash_5(int index) { return ((ARCH_WORD_32*)crypt_key)[HASH_IDX] & PH_MASK_5; } static int get_hash_6(int index) { return ((ARCH_WORD_32*)crypt_key)[HASH_IDX] & PH_MASK_6; } #else static int get_hash_0(int index) { return crypt_key[index][0] & PH_MASK_0; } static int get_hash_1(int index) { return crypt_key[index][0] & PH_MASK_1; } static int get_hash_2(int index) { return crypt_key[index][0] & PH_MASK_2; } static int get_hash_3(int index) { return crypt_key[index][0] & PH_MASK_3; } static int get_hash_4(int index) { return crypt_key[index][0] & PH_MASK_4; } static int get_hash_5(int index) { return crypt_key[index][0] & PH_MASK_5; } static int get_hash_6(int index) { return crypt_key[index][0] & PH_MASK_6; } #endif static int salt_hash(void *salt) { return *(ARCH_WORD_32*)salt & (SALT_HASH_SIZE - 1); } struct fmt_main fmt_ctrxns = { { 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_OMP_BAD, { NULL }, { NULL }, tests }, { init, done, fmt_default_reset, fmt_default_prepare, valid, fmt_default_split, get_binary, get_salt, { NULL }, 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 }, salt_hash, NULL, 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 */
move.h
#pragma once #include "core.h" #include "energy.h" #include "average.h" //#include "analysis.h" #include "potentials.h" #include "mpi.h" namespace Faunus { namespace Move { class Movebase { private: virtual void _move(Change&)=0; //!< Perform move and modify change object virtual void _accept(Change&); //!< Call after move is accepted virtual void _reject(Change&); //!< Call after move is rejected virtual void _to_json(json &j) const=0; //!< Extra info for report if needed virtual void _from_json(const json &j)=0; //!< Extra info for report if needed TimeRelativeOfTotal<std::chrono::microseconds> timer; protected: unsigned long cnt=0; unsigned long accepted=0; unsigned long rejected=0; public: static Random slump; //!< Shared for all moves std::string name; //!< Name of move std::string cite; //!< Reference int repeat=1; //!< How many times the move should be repeated per sweep void from_json(const json &j); void to_json(json &j) const; //!< JSON report w. statistics, output etc. void move(Change &change); //!< Perform move and modify given change object void accept(Change &c); void reject(Change &c); virtual double bias(Change &c, double uold, double unew); //!< adds extra energy change not captured by the Hamiltonian }; void from_json(const json &j, Movebase &m); //!< Configure any move via json void to_json(json &j, const Movebase &m); /** * @brief Swap the charge of a single atom */ template<typename Tspace> class AtomicSwapCharge : public Movebase { private: typedef typename Tspace::Tpvec Tpvec; typedef typename Tspace::Tparticle Tparticle; Tspace& spc; // Space to operate on int molid=-1; double ln10 = log(10); double pKa, pH; Average<double> msqd; // mean squared displacement double _sqd, _bias; // squared displament std::string molname; // name of molecule to operate on Change::data cdata; void _to_json(json &j) const override { j = { {"pH", pH}, {"pka", pKa}, {"molid", molid}, {u8::rootof + u8::bracket("r" + u8::squared), std::sqrt(msqd.avg())}, {"molecule", molname} }; _roundjson(j,3); } void _from_json(const json &j) override { assert(!molecules<Tpvec>.empty()); try { molname = j.at("molecule"); auto it = findName(molecules<Tpvec>, molname); if (it == molecules<Tpvec>.end()) throw std::runtime_error("unknown molecule '" + molname + "'"); molid = it->id(); pH = j.at("pH").get<double>(); pKa = j.at("pKa").get<double>(); if (repeat<0) { auto v = spc.findMolecules(molid); repeat = std::distance(v.begin(), v.end()); // repeat for each molecule... if (repeat>0) repeat = repeat * v.front().size(); // ...and for each atom } } catch (std::exception &e) { std::cerr << name << ": " << e.what(); throw; } } //!< Configure via json object typename Tpvec::iterator randomAtom() { assert(molid>=0); auto mollist = spc.findMolecules( molid ); // all `molid` groups if (size(mollist)>0) { auto git = slump.sample( mollist.begin(), mollist.end() ); // random molecule iterator if (!git->empty()) { auto p = slump.sample( git->begin(), git->end() ); // random particle iterator cdata.index = Faunus::distance( spc.groups.begin(), git ); // integer *index* of moved group cdata.atoms[0] = std::distance(git->begin(), p); // index of particle rel. to group return p; } } return spc.p.end(); } void _move(Change &change) override { auto p = randomAtom(); if (p!=spc.p.end()) { auto& g = spc.groups[cdata.index]; double oldcharge = p->charge; p->charge = fabs(oldcharge - 1); _sqd = fabs(oldcharge - 1) - oldcharge; change.groups.push_back( cdata ); // add to list of moved groups _bias = _sqd*(pH-pKa)*ln10; // one may add bias here... } } double bias(Change &change, double uold, double unew) override { return _bias; } //!< adds extra energy change not captured by the Hamiltonian void _accept(Change &change) override { msqd += _sqd; } void _reject(Change &change) override { msqd += 0; } public: AtomicSwapCharge(Tspace &spc) : spc(spc) { name = "swapcharge"; repeat = -1; // meaning repeat N times cdata.atoms.resize(1); cdata.internal=true; } }; /** * @brief Translate and rotate a molecular group */ template<typename Tspace> class AtomicTranslateRotate : public Movebase { private: typedef typename Tspace::Tpvec Tpvec; typedef typename Tspace::Tparticle Tparticle; Tspace& spc; // Space to operate on int molid=-1; Point dir={1,1,1}; Average<double> msqd; // mean squared displacement double _sqd; // squared displament std::string molname; // name of molecule to operate on Change::data cdata; void _to_json(json &j) const override { j = { {"dir", dir}, {"molid", molid}, {u8::rootof + u8::bracket("r" + u8::squared), std::sqrt(msqd.avg())}, {"molecule", molname} }; _roundjson(j,3); } void _from_json(const json &j) override { assert(!molecules<Tpvec>.empty()); try { molname = j.at("molecule"); auto it = findName(molecules<Tpvec>, molname); if (it == molecules<Tpvec>.end()) throw std::runtime_error("unknown molecule '" + molname + "'"); molid = it->id(); dir = j.value("dir", Point(1,1,1)); if (repeat<0) { auto v = spc.findMolecules(molid, Tspace::ALL ); repeat = std::distance(v.begin(), v.end()); // repeat for each molecule... if (repeat>0) repeat = repeat * v.front().size(); // ...and for each atom } } catch (std::exception &e) { std::cerr << name << ": " << e.what(); throw; } } //!< Configure via json object typename Tpvec::iterator randomAtom() { assert(molid>=0); //std::cout<<"molid "<<molid<<std::endl; auto mollist = spc.findMolecules( molid, Tspace::ALL ); // all `molid` groups if (size(mollist)>0) { //std::cout<<"looking for atoms"<<std::endl; auto git = slump.sample( mollist.begin(), mollist.end() ); // random molecule iterator if (!git->empty()) { //std::cout<<"found molecule"<<std::endl; auto p = slump.sample( git->begin(), git->end() ); // random particle iterator cdata.index = Faunus::distance( spc.groups.begin(), git ); // integer *index* of moved group cdata.atoms[0] = std::distance(git->begin(), p); // index of particle rel. to group return p; } } return spc.p.end(); } void _move(Change &change) override { auto p = randomAtom(); if (p!=spc.p.end()) { double dp = atoms.at(p->id).dp; double dprot = atoms.at(p->id).dprot; auto& g = spc.groups[cdata.index]; if (dp>0) { // translate Point oldpos = p->pos; p->pos += 0.5 * dp * ranunit(slump).cwiseProduct(dir); spc.geo.boundaryFunc(p->pos); _sqd = spc.geo.sqdist(oldpos, p->pos); // squared displacement if (!g.atomic) g.cm = Geometry::massCenter(g.begin(), g.end(), spc.geo.boundaryFunc, -g.cm); } if (dprot>0) { // rotate Point u = ranunit(slump); double angle = dprot * (slump()-0.5); Eigen::Quaterniond Q( Eigen::AngleAxisd(angle, u) ); p->rotate(Q, Q.toRotationMatrix()); } if (dp>0 || dprot>0) change.groups.push_back( cdata ); // add to list of moved groups } //else // std::cerr << name << ": no atoms found" << std::endl; } void _accept(Change &change) override { msqd += _sqd; } void _reject(Change &change) override { msqd += 0; } public: AtomicTranslateRotate(Tspace &spc) : spc(spc) { name = "transrot"; repeat = -1; // meaning repeat N times cdata.atoms.resize(1); cdata.internal=true; } }; /** * @brief Translate and rotate a molecular group */ template<typename Tspace> class TranslateRotate : public Movebase { protected: typedef typename Tspace::Tpvec Tpvec; Tspace& spc; // Space to operate on int molid=-1; double dptrans=0; double dprot=0; Point dir={1,1,1}; double _sqd; // squared displacement Average<double> msqd; // mean squared displacement void _to_json(json &j) const override { j = { {"dir", dir}, {"dp", dptrans}, {"dprot", dprot}, {"molid", molid}, {u8::rootof + u8::bracket("r" + u8::squared), std::sqrt(msqd.avg())}, {"molecule", molecules<Tpvec>[molid].name} }; _roundjson(j,3); } void _from_json(const json &j) override { assert(!molecules<Tpvec>.empty()); try { std::string molname = j.at("molecule"); auto it = findName(molecules<Tpvec>, molname); if (it == molecules<Tpvec>.end()) throw std::runtime_error("unknown molecule '" + molname + "'"); molid = it->id(); dir = j.value("dir", Point(1,1,1)); dprot = j.at("dprot"); dptrans = j.at("dp"); if (repeat<0) { auto v = spc.findMolecules(molid); repeat = std::distance(v.begin(), v.end()); } } catch (std::exception &e) { throw std::runtime_error(name+": " + e.what()); } } //!< Configure via json object void _move(Change &change) override { assert(molid>=0); assert(!spc.groups.empty()); assert(spc.geo.getVolume()>0); // pick random group from the system matching molecule type // TODO: This can be slow -- implement look-up-table in Space auto mollist = spc.findMolecules( molid, Tspace::ACTIVE ); // list of molecules w. 'molid' if (size(mollist)>0) { auto it = slump.sample( mollist.begin(), mollist.end() ); if (!it->empty()) { assert(it->id==molid); if (dptrans>0) { // translate Point oldcm = it->cm; Point dp = 0.5*ranunit(slump).cwiseProduct(dir) * dptrans; it->translate( dp, spc.geo.boundaryFunc ); _sqd = spc.geo.sqdist(oldcm, it->cm); // squared displacement } if (dprot>0) { // rotate Point u = ranunit(slump); double angle = dprot * (slump()-0.5); Eigen::Quaterniond Q( Eigen::AngleAxisd(angle, u) ); it->rotate(Q, spc.geo.boundaryFunc); } if (dptrans>0||dprot>0) { // define changes Change::data d; d.index = Faunus::distance( spc.groups.begin(), it ); // integer *index* of moved group d.all = true; // *all* atoms in group were moved change.groups.push_back( d ); // add to list of moved groups } assert( spc.geo.sqdist( it->cm, Geometry::massCenter(it->begin(),it->end(),spc.geo.boundaryFunc,-it->cm) ) < 1e-9 ); } } } void _accept(Change &change) override { msqd += _sqd; } void _reject(Change &change) override { msqd += 0; } public: TranslateRotate(Tspace &spc) : spc(spc) { name = "moltransrot"; repeat = -1; // meaning repeat N times } }; /** * @brief Move that will swap conformation of a molecule * * This will swap between different molecular conformations * as defined in `MoleculeData` with `traj` and `weight`. * If defined, the weight * distribution is respected, otherwise all conformations * have equal intrinsic weight. Upon insertion, the new conformation * is randomly oriented and placed on top of the mass-center of * an exising molecule. That is, there is no mass center movement. * * @todo Add feature to align molecule on top of an exiting one * @todo Expand `_info()` to show number of conformations * @warning Weighted distributions untested and not verified for correctness * @date Malmo, November 2016 */ template<class Tspace> class ConformationSwap : public Movebase { private: typedef typename Tspace::Tpvec Tpvec; typedef MoleculeData<Tpvec> Tmoldata; RandomInserter<Tmoldata> inserter; Tspace& spc; // Space to operate on int molid=-1; int newconfid=-1; void _to_json(json &j) const override { j = { {"molid", molid}, {"molecule", molecules<Tpvec>[molid].name} }; _roundjson(j,3); } void _from_json(const json &j) override { assert(!molecules<Tpvec>.empty()); try { std::string molname = j.at("molecule"); auto it = findName(molecules<Tpvec>, molname); if (it == molecules<Tpvec>.end()) throw std::runtime_error("unknown molecule '" + molname + "'"); molid = it->id(); if ( molecules<Tpvec>[molid].conformations.size()<2) throw std::runtime_error("minimum two conformations required"); if (repeat<0) { auto v = spc.findMolecules(molid); repeat = std::distance(v.begin(), v.end()); } } catch (std::exception &e) { throw std::runtime_error(name+": " + e.what()); } } //!< Configure via json object void _move(Change &change) override { assert(molid>=0); assert(change.empty()); auto mollist = spc.findMolecules( molid, Tspace::ACTIVE ); // list of molecules w. 'molid' if ( size(mollist)>0 ) { auto g = slump.sample( mollist.begin(), mollist.end() ); if (not g->empty()) { inserter.offset = g->cm; // Get a new conformation that should be properly wrapped around the boundaries // (if applicable) and have the same mass-center as "g->cm". Tpvec p = inserter(spc.geo, spc.p, molecules<Tpvec>[molid]); if (p.size() not_eq g->size()) throw std::runtime_error(name + ": conformation atom count mismatch"); newconfid = molecules<Tpvec>[molid].conformations.index; std::copy( p.begin(), p.end(), g->begin() ); // override w. new conformation #ifndef NDEBUG // this move shouldn't move mass centers, so let's check if this is true: Point newcm = Geometry::massCenter(p.begin(), p.end(), spc.geo.boundaryFunc, -g->cm); if ( (newcm - g->cm).norm()>1e-6 ) throw std::runtime_error(name + ": unexpected mass center movement"); #endif Change::data d; d.index = Faunus::distance(spc.groups.begin(), g); // integer *index* of moved group d.all = true; // *all* atoms in group were moved d.internal = false; // we *don't* want to calculate the internal energy change.groups.push_back( d ); // add to list of moved groups } } } void _accept(Change &change) override { assert(change.groups.size()==1); spc.groups[ change.groups.front().index ].confid = newconfid; } public: ConformationSwap(Tspace &spc) : spc(spc) { name = "conformationswap"; repeat = -1; // meaning repeat n times inserter.dir = {0,0,0}; inserter.rotate = true; } }; // end of conformation swap move /** * @brief Sketch for MD move */ template<typename Tspace> class ForceMove : public Movebase { private: typedef typename Tspace::Tpvec Tpvec; void _to_json(json &j) const {}; void _from_json(const json &j) {}; std::vector<Point> forces, velocities; public: ForceMove() { // resize forces and velocities to mathc spc.p } }; // end of forcemove #ifdef DOCTEST_LIBRARY_INCLUDED TEST_CASE("[Faunus] TranslateRotate") { typedef Particle<Radius, Charge, Dipole, Cigar> Tparticle; typedef Space<Geometry::Cuboid, Tparticle> Tspace; typedef typename Tspace::Tpvec Tpvec; CHECK( !atoms.empty() ); // set in a previous test CHECK( !molecules<Tpvec>.empty() ); // set in a previous test Tspace spc; TranslateRotate<Tspace> mv(spc); json j = R"( {"molecule":"B", "dp":1.0, "dprot":0.5, "dir":[0,1,0], "repeat":2 })"_json; mv.from_json(j); j = json(mv).at(mv.name); CHECK( j.at("molecule") == "B"); CHECK( j.at("dir") == Point(0,1,0) ); CHECK( j.at("dp") == 1.0 ); CHECK( j.at("repeat") == 2 ); CHECK( j.at("dprot") == 0.5 ); } #endif template<typename Tspace> class VolumeMove : public Movebase { private: const std::map<std::string, Geometry::VolumeMethod> methods = { {"xy", Geometry::XY}, {"isotropic", Geometry::ISOTROPIC}, {"isochoric", Geometry::ISOCHORIC} }; typename decltype(methods)::const_iterator method; typedef typename Tspace::Tpvec Tpvec; Tspace& spc; Average<double> msqd; // mean squared displacement double dV=0, deltaV=0, Vnew=0, Vold=0; void _to_json(json &j) const override { using namespace u8; j = { {"dV", dV}, {"method", method->first}, {rootof + bracket(Delta + "V" + squared), std::sqrt(msqd.avg())}, {cuberoot + rootof + bracket(Delta + "V" + squared), std::cbrt(std::sqrt(msqd.avg()))} }; _roundjson(j,3); } void _from_json(const json &j) override { method = methods.find( j.value("method", "isotropic") ); if (method==methods.end()) std::runtime_error("unknown volume change method"); dV = j.at("dV"); } void _move(Change &change) override { if (dV>0) { change.dV=true; change.all=true; Vold = spc.geo.getVolume(); if (method->second == Geometry::ISOCHORIC) Vold = std::pow(Vold,1.0/3.0); // volume is constant Vnew = std::exp(std::log(Vold) + (slump()-0.5) * dV); deltaV = Vnew-Vold; spc.scaleVolume(Vnew, method->second); } else deltaV=0; } void _accept(Change &change) override { msqd += deltaV*deltaV; } void _reject(Change &change) override { msqd += 0; } public: VolumeMove(Tspace &spc) : spc(spc) { name = "volume"; repeat = 1; } }; // end of VolumeMove /* * @brief Establishes equilibrium of matter * Establishes equilibrium of matter between all species * * Consider the dissociation process AX=A+X. This class will locate * all species of type AX and A and make a MC swap move between them. * X is implicit, meaning that it enters only with its chemical potential * (activity). The titrating species, their dissociation constants * and the chemical potential of the titrant are read from a * `processes` JSON object. * For example, for proton titration of phosphate one would * use the following JSON input (pH 7.0): * * @todo * Implement classification of reactions to group weight in * mc sweep {refrerence : prob(reference)} * */ template<typename Tspace> class SpeciationMove : public Movebase { private: typedef typename Tspace::Tpvec Tpvec; Tspace& spc; Tspace *otherspc; ReactionData<Tpvec> *trialprocess; std::map<std::string, Average<double>> accmap; double lnK; bool forward; std::vector<int> molDel; // index of groups to delete std::vector<int> atomDel; // atom index to delete std::map<int, int> molcnt_ins, atomcnt_ins, molcnt_del, atomcnt_del, molcnt, atomcnt; // id's and number of inserted/deleted mols and atoms std::multimap<int, Tpvec> pmap; // coordinates of mols and atoms to be inserted unsigned int Ndeleted, Ninserted; // Number of accepted deletions and insertions void _to_json(json &j) const override { j = { // { "replicas", mpi.nproc() }, // { "datasize", pt.getFormat() } }; json &_j = j["reactions"]; _j = json::object(); for (auto &m : accmap) _j[m.first] = { {"attempts", m.second.cnt}, {"acceptance", m.second.avg()} }; } void _from_json(const json &j) override { //j["speciation"] = "speciation"; } public: SpeciationMove(Tspace &spc) : spc(spc) { name = "speciation"; repeat = 1; } void setOther(Tspace &ospc) { otherspc = &ospc; } double energy(); //!< Returns intrinsic energy of the process void _move(Change &change) override { if ( reactions<Tpvec>.size()>0 ) { auto rit = slump.sample( reactions<Tpvec>.begin(), reactions<Tpvec>.end() ); lnK = rit->lnK; forward = (bool)slump.range(0,1); // random boolean trialprocess = &(*rit); if ( rit->empty(forward) ) // Enforce canonic constraint if invoked return; //Out of material, slip out the back door for (auto &m : rit->Molecules2Add( !forward )) { // Delete checks auto mollist = spc.findMolecules( m.first, Tspace::ALL); if ( molecules<Tpvec>[m.first].atomic ) { if( size(mollist)!=1 ) // There can be only one throw std::runtime_error("Bad definition: One group per atomic molecule!"); auto git = mollist.begin(); if ( git->size() < m.second ) // assure that there are atoms enough in the group return; } else { mollist = spc.findMolecules( m.first, Tspace::ACTIVE); if ( size(mollist) < m.second ) return; // Not possible to perform change, escape through the back door } } for (auto &m : rit->Molecules2Add( forward )) { // Addition checks auto mollist = spc.findMolecules( m.first, Tspace::ALL); if ( molecules<Tpvec>[m.first].atomic ) { if( size(mollist)!=1 ) // There can be only one throw std::runtime_error("Bad definition: One group per atomic molecule!"); auto git = mollist.begin(); if ( (git->size() + m.second) > git->capacity() ) // assure that there are atoms enough in the group return; // if not slip out the back door } else { mollist = spc.findMolecules( m.first, Tspace::INACTIVE); if ( size(mollist) < m.second ) return; // Not possible to perform change, escape through the back door } } //The move is doable, raise flag change.dNpart=true; for (auto &m : rit->Molecules2Add( !forward )) { // Delete auto mollist = spc.findMolecules( m.first, Tspace::ALL); if ( molecules<Tpvec>[m.first].atomic ) { if( size(mollist)!=1 ) // There can be only one throw std::runtime_error("Bad definition: One group per atomic molecule!"); Change::data d; auto git = mollist.begin(); auto othermollist = otherspc->findMolecules(m.first, Tspace::ALL); // implies that new and old are in sync auto othergit=othermollist.begin(); d.index = Faunus::distance( spc.groups.begin(), git ); // integer *index* of moved group d.internal = true; d.dNpart = true; for ( int N=0; N<m.second; N++ ) { // deactivate m.second m.first atoms auto ait = slump.sample( git->begin(), git->end()); // iterator to random atom // Shuffle back to end, both in trial and new auto nait = git->end()-1; //iterator to last atom int dist = Faunus::distance( ait, git->end() ); // distance to random atom from end if ( Faunus::distance( ait, nait) > 1 ) { std::iter_swap(ait, nait); std::iter_swap(othergit->end()-dist-N, othergit->end() - (1+N) ); } d.atoms.push_back ( Faunus::distance(git->begin(), nait) ); git->deactivate( nait, git->end()); } std::sort( d.atoms.begin(), d.atoms.end() ); change.groups.push_back( d ); // add to list of moved groups spc.moltracker[m.first] -= m.second; } else { mollist = spc.findMolecules( m.first, Tspace::ACTIVE); for ( int N=0; N <m.second; N++ ) { Change::data d; auto git = slump.sample(mollist.begin(), mollist.end()); git->deactivate( git->begin(), git->end()); d.index = Faunus::distance( spc.groups.begin(), git ); // integer *index* of moved group d.all = true; // *all* atoms in group were moved d.internal = true; for (int i=0; i<git->capacity(); i++) d.atoms.push_back(i); change.groups.push_back( d ); // add to list of moved groups mollist = spc.findMolecules( m.first , Tspace::ACTIVE); // Activate/deactivate all? simply move end to front? } spc.moltracker[m.first] -= m.second; } } for (auto &m : rit->Molecules2Add( forward )) { // Add auto mollist = spc.findMolecules( m.first, Tspace::ALL); if ( molecules<Tpvec>[m.first].atomic ) { Change::data d; auto git = mollist.begin(); d.index = Faunus::distance( spc.groups.begin(), git); d.internal = true; d.dNpart = true; for ( int N=0; N<m.second; N++ ) { // activate m.second m.first atoms git->activate( git->end(), git->end() + 1); auto ait = git->end()-1; spc.geo.randompos(ait->pos, slump); spc.geo.boundaryFunc(ait->pos); d.atoms.push_back( Faunus::distance(git->begin(), ait) ); // index of particle rel. to group } std::sort( d.atoms.begin(), d.atoms.end()); change.groups.push_back( d ); // add to list of moved groups spc.moltracker[m.first] += m.second; } else { mollist = spc.findMolecules( m.first, Tspace::INACTIVE); if ( size(mollist) < m.second ) { change.dNpart=false; return; // Not possible to perform change, escape through the back door } for ( int N=0; N <m.second; N++ ) { Change::data d; auto git = slump.sample(mollist.begin(), mollist.end()); git->activate( git->inactive().begin(), git->inactive().end()); Point newpoint; // = git->cm; spc.geo.randompos(newpoint, random); git->translate( -git->cm, spc.geo.boundaryFunc ); git->translate( newpoint, spc.geo.boundaryFunc ); Point u = ranunit(slump); //double angle = dprot * (slump()-0.5); Eigen::Quaterniond Q( Eigen::AngleAxisd(2*pc::pi*random(), u) ); git->rotate(Q, spc.geo.boundaryFunc); d.index = Faunus::distance( spc.groups.begin(), git ); // integer *index* of moved group d.all = true; // *all* atoms in group were moved d.internal = true; for (int i=0; i<git->capacity(); i++) d.atoms.push_back(i); change.groups.push_back( d ); // add to list of moved groups assert( spc.geo.sqdist( git->cm, Geometry::massCenter(git->begin(),git->end(),spc.geo.boundaryFunc, -git->cm ) ) < 1e-9 ); mollist = spc.findMolecules( m.first , Tspace::INACTIVE); } spc.moltracker[m.first] += m.second; } } std::sort(change.groups.begin(), change.groups.end() ); } else throw std::runtime_error("No reactions in list, disable speciation or add reactions"); } double bias(Change &change, double uold, double unew) override { if (forward) return -lnK; return lnK; } //!< adds extra energy change not captured by the Hamiltonian void _accept(Change &change) override { accmap[ trialprocess->name ] += 1; trialprocess->N_reservoir += (forward == true) ? -1 : 1; if( trialprocess->N_reservoir < 0 && trialprocess->canonic == true ) throw std::runtime_error("There are no negative number of molecules"); } void _reject(Change &change) override { accmap[ trialprocess->name ] += 0; } }; // End of class SpeciationMove template<typename Tspace> class Cluster : public Movebase { private: typedef typename Tspace::Tpvec Tpvec; typedef typename Tspace::Tgroup Tgroup; Tspace& spc; Average<double> msqd, msqd_angle, N; double thresholdsq=0, dptrans=0, dprot=0, angle=0, _bias=0; size_t bias_rejected=0; Point dir={1,1,1}, dp; std::vector<std::string> names; // names of molecules to be considered std::vector<int> ids; // molecule id's of molecules to be considered std::vector<size_t> index; // index of all possible molecules to be considered virtual double clusterProbability(const Tgroup &g1, const Tgroup &g2) const { if (spc.geo.sqdist(g1.cm, g2.cm)<=thresholdsq) return 1.0; return 0.0; } void _to_json(json &j) const override { using namespace u8; j = { {"threshold", std::sqrt(thresholdsq)}, {"dir", dir}, {"dp", dptrans}, {"dprot", dprot}, {rootof + bracket("r" + squared), std::sqrt(msqd.avg())}, {rootof + bracket(theta + squared) + "/" + degrees, std::sqrt(msqd_angle.avg()) / 1.0_deg}, {bracket("N"), N.avg()}, {"bias rejection rate", double(bias_rejected) / cnt} }; _roundjson(j,3); } void _from_json(const json &j) override { dptrans = j.at("dp"); dir = j.value("dir", Point(1,1,1)); dprot = j.at("dprot"); thresholdsq = std::pow(j.at("threshold").get<double>(), 2); names = j.at("molecules").get<decltype(names)>(); // molecule names ids = names2ids(molecules<Tpvec>, names); // names --> molids index.clear(); for (auto &g : spc.groups) if (!g.atomic) if (std::find(ids.begin(), ids.end(), g.id)!=ids.end() ) index.push_back( &g-&spc.groups.front() ); if (repeat<0) repeat = index.size(); } /** * @param spc Space * @param first Index of initial molecule (randomly selected) * @param index w. all molecules clustered around first (first included) */ void findCluster(Tspace &spc, size_t first, std::set<size_t>& cluster) const { assert(first < spc.p.size()); std::set<size_t> pool(index.begin(), index.end()); assert(pool.count(first)>0); cluster.clear(); cluster.insert(first); pool.erase(first); size_t n; do { // find cluster (not very clever...) n = cluster.size(); for (size_t i : cluster) if (not spc.groups.at(i).empty()) // check if group is inactive for (size_t j : pool) if (not spc.groups.at(j).empty()) // check if group is inactive if (i!=j) { // probability to cluster double P = clusterProbability(spc.groups.at(i), spc.groups.at(j)); if ( Movebase::slump() <= P ) { cluster.insert(j); pool.erase(j); break; } } } while (cluster.size() not_eq n); // check if cluster is too large double max = spc.geo.getLength().minCoeff()/2; for (auto i : cluster) for (auto j : cluster) if (j>i) if (spc.geo.sqdist(spc.groups.at(i).cm, spc.groups.at(j).cm)>=max*max) throw std::runtime_error(name+": cluster larger than half box length"); } void _move(Change &change) override { if (thresholdsq>0 && !index.empty()) { std::set<size_t> cluster; // all group index in cluster size_t first = *slump.sample(index.begin(), index.end()); // random molecule (nuclei) findCluster(spc, first, cluster); // find cluster around first N += cluster.size(); // average cluster size Change::data d; d.all=true; dp = 0.5*ranunit(slump).cwiseProduct(dir) * dptrans; angle = dprot * (slump()-0.5); Point COM = Geometry::trigoCom(spc, cluster); // cluster center Eigen::Quaterniond Q; Q = Eigen::AngleAxisd(angle, ranunit(slump)); // quaternion for (auto i : cluster) { // loop over molecules in cluster auto &g = spc.groups[i]; Geometry::rotate(g.begin(), g.end(), Q, spc.geo.boundaryFunc, -COM); g.cm = g.cm-COM; spc.geo.boundary(g.cm); g.cm = Q*g.cm+COM; spc.geo.boundary(g.cm); g.translate( dp, spc.geo.boundaryFunc ); d.index=i; change.groups.push_back(d); } #ifndef NDEBUG Point newCOM = Geometry::trigoCom(spc, cluster); double _zero = std::sqrt( spc.geo.sqdist(COM,newCOM) ) - dp.norm(); if (fabs(_zero)>1) std::cerr << _zero << " "; #endif // Reject if cluster composition changes during move // Note: this only works for the binary 0/1 probability function // currently implemented in `findCluster()`. std::set<size_t> aftercluster; // all group index in cluster _after_move findCluster(spc, first, aftercluster); // find cluster around first if (aftercluster == cluster) _bias = 0; else { _bias = pc::infty; bias_rejected++; } } } double bias(Change &change, double uold, double unew) override { return _bias; } //!< adds extra energy change not captured by the Hamiltonian void _reject(Change &change) override { msqd += 0; msqd_angle += 0; } void _accept(Change &change) override { msqd += dp.squaredNorm(); msqd_angle += angle*angle; } public: Cluster(Tspace &spc) : spc(spc) { cite = "doi:10/cj9gnn"; name = "cluster"; repeat = -1; // meaning repeat N times } }; template<typename Tspace> class Pivot : public Movebase { private: typedef typename Tspace::Tpvec Tpvec; std::vector<std::shared_ptr<Potential::BondData>> bonds; std::vector<int> index; // atom index to rotate Tspace& spc; std::string molname; int molid; double dprot; double d2; // cm movement, squared Average<double> msqd; // cm mean squared displacement void _to_json(json &j) const override { using namespace u8; j = { {"molecule", molname}, {"dprot", dprot}, {u8::rootof + u8::bracket("r_cm" + u8::squared), std::sqrt(msqd.avg())} }; _roundjson(j,3); } void _from_json(const json &j) override { dprot = j.at("dprot"); molname = j.at("molecule"); auto it = findName(molecules<Tpvec>, molname); if (it == molecules<Tpvec>.end()) throw std::runtime_error("unknown molecule '" + molname + "'"); molid = it->id(); bonds = Potential::filterBonds( molecules<Tpvec>[molid].bonds, Potential::BondData::HARMONIC); if (repeat<0) { auto v = spc.findMolecules(molid); repeat = std::distance(v.begin(), v.end()); // repeat for each molecule... if (repeat>0) repeat *= bonds.size(); } } void _move(Change &change) override { d2=0; if (std::fabs(dprot)>1e-9) { auto g = spc.randomMolecule(molid, slump); // look for random group if (g!=spc.groups.end()) if (g->size()>2) { // must at least have three atoms auto b = slump.sample(bonds.begin(), bonds.end()); // random harmonic bond if (b != bonds.end()) { int i1 = (*b)->index.at(0); int i2 = (*b)->index.at(1); int offset = std::distance( spc.p.begin(), g->begin() ); index.clear(); if (slump()>0.5) for (size_t i=i2+1; i<g->size(); i++) index.push_back(i+offset); else for (int i=0; i<i1; i++) index.push_back(i+offset); i1+=offset; i2+=offset; if (!index.empty()) { Point oldcm = g->cm; g->unwrap(spc.geo.distanceFunc); // remove pbc Point u = (spc.p[i1].pos - spc.p[i2].pos).normalized(); double angle = dprot * (slump()-0.5); Eigen::Quaterniond Q( Eigen::AngleAxisd(angle, u) ); auto M = Q.toRotationMatrix(); for (auto i : index) { spc.p[i].rotate(Q, M); // internal rot. spc.p[i].pos = Q * ( spc.p[i].pos - spc.p[i1].pos) + spc.p[i1].pos; // positional rot. } g->cm = Geometry::massCenter(g->begin(), g->end()); g->wrap(spc.geo.boundaryFunc); // re-apply pbc d2 = spc.geo.sqdist(g->cm, oldcm); // CM movement Change::data d; d.index = Faunus::distance( spc.groups.begin(), g ); // integer *index* of moved group d.all = d.internal = true; // trigger internal interactions change.groups.push_back( d ); // add to list of moved groups } } } } } void _accept(Change &change) override { msqd += d2; } void _reject(Change &change) override { msqd += 0; } public: Pivot(Tspace &spc) : spc(spc) { name = "pivot"; repeat = -1; // --> repeat=N } }; //!< Pivot move around random harmonic bond axis #ifdef ENABLE_MPI /** * @brief Class for parallel tempering (aka replica exchange) using MPI * * Although not completely correct, the recommended way of performing a temper move * is to do `N` Monte Carlo passes with regular moves and then do a tempering move. * This is because the MPI nodes must be in sync and if you have a system where * the random number generator calls are influenced by the Hamiltonian we could * end up in a deadlock. * * @date Lund 2012, 2018 */ template<class Tspace> class ParallelTempering : public Movebase { private: typedef typename Tspace::Tpvec Tpvec; typedef typename Tspace::Tparticle Tparticle; Tspace& spc; // Space to operate on MPI::MPIController& mpi; int partner; //!< Exchange replica (partner) enum extradata {VOLUME=0}; //!< Structure of extra data to send std::map<std::string, Average<double>> accmap; MPI::FloatTransmitter ft; //!< Class for transmitting floats over MPI MPI::ParticleTransmitter<Tpvec> pt;//!< Class for transmitting particles over MPI void findPartner() { int dr=0; partner = mpi.rank(); (mpi.random()>0.5) ? dr++ : dr--; (mpi.rank() % 2 == 0) ? partner+=dr : partner-=dr; } //!< Find replica to exchange with bool goodPartner() { assert(partner!=mpi.rank() && "Selfpartner! This is not supposed to happen."); if (partner>=0) if ( partner<mpi.nproc() ) if ( partner!=mpi.rank() ) return true; return false; } //!< Is partner valid? void _to_json(json &j) const override { j = { { "replicas", mpi.nproc() }, { "datasize", pt.getFormat() } }; json &_j = j["exchange"]; _j = json::object(); for (auto &m : accmap) _j[m.first] = { {"attempts", m.second.cnt}, {"acceptance", m.second.avg()} }; } void _move(Change &change) override { double Vold = spc.geo.getVolume(); findPartner(); Tpvec p; // temperary storage p.resize(spc.p.size()); if (goodPartner()) { change.all=true; pt.sendExtra[VOLUME]=Vold; // copy current volume for sending pt.recv(mpi, partner, p); // receive particles pt.send(mpi, spc.p, partner); // send everything pt.waitrecv(); pt.waitsend(); double Vnew = pt.recvExtra[VOLUME]; if (Vnew<1e-9 || spc.p.size() != p.size()) MPI_Abort(mpi.comm, 1); if (std::fabs(Vnew-Vold)>1e-9) change.dV=true; spc.p = p; spc.geo.setVolume(Vnew); // update mass centers for (auto& g : spc.groups) if (g.atomic==false) g.cm = Geometry::massCenter(g.begin(), g.end(), spc.geo.boundaryFunc, -g.begin()->pos); } } double exchangeEnergy(double mydu) { std::vector<MPI::FloatTransmitter::floatp> duSelf(1), duPartner; duSelf[0]=mydu; duPartner = ft.swapf(mpi, duSelf, partner); return duPartner.at(0); // return partner energy change } //!< Exchange energy with partner double bias(Change &change, double uold, double unew) override { return exchangeEnergy(unew-uold); // Exchange dU with partner (MPI) } std::string id() { std::ostringstream o; if (mpi.rank() < partner) o << mpi.rank() << " <-> " << partner; else o << partner << " <-> " << mpi.rank(); return o.str(); } //!< Unique string to identify set of partners void _accept(Change &change) override { if ( goodPartner() ) accmap[ id() ] += 1; } void _reject(Change &change) override { if ( goodPartner() ) accmap[ id() ] += 0; } void _from_json(const json &j) override { pt.setFormat( j.value("format", std::string("XYZQI") ) ); } public: ParallelTempering(Tspace &spc, MPI::MPIController &mpi ) : spc(spc), mpi(mpi) { name="temper"; partner=-1; pt.recvExtra.resize(1); pt.sendExtra.resize(1); } }; #endif template<typename Tspace> class Propagator : public BasePointerVector<Movebase> { private: int _repeat; std::discrete_distribution<> dist; std::vector<double> w; // list of weights for each move void addWeight(double weight=1) { w.push_back(weight); dist = std::discrete_distribution<>(w.begin(), w.end()); _repeat = int(std::accumulate(w.begin(), w.end(), 0.0)); } public: using BasePointerVector<Movebase>::vec; inline Propagator() {} inline Propagator(const json &j, Tspace &spc, MPI::MPIController &mpi) { if (j.count("random")==1) Movebase::slump = j["random"]; // slump is static --> shared for all moves for (auto &m : j.at("moves")) {// loop over move list size_t oldsize = vec.size(); for (auto it : m.items()) { try { #ifdef ENABLE_MPI if (it.key()=="temper") this->template push_back<Move::ParallelTempering<Tspace>>(spc, mpi); #endif if (it.key()=="moltransrot") this->template push_back<Move::TranslateRotate<Tspace>>(spc); if (it.key()=="conformationswap") this->template push_back<Move::ConformationSwap<Tspace>>(spc); if (it.key()=="transrot") this->template push_back<Move::AtomicTranslateRotate<Tspace>>(spc); if (it.key()=="pivot") this->template push_back<Move::Pivot<Tspace>>(spc); if (it.key()=="volume") this->template push_back<Move::VolumeMove<Tspace>>(spc); if (it.key()=="speciation") this->template push_back<Move::SpeciationMove<Tspace>>(spc); if (it.key()=="cluster") this->template push_back<Move::Cluster<Tspace>>(spc); if (vec.size()==oldsize+1) { vec.back()->from_json( it.value() ); addWeight(vec.back()->repeat); } else std::cerr << "warning: ignoring unknown move '" << it.key() << "'" << endl; } catch (std::exception &e) { throw std::runtime_error("Error adding move '" + it.key() + "': " + e.what()); } } } } int repeat() { return _repeat; } auto sample() { if (!vec.empty()) { assert(w.size() == vec.size()); return vec.begin() + dist( Move::Movebase::slump.engine ); } return vec.end(); } //!< Pick move from a weighted, random distribution }; }//Move namespace template<class Tgeometry, class Tparticle> class MCSimulation { private: typedef Space<Tgeometry, Tparticle> Tspace; typedef typename Tspace::Tpvec Tpvec; bool metropolis(double du) const { if (std::isnan(du)) throw std::runtime_error("Metropolis error: energy cannot be NaN"); if (du<0) return true; return ( Move::Movebase::slump() > std::exp(-du)) ? false : true; } //!< Metropolis criterion (true=accept) struct State { Tspace spc; Energy::Hamiltonian<Tspace> pot; State(const json &j) : spc(j), pot(spc,j) {} void sync(State &other, Change &change) { spc.sync( other.spc, change ); pot.sync( &other.pot, change ); } }; //!< Contains everything to describe a state State state1, // old state state2; // new state (trial); double uinit=0, dusum=0; Average<double> uavg; void init() { dusum=0; Change c; c.all=true; state1.pot.key = Energy::Energybase::OLD; // this is the old energy (current) state2.pot.key = Energy::Energybase::NEW; // this is the new energy (trial) state1.pot.init(); uinit = state1.pot.energy(c); state2.sync(state1, c); state2.pot.init(); // Hack in reference to state1 in speciation for (auto base : moves.vec) { auto derived = std::dynamic_pointer_cast<Move::SpeciationMove<Tspace>>(base); if (derived) derived->setOther(state1.spc); } #ifndef NDEBUG double u2 = state2.pot.energy(c); double error = std::fabs(uinit-u2); if (std::isfinite(uinit)) { if (uinit!=0) assert(error/uinit<1e-3); else assert(error<1e-6); } //cout << "u1 = " << uinit << " u2 = " << u2 << endl; //assert( std::fabs((uinit-u2)/uinit)<1e-3 ); #endif } public: Move::Propagator<Tspace> moves; auto& pot() { return state1.pot; } auto& space() { return state1.spc; } const auto& pot() const { return state1.pot; } const auto& space() const { return state1.spc; } const auto& geometry() const { return state1.spc.geo; } const auto& particles() const { return state1.spc.p; } double drift() { Change c; c.all=true; double ufinal = state1.pot.energy(c); return ( ufinal-(uinit+dusum) ) / uinit; } //!< Calculates the relative energy drift from initial configuration MCSimulation(const json &j, MPI::MPIController &mpi) : state1(j), state2(j), moves(j, state2.spc, mpi) { init(); } void store(json &j) const { j = state1.spc; j["random-move"] = Move::Movebase::slump; j["random-global"] = Faunus::random; } // store system to json object void restore(const json &j) { state1.spc = j; state2.spc = j; Move::Movebase::slump = j["random-move"]; // restore move random number generator Faunus::random = j["random-global"]; // restore global random number generator reactions<Tpvec> = j.at("reactionlist").get<decltype(reactions<Tpvec>)>(); // should be handled by space init(); } //!< restore system from previously store json object void move() { Change change; for (int i=0; i<moves.repeat(); i++) { auto mv = moves.sample(); // pick random move if (mv != moves.end() ) { change.clear(); (**mv).move(change); if (!change.empty()) { double unew, uold, du; #pragma omp parallel sections { #pragma omp section { unew = state2.pot.energy(change); } #pragma omp section { uold = state1.pot.energy(change); } } du = unew - uold; // if any energy returns NaN (from i.e. division by zero), the // configuration will always be rejected, or if moving from NaN // to a finite energy, always accepted. if (std::isnan(uold) and not std::isnan(unew)) du = -pc::infty; // accept else if (std::isnan(unew)) du = pc::infty; // reject // if the difference in energy is NaN (from i.e. infinity minus infinity), the // configuration will always be accepted. This should be // noted during equilibration. else if (std::isnan(du)) du = 0; // accept double bias = (**mv).bias(change, uold, unew) + Nchem( state2.spc, state1.spc , change); if ( metropolis(du + bias) ) { // accept move state1.sync( state2, change ); (**mv).accept(change); } else { // reject move state2.sync( state1, change ); (**mv).reject(change); du=0; } dusum+=du; // sum of all energy changes } } } } void to_json(json &j) { j = state1.spc.info(); j["temperature"] = pc::temperature / 1.0_K; j["moves"] = moves; j["energy"].push_back(state1.pot); } }; template<class Tgeometry, class Tparticle> void to_json(json &j, MCSimulation<Tgeometry,Tparticle> &mc) { mc.to_json(j); } /** * @brief add documentation..... * * @f[ * \beta U = \ln ( \sum N_o!/N_n! \exp([N_n - N_o]\beta \mu) V^{N_n - N_o} ) * @f] * * @todo * - Rename to something more descriptive * - use exception message to suggest how to fix the problem */ template<typename Tspace> double Nchem( Tspace &spc_n, Tspace &spc_o, const Change &change) { using Tpvec = typename Tspace::Tpvec; double NoverO=0; if ( change.dNpart ) {// Have the number of any molecules changed for ( auto &m : change.groups ) { // ToDo fix so that it works for dN > 1 for molecuar species int N_o = 0;//spc_o.moltracker[spc_n.groups[m.index].id]; int N_n = 0;//spc_n.moltracker[spc_n.groups[m.index].id]; // int dN = N_n - N_o; if (!m.dNpart) if (!molecules<Tpvec>[ spc_n.groups[m.index].id ].atomic) { // Molecular species auto mollist_n = spc_n.findMolecules(m.index, Tspace::ACTIVE); auto mollist_o = spc_o.findMolecules(m.index, Tspace::ACTIVE); N_n=size(mollist_n); N_o=size(mollist_o); } if ( m.dNpart ) { auto mollist_n = spc_n.findMolecules(spc_n.groups[m.index].id, Tspace::ALL); auto mollist_o = spc_o.findMolecules(spc_o.groups[m.index].id, Tspace::ALL); if ( size(mollist_n) > 1 || size(mollist_o) > 1 ) throw std::runtime_error("Bad definition: One group per atomic molecule!"); // Below is safe due to the catches above // add consistency criteria with m.atoms.size() == N N_n = mollist_n.begin()->size(); N_o = mollist_o.begin()->size(); } int dN = N_n - N_o; // std::cout <<"old dN "<<dN<<" new dN"<< spc_n.moltracker[spc_n.groups[m.index].id]-spc_o.moltracker[spc_n.groups[m.index].id]<<std::endl // <<"old N_n and N_o "<<N_n<<" "<<N_o<<std::endl // <<"new N_n and N_o "<<spc_n.moltracker[spc_n.groups[m.index].id]<<" "<<spc_o.moltracker[spc_n.groups[m.index].id]<<std::endl; if (dN!=0) { double V_n = spc_n.geo.getVolume(); double V_o = spc_o.geo.getVolume(); double betamu = molecules<Tpvec>[ spc_n.groups[m.index].id ].activity; // todo: add runtime error if activity <=0 ? if (betamu > 1e-20) betamu = std::log( betamu / 1.0_molar ); if (dN>0) for (int n=0; n < dN; n++) NoverO += -std::log( (N_o + 1 + n) / ( V_n * 1.0_molar )) + betamu; else if (dN<0) for (int n=0; n < (-dN); n++) NoverO += std::log( (N_o - n) / ( V_n * 1.0_molar )) - betamu; } } } return -NoverO; // negative sign since Pref exp{-beta(dU)} = exp{-beta(dU -ln(Pref)} } }//Faunus namespace
thdat02.c
/* * Redistribution and use in source and binary forms, with * or without modification, are permitted provided that the * following conditions are met: * * 1. Redistributions of source code must retain this list * of conditions and the following disclaimer. * 2. Redistributions in binary form must reproduce 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 OWNER 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 <config.h> #include <stdlib.h> #include <thtk/thtk.h> #include "thdat.h" #include "thrle.h" #include "util.h" #include "dattypes.h" static int th02_open( thdat_t* thdat, thtk_error_t** error) { th03_archive_header_t th03_archive_header; th02_entry_header_t* th02_entry_headers = NULL; th03_entry_header_t* th03_entry_headers = NULL; if (thdat->version <= 2) { th02_entry_header_t eh2; if (thtk_io_read(thdat->stream, &eh2, sizeof(eh2), error) != sizeof(eh2)) return 0; if (thtk_io_seek(thdat->stream, 0, SEEK_SET, error) == -1) return 0; if (eh2.offset % sizeof(eh2)) { thtk_error_new(error, "first entry offset invalid"); return 0; } thdat->entry_count = (eh2.offset / sizeof(eh2)) - 1; } else { if (thtk_io_read(thdat->stream, &th03_archive_header, sizeof(th03_archive_header), error) != sizeof(th03_archive_header)) return 0; thdat->entry_count = th03_archive_header.count; } thdat->entries = malloc(thdat->entry_count * sizeof(thdat_entry_t)); if (thdat->version <= 2) { th02_entry_headers = malloc(thdat->entry_count * sizeof(th02_entry_header_t)); if (thtk_io_read(thdat->stream, th02_entry_headers, thdat->entry_count * sizeof(th02_entry_header_t), error) != (ssize_t)(thdat->entry_count * sizeof(th02_entry_header_t))) return 0; } else { th03_entry_headers = malloc(thdat->entry_count * sizeof(th03_entry_header_t)); if (thtk_io_read(thdat->stream, th03_entry_headers, thdat->entry_count * sizeof(th03_entry_header_t), error) != (ssize_t)(thdat->entry_count * sizeof(th03_entry_header_t))) return 0; unsigned char* data = (unsigned char*)th03_entry_headers; for (size_t i = 0; i < thdat->entry_count * sizeof(th03_entry_header_t); ++i) { data[i] ^= th03_archive_header.key; th03_archive_header.key -= data[i]; } } for (unsigned int e = 0; e < thdat->entry_count; ++e) { thdat_entry_t* entry = &thdat->entries[e]; entry->extra = thdat->version <= 2 ? th02_keys[thdat->version - 1] /* th02_entry_headers[e].key */ : th03_entry_headers[e].key; if (thdat->version <= 2) { for (unsigned int i = 0; i < 13 && th02_entry_headers[e].name[i]; ++i) th02_entry_headers[e].name[i] ^= 0xff; } memcpy(entry->name, thdat->version <= 2 ? th02_entry_headers[e].name : th03_entry_headers[e].name, 13); entry->zsize = thdat->version <= 2 ? th02_entry_headers[e].zsize : th03_entry_headers[e].zsize; entry->size = thdat->version <= 2 ? th02_entry_headers[e].size : th03_entry_headers[e].size; entry->offset = thdat->version <= 2 ? th02_entry_headers[e].offset : th03_entry_headers[e].offset; } free(th02_entry_headers); free(th03_entry_headers); return 1; } static ssize_t th02_read( thdat_t* thdat, int entry_index, thtk_io_t* output, thtk_error_t** error) { thdat_entry_t* entry = &thdat->entries[entry_index]; unsigned char* data; ssize_t ret; #pragma omp critical { data = thtk_io_map(thdat->stream, entry->offset, entry->zsize, error); } if (!data) return -1; for (ssize_t i = 0; i < entry->zsize; ++i) data[i] ^= entry->extra; if (entry->size == entry->zsize) { ret = thtk_io_write(output, data, entry->zsize, error); thtk_io_unmap(thdat->stream, data); } else { thtk_io_t* data_stream = thtk_io_open_memory(data, entry->zsize, error); if (!data_stream) return -1; ret = thtk_unrle(data_stream, entry->zsize, output, error); thtk_io_close(data_stream); } return ret; } static int th02_create( thdat_t* thdat, thtk_error_t** error) { if (thdat->version <= 2) thdat->offset = (thdat->entry_count + 1) * sizeof(th02_entry_header_t); else thdat->offset = sizeof(th03_archive_header_t) + (thdat->entry_count + 1) * sizeof(th03_entry_header_t); if (thtk_io_seek(thdat->stream, thdat->offset, SEEK_SET, error) == -1) return 0; return 1; } /* TODO: Find out if lowercase filenames are supported. */ static ssize_t th02_write( thdat_t* thdat, int entry_index, thtk_io_t* input, size_t input_length, thtk_error_t** error) { thdat_entry_t* entry = &thdat->entries[entry_index]; entry->size = input_length; off_t input_offset = thtk_io_seek(input, 0, SEEK_CUR, error); if (input_offset == -1) return -1; if (thdat->version <= 2) { for (unsigned int i = 0; i < 13; ++i) if (entry->name[i]) entry->name[i] ^= 0xff; } thtk_io_t* output = thtk_io_open_growing_memory(error); if (!output) return -1; if ((entry->zsize = thtk_rle(input, entry->size, output, error)) == -1) return -1; if (entry->zsize >= entry->size) { entry->zsize = entry->size; thtk_io_close(output); if (thtk_io_seek(input, input_offset, SEEK_SET, error) == -1) return -1; output = input; } unsigned char* data = thtk_io_map(output, 0, entry->zsize, error); if (!data) return -1; for (ssize_t i = 0; i < entry->zsize; ++i) data[i] ^= thdat->version <= 2 ? th02_keys[thdat->version - 1] : entry_key; ssize_t ret = -1; #pragma omp critical { entry->offset = thtk_io_seek(thdat->stream, 0, SEEK_CUR, error); if (entry->offset != -1) ret = thtk_io_write(thdat->stream, data, entry->zsize, error); if (ret != -1) thdat->offset += ret; } thtk_io_unmap(output, data); if (output != input) thtk_io_close(output); return ret; } static int th02_close( thdat_t* thdat, thtk_error_t** error) { if (thtk_io_seek(thdat->stream, 0, SEEK_SET, error) == -1) return 0; const th03_archive_header_t ah3 = { .size = (thdat->entry_count + 1) * sizeof(th03_entry_header_t), .unknown1 = 2, .count = thdat->entry_count, .key = archive_key }; if (thdat->version > 2) { if (thtk_io_write(thdat->stream, &ah3, sizeof(ah3), error) == -1) return 0; } size_t buffer_size = (thdat->entry_count + 1) * (thdat->version <= 2 ? sizeof(th02_entry_header_t) : sizeof(th03_entry_header_t)); unsigned char* buffer = malloc(buffer_size); unsigned char* buffer_ptr = buffer; memset(buffer, 0, buffer_size); for (size_t i = 0; i < thdat->entry_count; ++i) { thdat_entry_t* entry = &thdat->entries[i]; if (thdat->version <= 2) { th02_entry_header_t eh2 = { .magic = entry->zsize == entry->size ? magic1 : magic2, .key = 3, .zsize = entry->zsize, .size = entry->size, .offset = entry->offset }; memcpy(eh2.name, entry->name, 13); buffer_ptr = MEMPCPY(buffer_ptr, &eh2, sizeof(eh2)); } else { th03_entry_header_t eh3 = { .magic = entry->zsize == entry->size ? magic1 : magic2, .key = entry_key, .zsize = entry->zsize, .size = entry->size, .offset = entry->offset }; memcpy(eh3.name, entry->name, 13); buffer_ptr = MEMPCPY(buffer_ptr, &eh3, sizeof(eh3)); } } if (thdat->version > 2) { uint32_t data_key = archive_key; for (uint16_t i = 0; i < buffer_size; ++i) { unsigned char tmp = buffer[i]; buffer[i] ^= data_key; data_key -= tmp; } } if (thtk_io_write(thdat->stream, buffer, buffer_size, error) == -1) { free(buffer); return 0; } free(buffer); return 1; } const thdat_module_t archive_th02 = { THDAT_BASENAME | THDAT_UPPERCASE | THDAT_8_3, th02_open, th02_create, th02_close, th02_read, th02_write };
constant_density_acoustic_time_scalar_3D_6.h
#ifndef __CDA_TIME_SCALAR_3D_6__ #define __CDA_TIME_SCALAR_3D_6__ #include <stdlib.h> template< typename T, int ACCURACY > void cda_time_scalar_3D_6( T* km1_u, int nr_km1_u, int nc_km1_u, // in - padded wavefield shape T* k_Phix, int nr_k_Phix, int nc_k_Phix, // in - padded wavefield shape T* k_Phiy, int nr_k_Phiy, int nc_k_Phiy, // in - padded wavefield shape T* k_Phiz, int nr_k_Phiz, int nc_k_Phiz, // in - padded wavefield shape T* k_psi, int nr_k_psi, int nc_k_psi, // in T* k_u, int nr_k_u, int nc_k_u, // in - padded wavefield shape T* C, int nr_C, int nc_C, // in - padded wavefield shape T* rhs, int nr_rhs, int nc_rhs, // in - padded wavefield shape T* xlpml, int n_xlpml, // in - length is the number of nodes inside the padding that the pml value is defined. T* xrpml, int n_xrpml, // in - length is the number of nodes inside the padding that the pml value is defined. T* ylpml, int n_ylpml, // in - length is the number of nodes inside the padding that the pml value is defined. T* yrpml, int n_yrpml, // in - length is the number of nodes inside the padding that the pml value is defined. T* zlpml, int n_zlpml, // in - length is the number of nodes inside the padding that the pml value is defined. T* zrpml, int n_zrpml, // in - length is the number of nodes inside the padding that the pml value is defined. double const& dt, // in double const& dx, // in double const& dy, // in double const& dz, // in int const& nx, // in int const& ny, // in int const& nz, // in T* kp1_Phix, int nr_kp1_Phix, int nc_kp1_Phix, // out T* kp1_Phiy, int nr_kp1_Phiy, int nc_kp1_Phiy, // out T* kp1_Phiz, int nr_kp1_Phiz, int nc_kp1_Phiz, // out T* kp1_psi, int nr_kp1_psi, int nc_kp1_psi, // out T* kp1_u, int nr_kp1_u, int nc_kp1_u ) // out { enum {MAX_FD_SHIFT = ACCURACY/2}; T lapU = 0.0; // PML variable T sigmax = 0.0; T sigmay = 0.0; T sigmaz = 0.0; // Time delta variables T dt2 = dt*dt; // Loop/index variables int idx; int xstride = nz*ny; int ystride = nz; int zstride = 1; int s = zstride; int i, k, j; // shared space step square variable T dx2 = dx*dx; T dz2 = dz*dz; T dy2 = dy*dy; // private variables //non derivatives T fac1; T fac2; //derivatives T dux , duz, duy; T dPhix, dPhiz, dPhiy; T dPsix, dPsiz, dPsiy; char* NUM = getenv("OMP_NUM_THREADS"); int Num_Th = atoi (NUM); #pragma omp parallel for private(sigmaz, sigmax, sigmay, i, k, j, idx, dux, duz, duy, dPhix, dPhiz, dPhiy, lapU, fac1, fac2, dPsix, dPsiy, dPsiz) shared(dx, dx2, dz, dz2, dy, dy2, xstride, zstride, ystride, kp1_Phix, kp1_Phiz, kp1_Phiy, k_Phix, k_Phiz, k_Phiy, n_zrpml, n_zlpml, n_yrpml, n_ylpml, n_xrpml, n_xlpml, xrpml, xlpml, zrpml, zlpml, yrpml, ylpml, s, rhs, C, dt, dt2, km1_u, k_u, kp1_u) num_threads(Num_Th) collapse(3) for(int i=0; i < nx; ++i) { for(int j=0; j < ny; ++j) { for(int k=0; k < nz; k++) { idx = i*xstride + j*ystride + k; kp1_u[idx] = 0.0; kp1_Phix[idx] = 0.0; kp1_Phiy[idx] = 0.0; kp1_Phiz[idx] = 0.0; kp1_psi[idx] = 0.0; // This handles homogeneous Dirichlet BCs and non-updating in ghost regions. if ((i == 0) || (i == nx-1)) continue; if ((j == 0) || (j == ny-1)) continue; if ((k == 0) || (k == nz-1)) continue; lapU = 0.0; // Do the X direction if (i==0) { dux = ((-1./60.)*0.0+(3./20.)*0.0+(-3./4.)*0.0+0.0+(3./4.)*k_u[idx+xstride]+(-3./20.)*k_u[idx+2*xstride]+(1./60.)*k_u[idx+3*xstride])/dx; dPsix = ((-1./60.)*0.0+(3./20.)*0.0+(-3./4.)*0.0+0.0+(3./4.)*k_psi[idx+xstride]+(-3./20.)*k_psi[idx+2*xstride]+(1./60.)*k_psi[idx+3*xstride])/dx; dPhix = ((-1./60.)*0.0+(3./20.)*0.0+(-3./4.)*0.0+0.0+(3./4.)*k_Phix[idx+xstride]+(-3./20.)*k_Phix[idx+2*xstride]+(1./60.)*k_Phix[idx+3*xstride])/dx; lapU += ((1./90.)*0.0+(-3./20.)*0.0+(3./2.)*0.0+(-49./18.)*k_u[idx]+(3./2.)*k_u[idx+xstride]+(-3./20.)*k_u[idx+2*xstride]+(1./90.)*k_u[idx+3*xstride])/dx2; } else if (i == 1) { dux = ((-1./60.)*0.0+(3./20.)*0.0+(-3./4.)*k_u[idx-xstride]+0.0+(3./4.)*k_u[idx+xstride]+(-3./20.)*k_u[idx+2*xstride]+(1./60.)*k_u[idx+3*xstride])/dx; dPsix = ((-1./60.)*0.0+(3./20.)*0.0+(-3./4.)*k_psi[idx-xstride]+0.0+(3./4.)*k_psi[idx+xstride]+(-3./20.)*k_psi[idx+2*xstride]+(1./60.)*k_psi[idx+3*xstride])/dx; dPhix = ((-1./60.)*0.0+(3./20.)*0.0+(-3./4.)*k_Phix[idx-xstride]+0.0+(3./4.)*k_Phix[idx+xstride]+(-3./20.)*k_Phix[idx+2*xstride]+(1./60.)*k_Phix[idx+3*xstride])/dx; lapU += ((1./90.)*0.0+(-3./20.)*0.0+(3./2.)*k_u[idx-xstride]+(-49./18.)*k_u[idx]+(3./2.)*k_u[idx+xstride]+(-3./20.)*k_u[idx+2*xstride]+(1./90.)*k_u[idx+3*xstride])/dx2; } else if (i == 2) { dux = ((-1./60.)*0.0+(3./20.)*k_u[idx-2*xstride]+(-3./4.)*k_u[idx-xstride]+0.0+(3./4.)*k_u[idx+xstride]+(-3./20.)*k_u[idx+2*xstride]+(1./60.)*k_u[idx+3*xstride])/dx; dPsix = ((-1./60.)*0.0+(3./20.)*k_psi[idx-2*xstride]+(-3./4.)*k_psi[idx-xstride]+0.0+(3./4.)*k_psi[idx+xstride]+(-3./20.)*k_psi[idx+2*xstride]+(1./60.)*k_psi[idx+3*xstride])/dx; dPhix = ((-1./60.)*0.0+(3./20.)*k_Phix[idx-2*xstride]+(-3./4.)*k_Phix[idx-xstride]+0.0+(3./4.)*k_Phix[idx+xstride]+(-3./20.)*k_Phix[idx+2*xstride]+(1./60.)*k_Phix[idx+3*xstride])/dx; lapU += ((1./90.)*0.0+(-3./20.)*k_u[idx-2*xstride]+(3./2.)*k_u[idx-xstride]+(-49./18.)*k_u[idx]+(3./2.)*k_u[idx+xstride]+(-3./20.)*k_u[idx+2*xstride]+(1./90.)*k_u[idx+3*xstride])/dx2; } else if (i == nx-1) { dux = ((-1./60.)*k_u[idx-3*xstride]+(3./20.)*k_u[idx-2*xstride]+(-3./4.)*k_u[idx-xstride]+0.0+(3./4.)*0.0+(-3./20.)*0.0+(1./60.)*0.0)/dx; dPsix = ((-1./60.)*k_psi[idx-3*xstride]+(3./20.)*k_psi[idx-2*xstride]+(-3./4.)*k_psi[idx-xstride]+0.0+(3./4.)*0.0+(-3./20.)*0.0+(1./60.)*0.0)/dx; dPhix = ((-1./60.)*k_Phix[idx-3*xstride]+(3./20.)*k_Phix[idx-2*xstride]+(-3./4.)*k_Phix[idx-xstride]+0.0+(3./4.)*0.0+(-3./20.)*0.0+(1./60.)*0.0)/dx; lapU += ((1./90.)*k_u[idx-3*xstride]+(-3./20.)*k_u[idx-2*xstride]+(3./2.)*k_u[idx-xstride]+(-49./18.)*k_u[idx]+(3./2.)*0.0+(-3./20.)*0.0+(1./90.)*0.0)/dx2; } else if (i == nx-2) { dux = ((-1./60.)*k_u[idx-3*xstride]+(3./20.)*k_u[idx-2*xstride]+(-3./4.)*k_u[idx-xstride]+0.0+(3./4.)*k_u[idx+xstride]+(-3./20.)*0.0+(1./60.)*0.0)/dx; dPsix = ((-1./60.)*k_psi[idx-3*xstride]+(3./20.)*k_psi[idx-2*xstride]+(-3./4.)*k_psi[idx-xstride]+0.0+(3./4.)*k_psi[idx+xstride]+(-3./20.)*0.0+(1./60.)*0.0)/dx; dPhix = ((-1./60.)*k_Phix[idx-3*xstride]+(3./20.)*k_Phix[idx-2*xstride]+(-3./4.)*k_Phix[idx-xstride]+0.0+(3./4.)*k_Phix[idx+xstride]+(-3./20.)*0.0+(1./60.)*0.0)/dx; lapU += ((1./90.)*k_u[idx-3*xstride]+(-3./20.)*k_u[idx-2*xstride]+(3./2.)*k_u[idx-xstride]+(-49./18.)*k_u[idx]+(3./2.)*k_u[idx+xstride]+(-3./20.)*0.0+(1./90.)*0.0)/dx2; } else if (i == nx-3) { dux = ((-1./60.)*k_u[idx-3*xstride]+(3./20.)*k_u[idx-2*xstride]+(-3./4.)*k_u[idx-xstride]+0.0+(3./4.)*k_u[idx+xstride]+(-3./20.)*k_u[idx+2*xstride]+(1./60.)*0.0)/dx; dPsix = ((-1./60.)*k_psi[idx-3*xstride]+(3./20.)*k_psi[idx-2*xstride]+(-3./4.)*k_psi[idx-xstride]+0.0+(3./4.)*k_psi[idx+xstride]+(-3./20.)*k_psi[idx+2*xstride]+(1./60.)*0.0)/dx; dPhix = ((-1./60.)*k_Phix[idx-3*xstride]+(3./20.)*k_Phix[idx-2*xstride]+(-3./4.)*k_Phix[idx-xstride]+0.0+(3./4.)*k_Phix[idx+xstride]+(-3./20.)*k_Phix[idx+2*xstride]+(1./60.)*0.0)/dx; lapU += ((1./90.)*k_u[idx-3*xstride]+(-3./20.)*k_u[idx-2*xstride]+(3./2.)*k_u[idx-xstride]+(-49./18.)*k_u[idx]+(3./2.)*k_u[idx+xstride]+(-3./20.)*k_u[idx+2*xstride]+(1./90.)*0.0)/dx2; } else { dux = ((-1./60.)*k_u[idx-3*xstride]+(3./20.)*k_u[idx-2*xstride]+(-3./4.)*k_u[idx-xstride]+0.0+(3./4.)*k_u[idx+xstride]+(-3./20.)*k_u[idx+2*xstride]+(1./60.)*k_u[idx+3*xstride])/dx; dPsix = ((-1./60.)*k_psi[idx-3*xstride]+(3./20.)*k_psi[idx-2*xstride]+(-3./4.)*k_psi[idx-xstride]+0.0+(3./4.)*k_psi[idx+xstride]+(-3./20.)*k_psi[idx+2*xstride]+(1./60.)*k_psi[idx+3*xstride])/dx; dPhix = ((-1./60.)*k_Phix[idx-3*xstride]+(3./20.)*k_Phix[idx-2*xstride]+(-3./4.)*k_Phix[idx-xstride]+0.0+(3./4.)*k_Phix[idx+xstride]+(-3./20.)*k_Phix[idx+2*xstride]+(1./60.)*k_Phix[idx+3*xstride])/dx; lapU += ((1./90.)*k_u[idx-3*xstride]+(-3./20.)*k_u[idx-2*xstride]+(3./2.)*k_u[idx-xstride]+(-49./18.)*k_u[idx]+(3./2.)*k_u[idx+xstride]+(-3./20.)*k_u[idx+2*xstride]+(1./90.)*k_u[idx+3*xstride])/dx2; } // Do the Y direction if (j==0) { duy = ((-1./60.)*0.0+(3./20.)*0.0+(-3./4.)*0.0+0.0+(3./4.)*k_u[idx+ystride]+(-3./20.)*k_u[idx+2*ystride]+(1./60.)*k_u[idx+3*ystride])/dy; dPsiy = ((-1./60.)*0.0+(3./20.)*0.0+(-3./4.)*0.0+0.0+(3./4.)*k_psi[idx+ystride]+(-3./20.)*k_psi[idx+2*ystride]+(1./60.)*k_psi[idx+3*ystride])/dy; dPhiy = ((-1./60.)*0.0+(3./20.)*0.0+(-3./4.)*0.0+0.0+(3./4.)*k_Phiy[idx+ystride]+(-3./20.)*k_Phiy[idx+2*ystride]+(1./60.)*k_Phiy[idx+3*ystride])/dy; lapU += ((1./90.)*0.0+(-3./20.)*0.0+(3./2.)*0.0+(-49./18.)*k_u[idx]+(3./2.)*k_u[idx+ystride]+(-3./20.)*k_u[idx+2*ystride]+(1./90.)*k_u[idx+3*ystride])/dy2; } else if (j == 1) { duy = ((-1./60.)*0.0+(3./20.)*0.0+(-3./4.)*k_u[idx-ystride]+0.0+(3./4.)*k_u[idx+ystride]+(-3./20.)*k_u[idx+2*ystride]+(1./60.)*k_u[idx+3*ystride])/dy; dPsiy = ((-1./60.)*0.0+(3./20.)*0.0+(-3./4.)*k_psi[idx-ystride]+0.0+(3./4.)*k_psi[idx+ystride]+(-3./20.)*k_psi[idx+2*ystride]+(1./60.)*k_psi[idx+3*ystride])/dy; dPhiy = ((-1./60.)*0.0+(3./20.)*0.0+(-3./4.)*k_Phiy[idx-ystride]+0.0+(3./4.)*k_Phiy[idx+ystride]+(-3./20.)*k_Phiy[idx+2*ystride]+(1./60.)*k_Phiy[idx+3*ystride])/dy; lapU += ((1./90.)*0.0+(-3./20.)*0.0+(3./2.)*k_u[idx-ystride]+(-49./18.)*k_u[idx]+(3./2.)*k_u[idx+ystride]+(-3./20.)*k_u[idx+2*ystride]+(1./90.)*k_u[idx+3*ystride])/dy2; } else if (j == 2) { duy = ((-1./60.)*0.0+(3./20.)*k_u[idx-2*ystride]+(-3./4.)*k_u[idx-ystride]+0.0+(3./4.)*k_u[idx+ystride]+(-3./20.)*k_u[idx+2*ystride]+(1./60.)*k_u[idx+3*ystride])/dy; dPsiy = ((-1./60.)*0.0+(3./20.)*k_psi[idx-2*ystride]+(-3./4.)*k_psi[idx-ystride]+0.0+(3./4.)*k_psi[idx+ystride]+(-3./20.)*k_psi[idx+2*ystride]+(1./60.)*k_psi[idx+3*ystride])/dy; dPhiy = ((-1./60.)*0.0+(3./20.)*k_Phiy[idx-2*ystride]+(-3./4.)*k_Phiy[idx-ystride]+0.0+(3./4.)*k_Phiy[idx+ystride]+(-3./20.)*k_Phiy[idx+2*ystride]+(1./60.)*k_Phiy[idx+3*ystride])/dy; lapU += ((1./90.)*0.0+(-3./20.)*k_u[idx-2*ystride]+(3./2.)*k_u[idx-ystride]+(-49./18.)*k_u[idx]+(3./2.)*k_u[idx+ystride]+(-3./20.)*k_u[idx+2*ystride]+(1./90.)*k_u[idx+3*ystride])/dy2; } else if (j== nx-1) { duy = ((-1./60.)*k_u[idx-3*ystride]+(3./20.)*k_u[idx-2*ystride]+(-3./4.)*k_u[idx-ystride]+0.0+(3./4.)*0.0+(-3./20.)*0.0+(1./60.)*0.0)/dy; dPsiy = ((-1./60.)*k_psi[idx-3*ystride]+(3./20.)*k_psi[idx-2*ystride]+(-3./4.)*k_psi[idx-ystride]+0.0+(3./4.)*0.0+(-3./20.)*0.0+(1./60.)*0.0)/dy; dPhiy = ((-1./60.)*k_Phiy[idx-3*ystride]+(3./20.)*k_Phiy[idx-2*ystride]+(-3./4.)*k_Phiy[idx-ystride]+0.0+(3./4.)*0.0+(-3./20.)*0.0+(1./60.)*0.0)/dy; lapU += ((1./90.)*k_u[idx-3*ystride]+(-3./20.)*k_u[idx-2*ystride]+(3./2.)*k_u[idx-ystride]+(-49./18.)*k_u[idx]+(3./2.)*0.0+(-3./20.)*0.0+(1./90.)*0.0)/dy2; } else if (j == nx-2) { duy = ((-1./60.)*k_u[idx-3*ystride]+(3./20.)*k_u[idx-2*ystride]+(-3./4.)*k_u[idx-ystride]+0.0+(3./4.)*k_u[idx+ystride]+(-3./20.)*0.0+(1./60.)*0.0)/dy; dPsiy = ((-1./60.)*k_psi[idx-3*ystride]+(3./20.)*k_psi[idx-2*ystride]+(-3./4.)*k_psi[idx-ystride]+0.0+(3./4.)*k_psi[idx+ystride]+(-3./20.)*0.0+(1./60.)*0.0)/dy; dPhiy = ((-1./60.)*k_Phiy[idx-3*ystride]+(3./20.)*k_Phiy[idx-2*ystride]+(-3./4.)*k_Phiy[idx-ystride]+0.0+(3./4.)*k_Phiy[idx+ystride]+(-3./20.)*0.0+(1./60.)*0.0)/dy; lapU += ((1./90.)*k_u[idx-3*ystride]+(-3./20.)*k_u[idx-2*ystride]+(3./2.)*k_u[idx-ystride]+(-49./18.)*k_u[idx]+(3./2.)*k_u[idx+ystride]+(-3./20.)*0.0+(1./90.)*0.0)/dy2; } else if (j == nx-3) { duy = ((-1./60.)*k_u[idx-3*ystride]+(3./20.)*k_u[idx-2*ystride]+(-3./4.)*k_u[idx-ystride]+0.0+(3./4.)*k_u[idx+ystride]+(-3./20.)*k_u[idx+2*ystride]+(1./60.)*0.0)/dy; dPsiy = ((-1./60.)*k_psi[idx-3*ystride]+(3./20.)*k_psi[idx-2*ystride]+(-3./4.)*k_psi[idx-ystride]+0.0+(3./4.)*k_psi[idx+ystride]+(-3./20.)*k_psi[idx+2*ystride]+(1./60.)*0.0)/dy; dPhiy = ((-1./60.)*k_Phiy[idx-3*ystride]+(3./20.)*k_Phiy[idx-2*ystride]+(-3./4.)*k_Phiy[idx-ystride]+0.0+(3./4.)*k_Phiy[idx+ystride]+(-3./20.)*k_Phiy[idx+2*ystride]+(1./60.)*0.0)/dy; lapU += ((1./90.)*k_u[idx-3*ystride]+(-3./20.)*k_u[idx-2*ystride]+(3./2.)*k_u[idx-ystride]+(-49./18.)*k_u[idx]+(3./2.)*k_u[idx+ystride]+(-3./20.)*k_u[idx+2*ystride]+(1./90.)*0.0)/dy2; } else { duy = ((-1./60.)*k_u[idx-3*ystride]+(3./20.)*k_u[idx-2*ystride]+(-3./4.)*k_u[idx-ystride]+0.0+(3./4.)*k_u[idx+ystride]+(-3./20.)*k_u[idx+2*ystride]+(1./60.)*k_u[idx+3*ystride])/dy; dPsiy = ((-1./60.)*k_psi[idx-3*ystride]+(3./20.)*k_psi[idx-2*ystride]+(-3./4.)*k_psi[idx-ystride]+0.0+(3./4.)*k_psi[idx+ystride]+(-3./20.)*k_psi[idx+2*ystride]+(1./60.)*k_psi[idx+3*ystride])/dy; dPhiy = ((-1./60.)*k_Phiy[idx-3*ystride]+(3./20.)*k_Phiy[idx-2*ystride]+(-3./4.)*k_Phiy[idx-ystride]+0.0+(3./4.)*k_Phiy[idx+ystride]+(-3./20.)*k_Phiy[idx+2*ystride]+(1./60.)*k_Phiy[idx+3*ystride])/dy; lapU += ((1./90.)*k_u[idx-3*ystride]+(-3./20.)*k_u[idx-2*ystride]+(3./2.)*k_u[idx-ystride]+(-49./18.)*k_u[idx]+(3./2.)*k_u[idx+ystride]+(-3./20.)*k_u[idx+2*ystride]+(1./90.)*k_u[idx+3*ystride])/dy2; } // Do the Z direction // Left side if (k==0) { duz = ((-1./60.)*0.0+(3./20.)*0.0+(-3./4.)*0.0+0.0+(3./4.)*k_u[idx+s]+(-3./20.)*k_u[idx+2*s]+(1./60.)*k_u[idx+3*s])/dz; dPsiz = ((-1./60.)*0.0+(3./20.)*0.0+(-3./4.)*0.0+0.0+(3./4.)*k_psi[idx+s]+(-3./20.)*k_psi[idx+2*s]+(1./60.)*k_psi[idx+3*s])/dz; dPhiz = ((-1./60.)*0.0+(3./20.)*0.0+(-3./4.)*0.0+0.0+(3./4.)*k_Phiz[idx+s]+(-3./20.)*k_Phiz[idx+2*s]+(1./60.)*k_Phiz[idx+3*s])/dz; lapU += ((1./90.)*0.0+(-3./20.)*0.0+(3./2.)*0.0+(-49./18.)*k_u[idx]+(3./2.)*k_u[idx+s]+(-3./20.)*k_u[idx+2*s]+(1./90.)*k_u[idx+3*s])/dz2; } else if (k == 1) { duz = ((-1./60.)*0.0+(3./20.)*0.0+(-3./4.)*k_u[idx-s]+0.0+(3./4.)*k_u[idx+s]+(-3./20.)*k_u[idx+2*s]+(1./60.)*k_u[idx+3*s])/dz; dPsiz = ((-1./60.)*0.0+(3./20.)*0.0+(-3./4.)*k_psi[idx-s]+0.0+(3./4.)*k_psi[idx+s]+(-3./20.)*k_psi[idx+2*s]+(1./60.)*k_psi[idx+3*s])/dz; dPhiz = ((-1./60.)*0.0+(3./20.)*0.0+(-3./4.)*k_Phiz[idx-s]+0.0+(3./4.)*k_Phiz[idx+s]+(-3./20.)*k_Phiz[idx+2*s]+(1./60.)*k_Phiz[idx+3*s])/dz; lapU += ((1./90.)*0.0+(-3./20.)*0.0+(3./2.)*k_u[idx-s]+(-49./18.)*k_u[idx]+(3./2.)*k_u[idx+s]+(-3./20.)*k_u[idx+2*s]+(1./90.)*k_u[idx+3*s])/dz2; } else if (k == 2) { duz = ((-1./60.)*0.0+(3./20.)*k_u[idx-2*s]+(-3./4.)*k_u[idx-s]+0.0+(3./4.)*k_u[idx+s]+(-3./20.)*k_u[idx+2*s]+(1./60.)*k_u[idx+3*s])/dz; dPsiz = ((-1./60.)*0.0+(3./20.)*k_psi[idx-2*s]+(-3./4.)*k_psi[idx-s]+0.0+(3./4.)*k_psi[idx+s]+(-3./20.)*k_psi[idx+2*s]+(1./60.)*k_psi[idx+3*s])/dz; dPhiz = ((-1./60.)*0.0+(3./20.)*k_Phiz[idx-2*s]+(-3./4.)*k_Phiz[idx-s]+0.0+(3./4.)*k_Phiz[idx+s]+(-3./20.)*k_Phiz[idx+2*s]+(1./60.)*k_Phiz[idx+3*s])/dz; lapU += ((1./90.)*0.0+(-3./20.)*k_u[idx-2*s]+(3./2.)*k_u[idx-s]+(-49./18.)*k_u[idx]+(3./2.)*k_u[idx+s]+(-3./20.)*k_u[idx+2*s]+(1./90.)*k_u[idx+3*s])/dz2; } else if (k == nz-1) { duz = ((-1./60.)*k_u[idx-3*s]+(3./20.)*k_u[idx-2*s]+(-3./4.)*k_u[idx-s]+0.0+(3./4.)*0.0+(-3./20.)*0.0+(1./60.)*0.0)/dz; dPsiz = ((-1./60.)*k_psi[idx-3*s]+(3./20.)*k_psi[idx-2*s]+(-3./4.)*k_psi[idx-s]+0.0+(3./4.)*0.0+(-3./20.)*0.0+(1./60.)*0.0)/dz; dPhiz = ((-1./60.)*k_Phiz[idx-3*s]+(3./20.)*k_Phiz[idx-2*s]+(-3./4.)*k_Phiz[idx-s]+0.0+(3./4.)*0.0+(-3./20.)*0.0+(1./60.)*0.0)/dz; lapU += ((1./90.)*k_u[idx-3*s]+(-3./20.)*k_u[idx-2*s]+(3./2.)*k_u[idx-s]+(-49./18.)*k_u[idx]+(3./2.)*0.0+(-3./20.)*0.0+(1./90.)*0.0)/dz2; } else if (k == nz-2) { duz = ((-1./60.)*k_u[idx-3*s]+(3./20.)*k_u[idx-2*s]+(-3./4.)*k_u[idx-s]+0.0+(3./4.)*k_u[idx+s]+(-3./20.)*0.0+(1./60.)*0.0)/dz; dPsiz = ((-1./60.)*k_psi[idx-3*s]+(3./20.)*k_psi[idx-2*s]+(-3./4.)*k_psi[idx-s]+0.0+(3./4.)*k_psi[idx+s]+(-3./20.)*0.0+(1./60.)*0.0)/dz; dPhiz = ((-1./60.)*k_Phiz[idx-3*s]+(3./20.)*k_Phiz[idx-2*s]+(-3./4.)*k_Phiz[idx-s]+0.0+(3./4.)*k_Phiz[idx+s]+(-3./20.)*0.0+(1./60.)*0.0)/dz; lapU += ((1./90.)*k_u[idx-3*s]+(-3./20.)*k_u[idx-2*s]+(3./2.)*k_u[idx-s]+(-49./18.)*k_u[idx]+(3./2.)*k_u[idx+s]+(-3./20.)*0.0+(1./90.)*0.0)/dz2; } else if (k == nz-3) { duz = ((-1./60.)*k_u[idx-3*s]+(3./20.)*k_u[idx-2*s]+(-3./4.)*k_u[idx-s]+0.0+(3./4.)*k_u[idx+s]+(-3./20.)*k_u[idx+2*s]+(1./60.)*0.0)/dz; dPsiz = ((-1./60.)*k_psi[idx-3*s]+(3./20.)*k_psi[idx-2*s]+(-3./4.)*k_psi[idx-s]+0.0+(3./4.)*k_psi[idx+s]+(-3./20.)*k_psi[idx+2*s]+(1./60.)*0.0)/dz; dPhiz = ((-1./60.)*k_Phiz[idx-3*s]+(3./20.)*k_Phiz[idx-2*s]+(-3./4.)*k_Phiz[idx-s]+0.0+(3./4.)*k_Phiz[idx+s]+(-3./20.)*k_Phiz[idx+2*s]+(1./60.)*0.0)/dz; lapU += ((1./90.)*k_u[idx-3*s]+(-3./20.)*k_u[idx-2*s]+(3./2.)*k_u[idx-s]+(-49./18.)*k_u[idx]+(3./2.)*k_u[idx+s]+(-3./20.)*k_u[idx+2*s]+(1./90.)*0.0)/dz2; } else { duz = ((-1./60.)*k_u[idx-3*s]+(3./20.)*k_u[idx-2*s]+(-3./4.)*k_u[idx-s]+0.0+(3./4.)*k_u[idx+s]+(-3./20.)*k_u[idx+2*s]+(1./60.)*k_u[idx+3*s])/dz; dPsiz = ((-1./60.)*k_psi[idx-3*s]+(3./20.)*k_psi[idx-2*s]+(-3./4.)*k_psi[idx-s]+0.0+(3./4.)*k_psi[idx+s]+(-3./20.)*k_psi[idx+2*s]+(1./60.)*k_psi[idx+3*s])/dz; dPhiz = ((-1./60.)*k_Phiz[idx-3*s]+(3./20.)*k_Phiz[idx-2*s]+(-3./4.)*k_Phiz[idx-s]+0.0+(3./4.)*k_Phiz[idx+s]+(-3./20.)*k_Phiz[idx+2*s]+(1./60.)*k_Phiz[idx+3*s])/dz; lapU += ((1./90.)*k_u[idx-3*s]+(-3./20.)*k_u[idx-2*s]+(3./2.)*k_u[idx-s]+(-49./18.)*k_u[idx]+(3./2.)*k_u[idx+s]+(-3./20.)*k_u[idx+2*s]+(1./90.)*k_u[idx+3*s])/dz2; } sigmax = 0.0; sigmay = 0.0; sigmaz = 0.0; // Check if in left PML-X if((n_xlpml>0) && (i < n_xlpml)) { sigmax = xlpml[i]; } // Check if in right PML-X else if((n_xrpml>0) && (i >= nx-n_xrpml)) { sigmax = xrpml[n_xrpml-((nx-1)-i)]; } // Check if in left PML-Y if((n_ylpml>0) && (j < n_ylpml)) { sigmay = ylpml[j]; } // Check if in right PML-Y else if((n_yrpml>0) && (j >= ny-n_yrpml)) { sigmay = yrpml[n_yrpml-((ny-1)-j)]; } // Check if in left PML-Z if((n_zlpml>0) && (k < n_zlpml)) { sigmaz = zlpml[k]; } // Check if in right PML-Z else if((n_zrpml>0) && (k >= nz-n_zrpml)) { sigmaz = zrpml[n_zrpml-((nz-1)-k)]; // 0th element of the right pml array corresponds to n_zrpml'th node from the right boundary. } if((sigmaz != 0.0) || (sigmay != 0.0) || (sigmax != 0.0)) { kp1_Phix[idx] = k_Phix[idx] - dt*sigmax*k_Phix[idx] + dt*(sigmay+sigmaz-sigmax)*dux + dt*(sigmay*sigmaz*dPsix); kp1_Phiy[idx] = k_Phiy[idx] - dt*sigmay*k_Phiy[idx] + dt*(sigmaz+sigmax-sigmay)*duy + dt*(sigmaz*sigmax*dPsiy); kp1_Phiz[idx] = k_Phiz[idx] - dt*sigmaz*k_Phiz[idx] + dt*(sigmax+sigmay-sigmaz)*duz + dt*(sigmax*sigmay*dPsiz); kp1_psi[idx] = k_psi[idx] + dt * k_u[idx]; fac1 = (2.0*dt2 / (2.0 + dt*(sigmax+sigmay+sigmaz))); fac2 = (C[idx]*C[idx]) * (rhs[idx] + lapU + dPhix + dPhiy + dPhiz - (sigmax*sigmay*sigmaz)*k_psi[idx]) - (km1_u[idx]-2.0*k_u[idx])/dt2 + (sigmax+sigmay+sigmaz)*km1_u[idx]/(2.0*dt) - (sigmax*sigmay + sigmay*sigmaz + sigmaz*sigmax)*k_u[idx]; kp1_u[idx] = fac1 * fac2; } else { kp1_Phix[idx] = k_Phix[idx]; kp1_Phiy[idx] = k_Phiy[idx]; kp1_Phiz[idx] = k_Phiz[idx]; kp1_psi[idx] = k_psi[idx] + dt * k_u[idx]; kp1_u[idx] = dt2*(C[idx]*C[idx])*(rhs[idx]+lapU+dPhix+dPhiy+dPhiz) - (km1_u[idx]-2.0*k_u[idx]); } } } } }; #endif
GB_binop__times_int8.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__times_int8 // A.*B function (eWiseMult): GB_AemultB__times_int8 // A*D function (colscale): GB_AxD__times_int8 // D*A function (rowscale): GB_DxB__times_int8 // C+=B function (dense accum): GB_Cdense_accumB__times_int8 // C+=b function (dense accum): GB_Cdense_accumb__times_int8 // C+=A+B function (dense ewise3): GB_Cdense_ewise3_accum__times_int8 // C=A+B function (dense ewise3): GB_Cdense_ewise3_noaccum__times_int8 // C=scalar+B GB_bind1st__times_int8 // C=scalar+B' GB_bind1st_tran__times_int8 // C=A+scalar GB_bind2nd__times_int8 // C=A'+scalar GB_bind2nd_tran__times_int8 // C type: int8_t // A type: int8_t // B,b type: int8_t // BinaryOp: cij = (aij * bij) #define GB_ATYPE \ int8_t #define GB_BTYPE \ int8_t #define GB_CTYPE \ int8_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) \ int8_t aij = Ax [pA] // bij = Bx [pB] #define GB_GETB(bij,Bx,pB) \ int8_t bij = Bx [pB] // declare scalar of the same type as C #define GB_CTYPE_SCALAR(t) \ int8_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_TIMES || GxB_NO_INT8 || GxB_NO_TIMES_INT8) //------------------------------------------------------------------------------ // C += A+B, all 3 matrices dense //------------------------------------------------------------------------------ // The op must be MIN, MAX, PLUS, MINUS, RMINUS, TIMES, DIV, or RDIV. void GB_Cdense_ewise3_accum__times_int8 ( GrB_Matrix C, const GrB_Matrix A, const GrB_Matrix B, const int nthreads ) { #include "GB_dense_ewise3_accum_template.c" } //------------------------------------------------------------------------------ // C = A+B, all 3 matrices dense //------------------------------------------------------------------------------ GrB_Info GB_Cdense_ewise3_noaccum__times_int8 ( 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__times_int8 ( 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__times_int8 ( 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 int8_t int8_t bwork = (*((int8_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__times_int8 ( 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 int8_t *GB_RESTRICT Cx = (int8_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__times_int8 ( 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 int8_t *GB_RESTRICT Cx = (int8_t *) C->x ; #include "GB_AxB_rowscale_meta.c" return (GrB_SUCCESS) ; #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__times_int8 ( 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__times_int8 ( 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__times_int8 ( 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 int8_t *Cx = (int8_t *) Cx_output ; int8_t x = (*((int8_t *) x_input)) ; int8_t *Bx = (int8_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 ; int8_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__times_int8 ( 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 ; int8_t *Cx = (int8_t *) Cx_output ; int8_t *Ax = (int8_t *) Ax_input ; int8_t y = (*((int8_t *) y_input)) ; #pragma omp parallel for num_threads(nthreads) schedule(static) for (p = 0 ; p < anz ; p++) { if (!GBB (Ab, p)) continue ; int8_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) \ { \ int8_t aij = Ax [pA] ; \ Cx [pC] = (x * aij) ; \ } GrB_Info GB_bind1st_tran__times_int8 ( 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 \ int8_t #if GB_DISABLE return (GrB_NO_VALUE) ; #else int8_t x = (*((const int8_t *) x_input)) ; #include "GB_unop_transpose.c" return (GrB_SUCCESS) ; #endif #undef GB_ATYPE #define GB_ATYPE \ int8_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) \ { \ int8_t aij = Ax [pA] ; \ Cx [pC] = (aij * y) ; \ } GrB_Info GB_bind2nd_tran__times_int8 ( 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 int8_t y = (*((const int8_t *) y_input)) ; #include "GB_unop_transpose.c" return (GrB_SUCCESS) ; #endif } #endif
apriori.c
/*Copyright(C) 2016 João Saffran <joaosaffran@gmail.com> * * apriori.c - Apriori Methods Implementation */ #include <assert.h> #include "apriori.h" /* * Checks if has combination in an item of the database */ static inline int has_item_in_line(const struct Item *it, char *line) { int resp = 1; char *token = malloc(LINE_MAX*sizeof(char)); int aux[it->num_itens]; size_t j = 0; memset(aux, 0, it->num_itens*sizeof(int)); memset(token, 0, LINE_MAX*sizeof(char)); for (int i = 0; i < it->num_itens; i++) { for (int k = 0; ((it->item[j] != (',')) && (j < strlen(it->item))); k++, j++) { token[k] = it->item[j]; } ++j; if (strstr(line, token) != NULL) { aux[i] = 1; } } free(token); for (int i = 0; i < it->num_itens; i++) { resp = (resp && aux[i]); } return (resp); } /* * Counts the frequency of the combinations specified. */ void count_combinations_frequency(int ini_pos, int end_pos) { #pragma omp parallel for for (int i = 0; i< DATABASE_SIZE; i++) { for (int j = ini_pos; j < end_pos; j++) { if (has_item_in_line(&data[j], database[i])) { ++data[j].frequency; } } } } /* * Determines if items are frequent. */ void determinate_frequents(struct Item *dataset, int begin, int end, int threshold) { for (int i = begin; i< end; i++) { dataset[i].isFrequent = (dataset[i].frequency >= threshold); } } /* * Combines two databases itens. */ void combine(struct Item *dataset1, int size1, struct Item *dataset2, int size2, int num_threads) { struct Item tmp_data[10000*num_threads][num_threads]; int aux_lpi[num_threads]; memset(aux_lpi, 0, num_threads * sizeof(int)); #pragma omp parallel { int tid = omp_get_thread_num(); int lpi = 0; char *str; str = malloc( LINE_MAX*sizeof(char) ); assert(str != NULL); #pragma omp for for (int i = 0; i < size1; i++) { if (!dataset1[i].isFrequent) { continue; } for (int j = 0; j < size2; j++) { if (!dataset2[j].isFrequent) { continue; } if (strcmp(dataset1[i].item,dataset2[j].item) < 0) { strcat(str, dataset1[i].item); strcat(str, ","); strcat(str, dataset2[j].item); } else { strcat(str, dataset2[j].item); strcat(str, ","); strcat(str, dataset1[i].item); } tmp_data[lpi][tid].num_itens = dataset1[i].num_itens + 1; tmp_data[lpi++][tid].item = str; str = NULL; free(str); str = malloc( LINE_MAX * sizeof(char) ); } } free(str); aux_lpi[tid] = lpi; } for(int i = 0; i< num_threads; i++) { for(int j = 0; j< aux_lpi[i];j++) { data[pos_to_insert++] = tmp_data[j][i]; } } }
GB_critical_section.c
//------------------------------------------------------------------------------ // Source/Template/GB_critical_section: execute code in a critical section //------------------------------------------------------------------------------ // SuiteSparse:GraphBLAS, Timothy A. Davis, (c) 2017-2019, All Rights Reserved. // http://suitesparse.com See GraphBLAS/Doc/License.txt for license. //------------------------------------------------------------------------------ // All access to the global matrix queue, via GB_queue_* operations, must // be done through a critical section. No other part of SuiteSparse:GraphBLAS // uses this critical section; it is only used for accessing the global matrix // queue via GB_queue_*. All GB_queue_* operations use the GB_CRITICAL macro // to check the result, and if the critical section fails (ok == false), // they return GrB_PANIC. // Critical sections for Windows threads and ANSI C11 threads are listed below // as drafts, but these threading models are not yet supported. // not parallel: this function does O(1) work and is already thread-safe. { //-------------------------------------------------------------------------- // POSIX pthreads //-------------------------------------------------------------------------- #if defined (USER_POSIX_THREADS) { if (GB_Global.user_multithreaded) { ok = (pthread_mutex_lock (&GB_sync) == 0) ; } GB_CRITICAL_SECTION ; if (GB_Global.user_multithreaded) { ok = ok && (pthread_mutex_unlock (&GB_sync) == 0) ; } } //-------------------------------------------------------------------------- // Microsoft Windows //-------------------------------------------------------------------------- #elif defined (USER_WINDOWS_THREADS) { // This is not yet supported. if (GB_Global.user_multithreaded) { EnterCriticalSection (&GB_sync) ; } GB_CRITICAL_SECTION ; if (GB_Global.user_multithreaded) { LeaveCriticalSection (&GB_sync) ; } } //-------------------------------------------------------------------------- // ANSI C11 threads //-------------------------------------------------------------------------- #elif defined (USER_ANSI_THREADS) { // This should work per the ANSI C11 Spec, but is not yet supported. if (GB_Global.user_multithreaded) { ok = (mtx_lock (&GB_sync) == thrd_success) ; } GB_CRITICAL_SECTION ; if (GB_Global.user_multithreaded) { ok = ok && (mtx_unlock (&GB_sync) == thrd_success) ; } } //-------------------------------------------------------------------------- // OpenMP //-------------------------------------------------------------------------- #else // USER_OPENMP_THREADS or USER_NO_THREADS { // default: use a named OpenMP critical section. If OpenMP is not // available, then the #pragma is ignored and this becomes vanilla, // single-threaded code. #pragma omp critical (GB_critical_section) GB_CRITICAL_SECTION ; } #endif } #undef GB_CRITICAL_SECTION
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
convolution_3x3_pack4.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 conv3x3s1_winograd64_transform_kernel_pack4_neon(const Mat& kernel, Mat& kernel_tm_pack4, int inch, int outch) { // winograd63 transform kernel Mat kernel_tm; kernel_tm.create(8*8, inch, outch); const float ktm[8][3] = { { 1.0f, 0.0f, 0.0f}, {-2.0f/9, -2.0f/9, -2.0f/9}, {-2.0f/9, 2.0f/9, -2.0f/9}, {1.0f/90, 1.0f/45, 2.0f/45}, {1.0f/90, -1.0f/45, 2.0f/45}, {1.0f/45, 1.0f/90, 1.0f/180}, {1.0f/45, -1.0f/90, 1.0f/180}, { 0.0f, 0.0f, 1.0f} }; #pragma omp parallel for for (int p = 0; p<outch; p++) { for (int q = 0; q<inch; q++) { const float* kernel0 = (const float*)kernel + p*inch * 9 + q * 9; float* kernel_tm0 = kernel_tm.channel(p).row(q); // transform kernel, transposed const float* k0 = kernel0; const float* k1 = kernel0 + 3; const float* k2 = kernel0 + 6; // h float tmp[8][3]; for (int i=0; i<8; i++) { tmp[i][0] = k0[0] * ktm[i][0] + k0[1] * ktm[i][1] + k0[2] * ktm[i][2]; tmp[i][1] = k1[0] * ktm[i][0] + k1[1] * ktm[i][1] + k1[2] * ktm[i][2]; tmp[i][2] = k2[0] * ktm[i][0] + k2[1] * ktm[i][1] + k2[2] * ktm[i][2]; } // v for (int j=0; j<8; j++) { float* tmpp = &tmp[j][0]; for (int i=0; i<8; i++) { kernel_tm0[j*8 + i] = tmpp[0] * ktm[i][0] + tmpp[1] * ktm[i][1] + tmpp[2] * ktm[i][2]; } } } } // interleave // src = 64-inch-outch // dst = 4b-4a-inch/4a-64-outch/4b; #if __aarch64__ kernel_tm_pack4.create(2 * inch/4, 64, (outch/4)/2 + (outch/4)%2, (size_t)4u*16, 16); #else kernel_tm_pack4.create(inch/4, 64, outch/4, (size_t)4u*16, 16); #endif int q=0; #if __aarch64__ for (; q+7<outch; q+=8) { const Mat k0 = kernel_tm.channel(q); const Mat k1 = kernel_tm.channel(q+1); const Mat k2 = kernel_tm.channel(q+2); const Mat k3 = kernel_tm.channel(q+3); const Mat k4 = kernel_tm.channel(q+4); const Mat k5 = kernel_tm.channel(q+5); const Mat k6 = kernel_tm.channel(q+6); const Mat k7 = kernel_tm.channel(q+7); Mat g0 = kernel_tm_pack4.channel(q/8); for (int k=0; k<64; k++) { float* g00 = g0.row(k); for (int p=0; p+3<inch; p+=4) { 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* 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* 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* 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* 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* 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* 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* 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); g00[0] = k00[k]; g00[1] = k10[k]; g00[2] = k20[k]; g00[3] = k30[k]; g00[4] = k40[k]; g00[5] = k50[k]; g00[6] = k60[k]; g00[7] = k70[k]; g00[8] = k01[k]; g00[9] = k11[k]; g00[10] = k21[k]; g00[11] = k31[k]; g00[12] = k41[k]; g00[13] = k51[k]; g00[14] = k61[k]; g00[15] = k71[k]; g00[16] = k02[k]; g00[17] = k12[k]; g00[18] = k22[k]; g00[19] = k32[k]; g00[20] = k42[k]; g00[21] = k52[k]; g00[22] = k62[k]; g00[23] = k72[k]; g00[24] = k03[k]; g00[25] = k13[k]; g00[26] = k23[k]; g00[27] = k33[k]; g00[28] = k43[k]; g00[29] = k53[k]; g00[30] = k63[k]; g00[31] = k73[k]; g00 += 32; } } } #endif // __aarch64__ for (; q+3<outch; q+=4) { const Mat k0 = kernel_tm.channel(q); const Mat k1 = kernel_tm.channel(q+1); const Mat k2 = kernel_tm.channel(q+2); const Mat k3 = kernel_tm.channel(q+3); #if __aarch64__ Mat g0 = kernel_tm_pack4.channel(q/8+(q%8)/4); #else Mat g0 = kernel_tm_pack4.channel(q/4); #endif for (int k=0; k<64; k++) { float* g00 = g0.row(k); for (int p=0; p+3<inch; p+=4) { 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* 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* 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* 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); g00[0] = k00[k]; g00[1] = k10[k]; g00[2] = k20[k]; g00[3] = k30[k]; g00[4] = k01[k]; g00[5] = k11[k]; g00[6] = k21[k]; g00[7] = k31[k]; g00[8] = k02[k]; g00[9] = k12[k]; g00[10] = k22[k]; g00[11] = k32[k]; g00[12] = k03[k]; g00[13] = k13[k]; g00[14] = k23[k]; g00[15] = k33[k]; g00 += 16; } } } } static void conv3x3s1_winograd64_pack4_neon(const Mat& bottom_blob, Mat& top_blob, const Mat& kernel_tm, const Mat& _bias, const Option& opt) { int w = bottom_blob.w; int h = bottom_blob.h; int inch = bottom_blob.c; size_t elemsize = bottom_blob.elemsize; int elempack = bottom_blob.elempack; int outw = top_blob.w; int outh = top_blob.h; int outch = top_blob.c; // pad to 6n+2 Mat bottom_blob_bordered = bottom_blob; outw = (outw + 5) / 6 * 6; outh = (outh + 5) / 6 * 6; w = outw + 2; h = outh + 2; copy_make_border(bottom_blob, bottom_blob_bordered, 0, h - bottom_blob.h, 0, w - bottom_blob.w, BORDER_CONSTANT, 0.f, opt); const float* bias = _bias; // BEGIN transform input Mat bottom_blob_tm; { int w_tm = outw / 6 * 8; int h_tm = outh / 6 * 8; const int tiles = w_tm/8 * h_tm/8; bottom_blob_tm.create(tiles, 64, inch, elemsize, elempack, opt.workspace_allocator); // const float itm[8][8] = { // {1.0f, 0.0f, -5.25f, 0.00f, 5.25f, 0.00f, -1.0f, 0.0f}, // // {0.0f, 1.0f, 1.00f, -4.25f, -4.25f, 1.00f, 1.0f, 0.0f}, // {0.0f, -1.0f, 1.00f, 4.25f, -4.25f, -1.00f, 1.0f, 0.0f}, // // {0.0f, 0.5f, 0.25f, -2.50f, -1.25f, 2.00f, 1.0f, 0.0f}, // {0.0f, -0.5f, 0.25f, 2.50f, -1.25f, -2.00f, 1.0f, 0.0f}, // // {0.0f, 2.0f, 4.00f, -2.50f, -5.00f, 0.50f, 1.0f, 0.0f}, // {0.0f, -2.0f, 4.00f, 2.50f, -5.00f, -0.50f, 1.0f, 0.0f}, // // {0.0f, -1.0f, 0.00f, 5.25f, 0.00f, -5.25f, 0.0f, 1.0f} // }; // 0 = r00 - r06 + (r04 - r02) * 5.25 // 7 = r07 - r01 + (r03 - r05) * 5.25 // 1 = (r02 + r06 - r04 * 4.25) + (r01 - r03 * 4.25 + r05) // 2 = (r02 + r06 - r04 * 4.25) - (r01 - r03 * 4.25 + r05) // 3 = (r06 + r02 * 0.25 - r04 * 1.25) + (r01 * 0.5 - r03 * 2.5 + r05 * 2) // 4 = (r06 + r02 * 0.25 - r04 * 1.25) - (r01 * 0.5 - r03 * 2.5 + r05 * 2) // reuse r04 * 1.25 // reuse r03 * 2.5 // 5 = (r06 + (r02 - r04 * 1.25) * 4) + (r01 * 2 - r03 * 2.5 + r05 * 0.5) // 6 = (r06 + (r02 - r04 * 1.25) * 4) - (r01 * 2 - r03 * 2.5 + r05 * 0.5) #pragma omp parallel for num_threads(opt.num_threads) for (int q = 0; q<inch; q++) { const Mat img0 = bottom_blob_bordered.channel(q); Mat img0_tm = bottom_blob_tm.channel(q); float tmp[8][8][4]; // tile for (int i=0; i<h_tm/8; i++) { for (int j=0; j<w_tm/8; j++) { const float* r0 = img0.row(i * 6) + (j * 6) * 4; for (int m=0; m<8; m++) { float32x4_t _r00 = vld1q_f32(r0); float32x4_t _r01 = vld1q_f32(r0 + 4); float32x4_t _r02 = vld1q_f32(r0 + 8); float32x4_t _r03 = vld1q_f32(r0 + 12); float32x4_t _r04 = vld1q_f32(r0 + 16); float32x4_t _r05 = vld1q_f32(r0 + 20); float32x4_t _r06 = vld1q_f32(r0 + 24); float32x4_t _r07 = vld1q_f32(r0 + 28); float32x4_t _tmp0m = vmlaq_n_f32(vsubq_f32(_r00, _r06), vsubq_f32(_r04, _r02), 5.25f); float32x4_t _tmp7m = vmlaq_n_f32(vsubq_f32(_r07, _r01), vsubq_f32(_r03, _r05), 5.25f); vst1q_f32(tmp[0][m], _tmp0m); vst1q_f32(tmp[7][m], _tmp7m); // tmp[0][m] = r0[0] - r0[6] + (r0[4] - r0[2]) * 5.25; // tmp[7][m] = r0[7] - r0[1] + (r0[3] - r0[5]) * 5.25; float32x4_t _tmp12a = vmlsq_n_f32(vaddq_f32(_r02, _r06), _r04, 4.25f); float32x4_t _tmp12b = vmlsq_n_f32(vaddq_f32(_r01, _r05), _r03, 4.25f); // float tmp12a = (r0[2] + r0[6] - r0[4] * 4.25); // float tmp12b = (r0[1] + r0[5] - r0[3] * 4.25); float32x4_t _tmp1m = vaddq_f32(_tmp12a, _tmp12b); float32x4_t _tmp2m = vsubq_f32(_tmp12a, _tmp12b); vst1q_f32(tmp[1][m], _tmp1m); vst1q_f32(tmp[2][m], _tmp2m); // tmp[1][m] = tmp12a + tmp12b; // tmp[2][m] = tmp12a - tmp12b; float32x4_t _tmp34a = vmlsq_n_f32(vmlaq_n_f32(_r06, _r02, 0.25f), _r04, 1.25f); float32x4_t _tmp34b = vmlaq_n_f32(vmlsq_n_f32(vmulq_n_f32(_r01, 0.5f), _r03, 2.5f), _r05, 2.f); // float tmp34a = (r0[6] + r0[2] * 0.25 - r0[4] * 1.25); // float tmp34b = (r0[1] * 0.5 - r0[3] * 2.5 + r0[5] * 2); float32x4_t _tmp3m = vaddq_f32(_tmp34a, _tmp34b); float32x4_t _tmp4m = vsubq_f32(_tmp34a, _tmp34b); vst1q_f32(tmp[3][m], _tmp3m); vst1q_f32(tmp[4][m], _tmp4m); // tmp[3][m] = tmp34a + tmp34b; // tmp[4][m] = tmp34a - tmp34b; float32x4_t _tmp56a = vmlaq_n_f32(_r06, vmlsq_n_f32(_r02, _r04, 1.25f), 4.f); float32x4_t _tmp56b = vmlaq_n_f32(vmlsq_n_f32(vmulq_n_f32(_r01, 2.f), _r03, 2.5f), _r05, 0.5f); // float tmp56a = (r0[6] + (r0[2] - r0[4] * 1.25) * 4); // float tmp56b = (r0[1] * 2 - r0[3] * 2.5 + r0[5] * 0.5); float32x4_t _tmp5m = vaddq_f32(_tmp56a, _tmp56b); float32x4_t _tmp6m = vsubq_f32(_tmp56a, _tmp56b); vst1q_f32(tmp[5][m], _tmp5m); vst1q_f32(tmp[6][m], _tmp6m); // tmp[5][m] = tmp56a + tmp56b; // tmp[6][m] = tmp56a - tmp56b; r0 += w * 4; } float* r0_tm_0 = (float*)img0_tm + (i * w_tm/8 + j) * 4; float* r0_tm_1 = r0_tm_0 + tiles * 4; float* r0_tm_2 = r0_tm_0 + tiles * 8; float* r0_tm_3 = r0_tm_0 + tiles * 12; float* r0_tm_4 = r0_tm_0 + tiles * 16; float* r0_tm_5 = r0_tm_0 + tiles * 20; float* r0_tm_6 = r0_tm_0 + tiles * 24; float* r0_tm_7 = r0_tm_0 + tiles * 28; for (int m=0; m<8; m++) { float32x4_t _tmp00 = vld1q_f32(tmp[m][0]); float32x4_t _tmp01 = vld1q_f32(tmp[m][1]); float32x4_t _tmp02 = vld1q_f32(tmp[m][2]); float32x4_t _tmp03 = vld1q_f32(tmp[m][3]); float32x4_t _tmp04 = vld1q_f32(tmp[m][4]); float32x4_t _tmp05 = vld1q_f32(tmp[m][5]); float32x4_t _tmp06 = vld1q_f32(tmp[m][6]); float32x4_t _tmp07 = vld1q_f32(tmp[m][7]); float32x4_t _r0tm0 = vmlaq_n_f32(vsubq_f32(_tmp00, _tmp06), vsubq_f32(_tmp04, _tmp02), 5.25f); float32x4_t _r0tm7 = vmlaq_n_f32(vsubq_f32(_tmp07, _tmp01), vsubq_f32(_tmp03, _tmp05), 5.25f); // r0_tm[0] = tmp0[0] - tmp0[6] + (tmp0[4] - tmp0[2]) * 5.25; // r0_tm[7] = tmp0[7] - tmp0[1] + (tmp0[3] - tmp0[5]) * 5.25; float32x4_t _tmp12a = vmlsq_n_f32(vaddq_f32(_tmp02, _tmp06), _tmp04, 4.25f); float32x4_t _tmp12b = vmlsq_n_f32(vaddq_f32(_tmp01, _tmp05), _tmp03, 4.25f); // float tmp12a = (tmp0[2] + tmp0[6] - tmp0[4] * 4.25); // float tmp12b = (tmp0[1] + tmp0[5] - tmp0[3] * 4.25); float32x4_t _r0tm1 = vaddq_f32(_tmp12a, _tmp12b); float32x4_t _r0tm2 = vsubq_f32(_tmp12a, _tmp12b); // r0_tm[1] = tmp12a + tmp12b; // r0_tm[2] = tmp12a - tmp12b; float32x4_t _tmp34a = vmlsq_n_f32(vmlaq_n_f32(_tmp06, _tmp02, 0.25f), _tmp04, 1.25f); float32x4_t _tmp34b = vmlaq_n_f32(vmlsq_n_f32(vmulq_n_f32(_tmp01, 0.5f), _tmp03, 2.5f), _tmp05, 2.f); // float tmp34a = (tmp0[6] + tmp0[2] * 0.25 - tmp0[4] * 1.25); // float tmp34b = (tmp0[1] * 0.5 - tmp0[3] * 2.5 + tmp0[5] * 2); float32x4_t _r0tm3 = vaddq_f32(_tmp34a, _tmp34b); float32x4_t _r0tm4 = vsubq_f32(_tmp34a, _tmp34b); // r0_tm[3] = tmp34a + tmp34b; // r0_tm[4] = tmp34a - tmp34b; float32x4_t _tmp56a = vmlaq_n_f32(_tmp06, vmlsq_n_f32(_tmp02, _tmp04, 1.25f), 4.f); float32x4_t _tmp56b = vmlaq_n_f32(vmlsq_n_f32(vmulq_n_f32(_tmp01, 2.f), _tmp03, 2.5f), _tmp05, 0.5f); // float tmp56a = (tmp0[6] + (tmp0[2] - tmp0[4] * 1.25) * 4); // float tmp56b = (tmp0[1] * 2 - tmp0[3] * 2.5 + tmp0[5] * 0.5); float32x4_t _r0tm5 = vaddq_f32(_tmp56a, _tmp56b); float32x4_t _r0tm6 = vsubq_f32(_tmp56a, _tmp56b); // r0_tm[5] = tmp56a + tmp56b; // r0_tm[6] = tmp56a - tmp56b; vst1q_f32(r0_tm_0, _r0tm0); vst1q_f32(r0_tm_1, _r0tm1); vst1q_f32(r0_tm_2, _r0tm2); vst1q_f32(r0_tm_3, _r0tm3); vst1q_f32(r0_tm_4, _r0tm4); vst1q_f32(r0_tm_5, _r0tm5); vst1q_f32(r0_tm_6, _r0tm6); vst1q_f32(r0_tm_7, _r0tm7); r0_tm_0 += tiles * 32; r0_tm_1 += tiles * 32; r0_tm_2 += tiles * 32; r0_tm_3 += tiles * 32; r0_tm_4 += tiles * 32; r0_tm_5 += tiles * 32; r0_tm_6 += tiles * 32; r0_tm_7 += tiles * 32; } } } } } bottom_blob_bordered = Mat(); // END transform input // BEGIN dot Mat top_blob_tm; { int w_tm = outw / 6 * 8; int h_tm = outh / 6 * 8; const int tiles = h_tm/8 * w_tm/8; // permute // bottom_blob_tm.create(tiles, 64, inch, elemsize, elempack, opt.workspace_allocator); Mat bottom_blob_tm2; #if __aarch64__ if (tiles >= 12) bottom_blob_tm2.create(12 * inch, tiles/12 + (tiles%12)/8 + (tiles%12%8)/4 + (tiles%12%4)/2 + tiles%12%2, 64, elemsize, elempack, opt.workspace_allocator); else if (tiles >= 8) bottom_blob_tm2.create(8 * inch, tiles/8 + (tiles%8)/4 + (tiles%4)/2 + tiles%2, 64, elemsize, elempack, opt.workspace_allocator); else if (tiles >= 4) bottom_blob_tm2.create(4 * inch, tiles/4 + (tiles%4)/2 + tiles%2, 64, elemsize, elempack, opt.workspace_allocator); else if (tiles >= 2) bottom_blob_tm2.create(2 * inch, tiles/2 + tiles%2, 64, elemsize, elempack, opt.workspace_allocator); else // if (tiles >= 1) bottom_blob_tm2.create(1 * inch, tiles, 64, elemsize, elempack, opt.workspace_allocator); #else if (tiles >= 8) bottom_blob_tm2.create(8 * inch, tiles/8 + (tiles%8)/4 + (tiles%4)/2 + tiles%2, 64, elemsize, elempack, opt.workspace_allocator); else if (tiles >= 4) bottom_blob_tm2.create(4 * inch, tiles/4 + (tiles%4)/2 + tiles%2, 64, elemsize, elempack, opt.workspace_allocator); else if (tiles >= 2) bottom_blob_tm2.create(2 * inch, tiles/2 + tiles%2, 64, elemsize, elempack, opt.workspace_allocator); else // if (tiles >= 1) bottom_blob_tm2.create(1 * inch, tiles, 64, elemsize, elempack, opt.workspace_allocator); #endif #pragma omp parallel for num_threads(opt.num_threads) for (int r=0; r<64; r++) { Mat tm2 = bottom_blob_tm2.channel(r); // tile int i=0; #if __aarch64__ for (; i+11<tiles; i+=12) { float* tm2p = tm2.row(i/12); const float* r0 = bottom_blob_tm; r0 += (r*tiles + i) * 4; for (int q=0; q<inch; q++) { asm volatile( "prfm pldl1keep, [%0, #512] \n" "ld4 {v0.4s, v1.4s, v2.4s, v3.4s}, [%0], #64 \n" "prfm pldl1keep, [%0, #512] \n" "ld4 {v4.4s, v5.4s, v6.4s, v7.4s}, [%0], #64 \n" "prfm pldl1keep, [%0, #512] \n" "ld4 {v8.4s, v9.4s, v10.4s, v11.4s}, [%0] \n" "st1 {v0.4s}, [%1], #16 \n" "st1 {v4.4s}, [%1], #16 \n" "st1 {v8.4s}, [%1], #16 \n" "sub %0, %0, #128 \n" "st1 {v1.4s}, [%1], #16 \n" "st1 {v5.4s}, [%1], #16 \n" "st1 {v9.4s}, [%1], #16 \n" "st1 {v2.4s}, [%1], #16 \n" "st1 {v6.4s}, [%1], #16 \n" "st1 {v10.4s}, [%1], #16 \n" "st1 {v3.4s}, [%1], #16 \n" "st1 {v7.4s}, [%1], #16 \n" "st1 {v11.4s}, [%1], #16 \n" : "=r"(r0), // %0 "=r"(tm2p) // %1 : "0"(r0), "1"(tm2p) : "memory", "v0", "v1", "v2", "v3", "v4", "v5", "v6", "v7", "v8", "v9", "v10", "v11" ); r0 += bottom_blob_tm.cstep * 4; } } #endif for (; i+7<tiles; i+=8) { #if __aarch64__ float* tm2p = tm2.row(i/12 + (i%12)/8); #else float* tm2p = tm2.row(i/8); #endif const float* r0 = bottom_blob_tm; r0 += (r*tiles + i) * 4; for (int q=0; q<inch; q++) { #if __aarch64__ asm volatile( "prfm pldl1keep, [%0, #512] \n" "ld1 {v0.4s, v1.4s, v2.4s, v3.4s}, [%0], #64 \n" "prfm pldl1keep, [%0, #512] \n" "ld1 {v4.4s, v5.4s, v6.4s, v7.4s}, [%0] \n" "st1 {v0.4s, v1.4s, v2.4s, v3.4s}, [%1], #64 \n" "sub %0, %0, #64 \n" "st1 {v4.4s, v5.4s, v6.4s, v7.4s}, [%1], #64 \n" : "=r"(r0), // %0 "=r"(tm2p) // %1 : "0"(r0), "1"(tm2p) : "memory", "v0", "v1", "v2", "v3", "v4", "v5", "v6", "v7" ); #else asm volatile( "pld [%0, #512] \n" "vldm %0!, {d0-d7} \n" "pld [%0, #512] \n" "vldm %0, {d16-d23} \n" // transpose 8x4 "vtrn.32 q0, q1 \n" "vtrn.32 q2, q3 \n" "vtrn.32 q8, q9 \n" "vtrn.32 q10, q11 \n" "vswp d1, d4 \n" "vswp d3, d6 \n" "vswp d17, d20 \n" "vswp d19, d22 \n" "vswp q1, q8 \n" "vswp q3, q10 \n" "vst1.f32 {d0-d3}, [%1 :128]! \n" "vst1.f32 {d16-d19}, [%1 :128]! \n" "sub %0, %0, #64 \n" "vst1.f32 {d4-d7}, [%1 :128]! \n" "vst1.f32 {d20-d23}, [%1 :128]! \n" : "=r"(r0), // %0 "=r"(tm2p) // %1 : "0"(r0), "1"(tm2p) : "memory", "q0", "q1", "q2", "q3", "q8", "q9", "q10", "q11" ); #endif r0 += bottom_blob_tm.cstep * 4; } } for (; i+3<tiles; i+=4) { #if __aarch64__ float* tm2p = tm2.row(i/12 + (i%12)/8 + (i%12%8)/4); #else float* tm2p = tm2.row(i/8 + (i%8)/4); #endif const float* r0 = bottom_blob_tm; r0 += (r*tiles + i) * 4; for (int q=0; q<inch; q++) { #if __aarch64__ asm volatile( "prfm pldl1keep, [%0, #512] \n" "ld1 {v0.4s, v1.4s, v2.4s, v3.4s}, [%0] \n" "st1 {v0.4s, v1.4s, v2.4s, v3.4s}, [%1], #64 \n" : "=r"(r0), // %0 "=r"(tm2p) // %1 : "0"(r0), "1"(tm2p) : "memory", "v0", "v1", "v2", "v3" ); #else asm volatile( "pld [%0, #512] \n" "vldm %0, {d0-d7} \n" "vstm %1!, {d0-d7} \n" : "=r"(r0), // %0 "=r"(tm2p) // %1 : "0"(r0), "1"(tm2p) : "memory", "q0", "q1", "q2", "q3" ); #endif // __aarch64__ r0 += bottom_blob_tm.cstep * 4; } } for (; i+1<tiles; i+=2) { #if __aarch64__ float* tm2p = tm2.row(i/12 + (i%12)/8 + (i%12%8)/4 + (i%12%4)/2); #else float* tm2p = tm2.row(i/8 + (i%8)/4 + (i%4)/2); #endif const float* r0 = bottom_blob_tm; r0 += (r*tiles + i) * 4; for (int q=0; q<inch; q++) { #if __aarch64__ asm volatile( "prfm pldl1keep, [%0, #256] \n" "ld1 {v0.4s, v1.4s}, [%0] \n" "st1 {v0.4s, v1.4s}, [%1], #32 \n" : "=r"(r0), // %0 "=r"(tm2p) // %1 : "0"(r0), "1"(tm2p) : "memory", "v0", "v1" ); #else asm volatile( "pld [%0, #256] \n" "vld1.f32 {d0-d3}, [%0 :128] \n" "vst1.f32 {d0-d3}, [%1 :128]! \n" : "=r"(r0), // %0 "=r"(tm2p) // %1 : "0"(r0), "1"(tm2p) : "memory", "q0", "q1" ); #endif // __aarch64__ r0 += bottom_blob_tm.cstep * 4; } } for (; i<tiles; i++) { #if __aarch64__ float* tm2p = tm2.row(i/12 + (i%12)/8 + (i%12%8)/4 + (i%12%4)/2 + i%12%2); #else float* tm2p = tm2.row(i/8 + (i%8)/4 + (i%4)/2 + i%2); #endif const float* r0 = bottom_blob_tm; r0 += (r*tiles + i) * 4; for (int q=0; q<inch; q++) { #if __aarch64__ asm volatile( "prfm pldl1keep, [%0, #128] \n" "ld1 {v0.4s}, [%0] \n" "st1 {v0.4s}, [%1], #16 \n" : "=r"(r0), // %0 "=r"(tm2p) // %1 : "0"(r0), "1"(tm2p) : "memory", "v0" ); #else asm volatile( "pld [%0, #128] \n" "vld1.f32 {d0-d1}, [%0 :128] \n" "vst1.f32 {d0-d1}, [%1 :128]! \n" : "=r"(r0), // %0 "=r"(tm2p) // %1 : "0"(r0), "1"(tm2p) : "memory", "q0" ); #endif // __aarch64__ r0 += bottom_blob_tm.cstep * 4; } } } bottom_blob_tm = Mat(); // permute end top_blob_tm.create(tiles, 64, outch, elemsize, elempack, opt.workspace_allocator); int nn_outch = 0; int remain_outch_start = 0; #if __ARM_NEON && __aarch64__ nn_outch = outch >> 1; remain_outch_start = nn_outch << 1; #pragma omp parallel for num_threads(opt.num_threads) for (int pp=0; pp<nn_outch; pp++) { int p = pp * 2; float* output0_tm = top_blob_tm.channel(p); float* output1_tm = top_blob_tm.channel(p+1); const Mat kernel01_tm = kernel_tm.channel(pp); for (int r=0; r<64; r++) { const Mat bb2 = bottom_blob_tm2.channel(r); int i=0; for (; i+11<tiles; i+=12) { const float* r0 = bb2.row(i/12); const float* k01 = kernel01_tm.row(r); int nn = inch;// inch always > 0 asm volatile( "eor v8.16b, v8.16b, v8.16b \n" "eor v9.16b, v9.16b, v9.16b \n" "eor v10.16b, v10.16b, v10.16b \n" "eor v11.16b, v11.16b, v11.16b \n" "eor v12.16b, v12.16b, v12.16b \n" "eor v13.16b, v13.16b, v13.16b \n" "eor v14.16b, v14.16b, v14.16b \n" "eor v15.16b, v15.16b, v15.16b \n" "eor v16.16b, v16.16b, v16.16b \n" "eor v17.16b, v17.16b, v17.16b \n" "eor v18.16b, v18.16b, v18.16b \n" "eor v19.16b, v19.16b, v19.16b \n" "eor v20.16b, v20.16b, v20.16b \n" "eor v21.16b, v21.16b, v21.16b \n" "eor v22.16b, v22.16b, v22.16b \n" "eor v23.16b, v23.16b, v23.16b \n" "eor v24.16b, v24.16b, v24.16b \n" "eor v25.16b, v25.16b, v25.16b \n" "eor v26.16b, v26.16b, v26.16b \n" "eor v27.16b, v27.16b, v27.16b \n" "eor v28.16b, v28.16b, v28.16b \n" "eor v29.16b, v29.16b, v29.16b \n" "eor v30.16b, v30.16b, v30.16b \n" "eor v31.16b, v31.16b, v31.16b \n" "0: \n" "prfm pldl1keep, [%3, #512] \n" "ld1 {v0.4s, v1.4s, v2.4s, v3.4s}, [%3], #64 \n" "prfm pldl1keep, [%4, #512] \n" "ld1 {v4.4s, v5.4s, v6.4s, v7.4s}, [%4], #64 \n"// w0011_01 "fmla v8.4s, v4.4s, v0.s[0] \n" "fmla v9.4s, v4.4s, v0.s[1] \n" "fmla v10.4s, v4.4s, v0.s[2] \n" "fmla v11.4s, v4.4s, v0.s[3] \n" "fmla v12.4s, v4.4s, v1.s[0] \n" "fmla v13.4s, v4.4s, v1.s[1] \n" "fmla v14.4s, v4.4s, v1.s[2] \n" "fmla v15.4s, v4.4s, v1.s[3] \n" "fmla v16.4s, v4.4s, v2.s[0] \n" "fmla v17.4s, v4.4s, v2.s[1] \n" "fmla v18.4s, v4.4s, v2.s[2] \n" "fmla v19.4s, v4.4s, v2.s[3] \n" "fmla v20.4s, v5.4s, v0.s[0] \n" "fmla v21.4s, v5.4s, v0.s[1] \n" "fmla v22.4s, v5.4s, v0.s[2] \n" "fmla v23.4s, v5.4s, v0.s[3] \n" "fmla v24.4s, v5.4s, v1.s[0] \n" "fmla v25.4s, v5.4s, v1.s[1] \n" "fmla v26.4s, v5.4s, v1.s[2] \n" "fmla v27.4s, v5.4s, v1.s[3] \n" "fmla v28.4s, v5.4s, v2.s[0] \n" "fmla v29.4s, v5.4s, v2.s[1] \n" "fmla v30.4s, v5.4s, v2.s[2] \n" "fmla v31.4s, v5.4s, v2.s[3] \n" "fmla v8.4s, v6.4s, v3.s[0] \n" "fmla v9.4s, v6.4s, v3.s[1] \n" "fmla v10.4s, v6.4s, v3.s[2] \n" "fmla v11.4s, v6.4s, v3.s[3] \n" "fmla v20.4s, v7.4s, v3.s[0] \n" "fmla v21.4s, v7.4s, v3.s[1] \n" "fmla v22.4s, v7.4s, v3.s[2] \n" "fmla v23.4s, v7.4s, v3.s[3] \n" "prfm pldl1keep, [%3, #512] \n" "ld1 {v0.4s, v1.4s, v2.4s, v3.4s}, [%3], #64 \n" "fmla v12.4s, v6.4s, v0.s[0] \n" "fmla v13.4s, v6.4s, v0.s[1] \n" "fmla v14.4s, v6.4s, v0.s[2] \n" "fmla v15.4s, v6.4s, v0.s[3] \n" "fmla v16.4s, v6.4s, v1.s[0] \n" "fmla v17.4s, v6.4s, v1.s[1] \n" "fmla v18.4s, v6.4s, v1.s[2] \n" "fmla v19.4s, v6.4s, v1.s[3] \n" "fmla v24.4s, v7.4s, v0.s[0] \n" "fmla v25.4s, v7.4s, v0.s[1] \n" "fmla v26.4s, v7.4s, v0.s[2] \n" "fmla v27.4s, v7.4s, v0.s[3] \n" "fmla v28.4s, v7.4s, v1.s[0] \n" "fmla v29.4s, v7.4s, v1.s[1] \n" "fmla v30.4s, v7.4s, v1.s[2] \n" "fmla v31.4s, v7.4s, v1.s[3] \n" "prfm pldl1keep, [%4, #512] \n" "ld1 {v4.4s, v5.4s, v6.4s, v7.4s}, [%4], #64 \n"// w2233_01 "fmla v8.4s, v4.4s, v2.s[0] \n" "fmla v9.4s, v4.4s, v2.s[1] \n" "fmla v10.4s, v4.4s, v2.s[2] \n" "fmla v11.4s, v4.4s, v2.s[3] \n" "fmla v12.4s, v4.4s, v3.s[0] \n" "fmla v13.4s, v4.4s, v3.s[1] \n" "fmla v14.4s, v4.4s, v3.s[2] \n" "fmla v15.4s, v4.4s, v3.s[3] \n" "fmla v20.4s, v5.4s, v2.s[0] \n" "fmla v21.4s, v5.4s, v2.s[1] \n" "fmla v22.4s, v5.4s, v2.s[2] \n" "fmla v23.4s, v5.4s, v2.s[3] \n" "fmla v24.4s, v5.4s, v3.s[0] \n" "fmla v25.4s, v5.4s, v3.s[1] \n" "fmla v26.4s, v5.4s, v3.s[2] \n" "fmla v27.4s, v5.4s, v3.s[3] \n" "prfm pldl1keep, [%3, #512] \n" "ld1 {v0.4s, v1.4s, v2.4s, v3.4s}, [%3], #64 \n" "fmla v16.4s, v4.4s, v0.s[0] \n" "fmla v17.4s, v4.4s, v0.s[1] \n" "fmla v18.4s, v4.4s, v0.s[2] \n" "fmla v19.4s, v4.4s, v0.s[3] \n" "fmla v28.4s, v5.4s, v0.s[0] \n" "fmla v29.4s, v5.4s, v0.s[1] \n" "fmla v30.4s, v5.4s, v0.s[2] \n" "fmla v31.4s, v5.4s, v0.s[3] \n" "fmla v8.4s, v6.4s, v1.s[0] \n" "fmla v9.4s, v6.4s, v1.s[1] \n" "fmla v10.4s, v6.4s, v1.s[2] \n" "fmla v11.4s, v6.4s, v1.s[3] \n" "fmla v12.4s, v6.4s, v2.s[0] \n" "fmla v13.4s, v6.4s, v2.s[1] \n" "fmla v14.4s, v6.4s, v2.s[2] \n" "fmla v15.4s, v6.4s, v2.s[3] \n" "fmla v16.4s, v6.4s, v3.s[0] \n" "fmla v17.4s, v6.4s, v3.s[1] \n" "fmla v18.4s, v6.4s, v3.s[2] \n" "fmla v19.4s, v6.4s, v3.s[3] \n" "subs %w0, %w0, #1 \n" "fmla v20.4s, v7.4s, v1.s[0] \n" "fmla v21.4s, v7.4s, v1.s[1] \n" "fmla v22.4s, v7.4s, v1.s[2] \n" "fmla v23.4s, v7.4s, v1.s[3] \n" "fmla v24.4s, v7.4s, v2.s[0] \n" "fmla v25.4s, v7.4s, v2.s[1] \n" "fmla v26.4s, v7.4s, v2.s[2] \n" "fmla v27.4s, v7.4s, v2.s[3] \n" "fmla v28.4s, v7.4s, v3.s[0] \n" "fmla v29.4s, v7.4s, v3.s[1] \n" "fmla v30.4s, v7.4s, v3.s[2] \n" "fmla v31.4s, v7.4s, v3.s[3] \n" "bne 0b \n" "st1 {v8.4s, v9.4s, v10.4s, v11.4s}, [%1], #64 \n" "st1 {v20.4s, v21.4s, v22.4s, v23.4s}, [%2], #64 \n" "st1 {v12.4s, v13.4s, v14.4s, v15.4s}, [%1], #64 \n" "st1 {v24.4s, v25.4s, v26.4s, v27.4s}, [%2], #64 \n" "st1 {v16.4s, v17.4s, v18.4s, v19.4s}, [%1], #64 \n" "st1 {v28.4s, v29.4s, v30.4s, v31.4s}, [%2], #64 \n" : "=r"(nn), // %0 "=r"(output0_tm), // %1 "=r"(output1_tm), // %2 "=r"(r0), // %3 "=r"(k01) // %4 : "0"(nn), "1"(output0_tm), "2"(output1_tm), "3"(r0), "4"(k01) : "cc", "memory", "v0", "v1", "v2", "v3", "v4", "v5", "v6", "v7", "v8", "v9", "v10", "v11", "v12", "v13", "v14", "v15", "v16", "v17", "v18", "v19", "v20", "v21", "v22", "v23", "v24", "v25", "v26", "v27", "v28", "v29", "v30", "v31" ); } for (; i+7<tiles; i+=8) { const float* r0 = bb2.row(i/12 + (i%12)/8); const float* k01 = kernel01_tm.row(r); int nn = inch;// inch always > 0 asm volatile( "eor v16.16b, v16.16b, v16.16b \n" "eor v17.16b, v17.16b, v17.16b \n" "eor v18.16b, v18.16b, v18.16b \n" "eor v19.16b, v19.16b, v19.16b \n" "eor v20.16b, v20.16b, v20.16b \n" "eor v21.16b, v21.16b, v21.16b \n" "eor v22.16b, v22.16b, v22.16b \n" "eor v23.16b, v23.16b, v23.16b \n" "eor v24.16b, v24.16b, v24.16b \n" "eor v25.16b, v25.16b, v25.16b \n" "eor v26.16b, v26.16b, v26.16b \n" "eor v27.16b, v27.16b, v27.16b \n" "eor v28.16b, v28.16b, v28.16b \n" "eor v29.16b, v29.16b, v29.16b \n" "eor v30.16b, v30.16b, v30.16b \n" "eor v31.16b, v31.16b, v31.16b \n" "0: \n" "prfm pldl1keep, [%3, #512] \n" "ld1 {v0.4s, v1.4s, v2.4s, v3.4s}, [%3], #64 \n"// r0 r1 r2 r3 "prfm pldl1keep, [%4, #512] \n" "ld1 {v8.4s, v9.4s, v10.4s, v11.4s}, [%4], #64 \n"// w0011_01 "prfm pldl1keep, [%3, #512] \n" "ld1 {v4.4s, v5.4s, v6.4s, v7.4s}, [%3], #64 \n"// r4 r5 r6 r7 "fmla v16.4s, v8.4s, v0.s[0] \n" "fmla v17.4s, v8.4s, v1.s[0] \n" "fmla v18.4s, v8.4s, v2.s[0] \n" "fmla v19.4s, v8.4s, v3.s[0] \n" "fmla v20.4s, v8.4s, v4.s[0] \n" "fmla v21.4s, v8.4s, v5.s[0] \n" "fmla v22.4s, v8.4s, v6.s[0] \n" "fmla v23.4s, v8.4s, v7.s[0] \n" "fmla v24.4s, v9.4s, v0.s[0] \n" "fmla v25.4s, v9.4s, v1.s[0] \n" "fmla v26.4s, v9.4s, v2.s[0] \n" "fmla v27.4s, v9.4s, v3.s[0] \n" "fmla v28.4s, v9.4s, v4.s[0] \n" "fmla v29.4s, v9.4s, v5.s[0] \n" "fmla v30.4s, v9.4s, v6.s[0] \n" "fmla v31.4s, v9.4s, v7.s[0] \n" "prfm pldl1keep, [%4, #512] \n" "ld1 {v12.4s, v13.4s, v14.4s, v15.4s}, [%4], #64 \n"// w2233_01 "fmla v16.4s, v10.4s, v0.s[1] \n" "fmla v17.4s, v10.4s, v1.s[1] \n" "fmla v18.4s, v10.4s, v2.s[1] \n" "fmla v19.4s, v10.4s, v3.s[1] \n" "fmla v20.4s, v10.4s, v4.s[1] \n" "fmla v21.4s, v10.4s, v5.s[1] \n" "fmla v22.4s, v10.4s, v6.s[1] \n" "fmla v23.4s, v10.4s, v7.s[1] \n" "fmla v24.4s, v11.4s, v0.s[1] \n" "fmla v25.4s, v11.4s, v1.s[1] \n" "fmla v26.4s, v11.4s, v2.s[1] \n" "fmla v27.4s, v11.4s, v3.s[1] \n" "fmla v28.4s, v11.4s, v4.s[1] \n" "fmla v29.4s, v11.4s, v5.s[1] \n" "fmla v30.4s, v11.4s, v6.s[1] \n" "fmla v31.4s, v11.4s, v7.s[1] \n" "fmla v16.4s, v12.4s, v0.s[2] \n" "fmla v17.4s, v12.4s, v1.s[2] \n" "fmla v18.4s, v12.4s, v2.s[2] \n" "fmla v19.4s, v12.4s, v3.s[2] \n" "fmla v20.4s, v12.4s, v4.s[2] \n" "fmla v21.4s, v12.4s, v5.s[2] \n" "fmla v22.4s, v12.4s, v6.s[2] \n" "fmla v23.4s, v12.4s, v7.s[2] \n" "fmla v24.4s, v13.4s, v0.s[2] \n" "fmla v25.4s, v13.4s, v1.s[2] \n" "fmla v26.4s, v13.4s, v2.s[2] \n" "fmla v27.4s, v13.4s, v3.s[2] \n" "fmla v28.4s, v13.4s, v4.s[2] \n" "fmla v29.4s, v13.4s, v5.s[2] \n" "fmla v30.4s, v13.4s, v6.s[2] \n" "fmla v31.4s, v13.4s, v7.s[2] \n" "fmla v16.4s, v14.4s, v0.s[3] \n" "fmla v17.4s, v14.4s, v1.s[3] \n" "fmla v18.4s, v14.4s, v2.s[3] \n" "fmla v19.4s, v14.4s, v3.s[3] \n" "fmla v20.4s, v14.4s, v4.s[3] \n" "fmla v21.4s, v14.4s, v5.s[3] \n" "fmla v22.4s, v14.4s, v6.s[3] \n" "fmla v23.4s, v14.4s, v7.s[3] \n" "subs %w0, %w0, #1 \n" "fmla v24.4s, v15.4s, v0.s[3] \n" "fmla v25.4s, v15.4s, v1.s[3] \n" "fmla v26.4s, v15.4s, v2.s[3] \n" "fmla v27.4s, v15.4s, v3.s[3] \n" "fmla v28.4s, v15.4s, v4.s[3] \n" "fmla v29.4s, v15.4s, v5.s[3] \n" "fmla v30.4s, v15.4s, v6.s[3] \n" "fmla v31.4s, v15.4s, v7.s[3] \n" "bne 0b \n" "st1 {v16.4s, v17.4s, v18.4s, v19.4s}, [%1], #64 \n" "st1 {v24.4s, v25.4s, v26.4s, v27.4s}, [%2], #64 \n" "st1 {v20.4s, v21.4s, v22.4s, v23.4s}, [%1], #64 \n" "st1 {v28.4s, v29.4s, v30.4s, v31.4s}, [%2], #64 \n" : "=r"(nn), // %0 "=r"(output0_tm), // %1 "=r"(output1_tm), // %2 "=r"(r0), // %3 "=r"(k01) // %4 : "0"(nn), "1"(output0_tm), "2"(output1_tm), "3"(r0), "4"(k01) : "cc", "memory", "v0", "v1", "v2", "v3", "v4", "v5", "v6", "v7", "v8", "v9", "v10", "v11", "v12", "v13", "v14", "v15", "v16", "v17", "v18", "v19", "v20", "v21", "v22", "v23", "v24", "v25", "v26", "v27", "v28", "v29", "v30", "v31" ); } for (; i+3<tiles; i+=4) { const float* r0 = bb2.row(i/12 + (i%12)/8 + (i%12%8)/4); const float* k01 = kernel01_tm.row(r); int nn = inch;// inch always > 0 asm volatile( "eor v16.16b, v16.16b, v16.16b \n" "eor v17.16b, v17.16b, v17.16b \n" "eor v18.16b, v18.16b, v18.16b \n" "eor v19.16b, v19.16b, v19.16b \n" "eor v20.16b, v20.16b, v20.16b \n" "eor v21.16b, v21.16b, v21.16b \n" "eor v22.16b, v22.16b, v22.16b \n" "eor v23.16b, v23.16b, v23.16b \n" "0: \n" "prfm pldl1keep, [%3, #512] \n" "ld1 {v0.4s, v1.4s, v2.4s, v3.4s}, [%3], #64 \n"// r0 r1 r2 r3 "prfm pldl1keep, [%4, #512] \n" "ld1 {v8.4s, v9.4s, v10.4s, v11.4s}, [%4], #64 \n"// w0011_01 "fmla v16.4s, v8.4s, v0.s[0] \n" "fmla v17.4s, v8.4s, v1.s[0] \n" "fmla v18.4s, v8.4s, v2.s[0] \n" "fmla v19.4s, v8.4s, v3.s[0] \n" "fmla v20.4s, v9.4s, v0.s[0] \n" "fmla v21.4s, v9.4s, v1.s[0] \n" "fmla v22.4s, v9.4s, v2.s[0] \n" "fmla v23.4s, v9.4s, v3.s[0] \n" "prfm pldl1keep, [%4, #512] \n" "ld1 {v12.4s, v13.4s, v14.4s, v15.4s}, [%4], #64 \n"// w2233_01 "fmla v16.4s, v10.4s, v0.s[1] \n" "fmla v17.4s, v10.4s, v1.s[1] \n" "fmla v18.4s, v10.4s, v2.s[1] \n" "fmla v19.4s, v10.4s, v3.s[1] \n" "fmla v20.4s, v11.4s, v0.s[1] \n" "fmla v21.4s, v11.4s, v1.s[1] \n" "fmla v22.4s, v11.4s, v2.s[1] \n" "fmla v23.4s, v11.4s, v3.s[1] \n" "fmla v16.4s, v12.4s, v0.s[2] \n" "fmla v17.4s, v12.4s, v1.s[2] \n" "fmla v18.4s, v12.4s, v2.s[2] \n" "fmla v19.4s, v12.4s, v3.s[2] \n" "fmla v20.4s, v13.4s, v0.s[2] \n" "fmla v21.4s, v13.4s, v1.s[2] \n" "fmla v22.4s, v13.4s, v2.s[2] \n" "fmla v23.4s, v13.4s, v3.s[2] \n" "subs %w0, %w0, #1 \n" "fmla v16.4s, v14.4s, v0.s[3] \n" "fmla v17.4s, v14.4s, v1.s[3] \n" "fmla v18.4s, v14.4s, v2.s[3] \n" "fmla v19.4s, v14.4s, v3.s[3] \n" "fmla v20.4s, v15.4s, v0.s[3] \n" "fmla v21.4s, v15.4s, v1.s[3] \n" "fmla v22.4s, v15.4s, v2.s[3] \n" "fmla v23.4s, v15.4s, v3.s[3] \n" "bne 0b \n" "st1 {v16.4s, v17.4s, v18.4s, v19.4s}, [%1], #64 \n" "st1 {v20.4s, v21.4s, v22.4s, v23.4s}, [%2], #64 \n" : "=r"(nn), // %0 "=r"(output0_tm), // %1 "=r"(output1_tm), // %2 "=r"(r0), // %3 "=r"(k01) // %4 : "0"(nn), "1"(output0_tm), "2"(output1_tm), "3"(r0), "4"(k01) : "cc", "memory", "v0", "v1", "v2", "v3", "v8", "v9", "v10", "v11", "v12", "v13", "v14", "v15", "v16", "v17", "v18", "v19", "v20", "v21", "v22", "v23" ); } for (; i+1<tiles; i+=2) { const float* r0 = bb2.row(i/12 + (i%12)/8 + (i%12%8)/4 + (i%12%4)/2); const float* k01 = kernel01_tm.row(r); int nn = inch;// inch always > 0 asm volatile( "eor v16.16b, v16.16b, v16.16b \n" "eor v17.16b, v17.16b, v17.16b \n" "eor v18.16b, v18.16b, v18.16b \n" "eor v19.16b, v19.16b, v19.16b \n" "0: \n" "prfm pldl1keep, [%3, #256] \n" "ld1 {v0.4s, v1.4s}, [%3], #32 \n"// r0 r1 "prfm pldl1keep, [%4, #512] \n" "ld1 {v8.4s, v9.4s, v10.4s, v11.4s}, [%4], #64 \n"// w0011_01 "fmla v16.4s, v8.4s, v0.s[0] \n" "fmla v17.4s, v8.4s, v1.s[0] \n" "fmla v18.4s, v9.4s, v0.s[0] \n" "fmla v19.4s, v9.4s, v1.s[0] \n" "prfm pldl1keep, [%4, #512] \n" "ld1 {v12.4s, v13.4s, v14.4s, v15.4s}, [%4], #64 \n"// w2233_01 "fmla v16.4s, v10.4s, v0.s[1] \n" "fmla v17.4s, v10.4s, v1.s[1] \n" "fmla v18.4s, v11.4s, v0.s[1] \n" "fmla v19.4s, v11.4s, v1.s[1] \n" "fmla v16.4s, v12.4s, v0.s[2] \n" "fmla v17.4s, v12.4s, v1.s[2] \n" "fmla v18.4s, v13.4s, v0.s[2] \n" "fmla v19.4s, v13.4s, v1.s[2] \n" "subs %w0, %w0, #1 \n" "fmla v16.4s, v14.4s, v0.s[3] \n" "fmla v17.4s, v14.4s, v1.s[3] \n" "fmla v18.4s, v15.4s, v0.s[3] \n" "fmla v19.4s, v15.4s, v1.s[3] \n" "bne 0b \n" "st1 {v16.4s, v17.4s}, [%1], #32 \n" "st1 {v18.4s, v19.4s}, [%2], #32 \n" : "=r"(nn), // %0 "=r"(output0_tm), // %1 "=r"(output1_tm), // %2 "=r"(r0), // %3 "=r"(k01) // %4 : "0"(nn), "1"(output0_tm), "2"(output1_tm), "3"(r0), "4"(k01) : "cc", "memory", "v0", "v1", "v8", "v9", "v10", "v11", "v12", "v13", "v14", "v15", "v16", "v17", "v18", "v19" ); } for (; i<tiles; i++) { const float* r0 = bb2.row(i/12 + (i%12)/8 + (i%12%8)/4 + (i%12%4)/2 + i%12%2); const float* k01 = kernel01_tm.row(r); int nn = inch;// inch always > 0 asm volatile( "eor v16.16b, v16.16b, v16.16b \n" "eor v17.16b, v17.16b, v17.16b \n" "0: \n" "prfm pldl1keep, [%3, #128] \n" "ld1 {v0.4s}, [%3], #16 \n"// r0 "prfm pldl1keep, [%4, #512] \n" "ld1 {v8.4s, v9.4s, v10.4s, v11.4s}, [%4], #64 \n"// w0011_01 "fmla v16.4s, v8.4s, v0.s[0] \n" "fmla v17.4s, v9.4s, v0.s[0] \n" "prfm pldl1keep, [%4, #512] \n" "ld1 {v12.4s, v13.4s, v14.4s, v15.4s}, [%4], #64 \n"// w2233_01 "fmla v16.4s, v10.4s, v0.s[1] \n" "fmla v17.4s, v11.4s, v0.s[1] \n" "fmla v16.4s, v12.4s, v0.s[2] \n" "fmla v17.4s, v13.4s, v0.s[2] \n" "subs %w0, %w0, #1 \n" "fmla v16.4s, v14.4s, v0.s[3] \n" "fmla v17.4s, v15.4s, v0.s[3] \n" "bne 0b \n" "st1 {v16.4s}, [%1], #16 \n" "st1 {v17.4s}, [%2], #16 \n" : "=r"(nn), // %0 "=r"(output0_tm), // %1 "=r"(output1_tm), // %2 "=r"(r0), // %3 "=r"(k01) // %4 : "0"(nn), "1"(output0_tm), "2"(output1_tm), "3"(r0), "4"(k01) : "cc", "memory", "v0", "v8", "v9", "v10", "v11", "v12", "v13", "v14", "v15", "v16", "v17" ); } } } #endif // __ARM_NEON && __aarch64__ #pragma omp parallel for num_threads(opt.num_threads) for (int p=remain_outch_start; p<outch; p++) { float* output0_tm = top_blob_tm.channel(p); #if __aarch64__ const Mat kernel0_tm = kernel_tm.channel(p/2+p%2); #else const Mat kernel0_tm = kernel_tm.channel(p); #endif for (int r=0; r<64; r++) { const Mat bb2 = bottom_blob_tm2.channel(r); int i=0; #if __aarch64__ for (; i+11<tiles; i+=12) { const float* r0 = bb2.row(i/12); const float* k0 = kernel0_tm.row(r); int nn = inch;// inch always > 0 asm volatile( "eor v8.16b, v8.16b, v8.16b \n" "eor v9.16b, v9.16b, v9.16b \n" "eor v10.16b, v10.16b, v10.16b \n" "eor v11.16b, v11.16b, v11.16b \n" "eor v12.16b, v12.16b, v12.16b \n" "eor v13.16b, v13.16b, v13.16b \n" "eor v14.16b, v14.16b, v14.16b \n" "eor v15.16b, v15.16b, v15.16b \n" "eor v16.16b, v16.16b, v16.16b \n" "eor v17.16b, v17.16b, v17.16b \n" "eor v18.16b, v18.16b, v18.16b \n" "eor v19.16b, v19.16b, v19.16b \n" "0: \n" "prfm pldl1keep, [%2, #512] \n" "ld1 {v0.4s, v1.4s, v2.4s, v3.4s}, [%2], #64 \n" "prfm pldl1keep, [%3, #512] \n" "ld1 {v4.4s, v5.4s, v6.4s, v7.4s}, [%3], #64 \n"// w0123_0 "fmla v8.4s, v4.4s, v0.s[0] \n" "fmla v9.4s, v4.4s, v0.s[1] \n" "fmla v10.4s, v4.4s, v0.s[2] \n" "fmla v11.4s, v4.4s, v0.s[3] \n" "fmla v12.4s, v4.4s, v1.s[0] \n" "fmla v13.4s, v4.4s, v1.s[1] \n" "fmla v14.4s, v4.4s, v1.s[2] \n" "fmla v15.4s, v4.4s, v1.s[3] \n" "fmla v16.4s, v4.4s, v2.s[0] \n" "fmla v17.4s, v4.4s, v2.s[1] \n" "fmla v18.4s, v4.4s, v2.s[2] \n" "fmla v19.4s, v4.4s, v2.s[3] \n" "prfm pldl1keep, [%2, #512] \n" "ld1 {v20.4s, v21.4s, v22.4s, v23.4s}, [%2], #64 \n" "fmla v8.4s, v5.4s, v3.s[0] \n" "fmla v9.4s, v5.4s, v3.s[1] \n" "fmla v10.4s, v5.4s, v3.s[2] \n" "fmla v11.4s, v5.4s, v3.s[3] \n" "fmla v12.4s, v5.4s, v20.s[0] \n" "fmla v13.4s, v5.4s, v20.s[1] \n" "fmla v14.4s, v5.4s, v20.s[2] \n" "fmla v15.4s, v5.4s, v20.s[3] \n" "fmla v16.4s, v5.4s, v21.s[0] \n" "fmla v17.4s, v5.4s, v21.s[1] \n" "fmla v18.4s, v5.4s, v21.s[2] \n" "fmla v19.4s, v5.4s, v21.s[3] \n" "prfm pldl1keep, [%2, #512] \n" "ld1 {v24.4s, v25.4s, v26.4s, v27.4s}, [%2], #64 \n" "fmla v8.4s, v6.4s, v22.s[0] \n" "fmla v9.4s, v6.4s, v22.s[1] \n" "fmla v10.4s, v6.4s, v22.s[2] \n" "fmla v11.4s, v6.4s, v22.s[3] \n" "fmla v12.4s, v6.4s, v23.s[0] \n" "fmla v13.4s, v6.4s, v23.s[1] \n" "fmla v14.4s, v6.4s, v23.s[2] \n" "fmla v15.4s, v6.4s, v23.s[3] \n" "fmla v16.4s, v6.4s, v24.s[0] \n" "fmla v17.4s, v6.4s, v24.s[1] \n" "fmla v18.4s, v6.4s, v24.s[2] \n" "fmla v19.4s, v6.4s, v24.s[3] \n" "subs %w0, %w0, #1 \n" "fmla v8.4s, v7.4s, v25.s[0] \n" "fmla v9.4s, v7.4s, v25.s[1] \n" "fmla v10.4s, v7.4s, v25.s[2] \n" "fmla v11.4s, v7.4s, v25.s[3] \n" "fmla v12.4s, v7.4s, v26.s[0] \n" "fmla v13.4s, v7.4s, v26.s[1] \n" "fmla v14.4s, v7.4s, v26.s[2] \n" "fmla v15.4s, v7.4s, v26.s[3] \n" "fmla v16.4s, v7.4s, v27.s[0] \n" "fmla v17.4s, v7.4s, v27.s[1] \n" "fmla v18.4s, v7.4s, v27.s[2] \n" "fmla v19.4s, v7.4s, v27.s[3] \n" "bne 0b \n" "st1 {v8.4s, v9.4s, v10.4s, v11.4s}, [%1], #64 \n" "st1 {v12.4s, v13.4s, v14.4s, v15.4s}, [%1], #64 \n" "st1 {v16.4s, v17.4s, v18.4s, v19.4s}, [%1], #64 \n" : "=r"(nn), // %0 "=r"(output0_tm), // %1 "=r"(r0), // %2 "=r"(k0) // %3 : "0"(nn), "1"(output0_tm), "2"(r0), "3"(k0) : "cc", "memory", "v0", "v1", "v2", "v3", "v4", "v5", "v6", "v7", "v8", "v9", "v10", "v11", "v12", "v13", "v14", "v15", "v16", "v17", "v18", "v19", "v20", "v21", "v22", "v23", "v24", "v25", "v26", "v27" ); } #endif for (; i+7<tiles; i+=8) { #if __aarch64__ const float* r0 = bb2.row(i/12 + (i%12)/8); #else const float* r0 = bb2.row(i/8); #endif const float* k0 = kernel0_tm.row(r); int nn = inch;// inch always > 0 #if __aarch64__ asm volatile( "eor v16.16b, v16.16b, v16.16b \n" "eor v17.16b, v17.16b, v17.16b \n" "eor v18.16b, v18.16b, v18.16b \n" "eor v19.16b, v19.16b, v19.16b \n" "eor v20.16b, v20.16b, v20.16b \n" "eor v21.16b, v21.16b, v21.16b \n" "eor v22.16b, v22.16b, v22.16b \n" "eor v23.16b, v23.16b, v23.16b \n" "0: \n" "prfm pldl1keep, [%2, #512] \n" "ld1 {v0.4s, v1.4s, v2.4s, v3.4s}, [%2], #64 \n"// r0 r1 r2 r3 "prfm pldl1keep, [%3, #512] \n" "ld1 {v8.4s, v9.4s, v10.4s, v11.4s}, [%3], #64 \n"// w0123 "fmla v16.4s, v8.4s, v0.s[0] \n" "fmla v17.4s, v8.4s, v1.s[0] \n" "fmla v18.4s, v8.4s, v2.s[0] \n" "fmla v19.4s, v8.4s, v3.s[0] \n" "prfm pldl1keep, [%2, #512] \n" "ld1 {v4.4s, v5.4s, v6.4s, v7.4s}, [%2], #64 \n"// r4 r5 r6 r7 "fmla v20.4s, v8.4s, v4.s[0] \n" "fmla v21.4s, v8.4s, v5.s[0] \n" "fmla v22.4s, v8.4s, v6.s[0] \n" "fmla v23.4s, v8.4s, v7.s[0] \n" "fmla v16.4s, v9.4s, v0.s[1] \n" "fmla v17.4s, v9.4s, v1.s[1] \n" "fmla v18.4s, v9.4s, v2.s[1] \n" "fmla v19.4s, v9.4s, v3.s[1] \n" "fmla v20.4s, v9.4s, v4.s[1] \n" "fmla v21.4s, v9.4s, v5.s[1] \n" "fmla v22.4s, v9.4s, v6.s[1] \n" "fmla v23.4s, v9.4s, v7.s[1] \n" "fmla v16.4s, v10.4s, v0.s[2] \n" "fmla v17.4s, v10.4s, v1.s[2] \n" "fmla v18.4s, v10.4s, v2.s[2] \n" "fmla v19.4s, v10.4s, v3.s[2] \n" "fmla v20.4s, v10.4s, v4.s[2] \n" "fmla v21.4s, v10.4s, v5.s[2] \n" "fmla v22.4s, v10.4s, v6.s[2] \n" "fmla v23.4s, v10.4s, v7.s[2] \n" "subs %w0, %w0, #1 \n" "fmla v16.4s, v11.4s, v0.s[3] \n" "fmla v17.4s, v11.4s, v1.s[3] \n" "fmla v18.4s, v11.4s, v2.s[3] \n" "fmla v19.4s, v11.4s, v3.s[3] \n" "fmla v20.4s, v11.4s, v4.s[3] \n" "fmla v21.4s, v11.4s, v5.s[3] \n" "fmla v22.4s, v11.4s, v6.s[3] \n" "fmla v23.4s, v11.4s, v7.s[3] \n" "bne 0b \n" "st1 {v16.4s, v17.4s, v18.4s, v19.4s}, [%1], #64 \n" "st1 {v20.4s, v21.4s, v22.4s, v23.4s}, [%1], #64 \n" : "=r"(nn), // %0 "=r"(output0_tm), // %1 "=r"(r0), // %2 "=r"(k0) // %3 : "0"(nn), "1"(output0_tm), "2"(r0), "3"(k0) : "cc", "memory", "v0", "v1", "v2", "v3", "v4", "v5", "v6", "v7", "v8", "v9", "v10", "v11", "v16", "v17", "v18", "v19", "v20", "v21", "v22", "v23" ); #else asm volatile( "veor q8, q8 \n" "veor q9, q9 \n" "veor q10, q10 \n" "veor q11, q11 \n" "veor q12, q12 \n" "veor q13, q13 \n" "veor q14, q14 \n" "veor q15, q15 \n" "0: \n" "pld [%2, #512] \n" "vldm %2!, {d0-d7} \n" "pld [%3, #512] \n" "vldm %3!, {d8-d15} \n" "vmla.f32 q8, q4, d0[0] \n" "vmla.f32 q9, q4, d0[1] \n" "vmla.f32 q10, q4, d1[0] \n" "vmla.f32 q11, q4, d1[1] \n" "vmla.f32 q12, q4, d2[0] \n" "vmla.f32 q13, q4, d2[1] \n" "vmla.f32 q14, q4, d3[0] \n" "vmla.f32 q15, q4, d3[1] \n" "vmla.f32 q8, q5, d4[0] \n" "vmla.f32 q9, q5, d4[1] \n" "vmla.f32 q10, q5, d5[0] \n" "vmla.f32 q11, q5, d5[1] \n" "vmla.f32 q12, q5, d6[0] \n" "vmla.f32 q13, q5, d6[1] \n" "vmla.f32 q14, q5, d7[0] \n" "vmla.f32 q15, q5, d7[1] \n" "pld [%2, #512] \n" "vldm %2!, {d0-d7} \n" "vmla.f32 q8, q6, d0[0] \n" "vmla.f32 q9, q6, d0[1] \n" "vmla.f32 q10, q6, d1[0] \n" "vmla.f32 q11, q6, d1[1] \n" "vmla.f32 q12, q6, d2[0] \n" "vmla.f32 q13, q6, d2[1] \n" "vmla.f32 q14, q6, d3[0] \n" "vmla.f32 q15, q6, d3[1] \n" "subs %0, %0, #1 \n" "vmla.f32 q8, q7, d4[0] \n" "vmla.f32 q9, q7, d4[1] \n" "vmla.f32 q10, q7, d5[0] \n" "vmla.f32 q11, q7, d5[1] \n" "vmla.f32 q12, q7, d6[0] \n" "vmla.f32 q13, q7, d6[1] \n" "vmla.f32 q14, q7, d7[0] \n" "vmla.f32 q15, q7, d7[1] \n" "bne 0b \n" "vstm %1!, {d16-d23} \n" "vstm %1!, {d24-d31} \n" : "=r"(nn), // %0 "=r"(output0_tm), // %1 "=r"(r0), // %2 "=r"(k0) // %3 : "0"(nn), "1"(output0_tm), "2"(r0), "3"(k0) : "cc", "memory", "q0", "q1", "q2", "q3", "q4", "q5", "q6", "q7", "q8", "q9", "q10", "q11", "q12", "q13", "q14", "q15" ); #endif } for (; i+3<tiles; i+=4) { #if __aarch64__ const float* r0 = bb2.row(i/12 + (i%12)/8 + (i%12%8)/4); #else const float* r0 = bb2.row(i/8 + (i%8)/4); #endif const float* k0 = kernel0_tm.row(r); int nn = inch;// inch always > 0 #if __aarch64__ asm volatile( "eor v16.16b, v16.16b, v16.16b \n" "eor v17.16b, v17.16b, v17.16b \n" "eor v18.16b, v18.16b, v18.16b \n" "eor v19.16b, v19.16b, v19.16b \n" "0: \n" "prfm pldl1keep, [%2, #512] \n" "ld1 {v0.4s, v1.4s, v2.4s, v3.4s}, [%2], #64 \n"// r0 r1 r2 r3 "prfm pldl1keep, [%3, #512] \n" "ld1 {v8.4s, v9.4s, v10.4s, v11.4s}, [%3], #64 \n"// w0123 "fmla v16.4s, v8.4s, v0.s[0] \n" "fmla v17.4s, v8.4s, v1.s[0] \n" "fmla v18.4s, v8.4s, v2.s[0] \n" "fmla v19.4s, v8.4s, v3.s[0] \n" "fmla v16.4s, v9.4s, v0.s[1] \n" "fmla v17.4s, v9.4s, v1.s[1] \n" "fmla v18.4s, v9.4s, v2.s[1] \n" "fmla v19.4s, v9.4s, v3.s[1] \n" "fmla v16.4s, v10.4s, v0.s[2] \n" "fmla v17.4s, v10.4s, v1.s[2] \n" "fmla v18.4s, v10.4s, v2.s[2] \n" "fmla v19.4s, v10.4s, v3.s[2] \n" "subs %w0, %w0, #1 \n" "fmla v16.4s, v11.4s, v0.s[3] \n" "fmla v17.4s, v11.4s, v1.s[3] \n" "fmla v18.4s, v11.4s, v2.s[3] \n" "fmla v19.4s, v11.4s, v3.s[3] \n" "bne 0b \n" "st1 {v16.4s, v17.4s, v18.4s, v19.4s}, [%1], #64 \n" : "=r"(nn), // %0 "=r"(output0_tm), // %1 "=r"(r0), // %2 "=r"(k0) // %3 : "0"(nn), "1"(output0_tm), "2"(r0), "3"(k0) : "cc", "memory", "v0", "v1", "v2", "v3", "v8", "v9", "v10", "v11", "v16", "v17", "v18", "v19" ); #else asm volatile( "veor q8, q8 \n" "veor q9, q9 \n" "veor q10, q10 \n" "veor q11, q11 \n" "0: \n" "pld [%2, #512] \n" "vldm %2!, {d0-d7} \n" "pld [%3, #512] \n" "vldm %3!, {d8-d15} \n" "vmla.f32 q8, q4, d0[0] \n" "vmla.f32 q9, q4, d2[0] \n" "vmla.f32 q10, q4, d4[0] \n" "vmla.f32 q11, q4, d6[0] \n" "vmla.f32 q8, q5, d0[1] \n" "vmla.f32 q9, q5, d2[1] \n" "vmla.f32 q10, q5, d4[1] \n" "vmla.f32 q11, q5, d6[1] \n" "vmla.f32 q8, q6, d1[0] \n" "vmla.f32 q9, q6, d3[0] \n" "vmla.f32 q10, q6, d5[0] \n" "vmla.f32 q11, q6, d7[0] \n" "subs %0, %0, #1 \n" "vmla.f32 q8, q7, d1[1] \n" "vmla.f32 q9, q7, d3[1] \n" "vmla.f32 q10, q7, d5[1] \n" "vmla.f32 q11, q7, d7[1] \n" "bne 0b \n" "vstm %1!, {d16-d23} \n" : "=r"(nn), // %0 "=r"(output0_tm), // %1 "=r"(r0), // %2 "=r"(k0) // %3 : "0"(nn), "1"(output0_tm), "2"(r0), "3"(k0) : "cc", "memory", "q0", "q1", "q2", "q3", "q4", "q5", "q6", "q7", "q8", "q9", "q10", "q11" ); #endif } for (; i+1<tiles; i+=2) { #if __aarch64__ const float* r0 = bb2.row(i/12 + (i%12)/8 + (i%12%8)/4 + (i%12%4)/2); #else const float* r0 = bb2.row(i/8 + (i%8)/4 + (i%4)/2); #endif const float* k0 = kernel0_tm.row(r); int nn = inch;// inch always > 0 #if __aarch64__ asm volatile( "eor v16.16b, v16.16b, v16.16b \n" "eor v17.16b, v17.16b, v17.16b \n" "0: \n" "prfm pldl1keep, [%2, #256] \n" "ld1 {v0.4s, v1.4s}, [%2], #32 \n"// r0 r1 "prfm pldl1keep, [%3, #512] \n" "ld1 {v8.4s, v9.4s, v10.4s, v11.4s}, [%3], #64 \n"// w0123 "fmla v16.4s, v8.4s, v0.s[0] \n" "fmla v17.4s, v8.4s, v1.s[0] \n" "fmla v16.4s, v9.4s, v0.s[1] \n" "fmla v17.4s, v9.4s, v1.s[1] \n" "fmla v16.4s, v10.4s, v0.s[2] \n" "fmla v17.4s, v10.4s, v1.s[2] \n" "subs %w0, %w0, #1 \n" "fmla v16.4s, v11.4s, v0.s[3] \n" "fmla v17.4s, v11.4s, v1.s[3] \n" "bne 0b \n" "st1 {v16.4s, v17.4s}, [%1], #32 \n" : "=r"(nn), // %0 "=r"(output0_tm), // %1 "=r"(r0), // %2 "=r"(k0) // %3 : "0"(nn), "1"(output0_tm), "2"(r0), "3"(k0) : "cc", "memory", "v0", "v1", "v8", "v9", "v10", "v11", "v16", "v17" ); #else asm volatile( "veor q8, q8 \n" "veor q9, q9 \n" "0: \n" "pld [%2, #256] \n" "vld1.f32 {d0-d3}, [%2 :128]! \n" "pld [%3, #512] \n" "vldm %3!, {d8-d15} \n" "vmla.f32 q8, q4, d0[0] \n" "vmla.f32 q9, q4, d2[0] \n" "vmla.f32 q8, q5, d0[1] \n" "vmla.f32 q9, q5, d2[1] \n" "vmla.f32 q8, q6, d1[0] \n" "vmla.f32 q9, q6, d3[0] \n" "subs %0, %0, #1 \n" "vmla.f32 q8, q7, d1[1] \n" "vmla.f32 q9, q7, d3[1] \n" "bne 0b \n" "vst1.f32 {d16-d19}, [%1 :128]! \n" : "=r"(nn), // %0 "=r"(output0_tm), // %1 "=r"(r0), // %2 "=r"(k0) // %3 : "0"(nn), "1"(output0_tm), "2"(r0), "3"(k0) : "cc", "memory", "q0", "q1", "q4", "q5", "q6", "q7", "q8", "q9" ); #endif } for (; i<tiles; i++) { #if __aarch64__ const float* r0 = bb2.row(i/12 + (i%12)/8 + (i%12%8)/4 + (i%12%4)/2 + i%12%2); #else const float* r0 = bb2.row(i/8 + (i%8)/4 + (i%4)/2 + i%2); #endif const float* k0 = kernel0_tm.row(r); int nn = inch;// inch always > 0 #if __aarch64__ asm volatile( "eor v16.16b, v16.16b, v16.16b \n" "0: \n" "prfm pldl1keep, [%2, #128] \n" "ld1 {v0.4s}, [%2], #16 \n"// r0 "prfm pldl1keep, [%3, #512] \n" "ld1 {v8.4s, v9.4s, v10.4s, v11.4s}, [%3], #64 \n"// w0123 "fmla v16.4s, v8.4s, v0.s[0] \n" "fmla v16.4s, v9.4s, v0.s[1] \n" "subs %w0, %w0, #1 \n" "fmla v16.4s, v10.4s, v0.s[2] \n" "fmla v16.4s, v11.4s, v0.s[3] \n" "bne 0b \n" "st1 {v16.4s}, [%1], #16 \n" : "=r"(nn), // %0 "=r"(output0_tm), // %1 "=r"(r0), // %2 "=r"(k0) // %3 : "0"(nn), "1"(output0_tm), "2"(r0), "3"(k0) : "cc", "memory", "v0", "v8", "v9", "v10", "v11", "v16" ); #else asm volatile( "veor q8, q8 \n" "0: \n" "pld [%2, #128] \n" "vld1.f32 {d0-d1}, [%2 :128]! \n" "pld [%3, #512] \n" "vldm %3!, {d8-d15} \n" "vmla.f32 q8, q4, d0[0] \n" "vmla.f32 q8, q5, d0[1] \n" "subs %0, %0, #1 \n" "vmla.f32 q8, q6, d1[0] \n" "vmla.f32 q8, q7, d1[1] \n" "bne 0b \n" "vst1.f32 {d16-d17}, [%1 :128]! \n" : "=r"(nn), // %0 "=r"(output0_tm), // %1 "=r"(r0), // %2 "=r"(k0) // %3 : "0"(nn), "1"(output0_tm), "2"(r0), "3"(k0) : "cc", "memory", "q0", "q4", "q5", "q6", "q7", "q8" ); #endif } } } } bottom_blob_tm = Mat(); // END dot // BEGIN transform output Mat top_blob_bordered; if (outw == top_blob.w && outh == top_blob.h) { top_blob_bordered = top_blob; } else { top_blob_bordered.create(outw, outh, outch, elemsize, elempack, opt.workspace_allocator); } { // const float otm[6][8] = { // {1.0f, 1.0f, 1.0f, 1.0f, 1.0f, 32.0f, 32.0f, 0.0f}, // {0.0f, 1.0f, -1.0f, 2.0f, -2.0f, 16.0f,-16.0f, 0.0f}, // {0.0f, 1.0f, 1.0f, 4.0f, 4.0f, 8.0f, 8.0f, 0.0f}, // {0.0f, 1.0f, -1.0f, 8.0f, -8.0f, 4.0f, -4.0f, 0.0f}, // {0.0f, 1.0f, 1.0f, 16.0f, 16.0f, 2.0f, 2.0f, 0.0f}, // {0.0f, 1.0f, -1.0f, 32.0f, -32.0f, 1.0f, -1.0f, 1.0f} // }; // 0 = r0 + (r1 + r2) + (r3 + r4) + (r5 + r6) * 32 // 1 = (r1 - r2) + (r3 - r4) * 2 + (r5 - r6) * 16 // 2 = (r1 + r2) + (r3 + r4) * 4 + (r5 + r6) * 8 // 3 = (r1 - r2) + (r3 - r4) * 8 + (r5 - r6) * 4 // 4 = (r1 + r2) + (r3 + r4) * 16+ (r5 + r6) * 2 // 5 = r7 + (r1 - r2) + (r3 - r4) * 32+ (r5 - r6) int w_tm = outw / 6 * 8; int h_tm = outh / 6 * 8; const int tiles = w_tm/8 * h_tm/8; #pragma omp parallel for num_threads(opt.num_threads) for (int p = 0; p<outch; p++) { const Mat out0_tm = top_blob_tm.channel(p); Mat out0 = top_blob_bordered.channel(p); // const float bias0 = bias ? bias[p] : 0.f; float32x4_t _bias0 = bias ? vld1q_f32( (const float*)bias + p * 4) : vdupq_n_f32(0.f); float tmp[6][8][4]; // tile for (int i=0; i<outh/6; i++) { for (int j=0; j<outw/6; j++) { // top_blob_tm.create(tiles, 64, outch, elemsize, elempack); const float* output0_tm_0 = (const float*)out0_tm + (i * w_tm/8 + j) * 4; const float* output0_tm_1 = output0_tm_0 + tiles * 4; const float* output0_tm_2 = output0_tm_0 + tiles * 8; const float* output0_tm_3 = output0_tm_0 + tiles * 12; const float* output0_tm_4 = output0_tm_0 + tiles * 16; const float* output0_tm_5 = output0_tm_0 + tiles * 20; const float* output0_tm_6 = output0_tm_0 + tiles * 24; const float* output0_tm_7 = output0_tm_0 + tiles * 28; float* output0 = out0.row(i * 6) + (j * 6) * 4; // TODO neon optimize for (int m=0; m<8; m++) { float32x4_t _out0tm0 = vld1q_f32(output0_tm_0); float32x4_t _out0tm1 = vld1q_f32(output0_tm_1); float32x4_t _out0tm2 = vld1q_f32(output0_tm_2); float32x4_t _out0tm3 = vld1q_f32(output0_tm_3); float32x4_t _out0tm4 = vld1q_f32(output0_tm_4); float32x4_t _out0tm5 = vld1q_f32(output0_tm_5); float32x4_t _out0tm6 = vld1q_f32(output0_tm_6); float32x4_t _out0tm7 = vld1q_f32(output0_tm_7); float32x4_t _tmp024a = vaddq_f32(_out0tm1, _out0tm2); float32x4_t _tmp135a = vsubq_f32(_out0tm1, _out0tm2); // float tmp024a = output0_tm[1] + output0_tm[2]; // float tmp135a = output0_tm[1] - output0_tm[2]; float32x4_t _tmp024b = vaddq_f32(_out0tm3, _out0tm4); float32x4_t _tmp135b = vsubq_f32(_out0tm3, _out0tm4); // float tmp024b = output0_tm[3] + output0_tm[4]; // float tmp135b = output0_tm[3] - output0_tm[4]; float32x4_t _tmp024c = vaddq_f32(_out0tm5, _out0tm6); float32x4_t _tmp135c = vsubq_f32(_out0tm5, _out0tm6); // float tmp024c = output0_tm[5] + output0_tm[6]; // float tmp135c = output0_tm[5] - output0_tm[6]; float32x4_t _tmp0m = vaddq_f32(vaddq_f32(_out0tm0, _tmp024a), vmlaq_n_f32(_tmp024b, _tmp024c, 32.f)); float32x4_t _tmp2m = vmlaq_n_f32(vmlaq_n_f32(_tmp024a, _tmp024b, 4.f), _tmp024c, 8.f); float32x4_t _tmp4m = vmlaq_n_f32(vmlaq_n_f32(_tmp024a, _tmp024b, 16.f), _tmp024c, 2.f); vst1q_f32(tmp[0][m], _tmp0m); vst1q_f32(tmp[2][m], _tmp2m); vst1q_f32(tmp[4][m], _tmp4m); // tmp[0][m] = output0_tm[0] + tmp024a + tmp024b + tmp024c * 32; // tmp[2][m] = tmp024a + tmp024b * 4 + tmp024c * 8; // tmp[4][m] = tmp024a + tmp024b * 16 + tmp024c + tmp024c; float32x4_t _tmp1m = vmlaq_n_f32(vmlaq_n_f32(_tmp135a, _tmp135b, 2.f), _tmp135c, 16.f); float32x4_t _tmp3m = vmlaq_n_f32(vmlaq_n_f32(_tmp135a, _tmp135b, 8.f), _tmp135c, 4.f); float32x4_t _tmp5m = vaddq_f32(vaddq_f32(_out0tm7, _tmp135a), vmlaq_n_f32(_tmp135c, _tmp135b, 32.f)); vst1q_f32(tmp[1][m], _tmp1m); vst1q_f32(tmp[3][m], _tmp3m); vst1q_f32(tmp[5][m], _tmp5m); // tmp[1][m] = tmp135a + tmp135b + tmp135b + tmp135c * 16; // tmp[3][m] = tmp135a + tmp135b * 8 + tmp135c * 4; // tmp[5][m] = output0_tm[7] + tmp135a + tmp135b * 32 + tmp135c; output0_tm_0 += tiles * 32; output0_tm_1 += tiles * 32; output0_tm_2 += tiles * 32; output0_tm_3 += tiles * 32; output0_tm_4 += tiles * 32; output0_tm_5 += tiles * 32; output0_tm_6 += tiles * 32; output0_tm_7 += tiles * 32; } for (int m=0; m<6; m++) { float32x4_t _tmp00 = vld1q_f32(tmp[m][0]); float32x4_t _tmp01 = vld1q_f32(tmp[m][1]); float32x4_t _tmp02 = vld1q_f32(tmp[m][2]); float32x4_t _tmp03 = vld1q_f32(tmp[m][3]); float32x4_t _tmp04 = vld1q_f32(tmp[m][4]); float32x4_t _tmp05 = vld1q_f32(tmp[m][5]); float32x4_t _tmp06 = vld1q_f32(tmp[m][6]); float32x4_t _tmp07 = vld1q_f32(tmp[m][7]); float32x4_t _tmp024a = vaddq_f32(_tmp01, _tmp02); float32x4_t _tmp135a = vsubq_f32(_tmp01, _tmp02); // float tmp024a = tmp0[1] + tmp0[2]; // float tmp135a = tmp0[1] - tmp0[2]; float32x4_t _tmp024b = vaddq_f32(_tmp03, _tmp04); float32x4_t _tmp135b = vsubq_f32(_tmp03, _tmp04); // float tmp024b = tmp0[3] + tmp0[4]; // float tmp135b = tmp0[3] - tmp0[4]; float32x4_t _tmp024c = vaddq_f32(_tmp05, _tmp06); float32x4_t _tmp135c = vsubq_f32(_tmp05, _tmp06); // float tmp024c = tmp0[5] + tmp0[6]; // float tmp135c = tmp0[5] - tmp0[6]; float32x4_t _out00 = vaddq_f32(_bias0, vaddq_f32(vaddq_f32(_tmp00, _tmp024a), vmlaq_n_f32(_tmp024b, _tmp024c, 32.f))); float32x4_t _out02 = vaddq_f32(_bias0, vmlaq_n_f32(vmlaq_n_f32(_tmp024a, _tmp024b, 4.f), _tmp024c, 8.f)); float32x4_t _out04 = vaddq_f32(_bias0, vmlaq_n_f32(vmlaq_n_f32(_tmp024a, _tmp024b, 16.f), _tmp024c, 2.f)); vst1q_f32(output0, _out00); vst1q_f32(output0 + 8, _out02); vst1q_f32(output0 + 16, _out04); // output0[0] = bias0 + tmp0[0] + tmp024a + tmp024b + tmp024c * 32; // output0[2] = bias0 + tmp024a + tmp024b * 4 + tmp024c * 8; // output0[4] = bias0 + tmp024a + tmp024b * 16 + tmp024c + tmp024c; float32x4_t _out01 = vaddq_f32(_bias0, vmlaq_n_f32(vmlaq_n_f32(_tmp135a, _tmp135b, 2.f), _tmp135c, 16.f)); float32x4_t _out03 = vaddq_f32(_bias0, vmlaq_n_f32(vmlaq_n_f32(_tmp135a, _tmp135b, 8.f), _tmp135c, 4.f)); float32x4_t _out05 = vaddq_f32(_bias0, vaddq_f32(vaddq_f32(_tmp07, _tmp135a), vmlaq_n_f32(_tmp135c, _tmp135b, 32.f))); vst1q_f32(output0 + 4, _out01); vst1q_f32(output0 + 12, _out03); vst1q_f32(output0 + 20, _out05); // output0[1] = bias0 + tmp135a + tmp135b + tmp135b + tmp135c * 16; // output0[3] = bias0 + tmp135a + tmp135b * 8 + tmp135c * 4; // output0[5] = bias0 + tmp0[7] + tmp135a + tmp135b * 32 + tmp135c; output0 += outw * 4; } } } } } // END transform output // cut result pad copy_cut_border(top_blob_bordered, top_blob, 0, top_blob_bordered.h - top_blob.h, 0, top_blob_bordered.w - top_blob.w, opt); } static void conv3x3s2_pack4_neon(const Mat& bottom_blob, Mat& top_blob, const Mat& kernel, const Mat& _bias, const Option& opt) { int w = bottom_blob.w; int inch = bottom_blob.c; int outw = top_blob.w; int outh = top_blob.h; int outch = top_blob.c; const int tailstep = (w - 2*outw + w) * 4; const float* bias = _bias; #pragma omp parallel for num_threads(opt.num_threads) for (int p=0; p<outch; p++) { Mat out0 = top_blob.channel(p); float32x4_t _bias0 = bias ? vld1q_f32((const float*)bias + p * 4) : vdupq_n_f32(0.f); out0.fill(_bias0); for (int q=0; q<inch; q++) { float* outptr0 = out0.row(0); const Mat img0 = bottom_blob.channel(q); const float* r0 = img0.row(0); const float* r1 = img0.row(1); const float* r2 = img0.row(2); const float* kptr = (const float*)kernel.channel(p).row(q); int i = 0; for (; i < outh; i++) { int j = 0; for (; j+3<outw; j+=4) { #if __aarch64__ asm volatile( "prfm pldl1keep, [%0, #512] \n" "ld1 {v20.4s, v21.4s, v22.4s, v23.4s}, [%0] \n"// sum0 sum1 sum2 sum3 "prfm pldl1keep, [%1, #512] \n" "ld1 {v0.4s, v1.4s, v2.4s, v3.4s}, [%1], #64 \n"// r00 r01 r02 r03 "prfm pldl1keep, [%1, #512] \n" "ld1 {v4.4s, v5.4s, v6.4s, v7.4s}, [%1], #64 \n"// r04 r05 r06 r07 "prfm pldl1keep, [%4, #512] \n" "ld1 {v16.4s, v17.4s, v18.4s, v19.4s}, [%4], #64 \n" "fmla v20.4s, v16.4s, v0.s[0] \n" "fmla v21.4s, v16.4s, v2.s[0] \n" "fmla v22.4s, v16.4s, v4.s[0] \n" "fmla v23.4s, v16.4s, v6.s[0] \n" "fmla v20.4s, v17.4s, v0.s[1] \n" "fmla v21.4s, v17.4s, v2.s[1] \n" "fmla v22.4s, v17.4s, v4.s[1] \n" "fmla v23.4s, v17.4s, v6.s[1] \n" "prfm pldl1keep, [%4, #512] \n" "ld1 {v24.4s, v25.4s, v26.4s, v27.4s}, [%4], #64 \n" "fmla v20.4s, v18.4s, v0.s[2] \n" "fmla v21.4s, v18.4s, v2.s[2] \n" "fmla v22.4s, v18.4s, v4.s[2] \n" "fmla v23.4s, v18.4s, v6.s[2] \n" "fmla v20.4s, v19.4s, v0.s[3] \n" "fmla v21.4s, v19.4s, v2.s[3] \n" "fmla v22.4s, v19.4s, v4.s[3] \n" "fmla v23.4s, v19.4s, v6.s[3] \n" "prfm pldl1keep, [%1, #128] \n" "ld1 {v28.4s}, [%1] \n"// r08 "fmla v20.4s, v24.4s, v1.s[0] \n" "fmla v21.4s, v24.4s, v3.s[0] \n" "fmla v22.4s, v24.4s, v5.s[0] \n" "fmla v23.4s, v24.4s, v7.s[0] \n" "fmla v20.4s, v25.4s, v1.s[1] \n" "fmla v21.4s, v25.4s, v3.s[1] \n" "fmla v22.4s, v25.4s, v5.s[1] \n" "fmla v23.4s, v25.4s, v7.s[1] \n" "prfm pldl1keep, [%4, #512] \n" "ld1 {v16.4s, v17.4s, v18.4s, v19.4s}, [%4], #64 \n" "fmla v20.4s, v26.4s, v1.s[2] \n" "fmla v21.4s, v26.4s, v3.s[2] \n" "fmla v22.4s, v26.4s, v5.s[2] \n" "fmla v23.4s, v26.4s, v7.s[2] \n" "fmla v20.4s, v27.4s, v1.s[3] \n" "fmla v21.4s, v27.4s, v3.s[3] \n" "fmla v22.4s, v27.4s, v5.s[3] \n" "fmla v23.4s, v27.4s, v7.s[3] \n" "prfm pldl1keep, [%2, #512] \n" "ld1 {v8.4s, v9.4s, v10.4s, v11.4s}, [%2], #64 \n"// r10 r11 r12 r13 "fmla v20.4s, v16.4s, v2.s[0] \n" "fmla v21.4s, v16.4s, v4.s[0] \n" "fmla v22.4s, v16.4s, v6.s[0] \n" "fmla v23.4s, v16.4s, v28.s[0] \n" "fmla v20.4s, v17.4s, v2.s[1] \n" "fmla v21.4s, v17.4s, v4.s[1] \n" "fmla v22.4s, v17.4s, v6.s[1] \n" "fmla v23.4s, v17.4s, v28.s[1] \n" "prfm pldl1keep, [%4, #512] \n" "ld1 {v24.4s, v25.4s, v26.4s, v27.4s}, [%4], #64 \n" "fmla v20.4s, v18.4s, v2.s[2] \n" "fmla v21.4s, v18.4s, v4.s[2] \n" "fmla v22.4s, v18.4s, v6.s[2] \n" "fmla v23.4s, v18.4s, v28.s[2] \n" "fmla v20.4s, v19.4s, v2.s[3] \n" "fmla v21.4s, v19.4s, v4.s[3] \n" "fmla v22.4s, v19.4s, v6.s[3] \n" "fmla v23.4s, v19.4s, v28.s[3] \n" "prfm pldl1keep, [%2, #512] \n" "ld1 {v12.4s, v13.4s, v14.4s, v15.4s}, [%2], #64 \n"// r14 r15 r16 r17 "fmla v20.4s, v24.4s, v8.s[0] \n" "fmla v21.4s, v24.4s, v10.s[0] \n" "fmla v22.4s, v24.4s, v12.s[0] \n" "fmla v23.4s, v24.4s, v14.s[0] \n" "fmla v20.4s, v25.4s, v8.s[1] \n" "fmla v21.4s, v25.4s, v10.s[1] \n" "fmla v22.4s, v25.4s, v12.s[1] \n" "fmla v23.4s, v25.4s, v14.s[1] \n" "prfm pldl1keep, [%4, #512] \n" "ld1 {v16.4s, v17.4s, v18.4s, v19.4s}, [%4], #64 \n" "fmla v20.4s, v26.4s, v8.s[2] \n" "fmla v21.4s, v26.4s, v10.s[2] \n" "fmla v22.4s, v26.4s, v12.s[2] \n" "fmla v23.4s, v26.4s, v14.s[2] \n" "fmla v20.4s, v27.4s, v8.s[3] \n" "fmla v21.4s, v27.4s, v10.s[3] \n" "fmla v22.4s, v27.4s, v12.s[3] \n" "fmla v23.4s, v27.4s, v14.s[3] \n" "prfm pldl1keep, [%2, #128] \n" "ld1 {v28.4s}, [%2] \n"// r18 "fmla v20.4s, v16.4s, v9.s[0] \n" "fmla v21.4s, v16.4s, v11.s[0] \n" "fmla v22.4s, v16.4s, v13.s[0] \n" "fmla v23.4s, v16.4s, v15.s[0] \n" "fmla v20.4s, v17.4s, v9.s[1] \n" "fmla v21.4s, v17.4s, v11.s[1] \n" "fmla v22.4s, v17.4s, v13.s[1] \n" "fmla v23.4s, v17.4s, v15.s[1] \n" "prfm pldl1keep, [%4, #512] \n" "ld1 {v24.4s, v25.4s, v26.4s, v27.4s}, [%4], #64 \n" "fmla v20.4s, v18.4s, v9.s[2] \n" "fmla v21.4s, v18.4s, v11.s[2] \n" "fmla v22.4s, v18.4s, v13.s[2] \n" "fmla v23.4s, v18.4s, v15.s[2] \n" "fmla v20.4s, v19.4s, v9.s[3] \n" "fmla v21.4s, v19.4s, v11.s[3] \n" "fmla v22.4s, v19.4s, v13.s[3] \n" "fmla v23.4s, v19.4s, v15.s[3] \n" "prfm pldl1keep, [%3, #512] \n" "ld1 {v0.4s, v1.4s, v2.4s, v3.4s}, [%3], #64 \n"// r20 r21 r22 r23 "fmla v20.4s, v24.4s, v10.s[0] \n" "fmla v21.4s, v24.4s, v12.s[0] \n" "fmla v22.4s, v24.4s, v14.s[0] \n" "fmla v23.4s, v24.4s, v28.s[0] \n" "fmla v20.4s, v25.4s, v10.s[1] \n" "fmla v21.4s, v25.4s, v12.s[1] \n" "fmla v22.4s, v25.4s, v14.s[1] \n" "fmla v23.4s, v25.4s, v28.s[1] \n" "prfm pldl1keep, [%4, #512] \n" "ld1 {v16.4s, v17.4s, v18.4s, v19.4s}, [%4], #64 \n" "fmla v20.4s, v26.4s, v10.s[2] \n" "fmla v21.4s, v26.4s, v12.s[2] \n" "fmla v22.4s, v26.4s, v14.s[2] \n" "fmla v23.4s, v26.4s, v28.s[2] \n" "fmla v20.4s, v27.4s, v10.s[3] \n" "fmla v21.4s, v27.4s, v12.s[3] \n" "fmla v22.4s, v27.4s, v14.s[3] \n" "fmla v23.4s, v27.4s, v28.s[3] \n" "prfm pldl1keep, [%3, #512] \n" "ld1 {v4.4s, v5.4s, v6.4s, v7.4s}, [%3], #64 \n"// r24 r25 r26 r27 "fmla v20.4s, v16.4s, v0.s[0] \n" "fmla v21.4s, v16.4s, v2.s[0] \n" "fmla v22.4s, v16.4s, v4.s[0] \n" "fmla v23.4s, v16.4s, v6.s[0] \n" "fmla v20.4s, v17.4s, v0.s[1] \n" "fmla v21.4s, v17.4s, v2.s[1] \n" "fmla v22.4s, v17.4s, v4.s[1] \n" "fmla v23.4s, v17.4s, v6.s[1] \n" "prfm pldl1keep, [%4, #512] \n" "ld1 {v24.4s, v25.4s, v26.4s, v27.4s}, [%4], #64 \n" "fmla v20.4s, v18.4s, v0.s[2] \n" "fmla v21.4s, v18.4s, v2.s[2] \n" "fmla v22.4s, v18.4s, v4.s[2] \n" "fmla v23.4s, v18.4s, v6.s[2] \n" "fmla v20.4s, v19.4s, v0.s[3] \n" "fmla v21.4s, v19.4s, v2.s[3] \n" "fmla v22.4s, v19.4s, v4.s[3] \n" "fmla v23.4s, v19.4s, v6.s[3] \n" "prfm pldl1keep, [%3, #128] \n" "ld1 {v28.4s}, [%3] \n"// r28 "fmla v20.4s, v24.4s, v1.s[0] \n" "fmla v21.4s, v24.4s, v3.s[0] \n" "fmla v22.4s, v24.4s, v5.s[0] \n" "fmla v23.4s, v24.4s, v7.s[0] \n" "fmla v20.4s, v25.4s, v1.s[1] \n" "fmla v21.4s, v25.4s, v3.s[1] \n" "fmla v22.4s, v25.4s, v5.s[1] \n" "fmla v23.4s, v25.4s, v7.s[1] \n" // "prfm pldl1keep, [%4, #512] \n" "ld1 {v16.4s, v17.4s, v18.4s, v19.4s}, [%4] \n" "fmla v20.4s, v26.4s, v1.s[2] \n" "fmla v21.4s, v26.4s, v3.s[2] \n" "fmla v22.4s, v26.4s, v5.s[2] \n" "fmla v23.4s, v26.4s, v7.s[2] \n" "fmla v20.4s, v27.4s, v1.s[3] \n" "fmla v21.4s, v27.4s, v3.s[3] \n" "fmla v22.4s, v27.4s, v5.s[3] \n" "fmla v23.4s, v27.4s, v7.s[3] \n" "fmla v20.4s, v16.4s, v2.s[0] \n" "fmla v21.4s, v16.4s, v4.s[0] \n" "fmla v22.4s, v16.4s, v6.s[0] \n" "fmla v23.4s, v16.4s, v28.s[0] \n" "fmla v20.4s, v17.4s, v2.s[1] \n" "fmla v21.4s, v17.4s, v4.s[1] \n" "fmla v22.4s, v17.4s, v6.s[1] \n" "fmla v23.4s, v17.4s, v28.s[1] \n" "fmla v20.4s, v18.4s, v2.s[2] \n" "fmla v21.4s, v18.4s, v4.s[2] \n" "fmla v22.4s, v18.4s, v6.s[2] \n" "fmla v23.4s, v18.4s, v28.s[2] \n" "fmla v20.4s, v19.4s, v2.s[3] \n" "fmla v21.4s, v19.4s, v4.s[3] \n" "fmla v22.4s, v19.4s, v6.s[3] \n" "fmla v23.4s, v19.4s, v28.s[3] \n" "sub %4, %4, #512 \n"// kptr -= 8 * 16; "st1 {v20.4s, v21.4s, v22.4s, v23.4s}, [%0], #64 \n" : "=r"(outptr0), // %0 "=r"(r0), // %1 "=r"(r1), // %2 "=r"(r2), // %3 "=r"(kptr) // %4 : "0"(outptr0), "1"(r0), "2"(r1), "3"(r2), "4"(kptr) : "memory", "v0", "v1", "v2", "v3", "v4", "v5", "v6", "v7", "v8", "v9", "v10", "v11", "v12", "v13", "v14", "v15", "v16", "v17", "v18", "v19", "v20", "v21", "v22", "v23", "v24", "v25", "v26", "v27", "v28" ); #else // __aarch64__ asm volatile( "pld [%0, #512] \n" "vldm %0, {d24-d31} \n"// sum0 sum1 sum2 sum3 "pld [%1, #512] \n" "vldm %1!, {d0-d7} \n"// r00 r01 r02 r03 "pld [%1, #512] \n" "vldm %1!, {d8-d15} \n"// r04 r05 r06 r07 "pld [%4, #512] \n" "vldm %4!, {d16-d23} \n" "vmla.f32 q12, q8, d0[0] \n" "vmla.f32 q13, q8, d4[0] \n" "vmla.f32 q14, q8, d8[0] \n" "vmla.f32 q15, q8, d12[0] \n" "vmla.f32 q12, q9, d0[1] \n" "vmla.f32 q13, q9, d4[1] \n" "vmla.f32 q14, q9, d8[1] \n" "vmla.f32 q15, q9, d12[1] \n" "vmla.f32 q12, q10, d1[0] \n" "vmla.f32 q13, q10, d5[0] \n" "vmla.f32 q14, q10, d9[0] \n" "vmla.f32 q15, q10, d13[0] \n" "vmla.f32 q12, q11, d1[1] \n" "vmla.f32 q13, q11, d5[1] \n" "vmla.f32 q14, q11, d9[1] \n" "vmla.f32 q15, q11, d13[1] \n" "pld [%4, #512] \n" "vldm %4!, {d16-d23} \n" "pld [%1, #128] \n" "vld1.f32 {d0-d1}, [%1 :128] \n"// r08 "vmla.f32 q12, q8, d2[0] \n" "vmla.f32 q13, q8, d6[0] \n" "vmla.f32 q14, q8, d10[0] \n" "vmla.f32 q15, q8, d14[0] \n" "vmla.f32 q12, q9, d2[1] \n" "vmla.f32 q13, q9, d6[1] \n" "vmla.f32 q14, q9, d10[1] \n" "vmla.f32 q15, q9, d14[1] \n" "vmla.f32 q12, q10, d3[0] \n" "vmla.f32 q13, q10, d7[0] \n" "vmla.f32 q14, q10, d11[0] \n" "vmla.f32 q15, q10, d15[0] \n" "vmla.f32 q12, q11, d3[1] \n" "vmla.f32 q13, q11, d7[1] \n" "vmla.f32 q14, q11, d11[1] \n" "vmla.f32 q15, q11, d15[1] \n" "pld [%4, #512] \n" "vldm %4!, {d16-d23} \n" "vmla.f32 q12, q8, d4[0] \n" "vmla.f32 q13, q8, d8[0] \n" "vmla.f32 q14, q8, d12[0] \n" "vmla.f32 q15, q8, d0[0] \n" "vmla.f32 q12, q9, d4[1] \n" "vmla.f32 q13, q9, d8[1] \n" "vmla.f32 q14, q9, d12[1] \n" "vmla.f32 q15, q9, d0[1] \n" "vmla.f32 q12, q10, d5[0] \n" "vmla.f32 q13, q10, d9[0] \n" "vmla.f32 q14, q10, d13[0] \n" "vmla.f32 q15, q10, d1[0] \n" "vmla.f32 q12, q11, d5[1] \n" "vmla.f32 q13, q11, d9[1] \n" "vmla.f32 q14, q11, d13[1] \n" "vmla.f32 q15, q11, d1[1] \n" "pld [%2, #512] \n" "vldm %2!, {d8-d15} \n"// r10 r11 r12 r13 "pld [%2, #512] \n" "vldm %2!, {d0-d7} \n"// r14 r15 r16 r17 "pld [%4, #512] \n" "vldm %4!, {d16-d23} \n" "vmla.f32 q12, q8, d8[0] \n" "vmla.f32 q13, q8, d12[0] \n" "vmla.f32 q14, q8, d0[0] \n" "vmla.f32 q15, q8, d4[0] \n" "vmla.f32 q12, q9, d8[1] \n" "vmla.f32 q13, q9, d12[1] \n" "vmla.f32 q14, q9, d0[1] \n" "vmla.f32 q15, q9, d4[1] \n" "vmla.f32 q12, q10, d9[0] \n" "vmla.f32 q13, q10, d13[0] \n" "vmla.f32 q14, q10, d1[0] \n" "vmla.f32 q15, q10, d5[0] \n" "vmla.f32 q12, q11, d9[1] \n" "vmla.f32 q13, q11, d13[1] \n" "vmla.f32 q14, q11, d1[1] \n" "vmla.f32 q15, q11, d5[1] \n" "pld [%4, #512] \n" "vldm %4!, {d16-d23} \n" "pld [%2, #128] \n" "vld1.f32 {d8-d9}, [%2 :128] \n"// r18 "vmla.f32 q12, q8, d10[0] \n" "vmla.f32 q13, q8, d14[0] \n" "vmla.f32 q14, q8, d2[0] \n" "vmla.f32 q15, q8, d6[0] \n" "vmla.f32 q12, q9, d10[1] \n" "vmla.f32 q13, q9, d14[1] \n" "vmla.f32 q14, q9, d2[1] \n" "vmla.f32 q15, q9, d6[1] \n" "vmla.f32 q12, q10, d11[0] \n" "vmla.f32 q13, q10, d15[0] \n" "vmla.f32 q14, q10, d3[0] \n" "vmla.f32 q15, q10, d7[0] \n" "vmla.f32 q12, q11, d11[1] \n" "vmla.f32 q13, q11, d15[1] \n" "vmla.f32 q14, q11, d3[1] \n" "vmla.f32 q15, q11, d7[1] \n" "pld [%4, #512] \n" "vldm %4!, {d16-d23} \n" "vmla.f32 q12, q8, d12[0] \n" "vmla.f32 q13, q8, d0[0] \n" "vmla.f32 q14, q8, d4[0] \n" "vmla.f32 q15, q8, d8[0] \n" "vmla.f32 q12, q9, d12[1] \n" "vmla.f32 q13, q9, d0[1] \n" "vmla.f32 q14, q9, d4[1] \n" "vmla.f32 q15, q9, d8[1] \n" "vmla.f32 q12, q10, d13[0] \n" "vmla.f32 q13, q10, d1[0] \n" "vmla.f32 q14, q10, d5[0] \n" "vmla.f32 q15, q10, d9[0] \n" "vmla.f32 q12, q11, d13[1] \n" "vmla.f32 q13, q11, d1[1] \n" "vmla.f32 q14, q11, d5[1] \n" "vmla.f32 q15, q11, d9[1] \n" "pld [%3, #512] \n" "vldm %3!, {d0-d7} \n"// r20 r21 r22 r23 "pld [%3, #512] \n" "vldm %3!, {d8-d15} \n"// r24 r25 r26 r27 "pld [%4, #512] \n" "vldm %4!, {d16-d23} \n" "vmla.f32 q12, q8, d0[0] \n" "vmla.f32 q13, q8, d4[0] \n" "vmla.f32 q14, q8, d8[0] \n" "vmla.f32 q15, q8, d12[0] \n" "vmla.f32 q12, q9, d0[1] \n" "vmla.f32 q13, q9, d4[1] \n" "vmla.f32 q14, q9, d8[1] \n" "vmla.f32 q15, q9, d12[1] \n" "vmla.f32 q12, q10, d1[0] \n" "vmla.f32 q13, q10, d5[0] \n" "vmla.f32 q14, q10, d9[0] \n" "vmla.f32 q15, q10, d13[0] \n" "vmla.f32 q12, q11, d1[1] \n" "vmla.f32 q13, q11, d5[1] \n" "vmla.f32 q14, q11, d9[1] \n" "vmla.f32 q15, q11, d13[1] \n" "pld [%4, #512] \n" "vldm %4!, {d16-d23} \n" "pld [%3, #128] \n" "vld1.f32 {d0-d1}, [%3 :128] \n"// r28 "vmla.f32 q12, q8, d2[0] \n" "vmla.f32 q13, q8, d6[0] \n" "vmla.f32 q14, q8, d10[0] \n" "vmla.f32 q15, q8, d14[0] \n" "vmla.f32 q12, q9, d2[1] \n" "vmla.f32 q13, q9, d6[1] \n" "vmla.f32 q14, q9, d10[1] \n" "vmla.f32 q15, q9, d14[1] \n" "vmla.f32 q12, q10, d3[0] \n" "vmla.f32 q13, q10, d7[0] \n" "vmla.f32 q14, q10, d11[0] \n" "vmla.f32 q15, q10, d15[0] \n" "vmla.f32 q12, q11, d3[1] \n" "vmla.f32 q13, q11, d7[1] \n" "vmla.f32 q14, q11, d11[1] \n" "vmla.f32 q15, q11, d15[1] \n" // "pld [%4, #512] \n" "vldm %4, {d16-d23} \n" "vmla.f32 q12, q8, d4[0] \n" "vmla.f32 q13, q8, d8[0] \n" "vmla.f32 q14, q8, d12[0] \n" "vmla.f32 q15, q8, d0[0] \n" "vmla.f32 q12, q9, d4[1] \n" "vmla.f32 q13, q9, d8[1] \n" "vmla.f32 q14, q9, d12[1] \n" "vmla.f32 q15, q9, d0[1] \n" "vmla.f32 q12, q10, d5[0] \n" "vmla.f32 q13, q10, d9[0] \n" "vmla.f32 q14, q10, d13[0] \n" "vmla.f32 q15, q10, d1[0] \n" "vmla.f32 q12, q11, d5[1] \n" "vmla.f32 q13, q11, d9[1] \n" "vmla.f32 q14, q11, d13[1] \n" "vmla.f32 q15, q11, d1[1] \n" "sub %4, %4, #512 \n"// kptr -= 8 * 16; "vstm %0!, {d24-d31} \n" : "=r"(outptr0), // %0 "=r"(r0), // %1 "=r"(r1), // %2 "=r"(r2), // %3 "=r"(kptr) // %4 : "0"(outptr0), "1"(r0), "2"(r1), "3"(r2), "4"(kptr) : "memory", "q0", "q1", "q2", "q3", "q4", "q5", "q6", "q7", "q8", "q9", "q10", "q11", "q12", "q13", "q14", "q15" ); #endif // __aarch64__ } for (; j+1<outw; j+=2) { #if __aarch64__ asm volatile( "prfm pldl1keep, [%0, #256] \n" "ld1 {v20.4s, v21.4s}, [%0] \n"// sum0 sum1 "prfm pldl1keep, [%1, #512] \n" "ld1 {v0.4s, v1.4s, v2.4s, v3.4s}, [%1], #64 \n"// r00 r01 r02 r03 "prfm pldl1keep, [%4, #512] \n" "ld1 {v16.4s, v17.4s, v18.4s, v19.4s}, [%4], #64 \n" "fmul v22.4s, v16.4s, v0.s[0] \n" "fmul v23.4s, v16.4s, v2.s[0] \n" "fmla v20.4s, v17.4s, v0.s[1] \n" "fmla v21.4s, v17.4s, v2.s[1] \n" "prfm pldl1keep, [%4, #512] \n" "ld1 {v24.4s, v25.4s, v26.4s, v27.4s}, [%4], #64 \n" "fmla v22.4s, v18.4s, v0.s[2] \n" "fmla v23.4s, v18.4s, v2.s[2] \n" "fmla v20.4s, v19.4s, v0.s[3] \n" "fmla v21.4s, v19.4s, v2.s[3] \n" "prfm pldl1keep, [%1, #128] \n" "ld1 {v4.4s}, [%1] \n"// r04 "fmla v22.4s, v24.4s, v1.s[0] \n" "fmla v23.4s, v24.4s, v3.s[0] \n" "fmla v20.4s, v25.4s, v1.s[1] \n" "fmla v21.4s, v25.4s, v3.s[1] \n" "prfm pldl1keep, [%4, #512] \n" "ld1 {v16.4s, v17.4s, v18.4s, v19.4s}, [%4], #64 \n" "fmla v22.4s, v26.4s, v1.s[2] \n" "fmla v23.4s, v26.4s, v3.s[2] \n" "fmla v20.4s, v27.4s, v1.s[3] \n" "fmla v21.4s, v27.4s, v3.s[3] \n" "fmla v22.4s, v16.4s, v2.s[0] \n" "fmla v23.4s, v16.4s, v4.s[0] \n" "fmla v20.4s, v17.4s, v2.s[1] \n" "fmla v21.4s, v17.4s, v4.s[1] \n" "prfm pldl1keep, [%4, #512] \n" "ld1 {v24.4s, v25.4s, v26.4s, v27.4s}, [%4], #64 \n" "fmla v22.4s, v18.4s, v2.s[2] \n" "fmla v23.4s, v18.4s, v4.s[2] \n" "fmla v20.4s, v19.4s, v2.s[3] \n" "fmla v21.4s, v19.4s, v4.s[3] \n" "prfm pldl1keep, [%2, #512] \n" "ld1 {v0.4s, v1.4s, v2.4s, v3.4s}, [%2], #64 \n"// r10 r11 r12 r13 "fmla v22.4s, v24.4s, v0.s[0] \n" "fmla v23.4s, v24.4s, v2.s[0] \n" "fmla v20.4s, v25.4s, v0.s[1] \n" "fmla v21.4s, v25.4s, v2.s[1] \n" "prfm pldl1keep, [%4, #512] \n" "ld1 {v16.4s, v17.4s, v18.4s, v19.4s}, [%4], #64 \n" "fmla v22.4s, v26.4s, v0.s[2] \n" "fmla v23.4s, v26.4s, v2.s[2] \n" "fmla v20.4s, v27.4s, v0.s[3] \n" "fmla v21.4s, v27.4s, v2.s[3] \n" "prfm pldl1keep, [%2, #128] \n" "ld1 {v4.4s}, [%2] \n"// r14 "fmla v22.4s, v16.4s, v1.s[0] \n" "fmla v23.4s, v16.4s, v3.s[0] \n" "fmla v20.4s, v17.4s, v1.s[1] \n" "fmla v21.4s, v17.4s, v3.s[1] \n" "prfm pldl1keep, [%4, #512] \n" "ld1 {v24.4s, v25.4s, v26.4s, v27.4s}, [%4], #64 \n" "fmla v22.4s, v18.4s, v1.s[2] \n" "fmla v23.4s, v18.4s, v3.s[2] \n" "fmla v20.4s, v19.4s, v1.s[3] \n" "fmla v21.4s, v19.4s, v3.s[3] \n" "fmla v22.4s, v24.4s, v2.s[0] \n" "fmla v23.4s, v24.4s, v4.s[0] \n" "fmla v20.4s, v25.4s, v2.s[1] \n" "fmla v21.4s, v25.4s, v4.s[1] \n" "prfm pldl1keep, [%4, #512] \n" "ld1 {v16.4s, v17.4s, v18.4s, v19.4s}, [%4], #64 \n" "fmla v22.4s, v26.4s, v2.s[2] \n" "fmla v23.4s, v26.4s, v4.s[2] \n" "fmla v20.4s, v27.4s, v2.s[3] \n" "fmla v21.4s, v27.4s, v4.s[3] \n" "prfm pldl1keep, [%3, #512] \n" "ld1 {v0.4s, v1.4s, v2.4s, v3.4s}, [%3], #64 \n"// r20 r21 r22 r23 "fmla v22.4s, v16.4s, v0.s[0] \n" "fmla v23.4s, v16.4s, v2.s[0] \n" "fmla v20.4s, v17.4s, v0.s[1] \n" "fmla v21.4s, v17.4s, v2.s[1] \n" "prfm pldl1keep, [%4, #512] \n" "ld1 {v24.4s, v25.4s, v26.4s, v27.4s}, [%4], #64 \n" "fmla v22.4s, v18.4s, v0.s[2] \n" "fmla v23.4s, v18.4s, v2.s[2] \n" "fmla v20.4s, v19.4s, v0.s[3] \n" "fmla v21.4s, v19.4s, v2.s[3] \n" "prfm pldl1keep, [%3, #128] \n" "ld1 {v4.4s}, [%3] \n"// r24 "fmla v22.4s, v24.4s, v1.s[0] \n" "fmla v23.4s, v24.4s, v3.s[0] \n" "fmla v20.4s, v25.4s, v1.s[1] \n" "fmla v21.4s, v25.4s, v3.s[1] \n" // "prfm pldl1keep, [%4, #512] \n" "ld1 {v16.4s, v17.4s, v18.4s, v19.4s}, [%4] \n" "fmla v22.4s, v26.4s, v1.s[2] \n" "fmla v23.4s, v26.4s, v3.s[2] \n" "fmla v20.4s, v27.4s, v1.s[3] \n" "fmla v21.4s, v27.4s, v3.s[3] \n" "fmla v22.4s, v16.4s, v2.s[0] \n" "fmla v23.4s, v16.4s, v4.s[0] \n" "fmla v20.4s, v17.4s, v2.s[1] \n" "fmla v21.4s, v17.4s, v4.s[1] \n" "fmla v22.4s, v18.4s, v2.s[2] \n" "fmla v23.4s, v18.4s, v4.s[2] \n" "fmla v20.4s, v19.4s, v2.s[3] \n" "fmla v21.4s, v19.4s, v4.s[3] \n" "fadd v20.4s, v20.4s, v22.4s \n" "fadd v21.4s, v21.4s, v23.4s \n" "sub %4, %4, #512 \n"// kptr -= 8 * 16; "st1 {v20.4s, v21.4s}, [%0], #32 \n" : "=r"(outptr0), // %0 "=r"(r0), // %1 "=r"(r1), // %2 "=r"(r2), // %3 "=r"(kptr) // %4 : "0"(outptr0), "1"(r0), "2"(r1), "3"(r2), "4"(kptr) : "memory", "v0", "v1", "v2", "v3", "v4", "v5", "v6", "v16", "v17", "v18", "v19", "v20", "v21", "v22", "v23", "v24", "v25", "v26", "v27" ); #else // __aarch64__ asm volatile( "pld [%0, #256] \n" "vld1.f32 {d24-d27}, [%0 :128] \n"// sum0 sum1 "pld [%1, #512] \n" "vldm %1!, {d0-d7} \n"// r00 r01 r02 r03 "pld [%4, #512] \n" "vldm %4!, {d16-d23} \n" "vmul.f32 q14, q8, d0[0] \n" "vmul.f32 q15, q8, d4[0] \n" "vmla.f32 q12, q9, d0[1] \n" "vmla.f32 q13, q9, d4[1] \n" "vmla.f32 q14, q10, d1[0] \n" "vmla.f32 q15, q10, d5[0] \n" "vmla.f32 q12, q11, d1[1] \n" "vmla.f32 q13, q11, d5[1] \n" "pld [%4, #512] \n" "vldm %4!, {d16-d23} \n" "pld [%1, #128] \n" "vld1.f32 {d8-d9}, [%1 :128] \n"// r04 "vmla.f32 q14, q8, d2[0] \n" "vmla.f32 q15, q8, d6[0] \n" "vmla.f32 q12, q9, d2[1] \n" "vmla.f32 q13, q9, d6[1] \n" "vmla.f32 q14, q10, d3[0] \n" "vmla.f32 q15, q10, d7[0] \n" "vmla.f32 q12, q11, d3[1] \n" "vmla.f32 q13, q11, d7[1] \n" "pld [%4, #512] \n" "vldm %4!, {d16-d23} \n" "vmla.f32 q14, q8, d4[0] \n" "vmla.f32 q15, q8, d8[0] \n" "vmla.f32 q12, q9, d4[1] \n" "vmla.f32 q13, q9, d8[1] \n" "vmla.f32 q14, q10, d5[0] \n" "vmla.f32 q15, q10, d9[0] \n" "vmla.f32 q12, q11, d5[1] \n" "vmla.f32 q13, q11, d9[1] \n" "pld [%2, #512] \n" "vldm %2!, {d0-d7} \n"// r10 r11 r12 r13 "pld [%4, #512] \n" "vldm %4!, {d16-d23} \n" "vmla.f32 q14, q8, d0[0] \n" "vmla.f32 q15, q8, d4[0] \n" "vmla.f32 q12, q9, d0[1] \n" "vmla.f32 q13, q9, d4[1] \n" "vmla.f32 q14, q10, d1[0] \n" "vmla.f32 q15, q10, d5[0] \n" "vmla.f32 q12, q11, d1[1] \n" "vmla.f32 q13, q11, d5[1] \n" "pld [%4, #512] \n" "vldm %4!, {d16-d23} \n" "pld [%2, #128] \n" "vld1.f32 {d8-d9}, [%2 :128] \n"// r14 "vmla.f32 q14, q8, d2[0] \n" "vmla.f32 q15, q8, d6[0] \n" "vmla.f32 q12, q9, d2[1] \n" "vmla.f32 q13, q9, d6[1] \n" "vmla.f32 q14, q10, d3[0] \n" "vmla.f32 q15, q10, d7[0] \n" "vmla.f32 q12, q11, d3[1] \n" "vmla.f32 q13, q11, d7[1] \n" "pld [%4, #512] \n" "vldm %4!, {d16-d23} \n" "vmla.f32 q14, q8, d4[0] \n" "vmla.f32 q15, q8, d8[0] \n" "vmla.f32 q12, q9, d4[1] \n" "vmla.f32 q13, q9, d8[1] \n" "vmla.f32 q14, q10, d5[0] \n" "vmla.f32 q15, q10, d9[0] \n" "vmla.f32 q12, q11, d5[1] \n" "vmla.f32 q13, q11, d9[1] \n" "pld [%3, #512] \n" "vldm %3!, {d0-d7} \n"// r20 r21 r22 r23 "pld [%4, #512] \n" "vldm %4!, {d16-d23} \n" "vmla.f32 q14, q8, d0[0] \n" "vmla.f32 q15, q8, d4[0] \n" "vmla.f32 q12, q9, d0[1] \n" "vmla.f32 q13, q9, d4[1] \n" "vmla.f32 q14, q10, d1[0] \n" "vmla.f32 q15, q10, d5[0] \n" "vmla.f32 q12, q11, d1[1] \n" "vmla.f32 q13, q11, d5[1] \n" "pld [%4, #512] \n" "vldm %4!, {d16-d23} \n" "pld [%3, #128] \n" "vld1.f32 {d8-d9}, [%3 :128] \n"// r24 "vmla.f32 q14, q8, d2[0] \n" "vmla.f32 q15, q8, d6[0] \n" "vmla.f32 q12, q9, d2[1] \n" "vmla.f32 q13, q9, d6[1] \n" "vmla.f32 q14, q10, d3[0] \n" "vmla.f32 q15, q10, d7[0] \n" "vmla.f32 q12, q11, d3[1] \n" "vmla.f32 q13, q11, d7[1] \n" // "pld [%4, #512] \n" "vldm %4, {d16-d23} \n" "vmla.f32 q14, q8, d4[0] \n" "vmla.f32 q15, q8, d8[0] \n" "vmla.f32 q12, q9, d4[1] \n" "vmla.f32 q13, q9, d8[1] \n" "vmla.f32 q14, q10, d5[0] \n" "vmla.f32 q15, q10, d9[0] \n" "vmla.f32 q12, q11, d5[1] \n" "vmla.f32 q13, q11, d9[1] \n" "vadd.f32 q12, q12, q14 \n" "vadd.f32 q13, q13, q15 \n" "sub %4, %4, #512 \n"// kptr -= 8 * 16; "vst1.f32 {d24-d27}, [%0 :128]! \n" : "=r"(outptr0), // %0 "=r"(r0), // %1 "=r"(r1), // %2 "=r"(r2), // %3 "=r"(kptr) // %4 : "0"(outptr0), "1"(r0), "2"(r1), "3"(r2), "4"(kptr) : "memory", "q0", "q1", "q2", "q3", "q4", "q5", "q6", "q7", "q8", "q9", "q10", "q11", "q12", "q13", "q14", "q15" ); #endif // __aarch64__ } for (; j<outw; j++) { #if __aarch64__ asm volatile( "prfm pldl1keep, [%0, #128] \n" "ld1 {v20.4s}, [%0] \n"// sum0 "prfm pldl1keep, [%1, #384] \n" "ld1 {v0.4s, v1.4s, v2.4s}, [%1] \n"// r00 r01 r02 "prfm pldl1keep, [%4, #512] \n" "ld1 {v16.4s, v17.4s, v18.4s, v19.4s}, [%4], #64 \n" "fmul v21.4s, v16.4s, v0.s[0] \n" "fmul v22.4s, v17.4s, v0.s[1] \n" "prfm pldl1keep, [%4, #512] \n" "ld1 {v24.4s, v25.4s, v26.4s, v27.4s}, [%4], #64 \n" "fmul v23.4s, v18.4s, v0.s[2] \n" "fmla v20.4s, v19.4s, v0.s[3] \n" "fmla v21.4s, v24.4s, v1.s[0] \n" "fmla v22.4s, v25.4s, v1.s[1] \n" "prfm pldl1keep, [%4, #512] \n" "ld1 {v16.4s, v17.4s, v18.4s, v19.4s}, [%4], #64 \n" "fmla v23.4s, v26.4s, v1.s[2] \n" "fmla v20.4s, v27.4s, v1.s[3] \n" "prfm pldl1keep, [%2, #384] \n" "ld1 {v3.4s, v4.4s, v5.4s}, [%2] \n"// r10 r11 r12 "fmla v21.4s, v16.4s, v2.s[0] \n" "fmla v22.4s, v17.4s, v2.s[1] \n" "prfm pldl1keep, [%4, #512] \n" "ld1 {v24.4s, v25.4s, v26.4s, v27.4s}, [%4], #64 \n" "fmla v23.4s, v18.4s, v2.s[2] \n" "fmla v20.4s, v19.4s, v2.s[3] \n" "fmla v21.4s, v24.4s, v3.s[0] \n" "fmla v22.4s, v25.4s, v3.s[1] \n" "prfm pldl1keep, [%4, #512] \n" "ld1 {v16.4s, v17.4s, v18.4s, v19.4s}, [%4], #64 \n" "fmla v23.4s, v26.4s, v3.s[2] \n" "fmla v20.4s, v27.4s, v3.s[3] \n" "fmla v21.4s, v16.4s, v4.s[0] \n" "fmla v22.4s, v17.4s, v4.s[1] \n" "prfm pldl1keep, [%4, #512] \n" "ld1 {v24.4s, v25.4s, v26.4s, v27.4s}, [%4], #64 \n" "fmla v23.4s, v18.4s, v4.s[2] \n" "fmla v20.4s, v19.4s, v4.s[3] \n" "prfm pldl1keep, [%3, #384] \n" "ld1 {v0.4s, v1.4s, v2.4s}, [%3] \n"// r20 r21 r22 "fmla v21.4s, v24.4s, v5.s[0] \n" "fmla v22.4s, v25.4s, v5.s[1] \n" "prfm pldl1keep, [%4, #512] \n" "ld1 {v16.4s, v17.4s, v18.4s, v19.4s}, [%4], #64 \n" "fmla v23.4s, v26.4s, v5.s[2] \n" "fmla v20.4s, v27.4s, v5.s[3] \n" "fmla v21.4s, v16.4s, v0.s[0] \n" "fmla v22.4s, v17.4s, v0.s[1] \n" "prfm pldl1keep, [%4, #512] \n" "ld1 {v24.4s, v25.4s, v26.4s, v27.4s}, [%4], #64 \n" "fmla v23.4s, v18.4s, v0.s[2] \n" "fmla v20.4s, v19.4s, v0.s[3] \n" "fmla v21.4s, v24.4s, v1.s[0] \n" "fmla v22.4s, v25.4s, v1.s[1] \n" // "prfm pldl1keep, [%4, #512] \n" "ld1 {v16.4s, v17.4s, v18.4s, v19.4s}, [%4] \n" "fmla v23.4s, v26.4s, v1.s[2] \n" "fmla v20.4s, v27.4s, v1.s[3] \n" "fmla v21.4s, v16.4s, v2.s[0] \n" "fmla v22.4s, v17.4s, v2.s[1] \n" "fmla v23.4s, v18.4s, v2.s[2] \n" "fmla v20.4s, v19.4s, v2.s[3] \n" "add %1, %1, #32 \n" "fadd v22.4s, v21.4s, v22.4s \n" "add %2, %2, #32 \n" "fadd v23.4s, v23.4s, v22.4s \n" "add %3, %3, #32 \n" "fadd v20.4s, v20.4s, v23.4s \n" "sub %4, %4, #512 \n"// kptr -= 8 * 16; "st1 {v20.4s}, [%0], #16 \n" : "=r"(outptr0), // %0 "=r"(r0), // %1 "=r"(r1), // %2 "=r"(r2), // %3 "=r"(kptr) // %4 : "0"(outptr0), "1"(r0), "2"(r1), "3"(r2), "4"(kptr) : "memory", "v0", "v1", "v2", "v3", "v4", "v5", "v16", "v17", "v18", "v19", "v20", "v21", "v22", "v23", "v24", "v25", "v26", "v27" ); #else // __aarch64__ asm volatile( "pld [%0, #128] \n" "vld1.f32 {d24-d25}, [%0 :128] \n"// sum0 "pld [%1, #384] \n" "vldm %1, {d0-d5} \n"// r00 r01 r02 "pld [%4, #512] \n" "vldm %4!, {d16-d23} \n" "vmul.f32 q13, q8, d0[0] \n" "vmul.f32 q14, q9, d0[1] \n" "vmul.f32 q15, q10, d1[0] \n" "vmla.f32 q12, q11, d1[1] \n" "pld [%4, #512] \n" "vldm %4!, {d16-d23} \n" "vmla.f32 q13, q8, d2[0] \n" "vmla.f32 q14, q9, d2[1] \n" "vmla.f32 q15, q10, d3[0] \n" "vmla.f32 q12, q11, d3[1] \n" "pld [%4, #512] \n" "vldm %4!, {d16-d23} \n" "vmla.f32 q13, q8, d4[0] \n" "vmla.f32 q14, q9, d4[1] \n" "vmla.f32 q15, q10, d5[0] \n" "vmla.f32 q12, q11, d5[1] \n" "pld [%2, #384] \n" "vldm %2, {d0-d5} \n"// r10 r11 r12 "pld [%4, #512] \n" "vldm %4!, {d16-d23} \n" "vmla.f32 q13, q8, d0[0] \n" "vmla.f32 q14, q9, d0[1] \n" "vmla.f32 q15, q10, d1[0] \n" "vmla.f32 q12, q11, d1[1] \n" "pld [%4, #512] \n" "vldm %4!, {d16-d23} \n" "vmla.f32 q13, q8, d2[0] \n" "vmla.f32 q14, q9, d2[1] \n" "vmla.f32 q15, q10, d3[0] \n" "vmla.f32 q12, q11, d3[1] \n" "pld [%4, #512] \n" "vldm %4!, {d16-d23} \n" "vmla.f32 q13, q8, d4[0] \n" "vmla.f32 q14, q9, d4[1] \n" "vmla.f32 q15, q10, d5[0] \n" "vmla.f32 q12, q11, d5[1] \n" "pld [%3, #384] \n" "vldm %3, {d0-d5} \n"// r20 r21 r22 "pld [%4, #512] \n" "vldm %4!, {d16-d23} \n" "vmla.f32 q13, q8, d0[0] \n" "vmla.f32 q14, q9, d0[1] \n" "vmla.f32 q15, q10, d1[0] \n" "vmla.f32 q12, q11, d1[1] \n" "pld [%4, #512] \n" "vldm %4!, {d16-d23} \n" "vmla.f32 q13, q8, d2[0] \n" "vmla.f32 q14, q9, d2[1] \n" "vmla.f32 q15, q10, d3[0] \n" "vmla.f32 q12, q11, d3[1] \n" // "pld [%4, #512] \n" "vldm %4, {d16-d23} \n" "vmla.f32 q13, q8, d4[0] \n" "vmla.f32 q14, q9, d4[1] \n" "vmla.f32 q15, q10, d5[0] \n" "vmla.f32 q12, q11, d5[1] \n" "vadd.f32 q14, q14, q13 \n" "add %1, %1, #32 \n" "vadd.f32 q15, q15, q14 \n" "add %2, %2, #32 \n" "vadd.f32 q12, q12, q15 \n" "add %3, %3, #32 \n" "sub %4, %4, #512 \n"// kptr -= 8 * 16; "vst1.f32 {d24-d25}, [%0 :128]! \n" : "=r"(outptr0), // %0 "=r"(r0), // %1 "=r"(r1), // %2 "=r"(r2), // %3 "=r"(kptr) // %4 : "0"(outptr0), "1"(r0), "2"(r1), "3"(r2), "4"(kptr) : "memory", "q0", "q1", "q2", "q3", "q4", "q5", "q6", "q7", "q8", "q9", "q10", "q11", "q12", "q13", "q14", "q15" ); #endif // __aarch64__ } r0 += tailstep; r1 += tailstep; r2 += tailstep; } } } }
_myomplib.c
#include <omp.h> #pragma omp declare target void inc_omp(int i, int *array) { array[i]++; } void dec_omp(int i, int *array) { array[i]--; } #pragma omp end declare target
icv-2.c
/* { dg-do run { target *-*-linux* } } */ #ifndef _GNU_SOURCE #define _GNU_SOURCE 1 #endif #include <pthread.h> #include <omp.h> #include <stdio.h> #include <stdlib.h> pthread_barrier_t bar; void *tf (void *p) { int l; if (p) omp_set_num_threads (3); pthread_barrier_wait (&bar); if (!p) omp_set_num_threads (6); pthread_barrier_wait (&bar); omp_set_dynamic (0); if (omp_get_max_threads () != (p ? 3 : 6)) abort (); l = 0; #pragma omp parallel num_threads (6) reduction (|:l) { l |= omp_get_max_threads () != (p ? 3 : 6); omp_set_num_threads ((p ? 3 : 6) + omp_get_thread_num ()); l |= omp_get_max_threads () != ((p ? 3 : 6) + omp_get_thread_num ()); } if (l) abort (); return NULL; } int main (void) { pthread_t th; pthread_barrier_init (&bar, NULL, 2); pthread_create (&th, NULL, tf, NULL); tf (""); pthread_join (th, NULL); return 0; }
GB_binop__rminus_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 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__rminus_int32) // A.*B function (eWiseMult): GB (_AemultB_01__rminus_int32) // A.*B function (eWiseMult): GB (_AemultB_02__rminus_int32) // A.*B function (eWiseMult): GB (_AemultB_03__rminus_int32) // A.*B function (eWiseMult): GB (_AemultB_bitmap__rminus_int32) // A*D function (colscale): GB (_AxD__rminus_int32) // D*A function (rowscale): GB (_DxB__rminus_int32) // C+=B function (dense accum): GB (_Cdense_accumB__rminus_int32) // C+=b function (dense accum): GB (_Cdense_accumb__rminus_int32) // C+=A+B function (dense ewise3): GB (_Cdense_ewise3_accum__rminus_int32) // C=A+B function (dense ewise3): GB (_Cdense_ewise3_noaccum__rminus_int32) // C=scalar+B GB (_bind1st__rminus_int32) // C=scalar+B' GB (_bind1st_tran__rminus_int32) // C=A+scalar GB (_bind2nd__rminus_int32) // C=A'+scalar GB (_bind2nd_tran__rminus_int32) // C type: int32_t // A type: int32_t // B,b type: int32_t // BinaryOp: cij = (bij - aij) #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,A_iso) \ int32_t aij = GBX (Ax, pA, A_iso) // bij = Bx [pB] #define GB_GETB(bij,Bx,pB,B_iso) \ int32_t bij = GBX (Bx, pB, B_iso) // 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,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 = (y - x) ; // 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_RMINUS || GxB_NO_INT32 || GxB_NO_RMINUS_INT32) //------------------------------------------------------------------------------ // C += A+B, all 3 matrices dense //------------------------------------------------------------------------------ // The op must be MIN, MAX, PLUS, MINUS, RMINUS, TIMES, DIV, or RDIV. void GB (_Cdense_ewise3_accum__rminus_int32) ( GrB_Matrix C, const GrB_Matrix A, const GrB_Matrix B, const int nthreads ) { #include "GB_dense_ewise3_accum_template.c" } //------------------------------------------------------------------------------ // C = A+B, all 3 matrices dense //------------------------------------------------------------------------------ GrB_Info GB (_Cdense_ewise3_noaccum__rminus_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__rminus_int32) ( 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__rminus_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 //------------------------------------------------------------------------------ GrB_Info GB (_AxD__rminus_int32) ( 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 int32_t *restrict Cx = (int32_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__rminus_int32) ( 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 *restrict Cx = (int32_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__rminus_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 *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__rminus_int32) ( 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__rminus_int32) ( 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__rminus_int32) ( 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__rminus_int32) ( 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__rminus_int32) ( 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 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 < bnz ; p++) { if (!GBB (Bb, p)) continue ; int32_t bij = GBX (Bx, p, false) ; Cx [p] = (bij - x) ; } return (GrB_SUCCESS) ; #endif } //------------------------------------------------------------------------------ // Cx = op (Ax,y): apply a binary operator to a matrix with scalar bind2nd //------------------------------------------------------------------------------ GrB_Info GB (_bind2nd__rminus_int32) ( 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 ; 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 = GBX (Ax, p, false) ; Cx [p] = (y - aij) ; } 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 = GBX (Ax, pA, false) ; \ Cx [pC] = (aij - x) ; \ } GrB_Info GB (_bind1st_tran__rminus_int32) ( 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 \ 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 = GBX (Ax, pA, false) ; \ Cx [pC] = (y - aij) ; \ } GrB_Info GB (_bind2nd_tran__rminus_int32) ( 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 int32_t y = (*((const int32_t *) y_input)) ; #include "GB_unop_transpose.c" return (GrB_SUCCESS) ; #endif } #endif
concattest0.c
#include <stdlib.h> #include "concattest0.h" void concattest0(float* l,int m,int n,float*output){ #pragma omp parallel for for (int H10 = 0; H10 < 1; H10++) { for (int H11 = 0; H11 < n; H11++) { output[((1 + (m - (1)))) * (H11) + H10] = l[(((m)) * (H11)) + H10]; } } #pragma omp parallel for for (int H12 = 1; H12 < m; H12++) { for (int H13 = 0; H13 < n; H13++) { output[((1 + (m - (1)))) * (H13) + ((H12 - (1)) + 1)] = l[(((m)) * (H13)) + H12]; } } }
single-modificado.c
#include <stdio.h> #include <omp.h> int main() { int n = 9, i, a, b[n]; for (i=0; i<n; i++) b[i] = -1; #pragma omp parallel { #pragma omp single { printf("Dentro de la región parallel:\n"); } #pragma omp single { printf("Introduce valor de inicialización a:"); scanf("%d", &a ); printf("Single ejecutada por el thread %d\n", omp_get_thread_num()); } #pragma omp for for (i=0; i<n; i++) b[i] = a; } #pragma omp single { for (i=0; i<n; i++) printf("b[%d] = %d\t",i,b[i]); printf("\n"); printf("Single ejecutada por el thread %d\n", omp_get_thread_num()); } printf("Después de la región parallel:\n"); printf("Single ejecutada por el thread %d\n", omp_get_thread_num()); for (i=0; i<n; i++) printf("b[%d] = %d\t",i,b[i]); printf("\n"); }
DRB004-antidep2-var-yes.c
/* Copyright (C) 1991-2018 Free Software Foundation, Inc. This file is part of the GNU C Library. The GNU C Library is free software; you can redistribute it andor 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 Unicode 10.0.0. Version 10.0 of the Unicode Standard is synchronized with ISOIEC 10646:2017, fifth edition, plus the following additions from Amendment 1 to the fifth edition: - 56 emoji characters - 285 hentaigana - 3 additional Zanabazar Square characters */ /* 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.comLLNL/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. */ /* Two nested loops with loop-carried anti-dependence on the outer level. This is a variable-length array version in C99. Data race pair: a[i][j]@70:7 vs. a[i+1][j]@70:18 */ #include <stdlib.h> #include <stdio.h> int main(int argc, char * argv[]) { int i, j; int len = 20; double a[len][len]; int _ret_val_0; if (argc>1) { len=atoi(argv[1]); } #pragma cetus private(i, j) #pragma loop name main#0 #pragma cetus parallel #pragma omp parallel for private(i, j) for (i=0; i<len; i ++ ) { #pragma cetus private(j) #pragma loop name main#0#0 #pragma cetus parallel #pragma omp parallel for private(j) for (j=0; j<len; j ++ ) { a[i][j]=0.5; } } #pragma cetus private(i, j) #pragma loop name main#1 for (i=0; i<(len-1); i+=1) { #pragma cetus private(j) #pragma loop name main#1#0 #pragma cetus parallel #pragma omp parallel for private(j) for (j=0; j<len; j+=1) { a[i][j]+=a[i+1][j]; } } #pragma cetus private(i, j) #pragma loop name main#2 for (i=0; i<len; i ++ ) { #pragma cetus private(j) #pragma loop name main#2#0 for (j=0; j<len; j ++ ) { printf("%lf\n", a[i][j]); } } _ret_val_0=0; return _ret_val_0; }
omp_realloc_def_fb.c
// RUN: %libomp-compile-and-run #include <stdio.h> #include <omp.h> int main() { omp_alloctrait_t at[2]; omp_allocator_handle_t a; omp_allocator_handle_t f_a; void *ptr[2]; void *nptr[2]; at[0].key = omp_atk_pool_size; at[0].value = 2 * 1024 * 1024; at[1].key = omp_atk_fallback; at[1].value = omp_atv_default_mem_fb; a = omp_init_allocator(omp_large_cap_mem_space, 2, at); f_a = omp_init_allocator(omp_default_mem_space, 2, at); printf("allocator large created: %p\n", (void *)a); printf("allocator default created: %p\n", (void *)f_a); #pragma omp parallel num_threads(2) { int i = omp_get_thread_num(); ptr[i] = omp_alloc(1024 * 1024, f_a); #pragma omp barrier nptr[i] = omp_realloc(ptr[i], 1024 * 1024, a, f_a); #pragma omp barrier printf("th %d, nptr %p\n", i, nptr[i]); omp_free(nptr[i], a); } // Both pointers should be non-NULL if (nptr[0] != NULL && nptr[1] != NULL) { printf("passed\n"); return 0; } else { printf("failed: pointers %p %p\n", nptr[0], nptr[1]); return 1; } }
parallel.c
// OpenMP version. Edit and submit only this file. /* Enter your details below * Name : Qingwei Zeng * UCLA ID : 005181694 * Email : zenn@ucla.edu */ #include <omp.h> #include <stdio.h> #include <stdlib.h> #include "utils.h" /* This function takes in two 3-d matrices: long *old, long *new. * It only updates the **non-boundary entries (NBE)** of the two matrices. * * It does the following: * - calculate the sum of old matrix's NBEs * we_need_the_var / gimmie_the_var * - make new matrix's NBEs the sum of the 9 neighboring entries in old matrix * - Record a histogram of new matrix's NBEs constant */ void work_it_par(long *old, long *new) { long aggregate = 1; const int DIM2 = DIM * DIM; /* size of one layer */ const int DIM3 = DIM2 * DIM; /* size of the whole cube */ const long we_need_the_var = we_need_the_func(); const long gimmie_the_var = gimmie_the_func(); const int num_procs = omp_get_num_procs(); omp_set_num_threads(num_procs); /* we first need to assign the workload evenly to each core. */ const int chunk_size = (DIM - 2) / num_procs; const int chunk_rmdr = (DIM - 2) % num_procs; #pragma omp parallel { int proc_id; int chunk_start, chunk_end; int i, j, k, u; long tmp; int aggregate_private; int histogrammy_private[10] = {0}; #pragma omp for reduction(+ : aggregate) for (proc_id = 0; proc_id < num_procs; ++proc_id) { chunk_start = 1 + proc_id * chunk_size + (proc_id < chunk_rmdr ? proc_id : chunk_rmdr); chunk_end = chunk_start + chunk_size + (proc_id < chunk_rmdr ? 1 : 0); /* the first chunk_rmdr cores works on an extra layer */ for (i = chunk_start * DIM2; i < chunk_end * DIM2; i += DIM2) for (j = i + DIM; j < i + DIM2 - DIM; j += DIM) for (k = j + 1; k < j + DIM - 1; ++k) { aggregate_private += old[k] * we_need_the_var / gimmie_the_var; tmp = 0; /* sum up neighboring NBEs without for loop (unrolling) */ u = k - DIM2; tmp += old[u - DIM - 1] + old[u - DIM] + old[u - DIM + 1]; tmp += old[u - 1] + old[u] + old[u + 1]; tmp += old[u + DIM - 1] + old[u + DIM] + old[u + DIM + 1]; u = k; tmp += old[u - DIM - 1] + old[u - DIM] + old[u - DIM + 1]; tmp += old[u - 1] + old[u] + old[u + 1]; tmp += old[u + DIM - 1] + old[u + DIM] + old[u + DIM + 1]; u = k + DIM2; tmp += old[u - DIM - 1] + old[u - DIM] + old[u - DIM + 1]; tmp += old[u - 1] + old[u] + old[u + 1]; tmp += old[u + DIM - 1] + old[u + DIM] + old[u + DIM + 1]; tmp /= 27; u = tmp / 100; new[k] = tmp; u = u <= 0 ? 0 : (u >= 9 ? 9 : u); histogrammy_private[u]++; } aggregate += aggregate_private; } #pragma omp critical { for (i = 0; i < 10; ++i) histogrammy[i] += histogrammy_private[i]; } } printf("AGGR:%ld\n", aggregate); }
3d25pt.c
/* * Order-2, 3D 25 point stencil * 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) #ifndef min #define min(x,y) ((x) < (y)? (x) : (y)) #endif /* 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, 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]); double ****A = (double ****) malloc(sizeof(double***)*2); double ***roc2 = (double ***) malloc(sizeof(double**)); A[0] = (double ***) malloc(sizeof(double**)*Nz); A[1] = (double ***) malloc(sizeof(double**)*Nz); roc2 = (double ***) malloc(sizeof(double**)*Nz); for(i=0; i<Nz; i++){ A[0][i] = (double**) malloc(sizeof(double*)*Ny); A[1][i] = (double**) malloc(sizeof(double*)*Ny); roc2[i] = (double**) malloc(sizeof(double*)*Ny); for(j=0;j<Ny;j++){ A[0][i][j] = (double*) malloc(sizeof(double)*Nx); A[1][i][j] = (double*) malloc(sizeof(double)*Nx); roc2[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] = 8; tile_size[1] = 8; tile_size[2] = 8; tile_size[3] = 1024; 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); roc2[i][j][k] = 2.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 const double coef0 = -0.28472; const double coef1 = 0.16000; const double coef2 = -0.02000; const double coef3 = 0.00254; const double coef4 = -0.00018; for(test=0; test<TESTS; test++){ gettimeofday(&start, 0); // serial execution - Addition: 6 && Multiplication: 2 #pragma scop for (t = 0; t < Nt; t++) { for (i = 4; i < Nz-4; i++) { for (j = 4; j < Ny-4; j++) { for (k = 4; k < Nx-4; k++) { A[(t+1)%2][i][j][k] = 2.0*A[t%2][i][j][k] - A[(t+1)%2][i][j][k] + roc2[i][j][k]*( coef0* A[t%2][i ][j ][k ] + coef1*(A[t%2][i-1][j ][k ] + A[t%2][i+1][j ][k ] + A[t%2][i ][j-1][k ] + A[t%2][i ][j+1][k ] + A[t%2][i ][j ][k-1] + A[t%2][i ][j ][k+1]) + coef2*(A[t%2][i-2][j ][k ] + A[t%2][i+2][j ][k ] + A[t%2][i ][j-2][k ] + A[t%2][i ][j+2][k ] + A[t%2][i ][j ][k-2] + A[t%2][i ][j ][k+2]) + coef3*(A[t%2][i-3][j ][k ] + A[t%2][i+3][j ][k ] + A[t%2][i ][j-3][k ] + A[t%2][i ][j+3][k ] + A[t%2][i ][j ][k-3] + A[t%2][i ][j ][k+3]) + coef4*(A[t%2][i-4][j ][k ] + A[t%2][i+4][j ][k ] + A[t%2][i ][j-4][k ] + A[t%2][i ][j+4][k ] + A[t%2][i ][j ][k-4] + A[t%2][i ][j ][k+4]) ); } } } } #pragma endscop 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, "constant") #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(roc2[i][j]); } free(A[0][i]); free(A[1][i]); free(roc2[i]); } free(A[0]); free(A[1]); free(roc2); return 0; }