07 September 2018, 00:03 | #441 | ||
Registered User
Join Date: Jul 2005
Location: -
Posts: 1,696
|
Quote:
Quote:
|
||
07 September 2018, 09:12 | #442 | |
Registered User
Join Date: Mar 2016
Location: Australia
Posts: 881
|
Quote:
Code:
void drawline(register int x0 asm("d1"), register int y0 asm("d2"), register int c asm("d3"), register int dx asm("d4"), register int dy asm("d5")) { int p, x, y, x1; x=x0; y=y0; x1=x0+dx; p=2*dy-dx; while(x<x1) { if(p>=0) { putpixel(x,y,c); y=y+1; p=p+2*dy-2*dx; } else { putpixel(x,y,c); p=p+2*dy; } x=x+1; } } Code:
m68k-amigaosvasm-gcc -fomit-frame-pointer -Os -S line.c Code:
_drawline: movem.l a3/a2/d7/d6/d5/d4/d3/d2,-(sp) move.l d1,d7 move.l d1,a3 add.l d4,a3 add.l d5,d5 move.l d5,d6 sub.l d4,d6 add.l d4,d4 lea _putpixel,a2 _.L2: cmp.l d7,a3 jgt _.L5 movem.l (sp)+,d2/d3/d4/d5/d6/d7/a2/a3 rts _.L5: tst.l d6 jlt _.L3 move.l d3,-(sp) move.l d2,-(sp) move.l d7,-(sp) jsr (a2) addq.l #1,d2 add.l d5,d6 sub.l d4,d6 _.L6: lea (12,sp),sp addq.l #1,d7 jra _.L2 _.L3: move.l d3,-(sp) move.l d2,-(sp) move.l d7,-(sp) jsr (a2) add.l d5,d6 jra _.L6 I didn't have time to confirm that the C is correct (only spent 1 minute on this), but it's interesting either way. |
|
07 September 2018, 09:17 | #443 |
Registered User
Join Date: Mar 2016
Location: Australia
Posts: 881
|
Realised it was passing the params to putpixel via the stack so update:
Code:
extern void putpixel(register int x0 asm("d1"), register int y0 asm("d2"), register int c asm("d3")); void drawline(register int x0 asm("d1"), register int y0 asm("d2"), register int c asm("d3"), register int dx asm("d4"), register int dy asm("d5")) { int p, x, y, x1; x=x0; y=y0; x1=x0+dx; p=2*dy-dx; while(x<x1) { if(p>=0) { putpixel(x,y,c); y=y+1; p=p+2*dy-2*dx; } else { putpixel(x,y,c); p=p+2*dy; } x=x+1; } } Code:
_drawline: movem.l a5/a4/a3/a2/d7/d6/d5/d4/d3/d2,-(sp) move.l d1,d7 move.l d2,a2 move.l d3,a3 move.l d1,a4 add.l d4,a4 add.l d5,d5 move.l d5,d6 sub.l d4,d6 add.l d4,d4 lea _putpixel,a5 _.L2: cmp.l d7,a4 jgt _.L5 movem.l (sp)+,d2/d3/d4/d5/d6/d7/a2/a3/a4/a5 rts _.L5: move.l a3,d3 move.l a2,d2 move.l d7,d1 tst.l d6 jlt _.L3 jsr (a5) addq.l #1,a2 add.l d5,d6 sub.l d4,d6 _.L4: addq.l #1,d7 jra _.L2 _.L3: jsr (a5) add.l d5,d6 jra _.L4 |
07 September 2018, 09:35 | #444 | |
son of 68k
Join Date: Nov 2007
Location: Lyon / France
Age: 51
Posts: 5,323
|
Quote:
More precisely, if you examine the C code you will notice it can draw a line only if dx,dy are positive values (IOW x,y positions can only increase). But my routine has to draw lines with just about any direction... |
|
07 September 2018, 09:54 | #445 | |
Registered User
Join Date: Mar 2016
Location: Australia
Posts: 881
|
Quote:
Code:
extern void putpixel(register int x0 asm("d1"), register int y0 asm("d2"), register int c asm("d3")); void drawline(register int x0 asm("d1"), register int y0 asm("d2"), register int c asm("d3"), register int dx asm("d4"), register int dy asm("d5")) { int x1 = x0 + dx; int y1 = y0 + dy; int sx = x0 < x1 ? 1 : -1; int sy = y0 < y1 ? 1 : -1; int err = dx + dy, e2; /* error value e_xy */ for (;;){ /* loop */ putpixel(x0,y0,c); if (x0 == x1 && y0 == y1) break; e2 = 2 * err; if (e2 >= dy) { err += dy; x0 += sx; } /* e_xy+e_x > 0 */ if (e2 <= dx) { err += dx; y0 += sy; } /* e_xy+e_y < 0 */ } } Code:
_drawline: subq.l #4,sp movem.l a6/a5/a4/a3/a2/d7/d6/d5/d4/d3/d2,-(sp) move.l d1,a3 move.l d2,a2 move.l d3,44(sp) lea (a3,d4.l),a5 lea (a2,d5.l),a6 cmp.l d1,a5 sle d7 ext.w d7 ext.l d7 moveq #1,d0 or.l d0,d7 cmp.l d2,a6 sle d6 ext.w d6 ext.l d6 or.l d0,d6 move.l d4,a4 add.l d5,a4 _.L4: move.l 44(sp),d3 move.l a2,d2 move.l a3,d1 jsr _putpixel cmp.l a3,a5 jne _.L5 cmp.l a2,a6 jeq _.L1 _.L5: move.l a4,d0 add.l a4,d0 cmp.l d5,d0 jlt _.L7 add.l d5,a4 add.l d7,a3 _.L7: cmp.l d4,d0 jgt _.L4 add.l d4,a4 add.l d6,a2 jra _.L4 _.L1: movem.l (sp)+,d2/d3/d4/d5/d6/d7/a2/a3/a4/a5/a6 addq.l #4,sp rts |
|
07 September 2018, 10:36 | #446 |
son of 68k
Join Date: Nov 2007
Location: Lyon / France
Age: 51
Posts: 5,323
|
Not seeing anything obvious i tried it directly. Got endless loop filling a large pixel area.
Please check your code ; hit-and-miss has its limits |
07 September 2018, 16:42 | #447 |
Registered User
Join Date: Jun 2015
Location: Germany
Posts: 1,918
|
Comparing the x86 and 68k ISAs is a pretty easy job. The 68k Instruction Set Architecture is like a nice house with four bedrooms, two bathrooms and a garage for two cars. The x86 Instruction Set Architecture is a shed that has lots of rooms added for the newborn kids, other parts wrecked, windows and doors broken into walls, others bricked up, new floors added on top with staircases added to be able to go there. It is clear which one is the better Architecture. However, it may be correct to say that the shed with the added rooms may have been economically more feasible for a young couple planning to have children that couldn't afford building a house with four bedrooms right from the start.
Intel could put much more money into R&D to work around the quirks of their architecture and into developing a semiconductor process that has been at least one node size ahead of all competition. They simply can afford to put a far more complex core onto a chip because they can produce the chips with smaller feature size. Just have a look at processors of a comparable generation and speed: 1993: Pentium 3.1 million transistors 1994: 68060 2.5 million transistors 1994: PPC603 1.6 million transistors Intel could afford putting more transistors on a die earlier than the others and still make a ton of money. |
08 September 2018, 01:01 | #448 | |
Registered User
Join Date: Mar 2016
Location: Australia
Posts: 881
|
Quote:
It's still just a cut and paste from here, I am guessing even the C is not optimal the way I hacked it to your API spec (most of the line draw implementations that come up from a search go x0,y0,x1,y1 rather than x,y,dx,dy) Code:
#define __REG(reg, arg) register arg asm(reg) extern void putpixel(__REG("d1", int x0), __REG("d2", int y0), __REG("d3", int c)); void drawline(__REG("d1", int x0), __REG("d2", int y0), __REG("d3", int c), __REG("d4", int _dx), __REG("d5", int _dy)) { int x1 = x0+_dx; int y1 = y0+_dy; int dx = _dx < 0 ? -_dx : _dx; int dy = _dy < 0 ? -_dy : _dy; int sx = x0 < x1 ? 1 : -1; int sy = y0 < y1 ? 1 : -1; int err = dx - dy, e2; /* error value e_xy */ for (;;){ /* loop */ putpixel (x0,y0,c); if (x0 == x1 && y0 == y1) break; e2 = 2 * err; if (e2 <= dy) { err -= dy; x0 += sx; } /* e_xy+e_x > 0 */ if (e2 <= dx) { err += dx; y0 += sy; } /* e_xy+e_y < 0 */ } } Code:
_drawline: subq.l #4,sp movem.l a6/a5/a4/a3/a2/d7/d6/d5/d4/d3/d2,-(sp) move.l d1,a4 move.l d2,a3 move.l d3,44(sp) lea (a4,d4.l),a5 lea (a3,d5.l),a6 tst.l d4 jge _.L2 neg.l d4 _.L2: tst.l d5 jge _.L3 neg.l d5 _.L3: cmp.l a4,a5 sle d7 ext.w d7 ext.l d7 moveq #1,d0 or.l d0,d7 cmp.l a3,a6 sle d6 ext.w d6 ext.l d6 or.l d0,d6 move.l d4,a2 sub.l d5,a2 _.L6: move.l 44(sp),d3 move.l a3,d2 move.l a4,d1 jsr _putpixel cmp.l a4,a5 jne _.L7 cmp.l a3,a6 jeq _.L1 _.L7: move.l a2,d0 add.l a2,d0 cmp.l d5,d0 jgt _.L9 sub.l d5,a2 add.l d7,a4 _.L9: cmp.l d4,d0 jgt _.L6 add.l d4,a2 add.l d6,a3 jra _.L6 _.L1: movem.l (sp)+,d2/d3/d4/d5/d6/d7/a2/a3/a4/a5/a6 addq.l #4,sp rts |
|
08 September 2018, 08:57 | #449 | ||
son of 68k
Join Date: Nov 2007
Location: Lyon / France
Age: 51
Posts: 5,323
|
Quote:
EDIT: spoke too fast. Messed up with my if/endc and was using my routine instead It actually freezes if doing draw 120,100,7,1... Quote:
That's the reason why d1,d2 are updated in my code (something not straightforward in C). Last edited by meynaf; 08 September 2018 at 10:10. Reason: oops - wrong routine used |
||
08 September 2018, 10:46 | #450 | |
Registered User
Join Date: Mar 2016
Location: Australia
Posts: 881
|
Quote:
Code:
#define __REG(reg, arg) register arg asm(reg) #define abs(x) ((x) < 0 ? -(x) : (x)) extern void putpixel(__REG("d1", int x0), __REG("d2", int y0), __REG("d3", int c)); void drawline(__REG("d1", int x0), __REG("d2", int y0), __REG("d3", int c), __REG("d4", int _dx), __REG("d5", int _dy)) { int x1 = _dx + x0; int y1 = _dy + y0; int dx = abs (x1 - x0), sx = x0 < x1 ? 1 : -1; int dy = -abs (y1 - y0), sy = y0 < y1 ? 1 : -1; int err = dx + dy, e2; /* error value e_xy */ for (;;){ /* loop */ putpixel(x0,y0,c); if (x0 == x1 && y0 == y1) break; e2 = 2 * err; if (e2 >= dy) { err += dy; x0 += sx; } /* e_xy+e_x > 0 */ if (e2 <= dx) { err += dx; y0 += sy; } /* e_xy+e_y < 0 */ } } Code:
_drawline: subq.l #8,sp movem.l a6/a5/a4/a3/a2/d7/d6/d5/d4/d3/d2,-(sp) move.l d1,a4 move.l d2,a2 move.l d3,48(sp) lea (a4,d4.l),a3 lea (a2,d5.l),a6 tst.l d4 jge _.L2 neg.l d4 _.L2: cmp.l a4,a3 sle d7 ext.w d7 ext.l d7 moveq #1,d0 or.l d0,d7 tst.l d5 jge _.L4 neg.l d5 _.L4: move.l d5,d0 neg.l d0 move.l d0,44(sp) cmp.l a2,a6 sle d6 ext.w d6 ext.l d6 moveq #1,d0 or.l d0,d6 move.l d4,a5 sub.l d5,a5 _.L6: move.l 48(sp),d3 move.l a2,d2 move.l a4,d1 jsr _putpixel cmp.l a4,a3 jne _.L7 cmp.l a2,a6 jeq _.L1 _.L7: move.l a5,d0 add.l a5,d0 cmp.l 44(sp),d0 jlt _.L9 sub.l d5,a5 add.l d7,a4 cmp.l d4,d0 jgt _.L6 _.L9: add.l d4,a5 add.l d6,a2 jra _.L6 _.L1: movem.l (sp)+,d2/d3/d4/d5/d6/d7/a2/a3/a4/a5/a6 addq.l #8,sp rts |
|
08 September 2018, 10:59 | #451 |
son of 68k
Join Date: Nov 2007
Location: Lyon / France
Age: 51
Posts: 5,323
|
Now it works (yes, really).
But again, please, next time you submit code, debug it first. This would save us a lot of time. |
08 September 2018, 11:08 | #452 |
Registered User
Join Date: Mar 2016
Location: Australia
Posts: 881
|
|
08 September 2018, 12:40 | #453 |
son of 68k
Join Date: Nov 2007
Location: Lyon / France
Age: 51
Posts: 5,323
|
|
08 September 2018, 14:32 | #454 | |
Registered User
Join Date: Mar 2016
Location: Australia
Posts: 881
|
Quote:
It’s fun to compare hand crafted asm with C generated equivalent, surely you have some stuff in your library you want to share. We could also compare some other architectures with GCC. |
|
08 September 2018, 14:56 | #455 | ||
son of 68k
Join Date: Nov 2007
Location: Lyon / France
Age: 51
Posts: 5,323
|
Quote:
I had to do what you didn't do. Quote:
I do have, however, something that i'd like to have in c or cpp (must compile in VS at least). And it can't be too fast. But it's big, way beyond the scope of this thread, and if you don't have time to invest for testing a small routine then for that thing it's hopeless. |
||
08 September 2018, 15:55 | #456 | ||
Registered User
Join Date: Sep 2007
Location: Stockholm
Posts: 4,334
|
Quote:
Quote:
You would have had a point of the x86 had had 24-bit addressing with 24-bit addressing registers. But it doesn't have that — it has a segment register which is a nightmare both for assembly programmers and for compilers. PC relative addressing solves the same problem without dividing the entire address space into separate little compartments. A programmer-friendly (or compiler-friendly) ISA makes for faster and safer code. It is also fundamental when choosing an architecture – do note that almost all 16/32-bit designs before the rise of RISC used a Motorola 680x0 and that almost none used the x86. |
||
08 September 2018, 17:09 | #457 |
son of 68k
Join Date: Nov 2007
Location: Lyon / France
Age: 51
Posts: 5,323
|
The story of why IBM used 8088 :
https://spectrum.ieee.org/tech-histo...microprocessor In short, the only other competitor was TMS9900 because 68000 was not ready at the time and they wanted their computer to be put to market fast. Compare 64Kb with 1MB... Job done... |
08 September 2018, 22:12 | #458 | |
Registered User
Join Date: Mar 2016
Location: Ozherele
Posts: 229
|
Quote:
Code:
//x0 - d1, y0 - d2, c - d3, dx - d4, dy - d5 void drawline(register int x0, register int y0, register int c, register int dx, register int dy) { int sx = dx > 0 ? 1 : -1; //a0 int sy = dy > 0 ? 1 : -1; //a1 dx = abs(dx); dy = abs(dy); int xc = dx; if (dx < dy) xc = dy; //xc = max(dx, dy) int lc = xc, sa = xc; //d0, a2 xc >>= 1; //d6 int yc = xc; //d7 goto l1; do { if ((xc -= dx) <= 0) { x0 += sx; xc += sa; } if ((yc -= dy) <= 0) { y0 += sy; yc += sa; } l1: putpixel(x0, y0, c); } while (--lc >= 0); } EDIT. I'm sorry I have made a typo in my C code, it was an excessive minus sign. The mistake is corrected. I hope to make x86 code soon. Last edited by litwr; 08 September 2018 at 22:31. |
|
09 September 2018, 07:57 | #459 | ||
son of 68k
Join Date: Nov 2007
Location: Lyon / France
Age: 51
Posts: 5,323
|
Quote:
Quote:
Data coming out of ABS is necessarily a positive value. So this does not matter. At least you've checked if your C code works. Not eveyone does this here |
||
09 September 2018, 08:16 | #460 | |
Registered User
Join Date: Mar 2016
Location: Australia
Posts: 881
|
Quote:
|
|
Currently Active Users Viewing This Thread: 1 (0 members and 1 guests) | |
Thread Tools | |
Similar Threads | ||||
Thread | Thread Starter | Forum | Replies | Last Post |
Any software to see technical OS details? | necronom | support.Other | 3 | 02 April 2016 12:05 |
2-star rarity details? | stet | HOL suggestions and feedback | 0 | 14 December 2015 05:24 |
EAB's FTP details... | Basquemactee1 | project.Amiga File Server | 2 | 30 October 2013 22:54 |
req details for sdl | turrican3 | request.Other | 0 | 20 April 2008 22:06 |
Forum Details | BippyM | request.Other | 0 | 15 May 2006 00:56 |
|
|