Re: [Tinycc-devel] where are the functions?

2023-09-11 Thread Samir Ribić via Tinycc-devel
To link with Windows system DLLs, TCC uses import definition
files (.def) instead of libraries.
I have downloaded the version you mention and in the directory tcc\lib
there are files

17. 12. 2017.  09:27 5.052 gdi32.def
17. 12. 2017.  09:2712.882 kernel32.def
17. 12. 2017.  09:2726.866 libtcc1-32.a
17. 12. 2017.  09:2741.706 libtcc1-64.a
17. 12. 2017.  09:2715.880 msvcrt.def
17. 12. 2017.  09:2710.439 user32.def

All your functions missing are either from user32 or gdi32, so most
probably you used the wrong -L parameter.
Try;
tcc\tcc test.c -luser32 -lgdi32
or even plain
tcc\tcc test.c


On Sun, Sep 10, 2023 at 4:05 PM Dieter Dewald  wrote:

>10.09.2023
> i used tcc-0.9.27-win64-bin.zip,
> i written #include  else no include,
> but i got this error-message:
>
> tcc: error: undefined symbol 'DefWindowProcA'
> tcc: error: undefined symbol 'LoadIconA'
> tcc: error: undefined symbol 'RegisterClassA'
> tcc: error: undefined symbol 'CreateWindowExA'
> tcc: error: undefined symbol 'ShowWindow'
> tcc: error: undefined symbol 'UpdateWindow'
> tcc: error: undefined symbol 'DestroyWindow'
> tcc: error: undefined symbol 'RegisterClassExA'
> tcc: error: undefined symbol 'MoveWindow'
> tcc: error: undefined symbol 'GetDC'
> tcc: error: undefined symbol 'BeginPaint'
> tcc: error: undefined symbol 'EndPaint'
> tcc: error: undefined symbol 'ReleaseDC'
> tcc: error: undefined symbol 'SetTextColor'
> tcc: error: undefined symbol 'SetBkColor'
> tcc: error: undefined symbol 'SetBKMode'
> tcc: error: undefined symbol 'CreateFontA'
> tcc: error: undefined symbol 'SelectObject'
> tcc: error: undefined symbol 'DeleteObject'
> tcc: error: undefined symbol 'SetPixel'
> tcc: error: undefined symbol 'CreateSolidBrush'
> tcc: error: undefined symbol 'FillRect'
> tcc: error: undefined symbol 'TextOutA'
> tcc: error: undefined symbol 'PeekMessageA'
> tcc: error: undefined symbol 'GetAsyncKeyState'
> tcc: error: undefined symbol 'GetSystemMetrics'
> tcc: error: undefined symbol 'main'
>
> i have no main, and i written the functions without A
>
> ___
> Tinycc-devel mailing list
> Tinycc-devel@nongnu.org
> https://lists.nongnu.org/mailman/listinfo/tinycc-devel
>
___
Tinycc-devel mailing list
Tinycc-devel@nongnu.org
https://lists.nongnu.org/mailman/listinfo/tinycc-devel


Re: [Tinycc-devel] Is anyone on the C standards committee?

2023-01-25 Thread Samir Ribić via Tinycc-devel
I am a member of ISO Technical committee Information Technology for Bosnia
and Herzegovina. I remember when we accepted the ISO C  standard for local
use by acclamation.

On Wed, Jan 25, 2023 at 7:56 PM Charles Lohr  wrote:

> I was just wondering if anyone from TCC on the standards committee?  I
> just really hope for a compiler as popular as TCC, there's someone there
> defending the interests of all the not-GCC, not-clang compilers, where
> difficulty of feature addition is a paramount concern.  I use TCC as my
> daily driver, and I have been increasingly anxious about some of the
> proposals and things that are being added to the C standard.
>
> Charles
> ___
> Tinycc-devel mailing list
> Tinycc-devel@nongnu.org
> https://lists.nongnu.org/mailman/listinfo/tinycc-devel
>
___
Tinycc-devel mailing list
Tinycc-devel@nongnu.org
https://lists.nongnu.org/mailman/listinfo/tinycc-devel


[Tinycc-devel] Unicode letter escape

2022-08-05 Thread Samir Ribić via Tinycc-devel
Tcc supports \u escape sequence inside L"" but I have no idea how to
overcome this problem:
The code inside parse_escape_string function, in this part

   case 'x':
