rotate operator?

Go To Last Post
51 posts / 0 new
Author
Message
#1
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

dear friends!

is there any codevision operators to rotate an variable on its bits? i mean 0101 ----> 1010

that >> makes a shift right? how about rotate?

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0
uint8_t rotateR(uint8_t c) {
  if (c & 1) {
    return (c>>1) | 0x80;
  }
  else {
    return c>>1;
  }
}

but when using C you almost never need a rotate. It tends to be frustrated Asm programmers who pointlessly look for this.

EDIT: someone ate my [X] key - hex constant now corrected.

Last Edited: Wed. Jul 13, 2011 - 08:35 AM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

its for the use in a stepper motor control application, why there is no need on rotate in c?

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Quote:

its for the use in a stepper motor control application, why there is no need on rotate in c?


I've done stepper apps, and never saw the need to rotate. But then perhaps it might be more efficient than my approach of laying out the excitation tables for the different modes?
https://www.avrfreaks.net/index.p...
Hmmm--I guess I didn't use tables, but rather a state machine...

Oh, by the way: How would you do it better in ASM on an AVR since ROL/ROR go through C Carry?

You can put lipstick on a pig, but it is still a pig.

I've never met a pig I didn't like, as long as you have some salt and pepper.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

i dont want to do it on ASM because then i will have to devote some registers to the variable and that may screw whole program! i would like to use a simple C operator but there is none!
its my own idea to use a rotation strategy on steppers! but C's limitations are preventing me.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Quote:

i dont want to do it on ASM because then i will have to devote some registers to the variable and that may screw whole program! i would like to use a simple C operator but there is none!
its my own idea to use a rotation strategy on steppers! but C's limitations are preventing me.

Please address my comments/questions. Let me rephrase: What is the optimal AVR instruction sequence that you are trying to carry out? How does the manufactured rotate routine compare in cycles?

Quote:

i dont want to do it on ASM because then i will have to devote some registers to the variable and that may screw whole program!

??? Either your variable is in a register or it isn't. C operations on an SRAM variable will, in almost all cases, load the value with LDS, do an operation, and store the result with STS. It loads into--wait for it--a register.

And to repeat--once it is loaded into a register, what sequence of AVR machine instructions is optimal for you?

[Given the "screw whole program", what toolchain are you using and who/what is getting screwed?]

(Note what you get with a Google or Forum search for "rotate gcc": https://www.avrfreaks.net/index.p... )

You can put lipstick on a pig, but it is still a pig.

I've never met a pig I didn't like, as long as you have some salt and pepper.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

whiteman7777 wrote:
its my own idea to use a rotation strategy on steppers! but C's limitations are preventing me.
No they aren't. You simply try to do it the wrong way (in C). Learn the language then try to implement your ideas. It isn't that easy to change a language, unless you write your own compiler... (or modify one ...)
Edit: And that's not easy.

Last Edited: Tue. Jul 12, 2011 - 08:55 PM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

the codevision compiler automaticaly assigns sram registers to the variables put in the program, if u devote a register to a specified variable then its possible that compiler reassigns that to another variable, also the carry bit is unknown what to content since almost all routins use it, so u have to write whole program in assembely or forget using these assembly orders. i dont want to put time on assembly programing since its too time consuming.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Quote:

the codevision compiler automaticaly assigns sram registers to the variables put in the program, if u devote a register to a specified variable then its possible that compiler reassigns that to another variable, also the carry bit is unknown what to content since almost all routins use it, so u have to write whole program in assembely or forget using these assembly orders. i dont want to put time on assembly programing since its too time consuming.

You just don't get it. Actually, several things.

1) You were given a roate routine. why have you seen fit to discard that solution?
2) If you follow the link I gave, you see that even for the gurus IT MAKES NO DIFFERENCE WHETHER C HAS A ROTATE OR NOT--on an AVR there is not a single machine instruction to carry out the rate you described in a single machine instruction. Thus, there are a couple of alternative sequences presented.
3) CodeVision, eh? Have you considered putting this important variable in a global register variable? (Given your concern, I assume it is "important" for speed/efficiency.)
4) #asm sequences in CV screw no pooches. In fact you have nearly all the AVR's GP registers under your control. In particular in this case all you probably need is one high register and there are lots of those available.
4a) If you are doing the work in main() then the first variable is in R16, etc.
5) Once you have it in a register, what are you going to do with it? What is the optimum set of machine instructions to do what you want?
5a) Once you tell me/us that, then we can work on the "best" C version for you. It may well be that it can be done in straight C--but maybe not.

