From c9728398e0f9cb1837288d74cbb65a5be0028a69 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Martin=20Kr=C3=B6ning?= <m.kroening@hotmail.de>
Date: Mon, 3 Jun 2019 13:29:53 +0200
Subject: [PATCH] Use standard conformant alignment enforcement

---
 chapters/chapter2/pi/v6/Makefile |  8 ++++----
 chapters/chapter2/pi/v6/main.c   | 15 ++++++++-------
 chapters/chapter2/pi/v7/Makefile |  4 ++--
 chapters/chapter2/pi/v7/main.c   |  9 +++++----
 4 files changed, 19 insertions(+), 17 deletions(-)

diff --git a/chapters/chapter2/pi/v6/Makefile b/chapters/chapter2/pi/v6/Makefile
index b059cfb..9f63165 100644
--- a/chapters/chapter2/pi/v6/Makefile
+++ b/chapters/chapter2/pi/v6/Makefile
@@ -5,13 +5,13 @@ CXX = g++
 RM = rm -rf
 ASM = nasm
 ifeq ($(UNAME), Darwin)
-#CFLAGS = -Wall -O3 -march=native -mtune=native
-CFLAGS = -Wall -O0 -g
+#CFLAGS = -Wall -std=c11 -O3 -march=native -mtune=native
+CFLAGS = -Wall -std=c11 -O0 -g
 ASMFLAGS = -f macho64 -O0 -g --prefix _
 LDFLAGS =
 else
-#CFLAGS = -Wall -O3 -g -march=native -mtune=native -mfpmath=sse,387
-CFLAGS = -Wall -O0 -g
+#CFLAGS = -Wall -std=c11 -O3 -g -march=native -mtune=native -mfpmath=sse,387
+CFLAGS = -Wall -std=c11 -O0 -g
 ASMFLAGS = -f elf64 -O0 -g -F dwarf
 LDFLAGS =
 endif
diff --git a/chapters/chapter2/pi/v6/main.c b/chapters/chapter2/pi/v6/main.c
index 7f12642..1a09b16 100644
--- a/chapters/chapter2/pi/v6/main.c
+++ b/chapters/chapter2/pi/v6/main.c
@@ -1,17 +1,18 @@
 #include <emmintrin.h>
+#include <stdalign.h>
 #include <stddef.h>
 #include <stdio.h>
 #include <stdlib.h>
 #include <sys/time.h>
 
-double step __attribute__ ((aligned(32)));
-double sum __attribute__ ((aligned(32)));
-long long num_steps __attribute__ ((aligned(32))) = 1000000;
+alignas(32) double step;
+alignas(32) double sum;
+alignas(32) long long num_steps = 1000000;
 
-double four[] __attribute__ ((aligned(32))) = {4.0, 4.0, 4.0, 4.0};
-double two[] __attribute__ ((aligned(32))) = {2.0, 2.0, 2.0, 2.0};
-double one[] __attribute__ ((aligned(32))) = {1.0, 1.0, 1.0, 1.0};
-double ofs[] __attribute__ ((aligned(32))) = {0.5, 1.5, 2.5, 3.5};
+alignas(32) double four[] = {4.0, 4.0, 4.0, 4.0};
+alignas(32) double two[] = {2.0, 2.0, 2.0, 2.0};
+alignas(32) double one[] = {1.0, 1.0, 1.0, 1.0};
+alignas(32) double ofs[] = {0.5, 1.5, 2.5, 3.5};
 
 void calcPi(void)
 {
diff --git a/chapters/chapter2/pi/v7/Makefile b/chapters/chapter2/pi/v7/Makefile
index 4e9f20c..c4f1e4c 100644
--- a/chapters/chapter2/pi/v7/Makefile
+++ b/chapters/chapter2/pi/v7/Makefile
@@ -3,11 +3,11 @@ MAKE = make
 CC = gcc
 CXX = g++
 ifeq ($(UNAME), Darwin)
-CFLAGS = -Wall -O3 -g -march=native -mtune=native -pthread
+CFLAGS = -Wall -std=c11 -O3 -g -march=native -mtune=native -pthread
 ASMFLAGS = -f macho64 -O0 -g --prefix _
 LDFLAGS =
 else
-CFLAGS = -Wall -O3 -g -march=native -mtune=native -mfpmath=sse,387 -pthread
+CFLAGS = -Wall -std=c11 -O3 -g -march=native -mtune=native -mfpmath=sse,387 -pthread
 ASMFLAGS = -f elf64 -O0 -g -F dwarf
 LDFLAGS =
 endif
diff --git a/chapters/chapter2/pi/v7/main.c b/chapters/chapter2/pi/v7/main.c
index 1dd7473..d52930d 100644
--- a/chapters/chapter2/pi/v7/main.c
+++ b/chapters/chapter2/pi/v7/main.c
@@ -1,3 +1,4 @@
+#include <stdalign.h>
 #include <stdio.h>
 #include <stdlib.h>
 #include <pthread.h>
@@ -5,10 +6,10 @@
 
 #define MAX_THREADS		2
 
-double four[] __attribute__ ((aligned(16))) = {4.0, 4.0};
-double two[] __attribute__ ((aligned(16))) = {2.0, 2.0};
-double one[] __attribute__ ((aligned(16))) = {1.0, 1.0};
-double ofs[] __attribute__ ((aligned(16))) = {0.5, 1.5};
+alignas(16) double four[] = {4.0, 4.0};
+alignas(16) double two[] = {2.0, 2.0};
+alignas(16) double one[] = {1.0, 1.0};
+alignas(16) double ofs[] = {0.5, 1.5};
 
 long long num_steps = 1000000;
 double step;
-- 
GitLab