Issue with converting tiny classifier routine into a macro

Just starting out? Need help? Post your questions and find answers here.
infratec
Always Here
Always Here
Posts: 7598
Joined: Sun Sep 07, 2008 12:45 pm
Location: Germany

Re: Issue with converting tiny classifier routine into a macro

Post by infratec »

Suboptimal:

Code: Select all

Structure AsciiArray
	a.a[0]
EndStructure


Define IsLetter.i
Define *IsLetter.AsciiArray = ?IsLetter
Define *IsLetterCharacter.Character

Macro IsLetterMacro(String)
  IsLetter = 0
  *IsLetterCharacter = @String
  If *IsLetterCharacter\c < 128
    IsLetter = *IsLetter\a[*IsLetterCharacter\c]
  EndIf
EndMacro


DataSection
	IsLetter:
	Data.a 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0
	Data.a 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0
	Data.a 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0
	Data.a 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0
	Data.a 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1
	Data.a 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 1
	Data.a 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1
	Data.a 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0
EndDataSection

IsLetterMacro("a")
Debug IsLetter
IsLetterMacro("_")
Debug IsLetter
IsLetterMacro("ß")
Debug IsLetter
IsLetterMacro("1")
Debug IsLetter
Olli
Addict
Addict
Posts: 1218
Joined: Wed May 27, 2020 12:26 pm

Re: Issue with converting tiny classifier routine into a macro

Post by Olli »

Olli wrote: Tue Jul 29, 2025 7:14 am This is "SIMDable" :

Code: Select all

Dim NonLetter(65535)
For i = 0 to 65535
 NonLetter(i) = (((i & ~32) - 52) / 13 - 1) >> 1
Next
Hello skiper, I am sorry for having done short. Maybe an other short version ?

Code: Select all

macro isNotLetter(self)
(((self&~32)-52)/13-1)>>1
endmacro
It is method to be fast. And normally, the optimizer should use it, as SIMD if you use it in a contiguous array.

@infratec
IsLetterMacro("ß")
That is a problem this letter : 's' und 'z', as 'o' und 'e' für << (french) des œufs >> (œ) ("eggs"). I used it long time ago to learn my deutsch ! chr$(223)
User avatar
idle
Always Here
Always Here
Posts: 5858
Joined: Fri Sep 21, 2007 5:52 am
Location: New Zealand

Re: Issue with converting tiny classifier routine into a macro

Post by idle »

Olli wrote: Tue Jul 29, 2025 7:14 am

Code: Select all

macro isNotLetter(self)
(((self&~32)-52)/13-1)>>1
endmacro
It is method to be fast. And normally, the optimizer should use it, as SIMD if you use it in a contiguous array.
That's really nice for azAZ
Post Reply