File otp-R15B03-1-led.patch of Package erlang

erts/emulator/beam/bif.c     | 43 ++++++++++++++++++++++++++-----------------
 erts/emulator/beam/bif.h     | 26 ++++++++++++++++++++++++++
 erts/emulator/beam/erl_nif.c |  4 +---
 lib/Makefile                 | 18 ++++++++++++++++++
 make/otp_subdir.mk           | 27 +++++++++++++++++++++++++--
 5 files changed, 96 insertions(+), 22 deletions(-)

diff --git a/erts/emulator/beam/bif.c b/erts/emulator/beam/bif.c
index fc00b42..5a40482 100644
--- a/erts/emulator/beam/bif.c
+++ b/erts/emulator/beam/bif.c
@@ -2301,9 +2301,7 @@ consolidate(Process* p, Eterm acc, Uint size)
 	sz = BIG_NEED_SIZE(BIG_SIZE(big));
 	hp = HAlloc(p, sz);
 	res = make_big(hp);
-	while (sz--) {
-	    *hp++ = *big++;
-	}
+	etermcpy(hp, big, sz);
 	erts_free(ERTS_ALC_T_TEMP_TERM, (void *) big_val(acc));
 	return res;
     }
@@ -2426,7 +2424,6 @@ BIF_RETTYPE setelement_3(BIF_ALIST_3)
 {
     Eterm* ptr;
     Eterm* hp;
-    Eterm* resp;
     Uint ix;
     Uint size;
 
@@ -2444,12 +2441,9 @@ BIF_RETTYPE setelement_3(BIF_ALIST_3)
     hp = HAlloc(BIF_P, size);
 
     /* copy the tuple */
-    resp = hp;
-    while (size--) {		/* XXX use memcpy? */
-	*hp++ = *ptr++;
-    }
-    resp[ix] = BIF_ARG_3;
-    BIF_RET(make_tuple(resp));
+    etermcpy(hp, ptr, size);
+    hp[ix] = BIF_ARG_3;
+    BIF_RET(make_tuple(hp));
 }
 
 /**********************************************************************/
@@ -2466,9 +2460,15 @@ BIF_RETTYPE make_tuple_2(BIF_ALIST_2)
     hp = HAlloc(BIF_P, n+1);
     res = make_tuple(hp);
     *hp++ = make_arityval(n);
-    while (n--) {
-	*hp++ = BIF_ARG_2;
-    }
+#ifdef ASM_OPT_X86
+    asm volatile ("rep stos %2, %%es:(%0)"
+    : "=&D" (hp), "=&c" (n), "=&a" (BIF_ARG_2)
+    : "0" (hp), "1" (n), "2" (BIF_ARG_2)
+    : "memory");
+#else
+    for (; n; n--, hp++)
+	*hp = BIF_ARG_2;
+#endif
     BIF_RET(res);
 }
 
@@ -2540,10 +2540,19 @@ BIF_RETTYPE append_element_2(BIF_ALIST_2)
     hp = HAlloc(BIF_P, arity + 2);
     res = make_tuple(hp);
     *hp = make_arityval(arity+1);
-    while (arity--) {
-	*++hp = *++ptr;
-    }
-    *++hp = BIF_ARG_2;
+    ptr++;
+    hp++;
+#ifdef ASM_OPT_X86
+    asm volatile (
+	"rep " MOVS_ETERM "\n\t"
+	"stos %3, %%es:(%1)"
+    : "=&S" (ptr), "=&D" (hp), "=&c" (arity), "=&a" (BIF_ARG_2)
+    : "0" (ptr), "1" (hp), "2" (arity), "3" (BIF_ARG_2)
+    : "memory");
+#else
+    etermcpy(hp, ptr, arity);
+    *(hp + arity) = BIF_ARG_2;
+#endif
     BIF_RET(res);
 }
 
diff --git a/erts/emulator/beam/bif.h b/erts/emulator/beam/bif.h
index d20089a..92a394a 100644
--- a/erts/emulator/beam/bif.h
+++ b/erts/emulator/beam/bif.h
@@ -20,6 +20,8 @@
 #ifndef __BIF_H__
 #define __BIF_H__
 
+#include "sys.h"
+
 extern Export* erts_format_cpu_topology_trap;
 
 #define BIF_RETTYPE Eterm
@@ -404,6 +406,30 @@ erts_bif_prep_await_proc_exit_apply_trap(Process *c_p,
 					 Eterm args[],
 					 int nargs);
 
