]> Sergey Matveev's repositories - nnn.git/commitdiff
Check alignment and enable -O3
authorArun Prakash Jana <engineerarun@gmail.com>
Fri, 29 Dec 2017 05:38:07 +0000 (11:08 +0530)
committerArun Prakash Jana <engineerarun@gmail.com>
Fri, 29 Dec 2017 05:38:07 +0000 (11:08 +0530)
Makefile
nnn.c

index 03dfd77ce0dd75bc060d971936e2cdc2a2991c93..e8224d8006784430d0bab8995526f689e5d695c5 100644 (file)
--- a/Makefile
+++ b/Makefile
@@ -3,7 +3,7 @@ VERSION = 1.6
 PREFIX ?= /usr/local
 MANPREFIX = $(PREFIX)/share/man
 
-CFLAGS += -Wall -Wextra -Wno-unused-parameter
+CFLAGS += -O3 -Wall -Wextra -Wno-unused-parameter
 LDLIBS = -lreadline
 
 ifeq ($(shell pkg-config ncursesw && echo 1),1)
@@ -23,7 +23,7 @@ all: $(BIN) $(PLAYER)
 $(SRC): nnn.h
 
 $(BIN): $(SRC)
-       $(CC) -O2 $(CFLAGS) -o $@ $^ $(LDFLAGS) $(LDLIBS)
+       $(CC) $(CFLAGS) -o $@ $^ $(LDFLAGS) $(LDLIBS)
        strip $@
 
 debug: $(SRC)
diff --git a/nnn.c b/nnn.c
index fb1d5b4ea152260be9fcbdc41501c0ff36165206..721ef80bac4afe1231379ecae329181f57db285d 100644 (file)
--- a/nnn.c
+++ b/nnn.c
@@ -357,11 +357,12 @@ xstrlen(const char *s)
 static size_t
 xstrlcpy(char *dest, const char *src, size_t n)
 {
+       static ulong *s, *d;
        static size_t len, blocks;
        static const uint lsize = sizeof(ulong);
        static const uint _WSHIFT = (sizeof(ulong) == 8) ? 3 : 2;
 
-       if (!src || !dest)
+       if (!src || !dest || !n)
                return 0;
 
        len = xstrlen(src) + 1;
@@ -371,17 +372,15 @@ xstrlcpy(char *dest, const char *src, size_t n)
                /* Save total number of bytes to copy in len */
                len = n;
 
-       if (n >= lsize) {
-               blocks = n >> _WSHIFT;
-               n -= (blocks << _WSHIFT);
-       } else
-               blocks = 0;
-
-       if (blocks) {
-               static ulong *s, *d;
-
+       /*
+        * To enable -O3 ensure src and dest are 16-byte aligned
+        * More info: http://www.felixcloutier.com/x86/MOVDQA.html
+        */
+       if ((n >= lsize) && !((ulong)src & (ulong)dest & 0xF)) {
                s = (ulong *)src;
                d = (ulong *)dest;
+               blocks = n >> _WSHIFT;
+               n -= (blocks << _WSHIFT);
 
                while (blocks) {
                        *d = *s;