Skip to content

Commit

Permalink
Merge branch 'c++20'
Browse files Browse the repository at this point in the history
* c++20:
  MISC: mkAppImage.sh: fix $ORIGIN in AnklangSynthEngine-fma, add jackdriver.so
  MISC: Dockerfile.focal: install latest poxy (again)
  MISC: Dockerfile.focal: provide libstdc++-10-dev and a recent castxml
  MISC: config-uname.mk: optimize with clang -march=x86-64-v3 on modern platforms
	Clang chokes on '-march=haswell -mno-hle', so we use '-march=x86-64-v3' which
	is close to Haswell, the clang docs say:
	-march=x86-64: CMOV, CMPXCHG8B, FPU, FXSR, MMX, FXSR, SCE, SSE, SSE2
	-march=x86-64-v2: (close to Nehalem) CMPXCHG16B, LAHF-SAHF, POPCNT, SSE3, SSE4.1, SSE4.2, SSSE3
	-march=x86-64-v3: (close to Haswell) AVX, AVX2, BMI1, BMI2, F16C, FMA, LZCNT, MOVBE, XSAVE
	-march=x86-64-v4: AVX512F, AVX512BW, AVX512CD, AVX512DQ, AVX512VL
  MISC: mkassets.sh: adopt compiler config and fix make V=1
	* Support make with V=1 during asset builds
	* Copy compiler config from config-defaults.mk for mkassets
  Makefile.mk: ignore leading spaces in config-defaults.mk
  ASE: properties.hh, processor.hh: remove unused (and conflicting) GroupId
  ASE: memory.cc: test CString operators
  ASE: memory.hh: CString: provide operator== and operator<=> to disambiguate
  JSONIPC: cxxjip.py: switch from C++17 to C++20
  README.md, *.mk: switch from C++17 to C++20
  ASE: memory.hh: always provide ctor for Block initialization

Signed-off-by: Tim Janik <[email protected]>
  • Loading branch information
tim-janik committed Oct 10, 2023
2 parents 8067acc + efc0b09 commit 3a7c2d3
Show file tree
Hide file tree
Showing 12 changed files with 104 additions and 71 deletions.
4 changes: 2 additions & 2 deletions Makefile.mk
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ INCLUDES ::= -I.
DEFS ::=

# == Compiler Setup ==
CXXSTD ::= -std=gnu++17 -pthread -pipe
CXXSTD ::= -std=gnu++20 -pthread -pipe
CSTD ::= -std=gnu11 -pthread -pipe
EXTRA_DEFS ::= # target private defs, lesser precedence than CXXFLAGS
EXTRA_INCLUDES ::= # target private defs, lesser precedence than CXXFLAGS
Expand Down Expand Up @@ -205,7 +205,7 @@ default: FORCE
if $(if $(filter command, $(origin $(VAR)) $($(VAR).origin)), \
true, false) ; then \
echo '$(VAR) = $(value $(VAR))' >>$@.tmp ; \
elif ! grep -sEm1 '^$(VAR)\s*:?[:!?]?=' config-defaults.mk >>$@.tmp ; then \
elif ! grep -sEm1 '^\s*$(VAR)\s*:?[:!?]?=' config-defaults.mk >>$@.tmp ; then \
echo '# $(VAR) = $(value $(VAR))' >>$@.tmp ; \
fi )
$Q mv $@.tmp config-defaults.mk
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ and run it.
<!-- ROADMAP -->
## Roadmap

☑ Implement the application core in C++17 and the GUI as a web front-end, utilizing web browsers or Electron
☑ Implement the application core in C++20 and the GUI as a web front-end, utilizing web browsers or Electron

☑ Implement separate audio synthesis threads with MIDI device support

