Tunguska the ternary emulator

Balanced Ternary Numeral System - forum was moved from http://ternary.info

Moderator: haqreu

User avatar
Shaos
Admin
Posts: 24011
Joined: 08 Jan 2003 23:22
Location: Silicon Valley

Re: Tunguska the ternary emulator

Post by Shaos »

eudoxie wrote: Nice :-)
1st run on G4-Cube with Debian 5.0:

Code: Select all

g++ `pkg-config sdl --cflags` -O3 -funroll-loops -Wall    -c -o tryte.o tryte.cc
tryte.h: In constructor tryte::tryte():
tryte.h:41: warning: tryte::cache will be initialized after
tryte.h:38: warning:   tryte::change_hook* tryte::hook
tryte.cc:30: warning:   when initialized here
g++ `pkg-config sdl --cflags` -O3 -funroll-loops -Wall    -c -o machine.o machine.cc
g++ `pkg-config sdl --cflags` -O3 -funroll-loops -Wall    -c -o tunguska.o tunguska.cc
g++ `pkg-config sdl --cflags` -O3 -funroll-loops -Wall    -c -o display.o display.cc
g++ `pkg-config sdl --cflags` -O3 -funroll-loops -Wall    -c -o keyboard.o keyboard.cc
g++ `pkg-config sdl --cflags` -O3 -funroll-loops -Wall    -c -o interrupt.o interrupt.cc
g++ `pkg-config sdl --cflags` -O3 -funroll-loops -Wall    -c -o disk.o disk.cc
disk.cc: In member function virtual void disk::load(const char*):
disk.cc:49: error: strdup was not declared in this scope
make: *** [disk.o] Ошибка 1
This is for gcc (Debian 4.3.2-1.1) 4.3.2
User avatar
Shaos
Admin
Posts: 24011
Joined: 08 Jan 2003 23:22
Location: Silicon Valley

Re: Tunguska the ternary emulator

Post by Shaos »

