Subject:
|
Re: NQC 2.0 and some math questions
|
Newsgroups:
|
lugnet.robotics.rcx.nqc
|
Date:
|
Thu, 30 Sep 1999 06:01:04 GMT
|
Viewed:
|
2262 times
|
| |
| |
In article <37f16547.6612368@lugnet.com>, marcob@equalis.it wrote:
> x = y % z
>
> is equivalent to (where w is an temporary integer):
>
> w = y / z;
> x = y - z * w;
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 didn't occur to me until a few days ago.
There is one subtle problem. The operations above won't happen
atomically, so there are some concurrency issues. To be completely safe,
I'd have to latch both y and z into temps as well. Without this, some
truly weird stuff can happen. For example, lets say that intially y is a
multiple of z, and then you decrement y in-between the computation of w
and x. The result will be that x is negative. This is a result that is
inconsistient with the decrement happening either before or after the
entire mod calculation.
My personal feeling on this, however, is that if you're running around
changing y amd z in one task while calculating with them in another,
you're just asking for trouble.
Dave Baum
--
reply to: dbaum at enteract dot com
|
|
Message has 2 Replies:
Message is in Reply To:
16 Messages in This Thread:
- Entire Thread on One Page:
- Nested:
All | Brief | Compact | Dots
Linear:
All | Brief | Compact
This Message and its Replies on One Page:
- Nested:
All | Brief | Compact | Dots
Linear:
All | Brief | Compact
|
|
|
|