Browse Source

Check alignment and enable -O3

master
Arun Prakash Jana 7 years ago
parent
commit
3a88e31a0e
No known key found for this signature in database GPG Key ID: A75979F35C080412
2 changed files with 11 additions and 12 deletions
  1. +2
    -2
      Makefile
  2. +9
    -10
      nnn.c

+ 2
- 2
Makefile View File

@@ -3,7 +3,7 @@ VERSION = 1.6
PREFIX ?= /usr/local PREFIX ?= /usr/local
MANPREFIX = $(PREFIX)/share/man MANPREFIX = $(PREFIX)/share/man


CFLAGS += -Wall -Wextra -Wno-unused-parameter CFLAGS += -O3 -Wall -Wextra -Wno-unused-parameter
LDLIBS = -lreadline LDLIBS = -lreadline


ifeq ($(shell pkg-config ncursesw && echo 1),1) ifeq ($(shell pkg-config ncursesw && echo 1),1)
@@ -23,7 +23,7 @@ all: $(BIN) $(PLAYER)
$(SRC): nnn.h $(SRC): nnn.h


$(BIN): $(SRC) $(BIN): $(SRC)
$(CC) -O2 $(CFLAGS) -o $@ $^ $(LDFLAGS) $(LDLIBS) $(CC) $(CFLAGS) -o $@ $^ $(LDFLAGS) $(LDLIBS)
strip $@ strip $@


debug: $(SRC) debug: $(SRC)


+ 9
- 10
nnn.c View File

@@ -357,11 +357,12 @@ xstrlen(const char *s)
static size_t static size_t
xstrlcpy(char *dest, const char *src, size_t n) xstrlcpy(char *dest, const char *src, size_t n)
{ {
static ulong *s, *d;
static size_t len, blocks; static size_t len, blocks;
static const uint lsize = sizeof(ulong); static const uint lsize = sizeof(ulong);
static const uint _WSHIFT = (sizeof(ulong) == 8) ? 3 : 2; static const uint _WSHIFT = (sizeof(ulong) == 8) ? 3 : 2;


if (!src || !dest) if (!src || !dest || !n)
return 0; return 0;


len = xstrlen(src) + 1; 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 */ /* Save total number of bytes to copy in len */
len = n; len = n;


if (n >= lsize) { /*
blocks = n >> _WSHIFT; * To enable -O3 ensure src and dest are 16-byte aligned
n -= (blocks << _WSHIFT); * More info: http://www.felixcloutier.com/x86/MOVDQA.html
} else */
blocks = 0; if ((n >= lsize) && !((ulong)src & (ulong)dest & 0xF)) {

if (blocks) {
static ulong *s, *d;

s = (ulong *)src; s = (ulong *)src;
d = (ulong *)dest; d = (ulong *)dest;
blocks = n >> _WSHIFT;
n -= (blocks << _WSHIFT);


while (blocks) { while (blocks) {
*d = *s; *d = *s;


||||||
x
 
000:0
Loading…
Cancel
Save