Presentation is loading. Please wait.

Presentation is loading. Please wait.

13. Floating Point Operations

Similar presentations


Presentation on theme: "13. Floating Point Operations"— Presentation transcript:

1 13. Floating Point Operations
RTLAB 전영준

2 About floating point data Cortex-M4 floating point unit ( FPU )
목차 About floating point data Cortex-M4 floating point unit ( FPU ) Lazy stacking in detail Using the floating point unit Floating point exception

3 1. About floating point data
In C programming, you can define data as floating point values. For example, a value can be declared as single precision: float pi = F; double precision: double pi = ;

4 1. About floating point data

5 1. About floating point data : Normalized number format
( exponent의 범위 : -126~127 ) single-precision Floating point 연산의 경우 수의 값을 1.0에서 2.0사이의 값으로 정규화해야 한다. 만약 exponent의 값이 0인 경우 1) +0은 sign과 fraction이 모두 0이어야 한다. 2) -0은 sign은 1, fraction은 0이어야 한다. 3) fraction이 0이 아니라면, denormalized value가 된다. normalized number 라는 것은 뭘까요?    앞 문제에서 설명했듯이 가수가 지켜야 할 규칙 (norm) 이 있었죠.    그 규칙을 따르는 수를 normalized number 라고 합니다.    즉, 규칙에 맞게 변형된 수라는 것이죠.

6 1. About floating point data : Denormalized number format
가장 작은 normalized number = 2^(-126), 두번째로 작은 normalized number = 2^(-126)+2^(-23)*2^(-126) ( ) 0과 가장 작은 수와 두번째로 작은 수의 gap이 너무 크기에 0과 2^(-126) 사이의 수를 표현할 수 있는 값 표현 1) exponential bits = ( = -126 ) 2) fraction bits 존재 3) implicit leading 1이 존재하지 않음 Denormalized number 는 우리말로 옮기면 비정규수 정도로 번역할 수 있습니다.    IEEE-754 에서는 이 용어 대신에 subnormal number 라는 말을 사용합니다.    즉, 정규수 아래에 있는 수라는 말이죠.

7 1. About floating point data : Denormalized number format
만약 expnent 값이 0xFF인 경우 1) Fraction == 0, Sign == 0 -> infinity ( +∞ ) 2) Fraction == 0, Sign == 1 -> infinity ( - ∞ ) 3) Fraction ≠0 →𝑁𝐴𝑁 ( Not a Number ) NaN 1) Signaling NaN : Fraction의 bit 22개가 0일 경우 2) quiet NaN : Fraction의 bit 22개가 1일 경우 3) QNaNs은 대부분의 산술 연산에서 예외를 signaling 하지 않은 채로 스며들게 (propagate) 할 수 있다. : 디버깅 속도 향상 시 4) SNaNs은 일반적으로, 산술 연산에서 연산자 사용될 때마다 발생하는 invalid operation 예외 시그널이다. : 초기화되지 않은 (실수) 배열 요소 참조 Denormalized number 는 우리말로 옮기면 비정규수 정도로 번역할 수 있습니다.    IEEE-754 에서는 이 용어 대신에 subnormal number 라는 말을 사용합니다.    즉, 정규수 아래에 있는 수라는 말이죠.

8 1. About floating point data : Half-precision floating point numbers

9 1. About floating point data : Double-precision floating point numbers

10 2. Cortex-M4 floating point unit ( FPU )
M4에서는 single-precision floating point를 할 수 있는 option이 포함 -> single-precision floating point operation을 빠르게 계산하도록 ARMv7-M Architecture에서 floating point 연산은 IEEE Std , IEEE Standard for Binary Floating Point Arithmetic을 따른다. Cortex-M4의 FPU는 선택적으로 사용가능하며, Single precision floating point를 지원하고, conversion 및 memory access function 을 지원한다. 아래의 것들은 지원하지 않는다. 1) Double-precision data calculations 2) Floating point 나누기 (e.g., z ¼ fmod (x, y)) 3) 부동소수점 수를 정수 값으로 반올림 4) 2진수 <-> 10진수 변환 5) single-precision과 double-precision간의 직접적 비교

11 2. Cortex-M4 floating point unit ( FPU )
Floating point register bank : 32-bit register or 16 double-word register Conversion instruction 1) integer <-> single-precision floating point 2) fixed point <-> single-precision floating point 3) half precision <-> single-precision floating point Data transfers of single-precision and double-word data between floating point register bank and memory Data transfer of single-precision between floating point register bank and integer register bank

