Search found 30 matches

by schooner
Dec 26, 2017 20:11
Forum: General
Topic: CShort Question
Replies: 16
Views: 1819

Re: CShort Question

Does not work on my configuration. Which one is that? I get those results in 32-bit GAS, 32-bit GCC and 64-bit GCC. Tested on FreeBasic compiler version 1.05.0. Hello paul doe. It does not matter for this topic. There is a work-around from lizard. There is no need to change the FBC configuration un...
by schooner
Dec 26, 2017 17:31
Forum: General
Topic: CShort Question
Replies: 16
Views: 1819

Re: CShort Question

paul doe wrote:Simply convert the expression to single, and then cast it to short:

Code: Select all

dim as integer x = 5

? cast( short, csng( 3.1 * x - 79 ) )
? cast( short, csng( 3.1 * 5 - 79 ) ) 

sleep()

Output:
-64
-64
Does not work on my configuration.
by schooner
Dec 26, 2017 14:37
Forum: General
Topic: CShort Question
Replies: 16
Views: 1819

Re: CShort Question

In case you need a workaround you maybe could use something like this, dear Schooner. It first multiplies with 10 and then divides with 10: dim as integer x = 5 print cshort(3.1 * x - 79) print cshort(3.1 * 5 - 79) sleep print print cshort((31 * x)/10 - 79) print cshort((31 * 5)/10 - 79) sleep -63 ...
by schooner
Dec 26, 2017 14:35
Forum: General
Topic: CShort Question
Replies: 16
Views: 1819

Re: CShort Question

Different things are happening at run time and compile time: '' run-time - 80 bits of precision on FPU stack dim as integer x = 5 print cshort(3.1 * x - 79) '' -63 '' compile-time constant folding - 64 bits of precision using DOUBLE type print cshort(3.1 * 5 - 79) '' -64 '' run-time, but emulate wh...
by schooner
Dec 26, 2017 1:55
Forum: General
Topic: CShort Question
Replies: 16
Views: 1819

CShort Question

Why do these produce different numbers for the 32-bit gas? Shouldn't the rounding be the same for all variations?

Code: Select all

dim as integer x = 5
print cshort(3.1 * x - 79)
print cshort(3.1 * 5 - 79) 

-63
-64
by schooner
Nov 11, 2016 20:58
Forum: General
Topic: BitScanForward
Replies: 35
Views: 8381

Re: BitScanForward

schooner, here comes my best guess, being the following: - easier switching (as between 0 and +1) - -1 = &hFF (a Byte), 0 = &h00 - so, a switch is simple by just using a NOT (binary bit-wise inversion) Example: Dim As Boolean flag ' init. default is 0 = FALSE If (some condition) Then flag =...
by schooner
Nov 11, 2016 19:50
Forum: General
Topic: BitScanForward
Replies: 35
Views: 8381

Re: BitScanForward

What is the reasoning for the -1? -1 = TRUE -- 0 = FALSE (definition of FB-Boolean var.) as from version >= 1.04.0 MrSwiss, Yes, but you have not really answered the question, only restated the definition. I suspect the negative logic might have something to do with a desired FreeBasic testing synt...
by schooner
Nov 11, 2016 18:11
Forum: General
Topic: BitScanForward
Replies: 35
Views: 8381

Re: BitScanForward

I ran the above code on different machines, but it returns -1 no matter what hardware it is tested with. What value should it return? It should return -1 if POPCNT is supported, otherwise 0. Per the Intel instruction set reference available here , for CPUID function 1 (EAX=1), support for the POPCN...
by schooner
Nov 11, 2016 15:02
Forum: General
Topic: BitScanForward
Replies: 35
Views: 8381

Re: BitScanForward

''------------------------------------------------------------------------------ '' POPCNT instruction supported if for CPUID Function 1, bit 23 of ECX is set. '' Note that CPUID will trash the callee-save register RBX. ''-----------------------------------------------------------------------------...
by schooner
Sep 13, 2015 15:55
Forum: General
Topic: Force Register Use
Replies: 16
Views: 3257

Re: Force Register Use

Sounds like you're using fbc 0.24 or older. -RR was added in fbc 0.90, the Data/Restore issue was fixed in 0.90 too. (if you want to use -gen gcc with fbc 0.24 now, then I think you need to use gcc 4.6.* or older, which didn't have that structure packing bug yet which made the Data/Restore fixes on...
by schooner
Sep 13, 2015 15:30
Forum: General
Topic: Force Register Use
Replies: 16
Views: 3257

Re: Force Register Use

-RR produces a .c file. -R should preserve the .c file, -RR should preserve the .asm file. That seems to work for me with fbc 1.03 at least. My mistake. -R produces a .c file. -RR produces an error. C:\Program Files (x86)\FreeBASIC>fbc test.bas -RR -gen gcc error 74: Invalid command-line option, &q...
by schooner
Sep 13, 2015 14:27
Forum: General
Topic: Force Register Use
Replies: 16
Views: 3257

Re: Force Register Use

See at http://www.freebasic.net/get : gcc-4.9.2-for-FB-win32-gengcc.zip : 32bit gcc for the FB-win32 package, in case you want to use -gen gcc. I tested gcc-4.9.2-for-FB-win32-gengcc. The next problem is how to dump the .asm file to observe register use? fbc test.bas -RR -gen gcc The gcc -S switch ...
by schooner
Sep 11, 2015 21:31
Forum: General
Topic: Force Register Use
Replies: 16
Views: 3257

Re: Force Register Use

Did you add -gen gcc too? (it's needed explicitly on 32bit, because the default is -gen gas) C:\Program Files (x86)\FreeBASIC>fbc test.bas -gen gcc gcc.exe: error: CreateProcess: No such file or directory The 32-bit package installed for FBC does not include gcc in the bin folder. This would at lea...
by schooner
Sep 11, 2015 17:44
Forum: General
Topic: Force Register Use
Replies: 16
Views: 3257

Re: Force Register Use

The trick for 64-bit is to use the optimization flag -O 2. The output code then uses registers. This does not seem to work in 32-bit.
by schooner
Sep 11, 2015 17:34
Forum: General
Topic: Force Register Use
Replies: 16
Views: 3257

Re: Force Register Use

Register use should offer better performance for everyone. You are probably using the x32 version of FBC. I'm not convinced this is going to happen in x32 compiler versions. x64 is different in that it "hands over" the first 4 Arguments (of Sub/Function) directly to registers. E.g.: RCX, ...