C言語に基づくDataLabのデータ表現実験

目次

第1章 実験の基本情報 - 4 -
1.1 実験の目的 - 4 -
1.2 実験環境とツール - 4 -
1.2.1 ハードウェア環境 - 4 -
1.2.2 ソフトウェア環境 - 4 -
1.2.3 開発ツール - 4 -
1.3 実験プレビュー - 4 -
第 2 章 実験環境の構築 - 5 -
2.1 Ubuntu での CodeBlocks のインストール (5 点) - 5 -
2.2 64 ビット Ubuntu での 32 ビット動作環境の構築 (5 点) - 5 -
第 3 章 ビット操作命令C言語編 - 6 -
3.1 論理演算(1点) - 6 -
3.2 符号なしビット演算(2点) - 6 -
3.3 符号付きビット演算(2点) - 6 -
第4章 アセンブリ言語のビット演算命令 - 7 -
4.1論理演算(1点) - 7 -
4.2 符号なし左右シフト(2点) - 7 -
4.3 符号付き左右シフト(2点) - 7 -
4.4 循環シフト(2点) - 7 -
4.5 キャリービットあり 循環シフト(2点) - 7 -
4.6 テスト、ビットテストBTx(2点) - 7 -
4.7 条件転送CMOVxx(2点) - 7 -
4.8 条件設定SETCxx(1点) - 7 -
4.9 キャリービット演算(1点) ) - 7 -
第 5 章 BITS 機能の実験と解析 - 8 -
5.1 関数lsbZeroの実装と説明 - 8 -
5.2 関数byteNotの実装と説明 - 8 -
5.3 関数byteXorの実装と説明 - 8 -
5.4 関数logicalAndの実装と説明 - 8 -
5.5 関数logicalOrの実装と説明 関数 - 8 -
5.6 関数rotateLeft関数の実装と説明 - 8 -
5.7 関数parityCheck関数の実装と説明 - 8 -
5.8 関数mul2OK関数の実装と説明 - 9 -
5.9 関数mult3div2関数の実装と説明 - 9 -
5.10 関数subOK の記述関数 - 9 -
5.11 関数 absVal の実装と記述関数 - 9 -
5.12 関数 float_abs の実装と記述関数 - 9 -
5.13 関数 float_f2i の実装と記述関数 - 9 - 5.14 関数 float_f2i の
実装と記述関数 - 9 - 5.14 function XXXX (CMU からの追加機能 - ポイントなし) - 9 -
第 6 章のまとめ - 10 -
10.1 この実験の結果を要約してください - 10 -
10.2 この実験の内容について提案してください - 10 -
参考文献 - 11 -
1.2実験環境とツール
1.2.1 ハードウェア環境
X64 CPU; 2.5GHz; 8G RAM; 500GHD ディスク以上
1.2.2 ソフトウェア環境
Windows10 64 ビット; VirtualBox; Ubuntu 16.04 LTS 64 ビット;
1.2.3 開発ツール
Visual Studio 2017 64 ビット; CodeBlocks; /vim/gpedit+gcc
1.3 実験プレビュー
1 論理演算
論理 AND x=x&x;
論理 OR x= x|x ;
論理 NOT x=~ x ;OR排他的
論理



論理演算:
論理 AND AND %rax、%rbx
論理 OR OR %rax、%rbx
論理排他的 OR XOR %rax、%rbx
論理 NOT NOT %rax、%rbx

符号なし数値の左および右シフト
論理左シフト SHL %rax、%rbx
論理右シフト SHR %rax、%rbx

符号付き左右
シフト 算術左シフト SAL: %rax、%rbx
算術右シフト SAR: %rax、%rbx

回転シフト
左回転: ROL %rax、%rbx
右回転: ROR %rax、%rbx

キャリー ビットによる回転シフト キャリー
ビットによる左回転: RCL %rax、%rbx
キャリー ビットによる右回転: RCR %rax、%rbx

テスト、ビット テスト BTx は
指定されたビット n をキャリー フラグにコピーし、宛先オペランドには演算対象のビット番号 n が含まれます。BT はソース オペランドのビット n をキャリー フラグにコピーし、BTC はソース オペランドのビット n をキャリー フラグにコピーし、ビット n を反転します。BTR はソース オペランドのビット n をキャリー フラグにコピーし、ビット n を反転します。n はクリアされ、BTS はソース オペランドのビット n をキャリー フラグにコピーし、ビット n を 1 に設定します。ビットごとの AND (演算結果は保存されません。その値はフラグ ビットの値を変更します)
TEST %rax、%rbx
BT 2、%rax
BTC 2、%rax
BTR 2、%rax
BTS 2、%rax

条件付き転送 CMOVxx
CMOV+a、b、e、n、l はそれぞれ、「より大きい」、「より小さい」、「等しい」、否定、キャリーを表します。 符号付き数値:
g、l、e、n、o はそれぞれ、「より大きい」、「より小さい」、「より小さい」を表します。等しい、いいえ、オーバーフロー
CMOVO、オーバーフロー OF = 1 の場合、
CMOVNO を転送、オーバーフロー OF = 0 の場合、
CMOVS を転送、符号付き (負)、SF = 1、転送
CMOVNS、符号なし (非負)、SF = 0、転送

