 |
 |
|
 |
|
 |
|  |
|  |
|
 |
|
 |
|  |
|  |
|
 |
Hello,
I am attempting to learn the use of Arrrays for positioning of objects.
It works, a little.
I have a [3][10] array. I wish to use all data therein by counting down with
while loops. I wish for the loop to first use all 10 values from 3, then all
ten from 2 and lastly all 10 from 1.
I can't make code to do this. I am now very irritated.
The data in the array is controlled by two while loops that surround all of
this; this part works.
It seems that no computer/programming language of any sort works as I think
it should, I can't do as I wish with arrays, loops or etc.. Everything is
too dependant.
My main problem is creation of data in a loop, storage of this data, and
retrieval for usage outside the loops the data was generated with.
I'm not sure my sourcecode will help any, but I'll post it if needed.
Suggestions?
ian
Post a reply to this message
|
 |
|  |
|  |
|
 |
|
 |
|  |
|  |
|
 |
ian mcdonald wrote:
>
> Hello,
>
> I am attempting to learn the use of Arrrays for positioning of objects.
> It works, a little.
>
> I have a [3][10] array. I wish to use all data therein by counting down with
> while loops. I wish for the loop to first use all 10 values from 3, then all
> ten from 2 and lastly all 10 from 1.
>
> I can't make code to do this. I am now very irritated.
>
> The data in the array is controlled by two while loops that surround all of
> this; this part works.
>
> It seems that no computer/programming language of any sort works as I think
> it should, I can't do as I wish with arrays, loops or etc.. Everything is
> too dependant.
>
> My main problem is creation of data in a loop, storage of this data, and
> retrieval for usage outside the loops the data was generated with.
>
> I'm not sure my sourcecode will help any, but I'll post it if needed.
>
> Suggestions?
>
> ian
// to declare the array
#declare MyArray = array[3][10] // remember :- indices [0..2][0..9]
// to initialise the array
#declare Index1 = 0; #while (Index1 < 3)
#declare Index2 = 0; #while (index2 < 10)
#declare MyAray[Index1][Index2] = Whatever_You_Want_To_Put;
#declare Index2 = Index2 + 1; #end
#declare Index1 = Index1 + 1; #end
// to read the array as specified
#declare Index1 = 2; #while (Index1 >= 0)
#declare Index2 = 9; #while (Index2 >= 0)
#declare My_Retrieved_Value = My_Array[Index1][Index2];
#declare Index2 = Index2 - 1; #end
#declare Index1 = Index1 - 1; #end
Hope this helps,
Mike Andrews.
Post a reply to this message
|
 |
|  |
|  |
|
 |
|
 |
|  |
|  |
|
 |
Source code might help (try to simplify it before posting if possible).
It would probably also help with a more precise description of what you want
to do, and what the problem is.
Greetings,
Rune
--
\ Include files, tutorials, 3D images, raytracing jokes,
/ The POV Desktop Theme, and The POV-Ray Logo Contest can
\ all be found at http://rsj.mobilixnet.dk (updated October 9)
/ Also visit http://www.povrayusers.org
Post a reply to this message
|
 |
|  |
|  |
|
 |
|
 |
|  |
|  |
|
 |
On Tue, 17 Oct 2000 12:36:23 -0700, "ian mcdonald" <ian### [at] hotmail com>
wrote:
>Hello,
>
>I am attempting to learn the use of Arrrays for positioning of objects.
>It works, a little.
>
>I have a [3][10] array. I wish to use all data therein by counting down with
>while loops. I wish for the loop to first use all 10 values from 3, then all
>ten from 2 and lastly all 10 from 1.
>
>I can't make code to do this. I am now very irritated.
>
>The data in the array is controlled by two while loops that surround all of
>this; this part works.
>
>It seems that no computer/programming language of any sort works as I think
>it should, I can't do as I wish with arrays, loops or etc.. Everything is
>too dependant.
>
>My main problem is creation of data in a loop, storage of this data, and
>retrieval for usage outside the loops the data was generated with.
>
>I'm not sure my sourcecode will help any, but I'll post it if needed.
>
>Suggestions?
>
>ian
>
#declare A1=array[3][10]
{
{"1","s","t"," "," ","A","r","r","a","y"}
{"2","n","d"," "," ","A","r","r","a","y"}
{"3","r","d"," "," ","A","r","r","a","y"}
}
#declare Rowcount = 2;
#declare Colcount = 0;
#while (Rowcount>-1)
#debug "\n"
#while (Colcount<10)
#debug concat(A1[Rowcount][Colcount])
#declare Colcount=Colcount+1;
#end
#debug "\n"
#declare Colcount=0;
#declare Rowcount = Rowcount-1;
#end
----------------------
dav### [at] hamiltonite com
http://hamiltonite.com/
Post a reply to this message
|
 |
