English Amiga Board


Go Back   English Amiga Board > Coders > Coders. Language > Coders. C/C++

 
 
Thread Tools
Old 23 November 2020, 20:35   #1241
Samurai_Crow
Total Chaos forever!
 
Samurai_Crow's Avatar
 
Join Date: Aug 2007
Location: Waterville, MN, USA
Age: 49
Posts: 2,186
Quote:
Originally Posted by ciVic View Post
Hi all!

I'm trying this:

Code:
#include <string>
#include <fstream>
#include <iostream>
using namespace std;

int main (int argc, char *argv[])
{
    cout << "running test" << endl;
    ofstream out("test.dat");
    out << "Hallo Welt";
    out.close();
    return 0;
}
Compiling this way writes data to file but crashes afterwards:

Code:
m68k-amigaos-g++  -mcrt=clib2  main.cpp
If I omit -mcrt=clib2 it works. I'm using m68k-amigaos-g++ (GCC) 6.5.0b 200706181046 and my last pull was last week.
If CLib2 doesn't work, try LibNix.
Samurai_Crow is offline  
Old 23 November 2020, 21:55   #1242
ciVic
Registered User
 
Join Date: Oct 2013
Location: Germany
Posts: 39
Quote:
Originally Posted by Samurai_Crow View Post
If CLib2 doesn't work, try LibNix.

Thx but I have no choice. I need a lib that was compiled with clib2 and then the exe cannot use a different system afaik.
ciVic is offline  
Old 24 November 2020, 15:57   #1243
Warty
Registered User
 
Join Date: Aug 2018
Location: Minneapolis, USA
Posts: 301
What's the current version of Bebbo's bgdbserver? The link on his page to version 6 is a 404. I was working on some code for deleting files recursively, and well, I seem to have deleted the contents of my 'test' directory, including bgdbserver. Version 5 is available on the web site, but I think that's an older version, as it requires -r.

Is there a version 7 coming? Anybody have a link to 6 I could use?

404:
https://franke.ms/amiga/bgdbserver_6.zip

from:
https://franke.ms/amiga/gdb-eclipse.wiki
Warty is offline  
Old 24 November 2020, 19:26   #1244
bebbo
bye
 
Join Date: Jun 2016
Location: Some / Where
Posts: 680
Quote:
Originally Posted by Warty View Post
What's the current version of Bebbo's bgdbserver? The link on his page to version 6 is a 404. I was working on some code for deleting files recursively, and well, I seem to have deleted the contents of my 'test' directory, including bgdbserver. Version 5 is available on the web site, but I think that's an older version, as it requires -r.

Is there a version 7 coming? Anybody have a link to 6 I could use?

404:
https://franke.ms/amiga/bgdbserver_6.zip

from:
https://franke.ms/amiga/gdb-eclipse.wiki

the correct link is: https://franke.ms/download/bgdbserver_6.zip - I updated the page. Thank you!
bebbo is offline  
Old 25 November 2020, 21:05   #1245
Warty
Registered User
 
Join Date: Aug 2018
Location: Minneapolis, USA
Posts: 301
Awesome, thanks Bebbo!
Warty is offline  
Old 01 February 2021, 02:02   #1246
mateusz_s
Registered User
 
Join Date: Jan 2020
Location: Poland
Posts: 181
Quote:
Originally Posted by bebbo View Post
the correct link is: https://franke.ms/download/bgdbserver_6.zip - I updated the page. Thank you!
What that server does? Is it got some special features? For testing my apps I was planning to just static win running winuae, compiling the output to shared folder, and just relaunching the exe after every new build.
mateusz_s is offline  
Old 02 February 2021, 07:21   #1247
thyslo
Registered User
 
Join Date: Apr 2018
Location: Germany
Posts: 189
I try to port some code from SAS-C. It's a callback function defined like this:
Code:
int __asm __saveds QBobFunc(register __a1 struct myBltNode *node)
{
...
}
Can I achive this somehow with gcc, too?
thyslo is offline  
Old 02 February 2021, 08:50   #1248
bebbo
bye
 
Join Date: Jun 2016
Location: Some / Where
Posts: 680
Quote:
Originally Posted by mateusz_s View Post
What that server does? Is it got some special features? For testing my apps I was planning to just static win running winuae, compiling the output to shared folder, and just relaunching the exe after every new build.

the bgdbserver allows you to debug your program on the Amiga remotely.
What you need is a working TCP/IP stack on your Amiga, then you can debug the program even on a real Amiga.


debugging > printf
bebbo is offline  
Old 02 February 2021, 08:53   #1249
bebbo
bye
 