Quote:

if u devote a register to a specified variable then its possible that compiler reassigns that to another variable,

Simply untrue.

register	unsigned int	worknum;	// working 16-bit value
register	unsigned char	state;		// program main state

are some of my very important variables in a Mega1280 app, 70% full. They stay right where I put them:

Register Allocation
Variable                                                          Register  Size
--------------------------------------------------------------------------------
worknum                                                           R3,R4        2
state                                                             R6           1

Quote:


Quote:

also the carry bit is unknown what to content since almost all routins use it

Immaterial. Starting the rotate it makes no difference. After the rotate it is a don't-care.

Quote:

so u have to write whole program in assembely or forget using these assembly orders.

Simply not true, given the above.

>> If you tell us what you really need to do and your constraints we can help. All here enjoy puzzles on "how can XYZ best be done on an AVR?" Start by telling why the C solution presented isn't good enough?

You can put lipstick on a pig, but it is still a pig.

I've never met a pig I didn't like, as long as you have some salt and pepper.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

at first, i am worried about what carry contains before the rotation not after it, an unwanted high bit may get in the variable sequence!
second, yes that rotation function which friend provided us works, but my problem is that the stepper is a 4 phase mono polar one! i need to rotate just a nible while no kind of variables in c uses only 4 bits, there are all on a byte or word or longer while i need to rotate only a nible. this way not even an ASM program handles the problem, any suggestions?

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

i have written the program on other method (number sequences), i just did it but i would love to use rotation mode! it should be far better, perhaps next time.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

You were given alterate solutions- either use a table ( array) or a finite state machine. You asked the wrong question as a rotate is not needed, you really should've asked for possible solutions for driving a stapper motor. Did you Google "avr stepper motor"?
For a table solution, write down a list of your wanted output combinations and put the resultant values into an array.

Char step_table[8] ={1,3,2,6,4,12,8,9};



PORTA = step_ table[step];
step++;// to go forward
step--;// to go backwards
step &= 0x07; // mask so we always remain from 0 to 7
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

I fail to see how using rotate would help. How do you do half step?

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Quote:

at first, i am worried about what carry contains before the rotation not after it, an unwanted high bit may get in the variable sequence!

No, your sequence needs to do it properly. previous carry shouldn't end up anywhere in the result.
Quote:

but my problem is that the stepper is a 4 phase mono polar one! i need to rotate just a nible while no kind of variables in c uses only 4 bits, there are all on a byte or word or longer while i need to rotate only a nible. this way not even an ASM program handles the problem, any suggestions?

Sigh. The same way you'd do 8 bits or even more bits. As the sequences in the link show, there are a couple of tests to do.

I assume you need both directions? Going to the left, maybe one of the few time H /half-carry is pertinent.

Quote:

this way not even an ASM program handles the problem, any suggestions?


LOL--gotta go play poker now, but

// this will work better if a local to main() 'cause it will be in a high register.
register unsigned char pattern;
...
// Left rotate
pattern <<= 1;
if (pattern & (1<<4))
   {
   pattern |= 1;
   }
// If you only use the low 4 bits of "pattern", you are done.
// Otherwise you might want to mask them off.

Note that in CV you can, with some thought, map bit variables to the register variable...

You can put lipstick on a pig, but it is still a pig.

I've never met a pig I didn't like, as long as you have some salt and pepper.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

i dont want those "if" sentences, neigther an ASM program, i am a new in this field and i want an straight order! i dont know why none have arranged some thing about it in C?

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Quote:

why none have arranged some thing about it in C?

Why would C ever need to know about a "carry flag". If you are in Asm and want to shift 123 five places to the left you have to worry about shifting the lower half then bringing in the carry in the upper half.

