History

Address various performance issues discovered while profiling debugger Fix logical errors in bit shifting bytecodes Add assert for bit shifting issues that may arise on other compilers Fix bug in vm_array assert

arr committed 10 years ago

Commit d8c9a331 parent 42194725 files · +39 −25Browse files

Unified · Split

5 files
  1. src/include/runtime.h +4 −4
  2. src/vm/array.cpp +7 −7
  3. src/vm/execution_table.cpp +23 −9
  4. src/vm/module_reader.cpp +1 −1
  5. src/vm/stack.cpp +4 −4
src/include/runtime.h+4−4
@@ -107,7 +107,7 @@ namespace disvm · 106 unmodified lines
107107 {
108108 auto alloc_inst = vm_alloc_t::from_allocation(allocation);
109109 assert(alloc_inst == nullptr || alloc_inst->alloc_type == intrinsic_type_desc::type<T>());
110− return dynamic_cast<T *>(alloc_inst);
110+ return static_cast<T *>(alloc_inst);
111111 }
112112
113113 protected:
@@ -199,9 +199,9 @@ namespace disvm · 85 unmodified lines
199199 static std::shared_ptr<const type_descriptor_t> type_desc();
200200
201201 public:
202− vm_array_t(std::shared_ptr<const type_descriptor_t> td, word_t count);
203− vm_array_t(std::shared_ptr<const type_descriptor_t> td, word_t count, const zero_memory_t&);
204− vm_array_t(vm_array_t *original, word_t begin_index, word_t count);
202+ vm_array_t(std::shared_ptr<const type_descriptor_t> td, word_t length);
203+ vm_array_t(std::shared_ptr<const type_descriptor_t> td, word_t length, const zero_memory_t&);
204+ vm_array_t(vm_array_t *original, word_t begin_index, word_t length);
205205 vm_array_t(const vm_string_t *s);
206206 ~vm_array_t();
207207
src/vm/array.cpp+7−7
@@ -17,11 +17,11 @@ std::shared_ptr<const type_descriptor_t> vm_array_t::type_desc() · 16 unmodified lines
1717 return intrinsic_type_desc::type<vm_array_t>();
1818 }
1919
20−vm_array_t::vm_array_t(std::shared_ptr<const type_descriptor_t> td, word_t count)
20+vm_array_t::vm_array_t(std::shared_ptr<const type_descriptor_t> td, word_t length)
2121 : vm_alloc_t(vm_array_t::type_desc())
2222 , _arr{ nullptr }
2323 , _element_type{ td }
24− , _length{ count }
24+ , _length{ length }
2525 , _original{ nullptr }
2626 {
2727 assert(_element_type != nullptr);
@@ -43,11 +43,11 @@ vm_array_t::vm_array_t(std::shared_ptr<const type_descriptor_t> td, word_t count · 15 unmodified lines
4343 debug::log_msg(debug::component_trace_t::memory, debug::log_level_t::debug, "end: init: elements: %d\n", array_len);
4444 }
4545
46−vm_array_t::vm_array_t(std::shared_ptr<const type_descriptor_t> td, word_t count, const zero_memory_t&)
46+vm_array_t::vm_array_t(std::shared_ptr<const type_descriptor_t> td, word_t length, const zero_memory_t&)
4747 : vm_alloc_t(vm_array_t::type_desc())
4848 , _arr{ nullptr }
4949 , _element_type{ td }
50− , _length{ count }
50+ , _length{ length }
5151 , _original{ nullptr }
5252 {
5353 assert(_element_type != nullptr);
@@ -56,16 +56,16 @@ vm_array_t::vm_array_t(std::shared_ptr<const type_descriptor_t> td, word_t count · 2 unmodified lines
5656 debug::log_msg(debug::component_trace_t::memory, debug::log_level_t::debug, "initz: vm array: %d\n", _length);
5757 }
5858
59−vm_array_t::vm_array_t(vm_array_t *original, word_t begin_index, word_t count)
59+vm_array_t::vm_array_t(vm_array_t *original, word_t begin_index, word_t length)
6060 : vm_alloc_t(vm_array_t::type_desc())
6161 , _arr{ nullptr }
6262 , _element_type{ original->get_element_type() }
63− , _length{ count }
63+ , _length{ length }
6464 , _original{ original }
6565 {
6666 assert(_original != nullptr);
6767 assert(0 <= begin_index && begin_index < _original->get_length());
68− assert(_length >= 0 && (count - begin_index) < _original->get_length());
68+ assert(_length >= 0 && (_length + begin_index) <= _original->get_length());
6969
7070 if (debug::is_component_tracing_enabled<debug::component_trace_t::memory>())
7171 debug::log_msg(debug::component_trace_t::memory, debug::log_level_t::debug, "init: vm array: slice: %d %d\n", begin_index, _length);
src/vm/execution_table.cpp+23−9
@@ -66,8 +66,22 @@ namespace · 65 unmodified lines
6666 EXEC_DECL(shlw) { vt_ref<word_t>(r.dest) = vt_ref<word_t>(r.mid) << vt_ref<word_t>(r.src); }
6767 EXEC_DECL(shll) { vt_ref<big_t>(r.dest) = vt_ref<big_t>(r.mid) << vt_ref<big_t>(r.src); }
6868 EXEC_DECL(shrb) { vt_ref<byte_t>(r.dest) = vt_ref<byte_t>(r.mid) >> vt_ref<byte_t>(r.src); }
69− EXEC_DECL(shrw) { vt_ref<word_t>(r.dest) = vt_ref<word_t>(r.mid) >> vt_ref<word_t>(r.src); }
70− EXEC_DECL(shrl) { vt_ref<big_t>(r.dest) = vt_ref<big_t>(r.mid) >> vt_ref<big_t>(r.src); }
69+ EXEC_DECL(shrw)
70+ {
71+ vt_ref<word_t>(r.dest) = vt_ref<word_t>(r.mid) >> vt_ref<word_t>(r.src);
72+ // Right shifting a negative number is implementation dependent in C++.
73+ // Assert the current compiler defaults to arithmetic shifting, not logical.
74+ assert(vt_ref<word_t>(r.mid) >= 0 || (vt_ref<word_t>(r.mid) < 0 && vt_ref<word_t>(r.dest) < 0));
75+ }
76+
77+ EXEC_DECL(shrl)
78+ {
79+ vt_ref<big_t>(r.dest) = vt_ref<big_t>(r.mid) >> vt_ref<big_t>(r.src);
80+ // Right shifting a negative number is implementation dependent in C++.
81+ // Assert the current compiler defaults to arithmetic shifting, not logical.
82+ assert(vt_ref<word_t>(r.mid) >= 0 || (vt_ref<word_t>(r.mid) < 0 && vt_ref<word_t>(r.dest) < 0));
83+ }
84+
7185 EXEC_DECL(lsrw) { vt_ref<word_t>(r.dest) = vt_ref<uword_t>(r.mid) >> vt_ref<word_t>(r.src); }
7286 EXEC_DECL(lsrl) { vt_ref<big_t>(r.dest) = vt_ref<ubig_t>(r.mid) >> vt_ref<big_t>(r.src); }
7387
@@ -75,14 +89,14 @@ namespace · 1 unmodified line
7589 // Conversion operations
7690 //
7791
78− EXEC_DECL(cvtbw) { vt_ref<word_t>(r.dest) = std::numeric_limits<byte_t>::max() & vt_ref<byte_t>(r.src); }
79− EXEC_DECL(cvtwb) { vt_ref<byte_t>(r.dest) = std::numeric_limits<byte_t>::max() & vt_ref<word_t>(r.src); }
80− EXEC_DECL(cvtwl) { vt_ref<big_t>(r.dest) = std::numeric_limits<word_t>::max() & vt_ref<word_t>(r.src); }
81− EXEC_DECL(cvtlw) { vt_ref<word_t>(r.dest) = std::numeric_limits<word_t>::max() & vt_ref<big_t>(r.src); }
92+ EXEC_DECL(cvtbw) { vt_ref<word_t>(r.dest) = vt_ref<byte_t>(r.src); }
93+ EXEC_DECL(cvtwb) { vt_ref<byte_t>(r.dest) = vt_ref<word_t>(r.src); }
94+ EXEC_DECL(cvtwl) { vt_ref<big_t>(r.dest) = vt_ref<word_t>(r.src); }
95+ EXEC_DECL(cvtlw) { vt_ref<word_t>(r.dest) = static_cast<word_t>(vt_ref<big_t>(r.src)); }
8296 EXEC_DECL(cvtrf) { vt_ref<short_real_t>(r.dest) = static_cast<short_real_t>(vt_ref<real_t>(r.src)); }
8397 EXEC_DECL(cvtfr) { vt_ref<real_t>(r.dest) = static_cast<real_t>(vt_ref<short_real_t>(r.src)); }
84− EXEC_DECL(cvtws) { vt_ref<short_word_t>(r.dest) = std::numeric_limits<short_word_t>::max() & vt_ref<word_t>(r.src); }
85− EXEC_DECL(cvtsw) { vt_ref<word_t>(r.dest) = std::numeric_limits<short_word_t>::max() & vt_ref<short_word_t>(r.src); }
98+ EXEC_DECL(cvtws) { vt_ref<short_word_t>(r.dest) = vt_ref<word_t>(r.src); }
99+ EXEC_DECL(cvtsw) { vt_ref<word_t>(r.dest) = vt_ref<short_word_t>(r.src); }
86100 EXEC_DECL(cvtlf) { vt_ref<real_t>(r.dest) = static_cast<real_t>(vt_ref<big_t>(r.src)); }
87101 EXEC_DECL(cvtfl)
88102 {
@@ -1626,7 +1640,7 @@ namespace · 1537 unmodified lines
16261640 if (e->alloc_type == vm_string_t::type_desc())
16271641 {
16281642 // String
1629− exception_id = dynamic_cast<vm_string_t *>(e);
1643+ exception_id = static_cast<vm_string_t *>(e);
16301644
16311645 if (debug::is_component_tracing_enabled<debug::component_trace_t::exception>())
16321646 debug::log_msg(debug::component_trace_t::exception, debug::log_level_t::debug, "raise: string: >>%s<<\n", exception_id->str());
src/vm/module_reader.cpp+1−1
@@ -481,7 +481,7 @@ namespace · 480 unmodified lines
481481 if (arr_maybe->alloc_type != vm_array_t::type_desc())
482482 throw module_reader_exception{ "Data index not an array type" };
483483
484− auto arr = dynamic_cast<vm_array_t *>(arr_maybe);
484+ auto arr = static_cast<vm_array_t *>(arr_maybe);
485485
486486 auto array_index = word_t{};
487487 std::tie(success, array_index) = read_next_word(reader);
src/vm/stack.cpp+4−4
@@ -203,7 +203,7 @@ vm_frame_t *vm_stack_t::alloc_frame(std::shared_ptr<const type_descriptor_t> fra · 202 unmodified lines
203203 assert(frame_type != nullptr);
204204 assert(sizeof(vm_frame_base_alloc_t) < frame_type->size_in_bytes && "Requested frame size less than VM frame base size");
205205
206− auto layout = dynamic_cast<vm_stack_layout *>(_mem.get());
206+ auto layout = static_cast<vm_stack_layout *>(_mem.get());
207207
208208 auto page_top_frame = layout->top_page->page_top_frame;
209209 const auto new_frame_size = sizeof(vm_frame_t) + frame_type->size_in_bytes;
@@ -236,7 +236,7 @@ vm_frame_t *vm_stack_t::alloc_frame(std::shared_ptr<const type_descriptor_t> fra · 26 unmodified lines
236236
237237 vm_frame_t *vm_stack_t::push_frame()
238238 {
239− auto layout = dynamic_cast<vm_stack_layout *>(_mem.get());
239+ auto layout = static_cast<vm_stack_layout *>(_mem.get());
240240
241241 auto current_top_frame = layout->top_frame;
242242 auto new_top_frame = layout->top_page->page_top_frame;
@@ -252,7 +252,7 @@ vm_frame_t *vm_stack_t::push_frame() · 9 unmodified lines
252252
253253 vm_frame_t *vm_stack_t::pop_frame()
254254 {
255− auto layout = dynamic_cast<vm_stack_layout *>(_mem.get());
255+ auto layout = static_cast<vm_stack_layout *>(_mem.get());
256256
257257 auto current_frame = layout->top_frame;
258258 if (current_frame == nullptr)
@@ -292,6 +292,6 @@ vm_frame_t *vm_stack_t::pop_frame() · 33 unmodified lines
292292
293293 vm_frame_t *vm_stack_t::peek_frame() const
294294 {
295− auto layout = dynamic_cast<vm_stack_layout *>(_mem.get());
295+ auto layout = static_cast<vm_stack_layout *>(_mem.get());
296296 return layout->top_frame;
297297 }

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t