stryd_one Posted February 11, 2008 Report Posted February 11, 2008 Hi guys, Good news, I have just tested a 15-bit bitfield (15, not 16, to test correct alignment of odd sizes across bytes), and all accesses are correct :)This was with a post 2.7.0 SDCC release.AC and I have been warning people of this limitation for years now, I had to add this info to lots of old threads which are used as references in the wiki and such. Ugh!Definition looks like this:typedef union {struct { unsigned ALL:15; } struct { unsigned test1:1; unsigned test2:1; unsigned test3:1; unsigned test4:1; unsigned test5:1; unsigned test6:1; unsigned test7:1; unsigned test8:1; unsigned test9:1; unsigned test10:1; unsigned test11:1; unsigned test12:1; unsigned test13:1; unsigned test14:1; unsigned test15:1; } } bitfield_t;I tested it by sending notes depending on the bits 6,7,8 and 14 (test7, test8, test9 and test15).More useless info brought to you by stryd_one ;D Quote
audiocommander Posted February 11, 2008 Report Posted February 11, 2008 jipee :Dhave you also tested bitfields > 15 entries?Best,Michael Quote
stryd_one Posted February 11, 2008 Author Report Posted February 11, 2008 I haven't yet, but I suspect they will be almost unlimited... The output ASM is pretty simple, it just uses for EG:BTFSC (_bitfield) ,6 for bit 6or BTFSC (_bitfield +1) ,4 for bit 12That's from memory... I'll test it with some really silly big bitfields tomorrow night, and paste the code. Quote
stryd_one Posted February 12, 2008 Author Report Posted February 12, 2008 Yeh, sweet. Our new limit looks like... a whole bank :) LOL typedef union { struct { unsigned ALL:8; }; struct { unsigned test1:1; unsigned test2:1; unsigned test3:1; unsigned test4:1; unsigned test5:1; unsigned test6:1; unsigned test7:1; unsigned test8:1; unsigned test9:1; unsigned test10:1; unsigned test11:1; unsigned test12:1; unsigned test13:1; unsigned test14:1; unsigned test15:1; unsigned test16:1; unsigned test17:1; unsigned test18:1; unsigned test19:1; unsigned test20:1; unsigned test21:1; unsigned test22:1; unsigned test23:1; unsigned test24:1; unsigned test25:1; unsigned test26:1; unsigned test27:1; unsigned test28:1; unsigned test29:1; unsigned test30:1; unsigned test31:1; unsigned test32:1; unsigned test33:1; unsigned test34:1; unsigned test35:1; unsigned test36:1; unsigned test37:1; unsigned test38:1; unsigned test39:1; unsigned test40:1; unsigned test41:1; unsigned test42:1; unsigned test43:1; unsigned test44:1; unsigned test45:1; unsigned test46:1; unsigned test47:1; unsigned test48:1; unsigned test49:1; unsigned test50:1; unsigned test51:1; unsigned test52:1; unsigned test53:1; unsigned test54:1; unsigned test55:1; unsigned test56:1; unsigned test57:1; unsigned test58:1; unsigned test59:1; unsigned test60:1; unsigned test61:1; unsigned test62:1; unsigned test63:1; unsigned test64:1; unsigned test65:1; unsigned test66:1; unsigned test67:1; unsigned test68:1; unsigned test69:1; }; } testbits_t; testbits_t mybitfield; void MPROC_NotifyReceivedEvnt(unsigned char evnt0, unsigned char evnt1, unsigned char evnt2) __wparam { if (evnt0 == 0x92) { mybitfield.test6 = 0; mybitfield.test15 = 0; mybitfield.test55 = 0; }; if (evnt0 == 0x93) { mybitfield.test6 = 1; mybitfield.test15 = 1; mybitfield.test55 = 1; }; if (evnt0 == 0x91) { if (mybitfield.test55) { MIOS_MIDI_TxBufferPut(0x90); MIOS_MIDI_TxBufferPut(0x55); MIOS_MIDI_TxBufferPut(0x7f); }; if (mybitfield.test15) { MIOS_MIDI_TxBufferPut(0x90); MIOS_MIDI_TxBufferPut(0x15); MIOS_MIDI_TxBufferPut(0x7f); }; if (mybitfield.test6) { MIOS_MIDI_TxBufferPut(0x90); MIOS_MIDI_TxBufferPut(0x06); MIOS_MIDI_TxBufferPut(0x7f); }; }; } It's ugly, but it works!: udata_main_0 udata 0x000080 data 0x000009 _mybitfield 0x000080 data extern _output\main.asm ; Starting pCode block S_main__MPROC_NotifyReceivedEvnt code _MPROC_NotifyReceivedEvnt: ; .line 143; main.c void MPROC_NotifyReceivedEvnt(unsigned char evnt0, unsigned char evnt1, unsigned char evnt2) __wparam MOVFF FSR2L, POSTDEC1 MOVFF FSR1L, FSR2L MOVFF r0x00, POSTDEC1 MOVWF r0x00 ; .line 147; main.c if (evnt0 == 0x92) { MOVF r0x00, W XORLW 0x92 BNZ _00126_DS_ _00146_DS_: BANKSEL _mybitfield ; .line 150; main.c mybitfield.test6 = 0; BCF _mybitfield, 5, B ; removed redundant BANKSEL ; .line 151; main.c mybitfield.test15 = 0; BCF (_mybitfield + 1), 6, B ; removed redundant BANKSEL ; .line 152; main.c mybitfield.test55 = 0; BCF (_mybitfield + 6), 6, B _00126_DS_: ; .line 157; main.c if (evnt0 == 0x93) { MOVF r0x00, W XORLW 0x93 BNZ _00128_DS_ _00148_DS_: BANKSEL _mybitfield ; .line 160; main.c mybitfield.test6 = 1; BSF _mybitfield, 5, B ; removed redundant BANKSEL ; .line 161; main.c mybitfield.test15 = 1; BSF (_mybitfield + 1), 6, B ; removed redundant BANKSEL ; .line 162; main.c mybitfield.test55 = 1; BSF (_mybitfield + 6), 6, B _00128_DS_: ; .line 168; main.c if (evnt0 == 0x91) { MOVF r0x00, W XORLW 0x91 BNZ _00137_DS_ _00150_DS_: BANKSEL (_mybitfield + 6) ; .line 172; main.c if (mybitfield.test55) { BTFSS (_mybitfield + 6), 6, B BRA _00130_DS_ ; .line 173; main.c MIOS_MIDI_TxBufferPut(0x90); MOVLW 0x90 CALL _MIOS_MIDI_TxBufferPut ; .line 174; main.c MIOS_MIDI_TxBufferPut(0x55); MOVLW 0x55 CALL _MIOS_MIDI_TxBufferPut ; .line 175; main.c MIOS_MIDI_TxBufferPut(0x7f); MOVLW 0x7f CALL _MIOS_MIDI_TxBufferPut _00130_DS_: BANKSEL (_mybitfield + 1) ; .line 178; main.c if (mybitfield.test15) { BTFSS (_mybitfield + 1), 6, B BRA _00132_DS_ ; .line 179; main.c MIOS_MIDI_TxBufferPut(0x90); MOVLW 0x90 CALL _MIOS_MIDI_TxBufferPut ; .line 180; main.c MIOS_MIDI_TxBufferPut(0x15); MOVLW 0x15 CALL _MIOS_MIDI_TxBufferPut ; .line 181; main.c MIOS_MIDI_TxBufferPut(0x7f); MOVLW 0x7f CALL _MIOS_MIDI_TxBufferPut _00132_DS_: BANKSEL _mybitfield ; .line 184; main.c if (mybitfield.test6) { BTFSS _mybitfield, 5, B BRA _00137_DS_ ; .line 185; main.c MIOS_MIDI_TxBufferPut(0x90); MOVLW 0x90 CALL _MIOS_MIDI_TxBufferPut ; .line 186; main.c MIOS_MIDI_TxBufferPut(0x06); MOVLW 0x06 CALL _MIOS_MIDI_TxBufferPut ; .line 187; main.c MIOS_MIDI_TxBufferPut(0x7f); MOVLW 0x7f CALL _MIOS_MIDI_TxBufferPut _00137_DS_: MOVFF PREINC1, r0x00 MOVFF PREINC1, FSR2L RETURN So why a whole bank? cause it does the arithmetic pre-assembly, and optimises out any banksels. I don't see why it couldn't access like (_mybitfield + 20) hahah. Something of note: typedef union { struct { unsigned ALL:8; }; struct { unsigned test1:1; unsigned test2:1; unsigned test3:1; unsigned test4:1; .........This works. If you make it ALL:69, it says that each field has a 16 bit max. So ALL:16 is good, ALL:17 bad. But the rest is happy :)Edit: I chose 69 because I wanted to go higher than 64, and that's how it pasted out. I am not a pervert. Well, I am. But that's not why I chose 69. :D Quote
audiocommander Posted February 12, 2008 Report Posted February 12, 2008 I am not a pervert. Well' date=' I am. But that's not why I chose 69. [/quote']ohhhh, I know you are... ::)nudge nudge, say no more! Say no more! hehehehehehe ;Dand now for something completely different: I'm really happy about loosing this 8-bit restriction! Thanks for testing & sharing! =) Quote
stryd_one Posted February 13, 2008 Author Report Posted February 13, 2008 eh? eh? *click click*LOL Quote
stryd_one Posted July 30, 2008 Author Report Posted July 30, 2008 AAaaaaand we're back to 8 bits: SDCC pic16 port error: the port currently does not support *reading* bitfields of size >=8. Instead of generating wrong code, bailling out... make: *** [_output/main.o] Error 1 That's erroneous, it doesnt support >8 (=8 is ok) Quote
lylehaze Posted July 30, 2008 Report Posted July 30, 2008 The first thing you need to ask yourself is:How many people can get excited about a bitfield?Then you need to ask, and how many friends can they share their excitement with?The internet is truly making the world a global village.LyleHaze Quote
stryd_one Posted July 31, 2008 Author Report Posted July 31, 2008 Bitfield obsessed coding geek loner hermits of the world, UNITE! Quote
nILS Posted August 3, 2008 Report Posted August 3, 2008 [me=nILS Podewski]cues comic-style trumpet clip: "mwuah mwuah mwuaaaaaaaaaaaaaah"[/me] Quote
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.