Re: [ft-devel] FT_New_Memory_Face: get error code 2 on arm

2018-03-14 Thread duhuanpeng
Hi, Please check my previously email carefully.

And you addw produce a grammar error.
add.w is not supported.

"aplusb.s" 41L, 1076C written   
   
du@router:~/asm$ armcc aplusb.s 
"aplusb.s", line 13: Error: A1617E: Specified width is not supported by the 
current instruction set
   13 0006  add.w r0, r0, #0x8000
"aplusb.s", line 14: Error: A1854E: Unknown opcode 'addw', maybe wrong target 
CPU?
   14 000a  addw r0, r0, #0x8000
"aplusb.s", line 35: Error: A1312E: Assertion failed
   35 0004 ASSERT {INTER} = {TRUE}
3 Errors, 0 Warnings


___
Freetype-devel mailing list
Freetype-devel@nongnu.org
https://lists.nongnu.org/mailman/listinfo/freetype-devel


Re: [ft-devel] FT_New_Memory_Face: get error code 2 on arm

2018-03-14 Thread duhuanpeng
-Original Message-
From: Alexei Podtelezhnikov [mailto:apodt...@gmail.com] 
Sent: Thursday, March 15, 2018 4:00 AM
To: duhuanpeng; freetype-devel
Subject: Re: [ft-devel] FT_New_Memory_Face: get error code 2 on arm

On Wed, Mar 14, 2018 at 9:22 AM, duhuanpeng <548708...@qq.com> wrote:
> My cortex-m0 board is using a armcc(rvct) with keil 5.22a I can send 
> me my whole project if you wish.

Please try "addw" instead of "add" in the assembler code.
addw   a,  a,  #0x8000 /* a  += 0x8000 */
Then we can think how to merge ARMCC and GNUC assembly versions.

0x8000 takes at least 8+(log32/log(n)) bits. n is 5 , 
So 0x8000 is a 13 bit number.
The thumb code is 16 bit machine code.
So, "add a, a, #0x8000" will be translated in to at least two machine code. 



"aplusb.s" 40L, 1054C written   
   
du@router:~/asm$ armcc aplusb.s 
"aplusb.s", line 13: Error: A1617E: Specified width is not supported by the 
current instruction set
   13 0006  add.w r0, r0, #0x8000
"aplusb.s", line 34: Error: A1312E: Assertion failed
   34 0004 ASSERT {INTER} = {TRUE}
2 Errors, 0 Warnings



Hi, here is my experiment:
C program: aplusb.c 

int plusa(int a)
{
a += 0x8000;
return a;
}

; generated by Component: ARM Compiler 5.06 update 3 (build 30
0) Tool: armcc [4d35f0]
; commandline armcc [-S --cpu=Cortex-M0 -O3 aplusb.c]
THUMB
REQUIRE8
PRESERVE8

AREA ||.text||, CODE, READONLY, ALIGN=1

plusa PROC
MOVS r1,#1
LSLS r1,r1,#15
ADDS r0,r0,r1
BX   lr
ENDP


AREA ||.arm_vfe_header||, DATA, READONLY, NOALLOC, ALIGN=2

; generated by Component: ARM Compiler 5.06 update 3 (build 30
0) Tool: armcc [4d35f0]
; commandline armcc [-S --cpu=Cortex-R4 -O3 aplusb.c]
ARM
REQUIRE8
PRESERVE8

AREA ||.text||, CODE, READONLY, ALIGN=2

plusa PROC
ADD  r0,r0,#0x8000
BX   lr
ENDP


AREA ||.arm_vfe_header||, DATA, READONLY, NOALLOC, ALI
GN=2

DCD  0x


