English Amiga Board


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

 
 
Thread Tools
Old 01 October 2015, 13:25   #1
Asman
68k
 
Asman's Avatar
 
Join Date: Sep 2005
Location: Somewhere
Posts: 829
vbcc code generation and dbf

Does vbcc can generate a loop with dbf ?

I'm trying to make such loop in C but without success. Without asm insertion of course.

Any ideas ?
Asman is offline  
Old 03 October 2015, 17:26   #2
Samurai_Crow
Total Chaos forever!
 
Samurai_Crow's Avatar
 
Join Date: Aug 2007
Location: Waterville, MN, USA
Age: 49
Posts: 2,200
Quote:
Originally Posted by Asman View Post
Does vbcc can generate a loop with dbf ?

I'm trying to make such loop in C but without success. Without asm insertion of course.

Any ideas ?
Since a byte branch offset with a subtract is smaller and faster than DBF, I wouldn't imagine it would generate a DBF for anything smaller than 128 bytes forward or 130 bytes back as an offset. Even then, I don't recall seeing a DBF optimization mentioned in the manual. The only real frequent time to see an improvement in speed with DBcc is if the condition code is not false.
Samurai_Crow is offline  
Old 03 October 2015, 17:54   #3
Asman
68k
 
Asman's Avatar
 
Join Date: Sep 2005
Location: Somewhere
Posts: 829
Let consider two very small examples: first take 142c second one 108c. Both doing same thing, mean nothing

Code:
        moveq   #10,d0
loop1
        subq.b  #1,d0
        bne     loop1
;total 142c
Code:
       moveq   #10-1,d0
loop2   dbf     d0,loop2
;total 108c
So for me its real gain even for small loops. For 10000 elements then you have 140006c and 100012c. Of course I mean about MC68000.
Asman is offline  
Old 03 October 2015, 19:14   #4
matthey
Banned
 
Join Date: Jan 2010
Location: Kansas
Posts: 1,284
Quote:
Originally Posted by Asman View Post
Does vbcc can generate a loop with dbf ?
I doubt the vbcc 68k backend will currently generate a dbf. Some of the C static library code and assembler inlines will use it though. If i recall correctly, the startup code and 68000 inlined memcpy() will use it.

Quote:
Originally Posted by Samurai_Crow View Post
Since a byte branch offset with a subtract is smaller and faster than DBF, I wouldn't imagine it would generate a DBF for anything smaller than 128 bytes forward or 130 bytes back as an offset. Even then, I don't recall seeing a DBF optimization mentioned in the manual. The only real frequent time to see an improvement in speed with DBcc is if the condition code is not false.
A SUBQ+Bcc.B is 4 bytes and DBcc is also 4 bytes so they are the same size. I believe DBF is considerably faster on the 68000 and 68020 but there is no speed advantage to DBF on the 68040 and 68060.

SUBQ+Bcc.B is used by the compiler because it is more flexible. DBcc only works with a 16 bit counter and 16 bit displacement and often needs to be branched into at the start. It would be possible to make an optimization that uses DBF when the counter is 16 bit or less and static but most C code today is using 32 bit and 64 bit counters as they avoid the chances of the counter variable overflowing.

Last edited by matthey; 03 October 2015 at 19:22.
matthey is offline  
Old 03 October 2015, 20:46   #5
Leffmann
 
Join Date: Jul 2008
Location: Sweden
Posts: 2,269
There is code in the M68K backend to use DBF for loop constructs actually, but the conditions are never met, probably due to a bug somewhere, and it always ends up emitting the SUBQ+Bcc sequence instead.
Leffmann is offline  
Old 04 October 2015, 09:46   #6
Asman
68k
 
Asman's Avatar
 
Join Date: Sep 2005
Location: Somewhere
Posts: 829
Quote:
Originally Posted by Leffmann View Post
There is code in the M68K backend to use DBF for loop constructs actually, but the conditions are never met, probably due to a bug somewhere, and it always ends up emitting the SUBQ+Bcc sequence instead.
You mean about this code from vbcc/machines/m68k/machine.c ?

