void ovm_dd_ne(oregister_t *l, oregister_t *r) { l->t = t_word; switch (r->t) { case t_cdd: l->v.w = l->v.dd != r->v.dd; break; case t_cqq: l->v.w = mpq_get_d(oqr(r)) != real(l->v.dd) || mpq_get_d(oqi(r)) != imag(l->v.dd); break; case t_mpc: mpfr_set_d(orr(l), real(l->v.dd), thr_rnd); if (mpfr_equal_p(orr(l), orr(r))) { mpfr_set_d(ori(l), imag(l->v.dd), thr_rnd); l->v.w = !mpfr_equal_p(ori(l), ori(r)); } else l->v.w = 1; break; default: l->v.w = 1; break; } }
void ovm_q_le(oregister_t *l, oregister_t *r) { l->t = t_word; switch (r->t) { case t_void: l->v.w = mpq_sgn(oqr(l)) <= 0; break; case t_word: l->v.w = mpq_cmp_si(oqr(l), r->v.w, 1) <= 0; break; case t_float: l->v.w = mpq_get_d(oqr(l)) <= r->v.d; break; case t_mpz: mpq_set_z(oqr(r), ozr(r)); l->v.w = mpq_cmp(oqr(l), oqr(r)) <= 0; break; case t_rat: mpq_set_si(oqr(r), rat_num(r->v.r), rat_den(r->v.r)); l->v.w = mpq_cmp(oqr(l), oqr(r)) <= 0; break; case t_mpq: l->v.w = mpq_cmp(oqr(l), oqr(r)) <= 0; break; case t_mpr: mpfr_set_z(orr(l), ozr(l), thr_rnd); l->v.w = mpfr_lessequal_p(orr(l), orr(r)); break; default: ovm_raise(except_not_a_real_number); } }
/*! PUSH16(PC) PUSH8((P&~B) | U) P |= I PC = READ16(vector) ADDCYC(7) */ void NesCpuTranslator::mHwInterrupt() { // r0 - 6502.PC address of interrupted instruction // r1 - vector addresss - selects (nmi, irq, reset) which interrupt will // be executed // as a result lr register is loaded with the address of code mPush16(r0); mRestoreInternalFlags(); mPackFlags(r0); __ bic(r0, r0, Operand(NesCpuBase::Break)); __ orr(r0, r0, Operand(NesCpuBase::Unused)); mPush8(r0); mSei(); mAddCycles(7); // new address will be loaded, r0 must point to PC address as translation // can occur for the given interrupt mReadDirect8(r1, r0); __ add(r1, r1, Operand(1)); mReadDirect8(r1, r2); __ orr(r0, r0, Operand(r2, LSL, 8)); // load lr with label pos mLoadLabelAddress(r0, lr); }
void ovm_q_mul(oregister_t *l, oregister_t *r) { switch (r->t) { case t_void: l->t = t_word; l->v.w = 0; break; case t_word: mpq_set_si(oqr(r), r->v.w, 1); mpq_mul(oqr(l), oqr(l), oqr(r)); check_mpq(l); break; case t_float: l->t = t_float; l->v.d = mpq_get_d(oqr(l)) * r->v.d; break; case t_mpz: mpz_set_ui(ozs(r), 1); mpq_mul(oqr(l), oqr(l), oqr(r)); check_mpq(l); break; case t_rat: mpq_set_si(oqr(r), rat_num(r->v.r), rat_den(r->v.r)); mpq_mul(oqr(l), oqr(l), oqr(r)); check_mpq(l); break; case t_mpq: mpq_mul(oqr(l), oqr(l), oqr(r)); check_mpq(l); break; case t_mpr: l->t = t_mpr; mpfr_set_q(orr(l), oqr(l), thr_rnd); mpfr_mul(orr(l), orr(l), orr(r), thr_rnd); break; case t_cdd: l->t = t_cdd; l->v.dd = mpq_get_d(oqr(l)) * r->v.dd; check_cdd(l); break; case t_cqq: l->t = t_cqq; mpq_set_ui(oqi(l), 0, 1); cqq_mul(oqq(l), oqq(l), oqq(r)); check_cqq(l); break; case t_mpc: l->t = t_mpc; mpc_set_q(occ(l), oqr(l), thr_rndc); mpc_mul(occ(l), occ(l), occ(r), thr_rndc); check_mpc(l); break; default: ovm_raise(except_not_a_number); } }
void ovm_q_rem(oregister_t *l, oregister_t *r) { switch (r->t) { case t_void: ovm_raise(except_floating_point_error); case t_word: if (r->v.w == 0) ovm_raise(except_floating_point_error); if (r->v.w > 0) mpz_mul_ui(ozr(r), ozs(l), r->v.w); else { mpz_set_si(ozr(r), r->v.w); mpz_mul(ozr(r), ozs(l), ozr(r)); } mpz_tdiv_r(ozr(l), ozr(l), ozr(r)); mpq_canonicalize(oqr(l)); check_mpq(l); break; case t_float: l->t = t_float; l->v.d = fmod(mpq_get_d(oqr(l)), r->v.d); break; case t_mpz: mpz_mul(ozr(r), ozs(l), ozr(r)); mpz_tdiv_r(ozr(l), ozr(l), ozr(r)); check_mpq(l); break; case t_rat: mpq_set_si(oqr(r), rat_num(r->v.r), rat_den(r->v.r)); case t_mpq: mpq_div(oqr(l), oqr(l), oqr(r)); mpz_tdiv_r(ozr(l), ozr(l), ozs(l)); mpz_mul(ozs(l), ozs(l), ozs(r)); mpq_canonicalize(oqr(l)); if (mpq_sgn(oqr(r)) < 0) mpq_neg(oqr(l), oqr(l)); check_mpq(l); break; case t_mpr: l->t = t_mpr; mpfr_set_q(orr(l), oqr(l), thr_rnd); mpfr_fmod(orr(l), orr(l), orr(r), thr_rnd); break; default: ovm_raise(except_not_a_real_number); } }
address AbstractInterpreterGenerator::generate_result_handler_for(BasicType type) { // // Registers alive // R3_RET // LR // // Registers updated // R3_RET // Label done; address entry = __ pc(); switch (type) { case T_BOOLEAN: // convert !=0 to 1 __ neg(R0, R3_RET); __ orr(R0, R3_RET, R0); __ srwi(R3_RET, R0, 31); break; case T_BYTE: // sign extend 8 bits __ extsb(R3_RET, R3_RET); break; case T_CHAR: // zero extend 16 bits __ clrldi(R3_RET, R3_RET, 48); break; case T_SHORT: // sign extend 16 bits __ extsh(R3_RET, R3_RET); break; case T_INT: // sign extend 32 bits __ extsw(R3_RET, R3_RET); break; case T_LONG: break; case T_OBJECT: // unbox result if not null __ cmpdi(CCR0, R3_RET, 0); __ beq(CCR0, done); __ ld(R3_RET, 0, R3_RET); __ verify_oop(R3_RET); break; case T_FLOAT: break; case T_DOUBLE: break; case T_VOID: break; default: ShouldNotReachHere(); } __ BIND(done); __ blr(); return entry; }
void ovm_dd_atan2(oregister_t *l, oregister_t *r) { switch (r->t) { case t_void: goto flt; case t_word: if (r->v.w) { real(r->v.dd) = r->v.w; imag(r->v.dd) = 0.0; goto cdd; } flt: l->t = t_float; l->v.d = real(l->v.dd) >= 0.0 ? M_PI_2 : -M_PI_2; break; case t_float: if (r->v.d) { real(r->v.dd) = r->v.d; imag(r->v.dd) = 0.0; goto cdd; } goto flt; case t_mpz: real(r->v.dd) = mpz_get_d(ozr(r)); imag(r->v.dd) = 0.0; goto cdd; case t_rat: real(r->v.dd) = rat_get_d(r->v.r); imag(r->v.dd) = 0.0; goto cdd; case t_mpq: real(r->v.dd) = mpq_get_d(oqr(r)); imag(r->v.dd) = 0.0; goto cdd; case t_mpr: mpc_set_fr(occ(r), orr(r), thr_rndc); goto mpc; case t_cdd: cdd: l->v.dd = catan(l->v.dd / r->v.dd); check_cdd(l); break; case t_cqq: real(r->v.dd) = mpq_get_d(oqr(r)); imag(r->v.dd) = mpq_get_d(oqi(r)); goto cdd; case t_mpc: mpc: l->t = t_mpc; mpc_set_d_d(occ(l), real(l->v.dd), imag(l->v.dd), thr_rndc); mpc_div(occ(l), occ(l), occ(r), thr_rndc); mpc_atan(occ(l), occ(l), thr_rndc); check_mpc(l); break; default: ovm_raise(except_not_a_number); } }
void ovm_dd_div(oregister_t *l, oregister_t *r) { switch (r->t) { case t_void: l->v.dd /= 0.0; check_cdd(l); break; case t_word: l->v.dd /= r->v.w; check_cdd(l); break; case t_float: l->v.dd /= r->v.d; check_cdd(l); break; case t_mpz: l->v.dd /= mpz_get_d(ozr(r)); check_cdd(l); break; case t_rat: l->v.dd /= rat_get_d(r->v.r); check_cdd(l); break; case t_mpq: l->v.dd /= mpq_get_d(oqr(r)); check_cdd(l); break; case t_mpr: l->t = t_mpc; mpc_set_d_d(occ(l), real(l->v.dd), imag(l->v.dd), thr_rndc); mpc_set_fr(occ(r), orr(r), thr_rndc); mpc_div(occ(l), occ(l), occ(r), thr_rndc); check_mpc(l); break; case t_cdd: l->v.dd /= r->v.dd; check_cdd(l); break; case t_cqq: real(r->v.dd) = mpq_get_d(oqr(r)); imag(r->v.dd) = mpq_get_d(oqi(r)); l->v.dd /= r->v.dd; check_cdd(l); break; case t_mpc: l->t = t_mpc; mpc_set_d_d(occ(l), real(l->v.dd), imag(l->v.dd), thr_rndc); mpc_div(occ(l), occ(l), occ(r), thr_rndc); check_mpc(l); break; default: ovm_raise(except_not_a_number); } }
void ovm_q_trunc2(oregister_t *l, oregister_t *r) { switch (r->t) { case t_void: ovm_raise(except_floating_point_error); case t_word: if (r->v.w == 0) ovm_raise(except_floating_point_error); l->t = t_mpz; if (r->v.w > 0) mpz_mul_ui(ozr(r), ozs(l), r->v.w); else { mpz_set_si(ozr(r), r->v.w); mpz_mul(ozr(r), ozs(l), ozr(r)); } mpz_tdiv_q(ozr(l), ozr(l), ozr(r)); check_mpz(l); break; case t_float: ovm_trunc_d(l, mpq_get_d(oqr(l)) / r->v.d); break; case t_mpz: mpz_tdiv_q(ozr(l), ozr(l), ozr(r)); check_mpz(l); break; case t_rat: mpq_set_si(oqr(r), rat_num(r->v.r), rat_den(r->v.r)); case t_mpq: l->t = t_mpz; mpq_div(oqr(l), oqr(l), oqr(r)); mpz_tdiv_q(ozr(l), ozr(l), ozs(l)); check_mpz(l); break; case t_mpr: mpfr_set_q(orr(l), oqr(l), thr_rnd); ovm_trunc_r(l, orr(r)); break; default: ovm_raise(except_not_a_real_number); } }
void ovm_q_eq(oregister_t *l, oregister_t *r) { l->t = t_word; switch (r->t) { case t_float: l->v.w = mpq_get_d(oqr(l)) == r->v.d; break; case t_mpq: l->v.w = mpq_cmp(oqr(l), oqr(r)) == 0; break; case t_mpr: mpfr_set_q(orr(l), oqr(l), thr_rnd); l->v.w = mpfr_equal_p(orr(l), orr(r)); break; default: l->v.w = 0; break; } }
static void eval_fetch(oobject_t *p) { oregister_t *r; oobject_t v; r = &thread_main->r0; switch (r->t) { case t_void: *p = null; break; case t_word: oget_word(p); v = *p; *(oword_t *)v = r->v.w; break; case t_float: oget_float(p); v = *p; *(ofloat_t *)v = r->v.d; break; case t_rat: oget_rat(p); v = *p; *(orat_t )v = r->v.r; break; case t_mpz: oget_mpz(p); v = *p; mpz_set((ompz_t)v, ozr(r)); break; case t_mpq: oget_mpq(p); v = *p; mpq_set((ompq_t)v, oqr(r)); break; case t_mpr: oget_mpr(p); v = *p; mpfr_set((ompr_t)v, orr(r), thr_rnd); break; case t_cdd: oget_cdd(p); v = *p; *(ocdd_t *)v = r->v.dd; break; case t_cqq: oget_cqq(p); v = *p; cqq_set((ocqq_t)v, oqq(r)); break; default: assert(r->t == t_mpc); oget_mpc(p); v = *p; mpc_set((ompc_t)v, occ(r), thr_rndc); break; } }
void ovm_q_complex(oregister_t *l, oregister_t *r) { switch (r->t) { case t_void: break; case t_word: l->t = t_cqq; mpq_set_si(oqi(l), r->v.w, 1); check_cqq(l); break; case t_float: l->t = t_cdd; real(l->v.dd) = mpq_get_d(oqr(l)); imag(l->v.dd) = r->v.d; check_cdd(l); break; case t_mpz: l->t = t_cqq; mpq_set_z(oqi(l), ozr(r)); check_cqq(l); break; case t_mpq: l->t = t_cqq; mpq_set(oqi(l), oqr(r)); check_cqq(l); break; case t_mpr: l->t = t_mpc; mpfr_set_q(orr(l), oqr(l), thr_rnd); mpfr_set(ori(l), orr(r), thr_rnd); check_mpc(l); break; default: ovm_raise(except_not_a_real_number); } }
void ovm_dd_hypot(oregister_t *l, oregister_t *r) { switch (r->t) { case t_void: l->t = t_float; l->v.d = cabs(l->v.dd); break; case t_word: l->t = t_float; l->v.d = hypot(hypot(real(l->v.dd), imag(l->v.dd)), r->v.w); break; case t_float: l->t = t_float; l->v.d = hypot(hypot(real(l->v.dd), imag(l->v.dd)), r->v.d); break; case t_mpz: l->t = t_float; l->v.d = hypot(hypot(real(l->v.dd), imag(l->v.dd)), mpz_get_d(ozr(r))); break; case t_rat: l->t = t_float; l->v.d = hypot(hypot(real(l->v.dd), imag(l->v.dd)), rat_get_d(r->v.r)); break; case t_mpq: l->t = t_float; l->v.d = hypot(hypot(real(l->v.dd), imag(l->v.dd)), mpq_get_d(oqr(r))); break; case t_mpr: mpc_set_fr(occ(r), orr(r), thr_rndc); goto mpc; case t_cdd: cdd: l->t = t_float; l->v.d = hypot(hypot(real(l->v.dd), imag(l->v.dd)), hypot(real(r->v.dd), imag(r->v.dd))); break; case t_cqq: real(r->v.dd) = mpq_get_d(oqr(r)); imag(r->v.dd) = mpq_get_d(oqi(r)); goto cdd; case t_mpc: mpc: l->t = t_mpr; mpc_set_d_d(occ(l), real(l->v.dd), imag(l->v.dd), thr_rndc); mpfr_hypot(orr(l), orr(l), ori(l), thr_rnd); mpfr_hypot(ori(l), orr(r), ori(r), thr_rnd); mpfr_hypot(orr(l), orr(l), ori(l), thr_rnd); break; default: ovm_raise(except_not_a_number); } }
static void eval_setup(oregister_t *r, oobject_t v) { if (v == null) { r->t = t_void; r->v.o = null; } else { switch (r->t = otype(v)) { case t_word: r->v.w = *(oword_t *)v; break; case t_float: r->v.d = *(ofloat_t *)v; break; case t_rat: r->v.r = *(orat_t)v; break; case t_mpz: mpz_set(ozr(r), (ompz_t)v); break; case t_mpq: mpq_set(oqr(r), (ompq_t)v); break; case t_mpr: mpfr_set(orr(r), (ompr_t)v, thr_rnd); break; case t_cdd: r->v.dd = *(ocdd_t *)v; break; case t_cqq: cqq_set(oqq(r), (ocqq_t)v); break; default: assert(r->t == t_mpc); mpc_set(occ(r), (ompc_t)v, thr_rndc); break; } } }
void ovm_q_hypot(oregister_t *l, oregister_t *r) { switch (r->t) { case t_void: if (!cfg_float_format) { l->t = t_float; l->v.d = fabs(mpq_get_d(oqr(l))); } else { mpfr_set_ui(orr(r), 0, thr_rnd); goto mpr; } break; case t_word: if (!cfg_float_format) { l->t = t_float; l->v.d = hypot(mpq_get_d(oqr(l)), r->v.w); } else { mpfr_set_si(orr(r), r->v.w, thr_rnd); goto mpr; } break; case t_float: l->t = t_float; l->v.d = hypot(mpq_get_d(oqr(l)), r->v.d); break; case t_mpz: if (!cfg_float_format) { l->t = t_float; l->v.d = hypot(mpq_get_d(oqr(l)), mpz_get_d(ozr(r))); } else { mpfr_set_z(orr(r), ozr(r), thr_rnd); goto mpr; } break; case t_rat: if (!cfg_float_format) { l->t = t_float; l->v.d = hypot(mpq_get_d(oqr(l)), rat_get_d(r->v.r)); } else { mpq_set_si(oqr(r), rat_num(r->v.r), rat_den(r->v.r)); mpfr_set_q(orr(r), oqr(r), thr_rnd); goto mpr; } break; case t_mpq: if (!cfg_float_format) { l->t = t_float; l->v.d = hypot(mpq_get_d(oqr(l)), mpq_get_d(oqr(r))); } else { mpfr_set_q(orr(r), oqr(r), thr_rnd); goto mpr; } break; case t_mpr: mpr: l->t = t_mpr; mpfr_set_q(orr(l), oqr(l), thr_rnd); mpfr_hypot(orr(l), orr(l), orr(r), thr_rnd); break; case t_cdd: cdd: l->t = t_float; l->v.d = hypot(mpq_get_d(oqr(l)), hypot(real(r->v.dd), imag(r->v.dd))); break; case t_cqq: if (!cfg_float_format) { real(r->v.dd) = mpq_get_d(oqr(r)); imag(r->v.dd) = mpq_get_d(oqi(r)); goto cdd; } mpc_set_q_q(occ(r), oqr(r), oqi(r), thr_rndc); case t_mpc: l->t = t_mpr; mpc_set_q(occ(l), oqr(l), thr_rndc); mpfr_hypot(ori(l), orr(l), ori(l), thr_rnd); mpfr_hypot(orr(l), orr(r), ori(r), thr_rnd); mpfr_hypot(orr(l), ori(l), orr(l), thr_rnd); break; default: ovm_raise(except_not_a_number); } }
void ovm_q_pow(oregister_t *l, oregister_t *r) { switch (r->t) { case t_void: if (!cfg_float_format) { l->t = t_float; l->v.d = 1.0; } else { l->t = t_mpr; mpfr_set_ui(orr(l), 1, thr_rnd); } break; case t_word: if (!cfg_float_format) { l->t = t_float; l->v.d = pow(mpq_get_d(oqr(l)), r->v.w); } else { mpfr_set_si(orr(r), r->v.w, thr_rnd); goto mpr; } break; case t_float: if (mpq_sgn(oqr(l)) < 0 && finite(r->v.d) && rint(r->v.d) != r->v.d) { real(r->v.dd) = r->v.d; imag(r->v.dd) = 0.0; goto cdd; } l->t = t_float; l->v.d = pow(mpq_get_d(oqr(l)), r->v.d); break; case t_mpz: if (!cfg_float_format) { l->t = t_float; l->v.d = pow(mpq_get_d(oqr(l)), mpz_get_d(ozr(r))); } else { mpfr_set_z(orr(r), ozr(r), thr_rnd); goto mpr; } break; case t_rat: if (mpq_sgn(oqr(l)) < 0) { if (!cfg_float_format) { real(r->v.dd) = mpq_get_d(oqr(r)); imag(r->v.dd) = 0.0; goto cdd; } mpc_set_q(occ(r), oqr(r), thr_rndc); goto mpc; } else { if (!cfg_float_format) { l->t = t_float; l->v.d = pow(mpq_get_d(oqr(l)), rat_get_d(r->v.r)); } else { mpq_set_si(oqr(r), rat_num(r->v.r), rat_den(r->v.r)); mpfr_set_q(orr(r), oqr(r), thr_rnd); goto mpr; } } break; case t_mpq: if (mpq_sgn(oqr(r)) < 0) { if (!cfg_float_format) { real(r->v.dd) = mpq_get_d(oqr(r)); imag(r->v.dd) = 0.0; goto cdd; } mpc_set_q(occ(r), oqr(r), thr_rndc); goto mpc; } else { if (!cfg_float_format) { l->t = t_float; l->v.d = pow(mpq_get_d(oqr(l)), mpq_get_d(oqr(r))); } else { mpfr_set_q(orr(r), oqr(r), thr_rnd); goto mpr; } } break; case t_mpr: if (mpq_sgn(oqr(l)) < 0 && mpfr_number_p(orr(r)) && !mpfr_integer_p(orr(r))) { mpc_set_q(occ(r), oqr(r), thr_rndc); goto mpc; } mpr: l->t = t_mpr; mpfr_set_q(orr(l), oqr(l), thr_rnd); mpfr_pow(orr(l), orr(l), orr(r), thr_rnd); break; case t_cdd: cdd: l->t = t_cdd; real(l->v.dd) = mpq_get_d(oqr(l)); imag(l->v.dd) = 0.0; l->v.dd = cpow(l->v.dd, r->v.dd); check_cdd(l); break; case t_cqq: if (!cfg_float_format) { real(r->v.dd) = mpq_get_d(oqr(r)); imag(r->v.dd) = mpq_get_d(oqi(r)); goto cdd; } mpc_set_q_q(occ(r), oqr(r), oqi(r), thr_rndc); case t_mpc: mpc: l->t = t_mpc; mpc_set_q(occ(l), oqr(l), thr_rndc); mpc_pow(occ(l), occ(l), occ(r), thr_rndc); check_mpc(l); break; default: ovm_raise(except_not_a_number); } }
void ovm_q_atan2(oregister_t *l, oregister_t *r) { switch (r->t) { case t_void: if (!cfg_float_format) { l->t = t_float; l->v.d = atan2(mpq_get_d(oqr(l)), 0.0); } else { mpfr_set_ui(orr(r), 0, thr_rnd); goto mpr; } break; case t_word: if (!cfg_float_format) { l->t = t_float; l->v.d = atan2(mpq_get_d(oqr(l)), r->v.w); } else { mpfr_set_si(orr(r), r->v.w, thr_rnd); goto mpr; } break; case t_float: l->t = t_float; l->v.d = atan2(mpq_get_d(oqr(l)), r->v.d); break; case t_mpz: if (!cfg_float_format) { l->t = t_float; l->v.d = atan2(mpq_get_d(oqr(l)), mpz_get_d(ozr(r))); } else { mpfr_set_z(orr(r), ozr(r), thr_rnd); goto mpr; } break; case t_rat: if (!cfg_float_format) { l->t = t_float; l->v.d = atan2(mpq_get_d(oqr(l)), rat_get_d(r->v.r)); } else { mpq_set_si(oqr(r), rat_num(r->v.r), rat_den(r->v.r)); mpfr_set_q(orr(r), oqr(r), thr_rnd); goto mpr; } break; case t_mpq: if (!cfg_float_format) { l->t = t_float; l->v.d = atan2(mpq_get_d(oqr(l)), mpq_get_d(oqr(r))); } else { mpfr_set_q(orr(r), oqr(r), thr_rnd); goto mpr; } break; case t_mpr: mpr: mpfr_set_q(orr(l), oqr(l), thr_rnd); l->t = t_mpr; mpfr_atan2(orr(l), orr(l), orr(r), thr_rnd); break; case t_cdd: cdd: l->t = t_cdd; real(l->v.dd) = mpq_get_d(oqr(l)); imag(l->v.dd) = 0.0; l->v.dd = catan(l->v.dd / r->v.dd); check_cdd(l); break; case t_cqq: if (!cfg_float_format) { real(r->v.dd) = mpq_get_d(oqr(r)); imag(r->v.dd) = mpq_get_d(oqi(r)); goto cdd; } mpc_set_q_q(occ(r), oqr(r), oqi(r), thr_rndc); case t_mpc: l->t = t_mpc; mpc_set_q(occ(l), oqr(l), thr_rndc); mpc_div(occ(l), occ(l), occ(r), thr_rndc); mpc_atan(occ(l), occ(l), thr_rndc); check_mpc(l); break; default: ovm_raise(except_not_a_number); } }
K runtest(K opv, K ecxv, K eaxv, K edxv, K testCount) { struct MsrInOut s_pmc_reset[9]; struct MsrInOut s_pmc_read[9]; unsigned long long s_ffc_fixed[FFC_COUNT]; unsigned long long s_pmc_fixed[PMC_COUNT]; struct MsrInOut *ptr; int i; long long count; void *handle; char *error; K result; void (*execute_test)(void (s1)(void), void(s2)(void)); // dynamically load the test library handle = dlopen("libtest.so", RTLD_NOW); //handle = dlopen("libtest.so", RTLD_LAZY); if (!handle) { krr(dlerror()); // signal exception to kdb+ return (K)0; } execute_test = dlsym(handle, "execute_test"); if ((error = dlerror()) != NULL) { krr("While locating symbof 'execute_test'"); return (K)0; } // zero the fixed-cost accumulators for (i = 0 ; i < PMC_COUNT ; i++) s_pmc_fixed[i] = 0; for (i = 0 ; i < FFC_COUNT ; i++) s_ffc_fixed[i] = 0; // set the global (static) pointers ffc_fixed = s_ffc_fixed; pmc_fixed = s_pmc_fixed; pmc_reset = s_pmc_reset; pmc_read = s_pmc_read; ptr = pmc_cfg = (struct MsrInOut*)malloc((opv->n + 1) * sizeof(struct MsrInOut)); if (pmc_cfg == NULL) { orr("malloc"); return (K)0; } record_reset(); record_read(); // record the PMC instructions to memory count = opv->n; for (i = 0 ; i < count ; i++) { wr_msrio(ptr++, kI(opv)[i], kI(ecxv)[i], kI(eaxv)[i], kI(edxv)[i]); } msr_wr_stop(ptr++); loadDriver(); if (fd == -1) { return (K)0; } result = run_test(execute_test, testCount->i); // disable and zero the PMC MSRs ioctl(fd, IOCTL_MSR_CMDS, (long long)s_pmc_reset); // return the dynamically allocated memory free(pmc_cfg); // close the dyn-lib function handle dlclose(handle); // close the MSR driver closeDriver(fd); return result; }
K f(I d){ZC b[256];ZI r;S p;I s=recv(d,b+r,b+256-r,0);P(1>s,orr("")) for(s+=r,p=b;r=*p,p+r<b+s;p+=r)r0(k(0,".qs.am",kpn(++p,r),(K)0)); memmove(b,p,r=b+s-p);R 0;}