/* Testing Code */

#include <limits.h>
#include <math.h>

/* Routines used by floation point test code */

/* Convert from bit level representation to floating point number */
float u2f(unsigned u) {
    
    
  union {
    
    
    unsigned u;
    float f;
  } a;
  a.u = u;
  return a.f;
}

/* Convert from floating point number to bit-level representation */
unsigned f2u(float f) {
    
    
  union {
    
    
    unsigned u;
    float f;
  } a;
  a.f = f;
  return a.u;
}

/* Copyright (C) 1991-2016 Free Software Foundation, Inc.
   This file is part of the GNU C Library.

   The GNU C 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.

   The GNU C 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 the GNU C Library; if not, see
   <http://www.gnu.org/licenses/>.  */
/* This header is separate from features.h so that the compiler can
   include it implicitly at the start of every compilation.  It must
   not itself include <features.h> or any other header that includes
   <features.h> because the implicit include comes before any feature
   test macros that may be defined in a source file before it first
   explicitly includes a system header.  GCC knows the name of this
   header in order to preinclude it.  */
/* glibc's intent is to support the IEC 559 math functionality, real
   and complex.  If the GCC (4.9 and later) predefined macros
   specifying compiler intent are available, use them to determine
   whether the overall intent is to support these features; otherwise,
   presume an older compiler has intent to support these features and
   define these macros by default.  */
/* wchar_t uses Unicode 8.0.0.  Version 8.0 of the Unicode Standard is
   synchronized with ISO/IEC 10646:2014, plus Amendment 1 (published
   2015-05-15).  */
/* We do not support C11 <threads.h>.  */
int test_lsbZero(int x) {
    
    
 if((x>0 && x%2==1) ||(x<0 && x%2==-1))
   x--;
 return x;
}
int test_byteNot(int x, int n)
{
    
    
    union {
    
    
  int xs;
  char b[4];
 }exp;
 exp.xs=x;
 exp.b[n]=~exp.b[n];
 return x=exp.xs;
}
int test_byteXor(int x, int y, int n) {
    
    
  union {
    
    
  int xs;
  char b[4];
 }exp1,exp2;
 exp1.xs=x;
 exp2.xs=y;
 return (exp1.b[n] - exp2.b[n]) != 0;
}
int test_logicalAnd(int x, int y) {
    
    
  return x && y;
}
int test_logicalOr(int x, int y) {
    
    
  return x || y;
}
int test_rotateLeft(int x, int n) {
    
    
  unsigned u = (unsigned) x;
  int i;
  for (i = 0; i < n; i++) {
    
    
      unsigned msb = u >> 31;
      unsigned rest = u << 1;
      u = rest | msb;
  }
  return (int) u;
}
int test_parityCheck(int x) {
    
    
  int result = 0;
  int i;
  for (i = 0; i < 32; i++)
    result ^= (x >> i) & 0x1;
  return result;
}
int test_mul2OK(int x)
{
    
    
  if ((x+x)/2 != x)
    return 0;
  else
    return 1;
}
int test_mult3div2(int x)
{
    
    
  return (x*3)/2;
}
int test_subOK(int x, int y)
{
    
    
  long long ldiff = (long long) x - y;
  return ldiff == (int) ldiff;
}
int test_absVal(int x) {
    
    
  return (x < 0) ? -x : x;
}
unsigned test_float_abs(unsigned uf) {
    
    
  float f = u2f(uf);
  unsigned unf = f2u(-f);
  if (isnan(f))
    return uf;
  /* An unfortunate hack to get around a limitation of the BDD Checker */
  if ((int) uf < 0)
      return unf;
  else
      return uf;
}
int test_float_f2i(unsigned uf) {
    
    
  float f = u2f(uf);
  int x = (int) f;
  return x;
}

ここに画像の説明を挿入します
ここに画像の説明を挿入します
ここに画像の説明を挿入します
ここに画像の説明を挿入します
ここに画像の説明を挿入します
ここに画像の説明を挿入します
ここに画像の説明を挿入します
ここに画像の説明を挿入します
ここに画像の説明を挿入します
ここに画像の説明を挿入します
ここに画像の説明を挿入します
ここに画像の説明を挿入します
ここに画像の説明を挿入します
ここに画像の説明を挿入します
ここに画像の説明を挿入します
ここに画像の説明を挿入します
ここに画像の説明を挿入します
ここに画像の説明を挿入します
ここに画像の説明を挿入します
ここに画像の説明を挿入します
ここに画像の説明を挿入します
ここに画像の説明を挿入します
ここに画像の説明を挿入します
ここに画像の説明を挿入します

おすすめ

転載: blog.csdn.net/newlw/article/details/132799238