.cpu cortex-m0
.eabi_attribute 20, 1
.eabi_attribute 21, 1
.eabi_attribute 23, 3
.eabi_attribute 24, 1
.eabi_attribute 25, 1
.eabi_attribute 26, 1
.eabi_attribute 30, 2
.eabi_attribute 34, 0
.eabi_attribute 18, 4
.file   "aplusb.c"
.text
.align  1
.p2align 2,,3
.global plusa
.syntax unified
.code   16
.thumb_func
.fpu softvfp
.type   plusa, %function
plusa:
@ args = 0, pretend = 0, frame = 0
@ frame_needed = 0, uses_anonymous_args = 0
@ link register save eliminated.
movsr3, #128
lslsr3, r3, #8
mov ip, r3
@ sp needed
add r0, r0, ip
bx  lr
.size   plusa, .-plusa
.ident  "GCC: (GNU Tools for Arm Embedded Processors 7-2017-q4-major) 
7.2.1 20170904 (release
) [ARM/embedded-7-branch revision 255204]"



___
Freetype-devel mailing list
Freetype-devel@nongnu.org
https://lists.nongnu.org/mailman/listinfo/freetype-devel


Re: [ft-devel] FT_New_Memory_Face: get error code 2 on arm

2018-03-14 Thread Alexei Podtelezhnikov
On Wed, Mar 14, 2018 at 9:22 AM, duhuanpeng <548708...@qq.com> wrote:
> My cortex-m0 board is using a armcc(rvct) with keil 5.22a
> I can send me my whole project if you wish.

Please try "addw" instead of "add" in the assembler code.
addw   a,  a,  #0x8000 /* a  += 0x8000 */
Then we can think how to merge ARMCC and GNUC assembly versions.

___
Freetype-devel mailing list
Freetype-devel@nongnu.org
https://lists.nongnu.org/mailman/listinfo/freetype-devel


Re: [ft-devel] FT_New_Memory_Face: get error code 2 on arm

2018-03-14 Thread duhuanpeng
Hi, 
> http://www.keil.com/support/man/docs/armasm/armasm_dom1361289902800.htm

>From this piece code: (ftcalc.c +244)
return (int32_t)( ( ab + 0x8000L - ( ab < 0 ) ) >> 16 );

this routine seems produce a result of a integer include the bit 16 to bit 
(16+32)
and round up?

Greater than one half   --> +1
Less than one half  --> discard

FT_MulFix  a b

  a x b become a 64bit interger.

 a x b:|B7|B6|B5|B4|B3|B2|B1|B0|
   |xx|xx|B5|B4|B3|B2|xx|xx|

If(|B1|B0| > 0x1/2) 
  |B5|B4|B3|B2| += 1
  
->return |B5|B4|B3|B2|

Am I understand this right?

Regards,
duhuanpeng





___
Freetype-devel mailing list
Freetype-devel@nongnu.org
https://lists.nongnu.org/mailman/listinfo/freetype-devel


Re: [ft-devel] FT_New_Memory_Face: get error code 2 on arm

2018-03-14 Thread Werner LEMBERG

>>> By the way, the assembly code is broken with thumb2: [...]
>>> Can you fix it?  I have zero knowledge w.r.t. assembler code.
>>
>> I will try, can you tell me what it's intention...
> 
> It should be a fast equivalent of the corresponding C code
> (cf. `FT_MulFix' in files `freetype.h' and `ftcalc.c').
> 
>> This is the code I found in freetype [...]
> 
> Yep.
> 
>> int64_t is supported, but generate long code like this: [...]
> 
> Maybe this code can be manually optimized.  Note, however, that for
> handling PCF files this is overkill since the PCF module doesn't
> need FT_MulFix at all.

Another solution is to add preprocessor macros around the assembler
code that prevent execution on your platform and/or processor.


Werner

___
Freetype-devel mailing list
Freetype-devel@nongnu.org
https://lists.nongnu.org/mailman/listinfo/freetype-devel


Re: [ft-devel] FT_New_Memory_Face: get error code 2 on arm

2018-03-13 Thread Werner LEMBERG
>> Maybe an endianness problem while setting up the external array
>> holding the PCF data?
>
> I believe no.

OK.

>> If you activate debugging with
>>
>>   #define FT_DEBUG_LEVEL_ERROR
>>   #define FT_DEBUG_LEVEL_TRACE
>>
>> in `ftoption.h', then setting the environment variable `FT2_DEBUG'
>> to `any:7' you will perhaps get more detailed information on the
>> problem FreeType has encountered.  [In case your environment
>> doesn't have environment variables you have to adjust `ftdebug.c'
>> accordingly.]
>
> FT_BASE_DEF( void )
> ft_debug_init( void )
> [...]
>
> Hmm no output.

