English Amiga Board


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

 
 
Thread Tools
Old 20 January 2017, 18:52   #41
Thorham
Computer Nerd
 
Thorham's Avatar
 
Join Date: Sep 2007
Location: Rotterdam/Netherlands
Age: 47
Posts: 3,751
Quote:
Originally Posted by matthey View Post
I expect it is generally better to inline strcpy() where it is called than unroll strcpy()
This code can be both inlined and unrolled at the same time.

Quote:
Originally Posted by matthey View Post
It is much more useful to return a pointer to the end of the string like stpcpy().
What's more useful depends on what's needed and how the function is called.
Thorham is offline  
Old 20 January 2017, 20:30   #42
matthey
Banned
 
Join Date: Jan 2010
Location: Kansas
Posts: 1,284
Quote:
Originally Posted by Thorham View Post
This code can be both inlined and unrolled at the same time.
True. But...

o Inlining helps more with short strings and unrolling more with long strings. Strings tend to be short thus unrolling may be unnecessary.

o Inlining generally gives smaller code than the push/bsr/rts/pop of the AT&T ABI function call so is faster and smaller. Unrolling gives more code which can be bad for ICache usage and wastes memory. Inlining unrolled loops could result in substantially larger program sizes.

o String processing is rarely the bottleneck anyway (unless the compiler does an awful job of optimizing string handling ).

Quote:
Originally Posted by Thorham View Post
What's more useful depends on what's needed and how the function is called.
True again, but it is not so simple for compilers to figure out what is needed. Compilers generally need intrinsic and profiling information or they are ignorant but most programmers ignore this and expect them to figure out what they meant. Of course this is a separate problem than compilers not being able to do basic backend code generation right .
matthey is offline  
Old 20 January 2017, 21:33   #43
esc
 
Posts: n/a
Admittedly OT here, but some folks in this thread appear to be the right ones to ask...so..

I've been writing code in C for a long time. However, I'm completely unfamiliar with the assembly it compiles into. Can someone recommend a good online class or reading material to help me learn this? A friend mentioned taking a class at some point whereby they actually wrote a C compiler in assembly, but he did it at his university and as such it isn't available to me. I'd be curious to do something like that. Thanks!
 
Old 20 January 2017, 22:09   #44
Thorham
Computer Nerd
 
Thorham's Avatar
 
Join Date: Sep 2007
Location: Rotterdam/Netherlands
Age: 47
Posts: 3,751
Quote:
Originally Posted by matthey View Post
True. But...

o Inlining helps more with short strings and unrolling more with long strings. Strings tend to be short thus unrolling may be unnecessary.

o Inlining generally gives smaller code than the push/bsr/rts/pop of the AT&T ABI function call so is faster and smaller. Unrolling gives more code which can be bad for ICache usage and wastes memory. Inlining unrolled loops could result in substantially larger program sizes.

o String processing is rarely the bottleneck anyway (unless the compiler does an awful job of optimizing string handling ).
Very true, which is why you should be able to specify what you want per function call when needed, or use a default setting when it doesn't matter.

Quote:
Originally Posted by matthey View Post
True again, but it is not so simple for compilers to figure out what is needed. Compilers generally need intrinsic and profiling information or they are ignorant but most programmers ignore this and expect them to figure out what they meant. Of course this is a separate problem than compilers not being able to do basic backend code generation right .
This isn't up to the compiler. A good example is when you want a string copy that returns a pointer to the end of string character of the copy, which is useful for string concatenation. You either write the function, or see if there's one in the standard library.
Thorham is offline  
Old 20 January 2017, 22:21   #45
alkis
Registered User
 
Join Date: Dec 2010
Location: Athens/Greece
Age: 53
Posts: 719
Quote:
Originally Posted by esc View Post
Admittedly OT here, but some folks in this thread appear to be the right ones to ask...so..

I've been writing code in C for a long time. However, I'm completely unfamiliar with the assembly it compiles into. Can someone recommend a good online class or reading material to help me learn this? A friend mentioned taking a class at some point whereby they actually wrote a C compiler in assembly, but he did it at his university and as such it isn't available to me. I'd be curious to do something like that. Thanks!
There is this https://godbolt.org/g/aa9FDd

On how a compiler works this might be of help http://compilers.iecc.com/crenshaw/
alkis is offline  
Old 21 January 2017, 01:16   #46
matthey
Banned
 