|  |
|  |
|
 |
|
 |
|  |
|  |
|
 |
David Wilkinson wrote:
> #debug concat(A1[Rowcount][Colcount])
Why concatenate one string? :)
--
David Fontaine <dav### [at] faricy net> ICQ 55354965
My raytracing gallery: http://davidf.faricy.net/
Post a reply to this message
|
 |
|  |
|  |
|
 |
|
 |
|  |
|  |
|
 |
David Fontaine <dav### [at] faricy net> wrote:
: Why concatenate one string? :)
I have seen this written in C:
double x = (double)(1.0);
I'm just wondering why this wasn't enough:
double x = 1;
--
main(i,_){for(_?--i,main(i+2,"FhhQHFIJD|FQTITFN]zRFHhhTBFHhhTBFysdB"[i]
):_;i&&_>1;printf("%s",_-70?_&1?"[]":" ":(_=0,"\n")),_/=2);} /*- Warp -*/
Post a reply to this message
|
 |
|  |
|  |
|
 |
|
 |
|  |
|  |
|
 |
Warp wrote:
> I have seen this written in C:
> double x = (double)(1.0);
<chuckle> Who wrote that </chuckle> :)))
As far as I know most compilers convert constants at compile time.
> I'm just wondering why this wasn't enough:
> double x = 1;
Maybe they thought that the compiler would insert instructions to convert an
int to a double at runtime, unlikely though it is?
--
Bye
Pabs
Post a reply to this message
|
 |
|  |
|  |
|
 |
|
 |
|  |
|  |
|
 |
On Tue, 17 Oct 2000 16:44:34 -0500, in povray.advanced-users you wrote:
>David Wilkinson wrote:
>
>> #debug concat(A1[Rowcount][Colcount])
>
>Why concatenate one string? :)
You're right David, concatenation is absolutely redundant, although it does no
harm in this instance. It's a good example of how bugs arise when you are
re-using code and don't think it through carefully enough :-)
----------------------
dav### [at] hamiltonite com
http://hamiltonite.com/
Post a reply to this message
|
 |
|  |
|  |
|
 |
|
 |
|  |
|  |
|
 |
Pabs <pab### [at] hotmail com> wrote:
: Maybe they thought that the compiler would insert instructions to convert an
: int to a double at runtime, unlikely though it is?
Current compilers can do lots of optimizations. Some of them are even
surprising.
I was once debugging this kind of code (in C++):
int main()
{
int i = 1;
cout << i << endl;
}
It was very strange since the debugger didn't execute the 'int i=1;' line
at all and it didn't even show the value of the variable 'i'.
I thought that "what the **** is wrong with this?" until I realized that
I had all compile optimizations turned on. I turned them off and then the
debugging worked as expected.
What happened was that the optimizations made by the compiler had converted
the above code to one equivalent to this:
int main()
{
cout << 1 << endl;
}
The compiler had completely wiped out the 'i' variable and that's why the
debugging looked so strange :)
Btw, too many times I see code like this:
a = var>>2; // equivalent to: a = var/4;
The idea is that shifting is usually a lot faster than dividing so people
optimize by hand in this way.
This, however, is nowadays made in vain and makes only the code harder to
read. I'd say that every current C(++) compiler can internally optimize this:
a = var/4;
to this:
a = var>>2;
so it's not necessary to do it by hand.
Sometimes the optimizations made by a compiler are just marvelous. For
example most implementations of gcc convert this kind of code:
(var << 5)|(var >> 27);
(supposing that 'var' is an unsigned int of size 32 bits)
to this (in assembler):
rol [Variable], 5
(ie. "rotate the value [Variable] to the left 5 positions").
In C there's no operation to rotate values like in most assemblers so you
have to do it with two shifts and one or.
It's just incredible how the compiler can figure out that what you are
actually trying to do is a rotation and compiles the rather complex command
into one rotation assembler instruction (instead of two shifts and an or).
--
main(i,_){for(_?--i,main(i+2,"FhhQHFIJD|FQTITFN]zRFHhhTBFHhhTBFysdB"[i]
):_;i&&_>1;printf("%s",_-70?_&1?"[]":" ":(_=0,"\n")),_/=2);} /*- Warp -*/
Post a reply to this message
|
 |
