forums.ps2dev.org Forum Index forums.ps2dev.org
Homebrew PS2, PSP & PS3 Development Discussions
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

Request - add bit shifting

 
Post new topic   Reply to topic    forums.ps2dev.org Forum Index -> PSP Lua Player Development
View previous topic :: View next topic  
Author Message
modsyn



Joined: 27 Sep 2005
Posts: 28

PostPosted: Tue Jan 24, 2006 2:44 am    Post subject: Request - add bit shifting Reply with quote

i recently found out that lua doesn't support shifting bits (ie, <</>>/>>>)
and i found this page with a suggested way of adding the feature:
http://lua-users.org/lists/lua-l/1999-02/msg00024.html

For those too lazy to follow the link wrote:

>From: erik@hougaard.com (Erik Hougaard)
>This might be a stupid function, but is Lua missing a << >> bitshift function

yes, since it does not make sense for real numbers.

>and if so, how do I make it ?

how about this:

static void math_lshift (void)
{
int v=luaL_check_number(1);
int n=luaL_check_number(2);
lua_pushnumber(v<<n);
}

static void math_rshift (void)
{
int v=luaL_check_number(1);
int n=luaL_check_number(2);
lua_pushnumber(v>>n);
}

lua_register("lshift",math_lshift);
lua_register("rshift",math_rshift);

--lhf


could this possibly be added for future releases?
sorry if i posted this in the wrong place,
modsyn
Back to top
View user's profile Send private message
fullerlee



Joined: 03 Nov 2005
Posts: 54

PostPosted: Tue Jan 24, 2006 4:00 am    Post subject: Reply with quote

I second this request, I have a need for it in my current project.

Thanks,

Lee
Back to top
View user's profile Send private message
Shine



Joined: 03 Dec 2004
Posts: 728
Location: Germany

PostPosted: Tue Jan 24, 2006 7:28 am    Post subject: Reply with quote

What about x << y == x * math.pow(2, y) and x >> y == math.floor(x / math.pow(2, y)) ?
Back to top
View user's profile Send private message
fullerlee



Joined: 03 Nov 2005
Posts: 54

PostPosted: Tue Jan 24, 2006 7:50 am    Post subject: Reply with quote

Shine,

I have used mathematics in place of bit shifting, I just thought geniune bit shifting would give some decent performance benefits.

Thanks,

Lee
Back to top
View user's profile Send private message
Shine



Joined: 03 Dec 2004
Posts: 728
Location: Germany

PostPosted: Tue Jan 24, 2006 8:03 am    Post subject: Reply with quote

Do you need the speed? Lua uses always floats as its numbers, so perhaps it would be a better idea to extend the PRX concept of Lua Player and write performance critical parts in your own PRX in C.
Back to top
View user's profile Send private message
fullerlee



Joined: 03 Nov 2005
Posts: 54

PostPosted: Tue Jan 24, 2006 11:55 am    Post subject: Reply with quote

Time will tell regarding performance. My project involves an AI player and a lot of tree searching, at the moment, performance looks like it might be acceptable, but I've been keeping an eye on the PRX concept.

Keep up the good work!

Thanks,

Lee
Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic    forums.ps2dev.org Forum Index -> PSP Lua Player Development All times are GMT + 10 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group