Join Date: Jun 2016
Location: Some / Where
Posts: 680
Quote:
Originally Posted by thyslo View Post
I try to port some code from SAS-C. It's a callback function defined like this:
Code:
int __asm __saveds QBobFunc(register __a1 struct myBltNode *node)
{
...
}
Can I achive this somehow with gcc, too?

Code:
int __saveds QBobFunc(struct myBltNode *node asm("a1"))
{
...
}

__saveds is only needed if a baserel data model is used - it means that the function loads the a4 register. Useful in callbacks given to someone else or interrupt handlers... the latter may also need the __interrupt attribute.
bebbo is offline  
Old 02 February 2021, 10:31   #1250
thyslo
Registered User
 
Join Date: Apr 2018
Location: Germany
Posts: 189
Thanks a lot, this works
thyslo is offline  
Old 07 March 2021, 18:03   #1251
zero
Registered User
 
Join Date: Jun 2016
Location: UK
Posts: 428
Is it me or does KPrintF formatting not work? I tried this:

KPrintF("Right: %d\n", 112);

And the output is

"Right: 0"
zero is offline  
Old 07 March 2021, 18:22   #1252
alkis
Registered User
 
Join Date: Dec 2010
Location: Athens/Greece
Age: 53
Posts: 719
Quote:
Originally Posted by zero View Post
Is it me or does KPrintF formatting not work? I tried this:

KPrintF("Right: %d\n", 112);

And the output is

"Right: 0"
Try %ld
Every parameter in variadic functions is promoted to longs (32bits)
alkis is offline  
Old 07 March 2021, 20:45   #1253
zero
Registered User
 
Join Date: Jun 2016
Location: UK
Posts: 428
Quote:
Originally Posted by alkis View Post
Try %ld
Every parameter in variadic functions is promoted to longs (32bits)
Thanks, that works.
zero is offline  
Old 11 March 2021, 09:00   #1254
mateusz_s
Registered User
 
Join Date: Jan 2020
Location: Poland
Posts: 181
@Bebbo Hello, I just started using Your GCC 6.5.0b from that link" https://github.com/bebbo/amiga-gcc/releases/tag/gridone

I found this strange behaviour in performance between unsigned int and ULONG/LONG types.


I made dynamic int or LONG buffer to generate graphic there:
Code:
unsigned int* my_buf_1 = (unsigned int*)malloc(size);
and copy it to rtg output using CGX api, here are the results:


Code:
*******
with flags: -O3 -noixemul -lm -Wall :

ULONG - 30fps
LONG - 70fps
int / unsigned int - 171 fps

with theese flags: -O3 -noixemul -lm -Wall -march=68060 -mcpu=68060 -mtune=68060 -mhard-float -68881:

ULONG - 70fps
LONG - 70fps
int / unsigned int - 180 fps

*******

You can see the differences in both generated asm sources,
generated by this Diffchecker website by one of ppa.pl portal users @san_u:
https://www.diffchecker.com/gi3FDbkt



mateusz_s is offline  
Old 11 March 2021, 16:05   #1255
mschulz
Registered User
 
Join Date: Nov 2018
Location: Germany
Posts: 110
Quote:
Originally Posted by mateusz_s View Post
@Bebbo Hello, I just started using Your GCC 6.5.0b from that link" https://github.com/bebbo/amiga-gcc/releases/tag/gridone

I found this strange behaviour in performance between unsigned int and ULONG/LONG types.
Hi. If you want to analyze code, always try to make a test case which is short enough to allow one to analyze it properly. The diff you have provided is very nice, but not really optimal to follow it. I have toyed with the code a little and extracted the innermost loop which was problematic:

Code:
#include <exec/types.h>
#include <stdlib.h>

ULONG APP_requested_width = 320;
ULONG APP_requested_height = 240;
ULONG APP_requested_depth = 24;

void* APP_Main_Loop(unsigned int fade)
{
    int size = APP_requested_width * APP_requested_height * sizeof(int);
    unsigned int* my_buf_1 = (unsigned int*)malloc(size);

    for (int y = 0; y < APP_requested_height; ++y)
        for(int x = 0; x < APP_requested_width; ++x)
        {
            my_buf_1[x + y * APP_requested_width] = (unsigned int)fade<<24;
        }

    return my_buf_1;
}
I have added few simplifications there, the code also returns the allocated pointer in order to prevent gcc from optimizing it away. The code compiled with flags -m68020 -m68881 -Os -fomit-frame-pointer, outputs following assembly:

Code:
_APP_requested_width:
        .long   320
_APP_requested_height:
        .long   240
_APP_requested_depth:
        .long   24
__Z13APP_Main_Loopj:
        movem.l d5/d4/d3/d2,-(sp)
        move.l _APP_requested_width,d3
        move.l _APP_requested_height,d2
        move.l d3,d0
        muls.l d2,d0
        lsl.l #2,d0
        move.l d0,-(sp)
        jsr _malloc
        move.l (24,sp),d4
        moveq #24,d1
        lsl.l d1,d4
        move.l d3,d5
        lsl.l #2,d5
        move.l d0,a0
        addq.l #4,sp
        move.l d2,d1
.L5:
        dbra d1,.L6
        clr.w d1
        subq.l #1,d1
        jcc .L6
        movem.l (sp)+,d2/d3/d4/d5
        rts
.L6:
        move.l a0,a1
        move.l d3,d2
.L4:
        dbra d2,.L7
        clr.w d2
        subq.l #1,d2
        jcc .L7
        add.l d5,a0
        jra .L5
.L7:
        move.l d4,(a1)+
        jra .L4
Here, few comments and questions. First of all, you should know few underlying details of m68k architecture if you want to obtain optimal code. The loops counting on a 32-bit type can be slower on m68k. The DBxx instructions operate on 16-bit portion of register only. Therefore, changing the counters within loop from "unsigned int" to "unsigned short", or preferably to UWORD will allow gcc to use one DBxx instruction per loop.

Another issue are width and height parameters. Do they need to be changeable? Are they changed once when your code starts or can they be made const? If the latter is the case, it would allow gcc to optimize even more. Making them const and changing ints to shorts, i.e.:

Code:
#include <exec/types.h>
#include <stdlib.h>

const ULONG APP_requested_width = 320;
const ULONG APP_requested_height = 240;
const ULONG APP_requested_depth = 24;

void* APP_Main_Loop(unsigned int fade)
{
    int size = APP_requested_width * APP_requested_height * sizeof(int);
    unsigned int* my_buf_1 = (unsigned int*)malloc(size);

    for (UWORD y = 0; y < APP_requested_height; ++y)
        for(UWORD x = 0; x < APP_requested_width; ++x)
        {
            my_buf_1[x + y * APP_requested_width] = (unsigned int)fade<<24;
        }

    return my_buf_1;
}
allows gcc to show its strength:

Code:
__Z13APP_Main_Loopj:
        move.l d3,-(sp)
        move.l d2,-(sp)
        move.l #307200,-(sp)
        jsr _malloc
        move.l (16,sp),d2
        moveq #24,d1
        lsl.l d1,d2
        move.l d0,a0
        addq.l #4,sp
        move.w #239,d1
.L3:
        move.l a0,a1
        move.w #319,d3
.L2:
        move.l d2,(a1)+
        dbra d3,.L2
        lea (1280,a0),a0
        dbra d1,.L3
        move.l (sp)+,d2
        move.l (sp)+,d3
        rts
Or, if you prefer "asm coder" solution and want to work with faster loops, add "-funroll-loops" to the flags (-m68020 -m68881 -O3 -funroll-loops -fomit-frame-pointer) to obtain:

Code:
__Z13APP_Main_Loopj:
        movem.l d4/d3/d2,-(sp)
        move.l #307200,-(sp)
        jsr _malloc
        move.l (20,sp),d1
        moveq #24,d2
        lsl.l d2,d1
        move.l d0,d4
        addq.l #4,sp
        move.w #239,d3
.L3:
        move.l d4,a0
        moveq #39,d2
.L2:
        move.l a0,a1
        move.l d1,(a1)+
        move.l d1,(a1)+
        move.l d1,(a1)
        move.l d1,(12,a0)
        move.l d1,(16,a0)
        move.l d1,(20,a0)
        move.l d1,(24,a0)
        move.l d1,(28,a0)
        lea (32,a0),a0
        dbra d2,.L2
        add.l #1280,d4
        dbra d3,.L3
        movem.l (sp)+,d2/d3/d4
        rts
mschulz is offline  
Old 12 March 2021, 00:24   #1256
mateusz_s
Registered User
 
Join Date: Jan 2020
Location: Poland
Posts: 181
Thank You very much for very long answer. I am going to test all of that.
So do you suggest using shorts insted of ints where it is possible to have some speedups?


edit:
I must say, that I was checking different gcc flags, I switched ints into UINT8 or UINT16 where was possible,
changed width, height into CONST.. but there is almost no change at all in the performance.
It even looks like turning on/off 060/040 cpu flags doeasnt change anything..

maybe something is wrong with my gcc distribution, I used that precompiled version from msys2, that Bebo provided: http://franke.ms/download/setup-amiga-gcc.exe

