History

arm-asm: Add vcvt

Danny Milosavljevic committed 5 years ago

Commit 24c94ff1 parent f1fb23a3 files · +177 −4Browse files

Unified · Split

3 files
  1. arm-asm.c +138 −3
  2. arm-tok.h +36 −0
  3. tests/arm-asm-testsuite.sh +3 −1
arm-asm.c+138−3
@@ -1902,6 +1902,127 @@ static void asm_floating_point_reg_arm_reg_transfer_opcode_tail(TCCState *s1, in · 1901 unmodified lines
19021902 }
19031903 }
19041904
1905+static void asm_floating_point_vcvt_data_processing_opcode(TCCState *s1, int token) {
1906+ uint8_t coprocessor = 0;
1907+ Operand ops[3];
1908+ uint8_t opcode1 = 11;
1909+ uint8_t opcode2 = 2;
1910+
1911+ switch (ARM_INSTRUCTION_GROUP(token)) {
1912+ case TOK_ASM_vcvtreq_s32_f64:
1913+ case TOK_ASM_vcvtreq_u32_f64:
1914+ case TOK_ASM_vcvteq_s32_f64:
1915+ case TOK_ASM_vcvteq_u32_f64:
1916+ case TOK_ASM_vcvteq_f64_s32:
1917+ case TOK_ASM_vcvteq_f64_u32:
1918+ case TOK_ASM_vcvteq_f32_f64:
1919+ coprocessor = CP_DOUBLE_PRECISION_FLOAT;
1920+ break;
1921+ case TOK_ASM_vcvtreq_s32_f32:
1922+ case TOK_ASM_vcvtreq_u32_f32:
1923+ case TOK_ASM_vcvteq_s32_f32:
1924+ case TOK_ASM_vcvteq_u32_f32:
1925+ case TOK_ASM_vcvteq_f32_s32:
1926+ case TOK_ASM_vcvteq_f32_u32:
1927+ case TOK_ASM_vcvteq_f64_f32:
1928+ coprocessor = CP_SINGLE_PRECISION_FLOAT;
1929+ break;
1930+ default:
1931+ tcc_error("Unknown coprocessor for instruction '%s'", get_tok_str(token, NULL));
1932+ return;
1933+ }
1934+
1935+ parse_operand(s1, &ops[0]);
1936+ ops[1].type = OP_IM8;
1937+ ops[1].e.v = 8;
1938+ /* floating-point -> integer */
1939+ switch (ARM_INSTRUCTION_GROUP(token)) {
1940+ case TOK_ASM_vcvtreq_s32_f32:
1941+ case TOK_ASM_vcvtreq_s32_f64:
1942+ case TOK_ASM_vcvteq_s32_f32:
1943+ case TOK_ASM_vcvteq_s32_f64:
1944+ ops[1].e.v |= 1; // signed
1945+ /* fall through */
1946+ case TOK_ASM_vcvteq_u32_f32:
1947+ case TOK_ASM_vcvteq_u32_f64:
1948+ case TOK_ASM_vcvtreq_u32_f32:
1949+ case TOK_ASM_vcvtreq_u32_f64:
1950+ ops[1].e.v |= 4; // to_integer (opc2)
1951+ break;
1952+ /* floating-point size conversion */
1953+ case TOK_ASM_vcvteq_f64_f32:
1954+ case TOK_ASM_vcvteq_f32_f64:
1955+ ops[1].e.v = 7;
1956+ break;
1957+ }
1958+
1959+ if (tok == ',')
1960+ next();
1961+ else
1962+ expect("','");
1963+ parse_operand(s1, &ops[2]);
1964+
1965+ switch (ARM_INSTRUCTION_GROUP(token)) {
1966+ /* floating-point -> integer */
1967+ case TOK_ASM_vcvteq_s32_f32:
1968+ case TOK_ASM_vcvteq_s32_f64:
1969+ case TOK_ASM_vcvteq_u32_f32:
1970+ case TOK_ASM_vcvteq_u32_f64:
1971+ opcode2 |= 4; // round_zero
1972+ break;
1973+
1974+ /* integer -> floating-point */
1975+ case TOK_ASM_vcvteq_f64_s32:
1976+ case TOK_ASM_vcvteq_f32_s32:
1977+ opcode2 |= 4; // signed--special
1978+ break;
1979+
1980+ /* floating-point size conversion */
1981+ case TOK_ASM_vcvteq_f64_f32:
1982+ case TOK_ASM_vcvteq_f32_f64:
1983+ opcode2 |= 4; // always set
1984+ break;
1985+ }
1986+
1987+ switch (ARM_INSTRUCTION_GROUP(token)) {
1988+ case TOK_ASM_vcvteq_f64_u32:
1989+ case TOK_ASM_vcvteq_f64_s32:
1990+ case TOK_ASM_vcvteq_f64_f32:
1991+ if (ops[0].type == OP_VREG64 && ops[2].type == OP_VREG32) {
1992+ } else {
1993+ expect("d<number>, s<number>");
1994+ return;
1995+ }
1996+ break;
1997+ default:
1998+ if (coprocessor == CP_SINGLE_PRECISION_FLOAT) {
1999+ if (ops[0].type == OP_VREG32 && ops[2].type == OP_VREG32) {
2000+ } else {
2001+ expect("s<number>, s<number>");
2002+ return;
2003+ }
2004+ } else if (coprocessor == CP_DOUBLE_PRECISION_FLOAT) {
2005+ if (ops[0].type == OP_VREG32 && ops[2].type == OP_VREG64) {
2006+ } else {
2007+ expect("s<number>, d<number>");
2008+ return;
2009+ }
2010+ }
2011+ }
2012+
2013+ if (ops[2].type == OP_VREG32) {
2014+ if (ops[2].reg & 1)
2015+ opcode2 |= 1;
2016+ ops[2].reg >>= 1;
2017+ }
2018+ if (ops[0].type == OP_VREG32) {
2019+ if (ops[0].reg & 1)
2020+ opcode1 |= 4;
2021+ ops[0].reg >>= 1;
2022+ }
2023+ asm_emit_coprocessor_opcode(condition_code_of_token(token), coprocessor, opcode1, ops[0].reg, (ops[1].type == OP_IM8) ? ops[1].e.v : ops[1].reg, (ops[2].type == OP_IM8) ? ops[2].e.v : ops[2].reg, opcode2, 0);
2024+}
2025+
19052026 static void asm_floating_point_data_processing_opcode(TCCState *s1, int token) {
19062027 uint8_t coprocessor = CP_SINGLE_PRECISION_FLOAT;
19072028 uint8_t opcode1 = 0;
@@ -1920,8 +2041,6 @@ static void asm_floating_point_data_processing_opcode(TCCState *s1, int token) { · 12 unmodified lines
19202041 VFMA 1?10 ?0? Must be unconditional
19212042 VFMS 1?10 ?1? Must be unconditional
19222043
1923− VCVT*
1924−
19252044 VMOV Fd, Fm
19262045 VMOV Sn, Sm, Rd, Rn
19272046 VMOV Rd, Rn, Sn, Sm
@@ -2092,7 +2211,6 @@ static void asm_floating_point_data_processing_opcode(TCCState *s1, int token) { · 164 unmodified lines
20922211 ops[1].e.v = 0;
20932212 }
20942213 break;
2095− // TODO: vcvt; vcvtr
20962214 default:
20972215 expect("known floating point instruction");
20982216 return;
@@ -2580,6 +2698,23 @@ ST_FUNC void asm_opcode(TCCState *s1, int token) · 481 unmodified lines
25802698 asm_floating_point_data_processing_opcode(s1, token);
25812699 return;
25822700
2701+ case TOK_ASM_vcvtreq_s32_f32:
2702+ case TOK_ASM_vcvtreq_s32_f64:
2703+ case TOK_ASM_vcvteq_s32_f32:
2704+ case TOK_ASM_vcvteq_s32_f64:
2705+ case TOK_ASM_vcvtreq_u32_f32:
2706+ case TOK_ASM_vcvtreq_u32_f64:
2707+ case TOK_ASM_vcvteq_u32_f32:
2708+ case TOK_ASM_vcvteq_u32_f64:
2709+ case TOK_ASM_vcvteq_f64_s32:
2710+ case TOK_ASM_vcvteq_f32_s32:
2711+ case TOK_ASM_vcvteq_f64_u32:
2712+ case TOK_ASM_vcvteq_f32_u32:
2713+ case TOK_ASM_vcvteq_f64_f32:
2714+ case TOK_ASM_vcvteq_f32_f64:
2715+ asm_floating_point_vcvt_data_processing_opcode(s1, token);
2716+ return;
2717+
25832718 case TOK_ASM_vpusheq:
25842719 case TOK_ASM_vpopeq:
25852720 case TOK_ASM_vldmeq:
arm-tok.h+36−0
@@ -186,6 +186,24 @@ · 185 unmodified lines
186186 DEF_ASM_CONDED_WITH_SUFFIX(x, f32) \
187187 DEF_ASM_CONDED_WITH_SUFFIX(x, f64)
188188
189+#define DEF_ASM_CONDED_WITH_TWO_SUFFIXES(x, y, z) \
190+ DEF(TOK_ASM_ ## x ## eq ## _ ## y ## _ ## z, #x "eq." #y "." #z) \
191+ DEF(TOK_ASM_ ## x ## ne ## _ ## y ## _ ## z, #x "ne." #y "." #z) \
192+ DEF(TOK_ASM_ ## x ## cs ## _ ## y ## _ ## z, #x "cs." #y "." #z) \
193+ DEF(TOK_ASM_ ## x ## cc ## _ ## y ## _ ## z, #x "cc." #y "." #z) \
194+ DEF(TOK_ASM_ ## x ## mi ## _ ## y ## _ ## z, #x "mi." #y "." #z) \
195+ DEF(TOK_ASM_ ## x ## pl ## _ ## y ## _ ## z, #x "pl." #y "." #z) \
196+ DEF(TOK_ASM_ ## x ## vs ## _ ## y ## _ ## z, #x "vs." #y "." #z) \
197+ DEF(TOK_ASM_ ## x ## vc ## _ ## y ## _ ## z, #x "vc." #y "." #z) \
198+ DEF(TOK_ASM_ ## x ## hi ## _ ## y ## _ ## z, #x "hi." #y "." #z) \
199+ DEF(TOK_ASM_ ## x ## ls ## _ ## y ## _ ## z, #x "ls." #y "." #z) \
200+ DEF(TOK_ASM_ ## x ## ge ## _ ## y ## _ ## z, #x "ge." #y "." #z) \
201+ DEF(TOK_ASM_ ## x ## lt ## _ ## y ## _ ## z, #x "lt." #y "." #z) \
202+ DEF(TOK_ASM_ ## x ## gt ## _ ## y ## _ ## z, #x "gt." #y "." #z) \
203+ DEF(TOK_ASM_ ## x ## le ## _ ## y ## _ ## z, #x "le." #y "." #z) \
204+ DEF(TOK_ASM_ ## x ## _ ## y ## _ ## z, #x "." #y "." #z) \
205+ DEF(TOK_ASM_ ## x ## rsvd ## _ ## y ## _ ## z, #x "rsvd." #y "." #z)
206+
189207 /* Note: add new tokens after nop (MUST always use DEF_ASM_CONDED) */
190208
191209 DEF_ASM_CONDED(nop)
@@ -335,6 +353,24 @@ · 143 unmodified lines
335353 DEF_ASM_CONDED_VFP_F32_F64(vcmpe)
336354 DEF_ASM_CONDED_VFP_F32_F64(vmov)
337355
356+ DEF_ASM_CONDED_WITH_TWO_SUFFIXES(vcvtr, s32, f64)
357+ DEF_ASM_CONDED_WITH_TWO_SUFFIXES(vcvtr, s32, f32)
358+ DEF_ASM_CONDED_WITH_TWO_SUFFIXES(vcvtr, u32, f64)
359+ DEF_ASM_CONDED_WITH_TWO_SUFFIXES(vcvtr, u32, f32)
360+
361+ DEF_ASM_CONDED_WITH_TWO_SUFFIXES(vcvt, s32, f64)
362+ DEF_ASM_CONDED_WITH_TWO_SUFFIXES(vcvt, s32, f32)
363+ DEF_ASM_CONDED_WITH_TWO_SUFFIXES(vcvt, u32, f64)
364+ DEF_ASM_CONDED_WITH_TWO_SUFFIXES(vcvt, u32, f32)
365+
366+ DEF_ASM_CONDED_WITH_TWO_SUFFIXES(vcvt, f64, s32)
367+ DEF_ASM_CONDED_WITH_TWO_SUFFIXES(vcvt, f32, s32)
368+ DEF_ASM_CONDED_WITH_TWO_SUFFIXES(vcvt, f64, u32)
369+ DEF_ASM_CONDED_WITH_TWO_SUFFIXES(vcvt, f32, u32)
370+
371+ DEF_ASM_CONDED_WITH_TWO_SUFFIXES(vcvt, f64, f32)
372+ DEF_ASM_CONDED_WITH_TWO_SUFFIXES(vcvt, f32, f64)
373+
338374 DEF_ASM_CONDED(vpush)
339375 DEF_ASM_CONDED(vpop)
340376 DEF_ASM_CONDED(vldm)
tests/arm-asm-testsuite.sh+3−1
@@ -13,7 +13,7 @@ cat ../arm-tok.h | \ · 12 unmodified lines
1313 grep -v 'DEF_ASM_CONDED_WITH_SUFFIX(x' | \
1414 sed -e 's;^[ ]*DEF_ASM_CONDED_VFP_F32_F64[^(]*(\(.*\)).*$; DEF_ASM_CONDED(\1.f32)\
1515 DEF_ASM_CONDED(\1.f64);g' | \
16− sed -e 's;^[ ]*DEF_ASM[^(]*(\(.*\)).*$;\1;g' | \
16+ sed -e 's;^[ ]*DEF_ASM[^(]*(\(.*\)).*$;\1;g' -e 's;, ;.;g' | \
1717 egrep -v '^((r|c|p|s|d)[0-9]+|fp|ip|sp|lr|pc|asl|apsr_nzcv|fpsid|fpscr|fpexc)$' | while read s
1818 do
1919 as_opts=""
@@ -162,6 +162,8 @@ do · 142 unmodified lines
162162 "fpexc, r2" \
163163 "fpscr, r2" \
164164 "fpsid, r2" \
165+ "s3, d4" \
166+ "d4, s3" \
165167 ""
166168 do
167169 #echo ".syntax unified" > a.s

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t