case 'u':
case 'U':
p++;
n = 0;
for(;;) {
c = *p;
if (c >= 'a' && c <= 'f')
c = c - 'a' + 10;
else if (c >= 'A' && c <= 'F')
c = c - 'A' + 10;
else if (isnum(c))
c = c - '0';
else
break;
n = n * 16 + c;
p++;
}

does not limit the size of the hexadecimal number written after the \u
escape code. Why is this a problem? If the text with an unicode letter is
followed by letters a,b, c, d, e or f, it will be part of the code itself.
For example L"Mogu\u0107i" will display the word "Mogući" as should be,
because the code 0107 is c acute.  However, the word L"Mogu\u0107e" will
not display "Moguće" but "Moguၾ" because 107e is  Myanmar Shan Fa

Section 6.4.3 of C99 standard  ISO/IEC 9899:1999(E) -- Programming
Languages -- C (uchile.cl)
 states
that \u escape sequence requires exactly four hexadecimal digits, so
the code above needs  to be changed.
___
Tinycc-devel mailing list
Tinycc-devel@nongnu.org
https://lists.nongnu.org/mailman/listinfo/tinycc-devel


Re: [Tinycc-devel] How to make TCC support utf8

2022-06-09 Thread Samir Ribić via Tinycc-devel
UTF-8  is compatible with char * because the codes between 0 and 127 are
the same (in code and size). This is different from 16 bit Unicode. So,
many functions that are intended for ANSI will work with UTF-8.  It is now
a question of OS support.

See the following program:

#include 
#include 
void main() {
  char * m="Конференция u Čačku Οὐχὶ ταὐτὰ παρίσταταί \n";
 // SetConsoleOutputCP(65001);
  printf(m);
}

Compile it and start it under Windows (I tried Windows 10) . The text is
incorrectly written. Now uncomment the  line SetConsoleOutputCP(65001);
and  you will see the text..
However, strlen still returns string length in bytes, not in characters.
Also m[5] accesses fifth byte, not fifth character. So, you need to prepare
your own versions of string handling functions.

On Thu, Jun 9, 2022 at 6:34 AM Larry Doolittle via Tinycc-devel <
tinycc-devel@nongnu.org> wrote:

> lrd -
>
> On Thu, Jun 09, 2022 at 12:01:09PM +0800, lrt via Tinycc-devel wrote:
> > Who can tell me how to make TCC support utf8.
> > I want to use the Unicode API.
>
> Just .. don't.
>
> ‘Trojan Source’ Bug Threatens the Security of All Code
> November 1, 2021
>
> https://krebsonsecurity.com/2021/11/trojan-source-bug-threatens-the-security-of-all-code/
> (as seen on slashdot)
>
>   - Larry
>
> ___
> Tinycc-devel mailing list
> Tinycc-devel@nongnu.org
> https://lists.nongnu.org/mailman/listinfo/tinycc-devel
>
___
Tinycc-devel mailing list
Tinycc-devel@nongnu.org
https://lists.nongnu.org/mailman/listinfo/tinycc-devel


Re: [Tinycc-devel] Optimizing for avx512

2022-02-06 Thread Samir Ribić via Tinycc-devel
Even if inline  assembly does not support AVx-512  you can still use NASM
and link externally.. Anyway, there are only six instructions you need to
use:
VMOVUPS zmm1,[memory location]  ; Loads 8 floats from memory location to
zmm1
VMULPS zmm1,zmm2,zmm3 ; multiplies 8 float numbers in zmm2 with 8 numbers
in zmm3 and stores result in 8 numbers of zmm1
VADDPS zmm1,zmm2,zmm3 ; adds 8 float numbers in zmm2 with 8 numbers in zmm3
and stores result in 8 numbers of zmm1
VSUBPS zmm1,zmm2,zmm3 ; subtracts 8 float numbers in zmm3 from 8 numbers in
zmm2 and stores result in 8 numbers of zmm1
VDIVPS zmm1,zmm2,zmm3 ; divides 8 float numbers in zmm2 with 8 numbers in
zmm3 and stores result in 8 numbers of zmm1
VMOVUPS [memory location],zmm1  ; Stores 8 floats from zmn1 to memory
location
A bit faster than VMOVUPS is VMOVAPS, but the numbers must be at addresses
divisible by 64.
Check if your PC supports AVX-512. All Xeon processors support it, usually
no Pentium and Celeron, while Core processors may and may not.