12 2. Cortex-M4 floating point unit ( FPU )
FPU는 co-processor로 간주된다. Normal processing pipeline과 floating point unit은 같은 instruction fetch stage를 공유하지만 그림 13.11과 같이 insturction decode 및 excution stages는 별개이다. Floating point operation/transfers의 경우 floating point instruction 사용 명령어 페치첫 번째 단계인 명령어 페치 단계를 페치 사이클(fetch cycle)로 부른다. 이 단계는 각 명령에 동일한 작업을 수행한다. 페치 사이클은 opcode를 포함하는 명령어(instruction word)로부터 명령(instruction)을 처리한다. 명령어 디코딩두 번째 단계는 디코딩으로 부른다. 메모리로부터 페치된 opcode는 다음 단계를 위해 디코딩되며 적절한 레지스터로 이동된다. 유효한 주소 읽기세 번째 단계인 유효한 주소 읽기는 어떠한 명령인지를 결정하는 단계이다. 이것이 메모리 명령이라면 이 컴퓨터 단계에서 직접 메모리 명령인지 간접 메모리 명령인지를 확인한다: 직접 메모리 명령 - 아무 것도 처리하지 않는다. 간접 메모리 명령 - 유효 주소를 메모리로부터 읽어들인다. 이것이 입출력 명령이나 레지스터 명령이라면 컴퓨터는 이에 대한 종류를 확인하고 명령을 실행한다. 명령 실행네 번째 단계는 실행 사이클이다. 이 단계는 각 명령에 따라 변동된다.실행 사이클의 첫 번째 단계는 프로세스-메모리(Process-Memory)이다. 데이터는 CPU와 입출력 모듈 사이를 오고간다.그 다음 단계는 데이터-프로세싱(Data-Processing)이며 데이터 참조에서 논리 명령뿐 아니라 수치 명령도 이용한다. 그 다음 단계는 중심 변경(Central alteration)으로, 점프(jump) 명령과 같은 명령의 연속이다. 마지막 단계는 다른 모든 단계에서 나온 모든 명령을 아우른다.

13 2. Cortex-M4 floating point unit ( FPU ) : Floating point registers overview
CPACR (Co-processor Access Control Register) in SCB (System Control Block) Floating point register bank Floating point Status and Control Register (FPSCR) Additional registers in the FPU for floating point operations and control, as shown in Table 13.2.

14 CPACR (Co-processor Access Control Register) register
2. Cortex-M4 floating point unit ( FPU ) : Floating point registers overview CPACR (Co-processor Access Control Register) register The CPACR register allows you to enable or disable the FPU located in address 0xE000ED88 and can be accessed as “SCB->CPACR” in CMSIS-Core. Bit 0 to bit 19 and bit 24 to bit 31 are not implemented and are reserved FPU is defined as co-processor 10 and 11. only CP10 and CP11 are available and both are for the FPU. SCB->CPACRj= 0x00F00000; // Enable the floating point unit for full access

15 Floating point register bank
2. Cortex-M4 floating point unit ( FPU ) : Floating point registers overview Floating point register bank Caller saved register : A가 B를 호출할 때 A의 register 정보를 저장해 두는 stack ( 마음대로 사용할 수 있는 레지스터 ) Calle saved register : A가 B를 호출할 때 B가 16개 이상의 register를 계산에 사용하는 경우 저장하는 부분 A함수로 돌아가기 전에 복원을 해야만 함. ( 마음대로 사용되는 레지스터 )

16 Floating point status and control register (FPSCR)
2. Cortex-M4 floating point unit ( FPU ) : Floating point registers overview Floating point status and control register (FPSCR) FPSCR은 arithmetic result flags 및 sticky status flags 뿐만 아니라 부동 소수점 장치의 동작을 제어하는 ​​bit fields. the sticky bit is a user ownership access right flag that can be assigned to files and directories on Unix-like systems. 컴퓨팅에서 스티키 비트는 유닉스 계열 시스템의 파일과 디렉토리에 할당 할 수있는 사용자 소유권 액세스 권한 플래그입니다.

