Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Small optimizations #8

Open
wants to merge 7 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion bbruntime/basic.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -476,7 +476,7 @@ BBStr *_bbReadStr(){
}

int _bbAbs( int n ){
return n>=0 ? n : -n;
return n & 0x7FFFFFFF;
}

int _bbSgn( int n ){
Expand Down
14 changes: 13 additions & 1 deletion bbruntime/bbmath.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,18 @@ float bbClamp( float v, float lo, float hi){
if (lo > hi){
std::swap(lo,hi);
}
return (float)max(lo, min(v, hi));
if (v < lo){
return lo;
} else if (v > hi){
return hi;
} else{
return v;
}
}

int bbIsNaN( float n ){
unsigned int i = *((unsigned int*)(void*)&n);
return ((i&0x7F800000)==0x7F800000) && ((i&(~0xFF800000)) != 0);
}

//return rand float from 0...1
Expand Down Expand Up @@ -88,6 +99,7 @@ void math_link( void (*rtSym)( const char *sym,void *pc ) ){
rtSym( "#Min#n#m",bbMin );
rtSym( "#Max#n#m",bbMax );
rtSym( "#Clamp#v#lo#hi",bbClamp );
rtSym( "%IsNaN#n",bbIsNaN );
rtSym( "#Rnd#from#to=0",bbRnd );
rtSym( "%Rand%from%to=1",bbRand );
rtSym( "SeedRnd%seed",bbSeedRnd );
Expand Down
14 changes: 0 additions & 14 deletions bbruntime_dll/bbruntime_dll.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,6 @@
#include "bbruntime_dll.h"
#include "../debugger/debugger.h"

#ifdef PRODEMO
#include "../shareprot/shareprot.h"
#endif

using namespace std;

#include <map>
Expand Down Expand Up @@ -39,12 +35,6 @@ static void rtSym( const char *sym,void *pc ){
syms[sym]=pc;
}

#ifdef PRODEMO
static void killer(){
ExitProcess( -1 );
}
#endif

static void _cdecl seTranslator( unsigned int u,EXCEPTION_POINTERS* pExp ){
switch( u ){
case EXCEPTION_INT_DIVIDE_BY_ZERO:
Expand Down Expand Up @@ -118,10 +108,6 @@ void Runtime::execute( void (*pc)(),const char *args,Debugger *dbg ){
while( params.size() && params[params.size()-1]==' ' ) params=params.substr( 0,params.size()-1 );

if( gx_runtime=gxRuntime::openRuntime( hinst,params,dbg ) ){

#ifdef PRODEMO
shareProtCheck( killer );
#endif
bbruntime_run( gx_runtime,pc,debug );

gxRuntime *t=gx_runtime;
Expand Down
9 changes: 0 additions & 9 deletions blitz/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -130,11 +130,6 @@ static void versInfo(){
cout<<"Linker version:"<<verstr(lnk_ver)<<endl;
}

static void demoError(){
cout<<"Compiler can not be used standalone in demo version."<<endl;
exit(0);
}

int _cdecl main( int argc,char *argv[] ){

string in_file,out_file,args;
Expand Down Expand Up @@ -194,10 +189,6 @@ int _cdecl main( int argc,char *argv[] ){

if( !in_file.size() ) return 0;

#ifdef DEMO
if( !getenv( "blitzide" ) ) demoError();
#endif

if( in_file[0]=='\"' ){
if( in_file.size()<3 || in_file[in_file.size()-1]!='\"' ) usageErr();
in_file=in_file.substr( 1,in_file.size()-2 );
Expand Down
37 changes: 4 additions & 33 deletions blitzide/about.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,10 @@
char _credits[]=
"\r\n"
"Programming and design: Mark Sibly\r\n\r\n"
"Fixing this shit: Vane Brain And Salvage\r\n\r\n"
"Documentation: Mark Sibly, Simon Harrison, Paul Gerfen, Shane Monroe and the Blitz Doc Team\r\n\r\n"
"Testing and support: James Boyd, Simon Armstrong and the Blitz Dev Team\r\n\r\n"
"Image loader courtesy of FreeImage by Floris van den berg\r\n\r\n"
"Please visit www.blitzbasic.com for all your Blitz related needs!";
"Image loader courtesy of FreeImage by Floris van den berg\r\n\r\n";

/*
char _credits[]=
Expand Down Expand Up @@ -65,7 +65,7 @@ class Dialog : public CDialog{
}
};

void aboutBlitz( bool delay ){
void aboutBlitz(){

AfxGetMainWnd()->EnableWindow(0);

Expand Down Expand Up @@ -94,43 +94,14 @@ void aboutBlitz( bool delay ){
t+="Blitz2D";
#endif

#ifdef EDU
t+=" - Educational Version";
#else
#ifdef DEMO
t+=" - Demo Version\n\n";
/*
int n=shareProtCheck();
if( n>1 ) t+=itoa(n)+" runs left";
else if( n ) t+=itoa(n)+" run left";
else t+="expired";
t+=")\n\n";
*/
#else
t+=" - Release Version\n\n";
#endif
#endif
t+=" - Release Version\n\n";

about.GetDlgItem( IDC_PRODUCT )->SetWindowText( t.c_str() );

// t="IDE V"+ide_v+" Linker V"+lnk_v+" Runtime V"+run_v;
t="Runtime V"+itoa((VERSION&0xffff)/1000)+"."+itoa((VERSION&0xffff)%1000);
about.GetDlgItem( IDC_VERSION )->SetWindowText( t.c_str() );

#ifdef DEMO

if( delay ){
about.GetDlgItem( IDOK )->ShowWindow( SW_HIDE );
about.GetDlgItem( IDC_PROGRESS1 )->ShowWindow( SW_SHOW );
for( int k=0;k<100;++k ){
((CProgressCtrl*)about.GetDlgItem( IDC_PROGRESS1 ))->SetPos( k+1 );
about.wait( 50 );
}
about.GetDlgItem( IDOK )->ShowWindow( SW_SHOW );
}

#endif

about.GetDlgItem( IDC_PROGRESS1 )->ShowWindow( SW_HIDE );
about.wait();
about.EndDialog(0);
Expand Down
2 changes: 1 addition & 1 deletion blitzide/about.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,6 @@
#ifndef ABOUT_H
#define ABOUT_H

void aboutBlitz( bool delay );
void aboutBlitz();

#endif
4 changes: 0 additions & 4 deletions blitzide/blitzide.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,6 @@ BOOL BlitzIDE::InitInstance(){
mainFrame=new MainFrame();
m_pMainWnd = mainFrame;

#ifdef DEMO
aboutBlitz( true );
#endif

mainFrame->LoadFrame( IDR_MAINFRAME );
mainFrame->MoveWindow( CRect( prefs.win_rect ) );
mainFrame->ShowWindow( m_nCmdShow );
Expand Down
6 changes: 3 additions & 3 deletions blitzide/blitzide.rc
Original file line number Diff line number Diff line change
Expand Up @@ -295,11 +295,11 @@ STYLE DS_MODALFRAME | WS_POPUP | WS_VISIBLE | WS_CAPTION
CAPTION "About Blitz"
FONT 10, "MS Sans Serif"
BEGIN
DEFPUSHBUTTON "Okee Dokee!",IDOK,79,150,50,14
DEFPUSHBUTTON "Okay then..",IDOK,79,150,50,14
CONTROL 132,IDC_STATIC,"Static",SS_BITMAP | SS_REALSIZEIMAGE,11,
5,64,32
CTEXT "BlitzPlus - Demo Version",IDC_PRODUCT,78,7,139,8
CTEXT "IDE V1.1 Runtime V1.1 Linker V1.1",IDC_VERSION,78,27,
CTEXT "",IDC_PRODUCT,78,7,139,8
CTEXT "",IDC_VERSION,78,27,
139,8
CTEXT "Copyright Blitz Research Ltd",IDC_STATIC,78,17,139,8
CONTROL "Progress1",IDC_PROGRESS1,"msctls_progress32",PBS_SMOOTH |
Expand Down
4 changes: 0 additions & 4 deletions blitzide/editor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,7 @@

static bool locked;

#ifdef DEMO
static const int TEXTLIMIT=16384;
#else
static const int TEXTLIMIT=1024*1024-1;
#endif

static const UINT wm_Find=RegisterWindowMessage( FINDMSGSTRING );

Expand Down
6 changes: 1 addition & 5 deletions blitzide/mainframe.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -734,10 +734,6 @@ void MainFrame::programCompile(){
}

void MainFrame::programPublish(){
#ifdef DEMO
MessageBox( "Create Executable unavailable in demo version","Sorry!",MB_TOPMOST|MB_SETFOREGROUND|MB_ICONINFORMATION );
return;
#endif
Editor *e=getEditor();if( !e ) return;
if( prefs.prg_debug ){
string t=
Expand Down Expand Up @@ -796,7 +792,7 @@ void MainFrame::helpForward(){
}

void MainFrame::helpAbout(){
aboutBlitz( false );
aboutBlitz();
}

void MainFrame::ctrlTab(){
Expand Down
4 changes: 2 additions & 2 deletions compiler/codegen.h
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,11 @@ enum{
IR_JSR,IR_RET,IR_AND,IR_LOR,IR_OR,IR_XOR,IR_SHL,IR_SHR,IR_SAR,

IR_CALL,IR_RETURN,IR_CAST,
IR_NEG,IR_ADD,IR_SUB,IR_MUL,IR_DIV,
IR_NEG,IR_ADD,IR_SUB,IR_MUL,IR_DIV,IR_POWTWO,
IR_SETEQ,IR_SETNE,IR_SETLT,IR_SETGT,IR_SETLE,IR_SETGE,

IR_FCALL,IR_FRETURN,IR_FCAST,
IR_FNEG,IR_FADD,IR_FSUB,IR_FMUL,IR_FDIV,
IR_FNEG,IR_FADD,IR_FSUB,IR_FMUL,IR_FDIV,IR_FPOWTWO,
IR_FSETEQ,IR_FSETNE,IR_FSETLT,IR_FSETGT,IR_FSETLE,IR_FSETGE,
};

Expand Down
6 changes: 4 additions & 2 deletions compiler/codegen_x86/codegen_x86.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,7 @@ Tile *Codegen_x86::munchUnary( TNode *t ){
string s;
switch( t->op ){
case IR_NEG:s="\tneg\t%l\n";break;
case IR_POWTWO:s="\timul\t%l,%l\n";break;
default:return 0;
}
return d_new Tile( s,munchReg( t->l ) );
Expand Down Expand Up @@ -228,6 +229,7 @@ Tile *Codegen_x86::munchFPUnary( TNode *t ){
string s;
switch( t->op ){
case IR_FNEG:s="\tfchs\n";break;
case IR_FPOWTWO:s="\tfmulp\tst(0)\n";break;
default:return 0;
}
return d_new Tile( s,munchFP( t->l ) );
Expand Down Expand Up @@ -420,7 +422,7 @@ Tile *Codegen_x86::munchReg( TNode *t ){
case IR_CONST:
q=d_new Tile( "\tmov\t%l,"+itoa(t->iconst)+"\n" );
break;
case IR_NEG:
case IR_NEG:case IR_POWTWO:
q=munchUnary( t );
break;
case IR_AND:case IR_LOR:case IR_OR:case IR_XOR:
Expand Down Expand Up @@ -463,7 +465,7 @@ Tile *Codegen_x86::munchFP( TNode *t ){
s="\tpush\t%l\n\tfild\t[esp]\n\tpop\t%l\n";
q=d_new Tile( s,munchReg( t->l ) );
break;
case IR_FNEG:
case IR_FNEG:case IR_FPOWTWO:
q=munchFPUnary( t );
break;
case IR_FADD:case IR_FSUB:case IR_FMUL:case IR_FDIV:
Expand Down
4 changes: 4 additions & 0 deletions compiler/exprnode.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -321,13 +321,15 @@ ExprNode *UniExprNode::semant( Environ *e ){
case '-':e=d_new IntConstNode( -c->intValue() );break;
case ABS:e=d_new IntConstNode( c->intValue()>=0 ? c->intValue() : -c->intValue() );break;
case SGN:e=d_new IntConstNode( c->intValue()>0 ? 1 : (c->intValue()<0 ? -1 : 0) );break;
case POWTWO:e=d_new IntConstNode( c->intValue()*c->intValue() );break;
}
}else{
switch( op ){
case '+':e=d_new FloatConstNode( +c->floatValue() );break;
case '-':e=d_new FloatConstNode( -c->floatValue() );break;
case ABS:e=d_new FloatConstNode( c->floatValue()>=0 ? c->floatValue() : -c->floatValue() );break;
case SGN:e=d_new FloatConstNode( c->floatValue()>0 ? 1 : (c->floatValue()<0 ? -1 : 0) );break;
case POWTWO:e=d_new FloatConstNode( c->floatValue()*c->floatValue() );break;
}
}
delete this;
Expand All @@ -345,13 +347,15 @@ TNode *UniExprNode::translate( Codegen *g ){
case '-':n=IR_NEG;break;
case ABS:return call( "__bbAbs",l );
case SGN:return call( "__bbSgn",l );
case POWTWO:return d_new TNode(IR_POWTWO, l);
}
}else{
switch( op ){
case '+':return l;
case '-':n=IR_FNEG;break;
case ABS:return fcall( "__bbFAbs",l );
case SGN:return fcall( "__bbFSgn",l );
case POWTWO:return d_new TNode(IR_FPOWTWO, l);
}
}
return d_new TNode( n,l,0 );
Expand Down
22 changes: 3 additions & 19 deletions compiler/parser.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,9 @@
#include "std.h"
#include <cstdlib>
#include "parser.h"
#include <math.h>

#ifdef DEMO
static const int TEXTLIMIT=16384;
#else
static const int TEXTLIMIT=1024*1024-1;
#endif

enum{
STMTS_PROG,STMTS_BLOCK,STMTS_LINE
Expand Down Expand Up @@ -84,11 +81,6 @@ void Parser::parseStmtSeq( StmtSeqNode *stmts,int scope, bool debug){

int pos=toker->pos();

#ifdef DEMO
if( Toker::chars_toked>TEXTLIMIT ){
ex( "Demo version source limit exceeded" );
}
#endif
switch( toker->curr() ){
case INCLUDE:
{
Expand Down Expand Up @@ -668,7 +660,7 @@ ExprNode *Parser::parseUniExpr( bool opt ){
result=parseUniExpr( false );
result=d_new AfterNode( result );
break;
case '+':case '-':case '~':case ABS:case SGN:
case '+':case '-':case '~':case ABS:case SGN:case POWTWO:
toker->next();
result=parseUniExpr( false );
if( c=='~' ){
Expand All @@ -683,11 +675,6 @@ ExprNode *Parser::parseUniExpr( bool opt ){
return result;
}

// Don't ask me what this does. Thanks Juan!
float stuff(unsigned int i){
return *((float*)(void*)&i);
}

ExprNode *Parser::parsePrimary( bool opt ){

a_ptr<ExprNode> expr;
Expand Down Expand Up @@ -748,10 +735,7 @@ ExprNode *Parser::parsePrimary( bool opt ){
result=d_new FloatConstNode( 3.1415926535897932384626433832795f );
toker->next();break;
case INFINITY:
result=d_new FloatConstNode( stuff(0x7F800000) );
toker->next();break;
case NANCONST:
result=d_new FloatConstNode( stuff(0x7FFFFFFF) );
result=d_new FloatConstNode(INFINITY);
toker->next();break;
case BBTRUE:
result=d_new IntConstNode( 1 );
Expand Down
3 changes: 2 additions & 1 deletion compiler/toker.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,8 @@ static void makeKeywords(){

alphaTokes["Null"]=NULLCONST;
alphaTokes["Infinity"]=INFINITY;
alphaTokes["NaN"]=NANCONST;

alphaTokes["PowTwo"]=POWTWO;

map<string,int>::const_iterator it;
for( it=alphaTokes.begin();it!=alphaTokes.end();++it ){
Expand Down
2 changes: 1 addition & 1 deletion compiler/toker.h
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ enum{
AND,OR,LOR,XOR,NOT,SHL,SHR,SAR,

LE,GE,NE,
IDENT,INTCONST,BINCONST,HEXCONST,FLOATCONST,STRINGCONST,NULLCONST,INFINITY,NANCONST
IDENT,INTCONST,BINCONST,HEXCONST,FLOATCONST,STRINGCONST,NULLCONST,INFINITY,POWTWO
};

class Toker{
Expand Down
Loading