├── .gitignore ├── CMakeLists.txt ├── MakeVS14 - 64.bat ├── external ├── LuaJIT │ ├── COPYRIGHT │ ├── Makefile │ ├── README │ ├── doc │ │ ├── bluequad-print.css │ │ ├── bluequad.css │ │ ├── changes.html │ │ ├── contact.html │ │ ├── ext_c_api.html │ │ ├── ext_ffi.html │ │ ├── ext_ffi_api.html │ │ ├── ext_ffi_semantics.html │ │ ├── ext_ffi_tutorial.html │ │ ├── ext_jit.html │ │ ├── extensions.html │ │ ├── faq.html │ │ ├── img │ │ │ └── contact.png │ │ ├── install.html │ │ ├── luajit.html │ │ ├── running.html │ │ └── status.html │ ├── dynasm │ │ ├── dasm_arm.h │ │ ├── dasm_arm.lua │ │ ├── dasm_mips.h │ │ ├── dasm_mips.lua │ │ ├── dasm_ppc.h │ │ ├── dasm_ppc.lua │ │ ├── dasm_proto.h │ │ ├── dasm_x64.lua │ │ ├── dasm_x86.h │ │ ├── dasm_x86.lua │ │ └── dynasm.lua │ ├── etc │ │ ├── luajit.1 │ │ └── luajit.pc │ ├── lib │ │ ├── x64 │ │ │ └── vs2012 │ │ │ │ ├── lua51.dll │ │ │ │ ├── lua51.exp │ │ │ │ └── lua51.lib │ │ └── x86 │ │ │ ├── lua51.dll │ │ │ ├── lua51.exp │ │ │ ├── lua51.lib │ │ │ └── luajit.exe │ └── src │ │ ├── Makefile │ │ ├── Makefile.dep │ │ ├── host │ │ ├── README │ │ ├── buildvm.c │ │ ├── buildvm.h │ │ ├── buildvm_arch.h │ │ ├── buildvm_asm.c │ │ ├── buildvm_fold.c │ │ ├── buildvm_lib.c │ │ ├── buildvm_peobj.c │ │ ├── genminilua.lua │ │ └── minilua.c │ │ ├── jit │ │ ├── bc.lua │ │ ├── bcsave.lua │ │ ├── dis_arm.lua │ │ ├── dis_mips.lua │ │ ├── dis_mipsel.lua │ │ ├── dis_ppc.lua │ │ ├── dis_x64.lua │ │ ├── dis_x86.lua │ │ ├── dump.lua │ │ ├── v.lua │ │ └── vmdef.lua │ │ ├── lauxlib.h │ │ ├── lib_aux.c │ │ ├── lib_base.c │ │ ├── lib_bit.c │ │ ├── lib_debug.c │ │ ├── lib_ffi.c │ │ ├── lib_init.c │ │ ├── lib_io.c │ │ ├── lib_jit.c │ │ ├── lib_math.c │ │ ├── lib_os.c │ │ ├── lib_package.c │ │ ├── lib_string.c │ │ ├── lib_table.c │ │ ├── lj.supp │ │ ├── lj_alloc.c │ │ ├── lj_alloc.h │ │ ├── lj_api.c │ │ ├── lj_arch.h │ │ ├── lj_asm.c │ │ ├── lj_asm.h │ │ ├── lj_asm_arm.h │ │ ├── lj_asm_mips.h │ │ ├── lj_asm_ppc.h │ │ ├── lj_asm_x86.h │ │ ├── lj_bc.c │ │ ├── lj_bc.h │ │ ├── lj_bcdef.h │ │ ├── lj_bcdump.h │ │ ├── lj_bcread.c │ │ ├── lj_bcwrite.c │ │ ├── lj_carith.c │ │ ├── lj_carith.h │ │ ├── lj_ccall.c │ │ ├── lj_ccall.h │ │ ├── lj_ccallback.c │ │ ├── lj_ccallback.h │ │ ├── lj_cconv.c │ │ ├── lj_cconv.h │ │ ├── lj_cdata.c │ │ ├── lj_cdata.h │ │ ├── lj_char.c │ │ ├── lj_char.h │ │ ├── lj_clib.c │ │ ├── lj_clib.h │ │ ├── lj_cparse.c │ │ ├── lj_cparse.h │ │ ├── lj_crecord.c │ │ ├── lj_crecord.h │ │ ├── lj_ctype.c │ │ ├── lj_ctype.h │ │ ├── lj_debug.c │ │ ├── lj_debug.h │ │ ├── lj_def.h │ │ ├── lj_dispatch.c │ │ ├── lj_dispatch.h │ │ ├── lj_emit_arm.h │ │ ├── lj_emit_mips.h │ │ ├── lj_emit_ppc.h │ │ ├── lj_emit_x86.h │ │ ├── lj_err.c │ │ ├── lj_err.h │ │ ├── lj_errmsg.h │ │ ├── lj_ff.h │ │ ├── lj_ffdef.h │ │ ├── lj_ffrecord.c │ │ ├── lj_ffrecord.h │ │ ├── lj_folddef.h │ │ ├── lj_frame.h │ │ ├── lj_func.c │ │ ├── lj_func.h │ │ ├── lj_gc.c │ │ ├── lj_gc.h │ │ ├── lj_gdbjit.c │ │ ├── lj_gdbjit.h │ │ ├── lj_ir.c │ │ ├── lj_ir.h │ │ ├── lj_ircall.h │ │ ├── lj_iropt.h │ │ ├── lj_jit.h │ │ ├── lj_lex.c │ │ ├── lj_lex.h │ │ ├── lj_lib.c │ │ ├── lj_lib.h │ │ ├── lj_libdef.h │ │ ├── lj_load.c │ │ ├── lj_mcode.c │ │ ├── lj_mcode.h │ │ ├── lj_meta.c │ │ ├── lj_meta.h │ │ ├── lj_obj.c │ │ ├── lj_obj.h │ │ ├── lj_opt_dce.c │ │ ├── lj_opt_fold.c │ │ ├── lj_opt_loop.c │ │ ├── lj_opt_mem.c │ │ ├── lj_opt_narrow.c │ │ ├── lj_opt_sink.c │ │ ├── lj_opt_split.c │ │ ├── lj_parse.c │ │ ├── lj_parse.h │ │ ├── lj_recdef.h │ │ ├── lj_record.c │ │ ├── lj_record.h │ │ ├── lj_snap.c │ │ ├── lj_snap.h │ │ ├── lj_state.c │ │ ├── lj_state.h │ │ ├── lj_str.c │ │ ├── lj_str.h │ │ ├── lj_strscan.c │ │ ├── lj_strscan.h │ │ ├── lj_tab.c │ │ ├── lj_tab.h │ │ ├── lj_target.h │ │ ├── lj_target_arm.h │ │ ├── lj_target_mips.h │ │ ├── lj_target_ppc.h │ │ ├── lj_target_x86.h │ │ ├── lj_trace.c │ │ ├── lj_trace.h │ │ ├── lj_traceerr.h │ │ ├── lj_udata.c │ │ ├── lj_udata.h │ │ ├── lj_vm.h │ │ ├── lj_vmevent.c │ │ ├── lj_vmevent.h │ │ ├── lj_vmmath.c │ │ ├── ljamalg.c │ │ ├── lua.h │ │ ├── lua.hpp │ │ ├── luaconf.h │ │ ├── luajit.c │ │ ├── luajit.exp │ │ ├── luajit.h │ │ ├── luajit.lib │ │ ├── lualib.h │ │ ├── msvcbuild.bat │ │ ├── vm_arm.dasc │ │ ├── vm_mips.dasc │ │ ├── vm_ppc.dasc │ │ ├── vm_ppcspe.dasc │ │ └── vm_x86.dasc ├── ispc │ ├── ReleaseNotes.txt │ ├── contrib │ │ ├── ispc.vim │ │ └── ispc.vim.README │ ├── css │ │ ├── ie.css │ │ └── style.css │ ├── examples │ │ ├── tasksys.cpp │ │ └── timing.h │ ├── faq.html │ ├── ispc.exe │ ├── ispc32.bat │ ├── ispc64.bat │ ├── perfguide.html │ └── users_guide.html ├── rdestl │ ├── LICENSE │ ├── algorithm.h │ ├── alignment.h │ ├── allocator.cpp │ ├── allocator.h │ ├── basic_string.h │ ├── buffer_allocator.h │ ├── cow_string_storage.h │ ├── fixed_array.h │ ├── fixed_list.h │ ├── fixed_sorted_vector.h │ ├── fixed_substring.h │ ├── fixed_vector.h │ ├── functional.h │ ├── hash.h │ ├── hash_map.h │ ├── int_to_type.h │ ├── intrusive_list.cpp │ ├── intrusive_list.h │ ├── intrusive_slist.cpp │ ├── intrusive_slist.h │ ├── iterator.h │ ├── list.cpp │ ├── list.h │ ├── map.h │ ├── pair.h │ ├── radix_sorter.h │ ├── rb_tree.h │ ├── rde_string.h │ ├── rdestl.h │ ├── rdestl_common.h │ ├── set.h │ ├── simple_string_storage.h │ ├── slist.cpp │ ├── slist.h │ ├── sort.h │ ├── sorted_vector.h │ ├── sstream.h │ ├── stack.h │ ├── stack_allocator.h │ ├── string_utils.h │ ├── type_traits.h │ ├── utility.h │ └── vector.h ├── socfatkas │ ├── copyright.txt │ ├── math.h │ ├── rasterizer.cpp │ ├── rasterizer.h │ ├── rasterizer_tile.cpp │ └── rasterizer_tile.h ├── tilde │ ├── HostConfig.cpp │ ├── HostConfig.h │ ├── LuaDebugger.cpp │ ├── LuaDebugger.h │ ├── LuaDebuggerComms.cpp │ ├── LuaDebuggerComms.h │ ├── LuaDebuggerHost.h │ ├── LuaDebuggerProtocol.h │ ├── LuaHostWindows.cpp │ ├── LuaHostWindows.h │ ├── ReceiveMessageBuffer.h │ └── SendMessageBuffer.h └── timer_lib │ ├── Makefile │ ├── README │ ├── test.c │ ├── test.vcxproj │ ├── timer.c │ ├── timer.h │ ├── timer.sln │ └── timer.vcxproj ├── include └── eight │ ├── core │ ├── algorithm.h │ ├── align.h │ ├── alloc │ │ ├── compactpool.h │ │ ├── compactpool.hpp │ │ ├── fixedarray.h │ │ ├── interface.h │ │ ├── malloc.h │ │ ├── new.h │ │ ├── pool.h │ │ ├── pool.hpp │ │ ├── scope.h │ │ ├── scope.hpp │ │ ├── scopearray.h │ │ ├── soapool.h │ │ ├── soapool.hpp │ │ ├── stack.h │ │ └── stack.hpp │ ├── application.h │ ├── array.h │ ├── bind.h │ ├── bit │ │ └── twiddling.h │ ├── blob │ │ ├── asset.h │ │ ├── assetscope.h │ │ ├── blobfactory.h │ │ ├── loader.h │ │ ├── loader_win.h │ │ ├── statichash.h │ │ └── types.h │ ├── bytestream.h │ ├── bytestream.hpp │ ├── debug.h │ ├── handlemap.h │ ├── handlemap.hpp │ ├── hash.h │ ├── id.h │ ├── intrinsics.h │ ├── macro.h │ ├── math │ │ ├── arithmetic.h │ │ ├── frustum.h │ │ ├── half.h │ │ ├── matrix.h │ │ ├── matrix.ispc.h │ │ ├── tmp.h │ │ ├── types.ispc.h │ │ └── vector.h │ ├── message.h │ ├── noncopyable.h │ ├── os │ │ ├── win32.h │ │ ├── win32_undef.h │ │ ├── window.h │ │ └── window_impl.h │ ├── performance.h │ ├── profiler.h │ ├── soa.h │ ├── sort │ │ ├── radix.h │ │ ├── radix.hpp │ │ └── search.h │ ├── test.h │ ├── thread │ │ ├── atomic.h │ │ ├── atomic.hpp │ │ ├── fifo_mpmc.h │ │ ├── fifo_mpmc.hpp │ │ ├── fifo_spsc.h │ │ ├── fifo_spsc.hpp │ │ ├── futex.h │ │ ├── gate.h │ │ ├── hashtable.h │ │ ├── hashtable.hpp │ │ ├── jobqueue.h │ │ ├── latent.h │ │ ├── latentpipe.h │ │ ├── latentpipe.hpp │ │ ├── pool.h │ │ ├── task.h │ │ ├── taskloop.h │ │ ├── tasksection.h │ │ ├── thread.h │ │ ├── threadlocal.h │ │ └── timedloop.h │ ├── throw.h │ ├── timer │ │ └── timer.h │ ├── traits.h │ ├── tuple.h │ ├── typeinfo.h │ ├── types.h │ ├── variablestream.h │ ├── variablestream.hpp │ └── win │ │ └── os.h │ └── lua │ ├── bindlua.h │ ├── lua.h │ └── lua_api.h ├── readme.md └── src ├── core ├── CMakeLists.txt ├── align.cpp ├── alloc │ └── scope.cpp ├── bind.cpp ├── bit │ └── twiddling.cpp ├── blob │ ├── asset.cpp │ └── loader_win.cpp ├── core.cpp ├── core_test.cpp ├── math │ ├── frustum.cpp │ ├── frustum.ispc │ └── frustum_ispc.h ├── message.cpp ├── os │ └── window_win.cpp ├── profiler.cpp ├── profiler_json.cpp ├── sort.cpp ├── test.cpp ├── test_app.cpp ├── thread │ ├── atomic.cpp │ ├── fifo_mpmc.cpp │ ├── fifo_spsc.cpp │ ├── futex.cpp │ ├── jobqueue.cpp │ ├── latentpipe.cpp │ ├── pool.cpp │ ├── task.cpp │ ├── task_test.cpp │ ├── taskloop.cpp │ ├── tasksection.cpp │ ├── tasksection_test.cpp │ ├── thread.cpp │ └── threadlocal.cpp └── timer │ └── timer.cpp └── lua ├── CMakeLists.txt ├── lua.cpp ├── lua_test_app.cpp └── luadebug.cpp /.gitignore: -------------------------------------------------------------------------------- 1 | intermediate/ 2 | cmake_install.cmake 3 | Eight.sln 4 | *.vcproj* 5 | *.ncb 6 | *.suo 7 | *.tmp 8 | *.sdf 9 | *.user 10 | *.opensdf 11 | *.pyc 12 | .DS_Store 13 | ~$* 14 | /bin/ 15 | /lib/ 16 | /tool/bin/ 17 | /tool/eightnet/bin/ 18 | obj/ 19 | *.dir/ 20 | CMakeCache.txt 21 | CMakeFiles/ 22 | doc/html/ 23 | doc/latex/ 24 | doc/rtf/ 25 | msvc/ 26 | msvc10/ 27 | /external/librocket/Build/build/ 28 | /external/freetype-2.3.5/objs/ 29 | *Debug*/ 30 | *Release*/ 31 | *_ispc.h 32 | /external/steam_sdk/tools/ContentBuilder/output 33 | 34 | /msvc11_64 35 | /bin64 36 | /lib64 37 | 38 | /msvc14_64 39 | 40 | -------------------------------------------------------------------------------- /MakeVS14 - 64.bat: -------------------------------------------------------------------------------- 1 | mkdir msvc14_64 2 | cd msvc14_64 3 | cmake -G "Visual Studio 14 2015 Win64" .. 4 | pause -------------------------------------------------------------------------------- /external/LuaJIT/README: -------------------------------------------------------------------------------- 1 | README for LuaJIT 2.0.0 2 | ----------------------- 3 | 4 | LuaJIT is a Just-In-Time (JIT) compiler for the Lua programming language. 5 | 6 | Project Homepage: http://luajit.org/ 7 | 8 | LuaJIT is Copyright (C) 2005-2012 Mike Pall. 9 | LuaJIT is free software, released under the MIT license. 10 | See full Copyright Notice in the COPYRIGHT file or in luajit.h. 11 | 12 | Documentation for LuaJIT is available in HTML format. 13 | Please point your favorite browser to: 14 | 15 | doc/luajit.html 16 | 17 | -------------------------------------------------------------------------------- /external/LuaJIT/doc/img/contact.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hodgman/eight/b3ade9ad355e47bcc853c087d670b55b33933ccb/external/LuaJIT/doc/img/contact.png -------------------------------------------------------------------------------- /external/LuaJIT/dynasm/dasm_proto.h: -------------------------------------------------------------------------------- 1 | /* 2 | ** DynASM encoding engine prototypes. 3 | ** Copyright (C) 2005-2012 Mike Pall. All rights reserved. 4 | ** Released under the MIT license. See dynasm.lua for full copyright notice. 5 | */ 6 | 7 | #ifndef _DASM_PROTO_H 8 | #define _DASM_PROTO_H 9 | 10 | #include 11 | #include 12 | 13 | #define DASM_IDENT "DynASM 1.3.0" 14 | #define DASM_VERSION 10300 /* 1.3.0 */ 15 | 16 | #ifndef Dst_DECL 17 | #define Dst_DECL dasm_State **Dst 18 | #endif 19 | 20 | #ifndef Dst_REF 21 | #define Dst_REF (*Dst) 22 | #endif 23 | 24 | #ifndef DASM_FDEF 25 | #define DASM_FDEF extern 26 | #endif 27 | 28 | #ifndef DASM_M_GROW 29 | #define DASM_M_GROW(ctx, t, p, sz, need) \ 30 | do { \ 31 | size_t _sz = (sz), _need = (need); \ 32 | if (_sz < _need) { \ 33 | if (_sz < 16) _sz = 16; \ 34 | while (_sz < _need) _sz += _sz; \ 35 | (p) = (t *)realloc((p), _sz); \ 36 | if ((p) == NULL) exit(1); \ 37 | (sz) = _sz; \ 38 | } \ 39 | } while(0) 40 | #endif 41 | 42 | #ifndef DASM_M_FREE 43 | #define DASM_M_FREE(ctx, p, sz) free(p) 44 | #endif 45 | 46 | /* Internal DynASM encoder state. */ 47 | typedef struct dasm_State dasm_State; 48 | 49 | 50 | /* Initialize and free DynASM state. */ 51 | DASM_FDEF void dasm_init(Dst_DECL, int maxsection); 52 | DASM_FDEF void dasm_free(Dst_DECL); 53 | 54 | /* Setup global array. Must be called before dasm_setup(). */ 55 | DASM_FDEF void dasm_setupglobal(Dst_DECL, void **gl, unsigned int maxgl); 56 | 57 | /* Grow PC label array. Can be called after dasm_setup(), too. */ 58 | DASM_FDEF void dasm_growpc(Dst_DECL, unsigned int maxpc); 59 | 60 | /* Setup encoder. */ 61 | DASM_FDEF void dasm_setup(Dst_DECL, const void *actionlist); 62 | 63 | /* Feed encoder with actions. Calls are generated by pre-processor. */ 64 | DASM_FDEF void dasm_put(Dst_DECL, int start, ...); 65 | 66 | /* Link sections and return the resulting size. */ 67 | DASM_FDEF int dasm_link(Dst_DECL, size_t *szp); 68 | 69 | /* Encode sections into buffer. */ 70 | DASM_FDEF int dasm_encode(Dst_DECL, void *buffer); 71 | 72 | /* Get PC label offset. */ 73 | DASM_FDEF int dasm_getpclabel(Dst_DECL, unsigned int pc); 74 | 75 | #ifdef DASM_CHECKS 76 | /* Optional sanity checker to call between isolated encoding steps. */ 77 | DASM_FDEF int dasm_checkstep(Dst_DECL, int secmatch); 78 | #else 79 | #define dasm_checkstep(a, b) 0 80 | #endif 81 | 82 | 83 | #endif /* _DASM_PROTO_H */ 84 | -------------------------------------------------------------------------------- /external/LuaJIT/dynasm/dasm_x64.lua: -------------------------------------------------------------------------------- 1 | ------------------------------------------------------------------------------ 2 | -- DynASM x64 module. 3 | -- 4 | -- Copyright (C) 2005-2012 Mike Pall. All rights reserved. 5 | -- See dynasm.lua for full copyright notice. 6 | ------------------------------------------------------------------------------ 7 | -- This module just sets 64 bit mode for the combined x86/x64 module. 8 | -- All the interesting stuff is there. 9 | ------------------------------------------------------------------------------ 10 | 11 | x64 = true -- Using a global is an ugly, but effective solution. 12 | return require("dasm_x86") 13 | -------------------------------------------------------------------------------- /external/LuaJIT/etc/luajit.1: -------------------------------------------------------------------------------- 1 | .TH luajit 1 "" "" "LuaJIT documentation" 2 | .SH NAME 3 | luajit \- Just-In-Time Compiler for the Lua Language 4 | \fB 5 | .SH SYNOPSIS 6 | .B luajit 7 | [\fIoptions\fR]... [\fIscript\fR [\fIargs\fR]...] 8 | .SH "WEB SITE" 9 | .IR http://luajit.org 10 | .SH DESCRIPTION 11 | .PP 12 | This is the command-line program to run Lua programs with \fBLuaJIT\fR. 13 | .PP 14 | \fBLuaJIT\fR is a just-in-time (JIT) compiler for the Lua language. 15 | The virtual machine (VM) is based on a fast interpreter combined with 16 | a trace compiler. It can significantly improve the performance of Lua programs. 17 | .PP 18 | \fBLuaJIT\fR is API\- and ABI-compatible with the VM of the standard 19 | Lua\ 5.1 interpreter. When embedding the VM into an application, 20 | the built library can be used as a drop-in replacement. 21 | .SH OPTIONS 22 | .TP 23 | .BI "\-e " chunk 24 | Run the given chunk of Lua code. 25 | .TP 26 | .BI "\-l " library 27 | Load the named library, just like \fBrequire("\fR\fIlibrary\fR\fB")\fR. 28 | .TP 29 | .BI "\-b " ... 30 | Save or list bytecode. Run without arguments to get help on options. 31 | .TP 32 | .BI "\-j " command 33 | Perform LuaJIT control command (optional space after \fB\-j\fR). 34 | .TP 35 | .BI "\-O" [opt] 36 | Control LuaJIT optimizations. 37 | .TP 38 | .B "\-i" 39 | Run in interactive mode. 40 | .TP 41 | .B "\-v" 42 | Show \fBLuaJIT\fR version. 43 | .TP 44 | .B "\-E" 45 | Ignore environment variables. 46 | .TP 47 | .B "\-\-" 48 | Stop processing options. 49 | .TP 50 | .B "\-" 51 | Read script from stdin instead. 52 | .PP 53 | After all options are processed, the given \fIscript\fR is run. 54 | The arguments are passed in the global \fIarg\fR table. 55 | .PP 56 | Interactive mode is only entered, if no \fIscript\fR and no \fB\-e\fR 57 | option is given. Interactive mode can be left with EOF (\fICtrl\-Z\fB). 58 | .SH EXAMPLES 59 | .TP 60 | luajit hello.lua world 61 | 62 | Prints "Hello world", assuming \fIhello.lua\fR contains: 63 | .br 64 | print("Hello", arg[1]) 65 | .TP 66 | luajit \-e "local x=0; for i=1,1e9 do x=x+i end; print(x)" 67 | 68 | Calculates the sum of the numbers from 1 to 1000000000. 69 | .br 70 | And finishes in a reasonable amount of time, too. 71 | .TP 72 | luajit \-jv \-e "for i=1,10 do for j=1,10 do for k=1,100 do end end end" 73 | 74 | Runs some nested loops and shows the resulting traces. 75 | .SH COPYRIGHT 76 | .PP 77 | \fBLuaJIT\fR is Copyright \(co 2005-2012 Mike Pall. 78 | .br 79 | \fBLuaJIT\fR is open source software, released under the MIT license. 80 | .SH SEE ALSO 81 | .PP 82 | More details in the provided HTML docs or at: 83 | .IR http://luajit.org 84 | .br 85 | More about the Lua language can be found at: 86 | .IR http://lua.org/docs.html 87 | .PP 88 | lua(1) 89 | -------------------------------------------------------------------------------- /external/LuaJIT/etc/luajit.pc: -------------------------------------------------------------------------------- 1 | # Package information for LuaJIT to be used by pkg-config. 2 | majver=2 3 | minver=0 4 | relver=0 5 | version=${majver}.${minver}.${relver} 6 | abiver=5.1 7 | 8 | prefix=/usr/local 9 | exec_prefix=${prefix} 10 | libdir=${exec_prefix}/lib 11 | libname=luajit-${abiver} 12 | includedir=${prefix}/include/luajit-${majver}.${minver} 13 | 14 | INSTALL_LMOD=${prefix}/share/lua/${abiver} 15 | INSTALL_CMOD=${prefix}/lib/lua/${abiver} 16 | 17 | Name: LuaJIT 18 | Description: Just-in-time compiler for Lua 19 | URL: http://luajit.org 20 | Version: ${version} 21 | Requires: 22 | Libs: -L${libdir} -l${libname} 23 | Libs.private: -Wl,-E -lm -ldl 24 | Cflags: -I${includedir} 25 | -------------------------------------------------------------------------------- /external/LuaJIT/lib/x64/vs2012/lua51.dll: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hodgman/eight/b3ade9ad355e47bcc853c087d670b55b33933ccb/external/LuaJIT/lib/x64/vs2012/lua51.dll -------------------------------------------------------------------------------- /external/LuaJIT/lib/x64/vs2012/lua51.exp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hodgman/eight/b3ade9ad355e47bcc853c087d670b55b33933ccb/external/LuaJIT/lib/x64/vs2012/lua51.exp -------------------------------------------------------------------------------- /external/LuaJIT/lib/x64/vs2012/lua51.lib: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hodgman/eight/b3ade9ad355e47bcc853c087d670b55b33933ccb/external/LuaJIT/lib/x64/vs2012/lua51.lib -------------------------------------------------------------------------------- /external/LuaJIT/lib/x86/lua51.dll: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hodgman/eight/b3ade9ad355e47bcc853c087d670b55b33933ccb/external/LuaJIT/lib/x86/lua51.dll -------------------------------------------------------------------------------- /external/LuaJIT/lib/x86/lua51.exp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hodgman/eight/b3ade9ad355e47bcc853c087d670b55b33933ccb/external/LuaJIT/lib/x86/lua51.exp -------------------------------------------------------------------------------- /external/LuaJIT/lib/x86/lua51.lib: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hodgman/eight/b3ade9ad355e47bcc853c087d670b55b33933ccb/external/LuaJIT/lib/x86/lua51.lib -------------------------------------------------------------------------------- /external/LuaJIT/lib/x86/luajit.exe: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hodgman/eight/b3ade9ad355e47bcc853c087d670b55b33933ccb/external/LuaJIT/lib/x86/luajit.exe -------------------------------------------------------------------------------- /external/LuaJIT/src/host/README: -------------------------------------------------------------------------------- 1 | The files in this directory are only used during the build process of LuaJIT. 2 | For cross-compilation, they must be executed on the host, not on the target. 3 | 4 | These files should NOT be installed! 5 | -------------------------------------------------------------------------------- /external/LuaJIT/src/jit/dis_mipsel.lua: -------------------------------------------------------------------------------- 1 | ---------------------------------------------------------------------------- 2 | -- LuaJIT MIPSEL disassembler wrapper module. 3 | -- 4 | -- Copyright (C) 2005-2011 Mike Pall. All rights reserved. 5 | -- Released under the MIT license. See Copyright Notice in luajit.h 6 | ---------------------------------------------------------------------------- 7 | -- This module just exports the little-endian functions from the 8 | -- MIPS disassembler module. All the interesting stuff is there. 9 | ------------------------------------------------------------------------------ 10 | 11 | local require = require 12 | 13 | module(...) 14 | 15 | local dis_mips = require(_PACKAGE.."dis_mips") 16 | 17 | create = dis_mips.create_el 18 | disass = dis_mips.disass_el 19 | regname = dis_mips.regname 20 | 21 | -------------------------------------------------------------------------------- /external/LuaJIT/src/jit/dis_x64.lua: -------------------------------------------------------------------------------- 1 | ---------------------------------------------------------------------------- 2 | -- LuaJIT x64 disassembler wrapper module. 3 | -- 4 | -- Copyright (C) 2005-2012 Mike Pall. All rights reserved. 5 | -- Released under the MIT license. See Copyright Notice in luajit.h 6 | ---------------------------------------------------------------------------- 7 | -- This module just exports the 64 bit functions from the combined 8 | -- x86/x64 disassembler module. All the interesting stuff is there. 9 | ------------------------------------------------------------------------------ 10 | 11 | local require = require 12 | 13 | module(...) 14 | 15 | local dis_x86 = require(_PACKAGE.."dis_x86") 16 | 17 | create = dis_x86.create64 18 | disass = dis_x86.disass64 19 | regname = dis_x86.regname64 20 | 21 | -------------------------------------------------------------------------------- /external/LuaJIT/src/lib_bit.c: -------------------------------------------------------------------------------- 1 | /* 2 | ** Bit manipulation library. 3 | ** Copyright (C) 2005-2012 Mike Pall. See Copyright Notice in luajit.h 4 | */ 5 | 6 | #define lib_bit_c 7 | #define LUA_LIB 8 | 9 | #include "lua.h" 10 | #include "lauxlib.h" 11 | #include "lualib.h" 12 | 13 | #include "lj_obj.h" 14 | #include "lj_err.h" 15 | #include "lj_str.h" 16 | #include "lj_lib.h" 17 | 18 | /* ------------------------------------------------------------------------ */ 19 | 20 | #define LJLIB_MODULE_bit 21 | 22 | LJLIB_ASM(bit_tobit) LJLIB_REC(bit_unary IR_TOBIT) 23 | { 24 | lj_lib_checknumber(L, 1); 25 | return FFH_RETRY; 26 | } 27 | LJLIB_ASM_(bit_bnot) LJLIB_REC(bit_unary IR_BNOT) 28 | LJLIB_ASM_(bit_bswap) LJLIB_REC(bit_unary IR_BSWAP) 29 | 30 | LJLIB_ASM(bit_lshift) LJLIB_REC(bit_shift IR_BSHL) 31 | { 32 | lj_lib_checknumber(L, 1); 33 | lj_lib_checkbit(L, 2); 34 | return FFH_RETRY; 35 | } 36 | LJLIB_ASM_(bit_rshift) LJLIB_REC(bit_shift IR_BSHR) 37 | LJLIB_ASM_(bit_arshift) LJLIB_REC(bit_shift IR_BSAR) 38 | LJLIB_ASM_(bit_rol) LJLIB_REC(bit_shift IR_BROL) 39 | LJLIB_ASM_(bit_ror) LJLIB_REC(bit_shift IR_BROR) 40 | 41 | LJLIB_ASM(bit_band) LJLIB_REC(bit_nary IR_BAND) 42 | { 43 | int i = 0; 44 | do { lj_lib_checknumber(L, ++i); } while (L->base+i < L->top); 45 | return FFH_RETRY; 46 | } 47 | LJLIB_ASM_(bit_bor) LJLIB_REC(bit_nary IR_BOR) 48 | LJLIB_ASM_(bit_bxor) LJLIB_REC(bit_nary IR_BXOR) 49 | 50 | /* ------------------------------------------------------------------------ */ 51 | 52 | LJLIB_CF(bit_tohex) 53 | { 54 | uint32_t b = (uint32_t)lj_lib_checkbit(L, 1); 55 | int32_t i, n = L->base+1 >= L->top ? 8 : lj_lib_checkbit(L, 2); 56 | const char *hexdigits = "0123456789abcdef"; 57 | char buf[8]; 58 | if (n < 0) { n = -n; hexdigits = "0123456789ABCDEF"; } 59 | if (n > 8) n = 8; 60 | for (i = n; --i >= 0; ) { buf[i] = hexdigits[b & 15]; b >>= 4; } 61 | lua_pushlstring(L, buf, (size_t)n); 62 | return 1; 63 | } 64 | 65 | /* ------------------------------------------------------------------------ */ 66 | 67 | #include "lj_libdef.h" 68 | 69 | LUALIB_API int luaopen_bit(lua_State *L) 70 | { 71 | LJ_LIB_REG(L, LUA_BITLIBNAME, bit); 72 | return 1; 73 | } 74 | 75 | -------------------------------------------------------------------------------- /external/LuaJIT/src/lib_init.c: -------------------------------------------------------------------------------- 1 | /* 2 | ** Library initialization. 3 | ** Major parts taken verbatim from the Lua interpreter. 4 | ** Copyright (C) 1994-2008 Lua.org, PUC-Rio. See Copyright Notice in lua.h 5 | */ 6 | 7 | #define lib_init_c 8 | #define LUA_LIB 9 | 10 | #include "lua.h" 11 | #include "lauxlib.h" 12 | #include "lualib.h" 13 | 14 | #include "lj_arch.h" 15 | 16 | static const luaL_Reg lj_lib_load[] = { 17 | { "", luaopen_base }, 18 | { LUA_LOADLIBNAME, luaopen_package }, 19 | { LUA_TABLIBNAME, luaopen_table }, 20 | { LUA_IOLIBNAME, luaopen_io }, 21 | { LUA_OSLIBNAME, luaopen_os }, 22 | { LUA_STRLIBNAME, luaopen_string }, 23 | { LUA_MATHLIBNAME, luaopen_math }, 24 | { LUA_DBLIBNAME, luaopen_debug }, 25 | { LUA_BITLIBNAME, luaopen_bit }, 26 | { LUA_JITLIBNAME, luaopen_jit }, 27 | { NULL, NULL } 28 | }; 29 | 30 | static const luaL_Reg lj_lib_preload[] = { 31 | #if LJ_HASFFI 32 | { LUA_FFILIBNAME, luaopen_ffi }, 33 | #endif 34 | { NULL, NULL } 35 | }; 36 | 37 | LUALIB_API void luaL_openlibs(lua_State *L) 38 | { 39 | const luaL_Reg *lib; 40 | for (lib = lj_lib_load; lib->func; lib++) { 41 | lua_pushcfunction(L, lib->func); 42 | lua_pushstring(L, lib->name); 43 | lua_call(L, 1, 0); 44 | } 45 | luaL_findtable(L, LUA_REGISTRYINDEX, "_PRELOAD", 46 | sizeof(lj_lib_preload)/sizeof(lj_lib_preload[0])-1); 47 | for (lib = lj_lib_preload; lib->func; lib++) { 48 | lua_pushcfunction(L, lib->func); 49 | lua_setfield(L, -2, lib->name); 50 | } 51 | lua_pop(L, 1); 52 | } 53 | 54 | -------------------------------------------------------------------------------- /external/LuaJIT/src/lj.supp: -------------------------------------------------------------------------------- 1 | # Valgrind suppression file for LuaJIT 2.0. 2 | { 3 | Optimized string compare 4 | Memcheck:Addr4 5 | fun:lj_str_cmp 6 | } 7 | { 8 | Optimized string compare 9 | Memcheck:Addr1 10 | fun:lj_str_cmp 11 | } 12 | { 13 | Optimized string compare 14 | Memcheck:Addr4 15 | fun:lj_str_new 16 | } 17 | { 18 | Optimized string compare 19 | Memcheck:Addr1 20 | fun:lj_str_new 21 | } 22 | { 23 | Optimized string compare 24 | Memcheck:Cond 25 | fun:lj_str_new 26 | } 27 | -------------------------------------------------------------------------------- /external/LuaJIT/src/lj_alloc.h: -------------------------------------------------------------------------------- 1 | /* 2 | ** Bundled memory allocator. 3 | ** Donated to the public domain. 4 | */ 5 | 6 | #ifndef _LJ_ALLOC_H 7 | #define _LJ_ALLOC_H 8 | 9 | #include "lj_def.h" 10 | 11 | #ifndef LUAJIT_USE_SYSMALLOC 12 | LJ_FUNC void *lj_alloc_create(void); 13 | LJ_FUNC void lj_alloc_destroy(void *msp); 14 | LJ_FUNC void *lj_alloc_f(void *msp, void *ptr, size_t osize, size_t nsize); 15 | #endif 16 | 17 | #endif 18 | -------------------------------------------------------------------------------- /external/LuaJIT/src/lj_asm.h: -------------------------------------------------------------------------------- 1 | /* 2 | ** IR assembler (SSA IR -> machine code). 3 | ** Copyright (C) 2005-2012 Mike Pall. See Copyright Notice in luajit.h 4 | */ 5 | 6 | #ifndef _LJ_ASM_H 7 | #define _LJ_ASM_H 8 | 9 | #include "lj_jit.h" 10 | 11 | #if LJ_HASJIT 12 | LJ_FUNC void lj_asm_trace(jit_State *J, GCtrace *T); 13 | LJ_FUNC void lj_asm_patchexit(jit_State *J, GCtrace *T, ExitNo exitno, 14 | MCode *target); 15 | #endif 16 | 17 | #endif 18 | -------------------------------------------------------------------------------- /external/LuaJIT/src/lj_bc.c: -------------------------------------------------------------------------------- 1 | /* 2 | ** Bytecode instruction modes. 3 | ** Copyright (C) 2005-2012 Mike Pall. See Copyright Notice in luajit.h 4 | */ 5 | 6 | #define lj_bc_c 7 | #define LUA_CORE 8 | 9 | #include "lj_obj.h" 10 | #include "lj_bc.h" 11 | 12 | /* Bytecode offsets and bytecode instruction modes. */ 13 | #include "lj_bcdef.h" 14 | 15 | -------------------------------------------------------------------------------- /external/LuaJIT/src/lj_bcdump.h: -------------------------------------------------------------------------------- 1 | /* 2 | ** Bytecode dump definitions. 3 | ** Copyright (C) 2005-2012 Mike Pall. See Copyright Notice in luajit.h 4 | */ 5 | 6 | #ifndef _LJ_BCDUMP_H 7 | #define _LJ_BCDUMP_H 8 | 9 | #include "lj_obj.h" 10 | #include "lj_lex.h" 11 | 12 | /* -- Bytecode dump format ------------------------------------------------ */ 13 | 14 | /* 15 | ** dump = header proto+ 0U 16 | ** header = ESC 'L' 'J' versionB flagsU [namelenU nameB*] 17 | ** proto = lengthU pdata 18 | ** pdata = phead bcinsW* uvdataH* kgc* knum* [debugB*] 19 | ** phead = flagsB numparamsB framesizeB numuvB numkgcU numknU numbcU 20 | ** [debuglenU [firstlineU numlineU]] 21 | ** kgc = kgctypeU { ktab | (loU hiU) | (rloU rhiU iloU ihiU) | strB* } 22 | ** knum = intU0 | (loU1 hiU) 23 | ** ktab = narrayU nhashU karray* khash* 24 | ** karray = ktabk 25 | ** khash = ktabk ktabk 26 | ** ktabk = ktabtypeU { intU | (loU hiU) | strB* } 27 | ** 28 | ** B = 8 bit, H = 16 bit, W = 32 bit, U = ULEB128 of W, U0/U1 = ULEB128 of W+1 29 | */ 30 | 31 | /* Bytecode dump header. */ 32 | #define BCDUMP_HEAD1 0x1b 33 | #define BCDUMP_HEAD2 0x4c 34 | #define BCDUMP_HEAD3 0x4a 35 | 36 | /* If you perform *any* kind of private modifications to the bytecode itself 37 | ** or to the dump format, you *must* set BCDUMP_VERSION to 0x80 or higher. 38 | */ 39 | #define BCDUMP_VERSION 1 40 | 41 | /* Compatibility flags. */ 42 | #define BCDUMP_F_BE 0x01 43 | #define BCDUMP_F_STRIP 0x02 44 | #define BCDUMP_F_FFI 0x04 45 | 46 | #define BCDUMP_F_KNOWN (BCDUMP_F_FFI*2-1) 47 | 48 | /* Type codes for the GC constants of a prototype. Plus length for strings. */ 49 | enum { 50 | BCDUMP_KGC_CHILD, BCDUMP_KGC_TAB, BCDUMP_KGC_I64, BCDUMP_KGC_U64, 51 | BCDUMP_KGC_COMPLEX, BCDUMP_KGC_STR 52 | }; 53 | 54 | /* Type codes for the keys/values of a constant table. */ 55 | enum { 56 | BCDUMP_KTAB_NIL, BCDUMP_KTAB_FALSE, BCDUMP_KTAB_TRUE, 57 | BCDUMP_KTAB_INT, BCDUMP_KTAB_NUM, BCDUMP_KTAB_STR 58 | }; 59 | 60 | /* -- Bytecode reader/writer ---------------------------------------------- */ 61 | 62 | LJ_FUNC int lj_bcwrite(lua_State *L, GCproto *pt, lua_Writer writer, 63 | void *data, int strip); 64 | LJ_FUNC GCproto *lj_bcread(LexState *ls); 65 | 66 | #endif 67 | -------------------------------------------------------------------------------- /external/LuaJIT/src/lj_carith.h: -------------------------------------------------------------------------------- 1 | /* 2 | ** C data arithmetic. 3 | ** Copyright (C) 2005-2012 Mike Pall. See Copyright Notice in luajit.h 4 | */ 5 | 6 | #ifndef _LJ_CARITH_H 7 | #define _LJ_CARITH_H 8 | 9 | #include "lj_obj.h" 10 | 11 | #if LJ_HASFFI 12 | 13 | LJ_FUNC int lj_carith_op(lua_State *L, MMS mm); 14 | 15 | #if LJ_32 && LJ_HASJIT 16 | LJ_FUNC int64_t lj_carith_mul64(int64_t x, int64_t k); 17 | #endif 18 | LJ_FUNC uint64_t lj_carith_divu64(uint64_t a, uint64_t b); 19 | LJ_FUNC int64_t lj_carith_divi64(int64_t a, int64_t b); 20 | LJ_FUNC uint64_t lj_carith_modu64(uint64_t a, uint64_t b); 21 | LJ_FUNC int64_t lj_carith_modi64(int64_t a, int64_t b); 22 | LJ_FUNC uint64_t lj_carith_powu64(uint64_t x, uint64_t k); 23 | LJ_FUNC int64_t lj_carith_powi64(int64_t x, int64_t k); 24 | 25 | #endif 26 | 27 | #endif 28 | -------------------------------------------------------------------------------- /external/LuaJIT/src/lj_ccallback.h: -------------------------------------------------------------------------------- 1 | /* 2 | ** FFI C callback handling. 3 | ** Copyright (C) 2005-2012 Mike Pall. See Copyright Notice in luajit.h 4 | */ 5 | 6 | #ifndef _LJ_CCALLBACK_H 7 | #define _LJ_CCALLBACK_H 8 | 9 | #include "lj_obj.h" 10 | #include "lj_ctype.h" 11 | 12 | #if LJ_HASFFI 13 | 14 | /* Really belongs to lj_vm.h. */ 15 | LJ_ASMF void lj_vm_ffi_callback(void); 16 | 17 | LJ_FUNC MSize lj_ccallback_ptr2slot(CTState *cts, void *p); 18 | LJ_FUNCA lua_State * LJ_FASTCALL lj_ccallback_enter(CTState *cts, void *cf); 19 | LJ_FUNCA void LJ_FASTCALL lj_ccallback_leave(CTState *cts, TValue *o); 20 | LJ_FUNC void *lj_ccallback_new(CTState *cts, CType *ct, GCfunc *fn); 21 | LJ_FUNC void lj_ccallback_mcode_free(CTState *cts); 22 | 23 | #endif 24 | 25 | #endif 26 | -------------------------------------------------------------------------------- /external/LuaJIT/src/lj_cconv.h: -------------------------------------------------------------------------------- 1 | /* 2 | ** C type conversions. 3 | ** Copyright (C) 2005-2012 Mike Pall. See Copyright Notice in luajit.h 4 | */ 5 | 6 | #ifndef _LJ_CCONV_H 7 | #define _LJ_CCONV_H 8 | 9 | #include "lj_obj.h" 10 | #include "lj_ctype.h" 11 | 12 | #if LJ_HASFFI 13 | 14 | /* Compressed C type index. ORDER CCX. */ 15 | enum { 16 | CCX_B, /* Bool. */ 17 | CCX_I, /* Integer. */ 18 | CCX_F, /* Floating-point number. */ 19 | CCX_C, /* Complex. */ 20 | CCX_V, /* Vector. */ 21 | CCX_P, /* Pointer. */ 22 | CCX_A, /* Refarray. */ 23 | CCX_S /* Struct/union. */ 24 | }; 25 | 26 | /* Convert C type info to compressed C type index. ORDER CT. ORDER CCX. */ 27 | static LJ_AINLINE uint32_t cconv_idx(CTInfo info) 28 | { 29 | uint32_t idx = ((info >> 26) & 15u); /* Dispatch bits. */ 30 | lua_assert(ctype_type(info) <= CT_MAYCONVERT); 31 | #if LJ_64 32 | idx = ((U64x(f436fff5,fff7f021) >> 4*idx) & 15u); 33 | #else 34 | idx = (((idx < 8 ? 0xfff7f021u : 0xf436fff5) >> 4*(idx & 7u)) & 15u); 35 | #endif 36 | lua_assert(idx < 8); 37 | return idx; 38 | } 39 | 40 | #define cconv_idx2(dinfo, sinfo) \ 41 | ((cconv_idx((dinfo)) << 3) + cconv_idx((sinfo))) 42 | 43 | #define CCX(dst, src) ((CCX_##dst << 3) + CCX_##src) 44 | 45 | /* Conversion flags. */ 46 | #define CCF_CAST 0x00000001u 47 | #define CCF_FROMTV 0x00000002u 48 | #define CCF_SAME 0x00000004u 49 | #define CCF_IGNQUAL 0x00000008u 50 | 51 | #define CCF_ARG_SHIFT 8 52 | #define CCF_ARG(n) ((n) << CCF_ARG_SHIFT) 53 | #define CCF_GETARG(f) ((f) >> CCF_ARG_SHIFT) 54 | 55 | LJ_FUNC int lj_cconv_compatptr(CTState *cts, CType *d, CType *s, CTInfo flags); 56 | LJ_FUNC void lj_cconv_ct_ct(CTState *cts, CType *d, CType *s, 57 | uint8_t *dp, uint8_t *sp, CTInfo flags); 58 | LJ_FUNC int lj_cconv_tv_ct(CTState *cts, CType *s, CTypeID sid, 59 | TValue *o, uint8_t *sp); 60 | LJ_FUNC int lj_cconv_tv_bf(CTState *cts, CType *s, TValue *o, uint8_t *sp); 61 | LJ_FUNC void lj_cconv_ct_tv(CTState *cts, CType *d, 62 | uint8_t *dp, TValue *o, CTInfo flags); 63 | LJ_FUNC void lj_cconv_bf_tv(CTState *cts, CType *d, uint8_t *dp, TValue *o); 64 | LJ_FUNC int lj_cconv_multi_init(CTState *cts, CType *d, TValue *o); 65 | LJ_FUNC void lj_cconv_ct_init(CTState *cts, CType *d, CTSize sz, 66 | uint8_t *dp, TValue *o, MSize len); 67 | 68 | #endif 69 | 70 | #endif 71 | -------------------------------------------------------------------------------- /external/LuaJIT/src/lj_cdata.h: -------------------------------------------------------------------------------- 1 | /* 2 | ** C data management. 3 | ** Copyright (C) 2005-2012 Mike Pall. See Copyright Notice in luajit.h 4 | */ 5 | 6 | #ifndef _LJ_CDATA_H 7 | #define _LJ_CDATA_H 8 | 9 | #include "lj_obj.h" 10 | #include "lj_gc.h" 11 | #include "lj_ctype.h" 12 | 13 | #if LJ_HASFFI 14 | 15 | /* Get C data pointer. */ 16 | static LJ_AINLINE void *cdata_getptr(void *p, CTSize sz) 17 | { 18 | if (LJ_64 && sz == 4) { /* Support 32 bit pointers on 64 bit targets. */ 19 | return ((void *)(uintptr_t)*(uint32_t *)p); 20 | } else { 21 | lua_assert(sz == CTSIZE_PTR); 22 | return *(void **)p; 23 | } 24 | } 25 | 26 | /* Set C data pointer. */ 27 | static LJ_AINLINE void cdata_setptr(void *p, CTSize sz, const void *v) 28 | { 29 | if (LJ_64 && sz == 4) { /* Support 32 bit pointers on 64 bit targets. */ 30 | *(uint32_t *)p = (uint32_t)(uintptr_t)v; 31 | } else { 32 | lua_assert(sz == CTSIZE_PTR); 33 | *(void **)p = (void *)v; 34 | } 35 | } 36 | 37 | /* Allocate fixed-size C data object. */ 38 | static LJ_AINLINE GCcdata *lj_cdata_new(CTState *cts, CTypeID id, CTSize sz) 39 | { 40 | GCcdata *cd; 41 | #ifdef LUA_USE_ASSERT 42 | CType *ct = ctype_raw(cts, id); 43 | lua_assert((ctype_hassize(ct->info) ? ct->size : CTSIZE_PTR) == sz); 44 | #endif 45 | cd = (GCcdata *)lj_mem_newgco(cts->L, sizeof(GCcdata) + sz); 46 | cd->gct = ~LJ_TCDATA; 47 | cd->ctypeid = ctype_check(cts, id); 48 | return cd; 49 | } 50 | 51 | /* Variant which works without a valid CTState. */ 52 | static LJ_AINLINE GCcdata *lj_cdata_new_(lua_State *L, CTypeID id, CTSize sz) 53 | { 54 | GCcdata *cd = (GCcdata *)lj_mem_newgco(L, sizeof(GCcdata) + sz); 55 | cd->gct = ~LJ_TCDATA; 56 | cd->ctypeid = id; 57 | return cd; 58 | } 59 | 60 | LJ_FUNC GCcdata *lj_cdata_newref(CTState *cts, const void *pp, CTypeID id); 61 | LJ_FUNC GCcdata *lj_cdata_newv(CTState *cts, CTypeID id, CTSize sz, 62 | CTSize align); 63 | 64 | LJ_FUNC void LJ_FASTCALL lj_cdata_free(global_State *g, GCcdata *cd); 65 | LJ_FUNCA TValue * LJ_FASTCALL lj_cdata_setfin(lua_State *L, GCcdata *cd); 66 | 67 | LJ_FUNC CType *lj_cdata_index(CTState *cts, GCcdata *cd, cTValue *key, 68 | uint8_t **pp, CTInfo *qual); 69 | LJ_FUNC int lj_cdata_get(CTState *cts, CType *s, TValue *o, uint8_t *sp); 70 | LJ_FUNC void lj_cdata_set(CTState *cts, CType *d, uint8_t *dp, TValue *o, 71 | CTInfo qual); 72 | 73 | #endif 74 | 75 | #endif 76 | -------------------------------------------------------------------------------- /external/LuaJIT/src/lj_char.c: -------------------------------------------------------------------------------- 1 | /* 2 | ** Character types. 3 | ** Donated to the public domain. 4 | ** 5 | ** This is intended to replace the problematic libc single-byte NLS functions. 6 | ** These just don't make sense anymore with UTF-8 locales becoming the norm 7 | ** on POSIX systems. It never worked too well on Windows systems since hardly 8 | ** anyone bothered to call setlocale(). 9 | ** 10 | ** This table is hardcoded for ASCII. Identifiers include the characters 11 | ** 128-255, too. This allows for the use of all non-ASCII chars as identifiers 12 | ** in the lexer. This is a broad definition, but works well in practice 13 | ** for both UTF-8 locales and most single-byte locales (such as ISO-8859-*). 14 | ** 15 | ** If you really need proper character types for UTF-8 strings, please use 16 | ** an add-on library such as slnunicode: http://luaforge.net/projects/sln/ 17 | */ 18 | 19 | #define lj_char_c 20 | #define LUA_CORE 21 | 22 | #include "lj_char.h" 23 | 24 | LJ_DATADEF const uint8_t lj_char_bits[257] = { 25 | 0, 26 | 1, 1, 1, 1, 1, 1, 1, 1, 1, 3, 3, 3, 3, 3, 1, 1, 27 | 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 28 | 2, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 29 | 152,152,152,152,152,152,152,152,152,152, 4, 4, 4, 4, 4, 4, 30 | 4,176,176,176,176,176,176,160,160,160,160,160,160,160,160,160, 31 | 160,160,160,160,160,160,160,160,160,160,160, 4, 4, 4, 4,132, 32 | 4,208,208,208,208,208,208,192,192,192,192,192,192,192,192,192, 33 | 192,192,192,192,192,192,192,192,192,192,192, 4, 4, 4, 4, 1, 34 | 128,128,128,128,128,128,128,128,128,128,128,128,128,128,128,128, 35 | 128,128,128,128,128,128,128,128,128,128,128,128,128,128,128,128, 36 | 128,128,128,128,128,128,128,128,128,128,128,128,128,128,128,128, 37 | 128,128,128,128,128,128,128,128,128,128,128,128,128,128,128,128, 38 | 128,128,128,128,128,128,128,128,128,128,128,128,128,128,128,128, 39 | 128,128,128,128,128,128,128,128,128,128,128,128,128,128,128,128, 40 | 128,128,128,128,128,128,128,128,128,128,128,128,128,128,128,128, 41 | 128,128,128,128,128,128,128,128,128,128,128,128,128,128,128,128 42 | }; 43 | 44 | -------------------------------------------------------------------------------- /external/LuaJIT/src/lj_char.h: -------------------------------------------------------------------------------- 1 | /* 2 | ** Character types. 3 | ** Donated to the public domain. 4 | */ 5 | 6 | #ifndef _LJ_CHAR_H 7 | #define _LJ_CHAR_H 8 | 9 | #include "lj_def.h" 10 | 11 | #define LJ_CHAR_CNTRL 0x01 12 | #define LJ_CHAR_SPACE 0x02 13 | #define LJ_CHAR_PUNCT 0x04 14 | #define LJ_CHAR_DIGIT 0x08 15 | #define LJ_CHAR_XDIGIT 0x10 16 | #define LJ_CHAR_UPPER 0x20 17 | #define LJ_CHAR_LOWER 0x40 18 | #define LJ_CHAR_IDENT 0x80 19 | #define LJ_CHAR_ALPHA (LJ_CHAR_LOWER|LJ_CHAR_UPPER) 20 | #define LJ_CHAR_ALNUM (LJ_CHAR_ALPHA|LJ_CHAR_DIGIT) 21 | #define LJ_CHAR_GRAPH (LJ_CHAR_ALNUM|LJ_CHAR_PUNCT) 22 | 23 | /* Only pass -1 or 0..255 to these macros. Never pass a signed char! */ 24 | #define lj_char_isa(c, t) ((lj_char_bits+1)[(c)] & t) 25 | #define lj_char_iscntrl(c) lj_char_isa((c), LJ_CHAR_CNTRL) 26 | #define lj_char_isspace(c) lj_char_isa((c), LJ_CHAR_SPACE) 27 | #define lj_char_ispunct(c) lj_char_isa((c), LJ_CHAR_PUNCT) 28 | #define lj_char_isdigit(c) lj_char_isa((c), LJ_CHAR_DIGIT) 29 | #define lj_char_isxdigit(c) lj_char_isa((c), LJ_CHAR_XDIGIT) 30 | #define lj_char_isupper(c) lj_char_isa((c), LJ_CHAR_UPPER) 31 | #define lj_char_islower(c) lj_char_isa((c), LJ_CHAR_LOWER) 32 | #define lj_char_isident(c) lj_char_isa((c), LJ_CHAR_IDENT) 33 | #define lj_char_isalpha(c) lj_char_isa((c), LJ_CHAR_ALPHA) 34 | #define lj_char_isalnum(c) lj_char_isa((c), LJ_CHAR_ALNUM) 35 | #define lj_char_isgraph(c) lj_char_isa((c), LJ_CHAR_GRAPH) 36 | 37 | #define lj_char_toupper(c) ((c) - (lj_char_islower(c) >> 1)) 38 | #define lj_char_tolower(c) ((c) + lj_char_isupper(c)) 39 | 40 | LJ_DATA const uint8_t lj_char_bits[257]; 41 | 42 | #endif 43 | -------------------------------------------------------------------------------- /external/LuaJIT/src/lj_clib.h: -------------------------------------------------------------------------------- 1 | /* 2 | ** FFI C library loader. 3 | ** Copyright (C) 2005-2012 Mike Pall. See Copyright Notice in luajit.h 4 | */ 5 | 6 | #ifndef _LJ_CLIB_H 7 | #define _LJ_CLIB_H 8 | 9 | #include "lj_obj.h" 10 | 11 | #if LJ_HASFFI 12 | 13 | /* Namespace for C library indexing. */ 14 | #define CLNS_INDEX ((1u<env. */ 20 | } CLibrary; 21 | 22 | LJ_FUNC TValue *lj_clib_index(lua_State *L, CLibrary *cl, GCstr *name); 23 | LJ_FUNC void lj_clib_load(lua_State *L, GCtab *mt, GCstr *name, int global); 24 | LJ_FUNC void lj_clib_unload(CLibrary *cl); 25 | LJ_FUNC void lj_clib_default(lua_State *L, GCtab *mt); 26 | 27 | #endif 28 | 29 | #endif 30 | -------------------------------------------------------------------------------- /external/LuaJIT/src/lj_cparse.h: -------------------------------------------------------------------------------- 1 | /* 2 | ** C declaration parser. 3 | ** Copyright (C) 2005-2012 Mike Pall. See Copyright Notice in luajit.h 4 | */ 5 | 6 | #ifndef _LJ_CPARSE_H 7 | #define _LJ_CPARSE_H 8 | 9 | #include "lj_obj.h" 10 | #include "lj_ctype.h" 11 | 12 | #if LJ_HASFFI 13 | 14 | /* C parser limits. */ 15 | #define CPARSE_MAX_BUF 32768 /* Max. token buffer size. */ 16 | #define CPARSE_MAX_DECLSTACK 100 /* Max. declaration stack depth. */ 17 | #define CPARSE_MAX_DECLDEPTH 20 /* Max. recursive declaration depth. */ 18 | #define CPARSE_MAX_PACKSTACK 7 /* Max. pack pragma stack depth. */ 19 | 20 | /* Flags for C parser mode. */ 21 | #define CPARSE_MODE_MULTI 1 /* Process multiple declarations. */ 22 | #define CPARSE_MODE_ABSTRACT 2 /* Accept abstract declarators. */ 23 | #define CPARSE_MODE_DIRECT 4 /* Accept direct declarators. */ 24 | #define CPARSE_MODE_FIELD 8 /* Accept field width in bits, too. */ 25 | #define CPARSE_MODE_NOIMPLICIT 16 /* Reject implicit declarations. */ 26 | #define CPARSE_MODE_SKIP 32 /* Skip definitions, ignore errors. */ 27 | 28 | typedef int CPChar; /* C parser character. Unsigned ext. from char. */ 29 | typedef int CPToken; /* C parser token. */ 30 | 31 | /* C parser internal value representation. */ 32 | typedef struct CPValue { 33 | union { 34 | int32_t i32; /* Value for CTID_INT32. */ 35 | uint32_t u32; /* Value for CTID_UINT32. */ 36 | }; 37 | CTypeID id; /* C Type ID of the value. */ 38 | } CPValue; 39 | 40 | /* C parser state. */ 41 | typedef struct CPState { 42 | CPChar c; /* Current character. */ 43 | CPToken tok; /* Current token. */ 44 | CPValue val; /* Token value. */ 45 | GCstr *str; /* Interned string of identifier/keyword. */ 46 | CType *ct; /* C type table entry. */ 47 | const char *p; /* Current position in input buffer. */ 48 | SBuf sb; /* String buffer for tokens. */ 49 | lua_State *L; /* Lua state. */ 50 | CTState *cts; /* C type state. */ 51 | TValue *param; /* C type parameters. */ 52 | const char *srcname; /* Current source name. */ 53 | BCLine linenumber; /* Input line counter. */ 54 | int depth; /* Recursive declaration depth. */ 55 | uint32_t tmask; /* Type mask for next identifier. */ 56 | uint32_t mode; /* C parser mode. */ 57 | uint8_t packstack[CPARSE_MAX_PACKSTACK]; /* Stack for pack pragmas. */ 58 | uint8_t curpack; /* Current position in pack pragma stack. */ 59 | } CPState; 60 | 61 | LJ_FUNC int lj_cparse(CPState *cp); 62 | 63 | #endif 64 | 65 | #endif 66 | -------------------------------------------------------------------------------- /external/LuaJIT/src/lj_crecord.h: -------------------------------------------------------------------------------- 1 | /* 2 | ** Trace recorder for C data operations. 3 | ** Copyright (C) 2005-2012 Mike Pall. See Copyright Notice in luajit.h 4 | */ 5 | 6 | #ifndef _LJ_CRECORD_H 7 | #define _LJ_CRECORD_H 8 | 9 | #include "lj_obj.h" 10 | #include "lj_jit.h" 11 | #include "lj_ffrecord.h" 12 | 13 | #if LJ_HASJIT && LJ_HASFFI 14 | LJ_FUNC void LJ_FASTCALL recff_cdata_index(jit_State *J, RecordFFData *rd); 15 | LJ_FUNC void LJ_FASTCALL recff_cdata_call(jit_State *J, RecordFFData *rd); 16 | LJ_FUNC void LJ_FASTCALL recff_cdata_arith(jit_State *J, RecordFFData *rd); 17 | LJ_FUNC void LJ_FASTCALL recff_clib_index(jit_State *J, RecordFFData *rd); 18 | LJ_FUNC void LJ_FASTCALL recff_ffi_new(jit_State *J, RecordFFData *rd); 19 | LJ_FUNC void LJ_FASTCALL recff_ffi_errno(jit_State *J, RecordFFData *rd); 20 | LJ_FUNC void LJ_FASTCALL recff_ffi_string(jit_State *J, RecordFFData *rd); 21 | LJ_FUNC void LJ_FASTCALL recff_ffi_copy(jit_State *J, RecordFFData *rd); 22 | LJ_FUNC void LJ_FASTCALL recff_ffi_fill(jit_State *J, RecordFFData *rd); 23 | LJ_FUNC void LJ_FASTCALL recff_ffi_typeof(jit_State *J, RecordFFData *rd); 24 | LJ_FUNC void LJ_FASTCALL recff_ffi_istype(jit_State *J, RecordFFData *rd); 25 | LJ_FUNC void LJ_FASTCALL recff_ffi_abi(jit_State *J, RecordFFData *rd); 26 | LJ_FUNC void LJ_FASTCALL recff_ffi_xof(jit_State *J, RecordFFData *rd); 27 | LJ_FUNC void LJ_FASTCALL recff_ffi_gc(jit_State *J, RecordFFData *rd); 28 | LJ_FUNC void LJ_FASTCALL lj_crecord_tonumber(jit_State *J, RecordFFData *rd); 29 | #endif 30 | 31 | #endif 32 | -------------------------------------------------------------------------------- /external/LuaJIT/src/lj_debug.h: -------------------------------------------------------------------------------- 1 | /* 2 | ** Debugging and introspection. 3 | ** Copyright (C) 2005-2012 Mike Pall. See Copyright Notice in luajit.h 4 | */ 5 | 6 | #ifndef _LJ_DEBUG_H 7 | #define _LJ_DEBUG_H 8 | 9 | #include "lj_obj.h" 10 | 11 | typedef struct lj_Debug { 12 | /* Common fields. Must be in the same order as in lua.h. */ 13 | int event; 14 | const char *name; 15 | const char *namewhat; 16 | const char *what; 17 | const char *source; 18 | int currentline; 19 | int nups; 20 | int linedefined; 21 | int lastlinedefined; 22 | char short_src[LUA_IDSIZE]; 23 | int i_ci; 24 | /* Extended fields. Only valid if lj_debug_getinfo() is called with ext = 1.*/ 25 | int nparams; 26 | int isvararg; 27 | } lj_Debug; 28 | 29 | LJ_FUNC cTValue *lj_debug_frame(lua_State *L, int level, int *size); 30 | LJ_FUNC BCLine LJ_FASTCALL lj_debug_line(GCproto *pt, BCPos pc); 31 | LJ_FUNC const char *lj_debug_uvname(GCproto *pt, uint32_t idx); 32 | LJ_FUNC const char *lj_debug_uvnamev(cTValue *o, uint32_t idx, TValue **tvp); 33 | LJ_FUNC const char *lj_debug_slotname(GCproto *pt, const BCIns *pc, 34 | BCReg slot, const char **name); 35 | LJ_FUNC const char *lj_debug_funcname(lua_State *L, TValue *frame, 36 | const char **name); 37 | LJ_FUNC void lj_debug_shortname(char *out, GCstr *str); 38 | LJ_FUNC void lj_debug_addloc(lua_State *L, const char *msg, 39 | cTValue *frame, cTValue *nextframe); 40 | LJ_FUNC void lj_debug_pushloc(lua_State *L, GCproto *pt, BCPos pc); 41 | LJ_FUNC int lj_debug_getinfo(lua_State *L, const char *what, lj_Debug *ar, 42 | int ext); 43 | 44 | /* Fixed internal variable names. */ 45 | #define VARNAMEDEF(_) \ 46 | _(FOR_IDX, "(for index)") \ 47 | _(FOR_STOP, "(for limit)") \ 48 | _(FOR_STEP, "(for step)") \ 49 | _(FOR_GEN, "(for generator)") \ 50 | _(FOR_STATE, "(for state)") \ 51 | _(FOR_CTL, "(for control)") 52 | 53 | enum { 54 | VARNAME_END, 55 | #define VARNAMEENUM(name, str) VARNAME_##name, 56 | VARNAMEDEF(VARNAMEENUM) 57 | #undef VARNAMEENUM 58 | VARNAME__MAX 59 | }; 60 | 61 | #endif 62 | -------------------------------------------------------------------------------- /external/LuaJIT/src/lj_err.h: -------------------------------------------------------------------------------- 1 | /* 2 | ** Error handling. 3 | ** Copyright (C) 2005-2012 Mike Pall. See Copyright Notice in luajit.h 4 | */ 5 | 6 | #ifndef _LJ_ERR_H 7 | #define _LJ_ERR_H 8 | 9 | #include 10 | 11 | #include "lj_obj.h" 12 | 13 | typedef enum { 14 | #define ERRDEF(name, msg) \ 15 | LJ_ERR_##name, LJ_ERR_##name##_ = LJ_ERR_##name + sizeof(msg)-1, 16 | #include "lj_errmsg.h" 17 | LJ_ERR__MAX 18 | } ErrMsg; 19 | 20 | LJ_DATA const char *lj_err_allmsg; 21 | #define err2msg(em) (lj_err_allmsg+(int)(em)) 22 | 23 | LJ_FUNC GCstr *lj_err_str(lua_State *L, ErrMsg em); 24 | LJ_FUNCA_NORET void LJ_FASTCALL lj_err_throw(lua_State *L, int errcode); 25 | LJ_FUNC_NORET void lj_err_mem(lua_State *L); 26 | LJ_FUNC_NORET void lj_err_run(lua_State *L); 27 | LJ_FUNC_NORET void lj_err_msg(lua_State *L, ErrMsg em); 28 | LJ_FUNC_NORET void lj_err_lex(lua_State *L, GCstr *src, const char *tok, 29 | BCLine line, ErrMsg em, va_list argp); 30 | LJ_FUNC_NORET void lj_err_optype(lua_State *L, cTValue *o, ErrMsg opm); 31 | LJ_FUNC_NORET void lj_err_comp(lua_State *L, cTValue *o1, cTValue *o2); 32 | LJ_FUNC_NORET void lj_err_optype_call(lua_State *L, TValue *o); 33 | LJ_FUNC_NORET void lj_err_callermsg(lua_State *L, const char *msg); 34 | LJ_FUNC_NORET void lj_err_callerv(lua_State *L, ErrMsg em, ...); 35 | LJ_FUNC_NORET void lj_err_caller(lua_State *L, ErrMsg em); 36 | LJ_FUNC_NORET void lj_err_arg(lua_State *L, int narg, ErrMsg em); 37 | LJ_FUNC_NORET void lj_err_argv(lua_State *L, int narg, ErrMsg em, ...); 38 | LJ_FUNC_NORET void lj_err_argtype(lua_State *L, int narg, const char *xname); 39 | LJ_FUNC_NORET void lj_err_argt(lua_State *L, int narg, int tt); 40 | 41 | #endif 42 | -------------------------------------------------------------------------------- /external/LuaJIT/src/lj_ff.h: -------------------------------------------------------------------------------- 1 | /* 2 | ** Fast function IDs. 3 | ** Copyright (C) 2005-2012 Mike Pall. See Copyright Notice in luajit.h 4 | */ 5 | 6 | #ifndef _LJ_FF_H 7 | #define _LJ_FF_H 8 | 9 | /* Fast function ID. */ 10 | typedef enum { 11 | FF_LUA_ = FF_LUA, /* Lua function (must be 0). */ 12 | FF_C_ = FF_C, /* Regular C function (must be 1). */ 13 | #define FFDEF(name) FF_##name, 14 | #include "lj_ffdef.h" 15 | FF__MAX 16 | } FastFunc; 17 | 18 | #endif 19 | -------------------------------------------------------------------------------- /external/LuaJIT/src/lj_ffrecord.h: -------------------------------------------------------------------------------- 1 | /* 2 | ** Fast function call recorder. 3 | ** Copyright (C) 2005-2012 Mike Pall. See Copyright Notice in luajit.h 4 | */ 5 | 6 | #ifndef _LJ_FFRECORD_H 7 | #define _LJ_FFRECORD_H 8 | 9 | #include "lj_obj.h" 10 | #include "lj_jit.h" 11 | 12 | #if LJ_HASJIT 13 | /* Data used by handlers to record a fast function. */ 14 | typedef struct RecordFFData { 15 | TValue *argv; /* Runtime argument values. */ 16 | ptrdiff_t nres; /* Number of returned results (defaults to 1). */ 17 | uint32_t data; /* Per-ffid auxiliary data (opcode, literal etc.). */ 18 | } RecordFFData; 19 | 20 | LJ_FUNC int32_t lj_ffrecord_select_mode(jit_State *J, TRef tr, TValue *tv); 21 | LJ_FUNC void lj_ffrecord_func(jit_State *J); 22 | #endif 23 | 24 | #endif 25 | -------------------------------------------------------------------------------- /external/LuaJIT/src/lj_func.h: -------------------------------------------------------------------------------- 1 | /* 2 | ** Function handling (prototypes, functions and upvalues). 3 | ** Copyright (C) 2005-2012 Mike Pall. See Copyright Notice in luajit.h 4 | */ 5 | 6 | #ifndef _LJ_FUNC_H 7 | #define _LJ_FUNC_H 8 | 9 | #include "lj_obj.h" 10 | 11 | /* Prototypes. */ 12 | LJ_FUNC void LJ_FASTCALL lj_func_freeproto(global_State *g, GCproto *pt); 13 | 14 | /* Upvalues. */ 15 | LJ_FUNCA void LJ_FASTCALL lj_func_closeuv(lua_State *L, TValue *level); 16 | LJ_FUNC void LJ_FASTCALL lj_func_freeuv(global_State *g, GCupval *uv); 17 | 18 | /* Functions (closures). */ 19 | LJ_FUNC GCfunc *lj_func_newC(lua_State *L, MSize nelems, GCtab *env); 20 | LJ_FUNC GCfunc *lj_func_newL_empty(lua_State *L, GCproto *pt, GCtab *env); 21 | LJ_FUNCA GCfunc *lj_func_newL_gc(lua_State *L, GCproto *pt, GCfuncL *parent); 22 | LJ_FUNC void LJ_FASTCALL lj_func_free(global_State *g, GCfunc *c); 23 | 24 | #endif 25 | -------------------------------------------------------------------------------- /external/LuaJIT/src/lj_gdbjit.h: -------------------------------------------------------------------------------- 1 | /* 2 | ** Client for the GDB JIT API. 3 | ** Copyright (C) 2005-2012 Mike Pall. See Copyright Notice in luajit.h 4 | */ 5 | 6 | #ifndef _LJ_GDBJIT_H 7 | #define _LJ_GDBJIT_H 8 | 9 | #include "lj_obj.h" 10 | #include "lj_jit.h" 11 | 12 | #if LJ_HASJIT && defined(LUAJIT_USE_GDBJIT) 13 | 14 | LJ_FUNC void lj_gdbjit_addtrace(jit_State *J, GCtrace *T); 15 | LJ_FUNC void lj_gdbjit_deltrace(jit_State *J, GCtrace *T); 16 | 17 | #else 18 | #define lj_gdbjit_addtrace(J, T) UNUSED(T) 19 | #define lj_gdbjit_deltrace(J, T) UNUSED(T) 20 | #endif 21 | 22 | #endif 23 | -------------------------------------------------------------------------------- /external/LuaJIT/src/lj_mcode.h: -------------------------------------------------------------------------------- 1 | /* 2 | ** Machine code management. 3 | ** Copyright (C) 2005-2012 Mike Pall. See Copyright Notice in luajit.h 4 | */ 5 | 6 | #ifndef _LJ_MCODE_H 7 | #define _LJ_MCODE_H 8 | 9 | #include "lj_obj.h" 10 | 11 | #if LJ_HASJIT || LJ_HASFFI 12 | LJ_FUNC void lj_mcode_sync(void *start, void *end); 13 | #endif 14 | 15 | #if LJ_HASJIT 16 | 17 | #include "lj_jit.h" 18 | 19 | LJ_FUNC void lj_mcode_free(jit_State *J); 20 | LJ_FUNC MCode *lj_mcode_reserve(jit_State *J, MCode **lim); 21 | LJ_FUNC void lj_mcode_commit(jit_State *J, MCode *m); 22 | LJ_FUNC void lj_mcode_abort(jit_State *J); 23 | LJ_FUNC MCode *lj_mcode_patch(jit_State *J, MCode *ptr, int finish); 24 | LJ_FUNC_NORET void lj_mcode_limiterr(jit_State *J, size_t need); 25 | 26 | #define lj_mcode_commitbot(J, m) (J->mcbot = (m)) 27 | 28 | #endif 29 | 30 | #endif 31 | -------------------------------------------------------------------------------- /external/LuaJIT/src/lj_meta.h: -------------------------------------------------------------------------------- 1 | /* 2 | ** Metamethod handling. 3 | ** Copyright (C) 2005-2012 Mike Pall. See Copyright Notice in luajit.h 4 | */ 5 | 6 | #ifndef _LJ_META_H 7 | #define _LJ_META_H 8 | 9 | #include "lj_obj.h" 10 | 11 | /* Metamethod handling */ 12 | LJ_FUNC void lj_meta_init(lua_State *L); 13 | LJ_FUNC cTValue *lj_meta_cache(GCtab *mt, MMS mm, GCstr *name); 14 | LJ_FUNC cTValue *lj_meta_lookup(lua_State *L, cTValue *o, MMS mm); 15 | #if LJ_HASFFI 16 | LJ_FUNC int lj_meta_tailcall(lua_State *L, cTValue *tv); 17 | #endif 18 | 19 | #define lj_meta_fastg(g, mt, mm) \ 20 | ((mt) == NULL ? NULL : ((mt)->nomm & (1u<<(mm))) ? NULL : \ 21 | lj_meta_cache(mt, mm, mmname_str(g, mm))) 22 | #define lj_meta_fast(L, mt, mm) lj_meta_fastg(G(L), mt, mm) 23 | 24 | /* C helpers for some instructions, called from assembler VM. */ 25 | LJ_FUNCA cTValue *lj_meta_tget(lua_State *L, cTValue *o, cTValue *k); 26 | LJ_FUNCA TValue *lj_meta_tset(lua_State *L, cTValue *o, cTValue *k); 27 | LJ_FUNCA TValue *lj_meta_arith(lua_State *L, TValue *ra, cTValue *rb, 28 | cTValue *rc, BCReg op); 29 | LJ_FUNCA TValue *lj_meta_cat(lua_State *L, TValue *top, int left); 30 | LJ_FUNCA TValue * LJ_FASTCALL lj_meta_len(lua_State *L, cTValue *o); 31 | LJ_FUNCA TValue *lj_meta_equal(lua_State *L, GCobj *o1, GCobj *o2, int ne); 32 | LJ_FUNCA TValue * LJ_FASTCALL lj_meta_equal_cd(lua_State *L, BCIns ins); 33 | LJ_FUNCA TValue *lj_meta_comp(lua_State *L, cTValue *o1, cTValue *o2, int op); 34 | LJ_FUNCA void lj_meta_call(lua_State *L, TValue *func, TValue *top); 35 | LJ_FUNCA void LJ_FASTCALL lj_meta_for(lua_State *L, TValue *o); 36 | 37 | #endif 38 | -------------------------------------------------------------------------------- /external/LuaJIT/src/lj_obj.c: -------------------------------------------------------------------------------- 1 | /* 2 | ** Miscellaneous object handling. 3 | ** Copyright (C) 2005-2012 Mike Pall. See Copyright Notice in luajit.h 4 | */ 5 | 6 | #define lj_obj_c 7 | #define LUA_CORE 8 | 9 | #include "lj_obj.h" 10 | 11 | /* Object type names. */ 12 | LJ_DATADEF const char *const lj_obj_typename[] = { /* ORDER LUA_T */ 13 | "no value", "nil", "boolean", "userdata", "number", "string", 14 | "table", "function", "userdata", "thread", "proto", "cdata" 15 | }; 16 | 17 | LJ_DATADEF const char *const lj_obj_itypename[] = { /* ORDER LJ_T */ 18 | "nil", "boolean", "boolean", "userdata", "string", "upval", "thread", 19 | "proto", "function", "trace", "cdata", "table", "userdata", "number" 20 | }; 21 | 22 | /* Compare two objects without calling metamethods. */ 23 | int lj_obj_equal(cTValue *o1, cTValue *o2) 24 | { 25 | if (itype(o1) == itype(o2)) { 26 | if (tvispri(o1)) 27 | return 1; 28 | if (!tvisnum(o1)) 29 | return gcrefeq(o1->gcr, o2->gcr); 30 | } else if (!tvisnumber(o1) || !tvisnumber(o2)) { 31 | return 0; 32 | } 33 | return numberVnum(o1) == numberVnum(o2); 34 | } 35 | 36 | -------------------------------------------------------------------------------- /external/LuaJIT/src/lj_opt_dce.c: -------------------------------------------------------------------------------- 1 | /* 2 | ** DCE: Dead Code Elimination. Pre-LOOP only -- ASM already performs DCE. 3 | ** Copyright (C) 2005-2012 Mike Pall. See Copyright Notice in luajit.h 4 | */ 5 | 6 | #define lj_opt_dce_c 7 | #define LUA_CORE 8 | 9 | #include "lj_obj.h" 10 | 11 | #if LJ_HASJIT 12 | 13 | #include "lj_ir.h" 14 | #include "lj_jit.h" 15 | #include "lj_iropt.h" 16 | 17 | /* Some local macros to save typing. Undef'd at the end. */ 18 | #define IR(ref) (&J->cur.ir[(ref)]) 19 | 20 | /* Scan through all snapshots and mark all referenced instructions. */ 21 | static void dce_marksnap(jit_State *J) 22 | { 23 | SnapNo i, nsnap = J->cur.nsnap; 24 | for (i = 0; i < nsnap; i++) { 25 | SnapShot *snap = &J->cur.snap[i]; 26 | SnapEntry *map = &J->cur.snapmap[snap->mapofs]; 27 | MSize n, nent = snap->nent; 28 | for (n = 0; n < nent; n++) { 29 | IRRef ref = snap_ref(map[n]); 30 | if (ref >= REF_FIRST) 31 | irt_setmark(IR(ref)->t); 32 | } 33 | } 34 | } 35 | 36 | /* Backwards propagate marks. Replace unused instructions with NOPs. */ 37 | static void dce_propagate(jit_State *J) 38 | { 39 | IRRef1 *pchain[IR__MAX]; 40 | IRRef ins; 41 | uint32_t i; 42 | for (i = 0; i < IR__MAX; i++) pchain[i] = &J->chain[i]; 43 | for (ins = J->cur.nins-1; ins >= REF_FIRST; ins--) { 44 | IRIns *ir = IR(ins); 45 | if (irt_ismarked(ir->t)) { 46 | irt_clearmark(ir->t); 47 | pchain[ir->o] = &ir->prev; 48 | } else if (!ir_sideeff(ir)) { 49 | *pchain[ir->o] = ir->prev; /* Reroute original instruction chain. */ 50 | ir->t.irt = IRT_NIL; 51 | ir->o = IR_NOP; /* Replace instruction with NOP. */ 52 | ir->op1 = ir->op2 = 0; 53 | ir->prev = 0; 54 | continue; 55 | } 56 | if (ir->op1 >= REF_FIRST) irt_setmark(IR(ir->op1)->t); 57 | if (ir->op2 >= REF_FIRST) irt_setmark(IR(ir->op2)->t); 58 | } 59 | } 60 | 61 | /* Dead Code Elimination. 62 | ** 63 | ** First backpropagate marks for all used instructions. Then replace 64 | ** the unused ones with a NOP. Note that compressing the IR to eliminate 65 | ** the NOPs does not pay off. 66 | */ 67 | void lj_opt_dce(jit_State *J) 68 | { 69 | if ((J->flags & JIT_F_OPT_DCE)) { 70 | dce_marksnap(J); 71 | dce_propagate(J); 72 | } 73 | } 74 | 75 | #undef IR 76 | 77 | #endif 78 | -------------------------------------------------------------------------------- /external/LuaJIT/src/lj_parse.h: -------------------------------------------------------------------------------- 1 | /* 2 | ** Lua parser (source code -> bytecode). 3 | ** Copyright (C) 2005-2012 Mike Pall. See Copyright Notice in luajit.h 4 | */ 5 | 6 | #ifndef _LJ_PARSE_H 7 | #define _LJ_PARSE_H 8 | 9 | #include "lj_obj.h" 10 | #include "lj_lex.h" 11 | 12 | LJ_FUNC GCproto *lj_parse(LexState *ls); 13 | LJ_FUNC GCstr *lj_parse_keepstr(LexState *ls, const char *str, size_t l); 14 | #if LJ_HASFFI 15 | LJ_FUNC void lj_parse_keepcdata(LexState *ls, TValue *tv, GCcdata *cd); 16 | #endif 17 | 18 | #endif 19 | -------------------------------------------------------------------------------- /external/LuaJIT/src/lj_record.h: -------------------------------------------------------------------------------- 1 | /* 2 | ** Trace recorder (bytecode -> SSA IR). 3 | ** Copyright (C) 2005-2012 Mike Pall. See Copyright Notice in luajit.h 4 | */ 5 | 6 | #ifndef _LJ_RECORD_H 7 | #define _LJ_RECORD_H 8 | 9 | #include "lj_obj.h" 10 | #include "lj_jit.h" 11 | 12 | #if LJ_HASJIT 13 | /* Context for recording an indexed load/store. */ 14 | typedef struct RecordIndex { 15 | TValue tabv; /* Runtime value of table (or indexed object). */ 16 | TValue keyv; /* Runtime value of key. */ 17 | TValue valv; /* Runtime value of stored value. */ 18 | TValue mobjv; /* Runtime value of metamethod object. */ 19 | GCtab *mtv; /* Runtime value of metatable object. */ 20 | cTValue *oldv; /* Runtime value of previously stored value. */ 21 | TRef tab; /* Table (or indexed object) reference. */ 22 | TRef key; /* Key reference. */ 23 | TRef val; /* Value reference for a store or 0 for a load. */ 24 | TRef mt; /* Metatable reference. */ 25 | TRef mobj; /* Metamethod object reference. */ 26 | int idxchain; /* Index indirections left or 0 for raw lookup. */ 27 | } RecordIndex; 28 | 29 | LJ_FUNC int lj_record_objcmp(jit_State *J, TRef a, TRef b, 30 | cTValue *av, cTValue *bv); 31 | LJ_FUNC TRef lj_record_constify(jit_State *J, cTValue *o); 32 | 33 | LJ_FUNC void lj_record_call(jit_State *J, BCReg func, ptrdiff_t nargs); 34 | LJ_FUNC void lj_record_tailcall(jit_State *J, BCReg func, ptrdiff_t nargs); 35 | LJ_FUNC void lj_record_ret(jit_State *J, BCReg rbase, ptrdiff_t gotresults); 36 | 37 | LJ_FUNC int lj_record_mm_lookup(jit_State *J, RecordIndex *ix, MMS mm); 38 | LJ_FUNC TRef lj_record_idx(jit_State *J, RecordIndex *ix); 39 | 40 | LJ_FUNC void lj_record_ins(jit_State *J); 41 | LJ_FUNC void lj_record_setup(jit_State *J); 42 | #endif 43 | 44 | #endif 45 | -------------------------------------------------------------------------------- /external/LuaJIT/src/lj_snap.h: -------------------------------------------------------------------------------- 1 | /* 2 | ** Snapshot handling. 3 | ** Copyright (C) 2005-2012 Mike Pall. See Copyright Notice in luajit.h 4 | */ 5 | 6 | #ifndef _LJ_SNAP_H 7 | #define _LJ_SNAP_H 8 | 9 | #include "lj_obj.h" 10 | #include "lj_jit.h" 11 | 12 | #if LJ_HASJIT 13 | LJ_FUNC void lj_snap_add(jit_State *J); 14 | LJ_FUNC void lj_snap_purge(jit_State *J); 15 | LJ_FUNC void lj_snap_shrink(jit_State *J); 16 | LJ_FUNC IRIns *lj_snap_regspmap(GCtrace *T, SnapNo snapno, IRIns *ir); 17 | LJ_FUNC void lj_snap_replay(jit_State *J, GCtrace *T); 18 | LJ_FUNC const BCIns *lj_snap_restore(jit_State *J, void *exptr); 19 | LJ_FUNC void lj_snap_grow_buf_(jit_State *J, MSize need); 20 | LJ_FUNC void lj_snap_grow_map_(jit_State *J, MSize need); 21 | 22 | static LJ_AINLINE void lj_snap_grow_buf(jit_State *J, MSize need) 23 | { 24 | if (LJ_UNLIKELY(need > J->sizesnap)) lj_snap_grow_buf_(J, need); 25 | } 26 | 27 | static LJ_AINLINE void lj_snap_grow_map(jit_State *J, MSize need) 28 | { 29 | if (LJ_UNLIKELY(need > J->sizesnapmap)) lj_snap_grow_map_(J, need); 30 | } 31 | 32 | #endif 33 | 34 | #endif 35 | -------------------------------------------------------------------------------- /external/LuaJIT/src/lj_state.h: -------------------------------------------------------------------------------- 1 | /* 2 | ** State and stack handling. 3 | ** Copyright (C) 2005-2012 Mike Pall. See Copyright Notice in luajit.h 4 | */ 5 | 6 | #ifndef _LJ_STATE_H 7 | #define _LJ_STATE_H 8 | 9 | #include "lj_obj.h" 10 | 11 | #define incr_top(L) \ 12 | (++L->top >= tvref(L->maxstack) && (lj_state_growstack1(L), 0)) 13 | 14 | #define savestack(L, p) ((char *)(p) - mref(L->stack, char)) 15 | #define restorestack(L, n) ((TValue *)(mref(L->stack, char) + (n))) 16 | 17 | LJ_FUNC void lj_state_relimitstack(lua_State *L); 18 | LJ_FUNC void lj_state_shrinkstack(lua_State *L, MSize used); 19 | LJ_FUNCA void LJ_FASTCALL lj_state_growstack(lua_State *L, MSize need); 20 | LJ_FUNC void LJ_FASTCALL lj_state_growstack1(lua_State *L); 21 | 22 | static LJ_AINLINE void lj_state_checkstack(lua_State *L, MSize need) 23 | { 24 | if ((mref(L->maxstack, char) - (char *)L->top) <= 25 | (ptrdiff_t)need*(ptrdiff_t)sizeof(TValue)) 26 | lj_state_growstack(L, need); 27 | } 28 | 29 | LJ_FUNC lua_State *lj_state_new(lua_State *L); 30 | LJ_FUNC void LJ_FASTCALL lj_state_free(global_State *g, lua_State *L); 31 | #if LJ_64 32 | LJ_FUNC lua_State *lj_state_newstate(lua_Alloc f, void *ud); 33 | #endif 34 | 35 | #endif 36 | -------------------------------------------------------------------------------- /external/LuaJIT/src/lj_str.h: -------------------------------------------------------------------------------- 1 | /* 2 | ** String handling. 3 | ** Copyright (C) 2005-2012 Mike Pall. See Copyright Notice in luajit.h 4 | */ 5 | 6 | #ifndef _LJ_STR_H 7 | #define _LJ_STR_H 8 | 9 | #include 10 | 11 | #include "lj_obj.h" 12 | 13 | /* String interning. */ 14 | LJ_FUNC int32_t LJ_FASTCALL lj_str_cmp(GCstr *a, GCstr *b); 15 | LJ_FUNC void lj_str_resize(lua_State *L, MSize newmask); 16 | LJ_FUNCA GCstr *lj_str_new(lua_State *L, const char *str, size_t len); 17 | LJ_FUNC void LJ_FASTCALL lj_str_free(global_State *g, GCstr *s); 18 | 19 | #define lj_str_newz(L, s) (lj_str_new(L, s, strlen(s))) 20 | #define lj_str_newlit(L, s) (lj_str_new(L, "" s, sizeof(s)-1)) 21 | 22 | /* Type conversions. */ 23 | LJ_FUNC size_t LJ_FASTCALL lj_str_bufnum(char *s, cTValue *o); 24 | LJ_FUNC char * LJ_FASTCALL lj_str_bufint(char *p, int32_t k); 25 | LJ_FUNCA GCstr * LJ_FASTCALL lj_str_fromnum(lua_State *L, const lua_Number *np); 26 | LJ_FUNC GCstr * LJ_FASTCALL lj_str_fromint(lua_State *L, int32_t k); 27 | LJ_FUNCA GCstr * LJ_FASTCALL lj_str_fromnumber(lua_State *L, cTValue *o); 28 | 29 | #define LJ_STR_INTBUF (1+10) 30 | #define LJ_STR_NUMBUF LUAI_MAXNUMBER2STR 31 | 32 | /* String formatting. */ 33 | LJ_FUNC const char *lj_str_pushvf(lua_State *L, const char *fmt, va_list argp); 34 | LJ_FUNC const char *lj_str_pushf(lua_State *L, const char *fmt, ...) 35 | #if defined(__GNUC__) 36 | __attribute__ ((format (printf, 2, 3))) 37 | #endif 38 | ; 39 | 40 | /* Resizable string buffers. Struct definition in lj_obj.h. */ 41 | LJ_FUNC char *lj_str_needbuf(lua_State *L, SBuf *sb, MSize sz); 42 | 43 | #define lj_str_initbuf(sb) ((sb)->buf = NULL, (sb)->sz = 0) 44 | #define lj_str_resetbuf(sb) ((sb)->n = 0) 45 | #define lj_str_resizebuf(L, sb, size) \ 46 | ((sb)->buf = (char *)lj_mem_realloc(L, (sb)->buf, (sb)->sz, (size)), \ 47 | (sb)->sz = (size)) 48 | #define lj_str_freebuf(g, sb) lj_mem_free(g, (void *)(sb)->buf, (sb)->sz) 49 | 50 | #endif 51 | -------------------------------------------------------------------------------- /external/LuaJIT/src/lj_strscan.h: -------------------------------------------------------------------------------- 1 | /* 2 | ** String scanning. 3 | ** Copyright (C) 2005-2012 Mike Pall. See Copyright Notice in luajit.h 4 | */ 5 | 6 | #ifndef _LJ_STRSCAN_H 7 | #define _LJ_STRSCAN_H 8 | 9 | #include "lj_obj.h" 10 | 11 | /* Options for accepted/returned formats. */ 12 | #define STRSCAN_OPT_TOINT 0x01 /* Convert to int32_t, if possible. */ 13 | #define STRSCAN_OPT_TONUM 0x02 /* Always convert to double. */ 14 | #define STRSCAN_OPT_IMAG 0x04 15 | #define STRSCAN_OPT_LL 0x08 16 | #define STRSCAN_OPT_C 0x10 17 | 18 | /* Returned format. */ 19 | typedef enum { 20 | STRSCAN_ERROR, 21 | STRSCAN_NUM, STRSCAN_IMAG, 22 | STRSCAN_INT, STRSCAN_U32, STRSCAN_I64, STRSCAN_U64, 23 | } StrScanFmt; 24 | 25 | LJ_FUNC StrScanFmt lj_strscan_scan(const uint8_t *p, TValue *o, uint32_t opt); 26 | LJ_FUNC int LJ_FASTCALL lj_strscan_num(GCstr *str, TValue *o); 27 | #if LJ_DUALNUM 28 | LJ_FUNC int LJ_FASTCALL lj_strscan_number(GCstr *str, TValue *o); 29 | #else 30 | #define lj_strscan_number(s, o) lj_strscan_num((s), (o)) 31 | #endif 32 | 33 | /* Check for number or convert string to number/int in-place (!). */ 34 | static LJ_AINLINE int lj_strscan_numberobj(TValue *o) 35 | { 36 | return tvisnumber(o) || (tvisstr(o) && lj_strscan_number(strV(o), o)); 37 | } 38 | 39 | #endif 40 | -------------------------------------------------------------------------------- /external/LuaJIT/src/lj_tab.h: -------------------------------------------------------------------------------- 1 | /* 2 | ** Table handling. 3 | ** Copyright (C) 2005-2012 Mike Pall. See Copyright Notice in luajit.h 4 | */ 5 | 6 | #ifndef _LJ_TAB_H 7 | #define _LJ_TAB_H 8 | 9 | #include "lj_obj.h" 10 | 11 | /* Hash constants. Tuned using a brute force search. */ 12 | #define HASH_BIAS (-0x04c11db7) 13 | #define HASH_ROT1 14 14 | #define HASH_ROT2 5 15 | #define HASH_ROT3 13 16 | 17 | /* Scramble the bits of numbers and pointers. */ 18 | static LJ_AINLINE uint32_t hashrot(uint32_t lo, uint32_t hi) 19 | { 20 | #if LJ_TARGET_X86ORX64 21 | /* Prefer variant that compiles well for a 2-operand CPU. */ 22 | lo ^= hi; hi = lj_rol(hi, HASH_ROT1); 23 | lo -= hi; hi = lj_rol(hi, HASH_ROT2); 24 | hi ^= lo; hi -= lj_rol(lo, HASH_ROT3); 25 | #else 26 | lo ^= hi; 27 | lo = lo - lj_rol(hi, HASH_ROT1); 28 | hi = lo ^ lj_rol(hi, HASH_ROT1 + HASH_ROT2); 29 | hi = hi - lj_rol(lo, HASH_ROT3); 30 | #endif 31 | return hi; 32 | } 33 | 34 | #define hsize2hbits(s) ((s) ? ((s)==1 ? 1 : 1+lj_fls((uint32_t)((s)-1))) : 0) 35 | 36 | LJ_FUNCA GCtab *lj_tab_new(lua_State *L, uint32_t asize, uint32_t hbits); 37 | #if LJ_HASJIT 38 | LJ_FUNC GCtab * LJ_FASTCALL lj_tab_new1(lua_State *L, uint32_t ahsize); 39 | #endif 40 | LJ_FUNCA GCtab * LJ_FASTCALL lj_tab_dup(lua_State *L, const GCtab *kt); 41 | LJ_FUNC void LJ_FASTCALL lj_tab_free(global_State *g, GCtab *t); 42 | LJ_FUNCA void lj_tab_reasize(lua_State *L, GCtab *t, uint32_t nasize); 43 | 44 | /* Caveat: all getters except lj_tab_get() can return NULL! */ 45 | 46 | LJ_FUNCA cTValue * LJ_FASTCALL lj_tab_getinth(GCtab *t, int32_t key); 47 | LJ_FUNC cTValue *lj_tab_getstr(GCtab *t, GCstr *key); 48 | LJ_FUNCA cTValue *lj_tab_get(lua_State *L, GCtab *t, cTValue *key); 49 | 50 | /* Caveat: all setters require a write barrier for the stored value. */ 51 | 52 | LJ_FUNCA TValue *lj_tab_newkey(lua_State *L, GCtab *t, cTValue *key); 53 | LJ_FUNC TValue *lj_tab_setinth(lua_State *L, GCtab *t, int32_t key); 54 | LJ_FUNC TValue *lj_tab_setstr(lua_State *L, GCtab *t, GCstr *key); 55 | LJ_FUNC TValue *lj_tab_set(lua_State *L, GCtab *t, cTValue *key); 56 | 57 | #define inarray(t, key) ((MSize)(key) < (MSize)(t)->asize) 58 | #define arrayslot(t, i) (&tvref((t)->array)[(i)]) 59 | #define lj_tab_getint(t, key) \ 60 | (inarray((t), (key)) ? arrayslot((t), (key)) : lj_tab_getinth((t), (key))) 61 | #define lj_tab_setint(L, t, key) \ 62 | (inarray((t), (key)) ? arrayslot((t), (key)) : lj_tab_setinth(L, (t), (key))) 63 | 64 | LJ_FUNCA int lj_tab_next(lua_State *L, GCtab *t, TValue *key); 65 | LJ_FUNCA MSize LJ_FASTCALL lj_tab_len(GCtab *t); 66 | 67 | #endif 68 | -------------------------------------------------------------------------------- /external/LuaJIT/src/lj_trace.h: -------------------------------------------------------------------------------- 1 | /* 2 | ** Trace management. 3 | ** Copyright (C) 2005-2012 Mike Pall. See Copyright Notice in luajit.h 4 | */ 5 | 6 | #ifndef _LJ_TRACE_H 7 | #define _LJ_TRACE_H 8 | 9 | #include "lj_obj.h" 10 | 11 | #if LJ_HASJIT 12 | #include "lj_jit.h" 13 | #include "lj_dispatch.h" 14 | 15 | /* Trace errors. */ 16 | typedef enum { 17 | #define TREDEF(name, msg) LJ_TRERR_##name, 18 | #include "lj_traceerr.h" 19 | LJ_TRERR__MAX 20 | } TraceError; 21 | 22 | LJ_FUNC_NORET void lj_trace_err(jit_State *J, TraceError e); 23 | LJ_FUNC_NORET void lj_trace_err_info(jit_State *J, TraceError e); 24 | 25 | /* Trace management. */ 26 | LJ_FUNC void LJ_FASTCALL lj_trace_free(global_State *g, GCtrace *T); 27 | LJ_FUNC void lj_trace_reenableproto(GCproto *pt); 28 | LJ_FUNC void lj_trace_flushproto(global_State *g, GCproto *pt); 29 | LJ_FUNC void lj_trace_flush(jit_State *J, TraceNo traceno); 30 | LJ_FUNC int lj_trace_flushall(lua_State *L); 31 | LJ_FUNC void lj_trace_initstate(global_State *g); 32 | LJ_FUNC void lj_trace_freestate(global_State *g); 33 | 34 | /* Event handling. */ 35 | LJ_FUNC void lj_trace_ins(jit_State *J, const BCIns *pc); 36 | LJ_FUNCA void LJ_FASTCALL lj_trace_hot(jit_State *J, const BCIns *pc); 37 | LJ_FUNCA int LJ_FASTCALL lj_trace_exit(jit_State *J, void *exptr); 38 | 39 | /* Signal asynchronous abort of trace or end of trace. */ 40 | #define lj_trace_abort(g) (G2J(g)->state &= ~LJ_TRACE_ACTIVE) 41 | #define lj_trace_end(J) (J->state = LJ_TRACE_END) 42 | 43 | #else 44 | 45 | #define lj_trace_flushall(L) (UNUSED(L), 0) 46 | #define lj_trace_initstate(g) UNUSED(g) 47 | #define lj_trace_freestate(g) UNUSED(g) 48 | #define lj_trace_abort(g) UNUSED(g) 49 | #define lj_trace_end(J) UNUSED(J) 50 | 51 | #endif 52 | 53 | #endif 54 | -------------------------------------------------------------------------------- /external/LuaJIT/src/lj_traceerr.h: -------------------------------------------------------------------------------- 1 | /* 2 | ** Trace compiler error messages. 3 | ** Copyright (C) 2005-2012 Mike Pall. See Copyright Notice in luajit.h 4 | */ 5 | 6 | /* This file may be included multiple times with different TREDEF macros. */ 7 | 8 | /* Recording. */ 9 | TREDEF(RECERR, "error thrown or hook called during recording") 10 | TREDEF(TRACEOV, "trace too long") 11 | TREDEF(STACKOV, "trace too deep") 12 | TREDEF(SNAPOV, "too many snapshots") 13 | TREDEF(BLACKL, "blacklisted") 14 | TREDEF(NYIBC, "NYI: bytecode %d") 15 | 16 | /* Recording loop ops. */ 17 | TREDEF(LLEAVE, "leaving loop in root trace") 18 | TREDEF(LINNER, "inner loop in root trace") 19 | TREDEF(LUNROLL, "loop unroll limit reached") 20 | 21 | /* Recording calls/returns. */ 22 | TREDEF(BADTYPE, "bad argument type") 23 | TREDEF(CJITOFF, "call to JIT-disabled function") 24 | TREDEF(CUNROLL, "call unroll limit reached") 25 | TREDEF(DOWNREC, "down-recursion, restarting") 26 | TREDEF(NYICF, "NYI: C function %p") 27 | TREDEF(NYIFF, "NYI: FastFunc %s") 28 | TREDEF(NYIFFU, "NYI: unsupported variant of FastFunc %s") 29 | TREDEF(NYIRETL, "NYI: return to lower frame") 30 | 31 | /* Recording indexed load/store. */ 32 | TREDEF(STORENN, "store with nil or NaN key") 33 | TREDEF(NOMM, "missing metamethod") 34 | TREDEF(IDXLOOP, "looping index lookup") 35 | TREDEF(NYITMIX, "NYI: mixed sparse/dense table") 36 | 37 | /* Recording C data operations. */ 38 | TREDEF(NOCACHE, "symbol not in cache") 39 | TREDEF(NYICONV, "NYI: unsupported C type conversion") 40 | TREDEF(NYICALL, "NYI: unsupported C function type") 41 | 42 | /* Optimizations. */ 43 | TREDEF(GFAIL, "guard would always fail") 44 | TREDEF(PHIOV, "too many PHIs") 45 | TREDEF(TYPEINS, "persistent type instability") 46 | 47 | /* Assembler. */ 48 | TREDEF(MCODEAL, "failed to allocate mcode memory") 49 | TREDEF(MCODEOV, "machine code too long") 50 | TREDEF(MCODELM, "hit mcode limit (retrying)") 51 | TREDEF(SPILLOV, "too many spill slots") 52 | TREDEF(BADRA, "inconsistent register allocation") 53 | TREDEF(NYIIR, "NYI: cannot assemble IR instruction %d") 54 | TREDEF(NYIPHI, "NYI: PHI shuffling too complex") 55 | TREDEF(NYICOAL, "NYI: register coalescing too complex") 56 | 57 | #undef TREDEF 58 | 59 | /* Detecting unused error messages: 60 | awk -F, '/^TREDEF/ { gsub(/TREDEF./, ""); printf "grep -q LJ_TRERR_%s *.[ch] || echo %s\n", $1, $1}' lj_traceerr.h | sh 61 | */ 62 | -------------------------------------------------------------------------------- /external/LuaJIT/src/lj_udata.c: -------------------------------------------------------------------------------- 1 | /* 2 | ** Userdata handling. 3 | ** Copyright (C) 2005-2012 Mike Pall. See Copyright Notice in luajit.h 4 | */ 5 | 6 | #define lj_udata_c 7 | #define LUA_CORE 8 | 9 | #include "lj_obj.h" 10 | #include "lj_gc.h" 11 | #include "lj_udata.h" 12 | 13 | GCudata *lj_udata_new(lua_State *L, MSize sz, GCtab *env) 14 | { 15 | GCudata *ud = lj_mem_newt(L, sizeof(GCudata) + sz, GCudata); 16 | global_State *g = G(L); 17 | newwhite(g, ud); /* Not finalized. */ 18 | ud->gct = ~LJ_TUDATA; 19 | ud->udtype = UDTYPE_USERDATA; 20 | ud->len = sz; 21 | /* NOBARRIER: The GCudata is new (marked white). */ 22 | setgcrefnull(ud->metatable); 23 | setgcref(ud->env, obj2gco(env)); 24 | /* Chain to userdata list (after main thread). */ 25 | setgcrefr(ud->nextgc, mainthread(g)->nextgc); 26 | setgcref(mainthread(g)->nextgc, obj2gco(ud)); 27 | return ud; 28 | } 29 | 30 | void LJ_FASTCALL lj_udata_free(global_State *g, GCudata *ud) 31 | { 32 | lj_mem_free(g, ud, sizeudata(ud)); 33 | } 34 | 35 | -------------------------------------------------------------------------------- /external/LuaJIT/src/lj_udata.h: -------------------------------------------------------------------------------- 1 | /* 2 | ** Userdata handling. 3 | ** Copyright (C) 2005-2012 Mike Pall. See Copyright Notice in luajit.h 4 | */ 5 | 6 | #ifndef _LJ_UDATA_H 7 | #define _LJ_UDATA_H 8 | 9 | #include "lj_obj.h" 10 | 11 | LJ_FUNC GCudata *lj_udata_new(lua_State *L, MSize sz, GCtab *env); 12 | LJ_FUNC void LJ_FASTCALL lj_udata_free(global_State *g, GCudata *ud); 13 | 14 | #endif 15 | -------------------------------------------------------------------------------- /external/LuaJIT/src/lj_vmevent.c: -------------------------------------------------------------------------------- 1 | /* 2 | ** VM event handling. 3 | ** Copyright (C) 2005-2012 Mike Pall. See Copyright Notice in luajit.h 4 | */ 5 | 6 | #include 7 | 8 | #define lj_vmevent_c 9 | #define LUA_CORE 10 | 11 | #include "lj_obj.h" 12 | #include "lj_str.h" 13 | #include "lj_tab.h" 14 | #include "lj_state.h" 15 | #include "lj_dispatch.h" 16 | #include "lj_vm.h" 17 | #include "lj_vmevent.h" 18 | 19 | ptrdiff_t lj_vmevent_prepare(lua_State *L, VMEvent ev) 20 | { 21 | global_State *g = G(L); 22 | GCstr *s = lj_str_newlit(L, LJ_VMEVENTS_REGKEY); 23 | cTValue *tv = lj_tab_getstr(tabV(registry(L)), s); 24 | if (tvistab(tv)) { 25 | int hash = VMEVENT_HASH(ev); 26 | tv = lj_tab_getint(tabV(tv), hash); 27 | if (tv && tvisfunc(tv)) { 28 | lj_state_checkstack(L, LUA_MINSTACK); 29 | setfuncV(L, L->top++, funcV(tv)); 30 | return savestack(L, L->top); 31 | } 32 | } 33 | g->vmevmask &= ~VMEVENT_MASK(ev); /* No handler: cache this fact. */ 34 | return 0; 35 | } 36 | 37 | void lj_vmevent_call(lua_State *L, ptrdiff_t argbase) 38 | { 39 | global_State *g = G(L); 40 | uint8_t oldmask = g->vmevmask; 41 | uint8_t oldh = hook_save(g); 42 | int status; 43 | g->vmevmask = 0; /* Disable all events. */ 44 | hook_vmevent(g); 45 | status = lj_vm_pcall(L, restorestack(L, argbase), 0+1, 0); 46 | if (LJ_UNLIKELY(status)) { 47 | /* Really shouldn't use stderr here, but where else to complain? */ 48 | L->top--; 49 | fputs("VM handler failed: ", stderr); 50 | fputs(tvisstr(L->top) ? strVdata(L->top) : "?", stderr); 51 | fputc('\n', stderr); 52 | } 53 | hook_restore(g, oldh); 54 | if (g->vmevmask != VMEVENT_NOCACHE) 55 | g->vmevmask = oldmask; /* Restore event mask, but not if not modified. */ 56 | } 57 | 58 | -------------------------------------------------------------------------------- /external/LuaJIT/src/lj_vmevent.h: -------------------------------------------------------------------------------- 1 | /* 2 | ** VM event handling. 3 | ** Copyright (C) 2005-2012 Mike Pall. See Copyright Notice in luajit.h 4 | */ 5 | 6 | #ifndef _LJ_VMEVENT_H 7 | #define _LJ_VMEVENT_H 8 | 9 | #include "lj_obj.h" 10 | 11 | /* Registry key for VM event handler table. */ 12 | #define LJ_VMEVENTS_REGKEY "_VMEVENTS" 13 | #define LJ_VMEVENTS_HSIZE 4 14 | 15 | #define VMEVENT_MASK(ev) ((uint8_t)1 << ((int)(ev) & 7)) 16 | #define VMEVENT_HASH(ev) ((int)(ev) & ~7) 17 | #define VMEVENT_HASHIDX(h) ((int)(h) << 3) 18 | #define VMEVENT_NOCACHE 255 19 | 20 | #define VMEVENT_DEF(name, hash) \ 21 | LJ_VMEVENT_##name##_, \ 22 | LJ_VMEVENT_##name = ((LJ_VMEVENT_##name##_) & 7)|((hash) << 3) 23 | 24 | /* VM event IDs. */ 25 | typedef enum { 26 | VMEVENT_DEF(BC, 0x00003883), 27 | VMEVENT_DEF(TRACE, 0xb2d91467), 28 | VMEVENT_DEF(RECORD, 0x9284bf4f), 29 | VMEVENT_DEF(TEXIT, 0xb29df2b0), 30 | LJ_VMEVENT__MAX 31 | } VMEvent; 32 | 33 | #ifdef LUAJIT_DISABLE_VMEVENT 34 | #define lj_vmevent_send(L, ev, args) UNUSED(L) 35 | #define lj_vmevent_send_(L, ev, args, post) UNUSED(L) 36 | #else 37 | #define lj_vmevent_send(L, ev, args) \ 38 | if (G(L)->vmevmask & VMEVENT_MASK(LJ_VMEVENT_##ev)) { \ 39 | ptrdiff_t argbase = lj_vmevent_prepare(L, LJ_VMEVENT_##ev); \ 40 | if (argbase) { \ 41 | args \ 42 | lj_vmevent_call(L, argbase); \ 43 | } \ 44 | } 45 | #define lj_vmevent_send_(L, ev, args, post) \ 46 | if (G(L)->vmevmask & VMEVENT_MASK(LJ_VMEVENT_##ev)) { \ 47 | ptrdiff_t argbase = lj_vmevent_prepare(L, LJ_VMEVENT_##ev); \ 48 | if (argbase) { \ 49 | args \ 50 | lj_vmevent_call(L, argbase); \ 51 | post \ 52 | } \ 53 | } 54 | 55 | LJ_FUNC ptrdiff_t lj_vmevent_prepare(lua_State *L, VMEvent ev); 56 | LJ_FUNC void lj_vmevent_call(lua_State *L, ptrdiff_t argbase); 57 | #endif 58 | 59 | #endif 60 | -------------------------------------------------------------------------------- /external/LuaJIT/src/ljamalg.c: -------------------------------------------------------------------------------- 1 | /* 2 | ** LuaJIT core and libraries amalgamation. 3 | ** Copyright (C) 2005-2012 Mike Pall. See Copyright Notice in luajit.h 4 | */ 5 | 6 | /* 7 | +--------------------------------------------------------------------------+ 8 | | WARNING: Compiling the amalgamation needs a lot of virtual memory | 9 | | (around 200 MB with GCC 4.x)! If you don't have enough physical memory | 10 | | your machine will start swapping to disk and the compile will not finish | 11 | | within a reasonable amount of time. | 12 | | So either compile on a bigger machine or use the non-amalgamated build. | 13 | +--------------------------------------------------------------------------+ 14 | */ 15 | 16 | #define ljamalg_c 17 | #define LUA_CORE 18 | 19 | /* To get the mremap prototype. Must be defined before any system includes. */ 20 | #if defined(__linux__) && !defined(_GNU_SOURCE) 21 | #define _GNU_SOURCE 22 | #endif 23 | 24 | #ifndef WINVER 25 | #define WINVER 0x0500 26 | #endif 27 | 28 | #include "lua.h" 29 | #include "lauxlib.h" 30 | 31 | #include "lj_gc.c" 32 | #include "lj_err.c" 33 | #include "lj_char.c" 34 | #include "lj_bc.c" 35 | #include "lj_obj.c" 36 | #include "lj_str.c" 37 | #include "lj_tab.c" 38 | #include "lj_func.c" 39 | #include "lj_udata.c" 40 | #include "lj_meta.c" 41 | #include "lj_debug.c" 42 | #include "lj_state.c" 43 | #include "lj_dispatch.c" 44 | #include "lj_vmevent.c" 45 | #include "lj_vmmath.c" 46 | #include "lj_strscan.c" 47 | #include "lj_api.c" 48 | #include "lj_lex.c" 49 | #include "lj_parse.c" 50 | #include "lj_bcread.c" 51 | #include "lj_bcwrite.c" 52 | #include "lj_load.c" 53 | #include "lj_ctype.c" 54 | #include "lj_cdata.c" 55 | #include "lj_cconv.c" 56 | #include "lj_ccall.c" 57 | #include "lj_ccallback.c" 58 | #include "lj_carith.c" 59 | #include "lj_clib.c" 60 | #include "lj_cparse.c" 61 | #include "lj_lib.c" 62 | #include "lj_ir.c" 63 | #include "lj_opt_mem.c" 64 | #include "lj_opt_fold.c" 65 | #include "lj_opt_narrow.c" 66 | #include "lj_opt_dce.c" 67 | #include "lj_opt_loop.c" 68 | #include "lj_opt_split.c" 69 | #include "lj_opt_sink.c" 70 | #include "lj_mcode.c" 71 | #include "lj_snap.c" 72 | #include "lj_record.c" 73 | #include "lj_crecord.c" 74 | #include "lj_ffrecord.c" 75 | #include "lj_asm.c" 76 | #include "lj_trace.c" 77 | #include "lj_gdbjit.c" 78 | #include "lj_alloc.c" 79 | 80 | #include "lib_aux.c" 81 | #include "lib_base.c" 82 | #include "lib_math.c" 83 | #include "lib_string.c" 84 | #include "lib_table.c" 85 | #include "lib_io.c" 86 | #include "lib_os.c" 87 | #include "lib_package.c" 88 | #include "lib_debug.c" 89 | #include "lib_bit.c" 90 | #include "lib_jit.c" 91 | #include "lib_ffi.c" 92 | #include "lib_init.c" 93 | 94 | -------------------------------------------------------------------------------- /external/LuaJIT/src/lua.hpp: -------------------------------------------------------------------------------- 1 | // C++ wrapper for LuaJIT header files. 2 | 3 | extern "C" { 4 | #include "lua.h" 5 | #include "lauxlib.h" 6 | #include "lualib.h" 7 | #include "luajit.h" 8 | } 9 | 10 | -------------------------------------------------------------------------------- /external/LuaJIT/src/luajit.exp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hodgman/eight/b3ade9ad355e47bcc853c087d670b55b33933ccb/external/LuaJIT/src/luajit.exp -------------------------------------------------------------------------------- /external/LuaJIT/src/luajit.h: -------------------------------------------------------------------------------- 1 | /* 2 | ** LuaJIT -- a Just-In-Time Compiler for Lua. http://luajit.org/ 3 | ** 4 | ** Copyright (C) 2005-2012 Mike Pall. All rights reserved. 5 | ** 6 | ** Permission is hereby granted, free of charge, to any person obtaining 7 | ** a copy of this software and associated documentation files (the 8 | ** "Software"), to deal in the Software without restriction, including 9 | ** without limitation the rights to use, copy, modify, merge, publish, 10 | ** distribute, sublicense, and/or sell copies of the Software, and to 11 | ** permit persons to whom the Software is furnished to do so, subject to 12 | ** the following conditions: 13 | ** 14 | ** The above copyright notice and this permission notice shall be 15 | ** included in all copies or substantial portions of the Software. 16 | ** 17 | ** THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 18 | ** EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 19 | ** MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. 20 | ** IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY 21 | ** CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, 22 | ** TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE 23 | ** SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 24 | ** 25 | ** [ MIT license: http://www.opensource.org/licenses/mit-license.php ] 26 | */ 27 | 28 | #ifndef _LUAJIT_H 29 | #define _LUAJIT_H 30 | 31 | #include "lua.h" 32 | 33 | #define LUAJIT_VERSION "LuaJIT 2.0.0" 34 | #define LUAJIT_VERSION_NUM 20000 /* Version 2.0.0 = 02.00.00. */ 35 | #define LUAJIT_VERSION_SYM luaJIT_version_2_0_0 36 | #define LUAJIT_COPYRIGHT "Copyright (C) 2005-2012 Mike Pall" 37 | #define LUAJIT_URL "http://luajit.org/" 38 | 39 | /* Modes for luaJIT_setmode. */ 40 | #define LUAJIT_MODE_MASK 0x00ff 41 | 42 | enum { 43 | LUAJIT_MODE_ENGINE, /* Set mode for whole JIT engine. */ 44 | LUAJIT_MODE_DEBUG, /* Set debug mode (idx = level). */ 45 | 46 | LUAJIT_MODE_FUNC, /* Change mode for a function. */ 47 | LUAJIT_MODE_ALLFUNC, /* Recurse into subroutine protos. */ 48 | LUAJIT_MODE_ALLSUBFUNC, /* Change only the subroutines. */ 49 | 50 | LUAJIT_MODE_TRACE, /* Flush a compiled trace. */ 51 | 52 | LUAJIT_MODE_WRAPCFUNC = 0x10, /* Set wrapper mode for C function calls. */ 53 | 54 | LUAJIT_MODE_MAX 55 | }; 56 | 57 | /* Flags or'ed in to the mode. */ 58 | #define LUAJIT_MODE_OFF 0x0000 /* Turn feature off. */ 59 | #define LUAJIT_MODE_ON 0x0100 /* Turn feature on. */ 60 | #define LUAJIT_MODE_FLUSH 0x0200 /* Flush JIT-compiled code. */ 61 | 62 | /* LuaJIT public C API. */ 63 | 64 | /* Control the JIT engine. */ 65 | LUA_API int luaJIT_setmode(lua_State *L, int idx, int mode); 66 | 67 | /* Enforce (dynamic) linker error for version mismatches. Call from main. */ 68 | LUA_API void LUAJIT_VERSION_SYM(void); 69 | 70 | #endif 71 | -------------------------------------------------------------------------------- /external/LuaJIT/src/luajit.lib: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hodgman/eight/b3ade9ad355e47bcc853c087d670b55b33933ccb/external/LuaJIT/src/luajit.lib -------------------------------------------------------------------------------- /external/LuaJIT/src/lualib.h: -------------------------------------------------------------------------------- 1 | /* 2 | ** Standard library header. 3 | ** Copyright (C) 2005-2012 Mike Pall. See Copyright Notice in luajit.h 4 | */ 5 | 6 | #ifndef _LUALIB_H 7 | #define _LUALIB_H 8 | 9 | #include "lua.h" 10 | 11 | #define LUA_FILEHANDLE "FILE*" 12 | 13 | #define LUA_COLIBNAME "coroutine" 14 | #define LUA_MATHLIBNAME "math" 15 | #define LUA_STRLIBNAME "string" 16 | #define LUA_TABLIBNAME "table" 17 | #define LUA_IOLIBNAME "io" 18 | #define LUA_OSLIBNAME "os" 19 | #define LUA_LOADLIBNAME "package" 20 | #define LUA_DBLIBNAME "debug" 21 | #define LUA_BITLIBNAME "bit" 22 | #define LUA_JITLIBNAME "jit" 23 | #define LUA_FFILIBNAME "ffi" 24 | 25 | LUALIB_API int luaopen_base(lua_State *L); 26 | LUALIB_API int luaopen_math(lua_State *L); 27 | LUALIB_API int luaopen_string(lua_State *L); 28 | LUALIB_API int luaopen_table(lua_State *L); 29 | LUALIB_API int luaopen_io(lua_State *L); 30 | LUALIB_API int luaopen_os(lua_State *L); 31 | LUALIB_API int luaopen_package(lua_State *L); 32 | LUALIB_API int luaopen_debug(lua_State *L); 33 | LUALIB_API int luaopen_bit(lua_State *L); 34 | LUALIB_API int luaopen_jit(lua_State *L); 35 | LUALIB_API int luaopen_ffi(lua_State *L); 36 | 37 | LUALIB_API void luaL_openlibs(lua_State *L); 38 | 39 | #ifndef lua_assert 40 | #define lua_assert(x) ((void)0) 41 | #endif 42 | 43 | #endif 44 | -------------------------------------------------------------------------------- /external/ispc/contrib/ispc.vim: -------------------------------------------------------------------------------- 1 | " Vim syntax file 2 | " Language: ISPC 3 | " Maintainer: Andreas Wendleder 4 | " Last Change: 2011 Aug 3 5 | 6 | " Quit when a syntax file was already loaded 7 | if exists("b:current_syntax") 8 | finish 9 | endif 10 | 11 | " Read the C syntax to start with 12 | runtime! syntax/c.vim 13 | unlet b:current_syntax 14 | 15 | " New keywords 16 | syn keyword ispcStatement cbreak ccontinue creturn launch print reference soa sync task 17 | syn keyword ispcConditional cif 18 | syn keyword ispcRepeat cdo cfor cwhile 19 | syn keyword ispcBuiltin programCount programIndex 20 | syn keyword ispcType export uniform varying int8 int16 int32 int64 21 | 22 | " Default highlighting 23 | command -nargs=+ HiLink hi def link 24 | HiLink ispcStatement Statement 25 | HiLink ispcConditional Conditional 26 | HiLink ispcRepeat Repeat 27 | HiLink ispcBuiltin Statement 28 | HiLink ispcType Type 29 | delcommand HiLink 30 | 31 | let b:current_syntax = "ispc" 32 | 33 | -------------------------------------------------------------------------------- /external/ispc/contrib/ispc.vim.README: -------------------------------------------------------------------------------- 1 | To install vim syntax highlighting for ispc files: 2 | 3 | 1) Copy ispc.vim into ~/.vim/syntax/ispc.vim (create if necessary) 4 | 2) Create a filetype for ispc files to correspond to that syntax file 5 | To do this, create and append the following line to ~/.vim/ftdetect/ispc.vim 6 | 7 | au BufRead,BufNewFile *.ispc set filetype=ispc 8 | 9 | -------------------------------------------------------------------------------- /external/ispc/css/ie.css: -------------------------------------------------------------------------------- 1 | @charset "utf-8"; 2 | /* CSS Document for IE */ 3 | 4 | body {font-size: 12px;} 5 | #logo {padding-bottom: 5px;} 6 | form.search {top: 10px;} 7 | blockquote {padding:0;} -------------------------------------------------------------------------------- /external/ispc/examples/timing.h: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (c) 2010-2011, Intel Corporation 3 | All rights reserved. 4 | 5 | Redistribution and use in source and binary forms, with or without 6 | modification, are permitted provided that the following conditions are 7 | met: 8 | 9 | * Redistributions of source code must retain the above copyright 10 | notice, this list of conditions and the following disclaimer. 11 | 12 | * Redistributions in binary form must reproduce the above copyright 13 | notice, this list of conditions and the following disclaimer in the 14 | documentation and/or other materials provided with the distribution. 15 | 16 | * Neither the name of Intel Corporation nor the names of its 17 | contributors may be used to endorse or promote products derived from 18 | this software without specific prior written permission. 19 | 20 | 21 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS 22 | IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED 23 | TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A 24 | PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER 25 | OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, 26 | EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 27 | PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR 28 | PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF 29 | LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING 30 | NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 31 | SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 32 | */ 33 | 34 | #include 35 | 36 | 37 | #ifdef WIN32 38 | #include 39 | #define rdtsc __rdtsc 40 | #else 41 | #ifdef __cplusplus 42 | extern "C" { 43 | #endif /* __cplusplus */ 44 | __inline__ uint64_t rdtsc() { 45 | uint32_t low, high; 46 | #ifdef __x86_64 47 | __asm__ __volatile__ ( 48 | "xorl %%eax,%%eax \n cpuid" 49 | ::: "%rax", "%rbx", "%rcx", "%rdx" ); 50 | #else 51 | __asm__ __volatile__ ( 52 | "xorl %%eax,%%eax \n cpuid" 53 | ::: "%eax", "%ebx", "%ecx", "%edx" ); 54 | #endif 55 | __asm__ __volatile__ ( 56 | "rdtsc" : "=a" (low), "=d" (high)); 57 | return (uint64_t)high << 32 | low; 58 | } 59 | #ifdef __cplusplus 60 | } 61 | #endif /* __cplusplus */ 62 | #endif 63 | 64 | static uint64_t start, end; 65 | 66 | static inline void reset_and_start_timer() 67 | { 68 | start = rdtsc(); 69 | } 70 | 71 | /* Returns the number of millions of elapsed processor cycles since the 72 | last reset_and_start_timer() call. */ 73 | static inline double get_elapsed_mcycles() 74 | { 75 | end = rdtsc(); 76 | return (end-start) / (1024. * 1024.); 77 | } 78 | -------------------------------------------------------------------------------- /external/ispc/ispc.exe: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hodgman/eight/b3ade9ad355e47bcc853c087d670b55b33933ccb/external/ispc/ispc.exe -------------------------------------------------------------------------------- /external/ispc/ispc32.bat: -------------------------------------------------------------------------------- 1 | set ispcPath=%~dp0 2 | 3 | if "%1"=="Debug" set ispc_cfg_flags=-DeiBUILD_DEBUG --math-lib=fast --wno-perf -O0 4 | if "%1"=="Dev" set ispc_cfg_flags=-DeiBUILD_DEV --math-lib=fast --opt=fast-math 5 | if "%1"=="Retail" set ispc_cfg_flags=-DeiBUILD_RETAIL --math-lib=fast --opt=fast-math --opt=disable-assertions 6 | 7 | REM throw the first parameter away 8 | shift 9 | set args=%1 10 | :loop 11 | shift 12 | if "%1"=="" goto afterloop 13 | set args=%args% %1 14 | goto loop 15 | :afterloop 16 | 17 | %ispcPath%/ispc.exe %args% %ispc_cfg_flags% --target=sse2 --arch=x86 18 | -------------------------------------------------------------------------------- /external/ispc/ispc64.bat: -------------------------------------------------------------------------------- 1 | set ispcPath=%~dp0 2 | 3 | if "%1"=="Debug" set ispc_cfg_flags=-DeiBUILD_DEBUG --math-lib=fast --wno-perf -O0 4 | if "%1"=="Dev" set ispc_cfg_flags=-DeiBUILD_DEV --math-lib=fast --opt=fast-math 5 | if "%1"=="Retail" set ispc_cfg_flags=-DeiBUILD_RETAIL --math-lib=fast --opt=fast-math --opt=disable-assertions 6 | 7 | REM throw the first parameter away 8 | shift 9 | set args=%1 10 | :loop 11 | shift 12 | if "%1"=="" goto afterloop 13 | set args=%args% %1 14 | goto loop 15 | :afterloop 16 | 17 | %ispcPath%/ispc.exe %args% %ispc_cfg_flags% --target=sse2 --arch=x86-64 18 | -------------------------------------------------------------------------------- /external/rdestl/LICENSE: -------------------------------------------------------------------------------- 1 | 2 | 3 | The MIT License 4 | 5 | Copyright (c) 2007 Maciej Sinilo 6 | 7 | Permission is hereby granted, free of charge, to any person obtaining a copy 8 | of this software and associated documentation files (the "Software"), to deal 9 | in the Software without restriction, including without limitation the rights 10 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 11 | copies of the Software, and to permit persons to whom the Software is 12 | furnished to do so, subject to the following conditions: 13 | 14 | The above copyright notice and this permission notice shall be included in 15 | all copies or substantial portions of the Software. 16 | 17 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 18 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 19 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 20 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 21 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 22 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 23 | THE SOFTWARE. 24 | -------------------------------------------------------------------------------- /external/rdestl/alignment.h: -------------------------------------------------------------------------------- 1 | #ifndef RDESTL_ALIGNMENT_H 2 | #define RDESTL_ALIGNMENT_H 3 | 4 | #include "rdestl_common.h" 5 | #include 6 | 7 | namespace rde 8 | { 9 | namespace internal 10 | { 11 | #pragma warning(push) 12 | // structure was padded due to __declspec(align()) 13 | #pragma warning(disable: 4324) 14 | template 15 | struct alignof_helper 16 | { 17 | char x; 18 | T y; 19 | }; 20 | #ifdef _MSC_VER 21 | __declspec(align(16)) struct aligned16 { uint64 member[2]; }; 22 | #else 23 | struct __attribute__ ((aligned (16))) aligned16 { uint64 member[2]; } ; 24 | #endif 25 | 26 | #pragma warning(pop) 27 | template struct type_with_alignment 28 | { 29 | typedef char err_invalid_alignment[N > 0 ? -1 : 1]; 30 | }; 31 | template<> struct type_with_alignment<0> {}; 32 | template<> struct type_with_alignment<1> { uint8 member; }; 33 | template<> struct type_with_alignment<2> { uint16 member; }; 34 | template<> struct type_with_alignment<4> { uint32 member; }; 35 | template<> struct type_with_alignment<8> { uint64 member; }; 36 | template<> struct type_with_alignment<16> { aligned16 member; }; 37 | } 38 | template 39 | struct align_of 40 | { 41 | enum 42 | { 43 | res = offsetof(internal::alignof_helper, y) 44 | }; 45 | }; 46 | template 47 | struct aligned_as 48 | { 49 | typedef typename internal::type_with_alignment::res> res; 50 | }; 51 | 52 | } 53 | 54 | #endif 55 | -------------------------------------------------------------------------------- /external/rdestl/allocator.cpp: -------------------------------------------------------------------------------- 1 | #include "allocator.h" 2 | 3 | namespace rde 4 | { 5 | const char* allocator::get_name() const 6 | { 7 | return m_name; 8 | } 9 | } // rde 10 | -------------------------------------------------------------------------------- /external/rdestl/allocator.h: -------------------------------------------------------------------------------- 1 | #ifndef RDESTL_ALLOCATOR_H 2 | #define RDESTL_ALLOCATOR_H 3 | 4 | namespace rde 5 | { 6 | 7 | // CONCEPT! 8 | class allocator 9 | { 10 | public: 11 | explicit allocator(const char* name = "DEFAULT"): m_name(name) {} 12 | // Copy ctor generated by compiler. 13 | // allocator(const allocator&) 14 | ~allocator() {} 15 | 16 | // Generated by compiler. 17 | //allocator& operator=(const allocator&) 18 | 19 | void* allocate(unsigned int bytes, int flags = 0); 20 | // Not supported for standard allocator for the time being. 21 | void* allocate_aligned(unsigned int bytes, unsigned int alignment, int flags = 0); 22 | void deallocate(void* ptr, unsigned int bytes); 23 | 24 | const char* get_name() const; 25 | 26 | private: 27 | const char* m_name; 28 | }; 29 | 30 | // True if lhs can free memory allocated by rhs and vice-versa. 31 | inline bool operator==(const allocator& /*lhs*/, const allocator& /*rhs*/) 32 | { 33 | return true; 34 | } 35 | inline bool operator!=(const allocator& lhs, const allocator& rhs) 36 | { 37 | return !(lhs == rhs); 38 | } 39 | 40 | inline void* allocator::allocate(unsigned int bytes, int) 41 | { 42 | return operator new(bytes); 43 | } 44 | 45 | inline void allocator::deallocate(void* ptr, unsigned int) 46 | { 47 | operator delete(ptr); 48 | } 49 | 50 | } // namespace rde 51 | 52 | //----------------------------------------------------------------------------- 53 | #endif // #ifndef RDESTL_ALLOCATOR_H 54 | -------------------------------------------------------------------------------- /external/rdestl/buffer_allocator.h: -------------------------------------------------------------------------------- 1 | #ifndef RDESTL_BUFFER_ALLOCATOR_H 2 | #define RDESTL_BUFFER_ALLOCATOR_H 3 | 4 | #include "rdestl_common.h" 5 | 6 | namespace rde 7 | { 8 | 9 | // CONCEPT! 10 | class buffer_allocator 11 | { 12 | public: 13 | explicit buffer_allocator(const char* name, char* mem, 14 | size_t bufferSize) 15 | : m_name(name), 16 | m_buffer(mem), 17 | m_bufferTop(0), 18 | m_bufferSize(bufferSize) 19 | { 20 | /**/ 21 | } 22 | 23 | void* allocate(size_t bytes, int /*flags*/ = 0) 24 | { 25 | RDE_ASSERT(m_bufferTop + bytes <= m_bufferSize); 26 | char* ret = m_buffer + m_bufferTop; 27 | m_bufferTop += bytes; 28 | return ret; 29 | } 30 | void deallocate(void* ptr, size_t /*bytes*/) 31 | { 32 | RDE_ASSERT(ptr == 0 || (ptr >= m_buffer && ptr < m_buffer + m_bufferSize)); 33 | sizeof(ptr); 34 | } 35 | 36 | const char* get_name() const { return m_name; } 37 | 38 | private: 39 | const char* m_name; 40 | char* m_buffer; 41 | size_t m_bufferTop; 42 | size_t m_bufferSize; 43 | }; 44 | 45 | } // namespace rde 46 | //----------------------------------------------------------------------------- 47 | #endif // #ifndef RDESTL_BUFFER_ALLOCATOR_H 48 | -------------------------------------------------------------------------------- /external/rdestl/fixed_array.h: -------------------------------------------------------------------------------- 1 | #ifndef RDESTL_FIXED_ARRAY_H 2 | #define RDESTL_FIXED_ARRAY_H 3 | 4 | #include "algorithm.h" 5 | 6 | namespace rde 7 | { 8 | //============================================================================= 9 | template 10 | class fixed_array 11 | { 12 | typedef char ERR_N_MustBeBiggerThanZero[N > 0 ? 1 : -1]; 13 | public: 14 | typedef T value_type; 15 | typedef T* iterator; 16 | typedef const T* const_iterator; 17 | typedef size_t size_type; 18 | 19 | fixed_array() {/**/} 20 | fixed_array(const T array[N]) 21 | { 22 | rde::copy_n(&array[0], N, m_data); 23 | } 24 | // copy ctor/dtor generated 25 | // assignment op generated 26 | 27 | iterator begin() { return &m_data[0]; } 28 | const_iterator begin() const { return &m_data[0]; } 29 | iterator end() { return begin() + N; } 30 | const_iterator end() const { return begin() + N; } 31 | size_type size() const { return N; } 32 | T* data() { return &m_data[0]; } 33 | const T* data() const { return &m_data[0]; } 34 | 35 | const T& front() const { return *begin(); } 36 | T& front() { return *begin(); } 37 | const T& back() const { return *(end() - 1); } 38 | T& back() { return *(end() - 1); } 39 | 40 | RDE_FORCEINLINE T& operator[](size_type i) 41 | { 42 | RDE_ASSERT(i < size()); 43 | return m_data[i]; 44 | } 45 | RDE_FORCEINLINE const T& operator[](size_type i) const 46 | { 47 | RDE_ASSERT(i < size()); 48 | return m_data[i]; 49 | } 50 | 51 | private: 52 | T m_data[N]; 53 | }; 54 | 55 | } // rde 56 | 57 | //----------------------------------------------------------------------------- 58 | #endif // #ifndef RDESTL_FIXED_ARRAY_H 59 | 60 | -------------------------------------------------------------------------------- /external/rdestl/fixed_sorted_vector.h: -------------------------------------------------------------------------------- 1 | #ifndef RDESTL_FIXED_SORTED_VECTOR_H 2 | #define RDESTL_FIXED_SORTED_VECTOR_H 3 | 4 | #include "fixed_vector.h" 5 | #include "sorted_vector.h" 6 | 7 | namespace rde 8 | { 9 | template, 11 | class TAllocator = rde::allocator> 12 | class fixed_sorted_vector : public sorted_vector, TAllocator, TCapacity, 15 | TGrowOnOverflow> > 16 | { 17 | public: 18 | explicit fixed_sorted_vector(const allocator_type& allocator = allocator_type()) 19 | : sorted_vector(allocator) 20 | { 21 | /**/ 22 | } 23 | }; 24 | 25 | } // rde 26 | 27 | #endif // #ifndef RDESTL_FIXED_SORTED_VECTOR_H 28 | 29 | -------------------------------------------------------------------------------- /external/rdestl/functional.h: -------------------------------------------------------------------------------- 1 | #ifndef RDESTL_FUNCTIONAL_H 2 | #define RDESTL_FUNCTIONAL_H 3 | 4 | namespace rde 5 | { 6 | //============================================================================= 7 | template 8 | struct less 9 | { 10 | bool operator()(const T& lhs, const T& rhs) const 11 | { 12 | return lhs < rhs; 13 | } 14 | }; 15 | 16 | //============================================================================= 17 | template 18 | struct greater 19 | { 20 | bool operator()(const T& lhs, const T& rhs) const 21 | { 22 | return lhs > rhs; 23 | } 24 | }; 25 | 26 | //============================================================================= 27 | template 28 | struct equal_to 29 | { 30 | bool operator()(const T& lhs, const T& rhs) const 31 | { 32 | return lhs == rhs; 33 | } 34 | }; 35 | 36 | } 37 | 38 | //----------------------------------------------------------------------------- 39 | #endif // #ifndef RDESTL_FUNCTIONAL_H 40 | -------------------------------------------------------------------------------- /external/rdestl/hash.h: -------------------------------------------------------------------------------- 1 | #ifndef RDESTL_HASH_H 2 | #define RDESTL_HASH_H 3 | 4 | namespace rde 5 | { 6 | 7 | typedef unsigned long hash_value_t; 8 | 9 | // Default implementations, just casts to hash_value. 10 | template 11 | hash_value_t extract_int_key_value(const T& t) 12 | { 13 | return (hash_value_t)t; 14 | } 15 | 16 | // Default implementation of hasher. 17 | // Works for keys that can be converted to 32-bit integer 18 | // with extract_int_key_value. 19 | // Algorithm by Robert Jenkins. 20 | // (see http://www.cris.com/~Ttwang/tech/inthash.htm for example). 21 | template 22 | struct hash 23 | { 24 | hash_value_t operator()(const T& t) const 25 | { 26 | hash_value_t a = extract_int_key_value(t); 27 | a = (a+0x7ed55d16) + (a<<12); 28 | a = (a^0xc761c23c) ^ (a>>19); 29 | a = (a+0x165667b1) + (a<<5); 30 | a = (a+0xd3a2646c) ^ (a<<9); 31 | a = (a+0xfd7046c5) + (a<<3); 32 | a = (a^0xb55a4f09) ^ (a>>16); 33 | return a; 34 | } 35 | }; 36 | 37 | } 38 | 39 | #endif 40 | -------------------------------------------------------------------------------- /external/rdestl/int_to_type.h: -------------------------------------------------------------------------------- 1 | #ifndef RDESTL_INT_TO_TYPE_H 2 | #define RDESTL_INT_TO_TYPE_H 3 | 4 | namespace rde 5 | { 6 | 7 | /** 8 | * Sample usage: 9 | * void fun(int_to_type) { ... } 10 | * void fun(int_to_type) { ... } 11 | * template void bar() 12 | * { 13 | * fun(int_to_type::is_exact>()) 14 | * } 15 | */ 16 | template 17 | struct int_to_type 18 | { 19 | enum 20 | { 21 | value = TVal 22 | }; 23 | }; 24 | 25 | } // namespaces 26 | 27 | #endif // #ifndef RDESTL_INT_TO_TYPE_H 28 | -------------------------------------------------------------------------------- /external/rdestl/intrusive_list.cpp: -------------------------------------------------------------------------------- 1 | #include "intrusive_list.h" 2 | 3 | namespace rde 4 | { 5 | intrusive_list_base::intrusive_list_base() 6 | : m_root() 7 | { 8 | /**/ 9 | } 10 | 11 | intrusive_list_base::size_type intrusive_list_base::size() const 12 | { 13 | size_type numNodes(0); 14 | const intrusive_list_node* iter = &m_root; 15 | do 16 | { 17 | iter = iter->next; 18 | ++numNodes; 19 | } while (iter != &m_root); 20 | return numNodes - 1; 21 | } 22 | 23 | void intrusive_list_base::link(intrusive_list_node* node, intrusive_list_node* nextNode) 24 | { 25 | RDE_ASSERT(!node->in_list()); 26 | node->prev = nextNode->prev; 27 | node->prev->next = node; 28 | nextNode->prev = node; 29 | node->next = nextNode; 30 | } 31 | void intrusive_list_base::unlink(intrusive_list_node* node) 32 | { 33 | RDE_ASSERT(node->in_list()); 34 | node->prev->next = node->next; 35 | node->next->prev = node->prev; 36 | node->next = node->prev = node; 37 | } 38 | } 39 | -------------------------------------------------------------------------------- /external/rdestl/intrusive_slist.cpp: -------------------------------------------------------------------------------- 1 | #include "intrusive_slist.h" 2 | 3 | namespace rde 4 | { 5 | intrusive_slist_base::intrusive_slist_base() 6 | { 7 | /**/ 8 | } 9 | 10 | intrusive_slist_base::size_type intrusive_slist_base::size() const 11 | { 12 | size_type numNodes(0); 13 | const intrusive_slist_node* iter = &m_root; 14 | do 15 | { 16 | iter = iter->next; 17 | ++numNodes; 18 | } while (iter != &m_root); 19 | return numNodes - 1; 20 | } 21 | 22 | void intrusive_slist_base::link_after(intrusive_slist_node* node, intrusive_slist_node* prevNode) 23 | { 24 | RDE_ASSERT(!node->in_list()); 25 | node->next = prevNode->next; 26 | prevNode->next = node; 27 | } 28 | void intrusive_slist_base::unlink_after(intrusive_slist_node* node) 29 | { 30 | RDE_ASSERT(node->in_list()); 31 | intrusive_slist_node* thisNode = node->next; 32 | node->next = thisNode->next; 33 | thisNode->next = thisNode; 34 | } 35 | } 36 | -------------------------------------------------------------------------------- /external/rdestl/iterator.h: -------------------------------------------------------------------------------- 1 | #ifndef RDESTL_ITERATOR_H 2 | #define RDESTL_ITERATOR_H 3 | 4 | #include "rdestl_common.h" 5 | 6 | namespace rde 7 | { 8 | 9 | //----------------------------------------------------------------------------- 10 | struct input_iterator_tag {}; 11 | struct output_iterator_tag {}; 12 | struct forward_iterator_tag: public input_iterator_tag {}; 13 | struct bidirectional_iterator_tag: public forward_iterator_tag {}; 14 | struct random_access_iterator_tag: public bidirectional_iterator_tag {}; 15 | 16 | //----------------------------------------------------------------------------- 17 | template 18 | struct iterator_traits 19 | { 20 | typedef typename IterT::iterator_category iterator_category; 21 | }; 22 | 23 | template 24 | struct iterator_traits 25 | { 26 | typedef random_access_iterator_tag iterator_category; 27 | }; 28 | 29 | //----------------------------------------------------------------------------- 30 | namespace internal 31 | { 32 | template RDE_FORCEINLINE 33 | void distance(TIter first, TIter last, TDist& dist, rde::random_access_iterator_tag) 34 | { 35 | dist = TDist(last - first); 36 | } 37 | template RDE_FORCEINLINE 38 | void distance(TIter first, TIter last, TDist& dist, rde::input_iterator_tag) 39 | { 40 | dist = 0; 41 | while (first != last) 42 | { 43 | ++dist; 44 | ++first; 45 | } 46 | } 47 | 48 | template RDE_FORCEINLINE 49 | void advance(TIter& iter, TDist d, rde::random_access_iterator_tag) 50 | { 51 | iter += d; 52 | } 53 | template RDE_FORCEINLINE 54 | void advance(TIter& iter, TDist d, rde::bidirectional_iterator_tag) 55 | { 56 | if (d >= 0) 57 | { 58 | while (d--) 59 | ++iter; 60 | } 61 | else 62 | { 63 | while (d++) 64 | --iter; 65 | } 66 | } 67 | template RDE_FORCEINLINE 68 | void advance(TIter& iter, TDist d, rde::input_iterator_tag) 69 | { 70 | RDE_ASSERT(d >= 0); 71 | while (d--) 72 | ++iter; 73 | } 74 | } // namespace internal 75 | } // namespace rde 76 | 77 | //----------------------------------------------------------------------------- 78 | #endif // #ifndef RDESTL_ITERATOR_H 79 | -------------------------------------------------------------------------------- /external/rdestl/list.cpp: -------------------------------------------------------------------------------- 1 | #include "list.h" 2 | 3 | namespace rde 4 | { 5 | namespace internal 6 | { 7 | void list_base_node::link_before(list_base_node* nextNode) 8 | { 9 | RDE_ASSERT(!in_list()); 10 | prev = nextNode->prev; 11 | prev->next = this; 12 | nextNode->prev = this; 13 | next = nextNode; 14 | } 15 | void list_base_node::unlink() 16 | { 17 | RDE_ASSERT(in_list()); 18 | prev->next = next; 19 | next->prev = prev; 20 | next = prev = this; 21 | } 22 | } // internal 23 | } 24 | -------------------------------------------------------------------------------- /external/rdestl/pair.h: -------------------------------------------------------------------------------- 1 | #ifndef RDESTL_PAIR_H 2 | #define RDESTL_PAIR_H 3 | 4 | #include "type_traits.h" 5 | 6 | namespace rde 7 | { 8 | //============================================================================= 9 | template 10 | struct pair 11 | { 12 | typedef T1 first_type; 13 | typedef T2 second_type; 14 | 15 | pair() {/**/} 16 | pair(const T1& a, const T2& b): first(a), second(b) {/**/} 17 | explicit pair(const T1& a): first(a) {/**/} 18 | 19 | pair(const pair& rhs) : first(rhs.first), second(rhs.second) {/**/} 20 | 21 | pair& operator=(const pair& rhs) 22 | { 23 | first = rhs.first; 24 | second = rhs.second; 25 | return *this; 26 | } 27 | 28 | T1 first; 29 | T2 second; 30 | }; 31 | 32 | //============================================================================= 33 | // Pair is POD if every element is POD/fundamental 34 | template struct is_pod > 35 | { 36 | enum { value = (is_pod::value || is_fundamental::value) && 37 | (is_pod::value || is_fundamental::value) }; 38 | }; 39 | 40 | //----------------------------------------------------------------------------- 41 | template 42 | pair make_pair(const T1& a, const T2& b) 43 | { 44 | return pair(a, b); 45 | } 46 | 47 | } 48 | 49 | //----------------------------------------------------------------------------- 50 | #endif // #ifndef RDESTL_PAIR_H 51 | -------------------------------------------------------------------------------- /external/rdestl/rde_string.h: -------------------------------------------------------------------------------- 1 | #ifndef RDESTL_STRING_H 2 | #define RDESTL_STRING_H 3 | 4 | #include "basic_string.h" 5 | #include "hash.h" 6 | 7 | namespace rde 8 | { 9 | typedef basic_string string; 10 | 11 | template 12 | struct hash > 13 | { 14 | hash_value_t operator()(const basic_string& x) const 15 | { 16 | // Derived from: http://blade.nagaokaut.ac.jp/cgi-bin/scat.rb/ruby/ruby-talk/142054 17 | hash_value_t h = 0; 18 | for (basic_string::size_type p = 0; p < x.length(); ++p) 19 | { 20 | h = x[p] + (h<<6) + (h<<16) - h; 21 | } 22 | return h & 0x7FFFFFFF; 23 | } 24 | }; 25 | 26 | } 27 | 28 | #endif // RDESTL_STRING_H 29 | -------------------------------------------------------------------------------- /external/rdestl/rdestl.h: -------------------------------------------------------------------------------- 1 | #ifndef RDESTL_H 2 | #define RDESTL_H 3 | 4 | #include "rdestl_common.h" 5 | #include "vector.h" 6 | #include "hash_map.h" 7 | #include "rde_string.h" 8 | #include "stack.h" 9 | #include "algorithm.h" 10 | #include "functional.h" 11 | #include "list.h" 12 | #include "pair.h" 13 | #include "sort.h" 14 | #include "utility.h" 15 | #include "sstream.h" 16 | 17 | namespace rde 18 | { 19 | template > 21 | struct deque : public vector 22 | { 23 | // TODO 24 | }; 25 | }; 26 | #endif 27 | -------------------------------------------------------------------------------- /external/rdestl/rdestl_common.h: -------------------------------------------------------------------------------- 1 | #ifndef RDESTL_COMMON_H 2 | #define RDESTL_COMMON_H 3 | 4 | #ifndef RDESTL_STANDALONE 5 | # define RDESTL_STANDALONE 1 6 | #endif 7 | 8 | #if RDESTL_STANDALONE 9 | # ifdef _MSC_VER 10 | # include 11 | # include 12 | # define RDE_FORCEINLINE __forceinline 13 | # else 14 | # include 15 | # include 16 | # include 17 | # define RDE_FORCEINLINE inline 18 | # endif 19 | 20 | # ifdef _DEBUG 21 | # undef RDE_DEBUG 22 | # define RDE_DEBUG 1 23 | # endif 24 | 25 | # define RDE_ASSERT assert 26 | 27 | namespace rde 28 | { 29 | // # Meh. MSVC doesnt seem to have 30 | // @todo Fixes to make this portable. 31 | typedef unsigned char uint8; 32 | typedef unsigned short uint16; 33 | typedef signed long int32; 34 | typedef unsigned long uint32; 35 | #ifdef _MSC_VER 36 | typedef unsigned __int64 uint64; 37 | #else 38 | typedef unsigned long long uint64; 39 | #endif 40 | namespace Sys 41 | { 42 | RDE_FORCEINLINE void MemCpy(void* to, const void* from, size_t bytes) 43 | { 44 | memcpy(to, from, bytes); 45 | } 46 | RDE_FORCEINLINE void MemMove(void* to, const void* from, size_t bytes) 47 | { 48 | memmove(to, from, bytes); 49 | } 50 | RDE_FORCEINLINE void MemSet(void* buf, unsigned char value, size_t bytes) 51 | { 52 | memset(buf, value, bytes); 53 | } 54 | } // sys 55 | } 56 | #else 57 | # include "core/RdeAssert.h" 58 | # include "core/System.h" 59 | #endif 60 | 61 | namespace rde 62 | { 63 | enum e_noinitialize 64 | { 65 | noinitialize 66 | }; 67 | } 68 | 69 | #endif // #ifndef RDESTL_H 70 | -------------------------------------------------------------------------------- /external/rdestl/slist.cpp: -------------------------------------------------------------------------------- 1 | #include "slist.h" 2 | 3 | namespace rde 4 | { 5 | namespace internal 6 | { 7 | void slist_base_node::link_after(slist_base_node* prevNode) 8 | { 9 | RDE_ASSERT(!in_list()); 10 | next = prevNode->next; 11 | prevNode->next = this; 12 | } 13 | void slist_base_node::unlink(slist_base_node* prevNode) 14 | { 15 | RDE_ASSERT(in_list()); 16 | RDE_ASSERT(prevNode->next == this); 17 | prevNode->next = next; 18 | next = this; 19 | } 20 | } 21 | } 22 | -------------------------------------------------------------------------------- /external/rdestl/stack.h: -------------------------------------------------------------------------------- 1 | #ifndef RDESTL_STACK_H 2 | #define RDESTL_STACK_H 3 | 4 | #include "vector.h" 5 | 6 | namespace rde 7 | { 8 | // Stack implemented on top of another container (vector by default). 9 | template > 11 | class stack 12 | { 13 | public: 14 | typedef TContainer container_type; 15 | typedef typename TContainer::value_type value_type; 16 | typedef typename TContainer::size_type size_type; 17 | typedef TAllocator allocator_type; 18 | 19 | explicit stack(const allocator_type& allocator = allocator_type()) 20 | : m_container(allocator) 21 | { 22 | } 23 | stack(const stack& rhs, const allocator_type& allocator = allocator_type()) 24 | : m_container(rhs, allocator) 25 | { 26 | } 27 | explicit stack(e_noinitialize n) 28 | : m_container(n) 29 | { 30 | } 31 | 32 | // @note Doesnt copy allocator from rhs. 33 | stack& operator=(const stack& rhs) 34 | { 35 | if (&rhs != this) 36 | { 37 | m_container = rhs.m_container; 38 | } 39 | return *this; 40 | } 41 | 42 | void push(const value_type& v) 43 | { 44 | m_container.push_back(v); 45 | } 46 | void pop() 47 | { 48 | m_container.pop_back(); 49 | } 50 | value_type& top() { return m_container.back(); } 51 | const value_type& top() const { return m_container.back(); } 52 | 53 | // @extension 54 | void clear() { m_container.clear(); } 55 | 56 | bool empty() const { return m_container.empty(); } 57 | size_type size() const { return m_container.size(); } 58 | 59 | const allocator_type& get_allocator() const 60 | { 61 | return m_container.get_allocator(); 62 | } 63 | void set_allocator(const allocator_type& allocator) 64 | { 65 | m_container.set_allocator(allocator); 66 | } 67 | 68 | private: 69 | TContainer m_container; 70 | }; 71 | 72 | } // rde 73 | 74 | #endif 75 | -------------------------------------------------------------------------------- /external/rdestl/stack_allocator.h: -------------------------------------------------------------------------------- 1 | #ifndef RDESTL_STACK_ALLOCATOR_H 2 | #define RDESTL_STACK_ALLOCATOR_H 3 | 4 | #include "rdestl_common.h" 5 | 6 | namespace rde 7 | { 8 | // Stack based allocator. 9 | // Traits: 10 | // - operates on buffer of TBytes bytes of stack memory 11 | // - never frees memory 12 | // - cannot be copied 13 | template 14 | class stack_allocator 15 | { 16 | public: 17 | explicit stack_allocator(const char* name = "STACK") 18 | : m_name(name), 19 | m_bufferTop(0) 20 | { 21 | /**/ 22 | } 23 | 24 | void* allocate(size_t bytes, int /*flags*/ = 0) 25 | { 26 | RDE_ASSERT(m_bufferTop + bytes <= TBytes); 27 | char* ret = &m_buffer[0] + m_bufferTop; 28 | m_bufferTop += bytes; 29 | return ret; 30 | } 31 | void deallocate(void* ptr, size_t /*bytes*/) 32 | { 33 | RDE_ASSERT(ptr == 0 || (ptr >= &m_buffer[0] && ptr < &m_buffer[TBytes])); 34 | sizeof(ptr); 35 | } 36 | 37 | const char* get_name() const { return m_name; } 38 | 39 | private: 40 | stack_allocator(const stack_allocator&); 41 | stack_allocator& operator=(const stack_allocator&); 42 | 43 | const char* m_name; 44 | char m_buffer[TBytes]; 45 | size_t m_bufferTop; 46 | }; 47 | 48 | } // namespace rde 49 | //----------------------------------------------------------------------------- 50 | #endif 51 | -------------------------------------------------------------------------------- /external/rdestl/string_utils.h: -------------------------------------------------------------------------------- 1 | #ifndef RDESTL_STRING_UTILS_H 2 | #define RDESTL_STRING_UTILS_H 3 | 4 | namespace rde 5 | { 6 | //----------------------------------------------------------------------------- 7 | template int strlen(const T* str) 8 | { 9 | int len(0); 10 | while (*str++) 11 | ++len; 12 | return len; 13 | } 14 | 15 | //----------------------------------------------------------------------------- 16 | template int strcompare(const T* s1, const T* s2, size_t len) 17 | { 18 | for (/**/; len != 0; --len) 19 | { 20 | const T c1 = *s1; 21 | const T c2 = *s2; 22 | if (c1 != c2) 23 | return (c1 < c2 ? -1 : 1); 24 | 25 | ++s1; 26 | ++s2; 27 | } 28 | return 0; 29 | } 30 | 31 | //----------------------------------------------------------------------------- 32 | template int strcompare(const T* s1, const T* s2) 33 | { 34 | while (*s1 && *s2) 35 | { 36 | const T c1 = *s1; 37 | const T c2 = *s2; 38 | if (c1 != c2) 39 | return (c1 < c2 ? -1 : 1); 40 | 41 | ++s1; 42 | ++s2; 43 | } 44 | if (*s1) 45 | return 1; 46 | if (*s2) 47 | return -1; 48 | return 0; 49 | } 50 | 51 | } // rde 52 | 53 | #endif // RDESTL_STRING_UTILS_H 54 | -------------------------------------------------------------------------------- /external/rdestl/type_traits.h: -------------------------------------------------------------------------------- 1 | #ifndef RDESTL_TYPETRAITS_H 2 | #define RDESTL_TYPETRAITS_H 3 | 4 | namespace rde 5 | { 6 | 7 | template struct is_integral 8 | { 9 | enum { value = false }; 10 | }; 11 | 12 | template struct is_floating_point 13 | { 14 | enum { value = false }; 15 | }; 16 | 17 | #define RDE_INTEGRAL(TYPE) template<> struct is_integral { enum { value = true }; } 18 | 19 | RDE_INTEGRAL(char); 20 | RDE_INTEGRAL(unsigned char); 21 | RDE_INTEGRAL(bool); 22 | RDE_INTEGRAL(short); 23 | RDE_INTEGRAL(unsigned short); 24 | RDE_INTEGRAL(int); 25 | RDE_INTEGRAL(unsigned int); 26 | RDE_INTEGRAL(long); 27 | RDE_INTEGRAL(unsigned long); 28 | RDE_INTEGRAL(wchar_t); 29 | 30 | template<> struct is_floating_point { enum { value = true }; }; 31 | template<> struct is_floating_point { enum { value = true }; }; 32 | 33 | template struct is_pointer 34 | { 35 | enum { value = false }; 36 | }; 37 | template struct is_pointer 38 | { 39 | enum { value = true }; 40 | }; 41 | 42 | template struct is_pod 43 | { 44 | enum { value = false }; 45 | }; 46 | 47 | template struct is_fundamental 48 | { 49 | enum 50 | { 51 | value = is_integral::value || is_floating_point::value 52 | }; 53 | }; 54 | 55 | template struct has_trivial_constructor 56 | { 57 | enum 58 | { 59 | value = is_fundamental::value || is_pointer::value || is_pod::value 60 | }; 61 | }; 62 | 63 | template struct has_trivial_copy 64 | { 65 | enum 66 | { 67 | value = is_fundamental::value || is_pointer::value || is_pod::value 68 | }; 69 | }; 70 | 71 | template struct has_trivial_assign 72 | { 73 | enum 74 | { 75 | value = is_fundamental::value || is_pointer::value || is_pod::value 76 | }; 77 | }; 78 | 79 | template struct has_trivial_destructor 80 | { 81 | enum 82 | { 83 | value = is_fundamental::value || is_pointer::value || is_pod::value 84 | }; 85 | }; 86 | 87 | template struct has_cheap_compare 88 | { 89 | enum 90 | { 91 | value = has_trivial_copy::value && sizeof(T) <= 4 92 | }; 93 | }; 94 | 95 | } // namespace rde 96 | 97 | //----------------------------------------------------------------------------- 98 | #endif // #ifndef RDESTL_TYPETRAITS_H 99 | 100 | -------------------------------------------------------------------------------- /external/socfatkas/copyright.txt: -------------------------------------------------------------------------------- 1 | On 05/10/13 8:11 AM, Vadim Shcherbakov wrote: 2 | -------------------- 3 | Hey, you can use the code as you like, there is no license or any limitations. 4 | Regards, Vadim 5 | 6 | On 05/06/13 8:16 PM, Brooke Hodgman wrote: 7 | -------------------- 8 | Hi Vadim, I'm really interested in the software occlusion demo on your blog! 9 | I'd like to make some changes to your ZIP to turn it into a reusable open-source library, but there is no license in the ZIP. Can you give me permission to re-publish your code using a license like MIT, ZLIB, WTFPL, etc? -------------------------------------------------------------------------------- /external/socfatkas/rasterizer.cpp: -------------------------------------------------------------------------------- 1 | 2 | #include "rasterizer.h" 3 | #include 4 | 5 | //__m128 Rasterizer::g_one = Vector4( 1.f, 1.f, 1.f, 1.f ); 6 | const __m128 Rasterizer::g_tile_bounds = Vector4( (float)Rasterizer::g_width, 1.f, (float)Rasterizer::g_width, 1.f ); 7 | const __m128 Rasterizer::g_fixed_point_factor = Vector4( 65536.f, 65536.f, 65536.f, 65536.f ); 8 | const __m128 Rasterizer::g_total_width_v = Vector4( (float)Rasterizer::g_total_width ); 9 | const __m128 Rasterizer::g_total_height_v = Vector4( (float)Rasterizer::g_total_height); 10 | 11 | inline static int Shift( int val ) 12 | { 13 | if( val > 31 ) 14 | return 0; 15 | if( val < 0 ) 16 | return 0xffffffff; 17 | return 0xffffffff >> val; 18 | } 19 | 20 | /* 21 | int Rasterizer::Present() const 22 | { 23 | int count = 0; 24 | 25 | // int indices[4] = { 1, 0, 3, 2 }; 26 | int indices[4] = { 0, 1, 2, 3 }; 27 | { 28 | for( int i = 0; i < Tile::g_tile_height; ++i ) 29 | { 30 | for ( int x = 0; x < g_width; ++x ) 31 | { 32 | for ( int k = 0; k < 4; ++k ) 33 | { 34 | int frame_buffer = *( (int*)&m_tiles[x].m_frame_buffer[i] + indices[k]); 35 | for( int j = 0; j < 32; ++j ) 36 | { 37 | char c = ( frame_buffer >> j ) & 1; 38 | count += c != 0 ? 1 : 0; 39 | } 40 | } 41 | } 42 | } 43 | } 44 | return count; 45 | }*/ 46 | 47 | void Rasterizer::Init() 48 | { 49 | static bool init = false; 50 | if( init ) 51 | return; 52 | for ( int j = 0; j < 10; ++j ) 53 | { 54 | for (int i = 0; i < j*128; ++i ) 55 | Tile::g_x_shifts[ j ][ i ] = Vector4Int( 0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff ); 56 | for (int i = (j+1)*128; i < 4096; ++i ) 57 | Tile::g_x_shifts[ j ][ i ] = VecIntZero(); 58 | for (int i = 0; i < 128; ++i ) 59 | Tile::g_x_shifts[ j ][ j*128 + i ] = _mm_set_epi32( Shift(i), Shift(i - 32), Shift(i - 64), Shift(i - 96) ); 60 | } 61 | init = true; 62 | } 63 | -------------------------------------------------------------------------------- /external/tilde/LuaHostWindows.h: -------------------------------------------------------------------------------- 1 | 2 | /**************************************************************************** 3 | 4 | Tilde 5 | 6 | Copyright (c) 2008 Tantalus Media Pty 7 | 8 | Permission is hereby granted, free of charge, to any person obtaining a copy 9 | of this software and associated documentation files (the "Software"), to deal 10 | in the Software without restriction, including without limitation the rights 11 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 12 | copies of the Software, and to permit persons to whom the Software is 13 | furnished to do so, subject to the following conditions: 14 | 15 | The above copyright notice and this permission notice shall be included in 16 | all copies or substantial portions of the Software. 17 | 18 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 19 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 20 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 21 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 22 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 23 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 24 | THE SOFTWARE. 25 | 26 | ****************************************************************************/ 27 | 28 | #ifndef LUAHOSTWINDOWS_H 29 | #define LUAHOSTWINDOWS_H 30 | 31 | #include "tilde/LuaDebuggerHost.h" 32 | 33 | namespace tilde 34 | { 35 | class LuaDebuggerComms; 36 | 37 | class LuaHostWindows : public tilde::LuaDebuggerHost 38 | { 39 | public: 40 | LuaHostWindows(int port = 10000); 41 | virtual ~LuaHostWindows(); 42 | 43 | bool IsConnected() const; 44 | void WaitForDebuggerConnection(); 45 | void Poll(); 46 | 47 | virtual void RegisterState(const char* stateName, lua_State* lvm); 48 | virtual void SendDebuggerData(const void * data, int size); 49 | virtual void CloseDebuggerConnection(); 50 | virtual bool AttachLuaHook(lua_State* lvm, lua_Hook hook, int mask, int count); 51 | virtual void DetachLuaHook(lua_State* lvm, lua_Hook hook); 52 | virtual void AttachPrintfHook( void (* hook)(const char *) ); 53 | virtual void DetachPrintfHook( void (* hook)(const char *) ); 54 | virtual void ReceiveExCommand(const char * command, int datalen, tilde::ReceiveMessageBuffer * data); 55 | virtual void OnIdle(); 56 | virtual void OnRun(); 57 | virtual const char * GetFunctionName(lua_State * lvm, int funcIndex, lua_Debug * ar); 58 | virtual const char *LookupSourceFile( const char *target ); 59 | virtual const char *LookupTargetFile( const char *source); 60 | 61 | 62 | private: 63 | class Detail; 64 | Detail* m_detail; 65 | }; 66 | 67 | } // namespace tilde 68 | 69 | #endif // LUAHOSTWINDOWS_H 70 | -------------------------------------------------------------------------------- /external/timer_lib/Makefile: -------------------------------------------------------------------------------- 1 | SRC = timer.c 2 | OBJ = $(SRC:.c=.o) 3 | OUT = libtimer.a 4 | TST = timertest 5 | TSR = test.c 6 | TOB = $(TSR:.c=.o) 7 | 8 | CFLAGS = -O3 9 | LDFLAGS = 10 | 11 | default: $(OUT) $(TST) 12 | 13 | .c.o: 14 | gcc $(CFLAGS) -c $< -o $@ 15 | 16 | $(OUT): $(OBJ) 17 | ar rcs $(OUT) $(OBJ) 18 | 19 | $(TST): $(OUT) $(TOB) 20 | gcc $(CFLAGS) $(LDFLAGS) -o $(TST) $(TOB) $(OUT) -lrt 21 | 22 | clean: 23 | rm -f $(OBJ) $(OUT) $(TOB) $(TST) 24 | -------------------------------------------------------------------------------- /external/timer_lib/README: -------------------------------------------------------------------------------- 1 | timer_lib - v0.4 - Public Domain - 2011 Mattias Jansson / Rampant Pixels 2 | 3 | This library provides a cross-platform interface to measure 4 | elapsed time with (at least) millisecond accuracy. The latest 5 | source code is always available at 6 | 7 | https://github.com/rampantpixels/timer_lib 8 | 9 | Used by the profile_lib public domain library for performing 10 | multithreaded application profiling, available at 11 | 12 | https://github.com/rampantpixels/profile_lib 13 | 14 | This library is put in the public domain; you can redistribute 15 | it and/or modify it without any restrictions. 16 | -------------------------------------------------------------------------------- /external/timer_lib/test.c: -------------------------------------------------------------------------------- 1 | #include "timer.h" 2 | 3 | #include 4 | #include 5 | #include 6 | 7 | 8 | int main( int argc, char** argv ) 9 | { 10 | timer* time; 11 | tick_t tick, freq, last, res; 12 | 13 | printf( "Timer test\n" ); 14 | 15 | timer_lib_initialize(); 16 | 17 | time = malloc( sizeof( timer ) ); 18 | timer_initialize( time ); 19 | 20 | last = 0; 21 | res = 0xFFFFFFFFFFFFFFFFULL; 22 | freq = timer_ticks_per_second( time ); 23 | 24 | while( 1 ) 25 | { 26 | tick = timer_elapsed_ticks( time, 0 ); 27 | 28 | if( tick > last ) 29 | { 30 | if( tick - last < res ) 31 | res = tick - last; 32 | } 33 | 34 | last = tick; 35 | 36 | if( (double)tick / (double)freq > 10.0 ) 37 | break; 38 | } 39 | 40 | printf( "Resolution: %lfms\n", 1000.0 * (double)res / (double)freq ); 41 | 42 | free( time ); 43 | timer_lib_shutdown(); 44 | 45 | return 0; 46 | } 47 | 48 | -------------------------------------------------------------------------------- /external/timer_lib/timer.sln: -------------------------------------------------------------------------------- 1 |  2 | Microsoft Visual Studio Solution File, Format Version 11.00 3 | # Visual Studio 2010 4 | Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "timer", "timer.vcxproj", "{321BAB92-2EDE-4B3B-939D-BD0BE0248C8F}" 5 | EndProject 6 | Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "test", "test.vcxproj", "{54E95B82-7759-4825-9478-91E76F1C1C89}" 7 | EndProject 8 | Global 9 | GlobalSection(SolutionConfigurationPlatforms) = preSolution 10 | Debug|Win32 = Debug|Win32 11 | Debug|x64 = Debug|x64 12 | Release|Win32 = Release|Win32 13 | Release|x64 = Release|x64 14 | EndGlobalSection 15 | GlobalSection(ProjectConfigurationPlatforms) = postSolution 16 | {321BAB92-2EDE-4B3B-939D-BD0BE0248C8F}.Debug|Win32.ActiveCfg = Debug|Win32 17 | {321BAB92-2EDE-4B3B-939D-BD0BE0248C8F}.Debug|Win32.Build.0 = Debug|Win32 18 | {321BAB92-2EDE-4B3B-939D-BD0BE0248C8F}.Debug|x64.ActiveCfg = Debug|x64 19 | {321BAB92-2EDE-4B3B-939D-BD0BE0248C8F}.Debug|x64.Build.0 = Debug|x64 20 | {321BAB92-2EDE-4B3B-939D-BD0BE0248C8F}.Release|Win32.ActiveCfg = Release|Win32 21 | {321BAB92-2EDE-4B3B-939D-BD0BE0248C8F}.Release|Win32.Build.0 = Release|Win32 22 | {321BAB92-2EDE-4B3B-939D-BD0BE0248C8F}.Release|x64.ActiveCfg = Release|x64 23 | {321BAB92-2EDE-4B3B-939D-BD0BE0248C8F}.Release|x64.Build.0 = Release|x64 24 | {54E95B82-7759-4825-9478-91E76F1C1C89}.Debug|Win32.ActiveCfg = Debug|Win32 25 | {54E95B82-7759-4825-9478-91E76F1C1C89}.Debug|Win32.Build.0 = Debug|Win32 26 | {54E95B82-7759-4825-9478-91E76F1C1C89}.Debug|x64.ActiveCfg = Debug|x64 27 | {54E95B82-7759-4825-9478-91E76F1C1C89}.Debug|x64.Build.0 = Debug|x64 28 | {54E95B82-7759-4825-9478-91E76F1C1C89}.Release|Win32.ActiveCfg = Release|Win32 29 | {54E95B82-7759-4825-9478-91E76F1C1C89}.Release|Win32.Build.0 = Release|Win32 30 | {54E95B82-7759-4825-9478-91E76F1C1C89}.Release|x64.ActiveCfg = Release|x64 31 | {54E95B82-7759-4825-9478-91E76F1C1C89}.Release|x64.Build.0 = Release|x64 32 | EndGlobalSection 33 | GlobalSection(SolutionProperties) = preSolution 34 | HideSolutionNode = FALSE 35 | EndGlobalSection 36 | EndGlobal 37 | -------------------------------------------------------------------------------- /include/eight/core/algorithm.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | -------------------------------------------------------------------------------- /include/eight/core/align.h: -------------------------------------------------------------------------------- 1 | //------------------------------------------------------------------------------ 2 | #pragma once 3 | namespace eight { 4 | //------------------------------------------------------------------------------ 5 | #ifdef _MSC_VER 6 | # define eiALIGN(bytes) __declspec( align(bytes) ) 7 | #else 8 | # define eiALIGN(bytes) __attribute__ ((aligned (bytes))) 9 | #endif 10 | 11 | #define eiATOMIC_ALIGNMENT 16 // todo, check build architecture 12 | 13 | template 14 | struct eiALIGN(eiATOMIC_ALIGNMENT) AtomicAligned 15 | { 16 | eiALIGN(eiATOMIC_ALIGNMENT) T data[I]; 17 | }; 18 | //------------------------------------------------------------------------------ 19 | } // namespace eight 20 | //------------------------------------------------------------------------------ 21 | -------------------------------------------------------------------------------- /include/eight/core/alloc/compactpool.h: -------------------------------------------------------------------------------- 1 | //------------------------------------------------------------------------------ 2 | #pragma once 3 | #include 4 | #include 5 | #include 6 | namespace eight { 7 | //------------------------------------------------------------------------------ 8 | 9 | template class CompactPool : NonCopyable 10 | { 11 | const static bool s_NonPod = true;//todo 12 | public: 13 | eiTYPEDEF_ID(Id); 14 | CompactPool( Scope& a, uint size ); 15 | ~CompactPool(); 16 | Id Handle(const T& object); 17 | Id Alloc( const T& data); 18 | Id Alloc(); 19 | void Release( Id handle ); 20 | T& operator[]( Id handle ); 21 | const T* Begin() const { return m_data; } 22 | T* Begin() { return m_data; } 23 | const T* End() const { return m_data+Size(); } 24 | T* End() { return m_data+Size(); } 25 | uint Capacity() const { return m_pool.Capacity(); } 26 | uint Size() const { return m_map.Size(); } 27 | void Clear(); 28 | template void ForEach(Fn& fn); 29 | template void ForEach(Fn& fn) const; 30 | private: 31 | PoolBase m_pool; 32 | HandleMap m_map; 33 | T* m_data; 34 | }; 35 | 36 | //------------------------------------------------------------------------------ 37 | #include "compactpool.hpp" 38 | //------------------------------------------------------------------------------ 39 | } // namespace eight 40 | //------------------------------------------------------------------------------ -------------------------------------------------------------------------------- /include/eight/core/alloc/compactpool.hpp: -------------------------------------------------------------------------------- 1 | 2 | template 3 | CompactPool::CompactPool( Scope& a, uint size ) 4 | : m_pool(a, size) 5 | , m_map(a, size) 6 | , m_data(eiAllocArray(a,T,size)) 7 | { 8 | } 9 | 10 | template 11 | CompactPool::~CompactPool() 12 | { 13 | if( s_NonPod ) 14 | { 15 | for( uint i=0, end=Size(); i!=end; ++i ) 16 | m_data[i].~T(); 17 | } 18 | } 19 | 20 | template 21 | T& CompactPool::operator[]( Id handle ) 22 | { 23 | eiDEBUG( m_pool.Dbg_ValidateIndex(handle) ); 24 | uint physical = m_map.ToPhysical(handle); 25 | T& data = m_data[physical]; 26 | return data; 27 | } 28 | 29 | template 30 | typename CompactPool::Id CompactPool::Handle(const T& object) 31 | { 32 | eiASSERT( &object >= m_data && &object < m_data+m_pool.Size() ); 33 | int physical = &object-m_data; 34 | return Id(m_map.ToHandle(physical)); 35 | } 36 | 37 | template 38 | typename CompactPool::Id CompactPool::Alloc(const T& data) 39 | { 40 | int handle = m_pool.Alloc(); 41 | if( handle < 0 ) 42 | return -1; 43 | uint physical = m_map.AllocHandleToPhysical(handle); 44 | T* t = &m_data[physical]; 45 | if( s_NonPod ) 46 | new(t) T(data); 47 | else 48 | *t = data; 49 | return Id(handle); 50 | } 51 | 52 | template 53 | typename CompactPool::Id CompactPool::Alloc() 54 | { 55 | int handle = m_pool.Alloc(); 56 | if( handle >= 0 ) 57 | { 58 | uint physical = m_map.AllocHandleToPhysical(handle); 59 | if( s_NonPod ) 60 | { 61 | T* t = &m_data[physical]; 62 | new(t) T; 63 | } 64 | } 65 | return Id(handle); 66 | } 67 | 68 | template 69 | void CompactPool::Release( Id handle ) 70 | { 71 | eiDEBUG( m_pool.Dbg_ValidateIndex(handle) ); 72 | m_pool.Release( handle ); 73 | HandleMap::MoveCmd move = m_map.EraseHandle( handle ); 74 | if( s_NonPod ) 75 | { 76 | m_data[move.to].~T(); 77 | if( move.from != move.to ) 78 | { 79 | new(&m_data[move.to])( m_data[move.from] ); 80 | m_data[move.from].~T(); 81 | } 82 | } 83 | else 84 | m_data[move.to] = m_data[move.from]; 85 | } 86 | 87 | template 88 | void CompactPool::Clear() 89 | { 90 | if( s_NonPod ) 91 | { 92 | for( uint i=0, end=Size(); i!=end; ++i ) 93 | m_data[i].~T(); 94 | } 95 | m_map.Clear(Capacity()); 96 | m_pool.Clear(); 97 | } 98 | 99 | template template 100 | void CompactPool::ForEach(Fn& fn) 101 | { 102 | T* data = m_data; 103 | for( uint i=0, end=m_map.Size(); i != end; ++i ) 104 | { 105 | fn(Id(m_map.ToHandle(i)), data[i]); 106 | } 107 | } 108 | template template 109 | void CompactPool::ForEach(Fn& fn) const 110 | { 111 | const T* data = m_data; 112 | for( uint i=0, end=m_map.Size(); i != end; ++i ) 113 | { 114 | fn(Id(m_map.ToHandle(i)), data[i]); 115 | } 116 | } -------------------------------------------------------------------------------- /include/eight/core/alloc/fixedarray.h: -------------------------------------------------------------------------------- 1 | //------------------------------------------------------------------------------ 2 | #pragma once 3 | #include 4 | #include 5 | namespace eight { 6 | //------------------------------------------------------------------------------ 7 | 8 | template 9 | class FixedArray 10 | { 11 | public: 12 | T& operator[](uint i) { eiASSERT(i < SIZE); return data[i]; } 13 | const T& operator[](uint i) const { eiASSERT(i < SIZE); return data[i]; } 14 | int IndexOf(const T& t) const 15 | { 16 | for (uint i = 0; i != SIZE; ++i) 17 | { 18 | if (data[i] == t) 19 | return i; 20 | } 21 | return -1; 22 | } 23 | private: 24 | T data[SIZE]; 25 | }; 26 | 27 | 28 | template 29 | class FixedArray 30 | { 31 | public: 32 | T& operator[](int i) { eiFatalError("bounds check"); return *(T*)0; } 33 | const T& operator[](int i) const { eiFatalError("bounds check"); return *(T*)0; } 34 | int IndexOf(const T&) const { return -1; } 35 | }; 36 | 37 | //------------------------------------------------------------------------------ 38 | } // namespace eight 39 | //------------------------------------------------------------------------------ 40 | -------------------------------------------------------------------------------- /include/eight/core/alloc/interface.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #include 3 | #include 4 | #include 5 | namespace eight { 6 | //------------------------------------------------------------------------------ 7 | 8 | struct TagInterface {}; 9 | template 10 | class Interface : NonCopyable, public TagInterface 11 | { 12 | public: 13 | static unsigned int Instance_Size(); 14 | static void Instance_Destruct(void*); 15 | private: 16 | friend T; 17 | ~Interface() { eiASSERT(false); } 18 | }; 19 | 20 | template 21 | class Implementation : NonCopyable 22 | { 23 | public: 24 | operator T&() { return *(T*)this; } 25 | operator T&() const { return *(T*)this; } 26 | }; 27 | 28 | #define eiImplementInterface( interface, implementation ) \ 29 | uint Interface::Instance_Size() { return sizeof(implementation); } \ 30 | void Interface::Instance_Destruct(void* p) { eiASSERT(p); \ 31 | ((implementation*)p)->~implementation(); } \ 32 | template<> struct eight::InterfaceType { typedef implementation Type; }; // 33 | 34 | #define eiInterfaceConstructor( interface, call, ... ) \ 35 | interface::interface(__VA_ARGS__) { new((void*)this) eight::InterfaceType::Type call; } // 36 | 37 | #define eiInterfaceFunction( ret, interface, name, call, ... ) \ 38 | ret interface::name(__VA_ARGS__) { return ((eight::InterfaceType::Type*)this)->name call; } // 39 | #define eiInterfaceFunctionConst( ret, interface, name, call, ... ) \ 40 | ret interface::name(__VA_ARGS__) const { return ((eight::InterfaceType::Type*)this)->name call; } // 41 | 42 | #define eiImplementNullInterface( interface ) \ 43 | uint Interface::Instance_Size() { eiASSERT(false); return 0; } \ 44 | void Interface::Instance_Destruct(void* p) { eiASSERT(p); } \ 45 | template<> struct eight::InterfaceType { typedef void Type; } ; // 46 | 47 | //internals: 48 | class Scope; 49 | template void* InterfaceAlloc(Scope& a) 50 | { 51 | u8* mem = a.Alloc( Interface::Instance_Size() ); 52 | a.OnUnwind( mem, &Interface::Instance_Destruct, sizeof(Interface::Instance_Size()) );//todo - shouldn't add destructor until after constructor runs... 53 | return mem; 54 | } 55 | template void* InterfaceAlloc(const ei_GlobalHeap& a) 56 | { 57 | u8* mem = a.Alloc( Interface::Instance_Size() ); 58 | return mem; 59 | } 60 | template struct InterfaceType {}; 61 | 62 | 63 | template typename InterfaceType::Type& Cast( T& o ) { return (InterfaceType::Type&)o; } 64 | 65 | //------------------------------------------------------------------------------ 66 | }//namespace 67 | //------------------------------------------------------------------------------ 68 | -------------------------------------------------------------------------------- /include/eight/core/alloc/malloc.h: -------------------------------------------------------------------------------- 1 | //------------------------------------------------------------------------------ 2 | #pragma once 3 | #include 4 | 5 | namespace eight { 6 | //------------------------------------------------------------------------------ 7 | void* Malloc( size_t size ); 8 | template T* Malloc() { return (T*)Malloc(sizeof(T)); } 9 | void Free( void* ); 10 | void* AlignedMalloc( size_t size, uint align ); 11 | void AlignedFree( void* ); 12 | 13 | void* VramAlloc( size_t size, uint align ); 14 | void VramFree( void* ); 15 | 16 | #define eiSAFE_FREE( x ) {if(x){Free(x);x=0;} 17 | #define eiSAFE_VRAM_FREE( x ) {if(x){VramFree(x);x=0;} 18 | 19 | 20 | #define eiMEMCPY memcpy 21 | #define eiMEMCMP memcmp 22 | #define eiMEMSET memset 23 | 24 | 25 | class ScopedMalloc : NonCopyable 26 | { 27 | public: 28 | ScopedMalloc( uint size ) : buffer( Malloc(size) ) {} 29 | ~ScopedMalloc() { Free( buffer ); } 30 | operator void*() { return buffer; } 31 | private: 32 | void* buffer; 33 | }; 34 | 35 | class MallocStack : NonCopyable 36 | { 37 | public: 38 | MallocStack( uint size ) : stack( Malloc(size), size ) {} 39 | ~MallocStack() { Free( (void*)stack.Begin() ); } 40 | StackAlloc stack; 41 | }; 42 | 43 | //------------------------------------------------------------------------------ 44 | } 45 | //------------------------------------------------------------------------------ 46 | -------------------------------------------------------------------------------- /include/eight/core/alloc/pool.h: -------------------------------------------------------------------------------- 1 | //------------------------------------------------------------------------------ 2 | #pragma once 3 | #include 4 | #include 5 | #include 6 | namespace eight { 7 | //------------------------------------------------------------------------------ 8 | 9 | eiInfoGroup( Pool, true ); 10 | 11 | template 12 | class PoolBase : NonCopyable 13 | { 14 | public: 15 | PoolBase( Scope& a, uint size ); 16 | void Clear() { eiASSERT( false && "todo" ); } 17 | void Dbg_ValidateIndex(uint i) const; 18 | bool IsIndexValid(uint i) const; 19 | int Alloc();//ret -1 on fail 20 | void Release( int index ); 21 | bool Empty() const; 22 | int Begin(); 23 | int Next(uint index); 24 | uint Capacity() const { return m_size; } 25 | private: 26 | struct Link { u16 prev, next; }; eiSTATIC_ASSERT( sizeof(Link) == sizeof(u32) ); 27 | const uint m_size; 28 | int m_free; 29 | int* m_offsNextFreeMinusOne; 30 | //if Enumerable: //todo - use specialization to avoid having these mempers in non Enumerable instances 31 | int m_used; 32 | Link* m_usedLinks;//todo - could just use the m_offsNextFreeMinusOne data, as it's invalid when allocated... 33 | eiDEBUG( uint m_dbgCount ); 34 | }; 35 | 36 | //------------------------------------------------------------------------------ 37 | 38 | template 39 | class Pool : NonCopyable 40 | { 41 | eiDEBUG( const static bool dbgNoMemcmp = true ); 42 | public: 43 | Pool( Scope& a, uint size ); 44 | T& operator[](uint i); 45 | const T& operator[](uint i) const; 46 | uint Index(const T& object); 47 | T* Alloc(const T& data); 48 | T* Alloc(); 49 | void Release( T* object ); 50 | T* Begin(); 51 | T* Next(const T& object); 52 | uint Capacity() const { return m_pool.Capacity(); } 53 | bool IsIndexValid(u32 i) const { return m_pool.IsIndexValid(i); } 54 | private: 55 | PoolBase m_pool; 56 | T* m_data; 57 | }; 58 | 59 | //------------------------------------------------------------------------------ 60 | #include "pool.hpp" 61 | //------------------------------------------------------------------------------ 62 | } // namespace eight 63 | //------------------------------------------------------------------------------ 64 | -------------------------------------------------------------------------------- /include/eight/core/alloc/scope.hpp: -------------------------------------------------------------------------------- 1 | //------------------------------------------------------------------------------ 2 | 3 | inline Scope& Scope::DestructorHelper::Owner() const 4 | { 5 | eiSTATIC_ASSERT( (eiOffsetOf(Scope,OnConstructed)) == 0 ); 6 | return *(Scope*)this; 7 | } 8 | template void* Scope::New() 9 | { 10 | void* newObject = Alloc(); 11 | if( IsSameType::value ) 12 | OnUnwind(newObject, &DestructorCallback, sizeof(T)); 13 | return newObject; 14 | } 15 | template T* Scope::New( uint count ) 16 | { 17 | eiASSERT( !Sealed() ); 18 | if( eiUnlikely(!count) ) 19 | return 0; 20 | T* result = Alloc( count ); 21 | for( int i=0; i != count; ++i ) 22 | { 23 | new(&result[i]) T; 24 | } 25 | if( HasDestructor::value ) 26 | { 27 | if( count > 1 ) 28 | { 29 | ArrayDestructor* d = Alloc(); 30 | d->count = count; 31 | d->p = result; 32 | OnUnwind( d, &ArrayDestructor::Callback, sizeof(T)*count ); 33 | } 34 | else 35 | OnUnwind( result, &DestructorCallback, sizeof(T) ); 36 | } 37 | return result; 38 | } 39 | template T* Scope::New( uint count, const T& init ) 40 | { 41 | eiASSERT( !Sealed() ); 42 | if( eiUnlikely(!count) ) 43 | return 0; 44 | T* result = Alloc( count ); 45 | for( int i=0; i != count; ++i ) 46 | { 47 | new(&result[i]) T(init); 48 | } 49 | if( HasDestructor::value ) 50 | { 51 | if( count > 1 ) 52 | { 53 | ArrayDestructor* d = Alloc(); 54 | d->count = count; 55 | d->p = result; 56 | OnUnwind( d, &ArrayDestructor::Callback, sizeof(T)*count ); 57 | } 58 | else 59 | OnUnwind( result, &DestructorCallback, sizeof(T) ); 60 | } 61 | return result; 62 | } 63 | template T* Scope::Alloc() 64 | { 65 | eiASSERT( !Sealed() ); 66 | for(;;) 67 | { 68 | if( alloc->Align(eiAlignOf(T)) ) 69 | { 70 | T* data = alloc->Alloc(); 71 | if( data ) 72 | return data; 73 | } 74 | OnOutOfMemory( eiAlignOf(T) + sizeof(T) ); 75 | } 76 | } 77 | template T* Scope::Alloc( uint count ) 78 | { 79 | eiASSERT( !Sealed() ); 80 | if( eiUnlikely(!count) ) 81 | return 0; 82 | for(;;) 83 | { 84 | if( alloc->Align(eiAlignOf(T)) ) 85 | { 86 | T* data = alloc->Alloc( count ); 87 | if( data ) 88 | return data; 89 | } 90 | OnOutOfMemory( eiAlignOf(T) + sizeof(T) * count ); 91 | } 92 | } 93 | template void Scope::ArrayDestructor::Callback(void* a) 94 | { 95 | eiASSERT(a); 96 | ArrayDestructor* ad = (ArrayDestructor*)a; 97 | eiASSERT(ad->p); 98 | for( T* t = (T*)ad->p, *end=t + ad->count; t!=end; ++t ) 99 | { 100 | t->~T(); 101 | } 102 | } 103 | template void Scope::DestructorCallback(void* p) 104 | { 105 | eiASSERT(p); 106 | ((T*)p)->~T(); 107 | } 108 | //------------------------------------------------------------------------------ -------------------------------------------------------------------------------- /include/eight/core/alloc/scopearray.h: -------------------------------------------------------------------------------- 1 | //------------------------------------------------------------------------------ 2 | #pragma once 3 | #include 4 | #include 5 | namespace eight { 6 | //------------------------------------------------------------------------------ 7 | 8 | template 9 | class ScopeArray 10 | { 11 | public: 12 | ScopeArray( Scope& a, uint s ) : data( s ? eiAllocArray( a, T, s ) : 0 ) { eiDEBUG( capacity=s ); } 13 | T& operator[]( uint i ) { eiASSERT( i < capacity ); return data[i]; } 14 | const T& operator[]( uint i ) const { eiASSERT( i < capacity ); return data[i]; } 15 | T* Begin() { return data; } 16 | int Index( const T& item ) { return (int)(&item - data); } 17 | private: 18 | T* data; 19 | eiDEBUG( uint capacity ); 20 | }; 21 | template 22 | class ScopeArray 23 | { 24 | public: 25 | ScopeArray( Scope& a, uint s ) : data( s ? eiNewArray( a, T, s ) : 0 ) { eiDEBUG( capacity=s ); } 26 | T& operator[]( uint i ) { eiASSERT( i < capacity ); return data[i]; } 27 | const T& operator[]( uint i ) const { eiASSERT( i < capacity ); return data[i]; } 28 | T* Begin() { return data; } 29 | int Index( const T& item ) { return (int)(&item - data); } 30 | private: 31 | T* data; 32 | eiDEBUG( uint capacity ); 33 | }; 34 | 35 | //------------------------------------------------------------------------------ 36 | } // namespace eight 37 | //------------------------------------------------------------------------------ 38 | -------------------------------------------------------------------------------- /include/eight/core/alloc/soapool.h: -------------------------------------------------------------------------------- 1 | //------------------------------------------------------------------------------ 2 | #pragma once 3 | #include 4 | #include 5 | #include 6 | namespace eight { 7 | //------------------------------------------------------------------------------ 8 | 9 | template 10 | class CompactSoaPool : NonCopyable 11 | { 12 | public: 13 | typedef typename Soa::Proxy Proxy; 14 | CompactSoaPool(Scope& a, uint size); 15 | Proxy operator[](uint handle); 16 | void Set( uint handle, const T& tuple ); 17 | void Get( uint handle, T& tuple ) const; 18 | int Alloc(const T& tuple); 19 | int Alloc(); 20 | void Release( int handle ); 21 | void Clear(); 22 | uint Capacity() const { eiASSERT(m_pool.Capacity()==m_data.Length()); return m_pool.Capacity(); } 23 | uint Size() const { return m_map.Size(); } 24 | private: 25 | PoolBase m_pool; 26 | HandleMap m_map; 27 | Soa m_data; 28 | }; 29 | 30 | //------------------------------------------------------------------------------ 31 | #include "soapool.hpp" 32 | //------------------------------------------------------------------------------ 33 | } 34 | //------------------------------------------------------------------------------ -------------------------------------------------------------------------------- /include/eight/core/alloc/soapool.hpp: -------------------------------------------------------------------------------- 1 | 2 | template 3 | CompactSoaPool::CompactSoaPool(Scope& a, uint size) 4 | : m_pool(a,size) 5 | , m_map(a,size) 6 | , m_data(a,size) 7 | { 8 | } 9 | 10 | template 11 | typename CompactSoaPool::Proxy CompactSoaPool::operator[](uint handle) 12 | { 13 | eiDEBUG( m_pool.Dbg_ValidateIndex(handle) ); 14 | uint physical = m_map.ToPhysical(handle); 15 | return m_data[physical]; 16 | } 17 | 18 | template 19 | void CompactSoaPool::Set( uint handle, const T& tuple ) 20 | { 21 | eiDEBUG( m_pool.Dbg_ValidateIndex(handle) ); 22 | uint physical = m_map.ToPhysical(handle); 23 | m_data.Set( physical, tuple ); 24 | } 25 | 26 | template 27 | void CompactSoaPool::Get( uint handle, T& tuple ) const 28 | { 29 | eiDEBUG( m_pool.Dbg_ValidateIndex(handle) ); 30 | uint physical = m_map.ToPhysical(handle); 31 | m_data.Get( physical, tuple ); 32 | } 33 | 34 | template 35 | int CompactSoaPool::Alloc(const T& tuple) 36 | { 37 | int handle = m_pool.Alloc(); 38 | if( handle < 0 ) 39 | return -1; 40 | uint physical = m_map.AllocHandleToPhysical(handle); 41 | m_data.Set( physical, tuple ); 42 | return handle; 43 | } 44 | 45 | template 46 | int CompactSoaPool::Alloc() 47 | { 48 | int handle = m_pool.Alloc(); 49 | if( handle < 0 ) 50 | return -1; 51 | m_map.AllocHandleToPhysical(handle); 52 | return handle; 53 | } 54 | 55 | template 56 | void CompactSoaPool::Release( int handle ) 57 | { 58 | eiDEBUG( m_pool.Dbg_ValidateIndex(handle) ); 59 | m_pool.Release( handle ); 60 | HandleMap::MoveCmd move = m_map.EraseHandle( handle ); 61 | if( move.to != move.from ) 62 | { 63 | T temp; 64 | m_data.Get( move.from, temp ); 65 | m_data.Set( move.to, temp ); 66 | eiDEBUG( memset(&temp, 0xfefefefe, sizeof(T)) ); 67 | eiDEBUG( m_data.Set( move.from, temp ) ); 68 | } 69 | } 70 | 71 | template 72 | void CompactSoaPool::Clear() 73 | { 74 | m_map.Clear(Capacity()); 75 | m_pool.Clear(); 76 | } 77 | -------------------------------------------------------------------------------- /include/eight/core/alloc/stack.h: -------------------------------------------------------------------------------- 1 | //------------------------------------------------------------------------------ 2 | #pragma once 3 | #include 4 | #include 5 | #include 6 | #include "string.h"//for memset 7 | namespace eight { 8 | //------------------------------------------------------------------------------ 9 | 10 | class StackAlloc : public NonCopyable 11 | { 12 | public: 13 | //StackAlloc(); 14 | StackAlloc( void* begin, void* end ); 15 | StackAlloc( void* begin, size_t size ); 16 | //bool Valid() const; 17 | void Clear(); 18 | //bool IsClear() const { return cursor == begin; } 19 | bool Align( uint ); 20 | inline u8* Alloc( size_t required, size_t reserve ); 21 | inline u8* Alloc( size_t size ); 22 | template T* Alloc( ); 23 | template T* Alloc( u32 count ); 24 | void Unwind(const void* p); 25 | const u8* Mark() const; 26 | const u8* Begin() const; 27 | size_t Capacity() const { return (end-begin); } 28 | 29 | void TransferOwnership(const void* from, const void* to) { eiASSERT(from==owner); owner=to; } 30 | const void* Owner() const { return owner; } 31 | private: 32 | u8* begin; 33 | u8* end; 34 | u8* cursor; 35 | const void* owner; 36 | }; 37 | 38 | class StackMeasure : public NonCopyable 39 | { 40 | public: 41 | StackMeasure() : cursor() {} 42 | void Clear(); 43 | void Align( uint );//assumes the base address will also be aligned to this value 44 | inline size_t Alloc( size_t size ); 45 | template size_t Alloc( ); 46 | template size_t Alloc( u32 count ); 47 | size_t Bytes() const { return cursor; } 48 | private: 49 | size_t cursor; 50 | }; 51 | 52 | template struct LocalStack 53 | { 54 | u8 buffer[SIZE]; 55 | StackAlloc stack; 56 | LocalStack(const char* name=0) 57 | : stack(buffer, SIZE) 58 | {} 59 | operator StackAlloc&() { return stack; } 60 | }; 61 | 62 | //------------------------------------------------------------------------------ 63 | #include "stack.hpp" 64 | } // namespace eight 65 | //------------------------------------------------------------------------------ 66 | -------------------------------------------------------------------------------- /include/eight/core/application.h: -------------------------------------------------------------------------------- 1 | //------------------------------------------------------------------------------ 2 | #pragma once 3 | #include 4 | #include 5 | namespace eight { 6 | //------------------------------------------------------------------------------ 7 | 8 | #define eiENTRY_POINT( fn ) \ 9 | int fn( int argc, char** argv ); \ 10 | int main( int argc, char** argv ) \ 11 | { \ 12 | int retVal = 0; \ 13 | bool error = false; \ 14 | eiBEGIN_CATCH_ALL(); \ 15 | retVal = fn( argc, argv ); \ 16 | eiEND_CATCH_ALL(error); \ 17 | eiASSERT( !error ); eiUNUSED( error ); \ 18 | return retVal; \ 19 | } // 20 | 21 | //------------------------------------------------------------------------------ 22 | } // namespace eight 23 | //------------------------------------------------------------------------------ 24 | -------------------------------------------------------------------------------- /include/eight/core/array.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #include 3 | #include 4 | #include 5 | 6 | namespace eight { 7 | class Scope; 8 | 9 | template struct Ptr 10 | { 11 | Ptr(T* data=0) : p(data) {} 12 | operator T*() { return p; } 13 | operator const T*() const { return p; } 14 | T* operator->() { eiASSERT(p); return p; } 15 | const T* operator->() const { eiASSERT(p); return p; } 16 | T& operator *() { eiASSERT(p); return *p; } 17 | const T& operator *() const { eiASSERT(p); return *p; } 18 | operator bool() const { return !!begin; } 19 | private: 20 | T* p; 21 | }; 22 | template struct ArrayPtr 23 | { 24 | ArrayPtr() : begin() { eiDEBUG(dbg_size=0); } 25 | ArrayPtr(Scope& a, uint size) : begin(eiAllocArray(a,T,size)) { eiDEBUG(dbg_size=size); } 26 | ArrayPtr(T* data, uint size) : begin(data) { eiDEBUG(dbg_size=size); } 27 | T& operator[]( uint i ) { eiASSERT(i struct ArrayData 36 | { 37 | uint length; 38 | T* data; 39 | explicit ArrayData( uint length=0 ) 40 | : length(length) 41 | , data(length ? eiNewArray(GlobalHeap, T, length) : 0) 42 | { 43 | } 44 | ArrayData( ArrayData&& o ) 45 | : length(o.length) 46 | , data(o.data) 47 | { 48 | o.length = 0; 49 | o.data = 0; 50 | } 51 | ArrayData( const ArrayData& o ) 52 | : length(0) 53 | , data(0) 54 | { 55 | *this = o; 56 | } 57 | void Consume( ArrayData& o ) 58 | { 59 | Clear(); 60 | length = o.length; 61 | data = o.data; 62 | o.length = 0; 63 | o.data = 0; 64 | } 65 | ArrayData& operator=( const ArrayData& o ) 66 | { 67 | Clear(); 68 | length = o.length; 69 | data = o.length ? eiNewArray(GlobalHeap, T, o.length) : 0; 70 | for( uint i=0; i!=o.length; ++i ) 71 | data[i] = o.data[i]; 72 | return *this; 73 | } 74 | ~ArrayData() 75 | { 76 | eiDeleteArray(GlobalHeap, data, length); 77 | } 78 | void ClearToSize(uint size) 79 | { 80 | Clear(); 81 | if( size ) 82 | { 83 | length = size; 84 | data = eiNewArray(GlobalHeap, T, size); 85 | } 86 | } 87 | void Clear() 88 | { 89 | eiDeleteArray(GlobalHeap, data, length); 90 | data = 0; 91 | length = 0; 92 | } 93 | 94 | T& operator[]( uint i ) { eiASSERT(i struct ReturnType { typedef void type; }; 8 | //template struct ReturnType { typedef T type; }; 9 | 10 | template class StaticHashMap 11 | { 12 | public: 13 | StaticHashMap( Scope& a, uint maxAssets ) : m_data(a.New(maxAssets)), m_capacity(maxAssets), m_size() {} 14 | 15 | struct KeyValue 16 | { 17 | K key; 18 | V value; 19 | }; 20 | V* Find( const K& ) 21 | { 22 | return 0; 23 | } 24 | void Add( const K&, const V& ) 25 | { 26 | } 27 | private: 28 | typedef typename NativeHash::type H; 29 | KeyValue* m_data; 30 | uint m_capacity; 31 | uint m_size; 32 | }; 33 | 34 | //------------------------------------------------------------------------------ 35 | } 36 | //------------------------------------------------------------------------------ -------------------------------------------------------------------------------- /include/eight/core/handlemap.h: -------------------------------------------------------------------------------- 1 | //------------------------------------------------------------------------------ 2 | #pragma once 3 | #include 4 | #include 5 | namespace eight { 6 | //------------------------------------------------------------------------------ 7 | 8 | class HandleMap : NonCopyable 9 | { 10 | public: 11 | HandleMap( Scope& a, uint capacity ); 12 | u16 ToPhysical( uint handle ) const; 13 | u16 ToHandle( uint physical ) const; 14 | u16 AllocHandleToPhysical( u16 handle ); 15 | struct MoveCmd { u16 from; u16 to; }; 16 | MoveCmd EraseHandle( u16 handle ); 17 | void Clear(uint capacity); 18 | uint Size() const { return m_size; } 19 | private: 20 | u16* m_h2p; 21 | u16* m_p2h; 22 | uint m_size; 23 | eiDEBUG( uint dbg_capacity ); 24 | }; 25 | 26 | //------------------------------------------------------------------------------ 27 | #include "handlemap.hpp" 28 | //------------------------------------------------------------------------------ 29 | } // namespace eight 30 | //------------------------------------------------------------------------------ -------------------------------------------------------------------------------- /include/eight/core/handlemap.hpp: -------------------------------------------------------------------------------- 1 | 2 | inline HandleMap::HandleMap( Scope& a, uint capacity ) 3 | : m_h2p( eiAllocArray(a, u16, capacity) ) 4 | , m_p2h( eiAllocArray(a, u16, capacity) ) 5 | eiDEBUG( COMMA dbg_capacity(capacity) ) 6 | { 7 | Clear(capacity); 8 | } 9 | 10 | inline u16 HandleMap::ToPhysical( uint handle ) const 11 | { 12 | eiASSERT( handle < dbg_capacity ); 13 | eiASSERT( handle == m_p2h[m_h2p[handle]] ); 14 | return m_h2p[handle]; 15 | } 16 | 17 | inline u16 HandleMap::ToHandle( uint physical ) const 18 | { 19 | eiASSERT( physical < dbg_capacity ); 20 | eiASSERT( physical == m_h2p[m_p2h[physical]] ); 21 | return m_p2h[physical]; 22 | } 23 | 24 | inline u16 HandleMap::AllocHandleToPhysical( u16 handle ) 25 | { 26 | u16 physical = m_size++; 27 | eiASSERT( m_p2h[physical] == 0xFFFFU ); 28 | eiASSERT( m_h2p[handle] == 0xFFFFU ); 29 | m_p2h[physical] = handle; 30 | m_h2p[handle] = physical; 31 | return physical; 32 | } 33 | 34 | inline HandleMap::MoveCmd HandleMap::EraseHandle( u16 handle ) 35 | { 36 | eiASSERT( m_size && handle != 0xFFFFU ); 37 | u16 physical = m_h2p[handle]; 38 | eiDEBUG( m_h2p[handle] = 0xFFFFU ); 39 | u16 lastPhysical = m_size-1; 40 | --m_size; 41 | u16 handleLast = m_p2h[lastPhysical]; 42 | eiDEBUG( m_p2h[lastPhysical] = 0xFFFFU ); 43 | m_p2h[physical] = handleLast; 44 | m_h2p[handleLast] = physical; 45 | MoveCmd cmd = { lastPhysical, physical }; 46 | return cmd; 47 | } 48 | 49 | inline void HandleMap::Clear(uint capacity) 50 | { 51 | eiASSERT( capacity == dbg_capacity ); 52 | m_size = 0; 53 | eiDEBUG( memset(m_h2p, 0xFFFFFFFF, capacity*sizeof(u16))); 54 | eiDEBUG( memset(m_p2h, 0xFFFFFFFF, capacity*sizeof(u16))); 55 | } -------------------------------------------------------------------------------- /include/eight/core/id.h: -------------------------------------------------------------------------------- 1 | //------------------------------------------------------------------------------ 2 | #pragma once 3 | #include 4 | namespace eight { 5 | //------------------------------------------------------------------------------ 6 | 7 | #define ei4CC(str) \ 8 | ((u32)(u8)(str[0]) | ((u32)(u8)(str[1]) << 8) | \ 9 | ((u32)(u8)(str[2]) << 16) | ((u32)(u8)(str[3]) << 24 )) // 10 | 11 | template 12 | struct PrimitiveWrap 13 | { 14 | typedef T Type; 15 | // explicit PrimitiveWrap( T v=d ) : value(v) {} 16 | PrimitiveWrap() : value() {} 17 | explicit PrimitiveWrap( T v ) : value(v) {} 18 | operator const T&() const { return value; } 19 | operator T&() { return value; } 20 | private: 21 | T value; 22 | }; 23 | 24 | template struct HideIntCastWarnings { typedef T Type; }; 25 | template struct HideIntCastWarnings< PrimitiveWrap > { typedef T Type; }; 26 | 27 | //#ifndef eiBUILD_RETAIL 28 | # define eiTYPEDEF_ID( name ) \ 29 | struct tag_##name; \ 30 | typedef PrimitiveWrap name; // 31 | 32 | #define eiTYPEDEF_ID_U64( name ) \ 33 | struct tag_##name; \ 34 | typedef PrimitiveWrap name; // 35 | 36 | #define eiTYPEDEF_ID_U32( name ) \ 37 | struct tag_##name; \ 38 | typedef PrimitiveWrap name; // 39 | 40 | #define eiTYPEDEF_ID_U16( name ) \ 41 | struct tag_##name; \ 42 | typedef PrimitiveWrap name; // 43 | 44 | #define eiTYPEDEF_ID_U8( name ) \ 45 | struct tag_##name; \ 46 | typedef PrimitiveWrap name; // 47 | 48 | #define eiTYPEDEF_ID_PTR( name ) \ 49 | struct tag_##name; \ 50 | typedef tag_##name* name; // 51 | 52 | // #else 53 | // # define eiTYPEDEF_ID( name ) \ 54 | // typedef uint name; // 55 | // 56 | // # define eiTYPEDEF_PTR( name ) \ 57 | // typedef void* name; // 58 | // #endif 59 | 60 | //------------------------------------------------------------------------------ 61 | } // namespace eight 62 | //------------------------------------------------------------------------------ 63 | -------------------------------------------------------------------------------- /include/eight/core/intrinsics.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | #include 5 | #if defined(eiBUILD_WINDOWS) 6 | # include "intrin.h" 7 | # include "emmintrin.h" 8 | #pragma intrinsic(_BitScanReverse) 9 | #ifdef eiBUILD_X64 10 | #pragma intrinsic(_BitScanReverse64) 11 | #endif 12 | #elif defined(eiBUILD_XBONE) 13 | # include "intrin.h" 14 | # include "nmmintrin.h" 15 | # include "immintrin.h" 16 | #elif defined(eiBUILD_PS4) 17 | # include "x86intrin.h" 18 | #endif 19 | 20 | typedef __m128 m128; 21 | typedef __m128i m128i; 22 | 23 | inline m128i SetZero_m128i() { return _mm_setzero_si128(); } 24 | inline m128i SetOne_m128i() { return _mm_set_epi32(0,0,0,1); } 25 | inline m128i And_m128i(m128i a, m128i b) { return _mm_and_si128(a, b); } 26 | inline m128i Or_m128i(m128i a, m128i b) { return _mm_or_si128(a, b); } 27 | template inline m128i ShiftLeftBytes_m128i(m128i a) { return _mm_slli_si128(a, bytes); } 28 | 29 | template struct Helper_ShiftLeft_m128i { 30 | template static inline m128i go(m128i a) 31 | { 32 | m128i v1; 33 | v1 = _mm_slli_si128(a, 8); 34 | v1 = _mm_slli_epi64(v1, bits - 64); 35 | return v1; 36 | } 37 | }; 38 | template<> struct Helper_ShiftLeft_m128i { 39 | template static inline m128i go(m128i a) 40 | { 41 | m128i v1, v2; 42 | v1 = _mm_slli_epi64(a, bits); 43 | v2 = _mm_slli_si128(a, 8); 44 | v2 = _mm_srli_epi64(v2, 64 - bits); 45 | v1 = _mm_or_si128(v1, v2); 46 | return v1; 47 | } 48 | }; 49 | template inline m128i ShiftLeft_m128i(m128i a) 50 | { 51 | return Helper_ShiftLeft_m128i= 64>::go(a); 52 | } 53 | 54 | 55 | template T Saturate( T f ) 56 | { 57 | return f < 0 ? 0 : (f > 1 ? 1 : f); 58 | } 59 | template T Clamp( T f, T min, T max ) 60 | { 61 | return f < min ? min : (f > max ? max : f); 62 | } 63 | template T SaturateNanSafe( T f ) 64 | { 65 | #if defined(eiBUILD_WINDOWS) 66 | f = _isnan(f) ? (T)0 : f; 67 | #else 68 | f = std::isnan(f) ? (T)0 : f; 69 | #endif 70 | return f < 0 ? 0 : (f > 1 ? 1 : f); 71 | } -------------------------------------------------------------------------------- /include/eight/core/macro.h: -------------------------------------------------------------------------------- 1 | //------------------------------------------------------------------------------ 2 | #pragma once 3 | #include "stddef.h" 4 | //------------------------------------------------------------------------------ 5 | 6 | #ifndef COMMA 7 | #define COMMA , 8 | #endif 9 | 10 | #define eiUNUSED( a ) (void)sizeof((void)(a),1) 11 | 12 | #define eiKiB(x) ( x *1024) 13 | #define eiMiB(x) (eiKiB(x)*1024) 14 | #define eiGiB(x) (eiMiB(x)*1024) 15 | 16 | #define eiLikely( x) !!(x) 17 | #define eiUnlikely(x) !!(x) 18 | 19 | #define eiJOIN_(a, b) a##b 20 | #define eiJOIN(a, b) eiJOIN_(a, b) 21 | 22 | 23 | #define eiOffsetOf(X, Y) offsetof(X, Y) 24 | 25 | #define eiAlignOf(T) __alignof(T) 26 | 27 | #ifdef eiBUILD_64BIT 28 | #define eiMAGIC_POINTER( bytePattern ) \ 29 | ((void*)(ptrdiff_t(bytePattern&0xff) | (ptrdiff_t(bytePattern&0xff)<<8) | (ptrdiff_t(bytePattern&0xff)<<16) | ((bytePattern&0xff)<<24) | (ptrdiff_t(bytePattern&0xff)<<32) | (ptrdiff_t(bytePattern&0xff)<<40) | (ptrdiff_t(bytePattern&0xff)<<48) | (ptrdiff_t(bytePattern&0xff)<<56))) 30 | #else 31 | #define eiMAGIC_POINTER( bytePattern ) \ 32 | ((void*)(ptrdiff_t(bytePattern&0xff) | (ptrdiff_t(bytePattern&0xff)<<8) | (ptrdiff_t(bytePattern&0xff)<<16) | (ptrdiff_t(bytePattern&0xff)<<24))) 33 | #endif -------------------------------------------------------------------------------- /include/eight/core/math/arithmetic.h: -------------------------------------------------------------------------------- 1 | //------------------------------------------------------------------------------ 2 | #pragma once 3 | #include 4 | namespace eight { 5 | //------------------------------------------------------------------------------ 6 | 7 | template T min( T a, T b ) { return a T max( T a, T b ) { return a>b ? a : b; } 9 | template T Min( T a, T b ) { return a T Max( T a, T b ) { return a>b ? a : b; } 11 | 12 | inline int isnan(double x) { return _isnan(x); }; 13 | 14 | inline float Clamp( float x, float min, float max ) { return x < min ? min : (x > max ? max : x); } 15 | inline float Saturate( float x ) { return Clamp(x,0,1); } 16 | inline float SignedSaturate( float x ) { return Clamp(x,-1,1); } 17 | inline float Sign( float x ) { return x>=0?1.0f:-1.0f; } 18 | inline float Lerp(float b, float a, float f) { return a*f + b*(1-f); } 19 | 20 | inline unsigned short ClampFloatToU16( float f ) 21 | { 22 | int i = f < 0 ? 0 23 | : (f > 0xFFFF ? 0xFFFF : (int)f); 24 | return (unsigned short)(i & 0xFFFF); 25 | } 26 | 27 | //------------------------------------------------------------------------------ 28 | } // namespace eight 29 | //------------------------------------------------------------------------------ 30 | -------------------------------------------------------------------------------- /include/eight/core/math/frustum.h: -------------------------------------------------------------------------------- 1 | //------------------------------------------------------------------------------ 2 | #pragma once 3 | #include 4 | namespace eight { 5 | //------------------------------------------------------------------------------ 6 | 7 | struct FrustumPlanes 8 | { 9 | Vec4 planes[6]; 10 | void Extract( const Mat4& viewProjection_ ) 11 | { 12 | Mat4 viewProjection = Transpose(viewProjection_); 13 | 14 | planes[0] = -viewProjection[0] + viewProjection[3];//r 15 | planes[1] = viewProjection[0] + viewProjection[3];//l 16 | planes[2] = -viewProjection[1] + viewProjection[3];//t 17 | planes[3] = viewProjection[1] + viewProjection[3];//b 18 | planes[4] = -viewProjection[2] + viewProjection[3];//f 19 | planes[5] = viewProjection[2] + viewProjection[3];//n 20 | 21 | for( uint i=0; i!=6; ++i ) 22 | planes[i] = -NormalizePlane(planes[i]); 23 | } 24 | bool SphereInFrustum( const Vec4& sphere ) 25 | { 26 | bool inside = true; 27 | for ( uint i = 0; i < 6; i++ ) 28 | { 29 | inside &= ( PlaneDotPoint( planes[i], sphere ) < sphere[3] ); 30 | } 31 | return inside; 32 | } 33 | void Sphere4InFrustum( const Vec4& x, const Vec4& y, const Vec4& z, const Vec4& radius, Vec4i& output ); 34 | /* { 35 | Vec4i inside = {{~0U, ~0U, ~0U, ~0U}}; 36 | for ( uint i = 0; i < 6; i++ ) 37 | { 38 | Vec4 px = {{planes[i][0], planes[i][0], planes[i][0], planes[i][0]}}; 39 | Vec4 py = {{planes[i][1], planes[i][1], planes[i][1], planes[i][1]}}; 40 | Vec4 pz = {{planes[i][2], planes[i][2], planes[i][2], planes[i][2]}}; 41 | Vec4 pw = {{planes[i][3], planes[i][3], planes[i][3], planes[i][3]}}; 42 | Vec4 dots = px * x + py * y + pz * z + pw; 43 | Vec4i cmp = dots < radius; 44 | inside &= cmp; 45 | } 46 | output = inside; 47 | }*/ 48 | }; 49 | 50 | //------------------------------------------------------------------------------ 51 | } // namespace eight 52 | //------------------------------------------------------------------------------ 53 | -------------------------------------------------------------------------------- /include/eight/core/math/half.h: -------------------------------------------------------------------------------- 1 | //------------------------------------------------------------------------------ 2 | #pragma once 3 | #include 4 | namespace eight { 5 | //------------------------------------------------------------------------------ 6 | union FloatBits 7 | { 8 | float m_float; 9 | u32 m_int; 10 | u32 Mantissa() const { return m_int & 0x7fffff; } 11 | u32 Exponent() const { return (m_int >> 23) & 0xff; } 12 | u32 Sign() const { return (m_int >> 31) & 0x1; } 13 | void Mantissa(u32 mantissa) { m_int = ((m_int & ~0x7fffffu) | mantissa); } 14 | void Exponent(u32 exponent) { m_int = ((m_int & ~0x7f800000u) | (exponent << 23)); } 15 | void Sign(u32 sign) { m_int = ((m_int & ~0x80000000u) | (sign << 31)); } 16 | void MantissaExponentSign(u32 mantissa, u32 exponent, u32 sign) 17 | { 18 | m_int = (mantissa | (exponent << 23) | (sign << 31)); 19 | } 20 | }; 21 | union HalfBits 22 | { 23 | u16 m_half; 24 | u32 Mantissa() const { return m_half & 0x3ff; } 25 | u32 Exponent() const { return (m_half >> 10) & 0x1f; } 26 | u32 Sign() const { return (m_half >> 15) & 0x1; } 27 | void Mantissa(u32 mantissa) { m_half = (u16)((m_half & ~0x3ff) | mantissa); } 28 | void Exponent(u32 exponent) { m_half = (u16)((m_half & ~0x7c00) | (exponent << 10)); } 29 | void Sign(u32 sign) { m_half = (u16)((m_half & ~0x8000) | (sign << 15)); } 30 | void MantissaExponentSign(u32 mantissa, u32 exponent, u32 sign) 31 | { 32 | m_half = (u16)(mantissa | (exponent<<10) | (sign<<15)); 33 | } 34 | }; 35 | struct half 36 | { 37 | half() {} 38 | half( const half& h ) : bits(h.bits) {} 39 | explicit half( float f ) { SetFromFloat(f); } 40 | void SetFromFloat( float input ) 41 | { 42 | FloatBits f; 43 | f.m_float = input; 44 | 45 | u32 newSign = f.Sign(); 46 | u32 newMantissa = 0; 47 | u32 newExponent = 0; 48 | u32 mantissa = f.Mantissa(); 49 | u32 exponent = f.Exponent(); 50 | 51 | if(exponent == 0xff)// Handle special cases 52 | { 53 | newExponent = 31; 54 | if(mantissa != 0)// NaN 55 | newMantissa = 1; 56 | } 57 | else if(exponent != 0)// Regular number 58 | { 59 | int unbiasedExponent = exponent - 127; 60 | if(unbiasedExponent < -14)// This maps to a denorm 61 | { 62 | u32 e = (u32) (-14 - unbiasedExponent); // 2 ^ -exponent 63 | if(e < 10) 64 | newMantissa = (0x800000 | mantissa) >> (13 + e); 65 | else if(e == 10) 66 | newMantissa = 1; 67 | } 68 | else if(unbiasedExponent > 15) 69 | { 70 | newExponent = 31; // Map this value to infinity 71 | } 72 | else 73 | { 74 | newMantissa = mantissa >> 13; 75 | newExponent = unbiasedExponent + 15; 76 | } 77 | } 78 | 79 | HalfBits h; 80 | h.MantissaExponentSign(newMantissa, newExponent, newSign); 81 | bits = h.m_half; 82 | } 83 | u16 bits; 84 | }; 85 | 86 | //------------------------------------------------------------------------------ 87 | } // namespace eight 88 | //------------------------------------------------------------------------------ 89 | -------------------------------------------------------------------------------- /include/eight/core/math/matrix.ispc.h: -------------------------------------------------------------------------------- 1 | 2 | #include "eight/core/math/types.ispc.h" 3 | 4 | inline uniform Mat4 Transpose( uniform Mat4 m ) 5 | { 6 | uniform Vec4 temp0 = { m.c[0][0], m.c[1][0], m.c[0][1], m.c[1][1] }; 7 | uniform Vec4 temp1 = { m.c[2][0], m.c[3][0], m.c[2][1], m.c[3][1] }; 8 | uniform Vec4 temp2 = { m.c[0][2], m.c[1][2], m.c[0][3], m.c[1][3] }; 9 | uniform Vec4 temp3 = { m.c[2][2], m.c[3][2], m.c[2][3], m.c[3][3] }; 10 | uniform Mat4 result = {{ 11 | { temp0.x, temp0.y, temp1.x, temp1.y }, 12 | { temp0.z, temp0.w, temp1.z, temp1.w }, 13 | { temp2.x, temp2.y, temp3.x, temp3.y }, 14 | { temp2.z, temp2.w, temp3.z, temp3.w } 15 | }}; 16 | return result; 17 | } 18 | 19 | inline uniform Mat4 FastInverse( uniform Mat4 mat_ ) 20 | { 21 | uniform Mat4 mat = mat_; 22 | uniform Vec4 c3 = mat.c[3]; 23 | uniform Vec4 zero = {0,0,0,0}; 24 | mat.c[3] = zero; 25 | uniform Mat4 result = Transpose(mat); 26 | uniform Vec4 col3 = -( result.c[0] * c3[0] + result.c[1] * c3[1] + result.c[2] * c3[2] ); 27 | col3[3] = 1; 28 | result.c[3] = col3; 29 | return result; 30 | } 31 | 32 | inline uniform Mat4 mul( uniform Mat4 lhs, uniform Mat4 rhs ) 33 | { 34 | uniform Mat4 result; 35 | for (uniform unsigned int j=0; j!=4; j++) 36 | { 37 | foreach ( i = 0 ... 4 ) 38 | { 39 | result.c[j][i] = lhs.c[0][i] * rhs.c[j][0] 40 | + lhs.c[1][i] * rhs.c[j][1] 41 | + lhs.c[2][i] * rhs.c[j][2] 42 | + lhs.c[3][i] * rhs.c[j][3]; 43 | } 44 | } 45 | return result; 46 | } -------------------------------------------------------------------------------- /include/eight/core/math/tmp.h: -------------------------------------------------------------------------------- 1 | //------------------------------------------------------------------------------ 2 | #pragma once 3 | namespace eight { 4 | //------------------------------------------------------------------------------ 5 | 6 | template struct Pow2Down_Try; 7 | template struct Pow2Down_Select 8 | { 9 | const static int value = I-1;//bust, use prev I 10 | }; 11 | template struct Pow2Down_Select 12 | { 13 | const static int value = Pow2Down_Try::value;//valid, try next I 14 | }; 15 | template struct Pow2Down_Try 16 | { 17 | const static int value = Pow2Down_Select< (1< V), V, I >::value;//see if we've bust or not 18 | }; 19 | template struct Pow2Down 20 | { 21 | const static int value = Pow2Down_Try::value;//start at 2^1 and increment the exponent until over V, then back up to previous (good) value 22 | }; 23 | 24 | //------------------------------------------------------------------------------ 25 | } // namespace eight 26 | //------------------------------------------------------------------------------ 27 | -------------------------------------------------------------------------------- /include/eight/core/math/types.ispc.h: -------------------------------------------------------------------------------- 1 | 2 | 3 | typedef float<4> Vec4; 4 | typedef int<4> Vec4i; 5 | 6 | struct Mat4 7 | { 8 | Vec4 c[4];//columns 9 | }; -------------------------------------------------------------------------------- /include/eight/core/noncopyable.h: -------------------------------------------------------------------------------- 1 | //------------------------------------------------------------------------------ 2 | #pragma once 3 | namespace eight { 4 | //------------------------------------------------------------------------------ 5 | 6 | class NonCopyable 7 | { 8 | public: 9 | NonCopyable(){} 10 | private: 11 | NonCopyable( const NonCopyable& ); 12 | NonCopyable& operator=( const NonCopyable& ); 13 | }; 14 | 15 | class NoCreate 16 | { 17 | private: 18 | NoCreate(){} 19 | NoCreate( const NoCreate& ); 20 | NoCreate& operator=( const NoCreate& ); 21 | }; 22 | 23 | //------------------------------------------------------------------------------ 24 | } // namespace eight 25 | //------------------------------------------------------------------------------ 26 | -------------------------------------------------------------------------------- /include/eight/core/os/win32.h: -------------------------------------------------------------------------------- 1 | //------------------------------------------------------------------------------ 2 | #pragma once 3 | 4 | #include 5 | 6 | #define VC_EXTRALEAN 7 | #define WIN32_LEAN_AND_MEAN 8 | #define NOMINMAX 9 | 10 | #ifndef _ASSERT 11 | #define _ASSERT(expr) eiASSERT(expr) 12 | #endif 13 | 14 | #ifndef _ASSERTE 15 | #define _ASSERTE(expr) eiASSERT(expr) 16 | #endif 17 | 18 | //#ifndef _ASSERT_EXPR 19 | //#define _ASSERT_EXPR(expr, expr_str) eiASSERTMSG(expr, expr_str) 20 | //#endif 21 | 22 | #include 23 | 24 | //------------------------------------------------------------------------------ 25 | -------------------------------------------------------------------------------- /include/eight/core/os/win32_undef.h: -------------------------------------------------------------------------------- 1 | //------------------------------------------------------------------------------ 2 | #ifdef far 3 | #undef far 4 | #endif 5 | #ifdef near 6 | #undef near 7 | #endif 8 | #ifdef min 9 | #undef min 10 | #endif 11 | #ifdef max 12 | #undef max 13 | #endif 14 | //------------------------------------------------------------------------------ 15 | -------------------------------------------------------------------------------- /include/eight/core/os/window_impl.h: -------------------------------------------------------------------------------- 1 | //------------------------------------------------------------------------------ 2 | #pragma once 3 | namespace eight { 4 | //------------------------------------------------------------------------------ 5 | 6 | class OsWindow 7 | { 8 | }; 9 | 10 | //------------------------------------------------------------------------------ 11 | } 12 | //------------------------------------------------------------------------------ 13 | -------------------------------------------------------------------------------- /include/eight/core/performance.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #define eiRESTRICT //todo 4 | 5 | 6 | #ifndef eiFORCE_INLINE 7 | # if defined(_MSC_VER) && (_MSC_VER >= 1200) 8 | # define eiFORCE_INLINE __forceinline 9 | # else 10 | # define eiFORCE_INLINE __inline 11 | # endif 12 | #endif -------------------------------------------------------------------------------- /include/eight/core/profiler.h: -------------------------------------------------------------------------------- 1 | //------------------------------------------------------------------------------ 2 | #pragma once 3 | #include 4 | #include 5 | #include 6 | namespace eight { 7 | class Scope; 8 | //------------------------------------------------------------------------------ 9 | 10 | #ifndef eiCPU_PROFILE 11 | # if 1//eiDEBUG_LEVEL > 0 12 | # define eiCPU_PROFILE 1 13 | # else 14 | # define eiCPU_PROFILE 0 15 | # endif 16 | #endif 17 | 18 | #if eiCPU_PROFILE 19 | # define eiProfile( name ) eight::ProfileScope eiJOIN(_cpuScope,__LINE__)(name) 20 | # define eiProfileFunction() eiProfile(__FUNCTION__) 21 | #else 22 | # define eiProfile( name ) 23 | # define eiProfileFunction() 24 | #endif 25 | 26 | bool PushProfileScope(const char* name); 27 | void PopProfileScope(); 28 | struct ProfileScope : NonCopyable 29 | { 30 | ProfileScope(const char* name) 31 | { 32 | b = PushProfileScope(name); 33 | } 34 | ~ProfileScope() 35 | { 36 | if( b ) 37 | PopProfileScope(); 38 | } 39 | private: 40 | bool b; 41 | }; 42 | 43 | void InitProfiler(Scope&, uint maxEvents); 44 | 45 | struct ProfileCallback 46 | { 47 | enum Type 48 | { 49 | Begin, 50 | End, 51 | Marker, 52 | }; 53 | typedef void (FnBeginEvents)(void*, bool disjoint); 54 | typedef void (FnEndEvents)(void*); 55 | typedef void (FnEvent)(void*, int tid, int pid, const char* name, double time, Type); 56 | FnBeginEvents* beginEvents; 57 | FnEndEvents* endEvents; 58 | FnEvent* event; 59 | void* data; 60 | }; 61 | 62 | bool ProfileBegin(); 63 | void ProfileEnd(); 64 | void ProfileEnd(const ProfileCallback&, Scope& a); 65 | 66 | //------------------------------------------------------------------------------ 67 | } // namespace eight 68 | //------------------------------------------------------------------------------ 69 | -------------------------------------------------------------------------------- /include/eight/core/sort/radix.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | #include 5 | 6 | namespace eight { 7 | //------------------------------------------------------------------------------ 8 | template 9 | struct DefaultRadixKey 10 | { 11 | typedef T Type;//the type that the algorithm is actually sorting from 12 | Type operator()( T* in ) const { return *in; }//convert an array element into a key 13 | }; 14 | 15 | #define eiRESTRICT 16 | 17 | template 18 | T* RadixSort( T* eiRESTRICT inputBegin, T* eiRESTRICT bufferBegin, uint size, const FnKey& fnKey ); 19 | 20 | template 21 | T* RadixSort( T* eiRESTRICT inputBegin, T* eiRESTRICT bufferBegin, uint size ); 22 | 23 | //TODO 3x11bit version as well as 4x8bit 24 | 25 | //------------------------------------------------------------------------------ 26 | #include "radix.hpp" 27 | //------------------------------------------------------------------------------ 28 | } 29 | -------------------------------------------------------------------------------- /include/eight/core/sort/radix.hpp: -------------------------------------------------------------------------------- 1 | //------------------------------------------------------------------------------ 2 | template 3 | T* RadixSort( T* eiRESTRICT inputBegin, T* eiRESTRICT bufferBegin, uint size, const FnKey& fnKey ) 4 | { 5 | typedef FnKey::Type Key; 6 | if( size <= 1 ) 7 | return inputBegin; 8 | const uint passes = sizeof( Key ); 9 | uint count[256]; 10 | uint index[256]; 11 | T* buffers[2] = { inputBegin, bufferBegin }; 12 | for( uint pass=0; pass!=passes; ++pass ) 13 | { 14 | T* out = buffers[1]; 15 | T* begin = buffers[0]; 16 | T* end = begin + size; 17 | //Build the histogram 18 | memset( count, 0, 256*sizeof(uint) ); 19 | for( T* it=begin; it!=end; ++it ) 20 | { 21 | Key k = fnKey(it); 22 | const u8& key = *(reinterpret_cast(&k) + pass); 23 | ++count[key]; 24 | } 25 | //Build the partition lookup 26 | index[0] = 0; 27 | for( uint i=1; i!=256; ++i ) 28 | { 29 | index[i] = index[i-1] + count[i-1]; 30 | } 31 | //Perform the sort 32 | for( T* it=begin; it!=end; ++it ) 33 | { 34 | Key k = fnKey(it); 35 | u8& key = *(reinterpret_cast(&k) + pass); 36 | uint idx = index[key]++; 37 | // ASSERT( idx < size ); 38 | out[idx] = *it; 39 | } 40 | //flip buffers for the next pass 41 | T* temp = buffers[0]; buffers[0] = buffers[1]; buffers[1] = temp; 42 | } 43 | return buffers[0]; 44 | } 45 | //------------------------------------------------------------------------------ 46 | template 47 | T* RadixSort( T* eiRESTRICT inputBegin, T* eiRESTRICT bufferBegin, uint size ) 48 | { 49 | return RadixSort( inputBegin, bufferBegin, size, DefaultRadixKey() ); 50 | } 51 | //------------------------------------------------------------------------------ -------------------------------------------------------------------------------- /include/eight/core/sort/search.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | 5 | namespace eight { 6 | //------------------------------------------------------------------------------ 7 | template 8 | I BinarySearch( I begin, I end, const T& value ) 9 | { 10 | begin = std::lower_bound( begin, end, value ); 11 | return (begin!=end && !(value<*begin)) ? begin : end; 12 | } 13 | template 14 | I BinarySearch( I begin, I end, const T& value, F pred ) 15 | { 16 | begin = std::lower_bound( begin, end, value, pred ); 17 | return (begin!=end && !(pred(value,*begin))) ? begin : end; 18 | } 19 | //------------------------------------------------------------------------------ 20 | template 21 | I LinearSearch( I begin, I end, const T& value ) 22 | { 23 | for( I i = begin; i != end; ++i ) 24 | { 25 | if( *i == value ) 26 | return i; 27 | } 28 | return end; 29 | } 30 | template 31 | I LinearSearch( I begin, I end, const T& value, F pred ) 32 | { 33 | for( I i = begin; i != end; ++i ) 34 | { 35 | if( pred(*i,value) ) 36 | return i; 37 | } 38 | return end; 39 | } 40 | //------------------------------------------------------------------------------ 41 | } 42 | //------------------------------------------------------------------------------ 43 | -------------------------------------------------------------------------------- /include/eight/core/test.h: -------------------------------------------------------------------------------- 1 | //------------------------------------------------------------------------------ 2 | #pragma once 3 | namespace eight { 4 | //------------------------------------------------------------------------------ 5 | 6 | bool RunProtected( void(*pfn)(void*), void* arg );//return false if the function crashed 7 | bool RunProtected( void(*pfn)() );//return false if the function crashed 8 | 9 | bool RunUnitTest( const char* name, void(*pfn)(), const char* file, int line, const char* function ); 10 | 11 | void TestFailure( const char* file, int line, const char* function, const char* message, ... ); 12 | 13 | void EnterTest(); 14 | bool ExitTest(); 15 | bool InTest(); 16 | 17 | #define eiTEST(name) \ 18 | void eiTest_##name() // 19 | 20 | #define eiRUN_TEST(name, errorCount) \ 21 | { \ 22 | void eiTest_##name(); \ 23 | if( !RunUnitTest(#name, &eiTest_##name, __FILE__, __LINE__, "eiTest_"#name) ) \ 24 | { \ 25 | ++errorCount; \ 26 | } \ 27 | } // 28 | 29 | void InitCrashHandler(); 30 | 31 | //------------------------------------------------------------------------------ 32 | } // namespace eight 33 | //------------------------------------------------------------------------------ 34 | -------------------------------------------------------------------------------- /include/eight/core/thread/atomic.hpp: -------------------------------------------------------------------------------- 1 | 2 | //extern uint g_defaultSpin; 3 | template void YieldThreadUntil( F& func, uint spin, bool doJobs, bool willFireWakeEvent ) 4 | { 5 | if( func() ) 6 | return; 7 | eiProfile("Yield"); 8 | if( willFireWakeEvent ) 9 | { 10 | BusyWait spinner(doJobs); 11 | while( !spinner.Try(func, spin) ) {} 12 | } 13 | else 14 | { 15 | BusyWait spinner(doJobs); 16 | while( !spinner.Try(func, spin) ) {} 17 | } 18 | } 19 | 20 | struct WaitFor1 21 | { 22 | WaitFor1( const Atomic& a ) : a(a) {} const Atomic& a; 23 | bool operator()() const { return 1 == (s32)a; } 24 | }; 25 | 26 | struct WaitForTrue 27 | { 28 | WaitForTrue( const Atomic& a ) : a(a) {} const Atomic& a; 29 | bool operator()() const { return a!=0; } 30 | }; 31 | struct WaitForNonNull 32 | { 33 | template 34 | WaitForNonNull( const AtomicPtr& a ) : a((AtomicPtr&)a) {} const AtomicPtr& a; 35 | bool operator()() const { return ((const void*)a)!=0; } 36 | }; 37 | 38 | struct WaitForFalse 39 | { 40 | WaitForFalse( const Atomic& a ) : a(a) {} const Atomic& a; 41 | bool operator()() const { return !a; } 42 | }; 43 | 44 | struct WaitForValue 45 | { 46 | WaitForValue( const Atomic& a, s32 v ) : a(a), value(v) {} const Atomic& a; s32 value; 47 | bool operator()() const { return value == (s32)a; } 48 | }; 49 | struct WaitForGreaterEqual 50 | { 51 | WaitForGreaterEqual( const Atomic& a, s32 v ) : a(a), value(v) {} const Atomic& a; s32 value; 52 | bool operator()() const { return (s32)a >= value; } 53 | }; 54 | 55 | struct WaitForTrue64 56 | { 57 | WaitForTrue64( const u64& a ) : a((Atomic64&)a) {} 58 | WaitForTrue64( const s64& a ) : a((Atomic64&)a) {} 59 | WaitForTrue64( const double& a ) : a((Atomic64&)a) {} const Atomic64& a; 60 | bool operator()() const 61 | { 62 | return a!=0; 63 | } 64 | }; -------------------------------------------------------------------------------- /include/eight/core/thread/fifo_mpmc.h: -------------------------------------------------------------------------------- 1 | //------------------------------------------------------------------------------ 2 | #pragma once 3 | #include 4 | #include 5 | #include 6 | #include 7 | #include 8 | #include 9 | namespace eight { 10 | //------------------------------------------------------------------------------ 11 | 12 | template 13 | class FifoMpmc : NonCopyable 14 | { 15 | public: 16 | FifoMpmc( Scope&, uint size );//size must be greater than 1 17 | 18 | T* Push( const T& );//NULL indicates failure. Don't read/write from/to the returned pointer unless you're sure it hasn't yet been popped via external logic... 19 | bool Pop( T& ); 20 | bool Empty() const;//only a hint. Even if you get a false result, someone might have pushed again simultaneously. 21 | 22 | uint Capacity() const { return m_size; } 23 | 24 | T* PeekSC();//not safe with multiple consumers. Only use in a MPSC/SPSC setting. 25 | bool Peek( T*&, uint ahead=0 );//not entirely safe, as value may be concurrently popped. User must use appropriate lifetime management. 26 | private: 27 | FifoMpmc(); 28 | struct Node 29 | { 30 | Atomic state; 31 | T data; 32 | }; 33 | Atomic m_read; 34 | u64 pad1[7]; 35 | Node* m_data; 36 | const uint m_size; 37 | u32 Next( u32 ); 38 | u64 pad2[7]; 39 | Atomic m_write; 40 | u64 pad3[7]; 41 | 42 | const static u32 freeForWrite = 0; 43 | const static u32 allocForWrite = 1; 44 | const static u32 freeForRead = 2; 45 | const static u32 allocForRead = 3; 46 | const static u32 stateMask = 3; 47 | const static u32 abaShift = 2; 48 | }; 49 | 50 | #include "fifo_mpmc.hpp" 51 | 52 | //------------------------------------------------------------------------------ 53 | } // namespace eight 54 | //------------------------------------------------------------------------------ 55 | -------------------------------------------------------------------------------- /include/eight/core/thread/fifo_spsc.h: -------------------------------------------------------------------------------- 1 | //------------------------------------------------------------------------------ 2 | #pragma once 3 | #include 4 | #include 5 | #include 6 | #include 7 | #include 8 | #include 9 | namespace eight { 10 | //------------------------------------------------------------------------------ 11 | 12 | template 13 | class FifoSpsc : NonCopyable 14 | { 15 | public: 16 | FifoSpsc( Scope&, uint size );//size must be greater than 1 17 | 18 | bool Push( const T& ); 19 | bool Pop( T& ); 20 | private: 21 | FifoSpsc(); 22 | T* m_data; 23 | const uint m_size; 24 | u32 Next( u32 ); 25 | Atomic m_read, m_write; 26 | }; 27 | 28 | #include "fifo_spsc.hpp" 29 | 30 | //------------------------------------------------------------------------------ 31 | } // namespace eight 32 | //------------------------------------------------------------------------------ 33 | -------------------------------------------------------------------------------- /include/eight/core/thread/fifo_spsc.hpp: -------------------------------------------------------------------------------- 1 | 2 | template 3 | FifoSpsc::FifoSpsc( Scope& a, uint size ) : m_data(eiNewArray(a,T,size)), m_size(size) 4 | { 5 | eiASSERT( size > 1 ); 6 | } 7 | 8 | template 9 | u32 FifoSpsc::Next( u32 index ) 10 | { 11 | ++index; 12 | return index >= m_size ? 0 : index; 13 | } 14 | 15 | template 16 | bool FifoSpsc::Push( const T& value ) 17 | { 18 | u32 read = m_read; 19 | u32 write = m_write; 20 | u32 nextWrite = Next(write); 21 | if( nextWrite == read ) 22 | return false; 23 | m_data[write] = value; 24 | m_write = nextWrite; 25 | return true; 26 | } 27 | 28 | template 29 | bool FifoSpsc::Pop( T& value ) 30 | { 31 | u32 read = m_read; 32 | u32 write = m_write; 33 | if( read == write ) 34 | return false; 35 | value = m_data[read]; 36 | m_read = Next( read ); 37 | return true; 38 | } 39 | -------------------------------------------------------------------------------- /include/eight/core/thread/futex.h: -------------------------------------------------------------------------------- 1 | //------------------------------------------------------------------------------ 2 | #pragma once 3 | #include 4 | #include 5 | #include 6 | #include 7 | namespace eight { 8 | //------------------------------------------------------------------------------ 9 | 10 | template 11 | class ScopeLock : NonCopyable 12 | { 13 | public: 14 | ScopeLock(T& l, bool doJobs=true) : mutex(l) { mutex.Lock(doJobs); } 15 | ~ScopeLock() { mutex.Unlock(); } 16 | private: 17 | T& mutex; 18 | }; 19 | 20 | class Futex : NonCopyable 21 | { 22 | public: 23 | void Lock(bool doJobs=true); 24 | bool TryLock(); 25 | void Unlock(); 26 | 27 | eiDEBUG( ~Futex() { eiASSERT(value==0); } ) 28 | private: 29 | Atomic value; 30 | }; 31 | 32 | 33 | inline void Futex::Lock(bool doJobs) 34 | { 35 | //eiProfile("Futex::Lock"); 36 | struct TryLock { TryLock( Futex* self ) : self(self) {} Futex* self; 37 | bool operator()() 38 | { 39 | return self->TryLock(); 40 | } 41 | }; 42 | YieldThreadUntil( TryLock(this), 0, doJobs ); 43 | } 44 | 45 | inline bool Futex::TryLock() 46 | { 47 | return value.SetIfEqual(1,0); 48 | } 49 | 50 | inline void Futex::Unlock() 51 | { 52 | eiASSERT( value == 1 ); 53 | value = 0; 54 | } 55 | 56 | //------------------------------------------------------------------------------ 57 | } // namespace eight 58 | //------------------------------------------------------------------------------ 59 | -------------------------------------------------------------------------------- /include/eight/core/thread/gate.h: -------------------------------------------------------------------------------- 1 | //------------------------------------------------------------------------------ 2 | #pragma once 3 | #include 4 | #include 5 | #include 6 | namespace eight { 7 | //------------------------------------------------------------------------------ 8 | 9 | class Gate 10 | { 11 | public: 12 | Gate( TaskSection& wait ) : wait(&wait) {} 13 | void PassGate() 14 | { 15 | BusyWait spinner; 16 | if( 1 != gate )//if gate not open 17 | { 18 | do 19 | { 20 | if( gate.SetIfEqual(-1,0) )//try move from closed to locked 21 | { 22 | u32 setTo; 23 | if( internal::IsTaskSectionDone(*wait) ) 24 | setTo = 1;//move from locked to open 25 | else 26 | setTo = 0;//move from locked to closed 27 | eiDEBUG( bool ok = (gate.SetIfEqual(setTo,-1)) ); 28 | eiASSERT( ok ); 29 | eiDEBUG( if( !ok ) ) 30 | gate = setTo; 31 | } 32 | } while( !spinner.Try(WaitFor1(gate)) );//while gate not open 33 | } 34 | passed++; 35 | } 36 | private: 37 | Atomic gate; 38 | Atomic passed; 39 | TaskSection* wait; 40 | }; 41 | 42 | 43 | //------------------------------------------------------------------------------ 44 | //#include ".hpp" 45 | } // namespace eight 46 | //------------------------------------------------------------------------------ 47 | -------------------------------------------------------------------------------- /include/eight/core/thread/jobqueue.h: -------------------------------------------------------------------------------- 1 | //------------------------------------------------------------------------------ 2 | #pragma once 3 | #include 4 | namespace eight { 5 | //------------------------------------------------------------------------------ 6 | class Scope; 7 | 8 | //------------------------------------------------------------------------------ 9 | } // namespace eight 10 | //------------------------------------------------------------------------------ 11 | -------------------------------------------------------------------------------- /include/eight/core/thread/latent.h: -------------------------------------------------------------------------------- 1 | //------------------------------------------------------------------------------ 2 | #pragma once 3 | namespace eight { 4 | //------------------------------------------------------------------------------ 5 | 6 | namespace ConcurrentFrames 7 | { 8 | enum Type 9 | { 10 | OneFrame = 1, 11 | TwoFrames = 2, 12 | ThreeFrames = 3, 13 | }; 14 | } 15 | 16 | //------------------------------------------------------------------------------ 17 | } // namespace eight 18 | //------------------------------------------------------------------------------ 19 | -------------------------------------------------------------------------------- /include/eight/core/thread/pool.h: -------------------------------------------------------------------------------- 1 | //------------------------------------------------------------------------------ 2 | #pragma once 3 | #include "eight/core/types.h" 4 | #include "eight/core/noncopyable.h" 5 | namespace eight { 6 | //------------------------------------------------------------------------------ 7 | class Scope; 8 | class Atomic; 9 | class JobPool; 10 | 11 | class ThreadId : NoCreate 12 | { 13 | public: 14 | u32 ThreadIndex() const; 15 | u32 NumThreadsInPool() const; 16 | JobPool& Jobs() const; 17 | u32 PoolId() const; 18 | }; 19 | 20 | typedef int(FnPoolThreadEntry)( void* arg, ThreadId&, uint systemId ); 21 | 22 | JobPool* StartBackgroundThreadPool( Scope&, FnPoolThreadEntry*, void* arg, int numWorkers=0, Atomic* runningCount=0 ); 23 | void StartThreadPool( Scope&, FnPoolThreadEntry*, void* arg, int numWorkers=0, Atomic* runningCount=0 ); 24 | 25 | class JobPool : NoCreate 26 | { 27 | public: 28 | typedef void (FnJob)( void*, ThreadId& ); 29 | struct Job 30 | { 31 | FnJob* fn; 32 | void* arg; 33 | }; 34 | struct JobList 35 | { 36 | Job* jobs; 37 | uint numJobs; 38 | Atomic* nextToExecute; 39 | }; 40 | void PushJob( Job ); 41 | void PushJob( Job, ThreadId& ); 42 | void PushJobList( JobList, ThreadId& ); 43 | bool RunJob( ThreadId& ); 44 | 45 | bool WaitForWakeEvent(); 46 | void FireWakeEvent(uint threadCount); 47 | 48 | u32 Id() const; 49 | }; 50 | 51 | bool InPool(); 52 | ThreadId* GetThreadId(); 53 | uint GetOsThreadId(); 54 | 55 | /* 56 | struct PoolThread 57 | { 58 | u32 mask; 59 | u32 index; 60 | u32 poolSize; 61 | u32 poolMask; 62 | }; 63 | bool InPool(); 64 | PoolThread CurrentPoolThread(); 65 | uint CurrentPoolSize(); 66 | 67 | struct JobPoolThread 68 | { 69 | JobPool* jobs; 70 | uint threadIndex; 71 | uint threadCount; 72 | }; 73 | JobPoolThread CurrentJobPool();*/ 74 | 75 | //------------------------------------------------------------------------------ 76 | } // namespace eight 77 | //------------------------------------------------------------------------------ -------------------------------------------------------------------------------- /include/eight/core/thread/thread.h: -------------------------------------------------------------------------------- 1 | //------------------------------------------------------------------------------ 2 | #pragma once 3 | #include 4 | #include 5 | namespace eight { 6 | //------------------------------------------------------------------------------ 7 | class Scope; 8 | 9 | uint NumberOfHardwareThreads(); 10 | uint NumberOfPhysicalCores(Scope& temp); 11 | 12 | typedef int(*ThreadEntry)(void*, int systemId); 13 | 14 | class Thread : NonCopyable 15 | { 16 | public: 17 | Thread(Scope&, ThreadEntry, void* arg); 18 | ~Thread(); 19 | private: 20 | void* pimpl; 21 | }; 22 | 23 | //------------------------------------------------------------------------------ 24 | } // namespace eight 25 | //------------------------------------------------------------------------------ 26 | -------------------------------------------------------------------------------- /include/eight/core/thread/threadlocal.h: -------------------------------------------------------------------------------- 1 | //------------------------------------------------------------------------------ 2 | #pragma once 3 | #include "eight/core/debug.h" 4 | #include "eight/core/types.h" 5 | #include "eight/core/noncopyable.h" 6 | #include "eight/core/thread/atomic.h" 7 | namespace eight { 8 | //------------------------------------------------------------------------------ 9 | 10 | #define eiBUILD_NO_STATIC_TLS 11 | #if defined(eiBUILD_MSVC) 12 | # define eiDYNAMIC_TLS_TYPE( T ) u32 13 | # define eiSTATIC_TLS_TYPE( T ) __declspec(thread) T 14 | #elif defined(eiBUILD_GCC) 15 | # error "GCC port not complete" 16 | # define eiSTATIC_TLS_TYPE( T ) __thread T 17 | #else 18 | # error "TLS not ported to this compiler" 19 | #endif 20 | 21 | #if defined(eiBUILD_NO_STATIC_TLS) 22 | # undef eiSTATIC_TLS_TYPE 23 | # define eiSTATIC_TLS_TYPE( T ) ThreadLocal 24 | #endif 25 | 26 | u32 TlsAlloc(); 27 | void TlsFree( u32 index ); 28 | void* TlsGet( u32 index ); 29 | void TlsSet( u32 index, void* value ); 30 | 31 | template 32 | class ThreadLocal : NonCopyable 33 | { 34 | public: 35 | ThreadLocal() : index(eight::TlsAlloc()) {} 36 | ~ThreadLocal() { eight::TlsFree( index ); } 37 | operator T*() { return (T*)eight::TlsGet( index ); } 38 | operator const T*() const { return (T*)eight::TlsGet( index ); } 39 | T& operator*() { return *(T*)eight::TlsGet( index ); } 40 | T* operator->() { return (T*)eight::TlsGet( index ); } 41 | ThreadLocal& operator=( T* p ) { return eight::TlsSet( index, p ), *this; } 42 | ThreadLocal& operator=( const T* p ) { return eight::TlsSet( index, p ), *this; } 43 | private: 44 | u32 index; 45 | }; 46 | 47 | template 48 | class ThreadLocalStatic 49 | { 50 | public: 51 | ThreadLocalStatic& operator=( T* t ) { return (data = t), *this; } 52 | ThreadLocalStatic& operator=( const T* t ) { return (data = t), *this; } 53 | operator const T*() const { return data; } 54 | operator T*() { return data; } 55 | T* operator->() { return data; } 56 | T& operator*() { return *data; } 57 | private: 58 | static eiSTATIC_TLS_TYPE(T) data; 59 | }; 60 | template eiSTATIC_TLS_TYPE(T) ThreadLocalStatic::data; 61 | 62 | //------------------------------------------------------------------------------ 63 | } // namespace eight 64 | //------------------------------------------------------------------------------ -------------------------------------------------------------------------------- /include/eight/core/throw.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #include 3 | 4 | #ifdef _HAS_EXCEPTIONS 5 | # if _HAS_EXCEPTIONS==0 && defined(eiBUILD_EXCEPTIONS) 6 | # pragma message("Warning: eiBUILD_EXCEPTIONS was defined with _HAS_EXCEPTIONS==0") 7 | # undef eiBUILD_EXCEPTIONS 8 | # endif 9 | #endif 10 | 11 | #ifdef eiBUILD_EXCEPTIONS 12 | # define eiTHROW( a ) throw a 13 | # define eiBEGIN_CATCH_ALL() try{ 14 | # define eiEND_CATCH_ALL(out) }catch(...){out = true;} 15 | #else 16 | # define eiTHROW( a ) eiASSERT( false && #a ) 17 | # define eiBEGIN_CATCH_ALL() 18 | # define eiEND_CATCH_ALL(out) 19 | #endif -------------------------------------------------------------------------------- /include/eight/core/timer/timer.h: -------------------------------------------------------------------------------- 1 | //------------------------------------------------------------------------------ 2 | #pragma once 3 | #include 4 | #include 5 | #include 6 | namespace eight { 7 | //------------------------------------------------------------------------------ 8 | class Scope; 9 | 10 | class Timer : Interface 11 | { 12 | public: 13 | Timer(); 14 | void Reset(); 15 | double Elapsed() const; 16 | double Elapsed(bool reset = false); 17 | private: 18 | ~Timer(); 19 | }; 20 | 21 | //------------------------------------------------------------------------------ 22 | } // namespace eight 23 | //------------------------------------------------------------------------------ 24 | -------------------------------------------------------------------------------- /include/eight/core/typeinfo.h: -------------------------------------------------------------------------------- 1 | //------------------------------------------------------------------------------ 2 | #pragma once 3 | #include 4 | #include 5 | namespace eight { 6 | //------------------------------------------------------------------------------ 7 | 8 | template 9 | struct TypeNameGetter 10 | { 11 | static const char* Get() 12 | { 13 | const char* fn = __FUNCTION__; 14 | const char* fn2 = typeid(T).name(); 15 | //std::find(); 16 | return fn2; 17 | } 18 | }; 19 | 20 | template 21 | struct TypeName 22 | { 23 | static void Get(const char*& begin, const char*& end) 24 | { 25 | begin = __FUNCTION__; 26 | for(++begin; *begin && *(begin-1) != '<'; ++ begin); 27 | for(end = begin; *end; ++ end); 28 | for(; end > begin && *end != '>'; -- end); 29 | } 30 | static const char* Get(Scope& a) 31 | { 32 | const char* begin=0, *end=0; 33 | Get(begin, end); 34 | uint length = end-begin; 35 | char* buf = (char*)a.Alloc(length+1); 36 | memcpy(buf, begin, length); 37 | buf[length] = 0; 38 | return buf; 39 | } 40 | static void Get(char* buf, uint bufLen) 41 | { 42 | const char* begin=0, *end=0; 43 | Get(begin, end); 44 | uint length = (uint)(end-begin); 45 | eiASSERT( length+1 <= bufLen ); 46 | memcpy(buf, begin, length); 47 | buf[length] = 0; 48 | } 49 | static const char* Get() 50 | { 51 | static const char* value = 0; 52 | if( !value ) 53 | { 54 | static char buffer[256]; 55 | Get(buffer, 256); 56 | //todo - memory fence 57 | value = buffer; 58 | } 59 | return value; 60 | } 61 | }; 62 | 63 | template 64 | struct TypeHash 65 | { 66 | static u32 Get_() 67 | { 68 | const char* begin; 69 | const char* end; 70 | TypeName::Get(begin, end); 71 | return Fnv32a(begin, end); 72 | } 73 | static u32 Get() 74 | { 75 | static const u32 value = Get_(); 76 | return value; 77 | } 78 | }; 79 | /* 80 | inline void test_typename() 81 | { 82 | const char* name = TypeNameGetter>::Get(); 83 | const char* name2 = TypeName>::Get(); 84 | const char* name3 = TypeNameGetter::Get(); 85 | } 86 | */ 87 | //------------------------------------------------------------------------------ 88 | } // namespace eight 89 | //------------------------------------------------------------------------------ 90 | -------------------------------------------------------------------------------- /include/eight/core/types.h: -------------------------------------------------------------------------------- 1 | //------------------------------------------------------------------------------ 2 | #pragma once 3 | namespace eight { 4 | //------------------------------------------------------------------------------ 5 | 6 | typedef long long int64; 7 | typedef unsigned long long uint64; 8 | typedef unsigned long ulong; 9 | typedef int int32; 10 | typedef unsigned int uint; 11 | typedef unsigned int uint32; 12 | typedef short int16; 13 | typedef unsigned short ushort; 14 | typedef unsigned short uint16; 15 | typedef char int8; 16 | typedef unsigned char uint8; 17 | typedef int8 byte; 18 | typedef uint8 ubyte; 19 | 20 | typedef int64 s64; 21 | typedef uint64 u64; 22 | typedef int32 s32; 23 | typedef uint32 u32; 24 | typedef int16 s16; 25 | typedef uint16 u16; 26 | typedef int8 s8; 27 | typedef uint8 u8; 28 | 29 | class class_ {}; 30 | typedef char class_::* memptr; 31 | typedef void (class_::*memfuncptr)(void*); 32 | typedef void (*callback)(void*); 33 | 34 | typedef u8 sizeone[1]; 35 | typedef u8 sizetwo[2]; 36 | 37 | //template uint eiArraySize(T(&)[N]) { return N; } //TODO - move 38 | 39 | template struct Sizer { char elems[N]; }; 40 | template Sizer ArraySize_( Type(&)[N] ); 41 | 42 | #define eiArraySize( a ) sizeof( ArraySize_( a ).elems ) 43 | 44 | 45 | struct Nil 46 | { 47 | operator void() {} 48 | bool operator==( const Nil& ) { return true; } 49 | }; 50 | const static Nil nil; 51 | 52 | template struct Maybe 53 | { 54 | Maybe( const T& v ) : value(v), initialized(true) {} 55 | Maybe( const Nil& ) : initialized(false) {} 56 | Maybe() : initialized(false) {} 57 | union 58 | { 59 | Nil nil; 60 | T value; 61 | }; 62 | bool initialized; 63 | }; 64 | 65 | #define eiPTR_TO_U64( x ) ((u64)(intptr_t)(void*)(x)) 66 | #define eiINTPTR_TO_PTR( x ) ((void*)((intptr_t)x)) 67 | 68 | //------------------------------------------------------------------------------ 69 | } // namespace eight 70 | //------------------------------------------------------------------------------ 71 | -------------------------------------------------------------------------------- /include/eight/core/variablestream.h: -------------------------------------------------------------------------------- 1 | //------------------------------------------------------------------------------ 2 | #pragma once 3 | #include 4 | namespace eight { 5 | //------------------------------------------------------------------------------ 6 | 7 | namespace core { 8 | 9 | template class TByteStream; 10 | typedef TByteStream CByteStream; 11 | //DECLARE_TEST( VariableStream ) 12 | 13 | class CVariableStream 14 | { 15 | public: 16 | CVariableStream( CByteStream& ); 17 | void ReadGroupStart(); 18 | void ReadGroupEnd(); 19 | void WriteGroupStart(); 20 | void WriteGroupEnd(); 21 | 22 | template bool Read ( uint id, T& d ); 23 | template void Write( uint id, const T& d ); 24 | template void NullWrite( uint id ); 25 | 26 | uint Size() const { return m_Data.Size(); } 27 | private: 28 | const static uint sm_NotYetRead = UINT_MAX; 29 | uint m_NextId; 30 | CByteStream& m_Data; 31 | }; 32 | 33 | //------------------------------------------------------------------------------ 34 | #include "variablestream.hpp" 35 | } // namespace eight 36 | //------------------------------------------------------------------------------ 37 | -------------------------------------------------------------------------------- /include/eight/core/variablestream.hpp: -------------------------------------------------------------------------------- 1 | //------------------------------------------------------------------------------ 2 | //------------------------------------------------------------------------------ 3 | inline CVariableStream::CVariableStream( CByteStream& data ) : m_Data(data) 4 | { 5 | DEBUG( m_NextId = 0; ) 6 | //TODO - add debug checks to ensure that all read/writes are surrounded by group start/end calls 7 | } 8 | //------------------------------------------------------------------------------ 9 | inline void CVariableStream::ReadGroupStart() 10 | { 11 | ASSERT( m_NextId == 0 ) 12 | m_NextId = sm_NotYetRead; 13 | } 14 | //------------------------------------------------------------------------------ 15 | inline void CVariableStream::ReadGroupEnd() 16 | { 17 | //if the termination marker hasn't yet been read, make sure to remove it from the stream now 18 | if( m_NextId != 0 ) 19 | { 20 | m_Data >> m_NextId; 21 | ASSERT( m_NextId == 0 ) 22 | } 23 | } 24 | //------------------------------------------------------------------------------ 25 | inline void CVariableStream::WriteGroupStart() 26 | { 27 | } 28 | //------------------------------------------------------------------------------ 29 | inline void CVariableStream::WriteGroupEnd() 30 | { 31 | //put a termination marker into the stream 32 | m_Data << uint(0); 33 | } 34 | //------------------------------------------------------------------------------ 35 | //------------------------------------------------------------------------------ 36 | template bool CVariableStream::Read( uint id, T& d ) 37 | { 38 | if( m_NextId == sm_NotYetRead ) 39 | m_Data >> m_NextId; 40 | ASSERT( m_NextId == 0 || m_NextId >= id+1 ) 41 | if( m_NextId == id+1 ) 42 | { 43 | m_Data >> d; 44 | m_NextId = sm_NotYetRead; 45 | return true; 46 | } 47 | else 48 | return false; 49 | } 50 | //------------------------------------------------------------------------------ 51 | template void CVariableStream::Write( uint id, const T& d ) 52 | { 53 | m_Data << id+1; 54 | m_Data << d; 55 | } 56 | //------------------------------------------------------------------------------ 57 | template void CVariableStream::NullWrite( uint id ) 58 | { 59 | } 60 | //------------------------------------------------------------------------------ 61 | //------------------------------------------------------------------------------ 62 | -------------------------------------------------------------------------------- /include/eight/core/win/os.h: -------------------------------------------------------------------------------- 1 | #include "eight/core.h" 2 | 3 | #if defined(_DEBUG) 4 | #include //TODO - for memory leak detection 5 | #endif -------------------------------------------------------------------------------- /include/eight/lua/lua_api.h: -------------------------------------------------------------------------------- 1 | //------------------------------------------------------------------------------ 2 | #pragma once 3 | #include 4 | #include 5 | extern "C" 6 | { 7 | # include 8 | # include 9 | # include 10 | } 11 | 12 | namespace eight { 13 | #if eiDEBUG_LEVEL > 1 14 | # define eiCheckLuaStack(L) eight::LuaStackBalanceCheck_ luaStackCheck##__LINE__(L) 15 | class LuaStackBalanceCheck_ : NonCopyable 16 | { 17 | public: 18 | LuaStackBalanceCheck_(lua_State* L) : L(L), mark(lua_gettop(L)) { eiASSERT(L); } 19 | ~LuaStackBalanceCheck_() { int newMark = lua_gettop(L); eiASSERT(newMark == mark); } 20 | private: 21 | lua_State* L; 22 | int mark; 23 | }; 24 | #else 25 | # define eiCheckLuaStack(L) do{}while(0) 26 | #endif 27 | } 28 | //------------------------------------------------------------------------------ 29 | -------------------------------------------------------------------------------- /src/core/align.cpp: -------------------------------------------------------------------------------- 1 | //------------------------------------------------------------------------------ 2 | #include 3 | #include 4 | using namespace eight; 5 | //------------------------------------------------------------------------------ 6 | 7 | void TodoUnitTest() 8 | { 9 | eiSTATIC_ASSERT( sizeof( int ) == 4 ) 10 | eiSTATIC_ASSERT( sizeof( AtomicAligned ) == 16 ) 11 | eiSTATIC_ASSERT( sizeof( AtomicAligned ) == 16 ) 12 | eiSTATIC_ASSERT( sizeof( AtomicAligned ) == 32 ) 13 | eiSTATIC_ASSERT( sizeof( AtomicAligned ) == 32 ) 14 | /* struct 15 | { 16 | char c; 17 | AtomicAligned a; 18 | }; stuff;*/ 19 | } -------------------------------------------------------------------------------- /src/core/bind.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include 5 | #include 6 | #include 7 | #include 8 | #include 9 | 10 | using namespace eight; 11 | 12 | /**//**//**//**//**//**//**//**//**//**//**//**//**//**//**//**//**//**/ 13 | /**//**//**//**//**//**//**//**//**//**//**//**//**//**//**//**//**//**/ 14 | 15 | namespace { 16 | class Test1 17 | { 18 | public: 19 | eiBind(Test1); 20 | int DoStuff(int, Test1*, const char*) { return 0; } 21 | void FooBar(int*, const float*) { } 22 | private: 23 | int m_stuff; 24 | }; 25 | struct Test2 {}; 26 | } 27 | 28 | eiBindClass( Test1 ) 29 | eiLuaBind( LuaCall ) 30 | eiBeginMethods() 31 | eiBindMethod( DoStuff ) 32 | eiEndMethods() 33 | eiBeginData() 34 | eiBindData( m_stuff ) 35 | eiEndData() 36 | eiEndBind(); 37 | 38 | eiBindStruct( Test2 ); 39 | eiEndBind(); 40 | 41 | 42 | eiTEST( Bind ) 43 | { 44 | const TypeBinding& a = ReflectTest2(); 45 | const TypeBinding& b = ReflectTest1(); 46 | 47 | Test1 t; 48 | char buf[1024]; 49 | StackAlloc s(buf,1024); 50 | 51 | 52 | eiASSERT( 0==strcmp(b.method[0].name,"DoStuff") ); 53 | (t.*((int(Test1::*)(int, Test1*, const char*))b.method[0].memfuncptr))(42, NULL, "foo"); 54 | (void)(b.dataCount + a.dataCount); 55 | } 56 | /**//**//**//**//**//**//**//**//**//**//**//**//**//**//**//**//**//**/ 57 | -------------------------------------------------------------------------------- /src/core/core_test.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | eiENTRY_POINT( test_main ) 5 | int test_main( int argc, char** argv ) 6 | { 7 | return 0; 8 | } 9 | -------------------------------------------------------------------------------- /src/core/thread/fifo_mpmc.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include 5 | #include 6 | #include 7 | 8 | using namespace eight; 9 | 10 | namespace { 11 | 12 | struct TestData 13 | { 14 | FifoMpmc* queue; 15 | Atomic result; 16 | Atomic numInvoked; 17 | Atomic invoked[16]; 18 | }; 19 | 20 | //const static int loops = 0x7fffffff/1600; 21 | const static int loops = 0x1000; 22 | const static int loopTotal = 0; 23 | const static int s_numThreads = 4; 24 | 25 | int ThreadEntry( void* arg, ThreadId& thread, uint systemId ) 26 | { 27 | const uint threadIndex = thread.ThreadIndex(); 28 | const uint numThreads = thread.NumThreadsInPool(); 29 | TestData& data = *(TestData*)arg; 30 | FifoMpmc& queue = *data.queue; 31 | 32 | eiASSERT( threadIndex >= 0 && threadIndex < s_numThreads ); 33 | eiASSERT( numThreads > 0 && numThreads <= s_numThreads ); 34 | data.invoked[threadIndex] = 1; 35 | ++data.numInvoked; 36 | 37 | const int testSize = 6; 38 | int testData[testSize] = { 1, -1, 900, 42, -900, -42 }; 39 | 40 | int total = 0; 41 | 42 | int popped; 43 | for( int i=0 ; i < loops; ++i ) 44 | { 45 | for( int j=0 ; j != testSize; ++j ) 46 | { 47 | while( !queue.Push(testData[j] ) ) 48 | { 49 | if( queue.Pop(popped) ) 50 | { 51 | total += popped; 52 | } 53 | } 54 | } 55 | } 56 | 57 | for( int i=0 ; i < 0xff; ++i ) 58 | while( queue.Pop(popped) ) 59 | { 60 | total += popped; 61 | } 62 | 63 | data.result += total; 64 | 65 | return 0; 66 | } 67 | 68 | }//end namespace 69 | 70 | eiTEST(FifoMpmc) 71 | { 72 | MallocStack buffer( 1024000 ); 73 | Scope a( buffer.stack, "test1" ); 74 | FifoMpmc queue( a, 100 ); 75 | for( int i =0; i<1/*0000*/; ++i ) 76 | { 77 | // printf( "attempt #%d\n", i ); 78 | 79 | TestData data = { &queue, Atomic(42) }; 80 | 81 | { 82 | Scope b( a, "test2" ); 83 | StartThreadPool( b, &ThreadEntry, &data, s_numThreads ); 84 | } 85 | 86 | eiRASSERT( data.numInvoked == s_numThreads ); 87 | for( int i=0; i!=s_numThreads; ++i ) 88 | { 89 | eiRASSERT( data.invoked[i] == 1 ); 90 | } 91 | 92 | eiRASSERT( queue.Empty() ); 93 | eiRASSERT( data.result == 42 + loops * loopTotal * s_numThreads ); 94 | } 95 | } -------------------------------------------------------------------------------- /src/core/thread/fifo_spsc.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include 5 | #include 6 | 7 | using namespace eight; 8 | 9 | eiTEST(FifoSpsc) 10 | { 11 | void* buffer = alloca( 1024 ); 12 | StackAlloc stack( buffer, 1024 ); 13 | Scope a( stack, "test" ); 14 | 15 | bool ok; 16 | FifoSpsc queue( a, 4 ); 17 | ok = queue.Push( 42 ); 18 | eiRASSERT( ok ); 19 | int fourtyTwo; 20 | ok = queue.Pop( fourtyTwo ); 21 | eiRASSERT( ok ); 22 | eiRASSERT( fourtyTwo == 42 ); 23 | } -------------------------------------------------------------------------------- /src/core/thread/futex.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | using namespace eight; 4 | -------------------------------------------------------------------------------- /src/core/thread/jobqueue.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include 5 | 6 | using namespace eight; 7 | 8 | #include 9 | struct Job { virtual void Execute() = 0; }; 10 | 11 | class WorkerThreads 12 | { 13 | public: 14 | struct ThreadData 15 | { 16 | Job* (*GetAJob)(WorkerThreads*); 17 | WorkerThreads* employer; 18 | volatile bool exit; 19 | }; 20 | 21 | WorkerThreads() 22 | { 23 | m_workerData.GetAJob = &PopJob; 24 | m_workerData.employer = this; 25 | m_workerData.exit = false; 26 | 27 | InitializeCriticalSection( &m_jobLock ); 28 | 29 | m_worker1 = CreateThread( 0, 0, &ThreadMain, &m_workerData, 0, 0 ); 30 | m_worker2 = CreateThread( 0, 0, &ThreadMain, &m_workerData, 0, 0 ); 31 | } 32 | ~WorkerThreads() 33 | { 34 | m_workerData.exit = true; 35 | WaitForSingleObject( m_worker1, INFINITE ); 36 | WaitForSingleObject( m_worker2, INFINITE ); 37 | DeleteCriticalSection( &m_jobLock ); 38 | } 39 | 40 | void PushJob( Job* job ) 41 | { 42 | EnterCriticalSection( &m_jobLock ); 43 | m_jobs.push_back( job ); 44 | LeaveCriticalSection( &m_jobLock ); 45 | } 46 | private: 47 | WorkerThreads( const WorkerThreads& ); 48 | WorkerThreads& operator=( const WorkerThreads& ); 49 | 50 | ThreadData m_workerData; 51 | HANDLE m_worker1, m_worker2; 52 | CRITICAL_SECTION m_jobLock; 53 | std::deque m_jobs; 54 | 55 | static DWORD WINAPI ThreadMain( void* data ) 56 | { 57 | ThreadData* threadData = (ThreadData*)data; 58 | while( !threadData->exit ) 59 | { 60 | Job* job = threadData->GetAJob( threadData->employer ); 61 | if( job ) 62 | job->Execute(); 63 | else 64 | Sleep(0); 65 | } 66 | return 0; 67 | } 68 | 69 | static Job* PopJob( WorkerThreads* self ) 70 | { 71 | Job* job = 0; 72 | EnterCriticalSection( &self->m_jobLock ); 73 | if( !self->m_jobs.empty() ) 74 | { 75 | job = self->m_jobs.front(); 76 | self->m_jobs.pop_front(); 77 | } 78 | LeaveCriticalSection( &self->m_jobLock ); 79 | return job; 80 | } 81 | }; -------------------------------------------------------------------------------- /src/core/thread/latentpipe.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include 5 | 6 | using namespace eight; 7 | 8 | 9 | uint PoolSize() 10 | { 11 | eiASSERT( static_cast(internal::_ei_thread_id) ); 12 | return internal::_ei_thread_id->poolSize; 13 | } 14 | 15 | BaseLatentPipe::BaseLatentPipe( Scope& a, uint capacity, uint sizeOfT, uint padding ) 16 | : m_capacity(capacity) 17 | , m_queue( eiAllocArray(a, byte*, PoolSize()) ) 18 | { 19 | uint sizeofQueue = sizeof(uint) + padding + m_capacity*sizeOfT; 20 | uint sizeof4FrameQueue = 4 * sizeofQueue; 21 | uint sizeofShared4FrameQueue = PoolSize() * sizeof4FrameQueue; 22 | byte* queueStorage = eiAllocArray( a, byte, sizeofShared4FrameQueue ); 23 | for( int i=0; i!=internal::_ei_thread_id->poolSize; ++i ) 24 | { 25 | m_queue[i] = queueStorage + i*sizeof4FrameQueue; 26 | for( int frame=0; frame!=4; ++frame ) 27 | { 28 | *(uint*)(m_queue[i] + sizeofQueue * frame) = 0; 29 | } 30 | } 31 | } 32 | 33 | uint BaseLatentPipe::GetQueueCount() const 34 | { 35 | return internal::_ei_thread_id->poolSize; 36 | } 37 | u32 BaseLatentPipe::GetQueueMask() const 38 | { 39 | eiASSERT( internal::_ei_thread_id->poolMask == (1<<(1+GetQueueCount()))-1 ); 40 | return internal::_ei_thread_id->poolMask; 41 | } 42 | byte* BaseLatentPipe::GetHeadQueue(uint sizeOfT, uint padding, uint frame) 43 | { 44 | uint thread = internal::_ei_thread_id->index; 45 | return GetHeadQueue(thread, sizeOfT, padding, frame); 46 | } 47 | byte* BaseLatentPipe::GetHeadQueue(uint thread, uint sizeOfT, uint padding, uint frame) 48 | { 49 | //other threads can be 1 frame behind or 1 frame ahead, so 50 | frame = (frame+2)%4;//write 2 frames ahead 51 | uint sizeofQueue = sizeof(uint) + padding + m_capacity*sizeOfT; 52 | return m_queue[thread] + sizeofQueue * frame; 53 | } 54 | byte* BaseLatentPipe::GetTailQueue(uint sizeOfT, uint padding, uint frame) 55 | { 56 | uint thread = internal::_ei_thread_id->index; 57 | return GetTailQueue(thread, sizeOfT, padding, frame); 58 | } 59 | byte* BaseLatentPipe::GetTailQueue(uint thread, uint sizeOfT, uint padding, uint frame) 60 | { 61 | frame = frame%4; 62 | eiASSERT( thread < internal::_ei_thread_id->poolSize ); 63 | uint sizeofQueue = sizeof(uint) + padding + m_capacity*sizeOfT; 64 | return m_queue[thread] + sizeofQueue * frame; 65 | } 66 | -------------------------------------------------------------------------------- /src/core/thread/threadlocal.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | using namespace eight; 5 | 6 | 7 | u32 eight::TlsAlloc() 8 | { 9 | u32 index = ::TlsAlloc(); 10 | eiASSERT( index != TLS_OUT_OF_INDEXES ); 11 | return index; 12 | } 13 | 14 | void eight::TlsFree( u32 index ) 15 | { 16 | eiDEBUG( BOOL ok = ) ::TlsFree( index ); 17 | eiASSERT( ok ); 18 | } 19 | 20 | void* eight::TlsGet( u32 index ) 21 | { 22 | return ::TlsGetValue( index ); 23 | } 24 | 25 | void eight::TlsSet( u32 index, void* value ) 26 | { 27 | ::TlsSetValue( index, value ); 28 | } -------------------------------------------------------------------------------- /src/core/timer/timer.cpp: -------------------------------------------------------------------------------- 1 | //------------------------------------------------------------------------------ 2 | #include 3 | #include 4 | #include 5 | #include 6 | #include 7 | #include 8 | 9 | using namespace eight; 10 | //------------------------------------------------------------------------------ 11 | 12 | class TimerImpl 13 | { 14 | public: 15 | TimerImpl(); 16 | ~TimerImpl(); 17 | void Reset(); 18 | double Elapsed() const; 19 | double Elapsed(bool reset); 20 | timer data; 21 | }; 22 | 23 | eiImplementInterface( Timer, TimerImpl ); 24 | eiInterfaceConstructor( Timer, () ); 25 | eiInterfaceFunction( void, Timer, Reset, () ); 26 | eiInterfaceFunctionConst( double, Timer, Elapsed, () ); 27 | eiInterfaceFunction( double, Timer, Elapsed, (a), bool a ); 28 | 29 | static eight::Atomic g_TimerSystemInit; 30 | 31 | static void InitSystem() 32 | { 33 | if( 0 == g_TimerSystemInit++ ) 34 | timer_lib_initialize(); 35 | //todo - init/shutdown here supposed to be able to be stupid-proof, allowing user to init multiple times. 36 | // not actually safe to use this feature yet: 37 | //thread A: g_TimerSystemInit++ -> true 38 | //thread B: g_TimerSystemInit++ -> false 39 | //thread B: return 40 | //thread B: ...goes on to use timer functions... 41 | //thread A: timer_lib_initialize(); -- too late 42 | } 43 | 44 | static void ShutdownSystem() 45 | { 46 | eiASSERT( g_TimerSystemInit ); 47 | if( --g_TimerSystemInit == 0 ) 48 | timer_lib_shutdown(); 49 | } 50 | 51 | TimerImpl::TimerImpl() 52 | { 53 | InitSystem(); 54 | eiASSERT( g_TimerSystemInit ); 55 | timer_initialize( &data ); 56 | } 57 | 58 | TimerImpl::~TimerImpl() 59 | { 60 | ShutdownSystem(); 61 | } 62 | 63 | void TimerImpl::Reset() 64 | { 65 | timer_reset( &data ); 66 | } 67 | 68 | double TimerImpl::Elapsed() const 69 | { 70 | return timer_elapsed( (timer*)&data, 0 ); 71 | } 72 | 73 | double TimerImpl::Elapsed(bool reset) 74 | { 75 | return timer_elapsed( &data, (int)reset ); 76 | } 77 | 78 | //------------------------------------------------------------------------------ 79 | -------------------------------------------------------------------------------- /src/lua/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | 2 | BeginLibrary( lua core luajit ) 3 | 4 | AddSourceGroup( lua 5 | lua.cpp 6 | lua.h 7 | lua_api.h 8 | bindlua.h 9 | luadebug.cpp 10 | ) 11 | 12 | AddSourceGroup( Tilde 13 | ../../external/tilde/HostConfig.cpp 14 | ../../external/tilde/HostConfig.h 15 | ../../external/tilde/LuaDebugger.cpp 16 | ../../external/tilde/LuaDebugger.h 17 | ../../external/tilde/LuaDebuggerComms.cpp 18 | ../../external/tilde/LuaDebuggerComms.h 19 | ../../external/tilde/LuaDebuggerHost.h 20 | ../../external/tilde/LuaDebuggerProtocol.h 21 | ../../external/tilde/LuaHostWindows.cpp 22 | ../../external/tilde/LuaHostWindows.h 23 | ../../external/tilde/ReceiveMessageBuffer.h 24 | ../../external/tilde/SendMessageBuffer.h 25 | ) 26 | 27 | EndLibrary() 28 | 29 | AddTest( test_lua lua_test_app.cpp lua ) 30 | 31 | 32 | 33 | -------------------------------------------------------------------------------- /src/lua/lua_test_app.cpp: -------------------------------------------------------------------------------- 1 | //------------------------------------------------------------------------------ 2 | #include 3 | #include 4 | using namespace eight; 5 | //------------------------------------------------------------------------------ 6 | 7 | eiENTRY_POINT( test_main ) 8 | int test_main( int argc, char** argv ) 9 | { 10 | int errorCount = 0; 11 | eiRUN_TEST( Lua, errorCount ); 12 | return errorCount; 13 | } 14 | 15 | //------------------------------------------------------------------------------ 16 | -------------------------------------------------------------------------------- /src/lua/luadebug.cpp: -------------------------------------------------------------------------------- 1 | #include "eight/core/alloc/scope.h" 2 | #include "eight/core/alloc/new.h" 3 | #include "eight/lua/lua.h" 4 | #include "eight/lua/lua_api.h" 5 | #include "tilde/LuaHostWindows.h" 6 | #include "tilde/LuaDebuggerComms.h" 7 | #include "stdio.h" 8 | #include "string.h" 9 | using namespace eight; 10 | using namespace tilde; 11 | 12 | Tilde* Tilde::New(Scope& a, int port) 13 | { 14 | return (Tilde*)(LuaHostWindows*)(eiNew(a,LuaHostWindows)(port));//-V572 15 | } 16 | 17 | void Tilde::Register(lua_State* L) 18 | { 19 | LuaHostWindows* self = (LuaHostWindows*)this; 20 | self->RegisterState("state", L); 21 | } 22 | void Tilde::WaitForDebuggerConnection() 23 | { 24 | LuaHostWindows* self = (LuaHostWindows*)this; 25 | self->WaitForDebuggerConnection(); 26 | } 27 | void Tilde::Poll() 28 | { 29 | LuaHostWindows* self = (LuaHostWindows*)this; 30 | self->Poll(); 31 | } 32 | //------------------------------------------------------------------------------ --------------------------------------------------------------------------------