Skip to content

Commit

Permalink
qmake: better way to detect sse2 sse4.1 for qt4/5
Browse files Browse the repository at this point in the history
  • Loading branch information
wang-bin committed May 3, 2014
1 parent 97548cc commit d049166
Show file tree
Hide file tree
Showing 8 changed files with 108 additions and 68 deletions.
4 changes: 2 additions & 2 deletions QtAV.pro
Original file line number Diff line number Diff line change
Expand Up @@ -32,11 +32,11 @@ OTHER_FILES += \

EssentialDepends = avutil avcodec avformat swscale
OptionalDepends = \
sse2 \
sse4_1 \
swresample \
avresample \
gl
## sse2 sse4_1 may be defined in Qt5 qmodule.pri. Qt4 only defines sse and sse2
lessThan(QT_MAJOR_VERSION, 5): OptionalDepends *= sse4_1
# no-xxx can set in $$PWD/user.conf
!no-openal: OptionalDepends *= openal
!no-portaudio: OptionalDepends *= portaudio
Expand Down
29 changes: 29 additions & 0 deletions common.pri
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,35 @@ defineTest(empty_file) {
##TODO: add defineReplace(getValue): parameter is varname
lessThan(QT_MAJOR_VERSION, 5): {

win32-icc {
QMAKE_CFLAGS_SSE2 = -arch:SSE2
QMAKE_CFLAGS_SSE4_1 = -arch:SSE4.1
} else:*-icc { #mac, linux
QMAKE_CFLAGS_SSE2 = -xSSE2
QMAKE_CFLAGS_SSE4_1 = -xSSE4.1
} else:*msvc* {
QMAKE_CFLAGS_SSE2 = -arch:SSE2
QMAKE_CFLAGS_SSE4_1 = -arch:SSE2
} else {
QMAKE_CFLAGS_SSE2 = -msse2
QMAKE_CFLAGS_SSE4_1 = -msse4.1
}

sse4_1|config_sse4_1 {
HEADERS += $$SSE4_1_HEADERS

sse4_1_compiler.commands = $$QMAKE_CXX -c $(CXXFLAGS)
!contains(QT_CPU_FEATURES, sse4_1):sse4_1_compiler.commands += $$QMAKE_CFLAGS_SSE4_1
sse4_1_compiler.commands += $(INCPATH) ${QMAKE_FILE_IN} -o ${QMAKE_FILE_OUT}
sse4_1_compiler.dependency_type = TYPE_C
sse4_1_compiler.output = ${QMAKE_VAR_OBJECTS_DIR}${QMAKE_FILE_BASE}$${first(QMAKE_EXT_OBJ)}
sse4_1_compiler.input = SSE4_1_SOURCES
sse4_1_compiler.variable_out = OBJECTS
sse4_1_compiler.name = compiling[sse4_1] ${QMAKE_FILE_IN}
silent:sse4_1_compiler.commands = @echo compiling[sse4_1] ${QMAKE_FILE_IN} && $$sse4_1_compiler.commands
QMAKE_EXTRA_COMPILERS += sse4_1_compiler
}

defineTest(log){
system(echo $$system_quote($$1))
}
Expand Down
52 changes: 0 additions & 52 deletions config.tests/sse2/sse2.cpp

This file was deleted.

7 changes: 0 additions & 7 deletions config.tests/sse2/sse2.pro

This file was deleted.

33 changes: 30 additions & 3 deletions config.tests/sse4_1/sse4_1.pro
Original file line number Diff line number Diff line change
@@ -1,7 +1,34 @@
SOURCES = sse4_1.cpp
#SSE4_1_SOURCES = sse4_1.cpp
CONFIG -= qt dylib release debug_and_release
CONFIG += debug console
#qt5 only has gcc, qcc, vc, linux icc. clang?
win32-icc: QMAKE_CFLAGS_SSE4_1 *= -arch:SSE4.1
CONFIG += debug console sse4_1

# for Qt4. we can only detect sse2 in Qt4
#qt5 only has gcc, qcc, vc, linux icc.
win32-icc {
QMAKE_CFLAGS_SSE4_1 = -arch:SSE4.1
} else:*-icc { #mac, linux
QMAKE_CFLAGS_SSE4_1 = -xSSE4.1
} else:*msvc* {
QMAKE_CFLAGS_SSE4_1 = -arch:SSE2
} else {
QMAKE_CFLAGS_SSE4_1 = -msse4.1
}

sse4_1 {
HEADERS += $$SSE4_1_HEADERS

sse4_1_compiler.commands = $$QMAKE_CXX -c $(CXXFLAGS)
!contains(QT_CPU_FEATURES, sse4_1):sse4_1_compiler.commands += $$QMAKE_CFLAGS_SSE4_1
sse4_1_compiler.commands += $(INCPATH) ${QMAKE_FILE_IN} -o ${QMAKE_FILE_OUT}
sse4_1_compiler.dependency_type = TYPE_C
sse4_1_compiler.output = ${QMAKE_VAR_OBJECTS_DIR}${QMAKE_FILE_BASE}$${first(QMAKE_EXT_OBJ)}
sse4_1_compiler.input = SSE4_1_SOURCES
sse4_1_compiler.variable_out = OBJECTS
sse4_1_compiler.name = compiling[sse4_1] ${QMAKE_FILE_IN}
silent:sse4_1_compiler.commands = @echo compiling[sse4_1] ${QMAKE_FILE_IN} && $$sse4_1_compiler.commands
QMAKE_EXTRA_COMPILERS += sse4_1_compiler
}

isEmpty(QMAKE_CFLAGS_SSE4_1):error("This compiler does not support SSE4.1")
else:QMAKE_CXXFLAGS += $$QMAKE_CFLAGS_SSE4_1
7 changes: 5 additions & 2 deletions src/libQtAV.pro
Original file line number Diff line number Diff line change
Expand Up @@ -32,11 +32,13 @@ win32 {
OTHER_FILES += $$RC_FILE
TRANSLATIONS = $${PROJECTROOT}/i18n/QtAV_zh_CN.ts

config_sse4_1|contains(TARGET_ARCH_SUB, sse4.1) {
## sse2 sse4_1 may be defined in Qt5 qmodule.pri. Qt4 only defines sse and sse2
sse4_1|config_sse4_1|contains(TARGET_ARCH_SUB, sse4.1) {
DEFINES += QTAV_HAVE_SSE4_1=1
## TODO: use SSE4_1_SOURCES
QMAKE_CXXFLAGS += $$QMAKE_CFLAGS_SSE4_1 #gcc -msse4.1
}
config_sse2|contains(TARGET_ARCH_SUB, sse2) {
sse2|config_sse2|contains(TARGET_ARCH_SUB, sse2) {
DEFINES += QTAV_HAVE_SSE2=1
QMAKE_CXXFLAGS += $$QMAKE_CFLAGS_SSE2 #gcc -msse2
}
Expand Down Expand Up @@ -172,6 +174,7 @@ config_libcedarv {
SOURCES += VideoDecoderCedarv.cpp
LIBS += -lvecore -lcedarv
}

SOURCES += \
QtAV_Compat.cpp \
QtAV_Global.cpp \
Expand Down
22 changes: 21 additions & 1 deletion src/utils/GPUMemCopy.cpp
Original file line number Diff line number Diff line change
@@ -1,3 +1,24 @@
/******************************************************************************
QtAV: Media play library based on Qt and FFmpeg
Copyright (C) 2012-2014 Wang Bin <[email protected]>
* This file is part of QtAV
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 2.1 of the License, or (at your option) any later version.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public
License along with this library; if not, write to the Free Software
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
******************************************************************************/

#include "GPUMemCopy.h"

#include <stdlib.h>
Expand All @@ -13,7 +34,6 @@
#include <smmintrin.h> //stream load
#endif


/* Branch prediction */
#ifdef __GNUC__
# define likely(p) __builtin_expect(!!(p), 1)
Expand Down
22 changes: 21 additions & 1 deletion src/utils/GPUMemCopy.h
Original file line number Diff line number Diff line change
@@ -1,3 +1,24 @@
/******************************************************************************
QtAV: Media play library based on Qt and FFmpeg
Copyright (C) 2012-2014 Wang Bin <[email protected]>
* This file is part of QtAV
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 2.1 of the License, or (at your option) any later version.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public
License along with this library; if not, write to the Free Software
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
******************************************************************************/

#ifndef GPUMemCopy_H
#define GPUMemCopy_H

Expand All @@ -9,7 +30,6 @@ class GPUMemCopy
{
public:
static bool isAvailable();

GPUMemCopy();
~GPUMemCopy();

Expand Down

0 comments on commit d049166

Please sign in to comment.