This is certainly a problem on your side :-)

>> By the way, the assembly code is broken with thumb2: [...]
>> Can you fix it?  I have zero knowledge w.r.t. assembler code.
>
> I will try, can you tell me what it's intention...

It should be a fast equivalent of the corresponding C code
(cf. `FT_MulFix' in files `freetype.h' and `ftcalc.c').

> This is the code I found in freetype [...]

Yep.

> int64_t is supported, but generate long code like this: [...]

Maybe this code can be manually optimized.  Note, however, that for
handling PCF files this is overkill since the PCF module doesn't need
FT_MulFix at all.


Werner

___
Freetype-devel mailing list
Freetype-devel@nongnu.org
https://lists.nongnu.org/mailman/listinfo/freetype-devel


Re: [ft-devel] FT_New_Memory_Face: get error code 2 on arm

2018-03-13 Thread duhuanpeng
> But I get an error code (2) on my M0 board.

>   >FT_New_Memory_Face: 2

>The error codes are given in file `fterrdef.h'; error 2 means `unknown file 
>format'.  Maybe an endianness problem while setting up the external array 
>holding 
>the PCF data?
I believe no. this font file is tested in my cortex-r4 board.
When I put a .fon(winfnt.c) or .pcf.Z(pcf.c+ftlzw.c), I get the same result.
The cortex-M0 board is little endian too.
(Maybe it is useless to run freetype2 on a cortex-m0 board. :D)


If you activate debugging with 

  #define FT_DEBUG_LEVEL_ERROR
  #define FT_DEBUG_LEVEL_TRACE