Join Date: Jan 2010
Location: Kansas
Posts: 1,284
Quote:
Originally Posted by esc View Post
I've been writing code in C for a long time. However, I'm completely unfamiliar with the assembly it compiles into. Can someone recommend a good online class or reading material to help me learn this? A friend mentioned taking a class at some point whereby they actually wrote a C compiler in assembly, but he did it at his university and as such it isn't available to me. I'd be curious to do something like that. Thanks!
Many of the "free" compiler design texts are rather old but can be fine for learning the basics. The Basics of Compiler Design is fairly modern and in depth.

Basics of Compiler Design
http://www.diku.dk/hjemmesider/ansat...sics_lulu2.pdf

It is always good to look at and play with some code too. The vbcc compiler source is fairly modern, advanced, has few dependencies (it compiles on my Amiga) and is written in C. The vbcc source, documentation and binaries are at the following link.

http://sun.hasenbraten.de/vbcc/

The GCC C source is available but a complex mess and full of dependencies. Clang/LLVM is written in C++ and has no official or finished 68k backend. The Amiga DICE source is in C and available but it is old and rather basic.

It is probably necessary to learn some basic assembly language and study the compiler output to fully understand the process. Various debuggers and disassemblers are available to disassemble compiled programs (ask if needed). The M68000PRM is the basic guide for the 68k ISA (now with spiffy NXP text).

http://www.nxp.com/assets/documents/.../M68000PRM.pdf

Last edited by matthey; 21 January 2017 at 01:26.
matthey is offline  
Old 21 January 2017, 04:01   #47
esc
 
Posts: n/a
Thanks matthey!
 
Old 21 January 2017, 15:37   #48
alkis
Registered User
 
Join Date: Dec 2010
Location: Athens/Greece
Age: 53
Posts: 719
Ok, I took the sources from the chess engine TSCP ( http://www.tckerrigan.com/Chess/TSCP/ )
and compiled them with sas/c, gcc and vbcc.

Tscp has an embedded benchmark. I lowered the 'max_depth' from 5 to 3, cause you know....amiga. And run the three executables produced from the three compilers.

gcc-3.4.0 19 secs
sas/c 25secs
vbcc 35secs.

gcc: m68k-amigaos-gcc -m68020 -O3 -fomit-frame-pointer -noixemul -o tscpgcc *.c
vbcc: vc +aos68k -O4 -o tscpvbcc *.c -I/usr/local/amiga/m68k-amigaos/sys-include/ -lmieee -cpu=68020
sas: see scoptions inside archive

All the above were run in fs-uae inside a vm so the absolute numbers probably shouldn't mean a thing, still the ratios should be good.

Included is the archive of sources, if you want to play with it. You run the executable, type 'bench' and wait. When it's finished type 'bye' to exit.
Attached Files
File Type: lha tscp181.lha (92.1 KB, 264 views)

Last edited by alkis; 21 January 2017 at 16:04. Reason: (-noixemul version now)
alkis is offline  
Old 31 January 2017, 21:37   #49
bebbo
bye
 
Join Date: Jun 2016
Location: Some / Where
Posts: 680
Quote:
Originally Posted by bebbo View Post
You need the patched binutil-2.14 which is in the toolchain:
Code:
./toolchain-m68k --gcc 6 --binutils 2.14
... it's just a start.

Bebbo
the toolchains is now able to build the libnix library.

The examples hello-ks13 and hello-ks20 do compile and run.

Bebbo


PS and gcc 6 / binutils 2.14 are the default setting now
bebbo is offline  
Old 31 January 2017, 21:43   #50
Marlon_
AmigaDev.com
 
Marlon_'s Avatar
 
Join Date: Mar 2016
Location: Stockholm, Sweden
Age: 35
Posts: 625
Quote:
Originally Posted by bebbo View Post
the toolchains is now able to build the libnix library.

The examples hello-ks13 and hello-ks20 do compile and run.

Bebbo


PS and gcc 6 / binutils 2.14 are the default setting now
Awesome news! =)
Marlon_ is offline  
Old 31 January 2017, 23:12   #51
bebbo
bye
 