Expand Down
44 changes: 43 additions & 1 deletion ase/memory.cc
Original file line number Diff line number Diff line change
Expand Up @@ -730,7 +730,27 @@ aligned_allocator_tests()
}
// test CString
#ifndef NDEBUG
assert_return (cstring_early_test == "NULL");
const bool equality_checks =
cstring_early_test == CString ("NULL") &&
cstring_early_test == String ("NULL") &&
cstring_early_test == "NULL" &&
cstring_early_test != CString ("u") &&
cstring_early_test != String ("u") &&
cstring_early_test != "u" &&
1;
assert_return (equality_checks == true);
const bool lesser_checks =
CString ("1") < CString ("2") && CString ("x") <= CString ("x") &&
CString ("1") < String ("2") && CString ("x") <= String ("x") &&
CString ("1") < "2" && CString ("x") <= "x" &&
1;
assert_return (lesser_checks == true);
const bool greater_checks =
CString ("2") > CString ("1") && CString ("x") >= CString ("x") &&
CString ("2") > String ("1") && CString ("x") >= String ("x") &&
CString ("2") > "1" && CString ("x") >= "x" &&
1;
assert_return (greater_checks == true);
#endif
CString c;
assert_return (c == "");
Expand Down Expand Up @@ -775,6 +795,28 @@ aligned_allocator_tests()
assert_return (c.empty() == false);
struct TwoCStrings { CString a, b; };
static_assert (sizeof (TwoCStrings) <= 2 * 4);
// CString temporary comparisons
assert_return (CString ("a") == String ("a"));
assert_return (String ("a") == CString ("a"));
assert_return (CString ("a") == CString ("a"));
assert_return ("a" == CString ("a"));
assert_return (CString ("a") == "a");
assert_return (CString ("a") != String ("b"));
assert_return (String ("a") != CString ("b"));
assert_return (CString ("a") != CString ("b"));
assert_return ("b" != CString ("a"));
assert_return (CString ("a") != "b");
// CString const comparisons
const CString ac ("a"), bc ("b");
CString a ("a"), b ("b");
assert_return (a == a);
assert_return (ac == ac);
assert_return (a == ac);
assert_return (ac == a);
assert_return (a != b);
assert_return (ac != bc);
assert_return (a != bc);
assert_return (ac != b);
}

} // Anon
47 changes: 14 additions & 33 deletions ase/memory.hh
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,7 @@ struct Block {
void *const block_start = nullptr;
const uint32 block_length = 0;
Block& operator= (const Block &src) { this->~Block(); new (this) Block (src); return *this; }
/*ctor*/ Block (void *b, uint32 l) : block_start (b), block_length (l) {}
/*copy*/ Block (const Block &src) = default;
/*dflt*/ Block () = default;
};
Expand Down Expand Up @@ -176,40 +177,20 @@ public:
const_reverse_iterator rend () const noexcept { return string().rend(); }
const_reverse_iterator crend () const noexcept { return string().crend(); }
/*conv*/ operator std::string () const noexcept { return string(); }
constexpr bool operator== (const CString &b) noexcept { return quark_ == b.quark_; }
bool operator== (const std::string &b) noexcept { return string() == b; }
bool operator== (const char *s) noexcept { return string() == s; }
constexpr bool operator!= (const CString &b) noexcept { return quark_ != b.quark_; }
bool operator!= (const std::string &b) noexcept { return string() != b; }
bool operator!= (const char *s) noexcept { return string() != s; }
bool operator< (const CString &b) noexcept { return string() < b.string(); }
bool operator< (const std::string &b) noexcept { return string() < b; }
bool operator< (const char *s) noexcept { return string() < s; }
bool operator<= (const CString &b) noexcept { return string() <= b.string(); }
bool operator<= (const std::string &b) noexcept { return string() <= b; }
bool operator<= (const char *s) noexcept { return string() <= s; }
bool operator> (const CString &b) noexcept { return string() > b.string(); }
bool operator> (const std::string &b) noexcept { return string() > b; }
bool operator> (const char *s) noexcept { return string() > s; }
bool operator>= (const CString &b) noexcept { return string() >= b.string(); }
bool operator>= (const std::string &b) noexcept { return string() >= b; }
bool operator>= (const char *s) noexcept { return string() >= s; }
friend bool operator== (const char *s, const CString &c) { return s == c.string(); }
friend bool operator!= (const char *s, const CString &c) { return s != c.string(); }
friend bool operator< (const char *s, const CString &c) { return s < c.string(); }
friend bool operator<= (const char *s, const CString &c) { return s <= c.string(); }
friend bool operator> (const char *s, const CString &c) { return s > c.string(); }
friend bool operator>= (const char *s, const CString &c) { return s >= c.string(); }
friend bool operator== (const std::string &s, const CString &c) { return s == c.string(); }
friend bool operator!= (const std::string &s, const CString &c) { return s != c.string(); }
friend bool operator< (const std::string &s, const CString &c) { return s < c.string(); }
friend bool operator<= (const std::string &s, const CString &c) { return s <= c.string(); }
friend bool operator> (const std::string &s, const CString &c) { return s > c.string(); }
friend bool operator>= (const std::string &s, const CString &c) { return s >= c.string(); }
friend std::string operator+ (const std::string &s, const CString &c) { return s + c.string(); }
friend std::string operator+ (const CString &c, const std::string &s) { return c.string() + s; }
friend bool operator== (CString a, CString b) { return a.quark_ == b.quark_; }
friend bool operator== (CString a, const std::string &b) { return a.string() == b; }
friend bool operator== (const std::string &a, CString b) { return a == b.string(); }
friend bool operator== (CString a, const char *b) { return a.string() == b; }
friend bool operator== (const char *a, CString b) { return a == b.string(); }
friend std::strong_ordering operator<=> (CString a, CString b) { return a.string() <=> b.string(); }
friend std::strong_ordering operator<=> (CString a, const String &b) { return a.string() <=> b; }
friend std::strong_ordering operator<=> (const String &a, CString b) { return a <=> b.string(); }
friend std::strong_ordering operator<=> (CString a, const char *b) { return a.string() <=> b; }
friend std::strong_ordering operator<=> (const char *a, CString b) { return a <=> b.string(); }
friend std::string operator+ (const std::string &s, CString c) { return s + c.string(); }
friend std::string operator+ (CString c, const std::string &s) { return c.string() + s; }
static CString lookup (const std::string &s);
friend std::ostream& operator<< (std::ostream &os, const CString &c) { os << c.string(); return os; }
friend std::ostream& operator<< (std::ostream &os, CString c) { os << c.string(); return os; }
static constexpr const std::string::size_type npos = -1;
};