>in `ftoption.h', then setting the environment variable `FT2_DEBUG' to `any:7' 
>you will perhaps get more detailed information on the problem FreeType has 
>encountered.  
>[In case your environment doesn't have environment variables you have to 
>adjust `ftdebug.c' accordingly.]
FT_BASE_DEF( void )
ft_debug_init( void )
{
  const char*  ft2_debug = ft_getenv( "FT2_DEBUG" );
+ const char any7[] = "any:7";
  
+ ft2_debug = any7;

And change these lines:
-vfprintf( stderr, fmt, ap );
+printf(fmt, ap);

And add -DFT_DEBUG_LEVEL_ERROR -DFT_DEBUG_LEVEL_TRACE

//#ifdef FT_DEBUG_LEVEL_ERROR
#if 1

  /* documentation is in ftdebug.h */

  FT_BASE_DEF( void )


Hmm no output.

Of course there could also be a bug in FreeType.  However, I can't debug this...

> By the way, the assembly code is broken with thumb2:
>   >  static __inline FT_Int32
>   >  FT_MulFix_arm( FT_Int32  a,
>   > FT_Int32  b )
>   >  {
>   >FT_Int32  t, t2;
>   >
>   >
>   >__asm
>   >{
>   >  smull t2, t,  b,  a   /* (lo=t2,hi=t) = a*b */
>   >  mov   a,  t,  asr #31 /* a   = (hi >> 31) */
>   >  add   a,  a,  #0x8000 /* a  += 0x8000 */
>   >  adds  t2, t2, a   /* t2 += a */
>   >  adc   t,  t,  #0  /* t  += carry */
>   >  mov   a,  t2, lsr #16 /* a   = t2 >> 16 */
>   >  orr   a,  a,  t,  lsl #16 /* a  |= t << 16 */
>   >}
>   >return a;
>   >  }

> Can you fix it?  I have zero knowledge w.r.t. assembler code.

I will try, can you tell me what it's intention...
I can write a small program to test this separate.

This is the code I found in freetype and make a little change:
  int32_t FT_MulFix_C( int32_t  a_, int32_t  b_ )
  {
int64_t ab = (int64_t)a_ * (int64_t)b_;

/* this requires arithmetic right shift of signed numbers */
return (int32_t)( ( ab + 0x8000L - ( ab < 0 ) ) >> 16 );
  }
  
Some staff:
http://www.keil.com/forum/59448/64bit-arithmetic-on-cortex-m0/

int64_t is supported, but generate long code like this:

FT_MulFix_C PROC
PUSH {r4,lr}
BL   __ARM_common_ll_mulss
CMP  r1,#0
BGE  |L0.14|
MOVS r2,#1
B|L0.16|
|L0.14|
MOVS r2,#0
|L0.16|
ASRS r3,r2,#31
SUBS r0,r0,r2
SBCS r1,r1,r3
MOVS r3,#1
LSLS r3,r3,#15
MOVS r2,#0
ADDS r0,r0,r3
ADCS r1,r1,r2
LSLS r1,r1,#16
LSRS r0,r0,#16
ORRS r0,r0,r1
POP  {r4,pc}
ENDP


AREA ||.arm_vfe_header||, DATA, READONLY, NOALLOC, ALIGN=2

DCD  0x

AREA ||i.__ARM_common_ll_mulss||, COMGROUP=__ARM_common_ll_mulss, CODE, 
READONLY, ALIGN=1

__ARM_common_ll_mulss PROC
PUSH {r3-r7,lr}
ASRS r4,r0,#16
UXTH r3,r1
MOV  r6,r4
UXTH r2,r0
MULS r6,r3,r6
ASRS r5,r1,#16
MOV  r0,r2
ASRS r7,r6,#16
MULS r0,r3,r0
LSLS r6,r6,#16
ADDS r0,r0,r6
MOVS r1,#0
ADCS r1,r1,r7
MOV  r6,r2
MULS r6,r5,r6
ASRS r7,r6,#16
LSLS r6,r6,#16
ADDS r0,r0,r6
ADCS r1,r1,r7
MOV  r6,r4
MULS r6,r5,r6
ADDS r1,r1,r6
POP  {r3-r7,pc}
ENDP

duhaunpeng




___
Freetype-devel mailing list
Freetype-devel@nongnu.org
https://lists.nongnu.org/mailman/listinfo/freetype-devel


Re: [ft-devel] FT_New_Memory_Face: get error code 2 on arm

2018-03-13 Thread Werner LEMBERG

> My test program 
>   https://paste.ubuntu.com/p/vvwW5bfmrF/
> runs normal on my pc and my cortex-r4 board.

Yes, this looks OK.

> But I get an error code (2) on my M0 board.

>   >FT_New_Memory_Face: 2

The error codes are given in file `fterrdef.h'; errorĀ 2 means `unknown
file format'.  Maybe an endianness problem while setting up the
external array holding the PCF data?

If you activate debugging with 

  #define FT_DEBUG_LEVEL_ERROR
  #define FT_DEBUG_LEVEL_TRACE

in `ftoption.h', then setting the environment variable `FT2_DEBUG' to
`any:7' you will perhaps get more detailed information on the problem
FreeType has encountered.  [In case your environment doesn't have
environment variables you have to adjust `ftdebug.c' accordingly.]

Of course there could also be a bug in FreeType.  However, I can't
debug this...

> By the way, the assembly code is broken with thumb2:
>   >  static __inline FT_Int32
>   >  FT_MulFix_arm( FT_Int32  a,
>   > FT_Int32  b )
>   >  {
>   >FT_Int32  t, t2;
>   >
>   >
>   >__asm
>   >{
>   >  smull t2, t,  b,  a   /* (lo=t2,hi=t) = a*b */
>   >  mov   a,  t,  asr #31 /* a   = (hi >> 31) */
>   >  add   a,  a,  #0x8000 /* a  += 0x8000 */
>   >  adds  t2, t2, a   /* t2 += a */
>   >  adc   t,  t,  #0  /* t  += carry */
>   >  mov   a,  t2, lsr #16 /* a   = t2 >> 16 */
>   >  orr   a,  a,  t,  lsl #16 /* a  |= t << 16 */
>   >}
>   >return a;
>   >  }

Can you fix it?  I have zero knowledge w.r.t. assembler code.


Werner
___
Freetype-devel mailing list
Freetype-devel@nongnu.org
https://lists.nongnu.org/mailman/listinfo/freetype-devel