English Amiga Board


Go Back   English Amiga Board > Coders > Coders. Language > Coders. Blitz Basic

 
 
Thread Tools
Old 24 October 2023, 15:13   #21
Thorham
Computer Nerd
 
Thorham's Avatar
 
Join Date: Sep 2007
Location: Rotterdam/Netherlands
Age: 47
Posts: 3,762
Quote:
Originally Posted by carrion View Post
Maybe they are
Not maybe, definitely.

Quote:
Originally Posted by carrion View Post
but as far as I can tell (and tested) they are slow in BB2.
That's quite a shame, because they're quite important.

Quote:
Originally Posted by carrion View Post
it's faster and compiles strictly to the same code in assembly language.
Yes, although in handwritten asm you'd use a register to pass the argument and you'd also have the routine save registers to the stack:
Code:
    move.l  #123,d0
    bsr     subroutine

subroutine
    movem.l d1,-(sp)
    
    move.l  d0,d1
    lsl.l   #1,d0
    add.l   d1,d0
    
    movem.l (sp)+,d1
    rts
Are you sure it's slow? The above code is basically what a function should more or less compile to.
Thorham is offline  
Old 24 October 2023, 15:14   #22
AestheticDebris
Registered User
 
Join Date: May 2023
Location: Norwich
Posts: 376
Quote:
Originally Posted by DisasterIncarna View Post
JSR/RTS?, never used that kind of thing before but ill try giving that a go, looks like a simple find/replace can be used to replace Gosub>JSR and Return>RTS.
I'm not convinced that will actually make any difference at all in terms of code efficiency. GOSUB is essentially just a synonym for JSR. It only makes a difference with functions/procedures because you're removing the overhead of passing parameters etc, which you could just as "easily" do by converting them to GOSUBs (obviously all the problems of using global variables to manage shared data would then exist).
AestheticDebris is offline  
Old 24 October 2023, 15:53   #23
Daedalus
Registered User
 
Daedalus's Avatar
 
Join Date: Jun 2009
Location: Dublin, then Glasgow
Posts: 6,343
Yep, there's an overhead involved in using functions. If you're using AmiBlitz, you can specify a FAST keyword when defining a function. This makes them a bit faster, but imposes some limitations like not initialising local variables to 0 and not being able to pass strings as parameters. Goto and Gosub are much more efficient - as said, they compile to pretty simple jumps, at the expense of the code modularity and organisation.

I haven't benchmarked it, but if you're looking for more condensed code, Blitz also supports the On version of Goto / Gosub from other Basics. You can jump to a number of labels based on a value, starting from 1. For your code:

Code:
If WHATEVENT= $40 AND EventWindow = mywindow  ; Do something if gadget is selected/hit
     On GadgetHit - 49 Gosub HITSEARCHBOX, HITSEARCHBUTT, HITDESTBOX, HITDESTBUTT, HITEXTRACTTYPE
  EndIf
This is, of course, dependent on your event codes being sequential, and is ripe for introducing bugs if you ever adjust your constants to e.g. fit more gadgets in. I don't think there's any advantage worth the potential for bugs there, but it's an option.
Daedalus is offline  
Old 24 October 2023, 16:39   #24
patrik
Registered User
 
patrik's Avatar
 
Join Date: Jan 2005
Location: UmeƄ
Age: 43
Posts: 924
Is the potential performance overhead of a function call relevant in this case? It looks like it will spend most time waiting on events here.

Had it been an hot inner loop of some computational function, it would be more relevant to worry about calling functions or jumping.
patrik is offline  
Old 24 October 2023, 16:54   #25
DisasterIncarna
Registered User
 
DisasterIncarna's Avatar
 
Join Date: Oct 2021
Location: England
Posts: 1,180
Quote:
Originally Posted by Daedalus View Post
Yep, there's an overhead involved in using functions. If you're using AmiBlitz, you can specify a FAST keyword when defining a function. This makes them a bit faster, but imposes some limitations like not initialising local variables to 0 and not being able to pass strings as parameters. Goto and Gosub are much more efficient - as said, they compile to pretty simple jumps, at the expense of the code modularity and organisation.

