aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAlon Zakai <alonzakai@gmail.com>2013-01-31 14:50:26 -0800
committerAlon Zakai <alonzakai@gmail.com>2013-01-31 14:50:26 -0800
commitdb418cbf5c42759fc880345c602e50d3bc4a9e00 (patch)
treee3bae17d9dff0acf97532445441fc61117e02268
parentfdf62e89373283f644be32e6c1749f5cb120bac7 (diff)
hand-optimize memcpy/asm
-rwxr-xr-xemcc30
-rw-r--r--src/library.js39
2 files changed, 27 insertions, 42 deletions
diff --git a/emcc b/emcc
index 88f38bda..73f12cda 100755
--- a/emcc
+++ b/emcc
@@ -1089,36 +1089,6 @@ try:
shared.Building.llvm_opt(in_temp(target_basename + '.bc'), link_opts)
if DEBUG: save_intermediate('linktime', 'bc')
- # Optimization and lto can add new intrinsics like memcpy that were not present before. We
- # are now *after* linking in libc, so we missed our chance to get memcpy - check and add it now
- # if necessary
- final_symbols = shared.Building.llvm_nm(final)
- need_memcpy = False
- for symbol in final_symbols.undefs:
- if symbol in MEMCPY_ALIASES:
- need_memcpy = True
- break
- has_memcpy = False
- for symbol in final_symbols.defs:
- if symbol in MEMCPY_ALIASES:
- has_memcpy = True
- break
- if need_memcpy and not has_memcpy:
- if DEBUG: print >> sys.stderr, 'memcpy intrinsic added in optimizations, linking in optimized memcpy'
- memcpy = in_temp('memcpy.bc')
- force_cxx = os.environ.get('EMMAKEN_CXX')
- if force_cxx is not None: del os.environ['EMMAKEN_CXX'] # memcpy must be compiled as C
- execute([shared.PYTHON, shared.EMCC, shared.path_from_root('system', 'lib', 'libc', 'musl', 'memcpy.c'), '-o', memcpy], stdout=stdout, stderr=stderr)
- if force_cxx is not None: os.environ['EMMAKEN_CXX'] = force_cxx
- shared.Building.llvm_opt(memcpy, llvm_opts) # optimize it just like normal code; no point in lto though
- next = final + '.postrinsics.bc'
- shared.Building.link([final, memcpy], next)
- final = next
- if shared.Settings.ASM_JS: # export it so other library functions etc. can use it
- if '_memcpy' not in shared.Settings.EXPORTED_FUNCTIONS:
- shared.Settings.EXPORTED_FUNCTIONS.append('_memcpy')
- if DEBUG: save_intermediate('postrinsics', 'bc')
-
# Prepare .ll for Emscripten
if not LEAVE_INPUTS_RAW:
final = shared.Building.llvm_dis(final, final + '.ll')
diff --git a/src/library.js b/src/library.js
index 53fc8617..bc8502bc 100644
--- a/src/library.js
+++ b/src/library.js
@@ -4217,16 +4217,31 @@ LibraryManager.library = {
return ret;
},
+ memcpy__asm: 'true',
+ memcpy__sig: 'iiii',
memcpy: function (dest, src, num) {
- // simple version, in general it should not be used - we should pull it in from libc
- if (!_memcpy.shown) {
- _memcpy.shown = true;
- Module.printErr('warning: library.js memcpy should not be running, it is only for testing!');
+ dest = dest|0; src = src|0; num = num|0;
+ if ((dest&3) == (src&3)) {
+ while (dest & 3 & num) {
+ {{{ makeSetValueAsm('dest', 0, makeGetValueAsm('src', 0, 'i8'), 'i8') }}};
+ dest = (dest+1)|0;
+ src = (src+1)|0;
+ num = (num-1)|0;
+ }
+ while (num|0 >= 4) {
+ {{{ makeSetValueAsm('dest', 0, makeGetValueAsm('src', 0, 'i32'), 'i32') }}};
+ dest = (dest+4)|0;
+ src = (src+4)|0;
+ num = (num-4)|0;
+ }
}
-#endif
- while (num--) {
- HEAP8[dest++] = HEAP8[src++];
+ while (num|0 > 0) {
+ {{{ makeSetValueAsm('dest', 0, makeGetValueAsm('src', 0, 'i8'), 'i8') }}};
+ dest = (dest+1)|0;
+ src = (src+1)|0;
+ num = (num-1)|0;
}
+ return dest|0;
},
wmemcpy: function() { throw 'wmemcpy not implemented' },
@@ -5601,11 +5616,11 @@ LibraryManager.library = {
// ==========================================================================
__utsname_struct_layout: Runtime.generateStructInfo([
- 'sysname',
- 'nodename',
- 'release',
- 'version',
- 'machine'], '%struct.utsname'),
+ 'sysname',
+ 'nodename',
+ 'release',
+ 'version',
+ 'machine'], '%struct.utsname'),
uname__deps: ['__utsname_struct_layout'],
uname: function(name) {
// int uname(struct utsname *name);