|  |
|  |
|
 |
|
 |
|  |
|  |
|
 |
Hi Warp, you recently wrote in povray.advanced-users:
> I have seen this written in C:
>
> double x = (double)(1.0);
>
> I'm just wondering why this wasn't enough:
>
> double x = 1;
Maybe the programmer previous written that line as
DBL x = (DBL) 1.0;
and had DBL defined as float, but didn't want to add the 'f' onto the
1.0.
Then he did a global search and replace and replaced DBL with double?
- Lutz
email : lut### [at] stmuc com
Web : http://www.stmuc.com/moray
Post a reply to this message
|
 |
|  |
|  |
|
 |
|
 |
|  |
|  |
|
 |
Lutz Kretzschmar <lut### [at] stmuc com> wrote:
: Then he did a global search and replace and replaced DBL with double?
Why would he do that?
--
main(i,_){for(_?--i,main(i+2,"FhhQHFIJD|FQTITFN]zRFHhhTBFHhhTBFysdB"[i]
):_;i&&_>1;printf("%s",_-70?_&1?"[]":" ":(_=0,"\n")),_/=2);} /*- Warp -*/
Post a reply to this message
|
 |
|  |
|  |
|
 |
|
 |
|  |
|  |
|
 |
David Wilkinson wrote:
> You're right David, concatenation is absolutely redundant, although it does no
> harm in this instance. It's a good example of how bugs arise when you are
> re-using code and don't think it through carefully enough :-)
Hmm, sounds like MS...
--
David Fontaine <dav### [at] faricy net> ICQ 55354965
My raytracing gallery: http://davidf.faricy.net/
Post a reply to this message
|
 |
|  |
|  |
|
 |
|
 |
|  |
|  |
|
 |
Warp wrote:
> Pabs <pab### [at] hotmail com> wrote:
> : Maybe they thought that the compiler would insert instructions to convert an
> : int to a double at runtime, unlikely though it is?
> It's just incredible how the compiler can figure out that what you are
> actually trying to do is a rotation and compiles the rather complex command
> into one rotation assembler instruction (instead of two shifts and an or).
Ever seen the sh*t f**cking code msvc produces with no optimisations for things
like the following?
++i;
the code is something like (I'm not to proficient in assembly so don't tease)
mov eax, i
add eax, 1
mov i, eax
The side effect is what we want since the value returned by the operator is just
discarded
What a waste of clock cycles - even I could tell you that
inc i
or something similar would achieve the desired result
Just because its compiled in debug mode doesn't mean I want the code to be bloated
like a bl**dy f**cking pig.
Grrrrrrrrrrrr!
Death to M$VC & M$ - NOW
--
Bye
Pabs
Post a reply to this message
|
 |
|  |
|  |
|
 |
|
 |
|  |
|  |
|
 |