Code:
    if(loops>0){
      if(!cf&&loops<=32767&&loops>=-32768){
	emit(f,"\tdbra\t%s,%s%d\n",mregnames[dreg],labprefix,label);
      }else{
	emit(f,"\tsubq.l\t#1,%s\n\tbge\t%s%d\n",mregnames[dreg],labprefix,label);
      }
    }
Asman is offline  
Old 04 October 2015, 11:37   #7
Leffmann
 
Join Date: Jul 2008
Location: Sweden
Posts: 2,269
Yeah I assumed that's what it was, but it seems to be part of the code for copying structs around, so matthey is right that VBCC doesn't use DBF for loops.
Leffmann is offline  
Old 04 October 2015, 18:16   #8
matthey
Banned
 
Join Date: Jan 2010
Location: Kansas
Posts: 1,284
Quote:
Originally Posted by Leffmann View Post
Yeah I assumed that's what it was, but it seems to be part of the code for copying structs around, so matthey is right that VBCC doesn't use DBF for loops.
Copying structures and memory use loops, at least when the copy can't be unrolled. Vbcc has sophisticated loop unrolling settings so the most common loop generating code is likely more complex than the code above. The code above almost looks too simple even for a structure copy.
matthey is offline  
Old 09 March 2016, 17:57   #9
kamelito
Zone Friend
 
kamelito's Avatar
 
Join Date: May 2006
Location: France
Posts: 1,847
@PHX
Not sure you read this but in case...What is the status of Vbcc regarding UB?
http://www.complang.tuwien.ac.at/kps...mission_29.pdf

Kamelito
kamelito is offline  
Old 09 March 2016, 23:33   #10
matthey
Banned
 
Join Date: Jan 2010
Location: Kansas
Posts: 1,284
Quote:
Originally Posted by kamelito View Post
@PHX
Not sure you read this but in case...What is the status of Vbcc regarding UB?
http://www.complang.tuwien.ac.at/kps...mission_29.pdf
Interesting article although nothing surprised me. Compiler developer's selling hype and C not being portable? Yawn. What's new? Undefined behavior? What can compilers do besides shoot an error, handle the code consistently between platforms and versions and not optimize the problem? Obviously, some of the top compilers can't even handle that. Vbcc is standards strict and more likely to give errors for UB cases unlike the default GCC slop but most of the C world has learned and expects GCC slop so it has become a pseudo standard which programmers use. It would help if the C standards would define more of the common UB cases but there will always be some problems. GCC adds their own GCCisms which also have UB problems. Programmers would like more GCC compatibility but Volker has tried to keep vbcc standards clean, non-bloated and able to be programmed at a low level for embedded systems. His efforts are under appreciated by those wanting perfect GCC compatibility and the best optimizations in the world. It is too bad that compilers like vbcc are not supported more as they could have a positive influence on the direction of C. Instead, we have one huge bloated GCC C standard and its optimization target x86_64 to rule the world.
matthey is offline  
Old 10 March 2016, 14:51   #11
phx
Natteravn
 
phx's Avatar
 
Join Date: Nov 2009
Location: Herford / Germany
Posts: 2,545
I agree with everything matthey has said. There is nothing to add.
phx is offline  
Old 10 March 2016, 20:15   #12
kamelito
Zone Friend
 
kamelito's Avatar
 
Join Date: May 2006
Location: France
Posts: 1,847
Is there any other C compiler that is doing it the right way like VBcc?
Any plan to support X64? (or 80x86 (386 and above) mean also x64...)
is VBcc for plateform other than Amiga is distributed as source code only?
Kamelito
kamelito is offline  
Old 11 March 2016, 16:09   #13
phx
Natteravn
 
phx's Avatar
 
Join Date: Nov 2009
Location: Herford / Germany
Posts: 2,545
Quote:
Originally Posted by kamelito View Post
Is there any other C compiler that is doing it the right way like VBcc?
I hope so.