On Sun, Feb 6, 2022 at 9:02 AM Yair Lenga  wrote:

> Thank you for feedback. I understand what are the limits of tcc. In my
> specific problem, I am trying to speed up user-provided expression in a
> simulation of 100 paths. Can I use the avx512 build-in - e.g. work on 8
> double precision values with one operation - practically reducing the 100
> evaluations to 13 (100/8) ?
>
> User expressions are all in the form that can be handle by AVX SIMD
> instructions: add, multiple, …
>
> Thanks, yair.
>
> Sent from my iPad
> ___
> Tinycc-devel mailing list
> Tinycc-devel@nongnu.org
> https://lists.nongnu.org/mailman/listinfo/tinycc-devel
>
___
Tinycc-devel mailing list
Tinycc-devel@nongnu.org
https://lists.nongnu.org/mailman/listinfo/tinycc-devel


Re: [Tinycc-devel] Optimizing for avx512

2022-02-05 Thread Samir Ribić via Tinycc-devel
Single pass compilers still can have peephole optimization. Once I
demonstrated with situations when tcc generates
MOV EAX,const
MOV [location],EAX
and catched this case to generate
MOV DWORD [location],const

Back to the topic, AVX-512 is difficult to be supported at language level.
In the case of tcc, it is impossible because to convert array operations
into AVX-512 instructions you need  to see a global picture of the program.

However, it is possible at library level. Simply write matrix manipulations
functions in assembly language. Inside functions load data into AVX
registers, do calculations in registers and at exit write the result into
memory.


On Sat, Feb 5, 2022 at 4:55 PM Christian Jullien  wrote:

> An optimizer compiler need several pass to operate.
> - constant folding
> - register allocation
> - peephole optimization
> - branch prediction
> ...
>
> When it knows the target it can reorganize code to keep as much as
> possible data un L1 cache and have the longest series of instructions that
> can be executed without breaking the pipeline. i.e. instructions nearly run
> in //
>
> Tcc, which is one pass compiler, definitely loses on this point. On the
> other end, one pass makes it damn fast and that's why we love it.
>
> We can't have the butter and the money for the butter
>
> -Original Message-
> From: rem...@tutanota.com [mailto:rem...@tutanota.com]
> Sent: Saturday, February 05, 2022 16:10
> To: Jullien; Tinycc Devel
> Cc: Tinycc Devel
> Subject: Re: [Tinycc-devel] Optimizing for avx512
>
> 5 Φεβ 2022, 11:01 Από eli...@orange.fr:
>
> > The price to pay its really fast compilation is that the generated code
> is poor compared to gcc, clang or vc++ (among others). Depending on your
> program, consider it is roughly 2 to 4x slower.
> >
> I would say that this is not always the case. And correct me if I'm wrong
> but aren't optimization (except few of them) mostly because the programmer
> wrote bad code and the compiler found a better instructions to do the same
> thing? Inline assembly exists in the end so if you really really care about
> performance, you should probably use inline assembly in the most critical
> algorithms/functions. I've seen some code running the same on TCC and GCC
> so I suppose optimization doesn't always makes magic. Or you may have a 5%
> increase or even less. In any case, I would suggest using both TCC and then
> GCC/Clang for the critical parts that will be hugely favored by the
> optimizations these compilers can do.
>
> But of course just my opinion on the topic.
>
>
> ___
> Tinycc-devel mailing list
> Tinycc-devel@nongnu.org
> https://lists.nongnu.org/mailman/listinfo/tinycc-devel
>
___
Tinycc-devel mailing list
Tinycc-devel@nongnu.org
https://lists.nongnu.org/mailman/listinfo/tinycc-devel


Re: [Tinycc-devel] Can a biggener (and idiot) like me read and understand TCC's backend so I can create my own frontend with it?

2022-01-29 Thread Samir Ribić via Tinycc-devel
I have already sent a tutorial to rempas to make a simple compiler using
parser generator Coco/r, but there is one extremely simple tutorial to
learn writing compilers from scratch: Let's build a compiler by Jack
Crenshaw  Let's Build a Compiler (iecc.com)
 . It is Pascal and Motorola 68000
target based. Do not discard it as obsolete. Pascal is a very readable
programming language, and MC 68000 has a quite good instruction set.

On Sat, Jan 29, 2022 at 11:11 AM Christian Jullien  wrote:

