1
0
mirror of https://github.com/f4exb/sdrangel.git synced 2024-12-22 17:45:48 -05:00

Strict aliasing.

This commit is contained in:
John Greb 2014-11-22 21:55:35 +00:00
parent 25cffee789
commit 836796fff4
5 changed files with 75 additions and 58 deletions

View File

@ -9,8 +9,6 @@ project(sdrangelove)
set(CMAKE_BUILD_TYPE "Release")
#set(CMAKE_BUILD_TYPE "ReleaseWithDebugInfo")
#set(CMAKE_BUILD_TYPE "Debug")
add_definitions(-Wall -fno-strict-aliasing)
set(QT_USE_QTOPENGL TRUE)
set(CMAKE_AUTOMOC ON)
@ -99,7 +97,7 @@ set(sdrbase_SOURCES
sdrbase/util/message.cpp
sdrbase/util/messagequeue.cpp
sdrbase/util/miniz.cpp
#sdrbase/util/miniz.cpp
sdrbase/util/simpleserializer.cpp
sdrbase/util/spinlock.cpp
)
@ -170,7 +168,7 @@ set(sdrbase_HEADERS
include/util/export.h
include/util/message.h
include/util/messagequeue.h
include/util/miniz.h
#include/util/miniz.h
include/util/simpleserializer.h
include/util/spinlock.h
)
@ -265,8 +263,9 @@ if(MSVC)
set( CMAKE_EXE_LINKER_FLAGS_RELEASE "${CMAKE_EXE_LINKER_FLAGS_RELEASE} /LTCG" )
add_definitions (/D "_CRT_SECURE_NO_WARNINGS")
else()
set( CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE} -msse2" )
set( CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} -msse2" )
#set( CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE} -msse2" )
#set( CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} -msse2" )
add_definitions(-msse2 -Wall)
endif()
##############################################################################

View File

@ -1,7 +1,7 @@
project(samplesource)
find_package(LibUSB)
find_package(LibOsmoSDR)
#find_package(LibOsmoSDR)
add_subdirectory(gnuradio)

View File