In C you write:

uint8_t a = 123;
uint16_t b;
b = a << 5;

Somewhere inside the generated code I guess the compiler is worrying about the carry flag - but the C programmer does not need to.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Quote:

dont want those "if" sentences, neigther an ASM program, i am a new in this field and i want an straight order!

You can want or not want anything you like.

The fact is that there is no rotate operator in C, so you will have tom implement something along the lines of the sugestions above.

Quote:
i dont know why none have arranged some thing about it in C?

Because C does not implement everything you need, but rather implement a set of basic operations that you combine into the sequence that do te job you need to get done. Someone else needs something else to be done, and will use the same basic operations but in another sequence.

You might argue that rotating a nibble in a byte should be among those fundamental operations, but the designers of the language apparently thought otherwise. You can keep on arguing, or you can accept the fact. I'd suggest the latter. Then we can start discussing if a pure algorithmic approach or a table-driven solution fits your bill best. I'm sure we will get into discussions on how pressed for performance (time, space) you actually are..

For being "new in this field" you sure have a lot of attitude. :wink:

As of January 15, 2018, Site fix-up work has begun! Now do your part and report any bugs or deficiencies here

No guarantees, but if we don't report problems they won't get much of  a chance to be fixed! Details/discussions at link given just above.

 

"Some questions have no answers."[C Baird] "There comes a point where the spoon-feeding has to stop and the independent thinking has to start." [C Lawson] "There are always ways to disagree, without being disagreeable."[E Weddington] "Words represent concepts. Use the wrong words, communicate the wrong concept." [J Morin] "Persistence only goes so far if you set yourself up for failure." [Kartman]

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

thanks, i guess i will have to some how ignore 4 steps of rottations and use 4 other using some delay orders between the 4 lower bits rotations! thanks every body!

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Quote:

i will have to some how ignore 4 steps of rottations

Unless my eyes deceive me our poker playing friend already posted an example of 4 bit rotation?? The key thing in that is testing bit 4 (pattern & (1<<4)) after the shift and setting bit 0 (pattern |= 1) if that "carry" were set.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

I'm yet to understand the fixation with doing a rotate. There was no mention of the 'fastest' or the 'smallest' code apart from rotate and no 'if's and probably no 'but's either. For better torque one normally uses at least a half step sequence with which a rotate is useless. Even in ttl logic you build the step sequencer using counters and xors and in PLD's a finite state machine. In a FPGA it probably resolves down to a look up table (in ram based fpgas it does anyway!!).

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Quote:

Unless my eyes deceive me our poker playing friend already posted an example of 4 bit rotation??

// this will work better if a local to main() 'cause it will be in a high register.
register unsigned char pattern;
//...
// Left rotate
pattern <<= 1;
if (pattern & (1<<4))
   {
   pattern |= 1;
   }
// If you only use the low 4 bits of "pattern", you are done.
// Otherwise you might want to mask them off.
pattern &= 0x0f;

// Right rotate
if (pattern & 1)
   {
   pattern |= (1<<4);
   }
pattern >>= 1;
// If you only use the low 4 bits of "pattern", you are done.
// Otherwise you might want to mask them off.
pattern &= 0x0f;
                 ; 0000 0013 register unsigned char pattern;
                 ; 0000 0014 //...
                 ; 0000 0015 // Left rotate
                 ; 0000 0016 pattern <<= 1;
                 ;	pattern -> R17
0000c1 0f11      	LSL  R17
                 ; 0000 0017 if (pattern & (1<<4))
0000c2 fd14      	SBRC R17,4
                 ; 0000 0018    {
                 ; 0000 0019    pattern |= 1;
0000c3 6011      	ORI  R17,LOW(1)
                 ; 0000 001A    }
                 ; 0000 001B // If you only use the low 4 bits of "pattern", you are done.
                 ; 0000 001C // Otherwise you might want to mask them off.
                 ; 0000 001D pattern &= 0x0f;
0000c4 701f      	ANDI R17,LOW(15)
                 ; 0000 001E 
                 ; 0000 001F // Right rotate
                 ; 0000 0020 if (pattern & 1)
