Skip to content
Snippets Groups Projects
Commit 40ec3287 authored by Nayoung Kim's avatar Nayoung Kim
Browse files

Update LEC12

parent ae64b2bd
Branches
No related tags found
No related merge requests found
......@@ -1744,3 +1744,152 @@ input 4 values with 0~255 : 127 127 127 127
127 127 127 127 : 1061109567 0x3f3f3f3f
127 127 127 127 : 1061109567 0x3f3f3f3f
```
## **Lecture 12** [2022.01.24]
### Final Project (fx_s17.14)
* fx_head.h
```
#pragma once
#define FX_S17_14 ((1<<16) | (17<<8) | (14))
// Operation Preference
#define FX_OP_FLOAT 1
#define FX_OP_PRECISION 2
#define FX_OP_FAIR 3
#define FX_OP_PERFORMANCE 4
```
* fx_s17_14.h
```
#include "fx_head.h"
#include <math.h>
#define FX_POINT FX_S17_14
#define FX_Q_NUM (FX_POINT & 0xFF) // 16
// If you want calculate with high precision set 64
#define FX_SYSTEM_INTEGER 64 // 32 or 64
#define FX_SYSTEM_FLOAT 64 // 32 or 64
#define FX_DATA_TYPE signed int
typedef int fx_s17_14;
typedef fx_s17_14 fixed;
#define fromDouble(d) ((fixed)((d)*DOUBLE_Q_VALUE))
#define toDouble(d) ((double)(d)*DOUBLE_1_Q_VALUE)
#define fromFloat(d) ((fixed)((d)*FLOAT_Q_VALUE))
#define toFloat(d) ((float)(d)*FLOAT_1_Q_VALUE)
// CONSTANTS
#define FLOAT_Q_VALUE (float)(1<<FX_Q_NUM)
#define DOUBLE_Q_VALUE (double)(1<<FX_Q_NUM)
#define FLOAT_1_Q_VALUE (float)(1.0f/FLOAT_Q_VALUE)
#define DOUBLE_1_Q_VALUE (double)(1.0f/DOUBLE_Q_VALUE)
#define FX_PI fromDOUBLE(M_PI)
// One of FX_OP_FLOAT, FX_OP_PRECISION, FX_OP_FAIR, FX_OP_PERFORMANCE
#define FX_OP_PREFERENCE FX_OP_FLOAT
extern fixed fxAdd_float(), fxAdd_precision(), fxAdd_fair(), fxAdd_performance();
extern fixed fxSub_float(), fxSub_precision(), fxSub_fair(), fxSub_performance();
extern fixed fxMul_float(), fxMul_precision(), fxMul_fair(), fxMul_performance();
extern fixed fxDiv_float(), fxDiv_precision(), fxDiv_fair(), fxDiv_performance();
```
* project_main.c
```
#include "fx_s17_14.h"
#include <stdio.h>
int main()
{
printf("%f : %d\n",1.0, fromDouble(1.0));
printf("%f : %f\n",1.3*0.3, toFloat(fxMul_float(fromDouble(1.3),fromDouble(0.3)))) ;
}
```
* cc project_main.c fx_s17_14.c 실행 결과
1.000000 : 16384
0.390000 : 0.389954
### Make (GNU make)
* Lots of source files: foo1.h, foo2.h, foobar1.cpp ...
* How to manage them allocated
* Compiling is not easy
* different target system
* different purpose of compiling - debug, release, preprocessor ...
* compile what we need to
* dependency
* Solution is
* make
### Understanding MAKE
* 파일 간의 종속관계를 파악하여 Makefile에 적힌 대로 컴파일러에 명령하고 SHELL 명령이 순차적으로 실행될 수 있게 함
* MAKE를 쓰는 이유
* 각 파일에 대한 반복적 명령의 자동화로 인한 시간 절약
* 프로그램의 종속 구조를 빠르게 파악할 수 있으며 관리가 용이
* 단순 반복 작업 및 재작성을 최소화
* Makefile의 구성
* 목적파일(Target) : 명령어가 수행되어 나온 결과를 저장할 파일
* 의존성(Dependency) : 목적파일을 만들기 위해 필요한 재료
* 명령어(Command) : 실행되어야 할 명령어들
* 매크로(Macro) : 코드를 단순화 시키기 위한 방법
* Makefile 작성규칙
```
목표파일 : 목표파일을 만드는데 필요한 구성요소들
목표를 달성하기 위한 명령 1
목표를 달성하기 위한 명령 2
```
* 더미타겟
* 파일을 생성하지 않는 개념적인 타겟
```
clean :
rm *.o projectfile
```
의 형태
실행할 때는 ``` make clean ``` 으로 명령하여 현재 디렉토리의 모든 object 파일과 생성된 실행파일인 projectfile을 제거할 수 있음
* 매크로 사용 작성 규칙
* 매크로를 참조할 때는 소괄호나 중괄호로 둘러싸고 앞에 $
* 탭으로 시작할 수 없으며 :, =, #, "" 등의 기호는 이름에 사용할 수 없음
* 매크로는 반드시 치환될 위치보다 먼저 정의
* 내부 매크로 사용
* $@ : 현재 타겟의 이름
* $^ : 현재 타겟의 종속 항목 리스트
* $< : 현재 타겟의 첫번째 요소
![macro](./image/macro.jpg)
* Make에서 컴파일 할 파일이 변경되는 경우 이미 실행 파일이 만들어져 있더라도 다시 만듦
* touch 명령을 통해 timestamps가 바뀌더라도 다시 make 명령 실행 가능
### CMake
* 요구 CMake 최소 버전
```
CMAKE_MINIMUM_REQUIRED (VERSION 2.8)
```
* 프로젝트 이름 및 버전
```
PROJECT ("andromeda")
SET (PROJECT_VERSION_MAJOR 0)
SET (PROJECT_VERSION_MINOR 1)
```
* 빌드 형상(Configuration) 및 Makefile 생성 여부
```
SET (CMAKE_BUILD_TYPE Debug)
SET (CMAKE_VERBOSE_MAKEFILE true)
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment