void LIRGenerator::do_AttemptUpdate(Intrinsic* x) {
  assert(x->number_of_arguments() == 3, "wrong type");
  LIRItem obj       (x->argument_at(0), this);  // AtomicLong object
  LIRItem cmp_value (x->argument_at(1), this);  // value to compare with field
  LIRItem new_value (x->argument_at(2), this);  // replace field with new_value if it matches cmp_value

  // compare value must be in rdx,eax (hi,lo); may be destroyed by cmpxchg8 instruction
  cmp_value.load_item_force(FrameMap::long0_opr);

  // new value must be in rcx,ebx (hi,lo)
  new_value.load_item_force(FrameMap::long1_opr);

  // object pointer register is overwritten with field address
  obj.load_item();

  // generate compare-and-swap; produces zero condition if swap occurs
  int value_offset = sun_misc_AtomicLongCSImpl::value_offset();
  LIR_Opr addr = new_pointer_register();
  __ leal(LIR_OprFact::address(new LIR_Address(obj.result(), value_offset, T_LONG)), addr);
  LIR_Opr t1 = LIR_OprFact::illegalOpr;  // no temp needed
  LIR_Opr t2 = LIR_OprFact::illegalOpr;  // no temp needed
  __ cas_long(addr, cmp_value.result(), new_value.result(), t1, t2);

  // generate conditional move of boolean result
  LIR_Opr result = rlock_result(x);
  __ cmove(lir_cond_equal, LIR_OprFact::intConst(1), LIR_OprFact::intConst(0), result, T_LONG);
}
Exemple #2
0
bool etype::operator==(const etype &var) const
{
  if (type == var.type && cmp_value(var.value))
    return(true);
  else if (type == ET_ESTR)
    return( *(estr*)value == var.s() );
  else if (var.type == ET_ESTR)
    return( s() == *(estr*)var.value );
  else if (type == ET_EARRAY || var.type == ET_EARRAY)
    return(false);
  else{
    switch(type){
      case ET_INT: return( s() == var.s() );
      case ET_FLOAT: return( *(float*)value == var.f() );
      case ET_DOUBLE: return( *(double*)value == var.d() );
      case ET_CHAR: return( *(char*)value == var.c() );
    }
  }

  return(false);
}
void LIRGenerator::do_AttemptUpdate(Intrinsic* x) {
  assert(x->number_of_arguments() == 3, "wrong type");
  LIRItem obj       (x->argument_at(0), this);  // AtomicLong object
  LIRItem cmp_value (x->argument_at(1), this);  // value to compare with field
  LIRItem new_value (x->argument_at(2), this);  // replace field with new_value if it matches cmp_value

  obj.load_item();
  cmp_value.load_item();
  new_value.load_item();

  // generate compare-and-swap and produce zero condition if swap occurs
  int value_offset = sun_misc_AtomicLongCSImpl::value_offset();
  LIR_Opr addr = FrameMap::O7_opr;
  __ add(obj.result(), LIR_OprFact::intConst(value_offset), addr);
  LIR_Opr t1 = FrameMap::G1_opr;  // temp for 64-bit value
  LIR_Opr t2 = FrameMap::G3_opr;  // temp for 64-bit value
  __ cas_long(addr, cmp_value.result(), new_value.result(), t1, t2);

  // generate conditional move of boolean result
  LIR_Opr result = rlock_result(x);
  __ cmove(lir_cond_equal, LIR_OprFact::intConst(1), LIR_OprFact::intConst(0), result);
}
Exemple #4
0
void SenCmp02::run() {

	char buffer[256];
	int wait_freq = update_rate? 1000000 / update_rate: 0;
	int wait_time = wait_freq;

	uint64_t frequency = wait_time;
	uint64_t start = get_time_us();
	uint64_t time_output = start + 1000000;
	uint64_t usec;
	vector<uint16_t> cmp_value(2);
	//mavlink_message_t msg;

	Logger::log("Cmp02: running (Hz)", update_rate, Logger::LOGLEVEL_INFO);
	// uint64_t end = getTimeUs() + 1000000;

	status = RUNNING;

	while((status == RUNNING) && update_rate) {
		try {

			/* wait time */
			usec = get_time_us();
			uint64_t end = usec;
			wait_time = wait_freq - (end - start);
			wait_time = (wait_time < 0)? 0: wait_time;
		
			/* wait */
			usleep(wait_time);
			//usleep(10);

			/* calculate frequency */
			end = get_time_us();
			frequency = (15 * frequency + end - start) / 16;
			start = end;

			// Logger::log("sencmp2: pre i2c_start_conversion", Logger::LOGLEVEL_DEBUG);
			i2c_start_conversion(fd, CMP02_ADR);

			// set read register
			buffer[0] = 0x00;
			// Logger::log("sencmp2: pre i2c_write_bytes", Logger::LOGLEVEL_DEBUG);
			i2c_write_bytes(fd, (uint8_t*)buffer, 1);

			// read data
			// Logger::log("sencmp2: pre i2c_read_bytes", Logger::LOGLEVEL_DEBUG);
			i2c_read_bytes(fd, (uint8_t*)buffer, 1);

			// get version
			version = *buffer;

			// Logger::log("Cmp02: version", (int)version, Logger::LOGLEVEL_INFO);

			buffer[0] = 0x01;
			// Logger::log("sencmp2: pre i2c_write_bytes 2", Logger::LOGLEVEL_DEBUG);
			i2c_write_bytes(fd, (uint8_t*)buffer, 1);
			// Logger::log("sencmp2: pre i2c_read_bytes 2", Logger::LOGLEVEL_DEBUG);
			i2c_read_bytes(fd, (uint8_t*)buffer, 1);
			
			// Logger::log("sencmp2: pre i2c_end_conversion", Logger::LOGLEVEL_DEBUG);
			i2c_end_conversion(fd);

			// get values
			memcpy(&cmp_value[0], buffer, 1);

			// Logger::log("Cmp02: value", (int)cmp_value[0], Logger::LOGLEVEL_INFO);

			// FIXME: smart++
			// exp_ctrl_rx_data.value0 = cmp_value[0];
			// exp_ctrl_rx_data.value1 = cmp_value[1];
			// exp_ctrl_rx_data.value2 = cmp_value[2];
			// exp_ctrl_rx_data.value3 = cmp_value[3];

			// FIXME: kopter specific mapping
			// FIXME: 0 is USS
			// huch_ranger.ranger2 = cmp_value[2];
			// huch_ranger.ranger3 = cmp_value[0];

			// home / qk01
			// huch_ranger.ranger2 = cmp_value[0];
			// huch_ranger.ranger3 = cmp_value[1];

			/* assign buffer to data */
#ifdef MAVLINK_ENABLED_HUCH
			{ // begin of data mutex scope
				int i;
				cpp_pthread::Lock ri_lock(data_mutex);
				for(i=0; i < CMP02_NUMCHAN; i++) {
					sensor_data[i].analog = cmp_value[i];
					sensor_data[i].usec = start;
					// Logger::log("Cmp02 sensor:", i, sensor_data[i].analog, Logger::LOGLEVEL_INFO);
				}
			} // end of data mutex scope
#endif // MAVLINK_ENABLED_HUCH
	
			// FIXME: if(publish) else poll or whatever
			publish_data(start);

			//Logger::log("Cmp02:", (int)exp_ctrl_rx_data.version, cmp_value, Logger::LOGLEVEL_INFO);
			//Logger::log("Cmp02:", DataCenter::get_sensor(chanmap[0]), Logger::LOGLEVEL_INFO);

			// pass more data
			// FIXME: system_id
			// mavlink_msg_huch_exp_ctrl_rx_encode(39, static_cast<uint8_t>(component_id), &msg, &exp_ctrl_rx_data);

			/* debug data */
			if (debug) print_debug();

			/* timings/benchmark output */
			if (timings) {
				if (time_output <= end) {
					Logger::log("Cmp02 frequency: ", (float)1000000/frequency, Logger::LOGLEVEL_DEBUG);
					time_output += 1000000;
				}
			}
		} // end try
		catch(const char *message) {
			i2c_end_conversion(fd);
			status = STRANGE;

			string s(message);
			Logger::log("sencmp2: would-be exception:", s, Logger::LOGLEVEL_DEBUG);
			// fallback termination and free bus
			i2c_end_conversion(fd);
			Logger::log("sencmp2: would-be exception:", s, Logger::LOGLEVEL_DEBUG);

			// FIXME: throw and exit on "write_bytes 2"
			// throw ("Cmp02::run(): " + s).c_str();
			status = RUNNING;
		}
	} // end while

	Logger::debug("sencmp02: stopped, exiting run()");
	return;
}