POV-Ray : Newsgroups : povray.advanced-users : Bitwise operators corrupting SDL parse-time execution of POV-Ray? Server Time
21 Nov 2024 12:15:05 EST (-0500)
  Bitwise operators corrupting SDL parse-time execution of POV-Ray? (Message 1 to 6 of 6)  
From: Bald Eagle
Subject: Bitwise operators corrupting SDL parse-time execution of POV-Ray?
Date: 3 Feb 2023 17:35:00
Message: <web.63dd8ba6afaac3401f9dae3025979125@news.povray.org>
So, I wanted to play around with quickly accessing data in an array, and figured
I could use a hash function to calculate semi-unique array indices.

I made a stab at converting c++ code from here:

http://www.azillionmonkeys.com/qed/hash.html

and just made some naive assumptions about some of the memory-location specific
operations, but I think I got the rest of it correct.

Then something interesting happened.

I tried to run a loop to process a series of input values, but my loop only
executed one iteration.

I then sent the value of my iterator to the #debug stream after the loop exited,
and it's greater than my maximum/exit value!

Perhaps someone could verify this behaviour on their machine/OS and look over my
conversion of c++ to SDL and see if something crazy is happening.
Am I writing to a memory location by using bitwise operators in SDL?

If so: WHOA.

Scene file is attached.

- Bald "POV-Ray breaker" Eagle


Post a reply to this message


Attachments:
Download 'superfasthash.pov.txt' (5 KB)

From: Cousin Ricky
Subject: Re: Bitwise operators corrupting SDL parse-time execution of POV-Ray?
Date: 3 Feb 2023 18:43:34
Message: <63dd9c26$1@news.povray.org>
On 2023-02-03 18:33 (-4), Bald Eagle wrote:
> 
> I tried to run a loop to process a series of input values, but my loop only
> executed one iteration.
> 
> I then sent the value of my iterator to the #debug stream after the loop exited,
> and it's greater than my maximum/exit value!

If you pass an identifier as a macro argument, POV-Ray treats it as
pass-by-reference.  Macro SuperFastHash() makes assignments to its
arguments, data and len.  This hoses your loop counter i during the
first call to SuperFastHash().

You can fix this by assigning data and len to new local variables within
SuperFastHash(), and using only those new variables.


Post a reply to this message

From: Bald Eagle
Subject: Re: Bitwise operators corrupting SDL parse-time execution of POV-Ray?
Date: 3 Feb 2023 19:15:00
Message: <web.63dda2a9835744611f9dae3025979125@news.povray.org>
Cousin Ricky <ric### [at] yahoocom> wrote:

> You can fix this by assigning data and len to new local variables within
> SuperFastHash(), and using only those new variables.

UGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGH!

I got snookered by this *AGAIN* !!!

Thank you, Richard.
jr and I grappled with this maddening behaviour before, but I forgot   :(

Any idea if I can modify the code to only give positive results?
Bitshift to the right by one position to clean the sign bit?


Post a reply to this message

From: jr
Subject: Re: Bitwise operators corrupting SDL parse-time execution of POV-Ray?
Date: 4 Feb 2023 03:05:00
Message: <web.63de10cc8357446188a828ca6cde94f1@news.povray.org>
hi,

"Bald Eagle" <cre### [at] netscapenet> wrote:
> Cousin Ricky <ric### [at] yahoocom> wrote:
>
> > You can fix this by assigning data and len to new local variables within
> > SuperFastHash(), and using only those new variables.

alternatively, you could invoke the macro as 'SuperFastHash (i, 0 + 10)'. the
expression forcing POV-Ray to pass in a value.


regards, jr.


Post a reply to this message

From: jr
Subject: Re: Bitwise operators corrupting SDL parse-time execution of POV-Ray?
Date: 4 Feb 2023 03:35:00
Message: <web.63de17af8357446188a828ca6cde94f1@news.povray.org>
"jr" <cre### [at] gmailcom> wrote:

early morning crap..


> ...
> alternatively, you could invoke the macro as 'SuperFastHash (i, 0 + 10)'. the
> expression forcing POV-Ray to pass in a value.

tja, did not look at the code, close enough and/or in time :-(

so the '#for (loop, len, 0, -1)' needs to be re arranged, as per docs: '#for
(Identifier, Start, End [, Step])'.


regards, jr.


Post a reply to this message

From: Cousin Ricky
Subject: Re: Bitwise operators corrupting SDL parse-time execution of POV-Ray?
Date: 4 Feb 2023 13:29:41
Message: <63dea415$1@news.povray.org>
On 2023-02-04 04:01 (-4), jr wrote:
>> Cousin Ricky <ric### [at] yahoocom> wrote:
>>
>>> You can fix this by assigning data and len to new local variables within
>>> SuperFastHash(), and using only those new variables.
> 
> alternatively, you could invoke the macro as 'SuperFastHash (i, 0 + 10)'. the
> expression forcing POV-Ray to pass in a value.

It would have to be 'SuperFastHash (i + 0, 10)', if you choose to do it
that way.  But I prefer not requiring the caller to babysit the macro.


Post a reply to this message

Copyright 2003-2023 Persistence of Vision Raytracer Pty. Ltd.