17 3. Lazy stacking in detail
Key elements of the lazy stacking feature Lazy stacking이 없으면, 모든 exception에 요구되는 시간이 29 cycles로 증가 Default lazy stacking feature을 enable하면 필요한 모든 작업이 하드웨어에 의해 자동으로 관리되므로 예외처리 중에 레지스터 설정이 필요가 없음 CONTROL register안의 FPCA bit 1) Processor가 floating point instruction을 실행하면 1으로 설정 2) exception handler 시작 시 0으로 clear 3) exception return 시 EXC_RETURN의 4번째 bit를 inverse 4) reset 후에 0으로 clear EXC_RETURN Key elements 핵심요소 Lazy stacking -> 인터럽트 지연시간을 줄이기 위한 메커니즘 ( interrupt latency ) Interrupt된 task가 floating point context가 있는 경우(FPCA가 1) exception entry에서 0으로 설정이 된다. (contains R0eR3, R12, LR, Return Address, xPSR, S0eS15, FPSCR) Stack frame이 짧을 경우 1로 설정 (contains R0eR3, R12, LR, Return Address, xPSR)

18 3. Lazy stacking in detail
LSPACT bit in FPCCR Processor가 exception handler에 진입해있고, lazy stacking이 enable 상태이며 interrupt task가 floating point context를 가질 경우 ( FPCA가 1 ), 더 긴 stack frame이 사용되어지고 LSPACT는 1로 set 된다. 이 때 float point 연산이 지연되고 FPCAR로 표시된 stack frame 공간이 할당된다. LSPACT가 1일 동안 Floating point 연산을 실행하면 processor는 pipeline을 정지하고 floating point register의 stacking을 시작한다. LSPACT가 0으로 Clear된 상태에서 재 수행 되면 floating point register stacking으로 인한 지연이 없다는 것을 나타낸다. Key elements 핵심요소 Lazy stacking -> 인터럽트 지연시간을 줄이기 위한 메커니즘 ( interrupt latency )

19 3. Lazy stacking in detail
No floating point context in interrupted task Lazy stacking -> 인터럽트 지연시간을 줄이기 위한 메커니즘 ( interrupt latency )

20 3. Lazy stacking in detail
Floating point context in interrupted task but not in ISR 인터럽트 이전에 부동 소수점 컨텍스트가있는 경우 FPCA는 1이고 스택 프레임의 긴 버전이 사용됩니다 (그림 13.20). 그러나 스택 프레임에는 S0eS15 및 FPSCR에 대한 공간이 포함되며 이러한 레지스터의 값은 스택으로 푸시되지 않습니다. LSPACT는 1로 설정되어 부동 소수점 레지스터의 스택이 지연됨을 나타냅니다. 예외 복귀시, 프로세서는 EXC_RETURN [4]가 0 (긴 스택 프레임)이지만 LSPACT가 1이며 부동 소수점 레지스터가 스택에 푸시되지 않았 음을 나타냅니다. 따라서 S0eS15 및 FPSCR의 언 스태킹은 수행되지 않고 변경되지 않습니다.

21 3. Lazy stacking in detail
Floating point context in interrupted task and in ISR

22 3. Lazy stacking in detail
Nested interrupt with floating point context in the second handler

23 3. Lazy stacking in detail
Nested interrupt with floating point context in the both handlers

24 4. Using the floating point unit
Floating point support in CMSIS-Core FPU_USED가 1로 set되면, reset handler가 실행될 때마다 SystemInit() 함수가 FPU를 enable 된다.

25 4. Using the floating point unit
Floating point programming in C 대부분의 프로그램에서는 single-precision floating point이면 충분하다. Double-precision을 사용하게 되면 코드가 커지고 Cortex-M4의 경우에는 이를 지원하지 않아서 run-time library function을 사용해야 한다. 하지만 대부분의 프로그래머의 경우 실수로 double-precision floating point를 사용한다.

26 4. Using the floating point unit
Compiler command line options ARM DS-5 or the older RealView Development Suite (RVDS) 사용자 gcc 사용자

27 4. Using the floating point unit
ABI Options: Hard-vfp and Soft-vfp

28 4. Using the floating point unit
ABI Options: Hard-vfp and Soft-vfp

29 4. Using the floating point unit
Special FPU modes Flush-to-Zero Mode Default NaN mode Alternate half-precision mode Rounding modes

30 5. Floating point exception

31 5. Floating point exception

32 Thank you for listening!


Download ppt "13. Floating Point Operations"

Similar presentations


Ads by Google