Now I installed msys2 myself on Windows and build all distribution as described on Bebbos git hub page: https://github.com/bebbo/amiga-gcc

maybe that will help.. or maybe on winuae the differences can't be seen?

It looks like filling the whole buffer 320x240x32 even with simple calculations, takes ages


edit 2:
ok, it seems that all that changes works on that particular example You worked.
I run this test again there was a huge speed up..

I was talking about rest of my code, that is bigger and makes raycasts, on that code
there is no changes at all.. weird.. must be some kind of bottle neck..


edit 3:
I done more tests, and its amazing how changing WIDTH and HEIGHT from "int" into "const unsigned short" speeds up the whole thing from 190 fps to 550 fps !! (including all gcc flags you mentioned)
I have similar things in my full code - must change it and test.
Also in my full code I am dealing with RGBA struct that contains 4 unsigned chars. Thats also slows down. Must change it into unsigned int..


Thanks again..!

Last edited by mateusz_s; 12 March 2021 at 02:58.
mateusz_s is offline  
Old 14 March 2021, 14:08   #1257
mateusz_s
Registered User
 
Join Date: Jan 2020
Location: Poland
Posts: 181
@mschulz @Bebbo

The problem from above post is solved when I am compiling only one file main.c - the speed up is huuuge..

But I got a weird problem, when I am compiling multiple files like that, using this flags:

Code:
m68k-amigaos-gcc 
-Wall
-O3 -noixemul -march=68060 -mcpu=68060 -mtune=68060 -mhard-float -funroll-loops
main.c 
BM_Bitmap.c 
BM_Bitmap_TGA.c 
EM_Engine_Main.c 
GP_Gameplay.c
LV_Level.c  
MY_Draw.c 
MY_Math.c 
RC_Raycaster.c 
TM_Timer.c
-lm
 -o 
output
but when I am doing profiling theese soft-float functions are used:
Code:
__mulsf3
__subsf3
__addsf3
__ieee754_expf
__kernel_sinf
__ieee754_rem_pio2f
the efect is that everything is very sloooow again even on very fast cpus.
Additionally tutring off or on any flags makes no any effect

What am I doing wrong?
mateusz_s is offline  
Old 14 March 2021, 16:04   #1258
bebbo
bye
 
Join Date: Jun 2016
Location: Some / Where
Posts: 680
Quote:
Originally Posted by mateusz_s View Post
@mschulz @Bebbo

The problem from above post is solved when I am compiling only one file main.c - the speed up is huuuge..

But I got a weird problem, when I am compiling multiple files like that, using this flags:

Code:
m68k-amigaos-gcc 
-Wall
-O3 -noixemul -march=68060 -mcpu=68060 -mtune=68060 -mhard-float -funroll-loops
main.c 
BM_Bitmap.c 
BM_Bitmap_TGA.c 
EM_Engine_Main.c 
GP_Gameplay.c
LV_Level.c  
MY_Draw.c 
MY_Math.c 
RC_Raycaster.c 
TM_Timer.c
-lm
 -o 
output
but when I am doing profiling theese soft-float functions are used:
Code:
__mulsf3
__subsf3
__addsf3
__ieee754_expf
__kernel_sinf
__ieee754_rem_pio2f
the efect is that everything is very sloooow again even on very fast cpus.
Additionally tutring off or on any flags makes no any effect

What am I doing wrong?

maybe you are not linking against -noixemul ?
bebbo is offline  
Old 14 March 2021, 16:05   #1259
bebbo
bye
 
Join Date: Jun 2016
Location: Some / Where
Posts: 680
Quote:
Originally Posted by bebbo View Post
maybe you are not linking against -noixemul ?

or some of the libs aren't build with -mhard-float?
bebbo is offline  
Old 14 March 2021, 17:11   #1260
mateusz_s
Registered User
 
Join Date: Jan 2020
Location: Poland
Posts: 181
Thanks for answer @Bebbo, I will try compile this using make file and compiling separately all .c files into .o and then merge it
mateusz_s 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
New GCC based dev toolchain for AmigaOS 3.x cla Coders. Releases 8 24 December 2017 10:18
Issue with photon/xxxx WinUAE Toolchain arpz Coders. Asm / Hardware 2 26 September 2015 22:33
New 68k gcc toolchain arti Coders. C/C++ 17 31 July 2015 03:59
Hannibal's WinUAE Demo Toolchain 5 Bobic Amiga scene 1 23 July 2015 21:04
From gcc to vbcc. Cowcat Coders. General 9 06 June 2014 14:45

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 06:37.

Top

Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2024, vBulletin Solutions Inc.
Page generated in 0.32651 seconds with 16 queries