0000c5 fd10      	SBRC R17,0
                 ; 0000 0021    {
                 ; 0000 0022    pattern |= (1<<4);
0000c6 6110      	ORI  R17,LOW(16)
                 ; 0000 0023    }
                 ; 0000 0024 pattern >>= 1;
0000c7 9516      	LSR  R17
                 ; 0000 0025 // If you only use the low 4 bits of "pattern", you are done.
                 ; 0000 0026 // Otherwise you might want to mask them off.
                 ; 0000 0027 pattern &= 0x0f;
0000c8 701f      	ANDI R17,LOW(15)

Pretty straight-forward code generation.

If pure ASM then perhaps a BLD/BST pair would make it all deterministic and save a cycle (how come the gurus in the thread linked to above didn't use SBRx sequence or BLD/BST? Non-optimum?) but for straight C not bad. When a register variable there are no additional GP registers involved.

Quote:

i dont want those "if" sentences

// No "if" left rotate
pattern <<= 1;
pattern |= (pattern & (1<<4)) ? 1 : 0;
                 ; 0000 0029 // No "if" left rotate
                 ; 0000 002A pattern <<= 1;
0000c9 0f11      	LSL  R17
                 ; 0000 002B pattern |= (pattern & (1<<4)) ? 1 : 0;
0000ca ff14      	SBRS R17,4
0000cb c002      	RJMP _0x7
0000cc e0e1      	LDI  R30,LOW(1)
0000cd c001      	RJMP _0x8
                 _0x7:
0000ce e0e0      	LDI  R30,LOW(0)
                 _0x8:
0000cf 2b1e      	OR   R17,R30

:twisted: Lee

You can put lipstick on a pig, but it is still a pig.

I've never met a pig I didn't like, as long as you have some salt and pepper.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Quote:

No "if" left rotate

Don't anyone tell him the implied meaning of '?' in that ;-)

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

clawson wrote:
Quote:

No "if" left rotate

Don't anyone tell him the implied meaning of '?' in that ;-)

What? Nobody?
They'd better not mention conditional evaluation either then :)

--greg
Still learning, don't shout at me, educate me.
Starting the fire is easy; the hardest part is learning how to keep the flame!

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Quote:

Note that in CV you can, with some thought, map bit variables to the register variable...


Indeed... (I grabbed some old code where I did this kind of thing so the comments won't match exactly...)

// Bank 1
bit    bank1_0;        // R5 Bit 0 (least significant)
bit    bank1_1;
bit    bank1_2;
bit    bank1_3;
bit    bank1_4;
bit    bank1_5;
bit    bank1_6;
bit    bank1_7;		// R5 Bit 7 (most significant)

register unsigned char pattern @ 0x05;
...
// Left rotate
pattern <<= 1;
bank1_0 = bank1_4;
...
// Right rotate
bank1_4 = bank1_0;
pattern >>= 1;
                 ; 0000 0021 // Left rotate
                 ; 0000 0022 pattern <<= 1;
000056 0c55      	LSL  R5
                 ; 0000 0023 bank1_0 = bank1_4;
000057 fa24      	BST  R2,4
000058 f820      	BLD  R2,0
...
                 ; 0000 0029 // Right rotate
                 ; 0000 002A bank1_4 = bank1_0;
00005b fa20      	BST  R2,0
00005c f824      	BLD  R2,4
                 ; 0000 002B pattern >>= 1;
00005d 9456      	LSR  R5

NOW let's see what objections OP has...

(Is that sequence optimum? It at least is deterministic. And it is straight (CV-flavoured) C.)

Lee

You can put lipstick on a pig, but it is still a pig.

I've never met a pig I didn't like, as long as you have some salt and pepper.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

gregsmithcts wrote:
clawson wrote:
Quote:

No "if" left rotate

Don't anyone tell him the implied meaning of '?' in that ;-)

What? Nobody?
They'd better not mention conditional evaluation either then :)
Of course it is also possible without any kind of conditional expression:

pattern = (pattern << 1) | ((pattern >> 3) & 0x01);

Stefan Ernst

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Quote:

Of course it is also possible without any kind of conditional expression:

Code:
pattern = (pattern << 1) | ((pattern >> 3) & 0x01);


Yeah, but one would assume OP is after some kind of efficiency--otherwise why all the fuss over not using lookup, etc.

Anyway, your shifting/masking and any conditional solution won't be as tight as my 3-word, 3-cycle sequence, right?

You can put lipstick on a pig, but it is still a pig.

I've never met a pig I didn't like, as long as you have some salt and pepper.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

theusch wrote:
Yeah, but one would assume OP is after some kind of efficiency--otherwise why all the fuss over not using lookup, etc.

Anyway, your shifting/masking and any conditional solution won't be as tight as my 3-word, 3-cycle sequence, right?

Yes, it is less efficient.
It was not my intention to fulfill any supposed demands. It is only an alternative offer for his "rotate without if" demand.

Stefan Ernst

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Quote:
Somewhere inside the generated code I guess the compiler is worrying about the carry flag - but the C programmer does not need to.
For << and >> the carry is unimportant since the compiler would use LSL, LSR or ASR which only put values into the carry, not take values out of the carry. If ASR is used, the msb is replicated, so you would need to account for that, but this can be avoided by making the value unsigned.

Regards,
Steve A.

The Board helps those that help themselves.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Quote:

For << and >> the carry is unimportant since the compiler would use LSL, LSR or ASR which only putsvalues into the carry, not take values out of the carry.

Rather sadly it uses:

extern uint8_t a;
extern uint16_t b;

int main(void) {
	b = a << 5;
  92:	80 91 60 00 	lds	r24, 0x0060
  96:	90 e0       	ldi	r25, 0x00	; 0
  98:	25 e0       	ldi	r18, 0x05	; 5
  9a:	88 0f       	add	r24, r24
  9c:	99 1f       	adc	r25, r25
  9e:	2a 95       	dec	r18
  a0:	e1 f7       	brne	.-8      	; 0x9a 
  a2:	90 93 63 00 	sts	0x0063, r25
  a6:	80 93 62 00 	sts	0x0062, r24

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

But surely that is because you chose the odd value of 5 to shift by. For 4 you get:

       		rot <<= 4;
49:   9582        SWAP      R24            Swap nibbles
4A:   7F80        ANDI      R24,0xF0       Logical AND with immediate

and for 1 you get:

      		rot <<= 1;
49:   0F88        LSL       R24            Logical Shift Left

Regards,
Steve A.

The Board helps those that help themselves.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

I deliberately chose 5 so it wasn't a simple shift. But I guess I thought it might unroll:

ldi r24, 123
mov r25, _zero_reg_
lsl r24
rol r25
lsl r24
rol r25
lsl r24
rol r25
lsl r24
rol r25
lsl r24
rol r25

except it didn't. It used a loop iterator and add/adc pairs. At least those add/adc could just as easily have been lsl/rol I guess?

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Quote:

But surely that is because you chose the odd value of 5 to shift by.

You guys have apples and oranges. Cliff's example is shifting an 8 bit value and storing into a 16 bit value. "rot" is just doing 8-bit work and that's where SWAP will likely show up.

You can put lipstick on a pig, but it is still a pig.

I've never met a pig I didn't like, as long as you have some salt and pepper.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

The expression "rot in hell" suddeny took on a new meaning...
[ducking]

As of January 15, 2018, Site fix-up work has begun! Now do your part and report any bugs or deficiencies here

No guarantees, but if we don't report problems they won't get much of  a chance to be fixed! Details/discussions at link given just above.

 

"Some questions have no answers."[C Baird] "There comes a point where the spoon-feeding has to stop and the independent thinking has to start." [C Lawson] "There are always ways to disagree, without being disagreeable."[E Weddington] "Words represent concepts. Use the wrong words, communicate the wrong concept." [J Morin] "Persistence only goes so far if you set yourself up for failure." [Kartman]

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Quote:
I deliberately chose 5 so it wasn't a simple shift. But I guess I thought it might unroll:

Code:
ldi r24, 123 
mov r25, _zero_reg_ 
lsl r24 
rol r25 
lsl r24 
rol r25 
lsl r24 
rol r25 
lsl r24 
rol r25 
lsl r24 
rol r25 


C and it's stupid rules :twisted:

ldi  r24,123
ldi  r25,32
mul  r24,r25
movw r24,r0
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Quote:

C and it's stupid rules Twisted Evil
Code:

ldi r24,123
ldi r25,32
mul r24,r25
movw r24,r0


LOL--but >>5 becomes a little trickier. (MUL by 8 and take the high byte?) (I seem to recall past threads and fragments where IAR did clever things such as your fragment.)

You can put lipstick on a pig, but it is still a pig.

I've never met a pig I didn't like, as long as you have some salt and pepper.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

and this code

  j+=j;
  if (j&0x10)
    j++;

should be something like

LSL  r24
SBRC r24,4
INC  r24

But no cigar

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Quote:

and this code
Code:

j+=j;
if (j&0x10)
j++;

should be something like
Code:

LSL r24
SBRC r24,4
INC r24

But no cigar


Speak for yourself, Oh, Infinite-Value Toolchain Breath...

                 ; 0000 002B unsigned char j;
                 ; 0000 002C j+=j;
                 ;	j -> R16
000054 0f00      	LSL  R16
                 ; 0000 002D   if (j&0x10)
000055 fd04      	SBRC R16,4
                 ; 0000 002E     j++;
000056 5f0f      	SUBI R16,-1

... and if a low register...

                 ; 0000 002C j+=j;
000054 0c88      	LSL  R8
                 ; 0000 002D   if (j&0x10)
000055 fc84      	SBRC R8,4
                 ; 0000 002E     j++;
000056 9483      	INC  R8

[edit] Right-rotate

                 ; 0000 0030 if (j & 0x01)
000057 fd00      	SBRC R16,0
                 ; 0000 0031     {
                 ; 0000 0032     j |= 0x10;
000058 6100      	ORI  R16,LOW(16)
                 ; 0000 0033     }
                 ; 0000 0034 j /= 2;
000059 9506      	LSR  R16

You can put lipstick on a pig, but it is still a pig.

I've never met a pig I didn't like, as long as you have some salt and pepper.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

theusch wrote:
Infinite-Value Toolchain
It does the same thing:
static uint8_t rotate(uint8_t j) {
  j+=j;
  dc:	88 0f       	add	r24, r24
  if (j&0x10)
  de:	84 fd       	sbrc	r24, 4
    j++;
  e0:	8f 5f       	subi	r24, 0xFF	; 255
  return j;
}
  e2:	08 95       	ret
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Quote:

It does the same thing:

Sorry--I guess I assumed that sparrow2 was using that toolchain.

Revised: "... Perhaps with YOUR toolchain, sparrow ..." ;)

You can put lipstick on a pig, but it is still a pig.

I've never met a pig I didn't like, as long as you have some salt and pepper.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

LOL -- as I mentioned earlier:

Quote:

All here enjoy puzzles on "how can XYZ best be done on an AVR?"

You can put lipstick on a pig, but it is still a pig.

I've never met a pig I didn't like, as long as you have some salt and pepper.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

I used the winavr and it made a SBRS over a rjmp.
But at least there some code "some of" the C compilers make optimal :)

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Quote:

"some of" the C compilers make optimal

One of those above *is* avr-gcc ;-)

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