BTW, Visual C++ is certainly not one of them. Last time I checked it didn't even implement the most basic C99 functionality. And Microsoft's attitude is that it doesn't matter, because everybody will use C++ anyway ...

Quote:
Any plan to support X64? (or 80x86 (386 and above) mean also x64...)
You have to ask Volker about that. An 80x86 code generator exists since nearly the beginning, but it never became mature - also because nobody used it. AROS is not very vbcc-friendly, so there was not much reason for it.

Quote:
is VBcc for plateform other than Amiga is distributed as source code only?
Yes. To be precise, my contract with Volker allows me to make releases for Amiga and Atari only.

BTW, vbcc 0.9e is currently in the final testing phase for the release.
phx is offline  
Old 11 March 2016, 16:35   #14
kamelito
Zone Friend
 
kamelito's Avatar
 
Join Date: May 2006
Location: France
Posts: 1,847
Maybe GCC with -Wall -Wextra -ansi -pedantic
I knew about MS, but is C99/C11 features any good, I'm sure some of them should be avoided.

Kamelito
kamelito is offline  
Old 11 March 2016, 19:54   #15
matthey
Banned
 
Join Date: Jan 2010
Location: Kansas
Posts: 1,284
Quote:
Originally Posted by phx View Post
BTW, vbcc 0.9e is currently in the final testing phase for the release.
Awesome. What is new? Mostly bug fixes? New functionality?

Quote:
Originally Posted by kamelito View Post
Maybe GCC with -Wall -Wextra -ansi -pedantic
I knew about MS, but is C99/C11 features any good, I'm sure some of them should be avoided.
IMO, C99 is overall a good standard for C. The new standard datatypes (64 bit integers, fixed length integers, boolean, etc.) make writing portable and optimized code easier. Allowing BCPL/C++ style comments and allowing variable declarations in the code are convenient additions. Floating point functions were standardized and there is a huge selection of functions. C99 is more strict and defined in some ways which helps with optimizations and UB (for example restrict and inline behavior). The biggest problem with C99 is that it went too far into unnecessary areas where optional C add-ons would have been better (complex number support, variable length character support, etc.). The amount of work and code needed to support C99 made full support of the C99 standard rare (vbcc does not fully support C99). C11 made several add-ons optional and added some important but mostly specialized new features like multi-threading support.

GCC is by default in slop mode (-std=GNU11). This includes POSIX support and GCCisms which can interfere with the standard (this is why phx has a different set of includes for his PosixLib). Some older GCC behavior is retained for compatibility with older GCC versions. Standards and errors are relaxed in general. GCC can be put in strict C99 (-std=c99) or C11 (-std=c11) mode. GCC with -std=c99 -pedantic switches would probably be closer to vbcc with -c99. I expect many existing GCC programs would no longer compile though.
matthey is offline  
Old 12 March 2016, 01:51   #16
Samurai_Crow
Total Chaos forever!
 
Samurai_Crow's Avatar
 
Join Date: Aug 2007
Location: Waterville, MN, USA
Age: 49
Posts: 2,200
I consider C11 to be interesting if for no other reason than the preprocessor supports "generic" style functionality and allows some unpopular features of C99 to be optional.

-edit-
This is a subject for another thread.

Last edited by Samurai_Crow; 12 March 2016 at 01:59. Reason: Off topic discussion
Samurai_Crow 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
vbcc 0.9d phx News 43 13 July 2015 19:41
Debugging vbcc code tolkien Coders. C/C++ 5 14 February 2015 06:45
VBCC code generation Asman Coders. C/C++ 9 17 August 2014 09:33
Mixed 68k / PPC code on VBCC. Cowcat Coders. General 10 01 August 2013 16:01
3D code and/or internet code for Blitz Basic 2.1 EdzUp Retrogaming General Discussion 0 10 February 2002 11:40

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 14:47.

Top

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