@@ -301,29 +301,16 @@ void asm_thumb_b_n(asm_thumb_t *as, int label) {
301301 }
302302}
303303
304- #define OP_BEQ_N (byte_offset ) (0xd000 | (((byte_offset) >> 1) & 0x00ff))
305- #define OP_BNE_N (byte_offset ) (0xd100 | (((byte_offset) >> 1) & 0x00ff))
306- #define OP_BCS_N (byte_offset ) (0xd200 | (((byte_offset) >> 1) & 0x00ff))
307- #define OP_BCC_N (byte_offset ) (0xd300 | (((byte_offset) >> 1) & 0x00ff))
308- #define OP_BMI_N (byte_offset ) (0xd400 | (((byte_offset) >> 1) & 0x00ff))
309- #define OP_BPL_N (byte_offset ) (0xd500 | (((byte_offset) >> 1) & 0x00ff))
310- #define OP_BVS_N (byte_offset ) (0xd600 | (((byte_offset) >> 1) & 0x00ff))
311- #define OP_BVC_N (byte_offset ) (0xd700 | (((byte_offset) >> 1) & 0x00ff))
312- #define OP_BHI_N (byte_offset ) (0xd800 | (((byte_offset) >> 1) & 0x00ff))
313- #define OP_BLS_N (byte_offset ) (0xd900 | (((byte_offset) >> 1) & 0x00ff))
314- #define OP_BGE_N (byte_offset ) (0xda00 | (((byte_offset) >> 1) & 0x00ff))
315- #define OP_BLT_N (byte_offset ) (0xdb00 | (((byte_offset) >> 1) & 0x00ff))
316- #define OP_BGT_N (byte_offset ) (0xdc00 | (((byte_offset) >> 1) & 0x00ff))
317- #define OP_BLE_N (byte_offset ) (0xdd00 | (((byte_offset) >> 1) & 0x00ff))
318-
319- void asm_thumb_bgt_n (asm_thumb_t * as , int label ) {
304+ #define OP_BCC_N (cond , byte_offset ) (0xd000 | ((cond) << 8) | (((byte_offset) >> 1) & 0x00ff))
305+
306+ void asm_thumb_bcc_n (asm_thumb_t * as , int cond , int label ) {
320307 int dest = get_label_dest (as , label );
321308 int rel = dest - as -> code_offset ;
322309 rel -= 4 ; // account for instruction prefetch, PC is 4 bytes ahead of this instruction
323310 if (SIGNED_FIT9 (rel )) {
324- asm_thumb_write_op16 (as , OP_BGT_N ( rel ));
311+ asm_thumb_write_op16 (as , OP_BCC_N ( cond , rel ));
325312 } else {
326- printf ("asm_thumb_bgt : branch does not fit in 9 bits\n" );
313+ printf ("asm_thumb_bcc_n : branch does not fit in 9 bits\n" );
327314 }
328315}
329316
@@ -408,32 +395,25 @@ void asm_thumb_b_label(asm_thumb_t *as, int label) {
408395}
409396
410397// all these bit arithmetics need coverage testing!
411- #define OP_BEQ (byte_offset ) (0xd000 | (((byte_offset) >> 1) & 0x00ff))
412- #define OP_BEQW_HI (byte_offset ) (0xf000 | (((byte_offset) >> 10) & 0x0400) | (((byte_offset) >> 14) & 0x003f))
413- #define OP_BEQW_LO (byte_offset ) (0x8000 | ((byte_offset) & 0x2000) | (((byte_offset) >> 1) & 0x0fff))
414-
415- void asm_thumb_cmp_reg_bz_label (asm_thumb_t * as , uint rlo , int label ) {
416- assert (rlo < REG_R8 );
417-
418- // compare reg with 0
419- asm_thumb_write_op16 (as , OP_CMP_RLO_I8 (rlo , 0 ));
398+ #define OP_BCC_W_HI (cond , byte_offset ) (0xf000 | ((cond) << 6) | (((byte_offset) >> 10) & 0x0400) | (((byte_offset) >> 14) & 0x003f))
399+ #define OP_BCC_W_LO (byte_offset ) (0x8000 | ((byte_offset) & 0x2000) | (((byte_offset) >> 1) & 0x0fff))
420400
421- // branch if equal
401+ void asm_thumb_bcc_label ( asm_thumb_t * as , int cond , int label ) {
422402 int dest = get_label_dest (as , label );
423403 int rel = dest - as -> code_offset ;
424404 rel -= 4 ; // account for instruction prefetch, PC is 4 bytes ahead of this instruction
425405 if (dest >= 0 && rel <= -4 ) {
426406 // is a backwards jump, so we know the size of the jump on the first pass
427407 // calculate rel assuming 9 bit relative jump
428408 if (SIGNED_FIT9 (rel )) {
429- asm_thumb_write_op16 (as , OP_BEQ ( rel ));
409+ asm_thumb_write_op16 (as , OP_BCC_N ( cond , rel ));
430410 } else {
431411 goto large_jump ;
432412 }
433413 } else {
434414 // is a forwards jump, so need to assume it's large
435415 large_jump :
436- asm_thumb_write_op32 (as , OP_BEQW_HI ( rel ), OP_BEQW_LO (rel ));
416+ asm_thumb_write_op32 (as , OP_BCC_W_HI ( cond , rel ), OP_BCC_W_LO (rel ));
437417 }
438418}
439419
0 commit comments