> I suggest you start with something simple:
>
>
>
> A language that implement 4 arithmetic integer operations, has integer
> variables, allows to define functions and includes print function as
> library function.
>
> Chose the syntax you like and start to write you own compiler that
> generate intermediate internal code, then choose a backend (for example C)
> that generates code corresponding to your intermediate code.
>
>
>
> You’ll learn of lot of things and you’ll get 80% of the knowledge you’ll
> need to write serious things.
>
>
>
> This globally how works my Lisp compiler from Lisp files up to standalone
> executable.
>
>
>
> See https://en.wikipedia.org/wiki/OpenLisp#Compiler
>
>
>
> *From:* Tinycc-devel [mailto:tinycc-devel-bounces+eligis=
> orange...@nongnu.org] *On Behalf Of *ian
> *Sent:* Saturday, January 29, 2022 10:43
> *To:* rempas via Tinycc-devel
> *Subject:* Re: [Tinycc-devel] Can a biggener (and idiot) like me read and
> understand TCC's backend so I can create my own frontend with it?
>
>
>
> Hi
>
> One thing or the other :
>
> - you wanna learn asm or algorithmics, and it's not the best place; but
> you obviously need to have to know them a "few",
>
> - or, you already know how to code something in ASM, and then the
> suggested book about how to make an interpreter is the good starting point
> for you.
>
> Rgds
>
> Le 29/01/2022 à 10:08, rempas via Tinycc-devel a écrit :
>
> 29 Ιαν 2022, 03:20 Από s...@conman.org:
>
>
>
> It was thus said that the Great rempas via Tinycc-devel once stated:
>
>
>
> I would advice you to start with this 
> https://craftinginterpreters.com/contents.html first.
>
>
>
> The rest will follow before you know it.
>
>
>
> Thanks! However, I don't understand how this will help me. I mean, I don't
>
> even want to create an intepreter to begin with. So this has nothing to do
>
> with what I want to make. Unless you are referring to the frontend so in
>
> this case, It will probably be a good idea to read this book. Or maybe I
>
> should make an intepreter in the end? Hm
>
>
>
>
>
> It's interpreters all the way down (what do you think CPUs do with machine
>
> code?  They interpret it).  Also, if you have parsed code into a form you
>
> can interpret, you have enough information to generate machine code.
>
>
>
>  -spc
>
>
>
> ___
>
> Tinycc-devel mailing list
>
> Tinycc-devel@nongnu.org
>
> https://lists.nongnu.org/mailman/listinfo/tinycc-devel
>
>
>
> I don't know if I'm that stupid but I really don't understand. I know that 
> the CPU interprets the instructions but an interpreter will use a programming 
> language to interpret. For example, the following statement:
>
>
>
> `println("Hello from my lang: {}", "BestLang")`
>
>
>
> will be translated to (suppose the interpreted is written in C) and then be 
> executed:
>
>
>
> `printf("Hello from my lang: %s", "BestLang);`
>
>
>
> So how is this going to teach my assembly and how the instructions are 
> represented in binary? The book specifically says that it won't work with 
> teaching assembly. The interpreted is a binary that takes source code and 
> executes it. It doesn't create a binary. So I really don't understand what's 
> going on here...
>
>
>
> ___
>
> Tinycc-devel mailing list
>
> Tinycc-devel@nongnu.org
>
> https://lists.nongnu.org/mailman/listinfo/tinycc-devel
>
> --
> -- sibian0...@gmail.com
> -- Développeur compulsif
> ___
> Tinycc-devel mailing list
> Tinycc-devel@nongnu.org
> https://lists.nongnu.org/mailman/listinfo/tinycc-devel
>
___
Tinycc-devel mailing list
Tinycc-devel@nongnu.org
https://lists.nongnu.org/mailman/listinfo/tinycc-devel


Re: [Tinycc-devel] Can a biggener (and idiot) like me read and understand TCC's backend so I can create my own frontend with it?

2022-01-26 Thread Samir Ribić via Tinycc-devel
If your language is quite different from C, and you wish to make a fast
compiler, I would suggest building  the compiler yourself. If you can make
EBNF of the langage syntax, your frontend is almost done. Take some fast
parser generator. I strongly recommend Coco/R because it generates easy to
understand and fast parser code and suipports different programming
languages.
The Compiler Generator Coco/R (jku.at)