Expand Down
2 changes: 1 addition & 1 deletion ase/processor.hh
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ struct ParamInfo {
CString nick; ///< Abbreviated user interface name, usually not more than 6 characters.
CString unit; ///< Units of the values within range.
CString hints; ///< Hints for parameter handling.
GroupId group; ///< Group for parameters of similar function.
CString group; ///< Group for parameters of similar function.
CString blurb; ///< Short description for user interface tooltips.
CString description; ///< Elaborate description for help dialogs.
using MinMax = std::pair<double,double>;
Expand Down
10 changes: 1 addition & 9 deletions ase/properties.hh
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,6 @@

namespace Ase {

/// A named ID used to group parameters.
struct GroupId : CString {
using CString::CString;
using CString::operator=;
using CString::operator==;
using CString::operator!=;
};

String property_guess_nick (const String &property_label);

/// Implementation namespace for Property helpers
Expand Down Expand Up @@ -120,7 +112,7 @@ public:
Bag& operator+= (PropertyP p);
void on_events (const String &eventselector, const EventHandler &eventhandler);
ConnectionS connections;
GroupId group;
CString group;
PropertyS props;
};

Expand Down
2 changes: 1 addition & 1 deletion jsonipc/cxxjip.py
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,7 @@ def method_kind (self, node):
return 'f' # function

def parse_file (ifile):
args = [ 'castxml', '-std=gnu++17', '-o', '/dev/stdout', '--castxml-output=1' ]
args = [ 'castxml', '-std=gnu++20', '-o', '/dev/stdout', '--castxml-output=1' ]
for inc in includes:
args += [ '-I', inc ]
args.append (ifile)
Expand Down
40 changes: 24 additions & 16 deletions misc/Dockerfile.focal
Original file line number Diff line number Diff line change
Expand Up @@ -13,14 +13,14 @@ RUN : \
&& apt-get -y upgrade \
&& apt-get clean

# Install build tools, TeX, etc
# Install build tools, libstdc++-10-dev>=10 for C++20
# Add libXss.so, libgtk-3-0 for Electron
RUN : \
&& apt-get install -y \
sudo build-essential gawk zstd unzip git wget curl \
gnupg lsb-release software-properties-common ca-certificates \
gettext graphviz imagemagick librsvg2-bin libxml2-utils \
ccache cmake g++ universal-ctags castxml cppcheck \
ccache cmake universal-ctags cppcheck libstdc++-10-dev \
pkg-config libxml2-dev libglib2.0-dev \
libboost-system-dev libasound2-dev libflac-dev libopus-dev libjack-dev libzstd-dev \
libgconf-2-4 libgtk2.0-dev libgtk-3-dev libgtk-3-0 \
Expand All @@ -42,7 +42,7 @@ RUN : \
&& apt-get install -y \
doxygen \
texlive-xetex fonts-sil-charis texlive-binaries texlive-fonts-extra \
&& pip install poxy==0.13.0 \
&& pip install poxy \
&& apt-get clean

# X11 recording tools
Expand All @@ -51,6 +51,25 @@ RUN : \
xvfb twm ffmpeg \
&& apt-get clean

# Install recent clang++
RUN : \
&& curl -fsSLO https://apt.llvm.org/llvm.sh && chmod +x llvm.sh \
&& yes | ./llvm.sh 17 && rm -f ./llvm.sh \
&& apt-get install -y clang-tidy-17 libclang-17-dev \
&& update-alternatives \
--install /usr/bin/clang clang /usr/bin/clang-17 0 \
--slave /usr/bin/clang++ clang++ /usr/bin/clang++-17 \
--slave /usr/bin/clang-tidy clang-tidy /usr/bin/clang-tidy-17 \
&& apt-get clean

# Build recent castxml
RUN : \
&& cd /tmp \
&& git clone https://github.com/CastXML/CastXML.git \
&& export CC=clang CXX=clang++ \
&& cd CastXML && cmake . && make -j`nproc` && sudo make install \
&& cd /tmp && rm -rf CastXML

# Nodejs - https://github.com/nodesource/distributions#nodejs
RUN : \
&& mkdir -p /etc/apt/keyrings \
Expand All @@ -61,17 +80,6 @@ RUN : \
&& apt-get install -y nodejs \
&& apt-get clean

# Install clang++
RUN : \
&& curl -fsSLO https://apt.llvm.org/llvm.sh && chmod +x llvm.sh \
&& yes | ./llvm.sh 17 && rm -f ./llvm.sh \
&& apt-get install -y clang-tidy-17 \
&& update-alternatives \
--install /usr/bin/clang clang /usr/bin/clang-17 0 \
--slave /usr/bin/clang++ clang++ /usr/bin/clang++-17 \
--slave /usr/bin/clang-tidy clang-tidy /usr/bin/clang-tidy-17 \
&& apt-get clean

# Build stripped down Fluidsynth version without drivers (not needed atm)
RUN exit 0 && \
mkdir -p /tmp/fluid/build && cd /tmp/fluid/ && \
Expand Down Expand Up @@ -100,5 +108,5 @@ RUN groupadd --gid 1000 ubuntu \
&& echo "ubuntu ALL=(ALL) NOPASSWD:ALL" > /etc/sudoers.d/ubuntu
USER ubuntu

# docker build -t cifocal:latest -f misc/Dockerfile.focal misc
# docker run -i -t --rm -v $PWD:/anklang -w /anklang cifocal:latest
# docker build -t focal:latest -f misc/Dockerfile.focal misc
# docker run -i -t --rm -v $PWD:/anklang -w /anklang focal:latest
2 changes: 1 addition & 1 deletion misc/Makefile.mk
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ $>/clang-tidy/%.log: % $(GITCOMMITDEPS) misc/Makefile.mk | $>/clang-tidy/
$Q mkdir -p $(dir $@) && rm -f $>/clang-tidy/$<.*
$Q set +o pipefail \
&& CTIDY_FLAGS=( $(ASE_EXTERNAL_INCLUDES) $(CLANG_TIDY_DEFS) $($<.LINT_CCFLAGS) ) \
&& [[ $< = @(*.[hc]) ]] || CTIDY_FLAGS+=( -std=gnu++17 ) \
&& [[ $< = @(*.[hc]) ]] || CTIDY_FLAGS+=( -std=gnu++20 ) \
&& (set -x ; $(CLANG_TIDY) --export-fixes=$>/clang-tidy/$<.yaml $< $($<.LINT_FLAGS) -- "$${CTIDY_FLAGS[@]}" ) >$@~ 2>&1 || :
$Q mv $@~ $@
CLANG_TIDY_DEFS := -I. -I$> -isystem external/ -isystem $>/external/ -DASE_COMPILATION $(ASEDEPS_CFLAGS) $(GTK2_CFLAGS)
Expand Down
8 changes: 6 additions & 2 deletions misc/config-uname.mk
Original file line number Diff line number Diff line change
Expand Up @@ -92,8 +92,12 @@ ifeq ($(uname_M),x86_64)
# 2006 era: Use just core2 features, but tune for newer CPUs
OPTIMIZE += -march=core2 -mtune=sandybridge
else ifeq ($(INSN),fma) # FMA AVX
# 2015 era: Use haswell (Intel) and bdver4 (AMD Excavator Family 15h) instructions (bdver4 lacks HLE)
OPTIMIZE += -march=haswell -mno-hle
ifdef HAVE_GCC # g++
# 2015 era: Use haswell (Intel) and bdver4 (AMD Excavator Family 15h) instructions (bdver4 lacks HLE)
OPTIMIZE += -march=haswell -mno-hle
else # clang++
OPTIMIZE += -march=x86-64-v3
endif
else # NATIVE
INSN = native
# Fastest, best for build machine CPU, not recommended for release builds
Expand Down
2 changes: 2 additions & 0 deletions misc/mkAppImage.sh
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,9 @@ LD_LIBRARY_PATH=$APPIMAGEPKGDIR/lib \
--appdir=$APPBASE \
--deploy-deps-only $APPIMAGEPKGDIR/bin/anklang \
--deploy-deps-only $APPIMAGEPKGDIR/lib/AnklangSynthEngine \
--deploy-deps-only $APPIMAGEPKGDIR/lib/AnklangSynthEngine-fma \
--deploy-deps-only $APPIMAGEPKGDIR/lib/gtk2wrap.so \
--deploy-deps-only $APPIMAGEPKGDIR/lib/jackdriver.so \
-i $APPIMAGEPKGDIR/ui/anklang.png \
-d $APPIMAGEPKGDIR/share/applications/anklang.desktop \
-l $LIB64/libXss.so.1 \
Expand Down
12 changes: 8 additions & 4 deletions misc/mkassets.sh
Original file line number Diff line number Diff line change
Expand Up @@ -13,21 +13,25 @@ rm -rf assets $BUILDDIR
mkdir -p $BUILDDIR assets/

# build dist tarball and ChangeLog in assets/
make dist
make -w V=${V:-} dist

# Extract release tarball and version
tar xf assets/anklang-*.tar.zst -C $BUILDDIR --strip-components=1

# Copy populated .dlcache/ to speed up builds
test -d .dlcache/ && cp -a --reflink=auto .dlcache/ $BUILDDIR/

# Copy compiler config variables over
test ! -r config-defaults.mk ||
grep '^ *[CL][CDLX]' config-defaults.mk >$BUILDDIR/config-defaults.mk

# Make production build + pdfs + package assets
( cd $BUILDDIR/
# Note, ase/ special cases MODE=production INSN=sse as non-native release builds
make default MODE=production INSN=sse
make -j`nproc` \
make -w V=${V:-} default MODE=production INSN=sse
make -w V=${V:-} -j`nproc` \
all assets/pdf
make check
make -w V=${V:-} check
misc/mkdeb.sh
misc/mkAppImage.sh
)
Expand Down

0 comments on commit 3a7c2d3

Please sign in to comment.