In article <39ed87d0@news.povray.org> , Warp <war### [at] tag povray org> wrote:
> (supposing that 'var' is an unsigned int of size 32 bits)
> to this (in assembler):
Ah, so you are learning assembler (variants) now...
> rol [Variable], 5
>
> (ie. "rotate the value [Variable] to the left 5 positions").
Just curious, which architecture were you compiling for here?
> In C there's no operation to rotate values like in most assemblers so you
> have to do it with two shifts and one or.
Yes, and there are many more tricks:
main:
addi $0, $0, 10
addi $1, $1, 15
andi $2, $2, 0
andi $3, $3, 0
for:
andi $2, $2, 0
beq $0, $2, ret
srl1 $0, $0
sll1 $1, $1
andi $2, $0, 1
subi $2, $2, 1
not $2, $2
and $2, $1, $2
add $3, $3, $2
j for
ret:
j ret
Assume j is a unconditional jump, and srl1/sll1 are logical right/left
shifts by one bit. Further assume all values are unsigned 8 bit ints. $0
to $3 are registers (MIPS assembly notation), your input is in $0 and $1,
and the result is in $2.
What is this program doing?
Thorsten
____________________________________________________
Thorsten Froehlich, Duisburg, Germany
e-mail: tho### [at] trf de
Visit POV-Ray on the web: http://mac.povray.org
Post a reply to this message
|
 |
|  |
|  |
|
 |
|
 |
|  |
|  |
|
 |
