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
1902 }1902 }
1903}1903}
1904 1904
1905static 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
1905static void asm_floating_point_data_processing_opcode(TCCState *s1, int token) {2026static void asm_floating_point_data_processing_opcode(TCCState *s1, int token) {
1906 uint8_t coprocessor = CP_SINGLE_PRECISION_FLOAT;2027 uint8_t coprocessor = CP_SINGLE_PRECISION_FLOAT;
1907 uint8_t opcode1 = 0;2028 uint8_t opcode1 = 0;
@@ -1920,8 +2041,6 @@ static void asm_floating_point_data_processing_opcode(TCCState *s1, int token) { · 12 unmodified lines
1920 VFMA 1?10 ?0? Must be unconditional2041 VFMA 1?10 ?0? Must be unconditional
1921 VFMS 1?10 ?1? Must be unconditional2042 VFMS 1?10 ?1? Must be unconditional
1922 2043
1923 VCVT*
1924
1925 VMOV Fd, Fm2044 VMOV Fd, Fm
1926 VMOV Sn, Sm, Rd, Rn2045 VMOV Sn, Sm, Rd, Rn
1927 VMOV Rd, Rn, Sn, Sm2046 VMOV Rd, Rn, Sn, Sm
@@ -2092,7 +2211,6 @@ static void asm_floating_point_data_processing_opcode(TCCState *s1, int token) { · 164 unmodified lines
2092 ops[1].e.v = 0;2211 ops[1].e.v = 0;
2093 }2212 }
2094 break;2213 break;
2095 // TODO: vcvt; vcvtr
2096 default:2214 default:
2097 expect("known floating point instruction");2215 expect("known floating point instruction");
2098 return;2216 return;
@@ -2580,6 +2698,23 @@ ST_FUNC void asm_opcode(TCCState *s1, int token) · 481 unmodified lines
2580 asm_floating_point_data_processing_opcode(s1, token);2698 asm_floating_point_data_processing_opcode(s1, token);
2581 return;2699 return;
2582 2700
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
2583 case TOK_ASM_vpusheq:2718 case TOK_ASM_vpusheq:
2584 case TOK_ASM_vpopeq:2719 case TOK_ASM_vpopeq:
2585 case TOK_ASM_vldmeq:2720 case TOK_ASM_vldmeq:
arm-tok.h+36−0
@@ -186,6 +186,24 @@ · 185 unmodified lines
186 DEF_ASM_CONDED_WITH_SUFFIX(x, f32) \186 DEF_ASM_CONDED_WITH_SUFFIX(x, f32) \
187 DEF_ASM_CONDED_WITH_SUFFIX(x, f64)187 DEF_ASM_CONDED_WITH_SUFFIX(x, f64)
188 188
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
189/* Note: add new tokens after nop (MUST always use DEF_ASM_CONDED) */207/* Note: add new tokens after nop (MUST always use DEF_ASM_CONDED) */
190 208
191 DEF_ASM_CONDED(nop)209 DEF_ASM_CONDED(nop)
@@ -335,6 +353,24 @@ · 143 unmodified lines
335 DEF_ASM_CONDED_VFP_F32_F64(vcmpe)353 DEF_ASM_CONDED_VFP_F32_F64(vcmpe)
336 DEF_ASM_CONDED_VFP_F32_F64(vmov)354 DEF_ASM_CONDED_VFP_F32_F64(vmov)
337 355
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
338 DEF_ASM_CONDED(vpush)374 DEF_ASM_CONDED(vpush)
339 DEF_ASM_CONDED(vpop)375 DEF_ASM_CONDED(vpop)
340 DEF_ASM_CONDED(vldm)376 DEF_ASM_CONDED(vldm)
tests/arm-asm-testsuite.sh+3−1
@@ -13,7 +13,7 @@ cat ../arm-tok.h | \ · 12 unmodified lines
13 grep -v 'DEF_ASM_CONDED_WITH_SUFFIX(x' | \13 grep -v 'DEF_ASM_CONDED_WITH_SUFFIX(x' | \
14 sed -e 's;^[ ]*DEF_ASM_CONDED_VFP_F32_F64[^(]*(\(.*\)).*$; DEF_ASM_CONDED(\1.f32)\14 sed -e 's;^[ ]*DEF_ASM_CONDED_VFP_F32_F64[^(]*(\(.*\)).*$; DEF_ASM_CONDED(\1.f32)\
15 DEF_ASM_CONDED(\1.f64);g' | \15 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' | \
17 egrep -v '^((r|c|p|s|d)[0-9]+|fp|ip|sp|lr|pc|asl|apsr_nzcv|fpsid|fpscr|fpexc)$' | while read s17 egrep -v '^((r|c|p|s|d)[0-9]+|fp|ip|sp|lr|pc|asl|apsr_nzcv|fpsid|fpscr|fpexc)$' | while read s
18do18do
19 as_opts=""19 as_opts=""
@@ -162,6 +162,8 @@ do · 142 unmodified lines
162 "fpexc, r2" \162 "fpexc, r2" \
163 "fpscr, r2" \163 "fpscr, r2" \
164 "fpsid, r2" \164 "fpsid, r2" \
165 "s3, d4" \
166 "d4, s3" \
165 ""167 ""
166 do168 do
167 #echo ".syntax unified" > a.s169 #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