History

DisVM will now only use 0 initialized memory. - The alloc_memory function will only return 0 initialize memory - calloc_memory was removed

Floating point division is now relying on underlying FPU and IEEE for behavior with respect to divide by 0

arr committed 9 years ago

Commit b92328e1 parent bd1f49311 files · +48 −112Browse files

Showing the changes to src/vm/execution_table.cpp (1 of 11 files). Show all

Unified · Split

src/vm/execution_table.cpp+23−9
@@ -294,6 +294,16 @@ namespace · 293 unmodified lines
294294 vt_ref<PrimitiveType>(r.dest) = vt_ref<PrimitiveType>(r.mid) / denom;
295295 }
296296
297+ // [SPEC] The C++ defines division by 0 as undefined, however the IEEE standard does
298+ // define the behavior. Therefore the behavior is platform dependent and controlled
299+ // by the built-in Math module.
300+ template<>
301+ void _div<real_t>(vm_registers_t &r)
302+ {
303+ const auto denom = vt_ref<real_t>(r.src);
304+ vt_ref<real_t>(r.dest) = vt_ref<real_t>(r.mid) / denom;
305+ }
306+
297307 EXEC_DECL(divb) { _div<byte_t>(r); }
298308 EXEC_DECL(divw) { _div<word_t>(r); }
299309 EXEC_DECL(divf) { _div<real_t>(r); }
@@ -1318,7 +1328,7 @@ namespace · 1018 unmodified lines
13181328
13191329 namespace
13201330 {
1321− void new_instance(vm_registers_t &r, const vm_t &vm, const bool zero_memory)
1331+ void new_instance(vm_registers_t &r, const vm_t &vm)
13221332 {
13231333 const auto type_id = vt_ref<word_t>(r.src);
13241334 const auto &types = r.module_ref->type_section;
@@ -1327,7 +1337,7 @@ namespace · 2 unmodified lines
13271337 dec_ref_count_and_free(at_val<vm_alloc_t>(r.dest));
13281338
13291339 auto type_desc = types[type_id];
1330− auto new_alloc = !zero_memory ? vm_alloc_t::allocate(type_desc) : vm_alloc_t::allocate(type_desc, vm_alloc_t::zero_memory);
1340+ auto new_alloc = vm_alloc_t::allocate(type_desc);
13311341
13321342 if (type_desc->map_in_bytes > 0)
13331343 vm.get_garbage_collector().track_allocation(new_alloc);
@@ -1338,12 +1348,14 @@ namespace · 4 unmodified lines
13381348
13391349 EXEC_DECL(new_)
13401350 {
1341− new_instance(r, vm, false /* zero memory */);
1351+ new_instance(r, vm);
13421352 }
13431353
13441354 EXEC_DECL(newz)
13451355 {
1346− new_instance(r, vm, true /* zero memory */);
1356+ // See allocation implementation for guarantee about
1357+ // always using zeroed memory.
1358+ new_instance(r, vm);
13471359 }
13481360
13491361 EXEC_DECL(mnewz)
@@ -1359,7 +1371,7 @@ namespace · 9 unmodified lines
13591371 dec_ref_count_and_free(at_val<vm_alloc_t>(r.dest));
13601372
13611373 auto type_desc = types[type_id];
1362− auto new_alloc = vm_alloc_t::allocate(type_desc, vm_alloc_t::zero_memory);
1374+ auto new_alloc = vm_alloc_t::allocate(type_desc);
13631375
13641376 if (type_desc->map_in_bytes > 0)
13651377 vm.get_garbage_collector().track_allocation(new_alloc);
@@ -1369,7 +1381,7 @@ namespace · 3 unmodified lines
13691381
13701382 namespace
13711383 {
1372− void new_array(vm_registers_t &r, const vm_t &vm, const bool zero_memory)
1384+ void new_array(vm_registers_t &r, const vm_t &vm)
13731385 {
13741386 assert(r.module_ref != nullptr);
13751387 const auto &types = r.module_ref->type_section;
@@ -1381,7 +1393,7 @@ namespace · 5 unmodified lines
13811393 dec_ref_count_and_free(at_val<vm_alloc_t>(r.dest));
13821394
13831395 const auto array_size = vt_ref<word_t>(r.src);
1384− auto new_array = !zero_memory ? new vm_array_t(type_desc, array_size) : new vm_array_t(type_desc, array_size, vm_alloc_t::zero_memory);
1396+ auto new_array = new vm_array_t(type_desc, array_size);
13851397
13861398 if (type_desc->map_in_bytes > 0)
13871399 vm.get_garbage_collector().track_allocation(new_array);
@@ -1392,12 +1404,14 @@ namespace · 4 unmodified lines
13921404
13931405 EXEC_DECL(newa)
13941406 {
1395− new_array(r, vm, false /* zero memory */);
1407+ new_array(r, vm);
13961408 }
13971409
13981410 EXEC_DECL(newaz)
13991411 {
1400− new_array(r, vm, true /* zero memory */);
1412+ // See allocation implementation for guarantee about
1413+ // always using zeroed memory.
1414+ new_array(r, vm);
14011415 }
14021416
14031417 EXEC_DECL(tcmp)