I must have a problem at the PC I'm at now!

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

clawson wrote:
At least those add/adc could just as easily have been lsl/rol I guess?
LSL X is just ADD X,X and likewide ROL X is just syntactic sugar for ADC X,X.
clawson wrote:

uint8_t a = 123;
uint16_t b = a << 5;

Somewhere inside the generated code I guess the compiler is worrying about the carry flag.

Infinite-value Toolchain actually does a shift here, whereas 4.7+ does a MUL (provided it has one).

avrfreaks does not support Opera. Profile inactive.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

yes i had put down wave drive method and used full step mode which has two phases activated concurrently.

how ever i believe some one must think of some rotation operators in C and codevision, and both for 4 bits and 8 bits variables!

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Quote:
how ever i believe some one must think of some rotation operators in C and codevision, and both for 4 bits and 8 bits variables!
:roll: Here :roll: we go :roll: AGAIN ( NOT ! )...

1) Studio 4.18 build 716 (SP3)
2) WinAvr 20100110
3) PN, all on Doze XP... For Now
A) Avr Dragon ver. 1
B) Avr MKII ISP, 2009 model
C) MKII JTAGICE ver. 1

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Quote:
how ever i believe some one must think of some rotation operators in C
C knows absolutely nothing about "rotation", so it can't possibly have a rotation "operator".