+#ifdef ASM_OPTIMIZE
+#if defined(__i386__) || defined(__x86_64__)
+#define ASM_OPT_X86
+#if ERTS_SIZEOF_ETERM == 8
+#define MOVS_ETERM "movsq"
+#else
+#define MOVS_ETERM "movsl"
+#endif
+#endif
+#endif
+
+static inline void etermcpy(Eterm *dst, const Eterm *src, size_t size)
+{
+#ifdef ASM_OPT_X86
+    void *d;
+    asm volatile ("rep " MOVS_ETERM
+    : "=&S" (d), "=&D" (d), "=&c" (d)
+    : "0" (src), "1" (dst), "2" (size)
+    : "memory");
+#else
+    memcpy(dst, src, size * sizeof(Eterm));
+#endif
+}
+
 #include "erl_bif_table.h"
 
 #endif
diff --git a/erts/emulator/beam/erl_nif.c b/erts/emulator/beam/erl_nif.c
index 4109c20..0644ddf 100644
--- a/erts/emulator/beam/erl_nif.c
+++ b/erts/emulator/beam/erl_nif.c
@@ -995,9 +995,7 @@ ERL_NIF_TERM enif_make_tuple_from_array(ErlNifEnv* env, const ERL_NIF_TERM arr[]
     const Eterm* src = arr;
 
     *hp++ = make_arityval(cnt);
-    while (cnt--) {
-	*hp++ = *src++;	   
-    }
+    etermcpy(hp, src, cnt);
     return ret;
 }
 
diff --git a/lib/Makefile b/lib/Makefile
index 3753bd1..e9b7e3c 100644
--- a/lib/Makefile
+++ b/lib/Makefile
@@ -55,4 +55,22 @@ endif
 
 
 # ----------------------------------------------------------------------
+ifneq ($(filter opt debug,$(MAKECMDGOALS)),)
+asn1 odbc: erl_interface
+compiler edoc snmp stdlib tools xmerl: parsetools
+cosEvent cosProperty cosTime cosTransactions orber: ic
+otp_mibs: snmp
+common_test: test_server snmp
+os_mon: otp_mibs snmp
+ic: parsetools jinterface
+megaco: parsetools asn1
+public_key: asn1 syntax_tools
+eldap: asn1
+ssh: asn1 syntax_tools public_key
+ssl: asn1 syntax_tools public_key
+cosEventDomain: ic cosNotification
+cosFileTransfer: ic cosProperty
+cosNotification: ic parsetools cosEvent cosTime
+endif
+
 include $(ERL_TOP)/make/otp_subdir.mk
diff --git a/make/otp_subdir.mk b/make/otp_subdir.mk
index 07294c2..ea02d70 100644
--- a/make/otp_subdir.mk
+++ b/make/otp_subdir.mk
@@ -19,12 +19,12 @@
 # Make include file for otp
 
 .PHONY: debug opt release docs release_docs tests release_tests \
-	clean depend valgrind
+	clean depend valgrind $(SUB_DIRECTORIES)
 
 #
 # Targets that don't affect documentation directories
 #
-opt debug release docs release_docs tests release_tests clean depend valgrind:
+release release_docs tests release_tests clean depend valgrind:
 	@set -e ;							\
 	app_pwd=`pwd` ;							\
 	if test -f vsn.mk; then						\
@@ -46,3 +46,26 @@ opt debug release docs release_docs tests release_tests clean depend valgrind:
 	if test -f vsn.mk; then						\
 	    echo "=== Leaving application" `basename $$app_pwd` ;	\
 	fi
+
+docs opt debug: $(SUB_DIRECTORIES)
+
+$(SUB_DIRECTORIES):
+	@set -e ;							\
+	app_pwd=`pwd` ;							\
+	if test -f vsn.mk; then						\
+	    echo "=== Entering application" `basename $$app_pwd` ;	\
+	fi ;								\
+	if test -f $@/SKIP ; then					\
+	    echo "=== Skipping subdir "$@", reason:" ;			\
+	    cat $@/SKIP ;						\
+	    echo "===" ;						\
+	else								\
+	    if test ! -d $@ ; then					\
+		echo "=== Skipping subdir "$@", it is missing" ;	\
+	    else							\
+		$(MAKE) -C $@ $$xflag $(MAKECMDGOALS) ;			\
+	    fi ;							\
+	fi ;								\
+	if test -f vsn.mk; then						\
+	    echo "=== Leaving application" `basename $$app_pwd` ;	\
+	fi