GPL Question

Code, algorithms, languages, construction...
Post Reply
User avatar
kingliveson
Posts: 1388
Joined: Thu Jun 10, 2010 1:22 am
Real Name: Franklin Titus
Location: 28°32'1"N 81°22'33"W

GPL Question

Post by kingliveson » Fri Sep 02, 2011 10:49 pm

A program is not derived or based on GPLed Stockfish, is it possible without violating its license to lift the following function?

Code: Select all

inline void __cpuid(int CPUInfo[4], int InfoType)
{
  int* eax = CPUInfo + 0;
  int* ebx = CPUInfo + 1;
  int* ecx = CPUInfo + 2;
  int* edx = CPUInfo + 3;

  *eax = InfoType;
  *ecx = 0;
  __asm__("cpuid" : "=a" (*eax), "=b" (*ebx), "=c" (*ecx), "=d" (*edx)
                  : "0" (*eax), "2" (*ecx));
}
PAWN : Knight >> Bishop >> Rook >>Queen

hyatt
Posts: 1242
Joined: Thu Jun 10, 2010 2:13 am
Real Name: Bob Hyatt (Robert M. Hyatt)
Location: University of Alabama at Birmingham
Contact:

Re: GPL Question

Post by hyatt » Fri Sep 02, 2011 11:25 pm

I would think that is perfectly OK. You are copying exactly one x86 assembly language instruction, "cpuid". I don't think anyone would make an issue of that. In fact, it is likely that that code came from some other place anyway, using that to discover everything from # of cores to cache size and such is quite common...

User avatar
kingliveson
Posts: 1388
Joined: Thu Jun 10, 2010 1:22 am
Real Name: Franklin Titus
Location: 28°32'1"N 81°22'33"W

Re: GPL Question

Post by kingliveson » Sat Sep 03, 2011 11:02 pm

Yes, I would have to agree. In the case of the above function, ecx register is right shifted 23 bits to see if it is set and ANDed with 1, for SSE4a (population count) instruction support. The snippet is pretty much generic as there aren't really many other ways of calling cpuid opcode. A slight modification for vendor checking:

Code: Select all

#include <stdio.h>
#include <string.h>

int main ()
{

  char VendorID[13];

  int CPUInfo[4] = {-1};
  int InfoType = 0x00000000;

  int* eax = CPUInfo + 0;
  int* ebx = CPUInfo + 1;
  int* ecx = CPUInfo + 2;
  int* edx = CPUInfo + 3;

  *eax = InfoType;
  *ecx = 0;

  {__asm__("cpuid" : "=a" (*eax), "=b" (*ebx), "=c" (*ecx), "=d" (*edx)
                  : "0" (*eax) , "1" (*ebx) , "2" (*ecx) , "3" (*edx));
  }

  strncpy(VendorID, (char*) ebx, 4);
  strncat(VendorID, (char*) edx, 4);
  strncat(VendorID, (char*) ecx, 4);

  printf("Vendor ID: %s\n", VendorID);

  return 0;
}
PAWN : Knight >> Bishop >> Rook >>Queen

Post Reply