File: insn-casesi.c

package info (click to toggle)
gcc-riscv64-unknown-elf 8.3.0.2019.08%2Bdfsg-1
  • links: PTS, VCS
  • area: main
  • in suites: bullseye
  • size: 680,956 kB
  • sloc: ansic: 3,237,715; cpp: 896,882; ada: 772,854; f90: 144,254; asm: 68,788; makefile: 67,456; sh: 29,743; exp: 28,045; objc: 15,273; fortran: 11,885; python: 7,369; pascal: 5,375; awk: 3,725; perl: 2,872; yacc: 316; xml: 311; ml: 285; lex: 198; haskell: 122
file content (112 lines) | stat: -rw-r--r-- 1,674 bytes parent folder | download | duplicates (6)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
/* { dg-do run } */
/* { dg-options "-mips16 -mcode-readable=yes" } */

int __attribute__ ((noinline))
frob (int i)
{
  switch (i)
    {
    case -5:
      return -2;
    case -3:
      return -1;
    case 0:
      return 0;
    case 3:
      return 1;
    case 5:
      break;
    default:
      __builtin_unreachable ();
    }
  return i;
}

int
main (int argc, char **argv)
{
  asm ("" : "+r" (argc));
  argc = frob ((argc & 10) - 5);
  asm ("" : "+r" (argc));
  return !argc;
}

/* This will result in assembly like:

	.text
	.align	2
	.globl	frob
	.set	mips16
	.set	nomicromips
	.ent	frob
	.type	frob, @function
frob:
	.frame	$sp,0,$31		# vars= 0, regs= 0/0, args= 0, gp= 0
	.mask	0x00000000,0
	.fmask	0x00000000,0
	addiu	$2,$4,5
	sltu	$2,11
	bteqz	$L2
	sll	$3,$2,1
	la	$2,$L4
	addu	$3,$2,$3
	lh	$3,0($3)
	addu	$2,$2,$3
	j	$2
	.align	1
	.align	2
$L4:
	.half	$L3-$L4
	.half	$L2-$L4
	.half	$L9-$L4
	.half	$L2-$L4
	.half	$L2-$L4
	.half	$L8-$L4
	.half	$L2-$L4
	.half	$L2-$L4
	.half	$L7-$L4
	.half	$L2-$L4
	.half	$L8-$L4
$L8:
	.set	noreorder
	.set	nomacro
	jr	$31
	move	$2,$4
	.set	macro
	.set	reorder

$L9:
	li	$2,1
	.set	noreorder
	.set	nomacro
	jr	$31
	neg	$2,$2
	.set	macro
	.set	reorder

$L3:
	li	$2,2
	.set	noreorder
	.set	nomacro
	jr	$31
	neg	$2,$2
	.set	macro
	.set	reorder

$L7:
	.set	noreorder
	.set	nomacro
	jr	$31
	li	$2,1
	.set	macro
	.set	reorder

$L2:
	.insn
	.end	frob
	.size	frob, .-frob

  for `frob' and we want to make sure it links correctly owing to the
  `.insn' pseudo-op which needs to be there at `$L2' as there's no
  code following and the label is a MIPS16 branch target (even though
  the branch is never taken.  See also insn-tablejump.c.  */