18c2ecf20Sopenharmony_ci/* SPDX-License-Identifier: GPL-2.0-or-later */
28c2ecf20Sopenharmony_ci/*
38c2ecf20Sopenharmony_ci    NetWinder Floating Point Emulator
48c2ecf20Sopenharmony_ci    (c) Rebel.COM, 1998,1999
58c2ecf20Sopenharmony_ci    (c) Philip Blundell, 2001
68c2ecf20Sopenharmony_ci
78c2ecf20Sopenharmony_ci    Direct questions, comments to Scott Bambrough <scottb@netwinder.org>
88c2ecf20Sopenharmony_ci
98c2ecf20Sopenharmony_ci*/
108c2ecf20Sopenharmony_ci
118c2ecf20Sopenharmony_ci#ifndef __FPOPCODE_H__
128c2ecf20Sopenharmony_ci#define __FPOPCODE_H__
138c2ecf20Sopenharmony_ci
148c2ecf20Sopenharmony_ci
158c2ecf20Sopenharmony_ci/*
168c2ecf20Sopenharmony_ciARM Floating Point Instruction Classes
178c2ecf20Sopenharmony_ci| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | |
188c2ecf20Sopenharmony_ci|c o n d|1 1 0 P|U|u|W|L|   Rn  |v|  Fd |0|0|0|1|  o f f s e t  | CPDT
198c2ecf20Sopenharmony_ci|c o n d|1 1 0 P|U|w|W|L|   Rn  |x|  Fd |0|0|1|0|  o f f s e t  | CPDT (copro 2)
208c2ecf20Sopenharmony_ci| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | |
218c2ecf20Sopenharmony_ci|c o n d|1 1 1 0|a|b|c|d|e|  Fn |j|  Fd |0|0|0|1|f|g|h|0|i|  Fm | CPDO
228c2ecf20Sopenharmony_ci|c o n d|1 1 1 0|a|b|c|L|e|  Fn |   Rd  |0|0|0|1|f|g|h|1|i|  Fm | CPRT
238c2ecf20Sopenharmony_ci|c o n d|1 1 1 0|a|b|c|1|e|  Fn |1|1|1|1|0|0|0|1|f|g|h|1|i|  Fm | comparisons
248c2ecf20Sopenharmony_ci| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | |
258c2ecf20Sopenharmony_ci
268c2ecf20Sopenharmony_ciCPDT		data transfer instructions
278c2ecf20Sopenharmony_ci		LDF, STF, LFM (copro 2), SFM (copro 2)
288c2ecf20Sopenharmony_ci
298c2ecf20Sopenharmony_ciCPDO		dyadic arithmetic instructions
308c2ecf20Sopenharmony_ci		ADF, MUF, SUF, RSF, DVF, RDF,
318c2ecf20Sopenharmony_ci		POW, RPW, RMF, FML, FDV, FRD, POL
328c2ecf20Sopenharmony_ci
338c2ecf20Sopenharmony_ciCPDO		monadic arithmetic instructions
348c2ecf20Sopenharmony_ci		MVF, MNF, ABS, RND, SQT, LOG, LGN, EXP,
358c2ecf20Sopenharmony_ci		SIN, COS, TAN, ASN, ACS, ATN, URD, NRM
368c2ecf20Sopenharmony_ci
378c2ecf20Sopenharmony_ciCPRT		joint arithmetic/data transfer instructions
388c2ecf20Sopenharmony_ci		FIX (arithmetic followed by load/store)
398c2ecf20Sopenharmony_ci		FLT (load/store followed by arithmetic)
408c2ecf20Sopenharmony_ci		CMF, CNF CMFE, CNFE (comparisons)
418c2ecf20Sopenharmony_ci		WFS, RFS (write/read floating point status register)
428c2ecf20Sopenharmony_ci		WFC, RFC (write/read floating point control register)
438c2ecf20Sopenharmony_ci
448c2ecf20Sopenharmony_cicond		condition codes
458c2ecf20Sopenharmony_ciP		pre/post index bit: 0 = postindex, 1 = preindex
468c2ecf20Sopenharmony_ciU		up/down bit: 0 = stack grows down, 1 = stack grows up
478c2ecf20Sopenharmony_ciW		write back bit: 1 = update base register (Rn)
488c2ecf20Sopenharmony_ciL		load/store bit: 0 = store, 1 = load
498c2ecf20Sopenharmony_ciRn		base register
508c2ecf20Sopenharmony_ciRd		destination/source register
518c2ecf20Sopenharmony_ciFd		floating point destination register
528c2ecf20Sopenharmony_ciFn		floating point source register
538c2ecf20Sopenharmony_ciFm		floating point source register or floating point constant
548c2ecf20Sopenharmony_ci
558c2ecf20Sopenharmony_ciuv		transfer length (TABLE 1)
568c2ecf20Sopenharmony_ciwx		register count (TABLE 2)
578c2ecf20Sopenharmony_ciabcd		arithmetic opcode (TABLES 3 & 4)
588c2ecf20Sopenharmony_cief		destination size (rounding precision) (TABLE 5)
598c2ecf20Sopenharmony_cigh		rounding mode (TABLE 6)
608c2ecf20Sopenharmony_cij		dyadic/monadic bit: 0 = dyadic, 1 = monadic
618c2ecf20Sopenharmony_cii 		constant bit: 1 = constant (TABLE 6)
628c2ecf20Sopenharmony_ci*/
638c2ecf20Sopenharmony_ci
648c2ecf20Sopenharmony_ci/*
658c2ecf20Sopenharmony_ciTABLE 1
668c2ecf20Sopenharmony_ci+-------------------------+---+---+---------+---------+
678c2ecf20Sopenharmony_ci|  Precision              | u | v | FPSR.EP | length  |
688c2ecf20Sopenharmony_ci+-------------------------+---+---+---------+---------+
698c2ecf20Sopenharmony_ci| Single                  | 0 | 0 |    x    | 1 words |
708c2ecf20Sopenharmony_ci| Double                  | 1 | 1 |    x    | 2 words |
718c2ecf20Sopenharmony_ci| Extended                | 1 | 1 |    x    | 3 words |
728c2ecf20Sopenharmony_ci| Packed decimal          | 1 | 1 |    0    | 3 words |
738c2ecf20Sopenharmony_ci| Expanded packed decimal | 1 | 1 |    1    | 4 words |
748c2ecf20Sopenharmony_ci+-------------------------+---+---+---------+---------+
758c2ecf20Sopenharmony_ciNote: x = don't care
768c2ecf20Sopenharmony_ci*/
778c2ecf20Sopenharmony_ci
788c2ecf20Sopenharmony_ci/*
798c2ecf20Sopenharmony_ciTABLE 2
808c2ecf20Sopenharmony_ci+---+---+---------------------------------+
818c2ecf20Sopenharmony_ci| w | x | Number of registers to transfer |
828c2ecf20Sopenharmony_ci+---+---+---------------------------------+
838c2ecf20Sopenharmony_ci| 0 | 1 |  1                              |
848c2ecf20Sopenharmony_ci| 1 | 0 |  2                              |
858c2ecf20Sopenharmony_ci| 1 | 1 |  3                              |
868c2ecf20Sopenharmony_ci| 0 | 0 |  4                              |
878c2ecf20Sopenharmony_ci+---+---+---------------------------------+
888c2ecf20Sopenharmony_ci*/
898c2ecf20Sopenharmony_ci
908c2ecf20Sopenharmony_ci/*
918c2ecf20Sopenharmony_ciTABLE 3: Dyadic Floating Point Opcodes
928c2ecf20Sopenharmony_ci+---+---+---+---+----------+-----------------------+-----------------------+
938c2ecf20Sopenharmony_ci| a | b | c | d | Mnemonic | Description           | Operation             |
948c2ecf20Sopenharmony_ci+---+---+---+---+----------+-----------------------+-----------------------+
958c2ecf20Sopenharmony_ci| 0 | 0 | 0 | 0 | ADF      | Add                   | Fd := Fn + Fm         |
968c2ecf20Sopenharmony_ci| 0 | 0 | 0 | 1 | MUF      | Multiply              | Fd := Fn * Fm         |
978c2ecf20Sopenharmony_ci| 0 | 0 | 1 | 0 | SUF      | Subtract              | Fd := Fn - Fm         |
988c2ecf20Sopenharmony_ci| 0 | 0 | 1 | 1 | RSF      | Reverse subtract      | Fd := Fm - Fn         |
998c2ecf20Sopenharmony_ci| 0 | 1 | 0 | 0 | DVF      | Divide                | Fd := Fn / Fm         |
1008c2ecf20Sopenharmony_ci| 0 | 1 | 0 | 1 | RDF      | Reverse divide        | Fd := Fm / Fn         |
1018c2ecf20Sopenharmony_ci| 0 | 1 | 1 | 0 | POW      | Power                 | Fd := Fn ^ Fm         |
1028c2ecf20Sopenharmony_ci| 0 | 1 | 1 | 1 | RPW      | Reverse power         | Fd := Fm ^ Fn         |
1038c2ecf20Sopenharmony_ci| 1 | 0 | 0 | 0 | RMF      | Remainder             | Fd := IEEE rem(Fn/Fm) |
1048c2ecf20Sopenharmony_ci| 1 | 0 | 0 | 1 | FML      | Fast Multiply         | Fd := Fn * Fm         |
1058c2ecf20Sopenharmony_ci| 1 | 0 | 1 | 0 | FDV      | Fast Divide           | Fd := Fn / Fm         |
1068c2ecf20Sopenharmony_ci| 1 | 0 | 1 | 1 | FRD      | Fast reverse divide   | Fd := Fm / Fn         |
1078c2ecf20Sopenharmony_ci| 1 | 1 | 0 | 0 | POL      | Polar angle (ArcTan2) | Fd := arctan2(Fn,Fm)  |
1088c2ecf20Sopenharmony_ci| 1 | 1 | 0 | 1 |          | undefined instruction | trap                  |
1098c2ecf20Sopenharmony_ci| 1 | 1 | 1 | 0 |          | undefined instruction | trap                  |
1108c2ecf20Sopenharmony_ci| 1 | 1 | 1 | 1 |          | undefined instruction | trap                  |
1118c2ecf20Sopenharmony_ci+---+---+---+---+----------+-----------------------+-----------------------+
1128c2ecf20Sopenharmony_ciNote: POW, RPW, POL are deprecated, and are available for backwards
1138c2ecf20Sopenharmony_ci      compatibility only.
1148c2ecf20Sopenharmony_ci*/
1158c2ecf20Sopenharmony_ci
1168c2ecf20Sopenharmony_ci/*
1178c2ecf20Sopenharmony_ciTABLE 4: Monadic Floating Point Opcodes
1188c2ecf20Sopenharmony_ci+---+---+---+---+----------+-----------------------+-----------------------+
1198c2ecf20Sopenharmony_ci| a | b | c | d | Mnemonic | Description           | Operation             |
1208c2ecf20Sopenharmony_ci+---+---+---+---+----------+-----------------------+-----------------------+
1218c2ecf20Sopenharmony_ci| 0 | 0 | 0 | 0 | MVF      | Move                  | Fd := Fm              |
1228c2ecf20Sopenharmony_ci| 0 | 0 | 0 | 1 | MNF      | Move negated          | Fd := - Fm            |
1238c2ecf20Sopenharmony_ci| 0 | 0 | 1 | 0 | ABS      | Absolute value        | Fd := abs(Fm)         |
1248c2ecf20Sopenharmony_ci| 0 | 0 | 1 | 1 | RND      | Round to integer      | Fd := int(Fm)         |
1258c2ecf20Sopenharmony_ci| 0 | 1 | 0 | 0 | SQT      | Square root           | Fd := sqrt(Fm)        |
1268c2ecf20Sopenharmony_ci| 0 | 1 | 0 | 1 | LOG      | Log base 10           | Fd := log10(Fm)       |
1278c2ecf20Sopenharmony_ci| 0 | 1 | 1 | 0 | LGN      | Log base e            | Fd := ln(Fm)          |
1288c2ecf20Sopenharmony_ci| 0 | 1 | 1 | 1 | EXP      | Exponent              | Fd := e ^ Fm          |
1298c2ecf20Sopenharmony_ci| 1 | 0 | 0 | 0 | SIN      | Sine                  | Fd := sin(Fm)         |
1308c2ecf20Sopenharmony_ci| 1 | 0 | 0 | 1 | COS      | Cosine                | Fd := cos(Fm)         |
1318c2ecf20Sopenharmony_ci| 1 | 0 | 1 | 0 | TAN      | Tangent               | Fd := tan(Fm)         |
1328c2ecf20Sopenharmony_ci| 1 | 0 | 1 | 1 | ASN      | Arc Sine              | Fd := arcsin(Fm)      |
1338c2ecf20Sopenharmony_ci| 1 | 1 | 0 | 0 | ACS      | Arc Cosine            | Fd := arccos(Fm)      |
1348c2ecf20Sopenharmony_ci| 1 | 1 | 0 | 1 | ATN      | Arc Tangent           | Fd := arctan(Fm)      |
1358c2ecf20Sopenharmony_ci| 1 | 1 | 1 | 0 | URD      | Unnormalized round    | Fd := int(Fm)         |
1368c2ecf20Sopenharmony_ci| 1 | 1 | 1 | 1 | NRM      | Normalize             | Fd := norm(Fm)        |
1378c2ecf20Sopenharmony_ci+---+---+---+---+----------+-----------------------+-----------------------+
1388c2ecf20Sopenharmony_ciNote: LOG, LGN, EXP, SIN, COS, TAN, ASN, ACS, ATN are deprecated, and are
1398c2ecf20Sopenharmony_ci      available for backwards compatibility only.
1408c2ecf20Sopenharmony_ci*/
1418c2ecf20Sopenharmony_ci
1428c2ecf20Sopenharmony_ci/*
1438c2ecf20Sopenharmony_ciTABLE 5
1448c2ecf20Sopenharmony_ci+-------------------------+---+---+
1458c2ecf20Sopenharmony_ci|  Rounding Precision     | e | f |
1468c2ecf20Sopenharmony_ci+-------------------------+---+---+
1478c2ecf20Sopenharmony_ci| IEEE Single precision   | 0 | 0 |
1488c2ecf20Sopenharmony_ci| IEEE Double precision   | 0 | 1 |
1498c2ecf20Sopenharmony_ci| IEEE Extended precision | 1 | 0 |
1508c2ecf20Sopenharmony_ci| undefined (trap)        | 1 | 1 |
1518c2ecf20Sopenharmony_ci+-------------------------+---+---+
1528c2ecf20Sopenharmony_ci*/
1538c2ecf20Sopenharmony_ci
1548c2ecf20Sopenharmony_ci/*
1558c2ecf20Sopenharmony_ciTABLE 5
1568c2ecf20Sopenharmony_ci+---------------------------------+---+---+
1578c2ecf20Sopenharmony_ci|  Rounding Mode                  | g | h |
1588c2ecf20Sopenharmony_ci+---------------------------------+---+---+
1598c2ecf20Sopenharmony_ci| Round to nearest (default)      | 0 | 0 |
1608c2ecf20Sopenharmony_ci| Round toward plus infinity      | 0 | 1 |
1618c2ecf20Sopenharmony_ci| Round toward negative infinity  | 1 | 0 |
1628c2ecf20Sopenharmony_ci| Round toward zero               | 1 | 1 |
1638c2ecf20Sopenharmony_ci+---------------------------------+---+---+
1648c2ecf20Sopenharmony_ci*/
1658c2ecf20Sopenharmony_ci
1668c2ecf20Sopenharmony_ci/*
1678c2ecf20Sopenharmony_ci===
1688c2ecf20Sopenharmony_ci=== Definitions for load and store instructions
1698c2ecf20Sopenharmony_ci===
1708c2ecf20Sopenharmony_ci*/
1718c2ecf20Sopenharmony_ci
1728c2ecf20Sopenharmony_ci/* bit masks */
1738c2ecf20Sopenharmony_ci#define BIT_PREINDEX	0x01000000
1748c2ecf20Sopenharmony_ci#define BIT_UP		0x00800000
1758c2ecf20Sopenharmony_ci#define BIT_WRITE_BACK	0x00200000
1768c2ecf20Sopenharmony_ci#define BIT_LOAD	0x00100000
1778c2ecf20Sopenharmony_ci
1788c2ecf20Sopenharmony_ci/* masks for load/store */
1798c2ecf20Sopenharmony_ci#define MASK_CPDT		0x0c000000	/* data processing opcode */
1808c2ecf20Sopenharmony_ci#define MASK_OFFSET		0x000000ff
1818c2ecf20Sopenharmony_ci#define MASK_TRANSFER_LENGTH	0x00408000
1828c2ecf20Sopenharmony_ci#define MASK_REGISTER_COUNT	MASK_TRANSFER_LENGTH
1838c2ecf20Sopenharmony_ci#define MASK_COPROCESSOR	0x00000f00
1848c2ecf20Sopenharmony_ci
1858c2ecf20Sopenharmony_ci/* Tests for transfer length */
1868c2ecf20Sopenharmony_ci#define TRANSFER_SINGLE		0x00000000
1878c2ecf20Sopenharmony_ci#define TRANSFER_DOUBLE		0x00008000
1888c2ecf20Sopenharmony_ci#define TRANSFER_EXTENDED	0x00400000
1898c2ecf20Sopenharmony_ci#define TRANSFER_PACKED		MASK_TRANSFER_LENGTH
1908c2ecf20Sopenharmony_ci
1918c2ecf20Sopenharmony_ci/* Get the coprocessor number from the opcode. */
1928c2ecf20Sopenharmony_ci#define getCoprocessorNumber(opcode)	((opcode & MASK_COPROCESSOR) >> 8)
1938c2ecf20Sopenharmony_ci
1948c2ecf20Sopenharmony_ci/* Get the offset from the opcode. */
1958c2ecf20Sopenharmony_ci#define getOffset(opcode)		(opcode & MASK_OFFSET)
1968c2ecf20Sopenharmony_ci
1978c2ecf20Sopenharmony_ci/* Tests for specific data transfer load/store opcodes. */
1988c2ecf20Sopenharmony_ci#define TEST_OPCODE(opcode,mask)	(((opcode) & (mask)) == (mask))
1998c2ecf20Sopenharmony_ci
2008c2ecf20Sopenharmony_ci#define LOAD_OP(opcode)   TEST_OPCODE((opcode),MASK_CPDT | BIT_LOAD)
2018c2ecf20Sopenharmony_ci#define STORE_OP(opcode)  ((opcode & (MASK_CPDT | BIT_LOAD)) == MASK_CPDT)
2028c2ecf20Sopenharmony_ci
2038c2ecf20Sopenharmony_ci#define LDF_OP(opcode)	(LOAD_OP(opcode) && (getCoprocessorNumber(opcode) == 1))
2048c2ecf20Sopenharmony_ci#define LFM_OP(opcode)	(LOAD_OP(opcode) && (getCoprocessorNumber(opcode) == 2))
2058c2ecf20Sopenharmony_ci#define STF_OP(opcode)	(STORE_OP(opcode) && (getCoprocessorNumber(opcode) == 1))
2068c2ecf20Sopenharmony_ci#define SFM_OP(opcode)	(STORE_OP(opcode) && (getCoprocessorNumber(opcode) == 2))
2078c2ecf20Sopenharmony_ci
2088c2ecf20Sopenharmony_ci#define PREINDEXED(opcode)		((opcode & BIT_PREINDEX) != 0)
2098c2ecf20Sopenharmony_ci#define POSTINDEXED(opcode)		((opcode & BIT_PREINDEX) == 0)
2108c2ecf20Sopenharmony_ci#define BIT_UP_SET(opcode)		((opcode & BIT_UP) != 0)
2118c2ecf20Sopenharmony_ci#define BIT_UP_CLEAR(opcode)		((opcode & BIT_DOWN) == 0)
2128c2ecf20Sopenharmony_ci#define WRITE_BACK(opcode)		((opcode & BIT_WRITE_BACK) != 0)
2138c2ecf20Sopenharmony_ci#define LOAD(opcode)			((opcode & BIT_LOAD) != 0)
2148c2ecf20Sopenharmony_ci#define STORE(opcode)			((opcode & BIT_LOAD) == 0)
2158c2ecf20Sopenharmony_ci
2168c2ecf20Sopenharmony_ci/*
2178c2ecf20Sopenharmony_ci===
2188c2ecf20Sopenharmony_ci=== Definitions for arithmetic instructions
2198c2ecf20Sopenharmony_ci===
2208c2ecf20Sopenharmony_ci*/
2218c2ecf20Sopenharmony_ci/* bit masks */
2228c2ecf20Sopenharmony_ci#define BIT_MONADIC	0x00008000
2238c2ecf20Sopenharmony_ci#define BIT_CONSTANT	0x00000008
2248c2ecf20Sopenharmony_ci
2258c2ecf20Sopenharmony_ci#define CONSTANT_FM(opcode)		((opcode & BIT_CONSTANT) != 0)
2268c2ecf20Sopenharmony_ci#define MONADIC_INSTRUCTION(opcode)	((opcode & BIT_MONADIC) != 0)
2278c2ecf20Sopenharmony_ci
2288c2ecf20Sopenharmony_ci/* instruction identification masks */
2298c2ecf20Sopenharmony_ci#define MASK_CPDO		0x0e000000	/* arithmetic opcode */
2308c2ecf20Sopenharmony_ci#define MASK_ARITHMETIC_OPCODE	0x00f08000
2318c2ecf20Sopenharmony_ci#define MASK_DESTINATION_SIZE	0x00080080
2328c2ecf20Sopenharmony_ci
2338c2ecf20Sopenharmony_ci/* dyadic arithmetic opcodes. */
2348c2ecf20Sopenharmony_ci#define ADF_CODE	0x00000000
2358c2ecf20Sopenharmony_ci#define MUF_CODE	0x00100000
2368c2ecf20Sopenharmony_ci#define SUF_CODE	0x00200000
2378c2ecf20Sopenharmony_ci#define RSF_CODE	0x00300000
2388c2ecf20Sopenharmony_ci#define DVF_CODE	0x00400000
2398c2ecf20Sopenharmony_ci#define RDF_CODE	0x00500000
2408c2ecf20Sopenharmony_ci#define POW_CODE	0x00600000
2418c2ecf20Sopenharmony_ci#define RPW_CODE	0x00700000
2428c2ecf20Sopenharmony_ci#define RMF_CODE	0x00800000
2438c2ecf20Sopenharmony_ci#define FML_CODE	0x00900000
2448c2ecf20Sopenharmony_ci#define FDV_CODE	0x00a00000
2458c2ecf20Sopenharmony_ci#define FRD_CODE	0x00b00000
2468c2ecf20Sopenharmony_ci#define POL_CODE	0x00c00000
2478c2ecf20Sopenharmony_ci/* 0x00d00000 is an invalid dyadic arithmetic opcode */
2488c2ecf20Sopenharmony_ci/* 0x00e00000 is an invalid dyadic arithmetic opcode */
2498c2ecf20Sopenharmony_ci/* 0x00f00000 is an invalid dyadic arithmetic opcode */
2508c2ecf20Sopenharmony_ci
2518c2ecf20Sopenharmony_ci/* monadic arithmetic opcodes. */
2528c2ecf20Sopenharmony_ci#define MVF_CODE	0x00008000
2538c2ecf20Sopenharmony_ci#define MNF_CODE	0x00108000
2548c2ecf20Sopenharmony_ci#define ABS_CODE	0x00208000
2558c2ecf20Sopenharmony_ci#define RND_CODE	0x00308000
2568c2ecf20Sopenharmony_ci#define SQT_CODE	0x00408000
2578c2ecf20Sopenharmony_ci#define LOG_CODE	0x00508000
2588c2ecf20Sopenharmony_ci#define LGN_CODE	0x00608000
2598c2ecf20Sopenharmony_ci#define EXP_CODE	0x00708000
2608c2ecf20Sopenharmony_ci#define SIN_CODE	0x00808000
2618c2ecf20Sopenharmony_ci#define COS_CODE	0x00908000
2628c2ecf20Sopenharmony_ci#define TAN_CODE	0x00a08000
2638c2ecf20Sopenharmony_ci#define ASN_CODE	0x00b08000
2648c2ecf20Sopenharmony_ci#define ACS_CODE	0x00c08000
2658c2ecf20Sopenharmony_ci#define ATN_CODE	0x00d08000
2668c2ecf20Sopenharmony_ci#define URD_CODE	0x00e08000
2678c2ecf20Sopenharmony_ci#define NRM_CODE	0x00f08000
2688c2ecf20Sopenharmony_ci
2698c2ecf20Sopenharmony_ci/*
2708c2ecf20Sopenharmony_ci===
2718c2ecf20Sopenharmony_ci=== Definitions for register transfer and comparison instructions
2728c2ecf20Sopenharmony_ci===
2738c2ecf20Sopenharmony_ci*/
2748c2ecf20Sopenharmony_ci
2758c2ecf20Sopenharmony_ci#define MASK_CPRT		0x0e000010	/* register transfer opcode */
2768c2ecf20Sopenharmony_ci#define MASK_CPRT_CODE		0x00f00000
2778c2ecf20Sopenharmony_ci#define FLT_CODE		0x00000000
2788c2ecf20Sopenharmony_ci#define FIX_CODE		0x00100000
2798c2ecf20Sopenharmony_ci#define WFS_CODE		0x00200000
2808c2ecf20Sopenharmony_ci#define RFS_CODE		0x00300000
2818c2ecf20Sopenharmony_ci#define WFC_CODE		0x00400000
2828c2ecf20Sopenharmony_ci#define RFC_CODE		0x00500000
2838c2ecf20Sopenharmony_ci#define CMF_CODE		0x00900000
2848c2ecf20Sopenharmony_ci#define CNF_CODE		0x00b00000
2858c2ecf20Sopenharmony_ci#define CMFE_CODE		0x00d00000
2868c2ecf20Sopenharmony_ci#define CNFE_CODE		0x00f00000
2878c2ecf20Sopenharmony_ci
2888c2ecf20Sopenharmony_ci/*
2898c2ecf20Sopenharmony_ci===
2908c2ecf20Sopenharmony_ci=== Common definitions
2918c2ecf20Sopenharmony_ci===
2928c2ecf20Sopenharmony_ci*/
2938c2ecf20Sopenharmony_ci
2948c2ecf20Sopenharmony_ci/* register masks */
2958c2ecf20Sopenharmony_ci#define MASK_Rd		0x0000f000
2968c2ecf20Sopenharmony_ci#define MASK_Rn		0x000f0000
2978c2ecf20Sopenharmony_ci#define MASK_Fd		0x00007000
2988c2ecf20Sopenharmony_ci#define MASK_Fm		0x00000007
2998c2ecf20Sopenharmony_ci#define MASK_Fn		0x00070000
3008c2ecf20Sopenharmony_ci
3018c2ecf20Sopenharmony_ci/* condition code masks */
3028c2ecf20Sopenharmony_ci#define CC_MASK		0xf0000000
3038c2ecf20Sopenharmony_ci#define CC_NEGATIVE	0x80000000
3048c2ecf20Sopenharmony_ci#define CC_ZERO		0x40000000
3058c2ecf20Sopenharmony_ci#define CC_CARRY	0x20000000
3068c2ecf20Sopenharmony_ci#define CC_OVERFLOW	0x10000000
3078c2ecf20Sopenharmony_ci#define CC_EQ		0x00000000
3088c2ecf20Sopenharmony_ci#define CC_NE		0x10000000
3098c2ecf20Sopenharmony_ci#define CC_CS		0x20000000
3108c2ecf20Sopenharmony_ci#define CC_HS		CC_CS
3118c2ecf20Sopenharmony_ci#define CC_CC		0x30000000
3128c2ecf20Sopenharmony_ci#define CC_LO		CC_CC
3138c2ecf20Sopenharmony_ci#define CC_MI		0x40000000
3148c2ecf20Sopenharmony_ci#define CC_PL		0x50000000
3158c2ecf20Sopenharmony_ci#define CC_VS		0x60000000
3168c2ecf20Sopenharmony_ci#define CC_VC		0x70000000
3178c2ecf20Sopenharmony_ci#define CC_HI		0x80000000
3188c2ecf20Sopenharmony_ci#define CC_LS		0x90000000
3198c2ecf20Sopenharmony_ci#define CC_GE		0xa0000000
3208c2ecf20Sopenharmony_ci#define CC_LT		0xb0000000
3218c2ecf20Sopenharmony_ci#define CC_GT		0xc0000000
3228c2ecf20Sopenharmony_ci#define CC_LE		0xd0000000
3238c2ecf20Sopenharmony_ci#define CC_AL		0xe0000000
3248c2ecf20Sopenharmony_ci#define CC_NV		0xf0000000
3258c2ecf20Sopenharmony_ci
3268c2ecf20Sopenharmony_ci/* rounding masks/values */
3278c2ecf20Sopenharmony_ci#define MASK_ROUNDING_MODE	0x00000060
3288c2ecf20Sopenharmony_ci#define ROUND_TO_NEAREST	0x00000000
3298c2ecf20Sopenharmony_ci#define ROUND_TO_PLUS_INFINITY	0x00000020
3308c2ecf20Sopenharmony_ci#define ROUND_TO_MINUS_INFINITY	0x00000040
3318c2ecf20Sopenharmony_ci#define ROUND_TO_ZERO		0x00000060
3328c2ecf20Sopenharmony_ci
3338c2ecf20Sopenharmony_ci#define MASK_ROUNDING_PRECISION	0x00080080
3348c2ecf20Sopenharmony_ci#define ROUND_SINGLE		0x00000000
3358c2ecf20Sopenharmony_ci#define ROUND_DOUBLE		0x00000080
3368c2ecf20Sopenharmony_ci#define ROUND_EXTENDED		0x00080000
3378c2ecf20Sopenharmony_ci
3388c2ecf20Sopenharmony_ci/* Get the condition code from the opcode. */
3398c2ecf20Sopenharmony_ci#define getCondition(opcode)		(opcode >> 28)
3408c2ecf20Sopenharmony_ci
3418c2ecf20Sopenharmony_ci/* Get the source register from the opcode. */
3428c2ecf20Sopenharmony_ci#define getRn(opcode)			((opcode & MASK_Rn) >> 16)
3438c2ecf20Sopenharmony_ci
3448c2ecf20Sopenharmony_ci/* Get the destination floating point register from the opcode. */
3458c2ecf20Sopenharmony_ci#define getFd(opcode)			((opcode & MASK_Fd) >> 12)
3468c2ecf20Sopenharmony_ci
3478c2ecf20Sopenharmony_ci/* Get the first source floating point register from the opcode. */
3488c2ecf20Sopenharmony_ci#define getFn(opcode)		((opcode & MASK_Fn) >> 16)
3498c2ecf20Sopenharmony_ci
3508c2ecf20Sopenharmony_ci/* Get the second source floating point register from the opcode. */
3518c2ecf20Sopenharmony_ci#define getFm(opcode)		(opcode & MASK_Fm)
3528c2ecf20Sopenharmony_ci
3538c2ecf20Sopenharmony_ci/* Get the destination register from the opcode. */
3548c2ecf20Sopenharmony_ci#define getRd(opcode)		((opcode & MASK_Rd) >> 12)
3558c2ecf20Sopenharmony_ci
3568c2ecf20Sopenharmony_ci/* Get the rounding mode from the opcode. */
3578c2ecf20Sopenharmony_ci#define getRoundingMode(opcode)		((opcode & MASK_ROUNDING_MODE) >> 5)
3588c2ecf20Sopenharmony_ci
3598c2ecf20Sopenharmony_ci#ifdef CONFIG_FPE_NWFPE_XP
3608c2ecf20Sopenharmony_cistatic inline floatx80 __pure getExtendedConstant(const unsigned int nIndex)
3618c2ecf20Sopenharmony_ci{
3628c2ecf20Sopenharmony_ci	extern const floatx80 floatx80Constant[];
3638c2ecf20Sopenharmony_ci	return floatx80Constant[nIndex];
3648c2ecf20Sopenharmony_ci}
3658c2ecf20Sopenharmony_ci#endif
3668c2ecf20Sopenharmony_ci
3678c2ecf20Sopenharmony_cistatic inline float64 __pure getDoubleConstant(const unsigned int nIndex)
3688c2ecf20Sopenharmony_ci{
3698c2ecf20Sopenharmony_ci	extern const float64 float64Constant[];
3708c2ecf20Sopenharmony_ci	return float64Constant[nIndex];
3718c2ecf20Sopenharmony_ci}
3728c2ecf20Sopenharmony_ci
3738c2ecf20Sopenharmony_cistatic inline float32 __pure getSingleConstant(const unsigned int nIndex)
3748c2ecf20Sopenharmony_ci{
3758c2ecf20Sopenharmony_ci	extern const float32 float32Constant[];
3768c2ecf20Sopenharmony_ci	return float32Constant[nIndex];
3778c2ecf20Sopenharmony_ci}
3788c2ecf20Sopenharmony_ci
3798c2ecf20Sopenharmony_cistatic inline unsigned int getTransferLength(const unsigned int opcode)
3808c2ecf20Sopenharmony_ci{
3818c2ecf20Sopenharmony_ci	unsigned int nRc;
3828c2ecf20Sopenharmony_ci
3838c2ecf20Sopenharmony_ci	switch (opcode & MASK_TRANSFER_LENGTH) {
3848c2ecf20Sopenharmony_ci	case 0x00000000:
3858c2ecf20Sopenharmony_ci		nRc = 1;
3868c2ecf20Sopenharmony_ci		break;		/* single precision */
3878c2ecf20Sopenharmony_ci	case 0x00008000:
3888c2ecf20Sopenharmony_ci		nRc = 2;
3898c2ecf20Sopenharmony_ci		break;		/* double precision */
3908c2ecf20Sopenharmony_ci	case 0x00400000:
3918c2ecf20Sopenharmony_ci		nRc = 3;
3928c2ecf20Sopenharmony_ci		break;		/* extended precision */
3938c2ecf20Sopenharmony_ci	default:
3948c2ecf20Sopenharmony_ci		nRc = 0;
3958c2ecf20Sopenharmony_ci	}
3968c2ecf20Sopenharmony_ci
3978c2ecf20Sopenharmony_ci	return (nRc);
3988c2ecf20Sopenharmony_ci}
3998c2ecf20Sopenharmony_ci
4008c2ecf20Sopenharmony_cistatic inline unsigned int getRegisterCount(const unsigned int opcode)
4018c2ecf20Sopenharmony_ci{
4028c2ecf20Sopenharmony_ci	unsigned int nRc;
4038c2ecf20Sopenharmony_ci
4048c2ecf20Sopenharmony_ci	switch (opcode & MASK_REGISTER_COUNT) {
4058c2ecf20Sopenharmony_ci	case 0x00000000:
4068c2ecf20Sopenharmony_ci		nRc = 4;
4078c2ecf20Sopenharmony_ci		break;
4088c2ecf20Sopenharmony_ci	case 0x00008000:
4098c2ecf20Sopenharmony_ci		nRc = 1;
4108c2ecf20Sopenharmony_ci		break;
4118c2ecf20Sopenharmony_ci	case 0x00400000:
4128c2ecf20Sopenharmony_ci		nRc = 2;
4138c2ecf20Sopenharmony_ci		break;
4148c2ecf20Sopenharmony_ci	case 0x00408000:
4158c2ecf20Sopenharmony_ci		nRc = 3;
4168c2ecf20Sopenharmony_ci		break;
4178c2ecf20Sopenharmony_ci	default:
4188c2ecf20Sopenharmony_ci		nRc = 0;
4198c2ecf20Sopenharmony_ci	}
4208c2ecf20Sopenharmony_ci
4218c2ecf20Sopenharmony_ci	return (nRc);
4228c2ecf20Sopenharmony_ci}
4238c2ecf20Sopenharmony_ci
4248c2ecf20Sopenharmony_cistatic inline unsigned int getRoundingPrecision(const unsigned int opcode)
4258c2ecf20Sopenharmony_ci{
4268c2ecf20Sopenharmony_ci	unsigned int nRc;
4278c2ecf20Sopenharmony_ci
4288c2ecf20Sopenharmony_ci	switch (opcode & MASK_ROUNDING_PRECISION) {
4298c2ecf20Sopenharmony_ci	case 0x00000000:
4308c2ecf20Sopenharmony_ci		nRc = 1;
4318c2ecf20Sopenharmony_ci		break;
4328c2ecf20Sopenharmony_ci	case 0x00000080:
4338c2ecf20Sopenharmony_ci		nRc = 2;
4348c2ecf20Sopenharmony_ci		break;
4358c2ecf20Sopenharmony_ci	case 0x00080000:
4368c2ecf20Sopenharmony_ci		nRc = 3;
4378c2ecf20Sopenharmony_ci		break;
4388c2ecf20Sopenharmony_ci	default:
4398c2ecf20Sopenharmony_ci		nRc = 0;
4408c2ecf20Sopenharmony_ci	}
4418c2ecf20Sopenharmony_ci
4428c2ecf20Sopenharmony_ci	return (nRc);
4438c2ecf20Sopenharmony_ci}
4448c2ecf20Sopenharmony_ci
4458c2ecf20Sopenharmony_cistatic inline unsigned int getDestinationSize(const unsigned int opcode)
4468c2ecf20Sopenharmony_ci{
4478c2ecf20Sopenharmony_ci	unsigned int nRc;
4488c2ecf20Sopenharmony_ci
4498c2ecf20Sopenharmony_ci	switch (opcode & MASK_DESTINATION_SIZE) {
4508c2ecf20Sopenharmony_ci	case 0x00000000:
4518c2ecf20Sopenharmony_ci		nRc = typeSingle;
4528c2ecf20Sopenharmony_ci		break;
4538c2ecf20Sopenharmony_ci	case 0x00000080:
4548c2ecf20Sopenharmony_ci		nRc = typeDouble;
4558c2ecf20Sopenharmony_ci		break;
4568c2ecf20Sopenharmony_ci	case 0x00080000:
4578c2ecf20Sopenharmony_ci		nRc = typeExtended;
4588c2ecf20Sopenharmony_ci		break;
4598c2ecf20Sopenharmony_ci	default:
4608c2ecf20Sopenharmony_ci		nRc = typeNone;
4618c2ecf20Sopenharmony_ci	}
4628c2ecf20Sopenharmony_ci
4638c2ecf20Sopenharmony_ci	return (nRc);
4648c2ecf20Sopenharmony_ci}
4658c2ecf20Sopenharmony_ci
4668c2ecf20Sopenharmony_ciextern const float64 float64Constant[];
4678c2ecf20Sopenharmony_ciextern const float32 float32Constant[];
4688c2ecf20Sopenharmony_ci
4698c2ecf20Sopenharmony_ci#endif
470