In article <39EE5D5E.CCAB2069@hotmail.com> , Pabs <pab### [at] hotmail com>
wrote:
> Ever seen the sh*t f**cking code msvc produces with no optimisations for
> things like the following?
> ++i;
Maybe it is optimising, but in a different way than you expect. On the one
hand "i" might be needed somewhere else and inc i could only work on
register variables (sorry, I don't know x86 assembler too well). This doing
either would give the same performance. Especially if "i" is stored in a
rather complicated place or only used once, or a global variable, or a
million other things.
Or it might well be that the sequence it generates executes faster on modern
processors that translate your code to internal RISC-like instructions (like
P6 and later do). Why come to this conclusion?
Well, what you see is a load/store (i.e. most RISC processors) way of
handling the problem. Basically a load/store architecture based processor
will not have complex operations that work on memory and data at the same
time. Everything first has to be loaded into a register, then it will be
processed and then placed back in memory. This is usually more efficient
because these processors have much larger register files, 32 or even 64
registers compared to the 8 registers a x86 has.
Thorsten
____________________________________________________
Thorsten Froehlich, Duisburg, Germany
e-mail: tho### [at] trf de
Visit POV-Ray on the web: http://mac.povray.org
Post a reply to this message
|
 |
|  |
|  |
|
 |
|
 |
|  |
|  |
|
 |
In article <39ee868d$1@news.povray.org> , "Thorsten Froehlich"
<tho### [at] trf de> wrote:
> and the result is in $2.
Correction: the result is in $3 or cousre. And btw, you may assume all
registers are inited to 0.
____________________________________________________
Thorsten Froehlich, Duisburg, Germany
e-mail: tho### [at] trf de
Visit POV-Ray on the web: http://mac.povray.org
Post a reply to this message
|
 |
|  |
|  |
|
 |
|
 |
|  |
|  |
|
 |
Thorsten Froehlich <tho### [at] trf de> wrote:
: Maybe it is optimising, but in a different way than you expect. On the one
: hand "i" might be needed somewhere else and inc i could only work on
: register variables (sorry, I don't know x86 assembler too well).
The 'inc' instruction works also directly with memory locations
(ie. variables) but is slower than an 'inc' on a register. But of course
loading the variable first on a register, incrementing the register and
then storing the register on the variable is not faster (it's actually slower,
I think).
And besides, if it's not optimizing (as the original poster said), it
should generate the simplest code, not the fastest.
--
main(i,_){for(_?--i,main(i+2,"FhhQHFIJD|FQTITFN]zRFHhhTBFHhhTBFysdB"[i]
):_;i&&_>1;printf("%s",_-70?_&1?"[]":" ":(_=0,"\n")),_/=2);} /*- Warp -*/
Post a reply to this message
|
 |
|  |
|  |
|
 |
|
 |
|  |
|  |
|
 |
Thorsten Froehlich <tho### [at] trf de> wrote:
: Just curious, which architecture were you compiling for here?
Sparc.
The assembler instruction I wrote in my article was fictitious
(pseudo-assembler). It's not Sparc assembler.
: What is this program doing?
No idea.
A wild guess: Either a multiplication or a division?
--
main(i,_){for(_?--i,main(i+2,"FhhQHFIJD|FQTITFN]zRFHhhTBFHhhTBFysdB"[i]
):_;i&&_>1;printf("%s",_-70?_&1?"[]":" ":(_=0,"\n")),_/=2);} /*- Warp -*/
Post a reply to this message
|
 |
|  |
|  |
|
 |
|
 |
|  |
|  |
|
 |
On 19 Oct 2000 03:59:13 -0400, Warp wrote:
>Thorsten Froehlich <tho### [at] trf de> wrote:
>: Maybe it is optimising, but in a different way than you expect. On the one
>: hand "i" might be needed somewhere else and inc i could only work on
>: register variables (sorry, I don't know x86 assembler too well).
>
> The 'inc' instruction works also directly with memory locations
>(ie. variables) but is slower than an 'inc' on a register. But of course
>loading the variable first on a register, incrementing the register and
>then storing the register on the variable is not faster (it's actually slower,
>I think).
It might pipeline better.
> And besides, if it's not optimizing (as the original poster said), it
>should generate the simplest code, not the fastest.
If it's not optimizing, it's not checking to see whether the result of
the calculation is used, so it always computes it.
--
Ron Parker http://www2.fwi.com/~parkerr/traces.html
My opinions. Mine. Not anyone else's.
Post a reply to this message
|
 |
|  |
|  |
|
 |
|
 |
|  |
|  |
|
 |
Ron Parker <ron### [at] povray org> wrote:
: It might pipeline better.
AFAIK instructions that handle the same register can't be executed in
different pipelines at the same time (at least this in a Pentium).
--
main(i,_){for(_?--i,main(i+2,"FhhQHFIJD|FQTITFN]zRFHhhTBFHhhTBFysdB"[i]
):_;i&&_>1;printf("%s",_-70?_&1?"[]":" ":(_=0,"\n")),_/=2);} /*- Warp -*/
Post a reply to this message
|
 |
|  |
|  |
|
 |
|
 |
|  |
|  |
|
 |
Hi Warp, you recently wrote in povray.advanced-users:
> Why would he do that?
Because he found that float was not precise enough?
- Lutz
email : lut### [at] stmuc com
Web : http://www.stmuc.com/moray
Post a reply to this message
|
 |
|  |
|  |
|
 |
|
 |
|  |
|  |
|
 |
On 19 Oct 2000 09:22:29 -0400, Warp wrote:
>Ron Parker <ron### [at] povray org> wrote:
>: It might pipeline better.
>
> AFAIK instructions that handle the same register can't be executed in
>different pipelines at the same time (at least this in a Pentium).
That's probably true, but a load-modify-store sequence might be more easily
run in parallel with another such sequence. Of course, if that's the case,
they would have microcoded inc as such a sequence. I suspect the real
reason your compiler built it that way is the second reason I gave.
--
Ron Parker http://www2.fwi.com/~parkerr/traces.html
My opinions. Mine. Not anyone else's.
Post a reply to this message
|
 |
|  |
|  |
|
 |
|
 |
|  |
|  |
|
 |
In article <39eeabab@news.povray.org> , Warp <war### [at] tag povray org> wrote:
> Sparc.
> The assembler instruction I wrote in my article was fictitious
> (pseudo-assembler). It's not Sparc assembler.
OK. I was asking because I was interested if Sparc supports rotations in
hardware.
> : What is this program doing?
>
> No idea.
> A wild guess: Either a multiplication or a division?
Good guess, it is a multiplication. It plays around with bit patterns and
overflows to be able to accomplish the result in only 4 registers.
Thorsten
PS: Division (recursive) could look like this ...
addi $3, $3, 4
addi $1, $1, 47
sw $1, 0($0)
sw $0, 1($3)
addi $1, $0, 10
sw $1, 2($3)
addi $1, $0, 1
sw $1, 3($3)
jal $1, sub
lw $1, 0($3)
lw $2, 1($3)
lw $2, 0($2)
wait:
j wait
sub:
sw $1, 4($3)
lw $1, 2($3)
subi $2, $0, 1
beq $1, $0, ret
lw $2, 1($3)
lw $2, 0($2)
slt $2, $2, $1
subi $2, $2, 1
beq $2, $0, ret
lw $2, 1($3)
sw $2, 6($3)
lw $2, 2($3)
sll1 $2, $2
sw $2, 7($3)
lw $2, 3($3)
sll1 $2, $2
sw $2, 8($3)
addi $3, $3, 5
jal $1, sub
subi $3, $3, 5
lw $2, 5($3)
sw $2, 0($3)
lw $1, 2($3)
lw $2, 1($3)
lw $2, 0($2)
slt $2, $2, $1
bne $2, $0, ret_now
lw $2, 1($3)
lw $2, 0($2)
sub $2, $2, $1
lw $1, 1($3)
sw $2, 0($1)
lw $2, 0($3)
lw $1, 3($3)
or $2, $2, $1
ret:
sw $2, 0($3)
ret_now:
lw $1, 4($3)
jr $1
// calculates x / y
int sub(int *x, int y, int cnt);
int main()
{
int x = 47;
cout << sub(&x, 4, 1) << "\n";
cout << x << "\n";
return 0;
}
int sub(int *x, int y, int cnt)
{
int temp;
if(y == 0)
return -1;
if(*x < y)
return 0;
temp = sub(x, y << 1, cnt << 1);
if(*x >= y)
{
*x -= y;
temp |= cnt;
}
return temp;
}
Post a reply to this message
|
 |
|  |
|  |
|
 |
|
 |
|  |
|  |
|
 |
First my apologies to the group for not responding in two days. I have been
working and not much else. I now know what 1,200mg of caffine does to the
human body. : (
I discovered my problem when I read Michael Andrews post, telling me that
the arrray is not as one would expect. I thought having an array of [N][N]
would mean I had an array of that precise size, and not [N-1][N-1].
That was my entire problem. Povray did not like the fact that I was calling
the array with the values it was defined with. My loops went from 3 to 1 and
10 to 1, not 2 to 0 and 9 to 0.
My thanks to the group for your help.
ian
Michael Andrews <M.C### [at] reading ac uk> wrote in message
news:39EC99EF.283EA738@reading.ac.uk...
Post a reply to this message
|
 |
|  |
|  |
|
 |
|
 |
|  |
|  |
|
 |
Lutz Kretzschmar <lut### [at] stmuc com> wrote:
:> Why would he do that?
: Because he found that float was not precise enough?
Wouldn't a
typedef double DBL;
be better and easier to do?
--
main(i,_){for(_?--i,main(i+2,"FhhQHFIJD|FQTITFN]zRFHhhTBFHhhTBFysdB"[i]
):_;i&&_>1;printf("%s",_-70?_&1?"[]":" ":(_=0,"\n")),_/=2);} /*- Warp -*/
Post a reply to this message
|
 |
|  |
|  |
|
 |
|
 |
|  |
|  |
|
 |
Hi Warp, you recently wrote in povray.advanced-users:
> typedef double DBL;
Yes, it would, I guess. Your guess is as good as mine about why
someone would write the example you quoted in the first place, you
certainly wouldn't find a construct like that in my code <g>......
- Lutz
email : lut### [at] stmuc com
Web : http://www.stmuc.com/moray
Post a reply to this message
|
 |
|  |
|  |
|
 |
|
 |
|  |
|  |
|
 |
For things like this, look at:
http://web2.airmail.net/~sjbaker1/software/horrors.html
--
main(i,_){for(_?--i,main(i+2,"FhhQHFIJD|FQTITFN]zRFHhhTBFHhhTBFysdB"[i]
):_;i&&_>1;printf("%s",_-70?_&1?"[]":" ":(_=0,"\n")),_/=2);} /*- Warp -*/
Post a reply to this message
|
 |
|  |
|  |
|
 |
|
 |
|  |
|
 |