TF++, Miscellaneous classes and modules in C++:

◆ cpu()

Ecpu_type tfxx::ioswap::cpu ( )

Check CPU model. ,.

check for my CPU model

Returns
return value indicates the CPU model found
Examples:
tests/fortraniotest.cc.

Definition at line 80 of file ioswap.cc.

References tfxx::ioswap::IOUnion< T >::bytes, cpu_Intel, cpu_Motorola, cpu_unknown, magic(), TFXX_assert, and tfxx::ioswap::IOUnion< T >::value.

Referenced by cpu_type().

81 {
82  Ecpu_type result=cpu_unknown;
83  IOUnion<int> u1,u2;
84  TFXX_assert((sizeof(int) == 4),
85  "The integer memory size on this CPU differs from the"
86  "required value of 4");
87  const int& intsize=sizeof(int);
88  char test_seq[]="ABCD";
89  // prepare sequence and reverse sequence
90  for (int i=0; i<intsize; i++)
91  {
92  u1.bytes[i]=test_seq[i];
93  u2.bytes[i]=test_seq[intsize-i-1];
94  }
95  // request magic number for sequence
96  int magnum=magic(u1.bytes);
97  // test against byte representation of sequence and reverse sequence
98  if (magnum == u1.value)
99  {
100  result=cpu_Motorola;
101  }
102  else if (magnum == u2.value)
103  {
104  result=cpu_Intel;
105  }
106  return(result);
107 } // cpu()
#define TFXX_assert(C, M)
Check an assertion and report by throwing an exception.
Definition: error.h:175
Ecpu_type
Define different CPU type that are recognized.
Definition: bytesex.h:104
int magic(const char *const cmagic)
Create a magic number from a character string. ,If represents the input character sequence cmagic an...
Definition: ioswap.cc:59
Motorola CPU.
Definition: bytesex.h:108
Here is the call graph for this function:
Here is the caller graph for this function: