Glenn McAllister | 2 Mar 17:05
Favicon

exponent and modulus operator oddities on ppc

We've been having some odd problems with the exponent operator ('^') and 
modulus operator ('%') on our PowerPC deployment environment; this issue 
doesn't exist on our x86 development environment.  We cross compile on 
x86 to the ppc target.

The tombstone data is:

Lua: 5.1.3

Make:
   make -C src MYCFLAGS="-DLUA_USE_POSIX -DLUA_USE_DLOPEN" 
MYLIBS="-Wl,-E -ldl -lncurses" all

Make Output:

powerpc-linux-gcc -O2 -Wall -DLUA_USE_POSIX -DLUA_USE_DLOPEN   -c -o 
lapi.o lapi.c
powerpc-linux-gcc -O2 -Wall -DLUA_USE_POSIX -DLUA_USE_DLOPEN   -c -o 
lcode.o lcode.c
powerpc-linux-gcc -O2 -Wall -DLUA_USE_POSIX -DLUA_USE_DLOPEN   -c -o 
ldebug.o ldebug.c

<snip/>

Host: ppc 32-bit

Given the following script, it produces the correct results on both x86 
and ppc:

  y = 2^3
(Continue reading)

Ralph Hempel | 2 Mar 17:55

Re: exponent and modulus operator oddities on ppc

Glenn McAllister wrote:
> We've been having some odd problems with the exponent operator ('^') and 

<snip>

> Host: ppc 32-bit
> 
> Given the following script, it produces the correct results on both x86 
> and ppc:
> 
>  y = 2^3
>  print('y = ', y)
> 
>  x = 10 % y
>  print('x = ', x)
> 
>  y = 2^3
>  print('y = ', y)
> 
> The output on both platforms is:
> 
>  y =     8
>  x =     2
>  y =     8
> 
> However, if we run the morally equivalent series of operations directly 
> in the lua interpreter on the target ppc system, we get a different result:
> 
>  Lua 5.1.3  Copyright (C) 1994-2008 Lua.org, PUC-Rio
>  > x = 2^3
(Continue reading)

Glenn McAllister | 2 Mar 18:09
Favicon

Re: exponent and modulus operator oddities on ppc

Ralph Hempel wrote:
> Glenn McAllister wrote:
>> We've been having some odd problems with the exponent operator ('^') and 
> 
> <snip>
> 
>> Host: ppc 32-bit
>>
>> Given the following script, it produces the correct results on both 
>> x86 and ppc:
>>
>>  y = 2^3
>>  print('y = ', y)
>>
>>  x = 10 % y
>>  print('x = ', x)
>>
>>  y = 2^3
>>  print('y = ', y)
>>
>> The output on both platforms is:
>>
>>  y =     8
>>  x =     2
>>  y =     8
>>
>> However, if we run the morally equivalent series of operations 
>> directly in the lua interpreter on the target ppc system, we get a 
>> different result:
>>
(Continue reading)

Ralph Hempel | 2 Mar 18:18

Re: exponent and modulus operator oddities on ppc

Glenn McAllister wrote:

>> What happens if you run the "morally equivalent" script from a file?
> 
> Sorry, I had changed around some of the variable for the interactive 
> session to show that its any assignment of 2^3 that triggers the issue, 
> and not just resetting y.
> 
> If I change the script to:
> 
>  x = 2^3
>  print('x = ', x)
> 
>  y = 10 % x
>  print('y = ', y)
> 
>  z = 2^3
>  print('z = ', z)
> 
> I get the expected output:
> 
>  x =     8
>  y =     2
>  z =     8

OK, so running from a script seems to work. So far so good.

> Its z = 2^3, which should have the value of 8.  So I'm using constants, 
> not the variable.
> 
(Continue reading)

Ralph Hempel | 2 Mar 18:20

Re: exponent and modulus operator oddities on ppc

Glenn McAllister wrote:
> Ralph Hempel wrote:
>> Glenn McAllister wrote:
>>> We've been having some odd problems with the exponent operator ('^') and 

Is your luaconf.h plain vanilla or have you changed any of the
definies for the math operators or number types

Ralph

Patrick Donnelly | 2 Mar 12:23

coroutine library can cause panic with low memory

