BBC BASIC
« Expression simplification »

Welcome Guest. Please Login or Register.
Mar 31st, 2018, 11:03pm



ATTENTION MEMBERS: Conforums will be closing it doors and discontinuing its service on April 15, 2018.
We apologize Conforums does not have any export functions to migrate data.
Ad-Free has been deactivated. Outstanding Ad-Free credits will be reimbursed to respective payment methods.

Thank you Conforums members.
Cross-platform BBC BASIC (Windows, Linux x86, Mac OS-X, Android, iOS, Raspberry Pi)
BBC BASIC Resources
BBC BASIC Help Documentation
BBC BASIC for Windows Home Page
BBC BASIC Programmers' Reference
BBC BASIC Beginners' Tutorial
BBC BASIC for SDL 2.0 Home Page
BBC BASIC Discussion Group

« Previous Topic | Next Topic »
Pages: 1  Notify Send Topic Print
 thread  Author  Topic: Expression simplification  (Read 369 times)
Richard Russell
Administrator
ImageImageImageImageImage


member is offline

Avatar




Homepage PM


Posts: 803
xx Expression simplification
« Thread started on: Dec 15th, 2016, 10:51pm »

In something I'm working on I've ended up with this rather unwieldy expression in a time-critical section of code:

Code:
P%!4 AND &80000000 OR ((P%!4 >> 21) - &1C0 << 24 OR P%!4 << 3 AND &FFFFFF OR !P% >>> 29) - ((!P% << 3) < 0) 

I've simplified it as much as I can, but maybe a fresh eye will spot something I haven't. Can anybody see a way of making it run faster? I know I can delete the spaces but I've left them in here for clarity.

Richard.
User IP Logged

Richard Russell
Administrator
ImageImageImageImageImage


member is offline

Avatar




Homepage PM


Posts: 803
xx Re: Expression simplification
« Reply #1 on: Dec 16th, 2016, 8:44pm »

I've made a major improvement, which I don't know how I missed originally:

Code:
P%!4 AND NOT &7FFFFFFF OR (P%!4-&38000000<<3 OR !P%>>29 AND 7) + (!P%>>28 AND 1) 

I also realised that since this code is intended for a library it's important that it works in both *hex32 and *hex64 modes, which the above does but it complicates things significantly.

Richard.
User IP Logged

michael
Full Member
ImageImageImage


member is offline

Avatar




PM


Posts: 157
question Re: Expression simplification
« Reply #2 on: Dec 17th, 2016, 04:00am »

> this code is intended for a library

what kind of library? cheesy
User IP Logged

I like reinventing the wheel, but for now I will work on tools for D3D
Richard Russell
Administrator
ImageImageImageImageImage


member is offline

Avatar




Homepage PM


Posts: 803
xx Re: Expression simplification
« Reply #3 on: Dec 17th, 2016, 09:20am »

on Dec 17th, 2016, 04:00am, michael wrote:
what kind of library?

Is that relevant, or are you just inquisitive? grin

You might recognise what the code is doing, and if so you can probably guess the sort of application it has. But it's largely an academic exercise to see just how much optimisation is possible.

Richard.
User IP Logged

Pages: 1  Notify Send Topic Print
« Previous Topic | Next Topic »

| |

This forum powered for FREE by Conforums ©
Terms of Service | Privacy Policy | Conforums Support | Parental Controls