m6[luca@moore ~/repos/jitter/_build/cross-mips32r6]$ cat testcase-beqzc.s
.set arch=mips32r6
	
        .text

good_then_bad:
        jic   $25, 0        # Good.
        bc    foo           # Good.
        beqzc $3, foo       # Wrong: delay slot.
        beqzc $3, foo       # No delay slot here because of the next instruction.
        addiu $5, $5, 1

bad:
        bnezc $3, foo
        bltzc $3, foo
        bgtzc $3, foo
        blezc $3, foo
        bgezc $3, foo
	
# Surrounding the misbehaving instruction I want to generate without
# a delay-slot nop with  .set noreorder ... .set reorder is not enough,
# when the instruction is the only one before .set reorder, or the last
# one.  After .set reorder the delay-slot nop may get added anyway,
# depending on the following instruction.
#
# Example (NO delay-slot nop):
workaround_good:
.set noreorder
        beqzc $3, foo
.set reorder
        addiu $5, $5, 42  # NO delay-slot nop added to the previous instruction,
                          # in this case.  But of course the hardware would
                          # not execute an instruction in this position anyway
	                  # after a taken branch, indepdendently from what it
                          # might be.
# Example (DELAY-slot nop):
workaround_bad:
.set noreorder
        beqzc $3, foo
.set reorder
        bc    foo           # DELAY-slot nop added to the previous instruction.
	
        bnezc $3, foo       # Wrong: delay-slot nop.
        bltzc $3, foo       # Wrong: delay-slot nop.
        bltc  $3, $4, foo   # Wrong: delay-slot nop.
        bltzc $3, foo
        bltzc $3, foo
        bltz  $3, foo       # Not compact: a nop after this is correct.
        bltzc $3, foo
m6[luca@moore ~/repos/jitter/_build/cross-mips32r6]$ mips-unknown-linux-gnu-as testcase-beqzc.s && mips-unknown-linux-gnu-objdump --architecture=mips:isa32r6 --disassembler-options=no-aliases,reg-names=numeric --disassemble a.out 

a.out:     file format elf32-tradbigmips


Disassembly of section .text:

00000000 <good_then_bad>:
   0:	d8190000 	jic	$25,0
   4:	cbffffff 	bc	4 <good_then_bad+0x4>
   8:	d87fffff 	beqzc	$3,8 <good_then_bad+0x8>
   c:	00000000 	sll	$0,$0,0x0
  10:	d87fffff 	beqzc	$3,10 <good_then_bad+0x10>
  14:	24a50001 	addiu	$5,$5,1

00000018 <bad>:
  18:	f87fffff 	bnezc	$3,18 <bad>
  1c:	00000000 	sll	$0,$0,0x0
  20:	5c63ffff 	bltzc	$3,20 <bad+0x8>
  24:	00000000 	sll	$0,$0,0x0
  28:	5c03ffff 	bgtzc	$3,28 <bad+0x10>
  2c:	00000000 	sll	$0,$0,0x0
  30:	5803ffff 	blezc	$3,30 <bad+0x18>
  34:	00000000 	sll	$0,$0,0x0
  38:	5863ffff 	bgezc	$3,38 <bad+0x20>
  3c:	00000000 	sll	$0,$0,0x0

00000040 <workaround_good>:
  40:	d87fffff 	beqzc	$3,40 <workaround_good>
  44:	24a5002a 	addiu	$5,$5,42

00000048 <workaround_bad>:
  48:	d87fffff 	beqzc	$3,48 <workaround_bad>
  4c:	00000000 	sll	$0,$0,0x0
  50:	cbffffff 	bc	50 <workaround_bad+0x8>
  54:	f87fffff 	bnezc	$3,54 <workaround_bad+0xc>
  58:	00000000 	sll	$0,$0,0x0
  5c:	5c63ffff 	bltzc	$3,5c <workaround_bad+0x14>
  60:	00000000 	sll	$0,$0,0x0
  64:	5c64ffff 	bltc	$3,$4,64 <workaround_bad+0x1c>
  68:	00000000 	sll	$0,$0,0x0
  6c:	5c63ffff 	bltzc	$3,6c <workaround_bad+0x24>
  70:	00000000 	sll	$0,$0,0x0
  74:	5c63ffff 	bltzc	$3,74 <workaround_bad+0x2c>
  78:	00000000 	sll	$0,$0,0x0
  7c:	0460ffff 	bltz	$3,7c <workaround_bad+0x34>
  80:	00000000 	sll	$0,$0,0x0
  84:	5c63ffff 	bltzc	$3,84 <workaround_bad+0x3c>
	...
m6[luca@moore ~/repos/jitter/_build/cross-mips32r6]$ mips-unknown-linux-gnu-gcc -c testcase-beqzc.s && mips-unknown-linux-gnu-objdump --architecture=mips:isa32r6 --disassembler-options=no-aliases,reg-names=numeric --disassemble testcase-beqzc.o

testcase-beqzc.o:     file format elf32-tradbigmips


Disassembly of section .text:

00000000 <good_then_bad>:
   0:	d8190000 	jic	$25,0
   4:	cbffffff 	bc	4 <good_then_bad+0x4>
   8:	d87fffff 	beqzc	$3,8 <good_then_bad+0x8>
   c:	00000000 	sll	$0,$0,0x0
  10:	d87fffff 	beqzc	$3,10 <good_then_bad+0x10>
  14:	24a50001 	addiu	$5,$5,1

00000018 <bad>:
  18:	f87fffff 	bnezc	$3,18 <bad>
  1c:	00000000 	sll	$0,$0,0x0
  20:	5c63ffff 	bltzc	$3,20 <bad+0x8>
  24:	00000000 	sll	$0,$0,0x0
  28:	5c03ffff 	bgtzc	$3,28 <bad+0x10>
  2c:	00000000 	sll	$0,$0,0x0
  30:	5803ffff 	blezc	$3,30 <bad+0x18>
  34:	00000000 	sll	$0,$0,0x0
  38:	5863ffff 	bgezc	$3,38 <bad+0x20>
  3c:	00000000 	sll	$0,$0,0x0

00000040 <workaround_good>:
  40:	d87fffff 	beqzc	$3,40 <workaround_good>
  44:	24a5002a 	addiu	$5,$5,42

00000048 <workaround_bad>:
  48:	d87fffff 	beqzc	$3,48 <workaround_bad>
  4c:	00000000 	sll	$0,$0,0x0
  50:	cbffffff 	bc	50 <workaround_bad+0x8>
  54:	f87fffff 	bnezc	$3,54 <workaround_bad+0xc>
  58:	00000000 	sll	$0,$0,0x0
  5c:	5c63ffff 	bltzc	$3,5c <workaround_bad+0x14>
  60:	00000000 	sll	$0,$0,0x0
  64:	5c64ffff 	bltc	$3,$4,64 <workaround_bad+0x1c>
  68:	00000000 	sll	$0,$0,0x0
  6c:	5c63ffff 	bltzc	$3,6c <workaround_bad+0x24>
  70:	00000000 	sll	$0,$0,0x0
  74:	5c63ffff 	bltzc	$3,74 <workaround_bad+0x2c>
  78:	00000000 	sll	$0,$0,0x0
  7c:	0460ffff 	bltz	$3,7c <workaround_bad+0x34>
  80:	00000000 	sll	$0,$0,0x0
  84:	5c63ffff 	bltzc	$3,84 <workaround_bad+0x3c>
	...
m6[luca@moore ~/repos/jitter/_build/cross-mips32r6]$ 