Regards,
Steve A.

The Board helps those that help themselves.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Damned CodeVision! It gets blasted when it introduces useful extensions, and now gets blasted when it doesn't introduce extensions.

Curiously enough, I've done production stepper apps and have yet to use a rotate of a mask in any of them.

OP must have a full port/contiguous bits to work with, and exactly in the desired order. Sounds like a specialty configuration--the world is rarely that orthogonal.

(I don't even have a step table. Rather, I have states for each type of stepping and move from state-to-state. That way I can have one set of code and just multiple state sequences for full, half, and high-power half modes.)

Lee

You can put lipstick on a pig, but it is still a pig.

I've never met a pig I didn't like, as long as you have some salt and pepper.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

whiteman7777 wrote:
how ever i believe some one must think of some rotation operators in C!
Just move to the next chapter of you C manual and you see you read you never believe...

Yes! It's really true! In C you can define — huh, well, shall I dare to name the unspeakable, unspoken, miraculous, wonderful Black Magic Witch Craft Thing?

Really?

Others would sell their grandma for it, so beware!

Get Ready!

F U N C T I O N

#include 

static inline uint8_t rol8 (uint8_t x, int off)
{
    return (x << off) | (x >> (8-off));
}

static inline uint8_t ror8 (uint8_t x, int off)
{
    return rol8 (x, 8-off);
}

static inline uint16_t rol16 (uint16_t x, int off)
{
    return (x << off) | (x >> (16-off));
}

static inline uint16_t ror16 (uint16_t x, int off)
{
    return rol16 (x, 16-off);
}

void roll_it (uint16_t x16, uint8_t x8, uint8_t *y)
{
    y[0] = rol8 (x8, 1);
    y[1] = ror8 (x8, 4);
    y[2] = rol8 (x8, 6);
    y[3] = rol8 (x8, 7);

    y[10] = rol16 (x16, 1);
    y[11] = ror16 (x16, 4);
    y[12] = rol16 (x16, 8);
}

And the code settled into the lovely green water and dropped toward the bottom. The waving branches of the algebra called to it and beckoned to it. The lights on its surface were green and lovely. It settled down to the sand bottom among the fern-like plants. Above, the surface of the water was a green mirror. And the code lay on the floor of the sea. A compiler scampering over the bottom raised a little cloud of sand, and when it settled the code was gone...

roll_it:
	movw r30,r20
	mov r18,r22
	lsl r18
	adc r18,__zero_reg__
	st Z,r18
	mov r18,r22
	swap r18
	std Z+1,r18
	mov r18,r22
	swap r18
	lsl r18
	adc r18,__zero_reg__
	lsl r18
	adc r18,__zero_reg__
	std Z+2,r18
	bst r22,0
	ror r22
	bld r22,7
	std Z+3,r22
	movw r18,r24
	lsl r18
	rol r19
	adc r18,__zero_reg__
	std Z+10,r18
	mov r18,r25
	swap r18
	andi r18,lo8(-16)
	mov r19,r24
	swap r19
	andi r19,lo8(15)
	or r18,r19
	std Z+11,r18
	eor r25,r24
	eor r24,r25
	std Z+12,r24
	ret

avrfreaks does not support Opera. Profile inactive.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Quote:

Just move to the next chapter of you C manual and you see you read you never believe...

Quote:

and both for 4 bits and 8 bits variables!

You can put lipstick on a pig, but it is still a pig.

I've never met a pig I didn't like, as long as you have some salt and pepper.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

You mean this doesn't just work?

uint4_t foo = 0x1;
foo @= 1;

(@ being the ROR operator of course!)

What an oversight!