What is here interesting, you can add code in your favorite language to be
executed after any syntax element is recognized inside (..)  brackets.
It may be storing new variables during the declaration into the table ,
recognizing the variable already in the table or machine code generating.
It is relatively easy to generate assembly code, but it is not the fastest
way to execute. In a case of machine code, you need to know also about
executable format (headers and sections), instruction encoding and code
patching in case of jumps.

On Wed, Jan 26, 2022 at 10:09 PM Niklas Rosencrantz 
wrote:

> I'm not an expert C programmer. I could find my way, read and learn from
> the TCC source code. It reminded me of reading the source of SASH (the
> stand-alone shell) which is readable compared to DASH for example.
>
> 2. What I would do to learn more but it's not guaranteed to work
>
> a) I would try and learn how statements (in C) translate to assembly for a
> target platform. Maybe start with ARM or MIPS that is supposed to be easier
> than x86 asm.
>
> b) I would try and write a disassembler because I heard it's a good
> exercise.
>
> My experience is that compilers or how to write an interpreter is not a
> learn-by-doing ability. I would need to read and practice a lot before
> trying to do it.
>
> /Niklas
>
> Den ons 26 jan. 2022 20:28rempas via Tinycc-devel 
> skrev:
>
>> **Huge post incoming!!!**
>>
>> Hi! I'm a beginner with low level programming and assembly. I'm
>> interested in learning
>> assembly so I can create my own (non-toy) compiler. Now, I'm a huge
>> fanatic for
>> TCC!!! I LOVE IT!!! I love it so much that it inspired my to create my
>> own compiler that
>> will output C code and then use TCC (or any C compiler to compile) it.
>> However, I thought about some things.
>>
>> 1. Compile times. TCC is the fastest non-toy compiler but my compiler
>> will add up to the compilation time because it will need to create
>> these C files. On top on that, the C programming language doesn't
>> use the best practices when it comes to header files as you have to
>> re-write the files end up on becoming slower not because of the
>> compiler
>> or the backend because because of the design of the language itself.
>>
>> 2. Having to deal with C. A lot of things of my language will not
>> translate to C
>> with the best possible way so it will be harder and I will need to
>> sacrifice the
>> compilation times and maybe runtime performance.
>>
>> 3. Optimizations. As we know, TCC doesn't make optimizations (or does
>> it?) so
>> the resulting code can run slower that GCC or Clang some times. This
>> means
>> that we will need to use 2 compilers in some projects to get the best
>> possible
>> performance while keeping the amazing fast compilation times of TCC.
>>
>> So what I thought was... "You know what? We don't I make a compiler that
>> will
>> create binaries itself? I will have the best possible compilation times
>> and I will
>> be able to apply the optimizations that I want!". Well that's a great
>> idea but there
>> are some problems.
>>
>> 1. This is HARD!!! Not only I must first learn assembly but I must also
>> read
>> the manufacturer manual for each CPU that I want to support. Also,
>> even
>> across the same instruction set, Each operating system needs different
>> work to be done (I don't know, I suppose even OSes that use something
>> common like ELF will not work out of the box without any small change
>> right?).
>> So even for people that know assembly NOW and are very experienced
>> with it,
>> this will be very hard to do and maintain unless you are a genius and
>> I am NOT
>> one for sure (the exact opposite probably).
>>
>> 2. Where do I learn? I mean, resources about creating binary files in ELF
>> format
>> (or whatever each OS is using) and learning the CPU instructions
>> don't exist here
>> and there and even in the places where they exist, it is most of the
>> times, references
>> or things like manufacturer manuals which are not the best things to
>> study if you
>> don't have years of experience and you are already confident enough
>> with this topic.
>>
>> Ok this is getting too big, I will be sort. So after all that, I either
>> do my original idea
>> and output C code or I'm writing this email and hope for a reply. So what
>> I wanted
>> to ask from people that have work with TCC's code and know how assembly
>> works,
>> is TCC's backed tied 

Re: [Tinycc-devel] Status of C language support, et al

2021-04-19 Thread Samir Ribić via Tinycc-devel
> * Which features are still missing, for example from C99 and C11?
>
> We do not want bloated tcc, but  winapi section needs to include, by
default, the following three much used header files and libraries:
commctrl.h
comdlg.h
mmsystem.h
___
Tinycc-devel mailing list
Tinycc-devel@nongnu.org
https://lists.nongnu.org/mailman/listinfo/tinycc-devel