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 

Bitwise operator syntax in C ?

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



Joined: 09 Nov 2005
Posts: 647

PostPosted: Tue Mar 28, 2006 1:52 pm    Post subject: Bitwise operator syntax in C ? Reply with quote

Hi Guys,
I'm in need of a little help.
Code:

RotateHMKright                      ;bitwise rotate HMK array
  rrf       HMK+0      ,F            ;a faster way thanx Potter :)
  rrf       HMK+1      ,F            ;
  rrf      HMK+2      ,F            ;went back to rotating right x 79
  rrf      HMK+3      ,F            ;for rotating left to save ten words
  rrf      HMK+4      ,F            ;
  rrf      HMK+5      ,F            ;
  rrf      HMK+6      ,F            ;
  rrf      HMK+7      ,F            ;
  rrf      HMK+8      ,F            ;
  rrf      HMK+9      ,F            ;
  bcf      HMK+0      ,7            ;preclear MSB
  btfsc      status      ,C            ;check carry bit
  bsf      HMK+0      ,7            ;set MSB
  return                     ;or return

This is a way to bitwise rotate a 10 byte array called HMK in asm (rr = rotate right).
The routine carries the right most bit to the left most bit of the next
byte, etc. so that if you rotated a 10 byte array 80 times you would end
up with the same values in each byte of the array as you started with,
and if you rotated right 79 times, you would have the same result as
rotating left only once.

I would be happy to find a way to do this in C for rthe PSP since it would
help me improve a lot of verbose routines that I have.
Cheers, Art.
ps. the rrf instructions weren't in an For...Next type loop because it had
to execute as fast as possible.
Back to top
View user's profile Send private message
groepaz



Joined: 01 Sep 2005
Posts: 305

PostPosted: Tue Mar 28, 2006 10:29 pm    Post subject: Reply with quote

there is no operator in C that can do this
_________________
http://www.hitmen-console.org
http://hitmen.c02.at/files/yapspd/
Back to top
View user's profile Send private message Visit poster's website
0okm0000



Joined: 13 Jan 2006
Posts: 116

PostPosted: Wed Mar 29, 2006 1:49 am    Post subject: Re: Bitwise operator syntax in C ? Reply with quote

Art wrote:
Hi Guys,
I'm in need of a little help.
Code:

RotateHMKright                      ;bitwise rotate HMK array
  rrf       HMK+0      ,F            ;a faster way thanx Potter :)
  rrf       HMK+1      ,F            ;
  rrf      HMK+2      ,F            ;went back to rotating right x 79
  rrf      HMK+3      ,F            ;for rotating left to save ten words
  rrf      HMK+4      ,F            ;
  rrf      HMK+5      ,F            ;
  rrf      HMK+6      ,F            ;
  rrf      HMK+7      ,F            ;
  rrf      HMK+8      ,F            ;
  rrf      HMK+9      ,F            ;
  bcf      HMK+0      ,7            ;preclear MSB
  btfsc      status      ,C            ;check carry bit
  bsf      HMK+0      ,7            ;set MSB
  return                     ;or return

This is a way to bitwise rotate a 10 byte array called HMK in asm (rr = rotate right).....

oh
it is MicroChip PIC asm

i m new in C
so the code may be wrong
Code:

   unsigned char HMK[9];
   HMK[9] = 0x55;
   HMK[8] = 0xAA;
   HMK[7] = 0x55;
   HMK[6] = 0xAB;
   HMK[5] = 0x55;
   HMK[4] = 0xAB;
   HMK[3] = 0x55;
   HMK[2] = 0xAA;
   HMK[1] = 0x55;
   HMK[0] = 0xAB;
   printf("\n0x%X%X%X%X%X%X%X%X%X%X", HMK[0], HMK[1], HMK[2], HMK[3], HMK[4], HMK[5], HMK[6], HMK[7], HMK[8], HMK[9]);

   unsigned char temp;
   unsigned int i;
   for(i=0; i<80; i++)
   {
      temp = (HMK[9] << 7);
      HMK[9] = (HMK[8] << 7) | (HMK[9] >> 1);
      HMK[8] = (HMK[7] << 7) | (HMK[8] >> 1);
      HMK[7] = (HMK[6] << 7) | (HMK[7] >> 1);
      HMK[6] = (HMK[5] << 7) | (HMK[6] >> 1);
      HMK[5] = (HMK[4] << 7) | (HMK[5] >> 1);
      HMK[4] = (HMK[3] << 7) | (HMK[4] >> 1);
      HMK[3] = (HMK[2] << 7) | (HMK[3] >> 1);
      HMK[2] = (HMK[1] << 7) | (HMK[2] >> 1);
      HMK[1] = (HMK[0] << 7) | (HMK[1] >> 1);
      HMK[0] = temp | (HMK[0] >> 1);
      printf("\n0x%X%X%X%X%X%X%X%X%X%X", HMK[0], HMK[1], HMK[2], HMK[3], HMK[4], HMK[5], HMK[6], HMK[7], HMK[8], HMK[9]);
   }

_________________
PSP hardware hack
http://0okm.blogspot.com/
Back to top
View user's profile Send private message Visit poster's website
groepaz



Joined: 01 Sep 2005
Posts: 305

PostPosted: Wed Mar 29, 2006 9:51 am    Post subject: Reply with quote

if this needs to be as fast as possible, i would suggest inline asm....the C solution above might work (didnt really check, but something simelar will do the trick atleast :=P), but the generated code will probably be far from optimal.

if you want to use C anyway, i'd cast the bitfield to a "unsigned long long" type, and shift those....most likely generates better code than shifting individual bytes.
_________________
http://www.hitmen-console.org
http://hitmen.c02.at/files/yapspd/
Back to top
View user's profile Send private message Visit poster's website
Art



Joined: 09 Nov 2005
Posts: 647

PostPosted: Wed Mar 29, 2006 8:13 pm    Post subject: Reply with quote

It needed to be fast in the pic code where I got the asm example from,
but I just want to learn useable syntax for bitwise operators so that
sample could be implemented in a program in any way possible.
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 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