gen pgcd(gen a,gen b){ gen q,r; for (;b!=0;){ r=irem(a,b,q); a=b; b=r; } return a; }
// for: _iadd, _imul, _isub, _idiv, _irem void LIRGenerator::do_ArithmeticOp_Int(ArithmeticOp* x) { bool is_div_rem = x->op() == Bytecodes::_idiv || x->op() == Bytecodes::_irem; LIRItem left(x->x(), this); LIRItem right(x->y(), this); // missing test if instr is commutative and if we should swap right.load_nonconstant(); assert(right.is_constant() || right.is_register(), "wrong state of right"); left.load_item(); rlock_result(x); if (is_div_rem) { CodeEmitInfo* info = state_for(x); LIR_Opr tmp = FrameMap::G1_opr; if (x->op() == Bytecodes::_irem) { __ irem(left.result(), right.result(), x->operand(), tmp, info); } else if (x->op() == Bytecodes::_idiv) { __ idiv(left.result(), right.result(), x->operand(), tmp, info); } } else { arithmetic_op_int(x->op(), x->operand(), left.result(), right.result(), FrameMap::G1_opr); } }
// for: _iadd, _imul, _isub, _idiv, _irem void LIRGenerator::do_ArithmeticOp_Int(ArithmeticOp* x) { if (x->op() == Bytecodes::_idiv || x->op() == Bytecodes::_irem) { // The requirements for division and modulo // input : rax,: dividend min_int // reg: divisor (may not be rax,/rdx) -1 // // output: rax,: quotient (= rax, idiv reg) min_int // rdx: remainder (= rax, irem reg) 0 // rax, and rdx will be destroyed // Note: does this invalidate the spec ??? LIRItem right(x->y(), this); LIRItem left(x->x() , this); // visit left second, so that the is_register test is valid // call state_for before load_item_force because state_for may // force the evaluation of other instructions that are needed for // correct debug info. Otherwise the live range of the fix // register might be too long. CodeEmitInfo* info = state_for(x); left.load_item_force(divInOpr()); right.load_item(); LIR_Opr result = rlock_result(x); LIR_Opr result_reg; if (x->op() == Bytecodes::_idiv) { result_reg = divOutOpr(); } else { result_reg = remOutOpr(); } if (!ImplicitDiv0Checks) { __ cmp(lir_cond_equal, right.result(), LIR_OprFact::intConst(0)); __ branch(lir_cond_equal, T_INT, new DivByZeroStub(info)); } LIR_Opr tmp = FrameMap::rdx_opr; // idiv and irem use rdx in their implementation if (x->op() == Bytecodes::_irem) { __ irem(left.result(), right.result(), result_reg, tmp, info); } else if (x->op() == Bytecodes::_idiv) { __ idiv(left.result(), right.result(), result_reg, tmp, info); } else { ShouldNotReachHere(); } __ move(result_reg, result); } else { // missing test if instr is commutative and if we should swap LIRItem left(x->x(), this); LIRItem right(x->y(), this); LIRItem* left_arg = &left; LIRItem* right_arg = &right; if (x->is_commutative() && left.is_stack() && right.is_register()) { // swap them if left is real stack (or cached) and right is real register(not cached) left_arg = &right; right_arg = &left; } left_arg->load_item(); // do not need to load right, as we can handle stack and constants if (x->op() == Bytecodes::_imul ) { // check if we can use shift instead bool use_constant = false; bool use_tmp = false; if (right_arg->is_constant()) { int iconst = right_arg->get_jint_constant(); if (iconst > 0) { if (is_power_of_2(iconst)) { use_constant = true; } else if (is_power_of_2(iconst - 1) || is_power_of_2(iconst + 1)) { use_constant = true; use_tmp = true; } } } if (use_constant) { right_arg->dont_load_item(); } else { right_arg->load_item(); } LIR_Opr tmp = LIR_OprFact::illegalOpr; if (use_tmp) { tmp = new_register(T_INT); } rlock_result(x); arithmetic_op_int(x->op(), x->operand(), left_arg->result(), right_arg->result(), tmp); } else { right_arg->dont_load_item(); rlock_result(x); LIR_Opr tmp = LIR_OprFact::illegalOpr; arithmetic_op_int(x->op(), x->operand(), left_arg->result(), right_arg->result(), tmp); } } }
void wv (type_signal Signal, type_TFR tfr) { int Nfft, column, row, time; int taumax, tau; double *lacf_real, *lacf_imag; /* local autocorrelation function */ /*--------------------------------------------------------------------*/ /* Test the input variables */ /*--------------------------------------------------------------------*/ if (tfr.is_complex == TRUE) { printf ("wv.c : The tfr matrix must be real valued\n"); exit(0); } if (tfr.N_freq <= 0) { printf ("wv.c : The field tfr.N_freq is not correctly set\n"); exit(0); } if (tfr.N_time <= 0) { printf ("wv.c : The field tfr.N_time is not correctly set\n"); exit(0); } /*--------------------------------------------------------------------*/ /* creation of the vector of frequency bins (output) */ /*--------------------------------------------------------------------*/ Nfft = po2 (tfr.N_freq); for (row = 0; row < tfr.N_freq; row++) { tfr.freq_bins[row] = (double) (0.5 * row) / tfr.N_freq; } /*--------------------------------------------------------------------*/ /* memory allocation for the local autocorrelation function */ /*--------------------------------------------------------------------*/ lacf_real = (double *) ALLOC (tfr.N_freq , sizeof (double)); lacf_imag = (double *) ALLOC (tfr.N_freq , sizeof (double)); /* initialization of these vectors */ for (row = 0; row < tfr.N_freq ; row++) { lacf_real[row] = 0.0; lacf_imag[row] = 0.0; } /*--------------------------------------------------------------------*/ /* computation of the fft for the current windowed signal */ /*--------------------------------------------------------------------*/ for (column = 0; column < tfr.N_time; column++) { /* time instants of interest to compute the Wigner distrib. */ time = ((int) tfr.time_instants[column]) - 1; /* taumax enables the computation near the edges */ taumax = MIN (time, (Signal.length - time - 1)); taumax = MIN (taumax, (tfr.N_freq / 2 - 1)); /* for each delay value, the laf is computed and ffted */ /* in order to pass from the (t,tau) domain to the (t,f) */ /* domain */ for (tau = -taumax; tau <= taumax; tau++) { row = irem((tfr.N_freq+tau), tfr.N_freq ) ; /* when the signal is complex valued */ if (Signal.is_complex == TRUE) { lacf_real[row] = Signal.real_part[time + tau] * Signal.real_part[time - tau] + Signal.imag_part[time + tau] * Signal.imag_part[time - tau]; lacf_imag[row] = Signal.imag_part[time + tau] * Signal.real_part[time - tau] - Signal.real_part[time + tau] * Signal.imag_part[time - tau]; } /* when the signal is real valued */ else { lacf_real[row] = Signal.real_part[time + tau] * Signal.real_part[time - tau]; lacf_imag[row] = 0.0; } } tau=floor(tfr.N_freq/2); if ((time<=Signal.length-tau-1)&(time>=tau)) { if (Signal.is_complex == TRUE) { lacf_real[tau] = Signal.real_part[time+tau]*Signal.real_part[time-tau] +Signal.imag_part[time+tau]*Signal.imag_part[time-tau]; lacf_imag[tau] = 0; } else { lacf_real[tau] = Signal.real_part[time+tau]*Signal.real_part[time-tau]; lacf_imag[tau] = 0; } } /* fft of the local autocorrelation function lacf */ fft (tfr.N_freq, Nfft, lacf_real, lacf_imag); /* the fft is put in the wv matrix and reinitialized */ for (row = 0; row < tfr.N_freq; row++) { tfr.real_part[idx (row,column,tfr.N_freq)]= lacf_real[row]; lacf_real[row] = 0.0; lacf_imag[row] = 0.0; } } /*--------------------------------------------------------------------*/ /* free the memory used in this program */ /*--------------------------------------------------------------------*/ FREE (lacf_real); FREE (lacf_imag); }
void mhs (type_signal Signal, double *WindowG, int WindowG_Length, double *WindowH, int WindowH_Length, type_TFR tfr ) { int Nfft, column, row, time; int taumin, taumax, tau; int half_WindowG_Length, half_WindowH_Length; double *windG_sig_real, *windG_sig_imag; /* windowed signal */ double *windH_sig_real, *windH_sig_imag; /* windowed signal */ double normH; int Lgh, points; double Kgh; /*--------------------------------------------------------------------*/ /* Test the input variables */ /*--------------------------------------------------------------------*/ if (tfr.is_complex == TRUE) { printf ("mhs.c : The tfr matrix must be real valued\n"); exit(0); } if (tfr.N_freq <= 0) { printf ("mhs.c : The field tfr.N_freq is not correctly set\n"); exit(0); } if (tfr.N_time <= 0) { printf ("mhs.c : The field tfr.N_time is not correctly set\n"); exit(0); } /*--------------------------------------------------------------------*/ /* checks that the window length is odd */ /*--------------------------------------------------------------------*/ if (ISODD(WindowG_Length) == 0) { printf ("mhs.c : The window G Length must be an ODD number\n"); exit(0); } if (ISODD(WindowH_Length) == 0) { printf ("mhs.c : The window H Length must be an ODD number\n"); exit(0); } half_WindowG_Length = (WindowG_Length - 1) / 2; half_WindowH_Length = (WindowH_Length - 1) / 2; normH=WindowH[half_WindowH_Length]; for(row = 0; row < WindowH_Length; row++) { WindowH[row] = WindowH[row]/normH; } Lgh = MIN( half_WindowG_Length , half_WindowH_Length ); Kgh = 0.0; for( points=-Lgh ; points<=Lgh ; points++) { Kgh = Kgh + WindowH[half_WindowH_Length+points] *WindowG[half_WindowG_Length+points]; } for(row = 0; row < WindowH_Length; row++) { WindowH[row] = WindowH[row]/Kgh; } /*--------------------------------------------------------------------*/ /* creation of the vector of frequency bins (output) */ /*--------------------------------------------------------------------*/ Nfft = po2 (tfr.N_freq); for (row = 0; row < tfr.N_freq; row++) { tfr.freq_bins[row] = (double) row / tfr.N_freq; } /*--------------------------------------------------------------------*/ /* memory allocation for the windowed signal */ /*--------------------------------------------------------------------*/ windG_sig_real = (double *) ALLOC (tfr.N_freq, sizeof (double)); windG_sig_imag = (double *) ALLOC (tfr.N_freq, sizeof (double)); windH_sig_real = (double *) ALLOC (tfr.N_freq, sizeof (double)); windH_sig_imag = (double *) ALLOC (tfr.N_freq, sizeof (double)); for (row = 0; row < tfr.N_freq; row++) { windG_sig_real[row] = 0.0; windG_sig_imag[row] = 0.0; windH_sig_real[row] = 0.0; windH_sig_imag[row] = 0.0; } /*--------------------------------------------------------------------*/ /* computation of the fft for the current windowed signal */ /*--------------------------------------------------------------------*/ for (column = 0; column < tfr.N_time; column++) { /* time instants of interest to compute the tfr */ time = ((int) tfr.time_instants[column]) - 1; taumin = MIN (tfr.N_freq / 2, half_WindowG_Length); taumin = MIN (taumin, time); taumax = MIN ((tfr.N_freq / 2 - 1), half_WindowG_Length); taumax = MIN (taumax, (Signal.length - time - 1)); /* The signal is windowed around the current time */ for (tau = -taumin; tau <= taumax; tau++) { row = irem( (tfr.N_freq+tau), tfr.N_freq ) ; windG_sig_real[row] = Signal.real_part[time + tau] * WindowG[half_WindowG_Length + tau]; if (Signal.is_complex == TRUE) { windG_sig_imag[row] = Signal.imag_part[time + tau] * WindowG[half_WindowG_Length + tau]; } } /* fft of the windowed signal */ fft (tfr.N_freq, Nfft, windG_sig_real, windG_sig_imag); taumin = MIN (tfr.N_freq / 2, half_WindowH_Length); taumin = MIN (taumin, time); taumax = MIN ((tfr.N_freq / 2 - 1), half_WindowH_Length); taumax = MIN (taumax, (Signal.length - time - 1)); /* The signal is windowed around the current time */ for (tau = -taumin; tau <= taumax; tau++) { row = irem( (tfr.N_freq+tau), tfr.N_freq ) ; windH_sig_real[row] = Signal.real_part[time + tau] * WindowH[half_WindowH_Length + tau]; if (Signal.is_complex == TRUE) { windH_sig_imag[row] = Signal.imag_part[time + tau] * WindowH[half_WindowH_Length + tau]; } } /* fft of the windowed signal */ fft (tfr.N_freq, Nfft, windH_sig_real, windH_sig_imag); /* the first half of the fft is put in the tfr matrix */ for (row = 0; row < tfr.N_freq; row++) { tfr.real_part[idx (row,column,tfr.N_freq)] = windG_sig_real[row]*windH_sig_real[row] + windG_sig_imag[row]*windH_sig_imag[row]; windG_sig_real[row] = 0.0; windG_sig_imag[row] = 0.0; windH_sig_real[row] = 0.0; windH_sig_imag[row] = 0.0; } } /*--------------------------------------------------------------------*/ /* free the memory used in this program */ /*--------------------------------------------------------------------*/ FREE (windG_sig_real); FREE (windG_sig_imag); FREE (windH_sig_real); FREE (windH_sig_imag); }
void ri (type_signal Signal, type_TFR tfr) { int Nfft, column, row, time; int taumin, taumax, tau; double *lacf_real, *lacf_imag; /* local autocorrelation function */ /*--------------------------------------------------------------------*/ /* Test the input variables */ /*--------------------------------------------------------------------*/ if (tfr.is_complex == FALSE) { printf ("ri.c : The tfr matrix must be complex valued\n"); exit(0); } if (tfr.N_freq <= 0) { printf ("ri.c : The field tfr.N_freq is not correctly set\n"); exit(0); } if (tfr.N_time <= 0) { printf ("ri.c : The field tfr.N_time is not correctly set\n"); exit(0); } /*--------------------------------------------------------------------*/ /* creation of the vector of frequency bins (output) */ /*--------------------------------------------------------------------*/ Nfft = po2 (tfr.N_freq); for (row = 0; row < tfr.N_freq; row++) { tfr.freq_bins[row] = (double) row / tfr.N_freq; } /*--------------------------------------------------------------------*/ /* memory allocation for the windowed signal */ /*--------------------------------------------------------------------*/ lacf_real = (double *) ALLOC (tfr.N_freq , sizeof (double)); lacf_imag = (double *) ALLOC (tfr.N_freq , sizeof (double)); /* initialization of the intermediary vectors */ for (row = 0; row < tfr.N_freq ; row++) { lacf_real[row] = 0.0; lacf_imag[row] = 0.0; } /*--------------------------------------------------------------------*/ /* computation of the fft for the current windowed signal */ /*--------------------------------------------------------------------*/ for (column = 0; column < tfr.N_time; column++) { /* time instants of interest to compute the tfr */ time = ((int) tfr.time_instants[column]) - 1; /* taumax and taumin enable the computation near the edges */ taumin = MIN( (tfr.N_freq - time), (Signal.length - time - 1) ); taumax = time; /* The signal is windowed around the current time */ for (tau = -taumin; tau <= taumax; tau++) { row = irem( (tfr.N_freq+tau), tfr.N_freq ) ; if (Signal.is_complex == TRUE) /* when the signal is complex valued */ { lacf_real[row] = Signal.real_part[time] * Signal.real_part[time - tau] + Signal.imag_part[time] * Signal.imag_part[time - tau]; lacf_imag[row] = Signal.imag_part[time] * Signal.real_part[time - tau] - Signal.real_part[time] * Signal.imag_part[time - tau]; } else /* when the signal is real valued */ { lacf_real[row] = Signal.real_part[time] * Signal.real_part[time - tau]; lacf_imag[row] = 0.0; } } /* fft of the local autocorrelation function lacf */ fft (tfr.N_freq, Nfft, lacf_real, lacf_imag); /* the fft is put in the tfr matrix */ for (row = 0; row < tfr.N_freq; row++) { tfr.real_part[idx (row,column,tfr.N_freq)]= lacf_real[row]; tfr.imag_part[idx (row,column,tfr.N_freq)]= lacf_imag[row]; lacf_real[row] = 0.0; lacf_imag[row] = 0.0; } } /*--------------------------------------------------------------------*/ /* free the memory used in this program */ /*--------------------------------------------------------------------*/ FREE (lacf_real); FREE (lacf_imag); }