@ -339,8 +339,8 @@ void MainWindow::updateStatus()
m_engineRunning->setColor(Qt::gray);
m_engineError->setColor(Qt::gray);
statusBar()->clearMessage();
if(m_startOsmoSDRUpdateAfterStop)
on_actionOsmoSDR_Firmware_Upgrade_triggered();
//if(m_startOsmoSDRUpdateAfterStop)
// on_actionOsmoSDR_Firmware_Upgrade_triggered();
break;
case DSPEngine::StRunning:
@ -355,8 +355,8 @@ void MainWindow::updateStatus()
m_engineRunning->setColor(Qt::gray);
m_engineError->setColor(Qt::red);
statusBar()->showMessage(tr("Error: %1").arg(m_dspEngine->errorMessage()));
if(m_startOsmoSDRUpdateAfterStop)
on_actionOsmoSDR_Firmware_Upgrade_triggered();
//if(m_startOsmoSDRUpdateAfterStop)
// on_actionOsmoSDR_Firmware_Upgrade_triggered();
break;
}
m_lastEngineState = state;
@ -401,6 +401,7 @@ void MainWindow::on_action_View_Fullscreen_toggled(bool checked)
void MainWindow::on_actionOsmoSDR_Firmware_Upgrade_triggered()
{
#if 0
DSPEngine::State engineState = m_dspEngine->state();
if((engineState != DSPEngine::StIdle) && (engineState != DSPEngine::StError)) {
m_startOsmoSDRUpdateAfterStop = true;
@ -412,6 +413,7 @@ void MainWindow::on_actionOsmoSDR_Firmware_Upgrade_triggered()
OsmoSDRUpgrade osmoSDRUpgrade;
osmoSDRUpgrade.exec();
*/
#endif
}
void MainWindow::on_presetSave_clicked()

View File

@ -50,15 +50,9 @@
<property name="title">
<string>&amp;File</string>
</property>
<addaction name="action_Exit"/>
</widget>
<widget class="QMenu" name="menu_Options">
<property name="title">
<string>&amp;Options</string>
</property>
<addaction name="actionOsmoSDR_Firmware_Upgrade"/>
<addaction name="separator"/>
<addaction name="action_Preferences"/>
<addaction name="separator"/>
<addaction name="action_Exit"/>
</widget>
<widget class="QMenu" name="menu_Acquisition">
<property name="title">
@ -79,9 +73,9 @@
<property name="title">
<string>&amp;Help</string>
</property>
<addaction name="action_Open_Website"/>
<!--addaction name="action_Open_Website"/>
<addaction name="action_Check_for_Update"/>
<addaction name="separator"/>
<addaction name="separator"/-->
<addaction name="action_Loaded_Plugins"/>
<addaction name="separator"/>
<addaction name="action_About"/>
@ -100,7 +94,7 @@
<addaction name="menu_View"/>
<addaction name="menu_Acquisition"/>
<addaction name="menu_Channels"/>
<addaction name="menu_Options"/>
<!--addaction name="menu_Options"/-->
<addaction name="menu_Window"/>
<addaction name="menu_Help"/>
</widget>
@ -371,11 +365,11 @@
<string>F11</string>
</property>
</action>
<action name="actionOsmoSDR_Firmware_Upgrade">
<!--action name="actionOsmoSDR_Firmware_Upgrade">
<property name="text">
<string>OsmoSDR &amp;Firmware Upgrade...</string>
</property>
</action>
</action-->
<action name="action_Oscilloscope">
<property name="checkable">
<bool>true</bool>
@ -407,16 +401,16 @@
<string>&amp;Preferences...</string>
</property>
</action>
<action name="action_Demod_NFM">
<!--action name="action_Demod_NFM">
<property name="text">
<string>N&amp;FM</string>
</property>
</action>
<action name="action_Tetra">
<action name="action_Demod_SSB">
<property name="text">
<string>&amp;Tetra</string>
<string>&amp;SSB</string>
</property>
</action>
</action-->
<action name="action_Loaded_Plugins">
<property name="text">
<string>Loaded &amp;Plugins...</string>

View File

@ -165,8 +165,14 @@ void SimpleSerializer::writeU64(quint32 id, quint64 value)
m_data.push_back((char)((value >> (i * 8)) & 0xff));
}
union floatasint {
quint32 u;
float f;
};
void SimpleSerializer::writeFloat(quint32 id, float value)
{
union floatasint tmp;
if(id == 0) {
qCritical("SimpleSerializer: ID 0 is not allowed");
return;
@ -175,15 +181,21 @@ void SimpleSerializer::writeFloat(quint32 id, float value)
if(!writeTag(TFloat, id, 4))
return;
quint32 tmp = *((quint32*)&value);
m_data.push_back((char)((tmp >> 24) & 0xff));
m_data.push_back((char)((tmp >> 16) & 0xff));
m_data.push_back((char)((tmp >> 8) & 0xff));
m_data.push_back((char)(tmp & 0xff));
tmp.f = value;
m_data.push_back((char)((tmp.u >> 24) & 0xff));
m_data.push_back((char)((tmp.u >> 16) & 0xff));
m_data.push_back((char)((tmp.u >> 8) & 0xff));
m_data.push_back((char)(tmp.u & 0xff));
}
union doubleasint {
quint64 u;
double d;
};
void SimpleSerializer::writeDouble(quint32 id, double value)
{
union doubleasint tmp;
if(id == 0) {
qCritical("SimpleSerializer: ID 0 is not allowed");
return;
@ -192,15 +204,15 @@ void SimpleSerializer::writeDouble(quint32 id, double value)
if(!writeTag(TDouble, id, 8))
return;
quint64 tmp = *((quint64*)&value);
m_data.push_back((char)((tmp >> 56) & 0xff));
m_data.push_back((char)((tmp >> 48) & 0xff));
m_data.push_back((char)((tmp >> 40) & 0xff));
m_data.push_back((char)((tmp >> 32) & 0xff));
m_data.push_back((char)((tmp >> 24) & 0xff));
m_data.push_back((char)((tmp >> 16) & 0xff));
m_data.push_back((char)((tmp >> 8) & 0xff));
m_data.push_back((char)(tmp & 0xff));
tmp.d = value;
m_data.push_back((char)((tmp.u >> 56) & 0xff));
m_data.push_back((char)((tmp.u >> 48) & 0xff));
m_data.push_back((char)((tmp.u >> 40) & 0xff));
m_data.push_back((char)((tmp.u >> 32) & 0xff));
m_data.push_back((char)((tmp.u >> 24) & 0xff));
m_data.push_back((char)((tmp.u >> 16) & 0xff));
m_data.push_back((char)((tmp.u >> 8) & 0xff));
m_data.push_back((char)(tmp.u & 0xff));
}
void SimpleSerializer::writeBool(quint32 id, bool value)
@ -414,7 +426,7 @@ returnDefault:
bool SimpleDeserializer::readFloat(quint32 id, float* result, float def) const
{
uint readOfs;
quint32 tmp;
union floatasint tmp;
Elements::const_iterator it = m_elements.constFind(id);
if(it == m_elements.constEnd())
goto returnDefault;
@ -424,10 +436,10 @@ bool SimpleDeserializer::readFloat(quint32 id, float* result, float def) const
goto returnDefault;
readOfs = it->ofs;
tmp = 0;
tmp.u = 0;
for(int i = 0; i < 4; i++)
tmp = (tmp << 8) | readByte(&readOfs);
*result = *((float*)&tmp);
tmp.u = (tmp.u << 8) | readByte(&readOfs);
*result = tmp.f;
return true;
returnDefault:
@ -438,7 +450,7 @@ returnDefault:
bool SimpleDeserializer::readDouble(quint32 id, double* result, double def) const
{
uint readOfs;
quint64 tmp;
union doubleasint tmp;
Elements::const_iterator it = m_elements.constFind(id);
if(it == m_elements.constEnd())
goto returnDefault;
@ -448,10 +460,10 @@ bool SimpleDeserializer::readDouble(quint32 id, double* result, double def) cons
goto returnDefault;
readOfs = it->ofs;
tmp = 0;
tmp.u = 0;
for(int i = 0; i < 8; i++)
tmp = (tmp << 8) | readByte(&readOfs);
*result = *((double*)&tmp);
tmp.u = (tmp.u << 8) | readByte(&readOfs);
*result = tmp.d;
return true;
returnDefault:
@ -459,11 +471,21 @@ returnDefault:
return false;
}
union real4asint {
quint32 u;
Real r;
};
union real8asint {
quint64 u;
Real r;
};
bool SimpleDeserializer::readReal(quint32 id, Real* result, Real def) const
{
if(sizeof(Real) == 4) {
uint readOfs;
quint32 tmp;
union real4asint tmp;
Elements::const_iterator it = m_elements.constFind(id);
if(it == m_elements.constEnd())
goto returnDefault32;
@ -473,10 +495,10 @@ bool SimpleDeserializer::readReal(quint32 id, Real* result, Real def) const
goto returnDefault32;
readOfs = it->ofs;
tmp = 0;
tmp.u = 0;
for(int i = 0; i < 4; i++)
tmp = (tmp << 8) | readByte(&readOfs);
*result = *((Real*)&tmp);
tmp.u = (tmp.u << 8) | readByte(&readOfs);
*result = tmp.r;
return true;
returnDefault32:
@ -484,7 +506,7 @@ bool SimpleDeserializer::readReal(quint32 id, Real* result, Real def) const
return false;
} else {
uint readOfs;
quint64 tmp;
union real8asint tmp;
Elements::const_iterator it = m_elements.constFind(id);
if(it == m_elements.constEnd())
goto returnDefault64;
@ -494,10 +516,10 @@ bool SimpleDeserializer::readReal(quint32 id, Real* result, Real def) const
goto returnDefault64;
readOfs = it->ofs;
tmp = 0;
tmp.u = 0;
for(int i = 0; i < 8; i++)
tmp = (tmp << 8) | readByte(&readOfs);
*result = *((Real*)&tmp);
tmp.u = (tmp.u << 8) | readByte(&readOfs);
*result = tmp.r;
return true;
returnDefault64: