[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[lmi-commits] [lmi] master c74ec0d 1/4: Use fixed-width integers where a
From: |
Greg Chicares |
Subject: |
[lmi-commits] [lmi] master c74ec0d 1/4: Use fixed-width integers where appropriate |
Date: |
Thu, 7 Jun 2018 06:37:03 -0400 (EDT) |
branch: master
commit c74ec0df98964a06b99db65025aead109fc70d07
Author: Gregory W. Chicares <address@hidden>
Commit: Gregory W. Chicares <address@hidden>
Use fixed-width integers where appropriate
The x87 control word has a fixed width.
---
fenv_lmi_test.cpp | 8 ++++----
fenv_lmi_x86.hpp | 23 ++++++++++++-----------
2 files changed, 16 insertions(+), 15 deletions(-)
diff --git a/fenv_lmi_test.cpp b/fenv_lmi_test.cpp
index 461f9b9..dc6a472 100644
--- a/fenv_lmi_test.cpp
+++ b/fenv_lmi_test.cpp
@@ -45,9 +45,9 @@
#include <math.h> // rint()
#include <stdexcept>
-std::bitset<CHAR_BIT * sizeof(unsigned long int)> bits(unsigned long int i)
+std::bitset<CHAR_BIT * sizeof(std::uint32_t)> bits(std::uint32_t i)
{
- return std::bitset<CHAR_BIT * sizeof(unsigned long int)>(i);
+ return std::bitset<CHAR_BIT * sizeof(std::uint32_t)>(i);
}
#define BOOST_TEST_EQUAL_BITS(a,b) \
@@ -65,7 +65,7 @@ std::bitset<CHAR_BIT * sizeof(unsigned long int)>
bits(unsigned long int i)
int test_main(int, char*[])
{
#if defined LMI_X87
- unsigned short int cw = 0x0000;
+ std::uint16_t cw = 0x0000;
BOOST_TEST_EQUAL_BITS(0x037f, msvc_to_intel(0x0008001f));
@@ -88,7 +88,7 @@ int test_main(int, char*[])
// ...but bit 12, the deprecated IC, remains settable.
x87_control_word
- (static_cast<unsigned short int>
+ (static_cast<std::uint16_t>
(~intel_control_word_parameters::settable
)
);
diff --git a/fenv_lmi_x86.hpp b/fenv_lmi_x86.hpp
index c108a73..942687e 100644
--- a/fenv_lmi_x86.hpp
+++ b/fenv_lmi_x86.hpp
@@ -25,6 +25,7 @@
#include "config.hpp"
#include <bitset>
+#include <cstdint>
#include <stdexcept>
#if defined __BORLANDC__ || defined _MSC_VER
@@ -152,7 +153,7 @@ enum e_x87_rounding
struct intel_control_word_parameters
{
- typedef unsigned short int integer_type;
+ typedef std::uint16_t integer_type;
enum {nbits = 16};
typedef e_x87_precision pc_type;
typedef e_x87_rounding rc_type;
@@ -220,7 +221,7 @@ class control_word
typedef typename std::bitset<ControlWordType::nbits>::reference ref_type;
public:
- control_word(unsigned long int w)
+ control_word(std::uint32_t w)
{
cw_ = ControlWordType::reserved_values | ControlWordType::settable & w;
}
@@ -288,37 +289,37 @@ inline unsigned int intel_to_msvc(intel_control_word i)
return msvc_control_word(i).cw();
}
-inline unsigned int intel_to_msvc(unsigned short int i)
+inline unsigned int intel_to_msvc(std::uint16_t i)
{
return intel_to_msvc(intel_control_word(i));
}
-inline unsigned short int msvc_to_intel(msvc_control_word m)
+inline std::uint16_t msvc_to_intel(msvc_control_word m)
{
return intel_control_word(m).cw();
}
-inline unsigned short int msvc_to_intel(unsigned int m)
+inline std::uint16_t msvc_to_intel(unsigned int m)
{
return msvc_to_intel(msvc_control_word(m));
}
/// Default settings for x87 fpu.
-inline unsigned short int default_x87_control_word()
+inline std::uint16_t default_x87_control_word()
{
return 0x037f;
}
/// Fetch settings for x87 fpu.
-inline unsigned short int x87_control_word()
+inline std::uint16_t x87_control_word()
{
- unsigned short int volatile control_word = 0x0;
+ std::uint16_t volatile control_word = 0x0;
# if defined __GNUC__
asm volatile("fstcw %0" : : "m" (control_word));
# elif defined __BORLANDC__
- control_word = static_cast<unsigned short int>(_control87(0, 0));
+ control_word = static_cast<std::uint16_t>(_control87(0, 0));
# elif defined _MSC_VER
// Test _MSC_VER last: some non-ms compilers or libraries define it.
control_word = msvc_to_intel(_control87(0, 0));
@@ -330,10 +331,10 @@ inline unsigned short int x87_control_word()
/// Change settings for x87 fpu.
-inline void x87_control_word(unsigned short int cw)
+inline void x87_control_word(std::uint16_t cw)
{
# if defined __GNUC__
- unsigned short int volatile control_word = cw;
+ std::uint16_t volatile control_word = cw;
asm volatile("fldcw %0" : : "m" (control_word));
# elif defined __BORLANDC__
_control87(cw, 0x0ffff);