I haven't benchmarked it, but if you're looking for more condensed code, Blitz also supports the On version of Goto / Gosub from other Basics. You can jump to a number of labels based on a value, starting from 1. For your code:

Code:
If WHATEVENT= $40 AND EventWindow = mywindow  ; Do something if gadget is selected/hit
     On GadgetHit - 49 Gosub HITSEARCHBOX, HITSEARCHBUTT, HITDESTBOX, HITDESTBUTT, HITEXTRACTTYPE
  EndIf
This is, of course, dependent on your event codes being sequential, and is ripe for introducing bugs if you ever adjust your constants to e.g. fit more gadgets in. I don't think there's any advantage worth the potential for bugs there, but it's an option.
this looks exactly like what im after to cut down a page and a half of code.

yeah i dont ever call the gadget numbers directly, they are all preassigned numbers at the beginning of the program starting at 50 and work up from there in 1's, so at the beginning for example i start with #_SEARCHBOX=50, and every time i need to refer to the button this equates to i refer to it as #_SEARCHBOX rather than a hard/fixed 50, just makes it easier for me when i see a load of GT-Gadget commands using those named tags instead of numbers.

Code:
GTString mywindow,#_SEARCHBOX,0,0,LRSIZE,GADHEIGHT,"",$0,256,SRCHTXT$
is easier for me to quickly identify than

Code:
GTString mywindow,50,0,0,LRSIZE,GADHEIGHT,"",$0,256,SRCHTXT$
probably extra fluff being added but helps me see whats what, esp as my GT gadget stuff looks a bit over complex due to it trying to smart adapt to the window when it resizes and adjust to fill the window when certain gadgets are turned off by the user.

but that "On" solution again looks perfect for what i want, ill try and use that for my 2 main projects.
DisasterIncarna is offline  
Old 24 October 2023, 16:58   #26
DisasterIncarna
Registered User
 
DisasterIncarna's Avatar
 
Join Date: Oct 2021
Location: England
Posts: 1,180
This is at the start of my GUI for UHC Tools, not a massive amount of gadgets but its how i refer to them rather than fixed numbers, my other program uses significantly more gadgets/number id's.

Code:
; Gadget Identifier List

; Row 1 of gadgets
#_SEARCHBOX = 50
#_SEARCHBUTT = 51
#_DESTBOX = 52
#_DESTBUTT = 53
#_EXTRACTTYPE = 54

; Row 2 of gadgets
#_DOWNLOADBUTT = 55
#_CLEARSEARCHBUTT = 56
#_RECENTUPLOADBUTT = 57
#_VIEWREADMEBUTT = 58
#_MIRRORLISTCYCLE = 59

; Row 3 HeaderText
#_HEADERTEXT = 60

; Row 4 of gadgets - Listviews
#_SEARCHRESULTLIST = 61
#_MIRRORLIST = 62
#_CATEGORYLIST = 63
#_UPDATEWATCHER = 64

; Row 5 of gadgets - Info bar
#_INFOTEXT = 65
DisasterIncarna is offline  
Old 25 October 2023, 10:35   #27
Daedalus
Registered User
 
Daedalus's Avatar
 
Join Date: Jun 2009
Location: Dublin, then Glasgow
Posts: 6,343
Yep, using constants definitely makes code more readable and is something that should be encouraged. The thing to bear in mind is that the On form of Gosub effectively does use gadget numbers directly, so if the constants ever change in the future you might have unexpected results from the jump. But so long as you don't change them, it should work fine.
Daedalus is offline  
Old 25 October 2023, 12:41   #28
DisasterIncarna
Registered User
 
DisasterIncarna's Avatar
 
Join Date: Oct 2021
Location: England
Posts: 1,180
noted, cheers.
DisasterIncarna is offline  
Old 09 November 2023, 10:48   #29
E-Penguin
Banana
 
