Show Posts

This section allows you to view all posts made by this member. Note that you can only see posts made in areas you currently have access to.


Messages - eric

Pages: [1]
1
QB64 Discussion / Re: _SHR bug with sign bit of _UNSIGNED _INTEGER64
« on: December 05, 2019, 03:34:28 am »
Finally i find a workaround based on http://qb64.org/wiki/C_Libraries#Bit_Shifting :

Modified C include file in qb64 dir :
Code: C: [Select]
  1.  //ushift.h
  2.  
  3. uint64 uShiftR(uint64 Value, unsigned ShiftValue)
  4. {
  5. return(Value >> ShiftValue);
  6.  
  7. }
  8. uint64 uShiftL(uint64 Value, unsigned ShiftValue)
  9. {
  10. return(Value << ShiftValue);
  11. }
Basic declare and a piece of code that works :
Code: QB64: [Select]
  1. 'ushift.bas
  2. DECLARE LIBRARY "ushift" 'use first name of .h file
  3.     FUNCTION uShiftR~&& (BYVAL Value AS _UNSIGNED _INTEGER64, BYVAL ShiftValue AS _UNSIGNED LONG)
  4.     FUNCTION uShiftL~&& (BYVAL Value AS _UNSIGNED _INTEGER64, BYVAL ShiftValue AS _UNSIGNED LONG)
  5.  
  6. n = &H1000000000000000
  7.  
  8. PRINT , HEX$(n)
  9. n = uShiftL(n, 3)
  10. PRINT , HEX$(n)
  11. n = uShiftR(n, 3)
  12. PRINT , HEX$(n)
  13.  

I had just to modify the types of variables and return value.

2
QB64 Discussion / Re: _SHR bug with sign bit of _UNSIGNED _INTEGER64
« on: December 04, 2019, 11:22:11 am »
Thanks for yours replies.

I got trouble because of the name _SHR that is like the assembly mnemonic :
Quote
shr
that means unsigned shift right without matter of a sign bit.

The qb64 _SHL function works as instruction :
Quote
sar

that  shifts right too but preserving the sign bit

Left shifts, sal and shl, exist but are the same.

Short example in assembly (debug screen copy in attachment):

mov ax, 8000h
mov dx, ax
mov cl, 3
shr ax, cl
sar dx, cl        ;  _SHR(&h8000, 3)

input ax  : 1000000000000000     &h8000
output ax: 0001000000000000     &h1000
output dx: 1111000000000000     &hF000       _SHR(&h8000, 3)



3
QB64 Discussion / _SHR bug with sign bit of _UNSIGNED _INTEGER64
« on: December 03, 2019, 06:20:30 pm »
Hello,

I use qb64 to test some algorithms on integers when i got a strange garbage.

So, i try :

Code: QB64: [Select]
  1.  
  2. n = &H0100000000000000
  3.  
  4. PRINT , HEX$(n)
  5. n = _SHL(n, 7)     'shift 1 to sign bit left most
  6. PRINT , HEX$(n)
  7. n = _SHR(n, 7)     'revert to first position
  8. PRINT , HEX$(n)
  9.  
  10. m~&& = &H0100000000000000
  11. PRINT , HEX$(m~&&)
  12. m~&& = _SHL(m~&&, 7)
  13. PRINT , HEX$(m~&&)
  14. m~&& = _SHR(m~&&, 7)
  15. PRINT , HEX$(m~&&)
  16.  

both display result as :

     100000000000000
     8000000000000000
     FF00000000000000


I think _SHR is not shifting but expanding the "sign" bit to the right.

The last print is the negative of the first.

Is it a solution ?

Thanks.


Pages: [1]