Discussion:
Atlas: Help with s390 ASM
(too old to reply)
Sylvestre Ledru
2010-01-28 00:10:02 UTC
Permalink
Hello,

I am trying to port the new version of Atlas on all Debian architectures
[1].
I am starting to try to fix s390 which is one of the non-supported archs
of Atlas and I need your help to translate some x86 asm to s390.

Atlas is an auto-optimized library. At the beginning of the script,
atlas launch a script to check what is the CPU architecture, the
optimisation available, etc.

One of the first check is the CPU. It is done in ASM.

For example, the code for x86 is:
--------
#include "atlas_asm.h"
#
# x86-32 assembler for:
# int asm_probe(int i)
# RETURNS: i*3
#
.text
.globl ATL_asmdecor(asm_probe)
ATL_asmdecor(asm_probe):
movl 4(%esp), %eax
movl %eax, %ecx
shl $1, %eax
addl %ecx, %eax
ret
---------

while the PPC is:
---------
#define ATL_GAS_PPC
#include "atlas_asm.h"
/*
* Linux PPC assembler for:
* int asm_probe(int i)
* RETURNS: i*3
*/
.globl ATL_asmdecor(asm_probe)
ATL_asmdecor(asm_probe):
add r4, r3, r3
add r3, r3, r4
blr
---------

I would like to know if someone could translate that for me to s390 ?

If someone needs it, the procedure to reproduce the failure with atlas
is:
$ apt-get source -t experimental atlas
$ cd atlas-*
$ gcc -I CONFIG/include/ -o xprobe_gas_s390
CONFIG/src/backend/probe_this_asm.c
CONFIG/src/backend/probe_gas_CHANGE_HERE.S

Many thanks!

Please C/C me.

Thanks
Sylvestre
[1]
https://buildd.debian.org/status/package.php?suite=experimental&p=atlas
--
To UNSUBSCRIBE, email to debian-s390-***@lists.debian.org
with a subject of "unsubscribe". Trouble? Contact ***@lists.debian.org
Stephen Powell
2010-01-28 01:40:02 UTC
Permalink
Post by Sylvestre Ledru
Hello,
I am trying to port the new version of Atlas on all Debian architectures
[1].
I am starting to try to fix s390 which is one of the non-supported archs
of Atlas and I need your help to translate some x86 asm to s390.
Atlas is an auto-optimized library. At the beginning of the script,
atlas launch a script to check what is the CPU architecture, the
optimisation available, etc.
One of the first check is the CPU. It is done in ASM.
--------
#include "atlas_asm.h"
#
# int asm_probe(int i)
# RETURNS: i*3
#
.text
.globl ATL_asmdecor(asm_probe)
movl 4(%esp), %eax
movl %eax, %ecx
shl $1, %eax
addl %ecx, %eax
ret
---------
---------
#define ATL_GAS_PPC
#include "atlas_asm.h"
/*
* int asm_probe(int i)
* RETURNS: i*3
*/
.globl ATL_asmdecor(asm_probe)
add r4, r3, r3
add r3, r3, r4
blr
---------
I would like to know if someone could translate that for me to s390 ?
If someone needs it, the procedure to reproduce the failure with atlas
$ apt-get source -t experimental atlas
$ cd atlas-*
$ gcc -I CONFIG/include/ -o xprobe_gas_s390
CONFIG/src/backend/probe_this_asm.c
CONFIG/src/backend/probe_gas_CHANGE_HERE.S
Many thanks!
Please C/C me.
Thanks
Sylvestre
[1] https://buildd.debian.org/status/package.php?suite=experimental&p=atlas
Hello, Sylvestre.

I know s390 assembler language well. Unfortunately, I don't x86
assembler language at all -- or PPC assembler language. And I don't know C either.
And that is the problem.

