To LUGNET HomepageTo LUGNET News HomepageTo LUGNET Guide Homepage
 Help on Searching
 
Post new message to lugnet.robotics.rcx.nqcOpen lugnet.robotics.rcx.nqc in your NNTP NewsreaderTo LUGNET News Traffic PageSign In (Members)
 Robotics / RCX / NQC / 161
  Re: NQC 2.0 and some math questions
 
A bug in the document. * and / are legal for any expressions. % is restricted to constants. I know the restrictions are confusing. The problem is that the RCX opcodes are somewhat incomplete. Now that I think about it, I can probably generate (...) (25 years ago, 23-Sep-99, to lugnet.robotics.rcx.nqc)
 
  Re: NQC 2.0 and some math questions
 
(...) x = y % z is equivalent to (where w is an temporary integer): w = y / z; x = y - z * w; I can't think of a useful use of % just with constants. Ciao. Marco. (25 years ago, 29-Sep-99, to lugnet.robotics.rcx.nqc)
 
  Re: NQC 2.0 and some math questions
 
(...) That's exaclty what I was thinking of doing. Originally, the compiler had no way of allocating temp variables which is why code for % couldn't be emitted. The temp allocator is now pretty good, so I could emit the above sequence, but it just (...) (25 years ago, 30-Sep-99, to lugnet.robotics.rcx.nqc)
 
  Re: NQC 2.0 and some math questions
 
(...) I think that if you do something like this you should use a semaphore to secure no tasks access y and z simultanously. But that wastes another variable storing the sema. (25 years ago, 30-Sep-99, to lugnet.robotics.rcx.nqc)
 
  Re: NQC 2.0 and some math questions
 
On semaphores... There was a lot of discussion a long time ago on whether NQC should use semaphores to protect temp variables between tasks. There isn't an atomic test-and-set bytecode, so the only way I know of implementing sempaphore would be to (...) (25 years ago, 1-Oct-99, to lugnet.robotics.rcx.nqc)
 
  Re: NQC 2.0 and some math questions
 
(...) There is a way to do it even if you have no test and set, though I can't remember it off the top of my head, and it is slow. Don't see how using bitflags helps? Cheers, Ben. -- (URL) grandfather once told me that there are two kinds of people: (...) (25 years ago, 1-Oct-99, to lugnet.robotics.rcx.nqc)
 
  Re: NQC 2.0 and some math questions
 
(...) I'm going from memory here, so I may miss a detail... int lock; #define TASK_BIT(task_num) (1 << task_num) void acquire_lock(int task_num) { while(1) { // wait for lock to be clear while(lock); // try to own it lock |= TASK_BIT(task_num); // (...) (25 years ago, 2-Oct-99, to lugnet.robotics.rcx.nqc)
 
  Re: NQC 2.0 and some math questions
 
Your proposed solution is susceptible to the "lockstep starvation" problem. Lockstep starvation happens when two tasks try to get the lock at the same time and execute the same code in lock step, like so: task 1: lock |= 2; task 2: lock |= 4; task (...) (25 years ago, 2-Oct-99, to lugnet.robotics.rcx.nqc)
 
  Re: NQC 2.0 and some math questions
 
(...) This only works if |= is atomic, though. Is it? Cheers, Ben. -- (URL) grandfather once told me that there are two kinds of people: those who work and those who take the credit. He told me to try to be in the first group; there was less (...) (25 years ago, 2-Oct-99, to lugnet.robotics.rcx.nqc)
 
  Re: NQC 2.0 and some math questions
 
(...) Yes, |= is atomic. At the bytecode level you always OR from some source into a destination variable. Dave (25 years ago, 2-Oct-99, to lugnet.robotics.rcx.nqc)
 
  Re: NQC 2.0 and some math questions
 
(...) You're right - I forgot the delay (that's what I get for typing code from memory). Yeah, 'test and set' is the best solution, but unfortunately the RCX doesn't have one. The bitflag stuff is a little ugly for my tastes, which is why NQC does (...) (25 years ago, 2-Oct-99, to lugnet.robotics.rcx.nqc)
 
  Sharing variables and using expressions (was Re: NQC 2.0 and some math questions
 
I have discovered a somewhat non-intuitive feature of NQC (in my version, at least, which is pre-2.0) The statement: var = (20 * var) / 21; gets compiled into the following: MUL var, 20 ; var = var * 20 DIV var, 21 ; var = var / 21 rather than the (...) (25 years ago, 19-Oct-99, to lugnet.robotics.rcx.nqc)
 
  Re: Sharing variables and using expressions (was Re: NQC 2.0 and some math questions
 
The optimization was intentional (and quite a lot of work, actually). I know it breaks with multiple tasks, but I was more concerned with keeping the variable pool from being cluttered with temporaries. With only 32 vars to use, its quite easy to (...) (25 years ago, 20-Oct-99, to lugnet.robotics.rcx.nqc)
 
  Re: Sharing variables and using expressions (was Re: NQC 2.0 and some math questions
 
(...) I appreciate this -- that's what the "Not Quite" is all about. As long as you explain things well, I think this kind of compromise is the right way. (25 years ago, 20-Oct-99, to lugnet.robotics.rcx.nqc)
 
  Re: Sharing variables and using expressions (was Re: NQC 2.0 and some math questions
 
Thanks, Dave! It will be good to have that in the manual, because it is a very confusing behavior that is difficult to track down. Variables take on values that are completely different from the values that the programmer is setting them to. Most (...) (25 years ago, 1-Nov-99, to lugnet.robotics.rcx.nqc)

©2005 LUGNET. All rights reserved. - hosted by steinbruch.info GbR