From: SourceForge.net <no...@so...> - 2008-05-31 13:09:31
|
Bugs item #1980592, was opened at 2008-05-31 15:09 Message generated for change (Tracker Item Submitted) made by Item Submitter You can respond by visiting: https://sourceforge.net/tracker/?func=detail&atid=520074&aid=1980592&group_id=68108 Please note that this message will contain a full copy of the comment thread, including the initial issue submission, for this request, not just the latest update. Category: None Group: None Status: Open Resolution: None Priority: 5 Private: No Submitted By: Bernhard Seifert (berni_seifert) Assigned to: Nobody/Anonymous (nobody) Summary: in asm: unable to use 64-bit operand Initial Comment: using the avr-libc manual I've created a 32-bit byteswap function uint32_t Math::reverse(uint32_t x) { // Reverse byte order asm volatile ( "mov __tmp_reg__, %A0 \n\t" "mov %A0, %D0 \n\t" "mov %D0, __tmp_reg__ \n\t" "mov __tmp_reg__, %B0 \n\t" "mov %B0, %C0 \n\t" "mov %C0, __tmp_reg__ \n\t" : "+r" (x) ); // Return value return x; } according to the manual %A0 is the lowest byte of parameter 1, %B0 the second-lowest, and so on. %A1 is the lowest byte of the second parameter and so on. This works fine for up to 32bit values, but the upper 4 bytes of a 64bit value cannot be addressed. %E0 til %H0 does not work, %A1 to %D1 doesn't work neither. I've found the following workaround to make a 64bit byte swap function: // Reverse byte order uint64_t Math::reverse(uint64_t x) { // Reverse byte order asm volatile ( "mov __tmp_reg__, r23 \n\t" "mov r23, r16 \n\t" "mov r16, __tmp_reg__ \n\t" "mov __tmp_reg__, r22 \n\t" "mov r22, r17 \n\t" "mov r17, __tmp_reg__ \n\t" "mov __tmp_reg__, r21 \n\t" "mov r21, r18 \n\t" "mov r18, __tmp_reg__ \n\t" "mov __tmp_reg__, r20 \n\t" "mov r20, r19 \n\t" "mov r19, __tmp_reg__ \n\t" : "+a" (x) ); // Return value return x; } by telling the compiler "+a" (x) the registers r16-r23 are used. But unnecessary moves between the registers make the function slower and larger. In no manual/forum I've found a solution to this problem! ---------------------------------------------------------------------- You can respond by visiting: https://sourceforge.net/tracker/?func=detail&atid=520074&aid=1980592&group_id=68108 |