Using the attached script one can cause Lua to panic. The problem is
the API call lua_checkstack which may throw a memory error. When
auxresume in lbaselib.c fails to allocate stack space, there is no
error handler set on the coroutine so Lua will panic.

batrick <at> li50-61:~$ ulimit -v 10000 # simulate a memory constrained env
batrick <at> li50-61:~$ lua test.lua
1       thread: 0x532c70        true    nil
2       thread: 0x539ac0        true    nil
3       thread: 0x537df0        true    nil
4       thread: 0x534650        true    nil
5       thread: 0x5365c0        true    nil
6       thread: 0x53b500        true    nil
7       thread: 0x53d470        true    nil
8       thread: 0x566c20        true    nil
9       thread: 0x53f3b0        true    nil
10      thread: 0x541500        true    nil
11      thread: 0x557480        true    nil
12      thread: 0x5593f0        true    nil
13      thread: 0x55c9b0        true    nil
14      thread: 0x55e920        true    nil
15      thread: 0x560890        true    nil
16      thread: 0x562800        true    nil
17      thread: 0x564770        true    nil
18      thread: 0x566e50        true    nil
19      thread: 0x568dc0        true    nil
20      thread: 0x588530        true    nil
PANIC: unprotected error in call to Lua API (not enough memory)

lua_checkstack should probably not throw memory errors because it
(Continue reading)

Miles Bader | 2 Mar 04:30
Picon
Gravatar

Re: Greedy matching with LPEG

Hmm, so why would one want to use "gema" instead of lpeg?

-Miles

--

-- 
Omochiroi!

Glenn McAllister | 2 Mar 19:18
Favicon

Re: exponent and modulus operator oddities on ppc

Ralph Hempel wrote:
> Glenn McAllister wrote:
>> But interestingly, if I change the last assignment in the script from
>>
>>   z = 2 ^ 3
>>
>> to be
>>
>>  z = y ^ 3
>>
>> I now get the broken output:
>>
>>  x =     8
>>  y =     2
>>  z =     4.0096609170284
> 
> Which may lead to thinking that y is not really 2

Agreed.  I'm still stumped that it was happening when we *weren't* 
referring to y, however.

> 
> What happens when you ask for:
> 
> z = y ^ 2

z =	4

> z = y ^ 4

(Continue reading)

Eike Decker | 2 Mar 19:58

Coroutine debug hook counter

I am planning to write a game for a competition where people can code
bots (artificial intelligences, AI). Contrary to the coding
competition AI games that I know (robocode for example), I want to
limit the number of instructions that each AI has - so that every AI
has the same amount of instructions per round. This should simulate
the realtime behaviour of real robots where each CPU has a limited
number of instructions per second. I would endorse this solution since
I have seen efficient clever yet simple solution that got beaten by
complex and inefficient solutions even though it was obvious, that the
clever solution would have been better in means of execution time.
Another benefit is, that this approach allows me to naturally force
users to write AIs that can be presented in realtime. Setting
execution time limits in seconds has proven to be not working
reliable.

Fortunately, Lua supports debug hooks with instruction counters - so I
can yield the program execution after a certain amount of instructions
and let other AIs run until I perform a new step in the simulated
physical world.
Unfortunately, this works only without problems as long as no
coroutines are used by the coders.

The idea is, that the debug hook yields when the instruction limit is
reached and the yield goes back to the initial kickoff for the running
AI, so the next AI code can be executed. This works fine, even if
multiple coroutines are used -  I rewrote the coroutine.resume
function so that it yields (and resumes) over all the AI coroutines
from my hook's yield back to the kickoff and back again when the
execution should be continued. All fine here.

(Continue reading)

M Joonas Pihlaja | 2 Mar 20:07
Picon
Picon

Re: coroutine library can cause panic with low memory


Hey,

On Mon, 2 Mar 2009, Patrick Donnelly wrote:

> Using the attached script one can cause Lua to panic. The problem is
> the API call lua_checkstack which may throw a memory error.

[snip]

> lua_checkstack should probably not throw memory errors because it
> cannot knowingly throw the error on the currently running thread. The
> thread you are checking stack space for may not actually be running!

Uhm.. sorry if I'm being dense, but isn't growing stack and possibly 
throwing a memory error the very reason for calling lua_checkstack in 
the first place?  What on earth is it supposed to do if it can't throw 
memory errors when it can't grow the stack?

Cheers,

Joonas


Gmane