13 October 2016, 13:20 | #1 |
Registered User
Join Date: Aug 2007
Location: berlin/germany
Posts: 1,054
|
how to rewrite particular asm inline syntax for gcc?
hi guys. im noob in c/c++, but im completely unaware of assembler. what i need to do, is to rewrite particular 68k asm inlines not understood by gcc4-6 compilers. the exemplary line in question is:
1: bset.b #0,4(a1)\n code below: static inline void _atomic_stack_push(struct _atomic_stack* list, struct _atomic_item* item) { asm volatile(" move.l %0,a0\n" " move.l %1,a1\n" "1: bset.b #0,4(a1)\n" " bne.b 1b\n" "2: move.l (a1),(a0)\n" " move.l a0,(a1)\n" " bclr.b #0,4(a1)\n" : : "m" (item), "m" (list) : "a0", "a1", "cc", "memory" ); } btw, if there is any handy guide, including different dialects of syntax to translate, you could point me to, id be grateful. |
14 October 2016, 11:42 | #2 |
Registered User
Join Date: Sep 2008
Location: Germany
Age: 49
Posts: 137
|
|
14 October 2016, 14:24 | #3 |
Registered User
Join Date: Aug 2007
Location: berlin/germany
Posts: 1,054
|
nope.
what has helped was to convert "1: bset.b #0,4(a1)\n" to "1: bset.b #0,4(%%a1)\n" which is curious, because i had only to change it in both cases of bset.b and bclr.b the assembler was complaining about, leaving all the other instructions syntax alone. |
29 October 2016, 12:26 | #4 |
Registered User
Join Date: Jul 2008
Location: Poland
Posts: 662
|
hi, like wawa "im noob in c/c++, but im completely unaware of assembler"
and would like to use this crc32 algorithm in libz to speedup png decoding in netsurf. Basicaly i want to use this Code:
;1. AmigaOS and AsmOne ;2. should be equal to LHA, LZX and so on ;3. no warranty of any kind is given ;4. further optimisations are very welcome ; ;bsr MakeCRC32Tab ;rept 20 ;lea.l $f80000,a0 ;move.l #512000,d2 ;bsr CalcCRC32 ;endr rts cnop 0,4 CalcCRC32: ;a0 - buffer ;d2 - size addq.l #1,d2 moveq #0,d7 not.b d7 lea.l CRC32tab,a3 move.l #$EDB88320,d4 ;classic move.l a0,a5 bra.s .A cnop 0,4 .loop: moveq #0,d1 move.b (a5)+,d1 move.l d4,d0 eor.l d1,d4 and.l d7,d4 lsl.l #2,d4 ;for 020+ shortens to move.l (a3,d4.L),d4 ;move.l (a3,d4.L*4),d4 lsr.l #8,d0 eor.l d0,d4 .A: subq.l #1,d2 bne.b .loop move.l d4,d0 rts cnop 0,4 MakeCRC32Tab: move.l #$100,d4 lea.l $EDB88320,a3 ;classic lea.l CRC32tab(pc),a0 moveq #0,d1 .A move.l d1,d6 moveq #0,d5 .B move.l d6,d0 lsr.l #1,d0 btst #0,d6 beq.s .C move.l a3,d6 eor.l d0,d6 bra.b .D cnop 0,4 .C move.l d0,d6 .D addq.l #1,d5 moveq #8,d0 cmp.l d0,d5 bcs.s .B addq.l #1,d1 move.l d6,(a0)+ cmp.l d4,d1 bcs.s .A rts CRC32tab: ds.b 1024 Code:
static mz_uint32 poly_table[256]; mz_ulong mz_crc32(mz_ulong crc, const mz_uint8 *ptr, size_t buf_len) { // Generate the poly table on first use. // This should match what mhash calls `crc32_table_b` if (!poly_table[1]) { mz_uint32 i, j; for (i = 0; i < 256; i++) { mz_uint32 entry = i; for (j = 0; j < 8; j++) { if (entry & 1) entry = (entry >> 1) ^ 0xedb88320; else entry >>= 1; } poly_table[i] = entry; } } crc = ~crc; while (buf_len--) { crc = ((crc >> 8) & 0xffffff) ^ poly_table[(*ptr++ ^ crc) & 0xff]; } return ~crc; } I assume mz_crc32(mz_ulong crc(?), const mz_uint8 *ptr(A0 here?), size_t buf_len (d2 here?)) but how about crc ? ^ |
29 October 2016, 13:13 | #5 |
son of 68k
Join Date: Nov 2007
Location: Lyon / France
Age: 51
Posts: 5,323
|
|
30 October 2016, 09:18 | #6 |
Registered User
Join Date: Jul 2008
Location: Poland
Posts: 662
|
You mean:
Code:
mz_ulong mz_crc32(mz_ulong crc, const mz_uint8 *ptr, size_t buf_len) { return crc; } |
31 October 2016, 08:30 | #7 |
son of 68k
Join Date: Nov 2007
Location: Lyon / France
Age: 51
Posts: 5,323
|
|
01 February 2018, 23:17 | #8 | |
Registered User
Join Date: Aug 2007
Location: berlin/germany
Posts: 1,054
|
Quote:
like "1: bset.b #0,4(a1)\n" > "1: bset.b #0,(a1)\n" if so, yes it works. doesnt the size of operand matter something? i still get the same runtime error, so apparently this is not the issue, but it assembles with relatively slight change in comparison to original source. |
|
02 February 2018, 00:24 | #9 | |
Going nowhere
Join Date: Oct 2001
Location: United Kingdom
Age: 50
Posts: 8,986
|
Quote:
Its not having issues because of the 1: is it? |
|
02 February 2018, 08:22 | #10 |
Registered User
Join Date: Dec 2017
Location: Denmark
Posts: 179
|
I don't know any C/C++, but assembler.
Maybe it dont like offsets being written as 4(a1), but need it as (4,a1). Resource Disassembler writes it like that, and both methods work in Asm-pro. so: Code:
static inline void _atomic_stack_push(struct _atomic_stack* list, struct _atomic_item* item) { asm volatile(" move.l %0,a0\n" " move.l %1,a1\n" "1: bset.b #0,(4,a1)\n" " bne.b 1b\n" "2: move.l (a1),(a0)\n" " move.l a0,(a1)\n" " bclr.b #0,(4,a1)\n" : : "m" (item), "m" (list) : "a0", "a1", "cc", "memory" ); } |
05 February 2018, 16:35 | #11 |
Registered User
Join Date: Aug 2007
Location: berlin/germany
Posts: 1,054
|
Apparently Not. and your method doesnt help.
once upon a time i "fixed" it like this: Code:
asm volatile(" move.l %0,%%a0\n" " move.l %1,%%a1\n" "1: bset.b #0,4(%%a1)\n" " bne.b 1b\n" "2: move.l (%%a1),(%%a0)\n" " move.l %%a0,(%%a1)\n" " bclr.b #0,4(%%a1)\n" : : "m" (item), "m" (list) : "a0", "a1", "cc", "memory" Last edited by wawa; 05 February 2018 at 22:45. |
06 February 2018, 08:42 | #12 | |
Registered User
Join Date: Dec 2017
Location: Denmark
Posts: 179
|
Dont think %%A1 will work.
from here: https://gcc.gnu.org/onlinedocs/gcc/Extended-Asm.html Quote:
then this: "1: bset.b #0,4(a1)\n" would be the same as: "1: bset.l #0,(a1)\n" (only a little slower) so maybe this will work: Code:
removed Last edited by LaBodilsen; 06 February 2018 at 09:08. Reason: meynaf corrected me, need more coffee |
|
06 February 2018, 08:56 | #13 |
son of 68k
Join Date: Nov 2007
Location: Lyon / France
Age: 51
Posts: 5,323
|
Should be 3(a1) rather than 4(a1) in the above code, but anyway bset has no size. Assemblers can eventually accept bset.b because the target is always bytes, but everything else is plain wrong (and can easily lead to faulty code).
|
06 February 2018, 09:06 | #14 | |
Registered User
Join Date: Dec 2017
Location: Denmark
Posts: 179
|
Quote:
Only when adressing a Data register direct, is the size Long, all else is byte size. previous post "scrambled" |
|
06 February 2018, 19:00 | #15 |
Registered User
Join Date: Aug 2007
Location: berlin/germany
Posts: 1,054
|
ok, guys, are you telling me that this assembly code is wrong anyway? and that "bset.b" should actually be "bset"?
i have made a c testcase source: Code:
static inline void _atomic_stack_push(struct _atomic_stack* list, struct _atomic_item* item) { asm volatile(" move.l %0,a0\n" " move.l %1,a1\n" "1: bset.b #0,4(a1)\n" " bne.b 1b\n" "2: move.l (a1),(a0)\n" " move.l a0,(a1)\n" " bclr.b #0,4(a1)\n" : : "m" (item), "m" (list) : "a0", "a1", "cc", "memory" ); } perhaps it is some compile flag on aros part, perhaps pedantic. so, if the code is wrong, can i ask you guys to correct it? there are just few 68k inlines here in frying pan source. |
07 February 2018, 10:35 | #16 |
Registered User
Join Date: Dec 2017
Location: Denmark
Posts: 179
|
It's only wrong in the sence that bset is always byte size, so no need to set .b on it.
But if it compiles fine with bset.b #0,(a1), then this is not the problem. but i suspect that it have a problem with the way that offsets are written. eg 4(a1). did you try it with bset.b #0,(4,a1) instead? |
07 February 2018, 14:05 | #17 |
Registered User
Join Date: Aug 2007
Location: berlin/germany
Posts: 1,054
|
Yes,i tried it, but it didnt help.
|
07 February 2018, 15:39 | #18 |
son of 68k
Join Date: Nov 2007
Location: Lyon / France
Age: 51
Posts: 5,323
|
Of course it will not help if the offset is wrong.
Again, last byte of a long is +3, not +4 (offsets are 0, +1, +2, +3, total 4 bytes). +4 is first byte of next long. |
07 February 2018, 17:24 | #19 |
Registered User
Join Date: Aug 2007
Location: berlin/germany
Posts: 1,054
|
but the assembler shouldnt complain about that (syntax), just the code wouldnt work, am i rght? so:
bset.b #0,4(a1)\n translates to: bset #0,(3,a1)\n ? |
07 February 2018, 17:35 | #20 |
son of 68k
Join Date: Nov 2007
Location: Lyon / France
Age: 51
Posts: 5,323
|
For the assembler there should be no difference between :
Code:
bset #0,3(a1) bset #0,(3,a1) bset.b #0,3(a1) bset.b #0,(3,a1) bset is same as bset.b because it has no size. Then perhaps some assemblers will accept one form and reject another. But if your code assembles with no error and the resulting code doesn't work, then there is a bug to be fetched elsewhere in the program. |
Currently Active Users Viewing This Thread: 1 (0 members and 1 guests) | |
Thread Tools | |
Similar Threads | ||||
Thread | Thread Starter | Forum | Replies | Last Post |
Tool to convert asm to gnu asm (gas) | Asman | Coders. Asm / Hardware | 13 | 30 December 2020 11:57 |
Inline ASM | xArtx | Coders. Asm / Hardware | 10 | 27 July 2014 16:21 |
XAMOS - new cross-platform rewrite of jAMOS | Mequa | News | 24 | 14 December 2012 09:49 |
Storm C V4...using inline assembler | NovaCoder | Coders. General | 11 | 26 February 2009 12:10 |
Syntax Error in IE. | Fred the Fop | project.EAB | 2 | 04 October 2002 14:47 |
|
|