flat assembler
Message board for the users of flat assembler.

Index > Projects and Ideas > Mandelbrot program for Linux64 (and now 32) [DONE.. kinda]

Author
Thread Post new topic Reply to topic
UCM



Joined: 25 Feb 2005
Posts: 285
Location: Canada
UCM 30 Aug 2007, 01:50
Okay, I wrote a Mandelbrot calculating program. The important part is that it works. Very Happy However, there are tons of features missing.... you can't zoom in (only render a massive image), I don't do error checking (uses the naivest str-to-int procedure you could think of Embarassed), there's a static buffer (how exactly do you dynamically allocate memory on Linux?), it unnecessarily uses 64-bit, it outputs a raw TGA file, etc.

Feel free to port it to 32-bit. I have a 64-bit system, so I didn't feel like doing it.

Important files are the mandel.asm and mpalette.inc file. LSCR package is included for the symbols.inc (it's useful!). Other files (PHP scripts etc) are helpers; mpalette.php generates the palette <gasp>, and mandel.php is the PHP version, which is slow and annoying, but is a nice reference.

Anybody want to help optimize?

It's licensed under the Artistic license, also included.

P.S. Please tell me if it doesn't work (can't assemble etc.) Remember, the image size limit is 4096x4096 (or 2048x8192, etc.), thanks to my limited knowledge of Linux programming.

P.P.S. Reading the README is recommended Wink

P.P.P.S. Yes, if you look in the tarball, my username is goffrie; you've all been tricked! Very Happy

EDIT: (i.e. P.P.P.P.S. Wink) New version, using sys_brk to dynamically allocate memory. Also, a little source code cleanup.

EDIT2: New 32-bit version. Old version is still here. Anybody know how to rename attachments? Neutral


Description: the output, resized from 4096x4096 to 256x256, then compressed into PNG, GIMPwork ;)
Filesize: 11.05 KB
Viewed: 11653 Time(s)

mandelbrot.png


Description: the (new) 32-bit version
Download
Filename: mandelbrot.tar.bz2
Filesize: 297 KB
Downloaded: 859 Time(s)

Description: the (now old) sources (64-bit) (and binary, etc)
Download
Filename: mandelbrot.tar.bz2
Filesize: 291.88 KB
Downloaded: 844 Time(s)


_________________
This calls for... Ultra CRUNCHY Man!
Ta da!! *crunch*


Last edited by UCM on 30 Aug 2007, 16:19; edited 3 times in total
Post 30 Aug 2007, 01:50
View user's profile Send private message Reply with quote
f0dder



Joined: 19 Feb 2004
Posts: 3175
Location: Denmark
f0dder 30 Aug 2007, 07:53
Quote:

(how exactly do you dynamically allocate memory on Linux?)

mmap()
Post 30 Aug 2007, 07:53
View user's profile Send private message Visit poster's website Reply with quote
UCM



Joined: 25 Feb 2005
Posts: 285
Location: Canada
UCM 30 Aug 2007, 15:17
sys_mmap was a little too confusing for me. Wink Instead, I looked into FASMLIB and how memory allocation was done there, which happens to be sys_brk; this fits very well with my previous scheme, so I use that now. Attachment updated!
Post 30 Aug 2007, 15:17
View user's profile Send private message Reply with quote
vid
Verbosity in development


Joined: 05 Sep 2003
Posts: 7105
Location: Slovakia
vid 30 Aug 2007, 16:10
UCM: but that works only if you need to allocate just one block at a time.
Post 30 Aug 2007, 16:10
View user's profile Send private message Visit poster's website AIM Address MSN Messenger ICQ Number Reply with quote
UCM



Joined: 25 Feb 2005
Posts: 285
Location: Canada
UCM 30 Aug 2007, 16:14
I only need to allocate one block, ever Wink
I modified the code to be 32-bit. I now use a few FASMLIB macros and the ATOI procedure from Reverend. (I will be using ATOF soon, so it's included but unused.) I plan to use FASMLIB to make it portable to Win32.
Post 30 Aug 2007, 16:14
View user's profile Send private message Reply with quote
f0dder



Joined: 19 Feb 2004
Posts: 3175
Location: Denmark
f0dder 31 Aug 2007, 09:29
I'm not a fan of sbrk(), been annoyed with it ever since DJGPP which used a similar method... mmap() allows for multiple allocs, more control, and won't interfere with e.g. libc.

But okay, it works if you'll only allocate one chunk of memory and never do deallocation or link with libc.
Post 31 Aug 2007, 09:29
View user's profile Send private message Visit poster's website Reply with quote
vid
Verbosity in development


Joined: 05 Sep 2003
Posts: 7105
Location: Slovakia
vid 31 Aug 2007, 12:10
f0dder: sbrk has one advantage over mmap(). you can enlarge sbrk data block, without having to fix pointers. that is not case with mmap, such block cannot often be enlarged without moving it
Post 31 Aug 2007, 12:10
View user's profile Send private message Visit poster's website AIM Address MSN Messenger ICQ Number Reply with quote
f0dder



Joined: 19 Feb 2004
Posts: 3175
Location: Denmark
f0dder 31 Aug 2007, 12:24
You can only enlarge "an sbrk() block" (which is imho incorrect terminology because of it's implementation) if no other sbrk() calls have been made in the meantime.

You can't use mmap() as a replacement for HeapAlloc/HeapReAlloc, but you can't do that with sbrk() either - you need to allocate big chunks of memory and do arena management ontop of that, no matter which method you choose as the underlying big-chunk-manager...
Post 31 Aug 2007, 12:24
View user's profile Send private message Visit poster's website Reply with quote
vid
Verbosity in development


Joined: 05 Sep 2003
Posts: 7105
Location: Slovakia
vid 31 Aug 2007, 13:03
Quote:
You can only enlarge "an sbrk() block" [...] if no other sbrk() calls have been made in the meantime.

yes, that is the disadvantage Smile

Quote:
You can't use mmap() as a replacement for HeapAlloc/HeapReAlloc, but you can't do that with sbrk() either

yup... you need heap manager for that.

- if you need one block, sbrk is okay, and you can enlarge it without having to fix pointers
- if you need more blocks, mmap can be used, but you haveto fix pointers when enlarging blocks, and every block has page-aligned size.
- with heap manager you have to fix pointers too, but blocks have only few bytes of size overhead
Post 31 Aug 2007, 13:03
View user's profile Send private message Visit poster's website AIM Address MSN Messenger ICQ Number Reply with quote
Display posts from previous:
Post new topic Reply to topic

Jump to:  


< Last Thread | Next Thread >
Forum Rules:
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You cannot attach files in this forum
You can download files in this forum


Copyright © 1999-2024, Tomasz Grysztar. Also on GitHub, YouTube.

Website powered by rwasa.