after minor fixes in tryte.cc (order of initialization in constructor) and machine.h (#include <string.h> for strdup):

Code: Select all

g++ `pkg-config sdl --cflags` -O3 -funroll-loops -Wall    -c -o trit.o trit.cc
g++ `pkg-config sdl --cflags` -O3 -funroll-loops -Wall    -c -o tryte.o tryte.cc
g++ `pkg-config sdl --cflags` -O3 -funroll-loops -Wall    -c -o machine.o machine.cc
g++ `pkg-config sdl --cflags` -O3 -funroll-loops -Wall    -c -o tunguska.o tunguska.cc
g++ `pkg-config sdl --cflags` -O3 -funroll-loops -Wall    -c -o display.o display.cc
g++ `pkg-config sdl --cflags` -O3 -funroll-loops -Wall    -c -o keyboard.o keyboard.cc
g++ `pkg-config sdl --cflags` -O3 -funroll-loops -Wall    -c -o interrupt.o interrupt.cc
g++ `pkg-config sdl --cflags` -O3 -funroll-loops -Wall    -c -o disk.o disk.cc
g++ `pkg-config sdl --cflags` -O3 -funroll-loops -Wall    -c -o agdp.o agdp.cc
g++ `pkg-config sdl --cflags` -O3 -funroll-loops -Wall    -c -o memory.o memory.cc
g++ trit.o tryte.o machine.o tunguska.o interrupt.o display.o keyboard.o disk.o agdp.o memory.o -o tunguska `pkg-config sdl --libs` -lfl -lz 
/usr/bin/ld: cannot find -lfl
collect2: ld returned 1 exit status
make: *** [tunguska] Ошибка 1
User avatar
Shaos
Admin
Posts: 24011
Joined: 08 Jan 2003 23:22
Location: Silicon Valley

Re: Tunguska the ternary emulator

Post by Shaos »

after aptitude install flex tunguska and tg_assembler were compiled successfully

after installing packages for GTK development:

Code: Select all

make -C gtkui all
make[1]: Entering directory `/home/shaos/Sources/Tunguska/tunguska_sources/gtkui'
g++ `pkg-config gtk+-2.0 gtksourceview-2.0 gio-2.0 --cflags` -I"../" -O3 -funroll-loops -Wall -DUSE_GTKSOURCEVIEW -ggdb   -c -o tunguska_gtk.o tunguska_gtk.cc
g++ `pkg-config gtk+-2.0 gtksourceview-2.0 gio-2.0 --cflags` -I"../" -O3 -funroll-loops -Wall -DUSE_GTKSOURCEVIEW -ggdb   -c -o processor_monitor.o processor_monitor.cc
g++ `pkg-config gtk+-2.0 gtksourceview-2.0 gio-2.0 --cflags` -I"../" -O3 -funroll-loops -Wall -DUSE_GTKSOURCEVIEW -ggdb   -c -o variable_tracker.o variable_tracker.cc
variable_tracker.cc: In function GtkWidget* build_tracker():
variable_tracker.cc:172: warning: deprecated conversion from string constant to char*
variable_tracker.cc:173: warning: deprecated conversion from string constant to char*
variable_tracker.cc:174: warning: deprecated conversion from string constant to char*
variable_tracker.cc:175: warning: deprecated conversion from string constant to char*
g++ `pkg-config gtk+-2.0 gtksourceview-2.0 gio-2.0 --cflags` -I"../" -O3 -funroll-loops -Wall -DUSE_GTKSOURCEVIEW -ggdb   -c -o code_editor.o code_editor.cc
code_editor.cc: In function GtkWidget* code_editor_new_from_file(const char*):
code_editor.cc:112: warning: deprecated conversion from string constant to char*
code_editor.cc: In function void initiate_language_manager():
code_editor.cc:147: warning: deprecated conversion from string constant to gchar*
code_editor.cc: At global scope:
code_editor.cc:14: warning: code_editor_signals defined but not used
g++ `pkg-config gtk+-2.0 gtksourceview-2.0 gio-2.0 --cflags` -I"../" -O3 -funroll-loops -Wall -DUSE_GTKSOURCEVIEW -ggdb   -c -o inspector.o inspector.cc
g++ `pkg-config gtk+-2.0 gtksourceview-2.0 gio-2.0 --cflags` -I"../" -O3 -funroll-loops -Wall -DUSE_GTKSOURCEVIEW -ggdb   -c -o file_manager.o file_manager.cc
file_manager.cc: In function GtkWidget* create_file_manager():
file_manager.cc:190: warning: deprecated conversion from string constant to gchar*
file_manager.cc:191: warning: deprecated conversion from string constant to gchar*
g++ `pkg-config gtk+-2.0 gtksourceview-2.0 gio-2.0 --cflags` -I"../" -O3 -funroll-loops -Wall -DUSE_GTKSOURCEVIEW -ggdb   -c -o tunguska_wrapper.o tunguska_wrapper.cc
tunguska_wrapper.cc: In function gboolean tunguska_keypress(GtkWidget*, GdkEventKey*, void*):
tunguska_wrapper.cc:168: warning: deprecated conversion from string constant to char*
tunguska_wrapper.cc: In function void init_gcs():
tunguska_wrapper.cc:243: warning: unused variable screen_cm
g++ tunguska_gtk.o processor_monitor.o variable_tracker.o code_editor.o inspector.o  file_manager.o tunguska_wrapper.o ../machine.o ../trit.o ../tryte.o ../disk.o ../memory.o ../interrupt.o ../agdp.o -o tunguska_gtk `pkg-config gtk+-2.0 gtksourceview-2.0 gio-2.0 --libs` -lfl -lz -ggdb
P.S. Also I fixed Makefile to avoid constant recompilation of lex.yy.o and parser.tab.o
User avatar
Shaos
Admin
Posts: 24011
Joined: 08 Jan 2003 23:22
Location: Silicon Valley

Re: Tunguska the ternary emulator

Post by Shaos »

tunguska_3cc also requires #include <string.h>

Code: Select all

bison -d parser.ypp
flex -+ scanner.l
g++ -Wall -g    -c -o variable.o variable.cc
In file included from variable.h:18,
                 from variable.cc:18:
type.h: In member function virtual bool t_struct::operator==(const type&) const:
type.h:179: error: strcmp was not declared in this scope
type.h: In member function virtual const t_struct::field* t_struct::get_field(const char*) const:
type.h:200: error: strcmp was not declared in this scope
In file included from variable.cc:22:
compiler.h: In member function void compiler::set_effective_location(const char*, int):
compiler.h:96: error: strdup was not declared in this scope
make: *** [variable.o] Ошибка 1
fixed type.h and Makefile (for lex and parser rules)

P.S. Everything is working now on my G4 Cube (Initial benchmark: 177.722 thousand operations per second), but tg_assembler produces different file than little-endian machine and I can fix it (to produce little-endian output file even on big-endian machines and to parse it as little-endian in Tunguska)
User avatar
Shaos
Admin
Posts: 24011
Joined: 08 Jan 2003 23:22
Location: Silicon Valley

Re: Tunguska the ternary emulator

Post by Shaos »

Shaos wrote: ... tg_assembler produces different file than little-endian machine and I can fix it (to produce little-endian output file even on big-endian machines and to parse it as little-endian in Tunguska)
memory.cc is fixed and now tg_assembler always produces little-endian output even on big-endian machines and tunguska on big-endian successfully reads input files created on little-endian machines.
User avatar
Shaos
Admin
Posts: 24011
Joined: 08 Jan 2003 23:22
Location: Silicon Valley

Re: Tunguska the ternary emulator

Post by Shaos »

So it's time to release 0.5.1? ;)
eudoxie
Maniac
Posts: 277
Joined: 17 Sep 2012 13:36
Location: 81.170.128.52

Re: Tunguska the ternary emulator

Post by eudoxie »

I've got a few small things to fix, but otherwise, sure. It's got enough fixes to merit a release. I'll try to have a test package ready this weekend.
User avatar
Shaos
Admin
Posts: 24011
Joined: 08 Jan 2003 23:22
Location: Silicon Valley

Re: Tunguska the ternary emulator

Post by Shaos »

eudoxie wrote: I've got a few small things to fix, but otherwise, sure. It's got enough fixes to merit a release. I'll try to have a test package ready this weekend.
OK, and I'll check current code under MacOS X 10.4 on my PowerBook G4
eudoxie
Maniac
Posts: 277
Joined: 17 Sep 2012 13:36
Location: 81.170.128.52

Re: Tunguska the ternary emulator

Post by eudoxie »

Fixed the embarrassing error in symbols.bmp.

Compiles and runs fine on gentoo x86_64 now with your fixes :-)
User avatar
Shaos
Admin
Posts: 24011
Joined: 08 Jan 2003 23:22
Location: Silicon Valley

Re: Tunguska the ternary emulator

Post by Shaos »

eudoxie wrote: Fixed the embarrassing error in symbols.bmp.

Compiles and runs fine on gentoo x86_64 now with your fixes :-)
That's great! :)
I do not have 64-bit Linux yet...
eudoxie
Maniac
Posts: 277
Joined: 17 Sep 2012 13:36
Location: 81.170.128.52

Re: Tunguska the ternary emulator

Post by eudoxie »

I've been thinking, it wouldn't be that much work to have AGDP make use of gcc's OpenMP support to allow parallelization of block transfer operations. They're pragma instructions, so they're fully backwards compatible with non-OpenMP ready compilers, and should seriously reduce the speed the block transfer operations take on multicore CPUs.

Preliminary testing shows that OpenMP-enabled for loops boosts the benchmark on the assembly memory image from ~1500 kOP/s to ~1600 kOP/s on my dual core CPU. Which is a really cheap speed boost, seeing as how the code is only modified at half a dozen places to make it work.
User avatar
Shaos
Admin
Posts: 24011
Joined: 08 Jan 2003 23:22
Location: Silicon Valley

Re: Tunguska the ternary emulator

Post by Shaos »

May be to fully utilize 2-core machine the better strategy is using 2 threads: 1st for graphics and 2nd for calculation itself?
eudoxie
Maniac
Posts: 277
Joined: 17 Sep 2012 13:36
Location: 81.170.128.52

Re: Tunguska the ternary emulator

Post by eudoxie »

That was easier to do before when memory registers weren't asynchronous like they are now, since SDL isn't thread safe making it necessary to do both input and output in the same thread.

A better approach to reduce the graphics overhead is to add some sort minimum redraw interval. Right now, the code often calls updates of the screen way too often (making, worst case scenario, 30% of the CPU time being spent doing nothing but updating the screen).
eudoxie
Maniac
Posts: 277
Joined: 17 Sep 2012 13:36
Location: 81.170.128.52

Re: Tunguska the ternary emulator

Post by eudoxie »

Actually, I tested that approach, and the initial results aren't looking promising. But I think I have a few ideas on ways it might be made to work.
User avatar
Shaos
Admin
Posts: 24011
Joined: 08 Jan 2003 23:22
Location: Silicon Valley

Re: Tunguska the ternary emulator

Post by Shaos »

Shaos wrote:
OK, and I'll check current code under MacOS X 10.4 on my PowerBook G4
I checked - bad news :(
MacOS X 10.4 has older bison version 1.28 that doesn't create cpp/hpp, instead it creates c/h files and I can't compile it even after renaming...