Dear all, _lror(unsigned long,unsigned char) is the math lib and implemented as function,not intrinsic function. But now I can not use it and need to implement myself.
Does anyone have the experience to implement it manually ?
I found the following code segments in Forum but it seems wrong after "my" verification:
unsigned long lror(unsigned long n,unsigned steps) { unsigned long t1,t2; steps &= 0x1f; t1 = n << steps; t2 = n >> (32-steps); return t1 | t2; }
Ex. n = 0xA5A5A5A5 and steps = 1
[verify sequence] - steps &= 0x1f => steps = 1 - t1 = 0xA5A5A5A5 << 1 => t1 = 0x4B4B4B4A - t2 = 0xA5A5A5A5 >> (32-1) => t2 = 1 - t1|t2 => 0x4B4B4B4B ! (But result should be: 0xD2D2D2D2...)
Anything I misunderstood ?
Take a look at this: http://www.keil.com/forum/docs/thread1252.asp
You can change rotate left or rotate right by switching place for steps and 32-steps.
After switching "steps and 32-steps" as below: unsigned long lror(unsigned long n,unsigned steps) { unsigned long t1,t2; steps &= 0x1f; t1 = n << 32-steps; t2 = n >> steps; return t1 | t2; }
I got the correct result when lror(0xA5A5A5A5,1) !
Thanks !