English Amiga Board


Go Back   English Amiga Board > Coders > Coders. Asm / Hardware

 
 
Thread Tools
Old 13 October 2016, 13:20   #1
wawa
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.
wawa is offline  
Old 14 October 2016, 11:42   #2
Apollo
Registered User

Apollo's Avatar
 
Join Date: Sep 2008
Location: Germany
Age: 46
Posts: 127
Quote:
Originally Posted by wawa View Post
1: bset.b #0,4(a1)\n
Maybe he just chokes on the size operand? Does it assemble withe size operand omitted?
Apollo is offline  
Old 14 October 2016, 14:24   #3
wawa
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.
wawa is offline  
Old 29 October 2016, 12:26   #4
arti
Registered User

 
Join Date: Jul 2008
Location: Poland
Posts: 565
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
instead of this:

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 ? ^
arti is offline  
Old 29 October 2016, 13:13   #5
meynaf
son of 68k
meynaf's Avatar
 
Join Date: Nov 2007
Location: Lyon / France
Age: 47
Posts: 3,925
Quote:
Originally Posted by arti View Post
and would like to use this crc32 algorithm in libz to speedup png decoding in netsurf.
Simple : drop crc computation completely. Showing a png doesn't need crc checking.
meynaf is offline  
Old 30 October 2016, 09:18   #6
arti
Registered User

 
Join Date: Jul 2008
Location: Poland
Posts: 565
You mean:

Code:
mz_ulong mz_crc32(mz_ulong crc, const mz_uint8 *ptr, size_t buf_len)
{
  return crc;
}
This gives CRC error.
arti is offline  
Old 31 October 2016, 08:30   #7
meynaf
son of 68k
meynaf's Avatar
 
Join Date: Nov 2007
Location: Lyon / France
Age: 47
Posts: 3,925
Quote:
Originally Posted by arti View Post
You mean:

Code:
mz_ulong mz_crc32(mz_ulong crc, const mz_uint8 *ptr, size_t buf_len)
{
  return crc;
}
This gives CRC error.
No, i mean not even calling that function and not checking crc result at all. Look where this function is called, not the function itself.
meynaf is offline  
Old 01 February 2018, 23:17   #8
wawa
Registered User
 
Join Date: Aug 2007
Location: berlin/germany
Posts: 1,054
Quote:
Originally Posted by Apollo View Post
Maybe he just chokes on the size operand? Does it assemble withe size operand omitted?
..long time gone, i applied probably wrong fix, back on it..

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.
wawa is offline  
Old 02 February 2018, 00:24   #9
Galahad/FLT
Going nowhere

Galahad/FLT's Avatar
 
Join Date: Oct 2001
Location: United Kingdom
Age: 47
Posts: 7,720
Quote:
Originally Posted by wawa View Post
..long time gone, i applied probably wrong fix, back on it..

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.
you can't do that, because that instruction is doing a bitset on the contents of A0 + 4, later in that routine of yours it does a BCLR to the same offset.

Its not having issues because of the 1: is it?
Galahad/FLT is online now  
Old 02 February 2018, 08:22   #10
LaBodilsen
Registered User

 
Join Date: Dec 2017
Location: Gandrup / Denmark
Posts: 92
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"
);
}
LaBodilsen is offline  
Old 05 February 2018, 16:35   #11
wawa
Registered User
 
Join Date: Aug 2007
Location: berlin/germany
Posts: 1,054
Quote:
Originally Posted by Galahad/FLT View Post

Its not having issues because of the 1: is it?
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"
it assembles, but i dont know if it actually works. have a feeling it might not.

Last edited by wawa; 05 February 2018 at 22:45.
wawa is offline  
Old 06 February 2018, 08:42   #12
LaBodilsen
Registered User

 
Join Date: Dec 2017
Location: Gandrup / Denmark
Posts: 92
Dont think %%A1 will work.
from here: https://gcc.gnu.org/onlinedocs/gcc/Extended-Asm.html

Quote:
Special format strings
In addition to the tokens described by the input, output, and goto operands, these tokens have special meanings in the assembler template:

‘%%’
Outputs a single ‘%’ into the assembler code.
But looking at the assembly code, and if it fails to compile offsets for address registers.

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
btw: if you want the Assembly code translated to something readable, that you can implement in C, let us now. I think it would be easy to create some psydo-code out if these few lines.

Last edited by LaBodilsen; 06 February 2018 at 09:08. Reason: meynaf corrected me, need more coffee
LaBodilsen is offline  
Old 06 February 2018, 08:56   #13
meynaf
son of 68k
meynaf's Avatar
 
Join Date: Nov 2007
Location: Lyon / France
Age: 47
Posts: 3,925
Quote:
Originally Posted by LaBodilsen View Post
then this: "1: bset.b #0,4(a1)\n"

would be the same as: "1: bset.l #0,(a1)\n"
(only a little slower)
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).
meynaf is offline  
Old 06 February 2018, 09:06   #14
LaBodilsen
Registered User

 
Join Date: Dec 2017
Location: Gandrup / Denmark
Posts: 92
Quote:
Originally Posted by meynaf View Post
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).
You are ofcourse right (need more coffee).

Only when adressing a Data register direct, is the size Long, all else is byte size.

previous post "scrambled"
LaBodilsen is offline  
Old 06 February 2018, 19:00   #15
wawa
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"
         );
}
plainly invoked with no flags both aros compilers i use and bebbos 6.3 are fine about this code. aros-4.6.4 complains about no "main" function, but both aros-6.3.0 and bebbos one have even built me a binary with few warnings.

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.
wawa is offline  
Old 07 February 2018, 10:35   #16
LaBodilsen
Registered User

 
Join Date: Dec 2017
Location: Gandrup / Denmark
Posts: 92
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?
LaBodilsen is offline  
Old 07 February 2018, 14:05   #17
wawa
Registered User
 
Join Date: Aug 2007
Location: berlin/germany
Posts: 1,054
Yes,i tried it, but it didnt help.
wawa is offline  
Old 07 February 2018, 15:39   #18
meynaf
son of 68k
meynaf's Avatar
 
Join Date: Nov 2007
Location: Lyon / France
Age: 47
Posts: 3,925
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.
meynaf is offline  
Old 07 February 2018, 17:24   #19
wawa
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

?
wawa is offline  
Old 07 February 2018, 17:35   #20
meynaf
son of 68k
meynaf's Avatar
 
Join Date: Nov 2007
Location: Lyon / France
Age: 47
Posts: 3,925
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)
3(a1) vs (3,a1) is simply 68000 vs 68020 syntax. And no, 4 doesn't translate to 3
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.
meynaf is offline  
 


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools

Similar Threads
Thread Thread Starter Forum Replies Last Post
Inline ASM xArtx Coders. Asm / Hardware 10 27 July 2014 16:21
Tool to convert asm to gnu asm (gas) Asman Coders. Asm / Hardware 6 12 October 2013 12:45
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

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +2. The time now is 22:26.


Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2020, vBulletin Solutions Inc.
Page generated in 0.10302 seconds with 13 queries