E-Penguin's Avatar
 
Join Date: Jul 2016
Location: Darmstadt
Posts: 1,214
Quote:
Originally Posted by Daedalus View Post
Yep, there's an overhead involved in using functions. If you're using AmiBlitz, you can specify a FAST keyword when defining a function. This makes them a bit faster, but imposes some limitations like not initialising local variables to 0 and not being able to pass strings as parameters. Goto and Gosub are much more efficient - as said, they compile to pretty simple jumps, at the expense of the code modularity and organisation.

I haven't benchmarked it, but if you're looking for more condensed code, Blitz also supports the On version of Goto / Gosub from other Basics. You can jump to a number of labels based on a value, starting from 1. For your code:

Code:
If WHATEVENT= $40 AND EventWindow = mywindow  ; Do something if gadget is selected/hit
     On GadgetHit - 49 Gosub HITSEARCHBOX, HITSEARCHBUTT, HITDESTBOX, HITDESTBUTT, HITEXTRACTTYPE
  EndIf
This is, of course, dependent on your event codes being sequential, and is ripe for introducing bugs if you ever adjust your constants to e.g. fit more gadgets in. I don't think there's any advantage worth the potential for bugs there, but it's an option.
If I was doing this in C, I'd use an array of function pointers and avoid the
case 
statement entirely. I guess this is more or less what's going on here. I don't know if it's possible to do function pointers in blitz? maybe with some embedded asm or something hacky.
E-Penguin is offline  
Old 09 November 2023, 10:55   #30
Dunny
Registered User
 
Dunny's Avatar
 
Join Date: Aug 2006
Location: Scunthorpe/United Kingdom
Posts: 1,987
Quote:
Originally Posted by E-Penguin View Post
If I was doing this in C, I'd use an array of function pointers and avoid the
case 
statement entirely. I guess this is more or less what's going on here. I don't know if it's possible to do function pointers in blitz? maybe with some embedded asm or something hacky.
That's what I was just wondering. If Blitz can maintain an array of addresses, then just use that as a LUT to branch to based on the ID number of the event?
Dunny is offline  
Old 09 November 2023, 14:26   #31
Daedalus
Registered User
 
Daedalus's Avatar
 
Join Date: Jun 2009
Location: Dublin, then Glasgow
Posts: 6,343
Yeah, I don't think you can do that with the standard Blitz commands, but you can jump to an address with a JMP or JSR. The addresses of program labels can be found using a question mark:

myAddress.l = ?myLabel
Daedalus is offline  
Old 17 February 2024, 01:47   #32
idrougge
Registered User
 
Join Date: Sep 2007
Location: Stockholm
Posts: 4,334
You can use a self-modifying macro to create an enumeration automatically.

Then you can use a macro to make a label for your Gosub matching the ID generated by the macro.
idrougge is offline  
Old 20 February 2024, 10:20   #33
Daedalus
Registered User
 
Daedalus's Avatar
 
Join Date: Jun 2009
Location: Dublin, then Glasgow
Posts: 6,343
Ooh, that sounds very clever, I must try it out some time.
Daedalus is offline  
Old 20 February 2024, 23:13   #34
idrougge
Registered User
 
Join Date: Sep 2007
Location: Stockholm
Posts: 4,334
There is also the CNAME ~expression~ feature to help out with this.
idrougge is offline  
 


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools

Similar Threads
Thread Thread Starter Forum Replies Last Post
Probably a dumb question about the aca1232 source Hardware mods 4 05 March 2019 18:47
Dumb Question but need help with printers source support.Apps 2 04 June 2015 06:21
Probably a dumb question.. xlar54 support.Other 6 03 January 2010 21:20
Question from a dumb American. illy5603 support.Hardware 43 19 September 2009 00:27
Probably a really dumb question... BumpyCarrot New to Emulation or Amiga scene 3 28 February 2003 02:04

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +2. The time now is 21:42.

Top

Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2024, vBulletin Solutions Inc.
Page generated in 0.10037 seconds with 15 queries