Finding someone who knows both the Linux world *AND* the s390 world
is very difficult. There aren't that many people who know both worlds well.
The definitive documentation for s390 machine and assembly instructions is
an IBM manual called "z/Architecture Principles of Operation" (SA22-7832).
At the time of this writing, suffix -06 is the current revision.
(Of course there are secret, proprietary instructions which aren't documented
there, but that's another story).
I was going to give you a link to a PDF copy of the manual,
http://publibz.boulder.ibm.com/pdf/dz9zr006.pdf
But it's not working for me right now for some reason. I'm not sure why.

One of the issues you're going to run into is privileged vs. non-privileged
instructions. For the most part, privileged instructions can only be
executed by a kernel module, not a user-space program. Maybe if you're root
you can execute a privileged instruction, I don't know. Anyway, there is
an assembler instruction called STORE CPU ID (mnemonic STIDP). But it is
privileged. The kernel issues one of these during initialization and you
may be able to extract that information from a kernel control block
somehow, but issuing it from a user-space program run by an ordinary user
almost certainly won't work.

Maybe you can get the information that you need by reading the right
pseudo-files in the /proc or /sys pseudo-filesystems. Then you won't
need to resort to assembler. Just a thought. If you can give me a
specific list of the information it wants, maybe I can tell you where to
find that information in /proc or /sys files.
--
To UNSUBSCRIBE, email to debian-s390-***@lists.debian.org
with a subject of "unsubscribe". Trouble? Contact ***@lists.debian.org
Bastian Blank
2010-01-28 08:00:01 UTC
Permalink
Post by Sylvestre Ledru
Atlas is an auto-optimized library. At the beginning of the script,
atlas launch a script to check what is the CPU architecture, the
optimisation available, etc.
Which different optimizations are available for s390?

But you remind me for something: I wanted to raise the minimum CPU
requirement to z900.
Post by Sylvestre Ledru
One of the first check is the CPU. It is done in ASM.
Why does it need to be done in assembler?
Post by Sylvestre Ledru
--------
movl 4(%esp), %eax
movl %eax, %ecx
shl $1, %eax
addl %ecx, %eax
This code does nothing really usefull except for the stack access, why
is it written in assembler at all? But this does not in any way help
with detecting the CPU type.
Post by Sylvestre Ledru
I would like to know if someone could translate that for me to s390 ?
Why does this tool not have a common implementation in a common language
like C to start with?

Bastian
--
Beam me up, Scotty!
--
To UNSUBSCRIBE, email to debian-s390-***@lists.debian.org
with a subject of "unsubscribe". Trouble? Contact ***@lists.debian.org
Sylvestre Ledru
2010-01-28 09:20:01 UTC
Permalink
Hello,
Post by Bastian Blank
Post by Sylvestre Ledru
Atlas is an auto-optimized library. At the beginning of the script,
atlas launch a script to check what is the CPU architecture, the
optimisation available, etc.
Which different optimizations are available for s390?
I don't think there is any. It is mainly about x86 and amd64.
Post by Bastian Blank
Post by Sylvestre Ledru
One of the first check is the CPU. It is done in ASM.
Why does it need to be done in assembler?
I don't know. It is the way it is currently done with Atlas.
Post by Bastian Blank
Post by Sylvestre Ledru
--------
movl 4(%esp), %eax
movl %eax, %ecx
shl $1, %eax
addl %ecx, %eax
This code does nothing really usefull except for the stack access, why
is it written in assembler at all? But this does not in any way help
with detecting the CPU type.
Post by Sylvestre Ledru
I would like to know if someone could translate that for me to s390 ?
Why does this tool not have a common implementation in a common language
like C to start with?
Good question... I can try to do that. I was just trying to match the
current upstream behavior first.

Sylvestre
--
To UNSUBSCRIBE, email to debian-s390-***@lists.debian.org
with a subject of "unsubscribe". Trouble? Contact ***@lists.debian.org
Sylvestre Ledru
2010-01-28 16:30:02 UTC
Permalink
Post by Sylvestre Ledru
Good question... I can try to do that. I was just trying to match the
current upstream behavior first.
[...]
That being said, and with the s390 ABI giving parm 1 in R2, returning
R2, R1 being expandable and R14 being the return address there are
several possibilities...
lr %r1,%r2
ar %r2,%r1
ar %r2,%r1
br %r14
would probably also work (3x=x+x+x)
Many thanks for that. It is working.
I might need your help on other aspects but for now, it is up to me!

Thanks again,
Sylvestre
--
To UNSUBSCRIBE, email to debian-s390-***@lists.debian.org
with a subject of "unsubscribe". Trouble? Contact ***@lists.debian.org
Sylvestre Ledru
2010-02-13 16:50:02 UTC
Permalink
Hello,
Post by Sylvestre Ledru
Good question... I can try to do that. I was just trying to match the
current upstream behavior first.
************
int foo(i)
{
return i*3;
}
************
gcc -O3 foo.c -S -o foo.s
Some feedbacks here. Thanks all for your help. I uploaded atlas and it
builds fine now under s390.

Thanks again,
Sylvestre
--
To UNSUBSCRIBE, email to debian-s390-***@lists.debian.org
with a subject of "unsubscribe". Trouble? Contact ***@lists.debian.org
Adam Thornton
2010-01-28 14:50:02 UTC
Permalink
Post by Bastian Blank
Post by Sylvestre Ledru
Atlas is an auto-optimized library. At the beginning of the script,
atlas launch a script to check what is the CPU architecture, the
optimisation available, etc.
Which different optimizations are available for s390?
But you remind me for something: I wanted to raise the minimum CPU
requirement to z900.
Er, why?

There are a number of shops out there still stuck running 31-bit processors (albeit, no longer supported by IBM). I supported one such right up until I left my previous job. Those guys don't have a lot of other Linux options available to them (although, granted, they tend to also not have any money available to them).

Adam
--
To UNSUBSCRIBE, email to debian-s390-***@lists.debian.org
with a subject of "unsubscribe". Trouble? Contact ***@lists.debian.org
Stephen Powell
2010-01-28 15:50:02 UTC
Permalink
Post by Adam Thornton
Post by Bastian Blank
But you remind me for something: I wanted to raise the minimum CPU
requirement to z900.
Er, why?
There are a number of shops out there still stuck running 31-bit
processors (albeit, no longer supported by IBM). I supported one
such right up until I left my previous job. Those guys don't have
a lot of other Linux options available to them (although, granted,
they tend to also not have any money available to them).
I can't speak for Bastian, but I do know that there has been no
upstream support for the "April 2004 Stream", the last "stream"
which supported ESA/390 processors, in years. The kernel modifications,
C compiler modifications, and C run-time library modifications
which support the "s390" architecture and the s390-tools package
come from IBM; and IBM dropped support for the April 2004 Stream long ago.
Starting with the "October 2005 stream", only z/Architecture
processors are supported. There may be other reasons too, and
Bastian may have something to say about it, but this alone would
appear to be enough.

If it's any consolation, Debian Lenny is the last kernel release
(2.6.26) by *any* distribution, to the best of my knowledge, to
support ESA/390 processors.
--
To UNSUBSCRIBE, email to debian-s390-***@lists.debian.org
with a subject of "unsubscribe". Trouble? Contact ***@lists.debian.org
Loading...