Join Date: Jun 2016
Location: Some / Where
Posts: 680
Quote:
Originally Posted by alkis View Post
Ok, I took the sources from the chess engine TSCP ( http://www.tckerrigan.com/Chess/TSCP/ )
and compiled them with sas/c, gcc and vbcc.

Tscp has an embedded benchmark. I lowered the 'max_depth' from 5 to 3, cause you know....amiga. And run the three executables produced from the three compilers.

gcc-3.4.0 19 secs
sas/c 25secs
vbcc 35secs.

gcc: m68k-amigaos-gcc -m68020 -O3 -fomit-frame-pointer -noixemul -o tscpgcc *.c
vbcc: vc +aos68k -O4 -o tscpvbcc *.c -I/usr/local/amiga/m68k-amigaos/sys-include/ -lmieee -cpu=68020
sas: see scoptions inside archive

All the above were run in fs-uae inside a vm so the absolute numbers probably shouldn't mean a thing, still the ratios should be good.

Included is the archive of sources, if you want to play with it. You run the executable, type 'bench' and wait. When it's finished type 'bye' to exit.
Right now it compiles with gcc6, but links only if multiple symbols are suppressed

Code:
 m68k-amigaos-gcc -m68020 -O3 -fomit-frame-pointer -noixemul -o tscpgcc *.c -Xlinker  --allow-multiple-definition
and crashes :-(


Bebbo
bebbo is offline  
Old 31 January 2017, 23:13   #52
bebbo
bye
 
Join Date: Jun 2016
Location: Some / Where
Posts: 680
Quote:
Originally Posted by Marlon_ View Post
Awesome news! =)
Don't expect to much. But I'm still on it.

Bebbo
bebbo is offline  
Old 31 January 2017, 23:48   #53
alkis
Registered User
 
Join Date: Dec 2010
Location: Athens/Greece
Age: 53
Posts: 719
Quote:
Originally Posted by bebbo View Post
the toolchains is now able to build the libnix library.

The examples hello-ks13 and hello-ks20 do compile and run.

Bebbo


PS and gcc 6 / binutils 2.14 are the default setting now
Ummm, as in you can actually run the exe on amiga 500 with kickstart1.3???!!!!

Btw, thanks for your work.
alkis is offline  
Old 31 January 2017, 23:51   #54
alkis
Registered User
 
Join Date: Dec 2010
Location: Athens/Greece
Age: 53
Posts: 719
Quote:
Originally Posted by bebbo View Post
Right now it compiles with gcc6, but links only if multiple symbols are suppressed

Code:
 m68k-amigaos-gcc -m68020 -O3 -fomit-frame-pointer -noixemul -o tscpgcc *.c -Xlinker  --allow-multiple-definition
and crashes :-(


Bebbo
What symbols it complains about? Possible to attach the log?
alkis is offline  
Old 01 February 2017, 06:20   #55
nyteshade
 
Posts: n/a
Bebbo, I am still having issues compiling under macOS Sierra. I filed an issue for some common bits I overcame but I'm now getting this:

Code:
: --statistics -o po/zh_TW.gmo /Volumes/Code/amigaos-cross-toolchain/submodules/gcc-6/gcc/po/zh_TW.po
/usr/bin/clang++ -m32 -std=gnu++11   -g -O2 -Wall -DIN_GCC  -DCROSS_DIRECTORY_STRUCTURE  -fno-strict-aliasing -fno-exceptions -fno-rtti -fasynchronous-unwind-tables -W -Wall -Wno-narrowing -Wwrite-strings -Wcast-qual -Wmissing-format-attribute -Woverloaded-virtual -pedantic -Wno-long-long -Wno-variadic-macros -Wno-overlength-strings   -DHAVE_CONFIG_H -DGENERATOR_FILE -fno-PIE   -o build/genmddeps \
    build/genmddeps.o build/read-md.o build/errors.o ../build-i686-linux-gnu/libiberty/libiberty.a
ld: illegal text-relocation to '___stdoutp' in /usr/lib/libSystem.dylib from '_main' in build/genmddeps.o for architecture i386
clang: error: linker command failed with exit code 1 (use -v to see invocation)
make[1]: *** [Makefile:2691: build/genmddeps] Error 1
make[1]: Leaving directory '/Volumes/Code/amigaos-cross-toolchain/.build-m68k/build/gcc-6/gcc'
make: *** [Makefile:4139: all-gcc] Error 2
ERROR: command "make all-gcc CFLAGS_FOR_TARGET=-noixemul MAKEINFO=makeinfo -j1" failed with 2
Any ideas?
 
Old 01 February 2017, 08:42   #56
alpine9000
Registered User
 
Join Date: Mar 2016
Location: Australia
Posts: 881
Quote:
Originally Posted by nyteshade View Post
Bebbo, I am still having issues compiling under macOS Sierra. I filed an issue for some common bits I overcame but I'm now getting this:

Code:
: --statistics -o po/zh_TW.gmo /Volumes/Code/amigaos-cross-toolchain/submodules/gcc-6/gcc/po/zh_TW.po
/usr/bin/clang++ -m32 -std=gnu++11   -g -O2 -Wall -DIN_GCC  -DCROSS_DIRECTORY_STRUCTURE  -fno-strict-aliasing -fno-exceptions -fno-rtti -fasynchronous-unwind-tables -W -Wall -Wno-narrowing -Wwrite-strings -Wcast-qual -Wmissing-format-attribute -Woverloaded-virtual -pedantic -Wno-long-long -Wno-variadic-macros -Wno-overlength-strings   -DHAVE_CONFIG_H -DGENERATOR_FILE -fno-PIE   -o build/genmddeps \
    build/genmddeps.o build/read-md.o build/errors.o ../build-i686-linux-gnu/libiberty/libiberty.a
ld: illegal text-relocation to '___stdoutp' in /usr/lib/libSystem.dylib from '_main' in build/genmddeps.o for architecture i386
clang: error: linker command failed with exit code 1 (use -v to see invocation)
make[1]: *** [Makefile:2691: build/genmddeps] Error 1
make[1]: Leaving directory '/Volumes/Code/amigaos-cross-toolchain/.build-m68k/build/gcc-6/gcc'
make: *** [Makefile:4139: all-gcc] Error 2
ERROR: command "make all-gcc CFLAGS_FOR_TARGET=-noixemul MAKEINFO=makeinfo -j1" failed with 2
Any ideas?
I managed to hack thru that error (manually hacked a generated makefile), but then I got a different error later in the build so I gave up.
alpine9000 is offline  
Old 01 February 2017, 09:29   #57
bebbo
bye
 
Join Date: Jun 2016
Location: Some / Where
Posts: 680
Quote:
Originally Posted by nyteshade View Post
Bebbo, I am still having issues compiling under macOS Sierra.

(...)
Since I don't own a Mac, I can't reproduce (I could get a VM with OSX, but then I'd also need XCode, which requires an account).

I'm not sure, but it looks like the target does match your system:

Code:
build-i686-linux-gnu
Does it work, if you build with gcc 2.9.3?

Bebbo
bebbo is offline  
Old 01 February 2017, 11:45   #58
bebbo
bye
 
Join Date: Jun 2016
Location: Some / Where
Posts: 680
Quote:
Originally Posted by nogginthenog View Post
I don't have libnix built yet but GCC 6.2.1 produces this:

Code:
_strcpy:
        move.l a2,-(sp) |,
        move.l a0,d0    | dst, dst
        move.l a0,a2    | dst, ivtmp.11
.L2:
        move.b (a1)+,d1 | MEM[base: src_8, offset: 4294967295B], _9
        move.b d1,(a2)+ | _9, MEM[base: _14, offset: 0B]
        jne .L2 |
        move.l (sp)+,a2 |,
        rts
Fixed the register usage.
without -mregparm=2 the parameters are passed via stack (again):

Code:
_strcpy:
        move.l 4(sp),d0
        move.l 8(sp),a1
        move.l d0,a0
.L2:
        move.b (a1)+,d1
        move.b d1,(a0)+
        jne .L2
        rts
And yes, the code could be better.

Bebbo
bebbo is offline  
Old 01 February 2017, 19:58   #59
Thorham
Computer Nerd
 
Thorham's Avatar
 
Join Date: Sep 2007
Location: Rotterdam/Netherlands
Age: 47
Posts: 3,751
Why is it so hard to get compilers to produce proper code for simple stuff like this? It absolutely boggles the mind
Thorham is offline  
Old 01 February 2017, 21:50   #60
bebbo
bye
 
Join Date: Jun 2016
Location: Some / Where
Posts: 680
Quote:
Originally Posted by Thorham View Post
Why is it so hard to get compilers to produce proper code for simple stuff like this? It absolutely boggles the mind
Because 68k is poorly and Amiga is not supported?

GCC performs the code generation and optimization with abstract instructions. A meta description/som code describes which operations are available, how they perform and how the assembly syntax looks like.

If that's not complete or the performance information is bogus, the optimal code can't be found.

If the code was still officially supported there were test cases and those bugs were found and fixed.

Now: Find and fix it yourself. You are part of the community.

Bebbo
bebbo 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 16:12.

Top

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